msw 2.6.1 → 2.6.2
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 +117 -24
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +117 -24
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/utils/request/getRequestCookies.js +12 -2
- package/lib/core/utils/request/getRequestCookies.js.map +1 -1
- package/lib/core/utils/request/getRequestCookies.mjs +12 -2
- package/lib/core/utils/request/getRequestCookies.mjs.map +1 -1
- package/lib/iife/index.js +202 -65
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/utils/request/getRequestCookies.ts +15 -2
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.36.
|
|
379
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/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,7 +392,7 @@ function toArrayBuffer(array) {
|
|
|
392
392
|
);
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
395
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-6MOMO77R.mjs
|
|
396
396
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
397
397
|
function isPropertyAccessible(obj, key) {
|
|
398
398
|
try {
|
|
@@ -878,7 +878,7 @@ var _Emitter = class {
|
|
|
878
878
|
var Emitter = _Emitter;
|
|
879
879
|
Emitter.defaultMaxListeners = 10;
|
|
880
880
|
|
|
881
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
881
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
882
882
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
883
883
|
function getGlobalSymbol(symbol) {
|
|
884
884
|
return (
|
|
@@ -1026,7 +1026,7 @@ function createRequestId() {
|
|
|
1026
1026
|
return Math.random().toString(16).slice(2);
|
|
1027
1027
|
}
|
|
1028
1028
|
|
|
1029
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
1029
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1030
1030
|
var BatchInterceptor = class extends Interceptor {
|
|
1031
1031
|
constructor(options) {
|
|
1032
1032
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -1312,7 +1312,7 @@ var DeferredPromise = class extends Promise {
|
|
|
1312
1312
|
}
|
|
1313
1313
|
};
|
|
1314
1314
|
|
|
1315
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
1315
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-4RQHC4IY.mjs
|
|
1316
1316
|
var InterceptorError = class extends Error {
|
|
1317
1317
|
constructor(message) {
|
|
1318
1318
|
super(message);
|
|
@@ -1416,13 +1416,17 @@ async function handleRequest2(options) {
|
|
|
1416
1416
|
});
|
|
1417
1417
|
const requestAbortPromise = new DeferredPromise();
|
|
1418
1418
|
if (options.request.signal) {
|
|
1419
|
-
options.request.signal.
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1419
|
+
if (options.request.signal.aborted) {
|
|
1420
|
+
requestAbortPromise.reject(options.request.signal.reason);
|
|
1421
|
+
} else {
|
|
1422
|
+
options.request.signal.addEventListener(
|
|
1423
|
+
"abort",
|
|
1424
|
+
() => {
|
|
1425
|
+
requestAbortPromise.reject(options.request.signal.reason);
|
|
1426
|
+
},
|
|
1427
|
+
{ once: true }
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1426
1430
|
}
|
|
1427
1431
|
const result = await until(async () => {
|
|
1428
1432
|
const requestListtenersPromise = emitAsync(options.emitter, "request", {
|
|
@@ -1480,7 +1484,28 @@ async function handleRequest2(options) {
|
|
|
1480
1484
|
return false;
|
|
1481
1485
|
}
|
|
1482
1486
|
|
|
1483
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
1487
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-TX5GBTFY.mjs
|
|
1488
|
+
function hasConfigurableGlobal(propertyName) {
|
|
1489
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
1490
|
+
if (typeof descriptor === "undefined") {
|
|
1491
|
+
return false;
|
|
1492
|
+
}
|
|
1493
|
+
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") {
|
|
1494
|
+
return false;
|
|
1495
|
+
}
|
|
1496
|
+
if (typeof descriptor.get === "undefined" && descriptor.value == null) {
|
|
1497
|
+
return false;
|
|
1498
|
+
}
|
|
1499
|
+
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
1500
|
+
console.error(
|
|
1501
|
+
`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`
|
|
1502
|
+
);
|
|
1503
|
+
return false;
|
|
1504
|
+
}
|
|
1505
|
+
return true;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-VXLPKFY4.mjs
|
|
1484
1509
|
function canParseUrl(url) {
|
|
1485
1510
|
try {
|
|
1486
1511
|
new URL(url);
|
|
@@ -1555,12 +1580,78 @@ function sameOrigin(left, right) {
|
|
|
1555
1580
|
}
|
|
1556
1581
|
return false;
|
|
1557
1582
|
}
|
|
1583
|
+
var BrotliDecompressionStream = class extends TransformStream {
|
|
1584
|
+
constructor() {
|
|
1585
|
+
console.warn(
|
|
1586
|
+
"[Interceptors]: Brotli decompression of response streams is not supported in the browser"
|
|
1587
|
+
);
|
|
1588
|
+
super({
|
|
1589
|
+
transform(chunk, controller) {
|
|
1590
|
+
controller.enqueue(chunk);
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
};
|
|
1595
|
+
var PipelineStream = class extends TransformStream {
|
|
1596
|
+
constructor(transformStreams, ...strategies) {
|
|
1597
|
+
super({}, ...strategies);
|
|
1598
|
+
const readable = [super.readable, ...transformStreams].reduce(
|
|
1599
|
+
(readable2, transform) => readable2.pipeThrough(transform)
|
|
1600
|
+
);
|
|
1601
|
+
Object.defineProperty(this, "readable", {
|
|
1602
|
+
get() {
|
|
1603
|
+
return readable;
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1608
|
+
function parseContentEncoding(contentEncoding) {
|
|
1609
|
+
return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
|
|
1610
|
+
}
|
|
1611
|
+
function createDecompressionStream(contentEncoding) {
|
|
1612
|
+
if (contentEncoding === "") {
|
|
1613
|
+
return null;
|
|
1614
|
+
}
|
|
1615
|
+
const codings = parseContentEncoding(contentEncoding);
|
|
1616
|
+
if (codings.length === 0) {
|
|
1617
|
+
return null;
|
|
1618
|
+
}
|
|
1619
|
+
const transformers = codings.reduceRight(
|
|
1620
|
+
(transformers2, coding) => {
|
|
1621
|
+
if (coding === "gzip" || coding === "x-gzip") {
|
|
1622
|
+
return transformers2.concat(new DecompressionStream("gzip"));
|
|
1623
|
+
} else if (coding === "deflate") {
|
|
1624
|
+
return transformers2.concat(new DecompressionStream("deflate"));
|
|
1625
|
+
} else if (coding === "br") {
|
|
1626
|
+
return transformers2.concat(new BrotliDecompressionStream());
|
|
1627
|
+
} else {
|
|
1628
|
+
transformers2.length = 0;
|
|
1629
|
+
}
|
|
1630
|
+
return transformers2;
|
|
1631
|
+
},
|
|
1632
|
+
[]
|
|
1633
|
+
);
|
|
1634
|
+
return new PipelineStream(transformers);
|
|
1635
|
+
}
|
|
1636
|
+
function decompressResponse(response) {
|
|
1637
|
+
if (response.body === null) {
|
|
1638
|
+
return null;
|
|
1639
|
+
}
|
|
1640
|
+
const decompressionStream = createDecompressionStream(
|
|
1641
|
+
response.headers.get("content-encoding") || ""
|
|
1642
|
+
);
|
|
1643
|
+
if (!decompressionStream) {
|
|
1644
|
+
return null;
|
|
1645
|
+
}
|
|
1646
|
+
response.body.pipeTo(decompressionStream.writable);
|
|
1647
|
+
return decompressionStream.readable;
|
|
1648
|
+
}
|
|
1558
1649
|
var _FetchInterceptor = class extends Interceptor {
|
|
1559
1650
|
constructor() {
|
|
1560
1651
|
super(_FetchInterceptor.symbol);
|
|
1561
1652
|
}
|
|
1562
1653
|
checkEnvironment() {
|
|
1563
|
-
return
|
|
1654
|
+
return hasConfigurableGlobal("fetch");
|
|
1564
1655
|
}
|
|
1565
1656
|
async setup() {
|
|
1566
1657
|
const pureFetch = globalThis.fetch;
|
|
@@ -1585,10 +1676,12 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1585
1676
|
requestId,
|
|
1586
1677
|
emitter: this.emitter,
|
|
1587
1678
|
controller,
|
|
1588
|
-
onResponse: async (
|
|
1679
|
+
onResponse: async (rawResponse) => {
|
|
1589
1680
|
this.logger.info("received mocked response!", {
|
|
1590
|
-
|
|
1681
|
+
rawResponse
|
|
1591
1682
|
});
|
|
1683
|
+
const decompressedStream = decompressResponse(rawResponse);
|
|
1684
|
+
const response = decompressedStream === null ? rawResponse : new Response(decompressedStream, rawResponse);
|
|
1592
1685
|
if (RESPONSE_STATUS_CODES_WITH_REDIRECT.has(response.status)) {
|
|
1593
1686
|
if (request.redirect === "error") {
|
|
1594
1687
|
responsePromise.reject(createNetworkError("unexpected redirect"));
|
|
@@ -1606,6 +1699,12 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1606
1699
|
return;
|
|
1607
1700
|
}
|
|
1608
1701
|
}
|
|
1702
|
+
Object.defineProperty(response, "url", {
|
|
1703
|
+
writable: false,
|
|
1704
|
+
enumerable: true,
|
|
1705
|
+
configurable: false,
|
|
1706
|
+
value: request.url
|
|
1707
|
+
});
|
|
1609
1708
|
if (this.emitter.listenerCount("response") > 0) {
|
|
1610
1709
|
this.logger.info('emitting the "response" event...');
|
|
1611
1710
|
await emitAsync(this.emitter, "response", {
|
|
@@ -1618,12 +1717,6 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1618
1717
|
requestId
|
|
1619
1718
|
});
|
|
1620
1719
|
}
|
|
1621
|
-
Object.defineProperty(response, "url", {
|
|
1622
|
-
writable: false,
|
|
1623
|
-
enumerable: true,
|
|
1624
|
-
configurable: false,
|
|
1625
|
-
value: request.url
|
|
1626
|
-
});
|
|
1627
1720
|
responsePromise.resolve(response);
|
|
1628
1721
|
},
|
|
1629
1722
|
onRequestError: (response) => {
|
|
@@ -1677,7 +1770,7 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1677
1770
|
var FetchInterceptor = _FetchInterceptor;
|
|
1678
1771
|
FetchInterceptor.symbol = Symbol("fetch");
|
|
1679
1772
|
|
|
1680
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
1773
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-MMAVIMED.mjs
|
|
1681
1774
|
function concatArrayBuffer(left, right) {
|
|
1682
1775
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
1683
1776
|
result.set(left, 0);
|
|
@@ -2424,7 +2517,7 @@ var _XMLHttpRequestInterceptor = class extends Interceptor {
|
|
|
2424
2517
|
super(_XMLHttpRequestInterceptor.interceptorSymbol);
|
|
2425
2518
|
}
|
|
2426
2519
|
checkEnvironment() {
|
|
2427
|
-
return
|
|
2520
|
+
return hasConfigurableGlobal("XMLHttpRequest");
|
|
2428
2521
|
}
|
|
2429
2522
|
setup() {
|
|
2430
2523
|
const logger = this.logger.extend("setup");
|