@mswjs/interceptors 0.41.9 → 0.42.1
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 +274 -228
- package/lib/browser/{bufferUtils-BiiO6HZv.mjs → buffer-utils-DJj7YzLG.js} +3 -3
- package/lib/browser/buffer-utils-DJj7YzLG.js.map +1 -0
- package/lib/browser/create-request-id-Bk5YX1AM.js +720 -0
- package/lib/browser/create-request-id-Bk5YX1AM.js.map +1 -0
- package/lib/browser/{getRawRequest-B1BqgWG6.mjs → fetch-utils-CUOrwEQf.js} +123 -52
- package/lib/browser/fetch-utils-CUOrwEQf.js.map +1 -0
- package/lib/browser/handle-request-CqVvBhcw.js +167 -0
- package/lib/browser/handle-request-CqVvBhcw.js.map +1 -0
- package/lib/{node/hasConfigurableGlobal-BiTmog1u.mjs → browser/has-configurable-global-Cew-dYqk.js} +5 -7
- package/lib/browser/has-configurable-global-Cew-dYqk.js.map +1 -0
- package/lib/browser/http-CB9rQ7i_.d.ts +105 -0
- package/lib/browser/{index.d.cts → index.d.ts} +33 -38
- package/lib/browser/index.js +130 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/interceptor-dtJZ_9QT.d.ts +50 -0
- package/lib/browser/interceptors/WebSocket/index.d.ts +2 -0
- package/lib/browser/interceptors/WebSocket/{index.mjs → index.js} +39 -30
- package/lib/browser/interceptors/WebSocket/index.js.map +1 -0
- package/lib/browser/interceptors/XMLHttpRequest/web.d.ts +11 -0
- package/lib/browser/interceptors/XMLHttpRequest/web.js +2 -0
- package/lib/browser/interceptors/fetch/web.d.ts +14 -0
- package/lib/browser/interceptors/fetch/web.js +2 -0
- package/lib/browser/presets/browser.d.ts +11 -0
- package/lib/browser/presets/browser.js +12 -0
- package/lib/browser/presets/browser.js.map +1 -0
- package/lib/browser/{resolveWebSocketUrl-C83-x9iE.mjs → resolve-web-socket-url-CSvNPLGi.js} +3 -3
- package/lib/browser/resolve-web-socket-url-CSvNPLGi.js.map +1 -0
- package/lib/browser/{XMLHttpRequest-DrZAf3w6.mjs → web-BcKSQghf.js} +327 -255
- package/lib/browser/web-BcKSQghf.js.map +1 -0
- package/lib/browser/web-CdcYFjgm.js +248 -0
- package/lib/browser/web-CdcYFjgm.js.map +1 -0
- package/lib/browser/{interceptors/WebSocket/index.d.cts → websocket-CC0nB0md.d.ts} +41 -33
- package/lib/node/batch-interceptor-ByEZVih3.js +119 -0
- package/lib/node/batch-interceptor-ByEZVih3.js.map +1 -0
- package/lib/node/batch-interceptor-CPjFK2td.d.ts +28 -0
- package/lib/node/buffer-utils-BvPY1Tc-.js +187 -0
- package/lib/node/buffer-utils-BvPY1Tc-.js.map +1 -0
- package/lib/node/fetch-utils-Dw1PsmtX.js +568 -0
- package/lib/node/fetch-utils-Dw1PsmtX.js.map +1 -0
- package/lib/node/has-configurable-global-CJCh_g1I.js +22 -0
- package/lib/node/has-configurable-global-CJCh_g1I.js.map +1 -0
- package/lib/node/http-CB9rQ7i_.d.ts +105 -0
- package/lib/{browser/interceptors/WebSocket/index.d.mts → node/index.d.ts} +120 -60
- package/lib/node/{index.mjs → index.js} +8 -11
- package/lib/node/index.js.map +1 -0
- package/lib/node/interceptor-dtJZ_9QT.d.ts +50 -0
- package/lib/node/interceptors/ClientRequest/index.d.ts +14 -0
- package/lib/node/interceptors/ClientRequest/index.js +67 -0
- package/lib/node/interceptors/ClientRequest/index.js.map +1 -0
- package/lib/node/interceptors/XMLHttpRequest/node.d.ts +12 -0
- package/lib/node/interceptors/XMLHttpRequest/node.js +74 -0
- package/lib/node/interceptors/XMLHttpRequest/node.js.map +1 -0
- package/lib/node/interceptors/fetch/node.d.ts +18 -0
- package/lib/node/interceptors/fetch/node.js +83 -0
- package/lib/node/interceptors/fetch/node.js.map +1 -0
- package/lib/node/interceptors/http/index.d.ts +14 -0
- package/lib/node/interceptors/http/index.js +32 -0
- package/lib/node/interceptors/http/index.js.map +1 -0
- package/lib/node/interceptors/net/index.d.ts +203 -0
- package/lib/node/interceptors/net/index.js +2 -0
- package/lib/node/llhttp/constants.cjs +485 -0
- package/lib/node/llhttp/constants.d.cts +957 -0
- package/lib/node/llhttp/llhttp.wasm +0 -0
- package/lib/node/net-DtMnyEeg.js +1388 -0
- package/lib/node/net-DtMnyEeg.js.map +1 -0
- package/lib/node/presets/node.d.ts +12 -0
- package/lib/node/presets/node.js +17 -0
- package/lib/node/presets/node.js.map +1 -0
- package/lib/node/{RemoteHttpInterceptor.d.cts → remote-http-interceptor.d.ts} +12 -11
- package/lib/node/{RemoteHttpInterceptor.mjs → remote-http-interceptor.js} +38 -33
- package/lib/node/remote-http-interceptor.js.map +1 -0
- package/lib/node/source-lP0yyEtA.js +1990 -0
- package/lib/node/source-lP0yyEtA.js.map +1 -0
- package/package.json +79 -118
- package/src/batch-interceptor.test.ts +475 -0
- package/src/batch-interceptor.ts +244 -0
- package/src/{createRequestId.test.ts → create-request-id.test.ts} +1 -2
- package/src/disposable.ts +13 -0
- package/src/events/http.ts +92 -0
- package/src/events/websocket.ts +47 -0
- package/src/glossary.ts +1 -27
- package/src/index.ts +18 -10
- package/src/interceptor.test.ts +279 -0
- package/src/interceptor.ts +139 -0
- package/src/interceptors/ClientRequest/index.test.ts +21 -39
- package/src/interceptors/ClientRequest/index.ts +64 -179
- package/src/interceptors/ClientRequest/utils/{recordRawHeaders.test.ts → record-raw-headers.test.ts} +1 -2
- package/src/interceptors/ClientRequest/utils/{recordRawHeaders.ts → record-raw-headers.ts} +29 -2
- package/src/interceptors/WebSocket/index.ts +33 -50
- package/src/interceptors/WebSocket/utils/{bindEvent.test.ts → bind-event.test.ts} +1 -2
- package/src/interceptors/WebSocket/utils/events.test.ts +0 -1
- package/src/interceptors/WebSocket/{WebSocketClassTransport.ts → web-socket-class-transport.ts} +3 -3
- package/src/interceptors/WebSocket/{WebSocketClientConnection.ts → web-socket-client-connection.ts} +4 -4
- package/src/interceptors/WebSocket/{WebSocketOverride.ts → web-socket-override.ts} +6 -7
- package/src/interceptors/WebSocket/{WebSocketServerConnection.ts → web-socket-server-connection.ts} +4 -4
- package/src/interceptors/WebSocket/{WebSocketTransport.ts → web-socket-transport.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/node.ts +104 -0
- package/src/interceptors/XMLHttpRequest/polyfills/{ProgressEventPolyfill.ts → progress-event-polyfill.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{concateArrayBuffer.test.ts → concat-array-buffer.test.ts} +1 -2
- package/src/interceptors/XMLHttpRequest/utils/{concatArrayBuffer.ts → concat-array-buffer.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{createEvent.test.ts → create-event.test.ts} +3 -4
- package/src/interceptors/XMLHttpRequest/utils/{createEvent.ts → create-event.ts} +2 -2
- package/src/interceptors/XMLHttpRequest/utils/{createResponse.ts → create-response.ts} +1 -1
- package/src/interceptors/XMLHttpRequest/utils/{getBodyByteLength.test.ts → get-body-byte-length.test.ts} +1 -2
- package/src/interceptors/XMLHttpRequest/web.ts +34 -0
- package/src/interceptors/XMLHttpRequest/{XMLHttpRequestController.ts → xml-http-request-controller.ts} +363 -204
- package/src/interceptors/XMLHttpRequest/{XMLHttpRequestProxy.ts → xml-http-request-proxy.ts} +28 -25
- package/src/interceptors/fetch/node.ts +103 -0
- package/src/interceptors/fetch/utils/{followRedirect.ts → follow-redirect.ts} +1 -1
- package/src/interceptors/fetch/web.ts +217 -0
- package/src/interceptors/http/forward-events.test.ts +86 -0
- package/src/interceptors/http/forward-events.ts +139 -0
- package/src/interceptors/http/http-parser/index.ts +310 -0
- package/src/interceptors/http/http-parser/llhttp/constants.cjs +485 -0
- package/src/interceptors/http/http-parser/llhttp/constants.d.cts +957 -0
- package/src/interceptors/http/http-parser/llhttp/llhttp.wasm +0 -0
- package/src/interceptors/http/http-parser.ts +138 -0
- package/src/interceptors/http/index.ts +34 -0
- package/src/interceptors/http/source.ts +688 -0
- package/src/interceptors/net/index.ts +368 -0
- package/src/interceptors/net/socket-controller.ts +1476 -0
- package/src/interceptors/net/utils/address-info.ts +54 -0
- package/src/interceptors/net/utils/connection-options-to-url.ts +56 -0
- package/src/interceptors/net/utils/flush-writes.ts +57 -0
- package/src/interceptors/net/utils/get-tls-connect-options.ts +23 -0
- package/src/interceptors/net/utils/normalize-net-connect-args.test.ts +233 -0
- package/src/interceptors/net/utils/normalize-net-connect-args.ts +121 -0
- package/src/interceptors/net/utils/normalize-tls-connect-args.ts +50 -0
- package/src/presets/browser.ts +4 -4
- package/src/presets/node.ts +4 -4
- package/src/{RemoteHttpInterceptor.ts → remote-http-interceptor.ts} +55 -42
- package/src/request-context.ts +40 -0
- package/src/{RequestController.test.ts → request-controller.test.ts} +37 -3
- package/src/{RequestController.ts → request-controller.ts} +33 -11
- package/src/utils/{bufferUtils.test.ts → buffer-utils.test.ts} +1 -2
- package/src/utils/buffer-utils.ts +37 -0
- package/src/utils/{cloneObject.test.ts → clone-object.test.ts} +1 -2
- package/src/utils/{cloneObject.ts → clone-object.ts} +8 -8
- package/src/utils/{createProxy.test.ts → create-proxy.test.ts} +6 -4
- package/src/utils/{createProxy.ts → create-proxy.ts} +1 -1
- package/src/utils/{fetchUtils.test.ts → fetch-utils.test.ts} +1 -1
- package/src/utils/{fetchUtils.ts → fetch-utils.ts} +28 -3
- package/src/utils/{findPropertySource.test.ts → find-property-source.test.ts} +1 -2
- package/src/utils/{getCleanUrl.test.ts → get-clean-url.test.ts} +1 -2
- package/src/utils/{getUrlByRequestOptions.test.ts → get-url-by-request-options.test.ts} +4 -8
- package/src/utils/{getUrlByRequestOptions.ts → get-url-by-request-options.ts} +16 -16
- package/src/utils/{getValueBySymbol.test.ts → get-value-by-symbol.test.ts} +1 -2
- package/src/utils/{handleRequest.ts → handle-request.ts} +61 -41
- package/src/utils/{hasConfigurableGlobal.test.ts → has-configurable-global.test.ts} +1 -2
- package/src/utils/{hasConfigurableGlobal.ts → has-configurable-global.ts} +2 -4
- package/src/utils/{isObject.test.ts → is-object.test.ts} +1 -2
- package/src/utils/logger.test.ts +154 -0
- package/src/utils/logger.ts +154 -0
- package/src/utils/{parseJson.test.ts → parse-json.test.ts} +1 -2
- package/src/utils/{patchesRegistry.test.ts → patches-registry.test.ts} +1 -1
- package/src/utils/{patchesRegistry.ts → patches-registry.ts} +1 -1
- package/src/utils/{responseUtils.ts → response-utils.ts} +25 -2
- package/ClientRequest/package.json +0 -11
- package/RemoteHttpInterceptor/package.json +0 -11
- package/WebSocket/package.json +0 -12
- package/XMLHttpRequest/package.json +0 -12
- package/fetch/package.json +0 -12
- package/lib/browser/Interceptor-Deczogc8.d.cts +0 -65
- package/lib/browser/Interceptor-gqKgs-aF.d.mts +0 -65
- package/lib/browser/XMLHttpRequest-DrZAf3w6.mjs.map +0 -1
- package/lib/browser/XMLHttpRequest-gXuzzX1g.cjs +0 -751
- package/lib/browser/XMLHttpRequest-gXuzzX1g.cjs.map +0 -1
- package/lib/browser/bufferUtils-BiiO6HZv.mjs.map +0 -1
- package/lib/browser/bufferUtils-Uc0eRItL.cjs +0 -38
- package/lib/browser/bufferUtils-Uc0eRItL.cjs.map +0 -1
- package/lib/browser/createRequestId-DOf8Ktjs.cjs +0 -205
- package/lib/browser/createRequestId-DOf8Ktjs.cjs.map +0 -1
- package/lib/browser/createRequestId-DYCsFHOi.mjs +0 -170
- package/lib/browser/createRequestId-DYCsFHOi.mjs.map +0 -1
- package/lib/browser/fetch-5IMPqr9e.mjs +0 -236
- package/lib/browser/fetch-5IMPqr9e.mjs.map +0 -1
- package/lib/browser/fetch-Bt9rMY9c.cjs +0 -241
- package/lib/browser/fetch-Bt9rMY9c.cjs.map +0 -1
- package/lib/browser/getRawRequest-B1BqgWG6.mjs.map +0 -1
- package/lib/browser/getRawRequest-DdfaiPVH.cjs +0 -376
- package/lib/browser/getRawRequest-DdfaiPVH.cjs.map +0 -1
- package/lib/browser/glossary-1lhZx6Aw.d.cts +0 -69
- package/lib/browser/glossary-nkHWcwvY.d.mts +0 -69
- package/lib/browser/handleRequest-CJim54xG.cjs +0 -191
- package/lib/browser/handleRequest-CJim54xG.cjs.map +0 -1
- package/lib/browser/handleRequest-CPPgsG7s.mjs +0 -180
- package/lib/browser/handleRequest-CPPgsG7s.mjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-C8zq1MCg.mjs +0 -109
- package/lib/browser/hasConfigurableGlobal-C8zq1MCg.mjs.map +0 -1
- package/lib/browser/hasConfigurableGlobal-CS7adEvV.cjs +0 -126
- package/lib/browser/hasConfigurableGlobal-CS7adEvV.cjs.map +0 -1
- package/lib/browser/index.cjs +0 -70
- package/lib/browser/index.cjs.map +0 -1
- package/lib/browser/index.d.mts +0 -125
- package/lib/browser/index.mjs +0 -56
- package/lib/browser/index.mjs.map +0 -1
- package/lib/browser/interceptors/WebSocket/index.cjs +0 -618
- package/lib/browser/interceptors/WebSocket/index.cjs.map +0 -1
- package/lib/browser/interceptors/WebSocket/index.mjs.map +0 -1
- package/lib/browser/interceptors/XMLHttpRequest/index.cjs +0 -8
- package/lib/browser/interceptors/XMLHttpRequest/index.d.cts +0 -15
- package/lib/browser/interceptors/XMLHttpRequest/index.d.mts +0 -15
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +0 -8
- package/lib/browser/interceptors/fetch/index.cjs +0 -7
- package/lib/browser/interceptors/fetch/index.d.cts +0 -13
- package/lib/browser/interceptors/fetch/index.d.mts +0 -13
- package/lib/browser/interceptors/fetch/index.mjs +0 -7
- package/lib/browser/presets/browser.cjs +0 -18
- package/lib/browser/presets/browser.cjs.map +0 -1
- package/lib/browser/presets/browser.d.cts +0 -12
- package/lib/browser/presets/browser.d.mts +0 -14
- package/lib/browser/presets/browser.mjs +0 -18
- package/lib/browser/presets/browser.mjs.map +0 -1
- package/lib/browser/resolveWebSocketUrl-6K6EgqsA.cjs +0 -31
- package/lib/browser/resolveWebSocketUrl-6K6EgqsA.cjs.map +0 -1
- package/lib/browser/resolveWebSocketUrl-C83-x9iE.mjs.map +0 -1
- package/lib/node/BatchInterceptor-BGhH8z1z.cjs +0 -49
- package/lib/node/BatchInterceptor-BGhH8z1z.cjs.map +0 -1
- package/lib/node/BatchInterceptor-C4-RX5rg.mjs +0 -44
- package/lib/node/BatchInterceptor-C4-RX5rg.mjs.map +0 -1
- package/lib/node/BatchInterceptor-KKF8Q47I.d.cts +0 -26
- package/lib/node/BatchInterceptor-rSr-NH_H.d.mts +0 -26
- package/lib/node/ClientRequest-2loAH7xM.cjs +0 -1058
- package/lib/node/ClientRequest-2loAH7xM.cjs.map +0 -1
- package/lib/node/ClientRequest-DGhBX21V.mjs +0 -1049
- package/lib/node/ClientRequest-DGhBX21V.mjs.map +0 -1
- package/lib/node/Interceptor-BsZ21ue0.d.cts +0 -132
- package/lib/node/Interceptor-soD-WpQO.d.mts +0 -132
- package/lib/node/RemoteHttpInterceptor.cjs +0 -155
- package/lib/node/RemoteHttpInterceptor.cjs.map +0 -1
- package/lib/node/RemoteHttpInterceptor.d.mts +0 -39
- package/lib/node/RemoteHttpInterceptor.mjs.map +0 -1
- package/lib/node/XMLHttpRequest-BtDNZipW.cjs +0 -752
- package/lib/node/XMLHttpRequest-BtDNZipW.cjs.map +0 -1
- package/lib/node/XMLHttpRequest-Dw6Wm-UU.mjs +0 -746
- package/lib/node/XMLHttpRequest-Dw6Wm-UU.mjs.map +0 -1
- package/lib/node/bufferUtils-DxPxwff_.mjs +0 -20
- package/lib/node/bufferUtils-DxPxwff_.mjs.map +0 -1
- package/lib/node/bufferUtils-S5_-2eN4.cjs +0 -38
- package/lib/node/bufferUtils-S5_-2eN4.cjs.map +0 -1
- package/lib/node/chunk-CbDLau6x.cjs +0 -34
- package/lib/node/fetch-CaC3rGEu.mjs +0 -252
- package/lib/node/fetch-CaC3rGEu.mjs.map +0 -1
- package/lib/node/fetch-D2ClLNN-.cjs +0 -259
- package/lib/node/fetch-D2ClLNN-.cjs.map +0 -1
- package/lib/node/fetchUtils-BKJ1XmiO.mjs +0 -480
- package/lib/node/fetchUtils-BKJ1XmiO.mjs.map +0 -1
- package/lib/node/fetchUtils-umV5xXBy.cjs +0 -546
- package/lib/node/fetchUtils-umV5xXBy.cjs.map +0 -1
- package/lib/node/getRawRequest-B6znU6il.cjs +0 -36
- package/lib/node/getRawRequest-B6znU6il.cjs.map +0 -1
- package/lib/node/getRawRequest-C2-1urzA.mjs +0 -24
- package/lib/node/getRawRequest-C2-1urzA.mjs.map +0 -1
- package/lib/node/handleRequest-C-cKYjIh.cjs +0 -222
- package/lib/node/handleRequest-C-cKYjIh.cjs.map +0 -1
- package/lib/node/handleRequest-FIQv5pwH.mjs +0 -192
- package/lib/node/handleRequest-FIQv5pwH.mjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-BiTmog1u.mjs.map +0 -1
- package/lib/node/hasConfigurableGlobal-MjY06_Ok.cjs +0 -108
- package/lib/node/hasConfigurableGlobal-MjY06_Ok.cjs.map +0 -1
- package/lib/node/index-BJ5E5aW-.d.cts +0 -113
- package/lib/node/index-DfoF45ih.d.mts +0 -113
- package/lib/node/index.cjs +0 -53
- package/lib/node/index.cjs.map +0 -1
- package/lib/node/index.d.cts +0 -104
- package/lib/node/index.d.mts +0 -104
- package/lib/node/index.mjs.map +0 -1
- package/lib/node/interceptors/ClientRequest/index.cjs +0 -6
- package/lib/node/interceptors/ClientRequest/index.d.cts +0 -2
- package/lib/node/interceptors/ClientRequest/index.d.mts +0 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +0 -6
- package/lib/node/interceptors/XMLHttpRequest/index.cjs +0 -7
- package/lib/node/interceptors/XMLHttpRequest/index.d.cts +0 -14
- package/lib/node/interceptors/XMLHttpRequest/index.d.mts +0 -14
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +0 -7
- package/lib/node/interceptors/fetch/index.cjs +0 -6
- package/lib/node/interceptors/fetch/index.d.cts +0 -12
- package/lib/node/interceptors/fetch/index.d.mts +0 -12
- package/lib/node/interceptors/fetch/index.mjs +0 -6
- package/lib/node/node-DIKcnzhK.cjs +0 -39
- package/lib/node/node-DIKcnzhK.cjs.map +0 -1
- package/lib/node/node-lsdNwZEW.mjs +0 -27
- package/lib/node/node-lsdNwZEW.mjs.map +0 -1
- package/lib/node/presets/node.cjs +0 -23
- package/lib/node/presets/node.cjs.map +0 -1
- package/lib/node/presets/node.d.cts +0 -13
- package/lib/node/presets/node.d.mts +0 -15
- package/lib/node/presets/node.mjs +0 -23
- package/lib/node/presets/node.mjs.map +0 -1
- package/lib/node/utils/node/index.cjs +0 -4
- package/lib/node/utils/node/index.d.cts +0 -16
- package/lib/node/utils/node/index.d.mts +0 -16
- package/lib/node/utils/node/index.mjs +0 -3
- package/presets/browser/package.json +0 -5
- package/presets/node/package.json +0 -11
- package/src/BatchInterceptor.test.ts +0 -255
- package/src/BatchInterceptor.ts +0 -96
- package/src/Interceptor.test.ts +0 -205
- package/src/Interceptor.ts +0 -249
- package/src/getRawRequest.ts +0 -21
- package/src/interceptors/ClientRequest/MockHttpSocket.ts +0 -724
- package/src/interceptors/ClientRequest/agents.ts +0 -110
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.test.ts +0 -54
- package/src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts +0 -45
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.test.ts +0 -427
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +0 -268
- package/src/interceptors/ClientRequest/utils/parserUtils.ts +0 -48
- package/src/interceptors/Socket/MockSocket.test.ts +0 -264
- package/src/interceptors/Socket/MockSocket.ts +0 -58
- package/src/interceptors/Socket/utils/baseUrlFromConnectionOptions.ts +0 -26
- package/src/interceptors/Socket/utils/normalizeSocketWriteArgs.test.ts +0 -52
- package/src/interceptors/Socket/utils/normalizeSocketWriteArgs.ts +0 -33
- package/src/interceptors/XMLHttpRequest/index.ts +0 -40
- package/src/interceptors/fetch/index.ts +0 -203
- package/src/utils/bufferUtils.ts +0 -22
- package/src/utils/canParseUrl.ts +0 -13
- package/src/utils/emitAsync.ts +0 -25
- package/src/utils/nextTick.ts +0 -11
- package/src/utils/node/index.ts +0 -39
- /package/src/{createRequestId.ts → create-request-id.ts} +0 -0
- /package/src/{InterceptorError.ts → interceptor-error.ts} +0 -0
- /package/src/interceptors/WebSocket/utils/{bindEvent.ts → bind-event.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/polyfills/{EventPolyfill.ts → event-polyfill.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/utils/{getBodyByteLength.ts → get-body-byte-length.ts} +0 -0
- /package/src/interceptors/XMLHttpRequest/utils/{isDomParserSupportedType.ts → is-dom-parser-supported-type.ts} +0 -0
- /package/src/interceptors/fetch/utils/{createNetworkError.ts → create-network-error.ts} +0 -0
- /package/src/utils/{findPropertySource.ts → find-property-source.ts} +0 -0
- /package/src/utils/{getCleanUrl.ts → get-clean-url.ts} +0 -0
- /package/src/utils/{getValueBySymbol.ts → get-value-by-symbol.ts} +0 -0
- /package/src/utils/{isNodeLikeError.ts → is-node-like-error.ts} +0 -0
- /package/src/utils/{isObject.ts → is-object.ts} +0 -0
- /package/src/utils/{isPropertyAccessible.ts → is-property-accessible.ts} +0 -0
- /package/src/utils/{parseJson.ts → parse-json.ts} +0 -0
- /package/src/utils/{resolveWebSocketUrl.ts → resolve-web-socket-url.ts} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { a as getDeepPropertyDescriptor } from "./net-DtMnyEeg.js";
|
|
2
|
+
//#region src/utils/has-configurable-global.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns a boolean indicating whether the given global property
|
|
5
|
+
* is defined and is configurable.
|
|
6
|
+
*/
|
|
7
|
+
function hasConfigurableGlobal(propertyName) {
|
|
8
|
+
const match = getDeepPropertyDescriptor(globalThis, propertyName);
|
|
9
|
+
if (typeof match === "undefined") return false;
|
|
10
|
+
const { descriptor } = match;
|
|
11
|
+
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
12
|
+
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
13
|
+
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
14
|
+
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.`);
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { hasConfigurableGlobal as t };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=has-configurable-global-CJCh_g1I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-configurable-global-CJCh_g1I.js","names":[],"sources":["../../src/utils/has-configurable-global.ts"],"sourcesContent":["import { getDeepPropertyDescriptor } from './patches-registry'\n\n/**\n * Returns a boolean indicating whether the given global property\n * is defined and is configurable.\n */\nexport function hasConfigurableGlobal(propertyName: string): boolean {\n const match = getDeepPropertyDescriptor(globalThis, propertyName)\n\n // The property is not set at all.\n if (typeof match === 'undefined') {\n return false\n }\n\n const { descriptor } = match\n\n // The property is set to a getter that returns undefined.\n if (\n typeof descriptor.get === 'function' &&\n typeof descriptor.get() === 'undefined'\n ) {\n return false\n }\n\n // The property is set to a value equal to undefined.\n if (typeof descriptor.get === 'undefined' && descriptor.value == null) {\n return false\n }\n\n if (typeof descriptor.set === 'undefined' && !descriptor.configurable) {\n console.error(\n `[MSW] Failed to apply interceptor: the global \\`${propertyName}\\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`\n )\n return false\n }\n\n return true\n}\n"],"mappings":";;;;;;AAMA,SAAgB,sBAAsB,cAA+B;CACnE,MAAM,QAAQ,0BAA0B,YAAY,YAAY;CAGhE,IAAI,OAAO,UAAU,aACnB,OAAO;CAGT,MAAM,EAAE,eAAe;CAGvB,IACE,OAAO,WAAW,QAAQ,cAC1B,OAAO,WAAW,IAAI,MAAM,aAE5B,OAAO;CAIT,IAAI,OAAO,WAAW,QAAQ,eAAe,WAAW,SAAS,MAC/D,OAAO;CAGT,IAAI,OAAO,WAAW,QAAQ,eAAe,CAAC,WAAW,cAAc;EACrE,QAAQ,MACN,mDAAmD,aAAa,mKAClE;EACA,OAAO;CACT;CAEA,OAAO;AACT"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { n as Logger } from "./interceptor-dtJZ_9QT.js";
|
|
2
|
+
import { TypedEvent } from "rettime";
|
|
3
|
+
//#region src/request-controller.d.ts
|
|
4
|
+
interface RequestControllerSource {
|
|
5
|
+
passthrough(): void | Promise<void>;
|
|
6
|
+
respondWith(response: Response): void | Promise<void>;
|
|
7
|
+
errorWith(reason?: unknown): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
interface RequestControllerOptions {
|
|
10
|
+
logger: Logger;
|
|
11
|
+
requestId: string;
|
|
12
|
+
}
|
|
13
|
+
declare class RequestController {
|
|
14
|
+
#private;
|
|
15
|
+
protected readonly request: Request;
|
|
16
|
+
protected readonly source: RequestControllerSource;
|
|
17
|
+
protected readonly options?: RequestControllerOptions | undefined;
|
|
18
|
+
static PENDING: 0;
|
|
19
|
+
static PASSTHROUGH: 1;
|
|
20
|
+
static RESPONSE: 2;
|
|
21
|
+
static ERROR: 3;
|
|
22
|
+
readyState: number;
|
|
23
|
+
/**
|
|
24
|
+
* A Promise that resolves when this controller handles a request.
|
|
25
|
+
* See `controller.readyState` for more information on the handling result.
|
|
26
|
+
*/
|
|
27
|
+
handled: Promise<void>;
|
|
28
|
+
constructor(request: Request, source: RequestControllerSource, options?: RequestControllerOptions | undefined);
|
|
29
|
+
/**
|
|
30
|
+
* Perform this request as-is.
|
|
31
|
+
*/
|
|
32
|
+
passthrough(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Respond to this request with the given `Response` instance.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* controller.respondWith(new Response())
|
|
38
|
+
* controller.respondWith(Response.json({ id }))
|
|
39
|
+
* controller.respondWith(Response.error())
|
|
40
|
+
*/
|
|
41
|
+
respondWith(response: Response): void;
|
|
42
|
+
/**
|
|
43
|
+
* Error this request with the given reason.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* controller.errorWith()
|
|
47
|
+
* controller.errorWith(new Error('Oops!'))
|
|
48
|
+
* controller.errorWith({ message: 'Oops!'})
|
|
49
|
+
*/
|
|
50
|
+
errorWith(reason?: unknown): void;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/events/http.d.ts
|
|
54
|
+
interface HttpRequestEventData {
|
|
55
|
+
request: Request;
|
|
56
|
+
requestId: string;
|
|
57
|
+
initiator: unknown;
|
|
58
|
+
controller: RequestController;
|
|
59
|
+
}
|
|
60
|
+
declare class HttpRequestEvent<DataType extends HttpRequestEventData = HttpRequestEventData> extends TypedEvent<DataType, void, 'request'> {
|
|
61
|
+
request: Request;
|
|
62
|
+
requestId: string;
|
|
63
|
+
initiator: unknown;
|
|
64
|
+
controller: RequestController;
|
|
65
|
+
constructor(data: DataType);
|
|
66
|
+
}
|
|
67
|
+
type HttpResponseType = 'mock' | 'original';
|
|
68
|
+
interface HttpResponseEventData {
|
|
69
|
+
response: Response;
|
|
70
|
+
responseType: HttpResponseType;
|
|
71
|
+
request: Request;
|
|
72
|
+
requestId: string;
|
|
73
|
+
initiator: unknown;
|
|
74
|
+
}
|
|
75
|
+
declare class HttpResponseEvent<DataType extends HttpResponseEventData = HttpResponseEventData> extends TypedEvent<DataType, void, 'response'> {
|
|
76
|
+
response: Response;
|
|
77
|
+
responseType: HttpResponseType;
|
|
78
|
+
request: Request;
|
|
79
|
+
requestId: string;
|
|
80
|
+
initiator: unknown;
|
|
81
|
+
constructor(data: DataType);
|
|
82
|
+
}
|
|
83
|
+
interface UnhandledHttpExceptionEventData {
|
|
84
|
+
error: unknown;
|
|
85
|
+
request: Request;
|
|
86
|
+
requestId: string;
|
|
87
|
+
initiator: unknown;
|
|
88
|
+
controller: RequestController;
|
|
89
|
+
}
|
|
90
|
+
declare class UnhandledHttpException<DataType extends UnhandledHttpExceptionEventData = UnhandledHttpExceptionEventData> extends TypedEvent<DataType, void, 'unhandledException'> {
|
|
91
|
+
error: unknown;
|
|
92
|
+
request: Request;
|
|
93
|
+
requestId: string;
|
|
94
|
+
initiator: unknown;
|
|
95
|
+
controller: RequestController;
|
|
96
|
+
constructor(data: DataType);
|
|
97
|
+
}
|
|
98
|
+
type HttpRequestEventMap = {
|
|
99
|
+
request: HttpRequestEvent;
|
|
100
|
+
response: HttpResponseEvent;
|
|
101
|
+
unhandledException: UnhandledHttpException;
|
|
102
|
+
};
|
|
103
|
+
//#endregion
|
|
104
|
+
export { RequestControllerSource as a, RequestController as i, HttpRequestEventMap as n, HttpResponseEvent as r, HttpRequestEvent as t };
|
|
105
|
+
//# sourceMappingURL=http-CB9rQ7i_.d.ts.map
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* in Node.js. It's rather non-intrusive so it can be safely
|
|
9
|
-
* used in the browser as well.
|
|
10
|
-
*
|
|
11
|
-
* @see https://github.com/nodejs/node/issues/51767
|
|
12
|
-
*/
|
|
13
|
-
declare class CancelableMessageEvent<T = any> extends MessageEvent<T> {
|
|
14
|
-
[kCancelable]: boolean;
|
|
15
|
-
[kDefaultPrevented]: boolean;
|
|
16
|
-
constructor(type: string, init: MessageEventInit<T>);
|
|
17
|
-
get cancelable(): boolean;
|
|
18
|
-
set cancelable(nextCancelable: boolean);
|
|
19
|
-
get defaultPrevented(): boolean;
|
|
20
|
-
set defaultPrevented(nextDefaultPrevented: boolean);
|
|
21
|
-
preventDefault(): void;
|
|
1
|
+
import { t as Interceptor } from "./interceptor-dtJZ_9QT.js";
|
|
2
|
+
import { t as BatchInterceptor } from "./batch-interceptor-CPjFK2td.js";
|
|
3
|
+
import { a as RequestControllerSource, i as RequestController, n as HttpRequestEventMap, r as HttpResponseEvent, t as HttpRequestEvent } from "./http-CB9rQ7i_.js";
|
|
4
|
+
import { TypedEvent } from "rettime";
|
|
5
|
+
//#region src/interceptor-error.d.ts
|
|
6
|
+
declare class InterceptorError extends Error {
|
|
7
|
+
constructor(message?: string);
|
|
22
8
|
}
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/interceptors/WebSocket/utils/events.d.ts
|
|
23
11
|
interface CloseEventInit extends EventInit {
|
|
24
12
|
code?: number;
|
|
25
13
|
reason?: string;
|
|
@@ -31,19 +19,9 @@ declare class CloseEvent extends Event {
|
|
|
31
19
|
wasClean: boolean;
|
|
32
20
|
constructor(type: string, init?: CloseEventInit);
|
|
33
21
|
}
|
|
34
|
-
declare class CancelableCloseEvent extends CloseEvent {
|
|
35
|
-
[kCancelable]: boolean;
|
|
36
|
-
[kDefaultPrevented]: boolean;
|
|
37
|
-
constructor(type: string, init?: CloseEventInit);
|
|
38
|
-
get cancelable(): boolean;
|
|
39
|
-
set cancelable(nextCancelable: boolean);
|
|
40
|
-
get defaultPrevented(): boolean;
|
|
41
|
-
set defaultPrevented(nextDefaultPrevented: boolean);
|
|
42
|
-
preventDefault(): void;
|
|
43
|
-
}
|
|
44
22
|
//#endregion
|
|
45
|
-
//#region src/interceptors/WebSocket/
|
|
46
|
-
type WebSocketData = string |
|
|
23
|
+
//#region src/interceptors/WebSocket/web-socket-transport.d.ts
|
|
24
|
+
type WebSocketData = string | ArrayBuffer | Blob | ArrayBufferView<ArrayBuffer>;
|
|
47
25
|
type WebSocketTransportEventMap = {
|
|
48
26
|
incoming: MessageEvent<WebSocketData>;
|
|
49
27
|
outgoing: MessageEvent<WebSocketData>;
|
|
@@ -65,7 +43,7 @@ interface WebSocketTransport {
|
|
|
65
43
|
close(code?: number, reason?: string): void;
|
|
66
44
|
}
|
|
67
45
|
//#endregion
|
|
68
|
-
//#region src/interceptors/WebSocket/
|
|
46
|
+
//#region src/interceptors/WebSocket/web-socket-override.d.ts
|
|
69
47
|
type WebSocketEventListener<EventType extends WebSocketEventMap[keyof WebSocketEventMap] = Event> = (this: WebSocket, event: EventType) => void;
|
|
70
48
|
declare const kPassthroughPromise: unique symbol;
|
|
71
49
|
declare const kOnSend: unique symbol;
|
|
@@ -111,7 +89,7 @@ declare class WebSocketOverride extends EventTarget implements WebSocket {
|
|
|
111
89
|
removeEventListener<K extends keyof WebSocketEventMap>(type: K, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;
|
|
112
90
|
}
|
|
113
91
|
//#endregion
|
|
114
|
-
//#region src/interceptors/WebSocket/
|
|
92
|
+
//#region src/interceptors/WebSocket/web-socket-client-connection.d.ts
|
|
115
93
|
declare const kEmitter$1: unique symbol;
|
|
116
94
|
interface WebSocketClientEventMap {
|
|
117
95
|
message: MessageEvent<WebSocketData>;
|
|
@@ -157,7 +135,7 @@ declare class WebSocketClientConnection implements WebSocketClientConnectionProt
|
|
|
157
135
|
close(code?: number, reason?: string): void;
|
|
158
136
|
}
|
|
159
137
|
//#endregion
|
|
160
|
-
//#region src/interceptors/WebSocket/
|
|
138
|
+
//#region src/interceptors/WebSocket/web-socket-class-transport.d.ts
|
|
161
139
|
/**
|
|
162
140
|
* Abstraction over the given mock `WebSocket` instance that allows
|
|
163
141
|
* for controlling that instance (e.g. sending and receiving messages).
|
|
@@ -171,7 +149,7 @@ declare class WebSocketClassTransport extends EventTarget implements WebSocketTr
|
|
|
171
149
|
close(code: number, reason?: string): void;
|
|
172
150
|
}
|
|
173
151
|
//#endregion
|
|
174
|
-
//#region src/interceptors/WebSocket/
|
|
152
|
+
//#region src/interceptors/WebSocket/web-socket-server-connection.d.ts
|
|
175
153
|
declare const kEmitter: unique symbol;
|
|
176
154
|
declare const kSend: unique symbol;
|
|
177
155
|
interface WebSocketServerEventMap {
|
|
@@ -239,11 +217,17 @@ declare class WebSocketServerConnection implements WebSocketServerConnectionProt
|
|
|
239
217
|
private handleRealClose;
|
|
240
218
|
}
|
|
241
219
|
//#endregion
|
|
242
|
-
//#region src/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
220
|
+
//#region src/events/websocket.d.ts
|
|
221
|
+
/**
|
|
222
|
+
* The connection information.
|
|
223
|
+
*/
|
|
224
|
+
interface WebSocketConnectionInfo {
|
|
225
|
+
/**
|
|
226
|
+
* The protocols supported by the WebSocket client.
|
|
227
|
+
*/
|
|
228
|
+
protocols: string | Array<string> | undefined;
|
|
229
|
+
}
|
|
230
|
+
interface WebSocketConnectionEventData {
|
|
247
231
|
/**
|
|
248
232
|
* The incoming WebSocket client connection.
|
|
249
233
|
*/
|
|
@@ -252,26 +236,102 @@ type WebSocketConnectionData = {
|
|
|
252
236
|
* The original WebSocket server connection.
|
|
253
237
|
*/
|
|
254
238
|
server: WebSocketServerConnection;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
239
|
+
info: WebSocketConnectionInfo;
|
|
240
|
+
}
|
|
241
|
+
declare class WebSocketConnectionEvent<DataType extends WebSocketConnectionEventData = WebSocketConnectionEventData> extends TypedEvent<DataType, void, 'connection'> {
|
|
242
|
+
client: WebSocketClientConnection;
|
|
243
|
+
server: WebSocketServerConnection;
|
|
244
|
+
info: WebSocketConnectionInfo;
|
|
245
|
+
constructor(data: DataType);
|
|
246
|
+
}
|
|
247
|
+
type WebSocketEventMap$1 = {
|
|
248
|
+
connection: WebSocketConnectionEvent;
|
|
264
249
|
};
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/create-request-id.d.ts
|
|
265
252
|
/**
|
|
266
|
-
*
|
|
267
|
-
*
|
|
253
|
+
* Generate a random ID string to represent a request.
|
|
254
|
+
* @example
|
|
255
|
+
* createRequestId()
|
|
256
|
+
* // "f774b6c9c600f"
|
|
268
257
|
*/
|
|
269
|
-
declare
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
258
|
+
declare function createRequestId(): string;
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/utils/get-clean-url.d.ts
|
|
261
|
+
/**
|
|
262
|
+
* Removes query parameters and hashes from a given URL.
|
|
263
|
+
*/
|
|
264
|
+
declare function getCleanUrl(url: URL, isAbsolute?: boolean): string;
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/utils/buffer-utils.d.ts
|
|
267
|
+
declare function encodeBuffer(text: string): Uint8Array<ArrayBuffer>;
|
|
268
|
+
declare function decodeBuffer(buffer: AllowSharedBufferSource, encoding?: string): string;
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/utils/fetch-utils.d.ts
|
|
271
|
+
interface FetchRequestInit extends Omit<RequestInit, 'mode'> {
|
|
272
|
+
mode?: RequestMode | 'websocket' | 'webtransport';
|
|
273
|
+
duplex?: 'half' | 'full';
|
|
274
|
+
}
|
|
275
|
+
declare class FetchRequest extends Request {
|
|
276
|
+
#private;
|
|
277
|
+
/**
|
|
278
|
+
* Check if the given request method is configurable.
|
|
279
|
+
* @see https://fetch.spec.whatwg.org/#methods
|
|
280
|
+
*/
|
|
281
|
+
static isConfigurableMethod(method: string): boolean;
|
|
282
|
+
static isMethodWithBody(method: string): boolean;
|
|
283
|
+
/**
|
|
284
|
+
* Check if the given request `mode` is configurable.
|
|
285
|
+
* @see https://fetch.spec.whatwg.org/#concept-request-mode
|
|
286
|
+
*/
|
|
287
|
+
static isConfigurableMode(mode: string): boolean;
|
|
288
|
+
constructor(input: URL | RequestInfo, init?: FetchRequestInit);
|
|
274
289
|
}
|
|
290
|
+
interface FetchResponseInit extends ResponseInit {
|
|
291
|
+
url?: string;
|
|
292
|
+
}
|
|
293
|
+
declare class FetchResponse extends Response {
|
|
294
|
+
#private;
|
|
295
|
+
static from(response: Response, init?: FetchResponseInit): FetchResponse;
|
|
296
|
+
/**
|
|
297
|
+
* Response status codes for responses that cannot have body.
|
|
298
|
+
* @see https://fetch.spec.whatwg.org/#statuses
|
|
299
|
+
*/
|
|
300
|
+
static readonly STATUS_CODES_WITHOUT_BODY: number[];
|
|
301
|
+
static readonly STATUS_CODES_WITH_REDIRECT: number[];
|
|
302
|
+
static isConfigurableStatusCode(status: number): boolean;
|
|
303
|
+
static isRedirectResponse(status: number): boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Returns a boolean indicating whether the given response status
|
|
306
|
+
* code represents a response that can have a body.
|
|
307
|
+
*/
|
|
308
|
+
static isResponseWithBody(status: number): boolean;
|
|
309
|
+
static setStatus(status: number, response: Response): void;
|
|
310
|
+
static setUrl(url: string | undefined, response: Response): void;
|
|
311
|
+
/**
|
|
312
|
+
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
|
313
|
+
*/
|
|
314
|
+
static parseRawHeaders(rawHeaders: Array<string>): Headers;
|
|
315
|
+
/**
|
|
316
|
+
* Safely clones the given `Response`.
|
|
317
|
+
* Coerces response clone exceptions into 500 mocked responses.
|
|
318
|
+
* Handy in the environments that introduce arbitrary response
|
|
319
|
+
* cloning restrictions, like "101 Switching Protocols" cloning
|
|
320
|
+
* in "miniflare".
|
|
321
|
+
*/
|
|
322
|
+
static clone(response: Response): Response;
|
|
323
|
+
constructor(body?: BodyInit | null, init?: FetchResponseInit);
|
|
324
|
+
clone(): Response;
|
|
325
|
+
}
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/utils/resolve-web-socket-url.d.ts
|
|
328
|
+
/**
|
|
329
|
+
* Resolve potentially relative WebSocket URLs the same way
|
|
330
|
+
* the browser does (replace the protocol, use the origin, etc).
|
|
331
|
+
*
|
|
332
|
+
* @see https://websockets.spec.whatwg.org//#dom-websocket-websocket
|
|
333
|
+
*/
|
|
334
|
+
declare function resolveWebSocketUrl(url: string | URL): string;
|
|
275
335
|
//#endregion
|
|
276
|
-
export {
|
|
277
|
-
//# sourceMappingURL=index.d.
|
|
336
|
+
export { BatchInterceptor, FetchRequest, FetchResponse, type HttpRequestEvent, type HttpRequestEventMap, type HttpResponseEvent, Interceptor, InterceptorError, RequestController, type RequestControllerSource, type WebSocketConnectionEvent, type WebSocketEventMap$1 as WebSocketEventMap, createRequestId, decodeBuffer, encodeBuffer, getCleanUrl, resolveWebSocketUrl };
|
|
337
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as BatchInterceptor } from "./
|
|
3
|
-
import { n as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//#region src/utils/getCleanUrl.ts
|
|
1
|
+
import { i as Interceptor, n as encodeBuffer, t as decodeBuffer } from "./buffer-utils-BvPY1Tc-.js";
|
|
2
|
+
import { t as BatchInterceptor } from "./batch-interceptor-ByEZVih3.js";
|
|
3
|
+
import { d as createRequestId, f as RequestController, n as FetchResponse, p as InterceptorError, t as FetchRequest } from "./fetch-utils-Dw1PsmtX.js";
|
|
4
|
+
//#region src/utils/get-clean-url.ts
|
|
7
5
|
/**
|
|
8
6
|
* Removes query parameters and hashes from a given URL.
|
|
9
7
|
*/
|
|
10
8
|
function getCleanUrl(url, isAbsolute = true) {
|
|
11
9
|
return [isAbsolute && url.origin, url.pathname].filter(Boolean).join("");
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
//#endregion
|
|
15
|
-
//#region src/utils/
|
|
12
|
+
//#region src/utils/resolve-web-socket-url.ts
|
|
16
13
|
/**
|
|
17
14
|
* Resolve potentially relative WebSocket URLs the same way
|
|
18
15
|
* the browser does (replace the protocol, use the origin, etc).
|
|
@@ -33,7 +30,7 @@ function resolveWebSocketUrl(url) {
|
|
|
33
30
|
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.`);
|
|
34
31
|
return url.href;
|
|
35
32
|
}
|
|
36
|
-
|
|
37
33
|
//#endregion
|
|
38
|
-
export { BatchInterceptor, FetchRequest, FetchResponse,
|
|
39
|
-
|
|
34
|
+
export { BatchInterceptor, FetchRequest, FetchResponse, Interceptor, InterceptorError, RequestController, createRequestId, decodeBuffer, encodeBuffer, getCleanUrl, resolveWebSocketUrl };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/utils/get-clean-url.ts","../../src/utils/resolve-web-socket-url.ts"],"sourcesContent":["/**\n * Removes query parameters and hashes from a given URL.\n */\nexport function getCleanUrl(url: URL, isAbsolute: boolean = true): string {\n return [isAbsolute && url.origin, url.pathname].filter(Boolean).join('')\n}\n","/**\n * Resolve potentially relative WebSocket URLs the same way\n * the browser does (replace the protocol, use the origin, etc).\n *\n * @see https://websockets.spec.whatwg.org//#dom-websocket-websocket\n */\nexport function resolveWebSocketUrl(url: string | URL): string {\n if (typeof url === 'string') {\n /**\n * @note Cast the string to a URL first so the parsing errors\n * are thrown as a part of the WebSocket constructor, not consumers.\n */\n const urlRecord = new URL(\n url,\n typeof location !== 'undefined' ? location.href : undefined\n )\n\n return resolveWebSocketUrl(urlRecord)\n }\n\n if (url.protocol === 'http:') {\n url.protocol = 'ws:'\n } else if (url.protocol === 'https:') {\n url.protocol = 'wss:'\n }\n\n if (url.protocol !== 'ws:' && url.protocol !== 'wss:') {\n /**\n * @note These errors are modeled after the browser errors.\n * The exact error messages aren't provided in the specification.\n * Node.js uses more obscure error messages that I don't wish to replicate.\n */\n throw new SyntaxError(\n `Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`\n )\n }\n\n if (url.hash !== '') {\n throw new SyntaxError(\n `Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`\n )\n }\n\n return url.href\n}\n"],"mappings":";;;;;;;AAGA,SAAgB,YAAY,KAAU,aAAsB,MAAc;CACxE,OAAO,CAAC,cAAc,IAAI,QAAQ,IAAI,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,EAAE;AACzE;;;;;;;;;ACCA,SAAgB,oBAAoB,KAA2B;CAC7D,IAAI,OAAO,QAAQ,UAUjB,OAAO,oBAAoB,IALL,IACpB,KACA,OAAO,aAAa,cAAc,SAAS,OAAO,KAAA,CAGjB,CAAC;CAGtC,IAAI,IAAI,aAAa,SACnB,IAAI,WAAW;MACV,IAAI,IAAI,aAAa,UAC1B,IAAI,WAAW;CAGjB,IAAI,IAAI,aAAa,SAAS,IAAI,aAAa;;;;;;CAM7C,MAAM,IAAI,YACR,sGAAsG,IAAI,SAAS,kBACrH;CAGF,IAAI,IAAI,SAAS,IACf,MAAM,IAAI,YACR,6EAA6E,IAAI,KAAK,4DACxF;CAGF,OAAO,IAAI;AACb"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { DefaultEventMap, Emitter } from "rettime";
|
|
2
|
+
//#region src/disposable.d.ts
|
|
3
|
+
type DisposableSubscription = () => void;
|
|
4
|
+
declare class Disposable {
|
|
5
|
+
protected subscriptions: Array<DisposableSubscription>;
|
|
6
|
+
dispose(): void;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/utils/logger.d.ts
|
|
10
|
+
type LogLevel = 'default' | 'verbose';
|
|
11
|
+
interface Logger {
|
|
12
|
+
info(message: string, ...positionals: Array<unknown>): void;
|
|
13
|
+
verbose(message: string, ...positionals: Array<unknown>): void;
|
|
14
|
+
isEnabled(level: LogLevel): boolean;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/interceptor.d.ts
|
|
18
|
+
declare enum InterceptorReadyState {
|
|
19
|
+
INACTIVE = "INACTIVE",
|
|
20
|
+
ACTIVE = "ACTIVE",
|
|
21
|
+
DISPOSED = "DISPOSED"
|
|
22
|
+
}
|
|
23
|
+
declare global {
|
|
24
|
+
var __MSW_INTERCEPTORS_REGISTRY: Map<symbol, Interceptor<any>> | undefined;
|
|
25
|
+
}
|
|
26
|
+
declare abstract class Interceptor<Events extends DefaultEventMap> extends Disposable {
|
|
27
|
+
#private;
|
|
28
|
+
['constructor']: typeof Interceptor;
|
|
29
|
+
protected emitter: Emitter<Events>;
|
|
30
|
+
protected readonly logger: Logger;
|
|
31
|
+
readyState: InterceptorReadyState;
|
|
32
|
+
static readonly symbol: symbol;
|
|
33
|
+
static singleton<T extends Interceptor<any>>(InterceptorClass: (new () => T) & {
|
|
34
|
+
symbol: symbol;
|
|
35
|
+
}): T;
|
|
36
|
+
constructor();
|
|
37
|
+
protected abstract predicate(): boolean;
|
|
38
|
+
protected abstract setup(): void;
|
|
39
|
+
apply(owner?: object): void;
|
|
40
|
+
dispose(owner?: object): void;
|
|
41
|
+
on: Emitter<Events>['on'];
|
|
42
|
+
once: Emitter<Events>['once'];
|
|
43
|
+
listeners: Emitter<Events>['listeners'];
|
|
44
|
+
listenerCount: Emitter<Events>['listenerCount'];
|
|
45
|
+
removeListener: Emitter<Events>['removeListener'];
|
|
46
|
+
removeAllListeners: Emitter<Events>['removeAllListeners'];
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { Logger as n, Interceptor as t };
|
|
50
|
+
//# sourceMappingURL=interceptor-dtJZ_9QT.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { t as Interceptor } from "../../interceptor-dtJZ_9QT.js";
|
|
2
|
+
import { n as HttpRequestEventMap } from "../../http-CB9rQ7i_.js";
|
|
3
|
+
//#region src/interceptors/ClientRequest/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Interceptor for HTTP requests in Node.js made via `http.ClientRequest`.
|
|
6
|
+
*/
|
|
7
|
+
declare class ClientRequestInterceptor extends Interceptor<HttpRequestEventMap> {
|
|
8
|
+
static symbol: symbol;
|
|
9
|
+
protected predicate(): boolean;
|
|
10
|
+
protected setup(): void;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ClientRequestInterceptor };
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { i as forwardHttpEvents, o as runInRequestContext, t as NodeHttpRequestSource } from "../../source-lP0yyEtA.js";
|
|
2
|
+
import { i as Interceptor } from "../../buffer-utils-BvPY1Tc-.js";
|
|
3
|
+
import { o as patchesRegistry } from "../../net-DtMnyEeg.js";
|
|
4
|
+
import http from "node:http";
|
|
5
|
+
import https from "node:https";
|
|
6
|
+
//#region src/interceptors/ClientRequest/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* Interceptor for HTTP requests in Node.js made via `http.ClientRequest`.
|
|
9
|
+
*/
|
|
10
|
+
var ClientRequestInterceptor = class extends Interceptor {
|
|
11
|
+
static {
|
|
12
|
+
this.symbol = Symbol.for("client-request-interceptor");
|
|
13
|
+
}
|
|
14
|
+
predicate() {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
setup() {
|
|
18
|
+
const requestSource = Interceptor.singleton(NodeHttpRequestSource);
|
|
19
|
+
const requestLogger = this.logger;
|
|
20
|
+
requestSource.apply(this);
|
|
21
|
+
this.subscriptions.push(() => {
|
|
22
|
+
requestSource.dispose(this);
|
|
23
|
+
});
|
|
24
|
+
this.subscriptions.push(forwardHttpEvents({
|
|
25
|
+
source: requestSource,
|
|
26
|
+
emitter: this.emitter,
|
|
27
|
+
predicate: (initiator) => {
|
|
28
|
+
return initiator instanceof http.ClientRequest;
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
this.subscriptions.push(patchesRegistry.applyPatch(http, "ClientRequest", (ClientRequest) => {
|
|
32
|
+
return new Proxy(ClientRequest, { construct(target, args, newTarget) {
|
|
33
|
+
return runInRequestContext(() => {
|
|
34
|
+
return Reflect.construct(target, args, newTarget);
|
|
35
|
+
}, requestLogger);
|
|
36
|
+
} });
|
|
37
|
+
}), patchesRegistry.applyPatch(http, "get", (httpGet) => {
|
|
38
|
+
return function mockHttpGet(...args) {
|
|
39
|
+
return runInRequestContext(() => {
|
|
40
|
+
return httpGet(...args);
|
|
41
|
+
}, requestLogger);
|
|
42
|
+
};
|
|
43
|
+
}), patchesRegistry.applyPatch(http, "request", (httpRequest) => {
|
|
44
|
+
return function mockHttpRequest(...args) {
|
|
45
|
+
return runInRequestContext(() => {
|
|
46
|
+
return httpRequest(...args);
|
|
47
|
+
}, requestLogger);
|
|
48
|
+
};
|
|
49
|
+
}), patchesRegistry.applyPatch(https, "get", (httpsGet) => {
|
|
50
|
+
return function mockHttpsGet(...args) {
|
|
51
|
+
return runInRequestContext(() => {
|
|
52
|
+
return httpsGet(...args);
|
|
53
|
+
}, requestLogger);
|
|
54
|
+
};
|
|
55
|
+
}), patchesRegistry.applyPatch(https, "request", (httpsRequest) => {
|
|
56
|
+
return function mockHttpsRequest(...args) {
|
|
57
|
+
return runInRequestContext(() => {
|
|
58
|
+
return httpsRequest(...args);
|
|
59
|
+
}, requestLogger);
|
|
60
|
+
};
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ClientRequestInterceptor };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/interceptors/ClientRequest/index.ts"],"sourcesContent":["import http from 'node:http'\nimport https from 'node:https'\nimport { runInRequestContext } from '#/src/request-context'\nimport { patchesRegistry } from '#/src/utils/patches-registry'\nimport { forwardHttpEvents } from '#/src/interceptors/http/forward-events'\nimport { NodeHttpRequestSource } from '#/src/interceptors/http/source'\nimport { Interceptor } from '../../interceptor'\nimport { HttpRequestEventMap } from '#/src/events/http'\n\n/**\n * Interceptor for HTTP requests in Node.js made via `http.ClientRequest`.\n */\nexport class ClientRequestInterceptor extends Interceptor<HttpRequestEventMap> {\n static symbol = Symbol.for('client-request-interceptor')\n\n protected predicate(): boolean {\n return true\n }\n\n protected setup(): void {\n const requestSource = Interceptor.singleton(NodeHttpRequestSource)\n const requestLogger = this.logger\n requestSource.apply(this)\n this.subscriptions.push(() => {\n requestSource.dispose(this)\n })\n\n this.subscriptions.push(\n forwardHttpEvents({\n source: requestSource,\n emitter: this.emitter,\n predicate: (initiator) => {\n return initiator instanceof http.ClientRequest\n },\n })\n )\n\n this.subscriptions.push(\n patchesRegistry.applyPatch(http, 'ClientRequest', (ClientRequest) => {\n return new Proxy(ClientRequest, {\n construct(target, args, newTarget) {\n return runInRequestContext(() => {\n return Reflect.construct(target, args, newTarget)\n }, requestLogger)\n },\n })\n }),\n patchesRegistry.applyPatch(http, 'get', (httpGet) => {\n return function mockHttpGet(...args) {\n return runInRequestContext(() => {\n return httpGet(...(args as [any, any]))\n }, requestLogger)\n }\n }),\n patchesRegistry.applyPatch(http, 'request', (httpRequest) => {\n return function mockHttpRequest(...args) {\n return runInRequestContext(() => {\n return httpRequest(...(args as [any, any]))\n }, requestLogger)\n }\n }),\n patchesRegistry.applyPatch(https, 'get', (httpsGet) => {\n return function mockHttpsGet(...args) {\n return runInRequestContext(() => {\n return httpsGet(...(args as [any, any]))\n }, requestLogger)\n }\n }),\n patchesRegistry.applyPatch(https, 'request', (httpsRequest) => {\n return function mockHttpsRequest(...args) {\n return runInRequestContext(() => {\n return httpsRequest(...(args as [any, any]))\n }, requestLogger)\n }\n })\n )\n }\n}\n"],"mappings":";;;;;;;;;AAYA,IAAa,2BAAb,cAA8C,YAAiC;;EAC7D,KAAA,SAAA,OAAO,IAAI,4BAA4B;;CAEvD,YAA+B;EAC7B,OAAO;CACT;CAEA,QAAwB;EACtB,MAAM,gBAAgB,YAAY,UAAU,qBAAqB;EACjE,MAAM,gBAAgB,KAAK;EAC3B,cAAc,MAAM,IAAI;EACxB,KAAK,cAAc,WAAW;GAC5B,cAAc,QAAQ,IAAI;EAC5B,CAAC;EAED,KAAK,cAAc,KACjB,kBAAkB;GAChB,QAAQ;GACR,SAAS,KAAK;GACd,YAAY,cAAc;IACxB,OAAO,qBAAqB,KAAK;GACnC;EACF,CAAC,CACH;EAEA,KAAK,cAAc,KACjB,gBAAgB,WAAW,MAAM,kBAAkB,kBAAkB;GACnE,OAAO,IAAI,MAAM,eAAe,EAC9B,UAAU,QAAQ,MAAM,WAAW;IACjC,OAAO,0BAA0B;KAC/B,OAAO,QAAQ,UAAU,QAAQ,MAAM,SAAS;IAClD,GAAG,aAAa;GAClB,EACF,CAAC;EACH,CAAC,GACD,gBAAgB,WAAW,MAAM,QAAQ,YAAY;GACnD,OAAO,SAAS,YAAY,GAAG,MAAM;IACnC,OAAO,0BAA0B;KAC/B,OAAO,QAAQ,GAAI,IAAmB;IACxC,GAAG,aAAa;GAClB;EACF,CAAC,GACD,gBAAgB,WAAW,MAAM,YAAY,gBAAgB;GAC3D,OAAO,SAAS,gBAAgB,GAAG,MAAM;IACvC,OAAO,0BAA0B;KAC/B,OAAO,YAAY,GAAI,IAAmB;IAC5C,GAAG,aAAa;GAClB;EACF,CAAC,GACD,gBAAgB,WAAW,OAAO,QAAQ,aAAa;GACrD,OAAO,SAAS,aAAa,GAAG,MAAM;IACpC,OAAO,0BAA0B;KAC/B,OAAO,SAAS,GAAI,IAAmB;IACzC,GAAG,aAAa;GAClB;EACF,CAAC,GACD,gBAAgB,WAAW,OAAO,YAAY,iBAAiB;GAC7D,OAAO,SAAS,iBAAiB,GAAG,MAAM;IACxC,OAAO,0BAA0B;KAC/B,OAAO,aAAa,GAAI,IAAmB;IAC7C,GAAG,aAAa;GAClB;EACF,CAAC,CACH;CACF;AACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { t as Interceptor } from "../../interceptor-dtJZ_9QT.js";
|
|
2
|
+
import { n as HttpRequestEventMap } from "../../http-CB9rQ7i_.js";
|
|
3
|
+
//#region src/interceptors/XMLHttpRequest/node.d.ts
|
|
4
|
+
declare class XMLHttpRequestInterceptor extends Interceptor<HttpRequestEventMap> {
|
|
5
|
+
#private;
|
|
6
|
+
static symbol: symbol;
|
|
7
|
+
protected predicate(): boolean;
|
|
8
|
+
protected setup(): void;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { XMLHttpRequestInterceptor };
|
|
12
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { a as requestContext, i as forwardHttpEvents, t as NodeHttpRequestSource } from "../../source-lP0yyEtA.js";
|
|
2
|
+
import { a as createLogger, i as Interceptor } from "../../buffer-utils-BvPY1Tc-.js";
|
|
3
|
+
import { t as FetchRequest } from "../../fetch-utils-Dw1PsmtX.js";
|
|
4
|
+
import { o as patchesRegistry } from "../../net-DtMnyEeg.js";
|
|
5
|
+
import { t as hasConfigurableGlobal } from "../../has-configurable-global-CJCh_g1I.js";
|
|
6
|
+
//#region src/interceptors/XMLHttpRequest/node.ts
|
|
7
|
+
const logger = createLogger("xhr");
|
|
8
|
+
var XMLHttpRequestInterceptor = class extends Interceptor {
|
|
9
|
+
static {
|
|
10
|
+
this.symbol = Symbol.for("xhr-interceptor");
|
|
11
|
+
}
|
|
12
|
+
predicate() {
|
|
13
|
+
return hasConfigurableGlobal("XMLHttpRequest");
|
|
14
|
+
}
|
|
15
|
+
setup() {
|
|
16
|
+
const requestSource = Interceptor.singleton(NodeHttpRequestSource);
|
|
17
|
+
requestSource.apply(this);
|
|
18
|
+
this.subscriptions.push(() => {
|
|
19
|
+
requestSource.dispose(this);
|
|
20
|
+
});
|
|
21
|
+
this.subscriptions.push(forwardHttpEvents({
|
|
22
|
+
source: requestSource,
|
|
23
|
+
emitter: this.emitter,
|
|
24
|
+
predicate: (initiator) => {
|
|
25
|
+
return initiator instanceof XMLHttpRequest;
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
logger.verbose("patching global \"XMLHttpRequest\"...");
|
|
29
|
+
const prepareRequest = this.#transformRequest.bind(this);
|
|
30
|
+
const requestLogger = this.logger;
|
|
31
|
+
this.subscriptions.push(patchesRegistry.applyPatch(globalThis, "XMLHttpRequest", (realXMLHttpRequest) => {
|
|
32
|
+
return new Proxy(realXMLHttpRequest, { construct(target, args, newTarget) {
|
|
33
|
+
const xmlHttpRequest = Reflect.construct(target, args, newTarget);
|
|
34
|
+
/**
|
|
35
|
+
* @note Scope the request context to the `send()` call.
|
|
36
|
+
* XHR in JSDOM is implemented via `http`/`https`, and the
|
|
37
|
+
* underlying `http.ClientRequest` is created within `send()`,
|
|
38
|
+
* so the initiator cascading keeps working. Binding the
|
|
39
|
+
* context to the caller's scope instead (e.g. `enterWith`)
|
|
40
|
+
* would attribute unrelated requests performed after this
|
|
41
|
+
* XMLHttpRequest to it.
|
|
42
|
+
*/
|
|
43
|
+
const realSend = xmlHttpRequest.send;
|
|
44
|
+
xmlHttpRequest.send = (...sendArgs) => {
|
|
45
|
+
return requestContext.run({
|
|
46
|
+
initiator: xmlHttpRequest,
|
|
47
|
+
logger: requestLogger,
|
|
48
|
+
transformRequest: (request) => {
|
|
49
|
+
return prepareRequest(request, xmlHttpRequest);
|
|
50
|
+
}
|
|
51
|
+
}, () => realSend.apply(xmlHttpRequest, sendArgs));
|
|
52
|
+
};
|
|
53
|
+
return xmlHttpRequest;
|
|
54
|
+
} });
|
|
55
|
+
}));
|
|
56
|
+
logger.verbose("global \"XMLHttpRequest\" patched!");
|
|
57
|
+
}
|
|
58
|
+
#transformRequest(request, initiator) {
|
|
59
|
+
const expectedCredentials = initiator.withCredentials ? "include" : "same-origin";
|
|
60
|
+
if (request.credentials === expectedCredentials) return request;
|
|
61
|
+
return new FetchRequest(request.url, {
|
|
62
|
+
...request,
|
|
63
|
+
method: request.method,
|
|
64
|
+
headers: request.headers,
|
|
65
|
+
credentials: expectedCredentials,
|
|
66
|
+
body: request.body,
|
|
67
|
+
signal: request.signal
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
export { XMLHttpRequestInterceptor };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","names":["#transformRequest"],"sources":["../../../../src/interceptors/XMLHttpRequest/node.ts"],"sourcesContent":["import { requestContext } from '#/src/request-context'\nimport { hasConfigurableGlobal } from '#/src/utils/has-configurable-global'\nimport { Interceptor } from '#/src/interceptor'\nimport { forwardHttpEvents } from '#/src/interceptors/http/forward-events'\nimport { NodeHttpRequestSource } from '#/src/interceptors/http/source'\nimport { patchesRegistry } from '#/src/utils/patches-registry'\nimport { FetchRequest } from '#/src/utils/fetch-utils'\nimport { HttpRequestEventMap } from '#/src/events/http'\nimport { createLogger } from '#/src/utils/logger'\n\nconst logger = createLogger('xhr')\n\nexport class XMLHttpRequestInterceptor extends Interceptor<HttpRequestEventMap> {\n static symbol = Symbol.for('xhr-interceptor')\n\n protected predicate() {\n return hasConfigurableGlobal('XMLHttpRequest')\n }\n\n protected setup(): void {\n const requestSource = Interceptor.singleton(NodeHttpRequestSource)\n requestSource.apply(this)\n this.subscriptions.push(() => {\n requestSource.dispose(this)\n })\n\n this.subscriptions.push(\n forwardHttpEvents({\n source: requestSource,\n emitter: this.emitter,\n predicate: (initiator) => {\n return initiator instanceof XMLHttpRequest\n },\n })\n )\n\n logger.verbose('patching global \"XMLHttpRequest\"...')\n\n const prepareRequest = this.#transformRequest.bind(this)\n const requestLogger = this.logger\n\n this.subscriptions.push(\n patchesRegistry.applyPatch(\n globalThis,\n 'XMLHttpRequest',\n (realXMLHttpRequest) => {\n return new Proxy(realXMLHttpRequest, {\n construct(target, args, newTarget) {\n const xmlHttpRequest = Reflect.construct(target, args, newTarget)\n\n /**\n * @note Scope the request context to the `send()` call.\n * XHR in JSDOM is implemented via `http`/`https`, and the\n * underlying `http.ClientRequest` is created within `send()`,\n * so the initiator cascading keeps working. Binding the\n * context to the caller's scope instead (e.g. `enterWith`)\n * would attribute unrelated requests performed after this\n * XMLHttpRequest to it.\n */\n const realSend = xmlHttpRequest.send\n xmlHttpRequest.send = (\n ...sendArgs: Parameters<XMLHttpRequest['send']>\n ) => {\n return requestContext.run(\n {\n initiator: xmlHttpRequest,\n logger: requestLogger,\n transformRequest: (request) => {\n return prepareRequest(request, xmlHttpRequest)\n },\n },\n () => realSend.apply(xmlHttpRequest, sendArgs)\n )\n }\n\n return xmlHttpRequest\n },\n })\n }\n )\n )\n\n logger.verbose('global \"XMLHttpRequest\" patched!')\n }\n\n #transformRequest(request: Request, initiator: XMLHttpRequest): Request {\n const expectedCredentials = initiator.withCredentials\n ? 'include'\n : 'same-origin'\n\n if (request.credentials === expectedCredentials) {\n return request\n }\n\n return new FetchRequest(request.url, {\n ...request,\n method: request.method,\n headers: request.headers,\n credentials: expectedCredentials,\n body: request.body,\n signal: request.signal,\n })\n }\n}\n"],"mappings":";;;;;;AAUA,MAAM,SAAS,aAAa,KAAK;AAEjC,IAAa,4BAAb,cAA+C,YAAiC;;EAC9D,KAAA,SAAA,OAAO,IAAI,iBAAiB;;CAE5C,YAAsB;EACpB,OAAO,sBAAsB,gBAAgB;CAC/C;CAEA,QAAwB;EACtB,MAAM,gBAAgB,YAAY,UAAU,qBAAqB;EACjE,cAAc,MAAM,IAAI;EACxB,KAAK,cAAc,WAAW;GAC5B,cAAc,QAAQ,IAAI;EAC5B,CAAC;EAED,KAAK,cAAc,KACjB,kBAAkB;GAChB,QAAQ;GACR,SAAS,KAAK;GACd,YAAY,cAAc;IACxB,OAAO,qBAAqB;GAC9B;EACF,CAAC,CACH;EAEA,OAAO,QAAQ,uCAAqC;EAEpD,MAAM,iBAAiB,KAAKA,kBAAkB,KAAK,IAAI;EACvD,MAAM,gBAAgB,KAAK;EAE3B,KAAK,cAAc,KACjB,gBAAgB,WACd,YACA,mBACC,uBAAuB;GACtB,OAAO,IAAI,MAAM,oBAAoB,EACnC,UAAU,QAAQ,MAAM,WAAW;IACjC,MAAM,iBAAiB,QAAQ,UAAU,QAAQ,MAAM,SAAS;;;;;;;;;;IAWhE,MAAM,WAAW,eAAe;IAChC,eAAe,QACb,GAAG,aACA;KACH,OAAO,eAAe,IACpB;MACE,WAAW;MACX,QAAQ;MACR,mBAAmB,YAAY;OAC7B,OAAO,eAAe,SAAS,cAAc;MAC/C;KACF,SACM,SAAS,MAAM,gBAAgB,QAAQ,CAC/C;IACF;IAEA,OAAO;GACT,EACF,CAAC;EACH,CACF,CACF;EAEA,OAAO,QAAQ,oCAAkC;CACnD;CAEA,kBAAkB,SAAkB,WAAoC;EACtE,MAAM,sBAAsB,UAAU,kBAClC,YACA;EAEJ,IAAI,QAAQ,gBAAgB,qBAC1B,OAAO;EAGT,OAAO,IAAI,aAAa,QAAQ,KAAK;GACnC,GAAG;GACH,QAAQ,QAAQ;GAChB,SAAS,QAAQ;GACjB,aAAa;GACb,MAAM,QAAQ;GACd,QAAQ,QAAQ;EAClB,CAAC;CACH;AACF"}
|