Socket
Socket
Sign inDemoInstall

mappersmith

Package Overview
Dependencies
Maintainers
1
Versions
120
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.27.2 to 2.28.0

mocks/mock-utils.js

39

gateway/http.js

@@ -82,5 +82,30 @@ "use strict";

if (httpOptions.onRequestWillStart) {
httpOptions.onRequestWillStart(requestParams);
}
var httpRequest = handler.request(requestParams, function (httpResponse) {
return _this.onResponse(httpResponse);
return _this.onResponse(httpResponse, httpOptions, 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) {

@@ -103,3 +128,3 @@ return _this.onError(e);

},
onResponse: function onResponse(httpResponse) {
onResponse: function onResponse(httpResponse, httpOptions, requestParams) {
var _this2 = this;

@@ -113,2 +138,7 @@

httpResponse.once('readable', function () {
if (httpOptions.onResponseReadable) {
httpOptions.onResponseReadable(requestParams);
}
});
httpResponse.on('data', function (chunk) {

@@ -123,2 +153,7 @@ return rawData.push(chunk);

});
httpResponse.on('end', function () {
if (httpOptions.onResponseEnd) {
httpOptions.onResponseEnd(requestParams);
}
});
},

@@ -125,0 +160,0 @@ onError: function onError(e) {

2

mappersmith.js

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

/* global VERSION */
var version = "2.27.2";
var version = "2.28.0";
exports.version = version;

@@ -19,0 +19,0 @@ var configs = {

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

var _mockUtils = require("./mock-utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -34,3 +36,3 @@

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

@@ -81,4 +83,4 @@ this.setResponseData(props.response.body);

isExactMatch: function isExactMatch(request) {
var bodyMatch = this.bodyFunction ? this.body(request.body()) : this.body === (0, _utils.toQueryString)(request.body());
var urlMatch = this.urlFunction ? this.url(request.url(), request.params()) : this.url === request.url();
var bodyMatch = this.bodyFunction ? this.body(request.body()) : this.body === (0, _mockUtils.toSortedQueryString)(request.body());
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;

@@ -85,0 +87,0 @@ },

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

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

@@ -1083,2 +1083,28 @@ [![npm version](https://badge.fury.io/js/mappersmith.svg)](http://badge.fury.io/js/mappersmith)

The HTTP gatewayConfigs also provides several callback functions that will be called when various events are emitted on the `request`, `socket`, and `response` EventEmitters. These callbacks can be used as a hook into the event cycle to execute any custom code.
For example, you may want to time how long each stage of the request or response takes.
These callback functions will receive the `requestParams` as the first argument.
The following callbacks are supported:
* `onRequestWillStart` - This callback is not based on a event emitted by Node but is called just before the `request` method is called.
* `onRequestSocketAssigned` - Called when the 'socket' event is emitted on the `request`
* `onSocketLookup` - Called when the `lookup` event is emitted on the `socket`
* `onSocketConnect` - Called when the `connect` event is emitted on the `socket`
* `onSocketSecureConnect` - Called when the `secureConnect` event is emitted on the `socket`
* `onResponseReadable` - Called when the `readable` event is emitted on the `response`
* `onResponseEnd` - Called when the `end` event is emitted on the `response`
```javascript
let startTime
configs.gatewayConfigs.HTTP = {
onRequestWillStart() {
startTime = Date.now()
}
onResponseReadable() {
console.log('Time to first byte', Date.now() - startTime)
}
}
```
### XHR

@@ -1085,0 +1111,0 @@

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

exports.isPlainObject = isPlainObject;
exports.btoa = exports.assign = void 0;
exports.btoa = exports.assign = exports.buildRecursive = exports.validKeys = void 0;

@@ -45,2 +45,4 @@ 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); }

exports.validKeys = validKeys;
var buildRecursive = function buildRecursive(key, value, suffix) {

@@ -66,2 +68,4 @@ suffix = suffix || '';

exports.buildRecursive = buildRecursive;
function toQueryString(entry) {

@@ -68,0 +72,0 @@ if (!isPlainObject(entry)) {

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc