@typespec/ts-http-runtime 0.3.4-alpha.20260227.2 → 0.3.4

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 (295) hide show
  1. package/dist/browser/client/sendRequest.d.ts +10 -1
  2. package/dist/browser/client/sendRequest.js +8 -2
  3. package/dist/browser/client/sendRequest.js.map +1 -1
  4. package/dist/browser/defaultHttpClient.d.ts +1 -1
  5. package/dist/browser/defaultHttpClient.js +1 -1
  6. package/dist/browser/defaultHttpClient.js.map +1 -0
  7. package/dist/browser/index.d.ts +2 -2
  8. package/dist/browser/index.js +0 -2
  9. package/dist/browser/index.js.map +1 -1
  10. package/dist/browser/logger/log.d.ts +1 -1
  11. package/dist/browser/logger/log.js +1 -1
  12. package/dist/browser/logger/log.js.map +1 -0
  13. package/dist/browser/pipelineRequest.d.ts +1 -1
  14. package/dist/browser/pipelineRequest.js.map +1 -1
  15. package/dist/browser/policies/decompressResponsePolicy.d.ts +3 -2
  16. package/dist/browser/policies/decompressResponsePolicy.js +1 -4
  17. package/dist/browser/policies/decompressResponsePolicy.js.map +1 -0
  18. package/dist/browser/policies/internal.d.ts +7 -7
  19. package/dist/browser/policies/internal.js +2 -2
  20. package/dist/browser/policies/internal.js.map +1 -1
  21. package/dist/browser/policies/proxyPolicy.common.d.ts +7 -3
  22. package/dist/browser/policies/proxyPolicy.common.js +2 -2
  23. package/dist/browser/policies/proxyPolicy.common.js.map +1 -1
  24. package/dist/browser/policies/proxyPolicy.d.ts +1 -1
  25. package/dist/browser/policies/proxyPolicy.js +1 -1
  26. package/dist/browser/policies/proxyPolicy.js.map +1 -0
  27. package/dist/browser/policies/redirectPolicy.d.ts +7 -0
  28. package/dist/browser/policies/redirectPolicy.js +13 -4
  29. package/dist/browser/policies/redirectPolicy.js.map +1 -1
  30. package/dist/browser/util/bytesEncoding.d.ts +1 -1
  31. package/dist/browser/util/bytesEncoding.js +1 -1
  32. package/dist/browser/util/bytesEncoding.js.map +1 -0
  33. package/dist/browser/util/concat.common.d.ts +1 -2
  34. package/dist/browser/util/concat.common.js.map +1 -1
  35. package/dist/browser/util/concat.d.ts +1 -1
  36. package/dist/browser/util/concat.js +1 -1
  37. package/dist/browser/util/concat.js.map +1 -0
  38. package/dist/browser/util/inspect.d.ts +1 -1
  39. package/dist/browser/util/inspect.js +1 -1
  40. package/dist/browser/util/inspect.js.map +1 -0
  41. package/dist/browser/util/sha256.d.ts +1 -1
  42. package/dist/browser/util/sha256.js +1 -1
  43. package/dist/browser/util/sha256.js.map +1 -0
  44. package/dist/browser/util/userAgentPlatform.d.ts +1 -1
  45. package/dist/browser/util/userAgentPlatform.js +1 -1
  46. package/dist/browser/util/userAgentPlatform.js.map +1 -0
  47. package/dist/browser/util/uuidUtils.d.ts +1 -1
  48. package/dist/browser/util/uuidUtils.js +1 -1
  49. package/dist/browser/util/uuidUtils.js.map +1 -0
  50. package/dist/commonjs/abort-controller/AbortError.js +30 -40
  51. package/dist/commonjs/abort-controller/AbortError.js.map +7 -1
  52. package/dist/commonjs/auth/credentials.js +36 -25
  53. package/dist/commonjs/auth/credentials.js.map +7 -1
  54. package/dist/commonjs/auth/oauth2Flows.js +15 -5
  55. package/dist/commonjs/auth/oauth2Flows.js.map +7 -1
  56. package/dist/commonjs/auth/schemes.js +15 -5
  57. package/dist/commonjs/auth/schemes.js.map +7 -1
  58. package/dist/commonjs/client/apiVersionPolicy.js +39 -25
  59. package/dist/commonjs/client/apiVersionPolicy.js.map +7 -1
  60. package/dist/commonjs/client/clientHelpers.js +62 -39
  61. package/dist/commonjs/client/clientHelpers.js.map +7 -1
  62. package/dist/commonjs/client/common.js +15 -5
  63. package/dist/commonjs/client/common.js.map +7 -1
  64. package/dist/commonjs/client/getClient.js +170 -82
  65. package/dist/commonjs/client/getClient.js.map +7 -1
  66. package/dist/commonjs/client/multipart.js +119 -110
  67. package/dist/commonjs/client/multipart.js.map +7 -1
  68. package/dist/commonjs/client/operationOptionHelpers.js +36 -21
  69. package/dist/commonjs/client/operationOptionHelpers.js.map +7 -1
  70. package/dist/commonjs/client/restError.js +44 -26
  71. package/dist/commonjs/client/restError.js.map +7 -1
  72. package/dist/commonjs/client/sendRequest.d.ts +10 -1
  73. package/dist/commonjs/client/sendRequest.js +150 -164
  74. package/dist/commonjs/client/sendRequest.js.map +7 -1
  75. package/dist/commonjs/client/urlHelpers.js +124 -131
  76. package/dist/commonjs/client/urlHelpers.js.map +7 -1
  77. package/dist/commonjs/constants.js +30 -8
  78. package/dist/commonjs/constants.js.map +7 -1
  79. package/dist/commonjs/createPipelineFromOptions.js +56 -45
  80. package/dist/commonjs/createPipelineFromOptions.js.map +7 -1
  81. package/dist/commonjs/defaultHttpClient.js +28 -11
  82. package/dist/commonjs/defaultHttpClient.js.map +7 -1
  83. package/dist/commonjs/fetchHttpClient.js +211 -256
  84. package/dist/commonjs/fetchHttpClient.js.map +7 -1
  85. package/dist/commonjs/httpHeaders.js +97 -82
  86. package/dist/commonjs/httpHeaders.js.map +7 -1
  87. package/dist/commonjs/index.d.ts +2 -2
  88. package/dist/commonjs/index.js +67 -36
  89. package/dist/commonjs/index.js.map +7 -1
  90. package/dist/commonjs/interfaces.js +15 -5
  91. package/dist/commonjs/interfaces.js.map +7 -1
  92. package/dist/commonjs/log.js +28 -8
  93. package/dist/commonjs/log.js.map +7 -1
  94. package/dist/commonjs/logger/debug.js +150 -155
  95. package/dist/commonjs/logger/debug.js.map +7 -1
  96. package/dist/commonjs/logger/internal.js +27 -8
  97. package/dist/commonjs/logger/internal.js.map +7 -1
  98. package/dist/commonjs/logger/log.common.js +39 -23
  99. package/dist/commonjs/logger/log.common.js.map +7 -1
  100. package/dist/commonjs/logger/log.js +40 -11
  101. package/dist/commonjs/logger/log.js.map +7 -1
  102. package/dist/commonjs/logger/logger.js +120 -110
  103. package/dist/commonjs/logger/logger.js.map +7 -1
  104. package/dist/commonjs/nodeHttpClient.js +313 -321
  105. package/dist/commonjs/nodeHttpClient.js.map +7 -1
  106. package/dist/commonjs/pipeline.js +190 -247
  107. package/dist/commonjs/pipeline.js.map +7 -1
  108. package/dist/commonjs/pipelineRequest.d.ts +1 -1
  109. package/dist/commonjs/pipelineRequest.js +69 -54
  110. package/dist/commonjs/pipelineRequest.js.map +7 -1
  111. package/dist/commonjs/policies/agentPolicy.js +38 -24
  112. package/dist/commonjs/policies/agentPolicy.js.map +7 -1
  113. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +45 -32
  114. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +7 -1
  115. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +50 -32
  116. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +7 -1
  117. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +47 -32
  118. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +7 -1
  119. package/dist/commonjs/policies/auth/checkInsecureConnection.js +47 -44
  120. package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +7 -1
  121. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +45 -32
  122. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +7 -1
  123. package/dist/commonjs/policies/decompressResponsePolicy.js +38 -25
  124. package/dist/commonjs/policies/decompressResponsePolicy.js.map +7 -1
  125. package/dist/commonjs/policies/defaultRetryPolicy.js +39 -27
  126. package/dist/commonjs/policies/defaultRetryPolicy.js.map +7 -1
  127. package/dist/commonjs/policies/exponentialRetryPolicy.js +43 -26
  128. package/dist/commonjs/policies/exponentialRetryPolicy.js.map +7 -1
  129. package/dist/commonjs/policies/formDataPolicy.js +101 -90
  130. package/dist/commonjs/policies/formDataPolicy.js.map +7 -1
  131. package/dist/commonjs/policies/internal.d.ts +7 -7
  132. package/dist/commonjs/policies/internal.js +94 -48
  133. package/dist/commonjs/policies/internal.js.map +7 -1
  134. package/dist/commonjs/policies/logPolicy.js +49 -35
  135. package/dist/commonjs/policies/logPolicy.js.map +7 -1
  136. package/dist/commonjs/policies/multipartPolicy.js +117 -99
  137. package/dist/commonjs/policies/multipartPolicy.js.map +7 -1
  138. package/dist/commonjs/policies/proxyPolicy.common.d.ts +7 -3
  139. package/dist/commonjs/policies/proxyPolicy.common.js +38 -25
  140. package/dist/commonjs/policies/proxyPolicy.common.js.map +7 -1
  141. package/dist/commonjs/policies/proxyPolicy.js +160 -171
  142. package/dist/commonjs/policies/proxyPolicy.js.map +7 -1
  143. package/dist/commonjs/policies/redirectPolicy.d.ts +7 -0
  144. package/dist/commonjs/policies/redirectPolicy.js +62 -51
  145. package/dist/commonjs/policies/redirectPolicy.js.map +7 -1
  146. package/dist/commonjs/policies/retryPolicy.js +123 -105
  147. package/dist/commonjs/policies/retryPolicy.js.map +7 -1
  148. package/dist/commonjs/policies/systemErrorRetryPolicy.js +46 -31
  149. package/dist/commonjs/policies/systemErrorRetryPolicy.js.map +7 -1
  150. package/dist/commonjs/policies/throttlingRetryPolicy.js +38 -30
  151. package/dist/commonjs/policies/throttlingRetryPolicy.js.map +7 -1
  152. package/dist/commonjs/policies/tlsPolicy.js +38 -24
  153. package/dist/commonjs/policies/tlsPolicy.js.map +7 -1
  154. package/dist/commonjs/policies/userAgentPolicy.js +41 -28
  155. package/dist/commonjs/policies/userAgentPolicy.js.map +7 -1
  156. package/dist/commonjs/restError.js +93 -90
  157. package/dist/commonjs/restError.js.map +7 -1
  158. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js +63 -62
  159. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js.map +7 -1
  160. package/dist/commonjs/retryStrategies/retryStrategy.js +15 -5
  161. package/dist/commonjs/retryStrategies/retryStrategy.js.map +7 -1
  162. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js +58 -69
  163. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js.map +7 -1
  164. package/dist/commonjs/util/arrayBuffer.js +34 -21
  165. package/dist/commonjs/util/arrayBuffer.js.map +7 -1
  166. package/dist/commonjs/util/bytesEncoding.common.js +83 -100
  167. package/dist/commonjs/util/bytesEncoding.common.js.map +7 -1
  168. package/dist/commonjs/util/bytesEncoding.js +30 -21
  169. package/dist/commonjs/util/bytesEncoding.js.map +7 -1
  170. package/dist/commonjs/util/checkEnvironment.js +45 -44
  171. package/dist/commonjs/util/checkEnvironment.js.map +7 -1
  172. package/dist/commonjs/util/concat.common.d.ts +1 -2
  173. package/dist/commonjs/util/concat.common.js +51 -52
  174. package/dist/commonjs/util/concat.common.js.map +7 -1
  175. package/dist/commonjs/util/concat.js +70 -61
  176. package/dist/commonjs/util/concat.js.map +7 -1
  177. package/dist/commonjs/util/delay.js +31 -21
  178. package/dist/commonjs/util/delay.js.map +7 -1
  179. package/dist/commonjs/util/error.js +33 -17
  180. package/dist/commonjs/util/error.js.map +7 -1
  181. package/dist/commonjs/util/helpers.js +65 -57
  182. package/dist/commonjs/util/helpers.js.map +7 -1
  183. package/dist/commonjs/util/inspect.common.js +27 -7
  184. package/dist/commonjs/util/inspect.common.js.map +7 -1
  185. package/dist/commonjs/util/inspect.js +28 -8
  186. package/dist/commonjs/util/inspect.js.map +7 -1
  187. package/dist/commonjs/util/internal.js +67 -32
  188. package/dist/commonjs/util/internal.js.map +7 -1
  189. package/dist/commonjs/util/object.js +27 -15
  190. package/dist/commonjs/util/object.js.map +7 -1
  191. package/dist/commonjs/util/random.js +30 -22
  192. package/dist/commonjs/util/random.js.map +7 -1
  193. package/dist/commonjs/util/sanitizer.js +157 -148
  194. package/dist/commonjs/util/sanitizer.js.map +7 -1
  195. package/dist/commonjs/util/sha256.common.js +61 -45
  196. package/dist/commonjs/util/sha256.common.js.map +7 -1
  197. package/dist/commonjs/util/sha256.js +32 -22
  198. package/dist/commonjs/util/sha256.js.map +7 -1
  199. package/dist/commonjs/util/typeGuards.js +41 -21
  200. package/dist/commonjs/util/typeGuards.js.map +7 -1
  201. package/dist/commonjs/util/userAgent.js +43 -28
  202. package/dist/commonjs/util/userAgent.js.map +7 -1
  203. package/dist/commonjs/util/userAgentPlatform.js +51 -29
  204. package/dist/commonjs/util/userAgentPlatform.js.map +7 -1
  205. package/dist/commonjs/util/uuidUtils.common.js +43 -39
  206. package/dist/commonjs/util/uuidUtils.common.js.map +7 -1
  207. package/dist/commonjs/util/uuidUtils.js +27 -12
  208. package/dist/commonjs/util/uuidUtils.js.map +7 -1
  209. package/dist/commonjs/xhrHttpClient.js +171 -163
  210. package/dist/commonjs/xhrHttpClient.js.map +7 -1
  211. package/dist/esm/client/sendRequest.d.ts +10 -1
  212. package/dist/esm/client/sendRequest.js +8 -2
  213. package/dist/esm/client/sendRequest.js.map +1 -1
  214. package/dist/esm/index.d.ts +2 -2
  215. package/dist/esm/index.js +0 -2
  216. package/dist/esm/index.js.map +1 -1
  217. package/dist/esm/pipelineRequest.d.ts +1 -1
  218. package/dist/esm/pipelineRequest.js.map +1 -1
  219. package/dist/esm/policies/internal.d.ts +7 -7
  220. package/dist/esm/policies/internal.js +2 -2
  221. package/dist/esm/policies/internal.js.map +1 -1
  222. package/dist/esm/policies/proxyPolicy.common.d.ts +7 -3
  223. package/dist/esm/policies/proxyPolicy.common.js +2 -2
  224. package/dist/esm/policies/proxyPolicy.common.js.map +1 -1
  225. package/dist/esm/policies/redirectPolicy.d.ts +7 -0
  226. package/dist/esm/policies/redirectPolicy.js +13 -4
  227. package/dist/esm/policies/redirectPolicy.js.map +1 -1
  228. package/dist/esm/util/concat.common.d.ts +1 -2
  229. package/dist/esm/util/concat.common.js.map +1 -1
  230. package/dist/react-native/client/sendRequest.d.ts +10 -1
  231. package/dist/react-native/client/sendRequest.js +8 -2
  232. package/dist/react-native/client/sendRequest.js.map +1 -1
  233. package/dist/react-native/defaultHttpClient.d.ts +1 -1
  234. package/dist/react-native/defaultHttpClient.js +1 -1
  235. package/dist/react-native/defaultHttpClient.js.map +1 -0
  236. package/dist/react-native/index.d.ts +2 -2
  237. package/dist/react-native/index.js +0 -2
  238. package/dist/react-native/index.js.map +1 -1
  239. package/dist/react-native/logger/log.d.ts +1 -1
  240. package/dist/react-native/logger/log.js +1 -1
  241. package/dist/react-native/logger/log.js.map +1 -0
  242. package/dist/react-native/pipelineRequest.d.ts +1 -1
  243. package/dist/react-native/pipelineRequest.js.map +1 -1
  244. package/dist/react-native/policies/internal.d.ts +7 -7
  245. package/dist/react-native/policies/internal.js +2 -2
  246. package/dist/react-native/policies/internal.js.map +1 -1
  247. package/dist/react-native/policies/proxyPolicy.common.d.ts +7 -3
  248. package/dist/react-native/policies/proxyPolicy.common.js +2 -2
  249. package/dist/react-native/policies/proxyPolicy.common.js.map +1 -1
  250. package/dist/react-native/policies/proxyPolicy.d.ts +1 -1
  251. package/dist/react-native/policies/proxyPolicy.js +1 -1
  252. package/dist/react-native/policies/proxyPolicy.js.map +1 -0
  253. package/dist/react-native/policies/redirectPolicy.d.ts +7 -0
  254. package/dist/react-native/policies/redirectPolicy.js +13 -4
  255. package/dist/react-native/policies/redirectPolicy.js.map +1 -1
  256. package/dist/react-native/util/bytesEncoding.d.ts +1 -1
  257. package/dist/react-native/util/bytesEncoding.js +1 -1
  258. package/dist/react-native/util/bytesEncoding.js.map +1 -0
  259. package/dist/react-native/util/concat.common.d.ts +1 -2
  260. package/dist/react-native/util/concat.common.js.map +1 -1
  261. package/dist/react-native/util/concat.d.ts +1 -1
  262. package/dist/react-native/util/concat.js +1 -1
  263. package/dist/react-native/util/concat.js.map +1 -0
  264. package/dist/react-native/util/inspect.d.ts +1 -1
  265. package/dist/react-native/util/inspect.js +1 -1
  266. package/dist/react-native/util/inspect.js.map +1 -0
  267. package/dist/react-native/util/sha256.d.ts +1 -1
  268. package/dist/react-native/util/sha256.js +1 -1
  269. package/dist/react-native/util/sha256.js.map +1 -0
  270. package/dist/react-native/util/userAgentPlatform.d.ts +1 -1
  271. package/dist/react-native/util/userAgentPlatform.js +1 -1
  272. package/dist/react-native/util/userAgentPlatform.js.map +1 -0
  273. package/dist/react-native/util/uuidUtils.d.ts +1 -1
  274. package/dist/react-native/util/uuidUtils.js +1 -1
  275. package/dist/react-native/util/uuidUtils.js.map +1 -0
  276. package/package.json +1 -21
  277. package/dist/browser/defaultHttpClient-browser.mjs.map +0 -1
  278. package/dist/browser/logger/log-browser.mjs.map +0 -1
  279. package/dist/browser/policies/decompressResponsePolicy-browser.mjs.map +0 -1
  280. package/dist/browser/policies/proxyPolicy-browser.mjs.map +0 -1
  281. package/dist/browser/util/bytesEncoding-browser.mjs.map +0 -1
  282. package/dist/browser/util/concat-browser.mjs.map +0 -1
  283. package/dist/browser/util/inspect-browser.mjs.map +0 -1
  284. package/dist/browser/util/sha256-browser.mjs.map +0 -1
  285. package/dist/browser/util/userAgentPlatform-browser.mjs.map +0 -1
  286. package/dist/browser/util/uuidUtils-browser.mjs.map +0 -1
  287. package/dist/react-native/defaultHttpClient-react-native.mjs.map +0 -1
  288. package/dist/react-native/logger/log-react-native.mjs.map +0 -1
  289. package/dist/react-native/policies/proxyPolicy-react-native.mjs.map +0 -1
  290. package/dist/react-native/util/bytesEncoding-react-native.mjs.map +0 -1
  291. package/dist/react-native/util/concat-react-native.mjs.map +0 -1
  292. package/dist/react-native/util/inspect-react-native.mjs.map +0 -1
  293. package/dist/react-native/util/sha256-react-native.mjs.map +0 -1
  294. package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +0 -1
  295. package/dist/react-native/util/uuidUtils-react-native.mjs.map +0 -1
