@mswjs/interceptors 0.39.8 → 0.41.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 (282) hide show
  1. package/ClientRequest/package.json +7 -2
  2. package/RemoteHttpInterceptor/package.json +7 -2
  3. package/WebSocket/package.json +9 -2
  4. package/XMLHttpRequest/package.json +9 -3
  5. package/fetch/package.json +9 -3
  6. package/lib/browser/Interceptor-2mUoKZL1.d.mts +65 -0
  7. package/lib/browser/Interceptor-Deczogc8.d.cts +65 -0
  8. package/lib/browser/XMLHttpRequest-BUfglQD1.cjs +761 -0
  9. package/lib/browser/XMLHttpRequest-BUfglQD1.cjs.map +1 -0
  10. package/lib/browser/XMLHttpRequest-DS5fc8Qs.mjs +756 -0
  11. package/lib/browser/XMLHttpRequest-DS5fc8Qs.mjs.map +1 -0
  12. package/lib/browser/bufferUtils-BiiO6HZv.mjs +20 -0
  13. package/lib/browser/bufferUtils-BiiO6HZv.mjs.map +1 -0
  14. package/lib/browser/bufferUtils-Uc0eRItL.cjs +38 -0
  15. package/lib/browser/bufferUtils-Uc0eRItL.cjs.map +1 -0
  16. package/lib/browser/createRequestId-Cs4oXfa1.cjs +205 -0
  17. package/lib/browser/createRequestId-Cs4oXfa1.cjs.map +1 -0
  18. package/lib/browser/createRequestId-DQcIlohW.mjs +170 -0
  19. package/lib/browser/createRequestId-DQcIlohW.mjs.map +1 -0
  20. package/lib/browser/fetch-BHcqM3z7.cjs +253 -0
  21. package/lib/browser/fetch-BHcqM3z7.cjs.map +1 -0
  22. package/lib/browser/fetch-DSJoynSF.mjs +248 -0
  23. package/lib/browser/fetch-DSJoynSF.mjs.map +1 -0
  24. package/lib/browser/getRawRequest-BTaNLFr0.mjs +218 -0
  25. package/lib/browser/getRawRequest-BTaNLFr0.mjs.map +1 -0
  26. package/lib/browser/getRawRequest-zx8rUJL2.cjs +259 -0
  27. package/lib/browser/getRawRequest-zx8rUJL2.cjs.map +1 -0
  28. package/lib/browser/glossary-BdLS4k1H.d.cts +70 -0
  29. package/lib/browser/glossary-gEEJhK4S.d.mts +70 -0
  30. package/lib/browser/handleRequest-DI6a7Dty.cjs +189 -0
  31. package/lib/browser/handleRequest-DI6a7Dty.cjs.map +1 -0
  32. package/lib/browser/handleRequest-DxGbCTbb.mjs +178 -0
  33. package/lib/browser/handleRequest-DxGbCTbb.mjs.map +1 -0
  34. package/lib/browser/hasConfigurableGlobal-C8kXFDic.mjs +33 -0
  35. package/lib/browser/hasConfigurableGlobal-C8kXFDic.mjs.map +1 -0
  36. package/lib/browser/hasConfigurableGlobal-D7S3l5h6.cjs +45 -0
  37. package/lib/browser/hasConfigurableGlobal-D7S3l5h6.cjs.map +1 -0
  38. package/lib/browser/index.cjs +68 -0
  39. package/lib/browser/index.cjs.map +1 -0
  40. package/lib/browser/index.d.cts +87 -0
  41. package/lib/browser/index.d.mts +87 -0
  42. package/lib/browser/index.mjs +49 -75
  43. package/lib/browser/index.mjs.map +1 -1
  44. package/lib/browser/interceptors/WebSocket/index.cjs +621 -0
  45. package/lib/browser/interceptors/WebSocket/index.cjs.map +1 -0
  46. package/lib/browser/interceptors/WebSocket/index.d.cts +277 -0
  47. package/lib/browser/interceptors/WebSocket/index.d.mts +277 -0
  48. package/lib/browser/interceptors/WebSocket/index.mjs +587 -694
  49. package/lib/browser/interceptors/WebSocket/index.mjs.map +1 -1
  50. package/lib/browser/interceptors/XMLHttpRequest/index.cjs +7 -0
  51. package/lib/browser/interceptors/XMLHttpRequest/index.d.cts +15 -0
  52. package/lib/browser/interceptors/XMLHttpRequest/index.d.mts +15 -0
  53. package/lib/browser/interceptors/XMLHttpRequest/index.mjs +7 -12
  54. package/lib/browser/interceptors/fetch/index.cjs +6 -0
  55. package/lib/browser/interceptors/fetch/index.d.cts +13 -0
  56. package/lib/browser/interceptors/fetch/index.d.mts +13 -0
  57. package/lib/browser/interceptors/fetch/index.mjs +6 -11
  58. package/lib/browser/presets/browser.cjs +17 -0
  59. package/lib/browser/presets/browser.cjs.map +1 -0
  60. package/lib/browser/presets/browser.d.cts +12 -0
  61. package/lib/browser/presets/browser.d.mts +14 -0
  62. package/lib/browser/presets/browser.mjs +15 -19
  63. package/lib/browser/presets/browser.mjs.map +1 -1
  64. package/lib/node/BatchInterceptor-3LnAnLTx.cjs +49 -0
  65. package/lib/node/BatchInterceptor-3LnAnLTx.cjs.map +1 -0
  66. package/lib/node/BatchInterceptor-D7mXzHcQ.d.mts +26 -0
  67. package/lib/node/BatchInterceptor-DFaBPilf.mjs +44 -0
  68. package/lib/node/BatchInterceptor-DFaBPilf.mjs.map +1 -0
  69. package/lib/node/BatchInterceptor-D_YqR8qU.d.cts +26 -0
  70. package/lib/node/ClientRequest-2rDe54Ui.cjs +1043 -0
  71. package/lib/node/ClientRequest-2rDe54Ui.cjs.map +1 -0
  72. package/lib/node/ClientRequest-Ca8Qykuv.mjs +1034 -0
  73. package/lib/node/ClientRequest-Ca8Qykuv.mjs.map +1 -0
  74. package/lib/node/Interceptor-DEazpLJd.d.mts +133 -0
  75. package/lib/node/Interceptor-DJ2akVWI.d.cts +133 -0
  76. package/lib/node/RemoteHttpInterceptor.cjs +154 -0
  77. package/lib/node/RemoteHttpInterceptor.cjs.map +1 -0
  78. package/lib/node/RemoteHttpInterceptor.d.cts +39 -0
  79. package/lib/node/RemoteHttpInterceptor.d.mts +39 -0
  80. package/lib/node/RemoteHttpInterceptor.mjs +145 -186
  81. package/lib/node/RemoteHttpInterceptor.mjs.map +1 -1
  82. package/lib/node/XMLHttpRequest-B7kJdYYI.cjs +763 -0
  83. package/lib/node/XMLHttpRequest-B7kJdYYI.cjs.map +1 -0
  84. package/lib/node/XMLHttpRequest-C8dIZpds.mjs +757 -0
  85. package/lib/node/XMLHttpRequest-C8dIZpds.mjs.map +1 -0
  86. package/lib/node/bufferUtils-DiCTqG-7.cjs +38 -0
  87. package/lib/node/bufferUtils-DiCTqG-7.cjs.map +1 -0
  88. package/lib/node/bufferUtils-_8XfKIfX.mjs +20 -0
  89. package/lib/node/bufferUtils-_8XfKIfX.mjs.map +1 -0
  90. package/lib/node/chunk-CbDLau6x.cjs +34 -0
  91. package/lib/node/fetch-BmXpK10r.cjs +272 -0
  92. package/lib/node/fetch-BmXpK10r.cjs.map +1 -0
  93. package/lib/node/fetch-G1DVwDKG.mjs +265 -0
  94. package/lib/node/fetch-G1DVwDKG.mjs.map +1 -0
  95. package/lib/node/fetchUtils-BaY5iWXw.cjs +419 -0
  96. package/lib/node/fetchUtils-BaY5iWXw.cjs.map +1 -0
  97. package/lib/node/fetchUtils-CoU35g3M.mjs +359 -0
  98. package/lib/node/fetchUtils-CoU35g3M.mjs.map +1 -0
  99. package/lib/node/getRawRequest-BavnMWh_.cjs +36 -0
  100. package/lib/node/getRawRequest-BavnMWh_.cjs.map +1 -0
  101. package/lib/node/getRawRequest-DnwmXyOW.mjs +24 -0
  102. package/lib/node/getRawRequest-DnwmXyOW.mjs.map +1 -0
  103. package/lib/node/glossary-BLKRyLBd.cjs +12 -0
  104. package/lib/node/glossary-BLKRyLBd.cjs.map +1 -0
  105. package/lib/node/glossary-glQBRnVD.mjs +6 -0
  106. package/lib/node/glossary-glQBRnVD.mjs.map +1 -0
  107. package/lib/node/handleRequest-Bb7Y-XLw.cjs +220 -0
  108. package/lib/node/handleRequest-Bb7Y-XLw.cjs.map +1 -0
  109. package/lib/node/handleRequest-Y97UwBbF.mjs +190 -0
  110. package/lib/node/handleRequest-Y97UwBbF.mjs.map +1 -0
  111. package/lib/node/hasConfigurableGlobal-C97fWuaA.cjs +26 -0
  112. package/lib/node/hasConfigurableGlobal-C97fWuaA.cjs.map +1 -0
  113. package/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs +20 -0
  114. package/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs.map +1 -0
  115. package/lib/node/index-BMbJ8FXL.d.cts +113 -0
  116. package/lib/node/index-C0YAQ36w.d.mts +113 -0
  117. package/lib/node/index.cjs +30 -0
  118. package/lib/node/index.cjs.map +1 -0
  119. package/lib/node/index.d.cts +66 -0
  120. package/lib/node/index.d.mts +66 -0
  121. package/lib/node/index.mjs +13 -39
  122. package/lib/node/index.mjs.map +1 -1
  123. package/lib/node/interceptors/ClientRequest/index.cjs +6 -0
  124. package/lib/node/interceptors/ClientRequest/index.d.cts +2 -0
  125. package/lib/node/interceptors/ClientRequest/index.d.mts +3 -0
  126. package/lib/node/interceptors/ClientRequest/index.mjs +6 -11
  127. package/lib/node/interceptors/XMLHttpRequest/index.cjs +6 -0
  128. package/lib/node/interceptors/XMLHttpRequest/index.d.cts +14 -0
  129. package/lib/node/interceptors/XMLHttpRequest/index.d.mts +14 -0
  130. package/lib/node/interceptors/XMLHttpRequest/index.mjs +6 -13
  131. package/lib/node/interceptors/fetch/index.cjs +5 -0
  132. package/lib/node/interceptors/fetch/index.d.cts +12 -0
  133. package/lib/node/interceptors/fetch/index.d.mts +12 -0
  134. package/lib/node/interceptors/fetch/index.mjs +5 -12
  135. package/lib/node/node-DwCc6iuP.mjs +27 -0
  136. package/lib/node/node-DwCc6iuP.mjs.map +1 -0
  137. package/lib/node/node-dKdAf3tC.cjs +39 -0
  138. package/lib/node/node-dKdAf3tC.cjs.map +1 -0
  139. package/lib/node/presets/node.cjs +22 -0
  140. package/lib/node/presets/node.cjs.map +1 -0
  141. package/lib/node/presets/node.d.cts +13 -0
  142. package/lib/node/presets/node.d.mts +15 -0
  143. package/lib/node/presets/node.mjs +18 -23
  144. package/lib/node/presets/node.mjs.map +1 -1
  145. package/lib/node/utils/node/index.cjs +4 -0
  146. package/lib/node/utils/node/{index.d.ts → index.d.cts} +5 -2
  147. package/lib/node/utils/node/index.d.mts +16 -0
  148. package/lib/node/utils/node/index.mjs +3 -10
  149. package/package.json +34 -59
  150. package/presets/browser/package.json +2 -3
  151. package/presets/node/package.json +7 -2
  152. package/src/RemoteHttpInterceptor.ts +18 -13
  153. package/src/RequestController.test.ts +78 -31
  154. package/src/RequestController.ts +63 -39
  155. package/src/index.ts +4 -0
  156. package/src/interceptors/ClientRequest/MockHttpSocket.ts +43 -9
  157. package/src/interceptors/ClientRequest/index.ts +14 -18
  158. package/src/interceptors/ClientRequest/utils/parserUtils.ts +48 -0
  159. package/src/interceptors/WebSocket/index.ts +4 -1
  160. package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +45 -35
  161. package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +24 -21
  162. package/src/interceptors/XMLHttpRequest/utils/getBodyByteLength.test.ts +2 -2
  163. package/src/interceptors/fetch/index.ts +61 -50
  164. package/src/utils/handleRequest.ts +65 -95
  165. package/lib/browser/Interceptor-af98b768.d.ts +0 -63
  166. package/lib/browser/chunk-2HUMWGRD.js +0 -37
  167. package/lib/browser/chunk-2HUMWGRD.js.map +0 -1
  168. package/lib/browser/chunk-2QICSCCS.js +0 -238
  169. package/lib/browser/chunk-2QICSCCS.js.map +0 -1
  170. package/lib/browser/chunk-3RXCRGL2.mjs +0 -117
  171. package/lib/browser/chunk-3RXCRGL2.mjs.map +0 -1
  172. package/lib/browser/chunk-6HYIRFX2.mjs +0 -22
  173. package/lib/browser/chunk-6HYIRFX2.mjs.map +0 -1
  174. package/lib/browser/chunk-E3CCOBRX.js +0 -846
  175. package/lib/browser/chunk-E3CCOBRX.js.map +0 -1
  176. package/lib/browser/chunk-E7UVBHVO.mjs +0 -846
  177. package/lib/browser/chunk-E7UVBHVO.mjs.map +0 -1
  178. package/lib/browser/chunk-H74PGQ4Y.js +0 -296
  179. package/lib/browser/chunk-H74PGQ4Y.js.map +0 -1
  180. package/lib/browser/chunk-LK6DILFK.js +0 -22
  181. package/lib/browser/chunk-LK6DILFK.js.map +0 -1
  182. package/lib/browser/chunk-PTTUYYVR.mjs +0 -238
  183. package/lib/browser/chunk-PTTUYYVR.mjs.map +0 -1
  184. package/lib/browser/chunk-Q7K2XAEP.mjs +0 -296
  185. package/lib/browser/chunk-Q7K2XAEP.mjs.map +0 -1
  186. package/lib/browser/chunk-QED3Q6Z2.mjs +0 -169
  187. package/lib/browser/chunk-QED3Q6Z2.mjs.map +0 -1
  188. package/lib/browser/chunk-T7TBRNJZ.js +0 -117
  189. package/lib/browser/chunk-T7TBRNJZ.js.map +0 -1
  190. package/lib/browser/chunk-TIPR373R.js +0 -169
  191. package/lib/browser/chunk-TIPR373R.js.map +0 -1
  192. package/lib/browser/chunk-VYSDLBSS.mjs +0 -37
  193. package/lib/browser/chunk-VYSDLBSS.mjs.map +0 -1
  194. package/lib/browser/glossary-7152281e.d.ts +0 -69
  195. package/lib/browser/index.d.ts +0 -83
  196. package/lib/browser/index.js +0 -81
  197. package/lib/browser/index.js.map +0 -1
  198. package/lib/browser/interceptors/WebSocket/index.d.ts +0 -271
  199. package/lib/browser/interceptors/WebSocket/index.js +0 -721
  200. package/lib/browser/interceptors/WebSocket/index.js.map +0 -1
  201. package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +0 -15
  202. package/lib/browser/interceptors/XMLHttpRequest/index.js +0 -12
  203. package/lib/browser/interceptors/XMLHttpRequest/index.js.map +0 -1
  204. package/lib/browser/interceptors/XMLHttpRequest/index.mjs.map +0 -1
  205. package/lib/browser/interceptors/fetch/index.d.ts +0 -14
  206. package/lib/browser/interceptors/fetch/index.js +0 -11
  207. package/lib/browser/interceptors/fetch/index.js.map +0 -1
  208. package/lib/browser/interceptors/fetch/index.mjs.map +0 -1
  209. package/lib/browser/presets/browser.d.ts +0 -15
  210. package/lib/browser/presets/browser.js +0 -21
  211. package/lib/browser/presets/browser.js.map +0 -1
  212. package/lib/node/BatchInterceptor-5b72232f.d.ts +0 -24
  213. package/lib/node/Interceptor-bc5a9d8e.d.ts +0 -130
  214. package/lib/node/RemoteHttpInterceptor.d.ts +0 -45
  215. package/lib/node/RemoteHttpInterceptor.js +0 -193
  216. package/lib/node/RemoteHttpInterceptor.js.map +0 -1
  217. package/lib/node/chunk-3CNGDJFB.mjs +0 -313
  218. package/lib/node/chunk-3CNGDJFB.mjs.map +0 -1
  219. package/lib/node/chunk-3GJB4JDF.mjs +0 -14
  220. package/lib/node/chunk-3GJB4JDF.mjs.map +0 -1
  221. package/lib/node/chunk-4NEYTVWD.mjs +0 -848
  222. package/lib/node/chunk-4NEYTVWD.mjs.map +0 -1
  223. package/lib/node/chunk-4YBV77DG.js +0 -32
  224. package/lib/node/chunk-4YBV77DG.js.map +0 -1
  225. package/lib/node/chunk-6HYIRFX2.mjs +0 -22
  226. package/lib/node/chunk-6HYIRFX2.mjs.map +0 -1
  227. package/lib/node/chunk-6YM4PLBI.mjs +0 -7
  228. package/lib/node/chunk-6YM4PLBI.mjs.map +0 -1
  229. package/lib/node/chunk-72ZIHMEB.js +0 -249
  230. package/lib/node/chunk-72ZIHMEB.js.map +0 -1
  231. package/lib/node/chunk-73NOP3T5.js +0 -7
  232. package/lib/node/chunk-73NOP3T5.js.map +0 -1
  233. package/lib/node/chunk-A7Q4RTDJ.mjs +0 -249
  234. package/lib/node/chunk-A7Q4RTDJ.mjs.map +0 -1
  235. package/lib/node/chunk-A7U44ARP.js +0 -268
  236. package/lib/node/chunk-A7U44ARP.js.map +0 -1
  237. package/lib/node/chunk-EKNRB5ZS.mjs +0 -1115
  238. package/lib/node/chunk-EKNRB5ZS.mjs.map +0 -1
  239. package/lib/node/chunk-IHJSPMYM.mjs +0 -268
  240. package/lib/node/chunk-IHJSPMYM.mjs.map +0 -1
  241. package/lib/node/chunk-LK6DILFK.js +0 -22
  242. package/lib/node/chunk-LK6DILFK.js.map +0 -1
  243. package/lib/node/chunk-N4ZZFE24.js +0 -1115
  244. package/lib/node/chunk-N4ZZFE24.js.map +0 -1
  245. package/lib/node/chunk-PFGO5BSM.js +0 -25
  246. package/lib/node/chunk-PFGO5BSM.js.map +0 -1
  247. package/lib/node/chunk-R6JVCM7X.js +0 -51
  248. package/lib/node/chunk-R6JVCM7X.js.map +0 -1
  249. package/lib/node/chunk-RC2XPCC4.mjs +0 -51
  250. package/lib/node/chunk-RC2XPCC4.mjs.map +0 -1
  251. package/lib/node/chunk-SMXZPJEA.js +0 -14
  252. package/lib/node/chunk-SMXZPJEA.js.map +0 -1
  253. package/lib/node/chunk-TJDMZZXE.mjs +0 -32
  254. package/lib/node/chunk-TJDMZZXE.mjs.map +0 -1
  255. package/lib/node/chunk-TX5GBTFY.mjs +0 -25
  256. package/lib/node/chunk-TX5GBTFY.mjs.map +0 -1
  257. package/lib/node/chunk-VV2LUF5K.js +0 -848
  258. package/lib/node/chunk-VV2LUF5K.js.map +0 -1
  259. package/lib/node/chunk-Z5LWCBZS.js +0 -313
  260. package/lib/node/chunk-Z5LWCBZS.js.map +0 -1
  261. package/lib/node/index.d.ts +0 -62
  262. package/lib/node/index.js +0 -43
  263. package/lib/node/index.js.map +0 -1
  264. package/lib/node/interceptors/ClientRequest/index.d.ts +0 -111
  265. package/lib/node/interceptors/ClientRequest/index.js +0 -11
  266. package/lib/node/interceptors/ClientRequest/index.js.map +0 -1
  267. package/lib/node/interceptors/ClientRequest/index.mjs.map +0 -1
  268. package/lib/node/interceptors/XMLHttpRequest/index.d.ts +0 -14
  269. package/lib/node/interceptors/XMLHttpRequest/index.js +0 -13
  270. package/lib/node/interceptors/XMLHttpRequest/index.js.map +0 -1
  271. package/lib/node/interceptors/XMLHttpRequest/index.mjs.map +0 -1
  272. package/lib/node/interceptors/fetch/index.d.ts +0 -13
  273. package/lib/node/interceptors/fetch/index.js +0 -12
  274. package/lib/node/interceptors/fetch/index.js.map +0 -1
  275. package/lib/node/interceptors/fetch/index.mjs.map +0 -1
  276. package/lib/node/presets/node.d.ts +0 -16
  277. package/lib/node/presets/node.js +0 -27
  278. package/lib/node/presets/node.js.map +0 -1
  279. package/lib/node/utils/node/index.js +0 -10
  280. package/lib/node/utils/node/index.js.map +0 -1
  281. package/lib/node/utils/node/index.mjs.map +0 -1
  282. package/src/utils/RequestController.ts +0 -21
