msw 2.15.0 → 3.0.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/README.md +8 -0
- package/cli/init.js +12 -9
- package/cli/invariant.js +2 -2
- package/lib/_chunks/attach-sibling-handlers.js +360 -0
- package/lib/_chunks/attach-sibling-handlers.js.map +1 -0
- package/lib/_chunks/colors.js +18 -0
- package/lib/_chunks/colors.js.map +1 -0
- package/lib/_chunks/cookie-store.js +348 -0
- package/lib/_chunks/cookie-store.js.map +1 -0
- package/lib/_chunks/execute-handlers.js +29 -0
- package/lib/_chunks/execute-handlers.js.map +1 -0
- package/lib/_chunks/handlers-controller.d.ts +262 -0
- package/lib/_chunks/has-ref-counted.js +9 -0
- package/lib/_chunks/has-ref-counted.js.map +1 -0
- package/lib/_chunks/http-handler.d.ts +72 -0
- package/lib/_chunks/http-handler.js +182 -0
- package/lib/_chunks/http-handler.js.map +1 -0
- package/lib/_chunks/http-response.js +137 -0
- package/lib/_chunks/http-response.js.map +1 -0
- package/lib/{core → _chunks}/http.d.ts +15 -18
- package/lib/_chunks/http.js +30 -0
- package/lib/_chunks/http.js.map +1 -0
- package/lib/_chunks/interceptor-source.d.ts +163 -0
- package/lib/_chunks/interceptor-source.js +756 -0
- package/lib/_chunks/interceptor-source.js.map +1 -0
- package/lib/_chunks/is-object.js +11 -0
- package/lib/_chunks/is-object.js.map +1 -0
- package/lib/_chunks/match-request-url.d.ts +14 -0
- package/lib/_chunks/request-handler.d.ts +295 -0
- package/lib/_chunks/request-handler.js +369 -0
- package/lib/_chunks/request-handler.js.map +1 -0
- package/lib/_chunks/shared-options.d.ts +20 -0
- package/lib/_chunks/sse.d.ts +95 -0
- package/lib/_chunks/sse.js +599 -0
- package/lib/_chunks/sse.js.map +1 -0
- package/lib/_chunks/symbols.js +22 -0
- package/lib/_chunks/symbols.js.map +1 -0
- package/lib/_chunks/websocket-upgrade.js +46 -0
- package/lib/_chunks/websocket-upgrade.js.map +1 -0
- package/lib/_chunks/ws.d.ts +133 -0
- package/lib/_chunks/ws.js +293 -0
- package/lib/_chunks/ws.js.map +1 -0
- package/lib/browser/index.d.ts +225 -96
- package/lib/browser/index.js +555 -3694
- package/lib/browser/index.js.map +1 -1
- package/lib/core/experimental/index.d.ts +3 -17
- package/lib/core/experimental/index.js +2 -38
- package/lib/core/index.d.ts +15 -27
- package/lib/core/index.js +15 -64
- package/lib/graphql/index.d.ts +550 -0
- package/lib/graphql/index.js +1244 -0
- package/lib/graphql/index.js.map +1 -0
- package/lib/http/index.d.ts +4 -0
- package/lib/http/index.js +4 -0
- package/lib/iife/index.js +35857 -28422
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +185 -86
- package/lib/node/index.d.ts +79 -104
- package/lib/node/index.js +103 -201
- package/lib/node/index.js.map +1 -1
- package/lib/sse/index.d.ts +2 -0
- package/lib/sse/index.js +2 -0
- package/lib/{core → utils}/bypass.d.ts +5 -4
- package/lib/utils/bypass.js +41 -0
- package/lib/utils/bypass.js.map +1 -0
- package/lib/utils/delay.d.ts +15 -0
- package/lib/utils/delay.js +45 -0
- package/lib/utils/delay.js.map +1 -0
- package/lib/utils/get-clean-url-string.d.ts +9 -0
- package/lib/utils/get-clean-url-string.js +15 -0
- package/lib/utils/get-clean-url-string.js.map +1 -0
- package/lib/utils/get-response.d.ts +13 -0
- package/lib/utils/get-response.js +23 -0
- package/lib/utils/get-response.js.map +1 -0
- package/lib/utils/is-common-asset-request.d.ts +22 -0
- package/lib/utils/is-common-asset-request.js +31 -0
- package/lib/utils/is-common-asset-request.js.map +1 -0
- package/lib/utils/passthrough.d.ts +31 -0
- package/lib/utils/passthrough.js +41 -0
- package/lib/utils/passthrough.js.map +1 -0
- package/lib/vite/index.d.ts +44 -0
- package/lib/vite/index.js +90 -0
- package/lib/vite/index.js.map +1 -0
- package/lib/vite/runtime.d.ts +6 -0
- package/lib/vite/runtime.js +77 -0
- package/lib/vite/runtime.js.map +1 -0
- package/lib/ws/index.d.ts +4 -0
- package/lib/ws/index.js +4 -0
- package/package.json +93 -201
- package/src/browser/default-network-options.ts +31 -0
- package/src/browser/glossary.ts +11 -23
- package/src/browser/index.ts +5 -1
- package/src/browser/setup-worker.ts +15 -68
- package/src/browser/sources/fallback-http-source.ts +1 -1
- package/src/browser/sources/service-worker-source.ts +76 -69
- package/src/browser/tsconfig.browser.json +4 -2
- package/src/browser/utils/{deserializeRequest.ts → deserialize-request.ts} +3 -4
- package/src/browser/utils/{getAbsoluteWorkerUrl.test.ts → get-absolute-worker-url.test.ts} +3 -3
- package/src/browser/utils/get-worker-instance.ts +2 -2
- package/src/browser/utils/should-invalidate-worker.test.ts +11 -11
- package/src/browser/utils/should-invalidate-worker.ts +1 -1
- package/src/browser/utils/validate-worker-scope.ts +1 -1
- package/src/browser/utils/{workerChannel.ts → worker-channel.ts} +42 -20
- package/src/core/experimental/define-network.test.ts +43 -8
- package/src/core/experimental/define-network.ts +32 -13
- package/src/core/experimental/frames/http-frame.test.ts +15 -13
- package/src/core/experimental/frames/http-frame.ts +10 -9
- package/src/core/experimental/frames/websocket-frame.test.ts +129 -15
- package/src/core/experimental/frames/websocket-frame.ts +71 -20
- package/src/core/experimental/handlers-controller.test.ts +141 -34
- package/src/core/experimental/handlers-controller.ts +107 -30
- package/src/core/experimental/index.ts +1 -0
- package/src/core/experimental/on-unhandled-frame.test.ts +19 -19
- package/src/core/experimental/on-unhandled-frame.ts +7 -12
- package/src/core/experimental/request-utils.test.ts +4 -29
- package/src/core/experimental/request-utils.ts +0 -14
- package/src/core/experimental/sources/interceptor-source.ts +44 -29
- package/src/core/experimental/sources/network-source.test.ts +3 -3
- package/src/core/experimental/sources/network-source.ts +3 -3
- package/src/core/handlers/handler.ts +42 -0
- package/src/core/handlers/{RequestHandler.ts → request-handler.ts} +26 -41
- package/src/core/index.ts +35 -58
- package/src/core/shared-options.ts +21 -0
- package/src/core/type-utils.ts +18 -0
- package/src/core/utils/{cookieStore.ts → cookie-store.ts} +14 -9
- package/src/core/utils/{executeHandlers.ts → execute-handlers.ts} +2 -2
- package/src/core/utils/http-status-messages.ts +69 -0
- package/src/core/utils/internal/{attachSiblingHandlers.ts → attach-sibling-handlers.ts} +20 -0
- package/src/core/utils/internal/{devUtils.test.ts → dev-utils.test.ts} +3 -3
- package/src/core/utils/internal/{Disposable.ts → disposable.ts} +1 -1
- package/src/core/utils/internal/{getCallFrame.test.ts → get-call-frame.test.ts} +1 -1
- package/src/core/utils/internal/{getCallFrame.ts → get-call-frame.ts} +1 -1
- package/src/core/utils/internal/{hasRefCounted.test.ts → has-ref-counted.test.ts} +4 -4
- package/src/core/utils/internal/{hasRefCounted.ts → has-ref-counted.ts} +1 -1
- package/src/core/utils/internal/{isIterable.test.ts → is-iterable.test.ts} +1 -1
- package/src/core/utils/internal/is-iterable.ts +16 -0
- package/src/core/utils/internal/{isObject.test.ts → is-object.test.ts} +1 -1
- package/src/core/utils/internal/{isStringEqual.test.ts → is-string-equal.test.ts} +7 -7
- package/src/core/utils/internal/{jsonParse.test.ts → json-parse.test.ts} +1 -1
- package/src/core/utils/internal/observe-response-body-stream.test.ts +7 -7
- package/src/core/utils/internal/observe-response-body-stream.ts +3 -4
- package/src/core/utils/internal/{parseMultipartData.test.ts → parse-multipart-data.test.ts} +1 -1
- package/src/core/utils/internal/{parseMultipartData.ts → parse-multipart-data.ts} +1 -1
- package/src/core/utils/internal/{toReadonlyArray.test.ts → to-readonly-array.test.ts} +4 -4
- package/src/core/utils/logging/colors.ts +13 -0
- package/src/core/utils/logging/{getStatusCodeColor.test.ts → get-status-code-color.test.ts} +1 -1
- package/src/core/utils/logging/{getTimestamp.test.ts → get-timestamp.test.ts} +1 -1
- package/src/core/utils/logging/{serializeRequest.test.ts → serialize-request.test.ts} +1 -1
- package/src/core/utils/logging/{serializeResponse.test.ts → serialize-response.test.ts} +8 -10
- package/src/core/utils/logging/{serializeResponse.ts → serialize-response.ts} +2 -4
- package/src/core/utils/matching/match-request-url.test.ts +90 -0
- package/src/core/utils/matching/match-request-url.ts +45 -0
- package/src/core/utils/matching/{normalizePath.node.test.ts → normalize-path.node.test.ts} +2 -4
- package/src/core/utils/matching/{normalizePath.test.ts → normalize-path.test.ts} +2 -4
- package/src/core/utils/matching/{normalizePath.ts → normalize-path.ts} +8 -5
- package/src/core/utils/request/{getAllAcceptedMimeTypes.test.ts → get-all-accepted-mime-types.test.ts} +14 -14
- package/src/core/utils/request/get-request-cookies.ts +76 -0
- package/src/core/utils/request/store-response-cookies.ts +15 -0
- package/src/core/utils/request/{toPublicUrl.node.test.ts → to-public-url.node.test.ts} +1 -1
- package/src/core/utils/request/{toPublicUrl.test.ts → to-public-url.test.ts} +2 -2
- package/src/core/utils/{HttpResponse/decorators.ts → response-decorators.ts} +6 -8
- package/src/core/utils/url/{getAbsoluteUrl.node.test.ts → get-absolute-url.node.test.ts} +5 -7
- package/src/core/utils/url/{getAbsoluteUrl.test.ts → get-absolute-url.test.ts} +7 -7
- package/src/core/utils/url/{getAbsoluteUrl.ts → get-absolute-url.ts} +1 -1
- package/src/core/utils/url/is-absolute-url.test.ts +30 -0
- package/src/{core/handlers/GraphQLHandler.test.ts → graphql/graphql-handler.test.ts} +37 -36
- package/src/{core/handlers/GraphQLHandler.ts → graphql/graphql-handler.ts} +54 -41
- package/src/graphql/graphql-subscription-event.ts +39 -0
- package/src/graphql/graphql-subscription.test.ts +208 -0
- package/src/graphql/graphql-subscription.ts +1487 -0
- package/src/graphql/graphql.test.ts +14 -0
- package/src/graphql/graphql.ts +179 -0
- package/src/graphql/index.ts +34 -0
- package/src/{core/utils/internal/parseGraphQLRequest.test.ts → graphql/parse-graphql-request.test.ts} +47 -6
- package/src/{core/utils/internal/parseGraphQLRequest.ts → graphql/parse-graphql-request.ts} +59 -32
- package/src/{core/handlers/HttpHandler.test.ts → http/http-handler.test.ts} +22 -22
- package/src/{core/handlers/HttpHandler.ts → http/http-handler.ts} +16 -18
- package/src/{core/HttpResponse.test.ts → http/http-response.test.ts} +25 -27
- package/src/{core/HttpResponse.ts → http/http-response.ts} +15 -17
- package/src/{core → http}/http.ts +7 -7
- package/src/http/index.test.ts +19 -0
- package/src/http/index.ts +22 -0
- package/src/http/symbols.ts +19 -0
- package/src/iife/index.ts +2 -0
- package/src/mockServiceWorker.js +183 -84
- package/src/node/async-handlers-controller.test.ts +4 -4
- package/src/node/glossary.ts +8 -4
- package/src/node/index.ts +1 -6
- package/src/node/setup-server-common.ts +16 -73
- package/src/node/setup-server.ts +9 -40
- package/src/sse/index.test.ts +14 -0
- package/src/sse/index.ts +7 -0
- package/src/{core → sse}/sse.ts +25 -21
- package/src/tsconfig.core.build.json +5 -1
- package/src/tsconfig.core.json +8 -1
- package/src/tsconfig.node.json +1 -1
- package/src/tsconfig.src.json +1 -1
- package/src/{core → utils}/bypass.test.ts +22 -5
- package/src/{core → utils}/bypass.ts +11 -0
- package/src/{core → utils}/delay.ts +5 -5
- package/src/utils/get-clean-url-string.test.ts +24 -0
- package/src/utils/get-clean-url-string.ts +16 -0
- package/src/{core/getResponse.test.ts → utils/get-response.test.ts} +9 -9
- package/src/{core/getResponse.ts → utils/get-response.ts} +2 -2
- package/src/{core/isCommonAssetRequest.ts → utils/is-common-asset-request.ts} +4 -3
- package/src/utils/passthrough.test.ts +41 -0
- package/src/utils/passthrough.ts +46 -0
- package/src/vite/client.d.ts +16 -0
- package/src/vite/index.ts +4 -0
- package/src/vite/options.d.ts +5 -0
- package/src/vite/plugin.test.ts +918 -0
- package/src/vite/plugin.ts +133 -0
- package/src/vite/runtime.ts +117 -0
- package/src/vite/tsconfig.build.json +7 -0
- package/src/ws/index.ts +23 -0
- package/src/{core/ws/utils/attachWebSocketLogger.ts → ws/utils/attach-websocket-logger.ts} +45 -23
- package/src/{core/ws/utils/getMessageLength.test.ts → ws/utils/get-message-length.test.ts} +4 -4
- package/src/{core/ws/utils/getMessageLength.ts → ws/utils/get-message-length.ts} +1 -1
- package/src/{core/ws/utils/getPublicData.test.ts → ws/utils/get-public-data.test.ts} +7 -7
- package/src/ws/utils/get-public-data.ts +23 -0
- package/src/{core/ws/utils/truncateMessage.test.ts → ws/utils/truncate-message.test.ts} +3 -3
- package/src/{core/ws/WebSocketClientManager.test.ts → ws/websocket-client-manager.test.ts} +8 -9
- package/src/{core/ws/WebSocketClientManager.ts → ws/websocket-client-manager.ts} +24 -28
- package/src/{core/ws/WebSocketClientStore.ts → ws/websocket-client-store.ts} +2 -2
- package/src/{core/handlers/WebSocketHandler.test.ts → ws/websocket-handler.test.ts} +15 -15
- package/src/{core/handlers/WebSocketHandler.ts → ws/websocket-handler.ts} +144 -32
- package/src/{core/ws/WebSocketIndexedDBClientStore.ts → ws/websocket-indexeddb-client-store.ts} +12 -13
- package/src/{core/ws/WebSocketMemoryClientStore.ts → ws/websocket-memory-client-store.ts} +4 -4
- package/src/ws/websocket-upgrade.ts +83 -0
- package/src/{core → ws}/ws.test.ts +3 -4
- package/src/{core → ws}/ws.ts +106 -53
- package/browser/package.json +0 -31
- package/cli/package.json +0 -3
- package/config/package.json +0 -3
- package/config/scripts/postinstall.js +0 -36
- package/lib/browser/index.d.mts +0 -112
- package/lib/browser/index.mjs +0 -3706
- package/lib/browser/index.mjs.map +0 -1
- package/lib/core/HttpResponse-BE_Y2Ak9.d.mts +0 -389
- package/lib/core/HttpResponse-DL-P1EeG.d.ts +0 -389
- package/lib/core/HttpResponse.d.mts +0 -6
- package/lib/core/HttpResponse.d.ts +0 -6
- package/lib/core/HttpResponse.js +0 -176
- package/lib/core/HttpResponse.js.map +0 -1
- package/lib/core/HttpResponse.mjs +0 -159
- package/lib/core/HttpResponse.mjs.map +0 -1
- package/lib/core/bypass.d.mts +0 -16
- package/lib/core/bypass.js +0 -42
- package/lib/core/bypass.js.map +0 -1
- package/lib/core/bypass.mjs +0 -22
- package/lib/core/bypass.mjs.map +0 -1
- package/lib/core/delay.d.mts +0 -18
- package/lib/core/delay.d.ts +0 -18
- package/lib/core/delay.js +0 -77
- package/lib/core/delay.js.map +0 -1
- package/lib/core/delay.mjs +0 -57
- package/lib/core/delay.mjs.map +0 -1
- package/lib/core/experimental/compat.d.mts +0 -17
- package/lib/core/experimental/compat.d.ts +0 -17
- package/lib/core/experimental/compat.js +0 -55
- package/lib/core/experimental/compat.js.map +0 -1
- package/lib/core/experimental/compat.mjs +0 -37
- package/lib/core/experimental/compat.mjs.map +0 -1
- package/lib/core/experimental/define-network.d.mts +0 -75
- package/lib/core/experimental/define-network.d.ts +0 -75
- package/lib/core/experimental/define-network.js +0 -134
- package/lib/core/experimental/define-network.js.map +0 -1
- package/lib/core/experimental/define-network.mjs +0 -119
- package/lib/core/experimental/define-network.mjs.map +0 -1
- package/lib/core/experimental/frames/http-frame.d.mts +0 -77
- package/lib/core/experimental/frames/http-frame.d.ts +0 -77
- package/lib/core/experimental/frames/http-frame.js +0 -197
- package/lib/core/experimental/frames/http-frame.js.map +0 -1
- package/lib/core/experimental/frames/http-frame.mjs +0 -181
- package/lib/core/experimental/frames/http-frame.mjs.map +0 -1
- package/lib/core/experimental/frames/network-frame.d.mts +0 -12
- package/lib/core/experimental/frames/network-frame.d.ts +0 -12
- package/lib/core/experimental/frames/network-frame.js +0 -35
- package/lib/core/experimental/frames/network-frame.js.map +0 -1
- package/lib/core/experimental/frames/network-frame.mjs +0 -15
- package/lib/core/experimental/frames/network-frame.mjs.map +0 -1
- package/lib/core/experimental/frames/websocket-frame.d.mts +0 -55
- package/lib/core/experimental/frames/websocket-frame.d.ts +0 -55
- package/lib/core/experimental/frames/websocket-frame.js +0 -131
- package/lib/core/experimental/frames/websocket-frame.js.map +0 -1
- package/lib/core/experimental/frames/websocket-frame.mjs +0 -118
- package/lib/core/experimental/frames/websocket-frame.mjs.map +0 -1
- package/lib/core/experimental/handlers-controller.d.mts +0 -36
- package/lib/core/experimental/handlers-controller.d.ts +0 -36
- package/lib/core/experimental/handlers-controller.js +0 -146
- package/lib/core/experimental/handlers-controller.js.map +0 -1
- package/lib/core/experimental/handlers-controller.mjs +0 -126
- package/lib/core/experimental/handlers-controller.mjs.map +0 -1
- package/lib/core/experimental/index.d.mts +0 -17
- package/lib/core/experimental/index.js.map +0 -1
- package/lib/core/experimental/index.mjs +0 -27
- package/lib/core/experimental/index.mjs.map +0 -1
- package/lib/core/experimental/on-unhandled-frame.d.mts +0 -12
- package/lib/core/experimental/on-unhandled-frame.d.ts +0 -12
- package/lib/core/experimental/on-unhandled-frame.js +0 -91
- package/lib/core/experimental/on-unhandled-frame.js.map +0 -1
- package/lib/core/experimental/on-unhandled-frame.mjs +0 -71
- package/lib/core/experimental/on-unhandled-frame.mjs.map +0 -1
- package/lib/core/experimental/request-utils.d.mts +0 -12
- package/lib/core/experimental/request-utils.d.ts +0 -12
- package/lib/core/experimental/request-utils.js +0 -50
- package/lib/core/experimental/request-utils.js.map +0 -1
- package/lib/core/experimental/request-utils.mjs +0 -30
- package/lib/core/experimental/request-utils.mjs.map +0 -1
- package/lib/core/experimental/setup-api.d.mts +0 -33
- package/lib/core/experimental/setup-api.d.ts +0 -33
- package/lib/core/experimental/setup-api.js +0 -58
- package/lib/core/experimental/setup-api.js.map +0 -1
- package/lib/core/experimental/setup-api.mjs +0 -40
- package/lib/core/experimental/setup-api.mjs.map +0 -1
- package/lib/core/experimental/sources/interceptor-source.d.mts +0 -28
- package/lib/core/experimental/sources/interceptor-source.d.ts +0 -28
- package/lib/core/experimental/sources/interceptor-source.js +0 -155
- package/lib/core/experimental/sources/interceptor-source.js.map +0 -1
- package/lib/core/experimental/sources/interceptor-source.mjs +0 -135
- package/lib/core/experimental/sources/interceptor-source.mjs.map +0 -1
- package/lib/core/experimental/sources/network-source.d.mts +0 -31
- package/lib/core/experimental/sources/network-source.d.ts +0 -31
- package/lib/core/experimental/sources/network-source.js +0 -51
- package/lib/core/experimental/sources/network-source.js.map +0 -1
- package/lib/core/experimental/sources/network-source.mjs +0 -32
- package/lib/core/experimental/sources/network-source.mjs.map +0 -1
- package/lib/core/getResponse.d.mts +0 -18
- package/lib/core/getResponse.d.ts +0 -18
- package/lib/core/getResponse.js +0 -35
- package/lib/core/getResponse.js.map +0 -1
- package/lib/core/getResponse.mjs +0 -17
- package/lib/core/getResponse.mjs.map +0 -1
- package/lib/core/graphql.d.mts +0 -76
- package/lib/core/graphql.d.ts +0 -76
- package/lib/core/graphql.js +0 -91
- package/lib/core/graphql.js.map +0 -1
- package/lib/core/graphql.mjs +0 -74
- package/lib/core/graphql.mjs.map +0 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +0 -6
- package/lib/core/handlers/GraphQLHandler.d.ts +0 -6
- package/lib/core/handlers/GraphQLHandler.js +0 -232
- package/lib/core/handlers/GraphQLHandler.js.map +0 -1
- package/lib/core/handlers/GraphQLHandler.mjs +0 -221
- package/lib/core/handlers/GraphQLHandler.mjs.map +0 -1
- package/lib/core/handlers/HttpHandler.d.mts +0 -75
- package/lib/core/handlers/HttpHandler.d.ts +0 -75
- package/lib/core/handlers/HttpHandler.js +0 -129
- package/lib/core/handlers/HttpHandler.js.map +0 -1
- package/lib/core/handlers/HttpHandler.mjs +0 -113
- package/lib/core/handlers/HttpHandler.mjs.map +0 -1
- package/lib/core/handlers/RequestHandler.d.mts +0 -6
- package/lib/core/handlers/RequestHandler.d.ts +0 -6
- package/lib/core/handlers/RequestHandler.js +0 -365
- package/lib/core/handlers/RequestHandler.js.map +0 -1
- package/lib/core/handlers/RequestHandler.mjs +0 -348
- package/lib/core/handlers/RequestHandler.mjs.map +0 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +0 -49
- package/lib/core/handlers/WebSocketHandler.d.ts +0 -49
- package/lib/core/handlers/WebSocketHandler.js +0 -178
- package/lib/core/handlers/WebSocketHandler.js.map +0 -1
- package/lib/core/handlers/WebSocketHandler.mjs +0 -160
- package/lib/core/handlers/WebSocketHandler.mjs.map +0 -1
- package/lib/core/http.d.mts +0 -31
- package/lib/core/http.js +0 -41
- package/lib/core/http.js.map +0 -1
- package/lib/core/http.mjs +0 -25
- package/lib/core/http.mjs.map +0 -1
- package/lib/core/index.d.mts +0 -27
- package/lib/core/index.js.map +0 -1
- package/lib/core/index.mjs +0 -52
- package/lib/core/index.mjs.map +0 -1
- package/lib/core/isCommonAssetRequest.d.mts +0 -20
- package/lib/core/isCommonAssetRequest.d.ts +0 -20
- package/lib/core/isCommonAssetRequest.js +0 -42
- package/lib/core/isCommonAssetRequest.js.map +0 -1
- package/lib/core/isCommonAssetRequest.mjs +0 -22
- package/lib/core/isCommonAssetRequest.mjs.map +0 -1
- package/lib/core/on-unhandled-frame-0KmwUmeV.d.ts +0 -56
- package/lib/core/on-unhandled-frame-gkokW4Rr.d.mts +0 -56
- package/lib/core/passthrough.d.mts +0 -24
- package/lib/core/passthrough.d.ts +0 -24
- package/lib/core/passthrough.js +0 -33
- package/lib/core/passthrough.js.map +0 -1
- package/lib/core/passthrough.mjs +0 -13
- package/lib/core/passthrough.mjs.map +0 -1
- package/lib/core/sharedOptions.d.mts +0 -68
- package/lib/core/sharedOptions.d.ts +0 -68
- package/lib/core/sharedOptions.js +0 -17
- package/lib/core/sharedOptions.js.map +0 -1
- package/lib/core/sharedOptions.mjs +0 -1
- package/lib/core/sharedOptions.mjs.map +0 -1
- package/lib/core/sse.d.mts +0 -102
- package/lib/core/sse.d.ts +0 -102
- package/lib/core/sse.js +0 -690
- package/lib/core/sse.js.map +0 -1
- package/lib/core/sse.mjs +0 -672
- package/lib/core/sse.mjs.map +0 -1
- package/lib/core/typeUtils.d.mts +0 -12
- package/lib/core/typeUtils.d.ts +0 -12
- package/lib/core/typeUtils.js +0 -17
- package/lib/core/typeUtils.js.map +0 -1
- package/lib/core/typeUtils.mjs +0 -1
- package/lib/core/typeUtils.mjs.map +0 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +0 -22
- package/lib/core/utils/HttpResponse/decorators.d.ts +0 -22
- package/lib/core/utils/HttpResponse/decorators.js +0 -84
- package/lib/core/utils/HttpResponse/decorators.js.map +0 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +0 -54
- package/lib/core/utils/HttpResponse/decorators.mjs.map +0 -1
- package/lib/core/utils/cookieStore.d.mts +0 -13
- package/lib/core/utils/cookieStore.d.ts +0 -13
- package/lib/core/utils/cookieStore.js +0 -90
- package/lib/core/utils/cookieStore.js.map +0 -1
- package/lib/core/utils/cookieStore.mjs +0 -74
- package/lib/core/utils/cookieStore.mjs.map +0 -1
- package/lib/core/utils/executeHandlers.d.mts +0 -6
- package/lib/core/utils/executeHandlers.d.ts +0 -6
- package/lib/core/utils/executeHandlers.js +0 -51
- package/lib/core/utils/executeHandlers.js.map +0 -1
- package/lib/core/utils/executeHandlers.mjs +0 -31
- package/lib/core/utils/executeHandlers.mjs.map +0 -1
- package/lib/core/utils/handleRequest.d.mts +0 -30
- package/lib/core/utils/handleRequest.d.ts +0 -30
- package/lib/core/utils/handleRequest.js +0 -76
- package/lib/core/utils/handleRequest.js.map +0 -1
- package/lib/core/utils/handleRequest.mjs +0 -58
- package/lib/core/utils/handleRequest.mjs.map +0 -1
- package/lib/core/utils/internal/Disposable.d.mts +0 -7
- package/lib/core/utils/internal/Disposable.d.ts +0 -7
- package/lib/core/utils/internal/Disposable.js +0 -51
- package/lib/core/utils/internal/Disposable.js.map +0 -1
- package/lib/core/utils/internal/Disposable.mjs +0 -31
- package/lib/core/utils/internal/Disposable.mjs.map +0 -1
- package/lib/core/utils/internal/attachSiblingHandlers.d.mts +0 -15
- package/lib/core/utils/internal/attachSiblingHandlers.d.ts +0 -15
- package/lib/core/utils/internal/attachSiblingHandlers.js +0 -44
- package/lib/core/utils/internal/attachSiblingHandlers.js.map +0 -1
- package/lib/core/utils/internal/attachSiblingHandlers.mjs +0 -24
- package/lib/core/utils/internal/attachSiblingHandlers.mjs.map +0 -1
- package/lib/core/utils/internal/checkGlobals.d.mts +0 -3
- package/lib/core/utils/internal/checkGlobals.d.ts +0 -3
- package/lib/core/utils/internal/checkGlobals.js +0 -34
- package/lib/core/utils/internal/checkGlobals.js.map +0 -1
- package/lib/core/utils/internal/checkGlobals.mjs +0 -14
- package/lib/core/utils/internal/checkGlobals.mjs.map +0 -1
- package/lib/core/utils/internal/devUtils.d.mts +0 -28
- package/lib/core/utils/internal/devUtils.d.ts +0 -28
- package/lib/core/utils/internal/devUtils.js +0 -48
- package/lib/core/utils/internal/devUtils.js.map +0 -1
- package/lib/core/utils/internal/devUtils.mjs +0 -28
- package/lib/core/utils/internal/devUtils.mjs.map +0 -1
- package/lib/core/utils/internal/getCallFrame.d.mts +0 -6
- package/lib/core/utils/internal/getCallFrame.d.ts +0 -6
- package/lib/core/utils/internal/getCallFrame.js +0 -41
- package/lib/core/utils/internal/getCallFrame.js.map +0 -1
- package/lib/core/utils/internal/getCallFrame.mjs +0 -21
- package/lib/core/utils/internal/getCallFrame.mjs.map +0 -1
- package/lib/core/utils/internal/hasRefCounted.d.mts +0 -3
- package/lib/core/utils/internal/hasRefCounted.d.ts +0 -3
- package/lib/core/utils/internal/hasRefCounted.js +0 -34
- package/lib/core/utils/internal/hasRefCounted.js.map +0 -1
- package/lib/core/utils/internal/hasRefCounted.mjs +0 -14
- package/lib/core/utils/internal/hasRefCounted.mjs.map +0 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +0 -19
- package/lib/core/utils/internal/isHandlerKind.d.ts +0 -19
- package/lib/core/utils/internal/isHandlerKind.js +0 -30
- package/lib/core/utils/internal/isHandlerKind.js.map +0 -1
- package/lib/core/utils/internal/isHandlerKind.mjs +0 -10
- package/lib/core/utils/internal/isHandlerKind.mjs.map +0 -1
- package/lib/core/utils/internal/isIterable.d.mts +0 -20
- package/lib/core/utils/internal/isIterable.d.ts +0 -20
- package/lib/core/utils/internal/isIterable.js +0 -30
- package/lib/core/utils/internal/isIterable.js.map +0 -1
- package/lib/core/utils/internal/isIterable.mjs +0 -10
- package/lib/core/utils/internal/isIterable.mjs.map +0 -1
- package/lib/core/utils/internal/isObject.d.mts +0 -6
- package/lib/core/utils/internal/isObject.d.ts +0 -6
- package/lib/core/utils/internal/isObject.js +0 -27
- package/lib/core/utils/internal/isObject.js.map +0 -1
- package/lib/core/utils/internal/isObject.mjs +0 -7
- package/lib/core/utils/internal/isObject.mjs.map +0 -1
- package/lib/core/utils/internal/isStringEqual.d.mts +0 -6
- package/lib/core/utils/internal/isStringEqual.d.ts +0 -6
- package/lib/core/utils/internal/isStringEqual.js +0 -27
- package/lib/core/utils/internal/isStringEqual.js.map +0 -1
- package/lib/core/utils/internal/isStringEqual.mjs +0 -7
- package/lib/core/utils/internal/isStringEqual.mjs.map +0 -1
- package/lib/core/utils/internal/jsonParse.d.mts +0 -7
- package/lib/core/utils/internal/jsonParse.d.ts +0 -7
- package/lib/core/utils/internal/jsonParse.js +0 -31
- package/lib/core/utils/internal/jsonParse.js.map +0 -1
- package/lib/core/utils/internal/jsonParse.mjs +0 -11
- package/lib/core/utils/internal/jsonParse.mjs.map +0 -1
- package/lib/core/utils/internal/mergeRight.d.mts +0 -7
- package/lib/core/utils/internal/mergeRight.d.ts +0 -7
- package/lib/core/utils/internal/mergeRight.js +0 -43
- package/lib/core/utils/internal/mergeRight.js.map +0 -1
- package/lib/core/utils/internal/mergeRight.mjs +0 -23
- package/lib/core/utils/internal/mergeRight.mjs.map +0 -1
- package/lib/core/utils/internal/observe-response-body-stream.d.mts +0 -18
- package/lib/core/utils/internal/observe-response-body-stream.d.ts +0 -18
- package/lib/core/utils/internal/observe-response-body-stream.js +0 -64
- package/lib/core/utils/internal/observe-response-body-stream.js.map +0 -1
- package/lib/core/utils/internal/observe-response-body-stream.mjs +0 -44
- package/lib/core/utils/internal/observe-response-body-stream.mjs.map +0 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +0 -6
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +0 -6
- package/lib/core/utils/internal/parseGraphQLRequest.js +0 -146
- package/lib/core/utils/internal/parseGraphQLRequest.js.map +0 -1
- package/lib/core/utils/internal/parseGraphQLRequest.mjs +0 -129
- package/lib/core/utils/internal/parseGraphQLRequest.mjs.map +0 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +0 -14
- package/lib/core/utils/internal/parseMultipartData.d.ts +0 -14
- package/lib/core/utils/internal/parseMultipartData.js +0 -84
- package/lib/core/utils/internal/parseMultipartData.js.map +0 -1
- package/lib/core/utils/internal/parseMultipartData.mjs +0 -64
- package/lib/core/utils/internal/parseMultipartData.mjs.map +0 -1
- package/lib/core/utils/internal/pipeEvents.d.mts +0 -8
- package/lib/core/utils/internal/pipeEvents.d.ts +0 -8
- package/lib/core/utils/internal/pipeEvents.js +0 -37
- package/lib/core/utils/internal/pipeEvents.js.map +0 -1
- package/lib/core/utils/internal/pipeEvents.mjs +0 -17
- package/lib/core/utils/internal/pipeEvents.mjs.map +0 -1
- package/lib/core/utils/internal/toReadonlyArray.d.mts +0 -6
- package/lib/core/utils/internal/toReadonlyArray.d.ts +0 -6
- package/lib/core/utils/internal/toReadonlyArray.js +0 -29
- package/lib/core/utils/internal/toReadonlyArray.js.map +0 -1
- package/lib/core/utils/internal/toReadonlyArray.mjs +0 -9
- package/lib/core/utils/internal/toReadonlyArray.mjs.map +0 -1
- package/lib/core/utils/internal/tryCatch.d.mts +0 -3
- package/lib/core/utils/internal/tryCatch.d.ts +0 -3
- package/lib/core/utils/internal/tryCatch.js +0 -32
- package/lib/core/utils/internal/tryCatch.js.map +0 -1
- package/lib/core/utils/internal/tryCatch.mjs +0 -12
- package/lib/core/utils/internal/tryCatch.mjs.map +0 -1
- package/lib/core/utils/logging/getStatusCodeColor.d.mts +0 -11
- package/lib/core/utils/logging/getStatusCodeColor.d.ts +0 -11
- package/lib/core/utils/logging/getStatusCodeColor.js +0 -40
- package/lib/core/utils/logging/getStatusCodeColor.js.map +0 -1
- package/lib/core/utils/logging/getStatusCodeColor.mjs +0 -20
- package/lib/core/utils/logging/getStatusCodeColor.mjs.map +0 -1
- package/lib/core/utils/logging/getTimestamp.d.mts +0 -9
- package/lib/core/utils/logging/getTimestamp.d.ts +0 -9
- package/lib/core/utils/logging/getTimestamp.js +0 -32
- package/lib/core/utils/logging/getTimestamp.js.map +0 -1
- package/lib/core/utils/logging/getTimestamp.mjs +0 -12
- package/lib/core/utils/logging/getTimestamp.mjs.map +0 -1
- package/lib/core/utils/logging/serializeRequest.d.mts +0 -12
- package/lib/core/utils/logging/serializeRequest.d.ts +0 -12
- package/lib/core/utils/logging/serializeRequest.js +0 -34
- package/lib/core/utils/logging/serializeRequest.js.map +0 -1
- package/lib/core/utils/logging/serializeRequest.mjs +0 -14
- package/lib/core/utils/logging/serializeRequest.mjs.map +0 -1
- package/lib/core/utils/logging/serializeResponse.d.mts +0 -9
- package/lib/core/utils/logging/serializeResponse.d.ts +0 -9
- package/lib/core/utils/logging/serializeResponse.js +0 -48
- package/lib/core/utils/logging/serializeResponse.js.map +0 -1
- package/lib/core/utils/logging/serializeResponse.mjs +0 -18
- package/lib/core/utils/logging/serializeResponse.mjs.map +0 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +0 -20
- package/lib/core/utils/matching/matchRequestUrl.d.ts +0 -20
- package/lib/core/utils/matching/matchRequestUrl.js +0 -55
- package/lib/core/utils/matching/matchRequestUrl.js.map +0 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +0 -35
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +0 -1
- package/lib/core/utils/matching/normalizePath.d.mts +0 -13
- package/lib/core/utils/matching/normalizePath.d.ts +0 -13
- package/lib/core/utils/matching/normalizePath.js +0 -33
- package/lib/core/utils/matching/normalizePath.js.map +0 -1
- package/lib/core/utils/matching/normalizePath.mjs +0 -13
- package/lib/core/utils/matching/normalizePath.mjs.map +0 -1
- package/lib/core/utils/request/getAllAcceptedMimeTypes.d.mts +0 -14
- package/lib/core/utils/request/getAllAcceptedMimeTypes.d.ts +0 -14
- package/lib/core/utils/request/getAllAcceptedMimeTypes.js +0 -61
- package/lib/core/utils/request/getAllAcceptedMimeTypes.js.map +0 -1
- package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs +0 -41
- package/lib/core/utils/request/getAllAcceptedMimeTypes.mjs.map +0 -1
- package/lib/core/utils/request/getRequestCookies.d.mts +0 -3
- package/lib/core/utils/request/getRequestCookies.d.ts +0 -3
- package/lib/core/utils/request/getRequestCookies.js +0 -79
- package/lib/core/utils/request/getRequestCookies.js.map +0 -1
- package/lib/core/utils/request/getRequestCookies.mjs +0 -62
- package/lib/core/utils/request/getRequestCookies.mjs.map +0 -1
- package/lib/core/utils/request/onUnhandledRequest.d.mts +0 -9
- package/lib/core/utils/request/onUnhandledRequest.d.ts +0 -9
- package/lib/core/utils/request/onUnhandledRequest.js +0 -76
- package/lib/core/utils/request/onUnhandledRequest.js.map +0 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +0 -56
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +0 -1
- package/lib/core/utils/request/storeResponseCookies.d.mts +0 -3
- package/lib/core/utils/request/storeResponseCookies.d.ts +0 -3
- package/lib/core/utils/request/storeResponseCookies.js +0 -32
- package/lib/core/utils/request/storeResponseCookies.js.map +0 -1
- package/lib/core/utils/request/storeResponseCookies.mjs +0 -12
- package/lib/core/utils/request/storeResponseCookies.mjs.map +0 -1
- package/lib/core/utils/request/toPublicUrl.d.mts +0 -7
- package/lib/core/utils/request/toPublicUrl.d.ts +0 -7
- package/lib/core/utils/request/toPublicUrl.js +0 -31
- package/lib/core/utils/request/toPublicUrl.js.map +0 -1
- package/lib/core/utils/request/toPublicUrl.mjs +0 -11
- package/lib/core/utils/request/toPublicUrl.mjs.map +0 -1
- package/lib/core/utils/toResponseInit.d.mts +0 -3
- package/lib/core/utils/toResponseInit.d.ts +0 -3
- package/lib/core/utils/toResponseInit.js +0 -31
- package/lib/core/utils/toResponseInit.js.map +0 -1
- package/lib/core/utils/toResponseInit.mjs +0 -11
- package/lib/core/utils/toResponseInit.mjs.map +0 -1
- package/lib/core/utils/url/cleanUrl.d.mts +0 -7
- package/lib/core/utils/url/cleanUrl.d.ts +0 -7
- package/lib/core/utils/url/cleanUrl.js +0 -31
- package/lib/core/utils/url/cleanUrl.js.map +0 -1
- package/lib/core/utils/url/cleanUrl.mjs +0 -11
- package/lib/core/utils/url/cleanUrl.mjs.map +0 -1
- package/lib/core/utils/url/getAbsoluteUrl.d.mts +0 -6
- package/lib/core/utils/url/getAbsoluteUrl.d.ts +0 -6
- package/lib/core/utils/url/getAbsoluteUrl.js +0 -38
- package/lib/core/utils/url/getAbsoluteUrl.js.map +0 -1
- package/lib/core/utils/url/getAbsoluteUrl.mjs +0 -18
- package/lib/core/utils/url/getAbsoluteUrl.mjs.map +0 -1
- package/lib/core/utils/url/isAbsoluteUrl.d.mts +0 -6
- package/lib/core/utils/url/isAbsoluteUrl.d.ts +0 -6
- package/lib/core/utils/url/isAbsoluteUrl.js +0 -27
- package/lib/core/utils/url/isAbsoluteUrl.js.map +0 -1
- package/lib/core/utils/url/isAbsoluteUrl.mjs +0 -7
- package/lib/core/utils/url/isAbsoluteUrl.mjs.map +0 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +0 -65
- package/lib/core/ws/WebSocketClientManager.d.ts +0 -65
- package/lib/core/ws/WebSocketClientManager.js +0 -163
- package/lib/core/ws/WebSocketClientManager.js.map +0 -1
- package/lib/core/ws/WebSocketClientManager.mjs +0 -143
- package/lib/core/ws/WebSocketClientManager.mjs.map +0 -1
- package/lib/core/ws/WebSocketClientStore.d.mts +0 -13
- package/lib/core/ws/WebSocketClientStore.d.ts +0 -13
- package/lib/core/ws/WebSocketClientStore.js +0 -26
- package/lib/core/ws/WebSocketClientStore.js.map +0 -1
- package/lib/core/ws/WebSocketClientStore.mjs +0 -6
- package/lib/core/ws/WebSocketClientStore.mjs.map +0 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.mts +0 -14
- package/lib/core/ws/WebSocketIndexedDBClientStore.d.ts +0 -14
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +0 -131
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +0 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +0 -111
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +0 -1
- package/lib/core/ws/WebSocketMemoryClientStore.d.mts +0 -12
- package/lib/core/ws/WebSocketMemoryClientStore.d.ts +0 -12
- package/lib/core/ws/WebSocketMemoryClientStore.js +0 -42
- package/lib/core/ws/WebSocketMemoryClientStore.js.map +0 -1
- package/lib/core/ws/WebSocketMemoryClientStore.mjs +0 -22
- package/lib/core/ws/WebSocketMemoryClientStore.mjs.map +0 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +0 -20
- package/lib/core/ws/handleWebSocketEvent.d.ts +0 -20
- package/lib/core/ws/handleWebSocketEvent.js +0 -61
- package/lib/core/ws/handleWebSocketEvent.js.map +0 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +0 -43
- package/lib/core/ws/handleWebSocketEvent.mjs.map +0 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +0 -18
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +0 -18
- package/lib/core/ws/utils/attachWebSocketLogger.js +0 -228
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +0 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +0 -208
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +0 -1
- package/lib/core/ws/utils/getMessageLength.d.mts +0 -11
- package/lib/core/ws/utils/getMessageLength.d.ts +0 -11
- package/lib/core/ws/utils/getMessageLength.js +0 -34
- package/lib/core/ws/utils/getMessageLength.js.map +0 -1
- package/lib/core/ws/utils/getMessageLength.mjs +0 -14
- package/lib/core/ws/utils/getMessageLength.mjs.map +0 -1
- package/lib/core/ws/utils/getPublicData.d.mts +0 -5
- package/lib/core/ws/utils/getPublicData.d.ts +0 -5
- package/lib/core/ws/utils/getPublicData.js +0 -37
- package/lib/core/ws/utils/getPublicData.js.map +0 -1
- package/lib/core/ws/utils/getPublicData.mjs +0 -17
- package/lib/core/ws/utils/getPublicData.mjs.map +0 -1
- package/lib/core/ws/utils/truncateMessage.d.mts +0 -3
- package/lib/core/ws/utils/truncateMessage.d.ts +0 -3
- package/lib/core/ws/utils/truncateMessage.js +0 -31
- package/lib/core/ws/utils/truncateMessage.js.map +0 -1
- package/lib/core/ws/utils/truncateMessage.mjs +0 -11
- package/lib/core/ws/utils/truncateMessage.mjs.map +0 -1
- package/lib/core/ws/webSocketInterceptor.d.mts +0 -5
- package/lib/core/ws/webSocketInterceptor.d.ts +0 -5
- package/lib/core/ws/webSocketInterceptor.js +0 -26
- package/lib/core/ws/webSocketInterceptor.js.map +0 -1
- package/lib/core/ws/webSocketInterceptor.mjs +0 -6
- package/lib/core/ws/webSocketInterceptor.mjs.map +0 -1
- package/lib/core/ws.d.mts +0 -88
- package/lib/core/ws.d.ts +0 -88
- package/lib/core/ws.js +0 -94
- package/lib/core/ws.js.map +0 -1
- package/lib/core/ws.mjs +0 -80
- package/lib/core/ws.mjs.map +0 -1
- package/lib/native/index.d.mts +0 -66
- package/lib/native/index.d.ts +0 -66
- package/lib/native/index.js +0 -88
- package/lib/native/index.js.map +0 -1
- package/lib/native/index.mjs +0 -67
- package/lib/native/index.mjs.map +0 -1
- package/lib/node/index.d.mts +0 -113
- package/lib/node/index.mjs +0 -185
- package/lib/node/index.mjs.map +0 -1
- package/lib/shims/cookie.d.mts +0 -7
- package/lib/shims/cookie.d.ts +0 -7
- package/lib/shims/cookie.js +0 -294
- package/lib/shims/cookie.mjs +0 -286
- package/lib/shims/statuses.d.mts +0 -6
- package/lib/shims/statuses.d.ts +0 -6
- package/lib/shims/statuses.js +0 -195
- package/lib/shims/statuses.mjs +0 -187
- package/native/package.json +0 -30
- package/node/package.json +0 -33
- package/src/browser/utils/pruneGetRequestBody.test.ts +0 -51
- package/src/browser/utils/pruneGetRequestBody.ts +0 -21
- package/src/core/experimental/compat.ts +0 -50
- package/src/core/experimental/setup-api.ts +0 -55
- package/src/core/graphql.test.ts +0 -11
- package/src/core/graphql.ts +0 -136
- package/src/core/passthrough.test.ts +0 -11
- package/src/core/passthrough.ts +0 -25
- package/src/core/sharedOptions.ts +0 -71
- package/src/core/typeUtils.ts +0 -26
- package/src/core/utils/handleRequest.test.ts +0 -574
- package/src/core/utils/handleRequest.ts +0 -117
- package/src/core/utils/internal/checkGlobals.ts +0 -17
- package/src/core/utils/internal/isHandlerKind.test.ts +0 -62
- package/src/core/utils/internal/isHandlerKind.ts +0 -17
- package/src/core/utils/internal/isIterable.ts +0 -32
- package/src/core/utils/internal/mergeRight.test.ts +0 -43
- package/src/core/utils/internal/mergeRight.ts +0 -30
- package/src/core/utils/internal/pipeEvents.test.ts +0 -14
- package/src/core/utils/internal/pipeEvents.ts +0 -26
- package/src/core/utils/internal/tryCatch.test.ts +0 -29
- package/src/core/utils/internal/tryCatch.ts +0 -11
- package/src/core/utils/matching/matchRequestUrl.test.ts +0 -267
- package/src/core/utils/matching/matchRequestUrl.ts +0 -77
- package/src/core/utils/request/getRequestCookies.ts +0 -88
- package/src/core/utils/request/onUnhandledRequest.node.test.ts +0 -62
- package/src/core/utils/request/onUnhandledRequest.test.ts +0 -226
- package/src/core/utils/request/onUnhandledRequest.ts +0 -81
- package/src/core/utils/request/storeResponseCookies.ts +0 -15
- package/src/core/utils/url/cleanUrl.test.ts +0 -22
- package/src/core/utils/url/cleanUrl.ts +0 -16
- package/src/core/utils/url/isAbsoluteUrl.test.ts +0 -32
- package/src/core/ws/handleWebSocketEvent.ts +0 -68
- package/src/core/ws/utils/getPublicData.ts +0 -18
- package/src/core/ws/webSocketInterceptor.ts +0 -3
- package/src/native/index.ts +0 -44
- package/src/package.json +0 -3
- package/src/shims/cookie.ts +0 -7
- package/src/shims/statuses.ts +0 -6
- /package/src/browser/utils/{getAbsoluteWorkerUrl.ts → get-absolute-worker-url.ts} +0 -0
- /package/src/core/utils/internal/{devUtils.ts → dev-utils.ts} +0 -0
- /package/src/core/utils/internal/{isObject.ts → is-object.ts} +0 -0
- /package/src/core/utils/internal/{isStringEqual.ts → is-string-equal.ts} +0 -0
- /package/src/core/utils/internal/{jsonParse.ts → json-parse.ts} +0 -0
- /package/src/core/utils/internal/{toReadonlyArray.ts → to-readonly-array.ts} +0 -0
- /package/src/core/utils/logging/{getStatusCodeColor.ts → get-status-code-color.ts} +0 -0
- /package/src/core/utils/logging/{getTimestamp.ts → get-timestamp.ts} +0 -0
- /package/src/core/utils/logging/{serializeRequest.ts → serialize-request.ts} +0 -0
- /package/src/core/utils/request/{getAllAcceptedMimeTypes.ts → get-all-accepted-mime-types.ts} +0 -0
- /package/src/core/utils/request/{toPublicUrl.ts → to-public-url.ts} +0 -0
- /package/src/core/utils/{toResponseInit.ts → to-response-init.ts} +0 -0
- /package/src/core/utils/url/{isAbsoluteUrl.ts → is-absolute-url.ts} +0 -0
- /package/src/{core → http}/http.test.ts +0 -0
- /package/src/{core/ws/utils/truncateMessage.ts → ws/utils/truncate-message.ts} +0 -0
package/lib/browser/index.js
CHANGED
|
@@ -1,3723 +1,584 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// src/browser/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
SetupWorkerApi: () => SetupWorkerApi,
|
|
24
|
-
setupWorker: () => setupWorker
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
|
-
// node_modules/.pnpm/outvariant@1.4.3/node_modules/outvariant/lib/index.mjs
|
|
29
|
-
var POSITIONALS_EXP = /(%?)(%([sdijo]))/g;
|
|
30
|
-
function serializePositional(positional, flag) {
|
|
31
|
-
switch (flag) {
|
|
32
|
-
case "s":
|
|
33
|
-
return positional;
|
|
34
|
-
case "d":
|
|
35
|
-
case "i":
|
|
36
|
-
return Number(positional);
|
|
37
|
-
case "j":
|
|
38
|
-
return JSON.stringify(positional);
|
|
39
|
-
case "o": {
|
|
40
|
-
if (typeof positional === "string") {
|
|
41
|
-
return positional;
|
|
42
|
-
}
|
|
43
|
-
const json = JSON.stringify(positional);
|
|
44
|
-
if (json === "{}" || json === "[]" || /^\[object .+?\]$/.test(json)) {
|
|
45
|
-
return positional;
|
|
46
|
-
}
|
|
47
|
-
return json;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function format(message, ...positionals) {
|
|
52
|
-
if (positionals.length === 0) {
|
|
53
|
-
return message;
|
|
54
|
-
}
|
|
55
|
-
let positionalIndex = 0;
|
|
56
|
-
let formattedMessage = message.replace(
|
|
57
|
-
POSITIONALS_EXP,
|
|
58
|
-
(match, isEscaped, _, flag) => {
|
|
59
|
-
const positional = positionals[positionalIndex];
|
|
60
|
-
const value = serializePositional(positional, flag);
|
|
61
|
-
if (!isEscaped) {
|
|
62
|
-
positionalIndex++;
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
return match;
|
|
66
|
-
}
|
|
67
|
-
);
|
|
68
|
-
if (positionalIndex < positionals.length) {
|
|
69
|
-
formattedMessage += ` ${positionals.slice(positionalIndex).join(" ")}`;
|
|
70
|
-
}
|
|
71
|
-
formattedMessage = formattedMessage.replace(/%{2,2}/g, "%");
|
|
72
|
-
return formattedMessage;
|
|
73
|
-
}
|
|
74
|
-
var STACK_FRAMES_TO_IGNORE = 2;
|
|
75
|
-
function cleanErrorStack(error2) {
|
|
76
|
-
if (!error2.stack) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const nextStack = error2.stack.split("\n");
|
|
80
|
-
nextStack.splice(1, STACK_FRAMES_TO_IGNORE);
|
|
81
|
-
error2.stack = nextStack.join("\n");
|
|
82
|
-
}
|
|
83
|
-
var InvariantError = class extends Error {
|
|
84
|
-
constructor(message, ...positionals) {
|
|
85
|
-
super(message);
|
|
86
|
-
this.message = message;
|
|
87
|
-
this.name = "Invariant Violation";
|
|
88
|
-
this.message = format(message, ...positionals);
|
|
89
|
-
cleanErrorStack(this);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
var invariant = (predicate, message, ...positionals) => {
|
|
93
|
-
if (!predicate) {
|
|
94
|
-
throw new InvariantError(message, ...positionals);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
invariant.as = (ErrorConstructor, predicate, message, ...positionals) => {
|
|
98
|
-
if (!predicate) {
|
|
99
|
-
const formatMessage = positionals.length === 0 ? message : format(message, ...positionals);
|
|
100
|
-
let error2;
|
|
101
|
-
try {
|
|
102
|
-
error2 = Reflect.construct(ErrorConstructor, [
|
|
103
|
-
formatMessage
|
|
104
|
-
]);
|
|
105
|
-
} catch (err) {
|
|
106
|
-
error2 = ErrorConstructor(formatMessage);
|
|
107
|
-
}
|
|
108
|
-
throw error2;
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
113
|
-
function isNodeProcess() {
|
|
114
|
-
if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
if (typeof process !== "undefined") {
|
|
118
|
-
const type = process.type;
|
|
119
|
-
if (type === "renderer" || type === "worker") {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
return !!(process.versions && process.versions.node);
|
|
123
|
-
}
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
|
|
128
|
-
var __defProp2 = Object.defineProperty;
|
|
129
|
-
var __export2 = (target, all) => {
|
|
130
|
-
for (var name in all)
|
|
131
|
-
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
132
|
-
};
|
|
133
|
-
var colors_exports = {};
|
|
134
|
-
__export2(colors_exports, {
|
|
135
|
-
blue: () => blue,
|
|
136
|
-
gray: () => gray,
|
|
137
|
-
green: () => green,
|
|
138
|
-
red: () => red,
|
|
139
|
-
yellow: () => yellow
|
|
140
|
-
});
|
|
141
|
-
function yellow(text) {
|
|
142
|
-
return `\x1B[33m${text}\x1B[0m`;
|
|
143
|
-
}
|
|
144
|
-
function blue(text) {
|
|
145
|
-
return `\x1B[34m${text}\x1B[0m`;
|
|
146
|
-
}
|
|
147
|
-
function gray(text) {
|
|
148
|
-
return `\x1B[90m${text}\x1B[0m`;
|
|
149
|
-
}
|
|
150
|
-
function red(text) {
|
|
151
|
-
return `\x1B[31m${text}\x1B[0m`;
|
|
152
|
-
}
|
|
153
|
-
function green(text) {
|
|
154
|
-
return `\x1B[32m${text}\x1B[0m`;
|
|
155
|
-
}
|
|
156
|
-
var IS_NODE = isNodeProcess();
|
|
157
|
-
var Logger = class {
|
|
158
|
-
constructor(name) {
|
|
159
|
-
this.name = name;
|
|
160
|
-
this.prefix = `[${this.name}]`;
|
|
161
|
-
const LOGGER_NAME = getVariable("DEBUG");
|
|
162
|
-
const LOGGER_LEVEL = getVariable("LOG_LEVEL");
|
|
163
|
-
const isLoggingEnabled = LOGGER_NAME === "1" || LOGGER_NAME === "true" || typeof LOGGER_NAME !== "undefined" && this.name.startsWith(LOGGER_NAME);
|
|
164
|
-
if (isLoggingEnabled) {
|
|
165
|
-
this.debug = isDefinedAndNotEquals(LOGGER_LEVEL, "debug") ? noop : this.debug;
|
|
166
|
-
this.info = isDefinedAndNotEquals(LOGGER_LEVEL, "info") ? noop : this.info;
|
|
167
|
-
this.success = isDefinedAndNotEquals(LOGGER_LEVEL, "success") ? noop : this.success;
|
|
168
|
-
this.warning = isDefinedAndNotEquals(LOGGER_LEVEL, "warning") ? noop : this.warning;
|
|
169
|
-
this.error = isDefinedAndNotEquals(LOGGER_LEVEL, "error") ? noop : this.error;
|
|
170
|
-
} else {
|
|
171
|
-
this.info = noop;
|
|
172
|
-
this.success = noop;
|
|
173
|
-
this.warning = noop;
|
|
174
|
-
this.error = noop;
|
|
175
|
-
this.only = noop;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
prefix;
|
|
179
|
-
extend(domain) {
|
|
180
|
-
return new Logger(`${this.name}:${domain}`);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Print a debug message.
|
|
184
|
-
* @example
|
|
185
|
-
* logger.debug('no duplicates found, creating a document...')
|
|
186
|
-
*/
|
|
187
|
-
debug(message, ...positionals) {
|
|
188
|
-
this.logEntry({
|
|
189
|
-
level: "debug",
|
|
190
|
-
message: gray(message),
|
|
191
|
-
positionals,
|
|
192
|
-
prefix: this.prefix,
|
|
193
|
-
colors: {
|
|
194
|
-
prefix: "gray"
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Print an info message.
|
|
200
|
-
* @example
|
|
201
|
-
* logger.info('start parsing...')
|
|
202
|
-
*/
|
|
203
|
-
info(message, ...positionals) {
|
|
204
|
-
this.logEntry({
|
|
205
|
-
level: "info",
|
|
206
|
-
message,
|
|
207
|
-
positionals,
|
|
208
|
-
prefix: this.prefix,
|
|
209
|
-
colors: {
|
|
210
|
-
prefix: "blue"
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
const performance2 = new PerformanceEntry();
|
|
214
|
-
return (message2, ...positionals2) => {
|
|
215
|
-
performance2.measure();
|
|
216
|
-
this.logEntry({
|
|
217
|
-
level: "info",
|
|
218
|
-
message: `${message2} ${gray(`${performance2.deltaTime}ms`)}`,
|
|
219
|
-
positionals: positionals2,
|
|
220
|
-
prefix: this.prefix,
|
|
221
|
-
colors: {
|
|
222
|
-
prefix: "blue"
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Print a success message.
|
|
229
|
-
* @example
|
|
230
|
-
* logger.success('successfully created document')
|
|
231
|
-
*/
|
|
232
|
-
success(message, ...positionals) {
|
|
233
|
-
this.logEntry({
|
|
234
|
-
level: "info",
|
|
235
|
-
message,
|
|
236
|
-
positionals,
|
|
237
|
-
prefix: `\u2714 ${this.prefix}`,
|
|
238
|
-
colors: {
|
|
239
|
-
timestamp: "green",
|
|
240
|
-
prefix: "green"
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Print a warning.
|
|
246
|
-
* @example
|
|
247
|
-
* logger.warning('found legacy document format')
|
|
248
|
-
*/
|
|
249
|
-
warning(message, ...positionals) {
|
|
250
|
-
this.logEntry({
|
|
251
|
-
level: "warning",
|
|
252
|
-
message,
|
|
253
|
-
positionals,
|
|
254
|
-
prefix: `\u26A0 ${this.prefix}`,
|
|
255
|
-
colors: {
|
|
256
|
-
timestamp: "yellow",
|
|
257
|
-
prefix: "yellow"
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Print an error message.
|
|
263
|
-
* @example
|
|
264
|
-
* logger.error('something went wrong')
|
|
265
|
-
*/
|
|
266
|
-
error(message, ...positionals) {
|
|
267
|
-
this.logEntry({
|
|
268
|
-
level: "error",
|
|
269
|
-
message,
|
|
270
|
-
positionals,
|
|
271
|
-
prefix: `\u2716 ${this.prefix}`,
|
|
272
|
-
colors: {
|
|
273
|
-
timestamp: "red",
|
|
274
|
-
prefix: "red"
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Execute the given callback only when the logging is enabled.
|
|
280
|
-
* This is skipped in its entirety and has no runtime cost otherwise.
|
|
281
|
-
* This executes regardless of the log level.
|
|
282
|
-
* @example
|
|
283
|
-
* logger.only(() => {
|
|
284
|
-
* logger.info('additional info')
|
|
285
|
-
* })
|
|
286
|
-
*/
|
|
287
|
-
only(callback) {
|
|
288
|
-
callback();
|
|
289
|
-
}
|
|
290
|
-
createEntry(level, message) {
|
|
291
|
-
return {
|
|
292
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
293
|
-
level,
|
|
294
|
-
message
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
logEntry(args) {
|
|
298
|
-
const {
|
|
299
|
-
level,
|
|
300
|
-
message,
|
|
301
|
-
prefix,
|
|
302
|
-
colors: customColors,
|
|
303
|
-
positionals = []
|
|
304
|
-
} = args;
|
|
305
|
-
const entry = this.createEntry(level, message);
|
|
306
|
-
const timestampColor = customColors?.timestamp || "gray";
|
|
307
|
-
const prefixColor = customColors?.prefix || "gray";
|
|
308
|
-
const colorize = {
|
|
309
|
-
timestamp: colors_exports[timestampColor],
|
|
310
|
-
prefix: colors_exports[prefixColor]
|
|
311
|
-
};
|
|
312
|
-
const write = this.getWriter(level);
|
|
313
|
-
write(
|
|
314
|
-
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "),
|
|
315
|
-
...positionals.map(serializeInput)
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
formatTimestamp(timestamp) {
|
|
319
|
-
return `${timestamp.toLocaleTimeString(
|
|
320
|
-
"en-GB"
|
|
321
|
-
)}:${timestamp.getMilliseconds()}`;
|
|
322
|
-
}
|
|
323
|
-
getWriter(level) {
|
|
324
|
-
switch (level) {
|
|
325
|
-
case "debug":
|
|
326
|
-
case "success":
|
|
327
|
-
case "info": {
|
|
328
|
-
return log;
|
|
329
|
-
}
|
|
330
|
-
case "warning": {
|
|
331
|
-
return warn;
|
|
332
|
-
}
|
|
333
|
-
case "error": {
|
|
334
|
-
return error;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
var PerformanceEntry = class {
|
|
340
|
-
startTime;
|
|
341
|
-
endTime;
|
|
342
|
-
deltaTime;
|
|
343
|
-
constructor() {
|
|
344
|
-
this.startTime = performance.now();
|
|
345
|
-
}
|
|
346
|
-
measure() {
|
|
347
|
-
this.endTime = performance.now();
|
|
348
|
-
const deltaTime = this.endTime - this.startTime;
|
|
349
|
-
this.deltaTime = deltaTime.toFixed(2);
|
|
350
|
-
}
|
|
351
|
-
};
|
|
352
|
-
var noop = () => void 0;
|
|
353
|
-
function log(message, ...positionals) {
|
|
354
|
-
if (IS_NODE) {
|
|
355
|
-
process.stdout.write(format(message, ...positionals) + "\n");
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
console.log(message, ...positionals);
|
|
359
|
-
}
|
|
360
|
-
function warn(message, ...positionals) {
|
|
361
|
-
if (IS_NODE) {
|
|
362
|
-
process.stderr.write(format(message, ...positionals) + "\n");
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
console.warn(message, ...positionals);
|
|
366
|
-
}
|
|
367
|
-
function error(message, ...positionals) {
|
|
368
|
-
if (IS_NODE) {
|
|
369
|
-
process.stderr.write(format(message, ...positionals) + "\n");
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
console.error(message, ...positionals);
|
|
373
|
-
}
|
|
374
|
-
function getVariable(variableName) {
|
|
375
|
-
if (IS_NODE) {
|
|
376
|
-
return process.env[variableName];
|
|
377
|
-
}
|
|
378
|
-
return globalThis[variableName]?.toString();
|
|
379
|
-
}
|
|
380
|
-
function isDefinedAndNotEquals(value, expected) {
|
|
381
|
-
return value !== void 0 && value !== expected;
|
|
382
|
-
}
|
|
383
|
-
function serializeInput(message) {
|
|
384
|
-
if (typeof message === "undefined") {
|
|
385
|
-
return "undefined";
|
|
386
|
-
}
|
|
387
|
-
if (message === null) {
|
|
388
|
-
return "null";
|
|
389
|
-
}
|
|
390
|
-
if (typeof message === "string") {
|
|
391
|
-
return message;
|
|
392
|
-
}
|
|
393
|
-
if (typeof message === "object") {
|
|
394
|
-
return JSON.stringify(message);
|
|
395
|
-
}
|
|
396
|
-
return message.toString();
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// node_modules/.pnpm/strict-event-emitter@0.5.1/node_modules/strict-event-emitter/lib/index.mjs
|
|
400
|
-
var MemoryLeakError = class extends Error {
|
|
401
|
-
constructor(emitter, type, count) {
|
|
402
|
-
super(
|
|
403
|
-
`Possible EventEmitter memory leak detected. ${count} ${type.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`
|
|
404
|
-
);
|
|
405
|
-
this.emitter = emitter;
|
|
406
|
-
this.type = type;
|
|
407
|
-
this.count = count;
|
|
408
|
-
this.name = "MaxListenersExceededWarning";
|
|
409
|
-
}
|
|
410
|
-
};
|
|
411
|
-
var _Emitter = class {
|
|
412
|
-
static listenerCount(emitter, eventName) {
|
|
413
|
-
return emitter.listenerCount(eventName);
|
|
414
|
-
}
|
|
415
|
-
constructor() {
|
|
416
|
-
this.events = /* @__PURE__ */ new Map();
|
|
417
|
-
this.maxListeners = _Emitter.defaultMaxListeners;
|
|
418
|
-
this.hasWarnedAboutPotentialMemoryLeak = false;
|
|
419
|
-
}
|
|
420
|
-
_emitInternalEvent(internalEventName, eventName, listener) {
|
|
421
|
-
this.emit(
|
|
422
|
-
internalEventName,
|
|
423
|
-
...[eventName, listener]
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
_getListeners(eventName) {
|
|
427
|
-
return Array.prototype.concat.apply([], this.events.get(eventName)) || [];
|
|
428
|
-
}
|
|
429
|
-
_removeListener(listeners, listener) {
|
|
430
|
-
const index = listeners.indexOf(listener);
|
|
431
|
-
if (index > -1) {
|
|
432
|
-
listeners.splice(index, 1);
|
|
433
|
-
}
|
|
434
|
-
return [];
|
|
435
|
-
}
|
|
436
|
-
_wrapOnceListener(eventName, listener) {
|
|
437
|
-
const onceListener = (...data) => {
|
|
438
|
-
this.removeListener(eventName, onceListener);
|
|
439
|
-
return listener.apply(this, data);
|
|
440
|
-
};
|
|
441
|
-
Object.defineProperty(onceListener, "name", { value: listener.name });
|
|
442
|
-
return onceListener;
|
|
443
|
-
}
|
|
444
|
-
setMaxListeners(maxListeners) {
|
|
445
|
-
this.maxListeners = maxListeners;
|
|
446
|
-
return this;
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Returns the current max listener value for the `Emitter` which is
|
|
450
|
-
* either set by `emitter.setMaxListeners(n)` or defaults to
|
|
451
|
-
* `Emitter.defaultMaxListeners`.
|
|
452
|
-
*/
|
|
453
|
-
getMaxListeners() {
|
|
454
|
-
return this.maxListeners;
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Returns an array listing the events for which the emitter has registered listeners.
|
|
458
|
-
* The values in the array will be strings or Symbols.
|
|
459
|
-
*/
|
|
460
|
-
eventNames() {
|
|
461
|
-
return Array.from(this.events.keys());
|
|
462
|
-
}
|
|
463
|
-
/**
|
|
464
|
-
* Synchronously calls each of the listeners registered for the event named `eventName`,
|
|
465
|
-
* in the order they were registered, passing the supplied arguments to each.
|
|
466
|
-
* Returns `true` if the event has listeners, `false` otherwise.
|
|
467
|
-
*
|
|
468
|
-
* @example
|
|
469
|
-
* const emitter = new Emitter<{ hello: [string] }>()
|
|
470
|
-
* emitter.emit('hello', 'John')
|
|
471
|
-
*/
|
|
472
|
-
emit(eventName, ...data) {
|
|
473
|
-
const listeners = this._getListeners(eventName);
|
|
474
|
-
listeners.forEach((listener) => {
|
|
475
|
-
listener.apply(this, data);
|
|
476
|
-
});
|
|
477
|
-
return listeners.length > 0;
|
|
478
|
-
}
|
|
479
|
-
addListener(eventName, listener) {
|
|
480
|
-
this._emitInternalEvent("newListener", eventName, listener);
|
|
481
|
-
const nextListeners = this._getListeners(eventName).concat(listener);
|
|
482
|
-
this.events.set(eventName, nextListeners);
|
|
483
|
-
if (this.maxListeners > 0 && this.listenerCount(eventName) > this.maxListeners && !this.hasWarnedAboutPotentialMemoryLeak) {
|
|
484
|
-
this.hasWarnedAboutPotentialMemoryLeak = true;
|
|
485
|
-
const memoryLeakWarning = new MemoryLeakError(
|
|
486
|
-
this,
|
|
487
|
-
eventName,
|
|
488
|
-
this.listenerCount(eventName)
|
|
489
|
-
);
|
|
490
|
-
console.warn(memoryLeakWarning);
|
|
491
|
-
}
|
|
492
|
-
return this;
|
|
493
|
-
}
|
|
494
|
-
on(eventName, listener) {
|
|
495
|
-
return this.addListener(eventName, listener);
|
|
496
|
-
}
|
|
497
|
-
once(eventName, listener) {
|
|
498
|
-
return this.addListener(
|
|
499
|
-
eventName,
|
|
500
|
-
this._wrapOnceListener(eventName, listener)
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
prependListener(eventName, listener) {
|
|
504
|
-
const listeners = this._getListeners(eventName);
|
|
505
|
-
if (listeners.length > 0) {
|
|
506
|
-
const nextListeners = [listener].concat(listeners);
|
|
507
|
-
this.events.set(eventName, nextListeners);
|
|
508
|
-
} else {
|
|
509
|
-
this.events.set(eventName, listeners.concat(listener));
|
|
510
|
-
}
|
|
511
|
-
return this;
|
|
512
|
-
}
|
|
513
|
-
prependOnceListener(eventName, listener) {
|
|
514
|
-
return this.prependListener(
|
|
515
|
-
eventName,
|
|
516
|
-
this._wrapOnceListener(eventName, listener)
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
removeListener(eventName, listener) {
|
|
520
|
-
const listeners = this._getListeners(eventName);
|
|
521
|
-
if (listeners.length > 0) {
|
|
522
|
-
this._removeListener(listeners, listener);
|
|
523
|
-
this.events.set(eventName, listeners);
|
|
524
|
-
this._emitInternalEvent("removeListener", eventName, listener);
|
|
525
|
-
}
|
|
526
|
-
return this;
|
|
527
|
-
}
|
|
528
|
-
/**
|
|
529
|
-
* Alias for `emitter.removeListener()`.
|
|
530
|
-
*
|
|
531
|
-
* @example
|
|
532
|
-
* emitter.off('hello', listener)
|
|
533
|
-
*/
|
|
534
|
-
off(eventName, listener) {
|
|
535
|
-
return this.removeListener(eventName, listener);
|
|
536
|
-
}
|
|
537
|
-
removeAllListeners(eventName) {
|
|
538
|
-
if (eventName) {
|
|
539
|
-
this.events.delete(eventName);
|
|
540
|
-
} else {
|
|
541
|
-
this.events.clear();
|
|
542
|
-
}
|
|
543
|
-
return this;
|
|
544
|
-
}
|
|
545
|
-
/**
|
|
546
|
-
* Returns a copy of the array of listeners for the event named `eventName`.
|
|
547
|
-
*/
|
|
548
|
-
listeners(eventName) {
|
|
549
|
-
return Array.from(this._getListeners(eventName));
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* Returns the number of listeners listening to the event named `eventName`.
|
|
553
|
-
*/
|
|
554
|
-
listenerCount(eventName) {
|
|
555
|
-
return this._getListeners(eventName).length;
|
|
556
|
-
}
|
|
557
|
-
rawListeners(eventName) {
|
|
558
|
-
return this.listeners(eventName);
|
|
559
|
-
}
|
|
560
|
-
};
|
|
561
|
-
var Emitter = _Emitter;
|
|
562
|
-
Emitter.defaultMaxListeners = 10;
|
|
563
|
-
|
|
564
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DYCsFHOi.mjs
|
|
565
|
-
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
566
|
-
function getGlobalSymbol(symbol) {
|
|
567
|
-
return globalThis[symbol] || void 0;
|
|
568
|
-
}
|
|
569
|
-
function setGlobalSymbol(symbol, value) {
|
|
570
|
-
globalThis[symbol] = value;
|
|
571
|
-
}
|
|
572
|
-
function deleteGlobalSymbol(symbol) {
|
|
573
|
-
delete globalThis[symbol];
|
|
574
|
-
}
|
|
575
|
-
var InterceptorReadyState = /* @__PURE__ */ (function(InterceptorReadyState$1) {
|
|
576
|
-
InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
|
|
577
|
-
InterceptorReadyState$1["APPLYING"] = "APPLYING";
|
|
578
|
-
InterceptorReadyState$1["APPLIED"] = "APPLIED";
|
|
579
|
-
InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
|
|
580
|
-
InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
|
|
581
|
-
return InterceptorReadyState$1;
|
|
582
|
-
})({});
|
|
583
|
-
var Interceptor = class {
|
|
584
|
-
constructor(symbol) {
|
|
585
|
-
this.symbol = symbol;
|
|
586
|
-
this.readyState = InterceptorReadyState.INACTIVE;
|
|
587
|
-
this.emitter = new Emitter();
|
|
588
|
-
this.subscriptions = [];
|
|
589
|
-
this.logger = new Logger(symbol.description);
|
|
590
|
-
this.emitter.setMaxListeners(0);
|
|
591
|
-
this.logger.info("constructing the interceptor...");
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* Determine if this interceptor can be applied
|
|
595
|
-
* in the current environment.
|
|
596
|
-
*/
|
|
597
|
-
checkEnvironment() {
|
|
598
|
-
return true;
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* Apply this interceptor to the current process.
|
|
602
|
-
* Returns an already running interceptor instance if it's present.
|
|
603
|
-
*/
|
|
604
|
-
apply() {
|
|
605
|
-
const logger = this.logger.extend("apply");
|
|
606
|
-
logger.info("applying the interceptor...");
|
|
607
|
-
if (this.readyState === InterceptorReadyState.APPLIED) {
|
|
608
|
-
logger.info("intercepted already applied!");
|
|
609
|
-
return;
|
|
610
|
-
}
|
|
611
|
-
if (!this.checkEnvironment()) {
|
|
612
|
-
logger.info("the interceptor cannot be applied in this environment!");
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
this.readyState = InterceptorReadyState.APPLYING;
|
|
616
|
-
const runningInstance = this.getInstance();
|
|
617
|
-
if (runningInstance) {
|
|
618
|
-
logger.info("found a running instance, reusing...");
|
|
619
|
-
this.on = (event, listener) => {
|
|
620
|
-
logger.info('proxying the "%s" listener', event);
|
|
621
|
-
runningInstance.emitter.addListener(event, listener);
|
|
622
|
-
this.subscriptions.push(() => {
|
|
623
|
-
runningInstance.emitter.removeListener(event, listener);
|
|
624
|
-
logger.info('removed proxied "%s" listener!', event);
|
|
625
|
-
});
|
|
626
|
-
return this;
|
|
627
|
-
};
|
|
628
|
-
this.readyState = InterceptorReadyState.APPLIED;
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
logger.info("no running instance found, setting up a new instance...");
|
|
632
|
-
this.setup();
|
|
633
|
-
this.setInstance();
|
|
634
|
-
this.readyState = InterceptorReadyState.APPLIED;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Setup the module augments and stubs necessary for this interceptor.
|
|
638
|
-
* This method is not run if there's a running interceptor instance
|
|
639
|
-
* to prevent instantiating an interceptor multiple times.
|
|
640
|
-
*/
|
|
641
|
-
setup() {
|
|
642
|
-
}
|
|
643
|
-
/**
|
|
644
|
-
* Listen to the interceptor's public events.
|
|
645
|
-
*/
|
|
646
|
-
on(event, listener) {
|
|
647
|
-
const logger = this.logger.extend("on");
|
|
648
|
-
if (this.readyState === InterceptorReadyState.DISPOSING || this.readyState === InterceptorReadyState.DISPOSED) {
|
|
649
|
-
logger.info("cannot listen to events, already disposed!");
|
|
650
|
-
return this;
|
|
651
|
-
}
|
|
652
|
-
logger.info('adding "%s" event listener:', event, listener);
|
|
653
|
-
this.emitter.on(event, listener);
|
|
654
|
-
return this;
|
|
655
|
-
}
|
|
656
|
-
once(event, listener) {
|
|
657
|
-
this.emitter.once(event, listener);
|
|
658
|
-
return this;
|
|
659
|
-
}
|
|
660
|
-
off(event, listener) {
|
|
661
|
-
this.emitter.off(event, listener);
|
|
662
|
-
return this;
|
|
663
|
-
}
|
|
664
|
-
removeAllListeners(event) {
|
|
665
|
-
this.emitter.removeAllListeners(event);
|
|
666
|
-
return this;
|
|
667
|
-
}
|
|
668
|
-
/**
|
|
669
|
-
* Disposes of any side-effects this interceptor has introduced.
|
|
670
|
-
*/
|
|
671
|
-
dispose() {
|
|
672
|
-
const logger = this.logger.extend("dispose");
|
|
673
|
-
if (this.readyState === InterceptorReadyState.DISPOSED) {
|
|
674
|
-
logger.info("cannot dispose, already disposed!");
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
logger.info("disposing the interceptor...");
|
|
678
|
-
this.readyState = InterceptorReadyState.DISPOSING;
|
|
679
|
-
if (!this.getInstance()) {
|
|
680
|
-
logger.info("no interceptors running, skipping dispose...");
|
|
681
|
-
return;
|
|
682
|
-
}
|
|
683
|
-
this.clearInstance();
|
|
684
|
-
logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
|
|
685
|
-
if (this.subscriptions.length > 0) {
|
|
686
|
-
logger.info("disposing of %d subscriptions...", this.subscriptions.length);
|
|
687
|
-
for (const dispose of this.subscriptions) dispose();
|
|
688
|
-
this.subscriptions = [];
|
|
689
|
-
logger.info("disposed of all subscriptions!", this.subscriptions.length);
|
|
690
|
-
}
|
|
691
|
-
this.emitter.removeAllListeners();
|
|
692
|
-
logger.info("destroyed the listener!");
|
|
693
|
-
this.readyState = InterceptorReadyState.DISPOSED;
|
|
694
|
-
}
|
|
695
|
-
getInstance() {
|
|
696
|
-
const instance = getGlobalSymbol(this.symbol);
|
|
697
|
-
this.logger.info("retrieved global instance:", instance?.constructor?.name);
|
|
698
|
-
return instance;
|
|
699
|
-
}
|
|
700
|
-
setInstance() {
|
|
701
|
-
setGlobalSymbol(this.symbol, this);
|
|
702
|
-
this.logger.info("set global instance!", this.symbol.description);
|
|
703
|
-
}
|
|
704
|
-
clearInstance() {
|
|
705
|
-
deleteGlobalSymbol(this.symbol);
|
|
706
|
-
this.logger.info("cleared global instance!", this.symbol.description);
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
function createRequestId() {
|
|
710
|
-
return Math.random().toString(16).slice(2);
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/resolveWebSocketUrl-C83-x9iE.mjs
|
|
714
|
-
function resolveWebSocketUrl(url) {
|
|
715
|
-
if (typeof url === "string") return resolveWebSocketUrl(new URL(url, typeof location !== "undefined" ? location.href : void 0));
|
|
716
|
-
if (url.protocol === "http:") url.protocol = "ws:";
|
|
717
|
-
else if (url.protocol === "https:") url.protocol = "wss:";
|
|
718
|
-
if (url.protocol !== "ws:" && url.protocol !== "wss:")
|
|
719
|
-
throw new SyntaxError(`Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`);
|
|
720
|
-
if (url.hash !== "") throw new SyntaxError(`Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`);
|
|
721
|
-
return url.href;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-C8zq1MCg.mjs
|
|
725
|
-
async function emitAsync(emitter, eventName, ...data) {
|
|
726
|
-
const listeners = emitter.listeners(eventName);
|
|
727
|
-
if (listeners.length === 0) return;
|
|
728
|
-
for (const listener of listeners) await listener.apply(emitter, data);
|
|
729
|
-
}
|
|
730
|
-
var PatchesRegistry = class {
|
|
731
|
-
#replacements = /* @__PURE__ */ new Map();
|
|
732
|
-
applyPatch(owner, key, getNextValue) {
|
|
733
|
-
const ownerReplacements = this.#replacements.get(owner);
|
|
734
|
-
invariant(!ownerReplacements?.has(key), `Failed to replace a global value at "${String(key)}": already replaced.`);
|
|
735
|
-
const match = getDeepPropertyDescriptor(owner, key);
|
|
736
|
-
if (typeof match === "undefined") {
|
|
737
|
-
console.warn(`Failed to replace a global value at "${String(key)}": not a global value.`);
|
|
738
|
-
return () => {
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
if (match.descriptor.configurable) Object.defineProperty(owner, key, {
|
|
742
|
-
value: getNextValue(owner[key]),
|
|
743
|
-
enumerable: true,
|
|
744
|
-
configurable: true
|
|
745
|
-
});
|
|
746
|
-
else if (match.descriptor.writable) owner[key] = getNextValue(owner[key]);
|
|
747
|
-
else throw new Error(`Failed to patch a non-configurable non-writable property "${key.toString()}"`);
|
|
748
|
-
const restorePatch = () => {
|
|
749
|
-
const currentReplacements = this.#replacements.get(owner);
|
|
750
|
-
if (!currentReplacements?.has(key)) return;
|
|
751
|
-
if (match.owner === owner)
|
|
752
|
-
Object.defineProperty(match.owner, key, match.descriptor);
|
|
753
|
-
else
|
|
754
|
-
Reflect.deleteProperty(owner, key);
|
|
755
|
-
currentReplacements.delete(key);
|
|
756
|
-
if (currentReplacements.size === 0) this.#replacements.delete(owner);
|
|
757
|
-
};
|
|
758
|
-
if (ownerReplacements) ownerReplacements.set(key, restorePatch);
|
|
759
|
-
else this.#replacements.set(owner, /* @__PURE__ */ new Map([[key, restorePatch]]));
|
|
760
|
-
return restorePatch;
|
|
761
|
-
}
|
|
762
|
-
restoreAllPatches() {
|
|
763
|
-
const errors = [];
|
|
764
|
-
for (const [, ownerReplacements] of this.#replacements) for (const [, restorePatch] of ownerReplacements) try {
|
|
765
|
-
restorePatch();
|
|
766
|
-
} catch (error2) {
|
|
767
|
-
if (error2 instanceof Error) errors.push(error2);
|
|
768
|
-
else throw error2;
|
|
769
|
-
}
|
|
770
|
-
if (errors.length > 0) throw new AggregateError(errors, "FOO!");
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
var patchesRegistry = new PatchesRegistry();
|
|
774
|
-
function getDeepPropertyDescriptor(owner, key) {
|
|
775
|
-
let currentOwner = owner;
|
|
776
|
-
let descriptor;
|
|
777
|
-
while (currentOwner) {
|
|
778
|
-
descriptor = Object.getOwnPropertyDescriptor(currentOwner, key);
|
|
779
|
-
if (descriptor) return {
|
|
780
|
-
owner: currentOwner,
|
|
781
|
-
descriptor
|
|
782
|
-
};
|
|
783
|
-
currentOwner = Object.getPrototypeOf(currentOwner);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
function hasConfigurableGlobal(propertyName) {
|
|
787
|
-
const match = getDeepPropertyDescriptor(globalThis, propertyName);
|
|
788
|
-
if (typeof match === "undefined") return false;
|
|
789
|
-
const { descriptor } = match;
|
|
790
|
-
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
791
|
-
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
792
|
-
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
793
|
-
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.`);
|
|
794
|
-
return false;
|
|
795
|
-
}
|
|
796
|
-
return true;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// node_modules/.pnpm/@open-draft+deferred-promise@2.2.0/node_modules/@open-draft/deferred-promise/build/index.mjs
|
|
800
|
-
function createDeferredExecutor() {
|
|
801
|
-
const executor = (resolve, reject) => {
|
|
802
|
-
executor.state = "pending";
|
|
803
|
-
executor.resolve = (data) => {
|
|
804
|
-
if (executor.state !== "pending") {
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
executor.result = data;
|
|
808
|
-
const onFulfilled = (value) => {
|
|
809
|
-
executor.state = "fulfilled";
|
|
810
|
-
return value;
|
|
811
|
-
};
|
|
812
|
-
return resolve(
|
|
813
|
-
data instanceof Promise ? data : Promise.resolve(data).then(onFulfilled)
|
|
814
|
-
);
|
|
815
|
-
};
|
|
816
|
-
executor.reject = (reason) => {
|
|
817
|
-
if (executor.state !== "pending") {
|
|
818
|
-
return;
|
|
819
|
-
}
|
|
820
|
-
queueMicrotask(() => {
|
|
821
|
-
executor.state = "rejected";
|
|
822
|
-
});
|
|
823
|
-
return reject(executor.rejectionReason = reason);
|
|
824
|
-
};
|
|
825
|
-
};
|
|
826
|
-
return executor;
|
|
827
|
-
}
|
|
828
|
-
var DeferredPromise = class extends Promise {
|
|
829
|
-
#executor;
|
|
830
|
-
resolve;
|
|
831
|
-
reject;
|
|
832
|
-
constructor(executor = null) {
|
|
833
|
-
const deferredExecutor = createDeferredExecutor();
|
|
834
|
-
super((originalResolve, originalReject) => {
|
|
835
|
-
deferredExecutor(originalResolve, originalReject);
|
|
836
|
-
executor?.(deferredExecutor.resolve, deferredExecutor.reject);
|
|
837
|
-
});
|
|
838
|
-
this.#executor = deferredExecutor;
|
|
839
|
-
this.resolve = this.#executor.resolve;
|
|
840
|
-
this.reject = this.#executor.reject;
|
|
841
|
-
}
|
|
842
|
-
get state() {
|
|
843
|
-
return this.#executor.state;
|
|
844
|
-
}
|
|
845
|
-
get rejectionReason() {
|
|
846
|
-
return this.#executor.rejectionReason;
|
|
847
|
-
}
|
|
848
|
-
then(onFulfilled, onRejected) {
|
|
849
|
-
return this.#decorate(super.then(onFulfilled, onRejected));
|
|
850
|
-
}
|
|
851
|
-
catch(onRejected) {
|
|
852
|
-
return this.#decorate(super.catch(onRejected));
|
|
853
|
-
}
|
|
854
|
-
finally(onfinally) {
|
|
855
|
-
return this.#decorate(super.finally(onfinally));
|
|
856
|
-
}
|
|
857
|
-
#decorate(promise) {
|
|
858
|
-
return Object.defineProperties(promise, {
|
|
859
|
-
resolve: { configurable: true, value: this.resolve },
|
|
860
|
-
reject: { configurable: true, value: this.reject }
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
};
|
|
864
|
-
|
|
865
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
866
|
-
function bindEvent(target, event) {
|
|
867
|
-
Object.defineProperties(event, {
|
|
868
|
-
target: {
|
|
869
|
-
value: target,
|
|
870
|
-
enumerable: true,
|
|
871
|
-
writable: true
|
|
872
|
-
},
|
|
873
|
-
currentTarget: {
|
|
874
|
-
value: target,
|
|
875
|
-
enumerable: true,
|
|
876
|
-
writable: true
|
|
877
|
-
}
|
|
878
|
-
});
|
|
879
|
-
return event;
|
|
880
|
-
}
|
|
881
|
-
var kCancelable = /* @__PURE__ */ Symbol("kCancelable");
|
|
882
|
-
var kDefaultPrevented = /* @__PURE__ */ Symbol("kDefaultPrevented");
|
|
883
|
-
var CancelableMessageEvent = class extends MessageEvent {
|
|
884
|
-
constructor(type, init) {
|
|
885
|
-
super(type, init);
|
|
886
|
-
this[kCancelable] = !!init.cancelable;
|
|
887
|
-
this[kDefaultPrevented] = false;
|
|
888
|
-
}
|
|
889
|
-
get cancelable() {
|
|
890
|
-
return this[kCancelable];
|
|
891
|
-
}
|
|
892
|
-
set cancelable(nextCancelable) {
|
|
893
|
-
this[kCancelable] = nextCancelable;
|
|
894
|
-
}
|
|
895
|
-
get defaultPrevented() {
|
|
896
|
-
return this[kDefaultPrevented];
|
|
897
|
-
}
|
|
898
|
-
set defaultPrevented(nextDefaultPrevented) {
|
|
899
|
-
this[kDefaultPrevented] = nextDefaultPrevented;
|
|
900
|
-
}
|
|
901
|
-
preventDefault() {
|
|
902
|
-
if (this.cancelable && !this[kDefaultPrevented]) this[kDefaultPrevented] = true;
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
var CloseEvent = class extends Event {
|
|
906
|
-
constructor(type, init = {}) {
|
|
907
|
-
super(type, init);
|
|
908
|
-
this.code = init.code === void 0 ? 0 : init.code;
|
|
909
|
-
this.reason = init.reason === void 0 ? "" : init.reason;
|
|
910
|
-
this.wasClean = init.wasClean === void 0 ? false : init.wasClean;
|
|
911
|
-
}
|
|
912
|
-
};
|
|
913
|
-
var CancelableCloseEvent = class extends CloseEvent {
|
|
914
|
-
constructor(type, init = {}) {
|
|
915
|
-
super(type, init);
|
|
916
|
-
this[kCancelable] = !!init.cancelable;
|
|
917
|
-
this[kDefaultPrevented] = false;
|
|
918
|
-
}
|
|
919
|
-
get cancelable() {
|
|
920
|
-
return this[kCancelable];
|
|
921
|
-
}
|
|
922
|
-
set cancelable(nextCancelable) {
|
|
923
|
-
this[kCancelable] = nextCancelable;
|
|
924
|
-
}
|
|
925
|
-
get defaultPrevented() {
|
|
926
|
-
return this[kDefaultPrevented];
|
|
927
|
-
}
|
|
928
|
-
set defaultPrevented(nextDefaultPrevented) {
|
|
929
|
-
this[kDefaultPrevented] = nextDefaultPrevented;
|
|
930
|
-
}
|
|
931
|
-
preventDefault() {
|
|
932
|
-
if (this.cancelable && !this[kDefaultPrevented]) this[kDefaultPrevented] = true;
|
|
933
|
-
}
|
|
934
|
-
};
|
|
935
|
-
var kEmitter$1 = /* @__PURE__ */ Symbol("kEmitter");
|
|
936
|
-
var kBoundListener$1 = /* @__PURE__ */ Symbol("kBoundListener");
|
|
937
|
-
var WebSocketClientConnection = class {
|
|
938
|
-
constructor(socket, transport) {
|
|
939
|
-
this.socket = socket;
|
|
940
|
-
this.transport = transport;
|
|
941
|
-
this.id = createRequestId();
|
|
942
|
-
this.url = new URL(socket.url);
|
|
943
|
-
this[kEmitter$1] = new EventTarget();
|
|
944
|
-
this.transport.addEventListener("outgoing", (event) => {
|
|
945
|
-
const message = bindEvent(this.socket, new CancelableMessageEvent("message", {
|
|
946
|
-
data: event.data,
|
|
947
|
-
origin: event.origin,
|
|
948
|
-
cancelable: true
|
|
949
|
-
}));
|
|
950
|
-
this[kEmitter$1].dispatchEvent(message);
|
|
951
|
-
if (message.defaultPrevented) event.preventDefault();
|
|
952
|
-
});
|
|
953
|
-
this.transport.addEventListener("close", (event) => {
|
|
954
|
-
this[kEmitter$1].dispatchEvent(bindEvent(this.socket, new CloseEvent("close", event)));
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* Listen for the outgoing events from the connected WebSocket client.
|
|
959
|
-
*/
|
|
960
|
-
addEventListener(type, listener, options) {
|
|
961
|
-
if (!Reflect.has(listener, kBoundListener$1)) {
|
|
962
|
-
const boundListener = listener.bind(this.socket);
|
|
963
|
-
Object.defineProperty(listener, kBoundListener$1, {
|
|
964
|
-
value: boundListener,
|
|
965
|
-
enumerable: false,
|
|
966
|
-
configurable: false
|
|
967
|
-
});
|
|
968
|
-
}
|
|
969
|
-
this[kEmitter$1].addEventListener(type, Reflect.get(listener, kBoundListener$1), options);
|
|
970
|
-
}
|
|
971
|
-
/**
|
|
972
|
-
* Removes the listener for the given event.
|
|
973
|
-
*/
|
|
974
|
-
removeEventListener(event, listener, options) {
|
|
975
|
-
this[kEmitter$1].removeEventListener(event, Reflect.get(listener, kBoundListener$1), options);
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* Send data to the connected client.
|
|
979
|
-
*/
|
|
980
|
-
send(data) {
|
|
981
|
-
this.transport.send(data);
|
|
982
|
-
}
|
|
983
|
-
/**
|
|
984
|
-
* Close the WebSocket connection.
|
|
985
|
-
* @param {number} code A status code (see https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1).
|
|
986
|
-
* @param {string} reason A custom connection close reason.
|
|
987
|
-
*/
|
|
988
|
-
close(code, reason) {
|
|
989
|
-
this.transport.close(code, reason);
|
|
990
|
-
}
|
|
991
|
-
};
|
|
992
|
-
var WEBSOCKET_CLOSE_CODE_RANGE_ERROR = "InvalidAccessError: close code out of user configurable range";
|
|
993
|
-
var kPassthroughPromise = /* @__PURE__ */ Symbol("kPassthroughPromise");
|
|
994
|
-
var kOnSend = /* @__PURE__ */ Symbol("kOnSend");
|
|
995
|
-
var kClose = /* @__PURE__ */ Symbol("kClose");
|
|
996
|
-
var WebSocketOverride = class extends EventTarget {
|
|
997
|
-
static {
|
|
998
|
-
this.CONNECTING = 0;
|
|
999
|
-
}
|
|
1000
|
-
static {
|
|
1001
|
-
this.OPEN = 1;
|
|
1002
|
-
}
|
|
1003
|
-
static {
|
|
1004
|
-
this.CLOSING = 2;
|
|
1005
|
-
}
|
|
1006
|
-
static {
|
|
1007
|
-
this.CLOSED = 3;
|
|
1008
|
-
}
|
|
1009
|
-
constructor(url, protocols) {
|
|
1010
|
-
super();
|
|
1011
|
-
this.CONNECTING = 0;
|
|
1012
|
-
this.OPEN = 1;
|
|
1013
|
-
this.CLOSING = 2;
|
|
1014
|
-
this.CLOSED = 3;
|
|
1015
|
-
this._onopen = null;
|
|
1016
|
-
this._onmessage = null;
|
|
1017
|
-
this._onerror = null;
|
|
1018
|
-
this._onclose = null;
|
|
1019
|
-
this.url = resolveWebSocketUrl(url);
|
|
1020
|
-
this.protocol = "";
|
|
1021
|
-
this.extensions = "";
|
|
1022
|
-
this.binaryType = "blob";
|
|
1023
|
-
this.readyState = this.CONNECTING;
|
|
1024
|
-
this.bufferedAmount = 0;
|
|
1025
|
-
this[kPassthroughPromise] = new DeferredPromise();
|
|
1026
|
-
queueMicrotask(async () => {
|
|
1027
|
-
if (await this[kPassthroughPromise]) return;
|
|
1028
|
-
this.protocol = typeof protocols === "string" ? protocols : Array.isArray(protocols) && protocols.length > 0 ? protocols[0] : "";
|
|
1029
|
-
if (this.readyState === this.CONNECTING) {
|
|
1030
|
-
this.readyState = this.OPEN;
|
|
1031
|
-
this.dispatchEvent(bindEvent(this, new Event("open")));
|
|
1032
|
-
}
|
|
1033
|
-
});
|
|
1034
|
-
}
|
|
1035
|
-
set onopen(listener) {
|
|
1036
|
-
this.removeEventListener("open", this._onopen);
|
|
1037
|
-
this._onopen = listener;
|
|
1038
|
-
if (listener !== null) this.addEventListener("open", listener);
|
|
1039
|
-
}
|
|
1040
|
-
get onopen() {
|
|
1041
|
-
return this._onopen;
|
|
1042
|
-
}
|
|
1043
|
-
set onmessage(listener) {
|
|
1044
|
-
this.removeEventListener("message", this._onmessage);
|
|
1045
|
-
this._onmessage = listener;
|
|
1046
|
-
if (listener !== null) this.addEventListener("message", listener);
|
|
1047
|
-
}
|
|
1048
|
-
get onmessage() {
|
|
1049
|
-
return this._onmessage;
|
|
1050
|
-
}
|
|
1051
|
-
set onerror(listener) {
|
|
1052
|
-
this.removeEventListener("error", this._onerror);
|
|
1053
|
-
this._onerror = listener;
|
|
1054
|
-
if (listener !== null) this.addEventListener("error", listener);
|
|
1055
|
-
}
|
|
1056
|
-
get onerror() {
|
|
1057
|
-
return this._onerror;
|
|
1058
|
-
}
|
|
1059
|
-
set onclose(listener) {
|
|
1060
|
-
this.removeEventListener("close", this._onclose);
|
|
1061
|
-
this._onclose = listener;
|
|
1062
|
-
if (listener !== null) this.addEventListener("close", listener);
|
|
1063
|
-
}
|
|
1064
|
-
get onclose() {
|
|
1065
|
-
return this._onclose;
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* @see https://websockets.spec.whatwg.org/#ref-for-dom-websocket-send%E2%91%A0
|
|
1069
|
-
*/
|
|
1070
|
-
send(data) {
|
|
1071
|
-
if (this.readyState === this.CONNECTING) {
|
|
1072
|
-
this.close();
|
|
1073
|
-
throw new DOMException("InvalidStateError");
|
|
1074
|
-
}
|
|
1075
|
-
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) return;
|
|
1076
|
-
this.bufferedAmount += getDataSize(data);
|
|
1077
|
-
queueMicrotask(() => {
|
|
1078
|
-
this.bufferedAmount = 0;
|
|
1079
|
-
this[kOnSend]?.(data);
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
|
-
close(code = 1e3, reason) {
|
|
1083
|
-
invariant(code, WEBSOCKET_CLOSE_CODE_RANGE_ERROR);
|
|
1084
|
-
invariant(code === 1e3 || code >= 3e3 && code <= 4999, WEBSOCKET_CLOSE_CODE_RANGE_ERROR);
|
|
1085
|
-
this[kClose](code, reason);
|
|
1086
|
-
}
|
|
1087
|
-
[kClose](code = 1e3, reason, wasClean = true) {
|
|
1088
|
-
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) return;
|
|
1089
|
-
this.readyState = this.CLOSING;
|
|
1090
|
-
queueMicrotask(() => {
|
|
1091
|
-
this.readyState = this.CLOSED;
|
|
1092
|
-
this.dispatchEvent(bindEvent(this, new CloseEvent("close", {
|
|
1093
|
-
code,
|
|
1094
|
-
reason,
|
|
1095
|
-
wasClean
|
|
1096
|
-
})));
|
|
1097
|
-
this._onopen = null;
|
|
1098
|
-
this._onmessage = null;
|
|
1099
|
-
this._onerror = null;
|
|
1100
|
-
this._onclose = null;
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
addEventListener(type, listener, options) {
|
|
1104
|
-
return super.addEventListener(type, listener, options);
|
|
1105
|
-
}
|
|
1106
|
-
removeEventListener(type, callback, options) {
|
|
1107
|
-
return super.removeEventListener(type, callback, options);
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
function getDataSize(data) {
|
|
1111
|
-
if (typeof data === "string") return data.length;
|
|
1112
|
-
if (data instanceof Blob) return data.size;
|
|
1113
|
-
return data.byteLength;
|
|
1114
|
-
}
|
|
1115
|
-
var kEmitter = /* @__PURE__ */ Symbol("kEmitter");
|
|
1116
|
-
var kBoundListener = /* @__PURE__ */ Symbol("kBoundListener");
|
|
1117
|
-
var kSend = /* @__PURE__ */ Symbol("kSend");
|
|
1118
|
-
var WebSocketServerConnection = class {
|
|
1119
|
-
constructor(client, transport, createConnection) {
|
|
1120
|
-
this.client = client;
|
|
1121
|
-
this.transport = transport;
|
|
1122
|
-
this.createConnection = createConnection;
|
|
1123
|
-
this[kEmitter] = new EventTarget();
|
|
1124
|
-
this.mockCloseController = new AbortController();
|
|
1125
|
-
this.realCloseController = new AbortController();
|
|
1126
|
-
this.transport.addEventListener("outgoing", (event) => {
|
|
1127
|
-
if (typeof this.realWebSocket === "undefined") return;
|
|
1128
|
-
queueMicrotask(() => {
|
|
1129
|
-
if (!event.defaultPrevented)
|
|
1130
|
-
this[kSend](event.data);
|
|
1131
|
-
});
|
|
1132
|
-
});
|
|
1133
|
-
this.transport.addEventListener("incoming", this.handleIncomingMessage.bind(this));
|
|
1134
|
-
}
|
|
1135
|
-
/**
|
|
1136
|
-
* The `WebSocket` instance connected to the original server.
|
|
1137
|
-
* Accessing this before calling `server.connect()` will throw.
|
|
1138
|
-
*/
|
|
1139
|
-
get socket() {
|
|
1140
|
-
invariant(this.realWebSocket, 'Cannot access "socket" on the original WebSocket server object: the connection is not open. Did you forget to call `server.connect()`?');
|
|
1141
|
-
return this.realWebSocket;
|
|
1142
|
-
}
|
|
1143
|
-
/**
|
|
1144
|
-
* Open connection to the original WebSocket server.
|
|
1145
|
-
*/
|
|
1146
|
-
connect() {
|
|
1147
|
-
invariant(!this.realWebSocket || this.realWebSocket.readyState !== WebSocket.OPEN, 'Failed to call "connect()" on the original WebSocket instance: the connection already open');
|
|
1148
|
-
const realWebSocket = this.createConnection();
|
|
1149
|
-
realWebSocket.binaryType = this.client.binaryType;
|
|
1150
|
-
realWebSocket.addEventListener("open", (event) => {
|
|
1151
|
-
this[kEmitter].dispatchEvent(bindEvent(this.realWebSocket, new Event("open", event)));
|
|
1152
|
-
}, { once: true });
|
|
1153
|
-
realWebSocket.addEventListener("message", (event) => {
|
|
1154
|
-
this.transport.dispatchEvent(bindEvent(this.realWebSocket, new MessageEvent("incoming", {
|
|
1155
|
-
data: event.data,
|
|
1156
|
-
origin: event.origin
|
|
1157
|
-
})));
|
|
1158
|
-
});
|
|
1159
|
-
this.client.addEventListener("close", (event) => {
|
|
1160
|
-
this.handleMockClose(event);
|
|
1161
|
-
}, { signal: this.mockCloseController.signal });
|
|
1162
|
-
realWebSocket.addEventListener("close", (event) => {
|
|
1163
|
-
this.handleRealClose(event);
|
|
1164
|
-
}, { signal: this.realCloseController.signal });
|
|
1165
|
-
realWebSocket.addEventListener("error", () => {
|
|
1166
|
-
const errorEvent = bindEvent(realWebSocket, new Event("error", { cancelable: true }));
|
|
1167
|
-
this[kEmitter].dispatchEvent(errorEvent);
|
|
1168
|
-
if (!errorEvent.defaultPrevented) this.client.dispatchEvent(bindEvent(this.client, new Event("error")));
|
|
1169
|
-
});
|
|
1170
|
-
this.realWebSocket = realWebSocket;
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Listen for the incoming events from the original WebSocket server.
|
|
1174
|
-
*/
|
|
1175
|
-
addEventListener(event, listener, options) {
|
|
1176
|
-
if (!Reflect.has(listener, kBoundListener)) {
|
|
1177
|
-
const boundListener = listener.bind(this.client);
|
|
1178
|
-
Object.defineProperty(listener, kBoundListener, {
|
|
1179
|
-
value: boundListener,
|
|
1180
|
-
enumerable: false
|
|
1181
|
-
});
|
|
1182
|
-
}
|
|
1183
|
-
this[kEmitter].addEventListener(event, Reflect.get(listener, kBoundListener), options);
|
|
1184
|
-
}
|
|
1185
|
-
/**
|
|
1186
|
-
* Remove the listener for the given event.
|
|
1187
|
-
*/
|
|
1188
|
-
removeEventListener(event, listener, options) {
|
|
1189
|
-
this[kEmitter].removeEventListener(event, Reflect.get(listener, kBoundListener), options);
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Send data to the original WebSocket server.
|
|
1193
|
-
* @example
|
|
1194
|
-
* server.send('hello')
|
|
1195
|
-
* server.send(new Blob(['hello']))
|
|
1196
|
-
* server.send(new TextEncoder().encode('hello'))
|
|
1197
|
-
*/
|
|
1198
|
-
send(data) {
|
|
1199
|
-
this[kSend](data);
|
|
1200
|
-
}
|
|
1201
|
-
[kSend](data) {
|
|
1202
|
-
const { realWebSocket } = this;
|
|
1203
|
-
invariant(realWebSocket, 'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "server.connect()"?', this.client.url);
|
|
1204
|
-
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) return;
|
|
1205
|
-
if (realWebSocket.readyState === WebSocket.CONNECTING) {
|
|
1206
|
-
realWebSocket.addEventListener("open", () => {
|
|
1207
|
-
realWebSocket.send(data);
|
|
1208
|
-
}, { once: true });
|
|
1209
|
-
return;
|
|
1210
|
-
}
|
|
1211
|
-
realWebSocket.send(data);
|
|
1212
|
-
}
|
|
1213
|
-
/**
|
|
1214
|
-
* Close the actual server connection.
|
|
1215
|
-
*/
|
|
1216
|
-
close() {
|
|
1217
|
-
const { realWebSocket } = this;
|
|
1218
|
-
invariant(realWebSocket, 'Failed to close server connection for "%s": the connection is not open. Did you forget to call "server.connect()"?', this.client.url);
|
|
1219
|
-
this.realCloseController.abort();
|
|
1220
|
-
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) return;
|
|
1221
|
-
realWebSocket.close();
|
|
1222
|
-
queueMicrotask(() => {
|
|
1223
|
-
this[kEmitter].dispatchEvent(bindEvent(this.realWebSocket, new CancelableCloseEvent("close", {
|
|
1224
|
-
code: 1e3,
|
|
1225
|
-
cancelable: true
|
|
1226
|
-
})));
|
|
1227
|
-
});
|
|
1228
|
-
}
|
|
1229
|
-
handleIncomingMessage(event) {
|
|
1230
|
-
const messageEvent = bindEvent(event.target, new CancelableMessageEvent("message", {
|
|
1231
|
-
data: event.data,
|
|
1232
|
-
origin: event.origin,
|
|
1233
|
-
cancelable: true
|
|
1234
|
-
}));
|
|
1235
|
-
this[kEmitter].dispatchEvent(messageEvent);
|
|
1236
|
-
if (!messageEvent.defaultPrevented) this.client.dispatchEvent(bindEvent(
|
|
1237
|
-
/**
|
|
1238
|
-
* @note Bind the forwarded original server events
|
|
1239
|
-
* to the mock WebSocket instance so it would
|
|
1240
|
-
* dispatch them straight away.
|
|
1241
|
-
*/
|
|
1242
|
-
this.client,
|
|
1243
|
-
new MessageEvent("message", {
|
|
1244
|
-
data: event.data,
|
|
1245
|
-
origin: event.origin
|
|
1246
|
-
})
|
|
1247
|
-
));
|
|
1248
|
-
}
|
|
1249
|
-
handleMockClose(_event) {
|
|
1250
|
-
if (this.realWebSocket) this.realWebSocket.close();
|
|
1251
|
-
}
|
|
1252
|
-
handleRealClose(event) {
|
|
1253
|
-
this.mockCloseController.abort();
|
|
1254
|
-
const closeEvent = bindEvent(this.realWebSocket, new CancelableCloseEvent("close", {
|
|
1255
|
-
code: event.code,
|
|
1256
|
-
reason: event.reason,
|
|
1257
|
-
wasClean: event.wasClean,
|
|
1258
|
-
cancelable: true
|
|
1259
|
-
}));
|
|
1260
|
-
this[kEmitter].dispatchEvent(closeEvent);
|
|
1261
|
-
if (!closeEvent.defaultPrevented) this.client[kClose](event.code, event.reason);
|
|
1262
|
-
}
|
|
1263
|
-
};
|
|
1264
|
-
var WebSocketClassTransport = class extends EventTarget {
|
|
1265
|
-
constructor(socket) {
|
|
1266
|
-
super();
|
|
1267
|
-
this.socket = socket;
|
|
1268
|
-
this.socket.addEventListener("close", (event) => {
|
|
1269
|
-
this.dispatchEvent(bindEvent(this.socket, new CloseEvent("close", event)));
|
|
1270
|
-
});
|
|
1271
|
-
this.socket[kOnSend] = (data) => {
|
|
1272
|
-
this.dispatchEvent(bindEvent(this.socket, new CancelableMessageEvent("outgoing", {
|
|
1273
|
-
data,
|
|
1274
|
-
origin: this.socket.url,
|
|
1275
|
-
cancelable: true
|
|
1276
|
-
})));
|
|
1277
|
-
};
|
|
1278
|
-
}
|
|
1279
|
-
addEventListener(type, callback, options) {
|
|
1280
|
-
return super.addEventListener(type, callback, options);
|
|
1281
|
-
}
|
|
1282
|
-
dispatchEvent(event) {
|
|
1283
|
-
return super.dispatchEvent(event);
|
|
1284
|
-
}
|
|
1285
|
-
send(data) {
|
|
1286
|
-
queueMicrotask(() => {
|
|
1287
|
-
if (this.socket.readyState === this.socket.CLOSING || this.socket.readyState === this.socket.CLOSED) return;
|
|
1288
|
-
const dispatchEvent = () => {
|
|
1289
|
-
this.socket.dispatchEvent(bindEvent(
|
|
1290
|
-
/**
|
|
1291
|
-
* @note Setting this event's "target" to the
|
|
1292
|
-
* WebSocket override instance is important.
|
|
1293
|
-
* This way it can tell apart original incoming events
|
|
1294
|
-
* (must be forwarded to the transport) from the
|
|
1295
|
-
* mocked message events like the one below
|
|
1296
|
-
* (must be dispatched on the client instance).
|
|
1297
|
-
*/
|
|
1298
|
-
this.socket,
|
|
1299
|
-
new MessageEvent("message", {
|
|
1300
|
-
data,
|
|
1301
|
-
origin: this.socket.url
|
|
1302
|
-
})
|
|
1303
|
-
));
|
|
1304
|
-
};
|
|
1305
|
-
if (this.socket.readyState === this.socket.CONNECTING) this.socket.addEventListener("open", () => {
|
|
1306
|
-
dispatchEvent();
|
|
1307
|
-
}, { once: true });
|
|
1308
|
-
else dispatchEvent();
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
close(code, reason) {
|
|
1312
|
-
this.socket[kClose](code, reason);
|
|
1313
|
-
}
|
|
1314
|
-
};
|
|
1315
|
-
var WebSocketInterceptor = class WebSocketInterceptor2 extends Interceptor {
|
|
1316
|
-
static {
|
|
1317
|
-
this.symbol = /* @__PURE__ */ Symbol.for("websocket-interceptor");
|
|
1318
|
-
}
|
|
1319
|
-
constructor() {
|
|
1320
|
-
super(WebSocketInterceptor2.symbol);
|
|
1321
|
-
}
|
|
1322
|
-
checkEnvironment() {
|
|
1323
|
-
return hasConfigurableGlobal("WebSocket");
|
|
1324
|
-
}
|
|
1325
|
-
setup() {
|
|
1326
|
-
const logger = this.logger.extend("setup");
|
|
1327
|
-
const WebSocketProxy = new Proxy(globalThis.WebSocket, { construct: (target, args, newTarget) => {
|
|
1328
|
-
const [url, protocols] = args;
|
|
1329
|
-
const createConnection = () => {
|
|
1330
|
-
return Reflect.construct(target, args, newTarget);
|
|
1331
|
-
};
|
|
1332
|
-
const socket = new WebSocketOverride(url, protocols);
|
|
1333
|
-
const transport = new WebSocketClassTransport(socket);
|
|
1334
|
-
queueMicrotask(async () => {
|
|
1335
|
-
try {
|
|
1336
|
-
const server = new WebSocketServerConnection(socket, transport, createConnection);
|
|
1337
|
-
const hasConnectionListeners = this.emitter.listenerCount("connection") > 0;
|
|
1338
|
-
await emitAsync(this.emitter, "connection", {
|
|
1339
|
-
client: new WebSocketClientConnection(socket, transport),
|
|
1340
|
-
server,
|
|
1341
|
-
info: { protocols }
|
|
1342
|
-
});
|
|
1343
|
-
if (hasConnectionListeners) socket[kPassthroughPromise].resolve(false);
|
|
1344
|
-
else {
|
|
1345
|
-
socket[kPassthroughPromise].resolve(true);
|
|
1346
|
-
server.connect();
|
|
1347
|
-
server.addEventListener("open", () => {
|
|
1348
|
-
socket.dispatchEvent(bindEvent(socket, new Event("open")));
|
|
1349
|
-
if (server["realWebSocket"]) socket.protocol = server["realWebSocket"].protocol;
|
|
1350
|
-
});
|
|
1351
|
-
}
|
|
1352
|
-
} catch (error2) {
|
|
1353
|
-
if (error2 instanceof Error) {
|
|
1354
|
-
socket.dispatchEvent(new Event("error"));
|
|
1355
|
-
if (socket.readyState !== WebSocket.CLOSING && socket.readyState !== WebSocket.CLOSED) socket[kClose](1011, error2.message, false);
|
|
1356
|
-
console.error(error2);
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
});
|
|
1360
|
-
return socket;
|
|
1361
|
-
} });
|
|
1362
|
-
logger.info("patching global WebSocket...");
|
|
1363
|
-
this.subscriptions.push(patchesRegistry.applyPatch(globalThis, "WebSocket", () => WebSocketProxy));
|
|
1364
|
-
logger.info("global WebSocket patched!", globalThis.WebSocket.name);
|
|
1365
|
-
}
|
|
1366
|
-
};
|
|
1367
|
-
|
|
1368
|
-
// src/browser/setup-worker.ts
|
|
1369
|
-
var import_define_network = require("../core/experimental/define-network");
|
|
1370
|
-
var import_interceptor_source2 = require("../core/experimental/sources/interceptor-source");
|
|
1371
|
-
var import_compat = require("../core/experimental/compat");
|
|
1372
|
-
var import_devUtils5 = require("../core/utils/internal/devUtils");
|
|
1373
|
-
|
|
1374
|
-
// src/browser/utils/supports.ts
|
|
1
|
+
import { m as devUtils } from "../_chunks/cookie-store.js";
|
|
2
|
+
import { t as RequestHandler } from "../_chunks/request-handler.js";
|
|
3
|
+
import { t as isObject } from "../_chunks/is-object.js";
|
|
4
|
+
import { t as HttpResponse } from "../_chunks/http-response.js";
|
|
5
|
+
import { i as ResponseEvent, r as HttpNetworkFrame, s as defineNetwork, t as InterceptorSource, u as NetworkSource } from "../_chunks/interceptor-source.js";
|
|
6
|
+
import { isNodeProcess } from "is-node-process";
|
|
7
|
+
import { invariant } from "outvariant";
|
|
8
|
+
import { FetchRequest, FetchResponse } from "@mswjs/interceptors";
|
|
9
|
+
import { Emitter, TypedEvent } from "rettime";
|
|
10
|
+
import { WebSocketInterceptor } from "@mswjs/interceptors/WebSocket";
|
|
11
|
+
import { until } from "until-async";
|
|
12
|
+
import { XMLHttpRequestInterceptor } from "@mswjs/interceptors/XMLHttpRequest";
|
|
13
|
+
import { FetchInterceptor } from "@mswjs/interceptors/fetch";
|
|
14
|
+
//#region src/browser/utils/supports.ts
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the Service Worker API is supproted and available
|
|
17
|
+
* in the current browsing context.
|
|
18
|
+
*/
|
|
1375
19
|
function supportsServiceWorker() {
|
|
1376
|
-
|
|
20
|
+
return typeof navigator !== "undefined" && "serviceWorker" in navigator && typeof location !== "undefined" && location.protocol !== "file:";
|
|
1377
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a boolean indicating whether the current browser
|
|
24
|
+
* supports `ReadableStream` as a `Transferable` when posting
|
|
25
|
+
* messages.
|
|
26
|
+
*/
|
|
1378
27
|
function supportsReadableStreamTransfer() {
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
return resolve(data instanceof Promise ? data : Promise.resolve(data).then(onFulfilled));
|
|
1403
|
-
};
|
|
1404
|
-
executor.reject = (reason) => {
|
|
1405
|
-
if (executor.state !== "pending") return;
|
|
1406
|
-
queueMicrotask(() => {
|
|
1407
|
-
executor.state = "rejected";
|
|
1408
|
-
});
|
|
1409
|
-
return reject(executor.rejectionReason = reason);
|
|
1410
|
-
};
|
|
1411
|
-
});
|
|
1412
|
-
return executor;
|
|
1413
|
-
}
|
|
1414
|
-
var DeferredPromise2 = class extends Promise {
|
|
1415
|
-
#executor;
|
|
1416
|
-
resolve;
|
|
1417
|
-
reject;
|
|
1418
|
-
constructor(executor = null) {
|
|
1419
|
-
const deferredExecutor = createDeferredExecutor2();
|
|
1420
|
-
super((originalResolve, originalReject) => {
|
|
1421
|
-
deferredExecutor(originalResolve, originalReject);
|
|
1422
|
-
executor?.(deferredExecutor.resolve, deferredExecutor.reject);
|
|
1423
|
-
});
|
|
1424
|
-
this.#executor = deferredExecutor;
|
|
1425
|
-
this.resolve = this.#executor.resolve;
|
|
1426
|
-
this.reject = this.#executor.reject;
|
|
1427
|
-
}
|
|
1428
|
-
get state() {
|
|
1429
|
-
return this.#executor.state;
|
|
1430
|
-
}
|
|
1431
|
-
get rejectionReason() {
|
|
1432
|
-
return this.#executor.rejectionReason;
|
|
1433
|
-
}
|
|
1434
|
-
then(onFulfilled, onRejected) {
|
|
1435
|
-
return this.#decorate(super.then(onFulfilled, onRejected));
|
|
1436
|
-
}
|
|
1437
|
-
catch(onRejected) {
|
|
1438
|
-
return this.#decorate(super.catch(onRejected));
|
|
1439
|
-
}
|
|
1440
|
-
finally(onfinally) {
|
|
1441
|
-
return this.#decorate(super.finally(onfinally));
|
|
1442
|
-
}
|
|
1443
|
-
#decorate(promise) {
|
|
1444
|
-
return Object.defineProperties(promise, {
|
|
1445
|
-
resolve: {
|
|
1446
|
-
configurable: true,
|
|
1447
|
-
value: this.resolve
|
|
1448
|
-
},
|
|
1449
|
-
reject: {
|
|
1450
|
-
configurable: true,
|
|
1451
|
-
value: this.reject
|
|
1452
|
-
}
|
|
1453
|
-
});
|
|
1454
|
-
}
|
|
1455
|
-
};
|
|
1456
|
-
|
|
1457
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-B1BqgWG6.mjs
|
|
1458
|
-
var InterceptorError = class InterceptorError2 extends Error {
|
|
1459
|
-
constructor(message) {
|
|
1460
|
-
super(message);
|
|
1461
|
-
this.name = "InterceptorError";
|
|
1462
|
-
Object.setPrototypeOf(this, InterceptorError2.prototype);
|
|
1463
|
-
}
|
|
1464
|
-
};
|
|
1465
|
-
var RequestController = class RequestController2 {
|
|
1466
|
-
static {
|
|
1467
|
-
this.PENDING = 0;
|
|
1468
|
-
}
|
|
1469
|
-
static {
|
|
1470
|
-
this.PASSTHROUGH = 1;
|
|
1471
|
-
}
|
|
1472
|
-
static {
|
|
1473
|
-
this.RESPONSE = 2;
|
|
1474
|
-
}
|
|
1475
|
-
static {
|
|
1476
|
-
this.ERROR = 3;
|
|
1477
|
-
}
|
|
1478
|
-
constructor(request, source) {
|
|
1479
|
-
this.request = request;
|
|
1480
|
-
this.source = source;
|
|
1481
|
-
this.readyState = RequestController2.PENDING;
|
|
1482
|
-
this.handled = new DeferredPromise();
|
|
1483
|
-
}
|
|
1484
|
-
get #handled() {
|
|
1485
|
-
return this.handled;
|
|
1486
|
-
}
|
|
1487
|
-
/**
|
|
1488
|
-
* Perform this request as-is.
|
|
1489
|
-
*/
|
|
1490
|
-
async passthrough() {
|
|
1491
|
-
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);
|
|
1492
|
-
this.readyState = RequestController2.PASSTHROUGH;
|
|
1493
|
-
await this.source.passthrough();
|
|
1494
|
-
this.#handled.resolve();
|
|
1495
|
-
}
|
|
1496
|
-
/**
|
|
1497
|
-
* Respond to this request with the given `Response` instance.
|
|
1498
|
-
*
|
|
1499
|
-
* @example
|
|
1500
|
-
* controller.respondWith(new Response())
|
|
1501
|
-
* controller.respondWith(Response.json({ id }))
|
|
1502
|
-
* controller.respondWith(Response.error())
|
|
1503
|
-
*/
|
|
1504
|
-
respondWith(response) {
|
|
1505
|
-
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);
|
|
1506
|
-
this.readyState = RequestController2.RESPONSE;
|
|
1507
|
-
this.#handled.resolve();
|
|
1508
|
-
this.source.respondWith(response);
|
|
1509
|
-
}
|
|
1510
|
-
/**
|
|
1511
|
-
* Error this request with the given reason.
|
|
1512
|
-
*
|
|
1513
|
-
* @example
|
|
1514
|
-
* controller.errorWith()
|
|
1515
|
-
* controller.errorWith(new Error('Oops!'))
|
|
1516
|
-
* controller.errorWith({ message: 'Oops!'})
|
|
1517
|
-
*/
|
|
1518
|
-
errorWith(reason) {
|
|
1519
|
-
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);
|
|
1520
|
-
this.readyState = RequestController2.ERROR;
|
|
1521
|
-
this.source.errorWith(reason);
|
|
1522
|
-
this.#handled.resolve();
|
|
1523
|
-
}
|
|
1524
|
-
};
|
|
1525
|
-
function canParseUrl(url) {
|
|
1526
|
-
try {
|
|
1527
|
-
new URL(url);
|
|
1528
|
-
return true;
|
|
1529
|
-
} catch (_error) {
|
|
1530
|
-
return false;
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
function getValueBySymbol(symbolName, source) {
|
|
1534
|
-
const symbol = Object.getOwnPropertySymbols(source).find((symbol$1) => {
|
|
1535
|
-
return symbol$1.description === symbolName;
|
|
1536
|
-
});
|
|
1537
|
-
if (symbol) return Reflect.get(source, symbol);
|
|
1538
|
-
}
|
|
1539
|
-
var FetchRequest = class FetchRequest2 extends Request {
|
|
1540
|
-
static #resolveProperty(input, init = {}, key) {
|
|
1541
|
-
return init[key] ?? (input instanceof Request ? input[key] : void 0);
|
|
1542
|
-
}
|
|
1543
|
-
/**
|
|
1544
|
-
* Check if the given request method is configurable.
|
|
1545
|
-
* @see https://fetch.spec.whatwg.org/#methods
|
|
1546
|
-
*/
|
|
1547
|
-
static isConfigurableMethod(method) {
|
|
1548
|
-
return method !== "CONNECT" && method !== "TRACE" && method !== "TRACK";
|
|
1549
|
-
}
|
|
1550
|
-
static isMethodWithBody(method) {
|
|
1551
|
-
return method !== "HEAD" && method !== "GET" && FetchRequest2.isConfigurableMethod(method);
|
|
1552
|
-
}
|
|
1553
|
-
/**
|
|
1554
|
-
* Check if the given request `mode` is configurable.
|
|
1555
|
-
* @see https://fetch.spec.whatwg.org/#concept-request-mode
|
|
1556
|
-
*/
|
|
1557
|
-
static isConfigurableMode(mode) {
|
|
1558
|
-
return mode !== "navigate" && mode !== "websocket" && mode !== "webtransport";
|
|
1559
|
-
}
|
|
1560
|
-
constructor(input, init) {
|
|
1561
|
-
const method = FetchRequest2.#resolveProperty(input, init, "method") || "GET";
|
|
1562
|
-
const safeMethod = FetchRequest2.isConfigurableMethod(method) ? method : "GET";
|
|
1563
|
-
const hasExplicitBody = init != null && "body" in init;
|
|
1564
|
-
const bodyInit = !FetchRequest2.isMethodWithBody(method) ? { body: void 0 } : hasExplicitBody ? { body: init.body } : {};
|
|
1565
|
-
const mode = FetchRequest2.#resolveProperty(input, init, "mode") ?? void 0;
|
|
1566
|
-
const safeMode = FetchRequest2.isConfigurableMode(mode) ? mode : void 0;
|
|
1567
|
-
super(input, {
|
|
1568
|
-
...init || {},
|
|
1569
|
-
method: safeMethod,
|
|
1570
|
-
mode: safeMode,
|
|
1571
|
-
duplex: init?.duplex ?? (FetchRequest2.isMethodWithBody(method) ? "half" : void 0),
|
|
1572
|
-
...bodyInit
|
|
1573
|
-
});
|
|
1574
|
-
if (method !== safeMethod) this.#setInternalProperty("method", method);
|
|
1575
|
-
if (method === "CONNECT") {
|
|
1576
|
-
const url = new URL(input instanceof Request ? input.url : input);
|
|
1577
|
-
let authority;
|
|
1578
|
-
if (url.protocol === "localhost:") authority = url.href;
|
|
1579
|
-
else authority = url.pathname.replace(/^\/+/, "");
|
|
1580
|
-
Object.defineProperty(this, "url", {
|
|
1581
|
-
get: () => authority,
|
|
1582
|
-
enumerable: true,
|
|
1583
|
-
configurable: true
|
|
1584
|
-
});
|
|
1585
|
-
}
|
|
1586
|
-
if (mode != null && mode !== safeMode) this.#setInternalProperty("mode", mode);
|
|
1587
|
-
}
|
|
1588
|
-
#setInternalProperty(key, value) {
|
|
1589
|
-
const internalState = getValueBySymbol("state", this);
|
|
1590
|
-
if (internalState) Reflect.set(internalState, key, value);
|
|
1591
|
-
else Object.defineProperty(this, key, {
|
|
1592
|
-
value,
|
|
1593
|
-
enumerable: true,
|
|
1594
|
-
configurable: true,
|
|
1595
|
-
writable: false
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
};
|
|
1599
|
-
var kStatus = /* @__PURE__ */ Symbol("kStatus");
|
|
1600
|
-
var kUrl = /* @__PURE__ */ Symbol("kUrl");
|
|
1601
|
-
var FetchResponse = class FetchResponse2 extends Response {
|
|
1602
|
-
static {
|
|
1603
|
-
this.STATUS_CODES_WITHOUT_BODY = [
|
|
1604
|
-
101,
|
|
1605
|
-
103,
|
|
1606
|
-
204,
|
|
1607
|
-
205,
|
|
1608
|
-
304
|
|
1609
|
-
];
|
|
1610
|
-
}
|
|
1611
|
-
static {
|
|
1612
|
-
this.STATUS_CODES_WITH_REDIRECT = [
|
|
1613
|
-
301,
|
|
1614
|
-
302,
|
|
1615
|
-
303,
|
|
1616
|
-
307,
|
|
1617
|
-
308
|
|
1618
|
-
];
|
|
1619
|
-
}
|
|
1620
|
-
static isConfigurableStatusCode(status) {
|
|
1621
|
-
return status >= 200 && status <= 599;
|
|
1622
|
-
}
|
|
1623
|
-
static isRedirectResponse(status) {
|
|
1624
|
-
return FetchResponse2.STATUS_CODES_WITH_REDIRECT.includes(status);
|
|
1625
|
-
}
|
|
1626
|
-
/**
|
|
1627
|
-
* Returns a boolean indicating whether the given response status
|
|
1628
|
-
* code represents a response that can have a body.
|
|
1629
|
-
*/
|
|
1630
|
-
static isResponseWithBody(status) {
|
|
1631
|
-
return !FetchResponse2.STATUS_CODES_WITHOUT_BODY.includes(status);
|
|
1632
|
-
}
|
|
1633
|
-
static setStatus(status, response) {
|
|
1634
|
-
const internalState = getValueBySymbol("state", response);
|
|
1635
|
-
if (internalState) internalState.status = status;
|
|
1636
|
-
else Object.defineProperty(response, "status", {
|
|
1637
|
-
value: status,
|
|
1638
|
-
enumerable: true,
|
|
1639
|
-
configurable: true,
|
|
1640
|
-
writable: false
|
|
1641
|
-
});
|
|
1642
|
-
Object.defineProperty(response, kStatus, {
|
|
1643
|
-
value: status,
|
|
1644
|
-
enumerable: false
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
static setUrl(url, response) {
|
|
1648
|
-
if (!url || url === "about:" || !canParseUrl(url)) return;
|
|
1649
|
-
const state = getValueBySymbol("state", response);
|
|
1650
|
-
if (state) state.urlList.push(new URL(url));
|
|
1651
|
-
else Object.defineProperty(response, "url", {
|
|
1652
|
-
value: url,
|
|
1653
|
-
enumerable: true,
|
|
1654
|
-
configurable: true,
|
|
1655
|
-
writable: false
|
|
1656
|
-
});
|
|
1657
|
-
Object.defineProperty(response, kUrl, {
|
|
1658
|
-
value: url,
|
|
1659
|
-
enumerable: false
|
|
1660
|
-
});
|
|
1661
|
-
}
|
|
1662
|
-
/**
|
|
1663
|
-
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
|
1664
|
-
*/
|
|
1665
|
-
static parseRawHeaders(rawHeaders) {
|
|
1666
|
-
const headers = new Headers();
|
|
1667
|
-
for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
|
1668
|
-
return headers;
|
|
1669
|
-
}
|
|
1670
|
-
/**
|
|
1671
|
-
* Safely clones the given `Response`.
|
|
1672
|
-
* Coerces response clone exceptions into 500 mocked responses.
|
|
1673
|
-
* Handy in the environments that introduce arbitrary response
|
|
1674
|
-
* cloning restrictions, like "101 Switching Protocols" cloning
|
|
1675
|
-
* in "miniflare".
|
|
1676
|
-
*/
|
|
1677
|
-
static clone(response) {
|
|
1678
|
-
try {
|
|
1679
|
-
return response.clone();
|
|
1680
|
-
} catch (error2) {
|
|
1681
|
-
return Response.json(error2 instanceof Error ? {
|
|
1682
|
-
name: error2.name,
|
|
1683
|
-
message: error2.message,
|
|
1684
|
-
stack: error2.stack
|
|
1685
|
-
} : {}, {
|
|
1686
|
-
status: 500,
|
|
1687
|
-
statusText: "Unclonable Response"
|
|
1688
|
-
});
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
constructor(body, init = {}) {
|
|
1692
|
-
const status = init.status ?? 200;
|
|
1693
|
-
const safeStatus = FetchResponse2.isConfigurableStatusCode(status) ? status : 200;
|
|
1694
|
-
const finalBody = FetchResponse2.isResponseWithBody(status) ? body : null;
|
|
1695
|
-
super(finalBody, {
|
|
1696
|
-
status: safeStatus,
|
|
1697
|
-
statusText: init.statusText,
|
|
1698
|
-
headers: init.headers
|
|
1699
|
-
});
|
|
1700
|
-
if (status !== safeStatus) FetchResponse2.setStatus(status, this);
|
|
1701
|
-
FetchResponse2.setUrl(init.url, this);
|
|
1702
|
-
}
|
|
1703
|
-
clone() {
|
|
1704
|
-
const clonedResponse = super.clone();
|
|
1705
|
-
const customStatus = Reflect.get(this, kStatus);
|
|
1706
|
-
if (customStatus) FetchResponse2.setStatus(customStatus, clonedResponse);
|
|
1707
|
-
const customUrl = Reflect.get(this, kUrl);
|
|
1708
|
-
if (customUrl) FetchResponse2.setUrl(customUrl, clonedResponse);
|
|
1709
|
-
return clonedResponse;
|
|
1710
|
-
}
|
|
1711
|
-
};
|
|
1712
|
-
var kRawRequest = /* @__PURE__ */ Symbol("kRawRequest");
|
|
1713
|
-
function setRawRequest(request, rawRequest) {
|
|
1714
|
-
Reflect.set(request, kRawRequest, rawRequest);
|
|
1715
|
-
}
|
|
1716
|
-
|
|
1717
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/bufferUtils-BiiO6HZv.mjs
|
|
1718
|
-
var encoder = new TextEncoder();
|
|
1719
|
-
function encodeBuffer(text) {
|
|
1720
|
-
return encoder.encode(text);
|
|
1721
|
-
}
|
|
1722
|
-
function decodeBuffer(buffer, encoding) {
|
|
1723
|
-
return new TextDecoder(encoding).decode(buffer);
|
|
1724
|
-
}
|
|
1725
|
-
function toArrayBuffer(array) {
|
|
1726
|
-
return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
// src/browser/sources/service-worker-source.ts
|
|
1730
|
-
var import_network_source = require("../core/experimental/sources/network-source");
|
|
1731
|
-
var import_RequestHandler = require("../core/handlers/RequestHandler");
|
|
1732
|
-
var import_http_frame = require("../core/experimental/frames/http-frame");
|
|
1733
|
-
var import_HttpResponse = require("../core/HttpResponse");
|
|
1734
|
-
var import_toResponseInit = require("../core/utils/toResponseInit");
|
|
1735
|
-
var import_devUtils3 = require("../core/utils/internal/devUtils");
|
|
1736
|
-
|
|
1737
|
-
// node_modules/.pnpm/until-async@3.0.2/node_modules/until-async/lib/index.js
|
|
1738
|
-
async function until(callback) {
|
|
1739
|
-
try {
|
|
1740
|
-
return [null, await callback().catch((error2) => {
|
|
1741
|
-
throw error2;
|
|
1742
|
-
})];
|
|
1743
|
-
} catch (error2) {
|
|
1744
|
-
return [error2, null];
|
|
1745
|
-
}
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1748
|
-
// src/browser/utils/get-worker-instance.ts
|
|
1749
|
-
var import_devUtils = require("../core/utils/internal/devUtils");
|
|
1750
|
-
|
|
1751
|
-
// src/browser/utils/getAbsoluteWorkerUrl.ts
|
|
28
|
+
try {
|
|
29
|
+
const stream = new ReadableStream({ start: (controller) => controller.close() });
|
|
30
|
+
new MessageChannel().port1.postMessage(stream, [stream]);
|
|
31
|
+
return true;
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/core/utils/to-response-init.ts
|
|
38
|
+
function toResponseInit(response) {
|
|
39
|
+
return {
|
|
40
|
+
status: response.status,
|
|
41
|
+
statusText: response.statusText,
|
|
42
|
+
headers: Object.fromEntries(response.headers.entries())
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/browser/utils/get-absolute-worker-url.ts
|
|
47
|
+
/**
|
|
48
|
+
* Returns an absolute Service Worker URL based on the given
|
|
49
|
+
* relative URL (known during the registration).
|
|
50
|
+
*/
|
|
1752
51
|
function getAbsoluteWorkerUrl(workerUrl) {
|
|
1753
|
-
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
|
|
52
|
+
return new URL(workerUrl, location.href).href;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/browser/utils/get-worker-by-registration.ts
|
|
56
|
+
/**
|
|
57
|
+
* Attempts to resolve a Service Worker instance from a given registration,
|
|
58
|
+
* regardless of its state (active, installing, waiting).
|
|
59
|
+
*/
|
|
1757
60
|
function getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker) {
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
existingRegistration
|
|
1793
|
-
];
|
|
1794
|
-
}
|
|
1795
|
-
const [registrationError, registrationResult] = await until(async () => {
|
|
1796
|
-
const registration = await navigator.serviceWorker.register(url, options);
|
|
1797
|
-
return [
|
|
1798
|
-
// Compare existing worker registration by its worker URL,
|
|
1799
|
-
// to prevent irrelevant workers to resolve here (such as Codesandbox worker).
|
|
1800
|
-
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
1801
|
-
registration
|
|
1802
|
-
];
|
|
1803
|
-
});
|
|
1804
|
-
if (registrationError) {
|
|
1805
|
-
const isWorkerMissing = registrationError.message.includes("(404)");
|
|
1806
|
-
if (isWorkerMissing) {
|
|
1807
|
-
const scopeUrl = new URL(options?.scope || "/", location.href);
|
|
1808
|
-
throw new Error(
|
|
1809
|
-
import_devUtils.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.
|
|
61
|
+
return [
|
|
62
|
+
registration.active,
|
|
63
|
+
registration.installing,
|
|
64
|
+
registration.waiting
|
|
65
|
+
].filter((state) => {
|
|
66
|
+
return state != null;
|
|
67
|
+
}).find((worker) => {
|
|
68
|
+
return findWorker(worker.scriptURL, absoluteWorkerUrl);
|
|
69
|
+
}) || null;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/browser/utils/get-worker-instance.ts
|
|
73
|
+
/**
|
|
74
|
+
* Returns an active Service Worker instance.
|
|
75
|
+
* When not found, registers a new Service Worker.
|
|
76
|
+
*/
|
|
77
|
+
const getWorkerInstance = async (url, options = {}, findWorker) => {
|
|
78
|
+
const absoluteWorkerUrl = getAbsoluteWorkerUrl(url);
|
|
79
|
+
const mockRegistrations = await navigator.serviceWorker.getRegistrations().then((registrations) => registrations.filter((registration) => getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker)));
|
|
80
|
+
if (!navigator.serviceWorker.controller && mockRegistrations.length > 0) location.reload();
|
|
81
|
+
const [existingRegistration] = mockRegistrations;
|
|
82
|
+
if (existingRegistration) {
|
|
83
|
+
existingRegistration.update();
|
|
84
|
+
return [getWorkerByRegistration(existingRegistration, absoluteWorkerUrl, findWorker), existingRegistration];
|
|
85
|
+
}
|
|
86
|
+
const [registrationError, registrationResult] = await until(async () => {
|
|
87
|
+
const registration = await navigator.serviceWorker.register(url, options);
|
|
88
|
+
return [getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker), registration];
|
|
89
|
+
});
|
|
90
|
+
if (registrationError) {
|
|
91
|
+
if (registrationError.message.includes("(404)")) {
|
|
92
|
+
const scopeUrl = new URL(options?.scope || "/", location.href);
|
|
93
|
+
throw new Error(devUtils.formatMessage(`\
|
|
94
|
+
Failed to register a Service Worker for scope ('${scopeUrl.href}') with script ('${absoluteWorkerUrl}'): Service Worker script does not exist at the given path.
|
|
1810
95
|
|
|
1811
96
|
Did you forget to run "npx msw init <PUBLIC_DIR>"?
|
|
1812
97
|
|
|
1813
|
-
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init`)
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
"Failed to register the Service Worker:\n\n%s",
|
|
1819
|
-
registrationError.message
|
|
1820
|
-
)
|
|
1821
|
-
);
|
|
1822
|
-
}
|
|
1823
|
-
return registrationResult;
|
|
1824
|
-
};
|
|
1825
|
-
|
|
1826
|
-
// node_modules/.pnpm/rettime@0.11.11/node_modules/rettime/build/lens-list.mjs
|
|
1827
|
-
var LensList = class {
|
|
1828
|
-
#list;
|
|
1829
|
-
#lens;
|
|
1830
|
-
constructor() {
|
|
1831
|
-
this.#list = [];
|
|
1832
|
-
this.#lens = /* @__PURE__ */ new Map();
|
|
1833
|
-
}
|
|
1834
|
-
get [Symbol.iterator]() {
|
|
1835
|
-
return this.#list[Symbol.iterator].bind(this.#list);
|
|
1836
|
-
}
|
|
1837
|
-
entries() {
|
|
1838
|
-
return this.#lens.entries();
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Return an order-sensitive list of values by the given key.
|
|
1842
|
-
*/
|
|
1843
|
-
get(key) {
|
|
1844
|
-
return this.#lens.get(key) || [];
|
|
1845
|
-
}
|
|
1846
|
-
/**
|
|
1847
|
-
* Return an order-sensitive list of all values.
|
|
1848
|
-
*/
|
|
1849
|
-
getAll() {
|
|
1850
|
-
return this.#list.map(([, value]) => value);
|
|
1851
|
-
}
|
|
1852
|
-
/**
|
|
1853
|
-
* Append a new value to the given key.
|
|
1854
|
-
*/
|
|
1855
|
-
append(key, value) {
|
|
1856
|
-
this.#list.push([key, value]);
|
|
1857
|
-
this.#openLens(key, (list) => list.push(value));
|
|
1858
|
-
}
|
|
1859
|
-
/**
|
|
1860
|
-
* Prepend a new value to the given key.
|
|
1861
|
-
*/
|
|
1862
|
-
prepend(key, value) {
|
|
1863
|
-
this.#list.unshift([key, value]);
|
|
1864
|
-
this.#openLens(key, (list) => list.unshift(value));
|
|
1865
|
-
}
|
|
1866
|
-
/**
|
|
1867
|
-
* Delete the value belonging to the given key.
|
|
1868
|
-
* Returns `true` if the value was present and removed, `false` otherwise.
|
|
1869
|
-
*/
|
|
1870
|
-
delete(key, value) {
|
|
1871
|
-
if (this.size === 0) return false;
|
|
1872
|
-
const values = this.#lens.get(key);
|
|
1873
|
-
if (!values) return false;
|
|
1874
|
-
const index = values.indexOf(value);
|
|
1875
|
-
if (index === -1) return false;
|
|
1876
|
-
values.splice(index, 1);
|
|
1877
|
-
this.#list.splice(this.#list.findIndex((item) => item[0] === key && item[1] === value), 1);
|
|
1878
|
-
return true;
|
|
1879
|
-
}
|
|
1880
|
-
/**
|
|
1881
|
-
* Delete all values belogning to the given key.
|
|
1882
|
-
*/
|
|
1883
|
-
deleteAll(key) {
|
|
1884
|
-
if (this.size === 0) return;
|
|
1885
|
-
this.#list = this.#list.filter((item) => item[0] !== key);
|
|
1886
|
-
this.#lens.delete(key);
|
|
1887
|
-
}
|
|
1888
|
-
get size() {
|
|
1889
|
-
return this.#list.length;
|
|
1890
|
-
}
|
|
1891
|
-
clear() {
|
|
1892
|
-
if (this.size === 0) return;
|
|
1893
|
-
this.#list.length = 0;
|
|
1894
|
-
this.#lens.clear();
|
|
1895
|
-
}
|
|
1896
|
-
#openLens(key, setter) {
|
|
1897
|
-
setter(this.#lens.get(key) || this.#lens.set(key, []).get(key));
|
|
1898
|
-
}
|
|
1899
|
-
};
|
|
1900
|
-
|
|
1901
|
-
// node_modules/.pnpm/rettime@0.11.11/node_modules/rettime/build/index.mjs
|
|
1902
|
-
var kDefaultPrevented2 = /* @__PURE__ */ Symbol("kDefaultPrevented");
|
|
1903
|
-
var kPropagationStopped = /* @__PURE__ */ Symbol("kPropagationStopped");
|
|
1904
|
-
var kImmediatePropagationStopped = /* @__PURE__ */ Symbol("kImmediatePropagationStopped");
|
|
1905
|
-
var TypedEvent = class extends MessageEvent {
|
|
1906
|
-
/**
|
|
1907
|
-
* @note Keep a placeholder property with the return type
|
|
1908
|
-
* because the type must be set somewhere in order to be
|
|
1909
|
-
* correctly associated and inferred from the event.
|
|
1910
|
-
*/
|
|
1911
|
-
#returnType;
|
|
1912
|
-
[kDefaultPrevented2];
|
|
1913
|
-
[kPropagationStopped];
|
|
1914
|
-
[kImmediatePropagationStopped];
|
|
1915
|
-
constructor(...args) {
|
|
1916
|
-
super(args[0], args[1]);
|
|
1917
|
-
this[kDefaultPrevented2] = false;
|
|
1918
|
-
}
|
|
1919
|
-
get defaultPrevented() {
|
|
1920
|
-
return this[kDefaultPrevented2];
|
|
1921
|
-
}
|
|
1922
|
-
preventDefault() {
|
|
1923
|
-
super.preventDefault();
|
|
1924
|
-
this[kDefaultPrevented2] = true;
|
|
1925
|
-
}
|
|
1926
|
-
stopImmediatePropagation() {
|
|
1927
|
-
super.stopImmediatePropagation();
|
|
1928
|
-
this[kImmediatePropagationStopped] = true;
|
|
1929
|
-
}
|
|
98
|
+
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init`));
|
|
99
|
+
}
|
|
100
|
+
throw new Error(devUtils.formatMessage("Failed to register the Service Worker:\n\n%s", registrationError.message));
|
|
101
|
+
}
|
|
102
|
+
return registrationResult;
|
|
1930
103
|
};
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
#listenerAbortCleanups;
|
|
1935
|
-
#typelessListeners;
|
|
1936
|
-
#hookListeners;
|
|
1937
|
-
#hookListenerOptions;
|
|
1938
|
-
#hookListenerAbortCleanups;
|
|
1939
|
-
hooks;
|
|
1940
|
-
constructor() {
|
|
1941
|
-
this.#listeners = new LensList();
|
|
1942
|
-
this.#listenerOptions = /* @__PURE__ */ new WeakMap();
|
|
1943
|
-
this.#listenerAbortCleanups = /* @__PURE__ */ new WeakMap();
|
|
1944
|
-
this.#typelessListeners = /* @__PURE__ */ new WeakSet();
|
|
1945
|
-
this.#hookListeners = new LensList();
|
|
1946
|
-
this.#hookListenerOptions = /* @__PURE__ */ new WeakMap();
|
|
1947
|
-
this.#hookListenerAbortCleanups = /* @__PURE__ */ new WeakMap();
|
|
1948
|
-
this.hooks = {
|
|
1949
|
-
on: (hook, callback, options) => {
|
|
1950
|
-
if (options?.signal?.aborted) return;
|
|
1951
|
-
if (options?.once) {
|
|
1952
|
-
const original = callback;
|
|
1953
|
-
const wrapper = ((...args) => {
|
|
1954
|
-
this.#deleteHookListener(hook, wrapper);
|
|
1955
|
-
return original(...args);
|
|
1956
|
-
});
|
|
1957
|
-
callback = wrapper;
|
|
1958
|
-
}
|
|
1959
|
-
this.#hookListeners.append(hook, callback);
|
|
1960
|
-
if (options) this.#hookListenerOptions.set(callback, options);
|
|
1961
|
-
if (options?.signal) {
|
|
1962
|
-
const { signal } = options;
|
|
1963
|
-
const onAbort = () => {
|
|
1964
|
-
this.#deleteHookListener(hook, callback);
|
|
1965
|
-
};
|
|
1966
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
1967
|
-
this.#hookListenerAbortCleanups.set(callback, () => {
|
|
1968
|
-
signal.removeEventListener("abort", onAbort);
|
|
1969
|
-
});
|
|
1970
|
-
}
|
|
1971
|
-
},
|
|
1972
|
-
removeListener: (hook, callback) => {
|
|
1973
|
-
this.#deleteHookListener(hook, callback);
|
|
1974
|
-
}
|
|
1975
|
-
};
|
|
1976
|
-
}
|
|
1977
|
-
#deleteHookListener(hook, callback) {
|
|
1978
|
-
this.#hookListeners.delete(hook, callback);
|
|
1979
|
-
const cleanup = this.#hookListenerAbortCleanups.get(callback);
|
|
1980
|
-
if (cleanup) {
|
|
1981
|
-
cleanup();
|
|
1982
|
-
this.#hookListenerAbortCleanups.delete(callback);
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
#deleteListener(type, listener) {
|
|
1986
|
-
const removed = this.#listeners.delete(type, listener);
|
|
1987
|
-
const cleanup = this.#listenerAbortCleanups.get(listener);
|
|
1988
|
-
if (cleanup) {
|
|
1989
|
-
cleanup();
|
|
1990
|
-
this.#listenerAbortCleanups.delete(listener);
|
|
1991
|
-
}
|
|
1992
|
-
return removed;
|
|
1993
|
-
}
|
|
1994
|
-
/**
|
|
1995
|
-
* Adds a listener for the given event type.
|
|
1996
|
-
*/
|
|
1997
|
-
on(type, listener, options) {
|
|
1998
|
-
this.#addListener(type, listener, options);
|
|
1999
|
-
return this;
|
|
2000
|
-
}
|
|
2001
|
-
/**
|
|
2002
|
-
* Adds a one-time listener for the given event type.
|
|
2003
|
-
*/
|
|
2004
|
-
once(type, listener, options) {
|
|
2005
|
-
return this.on(type, listener, {
|
|
2006
|
-
...options || {},
|
|
2007
|
-
once: true
|
|
2008
|
-
});
|
|
2009
|
-
}
|
|
2010
|
-
/**
|
|
2011
|
-
* Prepends a listener for the given event type.
|
|
2012
|
-
*/
|
|
2013
|
-
earlyOn(type, listener, options) {
|
|
2014
|
-
this.#addListener(type, listener, options, "prepend");
|
|
2015
|
-
return this;
|
|
2016
|
-
}
|
|
2017
|
-
/**
|
|
2018
|
-
* Prepends a one-time listener for the given event type.
|
|
2019
|
-
*/
|
|
2020
|
-
earlyOnce(type, listener, options) {
|
|
2021
|
-
return this.earlyOn(type, listener, {
|
|
2022
|
-
...options || {},
|
|
2023
|
-
once: true
|
|
2024
|
-
});
|
|
2025
|
-
}
|
|
2026
|
-
/**
|
|
2027
|
-
* Emits the given typed event.
|
|
2028
|
-
*
|
|
2029
|
-
* @returns {boolean} Returns `true` if the event had any listeners, `false` otherwise.
|
|
2030
|
-
*/
|
|
2031
|
-
emit(event) {
|
|
2032
|
-
if (this.#listeners.size === 0) return false;
|
|
2033
|
-
const hasListeners = this.listenerCount(event.type) > 0;
|
|
2034
|
-
const proxiedEvent = this.#proxyEvent(event);
|
|
2035
|
-
for (const listener of this.#matchListeners(event.type)) {
|
|
2036
|
-
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
2037
|
-
proxiedEvent.revoke();
|
|
2038
|
-
return false;
|
|
2039
|
-
}
|
|
2040
|
-
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
2041
|
-
this.#callListener(proxiedEvent.event, listener);
|
|
2042
|
-
}
|
|
2043
|
-
proxiedEvent.revoke();
|
|
2044
|
-
return hasListeners;
|
|
2045
|
-
}
|
|
2046
|
-
/**
|
|
2047
|
-
* Emits the given typed event and returns a promise that resolves
|
|
2048
|
-
* when all the listeners for that event have settled.
|
|
2049
|
-
*
|
|
2050
|
-
* @returns {Promise<Array<Emitter.ListenerReturnType>>} A promise that resolves
|
|
2051
|
-
* with the return values of all listeners.
|
|
2052
|
-
*/
|
|
2053
|
-
async emitAsPromise(event) {
|
|
2054
|
-
if (this.#listeners.size === 0) return [];
|
|
2055
|
-
const pendingListeners = [];
|
|
2056
|
-
const proxiedEvent = this.#proxyEvent(event);
|
|
2057
|
-
for (const listener of this.#matchListeners(event.type)) {
|
|
2058
|
-
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
2059
|
-
proxiedEvent.revoke();
|
|
2060
|
-
return [];
|
|
2061
|
-
}
|
|
2062
|
-
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
2063
|
-
const returnValue = await Promise.resolve(this.#callListener(proxiedEvent.event, listener));
|
|
2064
|
-
if (!this.#isTypelessListener(listener)) pendingListeners.push(returnValue);
|
|
2065
|
-
}
|
|
2066
|
-
proxiedEvent.revoke();
|
|
2067
|
-
return Promise.allSettled(pendingListeners).then((results) => {
|
|
2068
|
-
return results.map((result) => result.status === "fulfilled" ? result.value : result.reason);
|
|
2069
|
-
});
|
|
2070
|
-
}
|
|
2071
|
-
/**
|
|
2072
|
-
* Emits the given event and returns a generator that yields
|
|
2073
|
-
* the result of each listener in the order of their registration.
|
|
2074
|
-
* This way, you stop exhausting the listeners once you get the expected value.
|
|
2075
|
-
*/
|
|
2076
|
-
*emitAsGenerator(event) {
|
|
2077
|
-
if (this.#listeners.size === 0) return;
|
|
2078
|
-
const proxiedEvent = this.#proxyEvent(event);
|
|
2079
|
-
for (const listener of this.#matchListeners(event.type)) {
|
|
2080
|
-
if (proxiedEvent.event[kPropagationStopped] != null && proxiedEvent.event[kPropagationStopped] !== this) {
|
|
2081
|
-
proxiedEvent.revoke();
|
|
2082
|
-
return;
|
|
2083
|
-
}
|
|
2084
|
-
if (proxiedEvent.event[kImmediatePropagationStopped]) break;
|
|
2085
|
-
const returnValue = this.#callListener(proxiedEvent.event, listener);
|
|
2086
|
-
if (!this.#isTypelessListener(listener)) yield returnValue;
|
|
2087
|
-
}
|
|
2088
|
-
proxiedEvent.revoke();
|
|
2089
|
-
}
|
|
2090
|
-
/**
|
|
2091
|
-
* Removes a listener for the given event type.
|
|
2092
|
-
*/
|
|
2093
|
-
removeListener(type, listener) {
|
|
2094
|
-
const options = this.#listenerOptions.get(listener);
|
|
2095
|
-
if (!this.#deleteListener(type, listener)) return;
|
|
2096
|
-
for (const hook of this.#hookListeners.get("removeListener").slice()) hook(type, listener, options);
|
|
2097
|
-
}
|
|
2098
|
-
/**
|
|
2099
|
-
* Removes all listeners for the given event type.
|
|
2100
|
-
* If no event type is provided, removes all existing listeners.
|
|
2101
|
-
*/
|
|
2102
|
-
removeAllListeners(type) {
|
|
2103
|
-
if (type == null) {
|
|
2104
|
-
for (const [listenerType, listeners$1] of this.#listeners.entries()) while (listeners$1.length > 0) this.removeListener(listenerType, listeners$1[0]);
|
|
2105
|
-
for (const [hookType, hookListener] of [...this.#hookListeners]) if (!this.#hookListenerOptions.get(hookListener)?.persist) this.#deleteHookListener(hookType, hookListener);
|
|
2106
|
-
return;
|
|
2107
|
-
}
|
|
2108
|
-
const listeners = this.listeners(type);
|
|
2109
|
-
while (listeners.length > 0) this.removeListener(type, listeners[0]);
|
|
2110
|
-
}
|
|
2111
|
-
/**
|
|
2112
|
-
* Returns the list of listeners for the given event type.
|
|
2113
|
-
* If no even type is provided, returns all listeners.
|
|
2114
|
-
*/
|
|
2115
|
-
listeners(type) {
|
|
2116
|
-
if (type == null) return this.#listeners.getAll();
|
|
2117
|
-
return this.#listeners.get(type);
|
|
2118
|
-
}
|
|
2119
|
-
/**
|
|
2120
|
-
* Returns the number of listeners for the given event type.
|
|
2121
|
-
* If no even type is provided, returns the total number of listeners.
|
|
2122
|
-
*/
|
|
2123
|
-
listenerCount(type) {
|
|
2124
|
-
if (type == null) return this.#listeners.size;
|
|
2125
|
-
return this.listeners(type).length;
|
|
2126
|
-
}
|
|
2127
|
-
#addListener(type, listener, options, insertMode = "append") {
|
|
2128
|
-
if (options?.signal?.aborted) return;
|
|
2129
|
-
for (const hook of this.#hookListeners.get("newListener").slice()) hook(type, listener, options);
|
|
2130
|
-
if (type === "*") this.#typelessListeners.add(listener);
|
|
2131
|
-
if (insertMode === "prepend") this.#listeners.prepend(type, listener);
|
|
2132
|
-
else this.#listeners.append(type, listener);
|
|
2133
|
-
if (options) {
|
|
2134
|
-
this.#listenerOptions.set(listener, options);
|
|
2135
|
-
if (options.signal) {
|
|
2136
|
-
const { signal } = options;
|
|
2137
|
-
const onAbort = () => {
|
|
2138
|
-
this.removeListener(type, listener);
|
|
2139
|
-
};
|
|
2140
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
2141
|
-
this.#listenerAbortCleanups.set(listener, () => {
|
|
2142
|
-
signal.removeEventListener("abort", onAbort);
|
|
2143
|
-
});
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
#proxyEvent(event) {
|
|
2148
|
-
const { stopPropagation } = event;
|
|
2149
|
-
event.stopPropagation = () => {
|
|
2150
|
-
event[kPropagationStopped] = this;
|
|
2151
|
-
stopPropagation.call(event);
|
|
2152
|
-
};
|
|
2153
|
-
return {
|
|
2154
|
-
event,
|
|
2155
|
-
revoke() {
|
|
2156
|
-
event.stopPropagation = stopPropagation;
|
|
2157
|
-
}
|
|
2158
|
-
};
|
|
2159
|
-
}
|
|
2160
|
-
#callListener(event, listener) {
|
|
2161
|
-
for (const hook of this.#hookListeners.get("beforeEmit").slice()) if (hook(event) === false) return;
|
|
2162
|
-
const returnValue = listener.call(this, event);
|
|
2163
|
-
const options = this.#listenerOptions.get(listener);
|
|
2164
|
-
if (options?.once) {
|
|
2165
|
-
const type = this.#isTypelessListener(listener) ? "*" : event.type;
|
|
2166
|
-
if (this.#deleteListener(type, listener)) for (const hook of this.#hookListeners.get("removeListener").slice()) hook(type, listener, options);
|
|
2167
|
-
}
|
|
2168
|
-
return returnValue;
|
|
2169
|
-
}
|
|
2170
|
-
/**
|
|
2171
|
-
* Return a list of all event listeners relevant for the given event type.
|
|
2172
|
-
* This includes the explicit event listeners and also typeless event listeners.
|
|
2173
|
-
*
|
|
2174
|
-
* @note Snapshot the matching listeners before yielding. Listeners can add or
|
|
2175
|
-
* remove other listeners during emission (e.g. `earlyOn` unshifts `#list`),
|
|
2176
|
-
* which would otherwise shift the live iterator and re-yield prior entries.
|
|
2177
|
-
*/
|
|
2178
|
-
*#matchListeners(type) {
|
|
2179
|
-
const snapshot = [];
|
|
2180
|
-
for (const [key, listener] of this.#listeners) if (key === "*" || key === type) snapshot.push(listener);
|
|
2181
|
-
yield* snapshot;
|
|
2182
|
-
}
|
|
2183
|
-
#isTypelessListener(listener) {
|
|
2184
|
-
return this.#typelessListeners.has(listener);
|
|
2185
|
-
}
|
|
2186
|
-
};
|
|
2187
|
-
|
|
2188
|
-
// src/browser/utils/workerChannel.ts
|
|
2189
|
-
var import_isObject = require("../core/utils/internal/isObject");
|
|
2190
|
-
var SUPPORTS_SERVICE_WORKER = supportsServiceWorker();
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/browser/utils/worker-channel.ts
|
|
106
|
+
const SUPPORTS_SERVICE_WORKER = supportsServiceWorker();
|
|
2191
107
|
var WorkerEvent = class extends TypedEvent {
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
/**
|
|
2257
|
-
* Terminal teardown. Removes the `navigator.serviceWorker` message listener
|
|
2258
|
-
* and all emitter subscriptions. The channel is not usable afterwards.
|
|
2259
|
-
*/
|
|
2260
|
-
terminate() {
|
|
2261
|
-
this.#controller.abort();
|
|
2262
|
-
this.removeAllListeners();
|
|
2263
|
-
}
|
|
2264
|
-
};
|
|
2265
|
-
|
|
2266
|
-
// src/browser/utils/pruneGetRequestBody.ts
|
|
2267
|
-
function pruneGetRequestBody(request) {
|
|
2268
|
-
if (["HEAD", "GET"].includes(request.method)) {
|
|
2269
|
-
return void 0;
|
|
2270
|
-
}
|
|
2271
|
-
return request.body;
|
|
2272
|
-
}
|
|
2273
|
-
|
|
2274
|
-
// src/browser/utils/deserializeRequest.ts
|
|
108
|
+
#workerEvent;
|
|
109
|
+
constructor(workerEvent) {
|
|
110
|
+
const type = workerEvent.data.type;
|
|
111
|
+
const data = workerEvent.data.payload;
|
|
112
|
+
/**
|
|
113
|
+
* @note This is the only place we're mapping { type, payload }
|
|
114
|
+
* message structure of the worker. The client references the
|
|
115
|
+
* payload via `event.data`.
|
|
116
|
+
*/
|
|
117
|
+
super(type, { data });
|
|
118
|
+
this.#workerEvent = workerEvent;
|
|
119
|
+
}
|
|
120
|
+
get ports() {
|
|
121
|
+
return this.#workerEvent.ports;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Reply directly to this event using its `MessagePort`.
|
|
125
|
+
*/
|
|
126
|
+
postMessage(type, ...rest) {
|
|
127
|
+
this.#workerEvent.ports[0].postMessage({
|
|
128
|
+
type,
|
|
129
|
+
data: rest[0]
|
|
130
|
+
}, { transfer: rest[1] });
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var WorkerChannel = class extends Emitter {
|
|
134
|
+
#getWorker;
|
|
135
|
+
#controller;
|
|
136
|
+
constructor(options) {
|
|
137
|
+
super();
|
|
138
|
+
invariant(SUPPORTS_SERVICE_WORKER, "Failed to open a WorkerChannel: Service Worker is not supported in this environment.");
|
|
139
|
+
this.#getWorker = options.getWorker;
|
|
140
|
+
this.#controller = new AbortController();
|
|
141
|
+
navigator.serviceWorker.addEventListener("message", async (event) => {
|
|
142
|
+
const worker = await this.#getWorker();
|
|
143
|
+
if (event.source != null && event.source !== worker) return;
|
|
144
|
+
if (event.data && isObject(event.data) && "type" in event.data) this.emit(new WorkerEvent(event));
|
|
145
|
+
}, { signal: this.#controller.signal });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Send data to the Service Worker controlling this client.
|
|
149
|
+
* This triggers the `message` event listener on ServiceWorkerGlobalScope.
|
|
150
|
+
*/
|
|
151
|
+
postMessage(type) {
|
|
152
|
+
invariant(SUPPORTS_SERVICE_WORKER, "Failed to post message on a WorkerChannel: the Service Worker API is unavailable in this environment. This is likely an issue with MSW. Please report it on GitHub: https://github.com/mswjs/msw/issues");
|
|
153
|
+
this.#getWorker().then((worker) => {
|
|
154
|
+
worker.postMessage(type);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Terminal teardown. Removes the `navigator.serviceWorker` message listener
|
|
159
|
+
* and all emitter subscriptions. The channel is not usable afterwards.
|
|
160
|
+
*/
|
|
161
|
+
terminate() {
|
|
162
|
+
this.#controller.abort();
|
|
163
|
+
this.removeAllListeners();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/browser/utils/deserialize-request.ts
|
|
168
|
+
/**
|
|
169
|
+
* Converts a given request received from the Service Worker
|
|
170
|
+
* into a Fetch `Request` instance.
|
|
171
|
+
*/
|
|
2275
172
|
function deserializeRequest(serializedRequest) {
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
173
|
+
return new FetchRequest(serializedRequest.url, { ...serializedRequest });
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/browser/utils/validate-worker-scope.ts
|
|
177
|
+
/**
|
|
178
|
+
* Print a warning if the given Service Worker registration has a scope
|
|
179
|
+
* outside of the current page's location. That is to help with debugging
|
|
180
|
+
* issues caused by the incorrectly registered Service Worker.
|
|
181
|
+
*/
|
|
2284
182
|
function validateWorkerScope(registration) {
|
|
2285
|
-
|
|
2286
|
-
import_devUtils2.devUtils.warn(
|
|
2287
|
-
`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.
|
|
183
|
+
if (!location.href.startsWith(registration.scope)) devUtils.warn(`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.
|
|
2288
184
|
|
|
2289
185
|
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
2290
|
-
- Set the "Service-Worker-Allowed" response header to allow out-of-scope workers.`
|
|
2291
|
-
);
|
|
2292
|
-
}
|
|
186
|
+
- Set the "Service-Worker-Allowed" response header to allow out-of-scope workers.`);
|
|
2293
187
|
}
|
|
2294
|
-
|
|
2295
|
-
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/browser/utils/should-invalidate-worker.ts
|
|
2296
190
|
function shouldInvalidateWorker(prevOptions, nextOptions) {
|
|
2297
|
-
|
|
2298
|
-
}
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
var ServiceWorkerSource = class
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
await registration.unregister();
|
|
2410
|
-
}
|
|
2411
|
-
if (_ServiceWorkerSource.#current === this) {
|
|
2412
|
-
_ServiceWorkerSource.#current = void 0;
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
async #startWorker() {
|
|
2416
|
-
if (this.#keepAliveInterval) {
|
|
2417
|
-
clearInterval(this.#keepAliveInterval);
|
|
2418
|
-
}
|
|
2419
|
-
const workerUrl = this.#options.serviceWorker.url;
|
|
2420
|
-
const [worker, registration] = await getWorkerInstance(
|
|
2421
|
-
workerUrl,
|
|
2422
|
-
this.#options.serviceWorker.options,
|
|
2423
|
-
this.#options.findWorker || this.#defaultFindWorker
|
|
2424
|
-
);
|
|
2425
|
-
if (worker == null) {
|
|
2426
|
-
const missingWorkerMessage = this.#options?.findWorker ? import_devUtils3.devUtils.formatMessage(
|
|
2427
|
-
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
191
|
+
return prevOptions.findWorker !== nextOptions.findWorker || prevOptions.serviceWorker.url !== nextOptions.serviceWorker.url || JSON.stringify(prevOptions.serviceWorker.options) !== JSON.stringify(nextOptions.serviceWorker.options);
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/browser/sources/service-worker-source.ts
|
|
195
|
+
var ServiceWorkerSource = class ServiceWorkerSource extends NetworkSource {
|
|
196
|
+
static #current;
|
|
197
|
+
/**
|
|
198
|
+
* Create a new Service Worker source or reuse an existing one.
|
|
199
|
+
* These sources act as a singleton and only get recreated if the options change.
|
|
200
|
+
*/
|
|
201
|
+
static async from(options) {
|
|
202
|
+
if (ServiceWorkerSource.#current == null) ServiceWorkerSource.#current = new ServiceWorkerSource(options);
|
|
203
|
+
else if (shouldInvalidateWorker(ServiceWorkerSource.#current.#options, options)) {
|
|
204
|
+
await ServiceWorkerSource.#current.terminate();
|
|
205
|
+
ServiceWorkerSource.#current = new ServiceWorkerSource(options);
|
|
206
|
+
}
|
|
207
|
+
return ServiceWorkerSource.#current;
|
|
208
|
+
}
|
|
209
|
+
#options;
|
|
210
|
+
/**
|
|
211
|
+
* @note We cannot use `WeakMap` here as request/response
|
|
212
|
+
* identity cannot be preserved through the client-worker channel.
|
|
213
|
+
*/
|
|
214
|
+
#frames;
|
|
215
|
+
#channel;
|
|
216
|
+
#listenerController;
|
|
217
|
+
#clientPromise;
|
|
218
|
+
#keepAliveInterval;
|
|
219
|
+
workerPromise;
|
|
220
|
+
#workerResolvers;
|
|
221
|
+
#workerState;
|
|
222
|
+
constructor(options) {
|
|
223
|
+
super();
|
|
224
|
+
invariant(supportsServiceWorker(), "Failed to use Service Worker as the network source: the Service Worker API is not supported in this environment");
|
|
225
|
+
this.#options = options;
|
|
226
|
+
this.#frames = /* @__PURE__ */ new Map();
|
|
227
|
+
this.#workerResolvers = Promise.withResolvers();
|
|
228
|
+
this.workerPromise = this.#workerResolvers.promise;
|
|
229
|
+
this.#workerState = "pending";
|
|
230
|
+
this.#channel = new WorkerChannel({ getWorker: () => this.workerPromise.then(([worker]) => worker) });
|
|
231
|
+
}
|
|
232
|
+
async enable() {
|
|
233
|
+
this.#channel.removeAllListeners();
|
|
234
|
+
this.#frames.clear();
|
|
235
|
+
this.#listenerController = new AbortController();
|
|
236
|
+
const [worker, registration] = await this.#startWorker();
|
|
237
|
+
if (worker.state !== "activated") {
|
|
238
|
+
const controller = new AbortController();
|
|
239
|
+
const activationPromise = Promise.withResolvers();
|
|
240
|
+
activationPromise.promise.then(() => controller.abort());
|
|
241
|
+
worker.addEventListener("statechange", () => {
|
|
242
|
+
if (worker.state === "activated") activationPromise.resolve();
|
|
243
|
+
}, { signal: controller.signal });
|
|
244
|
+
await activationPromise.promise;
|
|
245
|
+
}
|
|
246
|
+
this.#channel.postMessage("MOCK_ACTIVATE");
|
|
247
|
+
const clientConfirmationPromise = Promise.withResolvers();
|
|
248
|
+
this.#clientPromise = clientConfirmationPromise.promise;
|
|
249
|
+
this.#channel.once("MOCKING_ENABLED", (event) => {
|
|
250
|
+
clientConfirmationPromise.resolve(event.data.client);
|
|
251
|
+
});
|
|
252
|
+
await clientConfirmationPromise.promise;
|
|
253
|
+
if (!this.#options.quiet) this.#printStartMessage();
|
|
254
|
+
return registration;
|
|
255
|
+
}
|
|
256
|
+
async disable() {
|
|
257
|
+
/**
|
|
258
|
+
* @note Do NOT call `super.disable()` because it removes any "frame" listeners
|
|
259
|
+
* from this network source, effectively turning it off. The Service Worker source
|
|
260
|
+
* is a bit special since it might process in-flight requests that have been performed
|
|
261
|
+
* after it's been disabled.
|
|
262
|
+
*/
|
|
263
|
+
this.#listenerController?.abort();
|
|
264
|
+
this.#listenerController = void 0;
|
|
265
|
+
const closedPromise = Promise.withResolvers();
|
|
266
|
+
this.#channel.once("CLIENT_CLOSED", () => closedPromise.resolve());
|
|
267
|
+
this.#channel.postMessage("CLIENT_CLOSE");
|
|
268
|
+
await closedPromise.promise;
|
|
269
|
+
/**
|
|
270
|
+
* @note Do NOT reset `workerPromise` here. The channel must continue to
|
|
271
|
+
* resolve the currently registered SW so that any in-flight requests the
|
|
272
|
+
* worker forwards after `stop()` can be answered with `PASSTHROUGH` by
|
|
273
|
+
* `#handleRequest`. `#startWorker` swaps in a fresh deferred on re-enable.
|
|
274
|
+
*/
|
|
275
|
+
if (!this.#options.quiet) this.#printStopMessage();
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Terminal teardown. Unregisters the Service Worker, tears down the channel,
|
|
279
|
+
* and clears timers. Called when the singleton is being replaced with one
|
|
280
|
+
* that has different options. The instance is not usable afterwards.
|
|
281
|
+
*/
|
|
282
|
+
async terminate() {
|
|
283
|
+
if (this.#keepAliveInterval != null) {
|
|
284
|
+
clearInterval(this.#keepAliveInterval);
|
|
285
|
+
this.#keepAliveInterval = void 0;
|
|
286
|
+
}
|
|
287
|
+
this.#frames.clear();
|
|
288
|
+
this.#channel.terminate();
|
|
289
|
+
this.#listenerController?.abort();
|
|
290
|
+
this.#listenerController = void 0;
|
|
291
|
+
if (this.#workerState === "fulfilled") {
|
|
292
|
+
const [, registration] = await this.workerPromise;
|
|
293
|
+
await registration.unregister();
|
|
294
|
+
}
|
|
295
|
+
if (ServiceWorkerSource.#current === this) ServiceWorkerSource.#current = void 0;
|
|
296
|
+
}
|
|
297
|
+
async #startWorker() {
|
|
298
|
+
if (this.#keepAliveInterval) clearInterval(this.#keepAliveInterval);
|
|
299
|
+
const workerUrl = this.#options.serviceWorker.url;
|
|
300
|
+
const [worker, registration] = await getWorkerInstance(workerUrl, this.#options.serviceWorker.options, this.#options.findWorker || this.#defaultFindWorker);
|
|
301
|
+
if (worker == null) {
|
|
302
|
+
const missingWorkerMessage = this.#options?.findWorker ? devUtils.formatMessage(`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
2428
303
|
|
|
2429
304
|
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
2430
305
|
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
2431
|
-
`,
|
|
2432
|
-
workerUrl
|
|
2433
|
-
) : import_devUtils3.devUtils.formatMessage(
|
|
2434
|
-
`Failed to locate the Service Worker registration.
|
|
306
|
+
`, workerUrl) : devUtils.formatMessage(`Failed to locate the Service Worker registration.
|
|
2435
307
|
|
|
2436
308
|
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.
|
|
2437
309
|
|
|
2438
|
-
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`,
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
310
|
+
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`, workerUrl, location.host);
|
|
311
|
+
throw new Error(missingWorkerMessage);
|
|
312
|
+
}
|
|
313
|
+
if (this.#workerState === "pending") {
|
|
314
|
+
this.#workerResolvers.resolve([worker, registration]);
|
|
315
|
+
this.#workerState = "fulfilled";
|
|
316
|
+
} else {
|
|
317
|
+
/**
|
|
318
|
+
* @note Re-enable after `stop()`: the previous `workerPromise` is already
|
|
319
|
+
* fulfilled and cannot be resolved again. Swap in a pre-resolved one so
|
|
320
|
+
* `getWorker()` sees the new worker instance immediately.
|
|
321
|
+
*/
|
|
322
|
+
this.#workerResolvers = Promise.withResolvers();
|
|
323
|
+
this.#workerResolvers.resolve([worker, registration]);
|
|
324
|
+
this.workerPromise = this.#workerResolvers.promise;
|
|
325
|
+
}
|
|
326
|
+
this.#channel.on("REQUEST", this.#handleRequest.bind(this));
|
|
327
|
+
this.#channel.on("RESPONSE", this.#handleResponse.bind(this));
|
|
328
|
+
this.#channel.on("REQUEST_ERROR", this.#handleRequestError.bind(this));
|
|
329
|
+
window.addEventListener("pagehide", (event) => {
|
|
330
|
+
if (event.persisted) return;
|
|
331
|
+
if (worker.state !== "redundant") this.#channel.postMessage("CLIENT_CLOSE");
|
|
332
|
+
clearInterval(this.#keepAliveInterval);
|
|
333
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
334
|
+
}, { signal: this.#listenerController?.signal });
|
|
335
|
+
await this.#checkWorkerIntegrity().catch((error) => {
|
|
336
|
+
devUtils.error("Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below.");
|
|
337
|
+
console.error(error);
|
|
338
|
+
});
|
|
339
|
+
this.#keepAliveInterval = window.setInterval(() => {
|
|
340
|
+
this.#channel.postMessage("KEEPALIVE_REQUEST");
|
|
341
|
+
}, 5e3);
|
|
342
|
+
if (!this.#options.quiet) validateWorkerScope(registration);
|
|
343
|
+
return [worker, registration];
|
|
344
|
+
}
|
|
345
|
+
async #handleRequest(event) {
|
|
346
|
+
const request = deserializeRequest(event.data);
|
|
347
|
+
RequestHandler.cache.set(request, request.clone());
|
|
348
|
+
const frame = new ServiceWorkerHttpNetworkFrame({
|
|
349
|
+
event,
|
|
350
|
+
request
|
|
351
|
+
});
|
|
352
|
+
this.#frames.set(event.data.id, frame);
|
|
353
|
+
await this.queue(frame);
|
|
354
|
+
}
|
|
355
|
+
async #handleResponse(event) {
|
|
356
|
+
const { request, response, isMockedResponse } = event.data;
|
|
357
|
+
const frame = this.#frames.get(request.id);
|
|
358
|
+
/**
|
|
359
|
+
* CORS requests with `mode: "no-cors"` result in "opaque" responses.
|
|
360
|
+
* That kind of responses cannot be manipulated in JavaScript due
|
|
361
|
+
* to the security considerations.
|
|
362
|
+
* @see https://fetch.spec.whatwg.org/#concept-filtered-response-opaque
|
|
363
|
+
* @see https://github.com/mswjs/msw/issues/529
|
|
364
|
+
*/
|
|
365
|
+
if (response.type?.includes("opaque")) {
|
|
366
|
+
this.#frames.delete(request.id);
|
|
367
|
+
frame?.events.removeAllListeners();
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
this.#frames.delete(request.id);
|
|
371
|
+
/**
|
|
372
|
+
* @note A request frame will be missing in case of passthrough after the worker is stopped.
|
|
373
|
+
* Creating a frame is costly so it's better to handle it as an edge case here.
|
|
374
|
+
*/
|
|
375
|
+
if (frame == null) return;
|
|
376
|
+
const fetchRequest = deserializeRequest(request);
|
|
377
|
+
const fetchResponse = response.status === 0 ? Response.error() : new FetchResponse(
|
|
378
|
+
/**
|
|
379
|
+
* Responses may be streams here, but when we create a response object
|
|
380
|
+
* with null-body status codes, like 204, 205, 304 Response will
|
|
381
|
+
* throw when passed a non-null body, so ensure it's null here
|
|
382
|
+
* for those codes
|
|
383
|
+
*/
|
|
384
|
+
FetchResponse.isResponseWithBody(response.status) ? response.body : null,
|
|
385
|
+
{
|
|
386
|
+
...response,
|
|
387
|
+
/**
|
|
388
|
+
* Set response URL if it's not set already.
|
|
389
|
+
* @see https://github.com/mswjs/msw/issues/2030
|
|
390
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
|
|
391
|
+
*/
|
|
392
|
+
url: request.url
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
try {
|
|
396
|
+
frame.events.emit(new ResponseEvent(isMockedResponse ? "response:mocked" : "response:bypass", {
|
|
397
|
+
requestId: frame.data.id,
|
|
398
|
+
request: fetchRequest,
|
|
399
|
+
response: fetchResponse,
|
|
400
|
+
isMockedResponse
|
|
401
|
+
}));
|
|
402
|
+
} finally {
|
|
403
|
+
frame.events.removeAllListeners();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* @note A request can settle without ever producing a response
|
|
408
|
+
* (e.g. a passthrough request failing with a network error).
|
|
409
|
+
* The worker never sends the "RESPONSE" message for such requests,
|
|
410
|
+
* so the frame must be released here to prevent it from being retained.
|
|
411
|
+
* No "response:*" event is emitted, consistent with the Node.js source.
|
|
412
|
+
* @see https://github.com/mswjs/msw/issues/2792
|
|
413
|
+
*/
|
|
414
|
+
#handleRequestError(event) {
|
|
415
|
+
const { request } = event.data;
|
|
416
|
+
const frame = this.#frames.get(request.id);
|
|
417
|
+
this.#frames.delete(request.id);
|
|
418
|
+
frame?.events.removeAllListeners();
|
|
419
|
+
}
|
|
420
|
+
#defaultFindWorker = (workerUrl, mockServiceWorkerUrl) => {
|
|
421
|
+
return workerUrl === mockServiceWorkerUrl;
|
|
422
|
+
};
|
|
423
|
+
async #checkWorkerIntegrity() {
|
|
424
|
+
const integrityCheckPromise = Promise.withResolvers();
|
|
425
|
+
this.#channel.postMessage("INTEGRITY_CHECK_REQUEST");
|
|
426
|
+
this.#channel.once("INTEGRITY_CHECK_RESPONSE", (event) => {
|
|
427
|
+
const { checksum, packageVersion } = event.data;
|
|
428
|
+
if (checksum !== "5cd5cf8b54c3a90f82960cedcd637772") devUtils.warn(`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.
|
|
2551
429
|
|
|
2552
430
|
It's recommended you update your worker script by running this command:
|
|
2553
431
|
|
|
2554
432
|
\u2022 npx msw init <PUBLIC_DIR>
|
|
2555
433
|
|
|
2556
|
-
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.`
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
);
|
|
2653
|
-
}
|
|
2654
|
-
};
|
|
2655
|
-
|
|
2656
|
-
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
2657
|
-
var until2 = async (promise) => {
|
|
2658
|
-
try {
|
|
2659
|
-
const data = await promise().catch((error2) => {
|
|
2660
|
-
throw error2;
|
|
2661
|
-
});
|
|
2662
|
-
return { error: null, data };
|
|
2663
|
-
} catch (error2) {
|
|
2664
|
-
return { error: error2, data: null };
|
|
2665
|
-
}
|
|
2666
|
-
};
|
|
2667
|
-
|
|
2668
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/handleRequest-CPPgsG7s.mjs
|
|
2669
|
-
function isObject2(value, loose = false) {
|
|
2670
|
-
return loose ? Object.prototype.toString.call(value).startsWith("[object ") : Object.prototype.toString.call(value) === "[object Object]";
|
|
2671
|
-
}
|
|
2672
|
-
function isPropertyAccessible(obj, key) {
|
|
2673
|
-
try {
|
|
2674
|
-
obj[key];
|
|
2675
|
-
return true;
|
|
2676
|
-
} catch {
|
|
2677
|
-
return false;
|
|
2678
|
-
}
|
|
2679
|
-
}
|
|
2680
|
-
function createServerErrorResponse(body) {
|
|
2681
|
-
return new Response(JSON.stringify(body instanceof Error ? {
|
|
2682
|
-
name: body.name,
|
|
2683
|
-
message: body.message,
|
|
2684
|
-
stack: body.stack
|
|
2685
|
-
} : body), {
|
|
2686
|
-
status: 500,
|
|
2687
|
-
statusText: "Unhandled Exception",
|
|
2688
|
-
headers: { "Content-Type": "application/json" }
|
|
2689
|
-
});
|
|
2690
|
-
}
|
|
2691
|
-
function isResponseError(response) {
|
|
2692
|
-
return response != null && response instanceof Response && isPropertyAccessible(response, "type") && response.type === "error";
|
|
2693
|
-
}
|
|
2694
|
-
function isResponseLike(value) {
|
|
2695
|
-
return isObject2(value, true) && isPropertyAccessible(value, "status") && isPropertyAccessible(value, "statusText") && isPropertyAccessible(value, "bodyUsed");
|
|
2696
|
-
}
|
|
2697
|
-
function isNodeLikeError(error2) {
|
|
2698
|
-
if (error2 == null) return false;
|
|
2699
|
-
if (!(error2 instanceof Error)) return false;
|
|
2700
|
-
return "code" in error2 && "errno" in error2;
|
|
2701
|
-
}
|
|
2702
|
-
async function handleRequest(options) {
|
|
2703
|
-
const handleResponse = async (response) => {
|
|
2704
|
-
if (response instanceof Error) {
|
|
2705
|
-
await options.controller.errorWith(response);
|
|
2706
|
-
return true;
|
|
2707
|
-
}
|
|
2708
|
-
if (isResponseError(response)) {
|
|
2709
|
-
await options.controller.respondWith(response);
|
|
2710
|
-
return true;
|
|
2711
|
-
}
|
|
2712
|
-
if (isResponseLike(response)) {
|
|
2713
|
-
await options.controller.respondWith(response);
|
|
2714
|
-
return true;
|
|
2715
|
-
}
|
|
2716
|
-
if (isObject2(response)) {
|
|
2717
|
-
await options.controller.errorWith(response);
|
|
2718
|
-
return true;
|
|
2719
|
-
}
|
|
2720
|
-
return false;
|
|
2721
|
-
};
|
|
2722
|
-
const handleResponseError = async (error2) => {
|
|
2723
|
-
if (error2 instanceof InterceptorError) throw result.error;
|
|
2724
|
-
if (isNodeLikeError(error2)) {
|
|
2725
|
-
await options.controller.errorWith(error2);
|
|
2726
|
-
return true;
|
|
2727
|
-
}
|
|
2728
|
-
if (error2 instanceof Response) return await handleResponse(error2);
|
|
2729
|
-
return false;
|
|
2730
|
-
};
|
|
2731
|
-
const requestAbortPromise = new DeferredPromise();
|
|
2732
|
-
const onAbort = () => {
|
|
2733
|
-
requestAbortPromise.reject(options.request.signal?.reason);
|
|
2734
|
-
};
|
|
2735
|
-
if (options.request.signal) {
|
|
2736
|
-
if (options.request.signal.aborted) {
|
|
2737
|
-
await options.controller.errorWith(options.request.signal.reason);
|
|
2738
|
-
return;
|
|
2739
|
-
}
|
|
2740
|
-
options.request.signal.addEventListener("abort", onAbort, { once: true });
|
|
2741
|
-
}
|
|
2742
|
-
const result = await until2(async () => {
|
|
2743
|
-
const requestListenersPromise = emitAsync(options.emitter, "request", {
|
|
2744
|
-
requestId: options.requestId,
|
|
2745
|
-
request: options.request,
|
|
2746
|
-
controller: options.controller
|
|
2747
|
-
});
|
|
2748
|
-
await Promise.race([
|
|
2749
|
-
requestAbortPromise,
|
|
2750
|
-
requestListenersPromise,
|
|
2751
|
-
options.controller.handled
|
|
2752
|
-
]);
|
|
2753
|
-
});
|
|
2754
|
-
options.request.signal?.removeEventListener("abort", onAbort);
|
|
2755
|
-
if (requestAbortPromise.state === "rejected") {
|
|
2756
|
-
await options.controller.errorWith(requestAbortPromise.rejectionReason);
|
|
2757
|
-
return;
|
|
2758
|
-
}
|
|
2759
|
-
if (result.error) {
|
|
2760
|
-
if (await handleResponseError(result.error)) return;
|
|
2761
|
-
if (options.emitter.listenerCount("unhandledException") > 0) {
|
|
2762
|
-
const unhandledExceptionController = new RequestController(options.request, {
|
|
2763
|
-
passthrough() {
|
|
2764
|
-
},
|
|
2765
|
-
async respondWith(response) {
|
|
2766
|
-
await handleResponse(response);
|
|
2767
|
-
},
|
|
2768
|
-
async errorWith(reason) {
|
|
2769
|
-
await options.controller.errorWith(reason);
|
|
2770
|
-
}
|
|
2771
|
-
});
|
|
2772
|
-
await emitAsync(options.emitter, "unhandledException", {
|
|
2773
|
-
error: result.error,
|
|
2774
|
-
request: options.request,
|
|
2775
|
-
requestId: options.requestId,
|
|
2776
|
-
controller: unhandledExceptionController
|
|
2777
|
-
});
|
|
2778
|
-
if (unhandledExceptionController.readyState !== RequestController.PENDING) return;
|
|
2779
|
-
}
|
|
2780
|
-
await options.controller.respondWith(createServerErrorResponse(result.error));
|
|
2781
|
-
return;
|
|
2782
|
-
}
|
|
2783
|
-
if (options.controller.readyState === RequestController.PENDING) return await options.controller.passthrough();
|
|
2784
|
-
return options.controller.handled;
|
|
2785
|
-
}
|
|
2786
|
-
|
|
2787
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/fetch-5IMPqr9e.mjs
|
|
2788
|
-
function createNetworkError(cause) {
|
|
2789
|
-
return Object.assign(/* @__PURE__ */ new TypeError("Failed to fetch"), { cause });
|
|
2790
|
-
}
|
|
2791
|
-
var REQUEST_BODY_HEADERS = [
|
|
2792
|
-
"content-encoding",
|
|
2793
|
-
"content-language",
|
|
2794
|
-
"content-location",
|
|
2795
|
-
"content-type",
|
|
2796
|
-
"content-length"
|
|
2797
|
-
];
|
|
2798
|
-
var kRedirectCount = /* @__PURE__ */ Symbol("kRedirectCount");
|
|
2799
|
-
async function followFetchRedirect(request, response) {
|
|
2800
|
-
if (response.status !== 303 && request.body != null) return Promise.reject(createNetworkError());
|
|
2801
|
-
const requestUrl = new URL(request.url);
|
|
2802
|
-
let locationUrl;
|
|
2803
|
-
try {
|
|
2804
|
-
locationUrl = new URL(response.headers.get("location"), request.url);
|
|
2805
|
-
} catch (error2) {
|
|
2806
|
-
return Promise.reject(createNetworkError(error2));
|
|
2807
|
-
}
|
|
2808
|
-
if (!(locationUrl.protocol === "http:" || locationUrl.protocol === "https:")) return Promise.reject(createNetworkError("URL scheme must be a HTTP(S) scheme"));
|
|
2809
|
-
if (Reflect.get(request, kRedirectCount) > 20) return Promise.reject(createNetworkError("redirect count exceeded"));
|
|
2810
|
-
Object.defineProperty(request, kRedirectCount, { value: (Reflect.get(request, kRedirectCount) || 0) + 1 });
|
|
2811
|
-
if (request.mode === "cors" && (locationUrl.username || locationUrl.password) && !sameOrigin(requestUrl, locationUrl)) return Promise.reject(createNetworkError('cross origin not allowed for request mode "cors"'));
|
|
2812
|
-
const requestInit = {};
|
|
2813
|
-
if ([301, 302].includes(response.status) && request.method === "POST" || response.status === 303 && !["HEAD", "GET"].includes(request.method)) {
|
|
2814
|
-
requestInit.method = "GET";
|
|
2815
|
-
requestInit.body = null;
|
|
2816
|
-
REQUEST_BODY_HEADERS.forEach((headerName) => {
|
|
2817
|
-
request.headers.delete(headerName);
|
|
2818
|
-
});
|
|
2819
|
-
}
|
|
2820
|
-
if (!sameOrigin(requestUrl, locationUrl)) {
|
|
2821
|
-
request.headers.delete("authorization");
|
|
2822
|
-
request.headers.delete("proxy-authorization");
|
|
2823
|
-
request.headers.delete("cookie");
|
|
2824
|
-
request.headers.delete("host");
|
|
2825
|
-
}
|
|
2826
|
-
requestInit.headers = request.headers;
|
|
2827
|
-
const finalResponse = await fetch(new Request(locationUrl, requestInit));
|
|
2828
|
-
Object.defineProperty(finalResponse, "redirected", {
|
|
2829
|
-
value: true,
|
|
2830
|
-
configurable: true
|
|
2831
|
-
});
|
|
2832
|
-
return finalResponse;
|
|
2833
|
-
}
|
|
2834
|
-
function sameOrigin(left, right) {
|
|
2835
|
-
if (left.origin === right.origin && left.origin === "null") return true;
|
|
2836
|
-
if (left.protocol === right.protocol && left.hostname === right.hostname && left.port === right.port) return true;
|
|
2837
|
-
return false;
|
|
2838
|
-
}
|
|
2839
|
-
var BrotliDecompressionStream = class extends TransformStream {
|
|
2840
|
-
constructor() {
|
|
2841
|
-
console.warn("[Interceptors]: Brotli decompression of response streams is not supported in the browser");
|
|
2842
|
-
super({ transform(chunk, controller) {
|
|
2843
|
-
controller.enqueue(chunk);
|
|
2844
|
-
} });
|
|
2845
|
-
}
|
|
2846
|
-
};
|
|
2847
|
-
var PipelineStream = class extends TransformStream {
|
|
2848
|
-
constructor(transformStreams, ...strategies) {
|
|
2849
|
-
super({}, ...strategies);
|
|
2850
|
-
const readable = [super.readable, ...transformStreams].reduce((readable$1, transform) => readable$1.pipeThrough(transform));
|
|
2851
|
-
Object.defineProperty(this, "readable", { get() {
|
|
2852
|
-
return readable;
|
|
2853
|
-
} });
|
|
2854
|
-
}
|
|
2855
|
-
};
|
|
2856
|
-
function parseContentEncoding(contentEncoding) {
|
|
2857
|
-
return contentEncoding.toLowerCase().split(",").map((coding) => coding.trim());
|
|
2858
|
-
}
|
|
2859
|
-
function createDecompressionStream(contentEncoding) {
|
|
2860
|
-
if (contentEncoding === "") return null;
|
|
2861
|
-
const codings = parseContentEncoding(contentEncoding);
|
|
2862
|
-
if (codings.length === 0) return null;
|
|
2863
|
-
return new PipelineStream(codings.reduceRight((transformers, coding) => {
|
|
2864
|
-
if (coding === "gzip" || coding === "x-gzip") return transformers.concat(new DecompressionStream("gzip"));
|
|
2865
|
-
else if (coding === "deflate") return transformers.concat(new DecompressionStream("deflate"));
|
|
2866
|
-
else if (coding === "br") return transformers.concat(new BrotliDecompressionStream());
|
|
2867
|
-
else transformers.length = 0;
|
|
2868
|
-
return transformers;
|
|
2869
|
-
}, []));
|
|
2870
|
-
}
|
|
2871
|
-
function decompressResponse(response) {
|
|
2872
|
-
if (response.body === null) return null;
|
|
2873
|
-
const decompressionStream = createDecompressionStream(response.headers.get("content-encoding") || "");
|
|
2874
|
-
if (!decompressionStream) return null;
|
|
2875
|
-
response.body.pipeTo(decompressionStream.writable);
|
|
2876
|
-
return decompressionStream.readable;
|
|
2877
|
-
}
|
|
2878
|
-
var FetchInterceptor = class FetchInterceptor2 extends Interceptor {
|
|
2879
|
-
static {
|
|
2880
|
-
this.symbol = /* @__PURE__ */ Symbol.for("fetch-interceptor");
|
|
2881
|
-
}
|
|
2882
|
-
constructor() {
|
|
2883
|
-
super(FetchInterceptor2.symbol);
|
|
2884
|
-
}
|
|
2885
|
-
checkEnvironment() {
|
|
2886
|
-
return hasConfigurableGlobal("fetch");
|
|
2887
|
-
}
|
|
2888
|
-
async setup() {
|
|
2889
|
-
const logger = this.logger.extend("setup");
|
|
2890
|
-
const pureFetch = globalThis.fetch;
|
|
2891
|
-
const fetchProxy = async (input, init) => {
|
|
2892
|
-
const requestId = createRequestId();
|
|
2893
|
-
const request = new FetchRequest(typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.href) : input, init);
|
|
2894
|
-
if (input instanceof Request) setRawRequest(request, input);
|
|
2895
|
-
const responsePromise = new DeferredPromise();
|
|
2896
|
-
const controller = new RequestController(request, {
|
|
2897
|
-
passthrough: async () => {
|
|
2898
|
-
this.logger.info("request has not been handled, passthrough...");
|
|
2899
|
-
const requestCloneForResponseEvent = request.clone();
|
|
2900
|
-
const { error: responseError, data: originalResponse } = await until2(() => pureFetch(request));
|
|
2901
|
-
if (responseError) return responsePromise.reject(responseError);
|
|
2902
|
-
this.logger.info("original fetch performed", originalResponse);
|
|
2903
|
-
if (this.emitter.listenerCount("response") > 0) {
|
|
2904
|
-
this.logger.info('emitting the "response" event...');
|
|
2905
|
-
const responseClone = FetchResponse.clone(originalResponse);
|
|
2906
|
-
await emitAsync(this.emitter, "response", {
|
|
2907
|
-
response: responseClone,
|
|
2908
|
-
isMockedResponse: false,
|
|
2909
|
-
request: requestCloneForResponseEvent,
|
|
2910
|
-
requestId
|
|
2911
|
-
});
|
|
2912
|
-
}
|
|
2913
|
-
responsePromise.resolve(originalResponse);
|
|
2914
|
-
},
|
|
2915
|
-
respondWith: async (rawResponse) => {
|
|
2916
|
-
if (isResponseError(rawResponse)) {
|
|
2917
|
-
this.logger.info("request has errored!", { response: rawResponse });
|
|
2918
|
-
responsePromise.reject(createNetworkError(rawResponse));
|
|
2919
|
-
return;
|
|
2920
|
-
}
|
|
2921
|
-
this.logger.info("received mocked response!", { rawResponse });
|
|
2922
|
-
const response = new FetchResponse(decompressResponse(rawResponse) || rawResponse.body, {
|
|
2923
|
-
url: request.url,
|
|
2924
|
-
status: rawResponse.status,
|
|
2925
|
-
statusText: rawResponse.statusText,
|
|
2926
|
-
headers: rawResponse.headers
|
|
2927
|
-
});
|
|
2928
|
-
if (FetchResponse.isRedirectResponse(response.status)) {
|
|
2929
|
-
if (request.redirect === "error") {
|
|
2930
|
-
responsePromise.reject(createNetworkError("unexpected redirect"));
|
|
2931
|
-
return;
|
|
2932
|
-
}
|
|
2933
|
-
if (request.redirect === "follow") {
|
|
2934
|
-
followFetchRedirect(request, response).then((response$1) => {
|
|
2935
|
-
responsePromise.resolve(response$1);
|
|
2936
|
-
}, (reason) => {
|
|
2937
|
-
responsePromise.reject(reason);
|
|
2938
|
-
});
|
|
2939
|
-
return;
|
|
2940
|
-
}
|
|
2941
|
-
}
|
|
2942
|
-
if (this.emitter.listenerCount("response") > 0) {
|
|
2943
|
-
this.logger.info('emitting the "response" event...');
|
|
2944
|
-
await emitAsync(this.emitter, "response", {
|
|
2945
|
-
response: FetchResponse.clone(response),
|
|
2946
|
-
isMockedResponse: true,
|
|
2947
|
-
request,
|
|
2948
|
-
requestId
|
|
2949
|
-
});
|
|
2950
|
-
}
|
|
2951
|
-
responsePromise.resolve(response);
|
|
2952
|
-
},
|
|
2953
|
-
errorWith: (reason) => {
|
|
2954
|
-
this.logger.info("request has been aborted!", { reason });
|
|
2955
|
-
responsePromise.reject(reason);
|
|
2956
|
-
}
|
|
2957
|
-
});
|
|
2958
|
-
this.logger.info("[%s] %s", request.method, request.url);
|
|
2959
|
-
this.logger.info("awaiting for the mocked response...");
|
|
2960
|
-
this.logger.info('emitting the "request" event for %s listener(s)...', this.emitter.listenerCount("request"));
|
|
2961
|
-
await handleRequest({
|
|
2962
|
-
request,
|
|
2963
|
-
requestId,
|
|
2964
|
-
emitter: this.emitter,
|
|
2965
|
-
controller
|
|
2966
|
-
});
|
|
2967
|
-
return responsePromise;
|
|
2968
|
-
};
|
|
2969
|
-
logger.info("patching global fetch...");
|
|
2970
|
-
this.subscriptions.push(patchesRegistry.applyPatch(globalThis, "fetch", () => fetchProxy));
|
|
2971
|
-
logger.info("global fetch patched!", globalThis.fetch.name);
|
|
2972
|
-
}
|
|
2973
|
-
};
|
|
2974
|
-
|
|
2975
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.9/node_modules/@mswjs/interceptors/lib/browser/XMLHttpRequest-DrZAf3w6.mjs
|
|
2976
|
-
function concatArrayBuffer(left, right) {
|
|
2977
|
-
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
2978
|
-
result.set(left, 0);
|
|
2979
|
-
result.set(right, left.byteLength);
|
|
2980
|
-
return result;
|
|
2981
|
-
}
|
|
2982
|
-
var EventPolyfill = class {
|
|
2983
|
-
constructor(type, options) {
|
|
2984
|
-
this.NONE = 0;
|
|
2985
|
-
this.CAPTURING_PHASE = 1;
|
|
2986
|
-
this.AT_TARGET = 2;
|
|
2987
|
-
this.BUBBLING_PHASE = 3;
|
|
2988
|
-
this.type = "";
|
|
2989
|
-
this.srcElement = null;
|
|
2990
|
-
this.currentTarget = null;
|
|
2991
|
-
this.eventPhase = 0;
|
|
2992
|
-
this.isTrusted = true;
|
|
2993
|
-
this.composed = false;
|
|
2994
|
-
this.cancelable = true;
|
|
2995
|
-
this.defaultPrevented = false;
|
|
2996
|
-
this.bubbles = true;
|
|
2997
|
-
this.lengthComputable = true;
|
|
2998
|
-
this.loaded = 0;
|
|
2999
|
-
this.total = 0;
|
|
3000
|
-
this.cancelBubble = false;
|
|
3001
|
-
this.returnValue = true;
|
|
3002
|
-
this.type = type;
|
|
3003
|
-
this.target = options?.target || null;
|
|
3004
|
-
this.currentTarget = options?.currentTarget || null;
|
|
3005
|
-
this.timeStamp = Date.now();
|
|
3006
|
-
}
|
|
3007
|
-
composedPath() {
|
|
3008
|
-
return [];
|
|
3009
|
-
}
|
|
3010
|
-
initEvent(type, bubbles, cancelable) {
|
|
3011
|
-
this.type = type;
|
|
3012
|
-
this.bubbles = !!bubbles;
|
|
3013
|
-
this.cancelable = !!cancelable;
|
|
3014
|
-
}
|
|
3015
|
-
preventDefault() {
|
|
3016
|
-
this.defaultPrevented = true;
|
|
3017
|
-
}
|
|
3018
|
-
stopPropagation() {
|
|
3019
|
-
}
|
|
3020
|
-
stopImmediatePropagation() {
|
|
3021
|
-
}
|
|
3022
|
-
};
|
|
3023
|
-
var ProgressEventPolyfill = class extends EventPolyfill {
|
|
3024
|
-
constructor(type, init) {
|
|
3025
|
-
super(type);
|
|
3026
|
-
this.lengthComputable = init?.lengthComputable || false;
|
|
3027
|
-
this.composed = init?.composed || false;
|
|
3028
|
-
this.loaded = init?.loaded || 0;
|
|
3029
|
-
this.total = init?.total || 0;
|
|
3030
|
-
}
|
|
3031
|
-
};
|
|
3032
|
-
var SUPPORTS_PROGRESS_EVENT = typeof ProgressEvent !== "undefined";
|
|
3033
|
-
function createEvent(target, type, init) {
|
|
3034
|
-
const progressEvents = [
|
|
3035
|
-
"error",
|
|
3036
|
-
"progress",
|
|
3037
|
-
"loadstart",
|
|
3038
|
-
"loadend",
|
|
3039
|
-
"load",
|
|
3040
|
-
"timeout",
|
|
3041
|
-
"abort"
|
|
3042
|
-
];
|
|
3043
|
-
const ProgressEventClass = SUPPORTS_PROGRESS_EVENT ? ProgressEvent : ProgressEventPolyfill;
|
|
3044
|
-
return progressEvents.includes(type) ? new ProgressEventClass(type, {
|
|
3045
|
-
lengthComputable: true,
|
|
3046
|
-
loaded: init?.loaded || 0,
|
|
3047
|
-
total: init?.total || 0
|
|
3048
|
-
}) : new EventPolyfill(type, {
|
|
3049
|
-
target,
|
|
3050
|
-
currentTarget: target
|
|
3051
|
-
});
|
|
3052
|
-
}
|
|
3053
|
-
function findPropertySource(target, propertyName) {
|
|
3054
|
-
if (!(propertyName in target)) return null;
|
|
3055
|
-
if (Object.prototype.hasOwnProperty.call(target, propertyName)) return target;
|
|
3056
|
-
const prototype = Reflect.getPrototypeOf(target);
|
|
3057
|
-
return prototype ? findPropertySource(prototype, propertyName) : null;
|
|
3058
|
-
}
|
|
3059
|
-
function createProxy(target, options) {
|
|
3060
|
-
return new Proxy(target, optionsToProxyHandler(options));
|
|
3061
|
-
}
|
|
3062
|
-
function optionsToProxyHandler(options) {
|
|
3063
|
-
const { constructorCall, methodCall, getProperty, setProperty } = options;
|
|
3064
|
-
const handler = {};
|
|
3065
|
-
if (typeof constructorCall !== "undefined") handler.construct = function(target, args, newTarget) {
|
|
3066
|
-
const next = Reflect.construct.bind(null, target, args, newTarget);
|
|
3067
|
-
return constructorCall.call(newTarget, args, next);
|
|
3068
|
-
};
|
|
3069
|
-
handler.set = function(target, propertyName, nextValue) {
|
|
3070
|
-
const next = () => {
|
|
3071
|
-
const propertySource = findPropertySource(target, propertyName) || target;
|
|
3072
|
-
const ownDescriptors = Reflect.getOwnPropertyDescriptor(propertySource, propertyName);
|
|
3073
|
-
if (typeof ownDescriptors?.set !== "undefined") {
|
|
3074
|
-
ownDescriptors.set.apply(target, [nextValue]);
|
|
3075
|
-
return true;
|
|
3076
|
-
}
|
|
3077
|
-
return Reflect.defineProperty(propertySource, propertyName, {
|
|
3078
|
-
writable: true,
|
|
3079
|
-
enumerable: true,
|
|
3080
|
-
configurable: true,
|
|
3081
|
-
value: nextValue
|
|
3082
|
-
});
|
|
3083
|
-
};
|
|
3084
|
-
if (typeof setProperty !== "undefined") return setProperty.call(target, [propertyName, nextValue], next);
|
|
3085
|
-
return next();
|
|
3086
|
-
};
|
|
3087
|
-
handler.get = function(target, propertyName, receiver) {
|
|
3088
|
-
const next = () => target[propertyName];
|
|
3089
|
-
const value = typeof getProperty !== "undefined" ? getProperty.call(target, [propertyName, receiver], next) : next();
|
|
3090
|
-
if (typeof value === "function") return (...args) => {
|
|
3091
|
-
const next$1 = value.bind(target, ...args);
|
|
3092
|
-
if (typeof methodCall !== "undefined") return methodCall.call(target, [propertyName, args], next$1);
|
|
3093
|
-
return next$1();
|
|
3094
|
-
};
|
|
3095
|
-
return value;
|
|
3096
|
-
};
|
|
3097
|
-
return handler;
|
|
3098
|
-
}
|
|
3099
|
-
function isDomParserSupportedType(type) {
|
|
3100
|
-
return [
|
|
3101
|
-
"application/xhtml+xml",
|
|
3102
|
-
"application/xml",
|
|
3103
|
-
"image/svg+xml",
|
|
3104
|
-
"text/html",
|
|
3105
|
-
"text/xml"
|
|
3106
|
-
].some((supportedType) => {
|
|
3107
|
-
return type.startsWith(supportedType);
|
|
3108
|
-
});
|
|
3109
|
-
}
|
|
3110
|
-
function parseJson(data) {
|
|
3111
|
-
try {
|
|
3112
|
-
return JSON.parse(data);
|
|
3113
|
-
} catch (_) {
|
|
3114
|
-
return null;
|
|
3115
|
-
}
|
|
3116
|
-
}
|
|
3117
|
-
function createResponse(request, body) {
|
|
3118
|
-
return new FetchResponse(FetchResponse.isResponseWithBody(request.status) ? body : null, {
|
|
3119
|
-
url: request.responseURL,
|
|
3120
|
-
status: request.status,
|
|
3121
|
-
statusText: request.statusText,
|
|
3122
|
-
headers: createHeadersFromXMLHttpRequestHeaders(request.getAllResponseHeaders())
|
|
3123
|
-
});
|
|
3124
|
-
}
|
|
3125
|
-
function createHeadersFromXMLHttpRequestHeaders(headersString) {
|
|
3126
|
-
const headers = new Headers();
|
|
3127
|
-
const lines = headersString.split(/[\r\n]+/);
|
|
3128
|
-
for (const line of lines) {
|
|
3129
|
-
if (line.trim() === "") continue;
|
|
3130
|
-
const [name, ...parts] = line.split(": ");
|
|
3131
|
-
const value = parts.join(": ");
|
|
3132
|
-
headers.append(name, value);
|
|
3133
|
-
}
|
|
3134
|
-
return headers;
|
|
3135
|
-
}
|
|
3136
|
-
async function getBodyByteLength(input) {
|
|
3137
|
-
const explicitContentLength = input.headers.get("content-length");
|
|
3138
|
-
if (explicitContentLength != null && explicitContentLength !== "") return Number(explicitContentLength);
|
|
3139
|
-
return (await input.arrayBuffer()).byteLength;
|
|
3140
|
-
}
|
|
3141
|
-
var kIsRequestHandled = /* @__PURE__ */ Symbol("kIsRequestHandled");
|
|
3142
|
-
var IS_NODE2 = isNodeProcess();
|
|
3143
|
-
var kFetchRequest = /* @__PURE__ */ Symbol("kFetchRequest");
|
|
3144
|
-
var XMLHttpRequestController = class {
|
|
3145
|
-
constructor(initialRequest, logger) {
|
|
3146
|
-
this.initialRequest = initialRequest;
|
|
3147
|
-
this.logger = logger;
|
|
3148
|
-
this.method = "GET";
|
|
3149
|
-
this.url = null;
|
|
3150
|
-
this[kIsRequestHandled] = false;
|
|
3151
|
-
this.events = /* @__PURE__ */ new Map();
|
|
3152
|
-
this.uploadEvents = /* @__PURE__ */ new Map();
|
|
3153
|
-
this.requestId = createRequestId();
|
|
3154
|
-
this.requestHeaders = new Headers();
|
|
3155
|
-
this.responseBuffer = new Uint8Array();
|
|
3156
|
-
this.request = createProxy(initialRequest, {
|
|
3157
|
-
setProperty: ([propertyName, nextValue], invoke) => {
|
|
3158
|
-
switch (propertyName) {
|
|
3159
|
-
case "ontimeout": {
|
|
3160
|
-
const eventName = propertyName.slice(2);
|
|
3161
|
-
this.request.addEventListener(eventName, nextValue);
|
|
3162
|
-
return invoke();
|
|
3163
|
-
}
|
|
3164
|
-
default:
|
|
3165
|
-
return invoke();
|
|
3166
|
-
}
|
|
3167
|
-
},
|
|
3168
|
-
methodCall: ([methodName, args], invoke) => {
|
|
3169
|
-
switch (methodName) {
|
|
3170
|
-
case "open": {
|
|
3171
|
-
const [method, url] = args;
|
|
3172
|
-
if (typeof url === "undefined") {
|
|
3173
|
-
this.method = "GET";
|
|
3174
|
-
this.url = toAbsoluteUrl(method);
|
|
3175
|
-
} else {
|
|
3176
|
-
this.method = method;
|
|
3177
|
-
this.url = toAbsoluteUrl(url);
|
|
3178
|
-
}
|
|
3179
|
-
this.logger = this.logger.extend(`${this.method} ${this.url.href}`);
|
|
3180
|
-
this.logger.info("open", this.method, this.url.href);
|
|
3181
|
-
return invoke();
|
|
3182
|
-
}
|
|
3183
|
-
case "addEventListener": {
|
|
3184
|
-
const [eventName, listener] = args;
|
|
3185
|
-
this.registerEvent(eventName, listener);
|
|
3186
|
-
this.logger.info("addEventListener", eventName, listener);
|
|
3187
|
-
return invoke();
|
|
3188
|
-
}
|
|
3189
|
-
case "setRequestHeader": {
|
|
3190
|
-
const [name, value] = args;
|
|
3191
|
-
this.requestHeaders.set(name, value);
|
|
3192
|
-
this.logger.info("setRequestHeader", name, value);
|
|
3193
|
-
return invoke();
|
|
3194
|
-
}
|
|
3195
|
-
case "send": {
|
|
3196
|
-
const [body] = args;
|
|
3197
|
-
this.request.addEventListener("load", () => {
|
|
3198
|
-
if (typeof this.onResponse !== "undefined") {
|
|
3199
|
-
const fetchResponse = createResponse(
|
|
3200
|
-
this.request,
|
|
3201
|
-
/**
|
|
3202
|
-
* The `response` property is the right way to read
|
|
3203
|
-
* the ambiguous response body, as the request's "responseType" may differ.
|
|
3204
|
-
* @see https://xhr.spec.whatwg.org/#the-response-attribute
|
|
3205
|
-
*/
|
|
3206
|
-
this.request.response
|
|
3207
|
-
);
|
|
3208
|
-
this.onResponse.call(this, {
|
|
3209
|
-
response: fetchResponse,
|
|
3210
|
-
isMockedResponse: this[kIsRequestHandled],
|
|
3211
|
-
request: fetchRequest,
|
|
3212
|
-
requestId: this.requestId
|
|
3213
|
-
});
|
|
3214
|
-
}
|
|
3215
|
-
});
|
|
3216
|
-
const requestBody = typeof body === "string" ? encodeBuffer(body) : body;
|
|
3217
|
-
const fetchRequest = this.toFetchApiRequest(requestBody);
|
|
3218
|
-
this[kFetchRequest] = fetchRequest.clone();
|
|
3219
|
-
queueMicrotask(() => {
|
|
3220
|
-
(this.onRequest?.call(this, {
|
|
3221
|
-
request: fetchRequest,
|
|
3222
|
-
requestId: this.requestId
|
|
3223
|
-
}) || Promise.resolve()).finally(() => {
|
|
3224
|
-
if (!this[kIsRequestHandled]) {
|
|
3225
|
-
this.logger.info("request callback settled but request has not been handled (readystate %d), performing as-is...", this.request.readyState);
|
|
3226
|
-
if (IS_NODE2) this.request.setRequestHeader(INTERNAL_REQUEST_ID_HEADER_NAME, this.requestId);
|
|
3227
|
-
return invoke();
|
|
3228
|
-
}
|
|
3229
|
-
});
|
|
3230
|
-
});
|
|
3231
|
-
break;
|
|
3232
|
-
}
|
|
3233
|
-
default:
|
|
3234
|
-
return invoke();
|
|
3235
|
-
}
|
|
3236
|
-
}
|
|
3237
|
-
});
|
|
3238
|
-
define(this.request, "upload", createProxy(this.request.upload, {
|
|
3239
|
-
setProperty: ([propertyName, nextValue], invoke) => {
|
|
3240
|
-
switch (propertyName) {
|
|
3241
|
-
case "onloadstart":
|
|
3242
|
-
case "onprogress":
|
|
3243
|
-
case "onaboart":
|
|
3244
|
-
case "onerror":
|
|
3245
|
-
case "onload":
|
|
3246
|
-
case "ontimeout":
|
|
3247
|
-
case "onloadend": {
|
|
3248
|
-
const eventName = propertyName.slice(2);
|
|
3249
|
-
this.registerUploadEvent(eventName, nextValue);
|
|
3250
|
-
}
|
|
3251
|
-
}
|
|
3252
|
-
return invoke();
|
|
3253
|
-
},
|
|
3254
|
-
methodCall: ([methodName, args], invoke) => {
|
|
3255
|
-
switch (methodName) {
|
|
3256
|
-
case "addEventListener": {
|
|
3257
|
-
const [eventName, listener] = args;
|
|
3258
|
-
this.registerUploadEvent(eventName, listener);
|
|
3259
|
-
this.logger.info("upload.addEventListener", eventName, listener);
|
|
3260
|
-
return invoke();
|
|
3261
|
-
}
|
|
3262
|
-
}
|
|
3263
|
-
}
|
|
3264
|
-
}));
|
|
3265
|
-
}
|
|
3266
|
-
registerEvent(eventName, listener) {
|
|
3267
|
-
const nextEvents = (this.events.get(eventName) || []).concat(listener);
|
|
3268
|
-
this.events.set(eventName, nextEvents);
|
|
3269
|
-
this.logger.info('registered event "%s"', eventName, listener);
|
|
3270
|
-
}
|
|
3271
|
-
registerUploadEvent(eventName, listener) {
|
|
3272
|
-
const nextEvents = (this.uploadEvents.get(eventName) || []).concat(listener);
|
|
3273
|
-
this.uploadEvents.set(eventName, nextEvents);
|
|
3274
|
-
this.logger.info('registered upload event "%s"', eventName, listener);
|
|
3275
|
-
}
|
|
3276
|
-
/**
|
|
3277
|
-
* Responds to the current request with the given
|
|
3278
|
-
* Fetch API `Response` instance.
|
|
3279
|
-
*/
|
|
3280
|
-
async respondWith(response) {
|
|
3281
|
-
this[kIsRequestHandled] = true;
|
|
3282
|
-
if (this[kFetchRequest]) {
|
|
3283
|
-
const totalRequestBodyLength = await getBodyByteLength(this[kFetchRequest]);
|
|
3284
|
-
this.trigger("loadstart", this.request.upload, {
|
|
3285
|
-
loaded: 0,
|
|
3286
|
-
total: totalRequestBodyLength
|
|
3287
|
-
});
|
|
3288
|
-
this.trigger("progress", this.request.upload, {
|
|
3289
|
-
loaded: totalRequestBodyLength,
|
|
3290
|
-
total: totalRequestBodyLength
|
|
3291
|
-
});
|
|
3292
|
-
this.trigger("load", this.request.upload, {
|
|
3293
|
-
loaded: totalRequestBodyLength,
|
|
3294
|
-
total: totalRequestBodyLength
|
|
3295
|
-
});
|
|
3296
|
-
this.trigger("loadend", this.request.upload, {
|
|
3297
|
-
loaded: totalRequestBodyLength,
|
|
3298
|
-
total: totalRequestBodyLength
|
|
3299
|
-
});
|
|
3300
|
-
}
|
|
3301
|
-
this.logger.info("responding with a mocked response: %d %s", response.status, response.statusText);
|
|
3302
|
-
define(this.request, "status", response.status);
|
|
3303
|
-
define(this.request, "statusText", response.statusText);
|
|
3304
|
-
define(this.request, "responseURL", this.url.href);
|
|
3305
|
-
this.request.getResponseHeader = new Proxy(this.request.getResponseHeader, { apply: (_, __, args) => {
|
|
3306
|
-
this.logger.info("getResponseHeader", args[0]);
|
|
3307
|
-
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
|
3308
|
-
this.logger.info("headers not received yet, returning null");
|
|
3309
|
-
return null;
|
|
3310
|
-
}
|
|
3311
|
-
const headerValue = response.headers.get(args[0]);
|
|
3312
|
-
this.logger.info('resolved response header "%s" to', args[0], headerValue);
|
|
3313
|
-
return headerValue;
|
|
3314
|
-
} });
|
|
3315
|
-
this.request.getAllResponseHeaders = new Proxy(this.request.getAllResponseHeaders, { apply: () => {
|
|
3316
|
-
this.logger.info("getAllResponseHeaders");
|
|
3317
|
-
if (this.request.readyState < this.request.HEADERS_RECEIVED) {
|
|
3318
|
-
this.logger.info("headers not received yet, returning empty string");
|
|
3319
|
-
return "";
|
|
3320
|
-
}
|
|
3321
|
-
const allHeaders = Array.from(response.headers.entries()).map(([headerName, headerValue]) => {
|
|
3322
|
-
return `${headerName}: ${headerValue}`;
|
|
3323
|
-
}).join("\r\n");
|
|
3324
|
-
this.logger.info("resolved all response headers to", allHeaders);
|
|
3325
|
-
return allHeaders;
|
|
3326
|
-
} });
|
|
3327
|
-
Object.defineProperties(this.request, {
|
|
3328
|
-
response: {
|
|
3329
|
-
enumerable: true,
|
|
3330
|
-
configurable: false,
|
|
3331
|
-
get: () => this.response
|
|
3332
|
-
},
|
|
3333
|
-
responseText: {
|
|
3334
|
-
enumerable: true,
|
|
3335
|
-
configurable: false,
|
|
3336
|
-
get: () => this.responseText
|
|
3337
|
-
},
|
|
3338
|
-
responseXML: {
|
|
3339
|
-
enumerable: true,
|
|
3340
|
-
configurable: false,
|
|
3341
|
-
get: () => this.responseXML
|
|
3342
|
-
}
|
|
3343
|
-
});
|
|
3344
|
-
const totalResponseBodyLength = await getBodyByteLength(response.clone());
|
|
3345
|
-
this.logger.info("calculated response body length", totalResponseBodyLength);
|
|
3346
|
-
this.trigger("loadstart", this.request, {
|
|
3347
|
-
loaded: 0,
|
|
3348
|
-
total: totalResponseBodyLength
|
|
3349
|
-
});
|
|
3350
|
-
this.setReadyState(this.request.HEADERS_RECEIVED);
|
|
3351
|
-
this.setReadyState(this.request.LOADING);
|
|
3352
|
-
const finalizeResponse = () => {
|
|
3353
|
-
this.logger.info("finalizing the mocked response...");
|
|
3354
|
-
this.setReadyState(this.request.DONE);
|
|
3355
|
-
this.trigger("load", this.request, {
|
|
3356
|
-
loaded: this.responseBuffer.byteLength,
|
|
3357
|
-
total: totalResponseBodyLength
|
|
3358
|
-
});
|
|
3359
|
-
this.trigger("loadend", this.request, {
|
|
3360
|
-
loaded: this.responseBuffer.byteLength,
|
|
3361
|
-
total: totalResponseBodyLength
|
|
3362
|
-
});
|
|
3363
|
-
};
|
|
3364
|
-
if (response.body) {
|
|
3365
|
-
this.logger.info("mocked response has body, streaming...");
|
|
3366
|
-
const reader = response.body.getReader();
|
|
3367
|
-
const readNextResponseBodyChunk = async () => {
|
|
3368
|
-
const { value, done } = await reader.read();
|
|
3369
|
-
if (done) {
|
|
3370
|
-
this.logger.info("response body stream done!");
|
|
3371
|
-
finalizeResponse();
|
|
3372
|
-
return;
|
|
3373
|
-
}
|
|
3374
|
-
if (value) {
|
|
3375
|
-
this.logger.info("read response body chunk:", value);
|
|
3376
|
-
this.responseBuffer = concatArrayBuffer(this.responseBuffer, value);
|
|
3377
|
-
this.trigger("progress", this.request, {
|
|
3378
|
-
loaded: this.responseBuffer.byteLength,
|
|
3379
|
-
total: totalResponseBodyLength
|
|
3380
|
-
});
|
|
3381
|
-
}
|
|
3382
|
-
readNextResponseBodyChunk();
|
|
3383
|
-
};
|
|
3384
|
-
readNextResponseBodyChunk();
|
|
3385
|
-
} else finalizeResponse();
|
|
3386
|
-
}
|
|
3387
|
-
responseBufferToText() {
|
|
3388
|
-
return decodeBuffer(this.responseBuffer);
|
|
3389
|
-
}
|
|
3390
|
-
get response() {
|
|
3391
|
-
this.logger.info("getResponse (responseType: %s)", this.request.responseType);
|
|
3392
|
-
if (this.request.readyState !== this.request.DONE) return null;
|
|
3393
|
-
switch (this.request.responseType) {
|
|
3394
|
-
case "json": {
|
|
3395
|
-
const responseJson = parseJson(this.responseBufferToText());
|
|
3396
|
-
this.logger.info("resolved response JSON", responseJson);
|
|
3397
|
-
return responseJson;
|
|
3398
|
-
}
|
|
3399
|
-
case "arraybuffer": {
|
|
3400
|
-
const arrayBuffer = toArrayBuffer(this.responseBuffer);
|
|
3401
|
-
this.logger.info("resolved response ArrayBuffer", arrayBuffer);
|
|
3402
|
-
return arrayBuffer;
|
|
3403
|
-
}
|
|
3404
|
-
case "blob": {
|
|
3405
|
-
const mimeType = this.request.getResponseHeader("Content-Type") || "text/plain";
|
|
3406
|
-
const responseBlob = new Blob([this.responseBufferToText()], { type: mimeType });
|
|
3407
|
-
this.logger.info("resolved response Blob (mime type: %s)", responseBlob, mimeType);
|
|
3408
|
-
return responseBlob;
|
|
3409
|
-
}
|
|
3410
|
-
default: {
|
|
3411
|
-
const responseText = this.responseBufferToText();
|
|
3412
|
-
this.logger.info('resolving "%s" response type as text', this.request.responseType, responseText);
|
|
3413
|
-
return responseText;
|
|
3414
|
-
}
|
|
3415
|
-
}
|
|
3416
|
-
}
|
|
3417
|
-
get responseText() {
|
|
3418
|
-
invariant(this.request.responseType === "" || this.request.responseType === "text", "InvalidStateError: The object is in invalid state.");
|
|
3419
|
-
if (this.request.readyState !== this.request.LOADING && this.request.readyState !== this.request.DONE) return "";
|
|
3420
|
-
const responseText = this.responseBufferToText();
|
|
3421
|
-
this.logger.info('getResponseText: "%s"', responseText);
|
|
3422
|
-
return responseText;
|
|
3423
|
-
}
|
|
3424
|
-
get responseXML() {
|
|
3425
|
-
invariant(this.request.responseType === "" || this.request.responseType === "document", "InvalidStateError: The object is in invalid state.");
|
|
3426
|
-
if (this.request.readyState !== this.request.DONE) return null;
|
|
3427
|
-
const contentType = this.request.getResponseHeader("Content-Type") || "";
|
|
3428
|
-
if (typeof DOMParser === "undefined") {
|
|
3429
|
-
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.");
|
|
3430
|
-
return null;
|
|
3431
|
-
}
|
|
3432
|
-
if (isDomParserSupportedType(contentType)) return new DOMParser().parseFromString(this.responseBufferToText(), contentType);
|
|
3433
|
-
return null;
|
|
3434
|
-
}
|
|
3435
|
-
errorWith(error2) {
|
|
3436
|
-
this[kIsRequestHandled] = true;
|
|
3437
|
-
this.logger.info("responding with an error");
|
|
3438
|
-
this.setReadyState(this.request.DONE);
|
|
3439
|
-
this.trigger("error", this.request);
|
|
3440
|
-
this.trigger("loadend", this.request);
|
|
3441
|
-
}
|
|
3442
|
-
/**
|
|
3443
|
-
* Transitions this request's `readyState` to the given one.
|
|
3444
|
-
*/
|
|
3445
|
-
setReadyState(nextReadyState) {
|
|
3446
|
-
this.logger.info("setReadyState: %d -> %d", this.request.readyState, nextReadyState);
|
|
3447
|
-
if (this.request.readyState === nextReadyState) {
|
|
3448
|
-
this.logger.info("ready state identical, skipping transition...");
|
|
3449
|
-
return;
|
|
3450
|
-
}
|
|
3451
|
-
define(this.request, "readyState", nextReadyState);
|
|
3452
|
-
this.logger.info("set readyState to: %d", nextReadyState);
|
|
3453
|
-
if (nextReadyState !== this.request.UNSENT) {
|
|
3454
|
-
this.logger.info('triggering "readystatechange" event...');
|
|
3455
|
-
this.trigger("readystatechange", this.request);
|
|
3456
|
-
}
|
|
3457
|
-
}
|
|
3458
|
-
/**
|
|
3459
|
-
* Triggers given event on the `XMLHttpRequest` instance.
|
|
3460
|
-
*/
|
|
3461
|
-
trigger(eventName, target, options) {
|
|
3462
|
-
const callback = target[`on${eventName}`];
|
|
3463
|
-
const event = createEvent(target, eventName, options);
|
|
3464
|
-
this.logger.info('trigger "%s"', eventName, options || "");
|
|
3465
|
-
if (typeof callback === "function") {
|
|
3466
|
-
this.logger.info('found a direct "%s" callback, calling...', eventName);
|
|
3467
|
-
callback.call(target, event);
|
|
3468
|
-
}
|
|
3469
|
-
const events = target instanceof XMLHttpRequestUpload ? this.uploadEvents : this.events;
|
|
3470
|
-
for (const [registeredEventName, listeners] of events) if (registeredEventName === eventName) {
|
|
3471
|
-
this.logger.info('found %d listener(s) for "%s" event, calling...', listeners.length, eventName);
|
|
3472
|
-
listeners.forEach((listener) => listener.call(target, event));
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
/**
|
|
3476
|
-
* Converts this `XMLHttpRequest` instance into a Fetch API `Request` instance.
|
|
3477
|
-
*/
|
|
3478
|
-
toFetchApiRequest(body) {
|
|
3479
|
-
this.logger.info("converting request to a Fetch API Request...");
|
|
3480
|
-
const resolvedBody = body instanceof Document ? body.documentElement.innerText : body;
|
|
3481
|
-
const fetchRequest = new FetchRequest(this.url.href, {
|
|
3482
|
-
method: this.method,
|
|
3483
|
-
headers: this.requestHeaders,
|
|
3484
|
-
credentials: this.request.withCredentials ? "include" : "same-origin",
|
|
3485
|
-
body: ["GET", "HEAD"].includes(this.method.toUpperCase()) ? null : resolvedBody
|
|
3486
|
-
});
|
|
3487
|
-
define(fetchRequest, "headers", createProxy(fetchRequest.headers, { methodCall: ([methodName, args], invoke) => {
|
|
3488
|
-
switch (methodName) {
|
|
3489
|
-
case "append":
|
|
3490
|
-
case "set": {
|
|
3491
|
-
const [headerName, headerValue] = args;
|
|
3492
|
-
this.request.setRequestHeader(headerName, headerValue);
|
|
3493
|
-
break;
|
|
3494
|
-
}
|
|
3495
|
-
case "delete": {
|
|
3496
|
-
const [headerName] = args;
|
|
3497
|
-
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.`);
|
|
3498
|
-
break;
|
|
3499
|
-
}
|
|
3500
|
-
}
|
|
3501
|
-
return invoke();
|
|
3502
|
-
} }));
|
|
3503
|
-
setRawRequest(fetchRequest, this.request);
|
|
3504
|
-
this.logger.info("converted request to a Fetch API Request!", fetchRequest);
|
|
3505
|
-
return fetchRequest;
|
|
3506
|
-
}
|
|
3507
|
-
};
|
|
3508
|
-
function toAbsoluteUrl(url) {
|
|
3509
|
-
if (typeof location === "undefined") return new URL(url);
|
|
3510
|
-
return new URL(url.toString(), location.href);
|
|
3511
|
-
}
|
|
3512
|
-
function define(target, property, value) {
|
|
3513
|
-
Reflect.defineProperty(target, property, {
|
|
3514
|
-
writable: true,
|
|
3515
|
-
enumerable: true,
|
|
3516
|
-
value
|
|
3517
|
-
});
|
|
3518
|
-
}
|
|
3519
|
-
function createXMLHttpRequestProxy({ emitter, logger }) {
|
|
3520
|
-
return new Proxy(globalThis.XMLHttpRequest, { construct(target, args, newTarget) {
|
|
3521
|
-
logger.info("constructed new XMLHttpRequest");
|
|
3522
|
-
const originalRequest = Reflect.construct(target, args, newTarget);
|
|
3523
|
-
const prototypeDescriptors = Object.getOwnPropertyDescriptors(target.prototype);
|
|
3524
|
-
for (const propertyName in prototypeDescriptors) Reflect.defineProperty(originalRequest, propertyName, prototypeDescriptors[propertyName]);
|
|
3525
|
-
const xhrRequestController = new XMLHttpRequestController(originalRequest, logger);
|
|
3526
|
-
xhrRequestController.onRequest = async function({ request, requestId }) {
|
|
3527
|
-
const controller = new RequestController(request, {
|
|
3528
|
-
passthrough: () => {
|
|
3529
|
-
this.logger.info("no mocked response received, performing request as-is...");
|
|
3530
|
-
},
|
|
3531
|
-
respondWith: async (response) => {
|
|
3532
|
-
if (isResponseError(response)) {
|
|
3533
|
-
this.errorWith(/* @__PURE__ */ new TypeError("Network error"));
|
|
3534
|
-
return;
|
|
3535
|
-
}
|
|
3536
|
-
await this.respondWith(response);
|
|
3537
|
-
},
|
|
3538
|
-
errorWith: (reason) => {
|
|
3539
|
-
this.logger.info("request errored!", { error: reason });
|
|
3540
|
-
if (reason instanceof Error) this.errorWith(reason);
|
|
3541
|
-
}
|
|
3542
|
-
});
|
|
3543
|
-
this.logger.info("awaiting mocked response...");
|
|
3544
|
-
this.logger.info('emitting the "request" event for %s listener(s)...', emitter.listenerCount("request"));
|
|
3545
|
-
await handleRequest({
|
|
3546
|
-
request,
|
|
3547
|
-
requestId,
|
|
3548
|
-
controller,
|
|
3549
|
-
emitter
|
|
3550
|
-
});
|
|
3551
|
-
};
|
|
3552
|
-
xhrRequestController.onResponse = async function({ response, isMockedResponse, request, requestId }) {
|
|
3553
|
-
this.logger.info('emitting the "response" event for %s listener(s)...', emitter.listenerCount("response"));
|
|
3554
|
-
emitter.emit("response", {
|
|
3555
|
-
response,
|
|
3556
|
-
isMockedResponse,
|
|
3557
|
-
request,
|
|
3558
|
-
requestId
|
|
3559
|
-
});
|
|
3560
|
-
};
|
|
3561
|
-
return xhrRequestController.request;
|
|
3562
|
-
} });
|
|
3563
|
-
}
|
|
3564
|
-
var XMLHttpRequestInterceptor = class XMLHttpRequestInterceptor2 extends Interceptor {
|
|
3565
|
-
static {
|
|
3566
|
-
this.symbol = /* @__PURE__ */ Symbol.for("xhr-interceptor");
|
|
3567
|
-
}
|
|
3568
|
-
constructor() {
|
|
3569
|
-
super(XMLHttpRequestInterceptor2.symbol);
|
|
3570
|
-
}
|
|
3571
|
-
checkEnvironment() {
|
|
3572
|
-
return hasConfigurableGlobal("XMLHttpRequest");
|
|
3573
|
-
}
|
|
3574
|
-
setup() {
|
|
3575
|
-
const logger = this.logger.extend("setup");
|
|
3576
|
-
logger.info("patching global XMLHttpRequest...");
|
|
3577
|
-
this.subscriptions.push(patchesRegistry.applyPatch(globalThis, "XMLHttpRequest", () => {
|
|
3578
|
-
return createXMLHttpRequestProxy({
|
|
3579
|
-
emitter: this.emitter,
|
|
3580
|
-
logger: this.logger
|
|
3581
|
-
});
|
|
3582
|
-
}));
|
|
3583
|
-
logger.info("global XMLHttpRequest patched!", globalThis.XMLHttpRequest.name);
|
|
3584
|
-
}
|
|
3585
|
-
};
|
|
3586
|
-
|
|
3587
|
-
// src/browser/sources/fallback-http-source.ts
|
|
3588
|
-
var import_interceptor_source = require("../core/experimental/sources/interceptor-source");
|
|
3589
|
-
var import_devUtils4 = require("../core/utils/internal/devUtils");
|
|
3590
|
-
var FallbackHttpSource = class extends import_interceptor_source.InterceptorSource {
|
|
3591
|
-
constructor(options) {
|
|
3592
|
-
super({
|
|
3593
|
-
interceptors: [new XMLHttpRequestInterceptor(), new FetchInterceptor()]
|
|
3594
|
-
});
|
|
3595
|
-
this.options = options;
|
|
3596
|
-
}
|
|
3597
|
-
options;
|
|
3598
|
-
enable() {
|
|
3599
|
-
super.enable();
|
|
3600
|
-
if (!this.options.quiet) {
|
|
3601
|
-
this.#printStartMessage();
|
|
3602
|
-
}
|
|
3603
|
-
}
|
|
3604
|
-
disable() {
|
|
3605
|
-
super.disable();
|
|
3606
|
-
if (!this.options.quiet) {
|
|
3607
|
-
this.#printStopMessage();
|
|
3608
|
-
}
|
|
3609
|
-
}
|
|
3610
|
-
#printStartMessage() {
|
|
3611
|
-
console.groupCollapsed(
|
|
3612
|
-
`%c${import_devUtils4.devUtils.formatMessage("Mocking enabled (fallback mode).")}`,
|
|
3613
|
-
"color:orangered;font-weight:bold;"
|
|
3614
|
-
);
|
|
3615
|
-
console.log(
|
|
3616
|
-
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
3617
|
-
"font-weight:bold",
|
|
3618
|
-
"font-weight:normal"
|
|
3619
|
-
);
|
|
3620
|
-
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
3621
|
-
console.groupEnd();
|
|
3622
|
-
}
|
|
3623
|
-
#printStopMessage() {
|
|
3624
|
-
console.log(
|
|
3625
|
-
`%c${import_devUtils4.devUtils.formatMessage("Mocking disabled.")}`,
|
|
3626
|
-
"color:orangered;font-weight:bold;"
|
|
3627
|
-
);
|
|
3628
|
-
}
|
|
3629
|
-
};
|
|
3630
|
-
|
|
3631
|
-
// src/browser/setup-worker.ts
|
|
3632
|
-
var DEFAULT_WORKER_URL = "/mockServiceWorker.js";
|
|
434
|
+
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.`);
|
|
435
|
+
integrityCheckPromise.resolve();
|
|
436
|
+
});
|
|
437
|
+
return integrityCheckPromise.promise;
|
|
438
|
+
}
|
|
439
|
+
async #printStartMessage() {
|
|
440
|
+
if (this.#workerState === "rejected") return;
|
|
441
|
+
invariant(this.#clientPromise != null, "[ServiceWorkerSource] Failed to print a start message: client confirmation not received");
|
|
442
|
+
const client = await this.#clientPromise;
|
|
443
|
+
const [worker, registration] = await this.workerPromise;
|
|
444
|
+
console.groupCollapsed(`%c${devUtils.formatMessage("Mocking enabled.")}`, "color:orangered;font-weight:bold;");
|
|
445
|
+
console.log("%cDocumentation: %chttps://mswjs.io/docs", "font-weight:bold", "font-weight:normal");
|
|
446
|
+
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
447
|
+
console.log("Worker script URL:", worker.scriptURL);
|
|
448
|
+
console.log("Worker scope:", registration.scope);
|
|
449
|
+
if (client) console.log("Client ID: %s (%s)", client.id, client.frameType);
|
|
450
|
+
console.groupEnd();
|
|
451
|
+
}
|
|
452
|
+
#printStopMessage() {
|
|
453
|
+
console.log(`%c${devUtils.formatMessage("Mocking disabled.")}`, "color:orangered;font-weight:bold;");
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
var ServiceWorkerHttpNetworkFrame = class extends HttpNetworkFrame {
|
|
457
|
+
#event;
|
|
458
|
+
constructor(options) {
|
|
459
|
+
super({ request: options.request });
|
|
460
|
+
this.#event = options.event;
|
|
461
|
+
}
|
|
462
|
+
passthrough() {
|
|
463
|
+
this.#event.postMessage("PASSTHROUGH", { request: { headers: Array.from(this.data.request.headers) } });
|
|
464
|
+
}
|
|
465
|
+
respondWith(response) {
|
|
466
|
+
if (response) this.#respondWith(response);
|
|
467
|
+
}
|
|
468
|
+
errorWith(reason) {
|
|
469
|
+
if (reason instanceof Response) return this.respondWith(reason);
|
|
470
|
+
devUtils.warn(`Uncaught exception in the request handler for "%s %s". 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`, this.data.request.method, this.data.request.url);
|
|
471
|
+
const error = reason instanceof Error ? reason : new Error(reason?.toString() || "Request failure");
|
|
472
|
+
this.respondWith(HttpResponse.json({
|
|
473
|
+
name: error.name,
|
|
474
|
+
message: error.message,
|
|
475
|
+
stack: error.stack
|
|
476
|
+
}, {
|
|
477
|
+
status: 500,
|
|
478
|
+
statusText: "Request Handler Error"
|
|
479
|
+
}));
|
|
480
|
+
}
|
|
481
|
+
async #respondWith(response) {
|
|
482
|
+
let responseBody;
|
|
483
|
+
let transfer;
|
|
484
|
+
const responseInit = toResponseInit(response);
|
|
485
|
+
if (supportsReadableStreamTransfer()) {
|
|
486
|
+
responseBody = response.body;
|
|
487
|
+
transfer = response.body == null ? void 0 : [response.body];
|
|
488
|
+
} else responseBody = response.body == null ? null : await response.clone().arrayBuffer();
|
|
489
|
+
this.#event.postMessage("MOCK_RESPONSE", {
|
|
490
|
+
...responseInit,
|
|
491
|
+
body: responseBody
|
|
492
|
+
}, transfer);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/browser/sources/fallback-http-source.ts
|
|
497
|
+
var FallbackHttpSource = class extends InterceptorSource {
|
|
498
|
+
options;
|
|
499
|
+
constructor(options) {
|
|
500
|
+
super({ interceptors: [new XMLHttpRequestInterceptor(), new FetchInterceptor()] });
|
|
501
|
+
this.options = options;
|
|
502
|
+
}
|
|
503
|
+
enable() {
|
|
504
|
+
super.enable();
|
|
505
|
+
if (!this.options.quiet) this.#printStartMessage();
|
|
506
|
+
}
|
|
507
|
+
disable() {
|
|
508
|
+
super.disable();
|
|
509
|
+
if (!this.options.quiet) this.#printStopMessage();
|
|
510
|
+
}
|
|
511
|
+
#printStartMessage() {
|
|
512
|
+
console.groupCollapsed(`%c${devUtils.formatMessage("Mocking enabled (fallback mode).")}`, "color:orangered;font-weight:bold;");
|
|
513
|
+
console.log("%cDocumentation: %chttps://mswjs.io/docs", "font-weight:bold", "font-weight:normal");
|
|
514
|
+
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
515
|
+
console.groupEnd();
|
|
516
|
+
}
|
|
517
|
+
#printStopMessage() {
|
|
518
|
+
console.log(`%c${devUtils.formatMessage("Mocking disabled.")}`, "color:orangered;font-weight:bold;");
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/browser/setup-worker.ts
|
|
523
|
+
const DEFAULT_WORKER_URL = "/mockServiceWorker.js";
|
|
524
|
+
/**
|
|
525
|
+
* Sets up a requests interception in the browser with the given request handlers.
|
|
526
|
+
* @param {Array<AnyHandler>} handlers List of request handlers.
|
|
527
|
+
*
|
|
528
|
+
* @see {@link https://mswjs.io/docs/api/setup-worker `setupWorker()` API reference}
|
|
529
|
+
*/
|
|
3633
530
|
function setupWorker(...handlers) {
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
stop() {
|
|
3688
|
-
if (network.readyState === import_define_network.NetworkReadyState.DISABLED) {
|
|
3689
|
-
import_devUtils5.devUtils.warn(
|
|
3690
|
-
`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.`
|
|
3691
|
-
);
|
|
3692
|
-
return;
|
|
3693
|
-
}
|
|
3694
|
-
network.disable();
|
|
3695
|
-
window.postMessage({ type: "msw/worker:stop" });
|
|
3696
|
-
},
|
|
3697
|
-
events: network.events,
|
|
3698
|
-
use: network.use.bind(network),
|
|
3699
|
-
resetHandlers: network.resetHandlers.bind(network),
|
|
3700
|
-
restoreHandlers: network.restoreHandlers.bind(network),
|
|
3701
|
-
listHandlers: network.listHandlers.bind(network)
|
|
3702
|
-
};
|
|
3703
|
-
}
|
|
3704
|
-
var SetupWorkerApi = class {
|
|
3705
|
-
start;
|
|
3706
|
-
stop;
|
|
3707
|
-
use;
|
|
3708
|
-
resetHandlers;
|
|
3709
|
-
restoreHandlers;
|
|
3710
|
-
listHandlers;
|
|
3711
|
-
events;
|
|
3712
|
-
constructor() {
|
|
3713
|
-
const worker = setupWorker();
|
|
3714
|
-
this.start = worker.start.bind(worker);
|
|
3715
|
-
this.stop = worker.stop.bind(worker);
|
|
3716
|
-
this.use = worker.use.bind(worker);
|
|
3717
|
-
this.resetHandlers = worker.resetHandlers.bind(worker);
|
|
3718
|
-
this.restoreHandlers = worker.restoreHandlers.bind(worker);
|
|
3719
|
-
this.listHandlers = worker.listHandlers.bind(worker);
|
|
3720
|
-
this.events = worker.events;
|
|
3721
|
-
}
|
|
3722
|
-
};
|
|
531
|
+
invariant(!isNodeProcess(), devUtils.formatMessage("Failed to execute `setupWorker` in a non-browser environment"));
|
|
532
|
+
const network = defineNetwork({
|
|
533
|
+
sources: [],
|
|
534
|
+
handlers
|
|
535
|
+
});
|
|
536
|
+
return {
|
|
537
|
+
get readyState() {
|
|
538
|
+
return network.readyState;
|
|
539
|
+
},
|
|
540
|
+
async start(options) {
|
|
541
|
+
invariant(network.readyState === 0, devUtils.formatMessage("Failed to call \"worker.start()\": the worker is already started. Remove the redundant \"worker.start()\" call."));
|
|
542
|
+
const httpSource = supportsServiceWorker() ? await ServiceWorkerSource.from({
|
|
543
|
+
serviceWorker: {
|
|
544
|
+
url: options?.serviceWorker?.url?.toString() || DEFAULT_WORKER_URL,
|
|
545
|
+
options: options?.serviceWorker?.options
|
|
546
|
+
},
|
|
547
|
+
findWorker: options?.findWorker,
|
|
548
|
+
quiet: options?.quiet
|
|
549
|
+
}) : new FallbackHttpSource({ quiet: options?.quiet });
|
|
550
|
+
network.configure({
|
|
551
|
+
sources: [httpSource, new InterceptorSource({ interceptors: [new WebSocketInterceptor()] })],
|
|
552
|
+
onUnhandledFrame: options?.onUnhandledFrame ?? "warn",
|
|
553
|
+
context: { quiet: options?.quiet }
|
|
554
|
+
});
|
|
555
|
+
await network.enable();
|
|
556
|
+
if (httpSource instanceof ServiceWorkerSource) {
|
|
557
|
+
const [, registration] = await httpSource.workerPromise;
|
|
558
|
+
return registration;
|
|
559
|
+
}
|
|
560
|
+
},
|
|
561
|
+
async stop() {
|
|
562
|
+
await network.disable();
|
|
563
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
564
|
+
},
|
|
565
|
+
events: network.events,
|
|
566
|
+
use: network.use.bind(network),
|
|
567
|
+
resetHandlers: network.resetHandlers.bind(network),
|
|
568
|
+
restoreHandlers: network.restoreHandlers.bind(network),
|
|
569
|
+
listHandlers: network.listHandlers.bind(network)
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/browser/default-network-options.ts
|
|
574
|
+
function createDefaultNetworkOptions(workerUrl = "/mockServiceWorker.js") {
|
|
575
|
+
return {
|
|
576
|
+
sources: [supportsServiceWorker() ? new ServiceWorkerSource({ serviceWorker: { url: workerUrl } }) : new FallbackHttpSource({}), new InterceptorSource({ interceptors: [new WebSocketInterceptor()] })],
|
|
577
|
+
onUnhandledFrame: "warn"
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
const defaultNetworkOptions = createDefaultNetworkOptions();
|
|
581
|
+
//#endregion
|
|
582
|
+
export { createDefaultNetworkOptions, defaultNetworkOptions, setupWorker };
|
|
583
|
+
|
|
3723
584
|
//# sourceMappingURL=index.js.map
|