@mswjs/interceptors 0.39.8 → 0.40.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 (133) hide show
  1. package/lib/browser/{chunk-E3CCOBRX.js → chunk-2MCNQOY3.js} +54 -49
  2. package/lib/browser/chunk-2MCNQOY3.js.map +1 -0
  3. package/lib/browser/chunk-57RIRQUY.js +218 -0
  4. package/lib/browser/chunk-57RIRQUY.js.map +1 -0
  5. package/lib/browser/chunk-FW45TRCB.js +178 -0
  6. package/lib/browser/chunk-FW45TRCB.js.map +1 -0
  7. package/lib/browser/{chunk-TIPR373R.js → chunk-JQ2S7G56.js} +19 -3
  8. package/lib/browser/chunk-JQ2S7G56.js.map +1 -0
  9. package/lib/browser/{chunk-3RXCRGL2.mjs → chunk-LIKZF2VU.mjs} +102 -1
  10. package/lib/browser/chunk-LIKZF2VU.mjs.map +1 -0
  11. package/lib/browser/{chunk-H74PGQ4Y.js → chunk-MNT2FUCH.js} +58 -53
  12. package/lib/browser/chunk-MNT2FUCH.js.map +1 -0
  13. package/lib/browser/chunk-VOUOVDAW.mjs +178 -0
  14. package/lib/browser/chunk-VOUOVDAW.mjs.map +1 -0
  15. package/lib/browser/{chunk-E7UVBHVO.mjs → chunk-WADP6VHN.mjs} +48 -43
  16. package/lib/browser/chunk-WADP6VHN.mjs.map +1 -0
  17. package/lib/browser/{chunk-Q7K2XAEP.mjs → chunk-WOWPV4GR.mjs} +50 -45
  18. package/lib/browser/chunk-WOWPV4GR.mjs.map +1 -0
  19. package/lib/browser/{chunk-QED3Q6Z2.mjs → chunk-Z5TSB3T6.mjs} +17 -1
  20. package/lib/browser/{chunk-QED3Q6Z2.mjs.map → chunk-Z5TSB3T6.mjs.map} +1 -1
  21. package/lib/browser/{glossary-7152281e.d.ts → glossary-f7ee1c9d.d.ts} +22 -17
  22. package/lib/browser/index.d.ts +1 -2
  23. package/lib/browser/index.js +6 -4
  24. package/lib/browser/index.js.map +1 -1
  25. package/lib/browser/index.mjs +4 -2
  26. package/lib/browser/index.mjs.map +1 -1
  27. package/lib/browser/interceptors/WebSocket/index.js +3 -3
  28. package/lib/browser/interceptors/WebSocket/index.mjs +1 -1
  29. package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +1 -2
  30. package/lib/browser/interceptors/XMLHttpRequest/index.js +5 -5
  31. package/lib/browser/interceptors/XMLHttpRequest/index.mjs +4 -4
  32. package/lib/browser/interceptors/fetch/index.d.ts +1 -2
  33. package/lib/browser/interceptors/fetch/index.js +5 -5
  34. package/lib/browser/interceptors/fetch/index.mjs +4 -4
  35. package/lib/browser/presets/browser.d.ts +1 -2
  36. package/lib/browser/presets/browser.js +7 -7
  37. package/lib/browser/presets/browser.mjs +5 -5
  38. package/lib/node/{BatchInterceptor-5b72232f.d.ts → BatchInterceptor-cb9a2eee.d.ts} +1 -1
  39. package/lib/node/{Interceptor-bc5a9d8e.d.ts → Interceptor-dc0a39b5.d.ts} +22 -16
  40. package/lib/node/RemoteHttpInterceptor.d.ts +2 -3
  41. package/lib/node/RemoteHttpInterceptor.js +31 -27
  42. package/lib/node/RemoteHttpInterceptor.js.map +1 -1
  43. package/lib/node/RemoteHttpInterceptor.mjs +28 -24
  44. package/lib/node/RemoteHttpInterceptor.mjs.map +1 -1
  45. package/lib/node/{chunk-EKNRB5ZS.mjs → chunk-5UGIB6OX.mjs} +40 -29
  46. package/lib/node/chunk-5UGIB6OX.mjs.map +1 -0
  47. package/lib/node/{chunk-4NEYTVWD.mjs → chunk-5V3SIIW2.mjs} +48 -43
  48. package/lib/node/chunk-5V3SIIW2.mjs.map +1 -0
  49. package/lib/node/{chunk-VV2LUF5K.js → chunk-6B3ZQOO2.js} +51 -46
  50. package/lib/node/chunk-6B3ZQOO2.js.map +1 -0
  51. package/lib/node/chunk-7Q53NNPV.js +189 -0
  52. package/lib/node/chunk-7Q53NNPV.js.map +1 -0
  53. package/lib/node/{chunk-A7U44ARP.js → chunk-DOWWQYXZ.js} +104 -3
  54. package/lib/node/chunk-DOWWQYXZ.js.map +1 -0
  55. package/lib/node/{chunk-Z5LWCBZS.js → chunk-FRZQJNBO.js} +56 -51
  56. package/lib/node/chunk-FRZQJNBO.js.map +1 -0
  57. package/lib/node/{chunk-TJDMZZXE.mjs → chunk-GKN5RBVR.mjs} +2 -2
  58. package/lib/node/{chunk-R6JVCM7X.js → chunk-J5MULIHT.js} +3 -3
  59. package/lib/node/{chunk-IHJSPMYM.mjs → chunk-JXGB54LE.mjs} +102 -1
  60. package/lib/node/chunk-JXGB54LE.mjs.map +1 -0
  61. package/lib/node/{chunk-3CNGDJFB.mjs → chunk-OFW5L5ET.mjs} +50 -45
  62. package/lib/node/chunk-OFW5L5ET.mjs.map +1 -0
  63. package/lib/node/{chunk-A7Q4RTDJ.mjs → chunk-R6T7CL5E.mjs} +55 -115
  64. package/lib/node/chunk-R6T7CL5E.mjs.map +1 -0
  65. package/lib/node/{chunk-RC2XPCC4.mjs → chunk-SQ6RHTJR.mjs} +2 -2
  66. package/lib/node/chunk-SRMAQGPM.js +30 -0
  67. package/lib/node/chunk-SRMAQGPM.js.map +1 -0
  68. package/lib/node/{chunk-4YBV77DG.js → chunk-T3TW4P64.js} +3 -3
  69. package/lib/node/{chunk-N4ZZFE24.js → chunk-VYO5XDY2.js} +56 -45
  70. package/lib/node/chunk-VYO5XDY2.js.map +1 -0
  71. package/lib/node/chunk-YWNGXXUQ.mjs +30 -0
  72. package/lib/node/{chunk-3GJB4JDF.mjs.map → chunk-YWNGXXUQ.mjs.map} +1 -1
  73. package/lib/node/index.d.ts +2 -3
  74. package/lib/node/index.js +6 -4
  75. package/lib/node/index.js.map +1 -1
  76. package/lib/node/index.mjs +5 -3
  77. package/lib/node/index.mjs.map +1 -1
  78. package/lib/node/interceptors/ClientRequest/index.d.ts +1 -2
  79. package/lib/node/interceptors/ClientRequest/index.js +6 -6
  80. package/lib/node/interceptors/ClientRequest/index.mjs +5 -5
  81. package/lib/node/interceptors/XMLHttpRequest/index.d.ts +1 -2
  82. package/lib/node/interceptors/XMLHttpRequest/index.js +5 -5
  83. package/lib/node/interceptors/XMLHttpRequest/index.mjs +4 -4
  84. package/lib/node/interceptors/fetch/index.d.ts +1 -2
  85. package/lib/node/interceptors/fetch/index.js +5 -5
  86. package/lib/node/interceptors/fetch/index.mjs +4 -4
  87. package/lib/node/presets/node.d.ts +1 -2
  88. package/lib/node/presets/node.js +10 -10
  89. package/lib/node/presets/node.mjs +7 -7
  90. package/lib/node/utils/node/index.js +3 -3
  91. package/lib/node/utils/node/index.mjs +2 -2
  92. package/package.json +2 -1
  93. package/src/RemoteHttpInterceptor.ts +18 -13
  94. package/src/RequestController.test.ts +78 -31
  95. package/src/RequestController.ts +63 -39
  96. package/src/index.ts +4 -0
  97. package/src/interceptors/ClientRequest/MockHttpSocket.ts +24 -3
  98. package/src/interceptors/ClientRequest/index.ts +14 -18
  99. package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +45 -35
  100. package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +24 -21
  101. package/src/interceptors/fetch/index.ts +61 -50
  102. package/src/utils/handleRequest.ts +65 -95
  103. package/lib/browser/chunk-2QICSCCS.js +0 -238
  104. package/lib/browser/chunk-2QICSCCS.js.map +0 -1
  105. package/lib/browser/chunk-3RXCRGL2.mjs.map +0 -1
  106. package/lib/browser/chunk-E3CCOBRX.js.map +0 -1
  107. package/lib/browser/chunk-E7UVBHVO.mjs.map +0 -1
  108. package/lib/browser/chunk-H74PGQ4Y.js.map +0 -1
  109. package/lib/browser/chunk-PTTUYYVR.mjs +0 -238
  110. package/lib/browser/chunk-PTTUYYVR.mjs.map +0 -1
  111. package/lib/browser/chunk-Q7K2XAEP.mjs.map +0 -1
  112. package/lib/browser/chunk-T7TBRNJZ.js +0 -117
  113. package/lib/browser/chunk-T7TBRNJZ.js.map +0 -1
  114. package/lib/browser/chunk-TIPR373R.js.map +0 -1
  115. package/lib/node/chunk-3CNGDJFB.mjs.map +0 -1
  116. package/lib/node/chunk-3GJB4JDF.mjs +0 -14
  117. package/lib/node/chunk-4NEYTVWD.mjs.map +0 -1
  118. package/lib/node/chunk-72ZIHMEB.js +0 -249
  119. package/lib/node/chunk-72ZIHMEB.js.map +0 -1
  120. package/lib/node/chunk-A7Q4RTDJ.mjs.map +0 -1
  121. package/lib/node/chunk-A7U44ARP.js.map +0 -1
  122. package/lib/node/chunk-EKNRB5ZS.mjs.map +0 -1
  123. package/lib/node/chunk-IHJSPMYM.mjs.map +0 -1
  124. package/lib/node/chunk-N4ZZFE24.js.map +0 -1
  125. package/lib/node/chunk-SMXZPJEA.js +0 -14
  126. package/lib/node/chunk-SMXZPJEA.js.map +0 -1
  127. package/lib/node/chunk-VV2LUF5K.js.map +0 -1
  128. package/lib/node/chunk-Z5LWCBZS.js.map +0 -1
  129. package/src/utils/RequestController.ts +0 -21
  130. /package/lib/node/{chunk-TJDMZZXE.mjs.map → chunk-GKN5RBVR.mjs.map} +0 -0
  131. /package/lib/node/{chunk-R6JVCM7X.js.map → chunk-J5MULIHT.js.map} +0 -0
  132. /package/lib/node/{chunk-RC2XPCC4.mjs.map → chunk-SQ6RHTJR.mjs.map} +0 -0
  133. /package/lib/node/{chunk-4YBV77DG.js.map → chunk-T3TW4P64.js.map} +0 -0