@@ -0,0 +1,39 @@
1
+ import { l as HttpRequestEventMap, r as Interceptor } from "./Interceptor-DJ2akVWI.cjs";
2
+ import { t as BatchInterceptor } from "./BatchInterceptor-D_YqR8qU.cjs";
3
+ import { t as ClientRequestInterceptor } from "./index-BMbJ8FXL.cjs";
4
+ import { XMLHttpRequestInterceptor } from "./interceptors/XMLHttpRequest/index.cjs";
5
+ import { FetchInterceptor } from "./interceptors/fetch/index.cjs";
6
+ import { ChildProcess } from "child_process";
7
+
8
+ //#region src/RemoteHttpInterceptor.d.ts
9
+ interface SerializedRequest {
10
+ id: string;
11
+ url: string;
12
+ method: string;
13
+ headers: Array<[string, string]>;
14
+ credentials: RequestCredentials;
15
+ body: string;
16
+ }
17
+ interface SerializedResponse {
18
+ status: number;
19
+ statusText: string;
20
+ headers: Array<[string, string]>;
21
+ body: string;
22
+ }
23
+ declare class RemoteHttpInterceptor extends BatchInterceptor<[ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor]> {
24
+ constructor();
25
+ protected setup(): void;
26
+ }
27
+ declare function requestReviver(key: string, value: any): any;
28
+ interface RemoveResolverOptions {
29
+ process: ChildProcess;
30
+ }
31
+ declare class RemoteHttpResolver extends Interceptor<HttpRequestEventMap> {
32
+ static symbol: symbol;
33
+ private process;
34
+ constructor(options: RemoveResolverOptions);
35
+ protected setup(): void;
36
+ }
37
+ //#endregion
38
+ export { RemoteHttpInterceptor, RemoteHttpResolver, RemoveResolverOptions, SerializedRequest, SerializedResponse, requestReviver };
39
+ //# sourceMappingURL=RemoteHttpInterceptor.d.cts.map
@@ -0,0 +1,39 @@
1
+ import { l as HttpRequestEventMap, r as Interceptor } from "./Interceptor-DEazpLJd.mjs";
2
+ import { t as BatchInterceptor } from "./BatchInterceptor-D7mXzHcQ.mjs";
3
+ import { t as ClientRequestInterceptor } from "./index-C0YAQ36w.mjs";
4
+ import { XMLHttpRequestInterceptor } from "./interceptors/XMLHttpRequest/index.mjs";
5
+ import { FetchInterceptor } from "./interceptors/fetch/index.mjs";
6
+ import { ChildProcess } from "child_process";
7
+
8
+ //#region src/RemoteHttpInterceptor.d.ts
9
+ interface SerializedRequest {
10
+ id: string;
11
+ url: string;
12
+ method: string;
13
+ headers: Array<[string, string]>;
14
+ credentials: RequestCredentials;
15
+ body: string;
16
+ }
17
+ interface SerializedResponse {
18
+ status: number;
19
+ statusText: string;
20
+ headers: Array<[string, string]>;
21
+ body: string;
22
+ }
23
+ declare class RemoteHttpInterceptor extends BatchInterceptor<[ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor]> {
24
+ constructor();
25
+ protected setup(): void;
26
+ }
27
+ declare function requestReviver(key: string, value: any): any;
28
+ interface RemoveResolverOptions {
29
+ process: ChildProcess;
30
+ }
31
+ declare class RemoteHttpResolver extends Interceptor<HttpRequestEventMap> {
32
+ static symbol: symbol;
33
+ private process;
34
+ constructor(options: RemoveResolverOptions);
35
+ protected setup(): void;
36
+ }
37
+ //#endregion
38
+ export { RemoteHttpInterceptor, RemoteHttpResolver, RemoveResolverOptions, SerializedRequest, SerializedResponse, requestReviver };
39
+ //# sourceMappingURL=RemoteHttpInterceptor.d.mts.map
@@ -1,193 +1,152 @@
1
- import {
2
- BatchInterceptor
3
- } from "./chunk-RC2XPCC4.mjs";
4
- import {
5
- ClientRequestInterceptor
6
- } from "./chunk-EKNRB5ZS.mjs";
7
- import "./chunk-TJDMZZXE.mjs";
8
- import {
9
- XMLHttpRequestInterceptor
10
- } from "./chunk-4NEYTVWD.mjs";
11
- import "./chunk-6HYIRFX2.mjs";
12
- import {
13
- FetchInterceptor
14
- } from "./chunk-3CNGDJFB.mjs";
15
- import "./chunk-TX5GBTFY.mjs";
16
- import "./chunk-6YM4PLBI.mjs";
17
- import {
18
- RequestController,
19
- handleRequest
20
- } from "./chunk-A7Q4RTDJ.mjs";
21
- import {
22
- FetchResponse,
23
- Interceptor
24
- } from "./chunk-IHJSPMYM.mjs";
25
- import "./chunk-3GJB4JDF.mjs";
1
+ import { i as RequestController, s as Interceptor, t as FetchResponse } from "./fetchUtils-CoU35g3M.mjs";
2
+ import { t as BatchInterceptor } from "./BatchInterceptor-DFaBPilf.mjs";
3
+ import "./bufferUtils-_8XfKIfX.mjs";
4
+ import { t as ClientRequestInterceptor } from "./ClientRequest-Ca8Qykuv.mjs";
5
+ import { n as isResponseError, t as handleRequest } from "./handleRequest-Y97UwBbF.mjs";
6
+ import "./node-DwCc6iuP.mjs";
7
+ import { t as XMLHttpRequestInterceptor } from "./XMLHttpRequest-C8dIZpds.mjs";
8
+ import { t as FetchInterceptor } from "./fetch-G1DVwDKG.mjs";
26
9
 
