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.43.0-beta.0 to 2.43.0-beta.1

esm/index-723c3754.d.ts

3

gateway/fetch.d.ts
/// <reference types="node" />
import { Gateway, Method } from './index';
import { Gateway } from './gateway';
import Response from '../response';
import type { Method } from './types';
/**

@@ -5,0 +6,0 @@ * Gateway which uses the "fetch" implementation configured in "configs.fetch".

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

module.exports = __toCommonJS(fetch_exports);
var import_index = require("./index");
var import_gateway = require("./gateway");
var import_response = __toESM(require("../response"));

@@ -41,3 +41,3 @@ var import_mappersmith = require("../mappersmith");

var import_timeout_error = require("./timeout-error");
class Fetch extends import_index.Gateway {
class Fetch extends import_gateway.Gateway {
get() {

@@ -44,0 +44,0 @@ this.performRequest("get");

@@ -5,3 +5,2 @@ import { Request } from '../request';

import type { Primitive } from '../types';
export type Method = 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete';
export declare class Gateway {

@@ -8,0 +7,0 @@ request: Request;

/// <reference types="node" />
import * as http from 'http';
import { Gateway, Method } from './index';
import type { HTTPGatewayConfiguration, HTTPRequestParams } from './types';
import { Gateway } from './gateway';
import type { Method, HTTPGatewayConfiguration, HTTPRequestParams } from './types';
import Response from '../response';

@@ -6,0 +6,0 @@ type Chunk = any;

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

var import_utils = require("../utils/index");
var import_index = require("./index");
var import_gateway = require("./gateway");
var import_response = __toESM(require("../response"));
var import_timeout_error = require("./timeout-error");
class HTTP extends import_index.Gateway {
class HTTP extends import_gateway.Gateway {
canceled = false;

@@ -45,0 +45,0 @@ get() {

@@ -1,25 +0,9 @@

import { Request } from '../request';
import { Response } from '../response';
import { GatewayConfiguration } from '../gateway/types';
import type { Primitive } from '../types';
export type Method = 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete';
export declare class Gateway {
request: Request;
configs: GatewayConfiguration;
successCallback: (res: Response) => void;
failCallback: (res: Response) => void;
constructor(request: Request, configs: GatewayConfiguration);
get(): void;
head(): void;
post(): void;
put(): void;
patch(): void;
delete(): void;
options(): GatewayConfiguration;
shouldEmulateHTTP(): boolean;
call(): Promise<any>;
dispatchResponse(response: Response): void;
dispatchClientError(message: string, error: Error): void;
prepareBody(method: string, headers: Record<string, Primitive>): Primitive | null | undefined;
}
import { Gateway } from './gateway';
export { Fetch as FetchGateway } from './fetch';
export { HTTP as HTTPGateway } from './http';
export { Mock as MockGateway } from './mock';
export { isTimeoutError, createTimeoutError } from './timeout-error';
export { XHR as XHRGateway } from './xhr';
export type { HTTPRequestParams, HTTPGatewayConfiguration, GatewayConfiguration } from './types';
export default Gateway;
export { Gateway };

@@ -21,104 +21,29 @@ "use strict";

__export(gateway_exports, {
Gateway: () => Gateway,
default: () => gateway_default
FetchGateway: () => import_fetch.Fetch,
Gateway: () => import_gateway.Gateway,
HTTPGateway: () => import_http.HTTP,
MockGateway: () => import_mock.Mock,
XHRGateway: () => import_xhr.XHR,
createTimeoutError: () => import_timeout_error.createTimeoutError,
default: () => gateway_default,
isTimeoutError: () => import_timeout_error.isTimeoutError
});
module.exports = __toCommonJS(gateway_exports);
var import_utils = require("../utils/index");
var import_mappersmith = require("../mappersmith");
var import_response = require("../response");
var import_timeout_error = require("../gateway/timeout-error");
const REGEXP_EMULATE_HTTP = /^(delete|put|patch)/i;
class Gateway {
request;
configs;
successCallback;
failCallback;
constructor(request, configs) {
this.request = request;
this.configs = configs;
this.successCallback = function() {
return void 0;
};
this.failCallback = function() {
return void 0;
};
}
get() {
throw new Error("Not implemented");
}
head() {
throw new Error("Not implemented");
}
post() {
throw new Error("Not implemented");
}
put() {
throw new Error("Not implemented");
}
patch() {
throw new Error("Not implemented");
}
delete() {
throw new Error("Not implemented");
}
options() {
return this.configs;
}
shouldEmulateHTTP() {
return this.options().emulateHTTP && REGEXP_EMULATE_HTTP.test(this.request.method());
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
call() {
const timeStart = (0, import_utils.performanceNow)();
if (!import_mappersmith.configs.Promise) {
throw new Error("[Mappersmith] Promise not configured (configs.Promise)");
}
return new import_mappersmith.configs.Promise((resolve, reject) => {
this.successCallback = (response) => {
response.timeElapsed = (0, import_utils.performanceNow)() - timeStart;
resolve(response);
};
this.failCallback = (response) => {
response.timeElapsed = (0, import_utils.performanceNow)() - timeStart;
reject(response);
};
try {
this[this.request.method()].apply(this, arguments);
} catch (e) {
const err = e;
this.dispatchClientError(err.message, err);
}
});
}
dispatchResponse(response) {
response.success() ? this.successCallback(response) : this.failCallback(response);
}
dispatchClientError(message, error) {
if ((0, import_timeout_error.isTimeoutError)(error) && this.options().enableHTTP408OnTimeouts) {
this.failCallback(new import_response.Response(this.request, 408, message, {}, [error]));
} else {
this.failCallback(new import_response.Response(this.request, 400, message, {}, [error]));
}
}
prepareBody(method, headers) {
let body = this.request.body();
if (this.shouldEmulateHTTP()) {
body = body || {};
(0, import_utils.isPlainObject)(body) && (body["_method"] = method);
headers["x-http-method-override"] = method;
}
const bodyString = (0, import_utils.toQueryString)(body);
if (bodyString) {
if ((0, import_utils.isPlainObject)(body)) {
headers["content-type"] = "application/x-www-form-urlencoded;charset=utf-8";
}
}
return bodyString;
}
}
var gateway_default = Gateway;
var import_gateway = require("./gateway");
var import_fetch = require("./fetch");
var import_http = require("./http");
var import_mock = require("./mock");
var import_timeout_error = require("./timeout-error");
var import_xhr = require("./xhr");
var gateway_default = import_gateway.Gateway;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Gateway
FetchGateway,
Gateway,
HTTPGateway,
MockGateway,
XHRGateway,
createTimeoutError,
isTimeoutError
});
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import { Gateway } from './index';
import { Gateway } from './gateway';
export declare class Mock extends Gateway {

@@ -3,0 +3,0 @@ get(): void;

@@ -25,5 +25,5 @@ "use strict";

module.exports = __toCommonJS(mock_exports);
var import_index = require("./index");
var import_gateway = require("./gateway");
var import_test = require("../test/index");
class Mock extends import_index.Gateway {
class Mock extends import_gateway.Gateway {
get() {

@@ -30,0 +30,0 @@ this.callMock();

@@ -0,1 +1,2 @@

export type Method = 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete';
export interface HTTPRequestParams {

@@ -2,0 +3,0 @@ [key: string]: any;

@@ -1,3 +0,4 @@

import { Gateway, Method } from './index';
import { Gateway } from './gateway';
import Response from '../response';
import type { Method } from './types';
import type { Headers } from '../types';

@@ -4,0 +5,0 @@ export declare class XHR extends Gateway {

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

module.exports = __toCommonJS(xhr_exports);
var import_index = require("./index");
var import_gateway = require("./gateway");
var import_response = __toESM(require("../response"));

@@ -46,3 +46,3 @@ var import_utils = require("../utils/index");

}
class XHR extends import_index.Gateway {
class XHR extends import_gateway.Gateway {
canceled = false;

@@ -49,0 +49,0 @@ timer;

@@ -0,1 +1,2 @@

import { configs } from './mappersmith';
import type { GlobalConfigs, ManifestOptions, ResourceTypeConstraint } from './manifest';

@@ -23,2 +24,3 @@ export type { GlobalConfigs, ManifestOptions, ResourceTypeConstraint };

export type Configuration = GlobalConfigs;
export { default, version, configs, setContext } from './mappersmith';
export { forge as default, forge, version, setContext } from './mappersmith';
export { configs };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -20,10 +18,2 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

@@ -34,14 +24,14 @@ var src_exports = {};

configs: () => import_mappersmith.configs,
default: () => import_mappersmith.default,
setContext: () => import_mappersmith.setContext,
version: () => import_mappersmith.version
default: () => import_mappersmith2.forge,
forge: () => import_mappersmith2.forge,
setContext: () => import_mappersmith2.setContext,
version: () => import_mappersmith2.version
});
module.exports = __toCommonJS(src_exports);
var lib = __toESM(require("./mappersmith"));
var import_xhr = __toESM(require("./gateway/xhr"));
var import_http = __toESM(require("./gateway/http"));
var import_fetch = __toESM(require("./gateway/fetch"));
var import_mappersmith = require("./mappersmith");
var import_xhr = require("./gateway/xhr");
var import_http = require("./gateway/http");
var import_fetch = require("./gateway/fetch");
var import_response = require("./response");
var import_mappersmith = __toESM(require("./mappersmith"));
const { configs } = lib;
var import_mappersmith2 = require("./mappersmith");
let _process = null;

@@ -56,9 +46,9 @@ let defaultGateway = null;

if (typeof XMLHttpRequest !== "undefined") {
defaultGateway = import_xhr.default;
defaultGateway = import_xhr.XHR;
} else if (typeof _process !== "undefined") {
defaultGateway = import_http.default;
defaultGateway = import_http.HTTP;
} else if (typeof self !== "undefined") {
defaultGateway = import_fetch.default;
defaultGateway = import_fetch.Fetch;
}
configs.gateway = defaultGateway;
import_mappersmith.configs.gateway = defaultGateway;
// Annotate the CommonJS export names for ESM import in node:

@@ -68,2 +58,3 @@ 0 && (module.exports = {

configs,
forge,
setContext,

@@ -70,0 +61,0 @@ version

@@ -16,1 +16,2 @@ import { Client } from './client-builder';

export default function forge<Resources extends ResourceTypeConstraint>(manifest: ManifestOptions<Resources>): Client<Resources>;
export { forge };
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;

@@ -20,10 +18,2 @@ var __export = (target, all) => {

};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

@@ -35,2 +25,3 @@ var mappersmith_exports = {};

default: () => forge,
forge: () => forge,
setContext: () => setContext,

@@ -40,3 +31,3 @@ version: () => import_version.version

module.exports = __toCommonJS(mappersmith_exports);
var import_client_builder = __toESM(require("./client-builder"));
var import_client_builder = require("./client-builder");
var import_utils = require("./utils/index");

@@ -148,3 +139,3 @@ var import_response = require("./response");

const GatewayClassFactory = () => configs.gateway;
return new import_client_builder.default(manifest, GatewayClassFactory, configs).build();
return new import_client_builder.ClientBuilder(manifest, GatewayClassFactory, configs).build();
}

@@ -155,2 +146,3 @@ // Annotate the CommonJS export names for ESM import in node:

configs,
forge,
setContext,

@@ -157,0 +149,0 @@ version

@@ -16,3 +16,3 @@ import type { Auth } from '../types';

*/
declare const _default: (authConfig: Auth) => Middleware;
export default _default;
export declare const BasicAuthMiddleware: (authConfig: Auth) => Middleware;
export default BasicAuthMiddleware;

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

