msw 2.12.12 → 2.12.13

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 (66) hide show
  1. package/lib/core/{HttpResponse-B9rGc56D.d.mts → HttpResponse-Be4eT3x6.d.mts} +8 -2
  2. package/lib/core/{HttpResponse-Dz84tqeA.d.ts → HttpResponse-Dj6ibgFJ.d.ts} +8 -2
  3. package/lib/core/HttpResponse.d.mts +1 -1
  4. package/lib/core/HttpResponse.d.ts +1 -1
  5. package/lib/core/HttpResponse.js +53 -11
  6. package/lib/core/HttpResponse.js.map +1 -1
  7. package/lib/core/HttpResponse.mjs +53 -11
  8. package/lib/core/HttpResponse.mjs.map +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 +1 -1
  14. package/lib/core/graphql.d.ts +1 -1
  15. package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
  16. package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
  17. package/lib/core/handlers/GraphQLHandler.js +29 -1
  18. package/lib/core/handlers/GraphQLHandler.js.map +1 -1
  19. package/lib/core/handlers/GraphQLHandler.mjs +29 -1
  20. package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
  21. package/lib/core/handlers/HttpHandler.d.mts +1 -1
  22. package/lib/core/handlers/HttpHandler.d.ts +1 -1
  23. package/lib/core/handlers/RequestHandler.d.mts +1 -1
  24. package/lib/core/handlers/RequestHandler.d.ts +1 -1
  25. package/lib/core/handlers/RequestHandler.js.map +1 -1
  26. package/lib/core/handlers/RequestHandler.mjs.map +1 -1
  27. package/lib/core/http.d.mts +1 -1
  28. package/lib/core/http.d.ts +1 -1
  29. package/lib/core/index.d.mts +2 -2
  30. package/lib/core/index.d.ts +2 -2
  31. package/lib/core/passthrough.d.mts +1 -1
  32. package/lib/core/passthrough.d.ts +1 -1
  33. package/lib/core/sse.d.mts +1 -1
  34. package/lib/core/sse.d.ts +1 -1
  35. package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
  36. package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
  37. package/lib/core/utils/executeHandlers.d.mts +1 -1
  38. package/lib/core/utils/executeHandlers.d.ts +1 -1
  39. package/lib/core/utils/handleRequest.d.mts +1 -1
  40. package/lib/core/utils/handleRequest.d.ts +1 -1
  41. package/lib/core/utils/internal/isHandlerKind.d.mts +1 -1
  42. package/lib/core/utils/internal/isHandlerKind.d.ts +1 -1
  43. package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
  44. package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
  45. package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
  46. package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
  47. package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
  48. package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
  49. package/lib/core/utils/request/getAllAcceptedMimeTypes.d.mts +14 -0
  50. package/lib/core/utils/request/getAllAcceptedMimeTypes.d.ts +14 -0
  51. package/lib/core/utils/request/getAllAcceptedMimeTypes.js +61 -0
  52. package/lib/core/utils/request/getAllAcceptedMimeTypes.js.map +1 -0
  53. package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs +41 -0
  54. package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs.map +1 -0
  55. package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
  56. package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
  57. package/lib/iife/index.js +256 -150
  58. package/lib/iife/index.js.map +1 -1
  59. package/lib/mockServiceWorker.js +1 -1
  60. package/package.json +2 -2
  61. package/src/core/HttpResponse.test.ts +25 -9
  62. package/src/core/HttpResponse.ts +62 -10
  63. package/src/core/handlers/GraphQLHandler.ts +53 -1
  64. package/src/core/handlers/RequestHandler.ts +1 -1
  65. package/src/core/utils/request/getAllAcceptedMimeTypes.test.ts +86 -0
  66. package/src/core/utils/request/getAllAcceptedMimeTypes.ts +70 -0
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns all accepted mime types, ordered by precedence as defined
3
+ * in [RFC 7231 Section 5.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2).
4
+ *
5
+ * Precedence rules (highest to lowest):
6
+ * 1. Quality value (`q` parameter, default 1).
7
+ * 2. Specificity: `type/subtype` > `type/*` > `*\/*`.
8
+ * 3. Number of media type parameters (more = more specific).
9
+ *
10
+ * Types with `q=0` are excluded (explicitly not acceptable).
11
+ */
12
+ declare function getAllAcceptedMimeTypes(acceptHeader: string | null): Array<string>;
13
+
14
+ export { getAllAcceptedMimeTypes };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns all accepted mime types, ordered by precedence as defined
3
+ * in [RFC 7231 Section 5.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2).
4
+ *
5
+ * Precedence rules (highest to lowest):
6
+ * 1. Quality value (`q` parameter, default 1).
7
+ * 2. Specificity: `type/subtype` > `type/*` > `*\/*`.
8
+ * 3. Number of media type parameters (more = more specific).
9
+ *
10
+ * Types with `q=0` are excluded (explicitly not acceptable).
11
+ */
12
+ declare function getAllAcceptedMimeTypes(acceptHeader: string | null): Array<string>;
13
+
14
+ export { getAllAcceptedMimeTypes };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var getAllAcceptedMimeTypes_exports = {};
20
+ __export(getAllAcceptedMimeTypes_exports, {
21
+ getAllAcceptedMimeTypes: () => getAllAcceptedMimeTypes
22
+ });
23
+ module.exports = __toCommonJS(getAllAcceptedMimeTypes_exports);
24
+ function getAllAcceptedMimeTypes(acceptHeader) {
25
+ if (acceptHeader == null) {
26
+ return [];
27
+ }
28
+ const accepted = [];
29
+ for (const part of acceptHeader.split(",")) {
30
+ const [type, ...params] = part.split(";").map((v) => v.trim());
31
+ let quality = 1;
32
+ let parameterCount = 0;
33
+ for (const param of params) {
34
+ const [key, value] = param.split("=").map((v) => v.trim());
35
+ if (key === "q") {
36
+ quality = Number(value);
37
+ } else {
38
+ parameterCount++;
39
+ }
40
+ }
41
+ if (quality === 0) {
42
+ continue;
43
+ }
44
+ const [mediaType, mediaSubtype] = type.split("/");
45
+ const specificity = mediaType === "*" ? 0 : mediaSubtype === "*" ? 1 : 2;
46
+ accepted.push({ type, quality, specificity, parameterCount });
47
+ }
48
+ if (!accepted.length) {
49
+ return [];
50
+ }
51
+ return accepted.sort((left, right) => {
52
+ if (right.quality !== left.quality) {
53
+ return right.quality - left.quality;
54
+ }
55
+ if (right.specificity !== left.specificity) {
56
+ return right.specificity - left.specificity;
57
+ }
58
+ return right.parameterCount - left.parameterCount;
59
+ }).map((entry) => entry.type);
60
+ }
61
+ //# sourceMappingURL=getAllAcceptedMimeTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/core/utils/request/getAllAcceptedMimeTypes.ts"],"sourcesContent":["/**\n * Returns all accepted mime types, ordered by precedence as defined\n * in [RFC 7231 Section 5.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2).\n *\n * Precedence rules (highest to lowest):\n * 1. Quality value (`q` parameter, default 1).\n * 2. Specificity: `type/subtype` > `type/*` > `*\\/*`.\n * 3. Number of media type parameters (more = more specific).\n *\n * Types with `q=0` are excluded (explicitly not acceptable).\n */\nexport function getAllAcceptedMimeTypes(\n acceptHeader: string | null,\n): Array<string> {\n if (acceptHeader == null) {\n return []\n }\n\n const accepted: Array<{\n type: string\n quality: number\n specificity: number\n parameterCount: number\n }> = []\n\n for (const part of acceptHeader.split(',')) {\n const [type, ...params] = part.split(';').map((v) => v.trim())\n\n let quality = 1\n let parameterCount = 0\n\n for (const param of params) {\n const [key, value] = param.split('=').map((v) => v.trim())\n\n if (key === 'q') {\n quality = Number(value)\n } else {\n parameterCount++\n }\n }\n\n // RFC 7231: a quality value of 0 indicates \"not acceptable\".\n if (quality === 0) {\n continue\n }\n\n const [mediaType, mediaSubtype] = type.split('/')\n const specificity = mediaType === '*' ? 0 : mediaSubtype === '*' ? 1 : 2\n\n accepted.push({ type, quality, specificity, parameterCount })\n }\n\n if (!accepted.length) {\n return []\n }\n\n return accepted\n .sort((left, right) => {\n if (right.quality !== left.quality) {\n return right.quality - left.quality\n }\n\n if (right.specificity !== left.specificity) {\n return right.specificity - left.specificity\n }\n\n return right.parameterCount - left.parameterCount\n })\n .map((entry) => entry.type)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,SAAS,wBACd,cACe;AACf,MAAI,gBAAgB,MAAM;AACxB,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,WAKD,CAAC;AAEN,aAAW,QAAQ,aAAa,MAAM,GAAG,GAAG;AAC1C,UAAM,CAAC,MAAM,GAAG,MAAM,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAE7D,QAAI,UAAU;AACd,QAAI,iBAAiB;AAErB,eAAW,SAAS,QAAQ;AAC1B,YAAM,CAAC,KAAK,KAAK,IAAI,MAAM,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAEzD,UAAI,QAAQ,KAAK;AACf,kBAAU,OAAO,KAAK;AAAA,MACxB,OAAO;AACL;AAAA,MACF;AAAA,IACF;AAGA,QAAI,YAAY,GAAG;AACjB;AAAA,IACF;AAEA,UAAM,CAAC,WAAW,YAAY,IAAI,KAAK,MAAM,GAAG;AAChD,UAAM,cAAc,cAAc,MAAM,IAAI,iBAAiB,MAAM,IAAI;AAEvE,aAAS,KAAK,EAAE,MAAM,SAAS,aAAa,eAAe,CAAC;AAAA,EAC9D;AAEA,MAAI,CAAC,SAAS,QAAQ;AACpB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,SACJ,KAAK,CAAC,MAAM,UAAU;AACrB,QAAI,MAAM,YAAY,KAAK,SAAS;AAClC,aAAO,MAAM,UAAU,KAAK;AAAA,IAC9B;AAEA,QAAI,MAAM,gBAAgB,KAAK,aAAa;AAC1C,aAAO,MAAM,cAAc,KAAK;AAAA,IAClC;AAEA,WAAO,MAAM,iBAAiB,KAAK;AAAA,EACrC,CAAC,EACA,IAAI,CAAC,UAAU,MAAM,IAAI;AAC9B;","names":[]}
@@ -0,0 +1,41 @@
1
+ function getAllAcceptedMimeTypes(acceptHeader) {
2
+ if (acceptHeader == null) {
3
+ return [];
4
+ }
5
+ const accepted = [];
6
+ for (const part of acceptHeader.split(",")) {
7
+ const [type, ...params] = part.split(";").map((v) => v.trim());
8
+ let quality = 1;
9
+ let parameterCount = 0;
10
+ for (const param of params) {
11
+ const [key, value] = param.split("=").map((v) => v.trim());
12
+ if (key === "q") {
13
+ quality = Number(value);
14
+ } else {
15
+ parameterCount++;
16
+ }
17
+ }
18
+ if (quality === 0) {
19
+ continue;
20
+ }
21
+ const [mediaType, mediaSubtype] = type.split("/");
22
+ const specificity = mediaType === "*" ? 0 : mediaSubtype === "*" ? 1 : 2;
23
+ accepted.push({ type, quality, specificity, parameterCount });
24
+ }
25
+ if (!accepted.length) {
26
+ return [];
27
+ }
28
+ return accepted.sort((left, right) => {
29
+ if (right.quality !== left.quality) {
30
+ return right.quality - left.quality;
31
+ }
32
+ if (right.specificity !== left.specificity) {
33
+ return right.specificity - left.specificity;
34
+ }
35
+ return right.parameterCount - left.parameterCount;
36
+ }).map((entry) => entry.type);
37
+ }
38
+ export {
39
+ getAllAcceptedMimeTypes
40
+ };
41
+ //# sourceMappingURL=getAllAcceptedMimeTypes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/core/utils/request/getAllAcceptedMimeTypes.ts"],"sourcesContent":["/**\n * Returns all accepted mime types, ordered by precedence as defined\n * in [RFC 7231 Section 5.3.2](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2).\n *\n * Precedence rules (highest to lowest):\n * 1. Quality value (`q` parameter, default 1).\n * 2. Specificity: `type/subtype` > `type/*` > `*\\/*`.\n * 3. Number of media type parameters (more = more specific).\n *\n * Types with `q=0` are excluded (explicitly not acceptable).\n */\nexport function getAllAcceptedMimeTypes(\n acceptHeader: string | null,\n): Array<string> {\n if (acceptHeader == null) {\n return []\n }\n\n const accepted: Array<{\n type: string\n quality: number\n specificity: number\n parameterCount: number\n }> = []\n\n for (const part of acceptHeader.split(',')) {\n const [type, ...params] = part.split(';').map((v) => v.trim())\n\n let quality = 1\n let parameterCount = 0\n\n for (const param of params) {\n const [key, value] = param.split('=').map((v) => v.trim())\n\n if (key === 'q') {\n quality = Number(value)\n } else {\n parameterCount++\n }\n }\n\n // RFC 7231: a quality value of 0 indicates \"not acceptable\".\n if (quality === 0) {\n continue\n }\n\n const [mediaType, mediaSubtype] = type.split('/')\n const specificity = mediaType === '*' ? 0 : mediaSubtype === '*' ? 1 : 2\n\n accepted.push({ type, quality, specificity, parameterCount })\n }\n\n if (!accepted.length) {\n return []\n }\n\n return accepted\n .sort((left, right) => {\n if (right.quality !== left.quality) {\n return right.quality - left.quality\n }\n\n if (right.specificity !== left.specificity) {\n return right.specificity - left.specificity\n }\n\n return right.parameterCount - left.parameterCount\n })\n .map((entry) => entry.type)\n}\n"],"mappings":"AAWO,SAAS,wBACd,cACe;AACf,MAAI,gBAAgB,MAAM;AACxB,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,WAKD,CAAC;AAEN,aAAW,QAAQ,aAAa,MAAM,GAAG,GAAG;AAC1C,UAAM,CAAC,MAAM,GAAG,MAAM,IAAI,KAAK,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAE7D,QAAI,UAAU;AACd,QAAI,iBAAiB;AAErB,eAAW,SAAS,QAAQ;AAC1B,YAAM,CAAC,KAAK,KAAK,IAAI,MAAM,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC;AAEzD,UAAI,QAAQ,KAAK;AACf,kBAAU,OAAO,KAAK;AAAA,MACxB,OAAO;AACL;AAAA,MACF;AAAA,IACF;AAGA,QAAI,YAAY,GAAG;AACjB;AAAA,IACF;AAEA,UAAM,CAAC,WAAW,YAAY,IAAI,KAAK,MAAM,GAAG;AAChD,UAAM,cAAc,cAAc,MAAM,IAAI,iBAAiB,MAAM,IAAI;AAEvE,aAAS,KAAK,EAAE,MAAM,SAAS,aAAa,eAAe,CAAC;AAAA,EAC9D;AAEA,MAAI,CAAC,SAAS,QAAQ;AACpB,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,SACJ,KAAK,CAAC,MAAM,UAAU;AACrB,QAAI,MAAM,YAAY,KAAK,SAAS;AAClC,aAAO,MAAM,UAAU,KAAK;AAAA,IAC9B;AAEA,QAAI,MAAM,gBAAgB,KAAK,aAAa;AAC1C,aAAO,MAAM,cAAc,KAAK;AAAA,IAClC;AAEA,WAAO,MAAM,iBAAiB,KAAK;AAAA,EACrC,CAAC,EACA,IAAI,CAAC,UAAU,MAAM,IAAI;AAC9B;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
2
- import { R as RequestHandler } from '../HttpResponse-B9rGc56D.mjs';
2
+ import { R as RequestHandler } from '../HttpResponse-Be4eT3x6.mjs';
3
3
  import { WebSocketHandler } from '../handlers/WebSocketHandler.mjs';