@@ -1,38 +1,39 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkR6JVCM7Xjs = require('./chunk-R6JVCM7X.js');
3
+ var _chunkJ5MULIHTjs = require('./chunk-J5MULIHT.js');
4
4
 
5
5
 
6
- var _chunkN4ZZFE24js = require('./chunk-N4ZZFE24.js');
7
- require('./chunk-4YBV77DG.js');
6
+ var _chunkVYO5XDY2js = require('./chunk-VYO5XDY2.js');
7
+ require('./chunk-T3TW4P64.js');
8
8
 
9
9
 
10
- var _chunkVV2LUF5Kjs = require('./chunk-VV2LUF5K.js');
10
+ var _chunk6B3ZQOO2js = require('./chunk-6B3ZQOO2.js');
11
11
  require('./chunk-LK6DILFK.js');
12
12
 
13
13
 
14
- var _chunkZ5LWCBZSjs = require('./chunk-Z5LWCBZS.js');
14
+ var _chunkFRZQJNBOjs = require('./chunk-FRZQJNBO.js');
15
15
  require('./chunk-PFGO5BSM.js');
16
16
  require('./chunk-73NOP3T5.js');
17
17
 
18
18
 
19
19
 
20
- var _chunk72ZIHMEBjs = require('./chunk-72ZIHMEB.js');
20
+ var _chunk7Q53NNPVjs = require('./chunk-7Q53NNPV.js');
21
21
 
