@mswjs/interceptors 0.19.5 → 0.21.0

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.
Files changed (175) hide show
  1. package/README.md +7 -7
  2. package/lib/browser/Interceptor-959f650e.d.ts +104 -0
  3. package/lib/browser/chunk-5B525MKF.mjs +2139 -0
  4. package/lib/browser/chunk-BQYA7ER5.mjs +258 -0
  5. package/lib/browser/chunk-IIY3SHU3.js +2139 -0
  6. package/lib/browser/chunk-QWL3EOEY.js +258 -0
  7. package/lib/browser/chunk-STA6QBYM.mjs +64 -0
  8. package/lib/browser/chunk-ZJOF5MEZ.js +64 -0
  9. package/lib/browser/index.d.ts +31 -0
  10. package/lib/browser/index.js +51 -0
  11. package/lib/browser/index.mjs +51 -0
  12. package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +14 -0
  13. package/lib/browser/interceptors/XMLHttpRequest/index.js +657 -0
  14. package/lib/browser/interceptors/XMLHttpRequest/index.mjs +657 -0
  15. package/lib/browser/interceptors/fetch/index.d.ts +12 -0
  16. package/lib/browser/interceptors/fetch/index.js +94 -0
  17. package/lib/browser/interceptors/fetch/index.mjs +94 -0
  18. package/lib/node/BatchInterceptor-a7261b26.d.ts +21 -0
  19. package/lib/node/Interceptor-997045eb.d.ts +104 -0
  20. package/lib/{RemoteHttpInterceptor.d.ts → node/RemoteHttpInterceptor.d.ts} +17 -12
  21. package/lib/node/RemoteHttpInterceptor.js +176 -0
  22. package/lib/node/RemoteHttpInterceptor.mjs +176 -0
  23. package/lib/node/chunk-6GWWOJ23.js +29 -0
  24. package/lib/node/chunk-6V3JXLBF.js +6093 -0
  25. package/lib/node/chunk-CIN5URNI.mjs +29 -0
  26. package/lib/node/chunk-FCIAOT7W.mjs +660 -0
  27. package/lib/node/chunk-GFH37L5D.mjs +6 -0
  28. package/lib/node/chunk-HDUJCCWF.js +661 -0
  29. package/lib/node/chunk-JISWS3Y3.mjs +31 -0
  30. package/lib/node/chunk-KZJG2UW7.js +31 -0
  31. package/lib/node/chunk-NNVTJLQA.mjs +6093 -0
  32. package/lib/node/chunk-QMIXLBOU.js +291 -0
  33. package/lib/node/chunk-STA6QBYM.mjs +64 -0
  34. package/lib/node/chunk-VKKFXSTL.js +660 -0
  35. package/lib/node/chunk-VQ4DZOBB.js +6 -0
  36. package/lib/node/chunk-ZJOF5MEZ.js +64 -0
  37. package/lib/node/chunk-ZSI7MX3V.mjs +291 -0
  38. package/lib/node/chunk-ZWCZGO3W.mjs +661 -0
  39. package/lib/node/index.d.ts +14 -0
  40. package/lib/node/index.js +32 -0
  41. package/lib/node/index.mjs +32 -0
  42. package/lib/node/interceptors/ClientRequest/index.d.ts +22 -0
  43. package/lib/node/interceptors/ClientRequest/index.js +9 -0
  44. package/lib/node/interceptors/ClientRequest/index.mjs +9 -0
  45. package/lib/node/interceptors/XMLHttpRequest/index.d.ts +14 -0
  46. package/lib/node/interceptors/XMLHttpRequest/index.js +11 -0
  47. package/lib/node/interceptors/XMLHttpRequest/index.mjs +11 -0
  48. package/lib/node/interceptors/fetch/index.d.ts +12 -0
  49. package/lib/node/interceptors/fetch/index.js +96 -0
  50. package/lib/node/interceptors/fetch/index.mjs +96 -0
  51. package/package.json +58 -9
  52. package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +1 -1
  53. package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +578 -0
  54. package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +111 -0
  55. package/src/interceptors/XMLHttpRequest/index.ts +12 -13
  56. package/src/shims/webEncoding.ts +9 -0
  57. package/src/utils/bufferUtils.ts +1 -1
  58. package/src/utils/createProxy.ts +78 -0
  59. package/lib/BatchInterceptor.d.ts +0 -18
  60. package/lib/BatchInterceptor.js +0 -34
  61. package/lib/BatchInterceptor.js.map +0 -1
  62. package/lib/Interceptor.d.ts +0 -50
  63. package/lib/Interceptor.js +0 -172
  64. package/lib/Interceptor.js.map +0 -1
  65. package/lib/RemoteHttpInterceptor.js +0 -158
  66. package/lib/RemoteHttpInterceptor.js.map +0 -1
  67. package/lib/glossary.d.ts +0 -7
  68. package/lib/glossary.js +0 -5
  69. package/lib/glossary.js.map +0 -1
  70. package/lib/index.d.ts +0 -5
  71. package/lib/index.js +0 -23
  72. package/lib/index.js.map +0 -1
  73. package/lib/interceptors/ClientRequest/NodeClientRequest.d.ts +0 -46
  74. package/lib/interceptors/ClientRequest/NodeClientRequest.js +0 -325
  75. package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +0 -1
  76. package/lib/interceptors/ClientRequest/http.get.d.ts +0 -4
  77. package/lib/interceptors/ClientRequest/http.get.js +0 -19
  78. package/lib/interceptors/ClientRequest/http.get.js.map +0 -1
  79. package/lib/interceptors/ClientRequest/http.request.d.ts +0 -4
  80. package/lib/interceptors/ClientRequest/http.request.js +0 -16
  81. package/lib/interceptors/ClientRequest/http.request.js.map +0 -1
  82. package/lib/interceptors/ClientRequest/index.d.ts +0 -19
  83. package/lib/interceptors/ClientRequest/index.js +0 -50
  84. package/lib/interceptors/ClientRequest/index.js.map +0 -1
  85. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.d.ts +0 -10
  86. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +0 -60
  87. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +0 -1
  88. package/lib/interceptors/ClientRequest/utils/createRequest.d.ts +0 -6
  89. package/lib/interceptors/ClientRequest/utils/createRequest.js +0 -30
  90. package/lib/interceptors/ClientRequest/utils/createRequest.js.map +0 -1
  91. package/lib/interceptors/ClientRequest/utils/createResponse.d.ts +0 -8
  92. package/lib/interceptors/ClientRequest/utils/createResponse.js +0 -24
  93. package/lib/interceptors/ClientRequest/utils/createResponse.js.map +0 -1
  94. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.d.ts +0 -3
  95. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js +0 -57
  96. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +0 -1
  97. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.d.ts +0 -17
  98. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js +0 -151
  99. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js.map +0 -1
  100. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.d.ts +0 -15
  101. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js +0 -33
  102. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js.map +0 -1
  103. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.d.ts +0 -13
  104. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js +0 -20
  105. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js.map +0 -1
  106. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.d.ts +0 -93
  107. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js +0 -442
  108. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js.map +0 -1
  109. package/lib/interceptors/XMLHttpRequest/index.d.ts +0 -12
  110. package/lib/interceptors/XMLHttpRequest/index.js +0 -43
  111. package/lib/interceptors/XMLHttpRequest/index.js.map +0 -1
  112. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.d.ts +0 -31
  113. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js +0 -44
  114. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js.map +0 -1
  115. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.d.ts +0 -8
  116. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js +0 -15
  117. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js.map +0 -1
  118. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.d.ts +0 -4
  119. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js +0 -14
  120. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js.map +0 -1
  121. package/lib/interceptors/XMLHttpRequest/utils/createEvent.d.ts +0 -2
  122. package/lib/interceptors/XMLHttpRequest/utils/createEvent.js +0 -37
  123. package/lib/interceptors/XMLHttpRequest/utils/createEvent.js.map +0 -1
  124. package/lib/interceptors/XMLHttpRequest/utils/createResponse.d.ts +0 -2
  125. package/lib/interceptors/XMLHttpRequest/utils/createResponse.js +0 -14
  126. package/lib/interceptors/XMLHttpRequest/utils/createResponse.js.map +0 -1
  127. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.d.ts +0 -1
  128. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js +0 -17
  129. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js.map +0 -1
  130. package/lib/interceptors/fetch/index.d.ts +0 -8
  131. package/lib/interceptors/fetch/index.js +0 -81
  132. package/lib/interceptors/fetch/index.js.map +0 -1
  133. package/lib/presets/browser.d.ts +0 -8
  134. package/lib/presets/browser.js +0 -10
  135. package/lib/presets/browser.js.map +0 -1
  136. package/lib/presets/node.d.ts +0 -8
  137. package/lib/presets/node.js +0 -10
  138. package/lib/presets/node.js.map +0 -1
  139. package/lib/utils/AsyncEventEmitter.d.ts +0 -33
  140. package/lib/utils/AsyncEventEmitter.js +0 -148
  141. package/lib/utils/AsyncEventEmitter.js.map +0 -1
  142. package/lib/utils/bufferUtils.d.ts +0 -8
  143. package/lib/utils/bufferUtils.js +0 -24
  144. package/lib/utils/bufferUtils.js.map +0 -1
  145. package/lib/utils/cloneObject.d.ts +0 -1
  146. package/lib/utils/cloneObject.js +0 -28
  147. package/lib/utils/cloneObject.js.map +0 -1
  148. package/lib/utils/createLazyCallback.d.ts +0 -11
  149. package/lib/utils/createLazyCallback.js +0 -40
  150. package/lib/utils/createLazyCallback.js.map +0 -1
  151. package/lib/utils/getCleanUrl.d.ts +0 -4
  152. package/lib/utils/getCleanUrl.js +0 -11
  153. package/lib/utils/getCleanUrl.js.map +0 -1
  154. package/lib/utils/getRequestOptionsByUrl.d.ts +0 -8
  155. package/lib/utils/getRequestOptionsByUrl.js +0 -28
  156. package/lib/utils/getRequestOptionsByUrl.js.map +0 -1
  157. package/lib/utils/getUrlByRequestOptions.d.ts +0 -11
  158. package/lib/utils/getUrlByRequestOptions.js +0 -78
  159. package/lib/utils/getUrlByRequestOptions.js.map +0 -1
  160. package/lib/utils/isObject.d.ts +0 -4
  161. package/lib/utils/isObject.js +0 -11
  162. package/lib/utils/isObject.js.map +0 -1
  163. package/lib/utils/nextTick.d.ts +0 -2
  164. package/lib/utils/nextTick.js +0 -16
  165. package/lib/utils/nextTick.js.map +0 -1
  166. package/lib/utils/parseJson.d.ts +0 -5
  167. package/lib/utils/parseJson.js +0 -18
  168. package/lib/utils/parseJson.js.map +0 -1
  169. package/lib/utils/toInteractiveRequest.d.ts +0 -7
  170. package/lib/utils/toInteractiveRequest.js +0 -20
  171. package/lib/utils/toInteractiveRequest.js.map +0 -1
  172. package/lib/utils/uuid.d.ts +0 -1
  173. package/lib/utils/uuid.js +0 -12
  174. package/lib/utils/uuid.js.map +0 -1
  175. package/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts +0 -684
