msw 0.41.1 → 0.42.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -33,12 +33,6 @@ var __objRest = (source, exclude) => {
33
33
  }
34
34
  return target;
35
35
  };
36
- var __esm = (fn, res) => function __init() {
37
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
38
- };
39
- var __commonJS = (cb, mod) => function __require() {
40
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
41
- };
42
36
  var __export = (target, all) => {
43
37
  for (var name in all)
44
38
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -54,164 +48,6 @@ var __copyProps = (to, from, except, desc) => {
54
48
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
55
49
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
56
50
 
57
- // node_modules/tsup/assets/cjs_shims.js
58
- var init_cjs_shims = __esm({
59
- "node_modules/tsup/assets/cjs_shims.js"() {
60
- }
61
- });
62
-
63
- // node_modules/outvariant/lib/format.js
64
- var require_format = __commonJS({
65
- "node_modules/outvariant/lib/format.js"(exports) {
66
- "use strict";
67
- init_cjs_shims();
68
- Object.defineProperty(exports, "__esModule", { value: true });
69
- exports.format = void 0;
70
- var POSITIONALS_EXP = /(%?)(%([sdjo]))/g;
71
- function serializePositional(positional, flag) {
72
- switch (flag) {
73
- case "s":
74
- return positional;
75
- case "d":
76
- case "i":
77
- return Number(positional);
78
- case "j":
79
- return JSON.stringify(positional);
80
- case "o": {
81
- if (typeof positional === "string") {
82
- return positional;
83
- }
84
- var json2 = JSON.stringify(positional);
85
- if (json2 === "{}" || json2 === "[]" || /^\[object .+?\]$/.test(json2)) {
86
- return positional;
87
- }
88
- return json2;
89
- }
90
- }
91
- }
92
- function format2(message) {
93
- var positionals = [];
94
- for (var _i = 1; _i < arguments.length; _i++) {
95
- positionals[_i - 1] = arguments[_i];
96
- }
97
- if (positionals.length === 0) {
98
- return message;
99
- }
100
- var positionalIndex = 0;
101
- var formattedMessage = message.replace(POSITIONALS_EXP, function(match2, isEscaped, _, flag) {
102
- var positional = positionals[positionalIndex];
103
- var value = serializePositional(positional, flag);
104
- if (!isEscaped) {
105
- positionalIndex++;
106
- return value;
107
- }
108
- return match2;
109
- });
110
- if (positionalIndex < positionals.length) {
111
- formattedMessage += " " + positionals.slice(positionalIndex).join(" ");
112
- }
113
- formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
114
- return formattedMessage;
115
- }
116
- exports.format = format2;
117
- }
118
- });
119
-
120
- // node_modules/outvariant/lib/invariant.js
121
- var require_invariant = __commonJS({
122
- "node_modules/outvariant/lib/invariant.js"(exports) {
123
- "use strict";
124
- init_cjs_shims();
125
- var __extends = exports && exports.__extends || function() {
126
- var extendStatics = function(d, b) {
127
- extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
128
- d2.__proto__ = b2;
129
- } || function(d2, b2) {
130
- for (var p in b2)
131
- if (Object.prototype.hasOwnProperty.call(b2, p))
132
- d2[p] = b2[p];
133
- };
134
- return extendStatics(d, b);
135
- };
136
- return function(d, b) {
137
- if (typeof b !== "function" && b !== null)
138
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
139
- extendStatics(d, b);
140
- function __() {
141
- this.constructor = d;
142
- }
143
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
144
- };
145
- }();
146
- var __spreadArray = exports && exports.__spreadArray || function(to, from) {
147
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
148
- to[j] = from[i];
149
- return to;
150
- };
151
- Object.defineProperty(exports, "__esModule", { value: true });
152
- exports.invariant = exports.InvariantError = void 0;
153
- var format_1 = require_format();
154
- var STACK_FRAMES_TO_IGNORE = 2;
155
- var InvariantError = function(_super) {
156
- __extends(InvariantError2, _super);
157
- function InvariantError2(message) {
158
- var positionals = [];
159
- for (var _i = 1; _i < arguments.length; _i++) {
160
- positionals[_i - 1] = arguments[_i];
161
- }
162
- var _this = _super.call(this, message) || this;
163
- _this.name = "Invariant Violation";
164
- _this.message = format_1.format.apply(void 0, __spreadArray([message], positionals));
165
- if (_this.stack) {
166
- var nextStack = _this.stack.split("\n");
167
- nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
168
- _this.stack = nextStack.join("\n");
169
- }
170
- return _this;
171
- }
172
- return InvariantError2;
173
- }(Error);
174
- exports.InvariantError = InvariantError;
175
- function invariant(predicate, message) {
176
- var positionals = [];
177
- for (var _i = 2; _i < arguments.length; _i++) {
178
- positionals[_i - 2] = arguments[_i];
179
- }
180
- if (!predicate) {
181
- throw new (InvariantError.bind.apply(InvariantError, __spreadArray([void 0, message], positionals)))();
182
- }
183
- }
184
- exports.invariant = invariant;
185
- }
186
- });
187
-
188
- // node_modules/outvariant/lib/index.js
189
- var require_lib = __commonJS({
190
- "node_modules/outvariant/lib/index.js"(exports) {
191
- "use strict";
192
- init_cjs_shims();
193
- var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
194
- if (k2 === void 0)
195
- k2 = k;
196
- Object.defineProperty(o, k2, { enumerable: true, get: function() {
197
- return m[k];
198
- } });
199
- } : function(o, m, k, k2) {
200
- if (k2 === void 0)
201
- k2 = k;
202
- o[k2] = m[k];
203
- });
204
- var __exportStar = exports && exports.__exportStar || function(m, exports2) {
205
- for (var p in m)
206
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
207
- __createBinding(exports2, m, p);
208
- };
209
- Object.defineProperty(exports, "__esModule", { value: true });
210
- __exportStar(require_invariant(), exports);
211
- __exportStar(require_format(), exports);
212
- }
213
- });
214
-
215
51
  // src/index.ts
