@mswjs/interceptors 0.36.9 → 0.36.10

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 (53) hide show
  1. package/lib/browser/{chunk-4K55BZMG.mjs → chunk-4RQHC4IY.mjs} +12 -8
  2. package/lib/browser/chunk-4RQHC4IY.mjs.map +1 -0
  3. package/lib/browser/{chunk-LMBCDE7C.js → chunk-CAAXYHKD.js} +6 -6
  4. package/lib/browser/{chunk-UXPG527I.js → chunk-CK3NCGUG.js} +12 -8
  5. package/lib/browser/chunk-CK3NCGUG.js.map +1 -0
  6. package/lib/browser/{chunk-Q7PXVXSL.mjs → chunk-MMAVIMED.mjs} +2 -2
  7. package/lib/browser/{chunk-RKQSZCUD.js → chunk-NNR7JKYY.js} +4 -4
  8. package/lib/browser/{chunk-C6BKAAQW.mjs → chunk-VXLPKFY4.mjs} +2 -2
  9. package/lib/browser/interceptors/XMLHttpRequest/index.js +3 -3
  10. package/lib/browser/interceptors/XMLHttpRequest/index.mjs +2 -2
  11. package/lib/browser/interceptors/fetch/index.js +3 -3
  12. package/lib/browser/interceptors/fetch/index.mjs +2 -2
  13. package/lib/browser/presets/browser.js +5 -5
  14. package/lib/browser/presets/browser.mjs +3 -3
  15. package/lib/node/RemoteHttpInterceptor.js +7 -7
  16. package/lib/node/RemoteHttpInterceptor.mjs +3 -3
  17. package/lib/node/{chunk-MG3S53QP.mjs → chunk-5VLPRS7Y.mjs} +4 -6
  18. package/lib/node/chunk-5VLPRS7Y.mjs.map +1 -0
  19. package/lib/node/{chunk-4YT2XSVO.js → chunk-6F2CSTH4.js} +6 -6
  20. package/lib/node/{chunk-X2CFRRWY.js → chunk-7F5S3MDK.js} +4 -4
  21. package/lib/node/{chunk-EBDS6VMR.mjs → chunk-BBC5JYC4.mjs} +2 -2
  22. package/lib/node/{chunk-M4WQE4TR.mjs → chunk-DABV27J7.mjs} +12 -8
  23. package/lib/node/chunk-DABV27J7.mjs.map +1 -0
  24. package/lib/node/{chunk-6DIWEMO7.mjs → chunk-SYHIUXN7.mjs} +2 -2
  25. package/lib/node/{chunk-FPLETXGA.js → chunk-T6USXRLL.js} +7 -9
  26. package/lib/node/chunk-T6USXRLL.js.map +1 -0
  27. package/lib/node/{chunk-VCUEA4PL.js → chunk-W46RNDIE.js} +12 -8
  28. package/lib/node/chunk-W46RNDIE.js.map +1 -0
  29. package/lib/node/interceptors/ClientRequest/index.js +3 -3
  30. package/lib/node/interceptors/ClientRequest/index.mjs +2 -2
  31. package/lib/node/interceptors/XMLHttpRequest/index.js +3 -3
  32. package/lib/node/interceptors/XMLHttpRequest/index.mjs +2 -2
  33. package/lib/node/interceptors/fetch/index.js +3 -3
  34. package/lib/node/interceptors/fetch/index.mjs +2 -2
  35. package/lib/node/presets/node.js +7 -7
  36. package/lib/node/presets/node.mjs +4 -4
  37. package/package.json +3 -2
  38. package/src/interceptors/ClientRequest/MockHttpSocket.ts +7 -3
  39. package/src/utils/handleRequest.ts +11 -7
  40. package/lib/browser/chunk-4K55BZMG.mjs.map +0 -1
  41. package/lib/browser/chunk-UXPG527I.js.map +0 -1
  42. package/lib/node/chunk-FPLETXGA.js.map +0 -1
  43. package/lib/node/chunk-M4WQE4TR.mjs.map +0 -1
  44. package/lib/node/chunk-MG3S53QP.mjs.map +0 -1
  45. package/lib/node/chunk-VCUEA4PL.js.map +0 -1
  46. /package/lib/browser/{chunk-LMBCDE7C.js.map → chunk-CAAXYHKD.js.map} +0 -0
  47. /package/lib/browser/{chunk-Q7PXVXSL.mjs.map → chunk-MMAVIMED.mjs.map} +0 -0
  48. /package/lib/browser/{chunk-RKQSZCUD.js.map → chunk-NNR7JKYY.js.map} +0 -0
  49. /package/lib/browser/{chunk-C6BKAAQW.mjs.map → chunk-VXLPKFY4.mjs.map} +0 -0
  50. /package/lib/node/{chunk-4YT2XSVO.js.map → chunk-6F2CSTH4.js.map} +0 -0
  51. /package/lib/node/{chunk-X2CFRRWY.js.map → chunk-7F5S3MDK.js.map} +0 -0
  52. /package/lib/node/{chunk-EBDS6VMR.mjs.map → chunk-BBC5JYC4.mjs.map} +0 -0
  53. /package/lib/node/{chunk-6DIWEMO7.mjs.map → chunk-SYHIUXN7.mjs.map} +0 -0
@@ -124,13 +124,17 @@ async function handleRequest(options) {
124
124
  });
125
125
  const requestAbortPromise = new DeferredPromise2();
126
126
  if (options.request.signal) {
127
- options.request.signal.addEventListener(
128
- "abort",
129
- () => {
130
- requestAbortPromise.reject(options.request.signal.reason);
131
- },
132
- { once: true }
133
- );
127
+ if (options.request.signal.aborted) {
128
+ requestAbortPromise.reject(options.request.signal.reason);
129
+ } else {
130
+ options.request.signal.addEventListener(
131
+ "abort",
132
+ () => {
133
+ requestAbortPromise.reject(options.request.signal.reason);
134
+ },
135
+ { once: true }
136
+ );
137
+ }
134
138
  }
