msw 2.12.6 → 2.12.8

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 (62) hide show
  1. package/lib/browser/index.js +641 -925
  2. package/lib/browser/index.js.map +1 -1
  3. package/lib/browser/index.mjs +641 -925
  4. package/lib/browser/index.mjs.map +1 -1
  5. package/lib/core/{HttpResponse-DM21DMt_.d.ts → HttpResponse-CVs3ngx3.d.ts} +12 -2
  6. package/lib/core/{HttpResponse-C86fdZzb.d.mts → HttpResponse-Cw4ELwIN.d.mts} +12 -2
  7. package/lib/core/HttpResponse.d.mts +1 -1
  8. package/lib/core/HttpResponse.d.ts +1 -1
  9. package/lib/core/SetupApi.d.mts +1 -1
  10. package/lib/core/SetupApi.d.ts +1 -1
  11. package/lib/core/getResponse.d.mts +1 -1
  12. package/lib/core/getResponse.d.ts +1 -1
  13. package/lib/core/graphql.d.mts +21 -59
  14. package/lib/core/graphql.d.ts +21 -59
  15. package/lib/core/graphql.js +14 -15
  16. package/lib/core/graphql.js.map +1 -1
  17. package/lib/core/graphql.mjs +14 -15
  18. package/lib/core/graphql.mjs.map +1 -1
  19. package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
  20. package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
  21. package/lib/core/handlers/GraphQLHandler.js +42 -17
  22. package/lib/core/handlers/GraphQLHandler.js.map +1 -1
  23. package/lib/core/handlers/GraphQLHandler.mjs +44 -17
  24. package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
  25. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  26. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  27. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  28. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  29. package/lib/core/http.d.mts +1 -1
  30. package/lib/core/http.d.ts +1 -1
  31. package/lib/core/index.d.mts +2 -2
  32. package/lib/core/index.d.ts +2 -2
  33. package/lib/core/index.js.map +1 -1
  34. package/lib/core/index.mjs.map +1 -1
  35. package/lib/core/passthrough.d.mts +1 -1
  36. package/lib/core/passthrough.d.ts +1 -1
  37. package/lib/core/sse.d.mts +1 -1
  38. package/lib/core/sse.d.ts +1 -1
  39. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  40. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  41. package/lib/core/utils/executeHandlers.d.mts +1 -1
  42. package/lib/core/utils/executeHandlers.d.ts +1 -1
  43. package/lib/core/utils/handleRequest.d.mts +1 -1
  44. package/lib/core/utils/handleRequest.d.ts +1 -1
  45. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  46. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  47. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
  48. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
  49. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  50. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  51. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  52. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  53. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  54. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  55. package/lib/iife/index.js +977 -1407
  56. package/lib/iife/index.js.map +1 -1
  57. package/lib/mockServiceWorker.js +1 -1
  58. package/package.json +5 -5
  59. package/src/core/graphql.ts +43 -52
  60. package/src/core/handlers/GraphQLHandler.test.ts +1 -1
  61. package/src/core/handlers/GraphQLHandler.ts +73 -25
  62. package/src/core/index.ts +6 -1
@@ -467,20 +467,165 @@ You can also automate this process and make the worker script update automatical
467
467
  return integrityCheckPromise;
468
468
  }
469
469
 
470
- // node_modules/.pnpm/@mswjs+interceptors@0.40.0/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
471
- var encoder = new TextEncoder();
472
- function encodeBuffer(text) {
473
- return encoder.encode(text);
474
- }
475
- function decodeBuffer(buffer, encoding) {
476
- const decoder = new TextDecoder(encoding);
477
- return decoder.decode(buffer);
470
+ // node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-BTaNLFr0.mjs
471
+ var IS_PATCHED_MODULE = Symbol("isPatchedModule");
472
+ var InterceptorError = class InterceptorError2 extends Error {
473
+ constructor(message) {
474
+ super(message);
475
+ this.name = "InterceptorError";
476
+ Object.setPrototypeOf(this, InterceptorError2.prototype);
477
+ }
478
+ };
479
+ var RequestController = class RequestController2 {
480
+ static {
481
+ this.PENDING = 0;
482
+ }
483
+ static {
484
+ this.PASSTHROUGH = 1;
485
+ }
486
+ static {
487
+ this.RESPONSE = 2;
488
+ }
489
+ static {
490
+ this.ERROR = 3;
491
+ }
492
+ constructor(request, source) {
493
+ this.request = request;
494
+ this.source = source;
495
+ this.readyState = RequestController2.PENDING;
496
+ this.handled = new DeferredPromise();
497
+ }
498
+ get #handled() {
499
+ return this.handled;
500
+ }
501
+ /**
502
+ * Perform this request as-is.
503
+ */
504
+ async passthrough() {
505
+ invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to passthrough the "%s %s" request: the request has already been handled', this.request.method, this.request.url);
506
+ this.readyState = RequestController2.PASSTHROUGH;
507
+ await this.source.passthrough();
508
+ this.#handled.resolve();
509
+ }
510
+ /**
511
+ * Respond to this request with the given `Response` instance.
512
+ *
513
+ * @example
514
+ * controller.respondWith(new Response())
515
+ * controller.respondWith(Response.json({ id }))
516
+ * controller.respondWith(Response.error())
517
+ */
518
+ respondWith(response) {
519
+ invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to respond to the "%s %s" request with "%d %s": the request has already been handled (%d)', this.request.method, this.request.url, response.status, response.statusText || "OK", this.readyState);
520
+ this.readyState = RequestController2.RESPONSE;
521
+ this.#handled.resolve();
522
+ this.source.respondWith(response);
523
+ }
524
+ /**
525
+ * Error this request with the given reason.
526
+ *
527
+ * @example
528
+ * controller.errorWith()
529
+ * controller.errorWith(new Error('Oops!'))
530
+ * controller.errorWith({ message: 'Oops!'})
531
+ */
532
+ errorWith(reason) {
533
+ invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to error the "%s %s" request with "%s": the request has already been handled (%d)', this.request.method, this.request.url, reason?.toString(), this.readyState);
534
+ this.readyState = RequestController2.ERROR;
535
+ this.source.errorWith(reason);
536
+ this.#handled.resolve();
537
+ }
538
+ };
539
+ function canParseUrl(url) {
540
+ try {
541
+ new URL(url);
542
+ return true;
543
+ } catch (_error) {
544
+ return false;
545
+ }
478
546
  }