216
52
  var src_exports = {};
217
53
  __export(src_exports, {
@@ -236,7 +72,6 @@ __export(src_exports, {
236
72
  setupWorker: () => setupWorker
237
73
  });
238
74
  module.exports = __toCommonJS(src_exports);
239
- init_cjs_shims();
240
75
 
241
76
  // src/context/index.ts
242
77
  var context_exports = {};
@@ -254,10 +89,8 @@ __export(context_exports, {
254
89
  text: () => text,
255
90
  xml: () => xml
256
91
  });
257
- init_cjs_shims();
258
92
 
259
93
  // src/context/status.ts
260
- init_cjs_shims();
261
94
  var import_codes = __toESM(require("statuses/codes.json"));
262
95
  var status = (statusCode, statusText) => {
263
96
  return (res) => {
@@ -268,7 +101,6 @@ var status = (statusCode, statusText) => {
268
101
  };
269
102
 
270
103
  // src/context/set.ts
271
- init_cjs_shims();
272
104
  var import_headers_polyfill = require("headers-polyfill");
273
105
  function set(...args) {
274
106
  return (res) => {
@@ -286,7 +118,6 @@ function set(...args) {
286
118
  }
287
119
 
288
120
  // src/context/cookie.ts
289
- init_cjs_shims();
290
121
  var cookieUtils = __toESM(require("cookie"));
291
122
  var cookie = (name, value, options) => {
292
123
  return (res) => {
@@ -300,7 +131,6 @@ var cookie = (name, value, options) => {
300
131
  };
301
132
 
302
133
  // src/context/body.ts
303
- init_cjs_shims();
304
134
  var body = (value) => {
305
135
  return (res) => {
306
136
  res.body = value;
@@ -308,11 +138,7 @@ var body = (value) => {
308
138
  };
309
139
  };
310
140
 
311
- // src/context/data.ts
312
- init_cjs_shims();
313
-
314
141
  // src/utils/internal/jsonParse.ts
315
- init_cjs_shims();
316
142
  function jsonParse(value) {
317
143
  try {
318
144
  return JSON.parse(value);
@@ -321,11 +147,7 @@ function jsonParse(value) {
321
147
  }
322
148
  }
323
149
 
324
- // src/utils/internal/mergeRight.ts
325
- init_cjs_shims();
326
-
327
150
  // src/utils/internal/isObject.ts
328
- init_cjs_shims();
329
151
  function isObject(value) {
330
152
  return value != null && typeof value === "object" && !Array.isArray(value);
331
153
  }
@@ -348,7 +170,6 @@ function mergeRight(left, right) {
348
170
  }
349
171
 
350
172
  // src/context/json.ts
351
- init_cjs_shims();
352
173
  var json = (body2) => {
353
174
  return (res) => {
354
175
  res.headers.set("Content-Type", "application/json");
@@ -367,7 +188,6 @@ var data = (payload) => {
367
188
  };
368
189
 
369
190
  // src/context/extensions.ts
370
- init_cjs_shims();
371
191
  var extensions = (payload) => {
372
192
  return (res) => {
373
193
  const prevBody = jsonParse(res.body) || {};
@@ -377,7 +197,6 @@ var extensions = (payload) => {
377
197
  };
378
198
 
379
199
  // src/context/delay.ts
380
- init_cjs_shims();
381
200
  var import_is_node_process = require("is-node-process");
382
201
  var SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
383
202
  var MIN_SERVER_RESPONSE_TIME = 100;
@@ -420,7 +239,6 @@ var delay = (durationOrMode) => {
420
239
  };
421
240
 
422
241
  // src/context/errors.ts
423
- init_cjs_shims();
424
242
  var errors = (errorsList) => {
425
243
  return (res) => {
426
244
  if (errorsList == null) {
@@ -433,7 +251,6 @@ var errors = (errorsList) => {
433
251
  };
434
252
 
435
253
  // src/context/fetch.ts
436
- init_cjs_shims();
437
254
  var import_is_node_process2 = require("is-node-process");
438
255
  var import_headers_polyfill2 = require("headers-polyfill");
439
256
  var useFetch = (0, import_is_node_process2.isNodeProcess)() ? require("node-fetch") : window.fetch;
@@ -469,7 +286,6 @@ var fetch = (input, requestInit = {}) => {
469
286
  };
470
287
 
471
288
  // src/context/text.ts
472
- init_cjs_shims();
473
289
  var text = (body2) => {
474
290
  return (res) => {
475
291
  res.headers.set("Content-Type", "text/plain");
@@ -479,7 +295,6 @@ var text = (body2) => {
479
295
  };
480
296
 
481
297
  // src/context/xml.ts
482
- init_cjs_shims();
483
298
  var xml = (body2) => {
484
299
  return (res) => {
485
300
  res.headers.set("Content-Type", "text/xml");
@@ -489,20 +304,16 @@ var xml = (body2) => {
489
304
  };
490
305
 
491
306
  // src/setupWorker/setupWorker.ts
492
- init_cjs_shims();
493
307
  var import_is_node_process3 = require("is-node-process");
494
308
  var import_strict_event_emitter = require("strict-event-emitter");
495
309
 
496
310
  // src/setupWorker/start/createStartHandler.ts
497
- init_cjs_shims();
498
311
  var import_until4 = require("@open-draft/until");
499
312
 
500
313
  // src/setupWorker/start/utils/getWorkerInstance.ts
501
- init_cjs_shims();
502
314
  var import_until = require("@open-draft/until");
503
315
 
504
316
  // src/setupWorker/start/utils/getWorkerByRegistration.ts
505
- init_cjs_shims();
506
317
  var getWorkerByRegistration = (registration, absoluteWorkerUrl, findWorker) => {
507
318
  const allStates = [
508
319
  registration.active,
@@ -517,14 +328,12 @@ var getWorkerByRegistration = (registration, absoluteWorkerUrl, findWorker) => {
517
328
  };
518
329
 
519
330
  // src/utils/url/getAbsoluteWorkerUrl.ts
520
- init_cjs_shims();
521
331
  function getAbsoluteWorkerUrl(relativeUrl) {
522
332
  return new URL(relativeUrl, location.origin).href;
523
333
  }
524
334
 
525
335
  // src/utils/internal/devUtils.ts
526
- init_cjs_shims();
527
- var import_outvariant = __toESM(require_lib());
336
+ var import_outvariant = require("outvariant");
528
337
  var LIBRARY_PREFIX = "[MSW]";
529
338
  function formatMessage(message, ...positionals) {
530
339
  const interpolatedMessage = (0, import_outvariant.format)(message, ...positionals);
@@ -580,11 +389,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
580
389
  return instance;
581
390
  };
582
391
 
583
- // src/setupWorker/start/utils/enableMocking.ts
584
- init_cjs_shims();
585
-
586
392
  // src/setupWorker/start/utils/printStartMessage.ts
587
- init_cjs_shims();
588
393
  function printStartMessage(args = {}) {
589
394
  if (args.quiet) {
590
395
  return;
@@ -619,11 +424,7 @@ async function enableMocking(context, options) {
619
424
  });
620
425
  }
621
426
 
622
- // src/utils/worker/createRequestListener.ts
623
- init_cjs_shims();
624
-
625
427
  // src/utils/createBroadcastChannel.ts
626
- init_cjs_shims();
627
428
  var createBroadcastChannel = (event) => {
628
429
  const port = event.ports[0];
629
430
  return {
@@ -636,7 +437,6 @@ var createBroadcastChannel = (event) => {
636
437
  };
637
438
 
638
439
  // src/utils/NetworkError.ts
639
- init_cjs_shims();
640
440
  var NetworkError = class extends Error {
641
441
  constructor(message) {
642
442
  super(message);
@@ -645,19 +445,15 @@ var NetworkError = class extends Error {
645
445
  };
646
446
 
647
447
  // src/utils/request/parseWorkerRequest.ts
648
- init_cjs_shims();
649
448
  var import_headers_polyfill6 = require("headers-polyfill");
650
449
 
651
450
  // src/handlers/RequestHandler.ts
652
- init_cjs_shims();
653
451
  var import_headers_polyfill4 = require("headers-polyfill");
654
452
 
655
453
  // src/response.ts
656
- init_cjs_shims();
657
454
  var import_headers_polyfill3 = require("headers-polyfill");
658
455
 
659
456
  // src/utils/internal/compose.ts
660
- init_cjs_shims();
661
457
  function compose(...fns) {
662
458
  return (...args) => {
663
459
  return fns.reduceRight((leftFn, rightFn) => {
@@ -699,7 +495,6 @@ var response = Object.assign(createResponseComposition(), {
699
495
  });
700
496
 
701
497
  // src/utils/internal/getCallFrame.ts
702
- init_cjs_shims();
703
498
  var SOURCE_FRAME = /\/msw\/src\/(.+)/;
704
499
  var BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
705
500
  function getCallFrame(error2) {
@@ -719,7 +514,6 @@ function getCallFrame(error2) {
719
514
  }
720
515
 
721
516
  // src/utils/internal/isIterable.ts
722
- init_cjs_shims();
723
517
  function isIterable(fn) {
724
518
  if (!fn) {
725
519
  return false;
@@ -809,12 +603,10 @@ function passthrough() {
809
603
  }
810
604
 
811
605
  // src/utils/request/setRequestCookies.ts
812
- init_cjs_shims();
813
606
  var cookieUtils3 = __toESM(require("cookie"));
814
607
  var import_cookies = require("@mswjs/cookies");
815
608
 
816
609
  // src/utils/request/getRequestCookies.ts
817
- init_cjs_shims();
818
610
  var cookieUtils2 = __toESM(require("cookie"));
819
611
  function getAllCookies() {
820
612
  return cookieUtils2.parse(document.cookie);
@@ -853,11 +645,7 @@ function setRequestCookies(request) {
853
645
  request.cookies = __spreadValues(__spreadValues(__spreadValues({}, request.cookies), forwardedCookies), ownCookies);
854
646
  }
855
647
 
856
- // src/utils/request/parseBody.ts
857
- init_cjs_shims();
858
-
859
648
  // src/utils/internal/parseMultipartData.ts
860
- init_cjs_shims();
861
649
  var import_headers_polyfill5 = require("headers-polyfill");
862
650
  function parseContentHeaders(headersString) {
863
651
  var _a, _b;
@@ -897,8 +685,8 @@ function parseMultipartData(data2, headers) {
897
685
  }
898
686
  const parsedBody = {};
899
687
  try {
900
- for (const field of fields) {
901
- const [contentHeaders, ...rest2] = field.split("\r\n\r\n");
688
+ for (const field2 of fields) {
689
+ const [contentHeaders, ...rest2] = field2.split("\r\n\r\n");
902
690
  const contentBody = rest2.join("\r\n\r\n");
903
691
  const { contentType: contentType2, filename, name } = parseContentHeaders(contentHeaders);
904
692
  const value = filename === void 0 ? contentBody : new File([contentBody], filename, { type: contentType2 });
@@ -935,11 +723,7 @@ function parseBody(body2, headers) {
935
723
  return body2;
936
724
  }
937
725
 
938
- // src/utils/request/pruneGetRequestBody.ts
939
- init_cjs_shims();
940
-
941
726
  // src/utils/internal/isStringEqual.ts
942
- init_cjs_shims();
943
727
  function isStringEqual(actual, expected) {
944
728
  return actual.toLowerCase() === expected.toLowerCase();
945
729
  }
@@ -980,11 +764,9 @@ function parseWorkerRequest(rawRequest) {
980
764
  }
981
765
 
982
766
  // src/utils/handleRequest.ts
983
- init_cjs_shims();
984
767
  var import_until2 = require("@open-draft/until");
985
768
 
986
769
  // src/utils/getResponse.ts
987
- init_cjs_shims();
988
770
  var getResponse = async (request, handlers, resolutionContext) => {
989
771
  const relevantHandlers = handlers.filter((handler) => {
990
772
  return handler.test(request, resolutionContext);
@@ -1032,15 +814,12 @@ var getResponse = async (request, handlers, resolutionContext) => {
1032
814
  };
1033
815
 
1034
816
  // src/utils/request/onUnhandledRequest.ts
1035
- init_cjs_shims();
1036
817
  var import_js_levenshtein = __toESM(require("js-levenshtein"));
1037
818
 
1038
819
  // src/utils/internal/parseGraphQLRequest.ts
1039
- init_cjs_shims();
1040
820
  var import_graphql = require("graphql");
1041
821
 
1042
822
  // src/utils/request/getPublicUrlFromRequest.ts
1043
- init_cjs_shims();
1044
823
  var getPublicUrlFromRequest = (request) => {
1045
824
  return request.referrer.startsWith(request.url.origin) ? request.url.pathname : new URL(request.url.pathname, `${request.url.protocol}//${request.url.host}`).href;
1046
825
  };
@@ -1140,11 +919,7 @@ function parseGraphQLRequest(request) {
1140
919
  };
1141
920
  }
1142
921
 
1143
- // src/handlers/RestHandler.ts
1144
- init_cjs_shims();
1145
-
1146
922
  // src/utils/logging/getStatusCodeColor.ts
1147
- init_cjs_shims();
1148
923
  function getStatusCodeColor(status2) {
1149
924
  if (status2 < 300) {
1150
925
  return "#69AB32" /* Success */;
@@ -1156,14 +931,12 @@ function getStatusCodeColor(status2) {
1156
931
  }
1157
932
 
1158
933
  // src/utils/logging/getTimestamp.ts
1159
- init_cjs_shims();
1160
934
  function getTimestamp() {
1161
935
  const now = new Date();
1162
936
  return [now.getHours(), now.getMinutes(), now.getSeconds()].map(String).map((chunk) => chunk.slice(0, 2)).map((chunk) => chunk.padStart(2, "0")).join(":");
1163
937
  }
1164
938
 
1165
939
  // src/utils/logging/prepareRequest.ts
1166
- init_cjs_shims();
1167
940
  function prepareRequest(request) {
1168
941
  return __spreadProps(__spreadValues({}, request), {
1169
942
  headers: request.headers.all()
@@ -1171,7 +944,6 @@ function prepareRequest(request) {
1171
944
  }
1172
945
 
1173
946
  // src/utils/logging/prepareResponse.ts
1174
- init_cjs_shims();
1175
947
  var import_headers_polyfill7 = require("headers-polyfill");
1176
948
  function prepareResponse(res) {
1177
949
  const responseHeaders = (0, import_headers_polyfill7.objectToHeaders)(res.headers);
@@ -1181,15 +953,10 @@ function prepareResponse(res) {
1181
953
  }
1182
954
 
1183
955
  // src/utils/matching/matchRequestUrl.ts
1184
- init_cjs_shims();
1185
956
  var import_path_to_regexp = require("path-to-regexp");
1186
957
  var import_getCleanUrl = require("@mswjs/interceptors/lib/utils/getCleanUrl");
1187
958
 
1188
- // src/utils/matching/normalizePath.ts
1189
- init_cjs_shims();
1190
-
1191
959
  // src/utils/url/cleanUrl.ts
1192
- init_cjs_shims();
1193
960
  var REDUNDANT_CHARACTERS_EXP = /[\?|#].*$/g;
1194
961
  function getSearchParams(path) {
1195
962
  return new URL(`/${path}`, "http://localhost").searchParams;
@@ -1198,11 +965,7 @@ function cleanUrl(path) {
1198
965
  return path.replace(REDUNDANT_CHARACTERS_EXP, "");
1199
966
  }
1200
967
 
1201
- // src/utils/url/getAbsoluteUrl.ts
1202
- init_cjs_shims();
1203
-
1204
968
  // src/utils/url/isAbsoluteUrl.ts
1205
- init_cjs_shims();
1206
969
  function isAbsoluteUrl(url) {
1207
970
  return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
1208
971
  }
@@ -1325,11 +1088,24 @@ var RestHandler = class extends RequestHandler {
1325
1088
  }
1326
1089
  };
1327
1090
 
1328
- // src/handlers/GraphQLHandler.ts
1329
- init_cjs_shims();
1091
+ // src/context/field.ts
1092
+ var import_outvariant2 = require("outvariant");
1093
+ var field = (fieldName, fieldValue) => {
1094
+ return (res) => {
1095
+ validateFieldName(fieldName);
1096
+ const prevBody = jsonParse(res.body) || {};
1097
+ const nextBody = mergeRight(prevBody, { [fieldName]: fieldValue });
1098
+ return json(nextBody)(res);
1099
+ };
1100
+ };
1101
+ function validateFieldName(fieldName) {
1102
+ (0, import_outvariant2.invariant)(fieldName.trim() !== "", devUtils.formatMessage("Failed to set a custom field on a GraphQL response: field name cannot be empty."));
1103
+ (0, import_outvariant2.invariant)(fieldName !== "data", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.data()" instead?', fieldName));
1104
+ (0, import_outvariant2.invariant)(fieldName !== "errors", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.errors()" instead?', fieldName));
1105
+ (0, import_outvariant2.invariant)(fieldName !== "extensions", devUtils.formatMessage('Failed to set a custom "%s" field on a mocked GraphQL response: forbidden field name. Did you mean to call "ctx.extensions()" instead?', fieldName));
1106
+ }
1330
1107
 
1331
1108
  // src/utils/internal/tryCatch.ts
1332
- init_cjs_shims();
1333
1109
  function tryCatch(fn, onException) {
1334
1110
  try {
1335
1111
  const result = fn();
@@ -1344,7 +1120,8 @@ var graphqlContext = __spreadProps(__spreadValues({}, defaultContext), {
1344
1120
  data,
1345
1121
  extensions,
1346
1122
  errors,
1347
- cookie
1123
+ cookie,
1124
+ field
1348
1125
  });
1349
1126
  function isDocumentNode(value) {
1350
1127
  if (value == null) {
@@ -1524,7 +1301,6 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
1524
1301
  }
1525
1302
 
1526
1303
  // src/utils/request/readResponseCookies.ts
1527
- init_cjs_shims();
1528
1304
  var import_cookies2 = require("@mswjs/cookies");
1529
1305
  function readResponseCookies(request, response2) {
1530
1306
  import_cookies2.store.add(__spreadProps(__spreadValues({}, request), { url: request.url.toString() }), response2);
@@ -1592,11 +1368,7 @@ var createRequestListener = (context, options) => {
1592
1368
  try {
1593
1369
  const request = parseWorkerRequest(message.payload);
1594
1370
  await handleRequest(request, context.requestHandlers, options, context.emitter, {
1595
- transformResponse(response2) {
1596
- return __spreadProps(__spreadValues({}, response2), {
1597
- headers: response2.headers.all()
1598
- });
1599
- },
1371
+ transformResponse,
1600
1372
  onPassthroughResponse() {
1601
1373
  return channel.send({
1602
1374
  type: "MOCK_NOT_FOUND"
@@ -1609,9 +1381,10 @@ var createRequestListener = (context, options) => {
1609
1381
  });
1610
1382
  },
1611
1383
  onMockedResponseSent(response2, { handler, publicRequest, parsedRequest }) {
1612
- if (!options.quiet) {
1613
- handler.log(publicRequest, response2, handler, parsedRequest);
1384
+ if (options.quiet) {
1385
+ return;
1614
1386
  }
1387
+ handler.log(publicRequest, response2, handler, parsedRequest);
1615
1388
  }
1616
1389
  });
1617
1390
  } catch (error2) {
@@ -1640,9 +1413,17 @@ var createRequestListener = (context, options) => {
1640
1413
  }
1641
1414
  };
1642
1415
  };
1416
+ function transformResponse(response2) {
1417
+ return {
1418
+ status: response2.status,
1419
+ statusText: response2.statusText,
1420
+ headers: response2.headers.all(),
1421
+ body: response2.body,
1422
+ delay: response2.delay
1423
+ };
1424
+ }
1643
1425
 
1644
1426
  // src/utils/internal/requestIntegrityCheck.ts
1645
- init_cjs_shims();
1646
1427
  async function requestIntegrityCheck(context, serviceWorker) {
1647
1428
  context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
1648
1429
  const { payload: actualChecksum } = await context.events.once("INTEGRITY_CHECK_RESPONSE");
@@ -1653,7 +1434,6 @@ async function requestIntegrityCheck(context, serviceWorker) {
1653
1434
  }
1654
1435
 
1655
1436
  // src/utils/deferNetworkRequestsUntil.ts
1656
- init_cjs_shims();
1657
1437
  var import_until3 = require("@open-draft/until");
1658
1438
  function deferNetworkRequestsUntil(predicatePromise) {
1659
1439
  const originalXhrSend = window.XMLHttpRequest.prototype.send;
@@ -1672,7 +1452,6 @@ function deferNetworkRequestsUntil(predicatePromise) {
1672
1452
  }
1673
1453
 
1674
1454
  // src/utils/worker/createResponseListener.ts
1675
- init_cjs_shims();
1676
1455
  function createResponseListener(context) {
1677
1456
  return (_, message) => {
1678
1457
  var _a;
@@ -1691,7 +1470,6 @@ function createResponseListener(context) {
1691
1470
  }
1692
1471
 
1693
1472
  // src/setupWorker/start/utils/validateWorkerScope.ts
1694
- init_cjs_shims();
1695
1473
  function validateWorkerScope(registration, options) {
1696
1474
  if (!(options == null ? void 0 : options.quiet) && !location.href.startsWith(registration.scope)) {
1697
1475
  devUtils.warn(`Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
@@ -1768,11 +1546,7 @@ If this message still persists after updating, please report an issue: https://g
1768
1546
  };
1769
1547
  };
1770
1548
 
1771
- // src/setupWorker/stop/createStop.ts
1772
- init_cjs_shims();
1773
-
1774
1549
  // src/setupWorker/stop/utils/printStopMessage.ts
1775
- init_cjs_shims();
1776
1550
  function printStopMessage(args = {}) {
1777
1551
  if (args.quiet) {
1778
1552
  return;
@@ -1796,7 +1570,6 @@ var createStop = (context) => {
1796
1570
  };
1797
1571
 
1798
1572
  // src/utils/internal/requestHandlerUtils.ts
1799
- init_cjs_shims();
1800
1573
  function use(currentHandlers, ...handlers) {
1801
1574
  currentHandlers.unshift(...handlers);
1802
1575
  }
@@ -1810,7 +1583,6 @@ function resetHandlers(initialHandlers, ...nextHandlers) {
1810
1583
  }
1811
1584
 
1812
1585
  // src/setupWorker/start/utils/prepareStartHandler.ts
1813
- init_cjs_shims();
1814
1586
  var DEFAULT_START_OPTIONS = {
1815
1587
  serviceWorker: {
1816
1588
  url: "/mockServiceWorker.js",
@@ -1833,17 +1605,12 @@ function prepareStartHandler(handler, context) {
1833
1605
  };
1834
1606
  }
1835
1607
 
1836
- // src/setupWorker/start/createFallbackStart.ts
1837
- init_cjs_shims();
1838
-
1839
1608
  // src/utils/worker/createFallbackRequestListener.ts
1840
- init_cjs_shims();
1841
1609
  var import_interceptors = require("@mswjs/interceptors");
1842
1610
  var import_fetch3 = require("@mswjs/interceptors/lib/interceptors/fetch");
1843
1611
  var import_XMLHttpRequest = require("@mswjs/interceptors/lib/interceptors/XMLHttpRequest");
1844
1612
 
1845
1613
  // src/utils/request/parseIsomorphicRequest.ts
1846
- init_cjs_shims();
1847
1614
  function parseIsomorphicRequest(request) {
1848
1615
  const mockedRequest = {
1849
1616
  id: request.id,
@@ -1870,25 +1637,30 @@ function parseIsomorphicRequest(request) {
1870
1637
 
1871
1638
  // src/utils/worker/createFallbackRequestListener.ts
1872
1639
  function createFallbackRequestListener(context, options) {
1873
- const interceptor = (0, import_interceptors.createInterceptor)({
1874
- modules: [import_fetch3.interceptFetch, import_XMLHttpRequest.interceptXMLHttpRequest],
1875
- async resolver(request) {
1876
- const mockedRequest = parseIsomorphicRequest(request);
1877
- return handleRequest(mockedRequest, context.requestHandlers, options, context.emitter, {
1878
- transformResponse(response2) {
1879
- return {
1880
- status: response2.status,
1881
- statusText: response2.statusText,
1882
- headers: response2.headers.all(),
1883
- body: response2.body
1884
- };
1885
- },
1886
- onMockedResponseSent(response2, { handler, publicRequest, parsedRequest }) {
1887
- if (!options.quiet) {
1888
- handler.log(publicRequest, response2, handler, parsedRequest);
1889
- }
1640
+ const interceptor = new import_interceptors.BatchInterceptor({
1641
+ name: "fallback",
1642
+ interceptors: [new import_fetch3.FetchInterceptor(), new import_XMLHttpRequest.XMLHttpRequestInterceptor()]
1643
+ });
1644
+ interceptor.on("request", async (request) => {
1645
+ const mockedRequest = parseIsomorphicRequest(request);
1646
+ const response2 = await handleRequest(mockedRequest, context.requestHandlers, options, context.emitter, {
1647
+ transformResponse(response3) {
1648
+ return {
1649
+ status: response3.status,
1650
+ statusText: response3.statusText,
1651
+ headers: response3.headers.all(),
1652
+ body: response3.body,
1653
+ delay: response3.delay
1654
+ };
1655
+ },
1656
+ onMockedResponseSent(response3, { handler, publicRequest, parsedRequest }) {
1657
+ if (!options.quiet) {
1658
+ handler.log(publicRequest, response3, handler, parsedRequest);
1890
1659
  }
1891
- });
1660
+ }
1661
+ });
1662
+ if (response2) {
1663
+ request.respondWith(response2);
1892
1664
  }
1893
1665
  });
1894
1666
  interceptor.apply();
@@ -1908,17 +1680,15 @@ function createFallbackStart(context) {
1908
1680
  }
1909
1681
 
1910
1682
  // src/setupWorker/stop/createFallbackStop.ts
1911
- init_cjs_shims();
1912
1683
  function createFallbackStop(context) {
1913
1684
  return function stop() {
1914
1685
  var _a, _b;
1915
- (_a = context.fallbackInterceptor) == null ? void 0 : _a.restore();
1686
+ (_a = context.fallbackInterceptor) == null ? void 0 : _a.dispose();
1916
1687
  printStopMessage({ quiet: (_b = context.startOptions) == null ? void 0 : _b.quiet });
1917
1688
  };
1918
1689
  }
1919
1690
 
1920
1691
  // src/utils/internal/pipeEvents.ts
1921
- init_cjs_shims();
1922
1692
  function pipeEvents(source, destination) {
1923
1693
  const rawEmit = source.emit;
1924
1694
  if (rawEmit._isPiped) {
@@ -2055,7 +1825,6 @@ function setupWorker(...requestHandlers) {
2055
1825
  }
2056
1826
 
2057
1827
  // src/rest.ts
2058
- init_cjs_shims();
2059
1828
  function createRestHandler(method) {
2060
1829
  return (path, resolver) => {
2061
1830
  return new RestHandler(method, path, resolver);
@@ -2073,7 +1842,6 @@ var rest = {
2073
1842
  };
2074
1843
 
2075
1844
  // src/graphql.ts
2076
- init_cjs_shims();
2077
1845
  var import_graphql2 = require("graphql");
2078
1846
  function createScopedGraphQLHandler(operationType, url) {
2079
1847
  return (operationName, resolver) => {