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

@wix/motion-edm-autogen-transformations

Package Overview
Dependencies
Maintainers
21
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wix/motion-edm-autogen-transformations - npm Package Compare versions

Comparing version 1.23.0 to 1.24.0

181

dist/cjs/__tests__/transformations/errors/transformError.spec.js

@@ -6,2 +6,3 @@ "use strict";

var _dedentJs = _interopRequireDefault(require("dedent-js"));
var _httpStatusCodes = require("http-status-codes");
var _lodash = require("lodash");

@@ -15,35 +16,35 @@ var _ = require("../../..");

describe('system errors', () => {
// describe('server errors', () => {
// const httpStatus = aRandomItemFrom([500, 503]);
// const expectedErrorCodes = {
// 500: 'INTERNAL_SERVER_ERROR',
// 503: 'SERVICE_UNAVAILABLE',
// };
// const requestId = aRequestId();
describe('server errors', () => {
const httpStatus = (0, _motionRuntimeTestContext.aRandomItemFrom)([500, 503]);
const expectedErrorCodes = {
500: 'INTERNAL_SERVER_ERROR',
503: 'SERVICE_UNAVAILABLE'
};
const requestId = (0, _motionRuntimeTestContext.aRequestId)();
// /* eslint-disable max-len */
// test.each`
// details | description
// ${undefined} | ${'does not exist'}
// ${anObject()} | ${"an object without 'validationError', 'applicationError', and a status code exists on the request"}
// `(
// /* eslint-enable max-len */
// 'transforms the response object message property to a JS error when the details property $description',
// ({ details }) => {
// const ambassadorHTTPError = {
// httpStatus,
// response: { details, message },
// requestId,
// };
// expect(transformError(ambassadorHTTPError)).toMatchObject({
// constructor: Error,
// message: `System error occurred, request-id: ${requestId}`,
// requestId,
// code: expectedErrorCodes[httpStatus],
// });
// },
// );
// });
/* eslint-disable max-len */
test.each`
details | description
${undefined} | ${'does not exist'}
${(0, _motionRuntimeTestContext.anObject)()} | ${"an object without 'validationError', 'applicationError', and a status code exists on the request"}
`( /* eslint-enable max-len */
'transforms the response object message property to a JS error when the details property $description', ({
details
}) => {
const ambassadorHTTPError = {
httpStatus,
response: {
details,
message
},
requestId
};
expect((0, _.transformError)(ambassadorHTTPError)).toMatchObject({
constructor: Error,
message: `System error occurred, request-id: ${requestId}`,
requestId,
code: expectedErrorCodes[httpStatus]
});
});
});
describe('network errors (request-id does not exist, httpStatus is -1', () => {

@@ -346,62 +347,62 @@ test('omits the request-id from the message', () => {

});
// describe('when applicationError is missing, http-status is a client-error status-code', () => {
// const httpStatus = aRandomApplicationErrorHttpStatusCode();
// const statusText = HttpStatus.getStatusText(httpStatus);
// const expectedCode = statusText.split(' ').map(upperCase).join('_');
// describe('when no message exists in the response', () => {
// test('returns a description based on the status-code text only', () => {
// const ambassadorHTTPError = { httpStatus };
// const expectedMessage = dedent`
// message: ${statusText}
// details:
// applicationError:
// description: ${statusText}
// code: ${expectedCode}
// data: {}`;
// expect(transformError(ambassadorHTTPError)).toMatchObject({
// constructor: Error,
// message: expectedMessage,
// details: {
// applicationError: {
// description: statusText,
// code: expectedCode,
// data: {},
// },
// },
// });
// });
// });
// describe('when a message exists', () => {
// test('returns the given http status and a default application error description and message', () => {
// const ambassadorHTTPError = { httpStatus, response: { message } };
// const expectedMessage = dedent`
// message: ${message}
// details:
// applicationError:
// description: ${statusText}
// code: ${expectedCode}
// data: {}`;
// expect(transformError(ambassadorHTTPError)).toMatchObject({
// constructor: Error,
// message: expectedMessage,
// details: {
// applicationError: {
// description: statusText,
// code: expectedCode,
// data: {},
// },
// },
// });
// });
// });
// });
describe('when applicationError is missing, http-status is a client-error status-code', () => {
const httpStatus = aRandomApplicationErrorHttpStatusCode();
const statusText = (0, _httpStatusCodes.getStatusText)(httpStatus);
const expectedCode = statusText.split(' ').map(_lodash.upperCase).join('_');
describe('when no message exists in the response', () => {
test('returns a description based on the status-code text only', () => {
const ambassadorHTTPError = {
httpStatus
};
const expectedMessage = (0, _dedentJs.default)`
message: ${statusText}
details:
applicationError:
description: ${statusText}
code: ${expectedCode}
data: {}`;
expect((0, _.transformError)(ambassadorHTTPError)).toMatchObject({
constructor: Error,
message: expectedMessage,
details: {
applicationError: {
description: statusText,
code: expectedCode,
data: {}
}
}
});
});
});
describe('when a message exists', () => {
test('returns the given http status and a default application error description and message', () => {
const ambassadorHTTPError = {
httpStatus,
response: {
message
}
};
const expectedMessage = (0, _dedentJs.default)`
message: ${message}
details:
applicationError:
description: ${statusText}
code: ${expectedCode}
data: {}`;
expect((0, _.transformError)(ambassadorHTTPError)).toMatchObject({
constructor: Error,
message: expectedMessage,
details: {
applicationError: {
description: statusText,
code: expectedCode,
data: {}
}
}
});
});
});
});
});
});
//# sourceMappingURL=transformError.spec.js.map