22
22
 
23
23
 
24
- var _chunkA7U44ARPjs = require('./chunk-A7U44ARP.js');
25
- require('./chunk-SMXZPJEA.js');
24
+
25
+ var _chunkDOWWQYXZjs = require('./chunk-DOWWQYXZ.js');
26
+ require('./chunk-SRMAQGPM.js');
26
27
 
27
28
  // src/RemoteHttpInterceptor.ts
28
- var RemoteHttpInterceptor = class extends _chunkR6JVCM7Xjs.BatchInterceptor {
29
+ var RemoteHttpInterceptor = class extends _chunkJ5MULIHTjs.BatchInterceptor {
29
30
  constructor() {
30
31
  super({
31
32
  name: "remote-interceptor",
32
33
  interceptors: [
33
- new (0, _chunkN4ZZFE24js.ClientRequestInterceptor)(),
34
- new (0, _chunkVV2LUF5Kjs.XMLHttpRequestInterceptor)(),
35
- new (0, _chunkZ5LWCBZSjs.FetchInterceptor)()
34
+ new (0, _chunkVYO5XDY2js.ClientRequestInterceptor)(),
35
+ new (0, _chunk6B3ZQOO2js.XMLHttpRequestInterceptor)(),
36
+ new (0, _chunkFRZQJNBOjs.FetchInterceptor)()
36
37
  ]
37
38
  });
38
39
  }
@@ -67,7 +68,7 @@ var RemoteHttpInterceptor = class extends _chunkR6JVCM7Xjs.BatchInterceptor {
67
68
  const responseInit = JSON.parse(
68
69
  serializedResponse
69
70
  );
70
- const mockedResponse = new (0, _chunkA7U44ARPjs.FetchResponse)(responseInit.body, {
71
+ const mockedResponse = new (0, _chunkDOWWQYXZjs.FetchResponse)(responseInit.body, {
71
72
  url: request.url,
72
73
  status: responseInit.status,
73
74
  statusText: responseInit.statusText,
@@ -100,7 +101,7 @@ function requestReviver(key, value) {
100
101
  return value;
101
102
  }
102
103
  }
103
- var _RemoteHttpResolver = class extends _chunkA7U44ARPjs.Interceptor {
104
+ var _RemoteHttpResolver = class extends _chunkDOWWQYXZjs.Interceptor {
104
105
  constructor(options) {
105
106
  super(_RemoteHttpResolver.symbol);
106
107
  this.process = options.process;
@@ -128,13 +129,14 @@ var _RemoteHttpResolver = class extends _chunkA7U44ARPjs.Interceptor {
128
129
  credentials: requestJson.credentials,
129
130
  body: requestJson.body
130
131
  });
131
- const controller = new (0, _chunk72ZIHMEBjs.RequestController)(request);
132
- await _chunk72ZIHMEBjs.handleRequest.call(void 0, {
133
- request,
134
- requestId: requestJson.id,
135
- controller,
136
- emitter: this.emitter,
137
- onResponse: async (response) => {
132
+ const controller = new (0, _chunkDOWWQYXZjs.RequestController)(request, {
133
+ passthrough: () => {
134
+ },
135
+ respondWith: async (response) => {
136
+ if (_chunk7Q53NNPVjs.isResponseError.call(void 0, response)) {
137
+ this.logger.info("received a network error!", { response });
138
+ throw new Error("Not implemented");
139
+ }
138
140
  this.logger.info("received mocked response!", { response });
139
141
  const responseClone = response.clone();
140
142
  const responseText = await responseClone.text();
@@ -163,15 +165,17 @@ var _RemoteHttpResolver = class extends _chunkA7U44ARPjs.Interceptor {
163
165
  serializedResponse
164
166
  );
165
167
  },
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 });
168
+ errorWith: (reason) => {
169
+ this.logger.info("request has errored!", { error: reason });
172
170
  throw new Error("Not implemented");
173
171
  }
174
172
  });
173
+ await _chunk7Q53NNPVjs.handleRequest.call(void 0, {
174
+ request,
175
+ requestId: requestJson.id,
176
+ controller,
177
+ emitter: this.emitter
178
+ });
175
179
  };
176
180
  this.subscriptions.push(() => {
177
181
  this.process.removeListener("message", handleChildMessage);
@@ -1 +1 @@
1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,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","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"]}
1
+ {"version":3,"sources":["../../src/RemoteHttpInterceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCO,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;AA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A5GO,IAAM,qBAAN;AAAM,mBACJ,SAAS,OAAO,iBAAiB","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"]}
@@ -1,28 +1,29 @@
1
1
  import {
2
2
  BatchInterceptor
3
- } from "./chunk-RC2XPCC4.mjs";
3
+ } from "./chunk-SQ6RHTJR.mjs";
4
4
  import {
5
5
  ClientRequestInterceptor
6
- } from "./chunk-EKNRB5ZS.mjs";
7
- import "./chunk-TJDMZZXE.mjs";
6
+ } from "./chunk-5UGIB6OX.mjs";
7
+ import "./chunk-GKN5RBVR.mjs";
8
8
  import {
9
9
  XMLHttpRequestInterceptor
10
- } from "./chunk-4NEYTVWD.mjs";
10
+ } from "./chunk-5V3SIIW2.mjs";
11
11
  import "./chunk-6HYIRFX2.mjs";
12
12
  import {
13
13
  FetchInterceptor
14
- } from "./chunk-3CNGDJFB.mjs";
14
+ } from "./chunk-OFW5L5ET.mjs";
15
15
  import "./chunk-TX5GBTFY.mjs";
16
16
  import "./chunk-6YM4PLBI.mjs";
17
17
  import {
18
- RequestController,
19
- handleRequest
20
- } from "./chunk-A7Q4RTDJ.mjs";
18
+ handleRequest,
19
+ isResponseError
20
+ } from "./chunk-R6T7CL5E.mjs";
21
21
  import {
22
22
  FetchResponse,
23
- Interceptor
24
- } from "./chunk-IHJSPMYM.mjs";
25
- import "./chunk-3GJB4JDF.mjs";
23
+ Interceptor,
24
+ RequestController
25
+ } from "./chunk-JXGB54LE.mjs";
26
+ import "./chunk-YWNGXXUQ.mjs";
26
27
 
27
28
  // src/RemoteHttpInterceptor.ts
28
29
  var RemoteHttpInterceptor = class extends BatchInterceptor {
@@ -128,13 +129,14 @@ var _RemoteHttpResolver = class extends Interceptor {
128
129
  credentials: requestJson.credentials,
129
130
  body: requestJson.body
130
131
  });
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) => {
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
+ }
138
140
  this.logger.info("received mocked response!", { response });
139
141
  const responseClone = response.clone();
140
142
  const responseText = await responseClone.text();
@@ -163,15 +165,17 @@ var _RemoteHttpResolver = class extends Interceptor {
163
165
  serializedResponse
164
166
  );
165
167
  },
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 });
168
+ errorWith: (reason) => {
169
+ this.logger.info("request has errored!", { error: reason });
172
170
  throw new Error("Not implemented");
173
171
  }
