Socket
Socket
Sign inDemoInstall

mappersmith

Package Overview
Dependencies
Maintainers
3
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.37.1 to 2.38.0

client-builder.d.ts

11

client-builder.js

@@ -26,2 +26,9 @@ "use strict";

var isFactoryConfigured = function isFactoryConfigured(factory) {
if (!factory || !factory()) {
return false;
}
return true;
};
/**

@@ -32,2 +39,4 @@ * @typedef ClientBuilder

*/
var ClientBuilder = /*#__PURE__*/function () {

@@ -49,3 +58,3 @@ function ClientBuilder(manifestDefinition, GatewayClassFactory, configs) {

if (!GatewayClassFactory || !GatewayClassFactory()) {
if (!isFactoryConfigured(GatewayClassFactory)) {
throw new Error('[Mappersmith] gateway class not configured (configs.gateway)');

@@ -52,0 +61,0 @@ }

205

gateway.js

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

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

@@ -13,90 +13,161 @@ var _utils = require("./utils");

var _response = _interopRequireDefault(require("./response"));
var _response = require("./response");
var _timeoutError = require("./gateway/timeout-error");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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; }
var REGEXP_EMULATE_HTTP = /^(delete|put|patch)/i;
function Gateway(request) {
var configs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
this.request = request;
this.configs = configs;
var Gateway = /*#__PURE__*/function () {
function Gateway(request, configs) {
_classCallCheck(this, Gateway);
this.successCallback = function () {
return undefined;
};
_defineProperty(this, "request", void 0);
this.failCallback = function () {
return undefined;
};
}
_defineProperty(this, "configs", void 0);
Gateway["extends"] = function (methods) {
return (0, _utils.assign)({}, Gateway.prototype, methods);
};
_defineProperty(this, "successCallback", void 0);
Gateway.prototype = {
options: function options() {
return this.configs;
},
shouldEmulateHTTP: function shouldEmulateHTTP() {
return this.options().emulateHTTP && REGEXP_EMULATE_HTTP.test(this.request.method());
},
call: function call() {
var _arguments = arguments,
_this = this;
_defineProperty(this, "failCallback", void 0);
var timeStart = (0, _utils.performanceNow)();
return new _mappersmith.configs.Promise(function (resolve, reject) {
_this.successCallback = function (response) {
response.timeElapsed = (0, _utils.performanceNow)() - timeStart;
resolve(response);
};
this.request = request;
this.configs = configs;
_this.failCallback = function (response) {
response.timeElapsed = (0, _utils.performanceNow)() - timeStart;
reject(response);
};
this.successCallback = function () {
return undefined;
};
try {
_this[_this.request.method()].apply(_this, _arguments);
} catch (e) {
_this.dispatchClientError(e.message, e);
}
});
},
dispatchResponse: function dispatchResponse(response) {
response.success() ? this.successCallback(response) : this.failCallback(response);
},
dispatchClientError: function dispatchClientError(message, error) {
if ((0, _timeoutError.isTimeoutError)(error) && this.options().enableHTTP408OnTimeouts) {
this.failCallback(new _response["default"](this.request, 408, message, {}, [error]));
} else {
this.failCallback(new _response["default"](this.request, 400, message, {}, [error]));
this.failCallback = function () {
return undefined;
};
}
_createClass(Gateway, [{
key: "get",
value: function get() {
throw new Error('Not implemented');
}
},
prepareBody: function prepareBody(method, headers) {
var body = this.request.body();
}, {
key: "head",
value: function head() {
throw new Error('Not implemented');
}
}, {
key: "post",
value: function post() {
throw new Error('Not implemented');
}
}, {
key: "put",
value: function put() {
throw new Error('Not implemented');
}
}, {
key: "patch",
value: function patch() {
throw new Error('Not implemented');
}
}, {
key: "delete",
value: function _delete() {
throw new Error('Not implemented');
}
}, {
key: "options",
value: function options() {
return this.configs;
}
}, {
key: "shouldEmulateHTTP",
value: function shouldEmulateHTTP() {
return this.options().emulateHTTP && REGEXP_EMULATE_HTTP.test(this.request.method());
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
if (this.shouldEmulateHTTP()) {
body = body || {};
(0, _utils.isPlainObject)(body) && (body._method = method);
headers['x-http-method-override'] = method;
}, {
key: "call",
value: function call() {
var _arguments = arguments,
_this = this;
var timeStart = (0, _utils.performanceNow)();
if (!_mappersmith.configs.Promise) {
throw new Error('[Mappersmith] Promise not configured (configs.Promise)');
}
return new _mappersmith.configs.Promise(function (resolve, reject) {
_this.successCallback = function (response) {
response.timeElapsed = (0, _utils.performanceNow)() - timeStart;
resolve(response);
};
_this.failCallback = function (response) {
response.timeElapsed = (0, _utils.performanceNow)() - timeStart;
reject(response);
};
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
_this[_this.request.method()].apply(_this, _arguments); // eslint-disable-line prefer-spread,prefer-rest-params
} catch (e) {
var err = e;
_this.dispatchClientError(err.message, err);
}
});
}
}, {
key: "dispatchResponse",
value: function dispatchResponse(response) {
response.success() ? this.successCallback(response) : this.failCallback(response);
}
}, {
key: "dispatchClientError",
value: function dispatchClientError(message, error) {
if ((0, _timeoutError.isTimeoutError)(error) && this.options().enableHTTP408OnTimeouts) {
this.failCallback(new _response.Response(this.request, 408, message, {}, [error]));
} else {
this.failCallback(new _response.Response(this.request, 400, message, {}, [error]));
}
}
}, {
key: "prepareBody",
value: function prepareBody(method, headers) {
var body = this.request.body();
var bodyString = (0, _utils.toQueryString)(body);
if (this.shouldEmulateHTTP()) {
body = body || {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
if (bodyString) {
// If it's not simple, let the browser (or the user) set it
if ((0, _utils.isPlainObject)(body)) {
headers['content-type'] = 'application/x-www-form-urlencoded;charset=utf-8';
(0, _utils.isPlainObject)(body) && (body['_method'] = method);
headers['x-http-method-override'] = method;
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
var bodyString = (0, _utils.toQueryString)(body);
if (bodyString) {
// If it's not simple, let the browser (or the user) set it
if ((0, _utils.isPlainObject)(body)) {
headers['content-type'] = 'application/x-www-form-urlencoded;charset=utf-8';
}
}
return bodyString;
}
}]);
return bodyString;
}
};
return Gateway;
}();
exports.Gateway = Gateway;
var _default = Gateway;
exports["default"] = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
exports["default"] = exports.Fetch = void 0;
var _gateway = _interopRequireDefault(require("../gateway"));
var _gateway = require("../gateway");

@@ -20,8 +22,22 @@ var _response = _interopRequireDefault(require("../response"));

// Fetch can be used in nodejs, so it should always use the btoa util
var fetch = _mappersmith.configs.fetch;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
if (!fetch) {
throw new Error("[Mappersmith] global fetch does not exist, please assign \"configs.fetch\" to a valid implementation");
}
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**

@@ -33,101 +49,135 @@ * Gateway which uses the "fetch" implementation configured in "configs.fetch".

*/
var Fetch = /*#__PURE__*/function (_Gateway) {
_inherits(Fetch, _Gateway);
var _super = _createSuper(Fetch);
function Fetch() {
_gateway["default"].apply(this, arguments);
}
function Fetch() {
_classCallCheck(this, Fetch);
Fetch.prototype = _gateway["default"]["extends"]({
get: function get() {
this.performRequest('get');
},
head: function head() {
this.performRequest('head');
},
post: function post() {
this.performRequest('post');
},
put: function put() {
this.performRequest('put');
},
patch: function patch() {
this.performRequest('patch');
},
"delete": function _delete() {
this.performRequest('delete');
},
performRequest: function performRequest(method) {
var _this = this;
return _super.apply(this, arguments);
}
var customHeaders = {};
var body = this.prepareBody(method, customHeaders);
var auth = this.request.auth();
if (auth) {
var username = auth.username || '';
var password = auth.password || '';
customHeaders['authorization'] = "Basic ".concat((0, _utils.btoa)("".concat(username, ":").concat(password)));
_createClass(Fetch, [{
key: "get",
value: function get() {
this.performRequest('get');
}
}, {
key: "head",
value: function head() {
this.performRequest('head');
}
}, {
key: "post",
value: function post() {
this.performRequest('post');
}
}, {
key: "put",
value: function put() {
this.performRequest('put');
}
}, {
key: "patch",
value: function patch() {
this.performRequest('patch');
}
}, {
key: "delete",
value: function _delete() {
this.performRequest('delete');
}
}, {
key: "performRequest",
value: function performRequest(method) {
var _this = this;
var headers = (0, _utils.assign)(customHeaders, this.request.headers());
var requestMethod = this.shouldEmulateHTTP() ? 'post' : method;
var init = (0, _utils.assign)({
method: requestMethod,
headers: headers,
body: body
}, this.options().Fetch);
var timeout = this.request.timeout();
var timer = null;
var canceled = false;
var fetch = _mappersmith.configs.fetch;
if (timeout) {
timer = setTimeout(function () {
canceled = true;
var error = (0, _timeoutError.createTimeoutError)("Timeout (".concat(timeout, "ms)"));
if (!fetch) {
throw new Error("[Mappersmith] global fetch does not exist, please assign \"configs.fetch\" to a valid implementation");
}
_this.dispatchClientError(error.message, error);
}, timeout);
}
var customHeaders = {};
var body = this.prepareBody(method, customHeaders);
var auth = this.request.auth();
fetch(this.request.url(), init).then(function (fetchResponse) {
if (canceled) {
return;
if (auth) {
var username = auth.username || '';
var password = auth.password || '';
customHeaders['authorization'] = "Basic ".concat((0, _utils.btoa)("".concat(username, ":").concat(password)));
}
clearTimeout(timer);
var responseData;
var headers = (0, _utils.assign)(customHeaders, this.request.headers());
var requestMethod = this.shouldEmulateHTTP() ? 'post' : method;
var init = (0, _utils.assign)({
method: requestMethod,
headers: headers,
body: body
}, this.options().Fetch);
var timeout = this.request.timeout();
var timer = null;
var canceled = false;
if (_this.request.isBinary()) {
if (typeof fetchResponse.buffer === 'function') {
responseData = fetchResponse.buffer();
if (timeout) {
timer = setTimeout(function () {
canceled = true;
var error = (0, _timeoutError.createTimeoutError)("Timeout (".concat(timeout, "ms)"));
_this.dispatchClientError(error.message, error);
}, timeout);
}
fetch(this.request.url(), init).then(function (fetchResponse) {
if (canceled) {
return;
}
timer && clearTimeout(timer);
var responseData;
if (_this.request.isBinary()) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (typeof fetchResponse.buffer === 'function') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
responseData = fetchResponse.buffer();
} else {
responseData = fetchResponse.arrayBuffer();
}
} else {
responseData = fetchResponse.arrayBuffer();
responseData = fetchResponse.text();
}
} else {
responseData = fetchResponse.text();
}
responseData.then(function (data) {
_this.dispatchResponse(_this.createResponse(fetchResponse, data));
responseData.then(function (data) {
_this.dispatchResponse(_this.createResponse(fetchResponse, data));
});
})["catch"](function (error) {
if (canceled) {
return;
}
timer && clearTimeout(timer);
_this.dispatchClientError(error.message, error);
});
})["catch"](function (error) {
if (canceled) {
return;
}
}
}, {
key: "createResponse",
value: function createResponse(fetchResponse, data) {
var status = fetchResponse.status;
var responseHeaders = {};
fetchResponse.headers.forEach(function (value, key) {
responseHeaders[key] = value;
}); // eslint-disable-next-line @typescript-eslint/no-explicit-any
clearTimeout(timer);
return new _response["default"](this.request, status, data, responseHeaders);
}
}]);
_this.dispatchClientError(error.message, error);
});
},
createResponse: function createResponse(fetchResponse, data) {
var status = fetchResponse.status;
var responseHeaders = {};
fetchResponse.headers.forEach(function (value, key) {
responseHeaders[key] = value;
});
return new _response["default"](this.request, status, data, responseHeaders);
}
});
return Fetch;
}(_gateway.Gateway);
exports.Fetch = Fetch;
var _default = Fetch;
exports["default"] = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
exports["default"] = exports.HTTP = void 0;
var _url = _interopRequireDefault(require("url"));
var url = _interopRequireWildcard(require("url"));
var _http = _interopRequireDefault(require("http"));
var http = _interopRequireWildcard(require("http"));
var _https = _interopRequireDefault(require("https"));
var https = _interopRequireWildcard(require("https"));
var _utils = require("../utils");
var _gateway = _interopRequireDefault(require("../gateway"));
var _gateway = require("../gateway");

@@ -24,155 +26,223 @@ var _response = _interopRequireDefault(require("../response"));

function HTTP() {
_gateway["default"].apply(this, arguments);
}
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); }
HTTP.prototype = _gateway["default"]["extends"]({
get: function get() {
this.performRequest('get');
},
head: function head() {
this.performRequest('head');
},
post: function post() {
this.performRequest('post');
},
put: function put() {
this.performRequest('put');
},
patch: function patch() {
this.performRequest('patch');
},
"delete": function _delete() {
this.performRequest('delete');
},
performRequest: function performRequest(method) {
var _this = this;
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 headers = {}; // FIXME: Deprecated API
// eslint-disable-next-line n/no-deprecated-api
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var defaults = _url["default"].parse(this.request.url());
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
var requestMethod = this.shouldEmulateHTTP() ? 'post' : method;
var body = this.prepareBody(method, headers);
var timeout = this.request.timeout();
this.canceled = false;
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
if (body && typeof body.length === 'number') {
headers['content-length'] = Buffer.byteLength(body);
}
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
var handler = defaults.protocol === 'https:' ? _https["default"] : _http["default"];
var requestParams = (0, _utils.assign)(defaults, {
method: requestMethod,
headers: (0, _utils.assign)(headers, this.request.headers())
});
var auth = this.request.auth();
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
if (auth) {
var username = auth.username || '';
var password = auth.password || '';
requestParams['auth'] = "".concat(username, ":").concat(password);
}
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
var httpOptions = this.options().HTTP;
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
if (httpOptions.useSocketConnectionTimeout) {
requestParams['timeout'] = timeout;
}
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
if (httpOptions.configure) {
(0, _utils.assign)(requestParams, httpOptions.configure(requestParams));
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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; }
var HTTP = /*#__PURE__*/function (_Gateway) {
_inherits(HTTP, _Gateway);
var _super = _createSuper(HTTP);
function HTTP() {
var _this;
_classCallCheck(this, HTTP);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (httpOptions.onRequestWillStart) {
httpOptions.onRequestWillStart(requestParams);
_this = _super.call.apply(_super, [this].concat(args));
_defineProperty(_assertThisInitialized(_this), "canceled", false);
return _this;
}
_createClass(HTTP, [{
key: "get",
value: function get() {
this.performRequest('get');
}
}, {
key: "head",
value: function head() {
this.performRequest('head');
}
}, {
key: "post",
value: function post() {
this.performRequest('post');
}
}, {
key: "put",
value: function put() {
this.performRequest('put');
}
}, {
key: "patch",
value: function patch() {
this.performRequest('patch');
}
}, {
key: "delete",
value: function _delete() {
this.performRequest('delete');
}
}, {
key: "performRequest",
value: function performRequest(method) {
var _this2 = this;
var httpRequest = handler.request(requestParams, function (httpResponse) {
return _this.onResponse(httpResponse, httpOptions, requestParams);
});
httpRequest.on('socket', function (socket) {
if (httpOptions.onRequestSocketAssigned) {
httpOptions.onRequestSocketAssigned(requestParams);
var headers = {}; // FIXME: Deprecated API
// eslint-disable-next-line n/no-deprecated-api
var defaults = url.parse(this.request.url());
var requestMethod = this.shouldEmulateHTTP() ? 'post' : method;
var body = this.prepareBody(method, headers);
var timeout = this.request.timeout();
this.canceled = false;
if (body && typeof body !== 'boolean' && typeof body !== 'number' && typeof body.length === 'number') {
headers['content-length'] = Buffer.byteLength(body);
}
socket.on('lookup', function () {
if (httpOptions.onSocketLookup) {
httpOptions.onSocketLookup(requestParams);
}
var handler = defaults.protocol === 'https:' ? https : http;
var requestParams = (0, _utils.assign)(defaults, {
method: requestMethod,
headers: (0, _utils.assign)(headers, this.request.headers())
});
socket.on('connect', function () {
if (httpOptions.onSocketConnect) {
httpOptions.onSocketConnect(requestParams);
}
var auth = this.request.auth();
if (auth) {
var username = auth.username || '';
var password = auth.password || '';
requestParams['auth'] = "".concat(username, ":").concat(password);
}
var httpOptions = this.options().HTTP;
if (httpOptions.useSocketConnectionTimeout) {
requestParams['timeout'] = timeout;
}
if (httpOptions.configure) {
(0, _utils.assign)(requestParams, httpOptions.configure(requestParams));
}
if (httpOptions.onRequestWillStart) {
httpOptions.onRequestWillStart(requestParams);
}
var httpRequest = handler.request(requestParams, function (httpResponse) {
return _this2.onResponse(httpResponse, httpOptions, requestParams);
});
socket.on('secureConnect', function () {
if (httpOptions.onSocketSecureConnect) {
httpOptions.onSocketSecureConnect(requestParams);
httpRequest.on('socket', function (socket) {
if (httpOptions.onRequestSocketAssigned) {
httpOptions.onRequestSocketAssigned(requestParams);
}
socket.on('lookup', function () {
if (httpOptions.onSocketLookup) {
httpOptions.onSocketLookup(requestParams);
}
});
socket.on('connect', function () {
if (httpOptions.onSocketConnect) {
httpOptions.onSocketConnect(requestParams);
}
});
socket.on('secureConnect', function () {
if (httpOptions.onSocketSecureConnect) {
httpOptions.onSocketSecureConnect(requestParams);
}
});
});
});
httpRequest.on('error', function (e) {
return _this.onError(e);
});
body && httpRequest.write(body);
httpRequest.on('error', function (e) {
return _this2.onError(e);
});
body && httpRequest.write(body);
if (timeout) {
if (!httpOptions.useSocketConnectionTimeout) {
httpRequest.setTimeout(timeout);
if (timeout) {
if (!httpOptions.useSocketConnectionTimeout) {
httpRequest.setTimeout(timeout);
}
httpRequest.on('timeout', function () {
_this2.canceled = true;
httpRequest.abort();
var error = (0, _timeoutError.createTimeoutError)("Timeout (".concat(timeout, "ms)"));
_this2.dispatchClientError(error.message, error);
});
}
httpRequest.on('timeout', function () {
_this.canceled = true;
httpRequest.abort();
var error = (0, _timeoutError.createTimeoutError)("Timeout (".concat(timeout, "ms)"));
_this.dispatchClientError(error.message, error);
});
httpRequest.end();
}
}, {
key: "onResponse",
value: function onResponse(httpResponse, httpOptions, requestParams) {
var _this3 = this;
httpRequest.end();
},
onResponse: function onResponse(httpResponse, httpOptions, requestParams) {
var _this2 = this;
var rawData = [];
var rawData = [];
if (!this.request.isBinary()) {
httpResponse.setEncoding('utf8');
}
if (!this.request.isBinary()) {
httpResponse.setEncoding('utf8');
httpResponse.once('readable', function () {
if (httpOptions.onResponseReadable) {
httpOptions.onResponseReadable(requestParams);
}
});
httpResponse.on('data', function (chunk) {
return rawData.push(chunk);
}).on('end', function () {
if (_this3.canceled) {
return;
}
_this3.dispatchResponse(_this3.createResponse(httpResponse, rawData));
});
httpResponse.on('end', function () {
if (httpOptions.onResponseEnd) {
httpOptions.onResponseEnd(requestParams);
}
});
}
httpResponse.once('readable', function () {
if (httpOptions.onResponseReadable) {
httpOptions.onResponseReadable(requestParams);
}
});
httpResponse.on('data', function (chunk) {
return rawData.push(chunk);
}).on('end', function () {
if (_this2.canceled) {
}, {
key: "onError",
value: function onError(e) {
if (this.canceled) {
return;
}
_this2.dispatchResponse(_this2.createResponse(httpResponse, rawData));
});
httpResponse.on('end', function () {
if (httpOptions.onResponseEnd) {
httpOptions.onResponseEnd(requestParams);
}
});
},
onError: function onError(e) {
if (this.canceled) {
return;
this.dispatchClientError(e.message, e);
}
}, {
key: "createResponse",
value: function createResponse(httpResponse, rawData) {
var responseData = this.request.isBinary() ? Buffer.concat(rawData) : rawData.join('');
return new _response["default"](this.request, httpResponse.statusCode, responseData, // eslint-disable-next-line @typescript-eslint/no-explicit-any
httpResponse.headers);
}
}]);
this.dispatchClientError(e.message, e);
},
createResponse: function createResponse(httpResponse, rawData) {
return new _response["default"](this.request, httpResponse.statusCode, this.request.isBinary() ? Buffer.concat(rawData) : rawData.join(''), httpResponse.headers);
}
});
return HTTP;
}(_gateway.Gateway);
exports.HTTP = HTTP;
var _default = HTTP;
exports["default"] = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
exports["default"] = exports.Mock = void 0;
var _gateway = _interopRequireDefault(require("../gateway"));
var _gateway = require("../gateway");
var _test = require("../test");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function Mock() {
_gateway["default"].apply(this, arguments);
}
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
Mock.prototype = _gateway["default"]["extends"]({
get: function get() {
this.callMock();
},
head: function head() {
this.callMock();
},
post: function post() {
this.callMock();
},
put: function put() {
this.callMock();
},
patch: function patch() {
this.callMock();
},
"delete": function _delete() {
this.callMock();
},
callMock: function callMock() {
var _this = this;
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
return (0, _test.lookupResponseAsync)(this.request).then(function (response) {
return _this.dispatchResponse(response);
})["catch"](function (e) {
return _this.dispatchClientError(e.message, e);
});
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var Mock = /*#__PURE__*/function (_Gateway) {
_inherits(Mock, _Gateway);
var _super = _createSuper(Mock);
function Mock() {
_classCallCheck(this, Mock);
return _super.apply(this, arguments);
}
});
_createClass(Mock, [{
key: "get",
value: function get() {
this.callMock();
}
}, {
key: "head",
value: function head() {
this.callMock();
}
}, {
key: "post",
value: function post() {
this.callMock();
}
}, {
key: "put",
value: function put() {
this.callMock();
}
}, {
key: "patch",
value: function patch() {
this.callMock();
}
}, {
key: "delete",
value: function _delete() {
this.callMock();
}
}, {
key: "callMock",
value: function callMock() {
var _this = this;
return (0, _test.lookupResponseAsync)(this.request).then(function (response) {
return _this.dispatchResponse(response);
})["catch"](function (e) {
return _this.dispatchClientError(e.message, e);
});
}
}]);
return Mock;
}(_gateway.Gateway);
exports.Mock = Mock;
var _default = Mock;
exports["default"] = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
exports["default"] = exports.XHR = void 0;
var _gateway = _interopRequireDefault(require("../gateway"));
var _gateway = require("../gateway");

@@ -18,142 +20,211 @@ var _response = _interopRequireDefault(require("../response"));

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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; }
var toBase64 = window.btoa || _utils.btoa;
function XHR() {
_gateway["default"].apply(this, arguments);
}
var XHR = /*#__PURE__*/function (_Gateway) {
_inherits(XHR, _Gateway);
XHR.prototype = _gateway["default"]["extends"]({
get: function get() {
var xmlHttpRequest = this.createXHR();
xmlHttpRequest.open('GET', this.request.url(), true);
this.setHeaders(xmlHttpRequest, {});
this.configureTimeout(xmlHttpRequest);
this.configureBinary(xmlHttpRequest);
xmlHttpRequest.send();
},
head: function head() {
var xmlHttpRequest = this.createXHR();
xmlHttpRequest.open('HEAD', this.request.url(), true);
this.setHeaders(xmlHttpRequest, {});
this.configureTimeout(xmlHttpRequest);
this.configureBinary(xmlHttpRequest);
xmlHttpRequest.send();
},
post: function post() {
this.performRequest('post');
},
put: function put() {
this.performRequest('put');
},
patch: function patch() {
this.performRequest('patch');
},
"delete": function _delete() {
this.performRequest('delete');
},
configureBinary: function configureBinary(xmlHttpRequest) {
if (this.request.isBinary()) {
xmlHttpRequest.responseType = 'blob';
var _super = _createSuper(XHR);
function XHR() {
var _this;
_classCallCheck(this, XHR);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
},
configureTimeout: function configureTimeout(xmlHttpRequest) {
var _this = this;
this.canceled = false;
this.timer = null;
var timeout = this.request.timeout();
_this = _super.call.apply(_super, [this].concat(args));
if (timeout) {
xmlHttpRequest.timeout = timeout;
xmlHttpRequest.addEventListener('timeout', function () {
_this.canceled = true;
clearTimeout(_this.timer);
var error = (0, _timeoutError.createTimeoutError)("Timeout (".concat(timeout, "ms)"));
_defineProperty(_assertThisInitialized(_this), "canceled", false);
_this.dispatchClientError(error.message, error);
}); // PhantomJS doesn't support timeout for XMLHttpRequest
_defineProperty(_assertThisInitialized(_this), "timer", void 0);
this.timer = setTimeout(function () {
_this.canceled = true;
var error = (0, _timeoutError.createTimeoutError)("Timeout (".concat(timeout, "ms)"));
return _this;
}
_this.dispatchClientError(error.message, error);
}, timeout + 1);
_createClass(XHR, [{
key: "get",
value: function get() {
var xmlHttpRequest = this.createXHR();
xmlHttpRequest.open('GET', this.request.url(), true);
this.setHeaders(xmlHttpRequest, {});
this.configureTimeout(xmlHttpRequest);
this.configureBinary(xmlHttpRequest);
xmlHttpRequest.send();
}
},
configureCallbacks: function configureCallbacks(xmlHttpRequest) {
var _this2 = this;
xmlHttpRequest.addEventListener('load', function () {
if (_this2.canceled) {
return;
}, {
key: "head",
value: function head() {
var xmlHttpRequest = this.createXHR();
xmlHttpRequest.open('HEAD', this.request.url(), true);
this.setHeaders(xmlHttpRequest, {});
this.configureTimeout(xmlHttpRequest);
this.configureBinary(xmlHttpRequest);
xmlHttpRequest.send();
}
}, {
key: "post",
value: function post() {
this.performRequest('post');
}
}, {
key: "put",
value: function put() {
this.performRequest('put');
}
}, {
key: "patch",
value: function patch() {
this.performRequest('patch');
}
}, {
key: "delete",
value: function _delete() {
this.performRequest('delete');
}
}, {
key: "configureBinary",
value: function configureBinary(xmlHttpRequest) {
if (this.request.isBinary()) {
xmlHttpRequest.responseType = 'blob';
}
}
}, {
key: "configureTimeout",
value: function configureTimeout(xmlHttpRequest) {
var _this2 = this;
clearTimeout(_this2.timer);
this.canceled = false;
this.timer = undefined;
var timeout = this.request.timeout();
_this2.dispatchResponse(_this2.createResponse(xmlHttpRequest));
});
xmlHttpRequest.addEventListener('error', function (e) {
if (_this2.canceled) {
return;
}
if (timeout) {
xmlHttpRequest.timeout = timeout;
xmlHttpRequest.addEventListener('timeout', function () {
_this2.canceled = true;
_this2.timer && clearTimeout(_this2.timer);
var error = (0, _timeoutError.createTimeoutError)("Timeout (".concat(timeout, "ms)"));
clearTimeout(_this2.timer);
var guessedErrorCause = e ? e.message || e.name : xmlHttpRequest.responseText;
var errorMessage = 'Network error';
var enhancedMessage = guessedErrorCause ? ": ".concat(guessedErrorCause) : '';
var error = new Error("".concat(errorMessage).concat(enhancedMessage));
_this2.dispatchClientError(error.message, error);
}); // PhantomJS doesn't support timeout for XMLHttpRequest
_this2.dispatchClientError(errorMessage, error);
});
var xhrOptions = this.options().XHR;
this.timer = setTimeout(function () {
_this2.canceled = true;
var error = (0, _timeoutError.createTimeoutError)("Timeout (".concat(timeout, "ms)"));
if (xhrOptions.withCredentials) {
xmlHttpRequest.withCredentials = true;
_this2.dispatchClientError(error.message, error);
}, timeout + 1);
}
}
}, {
key: "configureCallbacks",
value: function configureCallbacks(xmlHttpRequest) {
var _this3 = this;
if (xhrOptions.configure) {
xhrOptions.configure(xmlHttpRequest);
}
},
performRequest: function performRequest(method) {
var requestMethod = this.shouldEmulateHTTP() ? 'post' : method;
var xmlHttpRequest = this.createXHR();
xmlHttpRequest.open(requestMethod.toUpperCase(), this.request.url(), true);
var customHeaders = {};
var body = this.prepareBody(method, customHeaders);
this.setHeaders(xmlHttpRequest, customHeaders);
this.configureTimeout(xmlHttpRequest);
this.configureBinary(xmlHttpRequest);
var args = [];
body && args.push(body);
xmlHttpRequest.send.apply(xmlHttpRequest, args);
},
createResponse: function createResponse(xmlHttpRequest) {
var status = xmlHttpRequest.status;
var data = this.request.isBinary() ? xmlHttpRequest.response : xmlHttpRequest.responseText;
var responseHeaders = (0, _utils.parseResponseHeaders)(xmlHttpRequest.getAllResponseHeaders());
return new _response["default"](this.request, status, data, responseHeaders);
},
setHeaders: function setHeaders(xmlHttpRequest, customHeaders) {
var auth = this.request.auth();
xmlHttpRequest.addEventListener('load', function () {
if (_this3.canceled) {
return;
}
if (auth) {
var username = auth.username || '';
var password = auth.password || '';
customHeaders['authorization'] = "Basic ".concat(toBase64("".concat(username, ":").concat(password)));
_this3.timer && clearTimeout(_this3.timer);
_this3.dispatchResponse(_this3.createResponse(xmlHttpRequest));
});
xmlHttpRequest.addEventListener('error', function (e) {
if (_this3.canceled) {
return;
}
_this3.timer && clearTimeout(_this3.timer);
var guessedErrorCause = e ? // eslint-disable-next-line @typescript-eslint/no-explicit-any
e.message || e.name : xmlHttpRequest.responseText;
var errorMessage = 'Network error';
var enhancedMessage = guessedErrorCause ? ": ".concat(guessedErrorCause) : '';
var error = new Error("".concat(errorMessage).concat(enhancedMessage));
_this3.dispatchClientError(errorMessage, error);
});
var xhrOptions = this.options().XHR;
if (xhrOptions.withCredentials) {
xmlHttpRequest.withCredentials = true;
}
if (xhrOptions.configure) {
xhrOptions.configure(xmlHttpRequest);
}
}
}, {
key: "performRequest",
value: function performRequest(method) {
var requestMethod = this.shouldEmulateHTTP() ? 'post' : method;
var xmlHttpRequest = this.createXHR();
xmlHttpRequest.open(requestMethod.toUpperCase(), this.request.url(), true);
var customHeaders = {};
var body = this.prepareBody(method, customHeaders);
this.setHeaders(xmlHttpRequest, customHeaders);
this.configureTimeout(xmlHttpRequest);
this.configureBinary(xmlHttpRequest);
xmlHttpRequest.send(body);
}
}, {
key: "createResponse",
value: function createResponse(xmlHttpRequest) {
var status = xmlHttpRequest.status;
var data = this.request.isBinary() ? xmlHttpRequest.response : xmlHttpRequest.responseText;
var responseHeaders = (0, _utils.parseResponseHeaders)(xmlHttpRequest.getAllResponseHeaders());
return new _response["default"](this.request, status, data, responseHeaders);
}
}, {
key: "setHeaders",
value: function setHeaders(xmlHttpRequest, customHeaders) {
var auth = this.request.auth();
var headers = (0, _utils.assign)(customHeaders, _objectSpread(_objectSpread({}, this.request.headers()), auth ? {
authorization: "Basic ".concat(toBase64("".concat(auth.username, ":").concat(auth.password)))
} : {}));
Object.keys(headers).forEach(function (headerName) {
xmlHttpRequest.setRequestHeader(headerName, "".concat(headers[headerName]));
});
}
}, {
key: "createXHR",
value: function createXHR() {
var xmlHttpRequest = new XMLHttpRequest();
this.configureCallbacks(xmlHttpRequest);
return xmlHttpRequest;
}
}]);
var headers = (0, _utils.assign)(customHeaders, this.request.headers());
Object.keys(headers).forEach(function (headerName) {
xmlHttpRequest.setRequestHeader(headerName, headers[headerName]);
});
},
createXHR: function createXHR() {
var xmlHttpRequest = new XMLHttpRequest();
this.configureCallbacks(xmlHttpRequest);
return xmlHttpRequest;
}
});
return XHR;
}(_gateway.Gateway);
exports.XHR = XHR;
var _default = XHR;
exports["default"] = _default;
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {

@@ -20,12 +22,16 @@ value: true

var Version = _interopRequireWildcard(require("./version.json"));
var _response = require("./response");
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; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
/* global VERSION */
/**
* Can be used to test for `instanceof Response`
*/
var version = "2.37.1";
var version = Version.version;
exports.version = version;

@@ -142,7 +148,3 @@ var configs = {

};
/**
* @param {Object} manifest
*/
exports.setContext = setContext;

@@ -149,0 +151,0 @@

@@ -14,2 +14,4 @@ "use strict";

var _clone = require("../utils/clone");
var _mockUtils = require("./mock-utils");

@@ -78,3 +80,5 @@

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

@@ -81,0 +85,0 @@

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

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

"main": "index.js",
"types": "typings/index.d.ts",
"types": "index.d.ts",
"scripts": {

@@ -26,9 +26,12 @@ "integration-server": "node spec/integration/server.js",

"test": "yarn test:types && yarn prettier --check . && yarn lint && yarn test:unit",
"build:node": "rm -rf lib/* && yarn babel src -d lib --extensions '.js,.ts' --ignore '**/*.spec.ts','**/*.spec.js'",
"build:browser": "rm -rf dist/* && yarn webpack --config webpack.conf.js",
"build:types": "rm -rf typings/generated && yarn tsc --project tsconfig.build.json",
"build": "yarn build:types && yarn build:node && yarn build:browser",
"build:node": "yarn babel src -d lib/ --extensions '.js,.ts' --ignore '**/*.spec.ts','**/*.spec.js','**/*.d.ts'",
"build:browser": "yarn webpack --config webpack.conf.js",
"build:typings": "yarn tsc --project tsconfig.typings.json && yarn copy:dts",
"build": "yarn copy:version:src && yarn build:node && yarn build:typings && yarn build:browser",
"build:clean": "rm -rf lib/ dist/ && yarn build",
"release": "./scripts/release.sh",
"build:project": "./scripts/build-project.sh",
"lint": "yarn eslint \"{src,spec,typings}/**/*.[j|t]s\""
"copy:dts": "copyfiles -u 1 \"src/**/*.d.ts\" lib/",
"copy:version:src": "echo {\\\"version\\\":\\\"${npm_package_version}\\\"} > src/version.json",
"lint": "yarn eslint \"{src,spec}/**/*.[j|t]s\""
},

@@ -68,3 +71,2 @@ "repository": {

"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.0.0",

@@ -86,6 +88,8 @@ "@babel/preset-typescript": "^7.0.0",

"cookie-parser": "^1.4.5",
"copyfiles": "^2.4.1",
"core-js": "^3.21.1",
"cross-env": "^7.0.3",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^17.0.0-0",
"eslint-config-standard": "^17.0.0-1",
"eslint-plugin-import": "^2.24.2",

@@ -95,3 +99,2 @@ "eslint-plugin-n": "^14.0.0",

"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-standard": "^5.0.0",
"express": "^4.17.1",

@@ -108,3 +111,3 @@ "faux-jax-tulios": "^5.0.9",

"karma-spec-reporter": "^0.0.33",
"karma-webpack": "^4.0.0",
"karma-webpack": "<5.0.0",
"mockdate": "^3.0.5",

@@ -114,2 +117,3 @@ "multer": "^1.4.3",

"puppeteer": "^13.1.1",
"regenerator-runtime": "^0.13.9",
"ts-jest": "^27.0.0",

@@ -119,3 +123,3 @@ "ts-node": "^10.2.1",

"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^4.46.0",
"webpack": "<5.0.0",
"webpack-cli": "^4.8.0",

@@ -122,0 +126,0 @@ "whatwg-fetch": "^3.6.2"

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

}, {});
var queryString = (0, _utils.toQueryString)(aliasedParams);
var queryString = (0, _utils.toQueryString)(aliasedParams, this.methodDescriptor.parameterEncoder);

@@ -171,0 +171,0 @@ if (typeof queryString === 'string' && queryString.length !== 0) {

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