msw 2.12.13 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.d.mts +29 -19
- package/lib/browser/index.d.ts +29 -19
- package/lib/browser/index.js +1763 -1321
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +1769 -1321
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-Dj6ibgFJ.d.ts → HttpResponse-CksOMVAa.d.ts} +5 -5
- package/lib/core/{HttpResponse-Be4eT3x6.d.mts → HttpResponse-DlRR1D-f.d.mts} +5 -5
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/experimental/compat.d.mts +17 -0
- package/lib/core/experimental/compat.d.ts +17 -0
- package/lib/core/experimental/compat.js +54 -0
- package/lib/core/experimental/compat.js.map +1 -0
- package/lib/core/experimental/compat.mjs +36 -0
- package/lib/core/experimental/compat.mjs.map +1 -0
- package/lib/core/experimental/define-network.d.mts +75 -0
- package/lib/core/experimental/define-network.d.ts +75 -0
- package/lib/core/experimental/define-network.js +124 -0
- package/lib/core/experimental/define-network.js.map +1 -0
- package/lib/core/experimental/define-network.mjs +107 -0
- package/lib/core/experimental/define-network.mjs.map +1 -0
- package/lib/core/experimental/frames/http-frame.d.mts +77 -0
- package/lib/core/experimental/frames/http-frame.d.ts +77 -0
- package/lib/core/experimental/frames/http-frame.js +194 -0
- package/lib/core/experimental/frames/http-frame.js.map +1 -0
- package/lib/core/experimental/frames/http-frame.mjs +176 -0
- package/lib/core/experimental/frames/http-frame.mjs.map +1 -0
- package/lib/core/experimental/frames/network-frame.d.mts +12 -0
- package/lib/core/experimental/frames/network-frame.d.ts +12 -0
- package/lib/core/{handlers/common.js → experimental/frames/network-frame.js} +19 -3
- package/lib/core/experimental/frames/network-frame.js.map +1 -0
- package/lib/core/experimental/frames/network-frame.mjs +13 -0
- package/lib/core/experimental/frames/network-frame.mjs.map +1 -0
- package/lib/core/experimental/frames/websocket-frame.d.mts +55 -0
- package/lib/core/experimental/frames/websocket-frame.d.ts +55 -0
- package/lib/core/experimental/frames/websocket-frame.js +129 -0
- package/lib/core/experimental/frames/websocket-frame.js.map +1 -0
- package/lib/core/experimental/frames/websocket-frame.mjs +116 -0
- package/lib/core/experimental/frames/websocket-frame.mjs.map +1 -0
- package/lib/core/experimental/handlers-controller.d.mts +35 -0
- package/lib/core/experimental/handlers-controller.d.ts +35 -0
- package/lib/core/experimental/handlers-controller.js +121 -0
- package/lib/core/experimental/handlers-controller.js.map +1 -0
- package/lib/core/experimental/handlers-controller.mjs +101 -0
- package/lib/core/experimental/handlers-controller.mjs.map +1 -0
- package/lib/core/experimental/index.d.mts +17 -0
- package/lib/core/experimental/index.d.ts +17 -0
- package/lib/core/experimental/index.js +36 -0
- package/lib/core/experimental/index.js.map +1 -0
- package/lib/core/experimental/index.mjs +20 -0
- package/lib/core/experimental/index.mjs.map +1 -0
- package/lib/core/experimental/on-unhandled-frame.d.mts +12 -0
- package/lib/core/experimental/on-unhandled-frame.d.ts +12 -0
- package/lib/core/experimental/on-unhandled-frame.js +90 -0
- package/lib/core/experimental/on-unhandled-frame.js.map +1 -0
- package/lib/core/experimental/on-unhandled-frame.mjs +70 -0
- package/lib/core/experimental/on-unhandled-frame.mjs.map +1 -0
- package/lib/core/experimental/request-utils.d.mts +12 -0
- package/lib/core/experimental/request-utils.d.ts +12 -0
- package/lib/core/experimental/request-utils.js +50 -0
- package/lib/core/experimental/request-utils.js.map +1 -0
- package/lib/core/experimental/request-utils.mjs +30 -0
- package/lib/core/experimental/request-utils.mjs.map +1 -0
- package/lib/core/experimental/setup-api.d.mts +33 -0
- package/lib/core/experimental/setup-api.d.ts +33 -0
- package/lib/core/experimental/setup-api.js +61 -0
- package/lib/core/experimental/setup-api.js.map +1 -0
- package/lib/core/experimental/setup-api.mjs +43 -0
- package/lib/core/experimental/setup-api.mjs.map +1 -0
- package/lib/core/experimental/sources/interceptor-source.d.mts +28 -0
- package/lib/core/experimental/sources/interceptor-source.d.ts +28 -0
- package/lib/core/experimental/sources/interceptor-source.js +142 -0
- package/lib/core/experimental/sources/interceptor-source.js.map +1 -0
- package/lib/core/experimental/sources/interceptor-source.mjs +124 -0
- package/lib/core/experimental/sources/interceptor-source.mjs.map +1 -0
- package/lib/core/experimental/sources/network-source.d.mts +31 -0
- package/lib/core/experimental/sources/network-source.d.ts +31 -0
- package/lib/core/experimental/sources/network-source.js +50 -0
- package/lib/core/experimental/sources/network-source.js.map +1 -0
- package/lib/core/experimental/sources/network-source.mjs +30 -0
- package/lib/core/experimental/sources/network-source.mjs.map +1 -0
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +5 -6
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +5 -6
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +8 -4
- package/lib/core/handlers/WebSocketHandler.d.ts +8 -4
- package/lib/core/handlers/WebSocketHandler.js +18 -5
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +18 -5
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +7 -12
- package/lib/core/index.d.ts +7 -12
- package/lib/core/index.js +2 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/network-frame-B7A0ggXE.d.mts +56 -0
- package/lib/core/network-frame-usYiHS0K.d.ts +56 -0
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sharedOptions.d.mts +6 -2
- package/lib/core/sharedOptions.d.ts +6 -2
- package/lib/core/sharedOptions.js.map +1 -1
- package/lib/core/sse.d.mts +1 -1
- package/lib/core/sse.d.ts +1 -1
- package/lib/core/sse.js.map +1 -1
- package/lib/core/sse.mjs.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.mjs.map +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -1
- package/lib/core/utils/handleRequest.d.ts +2 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +3 -3
- package/lib/core/utils/internal/isHandlerKind.d.ts +3 -3
- package/lib/core/utils/internal/isHandlerKind.js +2 -1
- package/lib/core/utils/internal/isHandlerKind.js.map +1 -1
- package/lib/core/utils/internal/isHandlerKind.mjs +2 -1
- package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/matching/matchRequestUrl.js +1 -1
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.d.mts +2 -2
- package/lib/core/utils/request/onUnhandledRequest.d.ts +2 -2
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.js +1 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.js +39 -10
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +39 -10
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -1
- package/lib/core/ws.d.mts +3 -3
- package/lib/core/ws.d.ts +3 -3
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +2022 -1433
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +21 -29
- package/lib/native/index.d.ts +21 -29
- package/lib/native/index.js +48 -116
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +51 -118
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +55 -33
- package/lib/node/index.d.ts +55 -33
- package/lib/node/index.js +152 -154
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +156 -156
- package/lib/node/index.mjs.map +1 -1
- package/package.json +10 -2
- package/src/browser/{setupWorker/glossary.ts → glossary.ts} +16 -33
- package/src/browser/index.ts +2 -3
- package/src/browser/{setupWorker/setupWorker.node.test.ts → setup-worker.node.test.ts} +2 -4
- package/src/browser/setup-worker.ts +148 -0
- package/src/browser/sources/fallback-http-source.ts +56 -0
- package/src/browser/sources/service-worker-source.ts +455 -0
- package/src/browser/tsconfig.browser.json +7 -2
- package/src/browser/utils/deserializeRequest.ts +1 -1
- package/src/browser/{setupWorker/start/utils/getWorkerByRegistration.ts → utils/get-worker-by-registration.ts} +3 -1
- package/src/browser/{setupWorker/start/utils/getWorkerInstance.ts → utils/get-worker-instance.ts} +4 -4
- package/src/browser/utils/pruneGetRequestBody.test.ts +1 -3
- package/src/browser/utils/pruneGetRequestBody.ts +1 -1
- package/src/browser/utils/validate-worker-scope.ts +19 -0
- package/src/browser/utils/workerChannel.ts +2 -2
- package/src/core/experimental/compat.ts +50 -0
- package/src/core/experimental/define-network.test.ts +124 -0
- package/src/core/experimental/define-network.ts +215 -0
- package/src/core/experimental/frames/http-frame.test.ts +360 -0
- package/src/core/experimental/frames/http-frame.ts +271 -0
- package/src/core/experimental/frames/network-frame.ts +64 -0
- package/src/core/experimental/frames/websocket-frame.test.ts +280 -0
- package/src/core/experimental/frames/websocket-frame.ts +188 -0
- package/src/core/experimental/handlers-controller.test.ts +198 -0
- package/src/core/experimental/handlers-controller.ts +145 -0
- package/src/core/experimental/index.ts +16 -0
- package/src/core/experimental/on-unhandled-frame.test.ts +360 -0
- package/src/core/experimental/on-unhandled-frame.ts +110 -0
- package/src/core/experimental/request-utils.test.ts +70 -0
- package/src/core/experimental/request-utils.ts +39 -0
- package/src/core/experimental/setup-api.ts +59 -0
- package/src/core/experimental/sources/interceptor-source.ts +185 -0
- package/src/core/experimental/sources/network-source.test.ts +74 -0
- package/src/core/experimental/sources/network-source.ts +56 -0
- package/src/core/handlers/RequestHandler.ts +9 -10
- package/src/core/handlers/WebSocketHandler.ts +27 -11
- package/src/core/index.ts +3 -7
- package/src/core/sharedOptions.ts +9 -4
- package/src/core/sse.ts +1 -1
- package/src/core/utils/cookieStore.ts +2 -1
- package/src/core/utils/internal/isHandlerKind.test.ts +20 -22
- package/src/core/utils/internal/isHandlerKind.ts +5 -9
- package/src/core/utils/matching/matchRequestUrl.test.ts +87 -3
- package/src/core/utils/matching/matchRequestUrl.ts +2 -2
- package/src/core/utils/request/onUnhandledRequest.ts +2 -2
- package/src/core/ws/WebSocketClientManager.test.ts +2 -10
- package/src/core/ws/handleWebSocketEvent.ts +5 -1
- package/src/core/ws/utils/attachWebSocketLogger.ts +43 -11
- package/src/core/ws.test.ts +1 -3
- package/src/core/ws.ts +6 -6
- package/src/iife/index.ts +1 -1
- package/src/native/index.ts +34 -11
- package/src/node/async-handlers-controller.test.ts +50 -0
- package/src/node/async-handlers-controller.ts +69 -0
- package/src/node/glossary.ts +19 -18
- package/src/node/index.ts +6 -2
- package/src/node/setup-server-common.ts +100 -0
- package/src/node/setup-server.ts +91 -0
- package/src/tsconfig.core.json +8 -0
- package/src/tsconfig.node.json +8 -3
- package/src/tsconfig.src.json +0 -2
- package/src/tsconfig.worker.json +2 -1
- package/lib/core/SetupApi.d.mts +0 -44
- package/lib/core/SetupApi.d.ts +0 -44
- package/lib/core/SetupApi.js +0 -112
- package/lib/core/SetupApi.js.map +0 -1
- package/lib/core/SetupApi.mjs +0 -92
- package/lib/core/SetupApi.mjs.map +0 -1
- package/lib/core/handlers/common.d.mts +0 -3
- package/lib/core/handlers/common.d.ts +0 -3
- package/lib/core/handlers/common.js.map +0 -1
- package/lib/core/handlers/common.mjs +0 -1
- package/lib/core/handlers/common.mjs.map +0 -1
- package/src/browser/setupWorker/setupWorker.ts +0 -184
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +0 -71
- package/src/browser/setupWorker/start/createRequestListener.ts +0 -138
- package/src/browser/setupWorker/start/createResponseListener.ts +0 -57
- package/src/browser/setupWorker/start/createStartHandler.ts +0 -137
- package/src/browser/setupWorker/start/utils/enableMocking.ts +0 -30
- package/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts +0 -59
- package/src/browser/setupWorker/start/utils/prepareStartHandler.ts +0 -44
- package/src/browser/setupWorker/start/utils/printStartMessage.test.ts +0 -84
- package/src/browser/setupWorker/start/utils/printStartMessage.ts +0 -51
- package/src/browser/setupWorker/start/utils/validateWorkerScope.ts +0 -18
- package/src/browser/setupWorker/stop/utils/printStopMessage.test.ts +0 -26
- package/src/browser/setupWorker/stop/utils/printStopMessage.ts +0 -13
- package/src/browser/utils/checkWorkerIntegrity.ts +0 -42
- package/src/core/SetupApi.ts +0 -127
- package/src/core/handlers/common.ts +0 -1
- package/src/node/SetupServerApi.ts +0 -87
- package/src/node/SetupServerCommonApi.ts +0 -169
- package/src/node/setupServer.ts +0 -15
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { TypedEvent } from 'rettime';
|
|
2
|
+
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../network-frame-B7A0ggXE.mjs';
|
|
3
|
+
import { HandlersController, AnyHandler } from '../handlers-controller.mjs';
|
|
4
|
+
import { R as RequestHandler } from '../../HttpResponse-DlRR1D-f.mjs';
|
|
5
|
+
import '../../handlers/WebSocketHandler.mjs';
|
|
6
|
+
import 'strict-event-emitter';
|
|
7
|
+
import '@mswjs/interceptors/WebSocket';
|
|
8
|
+
import '../../utils/matching/matchRequestUrl.mjs';
|
|
9
|
+
import '@mswjs/interceptors';
|
|
10
|
+
import '../../utils/internal/isIterable.mjs';
|
|
11
|
+
import '../../typeUtils.mjs';
|
|
12
|
+
import 'graphql';
|
|
13
|
+
|
|
14
|
+
interface HttpNetworkFrameOptions {
|
|
15
|
+
id?: string;
|
|
16
|
+
request: Request;
|
|
17
|
+
}
|
|
18
|
+
declare class RequestEvent<DataType extends {
|
|
19
|
+
requestId: string;
|
|
20
|
+
request: Request;
|
|
21
|
+
} = {
|
|
22
|
+
requestId: string;
|
|
23
|
+
request: Request;
|
|
24
|
+
}, ReturnType = void, EventType extends string = string> extends TypedEvent<DataType, ReturnType, EventType> {
|
|
25
|
+
readonly requestId: string;
|
|
26
|
+
readonly request: Request;
|
|
27
|
+
constructor(type: EventType, data: DataType);
|
|
28
|
+
}
|
|
29
|
+
declare class ResponseEvent<DataType extends {
|
|
30
|
+
requestId: string;
|
|
31
|
+
request: Request;
|
|
32
|
+
response: Response;
|
|
33
|
+
} = {
|
|
34
|
+
requestId: string;
|
|
35
|
+
request: Request;
|
|
36
|
+
response: Response;
|
|
37
|
+
}, ReturnType = void, EventType extends string = string> extends TypedEvent<DataType, ReturnType, EventType> {
|
|
38
|
+
readonly requestId: string;
|
|
39
|
+
readonly request: Request;
|
|
40
|
+
readonly response: Response;
|
|
41
|
+
constructor(type: EventType, data: DataType);
|
|
42
|
+
}
|
|
43
|
+
declare class UnhandledExceptionEvent<DataType extends {
|
|
44
|
+
error: Error;
|
|
45
|
+
requestId: string;
|
|
46
|
+
request: Request;
|
|
47
|
+
} = {
|
|
48
|
+
error: Error;
|
|
49
|
+
requestId: string;
|
|
50
|
+
request: Request;
|
|
51
|
+
}, ReturnType = void, EventType extends string = string> extends TypedEvent<DataType, ReturnType, EventType> {
|
|
52
|
+
readonly error: Error;
|
|
53
|
+
readonly requestId: string;
|
|
54
|
+
readonly request: Request;
|
|
55
|
+
constructor(type: EventType, data: DataType);
|
|
56
|
+
}
|
|
57
|
+
type HttpNetworkFrameEventMap = {
|
|
58
|
+
'request:start': RequestEvent;
|
|
59
|
+
'request:match': RequestEvent;
|
|
60
|
+
'request:unhandled': RequestEvent;
|
|
61
|
+
'request:end': RequestEvent;
|
|
62
|
+
'response:mocked': ResponseEvent;
|
|
63
|
+
'response:bypass': ResponseEvent;
|
|
64
|
+
unhandledException: UnhandledExceptionEvent;
|
|
65
|
+
};
|
|
66
|
+
declare abstract class HttpNetworkFrame extends NetworkFrame<'http', {
|
|
67
|
+
id: string;
|
|
68
|
+
request: Request;
|
|
69
|
+
}, HttpNetworkFrameEventMap> {
|
|
70
|
+
constructor(options: HttpNetworkFrameOptions);
|
|
71
|
+
getHandlers(controller: HandlersController): Array<AnyHandler>;
|
|
72
|
+
abstract respondWith(response?: Response): void;
|
|
73
|
+
getUnhandledMessage(): Promise<string>;
|
|
74
|
+
resolve(handlers: Array<RequestHandler>, onUnhandledFrame: UnhandledFrameHandle, resolutionContext?: NetworkFrameResolutionContext): Promise<boolean | null>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { HttpNetworkFrame, type HttpNetworkFrameEventMap, RequestEvent, ResponseEvent, UnhandledExceptionEvent };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { TypedEvent } from 'rettime';
|
|
2
|
+
import { N as NetworkFrame, b as UnhandledFrameHandle, a as NetworkFrameResolutionContext } from '../../network-frame-usYiHS0K.js';
|
|
3
|
+
import { HandlersController, AnyHandler } from '../handlers-controller.js';
|
|
4
|
+
import { R as RequestHandler } from '../../HttpResponse-CksOMVAa.js';
|
|
5
|
+
import '../../handlers/WebSocketHandler.js';
|
|
6
|
+
import 'strict-event-emitter';
|
|
7
|
+
import '@mswjs/interceptors/WebSocket';
|
|
8
|
+
import '../../utils/matching/matchRequestUrl.js';
|
|
9
|
+
import '@mswjs/interceptors';
|
|
10
|
+
import '../../utils/internal/isIterable.js';
|
|
11
|
+
import '../../typeUtils.js';
|
|
12
|
+
import 'graphql';
|
|
13
|
+
|
|
14
|
+
interface HttpNetworkFrameOptions {
|
|
15
|
+
id?: string;
|
|
16
|
+
request: Request;
|
|
17
|
+
}
|
|
18
|
+
declare class RequestEvent<DataType extends {
|
|
19
|
+
requestId: string;
|
|
20
|
+
request: Request;
|
|
21
|
+
} = {
|
|
22
|
+
requestId: string;
|
|
23
|
+
request: Request;
|
|
24
|
+
}, ReturnType = void, EventType extends string = string> extends TypedEvent<DataType, ReturnType, EventType> {
|
|
25
|
+
readonly requestId: string;
|
|
26
|
+
readonly request: Request;
|
|
27
|
+
constructor(type: EventType, data: DataType);
|
|
28
|
+
}
|
|
29
|
+
declare class ResponseEvent<DataType extends {
|
|
30
|
+
requestId: string;
|
|
31
|
+
request: Request;
|
|
32
|
+
response: Response;
|
|
33
|
+
} = {
|
|
34
|
+
requestId: string;
|
|
35
|
+
request: Request;
|
|
36
|
+
response: Response;
|
|
37
|
+
}, ReturnType = void, EventType extends string = string> extends TypedEvent<DataType, ReturnType, EventType> {
|
|
38
|
+
readonly requestId: string;
|
|
39
|
+
readonly request: Request;
|
|
40
|
+
readonly response: Response;
|
|
41
|
+
constructor(type: EventType, data: DataType);
|
|
42
|
+
}
|
|
43
|
+
declare class UnhandledExceptionEvent<DataType extends {
|
|
44
|
+
error: Error;
|
|
45
|
+
requestId: string;
|
|
46
|
+
request: Request;
|
|
47
|
+
} = {
|
|
48
|
+
error: Error;
|
|
49
|
+
requestId: string;
|
|
50
|
+
request: Request;
|
|
51
|
+
}, ReturnType = void, EventType extends string = string> extends TypedEvent<DataType, ReturnType, EventType> {
|
|
52
|
+
readonly error: Error;
|
|
53
|
+
readonly requestId: string;
|
|
54
|
+
readonly request: Request;
|
|
55
|
+
constructor(type: EventType, data: DataType);
|
|
56
|
+
}
|
|
57
|
+
type HttpNetworkFrameEventMap = {
|
|
58
|
+
'request:start': RequestEvent;
|
|
59
|
+
'request:match': RequestEvent;
|
|
60
|
+
'request:unhandled': RequestEvent;
|
|
61
|
+
'request:end': RequestEvent;
|
|
62
|
+
'response:mocked': ResponseEvent;
|
|
63
|
+
'response:bypass': ResponseEvent;
|
|
64
|
+
unhandledException: UnhandledExceptionEvent;
|
|
65
|
+
};
|
|
66
|
+
declare abstract class HttpNetworkFrame extends NetworkFrame<'http', {
|
|
67
|
+
id: string;
|
|
68
|
+
request: Request;
|
|
69
|
+
}, HttpNetworkFrameEventMap> {
|
|
70
|
+
constructor(options: HttpNetworkFrameOptions);
|
|
71
|
+
getHandlers(controller: HandlersController): Array<AnyHandler>;
|
|
72
|
+
abstract respondWith(response?: Response): void;
|
|
73
|
+
getUnhandledMessage(): Promise<string>;
|
|
74
|
+
resolve(handlers: Array<RequestHandler>, onUnhandledFrame: UnhandledFrameHandle, resolutionContext?: NetworkFrameResolutionContext): Promise<boolean | null>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { HttpNetworkFrame, type HttpNetworkFrameEventMap, RequestEvent, ResponseEvent, UnhandledExceptionEvent };
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var http_frame_exports = {};
|
|
20
|
+
__export(http_frame_exports, {
|
|
21
|
+
HttpNetworkFrame: () => HttpNetworkFrame,
|
|
22
|
+
RequestEvent: () => RequestEvent,
|
|
23
|
+
ResponseEvent: () => ResponseEvent,
|
|
24
|
+
UnhandledExceptionEvent: () => UnhandledExceptionEvent
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(http_frame_exports);
|
|
27
|
+
var import_rettime = require("rettime");
|
|
28
|
+
var import_until_async = require("until-async");
|
|
29
|
+
var import_interceptors = require("@mswjs/interceptors");
|
|
30
|
+
var import_network_frame = require("./network-frame");
|
|
31
|
+
var import_toPublicUrl = require("../../utils/request/toPublicUrl");
|
|
32
|
+
var import_executeHandlers = require("../../utils/executeHandlers");
|
|
33
|
+
var import_storeResponseCookies = require("../../utils/request/storeResponseCookies");
|
|
34
|
+
var import_request_utils = require("../request-utils");
|
|
35
|
+
var import_devUtils = require("../../utils/internal/devUtils");
|
|
36
|
+
var import_on_unhandled_frame = require("../on-unhandled-frame");
|
|
37
|
+
class RequestEvent extends import_rettime.TypedEvent {
|
|
38
|
+
requestId;
|
|
39
|
+
request;
|
|
40
|
+
constructor(type, data) {
|
|
41
|
+
super(...[type, {}]);
|
|
42
|
+
this.requestId = data.requestId;
|
|
43
|
+
this.request = data.request;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class ResponseEvent extends import_rettime.TypedEvent {
|
|
47
|
+
requestId;
|
|
48
|
+
request;
|
|
49
|
+
response;
|
|
50
|
+
constructor(type, data) {
|
|
51
|
+
super(...[type, {}]);
|
|
52
|
+
this.requestId = data.requestId;
|
|
53
|
+
this.request = data.request;
|
|
54
|
+
this.response = data.response;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
class UnhandledExceptionEvent extends import_rettime.TypedEvent {
|
|
58
|
+
error;
|
|
59
|
+
requestId;
|
|
60
|
+
request;
|
|
61
|
+
constructor(type, data) {
|
|
62
|
+
super(...[type, {}]);
|
|
63
|
+
this.error = data.error;
|
|
64
|
+
this.requestId = data.requestId;
|
|
65
|
+
this.request = data.request;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class HttpNetworkFrame extends import_network_frame.NetworkFrame {
|
|
69
|
+
constructor(options) {
|
|
70
|
+
const id = options.id || (0, import_interceptors.createRequestId)();
|
|
71
|
+
super("http", { id, request: options.request });
|
|
72
|
+
}
|
|
73
|
+
getHandlers(controller) {
|
|
74
|
+
return controller.getHandlersByKind("request");
|
|
75
|
+
}
|
|
76
|
+
async getUnhandledMessage() {
|
|
77
|
+
const { request } = this.data;
|
|
78
|
+
const url = new URL(request.url);
|
|
79
|
+
const publicUrl = (0, import_toPublicUrl.toPublicUrl)(url) + url.search;
|
|
80
|
+
const requestBody = request.body == null ? null : await request.clone().text();
|
|
81
|
+
const details = `
|
|
82
|
+
|
|
83
|
+
\u2022 ${request.method} ${publicUrl}
|
|
84
|
+
|
|
85
|
+
${requestBody ? ` \u2022 Request body: ${requestBody}
|
|
86
|
+
|
|
87
|
+
` : ""}`;
|
|
88
|
+
const message = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
89
|
+
Read more: https://mswjs.io/docs/http/intercepting-requests`;
|
|
90
|
+
return message;
|
|
91
|
+
}
|
|
92
|
+
async resolve(handlers, onUnhandledFrame, resolutionContext) {
|
|
93
|
+
const { id: requestId, request } = this.data;
|
|
94
|
+
const requestCloneForLogs = resolutionContext?.quiet ? null : request.clone();
|
|
95
|
+
this.events.emit(new RequestEvent("request:start", { requestId, request }));
|
|
96
|
+
if ((0, import_request_utils.shouldBypassRequest)(request)) {
|
|
97
|
+
this.events.emit(new RequestEvent("request:end", { requestId, request }));
|
|
98
|
+
this.passthrough();
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const [lookupError, lookupResult] = await (0, import_until_async.until)(() => {
|
|
102
|
+
return (0, import_executeHandlers.executeHandlers)({
|
|
103
|
+
requestId,
|
|
104
|
+
request,
|
|
105
|
+
handlers,
|
|
106
|
+
resolutionContext: {
|
|
107
|
+
baseUrl: resolutionContext?.baseUrl?.toString(),
|
|
108
|
+
quiet: resolutionContext?.quiet
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
if (lookupError != null) {
|
|
113
|
+
if (!this.events.emit(
|
|
114
|
+
new UnhandledExceptionEvent("unhandledException", {
|
|
115
|
+
error: lookupError,
|
|
116
|
+
requestId,
|
|
117
|
+
request
|
|
118
|
+
})
|
|
119
|
+
)) {
|
|
120
|
+
console.error(lookupError);
|
|
121
|
+
import_devUtils.devUtils.error(
|
|
122
|
+
'Encountered an unhandled exception during the handler lookup for "%s %s". Please see the original error above.',
|
|
123
|
+
request.method,
|
|
124
|
+
request.url
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
this.errorWith(lookupError);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
if (lookupResult == null) {
|
|
131
|
+
this.events.emit(
|
|
132
|
+
new RequestEvent("request:unhandled", {
|
|
133
|
+
requestId,
|
|
134
|
+
request
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
await (0, import_on_unhandled_frame.executeUnhandledFrameHandle)(this, onUnhandledFrame).then(
|
|
138
|
+
() => this.passthrough(),
|
|
139
|
+
(error) => this.errorWith(error)
|
|
140
|
+
);
|
|
141
|
+
this.events.emit(
|
|
142
|
+
new RequestEvent("request:end", {
|
|
143
|
+
requestId,
|
|
144
|
+
request
|
|
145
|
+
})
|
|
146
|
+
);
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const { response, handler, parsedResult } = lookupResult;
|
|
150
|
+
this.events.emit(
|
|
151
|
+
new RequestEvent("request:match", {
|
|
152
|
+
requestId,
|
|
153
|
+
request
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
if (response == null) {
|
|
157
|
+
this.events.emit(
|
|
158
|
+
new RequestEvent("request:end", {
|
|
159
|
+
requestId,
|
|
160
|
+
request
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
this.passthrough();
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if ((0, import_request_utils.isPassthroughResponse)(response)) {
|
|
167
|
+
this.events.emit(
|
|
168
|
+
new RequestEvent("request:end", {
|
|
169
|
+
requestId,
|
|
170
|
+
request
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
this.passthrough();
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
await (0, import_storeResponseCookies.storeResponseCookies)(request, response);
|
|
177
|
+
this.respondWith(response.clone());
|
|
178
|
+
this.events.emit(
|
|
179
|
+
new RequestEvent("request:end", {
|
|
180
|
+
requestId,
|
|
181
|
+
request
|
|
182
|
+
})
|
|
183
|
+
);
|
|
184
|
+
if (!resolutionContext?.quiet) {
|
|
185
|
+
handler.log({
|
|
186
|
+
request: requestCloneForLogs,
|
|
187
|
+
response,
|
|
188
|
+
parsedResult
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=http-frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/experimental/frames/http-frame.ts"],"sourcesContent":["import { TypedEvent } from 'rettime'\nimport { until } from 'until-async'\nimport { createRequestId } from '@mswjs/interceptors'\nimport { NetworkFrame, NetworkFrameResolutionContext } from './network-frame'\nimport { toPublicUrl } from '../../utils/request/toPublicUrl'\nimport { executeHandlers } from '../../utils/executeHandlers'\nimport { storeResponseCookies } from '../../utils/request/storeResponseCookies'\nimport { isPassthroughResponse, shouldBypassRequest } from '../request-utils'\nimport { devUtils } from '../../utils/internal/devUtils'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameHandle,\n} from '../on-unhandled-frame'\nimport { HandlersController, AnyHandler } from '../handlers-controller'\nimport { type RequestHandler } from '../../handlers/RequestHandler'\n\ninterface HttpNetworkFrameOptions {\n id?: string\n request: Request\n}\n\nexport class RequestEvent<\n DataType extends { requestId: string; request: Request } = {\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport class ResponseEvent<\n DataType extends {\n requestId: string\n request: Request\n response: Response\n } = {\n requestId: string\n request: Request\n response: Response\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n public readonly response: Response\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n this.response = data.response\n }\n}\n\nexport class UnhandledExceptionEvent<\n DataType extends {\n error: Error\n requestId: string\n request: Request\n } = {\n error: Error\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly error: Error\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.error = data.error\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport type HttpNetworkFrameEventMap = {\n 'request:start': RequestEvent\n 'request:match': RequestEvent\n 'request:unhandled': RequestEvent\n 'request:end': RequestEvent\n 'response:mocked': ResponseEvent\n 'response:bypass': ResponseEvent\n unhandledException: UnhandledExceptionEvent\n}\n\nexport abstract class HttpNetworkFrame extends NetworkFrame<\n 'http',\n {\n id: string\n request: Request\n },\n HttpNetworkFrameEventMap\n> {\n constructor(options: HttpNetworkFrameOptions) {\n const id = options.id || createRequestId()\n super('http', { id, request: options.request })\n }\n\n public getHandlers(controller: HandlersController): Array<AnyHandler> {\n return controller.getHandlersByKind('request')\n }\n\n public abstract respondWith(response?: Response): void\n\n public async getUnhandledMessage(): Promise<string> {\n const { request } = this.data\n\n const url = new URL(request.url)\n const publicUrl = toPublicUrl(url) + url.search\n const requestBody =\n request.body == null ? null : await request.clone().text()\n\n const details = `\\n\\n \\u2022 ${request.method} ${publicUrl}\\n\\n${requestBody ? ` \\u2022 Request body: ${requestBody}\\n\\n` : ''}`\n const message = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.\\nRead more: https://mswjs.io/docs/http/intercepting-requests`\n\n return message\n }\n\n public async resolve(\n handlers: Array<RequestHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null> {\n const { id: requestId, request } = this.data\n const requestCloneForLogs = resolutionContext?.quiet\n ? null\n : request.clone()\n\n this.events.emit(new RequestEvent('request:start', { requestId, request }))\n\n // Requests wrapped in explicit \"bypass(request)\".\n if (shouldBypassRequest(request)) {\n this.events.emit(new RequestEvent('request:end', { requestId, request }))\n this.passthrough()\n return null\n }\n\n const [lookupError, lookupResult] = await until(() => {\n return executeHandlers({\n requestId,\n request,\n handlers,\n resolutionContext: {\n baseUrl: resolutionContext?.baseUrl?.toString(),\n quiet: resolutionContext?.quiet,\n },\n })\n })\n\n if (lookupError != null) {\n if (\n !this.events.emit(\n new UnhandledExceptionEvent('unhandledException', {\n error: lookupError,\n requestId,\n request,\n }),\n )\n ) {\n // Surface the error to the developer since they haven't handled it.\n console.error(lookupError)\n devUtils.error(\n 'Encountered an unhandled exception during the handler lookup for \"%s %s\". Please see the original error above.',\n request.method,\n request.url,\n )\n }\n\n this.errorWith(lookupError)\n return null\n }\n\n // No matching handlers.\n if (lookupResult == null) {\n this.events.emit(\n new RequestEvent('request:unhandled', {\n requestId,\n request,\n }),\n )\n\n /**\n * @note The unhandled frame handle must be executed during the request resolution\n * since it can influence it (e.g. error the request if the \"error\" startegy was used).\n */\n await executeUnhandledFrameHandle(this, onUnhandledFrame).then(\n () => this.passthrough(),\n (error) => this.errorWith(error),\n )\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n return false\n }\n\n const { response, handler, parsedResult } = lookupResult\n\n this.events.emit(\n new RequestEvent('request:match', {\n requestId,\n request,\n }),\n )\n\n // Handlers that returned no mocked response.\n if (response == null) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n // Handlers that returned explicit `passthrough()`.\n if (isPassthroughResponse(response)) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n await storeResponseCookies(request, response)\n\n this.respondWith(response.clone())\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n if (!resolutionContext?.quiet) {\n handler.log({\n request: requestCloneForLogs!,\n response,\n parsedResult,\n })\n }\n\n return true\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA2B;AAC3B,yBAAsB;AACtB,0BAAgC;AAChC,2BAA4D;AAC5D,yBAA4B;AAC5B,6BAAgC;AAChC,kCAAqC;AACrC,2BAA2D;AAC3D,sBAAyB;AACzB,gCAGO;AASA,MAAM,qBAOH,0BAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;AAEO,MAAM,sBAYH,0BAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AACpB,SAAK,WAAW,KAAK;AAAA,EACvB;AACF;AAEO,MAAM,gCAYH,0BAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,QAAQ,KAAK;AAClB,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;AAYO,MAAe,yBAAyB,kCAO7C;AAAA,EACA,YAAY,SAAkC;AAC5C,UAAM,KAAK,QAAQ,UAAM,qCAAgB;AACzC,UAAM,QAAQ,EAAE,IAAI,SAAS,QAAQ,QAAQ,CAAC;AAAA,EAChD;AAAA,EAEO,YAAY,YAAmD;AACpE,WAAO,WAAW,kBAAkB,SAAS;AAAA,EAC/C;AA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MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { TypedEvent } from "rettime";
|
|
2
|
+
import { until } from "until-async";
|
|
3
|
+
import { createRequestId } from "@mswjs/interceptors";
|
|
4
|
+
import { NetworkFrame } from './network-frame.mjs';
|
|
5
|
+
import { toPublicUrl } from '../../utils/request/toPublicUrl.mjs';
|
|
6
|
+
import { executeHandlers } from '../../utils/executeHandlers.mjs';
|
|
7
|
+
import { storeResponseCookies } from '../../utils/request/storeResponseCookies.mjs';
|
|
8
|
+
import { isPassthroughResponse, shouldBypassRequest } from '../request-utils.mjs';
|
|
9
|
+
import { devUtils } from '../../utils/internal/devUtils.mjs';
|
|
10
|
+
import {
|
|
11
|
+
executeUnhandledFrameHandle
|
|
12
|
+
} from '../on-unhandled-frame.mjs';
|
|
13
|
+
class RequestEvent extends TypedEvent {
|
|
14
|
+
requestId;
|
|
15
|
+
request;
|
|
16
|
+
constructor(type, data) {
|
|
17
|
+
super(...[type, {}]);
|
|
18
|
+
this.requestId = data.requestId;
|
|
19
|
+
this.request = data.request;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class ResponseEvent extends TypedEvent {
|
|
23
|
+
requestId;
|
|
24
|
+
request;
|
|
25
|
+
response;
|
|
26
|
+
constructor(type, data) {
|
|
27
|
+
super(...[type, {}]);
|
|
28
|
+
this.requestId = data.requestId;
|
|
29
|
+
this.request = data.request;
|
|
30
|
+
this.response = data.response;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
class UnhandledExceptionEvent extends TypedEvent {
|
|
34
|
+
error;
|
|
35
|
+
requestId;
|
|
36
|
+
request;
|
|
37
|
+
constructor(type, data) {
|
|
38
|
+
super(...[type, {}]);
|
|
39
|
+
this.error = data.error;
|
|
40
|
+
this.requestId = data.requestId;
|
|
41
|
+
this.request = data.request;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class HttpNetworkFrame extends NetworkFrame {
|
|
45
|
+
constructor(options) {
|
|
46
|
+
const id = options.id || createRequestId();
|
|
47
|
+
super("http", { id, request: options.request });
|
|
48
|
+
}
|
|
49
|
+
getHandlers(controller) {
|
|
50
|
+
return controller.getHandlersByKind("request");
|
|
51
|
+
}
|
|
52
|
+
async getUnhandledMessage() {
|
|
53
|
+
const { request } = this.data;
|
|
54
|
+
const url = new URL(request.url);
|
|
55
|
+
const publicUrl = toPublicUrl(url) + url.search;
|
|
56
|
+
const requestBody = request.body == null ? null : await request.clone().text();
|
|
57
|
+
const details = `
|
|
58
|
+
|
|
59
|
+
\u2022 ${request.method} ${publicUrl}
|
|
60
|
+
|
|
61
|
+
${requestBody ? ` \u2022 Request body: ${requestBody}
|
|
62
|
+
|
|
63
|
+
` : ""}`;
|
|
64
|
+
const message = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.
|
|
65
|
+
Read more: https://mswjs.io/docs/http/intercepting-requests`;
|
|
66
|
+
return message;
|
|
67
|
+
}
|
|
68
|
+
async resolve(handlers, onUnhandledFrame, resolutionContext) {
|
|
69
|
+
const { id: requestId, request } = this.data;
|
|
70
|
+
const requestCloneForLogs = resolutionContext?.quiet ? null : request.clone();
|
|
71
|
+
this.events.emit(new RequestEvent("request:start", { requestId, request }));
|
|
72
|
+
if (shouldBypassRequest(request)) {
|
|
73
|
+
this.events.emit(new RequestEvent("request:end", { requestId, request }));
|
|
74
|
+
this.passthrough();
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const [lookupError, lookupResult] = await until(() => {
|
|
78
|
+
return executeHandlers({
|
|
79
|
+
requestId,
|
|
80
|
+
request,
|
|
81
|
+
handlers,
|
|
82
|
+
resolutionContext: {
|
|
83
|
+
baseUrl: resolutionContext?.baseUrl?.toString(),
|
|
84
|
+
quiet: resolutionContext?.quiet
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
if (lookupError != null) {
|
|
89
|
+
if (!this.events.emit(
|
|
90
|
+
new UnhandledExceptionEvent("unhandledException", {
|
|
91
|
+
error: lookupError,
|
|
92
|
+
requestId,
|
|
93
|
+
request
|
|
94
|
+
})
|
|
95
|
+
)) {
|
|
96
|
+
console.error(lookupError);
|
|
97
|
+
devUtils.error(
|
|
98
|
+
'Encountered an unhandled exception during the handler lookup for "%s %s". Please see the original error above.',
|
|
99
|
+
request.method,
|
|
100
|
+
request.url
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
this.errorWith(lookupError);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
if (lookupResult == null) {
|
|
107
|
+
this.events.emit(
|
|
108
|
+
new RequestEvent("request:unhandled", {
|
|
109
|
+
requestId,
|
|
110
|
+
request
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
await executeUnhandledFrameHandle(this, onUnhandledFrame).then(
|
|
114
|
+
() => this.passthrough(),
|
|
115
|
+
(error) => this.errorWith(error)
|
|
116
|
+
);
|
|
117
|
+
this.events.emit(
|
|
118
|
+
new RequestEvent("request:end", {
|
|
119
|
+
requestId,
|
|
120
|
+
request
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
const { response, handler, parsedResult } = lookupResult;
|
|
126
|
+
this.events.emit(
|
|
127
|
+
new RequestEvent("request:match", {
|
|
128
|
+
requestId,
|
|
129
|
+
request
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
if (response == null) {
|
|
133
|
+
this.events.emit(
|
|
134
|
+
new RequestEvent("request:end", {
|
|
135
|
+
requestId,
|
|
136
|
+
request
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
this.passthrough();
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (isPassthroughResponse(response)) {
|
|
143
|
+
this.events.emit(
|
|
144
|
+
new RequestEvent("request:end", {
|
|
145
|
+
requestId,
|
|
146
|
+
request
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
this.passthrough();
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
await storeResponseCookies(request, response);
|
|
153
|
+
this.respondWith(response.clone());
|
|
154
|
+
this.events.emit(
|
|
155
|
+
new RequestEvent("request:end", {
|
|
156
|
+
requestId,
|
|
157
|
+
request
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
if (!resolutionContext?.quiet) {
|
|
161
|
+
handler.log({
|
|
162
|
+
request: requestCloneForLogs,
|
|
163
|
+
response,
|
|
164
|
+
parsedResult
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
HttpNetworkFrame,
|
|
172
|
+
RequestEvent,
|
|
173
|
+
ResponseEvent,
|
|
174
|
+
UnhandledExceptionEvent
|
|
175
|
+
};
|
|
176
|
+
//# sourceMappingURL=http-frame.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/experimental/frames/http-frame.ts"],"sourcesContent":["import { TypedEvent } from 'rettime'\nimport { until } from 'until-async'\nimport { createRequestId } from '@mswjs/interceptors'\nimport { NetworkFrame, NetworkFrameResolutionContext } from './network-frame'\nimport { toPublicUrl } from '../../utils/request/toPublicUrl'\nimport { executeHandlers } from '../../utils/executeHandlers'\nimport { storeResponseCookies } from '../../utils/request/storeResponseCookies'\nimport { isPassthroughResponse, shouldBypassRequest } from '../request-utils'\nimport { devUtils } from '../../utils/internal/devUtils'\nimport {\n executeUnhandledFrameHandle,\n type UnhandledFrameHandle,\n} from '../on-unhandled-frame'\nimport { HandlersController, AnyHandler } from '../handlers-controller'\nimport { type RequestHandler } from '../../handlers/RequestHandler'\n\ninterface HttpNetworkFrameOptions {\n id?: string\n request: Request\n}\n\nexport class RequestEvent<\n DataType extends { requestId: string; request: Request } = {\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport class ResponseEvent<\n DataType extends {\n requestId: string\n request: Request\n response: Response\n } = {\n requestId: string\n request: Request\n response: Response\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly requestId: string\n public readonly request: Request\n public readonly response: Response\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.requestId = data.requestId\n this.request = data.request\n this.response = data.response\n }\n}\n\nexport class UnhandledExceptionEvent<\n DataType extends {\n error: Error\n requestId: string\n request: Request\n } = {\n error: Error\n requestId: string\n request: Request\n },\n ReturnType = void,\n EventType extends string = string,\n> extends TypedEvent<DataType, ReturnType, EventType> {\n public readonly error: Error\n public readonly requestId: string\n public readonly request: Request\n\n constructor(type: EventType, data: DataType) {\n super(...([type, {}] as any))\n this.error = data.error\n this.requestId = data.requestId\n this.request = data.request\n }\n}\n\nexport type HttpNetworkFrameEventMap = {\n 'request:start': RequestEvent\n 'request:match': RequestEvent\n 'request:unhandled': RequestEvent\n 'request:end': RequestEvent\n 'response:mocked': ResponseEvent\n 'response:bypass': ResponseEvent\n unhandledException: UnhandledExceptionEvent\n}\n\nexport abstract class HttpNetworkFrame extends NetworkFrame<\n 'http',\n {\n id: string\n request: Request\n },\n HttpNetworkFrameEventMap\n> {\n constructor(options: HttpNetworkFrameOptions) {\n const id = options.id || createRequestId()\n super('http', { id, request: options.request })\n }\n\n public getHandlers(controller: HandlersController): Array<AnyHandler> {\n return controller.getHandlersByKind('request')\n }\n\n public abstract respondWith(response?: Response): void\n\n public async getUnhandledMessage(): Promise<string> {\n const { request } = this.data\n\n const url = new URL(request.url)\n const publicUrl = toPublicUrl(url) + url.search\n const requestBody =\n request.body == null ? null : await request.clone().text()\n\n const details = `\\n\\n \\u2022 ${request.method} ${publicUrl}\\n\\n${requestBody ? ` \\u2022 Request body: ${requestBody}\\n\\n` : ''}`\n const message = `intercepted a request without a matching request handler:${details}If you still wish to intercept this unhandled request, please create a request handler for it.\\nRead more: https://mswjs.io/docs/http/intercepting-requests`\n\n return message\n }\n\n public async resolve(\n handlers: Array<RequestHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null> {\n const { id: requestId, request } = this.data\n const requestCloneForLogs = resolutionContext?.quiet\n ? null\n : request.clone()\n\n this.events.emit(new RequestEvent('request:start', { requestId, request }))\n\n // Requests wrapped in explicit \"bypass(request)\".\n if (shouldBypassRequest(request)) {\n this.events.emit(new RequestEvent('request:end', { requestId, request }))\n this.passthrough()\n return null\n }\n\n const [lookupError, lookupResult] = await until(() => {\n return executeHandlers({\n requestId,\n request,\n handlers,\n resolutionContext: {\n baseUrl: resolutionContext?.baseUrl?.toString(),\n quiet: resolutionContext?.quiet,\n },\n })\n })\n\n if (lookupError != null) {\n if (\n !this.events.emit(\n new UnhandledExceptionEvent('unhandledException', {\n error: lookupError,\n requestId,\n request,\n }),\n )\n ) {\n // Surface the error to the developer since they haven't handled it.\n console.error(lookupError)\n devUtils.error(\n 'Encountered an unhandled exception during the handler lookup for \"%s %s\". Please see the original error above.',\n request.method,\n request.url,\n )\n }\n\n this.errorWith(lookupError)\n return null\n }\n\n // No matching handlers.\n if (lookupResult == null) {\n this.events.emit(\n new RequestEvent('request:unhandled', {\n requestId,\n request,\n }),\n )\n\n /**\n * @note The unhandled frame handle must be executed during the request resolution\n * since it can influence it (e.g. error the request if the \"error\" startegy was used).\n */\n await executeUnhandledFrameHandle(this, onUnhandledFrame).then(\n () => this.passthrough(),\n (error) => this.errorWith(error),\n )\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n return false\n }\n\n const { response, handler, parsedResult } = lookupResult\n\n this.events.emit(\n new RequestEvent('request:match', {\n requestId,\n request,\n }),\n )\n\n // Handlers that returned no mocked response.\n if (response == null) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n // Handlers that returned explicit `passthrough()`.\n if (isPassthroughResponse(response)) {\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n this.passthrough()\n return null\n }\n\n await storeResponseCookies(request, response)\n\n this.respondWith(response.clone())\n\n this.events.emit(\n new RequestEvent('request:end', {\n requestId,\n request,\n }),\n )\n\n if (!resolutionContext?.quiet) {\n handler.log({\n request: requestCloneForLogs!,\n response,\n parsedResult,\n })\n }\n\n return true\n }\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,uBAAuB;AAChC,SAAS,oBAAmD;AAC5D,SAAS,mBAAmB;AAC5B,SAAS,uBAAuB;AAChC,SAAS,4BAA4B;AACrC,SAAS,uBAAuB,2BAA2B;AAC3D,SAAS,gBAAgB;AACzB;AAAA,EACE;AAAA,OAEK;AASA,MAAM,qBAOH,WAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AAAA,EACtB;AACF;AAEO,MAAM,sBAYH,WAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,YAAY,KAAK;AACtB,SAAK,UAAU,KAAK;AACpB,SAAK,WAAW,KAAK;AAAA,EACvB;AACF;AAEO,MAAM,gCAYH,WAA4C;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EAEhB,YAAY,MAAiB,MAAgB;AAC3C,UAAM,GAAI,CAAC,MAAM,CAAC,CAAC,CAAS;AAC5B,SAAK,QAAQ,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AK,YAAY;AACjB,aAAO;AAAA,IACT;AAEA,UAAM,qBAAqB,SAAS,QAAQ;AAE5C,SAAK,YAAY,SAAS,MAAM,CAAC;AAEjC,SAAK,OAAO;AAAA,MACV,IAAI,aAAa,eAAe;AAAA,QAC9B;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,CAAC,mBAAmB,OAAO;AAC7B,cAAQ,IAAI;AAAA,QACV,SAAS;AAAA,QACT;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'rettime';
|
|
2
|
+
import '../handlers-controller.mjs';
|
|
3
|
+
export { A as AnyNetworkFrame, E as ExtractFrameEvents, N as NetworkFrame, a as NetworkFrameResolutionContext } from '../../network-frame-B7A0ggXE.mjs';
|
|
4
|
+
import '../../HttpResponse-DlRR1D-f.mjs';
|
|
5
|
+
import '@mswjs/interceptors';
|
|
6
|
+
import '../../utils/internal/isIterable.mjs';
|
|
7
|
+
import '../../typeUtils.mjs';
|
|
8
|
+
import 'graphql';
|
|
9
|
+
import '../../utils/matching/matchRequestUrl.mjs';
|
|
10
|
+
import '../../handlers/WebSocketHandler.mjs';
|
|
11
|
+
import 'strict-event-emitter';
|
|
12
|
+
import '@mswjs/interceptors/WebSocket';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'rettime';
|
|
2
|
+
import '../handlers-controller.js';
|
|
3
|
+
export { A as AnyNetworkFrame, E as ExtractFrameEvents, N as NetworkFrame, a as NetworkFrameResolutionContext } from '../../network-frame-usYiHS0K.js';
|
|
4
|
+
import '../../HttpResponse-CksOMVAa.js';
|
|
5
|
+
import '@mswjs/interceptors';
|
|
6
|
+
import '../../utils/internal/isIterable.js';
|
|
7
|
+
import '../../typeUtils.js';
|
|
8
|
+
import 'graphql';
|
|
9
|
+
import '../../utils/matching/matchRequestUrl.js';
|
|
10
|
+
import '../../handlers/WebSocketHandler.js';
|
|
11
|
+
import 'strict-event-emitter';
|
|
12
|
+
import '@mswjs/interceptors/WebSocket';
|
|
@@ -3,6 +3,10 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
6
10
|
var __copyProps = (to, from, except, desc) => {
|
|
7
11
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
12
|
for (let key of __getOwnPropNames(from))
|
|
@@ -12,6 +16,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
16
|
return to;
|
|
13
17
|
};
|
|
14
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
var network_frame_exports = {};
|
|
20
|
+
__export(network_frame_exports, {
|
|
21
|
+
NetworkFrame: () => NetworkFrame
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(network_frame_exports);
|
|
24
|
+
var import_rettime = require("rettime");
|
|
25
|
+
class NetworkFrame {
|
|
26
|
+
constructor(protocol, data) {
|
|
27
|
+
this.protocol = protocol;
|
|
28
|
+
this.data = data;
|
|
29
|
+
this.events = new import_rettime.Emitter();
|
|
30
|
+
}
|
|
31
|
+
events;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=network-frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/experimental/frames/network-frame.ts"],"sourcesContent":["import { Emitter, type DefaultEventMap } from 'rettime'\nimport type { AnyHandler, HandlersController } from '../handlers-controller'\nimport type { UnhandledFrameHandle } from '../on-unhandled-frame'\n\nexport type AnyNetworkFrame = NetworkFrame<string, unknown, any>\n\nexport type ExtractFrameEvents<Frame> =\n Frame extends NetworkFrame<any, any, infer Events> ? Events : never\n\nexport interface NetworkFrameResolutionContext {\n baseUrl?: string | URL\n quiet?: boolean\n}\n\n/**\n * The base for the network frames. Extend this abstract class\n * to implement custom network frames.\n */\nexport abstract class NetworkFrame<\n Protocol extends string,\n Data,\n Events extends DefaultEventMap,\n> {\n public events: Emitter<Events>\n\n constructor(\n public readonly protocol: Protocol,\n public readonly data: Data,\n ) {\n this.events = new Emitter()\n }\n\n public abstract getHandlers(controller: HandlersController): Array<AnyHandler>\n\n /**\n * Resolve the current frame against the given list of handlers.\n * Optionally, use a custom resolution context to control behaviors\n * like `baseUrl`.\n *\n * Returns `true` if the frame was handled, `false` if it wasn't, and `null`\n * if its handling was skipped (e.g. the frame was bypassed).\n */\n public abstract resolve(\n handlers: Array<AnyHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null>\n\n /**\n * Perform this network frame as-is.\n */\n public abstract passthrough(): void\n\n /**\n * Error the underling network frame.\n * @param reason The reason for the error.\n */\n public abstract errorWith(reason?: unknown): void\n\n /**\n * Get a message to be used when this frame is unhandled.\n */\n public abstract getUnhandledMessage(): Promise<string>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8C;AAkBvC,MAAe,aAIpB;AAAA,EAGA,YACkB,UACA,MAChB;AAFgB;AACA;AAEhB,SAAK,SAAS,IAAI,uBAAQ;AAAA,EAC5B;AAAA,EAPO;AAwCT;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Emitter } from "rettime";
|
|
2
|
+
class NetworkFrame {
|
|
3
|
+
constructor(protocol, data) {
|
|
4
|
+
this.protocol = protocol;
|
|
5
|
+
this.data = data;
|
|
6
|
+
this.events = new Emitter();
|
|
7
|
+
}
|
|
8
|
+
events;
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
NetworkFrame
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=network-frame.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/core/experimental/frames/network-frame.ts"],"sourcesContent":["import { Emitter, type DefaultEventMap } from 'rettime'\nimport type { AnyHandler, HandlersController } from '../handlers-controller'\nimport type { UnhandledFrameHandle } from '../on-unhandled-frame'\n\nexport type AnyNetworkFrame = NetworkFrame<string, unknown, any>\n\nexport type ExtractFrameEvents<Frame> =\n Frame extends NetworkFrame<any, any, infer Events> ? Events : never\n\nexport interface NetworkFrameResolutionContext {\n baseUrl?: string | URL\n quiet?: boolean\n}\n\n/**\n * The base for the network frames. Extend this abstract class\n * to implement custom network frames.\n */\nexport abstract class NetworkFrame<\n Protocol extends string,\n Data,\n Events extends DefaultEventMap,\n> {\n public events: Emitter<Events>\n\n constructor(\n public readonly protocol: Protocol,\n public readonly data: Data,\n ) {\n this.events = new Emitter()\n }\n\n public abstract getHandlers(controller: HandlersController): Array<AnyHandler>\n\n /**\n * Resolve the current frame against the given list of handlers.\n * Optionally, use a custom resolution context to control behaviors\n * like `baseUrl`.\n *\n * Returns `true` if the frame was handled, `false` if it wasn't, and `null`\n * if its handling was skipped (e.g. the frame was bypassed).\n */\n public abstract resolve(\n handlers: Array<AnyHandler>,\n onUnhandledFrame: UnhandledFrameHandle,\n resolutionContext?: NetworkFrameResolutionContext,\n ): Promise<boolean | null>\n\n /**\n * Perform this network frame as-is.\n */\n public abstract passthrough(): void\n\n /**\n * Error the underling network frame.\n * @param reason The reason for the error.\n */\n public abstract errorWith(reason?: unknown): void\n\n /**\n * Get a message to be used when this frame is unhandled.\n */\n public abstract getUnhandledMessage(): Promise<string>\n}\n"],"mappings":"AAAA,SAAS,eAAqC;AAkBvC,MAAe,aAIpB;AAAA,EAGA,YACkB,UACA,MAChB;AAFgB;AACA;AAEhB,SAAK,SAAS,IAAI,QAAQ;AAAA,EAC5B;AAAA,EAPO;AAwCT;","names":[]}
|