msw 0.0.0-fetch.rc-20 → 0.0.0-fetch.rc-22

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 (46) hide show
  1. package/README.md +5 -2
  2. package/lib/browser/index.d.ts +21 -8
  3. package/lib/browser/index.js +14 -6
  4. package/lib/browser/index.mjs +14 -6
  5. package/lib/core/{GraphQLHandler-ef45ae39.d.ts → GraphQLHandler-a441dd03.d.ts} +18 -6
  6. package/lib/core/HttpResponse.d.ts +1 -1
  7. package/lib/core/{RequestHandler-7c716cf7.d.ts → RequestHandler-b59044ae.d.ts} +36 -10
  8. package/lib/core/SetupApi.d.ts +1 -1
  9. package/lib/core/bypass.d.ts +3 -1
  10. package/lib/core/delay.d.ts +3 -0
  11. package/lib/core/graphql.d.ts +62 -30
  12. package/lib/core/graphql.js +30 -14
  13. package/lib/core/graphql.mjs +30 -14
  14. package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
  15. package/lib/core/handlers/GraphQLHandler.js +23 -18
  16. package/lib/core/handlers/GraphQLHandler.mjs +23 -18
  17. package/lib/core/handlers/HttpHandler.d.ts +17 -5
  18. package/lib/core/handlers/HttpHandler.js +16 -15
  19. package/lib/core/handlers/HttpHandler.mjs +16 -15
  20. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  21. package/lib/core/handlers/RequestHandler.js +37 -30
  22. package/lib/core/handlers/RequestHandler.mjs +37 -30
  23. package/lib/core/http.d.ts +10 -1
  24. package/lib/core/index.d.ts +2 -2
  25. package/lib/core/passthrough.d.ts +3 -1
  26. package/lib/core/sharedOptions.d.ts +1 -1
  27. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  28. package/lib/core/utils/getResponse.d.ts +1 -1
  29. package/lib/core/utils/getResponse.js +2 -2
  30. package/lib/core/utils/getResponse.mjs +2 -2
  31. package/lib/core/utils/handleRequest.d.ts +1 -1
  32. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
  33. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  34. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  35. package/lib/core/utils/request/onUnhandledRequest.d.ts +1 -1
  36. package/lib/core/utils/request/onUnhandledRequest.js +1 -1
  37. package/lib/core/utils/request/onUnhandledRequest.mjs +1 -1
  38. package/lib/iife/index.js +279 -138
  39. package/lib/mockServiceWorker.js +3 -3
  40. package/lib/native/index.d.ts +20 -7
  41. package/lib/native/index.js +5 -0
  42. package/lib/native/index.mjs +5 -0
  43. package/lib/node/index.d.ts +20 -7
  44. package/lib/node/index.js +5 -0
  45. package/lib/node/index.mjs +5 -0
  46. package/package.json +2 -2