@@ -1,352 +1,344 @@
1
- "use strict";
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.getBodyLength = getBodyLength;
6
- exports.createNodeHttpClient = createNodeHttpClient;
7
- const tslib_1 = require("tslib");
8
- const node_http_1 = tslib_1.__importDefault(require("node:http"));
9
- const node_https_1 = tslib_1.__importDefault(require("node:https"));
10
- const node_zlib_1 = tslib_1.__importDefault(require("node:zlib"));
11
- const node_stream_1 = require("node:stream");
12
- const AbortError_js_1 = require("./abort-controller/AbortError.js");
13
- const httpHeaders_js_1 = require("./httpHeaders.js");
14
- const restError_js_1 = require("./restError.js");
15
- const log_js_1 = require("./log.js");
16
- const sanitizer_js_1 = require("./util/sanitizer.js");
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var nodeHttpClient_exports = {};
29
+ __export(nodeHttpClient_exports, {
30
+ createNodeHttpClient: () => createNodeHttpClient,
31
+ getBodyLength: () => getBodyLength
32
+ });
33
+ module.exports = __toCommonJS(nodeHttpClient_exports);
34
+ var import_node_http = __toESM(require("node:http"));
35
+ var import_node_https = __toESM(require("node:https"));
36
+ var import_node_zlib = __toESM(require("node:zlib"));
37
+ var import_node_stream = require("node:stream");
38
+ var import_AbortError = require("./abort-controller/AbortError.js");
39
+ var import_httpHeaders = require("./httpHeaders.js");
40
+ var import_restError = require("./restError.js");
41
+ var import_log = require("./log.js");
42
+ var import_sanitizer = require("./util/sanitizer.js");
17
43
  const DEFAULT_TLS_SETTINGS = {};
