Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gocommerce/utils

Package Overview
Dependencies
Maintainers
5
Versions
170
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gocommerce/utils - npm Package Compare versions

Comparing version 0.6.3 to 0.6.4

7

dist/buildGraphQLError.js

@@ -7,3 +7,3 @@ 'use strict';

exports.default = buildGraphQLError;
function buildGraphQLError(message, code) {
function buildGraphQLError(message, code, customFields) {
class CustomError extends Error {

@@ -13,6 +13,7 @@ constructor() {

this.code = code;
this.message = this.message || 'Internal server error';
this.message = message || 'Internal server error';
this.customFields = customFields || {};
}
}
throw new CustomError(message);
throw new CustomError();
}

@@ -11,2 +11,6 @@ export type AlertType = 'success' | 'error' | 'warning' | 'info'

export interface ErrorMap {
[name: string]: error | { [name: string]: error }
}
export interface error {

@@ -13,0 +17,0 @@ message: string

@@ -56,3 +56,3 @@ 'use strict';

_metricLogger('EndSubRequest', {
wasError: 'false',
wasError: 'fasle',
statusCode: response.status,

@@ -59,0 +59,0 @@ elapsed: (new Date().getTime() - start_time).toFixed(2)

@@ -13,10 +13,15 @@ 'use strict';

var _splunkEvents = require('splunk-events');
var _v = require('uuid/v4');
var _splunkEvents2 = _interopRequireDefault(_splunkEvents);
var _v2 = _interopRequireDefault(_v);
var _axiosRetry = require('axios-retry');
var _axiosRetry2 = _interopRequireDefault(_axiosRetry);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const SPLUNK_ENDPOINT = 'splunk-heavyforwarder-public.vtex.com';
const splunkEvents = new _splunkEvents2.default();
const SOURCE = 'gc_ui';
const SPLUNK_URI = `http://splunk-heavyforwarder-public.vtex.com/services/collector/event?channel=${(0, _v2.default)()}&source=${SOURCE}`;
//log to splunk a metric object
const metricLogger = (id, ctx, type = 'none', data, TOKEN, fieldName) => {

@@ -27,11 +32,20 @@ const vtex = ctx.vtex;

const host = headers['x-forwarded-host'];
const level = 'Debug';
const workflow_type = 'GCRequestTracing';
const operationId = headers['x-operationid'] && headers['x-operationid'].split('|') || ('; , ' + headers.cookie).split('; , X-OperationId=').pop().split(';').shift();
const operationId = headers['x-operationid'] && headers['x-operationid'].split('|') || ('; , ' + ctx.request.header.cookie).split('; , X-OperationId=').pop().split(';').shift();
const caller = headers[`x-vtex-caller`].split('@');
const userAgent = vtex.userAgent.split('@');
const event = _extends({}, data, {
const log = event => ({
time: +new Date(),
host: host,
source: SOURCE,
event: event,
sourcetype: 'json',
index: SOURCE
});
const event = {
resolverName: fieldName,
requestid: id,
sourcetype: 'Log',
type: 'info',
origin: origin,
workflow_instance: type,
userAgentcaller: caller && caller[0],

@@ -43,30 +57,27 @@ app_version: caller && caller[1],

requestHops: operationId && parseInt(operationId[1]) + 1,
workflow_instance: type,
account: vtex.account,
workflow_type: 'GCRequestTracing',
workspace: vtex.workspace
};
(0, _axiosRetry2.default)(_axios2.default, {
retries: 3,
retryDelay: retryCount => {
return retryCount * 500;
}
});
// fetcher to log events to splunk depends on colossus context
function splunkCustomFetcher(context) {
const headers = context.headers || {};
return (0, _axios2.default)(_extends({}, context, {
headers: _extends({}, headers, {
'Proxy-Authorization': vtex.authToken,
'X-Vtex-Proxy-To': `https://${SPLUNK_ENDPOINT}:8088`,
['X-OperationId']: `${operationId && operationId[0]}|${operationId && parseInt(operationId[1]) + 1}`
})
}));
}
try {
splunkEvents.config({
endpoint: `http://${SPLUNK_ENDPOINT}`,
request: splunkCustomFetcher,
host: host,
token: TOKEN,
injectTimestamp: true,
debug: true
});
splunkEvents.logEvent(level, type, workflow_type, type, event, vtex.account);
} catch (e) {
console.error(`Splunk Events Error: ${e} ${level} ${type} ${event ? JSON.stringify(event) : 'No event data'}`);
}
return (0, _axios2.default)({
url: SPLUNK_URI,
method: 'POST',
data: log(_extends({}, data, event)),
headers: {
'X-Vtex-Proxy-To': 'https://splunk-heavyforwarder-public.vtex.com:8088',
'Proxy-Authorization': vtex.authToken,
Authorization: `Splunk ${TOKEN}`,
['X-OperationId']: `${operationId && operationId[0]}|${operationId && parseInt(operationId[1]) + 1}`
}
}).then(res => {
return res;
// console.log(`log ${type}`)
}).catch(e => (console.log(`logError ${type}`, e.response), e));
};
exports.default = metricLogger;

@@ -22,2 +22,3 @@

Mutation?: { [key: string]: any }
[key: string]: any
}

@@ -53,3 +54,3 @@

export const Functions: any
export function buildGraphQLError(message: string, code?: string): void
export function buildGraphQLError(message: string, code?: string, customFields?: any): void
}

@@ -56,0 +57,0 @@

{
"name": "@gocommerce/utils",
"version": "0.6.3",
"version": "0.6.4",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc