msw 2.0.4 → 2.0.6

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.
@@ -35,6 +35,7 @@ type GraphQLResolverExtras<Variables extends GraphQLVariables> = {
35
35
  query: string;
36
36
  operationName: string;
37
37
  variables: Variables;
38
+ cookies: Record<string, string | Array<string>>;
38
39
  };
39
40
  type GraphQLRequestBody<VariablesType extends GraphQLVariables> = GraphQLJsonRequestBody<VariablesType> | GraphQLMultipartRequestBody | Record<string, any> | undefined;
40
41
  interface GraphQLJsonRequestBody<Variables extends GraphQLVariables> {
@@ -54,7 +55,7 @@ declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, ParsedGr
54
55
  }): Promise<ParsedGraphQLRequest<GraphQLVariables>>;
55
56
  predicate(args: {
56
57
  request: Request;
57
- parsedResult: ParsedGraphQLRequest;
58
+ parsedResult: ParsedGraphQLRequest<GraphQLVariables>;
58
59
  }): boolean;
59
60
  protected extendResolverArgs(args: {
60
61
  request: Request;
@@ -63,6 +64,7 @@ declare class GraphQLHandler extends RequestHandler<GraphQLHandlerInfo, ParsedGr
63
64
  query: string;
64
65
  operationName: string;
65
66
  variables: GraphQLVariables;
67
+ cookies: Record<string, string>;
66
68
  };
67
69
  log(args: {
68
70
  request: Request;
@@ -1,6 +1,6 @@
1
1
  import { DocumentNode } from 'graphql';
2
2
  import { a as ResponseResolver, c as RequestHandlerOptions } from './RequestHandler-bb5cbb8f.js';
3
- import { a as GraphQLVariables, d as GraphQLHandlerNameSelector, e as GraphQLResolverExtras, f as GraphQLResponseBody, G as GraphQLHandler } from './GraphQLHandler-d46c4f60.js';
3
+ import { a as GraphQLVariables, d as GraphQLHandlerNameSelector, e as GraphQLResolverExtras, f as GraphQLResponseBody, G as GraphQLHandler } from './GraphQLHandler-074ec9e5.js';
4
4
  import { Path } from './utils/matching/matchRequestUrl.js';
5
5
  import './typeUtils.js';
6
6
 
@@ -1,5 +1,5 @@
1
1
  import 'graphql';
2
2
  import '../RequestHandler-bb5cbb8f.js';
3
3
  import '../utils/matching/matchRequestUrl.js';
4
- export { E as ExpectedOperationTypeNode, G as GraphQLHandler, k as GraphQLHandlerInfo, d as GraphQLHandlerNameSelector, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, e as GraphQLResolverExtras, f as GraphQLResponseBody, a as GraphQLVariables, l as isDocumentNode } from '../GraphQLHandler-d46c4f60.js';
4
+ export { E as ExpectedOperationTypeNode, G as GraphQLHandler, k as GraphQLHandlerInfo, d as GraphQLHandlerNameSelector, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, e as GraphQLResolverExtras, f as GraphQLResponseBody, a as GraphQLVariables, l as isDocumentNode } from '../GraphQLHandler-074ec9e5.js';
5
5
  import '../typeUtils.js';
@@ -51,6 +51,7 @@ var import_matchRequestUrl = require("../utils/matching/matchRequestUrl.js");
51
51
  var import_parseGraphQLRequest = require("../utils/internal/parseGraphQLRequest.js");
52
52
  var import_getPublicUrlFromRequest = require("../utils/request/getPublicUrlFromRequest.js");
53
53
  var import_devUtils = require("../utils/internal/devUtils.js");
54
+ var import_getRequestCookies = require("../utils/request/getRequestCookies.js");
54
55
  function isDocumentNode(value) {
55
56
  if (value == null) {
56
57
  return false;
@@ -88,10 +89,21 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
88
89
  }
89
90
  parse(args) {
90
91
  return __async(this, null, function* () {
91
- return (0, import_parseGraphQLRequest.parseGraphQLRequest)(args.request).catch((error) => {
92
- console.error(error);
92
+ const parsedResult = yield (0, import_parseGraphQLRequest.parseGraphQLRequest)(args.request).catch(
93
+ (error) => {
94
+ console.error(error);
95
+ return void 0;
96
+ }
97
+ );
98
+ if (typeof parsedResult === "undefined") {
93
99
  return void 0;
94
- });
100
+ }
101
+ return {
102
+ query: parsedResult.query,
103
+ operationType: parsedResult.operationType,
104
+ operationName: parsedResult.operationName,
105
+ variables: parsedResult.variables
106
+ };
95
107
  });
96
108
  }
97
109
  predicate(args) {
@@ -102,7 +114,7 @@ class GraphQLHandler extends import_RequestHandler.RequestHandler {
102
114
  const publicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(args.request);
103
115
  import_devUtils.devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
104
116
 
105
- 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`);
117
+ 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/#graphqloperationresolver`);
106
118
  return false;
107
119
  }
108
120
  const hasMatchingUrl = (0, import_matchRequestUrl.matchRequestUrl)(
@@ -115,10 +127,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
115
127
  }
116
128
  extendResolverArgs(args) {
117
129
  var _a, _b, _c;
130
+ const cookies = (0, import_getRequestCookies.getAllRequestCookies)(args.request);
118
131
  return {
119
132
  query: ((_a = args.parsedResult) == null ? void 0 : _a.query) || "",
120
133
  operationName: ((_b = args.parsedResult) == null ? void 0 : _b.operationName) || "",
121
- variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
134
+ variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {},
135
+ cookies
122
136
  };
123
137
  }
124
138
  log(args) {
@@ -32,6 +32,7 @@ import {
32
32
  } from '../utils/internal/parseGraphQLRequest.mjs';
33
33
  import { getPublicUrlFromRequest } from '../utils/request/getPublicUrlFromRequest.mjs';
34
34
  import { devUtils } from '../utils/internal/devUtils.mjs';
35
+ import { getAllRequestCookies } from '../utils/request/getRequestCookies.mjs';
35
36
  function isDocumentNode(value) {
36
37
  if (value == null) {
37
38
  return false;
@@ -69,10 +70,21 @@ class GraphQLHandler extends RequestHandler {
69
70
  }
70
71
  parse(args) {
71
72
  return __async(this, null, function* () {
72
- return parseGraphQLRequest(args.request).catch((error) => {
73
- console.error(error);
73
+ const parsedResult = yield parseGraphQLRequest(args.request).catch(
74
+ (error) => {
75
+ console.error(error);
76
+ return void 0;
77
+ }
78
+ );
79
+ if (typeof parsedResult === "undefined") {
74
80
  return void 0;
75
- });
81
+ }
82
+ return {
83
+ query: parsedResult.query,
84
+ operationType: parsedResult.operationType,
85
+ operationName: parsedResult.operationName,
86
+ variables: parsedResult.variables
87
+ };
76
88
  });
77
89
  }
78
90
  predicate(args) {
@@ -83,7 +95,7 @@ class GraphQLHandler extends RequestHandler {
83
95
  const publicUrl = getPublicUrlFromRequest(args.request);
84
96
  devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
85
97
 
86
- 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`);
98
+ 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/#graphqloperationresolver`);
87
99
  return false;
88
100
  }
89
101
  const hasMatchingUrl = matchRequestUrl(
@@ -96,10 +108,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
96
108
  }
97
109
  extendResolverArgs(args) {
98
110
  var _a, _b, _c;
111
+ const cookies = getAllRequestCookies(args.request);
99
112
  return {
100
113
  query: ((_a = args.parsedResult) == null ? void 0 : _a.query) || "",
101
114
  operationName: ((_b = args.parsedResult) == null ? void 0 : _b.operationName) || "",
102
- variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
115
+ variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {},
116
+ cookies
103
117
  };
104
118
  }
105
119
  log(args) {
@@ -3,7 +3,7 @@ export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as Defaul
3
3
  export { http } from './http.js';
4
4
  export { HttpHandler, HttpMethods, HttpRequestParsedResult, RequestQuery } from './handlers/HttpHandler.js';
5
5
  export { graphql } from './graphql.js';
6
- export { G as GraphQLHandler, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, a as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-d46c4f60.js';
6
+ export { G as GraphQLHandler, c as GraphQLJsonRequestBody, b as GraphQLRequestBody, a as GraphQLVariables, P as ParsedGraphQLRequest } from './GraphQLHandler-074ec9e5.js';
7
7
  export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.js';
8
8
  export { HandleRequestOptions, handleRequest } from './utils/handleRequest.js';
9
9
  export { cleanUrl } from './utils/url/cleanUrl.js';
@@ -1,5 +1,5 @@
1
1
  import 'graphql';
2
- export { i as GraphQLMultipartRequestBody, h as GraphQLParsedOperationsMap, g as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, j as parseGraphQLRequest } from '../../GraphQLHandler-d46c4f60.js';
2
+ export { i as GraphQLMultipartRequestBody, h as GraphQLParsedOperationsMap, g as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, j as parseGraphQLRequest } from '../../GraphQLHandler-074ec9e5.js';
3
3
  import '../../RequestHandler-bb5cbb8f.js';
4
4
  import '../../typeUtils.js';
5
5
  import '../matching/matchRequestUrl.js';
package/lib/iife/index.js CHANGED
@@ -1596,7 +1596,7 @@ var MockServiceWorker = (() => {
1596
1596
  var Emitter2 = _Emitter2;
1597
1597
  Emitter2.defaultMaxListeners = 10;
1598
1598
 
1599
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/node/chunk-JAW6F2FR.mjs
1599
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/node/chunk-JAW6F2FR.mjs
1600
1600
  function getGlobalSymbol(symbol) {
1601
1601
  return (
1602
1602
  // @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
@@ -1740,7 +1740,7 @@ var MockServiceWorker = (() => {
1740
1740
  }
1741
1741
  };
1742
1742
 
1743
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/node/chunk-LNYHQTKT.mjs
1743
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/node/chunk-LNYHQTKT.mjs
1744
1744
  var BatchInterceptor = class extends Interceptor {
1745
1745
  constructor(options) {
1746
1746
  BatchInterceptor.symbol = Symbol(options.name);
@@ -1783,13 +1783,13 @@ var MockServiceWorker = (() => {
1783
1783
  }
1784
1784
  };
1785
1785
 
1786
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/node/chunk-7II4SWKS.mjs
1786
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/node/chunk-7II4SWKS.mjs
1787
1787
  var encoder = new TextEncoder();
1788
1788
 
1789
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/node/chunk-GFH37L5D.mjs
1789
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/node/chunk-GFH37L5D.mjs
1790
1790
  var IS_PATCHED_MODULE = Symbol("isPatchedModule");
1791
1791
 
1792
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/node/index.mjs
1792
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/node/index.mjs
1793
1793
  function getCleanUrl(url, isAbsolute = true) {
1794
1794
  return [isAbsolute && url.origin, url.pathname].filter(Boolean).join("");
1795
1795
  }
@@ -5639,10 +5639,21 @@ spurious results.`);
5639
5639
  }
5640
5640
  parse(args) {
5641
5641
  return __async(this, null, function* () {
5642
- return parseGraphQLRequest(args.request).catch((error3) => {
5643
- console.error(error3);
5642
+ const parsedResult = yield parseGraphQLRequest(args.request).catch(
5643
+ (error3) => {
5644
+ console.error(error3);
5645
+ return void 0;
5646
+ }
5647
+ );
5648
+ if (typeof parsedResult === "undefined") {
5644
5649
  return void 0;
5645
- });
5650
+ }
5651
+ return {
5652
+ query: parsedResult.query,
5653
+ operationType: parsedResult.operationType,
5654
+ operationName: parsedResult.operationName,
5655
+ variables: parsedResult.variables
5656
+ };
5646
5657
  });
5647
5658
  }
5648
5659
  predicate(args) {
@@ -5653,7 +5664,7 @@ spurious results.`);
5653
5664
  const publicUrl = getPublicUrlFromRequest(args.request);
5654
5665
  devUtils.warn(`Failed to intercept a GraphQL request at "${args.request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
5655
5666
 
5656
- 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`);
5667
+ 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/#graphqloperationresolver`);
5657
5668
  return false;
5658
5669
  }
5659
5670
  const hasMatchingUrl = matchRequestUrl(
@@ -5666,10 +5677,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
5666
5677
  }
5667
5678
  extendResolverArgs(args) {
5668
5679
  var _a3, _b2, _c;
5680
+ const cookies = getAllRequestCookies(args.request);
5669
5681
  return {
5670
5682
  query: ((_a3 = args.parsedResult) == null ? void 0 : _a3.query) || "",
5671
5683
  operationName: ((_b2 = args.parsedResult) == null ? void 0 : _b2.operationName) || "",
5672
- variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {}
5684
+ variables: ((_c = args.parsedResult) == null ? void 0 : _c.variables) || {},
5685
+ cookies
5673
5686
  };
5674
5687
  }
5675
5688
  log(args) {
@@ -6832,7 +6845,7 @@ If this message still persists after updating, please report an issue: https://g
6832
6845
  });
6833
6846
  }, _a2);
6834
6847
 
6835
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/browser/chunk-KK6APRON.mjs
6848
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/browser/chunk-KK6APRON.mjs
6836
6849
  function uuidv4() {
6837
6850
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
6838
6851
  const r = Math.random() * 16 | 0;
@@ -6879,7 +6892,7 @@ If this message still persists after updating, please report an issue: https://g
6879
6892
  });
6880
6893
  }
6881
6894
 
6882
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/browser/chunk-S72SKXXQ.mjs
6895
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/browser/chunk-S72SKXXQ.mjs
6883
6896
  var IS_PATCHED_MODULE2 = Symbol("isPatchedModule");
6884
6897
  function getGlobalSymbol2(symbol) {
6885
6898
  return (
@@ -7024,7 +7037,7 @@ If this message still persists after updating, please report an issue: https://g
7024
7037
  }
7025
7038
  };
7026
7039
 
7027
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/browser/chunk-KRADPSOF.mjs
7040
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/browser/chunk-KRADPSOF.mjs
7028
7041
  function isPropertyAccessible2(obj, key) {
7029
7042
  try {
7030
7043
  obj[key];
@@ -7161,7 +7174,7 @@ If this message still persists after updating, please report an issue: https://g
7161
7174
  });
7162
7175
  }
7163
7176
 
7164
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/browser/chunk-7II4SWKS.mjs
7177
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/browser/chunk-7II4SWKS.mjs
7165
7178
  var encoder2 = new TextEncoder();
7166
7179
  function encodeBuffer2(text) {
7167
7180
  return encoder2.encode(text);
@@ -7177,7 +7190,7 @@ If this message still persists after updating, please report an issue: https://g
7177
7190
  );
7178
7191
  }
7179
7192
 
7180
- // node_modules/.pnpm/@mswjs+interceptors@0.25.10/node_modules/@mswjs/interceptors/lib/browser/chunk-NJQK65MD.mjs
7193
+ // node_modules/.pnpm/@mswjs+interceptors@0.25.11/node_modules/@mswjs/interceptors/lib/browser/chunk-PYOA2PFX.mjs
7181
7194
  function concatArrayBuffer(left, right) {
7182
7195
  const result = new Uint8Array(left.byteLength + right.byteLength);
7183
7196
  result.set(left, 0);
@@ -7759,6 +7772,9 @@ If this message still persists after updating, please report an issue: https://g
7759
7772
  }
7760
7773
  };
7761
7774
  function toAbsoluteUrl(url) {
7775
+ if (typeof location === "undefined") {
7776
+ return new URL(url);
7777
+ }
7762
7778
  return new URL(url.toString(), location.href);
7763
7779
  }
7764
7780
  function define(target, property, value) {
@@ -2,7 +2,7 @@
2
2
  /* tslint:disable */
3
3
 
4
4
  /**
5
- * Mock Service Worker (2.0.4).
5
+ * Mock Service Worker (2.0.6).
6
6
  * @see https://github.com/mswjs/msw
7
7
  * - Please do NOT modify this file.
8
8
  * - Please do NOT serve this file on production.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "msw",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
5
5
  "main": "./lib/core/index.js",
6
6
  "module": "./lib/core/index.mjs",
@@ -94,7 +94,7 @@
94
94
  "@bundled-es-modules/js-levenshtein": "^2.0.1",
95
95
  "@bundled-es-modules/statuses": "^1.0.1",
96
96
  "@mswjs/cookies": "^1.1.0",
97
- "@mswjs/interceptors": "^0.25.10",
97
+ "@mswjs/interceptors": "^0.25.11",
98
98
  "@open-draft/until": "^2.1.0",
99
99
  "@types/cookie": "^0.4.1",
100
100
  "@types/js-levenshtein": "^1.1.1",
@@ -161,6 +161,7 @@
161
161
  "undici": "^5.20.0",
162
162
  "url-loader": "^4.1.1",
163
163
  "vitest": "^0.34.6",
164
+ "vitest-environment-miniflare": "^2.14.1",
164
165
  "webpack": "^5.68.0",
165
166
  "webpack-dev-server": "^3.11.2",
166
167
  "webpack-http-server": "^0.5.0"