@mswjs/interceptors 0.40.0 → 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 (272) 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 -77
  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 -190
  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 -41
  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 +33 -59
  150. package/presets/browser/package.json +2 -3
  151. package/presets/node/package.json +7 -2
  152. package/src/interceptors/ClientRequest/MockHttpSocket.ts +21 -8
  153. package/src/interceptors/ClientRequest/utils/parserUtils.ts +48 -0
  154. package/src/interceptors/WebSocket/index.ts +4 -1
  155. package/src/interceptors/XMLHttpRequest/utils/getBodyByteLength.test.ts +2 -2
  156. package/lib/browser/Interceptor-af98b768.d.ts +0 -63
  157. package/lib/browser/chunk-2HUMWGRD.js +0 -37
  158. package/lib/browser/chunk-2HUMWGRD.js.map +0 -1
  159. package/lib/browser/chunk-2MCNQOY3.js +0 -851
  160. package/lib/browser/chunk-2MCNQOY3.js.map +0 -1
  161. package/lib/browser/chunk-57RIRQUY.js +0 -218
  162. package/lib/browser/chunk-57RIRQUY.js.map +0 -1
  163. package/lib/browser/chunk-6HYIRFX2.mjs +0 -22
  164. package/lib/browser/chunk-6HYIRFX2.mjs.map +0 -1
  165. package/lib/browser/chunk-FW45TRCB.js +0 -178
  166. package/lib/browser/chunk-FW45TRCB.js.map +0 -1
  167. package/lib/browser/chunk-JQ2S7G56.js +0 -185
  168. package/lib/browser/chunk-JQ2S7G56.js.map +0 -1
  169. package/lib/browser/chunk-LIKZF2VU.mjs +0 -218
  170. package/lib/browser/chunk-LIKZF2VU.mjs.map +0 -1
  171. package/lib/browser/chunk-LK6DILFK.js +0 -22
  172. package/lib/browser/chunk-LK6DILFK.js.map +0 -1
  173. package/lib/browser/chunk-MNT2FUCH.js +0 -301
  174. package/lib/browser/chunk-MNT2FUCH.js.map +0 -1
  175. package/lib/browser/chunk-VOUOVDAW.mjs +0 -178
  176. package/lib/browser/chunk-VOUOVDAW.mjs.map +0 -1
  177. package/lib/browser/chunk-VYSDLBSS.mjs +0 -37
  178. package/lib/browser/chunk-VYSDLBSS.mjs.map +0 -1
  179. package/lib/browser/chunk-WADP6VHN.mjs +0 -851
  180. package/lib/browser/chunk-WADP6VHN.mjs.map +0 -1
  181. package/lib/browser/chunk-WOWPV4GR.mjs +0 -301
  182. package/lib/browser/chunk-WOWPV4GR.mjs.map +0 -1
  183. package/lib/browser/chunk-Z5TSB3T6.mjs +0 -185
  184. package/lib/browser/chunk-Z5TSB3T6.mjs.map +0 -1
  185. package/lib/browser/glossary-f7ee1c9d.d.ts +0 -74
  186. package/lib/browser/index.d.ts +0 -82
  187. package/lib/browser/index.js +0 -83
  188. package/lib/browser/index.js.map +0 -1
  189. package/lib/browser/interceptors/WebSocket/index.d.ts +0 -271
  190. package/lib/browser/interceptors/WebSocket/index.js +0 -721
  191. package/lib/browser/interceptors/WebSocket/index.js.map +0 -1
  192. package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +0 -14
  193. package/lib/browser/interceptors/XMLHttpRequest/index.js +0 -12
  194. package/lib/browser/interceptors/XMLHttpRequest/index.js.map +0 -1
  195. package/lib/browser/interceptors/XMLHttpRequest/index.mjs.map +0 -1
  196. package/lib/browser/interceptors/fetch/index.d.ts +0 -13
  197. package/lib/browser/interceptors/fetch/index.js +0 -11
  198. package/lib/browser/interceptors/fetch/index.js.map +0 -1
  199. package/lib/browser/interceptors/fetch/index.mjs.map +0 -1
  200. package/lib/browser/presets/browser.d.ts +0 -14
  201. package/lib/browser/presets/browser.js +0 -21
  202. package/lib/browser/presets/browser.js.map +0 -1
  203. package/lib/node/BatchInterceptor-cb9a2eee.d.ts +0 -24
  204. package/lib/node/Interceptor-dc0a39b5.d.ts +0 -136
  205. package/lib/node/RemoteHttpInterceptor.d.ts +0 -44
  206. package/lib/node/RemoteHttpInterceptor.js +0 -197
  207. package/lib/node/RemoteHttpInterceptor.js.map +0 -1
  208. package/lib/node/chunk-5UGIB6OX.mjs +0 -1126
  209. package/lib/node/chunk-5UGIB6OX.mjs.map +0 -1
  210. package/lib/node/chunk-5V3SIIW2.mjs +0 -853
  211. package/lib/node/chunk-5V3SIIW2.mjs.map +0 -1
  212. package/lib/node/chunk-6B3ZQOO2.js +0 -853
  213. package/lib/node/chunk-6B3ZQOO2.js.map +0 -1
  214. package/lib/node/chunk-6HYIRFX2.mjs +0 -22
  215. package/lib/node/chunk-6HYIRFX2.mjs.map +0 -1
  216. package/lib/node/chunk-6YM4PLBI.mjs +0 -7
  217. package/lib/node/chunk-6YM4PLBI.mjs.map +0 -1
  218. package/lib/node/chunk-73NOP3T5.js +0 -7
  219. package/lib/node/chunk-73NOP3T5.js.map +0 -1
  220. package/lib/node/chunk-7Q53NNPV.js +0 -189
  221. package/lib/node/chunk-7Q53NNPV.js.map +0 -1
  222. package/lib/node/chunk-DOWWQYXZ.js +0 -369
  223. package/lib/node/chunk-DOWWQYXZ.js.map +0 -1
  224. package/lib/node/chunk-FRZQJNBO.js +0 -318
  225. package/lib/node/chunk-FRZQJNBO.js.map +0 -1
  226. package/lib/node/chunk-GKN5RBVR.mjs +0 -32
  227. package/lib/node/chunk-GKN5RBVR.mjs.map +0 -1
  228. package/lib/node/chunk-J5MULIHT.js +0 -51
  229. package/lib/node/chunk-J5MULIHT.js.map +0 -1
  230. package/lib/node/chunk-JXGB54LE.mjs +0 -369
  231. package/lib/node/chunk-JXGB54LE.mjs.map +0 -1
  232. package/lib/node/chunk-LK6DILFK.js +0 -22
  233. package/lib/node/chunk-LK6DILFK.js.map +0 -1
  234. package/lib/node/chunk-OFW5L5ET.mjs +0 -318
  235. package/lib/node/chunk-OFW5L5ET.mjs.map +0 -1
  236. package/lib/node/chunk-PFGO5BSM.js +0 -25
  237. package/lib/node/chunk-PFGO5BSM.js.map +0 -1
  238. package/lib/node/chunk-R6T7CL5E.mjs +0 -189
  239. package/lib/node/chunk-R6T7CL5E.mjs.map +0 -1
  240. package/lib/node/chunk-SQ6RHTJR.mjs +0 -51
  241. package/lib/node/chunk-SQ6RHTJR.mjs.map +0 -1
  242. package/lib/node/chunk-SRMAQGPM.js +0 -30
  243. package/lib/node/chunk-SRMAQGPM.js.map +0 -1
  244. package/lib/node/chunk-T3TW4P64.js +0 -32
  245. package/lib/node/chunk-T3TW4P64.js.map +0 -1
  246. package/lib/node/chunk-TX5GBTFY.mjs +0 -25
  247. package/lib/node/chunk-TX5GBTFY.mjs.map +0 -1
  248. package/lib/node/chunk-VYO5XDY2.js +0 -1126
  249. package/lib/node/chunk-VYO5XDY2.js.map +0 -1
  250. package/lib/node/chunk-YWNGXXUQ.mjs +0 -30
  251. package/lib/node/chunk-YWNGXXUQ.mjs.map +0 -1
  252. package/lib/node/index.d.ts +0 -61
  253. package/lib/node/index.js +0 -45
  254. package/lib/node/index.js.map +0 -1
  255. package/lib/node/interceptors/ClientRequest/index.d.ts +0 -110
  256. package/lib/node/interceptors/ClientRequest/index.js +0 -11
  257. package/lib/node/interceptors/ClientRequest/index.js.map +0 -1
  258. package/lib/node/interceptors/ClientRequest/index.mjs.map +0 -1
  259. package/lib/node/interceptors/XMLHttpRequest/index.d.ts +0 -13
  260. package/lib/node/interceptors/XMLHttpRequest/index.js +0 -13
  261. package/lib/node/interceptors/XMLHttpRequest/index.js.map +0 -1
  262. package/lib/node/interceptors/XMLHttpRequest/index.mjs.map +0 -1
  263. package/lib/node/interceptors/fetch/index.d.ts +0 -12
  264. package/lib/node/interceptors/fetch/index.js +0 -12
  265. package/lib/node/interceptors/fetch/index.js.map +0 -1
  266. package/lib/node/interceptors/fetch/index.mjs.map +0 -1
  267. package/lib/node/presets/node.d.ts +0 -15
  268. package/lib/node/presets/node.js +0 -27
  269. package/lib/node/presets/node.js.map +0 -1
  270. package/lib/node/utils/node/index.js +0 -10
  271. package/lib/node/utils/node/index.js.map +0 -1
  272. package/lib/node/utils/node/index.mjs.map +0 -1
