msw 2.12.8 → 2.12.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js +8 -8
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +8 -8
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +3 -2
- package/lib/core/handlers/WebSocketHandler.d.ts +3 -2
- package/lib/core/handlers/WebSocketHandler.js +15 -1
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +16 -2
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/index.d.mts +10 -3
- package/lib/core/index.d.ts +10 -3
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/iife/index.js +36 -11
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +3 -3
- package/src/core/handlers/WebSocketHandler.ts +32 -3
- package/src/core/index.ts +6 -0
- package/src/core/utils/matching/matchRequestUrl.test.ts +57 -43
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Emitter } from 'strict-event-emitter';
|
|
2
2
|
import { WebSocketClientConnectionProtocol, WebSocketServerConnectionProtocol, WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
3
|
-
import {
|
|
3
|
+
import { Path, PathParams, Match } from '../utils/matching/matchRequestUrl.mjs';
|
|
4
4
|
|
|
5
5
|
type WebSocketHandlerParsedResult = {
|
|
6
6
|
match: Match;
|
|
@@ -20,7 +20,8 @@ interface WebSocketResolutionContext {
|
|
|
20
20
|
declare const kEmitter: unique symbol;
|
|
21
21
|
declare const kSender: unique symbol;
|
|
22
22
|
declare class WebSocketHandler {
|
|
23
|
-
private
|
|
23
|
+
#private;
|
|
24
|
+
protected readonly url: Path;
|
|
24
25
|
private readonly __kind;
|
|
25
26
|
id: string;
|
|
26
27
|
callFrame?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Emitter } from 'strict-event-emitter';
|
|
2
2
|
import { WebSocketClientConnectionProtocol, WebSocketServerConnectionProtocol, WebSocketConnectionData } from '@mswjs/interceptors/WebSocket';
|
|
3
|
-
import {
|
|
3
|
+
import { Path, PathParams, Match } from '../utils/matching/matchRequestUrl.js';
|
|
4
4
|
|
|
5
5
|
type WebSocketHandlerParsedResult = {
|
|
6
6
|
match: Match;
|
|
@@ -20,7 +20,8 @@ interface WebSocketResolutionContext {
|
|
|
20
20
|
declare const kEmitter: unique symbol;
|
|
21
21
|
declare const kSender: unique symbol;
|
|
22
22
|
declare class WebSocketHandler {
|
|
23
|
-
private
|
|
23
|
+
#private;
|
|
24
|
+
protected readonly url: Path;
|
|
24
25
|
private readonly __kind;
|
|
25
26
|
id: string;
|
|
26
27
|
callFrame?: string;
|
|
@@ -45,10 +45,11 @@ class WebSocketHandler {
|
|
|
45
45
|
[kEmitter];
|
|
46
46
|
parse(args) {
|
|
47
47
|
const clientUrl = new URL(args.url);
|
|
48
|
+
const resolvedHandlerUrl = this.url instanceof RegExp || this.url.startsWith("*") ? this.url : this.#resolveWebSocketUrl(this.url, args.resolutionContext?.baseUrl);
|
|
48
49
|
clientUrl.pathname = clientUrl.pathname.replace(/^\/socket.io\//, "/");
|
|
49
50
|
const match = (0, import_matchRequestUrl.matchRequestUrl)(
|
|
50
51
|
clientUrl,
|
|
51
|
-
|
|
52
|
+
resolvedHandlerUrl,
|
|
52
53
|
args.resolutionContext?.baseUrl
|
|
53
54
|
);
|
|
54
55
|
return {
|
|
@@ -99,6 +100,19 @@ class WebSocketHandler {
|
|
|
99
100
|
);
|
|
100
101
|
return this[kEmitter].emit("connection", connection);
|
|
101
102
|
}
|
|
103
|
+
#resolveWebSocketUrl(url, baseUrl) {
|
|
104
|
+
const resolvedUrl = (0, import_interceptors.resolveWebSocketUrl)(
|
|
105
|
+
baseUrl ? (
|
|
106
|
+
/**
|
|
107
|
+
* @note Resolve against the base URL preemtively because `resolveWebSocketUrl` only
|
|
108
|
+
* resolves against `location.href`, which is missing in Node.js. Base URL allows
|
|
109
|
+
* the handler to accept a relative URL in Node.js.
|
|
110
|
+
*/
|
|
111
|
+
new URL(url, baseUrl)
|
|
112
|
+
) : url
|
|
113
|
+
);
|
|
114
|
+
return resolvedUrl.replace(/\/$/, "");
|
|
115
|
+
}
|
|
102
116
|
}
|
|
103
117
|
function createStopPropagationListener(handler) {
|
|
104
118
|
return function stopPropagationListener(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/handlers/WebSocketHandler.ts"],"sourcesContent":["import { Emitter } from 'strict-event-emitter'\nimport { createRequestId } from '@mswjs/interceptors'\nimport type {\n WebSocketClientConnectionProtocol,\n WebSocketConnectionData,\n WebSocketServerConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n type Match,\n type Path,\n type PathParams,\n matchRequestUrl,\n} from '../utils/matching/matchRequestUrl'\nimport { getCallFrame } from '../utils/internal/getCallFrame'\nimport type { HandlerKind } from './common'\n\ntype WebSocketHandlerParsedResult = {\n match: Match\n}\n\nexport type WebSocketHandlerEventMap = {\n connection: [args: WebSocketHandlerConnection]\n}\n\nexport interface WebSocketHandlerConnection {\n client: WebSocketClientConnectionProtocol\n server: WebSocketServerConnectionProtocol\n info: WebSocketConnectionData['info']\n params: PathParams\n}\n\nexport interface WebSocketResolutionContext {\n baseUrl?: string\n}\n\nexport const kEmitter = Symbol('kEmitter')\nexport const kSender = Symbol('kSender')\nconst kStopPropagationPatched = Symbol('kStopPropagationPatched')\nconst KOnStopPropagation = Symbol('KOnStopPropagation')\n\nexport class WebSocketHandler {\n private readonly __kind: HandlerKind\n\n public id: string\n public callFrame?: string\n\n protected [kEmitter]: Emitter<WebSocketHandlerEventMap>\n\n constructor(
|
|
1
|
+
{"version":3,"sources":["../../../src/core/handlers/WebSocketHandler.ts"],"sourcesContent":["import { Emitter } from 'strict-event-emitter'\nimport { createRequestId, resolveWebSocketUrl } from '@mswjs/interceptors'\nimport type {\n WebSocketClientConnectionProtocol,\n WebSocketConnectionData,\n WebSocketServerConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n type Match,\n type Path,\n type PathParams,\n matchRequestUrl,\n} from '../utils/matching/matchRequestUrl'\nimport { getCallFrame } from '../utils/internal/getCallFrame'\nimport type { HandlerKind } from './common'\n\ntype WebSocketHandlerParsedResult = {\n match: Match\n}\n\nexport type WebSocketHandlerEventMap = {\n connection: [args: WebSocketHandlerConnection]\n}\n\nexport interface WebSocketHandlerConnection {\n client: WebSocketClientConnectionProtocol\n server: WebSocketServerConnectionProtocol\n info: WebSocketConnectionData['info']\n params: PathParams\n}\n\nexport interface WebSocketResolutionContext {\n baseUrl?: string\n}\n\nexport const kEmitter = Symbol('kEmitter')\nexport const kSender = Symbol('kSender')\nconst kStopPropagationPatched = Symbol('kStopPropagationPatched')\nconst KOnStopPropagation = Symbol('KOnStopPropagation')\n\nexport class WebSocketHandler {\n private readonly __kind: HandlerKind\n\n public id: string\n public callFrame?: string\n\n protected [kEmitter]: Emitter<WebSocketHandlerEventMap>\n\n constructor(protected readonly url: Path) {\n this.id = createRequestId()\n\n this[kEmitter] = new Emitter()\n this.callFrame = getCallFrame(new Error())\n this.__kind = 'EventHandler'\n }\n\n public parse(args: {\n url: URL\n resolutionContext?: WebSocketResolutionContext\n }): WebSocketHandlerParsedResult {\n const clientUrl = new URL(args.url)\n\n // Resolve the WebSocket handler path:\n // - Plain string URLs resolved as per the specification (via Interceptors).\n // - String URLs starting with a wildcard are preserved (prepending a scheme there will break them).\n // - RegExp paths are preserved.\n const resolvedHandlerUrl =\n this.url instanceof RegExp || this.url.startsWith('*')\n ? this.url\n : this.#resolveWebSocketUrl(this.url, args.resolutionContext?.baseUrl)\n\n /**\n * @note Remove the Socket.IO path prefix from the WebSocket\n * client URL. This is an exception to keep the users from\n * including the implementation details in their handlers.\n */\n clientUrl.pathname = clientUrl.pathname.replace(/^\\/socket.io\\//, '/')\n\n const match = matchRequestUrl(\n clientUrl,\n resolvedHandlerUrl,\n args.resolutionContext?.baseUrl,\n )\n\n return {\n match,\n }\n }\n\n public predicate(args: {\n url: URL\n parsedResult: WebSocketHandlerParsedResult\n }): boolean {\n return args.parsedResult.match.matches\n }\n\n public async run(\n connection: Omit<WebSocketHandlerConnection, 'params'>,\n resolutionContext?: WebSocketResolutionContext,\n ): Promise<boolean> {\n const parsedResult = this.parse({\n url: connection.client.url,\n resolutionContext,\n })\n\n if (!this.predicate({ url: connection.client.url, parsedResult })) {\n return false\n }\n\n const resolvedConnection: WebSocketHandlerConnection = {\n ...connection,\n params: parsedResult.match.params || {},\n }\n\n return this.connect(resolvedConnection)\n }\n\n protected connect(connection: WebSocketHandlerConnection): boolean {\n // Support `event.stopPropagation()` for various client/server events.\n connection.client.addEventListener(\n 'message',\n createStopPropagationListener(this),\n )\n connection.client.addEventListener(\n 'close',\n createStopPropagationListener(this),\n )\n\n connection.server.addEventListener(\n 'open',\n createStopPropagationListener(this),\n )\n connection.server.addEventListener(\n 'message',\n createStopPropagationListener(this),\n )\n connection.server.addEventListener(\n 'error',\n createStopPropagationListener(this),\n )\n connection.server.addEventListener(\n 'close',\n createStopPropagationListener(this),\n )\n\n // Emit the connection event on the handler.\n // This is what the developer adds listeners for.\n return this[kEmitter].emit('connection', connection)\n }\n\n #resolveWebSocketUrl(url: string, baseUrl?: string): string {\n const resolvedUrl = resolveWebSocketUrl(\n baseUrl\n ? /**\n * @note Resolve against the base URL preemtively because `resolveWebSocketUrl` only\n * resolves against `location.href`, which is missing in Node.js. Base URL allows\n * the handler to accept a relative URL in Node.js.\n */\n new URL(url, baseUrl)\n : url,\n )\n\n /**\n * @note Omit the trailing slash.\n * While the browser always produces a trailing slash at the end of a WebSocket URL,\n * having it in as the handler's predicate would mean it is *required* in the actual URL.\n */\n return resolvedUrl.replace(/\\/$/, '')\n }\n}\n\nfunction createStopPropagationListener(handler: WebSocketHandler) {\n return function stopPropagationListener(event: Event) {\n const propagationStoppedAt = Reflect.get(event, 'kPropagationStoppedAt') as\n | string\n | undefined\n\n if (propagationStoppedAt && handler.id !== propagationStoppedAt) {\n event.stopImmediatePropagation()\n return\n }\n\n Object.defineProperty(event, KOnStopPropagation, {\n value(this: WebSocketHandler) {\n Object.defineProperty(event, 'kPropagationStoppedAt', {\n value: handler.id,\n })\n },\n configurable: true,\n })\n\n // Since the same event instance is shared between all client/server objects,\n // make sure to patch its `stopPropagation` method only once.\n if (!Reflect.get(event, kStopPropagationPatched)) {\n event.stopPropagation = new Proxy(event.stopPropagation, {\n apply: (target, thisArg, args) => {\n Reflect.get(event, KOnStopPropagation)?.call(handler)\n return Reflect.apply(target, thisArg, args)\n },\n })\n\n Object.defineProperty(event, kStopPropagationPatched, {\n value: true,\n // If something else attempts to redefine this, throw.\n configurable: false,\n })\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAAwB;AACxB,0BAAqD;AAMrD,6BAKO;AACP,0BAA6B;AAsBtB,MAAM,WAAW,OAAO,UAAU;AAClC,MAAM,UAAU,OAAO,SAAS;AACvC,MAAM,0BAA0B,OAAO,yBAAyB;AAChE,MAAM,qBAAqB,OAAO,oBAAoB;AAE/C,MAAM,iBAAiB;AAAA,EAQ5B,YAA+B,KAAW;AAAX;AAC7B,SAAK,SAAK,qCAAgB;AAE1B,SAAK,QAAQ,IAAI,IAAI,oCAAQ;AAC7B,SAAK,gBAAY,kCAAa,IAAI,MAAM,CAAC;AACzC,SAAK,SAAS;AAAA,EAChB;AAAA,EAbiB;AAAA,EAEV;AAAA,EACA;AAAA,EAEP,CAAW,QAAQ;AAAA,EAUZ,MAAM,MAGoB;AAC/B,UAAM,YAAY,IAAI,IAAI,KAAK,GAAG;AAMlC,UAAM,qBACJ,KAAK,eAAe,UAAU,KAAK,IAAI,WAAW,GAAG,IACjD,KAAK,MACL,KAAK,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AAAA,QAMI,IAAI,IAAI,KAAK,OAAO;AAAA,UACpB;AAAA,IACN;AAOA,WAAO,YAAY,QAAQ,OAAO,EAAE;AAAA,EACtC;AACF;AAEA,SAAS,8BAA8B,SAA2B;AAChE,SAAO,SAAS,wBAAwB,OAAc;AACpD,UAAM,uBAAuB,QAAQ,IAAI,OAAO,uBAAuB;AAIvE,QAAI,wBAAwB,QAAQ,OAAO,sBAAsB;AAC/D,YAAM,yBAAyB;AAC/B;AAAA,IACF;AAEA,WAAO,eAAe,OAAO,oBAAoB;AAAA,MAC/C,QAA8B;AAC5B,eAAO,eAAe,OAAO,yBAAyB;AAAA,UACpD,OAAO,QAAQ;AAAA,QACjB,CAAC;AAAA,MACH;AAAA,MACA,cAAc;AAAA,IAChB,CAAC;AAID,QAAI,CAAC,QAAQ,IAAI,OAAO,uBAAuB,GAAG;AAChD,YAAM,kBAAkB,IAAI,MAAM,MAAM,iBAAiB;AAAA,QACvD,OAAO,CAAC,QAAQ,SAAS,SAAS;AAChC,kBAAQ,IAAI,OAAO,kBAAkB,GAAG,KAAK,OAAO;AACpD,iBAAO,QAAQ,MAAM,QAAQ,SAAS,IAAI;AAAA,QAC5C;AAAA,MACF,CAAC;AAED,aAAO,eAAe,OAAO,yBAAyB;AAAA,QACpD,OAAO;AAAA;AAAA,QAEP,cAAc;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Emitter } from "strict-event-emitter";
|
|
2
|
-
import { createRequestId } from "@mswjs/interceptors";
|
|
2
|
+
import { createRequestId, resolveWebSocketUrl } from "@mswjs/interceptors";
|
|
3
3
|
import {
|
|
4
4
|
matchRequestUrl
|
|
5
5
|
} from '../utils/matching/matchRequestUrl.mjs';
|
|
@@ -22,10 +22,11 @@ class WebSocketHandler {
|
|
|
22
22
|
[kEmitter];
|
|
23
23
|
parse(args) {
|
|
24
24
|
const clientUrl = new URL(args.url);
|
|
25
|
+
const resolvedHandlerUrl = this.url instanceof RegExp || this.url.startsWith("*") ? this.url : this.#resolveWebSocketUrl(this.url, args.resolutionContext?.baseUrl);
|
|
25
26
|
clientUrl.pathname = clientUrl.pathname.replace(/^\/socket.io\//, "/");
|
|
26
27
|
const match = matchRequestUrl(
|
|
27
28
|
clientUrl,
|
|
28
|
-
|
|
29
|
+
resolvedHandlerUrl,
|
|
29
30
|
args.resolutionContext?.baseUrl
|
|
30
31
|
);
|
|
31
32
|
return {
|
|
@@ -76,6 +77,19 @@ class WebSocketHandler {
|
|
|
76
77
|
);
|
|
77
78
|
return this[kEmitter].emit("connection", connection);
|
|
78
79
|
}
|
|
80
|
+
#resolveWebSocketUrl(url, baseUrl) {
|
|
81
|
+
const resolvedUrl = resolveWebSocketUrl(
|
|
82
|
+
baseUrl ? (
|
|
83
|
+
/**
|
|
84
|
+
* @note Resolve against the base URL preemtively because `resolveWebSocketUrl` only
|
|
85
|
+
* resolves against `location.href`, which is missing in Node.js. Base URL allows
|
|
86
|
+
* the handler to accept a relative URL in Node.js.
|
|
87
|
+
*/
|
|
88
|
+
new URL(url, baseUrl)
|
|
89
|
+
) : url
|
|
90
|
+
);
|
|
91
|
+
return resolvedUrl.replace(/\/$/, "");
|
|
92
|
+
}
|
|
79
93
|
}
|
|
80
94
|
function createStopPropagationListener(handler) {
|
|
81
95
|
return function stopPropagationListener(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/handlers/WebSocketHandler.ts"],"sourcesContent":["import { Emitter } from 'strict-event-emitter'\nimport { createRequestId } from '@mswjs/interceptors'\nimport type {\n WebSocketClientConnectionProtocol,\n WebSocketConnectionData,\n WebSocketServerConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n type Match,\n type Path,\n type PathParams,\n matchRequestUrl,\n} from '../utils/matching/matchRequestUrl'\nimport { getCallFrame } from '../utils/internal/getCallFrame'\nimport type { HandlerKind } from './common'\n\ntype WebSocketHandlerParsedResult = {\n match: Match\n}\n\nexport type WebSocketHandlerEventMap = {\n connection: [args: WebSocketHandlerConnection]\n}\n\nexport interface WebSocketHandlerConnection {\n client: WebSocketClientConnectionProtocol\n server: WebSocketServerConnectionProtocol\n info: WebSocketConnectionData['info']\n params: PathParams\n}\n\nexport interface WebSocketResolutionContext {\n baseUrl?: string\n}\n\nexport const kEmitter = Symbol('kEmitter')\nexport const kSender = Symbol('kSender')\nconst kStopPropagationPatched = Symbol('kStopPropagationPatched')\nconst KOnStopPropagation = Symbol('KOnStopPropagation')\n\nexport class WebSocketHandler {\n private readonly __kind: HandlerKind\n\n public id: string\n public callFrame?: string\n\n protected [kEmitter]: Emitter<WebSocketHandlerEventMap>\n\n constructor(
|
|
1
|
+
{"version":3,"sources":["../../../src/core/handlers/WebSocketHandler.ts"],"sourcesContent":["import { Emitter } from 'strict-event-emitter'\nimport { createRequestId, resolveWebSocketUrl } from '@mswjs/interceptors'\nimport type {\n WebSocketClientConnectionProtocol,\n WebSocketConnectionData,\n WebSocketServerConnectionProtocol,\n} from '@mswjs/interceptors/WebSocket'\nimport {\n type Match,\n type Path,\n type PathParams,\n matchRequestUrl,\n} from '../utils/matching/matchRequestUrl'\nimport { getCallFrame } from '../utils/internal/getCallFrame'\nimport type { HandlerKind } from './common'\n\ntype WebSocketHandlerParsedResult = {\n match: Match\n}\n\nexport type WebSocketHandlerEventMap = {\n connection: [args: WebSocketHandlerConnection]\n}\n\nexport interface WebSocketHandlerConnection {\n client: WebSocketClientConnectionProtocol\n server: WebSocketServerConnectionProtocol\n info: WebSocketConnectionData['info']\n params: PathParams\n}\n\nexport interface WebSocketResolutionContext {\n baseUrl?: string\n}\n\nexport const kEmitter = Symbol('kEmitter')\nexport const kSender = Symbol('kSender')\nconst kStopPropagationPatched = Symbol('kStopPropagationPatched')\nconst KOnStopPropagation = Symbol('KOnStopPropagation')\n\nexport class WebSocketHandler {\n private readonly __kind: HandlerKind\n\n public id: string\n public callFrame?: string\n\n protected [kEmitter]: Emitter<WebSocketHandlerEventMap>\n\n constructor(protected readonly url: Path) {\n this.id = createRequestId()\n\n this[kEmitter] = new Emitter()\n this.callFrame = getCallFrame(new Error())\n this.__kind = 'EventHandler'\n }\n\n public parse(args: {\n url: URL\n resolutionContext?: WebSocketResolutionContext\n }): WebSocketHandlerParsedResult {\n const clientUrl = new URL(args.url)\n\n // Resolve the WebSocket handler path:\n // - Plain string URLs resolved as per the specification (via Interceptors).\n // - String URLs starting with a wildcard are preserved (prepending a scheme there will break them).\n // - RegExp paths are preserved.\n const resolvedHandlerUrl =\n this.url instanceof RegExp || this.url.startsWith('*')\n ? this.url\n : this.#resolveWebSocketUrl(this.url, args.resolutionContext?.baseUrl)\n\n /**\n * @note Remove the Socket.IO path prefix from the WebSocket\n * client URL. This is an exception to keep the users from\n * including the implementation details in their handlers.\n */\n clientUrl.pathname = clientUrl.pathname.replace(/^\\/socket.io\\//, '/')\n\n const match = matchRequestUrl(\n clientUrl,\n resolvedHandlerUrl,\n args.resolutionContext?.baseUrl,\n )\n\n return {\n match,\n }\n }\n\n public predicate(args: {\n url: URL\n parsedResult: WebSocketHandlerParsedResult\n }): boolean {\n return args.parsedResult.match.matches\n }\n\n public async run(\n connection: Omit<WebSocketHandlerConnection, 'params'>,\n resolutionContext?: WebSocketResolutionContext,\n ): Promise<boolean> {\n const parsedResult = this.parse({\n url: connection.client.url,\n resolutionContext,\n })\n\n if (!this.predicate({ url: connection.client.url, parsedResult })) {\n return false\n }\n\n const resolvedConnection: WebSocketHandlerConnection = {\n ...connection,\n params: parsedResult.match.params || {},\n }\n\n return this.connect(resolvedConnection)\n }\n\n protected connect(connection: WebSocketHandlerConnection): boolean {\n // Support `event.stopPropagation()` for various client/server events.\n connection.client.addEventListener(\n 'message',\n createStopPropagationListener(this),\n )\n connection.client.addEventListener(\n 'close',\n createStopPropagationListener(this),\n )\n\n connection.server.addEventListener(\n 'open',\n createStopPropagationListener(this),\n )\n connection.server.addEventListener(\n 'message',\n createStopPropagationListener(this),\n )\n connection.server.addEventListener(\n 'error',\n createStopPropagationListener(this),\n )\n connection.server.addEventListener(\n 'close',\n createStopPropagationListener(this),\n )\n\n // Emit the connection event on the handler.\n // This is what the developer adds listeners for.\n return this[kEmitter].emit('connection', connection)\n }\n\n #resolveWebSocketUrl(url: string, baseUrl?: string): string {\n const resolvedUrl = resolveWebSocketUrl(\n baseUrl\n ? /**\n * @note Resolve against the base URL preemtively because `resolveWebSocketUrl` only\n * resolves against `location.href`, which is missing in Node.js. Base URL allows\n * the handler to accept a relative URL in Node.js.\n */\n new URL(url, baseUrl)\n : url,\n )\n\n /**\n * @note Omit the trailing slash.\n * While the browser always produces a trailing slash at the end of a WebSocket URL,\n * having it in as the handler's predicate would mean it is *required* in the actual URL.\n */\n return resolvedUrl.replace(/\\/$/, '')\n }\n}\n\nfunction createStopPropagationListener(handler: WebSocketHandler) {\n return function stopPropagationListener(event: Event) {\n const propagationStoppedAt = Reflect.get(event, 'kPropagationStoppedAt') as\n | string\n | undefined\n\n if (propagationStoppedAt && handler.id !== propagationStoppedAt) {\n event.stopImmediatePropagation()\n return\n }\n\n Object.defineProperty(event, KOnStopPropagation, {\n value(this: WebSocketHandler) {\n Object.defineProperty(event, 'kPropagationStoppedAt', {\n value: handler.id,\n })\n },\n configurable: true,\n })\n\n // Since the same event instance is shared between all client/server objects,\n // make sure to patch its `stopPropagation` method only once.\n if (!Reflect.get(event, kStopPropagationPatched)) {\n event.stopPropagation = new Proxy(event.stopPropagation, {\n apply: (target, thisArg, args) => {\n Reflect.get(event, KOnStopPropagation)?.call(handler)\n return Reflect.apply(target, thisArg, args)\n },\n })\n\n Object.defineProperty(event, kStopPropagationPatched, {\n value: true,\n // If something else attempts to redefine this, throw.\n configurable: false,\n })\n }\n }\n}\n"],"mappings":"AAAA,SAAS,eAAe;AACxB,SAAS,iBAAiB,2BAA2B;AAMrD;AAAA,EAIE;AAAA,OACK;AACP,SAAS,oBAAoB;AAsBtB,MAAM,WAAW,OAAO,UAAU;AA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A,QAC5C;AAAA,MACF,CAAC;AAED,aAAO,eAAe,OAAO,yBAAyB;AAAA,QACpD,OAAO;AAAA;AAAA,QAEP,cAAc;AAAA,MAChB,CAAC;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
package/lib/core/index.d.mts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { SetupApi } from './SetupApi.mjs';
|
|
2
|
-
|
|
2
|
+
import { G as GraphQLHandler } from './HttpResponse-Cw4ELwIN.mjs';
|
|
3
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, o as DefaultUnsafeFetchResponse, l as GraphQLCustomPredicate, j as GraphQLJsonRequestBody, k as GraphQLOperationType, f as GraphQLQuery, h as GraphQLRequestBody, i as GraphQLResponseBody, g as GraphQLVariables, q as HttpResponse, H as HttpResponseInit, J as JsonBodyType, P as ParsedGraphQLRequest, R as RequestHandler, c as RequestHandlerOptions, m as ResponseResolutionContext, a as ResponseResolver, e as ResponseResolverInfo, b as ResponseResolverReturnType, S as StrictRequest, p as StrictResponse, n as bodyType } from './HttpResponse-Cw4ELwIN.mjs';
|
|
3
4
|
export { HttpRequestHandler, HttpResponseResolver, http } from './http.mjs';
|
|
4
|
-
|
|
5
|
+
import { HttpHandler } from './handlers/HttpHandler.mjs';
|
|
6
|
+
export { HttpCustomPredicate, HttpHandlerInfo, HttpHandlerMethod, HttpMethods, HttpRequestParsedResult, HttpRequestResolverExtras, RequestQuery } from './handlers/HttpHandler.mjs';
|
|
5
7
|
export { GraphQLLinkHandlers, GraphQLOperationHandler, GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.mjs';
|
|
6
8
|
export { WebSocketEventListener, WebSocketLink, ws } from './ws.mjs';
|
|
7
|
-
|
|
9
|
+
import { WebSocketHandler } from './handlers/WebSocketHandler.mjs';
|
|
10
|
+
export { WebSocketHandlerConnection, WebSocketHandlerEventMap } from './handlers/WebSocketHandler.mjs';
|
|
8
11
|
export { ServerSentEventMessage, ServerSentEventRequestHandler, ServerSentEventResolver, ServerSentEventResolverExtras, sse } from './sse.mjs';
|
|
9
12
|
export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.mjs';
|
|
10
13
|
export { HandleRequestOptions, handleRequest } from './utils/handleRequest.mjs';
|
|
@@ -23,3 +26,7 @@ import '@mswjs/interceptors';
|
|
|
23
26
|
import './utils/internal/isIterable.mjs';
|
|
24
27
|
import './typeUtils.mjs';
|
|
25
28
|
import 'graphql';
|
|
29
|
+
|
|
30
|
+
type AnyHandler = HttpHandler | GraphQLHandler | WebSocketHandler;
|
|
31
|
+
|
|
32
|
+
export { type AnyHandler, GraphQLHandler, HttpHandler, WebSocketHandler };
|
package/lib/core/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { SetupApi } from './SetupApi.js';
|
|
2
|
-
|
|
2
|
+
import { G as GraphQLHandler } from './HttpResponse-CVs3ngx3.js';
|
|
3
|
+
export { A as AsyncResponseResolverReturnType, D as DefaultBodyType, d as DefaultRequestMultipartBody, o as DefaultUnsafeFetchResponse, l as GraphQLCustomPredicate, j as GraphQLJsonRequestBody, k as GraphQLOperationType, f as GraphQLQuery, h as GraphQLRequestBody, i as GraphQLResponseBody, g as GraphQLVariables, q as HttpResponse, H as HttpResponseInit, J as JsonBodyType, P as ParsedGraphQLRequest, R as RequestHandler, c as RequestHandlerOptions, m as ResponseResolutionContext, a as ResponseResolver, e as ResponseResolverInfo, b as ResponseResolverReturnType, S as StrictRequest, p as StrictResponse, n as bodyType } from './HttpResponse-CVs3ngx3.js';
|
|
3
4
|
export { HttpRequestHandler, HttpResponseResolver, http } from './http.js';
|
|
4
|
-
|
|
5
|
+
import { HttpHandler } from './handlers/HttpHandler.js';
|
|
6
|
+
export { HttpCustomPredicate, HttpHandlerInfo, HttpHandlerMethod, HttpMethods, HttpRequestParsedResult, HttpRequestResolverExtras, RequestQuery } from './handlers/HttpHandler.js';
|
|
5
7
|
export { GraphQLLinkHandlers, GraphQLOperationHandler, GraphQLRequestHandler, GraphQLResponseResolver, graphql } from './graphql.js';
|
|
6
8
|
export { WebSocketEventListener, WebSocketLink, ws } from './ws.js';
|
|
7
|
-
|
|
9
|
+
import { WebSocketHandler } from './handlers/WebSocketHandler.js';
|
|
10
|
+
export { WebSocketHandlerConnection, WebSocketHandlerEventMap } from './handlers/WebSocketHandler.js';
|
|
8
11
|
export { ServerSentEventMessage, ServerSentEventRequestHandler, ServerSentEventResolver, ServerSentEventResolverExtras, sse } from './sse.js';
|
|
9
12
|
export { Match, Path, PathParams, matchRequestUrl } from './utils/matching/matchRequestUrl.js';
|
|
10
13
|
export { HandleRequestOptions, handleRequest } from './utils/handleRequest.js';
|
|
@@ -23,3 +26,7 @@ import '@mswjs/interceptors';
|
|
|
23
26
|
import './utils/internal/isIterable.js';
|
|
24
27
|
import './typeUtils.js';
|
|
25
28
|
import 'graphql';
|
|
29
|
+
|
|
30
|
+
type AnyHandler = HttpHandler | GraphQLHandler | WebSocketHandler;
|
|
31
|
+
|
|
32
|
+
export { type AnyHandler, GraphQLHandler, HttpHandler, WebSocketHandler };
|
package/lib/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n type WebSocketHandlerConnection,\n} from './handlers/WebSocketHandler'\n\n/* Server-Sent Events */\nexport {\n sse,\n type ServerSentEventRequestHandler,\n type ServerSentEventResolver,\n type ServerSentEventResolverExtras,\n type ServerSentEventMessage,\n} from './sse'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport {\n onUnhandledRequest,\n type UnhandledRequestStrategy,\n type UnhandledRequestCallback,\n} from './utils/request/onUnhandledRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n ResponseResolverInfo,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n HttpHandlerInfo,\n HttpRequestResolverExtras,\n HttpHandlerMethod,\n HttpCustomPredicate,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLResponseBody,\n GraphQLJsonRequestBody,\n GraphQLOperationType,\n GraphQLCustomPredicate,\n} from './handlers/GraphQLHandler'\nexport type {\n GraphQLRequestHandler,\n GraphQLOperationHandler,\n GraphQLResponseResolver,\n GraphQLLinkHandlers,\n} from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\nexport type { ResponseResolutionContext } from './utils/executeHandlers'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\nexport { isCommonAssetRequest } from './isCommonAssetRequest'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,gBAAuC;AACvC,8BAIO;AAGP,iBAMO;
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n type WebSocketHandlerConnection,\n} from './handlers/WebSocketHandler'\n\n/* Server-Sent Events */\nexport {\n sse,\n type ServerSentEventRequestHandler,\n type ServerSentEventResolver,\n type ServerSentEventResolverExtras,\n type ServerSentEventMessage,\n} from './sse'\n\nimport type { HttpHandler } from './handlers/HttpHandler'\nimport type { GraphQLHandler } from './handlers/GraphQLHandler'\nimport type { WebSocketHandler } from './handlers/WebSocketHandler'\n\nexport type AnyHandler = HttpHandler | GraphQLHandler | WebSocketHandler\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport {\n onUnhandledRequest,\n type UnhandledRequestStrategy,\n type UnhandledRequestCallback,\n} from './utils/request/onUnhandledRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n ResponseResolverInfo,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n HttpHandlerInfo,\n HttpRequestResolverExtras,\n HttpHandlerMethod,\n HttpCustomPredicate,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLResponseBody,\n GraphQLJsonRequestBody,\n GraphQLOperationType,\n GraphQLCustomPredicate,\n} from './handlers/GraphQLHandler'\nexport type {\n GraphQLRequestHandler,\n GraphQLOperationHandler,\n GraphQLResponseResolver,\n GraphQLLinkHandlers,\n} from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\nexport type { ResponseResolutionContext } from './utils/executeHandlers'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\nexport { isCommonAssetRequest } from './isCommonAssetRequest'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAA6B;AAE7B,sBAAyB;AAGzB,4BAA+B;AAC/B,kBAAqB;AACrB,yBAAyC;AACzC,qBAAwB;AACxB,4BAA+B;AAG/B,gBAAuC;AACvC,8BAIO;AAGP,iBAMO;AASP,6BAAgC;AAChC,0BAAc,kCApCd;AAqCA,gCAIO;AACP,yBAA4B;AAC5B,sBAAyB;AAmDzB,0BAAc,2BA9Fd;AA+FA,0BAAc,oBA/Fd;AAgGA,oBAAuB;AACvB,yBAA4B;AAC5B,kCAAqC;AAAA,IAMrC,kCAAa;","names":[]}
|
package/lib/core/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n type WebSocketHandlerConnection,\n} from './handlers/WebSocketHandler'\n\n/* Server-Sent Events */\nexport {\n sse,\n type ServerSentEventRequestHandler,\n type ServerSentEventResolver,\n type ServerSentEventResolverExtras,\n type ServerSentEventMessage,\n} from './sse'\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport {\n onUnhandledRequest,\n type UnhandledRequestStrategy,\n type UnhandledRequestCallback,\n} from './utils/request/onUnhandledRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n ResponseResolverInfo,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n HttpHandlerInfo,\n HttpRequestResolverExtras,\n HttpHandlerMethod,\n HttpCustomPredicate,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLResponseBody,\n GraphQLJsonRequestBody,\n GraphQLOperationType,\n GraphQLCustomPredicate,\n} from './handlers/GraphQLHandler'\nexport type {\n GraphQLRequestHandler,\n GraphQLOperationHandler,\n GraphQLResponseResolver,\n GraphQLLinkHandlers,\n} from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\nexport type { ResponseResolutionContext } from './utils/executeHandlers'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\nexport { isCommonAssetRequest } from './isCommonAssetRequest'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAGzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAG/B,SAAS,UAA8B;AACvC;AAAA,EACE;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,OAKK;
|
|
1
|
+
{"version":3,"sources":["../../src/core/index.ts"],"sourcesContent":["import { checkGlobals } from './utils/internal/checkGlobals'\n\nexport { SetupApi } from './SetupApi'\n\n/* HTTP handlers */\nexport { RequestHandler } from './handlers/RequestHandler'\nexport { http } from './http'\nexport { HttpHandler, HttpMethods } from './handlers/HttpHandler'\nexport { graphql } from './graphql'\nexport { GraphQLHandler } from './handlers/GraphQLHandler'\n\n/* WebSocket handler */\nexport { ws, type WebSocketLink } from './ws'\nexport {\n WebSocketHandler,\n type WebSocketHandlerEventMap,\n type WebSocketHandlerConnection,\n} from './handlers/WebSocketHandler'\n\n/* Server-Sent Events */\nexport {\n sse,\n type ServerSentEventRequestHandler,\n type ServerSentEventResolver,\n type ServerSentEventResolverExtras,\n type ServerSentEventMessage,\n} from './sse'\n\nimport type { HttpHandler } from './handlers/HttpHandler'\nimport type { GraphQLHandler } from './handlers/GraphQLHandler'\nimport type { WebSocketHandler } from './handlers/WebSocketHandler'\n\nexport type AnyHandler = HttpHandler | GraphQLHandler | WebSocketHandler\n\n/* Utils */\nexport { matchRequestUrl } from './utils/matching/matchRequestUrl'\nexport * from './utils/handleRequest'\nexport {\n onUnhandledRequest,\n type UnhandledRequestStrategy,\n type UnhandledRequestCallback,\n} from './utils/request/onUnhandledRequest'\nexport { getResponse } from './getResponse'\nexport { cleanUrl } from './utils/url/cleanUrl'\n\n/**\n * Type definitions.\n */\n\nexport type { SharedOptions, LifeCycleEventsMap } from './sharedOptions'\n\nexport type {\n ResponseResolver,\n ResponseResolverReturnType,\n AsyncResponseResolverReturnType,\n RequestHandlerOptions,\n DefaultBodyType,\n DefaultRequestMultipartBody,\n JsonBodyType,\n ResponseResolverInfo,\n} from './handlers/RequestHandler'\n\nexport type {\n RequestQuery,\n HttpRequestParsedResult,\n HttpHandlerInfo,\n HttpRequestResolverExtras,\n HttpHandlerMethod,\n HttpCustomPredicate,\n} from './handlers/HttpHandler'\nexport type { HttpRequestHandler, HttpResponseResolver } from './http'\n\nexport type {\n GraphQLQuery,\n GraphQLVariables,\n GraphQLRequestBody,\n GraphQLResponseBody,\n GraphQLJsonRequestBody,\n GraphQLOperationType,\n GraphQLCustomPredicate,\n} from './handlers/GraphQLHandler'\nexport type {\n GraphQLRequestHandler,\n GraphQLOperationHandler,\n GraphQLResponseResolver,\n GraphQLLinkHandlers,\n} from './graphql'\n\nexport type { WebSocketData, WebSocketEventListener } from './ws'\n\nexport type { Path, PathParams, Match } from './utils/matching/matchRequestUrl'\nexport type { ParsedGraphQLRequest } from './utils/internal/parseGraphQLRequest'\nexport type { ResponseResolutionContext } from './utils/executeHandlers'\n\nexport * from './HttpResponse'\nexport * from './delay'\nexport { bypass } from './bypass'\nexport { passthrough } from './passthrough'\nexport { isCommonAssetRequest } from './isCommonAssetRequest'\n\n// Validate environmental globals before executing any code.\n// This ensures that the library gives user-friendly errors\n// when ran in the environments that require additional polyfills\n// from the end user.\ncheckGlobals()\n"],"mappings":"AAAA,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB;AAGzB,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,aAAa,mBAAmB;AACzC,SAAS,eAAe;AACxB,SAAS,sBAAsB;AAG/B,SAAS,UAA8B;AACvC;AAAA,EACE;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,OAKK;AASP,SAAS,uBAAuB;AAChC,cAAc;AACd;AAAA,EACE;AAAA,OAGK;AACP,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAmDzB,cAAc;AACd,cAAc;AACd,SAAS,cAAc;AACvB,SAAS,mBAAmB;AAC5B,SAAS,4BAA4B;AAMrC,aAAa;","names":[]}
|
package/lib/iife/index.js
CHANGED
|
@@ -15110,7 +15110,7 @@ ${operationTypes.join("\n")}
|
|
|
15110
15110
|
}
|
|
15111
15111
|
};
|
|
15112
15112
|
|
|
15113
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
15113
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-BTaNLFr0.mjs
|
|
15114
15114
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
15115
15115
|
var InterceptorError = class InterceptorError2 extends Error {
|
|
15116
15116
|
constructor(message4) {
|
|
@@ -15558,7 +15558,7 @@ ${operationTypes.join("\n")}
|
|
|
15558
15558
|
return message4.toString();
|
|
15559
15559
|
}
|
|
15560
15560
|
|
|
15561
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
15561
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DQcIlohW.mjs
|
|
15562
15562
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
15563
15563
|
function getGlobalSymbol(symbol) {
|
|
15564
15564
|
return globalThis[symbol] || void 0;
|
|
@@ -15707,7 +15707,7 @@ ${operationTypes.join("\n")}
|
|
|
15707
15707
|
return Math.random().toString(16).slice(2);
|
|
15708
15708
|
}
|
|
15709
15709
|
|
|
15710
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
15710
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/bufferUtils-BiiO6HZv.mjs
|
|
15711
15711
|
var encoder = new TextEncoder();
|
|
15712
15712
|
function encodeBuffer(text) {
|
|
15713
15713
|
return encoder.encode(text);
|
|
@@ -15719,7 +15719,18 @@ ${operationTypes.join("\n")}
|
|
|
15719
15719
|
return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
|
|
15720
15720
|
}
|
|
15721
15721
|
|
|
15722
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
15722
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/resolveWebSocketUrl-C83-x9iE.mjs
|
|
15723
|
+
function resolveWebSocketUrl(url) {
|
|
15724
|
+
if (typeof url === "string") return resolveWebSocketUrl(new URL(url, typeof location !== "undefined" ? location.href : void 0));
|
|
15725
|
+
if (url.protocol === "http:") url.protocol = "ws:";
|
|
15726
|
+
else if (url.protocol === "https:") url.protocol = "wss:";
|
|
15727
|
+
if (url.protocol !== "ws:" && url.protocol !== "wss:")
|
|
15728
|
+
throw new SyntaxError(`Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`);
|
|
15729
|
+
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.`);
|
|
15730
|
+
return url.href;
|
|
15731
|
+
}
|
|
15732
|
+
|
|
15733
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
15723
15734
|
var BatchInterceptor = class BatchInterceptor2 extends Interceptor {
|
|
15724
15735
|
constructor(options) {
|
|
15725
15736
|
BatchInterceptor2.symbol = Symbol(options.name);
|
|
@@ -19527,10 +19538,11 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
19527
19538
|
[kEmitter];
|
|
19528
19539
|
parse(args) {
|
|
19529
19540
|
const clientUrl = new URL(args.url);
|
|
19541
|
+
const resolvedHandlerUrl = this.url instanceof RegExp || this.url.startsWith("*") ? this.url : this.#resolveWebSocketUrl(this.url, args.resolutionContext?.baseUrl);
|
|
19530
19542
|
clientUrl.pathname = clientUrl.pathname.replace(/^\/socket.io\//, "/");
|
|
19531
19543
|
const match2 = matchRequestUrl(
|
|
19532
19544
|
clientUrl,
|
|
19533
|
-
|
|
19545
|
+
resolvedHandlerUrl,
|
|
19534
19546
|
args.resolutionContext?.baseUrl
|
|
19535
19547
|
);
|
|
19536
19548
|
return {
|
|
@@ -19581,6 +19593,19 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
19581
19593
|
);
|
|
19582
19594
|
return this[kEmitter].emit("connection", connection);
|
|
19583
19595
|
}
|
|
19596
|
+
#resolveWebSocketUrl(url, baseUrl) {
|
|
19597
|
+
const resolvedUrl = resolveWebSocketUrl(
|
|
19598
|
+
baseUrl ? (
|
|
19599
|
+
/**
|
|
19600
|
+
* @note Resolve against the base URL preemtively because `resolveWebSocketUrl` only
|
|
19601
|
+
* resolves against `location.href`, which is missing in Node.js. Base URL allows
|
|
19602
|
+
* the handler to accept a relative URL in Node.js.
|
|
19603
|
+
*/
|
|
19604
|
+
new URL(url, baseUrl)
|
|
19605
|
+
) : url
|
|
19606
|
+
);
|
|
19607
|
+
return resolvedUrl.replace(/\/$/, "");
|
|
19608
|
+
}
|
|
19584
19609
|
};
|
|
19585
19610
|
function createStopPropagationListener(handler) {
|
|
19586
19611
|
return function stopPropagationListener(event) {
|
|
@@ -21548,7 +21573,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
21548
21573
|
};
|
|
21549
21574
|
};
|
|
21550
21575
|
|
|
21551
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
21576
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-npXitu1-.mjs
|
|
21552
21577
|
async function emitAsync(emitter, eventName, ...data) {
|
|
21553
21578
|
const listeners = emitter.listeners(eventName);
|
|
21554
21579
|
if (listeners.length === 0) return;
|
|
@@ -21566,7 +21591,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
21566
21591
|
return true;
|
|
21567
21592
|
}
|
|
21568
21593
|
|
|
21569
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
21594
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
21570
21595
|
function bindEvent(target, event) {
|
|
21571
21596
|
Object.defineProperties(event, {
|
|
21572
21597
|
target: {
|
|
@@ -21720,7 +21745,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
21720
21745
|
this._onmessage = null;
|
|
21721
21746
|
this._onerror = null;
|
|
21722
21747
|
this._onclose = null;
|
|
21723
|
-
this.url = url
|
|
21748
|
+
this.url = resolveWebSocketUrl(url);
|
|
21724
21749
|
this.protocol = "";
|
|
21725
21750
|
this.extensions = "";
|
|
21726
21751
|
this.binaryType = "blob";
|
|
@@ -22464,7 +22489,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
22464
22489
|
}
|
|
22465
22490
|
};
|
|
22466
22491
|
|
|
22467
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
22492
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/handleRequest-D7kpTI5U.mjs
|
|
22468
22493
|
function isObject3(value, loose = false) {
|
|
22469
22494
|
return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
|
|
22470
22495
|
}
|
|
@@ -22581,7 +22606,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
22581
22606
|
return options.controller.handled;
|
|
22582
22607
|
}
|
|
22583
22608
|
|
|
22584
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
22609
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/fetch-DdKEdDOR.mjs
|
|
22585
22610
|
function createNetworkError(cause) {
|
|
22586
22611
|
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
|
22587
22612
|
}
|
|
@@ -22774,7 +22799,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
22774
22799
|
}
|
|
22775
22800
|
};
|
|
22776
22801
|
|
|
22777
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.
|
|
22802
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/XMLHttpRequest-BvxZV0WU.mjs
|
|
22778
22803
|
function concatArrayBuffer(left, right) {
|
|
22779
22804
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
22780
22805
|
result.set(left, 0);
|