27
- // src/RemoteHttpInterceptor.ts
10
+ //#region src/RemoteHttpInterceptor.ts
28
11
  var RemoteHttpInterceptor = class extends BatchInterceptor {
29
- constructor() {
30
- super({
31
- name: "remote-interceptor",
32
- interceptors: [
33
- new ClientRequestInterceptor(),
34
- new XMLHttpRequestInterceptor(),
35
- new FetchInterceptor()
36
- ]
37
- });
38
- }
39
- setup() {
40
- super.setup();
41
- let handleParentMessage;
42
- this.on("request", async ({ request, requestId, controller }) => {
43
- var _a;
44
- const serializedRequest = JSON.stringify({
45
- id: requestId,
46
- method: request.method,
47
- url: request.url,
48
- headers: Array.from(request.headers.entries()),
49
- credentials: request.credentials,
50
- body: ["GET", "HEAD"].includes(request.method) ? null : await request.text()
51
- });
52
- this.logger.info(
53
- "sent serialized request to the child:",
54
- serializedRequest
55
- );
56
- (_a = process.send) == null ? void 0 : _a.call(process, `request:${serializedRequest}`);
57
- const responsePromise = new Promise((resolve) => {
58
- handleParentMessage = (message) => {
59
- if (typeof message !== "string") {
60
- return resolve();
61
- }
62
- if (message.startsWith(`response:${requestId}`)) {
63
- const [, serializedResponse] = message.match(/^response:.+?:(.+)$/) || [];
64
- if (!serializedResponse) {
65
- return resolve();
66
- }
67
- const responseInit = JSON.parse(
68
- serializedResponse
69
- );
70
- const mockedResponse = new FetchResponse(responseInit.body, {
71
- url: request.url,
72
- status: responseInit.status,
73
- statusText: responseInit.statusText,
74
- headers: responseInit.headers
75
- });
76
- controller.respondWith(mockedResponse);
77
- return resolve();
78
- }
79
- };
80
- });
81
- this.logger.info(
82
- 'add "message" listener to the parent process',
83
- handleParentMessage
84
- );
85
- process.addListener("message", handleParentMessage);
86
- return responsePromise;
87
- });
88
- this.subscriptions.push(() => {
89
- process.removeListener("message", handleParentMessage);
90
- });
91
- }
12
+ constructor() {
13
+ super({
14
+ name: "remote-interceptor",
15
+ interceptors: [
16
+ new ClientRequestInterceptor(),
17
+ new XMLHttpRequestInterceptor(),
18
+ new FetchInterceptor()
19
+ ]
20
+ });
21
+ }
22
+ setup() {
23
+ super.setup();
24
+ let handleParentMessage;
25
+ this.on("request", async ({ request, requestId, controller }) => {
26
+ const serializedRequest = JSON.stringify({
27
+ id: requestId,
28
+ method: request.method,
29
+ url: request.url,
30
+ headers: Array.from(request.headers.entries()),
31
+ credentials: request.credentials,
32
+ body: ["GET", "HEAD"].includes(request.method) ? null : await request.text()
33
+ });
34
+ this.logger.info("sent serialized request to the child:", serializedRequest);
35
+ process.send?.(`request:${serializedRequest}`);
36
+ const responsePromise = new Promise((resolve) => {
37
+ handleParentMessage = (message) => {
38
+ if (typeof message !== "string") return resolve();
39
+ if (message.startsWith(`response:${requestId}`)) {
40
+ const [, serializedResponse] = message.match(/^response:.+?:(.+)$/) || [];
41
+ if (!serializedResponse) return resolve();
42
+ const responseInit = JSON.parse(serializedResponse);
43
+ const mockedResponse = new FetchResponse(responseInit.body, {
44
+ url: request.url,
45
+ status: responseInit.status,
46
+ statusText: responseInit.statusText,
47
+ headers: responseInit.headers
48
+ });
49
+ /**
50
+ * @todo Support "errorWith" as well.
51
+ * This response handling from the child is incomplete.
52
+ */
53
+ controller.respondWith(mockedResponse);
54
+ return resolve();
55
+ }
56
+ };
57
+ });
58
+ this.logger.info("add \"message\" listener to the parent process", handleParentMessage);
59
+ process.addListener("message", handleParentMessage);
60
+ return responsePromise;
61
+ });
62
+ this.subscriptions.push(() => {
63
+ process.removeListener("message", handleParentMessage);
64
+ });
65
+ }
92
66
  };