@@ -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,197 +1,152 @@
1
- import {
2
- BatchInterceptor
3
- } from "./chunk-SQ6RHTJR.mjs";
4
- import {
5
- ClientRequestInterceptor
6
- } from "./chunk-5UGIB6OX.mjs";
7
- import "./chunk-GKN5RBVR.mjs";
8
- import {
9
- XMLHttpRequestInterceptor
10
- } from "./chunk-5V3SIIW2.mjs";
11
- import "./chunk-6HYIRFX2.mjs";
12
- import {
13
- FetchInterceptor
14
- } from "./chunk-OFW5L5ET.mjs";
15
- import "./chunk-TX5GBTFY.mjs";
16
- import "./chunk-6YM4PLBI.mjs";
17
- import {
18
- handleRequest,
19
- isResponseError
20
- } from "./chunk-R6T7CL5E.mjs";
21
- import {
22
- FetchResponse,
23
- Interceptor,
24
- RequestController
25
- } from "./chunk-JXGB54LE.mjs";
26
- import "./chunk-YWNGXXUQ.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";
27
9
 
28
- // src/RemoteHttpInterceptor.ts
10
+ //#region src/RemoteHttpInterceptor.ts
29
11
  var RemoteHttpInterceptor = class extends BatchInterceptor {
30
- constructor() {
31
- super({
32
- name: "remote-interceptor",
33
- interceptors: [
34
- new ClientRequestInterceptor(),
35
- new XMLHttpRequestInterceptor(),
36
- new FetchInterceptor()
37
- ]
38
- });
39
- }
40
- setup() {
41
- super.setup();
42
- let handleParentMessage;
43
- this.on("request", async ({ request, requestId, controller }) => {
44
- var _a;
45
- const serializedRequest = JSON.stringify({
46
- id: requestId,
47
- method: request.method,
48
- url: request.url,
49
- headers: Array.from(request.headers.entries()),
50
- credentials: request.credentials,
51
- body: ["GET", "HEAD"].includes(request.method) ? null : await request.text()
52
- });
53
- this.logger.info(
54
- "sent serialized request to the child:",
55
- serializedRequest
56
- );
57
- (_a = process.send) == null ? void 0 : _a.call(process, `request:${serializedRequest}`);
58
- const responsePromise = new Promise((resolve) => {
59
- handleParentMessage = (message) => {
60
- if (typeof message !== "string") {
61
- return resolve();
62
- }
63
- if (message.startsWith(`response:${requestId}`)) {
64
- const [, serializedResponse] = message.match(/^response:.+?:(.+)$/) || [];
65
- if (!serializedResponse) {
66
- return resolve();
67
- }
68
- const responseInit = JSON.parse(
69
- serializedResponse
70
- );
71
- const mockedResponse = new FetchResponse(responseInit.body, {
72
- url: request.url,
73
- status: responseInit.status,
74
- statusText: responseInit.statusText,
75
- headers: responseInit.headers
76
- });
77
- controller.respondWith(mockedResponse);
78
- return resolve();
79
- }
80
- };
81
- });
82
- this.logger.info(
83
- 'add "message" listener to the parent process',
84
- handleParentMessage
85
- );
86
- process.addListener("message", handleParentMessage);
87
- return responsePromise;
88
- });
89
- this.subscriptions.push(() => {
90
- process.removeListener("message", handleParentMessage);
91
- });
92
- }
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
+ }
93
66
  };