4
4
  import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.mjs';
5
5
  import '@mswjs/interceptors';
@@ -1,5 +1,5 @@
1
1
  import { WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
2
- import { R as RequestHandler } from '../HttpResponse-Dz84tqeA.js';
2
+ import { R as RequestHandler } from '../HttpResponse-Dj6ibgFJ.js';
3
3
  import { WebSocketHandler } from '../handlers/WebSocketHandler.js';
4
4
  import { UnhandledRequestStrategy } from '../utils/request/onUnhandledRequest.js';
5
5
  import '@mswjs/interceptors';
package/lib/iife/index.js CHANGED
@@ -19281,6 +19281,236 @@ ${operationTypes.join("\n")}
19281
19281
  };
19282
19282
  }
19283
19283
 
19284
+ // src/core/utils/HttpResponse/decorators.ts
19285
+ var { message: message3 } = statuses_default;
19286
+ var kSetCookie = Symbol("kSetCookie");
19287
+ function normalizeResponseInit(init = {}) {
19288
+ const status = init?.status || 200;
19289
+ const statusText = init?.statusText || message3[status] || "";
19290
+ const headers = new Headers(init?.headers);
19291
+ return {
19292
+ ...init,
19293
+ headers,
19294
+ status,
19295
+ statusText
19296
+ };
19297
+ }
19298
+ function decorateResponse(response, init) {
19299
+ if (init.type) {
19300
+ Object.defineProperty(response, "type", {
19301
+ value: init.type,
19302
+ enumerable: true,
19303
+ writable: false
19304
+ });
19305
+ }
19306
+ const responseCookies = init.headers.get("set-cookie");
19307
+ if (responseCookies) {
19308
+ Object.defineProperty(response, kSetCookie, {
19309
+ value: responseCookies,
19310
+ enumerable: false,
19311
+ writable: false
19312
+ });
19313
+ if (typeof document !== "undefined") {
19314
+ const responseCookiePairs = Headers2.prototype.getSetCookie.call(
19315
+ init.headers
19316
+ );
19317
+ for (const cookieString of responseCookiePairs) {
19318
+ document.cookie = cookieString;
19319
+ }
19320
+ }
19321
+ }
19322
+ return response;
19323
+ }
19324
+
19325
+ // src/core/HttpResponse.ts
19326
+ var bodyType = Symbol("bodyType");
19327
+ var kDefaultContentType = Symbol.for("kDefaultContentType");
19328
+ var HttpResponse = class _HttpResponse extends FetchResponse {
19329
+ [bodyType] = null;
19330
+ constructor(body, init) {
19331
+ const responseInit = normalizeResponseInit(init);
19332
+ super(body, responseInit);
19333
+ decorateResponse(this, responseInit);
19334
+ }
19335
+ static error() {
19336
+ return super.error();
19337
+ }
19338
+ /**
19339
+ * Create a `Response` with a `Content-Type: "text/plain"` body.
19340
+ * @example
19341
+ * HttpResponse.text('hello world')
19342
+ * HttpResponse.text('Error', { status: 500 })
19343
+ */
19344
+ static text(body, init) {
19345
+ const responseInit = normalizeResponseInit(init);
19346
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19347
+ if (!hasExplicitContentType) {
19348
+ responseInit.headers.set("Content-Type", "text/plain");
19349
+ }
19350
+ if (!responseInit.headers.has("Content-Length")) {
19351
+ responseInit.headers.set(
19352
+ "Content-Length",
19353
+ body ? new Blob([body]).size.toString() : "0"
19354
+ );
19355
+ }
19356
+ const response = new _HttpResponse(body, responseInit);
19357
+ if (!hasExplicitContentType) {
19358
+ Object.defineProperty(response, kDefaultContentType, {
19359
+ value: true,
19360
+ enumerable: false
19361
+ });
19362
+ }
19363
+ return response;
19364
+ }
19365
+ /**
19366
+ * Create a `Response` with a `Content-Type: "application/json"` body.
19367
+ * @example
19368
+ * HttpResponse.json({ firstName: 'John' })
19369
+ * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
19370
+ */
19371
+ static json(body, init) {
19372
+ const responseInit = normalizeResponseInit(init);
19373
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19374
+ if (!hasExplicitContentType) {
19375
+ responseInit.headers.set("Content-Type", "application/json");
19376
+ }
19377
+ const responseText = JSON.stringify(body);
19378
+ if (!responseInit.headers.has("Content-Length")) {
19379
+ responseInit.headers.set(
19380
+ "Content-Length",
19381
+ responseText ? new Blob([responseText]).size.toString() : "0"
19382
+ );
19383
+ }
19384
+ const response = new _HttpResponse(responseText, responseInit);
19385
+ if (!hasExplicitContentType) {
19386
+ Object.defineProperty(response, kDefaultContentType, {
19387
+ value: true,
19388
+ enumerable: false
19389
+ });
19390
+ }
19391
+ return response;
19392
+ }
19393
+ /**
19394
+ * Create a `Response` with a `Content-Type: "application/xml"` body.
19395
+ * @example
19396
+ * HttpResponse.xml(`<user name="John" />`)
19397
+ * HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
19398
+ */
19399
+ static xml(body, init) {
19400
+ const responseInit = normalizeResponseInit(init);
19401
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19402
+ if (!hasExplicitContentType) {
19403
+ responseInit.headers.set("Content-Type", "text/xml");
19404
+ }
19405
+ const response = new _HttpResponse(body, responseInit);
19406
+ if (!hasExplicitContentType) {
19407
+ Object.defineProperty(response, kDefaultContentType, {
19408
+ value: true,
19409
+ enumerable: false
19410
+ });
19411
+ }
19412
+ return response;
19413
+ }
19414
+ /**
19415
+ * Create a `Response` with a `Content-Type: "text/html"` body.
19416
+ * @example
19417
+ * HttpResponse.html(`<p class="author">Jane Doe</p>`)
19418
+ * HttpResponse.html(`<main id="abc-123">Main text</main>`, { status: 201 })
19419
+ */
19420
+ static html(body, init) {
19421
+ const responseInit = normalizeResponseInit(init);
19422
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19423
+ if (!hasExplicitContentType) {
19424
+ responseInit.headers.set("Content-Type", "text/html");
19425
+ }
19426
+ const response = new _HttpResponse(body, responseInit);
19427
+ if (!hasExplicitContentType) {
19428
+ Object.defineProperty(response, kDefaultContentType, {
19429
+ value: true,
19430
+ enumerable: false
19431
+ });
19432
+ }
19433
+ return response;
19434
+ }
19435
+ /**
19436
+ * Create a `Response` with an `ArrayBuffer` body.
19437
+ * @example
19438
+ * const buffer = new ArrayBuffer(3)
19439
+ * const view = new Uint8Array(buffer)
19440
+ * view.set([1, 2, 3])
19441
+ *
19442
+ * HttpResponse.arrayBuffer(buffer)
19443
+ */
19444
+ static arrayBuffer(body, init) {
19445
+ const responseInit = normalizeResponseInit(init);
19446
+ const hasExplicitContentType = responseInit.headers.has("Content-Type");
19447
+ if (!hasExplicitContentType) {
19448
+ responseInit.headers.set("Content-Type", "application/octet-stream");
19449
+ }
19450
+ if (body && !responseInit.headers.has("Content-Length")) {
19451
+ responseInit.headers.set("Content-Length", body.byteLength.toString());
19452
+ }
19453
+ const response = new _HttpResponse(body, responseInit);
19454
+ if (!hasExplicitContentType) {
19455
+ Object.defineProperty(response, kDefaultContentType, {
19456
+ value: true,
19457
+ enumerable: false
19458
+ });
19459
+ }
19460
+ return response;
19461
+ }
19462
+ /**
19463
+ * Create a `Response` with a `FormData` body.
19464
+ * @example
19465
+ * const data = new FormData()
19466
+ * data.set('name', 'Alice')
19467
+ *
19468
+ * HttpResponse.formData(data)
19469
+ */
19470
+ static formData(body, init) {
19471
+ return new _HttpResponse(body, normalizeResponseInit(init));
19472
+ }
19473
+ };
19474
+
19475
+ // src/core/utils/request/getAllAcceptedMimeTypes.ts
19476
+ function getAllAcceptedMimeTypes(acceptHeader) {
19477
+ if (acceptHeader == null) {
19478
+ return [];
19479
+ }
19480
+ const accepted = [];
19481
+ for (const part of acceptHeader.split(",")) {
19482
+ const [type, ...params] = part.split(";").map((v) => v.trim());
19483
+ let quality = 1;
19484
+ let parameterCount = 0;
19485
+ for (const param of params) {
19486
+ const [key, value] = param.split("=").map((v) => v.trim());
19487
+ if (key === "q") {
19488
+ quality = Number(value);
19489
+ } else {
19490
+ parameterCount++;
19491
+ }
19492
+ }
19493
+ if (quality === 0) {
19494
+ continue;
19495
+ }
19496
+ const [mediaType, mediaSubtype] = type.split("/");
19497
+ const specificity = mediaType === "*" ? 0 : mediaSubtype === "*" ? 1 : 2;
19498
+ accepted.push({ type, quality, specificity, parameterCount });
19499
+ }
19500
+ if (!accepted.length) {
19501
+ return [];
19502
+ }
19503
+ return accepted.sort((left, right) => {
19504
+ if (right.quality !== left.quality) {
19505
+ return right.quality - left.quality;
19506
+ }
19507
+ if (right.specificity !== left.specificity) {
19508
+ return right.specificity - left.specificity;
19509
+ }
19510
+ return right.parameterCount - left.parameterCount;
19511
+ }).map((entry) => entry.type);
19512
+ }
19513
+
19284
19514
  // src/core/handlers/GraphQLHandler.ts