@@ -7,2 +7,3 @@ "use strict";

var _constantCase = require("constant-case");
var _httpStatusCodes = require("http-status-codes");
var _jsYaml = _interopRequireDefault(require("js-yaml"));

@@ -17,2 +18,5 @@ var _lodash = _interopRequireDefault(require("lodash"));

const MAX_YAML_LINE_WIDTH = 1000;
const CANCELLED_STATUS_CODE = 499;
const CANCELLED_STATUS_CODE_STRING = CANCELLED_STATUS_CODE.toString();
const CANCELLED_STATUS_TEXT = 'Client Closed Request';
const toYamlString = object => _jsYaml.default.dump(object, {

@@ -22,3 +26,10 @@ lineWidth: MAX_YAML_LINE_WIDTH

const ambassadorSafeStatusText = _maybeHttpStatus => {
return UNKNOWN_STATUS_CODE_TEST;
if (_maybeHttpStatus === CANCELLED_STATUS_CODE || _maybeHttpStatus === CANCELLED_STATUS_CODE_STRING) {
return CANCELLED_STATUS_TEXT;
}
try {
return (0, _httpStatusCodes.getReasonPhrase)(_maybeHttpStatus);
} catch (error) {
return UNKNOWN_STATUS_CODE_TEST;
}
};

@@ -25,0 +36,0 @@ const buildError = ({

import { __makeTemplateObject } from "tslib";
import { aNumber, aRandomItemFrom, aString, } from '@wix/motion-runtime-test-context';
import { anObject, aNumber, aRandomItemFrom, aRequestId, aString, } from '@wix/motion-runtime-test-context';
import dedent from 'dedent-js';
import { set, times } from 'lodash';
import { getStatusText } from 'http-status-codes';
import { set, times, upperCase } from 'lodash';
import { transformError } from '../../..';

@@ -12,32 +13,27 @@ describe('transformError', function () {

describe('system errors', function () {
// describe('server errors', () => {
// const httpStatus = aRandomItemFrom([500, 503]);
// const expectedErrorCodes = {
// 500: 'INTERNAL_SERVER_ERROR',
// 503: 'SERVICE_UNAVAILABLE',
// };
// const requestId = aRequestId();
// /* eslint-disable max-len */
// test.each`
// details | description
// ${undefined} | ${'does not exist'}
// ${anObject()} | ${"an object without 'validationError', 'applicationError', and a status code exists on the request"}
// `(
// /* eslint-enable max-len */
// 'transforms the response object message property to a JS error when the details property $description',
// ({ details }) => {
// const ambassadorHTTPError = {
// httpStatus,
// response: { details, message },
// requestId,
// };
// expect(transformError(ambassadorHTTPError)).toMatchObject({
// constructor: Error,
// message: `System error occurred, request-id: ${requestId}`,
// requestId,
// code: expectedErrorCodes[httpStatus],
// });
// },
// );
// });
describe('server errors', function () {
var httpStatus = aRandomItemFrom([500, 503]);
var expectedErrorCodes = {
500: 'INTERNAL_SERVER_ERROR',
503: 'SERVICE_UNAVAILABLE',
};
var requestId = aRequestId();
/* eslint-disable max-len */
test.each(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n details | description\n ", " | ", "\n ", " | ", "\n "], ["\n details | description\n ", " | ", "\n ", " | ", "\n "])), undefined, 'does not exist', anObject(), "an object without 'validationError', 'applicationError', and a status code exists on the request")(
/* eslint-enable max-len */
'transforms the response object message property to a JS error when the details property $description', function (_a) {
var details = _a.details;
var ambassadorHTTPError = {
httpStatus: httpStatus,
response: { details: details, message: message },
requestId: requestId,
};
expect(transformError(ambassadorHTTPError)).toMatchObject({
constructor: Error,
message: "System error occurred, request-id: ".concat(requestId),
requestId: requestId,
code: expectedErrorCodes[httpStatus],
});
});
});
describe('network errors (request-id does not exist, httpStatus is -1', function () {

@@ -71,3 +67,3 @@ test('omits the request-id from the message', function () {

};
var expectedMessage = dedent(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", "\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", "\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", ""])), argumentNames[1], description, argumentNames[1], description);
var expectedMessage = dedent(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", "\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", "\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", ""])), argumentNames[1], description, argumentNames[1], description);
expect(transformError(ambassadorHTTPError, transformation, argumentNames)).toMatchObject({

@@ -102,3 +98,3 @@ constructor: Error,

/* eslint-disable max-len */
var expectedMessage = dedent(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", "\" ", ", \"", "\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", "\n - field: ", "\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", "\" ", ", \"", "\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", "\n - field: ", "\n description: ", ""])), stableArgumentNames[1], anotherDescription, stableArgumentNames[0], description, stableArgumentNames[1], anotherDescription, stableArgumentNames[0], description);
var expectedMessage = dedent(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", "\" ", ", \"", "\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", "\n - field: ", "\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", "\" ", ", \"", "\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", "\n - field: ", "\n description: ", ""])), stableArgumentNames[1], anotherDescription, stableArgumentNames[0], description, stableArgumentNames[1], anotherDescription, stableArgumentNames[0], description);
expect(transformError(ambassadorHTTPError, transformation, stableArgumentNames)).toMatchObject({

@@ -141,3 +137,3 @@ constructor: Error,

};
var expectedMessage = dedent(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", ".some.arg.field\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", ".some.arg.field\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", ".some.arg.field\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", ".some.arg.field\n description: ", ""])), argumentNames[1], description, argumentNames[1], description);
var expectedMessage = dedent(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", ".some.arg.field\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", ".some.arg.field\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", ".some.arg.field\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", ".some.arg.field\n description: ", ""])), argumentNames[1], description, argumentNames[1], description);
expect(transformError(ambassadorHTTPError, transformation, argumentNames)).toMatchObject({

@@ -172,3 +168,3 @@ constructor: Error,

var transformation = set({}, fieldPathPrefix, '#wrap($[0].something, someValueWrapper)');
var expectedMessage = dedent(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", ".something\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", ".something\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", ".something\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", ".something\n description: ", ""])), argumentNames[0], description, argumentNames[0], description);
var expectedMessage = dedent(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", ".something\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", ".something\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", ".something\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", ".something\n description: ", ""])), argumentNames[0], description, argumentNames[0], description);
expect(transformError(ambassadorHTTPError, transformation, argumentNames)).toMatchObject({

@@ -212,3 +208,3 @@ constructor: Error,

};
var expectedMessage = dedent(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", "\" ", ", \"", ".maxPurchasesPerBuyer\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", "\n - field: ", ".maxPurchasesPerBuyer\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", "\" ", ", \"", ".maxPurchasesPerBuyer\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", "\n - field: ", ".maxPurchasesPerBuyer\n description: ", ""])), stableArgumentNames[1], description, stableArgumentNames[0], description, stableArgumentNames[1], description, stableArgumentNames[0], description);
var expectedMessage = dedent(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n message: 'INVALID_ARGUMENT: \"", "\" ", ", \"", ".maxPurchasesPerBuyer\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", "\n - field: ", ".maxPurchasesPerBuyer\n description: ", ""], ["\n message: 'INVALID_ARGUMENT: \"", "\" ", ", \"", ".maxPurchasesPerBuyer\" ", "'\n details:\n validationError:\n fieldViolations:\n - field: ", "\n description: ", "\n - field: ", ".maxPurchasesPerBuyer\n description: ", ""])), stableArgumentNames[1], description, stableArgumentNames[0], description, stableArgumentNames[1], description, stableArgumentNames[0], description);
expect(transformError(ambassadorHTTPError, transformation, stableArgumentNames)).toMatchObject({

@@ -256,3 +252,3 @@ constructor: Error,

};
var expectedMessage = dedent(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n message: '", ": ", "'\n details:\n applicationError:\n description: ", "\n code: ", "\n data:\n ", ": ", "\n ", ": ", ""], ["\n message: '", ": ", "'\n details:\n applicationError:\n description: ", "\n code: ", "\n data:\n ", ": ", "\n ", ": ", ""])), message, description, description, code, key1, value1, key2, value2);
var expectedMessage = dedent(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n message: '", ": ", "'\n details:\n applicationError:\n description: ", "\n code: ", "\n data:\n ", ": ", "\n ", ": ", ""], ["\n message: '", ": ", "'\n details:\n applicationError:\n description: ", "\n code: ", "\n data:\n ", ": ", "\n ", ": ", ""])), message, description, description, code, key1, value1, key2, value2);
expect(transformError(ambassadorHTTPError)).toMatchObject({

@@ -271,56 +267,44 @@ constructor: Error,

});
// describe('when applicationError is missing, http-status is a client-error status-code', () => {
// const httpStatus = aRandomApplicationErrorHttpStatusCode();
// const statusText = HttpStatus.getStatusText(httpStatus);
// const expectedCode = statusText.split(' ').map(upperCase).join('_');
// describe('when no message exists in the response', () => {
// test('returns a description based on the status-code text only', () => {
// const ambassadorHTTPError = { httpStatus };
// const expectedMessage = dedent`
// message: ${statusText}
// details:
// applicationError:
// description: ${statusText}
// code: ${expectedCode}
// data: {}`;
// expect(transformError(ambassadorHTTPError)).toMatchObject({
// constructor: Error,
// message: expectedMessage,
// details: {
// applicationError: {
// description: statusText,
// code: expectedCode,
// data: {},
// },
// },
// });
// });
// });
// describe('when a message exists', () => {
// test('returns the given http status and a default application error description and message', () => {
// const ambassadorHTTPError = { httpStatus, response: { message } };
// const expectedMessage = dedent`
// message: ${message}
// details:
// applicationError:
// description: ${statusText}
// code: ${expectedCode}
// data: {}`;
// expect(transformError(ambassadorHTTPError)).toMatchObject({
// constructor: Error,
// message: expectedMessage,
// details: {
// applicationError: {
// description: statusText,
// code: expectedCode,
// data: {},
// },
// },
// });
// });
// });
// });
describe('when applicationError is missing, http-status is a client-error status-code', function () {
var httpStatus = aRandomApplicationErrorHttpStatusCode();
var statusText = getStatusText(httpStatus);
var expectedCode = statusText.split(' ').map(upperCase).join('_');
describe('when no message exists in the response', function () {
test('returns a description based on the status-code text only', function () {
var ambassadorHTTPError = { httpStatus: httpStatus };
var expectedMessage = dedent(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n message: ", "\n details:\n applicationError:\n description: ", "\n code: ", "\n data: {}"], ["\n message: ", "\n details:\n applicationError:\n description: ", "\n code: ", "\n data: {}"])), statusText, statusText, expectedCode);
expect(transformError(ambassadorHTTPError)).toMatchObject({
constructor: Error,
message: expectedMessage,
details: {
applicationError: {
description: statusText,
code: expectedCode,
data: {},
},
},
});
});
});
describe('when a message exists', function () {
test('returns the given http status and a default application error description and message', function () {
var ambassadorHTTPError = { httpStatus: httpStatus, response: { message: message } };
var expectedMessage = dedent(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n message: ", "\n details:\n applicationError:\n description: ", "\n code: ", "\n data: {}"], ["\n message: ", "\n details:\n applicationError:\n description: ", "\n code: ", "\n data: {}"])), message, statusText, expectedCode);
expect(transformError(ambassadorHTTPError)).toMatchObject({
constructor: Error,
message: expectedMessage,
details: {
applicationError: {
description: statusText,
code: expectedCode,
data: {},
},
},
});
});
});
});
});
});
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9;
//# sourceMappingURL=transformError.spec.js.map
import { constantCase } from 'constant-case';
import { getReasonPhrase } from 'http-status-codes';
import yaml from 'js-yaml';

@@ -8,2 +9,5 @@ import _ from 'lodash';

var MAX_YAML_LINE_WIDTH = 1000;
var CANCELLED_STATUS_CODE = 499;
var CANCELLED_STATUS_CODE_STRING = CANCELLED_STATUS_CODE.toString();
var CANCELLED_STATUS_TEXT = 'Client Closed Request';
var toYamlString = function (object) {

@@ -13,3 +17,12 @@ return yaml.dump(object, { lineWidth: MAX_YAML_LINE_WIDTH }).replace(/\n$/, '');

var ambassadorSafeStatusText = function (_maybeHttpStatus) {
return UNKNOWN_STATUS_CODE_TEST;
if (_maybeHttpStatus === CANCELLED_STATUS_CODE ||
_maybeHttpStatus === CANCELLED_STATUS_CODE_STRING) {
return CANCELLED_STATUS_TEXT;
}
try {
return getReasonPhrase(_maybeHttpStatus);
}
catch (error) {
return UNKNOWN_STATUS_CODE_TEST;
}
};

@@ -16,0 +29,0 @@ var buildError = function (_a) {

{
"name": "@wix/motion-edm-autogen-transformations",
"version": "1.23.0",
"version": "1.24.0",
"license": "UNLICENSED",

@@ -44,2 +44,3 @@ "author": {

"deep-for-each": "~3.0.0",
"http-status-codes": "^2.0.0",
"js-yaml": "~4.1.0",

@@ -76,3 +77,3 @@ "jsonpath-plus": "~5.1.0",

},
"falconPackageHash": "f87de6f85d461f847d070bd7dc1a74eda5ed4900db4a7c6d80d295f6"
"falconPackageHash": "8ab148867ac9a3209b495bce24a6e523e296783a54814d7b6b1a5113"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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