msw 2.1.2 → 2.1.4
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 +5 -5
- package/lib/browser/index.js +1757 -27
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +1751 -23
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-2guuZL5R.d.ts → GraphQLHandler-eJejgV5u.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-fe5IYUg3.d.mts → GraphQLHandler-rZ7XkeDz.d.mts} +1 -1
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/{RequestHandler-TRh8Eh4H.d.ts → RequestHandler-CwjkprZE.d.ts} +8 -6
- package/lib/core/{RequestHandler-nfjVJ8Tp.d.mts → RequestHandler-MAVTMsma.d.mts} +8 -6
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/getResponse.d.mts +13 -0
- package/lib/core/getResponse.d.ts +13 -0
- package/lib/core/getResponse.js +34 -0
- package/lib/core/getResponse.js.map +1 -0
- package/lib/core/getResponse.mjs +14 -0
- package/lib/core/getResponse.mjs.map +1 -0
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +3 -2
- package/lib/core/index.d.ts +3 -2
- package/lib/core/index.js +2 -0
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +2 -0
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/sharedOptions.d.mts +0 -2
- package/lib/core/sharedOptions.d.ts +0 -2
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/executeHandlers.d.mts +2 -0
- package/lib/core/utils/executeHandlers.d.ts +2 -0
- package/lib/core/utils/{getResponse.js → executeHandlers.js} +6 -6
- package/lib/core/utils/executeHandlers.js.map +1 -0
- package/lib/core/utils/{getResponse.mjs → executeHandlers.mjs} +3 -3
- package/lib/core/utils/executeHandlers.mjs.map +1 -0
- package/lib/core/utils/handleRequest.d.mts +2 -2
- package/lib/core/utils/handleRequest.d.ts +2 -2
- package/lib/core/utils/handleRequest.js +3 -3
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs +3 -3
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/randomId.d.mts +3 -0
- package/lib/core/utils/internal/randomId.d.ts +3 -0
- package/lib/core/utils/internal/{uuidv4.js → randomId.js} +6 -6
- package/lib/core/utils/internal/randomId.js.map +1 -0
- package/lib/core/utils/internal/randomId.mjs +7 -0
- package/lib/core/utils/internal/randomId.mjs.map +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/request/onUnhandledRequest.d.mts +1 -4
- package/lib/core/utils/request/onUnhandledRequest.d.ts +1 -4
- package/lib/core/utils/request/onUnhandledRequest.js +9 -113
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +9 -105
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/iife/index.js +29 -216
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +1 -4
- package/src/core/getResponse.test.ts +63 -0
- package/src/core/getResponse.ts +23 -0
- package/src/core/handlers/GraphQLHandler.test.ts +4 -4
- package/src/core/handlers/HttpHandler.test.ts +5 -5
- package/src/core/handlers/HttpHandler.ts +1 -1
- package/src/core/handlers/RequestHandler.ts +1 -1
- package/src/core/index.ts +1 -0
- package/src/core/utils/{getResponse.ts → executeHandlers.ts} +7 -5
- package/src/core/utils/handleRequest.test.ts +14 -14
- package/src/core/utils/handleRequest.ts +5 -5
- package/src/core/utils/internal/{uuidv4.ts → randomId.ts} +1 -1
- package/src/core/utils/request/onUnhandledRequest.test.ts +5 -101
- package/src/core/utils/request/onUnhandledRequest.ts +3 -182
- package/lib/core/utils/getResponse.d.mts +0 -2
- package/lib/core/utils/getResponse.d.ts +0 -2
- package/lib/core/utils/getResponse.js.map +0 -1
- package/lib/core/utils/getResponse.mjs.map +0 -1
- package/lib/core/utils/internal/uuidv4.d.mts +0 -3
- package/lib/core/utils/internal/uuidv4.d.ts +0 -3
- package/lib/core/utils/internal/uuidv4.js.map +0 -1
- package/lib/core/utils/internal/uuidv4.mjs +0 -7
- package/lib/core/utils/internal/uuidv4.mjs.map +0 -1
|
@@ -1,113 +1,17 @@
|
|
|
1
|
-
import jsLevenshtein from "@bundled-es-modules/js-levenshtein";
|
|
2
|
-
import { HttpHandler, GraphQLHandler } from '../../index.mjs';
|
|
3
|
-
import {
|
|
4
|
-
parseGraphQLRequest
|
|
5
|
-
} from '../internal/parseGraphQLRequest.mjs';
|
|
6
1
|
import { getPublicUrlFromRequest } from './getPublicUrlFromRequest.mjs';
|
|
7
|
-
import { isStringEqual } from '../internal/isStringEqual.mjs';
|
|
8
2
|
import { devUtils } from '../internal/devUtils.mjs';
|
|
9
|
-
|
|
10
|
-
const MAX_MATCH_SCORE = 3;
|
|
11
|
-
const MAX_SUGGESTION_COUNT = 4;
|
|
12
|
-
const TYPE_MATCH_DELTA = 0.5;
|
|
13
|
-
function groupHandlersByType(handlers) {
|
|
14
|
-
return handlers.reduce(
|
|
15
|
-
(groups, handler) => {
|
|
16
|
-
if (handler instanceof HttpHandler) {
|
|
17
|
-
groups.http.push(handler);
|
|
18
|
-
}
|
|
19
|
-
if (handler instanceof GraphQLHandler) {
|
|
20
|
-
groups.graphql.push(handler);
|
|
21
|
-
}
|
|
22
|
-
return groups;
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
http: [],
|
|
26
|
-
graphql: []
|
|
27
|
-
}
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
function getHttpHandlerScore() {
|
|
31
|
-
return (request, handler) => {
|
|
32
|
-
const { path, method } = handler.info;
|
|
33
|
-
if (path instanceof RegExp || method instanceof RegExp) {
|
|
34
|
-
return Infinity;
|
|
35
|
-
}
|
|
36
|
-
const hasSameMethod = isStringEqual(request.method, method);
|
|
37
|
-
const methodScoreDelta = hasSameMethod ? TYPE_MATCH_DELTA : 0;
|
|
38
|
-
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
39
|
-
const score = getStringMatchScore(requestPublicUrl, path);
|
|
40
|
-
return score - methodScoreDelta;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function getGraphQLHandlerScore(parsedQuery) {
|
|
44
|
-
return (_, handler) => {
|
|
45
|
-
if (typeof parsedQuery.operationName === "undefined") {
|
|
46
|
-
return Infinity;
|
|
47
|
-
}
|
|
48
|
-
const { operationType, operationName } = handler.info;
|
|
49
|
-
if (typeof operationName !== "string") {
|
|
50
|
-
return Infinity;
|
|
51
|
-
}
|
|
52
|
-
const hasSameOperationType = parsedQuery.operationType === operationType;
|
|
53
|
-
const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0;
|
|
54
|
-
const score = getStringMatchScore(parsedQuery.operationName, operationName);
|
|
55
|
-
return score - operationTypeScoreDelta;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function getSuggestedHandler(request, handlers, getScore) {
|
|
59
|
-
const suggestedHandlers = handlers.reduce((suggestions, handler) => {
|
|
60
|
-
const score = getScore(request, handler);
|
|
61
|
-
return suggestions.concat([[score, handler]]);
|
|
62
|
-
}, []).sort(([leftScore], [rightScore]) => leftScore - rightScore).filter(([score]) => score <= MAX_MATCH_SCORE).slice(0, MAX_SUGGESTION_COUNT).map(([, handler]) => handler);
|
|
63
|
-
return suggestedHandlers;
|
|
64
|
-
}
|
|
65
|
-
function getSuggestedHandlersMessage(handlers) {
|
|
66
|
-
if (handlers.length > 1) {
|
|
67
|
-
return `Did you mean to request one of the following resources instead?
|
|
68
|
-
|
|
69
|
-
${handlers.map((handler) => ` \u2022 ${handler.info.header}`).join("\n")}`;
|
|
70
|
-
}
|
|
71
|
-
return `Did you mean to request "${handlers[0].info.header}" instead?`;
|
|
72
|
-
}
|
|
73
|
-
async function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
74
|
-
const parsedGraphQLQuery = await parseGraphQLRequest(request).catch(
|
|
75
|
-
() => null
|
|
76
|
-
);
|
|
3
|
+
async function onUnhandledRequest(request, strategy = "warn") {
|
|
77
4
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
parsedGraphQLQuery ? getGraphQLHandlerScore(parsedGraphQLQuery) : getHttpHandlerScore()
|
|
85
|
-
);
|
|
86
|
-
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
87
|
-
}
|
|
88
|
-
function getGraphQLRequestHeader(parsedGraphQLRequest) {
|
|
89
|
-
if (!parsedGraphQLRequest?.operationName) {
|
|
90
|
-
return `anonymous ${parsedGraphQLRequest?.operationType} (${request.method} ${publicUrl})`;
|
|
91
|
-
}
|
|
92
|
-
return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`;
|
|
93
|
-
}
|
|
94
|
-
function generateUnhandledRequestMessage() {
|
|
95
|
-
const requestHeader = parsedGraphQLQuery ? getGraphQLRequestHeader(parsedGraphQLQuery) : `${request.method} ${publicUrl}`;
|
|
96
|
-
const handlerSuggestion = generateHandlerSuggestion();
|
|
97
|
-
const messageTemplate = [
|
|
98
|
-
`intercepted a request without a matching request handler:`,
|
|
99
|
-
` \u2022 ${requestHeader}`,
|
|
100
|
-
handlerSuggestion,
|
|
101
|
-
`If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
102
|
-
Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
103
|
-
].filter(Boolean);
|
|
104
|
-
return messageTemplate.join("\n\n");
|
|
105
|
-
}
|
|
5
|
+
const unhandledRequestMessage = `intercepted a request without a matching request handler:
|
|
6
|
+
|
|
7
|
+
\u2022 ${request.method} ${publicUrl}
|
|
8
|
+
|
|
9
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
10
|
+
Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
106
11
|
function applyStrategy(strategy2) {
|
|
107
|
-
const message = generateUnhandledRequestMessage();
|
|
108
12
|
switch (strategy2) {
|
|
109
13
|
case "error": {
|
|
110
|
-
devUtils.error("Error: %s",
|
|
14
|
+
devUtils.error("Error: %s", unhandledRequestMessage);
|
|
111
15
|
throw new Error(
|
|
112
16
|
devUtils.formatMessage(
|
|
113
17
|
'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'
|
|
@@ -115,7 +19,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
115
19
|
);
|
|
116
20
|
}
|
|
117
21
|
case "warn": {
|
|
118
|
-
devUtils.warn("Warning: %s",
|
|
22
|
+
devUtils.warn("Warning: %s", unhandledRequestMessage);
|
|
119
23
|
break;
|
|
120
24
|
}
|
|
121
25
|
case "bypass":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/core/utils/request/onUnhandledRequest.ts"],"sourcesContent":["import jsLevenshtein from '@bundled-es-modules/js-levenshtein'\nimport { RequestHandler, HttpHandler, GraphQLHandler } from '../..'\nimport {\n ParsedGraphQLQuery,\n ParsedGraphQLRequest,\n parseGraphQLRequest,\n} from '../internal/parseGraphQLRequest'\nimport { getPublicUrlFromRequest } from './getPublicUrlFromRequest'\nimport { isStringEqual } from '../internal/isStringEqual'\nimport { devUtils } from '../internal/devUtils'\n\nconst getStringMatchScore = jsLevenshtein\n\nconst MAX_MATCH_SCORE = 3\nconst MAX_SUGGESTION_COUNT = 4\nconst TYPE_MATCH_DELTA = 0.5\n\nexport interface UnhandledRequestPrint {\n warning(): void\n error(): void\n}\n\nexport type UnhandledRequestCallback = (\n request: Request,\n print: UnhandledRequestPrint,\n) => void\n\nexport type UnhandledRequestStrategy =\n | 'bypass'\n | 'warn'\n | 'error'\n | UnhandledRequestCallback\n\ninterface RequestHandlerGroups {\n http: Array<HttpHandler>\n graphql: Array<GraphQLHandler>\n}\n\nfunction groupHandlersByType(\n handlers: Array<RequestHandler>,\n): RequestHandlerGroups {\n return handlers.reduce<RequestHandlerGroups>(\n (groups, handler) => {\n if (handler instanceof HttpHandler) {\n groups.http.push(handler)\n }\n\n if (handler instanceof GraphQLHandler) {\n groups.graphql.push(handler)\n }\n\n return groups\n },\n {\n http: [],\n graphql: [],\n },\n )\n}\n\ntype RequestHandlerSuggestion = [number, RequestHandler]\n\ntype ScoreGetterFn<RequestHandlerType extends RequestHandler> = (\n request: Request,\n handler: RequestHandlerType,\n) => number\n\nfunction getHttpHandlerScore(): ScoreGetterFn<HttpHandler> {\n return (request, handler) => {\n const { path, method } = handler.info\n\n if (path instanceof RegExp || method instanceof RegExp) {\n return Infinity\n }\n\n const hasSameMethod = isStringEqual(request.method, method)\n\n // Always treat a handler with the same method as a more similar one.\n const methodScoreDelta = hasSameMethod ? TYPE_MATCH_DELTA : 0\n const requestPublicUrl = getPublicUrlFromRequest(request)\n const score = getStringMatchScore(requestPublicUrl, path)\n\n return score - methodScoreDelta\n }\n}\n\nfunction getGraphQLHandlerScore(\n parsedQuery: ParsedGraphQLQuery,\n): ScoreGetterFn<GraphQLHandler> {\n return (_, handler) => {\n if (typeof parsedQuery.operationName === 'undefined') {\n return Infinity\n }\n\n const { operationType, operationName } = handler.info\n\n if (typeof operationName !== 'string') {\n return Infinity\n }\n\n const hasSameOperationType = parsedQuery.operationType === operationType\n // Always treat a handler with the same operation type as a more similar one.\n const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0\n const score = getStringMatchScore(parsedQuery.operationName, operationName)\n\n return score - operationTypeScoreDelta\n }\n}\n\nfunction getSuggestedHandler(\n request: Request,\n handlers: Array<HttpHandler> | Array<GraphQLHandler>,\n getScore: ScoreGetterFn<HttpHandler> | ScoreGetterFn<GraphQLHandler>,\n): Array<RequestHandler> {\n const suggestedHandlers = (handlers as Array<RequestHandler>)\n .reduce<Array<RequestHandlerSuggestion>>((suggestions, handler) => {\n const score = getScore(request, handler as any)\n return suggestions.concat([[score, handler]])\n }, [])\n .sort(([leftScore], [rightScore]) => leftScore - rightScore)\n .filter(([score]) => score <= MAX_MATCH_SCORE)\n .slice(0, MAX_SUGGESTION_COUNT)\n .map(([, handler]) => handler)\n\n return suggestedHandlers\n}\n\nfunction getSuggestedHandlersMessage(handlers: RequestHandler[]) {\n if (handlers.length > 1) {\n return `\\\nDid you mean to request one of the following resources instead?\n\n${handlers.map((handler) => ` • ${handler.info.header}`).join('\\n')}`\n }\n\n return `Did you mean to request \"${handlers[0].info.header}\" instead?`\n}\n\nexport async function onUnhandledRequest(\n request: Request,\n handlers: Array<RequestHandler>,\n strategy: UnhandledRequestStrategy = 'warn',\n): Promise<void> {\n const parsedGraphQLQuery = await parseGraphQLRequest(request).catch(\n () => null,\n )\n const publicUrl = getPublicUrlFromRequest(request)\n\n function generateHandlerSuggestion(): string {\n /**\n * @note Ignore exceptions during GraphQL request parsing because at this point\n * we cannot assume the unhandled request is a valid GraphQL request.\n * If the GraphQL parsing fails, just don't treat it as a GraphQL request.\n */\n const handlerGroups = groupHandlersByType(handlers)\n const relevantHandlers = parsedGraphQLQuery\n ? handlerGroups.graphql\n : handlerGroups.http\n\n const suggestedHandlers = getSuggestedHandler(\n request,\n relevantHandlers,\n parsedGraphQLQuery\n ? getGraphQLHandlerScore(parsedGraphQLQuery)\n : getHttpHandlerScore(),\n )\n\n return suggestedHandlers.length > 0\n ? getSuggestedHandlersMessage(suggestedHandlers)\n : ''\n }\n\n function getGraphQLRequestHeader(\n parsedGraphQLRequest: ParsedGraphQLRequest<any>,\n ): string {\n if (!parsedGraphQLRequest?.operationName) {\n return `anonymous ${parsedGraphQLRequest?.operationType} (${request.method} ${publicUrl})`\n }\n\n return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`\n }\n\n function generateUnhandledRequestMessage(): string {\n const requestHeader = parsedGraphQLQuery\n ? getGraphQLRequestHeader(parsedGraphQLQuery)\n : `${request.method} ${publicUrl}`\n const handlerSuggestion = generateHandlerSuggestion()\n\n const messageTemplate = [\n `intercepted a request without a matching request handler:`,\n ` \\u2022 ${requestHeader}`,\n handlerSuggestion,\n `\\\nIf you still wish to intercept this unhandled request, please create a request handler for it.\nRead more: https://mswjs.io/docs/getting-started/mocks\\\n`,\n ].filter(Boolean)\n return messageTemplate.join('\\n\\n')\n }\n\n function applyStrategy(strategy: UnhandledRequestStrategy) {\n // Generate handler suggestions only when applying the strategy.\n // This saves bandwidth for scenarios when developers opt-out\n // from the default unhandled request handling strategy.\n const message = generateUnhandledRequestMessage()\n\n switch (strategy) {\n case 'error': {\n // Print a developer-friendly error.\n devUtils.error('Error: %s', message)\n\n // Throw an exception to halt request processing and not perform the original request.\n throw new Error(\n devUtils.formatMessage(\n 'Cannot bypass a request when using the \"error\" strategy for the \"onUnhandledRequest\" option.',\n ),\n )\n }\n\n case 'warn': {\n devUtils.warn('Warning: %s', message)\n break\n }\n\n case 'bypass':\n break\n\n default:\n throw new Error(\n devUtils.formatMessage(\n 'Failed to react to an unhandled request: unknown strategy \"%s\". Please provide one of the supported strategies (\"bypass\", \"warn\", \"error\") or a custom callback function as the value of the \"onUnhandledRequest\" option.',\n strategy,\n ),\n )\n }\n }\n\n if (typeof strategy === 'function') {\n strategy(request, {\n warning: applyStrategy.bind(null, 'warn'),\n error: applyStrategy.bind(null, 'error'),\n })\n return\n }\n\n applyStrategy(strategy)\n}\n"],"mappings":"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","names":["strategy"]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/utils/request/onUnhandledRequest.ts"],"sourcesContent":["import { getPublicUrlFromRequest } from './getPublicUrlFromRequest'\nimport { devUtils } from '../internal/devUtils'\n\nexport interface UnhandledRequestPrint {\n warning(): void\n error(): void\n}\n\nexport type UnhandledRequestCallback = (\n request: Request,\n print: UnhandledRequestPrint,\n) => void\n\nexport type UnhandledRequestStrategy =\n | 'bypass'\n | 'warn'\n | 'error'\n | UnhandledRequestCallback\n\nexport async function onUnhandledRequest(\n request: Request,\n strategy: UnhandledRequestStrategy = 'warn',\n): Promise<void> {\n const publicUrl = getPublicUrlFromRequest(request)\n const unhandledRequestMessage = `intercepted a request without a matching request handler:\\n\\n \\u2022 ${request.method} ${publicUrl}\\n\\nIf you still wish to intercept this unhandled request, please create a request handler for it.\\nRead more: https://mswjs.io/docs/getting-started/mocks`\n\n function applyStrategy(strategy: UnhandledRequestStrategy) {\n switch (strategy) {\n case 'error': {\n // Print a developer-friendly error.\n devUtils.error('Error: %s', unhandledRequestMessage)\n\n // Throw an exception to halt request processing and not perform the original request.\n throw new Error(\n devUtils.formatMessage(\n 'Cannot bypass a request when using the \"error\" strategy for the \"onUnhandledRequest\" option.',\n ),\n )\n }\n\n case 'warn': {\n devUtils.warn('Warning: %s', unhandledRequestMessage)\n break\n }\n\n case 'bypass':\n break\n\n default:\n throw new Error(\n devUtils.formatMessage(\n 'Failed to react to an unhandled request: unknown strategy \"%s\". Please provide one of the supported strategies (\"bypass\", \"warn\", \"error\") or a custom callback function as the value of the \"onUnhandledRequest\" option.',\n strategy,\n ),\n )\n }\n }\n\n if (typeof strategy === 'function') {\n strategy(request, {\n warning: applyStrategy.bind(null, 'warn'),\n error: applyStrategy.bind(null, 'error'),\n })\n return\n }\n\n applyStrategy(strategy)\n}\n"],"mappings":"AAAA,SAAS,+BAA+B;AACxC,SAAS,gBAAgB;AAkBzB,eAAsB,mBACpB,SACA,WAAqC,QACtB;AACf,QAAM,YAAY,wBAAwB,OAAO;AACjD,QAAM,0BAA0B;AAAA;AAAA,WAAyE,QAAQ,MAAM,IAAI,SAAS;AAAA;AAAA;AAAA;AAEpI,WAAS,cAAcA,WAAoC;AACzD,YAAQA,WAAU;AAAA,MAChB,KAAK,SAAS;AAEZ,iBAAS,MAAM,aAAa,uBAAuB;AAGnD,cAAM,IAAI;AAAA,UACR,SAAS;AAAA,YACP;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MAEA,KAAK,QAAQ;AACX,iBAAS,KAAK,eAAe,uBAAuB;AACpD;AAAA,MACF;AAAA,MAEA,KAAK;AACH;AAAA,MAEF;AACE,cAAM,IAAI;AAAA,UACR,SAAS;AAAA,YACP;AAAA,YACAA;AAAA,UACF;AAAA,QACF;AAAA,IACJ;AAAA,EACF;AAEA,MAAI,OAAO,aAAa,YAAY;AAClC,aAAS,SAAS;AAAA,MAChB,SAAS,cAAc,KAAK,MAAM,MAAM;AAAA,MACxC,OAAO,cAAc,KAAK,MAAM,OAAO;AAAA,IACzC,CAAC;AACD;AAAA,EACF;AAEA,gBAAc,QAAQ;AACxB;","names":["strategy"]}
|
package/lib/iife/index.js
CHANGED
|
@@ -35,6 +35,7 @@ var MockServiceWorker = (() => {
|
|
|
35
35
|
bypass: () => bypass,
|
|
36
36
|
cleanUrl: () => cleanUrl,
|
|
37
37
|
delay: () => delay,
|
|
38
|
+
getResponse: () => getResponse,
|
|
38
39
|
graphql: () => graphql,
|
|
39
40
|
handleRequest: () => handleRequest,
|
|
40
41
|
http: () => http,
|
|
@@ -5604,8 +5605,8 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5604
5605
|
}
|
|
5605
5606
|
};
|
|
5606
5607
|
|
|
5607
|
-
// src/core/utils/
|
|
5608
|
-
var
|
|
5608
|
+
// src/core/utils/executeHandlers.ts
|
|
5609
|
+
var executeHandlers = async ({
|
|
5609
5610
|
request,
|
|
5610
5611
|
requestId,
|
|
5611
5612
|
handlers,
|
|
@@ -5632,222 +5633,19 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5632
5633
|
return null;
|
|
5633
5634
|
};
|
|
5634
5635
|
|
|
5635
|
-
// node_modules/.pnpm/@bundled-es-modules+js-levenshtein@2.0.1/node_modules/@bundled-es-modules/js-levenshtein/index-esm.js
|
|
5636
|
-
var __create5 = Object.create;
|
|
5637
|
-
var __defProp7 = Object.defineProperty;
|
|
5638
|
-
var __getOwnPropDesc6 = Object.getOwnPropertyDescriptor;
|
|
5639
|
-
var __getOwnPropNames6 = Object.getOwnPropertyNames;
|
|
5640
|
-
var __getProtoOf5 = Object.getPrototypeOf;
|
|
5641
|
-
var __hasOwnProp6 = Object.prototype.hasOwnProperty;
|
|
5642
|
-
var __commonJS5 = (cb, mod) => function __require() {
|
|
5643
|
-
return mod || (0, cb[__getOwnPropNames6(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
5644
|
-
};
|
|
5645
|
-
var __copyProps6 = (to, from, except, desc) => {
|
|
5646
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
5647
|
-
for (let key of __getOwnPropNames6(from))
|
|
5648
|
-
if (!__hasOwnProp6.call(to, key) && key !== except)
|
|
5649
|
-
__defProp7(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc6(from, key)) || desc.enumerable });
|
|
5650
|
-
}
|
|
5651
|
-
return to;
|
|
5652
|
-
};
|
|
5653
|
-
var __toESM5 = (mod, isNodeMode, target) => (target = mod != null ? __create5(__getProtoOf5(mod)) : {}, __copyProps6(
|
|
5654
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
5655
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
5656
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
5657
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
5658
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp7(target, "default", { value: mod, enumerable: true }) : target,
|
|
5659
|
-
mod
|
|
5660
|
-
));
|
|
5661
|
-
var require_js_levenshtein = __commonJS5({
|
|
5662
|
-
"node_modules/js-levenshtein/index.js"(exports, module) {
|
|
5663
|
-
"use strict";
|
|
5664
|
-
module.exports = /* @__PURE__ */ function() {
|
|
5665
|
-
function _min(d0, d1, d2, bx, ay) {
|
|
5666
|
-
return d0 < d1 || d2 < d1 ? d0 > d2 ? d2 + 1 : d0 + 1 : bx === ay ? d1 : d1 + 1;
|
|
5667
|
-
}
|
|
5668
|
-
return function(a, b) {
|
|
5669
|
-
if (a === b) {
|
|
5670
|
-
return 0;
|
|
5671
|
-
}
|
|
5672
|
-
if (a.length > b.length) {
|
|
5673
|
-
var tmp = a;
|
|
5674
|
-
a = b;
|
|
5675
|
-
b = tmp;
|
|
5676
|
-
}
|
|
5677
|
-
var la = a.length;
|
|
5678
|
-
var lb = b.length;
|
|
5679
|
-
while (la > 0 && a.charCodeAt(la - 1) === b.charCodeAt(lb - 1)) {
|
|
5680
|
-
la--;
|
|
5681
|
-
lb--;
|
|
5682
|
-
}
|
|
5683
|
-
var offset = 0;
|
|
5684
|
-
while (offset < la && a.charCodeAt(offset) === b.charCodeAt(offset)) {
|
|
5685
|
-
offset++;
|
|
5686
|
-
}
|
|
5687
|
-
la -= offset;
|
|
5688
|
-
lb -= offset;
|
|
5689
|
-
if (la === 0 || lb < 3) {
|
|
5690
|
-
return lb;
|
|
5691
|
-
}
|
|
5692
|
-
var x = 0;
|
|
5693
|
-
var y;
|
|
5694
|
-
var d0;
|
|
5695
|
-
var d1;
|
|
5696
|
-
var d2;
|
|
5697
|
-
var d3;
|
|
5698
|
-
var dd;
|
|
5699
|
-
var dy;
|
|
5700
|
-
var ay;
|
|
5701
|
-
var bx0;
|
|
5702
|
-
var bx1;
|
|
5703
|
-
var bx2;
|
|
5704
|
-
var bx3;
|
|
5705
|
-
var vector = [];
|
|
5706
|
-
for (y = 0; y < la; y++) {
|
|
5707
|
-
vector.push(y + 1);
|
|
5708
|
-
vector.push(a.charCodeAt(offset + y));
|
|
5709
|
-
}
|
|
5710
|
-
var len = vector.length - 1;
|
|
5711
|
-
for (; x < lb - 3; ) {
|
|
5712
|
-
bx0 = b.charCodeAt(offset + (d0 = x));
|
|
5713
|
-
bx1 = b.charCodeAt(offset + (d1 = x + 1));
|
|
5714
|
-
bx2 = b.charCodeAt(offset + (d2 = x + 2));
|
|
5715
|
-
bx3 = b.charCodeAt(offset + (d3 = x + 3));
|
|
5716
|
-
dd = x += 4;
|
|
5717
|
-
for (y = 0; y < len; y += 2) {
|
|
5718
|
-
dy = vector[y];
|
|
5719
|
-
ay = vector[y + 1];
|
|
5720
|
-
d0 = _min(dy, d0, d1, bx0, ay);
|
|
5721
|
-
d1 = _min(d0, d1, d2, bx1, ay);
|
|
5722
|
-
d2 = _min(d1, d2, d3, bx2, ay);
|
|
5723
|
-
dd = _min(d2, d3, dd, bx3, ay);
|
|
5724
|
-
vector[y] = dd;
|
|
5725
|
-
d3 = d2;
|
|
5726
|
-
d2 = d1;
|
|
5727
|
-
d1 = d0;
|
|
5728
|
-
d0 = dy;
|
|
5729
|
-
}
|
|
5730
|
-
}
|
|
5731
|
-
for (; x < lb; ) {
|
|
5732
|
-
bx0 = b.charCodeAt(offset + (d0 = x));
|
|
5733
|
-
dd = ++x;
|
|
5734
|
-
for (y = 0; y < len; y += 2) {
|
|
5735
|
-
dy = vector[y];
|
|
5736
|
-
vector[y] = dd = _min(dy, d0, dd, bx0, vector[y + 1]);
|
|
5737
|
-
d0 = dy;
|
|
5738
|
-
}
|
|
5739
|
-
}
|
|
5740
|
-
return dd;
|
|
5741
|
-
};
|
|
5742
|
-
}();
|
|
5743
|
-
}
|
|
5744
|
-
});
|
|
5745
|
-
var import_js_levenshtein = __toESM5(require_js_levenshtein(), 1);
|
|
5746
|
-
var source_default3 = import_js_levenshtein.default;
|
|
5747
|
-
|
|
5748
5636
|
// src/core/utils/request/onUnhandledRequest.ts
|
|
5749
|
-
|
|
5750
|
-
var MAX_MATCH_SCORE = 3;
|
|
5751
|
-
var MAX_SUGGESTION_COUNT = 4;
|
|
5752
|
-
var TYPE_MATCH_DELTA = 0.5;
|
|
5753
|
-
function groupHandlersByType(handlers) {
|
|
5754
|
-
return handlers.reduce(
|
|
5755
|
-
(groups, handler) => {
|
|
5756
|
-
if (handler instanceof HttpHandler) {
|
|
5757
|
-
groups.http.push(handler);
|
|
5758
|
-
}
|
|
5759
|
-
if (handler instanceof GraphQLHandler) {
|
|
5760
|
-
groups.graphql.push(handler);
|
|
5761
|
-
}
|
|
5762
|
-
return groups;
|
|
5763
|
-
},
|
|
5764
|
-
{
|
|
5765
|
-
http: [],
|
|
5766
|
-
graphql: []
|
|
5767
|
-
}
|
|
5768
|
-
);
|
|
5769
|
-
}
|
|
5770
|
-
function getHttpHandlerScore() {
|
|
5771
|
-
return (request, handler) => {
|
|
5772
|
-
const { path, method } = handler.info;
|
|
5773
|
-
if (path instanceof RegExp || method instanceof RegExp) {
|
|
5774
|
-
return Infinity;
|
|
5775
|
-
}
|
|
5776
|
-
const hasSameMethod = isStringEqual(request.method, method);
|
|
5777
|
-
const methodScoreDelta = hasSameMethod ? TYPE_MATCH_DELTA : 0;
|
|
5778
|
-
const requestPublicUrl = getPublicUrlFromRequest(request);
|
|
5779
|
-
const score = getStringMatchScore(requestPublicUrl, path);
|
|
5780
|
-
return score - methodScoreDelta;
|
|
5781
|
-
};
|
|
5782
|
-
}
|
|
5783
|
-
function getGraphQLHandlerScore(parsedQuery) {
|
|
5784
|
-
return (_, handler) => {
|
|
5785
|
-
if (typeof parsedQuery.operationName === "undefined") {
|
|
5786
|
-
return Infinity;
|
|
5787
|
-
}
|
|
5788
|
-
const { operationType, operationName } = handler.info;
|
|
5789
|
-
if (typeof operationName !== "string") {
|
|
5790
|
-
return Infinity;
|
|
5791
|
-
}
|
|
5792
|
-
const hasSameOperationType = parsedQuery.operationType === operationType;
|
|
5793
|
-
const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0;
|
|
5794
|
-
const score = getStringMatchScore(parsedQuery.operationName, operationName);
|
|
5795
|
-
return score - operationTypeScoreDelta;
|
|
5796
|
-
};
|
|
5797
|
-
}
|
|
5798
|
-
function getSuggestedHandler(request, handlers, getScore) {
|
|
5799
|
-
const suggestedHandlers = handlers.reduce((suggestions, handler) => {
|
|
5800
|
-
const score = getScore(request, handler);
|
|
5801
|
-
return suggestions.concat([[score, handler]]);
|
|
5802
|
-
}, []).sort(([leftScore], [rightScore]) => leftScore - rightScore).filter(([score]) => score <= MAX_MATCH_SCORE).slice(0, MAX_SUGGESTION_COUNT).map(([, handler]) => handler);
|
|
5803
|
-
return suggestedHandlers;
|
|
5804
|
-
}
|
|
5805
|
-
function getSuggestedHandlersMessage(handlers) {
|
|
5806
|
-
if (handlers.length > 1) {
|
|
5807
|
-
return `Did you mean to request one of the following resources instead?
|
|
5808
|
-
|
|
5809
|
-
${handlers.map((handler) => ` \u2022 ${handler.info.header}`).join("\n")}`;
|
|
5810
|
-
}
|
|
5811
|
-
return `Did you mean to request "${handlers[0].info.header}" instead?`;
|
|
5812
|
-
}
|
|
5813
|
-
async function onUnhandledRequest(request, handlers, strategy = "warn") {
|
|
5814
|
-
const parsedGraphQLQuery = await parseGraphQLRequest(request).catch(
|
|
5815
|
-
() => null
|
|
5816
|
-
);
|
|
5637
|
+
async function onUnhandledRequest(request, strategy = "warn") {
|
|
5817
5638
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
parsedGraphQLQuery ? getGraphQLHandlerScore(parsedGraphQLQuery) : getHttpHandlerScore()
|
|
5825
|
-
);
|
|
5826
|
-
return suggestedHandlers.length > 0 ? getSuggestedHandlersMessage(suggestedHandlers) : "";
|
|
5827
|
-
}
|
|
5828
|
-
function getGraphQLRequestHeader(parsedGraphQLRequest) {
|
|
5829
|
-
if (!parsedGraphQLRequest?.operationName) {
|
|
5830
|
-
return `anonymous ${parsedGraphQLRequest?.operationType} (${request.method} ${publicUrl})`;
|
|
5831
|
-
}
|
|
5832
|
-
return `${parsedGraphQLRequest.operationType} ${parsedGraphQLRequest.operationName} (${request.method} ${publicUrl})`;
|
|
5833
|
-
}
|
|
5834
|
-
function generateUnhandledRequestMessage() {
|
|
5835
|
-
const requestHeader = parsedGraphQLQuery ? getGraphQLRequestHeader(parsedGraphQLQuery) : `${request.method} ${publicUrl}`;
|
|
5836
|
-
const handlerSuggestion = generateHandlerSuggestion();
|
|
5837
|
-
const messageTemplate = [
|
|
5838
|
-
`intercepted a request without a matching request handler:`,
|
|
5839
|
-
` \u2022 ${requestHeader}`,
|
|
5840
|
-
handlerSuggestion,
|
|
5841
|
-
`If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
5842
|
-
Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
5843
|
-
].filter(Boolean);
|
|
5844
|
-
return messageTemplate.join("\n\n");
|
|
5845
|
-
}
|
|
5639
|
+
const unhandledRequestMessage = `intercepted a request without a matching request handler:
|
|
5640
|
+
|
|
5641
|
+
\u2022 ${request.method} ${publicUrl}
|
|
5642
|
+
|
|
5643
|
+
If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
5644
|
+
Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
5846
5645
|
function applyStrategy(strategy2) {
|
|
5847
|
-
const message3 = generateUnhandledRequestMessage();
|
|
5848
5646
|
switch (strategy2) {
|
|
5849
5647
|
case "error": {
|
|
5850
|
-
devUtils.error("Error: %s",
|
|
5648
|
+
devUtils.error("Error: %s", unhandledRequestMessage);
|
|
5851
5649
|
throw new Error(
|
|
5852
5650
|
devUtils.formatMessage(
|
|
5853
5651
|
'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'
|
|
@@ -5855,7 +5653,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5855
5653
|
);
|
|
5856
5654
|
}
|
|
5857
5655
|
case "warn": {
|
|
5858
|
-
devUtils.warn("Warning: %s",
|
|
5656
|
+
devUtils.warn("Warning: %s", unhandledRequestMessage);
|
|
5859
5657
|
break;
|
|
5860
5658
|
}
|
|
5861
5659
|
case "bypass":
|
|
@@ -5894,7 +5692,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5894
5692
|
return;
|
|
5895
5693
|
}
|
|
5896
5694
|
const lookupResult = await until(() => {
|
|
5897
|
-
return
|
|
5695
|
+
return executeHandlers({
|
|
5898
5696
|
request,
|
|
5899
5697
|
requestId,
|
|
5900
5698
|
handlers,
|
|
@@ -5910,7 +5708,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5910
5708
|
throw lookupResult.error;
|
|
5911
5709
|
}
|
|
5912
5710
|
if (!lookupResult.data) {
|
|
5913
|
-
await onUnhandledRequest(request,
|
|
5711
|
+
await onUnhandledRequest(request, options.onUnhandledRequest);
|
|
5914
5712
|
emitter.emit("request:unhandled", { request, requestId });
|
|
5915
5713
|
emitter.emit("request:end", { request, requestId });
|
|
5916
5714
|
handleRequestOptions?.onPassthroughResponse?.(request);
|
|
@@ -5939,6 +5737,21 @@ Read more: https://mswjs.io/docs/getting-started/mocks`
|
|
|
5939
5737
|
return transformedResponse;
|
|
5940
5738
|
}
|
|
5941
5739
|
|
|
5740
|
+
// src/core/utils/internal/randomId.ts
|
|
5741
|
+
function randomId() {
|
|
5742
|
+
return Math.random().toString(16).slice(2);
|
|
5743
|
+
}
|
|
5744
|
+
|
|
5745
|
+
// src/core/getResponse.ts
|
|
5746
|
+
var getResponse = async (handlers, request) => {
|
|
5747
|
+
const result = await executeHandlers({
|
|
5748
|
+
request,
|
|
5749
|
+
requestId: randomId(),
|
|
5750
|
+
handlers
|
|
5751
|
+
});
|
|
5752
|
+
return result?.response;
|
|
5753
|
+
};
|
|
5754
|
+
|
|
5942
5755
|
// src/core/utils/HttpResponse/decorators.ts
|
|
5943
5756
|
var { message: message2 } = source_default;
|
|
5944
5757
|
function normalizeResponseInit(init = {}) {
|