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.
- package/lib/browser/index.js +110 -71
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +110 -71
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +1 -1
- package/lib/core/utils/matching/matchRequestUrl.d.ts +1 -1
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/iife/index.js +111 -72
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/browser/setupWorker/start/createResponseListener.ts +14 -19
- package/src/core/utils/matching/matchRequestUrl.ts +1 -1
package/lib/browser/index.mjs
CHANGED
|
@@ -376,7 +376,7 @@ You can also automate this process and make the worker script update automatical
|
|
|
376
376
|
}
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
379
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
|
|
380
380
|
var encoder = new TextEncoder();
|
|
381
381
|
function encodeBuffer(text) {
|
|
382
382
|
return encoder.encode(text);
|
|
@@ -392,54 +392,67 @@ function toArrayBuffer(array) {
|
|
|
392
392
|
);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
395
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-F4BN745U.mjs
|
|
396
396
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return true;
|
|
401
|
-
} catch (e) {
|
|
402
|
-
return false;
|
|
397
|
+
var _FetchResponse = class extends Response {
|
|
398
|
+
static isConfigurableStatusCode(status) {
|
|
399
|
+
return status >= 200 && status <= 599;
|
|
403
400
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
)
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
401
|
+
static isRedirectResponse(status) {
|
|
402
|
+
return _FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Returns a boolean indicating whether the given response status
|
|
406
|
+
* code represents a response that can have a body.
|
|
407
|
+
*/
|
|
408
|
+
static isResponseWithBody(status) {
|
|
409
|
+
return !_FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
|
|
410
|
+
}
|
|
411
|
+
static setUrl(url, response) {
|
|
412
|
+
if (!url) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (response.url != "") {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
Object.defineProperty(response, "url", {
|
|
419
|
+
value: url,
|
|
420
|
+
enumerable: true,
|
|
421
|
+
configurable: true,
|
|
422
|
+
writable: false
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
constructor(body, init = {}) {
|
|
426
|
+
var _a;
|
|
427
|
+
const status = (_a = init.status) != null ? _a : 200;
|
|
428
|
+
const safeStatus = _FetchResponse.isConfigurableStatusCode(status) ? status : 200;
|
|
429
|
+
const finalBody = _FetchResponse.isResponseWithBody(status) ? body : null;
|
|
430
|
+
super(finalBody, {
|
|
431
|
+
...init,
|
|
432
|
+
status: safeStatus
|
|
433
|
+
});
|
|
434
|
+
if (status !== safeStatus) {
|
|
435
|
+
const stateSymbol = Object.getOwnPropertySymbols(this).find(
|
|
436
|
+
(symbol) => symbol.description === "state"
|
|
437
|
+
);
|
|
438
|
+
if (stateSymbol) {
|
|
439
|
+
const state = Reflect.get(this, stateSymbol);
|
|
440
|
+
Reflect.set(state, "status", status);
|
|
441
|
+
} else {
|
|
442
|
+
Object.defineProperty(this, "status", {
|
|
443
|
+
value: status,
|
|
444
|
+
enumerable: true,
|
|
445
|
+
configurable: true,
|
|
446
|
+
writable: false
|
|
447
|
+
});
|
|
436
448
|
}
|
|
437
449
|
}
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
450
|
+
_FetchResponse.setUrl(init.url, this);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
var FetchResponse = _FetchResponse;
|
|
454
|
+
FetchResponse.STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304];
|
|
455
|
+
FetchResponse.STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308];
|
|
443
456
|
|
|
444
457
|
// node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
|
|
445
458
|
var __defProp = Object.defineProperty;
|
|
@@ -878,7 +891,7 @@ var _Emitter = class {
|
|
|
878
891
|
var Emitter = _Emitter;
|
|
879
892
|
Emitter.defaultMaxListeners = 10;
|
|
880
893
|
|
|
881
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
894
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
882
895
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
883
896
|
function getGlobalSymbol(symbol) {
|
|
884
897
|
return (
|
|
@@ -1026,7 +1039,7 @@ function createRequestId() {
|
|
|
1026
1039
|
return Math.random().toString(16).slice(2);
|
|
1027
1040
|
}
|
|
1028
1041
|
|
|
1029
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1042
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1030
1043
|
var BatchInterceptor = class extends Interceptor {
|
|
1031
1044
|
constructor(options) {
|
|
1032
1045
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -1079,23 +1092,24 @@ function createResponseListener(context) {
|
|
|
1079
1092
|
if (responseJson.type?.includes("opaque")) {
|
|
1080
1093
|
return;
|
|
1081
1094
|
}
|
|
1082
|
-
const response = responseJson.status === 0 ? Response.error() : new
|
|
1095
|
+
const response = responseJson.status === 0 ? Response.error() : new FetchResponse(
|
|
1083
1096
|
/**
|
|
1084
1097
|
* Responses may be streams here, but when we create a response object
|
|
1085
1098
|
* with null-body status codes, like 204, 205, 304 Response will
|
|
1086
1099
|
* throw when passed a non-null body, so ensure it's null here
|
|
1087
1100
|
* for those codes
|
|
1088
1101
|
*/
|
|
1089
|
-
|
|
1090
|
-
|
|
1102
|
+
FetchResponse.isResponseWithBody(responseJson.status) ? responseJson.body : null,
|
|
1103
|
+
{
|
|
1104
|
+
...responseJson,
|
|
1105
|
+
/**
|
|
1106
|
+
* Set response URL if it's not set already.
|
|
1107
|
+
* @see https://github.com/mswjs/msw/issues/2030
|
|
1108
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
|
|
1109
|
+
*/
|
|
1110
|
+
url: request.url
|
|
1111
|
+
}
|
|
1091
1112
|
);
|
|
1092
|
-
if (!response.url) {
|
|
1093
|
-
Object.defineProperty(response, "url", {
|
|
1094
|
-
value: request.url,
|
|
1095
|
-
enumerable: true,
|
|
1096
|
-
writable: false
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1099
1113
|
context.emitter.emit(
|
|
1100
1114
|
responseJson.isMockedResponse ? "response:mocked" : "response:bypass",
|
|
1101
1115
|
{
|
|
@@ -1312,7 +1326,7 @@ var DeferredPromise = class extends Promise {
|
|
|
1312
1326
|
}
|
|
1313
1327
|
};
|
|
1314
1328
|
|
|
1315
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1329
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-H5O73WD2.mjs
|
|
1316
1330
|
var InterceptorError = class extends Error {
|
|
1317
1331
|
constructor(message) {
|
|
1318
1332
|
super(message);
|
|
@@ -1373,6 +1387,35 @@ async function emitAsync(emitter, eventName, ...data) {
|
|
|
1373
1387
|
await listener.apply(emitter, data);
|
|
1374
1388
|
}
|
|
1375
1389
|
}
|
|
1390
|
+
function isPropertyAccessible(obj, key) {
|
|
1391
|
+
try {
|
|
1392
|
+
obj[key];
|
|
1393
|
+
return true;
|
|
1394
|
+
} catch (e) {
|
|
1395
|
+
return false;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
function createServerErrorResponse(body) {
|
|
1399
|
+
return new Response(
|
|
1400
|
+
JSON.stringify(
|
|
1401
|
+
body instanceof Error ? {
|
|
1402
|
+
name: body.name,
|
|
1403
|
+
message: body.message,
|
|
1404
|
+
stack: body.stack
|
|
1405
|
+
} : body
|
|
1406
|
+
),
|
|
1407
|
+
{
|
|
1408
|
+
status: 500,
|
|
1409
|
+
statusText: "Unhandled Exception",
|
|
1410
|
+
headers: {
|
|
1411
|
+
"Content-Type": "application/json"
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
);
|
|
1415
|
+
}
|
|
1416
|
+
function isResponseError(response) {
|
|
1417
|
+
return isPropertyAccessible(response, "type") && response.type === "error";
|
|
1418
|
+
}
|
|
1376
1419
|
function isNodeLikeError(error2) {
|
|
1377
1420
|
if (error2 == null) {
|
|
1378
1421
|
return false;
|
|
@@ -1484,7 +1527,7 @@ async function handleRequest2(options) {
|
|
|
1484
1527
|
return false;
|
|
1485
1528
|
}
|
|
1486
1529
|
|
|
1487
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1530
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-TX5GBTFY.mjs
|
|
1488
1531
|
function hasConfigurableGlobal(propertyName) {
|
|
1489
1532
|
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
1490
1533
|
if (typeof descriptor === "undefined") {
|
|
@@ -1505,7 +1548,7 @@ function hasConfigurableGlobal(propertyName) {
|
|
|
1505
1548
|
return true;
|
|
1506
1549
|
}
|
|
1507
1550
|
|
|
1508
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1551
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-HER3NHBG.mjs
|
|
1509
1552
|
function canParseUrl(url) {
|
|
1510
1553
|
try {
|
|
1511
1554
|
new URL(url);
|
|
@@ -1681,8 +1724,9 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1681
1724
|
rawResponse
|
|
1682
1725
|
});
|
|
1683
1726
|
const decompressedStream = decompressResponse(rawResponse);
|
|
1684
|
-
const response = decompressedStream === null ? rawResponse : new
|
|
1685
|
-
|
|
1727
|
+
const response = decompressedStream === null ? rawResponse : new FetchResponse(decompressedStream, rawResponse);
|
|
1728
|
+
FetchResponse.setUrl(request.url, response);
|
|
1729
|
+
if (FetchResponse.isRedirectResponse(response.status)) {
|
|
1686
1730
|
if (request.redirect === "error") {
|
|
1687
1731
|
responsePromise.reject(createNetworkError("unexpected redirect"));
|
|
1688
1732
|
return;
|
|
@@ -1699,12 +1743,6 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1699
1743
|
return;
|
|
1700
1744
|
}
|
|
1701
1745
|
}
|
|
1702
|
-
Object.defineProperty(response, "url", {
|
|
1703
|
-
writable: false,
|
|
1704
|
-
enumerable: true,
|
|
1705
|
-
configurable: false,
|
|
1706
|
-
value: request.url
|
|
1707
|
-
});
|
|
1708
1746
|
if (this.emitter.listenerCount("response") > 0) {
|
|
1709
1747
|
this.logger.info('emitting the "response" event...');
|
|
1710
1748
|
await emitAsync(this.emitter, "response", {
|
|
@@ -1770,7 +1808,7 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1770
1808
|
var FetchInterceptor = _FetchInterceptor;
|
|
1771
1809
|
FetchInterceptor.symbol = Symbol("fetch");
|
|
1772
1810
|
|
|
1773
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1811
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.37.0/node_modules/@mswjs/interceptors/lib/browser/chunk-4SRQFK76.mjs
|
|
1774
1812
|
function concatArrayBuffer(left, right) {
|
|
1775
1813
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
1776
1814
|
result.set(left, 0);
|
|
@@ -1933,8 +1971,9 @@ function parseJson(data) {
|
|
|
1933
1971
|
}
|
|
1934
1972
|
}
|
|
1935
1973
|
function createResponse(request, body) {
|
|
1936
|
-
const responseBodyOrNull =
|
|
1937
|
-
return new
|
|
1974
|
+
const responseBodyOrNull = FetchResponse.isResponseWithBody(request.status) ? body : null;
|
|
1975
|
+
return new FetchResponse(responseBodyOrNull, {
|
|
1976
|
+
url: request.responseURL,
|
|
1938
1977
|
status: request.status,
|
|
1939
1978
|
statusText: request.statusText,
|
|
1940
1979
|
headers: createHeadersFromXMLHttpReqestHeaders(
|