修改后台权限
This commit is contained in:
49
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-3LnAnLTx.cjs
generated
vendored
Normal file
49
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-3LnAnLTx.cjs
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
const require_fetchUtils = require('./fetchUtils-BaY5iWXw.cjs');
|
||||
|
||||
//#region src/BatchInterceptor.ts
|
||||
/**
|
||||
* A batch interceptor that exposes a single interface
|
||||
* to apply and operate with multiple interceptors at once.
|
||||
*/
|
||||
var BatchInterceptor = class BatchInterceptor extends require_fetchUtils.Interceptor {
|
||||
constructor(options) {
|
||||
BatchInterceptor.symbol = Symbol(options.name);
|
||||
super(BatchInterceptor.symbol);
|
||||
this.interceptors = options.interceptors;
|
||||
}
|
||||
setup() {
|
||||
const logger = this.logger.extend("setup");
|
||||
logger.info("applying all %d interceptors...", this.interceptors.length);
|
||||
for (const interceptor of this.interceptors) {
|
||||
logger.info("applying \"%s\" interceptor...", interceptor.constructor.name);
|
||||
interceptor.apply();
|
||||
logger.info("adding interceptor dispose subscription");
|
||||
this.subscriptions.push(() => interceptor.dispose());
|
||||
}
|
||||
}
|
||||
on(event, listener) {
|
||||
for (const interceptor of this.interceptors) interceptor.on(event, listener);
|
||||
return this;
|
||||
}
|
||||
once(event, listener) {
|
||||
for (const interceptor of this.interceptors) interceptor.once(event, listener);
|
||||
return this;
|
||||
}
|
||||
off(event, listener) {
|
||||
for (const interceptor of this.interceptors) interceptor.off(event, listener);
|
||||
return this;
|
||||
}
|
||||
removeAllListeners(event) {
|
||||
for (const interceptors of this.interceptors) interceptors.removeAllListeners(event);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'BatchInterceptor', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return BatchInterceptor;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=BatchInterceptor-3LnAnLTx.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-3LnAnLTx.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-3LnAnLTx.cjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"BatchInterceptor-3LnAnLTx.cjs","names":["Interceptor"],"sources":["../../src/BatchInterceptor.ts"],"sourcesContent":["import { EventMap, Listener } from 'strict-event-emitter'\nimport { Interceptor, ExtractEventNames } from './Interceptor'\n\nexport interface BatchInterceptorOptions<\n InterceptorList extends ReadonlyArray<Interceptor<any>>\n> {\n name: string\n interceptors: InterceptorList\n}\n\nexport type ExtractEventMapType<\n InterceptorList extends ReadonlyArray<Interceptor<any>>\n> = InterceptorList extends ReadonlyArray<infer InterceptorType>\n ? InterceptorType extends Interceptor<infer EventMap>\n ? EventMap\n : never\n : never\n\n/**\n * A batch interceptor that exposes a single interface\n * to apply and operate with multiple interceptors at once.\n */\nexport class BatchInterceptor<\n InterceptorList extends ReadonlyArray<Interceptor<any>>,\n Events extends EventMap = ExtractEventMapType<InterceptorList>\n> extends Interceptor<Events> {\n static symbol: symbol\n\n private interceptors: InterceptorList\n\n constructor(options: BatchInterceptorOptions<InterceptorList>) {\n BatchInterceptor.symbol = Symbol(options.name)\n super(BatchInterceptor.symbol)\n this.interceptors = options.interceptors\n }\n\n protected setup() {\n const logger = this.logger.extend('setup')\n\n logger.info('applying all %d interceptors...', this.interceptors.length)\n\n for (const interceptor of this.interceptors) {\n logger.info('applying \"%s\" interceptor...', interceptor.constructor.name)\n interceptor.apply()\n\n logger.info('adding interceptor dispose subscription')\n this.subscriptions.push(() => interceptor.dispose())\n }\n }\n\n public on<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n // Instead of adding a listener to the batch interceptor,\n // propagate the listener to each of the individual interceptors.\n for (const interceptor of this.interceptors) {\n interceptor.on(event, listener)\n }\n\n return this\n }\n\n public once<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n for (const interceptor of this.interceptors) {\n interceptor.once(event, listener)\n }\n\n return this\n }\n\n public off<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n for (const interceptor of this.interceptors) {\n interceptor.off(event, listener)\n }\n\n return this\n }\n\n public removeAllListeners<EventName extends ExtractEventNames<Events>>(\n event?: EventName | undefined\n ): this {\n for (const interceptors of this.interceptors) {\n interceptors.removeAllListeners(event)\n }\n\n return this\n }\n}\n"],"mappings":";;;;;;;AAsBA,IAAa,mBAAb,MAAa,yBAGHA,+BAAoB;CAK5B,YAAY,SAAmD;AAC7D,mBAAiB,SAAS,OAAO,QAAQ,KAAK;AAC9C,QAAM,iBAAiB,OAAO;AAC9B,OAAK,eAAe,QAAQ;;CAG9B,AAAU,QAAQ;EAChB,MAAM,SAAS,KAAK,OAAO,OAAO,QAAQ;AAE1C,SAAO,KAAK,mCAAmC,KAAK,aAAa,OAAO;AAExE,OAAK,MAAM,eAAe,KAAK,cAAc;AAC3C,UAAO,KAAK,kCAAgC,YAAY,YAAY,KAAK;AACzE,eAAY,OAAO;AAEnB,UAAO,KAAK,0CAA0C;AACtD,QAAK,cAAc,WAAW,YAAY,SAAS,CAAC;;;CAIxD,AAAO,GACL,OACA,UACM;AAGN,OAAK,MAAM,eAAe,KAAK,aAC7B,aAAY,GAAG,OAAO,SAAS;AAGjC,SAAO;;CAGT,AAAO,KACL,OACA,UACM;AACN,OAAK,MAAM,eAAe,KAAK,aAC7B,aAAY,KAAK,OAAO,SAAS;AAGnC,SAAO;;CAGT,AAAO,IACL,OACA,UACM;AACN,OAAK,MAAM,eAAe,KAAK,aAC7B,aAAY,IAAI,OAAO,SAAS;AAGlC,SAAO;;CAGT,AAAO,mBACL,OACM;AACN,OAAK,MAAM,gBAAgB,KAAK,aAC9B,cAAa,mBAAmB,MAAM;AAGxC,SAAO"}
|
||||
26
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-D7mXzHcQ.d.mts
generated
vendored
Normal file
26
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-D7mXzHcQ.d.mts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { r as Interceptor, t as ExtractEventNames } from "./Interceptor-DEazpLJd.mjs";
|
||||
import { EventMap, Listener } from "strict-event-emitter";
|
||||
|
||||
//#region src/BatchInterceptor.d.ts
|
||||
interface BatchInterceptorOptions<InterceptorList extends ReadonlyArray<Interceptor<any>>> {
|
||||
name: string;
|
||||
interceptors: InterceptorList;
|
||||
}
|
||||
type ExtractEventMapType<InterceptorList extends ReadonlyArray<Interceptor<any>>> = InterceptorList extends ReadonlyArray<infer InterceptorType> ? InterceptorType extends Interceptor<infer EventMap> ? EventMap : never : never;
|
||||
/**
|
||||
* A batch interceptor that exposes a single interface
|
||||
* to apply and operate with multiple interceptors at once.
|
||||
*/
|
||||
declare class BatchInterceptor<InterceptorList extends ReadonlyArray<Interceptor<any>>, Events extends EventMap = ExtractEventMapType<InterceptorList>> extends Interceptor<Events> {
|
||||
static symbol: symbol;
|
||||
private interceptors;
|
||||
constructor(options: BatchInterceptorOptions<InterceptorList>);
|
||||
protected setup(): void;
|
||||
on<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
once<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
off<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
removeAllListeners<EventName extends ExtractEventNames<Events>>(event?: EventName | undefined): this;
|
||||
}
|
||||
//#endregion
|
||||
export { BatchInterceptorOptions as n, ExtractEventMapType as r, BatchInterceptor as t };
|
||||
//# sourceMappingURL=BatchInterceptor-D7mXzHcQ.d.mts.map
|
||||
44
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-DFaBPilf.mjs
generated
vendored
Normal file
44
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-DFaBPilf.mjs
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
import { s as Interceptor } from "./fetchUtils-CoU35g3M.mjs";
|
||||
|
||||
//#region src/BatchInterceptor.ts
|
||||
/**
|
||||
* A batch interceptor that exposes a single interface
|
||||
* to apply and operate with multiple interceptors at once.
|
||||
*/
|
||||
var BatchInterceptor = class BatchInterceptor extends Interceptor {
|
||||
constructor(options) {
|
||||
BatchInterceptor.symbol = Symbol(options.name);
|
||||
super(BatchInterceptor.symbol);
|
||||
this.interceptors = options.interceptors;
|
||||
}
|
||||
setup() {
|
||||
const logger = this.logger.extend("setup");
|
||||
logger.info("applying all %d interceptors...", this.interceptors.length);
|
||||
for (const interceptor of this.interceptors) {
|
||||
logger.info("applying \"%s\" interceptor...", interceptor.constructor.name);
|
||||
interceptor.apply();
|
||||
logger.info("adding interceptor dispose subscription");
|
||||
this.subscriptions.push(() => interceptor.dispose());
|
||||
}
|
||||
}
|
||||
on(event, listener) {
|
||||
for (const interceptor of this.interceptors) interceptor.on(event, listener);
|
||||
return this;
|
||||
}
|
||||
once(event, listener) {
|
||||
for (const interceptor of this.interceptors) interceptor.once(event, listener);
|
||||
return this;
|
||||
}
|
||||
off(event, listener) {
|
||||
for (const interceptor of this.interceptors) interceptor.off(event, listener);
|
||||
return this;
|
||||
}
|
||||
removeAllListeners(event) {
|
||||
for (const interceptors of this.interceptors) interceptors.removeAllListeners(event);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { BatchInterceptor as t };
|
||||
//# sourceMappingURL=BatchInterceptor-DFaBPilf.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-DFaBPilf.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-DFaBPilf.mjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"BatchInterceptor-DFaBPilf.mjs","names":[],"sources":["../../src/BatchInterceptor.ts"],"sourcesContent":["import { EventMap, Listener } from 'strict-event-emitter'\nimport { Interceptor, ExtractEventNames } from './Interceptor'\n\nexport interface BatchInterceptorOptions<\n InterceptorList extends ReadonlyArray<Interceptor<any>>\n> {\n name: string\n interceptors: InterceptorList\n}\n\nexport type ExtractEventMapType<\n InterceptorList extends ReadonlyArray<Interceptor<any>>\n> = InterceptorList extends ReadonlyArray<infer InterceptorType>\n ? InterceptorType extends Interceptor<infer EventMap>\n ? EventMap\n : never\n : never\n\n/**\n * A batch interceptor that exposes a single interface\n * to apply and operate with multiple interceptors at once.\n */\nexport class BatchInterceptor<\n InterceptorList extends ReadonlyArray<Interceptor<any>>,\n Events extends EventMap = ExtractEventMapType<InterceptorList>\n> extends Interceptor<Events> {\n static symbol: symbol\n\n private interceptors: InterceptorList\n\n constructor(options: BatchInterceptorOptions<InterceptorList>) {\n BatchInterceptor.symbol = Symbol(options.name)\n super(BatchInterceptor.symbol)\n this.interceptors = options.interceptors\n }\n\n protected setup() {\n const logger = this.logger.extend('setup')\n\n logger.info('applying all %d interceptors...', this.interceptors.length)\n\n for (const interceptor of this.interceptors) {\n logger.info('applying \"%s\" interceptor...', interceptor.constructor.name)\n interceptor.apply()\n\n logger.info('adding interceptor dispose subscription')\n this.subscriptions.push(() => interceptor.dispose())\n }\n }\n\n public on<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n // Instead of adding a listener to the batch interceptor,\n // propagate the listener to each of the individual interceptors.\n for (const interceptor of this.interceptors) {\n interceptor.on(event, listener)\n }\n\n return this\n }\n\n public once<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n for (const interceptor of this.interceptors) {\n interceptor.once(event, listener)\n }\n\n return this\n }\n\n public off<EventName extends ExtractEventNames<Events>>(\n event: EventName,\n listener: Listener<Events[EventName]>\n ): this {\n for (const interceptor of this.interceptors) {\n interceptor.off(event, listener)\n }\n\n return this\n }\n\n public removeAllListeners<EventName extends ExtractEventNames<Events>>(\n event?: EventName | undefined\n ): this {\n for (const interceptors of this.interceptors) {\n interceptors.removeAllListeners(event)\n }\n\n return this\n }\n}\n"],"mappings":";;;;;;;AAsBA,IAAa,mBAAb,MAAa,yBAGH,YAAoB;CAK5B,YAAY,SAAmD;AAC7D,mBAAiB,SAAS,OAAO,QAAQ,KAAK;AAC9C,QAAM,iBAAiB,OAAO;AAC9B,OAAK,eAAe,QAAQ;;CAG9B,AAAU,QAAQ;EAChB,MAAM,SAAS,KAAK,OAAO,OAAO,QAAQ;AAE1C,SAAO,KAAK,mCAAmC,KAAK,aAAa,OAAO;AAExE,OAAK,MAAM,eAAe,KAAK,cAAc;AAC3C,UAAO,KAAK,kCAAgC,YAAY,YAAY,KAAK;AACzE,eAAY,OAAO;AAEnB,UAAO,KAAK,0CAA0C;AACtD,QAAK,cAAc,WAAW,YAAY,SAAS,CAAC;;;CAIxD,AAAO,GACL,OACA,UACM;AAGN,OAAK,MAAM,eAAe,KAAK,aAC7B,aAAY,GAAG,OAAO,SAAS;AAGjC,SAAO;;CAGT,AAAO,KACL,OACA,UACM;AACN,OAAK,MAAM,eAAe,KAAK,aAC7B,aAAY,KAAK,OAAO,SAAS;AAGnC,SAAO;;CAGT,AAAO,IACL,OACA,UACM;AACN,OAAK,MAAM,eAAe,KAAK,aAC7B,aAAY,IAAI,OAAO,SAAS;AAGlC,SAAO;;CAGT,AAAO,mBACL,OACM;AACN,OAAK,MAAM,gBAAgB,KAAK,aAC9B,cAAa,mBAAmB,MAAM;AAGxC,SAAO"}
|
||||
26
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-D_YqR8qU.d.cts
generated
vendored
Normal file
26
node_modules/@mswjs/interceptors/lib/node/BatchInterceptor-D_YqR8qU.d.cts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { r as Interceptor, t as ExtractEventNames } from "./Interceptor-DJ2akVWI.cjs";
|
||||
import { EventMap, Listener } from "strict-event-emitter";
|
||||
|
||||
//#region src/BatchInterceptor.d.ts
|
||||
interface BatchInterceptorOptions<InterceptorList extends ReadonlyArray<Interceptor<any>>> {
|
||||
name: string;
|
||||
interceptors: InterceptorList;
|
||||
}
|
||||
type ExtractEventMapType<InterceptorList extends ReadonlyArray<Interceptor<any>>> = InterceptorList extends ReadonlyArray<infer InterceptorType> ? InterceptorType extends Interceptor<infer EventMap> ? EventMap : never : never;
|
||||
/**
|
||||
* A batch interceptor that exposes a single interface
|
||||
* to apply and operate with multiple interceptors at once.
|
||||
*/
|
||||
declare class BatchInterceptor<InterceptorList extends ReadonlyArray<Interceptor<any>>, Events extends EventMap = ExtractEventMapType<InterceptorList>> extends Interceptor<Events> {
|
||||
static symbol: symbol;
|
||||
private interceptors;
|
||||
constructor(options: BatchInterceptorOptions<InterceptorList>);
|
||||
protected setup(): void;
|
||||
on<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
once<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
off<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
removeAllListeners<EventName extends ExtractEventNames<Events>>(event?: EventName | undefined): this;
|
||||
}
|
||||
//#endregion
|
||||
export { BatchInterceptorOptions as n, ExtractEventMapType as r, BatchInterceptor as t };
|
||||
//# sourceMappingURL=BatchInterceptor-D_YqR8qU.d.cts.map
|
||||
1043
node_modules/@mswjs/interceptors/lib/node/ClientRequest-2rDe54Ui.cjs
generated
vendored
Normal file
1043
node_modules/@mswjs/interceptors/lib/node/ClientRequest-2rDe54Ui.cjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/@mswjs/interceptors/lib/node/ClientRequest-2rDe54Ui.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/ClientRequest-2rDe54Ui.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1034
node_modules/@mswjs/interceptors/lib/node/ClientRequest-Ca8Qykuv.mjs
generated
vendored
Normal file
1034
node_modules/@mswjs/interceptors/lib/node/ClientRequest-Ca8Qykuv.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
node_modules/@mswjs/interceptors/lib/node/ClientRequest-Ca8Qykuv.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/ClientRequest-Ca8Qykuv.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
133
node_modules/@mswjs/interceptors/lib/node/Interceptor-DEazpLJd.d.mts
generated
vendored
Normal file
133
node_modules/@mswjs/interceptors/lib/node/Interceptor-DEazpLJd.d.mts
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
import { Logger } from "@open-draft/logger";
|
||||
import { Emitter, Listener } from "strict-event-emitter";
|
||||
|
||||
//#region src/RequestController.d.ts
|
||||
interface RequestControllerSource {
|
||||
passthrough(): void;
|
||||
respondWith(response: Response): void;
|
||||
errorWith(reason?: unknown): void;
|
||||
}
|
||||
declare class RequestController {
|
||||
#private;
|
||||
protected readonly request: Request;
|
||||
protected readonly source: RequestControllerSource;
|
||||
static PENDING: 0;
|
||||
static PASSTHROUGH: 1;
|
||||
static RESPONSE: 2;
|
||||
static ERROR: 3;
|
||||
readyState: number;
|
||||
/**
|
||||
* A Promise that resolves when this controller handles a request.
|
||||
* See `controller.readyState` for more information on the handling result.
|
||||
*/
|
||||
handled: Promise<void>;
|
||||
constructor(request: Request, source: RequestControllerSource);
|
||||
/**
|
||||
* Perform this request as-is.
|
||||
*/
|
||||
passthrough(): Promise<void>;
|
||||
/**
|
||||
* Respond to this request with the given `Response` instance.
|
||||
*
|
||||
* @example
|
||||
* controller.respondWith(new Response())
|
||||
* controller.respondWith(Response.json({ id }))
|
||||
* controller.respondWith(Response.error())
|
||||
*/
|
||||
respondWith(response: Response): void;
|
||||
/**
|
||||
* Error this request with the given reason.
|
||||
*
|
||||
* @example
|
||||
* controller.errorWith()
|
||||
* controller.errorWith(new Error('Oops!'))
|
||||
* controller.errorWith({ message: 'Oops!'})
|
||||
*/
|
||||
errorWith(reason?: unknown): void;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/glossary.d.ts
|
||||
declare const IS_PATCHED_MODULE: unique symbol;
|
||||
type RequestCredentials = 'omit' | 'include' | 'same-origin';
|
||||
type HttpRequestEventMap = {
|
||||
request: [args: {
|
||||
request: Request;
|
||||
requestId: string;
|
||||
controller: RequestController;
|
||||
}];
|
||||
response: [args: {
|
||||
response: Response;
|
||||
isMockedResponse: boolean;
|
||||
request: Request;
|
||||
requestId: string;
|
||||
}];
|
||||
unhandledException: [args: {
|
||||
error: unknown;
|
||||
request: Request;
|
||||
requestId: string;
|
||||
controller: RequestController;
|
||||
}];
|
||||
};
|
||||
//#endregion
|
||||
//#region src/Interceptor.d.ts
|
||||
type InterceptorEventMap = Record<string, any>;
|
||||
type InterceptorSubscription = () => void;
|
||||
/**
|
||||
* Request header name to detect when a single request
|
||||
* is being handled by nested interceptors (XHR -> ClientRequest).
|
||||
* Obscure by design to prevent collisions with user-defined headers.
|
||||
* Ideally, come up with the Interceptor-level mechanism for this.
|
||||
* @see https://github.com/mswjs/interceptors/issues/378
|
||||
*/
|
||||
declare const INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
||||
declare function getGlobalSymbol<V>(symbol: Symbol): V | undefined;
|
||||
declare function deleteGlobalSymbol(symbol: Symbol): void;
|
||||
declare enum InterceptorReadyState {
|
||||
INACTIVE = "INACTIVE",
|
||||
APPLYING = "APPLYING",
|
||||
APPLIED = "APPLIED",
|
||||
DISPOSING = "DISPOSING",
|
||||
DISPOSED = "DISPOSED",
|
||||
}
|
||||
type ExtractEventNames<Events extends Record<string, any>> = Events extends Record<infer EventName, any> ? EventName : never;
|
||||
declare class Interceptor<Events extends InterceptorEventMap> {
|
||||
private readonly symbol;
|
||||
protected emitter: Emitter<Events>;
|
||||
protected subscriptions: Array<InterceptorSubscription>;
|
||||
protected logger: Logger;
|
||||
readyState: InterceptorReadyState;
|
||||
constructor(symbol: symbol);
|
||||
/**
|
||||
* Determine if this interceptor can be applied
|
||||
* in the current environment.
|
||||
*/
|
||||
protected checkEnvironment(): boolean;
|
||||
/**
|
||||
* Apply this interceptor to the current process.
|
||||
* Returns an already running interceptor instance if it's present.
|
||||
*/
|
||||
apply(): void;
|
||||
/**
|
||||
* Setup the module augments and stubs necessary for this interceptor.
|
||||
* This method is not run if there's a running interceptor instance
|
||||
* to prevent instantiating an interceptor multiple times.
|
||||
*/
|
||||
protected setup(): void;
|
||||
/**
|
||||
* Listen to the interceptor's public events.
|
||||
*/
|
||||
on<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
once<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
off<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
removeAllListeners<EventName extends ExtractEventNames<Events>>(event?: EventName): this;
|
||||
/**
|
||||
* Disposes of any side-effects this interceptor has introduced.
|
||||
*/
|
||||
dispose(): void;
|
||||
private getInstance;
|
||||
private setInstance;
|
||||
private clearInstance;
|
||||
}
|
||||
//#endregion
|
||||
export { InterceptorReadyState as a, getGlobalSymbol as c, RequestCredentials as d, RequestController as f, InterceptorEventMap as i, HttpRequestEventMap as l, INTERNAL_REQUEST_ID_HEADER_NAME as n, InterceptorSubscription as o, RequestControllerSource as p, Interceptor as r, deleteGlobalSymbol as s, ExtractEventNames as t, IS_PATCHED_MODULE as u };
|
||||
//# sourceMappingURL=Interceptor-DEazpLJd.d.mts.map
|
||||
133
node_modules/@mswjs/interceptors/lib/node/Interceptor-DJ2akVWI.d.cts
generated
vendored
Normal file
133
node_modules/@mswjs/interceptors/lib/node/Interceptor-DJ2akVWI.d.cts
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
import { Logger } from "@open-draft/logger";
|
||||
import { Emitter, Listener } from "strict-event-emitter";
|
||||
|
||||
//#region src/RequestController.d.ts
|
||||
interface RequestControllerSource {
|
||||
passthrough(): void;
|
||||
respondWith(response: Response): void;
|
||||
errorWith(reason?: unknown): void;
|
||||
}
|
||||
declare class RequestController {
|
||||
#private;
|
||||
protected readonly request: Request;
|
||||
protected readonly source: RequestControllerSource;
|
||||
static PENDING: 0;
|
||||
static PASSTHROUGH: 1;
|
||||
static RESPONSE: 2;
|
||||
static ERROR: 3;
|
||||
readyState: number;
|
||||
/**
|
||||
* A Promise that resolves when this controller handles a request.
|
||||
* See `controller.readyState` for more information on the handling result.
|
||||
*/
|
||||
handled: Promise<void>;
|
||||
constructor(request: Request, source: RequestControllerSource);
|
||||
/**
|
||||
* Perform this request as-is.
|
||||
*/
|
||||
passthrough(): Promise<void>;
|
||||
/**
|
||||
* Respond to this request with the given `Response` instance.
|
||||
*
|
||||
* @example
|
||||
* controller.respondWith(new Response())
|
||||
* controller.respondWith(Response.json({ id }))
|
||||
* controller.respondWith(Response.error())
|
||||
*/
|
||||
respondWith(response: Response): void;
|
||||
/**
|
||||
* Error this request with the given reason.
|
||||
*
|
||||
* @example
|
||||
* controller.errorWith()
|
||||
* controller.errorWith(new Error('Oops!'))
|
||||
* controller.errorWith({ message: 'Oops!'})
|
||||
*/
|
||||
errorWith(reason?: unknown): void;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/glossary.d.ts
|
||||
declare const IS_PATCHED_MODULE: unique symbol;
|
||||
type RequestCredentials = 'omit' | 'include' | 'same-origin';
|
||||
type HttpRequestEventMap = {
|
||||
request: [args: {
|
||||
request: Request;
|
||||
requestId: string;
|
||||
controller: RequestController;
|
||||
}];
|
||||
response: [args: {
|
||||
response: Response;
|
||||
isMockedResponse: boolean;
|
||||
request: Request;
|
||||
requestId: string;
|
||||
}];
|
||||
unhandledException: [args: {
|
||||
error: unknown;
|
||||
request: Request;
|
||||
requestId: string;
|
||||
controller: RequestController;
|
||||
}];
|
||||
};
|
||||
//#endregion
|
||||
//#region src/Interceptor.d.ts
|
||||
type InterceptorEventMap = Record<string, any>;
|
||||
type InterceptorSubscription = () => void;
|
||||
/**
|
||||
* Request header name to detect when a single request
|
||||
* is being handled by nested interceptors (XHR -> ClientRequest).
|
||||
* Obscure by design to prevent collisions with user-defined headers.
|
||||
* Ideally, come up with the Interceptor-level mechanism for this.
|
||||
* @see https://github.com/mswjs/interceptors/issues/378
|
||||
*/
|
||||
declare const INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
||||
declare function getGlobalSymbol<V>(symbol: Symbol): V | undefined;
|
||||
declare function deleteGlobalSymbol(symbol: Symbol): void;
|
||||
declare enum InterceptorReadyState {
|
||||
INACTIVE = "INACTIVE",
|
||||
APPLYING = "APPLYING",
|
||||
APPLIED = "APPLIED",
|
||||
DISPOSING = "DISPOSING",
|
||||
DISPOSED = "DISPOSED",
|
||||
}
|
||||
type ExtractEventNames<Events extends Record<string, any>> = Events extends Record<infer EventName, any> ? EventName : never;
|
||||
declare class Interceptor<Events extends InterceptorEventMap> {
|
||||
private readonly symbol;
|
||||
protected emitter: Emitter<Events>;
|
||||
protected subscriptions: Array<InterceptorSubscription>;
|
||||
protected logger: Logger;
|
||||
readyState: InterceptorReadyState;
|
||||
constructor(symbol: symbol);
|
||||
/**
|
||||
* Determine if this interceptor can be applied
|
||||
* in the current environment.
|
||||
*/
|
||||
protected checkEnvironment(): boolean;
|
||||
/**
|
||||
* Apply this interceptor to the current process.
|
||||
* Returns an already running interceptor instance if it's present.
|
||||
*/
|
||||
apply(): void;
|
||||
/**
|
||||
* Setup the module augments and stubs necessary for this interceptor.
|
||||
* This method is not run if there's a running interceptor instance
|
||||
* to prevent instantiating an interceptor multiple times.
|
||||
*/
|
||||
protected setup(): void;
|
||||
/**
|
||||
* Listen to the interceptor's public events.
|
||||
*/
|
||||
on<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
once<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
off<EventName extends ExtractEventNames<Events>>(event: EventName, listener: Listener<Events[EventName]>): this;
|
||||
removeAllListeners<EventName extends ExtractEventNames<Events>>(event?: EventName): this;
|
||||
/**
|
||||
* Disposes of any side-effects this interceptor has introduced.
|
||||
*/
|
||||
dispose(): void;
|
||||
private getInstance;
|
||||
private setInstance;
|
||||
private clearInstance;
|
||||
}
|
||||
//#endregion
|
||||
export { InterceptorReadyState as a, getGlobalSymbol as c, RequestCredentials as d, RequestController as f, InterceptorEventMap as i, HttpRequestEventMap as l, INTERNAL_REQUEST_ID_HEADER_NAME as n, InterceptorSubscription as o, RequestControllerSource as p, Interceptor as r, deleteGlobalSymbol as s, ExtractEventNames as t, IS_PATCHED_MODULE as u };
|
||||
//# sourceMappingURL=Interceptor-DJ2akVWI.d.cts.map
|
||||
154
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.cjs
generated
vendored
Normal file
154
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.cjs
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
const require_fetchUtils = require('./fetchUtils-BaY5iWXw.cjs');
|
||||
const require_BatchInterceptor = require('./BatchInterceptor-3LnAnLTx.cjs');
|
||||
require('./bufferUtils-DiCTqG-7.cjs');
|
||||
const require_ClientRequest = require('./ClientRequest-2rDe54Ui.cjs');
|
||||
const require_handleRequest = require('./handleRequest-Bb7Y-XLw.cjs');
|
||||
require('./node-dKdAf3tC.cjs');
|
||||
const require_XMLHttpRequest = require('./XMLHttpRequest-B7kJdYYI.cjs');
|
||||
const require_fetch = require('./fetch-BmXpK10r.cjs');
|
||||
|
||||
//#region src/RemoteHttpInterceptor.ts
|
||||
var RemoteHttpInterceptor = class extends require_BatchInterceptor.BatchInterceptor {
|
||||
constructor() {
|
||||
super({
|
||||
name: "remote-interceptor",
|
||||
interceptors: [
|
||||
new require_ClientRequest.ClientRequestInterceptor(),
|
||||
new require_XMLHttpRequest.XMLHttpRequestInterceptor(),
|
||||
new require_fetch.FetchInterceptor()
|
||||
]
|
||||
});
|
||||
}
|
||||
setup() {
|
||||
super.setup();
|
||||
let handleParentMessage;
|
||||
this.on("request", async ({ request, requestId, controller }) => {
|
||||
const serializedRequest = JSON.stringify({
|
||||
id: requestId,
|
||||
method: request.method,
|
||||
url: request.url,
|
||||
headers: Array.from(request.headers.entries()),
|
||||
credentials: request.credentials,
|
||||
body: ["GET", "HEAD"].includes(request.method) ? null : await request.text()
|
||||
});
|
||||
this.logger.info("sent serialized request to the child:", serializedRequest);
|
||||
process.send?.(`request:${serializedRequest}`);
|
||||
const responsePromise = new Promise((resolve) => {
|
||||
handleParentMessage = (message) => {
|
||||
if (typeof message !== "string") return resolve();
|
||||
if (message.startsWith(`response:${requestId}`)) {
|
||||
const [, serializedResponse] = message.match(/^response:.+?:(.+)$/) || [];
|
||||
if (!serializedResponse) return resolve();
|
||||
const responseInit = JSON.parse(serializedResponse);
|
||||
const mockedResponse = new require_fetchUtils.FetchResponse(responseInit.body, {
|
||||
url: request.url,
|
||||
status: responseInit.status,
|
||||
statusText: responseInit.statusText,
|
||||
headers: responseInit.headers
|
||||
});
|
||||
/**
|
||||
* @todo Support "errorWith" as well.
|
||||
* This response handling from the child is incomplete.
|
||||
*/
|
||||
controller.respondWith(mockedResponse);
|
||||
return resolve();
|
||||
}
|
||||
};
|
||||
});
|
||||
this.logger.info("add \"message\" listener to the parent process", handleParentMessage);
|
||||
process.addListener("message", handleParentMessage);
|
||||
return responsePromise;
|
||||
});
|
||||
this.subscriptions.push(() => {
|
||||
process.removeListener("message", handleParentMessage);
|
||||
});
|
||||
}
|
||||
};
|
||||
function requestReviver(key, value) {
|
||||
switch (key) {
|
||||
case "url": return new URL(value);
|
||||
case "headers": return new Headers(value);
|
||||
default: return value;
|
||||
}
|
||||
}
|
||||
var RemoteHttpResolver = class RemoteHttpResolver extends require_fetchUtils.Interceptor {
|
||||
static {
|
||||
this.symbol = Symbol("remote-resolver");
|
||||
}
|
||||
constructor(options) {
|
||||
super(RemoteHttpResolver.symbol);
|
||||
this.process = options.process;
|
||||
}
|
||||
setup() {
|
||||
const logger = this.logger.extend("setup");
|
||||
const handleChildMessage = async (message) => {
|
||||
logger.info("received message from child!", message);
|
||||
if (typeof message !== "string" || !message.startsWith("request:")) {
|
||||
logger.info("unknown message, ignoring...");
|
||||
return;
|
||||
}
|
||||
const [, serializedRequest] = message.match(/^request:(.+)$/) || [];
|
||||
if (!serializedRequest) return;
|
||||
const requestJson = JSON.parse(serializedRequest, requestReviver);
|
||||
logger.info("parsed intercepted request", requestJson);
|
||||
const request = new Request(requestJson.url, {
|
||||
method: requestJson.method,
|
||||
headers: new Headers(requestJson.headers),
|
||||
credentials: requestJson.credentials,
|
||||
body: requestJson.body
|
||||
});
|
||||
const controller = new require_fetchUtils.RequestController(request, {
|
||||
passthrough: () => {},
|
||||
respondWith: async (response) => {
|
||||
if (require_handleRequest.isResponseError(response)) {
|
||||
this.logger.info("received a network error!", { response });
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
this.logger.info("received mocked response!", { response });
|
||||
const responseClone = response.clone();
|
||||
const responseText = await responseClone.text();
|
||||
const serializedResponse = JSON.stringify({
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: Array.from(response.headers.entries()),
|
||||
body: responseText
|
||||
});
|
||||
this.process.send(`response:${requestJson.id}:${serializedResponse}`, (error) => {
|
||||
if (error) return;
|
||||
this.emitter.emit("response", {
|
||||
request,
|
||||
requestId: requestJson.id,
|
||||
response: responseClone,
|
||||
isMockedResponse: true
|
||||
});
|
||||
});
|
||||
logger.info("sent serialized mocked response to the parent:", serializedResponse);
|
||||
},
|
||||
errorWith: (reason) => {
|
||||
this.logger.info("request has errored!", { error: reason });
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
});
|
||||
await require_handleRequest.handleRequest({
|
||||
request,
|
||||
requestId: requestJson.id,
|
||||
controller,
|
||||
emitter: this.emitter
|
||||
});
|
||||
};
|
||||
this.subscriptions.push(() => {
|
||||
this.process.removeListener("message", handleChildMessage);
|
||||
logger.info("removed the \"message\" listener from the child process!");
|
||||
});
|
||||
logger.info("adding a \"message\" listener to the child process");
|
||||
this.process.addListener("message", handleChildMessage);
|
||||
this.process.once("error", () => this.dispose());
|
||||
this.process.once("exit", () => this.dispose());
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
exports.RemoteHttpInterceptor = RemoteHttpInterceptor;
|
||||
exports.RemoteHttpResolver = RemoteHttpResolver;
|
||||
exports.requestReviver = requestReviver;
|
||||
//# sourceMappingURL=RemoteHttpInterceptor.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
39
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.d.cts
generated
vendored
Normal file
39
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.d.cts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { l as HttpRequestEventMap, r as Interceptor } from "./Interceptor-DJ2akVWI.cjs";
|
||||
import { t as BatchInterceptor } from "./BatchInterceptor-D_YqR8qU.cjs";
|
||||
import { t as ClientRequestInterceptor } from "./index-BMbJ8FXL.cjs";
|
||||
import { XMLHttpRequestInterceptor } from "./interceptors/XMLHttpRequest/index.cjs";
|
||||
import { FetchInterceptor } from "./interceptors/fetch/index.cjs";
|
||||
import { ChildProcess } from "child_process";
|
||||
|
||||
//#region src/RemoteHttpInterceptor.d.ts
|
||||
interface SerializedRequest {
|
||||
id: string;
|
||||
url: string;
|
||||
method: string;
|
||||
headers: Array<[string, string]>;
|
||||
credentials: RequestCredentials;
|
||||
body: string;
|
||||
}
|
||||
interface SerializedResponse {
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: Array<[string, string]>;
|
||||
body: string;
|
||||
}
|
||||
declare class RemoteHttpInterceptor extends BatchInterceptor<[ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor]> {
|
||||
constructor();
|
||||
protected setup(): void;
|
||||
}
|
||||
declare function requestReviver(key: string, value: any): any;
|
||||
interface RemoveResolverOptions {
|
||||
process: ChildProcess;
|
||||
}
|
||||
declare class RemoteHttpResolver extends Interceptor<HttpRequestEventMap> {
|
||||
static symbol: symbol;
|
||||
private process;
|
||||
constructor(options: RemoveResolverOptions);
|
||||
protected setup(): void;
|
||||
}
|
||||
//#endregion
|
||||
export { RemoteHttpInterceptor, RemoteHttpResolver, RemoveResolverOptions, SerializedRequest, SerializedResponse, requestReviver };
|
||||
//# sourceMappingURL=RemoteHttpInterceptor.d.cts.map
|
||||
39
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.d.mts
generated
vendored
Normal file
39
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.d.mts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { l as HttpRequestEventMap, r as Interceptor } from "./Interceptor-DEazpLJd.mjs";
|
||||
import { t as BatchInterceptor } from "./BatchInterceptor-D7mXzHcQ.mjs";
|
||||
import { t as ClientRequestInterceptor } from "./index-C0YAQ36w.mjs";
|
||||
import { XMLHttpRequestInterceptor } from "./interceptors/XMLHttpRequest/index.mjs";
|
||||
import { FetchInterceptor } from "./interceptors/fetch/index.mjs";
|
||||
import { ChildProcess } from "child_process";
|
||||
|
||||
//#region src/RemoteHttpInterceptor.d.ts
|
||||
interface SerializedRequest {
|
||||
id: string;
|
||||
url: string;
|
||||
method: string;
|
||||
headers: Array<[string, string]>;
|
||||
credentials: RequestCredentials;
|
||||
body: string;
|
||||
}
|
||||
interface SerializedResponse {
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: Array<[string, string]>;
|
||||
body: string;
|
||||
}
|
||||
declare class RemoteHttpInterceptor extends BatchInterceptor<[ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor]> {
|
||||
constructor();
|
||||
protected setup(): void;
|
||||
}
|
||||
declare function requestReviver(key: string, value: any): any;
|
||||
interface RemoveResolverOptions {
|
||||
process: ChildProcess;
|
||||
}
|
||||
declare class RemoteHttpResolver extends Interceptor<HttpRequestEventMap> {
|
||||
static symbol: symbol;
|
||||
private process;
|
||||
constructor(options: RemoveResolverOptions);
|
||||
protected setup(): void;
|
||||
}
|
||||
//#endregion
|
||||
export { RemoteHttpInterceptor, RemoteHttpResolver, RemoveResolverOptions, SerializedRequest, SerializedResponse, requestReviver };
|
||||
//# sourceMappingURL=RemoteHttpInterceptor.d.mts.map
|
||||
152
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.mjs
generated
vendored
Normal file
152
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.mjs
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
import { i as RequestController, s as Interceptor, t as FetchResponse } from "./fetchUtils-CoU35g3M.mjs";
|
||||
import { t as BatchInterceptor } from "./BatchInterceptor-DFaBPilf.mjs";
|
||||
import "./bufferUtils-_8XfKIfX.mjs";
|
||||
import { t as ClientRequestInterceptor } from "./ClientRequest-Ca8Qykuv.mjs";
|
||||
import { n as isResponseError, t as handleRequest } from "./handleRequest-Y97UwBbF.mjs";
|
||||
import "./node-DwCc6iuP.mjs";
|
||||
import { t as XMLHttpRequestInterceptor } from "./XMLHttpRequest-C8dIZpds.mjs";
|
||||
import { t as FetchInterceptor } from "./fetch-G1DVwDKG.mjs";
|
||||
|
||||
//#region src/RemoteHttpInterceptor.ts
|
||||
var RemoteHttpInterceptor = class extends BatchInterceptor {
|
||||
constructor() {
|
||||
super({
|
||||
name: "remote-interceptor",
|
||||
interceptors: [
|
||||
new ClientRequestInterceptor(),
|
||||
new XMLHttpRequestInterceptor(),
|
||||
new FetchInterceptor()
|
||||
]
|
||||
});
|
||||
}
|
||||
setup() {
|
||||
super.setup();
|
||||
let handleParentMessage;
|
||||
this.on("request", async ({ request, requestId, controller }) => {
|
||||
const serializedRequest = JSON.stringify({
|
||||
id: requestId,
|
||||
method: request.method,
|
||||
url: request.url,
|
||||
headers: Array.from(request.headers.entries()),
|
||||
credentials: request.credentials,
|
||||
body: ["GET", "HEAD"].includes(request.method) ? null : await request.text()
|
||||
});
|
||||
this.logger.info("sent serialized request to the child:", serializedRequest);
|
||||
process.send?.(`request:${serializedRequest}`);
|
||||
const responsePromise = new Promise((resolve) => {
|
||||
handleParentMessage = (message) => {
|
||||
if (typeof message !== "string") return resolve();
|
||||
if (message.startsWith(`response:${requestId}`)) {
|
||||
const [, serializedResponse] = message.match(/^response:.+?:(.+)$/) || [];
|
||||
if (!serializedResponse) return resolve();
|
||||
const responseInit = JSON.parse(serializedResponse);
|
||||
const mockedResponse = new FetchResponse(responseInit.body, {
|
||||
url: request.url,
|
||||
status: responseInit.status,
|
||||
statusText: responseInit.statusText,
|
||||
headers: responseInit.headers
|
||||
});
|
||||
/**
|
||||
* @todo Support "errorWith" as well.
|
||||
* This response handling from the child is incomplete.
|
||||
*/
|
||||
controller.respondWith(mockedResponse);
|
||||
return resolve();
|
||||
}
|
||||
};
|
||||
});
|
||||
this.logger.info("add \"message\" listener to the parent process", handleParentMessage);
|
||||
process.addListener("message", handleParentMessage);
|
||||
return responsePromise;
|
||||
});
|
||||
this.subscriptions.push(() => {
|
||||
process.removeListener("message", handleParentMessage);
|
||||
});
|
||||
}
|
||||
};
|
||||
function requestReviver(key, value) {
|
||||
switch (key) {
|
||||
case "url": return new URL(value);
|
||||
case "headers": return new Headers(value);
|
||||
default: return value;
|
||||
}
|
||||
}
|
||||
var RemoteHttpResolver = class RemoteHttpResolver extends Interceptor {
|
||||
static {
|
||||
this.symbol = Symbol("remote-resolver");
|
||||
}
|
||||
constructor(options) {
|
||||
super(RemoteHttpResolver.symbol);
|
||||
this.process = options.process;
|
||||
}
|
||||
setup() {
|
||||
const logger = this.logger.extend("setup");
|
||||
const handleChildMessage = async (message) => {
|
||||
logger.info("received message from child!", message);
|
||||
if (typeof message !== "string" || !message.startsWith("request:")) {
|
||||
logger.info("unknown message, ignoring...");
|
||||
return;
|
||||
}
|
||||
const [, serializedRequest] = message.match(/^request:(.+)$/) || [];
|
||||
if (!serializedRequest) return;
|
||||
const requestJson = JSON.parse(serializedRequest, requestReviver);
|
||||
logger.info("parsed intercepted request", requestJson);
|
||||
const request = new Request(requestJson.url, {
|
||||
method: requestJson.method,
|
||||
headers: new Headers(requestJson.headers),
|
||||
credentials: requestJson.credentials,
|
||||
body: requestJson.body
|
||||
});
|
||||
const controller = new RequestController(request, {
|
||||
passthrough: () => {},
|
||||
respondWith: async (response) => {
|
||||
if (isResponseError(response)) {
|
||||
this.logger.info("received a network error!", { response });
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
this.logger.info("received mocked response!", { response });
|
||||
const responseClone = response.clone();
|
||||
const responseText = await responseClone.text();
|
||||
const serializedResponse = JSON.stringify({
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: Array.from(response.headers.entries()),
|
||||
body: responseText
|
||||
});
|
||||
this.process.send(`response:${requestJson.id}:${serializedResponse}`, (error) => {
|
||||
if (error) return;
|
||||
this.emitter.emit("response", {
|
||||
request,
|
||||
requestId: requestJson.id,
|
||||
response: responseClone,
|
||||
isMockedResponse: true
|
||||
});
|
||||
});
|
||||
logger.info("sent serialized mocked response to the parent:", serializedResponse);
|
||||
},
|
||||
errorWith: (reason) => {
|
||||
this.logger.info("request has errored!", { error: reason });
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
});
|
||||
await handleRequest({
|
||||
request,
|
||||
requestId: requestJson.id,
|
||||
controller,
|
||||
emitter: this.emitter
|
||||
});
|
||||
};
|
||||
this.subscriptions.push(() => {
|
||||
this.process.removeListener("message", handleChildMessage);
|
||||
logger.info("removed the \"message\" listener from the child process!");
|
||||
});
|
||||
logger.info("adding a \"message\" listener to the child process");
|
||||
this.process.addListener("message", handleChildMessage);
|
||||
this.process.once("error", () => this.dispose());
|
||||
this.process.once("exit", () => this.dispose());
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { RemoteHttpInterceptor, RemoteHttpResolver, requestReviver };
|
||||
//# sourceMappingURL=RemoteHttpInterceptor.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/RemoteHttpInterceptor.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
763
node_modules/@mswjs/interceptors/lib/node/XMLHttpRequest-B7kJdYYI.cjs
generated
vendored
Normal file
763
node_modules/@mswjs/interceptors/lib/node/XMLHttpRequest-B7kJdYYI.cjs
generated
vendored
Normal file
@@ -0,0 +1,763 @@
|
||||
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
||||
const require_glossary = require('./glossary-BLKRyLBd.cjs');
|
||||
const require_fetchUtils = require('./fetchUtils-BaY5iWXw.cjs');
|
||||
const require_bufferUtils = require('./bufferUtils-DiCTqG-7.cjs');
|
||||
const require_getRawRequest = require('./getRawRequest-BavnMWh_.cjs');
|
||||
const require_handleRequest = require('./handleRequest-Bb7Y-XLw.cjs');
|
||||
const require_hasConfigurableGlobal = require('./hasConfigurableGlobal-C97fWuaA.cjs');
|
||||
let outvariant = require("outvariant");
|
||||
let is_node_process = require("is-node-process");
|
||||
|
||||
//#region src/interceptors/XMLHttpRequest/utils/concatArrayBuffer.ts
|
||||
/**
|
||||
* Concatenate two `Uint8Array` buffers.
|
||||
*/
|
||||
function concatArrayBuffer(left, right) {
|
||||
const result = new Uint8Array(left.byteLength + right.byteLength);
|
||||
result.set(left, 0);
|
||||
result.set(right, left.byteLength);
|
||||
return result;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/polyfills/EventPolyfill.ts
|
||||
var EventPolyfill = class {
|
||||
constructor(type, options) {
|
||||
this.NONE = 0;
|
||||
this.CAPTURING_PHASE = 1;
|
||||
this.AT_TARGET = 2;
|
||||
this.BUBBLING_PHASE = 3;
|
||||
this.type = "";
|
||||
this.srcElement = null;
|
||||
this.currentTarget = null;
|
||||
this.eventPhase = 0;
|
||||
this.isTrusted = true;
|
||||
this.composed = false;
|
||||
this.cancelable = true;
|
||||
this.defaultPrevented = false;
|
||||
this.bubbles = true;
|
||||
this.lengthComputable = true;
|
||||
this.loaded = 0;
|
||||
this.total = 0;
|
||||
this.cancelBubble = false;
|
||||
this.returnValue = true;
|
||||
this.type = type;
|
||||
this.target = options?.target || null;
|
||||
this.currentTarget = options?.currentTarget || null;
|
||||
this.timeStamp = Date.now();
|
||||
}
|
||||
composedPath() {
|
||||
return [];
|
||||
}
|
||||
initEvent(type, bubbles, cancelable) {
|
||||
this.type = type;
|
||||
this.bubbles = !!bubbles;
|
||||
this.cancelable = !!cancelable;
|
||||
}
|
||||
preventDefault() {
|
||||
this.defaultPrevented = true;
|
||||
}
|
||||
stopPropagation() {}
|
||||
stopImmediatePropagation() {}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.ts
|
||||
var ProgressEventPolyfill = class extends EventPolyfill {
|
||||
constructor(type, init) {
|
||||
super(type);
|
||||
this.lengthComputable = init?.lengthComputable || false;
|
||||
this.composed = init?.composed || false;
|
||||
this.loaded = init?.loaded || 0;
|
||||
this.total = init?.total || 0;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/utils/createEvent.ts
|
||||
const SUPPORTS_PROGRESS_EVENT = typeof ProgressEvent !== "undefined";
|
||||
function createEvent(target, type, init) {
|
||||
const progressEvents = [
|
||||
"error",
|
||||
"progress",
|
||||
"loadstart",
|
||||
"loadend",
|
||||
"load",
|
||||
"timeout",
|
||||
"abort"
|
||||
];
|
||||
/**
|
||||
* `ProgressEvent` is not supported in React Native.
|
||||
* @see https://github.com/mswjs/interceptors/issues/40
|
||||
*/
|
||||
const ProgressEventClass = SUPPORTS_PROGRESS_EVENT ? ProgressEvent : ProgressEventPolyfill;
|
||||
return progressEvents.includes(type) ? new ProgressEventClass(type, {
|
||||
lengthComputable: true,
|
||||
loaded: init?.loaded || 0,
|
||||
total: init?.total || 0
|
||||
}) : new EventPolyfill(type, {
|
||||
target,
|
||||
currentTarget: target
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/findPropertySource.ts
|
||||
/**
|
||||
* Returns the source object of the given property on the target object
|
||||
* (the target itself, any parent in its prototype, or null).
|
||||
*/
|
||||
function findPropertySource(target, propertyName) {
|
||||
if (!(propertyName in target)) return null;
|
||||
if (Object.prototype.hasOwnProperty.call(target, propertyName)) return target;
|
||||
const prototype = Reflect.getPrototypeOf(target);
|
||||
return prototype ? findPropertySource(prototype, propertyName) : null;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/createProxy.ts
|
||||
function createProxy(target, options) {
|
||||
return new Proxy(target, optionsToProxyHandler(options));
|
||||
}
|
||||
function optionsToProxyHandler(options) {
|
||||
const { constructorCall, methodCall, getProperty, setProperty } = options;
|
||||
const handler = {};
|
||||
if (typeof constructorCall !== "undefined") handler.construct = function(target, args, newTarget) {
|
||||
const next = Reflect.construct.bind(null, target, args, newTarget);
|
||||
return constructorCall.call(newTarget, args, next);
|
||||
};
|
||||
handler.set = function(target, propertyName, nextValue) {
|
||||
const next = () => {
|
||||
const propertySource = findPropertySource(target, propertyName) || target;
|
||||
const ownDescriptors = Reflect.getOwnPropertyDescriptor(propertySource, propertyName);
|
||||
if (typeof ownDescriptors?.set !== "undefined") {
|
||||
ownDescriptors.set.apply(target, [nextValue]);
|
||||
return true;
|
||||
}
|
||||
return Reflect.defineProperty(propertySource, propertyName, {
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: nextValue
|
||||
});
|
||||
};
|
||||
if (typeof setProperty !== "undefined") return setProperty.call(target, [propertyName, nextValue], next);
|
||||
return next();
|
||||
};
|
||||
handler.get = function(target, propertyName, receiver) {
|
||||
/**
|
||||
* @note Using `Reflect.get()` here causes "TypeError: Illegal invocation".
|
||||
*/
|
||||
const next = () => target[propertyName];
|
||||
const value = typeof getProperty !== "undefined" ? getProperty.call(target, [propertyName, receiver], next) : next();
|
||||
if (typeof value === "function") return (...args) => {
|
||||
const next$1 = value.bind(target, ...args);
|
||||
if (typeof methodCall !== "undefined") return methodCall.call(target, [propertyName, args], next$1);
|
||||
return next$1();
|
||||
};
|
||||
return value;
|
||||
};
|
||||
return handler;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.ts
|
||||
function isDomParserSupportedType(type) {
|
||||
return [
|
||||
"application/xhtml+xml",
|
||||
"application/xml",
|
||||
"image/svg+xml",
|
||||
"text/html",
|
||||
"text/xml"
|
||||
].some((supportedType) => {
|
||||
return type.startsWith(supportedType);
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/parseJson.ts
|
||||
/**
|
||||
* Parses a given string into JSON.
|
||||
* Gracefully handles invalid JSON by returning `null`.
|
||||
*/
|
||||
function parseJson(data) {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/utils/createResponse.ts
|
||||
/**
|
||||
* Creates a Fetch API `Response` instance from the given
|
||||
* `XMLHttpRequest` instance and a response body.
|
||||
*/
|
||||
function createResponse(request, body) {
|
||||
return new require_fetchUtils.FetchResponse(require_fetchUtils.FetchResponse.isResponseWithBody(request.status) ? body : null, {
|
||||
url: request.responseURL,
|
||||
status: request.status,
|
||||
statusText: request.statusText,
|
||||
headers: createHeadersFromXMLHttpRequestHeaders(request.getAllResponseHeaders())
|
||||
});
|
||||
}
|
||||
function createHeadersFromXMLHttpRequestHeaders(headersString) {
|
||||
const headers = new Headers();
|
||||
const lines = headersString.split(/[\r\n]+/);
|
||||
for (const line of lines) {
|
||||
if (line.trim() === "") continue;
|
||||
const [name, ...parts] = line.split(": ");
|
||||
const value = parts.join(": ");
|
||||
headers.append(name, value);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/utils/getBodyByteLength.ts
|
||||
/**
|
||||
* Return a total byte length of the given request/response body.
|
||||
* If the `Content-Length` header is present, it will be used as the byte length.
|
||||
*/
|
||||
async function getBodyByteLength(input) {
|
||||
const explicitContentLength = input.headers.get("content-length");
|
||||
if (explicitContentLength != null && explicitContentLength !== "") return Number(explicitContentLength);
|
||||
return (await input.arrayBuffer()).byteLength;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts
|
||||
const kIsRequestHandled = Symbol("kIsRequestHandled");
|
||||
const IS_NODE = (0, is_node_process.isNodeProcess)();
|
||||
const kFetchRequest = Symbol("kFetchRequest");
|
||||
/**
|
||||
* An `XMLHttpRequest` instance controller that allows us
|
||||
* to handle any given request instance (e.g. responding to it).
|
||||
*/
|
||||
var XMLHttpRequestController = class {
|
||||
constructor(initialRequest, logger) {
|
||||
this.initialRequest = initialRequest;
|
||||
this.logger = logger;
|
||||
this.method = "GET";
|
||||
this.url = null;
|
||||
this[kIsRequestHandled] = false;
|
||||
this.events = /* @__PURE__ */ new Map();
|
||||
this.uploadEvents = /* @__PURE__ */ new Map();
|
||||
this.requestId = require_fetchUtils.createRequestId();
|
||||
this.requestHeaders = new Headers();
|
||||
this.responseBuffer = new Uint8Array();
|
||||
this.request = createProxy(initialRequest, {
|
||||
setProperty: ([propertyName, nextValue], invoke) => {
|
||||
switch (propertyName) {
|
||||
case "ontimeout": {
|
||||
const eventName = propertyName.slice(2);
|
||||
/**
|
||||
* @note Proxy callbacks to event listeners because JSDOM has trouble
|
||||
* translating these properties to callbacks. It seemed to be operating
|
||||
* on events exclusively.
|
||||
*/
|
||||
this.request.addEventListener(eventName, nextValue);
|
||||
return invoke();
|
||||
}
|
||||
default: return invoke();
|
||||
}
|
||||
},
|
||||
methodCall: ([methodName, args], invoke) => {
|
||||
switch (methodName) {
|
||||
case "open": {
|
||||
const [method, url] = args;
|
||||
if (typeof url === "undefined") {
|
||||
this.method = "GET";
|
||||
this.url = toAbsoluteUrl(method);
|
||||
} else {
|
||||
this.method = method;
|
||||
this.url = toAbsoluteUrl(url);
|
||||
}
|
||||
this.logger = this.logger.extend(`${this.method} ${this.url.href}`);
|
||||
this.logger.info("open", this.method, this.url.href);
|
||||
return invoke();
|
||||
}
|
||||
case "addEventListener": {
|
||||
const [eventName, listener] = args;
|
||||
this.registerEvent(eventName, listener);
|
||||
this.logger.info("addEventListener", eventName, listener);
|
||||
return invoke();
|
||||
}
|
||||
case "setRequestHeader": {
|
||||
const [name, value] = args;
|
||||
this.requestHeaders.set(name, value);
|
||||
this.logger.info("setRequestHeader", name, value);
|
||||
return invoke();
|
||||
}
|
||||
case "send": {
|
||||
const [body] = args;
|
||||
this.request.addEventListener("load", () => {
|
||||
if (typeof this.onResponse !== "undefined") {
|
||||
const fetchResponse = createResponse(
|
||||
this.request,
|
||||
/**
|
||||
* The `response` property is the right way to read
|
||||
* the ambiguous response body, as the request's "responseType" may differ.
|
||||
* @see https://xhr.spec.whatwg.org/#the-response-attribute
|
||||
*/
|
||||
this.request.response
|
||||
);
|
||||
this.onResponse.call(this, {
|
||||
response: fetchResponse,
|
||||
isMockedResponse: this[kIsRequestHandled],
|
||||
request: fetchRequest,
|
||||
requestId: this.requestId
|
||||
});
|
||||
}
|
||||
});
|
||||
const requestBody = typeof body === "string" ? require_bufferUtils.encodeBuffer(body) : body;
|
||||
const fetchRequest = this.toFetchApiRequest(requestBody);
|
||||
this[kFetchRequest] = fetchRequest.clone();
|
||||
/**
|
||||
* @note Start request handling on the next tick so that the user
|
||||
* could add event listeners for "loadend" before the interceptor fires it.
|
||||
*/
|
||||
queueMicrotask(() => {
|
||||
(this.onRequest?.call(this, {
|
||||
request: fetchRequest,
|
||||
requestId: this.requestId
|
||||
}) || Promise.resolve()).finally(() => {
|
||||
if (!this[kIsRequestHandled]) {
|
||||
this.logger.info("request callback settled but request has not been handled (readystate %d), performing as-is...", this.request.readyState);
|
||||
/**
|
||||
* @note Set the intercepted request ID on the original request in Node.js
|
||||
* so that if it triggers any other interceptors, they don't attempt
|
||||
* to process it once again.
|
||||
*
|
||||
* For instance, XMLHttpRequest is often implemented via "http.ClientRequest"
|
||||
* and we don't want for both XHR and ClientRequest interceptors to
|
||||
* handle the same request at the same time (e.g. emit the "response" event twice).
|
||||
*/
|
||||
if (IS_NODE) this.request.setRequestHeader(require_fetchUtils.INTERNAL_REQUEST_ID_HEADER_NAME, this.requestId);
|
||||
return invoke();
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: return invoke();
|
||||
}
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Proxy the `.upload` property to gather the event listeners/callbacks.
|
||||
*/
|
||||
define(this.request, "upload", createProxy(this.request.upload, {
|
||||
setProperty: ([propertyName, nextValue], invoke) => {
|
||||
switch (propertyName) {
|
||||
case "onloadstart":
|
||||
case "onprogress":
|
||||
case "onaboart":
|
||||
case "onerror":
|
||||
case "onload":
|
||||
case "ontimeout":
|
||||
case "onloadend": {
|
||||
const eventName = propertyName.slice(2);
|
||||
this.registerUploadEvent(eventName, nextValue);
|
||||
}
|
||||
}
|
||||
return invoke();
|
||||
},
|
||||
methodCall: ([methodName, args], invoke) => {
|
||||
switch (methodName) {
|
||||
case "addEventListener": {
|
||||
const [eventName, listener] = args;
|
||||
this.registerUploadEvent(eventName, listener);
|
||||
this.logger.info("upload.addEventListener", eventName, listener);
|
||||
return invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
registerEvent(eventName, listener) {
|
||||
const nextEvents = (this.events.get(eventName) || []).concat(listener);
|
||||
this.events.set(eventName, nextEvents);
|
||||
this.logger.info("registered event \"%s\"", eventName, listener);
|
||||
}
|
||||
registerUploadEvent(eventName, listener) {
|
||||
const nextEvents = (this.uploadEvents.get(eventName) || []).concat(listener);
|
||||
this.uploadEvents.set(eventName, nextEvents);
|
||||
this.logger.info("registered upload event \"%s\"", eventName, listener);
|
||||
}
|
||||
/**
|
||||
* Responds to the current request with the given
|
||||
* Fetch API `Response` instance.
|
||||
*/
|
||||
async respondWith(response) {
|
||||
/**
|
||||
* @note Since `XMLHttpRequestController` delegates the handling of the responses
|
||||
* to the "load" event listener that doesn't distinguish between the mocked and original
|
||||
* responses, mark the request that had a mocked response with a corresponding symbol.
|
||||
*
|
||||
* Mark this request as having a mocked response immediately since
|
||||
* calculating request/response total body length is asynchronous.
|
||||
*/
|
||||
this[kIsRequestHandled] = true;
|
||||
/**
|
||||
* Dispatch request upload events for requests with a body.
|
||||
* @see https://github.com/mswjs/interceptors/issues/573
|
||||
*/
|
||||
if (this[kFetchRequest]) {
|
||||
const totalRequestBodyLength = await getBodyByteLength(this[kFetchRequest]);
|
||||
this.trigger("loadstart", this.request.upload, {
|
||||
loaded: 0,
|
||||
total: totalRequestBodyLength
|
||||
});
|
||||
this.trigger("progress", this.request.upload, {
|
||||
loaded: totalRequestBodyLength,
|
||||
total: totalRequestBodyLength
|
||||
});
|
||||
this.trigger("load", this.request.upload, {
|
||||
loaded: totalRequestBodyLength,
|
||||
total: totalRequestBodyLength
|
||||
});
|
||||
this.trigger("loadend", this.request.upload, {
|
||||
loaded: totalRequestBodyLength,
|
||||
total: totalRequestBodyLength
|
||||
});
|
||||
}
|
||||
this.logger.info("responding with a mocked response: %d %s", response.status, response.statusText);
|
||||
define(this.request, "status", response.status);
|
||||
define(this.request, "statusText", response.statusText);
|
||||
define(this.request, "responseURL", this.url.href);
|
||||
this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, { apply: (_, __, args) => {
|
||||
this.logger.info("getResponseHeader", args[0]);
|
||||
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
||||
this.logger.info("headers not received yet, returning null");
|
||||
return null;
|
||||
}
|
||||
const headerValue = response.headers.get(args[0]);
|
||||
this.logger.info("resolved response header \"%s\" to", args[0], headerValue);
|
||||
return headerValue;
|
||||
} });
|
||||
this.request.getAllResponseHeaders = new Proxy(this.request.getAllResponseHeaders, { apply: () => {
|
||||
this.logger.info("getAllResponseHeaders");
|
||||
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
||||
this.logger.info("headers not received yet, returning empty string");
|
||||
return "";
|
||||
}
|
||||
const allHeaders = Array.from(response.headers.entries()).map(([headerName, headerValue]) => {
|
||||
return `${headerName}: ${headerValue}`;
|
||||
}).join("\r\n");
|
||||
this.logger.info("resolved all response headers to", allHeaders);
|
||||
return allHeaders;
|
||||
} });
|
||||
Object.defineProperties(this.request, {
|
||||
response: {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => this.response
|
||||
},
|
||||
responseText: {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => this.responseText
|
||||
},
|
||||
responseXML: {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => this.responseXML
|
||||
}
|
||||
});
|
||||
const totalResponseBodyLength = await getBodyByteLength(response.clone());
|
||||
this.logger.info("calculated response body length", totalResponseBodyLength);
|
||||
this.trigger("loadstart", this.request, {
|
||||
loaded: 0,
|
||||
total: totalResponseBodyLength
|
||||
});
|
||||
this.setReadyState(this.request.HEADERS_RECEIVED);
|
||||
this.setReadyState(this.request.LOADING);
|
||||
const finalizeResponse = () => {
|
||||
this.logger.info("finalizing the mocked response...");
|
||||
this.setReadyState(this.request.DONE);
|
||||
this.trigger("load", this.request, {
|
||||
loaded: this.responseBuffer.byteLength,
|
||||
total: totalResponseBodyLength
|
||||
});
|
||||
this.trigger("loadend", this.request, {
|
||||
loaded: this.responseBuffer.byteLength,
|
||||
total: totalResponseBodyLength
|
||||
});
|
||||
};
|
||||
if (response.body) {
|
||||
this.logger.info("mocked response has body, streaming...");
|
||||
const reader = response.body.getReader();
|
||||
const readNextResponseBodyChunk = async () => {
|
||||
const { value, done } = await reader.read();
|
||||
if (done) {
|
||||
this.logger.info("response body stream done!");
|
||||
finalizeResponse();
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
this.logger.info("read response body chunk:", value);
|
||||
this.responseBuffer = concatArrayBuffer(this.responseBuffer, value);
|
||||
this.trigger("progress", this.request, {
|
||||
loaded: this.responseBuffer.byteLength,
|
||||
total: totalResponseBodyLength
|
||||
});
|
||||
}
|
||||
readNextResponseBodyChunk();
|
||||
};
|
||||
readNextResponseBodyChunk();
|
||||
} else finalizeResponse();
|
||||
}
|
||||
responseBufferToText() {
|
||||
return require_bufferUtils.decodeBuffer(this.responseBuffer);
|
||||
}
|
||||
get response() {
|
||||
this.logger.info("getResponse (responseType: %s)", this.request.responseType);
|
||||
if (this.request.readyState !== this.request.DONE) return null;
|
||||
switch (this.request.responseType) {
|
||||
case "json": {
|
||||
const responseJson = parseJson(this.responseBufferToText());
|
||||
this.logger.info("resolved response JSON", responseJson);
|
||||
return responseJson;
|
||||
}
|
||||
case "arraybuffer": {
|
||||
const arrayBuffer = require_bufferUtils.toArrayBuffer(this.responseBuffer);
|
||||
this.logger.info("resolved response ArrayBuffer", arrayBuffer);
|
||||
return arrayBuffer;
|
||||
}
|
||||
case "blob": {
|
||||
const mimeType = this.request.getResponseHeader("Content-Type") || "text/plain";
|
||||
const responseBlob = new Blob([this.responseBufferToText()], { type: mimeType });
|
||||
this.logger.info("resolved response Blob (mime type: %s)", responseBlob, mimeType);
|
||||
return responseBlob;
|
||||
}
|
||||
default: {
|
||||
const responseText = this.responseBufferToText();
|
||||
this.logger.info("resolving \"%s\" response type as text", this.request.responseType, responseText);
|
||||
return responseText;
|
||||
}
|
||||
}
|
||||
}
|
||||
get responseText() {
|
||||
/**
|
||||
* Throw when trying to read the response body as text when the
|
||||
* "responseType" doesn't expect text. This just respects the spec better.
|
||||
* @see https://xhr.spec.whatwg.org/#the-responsetext-attribute
|
||||
*/
|
||||
(0, outvariant.invariant)(this.request.responseType === "" || this.request.responseType === "text", "InvalidStateError: The object is in invalid state.");
|
||||
if (this.request.readyState !== this.request.LOADING && this.request.readyState !== this.request.DONE) return "";
|
||||
const responseText = this.responseBufferToText();
|
||||
this.logger.info("getResponseText: \"%s\"", responseText);
|
||||
return responseText;
|
||||
}
|
||||
get responseXML() {
|
||||
(0, outvariant.invariant)(this.request.responseType === "" || this.request.responseType === "document", "InvalidStateError: The object is in invalid state.");
|
||||
if (this.request.readyState !== this.request.DONE) return null;
|
||||
const contentType = this.request.getResponseHeader("Content-Type") || "";
|
||||
if (typeof DOMParser === "undefined") {
|
||||
console.warn("Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly.");
|
||||
return null;
|
||||
}
|
||||
if (isDomParserSupportedType(contentType)) return new DOMParser().parseFromString(this.responseBufferToText(), contentType);
|
||||
return null;
|
||||
}
|
||||
errorWith(error) {
|
||||
/**
|
||||
* @note Mark this request as handled even if it received a mock error.
|
||||
* This prevents the controller from trying to perform this request as-is.
|
||||
*/
|
||||
this[kIsRequestHandled] = true;
|
||||
this.logger.info("responding with an error");
|
||||
this.setReadyState(this.request.DONE);
|
||||
this.trigger("error", this.request);
|
||||
this.trigger("loadend", this.request);
|
||||
}
|
||||
/**
|
||||
* Transitions this request's `readyState` to the given one.
|
||||
*/
|
||||
setReadyState(nextReadyState) {
|
||||
this.logger.info("setReadyState: %d -> %d", this.request.readyState, nextReadyState);
|
||||
if (this.request.readyState === nextReadyState) {
|
||||
this.logger.info("ready state identical, skipping transition...");
|
||||
return;
|
||||
}
|
||||
define(this.request, "readyState", nextReadyState);
|
||||
this.logger.info("set readyState to: %d", nextReadyState);
|
||||
if (nextReadyState !== this.request.UNSENT) {
|
||||
this.logger.info("triggering \"readystatechange\" event...");
|
||||
this.trigger("readystatechange", this.request);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Triggers given event on the `XMLHttpRequest` instance.
|
||||
*/
|
||||
trigger(eventName, target, options) {
|
||||
const callback = target[`on${eventName}`];
|
||||
const event = createEvent(target, eventName, options);
|
||||
this.logger.info("trigger \"%s\"", eventName, options || "");
|
||||
if (typeof callback === "function") {
|
||||
this.logger.info("found a direct \"%s\" callback, calling...", eventName);
|
||||
callback.call(target, event);
|
||||
}
|
||||
const events = target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events;
|
||||
for (const [registeredEventName, listeners] of events) if (registeredEventName === eventName) {
|
||||
this.logger.info("found %d listener(s) for \"%s\" event, calling...", listeners.length, eventName);
|
||||
listeners.forEach((listener) => listener.call(target, event));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
|
||||
*/
|
||||
toFetchApiRequest(body) {
|
||||
this.logger.info("converting request to a Fetch API Request...");
|
||||
const resolvedBody = body instanceof Document ? body.documentElement.innerText : body;
|
||||
const fetchRequest = new Request(this.url.href, {
|
||||
method: this.method,
|
||||
headers: this.requestHeaders,
|
||||
credentials: this.request.withCredentials ? "include" : "same-origin",
|
||||
body: ["GET", "HEAD"].includes(this.method.toUpperCase()) ? null : resolvedBody
|
||||
});
|
||||
define(fetchRequest, "headers", createProxy(fetchRequest.headers, { methodCall: ([methodName, args], invoke) => {
|
||||
switch (methodName) {
|
||||
case "append":
|
||||
case "set": {
|
||||
const [headerName, headerValue] = args;
|
||||
this.request.setRequestHeader(headerName, headerValue);
|
||||
break;
|
||||
}
|
||||
case "delete": {
|
||||
const [headerName] = args;
|
||||
console.warn(`XMLHttpRequest: Cannot remove a "${headerName}" header from the Fetch API representation of the "${fetchRequest.method} ${fetchRequest.url}" request. XMLHttpRequest headers cannot be removed.`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return invoke();
|
||||
} }));
|
||||
require_getRawRequest.setRawRequest(fetchRequest, this.request);
|
||||
this.logger.info("converted request to a Fetch API Request!", fetchRequest);
|
||||
return fetchRequest;
|
||||
}
|
||||
};
|
||||
function toAbsoluteUrl(url) {
|
||||
/**
|
||||
* @note XMLHttpRequest interceptor may run in environments
|
||||
* that implement XMLHttpRequest but don't implement "location"
|
||||
* (for example, React Native). If that's the case, return the
|
||||
* input URL as-is (nothing to be relative to).
|
||||
* @see https://github.com/mswjs/msw/issues/1777
|
||||
*/
|
||||
if (typeof location === "undefined") return new URL(url);
|
||||
return new URL(url.toString(), location.href);
|
||||
}
|
||||
function define(target, property, value) {
|
||||
Reflect.defineProperty(target, property, {
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
value
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts
|
||||
/**
|
||||
* Create a proxied `XMLHttpRequest` class.
|
||||
* The proxied class establishes spies on certain methods,
|
||||
* allowing us to intercept requests and respond to them.
|
||||
*/
|
||||
function createXMLHttpRequestProxy({ emitter, logger }) {
|
||||
return new Proxy(globalThis.XMLHttpRequest, { construct(target, args, newTarget) {
|
||||
logger.info("constructed new XMLHttpRequest");
|
||||
const originalRequest = Reflect.construct(target, args, newTarget);
|
||||
/**
|
||||
* @note Forward prototype descriptors onto the proxied object.
|
||||
* XMLHttpRequest is implemented in JSDOM in a way that assigns
|
||||
* a bunch of descriptors, like "set responseType()" on the prototype.
|
||||
* With this propagation, we make sure that those descriptors trigger
|
||||
* when the user operates with the proxied request instance.
|
||||
*/
|
||||
const prototypeDescriptors = Object.getOwnPropertyDescriptors(target.prototype);
|
||||
for (const propertyName in prototypeDescriptors) Reflect.defineProperty(originalRequest, propertyName, prototypeDescriptors[propertyName]);
|
||||
const xhrRequestController = new XMLHttpRequestController(originalRequest, logger);
|
||||
xhrRequestController.onRequest = async function({ request, requestId }) {
|
||||
const controller = new require_fetchUtils.RequestController(request, {
|
||||
passthrough: () => {
|
||||
this.logger.info("no mocked response received, performing request as-is...");
|
||||
},
|
||||
respondWith: async (response) => {
|
||||
if (require_handleRequest.isResponseError(response)) {
|
||||
this.errorWith(/* @__PURE__ */ new TypeError("Network error"));
|
||||
return;
|
||||
}
|
||||
await this.respondWith(response);
|
||||
},
|
||||
errorWith: (reason) => {
|
||||
this.logger.info("request errored!", { error: reason });
|
||||
if (reason instanceof Error) this.errorWith(reason);
|
||||
}
|
||||
});
|
||||
this.logger.info("awaiting mocked response...");
|
||||
this.logger.info("emitting the \"request\" event for %s listener(s)...", emitter.listenerCount("request"));
|
||||
await require_handleRequest.handleRequest({
|
||||
request,
|
||||
requestId,
|
||||
controller,
|
||||
emitter
|
||||
});
|
||||
};
|
||||
xhrRequestController.onResponse = async function({ response, isMockedResponse, request, requestId }) {
|
||||
this.logger.info("emitting the \"response\" event for %s listener(s)...", emitter.listenerCount("response"));
|
||||
emitter.emit("response", {
|
||||
response,
|
||||
isMockedResponse,
|
||||
request,
|
||||
requestId
|
||||
});
|
||||
};
|
||||
return xhrRequestController.request;
|
||||
} });
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/index.ts
|
||||
var XMLHttpRequestInterceptor = class XMLHttpRequestInterceptor extends require_fetchUtils.Interceptor {
|
||||
static {
|
||||
this.interceptorSymbol = Symbol("xhr");
|
||||
}
|
||||
constructor() {
|
||||
super(XMLHttpRequestInterceptor.interceptorSymbol);
|
||||
}
|
||||
checkEnvironment() {
|
||||
return require_hasConfigurableGlobal.hasConfigurableGlobal("XMLHttpRequest");
|
||||
}
|
||||
setup() {
|
||||
const logger = this.logger.extend("setup");
|
||||
logger.info("patching \"XMLHttpRequest\" module...");
|
||||
const PureXMLHttpRequest = globalThis.XMLHttpRequest;
|
||||
(0, outvariant.invariant)(!PureXMLHttpRequest[require_glossary.IS_PATCHED_MODULE], "Failed to patch the \"XMLHttpRequest\" module: already patched.");
|
||||
globalThis.XMLHttpRequest = createXMLHttpRequestProxy({
|
||||
emitter: this.emitter,
|
||||
logger: this.logger
|
||||
});
|
||||
logger.info("native \"XMLHttpRequest\" module patched!", globalThis.XMLHttpRequest.name);
|
||||
Object.defineProperty(globalThis.XMLHttpRequest, require_glossary.IS_PATCHED_MODULE, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: true
|
||||
});
|
||||
this.subscriptions.push(() => {
|
||||
Object.defineProperty(globalThis.XMLHttpRequest, require_glossary.IS_PATCHED_MODULE, { value: void 0 });
|
||||
globalThis.XMLHttpRequest = PureXMLHttpRequest;
|
||||
logger.info("native \"XMLHttpRequest\" module restored!", globalThis.XMLHttpRequest.name);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'XMLHttpRequestInterceptor', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return XMLHttpRequestInterceptor;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=XMLHttpRequest-B7kJdYYI.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/XMLHttpRequest-B7kJdYYI.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/XMLHttpRequest-B7kJdYYI.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
757
node_modules/@mswjs/interceptors/lib/node/XMLHttpRequest-C8dIZpds.mjs
generated
vendored
Normal file
757
node_modules/@mswjs/interceptors/lib/node/XMLHttpRequest-C8dIZpds.mjs
generated
vendored
Normal file
@@ -0,0 +1,757 @@
|
||||
import { t as IS_PATCHED_MODULE } from "./glossary-glQBRnVD.mjs";
|
||||
import { i as RequestController, o as INTERNAL_REQUEST_ID_HEADER_NAME, r as createRequestId, s as Interceptor, t as FetchResponse } from "./fetchUtils-CoU35g3M.mjs";
|
||||
import { n as encodeBuffer, r as toArrayBuffer, t as decodeBuffer } from "./bufferUtils-_8XfKIfX.mjs";
|
||||
import { n as setRawRequest } from "./getRawRequest-DnwmXyOW.mjs";
|
||||
import { n as isResponseError, t as handleRequest } from "./handleRequest-Y97UwBbF.mjs";
|
||||
import { t as hasConfigurableGlobal } from "./hasConfigurableGlobal-DBJA0vjm.mjs";
|
||||
import { invariant } from "outvariant";
|
||||
import { isNodeProcess } from "is-node-process";
|
||||
|
||||
//#region src/interceptors/XMLHttpRequest/utils/concatArrayBuffer.ts
|
||||
/**
|
||||
* Concatenate two `Uint8Array` buffers.
|
||||
*/
|
||||
function concatArrayBuffer(left, right) {
|
||||
const result = new Uint8Array(left.byteLength + right.byteLength);
|
||||
result.set(left, 0);
|
||||
result.set(right, left.byteLength);
|
||||
return result;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/polyfills/EventPolyfill.ts
|
||||
var EventPolyfill = class {
|
||||
constructor(type, options) {
|
||||
this.NONE = 0;
|
||||
this.CAPTURING_PHASE = 1;
|
||||
this.AT_TARGET = 2;
|
||||
this.BUBBLING_PHASE = 3;
|
||||
this.type = "";
|
||||
this.srcElement = null;
|
||||
this.currentTarget = null;
|
||||
this.eventPhase = 0;
|
||||
this.isTrusted = true;
|
||||
this.composed = false;
|
||||
this.cancelable = true;
|
||||
this.defaultPrevented = false;
|
||||
this.bubbles = true;
|
||||
this.lengthComputable = true;
|
||||
this.loaded = 0;
|
||||
this.total = 0;
|
||||
this.cancelBubble = false;
|
||||
this.returnValue = true;
|
||||
this.type = type;
|
||||
this.target = options?.target || null;
|
||||
this.currentTarget = options?.currentTarget || null;
|
||||
this.timeStamp = Date.now();
|
||||
}
|
||||
composedPath() {
|
||||
return [];
|
||||
}
|
||||
initEvent(type, bubbles, cancelable) {
|
||||
this.type = type;
|
||||
this.bubbles = !!bubbles;
|
||||
this.cancelable = !!cancelable;
|
||||
}
|
||||
preventDefault() {
|
||||
this.defaultPrevented = true;
|
||||
}
|
||||
stopPropagation() {}
|
||||
stopImmediatePropagation() {}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.ts
|
||||
var ProgressEventPolyfill = class extends EventPolyfill {
|
||||
constructor(type, init) {
|
||||
super(type);
|
||||
this.lengthComputable = init?.lengthComputable || false;
|
||||
this.composed = init?.composed || false;
|
||||
this.loaded = init?.loaded || 0;
|
||||
this.total = init?.total || 0;
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/utils/createEvent.ts
|
||||
const SUPPORTS_PROGRESS_EVENT = typeof ProgressEvent !== "undefined";
|
||||
function createEvent(target, type, init) {
|
||||
const progressEvents = [
|
||||
"error",
|
||||
"progress",
|
||||
"loadstart",
|
||||
"loadend",
|
||||
"load",
|
||||
"timeout",
|
||||
"abort"
|
||||
];
|
||||
/**
|
||||
* `ProgressEvent` is not supported in React Native.
|
||||
* @see https://github.com/mswjs/interceptors/issues/40
|
||||
*/
|
||||
const ProgressEventClass = SUPPORTS_PROGRESS_EVENT ? ProgressEvent : ProgressEventPolyfill;
|
||||
return progressEvents.includes(type) ? new ProgressEventClass(type, {
|
||||
lengthComputable: true,
|
||||
loaded: init?.loaded || 0,
|
||||
total: init?.total || 0
|
||||
}) : new EventPolyfill(type, {
|
||||
target,
|
||||
currentTarget: target
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/findPropertySource.ts
|
||||
/**
|
||||
* Returns the source object of the given property on the target object
|
||||
* (the target itself, any parent in its prototype, or null).
|
||||
*/
|
||||
function findPropertySource(target, propertyName) {
|
||||
if (!(propertyName in target)) return null;
|
||||
if (Object.prototype.hasOwnProperty.call(target, propertyName)) return target;
|
||||
const prototype = Reflect.getPrototypeOf(target);
|
||||
return prototype ? findPropertySource(prototype, propertyName) : null;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/createProxy.ts
|
||||
function createProxy(target, options) {
|
||||
return new Proxy(target, optionsToProxyHandler(options));
|
||||
}
|
||||
function optionsToProxyHandler(options) {
|
||||
const { constructorCall, methodCall, getProperty, setProperty } = options;
|
||||
const handler = {};
|
||||
if (typeof constructorCall !== "undefined") handler.construct = function(target, args, newTarget) {
|
||||
const next = Reflect.construct.bind(null, target, args, newTarget);
|
||||
return constructorCall.call(newTarget, args, next);
|
||||
};
|
||||
handler.set = function(target, propertyName, nextValue) {
|
||||
const next = () => {
|
||||
const propertySource = findPropertySource(target, propertyName) || target;
|
||||
const ownDescriptors = Reflect.getOwnPropertyDescriptor(propertySource, propertyName);
|
||||
if (typeof ownDescriptors?.set !== "undefined") {
|
||||
ownDescriptors.set.apply(target, [nextValue]);
|
||||
return true;
|
||||
}
|
||||
return Reflect.defineProperty(propertySource, propertyName, {
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: nextValue
|
||||
});
|
||||
};
|
||||
if (typeof setProperty !== "undefined") return setProperty.call(target, [propertyName, nextValue], next);
|
||||
return next();
|
||||
};
|
||||
handler.get = function(target, propertyName, receiver) {
|
||||
/**
|
||||
* @note Using `Reflect.get()` here causes "TypeError: Illegal invocation".
|
||||
*/
|
||||
const next = () => target[propertyName];
|
||||
const value = typeof getProperty !== "undefined" ? getProperty.call(target, [propertyName, receiver], next) : next();
|
||||
if (typeof value === "function") return (...args) => {
|
||||
const next$1 = value.bind(target, ...args);
|
||||
if (typeof methodCall !== "undefined") return methodCall.call(target, [propertyName, args], next$1);
|
||||
return next$1();
|
||||
};
|
||||
return value;
|
||||
};
|
||||
return handler;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.ts
|
||||
function isDomParserSupportedType(type) {
|
||||
return [
|
||||
"application/xhtml+xml",
|
||||
"application/xml",
|
||||
"image/svg+xml",
|
||||
"text/html",
|
||||
"text/xml"
|
||||
].some((supportedType) => {
|
||||
return type.startsWith(supportedType);
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/parseJson.ts
|
||||
/**
|
||||
* Parses a given string into JSON.
|
||||
* Gracefully handles invalid JSON by returning `null`.
|
||||
*/
|
||||
function parseJson(data) {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/utils/createResponse.ts
|
||||
/**
|
||||
* Creates a Fetch API `Response` instance from the given
|
||||
* `XMLHttpRequest` instance and a response body.
|
||||
*/
|
||||
function createResponse(request, body) {
|
||||
return new FetchResponse(FetchResponse.isResponseWithBody(request.status) ? body : null, {
|
||||
url: request.responseURL,
|
||||
status: request.status,
|
||||
statusText: request.statusText,
|
||||
headers: createHeadersFromXMLHttpRequestHeaders(request.getAllResponseHeaders())
|
||||
});
|
||||
}
|
||||
function createHeadersFromXMLHttpRequestHeaders(headersString) {
|
||||
const headers = new Headers();
|
||||
const lines = headersString.split(/[\r\n]+/);
|
||||
for (const line of lines) {
|
||||
if (line.trim() === "") continue;
|
||||
const [name, ...parts] = line.split(": ");
|
||||
const value = parts.join(": ");
|
||||
headers.append(name, value);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/utils/getBodyByteLength.ts
|
||||
/**
|
||||
* Return a total byte length of the given request/response body.
|
||||
* If the `Content-Length` header is present, it will be used as the byte length.
|
||||
*/
|
||||
async function getBodyByteLength(input) {
|
||||
const explicitContentLength = input.headers.get("content-length");
|
||||
if (explicitContentLength != null && explicitContentLength !== "") return Number(explicitContentLength);
|
||||
return (await input.arrayBuffer()).byteLength;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts
|
||||
const kIsRequestHandled = Symbol("kIsRequestHandled");
|
||||
const IS_NODE = isNodeProcess();
|
||||
const kFetchRequest = Symbol("kFetchRequest");
|
||||
/**
|
||||
* An `XMLHttpRequest` instance controller that allows us
|
||||
* to handle any given request instance (e.g. responding to it).
|
||||
*/
|
||||
var XMLHttpRequestController = class {
|
||||
constructor(initialRequest, logger) {
|
||||
this.initialRequest = initialRequest;
|
||||
this.logger = logger;
|
||||
this.method = "GET";
|
||||
this.url = null;
|
||||
this[kIsRequestHandled] = false;
|
||||
this.events = /* @__PURE__ */ new Map();
|
||||
this.uploadEvents = /* @__PURE__ */ new Map();
|
||||
this.requestId = createRequestId();
|
||||
this.requestHeaders = new Headers();
|
||||
this.responseBuffer = new Uint8Array();
|
||||
this.request = createProxy(initialRequest, {
|
||||
setProperty: ([propertyName, nextValue], invoke) => {
|
||||
switch (propertyName) {
|
||||
case "ontimeout": {
|
||||
const eventName = propertyName.slice(2);
|
||||
/**
|
||||
* @note Proxy callbacks to event listeners because JSDOM has trouble
|
||||
* translating these properties to callbacks. It seemed to be operating
|
||||
* on events exclusively.
|
||||
*/
|
||||
this.request.addEventListener(eventName, nextValue);
|
||||
return invoke();
|
||||
}
|
||||
default: return invoke();
|
||||
}
|
||||
},
|
||||
methodCall: ([methodName, args], invoke) => {
|
||||
switch (methodName) {
|
||||
case "open": {
|
||||
const [method, url] = args;
|
||||
if (typeof url === "undefined") {
|
||||
this.method = "GET";
|
||||
this.url = toAbsoluteUrl(method);
|
||||
} else {
|
||||
this.method = method;
|
||||
this.url = toAbsoluteUrl(url);
|
||||
}
|
||||
this.logger = this.logger.extend(`${this.method} ${this.url.href}`);
|
||||
this.logger.info("open", this.method, this.url.href);
|
||||
return invoke();
|
||||
}
|
||||
case "addEventListener": {
|
||||
const [eventName, listener] = args;
|
||||
this.registerEvent(eventName, listener);
|
||||
this.logger.info("addEventListener", eventName, listener);
|
||||
return invoke();
|
||||
}
|
||||
case "setRequestHeader": {
|
||||
const [name, value] = args;
|
||||
this.requestHeaders.set(name, value);
|
||||
this.logger.info("setRequestHeader", name, value);
|
||||
return invoke();
|
||||
}
|
||||
case "send": {
|
||||
const [body] = args;
|
||||
this.request.addEventListener("load", () => {
|
||||
if (typeof this.onResponse !== "undefined") {
|
||||
const fetchResponse = createResponse(
|
||||
this.request,
|
||||
/**
|
||||
* The `response` property is the right way to read
|
||||
* the ambiguous response body, as the request's "responseType" may differ.
|
||||
* @see https://xhr.spec.whatwg.org/#the-response-attribute
|
||||
*/
|
||||
this.request.response
|
||||
);
|
||||
this.onResponse.call(this, {
|
||||
response: fetchResponse,
|
||||
isMockedResponse: this[kIsRequestHandled],
|
||||
request: fetchRequest,
|
||||
requestId: this.requestId
|
||||
});
|
||||
}
|
||||
});
|
||||
const requestBody = typeof body === "string" ? encodeBuffer(body) : body;
|
||||
const fetchRequest = this.toFetchApiRequest(requestBody);
|
||||
this[kFetchRequest] = fetchRequest.clone();
|
||||
/**
|
||||
* @note Start request handling on the next tick so that the user
|
||||
* could add event listeners for "loadend" before the interceptor fires it.
|
||||
*/
|
||||
queueMicrotask(() => {
|
||||
(this.onRequest?.call(this, {
|
||||
request: fetchRequest,
|
||||
requestId: this.requestId
|
||||
}) || Promise.resolve()).finally(() => {
|
||||
if (!this[kIsRequestHandled]) {
|
||||
this.logger.info("request callback settled but request has not been handled (readystate %d), performing as-is...", this.request.readyState);
|
||||
/**
|
||||
* @note Set the intercepted request ID on the original request in Node.js
|
||||
* so that if it triggers any other interceptors, they don't attempt
|
||||
* to process it once again.
|
||||
*
|
||||
* For instance, XMLHttpRequest is often implemented via "http.ClientRequest"
|
||||
* and we don't want for both XHR and ClientRequest interceptors to
|
||||
* handle the same request at the same time (e.g. emit the "response" event twice).
|
||||
*/
|
||||
if (IS_NODE) this.request.setRequestHeader(INTERNAL_REQUEST_ID_HEADER_NAME, this.requestId);
|
||||
return invoke();
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: return invoke();
|
||||
}
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Proxy the `.upload` property to gather the event listeners/callbacks.
|
||||
*/
|
||||
define(this.request, "upload", createProxy(this.request.upload, {
|
||||
setProperty: ([propertyName, nextValue], invoke) => {
|
||||
switch (propertyName) {
|
||||
case "onloadstart":
|
||||
case "onprogress":
|
||||
case "onaboart":
|
||||
case "onerror":
|
||||
case "onload":
|
||||
case "ontimeout":
|
||||
case "onloadend": {
|
||||
const eventName = propertyName.slice(2);
|
||||
this.registerUploadEvent(eventName, nextValue);
|
||||
}
|
||||
}
|
||||
return invoke();
|
||||
},
|
||||
methodCall: ([methodName, args], invoke) => {
|
||||
switch (methodName) {
|
||||
case "addEventListener": {
|
||||
const [eventName, listener] = args;
|
||||
this.registerUploadEvent(eventName, listener);
|
||||
this.logger.info("upload.addEventListener", eventName, listener);
|
||||
return invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
registerEvent(eventName, listener) {
|
||||
const nextEvents = (this.events.get(eventName) || []).concat(listener);
|
||||
this.events.set(eventName, nextEvents);
|
||||
this.logger.info("registered event \"%s\"", eventName, listener);
|
||||
}
|
||||
registerUploadEvent(eventName, listener) {
|
||||
const nextEvents = (this.uploadEvents.get(eventName) || []).concat(listener);
|
||||
this.uploadEvents.set(eventName, nextEvents);
|
||||
this.logger.info("registered upload event \"%s\"", eventName, listener);
|
||||
}
|
||||
/**
|
||||
* Responds to the current request with the given
|
||||
* Fetch API `Response` instance.
|
||||
*/
|
||||
async respondWith(response) {
|
||||
/**
|
||||
* @note Since `XMLHttpRequestController` delegates the handling of the responses
|
||||
* to the "load" event listener that doesn't distinguish between the mocked and original
|
||||
* responses, mark the request that had a mocked response with a corresponding symbol.
|
||||
*
|
||||
* Mark this request as having a mocked response immediately since
|
||||
* calculating request/response total body length is asynchronous.
|
||||
*/
|
||||
this[kIsRequestHandled] = true;
|
||||
/**
|
||||
* Dispatch request upload events for requests with a body.
|
||||
* @see https://github.com/mswjs/interceptors/issues/573
|
||||
*/
|
||||
if (this[kFetchRequest]) {
|
||||
const totalRequestBodyLength = await getBodyByteLength(this[kFetchRequest]);
|
||||
this.trigger("loadstart", this.request.upload, {
|
||||
loaded: 0,
|
||||
total: totalRequestBodyLength
|
||||
});
|
||||
this.trigger("progress", this.request.upload, {
|
||||
loaded: totalRequestBodyLength,
|
||||
total: totalRequestBodyLength
|
||||
});
|
||||
this.trigger("load", this.request.upload, {
|
||||
loaded: totalRequestBodyLength,
|
||||
total: totalRequestBodyLength
|
||||
});
|
||||
this.trigger("loadend", this.request.upload, {
|
||||
loaded: totalRequestBodyLength,
|
||||
total: totalRequestBodyLength
|
||||
});
|
||||
}
|
||||
this.logger.info("responding with a mocked response: %d %s", response.status, response.statusText);
|
||||
define(this.request, "status", response.status);
|
||||
define(this.request, "statusText", response.statusText);
|
||||
define(this.request, "responseURL", this.url.href);
|
||||
this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, { apply: (_, __, args) => {
|
||||
this.logger.info("getResponseHeader", args[0]);
|
||||
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
||||
this.logger.info("headers not received yet, returning null");
|
||||
return null;
|
||||
}
|
||||
const headerValue = response.headers.get(args[0]);
|
||||
this.logger.info("resolved response header \"%s\" to", args[0], headerValue);
|
||||
return headerValue;
|
||||
} });
|
||||
this.request.getAllResponseHeaders = new Proxy(this.request.getAllResponseHeaders, { apply: () => {
|
||||
this.logger.info("getAllResponseHeaders");
|
||||
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
||||
this.logger.info("headers not received yet, returning empty string");
|
||||
return "";
|
||||
}
|
||||
const allHeaders = Array.from(response.headers.entries()).map(([headerName, headerValue]) => {
|
||||
return `${headerName}: ${headerValue}`;
|
||||
}).join("\r\n");
|
||||
this.logger.info("resolved all response headers to", allHeaders);
|
||||
return allHeaders;
|
||||
} });
|
||||
Object.defineProperties(this.request, {
|
||||
response: {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => this.response
|
||||
},
|
||||
responseText: {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => this.responseText
|
||||
},
|
||||
responseXML: {
|
||||
enumerable: true,
|
||||
configurable: false,
|
||||
get: () => this.responseXML
|
||||
}
|
||||
});
|
||||
const totalResponseBodyLength = await getBodyByteLength(response.clone());
|
||||
this.logger.info("calculated response body length", totalResponseBodyLength);
|
||||
this.trigger("loadstart", this.request, {
|
||||
loaded: 0,
|
||||
total: totalResponseBodyLength
|
||||
});
|
||||
this.setReadyState(this.request.HEADERS_RECEIVED);
|
||||
this.setReadyState(this.request.LOADING);
|
||||
const finalizeResponse = () => {
|
||||
this.logger.info("finalizing the mocked response...");
|
||||
this.setReadyState(this.request.DONE);
|
||||
this.trigger("load", this.request, {
|
||||
loaded: this.responseBuffer.byteLength,
|
||||
total: totalResponseBodyLength
|
||||
});
|
||||
this.trigger("loadend", this.request, {
|
||||
loaded: this.responseBuffer.byteLength,
|
||||
total: totalResponseBodyLength
|
||||
});
|
||||
};
|
||||
if (response.body) {
|
||||
this.logger.info("mocked response has body, streaming...");
|
||||
const reader = response.body.getReader();
|
||||
const readNextResponseBodyChunk = async () => {
|
||||
const { value, done } = await reader.read();
|
||||
if (done) {
|
||||
this.logger.info("response body stream done!");
|
||||
finalizeResponse();
|
||||
return;
|
||||
}
|
||||
if (value) {
|
||||
this.logger.info("read response body chunk:", value);
|
||||
this.responseBuffer = concatArrayBuffer(this.responseBuffer, value);
|
||||
this.trigger("progress", this.request, {
|
||||
loaded: this.responseBuffer.byteLength,
|
||||
total: totalResponseBodyLength
|
||||
});
|
||||
}
|
||||
readNextResponseBodyChunk();
|
||||
};
|
||||
readNextResponseBodyChunk();
|
||||
} else finalizeResponse();
|
||||
}
|
||||
responseBufferToText() {
|
||||
return decodeBuffer(this.responseBuffer);
|
||||
}
|
||||
get response() {
|
||||
this.logger.info("getResponse (responseType: %s)", this.request.responseType);
|
||||
if (this.request.readyState !== this.request.DONE) return null;
|
||||
switch (this.request.responseType) {
|
||||
case "json": {
|
||||
const responseJson = parseJson(this.responseBufferToText());
|
||||
this.logger.info("resolved response JSON", responseJson);
|
||||
return responseJson;
|
||||
}
|
||||
case "arraybuffer": {
|
||||
const arrayBuffer = toArrayBuffer(this.responseBuffer);
|
||||
this.logger.info("resolved response ArrayBuffer", arrayBuffer);
|
||||
return arrayBuffer;
|
||||
}
|
||||
case "blob": {
|
||||
const mimeType = this.request.getResponseHeader("Content-Type") || "text/plain";
|
||||
const responseBlob = new Blob([this.responseBufferToText()], { type: mimeType });
|
||||
this.logger.info("resolved response Blob (mime type: %s)", responseBlob, mimeType);
|
||||
return responseBlob;
|
||||
}
|
||||
default: {
|
||||
const responseText = this.responseBufferToText();
|
||||
this.logger.info("resolving \"%s\" response type as text", this.request.responseType, responseText);
|
||||
return responseText;
|
||||
}
|
||||
}
|
||||
}
|
||||
get responseText() {
|
||||
/**
|
||||
* Throw when trying to read the response body as text when the
|
||||
* "responseType" doesn't expect text. This just respects the spec better.
|
||||
* @see https://xhr.spec.whatwg.org/#the-responsetext-attribute
|
||||
*/
|
||||
invariant(this.request.responseType === "" || this.request.responseType === "text", "InvalidStateError: The object is in invalid state.");
|
||||
if (this.request.readyState !== this.request.LOADING && this.request.readyState !== this.request.DONE) return "";
|
||||
const responseText = this.responseBufferToText();
|
||||
this.logger.info("getResponseText: \"%s\"", responseText);
|
||||
return responseText;
|
||||
}
|
||||
get responseXML() {
|
||||
invariant(this.request.responseType === "" || this.request.responseType === "document", "InvalidStateError: The object is in invalid state.");
|
||||
if (this.request.readyState !== this.request.DONE) return null;
|
||||
const contentType = this.request.getResponseHeader("Content-Type") || "";
|
||||
if (typeof DOMParser === "undefined") {
|
||||
console.warn("Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly.");
|
||||
return null;
|
||||
}
|
||||
if (isDomParserSupportedType(contentType)) return new DOMParser().parseFromString(this.responseBufferToText(), contentType);
|
||||
return null;
|
||||
}
|
||||
errorWith(error) {
|
||||
/**
|
||||
* @note Mark this request as handled even if it received a mock error.
|
||||
* This prevents the controller from trying to perform this request as-is.
|
||||
*/
|
||||
this[kIsRequestHandled] = true;
|
||||
this.logger.info("responding with an error");
|
||||
this.setReadyState(this.request.DONE);
|
||||
this.trigger("error", this.request);
|
||||
this.trigger("loadend", this.request);
|
||||
}
|
||||
/**
|
||||
* Transitions this request's `readyState` to the given one.
|
||||
*/
|
||||
setReadyState(nextReadyState) {
|
||||
this.logger.info("setReadyState: %d -> %d", this.request.readyState, nextReadyState);
|
||||
if (this.request.readyState === nextReadyState) {
|
||||
this.logger.info("ready state identical, skipping transition...");
|
||||
return;
|
||||
}
|
||||
define(this.request, "readyState", nextReadyState);
|
||||
this.logger.info("set readyState to: %d", nextReadyState);
|
||||
if (nextReadyState !== this.request.UNSENT) {
|
||||
this.logger.info("triggering \"readystatechange\" event...");
|
||||
this.trigger("readystatechange", this.request);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Triggers given event on the `XMLHttpRequest` instance.
|
||||
*/
|
||||
trigger(eventName, target, options) {
|
||||
const callback = target[`on${eventName}`];
|
||||
const event = createEvent(target, eventName, options);
|
||||
this.logger.info("trigger \"%s\"", eventName, options || "");
|
||||
if (typeof callback === "function") {
|
||||
this.logger.info("found a direct \"%s\" callback, calling...", eventName);
|
||||
callback.call(target, event);
|
||||
}
|
||||
const events = target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events;
|
||||
for (const [registeredEventName, listeners] of events) if (registeredEventName === eventName) {
|
||||
this.logger.info("found %d listener(s) for \"%s\" event, calling...", listeners.length, eventName);
|
||||
listeners.forEach((listener) => listener.call(target, event));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
|
||||
*/
|
||||
toFetchApiRequest(body) {
|
||||
this.logger.info("converting request to a Fetch API Request...");
|
||||
const resolvedBody = body instanceof Document ? body.documentElement.innerText : body;
|
||||
const fetchRequest = new Request(this.url.href, {
|
||||
method: this.method,
|
||||
headers: this.requestHeaders,
|
||||
credentials: this.request.withCredentials ? "include" : "same-origin",
|
||||
body: ["GET", "HEAD"].includes(this.method.toUpperCase()) ? null : resolvedBody
|
||||
});
|
||||
define(fetchRequest, "headers", createProxy(fetchRequest.headers, { methodCall: ([methodName, args], invoke) => {
|
||||
switch (methodName) {
|
||||
case "append":
|
||||
case "set": {
|
||||
const [headerName, headerValue] = args;
|
||||
this.request.setRequestHeader(headerName, headerValue);
|
||||
break;
|
||||
}
|
||||
case "delete": {
|
||||
const [headerName] = args;
|
||||
console.warn(`XMLHttpRequest: Cannot remove a "${headerName}" header from the Fetch API representation of the "${fetchRequest.method} ${fetchRequest.url}" request. XMLHttpRequest headers cannot be removed.`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return invoke();
|
||||
} }));
|
||||
setRawRequest(fetchRequest, this.request);
|
||||
this.logger.info("converted request to a Fetch API Request!", fetchRequest);
|
||||
return fetchRequest;
|
||||
}
|
||||
};
|
||||
function toAbsoluteUrl(url) {
|
||||
/**
|
||||
* @note XMLHttpRequest interceptor may run in environments
|
||||
* that implement XMLHttpRequest but don't implement "location"
|
||||
* (for example, React Native). If that's the case, return the
|
||||
* input URL as-is (nothing to be relative to).
|
||||
* @see https://github.com/mswjs/msw/issues/1777
|
||||
*/
|
||||
if (typeof location === "undefined") return new URL(url);
|
||||
return new URL(url.toString(), location.href);
|
||||
}
|
||||
function define(target, property, value) {
|
||||
Reflect.defineProperty(target, property, {
|
||||
writable: true,
|
||||
enumerable: true,
|
||||
value
|
||||
});
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts
|
||||
/**
|
||||
* Create a proxied `XMLHttpRequest` class.
|
||||
* The proxied class establishes spies on certain methods,
|
||||
* allowing us to intercept requests and respond to them.
|
||||
*/
|
||||
function createXMLHttpRequestProxy({ emitter, logger }) {
|
||||
return new Proxy(globalThis.XMLHttpRequest, { construct(target, args, newTarget) {
|
||||
logger.info("constructed new XMLHttpRequest");
|
||||
const originalRequest = Reflect.construct(target, args, newTarget);
|
||||
/**
|
||||
* @note Forward prototype descriptors onto the proxied object.
|
||||
* XMLHttpRequest is implemented in JSDOM in a way that assigns
|
||||
* a bunch of descriptors, like "set responseType()" on the prototype.
|
||||
* With this propagation, we make sure that those descriptors trigger
|
||||
* when the user operates with the proxied request instance.
|
||||
*/
|
||||
const prototypeDescriptors = Object.getOwnPropertyDescriptors(target.prototype);
|
||||
for (const propertyName in prototypeDescriptors) Reflect.defineProperty(originalRequest, propertyName, prototypeDescriptors[propertyName]);
|
||||
const xhrRequestController = new XMLHttpRequestController(originalRequest, logger);
|
||||
xhrRequestController.onRequest = async function({ request, requestId }) {
|
||||
const controller = new RequestController(request, {
|
||||
passthrough: () => {
|
||||
this.logger.info("no mocked response received, performing request as-is...");
|
||||
},
|
||||
respondWith: async (response) => {
|
||||
if (isResponseError(response)) {
|
||||
this.errorWith(/* @__PURE__ */ new TypeError("Network error"));
|
||||
return;
|
||||
}
|
||||
await this.respondWith(response);
|
||||
},
|
||||
errorWith: (reason) => {
|
||||
this.logger.info("request errored!", { error: reason });
|
||||
if (reason instanceof Error) this.errorWith(reason);
|
||||
}
|
||||
});
|
||||
this.logger.info("awaiting mocked response...");
|
||||
this.logger.info("emitting the \"request\" event for %s listener(s)...", emitter.listenerCount("request"));
|
||||
await handleRequest({
|
||||
request,
|
||||
requestId,
|
||||
controller,
|
||||
emitter
|
||||
});
|
||||
};
|
||||
xhrRequestController.onResponse = async function({ response, isMockedResponse, request, requestId }) {
|
||||
this.logger.info("emitting the \"response\" event for %s listener(s)...", emitter.listenerCount("response"));
|
||||
emitter.emit("response", {
|
||||
response,
|
||||
isMockedResponse,
|
||||
request,
|
||||
requestId
|
||||
});
|
||||
};
|
||||
return xhrRequestController.request;
|
||||
} });
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/XMLHttpRequest/index.ts
|
||||
var XMLHttpRequestInterceptor = class XMLHttpRequestInterceptor extends Interceptor {
|
||||
static {
|
||||
this.interceptorSymbol = Symbol("xhr");
|
||||
}
|
||||
constructor() {
|
||||
super(XMLHttpRequestInterceptor.interceptorSymbol);
|
||||
}
|
||||
checkEnvironment() {
|
||||
return hasConfigurableGlobal("XMLHttpRequest");
|
||||
}
|
||||
setup() {
|
||||
const logger = this.logger.extend("setup");
|
||||
logger.info("patching \"XMLHttpRequest\" module...");
|
||||
const PureXMLHttpRequest = globalThis.XMLHttpRequest;
|
||||
invariant(!PureXMLHttpRequest[IS_PATCHED_MODULE], "Failed to patch the \"XMLHttpRequest\" module: already patched.");
|
||||
globalThis.XMLHttpRequest = createXMLHttpRequestProxy({
|
||||
emitter: this.emitter,
|
||||
logger: this.logger
|
||||
});
|
||||
logger.info("native \"XMLHttpRequest\" module patched!", globalThis.XMLHttpRequest.name);
|
||||
Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: true
|
||||
});
|
||||
this.subscriptions.push(() => {
|
||||
Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, { value: void 0 });
|
||||
globalThis.XMLHttpRequest = PureXMLHttpRequest;
|
||||
logger.info("native \"XMLHttpRequest\" module restored!", globalThis.XMLHttpRequest.name);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { XMLHttpRequestInterceptor as t };
|
||||
//# sourceMappingURL=XMLHttpRequest-C8dIZpds.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/XMLHttpRequest-C8dIZpds.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/XMLHttpRequest-C8dIZpds.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
38
node_modules/@mswjs/interceptors/lib/node/bufferUtils-DiCTqG-7.cjs
generated
vendored
Normal file
38
node_modules/@mswjs/interceptors/lib/node/bufferUtils-DiCTqG-7.cjs
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
//#region src/utils/bufferUtils.ts
|
||||
const encoder = new TextEncoder();
|
||||
function encodeBuffer(text) {
|
||||
return encoder.encode(text);
|
||||
}
|
||||
function decodeBuffer(buffer, encoding) {
|
||||
return new TextDecoder(encoding).decode(buffer);
|
||||
}
|
||||
/**
|
||||
* Create an `ArrayBuffer` from the given `Uint8Array`.
|
||||
* Takes the byte offset into account to produce the right buffer
|
||||
* in the case when the buffer is bigger than the data view.
|
||||
*/
|
||||
function toArrayBuffer(array) {
|
||||
return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'decodeBuffer', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return decodeBuffer;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'encodeBuffer', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return encodeBuffer;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'toArrayBuffer', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return toArrayBuffer;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=bufferUtils-DiCTqG-7.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/bufferUtils-DiCTqG-7.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/bufferUtils-DiCTqG-7.cjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"bufferUtils-DiCTqG-7.cjs","names":[],"sources":["../../src/utils/bufferUtils.ts"],"sourcesContent":["const encoder = new TextEncoder()\n\nexport function encodeBuffer(text: string): Uint8Array {\n return encoder.encode(text)\n}\n\nexport function decodeBuffer(buffer: ArrayBuffer, encoding?: string): string {\n const decoder = new TextDecoder(encoding)\n return decoder.decode(buffer)\n}\n\n/**\n * Create an `ArrayBuffer` from the given `Uint8Array`.\n * Takes the byte offset into account to produce the right buffer\n * in the case when the buffer is bigger than the data view.\n */\nexport function toArrayBuffer(array: Uint8Array): ArrayBuffer {\n return array.buffer.slice(\n array.byteOffset,\n array.byteOffset + array.byteLength\n )\n}\n"],"mappings":";;AAAA,MAAM,UAAU,IAAI,aAAa;AAEjC,SAAgB,aAAa,MAA0B;AACrD,QAAO,QAAQ,OAAO,KAAK;;AAG7B,SAAgB,aAAa,QAAqB,UAA2B;AAE3E,QADgB,IAAI,YAAY,SAAS,CAC1B,OAAO,OAAO;;;;;;;AAQ/B,SAAgB,cAAc,OAAgC;AAC5D,QAAO,MAAM,OAAO,MAClB,MAAM,YACN,MAAM,aAAa,MAAM,WAC1B"}
|
||||
20
node_modules/@mswjs/interceptors/lib/node/bufferUtils-_8XfKIfX.mjs
generated
vendored
Normal file
20
node_modules/@mswjs/interceptors/lib/node/bufferUtils-_8XfKIfX.mjs
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
//#region src/utils/bufferUtils.ts
|
||||
const encoder = new TextEncoder();
|
||||
function encodeBuffer(text) {
|
||||
return encoder.encode(text);
|
||||
}
|
||||
function decodeBuffer(buffer, encoding) {
|
||||
return new TextDecoder(encoding).decode(buffer);
|
||||
}
|
||||
/**
|
||||
* Create an `ArrayBuffer` from the given `Uint8Array`.
|
||||
* Takes the byte offset into account to produce the right buffer
|
||||
* in the case when the buffer is bigger than the data view.
|
||||
*/
|
||||
function toArrayBuffer(array) {
|
||||
return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { encodeBuffer as n, toArrayBuffer as r, decodeBuffer as t };
|
||||
//# sourceMappingURL=bufferUtils-_8XfKIfX.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/bufferUtils-_8XfKIfX.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/bufferUtils-_8XfKIfX.mjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"bufferUtils-_8XfKIfX.mjs","names":[],"sources":["../../src/utils/bufferUtils.ts"],"sourcesContent":["const encoder = new TextEncoder()\n\nexport function encodeBuffer(text: string): Uint8Array {\n return encoder.encode(text)\n}\n\nexport function decodeBuffer(buffer: ArrayBuffer, encoding?: string): string {\n const decoder = new TextDecoder(encoding)\n return decoder.decode(buffer)\n}\n\n/**\n * Create an `ArrayBuffer` from the given `Uint8Array`.\n * Takes the byte offset into account to produce the right buffer\n * in the case when the buffer is bigger than the data view.\n */\nexport function toArrayBuffer(array: Uint8Array): ArrayBuffer {\n return array.buffer.slice(\n array.byteOffset,\n array.byteOffset + array.byteLength\n )\n}\n"],"mappings":";AAAA,MAAM,UAAU,IAAI,aAAa;AAEjC,SAAgB,aAAa,MAA0B;AACrD,QAAO,QAAQ,OAAO,KAAK;;AAG7B,SAAgB,aAAa,QAAqB,UAA2B;AAE3E,QADgB,IAAI,YAAY,SAAS,CAC1B,OAAO,OAAO;;;;;;;AAQ/B,SAAgB,cAAc,OAAgC;AAC5D,QAAO,MAAM,OAAO,MAClB,MAAM,YACN,MAAM,aAAa,MAAM,WAC1B"}
|
||||
34
node_modules/@mswjs/interceptors/lib/node/chunk-CbDLau6x.cjs
generated
vendored
Normal file
34
node_modules/@mswjs/interceptors/lib/node/chunk-CbDLau6x.cjs
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
//#region rolldown:runtime
|
||||
var __create = Object.create;
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __getProtoOf = Object.getPrototypeOf;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
||||
key = keys[i];
|
||||
if (!__hasOwnProp.call(to, key) && key !== except) {
|
||||
__defProp(to, key, {
|
||||
get: ((k) => from[k]).bind(null, key),
|
||||
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
||||
value: mod,
|
||||
enumerable: true
|
||||
}) : target, mod));
|
||||
|
||||
//#endregion
|
||||
|
||||
Object.defineProperty(exports, '__toESM', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return __toESM;
|
||||
}
|
||||
});
|
||||
272
node_modules/@mswjs/interceptors/lib/node/fetch-BmXpK10r.cjs
generated
vendored
Normal file
272
node_modules/@mswjs/interceptors/lib/node/fetch-BmXpK10r.cjs
generated
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
||||
const require_glossary = require('./glossary-BLKRyLBd.cjs');
|
||||
const require_fetchUtils = require('./fetchUtils-BaY5iWXw.cjs');
|
||||
const require_getRawRequest = require('./getRawRequest-BavnMWh_.cjs');
|
||||
const require_handleRequest = require('./handleRequest-Bb7Y-XLw.cjs');
|
||||
const require_hasConfigurableGlobal = require('./hasConfigurableGlobal-C97fWuaA.cjs');
|
||||
let _open_draft_deferred_promise = require("@open-draft/deferred-promise");
|
||||
let outvariant = require("outvariant");
|
||||
let _open_draft_until = require("@open-draft/until");
|
||||
let node_zlib = require("node:zlib");
|
||||
node_zlib = require_chunk.__toESM(node_zlib);
|
||||
|
||||
//#region src/interceptors/fetch/utils/createNetworkError.ts
|
||||
function createNetworkError(cause) {
|
||||
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/fetch/utils/followRedirect.ts
|
||||
const REQUEST_BODY_HEADERS = [
|
||||
"content-encoding",
|
||||
"content-language",
|
||||
"content-location",
|
||||
"content-type",
|
||||
"content-length"
|
||||
];
|
||||
const kRedirectCount = Symbol("kRedirectCount");
|
||||
/**
|
||||
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1210
|
||||
*/
|
||||
async function followFetchRedirect(request, response) {
|
||||
if (response.status !== 303 && request.body != null) return Promise.reject(createNetworkError());
|
||||
const requestUrl = new URL(request.url);
|
||||
let locationUrl;
|
||||
try {
|
||||
locationUrl = new URL(response.headers.get("location"), request.url);
|
||||
} catch (error) {
|
||||
return Promise.reject(createNetworkError(error));
|
||||
}
|
||||
if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) return Promise.reject(createNetworkError("URL scheme must be a HTTP(S) scheme"));
|
||||
if (Reflect.get(request, kRedirectCount) > 20) return Promise.reject(createNetworkError("redirect count exceeded"));
|
||||
Object.defineProperty(request, kRedirectCount, { value: (Reflect.get(request, kRedirectCount) || 0) + 1 });
|
||||
if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) return Promise.reject(createNetworkError("cross origin not allowed for request mode \"cors\""));
|
||||
const requestInit = {};
|
||||
if ([301, 302].includes(response.status) && request.method === "POST" || response.status === 303 && !["HEAD", "GET"].includes(request.method)) {
|
||||
requestInit.method = "GET";
|
||||
requestInit.body = null;
|
||||
REQUEST_BODY_HEADERS.forEach((headerName) => {
|
||||
request.headers.delete(headerName);
|
||||
});
|
||||
}
|
||||
if (!sameOrigin(requestUrl, locationUrl)) {
|
||||
request.headers.delete("authorization");
|
||||
request.headers.delete("proxy-authorization");
|
||||
request.headers.delete("cookie");
|
||||
request.headers.delete("host");
|
||||
}
|
||||
/**
|
||||
* @note Undici "safely" extracts the request body.
|
||||
* I suspect we cannot dispatch this request again
|
||||
* since its body has been read and the stream is locked.
|
||||
*/
|
||||
requestInit.headers = request.headers;
|
||||
const finalResponse = await fetch(new Request(locationUrl, requestInit));
|
||||
Object.defineProperty(finalResponse, "redirected", {
|
||||
value: true,
|
||||
configurable: true
|
||||
});
|
||||
return finalResponse;
|
||||
}
|
||||
/**
|
||||
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/util.js#L761
|
||||
*/
|
||||
function sameOrigin(left, right) {
|
||||
if (left.origin === right.origin && left.origin === "null") return true;
|
||||
if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/fetch/utils/brotli-decompress.ts
|
||||
var BrotliDecompressionStream = class extends TransformStream {
|
||||
constructor() {
|
||||
const decompress = node_zlib.default.createBrotliDecompress({
|
||||
flush: node_zlib.default.constants.BROTLI_OPERATION_FLUSH,
|
||||
finishFlush: node_zlib.default.constants.BROTLI_OPERATION_FLUSH
|
||||
});
|
||||
super({ async transform(chunk, controller) {
|
||||
const buffer = Buffer.from(chunk);
|
||||
const decompressed = await new Promise((resolve, reject) => {
|
||||
decompress.write(buffer, (error) => {
|
||||
if (error) reject(error);
|
||||
});
|
||||
decompress.flush();
|
||||
decompress.once("data", (data) => resolve(data));
|
||||
decompress.once("error", (error) => reject(error));
|
||||
decompress.once("end", () => controller.terminate());
|
||||
}).catch((error) => {
|
||||
controller.error(error);
|
||||
});
|
||||
controller.enqueue(decompressed);
|
||||
} });
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/fetch/utils/decompression.ts
|
||||
var PipelineStream = class extends TransformStream {
|
||||
constructor(transformStreams, ...strategies) {
|
||||
super({}, ...strategies);
|
||||
const readable = [super.readable, ...transformStreams].reduce((readable$1, transform) => readable$1.pipeThrough(transform));
|
||||
Object.defineProperty(this, "readable", { get() {
|
||||
return readable;
|
||||
} });
|
||||
}
|
||||
};
|
||||
function parseContentEncoding(contentEncoding) {
|
||||
return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
|
||||
}
|
||||
function createDecompressionStream(contentEncoding) {
|
||||
if (contentEncoding === "") return null;
|
||||
const codings = parseContentEncoding(contentEncoding);
|
||||
if (codings.length === 0) return null;
|
||||
return new PipelineStream(codings.reduceRight((transformers, coding) => {
|
||||
if (coding === "gzip" || coding === "x-gzip") return transformers.concat(new DecompressionStream("gzip"));
|
||||
else if (coding === "deflate") return transformers.concat(new DecompressionStream("deflate"));
|
||||
else if (coding === "br") return transformers.concat(new BrotliDecompressionStream());
|
||||
else transformers.length = 0;
|
||||
return transformers;
|
||||
}, []));
|
||||
}
|
||||
function decompressResponse(response) {
|
||||
if (response.body === null) return null;
|
||||
const decompressionStream = createDecompressionStream(response.headers.get("content-encoding") || "");
|
||||
if (!decompressionStream) return null;
|
||||
response.body.pipeTo(decompressionStream.writable);
|
||||
return decompressionStream.readable;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/fetch/index.ts
|
||||
var FetchInterceptor = class FetchInterceptor extends require_fetchUtils.Interceptor {
|
||||
static {
|
||||
this.symbol = Symbol("fetch");
|
||||
}
|
||||
constructor() {
|
||||
super(FetchInterceptor.symbol);
|
||||
}
|
||||
checkEnvironment() {
|
||||
return require_hasConfigurableGlobal.hasConfigurableGlobal("fetch");
|
||||
}
|
||||
async setup() {
|
||||
const pureFetch = globalThis.fetch;
|
||||
(0, outvariant.invariant)(!pureFetch[require_glossary.IS_PATCHED_MODULE], "Failed to patch the \"fetch\" module: already patched.");
|
||||
globalThis.fetch = async (input, init) => {
|
||||
const requestId = require_fetchUtils.createRequestId();
|
||||
/**
|
||||
* @note Resolve potentially relative request URL
|
||||
* against the present `location`. This is mainly
|
||||
* for native `fetch` in JSDOM.
|
||||
* @see https://github.com/mswjs/msw/issues/1625
|
||||
*/
|
||||
const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !require_fetchUtils.canParseUrl(input) ? new URL(input, location.href) : input;
|
||||
const request = new Request(resolvedInput, init);
|
||||
/**
|
||||
* @note Set the raw request only if a Request instance was provided to fetch.
|
||||
*/
|
||||
if (input instanceof Request) require_getRawRequest.setRawRequest(request, input);
|
||||
const responsePromise = new _open_draft_deferred_promise.DeferredPromise();
|
||||
const controller = new require_fetchUtils.RequestController(request, {
|
||||
passthrough: async () => {
|
||||
this.logger.info("request has not been handled, passthrough...");
|
||||
/**
|
||||
* @note Clone the request instance right before performing it.
|
||||
* This preserves any modifications made to the intercepted request
|
||||
* in the "request" listener. This also allows the user to read the
|
||||
* request body in the "response" listener (otherwise "unusable").
|
||||
*/
|
||||
const requestCloneForResponseEvent = request.clone();
|
||||
const { error: responseError, data: originalResponse } = await (0, _open_draft_until.until)(() => pureFetch(request));
|
||||
if (responseError) return responsePromise.reject(responseError);
|
||||
this.logger.info("original fetch performed", originalResponse);
|
||||
if (this.emitter.listenerCount("response") > 0) {
|
||||
this.logger.info("emitting the \"response\" event...");
|
||||
const responseClone = originalResponse.clone();
|
||||
await require_handleRequest.emitAsync(this.emitter, "response", {
|
||||
response: responseClone,
|
||||
isMockedResponse: false,
|
||||
request: requestCloneForResponseEvent,
|
||||
requestId
|
||||
});
|
||||
}
|
||||
responsePromise.resolve(originalResponse);
|
||||
},
|
||||
respondWith: async (rawResponse) => {
|
||||
if (require_handleRequest.isResponseError(rawResponse)) {
|
||||
this.logger.info("request has errored!", { response: rawResponse });
|
||||
responsePromise.reject(createNetworkError(rawResponse));
|
||||
return;
|
||||
}
|
||||
this.logger.info("received mocked response!", { rawResponse });
|
||||
const decompressedStream = decompressResponse(rawResponse);
|
||||
const response = decompressedStream === null ? rawResponse : new require_fetchUtils.FetchResponse(decompressedStream, rawResponse);
|
||||
require_fetchUtils.FetchResponse.setUrl(request.url, response);
|
||||
/**
|
||||
* Undici's handling of following redirect responses.
|
||||
* Treat the "manual" redirect mode as a regular mocked response.
|
||||
* This way, the client can manually follow the redirect it receives.
|
||||
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1173
|
||||
*/
|
||||
if (require_fetchUtils.FetchResponse.isRedirectResponse(response.status)) {
|
||||
if (request.redirect === "error") {
|
||||
responsePromise.reject(createNetworkError("unexpected redirect"));
|
||||
return;
|
||||
}
|
||||
if (request.redirect === "follow") {
|
||||
followFetchRedirect(request, response).then((response$1) => {
|
||||
responsePromise.resolve(response$1);
|
||||
}, (reason) => {
|
||||
responsePromise.reject(reason);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.emitter.listenerCount("response") > 0) {
|
||||
this.logger.info("emitting the \"response\" event...");
|
||||
await require_handleRequest.emitAsync(this.emitter, "response", {
|
||||
response: response.clone(),
|
||||
isMockedResponse: true,
|
||||
request,
|
||||
requestId
|
||||
});
|
||||
}
|
||||
responsePromise.resolve(response);
|
||||
},
|
||||
errorWith: (reason) => {
|
||||
this.logger.info("request has been aborted!", { reason });
|
||||
responsePromise.reject(reason);
|
||||
}
|
||||
});
|
||||
this.logger.info("[%s] %s", request.method, request.url);
|
||||
this.logger.info("awaiting for the mocked response...");
|
||||
this.logger.info("emitting the \"request\" event for %s listener(s)...", this.emitter.listenerCount("request"));
|
||||
await require_handleRequest.handleRequest({
|
||||
request,
|
||||
requestId,
|
||||
emitter: this.emitter,
|
||||
controller
|
||||
});
|
||||
return responsePromise;
|
||||
};
|
||||
Object.defineProperty(globalThis.fetch, require_glossary.IS_PATCHED_MODULE, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: true
|
||||
});
|
||||
this.subscriptions.push(() => {
|
||||
Object.defineProperty(globalThis.fetch, require_glossary.IS_PATCHED_MODULE, { value: void 0 });
|
||||
globalThis.fetch = pureFetch;
|
||||
this.logger.info("restored native \"globalThis.fetch\"!", globalThis.fetch.name);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'FetchInterceptor', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return FetchInterceptor;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=fetch-BmXpK10r.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/fetch-BmXpK10r.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/fetch-BmXpK10r.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
265
node_modules/@mswjs/interceptors/lib/node/fetch-G1DVwDKG.mjs
generated
vendored
Normal file
265
node_modules/@mswjs/interceptors/lib/node/fetch-G1DVwDKG.mjs
generated
vendored
Normal file
@@ -0,0 +1,265 @@
|
||||
import { t as IS_PATCHED_MODULE } from "./glossary-glQBRnVD.mjs";
|
||||
import { i as RequestController, n as canParseUrl, r as createRequestId, s as Interceptor, t as FetchResponse } from "./fetchUtils-CoU35g3M.mjs";
|
||||
import { n as setRawRequest } from "./getRawRequest-DnwmXyOW.mjs";
|
||||
import { i as emitAsync, n as isResponseError, t as handleRequest } from "./handleRequest-Y97UwBbF.mjs";
|
||||
import { t as hasConfigurableGlobal } from "./hasConfigurableGlobal-DBJA0vjm.mjs";
|
||||
import { DeferredPromise } from "@open-draft/deferred-promise";
|
||||
import { invariant } from "outvariant";
|
||||
import { until } from "@open-draft/until";
|
||||
import zlib from "node:zlib";
|
||||
|
||||
//#region src/interceptors/fetch/utils/createNetworkError.ts
|
||||
function createNetworkError(cause) {
|
||||
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/fetch/utils/followRedirect.ts
|
||||
const REQUEST_BODY_HEADERS = [
|
||||
"content-encoding",
|
||||
"content-language",
|
||||
"content-location",
|
||||
"content-type",
|
||||
"content-length"
|
||||
];
|
||||
const kRedirectCount = Symbol("kRedirectCount");
|
||||
/**
|
||||
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1210
|
||||
*/
|
||||
async function followFetchRedirect(request, response) {
|
||||
if (response.status !== 303 && request.body != null) return Promise.reject(createNetworkError());
|
||||
const requestUrl = new URL(request.url);
|
||||
let locationUrl;
|
||||
try {
|
||||
locationUrl = new URL(response.headers.get("location"), request.url);
|
||||
} catch (error) {
|
||||
return Promise.reject(createNetworkError(error));
|
||||
}
|
||||
if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) return Promise.reject(createNetworkError("URL scheme must be a HTTP(S) scheme"));
|
||||
if (Reflect.get(request, kRedirectCount) > 20) return Promise.reject(createNetworkError("redirect count exceeded"));
|
||||
Object.defineProperty(request, kRedirectCount, { value: (Reflect.get(request, kRedirectCount) || 0) + 1 });
|
||||
if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) return Promise.reject(createNetworkError("cross origin not allowed for request mode \"cors\""));
|
||||
const requestInit = {};
|
||||
if ([301, 302].includes(response.status) && request.method === "POST" || response.status === 303 && !["HEAD", "GET"].includes(request.method)) {
|
||||
requestInit.method = "GET";
|
||||
requestInit.body = null;
|
||||
REQUEST_BODY_HEADERS.forEach((headerName) => {
|
||||
request.headers.delete(headerName);
|
||||
});
|
||||
}
|
||||
if (!sameOrigin(requestUrl, locationUrl)) {
|
||||
request.headers.delete("authorization");
|
||||
request.headers.delete("proxy-authorization");
|
||||
request.headers.delete("cookie");
|
||||
request.headers.delete("host");
|
||||
}
|
||||
/**
|
||||
* @note Undici "safely" extracts the request body.
|
||||
* I suspect we cannot dispatch this request again
|
||||
* since its body has been read and the stream is locked.
|
||||
*/
|
||||
requestInit.headers = request.headers;
|
||||
const finalResponse = await fetch(new Request(locationUrl, requestInit));
|
||||
Object.defineProperty(finalResponse, "redirected", {
|
||||
value: true,
|
||||
configurable: true
|
||||
});
|
||||
return finalResponse;
|
||||
}
|
||||
/**
|
||||
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/util.js#L761
|
||||
*/
|
||||
function sameOrigin(left, right) {
|
||||
if (left.origin === right.origin && left.origin === "null") return true;
|
||||
if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/fetch/utils/brotli-decompress.ts
|
||||
var BrotliDecompressionStream = class extends TransformStream {
|
||||
constructor() {
|
||||
const decompress = zlib.createBrotliDecompress({
|
||||
flush: zlib.constants.BROTLI_OPERATION_FLUSH,
|
||||
finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH
|
||||
});
|
||||
super({ async transform(chunk, controller) {
|
||||
const buffer = Buffer.from(chunk);
|
||||
const decompressed = await new Promise((resolve, reject) => {
|
||||
decompress.write(buffer, (error) => {
|
||||
if (error) reject(error);
|
||||
});
|
||||
decompress.flush();
|
||||
decompress.once("data", (data) => resolve(data));
|
||||
decompress.once("error", (error) => reject(error));
|
||||
decompress.once("end", () => controller.terminate());
|
||||
}).catch((error) => {
|
||||
controller.error(error);
|
||||
});
|
||||
controller.enqueue(decompressed);
|
||||
} });
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/fetch/utils/decompression.ts
|
||||
var PipelineStream = class extends TransformStream {
|
||||
constructor(transformStreams, ...strategies) {
|
||||
super({}, ...strategies);
|
||||
const readable = [super.readable, ...transformStreams].reduce((readable$1, transform) => readable$1.pipeThrough(transform));
|
||||
Object.defineProperty(this, "readable", { get() {
|
||||
return readable;
|
||||
} });
|
||||
}
|
||||
};
|
||||
function parseContentEncoding(contentEncoding) {
|
||||
return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
|
||||
}
|
||||
function createDecompressionStream(contentEncoding) {
|
||||
if (contentEncoding === "") return null;
|
||||
const codings = parseContentEncoding(contentEncoding);
|
||||
if (codings.length === 0) return null;
|
||||
return new PipelineStream(codings.reduceRight((transformers, coding) => {
|
||||
if (coding === "gzip" || coding === "x-gzip") return transformers.concat(new DecompressionStream("gzip"));
|
||||
else if (coding === "deflate") return transformers.concat(new DecompressionStream("deflate"));
|
||||
else if (coding === "br") return transformers.concat(new BrotliDecompressionStream());
|
||||
else transformers.length = 0;
|
||||
return transformers;
|
||||
}, []));
|
||||
}
|
||||
function decompressResponse(response) {
|
||||
if (response.body === null) return null;
|
||||
const decompressionStream = createDecompressionStream(response.headers.get("content-encoding") || "");
|
||||
if (!decompressionStream) return null;
|
||||
response.body.pipeTo(decompressionStream.writable);
|
||||
return decompressionStream.readable;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/interceptors/fetch/index.ts
|
||||
var FetchInterceptor = class FetchInterceptor extends Interceptor {
|
||||
static {
|
||||
this.symbol = Symbol("fetch");
|
||||
}
|
||||
constructor() {
|
||||
super(FetchInterceptor.symbol);
|
||||
}
|
||||
checkEnvironment() {
|
||||
return hasConfigurableGlobal("fetch");
|
||||
}
|
||||
async setup() {
|
||||
const pureFetch = globalThis.fetch;
|
||||
invariant(!pureFetch[IS_PATCHED_MODULE], "Failed to patch the \"fetch\" module: already patched.");
|
||||
globalThis.fetch = async (input, init) => {
|
||||
const requestId = createRequestId();
|
||||
/**
|
||||
* @note Resolve potentially relative request URL
|
||||
* against the present `location`. This is mainly
|
||||
* for native `fetch` in JSDOM.
|
||||
* @see https://github.com/mswjs/msw/issues/1625
|
||||
*/
|
||||
const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.href) : input;
|
||||
const request = new Request(resolvedInput, init);
|
||||
/**
|
||||
* @note Set the raw request only if a Request instance was provided to fetch.
|
||||
*/
|
||||
if (input instanceof Request) setRawRequest(request, input);
|
||||
const responsePromise = new DeferredPromise();
|
||||
const controller = new RequestController(request, {
|
||||
passthrough: async () => {
|
||||
this.logger.info("request has not been handled, passthrough...");
|
||||
/**
|
||||
* @note Clone the request instance right before performing it.
|
||||
* This preserves any modifications made to the intercepted request
|
||||
* in the "request" listener. This also allows the user to read the
|
||||
* request body in the "response" listener (otherwise "unusable").
|
||||
*/
|
||||
const requestCloneForResponseEvent = request.clone();
|
||||
const { error: responseError, data: originalResponse } = await until(() => pureFetch(request));
|
||||
if (responseError) return responsePromise.reject(responseError);
|
||||
this.logger.info("original fetch performed", originalResponse);
|
||||
if (this.emitter.listenerCount("response") > 0) {
|
||||
this.logger.info("emitting the \"response\" event...");
|
||||
const responseClone = originalResponse.clone();
|
||||
await emitAsync(this.emitter, "response", {
|
||||
response: responseClone,
|
||||
isMockedResponse: false,
|
||||
request: requestCloneForResponseEvent,
|
||||
requestId
|
||||
});
|
||||
}
|
||||
responsePromise.resolve(originalResponse);
|
||||
},
|
||||
respondWith: async (rawResponse) => {
|
||||
if (isResponseError(rawResponse)) {
|
||||
this.logger.info("request has errored!", { response: rawResponse });
|
||||
responsePromise.reject(createNetworkError(rawResponse));
|
||||
return;
|
||||
}
|
||||
this.logger.info("received mocked response!", { rawResponse });
|
||||
const decompressedStream = decompressResponse(rawResponse);
|
||||
const response = decompressedStream === null ? rawResponse : new FetchResponse(decompressedStream, rawResponse);
|
||||
FetchResponse.setUrl(request.url, response);
|
||||
/**
|
||||
* Undici's handling of following redirect responses.
|
||||
* Treat the "manual" redirect mode as a regular mocked response.
|
||||
* This way, the client can manually follow the redirect it receives.
|
||||
* @see https://github.com/nodejs/undici/blob/a6dac3149c505b58d2e6d068b97f4dc993da55f0/lib/web/fetch/index.js#L1173
|
||||
*/
|
||||
if (FetchResponse.isRedirectResponse(response.status)) {
|
||||
if (request.redirect === "error") {
|
||||
responsePromise.reject(createNetworkError("unexpected redirect"));
|
||||
return;
|
||||
}
|
||||
if (request.redirect === "follow") {
|
||||
followFetchRedirect(request, response).then((response$1) => {
|
||||
responsePromise.resolve(response$1);
|
||||
}, (reason) => {
|
||||
responsePromise.reject(reason);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.emitter.listenerCount("response") > 0) {
|
||||
this.logger.info("emitting the \"response\" event...");
|
||||
await emitAsync(this.emitter, "response", {
|
||||
response: response.clone(),
|
||||
isMockedResponse: true,
|
||||
request,
|
||||
requestId
|
||||
});
|
||||
}
|
||||
responsePromise.resolve(response);
|
||||
},
|
||||
errorWith: (reason) => {
|
||||
this.logger.info("request has been aborted!", { reason });
|
||||
responsePromise.reject(reason);
|
||||
}
|
||||
});
|
||||
this.logger.info("[%s] %s", request.method, request.url);
|
||||
this.logger.info("awaiting for the mocked response...");
|
||||
this.logger.info("emitting the \"request\" event for %s listener(s)...", this.emitter.listenerCount("request"));
|
||||
await handleRequest({
|
||||
request,
|
||||
requestId,
|
||||
emitter: this.emitter,
|
||||
controller
|
||||
});
|
||||
return responsePromise;
|
||||
};
|
||||
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: true
|
||||
});
|
||||
this.subscriptions.push(() => {
|
||||
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, { value: void 0 });
|
||||
globalThis.fetch = pureFetch;
|
||||
this.logger.info("restored native \"globalThis.fetch\"!", globalThis.fetch.name);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { FetchInterceptor as t };
|
||||
//# sourceMappingURL=fetch-G1DVwDKG.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/fetch-G1DVwDKG.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/fetch-G1DVwDKG.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
419
node_modules/@mswjs/interceptors/lib/node/fetchUtils-BaY5iWXw.cjs
generated
vendored
Normal file
419
node_modules/@mswjs/interceptors/lib/node/fetchUtils-BaY5iWXw.cjs
generated
vendored
Normal file
@@ -0,0 +1,419 @@
|
||||
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
||||
let _open_draft_logger = require("@open-draft/logger");
|
||||
let strict_event_emitter = require("strict-event-emitter");
|
||||
let _open_draft_deferred_promise = require("@open-draft/deferred-promise");
|
||||
let outvariant = require("outvariant");
|
||||
|
||||
//#region src/Interceptor.ts
|
||||
/**
|
||||
* Request header name to detect when a single request
|
||||
* is being handled by nested interceptors (XHR -> ClientRequest).
|
||||
* Obscure by design to prevent collisions with user-defined headers.
|
||||
* Ideally, come up with the Interceptor-level mechanism for this.
|
||||
* @see https://github.com/mswjs/interceptors/issues/378
|
||||
*/
|
||||
const INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
||||
function getGlobalSymbol(symbol) {
|
||||
return globalThis[symbol] || void 0;
|
||||
}
|
||||
function setGlobalSymbol(symbol, value) {
|
||||
globalThis[symbol] = value;
|
||||
}
|
||||
function deleteGlobalSymbol(symbol) {
|
||||
delete globalThis[symbol];
|
||||
}
|
||||
let InterceptorReadyState = /* @__PURE__ */ function(InterceptorReadyState$1) {
|
||||
InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
|
||||
InterceptorReadyState$1["APPLYING"] = "APPLYING";
|
||||
InterceptorReadyState$1["APPLIED"] = "APPLIED";
|
||||
InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
|
||||
InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
|
||||
return InterceptorReadyState$1;
|
||||
}({});
|
||||
var Interceptor = class {
|
||||
constructor(symbol) {
|
||||
this.symbol = symbol;
|
||||
this.readyState = InterceptorReadyState.INACTIVE;
|
||||
this.emitter = new strict_event_emitter.Emitter();
|
||||
this.subscriptions = [];
|
||||
this.logger = new _open_draft_logger.Logger(symbol.description);
|
||||
this.emitter.setMaxListeners(0);
|
||||
this.logger.info("constructing the interceptor...");
|
||||
}
|
||||
/**
|
||||
* Determine if this interceptor can be applied
|
||||
* in the current environment.
|
||||
*/
|
||||
checkEnvironment() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Apply this interceptor to the current process.
|
||||
* Returns an already running interceptor instance if it's present.
|
||||
*/
|
||||
apply() {
|
||||
const logger = this.logger.extend("apply");
|
||||
logger.info("applying the interceptor...");
|
||||
if (this.readyState === InterceptorReadyState.APPLIED) {
|
||||
logger.info("intercepted already applied!");
|
||||
return;
|
||||
}
|
||||
if (!this.checkEnvironment()) {
|
||||
logger.info("the interceptor cannot be applied in this environment!");
|
||||
return;
|
||||
}
|
||||
this.readyState = InterceptorReadyState.APPLYING;
|
||||
const runningInstance = this.getInstance();
|
||||
if (runningInstance) {
|
||||
logger.info("found a running instance, reusing...");
|
||||
this.on = (event, listener) => {
|
||||
logger.info("proxying the \"%s\" listener", event);
|
||||
runningInstance.emitter.addListener(event, listener);
|
||||
this.subscriptions.push(() => {
|
||||
runningInstance.emitter.removeListener(event, listener);
|
||||
logger.info("removed proxied \"%s\" listener!", event);
|
||||
});
|
||||
return this;
|
||||
};
|
||||
this.readyState = InterceptorReadyState.APPLIED;
|
||||
return;
|
||||
}
|
||||
logger.info("no running instance found, setting up a new instance...");
|
||||
this.setup();
|
||||
this.setInstance();
|
||||
this.readyState = InterceptorReadyState.APPLIED;
|
||||
}
|
||||
/**
|
||||
* Setup the module augments and stubs necessary for this interceptor.
|
||||
* This method is not run if there's a running interceptor instance
|
||||
* to prevent instantiating an interceptor multiple times.
|
||||
*/
|
||||
setup() {}
|
||||
/**
|
||||
* Listen to the interceptor's public events.
|
||||
*/
|
||||
on(event, listener) {
|
||||
const logger = this.logger.extend("on");
|
||||
if (this.readyState === InterceptorReadyState.DISPOSING || this.readyState === InterceptorReadyState.DISPOSED) {
|
||||
logger.info("cannot listen to events, already disposed!");
|
||||
return this;
|
||||
}
|
||||
logger.info("adding \"%s\" event listener:", event, listener);
|
||||
this.emitter.on(event, listener);
|
||||
return this;
|
||||
}
|
||||
once(event, listener) {
|
||||
this.emitter.once(event, listener);
|
||||
return this;
|
||||
}
|
||||
off(event, listener) {
|
||||
this.emitter.off(event, listener);
|
||||
return this;
|
||||
}
|
||||
removeAllListeners(event) {
|
||||
this.emitter.removeAllListeners(event);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Disposes of any side-effects this interceptor has introduced.
|
||||
*/
|
||||
dispose() {
|
||||
const logger = this.logger.extend("dispose");
|
||||
if (this.readyState === InterceptorReadyState.DISPOSED) {
|
||||
logger.info("cannot dispose, already disposed!");
|
||||
return;
|
||||
}
|
||||
logger.info("disposing the interceptor...");
|
||||
this.readyState = InterceptorReadyState.DISPOSING;
|
||||
if (!this.getInstance()) {
|
||||
logger.info("no interceptors running, skipping dispose...");
|
||||
return;
|
||||
}
|
||||
this.clearInstance();
|
||||
logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
|
||||
if (this.subscriptions.length > 0) {
|
||||
logger.info("disposing of %d subscriptions...", this.subscriptions.length);
|
||||
for (const dispose of this.subscriptions) dispose();
|
||||
this.subscriptions = [];
|
||||
logger.info("disposed of all subscriptions!", this.subscriptions.length);
|
||||
}
|
||||
this.emitter.removeAllListeners();
|
||||
logger.info("destroyed the listener!");
|
||||
this.readyState = InterceptorReadyState.DISPOSED;
|
||||
}
|
||||
getInstance() {
|
||||
const instance = getGlobalSymbol(this.symbol);
|
||||
this.logger.info("retrieved global instance:", instance?.constructor?.name);
|
||||
return instance;
|
||||
}
|
||||
setInstance() {
|
||||
setGlobalSymbol(this.symbol, this);
|
||||
this.logger.info("set global instance!", this.symbol.description);
|
||||
}
|
||||
clearInstance() {
|
||||
deleteGlobalSymbol(this.symbol);
|
||||
this.logger.info("cleared global instance!", this.symbol.description);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/InterceptorError.ts
|
||||
var InterceptorError = class InterceptorError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "InterceptorError";
|
||||
Object.setPrototypeOf(this, InterceptorError.prototype);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/RequestController.ts
|
||||
var RequestController = class RequestController {
|
||||
static {
|
||||
this.PENDING = 0;
|
||||
}
|
||||
static {
|
||||
this.PASSTHROUGH = 1;
|
||||
}
|
||||
static {
|
||||
this.RESPONSE = 2;
|
||||
}
|
||||
static {
|
||||
this.ERROR = 3;
|
||||
}
|
||||
constructor(request, source) {
|
||||
this.request = request;
|
||||
this.source = source;
|
||||
this.readyState = RequestController.PENDING;
|
||||
this.handled = new _open_draft_deferred_promise.DeferredPromise();
|
||||
}
|
||||
get #handled() {
|
||||
return this.handled;
|
||||
}
|
||||
/**
|
||||
* Perform this request as-is.
|
||||
*/
|
||||
async passthrough() {
|
||||
outvariant.invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to passthrough the \"%s %s\" request: the request has already been handled", this.request.method, this.request.url);
|
||||
this.readyState = RequestController.PASSTHROUGH;
|
||||
await this.source.passthrough();
|
||||
this.#handled.resolve();
|
||||
}
|
||||
/**
|
||||
* Respond to this request with the given `Response` instance.
|
||||
*
|
||||
* @example
|
||||
* controller.respondWith(new Response())
|
||||
* controller.respondWith(Response.json({ id }))
|
||||
* controller.respondWith(Response.error())
|
||||
*/
|
||||
respondWith(response) {
|
||||
outvariant.invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to respond to the \"%s %s\" request with \"%d %s\": the request has already been handled (%d)", this.request.method, this.request.url, response.status, response.statusText || "OK", this.readyState);
|
||||
this.readyState = RequestController.RESPONSE;
|
||||
this.#handled.resolve();
|
||||
/**
|
||||
* @note Although `source.respondWith()` is potentially asynchronous,
|
||||
* do NOT await it for backward-compatibility. Awaiting it will short-circuit
|
||||
* the request listener invocation as soon as a listener responds to a request.
|
||||
* Ideally, that's what we want, but that's not what we promise the user.
|
||||
*/
|
||||
this.source.respondWith(response);
|
||||
}
|
||||
/**
|
||||
* Error this request with the given reason.
|
||||
*
|
||||
* @example
|
||||
* controller.errorWith()
|
||||
* controller.errorWith(new Error('Oops!'))
|
||||
* controller.errorWith({ message: 'Oops!'})
|
||||
*/
|
||||
errorWith(reason) {
|
||||
outvariant.invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to error the \"%s %s\" request with \"%s\": the request has already been handled (%d)", this.request.method, this.request.url, reason?.toString(), this.readyState);
|
||||
this.readyState = RequestController.ERROR;
|
||||
this.source.errorWith(reason);
|
||||
this.#handled.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/createRequestId.ts
|
||||
/**
|
||||
* Generate a random ID string to represent a request.
|
||||
* @example
|
||||
* createRequestId()
|
||||
* // "f774b6c9c600f"
|
||||
*/
|
||||
function createRequestId() {
|
||||
return Math.random().toString(16).slice(2);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/canParseUrl.ts
|
||||
/**
|
||||
* Returns a boolean indicating whether the given URL string
|
||||
* can be parsed into a `URL` instance.
|
||||
* A substitute for `URL.canParse()` for Node.js 18.
|
||||
*/
|
||||
function canParseUrl(url) {
|
||||
try {
|
||||
new URL(url);
|
||||
return true;
|
||||
} catch (_error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/getValueBySymbol.ts
|
||||
/**
|
||||
* Returns the value behind the symbol with the given name.
|
||||
*/
|
||||
function getValueBySymbol(symbolName, source) {
|
||||
const symbol = Object.getOwnPropertySymbols(source).find((symbol$1) => {
|
||||
return symbol$1.description === symbolName;
|
||||
});
|
||||
if (symbol) return Reflect.get(source, symbol);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/fetchUtils.ts
|
||||
var FetchResponse = class FetchResponse extends Response {
|
||||
static {
|
||||
this.STATUS_CODES_WITHOUT_BODY = [
|
||||
101,
|
||||
103,
|
||||
204,
|
||||
205,
|
||||
304
|
||||
];
|
||||
}
|
||||
static {
|
||||
this.STATUS_CODES_WITH_REDIRECT = [
|
||||
301,
|
||||
302,
|
||||
303,
|
||||
307,
|
||||
308
|
||||
];
|
||||
}
|
||||
static isConfigurableStatusCode(status) {
|
||||
return status >= 200 && status <= 599;
|
||||
}
|
||||
static isRedirectResponse(status) {
|
||||
return FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
|
||||
}
|
||||
/**
|
||||
* Returns a boolean indicating whether the given response status
|
||||
* code represents a response that can have a body.
|
||||
*/
|
||||
static isResponseWithBody(status) {
|
||||
return !FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
|
||||
}
|
||||
static setUrl(url, response) {
|
||||
if (!url || url === "about:" || !canParseUrl(url)) return;
|
||||
const state = getValueBySymbol("state", response);
|
||||
if (state) state.urlList.push(new URL(url));
|
||||
else Object.defineProperty(response, "url", {
|
||||
value: url,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
||||
*/
|
||||
static parseRawHeaders(rawHeaders) {
|
||||
const headers = new Headers();
|
||||
for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
||||
return headers;
|
||||
}
|
||||
constructor(body, init = {}) {
|
||||
const status = init.status ?? 200;
|
||||
const safeStatus = FetchResponse.isConfigurableStatusCode(status) ? status : 200;
|
||||
const finalBody = FetchResponse.isResponseWithBody(status) ? body : null;
|
||||
super(finalBody, {
|
||||
status: safeStatus,
|
||||
statusText: init.statusText,
|
||||
headers: init.headers
|
||||
});
|
||||
if (status !== safeStatus) {
|
||||
/**
|
||||
* @note Undici keeps an internal "Symbol(state)" that holds
|
||||
* the actual value of response status. Update that in Node.js.
|
||||
*/
|
||||
const state = getValueBySymbol("state", this);
|
||||
if (state) state.status = status;
|
||||
else Object.defineProperty(this, "status", {
|
||||
value: status,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
FetchResponse.setUrl(init.url, this);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'FetchResponse', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return FetchResponse;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'INTERNAL_REQUEST_ID_HEADER_NAME', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return INTERNAL_REQUEST_ID_HEADER_NAME;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'Interceptor', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return Interceptor;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'InterceptorError', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return InterceptorError;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'InterceptorReadyState', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return InterceptorReadyState;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'RequestController', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return RequestController;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'canParseUrl', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return canParseUrl;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'createRequestId', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return createRequestId;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'deleteGlobalSymbol', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return deleteGlobalSymbol;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'getGlobalSymbol', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getGlobalSymbol;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=fetchUtils-BaY5iWXw.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/fetchUtils-BaY5iWXw.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/fetchUtils-BaY5iWXw.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
359
node_modules/@mswjs/interceptors/lib/node/fetchUtils-CoU35g3M.mjs
generated
vendored
Normal file
359
node_modules/@mswjs/interceptors/lib/node/fetchUtils-CoU35g3M.mjs
generated
vendored
Normal file
@@ -0,0 +1,359 @@
|
||||
import { Logger } from "@open-draft/logger";
|
||||
import { Emitter } from "strict-event-emitter";
|
||||
import { DeferredPromise } from "@open-draft/deferred-promise";
|
||||
import { invariant } from "outvariant";
|
||||
|
||||
//#region src/Interceptor.ts
|
||||
/**
|
||||
* Request header name to detect when a single request
|
||||
* is being handled by nested interceptors (XHR -> ClientRequest).
|
||||
* Obscure by design to prevent collisions with user-defined headers.
|
||||
* Ideally, come up with the Interceptor-level mechanism for this.
|
||||
* @see https://github.com/mswjs/interceptors/issues/378
|
||||
*/
|
||||
const INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
||||
function getGlobalSymbol(symbol) {
|
||||
return globalThis[symbol] || void 0;
|
||||
}
|
||||
function setGlobalSymbol(symbol, value) {
|
||||
globalThis[symbol] = value;
|
||||
}
|
||||
function deleteGlobalSymbol(symbol) {
|
||||
delete globalThis[symbol];
|
||||
}
|
||||
let InterceptorReadyState = /* @__PURE__ */ function(InterceptorReadyState$1) {
|
||||
InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
|
||||
InterceptorReadyState$1["APPLYING"] = "APPLYING";
|
||||
InterceptorReadyState$1["APPLIED"] = "APPLIED";
|
||||
InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
|
||||
InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
|
||||
return InterceptorReadyState$1;
|
||||
}({});
|
||||
var Interceptor = class {
|
||||
constructor(symbol) {
|
||||
this.symbol = symbol;
|
||||
this.readyState = InterceptorReadyState.INACTIVE;
|
||||
this.emitter = new Emitter();
|
||||
this.subscriptions = [];
|
||||
this.logger = new Logger(symbol.description);
|
||||
this.emitter.setMaxListeners(0);
|
||||
this.logger.info("constructing the interceptor...");
|
||||
}
|
||||
/**
|
||||
* Determine if this interceptor can be applied
|
||||
* in the current environment.
|
||||
*/
|
||||
checkEnvironment() {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Apply this interceptor to the current process.
|
||||
* Returns an already running interceptor instance if it's present.
|
||||
*/
|
||||
apply() {
|
||||
const logger = this.logger.extend("apply");
|
||||
logger.info("applying the interceptor...");
|
||||
if (this.readyState === InterceptorReadyState.APPLIED) {
|
||||
logger.info("intercepted already applied!");
|
||||
return;
|
||||
}
|
||||
if (!this.checkEnvironment()) {
|
||||
logger.info("the interceptor cannot be applied in this environment!");
|
||||
return;
|
||||
}
|
||||
this.readyState = InterceptorReadyState.APPLYING;
|
||||
const runningInstance = this.getInstance();
|
||||
if (runningInstance) {
|
||||
logger.info("found a running instance, reusing...");
|
||||
this.on = (event, listener) => {
|
||||
logger.info("proxying the \"%s\" listener", event);
|
||||
runningInstance.emitter.addListener(event, listener);
|
||||
this.subscriptions.push(() => {
|
||||
runningInstance.emitter.removeListener(event, listener);
|
||||
logger.info("removed proxied \"%s\" listener!", event);
|
||||
});
|
||||
return this;
|
||||
};
|
||||
this.readyState = InterceptorReadyState.APPLIED;
|
||||
return;
|
||||
}
|
||||
logger.info("no running instance found, setting up a new instance...");
|
||||
this.setup();
|
||||
this.setInstance();
|
||||
this.readyState = InterceptorReadyState.APPLIED;
|
||||
}
|
||||
/**
|
||||
* Setup the module augments and stubs necessary for this interceptor.
|
||||
* This method is not run if there's a running interceptor instance
|
||||
* to prevent instantiating an interceptor multiple times.
|
||||
*/
|
||||
setup() {}
|
||||
/**
|
||||
* Listen to the interceptor's public events.
|
||||
*/
|
||||
on(event, listener) {
|
||||
const logger = this.logger.extend("on");
|
||||
if (this.readyState === InterceptorReadyState.DISPOSING || this.readyState === InterceptorReadyState.DISPOSED) {
|
||||
logger.info("cannot listen to events, already disposed!");
|
||||
return this;
|
||||
}
|
||||
logger.info("adding \"%s\" event listener:", event, listener);
|
||||
this.emitter.on(event, listener);
|
||||
return this;
|
||||
}
|
||||
once(event, listener) {
|
||||
this.emitter.once(event, listener);
|
||||
return this;
|
||||
}
|
||||
off(event, listener) {
|
||||
this.emitter.off(event, listener);
|
||||
return this;
|
||||
}
|
||||
removeAllListeners(event) {
|
||||
this.emitter.removeAllListeners(event);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Disposes of any side-effects this interceptor has introduced.
|
||||
*/
|
||||
dispose() {
|
||||
const logger = this.logger.extend("dispose");
|
||||
if (this.readyState === InterceptorReadyState.DISPOSED) {
|
||||
logger.info("cannot dispose, already disposed!");
|
||||
return;
|
||||
}
|
||||
logger.info("disposing the interceptor...");
|
||||
this.readyState = InterceptorReadyState.DISPOSING;
|
||||
if (!this.getInstance()) {
|
||||
logger.info("no interceptors running, skipping dispose...");
|
||||
return;
|
||||
}
|
||||
this.clearInstance();
|
||||
logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
|
||||
if (this.subscriptions.length > 0) {
|
||||
logger.info("disposing of %d subscriptions...", this.subscriptions.length);
|
||||
for (const dispose of this.subscriptions) dispose();
|
||||
this.subscriptions = [];
|
||||
logger.info("disposed of all subscriptions!", this.subscriptions.length);
|
||||
}
|
||||
this.emitter.removeAllListeners();
|
||||
logger.info("destroyed the listener!");
|
||||
this.readyState = InterceptorReadyState.DISPOSED;
|
||||
}
|
||||
getInstance() {
|
||||
const instance = getGlobalSymbol(this.symbol);
|
||||
this.logger.info("retrieved global instance:", instance?.constructor?.name);
|
||||
return instance;
|
||||
}
|
||||
setInstance() {
|
||||
setGlobalSymbol(this.symbol, this);
|
||||
this.logger.info("set global instance!", this.symbol.description);
|
||||
}
|
||||
clearInstance() {
|
||||
deleteGlobalSymbol(this.symbol);
|
||||
this.logger.info("cleared global instance!", this.symbol.description);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/InterceptorError.ts
|
||||
var InterceptorError = class InterceptorError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = "InterceptorError";
|
||||
Object.setPrototypeOf(this, InterceptorError.prototype);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/RequestController.ts
|
||||
var RequestController = class RequestController {
|
||||
static {
|
||||
this.PENDING = 0;
|
||||
}
|
||||
static {
|
||||
this.PASSTHROUGH = 1;
|
||||
}
|
||||
static {
|
||||
this.RESPONSE = 2;
|
||||
}
|
||||
static {
|
||||
this.ERROR = 3;
|
||||
}
|
||||
constructor(request, source) {
|
||||
this.request = request;
|
||||
this.source = source;
|
||||
this.readyState = RequestController.PENDING;
|
||||
this.handled = new DeferredPromise();
|
||||
}
|
||||
get #handled() {
|
||||
return this.handled;
|
||||
}
|
||||
/**
|
||||
* Perform this request as-is.
|
||||
*/
|
||||
async passthrough() {
|
||||
invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to passthrough the \"%s %s\" request: the request has already been handled", this.request.method, this.request.url);
|
||||
this.readyState = RequestController.PASSTHROUGH;
|
||||
await this.source.passthrough();
|
||||
this.#handled.resolve();
|
||||
}
|
||||
/**
|
||||
* Respond to this request with the given `Response` instance.
|
||||
*
|
||||
* @example
|
||||
* controller.respondWith(new Response())
|
||||
* controller.respondWith(Response.json({ id }))
|
||||
* controller.respondWith(Response.error())
|
||||
*/
|
||||
respondWith(response) {
|
||||
invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to respond to the \"%s %s\" request with \"%d %s\": the request has already been handled (%d)", this.request.method, this.request.url, response.status, response.statusText || "OK", this.readyState);
|
||||
this.readyState = RequestController.RESPONSE;
|
||||
this.#handled.resolve();
|
||||
/**
|
||||
* @note Although `source.respondWith()` is potentially asynchronous,
|
||||
* do NOT await it for backward-compatibility. Awaiting it will short-circuit
|
||||
* the request listener invocation as soon as a listener responds to a request.
|
||||
* Ideally, that's what we want, but that's not what we promise the user.
|
||||
*/
|
||||
this.source.respondWith(response);
|
||||
}
|
||||
/**
|
||||
* Error this request with the given reason.
|
||||
*
|
||||
* @example
|
||||
* controller.errorWith()
|
||||
* controller.errorWith(new Error('Oops!'))
|
||||
* controller.errorWith({ message: 'Oops!'})
|
||||
*/
|
||||
errorWith(reason) {
|
||||
invariant.as(InterceptorError, this.readyState === RequestController.PENDING, "Failed to error the \"%s %s\" request with \"%s\": the request has already been handled (%d)", this.request.method, this.request.url, reason?.toString(), this.readyState);
|
||||
this.readyState = RequestController.ERROR;
|
||||
this.source.errorWith(reason);
|
||||
this.#handled.resolve();
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
//#region src/createRequestId.ts
|
||||
/**
|
||||
* Generate a random ID string to represent a request.
|
||||
* @example
|
||||
* createRequestId()
|
||||
* // "f774b6c9c600f"
|
||||
*/
|
||||
function createRequestId() {
|
||||
return Math.random().toString(16).slice(2);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/canParseUrl.ts
|
||||
/**
|
||||
* Returns a boolean indicating whether the given URL string
|
||||
* can be parsed into a `URL` instance.
|
||||
* A substitute for `URL.canParse()` for Node.js 18.
|
||||
*/
|
||||
function canParseUrl(url) {
|
||||
try {
|
||||
new URL(url);
|
||||
return true;
|
||||
} catch (_error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/getValueBySymbol.ts
|
||||
/**
|
||||
* Returns the value behind the symbol with the given name.
|
||||
*/
|
||||
function getValueBySymbol(symbolName, source) {
|
||||
const symbol = Object.getOwnPropertySymbols(source).find((symbol$1) => {
|
||||
return symbol$1.description === symbolName;
|
||||
});
|
||||
if (symbol) return Reflect.get(source, symbol);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/fetchUtils.ts
|
||||
var FetchResponse = class FetchResponse extends Response {
|
||||
static {
|
||||
this.STATUS_CODES_WITHOUT_BODY = [
|
||||
101,
|
||||
103,
|
||||
204,
|
||||
205,
|
||||
304
|
||||
];
|
||||
}
|
||||
static {
|
||||
this.STATUS_CODES_WITH_REDIRECT = [
|
||||
301,
|
||||
302,
|
||||
303,
|
||||
307,
|
||||
308
|
||||
];
|
||||
}
|
||||
static isConfigurableStatusCode(status) {
|
||||
return status >= 200 && status <= 599;
|
||||
}
|
||||
static isRedirectResponse(status) {
|
||||
return FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status);
|
||||
}
|
||||
/**
|
||||
* Returns a boolean indicating whether the given response status
|
||||
* code represents a response that can have a body.
|
||||
*/
|
||||
static isResponseWithBody(status) {
|
||||
return !FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status);
|
||||
}
|
||||
static setUrl(url, response) {
|
||||
if (!url || url === "about:" || !canParseUrl(url)) return;
|
||||
const state = getValueBySymbol("state", response);
|
||||
if (state) state.urlList.push(new URL(url));
|
||||
else Object.defineProperty(response, "url", {
|
||||
value: url,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
||||
*/
|
||||
static parseRawHeaders(rawHeaders) {
|
||||
const headers = new Headers();
|
||||
for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
||||
return headers;
|
||||
}
|
||||
constructor(body, init = {}) {
|
||||
const status = init.status ?? 200;
|
||||
const safeStatus = FetchResponse.isConfigurableStatusCode(status) ? status : 200;
|
||||
const finalBody = FetchResponse.isResponseWithBody(status) ? body : null;
|
||||
super(finalBody, {
|
||||
status: safeStatus,
|
||||
statusText: init.statusText,
|
||||
headers: init.headers
|
||||
});
|
||||
if (status !== safeStatus) {
|
||||
/**
|
||||
* @note Undici keeps an internal "Symbol(state)" that holds
|
||||
* the actual value of response status. Update that in Node.js.
|
||||
*/
|
||||
const state = getValueBySymbol("state", this);
|
||||
if (state) state.status = status;
|
||||
else Object.defineProperty(this, "status", {
|
||||
value: status,
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
writable: false
|
||||
});
|
||||
}
|
||||
FetchResponse.setUrl(init.url, this);
|
||||
}
|
||||
};
|
||||
|
||||
//#endregion
|
||||
export { InterceptorError as a, InterceptorReadyState as c, RequestController as i, deleteGlobalSymbol as l, canParseUrl as n, INTERNAL_REQUEST_ID_HEADER_NAME as o, createRequestId as r, Interceptor as s, FetchResponse as t, getGlobalSymbol as u };
|
||||
//# sourceMappingURL=fetchUtils-CoU35g3M.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/fetchUtils-CoU35g3M.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/fetchUtils-CoU35g3M.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
36
node_modules/@mswjs/interceptors/lib/node/getRawRequest-BavnMWh_.cjs
generated
vendored
Normal file
36
node_modules/@mswjs/interceptors/lib/node/getRawRequest-BavnMWh_.cjs
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
//#region src/getRawRequest.ts
|
||||
const kRawRequest = Symbol("kRawRequest");
|
||||
/**
|
||||
* Returns a raw request instance associated with this request.
|
||||
*
|
||||
* @example
|
||||
* interceptor.on('request', ({ request }) => {
|
||||
* const rawRequest = getRawRequest(request)
|
||||
*
|
||||
* if (rawRequest instanceof http.ClientRequest) {
|
||||
* console.log(rawRequest.rawHeaders)
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
function getRawRequest(request) {
|
||||
return Reflect.get(request, kRawRequest);
|
||||
}
|
||||
function setRawRequest(request, rawRequest) {
|
||||
Reflect.set(request, kRawRequest, rawRequest);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'getRawRequest', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getRawRequest;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'setRawRequest', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return setRawRequest;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=getRawRequest-BavnMWh_.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/getRawRequest-BavnMWh_.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/getRawRequest-BavnMWh_.cjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getRawRequest-BavnMWh_.cjs","names":[],"sources":["../../src/getRawRequest.ts"],"sourcesContent":["const kRawRequest = Symbol('kRawRequest')\n\n/**\n * Returns a raw request instance associated with this request.\n *\n * @example\n * interceptor.on('request', ({ request }) => {\n * const rawRequest = getRawRequest(request)\n *\n * if (rawRequest instanceof http.ClientRequest) {\n * console.log(rawRequest.rawHeaders)\n * }\n * })\n */\nexport function getRawRequest(request: Request): unknown | undefined {\n return Reflect.get(request, kRawRequest)\n}\n\nexport function setRawRequest(request: Request, rawRequest: unknown): void {\n Reflect.set(request, kRawRequest, rawRequest)\n}\n"],"mappings":";;AAAA,MAAM,cAAc,OAAO,cAAc;;;;;;;;;;;;;AAczC,SAAgB,cAAc,SAAuC;AACnE,QAAO,QAAQ,IAAI,SAAS,YAAY;;AAG1C,SAAgB,cAAc,SAAkB,YAA2B;AACzE,SAAQ,IAAI,SAAS,aAAa,WAAW"}
|
||||
24
node_modules/@mswjs/interceptors/lib/node/getRawRequest-DnwmXyOW.mjs
generated
vendored
Normal file
24
node_modules/@mswjs/interceptors/lib/node/getRawRequest-DnwmXyOW.mjs
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
//#region src/getRawRequest.ts
|
||||
const kRawRequest = Symbol("kRawRequest");
|
||||
/**
|
||||
* Returns a raw request instance associated with this request.
|
||||
*
|
||||
* @example
|
||||
* interceptor.on('request', ({ request }) => {
|
||||
* const rawRequest = getRawRequest(request)
|
||||
*
|
||||
* if (rawRequest instanceof http.ClientRequest) {
|
||||
* console.log(rawRequest.rawHeaders)
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
function getRawRequest(request) {
|
||||
return Reflect.get(request, kRawRequest);
|
||||
}
|
||||
function setRawRequest(request, rawRequest) {
|
||||
Reflect.set(request, kRawRequest, rawRequest);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { setRawRequest as n, getRawRequest as t };
|
||||
//# sourceMappingURL=getRawRequest-DnwmXyOW.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/getRawRequest-DnwmXyOW.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/getRawRequest-DnwmXyOW.mjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"getRawRequest-DnwmXyOW.mjs","names":[],"sources":["../../src/getRawRequest.ts"],"sourcesContent":["const kRawRequest = Symbol('kRawRequest')\n\n/**\n * Returns a raw request instance associated with this request.\n *\n * @example\n * interceptor.on('request', ({ request }) => {\n * const rawRequest = getRawRequest(request)\n *\n * if (rawRequest instanceof http.ClientRequest) {\n * console.log(rawRequest.rawHeaders)\n * }\n * })\n */\nexport function getRawRequest(request: Request): unknown | undefined {\n return Reflect.get(request, kRawRequest)\n}\n\nexport function setRawRequest(request: Request, rawRequest: unknown): void {\n Reflect.set(request, kRawRequest, rawRequest)\n}\n"],"mappings":";AAAA,MAAM,cAAc,OAAO,cAAc;;;;;;;;;;;;;AAczC,SAAgB,cAAc,SAAuC;AACnE,QAAO,QAAQ,IAAI,SAAS,YAAY;;AAG1C,SAAgB,cAAc,SAAkB,YAA2B;AACzE,SAAQ,IAAI,SAAS,aAAa,WAAW"}
|
||||
12
node_modules/@mswjs/interceptors/lib/node/glossary-BLKRyLBd.cjs
generated
vendored
Normal file
12
node_modules/@mswjs/interceptors/lib/node/glossary-BLKRyLBd.cjs
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
//#region src/glossary.ts
|
||||
const IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'IS_PATCHED_MODULE', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return IS_PATCHED_MODULE;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=glossary-BLKRyLBd.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/glossary-BLKRyLBd.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/glossary-BLKRyLBd.cjs.map
generated
vendored
Normal file
@@ -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"}
|
||||
6
node_modules/@mswjs/interceptors/lib/node/glossary-glQBRnVD.mjs
generated
vendored
Normal file
6
node_modules/@mswjs/interceptors/lib/node/glossary-glQBRnVD.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
//#region src/glossary.ts
|
||||
const IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
||||
|
||||
//#endregion
|
||||
export { IS_PATCHED_MODULE as t };
|
||||
//# sourceMappingURL=glossary-glQBRnVD.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/glossary-glQBRnVD.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/glossary-glQBRnVD.mjs.map
generated
vendored
Normal file
@@ -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"}
|
||||
220
node_modules/@mswjs/interceptors/lib/node/handleRequest-Bb7Y-XLw.cjs
generated
vendored
Normal file
220
node_modules/@mswjs/interceptors/lib/node/handleRequest-Bb7Y-XLw.cjs
generated
vendored
Normal file
@@ -0,0 +1,220 @@
|
||||
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
||||
const require_fetchUtils = require('./fetchUtils-BaY5iWXw.cjs');
|
||||
let _open_draft_deferred_promise = require("@open-draft/deferred-promise");
|
||||
let _open_draft_until = require("@open-draft/until");
|
||||
|
||||
//#region src/utils/isPropertyAccessible.ts
|
||||
/**
|
||||
* A function that validates if property access is possible on an object
|
||||
* without throwing. It returns `true` if the property access is possible
|
||||
* and `false` otherwise.
|
||||
*
|
||||
* Environments like miniflare will throw on property access on certain objects
|
||||
* like Request and Response, for unimplemented properties.
|
||||
*/
|
||||
function isPropertyAccessible(obj, key) {
|
||||
try {
|
||||
obj[key];
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/emitAsync.ts
|
||||
/**
|
||||
* Emits an event on the given emitter but executes
|
||||
* the listeners sequentially. This accounts for asynchronous
|
||||
* listeners (e.g. those having "sleep" and handling the request).
|
||||
*/
|
||||
async function emitAsync(emitter, eventName, ...data) {
|
||||
const listeners = emitter.listeners(eventName);
|
||||
if (listeners.length === 0) return;
|
||||
for (const listener of listeners) await listener.apply(emitter, data);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/isObject.ts
|
||||
/**
|
||||
* Determines if a given value is an instance of object.
|
||||
*/
|
||||
function isObject(value, loose = false) {
|
||||
return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/responseUtils.ts
|
||||
/**
|
||||
* Creates a generic 500 Unhandled Exception response.
|
||||
*/
|
||||
function createServerErrorResponse(body) {
|
||||
return new Response(JSON.stringify(body instanceof Error ? {
|
||||
name: body.name,
|
||||
message: body.message,
|
||||
stack: body.stack
|
||||
} : body), {
|
||||
status: 500,
|
||||
statusText: "Unhandled Exception",
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Check if the given response is a `Response.error()`.
|
||||
*
|
||||
* @note Some environments, like Miniflare (Cloudflare) do not
|
||||
* implement the "Response.type" property and throw on its access.
|
||||
* Safely check if we can access "type" on "Response" before continuing.
|
||||
* @see https://github.com/mswjs/msw/issues/1834
|
||||
*/
|
||||
function isResponseError(response) {
|
||||
return response != null && response instanceof Response && isPropertyAccessible(response, "type") && response.type === "error";
|
||||
}
|
||||
/**
|
||||
* Check if the given value is a `Response` or a Response-like object.
|
||||
* This is different from `value instanceof Response` because it supports
|
||||
* custom `Response` constructors, like the one when using Undici directly.
|
||||
*/
|
||||
function isResponseLike(value) {
|
||||
return isObject(value, true) && isPropertyAccessible(value, "status") && isPropertyAccessible(value, "statusText") && isPropertyAccessible(value, "bodyUsed");
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/isNodeLikeError.ts
|
||||
function isNodeLikeError(error) {
|
||||
if (error == null) return false;
|
||||
if (!(error instanceof Error)) return false;
|
||||
return "code" in error && "errno" in error;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/handleRequest.ts
|
||||
async function handleRequest(options) {
|
||||
const handleResponse = async (response) => {
|
||||
if (response instanceof Error) {
|
||||
await options.controller.errorWith(response);
|
||||
return true;
|
||||
}
|
||||
if (isResponseError(response)) {
|
||||
await options.controller.respondWith(response);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Handle normal responses or response-like objects.
|
||||
* @note This must come before the arbitrary object check
|
||||
* since Response instances are, in fact, objects.
|
||||
*/
|
||||
if (isResponseLike(response)) {
|
||||
await options.controller.respondWith(response);
|
||||
return true;
|
||||
}
|
||||
if (isObject(response)) {
|
||||
await options.controller.errorWith(response);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const handleResponseError = async (error) => {
|
||||
if (error instanceof require_fetchUtils.InterceptorError) throw result.error;
|
||||
if (isNodeLikeError(error)) {
|
||||
await options.controller.errorWith(error);
|
||||
return true;
|
||||
}
|
||||
if (error instanceof Response) return await handleResponse(error);
|
||||
return false;
|
||||
};
|
||||
const requestAbortPromise = new _open_draft_deferred_promise.DeferredPromise();
|
||||
/**
|
||||
* @note `signal` is not always defined in React Native.
|
||||
*/
|
||||
if (options.request.signal) {
|
||||
if (options.request.signal.aborted) {
|
||||
await options.controller.errorWith(options.request.signal.reason);
|
||||
return;
|
||||
}
|
||||
options.request.signal.addEventListener("abort", () => {
|
||||
requestAbortPromise.reject(options.request.signal.reason);
|
||||
}, { once: true });
|
||||
}
|
||||
const result = await (0, _open_draft_until.until)(async () => {
|
||||
const requestListenersPromise = emitAsync(options.emitter, "request", {
|
||||
requestId: options.requestId,
|
||||
request: options.request,
|
||||
controller: options.controller
|
||||
});
|
||||
await Promise.race([
|
||||
requestAbortPromise,
|
||||
requestListenersPromise,
|
||||
options.controller.handled
|
||||
]);
|
||||
});
|
||||
if (requestAbortPromise.state === "rejected") {
|
||||
await options.controller.errorWith(requestAbortPromise.rejectionReason);
|
||||
return;
|
||||
}
|
||||
if (result.error) {
|
||||
if (await handleResponseError(result.error)) return;
|
||||
if (options.emitter.listenerCount("unhandledException") > 0) {
|
||||
const unhandledExceptionController = new require_fetchUtils.RequestController(options.request, {
|
||||
passthrough() {},
|
||||
async respondWith(response) {
|
||||
await handleResponse(response);
|
||||
},
|
||||
async errorWith(reason) {
|
||||
/**
|
||||
* @note Handle the result of the unhandled controller
|
||||
* in the same way as the original request controller.
|
||||
* The exception here is that thrown errors within the
|
||||
* "unhandledException" event do NOT result in another
|
||||
* emit of the same event. They are forwarded as-is.
|
||||
*/
|
||||
await options.controller.errorWith(reason);
|
||||
}
|
||||
});
|
||||
await emitAsync(options.emitter, "unhandledException", {
|
||||
error: result.error,
|
||||
request: options.request,
|
||||
requestId: options.requestId,
|
||||
controller: unhandledExceptionController
|
||||
});
|
||||
if (unhandledExceptionController.readyState !== require_fetchUtils.RequestController.PENDING) return;
|
||||
}
|
||||
await options.controller.respondWith(createServerErrorResponse(result.error));
|
||||
return;
|
||||
}
|
||||
if (options.controller.readyState === require_fetchUtils.RequestController.PENDING) return await options.controller.passthrough();
|
||||
return options.controller.handled;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'emitAsync', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return emitAsync;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'handleRequest', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return handleRequest;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'isObject', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return isObject;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'isPropertyAccessible', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return isPropertyAccessible;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'isResponseError', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return isResponseError;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=handleRequest-Bb7Y-XLw.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/handleRequest-Bb7Y-XLw.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/handleRequest-Bb7Y-XLw.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
190
node_modules/@mswjs/interceptors/lib/node/handleRequest-Y97UwBbF.mjs
generated
vendored
Normal file
190
node_modules/@mswjs/interceptors/lib/node/handleRequest-Y97UwBbF.mjs
generated
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
import { a as InterceptorError, i as RequestController } from "./fetchUtils-CoU35g3M.mjs";
|
||||
import { DeferredPromise } from "@open-draft/deferred-promise";
|
||||
import { until } from "@open-draft/until";
|
||||
|
||||
//#region src/utils/isPropertyAccessible.ts
|
||||
/**
|
||||
* A function that validates if property access is possible on an object
|
||||
* without throwing. It returns `true` if the property access is possible
|
||||
* and `false` otherwise.
|
||||
*
|
||||
* Environments like miniflare will throw on property access on certain objects
|
||||
* like Request and Response, for unimplemented properties.
|
||||
*/
|
||||
function isPropertyAccessible(obj, key) {
|
||||
try {
|
||||
obj[key];
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/emitAsync.ts
|
||||
/**
|
||||
* Emits an event on the given emitter but executes
|
||||
* the listeners sequentially. This accounts for asynchronous
|
||||
* listeners (e.g. those having "sleep" and handling the request).
|
||||
*/
|
||||
async function emitAsync(emitter, eventName, ...data) {
|
||||
const listeners = emitter.listeners(eventName);
|
||||
if (listeners.length === 0) return;
|
||||
for (const listener of listeners) await listener.apply(emitter, data);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/isObject.ts
|
||||
/**
|
||||
* Determines if a given value is an instance of object.
|
||||
*/
|
||||
function isObject(value, loose = false) {
|
||||
return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/responseUtils.ts
|
||||
/**
|
||||
* Creates a generic 500 Unhandled Exception response.
|
||||
*/
|
||||
function createServerErrorResponse(body) {
|
||||
return new Response(JSON.stringify(body instanceof Error ? {
|
||||
name: body.name,
|
||||
message: body.message,
|
||||
stack: body.stack
|
||||
} : body), {
|
||||
status: 500,
|
||||
statusText: "Unhandled Exception",
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Check if the given response is a `Response.error()`.
|
||||
*
|
||||
* @note Some environments, like Miniflare (Cloudflare) do not
|
||||
* implement the "Response.type" property and throw on its access.
|
||||
* Safely check if we can access "type" on "Response" before continuing.
|
||||
* @see https://github.com/mswjs/msw/issues/1834
|
||||
*/
|
||||
function isResponseError(response) {
|
||||
return response != null && response instanceof Response && isPropertyAccessible(response, "type") && response.type === "error";
|
||||
}
|
||||
/**
|
||||
* Check if the given value is a `Response` or a Response-like object.
|
||||
* This is different from `value instanceof Response` because it supports
|
||||
* custom `Response` constructors, like the one when using Undici directly.
|
||||
*/
|
||||
function isResponseLike(value) {
|
||||
return isObject(value, true) && isPropertyAccessible(value, "status") && isPropertyAccessible(value, "statusText") && isPropertyAccessible(value, "bodyUsed");
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/isNodeLikeError.ts
|
||||
function isNodeLikeError(error) {
|
||||
if (error == null) return false;
|
||||
if (!(error instanceof Error)) return false;
|
||||
return "code" in error && "errno" in error;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/handleRequest.ts
|
||||
async function handleRequest(options) {
|
||||
const handleResponse = async (response) => {
|
||||
if (response instanceof Error) {
|
||||
await options.controller.errorWith(response);
|
||||
return true;
|
||||
}
|
||||
if (isResponseError(response)) {
|
||||
await options.controller.respondWith(response);
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Handle normal responses or response-like objects.
|
||||
* @note This must come before the arbitrary object check
|
||||
* since Response instances are, in fact, objects.
|
||||
*/
|
||||
if (isResponseLike(response)) {
|
||||
await options.controller.respondWith(response);
|
||||
return true;
|
||||
}
|
||||
if (isObject(response)) {
|
||||
await options.controller.errorWith(response);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const handleResponseError = async (error) => {
|
||||
if (error instanceof InterceptorError) throw result.error;
|
||||
if (isNodeLikeError(error)) {
|
||||
await options.controller.errorWith(error);
|
||||
return true;
|
||||
}
|
||||
if (error instanceof Response) return await handleResponse(error);
|
||||
return false;
|
||||
};
|
||||
const requestAbortPromise = new DeferredPromise();
|
||||
/**
|
||||
* @note `signal` is not always defined in React Native.
|
||||
*/
|
||||
if (options.request.signal) {
|
||||
if (options.request.signal.aborted) {
|
||||
await options.controller.errorWith(options.request.signal.reason);
|
||||
return;
|
||||
}
|
||||
options.request.signal.addEventListener("abort", () => {
|
||||
requestAbortPromise.reject(options.request.signal.reason);
|
||||
}, { once: true });
|
||||
}
|
||||
const result = await until(async () => {
|
||||
const requestListenersPromise = emitAsync(options.emitter, "request", {
|
||||
requestId: options.requestId,
|
||||
request: options.request,
|
||||
controller: options.controller
|
||||
});
|
||||
await Promise.race([
|
||||
requestAbortPromise,
|
||||
requestListenersPromise,
|
||||
options.controller.handled
|
||||
]);
|
||||
});
|
||||
if (requestAbortPromise.state === "rejected") {
|
||||
await options.controller.errorWith(requestAbortPromise.rejectionReason);
|
||||
return;
|
||||
}
|
||||
if (result.error) {
|
||||
if (await handleResponseError(result.error)) return;
|
||||
if (options.emitter.listenerCount("unhandledException") > 0) {
|
||||
const unhandledExceptionController = new RequestController(options.request, {
|
||||
passthrough() {},
|
||||
async respondWith(response) {
|
||||
await handleResponse(response);
|
||||
},
|
||||
async errorWith(reason) {
|
||||
/**
|
||||
* @note Handle the result of the unhandled controller
|
||||
* in the same way as the original request controller.
|
||||
* The exception here is that thrown errors within the
|
||||
* "unhandledException" event do NOT result in another
|
||||
* emit of the same event. They are forwarded as-is.
|
||||
*/
|
||||
await options.controller.errorWith(reason);
|
||||
}
|
||||
});
|
||||
await emitAsync(options.emitter, "unhandledException", {
|
||||
error: result.error,
|
||||
request: options.request,
|
||||
requestId: options.requestId,
|
||||
controller: unhandledExceptionController
|
||||
});
|
||||
if (unhandledExceptionController.readyState !== RequestController.PENDING) return;
|
||||
}
|
||||
await options.controller.respondWith(createServerErrorResponse(result.error));
|
||||
return;
|
||||
}
|
||||
if (options.controller.readyState === RequestController.PENDING) return await options.controller.passthrough();
|
||||
return options.controller.handled;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { isPropertyAccessible as a, emitAsync as i, isResponseError as n, isObject as r, handleRequest as t };
|
||||
//# sourceMappingURL=handleRequest-Y97UwBbF.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/handleRequest-Y97UwBbF.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/handleRequest-Y97UwBbF.mjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
26
node_modules/@mswjs/interceptors/lib/node/hasConfigurableGlobal-C97fWuaA.cjs
generated
vendored
Normal file
26
node_modules/@mswjs/interceptors/lib/node/hasConfigurableGlobal-C97fWuaA.cjs
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
//#region src/utils/hasConfigurableGlobal.ts
|
||||
/**
|
||||
* Returns a boolean indicating whether the given global property
|
||||
* is defined and is configurable.
|
||||
*/
|
||||
function hasConfigurableGlobal(propertyName) {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
||||
if (typeof descriptor === "undefined") return false;
|
||||
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
||||
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
||||
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
||||
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.`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'hasConfigurableGlobal', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return hasConfigurableGlobal;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=hasConfigurableGlobal-C97fWuaA.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/hasConfigurableGlobal-C97fWuaA.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/hasConfigurableGlobal-C97fWuaA.cjs.map
generated
vendored
Normal file
@@ -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"}
|
||||
20
node_modules/@mswjs/interceptors/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs
generated
vendored
Normal file
20
node_modules/@mswjs/interceptors/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
//#region src/utils/hasConfigurableGlobal.ts
|
||||
/**
|
||||
* Returns a boolean indicating whether the given global property
|
||||
* is defined and is configurable.
|
||||
*/
|
||||
function hasConfigurableGlobal(propertyName) {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
||||
if (typeof descriptor === "undefined") return false;
|
||||
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
||||
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
||||
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
||||
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.`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { hasConfigurableGlobal as t };
|
||||
//# sourceMappingURL=hasConfigurableGlobal-DBJA0vjm.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/hasConfigurableGlobal-DBJA0vjm.mjs.map
generated
vendored
Normal file
@@ -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"}
|
||||
113
node_modules/@mswjs/interceptors/lib/node/index-BMbJ8FXL.d.cts
generated
vendored
Normal file
113
node_modules/@mswjs/interceptors/lib/node/index-BMbJ8FXL.d.cts
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
import { l as HttpRequestEventMap, r as Interceptor } from "./Interceptor-DJ2akVWI.cjs";
|
||||
import net from "node:net";
|
||||
|
||||
//#region src/interceptors/Socket/utils/normalizeSocketWriteArgs.d.ts
|
||||
type WriteCallback = (error?: Error | null) => void;
|
||||
//#endregion
|
||||
//#region src/interceptors/Socket/MockSocket.d.ts
|
||||
interface MockSocketOptions {
|
||||
write: (chunk: Buffer | string, encoding: BufferEncoding | undefined, callback?: WriteCallback) => void;
|
||||
read: (chunk: Buffer, encoding: BufferEncoding | undefined) => void;
|
||||
}
|
||||
declare class MockSocket extends net.Socket {
|
||||
protected readonly options: MockSocketOptions;
|
||||
connecting: boolean;
|
||||
constructor(options: MockSocketOptions);
|
||||
connect(): this;
|
||||
write(...args: Array<unknown>): boolean;
|
||||
end(...args: Array<unknown>): this;
|
||||
push(chunk: any, encoding?: BufferEncoding): boolean;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/interceptors/ClientRequest/MockHttpSocket.d.ts
|
||||
type HttpConnectionOptions = any;
|
||||
type MockHttpSocketRequestCallback = (args: {
|
||||
requestId: string;
|
||||
request: Request;
|
||||
socket: MockHttpSocket;
|
||||
}) => void;
|
||||
type MockHttpSocketResponseCallback = (args: {
|
||||
requestId: string;
|
||||
request: Request;
|
||||
response: Response;
|
||||
isMockedResponse: boolean;
|
||||
socket: MockHttpSocket;
|
||||
}) => Promise<void>;
|
||||
interface MockHttpSocketOptions {
|
||||
connectionOptions: HttpConnectionOptions;
|
||||
createConnection: () => net.Socket;
|
||||
onRequest: MockHttpSocketRequestCallback;
|
||||
onResponse: MockHttpSocketResponseCallback;
|
||||
}
|
||||
declare class MockHttpSocket extends MockSocket {
|
||||
private connectionOptions;
|
||||
private createConnection;
|
||||
private baseUrl;
|
||||
private onRequest;
|
||||
private onResponse;
|
||||
private responseListenersPromise?;
|
||||
private requestRawHeadersBuffer;
|
||||
private responseRawHeadersBuffer;
|
||||
private writeBuffer;
|
||||
private request?;
|
||||
private requestParser;
|
||||
private requestStream?;
|
||||
private shouldKeepAlive?;
|
||||
private socketState;
|
||||
private responseParser;
|
||||
private responseStream?;
|
||||
private originalSocket?;
|
||||
constructor(options: MockHttpSocketOptions);
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
destroy(error?: Error | undefined): this;
|
||||
/**
|
||||
* Establish this Socket connection as-is and pipe
|
||||
* its data/events through this Socket.
|
||||
*/
|
||||
passthrough(): void;
|
||||
/**
|
||||
* Convert the given Fetch API `Response` instance to an
|
||||
* HTTP message and push it to the socket.
|
||||
*/
|
||||
respondWith(response: Response): Promise<void>;
|
||||
/**
|
||||
* Close this socket connection with the given error.
|
||||
*/
|
||||
errorWith(error?: Error): void;
|
||||
private mockConnect;
|
||||
private flushWriteBuffer;
|
||||
/**
|
||||
* This callback might be called when the request is "slow":
|
||||
* - Request headers were fragmented across multiple TCP packages;
|
||||
* - Request headers were too large to be processed in a single run
|
||||
* (e.g. more than 30 request headers).
|
||||
* @note This is called before request start.
|
||||
*/
|
||||
private onRequestHeaders;
|
||||
private onRequestStart;
|
||||
private onRequestBody;
|
||||
private onRequestEnd;
|
||||
/**
|
||||
* This callback might be called when the response is "slow":
|
||||
* - Response headers were fragmented across multiple TCP packages;
|
||||
* - Response headers were too large to be processed in a single run
|
||||
* (e.g. more than 30 response headers).
|
||||
* @note This is called before response start.
|
||||
*/
|
||||
private onResponseHeaders;
|
||||
private onResponseStart;
|
||||
private onResponseBody;
|
||||
private onResponseEnd;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/interceptors/ClientRequest/index.d.ts
|
||||
declare class ClientRequestInterceptor extends Interceptor<HttpRequestEventMap> {
|
||||
static symbol: symbol;
|
||||
constructor();
|
||||
protected setup(): void;
|
||||
private onRequest;
|
||||
onResponse: MockHttpSocketResponseCallback;
|
||||
}
|
||||
//#endregion
|
||||
export { ClientRequestInterceptor as t };
|
||||
//# sourceMappingURL=index-BMbJ8FXL.d.cts.map
|
||||
113
node_modules/@mswjs/interceptors/lib/node/index-C0YAQ36w.d.mts
generated
vendored
Normal file
113
node_modules/@mswjs/interceptors/lib/node/index-C0YAQ36w.d.mts
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
import { l as HttpRequestEventMap, r as Interceptor } from "./Interceptor-DEazpLJd.mjs";
|
||||
import net from "node:net";
|
||||
|
||||
//#region src/interceptors/Socket/utils/normalizeSocketWriteArgs.d.ts
|
||||
type WriteCallback = (error?: Error | null) => void;
|
||||
//#endregion
|
||||
//#region src/interceptors/Socket/MockSocket.d.ts
|
||||
interface MockSocketOptions {
|
||||
write: (chunk: Buffer | string, encoding: BufferEncoding | undefined, callback?: WriteCallback) => void;
|
||||
read: (chunk: Buffer, encoding: BufferEncoding | undefined) => void;
|
||||
}
|
||||
declare class MockSocket extends net.Socket {
|
||||
protected readonly options: MockSocketOptions;
|
||||
connecting: boolean;
|
||||
constructor(options: MockSocketOptions);
|
||||
connect(): this;
|
||||
write(...args: Array<unknown>): boolean;
|
||||
end(...args: Array<unknown>): this;
|
||||
push(chunk: any, encoding?: BufferEncoding): boolean;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/interceptors/ClientRequest/MockHttpSocket.d.ts
|
||||
type HttpConnectionOptions = any;
|
||||
type MockHttpSocketRequestCallback = (args: {
|
||||
requestId: string;
|
||||
request: Request;
|
||||
socket: MockHttpSocket;
|
||||
}) => void;
|
||||
type MockHttpSocketResponseCallback = (args: {
|
||||
requestId: string;
|
||||
request: Request;
|
||||
response: Response;
|
||||
isMockedResponse: boolean;
|
||||
socket: MockHttpSocket;
|
||||
}) => Promise<void>;
|
||||
interface MockHttpSocketOptions {
|
||||
connectionOptions: HttpConnectionOptions;
|
||||
createConnection: () => net.Socket;
|
||||
onRequest: MockHttpSocketRequestCallback;
|
||||
onResponse: MockHttpSocketResponseCallback;
|
||||
}
|
||||
declare class MockHttpSocket extends MockSocket {
|
||||
private connectionOptions;
|
||||
private createConnection;
|
||||
private baseUrl;
|
||||
private onRequest;
|
||||
private onResponse;
|
||||
private responseListenersPromise?;
|
||||
private requestRawHeadersBuffer;
|
||||
private responseRawHeadersBuffer;
|
||||
private writeBuffer;
|
||||
private request?;
|
||||
private requestParser;
|
||||
private requestStream?;
|
||||
private shouldKeepAlive?;
|
||||
private socketState;
|
||||
private responseParser;
|
||||
private responseStream?;
|
||||
private originalSocket?;
|
||||
constructor(options: MockHttpSocketOptions);
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
destroy(error?: Error | undefined): this;
|
||||
/**
|
||||
* Establish this Socket connection as-is and pipe
|
||||
* its data/events through this Socket.
|
||||
*/
|
||||
passthrough(): void;
|
||||
/**
|
||||
* Convert the given Fetch API `Response` instance to an
|
||||
* HTTP message and push it to the socket.
|
||||
*/
|
||||
respondWith(response: Response): Promise<void>;
|
||||
/**
|
||||
* Close this socket connection with the given error.
|
||||
*/
|
||||
errorWith(error?: Error): void;
|
||||
private mockConnect;
|
||||
private flushWriteBuffer;
|
||||
/**
|
||||
* This callback might be called when the request is "slow":
|
||||
* - Request headers were fragmented across multiple TCP packages;
|
||||
* - Request headers were too large to be processed in a single run
|
||||
* (e.g. more than 30 request headers).
|
||||
* @note This is called before request start.
|
||||
*/
|
||||
private onRequestHeaders;
|
||||
private onRequestStart;
|
||||
private onRequestBody;
|
||||
private onRequestEnd;
|
||||
/**
|
||||
* This callback might be called when the response is "slow":
|
||||
* - Response headers were fragmented across multiple TCP packages;
|
||||
* - Response headers were too large to be processed in a single run
|
||||
* (e.g. more than 30 response headers).
|
||||
* @note This is called before response start.
|
||||
*/
|
||||
private onResponseHeaders;
|
||||
private onResponseStart;
|
||||
private onResponseBody;
|
||||
private onResponseEnd;
|
||||
}
|
||||
//#endregion
|
||||
//#region src/interceptors/ClientRequest/index.d.ts
|
||||
declare class ClientRequestInterceptor extends Interceptor<HttpRequestEventMap> {
|
||||
static symbol: symbol;
|
||||
constructor();
|
||||
protected setup(): void;
|
||||
private onRequest;
|
||||
onResponse: MockHttpSocketResponseCallback;
|
||||
}
|
||||
//#endregion
|
||||
export { ClientRequestInterceptor as t };
|
||||
//# sourceMappingURL=index-C0YAQ36w.d.mts.map
|
||||
54
node_modules/@mswjs/interceptors/lib/node/index.cjs
generated
vendored
Normal file
54
node_modules/@mswjs/interceptors/lib/node/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
const require_glossary = require('./glossary-BLKRyLBd.cjs');
|
||||
const require_fetchUtils = require('./fetchUtils-BaY5iWXw.cjs');
|
||||
const require_BatchInterceptor = require('./BatchInterceptor-3LnAnLTx.cjs');
|
||||
const require_bufferUtils = require('./bufferUtils-DiCTqG-7.cjs');
|
||||
const require_getRawRequest = require('./getRawRequest-BavnMWh_.cjs');
|
||||
|
||||
//#region src/utils/getCleanUrl.ts
|
||||
/**
|
||||
* Removes query parameters and hashes from a given URL.
|
||||
*/
|
||||
function getCleanUrl(url, isAbsolute = true) {
|
||||
return [isAbsolute && url.origin, url.pathname].filter(Boolean).join("");
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/resolveWebSocketUrl.ts
|
||||
/**
|
||||
* Resolve potentially relative WebSocket URLs the same way
|
||||
* the browser does (replace the protocol, use the origin, etc).
|
||||
*
|
||||
* @see https://websockets.spec.whatwg.org//#dom-websocket-websocket
|
||||
*/
|
||||
function resolveWebSocketUrl(url) {
|
||||
if (typeof url === "string") return resolveWebSocketUrl(new URL(url, typeof location !== "undefined" ? location.href : void 0));
|
||||
if (url.protocol === "http:") url.protocol = "ws:";
|
||||
else if (url.protocol === "https:") url.protocol = "wss:";
|
||||
if (url.protocol !== "ws:" && url.protocol !== "wss:")
|
||||
/**
|
||||
* @note These errors are modeled after the browser errors.
|
||||
* The exact error messages aren't provided in the specification.
|
||||
* Node.js uses more obscure error messages that I don't wish to replicate.
|
||||
*/
|
||||
throw new SyntaxError(`Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`);
|
||||
if (url.hash !== "") throw new SyntaxError(`Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`);
|
||||
return url.href;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.BatchInterceptor = require_BatchInterceptor.BatchInterceptor;
|
||||
exports.FetchResponse = require_fetchUtils.FetchResponse;
|
||||
exports.INTERNAL_REQUEST_ID_HEADER_NAME = require_fetchUtils.INTERNAL_REQUEST_ID_HEADER_NAME;
|
||||
exports.IS_PATCHED_MODULE = require_glossary.IS_PATCHED_MODULE;
|
||||
exports.Interceptor = require_fetchUtils.Interceptor;
|
||||
exports.InterceptorReadyState = require_fetchUtils.InterceptorReadyState;
|
||||
exports.RequestController = require_fetchUtils.RequestController;
|
||||
exports.createRequestId = require_fetchUtils.createRequestId;
|
||||
exports.decodeBuffer = require_bufferUtils.decodeBuffer;
|
||||
exports.deleteGlobalSymbol = require_fetchUtils.deleteGlobalSymbol;
|
||||
exports.encodeBuffer = require_bufferUtils.encodeBuffer;
|
||||
exports.getCleanUrl = getCleanUrl;
|
||||
exports.getGlobalSymbol = require_fetchUtils.getGlobalSymbol;
|
||||
exports.getRawRequest = require_getRawRequest.getRawRequest;
|
||||
exports.resolveWebSocketUrl = resolveWebSocketUrl;
|
||||
//# sourceMappingURL=index.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/index.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/index.cjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/utils/getCleanUrl.ts","../../src/utils/resolveWebSocketUrl.ts"],"sourcesContent":["/**\n * Removes query parameters and hashes from a given URL.\n */\nexport function getCleanUrl(url: URL, isAbsolute: boolean = true): string {\n return [isAbsolute && url.origin, url.pathname].filter(Boolean).join('')\n}\n","/**\n * Resolve potentially relative WebSocket URLs the same way\n * the browser does (replace the protocol, use the origin, etc).\n *\n * @see https://websockets.spec.whatwg.org//#dom-websocket-websocket\n */\nexport function resolveWebSocketUrl(url: string | URL): string {\n if (typeof url === 'string') {\n /**\n * @note Cast the string to a URL first so the parsing errors\n * are thrown as a part of the WebSocket constructor, not consumers.\n */\n const urlRecord = new URL(\n url,\n typeof location !== 'undefined' ? location.href : undefined\n )\n\n return resolveWebSocketUrl(urlRecord)\n }\n\n if (url.protocol === 'http:') {\n url.protocol = 'ws:'\n } else if (url.protocol === 'https:') {\n url.protocol = 'wss:'\n }\n\n if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {\n /**\n * @note These errors are modeled after the browser errors.\n * The exact error messages aren't provided in the specification.\n * Node.js uses more obscure error messages that I don't wish to replicate.\n */\n throw new SyntaxError(\n `Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`\n )\n }\n\n if (url.hash !== '') {\n throw new SyntaxError(\n `Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`\n )\n }\n\n return url.href\n}\n"],"mappings":";;;;;;;;;;AAGA,SAAgB,YAAY,KAAU,aAAsB,MAAc;AACxE,QAAO,CAAC,cAAc,IAAI,QAAQ,IAAI,SAAS,CAAC,OAAO,QAAQ,CAAC,KAAK,GAAG;;;;;;;;;;;ACE1E,SAAgB,oBAAoB,KAA2B;AAC7D,KAAI,OAAO,QAAQ,SAUjB,QAAO,oBALW,IAAI,IACpB,KACA,OAAO,aAAa,cAAc,SAAS,OAAO,OACnD,CAEoC;AAGvC,KAAI,IAAI,aAAa,QACnB,KAAI,WAAW;UACN,IAAI,aAAa,SAC1B,KAAI,WAAW;AAGjB,KAAI,IAAI,aAAa,SAAS,IAAI,aAAa;;;;;;AAM7C,OAAM,IAAI,YACR,sGAAsG,IAAI,SAAS,mBACpH;AAGH,KAAI,IAAI,SAAS,GACf,OAAM,IAAI,YACR,6EAA6E,IAAI,KAAK,6DACvF;AAGH,QAAO,IAAI"}
|
||||
75
node_modules/@mswjs/interceptors/lib/node/index.d.cts
generated
vendored
Normal file
75
node_modules/@mswjs/interceptors/lib/node/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import { a as InterceptorReadyState, c as getGlobalSymbol, d as RequestCredentials, f as RequestController, i as InterceptorEventMap, l as HttpRequestEventMap, n as INTERNAL_REQUEST_ID_HEADER_NAME, o as InterceptorSubscription, p as RequestControllerSource, r as Interceptor, s as deleteGlobalSymbol, t as ExtractEventNames, u as IS_PATCHED_MODULE } from "./Interceptor-DJ2akVWI.cjs";
|
||||
import { n as BatchInterceptorOptions, r as ExtractEventMapType, t as BatchInterceptor } from "./BatchInterceptor-D_YqR8qU.cjs";
|
||||
|
||||
//#region src/createRequestId.d.ts
|
||||
|
||||
/**
|
||||
* Generate a random ID string to represent a request.
|
||||
* @example
|
||||
* createRequestId()
|
||||
* // "f774b6c9c600f"
|
||||
*/
|
||||
declare function createRequestId(): string;
|
||||
//#endregion
|
||||
//#region src/utils/getCleanUrl.d.ts
|
||||
/**
|
||||
* Removes query parameters and hashes from a given URL.
|
||||
*/
|
||||
declare function getCleanUrl(url: URL, isAbsolute?: boolean): string;
|
||||
//#endregion
|
||||
//#region src/utils/bufferUtils.d.ts
|
||||
declare function encodeBuffer(text: string): Uint8Array;
|
||||
declare function decodeBuffer(buffer: ArrayBuffer, encoding?: string): string;
|
||||
//#endregion
|
||||
//#region src/utils/fetchUtils.d.ts
|
||||
interface FetchResponseInit extends ResponseInit {
|
||||
url?: string;
|
||||
}
|
||||
declare class FetchResponse extends Response {
|
||||
/**
|
||||
* Response status codes for responses that cannot have body.
|
||||
* @see https://fetch.spec.whatwg.org/#statuses
|
||||
*/
|
||||
static readonly STATUS_CODES_WITHOUT_BODY: number[];
|
||||
static readonly STATUS_CODES_WITH_REDIRECT: number[];
|
||||
static isConfigurableStatusCode(status: number): boolean;
|
||||
static isRedirectResponse(status: number): boolean;
|
||||
/**
|
||||
* Returns a boolean indicating whether the given response status
|
||||
* code represents a response that can have a body.
|
||||
*/
|
||||
static isResponseWithBody(status: number): boolean;
|
||||
static setUrl(url: string | undefined, response: Response): void;
|
||||
/**
|
||||
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
||||
*/
|
||||
static parseRawHeaders(rawHeaders: Array<string>): Headers;
|
||||
constructor(body?: BodyInit | null, init?: FetchResponseInit);
|
||||
}
|
||||
//#endregion
|
||||
//#region src/getRawRequest.d.ts
|
||||
/**
|
||||
* Returns a raw request instance associated with this request.
|
||||
*
|
||||
* @example
|
||||
* interceptor.on('request', ({ request }) => {
|
||||
* const rawRequest = getRawRequest(request)
|
||||
*
|
||||
* if (rawRequest instanceof http.ClientRequest) {
|
||||
* console.log(rawRequest.rawHeaders)
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
declare function getRawRequest(request: Request): unknown | undefined;
|
||||
//#endregion
|
||||
//#region src/utils/resolveWebSocketUrl.d.ts
|
||||
/**
|
||||
* Resolve potentially relative WebSocket URLs the same way
|
||||
* the browser does (replace the protocol, use the origin, etc).
|
||||
*
|
||||
* @see https://websockets.spec.whatwg.org//#dom-websocket-websocket
|
||||
*/
|
||||
declare function resolveWebSocketUrl(url: string | URL): string;
|
||||
//#endregion
|
||||
export { BatchInterceptor, BatchInterceptorOptions, ExtractEventMapType, ExtractEventNames, FetchResponse, HttpRequestEventMap, INTERNAL_REQUEST_ID_HEADER_NAME, IS_PATCHED_MODULE, Interceptor, InterceptorEventMap, InterceptorReadyState, InterceptorSubscription, RequestController, type RequestControllerSource, RequestCredentials, createRequestId, decodeBuffer, deleteGlobalSymbol, encodeBuffer, getCleanUrl, getGlobalSymbol, getRawRequest, resolveWebSocketUrl };
|
||||
//# sourceMappingURL=index.d.cts.map
|
||||
75
node_modules/@mswjs/interceptors/lib/node/index.d.mts
generated
vendored
Normal file
75
node_modules/@mswjs/interceptors/lib/node/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
import { a as InterceptorReadyState, c as getGlobalSymbol, d as RequestCredentials, f as RequestController, i as InterceptorEventMap, l as HttpRequestEventMap, n as INTERNAL_REQUEST_ID_HEADER_NAME, o as InterceptorSubscription, p as RequestControllerSource, r as Interceptor, s as deleteGlobalSymbol, t as ExtractEventNames, u as IS_PATCHED_MODULE } from "./Interceptor-DEazpLJd.mjs";
|
||||
import { n as BatchInterceptorOptions, r as ExtractEventMapType, t as BatchInterceptor } from "./BatchInterceptor-D7mXzHcQ.mjs";
|
||||
|
||||
//#region src/createRequestId.d.ts
|
||||
|
||||
/**
|
||||
* Generate a random ID string to represent a request.
|
||||
* @example
|
||||
* createRequestId()
|
||||
* // "f774b6c9c600f"
|
||||
*/
|
||||
declare function createRequestId(): string;
|
||||
//#endregion
|
||||
//#region src/utils/getCleanUrl.d.ts
|
||||
/**
|
||||
* Removes query parameters and hashes from a given URL.
|
||||
*/
|
||||
declare function getCleanUrl(url: URL, isAbsolute?: boolean): string;
|
||||
//#endregion
|
||||
//#region src/utils/bufferUtils.d.ts
|
||||
declare function encodeBuffer(text: string): Uint8Array;
|
||||
declare function decodeBuffer(buffer: ArrayBuffer, encoding?: string): string;
|
||||
//#endregion
|
||||
//#region src/utils/fetchUtils.d.ts
|
||||
interface FetchResponseInit extends ResponseInit {
|
||||
url?: string;
|
||||
}
|
||||
declare class FetchResponse extends Response {
|
||||
/**
|
||||
* Response status codes for responses that cannot have body.
|
||||
* @see https://fetch.spec.whatwg.org/#statuses
|
||||
*/
|
||||
static readonly STATUS_CODES_WITHOUT_BODY: number[];
|
||||
static readonly STATUS_CODES_WITH_REDIRECT: number[];
|
||||
static isConfigurableStatusCode(status: number): boolean;
|
||||
static isRedirectResponse(status: number): boolean;
|
||||
/**
|
||||
* Returns a boolean indicating whether the given response status
|
||||
* code represents a response that can have a body.
|
||||
*/
|
||||
static isResponseWithBody(status: number): boolean;
|
||||
static setUrl(url: string | undefined, response: Response): void;
|
||||
/**
|
||||
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
||||
*/
|
||||
static parseRawHeaders(rawHeaders: Array<string>): Headers;
|
||||
constructor(body?: BodyInit | null, init?: FetchResponseInit);
|
||||
}
|
||||
//#endregion
|
||||
//#region src/getRawRequest.d.ts
|
||||
/**
|
||||
* Returns a raw request instance associated with this request.
|
||||
*
|
||||
* @example
|
||||
* interceptor.on('request', ({ request }) => {
|
||||
* const rawRequest = getRawRequest(request)
|
||||
*
|
||||
* if (rawRequest instanceof http.ClientRequest) {
|
||||
* console.log(rawRequest.rawHeaders)
|
||||
* }
|
||||
* })
|
||||
*/
|
||||
declare function getRawRequest(request: Request): unknown | undefined;
|
||||
//#endregion
|
||||
//#region src/utils/resolveWebSocketUrl.d.ts
|
||||
/**
|
||||
* Resolve potentially relative WebSocket URLs the same way
|
||||
* the browser does (replace the protocol, use the origin, etc).
|
||||
*
|
||||
* @see https://websockets.spec.whatwg.org//#dom-websocket-websocket
|
||||
*/
|
||||
declare function resolveWebSocketUrl(url: string | URL): string;
|
||||
//#endregion
|
||||
export { BatchInterceptor, BatchInterceptorOptions, ExtractEventMapType, ExtractEventNames, FetchResponse, HttpRequestEventMap, INTERNAL_REQUEST_ID_HEADER_NAME, IS_PATCHED_MODULE, Interceptor, InterceptorEventMap, InterceptorReadyState, InterceptorSubscription, RequestController, type RequestControllerSource, RequestCredentials, createRequestId, decodeBuffer, deleteGlobalSymbol, encodeBuffer, getCleanUrl, getGlobalSymbol, getRawRequest, resolveWebSocketUrl };
|
||||
//# sourceMappingURL=index.d.mts.map
|
||||
40
node_modules/@mswjs/interceptors/lib/node/index.mjs
generated
vendored
Normal file
40
node_modules/@mswjs/interceptors/lib/node/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { t as IS_PATCHED_MODULE } from "./glossary-glQBRnVD.mjs";
|
||||
import { c as InterceptorReadyState, i as RequestController, l as deleteGlobalSymbol, o as INTERNAL_REQUEST_ID_HEADER_NAME, r as createRequestId, s as Interceptor, t as FetchResponse, u as getGlobalSymbol } from "./fetchUtils-CoU35g3M.mjs";
|
||||
import { t as BatchInterceptor } from "./BatchInterceptor-DFaBPilf.mjs";
|
||||
import { n as encodeBuffer, t as decodeBuffer } from "./bufferUtils-_8XfKIfX.mjs";
|
||||
import { t as getRawRequest } from "./getRawRequest-DnwmXyOW.mjs";
|
||||
|
||||
//#region src/utils/getCleanUrl.ts
|
||||
/**
|
||||
* Removes query parameters and hashes from a given URL.
|
||||
*/
|
||||
function getCleanUrl(url, isAbsolute = true) {
|
||||
return [isAbsolute && url.origin, url.pathname].filter(Boolean).join("");
|
||||
}
|
||||
|
||||
//#endregion
|
||||
//#region src/utils/resolveWebSocketUrl.ts
|
||||
/**
|
||||
* Resolve potentially relative WebSocket URLs the same way
|
||||
* the browser does (replace the protocol, use the origin, etc).
|
||||
*
|
||||
* @see https://websockets.spec.whatwg.org//#dom-websocket-websocket
|
||||
*/
|
||||
function resolveWebSocketUrl(url) {
|
||||
if (typeof url === "string") return resolveWebSocketUrl(new URL(url, typeof location !== "undefined" ? location.href : void 0));
|
||||
if (url.protocol === "http:") url.protocol = "ws:";
|
||||
else if (url.protocol === "https:") url.protocol = "wss:";
|
||||
if (url.protocol !== "ws:" && url.protocol !== "wss:")
|
||||
/**
|
||||
* @note These errors are modeled after the browser errors.
|
||||
* The exact error messages aren't provided in the specification.
|
||||
* Node.js uses more obscure error messages that I don't wish to replicate.
|
||||
*/
|
||||
throw new SyntaxError(`Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`);
|
||||
if (url.hash !== "") throw new SyntaxError(`Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`);
|
||||
return url.href;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { BatchInterceptor, FetchResponse, INTERNAL_REQUEST_ID_HEADER_NAME, IS_PATCHED_MODULE, Interceptor, InterceptorReadyState, RequestController, createRequestId, decodeBuffer, deleteGlobalSymbol, encodeBuffer, getCleanUrl, getGlobalSymbol, getRawRequest, resolveWebSocketUrl };
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/index.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/index.mjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/utils/getCleanUrl.ts","../../src/utils/resolveWebSocketUrl.ts"],"sourcesContent":["/**\n * Removes query parameters and hashes from a given URL.\n */\nexport function getCleanUrl(url: URL, isAbsolute: boolean = true): string {\n return [isAbsolute && url.origin, url.pathname].filter(Boolean).join('')\n}\n","/**\n * Resolve potentially relative WebSocket URLs the same way\n * the browser does (replace the protocol, use the origin, etc).\n *\n * @see https://websockets.spec.whatwg.org//#dom-websocket-websocket\n */\nexport function resolveWebSocketUrl(url: string | URL): string {\n if (typeof url === 'string') {\n /**\n * @note Cast the string to a URL first so the parsing errors\n * are thrown as a part of the WebSocket constructor, not consumers.\n */\n const urlRecord = new URL(\n url,\n typeof location !== 'undefined' ? location.href : undefined\n )\n\n return resolveWebSocketUrl(urlRecord)\n }\n\n if (url.protocol === 'http:') {\n url.protocol = 'ws:'\n } else if (url.protocol === 'https:') {\n url.protocol = 'wss:'\n }\n\n if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {\n /**\n * @note These errors are modeled after the browser errors.\n * The exact error messages aren't provided in the specification.\n * Node.js uses more obscure error messages that I don't wish to replicate.\n */\n throw new SyntaxError(\n `Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`\n )\n }\n\n if (url.hash !== '') {\n throw new SyntaxError(\n `Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`\n )\n }\n\n return url.href\n}\n"],"mappings":";;;;;;;;;;AAGA,SAAgB,YAAY,KAAU,aAAsB,MAAc;AACxE,QAAO,CAAC,cAAc,IAAI,QAAQ,IAAI,SAAS,CAAC,OAAO,QAAQ,CAAC,KAAK,GAAG;;;;;;;;;;;ACE1E,SAAgB,oBAAoB,KAA2B;AAC7D,KAAI,OAAO,QAAQ,SAUjB,QAAO,oBALW,IAAI,IACpB,KACA,OAAO,aAAa,cAAc,SAAS,OAAO,OACnD,CAEoC;AAGvC,KAAI,IAAI,aAAa,QACnB,KAAI,WAAW;UACN,IAAI,aAAa,SAC1B,KAAI,WAAW;AAGjB,KAAI,IAAI,aAAa,SAAS,IAAI,aAAa;;;;;;AAM7C,OAAM,IAAI,YACR,sGAAsG,IAAI,SAAS,mBACpH;AAGH,KAAI,IAAI,SAAS,GACf,OAAM,IAAI,YACR,6EAA6E,IAAI,KAAK,6DACvF;AAGH,QAAO,IAAI"}
|
||||
6
node_modules/@mswjs/interceptors/lib/node/interceptors/ClientRequest/index.cjs
generated
vendored
Normal file
6
node_modules/@mswjs/interceptors/lib/node/interceptors/ClientRequest/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
require('../../fetchUtils-BaY5iWXw.cjs');
|
||||
const require_ClientRequest = require('../../ClientRequest-2rDe54Ui.cjs');
|
||||
require('../../handleRequest-Bb7Y-XLw.cjs');
|
||||
require('../../node-dKdAf3tC.cjs');
|
||||
|
||||
exports.ClientRequestInterceptor = require_ClientRequest.ClientRequestInterceptor;
|
||||
2
node_modules/@mswjs/interceptors/lib/node/interceptors/ClientRequest/index.d.cts
generated
vendored
Normal file
2
node_modules/@mswjs/interceptors/lib/node/interceptors/ClientRequest/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { t as ClientRequestInterceptor } from "../../index-BMbJ8FXL.cjs";
|
||||
export { ClientRequestInterceptor };
|
||||
3
node_modules/@mswjs/interceptors/lib/node/interceptors/ClientRequest/index.d.mts
generated
vendored
Normal file
3
node_modules/@mswjs/interceptors/lib/node/interceptors/ClientRequest/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import "../../Interceptor-DEazpLJd.mjs";
|
||||
import { t as ClientRequestInterceptor } from "../../index-C0YAQ36w.mjs";
|
||||
export { ClientRequestInterceptor };
|
||||
6
node_modules/@mswjs/interceptors/lib/node/interceptors/ClientRequest/index.mjs
generated
vendored
Normal file
6
node_modules/@mswjs/interceptors/lib/node/interceptors/ClientRequest/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import "../../fetchUtils-CoU35g3M.mjs";
|
||||
import { t as ClientRequestInterceptor } from "../../ClientRequest-Ca8Qykuv.mjs";
|
||||
import "../../handleRequest-Y97UwBbF.mjs";
|
||||
import "../../node-DwCc6iuP.mjs";
|
||||
|
||||
export { ClientRequestInterceptor };
|
||||
6
node_modules/@mswjs/interceptors/lib/node/interceptors/XMLHttpRequest/index.cjs
generated
vendored
Normal file
6
node_modules/@mswjs/interceptors/lib/node/interceptors/XMLHttpRequest/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
require('../../fetchUtils-BaY5iWXw.cjs');
|
||||
require('../../bufferUtils-DiCTqG-7.cjs');
|
||||
require('../../handleRequest-Bb7Y-XLw.cjs');
|
||||
const require_XMLHttpRequest = require('../../XMLHttpRequest-B7kJdYYI.cjs');
|
||||
|
||||
exports.XMLHttpRequestInterceptor = require_XMLHttpRequest.XMLHttpRequestInterceptor;
|
||||
14
node_modules/@mswjs/interceptors/lib/node/interceptors/XMLHttpRequest/index.d.cts
generated
vendored
Normal file
14
node_modules/@mswjs/interceptors/lib/node/interceptors/XMLHttpRequest/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { l as HttpRequestEventMap, r as Interceptor } from "../../Interceptor-DJ2akVWI.cjs";
|
||||
import { Emitter } from "strict-event-emitter";
|
||||
|
||||
//#region src/interceptors/XMLHttpRequest/index.d.ts
|
||||
type XMLHttpRequestEmitter = Emitter<HttpRequestEventMap>;
|
||||
declare class XMLHttpRequestInterceptor extends Interceptor<HttpRequestEventMap> {
|
||||
static interceptorSymbol: symbol;
|
||||
constructor();
|
||||
protected checkEnvironment(): boolean;
|
||||
protected setup(): void;
|
||||
}
|
||||
//#endregion
|
||||
export { XMLHttpRequestEmitter, XMLHttpRequestInterceptor };
|
||||
//# sourceMappingURL=index.d.cts.map
|
||||
14
node_modules/@mswjs/interceptors/lib/node/interceptors/XMLHttpRequest/index.d.mts
generated
vendored
Normal file
14
node_modules/@mswjs/interceptors/lib/node/interceptors/XMLHttpRequest/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { l as HttpRequestEventMap, r as Interceptor } from "../../Interceptor-DEazpLJd.mjs";
|
||||
import { Emitter } from "strict-event-emitter";
|
||||
|
||||
//#region src/interceptors/XMLHttpRequest/index.d.ts
|
||||
type XMLHttpRequestEmitter = Emitter<HttpRequestEventMap>;
|
||||
declare class XMLHttpRequestInterceptor extends Interceptor<HttpRequestEventMap> {
|
||||
static interceptorSymbol: symbol;
|
||||
constructor();
|
||||
protected checkEnvironment(): boolean;
|
||||
protected setup(): void;
|
||||
}
|
||||
//#endregion
|
||||
export { XMLHttpRequestEmitter, XMLHttpRequestInterceptor };
|
||||
//# sourceMappingURL=index.d.mts.map
|
||||
6
node_modules/@mswjs/interceptors/lib/node/interceptors/XMLHttpRequest/index.mjs
generated
vendored
Normal file
6
node_modules/@mswjs/interceptors/lib/node/interceptors/XMLHttpRequest/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import "../../fetchUtils-CoU35g3M.mjs";
|
||||
import "../../bufferUtils-_8XfKIfX.mjs";
|
||||
import "../../handleRequest-Y97UwBbF.mjs";
|
||||
import { t as XMLHttpRequestInterceptor } from "../../XMLHttpRequest-C8dIZpds.mjs";
|
||||
|
||||
export { XMLHttpRequestInterceptor };
|
||||
5
node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.cjs
generated
vendored
Normal file
5
node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
require('../../fetchUtils-BaY5iWXw.cjs');
|
||||
require('../../handleRequest-Bb7Y-XLw.cjs');
|
||||
const require_fetch = require('../../fetch-BmXpK10r.cjs');
|
||||
|
||||
exports.FetchInterceptor = require_fetch.FetchInterceptor;
|
||||
12
node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.d.cts
generated
vendored
Normal file
12
node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { l as HttpRequestEventMap, r as Interceptor } from "../../Interceptor-DJ2akVWI.cjs";
|
||||
|
||||
//#region src/interceptors/fetch/index.d.ts
|
||||
declare class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
|
||||
static symbol: symbol;
|
||||
constructor();
|
||||
protected checkEnvironment(): boolean;
|
||||
protected setup(): Promise<void>;
|
||||
}
|
||||
//#endregion
|
||||
export { FetchInterceptor };
|
||||
//# sourceMappingURL=index.d.cts.map
|
||||
12
node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.d.mts
generated
vendored
Normal file
12
node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { l as HttpRequestEventMap, r as Interceptor } from "../../Interceptor-DEazpLJd.mjs";
|
||||
|
||||
//#region src/interceptors/fetch/index.d.ts
|
||||
declare class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
|
||||
static symbol: symbol;
|
||||
constructor();
|
||||
protected checkEnvironment(): boolean;
|
||||
protected setup(): Promise<void>;
|
||||
}
|
||||
//#endregion
|
||||
export { FetchInterceptor };
|
||||
//# sourceMappingURL=index.d.mts.map
|
||||
5
node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.mjs
generated
vendored
Normal file
5
node_modules/@mswjs/interceptors/lib/node/interceptors/fetch/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import "../../fetchUtils-CoU35g3M.mjs";
|
||||
import "../../handleRequest-Y97UwBbF.mjs";
|
||||
import { t as FetchInterceptor } from "../../fetch-G1DVwDKG.mjs";
|
||||
|
||||
export { FetchInterceptor };
|
||||
27
node_modules/@mswjs/interceptors/lib/node/node-DwCc6iuP.mjs
generated
vendored
Normal file
27
node_modules/@mswjs/interceptors/lib/node/node-DwCc6iuP.mjs
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { t as getRawRequest } from "./getRawRequest-DnwmXyOW.mjs";
|
||||
import { invariant } from "outvariant";
|
||||
import { ClientRequest } from "node:http";
|
||||
import { Readable } from "node:stream";
|
||||
|
||||
//#region src/utils/node/index.ts
|
||||
const kRawRequestBodyStream = Symbol("kRawRequestBodyStream");
|
||||
/**
|
||||
* Returns the request body stream of the given request.
|
||||
* @note This is only relevant in the context of `http.ClientRequest`.
|
||||
* This function will throw if the given `request` wasn't created based on
|
||||
* the `http.ClientRequest` instance.
|
||||
* You must rely on the web stream consumers for other request clients.
|
||||
*/
|
||||
function getClientRequestBodyStream(request) {
|
||||
invariant(getRawRequest(request) instanceof ClientRequest, `Failed to retrieve raw request body stream: request is not an instance of "http.ClientRequest". Note that you can only use the "getClientRequestBodyStream" function with the requests issued by "http.clientRequest".`);
|
||||
const requestBodyStream = Reflect.get(request, kRawRequestBodyStream);
|
||||
invariant(requestBodyStream instanceof Readable, "Failed to retrieve raw request body stream: corrupted stream (%s)", typeof requestBodyStream);
|
||||
return requestBodyStream;
|
||||
}
|
||||
function setRawRequestBodyStream(request, stream) {
|
||||
Reflect.set(request, kRawRequestBodyStream, stream);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { setRawRequestBodyStream as n, getClientRequestBodyStream as t };
|
||||
//# sourceMappingURL=node-DwCc6iuP.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/node-DwCc6iuP.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/node-DwCc6iuP.mjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"node-DwCc6iuP.mjs","names":[],"sources":["../../src/utils/node/index.ts"],"sourcesContent":["import { ClientRequest } from 'node:http'\nimport { Readable } from 'node:stream'\nimport { invariant } from 'outvariant'\nimport { getRawRequest } from '../../getRawRequest'\n\nconst kRawRequestBodyStream = Symbol('kRawRequestBodyStream')\n\n/**\n * Returns the request body stream of the given request.\n * @note This is only relevant in the context of `http.ClientRequest`.\n * This function will throw if the given `request` wasn't created based on\n * the `http.ClientRequest` instance.\n * You must rely on the web stream consumers for other request clients.\n */\nexport function getClientRequestBodyStream(request: Request): Readable {\n const rawRequest = getRawRequest(request)\n\n invariant(\n rawRequest instanceof ClientRequest,\n `Failed to retrieve raw request body stream: request is not an instance of \"http.ClientRequest\". Note that you can only use the \"getClientRequestBodyStream\" function with the requests issued by \"http.clientRequest\".`\n )\n\n const requestBodyStream = Reflect.get(request, kRawRequestBodyStream)\n\n invariant(\n requestBodyStream instanceof Readable,\n 'Failed to retrieve raw request body stream: corrupted stream (%s)',\n typeof requestBodyStream\n )\n\n return requestBodyStream\n}\n\nexport function setRawRequestBodyStream(\n request: Request,\n stream: Readable\n): void {\n Reflect.set(request, kRawRequestBodyStream, stream)\n}\n"],"mappings":";;;;;;AAKA,MAAM,wBAAwB,OAAO,wBAAwB;;;;;;;;AAS7D,SAAgB,2BAA2B,SAA4B;AAGrE,WAFmB,cAAc,QAAQ,YAGjB,eACtB,yNACD;CAED,MAAM,oBAAoB,QAAQ,IAAI,SAAS,sBAAsB;AAErE,WACE,6BAA6B,UAC7B,qEACA,OAAO,kBACR;AAED,QAAO;;AAGT,SAAgB,wBACd,SACA,QACM;AACN,SAAQ,IAAI,SAAS,uBAAuB,OAAO"}
|
||||
39
node_modules/@mswjs/interceptors/lib/node/node-dKdAf3tC.cjs
generated
vendored
Normal file
39
node_modules/@mswjs/interceptors/lib/node/node-dKdAf3tC.cjs
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
||||
const require_getRawRequest = require('./getRawRequest-BavnMWh_.cjs');
|
||||
let outvariant = require("outvariant");
|
||||
let node_http = require("node:http");
|
||||
let node_stream = require("node:stream");
|
||||
|
||||
//#region src/utils/node/index.ts
|
||||
const kRawRequestBodyStream = Symbol("kRawRequestBodyStream");
|
||||
/**
|
||||
* Returns the request body stream of the given request.
|
||||
* @note This is only relevant in the context of `http.ClientRequest`.
|
||||
* This function will throw if the given `request` wasn't created based on
|
||||
* the `http.ClientRequest` instance.
|
||||
* You must rely on the web stream consumers for other request clients.
|
||||
*/
|
||||
function getClientRequestBodyStream(request) {
|
||||
(0, outvariant.invariant)(require_getRawRequest.getRawRequest(request) instanceof node_http.ClientRequest, `Failed to retrieve raw request body stream: request is not an instance of "http.ClientRequest". Note that you can only use the "getClientRequestBodyStream" function with the requests issued by "http.clientRequest".`);
|
||||
const requestBodyStream = Reflect.get(request, kRawRequestBodyStream);
|
||||
(0, outvariant.invariant)(requestBodyStream instanceof node_stream.Readable, "Failed to retrieve raw request body stream: corrupted stream (%s)", typeof requestBodyStream);
|
||||
return requestBodyStream;
|
||||
}
|
||||
function setRawRequestBodyStream(request, stream) {
|
||||
Reflect.set(request, kRawRequestBodyStream, stream);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
Object.defineProperty(exports, 'getClientRequestBodyStream', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return getClientRequestBodyStream;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, 'setRawRequestBodyStream', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return setRawRequestBodyStream;
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=node-dKdAf3tC.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/node-dKdAf3tC.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/node-dKdAf3tC.cjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"node-dKdAf3tC.cjs","names":["getRawRequest","ClientRequest","Readable"],"sources":["../../src/utils/node/index.ts"],"sourcesContent":["import { ClientRequest } from 'node:http'\nimport { Readable } from 'node:stream'\nimport { invariant } from 'outvariant'\nimport { getRawRequest } from '../../getRawRequest'\n\nconst kRawRequestBodyStream = Symbol('kRawRequestBodyStream')\n\n/**\n * Returns the request body stream of the given request.\n * @note This is only relevant in the context of `http.ClientRequest`.\n * This function will throw if the given `request` wasn't created based on\n * the `http.ClientRequest` instance.\n * You must rely on the web stream consumers for other request clients.\n */\nexport function getClientRequestBodyStream(request: Request): Readable {\n const rawRequest = getRawRequest(request)\n\n invariant(\n rawRequest instanceof ClientRequest,\n `Failed to retrieve raw request body stream: request is not an instance of \"http.ClientRequest\". Note that you can only use the \"getClientRequestBodyStream\" function with the requests issued by \"http.clientRequest\".`\n )\n\n const requestBodyStream = Reflect.get(request, kRawRequestBodyStream)\n\n invariant(\n requestBodyStream instanceof Readable,\n 'Failed to retrieve raw request body stream: corrupted stream (%s)',\n typeof requestBodyStream\n )\n\n return requestBodyStream\n}\n\nexport function setRawRequestBodyStream(\n request: Request,\n stream: Readable\n): void {\n Reflect.set(request, kRawRequestBodyStream, stream)\n}\n"],"mappings":";;;;;;;AAKA,MAAM,wBAAwB,OAAO,wBAAwB;;;;;;;;AAS7D,SAAgB,2BAA2B,SAA4B;AAGrE,2BAFmBA,oCAAc,QAAQ,YAGjBC,yBACtB,yNACD;CAED,MAAM,oBAAoB,QAAQ,IAAI,SAAS,sBAAsB;AAErE,2BACE,6BAA6BC,sBAC7B,qEACA,OAAO,kBACR;AAED,QAAO;;AAGT,SAAgB,wBACd,SACA,QACM;AACN,SAAQ,IAAI,SAAS,uBAAuB,OAAO"}
|
||||
22
node_modules/@mswjs/interceptors/lib/node/presets/node.cjs
generated
vendored
Normal file
22
node_modules/@mswjs/interceptors/lib/node/presets/node.cjs
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
require('../fetchUtils-BaY5iWXw.cjs');
|
||||
require('../bufferUtils-DiCTqG-7.cjs');
|
||||
const require_ClientRequest = require('../ClientRequest-2rDe54Ui.cjs');
|
||||
require('../handleRequest-Bb7Y-XLw.cjs');
|
||||
require('../node-dKdAf3tC.cjs');
|
||||
const require_XMLHttpRequest = require('../XMLHttpRequest-B7kJdYYI.cjs');
|
||||
const require_fetch = require('../fetch-BmXpK10r.cjs');
|
||||
|
||||
//#region src/presets/node.ts
|
||||
/**
|
||||
* The default preset provisions the interception of requests
|
||||
* regardless of their type (http/https/XMLHttpRequest).
|
||||
*/
|
||||
var node_default = [
|
||||
new require_ClientRequest.ClientRequestInterceptor(),
|
||||
new require_XMLHttpRequest.XMLHttpRequestInterceptor(),
|
||||
new require_fetch.FetchInterceptor()
|
||||
];
|
||||
|
||||
//#endregion
|
||||
module.exports = node_default;
|
||||
//# sourceMappingURL=node.cjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/presets/node.cjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/presets/node.cjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"node.cjs","names":["ClientRequestInterceptor","XMLHttpRequestInterceptor","FetchInterceptor"],"sources":["../../../src/presets/node.ts"],"sourcesContent":["import { ClientRequestInterceptor } from '../interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '../interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '../interceptors/fetch'\n\n/**\n * The default preset provisions the interception of requests\n * regardless of their type (http/https/XMLHttpRequest).\n */\nexport default [\n new ClientRequestInterceptor(),\n new XMLHttpRequestInterceptor(),\n new FetchInterceptor(),\n] as const\n"],"mappings":";;;;;;;;;;;;;AAQA,mBAAe;CACb,IAAIA,gDAA0B;CAC9B,IAAIC,kDAA2B;CAC/B,IAAIC,gCAAkB;CACvB"}
|
||||
13
node_modules/@mswjs/interceptors/lib/node/presets/node.d.cts
generated
vendored
Normal file
13
node_modules/@mswjs/interceptors/lib/node/presets/node.d.cts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { t as ClientRequestInterceptor } from "../index-BMbJ8FXL.cjs";
|
||||
import { XMLHttpRequestInterceptor } from "../interceptors/XMLHttpRequest/index.cjs";
|
||||
import { FetchInterceptor } from "../interceptors/fetch/index.cjs";
|
||||
|
||||
//#region src/presets/node.d.ts
|
||||
|
||||
/**
|
||||
* The default preset provisions the interception of requests
|
||||
* regardless of their type (http/https/XMLHttpRequest).
|
||||
*/
|
||||
declare const _default: readonly [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor];
|
||||
export = _default;
|
||||
//# sourceMappingURL=node.d.cts.map
|
||||
15
node_modules/@mswjs/interceptors/lib/node/presets/node.d.mts
generated
vendored
Normal file
15
node_modules/@mswjs/interceptors/lib/node/presets/node.d.mts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import "../Interceptor-DEazpLJd.mjs";
|
||||
import { t as ClientRequestInterceptor } from "../index-C0YAQ36w.mjs";
|
||||
import { XMLHttpRequestInterceptor } from "../interceptors/XMLHttpRequest/index.mjs";
|
||||
import { FetchInterceptor } from "../interceptors/fetch/index.mjs";
|
||||
|
||||
//#region src/presets/node.d.ts
|
||||
|
||||
/**
|
||||
* The default preset provisions the interception of requests
|
||||
* regardless of their type (http/https/XMLHttpRequest).
|
||||
*/
|
||||
declare const _default: readonly [ClientRequestInterceptor, XMLHttpRequestInterceptor, FetchInterceptor];
|
||||
//#endregion
|
||||
export { _default as default };
|
||||
//# sourceMappingURL=node.d.mts.map
|
||||
22
node_modules/@mswjs/interceptors/lib/node/presets/node.mjs
generated
vendored
Normal file
22
node_modules/@mswjs/interceptors/lib/node/presets/node.mjs
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import "../fetchUtils-CoU35g3M.mjs";
|
||||
import "../bufferUtils-_8XfKIfX.mjs";
|
||||
import { t as ClientRequestInterceptor } from "../ClientRequest-Ca8Qykuv.mjs";
|
||||
import "../handleRequest-Y97UwBbF.mjs";
|
||||
import "../node-DwCc6iuP.mjs";
|
||||
import { t as XMLHttpRequestInterceptor } from "../XMLHttpRequest-C8dIZpds.mjs";
|
||||
import { t as FetchInterceptor } from "../fetch-G1DVwDKG.mjs";
|
||||
|
||||
//#region src/presets/node.ts
|
||||
/**
|
||||
* The default preset provisions the interception of requests
|
||||
* regardless of their type (http/https/XMLHttpRequest).
|
||||
*/
|
||||
var node_default = [
|
||||
new ClientRequestInterceptor(),
|
||||
new XMLHttpRequestInterceptor(),
|
||||
new FetchInterceptor()
|
||||
];
|
||||
|
||||
//#endregion
|
||||
export { node_default as default };
|
||||
//# sourceMappingURL=node.mjs.map
|
||||
1
node_modules/@mswjs/interceptors/lib/node/presets/node.mjs.map
generated
vendored
Normal file
1
node_modules/@mswjs/interceptors/lib/node/presets/node.mjs.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"node.mjs","names":[],"sources":["../../../src/presets/node.ts"],"sourcesContent":["import { ClientRequestInterceptor } from '../interceptors/ClientRequest'\nimport { XMLHttpRequestInterceptor } from '../interceptors/XMLHttpRequest'\nimport { FetchInterceptor } from '../interceptors/fetch'\n\n/**\n * The default preset provisions the interception of requests\n * regardless of their type (http/https/XMLHttpRequest).\n */\nexport default [\n new ClientRequestInterceptor(),\n new XMLHttpRequestInterceptor(),\n new FetchInterceptor(),\n] as const\n"],"mappings":";;;;;;;;;;;;;AAQA,mBAAe;CACb,IAAI,0BAA0B;CAC9B,IAAI,2BAA2B;CAC/B,IAAI,kBAAkB;CACvB"}
|
||||
4
node_modules/@mswjs/interceptors/lib/node/utils/node/index.cjs
generated
vendored
Normal file
4
node_modules/@mswjs/interceptors/lib/node/utils/node/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
const require_node = require('../../node-dKdAf3tC.cjs');
|
||||
|
||||
exports.getClientRequestBodyStream = require_node.getClientRequestBodyStream;
|
||||
exports.setRawRequestBodyStream = require_node.setRawRequestBodyStream;
|
||||
16
node_modules/@mswjs/interceptors/lib/node/utils/node/index.d.cts
generated
vendored
Normal file
16
node_modules/@mswjs/interceptors/lib/node/utils/node/index.d.cts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Readable } from "node:stream";
|
||||
|
||||
//#region src/utils/node/index.d.ts
|
||||
|
||||
/**
|
||||
* Returns the request body stream of the given request.
|
||||
* @note This is only relevant in the context of `http.ClientRequest`.
|
||||
* This function will throw if the given `request` wasn't created based on
|
||||
* the `http.ClientRequest` instance.
|
||||
* You must rely on the web stream consumers for other request clients.
|
||||
*/
|
||||
declare function getClientRequestBodyStream(request: Request): Readable;
|
||||
declare function setRawRequestBodyStream(request: Request, stream: Readable): void;
|
||||
//#endregion
|
||||
export { getClientRequestBodyStream, setRawRequestBodyStream };
|
||||
//# sourceMappingURL=index.d.cts.map
|
||||
16
node_modules/@mswjs/interceptors/lib/node/utils/node/index.d.mts
generated
vendored
Normal file
16
node_modules/@mswjs/interceptors/lib/node/utils/node/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Readable } from "node:stream";
|
||||
|
||||
//#region src/utils/node/index.d.ts
|
||||
|
||||
/**
|
||||
* Returns the request body stream of the given request.
|
||||
* @note This is only relevant in the context of `http.ClientRequest`.
|
||||
* This function will throw if the given `request` wasn't created based on
|
||||
* the `http.ClientRequest` instance.
|
||||
* You must rely on the web stream consumers for other request clients.
|
||||
*/
|
||||
declare function getClientRequestBodyStream(request: Request): Readable;
|
||||
declare function setRawRequestBodyStream(request: Request, stream: Readable): void;
|
||||
//#endregion
|
||||
export { getClientRequestBodyStream, setRawRequestBodyStream };
|
||||
//# sourceMappingURL=index.d.mts.map
|
||||
3
node_modules/@mswjs/interceptors/lib/node/utils/node/index.mjs
generated
vendored
Normal file
3
node_modules/@mswjs/interceptors/lib/node/utils/node/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { n as setRawRequestBodyStream, t as getClientRequestBodyStream } from "../../node-DwCc6iuP.mjs";
|
||||
|
||||
export { getClientRequestBodyStream, setRawRequestBodyStream };
|
||||
Reference in New Issue
Block a user