174
172
  });
173
+ await handleRequest({
174
+ request,
175
+ requestId: requestJson.id,
176
+ controller,
177
+ emitter: this.emitter
178
+ });
175
179
  };
176
180
  this.subscriptions.push(() => {
177
181
  this.process.removeListener("message", handleChildMessage);
@@ -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,Q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AQ;AAAA,YACX,YAAY,YAAY,MAAM;AAAA,YAC9B,CAAC,UAAU;AACT,kBAAI,OAAO;AACT;AAAA,cACF;AAIA,mBAAK,QAAQ,KAAK,YAAY;AAAA,gBAC5B;AAAA,gBACA,WAAW,YAAY;AAAA,gBACvB,UAAU;AAAA,gBACV,kBAAkB;AAAA,cACpB,CAAC;AAAA,YACH;AAAA,UACF;AAEA,iBAAO;AAAA,YACL;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,gBAAgB,CAAC,aAAa;AAC5B,eAAK,OAAO,KAAK,6BAA6B,EAAE,SAAS,CAAC;AAC1D,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,QACA,SAAS,CAAC,UAAU;AAClB,eAAK,OAAO,KAAK,wBAAwB,EAAE,MAAM,CAAC;AAClD,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,MACF,CAAC;AAAA,IACH;AAEA,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,"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;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;AApDrE;AAuDM,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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YAAY;AAAA,gBACvB,UAAU;AAAA,gBACV,kBAAkB;AAAA,cACpB,CAAC;AAAA,YACH;AAAA,UACF;AAEA,iBAAO;AAAA,YACL;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,WAAW,CAAC,WAAW;AACrB,eAAK,OAAO,KAAK,wBAAwB,EAAE,OAAO,OAAO,CAAC;AAC1D,gBAAM,IAAI,MAAM,iBAAiB;AAAA,QACnC;AAAA,MACF,CAAC;AAED,YAAM,cAAc;AAAA,QAClB;AAAA,QACA,WAAW,YAAY;AAAA,QACvB;AAAA,QACA,SAAS,KAAK;AAAA,MAChB,CAAC;AAAA,IACH;AAEA,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;AA5GO,IAAM,qBAAN;AAAM,mBACJ,SAAS,OAAO,iBAAiB;","names":[]}
@@ -1,23 +1,22 @@
1
1
  import {
2
2
  setRawRequestBodyStream
3
- } from "./chunk-TJDMZZXE.mjs";
3
+ } from "./chunk-GKN5RBVR.mjs";
4
4
  import {
5
- RequestController,
6
- createServerErrorResponse,
7
5
  emitAsync,
8
6
  handleRequest,
9
7
  isObject,
10
8
  isPropertyAccessible
11
- } from "./chunk-A7Q4RTDJ.mjs";
9
+ } from "./chunk-R6T7CL5E.mjs";
12
10
  import {
13
11
  FetchResponse,
14
12
  INTERNAL_REQUEST_ID_HEADER_NAME,
15
13
  Interceptor,
14
+ RequestController,
16
15
  createRequestId
17
- } from "./chunk-IHJSPMYM.mjs";
16
+ } from "./chunk-JXGB54LE.mjs";
18
17
  import {
19
18
  setRawRequest
20
- } from "./chunk-3GJB4JDF.mjs";
19
+ } from "./chunk-YWNGXXUQ.mjs";
21
20
 
