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

mappersmith

Package Overview
Dependencies
Maintainers
2
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mappersmith - npm Package Compare versions

Comparing version 2.34.0 to 2.35.0

built/tsconfig.tsbuildinfo

20

client-builder.js

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -15,5 +15,5 @@ var _manifest = _interopRequireDefault(require("./manifest"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -37,3 +37,3 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

this.Promise = configs.Promise;
this.manifest = new _manifest.default(manifest, configs);
this.manifest = new _manifest["default"](manifest, configs);
this.GatewayClassFactory = GatewayClassFactory;

@@ -60,3 +60,3 @@ this.maxMiddlewareStackExecutionAllowed = configs.maxMiddlewareStackExecutionAllowed;

return (0, _utils.assign)(resource, _defineProperty({}, method.name, function (requestParams) {
var request = new _request.default(method.descriptor, requestParams);
var request = new _request["default"](method.descriptor, requestParams);
return _this2.invokeMiddlewares(resourceName, method.name, request);

@@ -95,3 +95,3 @@ }));

}).then(function (request) {
if (request instanceof _request.default) {
if (request instanceof _request["default"]) {
return request;

@@ -106,3 +106,3 @@ }

throw new Error("[Mappersmith] middleware \"".concat(middleware.__name, "\" should return \"Request\" but returned \"").concat(prettyType, "\""));
}).catch(function (e) {
})["catch"](function (e) {
requestPhaseFailureContext.middleware = middleware.__name;

@@ -118,3 +118,3 @@ throw e;

var executeMiddlewareStack = function executeMiddlewareStack() {
return prepareRequest().catch(function (e) {
return prepareRequest()["catch"](function (e) {
var returnedInvalidRequest = requestPhaseFailureContext.returnedInvalidRequest,

@@ -158,3 +158,3 @@ abortExecution = requestPhaseFailureContext.abortExecution,

return resolve(response);
}).catch(reject);
})["catch"](reject);
});

@@ -164,2 +164,2 @@ }

var _default = ClientBuilder;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -17,3 +17,3 @@ var _utils = require("./utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -32,3 +32,3 @@ var REGEXP_EMULATE_HTTP = /^(delete|put|patch)/i;

Gateway.extends = function (methods) {
Gateway["extends"] = function (methods) {
return (0, _utils.assign)({}, Gateway.prototype, methods);

@@ -45,4 +45,4 @@ };

call: function call() {
var _this = this,
_arguments = arguments;
var _arguments = arguments,
_this = this;

@@ -73,5 +73,5 @@ var timeStart = (0, _utils.performanceNow)();

if ((0, _timeoutError.isTimeoutError)(error) && this.options().enableHTTP408OnTimeouts) {
this.failCallback(new _response.default(this.request, 408, message, {}, [error]));
this.failCallback(new _response["default"](this.request, 408, message, {}, [error]));
} else {
this.failCallback(new _response.default(this.request, 400, message, {}, [error]));
this.failCallback(new _response["default"](this.request, 400, message, {}, [error]));
}

@@ -101,2 +101,2 @@ },

var _default = Gateway;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -19,3 +19,3 @@ var _gateway = _interopRequireDefault(require("../gateway"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -37,6 +37,6 @@ // Fetch can be used in nodejs, so it should always use the btoa util

function Fetch(request) {
_gateway.default.apply(this, arguments);
_gateway["default"].apply(this, arguments);
}
Fetch.prototype = _gateway.default.extends({
Fetch.prototype = _gateway["default"]["extends"]({
get: function get() {

@@ -57,3 +57,3 @@ this.performRequest('get');

},
delete: function _delete() {
"delete": function _delete() {
this.performRequest('delete');

@@ -115,3 +115,3 @@ },

});
}).catch(function (error) {
})["catch"](function (error) {
if (canceled) {

@@ -132,6 +132,6 @@ return;

});
return new _response.default(this.request, status, data, responseHeaders);
return new _response["default"](this.request, status, data, responseHeaders);
}
});
var _default = Fetch;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -23,9 +23,9 @@ var _url = _interopRequireDefault(require("url"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function HTTP(request) {
_gateway.default.apply(this, arguments);
_gateway["default"].apply(this, arguments);
}
HTTP.prototype = _gateway.default.extends({
HTTP.prototype = _gateway["default"]["extends"]({
get: function get() {

@@ -46,3 +46,3 @@ this.performRequest('get');

},
delete: function _delete() {
"delete": function _delete() {
this.performRequest('delete');

@@ -55,3 +55,3 @@ },

var defaults = _url.default.parse(this.request.url());
var defaults = _url["default"].parse(this.request.url());

@@ -67,3 +67,3 @@ var requestMethod = this.shouldEmulateHTTP() ? 'post' : method;

var handler = defaults.protocol === 'https:' ? _https.default : _http.default;
var handler = defaults.protocol === 'https:' ? _https["default"] : _http["default"];
var requestParams = (0, _utils.assign)(defaults, {

@@ -177,6 +177,6 @@ method: requestMethod,

createResponse: function createResponse(httpResponse, rawData) {
return new _response.default(this.request, httpResponse.statusCode, this.request.isBinary() ? Buffer.concat(rawData) : rawData.join(''), httpResponse.headers);
return new _response["default"](this.request, httpResponse.statusCode, this.request.isBinary() ? Buffer.concat(rawData) : rawData.join(''), httpResponse.headers);
}
});
var _default = HTTP;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -13,9 +13,9 @@ var _gateway = _interopRequireDefault(require("../gateway"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function Mock(request) {
_gateway.default.apply(this, arguments);
_gateway["default"].apply(this, arguments);
}
Mock.prototype = _gateway.default.extends({
Mock.prototype = _gateway["default"]["extends"]({
get: function get() {

@@ -36,3 +36,3 @@ this.callMock();

},
delete: function _delete() {
"delete": function _delete() {
this.callMock();

@@ -45,3 +45,3 @@ },

return _this.dispatchResponse(response);
}).catch(function (e) {
})["catch"](function (e) {
return _this.dispatchClientError(e.message, e);

@@ -52,2 +52,2 @@ });

var _default = Mock;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -17,3 +17,3 @@ var _gateway = _interopRequireDefault(require("../gateway"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -23,6 +23,6 @@ var toBase64 = window.btoa || _utils.btoa;

function XHR(request) {
_gateway.default.apply(this, arguments);
_gateway["default"].apply(this, arguments);
}
XHR.prototype = _gateway.default.extends({
XHR.prototype = _gateway["default"]["extends"]({
get: function get() {

@@ -53,3 +53,3 @@ var xmlHttpRequest = this.createXHR();

},
delete: function _delete() {
"delete": function _delete() {
this.performRequest('delete');

@@ -139,3 +139,3 @@ },

var responseHeaders = (0, _utils.parseResponseHeaders)(xmlHttpRequest.getAllResponseHeaders());
return new _response.default(this.request, status, data, responseHeaders);
return new _response["default"](this.request, status, data, responseHeaders);
},

@@ -164,2 +164,2 @@ setHeaders: function setHeaders(xmlHttpRequest, customHeaders) {

var _default = XHR;
exports.default = _default;
exports["default"] = _default;

@@ -15,6 +15,6 @@ "use strict";

// For browsers use XHR adapter
defaultGateway = require('./gateway/xhr').default;
defaultGateway = require('./gateway/xhr')["default"];
} else if (typeof _process !== 'undefined') {
// For node use HTTP adapter
defaultGateway = require('./gateway/http').default;
defaultGateway = require('./gateway/http')["default"];
}

@@ -21,0 +21,0 @@

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -13,12 +13,16 @@ var _methodDescriptor = _interopRequireDefault(require("./method-descriptor"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
/**

@@ -58,3 +62,3 @@ * @typedef Manifest

} else {
this.middleware = _toConsumableArray(clientMiddleware).concat(_toConsumableArray(middleware));
this.middleware = [].concat(_toConsumableArray(clientMiddleware), _toConsumableArray(middleware));
}

@@ -88,4 +92,5 @@ }

return new _methodDescriptor.default((0, _utils.assign)({
return new _methodDescriptor["default"]((0, _utils.assign)({
host: this.host,
allowResourceHostOverride: this.allowResourceHostOverride,
bodyAttr: this.bodyAttr,

@@ -141,5 +146,3 @@ headersAttr: this.headersAttr,

var resourceMiddleware = this.createMethodDescriptor(name, method).middleware;
var middlewares = _toConsumableArray(resourceMiddleware).concat(_toConsumableArray(this.middleware));
var middlewares = [].concat(_toConsumableArray(resourceMiddleware), _toConsumableArray(this.middleware));
return middlewares.map(createInstance);

@@ -149,2 +152,2 @@ }

var _default = Manifest;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = forge;
exports["default"] = forge;
exports.setContext = exports.configs = exports.version = void 0;

@@ -14,6 +14,6 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/* global VERSION */
var version = "2.34.0";
var version = "2.35.0";
exports.version = version;

@@ -119,10 +119,12 @@ var configs = {

}
/**
* @param {Object} context
*/
};
/**
* @deprecated Shouldn't be used, not safe for concurrent use.
* @param {Object} context
*/
};
exports.configs = configs;
var setContext = function setContext(context) {
console.warn('The use of setContext is deprecated - you need to find another way to pass data between your middlewares.');
configs.context = (0, _utils.assign)(configs.context, context);

@@ -142,3 +144,3 @@ };

return new _clientBuilder.default(manifest, GatewayClassFactory, configs).build();
return new _clientBuilder["default"](manifest, GatewayClassFactory, configs).build();
}

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

});
exports.default = MethodDescriptor;
exports["default"] = MethodDescriptor;

@@ -9,0 +9,0 @@ /**

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -40,2 +40,2 @@ var _utils = require("../utils");

exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -42,2 +42,2 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -40,2 +40,2 @@ /**

var _default = DurationMiddleware;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = exports.CONTENT_TYPE_JSON = void 0;
exports["default"] = exports.CONTENT_TYPE_JSON = void 0;
var mediaType = 'application/json';

@@ -57,2 +57,2 @@ var charset = 'charset=utf-8';

var _default = EncodeJsonMiddleware;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = exports.setErrorHandler = void 0;
exports["default"] = exports.setErrorHandler = void 0;

@@ -30,3 +30,3 @@ var _index = require("../index");

return resolve(response);
}).catch(function (response) {
})["catch"](function (response) {
var proceed = true;

@@ -42,2 +42,2 @@ handler && (proceed = !(handler(response) === true));

var _default = GlobalErrorHandlerMiddleware;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = exports.setLoggerEnabled = exports.setErrorLogger = exports.setSuccessLogger = exports.defaultErrorLogger = exports.defaultSuccessLogger = void 0;
exports["default"] = exports.setLoggerEnabled = exports.setErrorLogger = exports.setSuccessLogger = exports.defaultErrorLogger = exports.defaultSuccessLogger = void 0;

@@ -72,3 +72,3 @@ var defaultSuccessLogger = function defaultSuccessLogger(message) {

return log(response.request(), response);
}).catch(function (response) {
})["catch"](function (response) {
log(response.request(), response);

@@ -82,2 +82,2 @@ throw response;

var _default = ConsoleLogMiddleware;
exports.default = _default;
exports["default"] = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {

@@ -9,3 +11,3 @@ value: true

get: function get() {
return _v.default;
return _v["default"];
}

@@ -28,2 +30,4 @@ });

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = RetryMiddleware;
exports["default"] = RetryMiddleware;
exports.calculateExponentialRetryTime = exports.setRetryConfigs = void 0;

@@ -13,4 +15,6 @@

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var retryConfigs = (0, _utils.assign)({}, _v.defaultRetryConfigs);

@@ -35,3 +39,3 @@ /**

retryConfigs = (0, _utils.assign)({}, retryConfigs, newConfigs);
middlewareInstance = (0, _v.default)(retryConfigs)();
middlewareInstance = (0, _v["default"])(retryConfigs)();
};

@@ -56,3 +60,3 @@ /**

exports.setRetryConfigs = setRetryConfigs;
var middlewareInstance = (0, _v.default)(retryConfigs)();
var middlewareInstance = (0, _v["default"])(retryConfigs)();

@@ -59,0 +63,0 @@ function RetryMiddleware() {

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

});
exports.calculateExponentialRetryTime = exports.default = exports.defaultRetryConfigs = void 0;
exports.calculateExponentialRetryTime = exports["default"] = exports.defaultRetryConfigs = void 0;

@@ -15,3 +15,3 @@ var _index = require("../../../index");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -35,26 +35,26 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
* This middleware will automatically retry GET requests up to the configured amount of
* retries using a randomization function that grows exponentially. The retry count and
* the time used will be included as a header in the response.
*
* The retry time is calculated using the following formula:
* retryTime = min(
* random(previousRetryTime - randomizedFactor, previousRetryTime + randomizedFactor) * multipler,
* maxRetryTime
* )
*
* Take a look at `calculateExponentialRetryTime` for more information.
*
* @param {Object} retryConfigs
* @param {String} retryConfigs.headerRetryCount (default: 'X-Mappersmith-Retry-Count')
* @param {String} retryConfigs.headerRetryTime (default: 'X-Mappersmith-Retry-Time')
* @param {Number} retryConfigs.maxRetryTimeInSecs (default: 5)
* @param {Number} retryConfigs.initialRetryTimeInSecs (default: 1)
* @param {Number} retryConfigs.factor (default: 0.2) - randomization factor
* @param {Number} retryConfigs.multiplier (default: 2) - exponential factor
* @param {Number} retryConfigs.retries (default: 5) - max retries
*/
};
/**
* This middleware will automatically retry GET requests up to the configured amount of
* retries using a randomization function that grows exponentially. The retry count and
* the time used will be included as a header in the response.
*
* The retry time is calculated using the following formula:
* retryTime = min(
* random(previousRetryTime - randomizedFactor, previousRetryTime + randomizedFactor) * multipler,
* maxRetryTime
* )
*
* Take a look at `calculateExponentialRetryTime` for more information.
*
* @param {Object} retryConfigs
* @param {String} retryConfigs.headerRetryCount (default: 'X-Mappersmith-Retry-Count')
* @param {String} retryConfigs.headerRetryTime (default: 'X-Mappersmith-Retry-Time')
* @param {Number} retryConfigs.maxRetryTimeInSecs (default: 5)
* @param {Number} retryConfigs.initialRetryTimeInSecs (default: 1)
* @param {Number} retryConfigs.factor (default: 0.2) - randomization factor
* @param {Number} retryConfigs.multiplier (default: 2) - exponential factor
* @param {Number} retryConfigs.retries (default: 5) - max retries
*/
};
exports.defaultRetryConfigs = defaultRetryConfigs;

@@ -89,3 +89,3 @@

exports.default = _default;
exports["default"] = _default;

@@ -111,6 +111,6 @@ var retriableRequest = function retriableRequest(resolve, reject, next, request) {

var errorMessage = response instanceof Error ? response.message : e.message;
reject(new _response.default(request, 400, errorMessage, {}, [response]));
reject(new _response["default"](request, 400, errorMessage, {}, [response]));
}
}
}).catch(function (response) {
})["catch"](function (response) {
if (shouldRetry && retryConfigs.validateRetry(response)) {

@@ -123,3 +123,3 @@ scheduleRequest();

var errorMessage = response instanceof Error ? response.message : e.message;
reject(new _response.default(request, 400, errorMessage, {}, [response]));
reject(new _response["default"](request, 400, errorMessage, {}, [response]));
}

@@ -126,0 +126,0 @@ }

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -37,2 +37,2 @@ /**

exports.default = _default;
exports["default"] = _default;

@@ -9,3 +9,3 @@ "use strict";

get: function get() {
return _basicAuth.default;
return _basicAuth["default"];
}

@@ -16,2 +16,2 @@ });

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -9,3 +9,3 @@ "use strict";

get: function get() {
return _csrf.default;
return _csrf["default"];
}

@@ -16,2 +16,2 @@ });

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -9,3 +9,3 @@ "use strict";

get: function get() {
return _duration.default;
return _duration["default"];
}

@@ -16,2 +16,2 @@ });

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {

@@ -9,3 +11,3 @@ value: true

get: function get() {
return _encodeJson.default;
return _encodeJson["default"];
}

@@ -22,2 +24,4 @@ });

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {

@@ -9,3 +11,3 @@ value: true

get: function get() {
return _globalErrorHandler.default;
return _globalErrorHandler["default"];
}

@@ -22,2 +24,4 @@ });

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {

@@ -9,3 +11,3 @@ value: true

get: function get() {
return _log.default;
return _log["default"];
}

@@ -46,2 +48,4 @@ });

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {

@@ -9,3 +11,3 @@ value: true

get: function get() {
return _retry.default;
return _retry["default"];
}

@@ -28,2 +30,4 @@ });

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {

@@ -9,3 +11,3 @@ value: true

get: function get() {
return _v.default;
return _v["default"];
}

@@ -22,2 +24,4 @@ });

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

@@ -9,3 +9,3 @@ "use strict";

get: function get() {
return _timeout.default;
return _timeout["default"];
}

@@ -16,2 +16,2 @@ });

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -27,2 +27,2 @@ /**

var _default = MockAssert;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -17,3 +17,3 @@ var _mockAssert = _interopRequireDefault(require("./mock-assert"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -38,2 +38,5 @@ /**

this.body = this.bodyFunction ? props.body : (0, _mockUtils.toSortedQueryString)(props.body);
this.headersFunction = typeof props.headers === 'function';
this.headers = props.headersFunction ? props.headers : (0, _mockUtils.toSortedQueryString)(props.headers);
this.headersObject = props.headers;
this.responseHeaders = props.response.headers || {};

@@ -77,3 +80,3 @@ this.setResponseData(props.response.body);

this.calls.push(request);
return new _response.default(request, status, this.responseData, this.responseHeaders);
return new _response["default"](request, status, this.responseData, this.responseHeaders);
},

@@ -85,7 +88,7 @@

assertObject: function assertObject() {
return new _mockAssert.default(this.calls);
return new _mockAssert["default"](this.calls);
},
/**
* Checks if the request matches with the mock HTTP method, URL and body
* Checks if the request matches with the mock HTTP method, URL, headers and body
*

@@ -102,3 +105,4 @@ * @return {boolean}

var urlMatch = this.urlFunction ? this.url(request.url(), request.params()) : (0, _mockUtils.sortedUrl)(this.url) === (0, _mockUtils.sortedUrl)(request.url());
return this.method === request.method() && urlMatch && bodyMatch();
var headerMatch = !this.headers || (this.headersFunction ? this.headers(request.headers()) : (0, _mockUtils.isSubset)(this.headersObject, request.headers()));
return this.method === request.method() && urlMatch && bodyMatch() && headerMatch;
},

@@ -123,2 +127,2 @@

var _default = MockRequest;
exports.default = _default;
exports["default"] = _default;

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -15,3 +15,3 @@ var _mappersmith = require("../mappersmith");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -64,3 +64,3 @@ var VALUE_NOT_MATCHED = '<MAPPERSMITH_VALUE_NOT_MATCHED>';

*/
with: function _with(requestParams) {
"with": function _with(requestParams) {
this.requestParams = requestParams;

@@ -134,6 +134,7 @@ return this;

if (!this.mockRequest) {
this.mockRequest = new _mockRequest.default(this.id, {
this.mockRequest = new _mockRequest["default"](this.id, {
method: finalRequest.method(),
url: this.generateUrlMatcher(finalRequest),
body: finalRequest.body(),
headers: finalRequest.headers(),
response: {

@@ -227,3 +228,3 @@ status: responseStatus,

var methodDescriptor = this.manifest.createMethodDescriptor(this.resourceName, this.methodName);
return new _request.default(methodDescriptor, this.requestParams);
return new _request["default"](methodDescriptor, this.requestParams);
},

@@ -237,3 +238,3 @@

var methodDescriptor = this.manifest.createMethodDescriptor(this.resourceName, this.methodName);
var initialRequest = new _request.default(methodDescriptor, this.requestParams);
var initialRequest = new _request["default"](methodDescriptor, this.requestParams);
var middleware = this.manifest.createMiddleware({

@@ -264,2 +265,2 @@ resourceName: this.resourceName,

var _default = MockResource;
exports.default = _default;
exports["default"] = _default;

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

exports.toSortedQueryString = toSortedQueryString;
exports.isSubset = isSubset;
exports.sortedUrl = sortedUrl;

@@ -12,2 +13,20 @@

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function toSortedQueryString(entry) {

@@ -23,2 +42,45 @@ if (!(0, _utils.isPlainObject)(entry)) {

/**
* Filters an `object` by keeping only the keys fulfilling the `predicate`
*
* @param {Object} object - An object
* @param {Function} predicate - A function of type (key: string) => boolean
* @returns {Object} The filtered object
*/
function filterByPredicate(object, predicate) {
return Object.entries(object).filter(function (_ref) {
var _ref2 = _slicedToArray(_ref, 1),
key = _ref2[0];
return predicate(key);
}).reduce(function (acc, _ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
key = _ref4[0],
value = _ref4[1];
return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, value));
}, {});
}
/**
* Verify if the object `A` is contained within object `B` - shallowly.
* In other words, is A a subset of B?
*
* @see https://en.wikipedia.org/wiki/Subset
*
* @param {Object} A - The object to test
* @param {Object} B - The superset object to verify against
* @returns A boolean representing if A is a shallow subset of B
*/
function isSubset(A, B) {
// Make B only contain the non-nullish keys it has in in common with A
var keysFromA = (0, _utils.validKeys)(A);
var filteredB = filterByPredicate(B, function (keyFromB) {
return keysFromA.includes(keyFromB);
});
return toSortedQueryString(A) === toSortedQueryString(filteredB);
}
/**
* Sort the query params on a URL based on the 'key=value' string value.

@@ -25,0 +87,0 @@ * E.g. /example?b=2&a=1 will become /example?a=1&b=2

{
"name": "mappersmith",
"version": "2.34.0",
"version": "2.35.0",
"description": "It is a lightweight rest client for node.js and the browser",

@@ -15,15 +15,17 @@ "author": "Tulio Ornelas <ornelas.tulio@gmail.com>",

"integration-server": "node spec/integration/server.js",
"test:browser": "./node_modules/.bin/jest --config jestSetup/configs/config.web.json",
"test:browser:integration": "cross-env NODE_ENV=test ./node_modules/.bin/karma start spec/integration/browser/karma.conf.js",
"test:browser:watch": "./node_modules/.bin/jest --config jestSetup/configs/config.web.json --watchAll",
"test:node": "./node_modules/.bin/jest --config jestSetup/configs/config.node.json",
"test:node:integration": "cross-env NODE_ENV=test cross-env NODE_PATH=. cross-env JASMINE_CONFIG_PATH=spec/integration/node/support/jasmine.json jasmine",
"test:node:watch": "./node_modules/.bin/jest --config jestSetup/configs/config.node.json --watchAll",
"test:typings": "./node_modules/.bin/tsc",
"test": "concurrently --success first --names \"test,server\" --kill-others \"node scripts/ci.js\" \"yarn integration-server\"",
"build:node": "rm -rf lib/* && ./node_modules/.bin/babel src -d lib",
"build:browser": "rm -rf dist/* && ./node_modules/.bin/webpack --config webpack.conf.js",
"build": "npm run build:node && npm run build:browser",
"test:browser": "yarn jest --config jestSetup/configs/config.web.json",
"test:browser:integration": "cross-env NODE_ENV=test yarn karma start spec/integration/browser/karma.conf.js",
"test:browser:watch": "yarn jest --config jestSetup/configs/config.web.json --watchAll",
"test:node": "yarn jest --config jestSetup/configs/config.node.json",
"test:node:integration": "cross-env NODE_ENV=test cross-env NODE_PATH=. cross-env JASMINE_CONFIG_PATH=spec/integration/node/support/jasmine.json ts-node node_modules/jasmine/bin/jasmine",
"test:node:watch": "yarn jest --config jestSetup/configs/config.node.json --watchAll",
"test:typings": "yarn tsc --noEmit",
"test:unit": "concurrently --success first --names \"test,server\" --kill-others \"node scripts/ci.js\" \"yarn integration-server\"",
"test": "yarn test:typings && yarn test:unit",
"build:types": "yarn tsc --emitDeclarationOnly",
"build:node": "rm -rf lib/* && yarn babel src -d lib --extensions '.js,.ts'",
"build:browser": "rm -rf dist/* && yarn webpack --config webpack.conf.js",
"build": "yarn build:types && yarn build:node && yarn build:browser",
"release": "./scripts/release.sh",
"lint": "./node_modules/.bin/eslint \"{src,spec}/**/*.js\""
"lint": "yarn eslint \"{src,spec}/**/*.js\""
},

@@ -49,3 +51,2 @@ "repository": {

"homepage": "https://github.com/tulios/mappersmith",
"tonicExampleFilename": "example.js",
"browser": {

@@ -59,42 +60,48 @@ "./lib/gateway/http.js": false,

"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/register": "^7.0.0",
"@babel/preset-typescript": "^7.0.0",
"@babel/register": "<7.12.0",
"@chiragrupani/karma-chromium-edge-launcher": "^2.1.1",
"@types/node": "^16.10.3",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.4.2",
"babel-loader": "^8.0.5",
"babel-jest": "^23.6.0",
"babel-loader": "^8.2.2",
"babel-plugin-minify-replace": "^0.4.3",
"body-parser": "^1.15.2",
"concurrently": "^3.5.1",
"cookie-parser": "^1.4.3",
"cross-env": "^5.1.1",
"eslint": "^6.0.1",
"body-parser": "^1.19.0",
"concurrently": "^3.6.1",
"cookie-parser": "^1.4.5",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"express": "^4.15.4",
"faux-jax-tulios": "^5.0.8",
"jasmine": "^2.5.2",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-standard": "^5.0.0",
"express": "^4.17.1",
"faux-jax-tulios": "^5.0.9",
"jasmine": "^2.99.0",
"jasmine-core": "^2.5.2",
"jest": "^23.5.0",
"js-md5": "^0.6.1",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "^1.1.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "^0.0.31",
"karma-webpack": "^4.0.2",
"mockdate": "^2.0.1",
"multer": "^1.2.0",
"puppeteer": "^1.18.1",
"typescript": "^3.5.2",
"uglifyjs-webpack-plugin": "^2.1.1",
"webpack": "^4.35.2",
"webpack-cli": "^3.3.5",
"webpack-dev-server": "^3.7.2",
"whatwg-fetch": "^2.0.2"
"jest": "^23.6.0",
"js-md5": "^0.7.3",
"karma": "^6.3.4",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^4.0.1",
"karma-sourcemap-loader": "^0.3.8",
"karma-spec-reporter": "^0.0.32",
"karma-typescript": "5.5.2",
"karma-webpack": "^4.0.0",
"mockdate": "^3.0.5",
"multer": "^1.4.3",
"puppeteer": "^1.20.0",
"ts-jest": "^23.0.0",
"ts-node": "^10.2.1",
"typescript": "^4.4.3",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^4.46.0",
"webpack-cli": "^4.8.0",
"whatwg-fetch": "^3.6.2"
}
}
[![npm version](https://badge.fury.io/js/mappersmith.svg)](http://badge.fury.io/js/mappersmith)
[![Build Status](https://travis-ci.org/tulios/mappersmith.svg?branch=master)](https://travis-ci.org/tulios/mappersmith)
[![Node.js CI](https://github.com/tulios/mappersmith/actions/workflows/node.js.yml/badge.svg)](https://github.com/tulios/mappersmith/actions/workflows/node.js.yml)
[![Windows Tests](https://img.shields.io/appveyor/ci/tulios/mappersmith.svg?label=Windows%20Tests)](https://ci.appveyor.com/project/tulios/mappersmith)

@@ -26,3 +26,3 @@ # Mappersmith

- [Creating middleware](#creating-middleware)
- [Context](#context)
- [Context (deprecated)](#context)
- [Optional arguments](#creating-middleware-optional-arguments)

@@ -53,9 +53,12 @@ - [mockRequest](#creating-middleware-optional-arguments-mock-request)

#### NPM
```sh
npm install mappersmith --save
# yarn add mappersmith
```
or
```sh
yarn add mappersmith
```
#### Browser

@@ -76,4 +79,4 @@

```sh
npm run build
npm run release # for minified version
yarn build
yarn release # for minified version
```

@@ -347,5 +350,5 @@

*NOTE*: Since version `2.34.0` you need to also use `allowResourceHostOverride: true`, example:
**NOTE**: Since version `2.34.0` you need to also use `allowResourceHostOverride: true`, example:
```
```javascript
const client = forge({

@@ -433,56 +436,8 @@ host: 'https://new-host.com',

#### <a name="context"></a> Context
#### <a name="context"></a> Context (deprecated)
Sometimes you may need to set data to be available to all your client's middleware. In this
case you can use the `setContext` helper, like so:
⚠️ `setContext` is not safe for concurrent use, and shouldn't be used!
```javascript
import { setContext } from 'mappersmith'
Why is it not safe? Basically, the setContext function mutates a global state (see [here](https://github.com/tulios/mappersmith/blob/2.34.0/src/mappersmith.js#L114)), hence it is the last call to setContext that decides its global value. Which leads to a race condition when handling concurrent requests.
const MyMiddleware = ({ context }) => ({
/* ... */
})
setContext({ some: 'data'})
client.User.all()
// context: { some: 'data' }
```
This is specially useful when using mappermith coupled with back-end services.
For instance you could define a globally available correlation id middleware
like this:
```javascript
import forge, { configs, setContext } from 'mappersmith'
import express from 'express'
const CorrelationIdMiddleware = ({ context }) => ({
request(request) {
return request.enhance({
headers: {
'correlation-id': context.correlationId
}
})
}
})
configs.middleware = [CorrelationIdMiddleware]
const api = forge({ ... })
const app = express()
app.use((req, res, next) => {
setContext({
correlationId: req.headers['correlation-id']
})
})
// Then, when calling `api.User.all()` in any handler it will include the
// `correlation-id` header automatically.
```
Note that setContext will merge the object provided with the current context
instead of replacing it.
#### <a name="creating-middleware-optional-arguments"></a> Optional arguments

@@ -927,2 +882,3 @@

* `status(statusNumber | statusHandler)`, ex: `status(204)` or `status((request, mock) => 200)`
* `headers(responseHeaders)`, ex: `headers({ 'x-header': 'value' })`
* `response(responseData | responseHandler)`, ex: `response({ user: { id: 1 } })` or `response((request, mock) => ({ user: { id: request.body().id } }))`

@@ -1166,2 +1122,22 @@ * `assertObject()`

#### unusedMocks
`unusedMocks` can be used to check if there are any unused mocks after each test. It
will return count of unused mocks. It can be either unused `mockRequest` or `mockClient`.
```javascript
import { install, uninstall, unusedMocks } from 'mappersmith/test'
describe('Feature', () => {
beforeEach(() => install())
afterEach(() => {
const unusedMocksCount = unusedMocks()
uninstall()
if (unusedMocksCount > 0) {
throw new Error(`There are ${unusedMocksCount} unused mocks`) // fail the test
}
})
})
```
## <a name="gateways"></a> Gateways

@@ -1168,0 +1144,0 @@

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

});
exports.default = void 0;
exports["default"] = void 0;

@@ -107,4 +107,4 @@ var _utils = require("./utils");

for (var _i = 0; _i < dynamicSegmentKeys.length; _i++) {
var key = dynamicSegmentKeys[_i];
for (var _i = 0, _dynamicSegmentKeys = dynamicSegmentKeys; _i < _dynamicSegmentKeys.length; _i++) {
var key = _dynamicSegmentKeys[_i];
var pattern = new RegExp("{".concat(key, "\\??}"), 'g');

@@ -141,2 +141,19 @@

/**
* Returns the template path, without params, before interpolation.
* If path is a function, returns the result of request.path()
* Example: /some/{param}/path
*
* @return {String|Function}
*/
pathTemplate: function pathTemplate() {
var path = this.methodDescriptor.path;
if (typeof this.methodDescriptor.path !== 'function' && path[0] !== '/') {
path = "/".concat(path);
}
return path;
},
/**
* Returns the full URL

@@ -216,2 +233,2 @@ * Example: http://example.org/some/path?param1=true

var _default = Request;
exports.default = _default;
exports["default"] = _default;

@@ -6,15 +6,19 @@ "use strict";

});
exports.default = void 0;
exports["default"] = void 0;
var _utils = require("./utils");
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
var REGEXP_CONTENT_TYPE_JSON = /^application\/json/;
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var REGEXP_CONTENT_TYPE_JSON = /^application\/(json|.*\+json)/;
/**

@@ -154,3 +158,3 @@ * @typedef Response

enhance: function enhance(extras) {
var enhancedResponse = new Response(this.request(), extras.status || this.status(), extras.rawData || this.rawData(), (0, _utils.assign)({}, this.headers(), extras.headers), _toConsumableArray(this.errors).concat([extras.error]));
var enhancedResponse = new Response(this.request(), extras.status || this.status(), extras.rawData || this.rawData(), (0, _utils.assign)({}, this.headers(), extras.headers), extras.error ? [].concat(_toConsumableArray(this.errors), [extras.error]) : _toConsumableArray(this.errors));
enhancedResponse.timeElapsed = this.timeElapsed;

@@ -161,2 +165,2 @@ return enhancedResponse;

var _default = Response;
exports.default = _default;
exports["default"] = _default;

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

});
exports.m = exports.lookupResponse = exports.lookupResponseAsync = exports.clear = exports.uninstall = exports.install = exports.mockRequest = exports.mockClient = void 0;
exports.m = exports.lookupResponse = exports.lookupResponseAsync = exports.unusedMocks = exports.clear = exports.uninstall = exports.install = exports.mockRequest = exports.mockClient = void 0;

@@ -19,3 +19,3 @@ var _mockRequest = _interopRequireDefault(require("./mocks/mock-request"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

@@ -34,3 +34,3 @@ var store = [];

var mockClient = function mockClient(client) {
var entry = new _mockResource.default(ids++, client);
var entry = new _mockResource["default"](ids++, client);
store.push(entry);

@@ -57,3 +57,3 @@ return entry;

var mockRequest = function mockRequest(props) {
var entry = new _mockRequest.default(ids++, props);
var entry = new _mockRequest["default"](ids++, props);
store.push(entry);

@@ -71,3 +71,3 @@ return entry.assertObject();

originalGateway = _index.configs.gateway;
_index.configs.gateway = _mock.default;
_index.configs.gateway = _mock["default"];
};

@@ -100,2 +100,20 @@ /**

/**
* Returns number of unused mocks
* @returns {Number}
*/
exports.clear = clear;
var unusedMocks = function unusedMocks() {
var mocks = store.map(function (mock) {
return mock.toMockRequest();
});
var count = 0;
mocks.forEach(function (mock) {
if (mock.calls.length === 0) count++;
});
return count;
};
/**
* Similar to "lookupResponse" but it also runs the request/prepareRequest phase of the middleware

@@ -110,3 +128,3 @@ * stack

exports.clear = clear;
exports.unusedMocks = unusedMocks;

@@ -195,7 +213,7 @@ var lookupResponseAsync = function lookupResponseAsync(request) {

var requestToLog = function requestToLog(request) {
return "\"".concat(request.method().toUpperCase(), " ").concat(request.url(), "\" (body: \"").concat((0, _utils.toQueryString)(request.body()), "\")");
return "\"".concat(request.method().toUpperCase(), " ").concat(request.url(), "\" (body: \"").concat((0, _utils.toQueryString)(request.body()), "\"; headers: \"").concat((0, _utils.toQueryString)(request.headers()), "\")");
};
var mockToLog = function mockToLog(requestMock) {
return "\"".concat(requestMock.method.toUpperCase(), " ").concat(requestMock.url, "\" (body: \"").concat(requestMock.body, "\")");
return "\"".concat(requestMock.method.toUpperCase(), " ").concat(requestMock.url, "\" (body: \"").concat(requestMock.body, "\"; headers: \"").concat(requestMock.headers, "\")");
};

@@ -202,0 +220,0 @@

@@ -52,2 +52,3 @@ /// <reference path="./middleware/basic-auth.d.ts" />

path(): string
pathTemplate(): string | Function
url(): string

@@ -81,3 +82,3 @@ headers(): Headers

export type AbortFn = (error: Error) => void
export type AbortFn = (error: Error) => void

@@ -113,4 +114,6 @@ export type RenewFn = () => Promise<object>

readonly host?: string
readonly allowResourceHostOverride?: boolean
readonly ignoreGlobalMiddleware?: boolean
readonly middleware?: Middleware[]
readonly gatewayConfigs?: Partial<GatewayConfiguration>
// @alias middleware

@@ -117,0 +120,0 @@ readonly middlewares?: Middleware[]

@@ -22,2 +22,3 @@ declare module 'mappersmith/test' {

status(responder: StatusHandler | number): this;
headers(responseHeaders: Headers): this;
response(responder: ResponseHandler | object | string): this;

@@ -36,2 +37,4 @@ assertObject(): MockAssert;

export type MockRequestBodyFunction = (requestBody: MockRequestBody) => MockRequestBody
export type MockRequestHeaders = Headers
export type MockRequestHeadersFunction = (requestHeaders: MockRequestHeaders) => MockRequestHeaders
export interface MockRequestArgs {

@@ -41,2 +44,3 @@ method: string

body?: MockRequestBody | MockRequestBodyFunction
headers?: MockRequestHeaders | MockRequestHeadersFunction
response?: {

@@ -43,0 +47,0 @@ status?: number

@@ -6,10 +6,5 @@ "use strict";

});
exports.toQueryString = toQueryString;
exports.performanceNow = performanceNow;
exports.parseResponseHeaders = parseResponseHeaders;
exports.lowerCaseObjectKeys = lowerCaseObjectKeys;
exports.isPlainObject = isPlainObject;
exports.btoa = exports.assign = exports.buildRecursive = exports.validKeys = void 0;
exports.btoa = exports.isPlainObject = exports.assign = exports.lowerCaseObjectKeys = exports.parseResponseHeaders = exports.performanceNow = exports.toQueryString = exports.buildRecursive = exports.validKeys = void 0;
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

@@ -39,5 +34,9 @@ var _process, getNanoSeconds, loadTime;

var isNeitherNullNorUndefined = function isNeitherNullNorUndefined(x) {
return x !== null && x !== undefined;
};
var validKeys = function validKeys(entry) {
return Object.keys(entry).filter(function (key) {
return entry[key] !== undefined && entry[key] !== null;
return isNeitherNullNorUndefined(entry[key]);
});

@@ -48,12 +47,6 @@ };

var buildRecursive = function buildRecursive(key, value, suffix) {
suffix = suffix || '';
var isArray = Array.isArray(value);
var isObject = _typeof(value) === 'object';
var buildRecursive = function buildRecursive(key, value) {
var suffix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
if (!isArray && !isObject) {
return "".concat(encodeURIComponent(key + suffix), "=").concat(encodeURIComponent(value));
}
if (isArray) {
if (Array.isArray(value)) {
return value.map(function (v) {

@@ -64,2 +57,6 @@ return buildRecursive(key, v, suffix + '[]');

if (_typeof(value) !== 'object') {
return "".concat(encodeURIComponent(key + suffix), "=").concat(encodeURIComponent(value));
}
return validKeys(value).map(function (k) {

@@ -72,3 +69,3 @@ return buildRecursive(key, value[k], suffix + '[' + k + ']');

function toQueryString(entry) {
var toQueryString = function toQueryString(entry) {
if (!isPlainObject(entry)) {

@@ -81,3 +78,3 @@ return entry;

}).join('&').replace(R20, '+');
}
};
/**

@@ -89,9 +86,15 @@ * Gives time in miliseconds, but with sub-milisecond precision for Browser

function performanceNow() {
if (hasProcessHrtime()) {
return (getNanoSeconds() - loadTime) / 1e6;
exports.toQueryString = toQueryString;
var performanceNow = function performanceNow() {
if (hasProcessHrtime() && getNanoSeconds !== undefined) {
var now = getNanoSeconds();
if (now !== undefined && loadTime !== undefined) {
return (now - loadTime) / 1e6;
}
}
return Date.now();
}
};
/**

@@ -106,3 +109,5 @@ * borrowed from: {@link https://gist.github.com/monsur/706839}

function parseResponseHeaders(headerStr) {
exports.performanceNow = performanceNow;
var parseResponseHeaders = function parseResponseHeaders(headerStr) {
var headers = {};

@@ -130,5 +135,7 @@

return headers;
}
};
function lowerCaseObjectKeys(obj) {
exports.parseResponseHeaders = parseResponseHeaders;
var lowerCaseObjectKeys = function lowerCaseObjectKeys(obj) {
return Object.keys(obj).reduce(function (target, key) {

@@ -138,4 +145,5 @@ target[key.toLowerCase()] = obj[key];

}, {});
}
};
exports.lowerCaseObjectKeys = lowerCaseObjectKeys;
var hasOwnProperty = Object.prototype.hasOwnProperty;

@@ -160,5 +168,5 @@

function isPlainObject(value) {
var isPlainObject = function isPlainObject(value) {
return toString.call(value) === '[object Object]' && Object.getPrototypeOf(value) === Object.getPrototypeOf({});
}
};
/**

@@ -169,2 +177,3 @@ * borrowed from: {@link https://github.com/davidchambers/Base64.js}

exports.isPlainObject = isPlainObject;
var CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

@@ -178,3 +187,3 @@

for ( // initialize result and counter
var block, charCode, idx = 0; // if the next str index does not exist:
var block = 0, charCode, idx = 0; // if the next str index does not exist:
// change the mapping table to "="

@@ -181,0 +190,0 @@ // check if d has no fractional digits

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