@mswjs/interceptors 0.39.8 → 0.41.0
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/ClientRequest/package.json +7 -2
- package/RemoteHttpInterceptor/package.json +7 -2
- package/WebSocket/package.json +9 -2
- package/XMLHttpRequest/package.json +9 -3
- package/fetch/package.json +9 -3
- package/lib/browser/Interceptor-2mUoKZL1.d.mts +65 -0
- package/lib/browser/Interceptor-Deczogc8.d.cts +65 -0
- package/lib/browser/XMLHttpRequest-BUfglQD1.cjs +761 -0
- package/lib/browser/XMLHttpRequest-BUfglQD1.cjs.map +1 -0
- package/lib/browser/XMLHttpRequest-DS5fc8Qs.mjs +756 -0
- package/lib/browser/XMLHttpRequest-DS5fc8Qs.mjs.map +1 -0
- package/lib/browser/bufferUtils-BiiO6HZv.mjs +20 -0
- package/lib/browser/bufferUtils-BiiO6HZv.mjs.map +1 -0
- package/lib/browser/bufferUtils-Uc0eRItL.cjs +38 -0
- package/lib/browser/bufferUtils-Uc0eRItL.cjs.map +1 -0
- package/lib/browser/createRequestId-Cs4oXfa1.cjs +205 -0
- package/lib/browser/createRequestId-Cs4oXfa1.cjs.map +1 -0
- package/lib/browser/createRequestId-DQcIlohW.mjs +170 -0
- package/lib/browser/createRequestId-DQcIlohW.mjs.map +1 -0
- package/lib/browser/fetch-BHcqM3z7.cjs +253 -0
- package/lib/browser/fetch-BHcqM3z7.cjs.map +1 -0
- package/lib/browser/fetch-DSJoynSF.mjs +248 -0
- package/lib/browser/fetch-DSJoynSF.mjs.map +1 -0
- package/lib/browser/getRawRequest-BTaNLFr0.mjs +218 -0
- package/lib/browser/getRawRequest-BTaNLFr0.mjs.map +1 -0
- package/lib/browser/getRawRequest-zx8rUJL2.cjs +259 -0
- package/lib/browser/getRawRequest-zx8rUJL2.cjs.map +1 -0
- package/lib/browser/glossary-BdLS4k1H.d.cts +70 -0
- package/lib/browser/glossary-gEEJhK4S.d.mts +70 -0
- package/lib/browser/handleRequest-DI6a7Dty.cjs +189 -0
- package/lib/browser/handleRequest-DI6a7Dty.cjs.map +1 -0
- package/lib/browser/handleRequest-DxGbCTbb.mjs +178 -0
- package/lib/browser/handleRequest-DxGbCTbb.mjs.map +1 -0
- package/lib/browser/hasConfigurableGlobal-C8kXFDic.mjs +33 -0
- package/lib/browser/hasConfigurableGlobal-C8kXFDic.mjs.map +1 -0
- package/lib/browser/hasConfigurableGlobal-D7S3l5h6.cjs +45 -0
- package/lib/browser/hasConfigurableGlobal-D7S3l5h6.cjs.map +1 -0
- package/lib/browser/index.cjs +68 -0
- package/lib/browser/index.cjs.map +1 -0
- package/lib/browser/index.d.cts +87 -0
- package/lib/browser/index.d.mts +87 -0
- package/lib/browser/index.mjs +49 -75
- package/lib/browser/index.mjs.map +1 -1
- package/lib/browser/interceptors/WebSocket/index.cjs +621 -0
- package/lib/browser/interceptors/WebSocket/index.cjs.map +1 -0
- package/lib/browser/interceptors/WebSocket/index.d.cts +277 -0
- package/lib/browser/interceptors/WebSocket/index.d.mts +277 -0
- package/lib/browser/interceptors/WebSocket/index.mjs +587 -694
- package/lib/browser/interceptors/WebSocket/index.mjs.map +1 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.cjs +7 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.d.cts +15 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.d.mts +15 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +7 -12
- package/lib/browser/interceptors/fetch/index.cjs +6 -0
- package/lib/browser/interceptors/fetch/index.d.cts +13 -0
- package/lib/browser/interceptors/fetch/index.d.mts +13 -0
- package/lib/browser/interceptors/fetch/index.mjs +6 -11
- package/lib/browser/presets/browser.cjs +17 -0
- package/lib/browser/presets/browser.cjs.map +1 -0
- package/lib/browser/presets/browser.d.cts +12 -0
- package/lib/browser/presets/browser.d.mts +14 -0
- package/lib/browser/presets/browser.mjs +15 -19
- package/lib/browser/presets/browser.mjs.map +1 -1
- package/lib/node/BatchInterceptor-3LnAnLTx.cjs +49 -0
- package/lib/node/BatchInterceptor-3LnAnLTx.cjs.map +1 -0
- package/lib/node/BatchInterceptor-D7mXzHcQ.d.mts +26 -0
- package/lib/node/BatchInterceptor-DFaBPilf.mjs +44 -0
- package/lib/node/BatchInterceptor-DFaBPilf.mjs.map +1 -0
- package/lib/node/BatchInterceptor-D_YqR8qU.d.cts +26 -0
- package/lib/node/ClientRequest-2rDe54Ui.cjs +1043 -0
- package/lib/node/ClientRequest-2rDe54Ui.cjs.map +1 -0
- package/lib/node/ClientRequest-Ca8Qykuv.mjs +1034 -0
- package/lib/node/ClientRequest-Ca8Qykuv.mjs.map +1 -0
- package/lib/node/Interceptor-DEazpLJd.d.mts +133 -0
- package/lib/node/Interceptor-DJ2akVWI.d.cts +133 -0
- package/lib/node/RemoteHttpInterceptor.cjs +154 -0
- package/lib/node/RemoteHttpInterceptor.cjs.map +1 -0
- package/lib/node/RemoteHttpInterceptor.d.cts +39 -0
- package/lib/node/RemoteHttpInterceptor.d.mts +39 -0
- package/lib/node/RemoteHttpInterceptor.mjs +145 -186
- package/lib/node/RemoteHttpInterceptor.mjs.map +1 -1
- package/lib/node/XMLHttpRequest-B7kJdYYI.cjs +763 -0
- package/lib/node/XMLHttpRequest-B7kJdYYI.cjs.map +1 -0
- package/lib/node/XMLHttpRequest-C8dIZpds.mjs +757 -0
- package/lib/node/XMLHttpRequest-C8dIZpds.mjs.map +1 -0
- package/lib/node/bufferUtils-DiCTqG-7.cjs +38 -0
- package/lib/node/bufferUtils-DiCTqG-7.cjs.map +1 -0
- package/lib/node/bufferUtils-_8XfKIfX.mjs +20 -0
- package/lib/node/bufferUtils-_8XfKIfX.mjs.map +1 -0
- package/lib/node/chunk-CbDLau6x.cjs +34 -0
- package/lib/node/fetch-BmXpK10r.cjs +272 -0
- package/lib/node/fetch-BmXpK10r.cjs.map +1 -0
- package/lib/node/fetch-G1DVwDKG.mjs +265 -0
- package/lib/node/fetch-G1DVwDKG.mjs.map +1 -0
- package/lib/node/fetchUtils-BaY5iWXw.cjs +419 -0
- package/lib/node/fetchUtils-BaY5iWXw.cjs.map +1 -0
- package/lib/node/fetchUtils-CoU35g3M.mjs +359 -0
- package/lib/node/fetchUtils-CoU35g3M.mjs.map +1 -0
- package/lib/node/getRawRequest-BavnMWh_.cjs +36 -0
- package/lib/node/getRawRequest-BavnMWh_.cjs.map +1 -0
- package/lib/node/getRawRequest-DnwmXyOW.mjs +24 -0
- package/lib/node/getRawRequest-DnwmXyOW.mjs.map +1 -0
- package/lib/node/glossary-BLKRyLBd.cjs +12 -0
- package/lib/node/glossary-BLKRyLBd.cjs.map +1 -0
- package/lib/node/glossary-glQBRnVD.mjs +6 -0
- package/lib/node/glossary-glQBRnVD.mjs.map +1 -0
- package/lib/node/handleRequest-Bb7Y-XLw.cjs +220 -0
- package/lib/node/handleRequest-Bb7Y-XLw.cjs.map +1 -0
- package/lib/node/handleRequest-Y97UwBbF.mjs +190 -0
- package/lib/node/handleRequest-Y97UwBbF.mjs.map +1 -0
- package/lib/node/hasConfigurableGlobal-C97fWuaA.cjs +26 -0
- package/lib/node/hasConfigurableGlobal-C97fWuaA.cjs.map +1 -0
- package/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs +20 -0
- package/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs.map +1 -0
- package/lib/node/index-BMbJ8FXL.d.cts +113 -0
- package/lib/node/index-C0YAQ36w.d.mts +113 -0
- package/lib/node/index.cjs +30 -0
- package/lib/node/index.cjs.map +1 -0
- package/lib/node/index.d.cts +66 -0
- package/lib/node/index.d.mts +66 -0
- package/lib/node/index.mjs +13 -39
- package/lib/node/index.mjs.map +1 -1
- package/lib/node/interceptors/ClientRequest/index.cjs +6 -0
- package/lib/node/interceptors/ClientRequest/index.d.cts +2 -0
- package/lib/node/interceptors/ClientRequest/index.d.mts +3 -0
- package/lib/node/interceptors/ClientRequest/index.mjs +6 -11
- package/lib/node/interceptors/XMLHttpRequest/index.cjs +6 -0
- package/lib/node/interceptors/XMLHttpRequest/index.d.cts +14 -0
- package/lib/node/interceptors/XMLHttpRequest/index.d.mts +14 -0
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +6 -13
- package/lib/node/interceptors/fetch/index.cjs +5 -0
- package/lib/node/interceptors/fetch/index.d.cts +12 -0
- package/lib/node/interceptors/fetch/index.d.mts +12 -0
- package/lib/node/interceptors/fetch/index.mjs +5 -12
- package/lib/node/node-DwCc6iuP.mjs +27 -0
- package/lib/node/node-DwCc6iuP.mjs.map +1 -0
- package/lib/node/node-dKdAf3tC.cjs +39 -0
- package/lib/node/node-dKdAf3tC.cjs.map +1 -0
- package/lib/node/presets/node.cjs +22 -0
- package/lib/node/presets/node.cjs.map +1 -0
- package/lib/node/presets/node.d.cts +13 -0
- package/lib/node/presets/node.d.mts +15 -0
- package/lib/node/presets/node.mjs +18 -23
- package/lib/node/presets/node.mjs.map +1 -1
- package/lib/node/utils/node/index.cjs +4 -0
- package/lib/node/utils/node/{index.d.ts → index.d.cts} +5 -2
- package/lib/node/utils/node/index.d.mts +16 -0
- package/lib/node/utils/node/index.mjs +3 -10
- package/package.json +34 -59
- package/presets/browser/package.json +2 -3
- package/presets/node/package.json +7 -2
- package/src/RemoteHttpInterceptor.ts +18 -13
- package/src/RequestController.test.ts +78 -31
- package/src/RequestController.ts +63 -39
- package/src/index.ts +4 -0
- package/src/interceptors/ClientRequest/MockHttpSocket.ts +43 -9
- package/src/interceptors/ClientRequest/index.ts +14 -18
- package/src/interceptors/ClientRequest/utils/parserUtils.ts +48 -0
- package/src/interceptors/WebSocket/index.ts +4 -1
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +45 -35
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +24 -21
- package/src/interceptors/XMLHttpRequest/utils/getBodyByteLength.test.ts +2 -2
- package/src/interceptors/fetch/index.ts +61 -50
- package/src/utils/handleRequest.ts +65 -95
- package/lib/browser/Interceptor-af98b768.d.ts +0 -63
- package/lib/browser/chunk-2HUMWGRD.js +0 -37
- package/lib/browser/chunk-2HUMWGRD.js.map +0 -1
- package/lib/browser/chunk-2QICSCCS.js +0 -238
- package/lib/browser/chunk-2QICSCCS.js.map +0 -1
- package/lib/browser/chunk-3RXCRGL2.mjs +0 -117
- package/lib/browser/chunk-3RXCRGL2.mjs.map +0 -1
- package/lib/browser/chunk-6HYIRFX2.mjs +0 -22
- package/lib/browser/chunk-6HYIRFX2.mjs.map +0 -1
- package/lib/browser/chunk-E3CCOBRX.js +0 -846
- package/lib/browser/chunk-E3CCOBRX.js.map +0 -1
- package/lib/browser/chunk-E7UVBHVO.mjs +0 -846
- package/lib/browser/chunk-E7UVBHVO.mjs.map +0 -1
- package/lib/browser/chunk-H74PGQ4Y.js +0 -296
- package/lib/browser/chunk-H74PGQ4Y.js.map +0 -1
- package/lib/browser/chunk-LK6DILFK.js +0 -22
- package/lib/browser/chunk-LK6DILFK.js.map +0 -1
- package/lib/browser/chunk-PTTUYYVR.mjs +0 -238
- package/lib/browser/chunk-PTTUYYVR.mjs.map +0 -1
- package/lib/browser/chunk-Q7K2XAEP.mjs +0 -296
- package/lib/browser/chunk-Q7K2XAEP.mjs.map +0 -1
- package/lib/browser/chunk-QED3Q6Z2.mjs +0 -169
- package/lib/browser/chunk-QED3Q6Z2.mjs.map +0 -1
- package/lib/browser/chunk-T7TBRNJZ.js +0 -117
- package/lib/browser/chunk-T7TBRNJZ.js.map +0 -1
- package/lib/browser/chunk-TIPR373R.js +0 -169
- package/lib/browser/chunk-TIPR373R.js.map +0 -1
- package/lib/browser/chunk-VYSDLBSS.mjs +0 -37
- package/lib/browser/chunk-VYSDLBSS.mjs.map +0 -1
- package/lib/browser/glossary-7152281e.d.ts +0 -69
- package/lib/browser/index.d.ts +0 -83
- package/lib/browser/index.js +0 -81
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/interceptors/WebSocket/index.d.ts +0 -271
- package/lib/browser/interceptors/WebSocket/index.js +0 -721
- package/lib/browser/interceptors/WebSocket/index.js.map +0 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +0 -15
- package/lib/browser/interceptors/XMLHttpRequest/index.js +0 -12
- package/lib/browser/interceptors/XMLHttpRequest/index.js.map +0 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs.map +0 -1
- package/lib/browser/interceptors/fetch/index.d.ts +0 -14
- package/lib/browser/interceptors/fetch/index.js +0 -11
- package/lib/browser/interceptors/fetch/index.js.map +0 -1
- package/lib/browser/interceptors/fetch/index.mjs.map +0 -1
- package/lib/browser/presets/browser.d.ts +0 -15
- package/lib/browser/presets/browser.js +0 -21
- package/lib/browser/presets/browser.js.map +0 -1
- package/lib/node/BatchInterceptor-5b72232f.d.ts +0 -24
- package/lib/node/Interceptor-bc5a9d8e.d.ts +0 -130
- package/lib/node/RemoteHttpInterceptor.d.ts +0 -45
- package/lib/node/RemoteHttpInterceptor.js +0 -193
- package/lib/node/RemoteHttpInterceptor.js.map +0 -1
- package/lib/node/chunk-3CNGDJFB.mjs +0 -313
- package/lib/node/chunk-3CNGDJFB.mjs.map +0 -1
- package/lib/node/chunk-3GJB4JDF.mjs +0 -14
- package/lib/node/chunk-3GJB4JDF.mjs.map +0 -1
- package/lib/node/chunk-4NEYTVWD.mjs +0 -848
- package/lib/node/chunk-4NEYTVWD.mjs.map +0 -1
- package/lib/node/chunk-4YBV77DG.js +0 -32
- package/lib/node/chunk-4YBV77DG.js.map +0 -1
- package/lib/node/chunk-6HYIRFX2.mjs +0 -22
- package/lib/node/chunk-6HYIRFX2.mjs.map +0 -1
- package/lib/node/chunk-6YM4PLBI.mjs +0 -7
- package/lib/node/chunk-6YM4PLBI.mjs.map +0 -1
- package/lib/node/chunk-72ZIHMEB.js +0 -249
- package/lib/node/chunk-72ZIHMEB.js.map +0 -1
- package/lib/node/chunk-73NOP3T5.js +0 -7
- package/lib/node/chunk-73NOP3T5.js.map +0 -1
- package/lib/node/chunk-A7Q4RTDJ.mjs +0 -249
- package/lib/node/chunk-A7Q4RTDJ.mjs.map +0 -1
- package/lib/node/chunk-A7U44ARP.js +0 -268
- package/lib/node/chunk-A7U44ARP.js.map +0 -1
- package/lib/node/chunk-EKNRB5ZS.mjs +0 -1115
- package/lib/node/chunk-EKNRB5ZS.mjs.map +0 -1
- package/lib/node/chunk-IHJSPMYM.mjs +0 -268
- package/lib/node/chunk-IHJSPMYM.mjs.map +0 -1
- package/lib/node/chunk-LK6DILFK.js +0 -22
- package/lib/node/chunk-LK6DILFK.js.map +0 -1
- package/lib/node/chunk-N4ZZFE24.js +0 -1115
- package/lib/node/chunk-N4ZZFE24.js.map +0 -1
- package/lib/node/chunk-PFGO5BSM.js +0 -25
- package/lib/node/chunk-PFGO5BSM.js.map +0 -1
- package/lib/node/chunk-R6JVCM7X.js +0 -51
- package/lib/node/chunk-R6JVCM7X.js.map +0 -1
- package/lib/node/chunk-RC2XPCC4.mjs +0 -51
- package/lib/node/chunk-RC2XPCC4.mjs.map +0 -1
- package/lib/node/chunk-SMXZPJEA.js +0 -14
- package/lib/node/chunk-SMXZPJEA.js.map +0 -1
- package/lib/node/chunk-TJDMZZXE.mjs +0 -32
- package/lib/node/chunk-TJDMZZXE.mjs.map +0 -1
- package/lib/node/chunk-TX5GBTFY.mjs +0 -25
- package/lib/node/chunk-TX5GBTFY.mjs.map +0 -1
- package/lib/node/chunk-VV2LUF5K.js +0 -848
- package/lib/node/chunk-VV2LUF5K.js.map +0 -1
- package/lib/node/chunk-Z5LWCBZS.js +0 -313
- package/lib/node/chunk-Z5LWCBZS.js.map +0 -1
- package/lib/node/index.d.ts +0 -62
- package/lib/node/index.js +0 -43
- package/lib/node/index.js.map +0 -1
- package/lib/node/interceptors/ClientRequest/index.d.ts +0 -111
- package/lib/node/interceptors/ClientRequest/index.js +0 -11
- package/lib/node/interceptors/ClientRequest/index.js.map +0 -1
- package/lib/node/interceptors/ClientRequest/index.mjs.map +0 -1
- package/lib/node/interceptors/XMLHttpRequest/index.d.ts +0 -14
- package/lib/node/interceptors/XMLHttpRequest/index.js +0 -13
- package/lib/node/interceptors/XMLHttpRequest/index.js.map +0 -1
- package/lib/node/interceptors/XMLHttpRequest/index.mjs.map +0 -1
- package/lib/node/interceptors/fetch/index.d.ts +0 -13
- package/lib/node/interceptors/fetch/index.js +0 -12
- package/lib/node/interceptors/fetch/index.js.map +0 -1
- package/lib/node/interceptors/fetch/index.mjs.map +0 -1
- package/lib/node/presets/node.d.ts +0 -16
- package/lib/node/presets/node.js +0 -27
- package/lib/node/presets/node.js.map +0 -1
- package/lib/node/utils/node/index.js +0 -10
- package/lib/node/utils/node/index.js.map +0 -1
- package/lib/node/utils/node/index.mjs.map +0 -1
- package/src/utils/RequestController.ts +0 -21
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { t as IS_PATCHED_MODULE } from "./glossary-glQBRnVD.mjs";
|
|
2
|
+
import { i as RequestController, n as canParseUrl, r as createRequestId, s as Interceptor, t as FetchResponse } from "./fetchUtils-CoU35g3M.mjs";
|
|
3
|
+
import { n as setRawRequest } from "./getRawRequest-DnwmXyOW.mjs";
|
|
4
|
+
import { i as emitAsync, n as isResponseError, t as handleRequest } from "./handleRequest-Y97UwBbF.mjs";
|
|
5
|
+
import { t as hasConfigurableGlobal } from "./hasConfigurableGlobal-DBJA0vjm.mjs";
|
|
6
|
+
import { DeferredPromise } from "@open-draft/deferred-promise";
|
|
7
|
+
import { invariant } from "outvariant";
|
|
8
|
+
import { until } from "@open-draft/until";
|
|
9
|
+
import zlib from "node:zlib";
|
|
10
|
+
|
|
11
|
+
//#region src/interceptors/fetch/utils/createNetworkError.ts
|
|
12
|
+
function createNetworkError(cause) {
|
|
13
|
+
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/interceptors/fetch/utils/followRedirect.ts
|
|
18
|
+
const REQUEST_BODY_HEADERS = [
|
|
19
|
+
"content-encoding",
|
|
20
|
+
"content-language",
|
|
21
|
+
"content-location",
|
|
22
|
+
"content-type",
|
|
23
|
+
"content-length"
|
|
24
|
+
];
|
|
25
|
+
const kRedirectCount = Symbol("kRedirectCount");
|
|
26
|
+
/**
|
|
27
|
+
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1210
|
|
28
|
+
*/
|
|
29
|
+
async function followFetchRedirect(request, response) {
|
|
30
|
+
if (response.status !== 303 && request.body != null) return Promise.reject(createNetworkError());
|
|
31
|
+
const requestUrl = new URL(request.url);
|
|
32
|
+
let locationUrl;
|
|
33
|
+
try {
|
|
34
|
+
locationUrl = new URL(response.headers.get("location"), request.url);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
return Promise.reject(createNetworkError(error));
|
|
37
|
+
}
|
|
38
|
+
if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) return Promise.reject(createNetworkError("URL scheme must be a HTTP(S) scheme"));
|
|
39
|
+
if (Reflect.get(request, kRedirectCount) > 20) return Promise.reject(createNetworkError("redirect count exceeded"));
|
|
40
|
+
Object.defineProperty(request, kRedirectCount, { value: (Reflect.get(request, kRedirectCount) || 0) + 1 });
|
|
41
|
+
if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) return Promise.reject(createNetworkError("cross origin not allowed for request mode \"cors\""));
|
|
42
|
+
const requestInit = {};
|
|
43
|
+
if ([301, 302].includes(response.status) && request.method === "POST" || response.status === 303 && !["HEAD", "GET"].includes(request.method)) {
|
|
44
|
+
requestInit.method = "GET";
|
|
45
|
+
requestInit.body = null;
|
|
46
|
+
REQUEST_BODY_HEADERS.forEach((headerName) => {
|
|
47
|
+
request.headers.delete(headerName);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (!sameOrigin(requestUrl, locationUrl)) {
|
|
51
|
+
request.headers.delete("authorization");
|
|
52
|
+
request.headers.delete("proxy-authorization");
|
|
53
|
+
request.headers.delete("cookie");
|
|
54
|
+
request.headers.delete("host");
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @note Undici "safely" extracts the request body.
|
|
58
|
+
* I suspect we cannot dispatch this request again
|
|
59
|
+
* since its body has been read and the stream is locked.
|
|
60
|
+
*/
|
|
61
|
+
requestInit.headers = request.headers;
|
|
62
|
+
const finalResponse = await fetch(new Request(locationUrl, requestInit));
|
|
63
|
+
Object.defineProperty(finalResponse, "redirected", {
|
|
64
|
+
value: true,
|
|
65
|
+
configurable: true
|
|
66
|
+
});
|
|
67
|
+
return finalResponse;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/util.js#L761
|
|
71
|
+
*/
|
|
72
|
+
function sameOrigin(left, right) {
|
|
73
|
+
if (left.origin === right.origin && left.origin === "null") return true;
|
|
74
|
+
if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) return true;
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/interceptors/fetch/utils/brotli-decompress.ts
|
|
80
|
+
var BrotliDecompressionStream = class extends TransformStream {
|
|
81
|
+
constructor() {
|
|
82
|
+
const decompress = zlib.createBrotliDecompress({
|
|
83
|
+
flush: zlib.constants.BROTLI_OPERATION_FLUSH,
|
|
84
|
+
finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH
|
|
85
|
+
});
|
|
86
|
+
super({ async transform(chunk, controller) {
|
|
87
|
+
const buffer = Buffer.from(chunk);
|
|
88
|
+
const decompressed = await new Promise((resolve, reject) => {
|
|
89
|
+
decompress.write(buffer, (error) => {
|
|
90
|
+
if (error) reject(error);
|
|
91
|
+
});
|
|
92
|
+
decompress.flush();
|
|
93
|
+
decompress.once("data", (data) => resolve(data));
|
|
94
|
+
decompress.once("error", (error) => reject(error));
|
|
95
|
+
decompress.once("end", () => controller.terminate());
|
|
96
|
+
}).catch((error) => {
|
|
97
|
+
controller.error(error);
|
|
98
|
+
});
|
|
99
|
+
controller.enqueue(decompressed);
|
|
100
|
+
} });
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/interceptors/fetch/utils/decompression.ts
|
|
106
|
+
var PipelineStream = class extends TransformStream {
|
|
107
|
+
constructor(transformStreams, ...strategies) {
|
|
108
|
+
super({}, ...strategies);
|
|
109
|
+
const readable = [super.readable, ...transformStreams].reduce((readable$1, transform) => readable$1.pipeThrough(transform));
|
|
110
|
+
Object.defineProperty(this, "readable", { get() {
|
|
111
|
+
return readable;
|
|
112
|
+
} });
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
function parseContentEncoding(contentEncoding) {
|
|
116
|
+
return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
|
|
117
|
+
}
|
|
118
|
+
function createDecompressionStream(contentEncoding) {
|
|
119
|
+
if (contentEncoding === "") return null;
|
|
120
|
+
const codings = parseContentEncoding(contentEncoding);
|
|
121
|
+
if (codings.length === 0) return null;
|
|
122
|
+
return new PipelineStream(codings.reduceRight((transformers, coding) => {
|
|
123
|
+
if (coding === "gzip" || coding === "x-gzip") return transformers.concat(new DecompressionStream("gzip"));
|
|
124
|
+
else if (coding === "deflate") return transformers.concat(new DecompressionStream("deflate"));
|
|
125
|
+
else if (coding === "br") return transformers.concat(new BrotliDecompressionStream());
|
|
126
|
+
else transformers.length = 0;
|
|
127
|
+
return transformers;
|
|
128
|
+
}, []));
|
|
129
|
+
}
|
|
130
|
+
function decompressResponse(response) {
|
|
131
|
+
if (response.body === null) return null;
|
|
132
|
+
const decompressionStream = createDecompressionStream(response.headers.get("content-encoding") || "");
|
|
133
|
+
if (!decompressionStream) return null;
|
|
134
|
+
response.body.pipeTo(decompressionStream.writable);
|
|
135
|
+
return decompressionStream.readable;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
//#endregion
|
|
139
|
+
//#region src/interceptors/fetch/index.ts
|
|
140
|
+
var FetchInterceptor = class FetchInterceptor extends Interceptor {
|
|
141
|
+
static {
|
|
142
|
+
this.symbol = Symbol("fetch");
|
|
143
|
+
}
|
|
144
|
+
constructor() {
|
|
145
|
+
super(FetchInterceptor.symbol);
|
|
146
|
+
}
|
|
147
|
+
checkEnvironment() {
|
|
148
|
+
return hasConfigurableGlobal("fetch");
|
|
149
|
+
}
|
|
150
|
+
async setup() {
|
|
151
|
+
const pureFetch = globalThis.fetch;
|
|
152
|
+
invariant(!pureFetch[IS_PATCHED_MODULE], "Failed to patch the \"fetch\" module: already patched.");
|
|
153
|
+
globalThis.fetch = async (input, init) => {
|
|
154
|
+
const requestId = createRequestId();
|
|
155
|
+
/**
|
|
156
|
+
* @note Resolve potentially relative request URL
|
|
157
|
+
* against the present `location`. This is mainly
|
|
158
|
+
* for native `fetch` in JSDOM.
|
|
159
|
+
* @see https://github.com/mswjs/msw/issues/1625
|
|
160
|
+
*/
|
|
161
|
+
const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.href) : input;
|
|
162
|
+
const request = new Request(resolvedInput, init);
|
|
163
|
+
/**
|
|
164
|
+
* @note Set the raw request only if a Request instance was provided to fetch.
|
|
165
|
+
*/
|
|
166
|
+
if (input instanceof Request) setRawRequest(request, input);
|
|
167
|
+
const responsePromise = new DeferredPromise();
|
|
168
|
+
const controller = new RequestController(request, {
|
|
169
|
+
passthrough: async () => {
|
|
170
|
+
this.logger.info("request has not been handled, passthrough...");
|
|
171
|
+
/**
|
|
172
|
+
* @note Clone the request instance right before performing it.
|
|
173
|
+
* This preserves any modifications made to the intercepted request
|
|
174
|
+
* in the "request" listener. This also allows the user to read the
|
|
175
|
+
* request body in the "response" listener (otherwise "unusable").
|
|
176
|
+
*/
|
|
177
|
+
const requestCloneForResponseEvent = request.clone();
|
|
178
|
+
const { error: responseError, data: originalResponse } = await until(() => pureFetch(request));
|
|
179
|
+
if (responseError) return responsePromise.reject(responseError);
|
|
180
|
+
this.logger.info("original fetch performed", originalResponse);
|
|
181
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
182
|
+
this.logger.info("emitting the \"response\" event...");
|
|
183
|
+
const responseClone = originalResponse.clone();
|
|
184
|
+
await emitAsync(this.emitter, "response", {
|
|
185
|
+
response: responseClone,
|
|
186
|
+
isMockedResponse: false,
|
|
187
|
+
request: requestCloneForResponseEvent,
|
|
188
|
+
requestId
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
responsePromise.resolve(originalResponse);
|
|
192
|
+
},
|
|
193
|
+
respondWith: async (rawResponse) => {
|
|
194
|
+
if (isResponseError(rawResponse)) {
|
|
195
|
+
this.logger.info("request has errored!", { response: rawResponse });
|
|
196
|
+
responsePromise.reject(createNetworkError(rawResponse));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
this.logger.info("received mocked response!", { rawResponse });
|
|
200
|
+
const decompressedStream = decompressResponse(rawResponse);
|
|
201
|
+
const response = decompressedStream === null ? rawResponse : new FetchResponse(decompressedStream, rawResponse);
|
|
202
|
+
FetchResponse.setUrl(request.url, response);
|
|
203
|
+
/**
|
|
204
|
+
* Undici's handling of following redirect responses.
|
|
205
|
+
* Treat the "manual" redirect mode as a regular mocked response.
|
|
206
|
+
* This way, the client can manually follow the redirect it receives.
|
|
207
|
+
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1173
|
|
208
|
+
*/
|
|
209
|
+
if (FetchResponse.isRedirectResponse(response.status)) {
|
|
210
|
+
if (request.redirect === "error") {
|
|
211
|
+
responsePromise.reject(createNetworkError("unexpected redirect"));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (request.redirect === "follow") {
|
|
215
|
+
followFetchRedirect(request, response).then((response$1) => {
|
|
216
|
+
responsePromise.resolve(response$1);
|
|
217
|
+
}, (reason) => {
|
|
218
|
+
responsePromise.reject(reason);
|
|
219
|
+
});
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
224
|
+
this.logger.info("emitting the \"response\" event...");
|
|
225
|
+
await emitAsync(this.emitter, "response", {
|
|
226
|
+
response: response.clone(),
|
|
227
|
+
isMockedResponse: true,
|
|
228
|
+
request,
|
|
229
|
+
requestId
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
responsePromise.resolve(response);
|
|
233
|
+
},
|
|
234
|
+
errorWith: (reason) => {
|
|
235
|
+
this.logger.info("request has been aborted!", { reason });
|
|
236
|
+
responsePromise.reject(reason);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
this.logger.info("[%s] %s", request.method, request.url);
|
|
240
|
+
this.logger.info("awaiting for the mocked response...");
|
|
241
|
+
this.logger.info("emitting the \"request\" event for %s listener(s)...", this.emitter.listenerCount("request"));
|
|
242
|
+
await handleRequest({
|
|
243
|
+
request,
|
|
244
|
+
requestId,
|
|
245
|
+
emitter: this.emitter,
|
|
246
|
+
controller
|
|
247
|
+
});
|
|
248
|
+
return responsePromise;
|
|
249
|
+
};
|
|
250
|
+
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {
|
|
251
|
+
enumerable: true,
|
|
252
|
+
configurable: true,
|
|
253
|
+
value: true
|
|
254
|
+
});
|
|
255
|
+
this.subscriptions.push(() => {
|
|
256
|
+
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, { value: void 0 });
|
|
257
|
+
globalThis.fetch = pureFetch;
|
|
258
|
+
this.logger.info("restored native \"globalThis.fetch\"!", globalThis.fetch.name);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
export { FetchInterceptor as t };
|
|
265
|
+
//# sourceMappingURL=fetch-G1DVwDKG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-G1DVwDKG.mjs","names":["locationUrl: URL","requestInit: RequestInit","readable","response"],"sources":["../../src/interceptors/fetch/utils/createNetworkError.ts","../../src/interceptors/fetch/utils/followRedirect.ts","../../src/interceptors/fetch/utils/brotli-decompress.ts","../../src/interceptors/fetch/utils/decompression.ts","../../src/interceptors/fetch/index.ts"],"sourcesContent":["export function createNetworkError(cause?: unknown) {\n return Object.assign(new TypeError('Failed to fetch'), {\n cause,\n })\n}\n","import { createNetworkError } from './createNetworkError'\n\nconst REQUEST_BODY_HEADERS = [\n 'content-encoding',\n 'content-language',\n 'content-location',\n 'content-type',\n 'content-length',\n]\n\nconst kRedirectCount = Symbol('kRedirectCount')\n\n/**\n * @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1210\n */\nexport async function followFetchRedirect(\n request: Request,\n response: Response\n): Promise<Response> {\n if (response.status !== 303 && request.body != null) {\n return Promise.reject(createNetworkError())\n }\n\n const requestUrl = new URL(request.url)\n\n let locationUrl: URL\n try {\n // If the location is a relative URL, use the request URL as the base URL.\n locationUrl = new URL(response.headers.get('location')!, request.url) \n } catch (error) {\n return Promise.reject(createNetworkError(error))\n }\n\n if (\n !(locationUrl.protocol === 'http:' || locationUrl.protocol === 'https:')\n ) {\n return Promise.reject(\n createNetworkError('URL scheme must be a HTTP(S) scheme')\n )\n }\n\n if (Reflect.get(request, kRedirectCount) > 20) {\n return Promise.reject(createNetworkError('redirect count exceeded'))\n }\n\n Object.defineProperty(request, kRedirectCount, {\n value: (Reflect.get(request, kRedirectCount) || 0) + 1,\n })\n\n if (\n request.mode === 'cors' &&\n (locationUrl.username || locationUrl.password) &&\n !sameOrigin(requestUrl, locationUrl)\n ) {\n return Promise.reject(\n createNetworkError('cross origin not allowed for request mode \"cors\"')\n )\n }\n\n const requestInit: RequestInit = {}\n\n if (\n ([301, 302].includes(response.status) && request.method === 'POST') ||\n (response.status === 303 && !['HEAD', 'GET'].includes(request.method))\n ) {\n requestInit.method = 'GET'\n requestInit.body = null\n\n REQUEST_BODY_HEADERS.forEach((headerName) => {\n request.headers.delete(headerName)\n })\n }\n\n if (!sameOrigin(requestUrl, locationUrl)) {\n request.headers.delete('authorization')\n request.headers.delete('proxy-authorization')\n request.headers.delete('cookie')\n request.headers.delete('host')\n }\n\n /**\n * @note Undici \"safely\" extracts the request body.\n * I suspect we cannot dispatch this request again\n * since its body has been read and the stream is locked.\n */\n\n requestInit.headers = request.headers\n const finalResponse = await fetch(new Request(locationUrl, requestInit))\n Object.defineProperty(finalResponse, 'redirected', {\n value: true,\n configurable: true,\n })\n\n return finalResponse\n}\n\n/**\n * @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/util.js#L761\n */\nfunction sameOrigin(left: URL, right: URL): boolean {\n if (left.origin === right.origin && left.origin === 'null') {\n return true\n }\n\n if (\n left.protocol === right.protocol &&\n left.hostname === right.hostname &&\n left.port === right.port\n ) {\n return true\n }\n\n return false\n}\n","import zlib from 'node:zlib'\n\nexport class BrotliDecompressionStream extends TransformStream {\n constructor() {\n const decompress = zlib.createBrotliDecompress({\n flush: zlib.constants.BROTLI_OPERATION_FLUSH,\n finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH,\n })\n\n super({\n async transform(chunk, controller) {\n const buffer = Buffer.from(chunk)\n\n const decompressed = await new Promise<Buffer>((resolve, reject) => {\n decompress.write(buffer, (error) => {\n if (error) reject(error)\n })\n\n decompress.flush()\n decompress.once('data', (data) => resolve(data))\n decompress.once('error', (error) => reject(error))\n decompress.once('end', () => controller.terminate())\n }).catch((error) => {\n controller.error(error)\n })\n\n controller.enqueue(decompressed)\n },\n })\n }\n}\n","// Import from an internal alias that resolves to different modules\n// depending on the environment. This way, we can keep the fetch interceptor\n// intact while using different strategies for Brotli decompression.\nimport { BrotliDecompressionStream } from 'internal:brotli-decompress'\n\nclass PipelineStream extends TransformStream {\n constructor(\n transformStreams: Array<TransformStream>,\n ...strategies: Array<QueuingStrategy>\n ) {\n super({}, ...strategies)\n\n const readable = [super.readable as any, ...transformStreams].reduce(\n (readable, transform) => readable.pipeThrough(transform)\n )\n\n Object.defineProperty(this, 'readable', {\n get() {\n return readable\n },\n })\n }\n}\n\nexport function parseContentEncoding(contentEncoding: string): Array<string> {\n return contentEncoding\n .toLowerCase()\n .split(',')\n .map((coding) => coding.trim())\n}\n\nfunction createDecompressionStream(\n contentEncoding: string\n): TransformStream | null {\n if (contentEncoding === '') {\n return null\n }\n\n const codings = parseContentEncoding(contentEncoding)\n\n if (codings.length === 0) {\n return null\n }\n\n const transformers = codings.reduceRight<Array<TransformStream>>(\n (transformers, coding) => {\n if (coding === 'gzip' || coding === 'x-gzip') {\n return transformers.concat(new DecompressionStream('gzip'))\n } else if (coding === 'deflate') {\n return transformers.concat(new DecompressionStream('deflate'))\n } else if (coding === 'br') {\n return transformers.concat(new BrotliDecompressionStream())\n } else {\n transformers.length = 0\n }\n\n return transformers\n },\n []\n )\n\n return new PipelineStream(transformers)\n}\n\nexport function decompressResponse(\n response: Response\n): ReadableStream<any> | null {\n if (response.body === null) {\n return null\n }\n\n const decompressionStream = createDecompressionStream(\n response.headers.get('content-encoding') || ''\n )\n\n if (!decompressionStream) {\n return null\n }\n\n // Use `pipeTo` and return the decompression stream's readable\n // instead of `pipeThrough` because that will lock the original\n // response stream, making it unusable as the input to Response.\n response.body.pipeTo(decompressionStream.writable)\n return decompressionStream.readable\n}\n","import { invariant } from 'outvariant'\nimport { until } from '@open-draft/until'\nimport { DeferredPromise } from '@open-draft/deferred-promise'\nimport { HttpRequestEventMap, IS_PATCHED_MODULE } from '../../glossary'\nimport { Interceptor } from '../../Interceptor'\nimport { RequestController } from '../../RequestController'\nimport { emitAsync } from '../../utils/emitAsync'\nimport { handleRequest } from '../../utils/handleRequest'\nimport { canParseUrl } from '../../utils/canParseUrl'\nimport { createRequestId } from '../../createRequestId'\nimport { createNetworkError } from './utils/createNetworkError'\nimport { followFetchRedirect } from './utils/followRedirect'\nimport { decompressResponse } from './utils/decompression'\nimport { hasConfigurableGlobal } from '../../utils/hasConfigurableGlobal'\nimport { FetchResponse } from '../../utils/fetchUtils'\nimport { setRawRequest } from '../../getRawRequest'\nimport { isResponseError } from '../../utils/responseUtils'\n\nexport class FetchInterceptor extends Interceptor<HttpRequestEventMap> {\n static symbol = Symbol('fetch')\n\n constructor() {\n super(FetchInterceptor.symbol)\n }\n\n protected checkEnvironment() {\n return hasConfigurableGlobal('fetch')\n }\n\n protected async setup() {\n const pureFetch = globalThis.fetch\n\n invariant(\n !(pureFetch as any)[IS_PATCHED_MODULE],\n 'Failed to patch the \"fetch\" module: already patched.'\n )\n\n globalThis.fetch = async (input, init) => {\n const requestId = createRequestId()\n\n /**\n * @note Resolve potentially relative request URL\n * against the present `location`. This is mainly\n * for native `fetch` in JSDOM.\n * @see https://github.com/mswjs/msw/issues/1625\n */\n const resolvedInput =\n typeof input === 'string' &&\n typeof location !== 'undefined' &&\n !canParseUrl(input)\n ? new URL(input, location.href)\n : input\n\n const request = new Request(resolvedInput, init)\n\n /**\n * @note Set the raw request only if a Request instance was provided to fetch.\n */\n if (input instanceof Request) {\n setRawRequest(request, input)\n }\n\n const responsePromise = new DeferredPromise<Response>()\n\n const controller = new RequestController(request, {\n passthrough: async () => {\n this.logger.info('request has not been handled, passthrough...')\n\n /**\n * @note Clone the request instance right before performing it.\n * This preserves any modifications made to the intercepted request\n * in the \"request\" listener. This also allows the user to read the\n * request body in the \"response\" listener (otherwise \"unusable\").\n */\n const requestCloneForResponseEvent = request.clone()\n\n // Perform the intercepted request as-is.\n const { error: responseError, data: originalResponse } = await until(\n () => pureFetch(request)\n )\n\n if (responseError) {\n return responsePromise.reject(responseError)\n }\n\n this.logger.info('original fetch performed', originalResponse)\n\n if (this.emitter.listenerCount('response') > 0) {\n this.logger.info('emitting the \"response\" event...')\n\n const responseClone = originalResponse.clone()\n await emitAsync(this.emitter, 'response', {\n response: responseClone,\n isMockedResponse: false,\n request: requestCloneForResponseEvent,\n requestId,\n })\n }\n\n // Resolve the response promise with the original response\n // since the `fetch()` return this internal promise.\n responsePromise.resolve(originalResponse)\n },\n respondWith: async (rawResponse) => {\n // Handle mocked `Response.error()` (i.e. request errors).\n if (isResponseError(rawResponse)) {\n this.logger.info('request has errored!', { response: rawResponse })\n responsePromise.reject(createNetworkError(rawResponse))\n return\n }\n\n this.logger.info('received mocked response!', {\n rawResponse,\n })\n\n // Decompress the mocked response body, if applicable.\n const decompressedStream = decompressResponse(rawResponse)\n const response =\n decompressedStream === null\n ? rawResponse\n : new FetchResponse(decompressedStream, rawResponse)\n\n FetchResponse.setUrl(request.url, response)\n\n /**\n * Undici's handling of following redirect responses.\n * Treat the \"manual\" redirect mode as a regular mocked response.\n * This way, the client can manually follow the redirect it receives.\n * @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1173\n */\n if (FetchResponse.isRedirectResponse(response.status)) {\n // Reject the request promise if its `redirect` is set to `error`\n // and it receives a mocked redirect response.\n if (request.redirect === 'error') {\n responsePromise.reject(createNetworkError('unexpected redirect'))\n return\n }\n\n if (request.redirect === 'follow') {\n followFetchRedirect(request, response).then(\n (response) => {\n responsePromise.resolve(response)\n },\n (reason) => {\n responsePromise.reject(reason)\n }\n )\n return\n }\n }\n\n if (this.emitter.listenerCount('response') > 0) {\n this.logger.info('emitting the \"response\" event...')\n\n // Await the response listeners to finish before resolving\n // the response promise. This ensures all your logic finishes\n // before the interceptor resolves the pending response.\n await emitAsync(this.emitter, 'response', {\n // Clone the mocked response for the \"response\" event listener.\n // This way, the listener can read the response and not lock its body\n // for the actual fetch consumer.\n response: response.clone(),\n isMockedResponse: true,\n request,\n requestId,\n })\n }\n\n responsePromise.resolve(response)\n },\n errorWith: (reason) => {\n this.logger.info('request has been aborted!', { reason })\n responsePromise.reject(reason)\n },\n })\n\n this.logger.info('[%s] %s', request.method, request.url)\n this.logger.info('awaiting for the mocked response...')\n\n this.logger.info(\n 'emitting the \"request\" event for %s listener(s)...',\n this.emitter.listenerCount('request')\n )\n\n await handleRequest({\n request,\n requestId,\n emitter: this.emitter,\n controller,\n })\n\n return responsePromise\n }\n\n Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {\n enumerable: true,\n configurable: true,\n value: true,\n })\n\n this.subscriptions.push(() => {\n Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {\n value: undefined,\n })\n\n globalThis.fetch = pureFetch\n\n this.logger.info(\n 'restored native \"globalThis.fetch\"!',\n globalThis.fetch.name\n )\n })\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAgB,mBAAmB,OAAiB;AAClD,QAAO,OAAO,uBAAO,IAAI,UAAU,kBAAkB,EAAE,EACrD,OACD,CAAC;;;;;ACDJ,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;CACA;CACD;AAED,MAAM,iBAAiB,OAAO,iBAAiB;;;;AAK/C,eAAsB,oBACpB,SACA,UACmB;AACnB,KAAI,SAAS,WAAW,OAAO,QAAQ,QAAQ,KAC7C,QAAO,QAAQ,OAAO,oBAAoB,CAAC;CAG7C,MAAM,aAAa,IAAI,IAAI,QAAQ,IAAI;CAEvC,IAAIA;AACJ,KAAI;AAEF,gBAAc,IAAI,IAAI,SAAS,QAAQ,IAAI,WAAW,EAAG,QAAQ,IAAI;UAC9D,OAAO;AACd,SAAO,QAAQ,OAAO,mBAAmB,MAAM,CAAC;;AAGlD,KACE,EAAE,YAAY,aAAa,WAAW,YAAY,aAAa,UAE/D,QAAO,QAAQ,OACb,mBAAmB,sCAAsC,CAC1D;AAGH,KAAI,QAAQ,IAAI,SAAS,eAAe,GAAG,GACzC,QAAO,QAAQ,OAAO,mBAAmB,0BAA0B,CAAC;AAGtE,QAAO,eAAe,SAAS,gBAAgB,EAC7C,QAAQ,QAAQ,IAAI,SAAS,eAAe,IAAI,KAAK,GACtD,CAAC;AAEF,KACE,QAA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