msw 2.4.3 → 2.4.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/lib/browser/index.js +505 -253
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +507 -255
- package/lib/browser/index.mjs.map +1 -1
- package/lib/iife/index.js +527 -275
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +15 -12
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +15 -12
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +15 -12
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +15 -12
- package/lib/node/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +2 -2
- package/src/node/SetupServerCommonApi.ts +17 -14
package/lib/iife/index.js
CHANGED
|
@@ -77,7 +77,7 @@ var MockServiceWorker = (() => {
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
// node_modules/.pnpm/graphql@16.9.0/node_modules/graphql/jsutils/invariant.mjs
|
|
80
|
-
function
|
|
80
|
+
function invariant3(condition, message3) {
|
|
81
81
|
const booleanCondition = Boolean(condition);
|
|
82
82
|
if (!booleanCondition) {
|
|
83
83
|
throw new Error(
|
|
@@ -96,7 +96,7 @@ var MockServiceWorker = (() => {
|
|
|
96
96
|
let lastLineStart = 0;
|
|
97
97
|
let line = 1;
|
|
98
98
|
for (const match2 of source.body.matchAll(LineRegExp)) {
|
|
99
|
-
typeof match2.index === "number" ||
|
|
99
|
+
typeof match2.index === "number" || invariant3(false);
|
|
100
100
|
if (match2.index >= position) {
|
|
101
101
|
break;
|
|
102
102
|
}
|
|
@@ -4968,7 +4968,7 @@ spurious results.`);
|
|
|
4968
4968
|
}
|
|
4969
4969
|
throw new TypeError(`Cannot convert value to AST: ${inspect(serialized)}.`);
|
|
4970
4970
|
}
|
|
4971
|
-
|
|
4971
|
+
invariant3(false, "Unexpected input type: " + inspect(type));
|
|
4972
4972
|
}
|
|
4973
4973
|
var integerStringRegExp;
|
|
4974
4974
|
var init_astFromValue = __esm({
|
|
@@ -5190,7 +5190,7 @@ spurious results.`);
|
|
|
5190
5190
|
if (isNonNullType(type)) {
|
|
5191
5191
|
return TypeKind.NON_NULL;
|
|
5192
5192
|
}
|
|
5193
|
-
|
|
5193
|
+
invariant3(false, `Unexpected type: "${inspect(type)}".`);
|
|
5194
5194
|
}
|
|
5195
5195
|
},
|
|
5196
5196
|
name: {
|
|
@@ -6760,7 +6760,7 @@ spurious results.`);
|
|
|
6760
6760
|
}
|
|
6761
6761
|
function getDirectiveLocationForASTPath(ancestors) {
|
|
6762
6762
|
const appliedTo = ancestors[ancestors.length - 1];
|
|
6763
|
-
"kind" in appliedTo ||
|
|
6763
|
+
"kind" in appliedTo || invariant3(false);
|
|
6764
6764
|
switch (appliedTo.kind) {
|
|
6765
6765
|
case Kind.OPERATION_DEFINITION:
|
|
6766
6766
|
return getDirectiveLocationForOperation(appliedTo.operation);
|
|
@@ -6801,11 +6801,11 @@ spurious results.`);
|
|
|
6801
6801
|
return DirectiveLocation.INPUT_OBJECT;
|
|
6802
6802
|
case Kind.INPUT_VALUE_DEFINITION: {
|
|
6803
6803
|
const parentNode = ancestors[ancestors.length - 3];
|
|
6804
|
-
"kind" in parentNode ||
|
|
6804
|
+
"kind" in parentNode || invariant3(false);
|
|
6805
6805
|
return parentNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ? DirectiveLocation.INPUT_FIELD_DEFINITION : DirectiveLocation.ARGUMENT_DEFINITION;
|
|
6806
6806
|
}
|
|
6807
6807
|
default:
|
|
6808
|
-
|
|
6808
|
+
invariant3(false, "Unexpected kind: " + inspect(appliedTo.kind));
|
|
6809
6809
|
}
|
|
6810
6810
|
}
|
|
6811
6811
|
function getDirectiveLocationForOperation(operation) {
|
|
@@ -7875,7 +7875,7 @@ spurious results.`);
|
|
|
7875
7875
|
if (isInputObjectType(type)) {
|
|
7876
7876
|
return Kind.INPUT_OBJECT_TYPE_EXTENSION;
|
|
7877
7877
|
}
|
|
7878
|
-
|
|
7878
|
+
invariant3(false, "Unexpected type: " + inspect(type));
|
|
7879
7879
|
}
|
|
7880
7880
|
function extensionKindToTypeName(kind) {
|
|
7881
7881
|
switch (kind) {
|
|
@@ -7892,7 +7892,7 @@ spurious results.`);
|
|
|
7892
7892
|
case Kind.INPUT_OBJECT_TYPE_EXTENSION:
|
|
7893
7893
|
return "input object";
|
|
7894
7894
|
default:
|
|
7895
|
-
|
|
7895
|
+
invariant3(false, "Unexpected kind: " + inspect(kind));
|
|
7896
7896
|
}
|
|
7897
7897
|
}
|
|
7898
7898
|
var defKindToExtKind;
|
|
@@ -8238,7 +8238,7 @@ spurious results.`);
|
|
|
8238
8238
|
}
|
|
8239
8239
|
return parseResult;
|
|
8240
8240
|
}
|
|
8241
|
-
|
|
8241
|
+
invariant3(false, "Unexpected input type: " + inspect(type));
|
|
8242
8242
|
}
|
|
8243
8243
|
var init_coerceInputValue = __esm({
|
|
8244
8244
|
"node_modules/.pnpm/graphql@16.9.0/node_modules/graphql/utilities/coerceInputValue.mjs"() {
|
|
@@ -8352,7 +8352,7 @@ spurious results.`);
|
|
|
8352
8352
|
}
|
|
8353
8353
|
return result;
|
|
8354
8354
|
}
|
|
8355
|
-
|
|
8355
|
+
invariant3(false, "Unexpected input type: " + inspect(type));
|
|
8356
8356
|
}
|
|
8357
8357
|
function isMissingVariable(valueNode, variables) {
|
|
8358
8358
|
return valueNode.kind === Kind.VARIABLE && (variables == null || variables[valueNode.name.value] === void 0);
|
|
@@ -9114,7 +9114,7 @@ spurious results.`);
|
|
|
9114
9114
|
},
|
|
9115
9115
|
leave() {
|
|
9116
9116
|
const prevKnownNames = knownNameStack.pop();
|
|
9117
|
-
prevKnownNames ||
|
|
9117
|
+
prevKnownNames || invariant3(false);
|
|
9118
9118
|
knownNames = prevKnownNames;
|
|
9119
9119
|
}
|
|
9120
9120
|
},
|
|
@@ -10383,7 +10383,7 @@ spurious results.`);
|
|
|
10383
10383
|
result
|
|
10384
10384
|
);
|
|
10385
10385
|
}
|
|
10386
|
-
|
|
10386
|
+
invariant3(
|
|
10387
10387
|
false,
|
|
10388
10388
|
"Cannot complete value of unexpected output type: " + inspect(returnType)
|
|
10389
10389
|
);
|
|
@@ -10950,7 +10950,7 @@ spurious results.`);
|
|
|
10950
10950
|
const deprecationReason = fieldDef === null || fieldDef === void 0 ? void 0 : fieldDef.deprecationReason;
|
|
10951
10951
|
if (fieldDef && deprecationReason != null) {
|
|
10952
10952
|
const parentType = context.getParentType();
|
|
10953
|
-
parentType != null ||
|
|
10953
|
+
parentType != null || invariant3(false);
|
|
10954
10954
|
context.reportError(
|
|
10955
10955
|
new GraphQLError(
|
|
10956
10956
|
`The field ${parentType.name}.${fieldDef.name} is deprecated. ${deprecationReason}`,
|
|
@@ -10978,7 +10978,7 @@ spurious results.`);
|
|
|
10978
10978
|
} else {
|
|
10979
10979
|
const parentType = context.getParentType();
|
|
10980
10980
|
const fieldDef = context.getFieldDef();
|
|
10981
|
-
parentType != null && fieldDef != null ||
|
|
10981
|
+
parentType != null && fieldDef != null || invariant3(false);
|
|
10982
10982
|
context.reportError(
|
|
10983
10983
|
new GraphQLError(
|
|
10984
10984
|
`Field "${parentType.name}.${fieldDef.name}" argument "${argDef.name}" is deprecated. ${deprecationReason}`,
|
|
@@ -11012,7 +11012,7 @@ spurious results.`);
|
|
|
11012
11012
|
const deprecationReason = enumValueDef === null || enumValueDef === void 0 ? void 0 : enumValueDef.deprecationReason;
|
|
11013
11013
|
if (enumValueDef && deprecationReason != null) {
|
|
11014
11014
|
const enumTypeDef = getNamedType(context.getInputType());
|
|
11015
|
-
enumTypeDef != null ||
|
|
11015
|
+
enumTypeDef != null || invariant3(false);
|
|
11016
11016
|
context.reportError(
|
|
11017
11017
|
new GraphQLError(
|
|
11018
11018
|
`The enum value "${enumTypeDef.name}.${enumValueDef.name}" is deprecated. ${deprecationReason}`,
|
|
@@ -11337,7 +11337,7 @@ spurious results.`);
|
|
|
11337
11337
|
schema,
|
|
11338
11338
|
document: document2
|
|
11339
11339
|
});
|
|
11340
|
-
!result.errors && result.data ||
|
|
11340
|
+
!result.errors && result.data || invariant3(false);
|
|
11341
11341
|
return result.data;
|
|
11342
11342
|
}
|
|
11343
11343
|
var init_introspectionFromSchema = __esm({
|
|
@@ -11726,7 +11726,7 @@ spurious results.`);
|
|
|
11726
11726
|
if (isInputObjectType(type)) {
|
|
11727
11727
|
return extendInputObjectType(type);
|
|
11728
11728
|
}
|
|
11729
|
-
|
|
11729
|
+
invariant3(false, "Unexpected type: " + inspect(type));
|
|
11730
11730
|
}
|
|
11731
11731
|
function extendInputObjectType(type) {
|
|
11732
11732
|
var _typeExtensionsMap$co;
|
|
@@ -12253,7 +12253,7 @@ spurious results.`);
|
|
|
12253
12253
|
fields: () => sortInputFields(config.fields)
|
|
12254
12254
|
});
|
|
12255
12255
|
}
|
|
12256
|
-
|
|
12256
|
+
invariant3(false, "Unexpected type: " + inspect(type));
|
|
12257
12257
|
}
|
|
12258
12258
|
}
|
|
12259
12259
|
function sortObjMap(map, sortValueFn) {
|
|
@@ -12365,7 +12365,7 @@ ${operationTypes.join("\n")}
|
|
|
12365
12365
|
if (isInputObjectType(type)) {
|
|
12366
12366
|
return printInputObject(type);
|
|
12367
12367
|
}
|
|
12368
|
-
|
|
12368
|
+
invariant3(false, "Unexpected type: " + inspect(type));
|
|
12369
12369
|
}
|
|
12370
12370
|
function printScalar(type) {
|
|
12371
12371
|
return printDescription(type) + `scalar ${type.name}` + printSpecifiedByURL(type);
|
|
@@ -12952,11 +12952,11 @@ ${operationTypes.join("\n")}
|
|
|
12952
12952
|
if (isInputObjectType(type)) {
|
|
12953
12953
|
return "an Input type";
|
|
12954
12954
|
}
|
|
12955
|
-
|
|
12955
|
+
invariant3(false, "Unexpected type: " + inspect(type));
|
|
12956
12956
|
}
|
|
12957
12957
|
function stringifyValue2(value, type) {
|
|
12958
12958
|
const ast = astFromValue(value, type);
|
|
12959
|
-
ast != null ||
|
|
12959
|
+
ast != null || invariant3(false);
|
|
12960
12960
|
return print(sortValueNode(ast));
|
|
12961
12961
|
}
|
|
12962
12962
|
function diff(oldArray, newArray) {
|
|
@@ -14388,7 +14388,7 @@ ${operationTypes.join("\n")}
|
|
|
14388
14388
|
return stringToRegexp(path, keys, options);
|
|
14389
14389
|
}
|
|
14390
14390
|
|
|
14391
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14391
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.35.0/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
|
|
14392
14392
|
var encoder = new TextEncoder();
|
|
14393
14393
|
function encodeBuffer(text) {
|
|
14394
14394
|
return encoder.encode(text);
|
|
@@ -14404,7 +14404,7 @@ ${operationTypes.join("\n")}
|
|
|
14404
14404
|
);
|
|
14405
14405
|
}
|
|
14406
14406
|
|
|
14407
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14407
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.35.0/node_modules/@mswjs/interceptors/lib/browser/chunk-XVPRNJO7.mjs
|
|
14408
14408
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
14409
14409
|
function isPropertyAccessible(obj, key) {
|
|
14410
14410
|
try {
|
|
@@ -14421,6 +14421,13 @@ ${operationTypes.join("\n")}
|
|
|
14421
14421
|
205,
|
|
14422
14422
|
304
|
|
14423
14423
|
]);
|
|
14424
|
+
var RESPONSE_STATUS_CODES_WITH_REDIRECT = /* @__PURE__ */ new Set([
|
|
14425
|
+
301,
|
|
14426
|
+
302,
|
|
14427
|
+
303,
|
|
14428
|
+
307,
|
|
14429
|
+
308
|
|
14430
|
+
]);
|
|
14424
14431
|
function isResponseWithoutBody(status) {
|
|
14425
14432
|
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
14426
14433
|
}
|
|
@@ -14461,6 +14468,90 @@ ${operationTypes.join("\n")}
|
|
|
14461
14468
|
return false;
|
|
14462
14469
|
}
|
|
14463
14470
|
|
|
14471
|
+
// node_modules/.pnpm/outvariant@1.4.3/node_modules/outvariant/lib/index.mjs
|
|
14472
|
+
var POSITIONALS_EXP2 = /(%?)(%([sdijo]))/g;
|
|
14473
|
+
function serializePositional2(positional, flag) {
|
|
14474
|
+
switch (flag) {
|
|
14475
|
+
case "s":
|
|
14476
|
+
return positional;
|
|
14477
|
+
case "d":
|
|
14478
|
+
case "i":
|
|
14479
|
+
return Number(positional);
|
|
14480
|
+
case "j":
|
|
14481
|
+
return JSON.stringify(positional);
|
|
14482
|
+
case "o": {
|
|
14483
|
+
if (typeof positional === "string") {
|
|
14484
|
+
return positional;
|
|
14485
|
+
}
|
|
14486
|
+
const json = JSON.stringify(positional);
|
|
14487
|
+
if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) {
|
|
14488
|
+
return positional;
|
|
14489
|
+
}
|
|
14490
|
+
return json;
|
|
14491
|
+
}
|
|
14492
|
+
}
|
|
14493
|
+
}
|
|
14494
|
+
function format2(message3, ...positionals) {
|
|
14495
|
+
if (positionals.length === 0) {
|
|
14496
|
+
return message3;
|
|
14497
|
+
}
|
|
14498
|
+
let positionalIndex = 0;
|
|
14499
|
+
let formattedMessage = message3.replace(
|
|
14500
|
+
POSITIONALS_EXP2,
|
|
14501
|
+
(match2, isEscaped, _, flag) => {
|
|
14502
|
+
const positional = positionals[positionalIndex];
|
|
14503
|
+
const value = serializePositional2(positional, flag);
|
|
14504
|
+
if (!isEscaped) {
|
|
14505
|
+
positionalIndex++;
|
|
14506
|
+
return value;
|
|
14507
|
+
}
|
|
14508
|
+
return match2;
|
|
14509
|
+
}
|
|
14510
|
+
);
|
|
14511
|
+
if (positionalIndex < positionals.length) {
|
|
14512
|
+
formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;
|
|
14513
|
+
}
|
|
14514
|
+
formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
|
|
14515
|
+
return formattedMessage;
|
|
14516
|
+
}
|
|
14517
|
+
var STACK_FRAMES_TO_IGNORE2 = 2;
|
|
14518
|
+
function cleanErrorStack2(error3) {
|
|
14519
|
+
if (!error3.stack) {
|
|
14520
|
+
return;
|
|
14521
|
+
}
|
|
14522
|
+
const nextStack = error3.stack.split("\n");
|
|
14523
|
+
nextStack.splice(1, STACK_FRAMES_TO_IGNORE2);
|
|
14524
|
+
error3.stack = nextStack.join("\n");
|
|
14525
|
+
}
|
|
14526
|
+
var InvariantError2 = class extends Error {
|
|
14527
|
+
constructor(message3, ...positionals) {
|
|
14528
|
+
super(message3);
|
|
14529
|
+
this.message = message3;
|
|
14530
|
+
this.name = "Invariant Violation";
|
|
14531
|
+
this.message = format2(message3, ...positionals);
|
|
14532
|
+
cleanErrorStack2(this);
|
|
14533
|
+
}
|
|
14534
|
+
};
|
|
14535
|
+
var invariant2 = (predicate, message3, ...positionals) => {
|
|
14536
|
+
if (!predicate) {
|
|
14537
|
+
throw new InvariantError2(message3, ...positionals);
|
|
14538
|
+
}
|
|
14539
|
+
};
|
|
14540
|
+
invariant2.as = (ErrorConstructor, predicate, message3, ...positionals) => {
|
|
14541
|
+
if (!predicate) {
|
|
14542
|
+
const formatMessage2 = positionals.length === 0 ? message3 : format2(message3, ...positionals);
|
|
14543
|
+
let error3;
|
|
14544
|
+
try {
|
|
14545
|
+
error3 = Reflect.construct(ErrorConstructor, [
|
|
14546
|
+
formatMessage2
|
|
14547
|
+
]);
|
|
14548
|
+
} catch (err) {
|
|
14549
|
+
error3 = ErrorConstructor(formatMessage2);
|
|
14550
|
+
}
|
|
14551
|
+
throw error3;
|
|
14552
|
+
}
|
|
14553
|
+
};
|
|
14554
|
+
|
|
14464
14555
|
// node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
|
|
14465
14556
|
var __defProp3 = Object.defineProperty;
|
|
14466
14557
|
var __export2 = (target, all) => {
|
|
@@ -14689,21 +14780,21 @@ ${operationTypes.join("\n")}
|
|
|
14689
14780
|
var noop = () => void 0;
|
|
14690
14781
|
function log(message3, ...positionals) {
|
|
14691
14782
|
if (IS_NODE) {
|
|
14692
|
-
process.stdout.write(
|
|
14783
|
+
process.stdout.write(format2(message3, ...positionals) + "\n");
|
|
14693
14784
|
return;
|
|
14694
14785
|
}
|
|
14695
14786
|
console.log(message3, ...positionals);
|
|
14696
14787
|
}
|
|
14697
14788
|
function warn2(message3, ...positionals) {
|
|
14698
14789
|
if (IS_NODE) {
|
|
14699
|
-
process.stderr.write(
|
|
14790
|
+
process.stderr.write(format2(message3, ...positionals) + "\n");
|
|
14700
14791
|
return;
|
|
14701
14792
|
}
|
|
14702
14793
|
console.warn(message3, ...positionals);
|
|
14703
14794
|
}
|
|
14704
14795
|
function error2(message3, ...positionals) {
|
|
14705
14796
|
if (IS_NODE) {
|
|
14706
|
-
process.stderr.write(
|
|
14797
|
+
process.stderr.write(format2(message3, ...positionals) + "\n");
|
|
14707
14798
|
return;
|
|
14708
14799
|
}
|
|
14709
14800
|
console.error(message3, ...positionals);
|
|
@@ -14733,7 +14824,7 @@ ${operationTypes.join("\n")}
|
|
|
14733
14824
|
return message3.toString();
|
|
14734
14825
|
}
|
|
14735
14826
|
|
|
14736
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14827
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.35.0/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
14737
14828
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
14738
14829
|
function getGlobalSymbol(symbol) {
|
|
14739
14830
|
return (
|
|
@@ -14881,7 +14972,7 @@ ${operationTypes.join("\n")}
|
|
|
14881
14972
|
return Math.random().toString(16).slice(2);
|
|
14882
14973
|
}
|
|
14883
14974
|
|
|
14884
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14975
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.35.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
14885
14976
|
var BatchInterceptor = class extends Interceptor {
|
|
14886
14977
|
constructor(options) {
|
|
14887
14978
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -29010,34 +29101,58 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29010
29101
|
}
|
|
29011
29102
|
};
|
|
29012
29103
|
|
|
29013
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29104
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.35.0/node_modules/@mswjs/interceptors/lib/browser/chunk-THPGBWJQ.mjs
|
|
29105
|
+
var InterceptorError = class extends Error {
|
|
29106
|
+
constructor(message3) {
|
|
29107
|
+
super(message3);
|
|
29108
|
+
this.name = "InterceptorError";
|
|
29109
|
+
Object.setPrototypeOf(this, InterceptorError.prototype);
|
|
29110
|
+
}
|
|
29111
|
+
};
|
|
29112
|
+
var kRequestHandled = Symbol("kRequestHandled");
|
|
29113
|
+
var kResponsePromise = Symbol("kResponsePromise");
|
|
29014
29114
|
var RequestController = class {
|
|
29015
29115
|
constructor(request) {
|
|
29016
29116
|
this.request = request;
|
|
29017
|
-
this
|
|
29117
|
+
this[kRequestHandled] = false;
|
|
29118
|
+
this[kResponsePromise] = new DeferredPromise();
|
|
29018
29119
|
}
|
|
29120
|
+
/**
|
|
29121
|
+
* Respond to this request with the given `Response` instance.
|
|
29122
|
+
* @example
|
|
29123
|
+
* controller.respondWith(new Response())
|
|
29124
|
+
* controller.respondWith(Response.json({ id }))
|
|
29125
|
+
* controller.respondWith(Response.error())
|
|
29126
|
+
*/
|
|
29019
29127
|
respondWith(response) {
|
|
29020
|
-
|
|
29021
|
-
|
|
29022
|
-
|
|
29128
|
+
invariant2.as(
|
|
29129
|
+
InterceptorError,
|
|
29130
|
+
!this[kRequestHandled],
|
|
29131
|
+
'Failed to respond to the "%s %s" request: the "request" event has already been handled.',
|
|
29132
|
+
this.request.method,
|
|
29133
|
+
this.request.url
|
|
29134
|
+
);
|
|
29135
|
+
this[kRequestHandled] = true;
|
|
29136
|
+
this[kResponsePromise].resolve(response);
|
|
29137
|
+
}
|
|
29138
|
+
/**
|
|
29139
|
+
* Error this request with the given error.
|
|
29140
|
+
* @example
|
|
29141
|
+
* controller.errorWith()
|
|
29142
|
+
* controller.errorWith(new Error('Oops!'))
|
|
29143
|
+
*/
|
|
29144
|
+
errorWith(error3) {
|
|
29145
|
+
invariant2.as(
|
|
29146
|
+
InterceptorError,
|
|
29147
|
+
!this[kRequestHandled],
|
|
29148
|
+
'Failed to error the "%s %s" request: the "request" event has already been handled.',
|
|
29023
29149
|
this.request.method,
|
|
29024
29150
|
this.request.url
|
|
29025
29151
|
);
|
|
29026
|
-
this
|
|
29152
|
+
this[kRequestHandled] = true;
|
|
29153
|
+
this[kResponsePromise].resolve(error3);
|
|
29027
29154
|
}
|
|
29028
29155
|
};
|
|
29029
|
-
function toInteractiveRequest(request) {
|
|
29030
|
-
const requestController = new RequestController(request);
|
|
29031
|
-
Reflect.set(
|
|
29032
|
-
request,
|
|
29033
|
-
"respondWith",
|
|
29034
|
-
requestController.respondWith.bind(requestController)
|
|
29035
|
-
);
|
|
29036
|
-
return {
|
|
29037
|
-
interactiveRequest: request,
|
|
29038
|
-
requestController
|
|
29039
|
-
};
|
|
29040
|
-
}
|
|
29041
29156
|
async function emitAsync(emitter, eventName, ...data) {
|
|
29042
29157
|
const listners = emitter.listeners(eventName);
|
|
29043
29158
|
if (listners.length === 0) {
|
|
@@ -29047,8 +29162,114 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29047
29162
|
await listener.apply(emitter, data);
|
|
29048
29163
|
}
|
|
29049
29164
|
}
|
|
29165
|
+
function isNodeLikeError(error3) {
|
|
29166
|
+
if (error3 == null) {
|
|
29167
|
+
return false;
|
|
29168
|
+
}
|
|
29169
|
+
if (!(error3 instanceof Error)) {
|
|
29170
|
+
return false;
|
|
29171
|
+
}
|
|
29172
|
+
return "code" in error3 && "errno" in error3;
|
|
29173
|
+
}
|
|
29174
|
+
async function handleRequest2(options) {
|
|
29175
|
+
const handleResponse = async (response) => {
|
|
29176
|
+
if (response instanceof Error) {
|
|
29177
|
+
options.onError(response);
|
|
29178
|
+
} else if (isResponseError(response)) {
|
|
29179
|
+
options.onRequestError(response);
|
|
29180
|
+
} else {
|
|
29181
|
+
await options.onResponse(response);
|
|
29182
|
+
}
|
|
29183
|
+
return true;
|
|
29184
|
+
};
|
|
29185
|
+
const handleResponseError = async (error3) => {
|
|
29186
|
+
if (error3 instanceof InterceptorError) {
|
|
29187
|
+
throw result.error;
|
|
29188
|
+
}
|
|
29189
|
+
if (isNodeLikeError(error3)) {
|
|
29190
|
+
options.onError(error3);
|
|
29191
|
+
return true;
|
|
29192
|
+
}
|
|
29193
|
+
if (error3 instanceof Response) {
|
|
29194
|
+
return await handleResponse(error3);
|
|
29195
|
+
}
|
|
29196
|
+
return false;
|
|
29197
|
+
};
|
|
29198
|
+
options.emitter.once("request", ({ requestId: pendingRequestId }) => {
|
|
29199
|
+
if (pendingRequestId !== options.requestId) {
|
|
29200
|
+
return;
|
|
29201
|
+
}
|
|
29202
|
+
if (options.controller[kResponsePromise].state === "pending") {
|
|
29203
|
+
options.controller[kResponsePromise].resolve(void 0);
|
|
29204
|
+
}
|
|
29205
|
+
});
|
|
29206
|
+
const requestAbortPromise = new DeferredPromise();
|
|
29207
|
+
if (options.request.signal) {
|
|
29208
|
+
options.request.signal.addEventListener(
|
|
29209
|
+
"abort",
|
|
29210
|
+
() => {
|
|
29211
|
+
requestAbortPromise.reject(options.request.signal.reason);
|
|
29212
|
+
},
|
|
29213
|
+
{ once: true }
|
|
29214
|
+
);
|
|
29215
|
+
}
|
|
29216
|
+
const result = await until(async () => {
|
|
29217
|
+
const requestListtenersPromise = emitAsync(options.emitter, "request", {
|
|
29218
|
+
requestId: options.requestId,
|
|
29219
|
+
request: options.request,
|
|
29220
|
+
controller: options.controller
|
|
29221
|
+
});
|
|
29222
|
+
await Promise.race([
|
|
29223
|
+
// Short-circuit the request handling promise if the request gets aborted.
|
|
29224
|
+
requestAbortPromise,
|
|
29225
|
+
requestListtenersPromise,
|
|
29226
|
+
options.controller[kResponsePromise]
|
|
29227
|
+
]);
|
|
29228
|
+
const mockedResponse = await options.controller[kResponsePromise];
|
|
29229
|
+
return mockedResponse;
|
|
29230
|
+
});
|
|
29231
|
+
if (requestAbortPromise.state === "rejected") {
|
|
29232
|
+
options.onError(requestAbortPromise.rejectionReason);
|
|
29233
|
+
return true;
|
|
29234
|
+
}
|
|
29235
|
+
if (result.error) {
|
|
29236
|
+
if (await handleResponseError(result.error)) {
|
|
29237
|
+
return true;
|
|
29238
|
+
}
|
|
29239
|
+
if (options.emitter.listenerCount("unhandledException") > 0) {
|
|
29240
|
+
const unhandledExceptionController = new RequestController(
|
|
29241
|
+
options.request
|
|
29242
|
+
);
|
|
29243
|
+
await emitAsync(options.emitter, "unhandledException", {
|
|
29244
|
+
error: result.error,
|
|
29245
|
+
request: options.request,
|
|
29246
|
+
requestId: options.requestId,
|
|
29247
|
+
controller: unhandledExceptionController
|
|
29248
|
+
}).then(() => {
|
|
29249
|
+
if (unhandledExceptionController[kResponsePromise].state === "pending") {
|
|
29250
|
+
unhandledExceptionController[kResponsePromise].resolve(void 0);
|
|
29251
|
+
}
|
|
29252
|
+
});
|
|
29253
|
+
const nextResult = await until(
|
|
29254
|
+
() => unhandledExceptionController[kResponsePromise]
|
|
29255
|
+
);
|
|
29256
|
+
if (nextResult.error) {
|
|
29257
|
+
return handleResponseError(nextResult.error);
|
|
29258
|
+
}
|
|
29259
|
+
if (nextResult.data) {
|
|
29260
|
+
return handleResponse(nextResult.data);
|
|
29261
|
+
}
|
|
29262
|
+
}
|
|
29263
|
+
options.onResponse(createServerErrorResponse(result.error));
|
|
29264
|
+
return true;
|
|
29265
|
+
}
|
|
29266
|
+
if (result.data) {
|
|
29267
|
+
return handleResponse(result.data);
|
|
29268
|
+
}
|
|
29269
|
+
return false;
|
|
29270
|
+
}
|
|
29050
29271
|
|
|
29051
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29272
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.35.0/node_modules/@mswjs/interceptors/lib/browser/chunk-DZCGGRSJ.mjs
|
|
29052
29273
|
function canParseUrl(url) {
|
|
29053
29274
|
try {
|
|
29054
29275
|
new URL(url);
|
|
@@ -29057,6 +29278,72 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29057
29278
|
return false;
|
|
29058
29279
|
}
|
|
29059
29280
|
}
|
|
29281
|
+
function createNetworkError(cause) {
|
|
29282
|
+
return Object.assign(new TypeError("Failed to fetch"), {
|
|
29283
|
+
cause
|
|
29284
|
+
});
|
|
29285
|
+
}
|
|
29286
|
+
var REQUEST_BODY_HEADERS = [
|
|
29287
|
+
"content-encoding",
|
|
29288
|
+
"content-language",
|
|
29289
|
+
"content-location",
|
|
29290
|
+
"content-type",
|
|
29291
|
+
"content-length"
|
|
29292
|
+
];
|
|
29293
|
+
var kRedirectCount = Symbol("kRedirectCount");
|
|
29294
|
+
async function followFetchRedirect(request, response) {
|
|
29295
|
+
if (response.status !== 303 && request.body != null) {
|
|
29296
|
+
return Promise.reject(createNetworkError());
|
|
29297
|
+
}
|
|
29298
|
+
const requestUrl = new URL(request.url);
|
|
29299
|
+
let locationUrl;
|
|
29300
|
+
try {
|
|
29301
|
+
locationUrl = new URL(response.headers.get("location"));
|
|
29302
|
+
} catch (error3) {
|
|
29303
|
+
return Promise.reject(createNetworkError(error3));
|
|
29304
|
+
}
|
|
29305
|
+
if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) {
|
|
29306
|
+
return Promise.reject(
|
|
29307
|
+
createNetworkError("URL scheme must be a HTTP(S) scheme")
|
|
29308
|
+
);
|
|
29309
|
+
}
|
|
29310
|
+
if (Reflect.get(request, kRedirectCount) > 20) {
|
|
29311
|
+
return Promise.reject(createNetworkError("redirect count exceeded"));
|
|
29312
|
+
}
|
|
29313
|
+
Object.defineProperty(request, kRedirectCount, {
|
|
29314
|
+
value: (Reflect.get(request, kRedirectCount) || 0) + 1
|
|
29315
|
+
});
|
|
29316
|
+
if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) {
|
|
29317
|
+
return Promise.reject(
|
|
29318
|
+
createNetworkError('cross origin not allowed for request mode "cors"')
|
|
29319
|
+
);
|
|
29320
|
+
}
|
|
29321
|
+
const requestInit = {};
|
|
29322
|
+
if ([301, 302].includes(response.status) && request.method === "POST" || response.status === 303 && !["HEAD", "GET"].includes(request.method)) {
|
|
29323
|
+
requestInit.method = "GET";
|
|
29324
|
+
requestInit.body = null;
|
|
29325
|
+
REQUEST_BODY_HEADERS.forEach((headerName) => {
|
|
29326
|
+
request.headers.delete(headerName);
|
|
29327
|
+
});
|
|
29328
|
+
}
|
|
29329
|
+
if (!sameOrigin(requestUrl, locationUrl)) {
|
|
29330
|
+
request.headers.delete("authorization");
|
|
29331
|
+
request.headers.delete("proxy-authorization");
|
|
29332
|
+
request.headers.delete("cookie");
|
|
29333
|
+
request.headers.delete("host");
|
|
29334
|
+
}
|
|
29335
|
+
requestInit.headers = request.headers;
|
|
29336
|
+
return fetch(new Request(locationUrl, requestInit));
|
|
29337
|
+
}
|
|
29338
|
+
function sameOrigin(left, right) {
|
|
29339
|
+
if (left.origin === right.origin && left.origin === "null") {
|
|
29340
|
+
return true;
|
|
29341
|
+
}
|
|
29342
|
+
if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) {
|
|
29343
|
+
return true;
|
|
29344
|
+
}
|
|
29345
|
+
return false;
|
|
29346
|
+
}
|
|
29060
29347
|
var _FetchInterceptor = class extends Interceptor {
|
|
29061
29348
|
constructor() {
|
|
29062
29349
|
super(_FetchInterceptor.symbol);
|
|
@@ -29066,136 +29353,84 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29066
29353
|
}
|
|
29067
29354
|
async setup() {
|
|
29068
29355
|
const pureFetch = globalThis.fetch;
|
|
29069
|
-
|
|
29356
|
+
invariant2(
|
|
29070
29357
|
!pureFetch[IS_PATCHED_MODULE],
|
|
29071
29358
|
'Failed to patch the "fetch" module: already patched.'
|
|
29072
29359
|
);
|
|
29073
29360
|
globalThis.fetch = async (input, init) => {
|
|
29074
|
-
var _a2;
|
|
29075
29361
|
const requestId = createRequestId();
|
|
29076
29362
|
const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.origin) : input;
|
|
29077
29363
|
const request = new Request(resolvedInput, init);
|
|
29364
|
+
const responsePromise = new DeferredPromise();
|
|
29365
|
+
const controller = new RequestController(request);
|
|
29078
29366
|
this.logger.info("[%s] %s", request.method, request.url);
|
|
29079
|
-
|
|
29367
|
+
this.logger.info("awaiting for the mocked response...");
|
|
29080
29368
|
this.logger.info(
|
|
29081
|
-
'emitting the "request" event for %
|
|
29369
|
+
'emitting the "request" event for %s listener(s)...',
|
|
29082
29370
|
this.emitter.listenerCount("request")
|
|
29083
29371
|
);
|
|
29084
|
-
|
|
29085
|
-
|
|
29086
|
-
|
|
29087
|
-
|
|
29088
|
-
|
|
29089
|
-
|
|
29090
|
-
|
|
29091
|
-
|
|
29092
|
-
this.logger.info("awaiting for the mocked response...");
|
|
29093
|
-
const signal = interactiveRequest.signal;
|
|
29094
|
-
const requestAborted = new DeferredPromise();
|
|
29095
|
-
if (signal) {
|
|
29096
|
-
signal.addEventListener(
|
|
29097
|
-
"abort",
|
|
29098
|
-
() => {
|
|
29099
|
-
requestAborted.reject(signal.reason);
|
|
29100
|
-
},
|
|
29101
|
-
{ once: true }
|
|
29102
|
-
);
|
|
29103
|
-
}
|
|
29104
|
-
const responsePromise = new DeferredPromise();
|
|
29105
|
-
const respondWith = (response) => {
|
|
29106
|
-
this.logger.info("responding with a mock response:", response);
|
|
29107
|
-
if (this.emitter.listenerCount("response") > 0) {
|
|
29108
|
-
this.logger.info('emitting the "response" event...');
|
|
29109
|
-
const responseClone = response.clone();
|
|
29110
|
-
this.emitter.emit("response", {
|
|
29111
|
-
response: responseClone,
|
|
29112
|
-
isMockedResponse: true,
|
|
29113
|
-
request: interactiveRequest,
|
|
29114
|
-
requestId
|
|
29115
|
-
});
|
|
29116
|
-
}
|
|
29117
|
-
Object.defineProperty(response, "url", {
|
|
29118
|
-
writable: false,
|
|
29119
|
-
enumerable: true,
|
|
29120
|
-
configurable: false,
|
|
29121
|
-
value: request.url
|
|
29122
|
-
});
|
|
29123
|
-
responsePromise.resolve(response);
|
|
29124
|
-
};
|
|
29125
|
-
const errorWith = (reason) => {
|
|
29126
|
-
responsePromise.reject(reason);
|
|
29127
|
-
};
|
|
29128
|
-
const resolverResult = await until(
|
|
29129
|
-
async () => {
|
|
29130
|
-
const listenersFinished = emitAsync(this.emitter, "request", {
|
|
29131
|
-
request: interactiveRequest,
|
|
29132
|
-
requestId
|
|
29372
|
+
const isRequestHandled = await handleRequest2({
|
|
29373
|
+
request,
|
|
29374
|
+
requestId,
|
|
29375
|
+
emitter: this.emitter,
|
|
29376
|
+
controller,
|
|
29377
|
+
onResponse: async (response) => {
|
|
29378
|
+
this.logger.info("received mocked response!", {
|
|
29379
|
+
response
|
|
29133
29380
|
});
|
|
29134
|
-
|
|
29135
|
-
|
|
29136
|
-
|
|
29137
|
-
|
|
29138
|
-
|
|
29139
|
-
|
|
29140
|
-
|
|
29141
|
-
|
|
29142
|
-
|
|
29143
|
-
|
|
29144
|
-
|
|
29145
|
-
|
|
29146
|
-
|
|
29147
|
-
|
|
29148
|
-
|
|
29149
|
-
this.logger.info(
|
|
29150
|
-
"request has been aborted:",
|
|
29151
|
-
requestAborted.rejectionReason
|
|
29152
|
-
);
|
|
29153
|
-
responsePromise.reject(requestAborted.rejectionReason);
|
|
29154
|
-
return responsePromise;
|
|
29155
|
-
}
|
|
29156
|
-
if (resolverResult.error) {
|
|
29157
|
-
this.logger.info(
|
|
29158
|
-
"request listerner threw an error:",
|
|
29159
|
-
resolverResult.error
|
|
29160
|
-
);
|
|
29161
|
-
if (resolverResult.error instanceof Response) {
|
|
29162
|
-
if (isResponseError(resolverResult.error)) {
|
|
29163
|
-
errorWith(createNetworkError(resolverResult.error));
|
|
29164
|
-
} else {
|
|
29165
|
-
respondWith(resolverResult.error);
|
|
29166
|
-
}
|
|
29167
|
-
}
|
|
29168
|
-
if (this.emitter.listenerCount("unhandledException") > 0) {
|
|
29169
|
-
await emitAsync(this.emitter, "unhandledException", {
|
|
29170
|
-
error: resolverResult.error,
|
|
29171
|
-
request,
|
|
29172
|
-
requestId,
|
|
29173
|
-
controller: {
|
|
29174
|
-
respondWith,
|
|
29175
|
-
errorWith
|
|
29381
|
+
if (RESPONSE_STATUS_CODES_WITH_REDIRECT.has(response.status)) {
|
|
29382
|
+
if (request.redirect === "error") {
|
|
29383
|
+
responsePromise.reject(createNetworkError("unexpected redirect"));
|
|
29384
|
+
return;
|
|
29385
|
+
}
|
|
29386
|
+
if (request.redirect === "follow") {
|
|
29387
|
+
followFetchRedirect(request, response).then(
|
|
29388
|
+
(response2) => {
|
|
29389
|
+
responsePromise.resolve(response2);
|
|
29390
|
+
},
|
|
29391
|
+
(reason) => {
|
|
29392
|
+
responsePromise.reject(reason);
|
|
29393
|
+
}
|
|
29394
|
+
);
|
|
29395
|
+
return;
|
|
29176
29396
|
}
|
|
29177
|
-
});
|
|
29178
|
-
if (responsePromise.state !== "pending") {
|
|
29179
|
-
return responsePromise;
|
|
29180
29397
|
}
|
|
29398
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
29399
|
+
this.logger.info('emitting the "response" event...');
|
|
29400
|
+
await emitAsync(this.emitter, "response", {
|
|
29401
|
+
// Clone the mocked response for the "response" event listener.
|
|
29402
|
+
// This way, the listener can read the response and not lock its body
|
|
29403
|
+
// for the actual fetch consumer.
|
|
29404
|
+
response: response.clone(),
|
|
29405
|
+
isMockedResponse: true,
|
|
29406
|
+
request,
|
|
29407
|
+
requestId
|
|
29408
|
+
});
|
|
29409
|
+
}
|
|
29410
|
+
Object.defineProperty(response, "url", {
|
|
29411
|
+
writable: false,
|
|
29412
|
+
enumerable: true,
|
|
29413
|
+
configurable: false,
|
|
29414
|
+
value: request.url
|
|
29415
|
+
});
|
|
29416
|
+
responsePromise.resolve(response);
|
|
29417
|
+
},
|
|
29418
|
+
onRequestError: (response) => {
|
|
29419
|
+
this.logger.info("request has errored!", { response });
|
|
29420
|
+
responsePromise.reject(createNetworkError(response));
|
|
29421
|
+
},
|
|
29422
|
+
onError: (error3) => {
|
|
29423
|
+
this.logger.info("request has been aborted!", { error: error3 });
|
|
29424
|
+
responsePromise.reject(error3);
|
|
29181
29425
|
}
|
|
29182
|
-
|
|
29183
|
-
|
|
29184
|
-
|
|
29185
|
-
const mockedResponse = resolverResult.data;
|
|
29186
|
-
if (mockedResponse && !((_a2 = request.signal) == null ? void 0 : _a2.aborted)) {
|
|
29187
|
-
this.logger.info("received mocked response:", mockedResponse);
|
|
29188
|
-
if (isResponseError(mockedResponse)) {
|
|
29189
|
-
this.logger.info(
|
|
29190
|
-
"received a network error response, rejecting the request promise..."
|
|
29191
|
-
);
|
|
29192
|
-
errorWith(createNetworkError(mockedResponse));
|
|
29193
|
-
} else {
|
|
29194
|
-
respondWith(mockedResponse);
|
|
29195
|
-
}
|
|
29426
|
+
});
|
|
29427
|
+
if (isRequestHandled) {
|
|
29428
|
+
this.logger.info("request has been handled, returning mock promise...");
|
|
29196
29429
|
return responsePromise;
|
|
29197
29430
|
}
|
|
29198
|
-
this.logger.info(
|
|
29431
|
+
this.logger.info(
|
|
29432
|
+
"no mocked response received, performing request as-is..."
|
|
29433
|
+
);
|
|
29199
29434
|
return pureFetch(request).then((response) => {
|
|
29200
29435
|
this.logger.info("original fetch performed", response);
|
|
29201
29436
|
if (this.emitter.listenerCount("response") > 0) {
|
|
@@ -29204,7 +29439,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29204
29439
|
this.emitter.emit("response", {
|
|
29205
29440
|
response: responseClone,
|
|
29206
29441
|
isMockedResponse: false,
|
|
29207
|
-
request
|
|
29442
|
+
request,
|
|
29208
29443
|
requestId
|
|
29209
29444
|
});
|
|
29210
29445
|
}
|
|
@@ -29230,13 +29465,8 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29230
29465
|
};
|
|
29231
29466
|
var FetchInterceptor = _FetchInterceptor;
|
|
29232
29467
|
FetchInterceptor.symbol = Symbol("fetch");
|
|
29233
|
-
function createNetworkError(cause) {
|
|
29234
|
-
return Object.assign(new TypeError("Failed to fetch"), {
|
|
29235
|
-
cause
|
|
29236
|
-
});
|
|
29237
|
-
}
|
|
29238
29468
|
|
|
29239
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29469
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.35.0/node_modules/@mswjs/interceptors/lib/browser/chunk-PRBA3ES4.mjs
|
|
29240
29470
|
function concatArrayBuffer(left, right) {
|
|
29241
29471
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
29242
29472
|
result.set(left, 0);
|
|
@@ -29245,10 +29475,10 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29245
29475
|
}
|
|
29246
29476
|
var EventPolyfill = class {
|
|
29247
29477
|
constructor(type, options) {
|
|
29248
|
-
this.AT_TARGET = 0;
|
|
29249
|
-
this.BUBBLING_PHASE = 0;
|
|
29250
|
-
this.CAPTURING_PHASE = 0;
|
|
29251
29478
|
this.NONE = 0;
|
|
29479
|
+
this.CAPTURING_PHASE = 1;
|
|
29480
|
+
this.AT_TARGET = 2;
|
|
29481
|
+
this.BUBBLING_PHASE = 3;
|
|
29252
29482
|
this.type = "";
|
|
29253
29483
|
this.srcElement = null;
|
|
29254
29484
|
this.currentTarget = null;
|
|
@@ -29421,15 +29651,26 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29421
29651
|
}
|
|
29422
29652
|
return headers;
|
|
29423
29653
|
}
|
|
29424
|
-
|
|
29654
|
+
async function getBodyByteLength(input) {
|
|
29655
|
+
const explicitContentLength = input.headers.get("content-length");
|
|
29656
|
+
if (explicitContentLength != null && explicitContentLength !== "") {
|
|
29657
|
+
return Number(explicitContentLength);
|
|
29658
|
+
}
|
|
29659
|
+
const buffer = await input.arrayBuffer();
|
|
29660
|
+
return buffer.byteLength;
|
|
29661
|
+
}
|
|
29662
|
+
var kIsRequestHandled = Symbol("kIsRequestHandled");
|
|
29425
29663
|
var IS_NODE2 = isNodeProcess();
|
|
29664
|
+
var kFetchRequest = Symbol("kFetchRequest");
|
|
29426
29665
|
var XMLHttpRequestController = class {
|
|
29427
29666
|
constructor(initialRequest, logger) {
|
|
29428
29667
|
this.initialRequest = initialRequest;
|
|
29429
29668
|
this.logger = logger;
|
|
29430
29669
|
this.method = "GET";
|
|
29431
29670
|
this.url = null;
|
|
29671
|
+
this[kIsRequestHandled] = false;
|
|
29432
29672
|
this.events = /* @__PURE__ */ new Map();
|
|
29673
|
+
this.uploadEvents = /* @__PURE__ */ new Map();
|
|
29433
29674
|
this.requestId = createRequestId();
|
|
29434
29675
|
this.requestHeaders = new Headers();
|
|
29435
29676
|
this.responseBuffer = new Uint8Array();
|
|
@@ -29478,9 +29719,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29478
29719
|
}
|
|
29479
29720
|
case "send": {
|
|
29480
29721
|
const [body] = args;
|
|
29481
|
-
if (body != null) {
|
|
29482
|
-
this.requestBody = typeof body === "string" ? encodeBuffer(body) : body;
|
|
29483
|
-
}
|
|
29484
29722
|
this.request.addEventListener("load", () => {
|
|
29485
29723
|
if (typeof this.onResponse !== "undefined") {
|
|
29486
29724
|
const fetchResponse = createResponse(
|
|
@@ -29494,19 +29732,21 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29494
29732
|
);
|
|
29495
29733
|
this.onResponse.call(this, {
|
|
29496
29734
|
response: fetchResponse,
|
|
29497
|
-
isMockedResponse:
|
|
29735
|
+
isMockedResponse: this[kIsRequestHandled],
|
|
29498
29736
|
request: fetchRequest,
|
|
29499
29737
|
requestId: this.requestId
|
|
29500
29738
|
});
|
|
29501
29739
|
}
|
|
29502
29740
|
});
|
|
29503
|
-
const
|
|
29741
|
+
const requestBody = typeof body === "string" ? encodeBuffer(body) : body;
|
|
29742
|
+
const fetchRequest = this.toFetchApiRequest(requestBody);
|
|
29743
|
+
this[kFetchRequest] = fetchRequest;
|
|
29504
29744
|
const onceRequestSettled = ((_a2 = this.onRequest) == null ? void 0 : _a2.call(this, {
|
|
29505
29745
|
request: fetchRequest,
|
|
29506
29746
|
requestId: this.requestId
|
|
29507
29747
|
})) || Promise.resolve();
|
|
29508
29748
|
onceRequestSettled.finally(() => {
|
|
29509
|
-
if (this
|
|
29749
|
+
if (!this[kIsRequestHandled]) {
|
|
29510
29750
|
this.logger.info(
|
|
29511
29751
|
"request callback settled but request has not been handled (readystate %d), performing as-is...",
|
|
29512
29752
|
this.request.readyState
|
|
@@ -29528,6 +29768,39 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29528
29768
|
}
|
|
29529
29769
|
}
|
|
29530
29770
|
});
|
|
29771
|
+
define(
|
|
29772
|
+
this.request,
|
|
29773
|
+
"upload",
|
|
29774
|
+
createProxy(this.request.upload, {
|
|
29775
|
+
setProperty: ([propertyName, nextValue], invoke) => {
|
|
29776
|
+
switch (propertyName) {
|
|
29777
|
+
case "onloadstart":
|
|
29778
|
+
case "onprogress":
|
|
29779
|
+
case "onaboart":
|
|
29780
|
+
case "onerror":
|
|
29781
|
+
case "onload":
|
|
29782
|
+
case "ontimeout":
|
|
29783
|
+
case "onloadend": {
|
|
29784
|
+
const eventName = propertyName.slice(
|
|
29785
|
+
2
|
|
29786
|
+
);
|
|
29787
|
+
this.registerUploadEvent(eventName, nextValue);
|
|
29788
|
+
}
|
|
29789
|
+
}
|
|
29790
|
+
return invoke();
|
|
29791
|
+
},
|
|
29792
|
+
methodCall: ([methodName, args], invoke) => {
|
|
29793
|
+
switch (methodName) {
|
|
29794
|
+
case "addEventListener": {
|
|
29795
|
+
const [eventName, listener] = args;
|
|
29796
|
+
this.registerUploadEvent(eventName, listener);
|
|
29797
|
+
this.logger.info("upload.addEventListener", eventName, listener);
|
|
29798
|
+
return invoke();
|
|
29799
|
+
}
|
|
29800
|
+
}
|
|
29801
|
+
}
|
|
29802
|
+
})
|
|
29803
|
+
);
|
|
29531
29804
|
}
|
|
29532
29805
|
registerEvent(eventName, listener) {
|
|
29533
29806
|
const prevEvents = this.events.get(eventName) || [];
|
|
@@ -29535,17 +29808,44 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29535
29808
|
this.events.set(eventName, nextEvents);
|
|
29536
29809
|
this.logger.info('registered event "%s"', eventName, listener);
|
|
29537
29810
|
}
|
|
29811
|
+
registerUploadEvent(eventName, listener) {
|
|
29812
|
+
const prevEvents = this.uploadEvents.get(eventName) || [];
|
|
29813
|
+
const nextEvents = prevEvents.concat(listener);
|
|
29814
|
+
this.uploadEvents.set(eventName, nextEvents);
|
|
29815
|
+
this.logger.info('registered upload event "%s"', eventName, listener);
|
|
29816
|
+
}
|
|
29538
29817
|
/**
|
|
29539
29818
|
* Responds to the current request with the given
|
|
29540
29819
|
* Fetch API `Response` instance.
|
|
29541
29820
|
*/
|
|
29542
|
-
respondWith(response) {
|
|
29821
|
+
async respondWith(response) {
|
|
29822
|
+
this[kIsRequestHandled] = true;
|
|
29823
|
+
if (this[kFetchRequest]) {
|
|
29824
|
+
const totalRequestBodyLength = await getBodyByteLength(
|
|
29825
|
+
this[kFetchRequest].clone()
|
|
29826
|
+
);
|
|
29827
|
+
this.trigger("loadstart", this.request.upload, {
|
|
29828
|
+
loaded: 0,
|
|
29829
|
+
total: totalRequestBodyLength
|
|
29830
|
+
});
|
|
29831
|
+
this.trigger("progress", this.request.upload, {
|
|
29832
|
+
loaded: totalRequestBodyLength,
|
|
29833
|
+
total: totalRequestBodyLength
|
|
29834
|
+
});
|
|
29835
|
+
this.trigger("load", this.request.upload, {
|
|
29836
|
+
loaded: totalRequestBodyLength,
|
|
29837
|
+
total: totalRequestBodyLength
|
|
29838
|
+
});
|
|
29839
|
+
this.trigger("loadend", this.request.upload, {
|
|
29840
|
+
loaded: totalRequestBodyLength,
|
|
29841
|
+
total: totalRequestBodyLength
|
|
29842
|
+
});
|
|
29843
|
+
}
|
|
29543
29844
|
this.logger.info(
|
|
29544
29845
|
"responding with a mocked response: %d %s",
|
|
29545
29846
|
response.status,
|
|
29546
29847
|
response.statusText
|
|
29547
29848
|
);
|
|
29548
|
-
define(this.request, IS_MOCKED_RESPONSE, true);
|
|
29549
29849
|
define(this.request, "status", response.status);
|
|
29550
29850
|
define(this.request, "statusText", response.statusText);
|
|
29551
29851
|
define(this.request, "responseURL", this.url.href);
|
|
@@ -29600,14 +29900,9 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29600
29900
|
get: () => this.responseXML
|
|
29601
29901
|
}
|
|
29602
29902
|
});
|
|
29603
|
-
const totalResponseBodyLength =
|
|
29604
|
-
/**
|
|
29605
|
-
* @todo Infer the response body length from the response body.
|
|
29606
|
-
*/
|
|
29607
|
-
void 0
|
|
29608
|
-
);
|
|
29903
|
+
const totalResponseBodyLength = await getBodyByteLength(response.clone());
|
|
29609
29904
|
this.logger.info("calculated response body length", totalResponseBodyLength);
|
|
29610
|
-
this.trigger("loadstart", {
|
|
29905
|
+
this.trigger("loadstart", this.request, {
|
|
29611
29906
|
loaded: 0,
|
|
29612
29907
|
total: totalResponseBodyLength
|
|
29613
29908
|
});
|
|
@@ -29616,11 +29911,11 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29616
29911
|
const finalizeResponse = () => {
|
|
29617
29912
|
this.logger.info("finalizing the mocked response...");
|
|
29618
29913
|
this.setReadyState(this.request.DONE);
|
|
29619
|
-
this.trigger("load", {
|
|
29914
|
+
this.trigger("load", this.request, {
|
|
29620
29915
|
loaded: this.responseBuffer.byteLength,
|
|
29621
29916
|
total: totalResponseBodyLength
|
|
29622
29917
|
});
|
|
29623
|
-
this.trigger("loadend", {
|
|
29918
|
+
this.trigger("loadend", this.request, {
|
|
29624
29919
|
loaded: this.responseBuffer.byteLength,
|
|
29625
29920
|
total: totalResponseBodyLength
|
|
29626
29921
|
});
|
|
@@ -29638,7 +29933,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29638
29933
|
if (value) {
|
|
29639
29934
|
this.logger.info("read response body chunk:", value);
|
|
29640
29935
|
this.responseBuffer = concatArrayBuffer(this.responseBuffer, value);
|
|
29641
|
-
this.trigger("progress", {
|
|
29936
|
+
this.trigger("progress", this.request, {
|
|
29642
29937
|
loaded: this.responseBuffer.byteLength,
|
|
29643
29938
|
total: totalResponseBodyLength
|
|
29644
29939
|
});
|
|
@@ -29696,7 +29991,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29696
29991
|
}
|
|
29697
29992
|
}
|
|
29698
29993
|
get responseText() {
|
|
29699
|
-
|
|
29994
|
+
invariant2(
|
|
29700
29995
|
this.request.responseType === "" || this.request.responseType === "text",
|
|
29701
29996
|
"InvalidStateError: The object is in invalid state."
|
|
29702
29997
|
);
|
|
@@ -29708,7 +30003,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29708
30003
|
return responseText;
|
|
29709
30004
|
}
|
|
29710
30005
|
get responseXML() {
|
|
29711
|
-
|
|
30006
|
+
invariant2(
|
|
29712
30007
|
this.request.responseType === "" || this.request.responseType === "document",
|
|
29713
30008
|
"InvalidStateError: The object is in invalid state."
|
|
29714
30009
|
);
|
|
@@ -29731,10 +30026,11 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29731
30026
|
return null;
|
|
29732
30027
|
}
|
|
29733
30028
|
errorWith(error3) {
|
|
30029
|
+
this[kIsRequestHandled] = true;
|
|
29734
30030
|
this.logger.info("responding with an error");
|
|
29735
30031
|
this.setReadyState(this.request.DONE);
|
|
29736
|
-
this.trigger("error");
|
|
29737
|
-
this.trigger("loadend");
|
|
30032
|
+
this.trigger("error", this.request);
|
|
30033
|
+
this.trigger("loadend", this.request);
|
|
29738
30034
|
}
|
|
29739
30035
|
/**
|
|
29740
30036
|
* Transitions this request's `readyState` to the given one.
|
|
@@ -29753,36 +30049,38 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29753
30049
|
this.logger.info("set readyState to: %d", nextReadyState);
|
|
29754
30050
|
if (nextReadyState !== this.request.UNSENT) {
|
|
29755
30051
|
this.logger.info('triggerring "readystatechange" event...');
|
|
29756
|
-
this.trigger("readystatechange");
|
|
30052
|
+
this.trigger("readystatechange", this.request);
|
|
29757
30053
|
}
|
|
29758
30054
|
}
|
|
29759
30055
|
/**
|
|
29760
30056
|
* Triggers given event on the `XMLHttpRequest` instance.
|
|
29761
30057
|
*/
|
|
29762
|
-
trigger(eventName, options) {
|
|
29763
|
-
const callback =
|
|
29764
|
-
const event = createEvent(
|
|
30058
|
+
trigger(eventName, target, options) {
|
|
30059
|
+
const callback = target[`on${eventName}`];
|
|
30060
|
+
const event = createEvent(target, eventName, options);
|
|
29765
30061
|
this.logger.info('trigger "%s"', eventName, options || "");
|
|
29766
30062
|
if (typeof callback === "function") {
|
|
29767
30063
|
this.logger.info('found a direct "%s" callback, calling...', eventName);
|
|
29768
|
-
callback.call(
|
|
30064
|
+
callback.call(target, event);
|
|
29769
30065
|
}
|
|
29770
|
-
|
|
30066
|
+
const events = target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events;
|
|
30067
|
+
for (const [registeredEventName, listeners] of events) {
|
|
29771
30068
|
if (registeredEventName === eventName) {
|
|
29772
30069
|
this.logger.info(
|
|
29773
30070
|
'found %d listener(s) for "%s" event, calling...',
|
|
29774
30071
|
listeners.length,
|
|
29775
30072
|
eventName
|
|
29776
30073
|
);
|
|
29777
|
-
listeners.forEach((listener) => listener.call(
|
|
30074
|
+
listeners.forEach((listener) => listener.call(target, event));
|
|
29778
30075
|
}
|
|
29779
30076
|
}
|
|
29780
30077
|
}
|
|
29781
30078
|
/**
|
|
29782
30079
|
* Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
|
|
29783
30080
|
*/
|
|
29784
|
-
toFetchApiRequest() {
|
|
30081
|
+
toFetchApiRequest(body) {
|
|
29785
30082
|
this.logger.info("converting request to a Fetch API Request...");
|
|
30083
|
+
const resolvedBody = body instanceof Document ? body.documentElement.innerText : body;
|
|
29786
30084
|
const fetchRequest = new Request(this.url.href, {
|
|
29787
30085
|
method: this.method,
|
|
29788
30086
|
headers: this.requestHeaders,
|
|
@@ -29790,7 +30088,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29790
30088
|
* @see https://xhr.spec.whatwg.org/#cross-origin-credentials
|
|
29791
30089
|
*/
|
|
29792
30090
|
credentials: this.request.withCredentials ? "include" : "same-origin",
|
|
29793
|
-
body: ["GET", "HEAD"].includes(this.method) ? null :
|
|
30091
|
+
body: ["GET", "HEAD"].includes(this.method.toUpperCase()) ? null : resolvedBody
|
|
29794
30092
|
});
|
|
29795
30093
|
const proxyHeaders = createProxy(fetchRequest.headers, {
|
|
29796
30094
|
methodCall: ([methodName, args], invoke) => {
|
|
@@ -29858,81 +30156,35 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29858
30156
|
logger
|
|
29859
30157
|
);
|
|
29860
30158
|
xhrRequestController.onRequest = async function({ request, requestId }) {
|
|
29861
|
-
const
|
|
30159
|
+
const controller = new RequestController(request);
|
|
29862
30160
|
this.logger.info("awaiting mocked response...");
|
|
29863
|
-
|
|
29864
|
-
|
|
29865
|
-
|
|
29866
|
-
|
|
29867
|
-
|
|
29868
|
-
|
|
29869
|
-
|
|
29870
|
-
|
|
29871
|
-
|
|
29872
|
-
|
|
29873
|
-
|
|
29874
|
-
|
|
29875
|
-
)
|
|
29876
|
-
|
|
29877
|
-
|
|
29878
|
-
|
|
29879
|
-
|
|
29880
|
-
|
|
29881
|
-
|
|
29882
|
-
this.logger.info("event.respondWith called with:", mockedResponse2);
|
|
29883
|
-
return mockedResponse2;
|
|
29884
|
-
});
|
|
29885
|
-
if (resolverResult.error) {
|
|
29886
|
-
this.logger.info(
|
|
29887
|
-
"request listener threw an exception, aborting request...",
|
|
29888
|
-
resolverResult.error
|
|
29889
|
-
);
|
|
29890
|
-
if (resolverResult.error instanceof Response) {
|
|
29891
|
-
if (isResponseError(resolverResult.error)) {
|
|
29892
|
-
xhrRequestController.errorWith(new TypeError("Network error"));
|
|
29893
|
-
} else {
|
|
29894
|
-
this.respondWith(resolverResult.error);
|
|
29895
|
-
}
|
|
29896
|
-
return;
|
|
29897
|
-
}
|
|
29898
|
-
if (emitter.listenerCount("unhandledException") > 0) {
|
|
29899
|
-
await emitAsync(emitter, "unhandledException", {
|
|
29900
|
-
error: resolverResult.error,
|
|
29901
|
-
request,
|
|
29902
|
-
requestId,
|
|
29903
|
-
controller: {
|
|
29904
|
-
respondWith: xhrRequestController.respondWith.bind(xhrRequestController),
|
|
29905
|
-
errorWith: xhrRequestController.errorWith.bind(xhrRequestController)
|
|
29906
|
-
}
|
|
29907
|
-
});
|
|
29908
|
-
if (originalRequest.readyState > XMLHttpRequest.OPENED) {
|
|
29909
|
-
return;
|
|
30161
|
+
this.logger.info(
|
|
30162
|
+
'emitting the "request" event for %s listener(s)...',
|
|
30163
|
+
emitter.listenerCount("request")
|
|
30164
|
+
);
|
|
30165
|
+
const isRequestHandled = await handleRequest2({
|
|
30166
|
+
request,
|
|
30167
|
+
requestId,
|
|
30168
|
+
controller,
|
|
30169
|
+
emitter,
|
|
30170
|
+
onResponse: async (response) => {
|
|
30171
|
+
await this.respondWith(response);
|
|
30172
|
+
},
|
|
30173
|
+
onRequestError: () => {
|
|
30174
|
+
this.errorWith(new TypeError("Network error"));
|
|
30175
|
+
},
|
|
30176
|
+
onError: (error3) => {
|
|
30177
|
+
this.logger.info("request errored!", { error: error3 });
|
|
30178
|
+
if (error3 instanceof Error) {
|
|
30179
|
+
this.errorWith(error3);
|
|
29910
30180
|
}
|
|
29911
30181
|
}
|
|
29912
|
-
|
|
29913
|
-
|
|
29914
|
-
);
|
|
29915
|
-
return;
|
|
29916
|
-
}
|
|
29917
|
-
const mockedResponse = resolverResult.data;
|
|
29918
|
-
if (typeof mockedResponse !== "undefined") {
|
|
30182
|
+
});
|
|
30183
|
+
if (!isRequestHandled) {
|
|
29919
30184
|
this.logger.info(
|
|
29920
|
-
"
|
|
29921
|
-
mockedResponse.status,
|
|
29922
|
-
mockedResponse.statusText
|
|
30185
|
+
"no mocked response received, performing request as-is..."
|
|
29923
30186
|
);
|
|
29924
|
-
if (isResponseError(mockedResponse)) {
|
|
29925
|
-
this.logger.info(
|
|
29926
|
-
"received a network error response, rejecting the request promise..."
|
|
29927
|
-
);
|
|
29928
|
-
xhrRequestController.errorWith(new TypeError("Network error"));
|
|
29929
|
-
return;
|
|
29930
|
-
}
|
|
29931
|
-
return xhrRequestController.respondWith(mockedResponse);
|
|
29932
30187
|
}
|
|
29933
|
-
this.logger.info(
|
|
29934
|
-
"no mocked response received, performing request as-is..."
|
|
29935
|
-
);
|
|
29936
30188
|
};
|
|
29937
30189
|
xhrRequestController.onResponse = async function({
|
|
29938
30190
|
response,
|
|
@@ -29967,7 +30219,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29967
30219
|
const logger = this.logger.extend("setup");
|
|
29968
30220
|
logger.info('patching "XMLHttpRequest" module...');
|
|
29969
30221
|
const PureXMLHttpRequest = globalThis.XMLHttpRequest;
|
|
29970
|
-
|
|
30222
|
+
invariant2(
|
|
29971
30223
|
!PureXMLHttpRequest[IS_PATCHED_MODULE],
|
|
29972
30224
|
'Failed to patch the "XMLHttpRequest" module: already patched.'
|
|
29973
30225
|
);
|
|
@@ -30005,7 +30257,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30005
30257
|
name: "fallback",
|
|
30006
30258
|
interceptors: [new FetchInterceptor(), new XMLHttpRequestInterceptor()]
|
|
30007
30259
|
});
|
|
30008
|
-
interceptor.on("request", async ({ request, requestId }) => {
|
|
30260
|
+
interceptor.on("request", async ({ request, requestId, controller }) => {
|
|
30009
30261
|
const requestCloneForLogs = request.clone();
|
|
30010
30262
|
const response = await handleRequest(
|
|
30011
30263
|
request,
|
|
@@ -30028,7 +30280,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30028
30280
|
}
|
|
30029
30281
|
);
|
|
30030
30282
|
if (response) {
|
|
30031
|
-
|
|
30283
|
+
controller.respondWith(response);
|
|
30032
30284
|
}
|
|
30033
30285
|
});
|
|
30034
30286
|
interceptor.on(
|