msw 2.1.5 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js +17 -16
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +17 -16
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-rZ7XkeDz.d.mts → GraphQLHandler-AenIUdwE.d.mts} +1 -1
- package/lib/core/{GraphQLHandler-eJejgV5u.d.ts → GraphQLHandler-jOzqbxSK.d.ts} +1 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +2 -2
- package/lib/core/index.d.ts +2 -2
- package/lib/core/passthrough.d.mts +4 -1
- package/lib/core/passthrough.d.ts +4 -1
- package/lib/core/passthrough.js.map +1 -1
- package/lib/core/passthrough.mjs.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/iife/index.js +17 -16
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +5 -1
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +5 -1
- package/lib/native/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/core/passthrough.ts +4 -2
- package/src/native/index.ts +5 -1
- package/lib/core/{RequestHandler-CwjkprZE.d.ts → HttpResponse-_514VQ9z.d.ts} +68 -68
- package/lib/core/{RequestHandler-MAVTMsma.d.mts → HttpResponse-wcp03c7-.d.mts} +68 -68
package/lib/mockServiceWorker.js
CHANGED
package/lib/native/index.js
CHANGED
|
@@ -23,6 +23,7 @@ __export(native_exports, {
|
|
|
23
23
|
setupServer: () => setupServer
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(native_exports);
|
|
26
|
+
var import_fetch = require("@mswjs/interceptors/fetch");
|
|
26
27
|
var import_XMLHttpRequest = require("@mswjs/interceptors/XMLHttpRequest");
|
|
27
28
|
|
|
28
29
|
// src/node/SetupServerApi.ts
|
|
@@ -104,7 +105,10 @@ var SetupServerApi = class extends import_SetupApi.SetupApi {
|
|
|
104
105
|
|
|
105
106
|
// src/native/index.ts
|
|
106
107
|
function setupServer(...handlers) {
|
|
107
|
-
return new SetupServerApi(
|
|
108
|
+
return new SetupServerApi(
|
|
109
|
+
[import_fetch.FetchInterceptor, import_XMLHttpRequest.XMLHttpRequestInterceptor],
|
|
110
|
+
...handlers
|
|
111
|
+
);
|
|
108
112
|
}
|
|
109
113
|
// Annotate the CommonJS export names for ESM import in node:
|
|
110
114
|
0 && (module.exports = {
|
package/lib/native/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerApi.ts"],"sourcesContent":["import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from '../node/SetupServerApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerApi([XMLHttpRequestInterceptor]
|
|
1
|
+
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from '../node/SetupServerApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n ...handlers,\n )\n}\n","import {\n BatchInterceptor,\n HttpRequestEventMap,\n Interceptor,\n InterceptorReadyState,\n} from '@mswjs/interceptors'\nimport { invariant } from 'outvariant'\nimport { SetupApi } from '~/core/SetupApi'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { RequiredDeep } from '~/core/typeUtils'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { SetupServer } from './glossary'\n\nconst DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServer\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{\n new (): Interceptor<HttpRequestEventMap>\n }>,\n ...handlers: Array<RequestHandler>\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on('request', async ({ request, requestId }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.currentHandlers,\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n request.respondWith(response)\n }\n\n return\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n })\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAiC;AACjC,4BAA0C;;;ACD1C,0BAKO;AACP,wBAA0B;AAC1B,sBAAyB;AAIzB,2BAA8B;AAC9B,sBAAyB;AACzB,wBAA2B;AAG3B,IAAM,yBAAsD;AAAA,EAC1D,oBAAoB;AACtB;AAEO,IAAM,iBAAN,cACG,yBAEV;AAAA,EACqB;AAAA,EAIX;AAAA,EAER,YACE,iBAGG,UACH;AACA,UAAM,GAAG,QAAQ;AAEjB,SAAK,cAAc,IAAI,qCAAiB;AAAA,MACtC,MAAM;AAAA,MACN,cAAc,aAAa,IAAI,CAACA,iBAAgB,IAAIA,aAAY,CAAC;AAAA,IACnE,CAAC;AACD,SAAK,kBAAkB,CAAC;AAExB,SAAK,KAAK;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA,EAKQ,OAAa;AACnB,SAAK,YAAY,GAAG,WAAW,OAAO,EAAE,SAAS,UAAU,MAAM;AAC/D,YAAM,WAAW,UAAM;AAAA,QACrB;AAAA,QACA;AAAA,QACA,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,MACP;AAEA,UAAI,UAAU;AACZ,gBAAQ,YAAY,QAAQ;AAAA,MAC9B;AAEA;AAAA,IACF,CAAC;AAED,SAAK,YAAY;AAAA,MACf;AAAA,MACA,CAAC,EAAE,UAAU,kBAAkB,SAAS,UAAU,MAAM;AACtD,aAAK,QAAQ;AAAA,UACX,mBAAmB,oBAAoB;AAAA,UACvC;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEO,OAAO,UAAkC,CAAC,GAAS;AACxD,SAAK,sBAAkB;AAAA,MACrB;AAAA,MACA;AAAA,IACF;AAGA,SAAK,YAAY,MAAM;AAEvB,SAAK,cAAc,KAAK,MAAM;AAC5B,WAAK,YAAY,QAAQ;AAAA,IAC3B,CAAC;AAKD;AAAA,MACE,CAAC,0CAAsB,UAAU,0CAAsB,OAAO,EAAE;AAAA,QAC9D,KAAK,YAAY;AAAA,MACnB;AAAA,MACA,yBAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,SAAK,QAAQ;AAAA,EACf;AACF;;;ADrGO,SAAS,eACX,UACa;AAGhB,SAAO,IAAI;AAAA,IACT,CAAC,+BAAkB,+CAAyB;AAAA,IAC5C,GAAG;AAAA,EACL;AACF;","names":["Interceptor"]}
|
package/lib/native/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/native/index.ts
|
|
2
|
+
import { FetchInterceptor } from "@mswjs/interceptors/fetch";
|
|
2
3
|
import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/XMLHttpRequest";
|
|
3
4
|
|
|
4
5
|
// src/node/SetupServerApi.ts
|
|
@@ -83,7 +84,10 @@ var SetupServerApi = class extends SetupApi {
|
|
|
83
84
|
|
|
84
85
|
// src/native/index.ts
|
|
85
86
|
function setupServer(...handlers) {
|
|
86
|
-
return new SetupServerApi(
|
|
87
|
+
return new SetupServerApi(
|
|
88
|
+
[FetchInterceptor, XMLHttpRequestInterceptor],
|
|
89
|
+
...handlers
|
|
90
|
+
);
|
|
87
91
|
}
|
|
88
92
|
export {
|
|
89
93
|
setupServer
|
package/lib/native/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerApi.ts"],"sourcesContent":["import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from '../node/SetupServerApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerApi([XMLHttpRequestInterceptor]
|
|
1
|
+
{"version":3,"sources":["../../src/native/index.ts","../../src/node/SetupServerApi.ts"],"sourcesContent":["import { FetchInterceptor } from '@mswjs/interceptors/fetch'\nimport { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { SetupServerApi } from '../node/SetupServerApi'\n\n/**\n * Sets up a requests interception in React Native with the given request handlers.\n * @param {RequestHandler[]} handlers List of request handlers.\n *\n * @see {@link https://mswjs.io/docs/api/setup-server `setupServer()` API reference}\n */\nexport function setupServer(\n ...handlers: Array<RequestHandler>\n): SetupServerApi {\n // Provision request interception via patching the `XMLHttpRequest` class only\n // in React Native. There is no `http`/`https` modules in that environment.\n return new SetupServerApi(\n [FetchInterceptor, XMLHttpRequestInterceptor],\n ...handlers,\n )\n}\n","import {\n BatchInterceptor,\n HttpRequestEventMap,\n Interceptor,\n InterceptorReadyState,\n} from '@mswjs/interceptors'\nimport { invariant } from 'outvariant'\nimport { SetupApi } from '~/core/SetupApi'\nimport { RequestHandler } from '~/core/handlers/RequestHandler'\nimport { LifeCycleEventsMap, SharedOptions } from '~/core/sharedOptions'\nimport { RequiredDeep } from '~/core/typeUtils'\nimport { handleRequest } from '~/core/utils/handleRequest'\nimport { devUtils } from '~/core/utils/internal/devUtils'\nimport { mergeRight } from '~/core/utils/internal/mergeRight'\nimport { SetupServer } from './glossary'\n\nconst DEFAULT_LISTEN_OPTIONS: RequiredDeep<SharedOptions> = {\n onUnhandledRequest: 'warn',\n}\n\nexport class SetupServerApi\n extends SetupApi<LifeCycleEventsMap>\n implements SetupServer\n{\n protected readonly interceptor: BatchInterceptor<\n Array<Interceptor<HttpRequestEventMap>>,\n HttpRequestEventMap\n >\n private resolvedOptions: RequiredDeep<SharedOptions>\n\n constructor(\n interceptors: Array<{\n new (): Interceptor<HttpRequestEventMap>\n }>,\n ...handlers: Array<RequestHandler>\n ) {\n super(...handlers)\n\n this.interceptor = new BatchInterceptor({\n name: 'setup-server',\n interceptors: interceptors.map((Interceptor) => new Interceptor()),\n })\n this.resolvedOptions = {} as RequiredDeep<SharedOptions>\n\n this.init()\n }\n\n /**\n * Subscribe to all requests that are using the interceptor object\n */\n private init(): void {\n this.interceptor.on('request', async ({ request, requestId }) => {\n const response = await handleRequest(\n request,\n requestId,\n this.currentHandlers,\n this.resolvedOptions,\n this.emitter,\n )\n\n if (response) {\n request.respondWith(response)\n }\n\n return\n })\n\n this.interceptor.on(\n 'response',\n ({ response, isMockedResponse, request, requestId }) => {\n this.emitter.emit(\n isMockedResponse ? 'response:mocked' : 'response:bypass',\n {\n response,\n request,\n requestId,\n },\n )\n },\n )\n }\n\n public listen(options: Partial<SharedOptions> = {}): void {\n this.resolvedOptions = mergeRight(\n DEFAULT_LISTEN_OPTIONS,\n options,\n ) as RequiredDeep<SharedOptions>\n\n // Apply the interceptor when starting the server.\n this.interceptor.apply()\n\n this.subscriptions.push(() => {\n this.interceptor.dispose()\n })\n\n // Assert that the interceptor has been applied successfully.\n // Also guards us from forgetting to call \"interceptor.apply()\"\n // as a part of the \"listen\" method.\n invariant(\n [InterceptorReadyState.APPLYING, InterceptorReadyState.APPLIED].includes(\n this.interceptor.readyState,\n ),\n devUtils.formatMessage(\n 'Failed to start \"setupServer\": the interceptor failed to apply. This is likely an issue with the library and you should report it at \"%s\".',\n ),\n 'https://github.com/mswjs/msw/issues/new/choose',\n )\n }\n\n public close(): void {\n this.dispose()\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,iCAAiC;;;ACD1C;AAAA,EACE;AAAA,EAGA;AAAA,OACK;AACP,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAIzB,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAG3B,IAAM,yBAAsD;AAAA,EAC1D,oBAAoB;AACtB;AAEO,IAAM,iBAAN,cACG,SAEV;AAAA,EACqB;AAAA,EAIX;AAAA,EAER,YACE,iBAGG,UACH;AACA,UAAM,GAAG,QAAQ;AAEjB,SAAK,cAAc,IAAI,iBAAiB;AAAA,MACtC,MAAM;AAAA,MACN,cAAc,aAAa,IAAI,CAACA,iBAAgB,IAAIA,aAAY,CAAC;AAAA,IACnE,CAAC;AACD,SAAK,kBAAkB,CAAC;AAExB,SAAK,KAAK;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA,EAKQ,OAAa;AACnB,SAAK,YAAY,GAAG,WAAW,OAAO,EAAE,SAAS,UAAU,MAAM;AAC/D,YAAM,WAAW,MAAM;AAAA,QACrB;AAAA,QACA;AAAA,QACA,KAAK;AAAA,QACL,KAAK;AAAA,QACL,KAAK;AAAA,MACP;AAEA,UAAI,UAAU;AACZ,gBAAQ,YAAY,QAAQ;AAAA,MAC9B;AAEA;AAAA,IACF,CAAC;AAED,SAAK,YAAY;AAAA,MACf;AAAA,MACA,CAAC,EAAE,UAAU,kBAAkB,SAAS,UAAU,MAAM;AACtD,aAAK,QAAQ;AAAA,UACX,mBAAmB,oBAAoB;AAAA,UACvC;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEO,OAAO,UAAkC,CAAC,GAAS;AACxD,SAAK,kBAAkB;AAAA,MACrB;AAAA,MACA;AAAA,IACF;AAGA,SAAK,YAAY,MAAM;AAEvB,SAAK,cAAc,KAAK,MAAM;AAC5B,WAAK,YAAY,QAAQ;AAAA,IAC3B,CAAC;AAKD;AAAA,MACE,CAAC,sBAAsB,UAAU,sBAAsB,OAAO,EAAE;AAAA,QAC9D,KAAK,YAAY;AAAA,MACnB;AAAA,MACA,SAAS;AAAA,QACP;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEO,QAAc;AACnB,SAAK,QAAQ;AAAA,EACf;AACF;;;ADrGO,SAAS,eACX,UACa;AAGhB,SAAO,IAAI;AAAA,IACT,CAAC,kBAAkB,yBAAyB;AAAA,IAC5C,GAAG;AAAA,EACL;AACF;","names":["Interceptor"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"main": "./lib/core/index.js",
|
|
6
6
|
"module": "./lib/core/index.mjs",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"@bundled-es-modules/cookie": "^2.0.0",
|
|
96
96
|
"@bundled-es-modules/statuses": "^1.0.1",
|
|
97
97
|
"@mswjs/cookies": "^1.1.0",
|
|
98
|
-
"@mswjs/interceptors": "^0.25.
|
|
98
|
+
"@mswjs/interceptors": "^0.25.16",
|
|
99
99
|
"@open-draft/until": "^2.1.0",
|
|
100
100
|
"@types/cookie": "^0.6.0",
|
|
101
101
|
"@types/statuses": "^2.0.4",
|
package/src/core/passthrough.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { StrictResponse } from './HttpResponse'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Performs the intercepted request as-is.
|
|
3
5
|
*
|
|
@@ -12,12 +14,12 @@
|
|
|
12
14
|
*
|
|
13
15
|
* @see {@link https://mswjs.io/docs/api/passthrough `passthrough()` API reference}
|
|
14
16
|
*/
|
|
15
|
-
export function passthrough():
|
|
17
|
+
export function passthrough(): StrictResponse<any> {
|
|
16
18
|
return new Response(null, {
|
|
17
19
|
status: 302,
|
|
18
20
|
statusText: 'Passthrough',
|
|
19
21
|
headers: {
|
|
20
22
|
'x-msw-intention': 'passthrough',
|
|
21
23
|
},
|
|
22
|
-
})
|
|
24
|
+
}) as StrictResponse<any>
|
|
23
25
|
}
|
package/src/native/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FetchInterceptor } from '@mswjs/interceptors/fetch'
|
|
1
2
|
import { XMLHttpRequestInterceptor } from '@mswjs/interceptors/XMLHttpRequest'
|
|
2
3
|
import { RequestHandler } from '~/core/handlers/RequestHandler'
|
|
3
4
|
import { SetupServerApi } from '../node/SetupServerApi'
|
|
@@ -13,5 +14,8 @@ export function setupServer(
|
|
|
13
14
|
): SetupServerApi {
|
|
14
15
|
// Provision request interception via patching the `XMLHttpRequest` class only
|
|
15
16
|
// in React Native. There is no `http`/`https` modules in that environment.
|
|
16
|
-
return new SetupServerApi(
|
|
17
|
+
return new SetupServerApi(
|
|
18
|
+
[FetchInterceptor, XMLHttpRequestInterceptor],
|
|
19
|
+
...handlers,
|
|
20
|
+
)
|
|
17
21
|
}
|
|
@@ -20,74 +20,6 @@ declare const executeHandlers: <Handlers extends RequestHandler<RequestHandlerDe
|
|
|
20
20
|
resolutionContext?: ResponseResolutionContext | undefined;
|
|
21
21
|
}) => Promise<HandlersExecutionResult | null>;
|
|
22
22
|
|
|
23
|
-
interface HttpResponseInit extends ResponseInit {
|
|
24
|
-
type?: ResponseType;
|
|
25
|
-
}
|
|
26
|
-
declare const bodyType: unique symbol;
|
|
27
|
-
interface StrictRequest<BodyType extends DefaultBodyType> extends Request {
|
|
28
|
-
json(): Promise<BodyType>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Opaque `Response` type that supports strict body type.
|
|
32
|
-
*/
|
|
33
|
-
interface StrictResponse<BodyType extends DefaultBodyType> extends Response {
|
|
34
|
-
readonly [bodyType]: BodyType;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A drop-in replacement for the standard `Response` class
|
|
38
|
-
* to allow additional features, like mocking the response `Set-Cookie` header.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* new HttpResponse('Hello world', { status: 201 })
|
|
42
|
-
* HttpResponse.json({ name: 'John' })
|
|
43
|
-
* HttpResponse.formData(form)
|
|
44
|
-
*
|
|
45
|
-
* @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
|
|
46
|
-
*/
|
|
47
|
-
declare class HttpResponse extends Response {
|
|
48
|
-
constructor(body?: BodyInit | null, init?: HttpResponseInit);
|
|
49
|
-
/**
|
|
50
|
-
* Create a `Response` with a `Content-Type: "text/plain"` body.
|
|
51
|
-
* @example
|
|
52
|
-
* HttpResponse.text('hello world')
|
|
53
|
-
* HttpResponse.text('Error', { status: 500 })
|
|
54
|
-
*/
|
|
55
|
-
static text<BodyType extends string>(body?: BodyType | null, init?: HttpResponseInit): StrictResponse<BodyType>;
|
|
56
|
-
/**
|
|
57
|
-
* Create a `Response` with a `Content-Type: "application/json"` body.
|
|
58
|
-
* @example
|
|
59
|
-
* HttpResponse.json({ firstName: 'John' })
|
|
60
|
-
* HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
|
|
61
|
-
*/
|
|
62
|
-
static json<BodyType extends JsonBodyType>(body?: BodyType | null, init?: HttpResponseInit): StrictResponse<BodyType>;
|
|
63
|
-
/**
|
|
64
|
-
* Create a `Response` with a `Content-Type: "application/xml"` body.
|
|
65
|
-
* @example
|
|
66
|
-
* HttpResponse.xml(`<user name="John" />`)
|
|
67
|
-
* HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
|
|
68
|
-
*/
|
|
69
|
-
static xml<BodyType extends string>(body?: BodyType | null, init?: HttpResponseInit): Response;
|
|
70
|
-
/**
|
|
71
|
-
* Create a `Response` with an `ArrayBuffer` body.
|
|
72
|
-
* @example
|
|
73
|
-
* const buffer = new ArrayBuffer(3)
|
|
74
|
-
* const view = new Uint8Array(buffer)
|
|
75
|
-
* view.set([1, 2, 3])
|
|
76
|
-
*
|
|
77
|
-
* HttpResponse.arrayBuffer(buffer)
|
|
78
|
-
*/
|
|
79
|
-
static arrayBuffer(body?: ArrayBuffer, init?: HttpResponseInit): Response;
|
|
80
|
-
/**
|
|
81
|
-
* Create a `Response` with a `FormData` body.
|
|
82
|
-
* @example
|
|
83
|
-
* const data = new FormData()
|
|
84
|
-
* data.set('name', 'Alice')
|
|
85
|
-
*
|
|
86
|
-
* HttpResponse.formData(data)
|
|
87
|
-
*/
|
|
88
|
-
static formData(body?: FormData, init?: HttpResponseInit): Response;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
23
|
type DefaultRequestMultipartBody = Record<string, string | File | Array<string | File>>;
|
|
92
24
|
type DefaultBodyType = Record<string, any> | DefaultRequestMultipartBody | string | number | boolean | null | undefined;
|
|
93
25
|
type JsonBodyType = Record<string, any> | string | number | boolean | null | undefined;
|
|
@@ -186,4 +118,72 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
186
118
|
private createExecutionResult;
|
|
187
119
|
}
|
|
188
120
|
|
|
121
|
+
interface HttpResponseInit extends ResponseInit {
|
|
122
|
+
type?: ResponseType;
|
|
123
|
+
}
|
|
124
|
+
declare const bodyType: unique symbol;
|
|
125
|
+
interface StrictRequest<BodyType extends DefaultBodyType> extends Request {
|
|
126
|
+
json(): Promise<BodyType>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Opaque `Response` type that supports strict body type.
|
|
130
|
+
*/
|
|
131
|
+
interface StrictResponse<BodyType extends DefaultBodyType> extends Response {
|
|
132
|
+
readonly [bodyType]: BodyType;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A drop-in replacement for the standard `Response` class
|
|
136
|
+
* to allow additional features, like mocking the response `Set-Cookie` header.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* new HttpResponse('Hello world', { status: 201 })
|
|
140
|
+
* HttpResponse.json({ name: 'John' })
|
|
141
|
+
* HttpResponse.formData(form)
|
|
142
|
+
*
|
|
143
|
+
* @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
|
|
144
|
+
*/
|
|
145
|
+
declare class HttpResponse extends Response {
|
|
146
|
+
constructor(body?: BodyInit | null, init?: HttpResponseInit);
|
|
147
|
+
/**
|
|
148
|
+
* Create a `Response` with a `Content-Type: "text/plain"` body.
|
|
149
|
+
* @example
|
|
150
|
+
* HttpResponse.text('hello world')
|
|
151
|
+
* HttpResponse.text('Error', { status: 500 })
|
|
152
|
+
*/
|
|
153
|
+
static text<BodyType extends string>(body?: BodyType | null, init?: HttpResponseInit): StrictResponse<BodyType>;
|
|
154
|
+
/**
|
|
155
|
+
* Create a `Response` with a `Content-Type: "application/json"` body.
|
|
156
|
+
* @example
|
|
157
|
+
* HttpResponse.json({ firstName: 'John' })
|
|
158
|
+
* HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
|
|
159
|
+
*/
|
|
160
|
+
static json<BodyType extends JsonBodyType>(body?: BodyType | null, init?: HttpResponseInit): StrictResponse<BodyType>;
|
|
161
|
+
/**
|
|
162
|
+
* Create a `Response` with a `Content-Type: "application/xml"` body.
|
|
163
|
+
* @example
|
|
164
|
+
* HttpResponse.xml(`<user name="John" />`)
|
|
165
|
+
* HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
|
|
166
|
+
*/
|
|
167
|
+
static xml<BodyType extends string>(body?: BodyType | null, init?: HttpResponseInit): Response;
|
|
168
|
+
/**
|
|
169
|
+
* Create a `Response` with an `ArrayBuffer` body.
|
|
170
|
+
* @example
|
|
171
|
+
* const buffer = new ArrayBuffer(3)
|
|
172
|
+
* const view = new Uint8Array(buffer)
|
|
173
|
+
* view.set([1, 2, 3])
|
|
174
|
+
*
|
|
175
|
+
* HttpResponse.arrayBuffer(buffer)
|
|
176
|
+
*/
|
|
177
|
+
static arrayBuffer(body?: ArrayBuffer, init?: HttpResponseInit): Response;
|
|
178
|
+
/**
|
|
179
|
+
* Create a `Response` with a `FormData` body.
|
|
180
|
+
* @example
|
|
181
|
+
* const data = new FormData()
|
|
182
|
+
* data.set('name', 'Alice')
|
|
183
|
+
*
|
|
184
|
+
* HttpResponse.formData(data)
|
|
185
|
+
*/
|
|
186
|
+
static formData(body?: FormData, init?: HttpResponseInit): Response;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
189
|
export { type AsyncResponseResolverReturnType as A, type DefaultBodyType as D, type HttpResponseInit as H, type JsonBodyType as J, type MaybeAsyncResponseResolverReturnType as M, RequestHandler as R, type StrictRequest as S, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type StrictResponse as e, HttpResponse as f, type RequestHandlerDefaultInfo as g, type HandlersExecutionResult as h, type ResponseResolutionContext as i, executeHandlers as j, type RequestHandlerInternalInfo as k, type ResponseResolverInfo as l, type RequestHandlerArgs as m, type RequestHandlerExecutionResult as n };
|
|
@@ -20,74 +20,6 @@ declare const executeHandlers: <Handlers extends RequestHandler<RequestHandlerDe
|
|
|
20
20
|
resolutionContext?: ResponseResolutionContext | undefined;
|
|
21
21
|
}) => Promise<HandlersExecutionResult | null>;
|
|
22
22
|
|
|
23
|
-
interface HttpResponseInit extends ResponseInit {
|
|
24
|
-
type?: ResponseType;
|
|
25
|
-
}
|
|
26
|
-
declare const bodyType: unique symbol;
|
|
27
|
-
interface StrictRequest<BodyType extends DefaultBodyType> extends Request {
|
|
28
|
-
json(): Promise<BodyType>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Opaque `Response` type that supports strict body type.
|
|
32
|
-
*/
|
|
33
|
-
interface StrictResponse<BodyType extends DefaultBodyType> extends Response {
|
|
34
|
-
readonly [bodyType]: BodyType;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A drop-in replacement for the standard `Response` class
|
|
38
|
-
* to allow additional features, like mocking the response `Set-Cookie` header.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* new HttpResponse('Hello world', { status: 201 })
|
|
42
|
-
* HttpResponse.json({ name: 'John' })
|
|
43
|
-
* HttpResponse.formData(form)
|
|
44
|
-
*
|
|
45
|
-
* @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
|
|
46
|
-
*/
|
|
47
|
-
declare class HttpResponse extends Response {
|
|
48
|
-
constructor(body?: BodyInit | null, init?: HttpResponseInit);
|
|
49
|
-
/**
|
|
50
|
-
* Create a `Response` with a `Content-Type: "text/plain"` body.
|
|
51
|
-
* @example
|
|
52
|
-
* HttpResponse.text('hello world')
|
|
53
|
-
* HttpResponse.text('Error', { status: 500 })
|
|
54
|
-
*/
|
|
55
|
-
static text<BodyType extends string>(body?: BodyType | null, init?: HttpResponseInit): StrictResponse<BodyType>;
|
|
56
|
-
/**
|
|
57
|
-
* Create a `Response` with a `Content-Type: "application/json"` body.
|
|
58
|
-
* @example
|
|
59
|
-
* HttpResponse.json({ firstName: 'John' })
|
|
60
|
-
* HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
|
|
61
|
-
*/
|
|
62
|
-
static json<BodyType extends JsonBodyType>(body?: BodyType | null, init?: HttpResponseInit): StrictResponse<BodyType>;
|
|
63
|
-
/**
|
|
64
|
-
* Create a `Response` with a `Content-Type: "application/xml"` body.
|
|
65
|
-
* @example
|
|
66
|
-
* HttpResponse.xml(`<user name="John" />`)
|
|
67
|
-
* HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
|
|
68
|
-
*/
|
|
69
|
-
static xml<BodyType extends string>(body?: BodyType | null, init?: HttpResponseInit): Response;
|
|
70
|
-
/**
|
|
71
|
-
* Create a `Response` with an `ArrayBuffer` body.
|
|
72
|
-
* @example
|
|
73
|
-
* const buffer = new ArrayBuffer(3)
|
|
74
|
-
* const view = new Uint8Array(buffer)
|
|
75
|
-
* view.set([1, 2, 3])
|
|
76
|
-
*
|
|
77
|
-
* HttpResponse.arrayBuffer(buffer)
|
|
78
|
-
*/
|
|
79
|
-
static arrayBuffer(body?: ArrayBuffer, init?: HttpResponseInit): Response;
|
|
80
|
-
/**
|
|
81
|
-
* Create a `Response` with a `FormData` body.
|
|
82
|
-
* @example
|
|
83
|
-
* const data = new FormData()
|
|
84
|
-
* data.set('name', 'Alice')
|
|
85
|
-
*
|
|
86
|
-
* HttpResponse.formData(data)
|
|
87
|
-
*/
|
|
88
|
-
static formData(body?: FormData, init?: HttpResponseInit): Response;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
23
|
type DefaultRequestMultipartBody = Record<string, string | File | Array<string | File>>;
|
|
92
24
|
type DefaultBodyType = Record<string, any> | DefaultRequestMultipartBody | string | number | boolean | null | undefined;
|
|
93
25
|
type JsonBodyType = Record<string, any> | string | number | boolean | null | undefined;
|
|
@@ -186,4 +118,72 @@ declare abstract class RequestHandler<HandlerInfo extends RequestHandlerDefaultI
|
|
|
186
118
|
private createExecutionResult;
|
|
187
119
|
}
|
|
188
120
|
|
|
121
|
+
interface HttpResponseInit extends ResponseInit {
|
|
122
|
+
type?: ResponseType;
|
|
123
|
+
}
|
|
124
|
+
declare const bodyType: unique symbol;
|
|
125
|
+
interface StrictRequest<BodyType extends DefaultBodyType> extends Request {
|
|
126
|
+
json(): Promise<BodyType>;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Opaque `Response` type that supports strict body type.
|
|
130
|
+
*/
|
|
131
|
+
interface StrictResponse<BodyType extends DefaultBodyType> extends Response {
|
|
132
|
+
readonly [bodyType]: BodyType;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A drop-in replacement for the standard `Response` class
|
|
136
|
+
* to allow additional features, like mocking the response `Set-Cookie` header.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* new HttpResponse('Hello world', { status: 201 })
|
|
140
|
+
* HttpResponse.json({ name: 'John' })
|
|
141
|
+
* HttpResponse.formData(form)
|
|
142
|
+
*
|
|
143
|
+
* @see {@link https://mswjs.io/docs/api/http-response `HttpResponse` API reference}
|
|
144
|
+
*/
|
|
145
|
+
declare class HttpResponse extends Response {
|
|
146
|
+
constructor(body?: BodyInit | null, init?: HttpResponseInit);
|
|
147
|
+
/**
|
|
148
|
+
* Create a `Response` with a `Content-Type: "text/plain"` body.
|
|
149
|
+
* @example
|
|
150
|
+
* HttpResponse.text('hello world')
|
|
151
|
+
* HttpResponse.text('Error', { status: 500 })
|
|
152
|
+
*/
|
|
153
|
+
static text<BodyType extends string>(body?: BodyType | null, init?: HttpResponseInit): StrictResponse<BodyType>;
|
|
154
|
+
/**
|
|
155
|
+
* Create a `Response` with a `Content-Type: "application/json"` body.
|
|
156
|
+
* @example
|
|
157
|
+
* HttpResponse.json({ firstName: 'John' })
|
|
158
|
+
* HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
|
|
159
|
+
*/
|
|
160
|
+
static json<BodyType extends JsonBodyType>(body?: BodyType | null, init?: HttpResponseInit): StrictResponse<BodyType>;
|
|
161
|
+
/**
|
|
162
|
+
* Create a `Response` with a `Content-Type: "application/xml"` body.
|
|
163
|
+
* @example
|
|
164
|
+
* HttpResponse.xml(`<user name="John" />`)
|
|
165
|
+
* HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
|
|
166
|
+
*/
|
|
167
|
+
static xml<BodyType extends string>(body?: BodyType | null, init?: HttpResponseInit): Response;
|
|
168
|
+
/**
|
|
169
|
+
* Create a `Response` with an `ArrayBuffer` body.
|
|
170
|
+
* @example
|
|
171
|
+
* const buffer = new ArrayBuffer(3)
|
|
172
|
+
* const view = new Uint8Array(buffer)
|
|
173
|
+
* view.set([1, 2, 3])
|
|
174
|
+
*
|
|
175
|
+
* HttpResponse.arrayBuffer(buffer)
|
|
176
|
+
*/
|
|
177
|
+
static arrayBuffer(body?: ArrayBuffer, init?: HttpResponseInit): Response;
|
|
178
|
+
/**
|
|
179
|
+
* Create a `Response` with a `FormData` body.
|
|
180
|
+
* @example
|
|
181
|
+
* const data = new FormData()
|
|
182
|
+
* data.set('name', 'Alice')
|
|
183
|
+
*
|
|
184
|
+
* HttpResponse.formData(data)
|
|
185
|
+
*/
|
|
186
|
+
static formData(body?: FormData, init?: HttpResponseInit): Response;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
189
|
export { type AsyncResponseResolverReturnType as A, type DefaultBodyType as D, type HttpResponseInit as H, type JsonBodyType as J, type MaybeAsyncResponseResolverReturnType as M, RequestHandler as R, type StrictRequest as S, type ResponseResolver as a, type ResponseResolverReturnType as b, type RequestHandlerOptions as c, type DefaultRequestMultipartBody as d, type StrictResponse as e, HttpResponse as f, type RequestHandlerDefaultInfo as g, type HandlersExecutionResult as h, type ResponseResolutionContext as i, executeHandlers as j, type RequestHandlerInternalInfo as k, type ResponseResolverInfo as l, type RequestHandlerArgs as m, type RequestHandlerExecutionResult as n };
|