msw 2.6.4 → 2.6.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.
@@ -403,7 +403,7 @@ You can also automate this process and make the worker script update automatical
403
403
  }
404
404
  }
405
405
 
406
- // node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
406
+ // node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
407
407
  var encoder = new TextEncoder();
408
408
  function encodeBuffer(text) {
409
409
  return encoder.encode(text);
@@ -419,54 +419,67 @@ function toArrayBuffer(array) {
419
419
  );
420
420
  }
421
421
 
422
- // node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-6MOMO77R.mjs
422
+ // node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-F4BN745U.mjs
423
423
  var IS_PATCHED_MODULE = Symbol("isPatchedModule");
424
- function isPropertyAccessible(obj, key) {
425
- try {
426
- obj[key];
427
- return true;
428
- } catch (e) {
429
- return false;
424
+ var _FetchResponse = class extends Response {
425
+ static isConfigurableStatusCode(status) {
426
+ return status >= 200 && status <= 599;
430
427
  }
431
- }
432
- var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
433
- 101,
434
- 103,
435
- 204,
436
- 205,
437
- 304
438
- ]);
439
- var RESPONSE_STATUS_CODES_WITH_REDIRECT = /* @__PURE__ */ new Set([
440
- 301,
441
- 302,
442
- 303,
443
- 307,
444
- 308
445
- ]);
446
- function isResponseWithoutBody(status) {
447
- return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
448
- }
449
- function createServerErrorResponse(body) {
450
- return new Response(
451
- JSON.stringify(
452
- body instanceof Error ? {
453
- name: body.name,
454
- message: body.message,
455
- stack: body.stack
456
- } : body
457
- ),
458
- {
459
- status: 500,
460
- statusText: "Unhandled Exception",
461
- headers: {
462
- "Content-Type": "application/json"
428
+ static isRedirectResponse(status) {
429
+ return _FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
430
+ }
431
+ /**
432
+ * Returns a boolean indicating whether the given response status
433
+ * code represents a response that can have a body.
434
+ */
435
+ static isResponseWithBody(status) {
436
+ return !_FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
437
+ }
438
+ static setUrl(url, response) {
439
+ if (!url) {
440
+ return;
441
+ }
442
+ if (response.url != "") {
443
+ return;
444
+ }
445
+ Object.defineProperty(response, "url", {
446
+ value: url,
447
+ enumerable: true,
448
+ configurable: true,
449
+ writable: false
450
+ });
451
+ }
452
+ constructor(body, init = {}) {
453
+ var _a;
454
+ const status = (_a = init.status) != null ? _a : 200;
455
+ const safeStatus = _FetchResponse.isConfigurableStatusCode(status) ? status : 200;
456
+ const finalBody = _FetchResponse.isResponseWithBody(status) ? body : null;
457
+ super(finalBody, {
458
+ ...init,
459
+ status: safeStatus
460
+ });
461
+ if (status !== safeStatus) {
462
+ const stateSymbol = Object.getOwnPropertySymbols(this).find(
463
+ (symbol) => symbol.description === "state"
464
+ );
465
+ if (stateSymbol) {
466
+ const state = Reflect.get(this, stateSymbol);
467
+ Reflect.set(state, "status", status);
468
+ } else {
469
+ Object.defineProperty(this, "status", {
470
+ value: status,
471
+ enumerable: true,
472
+ configurable: true,
473
+ writable: false
474
+ });
463
475
  }
464
476
  }
465
- );
466
- }
467
- function isResponseError(response) {
468
- return isPropertyAccessible(response, "type") && response.type === "error";
469
- }
477
+ _FetchResponse.setUrl(init.url, this);
478
+ }
479
+ };
480
+ var FetchResponse = _FetchResponse;
481
+ FetchResponse.STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304];
482
+ FetchResponse.STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308];
470
483
 
471
484
  // node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
472
485
  var __defProp2 = Object.defineProperty;