22
21
  // src/interceptors/ClientRequest/index.ts
23
22
  import http2 from "http";
@@ -443,6 +442,7 @@ var MockHttpSocket = class extends MockSocket {
443
442
  Reflect.set(this, "getProtocol", () => "TLSv1.3");
444
443
  Reflect.set(this, "getSession", () => void 0);
445
444
  Reflect.set(this, "isSessionReused", () => false);
445
+ Reflect.set(this, "getCipher", () => ({ name: "AES256-SHA", standardName: "TLS_RSA_WITH_AES_256_CBC_SHA", version: "TLSv1.3" }));
446
446
  }
447
447
  }
448
448
  emit(event, ...args) {
@@ -514,7 +514,8 @@ var MockHttpSocket = class extends MockSocket {
514
514
  "authorized",
515
515
  "getProtocol",
516
516
  "getSession",
517
- "isSessionReused"
517
+ "isSessionReused",
518
+ "getCipher"
518
519
  ];
519
520
  tlsProperties.forEach((propertyName) => {
520
521
  Object.defineProperty(this, propertyName, {
@@ -541,10 +542,18 @@ var MockHttpSocket = class extends MockSocket {
541
542
  * HTTP message and push it to the socket.
542
543
  */
543
544
  async respondWith(response) {
544
- var _a;
545
+ var _a, _b, _c;
545
546
  if (this.destroyed) {
546
547
  return;
547
548
  }
549
+ invariant(
550
+ this.socketState !== "mock",
551
+ '[MockHttpSocket] Failed to respond to the "%s %s" request with "%s %s": the request has already been handled',
552
+ (_a = this.request) == null ? void 0 : _a.method,
553
+ (_b = this.request) == null ? void 0 : _b.url,
554
+ response.status,
555
+ response.statusText
556
+ );
548
557
  if (isPropertyAccessible(response, "type") && response.type === "error") {
549
558
  this.errorWith(new TypeError("Network error"));
550
559
  return;
@@ -586,15 +595,20 @@ var MockHttpSocket = class extends MockSocket {
586
595
  serverResponse.write(value);
587
596
  }
588
597
  } catch (error) {
589
- this.respondWith(createServerErrorResponse(error));
590
- return;
598
+ if (error instanceof Error) {
599
+ serverResponse.destroy();
600
+ this.destroy();
601
+ return;
602
+ }
603
+ serverResponse.destroy();
604
+ throw error;
591
605
  }
592
606
  } else {
593
607
  serverResponse.end();
594
608
  }
595
609
  if (!this.shouldKeepAlive) {
596
610
  this.emit("readable");
597
- (_a = this.responseStream) == null ? void 0 : _a.push(null);
611
+ (_c = this.responseStream) == null ? void 0 : _c.push(null);
598
612
  this.push(null);
599
613
  }
600
614
  }
@@ -973,28 +987,25 @@ var _ClientRequestInterceptor = class extends Interceptor {
973
987
  request,
974
988
  socket
975
989
  }) => {
976
- const requestId = Reflect.get(request, kRequestId);
977
- const controller = new RequestController(request);
978
- const isRequestHandled = await handleRequest({
979
- request,
980
- requestId,
981
- controller,
982
- emitter: this.emitter,
983
- onResponse: (response) => {
984
- socket.respondWith(response);
990
+ const controller = new RequestController(request, {
991
+ passthrough() {
992
+ socket.passthrough();
985
993
  },
986
- onRequestError: (response) => {
987
- socket.respondWith(response);
994
+ async respondWith(response) {
995
+ await socket.respondWith(response);
988
996
  },
989
- onError: (error) => {
990
- if (error instanceof Error) {
991
- socket.errorWith(error);
997
+ errorWith(reason) {
998
+ if (reason instanceof Error) {
999
+ socket.errorWith(reason);
992
1000
  }
993
1001
  }
994
1002
  });
995
- if (!isRequestHandled) {
996
- return socket.passthrough();
997
- }
1003
+ await handleRequest({
1004
+ request,
1005
+ requestId: Reflect.get(request, kRequestId),
1006
+ controller,
1007
+ emitter: this.emitter
1008
+ });
998
1009
  };
999
1010
  this.onResponse = async ({
1000
1011
  requestId,
@@ -1112,4 +1123,4 @@ ClientRequestInterceptor.symbol = Symbol("client-request-interceptor");
1112
1123
  export {
1113
1124
  ClientRequestInterceptor
1114
1125
  };
1115
- //# sourceMappingURL=chunk-EKNRB5ZS.mjs.map
1126
+ //# sourceMappingURL=chunk-5UGIB6OX.mjs.map