18
44
  function isReadableStream(body) {
19
- return body && typeof body.pipe === "function";
45
+ return body && typeof body.pipe === "function";
20
46
  }
21
47
  function isStreamComplete(stream) {
22
- if (stream.readable === false) {
23
- return Promise.resolve();
24
- }
25
- return new Promise((resolve) => {
26
- const handler = () => {
27
- resolve();
28
- stream.removeListener("close", handler);
29
- stream.removeListener("end", handler);
30
- stream.removeListener("error", handler);
31
- };
32
- stream.on("close", handler);
33
- stream.on("end", handler);
34
- stream.on("error", handler);
35
- });
48
+ if (stream.readable === false) {
49
+ return Promise.resolve();
50
+ }
51
+ return new Promise((resolve) => {
52
+ const handler = () => {
53
+ resolve();
54
+ stream.removeListener("close", handler);
55
+ stream.removeListener("end", handler);
56
+ stream.removeListener("error", handler);
57
+ };
58
+ stream.on("close", handler);
59
+ stream.on("end", handler);
60
+ stream.on("error", handler);
61
+ });
36
62
  }
37
63
  function isArrayBuffer(body) {
38
- return body && typeof body.byteLength === "number";
64
+ return body && typeof body.byteLength === "number";
39
65
  }