@@ -905,7 +918,7 @@ var _Emitter = class {
905
918
  var Emitter = _Emitter;
906
919
  Emitter.defaultMaxListeners = 10;
907
920
 
908
- // node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
921
+ // node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
909
922
  var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
910
923
  function getGlobalSymbol(symbol) {
911
924
  return (
@@ -1053,7 +1066,7 @@ function createRequestId() {
1053
1066
  return Math.random().toString(16).slice(2);
1054
1067
  }
1055
1068
 
1056
- // node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/index.mjs
1069
+ // node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
1057
1070
  var BatchInterceptor = class extends Interceptor {
1058
1071
  constructor(options) {
1059
1072
  BatchInterceptor.symbol = Symbol(options.name);
@@ -1106,23 +1119,24 @@ function createResponseListener(context) {
1106
1119
  if (responseJson.type?.includes("opaque")) {
1107
1120
  return;
1108
1121
  }
1109
- const response = responseJson.status === 0 ? Response.error() : new Response(
1122
+ const response = responseJson.status === 0 ? Response.error() : new FetchResponse(
1110
1123
  /**
1111
1124
  * Responses may be streams here, but when we create a response object
1112
1125
  * with null-body status codes, like 204, 205, 304 Response will
1113
1126
  * throw when passed a non-null body, so ensure it's null here
1114
1127
  * for those codes
1115
1128
  */
1116
- isResponseWithoutBody(responseJson.status) ? null : responseJson.body,
1117
- responseJson
1129
+ FetchResponse.isResponseWithBody(responseJson.status) ? responseJson.body : null,
1130
+ {
1131
+ ...responseJson,
1132
+ /**
1133
+ * Set response URL if it's not set already.
1134
+ * @see https://github.com/mswjs/msw/issues/2030
1135
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
1136
+ */
1137
+ url: request.url
1138
+ }
1118
1139
  );
1119
- if (!response.url) {
1120
- Object.defineProperty(response, "url", {
1121
- value: request.url,
1122
- enumerable: true,
1123
- writable: false
1124
- });
1125
- }
1126
1140
  context.emitter.emit(
1127
1141
  responseJson.isMockedResponse ? "response:mocked" : "response:bypass",
1128
1142
  {
@@ -1339,7 +1353,7 @@ var DeferredPromise = class extends Promise {
1339
1353
  }
1340
1354
  };
1341
1355
 
1342
- // node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-4RQHC4IY.mjs
1356
+ // node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-H5O73WD2.mjs
1343
1357
  var InterceptorError = class extends Error {
1344
1358
  constructor(message) {
1345
1359
  super(message);
@@ -1400,6 +1414,35 @@ async function emitAsync(emitter, eventName, ...data) {
1400
1414
  await listener.apply(emitter, data);
1401
1415
  }
1402
1416
  }
1417
+ function isPropertyAccessible(obj, key) {
1418
+ try {
1419
+ obj[key];
1420
+ return true;
1421
+ } catch (e) {
1422
+ return false;
1423
+ }
1424
+ }
1425
+ function createServerErrorResponse(body) {
1426
+ return new Response(
1427
+ JSON.stringify(
1428
+ body instanceof Error ? {
1429
+ name: body.name,
1430
+ message: body.message,
1431
+ stack: body.stack
1432
+ } : body
1433
+ ),
1434
+ {
1435
+ status: 500,
1436
+ statusText: "Unhandled Exception",
1437
+ headers: {
1438
+ "Content-Type": "application/json"
1439
+ }
1440
+ }
1441
+ );
1442
+ }
1443
+ function isResponseError(response) {
1444
+ return isPropertyAccessible(response, "type") && response.type === "error";
1445
+ }
1403
1446
  function isNodeLikeError(error2) {
1404
1447
  if (error2 == null) {
1405
1448
  return false;
@@ -1511,7 +1554,7 @@ async function handleRequest2(options) {
1511
1554
  return false;
1512
1555
  }
1513
1556
 
1514
- // node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-TX5GBTFY.mjs
1557
+ // node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-TX5GBTFY.mjs
1515
1558
  function hasConfigurableGlobal(propertyName) {
1516
1559
  const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
1517
1560
  if (typeof descriptor === "undefined") {
@@ -1532,7 +1575,7 @@ function hasConfigurableGlobal(propertyName) {
1532
1575
  return true;
1533
1576
  }
1534
1577
 
1535
- // node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-VXLPKFY4.mjs
1578
+ // node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-HER3NHBG.mjs
1536
1579
  function canParseUrl(url) {
1537
1580
  try {
1538
1581
  new URL(url);
@@ -1708,8 +1751,9 @@ var _FetchInterceptor = class extends Interceptor {
1708
1751
  rawResponse
1709
1752
  });
1710
1753
  const decompressedStream = decompressResponse(rawResponse);
1711
- const response = decompressedStream === null ? rawResponse : new Response(decompressedStream, rawResponse);
1712
- if (RESPONSE_STATUS_CODES_WITH_REDIRECT.has(response.status)) {
1754
+ const response = decompressedStream === null ? rawResponse : new FetchResponse(decompressedStream, rawResponse);
1755
+ FetchResponse.setUrl(request.url, response);
1756
+ if (FetchResponse.isRedirectResponse(response.status)) {
1713
1757
  if (request.redirect === "error") {
1714
1758
  responsePromise.reject(createNetworkError("unexpected redirect"));
1715
1759
  return;
@@ -1726,12 +1770,6 @@ var _FetchInterceptor = class extends Interceptor {
1726
1770
  return;
1727
1771
  }
1728
1772
  }
1729
- Object.defineProperty(response, "url", {
1730
- writable: false,
1731
- enumerable: true,
1732
- configurable: false,
1733
- value: request.url
1734
- });
1735
1773
  if (this.emitter.listenerCount("response") > 0) {
1736
1774
  this.logger.info('emitting the "response" event...');
1737
1775
  await emitAsync(this.emitter, "response", {
@@ -1797,7 +1835,7 @@ var _FetchInterceptor = class extends Interceptor {
1797
1835
  var FetchInterceptor = _FetchInterceptor;
1798
1836
  FetchInterceptor.symbol = Symbol("fetch");
1799
1837
 
1800
- // node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-MMAVIMED.mjs
1838
+ // node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-4SRQFK76.mjs
1801
1839
  function concatArrayBuffer(left, right) {
1802
1840
  const result = new Uint8Array(left.byteLength + right.byteLength);
1803
1841
  result.set(left, 0);
@@ -1960,8 +1998,9 @@ function parseJson(data) {
1960
1998
  }
1961
1999
  }
1962
2000
  function createResponse(request, body) {
1963
- const responseBodyOrNull = isResponseWithoutBody(request.status) ? null : body;
1964
- return new Response(responseBodyOrNull, {
2001
+ const responseBodyOrNull = FetchResponse.isResponseWithBody(request.status) ? body : null;
2002
+ return new FetchResponse(responseBodyOrNull, {
2003
+ url: request.responseURL,
1965
2004
  status: request.status,
1966
2005
  statusText: request.statusText,
1967
2006
  headers: createHeadersFromXMLHttpReqestHeaders(