479
- function toArrayBuffer(array) {
480
- return array.buffer.slice(
481
- array.byteOffset,
482
- array.byteOffset + array.byteLength
483
- );
547
+ function getValueBySymbol(symbolName, source) {
548
+ const symbol = Object.getOwnPropertySymbols(source).find((symbol$1) => {
549
+ return symbol$1.description === symbolName;
550
+ });
551
+ if (symbol) return Reflect.get(source, symbol);
552
+ }
553
+ var FetchResponse = class FetchResponse2 extends Response {
554
+ static {
555
+ this.STATUS_CODES_WITHOUT_BODY = [
556
+ 101,
557
+ 103,
558
+ 204,
559
+ 205,
560
+ 304
561
+ ];
562
+ }
563
+ static {
564
+ this.STATUS_CODES_WITH_REDIRECT = [
565
+ 301,
566
+ 302,
567
+ 303,
568
+ 307,
569
+ 308
570
+ ];
571
+ }
572
+ static isConfigurableStatusCode(status) {
573
+ return status >= 200 && status <= 599;
574
+ }
575
+ static isRedirectResponse(status) {
576
+ return FetchResponse2.STATUS_CODES_WITH_REDIRECT.includes(status);
577
+ }
578
+ /**
579
+ * Returns a boolean indicating whether the given response status
580
+ * code represents a response that can have a body.
581
+ */
582
+ static isResponseWithBody(status) {
583
+ return !FetchResponse2.STATUS_CODES_WITHOUT_BODY.includes(status);
584
+ }
585
+ static setUrl(url, response) {
586
+ if (!url || url === "about:" || !canParseUrl(url)) return;
587
+ const state = getValueBySymbol("state", response);
588
+ if (state) state.urlList.push(new URL(url));
589
+ else Object.defineProperty(response, "url", {
590
+ value: url,
591
+ enumerable: true,
592
+ configurable: true,
593
+ writable: false
594
+ });
595
+ }
596
+ /**
597
+ * Parses the given raw HTTP headers into a Fetch API `Headers` instance.
598
+ */
599
+ static parseRawHeaders(rawHeaders) {
600
+ const headers = new Headers();
601
+ for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
602
+ return headers;
603
+ }
604
+ constructor(body, init = {}) {
605
+ const status = init.status ?? 200;
606
+ const safeStatus = FetchResponse2.isConfigurableStatusCode(status) ? status : 200;
607
+ const finalBody = FetchResponse2.isResponseWithBody(status) ? body : null;
608
+ super(finalBody, {
609
+ status: safeStatus,
610
+ statusText: init.statusText,
611
+ headers: init.headers
612
+ });
613
+ if (status !== safeStatus) {
614
+ const state = getValueBySymbol("state", this);
615
+ if (state) state.status = status;
616
+ else Object.defineProperty(this, "status", {
617
+ value: status,
618
+ enumerable: true,
619
+ configurable: true,
620
+ writable: false
621
+ });
622
+ }
623
+ FetchResponse2.setUrl(init.url, this);
624
+ }
625
+ };
626
+ var kRawRequest = Symbol("kRawRequest");
627
+ function setRawRequest(request, rawRequest) {
628
+ Reflect.set(request, kRawRequest, rawRequest);
484
629
  }
485
630
 
486
631
  // node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
@@ -920,26 +1065,10 @@ var _Emitter = class {
920
1065
  var Emitter = _Emitter;
921
1066
  Emitter.defaultMaxListeners = 10;
922
1067
 
923
- // node_modules/.pnpm/@mswjs+interceptors@0.40.0/node_modules/@mswjs/interceptors/lib/browser/chunk-Z5TSB3T6.mjs
924
- var __accessCheck = (obj, member, msg) => {
925
- if (!member.has(obj))
926
- throw TypeError("Cannot " + msg);
927
- };
928
- var __privateGet = (obj, member, getter) => {
929
- __accessCheck(obj, member, "read from private field");
930
- return getter ? getter.call(obj) : member.get(obj);
931
- };
932
- var __privateAdd = (obj, member, value) => {
933
- if (member.has(obj))
934
- throw TypeError("Cannot add the same private member more than once");
935
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
936
- };
1068
+ // node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DQcIlohW.mjs
937
1069
  var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
938
1070
  function getGlobalSymbol(symbol) {
939
- return (
940
- // @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
941
- globalThis[symbol] || void 0
942
- );
1071
+ return globalThis[symbol] || void 0;
943
1072
  }
944
1073
  function setGlobalSymbol(symbol, value) {
945
1074
  globalThis[symbol] = value;
@@ -947,10 +1076,18 @@ function setGlobalSymbol(symbol, value) {
947
1076
  function deleteGlobalSymbol(symbol) {
948
1077
  delete globalThis[symbol];
949
1078
  }
1079
+ var InterceptorReadyState = /* @__PURE__ */ (function(InterceptorReadyState$1) {
1080
+ InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
1081
+ InterceptorReadyState$1["APPLYING"] = "APPLYING";
1082
+ InterceptorReadyState$1["APPLIED"] = "APPLIED";
1083
+ InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
1084
+ InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
1085
+ return InterceptorReadyState$1;
1086
+ })({});
950
1087
  var Interceptor = class {
951
1088
  constructor(symbol) {
952
1089
  this.symbol = symbol;
953
- this.readyState = "INACTIVE";
1090
+ this.readyState = InterceptorReadyState.INACTIVE;
954
1091
  this.emitter = new Emitter();
955
1092
  this.subscriptions = [];
956
1093
  this.logger = new Logger(symbol.description);
@@ -958,29 +1095,28 @@ var Interceptor = class {
958
1095
  this.logger.info("constructing the interceptor...");
959
1096
  }
960
1097
  /**
961
- * Determine if this interceptor can be applied
962
- * in the current environment.
963
- */
1098
+ * Determine if this interceptor can be applied
1099
+ * in the current environment.
1100
+ */
964
1101
  checkEnvironment() {
965
1102
  return true;
966
1103
  }
967
1104
  /**
968
- * Apply this interceptor to the current process.
969
- * Returns an already running interceptor instance if it's present.
970
- */
1105
+ * Apply this interceptor to the current process.
1106
+ * Returns an already running interceptor instance if it's present.
1107
+ */
971
1108
  apply() {
972
1109
  const logger = this.logger.extend("apply");
973
1110
  logger.info("applying the interceptor...");
974
- if (this.readyState === "APPLIED") {
1111
+ if (this.readyState === InterceptorReadyState.APPLIED) {
975
1112
  logger.info("intercepted already applied!");
976
1113
  return;
977
1114
  }
978
- const shouldApply = this.checkEnvironment();
979
- if (!shouldApply) {
1115
+ if (!this.checkEnvironment()) {
980
1116
  logger.info("the interceptor cannot be applied in this environment!");
981
1117
  return;
982
1118
  }
983
- this.readyState = "APPLYING";
1119
+ this.readyState = InterceptorReadyState.APPLYING;
984
1120
  const runningInstance = this.getInstance();
985
1121
  if (runningInstance) {
986
1122
  logger.info("found a running instance, reusing...");
@@ -993,27 +1129,27 @@ var Interceptor = class {
993
1129
  });
994
1130
  return this;
995
1131
  };
996
- this.readyState = "APPLIED";
1132
+ this.readyState = InterceptorReadyState.APPLIED;
997
1133
  return;
998
1134
  }
999
1135
  logger.info("no running instance found, setting up a new instance...");
1000
1136
  this.setup();
1001
1137
  this.setInstance();
1002
- this.readyState = "APPLIED";
1138
+ this.readyState = InterceptorReadyState.APPLIED;
1003
1139
  }
1004
1140
  /**
1005
- * Setup the module augments and stubs necessary for this interceptor.
1006
- * This method is not run if there's a running interceptor instance
1007
- * to prevent instantiating an interceptor multiple times.
1008
- */
1141
+ * Setup the module augments and stubs necessary for this interceptor.
1142
+ * This method is not run if there's a running interceptor instance
1143
+ * to prevent instantiating an interceptor multiple times.
1144
+ */
1009
1145
  setup() {
1010
1146
  }
1011
1147
  /**
1012
- * Listen to the interceptor's public events.
1013
- */
1148
+ * Listen to the interceptor's public events.
1149
+ */
1014
1150
  on(event, listener) {
1015
1151
  const logger = this.logger.extend("on");
1016
- if (this.readyState === "DISPOSING" || this.readyState === "DISPOSED") {
1152
+ if (this.readyState === InterceptorReadyState.DISPOSING || this.readyState === InterceptorReadyState.DISPOSED) {
1017
1153
  logger.info("cannot listen to events, already disposed!");
1018
1154
  return this;
1019
1155
  }
@@ -1034,16 +1170,16 @@ var Interceptor = class {
1034
1170
  return this;
1035
1171
  }
1036
1172
  /**
1037
- * Disposes of any side-effects this interceptor has introduced.
1038
- */
1173
+ * Disposes of any side-effects this interceptor has introduced.
1174
+ */
1039
1175
  dispose() {
1040
1176
  const logger = this.logger.extend("dispose");
1041
- if (this.readyState === "DISPOSED") {
1177
+ if (this.readyState === InterceptorReadyState.DISPOSED) {
1042
1178
  logger.info("cannot dispose, already disposed!");
1043
1179
  return;
1044
1180
  }
1045
1181
  logger.info("disposing the interceptor...");
1046
- this.readyState = "DISPOSING";
1182
+ this.readyState = InterceptorReadyState.DISPOSING;
1047
1183
  if (!this.getInstance()) {
1048
1184
  logger.info("no interceptors running, skipping dispose...");
1049
1185
  return;
@@ -1052,20 +1188,17 @@ var Interceptor = class {
1052
1188
  logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
1053
1189
  if (this.subscriptions.length > 0) {
1054
1190
  logger.info("disposing of %d subscriptions...", this.subscriptions.length);
1055
- for (const dispose of this.subscriptions) {
1056
- dispose();
1057
- }
1191
+ for (const dispose of this.subscriptions) dispose();
1058
1192
  this.subscriptions = [];
1059
1193
  logger.info("disposed of all subscriptions!", this.subscriptions.length);
1060
1194
  }
1061
1195
  this.emitter.removeAllListeners();
1062
1196
  logger.info("destroyed the listener!");
1063
- this.readyState = "DISPOSED";
1197
+ this.readyState = InterceptorReadyState.DISPOSED;
1064
1198
  }
1065
1199
  getInstance() {
1066
- var _a;
1067
1200
  const instance = getGlobalSymbol(this.symbol);
1068
- this.logger.info("retrieved global instance:", (_a = instance == null ? void 0 : instance.constructor) == null ? void 0 : _a.name);
1201
+ this.logger.info("retrieved global instance:", instance?.constructor?.name);
1069
1202
  return instance;
1070
1203
  }
1071
1204
  setInstance() {
@@ -1081,192 +1214,23 @@ function createRequestId() {
1081
1214
  return Math.random().toString(16).slice(2);
1082
1215
  }
1083
1216
 
1084
- // node_modules/.pnpm/@mswjs+interceptors@0.40.0/node_modules/@mswjs/interceptors/lib/browser/chunk-LIKZF2VU.mjs
1085
- var IS_PATCHED_MODULE = Symbol("isPatchedModule");
1086
- var InterceptorError = class extends Error {
1087
- constructor(message) {
1088
- super(message);
1089
- this.name = "InterceptorError";
1090
- Object.setPrototypeOf(this, InterceptorError.prototype);
1091
- }
1092
- };
1093
- var _handled;
1094
- var handled_get;
1095
- var _RequestController = class {
1096
- constructor(request, source) {
1097
- this.request = request;
1098
- this.source = source;
1099
- __privateAdd(this, _handled);
1100
- this.readyState = _RequestController.PENDING;
1101
- this.handled = new DeferredPromise();
1102
- }
1103
- /**
1104
- * Perform this request as-is.
1105
- */
1106
- async passthrough() {
1107
- invariant.as(
1108
- InterceptorError,
1109
- this.readyState === _RequestController.PENDING,
1110
- 'Failed to passthrough the "%s %s" request: the request has already been handled',
1111
- this.request.method,
1112
- this.request.url
1113
- );
1114
- this.readyState = _RequestController.PASSTHROUGH;
1115
- await this.source.passthrough();
1116
- __privateGet(this, _handled, handled_get).resolve();
1117
- }
1118
- /**
1119
- * Respond to this request with the given `Response` instance.
1120
- *
1121
- * @example
1122
- * controller.respondWith(new Response())
1123
- * controller.respondWith(Response.json({ id }))
1124
- * controller.respondWith(Response.error())
1125
- */
1126
- respondWith(response) {
1127
- invariant.as(
1128
- InterceptorError,
1129
- this.readyState === _RequestController.PENDING,
1130
- 'Failed to respond to the "%s %s" request with "%d %s": the request has already been handled (%d)',
1131
- this.request.method,
1132
- this.request.url,
1133
- response.status,
1134
- response.statusText || "OK",
1135
- this.readyState
1136
- );
1137
- this.readyState = _RequestController.RESPONSE;
1138
- __privateGet(this, _handled, handled_get).resolve();
1139
- this.source.respondWith(response);
1140
- }
1141
- /**
1142
- * Error this request with the given reason.
1143
- *
1144
- * @example
1145
- * controller.errorWith()
1146
- * controller.errorWith(new Error('Oops!'))
1147
- * controller.errorWith({ message: 'Oops!'})
1148
- */
1149
- errorWith(reason) {
1150
- invariant.as(
1151
- InterceptorError,
1152
- this.readyState === _RequestController.PENDING,
1153
- 'Failed to error the "%s %s" request with "%s": the request has already been handled (%d)',
1154
- this.request.method,
1155
- this.request.url,
1156
- reason == null ? void 0 : reason.toString(),
1157
- this.readyState
1158
- );
1159
- this.readyState = _RequestController.ERROR;
1160
- this.source.errorWith(reason);
1161
- __privateGet(this, _handled, handled_get).resolve();
1162
- }
1163
- };
1164
- var RequestController = _RequestController;
1165
- _handled = /* @__PURE__ */ new WeakSet();
1166
- handled_get = function() {
1167
- return this.handled;
1168
- };
1169
- RequestController.PENDING = 0;
1170
- RequestController.PASSTHROUGH = 1;
1171
- RequestController.RESPONSE = 2;
1172
- RequestController.ERROR = 3;
1173
- function canParseUrl(url) {
1174
- try {
1175
- new URL(url);
1176
- return true;
1177
- } catch (_error) {
1178
- return false;
1179
- }
1217
+ // node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/bufferUtils-BiiO6HZv.mjs
1218
+ var encoder = new TextEncoder();
1219
+ function encodeBuffer(text) {
1220
+ return encoder.encode(text);
1180
1221
  }
1181
- function getValueBySymbol(symbolName, source) {
1182
- const ownSymbols = Object.getOwnPropertySymbols(source);
1183
- const symbol = ownSymbols.find((symbol2) => {
1184
- return symbol2.description === symbolName;
1185
- });
1186
- if (symbol) {
1187
- return Reflect.get(source, symbol);
1188
- }
1189
- return;
1222
+ function decodeBuffer(buffer, encoding) {
1223
+ return new TextDecoder(encoding).decode(buffer);
1190
1224
  }
1191
- var _FetchResponse = class extends Response {
1192
- static isConfigurableStatusCode(status) {
1193
- return status >= 200 && status <= 599;
1194
- }
1195
- static isRedirectResponse(status) {
1196
- return _FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
1197
- }
1198
- /**
1199
- * Returns a boolean indicating whether the given response status
1200
- * code represents a response that can have a body.
1201
- */
1202
- static isResponseWithBody(status) {
1203
- return !_FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
1204
- }
1205
- static setUrl(url, response) {
1206
- if (!url || url === "about:" || !canParseUrl(url)) {
1207
- return;
1208
- }
1209
- const state = getValueBySymbol("state", response);
1210
- if (state) {
1211
- state.urlList.push(new URL(url));
1212
- } else {
1213
- Object.defineProperty(response, "url", {
1214
- value: url,
1215
- enumerable: true,
1216
- configurable: true,
1217
- writable: false
1218
- });
1219
- }
1220
- }
1221
- /**
1222
- * Parses the given raw HTTP headers into a Fetch API `Headers` instance.
1223
- */
1224
- static parseRawHeaders(rawHeaders) {
1225
- const headers = new Headers();
1226
- for (let line = 0; line < rawHeaders.length; line += 2) {
1227
- headers.append(rawHeaders[line], rawHeaders[line + 1]);
1228
- }
1229
- return headers;
1230
- }
1231
- constructor(body, init = {}) {
1232
- var _a;
1233
- const status = (_a = init.status) != null ? _a : 200;
1234
- const safeStatus = _FetchResponse.isConfigurableStatusCode(status) ? status : 200;
1235
- const finalBody = _FetchResponse.isResponseWithBody(status) ? body : null;
1236
- super(finalBody, {
1237
- status: safeStatus,
1238
- statusText: init.statusText,
1239
- headers: init.headers
1240
- });
1241
- if (status !== safeStatus) {
1242
- const state = getValueBySymbol("state", this);
1243
- if (state) {
1244
- state.status = status;
1245
- } else {
1246
- Object.defineProperty(this, "status", {
1247
- value: status,
1248
- enumerable: true,
1249
- configurable: true,
1250
- writable: false
1251
- });
1252
- }
1253
- }
1254
- _FetchResponse.setUrl(init.url, this);
1255
- }
1256
- };
1257
- var FetchResponse = _FetchResponse;
1258
- FetchResponse.STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304];
1259
- FetchResponse.STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308];
1260
- var kRawRequest = Symbol("kRawRequest");
1261
- function setRawRequest(request, rawRequest) {
1262
- Reflect.set(request, kRawRequest, rawRequest);
1225
+ function toArrayBuffer(array) {
1226
+ return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
1263
1227
  }
1264
1228
 
1265
- // node_modules/.pnpm/@mswjs+interceptors@0.40.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
1266
- var BatchInterceptor = class extends Interceptor {
1229
+ // node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
1230
+ var BatchInterceptor = class BatchInterceptor2 extends Interceptor {
1267
1231
  constructor(options) {
1268
- BatchInterceptor.symbol = Symbol(options.name);
1269
- super(BatchInterceptor.symbol);
1232
+ BatchInterceptor2.symbol = Symbol(options.name);
1233
+ super(BatchInterceptor2.symbol);
1270
1234
  this.interceptors = options.interceptors;
1271
1235
  }
1272
1236
  setup() {
@@ -1280,27 +1244,19 @@ var BatchInterceptor = class extends Interceptor {
1280
1244
  }
1281
1245
  }
1282
1246
  on(event, listener) {
1283
- for (const interceptor of this.interceptors) {
1284
- interceptor.on(event, listener);
1285
- }
1247
+ for (const interceptor of this.interceptors) interceptor.on(event, listener);
1286
1248
  return this;
1287
1249
  }
1288
1250
  once(event, listener) {
1289
- for (const interceptor of this.interceptors) {
1290
- interceptor.once(event, listener);
1291
- }
1251
+ for (const interceptor of this.interceptors) interceptor.once(event, listener);
1292
1252
  return this;
1293
1253
  }
1294
1254
  off(event, listener) {
1295
- for (const interceptor of this.interceptors) {
1296
- interceptor.off(event, listener);
1297
- }
1255
+ for (const interceptor of this.interceptors) interceptor.off(event, listener);
1298
1256
  return this;
1299
1257
  }
1300
1258
  removeAllListeners(event) {
1301
- for (const interceptors of this.interceptors) {
1302
- interceptors.removeAllListeners(event);
1303
- }
1259
+ for (const interceptors of this.interceptors) interceptors.removeAllListeners(event);
1304
1260
  return this;
1305
1261
  }
1306
1262
  };
@@ -1445,16 +1401,85 @@ import { webSocketInterceptor } from '../core/ws/webSocketInterceptor.mjs';
1445
1401
  import { handleWebSocketEvent } from '../core/ws/handleWebSocketEvent.mjs';
1446
1402
  import { attachWebSocketLogger } from '../core/ws/utils/attachWebSocketLogger.mjs';
1447
1403
 
1448
- // node_modules/.pnpm/rettime@0.7.0/node_modules/rettime/build/index.js
1404
+ // node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/lens-list.mjs
1405
+ var LensList = class {
1406
+ #list;
1407
+ #lens;
1408
+ constructor() {
1409
+ this.#list = [];
1410
+ this.#lens = /* @__PURE__ */ new Map();
1411
+ }
1412
+ get [Symbol.iterator]() {
1413
+ return this.#list[Symbol.iterator].bind(this.#list);
1414
+ }
1415
+ entries() {
1416
+ return this.#lens.entries();
1417
+ }
1418
+ /**
1419
+ * Return an order-sensitive list of values by the given key.
1420
+ */
1421
+ get(key) {
1422
+ return this.#lens.get(key) || [];
1423
+ }
1424
+ /**
1425
+ * Return an order-sensitive list of all values.
1426
+ */
1427
+ getAll() {
1428
+ return this.#list.map(([, value]) => value);
1429
+ }
1430
+ /**
1431
+ * Append a new value to the given key.
1432
+ */
1433
+ append(key, value) {
1434
+ this.#list.push([key, value]);
1435
+ this.#openLens(key, (list) => list.push(value));
1436
+ }
1437
+ /**
1438
+ * Prepend a new value to the given key.
1439
+ */
1440
+ prepend(key, value) {
1441
+ this.#list.unshift([key, value]);
1442
+ this.#openLens(key, (list) => list.unshift(value));
1443
+ }
1444
+ /**
1445
+ * Delete the value belonging to the given key.
1446
+ */
1447
+ delete(key, value) {
1448
+ if (this.size === 0) return;
1449
+ this.#list = this.#list.filter((item) => item[1] !== value);
1450
+ for (const [existingKey, values] of this.#lens) if (existingKey === key && values.includes(value)) values.splice(values.indexOf(value), 1);
1451
+ }
1452
+ /**
1453
+ * Delete all values belogning to the given key.
1454
+ */
1455
+ deleteAll(key) {
1456
+ if (this.size === 0) return;
1457
+ this.#list = this.#list.filter((item) => item[0] !== key);
1458
+ this.#lens.delete(key);
1459
+ }
1460
+ get size() {
1461
+ return this.#list.length;
1462
+ }
1463
+ clear() {
1464
+ if (this.size === 0) return;
1465
+ this.#list.length = 0;
1466
+ this.#lens.clear();
1467
+ }
1468
+ #openLens(key, setter) {
1469
+ setter(this.#lens.get(key) || this.#lens.set(key, []).get(key));
1470
+ }
1471
+ };
1472
+
1473
+ // node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/index.mjs
1449
1474
  var kDefaultPrevented = Symbol("kDefaultPrevented");
1450
1475
  var kPropagationStopped = Symbol("kPropagationStopped");
1451
1476
  var kImmediatePropagationStopped = Symbol("kImmediatePropagationStopped");
1452
1477
  var TypedEvent = class extends MessageEvent {
1453
1478
  /**
1454
- * @note Keep a placeholder property with the return type
1455
- * because the type must be set somewhere in order to be
1456
- * correctly associated and inferred from the event.
1457
- */
1479
+ * @note Keep a placeholder property with the return type
1480
+ * because the type must be set somewhere in order to be
1481
+ * correctly associated and inferred from the event.
1482
+ */
1458
1483
  #returnType;
1459
1484
  [kDefaultPrevented];
1460
1485
  [kPropagationStopped];
@@ -1479,189 +1504,157 @@ var kListenerOptions = Symbol("kListenerOptions");
1479
1504
  var Emitter2 = class {
1480
1505
  #listeners;
1481
1506
  constructor() {
1482
- this.#listeners = {};
1507
+ this.#listeners = new LensList();
1483
1508
  }
1484
1509
  /**
1485
- * Adds a listener for the given event type.
1486
- *
1487
- * @returns {AbortController} An `AbortController` that can be used to remove the listener.
1488
- */
1510
+ * Adds a listener for the given event type.
1511
+ */
1489
1512
  on(type, listener, options) {
1490
- return this.#addListener(type, listener, options);
1513
+ this.#addListener(type, listener, options);
1514
+ return this;
1491
1515
  }
1492
1516
  /**
1493
- * Adds a one-time listener for the given event type.
1494
- *
1495
- * @returns {AbortController} An `AbortController` that can be used to remove the listener.
1496
- */
1517
+ * Adds a one-time listener for the given event type.
1518
+ */
1497
1519
  once(type, listener, options) {
1498
- return this.on(type, listener, { ...options || {}, once: true });
1520
+ return this.on(type, listener, {
1521
+ ...options || {},
1522
+ once: true
1523
+ });
1499
1524
  }
1500
1525
  /**
1501
- * Prepends a listener for the given event type.
1502
- *
1503
- * @returns {AbortController} An `AbortController` that can be used to remove the listener.
1504
- */
1526
+ * Prepends a listener for the given event type.
1527
+ */
1505
1528
  earlyOn(type, listener, options) {
1506
- return this.#addListener(type, listener, options, "prepend");
1529
+ this.#addListener(type, listener, options, "prepend");
1530
+ return this;
1507
1531
  }
1508
1532
  /**
1509
- * Prepends a one-time listener for the given event type.
1510
- */
1533
+ * Prepends a one-time listener for the given event type.
1534
+ */
1511
1535
  earlyOnce(type, listener, options) {
1512
- return this.earlyOn(type, listener, { ...options || {}, once: true });
1536
+ return this.earlyOn(type, listener, {
1537
+ ...options || {},
1538
+ once: true
1539
+ });
1513
1540
  }
1514
1541
  /**
1515
- * Emits the given typed event.
1516
- *
1517
- * @returns {boolean} Returns `true` if the event had any listeners, `false` otherwise.
1518
- */
1542
+ * Emits the given typed event.
1543
+ *
1544
+ * @returns {boolean} Returns `true` if the event had any listeners, `false` otherwise.
1545
+ */
1519
1546
  emit(event) {
1520
- if (this.listenerCount(event.type) === 0) {
1521
- return false;
1522
- }
1547
+ if (this.#listeners.size === 0) return false;
1548
+ const hasListeners = this.listenerCount(event.type) > 0;
1523
1549
  const proxiedEvent = this.#proxyEvent(event);
1524
- for (const listener of this.#listeners[event.type]) {
1550
+ for (const listener of this.#matchListeners(event.type)) {
1525
1551
  if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
1552
+ proxiedEvent.revoke();
1526
1553
  return false;
1527
1554
  }
1528
- if (proxiedEvent.event[kImmediatePropagationStopped]) {
1529
- break;
1530
- }
1555
+ if (proxiedEvent.event[kImmediatePropagationStopped]) break;
1531
1556
  this.#callListener(proxiedEvent.event, listener);
1532
1557
  }
1533
1558
  proxiedEvent.revoke();
1534
- return true;
1559
+ return hasListeners;
1535
1560
  }
1536
1561
  /**
1537
- * Emits the given typed event and returns a promise that resolves
1538
- * when all the listeners for that event have settled.
1539
- *
1540
- * @returns {Promise<Array<Emitter.ListenerReturnType>>} A promise that resolves
1541
- * with the return values of all listeners.
1542
- */
1562
+ * Emits the given typed event and returns a promise that resolves
1563
+ * when all the listeners for that event have settled.
1564
+ *
1565
+ * @returns {Promise<Array<Emitter.ListenerReturnType>>} A promise that resolves
1566
+ * with the return values of all listeners.
1567
+ */
1543
1568
  async emitAsPromise(event) {
1544
- if (this.listenerCount(event.type) === 0) {
1545
- return [];
1546
- }
1569
+ if (this.#listeners.size === 0) return [];
1547
1570
  const pendingListeners = [];
1548
1571
  const proxiedEvent = this.#proxyEvent(event);
1549
- for (const listener of this.#listeners[event.type]) {
1572
+ for (const listener of this.#matchListeners(event.type)) {
1550
1573
  if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
1574
+ proxiedEvent.revoke();
1551
1575
  return [];
1552
1576
  }
1553
- if (proxiedEvent.event[kImmediatePropagationStopped]) {
1554
- break;
1555
- }
1556
- pendingListeners.push(
1557
- // Awaiting individual listeners guarantees their call order.
1558
- await Promise.resolve(this.#callListener(proxiedEvent.event, listener))
1559
- );
1577
+ if (proxiedEvent.event[kImmediatePropagationStopped]) break;
1578
+ const returnValue = await Promise.resolve(this.#callListener(proxiedEvent.event, listener));
1579
+ if (!this.#isTypelessListener(listener)) pendingListeners.push(returnValue);
1560
1580
  }
1561
1581
  proxiedEvent.revoke();
1562
1582
  return Promise.allSettled(pendingListeners).then((results) => {
1563
- return results.map(
1564
- (result) => result.status === "fulfilled" ? result.value : result.reason
1565
- );
1583
+ return results.map((result) => result.status === "fulfilled" ? result.value : result.reason);
1566
1584
  });
1567
1585
  }
1568
1586
  /**
1569
- * Emits the given event and returns a generator that yields
1570
- * the result of each listener in the order of their registration.
1571
- * This way, you stop exhausting the listeners once you get the expected value.
1572
- */
1587
+ * Emits the given event and returns a generator that yields
1588
+ * the result of each listener in the order of their registration.
1589
+ * This way, you stop exhausting the listeners once you get the expected value.
1590
+ */
1573
1591
  *emitAsGenerator(event) {
1574
- if (this.listenerCount(event.type) === 0) {
1575
- return;
1576
- }
1592
+ if (this.#listeners.size === 0) return;
1577
1593
  const proxiedEvent = this.#proxyEvent(event);
1578
- for (const listener of this.#listeners[event.type]) {
1594
+ for (const listener of this.#matchListeners(event.type)) {
1579
1595
  if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
1596
+ proxiedEvent.revoke();
1580
1597
  return;
1581
1598
  }
1582
- if (proxiedEvent.event[kImmediatePropagationStopped]) {
1583
- break;
1584
- }
1585
- yield this.#callListener(proxiedEvent.event, listener);
1599
+ if (proxiedEvent.event[kImmediatePropagationStopped]) break;
1600
+ const returnValue = this.#callListener(proxiedEvent.event, listener);
1601
+ if (!this.#isTypelessListener(listener)) yield returnValue;
1586
1602
  }
1587
1603
  proxiedEvent.revoke();
1588
1604
  }
1589
1605
  /**
1590
- * Removes a listener for the given event type.
1591
- */
1606
+ * Removes a listener for the given event type.
1607
+ */
1592
1608
  removeListener(type, listener) {
1593
- if (this.listenerCount(type) === 0) {
1594
- return;
1595
- }
1596
- const nextListeners = [];
1597
- for (const existingListener of this.#listeners[type]) {
1598
- if (existingListener !== listener) {
1599
- nextListeners.push(existingListener);
1600
- }
1601
- }
1602
- this.#listeners[type] = nextListeners;
1609
+ this.#listeners.delete(type, listener);
1603
1610
  }
1604
1611
  /**
1605
- * Removes all listeners for the given event type.
1606
- * If no event type is provided, removes all existing listeners.
1607
- */
1612
+ * Removes all listeners for the given event type.
1613
+ * If no event type is provided, removes all existing listeners.
1614
+ */
1608
1615
  removeAllListeners(type) {
1609
1616
  if (type == null) {
1610
- this.#listeners = {};
1617
+ this.#listeners.clear();
1611
1618
  return;
1612
1619
  }
1613
- this.#listeners[type] = [];
1620
+ this.#listeners.deleteAll(type);
1614
1621
  }
1615
1622
  /**
1616
- * Returns the list of listeners for the given event type.
1617
- * If no even type is provided, returns all listeners.
1618
- */
1623
+ * Returns the list of listeners for the given event type.
1624
+ * If no even type is provided, returns all listeners.
1625
+ */
1619
1626
  listeners(type) {
1620
- if (type == null) {
1621
- return Object.values(this.#listeners).flat();
1622
- }
1623
- return this.#listeners[type] || [];
1627
+ if (type == null) return this.#listeners.getAll();
1628
+ return this.#listeners.get(type);
1624
1629
  }
1625
1630
  /**
1626
- * Returns the number of listeners for the given event type.
1627
- * If no even type is provided, returns the total number of listeners.
1628
- */
1631
+ * Returns the number of listeners for the given event type.
1632
+ * If no even type is provided, returns the total number of listeners.
1633
+ */
1629
1634
  listenerCount(type) {
1635
+ if (type == null) return this.#listeners.size;
1630
1636
  return this.listeners(type).length;
1631
1637
  }
1632
1638
  #addListener(type, listener, options, insertMode = "append") {
1633
- this.#listeners[type] ??= [];
1634
- if (insertMode === "prepend") {
1635
- this.#listeners[type].unshift(listener);
1636
- } else {
1637
- this.#listeners[type].push(listener);
1638
- }
1639
+ if (insertMode === "prepend") this.#listeners.prepend(type, listener);
1640
+ else this.#listeners.append(type, listener);
1639
1641
  if (options) {
1640
1642
  Object.defineProperty(listener, kListenerOptions, {
1641
1643
  value: options,
1642
1644
  enumerable: false,
1643
1645
  writable: false
1644
1646
  });
1645
- if (options.signal) {
1646
- options.signal.addEventListener(
1647
- "abort",
1648
- () => {
1649
- this.removeListener(type, listener);
1650
- },
1651
- { once: true }
1652
- );
1653
- }
1647
+ if (options.signal) options.signal.addEventListener("abort", () => {
1648
+ this.removeListener(type, listener);
1649
+ }, { once: true });
1654
1650
  }
1655
- return this;
1656
1651
  }
1657
1652
  #proxyEvent(event) {
1658
1653
  const { stopPropagation } = event;
1659
- event.stopPropagation = new Proxy(event.stopPropagation, {
1660
- apply: (target, thisArg, argArray) => {
1661
- event[kPropagationStopped] = this;
1662
- return Reflect.apply(target, thisArg, argArray);
1663
- }
1664
- });
1654
+ event.stopPropagation = new Proxy(event.stopPropagation, { apply: (target, thisArg, argArray) => {
1655
+ event[kPropagationStopped] = this;
1656
+ return Reflect.apply(target, thisArg, argArray);
1657
+ } });
1665
1658
  return {
1666
1659
  event,
1667
1660
  revoke() {
@@ -1672,10 +1665,21 @@ var Emitter2 = class {
1672
1665
  #callListener(event, listener) {
1673
1666
  const returnValue = listener.call(this, event);
1674
1667
  if (listener[kListenerOptions]?.once) {
1675
- this.removeListener(event.type, listener);
1668
+ const key = this.#isTypelessListener(listener) ? "*" : event.type;
1669
+ this.#listeners.delete(key, listener);
1676
1670
  }
1677
1671
  return returnValue;
1678
1672
  }
1673
+ /**
1674
+ * Return a list of all event listeners relevant for the given event type.
1675
+ * This includes the explicit event listeners and also typeless event listeners.
1676
+ */
1677
+ *#matchListeners(type) {
1678
+ for (const [key, listener] of this.#listeners) if (key === "*" || key === type) yield listener;
1679
+ }
1680
+ #isTypelessListener(listener) {
1681
+ return this.#listeners.get("*").includes(listener);
1682
+ }
1679
1683
  };
1680
1684
 
1681
1685
  // src/browser/utils/workerChannel.ts
@@ -1738,31 +1742,19 @@ var WorkerChannel = class extends Emitter2 {
1738
1742
  }
1739
1743
  };
1740
1744
 
1741
- // node_modules/.pnpm/@mswjs+interceptors@0.40.0/node_modules/@mswjs/interceptors/lib/browser/chunk-VYSDLBSS.mjs
1745
+ // node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-C8kXFDic.mjs
1742
1746
  async function emitAsync(emitter, eventName, ...data) {
1743
1747
  const listeners = emitter.listeners(eventName);
1744
- if (listeners.length === 0) {
1745
- return;
1746
- }
1747
- for (const listener of listeners) {
1748
- await listener.apply(emitter, data);
1749
- }
1748
+ if (listeners.length === 0) return;
1749
+ for (const listener of listeners) await listener.apply(emitter, data);
1750
1750
  }
1751
1751
  function hasConfigurableGlobal(propertyName) {
1752
1752
  const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
1753
- if (typeof descriptor === "undefined") {
1754
- return false;
1755
- }
1756
- if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") {
1757
- return false;
1758
- }
1759
- if (typeof descriptor.get === "undefined" && descriptor.value == null) {
1760
- return false;
1761
- }
1753
+ if (typeof descriptor === "undefined") return false;
1754
+ if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
1755
+ if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
1762
1756
  if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
1763
- console.error(
1764
- `[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`
1765
- );
1757
+ console.error(`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`);
1766
1758
  return false;
1767
1759
  }
1768
1760
  return true;
@@ -1780,7 +1772,7 @@ var until2 = async (promise) => {
1780
1772
  }
1781
1773
  };
1782
1774
 
1783
- // node_modules/.pnpm/@mswjs+interceptors@0.40.0/node_modules/@mswjs/interceptors/lib/browser/chunk-VOUOVDAW.mjs
1775
+ // node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/handleRequest-DxGbCTbb.mjs
1784
1776
  function isObject2(value, loose = false) {
1785
1777
  return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
1786
1778
  }
@@ -1788,27 +1780,20 @@ function isPropertyAccessible(obj, key) {
1788
1780
  try {
1789
1781
  obj[key];
1790
1782
  return true;
1791
- } catch (e) {
1783
+ } catch {
1792
1784
  return false;
1793
1785
  }
1794
1786
  }
1795
1787
  function createServerErrorResponse(body) {
1796
- return new Response(
1797
- JSON.stringify(
1798
- body instanceof Error ? {
1799
- name: body.name,
1800
- message: body.message,
1801
- stack: body.stack
1802
- } : body
1803
- ),
1804
- {
1805
- status: 500,
1806
- statusText: "Unhandled Exception",
1807
- headers: {
1808
- "Content-Type": "application/json"
1809
- }
1810
- }
1811
- );
1788
+ return new Response(JSON.stringify(body instanceof Error ? {
1789
+ name: body.name,
1790
+ message: body.message,
1791
+ stack: body.stack
1792
+ } : body), {
1793
+ status: 500,
1794
+ statusText: "Unhandled Exception",
1795
+ headers: { "Content-Type": "application/json" }
1796
+ });
1812
1797
  }
1813
1798
  function isResponseError(response) {
1814
1799
  return response != null && response instanceof Response && isPropertyAccessible(response, "type") && response.type === "error";
@@ -1817,12 +1802,8 @@ function isResponseLike(value) {
1817
1802
  return isObject2(value, true) && isPropertyAccessible(value, "status") && isPropertyAccessible(value, "statusText") && isPropertyAccessible(value, "bodyUsed");
1818
1803
  }
1819
1804
  function isNodeLikeError(error2) {
1820
- if (error2 == null) {
1821
- return false;
1822
- }
1823
- if (!(error2 instanceof Error)) {
1824
- return false;
1825
- }
1805
+ if (error2 == null) return false;
1806
+ if (!(error2 instanceof Error)) return false;
1826
1807
  return "code" in error2 && "errno" in error2;
1827
1808
  }
1828
1809
  async function handleRequest2(options) {
@@ -1846,16 +1827,12 @@ async function handleRequest2(options) {
1846
1827
  return false;
1847
1828
  };
1848
1829
  const handleResponseError = async (error2) => {
1849
- if (error2 instanceof InterceptorError) {
1850
- throw result.error;
1851
- }
1830
+ if (error2 instanceof InterceptorError) throw result.error;
1852
1831
  if (isNodeLikeError(error2)) {
1853
1832
  await options.controller.errorWith(error2);
1854
1833
  return true;
1855
1834
  }
1856
- if (error2 instanceof Response) {
1857
- return await handleResponse(error2);
1858
- }
1835
+ if (error2 instanceof Response) return await handleResponse(error2);
1859
1836
  return false;
1860
1837
  };
1861
1838
  const requestAbortPromise = new DeferredPromise();
@@ -1864,13 +1841,9 @@ async function handleRequest2(options) {
1864
1841
  await options.controller.errorWith(options.request.signal.reason);
1865
1842
  return;
1866
1843
  }
1867
- options.request.signal.addEventListener(
1868
- "abort",
1869
- () => {
1870
- requestAbortPromise.reject(options.request.signal.reason);
1871
- },
1872
- { once: true }
1873
- );
1844
+ options.request.signal.addEventListener("abort", () => {
1845
+ requestAbortPromise.reject(options.request.signal.reason);
1846
+ }, { once: true });
1874
1847
  }
1875
1848
  const result = await until2(async () => {
1876
1849
  const requestListenersPromise = emitAsync(options.emitter, "request", {
@@ -1879,7 +1852,6 @@ async function handleRequest2(options) {
1879
1852
  controller: options.controller
1880
1853
  });
1881
1854
  await Promise.race([
1882
- // Short-circuit the request handling promise if the request gets aborted.
1883
1855
  requestAbortPromise,
1884
1856
  requestListenersPromise,
1885
1857
  options.controller.handled
@@ -1890,54 +1862,36 @@ async function handleRequest2(options) {
1890
1862
  return;
1891
1863
  }
1892
1864
  if (result.error) {
1893
- if (await handleResponseError(result.error)) {
1894
- return;
1895
- }
1865
+ if (await handleResponseError(result.error)) return;
1896
1866
  if (options.emitter.listenerCount("unhandledException") > 0) {
1897
- const unhandledExceptionController = new RequestController(
1898
- options.request,
1899
- {
1900
- /**
1901
- * @note Intentionally empty passthrough handle.
1902
- * This controller is created within another controller and we only need
1903
- * to know if `unhandledException` listeners handled the request.
1904
- */
1905
- passthrough() {
1906
- },
1907
- async respondWith(response) {
1908
- await handleResponse(response);
1909
- },
1910
- async errorWith(reason) {
1911
- await options.controller.errorWith(reason);
1912
- }
1867
+ const unhandledExceptionController = new RequestController(options.request, {
1868
+ passthrough() {
1869
+ },
1870
+ async respondWith(response) {
1871
+ await handleResponse(response);
1872
+ },
1873
+ async errorWith(reason) {
1874
+ await options.controller.errorWith(reason);
1913
1875
  }
1914
- );
1876
+ });
1915
1877
  await emitAsync(options.emitter, "unhandledException", {
1916
1878
  error: result.error,
1917
1879
  request: options.request,
1918
1880
  requestId: options.requestId,
1919
1881
  controller: unhandledExceptionController
1920
1882
  });
1921
- if (unhandledExceptionController.readyState !== RequestController.PENDING) {
1922
- return;
1923
- }
1883
+ if (unhandledExceptionController.readyState !== RequestController.PENDING) return;
1924
1884
  }
1925
- await options.controller.respondWith(
1926
- createServerErrorResponse(result.error)
1927
- );
1885
+ await options.controller.respondWith(createServerErrorResponse(result.error));
1928
1886
  return;
1929
1887
  }
1930
- if (options.controller.readyState === RequestController.PENDING) {
1931
- return await options.controller.passthrough();
1932
- }
1888
+ if (options.controller.readyState === RequestController.PENDING) return await options.controller.passthrough();
1933
1889
  return options.controller.handled;
1934
1890
  }
1935
1891
 
1936
- // node_modules/.pnpm/@mswjs+interceptors@0.40.0/node_modules/@mswjs/interceptors/lib/browser/chunk-WOWPV4GR.mjs
1892
+ // node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/fetch-DSJoynSF.mjs
1937
1893
  function createNetworkError(cause) {
1938
- return Object.assign(new TypeError("Failed to fetch"), {
1939
- cause
1940
- });
1894
+ return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
1941
1895
  }
1942
1896
  var REQUEST_BODY_HEADERS = [
1943
1897
  "content-encoding",
@@ -1948,9 +1902,7 @@ var REQUEST_BODY_HEADERS = [
1948
1902
  ];
1949
1903
  var kRedirectCount = Symbol("kRedirectCount");
1950
1904
  async function followFetchRedirect(request, response) {
1951
- if (response.status !== 303 && request.body != null) {
1952
- return Promise.reject(createNetworkError());
1953
- }
1905
+ if (response.status !== 303 && request.body != null) return Promise.reject(createNetworkError());
1954
1906
  const requestUrl = new URL(request.url);
1955
1907
  let locationUrl;
1956
1908
  try {
@@ -1958,22 +1910,10 @@ async function followFetchRedirect(request, response) {
1958
1910
  } catch (error2) {
1959
1911
  return Promise.reject(createNetworkError(error2));
1960
1912
  }
1961
- if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) {
1962
- return Promise.reject(
1963
- createNetworkError("URL scheme must be a HTTP(S) scheme")
1964
- );
1965
- }
1966
- if (Reflect.get(request, kRedirectCount) > 20) {
1967
- return Promise.reject(createNetworkError("redirect count exceeded"));
1968
- }
1969
- Object.defineProperty(request, kRedirectCount, {
1970
- value: (Reflect.get(request, kRedirectCount) || 0) + 1
1971
- });
1972
- if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) {
1973
- return Promise.reject(
1974
- createNetworkError('cross origin not allowed for request mode "cors"')
1975
- );
1976
- }
1913
+ if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) return Promise.reject(createNetworkError("URL scheme must be a HTTP(S) scheme"));
1914
+ if (Reflect.get(request, kRedirectCount) > 20) return Promise.reject(createNetworkError("redirect count exceeded"));
1915
+ Object.defineProperty(request, kRedirectCount, { value: (Reflect.get(request, kRedirectCount) || 0) + 1 });
1916
+ if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) return Promise.reject(createNetworkError('cross origin not allowed for request mode "cors"'));
1977
1917
  const requestInit = {};
1978
1918
  if ([301, 302].includes(response.status) && request.method === "POST" || response.status === 303 && !["HEAD", "GET"].includes(request.method)) {
1979
1919
  requestInit.method = "GET";
@@ -1997,111 +1937,74 @@ async function followFetchRedirect(request, response) {
1997
1937
  return finalResponse;
1998
1938
  }
1999
1939
  function sameOrigin(left, right) {
2000
- if (left.origin === right.origin && left.origin === "null") {
2001
- return true;
2002
- }
2003
- if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) {
2004
- return true;
2005
- }
1940
+ if (left.origin === right.origin && left.origin === "null") return true;
1941
+ if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) return true;
2006
1942
  return false;
2007
1943
  }
2008
1944
  var BrotliDecompressionStream = class extends TransformStream {
2009
1945
  constructor() {
2010
- console.warn(
2011
- "[Interceptors]: Brotli decompression of response streams is not supported in the browser"
2012
- );
2013
- super({
2014
- transform(chunk, controller) {
2015
- controller.enqueue(chunk);
2016
- }
2017
- });
1946
+ console.warn("[Interceptors]: Brotli decompression of response streams is not supported in the browser");
1947
+ super({ transform(chunk, controller) {
1948
+ controller.enqueue(chunk);
1949
+ } });
2018
1950
  }
2019
1951
  };
2020
1952
  var PipelineStream = class extends TransformStream {
2021
1953
  constructor(transformStreams, ...strategies) {
2022
1954
  super({}, ...strategies);
2023
- const readable = [super.readable, ...transformStreams].reduce(
2024
- (readable2, transform) => readable2.pipeThrough(transform)
2025
- );
2026
- Object.defineProperty(this, "readable", {
2027
- get() {
2028
- return readable;
2029
- }
2030
- });
1955
+ const readable = [super.readable, ...transformStreams].reduce((readable$1, transform) => readable$1.pipeThrough(transform));
1956
+ Object.defineProperty(this, "readable", { get() {
1957
+ return readable;
1958
+ } });
2031
1959
  }
2032
1960
  };
2033
1961
  function parseContentEncoding(contentEncoding) {
2034
1962
  return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
2035
1963
  }
2036
1964
  function createDecompressionStream(contentEncoding) {
2037
- if (contentEncoding === "") {
2038
- return null;
2039
- }
1965
+ if (contentEncoding === "") return null;
2040
1966
  const codings = parseContentEncoding(contentEncoding);
2041
- if (codings.length === 0) {
2042
- return null;
2043
- }
2044
- const transformers = codings.reduceRight(
2045
- (transformers2, coding) => {
2046
- if (coding === "gzip" || coding === "x-gzip") {
2047
- return transformers2.concat(new DecompressionStream("gzip"));
2048
- } else if (coding === "deflate") {
2049
- return transformers2.concat(new DecompressionStream("deflate"));
2050
- } else if (coding === "br") {
2051
- return transformers2.concat(new BrotliDecompressionStream());
2052
- } else {
2053
- transformers2.length = 0;
2054
- }
2055
- return transformers2;
2056
- },
2057
- []
2058
- );
2059
- return new PipelineStream(transformers);
1967
+ if (codings.length === 0) return null;
1968
+ return new PipelineStream(codings.reduceRight((transformers, coding) => {
1969
+ if (coding === "gzip" || coding === "x-gzip") return transformers.concat(new DecompressionStream("gzip"));
1970
+ else if (coding === "deflate") return transformers.concat(new DecompressionStream("deflate"));
1971
+ else if (coding === "br") return transformers.concat(new BrotliDecompressionStream());
1972
+ else transformers.length = 0;
1973
+ return transformers;
1974
+ }, []));
2060
1975
  }
2061
1976
  function decompressResponse(response) {
2062
- if (response.body === null) {
2063
- return null;
2064
- }
2065
- const decompressionStream = createDecompressionStream(
2066
- response.headers.get("content-encoding") || ""
2067
- );
2068
- if (!decompressionStream) {
2069
- return null;
2070
- }
1977
+ if (response.body === null) return null;
1978
+ const decompressionStream = createDecompressionStream(response.headers.get("content-encoding") || "");
1979
+ if (!decompressionStream) return null;
2071
1980
  response.body.pipeTo(decompressionStream.writable);
2072
1981
  return decompressionStream.readable;
2073
1982
  }
2074
- var _FetchInterceptor = class extends Interceptor {
1983
+ var FetchInterceptor = class FetchInterceptor2 extends Interceptor {
1984
+ static {
1985
+ this.symbol = Symbol("fetch");
1986
+ }
2075
1987
  constructor() {
2076
- super(_FetchInterceptor.symbol);
1988
+ super(FetchInterceptor2.symbol);
2077
1989
  }
2078
1990
  checkEnvironment() {
2079
1991
  return hasConfigurableGlobal("fetch");
2080
1992
  }
2081
1993
  async setup() {
2082
1994
  const pureFetch = globalThis.fetch;
2083
- invariant(
2084
- !pureFetch[IS_PATCHED_MODULE],
2085
- 'Failed to patch the "fetch" module: already patched.'
2086
- );
1995
+ invariant(!pureFetch[IS_PATCHED_MODULE], 'Failed to patch the "fetch" module: already patched.');
2087
1996
  globalThis.fetch = async (input, init) => {
2088
1997
  const requestId = createRequestId();
2089
1998
  const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.href) : input;
2090
1999
  const request = new Request(resolvedInput, init);
2091
- if (input instanceof Request) {
2092
- setRawRequest(request, input);
2093
- }
2000
+ if (input instanceof Request) setRawRequest(request, input);
2094
2001
  const responsePromise = new DeferredPromise();
2095
2002
  const controller = new RequestController(request, {
2096
2003
  passthrough: async () => {
2097
2004
  this.logger.info("request has not been handled, passthrough...");
2098
2005
  const requestCloneForResponseEvent = request.clone();
2099
- const { error: responseError, data: originalResponse } = await until2(
2100
- () => pureFetch(request)
2101
- );
2102
- if (responseError) {
2103
- return responsePromise.reject(responseError);
2104
- }
2006
+ const { error: responseError, data: originalResponse } = await until2(() => pureFetch(request));
2007
+ if (responseError) return responsePromise.reject(responseError);
2105
2008
  this.logger.info("original fetch performed", originalResponse);
2106
2009
  if (this.emitter.listenerCount("response") > 0) {
2107
2010
  this.logger.info('emitting the "response" event...');
@@ -2121,9 +2024,7 @@ var _FetchInterceptor = class extends Interceptor {
2121
2024
  responsePromise.reject(createNetworkError(rawResponse));
2122
2025
  return;
2123
2026
  }
2124
- this.logger.info("received mocked response!", {
2125
- rawResponse
2126
- });
2027
+ this.logger.info("received mocked response!", { rawResponse });
2127
2028
  const decompressedStream = decompressResponse(rawResponse);
2128
2029
  const response = decompressedStream === null ? rawResponse : new FetchResponse(decompressedStream, rawResponse);
2129
2030
  FetchResponse.setUrl(request.url, response);
@@ -2133,23 +2034,17 @@ var _FetchInterceptor = class extends Interceptor {
2133
2034
  return;
2134
2035
  }
2135
2036
  if (request.redirect === "follow") {
2136
- followFetchRedirect(request, response).then(
2137
- (response2) => {
2138
- responsePromise.resolve(response2);
2139
- },
2140
- (reason) => {
2141
- responsePromise.reject(reason);
2142
- }
2143
- );
2037
+ followFetchRedirect(request, response).then((response$1) => {
2038
+ responsePromise.resolve(response$1);
2039
+ }, (reason) => {
2040
+ responsePromise.reject(reason);
2041
+ });
2144
2042
  return;
2145
2043
  }
2146
2044
  }
2147
2045
  if (this.emitter.listenerCount("response") > 0) {
2148
2046
  this.logger.info('emitting the "response" event...');
2149
2047
  await emitAsync(this.emitter, "response", {
2150
- // Clone the mocked response for the "response" event listener.
2151
- // This way, the listener can read the response and not lock its body
2152
- // for the actual fetch consumer.
2153
2048
  response: response.clone(),
2154
2049
  isMockedResponse: true,
2155
2050
  request,
@@ -2165,10 +2060,7 @@ var _FetchInterceptor = class extends Interceptor {
2165
2060
  });
2166
2061
  this.logger.info("[%s] %s", request.method, request.url);
2167
2062
  this.logger.info("awaiting for the mocked response...");
2168
- this.logger.info(
2169
- 'emitting the "request" event for %s listener(s)...',
2170
- this.emitter.listenerCount("request")
2171
- );
2063
+ this.logger.info('emitting the "request" event for %s listener(s)...', this.emitter.listenerCount("request"));
2172
2064
  await handleRequest2({
2173
2065
  request,
2174
2066
  requestId,
@@ -2183,21 +2075,14 @@ var _FetchInterceptor = class extends Interceptor {
2183
2075
  value: true
2184
2076
  });
2185
2077
  this.subscriptions.push(() => {
2186
- Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {
2187
- value: void 0
2188
- });
2078
+ Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, { value: void 0 });
2189
2079
  globalThis.fetch = pureFetch;
2190
- this.logger.info(
2191
- 'restored native "globalThis.fetch"!',
2192
- globalThis.fetch.name
2193
- );
2080
+ this.logger.info('restored native "globalThis.fetch"!', globalThis.fetch.name);
2194
2081
  });
2195
2082
  }
2196
2083
  };
2197
- var FetchInterceptor = _FetchInterceptor;
2198
- FetchInterceptor.symbol = Symbol("fetch");
2199
2084
 
2200
- // node_modules/.pnpm/@mswjs+interceptors@0.40.0/node_modules/@mswjs/interceptors/lib/browser/chunk-WADP6VHN.mjs
2085
+ // node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/XMLHttpRequest-DS5fc8Qs.mjs
2201
2086
  function concatArrayBuffer(left, right) {
2202
2087
  const result = new Uint8Array(left.byteLength + right.byteLength);
2203
2088
  result.set(left, 0);
@@ -2225,8 +2110,8 @@ var EventPolyfill = class {
2225
2110
  this.cancelBubble = false;
2226
2111
  this.returnValue = true;
2227
2112
  this.type = type;
2228
- this.target = (options == null ? void 0 : options.target) || null;
2229
- this.currentTarget = (options == null ? void 0 : options.currentTarget) || null;
2113
+ this.target = options?.target || null;
2114
+ this.currentTarget = options?.currentTarget || null;
2230
2115
  this.timeStamp = Date.now();
2231
2116
  }
2232
2117
  composedPath() {
@@ -2248,10 +2133,10 @@ var EventPolyfill = class {
2248
2133
  var ProgressEventPolyfill = class extends EventPolyfill {
2249
2134
  constructor(type, init) {
2250
2135
  super(type);
2251
- this.lengthComputable = (init == null ? void 0 : init.lengthComputable) || false;
2252
- this.composed = (init == null ? void 0 : init.composed) || false;
2253
- this.loaded = (init == null ? void 0 : init.loaded) || 0;
2254
- this.total = (init == null ? void 0 : init.total) || 0;
2136
+ this.lengthComputable = init?.lengthComputable || false;
2137
+ this.composed = init?.composed || false;
2138
+ this.loaded = init?.loaded || 0;
2139
+ this.total = init?.total || 0;
2255
2140
  }
2256
2141
  };
2257
2142
  var SUPPORTS_PROGRESS_EVENT = typeof ProgressEvent !== "undefined";
@@ -2266,48 +2151,36 @@ function createEvent(target, type, init) {
2266
2151
  "abort"
2267
2152
  ];
2268
2153
  const ProgressEventClass = SUPPORTS_PROGRESS_EVENT ? ProgressEvent : ProgressEventPolyfill;
2269
- const event = progressEvents.includes(type) ? new ProgressEventClass(type, {
2154
+ return progressEvents.includes(type) ? new ProgressEventClass(type, {
2270
2155
  lengthComputable: true,
2271
- loaded: (init == null ? void 0 : init.loaded) || 0,
2272
- total: (init == null ? void 0 : init.total) || 0
2156
+ loaded: init?.loaded || 0,
2157
+ total: init?.total || 0
2273
2158
  }) : new EventPolyfill(type, {
2274
2159
  target,
2275
2160
  currentTarget: target
2276
2161
  });
2277
- return event;
2278
2162
  }
2279
2163
  function findPropertySource(target, propertyName) {
2280
- if (!(propertyName in target)) {
2281
- return null;
2282
- }
2283
- const hasProperty = Object.prototype.hasOwnProperty.call(target, propertyName);
2284
- if (hasProperty) {
2285
- return target;
2286
- }
2164
+ if (!(propertyName in target)) return null;
2165
+ if (Object.prototype.hasOwnProperty.call(target, propertyName)) return target;
2287
2166
  const prototype = Reflect.getPrototypeOf(target);
2288
2167
  return prototype ? findPropertySource(prototype, propertyName) : null;
2289
2168
  }
2290
2169
  function createProxy(target, options) {
2291
- const proxy = new Proxy(target, optionsToProxyHandler(options));
2292
- return proxy;
2170
+ return new Proxy(target, optionsToProxyHandler(options));
2293
2171
  }
2294
2172
  function optionsToProxyHandler(options) {
2295
2173
  const { constructorCall, methodCall, getProperty, setProperty } = options;
2296
2174
  const handler = {};
2297
- if (typeof constructorCall !== "undefined") {
2298
- handler.construct = function(target, args, newTarget) {
2299
- const next = Reflect.construct.bind(null, target, args, newTarget);
2300
- return constructorCall.call(newTarget, args, next);
2301
- };
2302
- }
2175
+ if (typeof constructorCall !== "undefined") handler.construct = function(target, args, newTarget) {
2176
+ const next = Reflect.construct.bind(null, target, args, newTarget);
2177
+ return constructorCall.call(newTarget, args, next);
2178
+ };
2303
2179
  handler.set = function(target, propertyName, nextValue) {
2304
2180
  const next = () => {
2305
2181
  const propertySource = findPropertySource(target, propertyName) || target;
2306
- const ownDescriptors = Reflect.getOwnPropertyDescriptor(
2307
- propertySource,
2308
- propertyName
2309
- );
2310
- if (typeof (ownDescriptors == null ? void 0 : ownDescriptors.set) !== "undefined") {
2182
+ const ownDescriptors = Reflect.getOwnPropertyDescriptor(propertySource, propertyName);
2183
+ if (typeof ownDescriptors?.set !== "undefined") {
2311
2184
  ownDescriptors.set.apply(target, [nextValue]);
2312
2185
  return true;
2313
2186
  }
@@ -2318,65 +2191,52 @@ function optionsToProxyHandler(options) {
2318
2191
  value: nextValue
2319
2192
  });
2320
2193
  };
2321
- if (typeof setProperty !== "undefined") {
2322
- return setProperty.call(target, [propertyName, nextValue], next);
2323
- }
2194
+ if (typeof setProperty !== "undefined") return setProperty.call(target, [propertyName, nextValue], next);
2324
2195
  return next();
2325
2196
  };
2326
2197
  handler.get = function(target, propertyName, receiver) {
2327
2198
  const next = () => target[propertyName];
2328
2199
  const value = typeof getProperty !== "undefined" ? getProperty.call(target, [propertyName, receiver], next) : next();
2329
- if (typeof value === "function") {
2330
- return (...args) => {
2331
- const next2 = value.bind(target, ...args);
2332
- if (typeof methodCall !== "undefined") {
2333
- return methodCall.call(target, [propertyName, args], next2);
2334
- }
2335
- return next2();
2336
- };
2337
- }
2200
+ if (typeof value === "function") return (...args) => {
2201
+ const next$1 = value.bind(target, ...args);
2202
+ if (typeof methodCall !== "undefined") return methodCall.call(target, [propertyName, args], next$1);
2203
+ return next$1();
2204
+ };
2338
2205
  return value;
2339
2206
  };
2340
2207
  return handler;
2341
2208
  }
2342
2209
  function isDomParserSupportedType(type) {
2343
- const supportedTypes = [
2210
+ return [
2344
2211
  "application/xhtml+xml",
2345
2212
  "application/xml",
2346
2213
  "image/svg+xml",
2347
2214
  "text/html",
2348
2215
  "text/xml"
2349
- ];
2350
- return supportedTypes.some((supportedType) => {
2216
+ ].some((supportedType) => {
2351
2217
  return type.startsWith(supportedType);
2352
2218
  });
2353
2219
  }
2354
2220
  function parseJson(data) {
2355
2221
  try {
2356
- const json = JSON.parse(data);
2357
- return json;
2222
+ return JSON.parse(data);
2358
2223
  } catch (_) {
2359
2224
  return null;
2360
2225
  }
2361
2226
  }
2362
2227
  function createResponse(request, body) {
2363
- const responseBodyOrNull = FetchResponse.isResponseWithBody(request.status) ? body : null;
2364
- return new FetchResponse(responseBodyOrNull, {
2228
+ return new FetchResponse(FetchResponse.isResponseWithBody(request.status) ? body : null, {
2365
2229
  url: request.responseURL,
2366
2230
  status: request.status,
2367
2231
  statusText: request.statusText,
2368
- headers: createHeadersFromXMLHttpRequestHeaders(
2369
- request.getAllResponseHeaders()
2370
- )
2232
+ headers: createHeadersFromXMLHttpRequestHeaders(request.getAllResponseHeaders())
2371
2233
  });
2372
2234
  }
2373
2235
  function createHeadersFromXMLHttpRequestHeaders(headersString) {
2374
2236
  const headers = new Headers();
2375
2237
  const lines = headersString.split(/[\r\n]+/);
2376
2238
  for (const line of lines) {
2377
- if (line.trim() === "") {
2378
- continue;
2379
- }
2239
+ if (line.trim() === "") continue;
2380
2240
  const [name, ...parts] = line.split(": ");
2381
2241
  const value = parts.join(": ");
2382
2242
  headers.append(name, value);
@@ -2385,11 +2245,8 @@ function createHeadersFromXMLHttpRequestHeaders(headersString) {
2385
2245
  }
2386
2246
  async function getBodyByteLength(input) {
2387
2247
  const explicitContentLength = input.headers.get("content-length");
2388
- if (explicitContentLength != null && explicitContentLength !== "") {
2389
- return Number(explicitContentLength);
2390
- }
2391
- const buffer = await input.arrayBuffer();
2392
- return buffer.byteLength;
2248
+ if (explicitContentLength != null && explicitContentLength !== "") return Number(explicitContentLength);
2249
+ return (await input.arrayBuffer()).byteLength;
2393
2250
  }
2394
2251
  var kIsRequestHandled = Symbol("kIsRequestHandled");
2395
2252
  var IS_NODE2 = isNodeProcess();
@@ -2410,15 +2267,12 @@ var XMLHttpRequestController = class {
2410
2267
  setProperty: ([propertyName, nextValue], invoke) => {
2411
2268
  switch (propertyName) {
2412
2269
  case "ontimeout": {
2413
- const eventName = propertyName.slice(
2414
- 2
2415
- );
2270
+ const eventName = propertyName.slice(2);
2416
2271
  this.request.addEventListener(eventName, nextValue);
2417
2272
  return invoke();
2418
2273
  }
2419
- default: {
2274
+ default:
2420
2275
  return invoke();
2421
- }
2422
2276
  }
2423
2277
  },
2424
2278
  methodCall: ([methodName, args], invoke) => {
@@ -2455,10 +2309,10 @@ var XMLHttpRequestController = class {
2455
2309
  const fetchResponse = createResponse(
2456
2310
  this.request,
2457
2311
  /**
2458
- * The `response` property is the right way to read
2459
- * the ambiguous response body, as the request's "responseType" may differ.
2460
- * @see https://xhr.spec.whatwg.org/#the-response-attribute
2461
- */
2312
+ * The `response` property is the right way to read
2313
+ * the ambiguous response body, as the request's "responseType" may differ.
2314
+ * @see https://xhr.spec.whatwg.org/#the-response-attribute
2315
+ */
2462
2316
  this.request.response
2463
2317
  );
2464
2318
  this.onResponse.call(this, {
@@ -2473,91 +2327,70 @@ var XMLHttpRequestController = class {
2473
2327
  const fetchRequest = this.toFetchApiRequest(requestBody);
2474
2328
  this[kFetchRequest] = fetchRequest.clone();
2475
2329
  queueMicrotask(() => {
2476
- var _a;
2477
- const onceRequestSettled = ((_a = this.onRequest) == null ? void 0 : _a.call(this, {
2330
+ (this.onRequest?.call(this, {
2478
2331
  request: fetchRequest,
2479
2332
  requestId: this.requestId
2480
- })) || Promise.resolve();
2481
- onceRequestSettled.finally(() => {
2333
+ }) || Promise.resolve()).finally(() => {
2482
2334
  if (!this[kIsRequestHandled]) {
2483
- this.logger.info(
2484
- "request callback settled but request has not been handled (readystate %d), performing as-is...",
2485
- this.request.readyState
2486
- );
2487
- if (IS_NODE2) {
2488
- this.request.setRequestHeader(
2489
- INTERNAL_REQUEST_ID_HEADER_NAME,
2490
- this.requestId
2491
- );
2492
- }
2335
+ this.logger.info("request callback settled but request has not been handled (readystate %d), performing as-is...", this.request.readyState);
2336
+ if (IS_NODE2) this.request.setRequestHeader(INTERNAL_REQUEST_ID_HEADER_NAME, this.requestId);
2493
2337
  return invoke();
2494
2338
  }
2495
2339
  });
2496
2340
  });
2497
2341
  break;
2498
2342
  }
2499
- default: {
2343
+ default:
2500
2344
  return invoke();
2501
- }
2502
2345
  }
2503
2346
  }
2504
2347
  });
2505
- define(
2506
- this.request,
2507
- "upload",
2508
- createProxy(this.request.upload, {
2509
- setProperty: ([propertyName, nextValue], invoke) => {
2510
- switch (propertyName) {
2511
- case "onloadstart":
2512
- case "onprogress":
2513
- case "onaboart":
2514
- case "onerror":
2515
- case "onload":
2516
- case "ontimeout":
2517
- case "onloadend": {
2518
- const eventName = propertyName.slice(
2519
- 2
2520
- );
2521
- this.registerUploadEvent(eventName, nextValue);
2522
- }
2348
+ define(this.request, "upload", createProxy(this.request.upload, {
2349
+ setProperty: ([propertyName, nextValue], invoke) => {
2350
+ switch (propertyName) {
2351
+ case "onloadstart":
2352
+ case "onprogress":
2353
+ case "onaboart":
2354
+ case "onerror":
2355
+ case "onload":
2356
+ case "ontimeout":
2357
+ case "onloadend": {
2358
+ const eventName = propertyName.slice(2);
2359
+ this.registerUploadEvent(eventName, nextValue);
2523
2360
  }
2524
- return invoke();
2525
- },
2526
- methodCall: ([methodName, args], invoke) => {
2527
- switch (methodName) {
2528
- case "addEventListener": {
2529
- const [eventName, listener] = args;
2530
- this.registerUploadEvent(eventName, listener);
2531
- this.logger.info("upload.addEventListener", eventName, listener);
2532
- return invoke();
2533
- }
2361
+ }
2362
+ return invoke();
2363
+ },
2364
+ methodCall: ([methodName, args], invoke) => {
2365
+ switch (methodName) {
2366
+ case "addEventListener": {
2367
+ const [eventName, listener] = args;
2368
+ this.registerUploadEvent(eventName, listener);
2369
+ this.logger.info("upload.addEventListener", eventName, listener);
2370
+ return invoke();
2534
2371
  }
2535
2372
  }
2536
- })
2537
- );
2373
+ }
2374
+ }));
2538
2375
  }
2539
2376
  registerEvent(eventName, listener) {
2540
- const prevEvents = this.events.get(eventName) || [];
2541
- const nextEvents = prevEvents.concat(listener);
2377
+ const nextEvents = (this.events.get(eventName) || []).concat(listener);
2542
2378
  this.events.set(eventName, nextEvents);
2543
2379
  this.logger.info('registered event "%s"', eventName, listener);
2544
2380
  }
2545
2381
  registerUploadEvent(eventName, listener) {
2546
- const prevEvents = this.uploadEvents.get(eventName) || [];
2547
- const nextEvents = prevEvents.concat(listener);
2382
+ const nextEvents = (this.uploadEvents.get(eventName) || []).concat(listener);
2548
2383
  this.uploadEvents.set(eventName, nextEvents);
2549
2384
  this.logger.info('registered upload event "%s"', eventName, listener);
2550
2385
  }
2551
2386
  /**
2552
- * Responds to the current request with the given
2553
- * Fetch API `Response` instance.
2554
- */
2387
+ * Responds to the current request with the given
2388
+ * Fetch API `Response` instance.
2389
+ */
2555
2390
  async respondWith(response) {
2556
2391
  this[kIsRequestHandled] = true;
2557
2392
  if (this[kFetchRequest]) {
2558
- const totalRequestBodyLength = await getBodyByteLength(
2559
- this[kFetchRequest]
2560
- );
2393
+ const totalRequestBodyLength = await getBodyByteLength(this[kFetchRequest]);
2561
2394
  this.trigger("loadstart", this.request.upload, {
2562
2395
  loaded: 0,
2563
2396
  total: totalRequestBodyLength
@@ -2575,48 +2408,32 @@ var XMLHttpRequestController = class {
2575
2408
  total: totalRequestBodyLength
2576
2409
  });
2577
2410
  }
2578
- this.logger.info(
2579
- "responding with a mocked response: %d %s",
2580
- response.status,
2581
- response.statusText
2582
- );
2411
+ this.logger.info("responding with a mocked response: %d %s", response.status, response.statusText);
2583
2412
  define(this.request, "status", response.status);
2584
2413
  define(this.request, "statusText", response.statusText);
2585
2414
  define(this.request, "responseURL", this.url.href);
2586
- this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, {
2587
- apply: (_, __, args) => {
2588
- this.logger.info("getResponseHeader", args[0]);
2589
- if (this.request.readyState < this.request.HEADERS_RECEIVED) {
2590
- this.logger.info("headers not received yet, returning null");
2591
- return null;
2592
- }
2593
- const headerValue = response.headers.get(args[0]);
2594
- this.logger.info(
2595
- 'resolved response header "%s" to',
2596
- args[0],
2597
- headerValue
2598
- );
2599
- return headerValue;
2415
+ this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, { apply: (_, __, args) => {
2416
+ this.logger.info("getResponseHeader", args[0]);
2417
+ if (this.request.readyState < this.request.HEADERS_RECEIVED) {
2418
+ this.logger.info("headers not received yet, returning null");
2419
+ return null;
2600
2420
  }
2601
- });
2602
- this.request.getAllResponseHeaders = new Proxy(
2603
- this.request.getAllResponseHeaders,
2604
- {
2605
- apply: () => {
2606
- this.logger.info("getAllResponseHeaders");
2607
- if (this.request.readyState < this.request.HEADERS_RECEIVED) {
2608
- this.logger.info("headers not received yet, returning empty string");
2609
- return "";
2610
- }
2611
- const headersList = Array.from(response.headers.entries());
2612
- const allHeaders = headersList.map(([headerName, headerValue]) => {
2613
- return `${headerName}: ${headerValue}`;
2614
- }).join("\r\n");
2615
- this.logger.info("resolved all response headers to", allHeaders);
2616
- return allHeaders;
2617
- }
2421
+ const headerValue = response.headers.get(args[0]);
2422
+ this.logger.info('resolved response header "%s" to', args[0], headerValue);
2423
+ return headerValue;
2424
+ } });
2425
+ this.request.getAllResponseHeaders = new Proxy(this.request.getAllResponseHeaders, { apply: () => {
2426
+ this.logger.info("getAllResponseHeaders");
2427
+ if (this.request.readyState < this.request.HEADERS_RECEIVED) {
2428
+ this.logger.info("headers not received yet, returning empty string");
2429
+ return "";
2618
2430
  }
2619
- );
2431
+ const allHeaders = Array.from(response.headers.entries()).map(([headerName, headerValue]) => {
2432
+ return `${headerName}: ${headerValue}`;
2433
+ }).join("\r\n");
2434
+ this.logger.info("resolved all response headers to", allHeaders);
2435
+ return allHeaders;
2436
+ } });
2620
2437
  Object.defineProperties(this.request, {
2621
2438
  response: {
2622
2439
  enumerable: true,
@@ -2675,21 +2492,14 @@ var XMLHttpRequestController = class {
2675
2492
  readNextResponseBodyChunk();
2676
2493
  };
2677
2494
  readNextResponseBodyChunk();
2678
- } else {
2679
- finalizeResponse();
2680
- }
2495
+ } else finalizeResponse();
2681
2496
  }
2682
2497
  responseBufferToText() {
2683
2498
  return decodeBuffer(this.responseBuffer);
2684
2499
  }
2685
2500
  get response() {
2686
- this.logger.info(
2687
- "getResponse (responseType: %s)",
2688
- this.request.responseType
2689
- );
2690
- if (this.request.readyState !== this.request.DONE) {
2691
- return null;
2692
- }
2501
+ this.logger.info("getResponse (responseType: %s)", this.request.responseType);
2502
+ if (this.request.readyState !== this.request.DONE) return null;
2693
2503
  switch (this.request.responseType) {
2694
2504
  case "json": {
2695
2505
  const responseJson = parseJson(this.responseBufferToText());
@@ -2703,60 +2513,33 @@ var XMLHttpRequestController = class {
2703
2513
  }
2704
2514
  case "blob": {
2705
2515
  const mimeType = this.request.getResponseHeader("Content-Type") || "text/plain";
2706
- const responseBlob = new Blob([this.responseBufferToText()], {
2707
- type: mimeType
2708
- });
2709
- this.logger.info(
2710
- "resolved response Blob (mime type: %s)",
2711
- responseBlob,
2712
- mimeType
2713
- );
2516
+ const responseBlob = new Blob([this.responseBufferToText()], { type: mimeType });
2517
+ this.logger.info("resolved response Blob (mime type: %s)", responseBlob, mimeType);
2714
2518
  return responseBlob;
2715
2519
  }
2716
2520
  default: {
2717
2521
  const responseText = this.responseBufferToText();
2718
- this.logger.info(
2719
- 'resolving "%s" response type as text',
2720
- this.request.responseType,
2721
- responseText
2722
- );
2522
+ this.logger.info('resolving "%s" response type as text', this.request.responseType, responseText);
2723
2523
  return responseText;
2724
2524
  }
2725
2525
  }
2726
2526
  }
2727
2527
  get responseText() {
2728
- invariant(
2729
- this.request.responseType === "" || this.request.responseType === "text",
2730
- "InvalidStateError: The object is in invalid state."
2731
- );
2732
- if (this.request.readyState !== this.request.LOADING && this.request.readyState !== this.request.DONE) {
2733
- return "";
2734
- }
2528
+ invariant(this.request.responseType === "" || this.request.responseType === "text", "InvalidStateError: The object is in invalid state.");
2529
+ if (this.request.readyState !== this.request.LOADING && this.request.readyState !== this.request.DONE) return "";
2735
2530
  const responseText = this.responseBufferToText();
2736
2531
  this.logger.info('getResponseText: "%s"', responseText);
2737
2532
  return responseText;
2738
2533
  }
2739
2534
  get responseXML() {
2740
- invariant(
2741
- this.request.responseType === "" || this.request.responseType === "document",
2742
- "InvalidStateError: The object is in invalid state."
2743
- );
2744
- if (this.request.readyState !== this.request.DONE) {
2745
- return null;
2746
- }
2535
+ invariant(this.request.responseType === "" || this.request.responseType === "document", "InvalidStateError: The object is in invalid state.");
2536
+ if (this.request.readyState !== this.request.DONE) return null;
2747
2537
  const contentType = this.request.getResponseHeader("Content-Type") || "";
2748
2538
  if (typeof DOMParser === "undefined") {
2749
- console.warn(
2750
- "Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly."
2751
- );
2539
+ console.warn("Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly.");
2752
2540
  return null;
2753
2541
  }
2754
- if (isDomParserSupportedType(contentType)) {
2755
- return new DOMParser().parseFromString(
2756
- this.responseBufferToText(),
2757
- contentType
2758
- );
2759
- }
2542
+ if (isDomParserSupportedType(contentType)) return new DOMParser().parseFromString(this.responseBufferToText(), contentType);
2760
2543
  return null;
2761
2544
  }
2762
2545
  errorWith(error2) {
@@ -2767,14 +2550,10 @@ var XMLHttpRequestController = class {
2767
2550
  this.trigger("loadend", this.request);
2768
2551
  }
2769
2552
  /**
2770
- * Transitions this request's `readyState` to the given one.
2771
- */
2553
+ * Transitions this request's `readyState` to the given one.
2554
+ */
2772
2555
  setReadyState(nextReadyState) {
2773
- this.logger.info(
2774
- "setReadyState: %d -> %d",
2775
- this.request.readyState,
2776
- nextReadyState
2777
- );
2556
+ this.logger.info("setReadyState: %d -> %d", this.request.readyState, nextReadyState);
2778
2557
  if (this.request.readyState === nextReadyState) {
2779
2558
  this.logger.info("ready state identical, skipping transition...");
2780
2559
  return;
@@ -2787,8 +2566,8 @@ var XMLHttpRequestController = class {
2787
2566
  }
2788
2567
  }
2789
2568
  /**
2790
- * Triggers given event on the `XMLHttpRequest` instance.
2791
- */
2569
+ * Triggers given event on the `XMLHttpRequest` instance.
2570
+ */
2792
2571
  trigger(eventName, target, options) {
2793
2572
  const callback = target[`on${eventName}`];
2794
2573
  const event = createEvent(target, eventName, options);
@@ -2798,156 +2577,106 @@ var XMLHttpRequestController = class {
2798
2577
  callback.call(target, event);
2799
2578
  }
2800
2579
  const events = target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events;
2801
- for (const [registeredEventName, listeners] of events) {
2802
- if (registeredEventName === eventName) {
2803
- this.logger.info(
2804
- 'found %d listener(s) for "%s" event, calling...',
2805
- listeners.length,
2806
- eventName
2807
- );
2808
- listeners.forEach((listener) => listener.call(target, event));
2809
- }
2580
+ for (const [registeredEventName, listeners] of events) if (registeredEventName === eventName) {
2581
+ this.logger.info('found %d listener(s) for "%s" event, calling...', listeners.length, eventName);
2582
+ listeners.forEach((listener) => listener.call(target, event));
2810
2583
  }
2811
2584
  }
2812
2585
  /**
2813
- * Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
2814
- */
2586
+ * Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
2587
+ */
2815
2588
  toFetchApiRequest(body) {
2816
2589
  this.logger.info("converting request to a Fetch API Request...");
2817
2590
  const resolvedBody = body instanceof Document ? body.documentElement.innerText : body;
2818
2591
  const fetchRequest = new Request(this.url.href, {
2819
2592
  method: this.method,
2820
2593
  headers: this.requestHeaders,
2821
- /**
2822
- * @see https://xhr.spec.whatwg.org/#cross-origin-credentials
2823
- */
2824
2594
  credentials: this.request.withCredentials ? "include" : "same-origin",
2825
2595
  body: ["GET", "HEAD"].includes(this.method.toUpperCase()) ? null : resolvedBody
2826
2596
  });
2827
- const proxyHeaders = createProxy(fetchRequest.headers, {
2828
- methodCall: ([methodName, args], invoke) => {
2829
- switch (methodName) {
2830
- case "append":
2831
- case "set": {
2832
- const [headerName, headerValue] = args;
2833
- this.request.setRequestHeader(headerName, headerValue);
2834
- break;
2835
- }
2836
- case "delete": {
2837
- const [headerName] = args;
2838
- console.warn(
2839
- `XMLHttpRequest: Cannot remove a "${headerName}" header from the Fetch API representation of the "${fetchRequest.method} ${fetchRequest.url}" request. XMLHttpRequest headers cannot be removed.`
2840
- );
2841
- break;
2842
- }
2597
+ define(fetchRequest, "headers", createProxy(fetchRequest.headers, { methodCall: ([methodName, args], invoke) => {
2598
+ switch (methodName) {
2599
+ case "append":
2600
+ case "set": {
2601
+ const [headerName, headerValue] = args;
2602
+ this.request.setRequestHeader(headerName, headerValue);
2603
+ break;
2604
+ }
2605
+ case "delete": {
2606
+ const [headerName] = args;
2607
+ console.warn(`XMLHttpRequest: Cannot remove a "${headerName}" header from the Fetch API representation of the "${fetchRequest.method} ${fetchRequest.url}" request. XMLHttpRequest headers cannot be removed.`);
2608
+ break;
2843
2609
  }
2844
- return invoke();
2845
2610
  }
2846
- });
2847
- define(fetchRequest, "headers", proxyHeaders);
2611
+ return invoke();
2612
+ } }));
2848
2613
  setRawRequest(fetchRequest, this.request);
2849
2614
  this.logger.info("converted request to a Fetch API Request!", fetchRequest);
2850
2615
  return fetchRequest;
2851
2616
  }
2852
2617
  };
2853
2618
  function toAbsoluteUrl(url) {
2854
- if (typeof location === "undefined") {
2855
- return new URL(url);
2856
- }
2619
+ if (typeof location === "undefined") return new URL(url);
2857
2620
  return new URL(url.toString(), location.href);
2858
2621
  }
2859
2622
  function define(target, property, value) {
2860
2623
  Reflect.defineProperty(target, property, {
2861
- // Ensure writable properties to allow redefining readonly properties.
2862
2624
  writable: true,
2863
2625
  enumerable: true,
2864
2626
  value
2865
2627
  });
2866
2628
  }
2867
- function createXMLHttpRequestProxy({
2868
- emitter,
2869
- logger
2870
- }) {
2871
- const XMLHttpRequestProxy = new Proxy(globalThis.XMLHttpRequest, {
2872
- construct(target, args, newTarget) {
2873
- logger.info("constructed new XMLHttpRequest");
2874
- const originalRequest = Reflect.construct(
2875
- target,
2876
- args,
2877
- newTarget
2878
- );
2879
- const prototypeDescriptors = Object.getOwnPropertyDescriptors(
2880
- target.prototype
2881
- );
2882
- for (const propertyName in prototypeDescriptors) {
2883
- Reflect.defineProperty(
2884
- originalRequest,
2885
- propertyName,
2886
- prototypeDescriptors[propertyName]
2887
- );
2888
- }
2889
- const xhrRequestController = new XMLHttpRequestController(
2890
- originalRequest,
2891
- logger
2892
- );
2893
- xhrRequestController.onRequest = async function({ request, requestId }) {
2894
- const controller = new RequestController(request, {
2895
- passthrough: () => {
2896
- this.logger.info(
2897
- "no mocked response received, performing request as-is..."
2898
- );
2899
- },
2900
- respondWith: async (response) => {
2901
- if (isResponseError(response)) {
2902
- this.errorWith(new TypeError("Network error"));
2903
- return;
2904
- }
2905
- await this.respondWith(response);
2906
- },
2907
- errorWith: (reason) => {
2908
- this.logger.info("request errored!", { error: reason });
2909
- if (reason instanceof Error) {
2910
- this.errorWith(reason);
2911
- }
2629
+ function createXMLHttpRequestProxy({ emitter, logger }) {
2630
+ return new Proxy(globalThis.XMLHttpRequest, { construct(target, args, newTarget) {
2631
+ logger.info("constructed new XMLHttpRequest");
2632
+ const originalRequest = Reflect.construct(target, args, newTarget);
2633
+ const prototypeDescriptors = Object.getOwnPropertyDescriptors(target.prototype);
2634
+ for (const propertyName in prototypeDescriptors) Reflect.defineProperty(originalRequest, propertyName, prototypeDescriptors[propertyName]);
2635
+ const xhrRequestController = new XMLHttpRequestController(originalRequest, logger);
2636
+ xhrRequestController.onRequest = async function({ request, requestId }) {
2637
+ const controller = new RequestController(request, {
2638
+ passthrough: () => {
2639
+ this.logger.info("no mocked response received, performing request as-is...");
2640
+ },
2641
+ respondWith: async (response) => {
2642
+ if (isResponseError(response)) {
2643
+ this.errorWith(/* @__PURE__ */ new TypeError("Network error"));
2644
+ return;
2912
2645
  }
2913
- });
2914
- this.logger.info("awaiting mocked response...");
2915
- this.logger.info(
2916
- 'emitting the "request" event for %s listener(s)...',
2917
- emitter.listenerCount("request")
2918
- );
2919
- await handleRequest2({
2920
- request,
2921
- requestId,
2922
- controller,
2923
- emitter
2924
- });
2925
- };
2926
- xhrRequestController.onResponse = async function({
2646
+ await this.respondWith(response);
2647
+ },
2648
+ errorWith: (reason) => {
2649
+ this.logger.info("request errored!", { error: reason });
2650
+ if (reason instanceof Error) this.errorWith(reason);
2651
+ }
2652
+ });
2653
+ this.logger.info("awaiting mocked response...");
2654
+ this.logger.info('emitting the "request" event for %s listener(s)...', emitter.listenerCount("request"));
2655
+ await handleRequest2({
2656
+ request,
2657
+ requestId,
2658
+ controller,
2659
+ emitter
2660
+ });
2661
+ };
2662
+ xhrRequestController.onResponse = async function({ response, isMockedResponse, request, requestId }) {
2663
+ this.logger.info('emitting the "response" event for %s listener(s)...', emitter.listenerCount("response"));
2664
+ emitter.emit("response", {
2927
2665
  response,
2928
2666
  isMockedResponse,
2929
2667
  request,
2930
2668
  requestId
2931
- }) {
2932
- this.logger.info(
2933
- 'emitting the "response" event for %s listener(s)...',
2934
- emitter.listenerCount("response")
2935
- );
2936
- emitter.emit("response", {
2937
- response,
2938
- isMockedResponse,
2939
- request,
2940
- requestId
2941
- });
2942
- };
2943
- return xhrRequestController.request;
2944
- }
2945
- });
2946
- return XMLHttpRequestProxy;
2669
+ });
2670
+ };
2671
+ return xhrRequestController.request;
2672
+ } });
2947
2673
  }
2948
- var _XMLHttpRequestInterceptor = class extends Interceptor {
2674
+ var XMLHttpRequestInterceptor = class XMLHttpRequestInterceptor2 extends Interceptor {
2675
+ static {
2676
+ this.interceptorSymbol = Symbol("xhr");
2677
+ }
2949
2678
  constructor() {
2950
- super(_XMLHttpRequestInterceptor.interceptorSymbol);
2679
+ super(XMLHttpRequestInterceptor2.interceptorSymbol);
2951
2680
  }
2952
2681
  checkEnvironment() {
2953
2682
  return hasConfigurableGlobal("XMLHttpRequest");
@@ -2956,37 +2685,24 @@ var _XMLHttpRequestInterceptor = class extends Interceptor {
2956
2685
  const logger = this.logger.extend("setup");
2957
2686
  logger.info('patching "XMLHttpRequest" module...');
2958
2687
  const PureXMLHttpRequest = globalThis.XMLHttpRequest;
2959
- invariant(
2960
- !PureXMLHttpRequest[IS_PATCHED_MODULE],
2961
- 'Failed to patch the "XMLHttpRequest" module: already patched.'
2962
- );
2688
+ invariant(!PureXMLHttpRequest[IS_PATCHED_MODULE], 'Failed to patch the "XMLHttpRequest" module: already patched.');
2963
2689
  globalThis.XMLHttpRequest = createXMLHttpRequestProxy({
2964
2690
  emitter: this.emitter,
2965
2691
  logger: this.logger
2966
2692
  });
2967
- logger.info(
2968
- 'native "XMLHttpRequest" module patched!',
2969
- globalThis.XMLHttpRequest.name
2970
- );
2693
+ logger.info('native "XMLHttpRequest" module patched!', globalThis.XMLHttpRequest.name);
2971
2694
  Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, {
2972
2695
  enumerable: true,
2973
2696
  configurable: true,
2974
2697
  value: true
2975
2698
  });
2976
2699
  this.subscriptions.push(() => {
2977
- Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, {
2978
- value: void 0
2979
- });
2700
+ Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, { value: void 0 });
2980
2701
  globalThis.XMLHttpRequest = PureXMLHttpRequest;
2981
- logger.info(
2982
- 'native "XMLHttpRequest" module restored!',
2983
- globalThis.XMLHttpRequest.name
2984
- );
2702
+ logger.info('native "XMLHttpRequest" module restored!', globalThis.XMLHttpRequest.name);
2985
2703
  });
2986
2704
  }
2987
2705
  };
2988
- var XMLHttpRequestInterceptor = _XMLHttpRequestInterceptor;
2989
- XMLHttpRequestInterceptor.interceptorSymbol = Symbol("xhr");
2990
2706
 
2991
2707
  // src/browser/setupWorker/start/createFallbackRequestListener.ts
2992
2708
  import { handleRequest as handleRequest3 } from '../core/utils/handleRequest.mjs';