@mswjs/interceptors 0.23.0 → 0.24.1

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.
Files changed (53) hide show
  1. package/README.md +1 -1
  2. package/lib/{node/chunk-IHW3ERPT.js → browser/chunk-3LFH2WCF.js} +1 -9
  3. package/lib/{node/chunk-MPFSBY4S.js → browser/chunk-4CFMDU7Z.js} +36 -9
  4. package/lib/{node/chunk-LTX5IGCQ.mjs → browser/chunk-7II4SWKS.mjs} +0 -8
  5. package/lib/browser/{chunk-DWXGORCS.mjs → chunk-BRIUGDYQ.mjs} +60 -11
  6. package/lib/browser/{chunk-MW6NCDWE.mjs → chunk-GXJLJMOT.mjs} +33 -7
  7. package/lib/browser/{chunk-AKTXHQ7X.mjs → chunk-KSCN3JS4.mjs} +16 -2
  8. package/lib/browser/{chunk-3GCTA2IC.js → chunk-XAQQ5IUC.js} +20 -6
  9. package/lib/browser/{chunk-OBNZMCHS.js → chunk-Y4XXQXAW.js} +67 -18
  10. package/lib/browser/index.d.ts +2 -2
  11. package/lib/browser/index.js +4 -4
  12. package/lib/browser/index.mjs +2 -2
  13. package/lib/browser/interceptors/XMLHttpRequest/index.js +4 -4
  14. package/lib/browser/interceptors/XMLHttpRequest/index.mjs +3 -3
  15. package/lib/browser/interceptors/fetch/index.js +3 -3
  16. package/lib/browser/interceptors/fetch/index.mjs +2 -2
  17. package/lib/browser/presets/browser.js +6 -6
  18. package/lib/browser/presets/browser.mjs +4 -4
  19. package/lib/node/RemoteHttpInterceptor.d.ts +2 -3
  20. package/lib/node/RemoteHttpInterceptor.js +15 -16
  21. package/lib/node/RemoteHttpInterceptor.mjs +9 -10
  22. package/lib/node/chunk-3LFH2WCF.js +21 -0
  23. package/lib/node/chunk-7II4SWKS.mjs +21 -0
  24. package/lib/node/{chunk-VJDB3MIV.js → chunk-MVPEJK4V.js} +2 -2
  25. package/lib/node/{chunk-GLYFVYMU.js → chunk-NM5BWVVB.js} +64 -15
  26. package/lib/node/{chunk-4YIZAGXJ.js → chunk-OOSIWXHX.js} +41 -8
  27. package/lib/node/{chunk-4LRRTLLD.mjs → chunk-PSIO3L7D.mjs} +39 -6
  28. package/lib/node/{chunk-Y5QA6OEZ.mjs → chunk-RGYCLCLK.mjs} +33 -10
  29. package/lib/node/{chunk-CO6XRA5H.mjs → chunk-SOWOSKLO.mjs} +60 -11
  30. package/lib/node/{chunk-NUSH7ACE.mjs → chunk-VS3GJPUE.mjs} +1 -1
  31. package/lib/{browser/chunk-7VJMJSIJ.js → node/chunk-XYZRP5S2.js} +35 -13
  32. package/lib/node/index.js +4 -4
  33. package/lib/node/index.mjs +3 -3
  34. package/lib/node/interceptors/ClientRequest/index.js +3 -3
  35. package/lib/node/interceptors/ClientRequest/index.mjs +2 -2
  36. package/lib/node/interceptors/XMLHttpRequest/index.js +4 -4
  37. package/lib/node/interceptors/XMLHttpRequest/index.mjs +3 -3
  38. package/lib/node/interceptors/fetch/index.js +17 -3
  39. package/lib/node/interceptors/fetch/index.mjs +16 -2
  40. package/lib/node/presets/node.js +6 -6
  41. package/lib/node/presets/node.mjs +4 -4
  42. package/package.json +19 -22
  43. package/src/RemoteHttpInterceptor.ts +6 -7
  44. package/src/interceptors/ClientRequest/index.test.ts +28 -0
  45. package/src/interceptors/ClientRequest/utils/createRequest.ts +0 -1
  46. package/src/interceptors/ClientRequest/utils/createResponse.ts +34 -3
  47. package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +15 -7
  48. package/src/interceptors/XMLHttpRequest/utils/createResponse.ts +40 -4
  49. package/src/interceptors/fetch/index.ts +21 -1
  50. package/src/utils/bufferUtils.ts +0 -2
  51. package/lib/browser/chunk-MQA5WAD4.mjs +0 -2139
  52. package/lib/browser/chunk-QAZ3SPQZ.js +0 -2139
  53. package/src/shims/webEncoding.ts +0 -9
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkQAZ3SPQZjs = require('./chunk-QAZ3SPQZ.js');
5
+ var _chunk3LFH2WCFjs = require('./chunk-3LFH2WCF.js');
6
6
 
