@mswjs/interceptors 0.22.4 → 0.22.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/browser/{Interceptor-959f650e.d.ts → Interceptor-c794917d.d.ts} +2 -2
- package/lib/browser/{chunk-IIY3SHU3.js → chunk-2EIH6L6D.js} +25 -25
- package/lib/browser/{chunk-BQYA7ER5.mjs → chunk-2GVXYEMC.mjs} +5 -5
- package/lib/browser/chunk-2Z7B3HL5.js +106 -0
- package/lib/browser/{chunk-5B525MKF.mjs → chunk-65HGG3CV.mjs} +1 -1
- package/lib/browser/chunk-BVV2ZW34.js +675 -0
- package/lib/browser/chunk-GL6Y4E24.mjs +106 -0
- package/lib/browser/{chunk-QWL3EOEY.js → chunk-OK5YCL7L.js} +7 -7
- package/lib/browser/{chunk-ZJOF5MEZ.js → chunk-PCFJD76X.js} +11 -11
- package/lib/browser/chunk-PGR64QLT.mjs +675 -0
- package/lib/browser/{chunk-STA6QBYM.mjs → chunk-RT3ATOJH.mjs} +11 -11
- package/lib/browser/index.d.ts +6 -6
- package/lib/browser/index.js +4 -4
- package/lib/browser/index.mjs +2 -2
- package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +3 -3
- package/lib/browser/interceptors/XMLHttpRequest/index.js +5 -677
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +5 -677
- package/lib/browser/interceptors/fetch/index.d.ts +2 -2
- package/lib/browser/interceptors/fetch/index.js +4 -101
- package/lib/browser/interceptors/fetch/index.mjs +4 -101
- package/lib/browser/presets/browser.d.ts +13 -0
- package/lib/browser/presets/browser.js +18 -0
- package/lib/browser/presets/browser.mjs +18 -0
- package/lib/node/{BatchInterceptor-a7261b26.d.ts → BatchInterceptor-5c1e5de3.d.ts} +5 -5
- package/lib/node/{Interceptor-997045eb.d.ts → Interceptor-b3a4098c.d.ts} +2 -2
- package/lib/node/RemoteHttpInterceptor.d.ts +3 -3
- package/lib/node/RemoteHttpInterceptor.js +9 -9
- package/lib/node/RemoteHttpInterceptor.mjs +5 -5
- package/lib/node/{chunk-FGPCRIW6.mjs → chunk-53LM4S3X.mjs} +59 -62
- package/lib/node/{chunk-WWHITCCI.js → chunk-62KFIM4W.js} +9 -8
- package/lib/node/{chunk-37CATPNG.mjs → chunk-6CRMKMDL.mjs} +6 -5
- package/lib/node/{chunk-XLZJAPVS.js → chunk-D7MOETL2.js} +59 -62
- package/lib/node/{chunk-RVLLS44W.js → chunk-F7BBA6FT.js} +9 -16
- package/lib/node/{chunk-KZEQH4YW.mjs → chunk-IC6Y7RGW.mjs} +1 -1
- package/lib/node/{chunk-SNNL2EXF.js → chunk-MUUQLKVJ.js} +3 -3
- package/lib/node/{chunk-G6ZTHYZQ.mjs → chunk-RFVEKRYP.mjs} +1 -1
- package/lib/node/{chunk-Q56TMOP5.js → chunk-SFLY7F52.js} +2 -2
- package/lib/node/{chunk-P7NKDCFD.mjs → chunk-X3TLFWGD.mjs} +5 -12
- package/lib/node/index.d.ts +3 -3
- package/lib/node/index.js +4 -4
- package/lib/node/index.mjs +3 -3
- package/lib/node/interceptors/ClientRequest/index.d.ts +3 -3
- package/lib/node/interceptors/ClientRequest/index.js +3 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +2 -2
- package/lib/node/interceptors/XMLHttpRequest/index.d.ts +3 -3
- package/lib/node/interceptors/XMLHttpRequest/index.js +4 -4
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +3 -3
- package/lib/node/interceptors/fetch/index.d.ts +2 -2
- package/lib/node/interceptors/fetch/index.js +2 -2
- package/lib/node/interceptors/fetch/index.mjs +1 -1
- package/lib/node/presets/node.d.ts +15 -0
- package/lib/node/presets/node.js +19 -0
- package/lib/node/presets/node.mjs +19 -0
- package/package.json +16 -1
- package/src/BatchInterceptor.ts +5 -5
- package/src/Interceptor.ts +2 -2
- package/src/interceptors/ClientRequest/NodeClientRequest.test.ts +1 -1
- package/src/interceptors/ClientRequest/http.request.ts +1 -1
- package/src/interceptors/ClientRequest/index.ts +2 -2
- package/src/interceptors/ClientRequest/utils/createRequest.test.ts +1 -1
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts +1 -1
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +1 -1
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.ts +5 -3
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.ts +1 -1
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +2 -8
- package/src/interceptors/XMLHttpRequest/index.ts +2 -2
- package/src/presets/browser.ts +4 -1
- package/src/presets/node.ts +4 -1
- package/src/utils/AsyncEventEmitter.ts +1 -1
- package/src/utils/cloneObject.ts +8 -6
- package/src/utils/debug.ts +4 -0
- package/src/utils/getUrlByRequestOptions.ts +13 -12
package/README.md
CHANGED
|
@@ -168,7 +168,7 @@ This preset combines `ClientRequestInterceptor`, `XMLHttpRequestInterceptor` and
|
|
|
168
168
|
|
|
169
169
|
```js
|
|
170
170
|
import { BatchInterceptor } from '@mswjs/interceptors'
|
|
171
|
-
import nodeInterceptors from '@mswjs/interceptors/
|
|
171
|
+
import nodeInterceptors from '@mswjs/interceptors/presets/node'
|
|
172
172
|
|
|
173
173
|
const interceptor = new BatchInterceptor({
|
|
174
174
|
name: 'my-interceptor',
|
|
@@ -186,7 +186,7 @@ This preset combines `XMLHttpRequestInterceptor` and `FetchInterceptor` and is m
|
|
|
186
186
|
|
|
187
187
|
```js
|
|
188
188
|
import { BatchInterceptor } from '@mswjs/interceptors'
|
|
189
|
-
import browserInterceptors from '@mswjs/interceptors/
|
|
189
|
+
import browserInterceptors from '@mswjs/interceptors/presets/browser'
|
|
190
190
|
|
|
191
191
|
const interceptor = new BatchInterceptor({
|
|
192
192
|
name: 'my-interceptor',
|
|
@@ -303,7 +303,7 @@ Applies multiple request interceptors at the same time.
|
|
|
303
303
|
|
|
304
304
|
```js
|
|
305
305
|
import { BatchInterceptor } from '@mswjs/interceptors'
|
|
306
|
-
import nodeInterceptors from '@mswjs/interceptors/
|
|
306
|
+
import nodeInterceptors from '@mswjs/interceptors/presets/node'
|
|
307
307
|
|
|
308
308
|
const interceptor = new BatchInterceptor({
|
|
309
309
|
name: 'my-interceptor',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Debugger } from 'debug';
|
|
2
1
|
import { EventMap, Emitter, Listener } from 'strict-event-emitter';
|
|
2
|
+
import { Debugger } from 'debug';
|
|
3
3
|
|
|
4
4
|
type AnyFunction = (...args: any[]) => any;
|
|
5
5
|
type LazyCallbackReturnType<FnType extends AnyFunction> = Parameters<FnType> | [];
|
|
@@ -71,7 +71,7 @@ declare class Interceptor<Events extends InterceptorEventMap> {
|
|
|
71
71
|
protected subscriptions: Array<InterceptorSubscription>;
|
|
72
72
|
protected log: Debugger;
|
|
73
73
|
readyState: InterceptorReadyState;
|
|
74
|
-
constructor(symbol:
|
|
74
|
+
constructor(symbol: symbol);
|
|
75
75
|
/**
|
|
76
76
|
* Determine if this interceptor can be applied
|
|
77
77
|
* in the current environment.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkOK5YCL7Ljs = require('./chunk-OK5YCL7L.js');
|
|
4
4
|
|
|
5
5
|
// node_modules/has-symbols/shams.js
|
|
6
|
-
var require_shams =
|
|
6
|
+
var require_shams = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
7
7
|
"node_modules/has-symbols/shams.js"(exports, module) {
|
|
8
8
|
"use strict";
|
|
9
9
|
module.exports = function hasSymbols() {
|
|
@@ -55,7 +55,7 @@ var require_shams = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
// node_modules/has-tostringtag/shams.js
|
|
58
|
-
var require_shams2 =
|
|
58
|
+
var require_shams2 = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
59
59
|
"node_modules/has-tostringtag/shams.js"(exports, module) {
|
|
60
60
|
"use strict";
|
|
61
61
|
var hasSymbols = require_shams();
|
|
@@ -66,7 +66,7 @@ var require_shams2 = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
// node_modules/call-bind/node_modules/has-symbols/shams.js
|
|
69
|
-
var require_shams3 =
|
|
69
|
+
var require_shams3 = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
70
70
|
"node_modules/call-bind/node_modules/has-symbols/shams.js"(exports, module) {
|
|
71
71
|
"use strict";
|
|
72
72
|
module.exports = function hasSymbols() {
|
|
@@ -118,7 +118,7 @@ var require_shams3 = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
// node_modules/call-bind/node_modules/has-symbols/index.js
|
|
121
|
-
var require_has_symbols =
|
|
121
|
+
var require_has_symbols = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
122
122
|
"node_modules/call-bind/node_modules/has-symbols/index.js"(exports, module) {
|
|
123
123
|
"use strict";
|
|
124
124
|
var origSymbol = typeof Symbol !== "undefined" && Symbol;
|
|
@@ -142,7 +142,7 @@ var require_has_symbols = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
142
142
|
});
|
|
143
143
|
|
|
144
144
|
// node_modules/function-bind/implementation.js
|
|
145
|
-
var require_implementation =
|
|
145
|
+
var require_implementation = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
146
146
|
"node_modules/function-bind/implementation.js"(exports, module) {
|
|
147
147
|
"use strict";
|
|
148
148
|
var ERROR_MESSAGE = "Function.prototype.bind called on incompatible ";
|
|
@@ -192,7 +192,7 @@ var require_implementation = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
192
192
|
});
|
|
193
193
|
|
|
194
194
|
// node_modules/function-bind/index.js
|
|
195
|
-
var require_function_bind =
|
|
195
|
+
var require_function_bind = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
196
196
|
"node_modules/function-bind/index.js"(exports, module) {
|
|
197
197
|
"use strict";
|
|
198
198
|
var implementation = require_implementation();
|
|
@@ -201,7 +201,7 @@ var require_function_bind = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
201
201
|
});
|
|
202
202
|
|
|
203
203
|
// node_modules/has/src/index.js
|
|
204
|
-
var require_src =
|
|
204
|
+
var require_src = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
205
205
|
"node_modules/has/src/index.js"(exports, module) {
|
|
206
206
|
"use strict";
|
|
207
207
|
var bind = require_function_bind();
|
|
@@ -210,7 +210,7 @@ var require_src = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
210
210
|
});
|
|
211
211
|
|
|
212
212
|
// node_modules/call-bind/node_modules/get-intrinsic/index.js
|
|
213
|
-
var require_get_intrinsic =
|
|
213
|
+
var require_get_intrinsic = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
214
214
|
"node_modules/call-bind/node_modules/get-intrinsic/index.js"(exports, module) {
|
|
215
215
|
"use strict";
|
|
216
216
|
var undefined2;
|
|
@@ -500,7 +500,7 @@ var require_get_intrinsic = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
500
500
|
});
|
|
501
501
|
|
|
502
502
|
// node_modules/call-bind/index.js
|
|
503
|
-
var require_call_bind =
|
|
503
|
+
var require_call_bind = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
504
504
|
"node_modules/call-bind/index.js"(exports, module) {
|
|
505
505
|
"use strict";
|
|
506
506
|
var bind = require_function_bind();
|
|
@@ -544,7 +544,7 @@ var require_call_bind = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
544
544
|
});
|
|
545
545
|
|
|
546
546
|
// node_modules/call-bind/callBound.js
|
|
547
|
-
var require_callBound =
|
|
547
|
+
var require_callBound = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
548
548
|
"node_modules/call-bind/callBound.js"(exports, module) {
|
|
549
549
|
"use strict";
|
|
550
550
|
var GetIntrinsic = require_get_intrinsic();
|
|
@@ -561,7 +561,7 @@ var require_callBound = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
561
561
|
});
|
|
562
562
|
|
|
563
563
|
// node_modules/is-arguments/index.js
|
|
564
|
-
var require_is_arguments =
|
|
564
|
+
var require_is_arguments = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
565
565
|
"node_modules/is-arguments/index.js"(exports, module) {
|
|
566
566
|
"use strict";
|
|
567
567
|
var hasToStringTag = require_shams2()();
|
|
@@ -588,7 +588,7 @@ var require_is_arguments = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
588
588
|
});
|
|
589
589
|
|
|
590
590
|
// node_modules/is-generator-function/index.js
|
|
591
|
-
var require_is_generator_function =
|
|
591
|
+
var require_is_generator_function = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
592
592
|
"node_modules/is-generator-function/index.js"(exports, module) {
|
|
593
593
|
"use strict";
|
|
594
594
|
var toStr = Object.prototype.toString;
|
|
@@ -630,7 +630,7 @@ var require_is_generator_function = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
630
630
|
});
|
|
631
631
|
|
|
632
632
|
// node_modules/is-callable/index.js
|
|
633
|
-
var require_is_callable =
|
|
633
|
+
var require_is_callable = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
634
634
|
"node_modules/is-callable/index.js"(exports, module) {
|
|
635
635
|
"use strict";
|
|
636
636
|
var fnToStr = Function.prototype.toString;
|
|
@@ -728,7 +728,7 @@ var require_is_callable = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
728
728
|
});
|
|
729
729
|
|
|
730
730
|
// node_modules/for-each/index.js
|
|
731
|
-
var require_for_each =
|
|
731
|
+
var require_for_each = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
732
732
|
"node_modules/for-each/index.js"(exports, module) {
|
|
733
733
|
"use strict";
|
|
734
734
|
var isCallable = require_is_callable();
|
|
@@ -786,7 +786,7 @@ var require_for_each = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
786
786
|
});
|
|
787
787
|
|
|
788
788
|
// node_modules/available-typed-arrays/index.js
|
|
789
|
-
var require_available_typed_arrays =
|
|
789
|
+
var require_available_typed_arrays = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
790
790
|
"node_modules/available-typed-arrays/index.js"(exports, module) {
|
|
791
791
|
"use strict";
|
|
792
792
|
var possibleNames = [
|
|
@@ -816,7 +816,7 @@ var require_available_typed_arrays = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
816
816
|
});
|
|
817
817
|
|
|
818
818
|
// node_modules/has-symbols/index.js
|
|
819
|
-
var require_has_symbols2 =
|
|
819
|
+
var require_has_symbols2 = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
820
820
|
"node_modules/has-symbols/index.js"(exports, module) {
|
|
821
821
|
"use strict";
|
|
822
822
|
var origSymbol = typeof Symbol !== "undefined" && Symbol;
|
|
@@ -840,7 +840,7 @@ var require_has_symbols2 = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
840
840
|
});
|
|
841
841
|
|
|
842
842
|
// node_modules/get-intrinsic/index.js
|
|
843
|
-
var require_get_intrinsic2 =
|
|
843
|
+
var require_get_intrinsic2 = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
844
844
|
"node_modules/get-intrinsic/index.js"(exports, module) {
|
|
845
845
|
"use strict";
|
|
846
846
|
var undefined2;
|
|
@@ -1134,7 +1134,7 @@ var require_get_intrinsic2 = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
1134
1134
|
});
|
|
1135
1135
|
|
|
1136
1136
|
// node_modules/es-abstract/helpers/getOwnPropertyDescriptor.js
|
|
1137
|
-
var require_getOwnPropertyDescriptor =
|
|
1137
|
+
var require_getOwnPropertyDescriptor = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
1138
1138
|
"node_modules/es-abstract/helpers/getOwnPropertyDescriptor.js"(exports, module) {
|
|
1139
1139
|
"use strict";
|
|
1140
1140
|
var GetIntrinsic = require_get_intrinsic2();
|
|
@@ -1151,7 +1151,7 @@ var require_getOwnPropertyDescriptor = _chunkQWL3EOEYjs.__commonJS.call(void 0,
|
|
|
1151
1151
|
});
|
|
1152
1152
|
|
|
1153
1153
|
// node_modules/is-typed-array/index.js
|
|
1154
|
-
var require_is_typed_array =
|
|
1154
|
+
var require_is_typed_array = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
1155
1155
|
"node_modules/is-typed-array/index.js"(exports, module) {
|
|
1156
1156
|
"use strict";
|
|
1157
1157
|
var forEach = require_for_each();
|
|
@@ -1216,7 +1216,7 @@ var require_is_typed_array = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
1216
1216
|
});
|
|
1217
1217
|
|
|
1218
1218
|
// node_modules/which-typed-array/index.js
|
|
1219
|
-
var require_which_typed_array =
|
|
1219
|
+
var require_which_typed_array = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
1220
1220
|
"node_modules/which-typed-array/index.js"(exports, module) {
|
|
1221
1221
|
"use strict";
|
|
1222
1222
|
var forEach = require_for_each();
|
|
@@ -1275,7 +1275,7 @@ var require_which_typed_array = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
1275
1275
|
});
|
|
1276
1276
|
|
|
1277
1277
|
// node_modules/util/support/types.js
|
|
1278
|
-
var require_types =
|
|
1278
|
+
var require_types = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
1279
1279
|
"node_modules/util/support/types.js"(exports) {
|
|
1280
1280
|
"use strict";
|
|
1281
1281
|
var isArgumentsObject = require_is_arguments();
|
|
@@ -1505,7 +1505,7 @@ var require_types = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
1505
1505
|
});
|
|
1506
1506
|
|
|
1507
1507
|
// node_modules/util/support/isBufferBrowser.js
|
|
1508
|
-
var require_isBufferBrowser =
|
|
1508
|
+
var require_isBufferBrowser = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
1509
1509
|
"node_modules/util/support/isBufferBrowser.js"(exports, module) {
|
|
1510
1510
|
module.exports = function isBuffer(arg) {
|
|
1511
1511
|
return arg && typeof arg === "object" && typeof arg.copy === "function" && typeof arg.fill === "function" && typeof arg.readUInt8 === "function";
|
|
@@ -1514,7 +1514,7 @@ var require_isBufferBrowser = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
1514
1514
|
});
|
|
1515
1515
|
|
|
1516
1516
|
// node_modules/inherits/inherits_browser.js
|
|
1517
|
-
var require_inherits_browser =
|
|
1517
|
+
var require_inherits_browser = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
1518
1518
|
"node_modules/inherits/inherits_browser.js"(exports, module) {
|
|
1519
1519
|
if (typeof Object.create === "function") {
|
|
1520
1520
|
module.exports = function inherits(ctor, superCtor) {
|
|
@@ -1546,7 +1546,7 @@ var require_inherits_browser = _chunkQWL3EOEYjs.__commonJS.call(void 0, {
|
|
|
1546
1546
|
});
|
|
1547
1547
|
|
|
1548
1548
|
// node_modules/util/util.js
|
|
1549
|
-
var require_util =
|
|
1549
|
+
var require_util = _chunkOK5YCL7Ljs.__commonJS.call(void 0, {
|
|
1550
1550
|
"node_modules/util/util.js"(exports) {
|
|
1551
1551
|
var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function getOwnPropertyDescriptors2(obj) {
|
|
1552
1552
|
var keys = Object.keys(obj);
|
|
@@ -6,11 +6,7 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
6
6
|
// src/glossary.ts
|
|
7
7
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
8
8
|
|
|
9
|
-
// src/Interceptor.ts
|
|
10
|
-
import { debug as debug2 } from "debug";
|
|
11
|
-
|
|
12
9
|
// src/utils/AsyncEventEmitter.ts
|
|
13
|
-
import { debug } from "debug";
|
|
14
10
|
import { Emitter } from "strict-event-emitter";
|
|
15
11
|
|
|
16
12
|
// src/utils/nextTick.ts
|
|
@@ -18,6 +14,10 @@ function nextTick(callback) {
|
|
|
18
14
|
setTimeout(callback, 0);
|
|
19
15
|
}
|
|
20
16
|
|
|
17
|
+
// src/utils/debug.ts
|
|
18
|
+
import debugCjsImport from "debug";
|
|
19
|
+
var debug = debugCjsImport;
|
|
20
|
+
|
|
21
21
|
// src/utils/AsyncEventEmitter.ts
|
|
22
22
|
var AsyncEventEmitter = class extends Emitter {
|
|
23
23
|
constructor() {
|
|
@@ -148,7 +148,7 @@ var Interceptor = class {
|
|
|
148
148
|
this.readyState = "INACTIVE" /* INACTIVE */;
|
|
149
149
|
this.emitter = new AsyncEventEmitter();
|
|
150
150
|
this.subscriptions = [];
|
|
151
|
-
this.log =
|
|
151
|
+
this.log = debug(symbol.description);
|
|
152
152
|
this.emitter.setMaxListeners(0);
|
|
153
153
|
this.log("constructing the interceptor...");
|
|
154
154
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkPCFJD76Xjs = require('./chunk-PCFJD76X.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkOK5YCL7Ljs = require('./chunk-OK5YCL7L.js');
|
|
9
|
+
|
|
10
|
+
// src/interceptors/fetch/index.ts
|
|
11
|
+
var _outvariant = require('outvariant');
|
|
12
|
+
var _until = require('@open-draft/until');
|
|
13
|
+
var _FetchInterceptor = class extends _chunkOK5YCL7Ljs.Interceptor {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(_FetchInterceptor.symbol);
|
|
16
|
+
}
|
|
17
|
+
checkEnvironment() {
|
|
18
|
+
return typeof globalThis !== "undefined" && typeof globalThis.fetch !== "undefined";
|
|
19
|
+
}
|
|
20
|
+
setup() {
|
|
21
|
+
const pureFetch = globalThis.fetch;
|
|
22
|
+
_outvariant.invariant.call(void 0,
|
|
23
|
+
!pureFetch[_chunkOK5YCL7Ljs.IS_PATCHED_MODULE],
|
|
24
|
+
'Failed to patch the "fetch" module: already patched.'
|
|
25
|
+
);
|
|
26
|
+
globalThis.fetch = async (input, init) => {
|
|
27
|
+
const requestId = _chunkPCFJD76Xjs.uuidv4.call(void 0, );
|
|
28
|
+
const request = new Request(input, init);
|
|
29
|
+
this.log("[%s] %s", request.method, request.url);
|
|
30
|
+
const interactiveRequest = _chunkPCFJD76Xjs.toInteractiveRequest.call(void 0, request);
|
|
31
|
+
this.log(
|
|
32
|
+
'emitting the "request" event for %d listener(s)...',
|
|
33
|
+
this.emitter.listenerCount("request")
|
|
34
|
+
);
|
|
35
|
+
this.emitter.emit("request", interactiveRequest, requestId);
|
|
36
|
+
this.log("awaiting for the mocked response...");
|
|
37
|
+
const [middlewareException, mockedResponse] = await _until.until.call(void 0, async () => {
|
|
38
|
+
await this.emitter.untilIdle(
|
|
39
|
+
"request",
|
|
40
|
+
({ args: [, pendingRequestId] }) => {
|
|
41
|
+
return pendingRequestId === requestId;
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
this.log("all request listeners have been resolved!");
|
|
45
|
+
const [mockedResponse2] = await interactiveRequest.respondWith.invoked();
|
|
46
|
+
this.log("event.respondWith called with:", mockedResponse2);
|
|
47
|
+
return mockedResponse2;
|
|
48
|
+
});
|
|
49
|
+
if (middlewareException) {
|
|
50
|
+
console.error(`${request.method} ${request.url} net::ERR_FAILED`);
|
|
51
|
+
const error = Object.assign(new TypeError("Failed to fetch"), {
|
|
52
|
+
cause: middlewareException
|
|
53
|
+
});
|
|
54
|
+
return Promise.reject(error);
|
|
55
|
+
}
|
|
56
|
+
if (mockedResponse) {
|
|
57
|
+
this.log("received mocked response:", mockedResponse);
|
|
58
|
+
const responseCloine = mockedResponse.clone();
|
|
59
|
+
this.emitter.emit(
|
|
60
|
+
"response",
|
|
61
|
+
responseCloine,
|
|
62
|
+
interactiveRequest,
|
|
63
|
+
requestId
|
|
64
|
+
);
|
|
65
|
+
const response = new Response(mockedResponse.body, mockedResponse);
|
|
66
|
+
Object.defineProperty(response, "url", {
|
|
67
|
+
writable: false,
|
|
68
|
+
enumerable: true,
|
|
69
|
+
configurable: false,
|
|
70
|
+
value: request.url
|
|
71
|
+
});
|
|
72
|
+
return response;
|
|
73
|
+
}
|
|
74
|
+
this.log("no mocked response received!");
|
|
75
|
+
return pureFetch(request).then((response) => {
|
|
76
|
+
const responseClone = response.clone();
|
|
77
|
+
this.log("original fetch performed", responseClone);
|
|
78
|
+
this.emitter.emit(
|
|
79
|
+
"response",
|
|
80
|
+
responseClone,
|
|
81
|
+
interactiveRequest,
|
|
82
|
+
requestId
|
|
83
|
+
);
|
|
84
|
+
return response;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
Object.defineProperty(globalThis.fetch, _chunkOK5YCL7Ljs.IS_PATCHED_MODULE, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
value: true
|
|
91
|
+
});
|
|
92
|
+
this.subscriptions.push(() => {
|
|
93
|
+
Object.defineProperty(globalThis.fetch, _chunkOK5YCL7Ljs.IS_PATCHED_MODULE, {
|
|
94
|
+
value: void 0
|
|
95
|
+
});
|
|
96
|
+
globalThis.fetch = pureFetch;
|
|
97
|
+
this.log('restored native "globalThis.fetch"!', globalThis.fetch.name);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var FetchInterceptor = _FetchInterceptor;
|
|
102
|
+
FetchInterceptor.symbol = Symbol("fetch");
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
exports.FetchInterceptor = FetchInterceptor;
|