package/lib/iife/index.js CHANGED
@@ -514,10 +514,10 @@ var MockServiceWorker = (() => {
514
514
  this.isUsed = false;
515
515
  }
516
516
  /**
517
- * Parse the captured request to extract additional information from it.
517
+ * Parse the intercepted request to extract additional information from it.
518
518
  * Parsed result is then exposed to other methods of this request handler.
519
519
  */
520
- parse(_request, _resolutionContext) {
520
+ parse(_args) {
521
521
  return __async(this, null, function* () {
522
522
  return {};
523
523
  });
@@ -525,54 +525,61 @@ var MockServiceWorker = (() => {
525
525
  /**
526
526
  * Test if this handler matches the given request.
527
527
  */
528
- test(request, resolutionContext) {
528
+ test(args) {
529
529
  return __async(this, null, function* () {
530
- return this.predicate(
531
- request,
532
- yield this.parse(request.clone(), resolutionContext),
533
- resolutionContext
534
- );
530
+ const parsedResult = yield this.parse({
531
+ request: args.request,
532
+ resolutionContext: args.resolutionContext
533
+ });
534
+ return this.predicate({
535
+ request: args.request,
536
+ parsedResult,
537
+ resolutionContext: args.resolutionContext
538
+ });
535
539
  });
536
540
  }
537
- extendInfo(_request, _parsedResult) {
541
+ extendResolverArgs(_args) {
538
542
  return {};
539
543
  }
540
544
  /**
541
545
  * Execute this request handler and produce a mocked response
542
546
  * using the given resolver function.
543
547
  */
544
- run(request, resolutionContext) {
548
+ run(args) {
545
549
  return __async(this, null, function* () {
546
550
  var _a3;
547
551
  if (this.isUsed && ((_a3 = this.options) == null ? void 0 : _a3.once)) {
548
552
  return null;
549
553
  }
550
- const mainRequestRef = request.clone();
554
+ const mainRequestRef = args.request.clone();
551
555
  this.isUsed = true;
552
- const parsedResult = yield this.parse(
553
- mainRequestRef.clone(),
554
- resolutionContext
555
- );
556
- const shouldInterceptRequest = this.predicate(
557
- mainRequestRef.clone(),
556
+ const parsedResult = yield this.parse({
557
+ request: args.request,
558
+ resolutionContext: args.resolutionContext
559
+ });
560
+ const shouldInterceptRequest = this.predicate({
561
+ request: args.request,
558
562
  parsedResult,
559
- resolutionContext
560
- );
563
+ resolutionContext: args.resolutionContext
564
+ });
561
565
  if (!shouldInterceptRequest) {
562
566
  return null;
563
567
  }
564
568
  const executeResolver = this.wrapResolver(this.resolver);
565
- const resolverExtras = this.extendInfo(request, parsedResult);
569
+ const resolverExtras = this.extendResolverArgs({
570
+ request: args.request,
571
+ parsedResult
572
+ });
566
573
  const mockedResponse = yield executeResolver(__spreadProps(__spreadValues({}, resolverExtras), {
567
- request
574
+ request: args.request
568
575
  }));
569
- const executionResult = this.createExecutionResult(
576
+ const executionResult = this.createExecutionResult({
570
577
  // Pass the cloned request to the result so that logging
571
578
  // and other consumers could read its body once more.
572
- mainRequestRef,
573
- parsedResult,
574
- mockedResponse
575
- );
579
+ request: mainRequestRef,
580
+ response: mockedResponse,
581
+ parsedResult
582
+ });
576
583
  return executionResult;
577
584
  });
578
585
  }
@@ -604,12 +611,12 @@ var MockServiceWorker = (() => {
604
611
  return result;
605
612
  });
606
613
  }
607
- createExecutionResult(request, parsedResult, response) {
614
+ createExecutionResult(args) {
608
615
  return {
609
616
  handler: this,
610
- parsedResult,
611
- request,
612
- response
617
+ request: args.request,
618
+ response: args.response,
619
+ parsedResult: args.parsedResult
613
620
  };
614
621
  }
615
622
  };
@@ -2335,46 +2342,47 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2335
2342
  `Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`
2336
2343
  );
2337
2344
  }
2338
- parse(request, resolutionContext) {
2345
+ parse(args) {
2339
2346
  return __async(this, null, function* () {
2340
- const url = new URL(request.url);
2347
+ var _a3;
2348
+ const url = new URL(args.request.url);
2341
2349
  const match2 = matchRequestUrl(
2342
2350
  url,
2343
2351
  this.info.path,
2344
- resolutionContext == null ? void 0 : resolutionContext.baseUrl
2352
+ (_a3 = args.resolutionContext) == null ? void 0 : _a3.baseUrl
2345
2353
  );
2346
- const cookies = getAllRequestCookies(request);
2354
+ const cookies = getAllRequestCookies(args.request);
2347
2355
  return {
2348
2356
  match: match2,
2349
2357
  cookies
2350
2358
  };
2351
2359
  });
2352
2360
  }
2353
- predicate(request, parsedResult) {
2354
- const hasMatchingMethod = this.matchMethod(request.method);
2355
- const hasMatchingUrl = parsedResult.match.matches;
2361
+ predicate(args) {
2362
+ const hasMatchingMethod = this.matchMethod(args.request.method);
2363
+ const hasMatchingUrl = args.parsedResult.match.matches;
2356
2364
  return hasMatchingMethod && hasMatchingUrl;
2357
2365
  }
2358
2366
  matchMethod(actualMethod) {
2359
2367
  return this.info.method instanceof RegExp ? this.info.method.test(actualMethod) : isStringEqual(this.info.method, actualMethod);
2360
2368
  }
2361
- extendInfo(_request, parsedResult) {
2369
+ extendResolverArgs(args) {
2362
2370
  var _a3;
2363
2371
  return {
2364
- params: ((_a3 = parsedResult.match) == null ? void 0 : _a3.params) || {},
2365
- cookies: parsedResult.cookies
2372
+ params: ((_a3 = args.parsedResult.match) == null ? void 0 : _a3.params) || {},
2373
+ cookies: args.parsedResult.cookies
2366
2374
  };
2367
2375
  }
2368
- log(request, response) {
2376
+ log(args) {
2369
2377
  return __async(this, null, function* () {
2370
- const publicUrl = getPublicUrlFromRequest(request);
2371
- const loggedRequest = yield serializeRequest(request);
2372
- const loggedResponse = yield serializeResponse(response);
2378
+ const publicUrl = getPublicUrlFromRequest(args.request);
2379
+ const loggedRequest = yield serializeRequest(args.request);
2380
+ const loggedResponse = yield serializeResponse(args.response);
2373
2381
  const statusColor = getStatusCodeColor(loggedResponse.status);
2374
2382
  console.groupCollapsed(
2375
2383
  devUtils.formatMessage("%s %s %s (%c%s%c)"),
2376
2384
  getTimestamp(),
2377
- request.method,
2385
+ args.request.method,
2378
2386
  publicUrl,
2379
2387
  `color:${statusColor}`,
2380
2388
  `${loggedResponse.status} ${loggedResponse.statusText}`,
@@ -2405,7 +2413,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2405
2413
  options: createHttpHandler("OPTIONS" /* OPTIONS */)
2406
2414
  };
2407
2415
 
2408
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/devAssert.mjs
2416
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/jsutils/devAssert.mjs
2409
2417
  function devAssert(condition, message3) {
2410
2418
  const booleanCondition = Boolean(condition);
2411
2419
  if (!booleanCondition) {
@@ -2413,12 +2421,12 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2413
2421
  }
2414
2422
  }
2415
2423
 
2416
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/isObjectLike.mjs
2424
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/jsutils/isObjectLike.mjs
2417
2425
  function isObjectLike(value) {
2418
2426
  return typeof value == "object" && value !== null;
2419
2427
  }
2420
2428
 
2421
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/invariant.mjs
2429
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/jsutils/invariant.mjs
2422
2430
  function invariant2(condition, message3) {
2423
2431
  const booleanCondition = Boolean(condition);
2424
2432
  if (!booleanCondition) {
@@ -2428,7 +2436,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2428
2436
  }
2429
2437
  }
2430
2438
 
2431
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/location.mjs
2439
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/location.mjs
2432
2440
  var LineRegExp = /\r\n|[\n\r]/g;
2433
2441
  function getLocation(source, position) {
2434
2442
  let lastLineStart = 0;
@@ -2447,7 +2455,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2447
2455
  };
2448
2456
  }
2449
2457
 
2450
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/printLocation.mjs
2458
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/printLocation.mjs
2451
2459
  function printLocation(location2) {
2452
2460
  return printSourceLocation(
2453
2461
  location2.source,
@@ -2494,7 +2502,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2494
2502
  return existingLines.map(([prefix, line]) => prefix.padStart(padLen) + (line ? " " + line : "")).join("\n");
2495
2503
  }
2496
2504
 
2497
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/error/GraphQLError.mjs
2505
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/error/GraphQLError.mjs
2498
2506
  function toNormalizedOptions(args) {
2499
2507
  const firstArg = args[0];
2500
2508
  if (firstArg == null || "kind" in firstArg || "length" in firstArg) {
@@ -2643,7 +2651,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2643
2651
  return array === void 0 || array.length === 0 ? void 0 : array;
2644
2652
  }
2645
2653
 
2646
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/error/syntaxError.mjs
2654
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/error/syntaxError.mjs
2647
2655
  function syntaxError(source, position, description) {
2648
2656
  return new GraphQLError(`Syntax Error: ${description}`, {
2649
2657
  source,
@@ -2651,7 +2659,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2651
2659
  });
2652
2660
  }
2653
2661
 
2654
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/ast.mjs
2662
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/ast.mjs
2655
2663
  var Location = class {
2656
2664
  /**
2657
2665
  * The character offset at which this Node begins.
@@ -2817,7 +2825,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2817
2825
  OperationTypeNode2["SUBSCRIPTION"] = "subscription";
2818
2826
  })(OperationTypeNode || (OperationTypeNode = {}));
2819
2827
 
2820
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/directiveLocation.mjs
2828
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/directiveLocation.mjs
2821
2829
  var DirectiveLocation;
2822
2830
  (function(DirectiveLocation2) {
2823
2831
  DirectiveLocation2["QUERY"] = "QUERY";
@@ -2841,7 +2849,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2841
2849
  DirectiveLocation2["INPUT_FIELD_DEFINITION"] = "INPUT_FIELD_DEFINITION";
2842
2850
  })(DirectiveLocation || (DirectiveLocation = {}));
2843
2851
 
2844
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/kinds.mjs
2852
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/kinds.mjs
2845
2853
  var Kind;
2846
2854
  (function(Kind2) {
2847
2855
  Kind2["NAME"] = "Name";
@@ -2889,7 +2897,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2889
2897
  Kind2["INPUT_OBJECT_TYPE_EXTENSION"] = "InputObjectTypeExtension";
2890
2898
  })(Kind || (Kind = {}));
2891
2899
 
2892
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/characterClasses.mjs
2900
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/characterClasses.mjs
2893
2901
  function isWhiteSpace(code) {
2894
2902
  return code === 9 || code === 32;
2895
2903
  }
@@ -2907,7 +2915,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2907
2915
  return isLetter(code) || isDigit(code) || code === 95;
2908
2916
  }
2909
2917
 
2910
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/blockString.mjs
2918
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/blockString.mjs
2911
2919
  function dedentBlockStringLines(lines) {
2912
2920
  var _firstNonEmptyLine2;
2913
2921
  let commonIndent = Number.MAX_SAFE_INTEGER;
@@ -2939,7 +2947,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2939
2947
  return i;
2940
2948
  }
2941
2949
 
2942
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/tokenKind.mjs
2950
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/tokenKind.mjs
2943
2951
  var TokenKind;
2944
2952
  (function(TokenKind2) {
2945
2953
  TokenKind2["SOF"] = "<SOF>";
@@ -2966,7 +2974,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
2966
2974
  TokenKind2["COMMENT"] = "Comment";
2967
2975
  })(TokenKind || (TokenKind = {}));
2968
2976
 
2969
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/lexer.mjs
2977
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/lexer.mjs
2970
2978
  var Lexer = class {
2971
2979
  /**
2972
2980
  * The previously focused non-ignored token.
@@ -3467,7 +3475,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
3467
3475
  );
3468
3476
  }
3469
3477
 
3470
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/inspect.mjs
3478
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/jsutils/inspect.mjs
3471
3479
  var MAX_ARRAY_LENGTH = 10;
3472
3480
  var MAX_RECURSIVE_DEPTH = 2;
3473
3481
  function inspect(value) {
@@ -3550,7 +3558,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
3550
3558
  return tag;
3551
3559
  }
3552
3560
 
3553
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/jsutils/instanceOf.mjs
3561
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/jsutils/instanceOf.mjs
3554
3562
  var instanceOf = (
3555
3563
  /* c8 ignore next 6 */
3556
3564
  // FIXME: https://github.com/graphql/graphql-js/issues/2317
@@ -3587,7 +3595,7 @@ spurious results.`);
3587
3595
  }
3588
3596
  );
3589
3597
 
3590
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/source.mjs
3598
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/source.mjs
3591
3599
  var Source = class {
3592
3600
  constructor(body, name = "GraphQL request", locationOffset = {
3593
3601
  line: 1,
@@ -3614,7 +3622,7 @@ spurious results.`);
3614
3622
  return instanceOf(source, Source);
3615
3623
  }
3616
3624
 
3617
- // node_modules/.pnpm/graphql@16.8.0/node_modules/graphql/language/parser.mjs
3625
+ // node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/parser.mjs
3618
3626
  function parse2(source, options) {
3619
3627
  const parser = new Parser(source, options);
3620
3628
  return parser.parseDocument();
@@ -4872,7 +4880,7 @@ spurious results.`);
4872
4880
  }
4873
4881
  }
4874
4882
 
4875
- // node_modules/.pnpm/headers-polyfill@3.2.3/node_modules/headers-polyfill/lib/index.mjs
4883
+ // node_modules/.pnpm/headers-polyfill@4.0.1/node_modules/headers-polyfill/lib/index.mjs
4876
4884
  var __create4 = Object.create;
4877
4885
  var __defProp6 = Object.defineProperty;
4878
4886
  var __getOwnPropDesc5 = Object.getOwnPropertyDescriptor;
@@ -4891,6 +4899,10 @@ spurious results.`);
4891
4899
  return to;
4892
4900
  };
4893
4901
  var __toESM4 = (mod, isNodeMode, target) => (target = mod != null ? __create4(__getProtoOf4(mod)) : {}, __copyProps5(
4902
+ // If the importer is in node compatibility mode or this is not an ESM
4903
+ // file that has been converted to a CommonJS file using a Babel-
4904
+ // compatible transform (i.e. "__esModule" has not been set), then set
4905
+ // "default" to the CommonJS "module.exports" for node compatibility.
4894
4906
  isNodeMode || !mod || !mod.__esModule ? __defProp6(target, "default", { value: mod, enumerable: true }) : target,
4895
4907
  mod
4896
4908
  ));
@@ -5063,30 +5075,92 @@ spurious results.`);
5063
5075
  var import_set_cookie_parser2 = __toESM4(require_set_cookie2());
5064
5076
  var HEADERS_INVALID_CHARACTERS = /[^a-z0-9\-#$%&'*+.^_`|~]/i;
5065
5077
  function normalizeHeaderName(name) {
5066
- if (typeof name !== "string") {
5067
- name = String(name);
5068
- }
5069
5078
  if (HEADERS_INVALID_CHARACTERS.test(name) || name.trim() === "") {
5070
5079
  throw new TypeError("Invalid character in header field name");
5071
5080
  }
5072
- return name.toLowerCase();
5073
- }
5081
+ return name.trim().toLowerCase();
5082
+ }
5083
+ var charCodesToRemove = [
5084
+ String.fromCharCode(10),
5085
+ String.fromCharCode(13),
5086
+ String.fromCharCode(9),
5087
+ String.fromCharCode(32)
5088
+ ];
5089
+ var HEADER_VALUE_REMOVE_REGEXP = new RegExp(
5090
+ `(^[${charCodesToRemove.join("")}]|$[${charCodesToRemove.join("")}])`,
5091
+ "g"
5092
+ );
5074
5093
  function normalizeHeaderValue(value) {
5094
+ const nextValue = value.replace(HEADER_VALUE_REMOVE_REGEXP, "");
5095
+ return nextValue;
5096
+ }
5097
+ function isValidHeaderName(value) {
5075
5098
  if (typeof value !== "string") {
5076
- value = String(value);
5099
+ return false;
5077
5100
  }
5078
- return value;
5101
+ if (value.length === 0) {
5102
+ return false;
5103
+ }
5104
+ for (let i = 0; i < value.length; i++) {
5105
+ const character = value.charCodeAt(i);
5106
+ if (character > 127 || !isToken(character)) {
5107
+ return false;
5108
+ }
5109
+ }
5110
+ return true;
5111
+ }
5112
+ function isToken(value) {
5113
+ return ![
5114
+ 127,
5115
+ 32,
5116
+ "(",
5117
+ ")",
5118
+ "<",
5119
+ ">",
5120
+ "@",
5121
+ ",",
5122
+ ";",
5123
+ ":",
5124
+ "\\",
5125
+ '"',
5126
+ "/",
5127
+ "[",
5128
+ "]",
5129
+ "?",
5130
+ "=",
5131
+ "{",
5132
+ "}"
5133
+ ].includes(value);
5134
+ }
5135
+ function isValidHeaderValue(value) {
5136
+ if (typeof value !== "string") {
5137
+ return false;
5138
+ }
5139
+ if (value.trim() !== value) {
5140
+ return false;
5141
+ }
5142
+ for (let i = 0; i < value.length; i++) {
5143
+ const character = value.charCodeAt(i);
5144
+ if (
5145
+ // NUL.
5146
+ character === 0 || // HTTP newline bytes.
5147
+ character === 10 || character === 13
5148
+ ) {
5149
+ return false;
5150
+ }
5151
+ }
5152
+ return true;
5079
5153
  }
5080
5154
  var NORMALIZED_HEADERS = Symbol("normalizedHeaders");
5081
5155
  var RAW_HEADER_NAMES = Symbol("rawHeaderNames");
5082
5156
  var HEADER_VALUE_DELIMITER = ", ";
5083
5157
  var _a;
5084
5158
  var _b;
5085
- var HeadersPolyfill = class {
5159
+ var Headers2 = class _Headers {
5086
5160
  constructor(init) {
5087
5161
  this[_a] = {};
5088
5162
  this[_b] = /* @__PURE__ */ new Map();
5089
- if (["Headers", "HeadersPolyfill"].includes(init == null ? void 0 : init.constructor.name) || init instanceof HeadersPolyfill) {
5163
+ if (["Headers", "HeadersPolyfill"].includes(init == null ? void 0 : init.constructor.name) || init instanceof _Headers) {
5090
5164
  const initialHeaders = init;
5091
5165
  initialHeaders.forEach((value, name) => {
5092
5166
  this.append(name, value);
@@ -5112,35 +5186,79 @@ spurious results.`);
5112
5186
  return this.entries();
5113
5187
  }
5114
5188
  *keys() {
5115
- for (const name of Object.keys(this[NORMALIZED_HEADERS])) {
5189
+ for (const [name] of this.entries()) {
5116
5190
  yield name;
5117
5191
  }
5118
5192
  }
5119
5193
  *values() {
5120
- for (const value of Object.values(this[NORMALIZED_HEADERS])) {
5194
+ for (const [, value] of this.entries()) {
5121
5195
  yield value;
5122
5196
  }
5123
5197
  }
5124
5198
  *entries() {
5125
- for (const name of Object.keys(this[NORMALIZED_HEADERS])) {
5126
- yield [name, this.get(name)];
5199
+ let sortedKeys = Object.keys(this[NORMALIZED_HEADERS]).sort(
5200
+ (a, b) => a.localeCompare(b)
5201
+ );
5202
+ for (const name of sortedKeys) {
5203
+ if (name === "set-cookie") {
5204
+ for (const value of this.getSetCookie()) {
5205
+ yield [name, value];
5206
+ }
5207
+ } else {
5208
+ yield [name, this.get(name)];
5209
+ }
5210
+ }
5211
+ }
5212
+ /**
5213
+ * Returns a boolean stating whether a `Headers` object contains a certain header.
5214
+ */
5215
+ has(name) {
5216
+ if (!isValidHeaderName(name)) {
5217
+ throw new TypeError(`Invalid header name "${name}"`);
5127
5218
  }
5219
+ return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name));
5128
5220
  }
5221
+ /**
5222
+ * Returns a `ByteString` sequence of all the values of a header with a given name.
5223
+ */
5129
5224
  get(name) {
5130
5225
  var _a3;
5226
+ if (!isValidHeaderName(name)) {
5227
+ throw TypeError(`Invalid header name "${name}"`);
5228
+ }
5131
5229
  return (_a3 = this[NORMALIZED_HEADERS][normalizeHeaderName(name)]) != null ? _a3 : null;
5132
5230
  }
5231
+ /**
5232
+ * Sets a new value for an existing header inside a `Headers` object, or adds the header if it does not already exist.
5233
+ */
5133
5234
  set(name, value) {
5235
+ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
5236
+ return;
5237
+ }
5134
5238
  const normalizedName = normalizeHeaderName(name);
5135
- this[NORMALIZED_HEADERS][normalizedName] = normalizeHeaderValue(value);
5239
+ const normalizedValue = normalizeHeaderValue(value);
5240
+ this[NORMALIZED_HEADERS][normalizedName] = normalizeHeaderValue(normalizedValue);
5136
5241
  this[RAW_HEADER_NAMES].set(normalizedName, name);
5137
5242
  }
5243
+ /**
5244
+ * Appends a new value onto an existing header inside a `Headers` object, or adds the header if it does not already exist.
5245
+ */
5138
5246
  append(name, value) {
5247
+ if (!isValidHeaderName(name) || !isValidHeaderValue(value)) {
5248
+ return;
5249
+ }
5139
5250
  const normalizedName = normalizeHeaderName(name);
5140
- let resolvedValue = this.has(normalizedName) ? `${this.get(normalizedName)}, ${value}` : value;
5251
+ const normalizedValue = normalizeHeaderValue(value);
5252
+ let resolvedValue = this.has(normalizedName) ? `${this.get(normalizedName)}, ${normalizedValue}` : normalizedValue;
5141
5253
  this.set(name, resolvedValue);
5142
5254
  }
5255
+ /**
5256
+ * Deletes a header from the `Headers` object.
5257
+ */
5143
5258
  delete(name) {
5259
+ if (!isValidHeaderName(name)) {
5260
+ return;
5261
+ }
5144
5262
  if (!this.has(name)) {
5145
5263
  return;
5146
5264
  }
@@ -5148,26 +5266,20 @@ spurious results.`);
5148
5266
  delete this[NORMALIZED_HEADERS][normalizedName];
5149
5267
  this[RAW_HEADER_NAMES].delete(normalizedName);
5150
5268
  }
5151
- all() {
5152
- return this[NORMALIZED_HEADERS];
5153
- }
5154
- raw() {
5155
- const rawHeaders = {};
5156
- for (const [name, value] of this.entries()) {
5157
- rawHeaders[this[RAW_HEADER_NAMES].get(name)] = value;
5158
- }
5159
- return rawHeaders;
5160
- }
5161
- has(name) {
5162
- return this[NORMALIZED_HEADERS].hasOwnProperty(normalizeHeaderName(name));
5163
- }
5269
+ /**
5270
+ * Traverses the `Headers` object,
5271
+ * calling the given callback for each header.
5272
+ */
5164
5273
  forEach(callback, thisArg) {
5165
- for (const name in this[NORMALIZED_HEADERS]) {
5166
- if (this[NORMALIZED_HEADERS].hasOwnProperty(name)) {
5167
- callback.call(thisArg, this[NORMALIZED_HEADERS][name], name, this);
5168
- }
5274
+ for (const [name, value] of this.entries()) {
5275
+ callback.call(thisArg, value, name, this);
5169
5276
  }
5170
5277
  }
5278
+ /**
5279
+ * Returns an array containing the values
5280
+ * of all Set-Cookie headers associated
5281
+ * with a response
5282
+ */
5171
5283
  getSetCookie() {
5172
5284
  const setCookieHeader = this.get("set-cookie");
5173
5285
  if (setCookieHeader === null) {
@@ -5190,7 +5302,7 @@ spurious results.`);
5190
5302
  const value = parts.join(": ");
5191
5303
  headers.append(name, value);
5192
5304
  return headers;
5193
- }, new HeadersPolyfill());
5305
+ }, new Headers2());
5194
5306
  }
5195
5307
 
5196
5308
  // src/core/utils/internal/parseMultipartData.ts
@@ -5411,43 +5523,48 @@ spurious results.`);
5411
5523
  });
5412
5524
  this.endpoint = endpoint;
5413
5525
  }
5414
- parse(request) {
5526
+ parse(args) {
5415
5527
  return __async(this, null, function* () {
5416
- return parseGraphQLRequest(request).catch((error3) => {
5528
+ return parseGraphQLRequest(args.request).catch((error3) => {
5417
5529
  console.error(error3);
5418
5530
  return void 0;
5419
5531
  });
5420
5532
  });
5421
5533
  }
5422
- predicate(request, parsedResult) {
5423
- if (!parsedResult) {
5534
+ predicate(args) {
5535
+ if (!args.parsedResult) {
5424
5536
  return false;
5425
5537
  }
5426
- if (!parsedResult.operationName && this.info.operationType !== "all") {
5427
- const publicUrl = getPublicUrlFromRequest(request);
5428
- devUtils.warn(`Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
5538
+ if (!args.parsedResult.operationName && this.info.operationType !== "all") {
5539
+ const publicUrl = getPublicUrlFromRequest(args.request);
5540
+ devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
5429
5541
 
5430
5542
  Consider naming this operation or using "graphql.operation()" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation`);
5431
5543
  return false;
5432
5544
  }
5433
- const hasMatchingUrl = matchRequestUrl(new URL(request.url), this.endpoint);
5434
- const hasMatchingOperationType = this.info.operationType === "all" || parsedResult.operationType === this.info.operationType;
5435
- const hasMatchingOperationName = this.info.operationName instanceof RegExp ? this.info.operationName.test(parsedResult.operationName || "") : parsedResult.operationName === this.info.operationName;
5545
+ const hasMatchingUrl = matchRequestUrl(
5546
+ new URL(args.request.url),
5547
+ this.endpoint
5548
+ );
5549
+ const hasMatchingOperationType = this.info.operationType === "all" || args.parsedResult.operationType === this.info.operationType;
5550
+ const hasMatchingOperationName = this.info.operationName instanceof RegExp ? this.info.operationName.test(args.parsedResult.operationName || "") : args.parsedResult.operationName === this.info.operationName;
5436
5551
  return hasMatchingUrl.matches && hasMatchingOperationType && hasMatchingOperationName;
5437
5552
  }
5438
- extendInfo(_request, parsedResult) {
5553
+ extendResolverArgs(args) {
5554
+ var _a3, _b2, _c;
5439
5555
  return {
5440
- query: (parsedResult == null ? void 0 : parsedResult.query) || "",
5441
- operationName: (parsedResult == null ? void 0 : parsedResult.operationName) || "",
5442
- variables: (parsedResult == null ? void 0 : parsedResult.variables) || {}
5556
+ query: ((_a3 = args.parsedResult) == null ? void 0 : _a3.query) || "",
5557
+ operationName: ((_b2 = args.parsedResult) == null ? void 0 : _b2.operationName) || "",
5558
+ variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
5443
5559
  };
5444
5560
  }
5445
- log(request, response, parsedRequest) {
5561
+ log(args) {
5446
5562
  return __async(this, null, function* () {
5447
- const loggedRequest = yield serializeRequest(request);
5448
- const loggedResponse = yield serializeResponse(response);
5563
+ var _a3, _b2, _c, _d;
5564
+ const loggedRequest = yield serializeRequest(args.request);
5565
+ const loggedResponse = yield serializeResponse(args.response);
5449
5566
  const statusColor = getStatusCodeColor(loggedResponse.status);
5450
- const requestInfo = (parsedRequest == null ? void 0 : parsedRequest.operationName) ? `${parsedRequest == null ? void 0 : parsedRequest.operationType} ${parsedRequest == null ? void 0 : parsedRequest.operationName}` : `anonymous ${parsedRequest == null ? void 0 : parsedRequest.operationType}`;
5567
+ const requestInfo = ((_a3 = args.parsedResult) == null ? void 0 : _a3.operationName) ? `${(_b2 = args.parsedResult) == null ? void 0 : _b2.operationType} ${(_c = args.parsedResult) == null ? void 0 : _c.operationName}` : `anonymous ${(_d = args.parsedResult) == null ? void 0 : _d.operationType}`;
5451
5568
  console.groupCollapsed(
5452
5569
  devUtils.formatMessage("%s %s (%c%s%c)"),
5453
5570
  getTimestamp(),
@@ -5483,32 +5600,39 @@ Consider naming this operation or using "graphql.operation()" request handler to
5483
5600
  }
5484
5601
  var standardGraphQLHandlers = {
5485
5602
  /**
5486
- * Captures any GraphQL operation, regardless of its name, under the current scope.
5487
- * @example
5488
- * graphql.operation(() => {
5489
- * return HttpResponse.json({ data: { name: 'John' } })
5490
- * })
5491
- * @see {@link https://mswjs.io/docs/api/graphql/operation `graphql.operation()`}
5492
- */
5493
- operation: createGraphQLOperationHandler("*"),
5494
- /**
5495
- * Captures a GraphQL query by a given name.
5603
+ * Intercepts a GraphQL query by a given name.
5604
+ *
5496
5605
  * @example
5497
5606
  * graphql.query('GetUser', () => {
5498
5607
  * return HttpResponse.json({ data: { user: { name: 'John' } } })
5499
5608
  * })
5500
- * @see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
5609
+ *
5610
+ * @see {@link https://mswjs.io/docs/api/graphql#graphqlqueryqueryname-resolver `graphql.query()` API reference}
5501
5611
  */
5502
5612
  query: createScopedGraphQLHandler("query", "*"),
5503
5613
  /**
5504
- * Captures a GraphQL mutation by a given name.
5614
+ * Intercepts a GraphQL mutation by its name.
5615
+ *
5505
5616
  * @example
5506
5617
  * graphql.mutation('SavePost', () => {
5507
5618
  * return HttpResponse.json({ data: { post: { id: 'abc-123 } } })
5508
5619
  * })
5509
- * @see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
5620
+ *
5621
+ * @see {@link https://mswjs.io/docs/api/graphql#graphqlmutationmutationname-resolver `graphql.query()` API reference}
5622
+ *
5510
5623
  */
5511
- mutation: createScopedGraphQLHandler("mutation", "*")
5624
+ mutation: createScopedGraphQLHandler("mutation", "*"),
5625
+ /**
5626
+ * Intercepts any GraphQL operation, regardless of its type or name.
5627
+ *
5628
+ * @example
5629
+ * graphql.operation(() => {
5630
+ * return HttpResponse.json({ data: { name: 'John' } })
5631
+ * })
5632
+ *
5633
+ * @see {@link https://mswjs.io/docs/api/graphql#graphloperationresolver `graphql.operation()` API reference}
5634
+ */
5635
+ operation: createGraphQLOperationHandler("*")
5512
5636
  };
5513
5637
  function createGraphQLLink(url) {
5514
5638
  return {
@@ -5518,6 +5642,15 @@ Consider naming this operation or using "graphql.operation()" request handler to
5518
5642
  };
5519
5643
  }
5520
5644
  var graphql = __spreadProps(__spreadValues({}, standardGraphQLHandlers), {
5645
+ /**
5646
+ * Intercepts GraphQL operations scoped by the given URL.
5647
+ *
5648
+ * @example
5649
+ * const github = graphql.link('https://api.github.com/graphql')
5650
+ * github.query('GetRepo', resolver)
5651
+ *
5652
+ * @see {@link https://mswjs.io/docs/api/graphql#graphqllinkurl `graphql.link()` API reference}
5653
+ */
5521
5654
  link: createGraphQLLink
5522
5655
  });
5523
5656
 
@@ -5538,7 +5671,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
5538
5671
  let matchingHandler = null;
5539
5672
  let result = null;
5540
5673
  for (const handler of handlers) {
5541
- result = yield handler.run(request, resolutionContext);
5674
+ result = yield handler.run({ request, resolutionContext });
5542
5675
  if (result !== null) {
5543
5676
  matchingHandler = handler;
5544
5677
  }
@@ -5549,7 +5682,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
5549
5682
  if (matchingHandler) {
5550
5683
  return {
5551
5684
  handler: matchingHandler,
5552
- parsedRequest: result == null ? void 0 : result.parsedResult,
5685
+ parsedResult: result == null ? void 0 : result.parsedResult,
5553
5686
  response: result == null ? void 0 : result.response
5554
5687
  };
5555
5688
  }
@@ -5760,7 +5893,7 @@ ${handlers.map((handler) => ` \u2022 ${handler.info.header}`).join("\n")}`;
5760
5893
  const requestHeader = parsedGraphQLQuery ? getGraphQLRequestHeader(parsedGraphQLQuery) : `${request.method} ${publicUrl}`;
5761
5894
  const handlerSuggestion = generateHandlerSuggestion();
5762
5895
  const messageTemplate = [
5763
- `captured a request without a matching request handler:`,
5896
+ `intercepted a request without a matching request handler:`,
5764
5897
  ` \u2022 ${requestHeader}`,
5765
5898
  handlerSuggestion,
5766
5899
  `If you still wish to intercept this unhandled request, please create a request handler for it.
@@ -6231,7 +6364,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
6231
6364
  messageChannel.postMessage("NOT_FOUND");
6232
6365
  },
6233
6366
  onMockedResponse(_0, _1) {
6234
- return __async(this, arguments, function* (response, { handler, parsedRequest }) {
6367
+ return __async(this, arguments, function* (response, { handler, parsedResult }) {
6235
6368
  const responseClone = response.clone();
6236
6369
  const responseInit = toResponseInit(response);
6237
6370
  const responseStream = responseClone.body;
@@ -6246,7 +6379,11 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
6246
6379
  );
6247
6380
  if (!options.quiet) {
6248
6381
  context.emitter.once("response:mocked", ({ response: response2 }) => {
6249
- handler.log(requestCloneForLogs, response2, parsedRequest);
6382
+ handler.log({
6383
+ request: requestCloneForLogs,
6384
+ response: response2,
6385
+ parsedResult
6386
+ });
6250
6387
  });
6251
6388
  }
6252
6389
  });
@@ -6289,9 +6426,9 @@ This exception has been gracefully handled as a 500 response, however, it's stro
6289
6426
  const { payload: actualChecksum } = yield context.events.once(
6290
6427
  "INTEGRITY_CHECK_RESPONSE"
6291
6428
  );
6292
- if (actualChecksum !== "3343a047c60712815551260184217eb5") {
6429
+ if (actualChecksum !== "0877fcdc026242810f5bfde0d7178db4") {
6293
6430
  throw new Error(
6294
- `Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"3343a047c60712815551260184217eb5"}).`
6431
+ `Currently active Service Worker (${actualChecksum}) is behind the latest published one (${"0877fcdc026242810f5bfde0d7178db4"}).`
6295
6432
  );
6296
6433
  }
6297
6434
  return serviceWorker;
@@ -7760,10 +7897,14 @@ If this message still persists after updating, please report an issue: https://g
7760
7897
  options,
7761
7898
  context.emitter,
7762
7899
  {
7763
- onMockedResponse(_, { handler, parsedRequest }) {
7900
+ onMockedResponse(_, { handler, parsedResult }) {
7764
7901
  if (!options.quiet) {
7765
7902
  context.emitter.once("response:mocked", ({ response: response2 }) => {
7766
- handler.log(requestCloneForLogs, response2, parsedRequest);
7903
+ handler.log({
7904
+ request: requestCloneForLogs,
7905
+ response: response2,
7906
+ parsedResult
7907
+ });
7767
7908
  });
7768
7909
  }
7769
7910
  }