msw 2.6.1 → 2.6.3
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/handleRequest.d.mts +0 -5
- package/lib/core/utils/handleRequest.d.ts +0 -5
- package/lib/core/utils/handleRequest.js +2 -6
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +2 -6
- package/lib/core/utils/handleRequest.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 +204 -71
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/utils/handleRequest.test.ts +1 -86
- package/src/core/utils/handleRequest.ts +2 -15
- package/src/core/utils/request/getRequestCookies.ts +15 -2
package/lib/browser/index.js
CHANGED
|
@@ -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.
|
|
406
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/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,7 +419,7 @@ function toArrayBuffer(array) {
|
|
|
419
419
|
);
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
422
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-6MOMO77R.mjs
|
|
423
423
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
424
424
|
function isPropertyAccessible(obj, key) {
|
|
425
425
|
try {
|
|
@@ -905,7 +905,7 @@ var _Emitter = class {
|
|
|
905
905
|
var Emitter = _Emitter;
|
|
906
906
|
Emitter.defaultMaxListeners = 10;
|
|
907
907
|
|
|
908
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
908
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
909
909
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
910
910
|
function getGlobalSymbol(symbol) {
|
|
911
911
|
return (
|
|
@@ -1053,7 +1053,7 @@ function createRequestId() {
|
|
|
1053
1053
|
return Math.random().toString(16).slice(2);
|
|
1054
1054
|
}
|
|
1055
1055
|
|
|
1056
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
1056
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1057
1057
|
var BatchInterceptor = class extends Interceptor {
|
|
1058
1058
|
constructor(options) {
|
|
1059
1059
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -1339,7 +1339,7 @@ var DeferredPromise = class extends Promise {
|
|
|
1339
1339
|
}
|
|
1340
1340
|
};
|
|
1341
1341
|
|
|
1342
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
1342
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-4RQHC4IY.mjs
|
|
1343
1343
|
var InterceptorError = class extends Error {
|
|
1344
1344
|
constructor(message) {
|
|
1345
1345
|
super(message);
|
|
@@ -1443,13 +1443,17 @@ async function handleRequest2(options) {
|
|
|
1443
1443
|
});
|
|
1444
1444
|
const requestAbortPromise = new DeferredPromise();
|
|
1445
1445
|
if (options.request.signal) {
|
|
1446
|
-
options.request.signal.
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1446
|
+
if (options.request.signal.aborted) {
|
|
1447
|
+
requestAbortPromise.reject(options.request.signal.reason);
|
|
1448
|
+
} else {
|
|
1449
|
+
options.request.signal.addEventListener(
|
|
1450
|
+
"abort",
|
|
1451
|
+
() => {
|
|
1452
|
+
requestAbortPromise.reject(options.request.signal.reason);
|
|
1453
|
+
},
|
|
1454
|
+
{ once: true }
|
|
1455
|
+
);
|
|
1456
|
+
}
|
|
1453
1457
|
}
|
|
1454
1458
|
const result = await until(async () => {
|
|
1455
1459
|
const requestListtenersPromise = emitAsync(options.emitter, "request", {
|
|
@@ -1507,7 +1511,28 @@ async function handleRequest2(options) {
|
|
|
1507
1511
|
return false;
|
|
1508
1512
|
}
|
|
1509
1513
|
|
|
1510
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
1514
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-TX5GBTFY.mjs
|
|
1515
|
+
function hasConfigurableGlobal(propertyName) {
|
|
1516
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
1517
|
+
if (typeof descriptor === "undefined") {
|
|
1518
|
+
return false;
|
|
1519
|
+
}
|
|
1520
|
+
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") {
|
|
1521
|
+
return false;
|
|
1522
|
+
}
|
|
1523
|
+
if (typeof descriptor.get === "undefined" && descriptor.value == null) {
|
|
1524
|
+
return false;
|
|
1525
|
+
}
|
|
1526
|
+
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
1527
|
+
console.error(
|
|
1528
|
+
`[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.`
|
|
1529
|
+
);
|
|
1530
|
+
return false;
|
|
1531
|
+
}
|
|
1532
|
+
return true;
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-VXLPKFY4.mjs
|
|
1511
1536
|
function canParseUrl(url) {
|
|
1512
1537
|
try {
|
|
1513
1538
|
new URL(url);
|
|
@@ -1582,12 +1607,78 @@ function sameOrigin(left, right) {
|
|
|
1582
1607
|
}
|
|
1583
1608
|
return false;
|
|
1584
1609
|
}
|
|
1610
|
+
var BrotliDecompressionStream = class extends TransformStream {
|
|
1611
|
+
constructor() {
|
|
1612
|
+
console.warn(
|
|
1613
|
+
"[Interceptors]: Brotli decompression of response streams is not supported in the browser"
|
|
1614
|
+
);
|
|
1615
|
+
super({
|
|
1616
|
+
transform(chunk, controller) {
|
|
1617
|
+
controller.enqueue(chunk);
|
|
1618
|
+
}
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
var PipelineStream = class extends TransformStream {
|
|
1623
|
+
constructor(transformStreams, ...strategies) {
|
|
1624
|
+
super({}, ...strategies);
|
|
1625
|
+
const readable = [super.readable, ...transformStreams].reduce(
|
|
1626
|
+
(readable2, transform) => readable2.pipeThrough(transform)
|
|
1627
|
+
);
|
|
1628
|
+
Object.defineProperty(this, "readable", {
|
|
1629
|
+
get() {
|
|
1630
|
+
return readable;
|
|
1631
|
+
}
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
};
|
|
1635
|
+
function parseContentEncoding(contentEncoding) {
|
|
1636
|
+
return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
|
|
1637
|
+
}
|
|
1638
|
+
function createDecompressionStream(contentEncoding) {
|
|
1639
|
+
if (contentEncoding === "") {
|
|
1640
|
+
return null;
|
|
1641
|
+
}
|
|
1642
|
+
const codings = parseContentEncoding(contentEncoding);
|
|
1643
|
+
if (codings.length === 0) {
|
|
1644
|
+
return null;
|
|
1645
|
+
}
|
|
1646
|
+
const transformers = codings.reduceRight(
|
|
1647
|
+
(transformers2, coding) => {
|
|
1648
|
+
if (coding === "gzip" || coding === "x-gzip") {
|
|
1649
|
+
return transformers2.concat(new DecompressionStream("gzip"));
|
|
1650
|
+
} else if (coding === "deflate") {
|
|
1651
|
+
return transformers2.concat(new DecompressionStream("deflate"));
|
|
1652
|
+
} else if (coding === "br") {
|
|
1653
|
+
return transformers2.concat(new BrotliDecompressionStream());
|
|
1654
|
+
} else {
|
|
1655
|
+
transformers2.length = 0;
|
|
1656
|
+
}
|
|
1657
|
+
return transformers2;
|
|
1658
|
+
},
|
|
1659
|
+
[]
|
|
1660
|
+
);
|
|
1661
|
+
return new PipelineStream(transformers);
|
|
1662
|
+
}
|
|
1663
|
+
function decompressResponse(response) {
|
|
1664
|
+
if (response.body === null) {
|
|
1665
|
+
return null;
|
|
1666
|
+
}
|
|
1667
|
+
const decompressionStream = createDecompressionStream(
|
|
1668
|
+
response.headers.get("content-encoding") || ""
|
|
1669
|
+
);
|
|
1670
|
+
if (!decompressionStream) {
|
|
1671
|
+
return null;
|
|
1672
|
+
}
|
|
1673
|
+
response.body.pipeTo(decompressionStream.writable);
|
|
1674
|
+
return decompressionStream.readable;
|
|
1675
|
+
}
|
|
1585
1676
|
var _FetchInterceptor = class extends Interceptor {
|
|
1586
1677
|
constructor() {
|
|
1587
1678
|
super(_FetchInterceptor.symbol);
|
|
1588
1679
|
}
|
|
1589
1680
|
checkEnvironment() {
|
|
1590
|
-
return
|
|
1681
|
+
return hasConfigurableGlobal("fetch");
|
|
1591
1682
|
}
|
|
1592
1683
|
async setup() {
|
|
1593
1684
|
const pureFetch = globalThis.fetch;
|
|
@@ -1612,10 +1703,12 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1612
1703
|
requestId,
|
|
1613
1704
|
emitter: this.emitter,
|
|
1614
1705
|
controller,
|
|
1615
|
-
onResponse: async (
|
|
1706
|
+
onResponse: async (rawResponse) => {
|
|
1616
1707
|
this.logger.info("received mocked response!", {
|
|
1617
|
-
|
|
1708
|
+
rawResponse
|
|
1618
1709
|
});
|
|
1710
|
+
const decompressedStream = decompressResponse(rawResponse);
|
|
1711
|
+
const response = decompressedStream === null ? rawResponse : new Response(decompressedStream, rawResponse);
|
|
1619
1712
|
if (RESPONSE_STATUS_CODES_WITH_REDIRECT.has(response.status)) {
|
|
1620
1713
|
if (request.redirect === "error") {
|
|
1621
1714
|
responsePromise.reject(createNetworkError("unexpected redirect"));
|
|
@@ -1633,6 +1726,12 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1633
1726
|
return;
|
|
1634
1727
|
}
|
|
1635
1728
|
}
|
|
1729
|
+
Object.defineProperty(response, "url", {
|
|
1730
|
+
writable: false,
|
|
1731
|
+
enumerable: true,
|
|
1732
|
+
configurable: false,
|
|
1733
|
+
value: request.url
|
|
1734
|
+
});
|
|
1636
1735
|
if (this.emitter.listenerCount("response") > 0) {
|
|
1637
1736
|
this.logger.info('emitting the "response" event...');
|
|
1638
1737
|
await emitAsync(this.emitter, "response", {
|
|
@@ -1645,12 +1744,6 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1645
1744
|
requestId
|
|
1646
1745
|
});
|
|
1647
1746
|
}
|
|
1648
|
-
Object.defineProperty(response, "url", {
|
|
1649
|
-
writable: false,
|
|
1650
|
-
enumerable: true,
|
|
1651
|
-
configurable: false,
|
|
1652
|
-
value: request.url
|
|
1653
|
-
});
|
|
1654
1747
|
responsePromise.resolve(response);
|
|
1655
1748
|
},
|
|
1656
1749
|
onRequestError: (response) => {
|
|
@@ -1704,7 +1797,7 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
1704
1797
|
var FetchInterceptor = _FetchInterceptor;
|
|
1705
1798
|
FetchInterceptor.symbol = Symbol("fetch");
|
|
1706
1799
|
|
|
1707
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.36.
|
|
1800
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.10/node_modules/@mswjs/interceptors/lib/browser/chunk-MMAVIMED.mjs
|
|
1708
1801
|
function concatArrayBuffer(left, right) {
|
|
1709
1802
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
1710
1803
|
result.set(left, 0);
|
|
@@ -2451,7 +2544,7 @@ var _XMLHttpRequestInterceptor = class extends Interceptor {
|
|
|
2451
2544
|
super(_XMLHttpRequestInterceptor.interceptorSymbol);
|
|
2452
2545
|
}
|
|
2453
2546
|
checkEnvironment() {
|
|
2454
|
-
return
|
|
2547
|
+
return hasConfigurableGlobal("XMLHttpRequest");
|
|
2455
2548
|
}
|
|
2456
2549
|
setup() {
|
|
2457
2550
|
const logger = this.logger.extend("setup");
|