@depup/msw 2.12.13-depup.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/LICENSE.md +21 -0
- package/README.md +40 -0
- package/browser/package.json +31 -0
- package/changes.json +46 -0
- package/cli/index.js +35 -0
- package/cli/init.js +226 -0
- package/cli/invariant.js +9 -0
- package/cli/package.json +3 -0
- package/config/constants.js +13 -0
- package/config/package.json +3 -0
- package/config/scripts/postinstall.js +36 -0
- package/lib/browser/index.d.mts +102 -0
- package/lib/browser/index.d.ts +102 -0
- package/lib/browser/index.js +2911 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/index.mjs +2888 -0
- package/lib/browser/index.mjs.map +1 -0
- package/lib/core/HttpResponse-Be4eT3x6.d.mts +338 -0
- package/lib/core/HttpResponse-Dj6ibgFJ.d.ts +338 -0
- package/lib/core/HttpResponse.d.mts +6 -0
- package/lib/core/HttpResponse.d.ts +6 -0
- package/lib/core/HttpResponse.js +176 -0
- package/lib/core/HttpResponse.js.map +1 -0
- package/lib/core/HttpResponse.mjs +159 -0
- package/lib/core/HttpResponse.mjs.map +1 -0
- package/lib/core/SetupApi.d.mts +44 -0
- package/lib/core/SetupApi.d.ts +44 -0
- package/lib/core/SetupApi.js +112 -0
- package/lib/core/SetupApi.js.map +1 -0
- package/lib/core/SetupApi.mjs +92 -0
- package/lib/core/SetupApi.mjs.map +1 -0
- package/lib/core/bypass.d.mts +16 -0
- package/lib/core/bypass.d.ts +16 -0
- package/lib/core/bypass.js +42 -0
- package/lib/core/bypass.js.map +1 -0
- package/lib/core/bypass.mjs +22 -0
- package/lib/core/bypass.mjs.map +1 -0
- package/lib/core/delay.d.mts +18 -0
- package/lib/core/delay.d.ts +18 -0
- package/lib/core/delay.js +77 -0
- package/lib/core/delay.js.map +1 -0
- package/lib/core/delay.mjs +57 -0
- package/lib/core/delay.mjs.map +1 -0
- package/lib/core/getResponse.d.mts +18 -0
- package/lib/core/getResponse.d.ts +18 -0
- package/lib/core/getResponse.js +35 -0
- package/lib/core/getResponse.js.map +1 -0
- package/lib/core/getResponse.mjs +17 -0
- package/lib/core/getResponse.mjs.map +1 -0
- package/lib/core/graphql.d.mts +76 -0
- package/lib/core/graphql.d.ts +76 -0
- package/lib/core/graphql.js +90 -0
- package/lib/core/graphql.js.map +1 -0
- package/lib/core/graphql.mjs +72 -0
- package/lib/core/graphql.mjs.map +1 -0
- package/lib/core/handlers/GraphQLHandler.d.mts +6 -0
- package/lib/core/handlers/GraphQLHandler.d.ts +6 -0
- package/lib/core/handlers/GraphQLHandler.js +231 -0
- package/lib/core/handlers/GraphQLHandler.js.map +1 -0
- package/lib/core/handlers/GraphQLHandler.mjs +218 -0
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -0
- package/lib/core/handlers/HttpHandler.d.mts +75 -0
- package/lib/core/handlers/HttpHandler.d.ts +75 -0
- package/lib/core/handlers/HttpHandler.js +128 -0
- package/lib/core/handlers/HttpHandler.js.map +1 -0
- package/lib/core/handlers/HttpHandler.mjs +112 -0
- package/lib/core/handlers/HttpHandler.mjs.map +1 -0
- package/lib/core/handlers/RequestHandler.d.mts +6 -0
- package/lib/core/handlers/RequestHandler.d.ts +6 -0
- package/lib/core/handlers/RequestHandler.js +173 -0
- package/lib/core/handlers/RequestHandler.js.map +1 -0
- package/lib/core/handlers/RequestHandler.mjs +155 -0
- package/lib/core/handlers/RequestHandler.mjs.map +1 -0
- package/lib/core/handlers/WebSocketHandler.d.mts +42 -0
- package/lib/core/handlers/WebSocketHandler.d.ts +42 -0
- package/lib/core/handlers/WebSocketHandler.js +147 -0
- package/lib/core/handlers/WebSocketHandler.js.map +1 -0
- package/lib/core/handlers/WebSocketHandler.mjs +129 -0
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -0
- package/lib/core/handlers/common.d.mts +3 -0
- package/lib/core/handlers/common.d.ts +3 -0
- package/lib/core/handlers/common.js +17 -0
- package/lib/core/handlers/common.js.map +1 -0
- package/lib/core/handlers/common.mjs +1 -0
- package/lib/core/handlers/common.mjs.map +1 -0
- package/lib/core/http.d.mts +31 -0
- package/lib/core/http.d.ts +31 -0
- package/lib/core/http.js +40 -0
- package/lib/core/http.js.map +1 -0
- package/lib/core/http.mjs +23 -0
- package/lib/core/http.mjs.map +1 -0
- package/lib/core/index.d.mts +32 -0
- package/lib/core/index.d.ts +32 -0
- package/lib/core/index.js +64 -0
- package/lib/core/index.js.map +1 -0
- package/lib/core/index.mjs +52 -0
- package/lib/core/index.mjs.map +1 -0
- package/lib/core/isCommonAssetRequest.d.mts +20 -0
- package/lib/core/isCommonAssetRequest.d.ts +20 -0
- package/lib/core/isCommonAssetRequest.js +42 -0
- package/lib/core/isCommonAssetRequest.js.map +1 -0
- package/lib/core/isCommonAssetRequest.mjs +22 -0
- package/lib/core/isCommonAssetRequest.mjs.map +1 -0
- package/lib/core/passthrough.d.mts +24 -0
- package/lib/core/passthrough.d.ts +24 -0
- package/lib/core/passthrough.js +33 -0
- package/lib/core/passthrough.js.map +1 -0
- package/lib/core/passthrough.mjs +13 -0
- package/lib/core/passthrough.mjs.map +1 -0
- package/lib/core/sharedOptions.d.mts +64 -0
- package/lib/core/sharedOptions.d.ts +64 -0
- package/lib/core/sharedOptions.js +17 -0
- package/lib/core/sharedOptions.js.map +1 -0
- package/lib/core/sharedOptions.mjs +1 -0
- package/lib/core/sharedOptions.mjs.map +1 -0
- package/lib/core/sse.d.mts +116 -0
- package/lib/core/sse.d.ts +116 -0
- package/lib/core/sse.js +607 -0
- package/lib/core/sse.js.map +1 -0
- package/lib/core/sse.mjs +589 -0
- package/lib/core/sse.mjs.map +1 -0
- package/lib/core/typeUtils.d.mts +12 -0
- package/lib/core/typeUtils.d.ts +12 -0
- package/lib/core/typeUtils.js +17 -0
- package/lib/core/typeUtils.js.map +1 -0
- package/lib/core/typeUtils.mjs +1 -0
- package/lib/core/typeUtils.mjs.map +1 -0
- package/lib/core/utils/HttpResponse/decorators.d.mts +17 -0
- package/lib/core/utils/HttpResponse/decorators.d.ts +17 -0
- package/lib/core/utils/HttpResponse/decorators.js +77 -0
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -0
- package/lib/core/utils/HttpResponse/decorators.mjs +47 -0
- package/lib/core/utils/HttpResponse/decorators.mjs.map +1 -0
- package/lib/core/utils/cookieStore.d.mts +13 -0
- package/lib/core/utils/cookieStore.d.ts +13 -0
- package/lib/core/utils/cookieStore.js +90 -0
- package/lib/core/utils/cookieStore.js.map +1 -0
- package/lib/core/utils/cookieStore.mjs +74 -0
- package/lib/core/utils/cookieStore.mjs.map +1 -0
- package/lib/core/utils/executeHandlers.d.mts +6 -0
- package/lib/core/utils/executeHandlers.d.ts +6 -0
- package/lib/core/utils/executeHandlers.js +50 -0
- package/lib/core/utils/executeHandlers.js.map +1 -0
- package/lib/core/utils/executeHandlers.mjs +30 -0
- package/lib/core/utils/executeHandlers.mjs.map +1 -0
- package/lib/core/utils/handleRequest.d.mts +29 -0
- package/lib/core/utils/handleRequest.d.ts +29 -0
- package/lib/core/utils/handleRequest.js +76 -0
- package/lib/core/utils/handleRequest.js.map +1 -0
- package/lib/core/utils/handleRequest.mjs +58 -0
- package/lib/core/utils/handleRequest.mjs.map +1 -0
- package/lib/core/utils/internal/Disposable.d.mts +7 -0
- package/lib/core/utils/internal/Disposable.d.ts +7 -0
- package/lib/core/utils/internal/Disposable.js +33 -0
- package/lib/core/utils/internal/Disposable.js.map +1 -0
- package/lib/core/utils/internal/Disposable.mjs +13 -0
- package/lib/core/utils/internal/Disposable.mjs.map +1 -0
- package/lib/core/utils/internal/checkGlobals.d.mts +3 -0
- package/lib/core/utils/internal/checkGlobals.d.ts +3 -0
- package/lib/core/utils/internal/checkGlobals.js +34 -0
- package/lib/core/utils/internal/checkGlobals.js.map +1 -0
- package/lib/core/utils/internal/checkGlobals.mjs +14 -0
- package/lib/core/utils/internal/checkGlobals.mjs.map +1 -0
- package/lib/core/utils/internal/devUtils.d.mts +28 -0
- package/lib/core/utils/internal/devUtils.d.ts +28 -0
- package/lib/core/utils/internal/devUtils.js +48 -0
- package/lib/core/utils/internal/devUtils.js.map +1 -0
- package/lib/core/utils/internal/devUtils.mjs +28 -0
- package/lib/core/utils/internal/devUtils.mjs.map +1 -0
- package/lib/core/utils/internal/getCallFrame.d.mts +6 -0
- package/lib/core/utils/internal/getCallFrame.d.ts +6 -0
- package/lib/core/utils/internal/getCallFrame.js +41 -0
- package/lib/core/utils/internal/getCallFrame.js.map +1 -0
- package/lib/core/utils/internal/getCallFrame.mjs +21 -0
- package/lib/core/utils/internal/getCallFrame.mjs.map +1 -0
- package/lib/core/utils/internal/hasRefCounted.d.mts +3 -0
- package/lib/core/utils/internal/hasRefCounted.d.ts +3 -0
- package/lib/core/utils/internal/hasRefCounted.js +27 -0
- package/lib/core/utils/internal/hasRefCounted.js.map +1 -0
- package/lib/core/utils/internal/hasRefCounted.mjs +7 -0
- package/lib/core/utils/internal/hasRefCounted.mjs.map +1 -0
- package/lib/core/utils/internal/isHandlerKind.d.mts +19 -0
- package/lib/core/utils/internal/isHandlerKind.d.ts +19 -0
- package/lib/core/utils/internal/isHandlerKind.js +29 -0
- package/lib/core/utils/internal/isHandlerKind.js.map +1 -0
- package/lib/core/utils/internal/isHandlerKind.mjs +9 -0
- package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -0
- package/lib/core/utils/internal/isIterable.d.mts +20 -0
- package/lib/core/utils/internal/isIterable.d.ts +20 -0
- package/lib/core/utils/internal/isIterable.js +30 -0
- package/lib/core/utils/internal/isIterable.js.map +1 -0
- package/lib/core/utils/internal/isIterable.mjs +10 -0
- package/lib/core/utils/internal/isIterable.mjs.map +1 -0
- package/lib/core/utils/internal/isObject.d.mts +6 -0
- package/lib/core/utils/internal/isObject.d.ts +6 -0
- package/lib/core/utils/internal/isObject.js +27 -0
- package/lib/core/utils/internal/isObject.js.map +1 -0
- package/lib/core/utils/internal/isObject.mjs +7 -0
- package/lib/core/utils/internal/isObject.mjs.map +1 -0
- package/lib/core/utils/internal/isStringEqual.d.mts +6 -0
- package/lib/core/utils/internal/isStringEqual.d.ts +6 -0
- package/lib/core/utils/internal/isStringEqual.js +27 -0
- package/lib/core/utils/internal/isStringEqual.js.map +1 -0
- package/lib/core/utils/internal/isStringEqual.mjs +7 -0
- package/lib/core/utils/internal/isStringEqual.mjs.map +1 -0
- package/lib/core/utils/internal/jsonParse.d.mts +7 -0
- package/lib/core/utils/internal/jsonParse.d.ts +7 -0
- package/lib/core/utils/internal/jsonParse.js +31 -0
- package/lib/core/utils/internal/jsonParse.js.map +1 -0
- package/lib/core/utils/internal/jsonParse.mjs +11 -0
- package/lib/core/utils/internal/jsonParse.mjs.map +1 -0
- package/lib/core/utils/internal/mergeRight.d.mts +7 -0
- package/lib/core/utils/internal/mergeRight.d.ts +7 -0
- package/lib/core/utils/internal/mergeRight.js +43 -0
- package/lib/core/utils/internal/mergeRight.js.map +1 -0
- package/lib/core/utils/internal/mergeRight.mjs +23 -0
- package/lib/core/utils/internal/mergeRight.mjs.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +6 -0
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +6 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js +146 -0
- package/lib/core/utils/internal/parseGraphQLRequest.js.map +1 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +129 -0
- package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +1 -0
- package/lib/core/utils/internal/parseMultipartData.d.mts +14 -0
- package/lib/core/utils/internal/parseMultipartData.d.ts +14 -0
- package/lib/core/utils/internal/parseMultipartData.js +83 -0
- package/lib/core/utils/internal/parseMultipartData.js.map +1 -0
- package/lib/core/utils/internal/parseMultipartData.mjs +63 -0
- package/lib/core/utils/internal/parseMultipartData.mjs.map +1 -0
- package/lib/core/utils/internal/pipeEvents.d.mts +8 -0
- package/lib/core/utils/internal/pipeEvents.d.ts +8 -0
- package/lib/core/utils/internal/pipeEvents.js +36 -0
- package/lib/core/utils/internal/pipeEvents.js.map +1 -0
- package/lib/core/utils/internal/pipeEvents.mjs +16 -0
- package/lib/core/utils/internal/pipeEvents.mjs.map +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +12 -0
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +12 -0
- package/lib/core/utils/internal/requestHandlerUtils.js +37 -0
- package/lib/core/utils/internal/requestHandlerUtils.js.map +1 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs +17 -0
- package/lib/core/utils/internal/requestHandlerUtils.mjs.map +1 -0
- package/lib/core/utils/internal/toReadonlyArray.d.mts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.d.ts +6 -0
- package/lib/core/utils/internal/toReadonlyArray.js +29 -0
- package/lib/core/utils/internal/toReadonlyArray.js.map +1 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs +9 -0
- package/lib/core/utils/internal/toReadonlyArray.mjs.map +1 -0
- package/lib/core/utils/internal/tryCatch.d.mts +3 -0
- package/lib/core/utils/internal/tryCatch.d.ts +3 -0
- package/lib/core/utils/internal/tryCatch.js +32 -0
- package/lib/core/utils/internal/tryCatch.js.map +1 -0
- package/lib/core/utils/internal/tryCatch.mjs +12 -0
- package/lib/core/utils/internal/tryCatch.mjs.map +1 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.mts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.d.ts +11 -0
- package/lib/core/utils/logging/getStatusCodeColor.js +40 -0
- package/lib/core/utils/logging/getStatusCodeColor.js.map +1 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs +20 -0
- package/lib/core/utils/logging/getStatusCodeColor.mjs.map +1 -0
- package/lib/core/utils/logging/getTimestamp.d.mts +9 -0
- package/lib/core/utils/logging/getTimestamp.d.ts +9 -0
- package/lib/core/utils/logging/getTimestamp.js +32 -0
- package/lib/core/utils/logging/getTimestamp.js.map +1 -0
- package/lib/core/utils/logging/getTimestamp.mjs +12 -0
- package/lib/core/utils/logging/getTimestamp.mjs.map +1 -0
- package/lib/core/utils/logging/serializeRequest.d.mts +12 -0
- package/lib/core/utils/logging/serializeRequest.d.ts +12 -0
- package/lib/core/utils/logging/serializeRequest.js +34 -0
- package/lib/core/utils/logging/serializeRequest.js.map +1 -0
- package/lib/core/utils/logging/serializeRequest.mjs +14 -0
- package/lib/core/utils/logging/serializeRequest.mjs.map +1 -0
- package/lib/core/utils/logging/serializeResponse.d.mts +9 -0
- package/lib/core/utils/logging/serializeResponse.d.ts +9 -0
- package/lib/core/utils/logging/serializeResponse.js +48 -0
- package/lib/core/utils/logging/serializeResponse.js.map +1 -0
- package/lib/core/utils/logging/serializeResponse.mjs +18 -0
- package/lib/core/utils/logging/serializeResponse.mjs.map +1 -0
- package/lib/core/utils/matching/matchRequestUrl.d.mts +20 -0
- package/lib/core/utils/matching/matchRequestUrl.d.ts +20 -0
- package/lib/core/utils/matching/matchRequestUrl.js +55 -0
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs +35 -0
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -0
- package/lib/core/utils/matching/normalizePath.d.mts +13 -0
- package/lib/core/utils/matching/normalizePath.d.ts +13 -0
- package/lib/core/utils/matching/normalizePath.js +33 -0
- package/lib/core/utils/matching/normalizePath.js.map +1 -0
- package/lib/core/utils/matching/normalizePath.mjs +13 -0
- package/lib/core/utils/matching/normalizePath.mjs.map +1 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.d.mts +14 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.d.ts +14 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.js +61 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.js.map +1 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs +41 -0
- package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs.map +1 -0
- package/lib/core/utils/request/getRequestCookies.d.mts +3 -0
- package/lib/core/utils/request/getRequestCookies.d.ts +3 -0
- package/lib/core/utils/request/getRequestCookies.js +79 -0
- package/lib/core/utils/request/getRequestCookies.js.map +1 -0
- package/lib/core/utils/request/getRequestCookies.mjs +62 -0
- package/lib/core/utils/request/getRequestCookies.mjs.map +1 -0
- package/lib/core/utils/request/onUnhandledRequest.d.mts +9 -0
- package/lib/core/utils/request/onUnhandledRequest.d.ts +9 -0
- package/lib/core/utils/request/onUnhandledRequest.js +76 -0
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs +56 -0
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -0
- package/lib/core/utils/request/storeResponseCookies.d.mts +3 -0
- package/lib/core/utils/request/storeResponseCookies.d.ts +3 -0
- package/lib/core/utils/request/storeResponseCookies.js +32 -0
- package/lib/core/utils/request/storeResponseCookies.js.map +1 -0
- package/lib/core/utils/request/storeResponseCookies.mjs +12 -0
- package/lib/core/utils/request/storeResponseCookies.mjs.map +1 -0
- package/lib/core/utils/request/toPublicUrl.d.mts +7 -0
- package/lib/core/utils/request/toPublicUrl.d.ts +7 -0
- package/lib/core/utils/request/toPublicUrl.js +31 -0
- package/lib/core/utils/request/toPublicUrl.js.map +1 -0
- package/lib/core/utils/request/toPublicUrl.mjs +11 -0
- package/lib/core/utils/request/toPublicUrl.mjs.map +1 -0
- package/lib/core/utils/toResponseInit.d.mts +3 -0
- package/lib/core/utils/toResponseInit.d.ts +3 -0
- package/lib/core/utils/toResponseInit.js +31 -0
- package/lib/core/utils/toResponseInit.js.map +1 -0
- package/lib/core/utils/toResponseInit.mjs +11 -0
- package/lib/core/utils/toResponseInit.mjs.map +1 -0
- package/lib/core/utils/url/cleanUrl.d.mts +7 -0
- package/lib/core/utils/url/cleanUrl.d.ts +7 -0
- package/lib/core/utils/url/cleanUrl.js +31 -0
- package/lib/core/utils/url/cleanUrl.js.map +1 -0
- package/lib/core/utils/url/cleanUrl.mjs +11 -0
- package/lib/core/utils/url/cleanUrl.mjs.map +1 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.mts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/getAbsoluteUrl.js +38 -0
- package/lib/core/utils/url/getAbsoluteUrl.js.map +1 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs +18 -0
- package/lib/core/utils/url/getAbsoluteUrl.mjs.map +1 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.mts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.d.ts +6 -0
- package/lib/core/utils/url/isAbsoluteUrl.js +27 -0
- package/lib/core/utils/url/isAbsoluteUrl.js.map +1 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs +7 -0
- package/lib/core/utils/url/isAbsoluteUrl.mjs.map +1 -0
- package/lib/core/ws/WebSocketClientManager.d.mts +65 -0
- package/lib/core/ws/WebSocketClientManager.d.ts +65 -0
- package/lib/core/ws/WebSocketClientManager.js +159 -0
- package/lib/core/ws/WebSocketClientManager.js.map +1 -0
- package/lib/core/ws/WebSocketClientManager.mjs +139 -0
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -0
- package/lib/core/ws/WebSocketClientStore.d.mts +13 -0
- package/lib/core/ws/WebSocketClientStore.d.ts +13 -0
- package/lib/core/ws/WebSocketClientStore.js +26 -0
- package/lib/core/ws/WebSocketClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketClientStore.mjs +6 -0
- package/lib/core/ws/WebSocketClientStore.mjs.map +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +14 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +14 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +130 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +110 -0
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.d.mts +12 -0
- package/lib/core/ws/WebSocketMemoryClientStore.d.ts +12 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js +41 -0
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +1 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +21 -0
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.d.mts +20 -0
- package/lib/core/ws/handleWebSocketEvent.d.ts +20 -0
- package/lib/core/ws/handleWebSocketEvent.js +61 -0
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -0
- package/lib/core/ws/handleWebSocketEvent.mjs +43 -0
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +18 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +18 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js +199 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +179 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -0
- package/lib/core/ws/utils/getMessageLength.d.mts +11 -0
- package/lib/core/ws/utils/getMessageLength.d.ts +11 -0
- package/lib/core/ws/utils/getMessageLength.js +34 -0
- package/lib/core/ws/utils/getMessageLength.js.map +1 -0
- package/lib/core/ws/utils/getMessageLength.mjs +14 -0
- package/lib/core/ws/utils/getMessageLength.mjs.map +1 -0
- package/lib/core/ws/utils/getPublicData.d.mts +5 -0
- package/lib/core/ws/utils/getPublicData.d.ts +5 -0
- package/lib/core/ws/utils/getPublicData.js +37 -0
- package/lib/core/ws/utils/getPublicData.js.map +1 -0
- package/lib/core/ws/utils/getPublicData.mjs +17 -0
- package/lib/core/ws/utils/getPublicData.mjs.map +1 -0
- package/lib/core/ws/utils/truncateMessage.d.mts +3 -0
- package/lib/core/ws/utils/truncateMessage.d.ts +3 -0
- package/lib/core/ws/utils/truncateMessage.js +31 -0
- package/lib/core/ws/utils/truncateMessage.js.map +1 -0
- package/lib/core/ws/utils/truncateMessage.mjs +11 -0
- package/lib/core/ws/utils/truncateMessage.mjs.map +1 -0
- package/lib/core/ws/webSocketInterceptor.d.mts +5 -0
- package/lib/core/ws/webSocketInterceptor.d.ts +5 -0
- package/lib/core/ws/webSocketInterceptor.js +26 -0
- package/lib/core/ws/webSocketInterceptor.js.map +1 -0
- package/lib/core/ws/webSocketInterceptor.mjs +6 -0
- package/lib/core/ws/webSocketInterceptor.mjs.map +1 -0
- package/lib/core/ws.d.mts +75 -0
- package/lib/core/ws.d.ts +75 -0
- package/lib/core/ws.js +69 -0
- package/lib/core/ws.js.map +1 -0
- package/lib/core/ws.mjs +52 -0
- package/lib/core/ws.mjs.map +1 -0
- package/lib/iife/index.js +23752 -0
- package/lib/iife/index.js.map +1 -0
- package/lib/mockServiceWorker.js +349 -0
- package/lib/native/index.d.mts +74 -0
- package/lib/native/index.d.ts +74 -0
- package/lib/native/index.js +156 -0
- package/lib/native/index.js.map +1 -0
- package/lib/native/index.mjs +134 -0
- package/lib/native/index.mjs.map +1 -0
- package/lib/node/index.d.mts +91 -0
- package/lib/node/index.d.ts +91 -0
- package/lib/node/index.js +209 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/index.mjs +184 -0
- package/lib/node/index.mjs.map +1 -0
- package/lib/shims/cookie.d.mts +7 -0
- package/lib/shims/cookie.d.ts +7 -0
- package/lib/shims/cookie.js +204 -0
- package/lib/shims/cookie.mjs +196 -0
- package/lib/shims/statuses.d.mts +6 -0
- package/lib/shims/statuses.d.ts +6 -0
- package/lib/shims/statuses.js +195 -0
- package/lib/shims/statuses.mjs +187 -0
- package/native/package.json +30 -0
- package/node/package.json +33 -0
- package/package.json +381 -0
- package/src/browser/global.browser.d.ts +1 -0
- package/src/browser/index.ts +3 -0
- package/src/browser/setupWorker/glossary.ts +138 -0
- package/src/browser/setupWorker/setupWorker.node.test.ts +10 -0
- package/src/browser/setupWorker/setupWorker.ts +184 -0
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +71 -0
- package/src/browser/setupWorker/start/createRequestListener.ts +138 -0
- package/src/browser/setupWorker/start/createResponseListener.ts +57 -0
- package/src/browser/setupWorker/start/createStartHandler.ts +137 -0
- package/src/browser/setupWorker/start/utils/enableMocking.ts +30 -0
- package/src/browser/setupWorker/start/utils/getWorkerByRegistration.ts +25 -0
- package/src/browser/setupWorker/start/utils/getWorkerInstance.ts +97 -0
- package/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts +59 -0
- package/src/browser/setupWorker/start/utils/prepareStartHandler.ts +44 -0
- package/src/browser/setupWorker/start/utils/printStartMessage.test.ts +84 -0
- package/src/browser/setupWorker/start/utils/printStartMessage.ts +51 -0
- package/src/browser/setupWorker/start/utils/validateWorkerScope.ts +18 -0
- package/src/browser/setupWorker/stop/utils/printStopMessage.test.ts +26 -0
- package/src/browser/setupWorker/stop/utils/printStopMessage.ts +13 -0
- package/src/browser/tsconfig.browser.build.json +6 -0
- package/src/browser/tsconfig.browser.json +9 -0
- package/src/browser/utils/checkWorkerIntegrity.ts +42 -0
- package/src/browser/utils/deserializeRequest.ts +15 -0
- package/src/browser/utils/getAbsoluteWorkerUrl.test.ts +29 -0
- package/src/browser/utils/getAbsoluteWorkerUrl.ts +7 -0
- package/src/browser/utils/pruneGetRequestBody.test.ts +53 -0
- package/src/browser/utils/pruneGetRequestBody.ts +21 -0
- package/src/browser/utils/supports.ts +30 -0
- package/src/browser/utils/workerChannel.ts +159 -0
- package/src/core/HttpResponse.test.ts +378 -0
- package/src/core/HttpResponse.ts +248 -0
- package/src/core/SetupApi.ts +127 -0
- package/src/core/bypass.test.ts +80 -0
- package/src/core/bypass.ts +46 -0
- package/src/core/delay.ts +82 -0
- package/src/core/getResponse.test.ts +74 -0
- package/src/core/getResponse.ts +29 -0
- package/src/core/graphql.test.ts +11 -0
- package/src/core/graphql.ts +136 -0
- package/src/core/handlers/GraphQLHandler.test.ts +873 -0
- package/src/core/handlers/GraphQLHandler.ts +437 -0
- package/src/core/handlers/HttpHandler.test.ts +253 -0
- package/src/core/handlers/HttpHandler.ts +214 -0
- package/src/core/handlers/RequestHandler.ts +391 -0
- package/src/core/handlers/WebSocketHandler.test.ts +127 -0
- package/src/core/handlers/WebSocketHandler.ts +209 -0
- package/src/core/handlers/common.ts +1 -0
- package/src/core/http.test.ts +15 -0
- package/src/core/http.ts +64 -0
- package/src/core/index.ts +110 -0
- package/src/core/isCommonAssetRequest.ts +45 -0
- package/src/core/passthrough.test.ts +11 -0
- package/src/core/passthrough.ts +25 -0
- package/src/core/sharedOptions.ts +66 -0
- package/src/core/sse.ts +916 -0
- package/src/core/typeUtils.ts +26 -0
- package/src/core/utils/HttpResponse/decorators.ts +76 -0
- package/src/core/utils/cookieStore.ts +94 -0
- package/src/core/utils/executeHandlers.ts +69 -0
- package/src/core/utils/handleRequest.test.ts +573 -0
- package/src/core/utils/handleRequest.ts +117 -0
- package/src/core/utils/internal/Disposable.ts +12 -0
- package/src/core/utils/internal/checkGlobals.ts +17 -0
- package/src/core/utils/internal/devUtils.test.ts +21 -0
- package/src/core/utils/internal/devUtils.ts +44 -0
- package/src/core/utils/internal/getCallFrame.test.ts +154 -0
- package/src/core/utils/internal/getCallFrame.ts +35 -0
- package/src/core/utils/internal/hasRefCounted.test.ts +16 -0
- package/src/core/utils/internal/hasRefCounted.ts +8 -0
- package/src/core/utils/internal/isHandlerKind.test.ts +64 -0
- package/src/core/utils/internal/isHandlerKind.ts +21 -0
- package/src/core/utils/internal/isIterable.test.ts +23 -0
- package/src/core/utils/internal/isIterable.ts +32 -0
- package/src/core/utils/internal/isObject.test.ts +20 -0
- package/src/core/utils/internal/isObject.ts +6 -0
- package/src/core/utils/internal/isStringEqual.test.ts +45 -0
- package/src/core/utils/internal/isStringEqual.ts +6 -0
- package/src/core/utils/internal/jsonParse.test.ts +13 -0
- package/src/core/utils/internal/jsonParse.ts +13 -0
- package/src/core/utils/internal/mergeRight.test.ts +43 -0
- package/src/core/utils/internal/mergeRight.ts +30 -0
- package/src/core/utils/internal/parseGraphQLRequest.test.ts +99 -0
- package/src/core/utils/internal/parseGraphQLRequest.ts +214 -0
- package/src/core/utils/internal/parseMultipartData.test.ts +76 -0
- package/src/core/utils/internal/parseMultipartData.ts +106 -0
- package/src/core/utils/internal/pipeEvents.test.ts +14 -0
- package/src/core/utils/internal/pipeEvents.ts +25 -0
- package/src/core/utils/internal/requestHandlerUtils.ts +21 -0
- package/src/core/utils/internal/toReadonlyArray.test.ts +30 -0
- package/src/core/utils/internal/toReadonlyArray.ts +8 -0
- package/src/core/utils/internal/tryCatch.test.ts +29 -0
- package/src/core/utils/internal/tryCatch.ts +11 -0
- package/src/core/utils/logging/getStatusCodeColor.test.ts +22 -0
- package/src/core/utils/logging/getStatusCodeColor.ts +20 -0
- package/src/core/utils/logging/getTimestamp.test.ts +32 -0
- package/src/core/utils/logging/getTimestamp.ts +17 -0
- package/src/core/utils/logging/serializeRequest.test.ts +23 -0
- package/src/core/utils/logging/serializeRequest.ts +23 -0
- package/src/core/utils/logging/serializeResponse.test.ts +77 -0
- package/src/core/utils/logging/serializeResponse.ts +31 -0
- package/src/core/utils/matching/matchRequestUrl.test.ts +183 -0
- package/src/core/utils/matching/matchRequestUrl.ts +77 -0
- package/src/core/utils/matching/normalizePath.node.test.ts +44 -0
- package/src/core/utils/matching/normalizePath.test.ts +56 -0
- package/src/core/utils/matching/normalizePath.ts +22 -0
- package/src/core/utils/request/getAllAcceptedMimeTypes.test.ts +86 -0
- package/src/core/utils/request/getAllAcceptedMimeTypes.ts +70 -0
- package/src/core/utils/request/getRequestCookies.ts +88 -0
- package/src/core/utils/request/onUnhandledRequest.node.test.ts +62 -0
- package/src/core/utils/request/onUnhandledRequest.test.ts +228 -0
- package/src/core/utils/request/onUnhandledRequest.ts +81 -0
- package/src/core/utils/request/storeResponseCookies.ts +17 -0
- package/src/core/utils/request/toPublicUrl.node.test.ts +17 -0
- package/src/core/utils/request/toPublicUrl.test.ts +16 -0
- package/src/core/utils/request/toPublicUrl.ts +16 -0
- package/src/core/utils/toResponseInit.ts +7 -0
- package/src/core/utils/url/cleanUrl.test.ts +22 -0
- package/src/core/utils/url/cleanUrl.ts +16 -0
- package/src/core/utils/url/getAbsoluteUrl.node.test.ts +19 -0
- package/src/core/utils/url/getAbsoluteUrl.test.ts +47 -0
- package/src/core/utils/url/getAbsoluteUrl.ts +25 -0
- package/src/core/utils/url/isAbsoluteUrl.test.ts +32 -0
- package/src/core/utils/url/isAbsoluteUrl.ts +6 -0
- package/src/core/ws/WebSocketClientManager.test.ts +164 -0
- package/src/core/ws/WebSocketClientManager.ts +241 -0
- package/src/core/ws/WebSocketClientStore.ts +14 -0
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +140 -0
- package/src/core/ws/WebSocketMemoryClientStore.ts +27 -0
- package/src/core/ws/handleWebSocketEvent.ts +64 -0
- package/src/core/ws/utils/attachWebSocketLogger.ts +245 -0
- package/src/core/ws/utils/getMessageLength.test.ts +16 -0
- package/src/core/ws/utils/getMessageLength.ts +20 -0
- package/src/core/ws/utils/getPublicData.test.ts +38 -0
- package/src/core/ws/utils/getPublicData.ts +18 -0
- package/src/core/ws/utils/truncateMessage.test.ts +12 -0
- package/src/core/ws/utils/truncateMessage.ts +9 -0
- package/src/core/ws/webSocketInterceptor.ts +3 -0
- package/src/core/ws.test.ts +23 -0
- package/src/core/ws.ts +161 -0
- package/src/iife/index.ts +2 -0
- package/src/mockServiceWorker.js +349 -0
- package/src/native/index.ts +21 -0
- package/src/node/SetupServerApi.ts +87 -0
- package/src/node/SetupServerCommonApi.ts +169 -0
- package/src/node/glossary.ts +74 -0
- package/src/node/index.ts +3 -0
- package/src/node/setupServer.ts +15 -0
- package/src/package.json +3 -0
- package/src/shims/cookie.ts +7 -0
- package/src/shims/statuses.ts +6 -0
- package/src/tsconfig.core.build.json +6 -0
- package/src/tsconfig.node.build.json +6 -0
- package/src/tsconfig.node.json +8 -0
- package/src/tsconfig.src.json +10 -0
- package/src/tsconfig.worker.json +13 -0
|
@@ -0,0 +1,2888 @@
|
|
|
1
|
+
// node_modules/.pnpm/outvariant@1.4.3/node_modules/outvariant/lib/index.mjs
|
|
2
|
+
var POSITIONALS_EXP = /(%?)(%([sdijo]))/g;
|
|
3
|
+
function serializePositional(positional, flag) {
|
|
4
|
+
switch (flag) {
|
|
5
|
+
case "s":
|
|
6
|
+
return positional;
|
|
7
|
+
case "d":
|
|
8
|
+
case "i":
|
|
9
|
+
return Number(positional);
|
|
10
|
+
case "j":
|
|
11
|
+
return JSON.stringify(positional);
|
|
12
|
+
case "o": {
|
|
13
|
+
if (typeof positional === "string") {
|
|
14
|
+
return positional;
|
|
15
|
+
}
|
|
16
|
+
const json = JSON.stringify(positional);
|
|
17
|
+
if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) {
|
|
18
|
+
return positional;
|
|
19
|
+
}
|
|
20
|
+
return json;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function format(message, ...positionals) {
|
|
25
|
+
if (positionals.length === 0) {
|
|
26
|
+
return message;
|
|
27
|
+
}
|
|
28
|
+
let positionalIndex = 0;
|
|
29
|
+
let formattedMessage = message.replace(
|
|
30
|
+
POSITIONALS_EXP,
|
|
31
|
+
(match, isEscaped, _, flag) => {
|
|
32
|
+
const positional = positionals[positionalIndex];
|
|
33
|
+
const value = serializePositional(positional, flag);
|
|
34
|
+
if (!isEscaped) {
|
|
35
|
+
positionalIndex++;
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
return match;
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
if (positionalIndex < positionals.length) {
|
|
42
|
+
formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;
|
|
43
|
+
}
|
|
44
|
+
formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
|
|
45
|
+
return formattedMessage;
|
|
46
|
+
}
|
|
47
|
+
var STACK_FRAMES_TO_IGNORE = 2;
|
|
48
|
+
function cleanErrorStack(error2) {
|
|
49
|
+
if (!error2.stack) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const nextStack = error2.stack.split("\n");
|
|
53
|
+
nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
|
|
54
|
+
error2.stack = nextStack.join("\n");
|
|
55
|
+
}
|
|
56
|
+
var InvariantError = class extends Error {
|
|
57
|
+
constructor(message, ...positionals) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.message = message;
|
|
60
|
+
this.name = "Invariant Violation";
|
|
61
|
+
this.message = format(message, ...positionals);
|
|
62
|
+
cleanErrorStack(this);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var invariant = (predicate, message, ...positionals) => {
|
|
66
|
+
if (!predicate) {
|
|
67
|
+
throw new InvariantError(message, ...positionals);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
invariant.as = (ErrorConstructor, predicate, message, ...positionals) => {
|
|
71
|
+
if (!predicate) {
|
|
72
|
+
const formatMessage = positionals.length === 0 ? message : format(message, ...positionals);
|
|
73
|
+
let error2;
|
|
74
|
+
try {
|
|
75
|
+
error2 = Reflect.construct(ErrorConstructor, [
|
|
76
|
+
formatMessage
|
|
77
|
+
]);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
error2 = ErrorConstructor(formatMessage);
|
|
80
|
+
}
|
|
81
|
+
throw error2;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
86
|
+
function isNodeProcess() {
|
|
87
|
+
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
if (typeof process !== "undefined") {
|
|
91
|
+
const type = process.type;
|
|
92
|
+
if (type === "renderer" || type === "worker") {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
return !!(process.versions && process.versions.node);
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// node_modules/.pnpm/@open-draft+deferred-promise@2.2.0/node_modules/@open-draft/deferred-promise/build/index.mjs
|
|
101
|
+
function createDeferredExecutor() {
|
|
102
|
+
const executor = (resolve, reject) => {
|
|
103
|
+
executor.state = "pending";
|
|
104
|
+
executor.resolve = (data) => {
|
|
105
|
+
if (executor.state !== "pending") {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
executor.result = data;
|
|
109
|
+
const onFulfilled = (value) => {
|
|
110
|
+
executor.state = "fulfilled";
|
|
111
|
+
return value;
|
|
112
|
+
};
|
|
113
|
+
return resolve(
|
|
114
|
+
data instanceof Promise ? data : Promise.resolve(data).then(onFulfilled)
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
executor.reject = (reason) => {
|
|
118
|
+
if (executor.state !== "pending") {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
queueMicrotask(() => {
|
|
122
|
+
executor.state = "rejected";
|
|
123
|
+
});
|
|
124
|
+
return reject(executor.rejectionReason = reason);
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
return executor;
|
|
128
|
+
}
|
|
129
|
+
var DeferredPromise = class extends Promise {
|
|
130
|
+
#executor;
|
|
131
|
+
resolve;
|
|
132
|
+
reject;
|
|
133
|
+
constructor(executor = null) {
|
|
134
|
+
const deferredExecutor = createDeferredExecutor();
|
|
135
|
+
super((originalResolve, originalReject) => {
|
|
136
|
+
deferredExecutor(originalResolve, originalReject);
|
|
137
|
+
executor?.(deferredExecutor.resolve, deferredExecutor.reject);
|
|
138
|
+
});
|
|
139
|
+
this.#executor = deferredExecutor;
|
|
140
|
+
this.resolve = this.#executor.resolve;
|
|
141
|
+
this.reject = this.#executor.reject;
|
|
142
|
+
}
|
|
143
|
+
get state() {
|
|
144
|
+
return this.#executor.state;
|
|
145
|
+
}
|
|
146
|
+
get rejectionReason() {
|
|
147
|
+
return this.#executor.rejectionReason;
|
|
148
|
+
}
|
|
149
|
+
then(onFulfilled, onRejected) {
|
|
150
|
+
return this.#decorate(super.then(onFulfilled, onRejected));
|
|
151
|
+
}
|
|
152
|
+
catch(onRejected) {
|
|
153
|
+
return this.#decorate(super.catch(onRejected));
|
|
154
|
+
}
|
|
155
|
+
finally(onfinally) {
|
|
156
|
+
return this.#decorate(super.finally(onfinally));
|
|
157
|
+
}
|
|
158
|
+
#decorate(promise) {
|
|
159
|
+
return Object.defineProperties(promise, {
|
|
160
|
+
resolve: { configurable: true, value: this.resolve },
|
|
161
|
+
reject: { configurable: true, value: this.reject }
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// src/browser/setupWorker/start/utils/prepareStartHandler.ts
|
|
167
|
+
import { mergeRight } from '../core/utils/internal/mergeRight.mjs';
|
|
168
|
+
var DEFAULT_START_OPTIONS = {
|
|
169
|
+
serviceWorker: {
|
|
170
|
+
url: "/mockServiceWorker.js",
|
|
171
|
+
options: null
|
|
172
|
+
},
|
|
173
|
+
quiet: false,
|
|
174
|
+
waitUntilReady: true,
|
|
175
|
+
onUnhandledRequest: "warn",
|
|
176
|
+
findWorker(scriptURL, mockServiceWorkerUrl) {
|
|
177
|
+
return scriptURL === mockServiceWorkerUrl;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// src/browser/setupWorker/start/createStartHandler.ts
|
|
182
|
+
import { devUtils as devUtils6 } from '../core/utils/internal/devUtils.mjs';
|
|
183
|
+
|
|
184
|
+
// node_modules/.pnpm/until-async@3.0.2/node_modules/until-async/lib/index.js
|
|
185
|
+
async function until(callback) {
|
|
186
|
+
try {
|
|
187
|
+
return [null, await callback().catch((error2) => {
|
|
188
|
+
throw error2;
|
|
189
|
+
})];
|
|
190
|
+
} catch (error2) {
|
|
191
|
+
return [error2, null];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/browser/setupWorker/start/utils/getWorkerInstance.ts
|
|
196
|
+
import { devUtils } from '../core/utils/internal/devUtils.mjs';
|
|
197
|
+
|
|
198
|
+
// src/browser/utils/getAbsoluteWorkerUrl.ts
|
|
199
|
+
function getAbsoluteWorkerUrl(workerUrl) {
|
|
200
|
+
return new URL(workerUrl, location.href).href;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/browser/setupWorker/start/utils/getWorkerByRegistration.ts
|
|
204
|
+
function getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker) {
|
|
205
|
+
const allStates = [
|
|
206
|
+
registration.active,
|
|
207
|
+
registration.installing,
|
|
208
|
+
registration.waiting
|
|
209
|
+
];
|
|
210
|
+
const relevantStates = allStates.filter((state) => {
|
|
211
|
+
return state != null;
|
|
212
|
+
});
|
|
213
|
+
const worker = relevantStates.find((worker2) => {
|
|
214
|
+
return findWorker(worker2.scriptURL, absoluteWorkerUrl);
|
|
215
|
+
});
|
|
216
|
+
return worker || null;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// src/browser/setupWorker/start/utils/getWorkerInstance.ts
|
|
220
|
+
var getWorkerInstance = async (url, options = {}, findWorker) => {
|
|
221
|
+
const absoluteWorkerUrl = getAbsoluteWorkerUrl(url);
|
|
222
|
+
const mockRegistrations = await navigator.serviceWorker.getRegistrations().then(
|
|
223
|
+
(registrations) => registrations.filter(
|
|
224
|
+
(registration) => getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker)
|
|
225
|
+
)
|
|
226
|
+
);
|
|
227
|
+
if (!navigator.serviceWorker.controller && mockRegistrations.length > 0) {
|
|
228
|
+
location.reload();
|
|
229
|
+
}
|
|
230
|
+
const [existingRegistration] = mockRegistrations;
|
|
231
|
+
if (existingRegistration) {
|
|
232
|
+
existingRegistration.update();
|
|
233
|
+
return [
|
|
234
|
+
getWorkerByRegistration(
|
|
235
|
+
existingRegistration,
|
|
236
|
+
absoluteWorkerUrl,
|
|
237
|
+
findWorker
|
|
238
|
+
),
|
|
239
|
+
existingRegistration
|
|
240
|
+
];
|
|
241
|
+
}
|
|
242
|
+
const [registrationError, registrationResult] = await until(async () => {
|
|
243
|
+
const registration = await navigator.serviceWorker.register(url, options);
|
|
244
|
+
return [
|
|
245
|
+
// Compare existing worker registration by its worker URL,
|
|
246
|
+
// to prevent irrelevant workers to resolve here (such as Codesandbox worker).
|
|
247
|
+
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
248
|
+
registration
|
|
249
|
+
];
|
|
250
|
+
});
|
|
251
|
+
if (registrationError) {
|
|
252
|
+
const isWorkerMissing = registrationError.message.includes("(404)");
|
|
253
|
+
if (isWorkerMissing) {
|
|
254
|
+
const scopeUrl = new URL(options?.scope || "/", location.href);
|
|
255
|
+
throw new Error(
|
|
256
|
+
devUtils.formatMessage(`Failed to register a Service Worker for scope ('${scopeUrl.href}') with script ('${absoluteWorkerUrl}'): Service Worker script does not exist at the given path.
|
|
257
|
+
|
|
258
|
+
Did you forget to run "npx msw init <PUBLIC_DIR>"?
|
|
259
|
+
|
|
260
|
+
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init`)
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
throw new Error(
|
|
264
|
+
devUtils.formatMessage(
|
|
265
|
+
"Failed to register the Service Worker:\n\n%s",
|
|
266
|
+
registrationError.message
|
|
267
|
+
)
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
return registrationResult;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/browser/setupWorker/start/utils/printStartMessage.ts
|
|
274
|
+
import { devUtils as devUtils2 } from '../core/utils/internal/devUtils.mjs';
|
|
275
|
+
function printStartMessage(args = {}) {
|
|
276
|
+
if (args.quiet) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const message = args.message || "Mocking enabled.";
|
|
280
|
+
console.groupCollapsed(
|
|
281
|
+
`%c${devUtils2.formatMessage(message)}`,
|
|
282
|
+
"color:orangered;font-weight:bold;"
|
|
283
|
+
);
|
|
284
|
+
console.log(
|
|
285
|
+
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
286
|
+
"font-weight:bold",
|
|
287
|
+
"font-weight:normal"
|
|
288
|
+
);
|
|
289
|
+
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
290
|
+
if (args.workerUrl) {
|
|
291
|
+
console.log("Worker script URL:", args.workerUrl);
|
|
292
|
+
}
|
|
293
|
+
if (args.workerScope) {
|
|
294
|
+
console.log("Worker scope:", args.workerScope);
|
|
295
|
+
}
|
|
296
|
+
if (args.client) {
|
|
297
|
+
console.log("Client ID: %s (%s)", args.client.id, args.client.frameType);
|
|
298
|
+
}
|
|
299
|
+
console.groupEnd();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// src/browser/setupWorker/start/utils/enableMocking.ts
|
|
303
|
+
function enableMocking(context, options) {
|
|
304
|
+
const mockingEnabledPromise = new DeferredPromise();
|
|
305
|
+
context.workerChannel.postMessage("MOCK_ACTIVATE");
|
|
306
|
+
context.workerChannel.once("MOCKING_ENABLED", async (event) => {
|
|
307
|
+
context.isMockingEnabled = true;
|
|
308
|
+
const worker = await context.workerPromise;
|
|
309
|
+
printStartMessage({
|
|
310
|
+
quiet: options.quiet,
|
|
311
|
+
workerScope: context.registration?.scope,
|
|
312
|
+
workerUrl: worker.scriptURL,
|
|
313
|
+
client: event.data.client
|
|
314
|
+
});
|
|
315
|
+
mockingEnabledPromise.resolve(true);
|
|
316
|
+
});
|
|
317
|
+
return mockingEnabledPromise;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/browser/utils/pruneGetRequestBody.ts
|
|
321
|
+
function pruneGetRequestBody(request) {
|
|
322
|
+
if (["HEAD", "GET"].includes(request.method)) {
|
|
323
|
+
return void 0;
|
|
324
|
+
}
|
|
325
|
+
return request.body;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// src/browser/utils/deserializeRequest.ts
|
|
329
|
+
function deserializeRequest(serializedRequest) {
|
|
330
|
+
return new Request(serializedRequest.url, {
|
|
331
|
+
...serializedRequest,
|
|
332
|
+
body: pruneGetRequestBody(serializedRequest)
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// src/browser/utils/supports.ts
|
|
337
|
+
function supportsServiceWorker() {
|
|
338
|
+
return typeof navigator !== "undefined" && "serviceWorker" in navigator && typeof location !== "undefined" && location.protocol !== "file:";
|
|
339
|
+
}
|
|
340
|
+
function supportsReadableStreamTransfer() {
|
|
341
|
+
try {
|
|
342
|
+
const stream = new ReadableStream({
|
|
343
|
+
start: (controller) => controller.close()
|
|
344
|
+
});
|
|
345
|
+
const message = new MessageChannel();
|
|
346
|
+
message.port1.postMessage(stream, [stream]);
|
|
347
|
+
return true;
|
|
348
|
+
} catch {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/browser/setupWorker/start/createRequestListener.ts
|
|
354
|
+
import { RequestHandler } from '../core/handlers/RequestHandler.mjs';
|
|
355
|
+
import { handleRequest } from '../core/utils/handleRequest.mjs';
|
|
356
|
+
import { devUtils as devUtils3 } from '../core/utils/internal/devUtils.mjs';
|
|
357
|
+
import { toResponseInit } from '../core/utils/toResponseInit.mjs';
|
|
358
|
+
import { isHandlerKind } from '../core/utils/internal/isHandlerKind.mjs';
|
|
359
|
+
var SUPPORTS_READABLE_STREAM_TRANSFER = supportsReadableStreamTransfer();
|
|
360
|
+
var createRequestListener = (context, options) => {
|
|
361
|
+
return async (event) => {
|
|
362
|
+
if (!context.isMockingEnabled && context.workerStoppedAt && event.data.interceptedAt > context.workerStoppedAt) {
|
|
363
|
+
event.postMessage("PASSTHROUGH");
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const requestId = event.data.id;
|
|
367
|
+
const request = deserializeRequest(event.data);
|
|
368
|
+
const requestCloneForLogs = request.clone();
|
|
369
|
+
const requestClone = request.clone();
|
|
370
|
+
RequestHandler.cache.set(request, requestClone);
|
|
371
|
+
try {
|
|
372
|
+
await handleRequest(
|
|
373
|
+
request,
|
|
374
|
+
requestId,
|
|
375
|
+
context.getRequestHandlers().filter(isHandlerKind("RequestHandler")),
|
|
376
|
+
options,
|
|
377
|
+
context.emitter,
|
|
378
|
+
{
|
|
379
|
+
resolutionContext: {
|
|
380
|
+
quiet: options.quiet
|
|
381
|
+
},
|
|
382
|
+
onPassthroughResponse() {
|
|
383
|
+
event.postMessage("PASSTHROUGH");
|
|
384
|
+
},
|
|
385
|
+
async onMockedResponse(response, { handler, parsedResult }) {
|
|
386
|
+
const responseClone = response.clone();
|
|
387
|
+
const responseCloneForLogs = response.clone();
|
|
388
|
+
const responseInit = toResponseInit(response);
|
|
389
|
+
if (SUPPORTS_READABLE_STREAM_TRANSFER) {
|
|
390
|
+
const responseStreamOrNull = response.body;
|
|
391
|
+
event.postMessage(
|
|
392
|
+
"MOCK_RESPONSE",
|
|
393
|
+
{
|
|
394
|
+
...responseInit,
|
|
395
|
+
body: responseStreamOrNull
|
|
396
|
+
},
|
|
397
|
+
responseStreamOrNull ? [responseStreamOrNull] : void 0
|
|
398
|
+
);
|
|
399
|
+
} else {
|
|
400
|
+
const responseBufferOrNull = response.body === null ? null : await responseClone.arrayBuffer();
|
|
401
|
+
event.postMessage("MOCK_RESPONSE", {
|
|
402
|
+
...responseInit,
|
|
403
|
+
body: responseBufferOrNull
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
if (!options.quiet) {
|
|
407
|
+
context.emitter.once("response:mocked", () => {
|
|
408
|
+
handler.log({
|
|
409
|
+
request: requestCloneForLogs,
|
|
410
|
+
response: responseCloneForLogs,
|
|
411
|
+
parsedResult
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
);
|
|
418
|
+
} catch (error2) {
|
|
419
|
+
if (error2 instanceof Error) {
|
|
420
|
+
devUtils3.error(
|
|
421
|
+
`Uncaught exception in the request handler for "%s %s":
|
|
422
|
+
|
|
423
|
+
%s
|
|
424
|
+
|
|
425
|
+
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/http/mocking-responses/error-responses`,
|
|
426
|
+
request.method,
|
|
427
|
+
request.url,
|
|
428
|
+
error2.stack ?? error2
|
|
429
|
+
);
|
|
430
|
+
event.postMessage("MOCK_RESPONSE", {
|
|
431
|
+
status: 500,
|
|
432
|
+
statusText: "Request Handler Error",
|
|
433
|
+
headers: {
|
|
434
|
+
"Content-Type": "application/json"
|
|
435
|
+
},
|
|
436
|
+
body: JSON.stringify({
|
|
437
|
+
name: error2.name,
|
|
438
|
+
message: error2.message,
|
|
439
|
+
stack: error2.stack
|
|
440
|
+
})
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
// src/browser/utils/checkWorkerIntegrity.ts
|
|
448
|
+
import { devUtils as devUtils4 } from '../core/utils/internal/devUtils.mjs';
|
|
449
|
+
function checkWorkerIntegrity(context) {
|
|
450
|
+
const integrityCheckPromise = new DeferredPromise();
|
|
451
|
+
context.workerChannel.postMessage("INTEGRITY_CHECK_REQUEST");
|
|
452
|
+
context.workerChannel.once("INTEGRITY_CHECK_RESPONSE", (event) => {
|
|
453
|
+
const { checksum, packageVersion } = event.data;
|
|
454
|
+
if (checksum !== "4db4a41e972cec1b64cc569c66952d82") {
|
|
455
|
+
devUtils4.warn(
|
|
456
|
+
`The currently registered Service Worker has been generated by a different version of MSW (${packageVersion}) and may not be fully compatible with the installed version.
|
|
457
|
+
|
|
458
|
+
It's recommended you update your worker script by running this command:
|
|
459
|
+
|
|
460
|
+
\u2022 npx msw init <PUBLIC_DIR>
|
|
461
|
+
|
|
462
|
+
You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
integrityCheckPromise.resolve();
|
|
466
|
+
});
|
|
467
|
+
return integrityCheckPromise;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-BTaNLFr0.mjs
|
|
471
|
+
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
472
|
+
var InterceptorError = class InterceptorError2 extends Error {
|
|
473
|
+
constructor(message) {
|
|
474
|
+
super(message);
|
|
475
|
+
this.name = "InterceptorError";
|
|
476
|
+
Object.setPrototypeOf(this, InterceptorError2.prototype);
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
var RequestController = class RequestController2 {
|
|
480
|
+
static {
|
|
481
|
+
this.PENDING = 0;
|
|
482
|
+
}
|
|
483
|
+
static {
|
|
484
|
+
this.PASSTHROUGH = 1;
|
|
485
|
+
}
|
|
486
|
+
static {
|
|
487
|
+
this.RESPONSE = 2;
|
|
488
|
+
}
|
|
489
|
+
static {
|
|
490
|
+
this.ERROR = 3;
|
|
491
|
+
}
|
|
492
|
+
constructor(request, source) {
|
|
493
|
+
this.request = request;
|
|
494
|
+
this.source = source;
|
|
495
|
+
this.readyState = RequestController2.PENDING;
|
|
496
|
+
this.handled = new DeferredPromise();
|
|
497
|
+
}
|
|
498
|
+
get #handled() {
|
|
499
|
+
return this.handled;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Perform this request as-is.
|
|
503
|
+
*/
|
|
504
|
+
async passthrough() {
|
|
505
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to passthrough the "%s %s" request: the request has already been handled', this.request.method, this.request.url);
|
|
506
|
+
this.readyState = RequestController2.PASSTHROUGH;
|
|
507
|
+
await this.source.passthrough();
|
|
508
|
+
this.#handled.resolve();
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Respond to this request with the given `Response` instance.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* controller.respondWith(new Response())
|
|
515
|
+
* controller.respondWith(Response.json({ id }))
|
|
516
|
+
* controller.respondWith(Response.error())
|
|
517
|
+
*/
|
|
518
|
+
respondWith(response) {
|
|
519
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to respond to the "%s %s" request with "%d %s": the request has already been handled (%d)', this.request.method, this.request.url, response.status, response.statusText || "OK", this.readyState);
|
|
520
|
+
this.readyState = RequestController2.RESPONSE;
|
|
521
|
+
this.#handled.resolve();
|
|
522
|
+
this.source.respondWith(response);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Error this request with the given reason.
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* controller.errorWith()
|
|
529
|
+
* controller.errorWith(new Error('Oops!'))
|
|
530
|
+
* controller.errorWith({ message: 'Oops!'})
|
|
531
|
+
*/
|
|
532
|
+
errorWith(reason) {
|
|
533
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to error the "%s %s" request with "%s": the request has already been handled (%d)', this.request.method, this.request.url, reason?.toString(), this.readyState);
|
|
534
|
+
this.readyState = RequestController2.ERROR;
|
|
535
|
+
this.source.errorWith(reason);
|
|
536
|
+
this.#handled.resolve();
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
function canParseUrl(url) {
|
|
540
|
+
try {
|
|
541
|
+
new URL(url);
|
|
542
|
+
return true;
|
|
543
|
+
} catch (_error) {
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
function getValueBySymbol(symbolName, source) {
|
|
548
|
+
const symbol = Object.getOwnPropertySymbols(source).find((symbol$1) => {
|
|
549
|
+
return symbol$1.description === symbolName;
|
|
550
|
+
});
|
|
551
|
+
if (symbol) return Reflect.get(source, symbol);
|
|
552
|
+
}
|
|
553
|
+
var FetchResponse = class FetchResponse2 extends Response {
|
|
554
|
+
static {
|
|
555
|
+
this.STATUS_CODES_WITHOUT_BODY = [
|
|
556
|
+
101,
|
|
557
|
+
103,
|
|
558
|
+
204,
|
|
559
|
+
205,
|
|
560
|
+
304
|
|
561
|
+
];
|
|
562
|
+
}
|
|
563
|
+
static {
|
|
564
|
+
this.STATUS_CODES_WITH_REDIRECT = [
|
|
565
|
+
301,
|
|
566
|
+
302,
|
|
567
|
+
303,
|
|
568
|
+
307,
|
|
569
|
+
308
|
|
570
|
+
];
|
|
571
|
+
}
|
|
572
|
+
static isConfigurableStatusCode(status) {
|
|
573
|
+
return status >= 200 && status <= 599;
|
|
574
|
+
}
|
|
575
|
+
static isRedirectResponse(status) {
|
|
576
|
+
return FetchResponse2.STATUS_CODES_WITH_REDIRECT.includes(status);
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Returns a boolean indicating whether the given response status
|
|
580
|
+
* code represents a response that can have a body.
|
|
581
|
+
*/
|
|
582
|
+
static isResponseWithBody(status) {
|
|
583
|
+
return !FetchResponse2.STATUS_CODES_WITHOUT_BODY.includes(status);
|
|
584
|
+
}
|
|
585
|
+
static setUrl(url, response) {
|
|
586
|
+
if (!url || url === "about:" || !canParseUrl(url)) return;
|
|
587
|
+
const state = getValueBySymbol("state", response);
|
|
588
|
+
if (state) state.urlList.push(new URL(url));
|
|
589
|
+
else Object.defineProperty(response, "url", {
|
|
590
|
+
value: url,
|
|
591
|
+
enumerable: true,
|
|
592
|
+
configurable: true,
|
|
593
|
+
writable: false
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
|
598
|
+
*/
|
|
599
|
+
static parseRawHeaders(rawHeaders) {
|
|
600
|
+
const headers = new Headers();
|
|
601
|
+
for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
|
602
|
+
return headers;
|
|
603
|
+
}
|
|
604
|
+
constructor(body, init = {}) {
|
|
605
|
+
const status = init.status ?? 200;
|
|
606
|
+
const safeStatus = FetchResponse2.isConfigurableStatusCode(status) ? status : 200;
|
|
607
|
+
const finalBody = FetchResponse2.isResponseWithBody(status) ? body : null;
|
|
608
|
+
super(finalBody, {
|
|
609
|
+
status: safeStatus,
|
|
610
|
+
statusText: init.statusText,
|
|
611
|
+
headers: init.headers
|
|
612
|
+
});
|
|
613
|
+
if (status !== safeStatus) {
|
|
614
|
+
const state = getValueBySymbol("state", this);
|
|
615
|
+
if (state) state.status = status;
|
|
616
|
+
else Object.defineProperty(this, "status", {
|
|
617
|
+
value: status,
|
|
618
|
+
enumerable: true,
|
|
619
|
+
configurable: true,
|
|
620
|
+
writable: false
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
FetchResponse2.setUrl(init.url, this);
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
var kRawRequest = Symbol("kRawRequest");
|
|
627
|
+
function setRawRequest(request, rawRequest) {
|
|
628
|
+
Reflect.set(request, kRawRequest, rawRequest);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
|
|
632
|
+
var __defProp = Object.defineProperty;
|
|
633
|
+
var __export = (target, all) => {
|
|
634
|
+
for (var name in all)
|
|
635
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
636
|
+
};
|
|
637
|
+
var colors_exports = {};
|
|
638
|
+
__export(colors_exports, {
|
|
639
|
+
blue: () => blue,
|
|
640
|
+
gray: () => gray,
|
|
641
|
+
green: () => green,
|
|
642
|
+
red: () => red,
|
|
643
|
+
yellow: () => yellow
|
|
644
|
+
});
|
|
645
|
+
function yellow(text) {
|
|
646
|
+
return `\x1B[33m${text}\x1B[0m`;
|
|
647
|
+
}
|
|
648
|
+
function blue(text) {
|
|
649
|
+
return `\x1B[34m${text}\x1B[0m`;
|
|
650
|
+
}
|
|
651
|
+
function gray(text) {
|
|
652
|
+
return `\x1B[90m${text}\x1B[0m`;
|
|
653
|
+
}
|
|
654
|
+
function red(text) {
|
|
655
|
+
return `\x1B[31m${text}\x1B[0m`;
|
|
656
|
+
}
|
|
657
|
+
function green(text) {
|
|
658
|
+
return `\x1B[32m${text}\x1B[0m`;
|
|
659
|
+
}
|
|
660
|
+
var IS_NODE = isNodeProcess();
|
|
661
|
+
var Logger = class {
|
|
662
|
+
constructor(name) {
|
|
663
|
+
this.name = name;
|
|
664
|
+
this.prefix = `[${this.name}]`;
|
|
665
|
+
const LOGGER_NAME = getVariable("DEBUG");
|
|
666
|
+
const LOGGER_LEVEL = getVariable("LOG_LEVEL");
|
|
667
|
+
const isLoggingEnabled = LOGGER_NAME === "1" || LOGGER_NAME === "true" || typeof LOGGER_NAME !== "undefined" && this.name.startsWith(LOGGER_NAME);
|
|
668
|
+
if (isLoggingEnabled) {
|
|
669
|
+
this.debug = isDefinedAndNotEquals(LOGGER_LEVEL, "debug") ? noop : this.debug;
|
|
670
|
+
this.info = isDefinedAndNotEquals(LOGGER_LEVEL, "info") ? noop : this.info;
|
|
671
|
+
this.success = isDefinedAndNotEquals(LOGGER_LEVEL, "success") ? noop : this.success;
|
|
672
|
+
this.warning = isDefinedAndNotEquals(LOGGER_LEVEL, "warning") ? noop : this.warning;
|
|
673
|
+
this.error = isDefinedAndNotEquals(LOGGER_LEVEL, "error") ? noop : this.error;
|
|
674
|
+
} else {
|
|
675
|
+
this.info = noop;
|
|
676
|
+
this.success = noop;
|
|
677
|
+
this.warning = noop;
|
|
678
|
+
this.error = noop;
|
|
679
|
+
this.only = noop;
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
prefix;
|
|
683
|
+
extend(domain) {
|
|
684
|
+
return new Logger(`${this.name}:${domain}`);
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Print a debug message.
|
|
688
|
+
* @example
|
|
689
|
+
* logger.debug('no duplicates found, creating a document...')
|
|
690
|
+
*/
|
|
691
|
+
debug(message, ...positionals) {
|
|
692
|
+
this.logEntry({
|
|
693
|
+
level: "debug",
|
|
694
|
+
message: gray(message),
|
|
695
|
+
positionals,
|
|
696
|
+
prefix: this.prefix,
|
|
697
|
+
colors: {
|
|
698
|
+
prefix: "gray"
|
|
699
|
+
}
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Print an info message.
|
|
704
|
+
* @example
|
|
705
|
+
* logger.info('start parsing...')
|
|
706
|
+
*/
|
|
707
|
+
info(message, ...positionals) {
|
|
708
|
+
this.logEntry({
|
|
709
|
+
level: "info",
|
|
710
|
+
message,
|
|
711
|
+
positionals,
|
|
712
|
+
prefix: this.prefix,
|
|
713
|
+
colors: {
|
|
714
|
+
prefix: "blue"
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
const performance2 = new PerformanceEntry();
|
|
718
|
+
return (message2, ...positionals2) => {
|
|
719
|
+
performance2.measure();
|
|
720
|
+
this.logEntry({
|
|
721
|
+
level: "info",
|
|
722
|
+
message: `${message2} ${gray(`${performance2.deltaTime}ms`)}`,
|
|
723
|
+
positionals: positionals2,
|
|
724
|
+
prefix: this.prefix,
|
|
725
|
+
colors: {
|
|
726
|
+
prefix: "blue"
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Print a success message.
|
|
733
|
+
* @example
|
|
734
|
+
* logger.success('successfully created document')
|
|
735
|
+
*/
|
|
736
|
+
success(message, ...positionals) {
|
|
737
|
+
this.logEntry({
|
|
738
|
+
level: "info",
|
|
739
|
+
message,
|
|
740
|
+
positionals,
|
|
741
|
+
prefix: `\u2714 ${this.prefix}`,
|
|
742
|
+
colors: {
|
|
743
|
+
timestamp: "green",
|
|
744
|
+
prefix: "green"
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Print a warning.
|
|
750
|
+
* @example
|
|
751
|
+
* logger.warning('found legacy document format')
|
|
752
|
+
*/
|
|
753
|
+
warning(message, ...positionals) {
|
|
754
|
+
this.logEntry({
|
|
755
|
+
level: "warning",
|
|
756
|
+
message,
|
|
757
|
+
positionals,
|
|
758
|
+
prefix: `\u26A0 ${this.prefix}`,
|
|
759
|
+
colors: {
|
|
760
|
+
timestamp: "yellow",
|
|
761
|
+
prefix: "yellow"
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Print an error message.
|
|
767
|
+
* @example
|
|
768
|
+
* logger.error('something went wrong')
|
|
769
|
+
*/
|
|
770
|
+
error(message, ...positionals) {
|
|
771
|
+
this.logEntry({
|
|
772
|
+
level: "error",
|
|
773
|
+
message,
|
|
774
|
+
positionals,
|
|
775
|
+
prefix: `\u2716 ${this.prefix}`,
|
|
776
|
+
colors: {
|
|
777
|
+
timestamp: "red",
|
|
778
|
+
prefix: "red"
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Execute the given callback only when the logging is enabled.
|
|
784
|
+
* This is skipped in its entirety and has no runtime cost otherwise.
|
|
785
|
+
* This executes regardless of the log level.
|
|
786
|
+
* @example
|
|
787
|
+
* logger.only(() => {
|
|
788
|
+
* logger.info('additional info')
|
|
789
|
+
* })
|
|
790
|
+
*/
|
|
791
|
+
only(callback) {
|
|
792
|
+
callback();
|
|
793
|
+
}
|
|
794
|
+
createEntry(level, message) {
|
|
795
|
+
return {
|
|
796
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
797
|
+
level,
|
|
798
|
+
message
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
logEntry(args) {
|
|
802
|
+
const {
|
|
803
|
+
level,
|
|
804
|
+
message,
|
|
805
|
+
prefix,
|
|
806
|
+
colors: customColors,
|
|
807
|
+
positionals = []
|
|
808
|
+
} = args;
|
|
809
|
+
const entry = this.createEntry(level, message);
|
|
810
|
+
const timestampColor = customColors?.timestamp || "gray";
|
|
811
|
+
const prefixColor = customColors?.prefix || "gray";
|
|
812
|
+
const colorize = {
|
|
813
|
+
timestamp: colors_exports[timestampColor],
|
|
814
|
+
prefix: colors_exports[prefixColor]
|
|
815
|
+
};
|
|
816
|
+
const write = this.getWriter(level);
|
|
817
|
+
write(
|
|
818
|
+
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "),
|
|
819
|
+
...positionals.map(serializeInput)
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
formatTimestamp(timestamp) {
|
|
823
|
+
return `${timestamp.toLocaleTimeString(
|
|
824
|
+
"en-GB"
|
|
825
|
+
)}:${timestamp.getMilliseconds()}`;
|
|
826
|
+
}
|
|
827
|
+
getWriter(level) {
|
|
828
|
+
switch (level) {
|
|
829
|
+
case "debug":
|
|
830
|
+
case "success":
|
|
831
|
+
case "info": {
|
|
832
|
+
return log;
|
|
833
|
+
}
|
|
834
|
+
case "warning": {
|
|
835
|
+
return warn;
|
|
836
|
+
}
|
|
837
|
+
case "error": {
|
|
838
|
+
return error;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
var PerformanceEntry = class {
|
|
844
|
+
startTime;
|
|
845
|
+
endTime;
|
|
846
|
+
deltaTime;
|
|
847
|
+
constructor() {
|
|
848
|
+
this.startTime = performance.now();
|
|
849
|
+
}
|
|
850
|
+
measure() {
|
|
851
|
+
this.endTime = performance.now();
|
|
852
|
+
const deltaTime = this.endTime - this.startTime;
|
|
853
|
+
this.deltaTime = deltaTime.toFixed(2);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
var noop = () => void 0;
|
|
857
|
+
function log(message, ...positionals) {
|
|
858
|
+
if (IS_NODE) {
|
|
859
|
+
process.stdout.write(format(message, ...positionals) + "\n");
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
console.log(message, ...positionals);
|
|
863
|
+
}
|
|
864
|
+
function warn(message, ...positionals) {
|
|
865
|
+
if (IS_NODE) {
|
|
866
|
+
process.stderr.write(format(message, ...positionals) + "\n");
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
console.warn(message, ...positionals);
|
|
870
|
+
}
|
|
871
|
+
function error(message, ...positionals) {
|
|
872
|
+
if (IS_NODE) {
|
|
873
|
+
process.stderr.write(format(message, ...positionals) + "\n");
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
console.error(message, ...positionals);
|
|
877
|
+
}
|
|
878
|
+
function getVariable(variableName) {
|
|
879
|
+
if (IS_NODE) {
|
|
880
|
+
return process.env[variableName];
|
|
881
|
+
}
|
|
882
|
+
return globalThis[variableName]?.toString();
|
|
883
|
+
}
|
|
884
|
+
function isDefinedAndNotEquals(value, expected) {
|
|
885
|
+
return value !== void 0 && value !== expected;
|
|
886
|
+
}
|
|
887
|
+
function serializeInput(message) {
|
|
888
|
+
if (typeof message === "undefined") {
|
|
889
|
+
return "undefined";
|
|
890
|
+
}
|
|
891
|
+
if (message === null) {
|
|
892
|
+
return "null";
|
|
893
|
+
}
|
|
894
|
+
if (typeof message === "string") {
|
|
895
|
+
return message;
|
|
896
|
+
}
|
|
897
|
+
if (typeof message === "object") {
|
|
898
|
+
return JSON.stringify(message);
|
|
899
|
+
}
|
|
900
|
+
return message.toString();
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// node_modules/.pnpm/strict-event-emitter@0.5.1/node_modules/strict-event-emitter/lib/index.mjs
|
|
904
|
+
var MemoryLeakError = class extends Error {
|
|
905
|
+
constructor(emitter, type, count) {
|
|
906
|
+
super(
|
|
907
|
+
`Possible EventEmitter memory leak detected. ${count} ${type.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`
|
|
908
|
+
);
|
|
909
|
+
this.emitter = emitter;
|
|
910
|
+
this.type = type;
|
|
911
|
+
this.count = count;
|
|
912
|
+
this.name = "MaxListenersExceededWarning";
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
var _Emitter = class {
|
|
916
|
+
static listenerCount(emitter, eventName) {
|
|
917
|
+
return emitter.listenerCount(eventName);
|
|
918
|
+
}
|
|
919
|
+
constructor() {
|
|
920
|
+
this.events = /* @__PURE__ */ new Map();
|
|
921
|
+
this.maxListeners = _Emitter.defaultMaxListeners;
|
|
922
|
+
this.hasWarnedAboutPotentialMemoryLeak = false;
|
|
923
|
+
}
|
|
924
|
+
_emitInternalEvent(internalEventName, eventName, listener) {
|
|
925
|
+
this.emit(
|
|
926
|
+
internalEventName,
|
|
927
|
+
...[eventName, listener]
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
_getListeners(eventName) {
|
|
931
|
+
return Array.prototype.concat.apply([], this.events.get(eventName)) || [];
|
|
932
|
+
}
|
|
933
|
+
_removeListener(listeners, listener) {
|
|
934
|
+
const index = listeners.indexOf(listener);
|
|
935
|
+
if (index > -1) {
|
|
936
|
+
listeners.splice(index, 1);
|
|
937
|
+
}
|
|
938
|
+
return [];
|
|
939
|
+
}
|
|
940
|
+
_wrapOnceListener(eventName, listener) {
|
|
941
|
+
const onceListener = (...data) => {
|
|
942
|
+
this.removeListener(eventName, onceListener);
|
|
943
|
+
return listener.apply(this, data);
|
|
944
|
+
};
|
|
945
|
+
Object.defineProperty(onceListener, "name", { value: listener.name });
|
|
946
|
+
return onceListener;
|
|
947
|
+
}
|
|
948
|
+
setMaxListeners(maxListeners) {
|
|
949
|
+
this.maxListeners = maxListeners;
|
|
950
|
+
return this;
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Returns the current max listener value for the `Emitter` which is
|
|
954
|
+
* either set by `emitter.setMaxListeners(n)` or defaults to
|
|
955
|
+
* `Emitter.defaultMaxListeners`.
|
|
956
|
+
*/
|
|
957
|
+
getMaxListeners() {
|
|
958
|
+
return this.maxListeners;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Returns an array listing the events for which the emitter has registered listeners.
|
|
962
|
+
* The values in the array will be strings or Symbols.
|
|
963
|
+
*/
|
|
964
|
+
eventNames() {
|
|
965
|
+
return Array.from(this.events.keys());
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Synchronously calls each of the listeners registered for the event named `eventName`,
|
|
969
|
+
* in the order they were registered, passing the supplied arguments to each.
|
|
970
|
+
* Returns `true` if the event has listeners, `false` otherwise.
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
973
|
+
* const emitter = new Emitter<{ hello: [string] }>()
|
|
974
|
+
* emitter.emit('hello', 'John')
|
|
975
|
+
*/
|
|
976
|
+
emit(eventName, ...data) {
|
|
977
|
+
const listeners = this._getListeners(eventName);
|
|
978
|
+
listeners.forEach((listener) => {
|
|
979
|
+
listener.apply(this, data);
|
|
980
|
+
});
|
|
981
|
+
return listeners.length > 0;
|
|
982
|
+
}
|
|
983
|
+
addListener(eventName, listener) {
|
|
984
|
+
this._emitInternalEvent("newListener", eventName, listener);
|
|
985
|
+
const nextListeners = this._getListeners(eventName).concat(listener);
|
|
986
|
+
this.events.set(eventName, nextListeners);
|
|
987
|
+
if (this.maxListeners > 0 && this.listenerCount(eventName) > this.maxListeners && !this.hasWarnedAboutPotentialMemoryLeak) {
|
|
988
|
+
this.hasWarnedAboutPotentialMemoryLeak = true;
|
|
989
|
+
const memoryLeakWarning = new MemoryLeakError(
|
|
990
|
+
this,
|
|
991
|
+
eventName,
|
|
992
|
+
this.listenerCount(eventName)
|
|
993
|
+
);
|
|
994
|
+
console.warn(memoryLeakWarning);
|
|
995
|
+
}
|
|
996
|
+
return this;
|
|
997
|
+
}
|
|
998
|
+
on(eventName, listener) {
|
|
999
|
+
return this.addListener(eventName, listener);
|
|
1000
|
+
}
|
|
1001
|
+
once(eventName, listener) {
|
|
1002
|
+
return this.addListener(
|
|
1003
|
+
eventName,
|
|
1004
|
+
this._wrapOnceListener(eventName, listener)
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
prependListener(eventName, listener) {
|
|
1008
|
+
const listeners = this._getListeners(eventName);
|
|
1009
|
+
if (listeners.length > 0) {
|
|
1010
|
+
const nextListeners = [listener].concat(listeners);
|
|
1011
|
+
this.events.set(eventName, nextListeners);
|
|
1012
|
+
} else {
|
|
1013
|
+
this.events.set(eventName, listeners.concat(listener));
|
|
1014
|
+
}
|
|
1015
|
+
return this;
|
|
1016
|
+
}
|
|
1017
|
+
prependOnceListener(eventName, listener) {
|
|
1018
|
+
return this.prependListener(
|
|
1019
|
+
eventName,
|
|
1020
|
+
this._wrapOnceListener(eventName, listener)
|
|
1021
|
+
);
|
|
1022
|
+
}
|
|
1023
|
+
removeListener(eventName, listener) {
|
|
1024
|
+
const listeners = this._getListeners(eventName);
|
|
1025
|
+
if (listeners.length > 0) {
|
|
1026
|
+
this._removeListener(listeners, listener);
|
|
1027
|
+
this.events.set(eventName, listeners);
|
|
1028
|
+
this._emitInternalEvent("removeListener", eventName, listener);
|
|
1029
|
+
}
|
|
1030
|
+
return this;
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Alias for `emitter.removeListener()`.
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* emitter.off('hello', listener)
|
|
1037
|
+
*/
|
|
1038
|
+
off(eventName, listener) {
|
|
1039
|
+
return this.removeListener(eventName, listener);
|
|
1040
|
+
}
|
|
1041
|
+
removeAllListeners(eventName) {
|
|
1042
|
+
if (eventName) {
|
|
1043
|
+
this.events.delete(eventName);
|
|
1044
|
+
} else {
|
|
1045
|
+
this.events.clear();
|
|
1046
|
+
}
|
|
1047
|
+
return this;
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Returns a copy of the array of listeners for the event named `eventName`.
|
|
1051
|
+
*/
|
|
1052
|
+
listeners(eventName) {
|
|
1053
|
+
return Array.from(this._getListeners(eventName));
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Returns the number of listeners listening to the event named `eventName`.
|
|
1057
|
+
*/
|
|
1058
|
+
listenerCount(eventName) {
|
|
1059
|
+
return this._getListeners(eventName).length;
|
|
1060
|
+
}
|
|
1061
|
+
rawListeners(eventName) {
|
|
1062
|
+
return this.listeners(eventName);
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
var Emitter = _Emitter;
|
|
1066
|
+
Emitter.defaultMaxListeners = 10;
|
|
1067
|
+
|
|
1068
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DQcIlohW.mjs
|
|
1069
|
+
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
1070
|
+
function getGlobalSymbol(symbol) {
|
|
1071
|
+
return globalThis[symbol] || void 0;
|
|
1072
|
+
}
|
|
1073
|
+
function setGlobalSymbol(symbol, value) {
|
|
1074
|
+
globalThis[symbol] = value;
|
|
1075
|
+
}
|
|
1076
|
+
function deleteGlobalSymbol(symbol) {
|
|
1077
|
+
delete globalThis[symbol];
|
|
1078
|
+
}
|
|
1079
|
+
var InterceptorReadyState = /* @__PURE__ */ (function(InterceptorReadyState$1) {
|
|
1080
|
+
InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
|
|
1081
|
+
InterceptorReadyState$1["APPLYING"] = "APPLYING";
|
|
1082
|
+
InterceptorReadyState$1["APPLIED"] = "APPLIED";
|
|
1083
|
+
InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
|
|
1084
|
+
InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
|
|
1085
|
+
return InterceptorReadyState$1;
|
|
1086
|
+
})({});
|
|
1087
|
+
var Interceptor = class {
|
|
1088
|
+
constructor(symbol) {
|
|
1089
|
+
this.symbol = symbol;
|
|
1090
|
+
this.readyState = InterceptorReadyState.INACTIVE;
|
|
1091
|
+
this.emitter = new Emitter();
|
|
1092
|
+
this.subscriptions = [];
|
|
1093
|
+
this.logger = new Logger(symbol.description);
|
|
1094
|
+
this.emitter.setMaxListeners(0);
|
|
1095
|
+
this.logger.info("constructing the interceptor...");
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Determine if this interceptor can be applied
|
|
1099
|
+
* in the current environment.
|
|
1100
|
+
*/
|
|
1101
|
+
checkEnvironment() {
|
|
1102
|
+
return true;
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Apply this interceptor to the current process.
|
|
1106
|
+
* Returns an already running interceptor instance if it's present.
|
|
1107
|
+
*/
|
|
1108
|
+
apply() {
|
|
1109
|
+
const logger = this.logger.extend("apply");
|
|
1110
|
+
logger.info("applying the interceptor...");
|
|
1111
|
+
if (this.readyState === InterceptorReadyState.APPLIED) {
|
|
1112
|
+
logger.info("intercepted already applied!");
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
if (!this.checkEnvironment()) {
|
|
1116
|
+
logger.info("the interceptor cannot be applied in this environment!");
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
this.readyState = InterceptorReadyState.APPLYING;
|
|
1120
|
+
const runningInstance = this.getInstance();
|
|
1121
|
+
if (runningInstance) {
|
|
1122
|
+
logger.info("found a running instance, reusing...");
|
|
1123
|
+
this.on = (event, listener) => {
|
|
1124
|
+
logger.info('proxying the "%s" listener', event);
|
|
1125
|
+
runningInstance.emitter.addListener(event, listener);
|
|
1126
|
+
this.subscriptions.push(() => {
|
|
1127
|
+
runningInstance.emitter.removeListener(event, listener);
|
|
1128
|
+
logger.info('removed proxied "%s" listener!', event);
|
|
1129
|
+
});
|
|
1130
|
+
return this;
|
|
1131
|
+
};
|
|
1132
|
+
this.readyState = InterceptorReadyState.APPLIED;
|
|
1133
|
+
return;
|
|
1134
|
+
}
|
|
1135
|
+
logger.info("no running instance found, setting up a new instance...");
|
|
1136
|
+
this.setup();
|
|
1137
|
+
this.setInstance();
|
|
1138
|
+
this.readyState = InterceptorReadyState.APPLIED;
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Setup the module augments and stubs necessary for this interceptor.
|
|
1142
|
+
* This method is not run if there's a running interceptor instance
|
|
1143
|
+
* to prevent instantiating an interceptor multiple times.
|
|
1144
|
+
*/
|
|
1145
|
+
setup() {
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Listen to the interceptor's public events.
|
|
1149
|
+
*/
|
|
1150
|
+
on(event, listener) {
|
|
1151
|
+
const logger = this.logger.extend("on");
|
|
1152
|
+
if (this.readyState === InterceptorReadyState.DISPOSING || this.readyState === InterceptorReadyState.DISPOSED) {
|
|
1153
|
+
logger.info("cannot listen to events, already disposed!");
|
|
1154
|
+
return this;
|
|
1155
|
+
}
|
|
1156
|
+
logger.info('adding "%s" event listener:', event, listener);
|
|
1157
|
+
this.emitter.on(event, listener);
|
|
1158
|
+
return this;
|
|
1159
|
+
}
|
|
1160
|
+
once(event, listener) {
|
|
1161
|
+
this.emitter.once(event, listener);
|
|
1162
|
+
return this;
|
|
1163
|
+
}
|
|
1164
|
+
off(event, listener) {
|
|
1165
|
+
this.emitter.off(event, listener);
|
|
1166
|
+
return this;
|
|
1167
|
+
}
|
|
1168
|
+
removeAllListeners(event) {
|
|
1169
|
+
this.emitter.removeAllListeners(event);
|
|
1170
|
+
return this;
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* Disposes of any side-effects this interceptor has introduced.
|
|
1174
|
+
*/
|
|
1175
|
+
dispose() {
|
|
1176
|
+
const logger = this.logger.extend("dispose");
|
|
1177
|
+
if (this.readyState === InterceptorReadyState.DISPOSED) {
|
|
1178
|
+
logger.info("cannot dispose, already disposed!");
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
logger.info("disposing the interceptor...");
|
|
1182
|
+
this.readyState = InterceptorReadyState.DISPOSING;
|
|
1183
|
+
if (!this.getInstance()) {
|
|
1184
|
+
logger.info("no interceptors running, skipping dispose...");
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
this.clearInstance();
|
|
1188
|
+
logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
|
|
1189
|
+
if (this.subscriptions.length > 0) {
|
|
1190
|
+
logger.info("disposing of %d subscriptions...", this.subscriptions.length);
|
|
1191
|
+
for (const dispose of this.subscriptions) dispose();
|
|
1192
|
+
this.subscriptions = [];
|
|
1193
|
+
logger.info("disposed of all subscriptions!", this.subscriptions.length);
|
|
1194
|
+
}
|
|
1195
|
+
this.emitter.removeAllListeners();
|
|
1196
|
+
logger.info("destroyed the listener!");
|
|
1197
|
+
this.readyState = InterceptorReadyState.DISPOSED;
|
|
1198
|
+
}
|
|
1199
|
+
getInstance() {
|
|
1200
|
+
const instance = getGlobalSymbol(this.symbol);
|
|
1201
|
+
this.logger.info("retrieved global instance:", instance?.constructor?.name);
|
|
1202
|
+
return instance;
|
|
1203
|
+
}
|
|
1204
|
+
setInstance() {
|
|
1205
|
+
setGlobalSymbol(this.symbol, this);
|
|
1206
|
+
this.logger.info("set global instance!", this.symbol.description);
|
|
1207
|
+
}
|
|
1208
|
+
clearInstance() {
|
|
1209
|
+
deleteGlobalSymbol(this.symbol);
|
|
1210
|
+
this.logger.info("cleared global instance!", this.symbol.description);
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
function createRequestId() {
|
|
1214
|
+
return Math.random().toString(16).slice(2);
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/bufferUtils-BiiO6HZv.mjs
|
|
1218
|
+
var encoder = new TextEncoder();
|
|
1219
|
+
function encodeBuffer(text) {
|
|
1220
|
+
return encoder.encode(text);
|
|
1221
|
+
}
|
|
1222
|
+
function decodeBuffer(buffer, encoding) {
|
|
1223
|
+
return new TextDecoder(encoding).decode(buffer);
|
|
1224
|
+
}
|
|
1225
|
+
function toArrayBuffer(array) {
|
|
1226
|
+
return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1230
|
+
var BatchInterceptor = class BatchInterceptor2 extends Interceptor {
|
|
1231
|
+
constructor(options) {
|
|
1232
|
+
BatchInterceptor2.symbol = Symbol(options.name);
|
|
1233
|
+
super(BatchInterceptor2.symbol);
|
|
1234
|
+
this.interceptors = options.interceptors;
|
|
1235
|
+
}
|
|
1236
|
+
setup() {
|
|
1237
|
+
const logger = this.logger.extend("setup");
|
|
1238
|
+
logger.info("applying all %d interceptors...", this.interceptors.length);
|
|
1239
|
+
for (const interceptor of this.interceptors) {
|
|
1240
|
+
logger.info('applying "%s" interceptor...', interceptor.constructor.name);
|
|
1241
|
+
interceptor.apply();
|
|
1242
|
+
logger.info("adding interceptor dispose subscription");
|
|
1243
|
+
this.subscriptions.push(() => interceptor.dispose());
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
on(event, listener) {
|
|
1247
|
+
for (const interceptor of this.interceptors) interceptor.on(event, listener);
|
|
1248
|
+
return this;
|
|
1249
|
+
}
|
|
1250
|
+
once(event, listener) {
|
|
1251
|
+
for (const interceptor of this.interceptors) interceptor.once(event, listener);
|
|
1252
|
+
return this;
|
|
1253
|
+
}
|
|
1254
|
+
off(event, listener) {
|
|
1255
|
+
for (const interceptor of this.interceptors) interceptor.off(event, listener);
|
|
1256
|
+
return this;
|
|
1257
|
+
}
|
|
1258
|
+
removeAllListeners(event) {
|
|
1259
|
+
for (const interceptors of this.interceptors) interceptors.removeAllListeners(event);
|
|
1260
|
+
return this;
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
// src/browser/setupWorker/start/createResponseListener.ts
|
|
1265
|
+
function createResponseListener(context) {
|
|
1266
|
+
return (event) => {
|
|
1267
|
+
const responseMessage = event.data;
|
|
1268
|
+
const request = deserializeRequest(responseMessage.request);
|
|
1269
|
+
if (responseMessage.response.type?.includes("opaque")) {
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
const response = responseMessage.response.status === 0 ? Response.error() : new FetchResponse(
|
|
1273
|
+
/**
|
|
1274
|
+
* Responses may be streams here, but when we create a response object
|
|
1275
|
+
* with null-body status codes, like 204, 205, 304 Response will
|
|
1276
|
+
* throw when passed a non-null body, so ensure it's null here
|
|
1277
|
+
* for those codes
|
|
1278
|
+
*/
|
|
1279
|
+
FetchResponse.isResponseWithBody(responseMessage.response.status) ? responseMessage.response.body : null,
|
|
1280
|
+
{
|
|
1281
|
+
...responseMessage.response,
|
|
1282
|
+
/**
|
|
1283
|
+
* Set response URL if it's not set already.
|
|
1284
|
+
* @see https://github.com/mswjs/msw/issues/2030
|
|
1285
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
|
|
1286
|
+
*/
|
|
1287
|
+
url: request.url
|
|
1288
|
+
}
|
|
1289
|
+
);
|
|
1290
|
+
context.emitter.emit(
|
|
1291
|
+
responseMessage.isMockedResponse ? "response:mocked" : "response:bypass",
|
|
1292
|
+
{
|
|
1293
|
+
requestId: responseMessage.request.id,
|
|
1294
|
+
request,
|
|
1295
|
+
response
|
|
1296
|
+
}
|
|
1297
|
+
);
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// src/browser/setupWorker/start/utils/validateWorkerScope.ts
|
|
1302
|
+
import { devUtils as devUtils5 } from '../core/utils/internal/devUtils.mjs';
|
|
1303
|
+
function validateWorkerScope(registration, options) {
|
|
1304
|
+
if (!options?.quiet && !location.href.startsWith(registration.scope)) {
|
|
1305
|
+
devUtils5.warn(
|
|
1306
|
+
`Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
|
|
1307
|
+
|
|
1308
|
+
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
1309
|
+
- Set the "Service-Worker-Allowed" response header to allow out-of-scope workers.`
|
|
1310
|
+
);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
// src/browser/setupWorker/start/createStartHandler.ts
|
|
1315
|
+
var createStartHandler = (context) => {
|
|
1316
|
+
return function start(options, customOptions) {
|
|
1317
|
+
const startWorkerInstance = async () => {
|
|
1318
|
+
context.workerChannel.removeAllListeners();
|
|
1319
|
+
context.workerChannel.on(
|
|
1320
|
+
"REQUEST",
|
|
1321
|
+
createRequestListener(context, options)
|
|
1322
|
+
);
|
|
1323
|
+
context.workerChannel.on("RESPONSE", createResponseListener(context));
|
|
1324
|
+
const instance = await getWorkerInstance(
|
|
1325
|
+
options.serviceWorker.url,
|
|
1326
|
+
options.serviceWorker.options,
|
|
1327
|
+
options.findWorker
|
|
1328
|
+
);
|
|
1329
|
+
const [worker, registration] = instance;
|
|
1330
|
+
if (!worker) {
|
|
1331
|
+
const missingWorkerMessage = customOptions?.findWorker ? devUtils6.formatMessage(
|
|
1332
|
+
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
1333
|
+
|
|
1334
|
+
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
1335
|
+
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
1336
|
+
`,
|
|
1337
|
+
options.serviceWorker.url
|
|
1338
|
+
) : devUtils6.formatMessage(
|
|
1339
|
+
`Failed to locate the Service Worker registration.
|
|
1340
|
+
|
|
1341
|
+
This most likely means that the worker script URL "%s" cannot resolve against the actual public hostname (%s). This may happen if your application runs behind a proxy, or has a dynamic hostname.
|
|
1342
|
+
|
|
1343
|
+
Please consider using a custom "serviceWorker.url" option to point to the actual worker script location, or a custom "findWorker" option to resolve the Service Worker registration manually. More details: https://mswjs.io/docs/api/setup-worker/start`,
|
|
1344
|
+
options.serviceWorker.url,
|
|
1345
|
+
location.host
|
|
1346
|
+
);
|
|
1347
|
+
throw new Error(missingWorkerMessage);
|
|
1348
|
+
}
|
|
1349
|
+
context.workerPromise.resolve(worker);
|
|
1350
|
+
context.registration = registration;
|
|
1351
|
+
window.addEventListener("beforeunload", () => {
|
|
1352
|
+
if (worker.state !== "redundant") {
|
|
1353
|
+
context.workerChannel.postMessage("CLIENT_CLOSED");
|
|
1354
|
+
}
|
|
1355
|
+
window.clearInterval(context.keepAliveInterval);
|
|
1356
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
1357
|
+
});
|
|
1358
|
+
await checkWorkerIntegrity(context).catch((error2) => {
|
|
1359
|
+
devUtils6.error(
|
|
1360
|
+
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
1361
|
+
);
|
|
1362
|
+
console.error(error2);
|
|
1363
|
+
});
|
|
1364
|
+
context.keepAliveInterval = window.setInterval(
|
|
1365
|
+
() => context.workerChannel.postMessage("KEEPALIVE_REQUEST"),
|
|
1366
|
+
5e3
|
|
1367
|
+
);
|
|
1368
|
+
validateWorkerScope(registration, context.startOptions);
|
|
1369
|
+
return registration;
|
|
1370
|
+
};
|
|
1371
|
+
const workerRegistration = startWorkerInstance().then(
|
|
1372
|
+
async (registration) => {
|
|
1373
|
+
const pendingInstance = registration.installing || registration.waiting;
|
|
1374
|
+
if (pendingInstance) {
|
|
1375
|
+
const activationPromise = new DeferredPromise();
|
|
1376
|
+
pendingInstance.addEventListener("statechange", () => {
|
|
1377
|
+
if (pendingInstance.state === "activated") {
|
|
1378
|
+
activationPromise.resolve();
|
|
1379
|
+
}
|
|
1380
|
+
});
|
|
1381
|
+
await activationPromise;
|
|
1382
|
+
}
|
|
1383
|
+
await enableMocking(context, options).catch((error2) => {
|
|
1384
|
+
devUtils6.error(
|
|
1385
|
+
"Failed to enable mocking. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
1386
|
+
);
|
|
1387
|
+
throw error2;
|
|
1388
|
+
});
|
|
1389
|
+
return registration;
|
|
1390
|
+
}
|
|
1391
|
+
);
|
|
1392
|
+
return workerRegistration;
|
|
1393
|
+
};
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1396
|
+
// src/browser/setupWorker/setupWorker.ts
|
|
1397
|
+
import { devUtils as devUtils8 } from '../core/utils/internal/devUtils.mjs';
|
|
1398
|
+
import { SetupApi } from '../core/SetupApi.mjs';
|
|
1399
|
+
import { mergeRight as mergeRight2 } from '../core/utils/internal/mergeRight.mjs';
|
|
1400
|
+
import { webSocketInterceptor } from '../core/ws/webSocketInterceptor.mjs';
|
|
1401
|
+
import { handleWebSocketEvent } from '../core/ws/handleWebSocketEvent.mjs';
|
|
1402
|
+
import { attachWebSocketLogger } from '../core/ws/utils/attachWebSocketLogger.mjs';
|
|
1403
|
+
|
|
1404
|
+
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/lens-list.mjs
|
|
1405
|
+
var LensList = class {
|
|
1406
|
+
#list;
|
|
1407
|
+
#lens;
|
|
1408
|
+
constructor() {
|
|
1409
|
+
this.#list = [];
|
|
1410
|
+
this.#lens = /* @__PURE__ */ new Map();
|
|
1411
|
+
}
|
|
1412
|
+
get [Symbol.iterator]() {
|
|
1413
|
+
return this.#list[Symbol.iterator].bind(this.#list);
|
|
1414
|
+
}
|
|
1415
|
+
entries() {
|
|
1416
|
+
return this.#lens.entries();
|
|
1417
|
+
}
|
|
1418
|
+
/**
|
|
1419
|
+
* Return an order-sensitive list of values by the given key.
|
|
1420
|
+
*/
|
|
1421
|
+
get(key) {
|
|
1422
|
+
return this.#lens.get(key) || [];
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* Return an order-sensitive list of all values.
|
|
1426
|
+
*/
|
|
1427
|
+
getAll() {
|
|
1428
|
+
return this.#list.map(([, value]) => value);
|
|
1429
|
+
}
|
|
1430
|
+
/**
|
|
1431
|
+
* Append a new value to the given key.
|
|
1432
|
+
*/
|
|
1433
|
+
append(key, value) {
|
|
1434
|
+
this.#list.push([key, value]);
|
|
1435
|
+
this.#openLens(key, (list) => list.push(value));
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Prepend a new value to the given key.
|
|
1439
|
+
*/
|
|
1440
|
+
prepend(key, value) {
|
|
1441
|
+
this.#list.unshift([key, value]);
|
|
1442
|
+
this.#openLens(key, (list) => list.unshift(value));
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Delete the value belonging to the given key.
|
|
1446
|
+
*/
|
|
1447
|
+
delete(key, value) {
|
|
1448
|
+
if (this.size === 0) return;
|
|
1449
|
+
this.#list = this.#list.filter((item) => item[1] !== value);
|
|
1450
|
+
for (const [existingKey, values] of this.#lens) if (existingKey === key && values.includes(value)) values.splice(values.indexOf(value), 1);
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Delete all values belogning to the given key.
|
|
1454
|
+
*/
|
|
1455
|
+
deleteAll(key) {
|
|
1456
|
+
if (this.size === 0) return;
|
|
1457
|
+
this.#list = this.#list.filter((item) => item[0] !== key);
|
|
1458
|
+
this.#lens.delete(key);
|
|
1459
|
+
}
|
|
1460
|
+
get size() {
|
|
1461
|
+
return this.#list.length;
|
|
1462
|
+
}
|
|
1463
|
+
clear() {
|
|
1464
|
+
if (this.size === 0) return;
|
|
1465
|
+
this.#list.length = 0;
|
|
1466
|
+
this.#lens.clear();
|
|
1467
|
+
}
|
|
1468
|
+
#openLens(key, setter) {
|
|
1469
|
+
setter(this.#lens.get(key) || this.#lens.set(key, []).get(key));
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
|
|
1473
|
+
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/index.mjs
|
|
1474
|
+
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
1475
|
+
var kPropagationStopped = Symbol("kPropagationStopped");
|
|
1476
|
+
var kImmediatePropagationStopped = Symbol("kImmediatePropagationStopped");
|
|
1477
|
+
var TypedEvent = class extends MessageEvent {
|
|
1478
|
+
/**
|
|
1479
|
+
* @note Keep a placeholder property with the return type
|
|
1480
|
+
* because the type must be set somewhere in order to be
|
|
1481
|
+
* correctly associated and inferred from the event.
|
|
1482
|
+
*/
|
|
1483
|
+
#returnType;
|
|
1484
|
+
[kDefaultPrevented];
|
|
1485
|
+
[kPropagationStopped];
|
|
1486
|
+
[kImmediatePropagationStopped];
|
|
1487
|
+
constructor(...args) {
|
|
1488
|
+
super(args[0], args[1]);
|
|
1489
|
+
this[kDefaultPrevented] = false;
|
|
1490
|
+
}
|
|
1491
|
+
get defaultPrevented() {
|
|
1492
|
+
return this[kDefaultPrevented];
|
|
1493
|
+
}
|
|
1494
|
+
preventDefault() {
|
|
1495
|
+
super.preventDefault();
|
|
1496
|
+
this[kDefaultPrevented] = true;
|
|
1497
|
+
}
|
|
1498
|
+
stopImmediatePropagation() {
|
|
1499
|
+
super.stopImmediatePropagation();
|
|
1500
|
+
this[kImmediatePropagationStopped] = true;
|
|
1501
|
+
}
|
|
1502
|
+
};
|
|
1503
|
+
var kListenerOptions = Symbol("kListenerOptions");
|
|
1504
|
+
var Emitter2 = class {
|
|
1505
|
+
#listeners;
|
|
1506
|
+
constructor() {
|
|
1507
|
+
this.#listeners = new LensList();
|
|
1508
|
+
}
|
|
1509
|
+
/**
|
|
1510
|
+
* Adds a listener for the given event type.
|
|
1511
|
+
*/
|
|
1512
|
+
on(type, listener, options) {
|
|
1513
|
+
this.#addListener(type, listener, options);
|
|
1514
|
+
return this;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Adds a one-time listener for the given event type.
|
|
1518
|
+
*/
|
|
1519
|
+
once(type, listener, options) {
|
|
1520
|
+
return this.on(type, listener, {
|
|
1521
|
+
...options || {},
|
|
1522
|
+
once: true
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
/**
|
|
1526
|
+
* Prepends a listener for the given event type.
|
|
1527
|
+
*/
|
|
1528
|
+
earlyOn(type, listener, options) {
|
|
1529
|
+
this.#addListener(type, listener, options, "prepend");
|
|
1530
|
+
return this;
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Prepends a one-time listener for the given event type.
|
|
1534
|
+
*/
|
|
1535
|
+
earlyOnce(type, listener, options) {
|
|
1536
|
+
return this.earlyOn(type, listener, {
|
|
1537
|
+
...options || {},
|
|
1538
|
+
once: true
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Emits the given typed event.
|
|
1543
|
+
*
|
|
1544
|
+
* @returns {boolean} Returns `true` if the event had any listeners, `false` otherwise.
|
|
1545
|
+
*/
|
|
1546
|
+
emit(event) {
|
|
1547
|
+
if (this.#listeners.size === 0) return false;
|
|
1548
|
+
const hasListeners = this.listenerCount(event.type) > 0;
|
|
1549
|
+
const proxiedEvent = this.#proxyEvent(event);
|
|
1550
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
1551
|
+
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
1552
|
+
proxiedEvent.revoke();
|
|
1553
|
+
return false;
|
|
1554
|
+
}
|
|
1555
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
1556
|
+
this.#callListener(proxiedEvent.event, listener);
|
|
1557
|
+
}
|
|
1558
|
+
proxiedEvent.revoke();
|
|
1559
|
+
return hasListeners;
|
|
1560
|
+
}
|
|
1561
|
+
/**
|
|
1562
|
+
* Emits the given typed event and returns a promise that resolves
|
|
1563
|
+
* when all the listeners for that event have settled.
|
|
1564
|
+
*
|
|
1565
|
+
* @returns {Promise<Array<Emitter.ListenerReturnType>>} A promise that resolves
|
|
1566
|
+
* with the return values of all listeners.
|
|
1567
|
+
*/
|
|
1568
|
+
async emitAsPromise(event) {
|
|
1569
|
+
if (this.#listeners.size === 0) return [];
|
|
1570
|
+
const pendingListeners = [];
|
|
1571
|
+
const proxiedEvent = this.#proxyEvent(event);
|
|
1572
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
1573
|
+
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
1574
|
+
proxiedEvent.revoke();
|
|
1575
|
+
return [];
|
|
1576
|
+
}
|
|
1577
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
1578
|
+
const returnValue = await Promise.resolve(this.#callListener(proxiedEvent.event, listener));
|
|
1579
|
+
if (!this.#isTypelessListener(listener)) pendingListeners.push(returnValue);
|
|
1580
|
+
}
|
|
1581
|
+
proxiedEvent.revoke();
|
|
1582
|
+
return Promise.allSettled(pendingListeners).then((results) => {
|
|
1583
|
+
return results.map((result) => result.status === "fulfilled" ? result.value : result.reason);
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Emits the given event and returns a generator that yields
|
|
1588
|
+
* the result of each listener in the order of their registration.
|
|
1589
|
+
* This way, you stop exhausting the listeners once you get the expected value.
|
|
1590
|
+
*/
|
|
1591
|
+
*emitAsGenerator(event) {
|
|
1592
|
+
if (this.#listeners.size === 0) return;
|
|
1593
|
+
const proxiedEvent = this.#proxyEvent(event);
|
|
1594
|
+
for (const listener of this.#matchListeners(event.type)) {
|
|
1595
|
+
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
1596
|
+
proxiedEvent.revoke();
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
1600
|
+
const returnValue = this.#callListener(proxiedEvent.event, listener);
|
|
1601
|
+
if (!this.#isTypelessListener(listener)) yield returnValue;
|
|
1602
|
+
}
|
|
1603
|
+
proxiedEvent.revoke();
|
|
1604
|
+
}
|
|
1605
|
+
/**
|
|
1606
|
+
* Removes a listener for the given event type.
|
|
1607
|
+
*/
|
|
1608
|
+
removeListener(type, listener) {
|
|
1609
|
+
this.#listeners.delete(type, listener);
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Removes all listeners for the given event type.
|
|
1613
|
+
* If no event type is provided, removes all existing listeners.
|
|
1614
|
+
*/
|
|
1615
|
+
removeAllListeners(type) {
|
|
1616
|
+
if (type == null) {
|
|
1617
|
+
this.#listeners.clear();
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
this.#listeners.deleteAll(type);
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Returns the list of listeners for the given event type.
|
|
1624
|
+
* If no even type is provided, returns all listeners.
|
|
1625
|
+
*/
|
|
1626
|
+
listeners(type) {
|
|
1627
|
+
if (type == null) return this.#listeners.getAll();
|
|
1628
|
+
return this.#listeners.get(type);
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Returns the number of listeners for the given event type.
|
|
1632
|
+
* If no even type is provided, returns the total number of listeners.
|
|
1633
|
+
*/
|
|
1634
|
+
listenerCount(type) {
|
|
1635
|
+
if (type == null) return this.#listeners.size;
|
|
1636
|
+
return this.listeners(type).length;
|
|
1637
|
+
}
|
|
1638
|
+
#addListener(type, listener, options, insertMode = "append") {
|
|
1639
|
+
if (insertMode === "prepend") this.#listeners.prepend(type, listener);
|
|
1640
|
+
else this.#listeners.append(type, listener);
|
|
1641
|
+
if (options) {
|
|
1642
|
+
Object.defineProperty(listener, kListenerOptions, {
|
|
1643
|
+
value: options,
|
|
1644
|
+
enumerable: false,
|
|
1645
|
+
writable: false
|
|
1646
|
+
});
|
|
1647
|
+
if (options.signal) options.signal.addEventListener("abort", () => {
|
|
1648
|
+
this.removeListener(type, listener);
|
|
1649
|
+
}, { once: true });
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
#proxyEvent(event) {
|
|
1653
|
+
const { stopPropagation } = event;
|
|
1654
|
+
event.stopPropagation = new Proxy(event.stopPropagation, { apply: (target, thisArg, argArray) => {
|
|
1655
|
+
event[kPropagationStopped] = this;
|
|
1656
|
+
return Reflect.apply(target, thisArg, argArray);
|
|
1657
|
+
} });
|
|
1658
|
+
return {
|
|
1659
|
+
event,
|
|
1660
|
+
revoke() {
|
|
1661
|
+
event.stopPropagation = stopPropagation;
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
#callListener(event, listener) {
|
|
1666
|
+
const returnValue = listener.call(this, event);
|
|
1667
|
+
if (listener[kListenerOptions]?.once) {
|
|
1668
|
+
const key = this.#isTypelessListener(listener) ? "*" : event.type;
|
|
1669
|
+
this.#listeners.delete(key, listener);
|
|
1670
|
+
}
|
|
1671
|
+
return returnValue;
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Return a list of all event listeners relevant for the given event type.
|
|
1675
|
+
* This includes the explicit event listeners and also typeless event listeners.
|
|
1676
|
+
*/
|
|
1677
|
+
*#matchListeners(type) {
|
|
1678
|
+
for (const [key, listener] of this.#listeners) if (key === "*" || key === type) yield listener;
|
|
1679
|
+
}
|
|
1680
|
+
#isTypelessListener(listener) {
|
|
1681
|
+
return this.#listeners.get("*").includes(listener);
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
|
|
1685
|
+
// src/browser/utils/workerChannel.ts
|
|
1686
|
+
import { isObject } from '../core/utils/internal/isObject.mjs';
|
|
1687
|
+
var SUPPORTS_SERVICE_WORKER = supportsServiceWorker();
|
|
1688
|
+
var WorkerEvent = class extends TypedEvent {
|
|
1689
|
+
#workerEvent;
|
|
1690
|
+
constructor(workerEvent) {
|
|
1691
|
+
const type = workerEvent.data.type;
|
|
1692
|
+
const data = workerEvent.data.payload;
|
|
1693
|
+
super(
|
|
1694
|
+
// @ts-expect-error Troublesome `TypedEvent` extension.
|
|
1695
|
+
type,
|
|
1696
|
+
{ data }
|
|
1697
|
+
);
|
|
1698
|
+
this.#workerEvent = workerEvent;
|
|
1699
|
+
}
|
|
1700
|
+
get ports() {
|
|
1701
|
+
return this.#workerEvent.ports;
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Reply directly to this event using its `MessagePort`.
|
|
1705
|
+
*/
|
|
1706
|
+
postMessage(type, ...rest) {
|
|
1707
|
+
this.#workerEvent.ports[0].postMessage(
|
|
1708
|
+
{ type, data: rest[0] },
|
|
1709
|
+
{ transfer: rest[1] }
|
|
1710
|
+
);
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
var WorkerChannel = class extends Emitter2 {
|
|
1714
|
+
constructor(options) {
|
|
1715
|
+
super();
|
|
1716
|
+
this.options = options;
|
|
1717
|
+
if (!SUPPORTS_SERVICE_WORKER) {
|
|
1718
|
+
return;
|
|
1719
|
+
}
|
|
1720
|
+
navigator.serviceWorker.addEventListener("message", async (event) => {
|
|
1721
|
+
const worker = await this.options.worker;
|
|
1722
|
+
if (event.source != null && event.source !== worker) {
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
if (event.data && isObject(event.data) && "type" in event.data) {
|
|
1726
|
+
this.emit(new WorkerEvent(event));
|
|
1727
|
+
}
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Send data to the Service Worker controlling this client.
|
|
1732
|
+
* This triggers the `message` event listener on ServiceWorkerGlobalScope.
|
|
1733
|
+
*/
|
|
1734
|
+
postMessage(type) {
|
|
1735
|
+
invariant(
|
|
1736
|
+
SUPPORTS_SERVICE_WORKER,
|
|
1737
|
+
"Failed to post message on a WorkerChannel: the Service Worker API is unavailable in this context. This is likely an issue with MSW. Please report it on GitHub: https://github.com/mswjs/msw/issues"
|
|
1738
|
+
);
|
|
1739
|
+
this.options.worker.then((worker) => {
|
|
1740
|
+
worker.postMessage(type);
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
|
|
1745
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-npXitu1-.mjs
|
|
1746
|
+
async function emitAsync(emitter, eventName, ...data) {
|
|
1747
|
+
const listeners = emitter.listeners(eventName);
|
|
1748
|
+
if (listeners.length === 0) return;
|
|
1749
|
+
for (const listener of listeners) await listener.apply(emitter, data);
|
|
1750
|
+
}
|
|
1751
|
+
function hasConfigurableGlobal(propertyName) {
|
|
1752
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
1753
|
+
if (typeof descriptor === "undefined") return false;
|
|
1754
|
+
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
1755
|
+
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
1756
|
+
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
1757
|
+
console.error(`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`);
|
|
1758
|
+
return false;
|
|
1759
|
+
}
|
|
1760
|
+
return true;
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
1764
|
+
var until2 = async (promise) => {
|
|
1765
|
+
try {
|
|
1766
|
+
const data = await promise().catch((error2) => {
|
|
1767
|
+
throw error2;
|
|
1768
|
+
});
|
|
1769
|
+
return { error: null, data };
|
|
1770
|
+
} catch (error2) {
|
|
1771
|
+
return { error: error2, data: null };
|
|
1772
|
+
}
|
|
1773
|
+
};
|
|
1774
|
+
|
|
1775
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/handleRequest-D7kpTI5U.mjs
|
|
1776
|
+
function isObject2(value, loose = false) {
|
|
1777
|
+
return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
|
|
1778
|
+
}
|
|
1779
|
+
function isPropertyAccessible(obj, key) {
|
|
1780
|
+
try {
|
|
1781
|
+
obj[key];
|
|
1782
|
+
return true;
|
|
1783
|
+
} catch {
|
|
1784
|
+
return false;
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
function createServerErrorResponse(body) {
|
|
1788
|
+
return new Response(JSON.stringify(body instanceof Error ? {
|
|
1789
|
+
name: body.name,
|
|
1790
|
+
message: body.message,
|
|
1791
|
+
stack: body.stack
|
|
1792
|
+
} : body), {
|
|
1793
|
+
status: 500,
|
|
1794
|
+
statusText: "Unhandled Exception",
|
|
1795
|
+
headers: { "Content-Type": "application/json" }
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
function isResponseError(response) {
|
|
1799
|
+
return response != null && response instanceof Response && isPropertyAccessible(response, "type") && response.type === "error";
|
|
1800
|
+
}
|
|
1801
|
+
function isResponseLike(value) {
|
|
1802
|
+
return isObject2(value, true) && isPropertyAccessible(value, "status") && isPropertyAccessible(value, "statusText") && isPropertyAccessible(value, "bodyUsed");
|
|
1803
|
+
}
|
|
1804
|
+
function isNodeLikeError(error2) {
|
|
1805
|
+
if (error2 == null) return false;
|
|
1806
|
+
if (!(error2 instanceof Error)) return false;
|
|
1807
|
+
return "code" in error2 && "errno" in error2;
|
|
1808
|
+
}
|
|
1809
|
+
async function handleRequest2(options) {
|
|
1810
|
+
const handleResponse = async (response) => {
|
|
1811
|
+
if (response instanceof Error) {
|
|
1812
|
+
await options.controller.errorWith(response);
|
|
1813
|
+
return true;
|
|
1814
|
+
}
|
|
1815
|
+
if (isResponseError(response)) {
|
|
1816
|
+
await options.controller.respondWith(response);
|
|
1817
|
+
return true;
|
|
1818
|
+
}
|
|
1819
|
+
if (isResponseLike(response)) {
|
|
1820
|
+
await options.controller.respondWith(response);
|
|
1821
|
+
return true;
|
|
1822
|
+
}
|
|
1823
|
+
if (isObject2(response)) {
|
|
1824
|
+
await options.controller.errorWith(response);
|
|
1825
|
+
return true;
|
|
1826
|
+
}
|
|
1827
|
+
return false;
|
|
1828
|
+
};
|
|
1829
|
+
const handleResponseError = async (error2) => {
|
|
1830
|
+
if (error2 instanceof InterceptorError) throw result.error;
|
|
1831
|
+
if (isNodeLikeError(error2)) {
|
|
1832
|
+
await options.controller.errorWith(error2);
|
|
1833
|
+
return true;
|
|
1834
|
+
}
|
|
1835
|
+
if (error2 instanceof Response) return await handleResponse(error2);
|
|
1836
|
+
return false;
|
|
1837
|
+
};
|
|
1838
|
+
const requestAbortPromise = new DeferredPromise();
|
|
1839
|
+
if (options.request.signal) {
|
|
1840
|
+
if (options.request.signal.aborted) {
|
|
1841
|
+
await options.controller.errorWith(options.request.signal.reason);
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1844
|
+
options.request.signal.addEventListener("abort", () => {
|
|
1845
|
+
requestAbortPromise.reject(options.request.signal.reason);
|
|
1846
|
+
}, { once: true });
|
|
1847
|
+
}
|
|
1848
|
+
const result = await until2(async () => {
|
|
1849
|
+
const requestListenersPromise = emitAsync(options.emitter, "request", {
|
|
1850
|
+
requestId: options.requestId,
|
|
1851
|
+
request: options.request,
|
|
1852
|
+
controller: options.controller
|
|
1853
|
+
});
|
|
1854
|
+
await Promise.race([
|
|
1855
|
+
requestAbortPromise,
|
|
1856
|
+
requestListenersPromise,
|
|
1857
|
+
options.controller.handled
|
|
1858
|
+
]);
|
|
1859
|
+
});
|
|
1860
|
+
if (requestAbortPromise.state === "rejected") {
|
|
1861
|
+
await options.controller.errorWith(requestAbortPromise.rejectionReason);
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
if (result.error) {
|
|
1865
|
+
if (await handleResponseError(result.error)) return;
|
|
1866
|
+
if (options.emitter.listenerCount("unhandledException") > 0) {
|
|
1867
|
+
const unhandledExceptionController = new RequestController(options.request, {
|
|
1868
|
+
passthrough() {
|
|
1869
|
+
},
|
|
1870
|
+
async respondWith(response) {
|
|
1871
|
+
await handleResponse(response);
|
|
1872
|
+
},
|
|
1873
|
+
async errorWith(reason) {
|
|
1874
|
+
await options.controller.errorWith(reason);
|
|
1875
|
+
}
|
|
1876
|
+
});
|
|
1877
|
+
await emitAsync(options.emitter, "unhandledException", {
|
|
1878
|
+
error: result.error,
|
|
1879
|
+
request: options.request,
|
|
1880
|
+
requestId: options.requestId,
|
|
1881
|
+
controller: unhandledExceptionController
|
|
1882
|
+
});
|
|
1883
|
+
if (unhandledExceptionController.readyState !== RequestController.PENDING) return;
|
|
1884
|
+
}
|
|
1885
|
+
await options.controller.respondWith(createServerErrorResponse(result.error));
|
|
1886
|
+
return;
|
|
1887
|
+
}
|
|
1888
|
+
if (options.controller.readyState === RequestController.PENDING) return await options.controller.passthrough();
|
|
1889
|
+
return options.controller.handled;
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/fetch-DdKEdDOR.mjs
|
|
1893
|
+
function createNetworkError(cause) {
|
|
1894
|
+
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
|
1895
|
+
}
|
|
1896
|
+
var REQUEST_BODY_HEADERS = [
|
|
1897
|
+
"content-encoding",
|
|
1898
|
+
"content-language",
|
|
1899
|
+
"content-location",
|
|
1900
|
+
"content-type",
|
|
1901
|
+
"content-length"
|
|
1902
|
+
];
|
|
1903
|
+
var kRedirectCount = Symbol("kRedirectCount");
|
|
1904
|
+
async function followFetchRedirect(request, response) {
|
|
1905
|
+
if (response.status !== 303 && request.body != null) return Promise.reject(createNetworkError());
|
|
1906
|
+
const requestUrl = new URL(request.url);
|
|
1907
|
+
let locationUrl;
|
|
1908
|
+
try {
|
|
1909
|
+
locationUrl = new URL(response.headers.get("location"), request.url);
|
|
1910
|
+
} catch (error2) {
|
|
1911
|
+
return Promise.reject(createNetworkError(error2));
|
|
1912
|
+
}
|
|
1913
|
+
if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) return Promise.reject(createNetworkError("URL scheme must be a HTTP(S) scheme"));
|
|
1914
|
+
if (Reflect.get(request, kRedirectCount) > 20) return Promise.reject(createNetworkError("redirect count exceeded"));
|
|
1915
|
+
Object.defineProperty(request, kRedirectCount, { value: (Reflect.get(request, kRedirectCount) || 0) + 1 });
|
|
1916
|
+
if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) return Promise.reject(createNetworkError('cross origin not allowed for request mode "cors"'));
|
|
1917
|
+
const requestInit = {};
|
|
1918
|
+
if ([301, 302].includes(response.status) && request.method === "POST" || response.status === 303 && !["HEAD", "GET"].includes(request.method)) {
|
|
1919
|
+
requestInit.method = "GET";
|
|
1920
|
+
requestInit.body = null;
|
|
1921
|
+
REQUEST_BODY_HEADERS.forEach((headerName) => {
|
|
1922
|
+
request.headers.delete(headerName);
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
if (!sameOrigin(requestUrl, locationUrl)) {
|
|
1926
|
+
request.headers.delete("authorization");
|
|
1927
|
+
request.headers.delete("proxy-authorization");
|
|
1928
|
+
request.headers.delete("cookie");
|
|
1929
|
+
request.headers.delete("host");
|
|
1930
|
+
}
|
|
1931
|
+
requestInit.headers = request.headers;
|
|
1932
|
+
const finalResponse = await fetch(new Request(locationUrl, requestInit));
|
|
1933
|
+
Object.defineProperty(finalResponse, "redirected", {
|
|
1934
|
+
value: true,
|
|
1935
|
+
configurable: true
|
|
1936
|
+
});
|
|
1937
|
+
return finalResponse;
|
|
1938
|
+
}
|
|
1939
|
+
function sameOrigin(left, right) {
|
|
1940
|
+
if (left.origin === right.origin && left.origin === "null") return true;
|
|
1941
|
+
if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) return true;
|
|
1942
|
+
return false;
|
|
1943
|
+
}
|
|
1944
|
+
var BrotliDecompressionStream = class extends TransformStream {
|
|
1945
|
+
constructor() {
|
|
1946
|
+
console.warn("[Interceptors]: Brotli decompression of response streams is not supported in the browser");
|
|
1947
|
+
super({ transform(chunk, controller) {
|
|
1948
|
+
controller.enqueue(chunk);
|
|
1949
|
+
} });
|
|
1950
|
+
}
|
|
1951
|
+
};
|
|
1952
|
+
var PipelineStream = class extends TransformStream {
|
|
1953
|
+
constructor(transformStreams, ...strategies) {
|
|
1954
|
+
super({}, ...strategies);
|
|
1955
|
+
const readable = [super.readable, ...transformStreams].reduce((readable$1, transform) => readable$1.pipeThrough(transform));
|
|
1956
|
+
Object.defineProperty(this, "readable", { get() {
|
|
1957
|
+
return readable;
|
|
1958
|
+
} });
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
function parseContentEncoding(contentEncoding) {
|
|
1962
|
+
return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
|
|
1963
|
+
}
|
|
1964
|
+
function createDecompressionStream(contentEncoding) {
|
|
1965
|
+
if (contentEncoding === "") return null;
|
|
1966
|
+
const codings = parseContentEncoding(contentEncoding);
|
|
1967
|
+
if (codings.length === 0) return null;
|
|
1968
|
+
return new PipelineStream(codings.reduceRight((transformers, coding) => {
|
|
1969
|
+
if (coding === "gzip" || coding === "x-gzip") return transformers.concat(new DecompressionStream("gzip"));
|
|
1970
|
+
else if (coding === "deflate") return transformers.concat(new DecompressionStream("deflate"));
|
|
1971
|
+
else if (coding === "br") return transformers.concat(new BrotliDecompressionStream());
|
|
1972
|
+
else transformers.length = 0;
|
|
1973
|
+
return transformers;
|
|
1974
|
+
}, []));
|
|
1975
|
+
}
|
|
1976
|
+
function decompressResponse(response) {
|
|
1977
|
+
if (response.body === null) return null;
|
|
1978
|
+
const decompressionStream = createDecompressionStream(response.headers.get("content-encoding") || "");
|
|
1979
|
+
if (!decompressionStream) return null;
|
|
1980
|
+
response.body.pipeTo(decompressionStream.writable);
|
|
1981
|
+
return decompressionStream.readable;
|
|
1982
|
+
}
|
|
1983
|
+
var FetchInterceptor = class FetchInterceptor2 extends Interceptor {
|
|
1984
|
+
static {
|
|
1985
|
+
this.symbol = Symbol("fetch");
|
|
1986
|
+
}
|
|
1987
|
+
constructor() {
|
|
1988
|
+
super(FetchInterceptor2.symbol);
|
|
1989
|
+
}
|
|
1990
|
+
checkEnvironment() {
|
|
1991
|
+
return hasConfigurableGlobal("fetch");
|
|
1992
|
+
}
|
|
1993
|
+
async setup() {
|
|
1994
|
+
const pureFetch = globalThis.fetch;
|
|
1995
|
+
invariant(!pureFetch[IS_PATCHED_MODULE], 'Failed to patch the "fetch" module: already patched.');
|
|
1996
|
+
globalThis.fetch = async (input, init) => {
|
|
1997
|
+
const requestId = createRequestId();
|
|
1998
|
+
const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.href) : input;
|
|
1999
|
+
const request = new Request(resolvedInput, init);
|
|
2000
|
+
if (input instanceof Request) setRawRequest(request, input);
|
|
2001
|
+
const responsePromise = new DeferredPromise();
|
|
2002
|
+
const controller = new RequestController(request, {
|
|
2003
|
+
passthrough: async () => {
|
|
2004
|
+
this.logger.info("request has not been handled, passthrough...");
|
|
2005
|
+
const requestCloneForResponseEvent = request.clone();
|
|
2006
|
+
const { error: responseError, data: originalResponse } = await until2(() => pureFetch(request));
|
|
2007
|
+
if (responseError) return responsePromise.reject(responseError);
|
|
2008
|
+
this.logger.info("original fetch performed", originalResponse);
|
|
2009
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
2010
|
+
this.logger.info('emitting the "response" event...');
|
|
2011
|
+
const responseClone = originalResponse.clone();
|
|
2012
|
+
await emitAsync(this.emitter, "response", {
|
|
2013
|
+
response: responseClone,
|
|
2014
|
+
isMockedResponse: false,
|
|
2015
|
+
request: requestCloneForResponseEvent,
|
|
2016
|
+
requestId
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
responsePromise.resolve(originalResponse);
|
|
2020
|
+
},
|
|
2021
|
+
respondWith: async (rawResponse) => {
|
|
2022
|
+
if (isResponseError(rawResponse)) {
|
|
2023
|
+
this.logger.info("request has errored!", { response: rawResponse });
|
|
2024
|
+
responsePromise.reject(createNetworkError(rawResponse));
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
this.logger.info("received mocked response!", { rawResponse });
|
|
2028
|
+
const decompressedStream = decompressResponse(rawResponse);
|
|
2029
|
+
const response = decompressedStream === null ? rawResponse : new FetchResponse(decompressedStream, rawResponse);
|
|
2030
|
+
FetchResponse.setUrl(request.url, response);
|
|
2031
|
+
if (FetchResponse.isRedirectResponse(response.status)) {
|
|
2032
|
+
if (request.redirect === "error") {
|
|
2033
|
+
responsePromise.reject(createNetworkError("unexpected redirect"));
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
if (request.redirect === "follow") {
|
|
2037
|
+
followFetchRedirect(request, response).then((response$1) => {
|
|
2038
|
+
responsePromise.resolve(response$1);
|
|
2039
|
+
}, (reason) => {
|
|
2040
|
+
responsePromise.reject(reason);
|
|
2041
|
+
});
|
|
2042
|
+
return;
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
2046
|
+
this.logger.info('emitting the "response" event...');
|
|
2047
|
+
await emitAsync(this.emitter, "response", {
|
|
2048
|
+
response: response.clone(),
|
|
2049
|
+
isMockedResponse: true,
|
|
2050
|
+
request,
|
|
2051
|
+
requestId
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
responsePromise.resolve(response);
|
|
2055
|
+
},
|
|
2056
|
+
errorWith: (reason) => {
|
|
2057
|
+
this.logger.info("request has been aborted!", { reason });
|
|
2058
|
+
responsePromise.reject(reason);
|
|
2059
|
+
}
|
|
2060
|
+
});
|
|
2061
|
+
this.logger.info("[%s] %s", request.method, request.url);
|
|
2062
|
+
this.logger.info("awaiting for the mocked response...");
|
|
2063
|
+
this.logger.info('emitting the "request" event for %s listener(s)...', this.emitter.listenerCount("request"));
|
|
2064
|
+
await handleRequest2({
|
|
2065
|
+
request,
|
|
2066
|
+
requestId,
|
|
2067
|
+
emitter: this.emitter,
|
|
2068
|
+
controller
|
|
2069
|
+
});
|
|
2070
|
+
return responsePromise;
|
|
2071
|
+
};
|
|
2072
|
+
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, {
|
|
2073
|
+
enumerable: true,
|
|
2074
|
+
configurable: true,
|
|
2075
|
+
value: true
|
|
2076
|
+
});
|
|
2077
|
+
this.subscriptions.push(() => {
|
|
2078
|
+
Object.defineProperty(globalThis.fetch, IS_PATCHED_MODULE, { value: void 0 });
|
|
2079
|
+
globalThis.fetch = pureFetch;
|
|
2080
|
+
this.logger.info('restored native "globalThis.fetch"!', globalThis.fetch.name);
|
|
2081
|
+
});
|
|
2082
|
+
}
|
|
2083
|
+
};
|
|
2084
|
+
|
|
2085
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/XMLHttpRequest-BvxZV0WU.mjs
|
|
2086
|
+
function concatArrayBuffer(left, right) {
|
|
2087
|
+
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
2088
|
+
result.set(left, 0);
|
|
2089
|
+
result.set(right, left.byteLength);
|
|
2090
|
+
return result;
|
|
2091
|
+
}
|
|
2092
|
+
var EventPolyfill = class {
|
|
2093
|
+
constructor(type, options) {
|
|
2094
|
+
this.NONE = 0;
|
|
2095
|
+
this.CAPTURING_PHASE = 1;
|
|
2096
|
+
this.AT_TARGET = 2;
|
|
2097
|
+
this.BUBBLING_PHASE = 3;
|
|
2098
|
+
this.type = "";
|
|
2099
|
+
this.srcElement = null;
|
|
2100
|
+
this.currentTarget = null;
|
|
2101
|
+
this.eventPhase = 0;
|
|
2102
|
+
this.isTrusted = true;
|
|
2103
|
+
this.composed = false;
|
|
2104
|
+
this.cancelable = true;
|
|
2105
|
+
this.defaultPrevented = false;
|
|
2106
|
+
this.bubbles = true;
|
|
2107
|
+
this.lengthComputable = true;
|
|
2108
|
+
this.loaded = 0;
|
|
2109
|
+
this.total = 0;
|
|
2110
|
+
this.cancelBubble = false;
|
|
2111
|
+
this.returnValue = true;
|
|
2112
|
+
this.type = type;
|
|
2113
|
+
this.target = options?.target || null;
|
|
2114
|
+
this.currentTarget = options?.currentTarget || null;
|
|
2115
|
+
this.timeStamp = Date.now();
|
|
2116
|
+
}
|
|
2117
|
+
composedPath() {
|
|
2118
|
+
return [];
|
|
2119
|
+
}
|
|
2120
|
+
initEvent(type, bubbles, cancelable) {
|
|
2121
|
+
this.type = type;
|
|
2122
|
+
this.bubbles = !!bubbles;
|
|
2123
|
+
this.cancelable = !!cancelable;
|
|
2124
|
+
}
|
|
2125
|
+
preventDefault() {
|
|
2126
|
+
this.defaultPrevented = true;
|
|
2127
|
+
}
|
|
2128
|
+
stopPropagation() {
|
|
2129
|
+
}
|
|
2130
|
+
stopImmediatePropagation() {
|
|
2131
|
+
}
|
|
2132
|
+
};
|
|
2133
|
+
var ProgressEventPolyfill = class extends EventPolyfill {
|
|
2134
|
+
constructor(type, init) {
|
|
2135
|
+
super(type);
|
|
2136
|
+
this.lengthComputable = init?.lengthComputable || false;
|
|
2137
|
+
this.composed = init?.composed || false;
|
|
2138
|
+
this.loaded = init?.loaded || 0;
|
|
2139
|
+
this.total = init?.total || 0;
|
|
2140
|
+
}
|
|
2141
|
+
};
|
|
2142
|
+
var SUPPORTS_PROGRESS_EVENT = typeof ProgressEvent !== "undefined";
|
|
2143
|
+
function createEvent(target, type, init) {
|
|
2144
|
+
const progressEvents = [
|
|
2145
|
+
"error",
|
|
2146
|
+
"progress",
|
|
2147
|
+
"loadstart",
|
|
2148
|
+
"loadend",
|
|
2149
|
+
"load",
|
|
2150
|
+
"timeout",
|
|
2151
|
+
"abort"
|
|
2152
|
+
];
|
|
2153
|
+
const ProgressEventClass = SUPPORTS_PROGRESS_EVENT ? ProgressEvent : ProgressEventPolyfill;
|
|
2154
|
+
return progressEvents.includes(type) ? new ProgressEventClass(type, {
|
|
2155
|
+
lengthComputable: true,
|
|
2156
|
+
loaded: init?.loaded || 0,
|
|
2157
|
+
total: init?.total || 0
|
|
2158
|
+
}) : new EventPolyfill(type, {
|
|
2159
|
+
target,
|
|
2160
|
+
currentTarget: target
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
function findPropertySource(target, propertyName) {
|
|
2164
|
+
if (!(propertyName in target)) return null;
|
|
2165
|
+
if (Object.prototype.hasOwnProperty.call(target, propertyName)) return target;
|
|
2166
|
+
const prototype = Reflect.getPrototypeOf(target);
|
|
2167
|
+
return prototype ? findPropertySource(prototype, propertyName) : null;
|
|
2168
|
+
}
|
|
2169
|
+
function createProxy(target, options) {
|
|
2170
|
+
return new Proxy(target, optionsToProxyHandler(options));
|
|
2171
|
+
}
|
|
2172
|
+
function optionsToProxyHandler(options) {
|
|
2173
|
+
const { constructorCall, methodCall, getProperty, setProperty } = options;
|
|
2174
|
+
const handler = {};
|
|
2175
|
+
if (typeof constructorCall !== "undefined") handler.construct = function(target, args, newTarget) {
|
|
2176
|
+
const next = Reflect.construct.bind(null, target, args, newTarget);
|
|
2177
|
+
return constructorCall.call(newTarget, args, next);
|
|
2178
|
+
};
|
|
2179
|
+
handler.set = function(target, propertyName, nextValue) {
|
|
2180
|
+
const next = () => {
|
|
2181
|
+
const propertySource = findPropertySource(target, propertyName) || target;
|
|
2182
|
+
const ownDescriptors = Reflect.getOwnPropertyDescriptor(propertySource, propertyName);
|
|
2183
|
+
if (typeof ownDescriptors?.set !== "undefined") {
|
|
2184
|
+
ownDescriptors.set.apply(target, [nextValue]);
|
|
2185
|
+
return true;
|
|
2186
|
+
}
|
|
2187
|
+
return Reflect.defineProperty(propertySource, propertyName, {
|
|
2188
|
+
writable: true,
|
|
2189
|
+
enumerable: true,
|
|
2190
|
+
configurable: true,
|
|
2191
|
+
value: nextValue
|
|
2192
|
+
});
|
|
2193
|
+
};
|
|
2194
|
+
if (typeof setProperty !== "undefined") return setProperty.call(target, [propertyName, nextValue], next);
|
|
2195
|
+
return next();
|
|
2196
|
+
};
|
|
2197
|
+
handler.get = function(target, propertyName, receiver) {
|
|
2198
|
+
const next = () => target[propertyName];
|
|
2199
|
+
const value = typeof getProperty !== "undefined" ? getProperty.call(target, [propertyName, receiver], next) : next();
|
|
2200
|
+
if (typeof value === "function") return (...args) => {
|
|
2201
|
+
const next$1 = value.bind(target, ...args);
|
|
2202
|
+
if (typeof methodCall !== "undefined") return methodCall.call(target, [propertyName, args], next$1);
|
|
2203
|
+
return next$1();
|
|
2204
|
+
};
|
|
2205
|
+
return value;
|
|
2206
|
+
};
|
|
2207
|
+
return handler;
|
|
2208
|
+
}
|
|
2209
|
+
function isDomParserSupportedType(type) {
|
|
2210
|
+
return [
|
|
2211
|
+
"application/xhtml+xml",
|
|
2212
|
+
"application/xml",
|
|
2213
|
+
"image/svg+xml",
|
|
2214
|
+
"text/html",
|
|
2215
|
+
"text/xml"
|
|
2216
|
+
].some((supportedType) => {
|
|
2217
|
+
return type.startsWith(supportedType);
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
function parseJson(data) {
|
|
2221
|
+
try {
|
|
2222
|
+
return JSON.parse(data);
|
|
2223
|
+
} catch (_) {
|
|
2224
|
+
return null;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
function createResponse(request, body) {
|
|
2228
|
+
return new FetchResponse(FetchResponse.isResponseWithBody(request.status) ? body : null, {
|
|
2229
|
+
url: request.responseURL,
|
|
2230
|
+
status: request.status,
|
|
2231
|
+
statusText: request.statusText,
|
|
2232
|
+
headers: createHeadersFromXMLHttpRequestHeaders(request.getAllResponseHeaders())
|
|
2233
|
+
});
|
|
2234
|
+
}
|
|
2235
|
+
function createHeadersFromXMLHttpRequestHeaders(headersString) {
|
|
2236
|
+
const headers = new Headers();
|
|
2237
|
+
const lines = headersString.split(/[\r\n]+/);
|
|
2238
|
+
for (const line of lines) {
|
|
2239
|
+
if (line.trim() === "") continue;
|
|
2240
|
+
const [name, ...parts] = line.split(": ");
|
|
2241
|
+
const value = parts.join(": ");
|
|
2242
|
+
headers.append(name, value);
|
|
2243
|
+
}
|
|
2244
|
+
return headers;
|
|
2245
|
+
}
|
|
2246
|
+
async function getBodyByteLength(input) {
|
|
2247
|
+
const explicitContentLength = input.headers.get("content-length");
|
|
2248
|
+
if (explicitContentLength != null && explicitContentLength !== "") return Number(explicitContentLength);
|
|
2249
|
+
return (await input.arrayBuffer()).byteLength;
|
|
2250
|
+
}
|
|
2251
|
+
var kIsRequestHandled = Symbol("kIsRequestHandled");
|
|
2252
|
+
var IS_NODE2 = isNodeProcess();
|
|
2253
|
+
var kFetchRequest = Symbol("kFetchRequest");
|
|
2254
|
+
var XMLHttpRequestController = class {
|
|
2255
|
+
constructor(initialRequest, logger) {
|
|
2256
|
+
this.initialRequest = initialRequest;
|
|
2257
|
+
this.logger = logger;
|
|
2258
|
+
this.method = "GET";
|
|
2259
|
+
this.url = null;
|
|
2260
|
+
this[kIsRequestHandled] = false;
|
|
2261
|
+
this.events = /* @__PURE__ */ new Map();
|
|
2262
|
+
this.uploadEvents = /* @__PURE__ */ new Map();
|
|
2263
|
+
this.requestId = createRequestId();
|
|
2264
|
+
this.requestHeaders = new Headers();
|
|
2265
|
+
this.responseBuffer = new Uint8Array();
|
|
2266
|
+
this.request = createProxy(initialRequest, {
|
|
2267
|
+
setProperty: ([propertyName, nextValue], invoke) => {
|
|
2268
|
+
switch (propertyName) {
|
|
2269
|
+
case "ontimeout": {
|
|
2270
|
+
const eventName = propertyName.slice(2);
|
|
2271
|
+
this.request.addEventListener(eventName, nextValue);
|
|
2272
|
+
return invoke();
|
|
2273
|
+
}
|
|
2274
|
+
default:
|
|
2275
|
+
return invoke();
|
|
2276
|
+
}
|
|
2277
|
+
},
|
|
2278
|
+
methodCall: ([methodName, args], invoke) => {
|
|
2279
|
+
switch (methodName) {
|
|
2280
|
+
case "open": {
|
|
2281
|
+
const [method, url] = args;
|
|
2282
|
+
if (typeof url === "undefined") {
|
|
2283
|
+
this.method = "GET";
|
|
2284
|
+
this.url = toAbsoluteUrl(method);
|
|
2285
|
+
} else {
|
|
2286
|
+
this.method = method;
|
|
2287
|
+
this.url = toAbsoluteUrl(url);
|
|
2288
|
+
}
|
|
2289
|
+
this.logger = this.logger.extend(`${this.method} ${this.url.href}`);
|
|
2290
|
+
this.logger.info("open", this.method, this.url.href);
|
|
2291
|
+
return invoke();
|
|
2292
|
+
}
|
|
2293
|
+
case "addEventListener": {
|
|
2294
|
+
const [eventName, listener] = args;
|
|
2295
|
+
this.registerEvent(eventName, listener);
|
|
2296
|
+
this.logger.info("addEventListener", eventName, listener);
|
|
2297
|
+
return invoke();
|
|
2298
|
+
}
|
|
2299
|
+
case "setRequestHeader": {
|
|
2300
|
+
const [name, value] = args;
|
|
2301
|
+
this.requestHeaders.set(name, value);
|
|
2302
|
+
this.logger.info("setRequestHeader", name, value);
|
|
2303
|
+
return invoke();
|
|
2304
|
+
}
|
|
2305
|
+
case "send": {
|
|
2306
|
+
const [body] = args;
|
|
2307
|
+
this.request.addEventListener("load", () => {
|
|
2308
|
+
if (typeof this.onResponse !== "undefined") {
|
|
2309
|
+
const fetchResponse = createResponse(
|
|
2310
|
+
this.request,
|
|
2311
|
+
/**
|
|
2312
|
+
* The `response` property is the right way to read
|
|
2313
|
+
* the ambiguous response body, as the request's "responseType" may differ.
|
|
2314
|
+
* @see https://xhr.spec.whatwg.org/#the-response-attribute
|
|
2315
|
+
*/
|
|
2316
|
+
this.request.response
|
|
2317
|
+
);
|
|
2318
|
+
this.onResponse.call(this, {
|
|
2319
|
+
response: fetchResponse,
|
|
2320
|
+
isMockedResponse: this[kIsRequestHandled],
|
|
2321
|
+
request: fetchRequest,
|
|
2322
|
+
requestId: this.requestId
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
});
|
|
2326
|
+
const requestBody = typeof body === "string" ? encodeBuffer(body) : body;
|
|
2327
|
+
const fetchRequest = this.toFetchApiRequest(requestBody);
|
|
2328
|
+
this[kFetchRequest] = fetchRequest.clone();
|
|
2329
|
+
queueMicrotask(() => {
|
|
2330
|
+
(this.onRequest?.call(this, {
|
|
2331
|
+
request: fetchRequest,
|
|
2332
|
+
requestId: this.requestId
|
|
2333
|
+
}) || Promise.resolve()).finally(() => {
|
|
2334
|
+
if (!this[kIsRequestHandled]) {
|
|
2335
|
+
this.logger.info("request callback settled but request has not been handled (readystate %d), performing as-is...", this.request.readyState);
|
|
2336
|
+
if (IS_NODE2) this.request.setRequestHeader(INTERNAL_REQUEST_ID_HEADER_NAME, this.requestId);
|
|
2337
|
+
return invoke();
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2340
|
+
});
|
|
2341
|
+
break;
|
|
2342
|
+
}
|
|
2343
|
+
default:
|
|
2344
|
+
return invoke();
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
});
|
|
2348
|
+
define(this.request, "upload", createProxy(this.request.upload, {
|
|
2349
|
+
setProperty: ([propertyName, nextValue], invoke) => {
|
|
2350
|
+
switch (propertyName) {
|
|
2351
|
+
case "onloadstart":
|
|
2352
|
+
case "onprogress":
|
|
2353
|
+
case "onaboart":
|
|
2354
|
+
case "onerror":
|
|
2355
|
+
case "onload":
|
|
2356
|
+
case "ontimeout":
|
|
2357
|
+
case "onloadend": {
|
|
2358
|
+
const eventName = propertyName.slice(2);
|
|
2359
|
+
this.registerUploadEvent(eventName, nextValue);
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
return invoke();
|
|
2363
|
+
},
|
|
2364
|
+
methodCall: ([methodName, args], invoke) => {
|
|
2365
|
+
switch (methodName) {
|
|
2366
|
+
case "addEventListener": {
|
|
2367
|
+
const [eventName, listener] = args;
|
|
2368
|
+
this.registerUploadEvent(eventName, listener);
|
|
2369
|
+
this.logger.info("upload.addEventListener", eventName, listener);
|
|
2370
|
+
return invoke();
|
|
2371
|
+
}
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
}));
|
|
2375
|
+
}
|
|
2376
|
+
registerEvent(eventName, listener) {
|
|
2377
|
+
const nextEvents = (this.events.get(eventName) || []).concat(listener);
|
|
2378
|
+
this.events.set(eventName, nextEvents);
|
|
2379
|
+
this.logger.info('registered event "%s"', eventName, listener);
|
|
2380
|
+
}
|
|
2381
|
+
registerUploadEvent(eventName, listener) {
|
|
2382
|
+
const nextEvents = (this.uploadEvents.get(eventName) || []).concat(listener);
|
|
2383
|
+
this.uploadEvents.set(eventName, nextEvents);
|
|
2384
|
+
this.logger.info('registered upload event "%s"', eventName, listener);
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Responds to the current request with the given
|
|
2388
|
+
* Fetch API `Response` instance.
|
|
2389
|
+
*/
|
|
2390
|
+
async respondWith(response) {
|
|
2391
|
+
this[kIsRequestHandled] = true;
|
|
2392
|
+
if (this[kFetchRequest]) {
|
|
2393
|
+
const totalRequestBodyLength = await getBodyByteLength(this[kFetchRequest]);
|
|
2394
|
+
this.trigger("loadstart", this.request.upload, {
|
|
2395
|
+
loaded: 0,
|
|
2396
|
+
total: totalRequestBodyLength
|
|
2397
|
+
});
|
|
2398
|
+
this.trigger("progress", this.request.upload, {
|
|
2399
|
+
loaded: totalRequestBodyLength,
|
|
2400
|
+
total: totalRequestBodyLength
|
|
2401
|
+
});
|
|
2402
|
+
this.trigger("load", this.request.upload, {
|
|
2403
|
+
loaded: totalRequestBodyLength,
|
|
2404
|
+
total: totalRequestBodyLength
|
|
2405
|
+
});
|
|
2406
|
+
this.trigger("loadend", this.request.upload, {
|
|
2407
|
+
loaded: totalRequestBodyLength,
|
|
2408
|
+
total: totalRequestBodyLength
|
|
2409
|
+
});
|
|
2410
|
+
}
|
|
2411
|
+
this.logger.info("responding with a mocked response: %d %s", response.status, response.statusText);
|
|
2412
|
+
define(this.request, "status", response.status);
|
|
2413
|
+
define(this.request, "statusText", response.statusText);
|
|
2414
|
+
define(this.request, "responseURL", this.url.href);
|
|
2415
|
+
this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, { apply: (_, __, args) => {
|
|
2416
|
+
this.logger.info("getResponseHeader", args[0]);
|
|
2417
|
+
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
|
2418
|
+
this.logger.info("headers not received yet, returning null");
|
|
2419
|
+
return null;
|
|
2420
|
+
}
|
|
2421
|
+
const headerValue = response.headers.get(args[0]);
|
|
2422
|
+
this.logger.info('resolved response header "%s" to', args[0], headerValue);
|
|
2423
|
+
return headerValue;
|
|
2424
|
+
} });
|
|
2425
|
+
this.request.getAllResponseHeaders = new Proxy(this.request.getAllResponseHeaders, { apply: () => {
|
|
2426
|
+
this.logger.info("getAllResponseHeaders");
|
|
2427
|
+
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
|
2428
|
+
this.logger.info("headers not received yet, returning empty string");
|
|
2429
|
+
return "";
|
|
2430
|
+
}
|
|
2431
|
+
const allHeaders = Array.from(response.headers.entries()).map(([headerName, headerValue]) => {
|
|
2432
|
+
return `${headerName}: ${headerValue}`;
|
|
2433
|
+
}).join("\r\n");
|
|
2434
|
+
this.logger.info("resolved all response headers to", allHeaders);
|
|
2435
|
+
return allHeaders;
|
|
2436
|
+
} });
|
|
2437
|
+
Object.defineProperties(this.request, {
|
|
2438
|
+
response: {
|
|
2439
|
+
enumerable: true,
|
|
2440
|
+
configurable: false,
|
|
2441
|
+
get: () => this.response
|
|
2442
|
+
},
|
|
2443
|
+
responseText: {
|
|
2444
|
+
enumerable: true,
|
|
2445
|
+
configurable: false,
|
|
2446
|
+
get: () => this.responseText
|
|
2447
|
+
},
|
|
2448
|
+
responseXML: {
|
|
2449
|
+
enumerable: true,
|
|
2450
|
+
configurable: false,
|
|
2451
|
+
get: () => this.responseXML
|
|
2452
|
+
}
|
|
2453
|
+
});
|
|
2454
|
+
const totalResponseBodyLength = await getBodyByteLength(response.clone());
|
|
2455
|
+
this.logger.info("calculated response body length", totalResponseBodyLength);
|
|
2456
|
+
this.trigger("loadstart", this.request, {
|
|
2457
|
+
loaded: 0,
|
|
2458
|
+
total: totalResponseBodyLength
|
|
2459
|
+
});
|
|
2460
|
+
this.setReadyState(this.request.HEADERS_RECEIVED);
|
|
2461
|
+
this.setReadyState(this.request.LOADING);
|
|
2462
|
+
const finalizeResponse = () => {
|
|
2463
|
+
this.logger.info("finalizing the mocked response...");
|
|
2464
|
+
this.setReadyState(this.request.DONE);
|
|
2465
|
+
this.trigger("load", this.request, {
|
|
2466
|
+
loaded: this.responseBuffer.byteLength,
|
|
2467
|
+
total: totalResponseBodyLength
|
|
2468
|
+
});
|
|
2469
|
+
this.trigger("loadend", this.request, {
|
|
2470
|
+
loaded: this.responseBuffer.byteLength,
|
|
2471
|
+
total: totalResponseBodyLength
|
|
2472
|
+
});
|
|
2473
|
+
};
|
|
2474
|
+
if (response.body) {
|
|
2475
|
+
this.logger.info("mocked response has body, streaming...");
|
|
2476
|
+
const reader = response.body.getReader();
|
|
2477
|
+
const readNextResponseBodyChunk = async () => {
|
|
2478
|
+
const { value, done } = await reader.read();
|
|
2479
|
+
if (done) {
|
|
2480
|
+
this.logger.info("response body stream done!");
|
|
2481
|
+
finalizeResponse();
|
|
2482
|
+
return;
|
|
2483
|
+
}
|
|
2484
|
+
if (value) {
|
|
2485
|
+
this.logger.info("read response body chunk:", value);
|
|
2486
|
+
this.responseBuffer = concatArrayBuffer(this.responseBuffer, value);
|
|
2487
|
+
this.trigger("progress", this.request, {
|
|
2488
|
+
loaded: this.responseBuffer.byteLength,
|
|
2489
|
+
total: totalResponseBodyLength
|
|
2490
|
+
});
|
|
2491
|
+
}
|
|
2492
|
+
readNextResponseBodyChunk();
|
|
2493
|
+
};
|
|
2494
|
+
readNextResponseBodyChunk();
|
|
2495
|
+
} else finalizeResponse();
|
|
2496
|
+
}
|
|
2497
|
+
responseBufferToText() {
|
|
2498
|
+
return decodeBuffer(this.responseBuffer);
|
|
2499
|
+
}
|
|
2500
|
+
get response() {
|
|
2501
|
+
this.logger.info("getResponse (responseType: %s)", this.request.responseType);
|
|
2502
|
+
if (this.request.readyState !== this.request.DONE) return null;
|
|
2503
|
+
switch (this.request.responseType) {
|
|
2504
|
+
case "json": {
|
|
2505
|
+
const responseJson = parseJson(this.responseBufferToText());
|
|
2506
|
+
this.logger.info("resolved response JSON", responseJson);
|
|
2507
|
+
return responseJson;
|
|
2508
|
+
}
|
|
2509
|
+
case "arraybuffer": {
|
|
2510
|
+
const arrayBuffer = toArrayBuffer(this.responseBuffer);
|
|
2511
|
+
this.logger.info("resolved response ArrayBuffer", arrayBuffer);
|
|
2512
|
+
return arrayBuffer;
|
|
2513
|
+
}
|
|
2514
|
+
case "blob": {
|
|
2515
|
+
const mimeType = this.request.getResponseHeader("Content-Type") || "text/plain";
|
|
2516
|
+
const responseBlob = new Blob([this.responseBufferToText()], { type: mimeType });
|
|
2517
|
+
this.logger.info("resolved response Blob (mime type: %s)", responseBlob, mimeType);
|
|
2518
|
+
return responseBlob;
|
|
2519
|
+
}
|
|
2520
|
+
default: {
|
|
2521
|
+
const responseText = this.responseBufferToText();
|
|
2522
|
+
this.logger.info('resolving "%s" response type as text', this.request.responseType, responseText);
|
|
2523
|
+
return responseText;
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
}
|
|
2527
|
+
get responseText() {
|
|
2528
|
+
invariant(this.request.responseType === "" || this.request.responseType === "text", "InvalidStateError: The object is in invalid state.");
|
|
2529
|
+
if (this.request.readyState !== this.request.LOADING && this.request.readyState !== this.request.DONE) return "";
|
|
2530
|
+
const responseText = this.responseBufferToText();
|
|
2531
|
+
this.logger.info('getResponseText: "%s"', responseText);
|
|
2532
|
+
return responseText;
|
|
2533
|
+
}
|
|
2534
|
+
get responseXML() {
|
|
2535
|
+
invariant(this.request.responseType === "" || this.request.responseType === "document", "InvalidStateError: The object is in invalid state.");
|
|
2536
|
+
if (this.request.readyState !== this.request.DONE) return null;
|
|
2537
|
+
const contentType = this.request.getResponseHeader("Content-Type") || "";
|
|
2538
|
+
if (typeof DOMParser === "undefined") {
|
|
2539
|
+
console.warn("Cannot retrieve XMLHttpRequest response body as XML: DOMParser is not defined. You are likely using an environment that is not browser or does not polyfill browser globals correctly.");
|
|
2540
|
+
return null;
|
|
2541
|
+
}
|
|
2542
|
+
if (isDomParserSupportedType(contentType)) return new DOMParser().parseFromString(this.responseBufferToText(), contentType);
|
|
2543
|
+
return null;
|
|
2544
|
+
}
|
|
2545
|
+
errorWith(error2) {
|
|
2546
|
+
this[kIsRequestHandled] = true;
|
|
2547
|
+
this.logger.info("responding with an error");
|
|
2548
|
+
this.setReadyState(this.request.DONE);
|
|
2549
|
+
this.trigger("error", this.request);
|
|
2550
|
+
this.trigger("loadend", this.request);
|
|
2551
|
+
}
|
|
2552
|
+
/**
|
|
2553
|
+
* Transitions this request's `readyState` to the given one.
|
|
2554
|
+
*/
|
|
2555
|
+
setReadyState(nextReadyState) {
|
|
2556
|
+
this.logger.info("setReadyState: %d -> %d", this.request.readyState, nextReadyState);
|
|
2557
|
+
if (this.request.readyState === nextReadyState) {
|
|
2558
|
+
this.logger.info("ready state identical, skipping transition...");
|
|
2559
|
+
return;
|
|
2560
|
+
}
|
|
2561
|
+
define(this.request, "readyState", nextReadyState);
|
|
2562
|
+
this.logger.info("set readyState to: %d", nextReadyState);
|
|
2563
|
+
if (nextReadyState !== this.request.UNSENT) {
|
|
2564
|
+
this.logger.info('triggering "readystatechange" event...');
|
|
2565
|
+
this.trigger("readystatechange", this.request);
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* Triggers given event on the `XMLHttpRequest` instance.
|
|
2570
|
+
*/
|
|
2571
|
+
trigger(eventName, target, options) {
|
|
2572
|
+
const callback = target[`on${eventName}`];
|
|
2573
|
+
const event = createEvent(target, eventName, options);
|
|
2574
|
+
this.logger.info('trigger "%s"', eventName, options || "");
|
|
2575
|
+
if (typeof callback === "function") {
|
|
2576
|
+
this.logger.info('found a direct "%s" callback, calling...', eventName);
|
|
2577
|
+
callback.call(target, event);
|
|
2578
|
+
}
|
|
2579
|
+
const events = target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events;
|
|
2580
|
+
for (const [registeredEventName, listeners] of events) if (registeredEventName === eventName) {
|
|
2581
|
+
this.logger.info('found %d listener(s) for "%s" event, calling...', listeners.length, eventName);
|
|
2582
|
+
listeners.forEach((listener) => listener.call(target, event));
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
|
|
2587
|
+
*/
|
|
2588
|
+
toFetchApiRequest(body) {
|
|
2589
|
+
this.logger.info("converting request to a Fetch API Request...");
|
|
2590
|
+
const resolvedBody = body instanceof Document ? body.documentElement.innerText : body;
|
|
2591
|
+
const fetchRequest = new Request(this.url.href, {
|
|
2592
|
+
method: this.method,
|
|
2593
|
+
headers: this.requestHeaders,
|
|
2594
|
+
credentials: this.request.withCredentials ? "include" : "same-origin",
|
|
2595
|
+
body: ["GET", "HEAD"].includes(this.method.toUpperCase()) ? null : resolvedBody
|
|
2596
|
+
});
|
|
2597
|
+
define(fetchRequest, "headers", createProxy(fetchRequest.headers, { methodCall: ([methodName, args], invoke) => {
|
|
2598
|
+
switch (methodName) {
|
|
2599
|
+
case "append":
|
|
2600
|
+
case "set": {
|
|
2601
|
+
const [headerName, headerValue] = args;
|
|
2602
|
+
this.request.setRequestHeader(headerName, headerValue);
|
|
2603
|
+
break;
|
|
2604
|
+
}
|
|
2605
|
+
case "delete": {
|
|
2606
|
+
const [headerName] = args;
|
|
2607
|
+
console.warn(`XMLHttpRequest: Cannot remove a "${headerName}" header from the Fetch API representation of the "${fetchRequest.method} ${fetchRequest.url}" request. XMLHttpRequest headers cannot be removed.`);
|
|
2608
|
+
break;
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
return invoke();
|
|
2612
|
+
} }));
|
|
2613
|
+
setRawRequest(fetchRequest, this.request);
|
|
2614
|
+
this.logger.info("converted request to a Fetch API Request!", fetchRequest);
|
|
2615
|
+
return fetchRequest;
|
|
2616
|
+
}
|
|
2617
|
+
};
|
|
2618
|
+
function toAbsoluteUrl(url) {
|
|
2619
|
+
if (typeof location === "undefined") return new URL(url);
|
|
2620
|
+
return new URL(url.toString(), location.href);
|
|
2621
|
+
}
|
|
2622
|
+
function define(target, property, value) {
|
|
2623
|
+
Reflect.defineProperty(target, property, {
|
|
2624
|
+
writable: true,
|
|
2625
|
+
enumerable: true,
|
|
2626
|
+
value
|
|
2627
|
+
});
|
|
2628
|
+
}
|
|
2629
|
+
function createXMLHttpRequestProxy({ emitter, logger }) {
|
|
2630
|
+
return new Proxy(globalThis.XMLHttpRequest, { construct(target, args, newTarget) {
|
|
2631
|
+
logger.info("constructed new XMLHttpRequest");
|
|
2632
|
+
const originalRequest = Reflect.construct(target, args, newTarget);
|
|
2633
|
+
const prototypeDescriptors = Object.getOwnPropertyDescriptors(target.prototype);
|
|
2634
|
+
for (const propertyName in prototypeDescriptors) Reflect.defineProperty(originalRequest, propertyName, prototypeDescriptors[propertyName]);
|
|
2635
|
+
const xhrRequestController = new XMLHttpRequestController(originalRequest, logger);
|
|
2636
|
+
xhrRequestController.onRequest = async function({ request, requestId }) {
|
|
2637
|
+
const controller = new RequestController(request, {
|
|
2638
|
+
passthrough: () => {
|
|
2639
|
+
this.logger.info("no mocked response received, performing request as-is...");
|
|
2640
|
+
},
|
|
2641
|
+
respondWith: async (response) => {
|
|
2642
|
+
if (isResponseError(response)) {
|
|
2643
|
+
this.errorWith(/* @__PURE__ */ new TypeError("Network error"));
|
|
2644
|
+
return;
|
|
2645
|
+
}
|
|
2646
|
+
await this.respondWith(response);
|
|
2647
|
+
},
|
|
2648
|
+
errorWith: (reason) => {
|
|
2649
|
+
this.logger.info("request errored!", { error: reason });
|
|
2650
|
+
if (reason instanceof Error) this.errorWith(reason);
|
|
2651
|
+
}
|
|
2652
|
+
});
|
|
2653
|
+
this.logger.info("awaiting mocked response...");
|
|
2654
|
+
this.logger.info('emitting the "request" event for %s listener(s)...', emitter.listenerCount("request"));
|
|
2655
|
+
await handleRequest2({
|
|
2656
|
+
request,
|
|
2657
|
+
requestId,
|
|
2658
|
+
controller,
|
|
2659
|
+
emitter
|
|
2660
|
+
});
|
|
2661
|
+
};
|
|
2662
|
+
xhrRequestController.onResponse = async function({ response, isMockedResponse, request, requestId }) {
|
|
2663
|
+
this.logger.info('emitting the "response" event for %s listener(s)...', emitter.listenerCount("response"));
|
|
2664
|
+
emitter.emit("response", {
|
|
2665
|
+
response,
|
|
2666
|
+
isMockedResponse,
|
|
2667
|
+
request,
|
|
2668
|
+
requestId
|
|
2669
|
+
});
|
|
2670
|
+
};
|
|
2671
|
+
return xhrRequestController.request;
|
|
2672
|
+
} });
|
|
2673
|
+
}
|
|
2674
|
+
var XMLHttpRequestInterceptor = class XMLHttpRequestInterceptor2 extends Interceptor {
|
|
2675
|
+
static {
|
|
2676
|
+
this.interceptorSymbol = Symbol("xhr");
|
|
2677
|
+
}
|
|
2678
|
+
constructor() {
|
|
2679
|
+
super(XMLHttpRequestInterceptor2.interceptorSymbol);
|
|
2680
|
+
}
|
|
2681
|
+
checkEnvironment() {
|
|
2682
|
+
return hasConfigurableGlobal("XMLHttpRequest");
|
|
2683
|
+
}
|
|
2684
|
+
setup() {
|
|
2685
|
+
const logger = this.logger.extend("setup");
|
|
2686
|
+
logger.info('patching "XMLHttpRequest" module...');
|
|
2687
|
+
const PureXMLHttpRequest = globalThis.XMLHttpRequest;
|
|
2688
|
+
invariant(!PureXMLHttpRequest[IS_PATCHED_MODULE], 'Failed to patch the "XMLHttpRequest" module: already patched.');
|
|
2689
|
+
globalThis.XMLHttpRequest = createXMLHttpRequestProxy({
|
|
2690
|
+
emitter: this.emitter,
|
|
2691
|
+
logger: this.logger
|
|
2692
|
+
});
|
|
2693
|
+
logger.info('native "XMLHttpRequest" module patched!', globalThis.XMLHttpRequest.name);
|
|
2694
|
+
Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, {
|
|
2695
|
+
enumerable: true,
|
|
2696
|
+
configurable: true,
|
|
2697
|
+
value: true
|
|
2698
|
+
});
|
|
2699
|
+
this.subscriptions.push(() => {
|
|
2700
|
+
Object.defineProperty(globalThis.XMLHttpRequest, IS_PATCHED_MODULE, { value: void 0 });
|
|
2701
|
+
globalThis.XMLHttpRequest = PureXMLHttpRequest;
|
|
2702
|
+
logger.info('native "XMLHttpRequest" module restored!', globalThis.XMLHttpRequest.name);
|
|
2703
|
+
});
|
|
2704
|
+
}
|
|
2705
|
+
};
|
|
2706
|
+
|
|
2707
|
+
// src/browser/setupWorker/start/createFallbackRequestListener.ts
|
|
2708
|
+
import { handleRequest as handleRequest3 } from '../core/utils/handleRequest.mjs';
|
|
2709
|
+
import { isHandlerKind as isHandlerKind2 } from '../core/utils/internal/isHandlerKind.mjs';
|
|
2710
|
+
function createFallbackRequestListener(context, options) {
|
|
2711
|
+
const interceptor = new BatchInterceptor({
|
|
2712
|
+
name: "fallback",
|
|
2713
|
+
interceptors: [new FetchInterceptor(), new XMLHttpRequestInterceptor()]
|
|
2714
|
+
});
|
|
2715
|
+
interceptor.on("request", async ({ request, requestId, controller }) => {
|
|
2716
|
+
const requestCloneForLogs = request.clone();
|
|
2717
|
+
const response = await handleRequest3(
|
|
2718
|
+
request,
|
|
2719
|
+
requestId,
|
|
2720
|
+
context.getRequestHandlers().filter(isHandlerKind2("RequestHandler")),
|
|
2721
|
+
options,
|
|
2722
|
+
context.emitter,
|
|
2723
|
+
{
|
|
2724
|
+
resolutionContext: {
|
|
2725
|
+
quiet: options.quiet
|
|
2726
|
+
},
|
|
2727
|
+
onMockedResponse(_, { handler, parsedResult }) {
|
|
2728
|
+
if (!options.quiet) {
|
|
2729
|
+
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
2730
|
+
handler.log({
|
|
2731
|
+
request: requestCloneForLogs,
|
|
2732
|
+
response: response2,
|
|
2733
|
+
parsedResult
|
|
2734
|
+
});
|
|
2735
|
+
});
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
);
|
|
2740
|
+
if (response) {
|
|
2741
|
+
controller.respondWith(response);
|
|
2742
|
+
}
|
|
2743
|
+
});
|
|
2744
|
+
interceptor.on(
|
|
2745
|
+
"response",
|
|
2746
|
+
({ response, isMockedResponse, request, requestId }) => {
|
|
2747
|
+
context.emitter.emit(
|
|
2748
|
+
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
2749
|
+
{
|
|
2750
|
+
response,
|
|
2751
|
+
request,
|
|
2752
|
+
requestId
|
|
2753
|
+
}
|
|
2754
|
+
);
|
|
2755
|
+
}
|
|
2756
|
+
);
|
|
2757
|
+
interceptor.apply();
|
|
2758
|
+
return interceptor;
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
// src/browser/setupWorker/stop/utils/printStopMessage.ts
|
|
2762
|
+
import { devUtils as devUtils7 } from '../core/utils/internal/devUtils.mjs';
|
|
2763
|
+
function printStopMessage(args = {}) {
|
|
2764
|
+
if (args.quiet) {
|
|
2765
|
+
return;
|
|
2766
|
+
}
|
|
2767
|
+
console.log(
|
|
2768
|
+
`%c${devUtils7.formatMessage("Mocking disabled.")}`,
|
|
2769
|
+
"color:orangered;font-weight:bold;"
|
|
2770
|
+
);
|
|
2771
|
+
}
|
|
2772
|
+
|
|
2773
|
+
// src/browser/setupWorker/setupWorker.ts
|
|
2774
|
+
var SetupWorkerApi = class extends SetupApi {
|
|
2775
|
+
context;
|
|
2776
|
+
constructor(...handlers) {
|
|
2777
|
+
super(...handlers);
|
|
2778
|
+
invariant(
|
|
2779
|
+
!isNodeProcess(),
|
|
2780
|
+
devUtils8.formatMessage(
|
|
2781
|
+
"Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
|
|
2782
|
+
)
|
|
2783
|
+
);
|
|
2784
|
+
this.context = this.createWorkerContext();
|
|
2785
|
+
}
|
|
2786
|
+
createWorkerContext() {
|
|
2787
|
+
const workerPromise = new DeferredPromise();
|
|
2788
|
+
return {
|
|
2789
|
+
// Mocking is not considered enabled until the worker
|
|
2790
|
+
// signals back the successful activation event.
|
|
2791
|
+
isMockingEnabled: false,
|
|
2792
|
+
startOptions: null,
|
|
2793
|
+
workerPromise,
|
|
2794
|
+
registration: void 0,
|
|
2795
|
+
getRequestHandlers: () => {
|
|
2796
|
+
return this.handlersController.currentHandlers();
|
|
2797
|
+
},
|
|
2798
|
+
emitter: this.emitter,
|
|
2799
|
+
workerChannel: new WorkerChannel({
|
|
2800
|
+
worker: workerPromise
|
|
2801
|
+
})
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
async start(options = {}) {
|
|
2805
|
+
if ("waitUntilReady" in options) {
|
|
2806
|
+
devUtils8.warn(
|
|
2807
|
+
'The "waitUntilReady" option has been deprecated. Please remove it from this "worker.start()" call. Follow the recommended Browser integration (https://mswjs.io/docs/integrations/browser) to eliminate any race conditions between the Service Worker registration and any requests made by your application on initial render.'
|
|
2808
|
+
);
|
|
2809
|
+
}
|
|
2810
|
+
if (this.context.isMockingEnabled) {
|
|
2811
|
+
devUtils8.warn(
|
|
2812
|
+
`Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.`
|
|
2813
|
+
);
|
|
2814
|
+
return this.context.registration;
|
|
2815
|
+
}
|
|
2816
|
+
this.context.workerStoppedAt = void 0;
|
|
2817
|
+
this.context.startOptions = mergeRight2(
|
|
2818
|
+
DEFAULT_START_OPTIONS,
|
|
2819
|
+
options
|
|
2820
|
+
);
|
|
2821
|
+
handleWebSocketEvent({
|
|
2822
|
+
getUnhandledRequestStrategy: () => {
|
|
2823
|
+
return this.context.startOptions.onUnhandledRequest;
|
|
2824
|
+
},
|
|
2825
|
+
getHandlers: () => {
|
|
2826
|
+
return this.handlersController.currentHandlers();
|
|
2827
|
+
},
|
|
2828
|
+
onMockedConnection: (connection) => {
|
|
2829
|
+
if (!this.context.startOptions.quiet) {
|
|
2830
|
+
attachWebSocketLogger(connection);
|
|
2831
|
+
}
|
|
2832
|
+
},
|
|
2833
|
+
onPassthroughConnection() {
|
|
2834
|
+
}
|
|
2835
|
+
});
|
|
2836
|
+
webSocketInterceptor.apply();
|
|
2837
|
+
this.subscriptions.push(() => {
|
|
2838
|
+
webSocketInterceptor.dispose();
|
|
2839
|
+
});
|
|
2840
|
+
if (!supportsServiceWorker()) {
|
|
2841
|
+
const fallbackInterceptor = createFallbackRequestListener(
|
|
2842
|
+
this.context,
|
|
2843
|
+
this.context.startOptions
|
|
2844
|
+
);
|
|
2845
|
+
this.subscriptions.push(() => {
|
|
2846
|
+
fallbackInterceptor.dispose();
|
|
2847
|
+
});
|
|
2848
|
+
this.context.isMockingEnabled = true;
|
|
2849
|
+
printStartMessage({
|
|
2850
|
+
message: "Mocking enabled (fallback mode).",
|
|
2851
|
+
quiet: this.context.startOptions.quiet
|
|
2852
|
+
});
|
|
2853
|
+
return void 0;
|
|
2854
|
+
}
|
|
2855
|
+
const startHandler = createStartHandler(this.context);
|
|
2856
|
+
const registration = await startHandler(this.context.startOptions, options);
|
|
2857
|
+
this.context.isMockingEnabled = true;
|
|
2858
|
+
return registration;
|
|
2859
|
+
}
|
|
2860
|
+
stop() {
|
|
2861
|
+
super.dispose();
|
|
2862
|
+
if (!this.context.isMockingEnabled) {
|
|
2863
|
+
devUtils8.warn(
|
|
2864
|
+
'Found a redundant "worker.stop()" call. Notice that stopping the worker after it has already been stopped has no effect. Consider removing this "worker.stop()" call.'
|
|
2865
|
+
);
|
|
2866
|
+
return;
|
|
2867
|
+
}
|
|
2868
|
+
this.context.isMockingEnabled = false;
|
|
2869
|
+
this.context.workerStoppedAt = Date.now();
|
|
2870
|
+
this.context.emitter.removeAllListeners();
|
|
2871
|
+
if (supportsServiceWorker()) {
|
|
2872
|
+
this.context.workerChannel.removeAllListeners("RESPONSE");
|
|
2873
|
+
window.clearInterval(this.context.keepAliveInterval);
|
|
2874
|
+
}
|
|
2875
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
2876
|
+
printStopMessage({
|
|
2877
|
+
quiet: this.context.startOptions?.quiet
|
|
2878
|
+
});
|
|
2879
|
+
}
|
|
2880
|
+
};
|
|
2881
|
+
function setupWorker(...handlers) {
|
|
2882
|
+
return new SetupWorkerApi(...handlers);
|
|
2883
|
+
}
|
|
2884
|
+
export {
|
|
2885
|
+
SetupWorkerApi,
|
|
2886
|
+
setupWorker
|
|
2887
|
+
};
|
|
2888
|
+
//# sourceMappingURL=index.mjs.map
|