7
7
 
8
8
 
@@ -10,7 +10,7 @@ var _chunkPCFJD76Xjs = require('./chunk-PCFJD76X.js');
10
10
 
11
11
 
12
12
 
13
- var _chunk7VJMJSIJjs = require('./chunk-7VJMJSIJ.js');
13
+ var _chunk4CFMDU7Zjs = require('./chunk-4CFMDU7Z.js');
14
14
 
15
15
  // src/interceptors/XMLHttpRequest/index.ts
16
16
  var _outvariant = require('outvariant');
@@ -20,7 +20,7 @@ var _until = require('@open-draft/until');
20
20
 
21
21
  // src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts
22
22
 
23
- var _headerspolyfill = require('headers-polyfill');
23
+ var _isnodeprocess = require('is-node-process');
24
24
 
25
25
  // src/interceptors/XMLHttpRequest/utils/concatArrayBuffer.ts
26
26
  function concatArrayBuffer(left, right) {
@@ -202,17 +202,34 @@ function parseJson(data) {
202
202
  }
203
203
 
204
204
  // src/interceptors/XMLHttpRequest/utils/createResponse.ts
205
-
206
- function createResponse(request, responseBody) {
207
- return new Response(responseBody, {
205
+ var statusCodesWithoutBody = [204, 205, 304];
206
+ function createResponse(request, body) {
207
+ const responseBodyOrNull = statusCodesWithoutBody.includes(request.status) ? null : body;
208
+ return new Response(responseBodyOrNull, {
208
209
  status: request.status,
209
210
  statusText: request.statusText,
210
- headers: _headerspolyfill.stringToHeaders.call(void 0, request.getAllResponseHeaders())
211
+ headers: createHeadersFromXMLHttpReqestHeaders(
212
+ request.getAllResponseHeaders()
213
+ )
211
214
  });
212
215
  }
216
+ function createHeadersFromXMLHttpReqestHeaders(headersString) {
217
+ const headers = new Headers();
218
+ const lines = headersString.split(/[\r\n]+/);
219
+ for (const line of lines) {
220
+ if (line.trim() === "") {
221
+ continue;
222
+ }
223
+ const [name, ...parts] = line.split(": ");
224
+ const value = parts.join(": ");
225
+ headers.append(name, value);
226
+ }
227
+ return headers;
228
+ }
213
229
 
214
230
  // src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts
215
231
  var IS_MOCKED_RESPONSE = Symbol("isMockedResponse");
232
+ var IS_NODE = _isnodeprocess.isNodeProcess.call(void 0, );
216
233
  var XMLHttpRequestController = class {
217
234
  constructor(initialRequest, logger) {
218
235
  this.initialRequest = initialRequest;
@@ -220,6 +237,7 @@ var XMLHttpRequestController = class {
220
237
  this.method = "GET";
221
238
  this.url = null;
222
239
  this.events = /* @__PURE__ */ new Map();
240
+ this.requestId = _chunkPCFJD76Xjs.uuidv4.call(void 0, );
223
241
  this.requestHeaders = new Headers();
224
242
  this.responseBuffer = new Uint8Array();
225
243
  this.request = createProxy(initialRequest, {
@@ -242,7 +260,6 @@ var XMLHttpRequestController = class {
242
260
  switch (methodName) {
243
261
  case "open": {
244
262
  const [method, url] = args;
245
- this.requestId = _chunkPCFJD76Xjs.uuidv4.call(void 0, );
246
263
  if (typeof url === "undefined") {
247
264
  this.method = "GET";
248
265
  this.url = toAbsoluteUrl(method);
@@ -269,12 +286,17 @@ var XMLHttpRequestController = class {
269
286
  case "send": {
270
287
  const [body] = args;
271
288
  if (body != null) {
272
- this.requestBody = typeof body === "string" ? _chunkQAZ3SPQZjs.encodeBuffer.call(void 0, body) : body;
289
+ this.requestBody = typeof body === "string" ? _chunk3LFH2WCFjs.encodeBuffer.call(void 0, body) : body;
273
290
  }
274
291
  this.request.addEventListener("load", () => {
275
292
  if (typeof this.onResponse !== "undefined") {
276
293
  const fetchResponse = createResponse(
277
294
  this.request,
295
+ /**
296
+ * The `response` property is the right way to read
297
+ * the ambiguous response body, as the request's "responseType" may differ.
298
+ * @see https://xhr.spec.whatwg.org/#the-response-attribute
299
+ */
278
300
  this.request.response
279
301
  );
280
302
  this.onResponse.call(this, {
@@ -296,7 +318,9 @@ var XMLHttpRequestController = class {
296
318
  "request callback settled but request has not been handled (readystate %d), performing as-is...",
297
319
  this.request.readyState
298
320
  );
299
- this.request.setRequestHeader("X-Request-Id", this.requestId);
321
+ if (IS_NODE) {
322
+ this.request.setRequestHeader("X-Request-Id", this.requestId);
323
+ }
300
324
  return invoke();
301
325
  }
302
326
  });
@@ -315,6 +339,10 @@ var XMLHttpRequestController = class {
315
339
  this.events.set(eventName, nextEvents);
316
340
  this.logger.info('registered event "%s"', eventName, listener.name);
317
341
  }
342
+ /**
343
+ * Responds to the current request with the given
344
+ * Fetch API `Response` instance.
345
+ */
318
346
  respondWith(response) {
319
347
  this.logger.info(
320
348
  "responding with a mocked response: %d %s",
@@ -350,7 +378,10 @@ var XMLHttpRequestController = class {
350
378
  this.logger.info("headers not received yet, returning empty string");
351
379
  return "";
352
380
  }
353
- const allHeaders = _headerspolyfill.headersToString.call(void 0, response.headers);
381
+ const headersList = Array.from(response.headers.entries());
382
+ const allHeaders = headersList.map(([headerName, headerValue]) => {
383
+ return `${headerName}: ${headerValue}`;
384
+ }).join("\r\n");
354
385
  this.logger.info("resolved all response headers to", allHeaders);
355
386
  return allHeaders;
356
387
  }
@@ -373,7 +404,12 @@ var XMLHttpRequestController = class {
373
404
  get: () => this.responseXML
374
405
  }
375
406
  });
376
- const totalResponseBodyLength = response.headers.has("Content-Length") ? Number(response.headers.get("Content-Length")) : void 0;
407
+ const totalResponseBodyLength = response.headers.has("Content-Length") ? Number(response.headers.get("Content-Length")) : (
408
+ /**
409
+ * @todo Infer the response body length from the response body.
410
+ */
411
+ void 0
412
+ );
377
413
  this.logger.info("calculated response body length", totalResponseBodyLength);
378
414
  this.trigger("loadstart", {
379
415
  loaded: 0,
@@ -419,7 +455,7 @@ var XMLHttpRequestController = class {
419
455
  }
420
456
  }
421
457
  responseBufferToText() {
422
- return _chunkQAZ3SPQZjs.decodeBuffer.call(void 0, this.responseBuffer);
458
+ return _chunk3LFH2WCFjs.decodeBuffer.call(void 0, this.responseBuffer);
423
459
  }
424
460
  get response() {
425
461
  this.logger.info(
@@ -436,7 +472,7 @@ var XMLHttpRequestController = class {
436
472
  return responseJson;
437
473
  }
438
474
  case "arraybuffer": {
439
- const arrayBuffer = _chunkQAZ3SPQZjs.toArrayBuffer.call(void 0, this.responseBuffer);
475
+ const arrayBuffer = _chunk3LFH2WCFjs.toArrayBuffer.call(void 0, this.responseBuffer);
440
476
  this.logger.info("resolved response ArrayBuffer", arrayBuffer);
441
477
  return arrayBuffer;
442
478
  }
@@ -504,6 +540,9 @@ var XMLHttpRequestController = class {
504
540
  this.trigger("error");
505
541
  this.trigger("loadend");
506
542
  }
543
+ /**
544
+ * Transitions this request's `readyState` to the given one.
545
+ */
507
546
  setReadyState(nextReadyState) {
508
547
  this.logger.info(
509
548
  "setReadyState: %d -> %d",
@@ -521,6 +560,9 @@ var XMLHttpRequestController = class {
521
560
  this.trigger("readystatechange");
522
561
  }
523
562
  }
563
+ /**
564
+ * Triggers given event on the `XMLHttpRequest` instance.
565
+ */
524
566
  trigger(eventName, options) {
525
567
  const callback = this.request[`on${eventName}`];
526
568
  const event = createEvent(this.request, eventName, options);
@@ -540,11 +582,17 @@ var XMLHttpRequestController = class {
540
582
  }
541
583
  }
542
584
  }
585
+ /**
586
+ * Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
587
+ */
543
588
  toFetchApiRequest() {
544
589
  this.logger.info("converting request to a Fetch API Request...");
545
590
  const fetchRequest = new Request(this.url.href, {
546
591
  method: this.method,
547
592
  headers: this.requestHeaders,
593
+ /**
594
+ * @see https://xhr.spec.whatwg.org/#cross-origin-credentials
595
+ */
548
596
  credentials: this.request.withCredentials ? "include" : "same-origin",
549
597
  body: ["GET", "HEAD"].includes(this.method) ? null : this.requestBody
550
598
  });
@@ -578,6 +626,7 @@ function toAbsoluteUrl(url) {
578
626
  }
579
627
  function define(target, property, value) {
580
628
  Reflect.defineProperty(target, property, {
629
+ // Ensure writable properties to allow redefining readonly properties.
581
630
  writable: true,
582
631
  enumerable: true,
583
632
  value
@@ -675,7 +724,7 @@ function createXMLHttpRequestProxy({
675
724
  }
676
725
 
677
726
  // src/interceptors/XMLHttpRequest/index.ts
678
- var _XMLHttpRequestInterceptor = class extends _chunk7VJMJSIJjs.Interceptor {
727
+ var _XMLHttpRequestInterceptor = class extends _chunk4CFMDU7Zjs.Interceptor {
679
728
  constructor() {
680
729
  super(_XMLHttpRequestInterceptor.interceptorSymbol);
681
730
  }
@@ -687,7 +736,7 @@ var _XMLHttpRequestInterceptor = class extends _chunk7VJMJSIJjs.Interceptor {
687
736
  logger.info('patching "XMLHttpRequest" module...');
688
737
  const PureXMLHttpRequest = globalThis.XMLHttpRequest;
689
738
  _outvariant.invariant.call(void 0,
690
- !PureXMLHttpRequest[_chunk7VJMJSIJjs.IS_PATCHED_MODULE],
739
+ !PureXMLHttpRequest[_chunk4CFMDU7Zjs.IS_PATCHED_MODULE],
691
740
  'Failed to patch the "XMLHttpRequest" module: already patched.'
692
741
  );
693
742
  globalThis.XMLHttpRequest = createXMLHttpRequestProxy({
@@ -698,13 +747,13 @@ var _XMLHttpRequestInterceptor = class extends _chunk7VJMJSIJjs.Interceptor {
698
747
  'native "XMLHttpRequest" module patched!',
699
748
  globalThis.XMLHttpRequest.name
700
749
  );
701
- Object.defineProperty(globalThis.XMLHttpRequest, _chunk7VJMJSIJjs.IS_PATCHED_MODULE, {
750
+ Object.defineProperty(globalThis.XMLHttpRequest, _chunk4CFMDU7Zjs.IS_PATCHED_MODULE, {
702
751
  enumerable: true,
703
752
  configurable: true,
704
753
  value: true
705
754
  });
706
755
  this.subscriptions.push(() => {
707
- Object.defineProperty(globalThis.XMLHttpRequest, _chunk7VJMJSIJjs.IS_PATCHED_MODULE, {
756
+ Object.defineProperty(globalThis.XMLHttpRequest, _chunk4CFMDU7Zjs.IS_PATCHED_MODULE, {
708
757
  value: void 0
709
758
  });
710
759
  globalThis.XMLHttpRequest = PureXMLHttpRequest;
@@ -1,5 +1,5 @@
1
1
  import { I as Interceptor, E as ExtractEventNames } from './Interceptor-0a020bc4.js';
2
- export { E as ExtractEventNames, H as HttpRequestEventMap, a as IS_PATCHED_MODULE, I as Interceptor, b as InterceptorEventMap, e as InterceptorReadyState, c as InterceptorSubscription, R as RequestCredentials, d as deleteGlobalSymbol, g as getGlobalSymbol } from './Interceptor-0a020bc4.js';
2
+ export { H as HttpRequestEventMap, a as IS_PATCHED_MODULE, b as InterceptorEventMap, e as InterceptorReadyState, c as InterceptorSubscription, R as RequestCredentials, d as deleteGlobalSymbol, g as getGlobalSymbol } from './Interceptor-0a020bc4.js';
3
3
  import { EventMap, Listener } from 'strict-event-emitter';
4
4
  import '@open-draft/logger';
5
5
 
@@ -28,4 +28,4 @@ declare function getCleanUrl(url: URL, isAbsolute?: boolean): string;
28
28
  declare function encodeBuffer(text: string): Uint8Array;
29
29
  declare function decodeBuffer(buffer: ArrayBuffer, encoding?: string): string;
30
30
 
31
- export { BatchInterceptor, BatchInterceptorOptions, ExtractEventMapType, decodeBuffer, encodeBuffer, getCleanUrl };
31
+ export { BatchInterceptor, BatchInterceptorOptions, ExtractEventMapType, ExtractEventNames, Interceptor, decodeBuffer, encodeBuffer, getCleanUrl };
@@ -1,17 +1,17 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkQAZ3SPQZjs = require('./chunk-QAZ3SPQZ.js');
4
+ var _chunk3LFH2WCFjs = require('./chunk-3LFH2WCF.js');
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
10
 
11
- var _chunk7VJMJSIJjs = require('./chunk-7VJMJSIJ.js');
11
+ var _chunk4CFMDU7Zjs = require('./chunk-4CFMDU7Z.js');
12
12
 
13
13
  // src/BatchInterceptor.ts
14
- var BatchInterceptor = class extends _chunk7VJMJSIJjs.Interceptor {
14
+ var BatchInterceptor = class extends _chunk4CFMDU7Zjs.Interceptor {
15
15
  constructor(options) {
16
16
  BatchInterceptor.symbol = Symbol(options.name);
17
17
  super(BatchInterceptor.symbol);
@@ -48,4 +48,4 @@ function getCleanUrl(url, isAbsolute = true) {
48
48
 
49
49
 
50
50
 
51
- exports.BatchInterceptor = BatchInterceptor; exports.IS_PATCHED_MODULE = _chunk7VJMJSIJjs.IS_PATCHED_MODULE; exports.Interceptor = _chunk7VJMJSIJjs.Interceptor; exports.InterceptorReadyState = _chunk7VJMJSIJjs.InterceptorReadyState; exports.decodeBuffer = _chunkQAZ3SPQZjs.decodeBuffer; exports.deleteGlobalSymbol = _chunk7VJMJSIJjs.deleteGlobalSymbol; exports.encodeBuffer = _chunkQAZ3SPQZjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunk7VJMJSIJjs.getGlobalSymbol;
51
+ exports.BatchInterceptor = BatchInterceptor; exports.IS_PATCHED_MODULE = _chunk4CFMDU7Zjs.IS_PATCHED_MODULE; exports.Interceptor = _chunk4CFMDU7Zjs.Interceptor; exports.InterceptorReadyState = _chunk4CFMDU7Zjs.InterceptorReadyState; exports.decodeBuffer = _chunk3LFH2WCFjs.decodeBuffer; exports.deleteGlobalSymbol = _chunk4CFMDU7Zjs.deleteGlobalSymbol; exports.encodeBuffer = _chunk3LFH2WCFjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunk4CFMDU7Zjs.getGlobalSymbol;
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  decodeBuffer,
3
3
  encodeBuffer
4
- } from "./chunk-MQA5WAD4.mjs";
4
+ } from "./chunk-7II4SWKS.mjs";
5
5
  import {
6
6
  IS_PATCHED_MODULE,
7
7
  Interceptor,
8
8
  InterceptorReadyState,
9
9
  deleteGlobalSymbol,
10
10
  getGlobalSymbol
11
- } from "./chunk-MW6NCDWE.mjs";
11
+ } from "./chunk-GXJLJMOT.mjs";
12
12
 
13
13
  // src/BatchInterceptor.ts
14
14
  var BatchInterceptor = class extends Interceptor {
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkOBNZMCHSjs = require('../../chunk-OBNZMCHS.js');
4
- require('../../chunk-QAZ3SPQZ.js');
3
+ var _chunkY4XXQXAWjs = require('../../chunk-Y4XXQXAW.js');
4
+ require('../../chunk-3LFH2WCF.js');
5
5
  require('../../chunk-PCFJD76X.js');
6
- require('../../chunk-7VJMJSIJ.js');
6
+ require('../../chunk-4CFMDU7Z.js');
7
7
 
8
8
 
9
- exports.XMLHttpRequestInterceptor = _chunkOBNZMCHSjs.XMLHttpRequestInterceptor;
9
+ exports.XMLHttpRequestInterceptor = _chunkY4XXQXAWjs.XMLHttpRequestInterceptor;
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  XMLHttpRequestInterceptor
3
- } from "../../chunk-DWXGORCS.mjs";
4
- import "../../chunk-MQA5WAD4.mjs";
3
+ } from "../../chunk-BRIUGDYQ.mjs";
4
+ import "../../chunk-7II4SWKS.mjs";
5
5
  import "../../chunk-RT3ATOJH.mjs";
6
- import "../../chunk-MW6NCDWE.mjs";
6
+ import "../../chunk-GXJLJMOT.mjs";
7
7
  export {
8
8
  XMLHttpRequestInterceptor
9
9
  };
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk3GCTA2ICjs = require('../../chunk-3GCTA2IC.js');
3
+ var _chunkXAQQ5IUCjs = require('../../chunk-XAQQ5IUC.js');
4
4
  require('../../chunk-PCFJD76X.js');
5
- require('../../chunk-7VJMJSIJ.js');
5
+ require('../../chunk-4CFMDU7Z.js');
6
6
 
7
7
 
8
- exports.FetchInterceptor = _chunk3GCTA2ICjs.FetchInterceptor;
8
+ exports.FetchInterceptor = _chunkXAQQ5IUCjs.FetchInterceptor;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  FetchInterceptor
3
- } from "../../chunk-AKTXHQ7X.mjs";
3
+ } from "../../chunk-KSCN3JS4.mjs";
4
4
  import "../../chunk-RT3ATOJH.mjs";
5
- import "../../chunk-MW6NCDWE.mjs";
5
+ import "../../chunk-GXJLJMOT.mjs";
6
6
  export {
7
7
  FetchInterceptor
8
8
  };
@@ -1,17 +1,17 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkOBNZMCHSjs = require('../chunk-OBNZMCHS.js');
4
- require('../chunk-QAZ3SPQZ.js');
3
+ var _chunkY4XXQXAWjs = require('../chunk-Y4XXQXAW.js');
4
+ require('../chunk-3LFH2WCF.js');
5
5
 
6
6
 
7
- var _chunk3GCTA2ICjs = require('../chunk-3GCTA2IC.js');
7
+ var _chunkXAQQ5IUCjs = require('../chunk-XAQQ5IUC.js');
8
8
  require('../chunk-PCFJD76X.js');
9
- require('../chunk-7VJMJSIJ.js');
9
+ require('../chunk-4CFMDU7Z.js');
10
10
 
11
11
  // src/presets/browser.ts
12
12
  var browser_default = [
13
- new (0, _chunk3GCTA2ICjs.FetchInterceptor)(),
14
- new (0, _chunkOBNZMCHSjs.XMLHttpRequestInterceptor)()
13
+ new (0, _chunkXAQQ5IUCjs.FetchInterceptor)(),
14
+ new (0, _chunkY4XXQXAWjs.XMLHttpRequestInterceptor)()
15
15
  ];
16
16
 
17
17
 
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  XMLHttpRequestInterceptor
3
- } from "../chunk-DWXGORCS.mjs";
4
- import "../chunk-MQA5WAD4.mjs";
3
+ } from "../chunk-BRIUGDYQ.mjs";
4
+ import "../chunk-7II4SWKS.mjs";
5
5
  import {
6
6
  FetchInterceptor
7
- } from "../chunk-AKTXHQ7X.mjs";
7
+ } from "../chunk-KSCN3JS4.mjs";
8
8
  import "../chunk-RT3ATOJH.mjs";
9
- import "../chunk-MW6NCDWE.mjs";
9
+ import "../chunk-GXJLJMOT.mjs";
10
10
 
11
11
  // src/presets/browser.ts
12
12
  var browser_default = [
@@ -1,5 +1,4 @@
1
1
  import { ChildProcess } from 'child_process';
2
- import { HeadersObject } from 'headers-polyfill';
3
2
  import { e as Interceptor, H as HttpRequestEventMap } from './Interceptor-738f79c5.js';
4
3
  import { a as BatchInterceptor } from './BatchInterceptor-c841b068.js';
5
4
  import { ClientRequestInterceptor } from './interceptors/ClientRequest/index.js';
@@ -13,14 +12,14 @@ interface SerializedRequest {
13
12
  id: string;
14
13
  url: string;
15
14
  method: string;
16
- headers: HeadersObject;
15
+ headers: Array<[string, string]>;
17
16
  credentials: RequestCredentials;
18
17
  body: string;
19
18
  }
20
19
  interface SerializedResponse {
21
20
  status: number;
22
21
  statusText: string;
23
- headers: HeadersObject;
22
+ headers: Array<[string, string]>;
24
23
  body: string;
25
24
  }
26
25
  declare class RemoteHttpInterceptor extends BatchInterceptor<[
@@ -1,30 +1,29 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkVJDB3MIVjs = require('./chunk-VJDB3MIV.js');
3
+ var _chunkMVPEJK4Vjs = require('./chunk-MVPEJK4V.js');
4
4
 
5
5
 
6
- var _chunk4YIZAGXJjs = require('./chunk-4YIZAGXJ.js');
6
+ var _chunkOOSIWXHXjs = require('./chunk-OOSIWXHX.js');
7
7
 
8
8
 
9
- var _chunkGLYFVYMUjs = require('./chunk-GLYFVYMU.js');
10
- require('./chunk-IHW3ERPT.js');
9
+ var _chunkNM5BWVVBjs = require('./chunk-NM5BWVVB.js');
10
+ require('./chunk-3LFH2WCF.js');
11
11
  require('./chunk-VQ4DZOBB.js');
12
12
 
13
13
 
14
14
  var _chunkZJOF5MEZjs = require('./chunk-ZJOF5MEZ.js');
15
15
 
16
16
 
17
- var _chunkMPFSBY4Sjs = require('./chunk-MPFSBY4S.js');
17
+ var _chunkXYZRP5S2js = require('./chunk-XYZRP5S2.js');
18
18
 
19
19
  // src/RemoteHttpInterceptor.ts
20
- var _headerspolyfill = require('headers-polyfill');
21
- var RemoteHttpInterceptor = class extends _chunkVJDB3MIVjs.BatchInterceptor {
20
+ var RemoteHttpInterceptor = class extends _chunkMVPEJK4Vjs.BatchInterceptor {
22
21
  constructor() {
23
22
  super({
24
23
  name: "remote-interceptor",
25
24
  interceptors: [
26
- new (0, _chunk4YIZAGXJjs.ClientRequestInterceptor)(),
27
- new (0, _chunkGLYFVYMUjs.XMLHttpRequestInterceptor)()
25
+ new (0, _chunkOOSIWXHXjs.ClientRequestInterceptor)(),
26
+ new (0, _chunkNM5BWVVBjs.XMLHttpRequestInterceptor)()
28
27
  ]
29
28
  });
30
29
  }
@@ -37,7 +36,7 @@ var RemoteHttpInterceptor = class extends _chunkVJDB3MIVjs.BatchInterceptor {
37
36
  id: requestId,
38
37
  method: request.method,
39
38
  url: request.url,
40
- headers: _headerspolyfill.headersToObject.call(void 0, request.headers),
39
+ headers: Array.from(request.headers.entries()),
41
40
  credentials: request.credentials,
42
41
  body: ["GET", "HEAD"].includes(request.method) ? null : await request.text()
43
42
  });
@@ -62,10 +61,10 @@ var RemoteHttpInterceptor = class extends _chunkVJDB3MIVjs.BatchInterceptor {
62
61
  const mockedResponse = new Response(responseInit.body, {
63
62
  status: responseInit.status,
64
63
  statusText: responseInit.statusText,
65
- headers: new (0, _headerspolyfill.Headers)(responseInit.headers)
64
+ headers: responseInit.headers
66
65
  });
67
66
  request.respondWith(mockedResponse);
68
- resolve();
67
+ return resolve();
69
68
  }
70
69
  };
71
70
  });
@@ -86,12 +85,12 @@ function requestReviver(key, value) {
86
85
  case "url":
87
86
  return new URL(value);
88
87
  case "headers":
89
- return new (0, _headerspolyfill.Headers)(value);
88
+ return new Headers(value);
90
89
  default:
91
90
  return value;
92
91
  }
93
92
  }
94
- var _RemoteHttpResolver = class extends _chunkMPFSBY4Sjs.Interceptor {
93
+ var _RemoteHttpResolver = class extends _chunkXYZRP5S2js.Interceptor {
95
94
  constructor(options) {
96
95
  super(_RemoteHttpResolver.symbol);
97
96
  this.process = options.process;
@@ -115,7 +114,7 @@ var _RemoteHttpResolver = class extends _chunkMPFSBY4Sjs.Interceptor {
115
114
  logger.info("parsed intercepted request", requestJson);
116
115
  const capturedRequest = new Request(requestJson.url, {
117
116
  method: requestJson.method,
118
- headers: new (0, _headerspolyfill.Headers)(requestJson.headers),
117
+ headers: new Headers(requestJson.headers),
119
118
  credentials: requestJson.credentials,
120
119
  body: requestJson.body
121
120
  });
@@ -140,7 +139,7 @@ var _RemoteHttpResolver = class extends _chunkMPFSBY4Sjs.Interceptor {
140
139
  const serializedResponse = JSON.stringify({
141
140
  status: mockedResponse.status,
142
141
  statusText: mockedResponse.statusText,
143
- headers: _headerspolyfill.headersToObject.call(void 0, mockedResponse.headers),
142
+ headers: Array.from(mockedResponse.headers.entries()),
144
143
  body: responseText
145
144
  });
146
145
  this.process.send(
@@ -1,23 +1,22 @@
1
1
  import {
2
2
  BatchInterceptor
3
- } from "./chunk-NUSH7ACE.mjs";
3
+ } from "./chunk-VS3GJPUE.mjs";
4
4
  import {
5
5
  ClientRequestInterceptor
6
- } from "./chunk-4LRRTLLD.mjs";
6
+ } from "./chunk-PSIO3L7D.mjs";
7
7
  import {
8
8
  XMLHttpRequestInterceptor
9
- } from "./chunk-CO6XRA5H.mjs";
10
- import "./chunk-LTX5IGCQ.mjs";
9
+ } from "./chunk-SOWOSKLO.mjs";
10
+ import "./chunk-7II4SWKS.mjs";
11
11
  import "./chunk-GFH37L5D.mjs";
12
12
  import {
13
13
  toInteractiveRequest
14
14
  } from "./chunk-STA6QBYM.mjs";
15
15
  import {
16
16
  Interceptor
17
- } from "./chunk-Y5QA6OEZ.mjs";
17
+ } from "./chunk-RGYCLCLK.mjs";
18
18
 
19
19
  // src/RemoteHttpInterceptor.ts
20
- import { Headers, headersToObject } from "headers-polyfill";
21
20
  var RemoteHttpInterceptor = class extends BatchInterceptor {
22
21
  constructor() {
23
22
  super({
@@ -37,7 +36,7 @@ var RemoteHttpInterceptor = class extends BatchInterceptor {
37
36
  id: requestId,
38
37
  method: request.method,
39
38
  url: request.url,
40
- headers: headersToObject(request.headers),
39
+ headers: Array.from(request.headers.entries()),
41
40
  credentials: request.credentials,
42
41
  body: ["GET", "HEAD"].includes(request.method) ? null : await request.text()
43
42
  });
@@ -62,10 +61,10 @@ var RemoteHttpInterceptor = class extends BatchInterceptor {
62
61
  const mockedResponse = new Response(responseInit.body, {
63
62
  status: responseInit.status,
64
63
  statusText: responseInit.statusText,
65
- headers: new Headers(responseInit.headers)
64
+ headers: responseInit.headers
66
65
  });
67
66
  request.respondWith(mockedResponse);
68
- resolve();
67
+ return resolve();
69
68
  }
70
69
  };
71
70
  });
@@ -140,7 +139,7 @@ var _RemoteHttpResolver = class extends Interceptor {
140
139
  const serializedResponse = JSON.stringify({
141
140
  status: mockedResponse.status,
142
141
  statusText: mockedResponse.statusText,
143
- headers: headersToObject(mockedResponse.headers),
142
+ headers: Array.from(mockedResponse.headers.entries()),
144
143
  body: responseText
145
144
  });
146
145
  this.process.send(
@@ -0,0 +1,21 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/bufferUtils.ts
2
+ var encoder = new TextEncoder();
3
+ function encodeBuffer(text) {
4
+ return encoder.encode(text);
5
+ }
6
+ function decodeBuffer(buffer, encoding) {
7
+ const decoder = new TextDecoder(encoding);
8
+ return decoder.decode(buffer);
9
+ }
10
+ function toArrayBuffer(array) {
11
+ return array.buffer.slice(
12
+ array.byteOffset,
13
+ array.byteOffset + array.byteLength
14
+ );
15
+ }
16
+
17
+
18
+
19
+
20
+
21
+ exports.encodeBuffer = encodeBuffer; exports.decodeBuffer = decodeBuffer; exports.toArrayBuffer = toArrayBuffer;
@@ -0,0 +1,21 @@
1
+ // src/utils/bufferUtils.ts
2
+ var encoder = new TextEncoder();
3
+ function encodeBuffer(text) {
4
+ return encoder.encode(text);
5
+ }
6
+ function decodeBuffer(buffer, encoding) {
7
+ const decoder = new TextDecoder(encoding);
8
+ return decoder.decode(buffer);
9
+ }
10
+ function toArrayBuffer(array) {
11
+ return array.buffer.slice(
12
+ array.byteOffset,
13
+ array.byteOffset + array.byteLength
14
+ );
15
+ }
16
+
17
+ export {
18
+ encodeBuffer,
19
+ decodeBuffer,
20
+ toArrayBuffer
21
+ };
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMPFSBY4Sjs = require('./chunk-MPFSBY4S.js');
3
+ var _chunkXYZRP5S2js = require('./chunk-XYZRP5S2.js');
4
4
 
5
5
  // src/BatchInterceptor.ts
6
- var BatchInterceptor = class extends _chunkMPFSBY4Sjs.Interceptor {
6
+ var BatchInterceptor = class extends _chunkXYZRP5S2js.Interceptor {
7
7
  constructor(options) {
8
8
  BatchInterceptor.symbol = Symbol(options.name);
9
9
  super(BatchInterceptor.symbol);