__export(basic_auth_exports, {
BasicAuthMiddleware: () => BasicAuthMiddleware,
default: () => basic_auth_default

@@ -26,3 +27,3 @@ });

var import_utils = require("../utils/index");
var basic_auth_default = (authConfig) => function BasicAuthMiddleware() {
const BasicAuthMiddleware = (authConfig) => function BasicAuthMiddleware2() {
return {

@@ -36,2 +37,7 @@ async prepareRequest(next) {

};
var basic_auth_default = BasicAuthMiddleware;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BasicAuthMiddleware
});
//# sourceMappingURL=basic-auth.js.map

@@ -5,3 +5,3 @@ import type { Middleware } from './index';

*/
declare const _default: (cookieName?: string, headerName?: string) => Middleware;
export default _default;
export declare const CsrfMiddleware: (cookieName?: string, headerName?: string) => Middleware;
export default CsrfMiddleware;

@@ -21,6 +21,7 @@ "use strict";

__export(csrf_exports, {
CsrfMiddleware: () => CsrfMiddleware,
default: () => csrf_default
});
module.exports = __toCommonJS(csrf_exports);
var csrf_default = (cookieName = "csrfToken", headerName = "x-csrf-token") => function CsrfMiddleware() {
const CsrfMiddleware = (cookieName = "csrfToken", headerName = "x-csrf-token") => function CsrfMiddleware2() {
const REGEXP_COOKIE_NAME = new RegExp(cookieName + "[^;]+");

@@ -44,2 +45,7 @@ const getCookie = () => {

};
var csrf_default = CsrfMiddleware;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CsrfMiddleware
});
//# sourceMappingURL=csrf.js.map

@@ -5,3 +5,3 @@ import type { Middleware } from './index';

*/
declare const DurationMiddleware: Middleware;
export declare const DurationMiddleware: Middleware;
export default DurationMiddleware;

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

__export(duration_exports, {
DurationMiddleware: () => DurationMiddleware,
default: () => duration_default

@@ -49,2 +50,6 @@ });

var duration_default = DurationMiddleware;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
DurationMiddleware
});
//# sourceMappingURL=duration.js.map

