@mswjs/interceptors 0.23.0 → 0.24.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/README.md +1 -1
- package/lib/browser/{chunk-3GCTA2IC.js → chunk-2TENISKM.js} +5 -5
- package/lib/{node/chunk-IHW3ERPT.js → browser/chunk-3LFH2WCF.js} +1 -9
- package/lib/{node/chunk-MPFSBY4S.js → browser/chunk-4CFMDU7Z.js} +36 -9
- package/lib/{node/chunk-LTX5IGCQ.mjs → browser/chunk-7II4SWKS.mjs} +0 -8
- package/lib/browser/{chunk-DWXGORCS.mjs → chunk-B74BGPYH.mjs} +58 -11
- package/lib/browser/{chunk-MW6NCDWE.mjs → chunk-GXJLJMOT.mjs} +33 -7
- package/lib/browser/{chunk-AKTXHQ7X.mjs → chunk-LHYX2GOM.mjs} +1 -1
- package/lib/browser/{chunk-OBNZMCHS.js → chunk-UGP4JOAM.js} +65 -18
- package/lib/browser/index.d.ts +2 -2
- package/lib/browser/index.js +4 -4
- package/lib/browser/index.mjs +2 -2
- package/lib/browser/interceptors/XMLHttpRequest/index.js +4 -4
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +3 -3
- package/lib/browser/interceptors/fetch/index.js +3 -3
- package/lib/browser/interceptors/fetch/index.mjs +2 -2
- package/lib/browser/presets/browser.js +6 -6
- package/lib/browser/presets/browser.mjs +4 -4
- package/lib/node/RemoteHttpInterceptor.d.ts +2 -3
- package/lib/node/RemoteHttpInterceptor.js +15 -16
- package/lib/node/RemoteHttpInterceptor.mjs +9 -10
- package/lib/node/chunk-3LFH2WCF.js +21 -0
- package/lib/node/chunk-7II4SWKS.mjs +21 -0
- package/lib/node/{chunk-VJDB3MIV.js → chunk-MVPEJK4V.js} +2 -2
- package/lib/node/{chunk-4YIZAGXJ.js → chunk-OOSIWXHX.js} +41 -8
- package/lib/node/{chunk-4LRRTLLD.mjs → chunk-PSIO3L7D.mjs} +39 -6
- package/lib/node/{chunk-Y5QA6OEZ.mjs → chunk-RGYCLCLK.mjs} +33 -10
- package/lib/node/{chunk-CO6XRA5H.mjs → chunk-UWSK5F3S.mjs} +58 -11
- package/lib/node/{chunk-NUSH7ACE.mjs → chunk-VS3GJPUE.mjs} +1 -1
- package/lib/{browser/chunk-7VJMJSIJ.js → node/chunk-XYZRP5S2.js} +35 -13
- package/lib/node/{chunk-GLYFVYMU.js → chunk-YCEMBJEM.js} +62 -15
- package/lib/node/index.js +4 -4
- package/lib/node/index.mjs +3 -3
- package/lib/node/interceptors/ClientRequest/index.js +3 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +2 -2
- package/lib/node/interceptors/XMLHttpRequest/index.js +4 -4
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +3 -3
- package/lib/node/interceptors/fetch/index.js +2 -2
- package/lib/node/interceptors/fetch/index.mjs +1 -1
- package/lib/node/presets/node.js +6 -6
- package/lib/node/presets/node.mjs +4 -4
- package/package.json +15 -18
- package/src/RemoteHttpInterceptor.ts +6 -7
- package/src/interceptors/ClientRequest/utils/createRequest.ts +0 -1
- package/src/interceptors/ClientRequest/utils/createResponse.ts +34 -3
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +15 -7
- package/src/interceptors/XMLHttpRequest/utils/createResponse.ts +27 -5
- package/src/utils/bufferUtils.ts +0 -2
- package/lib/browser/chunk-MQA5WAD4.mjs +0 -2139
- package/lib/browser/chunk-QAZ3SPQZ.js +0 -2139
- package/src/shims/webEncoding.ts +0 -9
package/README.md
CHANGED
|
@@ -206,7 +206,7 @@ All HTTP request interceptors emit a "request" event. In the listener to this ev
|
|
|
206
206
|
> There are many ways to describe a request in Node.js but this library coerces different request definitions to a single specification-compliant `Request` instance to make the handling consistent.
|
|
207
207
|
|
|
208
208
|
```js
|
|
209
|
-
interceptor.on('
|
|
209
|
+
interceptor.on('request', ({ request, requestId }) => {
|
|
210
210
|
console.log(request.method, request.url)
|
|
211
211
|
})
|
|
212
212
|
```
|
|
@@ -5,12 +5,12 @@ var _chunkPCFJD76Xjs = require('./chunk-PCFJD76X.js');
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunk4CFMDU7Zjs = require('./chunk-4CFMDU7Z.js');
|
|
9
9
|
|
|
10
10
|
// src/interceptors/fetch/index.ts
|
|
11
11
|
var _outvariant = require('outvariant');
|
|
12
12
|
var _until = require('@open-draft/until');
|
|
13
|
-
var _FetchInterceptor = class extends
|
|
13
|
+
var _FetchInterceptor = class extends _chunk4CFMDU7Zjs.Interceptor {
|
|
14
14
|
constructor() {
|
|
15
15
|
super(_FetchInterceptor.symbol);
|
|
16
16
|
}
|
|
@@ -20,7 +20,7 @@ var _FetchInterceptor = class extends _chunk7VJMJSIJjs.Interceptor {
|
|
|
20
20
|
setup() {
|
|
21
21
|
const pureFetch = globalThis.fetch;
|
|
22
22
|
_outvariant.invariant.call(void 0,
|
|
23
|
-
!pureFetch[
|
|
23
|
+
!pureFetch[_chunk4CFMDU7Zjs.IS_PATCHED_MODULE],
|
|
24
24
|
'Failed to patch the "fetch" module: already patched.'
|
|
25
25
|
);
|
|
26
26
|
globalThis.fetch = async (input, init) => {
|
|
@@ -88,13 +88,13 @@ var _FetchInterceptor = class extends _chunk7VJMJSIJjs.Interceptor {
|
|
|
88
88
|
return response;
|
|
89
89
|
});
|
|
90
90
|
};
|
|
91
|
-
Object.defineProperty(globalThis.fetch,
|
|
91
|
+
Object.defineProperty(globalThis.fetch, _chunk4CFMDU7Zjs.IS_PATCHED_MODULE, {
|
|
92
92
|
enumerable: true,
|
|
93
93
|
configurable: true,
|
|
94
94
|
value: true
|
|
95
95
|
});
|
|
96
96
|
this.subscriptions.push(() => {
|
|
97
|
-
Object.defineProperty(globalThis.fetch,
|
|
97
|
+
Object.defineProperty(globalThis.fetch, _chunk4CFMDU7Zjs.IS_PATCHED_MODULE, {
|
|
98
98
|
value: void 0
|
|
99
99
|
});
|
|
100
100
|
globalThis.fetch = pureFetch;
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
2
|
-
|
|
3
|
-
var _chunkMPFSBY4Sjs = require('./chunk-MPFSBY4S.js');
|
|
4
|
-
|
|
5
|
-
// src/shims/webEncoding.ts
|
|
6
|
-
var TextEncoder = typeof globalThis.TextEncoder === "undefined" ? _chunkMPFSBY4Sjs.__require.call(void 0, "util").TextEncoder : globalThis.TextEncoder;
|
|
7
|
-
var TextDecoder = typeof globalThis.TextDecoder === "undefined" ? _chunkMPFSBY4Sjs.__require.call(void 0, "util").TextDecoder : globalThis.TextDecoder;
|
|
8
|
-
|
|
9
|
-
// src/utils/bufferUtils.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/bufferUtils.ts
|
|
10
2
|
var encoder = new TextEncoder();
|
|
11
3
|
function encodeBuffer(text) {
|
|
12
4
|
return encoder.encode(text);
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
2
|
-
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined")
|
|
5
|
-
return require.apply(this, arguments);
|
|
6
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
-
});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/glossary.ts
|
|
2
|
+
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
8
3
|
|
|
9
4
|
// src/Interceptor.ts
|
|
10
5
|
var _logger = require('@open-draft/logger');
|
|
@@ -71,6 +66,11 @@ var AsyncEventEmitter = class extends _stricteventemitter.Emitter {
|
|
|
71
66
|
});
|
|
72
67
|
return super.emit(eventName, ...data);
|
|
73
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns a promise that resolves when all the listeners for the given event
|
|
71
|
+
* has been called. Awaits asynchronous listeners.
|
|
72
|
+
* If the event has no listeners, resolves immediately.
|
|
73
|
+
*/
|
|
74
74
|
async untilIdle(eventName, filter = () => true) {
|
|
75
75
|
const listenersQueue = this.queue.get(eventName) || [];
|
|
76
76
|
await Promise.all(
|
|
@@ -112,6 +112,11 @@ var AsyncEventEmitter = class extends _stricteventemitter.Emitter {
|
|
|
112
112
|
this.readyState = "ACTIVE" /* ACTIVE */;
|
|
113
113
|
logger.info("set state to:", this.readyState);
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Deactivate this event emitter.
|
|
117
|
+
* Deactivated emitter can no longer emit and listen to events
|
|
118
|
+
* and needs to be activated again in order to do so.
|
|
119
|
+
*/
|
|
115
120
|
deactivate() {
|
|
116
121
|
const logger = this.logger.extend("deactivate");
|
|
117
122
|
logger.info("removing all listeners...");
|
|
@@ -126,7 +131,10 @@ var AsyncEventEmitter = class extends _stricteventemitter.Emitter {
|
|
|
126
131
|
|
|
127
132
|
// src/Interceptor.ts
|
|
128
133
|
function getGlobalSymbol(symbol) {
|
|
129
|
-
return
|
|
134
|
+
return (
|
|
135
|
+
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
|
|
136
|
+
globalThis[symbol] || void 0
|
|
137
|
+
);
|
|
130
138
|
}
|
|
131
139
|
function setGlobalSymbol(symbol, value) {
|
|
132
140
|
globalThis[symbol] = value;
|
|
@@ -152,9 +160,17 @@ var Interceptor = class {
|
|
|
152
160
|
this.emitter.setMaxListeners(0);
|
|
153
161
|
this.logger.info("constructing the interceptor...");
|
|
154
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Determine if this interceptor can be applied
|
|
165
|
+
* in the current environment.
|
|
166
|
+
*/
|
|
155
167
|
checkEnvironment() {
|
|
156
168
|
return true;
|
|
157
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Apply this interceptor to the current process.
|
|
172
|
+
* Returns an already running interceptor instance if it's present.
|
|
173
|
+
*/
|
|
158
174
|
apply() {
|
|
159
175
|
const logger = this.logger.extend("apply");
|
|
160
176
|
logger.info("applying the interceptor...");
|
|
@@ -189,8 +205,16 @@ var Interceptor = class {
|
|
|
189
205
|
this.setInstance();
|
|
190
206
|
this.readyState = "APPLIED" /* APPLIED */;
|
|
191
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Setup the module augments and stubs necessary for this interceptor.
|
|
210
|
+
* This method is not run if there's a running interceptor instance
|
|
211
|
+
* to prevent instantiating an interceptor multiple times.
|
|
212
|
+
*/
|
|
192
213
|
setup() {
|
|
193
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Listen to the interceptor's public events.
|
|
217
|
+
*/
|
|
194
218
|
on(eventName, listener) {
|
|
195
219
|
const logger = this.logger.extend("on");
|
|
196
220
|
if (this.readyState === "DISPOSING" /* DISPOSING */ || this.readyState === "DISPOSED" /* DISPOSED */) {
|
|
@@ -200,6 +224,9 @@ var Interceptor = class {
|
|
|
200
224
|
logger.info('adding "%s" event listener:', eventName, listener.name);
|
|
201
225
|
this.emitter.on(eventName, listener);
|
|
202
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Disposes of any side-effects this interceptor has introduced.
|
|
229
|
+
*/
|
|
203
230
|
dispose() {
|
|
204
231
|
const logger = this.logger.extend("dispose");
|
|
205
232
|
if (this.readyState === "DISPOSED" /* DISPOSED */) {
|
|
@@ -248,4 +275,4 @@ var Interceptor = class {
|
|
|
248
275
|
|
|
249
276
|
|
|
250
277
|
|
|
251
|
-
exports.
|
|
278
|
+
exports.IS_PATCHED_MODULE = IS_PATCHED_MODULE; exports.getGlobalSymbol = getGlobalSymbol; exports.deleteGlobalSymbol = deleteGlobalSymbol; exports.InterceptorReadyState = InterceptorReadyState; exports.Interceptor = Interceptor;
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__require
|
|
3
|
-
} from "./chunk-Y5QA6OEZ.mjs";
|
|
4
|
-
|
|
5
|
-
// src/shims/webEncoding.ts
|
|
6
|
-
var TextEncoder = typeof globalThis.TextEncoder === "undefined" ? __require("util").TextEncoder : globalThis.TextEncoder;
|
|
7
|
-
var TextDecoder = typeof globalThis.TextDecoder === "undefined" ? __require("util").TextDecoder : globalThis.TextDecoder;
|
|
8
|
-
|
|
9
1
|
// src/utils/bufferUtils.ts
|
|
10
2
|
var encoder = new TextEncoder();
|
|
11
3
|
function encodeBuffer(text) {
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
decodeBuffer,
|
|
3
3
|
encodeBuffer,
|
|
4
4
|
toArrayBuffer
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-7II4SWKS.mjs";
|
|
6
6
|
import {
|
|
7
7
|
toInteractiveRequest,
|
|
8
8
|
uuidv4
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
IS_PATCHED_MODULE,
|
|
12
12
|
Interceptor
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-GXJLJMOT.mjs";
|
|
14
14
|
|
|
15
15
|
// src/interceptors/XMLHttpRequest/index.ts
|
|
16
16
|
import { invariant as invariant2 } from "outvariant";
|
|
@@ -20,7 +20,7 @@ import { until } from "@open-draft/until";
|
|
|
20
20
|
|
|
21
21
|
// src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts
|
|
22
22
|
import { invariant } from "outvariant";
|
|
23
|
-
import {
|
|
23
|
+
import { isNodeProcess } from "is-node-process";
|
|
24
24
|
|
|
25
25
|
// src/interceptors/XMLHttpRequest/utils/concatArrayBuffer.ts
|
|
26
26
|
function concatArrayBuffer(left, right) {
|
|
@@ -202,17 +202,32 @@ function parseJson(data) {
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
// src/interceptors/XMLHttpRequest/utils/createResponse.ts
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return new Response(responseBody, {
|
|
205
|
+
function createResponse(request, body) {
|
|
206
|
+
return new Response(body, {
|
|
208
207
|
status: request.status,
|
|
209
208
|
statusText: request.statusText,
|
|
210
|
-
headers:
|
|
209
|
+
headers: createHeadersFromXMLHttpReqestHeaders(
|
|
210
|
+
request.getAllResponseHeaders()
|
|
211
|
+
)
|
|
211
212
|
});
|
|
212
213
|
}
|
|
214
|
+
function createHeadersFromXMLHttpReqestHeaders(headersString) {
|
|
215
|
+
const headers = new Headers();
|
|
216
|
+
const lines = headersString.split(/[\r\n]+/);
|
|
217
|
+
for (const line of lines) {
|
|
218
|
+
if (line.trim() === "") {
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const [name, ...parts] = line.split(": ");
|
|
222
|
+
const value = parts.join(": ");
|
|
223
|
+
headers.append(name, value);
|
|
224
|
+
}
|
|
225
|
+
return headers;
|
|
226
|
+
}
|
|
213
227
|
|
|
214
228
|
// src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts
|
|
215
229
|
var IS_MOCKED_RESPONSE = Symbol("isMockedResponse");
|
|
230
|
+
var IS_NODE = isNodeProcess();
|
|
216
231
|
var XMLHttpRequestController = class {
|
|
217
232
|
constructor(initialRequest, logger) {
|
|
218
233
|
this.initialRequest = initialRequest;
|
|
@@ -220,6 +235,7 @@ var XMLHttpRequestController = class {
|
|
|
220
235
|
this.method = "GET";
|
|
221
236
|
this.url = null;
|
|
222
237
|
this.events = /* @__PURE__ */ new Map();
|
|
238
|
+
this.requestId = uuidv4();
|
|
223
239
|
this.requestHeaders = new Headers();
|
|
224
240
|
this.responseBuffer = new Uint8Array();
|
|
225
241
|
this.request = createProxy(initialRequest, {
|
|
@@ -242,7 +258,6 @@ var XMLHttpRequestController = class {
|
|
|
242
258
|
switch (methodName) {
|
|
243
259
|
case "open": {
|
|
244
260
|
const [method, url] = args;
|
|
245
|
-
this.requestId = uuidv4();
|
|
246
261
|
if (typeof url === "undefined") {
|
|
247
262
|
this.method = "GET";
|
|
248
263
|
this.url = toAbsoluteUrl(method);
|
|
@@ -275,6 +290,11 @@ var XMLHttpRequestController = class {
|
|
|
275
290
|
if (typeof this.onResponse !== "undefined") {
|
|
276
291
|
const fetchResponse = createResponse(
|
|
277
292
|
this.request,
|
|
293
|
+
/**
|
|
294
|
+
* The `response` property is the right way to read
|
|
295
|
+
* the ambiguous response body, as the request's "responseType" may differ.
|
|
296
|
+
* @see https://xhr.spec.whatwg.org/#the-response-attribute
|
|
297
|
+
*/
|
|
278
298
|
this.request.response
|
|
279
299
|
);
|
|
280
300
|
this.onResponse.call(this, {
|
|
@@ -296,7 +316,9 @@ var XMLHttpRequestController = class {
|
|
|
296
316
|
"request callback settled but request has not been handled (readystate %d), performing as-is...",
|
|
297
317
|
this.request.readyState
|
|
298
318
|
);
|
|
299
|
-
|
|
319
|
+
if (IS_NODE) {
|
|
320
|
+
this.request.setRequestHeader("X-Request-Id", this.requestId);
|
|
321
|
+
}
|
|
300
322
|
return invoke();
|
|
301
323
|
}
|
|
302
324
|
});
|
|
@@ -315,6 +337,10 @@ var XMLHttpRequestController = class {
|
|
|
315
337
|
this.events.set(eventName, nextEvents);
|
|
316
338
|
this.logger.info('registered event "%s"', eventName, listener.name);
|
|
317
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* Responds to the current request with the given
|
|
342
|
+
* Fetch API `Response` instance.
|
|
343
|
+
*/
|
|
318
344
|
respondWith(response) {
|
|
319
345
|
this.logger.info(
|
|
320
346
|
"responding with a mocked response: %d %s",
|
|
@@ -350,7 +376,10 @@ var XMLHttpRequestController = class {
|
|
|
350
376
|
this.logger.info("headers not received yet, returning empty string");
|
|
351
377
|
return "";
|
|
352
378
|
}
|
|
353
|
-
const
|
|
379
|
+
const headersList = Array.from(response.headers.entries());
|
|
380
|
+
const allHeaders = headersList.map(([headerName, headerValue]) => {
|
|
381
|
+
return `${headerName}: ${headerValue}`;
|
|
382
|
+
}).join("\r\n");
|
|
354
383
|
this.logger.info("resolved all response headers to", allHeaders);
|
|
355
384
|
return allHeaders;
|
|
356
385
|
}
|
|
@@ -373,7 +402,12 @@ var XMLHttpRequestController = class {
|
|
|
373
402
|
get: () => this.responseXML
|
|
374
403
|
}
|
|
375
404
|
});
|
|
376
|
-
const totalResponseBodyLength = response.headers.has("Content-Length") ? Number(response.headers.get("Content-Length")) :
|
|
405
|
+
const totalResponseBodyLength = response.headers.has("Content-Length") ? Number(response.headers.get("Content-Length")) : (
|
|
406
|
+
/**
|
|
407
|
+
* @todo Infer the response body length from the response body.
|
|
408
|
+
*/
|
|
409
|
+
void 0
|
|
410
|
+
);
|
|
377
411
|
this.logger.info("calculated response body length", totalResponseBodyLength);
|
|
378
412
|
this.trigger("loadstart", {
|
|
379
413
|
loaded: 0,
|
|
@@ -504,6 +538,9 @@ var XMLHttpRequestController = class {
|
|
|
504
538
|
this.trigger("error");
|
|
505
539
|
this.trigger("loadend");
|
|
506
540
|
}
|
|
541
|
+
/**
|
|
542
|
+
* Transitions this request's `readyState` to the given one.
|
|
543
|
+
*/
|
|
507
544
|
setReadyState(nextReadyState) {
|
|
508
545
|
this.logger.info(
|
|
509
546
|
"setReadyState: %d -> %d",
|
|
@@ -521,6 +558,9 @@ var XMLHttpRequestController = class {
|
|
|
521
558
|
this.trigger("readystatechange");
|
|
522
559
|
}
|
|
523
560
|
}
|
|
561
|
+
/**
|
|
562
|
+
* Triggers given event on the `XMLHttpRequest` instance.
|
|
563
|
+
*/
|
|
524
564
|
trigger(eventName, options) {
|
|
525
565
|
const callback = this.request[`on${eventName}`];
|
|
526
566
|
const event = createEvent(this.request, eventName, options);
|
|
@@ -540,11 +580,17 @@ var XMLHttpRequestController = class {
|
|
|
540
580
|
}
|
|
541
581
|
}
|
|
542
582
|
}
|
|
583
|
+
/**
|
|
584
|
+
* Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
|
|
585
|
+
*/
|
|
543
586
|
toFetchApiRequest() {
|
|
544
587
|
this.logger.info("converting request to a Fetch API Request...");
|
|
545
588
|
const fetchRequest = new Request(this.url.href, {
|
|
546
589
|
method: this.method,
|
|
547
590
|
headers: this.requestHeaders,
|
|
591
|
+
/**
|
|
592
|
+
* @see https://xhr.spec.whatwg.org/#cross-origin-credentials
|
|
593
|
+
*/
|
|
548
594
|
credentials: this.request.withCredentials ? "include" : "same-origin",
|
|
549
595
|
body: ["GET", "HEAD"].includes(this.method) ? null : this.requestBody
|
|
550
596
|
});
|
|
@@ -578,6 +624,7 @@ function toAbsoluteUrl(url) {
|
|
|
578
624
|
}
|
|
579
625
|
function define(target, property, value) {
|
|
580
626
|
Reflect.defineProperty(target, property, {
|
|
627
|
+
// Ensure writable properties to allow redefining readonly properties.
|
|
581
628
|
writable: true,
|
|
582
629
|
enumerable: true,
|
|
583
630
|
value
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
1
|
// src/glossary.ts
|
|
7
2
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
8
3
|
|
|
@@ -71,6 +66,11 @@ var AsyncEventEmitter = class extends Emitter {
|
|
|
71
66
|
});
|
|
72
67
|
return super.emit(eventName, ...data);
|
|
73
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Returns a promise that resolves when all the listeners for the given event
|
|
71
|
+
* has been called. Awaits asynchronous listeners.
|
|
72
|
+
* If the event has no listeners, resolves immediately.
|
|
73
|
+
*/
|
|
74
74
|
async untilIdle(eventName, filter = () => true) {
|
|
75
75
|
const listenersQueue = this.queue.get(eventName) || [];
|
|
76
76
|
await Promise.all(
|
|
@@ -112,6 +112,11 @@ var AsyncEventEmitter = class extends Emitter {
|
|
|
112
112
|
this.readyState = "ACTIVE" /* ACTIVE */;
|
|
113
113
|
logger.info("set state to:", this.readyState);
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Deactivate this event emitter.
|
|
117
|
+
* Deactivated emitter can no longer emit and listen to events
|
|
118
|
+
* and needs to be activated again in order to do so.
|
|
119
|
+
*/
|
|
115
120
|
deactivate() {
|
|
116
121
|
const logger = this.logger.extend("deactivate");
|
|
117
122
|
logger.info("removing all listeners...");
|
|
@@ -126,7 +131,10 @@ var AsyncEventEmitter = class extends Emitter {
|
|
|
126
131
|
|
|
127
132
|
// src/Interceptor.ts
|
|
128
133
|
function getGlobalSymbol(symbol) {
|
|
129
|
-
return
|
|
134
|
+
return (
|
|
135
|
+
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
|
|
136
|
+
globalThis[symbol] || void 0
|
|
137
|
+
);
|
|
130
138
|
}
|
|
131
139
|
function setGlobalSymbol(symbol, value) {
|
|
132
140
|
globalThis[symbol] = value;
|
|
@@ -152,9 +160,17 @@ var Interceptor = class {
|
|
|
152
160
|
this.emitter.setMaxListeners(0);
|
|
153
161
|
this.logger.info("constructing the interceptor...");
|
|
154
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Determine if this interceptor can be applied
|
|
165
|
+
* in the current environment.
|
|
166
|
+
*/
|
|
155
167
|
checkEnvironment() {
|
|
156
168
|
return true;
|
|
157
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Apply this interceptor to the current process.
|
|
172
|
+
* Returns an already running interceptor instance if it's present.
|
|
173
|
+
*/
|
|
158
174
|
apply() {
|
|
159
175
|
const logger = this.logger.extend("apply");
|
|
160
176
|
logger.info("applying the interceptor...");
|
|
@@ -189,8 +205,16 @@ var Interceptor = class {
|
|
|
189
205
|
this.setInstance();
|
|
190
206
|
this.readyState = "APPLIED" /* APPLIED */;
|
|
191
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Setup the module augments and stubs necessary for this interceptor.
|
|
210
|
+
* This method is not run if there's a running interceptor instance
|
|
211
|
+
* to prevent instantiating an interceptor multiple times.
|
|
212
|
+
*/
|
|
192
213
|
setup() {
|
|
193
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Listen to the interceptor's public events.
|
|
217
|
+
*/
|
|
194
218
|
on(eventName, listener) {
|
|
195
219
|
const logger = this.logger.extend("on");
|
|
196
220
|
if (this.readyState === "DISPOSING" /* DISPOSING */ || this.readyState === "DISPOSED" /* DISPOSED */) {
|
|
@@ -200,6 +224,9 @@ var Interceptor = class {
|
|
|
200
224
|
logger.info('adding "%s" event listener:', eventName, listener.name);
|
|
201
225
|
this.emitter.on(eventName, listener);
|
|
202
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Disposes of any side-effects this interceptor has introduced.
|
|
229
|
+
*/
|
|
203
230
|
dispose() {
|
|
204
231
|
const logger = this.logger.extend("dispose");
|
|
205
232
|
if (this.readyState === "DISPOSED" /* DISPOSED */) {
|
|
@@ -243,7 +270,6 @@ var Interceptor = class {
|
|
|
243
270
|
};
|
|
244
271
|
|
|
245
272
|
export {
|
|
246
|
-
__commonJS,
|
|
247
273
|
IS_PATCHED_MODULE,
|
|
248
274
|
getGlobalSymbol,
|
|
249
275
|
deleteGlobalSymbol,
|