94
67
  function requestReviver(key, value) {
95
- switch (key) {
96
- case "url":
97
- return new URL(value);
98
- case "headers":
99
- return new Headers(value);
100
- default:
101
- return value;
102
- }
68
+ switch (key) {
69
+ case "url": return new URL(value);
70
+ case "headers": return new Headers(value);
71
+ default: return value;
72
+ }
103
73
  }
104
- var _RemoteHttpResolver = class extends Interceptor {
105
- constructor(options) {
106
- super(_RemoteHttpResolver.symbol);
107
- this.process = options.process;
108
- }
109
- setup() {
110
- const logger = this.logger.extend("setup");
111
- const handleChildMessage = async (message) => {
112
- logger.info("received message from child!", message);
113
- if (typeof message !== "string" || !message.startsWith("request:")) {
114
- logger.info("unknown message, ignoring...");
115
- return;
116
- }
117
- const [, serializedRequest] = message.match(/^request:(.+)$/) || [];
118
- if (!serializedRequest) {
119
- return;
120
- }
121
- const requestJson = JSON.parse(
122
- serializedRequest,
123
- requestReviver
124
- );
125
- logger.info("parsed intercepted request", requestJson);
126
- const request = new Request(requestJson.url, {
127
- method: requestJson.method,
128
- headers: new Headers(requestJson.headers),
129
- credentials: requestJson.credentials,
130
- body: requestJson.body
131
- });
132
- const controller = new RequestController(request, {
133
- passthrough: () => {
134
- },
135
- respondWith: async (response) => {
136
- if (isResponseError(response)) {
137
- this.logger.info("received a network error!", { response });
138
- throw new Error("Not implemented");
139
- }
140
- this.logger.info("received mocked response!", { response });
141
- const responseClone = response.clone();
142
- const responseText = await responseClone.text();
143
- const serializedResponse = JSON.stringify({
144
- status: response.status,
145
- statusText: response.statusText,
146
- headers: Array.from(response.headers.entries()),
147
- body: responseText
148
- });
149
- this.process.send(
150
- `response:${requestJson.id}:${serializedResponse}`,
151
- (error) => {
152
- if (error) {
153
- return;
154
- }
155
- this.emitter.emit("response", {
156
- request,
157
- requestId: requestJson.id,
158
- response: responseClone,
159
- isMockedResponse: true
160
- });
161
- }
162
- );
163
- logger.info(
164
- "sent serialized mocked response to the parent:",
165
- serializedResponse
166
- );
167
- },
168
- errorWith: (reason) => {
169
- this.logger.info("request has errored!", { error: reason });
170
- throw new Error("Not implemented");
171
- }
172
- });
173
- await handleRequest({
174
- request,
175
- requestId: requestJson.id,
176
- controller,
177
- emitter: this.emitter
178
- });
179
- };
180
- this.subscriptions.push(() => {
181
- this.process.removeListener("message", handleChildMessage);
182
- logger.info('removed the "message" listener from the child process!');
183
- });
184
- logger.info('adding a "message" listener to the child process');
185
- this.process.addListener("message", handleChildMessage);
186
- this.process.once("error", () => this.dispose());
187
- this.process.once("exit", () => this.dispose());
188
- }
189
- };
190
- var RemoteHttpResolver = _RemoteHttpResolver;
191
- RemoteHttpResolver.symbol = Symbol("remote-resolver");
192
- export {
193
- RemoteHttpInterceptor,
194
- RemoteHttpResolver,
195
- 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
+ }
196
148
  };
149
+
150
+ //#endregion
151
+ export { RemoteHttpInterceptor, RemoteHttpResolver, requestReviver };
197
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'\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCO,IAAM,wBAAN,cAAoC,iBAEzC;AAAA,EACA,cAAc;AACZ,UAAM;AA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W,kBAAkB;AAEtD,SAAK,QAAQ,KAAK,SAAS,MAAM,KAAK,QAAQ,CAAC;AAC/C,SAAK,QAAQ,KAAK,QAAQ,MAAM,KAAK,QAAQ,CAAC;AAAA,EAChD;AACF;AA5GO,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,cAA2C,iBAEzC;CACA,cAAc;AACZ,QAAM;GACJ,MAAM;GACN,cAAc;IACZ,IAAI,0BAA0B;IAC9B,IAAI,2BAA2B;IAC/B,IAAI,kBAAkB;IACvB;GACF,CAAC;;CAGJ,AAAU,QAAQ;AA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