msw 1.3.2 → 2.0.1
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 +45 -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 +752 -0
- package/lib/browser/index.mjs +734 -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 +6204 -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,20 @@
|
|
|
1
|
+
const SOURCE_FRAME = /[\/\\]msw[\/\\]src[\/\\](.+)/;
|
|
2
|
+
const BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](core|browser|node|native|iife)[\/\\]|^[^\/\\]*$/;
|
|
3
|
+
function getCallFrame(error) {
|
|
4
|
+
const stack = error.stack;
|
|
5
|
+
if (!stack) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const frames = stack.split("\n").slice(1);
|
|
9
|
+
const declarationFrame = frames.find((frame) => {
|
|
10
|
+
return !(SOURCE_FRAME.test(frame) || BUILD_FRAME.test(frame));
|
|
11
|
+
});
|
|
12
|
+
if (!declarationFrame) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const declarationPath = declarationFrame.replace(/\s*at [^()]*\(([^)]+)\)/, "$1").replace(/^@/, "");
|
|
16
|
+
return declarationPath;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
getCallFrame
|
|
20
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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 isIterable_exports = {};
|
|
20
|
+
__export(isIterable_exports, {
|
|
21
|
+
isIterable: () => isIterable
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(isIterable_exports);
|
|
24
|
+
function isIterable(fn) {
|
|
25
|
+
if (!fn) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return typeof fn[Symbol.iterator] == "function";
|
|
29
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 isObject_exports = {};
|
|
20
|
+
__export(isObject_exports, {
|
|
21
|
+
isObject: () => isObject
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(isObject_exports);
|
|
24
|
+
function isObject(value) {
|
|
25
|
+
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 isStringEqual_exports = {};
|
|
20
|
+
__export(isStringEqual_exports, {
|
|
21
|
+
isStringEqual: () => isStringEqual
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(isStringEqual_exports);
|
|
24
|
+
function isStringEqual(actual, expected) {
|
|
25
|
+
return actual.toLowerCase() === expected.toLowerCase();
|
|
26
|
+
}
|
|
@@ -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 jsonParse_exports = {};
|
|
20
|
+
__export(jsonParse_exports, {
|
|
21
|
+
jsonParse: () => jsonParse
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(jsonParse_exports);
|
|
24
|
+
function jsonParse(value) {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(value);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 mergeRight_exports = {};
|
|
20
|
+
__export(mergeRight_exports, {
|
|
21
|
+
mergeRight: () => mergeRight
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(mergeRight_exports);
|
|
24
|
+
var import_isObject = require("./isObject.js");
|
|
25
|
+
function mergeRight(left, right) {
|
|
26
|
+
return Object.entries(right).reduce((result, [key, rightValue]) => {
|
|
27
|
+
const leftValue = result[key];
|
|
28
|
+
if (Array.isArray(leftValue) && Array.isArray(rightValue)) {
|
|
29
|
+
result[key] = leftValue.concat(rightValue);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
if ((0, import_isObject.isObject)(leftValue) && (0, import_isObject.isObject)(rightValue)) {
|
|
33
|
+
result[key] = mergeRight(leftValue, rightValue);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
result[key] = rightValue;
|
|
37
|
+
return result;
|
|
38
|
+
}, Object.assign({}, left));
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isObject } from './isObject.mjs';
|
|
2
|
+
function mergeRight(left, right) {
|
|
3
|
+
return Object.entries(right).reduce((result, [key, rightValue]) => {
|
|
4
|
+
const leftValue = result[key];
|
|
5
|
+
if (Array.isArray(leftValue) && Array.isArray(rightValue)) {
|
|
6
|
+
result[key] = leftValue.concat(rightValue);
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
if (isObject(leftValue) && isObject(rightValue)) {
|
|
10
|
+
result[key] = mergeRight(leftValue, rightValue);
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
result[key] = rightValue;
|
|
14
|
+
return result;
|
|
15
|
+
}, Object.assign({}, left));
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
mergeRight
|
|
19
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import 'graphql';
|
|
2
|
+
export { i as GraphQLMultipartRequestBody, h as GraphQLParsedOperationsMap, g as ParsedGraphQLQuery, P as ParsedGraphQLRequest, p as parseDocumentNode, j as parseGraphQLRequest } from '../../GraphQLHandler-b42ca96f.js';
|
|
3
|
+
import '../../RequestHandler-1a5dbdc7.js';
|
|
4
|
+
import '../../typeUtils.js';
|
|
5
|
+
import '../matching/matchRequestUrl.js';
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __objRest = (source, exclude) => {
|
|
9
|
+
var target = {};
|
|
10
|
+
for (var prop in source)
|
|
11
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
12
|
+
target[prop] = source[prop];
|
|
13
|
+
if (source != null && __getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
15
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
16
|
+
target[prop] = source[prop];
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __export = (target, all) => {
|
|
21
|
+
for (var name in all)
|
|
22
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
+
};
|
|
24
|
+
var __copyProps = (to, from, except, desc) => {
|
|
25
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
+
for (let key of __getOwnPropNames(from))
|
|
27
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
+
}
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __async = (__this, __arguments, generator) => {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
var fulfilled = (value) => {
|
|
36
|
+
try {
|
|
37
|
+
step(generator.next(value));
|
|
38
|
+
} catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var rejected = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.throw(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
50
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
var parseGraphQLRequest_exports = {};
|
|
54
|
+
__export(parseGraphQLRequest_exports, {
|
|
55
|
+
parseDocumentNode: () => parseDocumentNode,
|
|
56
|
+
parseGraphQLRequest: () => parseGraphQLRequest
|
|
57
|
+
});
|
|
58
|
+
module.exports = __toCommonJS(parseGraphQLRequest_exports);
|
|
59
|
+
var import_graphql = require("graphql");
|
|
60
|
+
var import_getPublicUrlFromRequest = require("../request/getPublicUrlFromRequest.js");
|
|
61
|
+
var import_devUtils = require("./devUtils.js");
|
|
62
|
+
var import_jsonParse = require("./jsonParse.js");
|
|
63
|
+
var import_parseMultipartData = require("./parseMultipartData.js");
|
|
64
|
+
function parseDocumentNode(node) {
|
|
65
|
+
var _a;
|
|
66
|
+
const operationDef = node.definitions.find((definition) => {
|
|
67
|
+
return definition.kind === "OperationDefinition";
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
operationType: operationDef == null ? void 0 : operationDef.operation,
|
|
71
|
+
operationName: (_a = operationDef == null ? void 0 : operationDef.name) == null ? void 0 : _a.value
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function parseQuery(query) {
|
|
75
|
+
try {
|
|
76
|
+
const ast = (0, import_graphql.parse)(query);
|
|
77
|
+
return parseDocumentNode(ast);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function extractMultipartVariables(variables, map, files) {
|
|
83
|
+
const operations = { variables };
|
|
84
|
+
for (const [key, pathArray] of Object.entries(map)) {
|
|
85
|
+
if (!(key in files)) {
|
|
86
|
+
throw new Error(`Given files do not have a key '${key}' .`);
|
|
87
|
+
}
|
|
88
|
+
for (const dotPath of pathArray) {
|
|
89
|
+
const [lastPath, ...reversedPaths] = dotPath.split(".").reverse();
|
|
90
|
+
const paths = reversedPaths.reverse();
|
|
91
|
+
let target = operations;
|
|
92
|
+
for (const path of paths) {
|
|
93
|
+
if (!(path in target)) {
|
|
94
|
+
throw new Error(`Property '${paths}' is not in operations.`);
|
|
95
|
+
}
|
|
96
|
+
target = target[path];
|
|
97
|
+
}
|
|
98
|
+
target[lastPath] = files[key];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return operations.variables;
|
|
102
|
+
}
|
|
103
|
+
function getGraphQLInput(request) {
|
|
104
|
+
return __async(this, null, function* () {
|
|
105
|
+
var _a;
|
|
106
|
+
switch (request.method) {
|
|
107
|
+
case "GET": {
|
|
108
|
+
const url = new URL(request.url);
|
|
109
|
+
const query = url.searchParams.get("query");
|
|
110
|
+
const variables = url.searchParams.get("variables") || "";
|
|
111
|
+
return {
|
|
112
|
+
query,
|
|
113
|
+
variables: (0, import_jsonParse.jsonParse)(variables)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
case "POST": {
|
|
117
|
+
const requestClone = request.clone();
|
|
118
|
+
if ((_a = request.headers.get("content-type")) == null ? void 0 : _a.includes("multipart/form-data")) {
|
|
119
|
+
const responseJson = (0, import_parseMultipartData.parseMultipartData)(
|
|
120
|
+
yield requestClone.text(),
|
|
121
|
+
request.headers
|
|
122
|
+
);
|
|
123
|
+
if (!responseJson) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const _b = responseJson, { operations, map } = _b, files = __objRest(_b, ["operations", "map"]);
|
|
127
|
+
const parsedOperations = (0, import_jsonParse.jsonParse)(
|
|
128
|
+
operations
|
|
129
|
+
) || {};
|
|
130
|
+
if (!parsedOperations.query) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const parsedMap = (0, import_jsonParse.jsonParse)(map || "") || {};
|
|
134
|
+
const variables = parsedOperations.variables ? extractMultipartVariables(
|
|
135
|
+
parsedOperations.variables,
|
|
136
|
+
parsedMap,
|
|
137
|
+
files
|
|
138
|
+
) : {};
|
|
139
|
+
return {
|
|
140
|
+
query: parsedOperations.query,
|
|
141
|
+
variables
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const requestJson = yield requestClone.json().catch(() => null);
|
|
145
|
+
if (requestJson == null ? void 0 : requestJson.query) {
|
|
146
|
+
const { query, variables } = requestJson;
|
|
147
|
+
return {
|
|
148
|
+
query,
|
|
149
|
+
variables
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
default:
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function parseGraphQLRequest(request) {
|
|
159
|
+
return __async(this, null, function* () {
|
|
160
|
+
const input = yield getGraphQLInput(request);
|
|
161
|
+
if (!input || !input.query) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const { query, variables } = input;
|
|
165
|
+
const parsedResult = parseQuery(query);
|
|
166
|
+
if (parsedResult instanceof Error) {
|
|
167
|
+
const requestPublicUrl = (0, import_getPublicUrlFromRequest.getPublicUrlFromRequest)(request);
|
|
168
|
+
throw new Error(
|
|
169
|
+
import_devUtils.devUtils.formatMessage(
|
|
170
|
+
'Failed to intercept a GraphQL request to "%s %s": cannot parse query. See the error message from the parser below.\n\n%s',
|
|
171
|
+
request.method,
|
|
172
|
+
requestPublicUrl,
|
|
173
|
+
parsedResult.message
|
|
174
|
+
)
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
query: input.query,
|
|
179
|
+
operationType: parsedResult.operationType,
|
|
180
|
+
operationName: parsedResult.operationName,
|
|
181
|
+
variables
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var __objRest = (source, exclude) => {
|
|
5
|
+
var target = {};
|
|
6
|
+
for (var prop in source)
|
|
7
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
8
|
+
target[prop] = source[prop];
|
|
9
|
+
if (source != null && __getOwnPropSymbols)
|
|
10
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
11
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
12
|
+
target[prop] = source[prop];
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
var __async = (__this, __arguments, generator) => {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
var fulfilled = (value) => {
|
|
19
|
+
try {
|
|
20
|
+
step(generator.next(value));
|
|
21
|
+
} catch (e) {
|
|
22
|
+
reject(e);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var rejected = (value) => {
|
|
26
|
+
try {
|
|
27
|
+
step(generator.throw(value));
|
|
28
|
+
} catch (e) {
|
|
29
|
+
reject(e);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
33
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
import { parse } from "graphql";
|
|
37
|
+
import { getPublicUrlFromRequest } from '../request/getPublicUrlFromRequest.mjs';
|
|
38
|
+
import { devUtils } from './devUtils.mjs';
|
|
39
|
+
import { jsonParse } from './jsonParse.mjs';
|
|
40
|
+
import { parseMultipartData } from './parseMultipartData.mjs';
|
|
41
|
+
function parseDocumentNode(node) {
|
|
42
|
+
var _a;
|
|
43
|
+
const operationDef = node.definitions.find((definition) => {
|
|
44
|
+
return definition.kind === "OperationDefinition";
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
operationType: operationDef == null ? void 0 : operationDef.operation,
|
|
48
|
+
operationName: (_a = operationDef == null ? void 0 : operationDef.name) == null ? void 0 : _a.value
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function parseQuery(query) {
|
|
52
|
+
try {
|
|
53
|
+
const ast = parse(query);
|
|
54
|
+
return parseDocumentNode(ast);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
return error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function extractMultipartVariables(variables, map, files) {
|
|
60
|
+
const operations = { variables };
|
|
61
|
+
for (const [key, pathArray] of Object.entries(map)) {
|
|
62
|
+
if (!(key in files)) {
|
|
63
|
+
throw new Error(`Given files do not have a key '${key}' .`);
|
|
64
|
+
}
|
|
65
|
+
for (const dotPath of pathArray) {
|
|
66
|
+
const [lastPath, ...reversedPaths] = dotPath.split(".").reverse();
|
|
67
|
+
const paths = reversedPaths.reverse();
|
|
68
|
+
let target = operations;
|
|
69
|
+
for (const path of paths) {
|
|
70
|
+
if (!(path in target)) {
|
|
71
|
+
throw new Error(`Property '${paths}' is not in operations.`);
|
|
72
|
+
}
|
|
73
|
+
target = target[path];
|
|
74
|
+
}
|
|
75
|
+
target[lastPath] = files[key];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return operations.variables;
|
|
79
|
+
}
|
|
80
|
+
function getGraphQLInput(request) {
|
|
81
|
+
return __async(this, null, function* () {
|
|
82
|
+
var _a;
|
|
83
|
+
switch (request.method) {
|
|
84
|
+
case "GET": {
|
|
85
|
+
const url = new URL(request.url);
|
|
86
|
+
const query = url.searchParams.get("query");
|
|
87
|
+
const variables = url.searchParams.get("variables") || "";
|
|
88
|
+
return {
|
|
89
|
+
query,
|
|
90
|
+
variables: jsonParse(variables)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
case "POST": {
|
|
94
|
+
const requestClone = request.clone();
|
|
95
|
+
if ((_a = request.headers.get("content-type")) == null ? void 0 : _a.includes("multipart/form-data")) {
|
|
96
|
+
const responseJson = parseMultipartData(
|
|
97
|
+
yield requestClone.text(),
|
|
98
|
+
request.headers
|
|
99
|
+
);
|
|
100
|
+
if (!responseJson) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const _b = responseJson, { operations, map } = _b, files = __objRest(_b, ["operations", "map"]);
|
|
104
|
+
const parsedOperations = jsonParse(
|
|
105
|
+
operations
|
|
106
|
+
) || {};
|
|
107
|
+
if (!parsedOperations.query) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
const parsedMap = jsonParse(map || "") || {};
|
|
111
|
+
const variables = parsedOperations.variables ? extractMultipartVariables(
|
|
112
|
+
parsedOperations.variables,
|
|
113
|
+
parsedMap,
|
|
114
|
+
files
|
|
115
|
+
) : {};
|
|
116
|
+
return {
|
|
117
|
+
query: parsedOperations.query,
|
|
118
|
+
variables
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const requestJson = yield requestClone.json().catch(() => null);
|
|
122
|
+
if (requestJson == null ? void 0 : requestJson.query) {
|
|
123
|
+
const { query, variables } = requestJson;
|
|
124
|
+
return {
|
|
125
|
+
query,
|
|
126
|
+
variables
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function parseGraphQLRequest(request) {
|
|
136
|
+
return __async(this, null, function* () {
|
|
137
|
+
const input = yield getGraphQLInput(request);
|
|
138
|
+
if (!input || !input.query) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const { query, variables } = input;
|
|
142
|
+
const parsedResult = parseQuery(query);
|
|
143
|
+
if (parsedResult instanceof Error) {
|
|
144
|
+
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
145
|
+
throw new Error(
|
|
146
|
+
devUtils.formatMessage(
|
|
147
|
+
'Failed to intercept a GraphQL request to "%s %s": cannot parse query. See the error message from the parser below.\n\n%s',
|
|
148
|
+
request.method,
|
|
149
|
+
requestPublicUrl,
|
|
150
|
+
parsedResult.message
|
|
151
|
+
)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
query: input.query,
|
|
156
|
+
operationType: parsedResult.operationType,
|
|
157
|
+
operationName: parsedResult.operationName,
|
|
158
|
+
variables
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
export {
|
|
163
|
+
parseDocumentNode,
|
|
164
|
+
parseGraphQLRequest
|
|
165
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { d as DefaultRequestMultipartBody } from '../../RequestHandler-1a5dbdc7.js';
|
|
2
|
+
import '../../typeUtils.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parses a given string as a multipart/form-data.
|
|
6
|
+
* Does not throw an exception on an invalid multipart string.
|
|
7
|
+
*/
|
|
8
|
+
declare function parseMultipartData<T extends DefaultRequestMultipartBody>(data: string, headers?: Headers): T | undefined;
|
|
9
|
+
|
|
10
|
+
export { parseMultipartData };
|