msw 1.3.2 → 2.0.0
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/README.md +32 -29
- package/browser/package.json +5 -0
- package/cli/init.js +3 -3
- package/config/constants.js +1 -2
- package/lib/browser/index.d.ts +104 -0
- package/lib/browser/index.js +751 -0
- package/lib/browser/index.mjs +733 -0
- package/lib/core/GraphQLHandler-b42ca96f.d.ts +74 -0
- package/lib/core/HttpResponse.d.ts +2 -0
- package/lib/core/HttpResponse.js +94 -0
- package/lib/core/HttpResponse.mjs +77 -0
- package/lib/core/RequestHandler-1a5dbdc7.d.ts +172 -0
- package/lib/core/SetupApi.d.ts +26 -0
- package/lib/core/SetupApi.js +83 -0
- package/lib/core/SetupApi.mjs +63 -0
- package/lib/core/bypass.d.ts +16 -0
- package/lib/core/bypass.js +36 -0
- package/lib/core/bypass.mjs +16 -0
- package/lib/core/delay.d.ts +18 -0
- package/lib/core/delay.js +92 -0
- package/lib/core/delay.mjs +72 -0
- package/lib/core/graphql.d.ts +109 -0
- package/lib/core/graphql.js +112 -0
- package/lib/core/graphql.mjs +96 -0
- package/lib/core/handlers/GraphQLHandler.d.ts +5 -0
- package/lib/core/handlers/GraphQLHandler.js +145 -0
- package/lib/core/handlers/GraphQLHandler.mjs +130 -0
- package/lib/core/handlers/HttpHandler.d.ts +62 -0
- package/lib/core/handlers/HttpHandler.js +149 -0
- package/lib/core/handlers/HttpHandler.mjs +133 -0
- package/lib/core/handlers/RequestHandler.d.ts +2 -0
- package/lib/core/handlers/RequestHandler.js +180 -0
- package/lib/core/handlers/RequestHandler.mjs +162 -0
- package/lib/core/http.d.ts +26 -0
- package/lib/core/http.js +39 -0
- package/lib/core/http.mjs +22 -0
- package/lib/core/http.spec.d.ts +2 -0
- package/lib/core/http.spec.js +15 -0
- package/lib/core/http.spec.mjs +14 -0
- package/lib/core/index.d.ts +18 -0
- package/lib/core/index.js +49 -0
- package/lib/core/index.mjs +28 -0
- package/lib/core/passthrough.d.ts +17 -0
- package/lib/core/passthrough.js +32 -0
- package/lib/core/passthrough.mjs +12 -0
- package/lib/core/sharedOptions.d.ts +66 -0
- package/lib/core/sharedOptions.js +16 -0
- package/lib/core/sharedOptions.mjs +0 -0
- package/lib/core/typeUtils.d.ts +7 -0
- package/lib/core/typeUtils.js +16 -0
- package/lib/core/typeUtils.mjs +0 -0
- package/lib/core/utils/HttpResponse/decorators.d.ts +12 -0
- package/lib/core/utils/HttpResponse/decorators.js +80 -0
- package/lib/core/utils/HttpResponse/decorators.mjs +52 -0
- package/lib/core/utils/getResponse.d.ts +2 -0
- package/lib/core/utils/getResponse.js +64 -0
- package/lib/core/utils/getResponse.mjs +44 -0
- package/lib/core/utils/handleRequest.d.ts +30 -0
- package/lib/core/utils/handleRequest.js +102 -0
- package/lib/core/utils/handleRequest.mjs +82 -0
- package/lib/core/utils/internal/Disposable.d.ts +7 -0
- package/lib/core/utils/internal/Disposable.js +53 -0
- package/lib/core/utils/internal/Disposable.mjs +33 -0
- package/lib/core/utils/internal/checkGlobals.d.ts +3 -0
- package/lib/core/utils/internal/checkGlobals.js +33 -0
- package/lib/core/utils/internal/checkGlobals.mjs +13 -0
- package/lib/core/utils/internal/devUtils.d.ts +19 -0
- package/lib/core/utils/internal/devUtils.js +40 -0
- package/lib/core/utils/internal/devUtils.mjs +20 -0
- package/lib/core/utils/internal/getCallFrame.d.ts +6 -0
- package/lib/core/utils/internal/getCallFrame.js +40 -0
- package/lib/core/utils/internal/getCallFrame.mjs +20 -0
- package/lib/core/utils/internal/isIterable.d.ts +6 -0
- package/lib/core/utils/internal/isIterable.js +29 -0
- package/lib/core/utils/internal/isIterable.mjs +9 -0
- package/lib/core/utils/internal/isObject.d.ts +6 -0
- package/lib/core/utils/internal/isObject.js +26 -0
- package/lib/core/utils/internal/isObject.mjs +6 -0
- package/lib/core/utils/internal/isStringEqual.d.ts +6 -0
- package/lib/core/utils/internal/isStringEqual.js +26 -0
- package/lib/core/utils/internal/isStringEqual.mjs +6 -0
- package/lib/core/utils/internal/jsonParse.d.ts +7 -0
- package/lib/core/utils/internal/jsonParse.js +30 -0
- package/lib/core/utils/internal/jsonParse.mjs +10 -0
- package/lib/core/utils/internal/mergeRight.d.ts +7 -0
- package/lib/core/utils/internal/mergeRight.js +39 -0
- package/lib/core/utils/internal/mergeRight.mjs +19 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +5 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js +184 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +165 -0
- package/lib/core/utils/internal/parseMultipartData.d.ts +10 -0
- package/lib/core/utils/internal/parseMultipartData.js +81 -0
- package/lib/core/utils/internal/parseMultipartData.mjs +61 -0
- package/lib/core/utils/internal/pipeEvents.d.ts +8 -0
- package/lib/core/utils/internal/pipeEvents.js +34 -0
- package/lib/core/utils/internal/pipeEvents.mjs +14 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +8 -0
- package/lib/core/utils/internal/requestHandlerUtils.js +36 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs +16 -0
- package/lib/core/utils/internal/toReadonlyArray.d.ts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.js +28 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs +8 -0
- package/lib/core/utils/internal/tryCatch.d.ts +3 -0
- package/lib/core/utils/internal/tryCatch.js +31 -0
- package/lib/core/utils/internal/tryCatch.mjs +11 -0
- package/lib/core/utils/internal/uuidv4.d.ts +3 -0
- package/lib/core/utils/internal/uuidv4.js +26 -0
- package/lib/core/utils/internal/uuidv4.mjs +6 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.ts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.js +39 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs +19 -0
- package/lib/core/utils/logging/getTimestamp.d.ts +6 -0
- package/lib/core/utils/logging/getTimestamp.js +27 -0
- package/lib/core/utils/logging/getTimestamp.mjs +7 -0
- package/lib/core/utils/logging/serializeRequest.d.ts +12 -0
- package/lib/core/utils/logging/serializeRequest.js +55 -0
- package/lib/core/utils/logging/serializeRequest.mjs +35 -0
- package/lib/core/utils/logging/serializeResponse.d.ts +9 -0
- package/lib/core/utils/logging/serializeResponse.js +69 -0
- package/lib/core/utils/logging/serializeResponse.mjs +39 -0
- package/lib/core/utils/matching/matchRequestUrl.d.ts +19 -0
- package/lib/core/utils/matching/matchRequestUrl.js +50 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs +30 -0
- package/lib/core/utils/matching/normalizePath.d.ts +12 -0
- package/lib/core/utils/matching/normalizePath.js +32 -0
- package/lib/core/utils/matching/normalizePath.mjs +12 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.d.ts +7 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.js +30 -0
- package/lib/core/utils/request/getPublicUrlFromRequest.mjs +10 -0
- package/lib/core/utils/request/getRequestCookies.d.ts +8 -0
- package/lib/core/utils/request/getRequestCookies.js +88 -0
- package/lib/core/utils/request/getRequestCookies.mjs +60 -0
- package/lib/core/utils/request/onUnhandledRequest.d.ts +12 -0
- package/lib/core/utils/request/onUnhandledRequest.js +193 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs +165 -0
- package/lib/core/utils/request/readResponseCookies.d.ts +3 -0
- package/lib/core/utils/request/readResponseCookies.js +45 -0
- package/lib/core/utils/request/readResponseCookies.mjs +27 -0
- package/lib/core/utils/toResponseInit.d.ts +3 -0
- package/lib/core/utils/toResponseInit.js +30 -0
- package/lib/core/utils/toResponseInit.mjs +10 -0
- package/lib/core/utils/url/cleanUrl.d.ts +7 -0
- package/lib/core/utils/url/cleanUrl.js +31 -0
- package/lib/core/utils/url/cleanUrl.mjs +11 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.js +37 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs +17 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.js +26 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs +6 -0
- package/lib/iife/index.js +6203 -12360
- package/lib/mockServiceWorker.js +82 -93
- package/lib/native/index.d.ts +67 -7
- package/lib/native/index.js +74 -1500
- package/lib/native/index.mjs +69 -1514
- package/lib/node/index.d.ts +68 -9
- package/lib/node/index.js +77 -1508
- package/lib/node/index.mjs +71 -1521
- package/native/package.json +2 -1
- package/node/package.json +2 -1
- package/package.json +53 -23
- package/lib/SetupServerApi-1855d9c6.d.ts +0 -20
- package/lib/glossary-de6278a9.d.ts +0 -385
- package/lib/iife/index.js.map +0 -1
- package/lib/index.d.ts +0 -365
- package/lib/index.js +0 -2295
- package/lib/index.js.map +0 -1
- package/lib/node/index.js.map +0 -1
- package/lib/node/index.mjs.map +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __async = (__this, __arguments, generator) => {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
var fulfilled = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.next(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var rejected = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.throw(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var serializeResponse_exports = {};
|
|
50
|
+
__export(serializeResponse_exports, {
|
|
51
|
+
serializeResponse: () => serializeResponse
|
|
52
|
+
});
|
|
53
|
+
module.exports = __toCommonJS(serializeResponse_exports);
|
|
54
|
+
var import_statuses = __toESM(require("@bundled-es-modules/statuses"));
|
|
55
|
+
const { message } = import_statuses.default;
|
|
56
|
+
function serializeResponse(response) {
|
|
57
|
+
return __async(this, null, function* () {
|
|
58
|
+
const responseClone = response.clone();
|
|
59
|
+
const responseText = yield responseClone.text();
|
|
60
|
+
const responseStatus = responseClone.status || 200;
|
|
61
|
+
const responseStatusText = responseClone.statusText || message[responseStatus] || "OK";
|
|
62
|
+
return {
|
|
63
|
+
status: responseStatus,
|
|
64
|
+
statusText: responseStatusText,
|
|
65
|
+
headers: Object.fromEntries(responseClone.headers.entries()),
|
|
66
|
+
body: responseText
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import statuses from "@bundled-es-modules/statuses";
|
|
22
|
+
const { message } = statuses;
|
|
23
|
+
function serializeResponse(response) {
|
|
24
|
+
return __async(this, null, function* () {
|
|
25
|
+
const responseClone = response.clone();
|
|
26
|
+
const responseText = yield responseClone.text();
|
|
27
|
+
const responseStatus = responseClone.status || 200;
|
|
28
|
+
const responseStatusText = responseClone.statusText || message[responseStatus] || "OK";
|
|
29
|
+
return {
|
|
30
|
+
status: responseStatus,
|
|
31
|
+
statusText: responseStatusText,
|
|
32
|
+
headers: Object.fromEntries(responseClone.headers.entries()),
|
|
33
|
+
body: responseText
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
serializeResponse
|
|
39
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type Path = string | RegExp;
|
|
2
|
+
type PathParams<KeyType extends keyof any = string> = {
|
|
3
|
+
[ParamName in KeyType]: string | ReadonlyArray<string>;
|
|
4
|
+
};
|
|
5
|
+
interface Match {
|
|
6
|
+
matches: boolean;
|
|
7
|
+
params?: PathParams;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Coerce a path supported by MSW into a path
|
|
11
|
+
* supported by "path-to-regexp".
|
|
12
|
+
*/
|
|
13
|
+
declare function coercePath(path: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the result of matching given request URL against a mask.
|
|
16
|
+
*/
|
|
17
|
+
declare function matchRequestUrl(url: URL, path: Path, baseUrl?: string): Match;
|
|
18
|
+
|
|
19
|
+
export { Match, Path, PathParams, coercePath, matchRequestUrl };
|
|
@@ -0,0 +1,50 @@
|
|
|
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 matchRequestUrl_exports = {};
|
|
20
|
+
__export(matchRequestUrl_exports, {
|
|
21
|
+
coercePath: () => coercePath,
|
|
22
|
+
matchRequestUrl: () => matchRequestUrl
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(matchRequestUrl_exports);
|
|
25
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
26
|
+
var import_interceptors = require("@mswjs/interceptors");
|
|
27
|
+
var import_normalizePath = require("./normalizePath.js");
|
|
28
|
+
function coercePath(path) {
|
|
29
|
+
return path.replace(
|
|
30
|
+
/([:a-zA-Z_-]*)(\*{1,2})+/g,
|
|
31
|
+
(_, parameterName, wildcard) => {
|
|
32
|
+
const expression = "(.*)";
|
|
33
|
+
if (!parameterName) {
|
|
34
|
+
return expression;
|
|
35
|
+
}
|
|
36
|
+
return parameterName.startsWith(":") ? `${parameterName}${wildcard}` : `${parameterName}${expression}`;
|
|
37
|
+
}
|
|
38
|
+
).replace(/([^\/])(:)(?=\d+)/, "$1\\$2").replace(/^([^\/]+)(:)(?=\/\/)/, "$1\\$2");
|
|
39
|
+
}
|
|
40
|
+
function matchRequestUrl(url, path, baseUrl) {
|
|
41
|
+
const normalizedPath = (0, import_normalizePath.normalizePath)(path, baseUrl);
|
|
42
|
+
const cleanPath = typeof normalizedPath === "string" ? coercePath(normalizedPath) : normalizedPath;
|
|
43
|
+
const cleanUrl = (0, import_interceptors.getCleanUrl)(url);
|
|
44
|
+
const result = (0, import_path_to_regexp.match)(cleanPath, { decode: decodeURIComponent })(cleanUrl);
|
|
45
|
+
const params = result && result.params || {};
|
|
46
|
+
return {
|
|
47
|
+
matches: result !== false,
|
|
48
|
+
params
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { match } from "path-to-regexp";
|
|
2
|
+
import { getCleanUrl } from "@mswjs/interceptors";
|
|
3
|
+
import { normalizePath } from './normalizePath.mjs';
|
|
4
|
+
function coercePath(path) {
|
|
5
|
+
return path.replace(
|
|
6
|
+
/([:a-zA-Z_-]*)(\*{1,2})+/g,
|
|
7
|
+
(_, parameterName, wildcard) => {
|
|
8
|
+
const expression = "(.*)";
|
|
9
|
+
if (!parameterName) {
|
|
10
|
+
return expression;
|
|
11
|
+
}
|
|
12
|
+
return parameterName.startsWith(":") ? `${parameterName}${wildcard}` : `${parameterName}${expression}`;
|
|
13
|
+
}
|
|
14
|
+
).replace(/([^\/])(:)(?=\d+)/, "$1\\$2").replace(/^([^\/]+)(:)(?=\/\/)/, "$1\\$2");
|
|
15
|
+
}
|
|
16
|
+
function matchRequestUrl(url, path, baseUrl) {
|
|
17
|
+
const normalizedPath = normalizePath(path, baseUrl);
|
|
18
|
+
const cleanPath = typeof normalizedPath === "string" ? coercePath(normalizedPath) : normalizedPath;
|
|
19
|
+
const cleanUrl = getCleanUrl(url);
|
|
20
|
+
const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl);
|
|
21
|
+
const params = result && result.params || {};
|
|
22
|
+
return {
|
|
23
|
+
matches: result !== false,
|
|
24
|
+
params
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
coercePath,
|
|
29
|
+
matchRequestUrl
|
|
30
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Path } from './matchRequestUrl.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a given request handler path:
|
|
5
|
+
* - Preserves RegExp.
|
|
6
|
+
* - Removes query parameters and hashes.
|
|
7
|
+
* - Rebases relative URLs against the "baseUrl" or the current location.
|
|
8
|
+
* - Preserves relative URLs in Node.js, unless specified otherwise.
|
|
9
|
+
*/
|
|
10
|
+
declare function normalizePath(path: Path, baseUrl?: string): Path;
|
|
11
|
+
|
|
12
|
+
export { normalizePath };
|
|
@@ -0,0 +1,32 @@
|
|
|
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 normalizePath_exports = {};
|
|
20
|
+
__export(normalizePath_exports, {
|
|
21
|
+
normalizePath: () => normalizePath
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(normalizePath_exports);
|
|
24
|
+
var import_cleanUrl = require("../url/cleanUrl.js");
|
|
25
|
+
var import_getAbsoluteUrl = require("../url/getAbsoluteUrl.js");
|
|
26
|
+
function normalizePath(path, baseUrl) {
|
|
27
|
+
if (path instanceof RegExp) {
|
|
28
|
+
return path;
|
|
29
|
+
}
|
|
30
|
+
const maybeAbsoluteUrl = (0, import_getAbsoluteUrl.getAbsoluteUrl)(path, baseUrl);
|
|
31
|
+
return (0, import_cleanUrl.cleanUrl)(maybeAbsoluteUrl);
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { cleanUrl } from '../url/cleanUrl.mjs';
|
|
2
|
+
import { getAbsoluteUrl } from '../url/getAbsoluteUrl.mjs';
|
|
3
|
+
function normalizePath(path, baseUrl) {
|
|
4
|
+
if (path instanceof RegExp) {
|
|
5
|
+
return path;
|
|
6
|
+
}
|
|
7
|
+
const maybeAbsoluteUrl = getAbsoluteUrl(path, baseUrl);
|
|
8
|
+
return cleanUrl(maybeAbsoluteUrl);
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
normalizePath
|
|
12
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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 getPublicUrlFromRequest_exports = {};
|
|
20
|
+
__export(getPublicUrlFromRequest_exports, {
|
|
21
|
+
getPublicUrlFromRequest: () => getPublicUrlFromRequest
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getPublicUrlFromRequest_exports);
|
|
24
|
+
function getPublicUrlFromRequest(request) {
|
|
25
|
+
if (typeof location === "undefined") {
|
|
26
|
+
return request.url;
|
|
27
|
+
}
|
|
28
|
+
const url = new URL(request.url);
|
|
29
|
+
return url.origin === location.origin ? url.pathname : url.origin + url.pathname;
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function getPublicUrlFromRequest(request) {
|
|
2
|
+
if (typeof location === "undefined") {
|
|
3
|
+
return request.url;
|
|
4
|
+
}
|
|
5
|
+
const url = new URL(request.url);
|
|
6
|
+
return url.origin === location.origin ? url.pathname : url.origin + url.pathname;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
getPublicUrlFromRequest
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @todo Rename this to "getDocumentCookies" */
|
|
2
|
+
/**
|
|
3
|
+
* Returns relevant document cookies based on the request `credentials` option.
|
|
4
|
+
*/
|
|
5
|
+
declare function getRequestCookies(request: Request): Record<string, string>;
|
|
6
|
+
declare function getAllRequestCookies(request: Request): Record<string, string>;
|
|
7
|
+
|
|
8
|
+
export { getAllRequestCookies, getRequestCookies };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __export = (target, all) => {
|
|
23
|
+
for (var name in all)
|
|
24
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
25
|
+
};
|
|
26
|
+
var __copyProps = (to, from, except, desc) => {
|
|
27
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
28
|
+
for (let key of __getOwnPropNames(from))
|
|
29
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
30
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
31
|
+
}
|
|
32
|
+
return to;
|
|
33
|
+
};
|
|
34
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
35
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
36
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
37
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
38
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
39
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
40
|
+
mod
|
|
41
|
+
));
|
|
42
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
43
|
+
var getRequestCookies_exports = {};
|
|
44
|
+
__export(getRequestCookies_exports, {
|
|
45
|
+
getAllRequestCookies: () => getAllRequestCookies,
|
|
46
|
+
getRequestCookies: () => getRequestCookies
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(getRequestCookies_exports);
|
|
49
|
+
var import_cookie = __toESM(require("@bundled-es-modules/cookie"));
|
|
50
|
+
var import_cookies = require("@mswjs/cookies");
|
|
51
|
+
function getAllDocumentCookies() {
|
|
52
|
+
return import_cookie.default.parse(document.cookie);
|
|
53
|
+
}
|
|
54
|
+
function getRequestCookies(request) {
|
|
55
|
+
if (typeof document === "undefined" || typeof location === "undefined") {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
switch (request.credentials) {
|
|
59
|
+
case "same-origin": {
|
|
60
|
+
const url = new URL(request.url);
|
|
61
|
+
return location.origin === url.origin ? getAllDocumentCookies() : {};
|
|
62
|
+
}
|
|
63
|
+
case "include": {
|
|
64
|
+
return getAllDocumentCookies();
|
|
65
|
+
}
|
|
66
|
+
default: {
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function getAllRequestCookies(request) {
|
|
72
|
+
var _a;
|
|
73
|
+
const requestCookiesString = request.headers.get("cookie");
|
|
74
|
+
const cookiesFromHeaders = requestCookiesString ? import_cookie.default.parse(requestCookiesString) : {};
|
|
75
|
+
import_cookies.store.hydrate();
|
|
76
|
+
const cookiesFromStore = Array.from((_a = import_cookies.store.get(request)) == null ? void 0 : _a.entries()).reduce(
|
|
77
|
+
(cookies, [name, { value }]) => {
|
|
78
|
+
return Object.assign(cookies, { [name.trim()]: value });
|
|
79
|
+
},
|
|
80
|
+
{}
|
|
81
|
+
);
|
|
82
|
+
const cookiesFromDocument = getRequestCookies(request);
|
|
83
|
+
const forwardedCookies = __spreadValues(__spreadValues({}, cookiesFromDocument), cookiesFromStore);
|
|
84
|
+
for (const [name, value] of Object.entries(forwardedCookies)) {
|
|
85
|
+
request.headers.append("cookie", `${name}=${value}`);
|
|
86
|
+
}
|
|
87
|
+
return __spreadValues(__spreadValues({}, forwardedCookies), cookiesFromHeaders);
|
|
88
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import cookieUtils from "@bundled-es-modules/cookie";
|
|
18
|
+
import { store } from "@mswjs/cookies";
|
|
19
|
+
function getAllDocumentCookies() {
|
|
20
|
+
return cookieUtils.parse(document.cookie);
|
|
21
|
+
}
|
|
22
|
+
function getRequestCookies(request) {
|
|
23
|
+
if (typeof document === "undefined" || typeof location === "undefined") {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
switch (request.credentials) {
|
|
27
|
+
case "same-origin": {
|
|
28
|
+
const url = new URL(request.url);
|
|
29
|
+
return location.origin === url.origin ? getAllDocumentCookies() : {};
|
|
30
|
+
}
|
|
31
|
+
case "include": {
|
|
32
|
+
return getAllDocumentCookies();
|
|
33
|
+
}
|
|
34
|
+
default: {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function getAllRequestCookies(request) {
|
|
40
|
+
var _a;
|
|
41
|
+
const requestCookiesString = request.headers.get("cookie");
|
|
42
|
+
const cookiesFromHeaders = requestCookiesString ? cookieUtils.parse(requestCookiesString) : {};
|
|
43
|
+
store.hydrate();
|
|
44
|
+
const cookiesFromStore = Array.from((_a = store.get(request)) == null ? void 0 : _a.entries()).reduce(
|
|
45
|
+
(cookies, [name, { value }]) => {
|
|
46
|
+
return Object.assign(cookies, { [name.trim()]: value });
|
|
47
|
+
},
|
|
48
|
+
{}
|
|
49
|
+
);
|
|
50
|
+
const cookiesFromDocument = getRequestCookies(request);
|
|
51
|
+
const forwardedCookies = __spreadValues(__spreadValues({}, cookiesFromDocument), cookiesFromStore);
|
|
52
|
+
for (const [name, value] of Object.entries(forwardedCookies)) {
|
|
53
|
+
request.headers.append("cookie", `${name}=${value}`);
|
|
54
|
+
}
|
|
55
|
+
return __spreadValues(__spreadValues({}, forwardedCookies), cookiesFromHeaders);
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
getAllRequestCookies,
|
|
59
|
+
getRequestCookies
|
|
60
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { R as RequestHandler } from '../../RequestHandler-1a5dbdc7.js';
|
|
2
|
+
import '../../typeUtils.js';
|
|
3
|
+
|
|
4
|
+
interface UnhandledRequestPrint {
|
|
5
|
+
warning(): void;
|
|
6
|
+
error(): void;
|
|
7
|
+
}
|
|
8
|
+
type UnhandledRequestCallback = (request: Request, print: UnhandledRequestPrint) => void;
|
|
9
|
+
type UnhandledRequestStrategy = 'bypass' | 'warn' | 'error' | UnhandledRequestCallback;
|
|
10
|
+
declare function onUnhandledRequest(request: Request, handlers: Array<RequestHandler>, strategy?: UnhandledRequestStrategy): Promise<void>;
|
|
11
|
+
|
|
12
|
+
export { UnhandledRequestCallback, UnhandledRequestPrint, UnhandledRequestStrategy, onUnhandledRequest };
|