@@ -11,3 +11,3 @@ import type { Middleware } from './index';

*/
declare const EncodeJsonMiddleware: Middleware;
export declare const EncodeJsonMiddleware: Middleware;
export default EncodeJsonMiddleware;

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

CONTENT_TYPE_JSON: () => CONTENT_TYPE_JSON,
EncodeJsonMiddleware: () => EncodeJsonMiddleware,
default: () => encode_json_default

@@ -52,4 +53,5 @@ });

0 && (module.exports = {
CONTENT_TYPE_JSON
CONTENT_TYPE_JSON,
EncodeJsonMiddleware
});
//# sourceMappingURL=encode-json.js.map

@@ -9,3 +9,3 @@ import type { Response } from '../response';

*/
declare const GlobalErrorHandlerMiddleware: Middleware;
export declare const GlobalErrorHandlerMiddleware: Middleware;
export default GlobalErrorHandlerMiddleware;

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

__export(global_error_handler_exports, {
GlobalErrorHandlerMiddleware: () => GlobalErrorHandlerMiddleware,
default: () => global_error_handler_default,

@@ -48,4 +49,5 @@ setErrorHandler: () => setErrorHandler

0 && (module.exports = {
GlobalErrorHandlerMiddleware,
setErrorHandler
});
//# sourceMappingURL=global-error-handler.js.map

@@ -1,25 +0,19 @@

import type { Request } from '../request'
import type { Response } from '../response'
export type Context = object
export type RequestGetter = () => Promise<Request>
export type ResponseGetter = () => Promise<Response>
export type AbortFn = (error: Error) => void
export type RenewFn = () => Promise<Response>
import type { Request } from '../request';
import type { Response } from '../response';
export type Context = object;
export type RequestGetter = () => Promise<Request>;
export type ResponseGetter = () => Promise<Response>;
export type AbortFn = (error: Error) => void;
export type RenewFn = () => Promise<Response>;
export interface MiddlewareDescriptor {
__name?: string
/**
* @deprecated: Use prepareRequest
*/
request?(request: Request): Promise<Request> | Request
/**
* Allows a middleware to tap into the prepare request phase
*/
prepareRequest(
__name?: string;
/**
* @deprecated: Use prepareRequest
*/
request?(request: Request): Promise<Request> | Request;
/**
* Allows a middleware to tap into the prepare request phase
*/
prepareRequest(
/**
* This function must return a `Promise` resolving the `Request`.

@@ -29,13 +23,12 @@ *

*/
next: RequestGetter,
next: RequestGetter,
/**
* Function that can be used to abort the middleware execution early on and throw a custom error to the user.
*/
abort: AbortFn
): Promise<Request | void>
/**
* Allows a middleware to tap into the response phase
*/
response(
abort: AbortFn): Promise<Request | void>;
/**
* Allows a middleware to tap into the response phase
*/
response(
/**
* This function must return a `Promise` resolving the `Response`.

@@ -45,3 +38,3 @@ *

*/
next: ResponseGetter,
next: ResponseGetter,
/**

@@ -52,3 +45,3 @@ * Function that is used to rerun the middleware stack.

*/
renew: RenewFn,
renew: RenewFn,
/**

@@ -59,17 +52,12 @@ * The final request object (after the whole middleware chain has prepared and all `prepareRequest` been executed).

*/
request: Request
): Promise<Response>
request: Request): Promise<Response>;
}
export interface MiddlewareParams {
readonly clientId: string | null
readonly context: Context
readonly resourceMethod: string
readonly resourceName: string
readonly mockRequest?: boolean
readonly clientId: string | null;
readonly context: Context;
readonly resourceMethod: string;
readonly resourceName: string;
readonly mockRequest?: boolean;
}
// eslint-disable-next-line @typescript-eslint/ban-types
type DefaultPrivateProps = {}
type DefaultPrivateProps = {};
/**

@@ -81,4 +69,10 @@ * Mappersmith middleware, used to describe a factory function that given MiddlewareParams

*/
export type Middleware<PrivateProps extends Record<string, unknown> = DefaultPrivateProps> = (
params: MiddlewareParams
) => Partial<MiddlewareDescriptor & PrivateProps>
export type Middleware<PrivateProps extends Record<string, unknown> = DefaultPrivateProps> = (params: MiddlewareParams) => Partial<MiddlewareDescriptor & PrivateProps>;
export { BasicAuthMiddleware } from './basic-auth';
export { RetryMiddleware } from './retry/v2/index';
export { CsrfMiddleware } from './csrf';
export { DurationMiddleware } from './duration';
export { EncodeJsonMiddleware } from './encode-json';
export { GlobalErrorHandlerMiddleware } from './global-error-handler';
export { LogMiddleware } from './log';
export { TimeoutMiddleware } from './timeout';

@@ -10,3 +10,3 @@ import type { Middleware } from './index';

*/
declare const ConsoleLogMiddleware: Middleware;
export default ConsoleLogMiddleware;
export declare const LogMiddleware: Middleware;
export default LogMiddleware;

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

__export(log_exports, {
LogMiddleware: () => LogMiddleware,
default: () => log_default,

@@ -63,3 +64,3 @@ defaultErrorLogger: () => defaultErrorLogger,

};
const ConsoleLogMiddleware = () => ({
const LogMiddleware = () => ({
async prepareRequest(next) {

@@ -83,5 +84,6 @@ const request = await next();

});
var log_default = ConsoleLogMiddleware;
var log_default = LogMiddleware;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
LogMiddleware,
defaultErrorLogger,

@@ -88,0 +90,0 @@ defaultSuccessLogger,

@@ -15,3 +15,3 @@ import type { Middleware } from '../../index';

export declare const defaultRetryConfigs: RetryMiddlewareOptions;
type RetryMiddleware = Middleware<{
type RetryMiddlewareType = Middleware<{
enableRetry: boolean;

@@ -42,4 +42,4 @@ inboundRequest: Request;

*/
declare const _default: (customConfigs?: Partial<RetryMiddlewareOptions>) => RetryMiddleware;
export default _default;
export declare const RetryMiddleware: (customConfigs?: Partial<RetryMiddlewareOptions>) => RetryMiddlewareType;
export default RetryMiddleware;
/**

@@ -46,0 +46,0 @@ * Increases the retry time for each attempt using a randomization function that grows exponentially.

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

__export(v2_exports, {
RetryMiddleware: () => RetryMiddleware,
calculateExponentialRetryTime: () => calculateExponentialRetryTime,

@@ -44,3 +45,3 @@ default: () => v2_default,

};
var v2_default = (customConfigs = {}) => function RetryMiddleware() {
const RetryMiddleware = (customConfigs = {}) => function RetryMiddleware2() {
return {

@@ -76,2 +77,3 @@ request(request) {

};
var v2_default = RetryMiddleware;
const retriableRequest = (resolve, reject, next, request) => {

@@ -157,2 +159,3 @@ const retry = (retryTime, retryCount, retryConfigs) => {

0 && (module.exports = {
RetryMiddleware,
calculateExponentialRetryTime,

@@ -159,0 +162,0 @@ defaultRetryConfigs

@@ -15,3 +15,3 @@ import type { Middleware } from './index';

*/
declare const _default: (timeoutValue: Milliseconds) => Middleware;
export default _default;
export declare const TimeoutMiddleware: (timeoutValue: Milliseconds) => Middleware;
export default TimeoutMiddleware;

@@ -21,6 +21,7 @@ "use strict";

__export(timeout_exports, {
TimeoutMiddleware: () => TimeoutMiddleware,
default: () => timeout_default
});
module.exports = __toCommonJS(timeout_exports);
var timeout_default = (timeoutValue) => function TimeoutMiddleware() {
const TimeoutMiddleware = (timeoutValue) => function TimeoutMiddleware2() {
return {

@@ -34,2 +35,7 @@ async prepareRequest(next) {

};
var timeout_default = TimeoutMiddleware;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
TimeoutMiddleware
});
//# sourceMappingURL=timeout.js.map
{
"name": "mappersmith",
"version": "2.43.0-beta.0",
"version": "2.43.0-beta.1",
"description": "It is a lightweight rest client for node.js and the browser",

@@ -22,2 +22,6 @@ "author": "Tulio Ornelas <ornelas.tulio@gmail.com>",

},
"./gateway": {
"import": "./esm/gateway/index.mjs",
"require": "./gateway/index.js"
},
"./gateway/fetch": {

@@ -43,2 +47,6 @@ "import": "./esm/gateway/fetch.mjs",

},
"./middleware": {
"import": "./esm/middleware/index.mjs",
"require": "./middleware/index.js"
},
"./middleware/basic-auth": {

@@ -45,0 +53,0 @@ "import": "./esm/middleware/basic-auth.mjs",

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

```javascript
import forge, { configs } from 'mappersmith'
import { forge, configs } from 'mappersmith'

@@ -699,3 +699,3 @@ configs.middleware = [MyMiddleware]

```javascript
import BasicAuthMiddleware from 'mappersmith/middleware/basic-auth'
import { BasicAuthMiddleware } from 'mappersmith/middleware'
const BasicAuth = BasicAuthMiddleware({ username: 'bob', password: 'bob' })

@@ -725,6 +725,6 @@

```javascript
import CSRF from 'mappersmith/middleware/csrf'
import { CsrfMiddleware } from 'mappersmith/middleware'
const client = forge({
middleware: [ CSRF('csrfToken', 'x-csrf-token') ],
middleware: [ CsrfMiddleware('csrfToken', 'x-csrf-token') ],
/* ... */

@@ -741,6 +741,6 @@ })

```javascript
import Duration from 'mappersmith/middleware/duration'
import { DurationMiddleware } from 'mappersmith/middleware'
const client = forge({
middleware: [ Duration ],
middleware: [ DurationMiddleware ],
/* ... */

@@ -758,6 +758,6 @@ })

```javascript
import EncodeJson from 'mappersmith/middleware/encode-json'
import { EncodeJsonMiddleware } from 'mappersmith/middleware'
const client = forge({
middleware: [ EncodeJson ],
middleware: [ EncodeJsonMiddleware ],
/* ... */

@@ -776,3 +776,3 @@ })

```javascript
import GlobalErrorHandler, { setErrorHandler } from 'mappersmith/middleware/global-error-handler'
import { GlobalErrorHandlerMiddleware, setErrorHandler } from 'mappersmith/middleware'

@@ -785,3 +785,3 @@ setErrorHandler((response) => {

const client = forge({
middleware: [ GlobalErrorHandler ],
middleware: [ GlobalErrorHandlerMiddleware ],
/* ... */

@@ -809,6 +809,6 @@ })

```javascript
import Log from 'mappersmith/middleware/log'
import { LogMiddleware } from 'mappersmith/middleware'
const client = forge({
middleware: [ Log ],
middleware: [ LogMiddleware ],
/* ... */

@@ -822,4 +822,2 @@ })

##### v2
It's possible to configure the header names and parameters used in the calculation by providing a configuration object when creating the middleware.

@@ -830,3 +828,3 @@

```javascript
import Retry from 'mappersmith/middleware/retry/v2'
import { RetryMiddleware } from 'mappersmith/middleware'

@@ -850,33 +848,2 @@ const retryConfigs = {

##### v1 (deprecated)
The v1 retry middleware is now deprecated as it relies on global configuration which can cause issues if you need to have multiple different configurations.
```javascript
import Retry from 'mappersmith/middleware/retry'
const client = forge({
middleware: [ Retry ],
/* ... */
})
```
It's possible to configure the header names and parameters used in the calculation by calling the deprecated setRetryConfigs method.
```javascript
import { setRetryConfigs } from 'mappersmith/middleware/retry'
// Using the default values as an example
setRetryConfigs({
headerRetryCount: 'X-Mappersmith-Retry-Count',
headerRetryTime: 'X-Mappersmith-Retry-Time',
maxRetryTimeInSecs: 5,
initialRetryTimeInSecs: 0.1,
factor: 0.2, // randomization factor
multiplier: 2, // exponential factor
retries: 5, // max retries
validateRetry: (response) => response.responseStatus >= 500 // a function that returns true if the request should be retried
})
```
#### <a name="middleware-timeout"></a> Timeout

@@ -887,3 +854,3 @@

```javascript
import TimeoutMiddleware from 'mappersmith/middleware/timeout'
import { TimeoutMiddleware } from 'mappersmith/middleware'
const Timeout = TimeoutMiddleware(500)

@@ -983,3 +950,3 @@

```javascript
import forge from 'mappersmith'
import { forge } from 'mappersmith'
import { install, uninstall, mockClient } from 'mappersmith/test'

@@ -1112,3 +1079,3 @@

```javascript
import forge from 'mappersmith'
import { forge } from 'mappersmith'
import { install, uninstall, mockRequest } from 'mappersmith/test'

@@ -1326,3 +1293,3 @@

```javascript
import FetchGateway from 'mappersmith/gateway/fetch'
import { FetchGateway } from 'mappersmith/gateway'
import { configs } from 'mappersmith'

@@ -1349,3 +1316,3 @@

```typescript
import { Middleware } from 'mappersmith'
import type { Middleware } from 'mappersmith'

@@ -1372,3 +1339,3 @@ const MyMiddleware: Middleware = () => ({

```typescript
import forge from 'mappersmith'
import { forge } from 'mappersmith'
import { mockClient } from 'mappersmith/test'

@@ -1375,0 +1342,0 @@

import { ClientBuilder } from './client-builder'
import { Manifest, GlobalConfigs } from './manifest'
import { GatewayConfiguration } from './gateway/types'
import type { GatewayConfiguration } from './gateway/types'
import { Gateway } from './gateway/index'

@@ -5,0 +5,0 @@ import Request from './request'

@@ -1,2 +0,2 @@

import { Gateway, Method } from './index'
import { Gateway } from './gateway'
import Response from '../response'

@@ -7,2 +7,3 @@ import { configs } from '../mappersmith'

import { createTimeoutError } from './timeout-error'
import type { Method } from './types'

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

@@ -11,4 +11,2 @@ import { performanceNow, toQueryString, isPlainObject } from '../utils/index'

export type Method = 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete'
export class Gateway {

@@ -15,0 +13,0 @@ public request: Request

@@ -6,4 +6,4 @@ import * as url from 'url'

import { assign } from '../utils/index'
import { Gateway, Method } from './index'
import type { HTTPGatewayConfiguration, HTTPRequestParams } from './types'
import { Gateway } from './gateway'
import type { Method, HTTPGatewayConfiguration, HTTPRequestParams } from './types'
import Response from '../response'

@@ -10,0 +10,0 @@ import { createTimeoutError } from './timeout-error'

@@ -1,126 +0,9 @@

import { performanceNow, toQueryString, isPlainObject } from '../utils/index'
import { configs as defaultConfigs } from '../mappersmith'
import { Request } from '../request'
import { Response } from '../response'
import { isTimeoutError } from '../gateway/timeout-error'
import { GatewayConfiguration } from '../gateway/types'
import type { Primitive } from '../types'
const REGEXP_EMULATE_HTTP = /^(delete|put|patch)/i
export type Method = 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete'
export class Gateway {
public request: Request
public configs: GatewayConfiguration
public successCallback: (res: Response) => void
public failCallback: (res: Response) => void
constructor(request: Request, configs: GatewayConfiguration) {
this.request = request
this.configs = configs
this.successCallback = function () {
return undefined
}
this.failCallback = function () {
return undefined
}
}
public get() {
throw new Error('Not implemented')
}
public head() {
throw new Error('Not implemented')
}
public post() {
throw new Error('Not implemented')
}
public put() {
throw new Error('Not implemented')
}
public patch() {
throw new Error('Not implemented')
}
public delete() {
throw new Error('Not implemented')
}
options() {
return this.configs
}
shouldEmulateHTTP() {
return this.options().emulateHTTP && REGEXP_EMULATE_HTTP.test(this.request.method())
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
call(): Promise<any> {
const timeStart = performanceNow()
if (!defaultConfigs.Promise) {
throw new Error('[Mappersmith] Promise not configured (configs.Promise)')
}
return new defaultConfigs.Promise((resolve, reject) => {
this.successCallback = (response) => {
response.timeElapsed = performanceNow() - timeStart
resolve(response)
}
this.failCallback = (response) => {
response.timeElapsed = 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: unknown) {
const err: Error = e as Error
this.dispatchClientError(err.message, err)
}
})
}
dispatchResponse(response: Response) {
response.success() ? this.successCallback(response) : this.failCallback(response)
}
dispatchClientError(message: string, error: Error) {
if (isTimeoutError(error) && this.options().enableHTTP408OnTimeouts) {
this.failCallback(new Response(this.request, 408, message, {}, [error]))
} else {
this.failCallback(new Response(this.request, 400, message, {}, [error]))
}
}
prepareBody(method: string, headers: Record<string, Primitive>) {
let body = this.request.body()
if (this.shouldEmulateHTTP()) {
body = body || {}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
isPlainObject(body) && ((body as any)['_method'] = method)
headers['x-http-method-override'] = method
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const bodyString = toQueryString(body as any)
if (bodyString) {
// If it's not simple, let the browser (or the user) set it
if (isPlainObject(body)) {
headers['content-type'] = 'application/x-www-form-urlencoded;charset=utf-8'
}
}
return bodyString
}
}
import { Gateway } from './gateway'
export { Fetch as FetchGateway } from './fetch'
export { HTTP as HTTPGateway } from './http'
export { Mock as MockGateway } from './mock'
export { isTimeoutError, createTimeoutError } from './timeout-error'
export { XHR as XHRGateway } from './xhr'
export type { HTTPRequestParams, HTTPGatewayConfiguration, GatewayConfiguration } from './types'
export default Gateway
export { Gateway }

@@ -1,2 +0,2 @@

import { Gateway } from './index'
import { Gateway } from './gateway'
import { lookupResponseAsync } from '../test/index'

@@ -3,0 +3,0 @@

@@ -0,1 +1,3 @@

export type Method = 'get' | 'head' | 'post' | 'put' | 'patch' | 'delete'
export interface HTTPRequestParams {

@@ -2,0 +4,0 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any

@@ -1,3 +0,4 @@

import { Gateway, Method } from './index'
import { Gateway } from './gateway'
import Response from '../response'
import type { Method } from './types'
import type { Headers } from '../types'

@@ -4,0 +5,0 @@ import { assign, parseResponseHeaders, btoa } from '../utils/index'

/* eslint-disable @typescript-eslint/no-var-requires */
import * as lib from './mappersmith'
import XHR from './gateway/xhr'
import HTTP from './gateway/http'
import Fetch from './gateway/fetch'
import { configs } from './mappersmith'
import { XHR } from './gateway/xhr'
import { HTTP } from './gateway/http'
import { Fetch } from './gateway/fetch'
import type { Gateway } from './gateway/index'
import type { GlobalConfigs, ManifestOptions, ResourceTypeConstraint } from './manifest'
const { configs } = lib
let _process = null
let defaultGateway = null
let defaultGateway: typeof Gateway | null = null

@@ -78,2 +78,3 @@ // Prevents webpack to load the nodejs process polyfill

export type Configuration = GlobalConfigs
export { default, version, configs, setContext } from './mappersmith'
export { forge as default, forge, version, setContext } from './mappersmith'
export { configs }

@@ -1,2 +0,2 @@

import ClientBuilder, { Client } from './client-builder'
import { ClientBuilder, Client } from './client-builder'
import { assign } from './utils/index'

@@ -133,1 +133,3 @@ import { GlobalConfigs, ManifestOptions, ResourceTypeConstraint } from './manifest'

}
export { forge }

@@ -18,3 +18,3 @@ import type { Auth } from '../types'

*/
export default (authConfig: Auth): Middleware =>
export const BasicAuthMiddleware = (authConfig: Auth): Middleware =>
function BasicAuthMiddleware() {

@@ -31,1 +31,2 @@ return {

}
export default BasicAuthMiddleware

@@ -6,3 +6,3 @@ import type { Middleware } from './index'

*/
export default (cookieName = 'csrfToken', headerName = 'x-csrf-token'): Middleware =>
export const CsrfMiddleware = (cookieName = 'csrfToken', headerName = 'x-csrf-token'): Middleware =>
function CsrfMiddleware() {

@@ -32,1 +32,2 @@ const REGEXP_COOKIE_NAME = new RegExp(cookieName + '[^;]+')

}
export default CsrfMiddleware

@@ -6,3 +6,3 @@ import type { Middleware } from './index'

*/
const DurationMiddleware: Middleware = ({ mockRequest }) => ({
export const DurationMiddleware: Middleware = ({ mockRequest }) => ({
async prepareRequest(next) {

@@ -9,0 +9,0 @@ if (mockRequest) {

@@ -17,3 +17,3 @@ import { REGEXP_CONTENT_TYPE_JSON } from '../response'

*/
const EncodeJsonMiddleware: Middleware = () => ({
export const EncodeJsonMiddleware: Middleware = () => ({
async prepareRequest(next) {

@@ -20,0 +20,0 @@ const request = await next()

@@ -16,3 +16,3 @@ import type { Response } from '../response'

*/
const GlobalErrorHandlerMiddleware: Middleware = () => ({
export const GlobalErrorHandlerMiddleware: Middleware = () => ({
response(next) {

@@ -19,0 +19,0 @@ if (!configs.Promise) {

@@ -47,3 +47,3 @@ import { Response } from '../response'

*/
const ConsoleLogMiddleware: Middleware = () => ({
export const LogMiddleware: Middleware = () => ({
async prepareRequest(next) {

@@ -69,2 +69,2 @@ const request = await next()

export default ConsoleLogMiddleware
export default LogMiddleware

@@ -29,3 +29,3 @@ import type { Middleware, ResponseGetter } from '../../index'

type RetryMiddleware = Middleware<{
type RetryMiddlewareType = Middleware<{
enableRetry: boolean

@@ -57,3 +57,5 @@ inboundRequest: Request

*/
export default (customConfigs: Partial<RetryMiddlewareOptions> = {}): RetryMiddleware =>
export const RetryMiddleware = (
customConfigs: Partial<RetryMiddlewareOptions> = {}
): RetryMiddlewareType =>
function RetryMiddleware() {

@@ -96,2 +98,4 @@ return {

export default RetryMiddleware
type RetryFn = (retryTime: number, retryCount: number, retryConfigs: RetryMiddlewareOptions) => void

@@ -98,0 +102,0 @@ type RetriableRequestFn = (

@@ -17,3 +17,3 @@ import type { Middleware } from './index'

*/
export default (timeoutValue: Milliseconds): Middleware =>
export const TimeoutMiddleware = (timeoutValue: Milliseconds): Middleware =>
function TimeoutMiddleware() {

@@ -30,1 +30,3 @@ return {

}
export default TimeoutMiddleware

@@ -1,4 +0,4 @@

import { Client } from '../client-builder'
import type { Client } from '../client-builder'
import { Request } from '../request'
import { Headers, Params } from '../types'
import type { Headers, Params } from '../types'
export { requestFactory, RequestFactoryArgs } from './request-factory'

@@ -5,0 +5,0 @@ export { responseFactory, ResponseFactoryArgs } from './response-factory'

import MockRequest from '../mocks/mock-request'
import MockResource from '../mocks/mock-resource'
import MockGateway from '../gateway/mock'
import { Mock as MockGateway } from '../gateway/mock'
import { configs } from '../index'

@@ -5,0 +5,0 @@ import { toQueryString } from '../utils/index'

import { Request, RequestContext } from '../request'
import { RequestParams } from '../types'
import type { RequestParams } from '../types'
import { MethodDescriptor } from '../method-descriptor'

@@ -4,0 +4,0 @@

@@ -1,4 +0,4 @@

import { Client } from '../client-builder'
import type { Client } from '../client-builder'
import { Request } from '../request'
import { Headers, Params } from '../types'
import type { Headers, Params } from '../types'
export { requestFactory, RequestFactoryArgs } from './request-factory'

@@ -5,0 +5,0 @@ export { responseFactory, ResponseFactoryArgs } from './response-factory'

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

var import_mock_resource = __toESM(require("../mocks/mock-resource"));
var import_mock = __toESM(require("../gateway/mock"));
var import_mock = require("../gateway/mock");
var import__ = require("../index");

@@ -67,3 +67,3 @@ var import_utils = require("../utils/index");

originalGateway = import__.configs.gateway;
import__.configs.gateway = import_mock.default;
import__.configs.gateway = import_mock.Mock;
};

@@ -70,0 +70,0 @@ const uninstall = () => {

import { Request, RequestContext } from '../request';
import { RequestParams } from '../types';
import type { RequestParams } from '../types';
export interface RequestFactoryArgs extends RequestParams {

@@ -4,0 +4,0 @@ method?: string;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc