msw 0.35.0 → 0.36.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/RequestHandler-deps.js +387 -65
- package/lib/esm/errors-deps.js +15 -1
- package/lib/esm/fetch-deps.js +9 -5
- package/lib/esm/graphql-deps.js +14 -9
- package/lib/esm/graphql.js +1 -0
- package/lib/esm/index-deps.js +2 -1
- package/lib/esm/index.js +61 -4263
- package/lib/esm/index2.js +1 -1
- package/lib/esm/mockServiceWorker.js +5 -5
- package/lib/esm/rest-deps.js +7 -15
- package/lib/esm/rest.js +1 -0
- package/lib/iife/index.js +2 -2
- package/lib/iife/mockServiceWorker.js +5 -5
- package/lib/types/context/data.d.ts +2 -3
- package/lib/types/context/extensions.d.ts +8 -0
- package/lib/types/context/index.d.ts +1 -0
- package/lib/types/graphql.d.ts +2 -1
- package/lib/types/handlers/GraphQLHandler.d.ts +7 -6
- package/lib/types/handlers/RequestHandler.d.ts +8 -8
- package/lib/types/handlers/RestHandler.d.ts +10 -12
- package/lib/types/index.d.ts +17 -7
- package/lib/types/native/index.d.ts +1 -1
- package/lib/types/node/index.d.ts +1 -1
- package/lib/types/node/setupServer.d.ts +1 -1
- package/lib/types/rest.d.ts +10 -9
- package/lib/types/setupWorker/glossary.d.ts +12 -12
- package/lib/types/setupWorker/start/utils/prepareStartHandler.d.ts +3 -3
- package/lib/types/sharedOptions.d.ts +1 -1
- package/lib/types/typeUtils.d.ts +5 -3
- package/lib/types/utils/getResponse.d.ts +1 -1
- package/lib/types/utils/handleRequest.d.ts +5 -5
- package/lib/types/utils/internal/getCallFrame.d.ts +1 -1
- package/lib/types/utils/internal/jsonParse.d.ts +2 -2
- package/lib/types/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/types/utils/logging/prepareResponse.d.ts +1 -1
- package/lib/types/utils/matching/matchRequestUrl.d.ts +12 -2
- package/lib/types/utils/matching/normalizePath.d.ts +1 -1
- package/lib/types/utils/request/onUnhandledRequest.d.ts +1 -2
- package/lib/types/utils/request/parseBody.d.ts +2 -2
- package/lib/types/utils/request/parseWorkerRequest.d.ts +2 -2
- package/lib/types/utils/worker/createFallbackRequestListener.d.ts +2 -1
- package/lib/types/utils/worker/createRequestListener.d.ts +2 -1
- package/lib/umd/index.js +547 -134
- package/lib/umd/mockServiceWorker.js +5 -5
- package/native/lib/index.js +474 -517
- package/node/lib/index.js +476 -519
- package/package.json +19 -19
package/node/lib/index.js
CHANGED
|
@@ -8,7 +8,9 @@ var require$$0 = require('os');
|
|
|
8
8
|
var require$$1 = require('tty');
|
|
9
9
|
var require$$0$1 = require('events');
|
|
10
10
|
var interceptors = require('@mswjs/interceptors');
|
|
11
|
+
var cookies = require('@mswjs/cookies');
|
|
11
12
|
var timers = require('timers');
|
|
13
|
+
var getCleanUrl = require('@mswjs/interceptors/lib/utils/getCleanUrl');
|
|
12
14
|
|
|
13
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
16
|
|
|
@@ -1400,8 +1402,8 @@ var hasFlag$1 = (flag, argv = process.argv) => {
|
|
|
1400
1402
|
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
1401
1403
|
};
|
|
1402
1404
|
|
|
1403
|
-
const os = require$$0__default[
|
|
1404
|
-
const tty = require$$1__default[
|
|
1405
|
+
const os = require$$0__default["default"];
|
|
1406
|
+
const tty = require$$1__default["default"];
|
|
1405
1407
|
const hasFlag = hasFlag$1;
|
|
1406
1408
|
|
|
1407
1409
|
const {env} = process;
|
|
@@ -1936,7 +1938,7 @@ chalk.stderr.supportsColor = stderrColor;
|
|
|
1936
1938
|
|
|
1937
1939
|
var source = chalk;
|
|
1938
1940
|
|
|
1939
|
-
var lib$
|
|
1941
|
+
var lib$3 = {exports: {}};
|
|
1940
1942
|
|
|
1941
1943
|
(function (module, exports) {
|
|
1942
1944
|
(function (global, factory) {
|
|
@@ -1959,9 +1961,9 @@ var lib$4 = {exports: {}};
|
|
|
1959
1961
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1960
1962
|
|
|
1961
1963
|
})));
|
|
1962
|
-
}(lib$
|
|
1964
|
+
}(lib$3, lib$3.exports));
|
|
1963
1965
|
|
|
1964
|
-
var lib$
|
|
1966
|
+
var lib$2 = {};
|
|
1965
1967
|
|
|
1966
1968
|
var StrictEventEmitter$1 = {};
|
|
1967
1969
|
|
|
@@ -1987,7 +1989,7 @@ var __spreadArrays = (commonjsGlobal && commonjsGlobal.__spreadArrays) || functi
|
|
|
1987
1989
|
};
|
|
1988
1990
|
StrictEventEmitter$1.__esModule = true;
|
|
1989
1991
|
StrictEventEmitter$1.StrictEventEmitter = void 0;
|
|
1990
|
-
var events_1 = require$$0__default$1[
|
|
1992
|
+
var events_1 = require$$0__default$1["default"];
|
|
1991
1993
|
var StrictEventEmitter = /** @class */ (function (_super) {
|
|
1992
1994
|
__extends$1(StrictEventEmitter, _super);
|
|
1993
1995
|
function StrictEventEmitter() {
|
|
@@ -2031,7 +2033,7 @@ exports.__esModule = true;
|
|
|
2031
2033
|
exports.StrictEventEmitter = void 0;
|
|
2032
2034
|
var StrictEventEmitter_1 = StrictEventEmitter$1;
|
|
2033
2035
|
__createBinding(exports, StrictEventEmitter_1, "StrictEventEmitter");
|
|
2034
|
-
}(lib$
|
|
2036
|
+
}(lib$2));
|
|
2035
2037
|
|
|
2036
2038
|
function use(currentHandlers, ...handlers) {
|
|
2037
2039
|
currentHandlers.unshift(...handlers);
|
|
@@ -2246,28 +2248,20 @@ function tryDecode(str, decode) {
|
|
|
2246
2248
|
}
|
|
2247
2249
|
}
|
|
2248
2250
|
|
|
2249
|
-
function uuidv4() {
|
|
2250
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
2251
|
-
const r = (Math.random() * 16) | 0;
|
|
2252
|
-
const v = c == 'x' ? r : (r & 0x3) | 0x8;
|
|
2253
|
-
return v.toString(16);
|
|
2254
|
-
});
|
|
2255
|
-
}
|
|
2256
|
-
|
|
2257
2251
|
/**
|
|
2258
|
-
* Parses a given
|
|
2252
|
+
* Parses a given value into a JSON.
|
|
2259
2253
|
* Does not throw an exception on an invalid JSON string.
|
|
2260
2254
|
*/
|
|
2261
|
-
function jsonParse(
|
|
2255
|
+
function jsonParse(value) {
|
|
2262
2256
|
try {
|
|
2263
|
-
return JSON.parse(
|
|
2257
|
+
return JSON.parse(value);
|
|
2264
2258
|
}
|
|
2265
2259
|
catch (error) {
|
|
2266
2260
|
return undefined;
|
|
2267
2261
|
}
|
|
2268
2262
|
}
|
|
2269
2263
|
|
|
2270
|
-
var lib$
|
|
2264
|
+
var lib$1 = {};
|
|
2271
2265
|
|
|
2272
2266
|
var Headers = {};
|
|
2273
2267
|
|
|
@@ -2791,11 +2785,11 @@ var flattenHeadersList_1 = flattenHeadersList$1;
|
|
|
2791
2785
|
Object.defineProperty(exports, "flattenHeadersList", { enumerable: true, get: function () { return flattenHeadersList_1.flattenHeadersList; } });
|
|
2792
2786
|
var flattenHeadersObject_1 = flattenHeadersObject$1;
|
|
2793
2787
|
Object.defineProperty(exports, "flattenHeadersObject", { enumerable: true, get: function () { return flattenHeadersObject_1.flattenHeadersObject; } });
|
|
2794
|
-
}(lib$
|
|
2788
|
+
}(lib$1));
|
|
2795
2789
|
|
|
2796
2790
|
function parseContentHeaders(headersString) {
|
|
2797
2791
|
var _a, _b;
|
|
2798
|
-
const headers = lib$
|
|
2792
|
+
const headers = lib$1.stringToHeaders(headersString);
|
|
2799
2793
|
const contentType = headers.get('content-type') || 'text/plain';
|
|
2800
2794
|
const disposition = headers.get('content-disposition');
|
|
2801
2795
|
if (!disposition) {
|
|
@@ -2866,403 +2860,30 @@ function parseMultipartData(data, headers) {
|
|
|
2866
2860
|
}
|
|
2867
2861
|
|
|
2868
2862
|
/**
|
|
2869
|
-
* Parses a given request/response body based on the
|
|
2863
|
+
* Parses a given request/response body based on the "Content-Type" header.
|
|
2870
2864
|
*/
|
|
2871
2865
|
function parseBody(body, headers) {
|
|
2872
2866
|
// Return whatever falsey body value is given.
|
|
2873
2867
|
if (!body) {
|
|
2874
2868
|
return body;
|
|
2875
2869
|
}
|
|
2876
|
-
const contentType = headers === null || headers === void 0 ? void 0 : headers.get('content-type');
|
|
2870
|
+
const contentType = (headers === null || headers === void 0 ? void 0 : headers.get('content-type')) || '';
|
|
2877
2871
|
// If the body has a Multipart Content-Type
|
|
2878
2872
|
// parse it into an object.
|
|
2879
|
-
const hasMultipartContent = contentType
|
|
2873
|
+
const hasMultipartContent = contentType.startsWith('multipart/form-data');
|
|
2880
2874
|
if (hasMultipartContent && typeof body !== 'object') {
|
|
2881
|
-
return parseMultipartData(body, headers) || body;
|
|
2875
|
+
return parseMultipartData(body.toString(), headers) || body;
|
|
2882
2876
|
}
|
|
2883
2877
|
// If the intercepted request's body has a JSON Content-Type
|
|
2884
2878
|
// parse it into an object.
|
|
2885
|
-
const hasJsonContent = contentType
|
|
2879
|
+
const hasJsonContent = contentType.includes('json');
|
|
2886
2880
|
if (hasJsonContent && typeof body !== 'object') {
|
|
2887
|
-
return jsonParse(body) || body;
|
|
2881
|
+
return jsonParse(body.toString()) || body;
|
|
2888
2882
|
}
|
|
2889
2883
|
// Otherwise leave as-is.
|
|
2890
2884
|
return body;
|
|
2891
2885
|
}
|
|
2892
2886
|
|
|
2893
|
-
var lib$1 = {};
|
|
2894
|
-
|
|
2895
|
-
var CookieStore = {};
|
|
2896
|
-
|
|
2897
|
-
var setCookie = {exports: {}};
|
|
2898
|
-
|
|
2899
|
-
var defaultParseOptions = {
|
|
2900
|
-
decodeValues: true,
|
|
2901
|
-
map: false,
|
|
2902
|
-
silent: false,
|
|
2903
|
-
};
|
|
2904
|
-
|
|
2905
|
-
function isNonEmptyString(str) {
|
|
2906
|
-
return typeof str === "string" && !!str.trim();
|
|
2907
|
-
}
|
|
2908
|
-
|
|
2909
|
-
function parseString(setCookieValue, options) {
|
|
2910
|
-
var parts = setCookieValue.split(";").filter(isNonEmptyString);
|
|
2911
|
-
var nameValue = parts.shift().split("=");
|
|
2912
|
-
var name = nameValue.shift();
|
|
2913
|
-
var value = nameValue.join("="); // everything after the first =, joined by a "=" if there was more than one part
|
|
2914
|
-
|
|
2915
|
-
options = options
|
|
2916
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
2917
|
-
: defaultParseOptions;
|
|
2918
|
-
|
|
2919
|
-
try {
|
|
2920
|
-
value = options.decodeValues ? decodeURIComponent(value) : value; // decode cookie value
|
|
2921
|
-
} catch (e) {
|
|
2922
|
-
console.error(
|
|
2923
|
-
"set-cookie-parser encountered an error while decoding a cookie with value '" +
|
|
2924
|
-
value +
|
|
2925
|
-
"'. Set options.decodeValues to false to disable this feature.",
|
|
2926
|
-
e
|
|
2927
|
-
);
|
|
2928
|
-
}
|
|
2929
|
-
|
|
2930
|
-
var cookie = {
|
|
2931
|
-
name: name, // grab everything before the first =
|
|
2932
|
-
value: value,
|
|
2933
|
-
};
|
|
2934
|
-
|
|
2935
|
-
parts.forEach(function (part) {
|
|
2936
|
-
var sides = part.split("=");
|
|
2937
|
-
var key = sides.shift().trimLeft().toLowerCase();
|
|
2938
|
-
var value = sides.join("=");
|
|
2939
|
-
if (key === "expires") {
|
|
2940
|
-
cookie.expires = new Date(value);
|
|
2941
|
-
} else if (key === "max-age") {
|
|
2942
|
-
cookie.maxAge = parseInt(value, 10);
|
|
2943
|
-
} else if (key === "secure") {
|
|
2944
|
-
cookie.secure = true;
|
|
2945
|
-
} else if (key === "httponly") {
|
|
2946
|
-
cookie.httpOnly = true;
|
|
2947
|
-
} else if (key === "samesite") {
|
|
2948
|
-
cookie.sameSite = value;
|
|
2949
|
-
} else {
|
|
2950
|
-
cookie[key] = value;
|
|
2951
|
-
}
|
|
2952
|
-
});
|
|
2953
|
-
|
|
2954
|
-
return cookie;
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
function parse$1(input, options) {
|
|
2958
|
-
options = options
|
|
2959
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
2960
|
-
: defaultParseOptions;
|
|
2961
|
-
|
|
2962
|
-
if (!input) {
|
|
2963
|
-
if (!options.map) {
|
|
2964
|
-
return [];
|
|
2965
|
-
} else {
|
|
2966
|
-
return {};
|
|
2967
|
-
}
|
|
2968
|
-
}
|
|
2969
|
-
|
|
2970
|
-
if (input.headers && input.headers["set-cookie"]) {
|
|
2971
|
-
// fast-path for node.js (which automatically normalizes header names to lower-case
|
|
2972
|
-
input = input.headers["set-cookie"];
|
|
2973
|
-
} else if (input.headers) {
|
|
2974
|
-
// slow-path for other environments - see #25
|
|
2975
|
-
var sch =
|
|
2976
|
-
input.headers[
|
|
2977
|
-
Object.keys(input.headers).find(function (key) {
|
|
2978
|
-
return key.toLowerCase() === "set-cookie";
|
|
2979
|
-
})
|
|
2980
|
-
];
|
|
2981
|
-
// warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
|
|
2982
|
-
if (!sch && input.headers.cookie && !options.silent) {
|
|
2983
|
-
console.warn(
|
|
2984
|
-
"Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
|
|
2985
|
-
);
|
|
2986
|
-
}
|
|
2987
|
-
input = sch;
|
|
2988
|
-
}
|
|
2989
|
-
if (!Array.isArray(input)) {
|
|
2990
|
-
input = [input];
|
|
2991
|
-
}
|
|
2992
|
-
|
|
2993
|
-
options = options
|
|
2994
|
-
? Object.assign({}, defaultParseOptions, options)
|
|
2995
|
-
: defaultParseOptions;
|
|
2996
|
-
|
|
2997
|
-
if (!options.map) {
|
|
2998
|
-
return input.filter(isNonEmptyString).map(function (str) {
|
|
2999
|
-
return parseString(str, options);
|
|
3000
|
-
});
|
|
3001
|
-
} else {
|
|
3002
|
-
var cookies = {};
|
|
3003
|
-
return input.filter(isNonEmptyString).reduce(function (cookies, str) {
|
|
3004
|
-
var cookie = parseString(str, options);
|
|
3005
|
-
cookies[cookie.name] = cookie;
|
|
3006
|
-
return cookies;
|
|
3007
|
-
}, cookies);
|
|
3008
|
-
}
|
|
3009
|
-
}
|
|
3010
|
-
|
|
3011
|
-
/*
|
|
3012
|
-
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
3013
|
-
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
3014
|
-
|
|
3015
|
-
This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
|
|
3016
|
-
Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
|
|
3017
|
-
React Native's fetch does this for *every* header, including set-cookie.
|
|
3018
|
-
|
|
3019
|
-
Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
|
|
3020
|
-
Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
|
|
3021
|
-
*/
|
|
3022
|
-
function splitCookiesString(cookiesString) {
|
|
3023
|
-
if (Array.isArray(cookiesString)) {
|
|
3024
|
-
return cookiesString;
|
|
3025
|
-
}
|
|
3026
|
-
if (typeof cookiesString !== "string") {
|
|
3027
|
-
return [];
|
|
3028
|
-
}
|
|
3029
|
-
|
|
3030
|
-
var cookiesStrings = [];
|
|
3031
|
-
var pos = 0;
|
|
3032
|
-
var start;
|
|
3033
|
-
var ch;
|
|
3034
|
-
var lastComma;
|
|
3035
|
-
var nextStart;
|
|
3036
|
-
var cookiesSeparatorFound;
|
|
3037
|
-
|
|
3038
|
-
function skipWhitespace() {
|
|
3039
|
-
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
|
|
3040
|
-
pos += 1;
|
|
3041
|
-
}
|
|
3042
|
-
return pos < cookiesString.length;
|
|
3043
|
-
}
|
|
3044
|
-
|
|
3045
|
-
function notSpecialChar() {
|
|
3046
|
-
ch = cookiesString.charAt(pos);
|
|
3047
|
-
|
|
3048
|
-
return ch !== "=" && ch !== ";" && ch !== ",";
|
|
3049
|
-
}
|
|
3050
|
-
|
|
3051
|
-
while (pos < cookiesString.length) {
|
|
3052
|
-
start = pos;
|
|
3053
|
-
cookiesSeparatorFound = false;
|
|
3054
|
-
|
|
3055
|
-
while (skipWhitespace()) {
|
|
3056
|
-
ch = cookiesString.charAt(pos);
|
|
3057
|
-
if (ch === ",") {
|
|
3058
|
-
// ',' is a cookie separator if we have later first '=', not ';' or ','
|
|
3059
|
-
lastComma = pos;
|
|
3060
|
-
pos += 1;
|
|
3061
|
-
|
|
3062
|
-
skipWhitespace();
|
|
3063
|
-
nextStart = pos;
|
|
3064
|
-
|
|
3065
|
-
while (pos < cookiesString.length && notSpecialChar()) {
|
|
3066
|
-
pos += 1;
|
|
3067
|
-
}
|
|
3068
|
-
|
|
3069
|
-
// currently special character
|
|
3070
|
-
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
|
|
3071
|
-
// we found cookies separator
|
|
3072
|
-
cookiesSeparatorFound = true;
|
|
3073
|
-
// pos is inside the next cookie, so back up and return it.
|
|
3074
|
-
pos = nextStart;
|
|
3075
|
-
cookiesStrings.push(cookiesString.substring(start, lastComma));
|
|
3076
|
-
start = pos;
|
|
3077
|
-
} else {
|
|
3078
|
-
// in param ',' or param separator ';',
|
|
3079
|
-
// we continue from that comma
|
|
3080
|
-
pos = lastComma + 1;
|
|
3081
|
-
}
|
|
3082
|
-
} else {
|
|
3083
|
-
pos += 1;
|
|
3084
|
-
}
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
|
-
if (!cookiesSeparatorFound || pos >= cookiesString.length) {
|
|
3088
|
-
cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
|
|
3089
|
-
}
|
|
3090
|
-
}
|
|
3091
|
-
|
|
3092
|
-
return cookiesStrings;
|
|
3093
|
-
}
|
|
3094
|
-
|
|
3095
|
-
setCookie.exports = parse$1;
|
|
3096
|
-
setCookie.exports.parse = parse$1;
|
|
3097
|
-
setCookie.exports.parseString = parseString;
|
|
3098
|
-
setCookie.exports.splitCookiesString = splitCookiesString;
|
|
3099
|
-
|
|
3100
|
-
(function (exports) {
|
|
3101
|
-
var __rest = (commonjsGlobal && commonjsGlobal.__rest) || function (s, e) {
|
|
3102
|
-
var t = {};
|
|
3103
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
3104
|
-
t[p] = s[p];
|
|
3105
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
3106
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
3107
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
3108
|
-
t[p[i]] = s[p[i]];
|
|
3109
|
-
}
|
|
3110
|
-
return t;
|
|
3111
|
-
};
|
|
3112
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3113
|
-
exports.PERSISTENCY_KEY = void 0;
|
|
3114
|
-
const set_cookie_parser_1 = setCookie.exports;
|
|
3115
|
-
exports.PERSISTENCY_KEY = 'MSW_COOKIE_STORE';
|
|
3116
|
-
const SUPPORTS_LOCAL_STORAGE = typeof localStorage !== 'undefined';
|
|
3117
|
-
class CookieStore {
|
|
3118
|
-
constructor() {
|
|
3119
|
-
this.store = new Map();
|
|
3120
|
-
}
|
|
3121
|
-
/**
|
|
3122
|
-
* Sets the given request cookies into the store.
|
|
3123
|
-
* Respects the `request.credentials` policy.
|
|
3124
|
-
*/
|
|
3125
|
-
add(request, response) {
|
|
3126
|
-
if (request.credentials === 'omit') {
|
|
3127
|
-
return;
|
|
3128
|
-
}
|
|
3129
|
-
const requestUrl = new URL(request.url);
|
|
3130
|
-
const responseCookies = response.headers.get('set-cookie');
|
|
3131
|
-
if (!responseCookies) {
|
|
3132
|
-
return;
|
|
3133
|
-
}
|
|
3134
|
-
const now = Date.now();
|
|
3135
|
-
const parsedResponseCookies = set_cookie_parser_1.parse(responseCookies).map((_a) => {
|
|
3136
|
-
var { maxAge } = _a, cookie = __rest(_a, ["maxAge"]);
|
|
3137
|
-
return (Object.assign(Object.assign({}, cookie), { expires: maxAge === undefined ? cookie.expires : new Date(now + maxAge * 1000), maxAge }));
|
|
3138
|
-
});
|
|
3139
|
-
const prevCookies = this.store.get(requestUrl.origin) || new Map();
|
|
3140
|
-
parsedResponseCookies.forEach((cookie) => {
|
|
3141
|
-
this.store.set(requestUrl.origin, prevCookies.set(cookie.name, cookie));
|
|
3142
|
-
});
|
|
3143
|
-
}
|
|
3144
|
-
/**
|
|
3145
|
-
* Returns cookies relevant to the given request
|
|
3146
|
-
* and its `request.credentials` policy.
|
|
3147
|
-
*/
|
|
3148
|
-
get(request) {
|
|
3149
|
-
this.deleteExpiredCookies();
|
|
3150
|
-
const requestUrl = new URL(request.url);
|
|
3151
|
-
const originCookies = this.store.get(requestUrl.origin) || new Map();
|
|
3152
|
-
switch (request.credentials) {
|
|
3153
|
-
case 'include': {
|
|
3154
|
-
const documentCookies = set_cookie_parser_1.parse(document.cookie);
|
|
3155
|
-
documentCookies.forEach((cookie) => {
|
|
3156
|
-
originCookies.set(cookie.name, cookie);
|
|
3157
|
-
});
|
|
3158
|
-
return originCookies;
|
|
3159
|
-
}
|
|
3160
|
-
case 'same-origin': {
|
|
3161
|
-
return originCookies;
|
|
3162
|
-
}
|
|
3163
|
-
default:
|
|
3164
|
-
return new Map();
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
/**
|
|
3168
|
-
* Returns a collection of all stored cookies.
|
|
3169
|
-
*/
|
|
3170
|
-
getAll() {
|
|
3171
|
-
this.deleteExpiredCookies();
|
|
3172
|
-
return this.store;
|
|
3173
|
-
}
|
|
3174
|
-
/**
|
|
3175
|
-
* Deletes all cookies associated with the given request.
|
|
3176
|
-
*/
|
|
3177
|
-
deleteAll(request) {
|
|
3178
|
-
const requestUrl = new URL(request.url);
|
|
3179
|
-
this.store.delete(requestUrl.origin);
|
|
3180
|
-
}
|
|
3181
|
-
/**
|
|
3182
|
-
* Clears the entire cookie store.
|
|
3183
|
-
*/
|
|
3184
|
-
clear() {
|
|
3185
|
-
this.store.clear();
|
|
3186
|
-
}
|
|
3187
|
-
/**
|
|
3188
|
-
* Hydrates the virtual cookie store from the `localStorage` if defined.
|
|
3189
|
-
*/
|
|
3190
|
-
hydrate() {
|
|
3191
|
-
if (!SUPPORTS_LOCAL_STORAGE) {
|
|
3192
|
-
return;
|
|
3193
|
-
}
|
|
3194
|
-
const persistedCookies = localStorage.getItem(exports.PERSISTENCY_KEY);
|
|
3195
|
-
if (persistedCookies) {
|
|
3196
|
-
try {
|
|
3197
|
-
const parsedCookies = JSON.parse(persistedCookies);
|
|
3198
|
-
parsedCookies.forEach(([origin, cookies]) => {
|
|
3199
|
-
this.store.set(origin, new Map(cookies.map((_a) => {
|
|
3200
|
-
var [token, _b] = _a, { expires } = _b, cookie = __rest(_b, ["expires"]);
|
|
3201
|
-
return [
|
|
3202
|
-
token,
|
|
3203
|
-
expires === undefined
|
|
3204
|
-
? cookie
|
|
3205
|
-
: Object.assign(Object.assign({}, cookie), { expires: new Date(expires) }),
|
|
3206
|
-
];
|
|
3207
|
-
})));
|
|
3208
|
-
});
|
|
3209
|
-
}
|
|
3210
|
-
catch (error) {
|
|
3211
|
-
console.warn(`
|
|
3212
|
-
[virtual-cookie] Failed to parse a stored cookie from the localStorage (key "${exports.PERSISTENCY_KEY}").
|
|
3213
|
-
|
|
3214
|
-
Stored value:
|
|
3215
|
-
${localStorage.getItem(exports.PERSISTENCY_KEY)}
|
|
3216
|
-
|
|
3217
|
-
Thrown exception:
|
|
3218
|
-
${error}
|
|
3219
|
-
|
|
3220
|
-
Invalid value has been removed from localStorage to prevent subsequent failed parsing attempts.`);
|
|
3221
|
-
localStorage.removeItem(exports.PERSISTENCY_KEY);
|
|
3222
|
-
}
|
|
3223
|
-
}
|
|
3224
|
-
}
|
|
3225
|
-
/**
|
|
3226
|
-
* Persists the current virtual cookies into the `localStorage` if defined,
|
|
3227
|
-
* so they are available on the next page load.
|
|
3228
|
-
*/
|
|
3229
|
-
persist() {
|
|
3230
|
-
if (!SUPPORTS_LOCAL_STORAGE) {
|
|
3231
|
-
return;
|
|
3232
|
-
}
|
|
3233
|
-
const serializedCookies = Array.from(this.store.entries()).map(([origin, cookies]) => {
|
|
3234
|
-
return [origin, Array.from(cookies.entries())];
|
|
3235
|
-
});
|
|
3236
|
-
localStorage.setItem(exports.PERSISTENCY_KEY, JSON.stringify(serializedCookies));
|
|
3237
|
-
}
|
|
3238
|
-
deleteExpiredCookies() {
|
|
3239
|
-
const now = Date.now();
|
|
3240
|
-
this.store.forEach((originCookies, origin) => {
|
|
3241
|
-
originCookies.forEach(({ expires, name }) => {
|
|
3242
|
-
if (expires !== undefined && expires.getTime() <= now) {
|
|
3243
|
-
originCookies.delete(name);
|
|
3244
|
-
}
|
|
3245
|
-
});
|
|
3246
|
-
if (originCookies.size === 0) {
|
|
3247
|
-
this.store.delete(origin);
|
|
3248
|
-
}
|
|
3249
|
-
});
|
|
3250
|
-
}
|
|
3251
|
-
}
|
|
3252
|
-
exports.default = new CookieStore();
|
|
3253
|
-
}(CookieStore));
|
|
3254
|
-
|
|
3255
|
-
(function (exports) {
|
|
3256
|
-
var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
|
|
3257
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
3258
|
-
};
|
|
3259
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3260
|
-
exports.PERSISTENCY_KEY = exports.store = void 0;
|
|
3261
|
-
var CookieStore_1 = CookieStore;
|
|
3262
|
-
Object.defineProperty(exports, "store", { enumerable: true, get: function () { return __importDefault(CookieStore_1).default; } });
|
|
3263
|
-
Object.defineProperty(exports, "PERSISTENCY_KEY", { enumerable: true, get: function () { return CookieStore_1.PERSISTENCY_KEY; } });
|
|
3264
|
-
}(lib$1));
|
|
3265
|
-
|
|
3266
2887
|
function getAllCookies() {
|
|
3267
2888
|
return parse_1(document.cookie);
|
|
3268
2889
|
}
|
|
@@ -3273,7 +2894,7 @@ function getRequestCookies(request) {
|
|
|
3273
2894
|
/**
|
|
3274
2895
|
* @note No cookies persist on the document in Node.js: no document.
|
|
3275
2896
|
*/
|
|
3276
|
-
if (typeof location === 'undefined') {
|
|
2897
|
+
if (typeof document === 'undefined' || typeof location === 'undefined') {
|
|
3277
2898
|
return {};
|
|
3278
2899
|
}
|
|
3279
2900
|
switch (request.credentials) {
|
|
@@ -3294,8 +2915,8 @@ function getRequestCookies(request) {
|
|
|
3294
2915
|
|
|
3295
2916
|
function setRequestCookies(request) {
|
|
3296
2917
|
var _a;
|
|
3297
|
-
|
|
3298
|
-
request.cookies = Object.assign(Object.assign({}, getRequestCookies(request)), Array.from((_a =
|
|
2918
|
+
cookies.store.hydrate();
|
|
2919
|
+
request.cookies = Object.assign(Object.assign({}, getRequestCookies(request)), Array.from((_a = cookies.store.get(Object.assign(Object.assign({}, request), { url: request.url.toString() }))) === null || _a === void 0 ? void 0 : _a.entries()).reduce((cookies, [name, { value }]) => Object.assign(cookies, { [name]: value }), {}));
|
|
3299
2920
|
request.headers.set('cookie', Object.entries(request.cookies)
|
|
3300
2921
|
.map(([name, value]) => `${name}=${value}`)
|
|
3301
2922
|
.join('; '));
|
|
@@ -3305,10 +2926,8 @@ function setRequestCookies(request) {
|
|
|
3305
2926
|
* Converts a given isomorphic request to a `MockedRequest` instance.
|
|
3306
2927
|
*/
|
|
3307
2928
|
function parseIsomorphicRequest(request) {
|
|
3308
|
-
const requestId = uuidv4();
|
|
3309
|
-
request.headers.set('x-msw-request-id', requestId);
|
|
3310
2929
|
const mockedRequest = {
|
|
3311
|
-
id:
|
|
2930
|
+
id: request.id,
|
|
3312
2931
|
url: request.url,
|
|
3313
2932
|
method: request.method,
|
|
3314
2933
|
body: parseBody(request.body, request.headers),
|
|
@@ -4114,6 +3733,7 @@ function invariant(condition, message) {
|
|
|
4114
3733
|
|
|
4115
3734
|
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
4116
3735
|
var nodejsCustomInspectSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function' ? Symbol.for('nodejs.util.inspect.custom') : undefined;
|
|
3736
|
+
var nodejsCustomInspectSymbol$1 = nodejsCustomInspectSymbol;
|
|
4117
3737
|
|
|
4118
3738
|
/**
|
|
4119
3739
|
* The `defineInspect()` function defines `inspect()` prototype method as alias of `toJSON`
|
|
@@ -4124,8 +3744,8 @@ function defineInspect(classObject) {
|
|
|
4124
3744
|
typeof fn === 'function' || invariant(0);
|
|
4125
3745
|
classObject.prototype.inspect = fn; // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2317')
|
|
4126
3746
|
|
|
4127
|
-
if (nodejsCustomInspectSymbol) {
|
|
4128
|
-
classObject.prototype[nodejsCustomInspectSymbol] = fn;
|
|
3747
|
+
if (nodejsCustomInspectSymbol$1) {
|
|
3748
|
+
classObject.prototype[nodejsCustomInspectSymbol$1] = fn;
|
|
4129
3749
|
}
|
|
4130
3750
|
}
|
|
4131
3751
|
|
|
@@ -4368,7 +3988,7 @@ function formatArray(array, seenValues) {
|
|
|
4368
3988
|
}
|
|
4369
3989
|
|
|
4370
3990
|
function getCustomFn(object) {
|
|
4371
|
-
var customInspectFn = object[String(nodejsCustomInspectSymbol)];
|
|
3991
|
+
var customInspectFn = object[String(nodejsCustomInspectSymbol$1)];
|
|
4372
3992
|
|
|
4373
3993
|
if (typeof customInspectFn === 'function') {
|
|
4374
3994
|
return customInspectFn;
|
|
@@ -5288,7 +4908,7 @@ function isNameStart(code) {
|
|
|
5288
4908
|
* Given a GraphQL source, parses it into a Document.
|
|
5289
4909
|
* Throws GraphQLError if a syntax error is encountered.
|
|
5290
4910
|
*/
|
|
5291
|
-
function parse(source, options) {
|
|
4911
|
+
function parse$1(source, options) {
|
|
5292
4912
|
var parser = new Parser(source, options);
|
|
5293
4913
|
return parser.parseDocument();
|
|
5294
4914
|
}
|
|
@@ -6807,7 +6427,7 @@ function parseDocumentNode(node) {
|
|
|
6807
6427
|
}
|
|
6808
6428
|
function parseQuery(query) {
|
|
6809
6429
|
try {
|
|
6810
|
-
const ast = parse(query);
|
|
6430
|
+
const ast = parse$1(query);
|
|
6811
6431
|
return parseDocumentNode(ast);
|
|
6812
6432
|
}
|
|
6813
6433
|
catch (error) {
|
|
@@ -7003,7 +6623,7 @@ function set(...args) {
|
|
|
7003
6623
|
res.headers.append(name, value);
|
|
7004
6624
|
}
|
|
7005
6625
|
else {
|
|
7006
|
-
const headers = lib$
|
|
6626
|
+
const headers = lib$1.objectToHeaders(name);
|
|
7007
6627
|
headers.forEach((value, name) => {
|
|
7008
6628
|
res.headers.append(name, value);
|
|
7009
6629
|
});
|
|
@@ -7100,12 +6720,26 @@ const data = (payload) => {
|
|
|
7100
6720
|
};
|
|
7101
6721
|
};
|
|
7102
6722
|
|
|
6723
|
+
/**
|
|
6724
|
+
* Sets the GraphQL extensions on a given response.
|
|
6725
|
+
* @example
|
|
6726
|
+
* res(ctx.extensions({ tracing: { version: 1 }}))
|
|
6727
|
+
* @see {@link https://mswjs.io/docs/api/context/extensions `ctx.extensions()`}
|
|
6728
|
+
*/
|
|
6729
|
+
const extensions = (payload) => {
|
|
6730
|
+
return (res) => {
|
|
6731
|
+
const prevBody = jsonParse(res.body) || {};
|
|
6732
|
+
const nextBody = mergeRight(prevBody, { extensions: payload });
|
|
6733
|
+
return json(nextBody)(res);
|
|
6734
|
+
};
|
|
6735
|
+
};
|
|
6736
|
+
|
|
7103
6737
|
const SET_TIMEOUT_MAX_ALLOWED_INT = 2147483647;
|
|
7104
6738
|
const MIN_SERVER_RESPONSE_TIME = 100;
|
|
7105
6739
|
const MAX_SERVER_RESPONSE_TIME = 400;
|
|
7106
6740
|
const NODE_SERVER_RESPONSE_TIME = 5;
|
|
7107
6741
|
const getRandomServerResponseTime = () => {
|
|
7108
|
-
if (lib$
|
|
6742
|
+
if (lib$3.exports.isNodeProcess()) {
|
|
7109
6743
|
return NODE_SERVER_RESPONSE_TIME;
|
|
7110
6744
|
}
|
|
7111
6745
|
return Math.floor(Math.random() * (MAX_SERVER_RESPONSE_TIME - MIN_SERVER_RESPONSE_TIME) +
|
|
@@ -7172,9 +6806,9 @@ const errors = (errorsList) => {
|
|
|
7172
6806
|
};
|
|
7173
6807
|
};
|
|
7174
6808
|
|
|
7175
|
-
const useFetch = lib$
|
|
6809
|
+
const useFetch = lib$3.exports.isNodeProcess() ? require('node-fetch') : window.fetch;
|
|
7176
6810
|
const augmentRequestInit = (requestInit) => {
|
|
7177
|
-
const headers = new lib$
|
|
6811
|
+
const headers = new lib$1.Headers(requestInit.headers);
|
|
7178
6812
|
headers.set('x-msw-bypass', 'true');
|
|
7179
6813
|
return Object.assign(Object.assign({}, requestInit), { headers: headers.all() });
|
|
7180
6814
|
};
|
|
@@ -7184,8 +6818,12 @@ const createFetchRequestParameters = (input) => {
|
|
|
7184
6818
|
if (['GET', 'HEAD'].includes(method)) {
|
|
7185
6819
|
return requestParameters;
|
|
7186
6820
|
}
|
|
7187
|
-
|
|
7188
|
-
|
|
6821
|
+
if (typeof body === 'object' || typeof body === 'number') {
|
|
6822
|
+
requestParameters.body = JSON.stringify(body);
|
|
6823
|
+
}
|
|
6824
|
+
else {
|
|
6825
|
+
requestParameters.body = body;
|
|
6826
|
+
}
|
|
7189
6827
|
return requestParameters;
|
|
7190
6828
|
};
|
|
7191
6829
|
/**
|
|
@@ -7274,63 +6912,345 @@ function prepareRequest(request) {
|
|
|
7274
6912
|
* Formats a mocked response for introspection in the browser's console.
|
|
7275
6913
|
*/
|
|
7276
6914
|
function prepareResponse(res) {
|
|
7277
|
-
const responseHeaders = lib$
|
|
6915
|
+
const responseHeaders = lib$1.objectToHeaders(res.headers);
|
|
7278
6916
|
return Object.assign(Object.assign({}, res), {
|
|
7279
6917
|
// Parse a response JSON body for preview in the logs
|
|
7280
6918
|
body: parseBody(res.body, responseHeaders) });
|
|
7281
6919
|
}
|
|
7282
6920
|
|
|
7283
|
-
/**
|
|
7284
|
-
* Converts a string path to a Regular Expression.
|
|
7285
|
-
* Transforms path parameters into named RegExp groups.
|
|
7286
|
-
*/
|
|
7287
|
-
const pathToRegExp = (path) => {
|
|
7288
|
-
const pattern = path
|
|
7289
|
-
// Escape literal dots
|
|
7290
|
-
.replace(/\./g, '\\.')
|
|
7291
|
-
// Escape literal slashes
|
|
7292
|
-
.replace(/\//g, '/')
|
|
7293
|
-
// Escape literal question marks
|
|
7294
|
-
.replace(/\?/g, '\\?')
|
|
7295
|
-
// Ignore trailing slashes
|
|
7296
|
-
.replace(/\/+$/, '')
|
|
7297
|
-
// Replace wildcard with any zero-to-any character sequence
|
|
7298
|
-
.replace(/\*+/g, '.*')
|
|
7299
|
-
// Replace parameters with named capturing groups
|
|
7300
|
-
.replace(/:([^\d|^\/][a-zA-Z0-9_]*(?=(?:\/|\\.)|$))/g, (_, paramName) => `(?<${paramName}>[^\/]+?)`)
|
|
7301
|
-
// Allow optional trailing slash
|
|
7302
|
-
.concat('(\\/|$)');
|
|
7303
|
-
return new RegExp(pattern, 'gi');
|
|
7304
|
-
};
|
|
7305
|
-
|
|
7306
|
-
/**
|
|
7307
|
-
* Matches a given url against a path.
|
|
7308
|
-
*/
|
|
7309
|
-
const match = (path, url) => {
|
|
7310
|
-
const expression = path instanceof RegExp ? path : pathToRegExp(path);
|
|
7311
|
-
const match = expression.exec(url) || false;
|
|
7312
|
-
// Matches in strict mode: match string should equal to input (url)
|
|
7313
|
-
// Otherwise loose matches will be considered truthy:
|
|
7314
|
-
// match('/messages/:id', '/messages/123/users') // true
|
|
7315
|
-
const matches = path instanceof RegExp ? !!match : !!match && match[0] === match.input;
|
|
7316
|
-
return {
|
|
7317
|
-
matches,
|
|
7318
|
-
params: match && matches ? match.groups || null : null,
|
|
7319
|
-
};
|
|
7320
|
-
};
|
|
7321
|
-
|
|
7322
|
-
var getCleanUrl$1 = {};
|
|
7323
|
-
|
|
7324
|
-
Object.defineProperty(getCleanUrl$1, "__esModule", { value: true });
|
|
7325
|
-
var getCleanUrl_2 = getCleanUrl$1.getCleanUrl = void 0;
|
|
7326
6921
|
/**
|
|
7327
|
-
*
|
|
6922
|
+
* Tokenize input string.
|
|
6923
|
+
*/
|
|
6924
|
+
function lexer(str) {
|
|
6925
|
+
var tokens = [];
|
|
6926
|
+
var i = 0;
|
|
6927
|
+
while (i < str.length) {
|
|
6928
|
+
var char = str[i];
|
|
6929
|
+
if (char === "*" || char === "+" || char === "?") {
|
|
6930
|
+
tokens.push({ type: "MODIFIER", index: i, value: str[i++] });
|
|
6931
|
+
continue;
|
|
6932
|
+
}
|
|
6933
|
+
if (char === "\\") {
|
|
6934
|
+
tokens.push({ type: "ESCAPED_CHAR", index: i++, value: str[i++] });
|
|
6935
|
+
continue;
|
|
6936
|
+
}
|
|
6937
|
+
if (char === "{") {
|
|
6938
|
+
tokens.push({ type: "OPEN", index: i, value: str[i++] });
|
|
6939
|
+
continue;
|
|
6940
|
+
}
|
|
6941
|
+
if (char === "}") {
|
|
6942
|
+
tokens.push({ type: "CLOSE", index: i, value: str[i++] });
|
|
6943
|
+
continue;
|
|
6944
|
+
}
|
|
6945
|
+
if (char === ":") {
|
|
6946
|
+
var name = "";
|
|
6947
|
+
var j = i + 1;
|
|
6948
|
+
while (j < str.length) {
|
|
6949
|
+
var code = str.charCodeAt(j);
|
|
6950
|
+
if (
|
|
6951
|
+
// `0-9`
|
|
6952
|
+
(code >= 48 && code <= 57) ||
|
|
6953
|
+
// `A-Z`
|
|
6954
|
+
(code >= 65 && code <= 90) ||
|
|
6955
|
+
// `a-z`
|
|
6956
|
+
(code >= 97 && code <= 122) ||
|
|
6957
|
+
// `_`
|
|
6958
|
+
code === 95) {
|
|
6959
|
+
name += str[j++];
|
|
6960
|
+
continue;
|
|
6961
|
+
}
|
|
6962
|
+
break;
|
|
6963
|
+
}
|
|
6964
|
+
if (!name)
|
|
6965
|
+
throw new TypeError("Missing parameter name at " + i);
|
|
6966
|
+
tokens.push({ type: "NAME", index: i, value: name });
|
|
6967
|
+
i = j;
|
|
6968
|
+
continue;
|
|
6969
|
+
}
|
|
6970
|
+
if (char === "(") {
|
|
6971
|
+
var count = 1;
|
|
6972
|
+
var pattern = "";
|
|
6973
|
+
var j = i + 1;
|
|
6974
|
+
if (str[j] === "?") {
|
|
6975
|
+
throw new TypeError("Pattern cannot start with \"?\" at " + j);
|
|
6976
|
+
}
|
|
6977
|
+
while (j < str.length) {
|
|
6978
|
+
if (str[j] === "\\") {
|
|
6979
|
+
pattern += str[j++] + str[j++];
|
|
6980
|
+
continue;
|
|
6981
|
+
}
|
|
6982
|
+
if (str[j] === ")") {
|
|
6983
|
+
count--;
|
|
6984
|
+
if (count === 0) {
|
|
6985
|
+
j++;
|
|
6986
|
+
break;
|
|
6987
|
+
}
|
|
6988
|
+
}
|
|
6989
|
+
else if (str[j] === "(") {
|
|
6990
|
+
count++;
|
|
6991
|
+
if (str[j + 1] !== "?") {
|
|
6992
|
+
throw new TypeError("Capturing groups are not allowed at " + j);
|
|
6993
|
+
}
|
|
6994
|
+
}
|
|
6995
|
+
pattern += str[j++];
|
|
6996
|
+
}
|
|
6997
|
+
if (count)
|
|
6998
|
+
throw new TypeError("Unbalanced pattern at " + i);
|
|
6999
|
+
if (!pattern)
|
|
7000
|
+
throw new TypeError("Missing pattern at " + i);
|
|
7001
|
+
tokens.push({ type: "PATTERN", index: i, value: pattern });
|
|
7002
|
+
i = j;
|
|
7003
|
+
continue;
|
|
7004
|
+
}
|
|
7005
|
+
tokens.push({ type: "CHAR", index: i, value: str[i++] });
|
|
7006
|
+
}
|
|
7007
|
+
tokens.push({ type: "END", index: i, value: "" });
|
|
7008
|
+
return tokens;
|
|
7009
|
+
}
|
|
7010
|
+
/**
|
|
7011
|
+
* Parse a string for the raw tokens.
|
|
7328
7012
|
*/
|
|
7329
|
-
function
|
|
7330
|
-
if (
|
|
7331
|
-
|
|
7013
|
+
function parse(str, options) {
|
|
7014
|
+
if (options === void 0) { options = {}; }
|
|
7015
|
+
var tokens = lexer(str);
|
|
7016
|
+
var _a = options.prefixes, prefixes = _a === void 0 ? "./" : _a;
|
|
7017
|
+
var defaultPattern = "[^" + escapeString(options.delimiter || "/#?") + "]+?";
|
|
7018
|
+
var result = [];
|
|
7019
|
+
var key = 0;
|
|
7020
|
+
var i = 0;
|
|
7021
|
+
var path = "";
|
|
7022
|
+
var tryConsume = function (type) {
|
|
7023
|
+
if (i < tokens.length && tokens[i].type === type)
|
|
7024
|
+
return tokens[i++].value;
|
|
7025
|
+
};
|
|
7026
|
+
var mustConsume = function (type) {
|
|
7027
|
+
var value = tryConsume(type);
|
|
7028
|
+
if (value !== undefined)
|
|
7029
|
+
return value;
|
|
7030
|
+
var _a = tokens[i], nextType = _a.type, index = _a.index;
|
|
7031
|
+
throw new TypeError("Unexpected " + nextType + " at " + index + ", expected " + type);
|
|
7032
|
+
};
|
|
7033
|
+
var consumeText = function () {
|
|
7034
|
+
var result = "";
|
|
7035
|
+
var value;
|
|
7036
|
+
// tslint:disable-next-line
|
|
7037
|
+
while ((value = tryConsume("CHAR") || tryConsume("ESCAPED_CHAR"))) {
|
|
7038
|
+
result += value;
|
|
7039
|
+
}
|
|
7040
|
+
return result;
|
|
7041
|
+
};
|
|
7042
|
+
while (i < tokens.length) {
|
|
7043
|
+
var char = tryConsume("CHAR");
|
|
7044
|
+
var name = tryConsume("NAME");
|
|
7045
|
+
var pattern = tryConsume("PATTERN");
|
|
7046
|
+
if (name || pattern) {
|
|
7047
|
+
var prefix = char || "";
|
|
7048
|
+
if (prefixes.indexOf(prefix) === -1) {
|
|
7049
|
+
path += prefix;
|
|
7050
|
+
prefix = "";
|
|
7051
|
+
}
|
|
7052
|
+
if (path) {
|
|
7053
|
+
result.push(path);
|
|
7054
|
+
path = "";
|
|
7055
|
+
}
|
|
7056
|
+
result.push({
|
|
7057
|
+
name: name || key++,
|
|
7058
|
+
prefix: prefix,
|
|
7059
|
+
suffix: "",
|
|
7060
|
+
pattern: pattern || defaultPattern,
|
|
7061
|
+
modifier: tryConsume("MODIFIER") || ""
|
|
7062
|
+
});
|
|
7063
|
+
continue;
|
|
7064
|
+
}
|
|
7065
|
+
var value = char || tryConsume("ESCAPED_CHAR");
|
|
7066
|
+
if (value) {
|
|
7067
|
+
path += value;
|
|
7068
|
+
continue;
|
|
7069
|
+
}
|
|
7070
|
+
if (path) {
|
|
7071
|
+
result.push(path);
|
|
7072
|
+
path = "";
|
|
7073
|
+
}
|
|
7074
|
+
var open = tryConsume("OPEN");
|
|
7075
|
+
if (open) {
|
|
7076
|
+
var prefix = consumeText();
|
|
7077
|
+
var name_1 = tryConsume("NAME") || "";
|
|
7078
|
+
var pattern_1 = tryConsume("PATTERN") || "";
|
|
7079
|
+
var suffix = consumeText();
|
|
7080
|
+
mustConsume("CLOSE");
|
|
7081
|
+
result.push({
|
|
7082
|
+
name: name_1 || (pattern_1 ? key++ : ""),
|
|
7083
|
+
pattern: name_1 && !pattern_1 ? defaultPattern : pattern_1,
|
|
7084
|
+
prefix: prefix,
|
|
7085
|
+
suffix: suffix,
|
|
7086
|
+
modifier: tryConsume("MODIFIER") || ""
|
|
7087
|
+
});
|
|
7088
|
+
continue;
|
|
7089
|
+
}
|
|
7090
|
+
mustConsume("END");
|
|
7091
|
+
}
|
|
7092
|
+
return result;
|
|
7093
|
+
}
|
|
7094
|
+
/**
|
|
7095
|
+
* Create path match function from `path-to-regexp` spec.
|
|
7096
|
+
*/
|
|
7097
|
+
function match(str, options) {
|
|
7098
|
+
var keys = [];
|
|
7099
|
+
var re = pathToRegexp(str, keys, options);
|
|
7100
|
+
return regexpToFunction(re, keys, options);
|
|
7101
|
+
}
|
|
7102
|
+
/**
|
|
7103
|
+
* Create a path match function from `path-to-regexp` output.
|
|
7104
|
+
*/
|
|
7105
|
+
function regexpToFunction(re, keys, options) {
|
|
7106
|
+
if (options === void 0) { options = {}; }
|
|
7107
|
+
var _a = options.decode, decode = _a === void 0 ? function (x) { return x; } : _a;
|
|
7108
|
+
return function (pathname) {
|
|
7109
|
+
var m = re.exec(pathname);
|
|
7110
|
+
if (!m)
|
|
7111
|
+
return false;
|
|
7112
|
+
var path = m[0], index = m.index;
|
|
7113
|
+
var params = Object.create(null);
|
|
7114
|
+
var _loop_1 = function (i) {
|
|
7115
|
+
// tslint:disable-next-line
|
|
7116
|
+
if (m[i] === undefined)
|
|
7117
|
+
return "continue";
|
|
7118
|
+
var key = keys[i - 1];
|
|
7119
|
+
if (key.modifier === "*" || key.modifier === "+") {
|
|
7120
|
+
params[key.name] = m[i].split(key.prefix + key.suffix).map(function (value) {
|
|
7121
|
+
return decode(value, key);
|
|
7122
|
+
});
|
|
7123
|
+
}
|
|
7124
|
+
else {
|
|
7125
|
+
params[key.name] = decode(m[i], key);
|
|
7126
|
+
}
|
|
7127
|
+
};
|
|
7128
|
+
for (var i = 1; i < m.length; i++) {
|
|
7129
|
+
_loop_1(i);
|
|
7130
|
+
}
|
|
7131
|
+
return { path: path, index: index, params: params };
|
|
7132
|
+
};
|
|
7133
|
+
}
|
|
7134
|
+
/**
|
|
7135
|
+
* Escape a regular expression string.
|
|
7136
|
+
*/
|
|
7137
|
+
function escapeString(str) {
|
|
7138
|
+
return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1");
|
|
7139
|
+
}
|
|
7140
|
+
/**
|
|
7141
|
+
* Get the flags for a regexp from the options.
|
|
7142
|
+
*/
|
|
7143
|
+
function flags(options) {
|
|
7144
|
+
return options && options.sensitive ? "" : "i";
|
|
7145
|
+
}
|
|
7146
|
+
/**
|
|
7147
|
+
* Pull out keys from a regexp.
|
|
7148
|
+
*/
|
|
7149
|
+
function regexpToRegexp(path, keys) {
|
|
7150
|
+
if (!keys)
|
|
7151
|
+
return path;
|
|
7152
|
+
var groupsRegex = /\((?:\?<(.*?)>)?(?!\?)/g;
|
|
7153
|
+
var index = 0;
|
|
7154
|
+
var execResult = groupsRegex.exec(path.source);
|
|
7155
|
+
while (execResult) {
|
|
7156
|
+
keys.push({
|
|
7157
|
+
// Use parenthesized substring match if available, index otherwise
|
|
7158
|
+
name: execResult[1] || index++,
|
|
7159
|
+
prefix: "",
|
|
7160
|
+
suffix: "",
|
|
7161
|
+
modifier: "",
|
|
7162
|
+
pattern: ""
|
|
7163
|
+
});
|
|
7164
|
+
execResult = groupsRegex.exec(path.source);
|
|
7165
|
+
}
|
|
7166
|
+
return path;
|
|
7167
|
+
}
|
|
7168
|
+
/**
|
|
7169
|
+
* Transform an array into a regexp.
|
|
7170
|
+
*/
|
|
7171
|
+
function arrayToRegexp(paths, keys, options) {
|
|
7172
|
+
var parts = paths.map(function (path) { return pathToRegexp(path, keys, options).source; });
|
|
7173
|
+
return new RegExp("(?:" + parts.join("|") + ")", flags(options));
|
|
7174
|
+
}
|
|
7175
|
+
/**
|
|
7176
|
+
* Create a path regexp from string input.
|
|
7177
|
+
*/
|
|
7178
|
+
function stringToRegexp(path, keys, options) {
|
|
7179
|
+
return tokensToRegexp(parse(path, options), keys, options);
|
|
7180
|
+
}
|
|
7181
|
+
/**
|
|
7182
|
+
* Expose a function for taking tokens and returning a RegExp.
|
|
7183
|
+
*/
|
|
7184
|
+
function tokensToRegexp(tokens, keys, options) {
|
|
7185
|
+
if (options === void 0) { options = {}; }
|
|
7186
|
+
var _a = options.strict, strict = _a === void 0 ? false : _a, _b = options.start, start = _b === void 0 ? true : _b, _c = options.end, end = _c === void 0 ? true : _c, _d = options.encode, encode = _d === void 0 ? function (x) { return x; } : _d;
|
|
7187
|
+
var endsWith = "[" + escapeString(options.endsWith || "") + "]|$";
|
|
7188
|
+
var delimiter = "[" + escapeString(options.delimiter || "/#?") + "]";
|
|
7189
|
+
var route = start ? "^" : "";
|
|
7190
|
+
// Iterate over the tokens and create our regexp string.
|
|
7191
|
+
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
7192
|
+
var token = tokens_1[_i];
|
|
7193
|
+
if (typeof token === "string") {
|
|
7194
|
+
route += escapeString(encode(token));
|
|
7195
|
+
}
|
|
7196
|
+
else {
|
|
7197
|
+
var prefix = escapeString(encode(token.prefix));
|
|
7198
|
+
var suffix = escapeString(encode(token.suffix));
|
|
7199
|
+
if (token.pattern) {
|
|
7200
|
+
if (keys)
|
|
7201
|
+
keys.push(token);
|
|
7202
|
+
if (prefix || suffix) {
|
|
7203
|
+
if (token.modifier === "+" || token.modifier === "*") {
|
|
7204
|
+
var mod = token.modifier === "*" ? "?" : "";
|
|
7205
|
+
route += "(?:" + prefix + "((?:" + token.pattern + ")(?:" + suffix + prefix + "(?:" + token.pattern + "))*)" + suffix + ")" + mod;
|
|
7206
|
+
}
|
|
7207
|
+
else {
|
|
7208
|
+
route += "(?:" + prefix + "(" + token.pattern + ")" + suffix + ")" + token.modifier;
|
|
7209
|
+
}
|
|
7210
|
+
}
|
|
7211
|
+
else {
|
|
7212
|
+
route += "(" + token.pattern + ")" + token.modifier;
|
|
7213
|
+
}
|
|
7214
|
+
}
|
|
7215
|
+
else {
|
|
7216
|
+
route += "(?:" + prefix + suffix + ")" + token.modifier;
|
|
7217
|
+
}
|
|
7218
|
+
}
|
|
7219
|
+
}
|
|
7220
|
+
if (end) {
|
|
7221
|
+
if (!strict)
|
|
7222
|
+
route += delimiter + "?";
|
|
7223
|
+
route += !options.endsWith ? "$" : "(?=" + endsWith + ")";
|
|
7224
|
+
}
|
|
7225
|
+
else {
|
|
7226
|
+
var endToken = tokens[tokens.length - 1];
|
|
7227
|
+
var isEndDelimited = typeof endToken === "string"
|
|
7228
|
+
? delimiter.indexOf(endToken[endToken.length - 1]) > -1
|
|
7229
|
+
: // tslint:disable-next-line
|
|
7230
|
+
endToken === undefined;
|
|
7231
|
+
if (!strict) {
|
|
7232
|
+
route += "(?:" + delimiter + "(?=" + endsWith + "))?";
|
|
7233
|
+
}
|
|
7234
|
+
if (!isEndDelimited) {
|
|
7235
|
+
route += "(?=" + delimiter + "|" + endsWith + ")";
|
|
7236
|
+
}
|
|
7237
|
+
}
|
|
7238
|
+
return new RegExp(route, flags(options));
|
|
7239
|
+
}
|
|
7240
|
+
/**
|
|
7241
|
+
* Normalize the given path string, returning a regular expression.
|
|
7242
|
+
*
|
|
7243
|
+
* An empty array can be passed in for the keys, which will hold the
|
|
7244
|
+
* placeholder key descriptions. For example, using `/user/:id`, `keys` will
|
|
7245
|
+
* contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
|
|
7246
|
+
*/
|
|
7247
|
+
function pathToRegexp(path, keys, options) {
|
|
7248
|
+
if (path instanceof RegExp)
|
|
7249
|
+
return regexpToRegexp(path, keys);
|
|
7250
|
+
if (Array.isArray(path))
|
|
7251
|
+
return arrayToRegexp(path, keys, options);
|
|
7252
|
+
return stringToRegexp(path, keys, options);
|
|
7332
7253
|
}
|
|
7333
|
-
getCleanUrl_2 = getCleanUrl$1.getCleanUrl = getCleanUrl;
|
|
7334
7254
|
|
|
7335
7255
|
const REDUNDANT_CHARACTERS_EXP = /[\?|#].*$/g;
|
|
7336
7256
|
function getSearchParams(path) {
|
|
@@ -7352,8 +7272,8 @@ function getAbsoluteUrl(path, baseUrl) {
|
|
|
7352
7272
|
return path;
|
|
7353
7273
|
}
|
|
7354
7274
|
// Resolve a relative request URL against a given custom "baseUrl"
|
|
7355
|
-
// or the
|
|
7356
|
-
const origin = baseUrl || (typeof
|
|
7275
|
+
// or the document baseURI (in the case of browser/browser-like environments).
|
|
7276
|
+
const origin = baseUrl || (typeof document !== 'undefined' && document.baseURI);
|
|
7357
7277
|
return origin
|
|
7358
7278
|
? // Encode and decode the path to preserve escaped characters.
|
|
7359
7279
|
decodeURI(new URL(encodeURI(path), origin).href)
|
|
@@ -7376,12 +7296,48 @@ function normalizePath(path, baseUrl) {
|
|
|
7376
7296
|
return cleanUrl(maybeAbsoluteUrl);
|
|
7377
7297
|
}
|
|
7378
7298
|
|
|
7299
|
+
/**
|
|
7300
|
+
* Coerce a path supported by MSW into a path
|
|
7301
|
+
* supported by "path-to-regexp".
|
|
7302
|
+
*/
|
|
7303
|
+
function coercePath(path) {
|
|
7304
|
+
return (path
|
|
7305
|
+
/**
|
|
7306
|
+
* Replace wildcards ("*") with unnamed capturing groups
|
|
7307
|
+
* because "path-to-regexp" doesn't support wildcards.
|
|
7308
|
+
* Ignore path parameter' modifiers (i.e. ":name*").
|
|
7309
|
+
*/
|
|
7310
|
+
.replace(/([:a-zA-Z_-]*)(\*{1,2})+/g, (_, parameterName, wildcard) => {
|
|
7311
|
+
const expression = '(.*)';
|
|
7312
|
+
if (!parameterName) {
|
|
7313
|
+
return expression;
|
|
7314
|
+
}
|
|
7315
|
+
return parameterName.startsWith(':')
|
|
7316
|
+
? `${parameterName}${wildcard}`
|
|
7317
|
+
: `${parameterName}${expression}`;
|
|
7318
|
+
})
|
|
7319
|
+
/**
|
|
7320
|
+
* Escape the protocol so that "path-to-regexp" could match
|
|
7321
|
+
* absolute URL.
|
|
7322
|
+
* @see https://github.com/pillarjs/path-to-regexp/issues/259
|
|
7323
|
+
*/
|
|
7324
|
+
.replace(/^([^\/]+)(:)(?=\/\/)/g, '$1\\$2'));
|
|
7325
|
+
}
|
|
7379
7326
|
/**
|
|
7380
7327
|
* Returns the result of matching given request URL against a mask.
|
|
7381
7328
|
*/
|
|
7382
7329
|
function matchRequestUrl(url, path, baseUrl) {
|
|
7383
7330
|
const normalizedPath = normalizePath(path, baseUrl);
|
|
7384
|
-
|
|
7331
|
+
const cleanPath = typeof normalizedPath === 'string'
|
|
7332
|
+
? coercePath(normalizedPath)
|
|
7333
|
+
: normalizedPath;
|
|
7334
|
+
const cleanUrl = getCleanUrl.getCleanUrl(url);
|
|
7335
|
+
const result = match(cleanPath, { decode: decodeURIComponent })(cleanUrl);
|
|
7336
|
+
const params = (result && result.params) || {};
|
|
7337
|
+
return {
|
|
7338
|
+
matches: result !== false,
|
|
7339
|
+
params,
|
|
7340
|
+
};
|
|
7385
7341
|
}
|
|
7386
7342
|
|
|
7387
7343
|
/**
|
|
@@ -7416,7 +7372,7 @@ const defaultResponseTransformers = [];
|
|
|
7416
7372
|
function createResponseComposition(responseOverrides, defaultTransformers = defaultResponseTransformers) {
|
|
7417
7373
|
return (...transformers) => __awaiter(this, void 0, void 0, function* () {
|
|
7418
7374
|
const initialResponse = Object.assign({}, defaultResponse, {
|
|
7419
|
-
headers: new lib$
|
|
7375
|
+
headers: new lib$1.Headers({
|
|
7420
7376
|
'x-powered-by': 'msw',
|
|
7421
7377
|
}),
|
|
7422
7378
|
}, responseOverrides);
|
|
@@ -7437,18 +7393,21 @@ const response = Object.assign(createResponseComposition(), {
|
|
|
7437
7393
|
},
|
|
7438
7394
|
});
|
|
7439
7395
|
|
|
7396
|
+
const BUILD_FRAME = /(node_modules)?[\/\\]lib[\/\\](umd|esm|iief|cjs)[\/\\]|^[^\/\\]*$/;
|
|
7440
7397
|
/**
|
|
7441
7398
|
* Return the stack trace frame of a function's invocation.
|
|
7442
7399
|
*/
|
|
7443
|
-
function getCallFrame() {
|
|
7400
|
+
function getCallFrame(error) {
|
|
7444
7401
|
// In <IE11, new Error may return an undefined stack
|
|
7445
|
-
const stack =
|
|
7446
|
-
|
|
7402
|
+
const stack = error.stack;
|
|
7403
|
+
if (!stack) {
|
|
7404
|
+
return;
|
|
7405
|
+
}
|
|
7406
|
+
const frames = stack.split('\n').slice(1);
|
|
7447
7407
|
// Get the first frame that doesn't reference the library's internal trace.
|
|
7448
7408
|
// Assume that frame is the invocation frame.
|
|
7449
|
-
const
|
|
7450
|
-
|
|
7451
|
-
return !ignoreFrameRegExp.test(frame);
|
|
7409
|
+
const declarationFrame = frames.find((frame) => {
|
|
7410
|
+
return !BUILD_FRAME.test(frame);
|
|
7452
7411
|
});
|
|
7453
7412
|
if (!declarationFrame) {
|
|
7454
7413
|
return;
|
|
@@ -7481,7 +7440,7 @@ class RequestHandler {
|
|
|
7481
7440
|
this.shouldSkip = false;
|
|
7482
7441
|
this.ctx = options.ctx || defaultContext;
|
|
7483
7442
|
this.resolver = options.resolver;
|
|
7484
|
-
const callFrame = getCallFrame();
|
|
7443
|
+
const callFrame = getCallFrame(new Error());
|
|
7485
7444
|
this.info = Object.assign(Object.assign({}, options.info), { callFrame });
|
|
7486
7445
|
}
|
|
7487
7446
|
/**
|
|
@@ -7608,21 +7567,9 @@ class RestHandler extends RequestHandler {
|
|
|
7608
7567
|
return;
|
|
7609
7568
|
}
|
|
7610
7569
|
const searchParams = getSearchParams(path);
|
|
7611
|
-
const queryParams = [];
|
|
7612
7570
|
searchParams.forEach((_, paramName) => {
|
|
7613
|
-
queryParams.push(paramName);
|
|
7614
7571
|
});
|
|
7615
|
-
devUtils.warn(
|
|
7616
|
-
Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead, and access query parameters in the response resolver function:
|
|
7617
|
-
|
|
7618
|
-
rest.${method.toLowerCase()}("${url}", (req, res, ctx) => {
|
|
7619
|
-
const query = req.url.searchParams
|
|
7620
|
-
${queryParams
|
|
7621
|
-
.map((paramName) => `\
|
|
7622
|
-
const ${paramName} = query.get("${paramName}")`)
|
|
7623
|
-
.join('\n')}
|
|
7624
|
-
})\
|
|
7625
|
-
`);
|
|
7572
|
+
devUtils.warn(`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters in the response resolver function using "req.url.searchParams".`);
|
|
7626
7573
|
}
|
|
7627
7574
|
parse(request, resolutionContext) {
|
|
7628
7575
|
return matchRequestUrl(request.url, this.info.path, resolutionContext === null || resolutionContext === void 0 ? void 0 : resolutionContext.baseUrl);
|
|
@@ -7631,7 +7578,10 @@ ${queryParams
|
|
|
7631
7578
|
return Object.assign(Object.assign({}, request), { params: parsedResult.params || {} });
|
|
7632
7579
|
}
|
|
7633
7580
|
predicate(request, parsedResult) {
|
|
7634
|
-
|
|
7581
|
+
const matchesMethod = this.info.method instanceof RegExp
|
|
7582
|
+
? this.info.method.test(request.method)
|
|
7583
|
+
: isStringEqual(this.info.method, request.method);
|
|
7584
|
+
return matchesMethod && parsedResult.matches;
|
|
7635
7585
|
}
|
|
7636
7586
|
log(request, response) {
|
|
7637
7587
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
@@ -7665,6 +7615,7 @@ const graphqlContext = {
|
|
|
7665
7615
|
delay,
|
|
7666
7616
|
fetch,
|
|
7667
7617
|
data,
|
|
7618
|
+
extensions,
|
|
7668
7619
|
errors,
|
|
7669
7620
|
cookie,
|
|
7670
7621
|
};
|
|
@@ -7711,10 +7662,10 @@ class GraphQLHandler extends RequestHandler {
|
|
|
7711
7662
|
if (!parsedResult) {
|
|
7712
7663
|
return false;
|
|
7713
7664
|
}
|
|
7714
|
-
if (!parsedResult.operationName) {
|
|
7665
|
+
if (!parsedResult.operationName && this.info.operationType !== 'all') {
|
|
7715
7666
|
const publicUrl = getPublicUrlFromRequest(request);
|
|
7716
7667
|
devUtils.warn(`\
|
|
7717
|
-
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}":
|
|
7668
|
+
Failed to intercept a GraphQL request at "${request.method} ${publicUrl}": anonymous GraphQL operations are not supported.
|
|
7718
7669
|
|
|
7719
7670
|
Consider naming this operation or using "graphql.operation" request handler to intercept GraphQL requests regardless of their operation name/type. Read more: https://mswjs.io/docs/api/graphql/operation\
|
|
7720
7671
|
`);
|
|
@@ -7724,7 +7675,7 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
7724
7675
|
const hasMatchingOperationType = this.info.operationType === 'all' ||
|
|
7725
7676
|
parsedResult.operationType === this.info.operationType;
|
|
7726
7677
|
const hasMatchingOperationName = this.info.operationName instanceof RegExp
|
|
7727
|
-
? this.info.operationName.test(parsedResult.operationName)
|
|
7678
|
+
? this.info.operationName.test(parsedResult.operationName || '')
|
|
7728
7679
|
: parsedResult.operationName === this.info.operationName;
|
|
7729
7680
|
return (hasMatchingUrl.matches &&
|
|
7730
7681
|
hasMatchingOperationType &&
|
|
@@ -7734,7 +7685,10 @@ Consider naming this operation or using "graphql.operation" request handler to i
|
|
|
7734
7685
|
const loggedRequest = prepareRequest(request);
|
|
7735
7686
|
const loggedResponse = prepareResponse(response);
|
|
7736
7687
|
const statusColor = getStatusCodeColor(response.status);
|
|
7737
|
-
|
|
7688
|
+
const requestInfo = (parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName)
|
|
7689
|
+
? `${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType} ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationName}`
|
|
7690
|
+
: `anonymous ${parsedRequest === null || parsedRequest === void 0 ? void 0 : parsedRequest.operationType}`;
|
|
7691
|
+
console.groupCollapsed(devUtils.formatMessage('%s %s (%c%s%c)'), getTimestamp(), `${requestInfo}`, `color:${statusColor}`, `${response.status} ${response.statusText}`, 'color:inherit');
|
|
7738
7692
|
console.log('Request:', loggedRequest);
|
|
7739
7693
|
console.log('Handler:', this);
|
|
7740
7694
|
console.log('Response:', loggedResponse);
|
|
@@ -7759,10 +7713,10 @@ function groupHandlersByType(handlers) {
|
|
|
7759
7713
|
graphql: [],
|
|
7760
7714
|
});
|
|
7761
7715
|
}
|
|
7762
|
-
function
|
|
7716
|
+
function getRestHandlerScore() {
|
|
7763
7717
|
return (request, handler) => {
|
|
7764
7718
|
const { path, method } = handler.info;
|
|
7765
|
-
if (path instanceof RegExp) {
|
|
7719
|
+
if (path instanceof RegExp || method instanceof RegExp) {
|
|
7766
7720
|
return Infinity;
|
|
7767
7721
|
}
|
|
7768
7722
|
const hasSameMethod = isStringEqual(request.method, method);
|
|
@@ -7773,12 +7727,15 @@ function getScoreForRestHandler() {
|
|
|
7773
7727
|
return score - methodScoreDelta;
|
|
7774
7728
|
};
|
|
7775
7729
|
}
|
|
7776
|
-
function
|
|
7730
|
+
function getGraphQLHandlerScore(parsedQuery) {
|
|
7777
7731
|
return (_, handler) => {
|
|
7778
7732
|
if (typeof parsedQuery.operationName === 'undefined') {
|
|
7779
7733
|
return Infinity;
|
|
7780
7734
|
}
|
|
7781
7735
|
const { operationType, operationName } = handler.info;
|
|
7736
|
+
if (typeof operationName !== 'string') {
|
|
7737
|
+
return Infinity;
|
|
7738
|
+
}
|
|
7782
7739
|
const hasSameOperationType = parsedQuery.operationType === operationType;
|
|
7783
7740
|
// Always treat a handler with the same operation type as a more similar one.
|
|
7784
7741
|
const operationTypeScoreDelta = hasSameOperationType ? TYPE_MATCH_DELTA : 0;
|
|
@@ -7788,16 +7745,12 @@ function getScoreForGraphQLHandler(parsedQuery) {
|
|
|
7788
7745
|
}
|
|
7789
7746
|
function getSuggestedHandler(request, handlers, getScore) {
|
|
7790
7747
|
const suggestedHandlers = handlers
|
|
7791
|
-
.reduce((
|
|
7748
|
+
.reduce((suggestions, handler) => {
|
|
7792
7749
|
const score = getScore(request, handler);
|
|
7793
|
-
return
|
|
7750
|
+
return suggestions.concat([[score, handler]]);
|
|
7794
7751
|
}, [])
|
|
7795
|
-
.sort(([leftScore], [rightScore]) =>
|
|
7796
|
-
|
|
7797
|
-
})
|
|
7798
|
-
.filter(([score]) => {
|
|
7799
|
-
return score <= MAX_MATCH_SCORE;
|
|
7800
|
-
})
|
|
7752
|
+
.sort(([leftScore], [rightScore]) => leftScore - rightScore)
|
|
7753
|
+
.filter(([score]) => score <= MAX_MATCH_SCORE)
|
|
7801
7754
|
.slice(0, MAX_SUGGESTION_COUNT)
|
|
7802
7755
|
.map(([, handler]) => handler);
|
|
7803
7756
|
return suggestedHandlers;
|
|
@@ -7827,8 +7780,8 @@ function onUnhandledRequest(request, handlers, strategy = 'warn') {
|
|
|
7827
7780
|
? handlerGroups.graphql
|
|
7828
7781
|
: handlerGroups.rest;
|
|
7829
7782
|
const suggestedHandlers = getSuggestedHandler(request, relevantHandlers, parsedGraphQLQuery
|
|
7830
|
-
?
|
|
7831
|
-
:
|
|
7783
|
+
? getGraphQLHandlerScore(parsedGraphQLQuery)
|
|
7784
|
+
: getRestHandlerScore());
|
|
7832
7785
|
const handlerSuggestion = suggestedHandlers.length > 0
|
|
7833
7786
|
? getSuggestedHandlersMessage(suggestedHandlers)
|
|
7834
7787
|
: '';
|
|
@@ -7851,7 +7804,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
7851
7804
|
// Print a developer-friendly error.
|
|
7852
7805
|
devUtils.error('Error: %s', message);
|
|
7853
7806
|
// Throw an exception to halt request processing and not perform the original request.
|
|
7854
|
-
throw new Error('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.');
|
|
7807
|
+
throw new Error(devUtils.formatMessage('Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'));
|
|
7855
7808
|
}
|
|
7856
7809
|
case 'warn': {
|
|
7857
7810
|
devUtils.warn('Warning: %s', message);
|
|
@@ -7865,8 +7818,8 @@ Read more: https://mswjs.io/docs/getting-started/mocks\
|
|
|
7865
7818
|
}
|
|
7866
7819
|
|
|
7867
7820
|
function readResponseCookies(request, response) {
|
|
7868
|
-
|
|
7869
|
-
|
|
7821
|
+
cookies.store.add(Object.assign(Object.assign({}, request), { url: request.url.toString() }), response);
|
|
7822
|
+
cookies.store.persist();
|
|
7870
7823
|
}
|
|
7871
7824
|
|
|
7872
7825
|
function handleRequest(request, handlers, options, emitter, handleRequestOptions) {
|
|
@@ -7894,7 +7847,12 @@ function handleRequest(request, handlers, options, emitter, handleRequestOptions
|
|
|
7894
7847
|
// When the handled request returned no mocked response, warn the developer,
|
|
7895
7848
|
// as it may be an oversight on their part. Perform the request as-is.
|
|
7896
7849
|
if (!response) {
|
|
7897
|
-
devUtils.warn(
|
|
7850
|
+
devUtils.warn(`\
|
|
7851
|
+
Expected response resolver to return a mocked response Object, but got %s. The original response is going to be used instead.\
|
|
7852
|
+
\n
|
|
7853
|
+
\u2022 %s
|
|
7854
|
+
%s\
|
|
7855
|
+
`, response, handler.info.header, handler.info.callFrame);
|
|
7898
7856
|
emitter.emit('request:end', request);
|
|
7899
7857
|
(_c = handleRequestOptions === null || handleRequestOptions === void 0 ? void 0 : handleRequestOptions.onBypassResponse) === null || _c === void 0 ? void 0 : _c.call(handleRequestOptions, request);
|
|
7900
7858
|
return;
|
|
@@ -7943,8 +7901,8 @@ const DEFAULT_LISTEN_OPTIONS = {
|
|
|
7943
7901
|
* Useful to generate identical API using different patches to request issuing modules.
|
|
7944
7902
|
*/
|
|
7945
7903
|
function createSetupServer(...interceptors$1) {
|
|
7946
|
-
const emitter = new lib$
|
|
7947
|
-
const publicEmitter = new lib$
|
|
7904
|
+
const emitter = new lib$2.StrictEventEmitter();
|
|
7905
|
+
const publicEmitter = new lib$2.StrictEventEmitter();
|
|
7948
7906
|
pipeEvents(emitter, publicEmitter);
|
|
7949
7907
|
return function setupServer(...requestHandlers) {
|
|
7950
7908
|
requestHandlers.forEach((handler) => {
|
|
@@ -7955,7 +7913,7 @@ function createSetupServer(...interceptors$1) {
|
|
|
7955
7913
|
// so it could be modified at a runtime.
|
|
7956
7914
|
let currentHandlers = [...requestHandlers];
|
|
7957
7915
|
// Error when attempting to run this function in a browser environment.
|
|
7958
|
-
if (!lib$
|
|
7916
|
+
if (!lib$3.exports.isNodeProcess()) {
|
|
7959
7917
|
throw new Error(devUtils.formatMessage('Failed to execute `setupServer` in the environment that is not Node.js (i.e. a browser). Consider using `setupWorker` instead.'));
|
|
7960
7918
|
}
|
|
7961
7919
|
let resolvedOptions = {};
|
|
@@ -7978,15 +7936,14 @@ function createSetupServer(...interceptors$1) {
|
|
|
7978
7936
|
},
|
|
7979
7937
|
});
|
|
7980
7938
|
interceptor.on('response', (request, response) => {
|
|
7981
|
-
|
|
7982
|
-
if (!requestId) {
|
|
7939
|
+
if (!request.id) {
|
|
7983
7940
|
return;
|
|
7984
7941
|
}
|
|
7985
7942
|
if (response.headers.get('x-powered-by') === 'msw') {
|
|
7986
|
-
emitter.emit('response:mocked', response,
|
|
7943
|
+
emitter.emit('response:mocked', response, request.id);
|
|
7987
7944
|
}
|
|
7988
7945
|
else {
|
|
7989
|
-
emitter.emit('response:bypass', response,
|
|
7946
|
+
emitter.emit('response:bypass', response, request.id);
|
|
7990
7947
|
}
|
|
7991
7948
|
});
|
|
7992
7949
|
return {
|