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.30.1 to 2.31.0

2

gateway/fetch.js

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

body: body
}, this.options());
}, this.options().Fetch);
var timeout = this.request.timeout();

@@ -79,0 +79,0 @@ var timer = null;

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

/* global VERSION */
var version = "2.30.1";
var version = "2.31.0";
exports.version = version;

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

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

isExactMatch: function isExactMatch(request) {
var bodyMatch = this.bodyFunction ? this.body(request.body()) : this.body === (0, _mockUtils.toSortedQueryString)(request.body());
var _this = this;
var bodyMatch = function bodyMatch() {
return _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;
return this.method === request.method() && urlMatch && bodyMatch();
},

@@ -86,0 +91,0 @@

{
"name": "mappersmith",
"version": "2.30.1",
"version": "2.31.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>",

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

- [Optional arguments](#creating-middleware-optional-arguments)
- [mockRequest](#creating-middleware-optional-arguments-mock-request)
- [Abort](#creating-middleware-optional-arguments-abort)

@@ -126,2 +127,8 @@ - [Renew](#creating-middleware-optional-arguments-renew)

byGroup: { path: '/users/groups/{group}', params: { group: 'general' } }
// {market?} is an optional dynamic segment. If called without a value
// for the "market" parameter, {market?} will be removed from the path
// including any prefixing "/".
// This example: '/{market?}/users' => '/users'
count: { path: '/{market?}/users' } }
},

@@ -461,6 +468,6 @@ Blog: {

It can, optionally, receive `resourceName`, `resourceMethod`, [#context](`context`) and `clientId`. Example:
It can, optionally, receive `resourceName`, `resourceMethod`, [#context](`context`), `clientId` and `mockRequest`. Example:
```javascript
const MyMiddleware = ({ resourceName, resourceMethod, context, clientId }) => ({
const MyMiddleware = ({ resourceName, resourceMethod, context, clientId, mockRequest }) => ({
/* ... */

@@ -474,4 +481,23 @@ })

// context: {}
// mockRequest: false
```
##### <a name="creating-middleware-optional-arguments-mock-request"></a> mockRequest
Before mocked clients can assert whether or not their mock definition matches a request they have to execute their middleware on that request. This means that middleware might be executed multiple times for the same request. More specifically, the middleware will be executed once per mocked client that utilises the middleware until a mocked client with a matching definition is found. If you want to avoid middleware from being called multiple times you can use the optional "mockRequest" boolean flag. The value of this flag will be truthy whenever the middleware is being executed during the mock definition matching phase. Otherwise its value will be falsy. Example:
```javascript
const MyMiddleware = ({ mockRequest }) => {
prepareRequest(next) {
if (mockRequest) {
... // executed once for each mocked client that utilises the middleware
}
if (!mockRequest) {
... // executed once for the matching mock definition
}
return next().then(request => request)
}
}
```
##### <a name="creating-middleware-optional-arguments-abort"></a> Abort

@@ -478,0 +504,0 @@

@@ -10,3 +10,4 @@ "use strict";

var REGEXP_DYNAMIC_SEGMENT = /{([^}]+)}/;
var REGEXP_DYNAMIC_SEGMENT = /{([^}?]+)\??}/;
var REGEXP_OPTIONAL_DYNAMIC_SEGMENT = /\/?{([^}?]+)\?}/g;
var REGEXP_TRAILING_SLASH = /\/$/;

@@ -86,12 +87,18 @@ /**

var params = this.params();
Object.keys(params).forEach(function (key) {
var value = params[key];
var pattern = "{".concat(key, "}");
var params = this.params(); // RegExp with 'g'-flag is stateful, therefore defining it locally
if (new RegExp(pattern).test(path)) {
path = path.replace("{".concat(key, "}"), encodeURIComponent(value));
var regexp = new RegExp(REGEXP_DYNAMIC_SEGMENT, 'g');
var match;
while ((match = regexp.exec(path)) !== null) {
var key = match[1];
var pattern = new RegExp("{".concat(key, "\\??}"), 'g');
if (key in params) {
path = path.replace(pattern, encodeURIComponent(params[key]));
delete params[key];
}
});
}
path = path.replace(REGEXP_OPTIONAL_DYNAMIC_SEGMENT, '');
var missingDynamicSegmentMatch = path.match(REGEXP_DYNAMIC_SEGMENT);

@@ -98,0 +105,0 @@

@@ -23,3 +23,3 @@ // @deprecated: Version 1 of retry is deprecated and should not be used anymore

export default function Retry(config: Partial<RetryMiddlewareOptions>): Middleware
export default function Retry(config?: Partial<RetryMiddlewareOptions>): Middleware
}

@@ -14,10 +14,13 @@ declare module 'mappersmith/test' {

export interface MockClient<ResourcesType> {
resource(name: keyof ResourcesType): MockClient<ResourcesType>
method(name: keyof ResourcesType[keyof ResourcesType]): MockClient<ResourcesType>
with(args: Partial<Parameters>): MockClient<ResourcesType>
status(responder: StatusHandler | number): MockClient<ResourcesType>
response(responder: ResponseHandler | object | string): MockClient<ResourcesType>
assertObject(): MockAssert
assertObjectAsync(): Promise<MockAssert>
export interface MockClient<
ResourcesType,
ResourceName extends keyof ResourcesType
> {
resource<ResourceName extends keyof ResourcesType>(name: ResourceName): MockClient<ResourcesType, ResourceName>;
method(name: keyof ResourcesType[ResourceName]): this;
with(args: Partial<Parameters>): this;
status(responder: StatusHandler | number): this;
response(responder: ResponseHandler | object | string): this;
assertObject(): MockAssert;
assertObjectAsync(): Promise<MockAssert>;
}

@@ -28,3 +31,3 @@

export function uninstall(): void
export function mockClient<ResourcesType>(client: Client<ResourcesType>): MockClient<ResourcesType>
export function mockClient<ResourcesType, ResourceName extends keyof ResourcesType = keyof ResourcesType>(client: Client<ResourcesType>): MockClient<ResourcesType, ResourceName>

@@ -36,3 +39,3 @@ export type MockRequestUrlFunction = (requestUrl: string, params: object) => string

method: string
url: string | MockRequestUrlFunction
url: string | MockRequestUrlFunction | TestMatchPredicate
body?: MockRequestBody | MockRequestBodyFunction

@@ -48,7 +51,8 @@ response?: {

export type TestMatchPredicate = (value: string) => boolean;
export interface TestMatchFunctions {
stringMatching(value: RegExp): (value: string) => boolean
stringContaining(value: string): (value: string) => boolean
uuid4(): (value: string) => boolean
anything(): () => true
stringMatching(value: RegExp): TestMatchPredicate
stringContaining(value: string): TestMatchPredicate
uuid4(): TestMatchPredicate
anything(): TestMatchPredicate
}

@@ -58,1 +62,2 @@

}
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