@mswjs/interceptors 0.41.3 → 0.41.5
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.
- package/lib/browser/{XMLHttpRequest-BACqefB-.cjs → XMLHttpRequest-DSAhl6_a.cjs} +10 -22
- package/lib/browser/XMLHttpRequest-DSAhl6_a.cjs.map +1 -0
- package/lib/browser/{XMLHttpRequest-BvxZV0WU.mjs → XMLHttpRequest-DYyDAIJh.mjs} +10 -22
- package/lib/browser/XMLHttpRequest-DYyDAIJh.mjs.map +1 -0
- package/lib/browser/{createRequestId-Cs4oXfa1.cjs → createRequestId-DOf8Ktjs.cjs} +1 -1
- package/lib/browser/{createRequestId-Cs4oXfa1.cjs.map → createRequestId-DOf8Ktjs.cjs.map} +1 -1
- package/lib/browser/{createRequestId-DQcIlohW.mjs → createRequestId-DYCsFHOi.mjs} +1 -1
- package/lib/browser/{createRequestId-DQcIlohW.mjs.map → createRequestId-DYCsFHOi.mjs.map} +1 -1
- package/lib/browser/{fetch-U3v3Y4ap.cjs → fetch-BMC2en2x.cjs} +11 -26
- package/lib/browser/fetch-BMC2en2x.cjs.map +1 -0
- package/lib/browser/{fetch-DdKEdDOR.mjs → fetch-D5LGhx5i.mjs} +11 -26
- package/lib/browser/fetch-D5LGhx5i.mjs.map +1 -0
- package/lib/browser/{getRawRequest-zx8rUJL2.cjs → getRawRequest-B9kRTvjs.cjs} +81 -9
- package/lib/browser/getRawRequest-B9kRTvjs.cjs.map +1 -0
- package/lib/browser/{getRawRequest-BTaNLFr0.mjs → getRawRequest-BEw5hEOW.mjs} +78 -6
- package/lib/browser/getRawRequest-BEw5hEOW.mjs.map +1 -0
- package/lib/browser/{glossary-BdLS4k1H.d.cts → glossary-1lhZx6Aw.d.cts} +2 -3
- package/lib/browser/{glossary-DYwOrogs.d.mts → glossary-nkHWcwvY.d.mts} +2 -3
- package/lib/browser/{handleRequest-CvX2G-Lz.cjs → handleRequest-BCtqvFSS.cjs} +3 -3
- package/lib/browser/{handleRequest-CvX2G-Lz.cjs.map → handleRequest-BCtqvFSS.cjs.map} +1 -1
- package/lib/browser/{handleRequest-D7kpTI5U.mjs → handleRequest-DuUoGpfA.mjs} +3 -3
- package/lib/browser/{handleRequest-D7kpTI5U.mjs.map → handleRequest-DuUoGpfA.mjs.map} +1 -1
- package/lib/browser/hasConfigurableGlobal-B39W0thh.mjs +98 -0
- package/lib/browser/hasConfigurableGlobal-B39W0thh.mjs.map +1 -0
- package/lib/browser/hasConfigurableGlobal-B5o6PHq3.cjs +115 -0
- package/lib/browser/hasConfigurableGlobal-B5o6PHq3.cjs.map +1 -0
- package/lib/browser/index.cjs +3 -3
- package/lib/browser/index.d.cts +21 -2
- package/lib/browser/index.d.mts +21 -2
- package/lib/browser/index.mjs +3 -3
- package/lib/browser/interceptors/WebSocket/index.cjs +6 -10
- package/lib/browser/interceptors/WebSocket/index.cjs.map +1 -1
- package/lib/browser/interceptors/WebSocket/index.mjs +6 -10
- package/lib/browser/interceptors/WebSocket/index.mjs.map +1 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.cjs +5 -4
- package/lib/browser/interceptors/XMLHttpRequest/index.d.cts +1 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.d.mts +1 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +5 -4
- package/lib/browser/interceptors/fetch/index.cjs +5 -4
- package/lib/browser/interceptors/fetch/index.d.cts +1 -1
- package/lib/browser/interceptors/fetch/index.d.mts +1 -1
- package/lib/browser/interceptors/fetch/index.mjs +5 -4
- package/lib/browser/presets/browser.cjs +6 -5
- package/lib/browser/presets/browser.cjs.map +1 -1
- package/lib/browser/presets/browser.mjs +6 -5
- package/lib/browser/presets/browser.mjs.map +1 -1
- package/lib/node/{BatchInterceptor-3LnAnLTx.cjs → BatchInterceptor-AZr7q8p_.cjs} +2 -2
- package/lib/node/{BatchInterceptor-3LnAnLTx.cjs.map → BatchInterceptor-AZr7q8p_.cjs.map} +1 -1
- package/lib/node/{BatchInterceptor-DFaBPilf.mjs → BatchInterceptor-B2YAn5m9.mjs} +2 -2
- package/lib/node/{BatchInterceptor-DFaBPilf.mjs.map → BatchInterceptor-B2YAn5m9.mjs.map} +1 -1
- package/lib/node/{BatchInterceptor-D_YqR8qU.d.cts → BatchInterceptor-KKF8Q47I.d.cts} +2 -2
- package/lib/node/{BatchInterceptor-D7mXzHcQ.d.mts → BatchInterceptor-rSr-NH_H.d.mts} +2 -2
- package/lib/node/{ClientRequest-Ca8Qykuv.mjs → ClientRequest-5WjHvs9Y.mjs} +20 -6
- package/lib/node/ClientRequest-5WjHvs9Y.mjs.map +1 -0
- package/lib/node/{ClientRequest-2rDe54Ui.cjs → ClientRequest-BgwQG-9G.cjs} +20 -6
- package/lib/node/ClientRequest-BgwQG-9G.cjs.map +1 -0
- package/lib/node/{Interceptor-DEazpLJd.d.mts → Interceptor-BsZ21ue0.d.cts} +2 -3
- package/lib/node/{Interceptor-DJ2akVWI.d.cts → Interceptor-soD-WpQO.d.mts} +2 -3
- package/lib/node/RemoteHttpInterceptor.cjs +10 -9
- package/lib/node/RemoteHttpInterceptor.cjs.map +1 -1
- package/lib/node/RemoteHttpInterceptor.d.cts +3 -3
- package/lib/node/RemoteHttpInterceptor.d.mts +3 -3
- package/lib/node/RemoteHttpInterceptor.mjs +10 -9
- package/lib/node/RemoteHttpInterceptor.mjs.map +1 -1
- package/lib/node/{XMLHttpRequest-B7kJdYYI.cjs → XMLHttpRequest-B7sloBex.cjs} +11 -24
- package/lib/node/XMLHttpRequest-B7sloBex.cjs.map +1 -0
- package/lib/node/{XMLHttpRequest-C8dIZpds.mjs → XMLHttpRequest-DmsdUGmj.mjs} +11 -24
- package/lib/node/XMLHttpRequest-DmsdUGmj.mjs.map +1 -0
- package/lib/node/{bufferUtils-_8XfKIfX.mjs → bufferUtils-DxPxwff_.mjs} +1 -1
- package/lib/node/{bufferUtils-_8XfKIfX.mjs.map → bufferUtils-DxPxwff_.mjs.map} +1 -1
- package/lib/node/{bufferUtils-DiCTqG-7.cjs → bufferUtils-S5_-2eN4.cjs} +1 -1
- package/lib/node/{bufferUtils-DiCTqG-7.cjs.map → bufferUtils-S5_-2eN4.cjs.map} +1 -1
- package/lib/node/{fetch-G1DVwDKG.mjs → fetch-DDAGTtZi.mjs} +11 -27
- package/lib/node/fetch-DDAGTtZi.mjs.map +1 -0
- package/lib/node/{fetch-BmXpK10r.cjs → fetch-uc7pNtPg.cjs} +11 -27
- package/lib/node/fetch-uc7pNtPg.cjs.map +1 -0
- package/lib/node/{fetchUtils-CoU35g3M.mjs → fetchUtils-BJxD7wvl.mjs} +78 -2
- package/lib/node/{fetchUtils-BaY5iWXw.cjs.map → fetchUtils-BJxD7wvl.mjs.map} +1 -1
- package/lib/node/{fetchUtils-BaY5iWXw.cjs → fetchUtils-Dw6kQghF.cjs} +83 -1
- package/lib/node/fetchUtils-Dw6kQghF.cjs.map +1 -0
- package/lib/node/{getRawRequest-BavnMWh_.cjs → getRawRequest-B6znU6il.cjs} +1 -1
- package/lib/node/{getRawRequest-BavnMWh_.cjs.map → getRawRequest-B6znU6il.cjs.map} +1 -1
- package/lib/node/{getRawRequest-DnwmXyOW.mjs → getRawRequest-C2-1urzA.mjs} +1 -1
- package/lib/node/{getRawRequest-DnwmXyOW.mjs.map → getRawRequest-C2-1urzA.mjs.map} +1 -1
- package/lib/node/{handleRequest-Y97UwBbF.mjs → handleRequest-DGfUg9bm.mjs} +2 -2
- package/lib/node/{handleRequest-Y97UwBbF.mjs.map → handleRequest-DGfUg9bm.mjs.map} +1 -1
- package/lib/node/{handleRequest-Bb7Y-XLw.cjs → handleRequest-Dzg1d3e5.cjs} +2 -2
- package/lib/node/{handleRequest-Bb7Y-XLw.cjs.map → handleRequest-Dzg1d3e5.cjs.map} +1 -1
- package/lib/node/hasConfigurableGlobal-Befl_QJD.cjs +97 -0
- package/lib/node/hasConfigurableGlobal-Befl_QJD.cjs.map +1 -0
- package/lib/node/hasConfigurableGlobal-jN_-v3gp.mjs +85 -0
- package/lib/node/hasConfigurableGlobal-jN_-v3gp.mjs.map +1 -0
- package/lib/node/{index-BMbJ8FXL.d.cts → index-BJ5E5aW-.d.cts} +2 -2
- package/lib/node/{index-C0YAQ36w.d.mts → index-DfoF45ih.d.mts} +2 -2
- package/lib/node/index.cjs +5 -6
- package/lib/node/index.cjs.map +1 -1
- package/lib/node/index.d.cts +22 -3
- package/lib/node/index.d.mts +22 -3
- package/lib/node/index.mjs +5 -6
- package/lib/node/index.mjs.map +1 -1
- package/lib/node/interceptors/ClientRequest/index.cjs +4 -4
- package/lib/node/interceptors/ClientRequest/index.d.cts +1 -1
- package/lib/node/interceptors/ClientRequest/index.d.mts +2 -2
- package/lib/node/interceptors/ClientRequest/index.mjs +4 -4
- package/lib/node/interceptors/XMLHttpRequest/index.cjs +5 -4
- package/lib/node/interceptors/XMLHttpRequest/index.d.cts +1 -1
- package/lib/node/interceptors/XMLHttpRequest/index.d.mts +1 -1
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +5 -4
- package/lib/node/interceptors/fetch/index.cjs +4 -3
- package/lib/node/interceptors/fetch/index.d.cts +1 -1
- package/lib/node/interceptors/fetch/index.d.mts +1 -1
- package/lib/node/interceptors/fetch/index.mjs +4 -3
- package/lib/node/{node-dKdAf3tC.cjs → node-DIKcnzhK.cjs} +2 -2
- package/lib/node/{node-dKdAf3tC.cjs.map → node-DIKcnzhK.cjs.map} +1 -1
- package/lib/node/{node-DwCc6iuP.mjs → node-lsdNwZEW.mjs} +2 -2
- package/lib/node/{node-DwCc6iuP.mjs.map → node-lsdNwZEW.mjs.map} +1 -1
- package/lib/node/presets/node.cjs +8 -7
- package/lib/node/presets/node.cjs.map +1 -1
- package/lib/node/presets/node.d.cts +1 -1
- package/lib/node/presets/node.d.mts +2 -2
- package/lib/node/presets/node.mjs +8 -7
- package/lib/node/presets/node.mjs.map +1 -1
- package/lib/node/utils/node/index.cjs +1 -1
- package/lib/node/utils/node/index.mjs +1 -1
- package/package.json +1 -1
- package/src/RemoteHttpInterceptor.ts +2 -2
- package/src/glossary.ts +3 -5
- package/src/index.ts +1 -1
- package/src/interceptors/ClientRequest/MockHttpSocket.ts +2 -2
- package/src/interceptors/ClientRequest/utils/recordRawHeaders.ts +18 -0
- package/src/interceptors/WebSocket/index.ts +8 -15
- package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +2 -1
- package/src/interceptors/XMLHttpRequest/index.ts +12 -32
- package/src/interceptors/fetch/index.ts +10 -26
- package/src/utils/fetchUtils.test.ts +85 -0
- package/src/utils/fetchUtils.ts +139 -3
- package/src/utils/globalUtils.test.ts +144 -0
- package/src/utils/globalsRegistry.ts +107 -0
- package/src/utils/hasConfigurableGlobal.test.ts +11 -0
- package/src/utils/hasConfigurableGlobal.ts +9 -3
- package/lib/browser/XMLHttpRequest-BACqefB-.cjs.map +0 -1
- package/lib/browser/XMLHttpRequest-BvxZV0WU.mjs.map +0 -1
- package/lib/browser/fetch-DdKEdDOR.mjs.map +0 -1
- package/lib/browser/fetch-U3v3Y4ap.cjs.map +0 -1
- package/lib/browser/getRawRequest-BTaNLFr0.mjs.map +0 -1
- package/lib/browser/getRawRequest-zx8rUJL2.cjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-BvCTG97d.cjs +0 -45
- package/lib/browser/hasConfigurableGlobal-BvCTG97d.cjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-npXitu1-.mjs +0 -33
- package/lib/browser/hasConfigurableGlobal-npXitu1-.mjs.map +0 -1
- package/lib/node/ClientRequest-2rDe54Ui.cjs.map +0 -1
- package/lib/node/ClientRequest-Ca8Qykuv.mjs.map +0 -1
- package/lib/node/XMLHttpRequest-B7kJdYYI.cjs.map +0 -1
- package/lib/node/XMLHttpRequest-C8dIZpds.mjs.map +0 -1
- package/lib/node/fetch-BmXpK10r.cjs.map +0 -1
- package/lib/node/fetch-G1DVwDKG.mjs.map +0 -1
- package/lib/node/fetchUtils-CoU35g3M.mjs.map +0 -1
- package/lib/node/glossary-BLKRyLBd.cjs +0 -12
- package/lib/node/glossary-BLKRyLBd.cjs.map +0 -1
- package/lib/node/glossary-glQBRnVD.mjs +0 -6
- package/lib/node/glossary-glQBRnVD.mjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-C97fWuaA.cjs +0 -26
- package/lib/node/hasConfigurableGlobal-C97fWuaA.cjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs +0 -20
- package/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fetchUtils-CoU35g3M.mjs","names":["symbol: symbol","request: Request","source: RequestControllerSource","#handled","symbol"],"sources":["../../src/Interceptor.ts","../../src/InterceptorError.ts","../../src/RequestController.ts","../../src/createRequestId.ts","../../src/utils/canParseUrl.ts","../../src/utils/getValueBySymbol.ts","../../src/utils/fetchUtils.ts"],"sourcesContent":["import { Logger } from '@open-draft/logger'\nimport { Emitter, Listener } from 'strict-event-emitter'\n\nexport type InterceptorEventMap = Record<string, any>\nexport type InterceptorSubscription = () => void\n\n/**\n * Request header name to detect when a single request\n * is being handled by nested interceptors (XHR -> ClientRequest).\n * Obscure by design to prevent collisions with user-defined headers.\n * Ideally, come up with the Interceptor-level mechanism for this.\n * @see https://github.com/mswjs/interceptors/issues/378\n */\nexport const INTERNAL_REQUEST_ID_HEADER_NAME =\n 'x-interceptors-internal-request-id'\n\nexport function getGlobalSymbol<V>(symbol: Symbol): V | undefined {\n return (\n // @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587\n globalThis[symbol] || undefined\n )\n}\n\nfunction setGlobalSymbol(symbol: Symbol, value: any): void {\n // @ts-ignore\n globalThis[symbol] = value\n}\n\nexport function deleteGlobalSymbol(symbol: Symbol): void {\n // @ts-ignore\n delete globalThis[symbol]\n}\n\nexport enum InterceptorReadyState {\n INACTIVE = 'INACTIVE',\n APPLYING = 'APPLYING',\n APPLIED = 'APPLIED',\n DISPOSING = 'DISPOSING',\n DISPOSED = 'DISPOSED',\n}\n\nexport type ExtractEventNames<Events extends Record<string, any>> =\n Events extends Record<infer EventName, any> ? EventName : never\n\nexport class Interceptor<Events extends InterceptorEventMap> {\n protected emitter: Emitter<Events>\n protected subscriptions: Array<InterceptorSubscription>\n protected logger: Logger\n\n public readyState: InterceptorReadyState\n\n constructor(private readonly symbol: symbol) {\n this.readyState = InterceptorReadyState.INACTIVE\n\n this.emitter = new Emitter()\n this.subscriptions = []\n this.logger = new Logger(symbol.description!)\n\n // Do not limit the maximum number of listeners\n // so not to limit the maximum amount of parallel events emitted.\n this.emitter.setMaxListeners(0)\n\n this.logger.info('constructing the interceptor...')\n }\n\n /**\n * Determine if this interceptor can be applied\n * in the current environment.\n */\n protected checkEnvironment(): boolean {\n return true\n }\n\n /**\n * Apply this interceptor to the current process.\n * Returns an already running interceptor instance if it's present.\n */\n public apply(): void {\n const logger = this.logger.extend('apply')\n logger.info('applying the interceptor...')\n\n if (this.readyState === InterceptorReadyState.APPLIED) {\n logger.info('intercepted already applied!')\n return\n }\n\n const shouldApply = this.checkEnvironment()\n\n if (!shouldApply) {\n logger.info('the interceptor cannot be applied in this environment!')\n return\n }\n\n this.readyState = InterceptorReadyState.APPLYING\n\n // Whenever applying a new interceptor, check if it hasn't been applied already.\n // This enables to apply the same interceptor multiple times, for example from a different\n // interceptor, only proxying events but keeping the stubs in a single place.\n const runningInstance = this.getInstance()\n\n if (runningInstance) {\n logger.info('found a running instance, reusing...')\n\n // Proxy any listeners you set on this instance to the running instance.\n this.on = (event, listener) => {\n logger.info('proxying the \"%s\" listener', event)\n\n // Add listeners to the running instance so they appear\n // at the top of the event listeners list and are executed first.\n runningInstance.emitter.addListener(event, listener)\n\n // Ensure that once this interceptor instance is disposed,\n // it removes all listeners it has appended to the running interceptor instance.\n this.subscriptions.push(() => {\n runningInstance.emitter.removeListener(event, listener)\n logger.info('removed proxied \"%s\" listener!', event)\n })\n\n return this\n }\n\n this.readyState = InterceptorReadyState.APPLIED\n\n return\n }\n\n logger.info('no running instance found, setting up a new instance...')\n\n // Setup the interceptor.\n this.setup()\n\n // Store the newly applied interceptor instance globally.\n this.setInstance()\n\n this.readyState = InterceptorReadyState.APPLIED\n }\n\n /**\n * Setup the module augments and stubs necessary for this interceptor.\n * This method is not run if there's a running interceptor instance\n * to prevent instantiating an interceptor multiple times.\n */\n protected setup(): void {}\n\n /**\n * Listen to the interceptor's public events.\n */\n public on<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n const logger = this.logger.extend('on')\n\n if (\n this.readyState === InterceptorReadyState.DISPOSING ||\n this.readyState === InterceptorReadyState.DISPOSED\n ) {\n logger.info('cannot listen to events, already disposed!')\n return this\n }\n\n logger.info('adding \"%s\" event listener:', event, listener)\n\n this.emitter.on(event, listener)\n return this\n }\n\n public once<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n this.emitter.once(event, listener)\n return this\n }\n\n public off<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n this.emitter.off(event, listener)\n return this\n }\n\n public removeAllListeners<EventName extends ExtractEventNames<Events>>(\n event?: EventName\n ): this {\n this.emitter.removeAllListeners(event)\n return this\n }\n\n /**\n * Disposes of any side-effects this interceptor has introduced.\n */\n public dispose(): void {\n const logger = this.logger.extend('dispose')\n\n if (this.readyState === InterceptorReadyState.DISPOSED) {\n logger.info('cannot dispose, already disposed!')\n return\n }\n\n logger.info('disposing the interceptor...')\n this.readyState = InterceptorReadyState.DISPOSING\n\n if (!this.getInstance()) {\n logger.info('no interceptors running, skipping dispose...')\n return\n }\n\n // Delete the global symbol as soon as possible,\n // indicating that the interceptor is no longer running.\n this.clearInstance()\n\n logger.info('global symbol deleted:', getGlobalSymbol(this.symbol))\n\n if (this.subscriptions.length > 0) {\n logger.info('disposing of %d subscriptions...', this.subscriptions.length)\n\n for (const dispose of this.subscriptions) {\n dispose()\n }\n\n this.subscriptions = []\n\n logger.info('disposed of all subscriptions!', this.subscriptions.length)\n }\n\n this.emitter.removeAllListeners()\n logger.info('destroyed the listener!')\n\n this.readyState = InterceptorReadyState.DISPOSED\n }\n\n private getInstance(): this | undefined {\n const instance = getGlobalSymbol<this>(this.symbol)\n this.logger.info('retrieved global instance:', instance?.constructor?.name)\n return instance\n }\n\n private setInstance(): void {\n setGlobalSymbol(this.symbol, this)\n this.logger.info('set global instance!', this.symbol.description)\n }\n\n private clearInstance(): void {\n deleteGlobalSymbol(this.symbol)\n this.logger.info('cleared global instance!', this.symbol.description)\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 { DeferredPromise } from '@open-draft/deferred-promise'\nimport { invariant } from 'outvariant'\nimport { InterceptorError } from './InterceptorError'\n\nexport interface RequestControllerSource {\n passthrough(): void\n respondWith(response: Response): void\n errorWith(reason?: unknown): void\n}\n\nexport class RequestController {\n static PENDING = 0 as const\n static PASSTHROUGH = 1 as const\n static RESPONSE = 2 as const\n static ERROR = 3 as const\n\n public readyState: number\n\n /**\n * A Promise that resolves when this controller handles a request.\n * See `controller.readyState` for more information on the handling result.\n */\n public handled: Promise<void>\n\n constructor(\n protected readonly request: Request,\n protected readonly source: RequestControllerSource\n ) {\n this.readyState = RequestController.PENDING\n this.handled = new DeferredPromise<void>()\n }\n\n get #handled() {\n return this.handled as DeferredPromise<void>\n }\n\n /**\n * Perform this request as-is.\n */\n public async passthrough(): Promise<void> {\n invariant.as(\n InterceptorError,\n this.readyState === RequestController.PENDING,\n 'Failed to passthrough the \"%s %s\" request: the request has already been handled',\n this.request.method,\n this.request.url\n )\n\n this.readyState = RequestController.PASSTHROUGH\n await this.source.passthrough()\n this.#handled.resolve()\n }\n\n /**\n * Respond to this request with the given `Response` instance.\n *\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.readyState === RequestController.PENDING,\n 'Failed to respond to the \"%s %s\" request with \"%d %s\": the request has already been handled (%d)',\n this.request.method,\n this.request.url,\n response.status,\n response.statusText || 'OK',\n this.readyState\n )\n\n this.readyState = RequestController.RESPONSE\n this.#handled.resolve()\n\n /**\n * @note Although `source.respondWith()` is potentially asynchronous,\n * do NOT await it for backward-compatibility. Awaiting it will short-circuit\n * the request listener invocation as soon as a listener responds to a request.\n * Ideally, that's what we want, but that's not what we promise the user.\n */\n this.source.respondWith(response)\n }\n\n /**\n * Error this request with the given reason.\n *\n * @example\n * controller.errorWith()\n * controller.errorWith(new Error('Oops!'))\n * controller.errorWith({ message: 'Oops!'})\n */\n public errorWith(reason?: unknown): void {\n invariant.as(\n InterceptorError,\n this.readyState === RequestController.PENDING,\n 'Failed to error the \"%s %s\" request with \"%s\": the request has already been handled (%d)',\n this.request.method,\n this.request.url,\n reason?.toString(),\n this.readyState\n )\n\n this.readyState = RequestController.ERROR\n this.source.errorWith(reason)\n this.#handled.resolve()\n }\n}\n","/**\n * Generate a random ID string to represent a request.\n * @example\n * createRequestId()\n * // \"f774b6c9c600f\"\n */\nexport function createRequestId(): string {\n return Math.random().toString(16).slice(2)\n}\n","/**\n * Returns a boolean indicating whether the given URL string\n * can be parsed into a `URL` instance.\n * A substitute for `URL.canParse()` for Node.js 18.\n */\nexport function canParseUrl(url: string): boolean {\n try {\n new URL(url)\n return true\n } catch (_error) {\n return false\n }\n}\n","/**\n * Returns the value behind the symbol with the given name.\n */\nexport function getValueBySymbol<T>(\n symbolName: string,\n source: object\n): T | undefined {\n const ownSymbols = Object.getOwnPropertySymbols(source)\n\n const symbol = ownSymbols.find((symbol) => {\n return symbol.description === symbolName\n })\n\n if (symbol) {\n return Reflect.get(source, symbol)\n }\n\n return\n}\n","import { canParseUrl } from './canParseUrl'\nimport { getValueBySymbol } from './getValueBySymbol'\n\nexport interface FetchResponseInit extends ResponseInit {\n url?: string\n}\n\ninterface UndiciFetchInternalState {\n aborted: boolean\n rangeRequested: boolean\n timingAllowPassed: boolean\n requestIncludesCredentials: boolean\n type: ResponseType\n status: number\n statusText: string\n timingInfo: unknown\n cacheState: unknown\n headersList: Record<symbol, Map<string, unknown>>\n urlList: Array<URL>\n body?: {\n stream: ReadableStream\n source: unknown\n length: number\n }\n}\n\nexport class FetchResponse extends Response {\n /**\n * Response status codes for responses that cannot have body.\n * @see https://fetch.spec.whatwg.org/#statuses\n */\n static readonly STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304]\n\n static readonly STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308]\n\n static isConfigurableStatusCode(status: number): boolean {\n return status >= 200 && status <= 599\n }\n\n static isRedirectResponse(status: number): boolean {\n return FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status)\n }\n\n /**\n * Returns a boolean indicating whether the given response status\n * code represents a response that can have a body.\n */\n static isResponseWithBody(status: number): boolean {\n return !FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status)\n }\n\n static setUrl(url: string | undefined, response: Response): void {\n if (!url || url === 'about:' || !canParseUrl(url)) {\n return\n }\n\n const state = getValueBySymbol<UndiciFetchInternalState>('state', response)\n\n if (state) {\n // In Undici, push the URL to the internal list of URLs.\n // This will respect the `response.url` getter logic correctly.\n state.urlList.push(new URL(url))\n } else {\n // In other libraries, redefine the `url` property directly.\n Object.defineProperty(response, 'url', {\n value: url,\n enumerable: true,\n configurable: true,\n writable: false,\n })\n }\n }\n\n /**\n * Parses the given raw HTTP headers into a Fetch API `Headers` instance.\n */\n static parseRawHeaders(rawHeaders: Array<string>): Headers {\n const headers = new Headers()\n for (let line = 0; line < rawHeaders.length; line += 2) {\n headers.append(rawHeaders[line], rawHeaders[line + 1])\n }\n return headers\n }\n\n constructor(body?: BodyInit | null, init: FetchResponseInit = {}) {\n const status = init.status ?? 200\n const safeStatus = FetchResponse.isConfigurableStatusCode(status)\n ? status\n : 200\n const finalBody = FetchResponse.isResponseWithBody(status) ? body : null\n\n super(finalBody, {\n status: safeStatus,\n statusText: init.statusText,\n headers: init.headers,\n })\n\n if (status !== safeStatus) {\n /**\n * @note Undici keeps an internal \"Symbol(state)\" that holds\n * the actual value of response status. Update that in Node.js.\n */\n const state = getValueBySymbol<UndiciFetchInternalState>('state', this)\n\n if (state) {\n state.status = status\n } else {\n Object.defineProperty(this, 'status', {\n value: status,\n enumerable: true,\n configurable: true,\n writable: false,\n })\n }\n }\n\n FetchResponse.setUrl(init.url, this)\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,kCACX;AAEF,SAAgB,gBAAmB,QAA+B;AAChE,QAEE,WAAW,WAAW;;AAI1B,SAAS,gBAAgB,QAAgB,OAAkB;AAEzD,YAAW,UAAU;;AAGvB,SAAgB,mBAAmB,QAAsB;AAEvD,QAAO,WAAW;;AAGpB,IAAY,0EAAL;AACL;AACA;AACA;AACA;AACA;;;AAMF,IAAa,cAAb,MAA6D;CAO3D,YAAY,AAAiBA,QAAgB;EAAhB;AAC3B,OAAK,aAAa,sBAAsB;AAExC,OAAK,UAAU,IAAI,SAAS;AAC5B,OAAK,gBAAgB,EAAE;AACvB,OAAK,SAAS,IAAI,OAAO,OAAO,YAAa;AAI7C,OAAK,QAAQ,gBAAgB,EAAE;AAE/B,OAAK,OAAO,KAAK,kCAAkC;;;;;;CAOrD,AAAU,mBAA4B;AACpC,SAAO;;;;;;CAOT,AAAO,QAAc;EACnB,MAAM,SAAS,KAAK,OAAO,OAAO,QAAQ;AAC1C,SAAO,KAAK,8BAA8B;AAE1C,MAAI,KAAK,eAAe,sBAAsB,SAAS;AACrD,UAAO,KAAK,+BAA+B;AAC3C;;AAKF,MAAI,CAFgB,KAAK,kBAAkB,EAEzB;AAChB,UAAO,KAAK,yDAAyD;AACrE;;AAGF,OAAK,aAAa,sBAAsB;EAKxC,MAAM,kBAAkB,KAAK,aAAa;AAE1C,MAAI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AI,CAAC,OAAO,QAAQ,YAAY,CAAC,YAAY,IAAI,CAC/C;EAGF,MAAM,QAAQ,iBAA2C,SAAS,SAAS;AAE3E,MAAI,MAGF,OAAM,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC;MAGhC,QAAO,eAAe,UAAU,OAAO;GACrC,OAAO;GACP,YAAY;GACZ,cAAc;GACd,UAAU;GACX,CAAC;;;;;CAON,OAAO,gBAAgB,YAAoC;EACzD,MAAM,UAAU,IAAI,SAAS;AAC7B,OAAK,IAAI,OAAO,GAAG,OAAO,WAAW,QAAQ,QAAQ,EACnD,SAAQ,OAAO,WAAW,OAAO,WAAW,OAAO,GAAG;AAExD,SAAO;;CAGT,YAAY,MAAwB,OAA0B,EAAE,EAAE;EAChE,MAAM,SAAS,KAAK,UAAU;EAC9B,MAAM,aAAa,cAAc,yBAAyB,OAAO,GAC7D,SACA;EACJ,MAAM,YAAY,cAAc,mBAAmB,OAAO,GAAG,OAAO;AAEpE,QAAM,WAAW;GACf,QAAQ;GACR,YAAY,KAAK;GACjB,SAAS,KAAK;GACf,CAAC;AAEF,MAAI,WAAW,YAAY;;;;;GAKzB,MAAM,QAAQ,iBAA2C,SAAS,KAAK;AAEvE,OAAI,MACF,OAAM,SAAS;OAEf,QAAO,eAAe,MAAM,UAAU;IACpC,OAAO;IACP,YAAY;IACZ,cAAc;IACd,UAAU;IACX,CAAC;;AAIN,gBAAc,OAAO,KAAK,KAAK,KAAK"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/glossary.ts
|
|
3
|
-
const IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
4
|
-
|
|
5
|
-
//#endregion
|
|
6
|
-
Object.defineProperty(exports, 'IS_PATCHED_MODULE', {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return IS_PATCHED_MODULE;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
//# sourceMappingURL=glossary-BLKRyLBd.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"glossary-BLKRyLBd.cjs","names":["IS_PATCHED_MODULE: unique symbol"],"sources":["../../src/glossary.ts"],"sourcesContent":["import type { RequestController } from './RequestController'\n\nexport const IS_PATCHED_MODULE: unique symbol = Symbol('isPatchedModule')\n\n/**\n * @note Export `RequestController` as a type only.\n * It's never meant to be created in the userland.\n */\nexport type { RequestController }\n\nexport type RequestCredentials = 'omit' | 'include' | 'same-origin'\n\nexport type HttpRequestEventMap = {\n request: [\n args: {\n request: Request\n requestId: string\n controller: RequestController\n }\n ]\n response: [\n args: {\n response: Response\n isMockedResponse: boolean\n request: Request\n requestId: string\n }\n ]\n unhandledException: [\n args: {\n error: unknown\n request: Request\n requestId: string\n controller: RequestController\n }\n ]\n}\n"],"mappings":";;AAEA,MAAaA,oBAAmC,OAAO,kBAAkB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"glossary-glQBRnVD.mjs","names":["IS_PATCHED_MODULE: unique symbol"],"sources":["../../src/glossary.ts"],"sourcesContent":["import type { RequestController } from './RequestController'\n\nexport const IS_PATCHED_MODULE: unique symbol = Symbol('isPatchedModule')\n\n/**\n * @note Export `RequestController` as a type only.\n * It's never meant to be created in the userland.\n */\nexport type { RequestController }\n\nexport type RequestCredentials = 'omit' | 'include' | 'same-origin'\n\nexport type HttpRequestEventMap = {\n request: [\n args: {\n request: Request\n requestId: string\n controller: RequestController\n }\n ]\n response: [\n args: {\n response: Response\n isMockedResponse: boolean\n request: Request\n requestId: string\n }\n ]\n unhandledException: [\n args: {\n error: unknown\n request: Request\n requestId: string\n controller: RequestController\n }\n ]\n}\n"],"mappings":";AAEA,MAAaA,oBAAmC,OAAO,kBAAkB"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/utils/hasConfigurableGlobal.ts
|
|
3
|
-
/**
|
|
4
|
-
* Returns a boolean indicating whether the given global property
|
|
5
|
-
* is defined and is configurable.
|
|
6
|
-
*/
|
|
7
|
-
function hasConfigurableGlobal(propertyName) {
|
|
8
|
-
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
9
|
-
if (typeof descriptor === "undefined") return false;
|
|
10
|
-
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
11
|
-
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
12
|
-
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
13
|
-
console.error(`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`);
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
Object.defineProperty(exports, 'hasConfigurableGlobal', {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return hasConfigurableGlobal;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
//# sourceMappingURL=hasConfigurableGlobal-C97fWuaA.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hasConfigurableGlobal-C97fWuaA.cjs","names":[],"sources":["../../src/utils/hasConfigurableGlobal.ts"],"sourcesContent":["/**\n * Returns a boolean indicating whether the given global property\n * is defined and is configurable.\n */\nexport function hasConfigurableGlobal(propertyName: string): boolean {\n const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName)\n\n // The property is not set at all.\n if (typeof descriptor === 'undefined') {\n return false\n }\n\n // The property is set to a getter that returns undefined.\n if (\n typeof descriptor.get === 'function' &&\n typeof descriptor.get() === 'undefined'\n ) {\n return false\n }\n\n // The property is set to a value equal to undefined.\n if (typeof descriptor.get === 'undefined' && descriptor.value == null) {\n return false\n }\n\n if (typeof descriptor.set === 'undefined' && !descriptor.configurable) {\n console.error(\n `[MSW] Failed to apply interceptor: the global \\`${propertyName}\\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`\n )\n return false\n }\n\n return true\n}\n"],"mappings":";;;;;;AAIA,SAAgB,sBAAsB,cAA+B;CACnE,MAAM,aAAa,OAAO,yBAAyB,YAAY,aAAa;AAG5E,KAAI,OAAO,eAAe,YACxB,QAAO;AAIT,KACE,OAAO,WAAW,QAAQ,cAC1B,OAAO,WAAW,KAAK,KAAK,YAE5B,QAAO;AAIT,KAAI,OAAO,WAAW,QAAQ,eAAe,WAAW,SAAS,KAC/D,QAAO;AAGT,KAAI,OAAO,WAAW,QAAQ,eAAe,CAAC,WAAW,cAAc;AACrE,UAAQ,MACN,mDAAmD,aAAa,oKACjE;AACD,SAAO;;AAGT,QAAO"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/utils/hasConfigurableGlobal.ts
|
|
2
|
-
/**
|
|
3
|
-
* Returns a boolean indicating whether the given global property
|
|
4
|
-
* is defined and is configurable.
|
|
5
|
-
*/
|
|
6
|
-
function hasConfigurableGlobal(propertyName) {
|
|
7
|
-
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
8
|
-
if (typeof descriptor === "undefined") return false;
|
|
9
|
-
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
10
|
-
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
11
|
-
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
12
|
-
console.error(`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`);
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
export { hasConfigurableGlobal as t };
|
|
20
|
-
//# sourceMappingURL=hasConfigurableGlobal-DBJA0vjm.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hasConfigurableGlobal-DBJA0vjm.mjs","names":[],"sources":["../../src/utils/hasConfigurableGlobal.ts"],"sourcesContent":["/**\n * Returns a boolean indicating whether the given global property\n * is defined and is configurable.\n */\nexport function hasConfigurableGlobal(propertyName: string): boolean {\n const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName)\n\n // The property is not set at all.\n if (typeof descriptor === 'undefined') {\n return false\n }\n\n // The property is set to a getter that returns undefined.\n if (\n typeof descriptor.get === 'function' &&\n typeof descriptor.get() === 'undefined'\n ) {\n return false\n }\n\n // The property is set to a value equal to undefined.\n if (typeof descriptor.get === 'undefined' && descriptor.value == null) {\n return false\n }\n\n if (typeof descriptor.set === 'undefined' && !descriptor.configurable) {\n console.error(\n `[MSW] Failed to apply interceptor: the global \\`${propertyName}\\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`\n )\n return false\n }\n\n return true\n}\n"],"mappings":";;;;;AAIA,SAAgB,sBAAsB,cAA+B;CACnE,MAAM,aAAa,OAAO,yBAAyB,YAAY,aAAa;AAG5E,KAAI,OAAO,eAAe,YACxB,QAAO;AAIT,KACE,OAAO,WAAW,QAAQ,cAC1B,OAAO,WAAW,KAAK,KAAK,YAE5B,QAAO;AAIT,KAAI,OAAO,WAAW,QAAQ,eAAe,WAAW,SAAS,KAC/D,QAAO;AAGT,KAAI,OAAO,WAAW,QAAQ,eAAe,CAAC,WAAW,cAAc;AACrE,UAAQ,MACN,mDAAmD,aAAa,oKACjE;AACD,SAAO;;AAGT,QAAO"}
|