@@ -3,7 +3,7 @@ import { HttpRequestEventMap, IS_PATCHED_MODULE } from '../../glossary'
3
3
  import { InteractiveRequest } from '../../utils/toInteractiveRequest'
4
4
  import { Interceptor } from '../../Interceptor'
5
5
  import { AsyncEventEmitter } from '../../utils/AsyncEventEmitter'
6
- import { createXMLHttpRequestOverride } from './XMLHttpRequestOverride'
6
+ import { createXMLHttpRequestProxy } from './XMLHttpRequestProxy'
7
7
 
8
8
  export type XMLHttpRequestEventListener = (
9
9
  request: InteractiveRequest,
@@ -20,10 +20,7 @@ export class XMLHttpRequestInterceptor extends Interceptor<HttpRequestEventMap>
20
20
  }
21
21
 
22
22
  protected checkEnvironment() {
23
- return (
24
- typeof window !== 'undefined' &&
25
- typeof window.XMLHttpRequest !== 'undefined'
26
- )
23
+ return typeof globalThis.XMLHttpRequest !== 'undefined'
27
24
  }
28
25
 
29
26
  protected setup() {
@@ -31,36 +28,38 @@ export class XMLHttpRequestInterceptor extends Interceptor<HttpRequestEventMap>
31
28
 
32
29
  log('patching "XMLHttpRequest" module...')
33
30
 
34
- const PureXMLHttpRequest = window.XMLHttpRequest
31
+ const PureXMLHttpRequest = globalThis.XMLHttpRequest
35
32
 
36
33
  invariant(
37
34
  !(PureXMLHttpRequest as any)[IS_PATCHED_MODULE],
38
35
  'Failed to patch the "XMLHttpRequest" module: already patched.'
39
36
  )
40
37
 
41
- window.XMLHttpRequest = createXMLHttpRequestOverride({
42
- XMLHttpRequest: PureXMLHttpRequest,
38
+ globalThis.XMLHttpRequest = createXMLHttpRequestProxy({
43
39
  emitter: this.emitter,
44
40
  log: this.log,
45
41
  })
46
42
 
47
- log('native "XMLHttpRequest" module patched!', window.XMLHttpRequest.name)
43
+ log(
44
+ 'native "XMLHttpRequest" module patched!',
45
+ globalThis.XMLHttpRequest.name
46
+ )
48
47
 
49
- Object.defineProperty(window.XMLHttpRequest, IS_PATCHED_MODULE, {
48
+ Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, {
50
49
  enumerable: true,
51
50
  configurable: true,
52
51
  value: true,
53
52
  })
54
53
 
55
54
  this.subscriptions.push(() => {
56
- Object.defineProperty(window.XMLHttpRequest, IS_PATCHED_MODULE, {
55
+ Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, {
57
56
  value: undefined,
58
57
  })
59
58
 
60
- window.XMLHttpRequest = PureXMLHttpRequest
59
+ globalThis.XMLHttpRequest = PureXMLHttpRequest
61
60
  log(
62
61
  'native "XMLHttpRequest" module restored!',
63
- window.XMLHttpRequest.name
62
+ globalThis.XMLHttpRequest.name
64
63
  )
65
64
  })
66
65
  }
@@ -0,0 +1,9 @@
1
+ export const TextEncoder: typeof globalThis.TextEncoder =
2
+ typeof globalThis.TextEncoder === 'undefined'
3
+ ? require('util').TextEncoder
4
+ : globalThis.TextEncoder
5
+
6
+ export const TextDecoder: typeof globalThis.TextDecoder =
7
+ typeof globalThis.TextDecoder === 'undefined'
8
+ ? require('util').TextDecoder
9
+ : globalThis.TextDecoder
@@ -1,4 +1,4 @@
1
- import { TextDecoder, TextEncoder } from 'web-encoding'
1
+ import { TextEncoder, TextDecoder } from '../shims/webEncoding'
2
2
 
3
3
  const encoder = new TextEncoder()
4
4
 
@@ -0,0 +1,78 @@
1
+ export interface ProxyOptions<Target extends Record<string, any>> {
2
+ constructorCall?(args: Array<unknown>, next: NextFunction<Target>): Target
3
+
4
+ methodCall?<F extends keyof Target>(
5
+ this: Target,
6
+ data: [methodName: F, args: Array<unknown>],
7
+ next: NextFunction<void>
8
+ ): void
9
+
10
+ setProperty?(
11
+ data: [propertyName: string | symbol, nextValue: unknown],
12
+ next: NextFunction<void>
13
+ ): void
14
+
15
+ getProperty?(
16
+ data: [propertyName: string | symbol, receiver: Target],
17
+ next: NextFunction<void>
18
+ ): void
19
+ }
20
+
21
+ export type NextFunction<ReturnType> = () => ReturnType
22
+
23
+ export function createProxy<Target extends object>(
24
+ target: Target,
25
+ options: ProxyOptions<Target>
26
+ ): Target {
27
+ const proxy = new Proxy(target, optionsToProxyHandler(options))
28
+ return proxy
29
+ }
30
+
31
+ function optionsToProxyHandler<T extends Record<string, any>>(
32
+ options: ProxyOptions<T>
33
+ ): ProxyHandler<T> {
34
+ const { constructorCall, methodCall, getProperty, setProperty } = options
35
+ const handler: ProxyHandler<T> = {}
36
+
37
+ if (typeof constructorCall !== 'undefined') {
38
+ handler.construct = function (target, args, newTarget) {
39
+ const next = Reflect.construct.bind(null, target as any, args, newTarget)
40
+ return constructorCall.call(newTarget, args, next)
41
+ }
42
+ }
43
+
44
+ if (typeof setProperty !== 'undefined') {
45
+ handler.set = function (target, propertyName, nextValue, receiver) {
46
+ const next = () => Reflect.set(target, propertyName, nextValue, receiver)
47
+ return setProperty.call(target, [propertyName, nextValue], next) as any
48
+ }
49
+ }
50
+
51
+ handler.get = function (target, propertyName, receiver) {
52
+ /**
53
+ * @note Using `Reflect.get()` here causes "TypeError: Illegal invocation".
54
+ */
55
+ const next = () => target[propertyName as any]
56
+
57
+ const value =
58
+ typeof getProperty !== 'undefined'
59
+ ? getProperty.call(target, [propertyName, receiver], next)
60
+ : next()
61
+
62
+ if (typeof value === 'function') {
63
+ return (...args: Array<any>) => {
64
+ const next = value.bind(target, ...args)
65
+
66
+ if (typeof methodCall !== 'undefined') {
67
+ return methodCall.call(target, [propertyName as any, args], next)
68
+ }
69
+
70
+ return next()
71
+ }
72
+ }
73
+
74
+ return value
75
+ }
76
+
77
+ return handler
78
+ }
@@ -1,18 +0,0 @@
1
- import { EventMap, Listener } from 'strict-event-emitter';
2
- import { ExtractEventNames, Interceptor } from './Interceptor';
3
- export interface BatchInterceptorOptions<InterceptorList extends Array<Interceptor<any>>> {
4
- name: string;
5
- interceptors: InterceptorList;
6
- }
7
- export declare type ExtractEventMapType<InterceptorList extends Array<Interceptor<any>>> = InterceptorList extends Array<infer InterceptorType> ? InterceptorType extends Interceptor<infer EventMap> ? EventMap : never : never;
8
- /**
9
- * A batch interceptor that exposes a single interface
10
- * to apply and operate with multiple interceptors at once.
11
- */
12
- export declare class BatchInterceptor<InterceptorList extends Array<Interceptor<any>>, Events extends EventMap = ExtractEventMapType<InterceptorList>> extends Interceptor<Events> {
13
- static symbol: Symbol;
14
- private interceptors;
15
- constructor(options: BatchInterceptorOptions<InterceptorList>);
16
- protected setup(): void;
17
- on<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): void;
18
- }
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BatchInterceptor = void 0;
4
- const Interceptor_1 = require("./Interceptor");
5
- /**
6
- * A batch interceptor that exposes a single interface
7
- * to apply and operate with multiple interceptors at once.
8
- */
9
- class BatchInterceptor extends Interceptor_1.Interceptor {
10
- constructor(options) {
11
- BatchInterceptor.symbol = Symbol(options.name);
12
- super(BatchInterceptor.symbol);
13
- this.interceptors = options.interceptors;
14
- }
15
- setup() {
16
- const log = this.log.extend('setup');
17
- log('applying all %d interceptors...', this.interceptors.length);
18
- for (const interceptor of this.interceptors) {
19
- log('applying "%s" interceptor...', interceptor.constructor.name);
20
- interceptor.apply();
21
- log('adding interceptor dispose subscription');
22
- this.subscriptions.push(() => interceptor.dispose());
23
- }
24
- }
25
- on(event, listener) {
26
- // Instead of adding a listener to the batch interceptor,
27
- // propagate the listener to each of the individual interceptors.
28
- this.interceptors.forEach((interceptor) => {
29
- interceptor.on(event, listener);
30
- });
31
- }
32
- }
33
- exports.BatchInterceptor = BatchInterceptor;
34
- //# sourceMappingURL=BatchInterceptor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BatchInterceptor.js","sourceRoot":"","sources":["../src/BatchInterceptor.ts"],"names":[],"mappings":";;;AACA,+CAA8D;AAiB9D;;;GAGG;AACH,MAAa,gBAGX,SAAQ,yBAAmB;IAK3B,YAAY,OAAiD;QAC3D,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC9C,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAA;IAC1C,CAAC;IAES,KAAK;QACb,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAEpC,GAAG,CAAC,iCAAiC,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QAEhE,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,YAAY,EAAE;YAC3C,GAAG,CAAC,8BAA8B,EAAE,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;YACjE,WAAW,CAAC,KAAK,EAAE,CAAA;YAEnB,GAAG,CAAC,yCAAyC,CAAC,CAAA;YAC9C,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC,CAAA;SACrD;IACH,CAAC;IAEM,EAAE,CACP,KAAgB,EAChB,QAAqC;QAErC,yDAAyD;QACzD,iEAAiE;QACjE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE;YACxC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAtCD,4CAsCC"}
@@ -1,50 +0,0 @@
1
- import { Debugger } from 'debug';
2
- import { Listener } from 'strict-event-emitter';
3
- import { AsyncEventEmitter } from './utils/AsyncEventEmitter';
4
- export declare type InterceptorEventMap = Record<string, any>;
5
- export declare type InterceptorSubscription = () => void;
6
- export declare function getGlobalSymbol<V>(symbol: Symbol): V | undefined;
7
- export declare function deleteGlobalSymbol(symbol: Symbol): void;
8
- export declare enum InterceptorReadyState {
9
- INACTIVE = "INACTIVE",
10
- APPLYING = "APPLYING",
11
- APPLIED = "APPLIED",
12
- DISPOSING = "DISPOSING",
13
- DISPOSED = "DISPOSED"
14
- }
15
- export declare type ExtractEventNames<Events extends Record<string, any>> = Events extends Record<infer EventName, any> ? EventName : never;
16
- export declare class Interceptor<Events extends InterceptorEventMap> {
17
- private readonly symbol;
18
- protected emitter: AsyncEventEmitter<Events>;
19
- protected subscriptions: Array<InterceptorSubscription>;
20
- protected log: Debugger;
21
- readyState: InterceptorReadyState;
22
- constructor(symbol: Symbol);
23
- /**
24
- * Determine if this interceptor can be applied
25
- * in the current environment.
26
- */
27
- protected checkEnvironment(): boolean;
28
- /**
29
- * Apply this interceptor to the current process.
30
- * Returns an already running interceptor instance if it's present.
31
- */
32
- apply(): void;
33
- /**
34
- * Setup the module augments and stubs necessary for this interceptor.
35
- * This method is not run if there's a running interceptor instance
36
- * to prevent instantiating an interceptor multiple times.
37
- */
38
- protected setup(): void;
39
- /**
40
- * Listen to the interceptor's public events.
41
- */
42
- on<EventName extends ExtractEventNames<Events>>(eventName: EventName, listener: Listener<Events[EventName]>): void;
43
- /**
44
- * Disposes of any side-effects this interceptor has introduced.
45
- */
46
- dispose(): void;
47
- private getInstance;
48
- private setInstance;
49
- private clearInstance;
50
- }
@@ -1,172 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Interceptor = exports.InterceptorReadyState = exports.deleteGlobalSymbol = exports.getGlobalSymbol = void 0;
4
- const debug_1 = require("debug");
5
- const AsyncEventEmitter_1 = require("./utils/AsyncEventEmitter");
6
- const nextTick_1 = require("./utils/nextTick");
7
- function getGlobalSymbol(symbol) {
8
- return (
9
- // @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
10
- globalThis[symbol] || undefined);
11
- }
12
- exports.getGlobalSymbol = getGlobalSymbol;
13
- function setGlobalSymbol(symbol, value) {
14
- // @ts-ignore
15
- globalThis[symbol] = value;
16
- }
17
- function deleteGlobalSymbol(symbol) {
18
- // @ts-ignore
19
- delete globalThis[symbol];
20
- }
21
- exports.deleteGlobalSymbol = deleteGlobalSymbol;
22
- var InterceptorReadyState;
23
- (function (InterceptorReadyState) {
24
- InterceptorReadyState["INACTIVE"] = "INACTIVE";
25
- InterceptorReadyState["APPLYING"] = "APPLYING";
26
- InterceptorReadyState["APPLIED"] = "APPLIED";
27
- InterceptorReadyState["DISPOSING"] = "DISPOSING";
28
- InterceptorReadyState["DISPOSED"] = "DISPOSED";
29
- })(InterceptorReadyState = exports.InterceptorReadyState || (exports.InterceptorReadyState = {}));
30
- class Interceptor {
31
- constructor(symbol) {
32
- this.symbol = symbol;
33
- this.readyState = InterceptorReadyState.INACTIVE;
34
- this.emitter = new AsyncEventEmitter_1.AsyncEventEmitter();
35
- this.subscriptions = [];
36
- this.log = (0, debug_1.debug)(symbol.description);
37
- // Do not limit the maximum number of listeners
38
- // so not to limit the maximum amount of parallel events emitted.
39
- this.emitter.setMaxListeners(0);
40
- this.log('constructing the interceptor...');
41
- }
42
- /**
43
- * Determine if this interceptor can be applied
44
- * in the current environment.
45
- */
46
- checkEnvironment() {
47
- return true;
48
- }
49
- /**
50
- * Apply this interceptor to the current process.
51
- * Returns an already running interceptor instance if it's present.
52
- */
53
- apply() {
54
- const log = this.log.extend('apply');
55
- log('applying the interceptor...');
56
- if (this.readyState === InterceptorReadyState.APPLIED) {
57
- log('intercepted already applied!');
58
- return;
59
- }
60
- const shouldApply = this.checkEnvironment();
61
- if (!shouldApply) {
62
- log('the interceptor cannot be applied in this environment!');
63
- return;
64
- }
65
- this.readyState = InterceptorReadyState.APPLYING;
66
- // Always activate the emitter when applying the interceptor.
67
- // This will ensure the interceptor can process events after it's
68
- // been disposed and re-applied again (it may be a singleton).
69
- this.emitter.activate();
70
- log('activated the emiter!', this.emitter.readyState);
71
- // Whenever applying a new interceptor, check if it hasn't been applied already.
72
- // This enables to apply the same interceptor multiple times, for example from a different
73
- // interceptor, only proxying events but keeping the stubs in a single place.
74
- const runningInstance = this.getInstance();
75
- if (runningInstance) {
76
- log('found a running instance, reusing...');
77
- // Proxy any listeners you set on this instance to the running instance.
78
- this.on = (event, listener) => {
79
- log('proxying the "%s" listener', event);
80
- // Add listeners to the running instance so they appear
81
- // at the top of the event listeners list and are executed first.
82
- runningInstance.emitter.addListener(event, listener);
83
- // Ensure that once this interceptor instance is disposed,
84
- // it removes all listeners it has appended to the running interceptor instance.
85
- this.subscriptions.push(() => {
86
- runningInstance.emitter.removeListener(event, listener);
87
- log('removed proxied "%s" listener!', event);
88
- });
89
- };
90
- (0, nextTick_1.nextTick)(() => {
91
- this.readyState = InterceptorReadyState.APPLIED;
92
- });
93
- return;
94
- }
95
- log('no running instance found, setting up a new instance...');
96
- // Setup the interceptor.
97
- this.setup();
98
- // Store the newly applied interceptor instance globally.
99
- this.setInstance();
100
- (0, nextTick_1.nextTick)(() => {
101
- this.readyState = InterceptorReadyState.APPLIED;
102
- });
103
- }
104
- /**
105
- * Setup the module augments and stubs necessary for this interceptor.
106
- * This method is not run if there's a running interceptor instance
107
- * to prevent instantiating an interceptor multiple times.
108
- */
109
- setup() { }
110
- /**
111
- * Listen to the interceptor's public events.
112
- */
113
- on(eventName, listener) {
114
- const log = this.log.extend('on');
115
- if (this.readyState === InterceptorReadyState.DISPOSING ||
116
- this.readyState === InterceptorReadyState.DISPOSED) {
117
- log('cannot listen to events, already disposed!');
118
- return;
119
- }
120
- log('adding "%s" event listener:', eventName, listener.name);
121
- this.emitter.on(eventName, listener);
122
- }
123
- /**
124
- * Disposes of any side-effects this interceptor has introduced.
125
- */
126
- dispose() {
127
- const log = this.log.extend('dispose');
128
- if (this.readyState === InterceptorReadyState.DISPOSED) {
129
- log('cannot dispose, already disposed!');
130
- return;
131
- }
132
- log('disposing the interceptor...');
133
- this.readyState = InterceptorReadyState.DISPOSING;
134
- if (!this.getInstance()) {
135
- log('no interceptors running, skipping dispose...');
136
- return;
137
- }
138
- // Delete the global symbol as soon as possible,
139
- // indicating that the interceptor is no longer running.
140
- this.clearInstance();
141
- log('global symbol deleted:', getGlobalSymbol(this.symbol));
142
- if (this.subscriptions.length > 0) {
143
- log('disposing of %d subscriptions...', this.subscriptions.length);
144
- for (const dispose of this.subscriptions) {
145
- dispose();
146
- }
147
- this.subscriptions = [];
148
- log('disposed of all subscriptions!', this.subscriptions.length);
149
- }
150
- this.emitter.deactivate();
151
- log('destroyed the listener!');
152
- (0, nextTick_1.nextTick)(() => {
153
- this.readyState = InterceptorReadyState.DISPOSED;
154
- });
155
- }
156
- getInstance() {
157
- var _a;
158
- const instance = getGlobalSymbol(this.symbol);
159
- this.log('retrieved global instance:', (_a = instance === null || instance === void 0 ? void 0 : instance.constructor) === null || _a === void 0 ? void 0 : _a.name);
160
- return instance;
161
- }
162
- setInstance() {
163
- setGlobalSymbol(this.symbol, this);
164
- this.log('set global instance!', this.symbol.description);
165
- }
166
- clearInstance() {
167
- deleteGlobalSymbol(this.symbol);
168
- this.log('cleared global instance!', this.symbol.description);
169
- }
170
- }
171
- exports.Interceptor = Interceptor;
172
- //# sourceMappingURL=Interceptor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Interceptor.js","sourceRoot":"","sources":["../src/Interceptor.ts"],"names":[],"mappings":";;;AAAA,iCAAuC;AAEvC,iEAA6D;AAC7D,+CAA2C;AAK3C,SAAgB,eAAe,CAAI,MAAc;IAC/C,OAAO;IACL,kEAAkE;IAClE,UAAU,CAAC,MAAM,CAAC,IAAI,SAAS,CAChC,CAAA;AACH,CAAC;AALD,0CAKC;AAED,SAAS,eAAe,CAAC,MAAc,EAAE,KAAU;IACjD,aAAa;IACb,UAAU,CAAC,MAAM,CAAC,GAAG,KAAK,CAAA;AAC5B,CAAC;AAED,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,aAAa;IACb,OAAO,UAAU,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC;AAHD,gDAGC;AAED,IAAY,qBAMX;AAND,WAAY,qBAAqB;IAC/B,8CAAqB,CAAA;IACrB,8CAAqB,CAAA;IACrB,4CAAmB,CAAA;IACnB,gDAAuB,CAAA;IACvB,8CAAqB,CAAA;AACvB,CAAC,EANW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAMhC;AAKD,MAAa,WAAW;IAOtB,YAA6B,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QACzC,IAAI,CAAC,UAAU,GAAG,qBAAqB,CAAC,QAAQ,CAAA;QAEhD,IAAI,CAAC,OAAO,GAAG,IAAI,qCAAiB,EAAE,CAAA;QACtC,IAAI,CAAC,aAAa,GAAG,EAAE,CAAA;QACvB,IAAI,CAAC,GAAG,GAAG,IAAA,aAAK,EAAC,MAAM,CAAC,WAAY,CAAC,CAAA;QAErC,+CAA+C;QAC/C,iEAAiE;QACjE,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;QAE/B,IAAI,CA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AAe,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QAClC,IAAI,CAAC,GAAG,CAAC,sBAAsB,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC3D,CAAC;IAEO,aAAa;QACnB,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC/B,IAAI,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAC/D,CAAC;CACF;AA9LD,kCA8LC"}
@@ -1,158 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.RemoteHttpResolver = exports.requestReviver = exports.RemoteHttpInterceptor = void 0;
13
- const web_fetch_1 = require("@remix-run/web-fetch");
14
- const headers_polyfill_1 = require("headers-polyfill");
15
- const Interceptor_1 = require("./Interceptor");
16
- const BatchInterceptor_1 = require("./BatchInterceptor");
17
- const ClientRequest_1 = require("./interceptors/ClientRequest");
18
- const XMLHttpRequest_1 = require("./interceptors/XMLHttpRequest");
19
- const toInteractiveRequest_1 = require("./utils/toInteractiveRequest");
20
- class RemoteHttpInterceptor extends BatchInterceptor_1.BatchInterceptor {
21
- constructor() {
22
- super({
23
- name: 'remote-interceptor',
24
- interceptors: [
25
- new ClientRequest_1.ClientRequestInterceptor(),
26
- new XMLHttpRequest_1.XMLHttpRequestInterceptor(),
27
- ],
28
- });
29
- }
30
- setup() {
31
- super.setup();
32
- let handleParentMessage;
33
- this.on('request', (request, requestId) => __awaiter(this, void 0, void 0, function* () {
34
- var _a;
35
- // Send the stringified intercepted request to
36
- // the parent process where the remote resolver is established.
37
- const serializedRequest = JSON.stringify({
38
- id: requestId,
39
- method: request.method,
40
- url: request.url,
41
- headers: (0, headers_polyfill_1.headersToObject)(request.headers),
42
- credentials: request.credentials,
43
- body: ['GET', 'HEAD'].includes(request.method)
44
- ? null
45
- : yield request.text(),
46
- });
47
- this.log('sent serialized request to the child:', serializedRequest);
48
- (_a = process.send) === null || _a === void 0 ? void 0 : _a.call(process, `request:${serializedRequest}`);
49
- const responsePromise = new Promise((resolve) => {
50
- handleParentMessage = (message) => {
51
- if (typeof message !== 'string') {
52
- return resolve();
53
- }
54
- if (message.startsWith(`response:${requestId}`)) {
55
- const [, serializedResponse] = message.match(/^response:.+?:(.+)$/) || [];
56
- if (!serializedResponse) {
57
- return resolve();
58
- }
59
- const responseInit = JSON.parse(serializedResponse);
60
- const mockedResponse = new web_fetch_1.Response(responseInit.body, {
61
- status: responseInit.status,
62
- statusText: responseInit.statusText,
63
- headers: new headers_polyfill_1.Headers(responseInit.headers),
64
- });
65
- request.respondWith(mockedResponse);
66
- resolve();
67
- }
68
- };
69
- });
70
- // Listen for the mocked response message from the parent.
71
- this.log('add "message" listener to the parent process', handleParentMessage);
72
- process.addListener('message', handleParentMessage);
73
- return responsePromise;
74
- }));
75
- this.subscriptions.push(() => {
76
- process.removeListener('message', handleParentMessage);
77
- });
78
- }
79
- }
80
- exports.RemoteHttpInterceptor = RemoteHttpInterceptor;
81
- function requestReviver(key, value) {
82
- switch (key) {
83
- case 'url':
84
- return new URL(value);
85
- case 'headers':
86
- return new headers_polyfill_1.Headers(value);
87
- default:
88
- return value;
89
- }
90
- }
91
- exports.requestReviver = requestReviver;
92
- class RemoteHttpResolver extends Interceptor_1.Interceptor {
93
- constructor(options) {
94
- super(RemoteHttpResolver.symbol);
95
- this.process = options.process;
96
- }
97
- setup() {
98
- const log = this.log.extend('setup');
99
- const handleChildMessage = (message) => __awaiter(this, void 0, void 0, function* () {
100
- log('received message from child!', message);
101
- if (typeof message !== 'string' || !message.startsWith('request:')) {
102
- log('unknown message, ignoring...');
103
- return;
104
- }
105
- const [, serializedRequest] = message.match(/^request:(.+)$/) || [];
106
- if (!serializedRequest) {
107
- return;
108
- }
109
- const requestJson = JSON.parse(serializedRequest, requestReviver);
110
- log('parsed intercepted request', requestJson);
111
- const capturedRequest = new web_fetch_1.Request(requestJson.url, {
112
- method: requestJson.method,
113
- headers: new headers_polyfill_1.Headers(requestJson.headers),
114
- credentials: requestJson.credentials,
115
- body: requestJson.body,
116
- });
117
- const interactiveRequest = (0, toInteractiveRequest_1.toInteractiveRequest)(capturedRequest);
118
- this.emitter.emit('request', interactiveRequest, requestJson.id);
119
- yield this.emitter.untilIdle('request', ({ args: [, pendingRequestId] }) => {
120
- return pendingRequestId === requestJson.id;
121
- });
122
- const [mockedResponse] = yield interactiveRequest.respondWith.invoked();
123
- if (!mockedResponse) {
124
- return;
125
- }
126
- log('event.respondWith called with:', mockedResponse);
127
- const responseClone = mockedResponse.clone();
128
- const responseText = yield mockedResponse.text();
129
- // Send the mocked response to the child process.
130
- const serializedResponse = JSON.stringify({
131
- status: mockedResponse.status,
132
- statusText: mockedResponse.statusText,
133
- headers: (0, headers_polyfill_1.headersToObject)(mockedResponse.headers),
134
- body: responseText,
135
- });
136
- this.process.send(`response:${requestJson.id}:${serializedResponse}`, (error) => {
137
- if (error) {
138
- return;
139
- }
140
- // Emit an optimistic "response" event at this point,
141
- // not to rely on the back-and-forth signaling for the sake of the event.
142
- this.emitter.emit('response', responseClone, capturedRequest, requestJson.id);
143
- });
144
- log('sent serialized mocked response to the parent:', serializedResponse);
145
- });
146
- this.subscriptions.push(() => {
147
- this.process.removeListener('message', handleChildMessage);
148
- log('removed the "message" listener from the child process!');
149
- });
150
- log('adding a "message" listener to the child process');
151
- this.process.addListener('message', handleChildMessage);
152
- this.process.once('error', () => this.dispose());
153
- this.process.once('exit', () => this.dispose());
154
- }
155
- }
156
- exports.RemoteHttpResolver = RemoteHttpResolver;
157
- RemoteHttpResolver.symbol = Symbol('remote-resolver');
158
- //# sourceMappingURL=RemoteHttpInterceptor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RemoteHttpInterceptor.js","sourceRoot":"","sources":["../src/RemoteHttpInterceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAAwD;AACxD,uDAA0E;AAE1E,+CAA2C;AAC3C,yDAAqD;AACrD,gEAAuE;AACvE,kEAAyE;AACzE,uEAAmE;AAuBnE,MAAa,qBAAsB,SAAQ,mCAE1C;IACC;QACE,KAAK,CAAC;YACJ,IAAI,EAAE,oBAAoB;YAC1B,YAAY,EAAE;gBACZ,IAAI,wCAAwB,EAAE;gBAC9B,IAAI,0CAAyB,EAAE;aAChC;SACF,CAAC,CAAA;IACJ,CAAC;IAES,KAAK;QACb,KAAK,CAAC,KAAK,EAAE,CAAA;QAEb,IAAI,mBAA2C,CAAA;QAE/C,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,CAAO,OAAO,EAAE,SAAS,EAAE,EAAE;;YAC9C,8CAA8C;YAC9C,+DAA+D;YAC/D,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC;gBACvC,EAAE,EAAE,SAAS;gBACb,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,GAAG,EAAE,OAAO,CAAC,GAAG;gBAChB,OAAO,EAAE,IAAA,kCAAe,EAAC,OAAO,CAAC,OAAO,CAAC;gBACzC,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;oBAC5C,CAAC,CAAC,IAAI;oBACN,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE;aACJ,CAAC,CAAA;YAEvB,IAAI,CAAC,GAAG,CAAC,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E;gBACR,IAAI,KAAK,EAAE;oBACT,OAAM;iBACP;gBAED,qDAAqD;gBACrD,yEAAyE;gBACzE,IAAI,CAAC,OAAO,CAAC,IAAI,CACf,UAAU,EACV,aAAa,EACb,eAAe,EACf,WAAW,CAAC,EAAE,CACf,CAAA;YACH,CAAC,CACF,CAAA;YAED,GAAG,CAAC,gDAAgD,EAAE,kBAAkB,CAAC,CAAA;QAC3E,CAAC,CAAA,CAAA;QAED,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE;YAC3B,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;YAC1D,GAAG,CAAC,wDAAwD,CAAC,CAAA;QAC/D,CAAC,CAAC,CAAA;QAEF,GAAG,CAAC,kDAAkD,CAAC,CAAA;QACvD,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;QAEvD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QAChD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;IACjD,CAAC;;AAhGH,gDAiGC;AAhGQ,yBAAM,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAA"}
package/lib/glossary.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import type { InteractiveRequest } from './utils/toInteractiveRequest';
2
- export declare const IS_PATCHED_MODULE: unique symbol;
3
- export declare type RequestCredentials = 'omit' | 'include' | 'same-origin';
4
- export declare type HttpRequestEventMap = {
5
- request: [request: InteractiveRequest, requestId: string];
6
- response: [response: Response, request: Request, requestId: string];
7
- };
package/lib/glossary.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IS_PATCHED_MODULE = void 0;
4
- exports.IS_PATCHED_MODULE = Symbol('isPatchedModule');
5
- //# sourceMappingURL=glossary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"glossary.js","sourceRoot":"","sources":["../src/glossary.ts"],"names":[],"mappings":";;;AAEa,QAAA,iBAAiB,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAA"}
package/lib/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './glossary';
2
- export * from './Interceptor';
3
- export * from './BatchInterceptor';
4
- export { getCleanUrl } from './utils/getCleanUrl';
5
- export { encodeBuffer, decodeBuffer } from './utils/bufferUtils';