@mswjs/interceptors 0.19.5 → 0.21.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.
Files changed (175) hide show
  1. package/README.md +7 -7
  2. package/lib/browser/Interceptor-959f650e.d.ts +104 -0
  3. package/lib/browser/chunk-5B525MKF.mjs +2139 -0
  4. package/lib/browser/chunk-BQYA7ER5.mjs +258 -0
  5. package/lib/browser/chunk-IIY3SHU3.js +2139 -0
  6. package/lib/browser/chunk-QWL3EOEY.js +258 -0
  7. package/lib/browser/chunk-STA6QBYM.mjs +64 -0
  8. package/lib/browser/chunk-ZJOF5MEZ.js +64 -0
  9. package/lib/browser/index.d.ts +31 -0
  10. package/lib/browser/index.js +51 -0
  11. package/lib/browser/index.mjs +51 -0
  12. package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +14 -0
  13. package/lib/browser/interceptors/XMLHttpRequest/index.js +657 -0
  14. package/lib/browser/interceptors/XMLHttpRequest/index.mjs +657 -0
  15. package/lib/browser/interceptors/fetch/index.d.ts +12 -0
  16. package/lib/browser/interceptors/fetch/index.js +94 -0
  17. package/lib/browser/interceptors/fetch/index.mjs +94 -0
  18. package/lib/node/BatchInterceptor-a7261b26.d.ts +21 -0
  19. package/lib/node/Interceptor-997045eb.d.ts +104 -0
  20. package/lib/{RemoteHttpInterceptor.d.ts → node/RemoteHttpInterceptor.d.ts} +17 -12
  21. package/lib/node/RemoteHttpInterceptor.js +176 -0
  22. package/lib/node/RemoteHttpInterceptor.mjs +176 -0
  23. package/lib/node/chunk-6GWWOJ23.js +29 -0
  24. package/lib/node/chunk-6V3JXLBF.js +6093 -0
  25. package/lib/node/chunk-CIN5URNI.mjs +29 -0
  26. package/lib/node/chunk-FCIAOT7W.mjs +660 -0
  27. package/lib/node/chunk-GFH37L5D.mjs +6 -0
  28. package/lib/node/chunk-HDUJCCWF.js +661 -0
  29. package/lib/node/chunk-JISWS3Y3.mjs +31 -0
  30. package/lib/node/chunk-KZJG2UW7.js +31 -0
  31. package/lib/node/chunk-NNVTJLQA.mjs +6093 -0
  32. package/lib/node/chunk-QMIXLBOU.js +291 -0
  33. package/lib/node/chunk-STA6QBYM.mjs +64 -0
  34. package/lib/node/chunk-VKKFXSTL.js +660 -0
  35. package/lib/node/chunk-VQ4DZOBB.js +6 -0
  36. package/lib/node/chunk-ZJOF5MEZ.js +64 -0
  37. package/lib/node/chunk-ZSI7MX3V.mjs +291 -0
  38. package/lib/node/chunk-ZWCZGO3W.mjs +661 -0
  39. package/lib/node/index.d.ts +14 -0
  40. package/lib/node/index.js +32 -0
  41. package/lib/node/index.mjs +32 -0
  42. package/lib/node/interceptors/ClientRequest/index.d.ts +22 -0
  43. package/lib/node/interceptors/ClientRequest/index.js +9 -0
  44. package/lib/node/interceptors/ClientRequest/index.mjs +9 -0
  45. package/lib/node/interceptors/XMLHttpRequest/index.d.ts +14 -0
  46. package/lib/node/interceptors/XMLHttpRequest/index.js +11 -0
  47. package/lib/node/interceptors/XMLHttpRequest/index.mjs +11 -0
  48. package/lib/node/interceptors/fetch/index.d.ts +12 -0
  49. package/lib/node/interceptors/fetch/index.js +96 -0
  50. package/lib/node/interceptors/fetch/index.mjs +96 -0
  51. package/package.json +58 -9
  52. package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +1 -1
  53. package/src/interceptors/XMLHttpRequest/XMLHttpRequestController.ts +578 -0
  54. package/src/interceptors/XMLHttpRequest/XMLHttpRequestProxy.ts +111 -0
  55. package/src/interceptors/XMLHttpRequest/index.ts +12 -13
  56. package/src/shims/webEncoding.ts +9 -0
  57. package/src/utils/bufferUtils.ts +1 -1
  58. package/src/utils/createProxy.ts +78 -0
  59. package/lib/BatchInterceptor.d.ts +0 -18
  60. package/lib/BatchInterceptor.js +0 -34
  61. package/lib/BatchInterceptor.js.map +0 -1
  62. package/lib/Interceptor.d.ts +0 -50
  63. package/lib/Interceptor.js +0 -172
  64. package/lib/Interceptor.js.map +0 -1
  65. package/lib/RemoteHttpInterceptor.js +0 -158
  66. package/lib/RemoteHttpInterceptor.js.map +0 -1
  67. package/lib/glossary.d.ts +0 -7
  68. package/lib/glossary.js +0 -5
  69. package/lib/glossary.js.map +0 -1
  70. package/lib/index.d.ts +0 -5
  71. package/lib/index.js +0 -23
  72. package/lib/index.js.map +0 -1
  73. package/lib/interceptors/ClientRequest/NodeClientRequest.d.ts +0 -46
  74. package/lib/interceptors/ClientRequest/NodeClientRequest.js +0 -325
  75. package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +0 -1
  76. package/lib/interceptors/ClientRequest/http.get.d.ts +0 -4
  77. package/lib/interceptors/ClientRequest/http.get.js +0 -19
  78. package/lib/interceptors/ClientRequest/http.get.js.map +0 -1
  79. package/lib/interceptors/ClientRequest/http.request.d.ts +0 -4
  80. package/lib/interceptors/ClientRequest/http.request.js +0 -16
  81. package/lib/interceptors/ClientRequest/http.request.js.map +0 -1
  82. package/lib/interceptors/ClientRequest/index.d.ts +0 -19
  83. package/lib/interceptors/ClientRequest/index.js +0 -50
  84. package/lib/interceptors/ClientRequest/index.js.map +0 -1
  85. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.d.ts +0 -10
  86. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +0 -60
  87. package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +0 -1
  88. package/lib/interceptors/ClientRequest/utils/createRequest.d.ts +0 -6
  89. package/lib/interceptors/ClientRequest/utils/createRequest.js +0 -30
  90. package/lib/interceptors/ClientRequest/utils/createRequest.js.map +0 -1
  91. package/lib/interceptors/ClientRequest/utils/createResponse.d.ts +0 -8
  92. package/lib/interceptors/ClientRequest/utils/createResponse.js +0 -24
  93. package/lib/interceptors/ClientRequest/utils/createResponse.js.map +0 -1
  94. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.d.ts +0 -3
  95. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js +0 -57
  96. package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +0 -1
  97. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.d.ts +0 -17
  98. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js +0 -151
  99. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js.map +0 -1
  100. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.d.ts +0 -15
  101. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js +0 -33
  102. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js.map +0 -1
  103. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.d.ts +0 -13
  104. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js +0 -20
  105. package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js.map +0 -1
  106. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.d.ts +0 -93
  107. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js +0 -442
  108. package/lib/interceptors/XMLHttpRequest/XMLHttpRequestOverride.js.map +0 -1
  109. package/lib/interceptors/XMLHttpRequest/index.d.ts +0 -12
  110. package/lib/interceptors/XMLHttpRequest/index.js +0 -43
  111. package/lib/interceptors/XMLHttpRequest/index.js.map +0 -1
  112. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.d.ts +0 -31
  113. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js +0 -44
  114. package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js.map +0 -1
  115. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.d.ts +0 -8
  116. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js +0 -15
  117. package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js.map +0 -1
  118. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.d.ts +0 -4
  119. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js +0 -14
  120. package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js.map +0 -1
  121. package/lib/interceptors/XMLHttpRequest/utils/createEvent.d.ts +0 -2
  122. package/lib/interceptors/XMLHttpRequest/utils/createEvent.js +0 -37
  123. package/lib/interceptors/XMLHttpRequest/utils/createEvent.js.map +0 -1
  124. package/lib/interceptors/XMLHttpRequest/utils/createResponse.d.ts +0 -2
  125. package/lib/interceptors/XMLHttpRequest/utils/createResponse.js +0 -14
  126. package/lib/interceptors/XMLHttpRequest/utils/createResponse.js.map +0 -1
  127. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.d.ts +0 -1
  128. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js +0 -17
  129. package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js.map +0 -1
  130. package/lib/interceptors/fetch/index.d.ts +0 -8
  131. package/lib/interceptors/fetch/index.js +0 -81
  132. package/lib/interceptors/fetch/index.js.map +0 -1
  133. package/lib/presets/browser.d.ts +0 -8
  134. package/lib/presets/browser.js +0 -10
  135. package/lib/presets/browser.js.map +0 -1
  136. package/lib/presets/node.d.ts +0 -8
  137. package/lib/presets/node.js +0 -10
  138. package/lib/presets/node.js.map +0 -1
  139. package/lib/utils/AsyncEventEmitter.d.ts +0 -33
  140. package/lib/utils/AsyncEventEmitter.js +0 -148
  141. package/lib/utils/AsyncEventEmitter.js.map +0 -1
  142. package/lib/utils/bufferUtils.d.ts +0 -8
  143. package/lib/utils/bufferUtils.js +0 -24
  144. package/lib/utils/bufferUtils.js.map +0 -1
  145. package/lib/utils/cloneObject.d.ts +0 -1
  146. package/lib/utils/cloneObject.js +0 -28
  147. package/lib/utils/cloneObject.js.map +0 -1
  148. package/lib/utils/createLazyCallback.d.ts +0 -11
  149. package/lib/utils/createLazyCallback.js +0 -40
  150. package/lib/utils/createLazyCallback.js.map +0 -1
  151. package/lib/utils/getCleanUrl.d.ts +0 -4
  152. package/lib/utils/getCleanUrl.js +0 -11
  153. package/lib/utils/getCleanUrl.js.map +0 -1
  154. package/lib/utils/getRequestOptionsByUrl.d.ts +0 -8
  155. package/lib/utils/getRequestOptionsByUrl.js +0 -28
  156. package/lib/utils/getRequestOptionsByUrl.js.map +0 -1
  157. package/lib/utils/getUrlByRequestOptions.d.ts +0 -11
  158. package/lib/utils/getUrlByRequestOptions.js +0 -78
  159. package/lib/utils/getUrlByRequestOptions.js.map +0 -1
  160. package/lib/utils/isObject.d.ts +0 -4
  161. package/lib/utils/isObject.js +0 -11
  162. package/lib/utils/isObject.js.map +0 -1
  163. package/lib/utils/nextTick.d.ts +0 -2
  164. package/lib/utils/nextTick.js +0 -16
  165. package/lib/utils/nextTick.js.map +0 -1
  166. package/lib/utils/parseJson.d.ts +0 -5
  167. package/lib/utils/parseJson.js +0 -18
  168. package/lib/utils/parseJson.js.map +0 -1
  169. package/lib/utils/toInteractiveRequest.d.ts +0 -7
  170. package/lib/utils/toInteractiveRequest.js +0 -20
  171. package/lib/utils/toInteractiveRequest.js.map +0 -1
  172. package/lib/utils/uuid.d.ts +0 -1
  173. package/lib/utils/uuid.js +0 -12
  174. package/lib/utils/uuid.js.map +0 -1
  175. package/src/interceptors/XMLHttpRequest/XMLHttpRequestOverride.ts +0 -684
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRequest = void 0;
4
- const web_fetch_1 = require("@remix-run/web-fetch");
5
- const headers_polyfill_1 = require("headers-polyfill");
6
- /**
7
- * Creates a Fetch API `Request` instance from the given `http.ClientRequest`.
8
- */
9
- function createRequest(clientRequest) {
10
- const headers = new headers_polyfill_1.Headers();
11
- const outgoingHeaders = clientRequest.getHeaders();
12
- for (const headerName in outgoingHeaders) {
13
- const headerValue = outgoingHeaders[headerName];
14
- if (!headerValue) {
15
- continue;
16
- }
17
- const valuesList = Array.prototype.concat([], headerValue);
18
- for (const value of valuesList) {
19
- headers.append(headerName, value.toString());
20
- }
21
- }
22
- return new web_fetch_1.Request(clientRequest.url, {
23
- method: clientRequest.method || 'GET',
24
- headers,
25
- credentials: 'same-origin',
26
- body: clientRequest.requestBuffer,
27
- });
28
- }
29
- exports.createRequest = createRequest;
30
- //# sourceMappingURL=createRequest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createRequest.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/createRequest.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;AAC9C,uDAA0C;AAG1C;;GAEG;AACH,SAAgB,aAAa,CAAC,aAAgC;IAC5D,MAAM,OAAO,GAAG,IAAI,0BAAO,EAAE,CAAA;IAE7B,MAAM,eAAe,GAAG,aAAa,CAAC,UAAU,EAAE,CAAA;IAClD,KAAK,MAAM,UAAU,IAAI,eAAe,EAAE;QACxC,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,CAAC,CAAA;QAE/C,IAAI,CAAC,WAAW,EAAE;YAChB,SAAQ;SACT;QAED,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,CAAA;QAC1D,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;YAC9B,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;SAC7C;KACF;IAED,OAAO,IAAI,mBAAO,CAAC,aAAa,CAAC,GAAG,EAAE;QACpC,MAAM,EAAE,aAAa,CAAC,MAAM,IAAI,KAAK;QACrC,OAAO;QACP,WAAW,EAAE,aAAa;QAC1B,IAAI,EAAE,aAAa,CAAC,aAAa;KAClC,CAAC,CAAA;AACJ,CAAC;AAvBD,sCAuBC"}
@@ -1,8 +0,0 @@
1
- /// <reference types="node" />
2
- import type { IncomingMessage } from 'http';
3
- import { Response } from '@remix-run/web-fetch';
4
- /**
5
- * Creates a Fetch API `Response` instance from the given
6
- * `http.IncomingMessage` instance.
7
- */
8
- export declare function createResponse(message: IncomingMessage): Response;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createResponse = void 0;
4
- const web_fetch_1 = require("@remix-run/web-fetch");
5
- const headers_polyfill_1 = require("headers-polyfill");
6
- /**
7
- * Creates a Fetch API `Response` instance from the given
8
- * `http.IncomingMessage` instance.
9
- */
10
- function createResponse(message) {
11
- const readable = new web_fetch_1.ReadableStream({
12
- start(controller) {
13
- message.on('data', (chunk) => controller.enqueue(chunk));
14
- message.on('end', () => controller.close());
15
- },
16
- });
17
- return new web_fetch_1.Response(readable, {
18
- status: message.statusCode,
19
- statusText: message.statusMessage,
20
- headers: (0, headers_polyfill_1.objectToHeaders)(message.headers),
21
- });
22
- }
23
- exports.createResponse = createResponse;
24
- //# sourceMappingURL=createResponse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createResponse.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/createResponse.ts"],"names":[],"mappings":";;;AACA,oDAA+D;AAC/D,uDAAkD;AAElD;;;GAGG;AACH,SAAgB,cAAc,CAAC,OAAwB;IACrD,MAAM,QAAQ,GAAG,IAAI,0BAAc,CAAC;QAClC,KAAK,CAAC,UAAU;YACd,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;YACxD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;QAC7C,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,IAAI,oBAAQ,CAAC,QAAQ,EAAE;QAC5B,MAAM,EAAE,OAAO,CAAC,UAAU;QAC1B,UAAU,EAAE,OAAO,CAAC,aAAa;QACjC,OAAO,EAAE,IAAA,kCAAe,EAAC,OAAO,CAAC,OAAO,CAAC;KAC1C,CAAC,CAAA;AACJ,CAAC;AAbD,wCAaC"}
@@ -1,3 +0,0 @@
1
- /// <reference types="node" />
2
- import { IncomingMessage } from 'http';
3
- export declare function getIncomingMessageBody(response: IncomingMessage): Promise<string>;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getIncomingMessageBody = void 0;
23
- const debug_1 = require("debug");
24
- const stream_1 = require("stream");
25
- const zlib = __importStar(require("zlib"));
26
- const log = (0, debug_1.debug)('http getIncomingMessageBody');
27
- function getIncomingMessageBody(response) {
28
- return new Promise((resolve, reject) => {
29
- log('cloning the original response...');
30
- // Pipe the original response to support non-clone
31
- // "response" input. No need to clone the response,
32
- // as we always have access to the full "response" input,
33
- // either a clone or an original one (in tests).
34
- const responseClone = response.pipe(new stream_1.PassThrough());
35
- const stream = response.headers['content-encoding'] === 'gzip'
36
- ? responseClone.pipe(zlib.createGunzip())
37
- : responseClone;
38
- const encoding = response.readableEncoding || 'utf8';
39
- stream.setEncoding(encoding);
40
- log('using encoding:', encoding);
41
- let body = '';
42
- stream.on('data', (responseBody) => {
43
- log('response body read:', responseBody);
44
- body += responseBody;
45
- });
46
- stream.once('end', () => {
47
- log('response body end');
48
- resolve(body);
49
- });
50
- stream.once('error', (error) => {
51
- log('error while reading response body:', error);
52
- reject(error);
53
- });
54
- });
55
- }
56
- exports.getIncomingMessageBody = getIncomingMessageBody;
57
- //# sourceMappingURL=getIncomingMessageBody.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getIncomingMessageBody.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/getIncomingMessageBody.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA6B;AAE7B,mCAAoC;AACpC,2CAA4B;AAE5B,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,6BAA6B,CAAC,CAAA;AAEhD,SAAgB,sBAAsB,CACpC,QAAyB;IAEzB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,GAAG,CAAC,kCAAkC,CAAC,CAAA;QAEvC,kDAAkD;QAClD,mDAAmD;QACnD,yDAAyD;QACzD,gDAAgD;QAChD,MAAM,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,oBAAW,EAAE,CAAC,CAAA;QACtD,MAAM,MAAM,GACV,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,MAAM;YAC7C,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACzC,CAAC,CAAC,aAAa,CAAA;QAEnB,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,IAAI,MAAM,CAAA;QACpD,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QAC5B,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAA;QAEhC,IAAI,IAAI,GAAG,EAAE,CAAA;QAEb,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,YAAY,EAAE,EAAE;YACjC,GAAG,CAAC,qBAAqB,EAAE,YAAY,CAAC,CAAA;YACxC,IAAI,IAAI,YAAY,CAAA;QACtB,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;YACtB,GAAG,CAAC,mBAAmB,CAAC,CAAA;YACxB,OAAO,CAAC,IAAI,CAAC,CAAA;QACf,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC7B,GAAG,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAA;YAChD,MAAM,CAAC,KAAK,CAAC,CAAA;QACf,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AArCD,wDAqCC"}
@@ -1,17 +0,0 @@
1
- /// <reference types="node" />
2
- import { IncomingMessage } from 'http';
3
- import { RequestOptions } from 'https';
4
- import { Url as LegacyURL } from 'url';
5
- import { ResolvedRequestOptions } from '../../../utils/getUrlByRequestOptions';
6
- export declare type HttpRequestCallback = (response: IncomingMessage) => void;
7
- export declare type ClientRequestArgs = [string | URL | LegacyURL, HttpRequestCallback?] | [string | URL | LegacyURL, RequestOptions, HttpRequestCallback?] | [RequestOptions, HttpRequestCallback?];
8
- export declare type NormalizedClientRequestArgs = [
9
- url: URL,
10
- options: ResolvedRequestOptions,
11
- callback?: HttpRequestCallback
12
- ];
13
- /**
14
- * Normalizes parameters given to a `http.request` call
15
- * so it always has a `URL` and `RequestOptions`.
16
- */
17
- export declare function normalizeClientRequestArgs(defaultProtocol: string, ...args: ClientRequestArgs): NormalizedClientRequestArgs;
@@ -1,151 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeClientRequestArgs = void 0;
4
- const debug_1 = require("debug");
5
- const http_1 = require("http");
6
- const https_1 = require("https");
7
- const getRequestOptionsByUrl_1 = require("../../../utils/getRequestOptionsByUrl");
8
- const getUrlByRequestOptions_1 = require("../../../utils/getUrlByRequestOptions");
9
- const cloneObject_1 = require("../../../utils/cloneObject");
10
- const isObject_1 = require("../../../utils/isObject");
11
- const log = (0, debug_1.debug)('http normalizeClientRequestArgs');
12
- function resolveRequestOptions(args, url) {
13
- // Calling `fetch` provides only URL to `ClientRequest`
14
- // without any `RequestOptions` or callback.
15
- if (typeof args[1] === 'undefined' || typeof args[1] === 'function') {
16
- log('request options not provided, deriving from the url', url);
17
- return (0, getRequestOptionsByUrl_1.getRequestOptionsByUrl)(url);
18
- }
19
- if (args[1]) {
20
- log('has custom RequestOptions!', args[1]);
21
- const requestOptionsFromUrl = (0, getRequestOptionsByUrl_1.getRequestOptionsByUrl)(url);
22
- log('derived RequestOptions from the URL:', requestOptionsFromUrl);
23
- /**
24
- * Clone the request options to lock their state
25
- * at the moment they are provided to `ClientRequest`.
26
- * @see https://github.com/mswjs/interceptors/issues/86
27
- */
28
- log('cloning RequestOptions...');
29
- const clonedRequestOptions = (0, cloneObject_1.cloneObject)(args[1]);
30
- log('successfully cloned RequestOptions!', clonedRequestOptions);
31
- return Object.assign(Object.assign({}, requestOptionsFromUrl), clonedRequestOptions);
32
- }
33
- log('using an empty object as request options');
34
- return {};
35
- }
36
- function resolveCallback(args) {
37
- return typeof args[1] === 'function' ? args[1] : args[2];
38
- }
39
- /**
40
- * Normalizes parameters given to a `http.request` call
41
- * so it always has a `URL` and `RequestOptions`.
42
- */
43
- function normalizeClientRequestArgs(defaultProtocol, ...args) {
44
- let url;
45
- let options;
46
- let callback;
47
- log('arguments', args);
48
- log('using default protocol:', defaultProtocol);
49
- // Convert a url string into a URL instance
50
- // and derive request options from it.
51
- if (typeof args[0] === 'string') {
52
- log('first argument is a location string:', args[0]);
53
- url = new URL(args[0]);
54
- log('created a url:', url);
55
- const requestOptionsFromUrl = (0, getRequestOptionsByUrl_1.getRequestOptionsByUrl)(url);
56
- log('request options from url:', requestOptionsFromUrl);
57
- options = resolveRequestOptions(args, url);
58
- log('resolved request options:', options);
59
- callback = resolveCallback(args);
60
- }
61
- // Handle a given URL instance as-is
62
- // and derive request options from it.
63
- else if (args[0] instanceof URL) {
64
- url = args[0];
65
- log('first argument is a URL:', url);
66
- options = resolveRequestOptions(args, url);
67
- log('derived request options:', options);
68
- callback = resolveCallback(args);
69
- }
70
- // Handle a legacy URL instance and re-normalize from either a RequestOptions object
71
- // or a WHATWG URL.
72
- else if ('hash' in args[0] && !('method' in args[0])) {
73
- const [legacyUrl] = args;
74
- log('first argument is a legacy URL:', legacyUrl);
75
- if (legacyUrl.hostname === null) {
76
- /**
77
- * We are dealing with a relative url, so use the path as an "option" and
78
- * merge in any existing options, giving priority to exising options -- i.e. a path in any
79
- * existing options will take precedence over the one contained in the url. This is consistent
80
- * with the behaviour in ClientRequest.
81
- * @see https://github.com/nodejs/node/blob/d84f1312915fe45fe0febe888db692c74894c382/lib/_http_client.js#L122
82
- */
83
- log('given legacy URL is relative (no hostname)');
84
- return (0, isObject_1.isObject)(args[1])
85
- ? normalizeClientRequestArgs(defaultProtocol, Object.assign({ path: legacyUrl.path }, args[1]), args[2])
86
- : normalizeClientRequestArgs(defaultProtocol, { path: legacyUrl.path }, args[1]);
87
- }
88
- log('given legacy url is absolute');
89
- // We are dealing with an absolute URL, so convert to WHATWG and try again.
90
- const resolvedUrl = new URL(legacyUrl.href);
91
- return args[1] === undefined
92
- ? normalizeClientRequestArgs(defaultProtocol, resolvedUrl)
93
- : typeof args[1] === 'function'
94
- ? normalizeClientRequestArgs(defaultProtocol, resolvedUrl, args[1])
95
- : normalizeClientRequestArgs(defaultProtocol, resolvedUrl, args[1], args[2]);
96
- }
97
- // Handle a given "RequestOptions" object as-is
98
- // and derive the URL instance from it.
99
- else if ((0, isObject_1.isObject)(args[0])) {
100
- options = args[0];
101
- log('first argument is RequestOptions:', options);
102
- // When handling a "RequestOptions" object without an explicit "protocol",
103
- // infer the protocol from the request issuing module (http/https).
104
- options.protocol = options.protocol || defaultProtocol;
105
- log('normalized request options:', options);
106
- url = (0, getUrlByRequestOptions_1.getUrlByRequestOptions)(options);
107
- log('created a URL from RequestOptions:', url.href);
108
- callback = resolveCallback(args);
109
- }
110
- else {
111
- throw new Error(`Failed to construct ClientRequest with these parameters: ${args}`);
112
- }
113
- options.protocol = options.protocol || url.protocol;
114
- options.method = options.method || 'GET';
115
- /**
116
- * Infer a fallback agent from the URL protocol.
117
- * The interception is done on the "ClientRequest" level ("NodeClientRequest")
118
- * and it may miss the correct agent. Always align the agent
119
- * with the URL protocol, if not provided.
120
- *
121
- * @note Respect the "agent: false" value.
122
- */
123
- if (typeof options.agent === 'undefined') {
124
- const agent = options.protocol === 'https:'
125
- ? new https_1.Agent({
126
- rejectUnauthorized: options.rejectUnauthorized,
127
- })
128
- : new http_1.Agent();
129
- options.agent = agent;
130
- log('resolved fallback agent:', agent);
131
- }
132
- /**
133
- * Ensure that the default Agent is always set.
134
- * This prevents the protocol mismatch for requests with { agent: false },
135
- * where the global Agent is inferred.
136
- * @see https://github.com/mswjs/msw/issues/1150
137
- * @see https://github.com/nodejs/node/blob/418ff70b810f0e7112d48baaa72932a56cfa213b/lib/_http_client.js#L130
138
- * @see https://github.com/nodejs/node/blob/418ff70b810f0e7112d48baaa72932a56cfa213b/lib/_http_client.js#L157-L159
139
- */
140
- if (!options._defaultAgent) {
141
- log('has no default agent, setting the default agent for "%s"', options.protocol);
142
- options._defaultAgent =
143
- options.protocol === 'https:' ? https_1.globalAgent : http_1.globalAgent;
144
- }
145
- log('successfully resolved url:', url.href);
146
- log('successfully resolved options:', options);
147
- log('successfully resolved callback:', callback);
148
- return [url, options, callback];
149
- }
150
- exports.normalizeClientRequestArgs = normalizeClientRequestArgs;
151
- //# sourceMappingURL=normalizeClientRequestArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeClientRequestArgs.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,+BAIa;AACb,iCAIc;AAEd,kFAA8E;AAC9E,kFAG8C;AAC9C,4DAAwD;AACxD,sDAAkD;AAElD,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,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IAEhD,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;AACjC,CAAC;AAtJD,gEAsJC"}
@@ -1,15 +0,0 @@
1
- /// <reference types="node" />
2
- export declare type ClientRequestEndChunk = string | Buffer;
3
- export declare type ClientRequestEndCallback = () => void;
4
- declare type HttpRequestEndArgs = [] | [ClientRequestEndCallback] | [ClientRequestEndChunk, ClientRequestEndCallback?] | [ClientRequestEndChunk, BufferEncoding, ClientRequestEndCallback?];
5
- declare type NormalizedHttpRequestEndParams = [
6
- ClientRequestEndChunk | null,
7
- BufferEncoding | null,
8
- ClientRequestEndCallback | null
9
- ];
10
- /**
11
- * Normalizes a list of arguments given to the `ClientRequest.end()`
12
- * method to always include `chunk`, `encoding`, and `callback`.
13
- */
14
- export declare function normalizeClientRequestEndArgs(...args: HttpRequestEndArgs): NormalizedHttpRequestEndParams;
15
- export {};
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeClientRequestEndArgs = void 0;
4
- const debug = require('debug')('http normalizeClientRequestEndArgs');
5
- /**
6
- * Normalizes a list of arguments given to the `ClientRequest.end()`
7
- * method to always include `chunk`, `encoding`, and `callback`.
8
- */
9
- function normalizeClientRequestEndArgs(...args) {
10
- debug('arguments', args);
11
- const normalizedArgs = new Array(3)
12
- .fill(null)
13
- .map((value, index) => args[index] || value);
14
- normalizedArgs.sort((a, b) => {
15
- // If first element is a function, move it rightwards.
16
- if (typeof a === 'function') {
17
- return 1;
18
- }
19
- // If second element is a function, move the first leftwards.
20
- if (typeof b === 'function') {
21
- return -1;
22
- }
23
- // If both elements are strings, preserve their original index.
24
- if (typeof a === 'string' && typeof b === 'string') {
25
- return normalizedArgs.indexOf(a) - normalizedArgs.indexOf(b);
26
- }
27
- return 0;
28
- });
29
- debug('normalized args', normalizedArgs);
30
- return normalizedArgs;
31
- }
32
- exports.normalizeClientRequestEndArgs = normalizeClientRequestEndArgs;
33
- //# sourceMappingURL=normalizeClientRequestEndArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeClientRequestEndArgs.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,oCAAoC,CAAC,CAAA;AAiBpE;;;GAGG;AACH,SAAgB,6BAA6B,CAC3C,GAAG,IAAwB;IAE3B,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;IACxB,MAAM,cAAc,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC;SAChC,IAAI,CAAC,IAAI,CAAC;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,CAAA;IAE9C,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3B,sDAAsD;QACtD,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;YAC3B,OAAO,CAAC,CAAA;SACT;QAED,6DAA6D;QAC7D,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;YAC3B,OAAO,CAAC,CAAC,CAAA;SACV;QAED,+DAA+D;QAC/D,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE;YAClD,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;SAC7D;QAED,OAAO,CAAC,CAAA;IACV,CAAC,CAAC,CAAA;IAEF,KAAK,CAAC,iBAAiB,EAAE,cAAc,CAAC,CAAA;IACxC,OAAO,cAAgD,CAAA;AACzD,CAAC;AA7BD,sEA6BC"}
@@ -1,13 +0,0 @@
1
- /// <reference types="node" />
2
- export declare type ClientRequestWriteCallback = (error?: Error | null) => void;
3
- export declare type ClientRequestWriteArgs = [
4
- chunk: string | Buffer,
5
- encoding?: BufferEncoding | ClientRequestWriteCallback,
6
- callback?: ClientRequestWriteCallback
7
- ];
8
- export declare type NormalizedClientRequestWriteArgs = [
9
- chunk: string | Buffer,
10
- encoding?: BufferEncoding,
11
- callback?: ClientRequestWriteCallback
12
- ];
13
- export declare function normalizeClientRequestWriteArgs(args: ClientRequestWriteArgs): NormalizedClientRequestWriteArgs;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeClientRequestWriteArgs = void 0;
4
- const debug_1 = require("debug");
5
- const log = (0, debug_1.debug)('http normalizeWriteArgs');
6
- function normalizeClientRequestWriteArgs(args) {
7
- log('normalizing ClientRequest.write arguments...', args);
8
- const chunk = args[0];
9
- const encoding = typeof args[1] === 'string' ? args[1] : undefined;
10
- const callback = typeof args[1] === 'function' ? args[1] : args[2];
11
- const writeArgs = [
12
- chunk,
13
- encoding,
14
- callback,
15
- ];
16
- log('successfully normalized ClientRequest.write arguments:', writeArgs);
17
- return writeArgs;
18
- }
19
- exports.normalizeClientRequestWriteArgs = normalizeClientRequestWriteArgs;
20
- //# sourceMappingURL=normalizeClientRequestWriteArgs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeClientRequestWriteArgs.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,yBAAyB,CAAC,CAAA;AAe5C,SAAgB,+BAA+B,CAC7C,IAA4B;IAE5B,GAAG,CAAC,8CAA8C,EAAE,IAAI,CAAC,CAAA;IAEzD,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACrB,MAAM,QAAQ,GACZ,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAE,IAAI,CAAC,CAAC,CAAoB,CAAC,CAAC,CAAC,SAAS,CAAA;IACvE,MAAM,QAAQ,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAElE,MAAM,SAAS,GAAqC;QAClD,KAAK;QACL,QAAQ;QACR,QAAQ;KACT,CAAA;IACD,GAAG,CAAC,wDAAwD,EAAE,SAAS,CAAC,CAAA;IAExE,OAAO,SAAS,CAAA;AAClB,CAAC;AAlBD,0EAkBC"}
@@ -1,93 +0,0 @@
1
- /**
2
- * XMLHttpRequest override class.
3
- * Inspired by https://github.com/marvinhagemeister/xhr-mocklet.
4
- */
5
- import type { Debugger } from 'debug';
6
- import { Headers } from 'headers-polyfill';
7
- import type { XMLHttpRequestEmitter } from '.';
8
- declare type XMLHttpRequestEventHandler = (this: XMLHttpRequest, event: Event | ProgressEvent<any>) => void;
9
- interface XMLHttpRequestEvent<EventMap extends any> {
10
- name: keyof EventMap;
11
- listener: XMLHttpRequestEventHandler;
12
- }
13
- interface CreateXMLHttpRequestOverrideOptions {
14
- XMLHttpRequest: typeof window.XMLHttpRequest;
15
- emitter: XMLHttpRequestEmitter;
16
- log: Debugger;
17
- }
18
- interface InternalXMLHttpRequestEventTargetEventMap extends XMLHttpRequestEventTargetEventMap {
19
- readystatechange: Event;
20
- }
21
- export declare type ExtractCallbacks<Key extends string> = Key extends 'abort' | `on${infer _CallbackName}` ? Key : never;
22
- export declare const createXMLHttpRequestOverride: (options: CreateXMLHttpRequestOverrideOptions) => {
23
- new (): {
24
- _requestHeaders: Headers;
25
- _responseHeaders: Headers;
26
- _responseBuffer: Uint8Array;
27
- _events: XMLHttpRequestEvent<InternalXMLHttpRequestEventTargetEventMap>[];
28
- log: Debugger;
29
- readonly UNSENT: 0;
30
- readonly OPENED: 1;
31
- readonly HEADERS_RECEIVED: 2;
32
- readonly LOADING: 3;
33
- readonly DONE: 4;
34
- method: string;
35
- url: string;
36
- withCredentials: boolean;
37
- status: number;
38
- statusText: string;
39
- user?: string | undefined;
40
- password?: string | undefined;
41
- async?: boolean | undefined;
42
- responseType: XMLHttpRequestResponseType;
43
- responseURL: string;
44
- upload: XMLHttpRequestUpload;
45
- readyState: number;
46
- onreadystatechange: (this: XMLHttpRequest, ev: Event) => any;
47
- timeout: number;
48
- onabort: (this: XMLHttpRequestEventTarget, event: ProgressEvent) => any;
49
- onerror: (this: XMLHttpRequestEventTarget, event: Event) => any;
50
- onload: (this: XMLHttpRequestEventTarget, event: ProgressEvent) => any;
51
- onloadend: (this: XMLHttpRequestEventTarget, event: ProgressEvent) => any;
52
- onloadstart: (this: XMLHttpRequestEventTarget, event: ProgressEvent) => any;
53
- onprogress: (this: XMLHttpRequestEventTarget, event: ProgressEvent) => any;
54
- ontimeout: (this: XMLHttpRequestEventTarget, event: ProgressEvent) => any;
55
- setReadyState(nextState: number): void;
56
- /**
57
- * Triggers both direct callback and attached event listeners
58
- * for the given event.
59
- */
60
- trigger<K extends "readystatechange" | keyof XMLHttpRequestEventTargetEventMap>(eventName: K, options?: ProgressEventInit | undefined): any;
61
- reset(): void;
62
- open(method: string, url: string, async?: boolean, user?: string | undefined, password?: string | undefined): Promise<void>;
63
- send(data?: string | ArrayBuffer | undefined): void;
64
- readonly responseText: string;
65
- readonly response: unknown;
66
- readonly responseXML: Document | null;
67
- abort(): void;
68
- dispatchEvent(): boolean;
69
- setRequestHeader(name: string, value: string): void;
70
- getResponseHeader(name: string): string | null;
71
- getAllResponseHeaders(): string;
72
- addEventListener<Event_1 extends keyof InternalXMLHttpRequestEventTargetEventMap>(event: Event_1, listener: XMLHttpRequestEventHandler): void;
73
- removeEventListener<Event_2 extends keyof XMLHttpRequestEventMap>(event: Event_2, listener: (event?: XMLHttpRequestEventMap[Event_2] | undefined) => void): void;
74
- overrideMimeType(): void;
75
- /**
76
- * Propagates mock XMLHttpRequest instance callbacks
77
- * to the given XMLHttpRequest instance.
78
- */
79
- propagateCallbacks(request: XMLHttpRequest): void;
80
- /**
81
- * Propagates the mock XMLHttpRequest instance listeners
82
- * to the given XMLHttpRequest instance.
83
- */
84
- propagateListeners(request: XMLHttpRequest): void;
85
- propagateHeaders(request: XMLHttpRequest, headers: Headers): void;
86
- };
87
- readonly UNSENT: 0;
88
- readonly OPENED: 1;
89
- readonly HEADERS_RECEIVED: 2;
90
- readonly LOADING: 3;
91
- readonly DONE: 4;
92
- };
93
- export {};