93
67
  function requestReviver(key, value) {
94
- switch (key) {
95
- case "url":
96
- return new URL(value);
97
- case "headers":
98
- return new Headers(value);
99
- default:
100
- return value;
101
- }
68
+ switch (key) {
69
+ case "url": return new URL(value);
70
+ case "headers": return new Headers(value);
71
+ default: return value;
72
+ }
102
73
  }
103
- var _RemoteHttpResolver = class extends Interceptor {
104
- constructor(options) {
105
- super(_RemoteHttpResolver.symbol);
106
- this.process = options.process;
107
- }
108
- setup() {
109
- const logger = this.logger.extend("setup");
110
- const handleChildMessage = async (message) => {
111
- logger.info("received message from child!", message);
112
- if (typeof message !== "string" || !message.startsWith("request:")) {
113
- logger.info("unknown message, ignoring...");
114
- return;
115
- }
116
- const [, serializedRequest] = message.match(/^request:(.+)$/) || [];
117
- if (!serializedRequest) {
118
- return;
119
- }
120
- const requestJson = JSON.parse(
121
- serializedRequest,
122
- requestReviver
123
- );
124
- logger.info("parsed intercepted request", requestJson);
125
- const request = new Request(requestJson.url, {
126
- method: requestJson.method,
127
- headers: new Headers(requestJson.headers),
128
- credentials: requestJson.credentials,
129
- body: requestJson.body
130
- });
131
- const controller = new RequestController(request);
132
- await handleRequest({
133
- request,
134
- requestId: requestJson.id,
135
- controller,
136
- emitter: this.emitter,
137
- onResponse: async (response) => {
138
- this.logger.info("received mocked response!", { response });
139
- const responseClone = response.clone();
140
- const responseText = await responseClone.text();
141
- const serializedResponse = JSON.stringify({
142
- status: response.status,
143
- statusText: response.statusText,
144
- headers: Array.from(response.headers.entries()),
145
- body: responseText
146
- });
147
- this.process.send(
148
- `response:${requestJson.id}:${serializedResponse}`,
149
- (error) => {
150
- if (error) {
151
- return;
152
- }
153
- this.emitter.emit("response", {
154
- request,
155
- requestId: requestJson.id,
156
- response: responseClone,
157
- isMockedResponse: true
158
- });
159
- }
160
- );
161
- logger.info(
162
- "sent serialized mocked response to the parent:",
163
- serializedResponse
164
- );
165
- },
166
- onRequestError: (response) => {
167
- this.logger.info("received a network error!", { response });
168
- throw new Error("Not implemented");
169
- },
170
- onError: (error) => {
171
- this.logger.info("request has errored!", { error });
172
- throw new Error("Not implemented");
173
- }
174
- });
175
- };
176
- this.subscriptions.push(() => {
177
- this.process.removeListener("message", handleChildMessage);
178
- logger.info('removed the "message" listener from the child process!');
179
- });
180
- logger.info('adding a "message" listener to the child process');
181
- this.process.addListener("message", handleChildMessage);
182
- this.process.once("error", () => this.dispose());
183
- this.process.once("exit", () => this.dispose());
184
- }
185
- };
186
- var RemoteHttpResolver = _RemoteHttpResolver;
187
- RemoteHttpResolver.symbol = Symbol("remote-resolver");
188
- export {
189
- RemoteHttpInterceptor,
190
- RemoteHttpResolver,
191
- requestReviver
74
+ var RemoteHttpResolver = class RemoteHttpResolver extends Interceptor {
75
+ static {
76
+ this.symbol = Symbol("remote-resolver");
77
+ }
78
+ constructor(options) {
79
+ super(RemoteHttpResolver.symbol);
80
+ this.process = options.process;
81
+ }
82
+ setup() {
83
+ const logger = this.logger.extend("setup");
84
+ const handleChildMessage = async (message) => {
85
+ logger.info("received message from child!", message);
86
+ if (typeof message !== "string" || !message.startsWith("request:")) {
87
+ logger.info("unknown message, ignoring...");
88
+ return;
89
+ }
90
+ const [, serializedRequest] = message.match(/^request:(.+)$/) || [];
91
+ if (!serializedRequest) return;
92
+ const requestJson = JSON.parse(serializedRequest, requestReviver);
93
+ logger.info("parsed intercepted request", requestJson);
94
+ const request = new Request(requestJson.url, {
95
+ method: requestJson.method,
96
+ headers: new Headers(requestJson.headers),
97
+ credentials: requestJson.credentials,
98
+ body: requestJson.body
99
+ });
100
+ const controller = new RequestController(request, {
101
+ passthrough: () => {},
102
+ respondWith: async (response) => {
103
+ if (isResponseError(response)) {
104
+ this.logger.info("received a network error!", { response });
105
+ throw new Error("Not implemented");
106
+ }
107
+ this.logger.info("received mocked response!", { response });
108
+ const responseClone = response.clone();
109
+ const responseText = await responseClone.text();
110
+ const serializedResponse = JSON.stringify({
111
+ status: response.status,
112
+ statusText: response.statusText,
113
+ headers: Array.from(response.headers.entries()),
114
+ body: responseText
115
+ });
116
+ this.process.send(`response:${requestJson.id}:${serializedResponse}`, (error) => {
117
+ if (error) return;
118
+ this.emitter.emit("response", {
119
+ request,
120
+ requestId: requestJson.id,
121
+ response: responseClone,
122
+ isMockedResponse: true
123
+ });
124
+ });
125
+ logger.info("sent serialized mocked response to the parent:", serializedResponse);
126
+ },
127
+ errorWith: (reason) => {
128
+ this.logger.info("request has errored!", { error: reason });
129
+ throw new Error("Not implemented");
130
+ }
131
+ });
132
+ await handleRequest({
133
+ request,
134
+ requestId: requestJson.id,
135
+ controller,
136
+ emitter: this.emitter
137
+ });
138
+ };
139
+ this.subscriptions.push(() => {
140
+ this.process.removeListener("message", handleChildMessage);
141
+ logger.info("removed the \"message\" listener from the child process!");
142
+ });
143
+ logger.info("adding a \"message\" listener to the child process");
144
+ this.process.addListener("message", handleChildMessage);
145
+ this.process.once("error", () => this.dispose());
146
+ this.process.once("exit", () => this.dispose());
147
+ }
192
148
  };
149
+
150
+ //#endregion
151
+ export { RemoteHttpInterceptor, RemoteHttpResolver, requestReviver };
193
152
  //# sourceMappingURL=RemoteHttpInterceptor.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/RemoteHttpInterceptor.ts"],"sourcesContent":["import { ChildProcess } from 'child_process'\nimport { HttpRequestEventMap } from './glossary'\nimport { Interceptor } from './Interceptor'\nimport { BatchInterceptor } from './BatchInterceptor'\nimport { ClientRequestInterceptor } from './interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from './interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from './interceptors/fetch'\nimport { handleRequest } from './utils/handleRequest'\nimport { RequestController } from './RequestController'\nimport { FetchResponse } from './utils/fetchUtils'\n\nexport interface SerializedRequest {\n id: string\n url: string\n method: string\n headers: Array<[string, string]>\n credentials: RequestCredentials\n body: string\n}\n\ninterface RevivedRequest extends Omit<SerializedRequest, 'url' | 'headers'> {\n url: URL\n headers: Headers\n}\n\nexport interface SerializedResponse {\n status: number\n statusText: string\n headers: Array<[string, string]>\n body: string\n}\n\nexport class RemoteHttpInterceptor extends BatchInterceptor<\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor]\n> {\n constructor() {\n super({\n name: 'remote-interceptor',\n interceptors: [\n new ClientRequestInterceptor(),\n new XMLHttpRequestInterceptor(),\n new FetchInterceptor(),\n ],\n })\n }\n\n protected setup() {\n super.setup()\n\n let handleParentMessage: NodeJS.MessageListener\n\n this.on('request', async ({ request, requestId, controller }) => {\n // Send the stringified intercepted request to\n // the parent process where the remote resolver is established.\n const serializedRequest = JSON.stringify({\n id: requestId,\n method: request.method,\n url: request.url,\n headers: Array.from(request.headers.entries()),\n credentials: request.credentials,\n body: ['GET', 'HEAD'].includes(request.method)\n ? null\n : await request.text(),\n } as SerializedRequest)\n\n this.logger.info(\n 'sent serialized request to the child:',\n serializedRequest\n )\n\n process.send?.(`request:${serializedRequest}`)\n\n const responsePromise = new Promise<void>((resolve) => {\n handleParentMessage = (message) => {\n if (typeof message !== 'string') {\n return resolve()\n }\n\n if (message.startsWith(`response:${requestId}`)) {\n const [, serializedResponse] =\n message.match(/^response:.+?:(.+)$/) || []\n\n if (!serializedResponse) {\n return resolve()\n }\n\n const responseInit = JSON.parse(\n serializedResponse\n ) as SerializedResponse\n\n const mockedResponse = new FetchResponse(responseInit.body, {\n url: request.url,\n status: responseInit.status,\n statusText: responseInit.statusText,\n headers: responseInit.headers,\n })\n\n /**\n * @todo Support \"errorWith\" as well.\n * This response handling from the child is incomplete.\n */\n\n controller.respondWith(mockedResponse)\n return resolve()\n }\n }\n })\n\n // Listen for the mocked response message from the parent.\n this.logger.info(\n 'add \"message\" listener to the parent process',\n handleParentMessage\n )\n process.addListener('message', handleParentMessage)\n\n return responsePromise\n })\n\n this.subscriptions.push(() => {\n process.removeListener('message', handleParentMessage)\n })\n }\n}\n\nexport function requestReviver(key: string, value: any) {\n switch (key) {\n case 'url':\n return new URL(value)\n\n case 'headers':\n return new Headers(value)\n\n default:\n return value\n }\n}\n\nexport interface RemoveResolverOptions {\n process: ChildProcess\n}\n\nexport class RemoteHttpResolver extends Interceptor<HttpRequestEventMap> {\n static symbol = Symbol('remote-resolver')\n private process: ChildProcess\n\n constructor(options: RemoveResolverOptions) {\n super(RemoteHttpResolver.symbol)\n this.process = options.process\n }\n\n protected setup() {\n const logger = this.logger.extend('setup')\n\n const handleChildMessage: NodeJS.MessageListener = async (message) => {\n logger.info('received message from child!', message)\n\n if (typeof message !== 'string' || !message.startsWith('request:')) {\n logger.info('unknown message, ignoring...')\n return\n }\n\n const [, serializedRequest] = message.match(/^request:(.+)$/) || []\n if (!serializedRequest) {\n return\n }\n\n const requestJson = JSON.parse(\n serializedRequest,\n requestReviver\n ) as RevivedRequest\n\n logger.info('parsed intercepted request', requestJson)\n\n const request = new Request(requestJson.url, {\n method: requestJson.method,\n headers: new Headers(requestJson.headers),\n credentials: requestJson.credentials,\n body: requestJson.body,\n })\n\n const controller = new RequestController(request)\n await handleRequest({\n request,\n requestId: requestJson.id,\n controller,\n emitter: this.emitter,\n onResponse: async (response) => {\n this.logger.info('received mocked response!', { response })\n\n const responseClone = response.clone()\n const responseText = await responseClone.text()\n\n // // Send the mocked response to the child process.\n const serializedResponse = JSON.stringify({\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n body: responseText,\n } as SerializedResponse)\n\n this.process.send(\n `response:${requestJson.id}:${serializedResponse}`,\n (error) => {\n if (error) {\n return\n }\n\n // Emit an optimistic \"response\" event at this point,\n // not to rely on the back-and-forth signaling for the sake of the event.\n this.emitter.emit('response', {\n request,\n requestId: requestJson.id,\n response: responseClone,\n isMockedResponse: true,\n })\n }\n )\n\n logger.info(\n 'sent serialized mocked response to the parent:',\n serializedResponse\n )\n },\n onRequestError: (response) => {\n this.logger.info('received a network error!', { response })\n throw new Error('Not implemented')\n },\n onError: (error) => {\n this.logger.info('request has errored!', { error })\n throw new Error('Not implemented')\n },\n })\n }\n\n this.subscriptions.push(() => {\n this.process.removeListener('message', handleChildMessage)\n logger.info('removed the \"message\" listener from the child process!')\n })\n\n logger.info('adding a \"message\" listener to the child process')\n this.process.addListener('message', handleChildMessage)\n\n this.process.once('error', () => this.dispose())\n this.process.once('exit', () => this.dispose())\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCO,IAAM,wBAAN,cAAoC,iBAEzC;AAAA,EACA,cAAc;AACZ,UAAM;AAAA,MACJ,MAAM;AAAA,MACN,cAAc;AAAA,QACZ,IAAI,yBAAyB;AAAA,QAC7B,IAAI,0BAA0B;AAAA,QAC9B,IAAI,iBAAiB;AAAA,MACvB;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEU,QAAQ;AAChB,UAAM,MAAM;AAEZ,QAAI;AAEJ,SAAK,GAAG,WAAW,OAAO,EAAE,SAAS,WAAW,WAAW,MAAM;AAnDrE;AAsDM,YAAM,oBAAoB,KAAK,UAAU;AAAA,QACvC,IAAI;AAAA,QACJ,QAAQ,QAAQ;AAAA,QAChB,KAAK,QAAQ;AAAA,QACb,SAAS,MAAM,KAAK,QAAQ,QAAQ,QAAQ,CAAC;AAAA,QAC7C,aAAa,QAAQ;AAAA,QACrB,MAAM,CAAC,OAAO,MAAM,EAAE,SAAS,QAAQ,MAAM,IACzC,OACA,MAAM,QAAQ,KAAK;AAAA,MACzB,CAAsB;AAEtB,WAAK,OAAO;AAAA,QACV;AAAA,QACA;AAAA,MACF;AAEA,oBAAQ,SAAR,iCAAe,WAAW;AAE1B,YAAM,kBAAkB,IAAI,QAAc,CAAC,YAAY;AACrD,8BAAsB,CAAC,YAAY;AACjC,cAAI,OAAO,YAAY,UAAU;AAC/B,mBAAO,QAAQ;AAAA,UACjB;AAEA,cAAI,QAAQ,WAAW,YAAY,WAAW,GAAG;AAC/C,kBAAM,CAAC,EAAE,kBAAkB,IACzB,QAAQ,MAAM,qBAAqB,KAAK,CAAC;AAE3C,gBAAI,CAAC,oBAAoB;AACvB,qBAAO,QAAQ;AAAA,YACjB;AAEA,kBAAM,eAAe,KAAK;AAAA,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SAAK,cAAc,KAAK,MAAM;AAC5B,WAAK,QAAQ,eAAe,WAAW,kBAAkB;AACzD,aAAO,KAAK,wDAAwD;AAAA,IACtE,CAAC;AAED,WAAO,KAAK,kDAAkD;AAC9D,SAAK,QAAQ,YAAY,WAAW,kBAAkB;AAEtD,SAAK,QAAQ,KAAK,SAAS,MAAM,KAAK,QAAQ,CAAC;AAC/C,SAAK,QAAQ,KAAK,QAAQ,MAAM,KAAK,QAAQ,CAAC;AAAA,EAChD;AACF;AAxGO,IAAM,qBAAN;AAAM,mBACJ,SAAS,OAAO,iBAAiB;","names":[]}
1
+ {"version":3,"file":"RemoteHttpInterceptor.mjs","names":["handleParentMessage: NodeJS.MessageListener","handleChildMessage: NodeJS.MessageListener"],"sources":["../../src/RemoteHttpInterceptor.ts"],"sourcesContent":["import { ChildProcess } from 'child_process'\nimport { HttpRequestEventMap } from './glossary'\nimport { Interceptor } from './Interceptor'\nimport { BatchInterceptor } from './BatchInterceptor'\nimport { ClientRequestInterceptor } from './interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from './interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from './interceptors/fetch'\nimport { handleRequest } from './utils/handleRequest'\nimport { RequestController } from './RequestController'\nimport { FetchResponse } from './utils/fetchUtils'\nimport { isResponseError } from './utils/responseUtils'\n\nexport interface SerializedRequest {\n id: string\n url: string\n method: string\n headers: Array<[string, string]>\n credentials: RequestCredentials\n body: string\n}\n\ninterface RevivedRequest extends Omit<SerializedRequest, 'url' | 'headers'> {\n url: URL\n headers: Headers\n}\n\nexport interface SerializedResponse {\n status: number\n statusText: string\n headers: Array<[string, string]>\n body: string\n}\n\nexport class RemoteHttpInterceptor extends BatchInterceptor<\n [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor]\n> {\n constructor() {\n super({\n name: 'remote-interceptor',\n interceptors: [\n new ClientRequestInterceptor(),\n new XMLHttpRequestInterceptor(),\n new FetchInterceptor(),\n ],\n })\n }\n\n protected setup() {\n super.setup()\n\n let handleParentMessage: NodeJS.MessageListener\n\n this.on('request', async ({ request, requestId, controller }) => {\n // Send the stringified intercepted request to\n // the parent process where the remote resolver is established.\n const serializedRequest = JSON.stringify({\n id: requestId,\n method: request.method,\n url: request.url,\n headers: Array.from(request.headers.entries()),\n credentials: request.credentials,\n body: ['GET', 'HEAD'].includes(request.method)\n ? null\n : await request.text(),\n } as SerializedRequest)\n\n this.logger.info(\n 'sent serialized request to the child:',\n serializedRequest\n )\n\n process.send?.(`request:${serializedRequest}`)\n\n const responsePromise = new Promise<void>((resolve) => {\n handleParentMessage = (message) => {\n if (typeof message !== 'string') {\n return resolve()\n }\n\n if (message.startsWith(`response:${requestId}`)) {\n const [, serializedResponse] =\n message.match(/^response:.+?:(.+)$/) || []\n\n if (!serializedResponse) {\n return resolve()\n }\n\n const responseInit = JSON.parse(\n serializedResponse\n ) as SerializedResponse\n\n const mockedResponse = new FetchResponse(responseInit.body, {\n url: request.url,\n status: responseInit.status,\n statusText: responseInit.statusText,\n headers: responseInit.headers,\n })\n\n /**\n * @todo Support \"errorWith\" as well.\n * This response handling from the child is incomplete.\n */\n\n controller.respondWith(mockedResponse)\n return resolve()\n }\n }\n })\n\n // Listen for the mocked response message from the parent.\n this.logger.info(\n 'add \"message\" listener to the parent process',\n handleParentMessage\n )\n process.addListener('message', handleParentMessage)\n\n return responsePromise\n })\n\n this.subscriptions.push(() => {\n process.removeListener('message', handleParentMessage)\n })\n }\n}\n\nexport function requestReviver(key: string, value: any) {\n switch (key) {\n case 'url':\n return new URL(value)\n\n case 'headers':\n return new Headers(value)\n\n default:\n return value\n }\n}\n\nexport interface RemoveResolverOptions {\n process: ChildProcess\n}\n\nexport class RemoteHttpResolver extends Interceptor<HttpRequestEventMap> {\n static symbol = Symbol('remote-resolver')\n private process: ChildProcess\n\n constructor(options: RemoveResolverOptions) {\n super(RemoteHttpResolver.symbol)\n this.process = options.process\n }\n\n protected setup() {\n const logger = this.logger.extend('setup')\n\n const handleChildMessage: NodeJS.MessageListener = async (message) => {\n logger.info('received message from child!', message)\n\n if (typeof message !== 'string' || !message.startsWith('request:')) {\n logger.info('unknown message, ignoring...')\n return\n }\n\n const [, serializedRequest] = message.match(/^request:(.+)$/) || []\n if (!serializedRequest) {\n return\n }\n\n const requestJson = JSON.parse(\n serializedRequest,\n requestReviver\n ) as RevivedRequest\n\n logger.info('parsed intercepted request', requestJson)\n\n const request = new Request(requestJson.url, {\n method: requestJson.method,\n headers: new Headers(requestJson.headers),\n credentials: requestJson.credentials,\n body: requestJson.body,\n })\n\n const controller = new RequestController(request, {\n passthrough: () => {},\n respondWith: async (response) => {\n if (isResponseError(response)) {\n this.logger.info('received a network error!', { response })\n throw new Error('Not implemented')\n }\n\n this.logger.info('received mocked response!', { response })\n\n const responseClone = response.clone()\n const responseText = await responseClone.text()\n\n // // Send the mocked response to the child process.\n const serializedResponse = JSON.stringify({\n status: response.status,\n statusText: response.statusText,\n headers: Array.from(response.headers.entries()),\n body: responseText,\n } as SerializedResponse)\n\n this.process.send(\n `response:${requestJson.id}:${serializedResponse}`,\n (error) => {\n if (error) {\n return\n }\n\n // Emit an optimistic \"response\" event at this point,\n // not to rely on the back-and-forth signaling for the sake of the event.\n this.emitter.emit('response', {\n request,\n requestId: requestJson.id,\n response: responseClone,\n isMockedResponse: true,\n })\n }\n )\n\n logger.info(\n 'sent serialized mocked response to the parent:',\n serializedResponse\n )\n },\n errorWith: (reason) => {\n this.logger.info('request has errored!', { error: reason })\n throw new Error('Not implemented')\n },\n })\n\n await handleRequest({\n request,\n requestId: requestJson.id,\n controller,\n emitter: this.emitter,\n })\n }\n\n this.subscriptions.push(() => {\n this.process.removeListener('message', handleChildMessage)\n logger.info('removed the \"message\" listener from the child process!')\n })\n\n logger.info('adding a \"message\" listener to the child process')\n this.process.addListener('message', handleChildMessage)\n\n this.process.once('error', () => this.dispose())\n this.process.once('exit', () => this.dispose())\n }\n}\n"],"mappings":";;;;;;;;;;AAiCA,IAAa,wBAAb,c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