@mswjs/interceptors 0.41.9 → 0.42.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 +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-DlEd4GOA.js +184 -0
- package/lib/browser/create-request-id-DlEd4GOA.js.map +1 -0
- package/lib/browser/{getRawRequest-B1BqgWG6.mjs → fetch-utils-zxA_SD66.js} +123 -52
- package/lib/browser/fetch-utils-zxA_SD66.js.map +1 -0
- package/lib/browser/handle-request-CIOa9O-N.js +167 -0
- package/lib/browser/handle-request-CIOa9O-N.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/web-BjVDkiX0.js +248 -0
- package/lib/browser/web-BjVDkiX0.js.map +1 -0
- package/lib/browser/{XMLHttpRequest-DrZAf3w6.mjs → web-C2oKsT3Q.js} +327 -255
- package/lib/browser/web-C2oKsT3Q.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 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-utils-Dw1PsmtX.js","names":["#handled","#resolveProperty","#setInternalProperty"],"sources":["../../src/interceptor-error.ts","../../src/request-controller.ts","../../src/create-request-id.ts","../../src/interceptors/ClientRequest/utils/record-raw-headers.ts","../../src/utils/get-value-by-symbol.ts","../../src/utils/is-object.ts","../../src/utils/is-property-accessible.ts","../../src/utils/response-utils.ts","../../src/utils/fetch-utils.ts"],"sourcesContent":["export class InterceptorError extends Error {\n constructor(message?: string) {\n super(message)\n this.name = 'InterceptorError'\n Object.setPrototypeOf(this, InterceptorError.prototype)\n }\n}\n","import { invariant } from 'outvariant'\nimport { InterceptorError } from './interceptor-error'\nimport { formatResponse, type Logger } from './utils/logger'\n\nexport interface RequestControllerSource {\n passthrough(): void | Promise<void>\n respondWith(response: Response): void | Promise<void>\n errorWith(reason?: unknown): void | Promise<void>\n}\n\ninterface RequestControllerOptions {\n logger: Logger\n requestId: string\n}\n\nexport class RequestController {\n static PENDING = 0 as const\n static PASSTHROUGH = 1 as const\n static RESPONSE = 2 as const\n static ERROR = 3 as const\n\n public readyState: number\n\n /**\n * A Promise that resolves when this controller handles a request.\n * See `controller.readyState` for more information on the handling result.\n */\n public handled: Promise<void>\n\n readonly #handled: PromiseWithResolvers<void>\n\n constructor(\n protected readonly request: Request,\n protected readonly source: RequestControllerSource,\n protected readonly options?: RequestControllerOptions\n ) {\n this.readyState = RequestController.PENDING\n this.#handled = Promise.withResolvers<void>()\n this.handled = this.#handled.promise\n }\n\n /**\n * Perform this request as-is.\n */\n public async passthrough(): Promise<void> {\n invariant.as(\n InterceptorError,\n this.readyState === RequestController.PENDING,\n 'Failed to passthrough the \"%s %s\" request: the request has already been handled',\n this.request.method,\n this.request.url\n )\n\n this.readyState = RequestController.PASSTHROUGH\n if (this.options) {\n this.options.logger.info('[%s] passthrough', this.options.requestId)\n }\n await this.source.passthrough()\n this.#handled.resolve()\n }\n\n /**\n * Respond to this request with the given `Response` instance.\n *\n * @example\n * controller.respondWith(new Response())\n * controller.respondWith(Response.json({ id }))\n * controller.respondWith(Response.error())\n */\n public respondWith(response: Response): void {\n invariant.as(\n InterceptorError,\n this.readyState === RequestController.PENDING,\n 'Failed to respond to the \"%s %s\" request with \"%d %s\": the request has already been handled (%d)',\n this.request.method,\n this.request.url,\n response.status,\n response.statusText || 'OK',\n this.readyState\n )\n\n this.readyState = RequestController.RESPONSE\n if (this.options?.logger.isEnabled('default')) {\n const { logger, requestId } = this.options\n\n void formatResponse(response).then((message) => {\n logger.info('[%s] mocked %s', requestId, message)\n })\n }\n this.#handled.resolve()\n\n /**\n * @note Although `source.respondWith()` is potentially asynchronous,\n * do NOT await it for backward-compatibility. Awaiting it will short-circuit\n * the request listener invocation as soon as a listener responds to a request.\n * Ideally, that's what we want, but that's not what we promise the user.\n */\n this.source.respondWith(response)\n }\n\n /**\n * Error this request with the given reason.\n *\n * @example\n * controller.errorWith()\n * controller.errorWith(new Error('Oops!'))\n * controller.errorWith({ message: 'Oops!'})\n */\n public errorWith(reason?: unknown): void {\n invariant.as(\n InterceptorError,\n this.readyState === RequestController.PENDING,\n 'Failed to error the \"%s %s\" request with \"%s\": the request has already been handled (%d)',\n this.request.method,\n this.request.url,\n reason?.toString(),\n this.readyState\n )\n\n this.readyState = RequestController.ERROR\n if (this.options) {\n this.options.logger.info(\n '[%s] error %o',\n this.options.requestId,\n reason\n )\n }\n this.source.errorWith(reason)\n this.#handled.resolve()\n }\n}\n","/**\n * Generate a random ID string to represent a request.\n * @example\n * createRequestId()\n * // \"f774b6c9c600f\"\n */\nexport function createRequestId(): string {\n return Math.random().toString(16).slice(2)\n}\n","import { FetchRequest, FetchResponse } from '../../../utils/fetch-utils'\n\ntype HeaderTuple = [string, string]\ntype RawHeaders = Array<HeaderTuple>\ntype SetHeaderBehavior = 'set' | 'append'\n\nconst kRawHeaders = Symbol('kRawHeaders')\nconst kRestorePatches = Symbol('kRestorePatches')\n\nfunction recordRawHeader(\n headers: Headers,\n args: HeaderTuple,\n behavior: SetHeaderBehavior\n) {\n ensureRawHeadersSymbol(headers, [])\n const rawHeaders = Reflect.get(headers, kRawHeaders) as RawHeaders\n\n if (behavior === 'set') {\n // When recording a set header, ensure we remove any matching existing headers.\n for (let index = rawHeaders.length - 1; index >= 0; index--) {\n if (rawHeaders[index][0].toLowerCase() === args[0].toLowerCase()) {\n rawHeaders.splice(index, 1)\n }\n }\n }\n\n rawHeaders.push(args)\n}\n\n/**\n * Define the raw headers symbol on the given `Headers` instance.\n * If the symbol already exists, this function does nothing.\n */\nfunction ensureRawHeadersSymbol(\n headers: Headers,\n rawHeaders: RawHeaders\n): void {\n if (Reflect.has(headers, kRawHeaders)) {\n return\n }\n\n defineRawHeadersSymbol(headers, rawHeaders)\n}\n\n/**\n * Define the raw headers symbol on the given `Headers` instance.\n * If the symbol already exists, it gets overridden.\n */\nfunction defineRawHeadersSymbol(headers: Headers, rawHeaders: RawHeaders) {\n Object.defineProperty(headers, kRawHeaders, {\n value: rawHeaders,\n enumerable: false,\n // Mark the symbol as configurable so its value can be overridden.\n // Overrides happen when merging raw headers from multiple sources.\n // E.g. new Request(new Request(url, { headers }), { headers })\n configurable: true,\n })\n}\n\n/**\n * Patch the global `Headers` class to store raw headers.\n * This is for compatibility with `IncomingMessage.prototype.rawHeaders`.\n *\n * @note Node.js has their own raw headers symbol but it\n * only records the first header name in case of multi-value headers.\n * Any other headers are normalized before comparing. This makes it\n * incompatible with the `rawHeaders` format.\n *\n * let h = new Headers()\n * h.append('X-Custom', 'one')\n * h.append('x-custom', 'two')\n * h[Symbol('headers map')] // Map { 'X-Custom' => 'one, two' }\n */\nexport function recordRawFetchHeaders(): () => void {\n // Prevent patching the Headers prototype multiple times.\n if (Reflect.get(Headers, kRestorePatches)) {\n return Reflect.get(Headers, kRestorePatches)\n }\n\n const {\n Headers: OriginalHeaders,\n Request: OriginalRequest,\n Response: OriginalResponse,\n } = globalThis\n const { set, append, delete: headersDeleteMethod } = Headers.prototype\n\n Object.defineProperty(Headers, kRestorePatches, {\n value: () => {\n Headers.prototype.set = set\n Headers.prototype.append = append\n Headers.prototype.delete = headersDeleteMethod\n globalThis.Headers = OriginalHeaders\n\n globalThis.Request = OriginalRequest\n globalThis.Response = OriginalResponse\n\n Object.setPrototypeOf(FetchRequest, OriginalRequest)\n Object.setPrototypeOf(FetchRequest.prototype, OriginalRequest.prototype)\n Object.setPrototypeOf(FetchResponse, OriginalResponse)\n Object.setPrototypeOf(FetchResponse.prototype, OriginalResponse.prototype)\n\n Reflect.deleteProperty(Headers, kRestorePatches)\n },\n enumerable: false,\n /**\n * @note Mark this property as configurable\n * so we can delete it using `Reflect.delete` during cleanup.\n */\n configurable: true,\n })\n\n Object.defineProperty(globalThis, 'Headers', {\n enumerable: true,\n writable: true,\n value: new Proxy(Headers, {\n construct(target, args, newTarget) {\n const headersInit = args[0] || []\n\n if (\n headersInit instanceof Headers &&\n Reflect.has(headersInit, kRawHeaders)\n ) {\n // Ensure each header tuple has exactly 2 elements (name, value).\n // Node.js 24+ may have stored tuples with extra internal arguments.\n const rawHeadersFromInit = Reflect.get(\n headersInit,\n kRawHeaders\n ) as RawHeaders\n const sanitizedHeaders = rawHeadersFromInit.map(\n (tuple): HeaderTuple => [tuple[0], tuple[1]]\n )\n const headers = Reflect.construct(\n target,\n [sanitizedHeaders],\n newTarget\n )\n ensureRawHeadersSymbol(headers, [\n /**\n * @note Spread the retrieved headers to clone them.\n * This prevents multiple Headers instances from pointing\n * at the same internal \"rawHeaders\" array.\n */\n ...sanitizedHeaders,\n ])\n return headers\n }\n\n const headers = Reflect.construct(target, args, newTarget)\n\n // Request/Response constructors will set the symbol\n // upon creating a new instance, using the raw developer\n // input as the raw headers. Skip the symbol altogether\n // in those cases because the input to Headers will be normalized.\n if (!Reflect.has(headers, kRawHeaders)) {\n const rawHeadersInit = Array.isArray(headersInit)\n ? headersInit\n : Object.entries(headersInit)\n ensureRawHeadersSymbol(headers, rawHeadersInit)\n }\n\n return headers\n },\n }),\n })\n\n Headers.prototype.set = new Proxy(Headers.prototype.set, {\n apply(target, thisArg, args: HeaderTuple) {\n // Use only the first two arguments (name, value) to record raw headers.\n // Node.js 24+ may pass additional internal arguments that should not\n // be included in the raw headers array.\n recordRawHeader(thisArg, [args[0], args[1]], 'set')\n return Reflect.apply(target, thisArg, args)\n },\n })\n\n Headers.prototype.append = new Proxy(Headers.prototype.append, {\n apply(target, thisArg, args: HeaderTuple) {\n // Use only the first two arguments (name, value) to record raw headers.\n // Node.js 24+ may pass additional internal arguments that should not\n // be included in the raw headers array.\n recordRawHeader(thisArg, [args[0], args[1]], 'append')\n return Reflect.apply(target, thisArg, args)\n },\n })\n\n Headers.prototype.delete = new Proxy(Headers.prototype.delete, {\n apply(target, thisArg, args: [string]) {\n const rawHeaders = Reflect.get(thisArg, kRawHeaders) as RawHeaders\n\n if (rawHeaders) {\n for (let index = rawHeaders.length - 1; index >= 0; index--) {\n if (rawHeaders[index][0].toLowerCase() === args[0].toLowerCase()) {\n rawHeaders.splice(index, 1)\n }\n }\n }\n\n return Reflect.apply(target, thisArg, args)\n },\n })\n\n Object.defineProperty(globalThis, 'Request', {\n enumerable: true,\n writable: true,\n value: new Proxy(Request, {\n construct(target, args, newTarget) {\n const request = Reflect.construct(target, args, newTarget)\n const inferredRawHeaders: RawHeaders = []\n\n // Infer raw headers from a `Request` instance used as init.\n if (typeof args[0] === 'object' && args[0].headers != null) {\n inferredRawHeaders.push(...inferRawHeaders(args[0].headers))\n }\n\n // Infer raw headers from the \"headers\" init argument.\n if (typeof args[1] === 'object' && args[1].headers != null) {\n inferredRawHeaders.push(...inferRawHeaders(args[1].headers))\n }\n\n if (inferredRawHeaders.length > 0) {\n ensureRawHeadersSymbol(request.headers, inferredRawHeaders)\n }\n\n return request\n },\n }),\n })\n\n Object.defineProperty(globalThis, 'Response', {\n enumerable: true,\n writable: true,\n value: new Proxy(Response, {\n construct(target, args, newTarget) {\n const response = Reflect.construct(target, args, newTarget)\n\n if (typeof args[1] === 'object' && args[1].headers != null) {\n ensureRawHeadersSymbol(\n response.headers,\n inferRawHeaders(args[1].headers)\n )\n }\n\n return response\n },\n }),\n })\n\n /**\n * Re-parent FetchRequest/FetchResponse so their `super()` calls go\n * through the proxied globalThis.Request/Response above. Without this,\n * FetchRequest extends the statically-captured (original) Request,\n * bypassing the construct proxy that records raw headers.\n */\n Object.setPrototypeOf(FetchRequest, globalThis.Request)\n Object.setPrototypeOf(FetchRequest.prototype, globalThis.Request.prototype)\n Object.setPrototypeOf(FetchResponse, globalThis.Response)\n Object.setPrototypeOf(FetchResponse.prototype, globalThis.Response.prototype)\n\n return restoreHeadersPrototype\n}\n\nexport function restoreHeadersPrototype() {\n if (!Reflect.get(Headers, kRestorePatches)) {\n return\n }\n\n Reflect.get(Headers, kRestorePatches)()\n}\n\nexport function getRawFetchHeaders(headers: Headers): RawHeaders {\n // If the raw headers recording failed for some reason,\n // use the normalized header entries instead.\n if (!Reflect.has(headers, kRawHeaders)) {\n return Array.from(headers.entries())\n }\n\n const rawHeaders = Reflect.get(headers, kRawHeaders) as RawHeaders\n return rawHeaders.length > 0 ? rawHeaders : Array.from(headers.entries())\n}\n\n/**\n * Infers the raw headers from the given `HeadersInit` provided\n * to the Request/Response constructor.\n *\n * If the `init.headers` is a Headers instance, use it directly.\n * That means the headers were created standalone and already have\n * the raw headers stored.\n * If the `init.headers` is a HeadersInit, create a new Headers\n * instance out of it.\n */\nfunction inferRawHeaders(headers: HeadersInit): RawHeaders {\n if (headers instanceof Headers) {\n return Reflect.get(headers, kRawHeaders) || []\n }\n\n return Reflect.get(new Headers(headers), kRawHeaders)\n}\n\nexport function copyRawHeaders(source: Headers, destination: Headers): void {\n const rawHeaders = [...getRawFetchHeaders(source)]\n\n if (rawHeaders.length === 0) {\n return\n }\n\n /**\n * @note Add headers from trhe destination that raw headers from the source\n * don't have. Undici automatically appends a \"Content-Type\" header for responses\n * and, for some reason, that change is not recorded. This preserves it.\n */\n for (const [name, value] of destination) {\n if (\n rawHeaders.every(\n (header) => header[0].toLowerCase() !== name.toLowerCase()\n )\n ) {\n rawHeaders.push([name, value])\n }\n }\n\n defineRawHeadersSymbol(destination, rawHeaders)\n}\n","/**\n * Returns the value behind the symbol with the given name.\n */\nexport function getValueBySymbol<T>(\n symbolName: string,\n source: object\n): T | undefined {\n const ownSymbols = Object.getOwnPropertySymbols(source)\n\n const symbol = ownSymbols.find((symbol) => {\n return symbol.description === symbolName\n })\n\n if (symbol) {\n return Reflect.get(source, symbol)\n }\n\n return\n}\n","/**\n * Determines if a given value is an instance of object.\n */\nexport function isObject<T>(value: any, loose = false): value is T {\n return loose\n ? Object.prototype.toString.call(value).startsWith('[object ')\n : Object.prototype.toString.call(value) === '[object Object]'\n}\n","/**\n * A function that validates if property access is possible on an object\n * without throwing. It returns `true` if the property access is possible\n * and `false` otherwise.\n *\n * Environments like miniflare will throw on property access on certain objects\n * like Request and Response, for unimplemented properties.\n */\nexport function isPropertyAccessible<Obj extends Record<string, any>>(\n obj: Obj,\n key: keyof Obj\n) {\n try {\n obj[key]\n return true\n } catch {\n return false\n }\n}\n","import { isObject } from './is-object'\nimport { isPropertyAccessible } from './is-property-accessible'\n\n/**\n * Creates a generic 500 Unhandled Exception response.\n */\nexport function createServerErrorResponse(body: unknown): Response {\n return new Response(\n JSON.stringify(\n body instanceof Error\n ? {\n name: body.name,\n message: body.message,\n stack: body.stack,\n }\n : body\n ),\n {\n status: 500,\n statusText: 'Unhandled Exception',\n headers: {\n 'Content-Type': 'application/json',\n },\n }\n )\n}\n\nexport type ResponseError = Response & { type: 'error' }\n\n/**\n * A key on the error a mocked `Response.error()` destroys the socket\n * with, referencing that error response. Allows the client-side\n * interceptors (e.g. fetch) to surface the error response to the\n * consumer instead of the internal socket error.\n */\nexport const kErrorResponse = Symbol('kErrorResponse')\n\n/**\n * Get the mocked error response that caused the given error, if any.\n */\nexport function getErrorResponse(error: unknown): ResponseError | undefined {\n if (\n error instanceof Error &&\n kErrorResponse in error &&\n isResponseError(error[kErrorResponse])\n ) {\n return error[kErrorResponse]\n }\n\n return undefined\n}\n\n/**\n * Check if the given response is a `Response.error()`.\n *\n * @note Some environments, like Miniflare (Cloudflare) do not\n * implement the \"Response.type\" property and throw on its access.\n * Safely check if we can access \"type\" on \"Response\" before continuing.\n * @see https://github.com/mswjs/msw/issues/1834\n */\nexport function isResponseError(response: unknown): response is ResponseError {\n return (\n response != null &&\n response instanceof Response &&\n isPropertyAccessible(response, 'type') &&\n response.type === 'error'\n )\n}\n\n/**\n * Check if the given value is a `Response` or a Response-like object.\n * This is different from `value instanceof Response` because it supports\n * custom `Response` constructors, like the one when using Undici directly.\n */\nexport function isResponseLike(value: unknown): value is Response {\n return (\n isObject<Record<string, any>>(value, true) &&\n isPropertyAccessible(value, 'status') &&\n isPropertyAccessible(value, 'statusText') &&\n isPropertyAccessible(value, 'bodyUsed')\n )\n}\n","import { copyRawHeaders } from '../interceptors/ClientRequest/utils/record-raw-headers'\nimport { getValueBySymbol } from './get-value-by-symbol'\nimport { isResponseError } from './response-utils'\n\ninterface UndiciRequestState extends RequestInit {}\n\ninterface FetchRequestInit extends Omit<RequestInit, 'mode'> {\n mode?: RequestMode | 'websocket' | 'webtransport'\n duplex?: 'half' | 'full'\n}\n\nexport class FetchRequest extends Request {\n static #resolveProperty<T extends keyof FetchRequestInit & keyof Request>(\n input: RequestInfo | URL,\n init: FetchRequestInit = {},\n key: T\n ): FetchRequestInit[T] {\n return init[key] ?? (input instanceof Request ? input[key] : undefined)\n }\n\n /**\n * Check if the given request method is configurable.\n * @see https://fetch.spec.whatwg.org/#methods\n */\n static isConfigurableMethod(method: string): boolean {\n return method !== 'CONNECT' && method !== 'TRACE' && method !== 'TRACK'\n }\n\n static isMethodWithBody(method: string): boolean {\n return (\n method !== 'HEAD' &&\n method !== 'GET' &&\n FetchRequest.isConfigurableMethod(method)\n )\n }\n\n /**\n * Check if the given request `mode` is configurable.\n * @see https://fetch.spec.whatwg.org/#concept-request-mode\n */\n static isConfigurableMode(mode: string): boolean {\n return (\n mode !== 'navigate' && mode !== 'websocket' && mode !== 'webtransport'\n )\n }\n\n constructor(input: URL | RequestInfo, init?: FetchRequestInit) {\n const method = FetchRequest.#resolveProperty(input, init, 'method') || 'GET'\n const safeMethod = FetchRequest.isConfigurableMethod(method)\n ? method\n : 'GET'\n\n const hasExplicitBody = init != null && 'body' in init\n\n /**\n * Only include `body` in the super init when it needs to be overridden.\n * When `input` is a Request and no explicit body is in `init`, let the\n * Request constructor handle body transfer naturally so it properly\n * marks the original request's body as consumed (bodyUsed = true).\n */\n const bodyInit: { body?: BodyInit | null } = !FetchRequest.isMethodWithBody(\n method\n )\n ? { body: undefined }\n : hasExplicitBody\n ? { body: init.body }\n : {}\n\n const mode =\n (FetchRequest.#resolveProperty(input, init, 'mode') as RequestMode) ??\n undefined\n const safeMode = FetchRequest.isConfigurableMode(mode) ? mode : undefined\n\n super(input, {\n ...(init || {}),\n method: safeMethod,\n mode: safeMode,\n // @ts-expect-error Untyped Node.js property.\n duplex:\n init?.duplex ??\n (FetchRequest.isMethodWithBody(method) ? 'half' : undefined),\n ...bodyInit,\n })\n\n if (method !== safeMethod) {\n this.#setInternalProperty('method', method)\n }\n\n if (method === 'CONNECT') {\n const url = new URL(input instanceof Request ? input.url : input)\n\n let authority: string\n\n /**\n * @note Node.js has a bug parsing raw CONNECT requests URLs like\n * \"http://127.0.0.1:1337/localhost:80\". It would treat \"localhost:\" as a protocol.\n */\n if (url.protocol === 'localhost:') {\n authority = url.href\n } else {\n authority = url.pathname.replace(/^\\/+/, '')\n }\n\n /**\n * @note Define \"url\" as a getter because Undici uses their own\n * logic to resolve the \"request.url\" property. Simply reassigning\n * its value doesn't do anything. This is a destructive action\n * but it's safe because \"CONNECT\" requests are forbidden per fetch.\n */\n Object.defineProperty(this, 'url', {\n get: () => authority,\n enumerable: true,\n configurable: true,\n })\n }\n\n if (mode != null && mode !== safeMode) {\n this.#setInternalProperty('mode', mode)\n }\n }\n\n #setInternalProperty<T extends keyof Request>(\n key: T,\n value: Request[T]\n ): void {\n const internalState = getValueBySymbol<UndiciRequestState>('state', this)\n\n if (internalState) {\n Reflect.set(internalState, key, value)\n } else {\n Object.defineProperty(this, key, {\n value,\n enumerable: true,\n configurable: true,\n writable: false,\n })\n }\n }\n}\n\nexport interface FetchResponseInit extends ResponseInit {\n url?: string\n}\n\ninterface UndiciResponseState {\n aborted: boolean\n rangeRequested: boolean\n timingAllowPassed: boolean\n requestIncludesCredentials: boolean\n type: ResponseType\n status: number\n statusText: string\n timingInfo: unknown\n cacheState: unknown\n headersList: Record<symbol, Map<string, unknown>>\n urlList: Array<URL>\n body?: {\n stream: ReadableStream\n source: unknown\n length: number\n }\n}\n\nconst kStatus = Symbol('kStatus')\nconst kUrl = Symbol('kUrl')\n\nexport class FetchResponse extends Response {\n static from(response: Response, init?: FetchResponseInit): FetchResponse {\n if (response instanceof FetchResponse) {\n return response\n }\n\n if (isResponseError(response)) {\n return response\n }\n\n const fetchResponse = new FetchResponse(response.body, {\n url: init?.url ?? response.url,\n status: init?.status || response.status,\n statusText: init?.statusText ?? response.statusText,\n headers: init?.headers ?? response.headers,\n })\n\n copyRawHeaders(response.headers, fetchResponse.headers)\n\n return fetchResponse\n }\n\n /**\n * Response status codes for responses that cannot have body.\n * @see https://fetch.spec.whatwg.org/#statuses\n */\n static readonly STATUS_CODES_WITHOUT_BODY = [101, 103, 204, 205, 304]\n\n static readonly STATUS_CODES_WITH_REDIRECT = [301, 302, 303, 307, 308]\n\n static isConfigurableStatusCode(status: number): boolean {\n return status >= 200 && status <= 599\n }\n\n static isRedirectResponse(status: number): boolean {\n return FetchResponse.STATUS_CODES_WITH_REDIRECT.includes(status)\n }\n\n /**\n * Returns a boolean indicating whether the given response status\n * code represents a response that can have a body.\n */\n static isResponseWithBody(status: number): boolean {\n return !FetchResponse.STATUS_CODES_WITHOUT_BODY.includes(status)\n }\n\n static setStatus(status: number, response: Response): void {\n /**\n * @note Undici keeps an internal \"Symbol(state)\" that holds\n * the actual value of response status. Update that in Node.js.\n */\n const internalState = getValueBySymbol<UndiciResponseState>(\n 'state',\n response\n )\n\n if (internalState) {\n internalState.status = status\n } else {\n Object.defineProperty(response, 'status', {\n value: status,\n enumerable: true,\n configurable: true,\n writable: false,\n })\n }\n\n Object.defineProperty(response, kStatus, {\n value: status,\n enumerable: false,\n })\n }\n\n static setUrl(url: string | undefined, response: Response): void {\n if (!url || url === 'about:' || !URL.canParse(url)) {\n return\n }\n\n const state = getValueBySymbol<UndiciResponseState>('state', response)\n\n if (state) {\n // In Undici, push the URL to the internal list of URLs.\n // This will respect the `response.url` getter logic correctly.\n state.urlList.push(new URL(url))\n } else {\n // In other libraries, redefine the `url` property directly.\n Object.defineProperty(response, 'url', {\n value: url,\n enumerable: true,\n configurable: true,\n writable: false,\n })\n }\n\n Object.defineProperty(response, kUrl, {\n value: url,\n enumerable: false,\n })\n }\n\n /**\n * Parses the given raw HTTP headers into a Fetch API `Headers` instance.\n */\n static parseRawHeaders(rawHeaders: Array<string>): Headers {\n const headers = new Headers()\n\n for (let line = 0; line < rawHeaders.length; line += 2) {\n headers.append(rawHeaders[line], rawHeaders[line + 1])\n }\n\n return headers\n }\n\n /**\n * Safely clones the given `Response`.\n * Coerces response clone exceptions into 500 mocked responses.\n * Handy in the environments that introduce arbitrary response\n * cloning restrictions, like \"101 Switching Protocols\" cloning\n * in \"miniflare\".\n */\n static clone(response: Response): Response {\n try {\n const clone = response.clone()\n return clone\n } catch (error) {\n return Response.json(\n error instanceof Error\n ? {\n name: error.name,\n message: error.message,\n stack: error.stack,\n }\n : {},\n {\n status: 500,\n statusText: 'Unclonable Response',\n }\n )\n }\n }\n\n #status?: number\n #url?: string\n\n constructor(body?: BodyInit | null, init: FetchResponseInit = {}) {\n const status = init.status ?? 200\n const safeStatus = FetchResponse.isConfigurableStatusCode(status)\n ? status\n : 200\n const finalBody = FetchResponse.isResponseWithBody(status) ? body : null\n\n super(finalBody, {\n status: safeStatus,\n statusText: init.statusText,\n headers: init.headers,\n })\n\n /**\n * Since Node.js v24, Undici stores the Response state in an inaccessible field \"#state\".\n * Forward the modified status/URL to the cloned response manually.\n * @see https://github.com/nodejs/undici/blob/f734c87280e626c75f59aad55b65eb6a89cef392/lib/web/fetch/response.js#L242\n */\n if (status !== safeStatus) {\n FetchResponse.setStatus(status, this)\n }\n\n FetchResponse.setUrl(init.url, this)\n }\n\n public clone() {\n const clonedResponse = super.clone()\n\n const customStatus = Reflect.get(this, kStatus) as number | undefined\n\n if (customStatus) {\n FetchResponse.setStatus(customStatus, clonedResponse)\n }\n\n const customUrl = Reflect.get(this, kUrl) as string | undefined\n\n if (customUrl) {\n FetchResponse.setUrl(customUrl, clonedResponse)\n }\n\n return cl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EAOD,IAAI,WAAW,YACb,cAAc,UAAU,QAAQ,IAAI;EAGtC,cAAc,OAAO,KAAK,KAAK,IAAI;CACrC;CAEA,QAAe;EACb,MAAM,iBAAiB,MAAM,MAAM;EAEnC,MAAM,eAAe,QAAQ,IAAI,MAAM,OAAO;EAE9C,IAAI,cACF,cAAc,UAAU,cAAc,cAAc;EAGtD,MAAM,YAAY,QAAQ,IAAI,MAAM,IAAI;EAExC,IAAI,WACF,cAAc,OAAO,WAAW,cAAc;EAGhD,OAAO;CACT;AACF"}
|
|
@@ -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
|