40
- class ReportTransform extends node_stream_1.Transform {
41
- loadedBytes = 0;
42
- progressCallback;
43
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
44
- _transform(chunk, _encoding, callback) {
45
- this.push(chunk);
46
- this.loadedBytes += chunk.length;
47
- try {
48
- this.progressCallback({ loadedBytes: this.loadedBytes });
49
- callback();
50
- }
51
- catch (e) {
52
- callback(e);
53
- }
54
- }
55
- constructor(progressCallback) {
56
- super();
57
- this.progressCallback = progressCallback;
66
+ class ReportTransform extends import_node_stream.Transform {
67
+ loadedBytes = 0;
68
+ progressCallback;
69
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
70
+ _transform(chunk, _encoding, callback) {
71
+ this.push(chunk);
72
+ this.loadedBytes += chunk.length;
73
+ try {
74
+ this.progressCallback({ loadedBytes: this.loadedBytes });
75
+ callback();
76
+ } catch (e) {
77
+ callback(e);
58
78
  }
79
+ }
80
+ constructor(progressCallback) {
81
+ super();
82
+ this.progressCallback = progressCallback;
83
+ }
59
84
  }
60
- /**
61
- * A HttpClient implementation that uses Node's "https" module to send HTTPS requests.
62
- * @internal
63
- */
64
85
  class NodeHttpClient {
65
- cachedHttpAgent;
66
- cachedHttpsAgents = new WeakMap();
67
- /**
68
- * Makes a request over an underlying transport layer and returns the response.
69
- * @param request - The request to be made.
70
- */
71
- async sendRequest(request) {
72
- const abortController = new AbortController();
73
- let abortListener;
74
- if (request.abortSignal) {
75
- if (request.abortSignal.aborted) {
76
- throw new AbortError_js_1.AbortError("The operation was aborted. Request has already been canceled.");
77
- }
78
- abortListener = (event) => {
79
- if (event.type === "abort") {
80
- abortController.abort();
81
- }
82
- };
83
- request.abortSignal.addEventListener("abort", abortListener);
86
+ cachedHttpAgent;
87
+ cachedHttpsAgents = /* @__PURE__ */ new WeakMap();
88
+ /**
89
+ * Makes a request over an underlying transport layer and returns the response.
90
+ * @param request - The request to be made.
91
+ */
92
+ async sendRequest(request) {
93
+ const abortController = new AbortController();
94
+ let abortListener;
95
+ if (request.abortSignal) {
96
+ if (request.abortSignal.aborted) {
97
+ throw new import_AbortError.AbortError("The operation was aborted. Request has already been canceled.");
98
+ }
99
+ abortListener = (event) => {
100
+ if (event.type === "abort") {
101
+ abortController.abort();
84
102
  }
85
- let timeoutId;
86
- if (request.timeout > 0) {
87
- timeoutId = setTimeout(() => {
88
- const sanitizer = new sanitizer_js_1.Sanitizer();
89
- log_js_1.logger.info(`request to '${sanitizer.sanitizeUrl(request.url)}' timed out. canceling...`);
90
- abortController.abort();
91
- }, request.timeout);
92
- }
93
- const acceptEncoding = request.headers.get("Accept-Encoding");
94
- const shouldDecompress = acceptEncoding?.includes("gzip") || acceptEncoding?.includes("deflate");
95
- let body = typeof request.body === "function" ? request.body() : request.body;
96
- if (body && !request.headers.has("Content-Length")) {
97
- const bodyLength = getBodyLength(body);
98
- if (bodyLength !== null) {
99
- request.headers.set("Content-Length", bodyLength);
100
- }
101
- }
102
- let responseStream;
103
- try {
104
- if (body && request.onUploadProgress) {
105
- const onUploadProgress = request.onUploadProgress;
106
- const uploadReportStream = new ReportTransform(onUploadProgress);
107
- uploadReportStream.on("error", (e) => {
108
- log_js_1.logger.error("Error in upload progress", e);
109
- });
110
- if (isReadableStream(body)) {
111
- body.pipe(uploadReportStream);
112
- }
113
- else {
114
- uploadReportStream.end(body);
115
- }
116
- body = uploadReportStream;
117
- }
118
- const res = await this.makeRequest(request, abortController, body);
119
- if (timeoutId !== undefined) {
120
- clearTimeout(timeoutId);
121
- }
122
- const headers = getResponseHeaders(res);
123
- const status = res.statusCode ?? 0;
124
- const response = {
125
- status,
126
- headers,
127
- request,
128
- };
129
- // Responses to HEAD must not have a body.
130
- // If they do return a body, that body must be ignored.
131
- if (request.method === "HEAD") {
132
- // call resume() and not destroy() to avoid closing the socket
133
- // and losing keep alive
134
- res.resume();
135
- return response;
136
- }
137
- responseStream = shouldDecompress ? getDecodedResponseStream(res, headers) : res;
138
- const onDownloadProgress = request.onDownloadProgress;
139
- if (onDownloadProgress) {
140
- const downloadReportStream = new ReportTransform(onDownloadProgress);
141
- downloadReportStream.on("error", (e) => {
142
- log_js_1.logger.error("Error in download progress", e);
143
- });
144
- responseStream.pipe(downloadReportStream);
145
- responseStream = downloadReportStream;
146
- }
147
- if (
148
- // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code
149
- request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) ||
150
- request.streamResponseStatusCodes?.has(response.status)) {
151
- response.readableStreamBody = responseStream;
152
- }
153
- else {
154
- response.bodyAsText = await streamToText(responseStream);
155
- }
156
- return response;
103
+ };
104
+ request.abortSignal.addEventListener("abort", abortListener);
105
+ }
106
+ let timeoutId;
107
+ if (request.timeout > 0) {
108
+ timeoutId = setTimeout(() => {
109
+ const sanitizer = new import_sanitizer.Sanitizer();
110
+ import_log.logger.info(`request to '${sanitizer.sanitizeUrl(request.url)}' timed out. canceling...`);
111
+ abortController.abort();
112
+ }, request.timeout);
113
+ }
114
+ const acceptEncoding = request.headers.get("Accept-Encoding");
115
+ const shouldDecompress = acceptEncoding?.includes("gzip") || acceptEncoding?.includes("deflate");
116
+ let body = typeof request.body === "function" ? request.body() : request.body;
117
+ if (body && !request.headers.has("Content-Length")) {
118
+ const bodyLength = getBodyLength(body);
119
+ if (bodyLength !== null) {
120
+ request.headers.set("Content-Length", bodyLength);
121
+ }
122
+ }
123
+ let responseStream;
124
+ try {
125
+ if (body && request.onUploadProgress) {
126
+ const onUploadProgress = request.onUploadProgress;
127
+ const uploadReportStream = new ReportTransform(onUploadProgress);
128
+ uploadReportStream.on("error", (e) => {
129
+ import_log.logger.error("Error in upload progress", e);
130
+ });
131
+ if (isReadableStream(body)) {
132
+ body.pipe(uploadReportStream);
133
+ } else {
134
+ uploadReportStream.end(body);
157
135
  }
158
- finally {
159
- // clean up event listener
160
- if (request.abortSignal && abortListener) {
161
- let uploadStreamDone = Promise.resolve();
162
- if (isReadableStream(body)) {
163
- uploadStreamDone = isStreamComplete(body);
164
- }
165
- let downloadStreamDone = Promise.resolve();
166
- if (isReadableStream(responseStream)) {
167
- downloadStreamDone = isStreamComplete(responseStream);
168
- }
169
- Promise.all([uploadStreamDone, downloadStreamDone])
170
- .then(() => {
171
- // eslint-disable-next-line promise/always-return
172
- if (abortListener) {
173
- request.abortSignal?.removeEventListener("abort", abortListener);
174
- }
175
- })
176
- .catch((e) => {
177
- log_js_1.logger.warning("Error when cleaning up abortListener on httpRequest", e);
178
- });
179
- }
136
+ body = uploadReportStream;
137
+ }
138
+ const res = await this.makeRequest(request, abortController, body);
139
+ if (timeoutId !== void 0) {
140
+ clearTimeout(timeoutId);
141
+ }
142
+ const headers = getResponseHeaders(res);
143
+ const status = res.statusCode ?? 0;
144
+ const response = {
145
+ status,
146
+ headers,
147
+ request
148
+ };
149
+ if (request.method === "HEAD") {
150
+ res.resume();
151
+ return response;
152
+ }
153
+ responseStream = shouldDecompress ? getDecodedResponseStream(res, headers) : res;
154
+ const onDownloadProgress = request.onDownloadProgress;
155
+ if (onDownloadProgress) {
156
+ const downloadReportStream = new ReportTransform(onDownloadProgress);
157
+ downloadReportStream.on("error", (e) => {
158
+ import_log.logger.error("Error in download progress", e);
159
+ });
160
+ responseStream.pipe(downloadReportStream);
161
+ responseStream = downloadReportStream;
162
+ }
163
+ if (
164
+ // Value of POSITIVE_INFINITY in streamResponseStatusCodes is considered as any status code
165
+ request.streamResponseStatusCodes?.has(Number.POSITIVE_INFINITY) || request.streamResponseStatusCodes?.has(response.status)
166
+ ) {
167
+ response.readableStreamBody = responseStream;
168
+ } else {
169
+ response.bodyAsText = await streamToText(responseStream);
170
+ }
171
+ return response;
172
+ } finally {
173
+ if (request.abortSignal && abortListener) {
174
+ let uploadStreamDone = Promise.resolve();
175
+ if (isReadableStream(body)) {
176
+ uploadStreamDone = isStreamComplete(body);
180
177
  }
181
- }
182
- makeRequest(request, abortController, body) {
183
- const url = new URL(request.url);
184
- const isInsecure = url.protocol !== "https:";
185
- if (isInsecure && !request.allowInsecureConnection) {
186
- throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);
178
+ let downloadStreamDone = Promise.resolve();
179
+ if (isReadableStream(responseStream)) {
180
+ downloadStreamDone = isStreamComplete(responseStream);
187
181
  }
188
- const agent = request.agent ?? this.getOrCreateAgent(request, isInsecure);
189
- const options = {
190
- agent,
191
- hostname: url.hostname,
192
- path: `${url.pathname}${url.search}`,
193
- port: url.port,
194
- method: request.method,
195
- headers: request.headers.toJSON({ preserveCase: true }),
196
- ...request.requestOverrides,
197
- };
198
- return new Promise((resolve, reject) => {
199
- const req = isInsecure ? node_http_1.default.request(options, resolve) : node_https_1.default.request(options, resolve);
200
- req.once("error", (err) => {
201
- reject(new restError_js_1.RestError(err.message, { code: err.code ?? restError_js_1.RestError.REQUEST_SEND_ERROR, request }));
202
- });
203
- abortController.signal.addEventListener("abort", () => {
204
- const abortError = new AbortError_js_1.AbortError("The operation was aborted. Rejecting from abort signal callback while making request.");
205
- req.destroy(abortError);
206
- reject(abortError);
207
- });
208
- if (body && isReadableStream(body)) {
209
- body.pipe(req);
210
- }
211
- else if (body) {
212
- if (typeof body === "string" || Buffer.isBuffer(body)) {
213
- req.end(body);
214
- }
215
- else if (isArrayBuffer(body)) {
216
- req.end(ArrayBuffer.isView(body) ? Buffer.from(body.buffer) : Buffer.from(body));
217
- }
218
- else {
219
- log_js_1.logger.error("Unrecognized body type", body);
220
- reject(new restError_js_1.RestError("Unrecognized body type"));
221
- }
222
- }
223
- else {
224
- // streams don't like "undefined" being passed as data
225
- req.end();
226
- }
182
+ Promise.all([uploadStreamDone, downloadStreamDone]).then(() => {
183
+ if (abortListener) {
184
+ request.abortSignal?.removeEventListener("abort", abortListener);
185
+ }
186
+ }).catch((e) => {
187
+ import_log.logger.warning("Error when cleaning up abortListener on httpRequest", e);
227
188
  });
189
+ }
228
190
  }
229
- getOrCreateAgent(request, isInsecure) {
230
- const disableKeepAlive = request.disableKeepAlive;
231
- // Handle Insecure requests first
232
- if (isInsecure) {
233
- if (disableKeepAlive) {
234
- // keepAlive:false is the default so we don't need a custom Agent
235
- return node_http_1.default.globalAgent;
236
- }
237
- if (!this.cachedHttpAgent) {
238
- // If there is no cached agent create a new one and cache it.
239
- this.cachedHttpAgent = new node_http_1.default.Agent({ keepAlive: true });
240
- }
241
- return this.cachedHttpAgent;
242
- }
243
- else {
244
- if (disableKeepAlive && !request.tlsSettings) {
245
- // When there are no tlsSettings and keepAlive is false
246
- // we don't need a custom agent
247
- return node_https_1.default.globalAgent;
248
- }
249
- // We use the tlsSettings to index cached clients
250
- const tlsSettings = request.tlsSettings ?? DEFAULT_TLS_SETTINGS;
251
- // Get the cached agent or create a new one with the
252
- // provided values for keepAlive and tlsSettings
253
- let agent = this.cachedHttpsAgents.get(tlsSettings);
254
- if (agent && agent.options.keepAlive === !disableKeepAlive) {
255
- return agent;
256
- }
257
- log_js_1.logger.info("No cached TLS Agent exist, creating a new Agent");
258
- agent = new node_https_1.default.Agent({
259
- // keepAlive is true if disableKeepAlive is false.
260
- keepAlive: !disableKeepAlive,
261
- // Since we are spreading, if no tslSettings were provided, nothing is added to the agent options.
262
- ...tlsSettings,
263
- });
264
- this.cachedHttpsAgents.set(tlsSettings, agent);
265
- return agent;
191
+ }
192
+ makeRequest(request, abortController, body) {
193
+ const url = new URL(request.url);
194
+ const isInsecure = url.protocol !== "https:";
195
+ if (isInsecure && !request.allowInsecureConnection) {
196
+ throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`);
197
+ }
198
+ const agent = request.agent ?? this.getOrCreateAgent(request, isInsecure);
199
+ const options = {
200
+ agent,
201
+ hostname: url.hostname,
202
+ path: `${url.pathname}${url.search}`,
203
+ port: url.port,
204
+ method: request.method,
205
+ headers: request.headers.toJSON({ preserveCase: true }),
206
+ ...request.requestOverrides
207
+ };
208
+ return new Promise((resolve, reject) => {
209
+ const req = isInsecure ? import_node_http.default.request(options, resolve) : import_node_https.default.request(options, resolve);
210
+ req.once("error", (err) => {
211
+ reject(
212
+ new import_restError.RestError(err.message, { code: err.code ?? import_restError.RestError.REQUEST_SEND_ERROR, request })
213
+ );
214
+ });
215
+ abortController.signal.addEventListener("abort", () => {
216
+ const abortError = new import_AbortError.AbortError(
217
+ "The operation was aborted. Rejecting from abort signal callback while making request."
218
+ );
219
+ req.destroy(abortError);
220
+ reject(abortError);
221
+ });
222
+ if (body && isReadableStream(body)) {
223
+ body.pipe(req);
224
+ } else if (body) {
225
+ if (typeof body === "string" || Buffer.isBuffer(body)) {
226
+ req.end(body);
227
+ } else if (isArrayBuffer(body)) {
228
+ req.end(ArrayBuffer.isView(body) ? Buffer.from(body.buffer) : Buffer.from(body));
229
+ } else {
230
+ import_log.logger.error("Unrecognized body type", body);
231
+ reject(new import_restError.RestError("Unrecognized body type"));
266
232
  }
233
+ } else {
234
+ req.end();
235
+ }
236
+ });
237
+ }
238
+ getOrCreateAgent(request, isInsecure) {
239
+ const disableKeepAlive = request.disableKeepAlive;
240
+ if (isInsecure) {
241
+ if (disableKeepAlive) {
242
+ return import_node_http.default.globalAgent;
243
+ }
244
+ if (!this.cachedHttpAgent) {
245
+ this.cachedHttpAgent = new import_node_http.default.Agent({ keepAlive: true });
246
+ }
247
+ return this.cachedHttpAgent;
248
+ } else {
249
+ if (disableKeepAlive && !request.tlsSettings) {
250
+ return import_node_https.default.globalAgent;
251
+ }
252
+ const tlsSettings = request.tlsSettings ?? DEFAULT_TLS_SETTINGS;
253
+ let agent = this.cachedHttpsAgents.get(tlsSettings);
254
+ if (agent && agent.options.keepAlive === !disableKeepAlive) {
255
+ return agent;
256
+ }
257
+ import_log.logger.info("No cached TLS Agent exist, creating a new Agent");
258
+ agent = new import_node_https.default.Agent({
259
+ // keepAlive is true if disableKeepAlive is false.
260
+ keepAlive: !disableKeepAlive,
261
+ // Since we are spreading, if no tslSettings were provided, nothing is added to the agent options.
262
+ ...tlsSettings
263
+ });
264
+ this.cachedHttpsAgents.set(tlsSettings, agent);
265
+ return agent;
267
266
  }
267
+ }
268
268
  }
269
269
  function getResponseHeaders(res) {
270
- const headers = (0, httpHeaders_js_1.createHttpHeaders)();
271
- for (const header of Object.keys(res.headers)) {
272
- const value = res.headers[header];
273
- if (Array.isArray(value)) {
274
- if (value.length > 0) {
275
- headers.set(header, value[0]);
276
- }
277
- }
278
- else if (value) {
279
- headers.set(header, value);
280
- }
270
+ const headers = (0, import_httpHeaders.createHttpHeaders)();
271
+ for (const header of Object.keys(res.headers)) {
272
+ const value = res.headers[header];
273
+ if (Array.isArray(value)) {
274
+ if (value.length > 0) {
275
+ headers.set(header, value[0]);
276
+ }
277
+ } else if (value) {
278
+ headers.set(header, value);
281
279
  }
282
- return headers;
280
+ }
281
+ return headers;
283
282
  }
284
283
  function getDecodedResponseStream(stream, headers) {
285
- const contentEncoding = headers.get("Content-Encoding");
286
- if (contentEncoding === "gzip") {
287
- const unzip = node_zlib_1.default.createGunzip();
288
- stream.pipe(unzip);
289
- return unzip;
290
- }
291
- else if (contentEncoding === "deflate") {
292
- const inflate = node_zlib_1.default.createInflate();
293
- stream.pipe(inflate);
294
- return inflate;
295
- }
296
- return stream;
284
+ const contentEncoding = headers.get("Content-Encoding");
285
+ if (contentEncoding === "gzip") {
286
+ const unzip = import_node_zlib.default.createGunzip();
287
+ stream.pipe(unzip);
288
+ return unzip;
289
+ } else if (contentEncoding === "deflate") {
290
+ const inflate = import_node_zlib.default.createInflate();
291
+ stream.pipe(inflate);
292
+ return inflate;
293
+ }
294
+ return stream;
297
295
  }
298
296
  function streamToText(stream) {
299
- return new Promise((resolve, reject) => {
300
- const buffer = [];
301
- stream.on("data", (chunk) => {
302
- if (Buffer.isBuffer(chunk)) {
303
- buffer.push(chunk);
304
- }
305
- else {
306
- buffer.push(Buffer.from(chunk));
307
- }
308
- });
309
- stream.on("end", () => {
310
- resolve(Buffer.concat(buffer).toString("utf8"));
311
- });
312
- stream.on("error", (e) => {
313
- if (e && e?.name === "AbortError") {
314
- reject(e);
315
- }
316
- else {
317
- reject(new restError_js_1.RestError(`Error reading response as text: ${e.message}`, {
318
- code: restError_js_1.RestError.PARSE_ERROR,
319
- }));
320
- }
321
- });
297
+ return new Promise((resolve, reject) => {
298
+ const buffer = [];
299
+ stream.on("data", (chunk) => {
300
+ if (Buffer.isBuffer(chunk)) {
301
+ buffer.push(chunk);
302
+ } else {
303
+ buffer.push(Buffer.from(chunk));
304
+ }
322
305
  });
306
+ stream.on("end", () => {
307
+ resolve(Buffer.concat(buffer).toString("utf8"));
308
+ });
309
+ stream.on("error", (e) => {
310
+ if (e && e?.name === "AbortError") {
311
+ reject(e);
312
+ } else {
313
+ reject(
314
+ new import_restError.RestError(`Error reading response as text: ${e.message}`, {
315
+ code: import_restError.RestError.PARSE_ERROR
316
+ })
317
+ );
318
+ }
319
+ });
320
+ });
323
321
  }
324
- /** @internal */
325
322
  function getBodyLength(body) {
326
- if (!body) {
327
- return 0;
328
- }
329
- else if (Buffer.isBuffer(body)) {
330
- return body.length;
331
- }
332
- else if (isReadableStream(body)) {
333
- return null;
334
- }
335
- else if (isArrayBuffer(body)) {
336
- return body.byteLength;
337
- }
338
- else if (typeof body === "string") {
339
- return Buffer.from(body).length;
340
- }
341
- else {
342
- return null;
343
- }
323
+ if (!body) {
324
+ return 0;
325
+ } else if (Buffer.isBuffer(body)) {
326
+ return body.length;
327
+ } else if (isReadableStream(body)) {
328
+ return null;
329
+ } else if (isArrayBuffer(body)) {
330
+ return body.byteLength;
331
+ } else if (typeof body === "string") {
332
+ return Buffer.from(body).length;
333
+ } else {
334
+ return null;
335
+ }
344
336
  }
345
- /**
346
- * Create a new HttpClient instance for the NodeJS environment.
347
- * @internal
348
- */
349
337
  function createNodeHttpClient() {
350
- return new NodeHttpClient();
338
+ return new NodeHttpClient();
351
339
  }
352
- //# sourceMappingURL=nodeHttpClient.js.map
340
+ // Annotate the CommonJS export names for ESM import in node:
341
+ 0 && (module.exports = {
342
+ createNodeHttpClient,
343
+ getBodyLength
344
+ });