135
139
  const result = await until(async () => {
136
140
  const requestListtenersPromise = emitAsync(options.emitter, "request", {
@@ -193,4 +197,4 @@ export {
193
197
  emitAsync,
194
198
  handleRequest
195
199
  };
196
- //# sourceMappingURL=chunk-4K55BZMG.mjs.map
200
+ //# sourceMappingURL=chunk-4RQHC4IY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/RequestController.ts","../../src/InterceptorError.ts","../../src/utils/emitAsync.ts","../../src/utils/handleRequest.ts","../../src/utils/isNodeLikeError.ts"],"sourcesContent":["import { invariant } from 'outvariant'\nimport { DeferredPromise } from '@open-draft/deferred-promise'\nimport { InterceptorError } from './InterceptorError'\n\nconst kRequestHandled = Symbol('kRequestHandled')\nexport const kResponsePromise = Symbol('kResponsePromise')\n\nexport class RequestController {\n /**\n * Internal response promise.\n * Available only for the library internals to grab the\n * response instance provided by the developer.\n * @note This promise cannot be rejected. It's either infinitely\n * pending or resolved with whichever Response was passed to `respondWith()`.\n */\n [kResponsePromise]: DeferredPromise<Response | Error | undefined>;\n\n /**\n * Internal flag indicating if this request has been handled.\n * @note The response promise becomes \"fulfilled\" on the next tick.\n */\n [kRequestHandled]: boolean\n\n constructor(private request: Request) {\n this[kRequestHandled] = false\n this[kResponsePromise] = new DeferredPromise()\n }\n\n /**\n * Respond to this request with the given `Response` instance.\n * @example\n * controller.respondWith(new Response())\n * controller.respondWith(Response.json({ id }))\n * controller.respondWith(Response.error())\n */\n public respondWith(response: Response): void {\n invariant.as(\n InterceptorError,\n !this[kRequestHandled],\n 'Failed to respond to the \"%s %s\" request: the \"request\" event has already been handled.',\n this.request.method,\n this.request.url\n )\n\n this[kRequestHandled] = true\n this[kResponsePromise].resolve(response)\n\n /**\n * @note The request conrtoller doesn't do anything\n * apart from letting the interceptor await the response\n * provided by the developer through the response promise.\n * Each interceptor implements the actual respondWith/errorWith\n * logic based on that interceptor's needs.\n */\n }\n\n /**\n * Error this request with the given error.\n * @example\n * controller.errorWith()\n * controller.errorWith(new Error('Oops!'))\n */\n public errorWith(error?: Error): void {\n invariant.as(\n InterceptorError,\n !this[kRequestHandled],\n 'Failed to error the \"%s %s\" request: the \"request\" event has already been handled.',\n this.request.method,\n this.request.url\n )\n\n this[kRequestHandled] = true\n\n /**\n * @note Resolve the response promise, not reject.\n * This helps us differentiate between unhandled exceptions\n * and intended errors (\"errorWith\") while waiting for the response.\n */\n this[kResponsePromise].resolve(error)\n }\n}\n","export class InterceptorError extends Error {\n constructor(message?: string) {\n super(message)\n this.name = 'InterceptorError'\n Object.setPrototypeOf(this, InterceptorError.prototype)\n }\n}\n","import { Emitter, EventMap } from 'strict-event-emitter'\n\n/**\n * Emits an event on the given emitter but executes\n * the listeners sequentially. This accounts for asynchronous\n * listeners (e.g. those having \"sleep\" and handling the request).\n */\nexport async function emitAsync<\n Events extends EventMap,\n EventName extends keyof Events\n>(\n emitter: Emitter<Events>,\n eventName: EventName,\n ...data: Events[EventName]\n): Promise<void> {\n const listners = emitter.listeners(eventName)\n\n if (listners.length === 0) {\n return\n }\n\n for (const listener of listners) {\n await listener.apply(emitter, data)\n }\n}\n","import type { Emitter } from 'strict-event-emitter'\nimport { DeferredPromise } from '@open-draft/deferred-promise'\nimport { until } from '@open-draft/until'\nimport type { HttpRequestEventMap } from '../glossary'\nimport { emitAsync } from './emitAsync'\nimport { kResponsePromise, RequestController } from '../RequestController'\nimport {\n createServerErrorResponse,\n isResponseError,\n ResponseError,\n} from './responseUtils'\nimport { InterceptorError } from '../InterceptorError'\nimport { isNodeLikeError } from './isNodeLikeError'\n\ninterface HandleRequestOptions {\n requestId: string\n request: Request\n emitter: Emitter<HttpRequestEventMap>\n controller: RequestController\n\n /**\n * Called when the request has been handled\n * with the given `Response` instance.\n */\n onResponse: (response: Response) => void | Promise<void>\n\n /**\n * Called when the request has been handled\n * with the given `Response.error()` instance.\n */\n onRequestError: (response: ResponseError) => void\n\n /**\n * Called when an unhandled error happens during the\n * request handling. This is never a thrown error/response.\n */\n onError: (error: unknown) => void\n}\n\n/**\n * @returns {Promise<boolean>} Indicates whether the request has been handled.\n */\nexport async function handleRequest(\n options: HandleRequestOptions\n): Promise<boolean> {\n const handleResponse = async (response: Response | Error) => {\n if (response instanceof Error) {\n options.onError(response)\n }\n\n // Handle \"Response.error()\" instances.\n else if (isResponseError(response)) {\n options.onRequestError(response)\n } else {\n await options.onResponse(response)\n }\n\n return true\n }\n\n const handleResponseError = async (error: unknown): Promise<boolean> => {\n // Forward the special interceptor error instances\n // to the developer. These must not be handled in any way.\n if (error instanceof InterceptorError) {\n throw result.error\n }\n\n // Support mocking Node.js-like errors.\n if (isNodeLikeError(error)) {\n options.onError(error)\n return true\n }\n\n // Handle thrown responses.\n if (error instanceof Response) {\n return await handleResponse(error)\n }\n\n return false\n }\n\n // Add the last \"request\" listener to check if the request\n // has been handled in any way. If it hasn't, resolve the\n // response promise with undefined.\n options.emitter.once('request', ({ requestId: pendingRequestId }) => {\n if (pendingRequestId !== options.requestId) {\n return\n }\n\n if (options.controller[kResponsePromise].state === 'pending') {\n options.controller[kResponsePromise].resolve(undefined)\n }\n })\n\n const requestAbortPromise = new DeferredPromise<void, unknown>()\n\n /**\n * @note `signal` is not always defined in React Native.\n */\n if (options.request.signal) {\n if (options.request.signal.aborted) {\n requestAbortPromise.reject(options.request.signal.reason)\n } else {\n options.request.signal.addEventListener(\n 'abort',\n () => {\n requestAbortPromise.reject(options.request.signal.reason)\n },\n { once: true }\n )\n }\n }\n\n const result = await until(async () => {\n // Emit the \"request\" event and wait until all the listeners\n // for that event are finished (e.g. async listeners awaited).\n // By the end of this promise, the developer cannot affect the\n // request anymore.\n const requestListtenersPromise = emitAsync(options.emitter, 'request', {\n requestId: options.requestId,\n request: options.request,\n controller: options.controller,\n })\n\n await Promise.race([\n // Short-circuit the request handling promise if the request gets aborted.\n requestAbortPromise,\n requestListtenersPromise,\n options.controller[kResponsePromise],\n ])\n\n // The response promise will settle immediately once\n // the developer calls either \"respondWith\" or \"errorWith\".\n const mockedResponse = await options.controller[kResponsePromise]\n return mockedResponse\n })\n\n // Handle the request being aborted while waiting for the request listeners.\n if (requestAbortPromise.state === 'rejected') {\n options.onError(requestAbortPromise.rejectionReason)\n return true\n }\n\n if (result.error) {\n // Handle the error during the request listener execution.\n // These can be thrown responses or request errors.\n if (await handleResponseError(result.error)) {\n return true\n }\n\n // If the developer has added \"unhandledException\" listeners,\n // allow them to handle the error. They can translate it to a\n // mocked response, network error, or forward it as-is.\n if (options.emitter.listenerCount('unhandledException') > 0) {\n // Create a new request controller just for the unhandled exception case.\n // This is needed because the original controller might have been already\n // interacted with (e.g. \"respondWith\" or \"errorWith\" called on it).\n const unhandledExceptionController = new RequestController(\n options.request\n )\n\n await emitAsync(options.emitter, 'unhandledException', {\n error: result.error,\n request: options.request,\n requestId: options.requestId,\n controller: unhandledExceptionController,\n }).then(() => {\n // If all the \"unhandledException\" listeners have finished\n // but have not handled the response in any way, preemptively\n // resolve the pending response promise from the new controller.\n // This prevents it from hanging forever.\n if (\n unhandledExceptionController[kResponsePromise].state === 'pending'\n ) {\n unhandledExceptionController[kResponsePromise].resolve(undefined)\n }\n })\n\n const nextResult = await until(\n () => unhandledExceptionController[kResponsePromise]\n )\n\n /**\n * @note Handle the result of the unhandled controller\n * in the same way as the original request controller.\n * The exception here is that thrown errors within the\n * \"unhandledException\" event do NOT result in another\n * emit of the same event. They are forwarded as-is.\n */\n if (nextResult.error) {\n return handleResponseError(nextResult.error)\n }\n\n if (nextResult.data) {\n return handleResponse(nextResult.data)\n }\n }\n\n // Otherwise, coerce unhandled exceptions to a 500 Internal Server Error response.\n options.onResponse(createServerErrorResponse(result.error))\n return true\n }\n\n /**\n * Handle a mocked Response instance.\n * @note That this can also be an Error in case\n * the developer called \"errorWith\". This differentiates\n * unhandled exceptions from intended errors.\n */\n if (result.data) {\n return handleResponse(result.data)\n }\n\n // In all other cases, consider the request unhandled.\n // The interceptor must perform it as-is.\n return false\n}\n","export function isNodeLikeError(\n error: unknown\n): error is NodeJS.ErrnoException {\n if (error == null) {\n return false\n }\n\n if (!(error instanceof Error)) {\n return false\n }\n\n return 'code' in error && 'errno' in error\n}\n"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;;;ACDzB,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,SAAkB;AAC5B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,iBAAiB,SAAS;AAAA,EACxD;AACF;;;ADFA,IAAM,kBAAkB,OAAO,iBAAiB;AACzC,IAAM,mBAAmB,OAAO,kBAAkB;AAElD,IAAM,oBAAN,MAAwB;AAAA,EAgB7B,YAAoB,SAAkB;AAAlB;AAClB,SAAK,eAAe,IAAI;AACxB,SAAK,gBAAgB,IAAI,IAAI,gBAAgB;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,YAAY,UAA0B;AAC3C,cAAU;AAAA,MACR;AAAA,MACA,CAAC,KAAK,eAAe;AAAA,MACrB;AAAA,MACA,KAAK,QAAQ;AAAA,MACb,KAAK,QAAQ;AAAA,IACf;AAEA,SAAK,eAAe,IA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,oBAAoB,IAAI,GAAG;AAI3D,YAAM,+BAA+B,IAAI;AAAA,QACvC,QAAQ;AAAA,MACV;AAEA,YAAM,UAAU,QAAQ,SAAS,sBAAsB;AAAA,QACrD,OAAO,OAAO;AAAA,QACd,SAAS,QAAQ;AAAA,QACjB,WAAW,QAAQ;AAAA,QACnB,YAAY;AAAA,MACd,CAAC,EAAE,KAAK,MAAM;AAKZ,YACE,6BAA6B,gBAAgB,EAAE,UAAU,WACzD;AACA,uCAA6B,gBAAgB,EAAE,QAAQ,MAAS;AAAA,QAClE;AAAA,MACF,CAAC;AAED,YAAM,aAAa,MAAM;AAAA,QACvB,MAAM,6BAA6B,gBAAgB;AAAA,MACrD;AASA,UAAI,WAAW,OAAO;AACpB,eAAO,oBAAoB,WAAW,KAAK;AAAA,MAC7C;AAEA,UAAI,WAAW,MAAM;AACnB,eAAO,eAAe,WAAW,IAAI;AAAA,MACvC;AAAA,IACF;AAGA,YAAQ,WAAW,0BAA0B,OAAO,KAAK,CAAC;AAC1D,WAAO;AAAA,EACT;AAQA,MAAI,OAAO,MAAM;AACf,WAAO,eAAe,OAAO,IAAI;AAAA,EACnC;AAIA,SAAO;AACT;","names":["DeferredPromise","DeferredPromise"]}
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkUXPG527Ijs = require('./chunk-UXPG527I.js');
5
+ var _chunkCK3NCGUGjs = require('./chunk-CK3NCGUG.js');
6
6
 
7
7
 
8
8
 
@@ -188,14 +188,14 @@ var _FetchInterceptor = class extends _chunkTIPR373Rjs.Interceptor {
188
188
  const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.origin) : input;
189
189
  const request = new Request(resolvedInput, init);
190
190
  const responsePromise = new (0, _deferredpromise.DeferredPromise)();
191
- const controller = new (0, _chunkUXPG527Ijs.RequestController)(request);
191
+ const controller = new (0, _chunkCK3NCGUGjs.RequestController)(request);
192
192
  this.logger.info("[%s] %s", request.method, request.url);
193
193
  this.logger.info("awaiting for the mocked response...");
194
194
  this.logger.info(
195
195
  'emitting the "request" event for %s listener(s)...',
196
196
  this.emitter.listenerCount("request")
197
197
  );
198
- const isRequestHandled = await _chunkUXPG527Ijs.handleRequest.call(void 0, {
198
+ const isRequestHandled = await _chunkCK3NCGUGjs.handleRequest.call(void 0, {
199
199
  request,
200
200
  requestId,
201
201
  emitter: this.emitter,
@@ -231,7 +231,7 @@ var _FetchInterceptor = class extends _chunkTIPR373Rjs.Interceptor {
231
231
  });
232
232
  if (this.emitter.listenerCount("response") > 0) {
233
233
  this.logger.info('emitting the "response" event...');
234
- await _chunkUXPG527Ijs.emitAsync.call(void 0, this.emitter, "response", {
234
+ await _chunkCK3NCGUGjs.emitAsync.call(void 0, this.emitter, "response", {
235
235
  // Clone the mocked response for the "response" event listener.
236
236
  // This way, the listener can read the response and not lock its body
237
237
  // for the actual fetch consumer.
@@ -264,7 +264,7 @@ var _FetchInterceptor = class extends _chunkTIPR373Rjs.Interceptor {
264
264
  if (this.emitter.listenerCount("response") > 0) {
265
265
  this.logger.info('emitting the "response" event...');
266
266
  const responseClone = response.clone();
267
- await _chunkUXPG527Ijs.emitAsync.call(void 0, this.emitter, "response", {
267
+ await _chunkCK3NCGUGjs.emitAsync.call(void 0, this.emitter, "response", {
268
268
  response: responseClone,
269
269
  isMockedResponse: false,
270
270
  request,
@@ -297,4 +297,4 @@ FetchInterceptor.symbol = Symbol("fetch");
297
297
 
298
298
 
299
299
  exports.FetchInterceptor = FetchInterceptor;
300
- //# sourceMappingURL=chunk-LMBCDE7C.js.map
300
+ //# sourceMappingURL=chunk-CAAXYHKD.js.map
@@ -124,13 +124,17 @@ async function handleRequest(options) {
124
124
  });
125
125
  const requestAbortPromise = new (0, _deferredpromise.DeferredPromise)();
126
126
  if (options.request.signal) {
127
- options.request.signal.addEventListener(
128
- "abort",
129
- () => {
130
- requestAbortPromise.reject(options.request.signal.reason);
131
- },
132
- { once: true }
133
- );
127
+ if (options.request.signal.aborted) {
128
+ requestAbortPromise.reject(options.request.signal.reason);
129
+ } else {
130
+ options.request.signal.addEventListener(
131
+ "abort",
132
+ () => {
133
+ requestAbortPromise.reject(options.request.signal.reason);
134
+ },
135
+ { once: true }
136
+ );
137
+ }
134
138
  }
135
139
  const result = await _until.until.call(void 0, async () => {
136
140
  const requestListtenersPromise = emitAsync(options.emitter, "request", {
@@ -193,4 +197,4 @@ async function handleRequest(options) {
193
197
 
194
198
 
195
199
  exports.RequestController = RequestController; exports.emitAsync = emitAsync; exports.handleRequest = handleRequest;
196
- //# sourceMappingURL=chunk-UXPG527I.js.map
200
+ //# sourceMappingURL=chunk-CK3NCGUG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/RequestController.ts","../../src/InterceptorError.ts","../../src/utils/emitAsync.ts","../../src/utils/handleRequest.ts","../../src/utils/isNodeLikeError.ts"],"names":["DeferredPromise"],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;;;ACDzB,IAAM,mBAAN,cAA+B,MAAM;AAAA,EAC1C,YAAY,SAAkB;AAC5B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,WAAO,eAAe,MAAM,iBAAiB,SAAS;AAAA,EACxD;AACF;;;ADFA,IAAM,kBAAkB,OAAO,iBAAiB;AACzC,IAAM,mBAAmB,OAAO,kBAAkB;AAElD,IAAM,oBAAN,MAAwB;AAAA,EAgB7B,YAAoB,SAAkB;AAAlB;AAClB,SAAK,eAAe,IAAI;AACxB,SAAK,gBAAgB,IAAI,IAAI,gBAAgB;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASO,YAAY,UAA0B;AAC3C,cAAU;AAAA,MACR;AAAA,MACA,CAAC,KAAK,eAAe;AAAA,MACrB;AAAA,MACA,KAAK,QAAQ;AAAA,MACb,KAAK,QAAQ;AAAA,IACf;AAEA,SAAK,eAAe,IAAI;AACxB,SAAK,gBAAgB,EAAE,QAAQ,QAAQ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IAAI;AAAA,QACvC,QAAQ;AAAA,MACV;AAEA,YAAM,UAAU,QAAQ,SAAS,sBAAsB;AAAA,QACrD,OAAO,OAAO;AAAA,QACd,SAAS,QAAQ;AAAA,QACjB,WAAW,QAAQ;AAAA,QACnB,YAAY;AAAA,MACd,CAAC,EAAE,KAAK,MAAM;AAKZ,YACE,6BAA6B,gBAAgB,EAAE,UAAU,WACzD;AACA,uCAA6B,gBAAgB,EAAE,QAAQ,MAAS;AAAA,QAClE;AAAA,MACF,CAAC;AAED,YAAM,aAAa,MAAM;AAAA,QACvB,MAAM,6BAA6B,gBAAgB;AAAA,MACrD;AASA,UAAI,WAAW,OAAO;AACpB,eAAO,oBAAoB,WAAW,KAAK;AAAA,MAC7C;AAEA,UAAI,WAAW,MAAM;AACnB,eAAO,eAAe,WAAW,IAAI;AAAA,MACvC;AAAA,IACF;AAGA,YAAQ,WAAW,0BAA0B,OAAO,KAAK,CAAC;AAC1D,WAAO;AAAA,EACT;AAQA,MAAI,OAAO,MAAM;AACf,WAAO,eAAe,OAAO,IAAI;AAAA,EACnC;AAIA,SAAO;AACT","sourcesContent":["import { invariant } from 'outvariant'\nimport { DeferredPromise } from '@open-draft/deferred-promise'\nimport { InterceptorError } from './InterceptorError'\n\nconst kRequestHandled = Symbol('kRequestHandled')\nexport const kResponsePromise = Symbol('kResponsePromise')\n\nexport class RequestController {\n /**\n * Internal response promise.\n * Available only for the library internals to grab the\n * response instance provided by the developer.\n * @note This promise cannot be rejected. It's either infinitely\n * pending or resolved with whichever Response was passed to `respondWith()`.\n */\n [kResponsePromise]: DeferredPromise<Response | Error | undefined>;\n\n /**\n * Internal flag indicating if this request has been handled.\n * @note The response promise becomes \"fulfilled\" on the next tick.\n */\n [kRequestHandled]: boolean\n\n constructor(private request: Request) {\n this[kRequestHandled] = false\n this[kResponsePromise] = new DeferredPromise()\n }\n\n /**\n * Respond to this request with the given `Response` instance.\n * @example\n * controller.respondWith(new Response())\n * controller.respondWith(Response.json({ id }))\n * controller.respondWith(Response.error())\n */\n public respondWith(response: Response): void {\n invariant.as(\n InterceptorError,\n !this[kRequestHandled],\n 'Failed to respond to the \"%s %s\" request: the \"request\" event has already been handled.',\n this.request.method,\n this.request.url\n )\n\n this[kRequestHandled] = true\n this[kResponsePromise].resolve(response)\n\n /**\n * @note The request conrtoller doesn't do anything\n * apart from letting the interceptor await the response\n * provided by the developer through the response promise.\n * Each interceptor implements the actual respondWith/errorWith\n * logic based on that interceptor's needs.\n */\n }\n\n /**\n * Error this request with the given error.\n * @example\n * controller.errorWith()\n * controller.errorWith(new Error('Oops!'))\n */\n public errorWith(error?: Error): void {\n invariant.as(\n InterceptorError,\n !this[kRequestHandled],\n 'Failed to error the \"%s %s\" request: the \"request\" event has already been handled.',\n this.request.method,\n this.request.url\n )\n\n this[kRequestHandled] = true\n\n /**\n * @note Resolve the response promise, not reject.\n * This helps us differentiate between unhandled exceptions\n * and intended errors (\"errorWith\") while waiting for the response.\n */\n this[kResponsePromise].resolve(error)\n }\n}\n","export class InterceptorError extends Error {\n constructor(message?: string) {\n super(message)\n this.name = 'InterceptorError'\n Object.setPrototypeOf(this, InterceptorError.prototype)\n }\n}\n","import { Emitter, EventMap } from 'strict-event-emitter'\n\n/**\n * Emits an event on the given emitter but executes\n * the listeners sequentially. This accounts for asynchronous\n * listeners (e.g. those having \"sleep\" and handling the request).\n */\nexport async function emitAsync<\n Events extends EventMap,\n EventName extends keyof Events\n>(\n emitter: Emitter<Events>,\n eventName: EventName,\n ...data: Events[EventName]\n): Promise<void> {\n const listners = emitter.listeners(eventName)\n\n if (listners.length === 0) {\n return\n }\n\n for (const listener of listners) {\n await listener.apply(emitter, data)\n }\n}\n","import type { Emitter } from 'strict-event-emitter'\nimport { DeferredPromise } from '@open-draft/deferred-promise'\nimport { until } from '@open-draft/until'\nimport type { HttpRequestEventMap } from '../glossary'\nimport { emitAsync } from './emitAsync'\nimport { kResponsePromise, RequestController } from '../RequestController'\nimport {\n createServerErrorResponse,\n isResponseError,\n ResponseError,\n} from './responseUtils'\nimport { InterceptorError } from '../InterceptorError'\nimport { isNodeLikeError } from './isNodeLikeError'\n\ninterface HandleRequestOptions {\n requestId: string\n request: Request\n emitter: Emitter<HttpRequestEventMap>\n controller: RequestController\n\n /**\n * Called when the request has been handled\n * with the given `Response` instance.\n */\n onResponse: (response: Response) => void | Promise<void>\n\n /**\n * Called when the request has been handled\n * with the given `Response.error()` instance.\n */\n onRequestError: (response: ResponseError) => void\n\n /**\n * Called when an unhandled error happens during the\n * request handling. This is never a thrown error/response.\n */\n onError: (error: unknown) => void\n}\n\n/**\n * @returns {Promise<boolean>} Indicates whether the request has been handled.\n */\nexport async function handleRequest(\n options: HandleRequestOptions\n): Promise<boolean> {\n const handleResponse = async (response: Response | Error) => {\n if (response instanceof Error) {\n options.onError(response)\n }\n\n // Handle \"Response.error()\" instances.\n else if (isResponseError(response)) {\n options.onRequestError(response)\n } else {\n await options.onResponse(response)\n }\n\n return true\n }\n\n const handleResponseError = async (error: unknown): Promise<boolean> => {\n // Forward the special interceptor error instances\n // to the developer. These must not be handled in any way.\n if (error instanceof InterceptorError) {\n throw result.error\n }\n\n // Support mocking Node.js-like errors.\n if (isNodeLikeError(error)) {\n options.onError(error)\n return true\n }\n\n // Handle thrown responses.\n if (error instanceof Response) {\n return await handleResponse(error)\n }\n\n return false\n }\n\n // Add the last \"request\" listener to check if the request\n // has been handled in any way. If it hasn't, resolve the\n // response promise with undefined.\n options.emitter.once('request', ({ requestId: pendingRequestId }) => {\n if (pendingRequestId !== options.requestId) {\n return\n }\n\n if (options.controller[kResponsePromise].state === 'pending') {\n options.controller[kResponsePromise].resolve(undefined)\n }\n })\n\n const requestAbortPromise = new DeferredPromise<void, unknown>()\n\n /**\n * @note `signal` is not always defined in React Native.\n */\n if (options.request.signal) {\n if (options.request.signal.aborted) {\n requestAbortPromise.reject(options.request.signal.reason)\n } else {\n options.request.signal.addEventListener(\n 'abort',\n () => {\n requestAbortPromise.reject(options.request.signal.reason)\n },\n { once: true }\n )\n }\n }\n\n const result = await until(async () => {\n // Emit the \"request\" event and wait until all the listeners\n // for that event are finished (e.g. async listeners awaited).\n // By the end of this promise, the developer cannot affect the\n // request anymore.\n const requestListtenersPromise = emitAsync(options.emitter, 'request', {\n requestId: options.requestId,\n request: options.request,\n controller: options.controller,\n })\n\n await Promise.race([\n // Short-circuit the request handling promise if the request gets aborted.\n requestAbortPromise,\n requestListtenersPromise,\n options.controller[kResponsePromise],\n ])\n\n // The response promise will settle immediately once\n // the developer calls either \"respondWith\" or \"errorWith\".\n const mockedResponse = await options.controller[kResponsePromise]\n return mockedResponse\n })\n\n // Handle the request being aborted while waiting for the request listeners.\n if (requestAbortPromise.state === 'rejected') {\n options.onError(requestAbortPromise.rejectionReason)\n return true\n }\n\n if (result.error) {\n // Handle the error during the request listener execution.\n // These can be thrown responses or request errors.\n if (await handleResponseError(result.error)) {\n return true\n }\n\n // If the developer has added \"unhandledException\" listeners,\n // allow them to handle the error. They can translate it to a\n // mocked response, network error, or forward it as-is.\n if (options.emitter.listenerCount('unhandledException') > 0) {\n // Create a new request controller just for the unhandled exception case.\n // This is needed because the original controller might have been already\n // interacted with (e.g. \"respondWith\" or \"errorWith\" called on it).\n const unhandledExceptionController = new RequestController(\n options.request\n )\n\n await emitAsync(options.emitter, 'unhandledException', {\n error: result.error,\n request: options.request,\n requestId: options.requestId,\n controller: unhandledExceptionController,\n }).then(() => {\n // If all the \"unhandledException\" listeners have finished\n // but have not handled the response in any way, preemptively\n // resolve the pending response promise from the new controller.\n // This prevents it from hanging forever.\n if (\n unhandledExceptionController[kResponsePromise].state === 'pending'\n ) {\n unhandledExceptionController[kResponsePromise].resolve(undefined)\n }\n })\n\n const nextResult = await until(\n () => unhandledExceptionController[kResponsePromise]\n )\n\n /**\n * @note Handle the result of the unhandled controller\n * in the same way as the original request controller.\n * The exception here is that thrown errors within the\n * \"unhandledException\" event do NOT result in another\n * emit of the same event. They are forwarded as-is.\n */\n if (nextResult.error) {\n return handleResponseError(nextResult.error)\n }\n\n if (nextResult.data) {\n return handleResponse(nextResult.data)\n }\n }\n\n // Otherwise, coerce unhandled exceptions to a 500 Internal Server Error response.\n options.onResponse(createServerErrorResponse(result.error))\n return true\n }\n\n /**\n * Handle a mocked Response instance.\n * @note That this can also be an Error in case\n * the developer called \"errorWith\". This differentiates\n * unhandled exceptions from intended errors.\n */\n if (result.data) {\n return handleResponse(result.data)\n }\n\n // In all other cases, consider the request unhandled.\n // The interceptor must perform it as-is.\n return false\n}\n","export function isNodeLikeError(\n error: unknown\n): error is NodeJS.ErrnoException {\n if (error == null) {\n return false\n }\n\n if (!(error instanceof Error)) {\n return false\n }\n\n return 'code' in error && 'errno' in error\n}\n"]}
@@ -6,7 +6,7 @@ import {
6
6
  import {
7
7
  RequestController,
8
8
  handleRequest
9
- } from "./chunk-4K55BZMG.mjs";
9
+ } from "./chunk-4RQHC4IY.mjs";
10
10
  import {
11
11
  IS_PATCHED_MODULE,
12
12
  isResponseWithoutBody
@@ -840,4 +840,4 @@ XMLHttpRequestInterceptor.interceptorSymbol = Symbol("xhr");
840
840
  export {
841
841
  XMLHttpRequestInterceptor
842
842
  };
843
- //# sourceMappingURL=chunk-Q7PXVXSL.mjs.map
843
+ //# sourceMappingURL=chunk-MMAVIMED.mjs.map
@@ -6,7 +6,7 @@ var _chunkLK6DILFKjs = require('./chunk-LK6DILFK.js');
6
6
 
7
7
 
8
8
 
9
- var _chunkUXPG527Ijs = require('./chunk-UXPG527I.js');
9
+ var _chunkCK3NCGUGjs = require('./chunk-CK3NCGUG.js');
10
10
 
11
11
 
12
12
 
@@ -740,13 +740,13 @@ function createXMLHttpRequestProxy({
740
740
  logger
741
741
  );
742
742
  xhrRequestController.onRequest = async function({ request, requestId }) {
743
- const controller = new (0, _chunkUXPG527Ijs.RequestController)(request);
743
+ const controller = new (0, _chunkCK3NCGUGjs.RequestController)(request);
744
744
  this.logger.info("awaiting mocked response...");
745
745
  this.logger.info(
746
746
  'emitting the "request" event for %s listener(s)...',
747
747
  emitter.listenerCount("request")
748
748
  );
749
- const isRequestHandled = await _chunkUXPG527Ijs.handleRequest.call(void 0, {
749
+ const isRequestHandled = await _chunkCK3NCGUGjs.handleRequest.call(void 0, {
750
750
  request,
751
751
  requestId,
752
752
  controller,
@@ -840,4 +840,4 @@ XMLHttpRequestInterceptor.interceptorSymbol = Symbol("xhr");
840
840
 
841
841
 
842
842
  exports.XMLHttpRequestInterceptor = XMLHttpRequestInterceptor;
843
- //# sourceMappingURL=chunk-RKQSZCUD.js.map
843
+ //# sourceMappingURL=chunk-NNR7JKYY.js.map
@@ -2,7 +2,7 @@ import {
2
2
  RequestController,
3
3
  emitAsync,
4
4
  handleRequest
5
- } from "./chunk-4K55BZMG.mjs";
5
+ } from "./chunk-4RQHC4IY.mjs";
6
6
  import {
7
7
  IS_PATCHED_MODULE,
8
8
  RESPONSE_STATUS_CODES_WITH_REDIRECT
@@ -297,4 +297,4 @@ FetchInterceptor.symbol = Symbol("fetch");
297
297
  export {
298
298
  FetchInterceptor
299
299
  };
300
- //# sourceMappingURL=chunk-C6BKAAQW.mjs.map
300
+ //# sourceMappingURL=chunk-VXLPKFY4.mjs.map
@@ -1,12 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkRKQSZCUDjs = require('../../chunk-RKQSZCUD.js');
3
+ var _chunkNNR7JKYYjs = require('../../chunk-NNR7JKYY.js');
4
4
  require('../../chunk-LK6DILFK.js');
5
- require('../../chunk-UXPG527I.js');
5
+ require('../../chunk-CK3NCGUG.js');
6
6
  require('../../chunk-7TPGF5DM.js');
7
7
  require('../../chunk-PFGO5BSM.js');
8
8
  require('../../chunk-TIPR373R.js');
9
9
 
10
10
 
11
- exports.XMLHttpRequestInterceptor = _chunkRKQSZCUDjs.XMLHttpRequestInterceptor;
11
+ exports.XMLHttpRequestInterceptor = _chunkNNR7JKYYjs.XMLHttpRequestInterceptor;
12
12
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  XMLHttpRequestInterceptor
3
- } from "../../chunk-Q7PXVXSL.mjs";
3
+ } from "../../chunk-MMAVIMED.mjs";
4
4
  import "../../chunk-6HYIRFX2.mjs";
5
- import "../../chunk-4K55BZMG.mjs";
5
+ import "../../chunk-4RQHC4IY.mjs";
6
6
  import "../../chunk-6MOMO77R.mjs";
7
7
  import "../../chunk-TX5GBTFY.mjs";
8
8
  import "../../chunk-QED3Q6Z2.mjs";
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkLMBCDE7Cjs = require('../../chunk-LMBCDE7C.js');
4
- require('../../chunk-UXPG527I.js');
3
+ var _chunkCAAXYHKDjs = require('../../chunk-CAAXYHKD.js');
4
+ require('../../chunk-CK3NCGUG.js');
5
5
  require('../../chunk-7TPGF5DM.js');
6
6
  require('../../chunk-PFGO5BSM.js');
7
7
  require('../../chunk-TIPR373R.js');
8
8
 
9
9
 
10
- exports.FetchInterceptor = _chunkLMBCDE7Cjs.FetchInterceptor;
10
+ exports.FetchInterceptor = _chunkCAAXYHKDjs.FetchInterceptor;
11
11
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FetchInterceptor
3
- } from "../../chunk-C6BKAAQW.mjs";
4
- import "../../chunk-4K55BZMG.mjs";
3
+ } from "../../chunk-VXLPKFY4.mjs";
4
+ import "../../chunk-4RQHC4IY.mjs";
5
5
  import "../../chunk-6MOMO77R.mjs";
6
6
  import "../../chunk-TX5GBTFY.mjs";
7
7
  import "../../chunk-QED3Q6Z2.mjs";
@@ -1,19 +1,19 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkRKQSZCUDjs = require('../chunk-RKQSZCUD.js');
3
+ var _chunkNNR7JKYYjs = require('../chunk-NNR7JKYY.js');
4
4
  require('../chunk-LK6DILFK.js');
5
5
 
6
6
 
7
- var _chunkLMBCDE7Cjs = require('../chunk-LMBCDE7C.js');
8
- require('../chunk-UXPG527I.js');
7
+ var _chunkCAAXYHKDjs = require('../chunk-CAAXYHKD.js');
8
+ require('../chunk-CK3NCGUG.js');
9
9
  require('../chunk-7TPGF5DM.js');
10
10
  require('../chunk-PFGO5BSM.js');
11
11
  require('../chunk-TIPR373R.js');
12
12
 
13
13
  // src/presets/browser.ts
14
14
  var browser_default = [
15
- new (0, _chunkLMBCDE7Cjs.FetchInterceptor)(),
16
- new (0, _chunkRKQSZCUDjs.XMLHttpRequestInterceptor)()
15
+ new (0, _chunkCAAXYHKDjs.FetchInterceptor)(),
16
+ new (0, _chunkNNR7JKYYjs.XMLHttpRequestInterceptor)()
17
17
  ];
18
18
 
19
19
 
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  XMLHttpRequestInterceptor
3
- } from "../chunk-Q7PXVXSL.mjs";
3
+ } from "../chunk-MMAVIMED.mjs";
4
4
  import "../chunk-6HYIRFX2.mjs";
5
5
  import {
6
6
  FetchInterceptor
7
- } from "../chunk-C6BKAAQW.mjs";
8
- import "../chunk-4K55BZMG.mjs";
7
+ } from "../chunk-VXLPKFY4.mjs";
8
+ import "../chunk-4RQHC4IY.mjs";
9
9
  import "../chunk-6MOMO77R.mjs";
10
10
  import "../chunk-TX5GBTFY.mjs";
11
11
  import "../chunk-QED3Q6Z2.mjs";
@@ -3,17 +3,17 @@
3
3
  var _chunkPGTBKPWNjs = require('./chunk-PGTBKPWN.js');
4
4
 
5
5
 
6
- var _chunkFPLETXGAjs = require('./chunk-FPLETXGA.js');
6
+ var _chunkT6USXRLLjs = require('./chunk-T6USXRLL.js');
7
7
 
8
8
 
9
- var _chunkX2CFRRWYjs = require('./chunk-X2CFRRWY.js');
9
+ var _chunk7F5S3MDKjs = require('./chunk-7F5S3MDK.js');
10
10
  require('./chunk-LK6DILFK.js');
11
11
  require('./chunk-PFGO5BSM.js');
12
12
  require('./chunk-73NOP3T5.js');
13
13
 
14
14
 
15
15
 
16
- var _chunkVCUEA4PLjs = require('./chunk-VCUEA4PL.js');
16
+ var _chunkW46RNDIEjs = require('./chunk-W46RNDIE.js');
17
17
 
18
18
 
19
19
  var _chunkAABH3XLQjs = require('./chunk-AABH3XLQ.js');
@@ -24,8 +24,8 @@ var RemoteHttpInterceptor = class extends _chunkPGTBKPWNjs.BatchInterceptor {
24
24
  super({
25
25
  name: "remote-interceptor",
26
26
  interceptors: [
27
- new (0, _chunkFPLETXGAjs.ClientRequestInterceptor)(),
28
- new (0, _chunkX2CFRRWYjs.XMLHttpRequestInterceptor)()
27
+ new (0, _chunkT6USXRLLjs.ClientRequestInterceptor)(),
28
+ new (0, _chunk7F5S3MDKjs.XMLHttpRequestInterceptor)()
29
29
  ]
30
30
  });
31
31
  }
@@ -120,8 +120,8 @@ var _RemoteHttpResolver = class extends _chunkAABH3XLQjs.Interceptor {
120
120
  credentials: requestJson.credentials,
121
121
  body: requestJson.body
122
122
  });
123
- const controller = new (0, _chunkVCUEA4PLjs.RequestController)(request);
124
- await _chunkVCUEA4PLjs.handleRequest.call(void 0, {
123
+ const controller = new (0, _chunkW46RNDIEjs.RequestController)(request);
124
+ await _chunkW46RNDIEjs.handleRequest.call(void 0, {
125
125
  request,
126
126
  requestId: requestJson.id,
127
127
  controller,
@@ -3,17 +3,17 @@ import {
3
3
  } from "./chunk-3NMVZQIH.mjs";
4
4
  import {
5
5
  ClientRequestInterceptor
6
- } from "./chunk-MG3S53QP.mjs";
6
+ } from "./chunk-5VLPRS7Y.mjs";
7
7
  import {
8
8
  XMLHttpRequestInterceptor
9
- } from "./chunk-EBDS6VMR.mjs";
9
+ } from "./chunk-BBC5JYC4.mjs";
10
10
  import "./chunk-6HYIRFX2.mjs";
11
11
  import "./chunk-TX5GBTFY.mjs";
12
12
  import "./chunk-6YM4PLBI.mjs";
13
13
  import {
14
14
  RequestController,
15
15
  handleRequest
16
- } from "./chunk-M4WQE4TR.mjs";
16
+ } from "./chunk-DABV27J7.mjs";
17
17
  import {
18
18
  Interceptor
19
19
  } from "./chunk-FQQAJBI2.mjs";
@@ -2,7 +2,7 @@ import {
2
2
  RequestController,
3
3
  emitAsync,
4
4
  handleRequest
5
- } from "./chunk-M4WQE4TR.mjs";
5
+ } from "./chunk-DABV27J7.mjs";
6
6
  import {
7
7
  INTERNAL_REQUEST_ID_HEADER_NAME,
8
8
  Interceptor,
@@ -581,10 +581,8 @@ var MockHttpSocket = class extends MockSocket {
581
581
  }
582
582
  }
583
583
  flushWriteBuffer() {
584
- var _a;
585
- let args;
586
- while (args = this.writeBuffer.shift()) {
587
- (_a = args == null ? void 0 : args[2]) == null ? void 0 : _a.call(args);
584
+ for (const [, , callback] of this.writeBuffer) {
585
+ callback == null ? void 0 : callback();
588
586
  }
589
587
  }
590
588
  onRequestBody(chunk) {
@@ -1044,4 +1042,4 @@ ClientRequestInterceptor.symbol = Symbol("client-request-interceptor");
1044
1042
  export {
1045
1043
  ClientRequestInterceptor
1046
1044
  };
1047
- //# sourceMappingURL=chunk-MG3S53QP.mjs.map
1045
+ //# sourceMappingURL=chunk-5VLPRS7Y.mjs.map