msw 2.12.7 → 2.12.8
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 +641 -925
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +641 -925
- package/lib/browser/index.mjs.map +1 -1
- package/lib/iife/index.js +924 -1379
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +5 -5
package/lib/browser/index.js
CHANGED
|
@@ -494,20 +494,165 @@ You can also automate this process and make the worker script update automatical
|
|
|
494
494
|
return integrityCheckPromise;
|
|
495
495
|
}
|
|
496
496
|
|
|
497
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
498
|
-
var
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
497
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-BTaNLFr0.mjs
|
|
498
|
+
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
499
|
+
var InterceptorError = class InterceptorError2 extends Error {
|
|
500
|
+
constructor(message) {
|
|
501
|
+
super(message);
|
|
502
|
+
this.name = "InterceptorError";
|
|
503
|
+
Object.setPrototypeOf(this, InterceptorError2.prototype);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
var RequestController = class RequestController2 {
|
|
507
|
+
static {
|
|
508
|
+
this.PENDING = 0;
|
|
509
|
+
}
|
|
510
|
+
static {
|
|
511
|
+
this.PASSTHROUGH = 1;
|
|
512
|
+
}
|
|
513
|
+
static {
|
|
514
|
+
this.RESPONSE = 2;
|
|
515
|
+
}
|
|
516
|
+
static {
|
|
517
|
+
this.ERROR = 3;
|
|
518
|
+
}
|
|
519
|
+
constructor(request, source) {
|
|
520
|
+
this.request = request;
|
|
521
|
+
this.source = source;
|
|
522
|
+
this.readyState = RequestController2.PENDING;
|
|
523
|
+
this.handled = new DeferredPromise();
|
|
524
|
+
}
|
|
525
|
+
get #handled() {
|
|
526
|
+
return this.handled;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Perform this request as-is.
|
|
530
|
+
*/
|
|
531
|
+
async passthrough() {
|
|
532
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to passthrough the "%s %s" request: the request has already been handled', this.request.method, this.request.url);
|
|
533
|
+
this.readyState = RequestController2.PASSTHROUGH;
|
|
534
|
+
await this.source.passthrough();
|
|
535
|
+
this.#handled.resolve();
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Respond to this request with the given `Response` instance.
|
|
539
|
+
*
|
|
540
|
+
* @example
|
|
541
|
+
* controller.respondWith(new Response())
|
|
542
|
+
* controller.respondWith(Response.json({ id }))
|
|
543
|
+
* controller.respondWith(Response.error())
|
|
544
|
+
*/
|
|
545
|
+
respondWith(response) {
|
|
546
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to respond to the "%s %s" request with "%d %s": the request has already been handled (%d)', this.request.method, this.request.url, response.status, response.statusText || "OK", this.readyState);
|
|
547
|
+
this.readyState = RequestController2.RESPONSE;
|
|
548
|
+
this.#handled.resolve();
|
|
549
|
+
this.source.respondWith(response);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Error this request with the given reason.
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* controller.errorWith()
|
|
556
|
+
* controller.errorWith(new Error('Oops!'))
|
|
557
|
+
* controller.errorWith({ message: 'Oops!'})
|
|
558
|
+
*/
|
|
559
|
+
errorWith(reason) {
|
|
560
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to error the "%s %s" request with "%s": the request has already been handled (%d)', this.request.method, this.request.url, reason?.toString(), this.readyState);
|
|
561
|
+
this.readyState = RequestController2.ERROR;
|
|
562
|
+
this.source.errorWith(reason);
|
|
563
|
+
this.#handled.resolve();
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
function canParseUrl(url) {
|
|
567
|
+
try {
|
|
568
|
+
new URL(url);
|
|
569
|
+
return true;
|
|
570
|
+
} catch (_error) {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
505
573
|
}
|
|
506
|
-
function
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
);
|
|
574
|
+
function getValueBySymbol(symbolName, source) {
|
|
575
|
+
const symbol = Object.getOwnPropertySymbols(source).find((symbol$1) => {
|
|
576
|
+
return symbol$1.description === symbolName;
|
|
577
|
+
});
|
|
578
|
+
if (symbol) return Reflect.get(source, symbol);
|
|
579
|
+
}
|
|
580
|
+
var FetchResponse = class FetchResponse2 extends Response {
|
|
581
|
+
static {
|
|
582
|
+
this.STATUS_CODES_WITHOUT_BODY = [
|
|
583
|
+
101,
|
|
584
|
+
103,
|
|
585
|
+
204,
|
|
586
|
+
205,
|
|
587
|
+
304
|
|
588
|
+
];
|
|
589
|
+
}
|
|
590
|
+
static {
|
|
591
|
+
this.STATUS_CODES_WITH_REDIRECT = [
|
|
592
|
+
301,
|
|
593
|
+
302,
|
|
594
|
+
303,
|
|
595
|
+
307,
|
|
596
|
+
308
|
|
597
|
+
];
|
|
598
|
+
}
|
|
599
|
+
static isConfigurableStatusCode(status) {
|
|
600
|
+
return status >= 200 && status <= 599;
|
|
601
|
+
}
|
|
602
|
+
static isRedirectResponse(status) {
|
|
603
|
+
return FetchResponse2.STATUS_CODES_WITH_REDIRECT.includes(status);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Returns a boolean indicating whether the given response status
|
|
607
|
+
* code represents a response that can have a body.
|
|
608
|
+
*/
|
|
609
|
+
static isResponseWithBody(status) {
|
|
610
|
+
return !FetchResponse2.STATUS_CODES_WITHOUT_BODY.includes(status);
|
|
611
|
+
}
|
|
612
|
+
static setUrl(url, response) {
|
|
613
|
+
if (!url || url === "about:" || !canParseUrl(url)) return;
|
|
614
|
+
const state = getValueBySymbol("state", response);
|
|
615
|
+
if (state) state.urlList.push(new URL(url));
|
|
616
|
+
else Object.defineProperty(response, "url", {
|
|
617
|
+
value: url,
|
|
618
|
+
enumerable: true,
|
|
619
|
+
configurable: true,
|
|
620
|
+
writable: false
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
|
625
|
+
*/
|
|
626
|
+
static parseRawHeaders(rawHeaders) {
|
|
627
|
+
const headers = new Headers();
|
|
628
|
+
for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
|
629
|
+
return headers;
|
|
630
|
+
}
|
|
631
|
+
constructor(body, init = {}) {
|
|
632
|
+
const status = init.status ?? 200;
|
|
633
|
+
const safeStatus = FetchResponse2.isConfigurableStatusCode(status) ? status : 200;
|
|
634
|
+
const finalBody = FetchResponse2.isResponseWithBody(status) ? body : null;
|
|
635
|
+
super(finalBody, {
|
|
636
|
+
status: safeStatus,
|
|
637
|
+
statusText: init.statusText,
|
|
638
|
+
headers: init.headers
|
|
639
|
+
});
|
|
640
|
+
if (status !== safeStatus) {
|
|
641
|
+
const state = getValueBySymbol("state", this);
|
|
642
|
+
if (state) state.status = status;
|
|
643
|
+
else Object.defineProperty(this, "status", {
|
|
644
|
+
value: status,
|
|
645
|
+
enumerable: true,
|
|
646
|
+
configurable: true,
|
|
647
|
+
writable: false
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
FetchResponse2.setUrl(init.url, this);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
var kRawRequest = Symbol("kRawRequest");
|
|
654
|
+
function setRawRequest(request, rawRequest) {
|
|
655
|
+
Reflect.set(request, kRawRequest, rawRequest);
|
|
511
656
|
}
|
|
512
657
|
|
|
513
658
|
// node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
|
|
@@ -947,26 +1092,10 @@ var _Emitter = class {
|
|
|
947
1092
|
var Emitter = _Emitter;
|
|
948
1093
|
Emitter.defaultMaxListeners = 10;
|
|
949
1094
|
|
|
950
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
951
|
-
var __accessCheck = (obj, member, msg) => {
|
|
952
|
-
if (!member.has(obj))
|
|
953
|
-
throw TypeError("Cannot " + msg);
|
|
954
|
-
};
|
|
955
|
-
var __privateGet = (obj, member, getter) => {
|
|
956
|
-
__accessCheck(obj, member, "read from private field");
|
|
957
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
958
|
-
};
|
|
959
|
-
var __privateAdd = (obj, member, value) => {
|
|
960
|
-
if (member.has(obj))
|
|
961
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
962
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
963
|
-
};
|
|
1095
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DQcIlohW.mjs
|
|
964
1096
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
965
1097
|
function getGlobalSymbol(symbol) {
|
|
966
|
-
return
|
|
967
|
-
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
|
|
968
|
-
globalThis[symbol] || void 0
|
|
969
|
-
);
|
|
1098
|
+
return globalThis[symbol] || void 0;
|
|
970
1099
|
}
|
|
971
1100
|
function setGlobalSymbol(symbol, value) {
|
|
972
1101
|
globalThis[symbol] = value;
|
|
@@ -974,10 +1103,18 @@ function setGlobalSymbol(symbol, value) {
|
|
|
974
1103
|
function deleteGlobalSymbol(symbol) {
|
|
975
1104
|
delete globalThis[symbol];
|
|
976
1105
|
}
|
|
1106
|
+
var InterceptorReadyState = /* @__PURE__ */ (function(InterceptorReadyState$1) {
|
|
1107
|
+
InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
|
|
1108
|
+
InterceptorReadyState$1["APPLYING"] = "APPLYING";
|
|
1109
|
+
InterceptorReadyState$1["APPLIED"] = "APPLIED";
|
|
1110
|
+
InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
|
|
1111
|
+
InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
|
|
1112
|
+
return InterceptorReadyState$1;
|
|
1113
|
+
})({});
|
|
977
1114
|
var Interceptor = class {
|
|
978
1115
|
constructor(symbol) {
|
|
979
1116
|
this.symbol = symbol;
|
|
980
|
-
this.readyState =
|
|
1117
|
+
this.readyState = InterceptorReadyState.INACTIVE;
|
|
981
1118
|
this.emitter = new Emitter();
|
|
982
1119
|
this.subscriptions = [];
|
|
983
1120
|
this.logger = new Logger(symbol.description);
|
|
@@ -985,29 +1122,28 @@ var Interceptor = class {
|
|
|
985
1122
|
this.logger.info("constructing the interceptor...");
|
|
986
1123
|
}
|
|
987
1124
|
/**
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1125
|
+
* Determine if this interceptor can be applied
|
|
1126
|
+
* in the current environment.
|
|
1127
|
+
*/
|
|
991
1128
|
checkEnvironment() {
|
|
992
1129
|
return true;
|
|
993
1130
|
}
|
|
994
1131
|
/**
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1132
|
+
* Apply this interceptor to the current process.
|
|
1133
|
+
* Returns an already running interceptor instance if it's present.
|
|
1134
|
+
*/
|
|
998
1135
|
apply() {
|
|
999
1136
|
const logger = this.logger.extend("apply");
|
|
1000
1137
|
logger.info("applying the interceptor...");
|
|
1001
|
-
if (this.readyState ===
|
|
1138
|
+
if (this.readyState === InterceptorReadyState.APPLIED) {
|
|
1002
1139
|
logger.info("intercepted already applied!");
|
|
1003
1140
|
return;
|
|
1004
1141
|
}
|
|
1005
|
-
|
|
1006
|
-
if (!shouldApply) {
|
|
1142
|
+
if (!this.checkEnvironment()) {
|
|
1007
1143
|
logger.info("the interceptor cannot be applied in this environment!");
|
|
1008
1144
|
return;
|
|
1009
1145
|
}
|
|
1010
|
-
this.readyState =
|
|
1146
|
+
this.readyState = InterceptorReadyState.APPLYING;
|
|
1011
1147
|
const runningInstance = this.getInstance();
|
|
1012
1148
|
if (runningInstance) {
|
|
1013
1149
|
logger.info("found a running instance, reusing...");
|
|
@@ -1020,27 +1156,27 @@ var Interceptor = class {
|
|
|
1020
1156
|
});
|
|
1021
1157
|
return this;
|
|
1022
1158
|
};
|
|
1023
|
-
this.readyState =
|
|
1159
|
+
this.readyState = InterceptorReadyState.APPLIED;
|
|
1024
1160
|
return;
|
|
1025
1161
|
}
|
|
1026
1162
|
logger.info("no running instance found, setting up a new instance...");
|
|
1027
1163
|
this.setup();
|
|
1028
1164
|
this.setInstance();
|
|
1029
|
-
this.readyState =
|
|
1165
|
+
this.readyState = InterceptorReadyState.APPLIED;
|
|
1030
1166
|
}
|
|
1031
1167
|
/**
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1168
|
+
* Setup the module augments and stubs necessary for this interceptor.
|
|
1169
|
+
* This method is not run if there's a running interceptor instance
|
|
1170
|
+
* to prevent instantiating an interceptor multiple times.
|
|
1171
|
+
*/
|
|
1036
1172
|
setup() {
|
|
1037
1173
|
}
|
|
1038
1174
|
/**
|
|
1039
|
-
|
|
1040
|
-
|
|
1175
|
+
* Listen to the interceptor's public events.
|
|
1176
|
+
*/
|
|
1041
1177
|
on(event, listener) {
|
|
1042
1178
|
const logger = this.logger.extend("on");
|
|
1043
|
-
if (this.readyState ===
|
|
1179
|
+
if (this.readyState === InterceptorReadyState.DISPOSING || this.readyState === InterceptorReadyState.DISPOSED) {
|
|
1044
1180
|
logger.info("cannot listen to events, already disposed!");
|
|
1045
1181
|
return this;
|
|
1046
1182
|
}
|
|
@@ -1061,16 +1197,16 @@ var Interceptor = class {
|
|
|
1061
1197
|
return this;
|
|
1062
1198
|
}
|
|
1063
1199
|
/**
|
|
1064
|
-
|
|
1065
|
-
|
|
1200
|
+
* Disposes of any side-effects this interceptor has introduced.
|
|
1201
|
+
*/
|
|
1066
1202
|
dispose() {
|
|
1067
1203
|
const logger = this.logger.extend("dispose");
|
|
1068
|
-
if (this.readyState ===
|
|
1204
|
+
if (this.readyState === InterceptorReadyState.DISPOSED) {
|
|
1069
1205
|
logger.info("cannot dispose, already disposed!");
|
|
1070
1206
|
return;
|
|
1071
1207
|
}
|
|
1072
1208
|
logger.info("disposing the interceptor...");
|
|
1073
|
-
this.readyState =
|
|
1209
|
+
this.readyState = InterceptorReadyState.DISPOSING;
|
|
1074
1210
|
if (!this.getInstance()) {
|
|
1075
1211
|
logger.info("no interceptors running, skipping dispose...");
|
|
1076
1212
|
return;
|
|
@@ -1079,20 +1215,17 @@ var Interceptor = class {
|
|
|
1079
1215
|
logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
|
|
1080
1216
|
if (this.subscriptions.length > 0) {
|
|
1081
1217
|
logger.info("disposing of %d subscriptions...", this.subscriptions.length);
|
|
1082
|
-
for (const dispose of this.subscriptions)
|
|
1083
|
-
dispose();
|
|
1084
|
-
}
|
|
1218
|
+
for (const dispose of this.subscriptions) dispose();
|
|
1085
1219
|
this.subscriptions = [];
|
|
1086
1220
|
logger.info("disposed of all subscriptions!", this.subscriptions.length);
|
|
1087
1221
|
}
|
|
1088
1222
|
this.emitter.removeAllListeners();
|
|
1089
1223
|
logger.info("destroyed the listener!");
|
|
1090
|
-
this.readyState =
|
|
1224
|
+
this.readyState = InterceptorReadyState.DISPOSED;
|
|
1091
1225
|
}
|
|
1092
1226
|
getInstance() {
|
|
1093
|
-
var _a;
|
|
1094
1227
|
const instance = getGlobalSymbol(this.symbol);
|
|
1095
|
-
this.logger.info("retrieved global instance:",
|
|
1228
|
+
this.logger.info("retrieved global instance:", instance?.constructor?.name);
|
|
1096
1229
|
return instance;
|
|
1097
1230
|
}
|
|
1098
1231
|
setInstance() {
|
|
@@ -1108,192 +1241,23 @@ function createRequestId() {
|
|
|
1108
1241
|
return Math.random().toString(16).slice(2);
|
|
1109
1242
|
}
|
|
1110
1243
|
|
|
1111
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1112
|
-
var
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
super(message);
|
|
1116
|
-
this.name = "InterceptorError";
|
|
1117
|
-
Object.setPrototypeOf(this, InterceptorError.prototype);
|
|
1118
|
-
}
|
|
1119
|
-
};
|
|
1120
|
-
var _handled;
|
|
1121
|
-
var handled_get;
|
|
1122
|
-
var _RequestController = class {
|
|
1123
|
-
constructor(request, source) {
|
|
1124
|
-
this.request = request;
|
|
1125
|
-
this.source = source;
|
|
1126
|
-
__privateAdd(this, _handled);
|
|
1127
|
-
this.readyState = _RequestController.PENDING;
|
|
1128
|
-
this.handled = new DeferredPromise();
|
|
1129
|
-
}
|
|
1130
|
-
/**
|
|
1131
|
-
* Perform this request as-is.
|
|
1132
|
-
*/
|
|
1133
|
-
async passthrough() {
|
|
1134
|
-
invariant.as(
|
|
1135
|
-
InterceptorError,
|
|
1136
|
-
this.readyState === _RequestController.PENDING,
|
|
1137
|
-
'Failed to passthrough the "%s %s" request: the request has already been handled',
|
|
1138
|
-
this.request.method,
|
|
1139
|
-
this.request.url
|
|
1140
|
-
);
|
|
1141
|
-
this.readyState = _RequestController.PASSTHROUGH;
|
|
1142
|
-
await this.source.passthrough();
|
|
1143
|
-
__privateGet(this, _handled, handled_get).resolve();
|
|
1144
|
-
}
|
|
1145
|
-
/**
|
|
1146
|
-
* Respond to this request with the given `Response` instance.
|
|
1147
|
-
*
|
|
1148
|
-
* @example
|
|
1149
|
-
* controller.respondWith(new Response())
|
|
1150
|
-
* controller.respondWith(Response.json({ id }))
|
|
1151
|
-
* controller.respondWith(Response.error())
|
|
1152
|
-
*/
|
|
1153
|
-
respondWith(response) {
|
|
1154
|
-
invariant.as(
|
|
1155
|
-
InterceptorError,
|
|
1156
|
-
this.readyState === _RequestController.PENDING,
|
|
1157
|
-
'Failed to respond to the "%s %s" request with "%d %s": the request has already been handled (%d)',
|
|
1158
|
-
this.request.method,
|
|
1159
|
-
this.request.url,
|
|
1160
|
-
response.status,
|
|
1161
|
-
response.statusText || "OK",
|
|
1162
|
-
this.readyState
|
|
1163
|
-
);
|
|
1164
|
-
this.readyState = _RequestController.RESPONSE;
|
|
1165
|
-
__privateGet(this, _handled, handled_get).resolve();
|
|
1166
|
-
this.source.respondWith(response);
|
|
1167
|
-
}
|
|
1168
|
-
/**
|
|
1169
|
-
* Error this request with the given reason.
|
|
1170
|
-
*
|
|
1171
|
-
* @example
|
|
1172
|
-
* controller.errorWith()
|
|
1173
|
-
* controller.errorWith(new Error('Oops!'))
|
|
1174
|
-
* controller.errorWith({ message: 'Oops!'})
|
|
1175
|
-
*/
|
|
1176
|
-
errorWith(reason) {
|
|
1177
|
-
invariant.as(
|
|
1178
|
-
InterceptorError,
|
|
1179
|
-
this.readyState === _RequestController.PENDING,
|
|
1180
|
-
'Failed to error the "%s %s" request with "%s": the request has already been handled (%d)',
|
|
1181
|
-
this.request.method,
|
|
1182
|
-
this.request.url,
|
|
1183
|
-
reason == null ? void 0 : reason.toString(),
|
|
1184
|
-
this.readyState
|
|
1185
|
-
);
|
|
1186
|
-
this.readyState = _RequestController.ERROR;
|
|
1187
|
-
this.source.errorWith(reason);
|
|
1188
|
-
__privateGet(this, _handled, handled_get).resolve();
|
|
1189
|
-
}
|
|
1190
|
-
};
|
|
1191
|
-
var RequestController = _RequestController;
|
|
1192
|
-
_handled = /* @__PURE__ */ new WeakSet();
|
|
1193
|
-
handled_get = function() {
|
|
1194
|
-
return this.handled;
|
|
1195
|
-
};
|
|
1196
|
-
RequestController.PENDING = 0;
|
|
1197
|
-
RequestController.PASSTHROUGH = 1;
|
|
1198
|
-
RequestController.RESPONSE = 2;
|
|
1199
|
-
RequestController.ERROR = 3;
|
|
1200
|
-
function canParseUrl(url) {
|
|
1201
|
-
try {
|
|
1202
|
-
new URL(url);
|
|
1203
|
-
return true;
|
|
1204
|
-
} catch (_error) {
|
|
1205
|
-
return false;
|
|
1206
|
-
}
|
|
1244
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/bufferUtils-BiiO6HZv.mjs
|
|
1245
|
+
var encoder = new TextEncoder();
|
|
1246
|
+
function encodeBuffer(text) {
|
|
1247
|
+
return encoder.encode(text);
|
|
1207
1248
|
}
|
|
1208
|
-
function
|
|
1209
|
-
|
|
1210
|
-
const symbol = ownSymbols.find((symbol2) => {
|
|
1211
|
-
return symbol2.description === symbolName;
|
|
1212
|
-
});
|
|
1213
|
-
if (symbol) {
|
|
1214
|
-
return Reflect.get(source, symbol);
|
|
1215
|
-
}
|
|
1216
|
-
return;
|
|
1249
|
+
function decodeBuffer(buffer, encoding) {
|
|
1250
|
+
return new TextDecoder(encoding).decode(buffer);
|
|
1217
1251
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
return status >= 200 && status <= 599;
|
|
1221
|
-
}
|
|
1222
|
-
static isRedirectResponse(status) {
|
|
1223
|
-
return _FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
|
|
1224
|
-
}
|
|
1225
|
-
/**
|
|
1226
|
-
* Returns a boolean indicating whether the given response status
|
|
1227
|
-
* code represents a response that can have a body.
|
|
1228
|
-
*/
|
|
1229
|
-
static isResponseWithBody(status) {
|
|
1230
|
-
return !_FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
|
|
1231
|
-
}
|
|
1232
|
-
static setUrl(url, response) {
|
|
1233
|
-
if (!url || url === "about:" || !canParseUrl(url)) {
|
|
1234
|
-
return;
|
|
1235
|
-
}
|
|
1236
|
-
const state = getValueBySymbol("state", response);
|
|
1237
|
-
if (state) {
|
|
1238
|
-
state.urlList.push(new URL(url));
|
|
1239
|
-
} else {
|
|
1240
|
-
Object.defineProperty(response, "url", {
|
|
1241
|
-
value: url,
|
|
1242
|
-
enumerable: true,
|
|
1243
|
-
configurable: true,
|
|
1244
|
-
writable: false
|
|
1245
|
-
});
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
|
1250
|
-
*/
|
|
1251
|
-
static parseRawHeaders(rawHeaders) {
|
|
1252
|
-
const headers = new Headers();
|
|
1253
|
-
for (let line = 0; line < rawHeaders.length; line += 2) {
|
|
1254
|
-
headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
|
1255
|
-
}
|
|
1256
|
-
return headers;
|
|
1257
|
-
}
|
|
1258
|
-
constructor(body, init = {}) {
|
|
1259
|
-
var _a;
|
|
1260
|
-
const status = (_a = init.status) != null ? _a : 200;
|
|
1261
|
-
const safeStatus = _FetchResponse.isConfigurableStatusCode(status) ? status : 200;
|
|
1262
|
-
const finalBody = _FetchResponse.isResponseWithBody(status) ? body : null;
|
|
1263
|
-
super(finalBody, {
|
|
1264
|
-
status: safeStatus,
|
|
1265
|
-
statusText: init.statusText,
|
|
1266
|
-
headers: init.headers
|
|
1267
|
-
});
|
|
1268
|
-
if (status !== safeStatus) {
|
|
1269
|
-
const state = getValueBySymbol("state", this);
|
|
1270
|
-
if (state) {
|
|
1271
|
-
state.status = status;
|
|
1272
|
-
} else {
|
|
1273
|
-
Object.defineProperty(this, "status", {
|
|
1274
|
-
value: status,
|
|
1275
|
-
enumerable: true,
|
|
1276
|
-
configurable: true,
|
|
1277
|
-
writable: false
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
_FetchResponse.setUrl(init.url, this);
|
|
1282
|
-
}
|
|
1283
|
-
};
|
|
1284
|
-
var FetchResponse = _FetchResponse;
|
|
1285
|
-
FetchResponse.STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304];
|
|
1286
|
-
FetchResponse.STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308];
|
|
1287
|
-
var kRawRequest = Symbol("kRawRequest");
|
|
1288
|
-
function setRawRequest(request, rawRequest) {
|
|
1289
|
-
Reflect.set(request, kRawRequest, rawRequest);
|
|
1252
|
+
function toArrayBuffer(array) {
|
|
1253
|
+
return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
|
|
1290
1254
|
}
|
|
1291
1255
|
|
|
1292
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1293
|
-
var BatchInterceptor = class extends Interceptor {
|
|
1256
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1257
|
+
var BatchInterceptor = class BatchInterceptor2 extends Interceptor {
|
|
1294
1258
|
constructor(options) {
|
|
1295
|
-
|
|
1296
|
-
super(
|
|
1259
|
+
BatchInterceptor2.symbol = Symbol(options.name);
|
|
1260
|
+
super(BatchInterceptor2.symbol);
|
|
1297
1261
|
this.interceptors = options.interceptors;
|
|
1298
1262
|
}
|
|
1299
1263
|
setup() {
|
|
@@ -1307,27 +1271,19 @@ var BatchInterceptor = class extends Interceptor {
|
|
|
1307
1271
|
}
|
|
1308
1272
|
}
|
|
1309
1273
|
on(event, listener) {
|
|
1310
|
-
for (const interceptor of this.interceptors)
|
|
1311
|
-
interceptor.on(event, listener);
|
|
1312
|
-
}
|
|
1274
|
+
for (const interceptor of this.interceptors) interceptor.on(event, listener);
|
|
1313
1275
|
return this;
|
|
1314
1276
|
}
|
|
1315
1277
|
once(event, listener) {
|
|
1316
|
-
for (const interceptor of this.interceptors)
|
|
1317
|
-
interceptor.once(event, listener);
|
|
1318
|
-
}
|
|
1278
|
+
for (const interceptor of this.interceptors) interceptor.once(event, listener);
|
|
1319
1279
|
return this;
|
|
1320
1280
|
}
|
|
1321
1281
|
off(event, listener) {
|
|
1322
|
-
for (const interceptor of this.interceptors)
|
|
1323
|
-
interceptor.off(event, listener);
|
|
1324
|
-
}
|
|
1282
|
+
for (const interceptor of this.interceptors) interceptor.off(event, listener);
|
|
1325
1283
|
return this;
|
|
1326
1284
|
}
|
|
1327
1285
|
removeAllListeners(event) {
|
|
1328
|
-
for (const interceptors of this.interceptors)
|
|
1329
|
-
interceptors.removeAllListeners(event);
|
|
1330
|
-
}
|
|
1286
|
+
for (const interceptors of this.interceptors) interceptors.removeAllListeners(event);
|
|
1331
1287
|
return this;
|
|
1332
1288
|
}
|
|
1333
1289
|
};
|
|
@@ -1472,16 +1428,85 @@ var import_webSocketInterceptor = require("../core/ws/webSocketInterceptor");
|
|
|
1472
1428
|
var import_handleWebSocketEvent = require("../core/ws/handleWebSocketEvent");
|
|
1473
1429
|
var import_attachWebSocketLogger = require("../core/ws/utils/attachWebSocketLogger");
|
|
1474
1430
|
|
|
1475
|
-
// node_modules/.pnpm/rettime@0.
|
|
1431
|
+
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/lens-list.mjs
|
|
1432
|
+
var LensList = class {
|
|
1433
|
+
#list;
|
|
1434
|
+
#lens;
|
|
1435
|
+
constructor() {
|
|
1436
|
+
this.#list = [];
|
|
1437
|
+
this.#lens = /* @__PURE__ */ new Map();
|
|
1438
|
+
}
|
|
1439
|
+
get [Symbol.iterator]() {
|
|
1440
|
+
return this.#list[Symbol.iterator].bind(this.#list);
|
|
1441
|
+
}
|
|
1442
|
+
entries() {
|
|
1443
|
+
return this.#lens.entries();
|
|
1444
|
+
}
|
|
1445
|
+
/**
|
|
1446
|
+
* Return an order-sensitive list of values by the given key.
|
|
1447
|
+
*/
|
|
1448
|
+
get(key) {
|
|
1449
|
+
return this.#lens.get(key) || [];
|
|
1450
|
+
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Return an order-sensitive list of all values.
|
|
1453
|
+
*/
|
|
1454
|
+
getAll() {
|
|
1455
|
+
return this.#list.map(([, value]) => value);
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Append a new value to the given key.
|
|
1459
|
+
*/
|
|
1460
|
+
append(key, value) {
|
|
1461
|
+
this.#list.push([key, value]);
|
|
1462
|
+
this.#openLens(key, (list) => list.push(value));
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Prepend a new value to the given key.
|
|
1466
|
+
*/
|
|
1467
|
+
prepend(key, value) {
|
|
1468
|
+
this.#list.unshift([key, value]);
|
|
1469
|
+
this.#openLens(key, (list) => list.unshift(value));
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Delete the value belonging to the given key.
|
|
1473
|
+
*/
|
|
1474
|
+
delete(key, value) {
|
|
1475
|
+
if (this.size === 0) return;
|
|
1476
|
+
this.#list = this.#list.filter((item) => item[1] !== value);
|
|
1477
|
+
for (const [existingKey, values] of this.#lens) if (existingKey === key && values.includes(value)) values.splice(values.indexOf(value), 1);
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Delete all values belogning to the given key.
|
|
1481
|
+
*/
|
|
1482
|
+
deleteAll(key) {
|
|
1483
|
+
if (this.size === 0) return;
|
|
1484
|
+
this.#list = this.#list.filter((item) => item[0] !== key);
|
|
1485
|
+
this.#lens.delete(key);
|
|
1486
|
+
}
|
|
1487
|
+
get size() {
|
|
1488
|
+
return this.#list.length;
|
|
1489
|
+
}
|
|
1490
|
+
clear() {
|
|
1491
|
+
if (this.size === 0) return;
|
|
1492
|
+
this.#list.length = 0;
|
|
1493
|
+
this.#lens.clear();
|
|
1494
|
+
}
|
|
1495
|
+
#openLens(key, setter) {
|
|
1496
|
+
setter(this.#lens.get(key) || this.#lens.set(key, []).get(key));
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
|
|
1500
|
+
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/index.mjs
|
|
1476
1501
|
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
1477
1502
|
var kPropagationStopped = Symbol("kPropagationStopped");
|
|
1478
1503
|
var kImmediatePropagationStopped = Symbol("kImmediatePropagationStopped");
|
|
1479
1504
|
var TypedEvent = class extends MessageEvent {
|
|
1480
1505
|
/**
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1506
|
+
* @note Keep a placeholder property with the return type
|
|
1507
|
+
* because the type must be set somewhere in order to be
|
|
1508
|
+
* correctly associated and inferred from the event.
|
|
1509
|
+
*/
|
|
1485
1510
|
#returnType;
|
|
1486
1511
|
[kDefaultPrevented];
|
|
1487
1512
|
[kPropagationStopped];
|
|
@@ -1506,189 +1531,157 @@ var kListenerOptions = Symbol("kListenerOptions");
|
|
|
1506
1531
|
var Emitter2 = class {
|
|
1507
1532
|
#listeners;
|
|
1508
1533
|
constructor() {
|
|
1509
|
-
this.#listeners =
|
|
1534
|
+
this.#listeners = new LensList();
|
|
1510
1535
|
}
|
|
1511
1536
|
/**
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
* @returns {AbortController} An `AbortController` that can be used to remove the listener.
|
|
1515
|
-
*/
|
|
1537
|
+
* Adds a listener for the given event type.
|
|
1538
|
+
*/
|
|
1516
1539
|
on(type, listener, options) {
|
|
1517
|
-
|
|
1540
|
+
this.#addListener(type, listener, options);
|
|
1541
|
+
return this;
|
|
1518
1542
|
}
|
|
1519
1543
|
/**
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
* @returns {AbortController} An `AbortController` that can be used to remove the listener.
|
|
1523
|
-
*/
|
|
1544
|
+
* Adds a one-time listener for the given event type.
|
|
1545
|
+
*/
|
|
1524
1546
|
once(type, listener, options) {
|
|
1525
|
-
return this.on(type, listener, {
|
|
1547
|
+
return this.on(type, listener, {
|
|
1548
|
+
...options || {},
|
|
1549
|
+
once: true
|
|
1550
|
+
});
|
|
1526
1551
|
}
|
|
1527
1552
|
/**
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
* @returns {AbortController} An `AbortController` that can be used to remove the listener.
|
|
1531
|
-
*/
|
|
1553
|
+
* Prepends a listener for the given event type.
|
|
1554
|
+
*/
|
|
1532
1555
|
earlyOn(type, listener, options) {
|
|
1533
|
-
|
|
1556
|
+
this.#addListener(type, listener, options, "prepend");
|
|
1557
|
+
return this;
|
|
1534
1558
|
}
|
|
1535
1559
|
/**
|
|
1536
|
-
|
|
1537
|
-
|
|
1560
|
+
* Prepends a one-time listener for the given event type.
|
|
1561
|
+
*/
|
|
1538
1562
|
earlyOnce(type, listener, options) {
|
|
1539
|
-
return this.earlyOn(type, listener, {
|
|
1563
|
+
return this.earlyOn(type, listener, {
|
|
1564
|
+
...options || {},
|
|
1565
|
+
once: true
|
|
1566
|
+
});
|
|
1540
1567
|
}
|
|
1541
1568
|
/**
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1569
|
+
* Emits the given typed event.
|
|
1570
|
+
*
|
|
1571
|
+
* @returns {boolean} Returns `true` if the event had any listeners, `false` otherwise.
|
|
1572
|
+
*/
|
|
1546
1573
|
emit(event) {
|
|
1547
|
-
if (this.
|
|
1548
|
-
|
|
1549
|
-
}
|
|
1574
|
+
if (this.#listeners.size === 0) return false;
|
|
1575
|
+
const hasListeners = this.listenerCount(event.type) > 0;
|
|
1550
1576
|
const proxiedEvent = this.#proxyEvent(event);
|
|
1551
|
-
for (const listener of this.#
|
|
1577
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
1552
1578
|
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
1579
|
+
proxiedEvent.revoke();
|
|
1553
1580
|
return false;
|
|
1554
1581
|
}
|
|
1555
|
-
if (proxiedEvent.event[kImmediatePropagationStopped])
|
|
1556
|
-
break;
|
|
1557
|
-
}
|
|
1582
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
1558
1583
|
this.#callListener(proxiedEvent.event, listener);
|
|
1559
1584
|
}
|
|
1560
1585
|
proxiedEvent.revoke();
|
|
1561
|
-
return
|
|
1586
|
+
return hasListeners;
|
|
1562
1587
|
}
|
|
1563
1588
|
/**
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1589
|
+
* Emits the given typed event and returns a promise that resolves
|
|
1590
|
+
* when all the listeners for that event have settled.
|
|
1591
|
+
*
|
|
1592
|
+
* @returns {Promise<Array<Emitter.ListenerReturnType>>} A promise that resolves
|
|
1593
|
+
* with the return values of all listeners.
|
|
1594
|
+
*/
|
|
1570
1595
|
async emitAsPromise(event) {
|
|
1571
|
-
if (this.
|
|
1572
|
-
return [];
|
|
1573
|
-
}
|
|
1596
|
+
if (this.#listeners.size === 0) return [];
|
|
1574
1597
|
const pendingListeners = [];
|
|
1575
1598
|
const proxiedEvent = this.#proxyEvent(event);
|
|
1576
|
-
for (const listener of this.#
|
|
1599
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
1577
1600
|
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
1601
|
+
proxiedEvent.revoke();
|
|
1578
1602
|
return [];
|
|
1579
1603
|
}
|
|
1580
|
-
if (proxiedEvent.event[kImmediatePropagationStopped])
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
pendingListeners.push(
|
|
1584
|
-
// Awaiting individual listeners guarantees their call order.
|
|
1585
|
-
await Promise.resolve(this.#callListener(proxiedEvent.event, listener))
|
|
1586
|
-
);
|
|
1604
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
1605
|
+
const returnValue = await Promise.resolve(this.#callListener(proxiedEvent.event, listener));
|
|
1606
|
+
if (!this.#isTypelessListener(listener)) pendingListeners.push(returnValue);
|
|
1587
1607
|
}
|
|
1588
1608
|
proxiedEvent.revoke();
|
|
1589
1609
|
return Promise.allSettled(pendingListeners).then((results) => {
|
|
1590
|
-
return results.map(
|
|
1591
|
-
(result) => result.status === "fulfilled" ? result.value : result.reason
|
|
1592
|
-
);
|
|
1610
|
+
return results.map((result) => result.status === "fulfilled" ? result.value : result.reason);
|
|
1593
1611
|
});
|
|
1594
1612
|
}
|
|
1595
1613
|
/**
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1614
|
+
* Emits the given event and returns a generator that yields
|
|
1615
|
+
* the result of each listener in the order of their registration.
|
|
1616
|
+
* This way, you stop exhausting the listeners once you get the expected value.
|
|
1617
|
+
*/
|
|
1600
1618
|
*emitAsGenerator(event) {
|
|
1601
|
-
if (this.
|
|
1602
|
-
return;
|
|
1603
|
-
}
|
|
1619
|
+
if (this.#listeners.size === 0) return;
|
|
1604
1620
|
const proxiedEvent = this.#proxyEvent(event);
|
|
1605
|
-
for (const listener of this.#
|
|
1621
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
1606
1622
|
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
1623
|
+
proxiedEvent.revoke();
|
|
1607
1624
|
return;
|
|
1608
1625
|
}
|
|
1609
|
-
if (proxiedEvent.event[kImmediatePropagationStopped])
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
yield this.#callListener(proxiedEvent.event, listener);
|
|
1626
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
1627
|
+
const returnValue = this.#callListener(proxiedEvent.event, listener);
|
|
1628
|
+
if (!this.#isTypelessListener(listener)) yield returnValue;
|
|
1613
1629
|
}
|
|
1614
1630
|
proxiedEvent.revoke();
|
|
1615
1631
|
}
|
|
1616
1632
|
/**
|
|
1617
|
-
|
|
1618
|
-
|
|
1633
|
+
* Removes a listener for the given event type.
|
|
1634
|
+
*/
|
|
1619
1635
|
removeListener(type, listener) {
|
|
1620
|
-
|
|
1621
|
-
return;
|
|
1622
|
-
}
|
|
1623
|
-
const nextListeners = [];
|
|
1624
|
-
for (const existingListener of this.#listeners[type]) {
|
|
1625
|
-
if (existingListener !== listener) {
|
|
1626
|
-
nextListeners.push(existingListener);
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
this.#listeners[type] = nextListeners;
|
|
1636
|
+
this.#listeners.delete(type, listener);
|
|
1630
1637
|
}
|
|
1631
1638
|
/**
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1639
|
+
* Removes all listeners for the given event type.
|
|
1640
|
+
* If no event type is provided, removes all existing listeners.
|
|
1641
|
+
*/
|
|
1635
1642
|
removeAllListeners(type) {
|
|
1636
1643
|
if (type == null) {
|
|
1637
|
-
this.#listeners
|
|
1644
|
+
this.#listeners.clear();
|
|
1638
1645
|
return;
|
|
1639
1646
|
}
|
|
1640
|
-
this.#listeners
|
|
1647
|
+
this.#listeners.deleteAll(type);
|
|
1641
1648
|
}
|
|
1642
1649
|
/**
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1650
|
+
* Returns the list of listeners for the given event type.
|
|
1651
|
+
* If no even type is provided, returns all listeners.
|
|
1652
|
+
*/
|
|
1646
1653
|
listeners(type) {
|
|
1647
|
-
if (type == null)
|
|
1648
|
-
|
|
1649
|
-
}
|
|
1650
|
-
return this.#listeners[type] || [];
|
|
1654
|
+
if (type == null) return this.#listeners.getAll();
|
|
1655
|
+
return this.#listeners.get(type);
|
|
1651
1656
|
}
|
|
1652
1657
|
/**
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1658
|
+
* Returns the number of listeners for the given event type.
|
|
1659
|
+
* If no even type is provided, returns the total number of listeners.
|
|
1660
|
+
*/
|
|
1656
1661
|
listenerCount(type) {
|
|
1662
|
+
if (type == null) return this.#listeners.size;
|
|
1657
1663
|
return this.listeners(type).length;
|
|
1658
1664
|
}
|
|
1659
1665
|
#addListener(type, listener, options, insertMode = "append") {
|
|
1660
|
-
this.#listeners
|
|
1661
|
-
|
|
1662
|
-
this.#listeners[type].unshift(listener);
|
|
1663
|
-
} else {
|
|
1664
|
-
this.#listeners[type].push(listener);
|
|
1665
|
-
}
|
|
1666
|
+
if (insertMode === "prepend") this.#listeners.prepend(type, listener);
|
|
1667
|
+
else this.#listeners.append(type, listener);
|
|
1666
1668
|
if (options) {
|
|
1667
1669
|
Object.defineProperty(listener, kListenerOptions, {
|
|
1668
1670
|
value: options,
|
|
1669
1671
|
enumerable: false,
|
|
1670
1672
|
writable: false
|
|
1671
1673
|
});
|
|
1672
|
-
if (options.signal) {
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
() => {
|
|
1676
|
-
this.removeListener(type, listener);
|
|
1677
|
-
},
|
|
1678
|
-
{ once: true }
|
|
1679
|
-
);
|
|
1680
|
-
}
|
|
1674
|
+
if (options.signal) options.signal.addEventListener("abort", () => {
|
|
1675
|
+
this.removeListener(type, listener);
|
|
1676
|
+
}, { once: true });
|
|
1681
1677
|
}
|
|
1682
|
-
return this;
|
|
1683
1678
|
}
|
|
1684
1679
|
#proxyEvent(event) {
|
|
1685
1680
|
const { stopPropagation } = event;
|
|
1686
|
-
event.stopPropagation = new Proxy(event.stopPropagation, {
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
}
|
|
1691
|
-
});
|
|
1681
|
+
event.stopPropagation = new Proxy(event.stopPropagation, { apply: (target, thisArg, argArray) => {
|
|
1682
|
+
event[kPropagationStopped] = this;
|
|
1683
|
+
return Reflect.apply(target, thisArg, argArray);
|
|
1684
|
+
} });
|
|
1692
1685
|
return {
|
|
1693
1686
|
event,
|
|
1694
1687
|
revoke() {
|
|
@@ -1699,10 +1692,21 @@ var Emitter2 = class {
|
|
|
1699
1692
|
#callListener(event, listener) {
|
|
1700
1693
|
const returnValue = listener.call(this, event);
|
|
1701
1694
|
if (listener[kListenerOptions]?.once) {
|
|
1702
|
-
this
|
|
1695
|
+
const key = this.#isTypelessListener(listener) ? "*" : event.type;
|
|
1696
|
+
this.#listeners.delete(key, listener);
|
|
1703
1697
|
}
|
|
1704
1698
|
return returnValue;
|
|
1705
1699
|
}
|
|
1700
|
+
/**
|
|
1701
|
+
* Return a list of all event listeners relevant for the given event type.
|
|
1702
|
+
* This includes the explicit event listeners and also typeless event listeners.
|
|
1703
|
+
*/
|
|
1704
|
+
*#matchListeners(type) {
|
|
1705
|
+
for (const [key, listener] of this.#listeners) if (key === "*" || key === type) yield listener;
|
|
1706
|
+
}
|
|
1707
|
+
#isTypelessListener(listener) {
|
|
1708
|
+
return this.#listeners.get("*").includes(listener);
|
|
1709
|
+
}
|
|
1706
1710
|
};
|
|
1707
1711
|
|
|
1708
1712
|
// src/browser/utils/workerChannel.ts
|
|
@@ -1765,31 +1769,19 @@ var WorkerChannel = class extends Emitter2 {
|
|
|
1765
1769
|
}
|
|
1766
1770
|
};
|
|
1767
1771
|
|
|
1768
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1772
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-C8kXFDic.mjs
|
|
1769
1773
|
async function emitAsync(emitter, eventName, ...data) {
|
|
1770
1774
|
const listeners = emitter.listeners(eventName);
|
|
1771
|
-
if (listeners.length === 0)
|
|
1772
|
-
|
|
1773
|
-
}
|
|
1774
|
-
for (const listener of listeners) {
|
|
1775
|
-
await listener.apply(emitter, data);
|
|
1776
|
-
}
|
|
1775
|
+
if (listeners.length === 0) return;
|
|
1776
|
+
for (const listener of listeners) await listener.apply(emitter, data);
|
|
1777
1777
|
}
|
|
1778
1778
|
function hasConfigurableGlobal(propertyName) {
|
|
1779
1779
|
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
1780
|
-
if (typeof descriptor === "undefined")
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") {
|
|
1784
|
-
return false;
|
|
1785
|
-
}
|
|
1786
|
-
if (typeof descriptor.get === "undefined" && descriptor.value == null) {
|
|
1787
|
-
return false;
|
|
1788
|
-
}
|
|
1780
|
+
if (typeof descriptor === "undefined") return false;
|
|
1781
|
+
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
1782
|
+
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
1789
1783
|
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
1790
|
-
console.error(
|
|
1791
|
-
`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`
|
|
1792
|
-
);
|
|
1784
|
+
console.error(`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`);
|
|
1793
1785
|
return false;
|
|
1794
1786
|
}
|
|
1795
1787
|
return true;
|
|
@@ -1807,7 +1799,7 @@ var until2 = async (promise) => {
|
|
|
1807
1799
|
}
|
|
1808
1800
|
};
|
|
1809
1801
|
|
|
1810
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1802
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/handleRequest-DxGbCTbb.mjs
|
|
1811
1803
|
function isObject2(value, loose = false) {
|
|
1812
1804
|
return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
|
|
1813
1805
|
}
|
|
@@ -1815,27 +1807,20 @@ function isPropertyAccessible(obj, key) {
|
|
|
1815
1807
|
try {
|
|
1816
1808
|
obj[key];
|
|
1817
1809
|
return true;
|
|
1818
|
-
} catch
|
|
1810
|
+
} catch {
|
|
1819
1811
|
return false;
|
|
1820
1812
|
}
|
|
1821
1813
|
}
|
|
1822
1814
|
function createServerErrorResponse(body) {
|
|
1823
|
-
return new Response(
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
status: 500,
|
|
1833
|
-
statusText: "Unhandled Exception",
|
|
1834
|
-
headers: {
|
|
1835
|
-
"Content-Type": "application/json"
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
);
|
|
1815
|
+
return new Response(JSON.stringify(body instanceof Error ? {
|
|
1816
|
+
name: body.name,
|
|
1817
|
+
message: body.message,
|
|
1818
|
+
stack: body.stack
|
|
1819
|
+
} : body), {
|
|
1820
|
+
status: 500,
|
|
1821
|
+
statusText: "Unhandled Exception",
|
|
1822
|
+
headers: { "Content-Type": "application/json" }
|
|
1823
|
+
});
|
|
1839
1824
|
}
|
|
1840
1825
|
function isResponseError(response) {
|
|
1841
1826
|
return response != null && response instanceof Response && isPropertyAccessible(response, "type") && response.type === "error";
|
|
@@ -1844,12 +1829,8 @@ function isResponseLike(value) {
|
|
|
1844
1829
|
return isObject2(value, true) && isPropertyAccessible(value, "status") && isPropertyAccessible(value, "statusText") && isPropertyAccessible(value, "bodyUsed");
|
|
1845
1830
|
}
|
|
1846
1831
|
function isNodeLikeError(error2) {
|
|
1847
|
-
if (error2 == null)
|
|
1848
|
-
|
|
1849
|
-
}
|
|
1850
|
-
if (!(error2 instanceof Error)) {
|
|
1851
|
-
return false;
|
|
1852
|
-
}
|
|
1832
|
+
if (error2 == null) return false;
|
|
1833
|
+
if (!(error2 instanceof Error)) return false;
|
|
1853
1834
|
return "code" in error2 && "errno" in error2;
|
|
1854
1835
|
}
|
|
1855
1836
|
async function handleRequest2(options) {
|
|
@@ -1873,16 +1854,12 @@ async function handleRequest2(options) {
|
|
|
1873
1854
|
return false;
|
|
1874
1855
|
};
|
|
1875
1856
|
const handleResponseError = async (error2) => {
|
|
1876
|
-
if (error2 instanceof InterceptorError)
|
|
1877
|
-
throw result.error;
|
|
1878
|
-
}
|
|
1857
|
+
if (error2 instanceof InterceptorError) throw result.error;
|
|
1879
1858
|
if (isNodeLikeError(error2)) {
|
|
1880
1859
|
await options.controller.errorWith(error2);
|
|
1881
1860
|
return true;
|
|
1882
1861
|
}
|
|
1883
|
-
if (error2 instanceof Response)
|
|
1884
|
-
return await handleResponse(error2);
|
|
1885
|
-
}
|
|
1862
|
+
if (error2 instanceof Response) return await handleResponse(error2);
|
|
1886
1863
|
return false;
|
|
1887
1864
|
};
|
|
1888
1865
|
const requestAbortPromise = new DeferredPromise();
|
|
@@ -1891,13 +1868,9 @@ async function handleRequest2(options) {
|
|
|
1891
1868
|
await options.controller.errorWith(options.request.signal.reason);
|
|
1892
1869
|
return;
|
|
1893
1870
|
}
|
|
1894
|
-
options.request.signal.addEventListener(
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
requestAbortPromise.reject(options.request.signal.reason);
|
|
1898
|
-
},
|
|
1899
|
-
{ once: true }
|
|
1900
|
-
);
|
|
1871
|
+
options.request.signal.addEventListener("abort", () => {
|
|
1872
|
+
requestAbortPromise.reject(options.request.signal.reason);
|
|
1873
|
+
}, { once: true });
|
|
1901
1874
|
}
|
|
1902
1875
|
const result = await until2(async () => {
|
|
1903
1876
|
const requestListenersPromise = emitAsync(options.emitter, "request", {
|
|
@@ -1906,7 +1879,6 @@ async function handleRequest2(options) {
|
|
|
1906
1879
|
controller: options.controller
|
|
1907
1880
|
});
|
|
1908
1881
|
await Promise.race([
|
|
1909
|
-
// Short-circuit the request handling promise if the request gets aborted.
|
|
1910
1882
|
requestAbortPromise,
|
|
1911
1883
|
requestListenersPromise,
|
|
1912
1884
|
options.controller.handled
|
|
@@ -1917,54 +1889,36 @@ async function handleRequest2(options) {
|
|
|
1917
1889
|
return;
|
|
1918
1890
|
}
|
|
1919
1891
|
if (result.error) {
|
|
1920
|
-
if (await handleResponseError(result.error))
|
|
1921
|
-
return;
|
|
1922
|
-
}
|
|
1892
|
+
if (await handleResponseError(result.error)) return;
|
|
1923
1893
|
if (options.emitter.listenerCount("unhandledException") > 0) {
|
|
1924
|
-
const unhandledExceptionController = new RequestController(
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
passthrough() {
|
|
1933
|
-
},
|
|
1934
|
-
async respondWith(response) {
|
|
1935
|
-
await handleResponse(response);
|
|
1936
|
-
},
|
|
1937
|
-
async errorWith(reason) {
|
|
1938
|
-
await options.controller.errorWith(reason);
|
|
1939
|
-
}
|
|
1894
|
+
const unhandledExceptionController = new RequestController(options.request, {
|
|
1895
|
+
passthrough() {
|
|
1896
|
+
},
|
|
1897
|
+
async respondWith(response) {
|
|
1898
|
+
await handleResponse(response);
|
|
1899
|
+
},
|
|
1900
|
+
async errorWith(reason) {
|
|
1901
|
+
await options.controller.errorWith(reason);
|
|
1940
1902
|
}
|
|
1941
|
-
);
|
|
1903
|
+
});
|
|
1942
1904
|
await emitAsync(options.emitter, "unhandledException", {
|
|
1943
1905
|
error: result.error,
|
|
1944
1906
|
request: options.request,
|
|
1945
1907
|
requestId: options.requestId,
|
|
1946
1908
|
controller: unhandledExceptionController
|
|
1947
1909
|
});
|
|
1948
|
-
if (unhandledExceptionController.readyState !== RequestController.PENDING)
|
|
1949
|
-
return;
|
|
1950
|
-
}
|
|
1910
|
+
if (unhandledExceptionController.readyState !== RequestController.PENDING) return;
|
|
1951
1911
|
}
|
|
1952
|
-
await options.controller.respondWith(
|
|
1953
|
-
createServerErrorResponse(result.error)
|
|
1954
|
-
);
|
|
1912
|
+
await options.controller.respondWith(createServerErrorResponse(result.error));
|
|
1955
1913
|
return;
|
|
1956
1914
|
}
|
|
1957
|
-
if (options.controller.readyState === RequestController.PENDING)
|
|
1958
|
-
return await options.controller.passthrough();
|
|
1959
|
-
}
|
|
1915
|
+
if (options.controller.readyState === RequestController.PENDING) return await options.controller.passthrough();
|
|
1960
1916
|
return options.controller.handled;
|
|
1961
1917
|
}
|
|
1962
1918
|
|
|
1963
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1919
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/fetch-DSJoynSF.mjs
|
|
1964
1920
|
function createNetworkError(cause) {
|
|
1965
|
-
return Object.assign(new TypeError("Failed to fetch"), {
|
|
1966
|
-
cause
|
|
1967
|
-
});
|
|
1921
|
+
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
|
1968
1922
|
}
|
|
1969
1923
|
var REQUEST_BODY_HEADERS = [
|
|
1970
1924
|
"content-encoding",
|
|
@@ -1975,9 +1929,7 @@ var REQUEST_BODY_HEADERS = [
|
|
|
1975
1929
|
];
|
|
1976
1930
|
var kRedirectCount = Symbol("kRedirectCount");
|
|
1977
1931
|
async function followFetchRedirect(request, response) {
|
|
1978
|
-
if (response.status !== 303 && request.body != null)
|
|
1979
|
-
return Promise.reject(createNetworkError());
|
|
1980
|
-
}
|
|
1932
|
+
if (response.status !== 303 && request.body != null) return Promise.reject(createNetworkError());
|
|
1981
1933
|
const requestUrl = new URL(request.url);
|
|
1982
1934
|
let locationUrl;
|
|
1983
1935
|
try {
|
|
@@ -1985,22 +1937,10 @@ async function followFetchRedirect(request, response) {
|
|
|
1985
1937
|
} catch (error2) {
|
|
1986
1938
|
return Promise.reject(createNetworkError(error2));
|
|
1987
1939
|
}
|
|
1988
|
-
if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:"))
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
}
|
|
1993
|
-
if (Reflect.get(request, kRedirectCount) > 20) {
|
|
1994
|
-
return Promise.reject(createNetworkError("redirect count exceeded"));
|
|
1995
|
-
}
|
|
1996
|
-
Object.defineProperty(request, kRedirectCount, {
|
|
1997
|
-
value: (Reflect.get(request, kRedirectCount) || 0) + 1
|
|
1998
|
-
});
|
|
1999
|
-
if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) {
|
|
2000
|
-
return Promise.reject(
|
|
2001
|
-
createNetworkError('cross origin not allowed for request mode "cors"')
|
|
2002
|
-
);
|
|
2003
|
-
}
|
|
1940
|
+
if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) return Promise.reject(createNetworkError("URL scheme must be a HTTP(S) scheme"));
|
|
1941
|
+
if (Reflect.get(request, kRedirectCount) > 20) return Promise.reject(createNetworkError("redirect count exceeded"));
|
|
1942
|
+
Object.defineProperty(request, kRedirectCount, { value: (Reflect.get(request, kRedirectCount) || 0) + 1 });
|
|
1943
|
+
if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) return Promise.reject(createNetworkError('cross origin not allowed for request mode "cors"'));
|
|
2004
1944
|
const requestInit = {};
|
|
2005
1945
|
if ([301, 302].includes(response.status) && request.method === "POST" || response.status === 303 && !["HEAD", "GET"].includes(request.method)) {
|
|
2006
1946
|
requestInit.method = "GET";
|
|
@@ -2024,111 +1964,74 @@ async function followFetchRedirect(request, response) {
|
|
|
2024
1964
|
return finalResponse;
|
|
2025
1965
|
}
|
|
2026
1966
|
function sameOrigin(left, right) {
|
|
2027
|
-
if (left.origin === right.origin && left.origin === "null")
|
|
2028
|
-
|
|
2029
|
-
}
|
|
2030
|
-
if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) {
|
|
2031
|
-
return true;
|
|
2032
|
-
}
|
|
1967
|
+
if (left.origin === right.origin && left.origin === "null") return true;
|
|
1968
|
+
if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) return true;
|
|
2033
1969
|
return false;
|
|
2034
1970
|
}
|
|
2035
1971
|
var BrotliDecompressionStream = class extends TransformStream {
|
|
2036
1972
|
constructor() {
|
|
2037
|
-
console.warn(
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
transform(chunk, controller) {
|
|
2042
|
-
controller.enqueue(chunk);
|
|
2043
|
-
}
|
|
2044
|
-
});
|
|
1973
|
+
console.warn("[Interceptors]: Brotli decompression of response streams is not supported in the browser");
|
|
1974
|
+
super({ transform(chunk, controller) {
|
|
1975
|
+
controller.enqueue(chunk);
|
|
1976
|
+
} });
|
|
2045
1977
|
}
|
|
2046
1978
|
};
|
|
2047
1979
|
var PipelineStream = class extends TransformStream {
|
|
2048
1980
|
constructor(transformStreams, ...strategies) {
|
|
2049
1981
|
super({}, ...strategies);
|
|
2050
|
-
const readable = [super.readable, ...transformStreams].reduce(
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
get() {
|
|
2055
|
-
return readable;
|
|
2056
|
-
}
|
|
2057
|
-
});
|
|
1982
|
+
const readable = [super.readable, ...transformStreams].reduce((readable$1, transform) => readable$1.pipeThrough(transform));
|
|
1983
|
+
Object.defineProperty(this, "readable", { get() {
|
|
1984
|
+
return readable;
|
|
1985
|
+
} });
|
|
2058
1986
|
}
|
|
2059
1987
|
};
|
|
2060
1988
|
function parseContentEncoding(contentEncoding) {
|
|
2061
1989
|
return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
|
|
2062
1990
|
}
|
|
2063
1991
|
function createDecompressionStream(contentEncoding) {
|
|
2064
|
-
if (contentEncoding === "")
|
|
2065
|
-
return null;
|
|
2066
|
-
}
|
|
1992
|
+
if (contentEncoding === "") return null;
|
|
2067
1993
|
const codings = parseContentEncoding(contentEncoding);
|
|
2068
|
-
if (codings.length === 0)
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
(
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
return transformers2.concat(new DecompressionStream("deflate"));
|
|
2077
|
-
} else if (coding === "br") {
|
|
2078
|
-
return transformers2.concat(new BrotliDecompressionStream());
|
|
2079
|
-
} else {
|
|
2080
|
-
transformers2.length = 0;
|
|
2081
|
-
}
|
|
2082
|
-
return transformers2;
|
|
2083
|
-
},
|
|
2084
|
-
[]
|
|
2085
|
-
);
|
|
2086
|
-
return new PipelineStream(transformers);
|
|
1994
|
+
if (codings.length === 0) return null;
|
|
1995
|
+
return new PipelineStream(codings.reduceRight((transformers, coding) => {
|
|
1996
|
+
if (coding === "gzip" || coding === "x-gzip") return transformers.concat(new DecompressionStream("gzip"));
|
|
1997
|
+
else if (coding === "deflate") return transformers.concat(new DecompressionStream("deflate"));
|
|
1998
|
+
else if (coding === "br") return transformers.concat(new BrotliDecompressionStream());
|
|
1999
|
+
else transformers.length = 0;
|
|
2000
|
+
return transformers;
|
|
2001
|
+
}, []));
|
|
2087
2002
|
}
|
|
2088
2003
|
function decompressResponse(response) {
|
|
2089
|
-
if (response.body === null)
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
const decompressionStream = createDecompressionStream(
|
|
2093
|
-
response.headers.get("content-encoding") || ""
|
|
2094
|
-
);
|
|
2095
|
-
if (!decompressionStream) {
|
|
2096
|
-
return null;
|
|
2097
|
-
}
|
|
2004
|
+
if (response.body === null) return null;
|
|
2005
|
+
const decompressionStream = createDecompressionStream(response.headers.get("content-encoding") || "");
|
|
2006
|
+
if (!decompressionStream) return null;
|
|
2098
2007
|
response.body.pipeTo(decompressionStream.writable);
|
|
2099
2008
|
return decompressionStream.readable;
|
|
2100
2009
|
}
|
|
2101
|
-
var
|
|
2010
|
+
var FetchInterceptor = class FetchInterceptor2 extends Interceptor {
|
|
2011
|
+
static {
|
|
2012
|
+
this.symbol = Symbol("fetch");
|
|
2013
|
+
}
|
|
2102
2014
|
constructor() {
|
|
2103
|
-
super(
|
|
2015
|
+
super(FetchInterceptor2.symbol);
|
|
2104
2016
|
}
|
|
2105
2017
|
checkEnvironment() {
|
|
2106
2018
|
return hasConfigurableGlobal("fetch");
|
|
2107
2019
|
}
|
|
2108
2020
|
async setup() {
|
|
2109
2021
|
const pureFetch = globalThis.fetch;
|
|
2110
|
-
invariant(
|
|
2111
|
-
!pureFetch[IS_PATCHED_MODULE],
|
|
2112
|
-
'Failed to patch the "fetch" module: already patched.'
|
|
2113
|
-
);
|
|
2022
|
+
invariant(!pureFetch[IS_PATCHED_MODULE], 'Failed to patch the "fetch" module: already patched.');
|
|
2114
2023
|
globalThis.fetch = async (input, init) => {
|
|
2115
2024
|
const requestId = createRequestId();
|
|
2116
2025
|
const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.href) : input;
|
|
2117
2026
|
const request = new Request(resolvedInput, init);
|
|
2118
|
-
if (input instanceof Request)
|
|
2119
|
-
setRawRequest(request, input);
|
|
2120
|
-
}
|
|
2027
|
+
if (input instanceof Request) setRawRequest(request, input);
|
|
2121
2028
|
const responsePromise = new DeferredPromise();
|
|
2122
2029
|
const controller = new RequestController(request, {
|
|
2123
2030
|
passthrough: async () => {
|
|
2124
2031
|
this.logger.info("request has not been handled, passthrough...");
|
|
2125
2032
|
const requestCloneForResponseEvent = request.clone();
|
|
2126
|
-
const { error: responseError, data: originalResponse } = await until2(
|
|
2127
|
-
|
|
2128
|
-
);
|
|
2129
|
-
if (responseError) {
|
|
2130
|
-
return responsePromise.reject(responseError);
|
|
2131
|
-
}
|
|
2033
|
+
const { error: responseError, data: originalResponse } = await until2(() => pureFetch(request));
|
|
2034
|
+
if (responseError) return responsePromise.reject(responseError);
|
|
2132
2035
|
this.logger.info("original fetch performed", originalResponse);
|
|
2133
2036
|
if (this.emitter.listenerCount("response") > 0) {
|
|
2134
2037
|
this.logger.info('emitting the "response" event...');
|
|
@@ -2148,9 +2051,7 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
2148
2051
|
responsePromise.reject(createNetworkError(rawResponse));
|
|
2149
2052
|
return;
|
|
2150
2053
|
}
|
|
2151
|
-
this.logger.info("received mocked response!", {
|
|
2152
|
-
rawResponse
|
|
2153
|
-
});
|
|
2054
|
+
this.logger.info("received mocked response!", { rawResponse });
|
|
2154
2055
|
const decompressedStream = decompressResponse(rawResponse);
|
|
2155
2056
|
const response = decompressedStream === null ? rawResponse : new FetchResponse(decompressedStream, rawResponse);
|
|
2156
2057
|
FetchResponse.setUrl(request.url, response);
|
|
@@ -2160,23 +2061,17 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
2160
2061
|
return;
|
|
2161
2062
|
}
|
|
2162
2063
|
if (request.redirect === "follow") {
|
|
2163
|
-
followFetchRedirect(request, response).then(
|
|
2164
|
-
(
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
responsePromise.reject(reason);
|
|
2169
|
-
}
|
|
2170
|
-
);
|
|
2064
|
+
followFetchRedirect(request, response).then((response$1) => {
|
|
2065
|
+
responsePromise.resolve(response$1);
|
|
2066
|
+
}, (reason) => {
|
|
2067
|
+
responsePromise.reject(reason);
|
|
2068
|
+
});
|
|
2171
2069
|
return;
|
|
2172
2070
|
}
|
|
2173
2071
|
}
|
|
2174
2072
|
if (this.emitter.listenerCount("response") > 0) {
|
|
2175
2073
|
this.logger.info('emitting the "response" event...');
|
|
2176
2074
|
await emitAsync(this.emitter, "response", {
|
|
2177
|
-
// Clone the mocked response for the "response" event listener.
|
|
2178
|
-
// This way, the listener can read the response and not lock its body
|
|
2179
|
-
// for the actual fetch consumer.
|
|
2180
2075
|
response: response.clone(),
|
|
2181
2076
|
isMockedResponse: true,
|
|
2182
2077
|
request,
|
|
@@ -2192,10 +2087,7 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
2192
2087
|
});
|
|
2193
2088
|
this.logger.info("[%s] %s", request.method, request.url);
|
|
2194
2089
|
this.logger.info("awaiting for the mocked response...");
|
|
2195
|
-
this.logger.info(
|
|
2196
|
-
'emitting the "request" event for %s listener(s)...',
|
|
2197
|
-
this.emitter.listenerCount("request")
|
|
2198
|
-
);
|
|
2090
|
+
this.logger.info('emitting the "request" event for %s listener(s)...', this.emitter.listenerCount("request"));
|
|
2199
2091
|
await handleRequest2({
|
|
2200
2092
|
request,
|
|
2201
2093
|
requestId,
|
|
@@ -2210,21 +2102,14 @@ var _FetchInterceptor = class extends Interceptor {
|
|
|
2210
2102
|
value: true
|
|
2211
2103
|
});
|
|
2212
2104
|
this.subscriptions.push(() => {
|
|
2213
|
-
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {
|
|
2214
|
-
value: void 0
|
|
2215
|
-
});
|
|
2105
|
+
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, { value: void 0 });
|
|
2216
2106
|
globalThis.fetch = pureFetch;
|
|
2217
|
-
this.logger.info(
|
|
2218
|
-
'restored native "globalThis.fetch"!',
|
|
2219
|
-
globalThis.fetch.name
|
|
2220
|
-
);
|
|
2107
|
+
this.logger.info('restored native "globalThis.fetch"!', globalThis.fetch.name);
|
|
2221
2108
|
});
|
|
2222
2109
|
}
|
|
2223
2110
|
};
|
|
2224
|
-
var FetchInterceptor = _FetchInterceptor;
|
|
2225
|
-
FetchInterceptor.symbol = Symbol("fetch");
|
|
2226
2111
|
|
|
2227
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
2112
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.0/node_modules/@mswjs/interceptors/lib/browser/XMLHttpRequest-DS5fc8Qs.mjs
|
|
2228
2113
|
function concatArrayBuffer(left, right) {
|
|
2229
2114
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
2230
2115
|
result.set(left, 0);
|
|
@@ -2252,8 +2137,8 @@ var EventPolyfill = class {
|
|
|
2252
2137
|
this.cancelBubble = false;
|
|
2253
2138
|
this.returnValue = true;
|
|
2254
2139
|
this.type = type;
|
|
2255
|
-
this.target =
|
|
2256
|
-
this.currentTarget =
|
|
2140
|
+
this.target = options?.target || null;
|
|
2141
|
+
this.currentTarget = options?.currentTarget || null;
|
|
2257
2142
|
this.timeStamp = Date.now();
|
|
2258
2143
|
}
|
|
2259
2144
|
composedPath() {
|
|
@@ -2275,10 +2160,10 @@ var EventPolyfill = class {
|
|
|
2275
2160
|
var ProgressEventPolyfill = class extends EventPolyfill {
|
|
2276
2161
|
constructor(type, init) {
|
|
2277
2162
|
super(type);
|
|
2278
|
-
this.lengthComputable =
|
|
2279
|
-
this.composed =
|
|
2280
|
-
this.loaded =
|
|
2281
|
-
this.total =
|
|
2163
|
+
this.lengthComputable = init?.lengthComputable || false;
|
|
2164
|
+
this.composed = init?.composed || false;
|
|
2165
|
+
this.loaded = init?.loaded || 0;
|
|
2166
|
+
this.total = init?.total || 0;
|
|
2282
2167
|
}
|
|
2283
2168
|
};
|
|
2284
2169
|
var SUPPORTS_PROGRESS_EVENT = typeof ProgressEvent !== "undefined";
|
|
@@ -2293,48 +2178,36 @@ function createEvent(target, type, init) {
|
|
|
2293
2178
|
"abort"
|
|
2294
2179
|
];
|
|
2295
2180
|
const ProgressEventClass = SUPPORTS_PROGRESS_EVENT ? ProgressEvent : ProgressEventPolyfill;
|
|
2296
|
-
|
|
2181
|
+
return progressEvents.includes(type) ? new ProgressEventClass(type, {
|
|
2297
2182
|
lengthComputable: true,
|
|
2298
|
-
loaded:
|
|
2299
|
-
total:
|
|
2183
|
+
loaded: init?.loaded || 0,
|
|
2184
|
+
total: init?.total || 0
|
|
2300
2185
|
}) : new EventPolyfill(type, {
|
|
2301
2186
|
target,
|
|
2302
2187
|
currentTarget: target
|
|
2303
2188
|
});
|
|
2304
|
-
return event;
|
|
2305
2189
|
}
|
|
2306
2190
|
function findPropertySource(target, propertyName) {
|
|
2307
|
-
if (!(propertyName in target))
|
|
2308
|
-
|
|
2309
|
-
}
|
|
2310
|
-
const hasProperty = Object.prototype.hasOwnProperty.call(target, propertyName);
|
|
2311
|
-
if (hasProperty) {
|
|
2312
|
-
return target;
|
|
2313
|
-
}
|
|
2191
|
+
if (!(propertyName in target)) return null;
|
|
2192
|
+
if (Object.prototype.hasOwnProperty.call(target, propertyName)) return target;
|
|
2314
2193
|
const prototype = Reflect.getPrototypeOf(target);
|
|
2315
2194
|
return prototype ? findPropertySource(prototype, propertyName) : null;
|
|
2316
2195
|
}
|
|
2317
2196
|
function createProxy(target, options) {
|
|
2318
|
-
|
|
2319
|
-
return proxy;
|
|
2197
|
+
return new Proxy(target, optionsToProxyHandler(options));
|
|
2320
2198
|
}
|
|
2321
2199
|
function optionsToProxyHandler(options) {
|
|
2322
2200
|
const { constructorCall, methodCall, getProperty, setProperty } = options;
|
|
2323
2201
|
const handler = {};
|
|
2324
|
-
if (typeof constructorCall !== "undefined") {
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2202
|
+
if (typeof constructorCall !== "undefined") handler.construct = function(target, args, newTarget) {
|
|
2203
|
+
const next = Reflect.construct.bind(null, target, args, newTarget);
|
|
2204
|
+
return constructorCall.call(newTarget, args, next);
|
|
2205
|
+
};
|
|
2330
2206
|
handler.set = function(target, propertyName, nextValue) {
|
|
2331
2207
|
const next = () => {
|
|
2332
2208
|
const propertySource = findPropertySource(target, propertyName) || target;
|
|
2333
|
-
const ownDescriptors = Reflect.getOwnPropertyDescriptor(
|
|
2334
|
-
|
|
2335
|
-
propertyName
|
|
2336
|
-
);
|
|
2337
|
-
if (typeof (ownDescriptors == null ? void 0 : ownDescriptors.set) !== "undefined") {
|
|
2209
|
+
const ownDescriptors = Reflect.getOwnPropertyDescriptor(propertySource, propertyName);
|
|
2210
|
+
if (typeof ownDescriptors?.set !== "undefined") {
|
|
2338
2211
|
ownDescriptors.set.apply(target, [nextValue]);
|
|
2339
2212
|
return true;
|
|
2340
2213
|
}
|
|
@@ -2345,65 +2218,52 @@ function optionsToProxyHandler(options) {
|
|
|
2345
2218
|
value: nextValue
|
|
2346
2219
|
});
|
|
2347
2220
|
};
|
|
2348
|
-
if (typeof setProperty !== "undefined")
|
|
2349
|
-
return setProperty.call(target, [propertyName, nextValue], next);
|
|
2350
|
-
}
|
|
2221
|
+
if (typeof setProperty !== "undefined") return setProperty.call(target, [propertyName, nextValue], next);
|
|
2351
2222
|
return next();
|
|
2352
2223
|
};
|
|
2353
2224
|
handler.get = function(target, propertyName, receiver) {
|
|
2354
2225
|
const next = () => target[propertyName];
|
|
2355
2226
|
const value = typeof getProperty !== "undefined" ? getProperty.call(target, [propertyName, receiver], next) : next();
|
|
2356
|
-
if (typeof value === "function") {
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
}
|
|
2362
|
-
return next2();
|
|
2363
|
-
};
|
|
2364
|
-
}
|
|
2227
|
+
if (typeof value === "function") return (...args) => {
|
|
2228
|
+
const next$1 = value.bind(target, ...args);
|
|
2229
|
+
if (typeof methodCall !== "undefined") return methodCall.call(target, [propertyName, args], next$1);
|
|
2230
|
+
return next$1();
|
|
2231
|
+
};
|
|
2365
2232
|
return value;
|
|
2366
2233
|
};
|
|
2367
2234
|
return handler;
|
|
2368
2235
|
}
|
|
2369
2236
|
function isDomParserSupportedType(type) {
|
|
2370
|
-
|
|
2237
|
+
return [
|
|
2371
2238
|
"application/xhtml+xml",
|
|
2372
2239
|
"application/xml",
|
|
2373
2240
|
"image/svg+xml",
|
|
2374
2241
|
"text/html",
|
|
2375
2242
|
"text/xml"
|
|
2376
|
-
]
|
|
2377
|
-
return supportedTypes.some((supportedType) => {
|
|
2243
|
+
].some((supportedType) => {
|
|
2378
2244
|
return type.startsWith(supportedType);
|
|
2379
2245
|
});
|
|
2380
2246
|
}
|
|
2381
2247
|
function parseJson(data) {
|
|
2382
2248
|
try {
|
|
2383
|
-
|
|
2384
|
-
return json;
|
|
2249
|
+
return JSON.parse(data);
|
|
2385
2250
|
} catch (_) {
|
|
2386
2251
|
return null;
|
|
2387
2252
|
}
|
|
2388
2253
|
}
|
|
2389
2254
|
function createResponse(request, body) {
|
|
2390
|
-
|
|
2391
|
-
return new FetchResponse(responseBodyOrNull, {
|
|
2255
|
+
return new FetchResponse(FetchResponse.isResponseWithBody(request.status) ? body : null, {
|
|
2392
2256
|
url: request.responseURL,
|
|
2393
2257
|
status: request.status,
|
|
2394
2258
|
statusText: request.statusText,
|
|
2395
|
-
headers: createHeadersFromXMLHttpRequestHeaders(
|
|
2396
|
-
request.getAllResponseHeaders()
|
|
2397
|
-
)
|
|
2259
|
+
headers: createHeadersFromXMLHttpRequestHeaders(request.getAllResponseHeaders())
|
|
2398
2260
|
});
|
|
2399
2261
|
}
|
|
2400
2262
|
function createHeadersFromXMLHttpRequestHeaders(headersString) {
|
|
2401
2263
|
const headers = new Headers();
|
|
2402
2264
|
const lines = headersString.split(/[\r\n]+/);
|
|
2403
2265
|
for (const line of lines) {
|
|
2404
|
-
if (line.trim() === "")
|
|
2405
|
-
continue;
|
|
2406
|
-
}
|
|
2266
|
+
if (line.trim() === "") continue;
|
|
2407
2267
|
const [name, ...parts] = line.split(": ");
|
|
2408
2268
|
const value = parts.join(": ");
|
|
2409
2269
|
headers.append(name, value);
|
|
@@ -2412,11 +2272,8 @@ function createHeadersFromXMLHttpRequestHeaders(headersString) {
|
|
|
2412
2272
|
}
|
|
2413
2273
|
async function getBodyByteLength(input) {
|
|
2414
2274
|
const explicitContentLength = input.headers.get("content-length");
|
|
2415
|
-
if (explicitContentLength != null && explicitContentLength !== "")
|
|
2416
|
-
|
|
2417
|
-
}
|
|
2418
|
-
const buffer = await input.arrayBuffer();
|
|
2419
|
-
return buffer.byteLength;
|
|
2275
|
+
if (explicitContentLength != null && explicitContentLength !== "") return Number(explicitContentLength);
|
|
2276
|
+
return (await input.arrayBuffer()).byteLength;
|
|
2420
2277
|
}
|
|
2421
2278
|
var kIsRequestHandled = Symbol("kIsRequestHandled");
|
|
2422
2279
|
var IS_NODE2 = isNodeProcess();
|
|
@@ -2437,15 +2294,12 @@ var XMLHttpRequestController = class {
|
|
|
2437
2294
|
setProperty: ([propertyName, nextValue], invoke) => {
|
|
2438
2295
|
switch (propertyName) {
|
|
2439
2296
|
case "ontimeout": {
|
|
2440
|
-
const eventName = propertyName.slice(
|
|
2441
|
-
2
|
|
2442
|
-
);
|
|
2297
|
+
const eventName = propertyName.slice(2);
|
|
2443
2298
|
this.request.addEventListener(eventName, nextValue);
|
|
2444
2299
|
return invoke();
|
|
2445
2300
|
}
|
|
2446
|
-
default:
|
|
2301
|
+
default:
|
|
2447
2302
|
return invoke();
|
|
2448
|
-
}
|
|
2449
2303
|
}
|
|
2450
2304
|
},
|
|
2451
2305
|
methodCall: ([methodName, args], invoke) => {
|
|
@@ -2482,10 +2336,10 @@ var XMLHttpRequestController = class {
|
|
|
2482
2336
|
const fetchResponse = createResponse(
|
|
2483
2337
|
this.request,
|
|
2484
2338
|
/**
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2339
|
+
* The `response` property is the right way to read
|
|
2340
|
+
* the ambiguous response body, as the request's "responseType" may differ.
|
|
2341
|
+
* @see https://xhr.spec.whatwg.org/#the-response-attribute
|
|
2342
|
+
*/
|
|
2489
2343
|
this.request.response
|
|
2490
2344
|
);
|
|
2491
2345
|
this.onResponse.call(this, {
|
|
@@ -2500,91 +2354,70 @@ var XMLHttpRequestController = class {
|
|
|
2500
2354
|
const fetchRequest = this.toFetchApiRequest(requestBody);
|
|
2501
2355
|
this[kFetchRequest] = fetchRequest.clone();
|
|
2502
2356
|
queueMicrotask(() => {
|
|
2503
|
-
|
|
2504
|
-
const onceRequestSettled = ((_a = this.onRequest) == null ? void 0 : _a.call(this, {
|
|
2357
|
+
(this.onRequest?.call(this, {
|
|
2505
2358
|
request: fetchRequest,
|
|
2506
2359
|
requestId: this.requestId
|
|
2507
|
-
})
|
|
2508
|
-
onceRequestSettled.finally(() => {
|
|
2360
|
+
}) || Promise.resolve()).finally(() => {
|
|
2509
2361
|
if (!this[kIsRequestHandled]) {
|
|
2510
|
-
this.logger.info(
|
|
2511
|
-
|
|
2512
|
-
this.request.readyState
|
|
2513
|
-
);
|
|
2514
|
-
if (IS_NODE2) {
|
|
2515
|
-
this.request.setRequestHeader(
|
|
2516
|
-
INTERNAL_REQUEST_ID_HEADER_NAME,
|
|
2517
|
-
this.requestId
|
|
2518
|
-
);
|
|
2519
|
-
}
|
|
2362
|
+
this.logger.info("request callback settled but request has not been handled (readystate %d), performing as-is...", this.request.readyState);
|
|
2363
|
+
if (IS_NODE2) this.request.setRequestHeader(INTERNAL_REQUEST_ID_HEADER_NAME, this.requestId);
|
|
2520
2364
|
return invoke();
|
|
2521
2365
|
}
|
|
2522
2366
|
});
|
|
2523
2367
|
});
|
|
2524
2368
|
break;
|
|
2525
2369
|
}
|
|
2526
|
-
default:
|
|
2370
|
+
default:
|
|
2527
2371
|
return invoke();
|
|
2528
|
-
}
|
|
2529
2372
|
}
|
|
2530
2373
|
}
|
|
2531
2374
|
});
|
|
2532
|
-
define(
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
case "onloadend": {
|
|
2545
|
-
const eventName = propertyName.slice(
|
|
2546
|
-
2
|
|
2547
|
-
);
|
|
2548
|
-
this.registerUploadEvent(eventName, nextValue);
|
|
2549
|
-
}
|
|
2375
|
+
define(this.request, "upload", createProxy(this.request.upload, {
|
|
2376
|
+
setProperty: ([propertyName, nextValue], invoke) => {
|
|
2377
|
+
switch (propertyName) {
|
|
2378
|
+
case "onloadstart":
|
|
2379
|
+
case "onprogress":
|
|
2380
|
+
case "onaboart":
|
|
2381
|
+
case "onerror":
|
|
2382
|
+
case "onload":
|
|
2383
|
+
case "ontimeout":
|
|
2384
|
+
case "onloadend": {
|
|
2385
|
+
const eventName = propertyName.slice(2);
|
|
2386
|
+
this.registerUploadEvent(eventName, nextValue);
|
|
2550
2387
|
}
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2388
|
+
}
|
|
2389
|
+
return invoke();
|
|
2390
|
+
},
|
|
2391
|
+
methodCall: ([methodName, args], invoke) => {
|
|
2392
|
+
switch (methodName) {
|
|
2393
|
+
case "addEventListener": {
|
|
2394
|
+
const [eventName, listener] = args;
|
|
2395
|
+
this.registerUploadEvent(eventName, listener);
|
|
2396
|
+
this.logger.info("upload.addEventListener", eventName, listener);
|
|
2397
|
+
return invoke();
|
|
2561
2398
|
}
|
|
2562
2399
|
}
|
|
2563
|
-
}
|
|
2564
|
-
);
|
|
2400
|
+
}
|
|
2401
|
+
}));
|
|
2565
2402
|
}
|
|
2566
2403
|
registerEvent(eventName, listener) {
|
|
2567
|
-
const
|
|
2568
|
-
const nextEvents = prevEvents.concat(listener);
|
|
2404
|
+
const nextEvents = (this.events.get(eventName) || []).concat(listener);
|
|
2569
2405
|
this.events.set(eventName, nextEvents);
|
|
2570
2406
|
this.logger.info('registered event "%s"', eventName, listener);
|
|
2571
2407
|
}
|
|
2572
2408
|
registerUploadEvent(eventName, listener) {
|
|
2573
|
-
const
|
|
2574
|
-
const nextEvents = prevEvents.concat(listener);
|
|
2409
|
+
const nextEvents = (this.uploadEvents.get(eventName) || []).concat(listener);
|
|
2575
2410
|
this.uploadEvents.set(eventName, nextEvents);
|
|
2576
2411
|
this.logger.info('registered upload event "%s"', eventName, listener);
|
|
2577
2412
|
}
|
|
2578
2413
|
/**
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2414
|
+
* Responds to the current request with the given
|
|
2415
|
+
* Fetch API `Response` instance.
|
|
2416
|
+
*/
|
|
2582
2417
|
async respondWith(response) {
|
|
2583
2418
|
this[kIsRequestHandled] = true;
|
|
2584
2419
|
if (this[kFetchRequest]) {
|
|
2585
|
-
const totalRequestBodyLength = await getBodyByteLength(
|
|
2586
|
-
this[kFetchRequest]
|
|
2587
|
-
);
|
|
2420
|
+
const totalRequestBodyLength = await getBodyByteLength(this[kFetchRequest]);
|
|
2588
2421
|
this.trigger("loadstart", this.request.upload, {
|
|
2589
2422
|
loaded: 0,
|
|
2590
2423
|
total: totalRequestBodyLength
|
|
@@ -2602,48 +2435,32 @@ var XMLHttpRequestController = class {
|
|
|
2602
2435
|
total: totalRequestBodyLength
|
|
2603
2436
|
});
|
|
2604
2437
|
}
|
|
2605
|
-
this.logger.info(
|
|
2606
|
-
"responding with a mocked response: %d %s",
|
|
2607
|
-
response.status,
|
|
2608
|
-
response.statusText
|
|
2609
|
-
);
|
|
2438
|
+
this.logger.info("responding with a mocked response: %d %s", response.status, response.statusText);
|
|
2610
2439
|
define(this.request, "status", response.status);
|
|
2611
2440
|
define(this.request, "statusText", response.statusText);
|
|
2612
2441
|
define(this.request, "responseURL", this.url.href);
|
|
2613
|
-
this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, {
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
return null;
|
|
2619
|
-
}
|
|
2620
|
-
const headerValue = response.headers.get(args[0]);
|
|
2621
|
-
this.logger.info(
|
|
2622
|
-
'resolved response header "%s" to',
|
|
2623
|
-
args[0],
|
|
2624
|
-
headerValue
|
|
2625
|
-
);
|
|
2626
|
-
return headerValue;
|
|
2442
|
+
this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, { apply: (_, __, args) => {
|
|
2443
|
+
this.logger.info("getResponseHeader", args[0]);
|
|
2444
|
+
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
|
2445
|
+
this.logger.info("headers not received yet, returning null");
|
|
2446
|
+
return null;
|
|
2627
2447
|
}
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
}
|
|
2638
|
-
const headersList = Array.from(response.headers.entries());
|
|
2639
|
-
const allHeaders = headersList.map(([headerName, headerValue]) => {
|
|
2640
|
-
return `${headerName}: ${headerValue}`;
|
|
2641
|
-
}).join("\r\n");
|
|
2642
|
-
this.logger.info("resolved all response headers to", allHeaders);
|
|
2643
|
-
return allHeaders;
|
|
2644
|
-
}
|
|
2448
|
+
const headerValue = response.headers.get(args[0]);
|
|
2449
|
+
this.logger.info('resolved response header "%s" to', args[0], headerValue);
|
|
2450
|
+
return headerValue;
|
|
2451
|
+
} });
|
|
2452
|
+
this.request.getAllResponseHeaders = new Proxy(this.request.getAllResponseHeaders, { apply: () => {
|
|
2453
|
+
this.logger.info("getAllResponseHeaders");
|
|
2454
|
+
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
|
2455
|
+
this.logger.info("headers not received yet, returning empty string");
|
|
2456
|
+
return "";
|
|
2645
2457
|
}
|
|
2646
|
-
|
|
2458
|
+
const allHeaders = Array.from(response.headers.entries()).map(([headerName, headerValue]) => {
|
|
2459
|
+
return `${headerName}: ${headerValue}`;
|
|
2460
|
+
}).join("\r\n");
|
|
2461
|
+
this.logger.info("resolved all response headers to", allHeaders);
|
|
2462
|
+
return allHeaders;
|
|
2463
|
+
} });
|
|
2647
2464
|
Object.defineProperties(this.request, {
|
|
2648
2465
|
response: {
|
|
2649
2466
|
enumerable: true,
|
|
@@ -2702,21 +2519,14 @@ var XMLHttpRequestController = class {
|
|
|
2702
2519
|
readNextResponseBodyChunk();
|
|
2703
2520
|
};
|
|
2704
2521
|
readNextResponseBodyChunk();
|
|
2705
|
-
} else
|
|
2706
|
-
finalizeResponse();
|
|
2707
|
-
}
|
|
2522
|
+
} else finalizeResponse();
|
|
2708
2523
|
}
|
|
2709
2524
|
responseBufferToText() {
|
|
2710
2525
|
return decodeBuffer(this.responseBuffer);
|
|
2711
2526
|
}
|
|
2712
2527
|
get response() {
|
|
2713
|
-
this.logger.info(
|
|
2714
|
-
|
|
2715
|
-
this.request.responseType
|
|
2716
|
-
);
|
|
2717
|
-
if (this.request.readyState !== this.request.DONE) {
|
|
2718
|
-
return null;
|
|
2719
|
-
}
|
|
2528
|
+
this.logger.info("getResponse (responseType: %s)", this.request.responseType);
|
|
2529
|
+
if (this.request.readyState !== this.request.DONE) return null;
|
|
2720
2530
|
switch (this.request.responseType) {
|
|
2721
2531
|
case "json": {
|
|
2722
2532
|
const responseJson = parseJson(this.responseBufferToText());
|
|
@@ -2730,60 +2540,33 @@ var XMLHttpRequestController = class {
|
|
|
2730
2540
|
}
|
|
2731
2541
|
case "blob": {
|
|
2732
2542
|
const mimeType = this.request.getResponseHeader("Content-Type") || "text/plain";
|
|
2733
|
-
const responseBlob = new Blob([this.responseBufferToText()], {
|
|
2734
|
-
|
|
2735
|
-
});
|
|
2736
|
-
this.logger.info(
|
|
2737
|
-
"resolved response Blob (mime type: %s)",
|
|
2738
|
-
responseBlob,
|
|
2739
|
-
mimeType
|
|
2740
|
-
);
|
|
2543
|
+
const responseBlob = new Blob([this.responseBufferToText()], { type: mimeType });
|
|
2544
|
+
this.logger.info("resolved response Blob (mime type: %s)", responseBlob, mimeType);
|
|
2741
2545
|
return responseBlob;
|
|
2742
2546
|
}
|
|
2743
2547
|
default: {
|
|
2744
2548
|
const responseText = this.responseBufferToText();
|
|
2745
|
-
this.logger.info(
|
|
2746
|
-
'resolving "%s" response type as text',
|
|
2747
|
-
this.request.responseType,
|
|
2748
|
-
responseText
|
|
2749
|
-
);
|
|
2549
|
+
this.logger.info('resolving "%s" response type as text', this.request.responseType, responseText);
|
|
2750
2550
|
return responseText;
|
|
2751
2551
|
}
|
|
2752
2552
|
}
|
|
2753
2553
|
}
|
|
2754
2554
|
get responseText() {
|
|
2755
|
-
invariant(
|
|
2756
|
-
|
|
2757
|
-
"InvalidStateError: The object is in invalid state."
|
|
2758
|
-
);
|
|
2759
|
-
if (this.request.readyState !== this.request.LOADING && this.request.readyState !== this.request.DONE) {
|
|
2760
|
-
return "";
|
|
2761
|
-
}
|
|
2555
|
+
invariant(this.request.responseType === "" || this.request.responseType === "text", "InvalidStateError: The object is in invalid state.");
|
|
2556
|
+
if (this.request.readyState !== this.request.LOADING && this.request.readyState !== this.request.DONE) return "";
|
|
2762
2557
|
const responseText = this.responseBufferToText();
|
|
2763
2558
|
this.logger.info('getResponseText: "%s"', responseText);
|
|
2764
2559
|
return responseText;
|
|
2765
2560
|
}
|
|
2766
2561
|
get responseXML() {
|
|
2767
|
-
invariant(
|
|
2768
|
-
|
|
2769
|
-
"InvalidStateError: The object is in invalid state."
|
|
2770
|
-
);
|
|
2771
|
-
if (this.request.readyState !== this.request.DONE) {
|
|
2772
|
-
return null;
|
|
2773
|
-
}
|
|
2562
|
+
invariant(this.request.responseType === "" || this.request.responseType === "document", "InvalidStateError: The object is in invalid state.");
|
|
2563
|
+
if (this.request.readyState !== this.request.DONE) return null;
|
|
2774
2564
|
const contentType = this.request.getResponseHeader("Content-Type") || "";
|
|
2775
2565
|
if (typeof DOMParser === "undefined") {
|
|
2776
|
-
console.warn(
|
|
2777
|
-
"Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly."
|
|
2778
|
-
);
|
|
2566
|
+
console.warn("Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly.");
|
|
2779
2567
|
return null;
|
|
2780
2568
|
}
|
|
2781
|
-
if (isDomParserSupportedType(contentType))
|
|
2782
|
-
return new DOMParser().parseFromString(
|
|
2783
|
-
this.responseBufferToText(),
|
|
2784
|
-
contentType
|
|
2785
|
-
);
|
|
2786
|
-
}
|
|
2569
|
+
if (isDomParserSupportedType(contentType)) return new DOMParser().parseFromString(this.responseBufferToText(), contentType);
|
|
2787
2570
|
return null;
|
|
2788
2571
|
}
|
|
2789
2572
|
errorWith(error2) {
|
|
@@ -2794,14 +2577,10 @@ var XMLHttpRequestController = class {
|
|
|
2794
2577
|
this.trigger("loadend", this.request);
|
|
2795
2578
|
}
|
|
2796
2579
|
/**
|
|
2797
|
-
|
|
2798
|
-
|
|
2580
|
+
* Transitions this request's `readyState` to the given one.
|
|
2581
|
+
*/
|
|
2799
2582
|
setReadyState(nextReadyState) {
|
|
2800
|
-
this.logger.info(
|
|
2801
|
-
"setReadyState: %d -> %d",
|
|
2802
|
-
this.request.readyState,
|
|
2803
|
-
nextReadyState
|
|
2804
|
-
);
|
|
2583
|
+
this.logger.info("setReadyState: %d -> %d", this.request.readyState, nextReadyState);
|
|
2805
2584
|
if (this.request.readyState === nextReadyState) {
|
|
2806
2585
|
this.logger.info("ready state identical, skipping transition...");
|
|
2807
2586
|
return;
|
|
@@ -2814,8 +2593,8 @@ var XMLHttpRequestController = class {
|
|
|
2814
2593
|
}
|
|
2815
2594
|
}
|
|
2816
2595
|
/**
|
|
2817
|
-
|
|
2818
|
-
|
|
2596
|
+
* Triggers given event on the `XMLHttpRequest` instance.
|
|
2597
|
+
*/
|
|
2819
2598
|
trigger(eventName, target, options) {
|
|
2820
2599
|
const callback = target[`on${eventName}`];
|
|
2821
2600
|
const event = createEvent(target, eventName, options);
|
|
@@ -2825,156 +2604,106 @@ var XMLHttpRequestController = class {
|
|
|
2825
2604
|
callback.call(target, event);
|
|
2826
2605
|
}
|
|
2827
2606
|
const events = target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events;
|
|
2828
|
-
for (const [registeredEventName, listeners] of events) {
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
'found %d listener(s) for "%s" event, calling...',
|
|
2832
|
-
listeners.length,
|
|
2833
|
-
eventName
|
|
2834
|
-
);
|
|
2835
|
-
listeners.forEach((listener) => listener.call(target, event));
|
|
2836
|
-
}
|
|
2607
|
+
for (const [registeredEventName, listeners] of events) if (registeredEventName === eventName) {
|
|
2608
|
+
this.logger.info('found %d listener(s) for "%s" event, calling...', listeners.length, eventName);
|
|
2609
|
+
listeners.forEach((listener) => listener.call(target, event));
|
|
2837
2610
|
}
|
|
2838
2611
|
}
|
|
2839
2612
|
/**
|
|
2840
|
-
|
|
2841
|
-
|
|
2613
|
+
* Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
|
|
2614
|
+
*/
|
|
2842
2615
|
toFetchApiRequest(body) {
|
|
2843
2616
|
this.logger.info("converting request to a Fetch API Request...");
|
|
2844
2617
|
const resolvedBody = body instanceof Document ? body.documentElement.innerText : body;
|
|
2845
2618
|
const fetchRequest = new Request(this.url.href, {
|
|
2846
2619
|
method: this.method,
|
|
2847
2620
|
headers: this.requestHeaders,
|
|
2848
|
-
/**
|
|
2849
|
-
* @see https://xhr.spec.whatwg.org/#cross-origin-credentials
|
|
2850
|
-
*/
|
|
2851
2621
|
credentials: this.request.withCredentials ? "include" : "same-origin",
|
|
2852
2622
|
body: ["GET", "HEAD"].includes(this.method.toUpperCase()) ? null : resolvedBody
|
|
2853
2623
|
});
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
`XMLHttpRequest: Cannot remove a "${headerName}" header from the Fetch API representation of the "${fetchRequest.method} ${fetchRequest.url}" request. XMLHttpRequest headers cannot be removed.`
|
|
2867
|
-
);
|
|
2868
|
-
break;
|
|
2869
|
-
}
|
|
2624
|
+
define(fetchRequest, "headers", createProxy(fetchRequest.headers, { methodCall: ([methodName, args], invoke) => {
|
|
2625
|
+
switch (methodName) {
|
|
2626
|
+
case "append":
|
|
2627
|
+
case "set": {
|
|
2628
|
+
const [headerName, headerValue] = args;
|
|
2629
|
+
this.request.setRequestHeader(headerName, headerValue);
|
|
2630
|
+
break;
|
|
2631
|
+
}
|
|
2632
|
+
case "delete": {
|
|
2633
|
+
const [headerName] = args;
|
|
2634
|
+
console.warn(`XMLHttpRequest: Cannot remove a "${headerName}" header from the Fetch API representation of the "${fetchRequest.method} ${fetchRequest.url}" request. XMLHttpRequest headers cannot be removed.`);
|
|
2635
|
+
break;
|
|
2870
2636
|
}
|
|
2871
|
-
return invoke();
|
|
2872
2637
|
}
|
|
2873
|
-
|
|
2874
|
-
|
|
2638
|
+
return invoke();
|
|
2639
|
+
} }));
|
|
2875
2640
|
setRawRequest(fetchRequest, this.request);
|
|
2876
2641
|
this.logger.info("converted request to a Fetch API Request!", fetchRequest);
|
|
2877
2642
|
return fetchRequest;
|
|
2878
2643
|
}
|
|
2879
2644
|
};
|
|
2880
2645
|
function toAbsoluteUrl(url) {
|
|
2881
|
-
if (typeof location === "undefined")
|
|
2882
|
-
return new URL(url);
|
|
2883
|
-
}
|
|
2646
|
+
if (typeof location === "undefined") return new URL(url);
|
|
2884
2647
|
return new URL(url.toString(), location.href);
|
|
2885
2648
|
}
|
|
2886
2649
|
function define(target, property, value) {
|
|
2887
2650
|
Reflect.defineProperty(target, property, {
|
|
2888
|
-
// Ensure writable properties to allow redefining readonly properties.
|
|
2889
2651
|
writable: true,
|
|
2890
2652
|
enumerable: true,
|
|
2891
2653
|
value
|
|
2892
2654
|
});
|
|
2893
2655
|
}
|
|
2894
|
-
function createXMLHttpRequestProxy({
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
Reflect.defineProperty(
|
|
2911
|
-
originalRequest,
|
|
2912
|
-
propertyName,
|
|
2913
|
-
prototypeDescriptors[propertyName]
|
|
2914
|
-
);
|
|
2915
|
-
}
|
|
2916
|
-
const xhrRequestController = new XMLHttpRequestController(
|
|
2917
|
-
originalRequest,
|
|
2918
|
-
logger
|
|
2919
|
-
);
|
|
2920
|
-
xhrRequestController.onRequest = async function({ request, requestId }) {
|
|
2921
|
-
const controller = new RequestController(request, {
|
|
2922
|
-
passthrough: () => {
|
|
2923
|
-
this.logger.info(
|
|
2924
|
-
"no mocked response received, performing request as-is..."
|
|
2925
|
-
);
|
|
2926
|
-
},
|
|
2927
|
-
respondWith: async (response) => {
|
|
2928
|
-
if (isResponseError(response)) {
|
|
2929
|
-
this.errorWith(new TypeError("Network error"));
|
|
2930
|
-
return;
|
|
2931
|
-
}
|
|
2932
|
-
await this.respondWith(response);
|
|
2933
|
-
},
|
|
2934
|
-
errorWith: (reason) => {
|
|
2935
|
-
this.logger.info("request errored!", { error: reason });
|
|
2936
|
-
if (reason instanceof Error) {
|
|
2937
|
-
this.errorWith(reason);
|
|
2938
|
-
}
|
|
2656
|
+
function createXMLHttpRequestProxy({ emitter, logger }) {
|
|
2657
|
+
return new Proxy(globalThis.XMLHttpRequest, { construct(target, args, newTarget) {
|
|
2658
|
+
logger.info("constructed new XMLHttpRequest");
|
|
2659
|
+
const originalRequest = Reflect.construct(target, args, newTarget);
|
|
2660
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(target.prototype);
|
|
2661
|
+
for (const propertyName in prototypeDescriptors) Reflect.defineProperty(originalRequest, propertyName, prototypeDescriptors[propertyName]);
|
|
2662
|
+
const xhrRequestController = new XMLHttpRequestController(originalRequest, logger);
|
|
2663
|
+
xhrRequestController.onRequest = async function({ request, requestId }) {
|
|
2664
|
+
const controller = new RequestController(request, {
|
|
2665
|
+
passthrough: () => {
|
|
2666
|
+
this.logger.info("no mocked response received, performing request as-is...");
|
|
2667
|
+
},
|
|
2668
|
+
respondWith: async (response) => {
|
|
2669
|
+
if (isResponseError(response)) {
|
|
2670
|
+
this.errorWith(/* @__PURE__ */ new TypeError("Network error"));
|
|
2671
|
+
return;
|
|
2939
2672
|
}
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2673
|
+
await this.respondWith(response);
|
|
2674
|
+
},
|
|
2675
|
+
errorWith: (reason) => {
|
|
2676
|
+
this.logger.info("request errored!", { error: reason });
|
|
2677
|
+
if (reason instanceof Error) this.errorWith(reason);
|
|
2678
|
+
}
|
|
2679
|
+
});
|
|
2680
|
+
this.logger.info("awaiting mocked response...");
|
|
2681
|
+
this.logger.info('emitting the "request" event for %s listener(s)...', emitter.listenerCount("request"));
|
|
2682
|
+
await handleRequest2({
|
|
2683
|
+
request,
|
|
2684
|
+
requestId,
|
|
2685
|
+
controller,
|
|
2686
|
+
emitter
|
|
2687
|
+
});
|
|
2688
|
+
};
|
|
2689
|
+
xhrRequestController.onResponse = async function({ response, isMockedResponse, request, requestId }) {
|
|
2690
|
+
this.logger.info('emitting the "response" event for %s listener(s)...', emitter.listenerCount("response"));
|
|
2691
|
+
emitter.emit("response", {
|
|
2954
2692
|
response,
|
|
2955
2693
|
isMockedResponse,
|
|
2956
2694
|
request,
|
|
2957
2695
|
requestId
|
|
2958
|
-
})
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
);
|
|
2963
|
-
emitter.emit("response", {
|
|
2964
|
-
response,
|
|
2965
|
-
isMockedResponse,
|
|
2966
|
-
request,
|
|
2967
|
-
requestId
|
|
2968
|
-
});
|
|
2969
|
-
};
|
|
2970
|
-
return xhrRequestController.request;
|
|
2971
|
-
}
|
|
2972
|
-
});
|
|
2973
|
-
return XMLHttpRequestProxy;
|
|
2696
|
+
});
|
|
2697
|
+
};
|
|
2698
|
+
return xhrRequestController.request;
|
|
2699
|
+
} });
|
|
2974
2700
|
}
|
|
2975
|
-
var
|
|
2701
|
+
var XMLHttpRequestInterceptor = class XMLHttpRequestInterceptor2 extends Interceptor {
|
|
2702
|
+
static {
|
|
2703
|
+
this.interceptorSymbol = Symbol("xhr");
|
|
2704
|
+
}
|
|
2976
2705
|
constructor() {
|
|
2977
|
-
super(
|
|
2706
|
+
super(XMLHttpRequestInterceptor2.interceptorSymbol);
|
|
2978
2707
|
}
|
|
2979
2708
|
checkEnvironment() {
|
|
2980
2709
|
return hasConfigurableGlobal("XMLHttpRequest");
|
|
@@ -2983,37 +2712,24 @@ var _XMLHttpRequestInterceptor = class extends Interceptor {
|
|
|
2983
2712
|
const logger = this.logger.extend("setup");
|
|
2984
2713
|
logger.info('patching "XMLHttpRequest" module...');
|
|
2985
2714
|
const PureXMLHttpRequest = globalThis.XMLHttpRequest;
|
|
2986
|
-
invariant(
|
|
2987
|
-
!PureXMLHttpRequest[IS_PATCHED_MODULE],
|
|
2988
|
-
'Failed to patch the "XMLHttpRequest" module: already patched.'
|
|
2989
|
-
);
|
|
2715
|
+
invariant(!PureXMLHttpRequest[IS_PATCHED_MODULE], 'Failed to patch the "XMLHttpRequest" module: already patched.');
|
|
2990
2716
|
globalThis.XMLHttpRequest = createXMLHttpRequestProxy({
|
|
2991
2717
|
emitter: this.emitter,
|
|
2992
2718
|
logger: this.logger
|
|
2993
2719
|
});
|
|
2994
|
-
logger.info(
|
|
2995
|
-
'native "XMLHttpRequest" module patched!',
|
|
2996
|
-
globalThis.XMLHttpRequest.name
|
|
2997
|
-
);
|
|
2720
|
+
logger.info('native "XMLHttpRequest" module patched!', globalThis.XMLHttpRequest.name);
|
|
2998
2721
|
Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, {
|
|
2999
2722
|
enumerable: true,
|
|
3000
2723
|
configurable: true,
|
|
3001
2724
|
value: true
|
|
3002
2725
|
});
|
|
3003
2726
|
this.subscriptions.push(() => {
|
|
3004
|
-
Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, {
|
|
3005
|
-
value: void 0
|
|
3006
|
-
});
|
|
2727
|
+
Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, { value: void 0 });
|
|
3007
2728
|
globalThis.XMLHttpRequest = PureXMLHttpRequest;
|
|
3008
|
-
logger.info(
|
|
3009
|
-
'native "XMLHttpRequest" module restored!',
|
|
3010
|
-
globalThis.XMLHttpRequest.name
|
|
3011
|
-
);
|
|
2729
|
+
logger.info('native "XMLHttpRequest" module restored!', globalThis.XMLHttpRequest.name);
|
|
3012
2730
|
});
|
|
3013
2731
|
}
|
|
3014
2732
|
};
|
|
3015
|
-
var XMLHttpRequestInterceptor = _XMLHttpRequestInterceptor;
|
|
3016
|
-
XMLHttpRequestInterceptor.interceptorSymbol = Symbol("xhr");
|
|
3017
2733
|
|
|
3018
2734
|
// src/browser/setupWorker/start/createFallbackRequestListener.ts
|
|
3019
2735
|
var import_handleRequest2 = require("../core/utils/handleRequest");
|