msw 2.6.3 → 2.6.5
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/README.md +6 -1
- package/lib/browser/index.js +111 -72
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +111 -72
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/bypass.js +1 -1
- package/lib/core/bypass.js.map +1 -1
- package/lib/core/bypass.mjs +1 -1
- package/lib/core/bypass.mjs.map +1 -1
- package/lib/core/utils/handleRequest.js +1 -1
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/iife/index.js +114 -75
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +10 -8
- package/lib/native/index.js +17 -1
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +17 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +17 -1
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +17 -1
- package/lib/node/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/browser/setupWorker/start/createResponseListener.ts +14 -19
- package/src/core/bypass.test.ts +25 -14
- package/src/core/bypass.ts +7 -5
- package/src/core/passthrough.test.ts +1 -3
- package/src/core/utils/handleRequest.test.ts +4 -4
- package/src/core/utils/handleRequest.ts +2 -2
- package/src/mockServiceWorker.js +8 -6
- package/src/node/SetupServerCommonApi.ts +23 -0
package/lib/core/bypass.js
CHANGED
|
@@ -36,7 +36,7 @@ function bypass(input, init) {
|
|
|
36
36
|
request.url
|
|
37
37
|
);
|
|
38
38
|
const requestClone = request.clone();
|
|
39
|
-
requestClone.headers.
|
|
39
|
+
requestClone.headers.append("accept", "msw/passthrough");
|
|
40
40
|
return requestClone;
|
|
41
41
|
}
|
|
42
42
|
//# sourceMappingURL=bypass.js.map
|
package/lib/core/bypass.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/bypass.ts"],"sourcesContent":["import { invariant } from 'outvariant'\n\nexport type BypassRequestInput = string | URL | Request\n\n/**\n * Creates a `Request` instance that will always be ignored by MSW.\n *\n * @example\n * import { bypass } from 'msw'\n *\n * fetch(bypass('/resource'))\n * fetch(bypass(new URL('/resource', 'https://example.com)))\n * fetch(bypass(new Request('https://example.com/resource')))\n *\n * @see {@link https://mswjs.io/docs/api/bypass `bypass()` API reference}\n */\nexport function bypass(input: BypassRequestInput, init?: RequestInit): Request {\n // Always create a new Request instance.\n // This way, the \"init\" modifications will propagate\n // to the bypass request instance automatically.\n const request = new Request(\n // If given a Request instance, clone it not to exhaust\n // the original request's body.\n input instanceof Request ? input.clone() : input,\n init,\n )\n\n invariant(\n !request.bodyUsed,\n 'Failed to create a bypassed request to \"%s %s\": given request instance already has its body read. Make sure to clone the intercepted request if you wish to read its body before bypassing it.',\n request.method,\n request.url,\n )\n\n const requestClone = request.clone()\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/core/bypass.ts"],"sourcesContent":["import { invariant } from 'outvariant'\n\nexport type BypassRequestInput = string | URL | Request\n\n/**\n * Creates a `Request` instance that will always be ignored by MSW.\n *\n * @example\n * import { bypass } from 'msw'\n *\n * fetch(bypass('/resource'))\n * fetch(bypass(new URL('/resource', 'https://example.com)))\n * fetch(bypass(new Request('https://example.com/resource')))\n *\n * @see {@link https://mswjs.io/docs/api/bypass `bypass()` API reference}\n */\nexport function bypass(input: BypassRequestInput, init?: RequestInit): Request {\n // Always create a new Request instance.\n // This way, the \"init\" modifications will propagate\n // to the bypass request instance automatically.\n const request = new Request(\n // If given a Request instance, clone it not to exhaust\n // the original request's body.\n input instanceof Request ? input.clone() : input,\n init,\n )\n\n invariant(\n !request.bodyUsed,\n 'Failed to create a bypassed request to \"%s %s\": given request instance already has its body read. Make sure to clone the intercepted request if you wish to read its body before bypassing it.',\n request.method,\n request.url,\n )\n\n const requestClone = request.clone()\n\n /**\n * Send the internal request header that would instruct MSW\n * to perform this request as-is, ignoring any matching handlers.\n * @note Use the `accept` header to support scenarios when the\n * request cannot have headers (e.g. `sendBeacon` requests).\n */\n requestClone.headers.append('accept', 'msw/passthrough')\n\n return requestClone\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA0B;AAgBnB,SAAS,OAAO,OAA2B,MAA6B;AAI7E,QAAM,UAAU,IAAI;AAAA;AAAA;AAAA,IAGlB,iBAAiB,UAAU,MAAM,MAAM,IAAI;AAAA,IAC3C;AAAA,EACF;AAEA;AAAA,IACE,CAAC,QAAQ;AAAA,IACT;AAAA,IACA,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAEA,QAAM,eAAe,QAAQ,MAAM;AAQnC,eAAa,QAAQ,OAAO,UAAU,iBAAiB;AAEvD,SAAO;AACT;","names":[]}
|
package/lib/core/bypass.mjs
CHANGED
package/lib/core/bypass.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/bypass.ts"],"sourcesContent":["import { invariant } from 'outvariant'\n\nexport type BypassRequestInput = string | URL | Request\n\n/**\n * Creates a `Request` instance that will always be ignored by MSW.\n *\n * @example\n * import { bypass } from 'msw'\n *\n * fetch(bypass('/resource'))\n * fetch(bypass(new URL('/resource', 'https://example.com)))\n * fetch(bypass(new Request('https://example.com/resource')))\n *\n * @see {@link https://mswjs.io/docs/api/bypass `bypass()` API reference}\n */\nexport function bypass(input: BypassRequestInput, init?: RequestInit): Request {\n // Always create a new Request instance.\n // This way, the \"init\" modifications will propagate\n // to the bypass request instance automatically.\n const request = new Request(\n // If given a Request instance, clone it not to exhaust\n // the original request's body.\n input instanceof Request ? input.clone() : input,\n init,\n )\n\n invariant(\n !request.bodyUsed,\n 'Failed to create a bypassed request to \"%s %s\": given request instance already has its body read. Make sure to clone the intercepted request if you wish to read its body before bypassing it.',\n request.method,\n request.url,\n )\n\n const requestClone = request.clone()\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/core/bypass.ts"],"sourcesContent":["import { invariant } from 'outvariant'\n\nexport type BypassRequestInput = string | URL | Request\n\n/**\n * Creates a `Request` instance that will always be ignored by MSW.\n *\n * @example\n * import { bypass } from 'msw'\n *\n * fetch(bypass('/resource'))\n * fetch(bypass(new URL('/resource', 'https://example.com)))\n * fetch(bypass(new Request('https://example.com/resource')))\n *\n * @see {@link https://mswjs.io/docs/api/bypass `bypass()` API reference}\n */\nexport function bypass(input: BypassRequestInput, init?: RequestInit): Request {\n // Always create a new Request instance.\n // This way, the \"init\" modifications will propagate\n // to the bypass request instance automatically.\n const request = new Request(\n // If given a Request instance, clone it not to exhaust\n // the original request's body.\n input instanceof Request ? input.clone() : input,\n init,\n )\n\n invariant(\n !request.bodyUsed,\n 'Failed to create a bypassed request to \"%s %s\": given request instance already has its body read. Make sure to clone the intercepted request if you wish to read its body before bypassing it.',\n request.method,\n request.url,\n )\n\n const requestClone = request.clone()\n\n /**\n * Send the internal request header that would instruct MSW\n * to perform this request as-is, ignoring any matching handlers.\n * @note Use the `accept` header to support scenarios when the\n * request cannot have headers (e.g. `sendBeacon` requests).\n */\n requestClone.headers.append('accept', 'msw/passthrough')\n\n return requestClone\n}\n"],"mappings":"AAAA,SAAS,iBAAiB;AAgBnB,SAAS,OAAO,OAA2B,MAA6B;AAI7E,QAAM,UAAU,IAAI;AAAA;AAAA;AAAA,IAGlB,iBAAiB,UAAU,MAAM,MAAM,IAAI;AAAA,IAC3C;AAAA,EACF;AAEA;AAAA,IACE,CAAC,QAAQ;AAAA,IACT;AAAA,IACA,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAEA,QAAM,eAAe,QAAQ,MAAM;AAQnC,eAAa,QAAQ,OAAO,UAAU,iBAAiB;AAEvD,SAAO;AACT;","names":[]}
|
|
@@ -27,7 +27,7 @@ var import_onUnhandledRequest = require("./request/onUnhandledRequest.js");
|
|
|
27
27
|
var import_storeResponseCookies = require("./request/storeResponseCookies.js");
|
|
28
28
|
async function handleRequest(request, requestId, handlers, options, emitter, handleRequestOptions) {
|
|
29
29
|
emitter.emit("request:start", { request, requestId });
|
|
30
|
-
if (request.headers.get("
|
|
30
|
+
if (request.headers.get("accept")?.includes("msw/passthrough")) {
|
|
31
31
|
emitter.emit("request:end", { request, requestId });
|
|
32
32
|
handleRequestOptions?.onPassthroughResponse?.(request);
|
|
33
33
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport type { RequestHandler } from '../handlers/RequestHandler'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<RequestHandler>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport type { RequestHandler } from '../handlers/RequestHandler'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<RequestHandler>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform requests wrapped in \"bypass()\" as-is.\n if (request.headers.get('accept')?.includes('msw/passthrough')) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the cookie jar.\n storeResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n handleRequestOptions?.onMockedResponse?.(response, requiredLookupResult)\n\n emitter.emit('request:end', { request, requestId })\n\n return response\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsB;AAKtB,6BAAyD;AACzD,gCAAmC;AACnC,kCAAqC;AA+BrC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,QAAQ,GAAG,SAAS,iBAAiB,GAAG;AAC9D,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,UAAM,oBAAM,MAAM;AACrC,eAAO,wCAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,cAAM,8CAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,wDAAqB,SAAS,QAAQ;AAEtC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,wBAAsB,mBAAmB,UAAU,oBAAoB;AAEvE,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
|
|
@@ -4,7 +4,7 @@ import { onUnhandledRequest } from './request/onUnhandledRequest.mjs';
|
|
|
4
4
|
import { storeResponseCookies } from './request/storeResponseCookies.mjs';
|
|
5
5
|
async function handleRequest(request, requestId, handlers, options, emitter, handleRequestOptions) {
|
|
6
6
|
emitter.emit("request:start", { request, requestId });
|
|
7
|
-
if (request.headers.get("
|
|
7
|
+
if (request.headers.get("accept")?.includes("msw/passthrough")) {
|
|
8
8
|
emitter.emit("request:end", { request, requestId });
|
|
9
9
|
handleRequestOptions?.onPassthroughResponse?.(request);
|
|
10
10
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport type { RequestHandler } from '../handlers/RequestHandler'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<RequestHandler>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/handleRequest.ts"],"sourcesContent":["import { until } from '@open-draft/until'\nimport { Emitter } from 'strict-event-emitter'\nimport { LifeCycleEventsMap, SharedOptions } from '../sharedOptions'\nimport { RequiredDeep } from '../typeUtils'\nimport type { RequestHandler } from '../handlers/RequestHandler'\nimport { HandlersExecutionResult, executeHandlers } from './executeHandlers'\nimport { onUnhandledRequest } from './request/onUnhandledRequest'\nimport { storeResponseCookies } from './request/storeResponseCookies'\n\nexport interface HandleRequestOptions {\n /**\n * `resolutionContext` is not part of the general public api\n * but is exposed to aid in creating extensions like\n * `@mswjs/http-middleware`.\n */\n resolutionContext?: {\n /**\n * A base url to use when resolving relative urls.\n * @note This is primarily used by the `@mswjs/http-middleware`\n * to resolve relative urls in the context of the running server\n */\n baseUrl?: string\n }\n\n /**\n * Invoked whenever a request is performed as-is.\n */\n onPassthroughResponse?(request: Request): void\n\n /**\n * Invoked when the mocked response is ready to be sent.\n */\n onMockedResponse?(\n response: Response,\n handler: RequiredDeep<HandlersExecutionResult>,\n ): void\n}\n\nexport async function handleRequest(\n request: Request,\n requestId: string,\n handlers: Array<RequestHandler>,\n options: RequiredDeep<SharedOptions>,\n emitter: Emitter<LifeCycleEventsMap>,\n handleRequestOptions?: HandleRequestOptions,\n): Promise<Response | undefined> {\n emitter.emit('request:start', { request, requestId })\n\n // Perform requests wrapped in \"bypass()\" as-is.\n if (request.headers.get('accept')?.includes('msw/passthrough')) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Resolve a mocked response from the list of request handlers.\n const lookupResult = await until(() => {\n return executeHandlers({\n request,\n requestId,\n handlers,\n resolutionContext: handleRequestOptions?.resolutionContext,\n })\n })\n\n if (lookupResult.error) {\n // Allow developers to react to unhandled exceptions in request handlers.\n emitter.emit('unhandledException', {\n error: lookupResult.error,\n request,\n requestId,\n })\n throw lookupResult.error\n }\n\n // If the handler lookup returned nothing, no request handler was found\n // matching this request. Report the request as unhandled.\n if (!lookupResult.data) {\n await onUnhandledRequest(request, options.onUnhandledRequest)\n emitter.emit('request:unhandled', { request, requestId })\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n const { response } = lookupResult.data\n\n // When the handled request returned no mocked response, warn the developer,\n // as it may be an oversight on their part. Perform the request as-is.\n if (!response) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Perform the request as-is when the developer explicitly returned \"req.passthrough()\".\n // This produces no warning as the request was handled.\n if (\n response.status === 302 &&\n response.headers.get('x-msw-intention') === 'passthrough'\n ) {\n emitter.emit('request:end', { request, requestId })\n handleRequestOptions?.onPassthroughResponse?.(request)\n return\n }\n\n // Store all the received response cookies in the cookie jar.\n storeResponseCookies(request, response)\n\n emitter.emit('request:match', { request, requestId })\n\n const requiredLookupResult =\n lookupResult.data as RequiredDeep<HandlersExecutionResult>\n\n handleRequestOptions?.onMockedResponse?.(response, requiredLookupResult)\n\n emitter.emit('request:end', { request, requestId })\n\n return response\n}\n"],"mappings":"AAAA,SAAS,aAAa;AAKtB,SAAkC,uBAAuB;AACzD,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AA+BrC,eAAsB,cACpB,SACA,WACA,UACA,SACA,SACA,sBAC+B;AAC/B,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAGpD,MAAI,QAAQ,QAAQ,IAAI,QAAQ,GAAG,SAAS,iBAAiB,GAAG;AAC9D,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,QAAM,eAAe,MAAM,MAAM,MAAM;AACrC,WAAO,gBAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB,sBAAsB;AAAA,IAC3C,CAAC;AAAA,EACH,CAAC;AAED,MAAI,aAAa,OAAO;AAEtB,YAAQ,KAAK,sBAAsB;AAAA,MACjC,OAAO,aAAa;AAAA,MACpB;AAAA,MACA;AAAA,IACF,CAAC;AACD,UAAM,aAAa;AAAA,EACrB;AAIA,MAAI,CAAC,aAAa,MAAM;AACtB,UAAM,mBAAmB,SAAS,QAAQ,kBAAkB;AAC5D,YAAQ,KAAK,qBAAqB,EAAE,SAAS,UAAU,CAAC;AACxD,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAEA,QAAM,EAAE,SAAS,IAAI,aAAa;AAIlC,MAAI,CAAC,UAAU;AACb,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAIA,MACE,SAAS,WAAW,OACpB,SAAS,QAAQ,IAAI,iBAAiB,MAAM,eAC5C;AACA,YAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAClD,0BAAsB,wBAAwB,OAAO;AACrD;AAAA,EACF;AAGA,uBAAqB,SAAS,QAAQ;AAEtC,UAAQ,KAAK,iBAAiB,EAAE,SAAS,UAAU,CAAC;AAEpD,QAAM,uBACJ,aAAa;AAEf,wBAAsB,mBAAmB,UAAU,oBAAoB;AAEvE,UAAQ,KAAK,eAAe,EAAE,SAAS,UAAU,CAAC;AAElD,SAAO;AACT;","names":[]}
|
package/lib/iife/index.js
CHANGED
|
@@ -14456,7 +14456,7 @@ ${operationTypes.join("\n")}
|
|
|
14456
14456
|
return stringToRegexp(path, keys, options);
|
|
14457
14457
|
}
|
|
14458
14458
|
|
|
14459
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14459
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
|
|
14460
14460
|
var encoder = new TextEncoder();
|
|
14461
14461
|
function encodeBuffer(text) {
|
|
14462
14462
|
return encoder.encode(text);
|
|
@@ -14472,54 +14472,67 @@ ${operationTypes.join("\n")}
|
|
|
14472
14472
|
);
|
|
14473
14473
|
}
|
|
14474
14474
|
|
|
14475
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14475
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-F4BN745U.mjs
|
|
14476
14476
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
14477
|
-
|
|
14478
|
-
|
|
14479
|
-
|
|
14480
|
-
return true;
|
|
14481
|
-
} catch (e) {
|
|
14482
|
-
return false;
|
|
14477
|
+
var _FetchResponse = class extends Response {
|
|
14478
|
+
static isConfigurableStatusCode(status) {
|
|
14479
|
+
return status >= 200 && status <= 599;
|
|
14483
14480
|
}
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
|
|
14494
|
-
|
|
14495
|
-
|
|
14496
|
-
|
|
14497
|
-
|
|
14498
|
-
|
|
14499
|
-
|
|
14500
|
-
|
|
14501
|
-
|
|
14502
|
-
|
|
14503
|
-
|
|
14504
|
-
|
|
14505
|
-
|
|
14506
|
-
|
|
14507
|
-
|
|
14508
|
-
|
|
14509
|
-
|
|
14510
|
-
)
|
|
14511
|
-
|
|
14512
|
-
|
|
14513
|
-
|
|
14514
|
-
|
|
14515
|
-
|
|
14481
|
+
static isRedirectResponse(status) {
|
|
14482
|
+
return _FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
|
|
14483
|
+
}
|
|
14484
|
+
/**
|
|
14485
|
+
* Returns a boolean indicating whether the given response status
|
|
14486
|
+
* code represents a response that can have a body.
|
|
14487
|
+
*/
|
|
14488
|
+
static isResponseWithBody(status) {
|
|
14489
|
+
return !_FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
|
|
14490
|
+
}
|
|
14491
|
+
static setUrl(url, response) {
|
|
14492
|
+
if (!url) {
|
|
14493
|
+
return;
|
|
14494
|
+
}
|
|
14495
|
+
if (response.url != "") {
|
|
14496
|
+
return;
|
|
14497
|
+
}
|
|
14498
|
+
Object.defineProperty(response, "url", {
|
|
14499
|
+
value: url,
|
|
14500
|
+
enumerable: true,
|
|
14501
|
+
configurable: true,
|
|
14502
|
+
writable: false
|
|
14503
|
+
});
|
|
14504
|
+
}
|
|
14505
|
+
constructor(body, init = {}) {
|
|
14506
|
+
var _a2;
|
|
14507
|
+
const status = (_a2 = init.status) != null ? _a2 : 200;
|
|
14508
|
+
const safeStatus = _FetchResponse.isConfigurableStatusCode(status) ? status : 200;
|
|
14509
|
+
const finalBody = _FetchResponse.isResponseWithBody(status) ? body : null;
|
|
14510
|
+
super(finalBody, {
|
|
14511
|
+
...init,
|
|
14512
|
+
status: safeStatus
|
|
14513
|
+
});
|
|
14514
|
+
if (status !== safeStatus) {
|
|
14515
|
+
const stateSymbol = Object.getOwnPropertySymbols(this).find(
|
|
14516
|
+
(symbol) => symbol.description === "state"
|
|
14517
|
+
);
|
|
14518
|
+
if (stateSymbol) {
|
|
14519
|
+
const state = Reflect.get(this, stateSymbol);
|
|
14520
|
+
Reflect.set(state, "status", status);
|
|
14521
|
+
} else {
|
|
14522
|
+
Object.defineProperty(this, "status", {
|
|
14523
|
+
value: status,
|
|
14524
|
+
enumerable: true,
|
|
14525
|
+
configurable: true,
|
|
14526
|
+
writable: false
|
|
14527
|
+
});
|
|
14516
14528
|
}
|
|
14517
14529
|
}
|
|
14518
|
-
|
|
14519
|
-
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14530
|
+
_FetchResponse.setUrl(init.url, this);
|
|
14531
|
+
}
|
|
14532
|
+
};
|
|
14533
|
+
var FetchResponse = _FetchResponse;
|
|
14534
|
+
FetchResponse.STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304];
|
|
14535
|
+
FetchResponse.STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308];
|
|
14523
14536
|
|
|
14524
14537
|
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
14525
14538
|
function isNodeProcess() {
|
|
@@ -14808,7 +14821,7 @@ ${operationTypes.join("\n")}
|
|
|
14808
14821
|
return message3.toString();
|
|
14809
14822
|
}
|
|
14810
14823
|
|
|
14811
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14824
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
14812
14825
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
14813
14826
|
function getGlobalSymbol(symbol) {
|
|
14814
14827
|
return (
|
|
@@ -14956,7 +14969,7 @@ ${operationTypes.join("\n")}
|
|
|
14956
14969
|
return Math.random().toString(16).slice(2);
|
|
14957
14970
|
}
|
|
14958
14971
|
|
|
14959
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14972
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
14960
14973
|
var BatchInterceptor = class extends Interceptor {
|
|
14961
14974
|
constructor(options) {
|
|
14962
14975
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -28799,7 +28812,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
28799
28812
|
// src/core/utils/handleRequest.ts
|
|
28800
28813
|
async function handleRequest(request, requestId, handlers, options, emitter, handleRequestOptions) {
|
|
28801
28814
|
emitter.emit("request:start", { request, requestId });
|
|
28802
|
-
if (request.headers.get("
|
|
28815
|
+
if (request.headers.get("accept")?.includes("msw/passthrough")) {
|
|
28803
28816
|
emitter.emit("request:end", { request, requestId });
|
|
28804
28817
|
handleRequestOptions?.onPassthroughResponse?.(request);
|
|
28805
28818
|
return;
|
|
@@ -29019,7 +29032,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
29019
29032
|
request.url
|
|
29020
29033
|
);
|
|
29021
29034
|
const requestClone = request.clone();
|
|
29022
|
-
requestClone.headers.
|
|
29035
|
+
requestClone.headers.append("accept", "msw/passthrough");
|
|
29023
29036
|
return requestClone;
|
|
29024
29037
|
}
|
|
29025
29038
|
|
|
@@ -29291,7 +29304,7 @@ This exception has been gracefully handled as a 500 response, however, it's stro
|
|
|
29291
29304
|
async function checkWorkerIntegrity(context) {
|
|
29292
29305
|
context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
|
|
29293
29306
|
const { payload } = await context.events.once("INTEGRITY_CHECK_RESPONSE");
|
|
29294
|
-
if (payload.checksum !== "
|
|
29307
|
+
if (payload.checksum !== "ca7800994cc8bfb5eb961e037c877074") {
|
|
29295
29308
|
devUtils.warn(
|
|
29296
29309
|
`The currently registered Service Worker has been generated by a different version of MSW (${payload.packageVersion}) and may not be fully compatible with the installed version.
|
|
29297
29310
|
|
|
@@ -29314,23 +29327,24 @@ You can also automate this process and make the worker script update automatical
|
|
|
29314
29327
|
if (responseJson.type?.includes("opaque")) {
|
|
29315
29328
|
return;
|
|
29316
29329
|
}
|
|
29317
|
-
const response = responseJson.status === 0 ? Response.error() : new
|
|
29330
|
+
const response = responseJson.status === 0 ? Response.error() : new FetchResponse(
|
|
29318
29331
|
/**
|
|
29319
29332
|
* Responses may be streams here, but when we create a response object
|
|
29320
29333
|
* with null-body status codes, like 204, 205, 304 Response will
|
|
29321
29334
|
* throw when passed a non-null body, so ensure it's null here
|
|
29322
29335
|
* for those codes
|
|
29323
29336
|
*/
|
|
29324
|
-
|
|
29325
|
-
|
|
29337
|
+
FetchResponse.isResponseWithBody(responseJson.status) ? responseJson.body : null,
|
|
29338
|
+
{
|
|
29339
|
+
...responseJson,
|
|
29340
|
+
/**
|
|
29341
|
+
* Set response URL if it's not set already.
|
|
29342
|
+
* @see https://github.com/mswjs/msw/issues/2030
|
|
29343
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
|
|
29344
|
+
*/
|
|
29345
|
+
url: request.url
|
|
29346
|
+
}
|
|
29326
29347
|
);
|
|
29327
|
-
if (!response.url) {
|
|
29328
|
-
Object.defineProperty(response, "url", {
|
|
29329
|
-
value: request.url,
|
|
29330
|
-
enumerable: true,
|
|
29331
|
-
writable: false
|
|
29332
|
-
});
|
|
29333
|
-
}
|
|
29334
29348
|
context.emitter.emit(
|
|
29335
29349
|
responseJson.isMockedResponse ? "response:mocked" : "response:bypass",
|
|
29336
29350
|
{
|
|
@@ -29500,7 +29514,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29500
29514
|
}
|
|
29501
29515
|
};
|
|
29502
29516
|
|
|
29503
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29517
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-H5O73WD2.mjs
|
|
29504
29518
|
var InterceptorError = class extends Error {
|
|
29505
29519
|
constructor(message3) {
|
|
29506
29520
|
super(message3);
|
|
@@ -29561,6 +29575,35 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29561
29575
|
await listener.apply(emitter, data);
|
|
29562
29576
|
}
|
|
29563
29577
|
}
|
|
29578
|
+
function isPropertyAccessible(obj, key) {
|
|
29579
|
+
try {
|
|
29580
|
+
obj[key];
|
|
29581
|
+
return true;
|
|
29582
|
+
} catch (e) {
|
|
29583
|
+
return false;
|
|
29584
|
+
}
|
|
29585
|
+
}
|
|
29586
|
+
function createServerErrorResponse(body) {
|
|
29587
|
+
return new Response(
|
|
29588
|
+
JSON.stringify(
|
|
29589
|
+
body instanceof Error ? {
|
|
29590
|
+
name: body.name,
|
|
29591
|
+
message: body.message,
|
|
29592
|
+
stack: body.stack
|
|
29593
|
+
} : body
|
|
29594
|
+
),
|
|
29595
|
+
{
|
|
29596
|
+
status: 500,
|
|
29597
|
+
statusText: "Unhandled Exception",
|
|
29598
|
+
headers: {
|
|
29599
|
+
"Content-Type": "application/json"
|
|
29600
|
+
}
|
|
29601
|
+
}
|
|
29602
|
+
);
|
|
29603
|
+
}
|
|
29604
|
+
function isResponseError(response) {
|
|
29605
|
+
return isPropertyAccessible(response, "type") && response.type === "error";
|
|
29606
|
+
}
|
|
29564
29607
|
function isNodeLikeError(error3) {
|
|
29565
29608
|
if (error3 == null) {
|
|
29566
29609
|
return false;
|
|
@@ -29672,7 +29715,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29672
29715
|
return false;
|
|
29673
29716
|
}
|
|
29674
29717
|
|
|
29675
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29718
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-TX5GBTFY.mjs
|
|
29676
29719
|
function hasConfigurableGlobal(propertyName) {
|
|
29677
29720
|
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
29678
29721
|
if (typeof descriptor === "undefined") {
|
|
@@ -29693,7 +29736,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29693
29736
|
return true;
|
|
29694
29737
|
}
|
|
29695
29738
|
|
|
29696
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29739
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-HER3NHBG.mjs
|
|
29697
29740
|
function canParseUrl(url) {
|
|
29698
29741
|
try {
|
|
29699
29742
|
new URL(url);
|
|
@@ -29869,8 +29912,9 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29869
29912
|
rawResponse
|
|
29870
29913
|
});
|
|
29871
29914
|
const decompressedStream = decompressResponse(rawResponse);
|
|
29872
|
-
const response = decompressedStream === null ? rawResponse : new
|
|
29873
|
-
|
|
29915
|
+
const response = decompressedStream === null ? rawResponse : new FetchResponse(decompressedStream, rawResponse);
|
|
29916
|
+
FetchResponse.setUrl(request.url, response);
|
|
29917
|
+
if (FetchResponse.isRedirectResponse(response.status)) {
|
|
29874
29918
|
if (request.redirect === "error") {
|
|
29875
29919
|
responsePromise.reject(createNetworkError("unexpected redirect"));
|
|
29876
29920
|
return;
|
|
@@ -29887,12 +29931,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29887
29931
|
return;
|
|
29888
29932
|
}
|
|
29889
29933
|
}
|
|
29890
|
-
Object.defineProperty(response, "url", {
|
|
29891
|
-
writable: false,
|
|
29892
|
-
enumerable: true,
|
|
29893
|
-
configurable: false,
|
|
29894
|
-
value: request.url
|
|
29895
|
-
});
|
|
29896
29934
|
if (this.emitter.listenerCount("response") > 0) {
|
|
29897
29935
|
this.logger.info('emitting the "response" event...');
|
|
29898
29936
|
await emitAsync(this.emitter, "response", {
|
|
@@ -29958,7 +29996,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29958
29996
|
var FetchInterceptor = _FetchInterceptor;
|
|
29959
29997
|
FetchInterceptor.symbol = Symbol("fetch");
|
|
29960
29998
|
|
|
29961
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29999
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-4SRQFK76.mjs
|
|
29962
30000
|
function concatArrayBuffer(left, right) {
|
|
29963
30001
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
29964
30002
|
result.set(left, 0);
|
|
@@ -30121,8 +30159,9 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30121
30159
|
}
|
|
30122
30160
|
}
|
|
30123
30161
|
function createResponse(request, body) {
|
|
30124
|
-
const responseBodyOrNull =
|
|
30125
|
-
return new
|
|
30162
|
+
const responseBodyOrNull = FetchResponse.isResponseWithBody(request.status) ? body : null;
|
|
30163
|
+
return new FetchResponse(responseBodyOrNull, {
|
|
30164
|
+
url: request.responseURL,
|
|
30126
30165
|
status: request.status,
|
|
30127
30166
|
statusText: request.statusText,
|
|
30128
30167
|
headers: createHeadersFromXMLHttpReqestHeaders(
|
|
@@ -30829,7 +30868,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30829
30868
|
}
|
|
30830
30869
|
}
|
|
30831
30870
|
|
|
30832
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
30871
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
30833
30872
|
function bindEvent(target, event) {
|
|
30834
30873
|
Object.defineProperties(event, {
|
|
30835
30874
|
target: {
|