19285
19515
  function isDocumentNode(value) {
19286
19516
  if (value == null) {
@@ -19405,6 +19635,32 @@ Consider naming this operation or using "graphql.operation()" request handler to
19405
19635
  });
19406
19636
  return args.parsedResult.match.matches && hasMatchingOperationType && hasMatchingOperationName;
19407
19637
  }
19638
+ async run(args) {
19639
+ const result = await super.run(args);
19640
+ if (result?.response == null) {
19641
+ return result;
19642
+ }
19643
+ if (!(kDefaultContentType in result.response)) {
19644
+ return result;
19645
+ }
19646
+ const acceptedMimeTypes = getAllAcceptedMimeTypes(
19647
+ args.request.headers.get("accept")
19648
+ );
19649
+ if (acceptedMimeTypes.length === 0) {
19650
+ return result;
19651
+ }
19652
+ const graphqlResponseIndex = acceptedMimeTypes.indexOf(
19653
+ "application/graphql-response+json"
19654
+ );
19655
+ const jsonIndex = acceptedMimeTypes.indexOf("application/json");
19656
+ if (graphqlResponseIndex !== -1 && (jsonIndex === -1 || graphqlResponseIndex <= jsonIndex)) {
19657
+ result.response.headers.set(
19658
+ "content-type",
19659
+ "application/graphql-response+json"
19660
+ );
19661
+ }
19662
+ return result;
19663
+ }
19408
19664
  async matchOperationName(args) {
19409
19665
  if (typeof this.info.operationName === "function") {
19410
19666
  const customPredicateResult = await this.info.operationName({
@@ -20879,47 +21135,6 @@ Read more: https://mswjs.io/docs/http/intercepting-requests`;
20879
21135
  }
20880
21136
  }
20881
21137
 
20882
- // src/core/utils/HttpResponse/decorators.ts
20883
- var { message: message3 } = statuses_default;
20884
- var kSetCookie = Symbol("kSetCookie");
20885
- function normalizeResponseInit(init = {}) {
20886
- const status = init?.status || 200;
20887
- const statusText = init?.statusText || message3[status] || "";
20888
- const headers = new Headers(init?.headers);
20889
- return {
20890
- ...init,
20891
- headers,
20892
- status,
20893
- statusText
20894
- };
20895
- }
20896
- function decorateResponse(response, init) {
20897
- if (init.type) {
20898
- Object.defineProperty(response, "type", {
20899
- value: init.type,
20900
- enumerable: true,
20901
- writable: false
20902
- });
20903
- }
20904
- const responseCookies = init.headers.get("set-cookie");
20905
- if (responseCookies) {
20906
- Object.defineProperty(response, kSetCookie, {
20907
- value: responseCookies,
20908
- enumerable: false,
20909
- writable: false
20910
- });
20911
- if (typeof document !== "undefined") {
20912
- const responseCookiePairs = Headers2.prototype.getSetCookie.call(
20913
- init.headers
20914
- );
20915
- for (const cookieString of responseCookiePairs) {
20916
- document.cookie = cookieString;
20917
- }
20918
- }
20919
- }
20920
- return response;
20921
- }
20922
-
20923
21138
  // src/core/utils/request/storeResponseCookies.ts
20924
21139
  async function storeResponseCookies(request, response) {
20925
21140
  const responseCookies = Reflect.get(response, kSetCookie);
@@ -20989,115 +21204,6 @@ Read more: https://mswjs.io/docs/http/intercepting-requests`;
20989
21204
  return result?.response;
20990
21205
  };
20991
21206
 
20992
- // src/core/HttpResponse.ts
20993
- var bodyType = Symbol("bodyType");
20994
- var HttpResponse = class _HttpResponse extends FetchResponse {
20995
- [bodyType] = null;
20996
- constructor(body, init) {
20997
- const responseInit = normalizeResponseInit(init);
20998
- super(body, responseInit);
20999
- decorateResponse(this, responseInit);
21000
- }
21001
- static error() {
21002
- return super.error();
21003
- }
21004
- /**
21005
- * Create a `Response` with a `Content-Type: "text/plain"` body.
21006
- * @example
21007
- * HttpResponse.text('hello world')
21008
- * HttpResponse.text('Error', { status: 500 })
21009
- */
21010
- static text(body, init) {
21011
- const responseInit = normalizeResponseInit(init);
21012
- if (!responseInit.headers.has("Content-Type")) {
21013
- responseInit.headers.set("Content-Type", "text/plain");
21014
- }
21015
- if (!responseInit.headers.has("Content-Length")) {
21016
- responseInit.headers.set(
21017
- "Content-Length",
21018
- body ? new Blob([body]).size.toString() : "0"
21019
- );
21020
- }
21021
- return new _HttpResponse(body, responseInit);
21022
- }
21023
- /**
21024
- * Create a `Response` with a `Content-Type: "application/json"` body.
21025
- * @example
21026
- * HttpResponse.json({ firstName: 'John' })
21027
- * HttpResponse.json({ error: 'Not Authorized' }, { status: 401 })
21028
- */
21029
- static json(body, init) {
21030
- const responseInit = normalizeResponseInit(init);
21031
- if (!responseInit.headers.has("Content-Type")) {
21032
- responseInit.headers.set("Content-Type", "application/json");
21033
- }
21034
- const responseText = JSON.stringify(body);
21035
- if (!responseInit.headers.has("Content-Length")) {
21036
- responseInit.headers.set(
21037
- "Content-Length",
21038
- responseText ? new Blob([responseText]).size.toString() : "0"
21039
- );
21040
- }
21041
- return new _HttpResponse(responseText, responseInit);
21042
- }
21043
- /**
21044
- * Create a `Response` with a `Content-Type: "application/xml"` body.
21045
- * @example
21046
- * HttpResponse.xml(`<user name="John" />`)
21047
- * HttpResponse.xml(`<article id="abc-123" />`, { status: 201 })
21048
- */
21049
- static xml(body, init) {
21050
- const responseInit = normalizeResponseInit(init);
21051
- if (!responseInit.headers.has("Content-Type")) {
21052
- responseInit.headers.set("Content-Type", "text/xml");
21053
- }
21054
- return new _HttpResponse(body, responseInit);
21055
- }
21056
- /**
21057
- * Create a `Response` with a `Content-Type: "text/html"` body.
21058
- * @example
21059
- * HttpResponse.html(`<p class="author">Jane Doe</p>`)
21060
- * HttpResponse.html(`<main id="abc-123">Main text</main>`, { status: 201 })
21061
- */
21062
- static html(body, init) {
21063
- const responseInit = normalizeResponseInit(init);
21064
- if (!responseInit.headers.has("Content-Type")) {
21065
- responseInit.headers.set("Content-Type", "text/html");
21066
- }
21067
- return new _HttpResponse(body, responseInit);
21068
- }
21069
- /**
21070
- * Create a `Response` with an `ArrayBuffer` body.
21071
- * @example
21072
- * const buffer = new ArrayBuffer(3)
21073
- * const view = new Uint8Array(buffer)
21074
- * view.set([1, 2, 3])
21075
- *
21076
- * HttpResponse.arrayBuffer(buffer)
21077
- */
21078
- static arrayBuffer(body, init) {
21079
- const responseInit = normalizeResponseInit(init);
21080
- if (!responseInit.headers.has("Content-Type")) {
21081
- responseInit.headers.set("Content-Type", "application/octet-stream");
21082
- }
21083
- if (body && !responseInit.headers.has("Content-Length")) {
21084
- responseInit.headers.set("Content-Length", body.byteLength.toString());
21085
- }
21086
- return new _HttpResponse(body, responseInit);
21087
- }
21088
- /**
21089
- * Create a `Response` with a `FormData` body.
21090
- * @example
21091
- * const data = new FormData()
21092
- * data.set('name', 'Alice')
21093
- *
21094
- * HttpResponse.formData(data)
21095
- */
21096
- static formData(body, init) {
21097
- return new _HttpResponse(body, normalizeResponseInit(init));
21098
- }
21099
- };
21100
-
21101
21207
  // src/core/bypass.ts
21102
21208
  function bypass(input, init) {
21103
21209
  const request = new Request(