@typespec/ts-http-runtime 1.0.0-alpha.20240328.4 → 1.0.0-alpha.20240329.3

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 (303) hide show
  1. package/dist/browser/accessTokenCache.js +0 -2
  2. package/dist/browser/accessTokenCache.js.map +1 -1
  3. package/dist/browser/client/clientHelpers.js +4 -3
  4. package/dist/browser/client/clientHelpers.js.map +1 -1
  5. package/dist/browser/client/getClient.js +9 -7
  6. package/dist/browser/client/getClient.js.map +1 -1
  7. package/dist/browser/client/operationOptionHelpers.js +7 -6
  8. package/dist/browser/client/operationOptionHelpers.js.map +1 -1
  9. package/dist/browser/client/restError.js +4 -2
  10. package/dist/browser/client/restError.js.map +1 -1
  11. package/dist/browser/client/sendRequest.js +18 -19
  12. package/dist/browser/client/sendRequest.js.map +1 -1
  13. package/dist/browser/client/urlHelpers.js +2 -1
  14. package/dist/browser/client/urlHelpers.js.map +1 -1
  15. package/dist/browser/fetchHttpClient.js +20 -26
  16. package/dist/browser/fetchHttpClient.js.map +1 -1
  17. package/dist/browser/httpHeaders.js +2 -2
  18. package/dist/browser/httpHeaders.js.map +1 -1
  19. package/dist/browser/nodeHttpClient.js +20 -18
  20. package/dist/browser/nodeHttpClient.js.map +1 -1
  21. package/dist/browser/pipeline.js +3 -3
  22. package/dist/browser/pipeline.js.map +1 -1
  23. package/dist/browser/pipelineRequest.js +8 -25
  24. package/dist/browser/pipelineRequest.js.map +1 -1
  25. package/dist/browser/policies/bearerTokenAuthenticationPolicy.js +3 -7
  26. package/dist/browser/policies/bearerTokenAuthenticationPolicy.js.map +1 -1
  27. package/dist/browser/policies/defaultRetryPolicy.js +2 -1
  28. package/dist/browser/policies/defaultRetryPolicy.js.map +1 -1
  29. package/dist/browser/policies/exponentialRetryPolicy.js +3 -5
  30. package/dist/browser/policies/exponentialRetryPolicy.js.map +1 -1
  31. package/dist/browser/policies/formDataPolicy.js +1 -1
  32. package/dist/browser/policies/formDataPolicy.js.map +1 -1
  33. package/dist/browser/policies/logPolicy.js +2 -1
  34. package/dist/browser/policies/logPolicy.js.map +1 -1
  35. package/dist/browser/policies/multipartPolicy.js +3 -2
  36. package/dist/browser/policies/multipartPolicy.js.map +1 -1
  37. package/dist/browser/policies/retryPolicy.js +3 -2
  38. package/dist/browser/policies/retryPolicy.js.map +1 -1
  39. package/dist/browser/policies/systemErrorRetryPolicy.js +3 -5
  40. package/dist/browser/policies/systemErrorRetryPolicy.js.map +1 -1
  41. package/dist/browser/policies/throttlingRetryPolicy.js +2 -1
  42. package/dist/browser/policies/throttlingRetryPolicy.js.map +1 -1
  43. package/dist/browser/policies/tracingPolicy.js +3 -2
  44. package/dist/browser/policies/tracingPolicy.js.map +1 -1
  45. package/dist/browser/restError.js +11 -31
  46. package/dist/browser/restError.js.map +1 -1
  47. package/dist/browser/retryStrategies/exponentialRetryStrategy.js +3 -2
  48. package/dist/browser/retryStrategies/exponentialRetryStrategy.js.map +1 -1
  49. package/dist/browser/tracing/tracingClient.js +3 -7
  50. package/dist/browser/tracing/tracingClient.js.map +1 -1
  51. package/dist/browser/tracing/tracingContext.js +0 -1
  52. package/dist/browser/tracing/tracingContext.js.map +1 -1
  53. package/dist/browser/util/aborterUtils.js +3 -2
  54. package/dist/browser/util/aborterUtils.js.map +1 -1
  55. package/dist/browser/util/checkEnvironment.js +7 -6
  56. package/dist/browser/util/checkEnvironment.js.map +1 -1
  57. package/dist/browser/util/createAbortablePromise.js +6 -6
  58. package/dist/browser/util/createAbortablePromise.js.map +1 -1
  59. package/dist/browser/util/delay.js +2 -2
  60. package/dist/browser/util/delay.js.map +1 -1
  61. package/dist/browser/util/file.js +5 -22
  62. package/dist/browser/util/file.js.map +1 -1
  63. package/dist/browser/util/helpers.js +4 -4
  64. package/dist/browser/util/helpers.js.map +1 -1
  65. package/dist/browser/util/sanitizer.js +1 -7
  66. package/dist/browser/util/sanitizer.js.map +1 -1
  67. package/dist/browser/util/tokenCycler.js +6 -7
  68. package/dist/browser/util/tokenCycler.js.map +1 -1
  69. package/dist/browser/util/userAgentPlatform-browser.mjs.map +1 -1
  70. package/dist/browser/util/userAgentPlatform.js +2 -1
  71. package/dist/browser/util/uuidUtils-browser.mjs.map +1 -1
  72. package/dist/browser/util/uuidUtils.js +2 -1
  73. package/dist/browser/xhrHttpClient.js +5 -3
  74. package/dist/browser/xhrHttpClient.js.map +1 -1
  75. package/dist/commonjs/accessTokenCache.js +0 -2
  76. package/dist/commonjs/accessTokenCache.js.map +1 -1
  77. package/dist/commonjs/client/clientHelpers.js +4 -3
  78. package/dist/commonjs/client/clientHelpers.js.map +1 -1
  79. package/dist/commonjs/client/getClient.js +9 -7
  80. package/dist/commonjs/client/getClient.js.map +1 -1
  81. package/dist/commonjs/client/operationOptionHelpers.js +7 -6
  82. package/dist/commonjs/client/operationOptionHelpers.js.map +1 -1
  83. package/dist/commonjs/client/restError.js +4 -2
  84. package/dist/commonjs/client/restError.js.map +1 -1
  85. package/dist/commonjs/client/sendRequest.js +18 -19
  86. package/dist/commonjs/client/sendRequest.js.map +1 -1
  87. package/dist/commonjs/client/urlHelpers.js +2 -1
  88. package/dist/commonjs/client/urlHelpers.js.map +1 -1
  89. package/dist/commonjs/fetchHttpClient.js +20 -26
  90. package/dist/commonjs/fetchHttpClient.js.map +1 -1
  91. package/dist/commonjs/httpHeaders.js +2 -2
  92. package/dist/commonjs/httpHeaders.js.map +1 -1
  93. package/dist/commonjs/nodeHttpClient.js +20 -18
  94. package/dist/commonjs/nodeHttpClient.js.map +1 -1
  95. package/dist/commonjs/pipeline.js +3 -3
  96. package/dist/commonjs/pipeline.js.map +1 -1
  97. package/dist/commonjs/pipelineRequest.js +8 -25
  98. package/dist/commonjs/pipelineRequest.js.map +1 -1
  99. package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js +3 -7
  100. package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js.map +1 -1
  101. package/dist/commonjs/policies/defaultRetryPolicy.js +2 -1
  102. package/dist/commonjs/policies/defaultRetryPolicy.js.map +1 -1
  103. package/dist/commonjs/policies/exponentialRetryPolicy.js +3 -5
  104. package/dist/commonjs/policies/exponentialRetryPolicy.js.map +1 -1
  105. package/dist/commonjs/policies/formDataPolicy.js +1 -1
  106. package/dist/commonjs/policies/formDataPolicy.js.map +1 -1
  107. package/dist/commonjs/policies/logPolicy.js +2 -1
  108. package/dist/commonjs/policies/logPolicy.js.map +1 -1
  109. package/dist/commonjs/policies/multipartPolicy.js +3 -2
  110. package/dist/commonjs/policies/multipartPolicy.js.map +1 -1
  111. package/dist/commonjs/policies/proxyPolicy.js +4 -3
  112. package/dist/commonjs/policies/proxyPolicy.js.map +1 -1
  113. package/dist/commonjs/policies/retryPolicy.js +3 -2
  114. package/dist/commonjs/policies/retryPolicy.js.map +1 -1
  115. package/dist/commonjs/policies/systemErrorRetryPolicy.js +3 -5
  116. package/dist/commonjs/policies/systemErrorRetryPolicy.js.map +1 -1
  117. package/dist/commonjs/policies/throttlingRetryPolicy.js +2 -1
  118. package/dist/commonjs/policies/throttlingRetryPolicy.js.map +1 -1
  119. package/dist/commonjs/policies/tracingPolicy.js +3 -2
  120. package/dist/commonjs/policies/tracingPolicy.js.map +1 -1
  121. package/dist/commonjs/restError.js +11 -31
  122. package/dist/commonjs/restError.js.map +1 -1
  123. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js +3 -2
  124. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js.map +1 -1
  125. package/dist/commonjs/tracing/tracingClient.js +3 -7
  126. package/dist/commonjs/tracing/tracingClient.js.map +1 -1
  127. package/dist/commonjs/tracing/tracingContext.js +0 -1
  128. package/dist/commonjs/tracing/tracingContext.js.map +1 -1
  129. package/dist/commonjs/util/aborterUtils.js +3 -2
  130. package/dist/commonjs/util/aborterUtils.js.map +1 -1
  131. package/dist/commonjs/util/checkEnvironment.js +7 -6
  132. package/dist/commonjs/util/checkEnvironment.js.map +1 -1
  133. package/dist/commonjs/util/concat.js +35 -17
  134. package/dist/commonjs/util/concat.js.map +1 -1
  135. package/dist/commonjs/util/createAbortablePromise.js +6 -6
  136. package/dist/commonjs/util/createAbortablePromise.js.map +1 -1
  137. package/dist/commonjs/util/delay.js +2 -2
  138. package/dist/commonjs/util/delay.js.map +1 -1
  139. package/dist/commonjs/util/file.js +5 -22
  140. package/dist/commonjs/util/file.js.map +1 -1
  141. package/dist/commonjs/util/helpers.js +4 -4
  142. package/dist/commonjs/util/helpers.js.map +1 -1
  143. package/dist/commonjs/util/sanitizer.js +1 -7
  144. package/dist/commonjs/util/sanitizer.js.map +1 -1
  145. package/dist/commonjs/util/tokenCycler.js +6 -7
  146. package/dist/commonjs/util/tokenCycler.js.map +1 -1
  147. package/dist/commonjs/util/uuidUtils.js +2 -1
  148. package/dist/commonjs/util/uuidUtils.js.map +1 -1
  149. package/dist/commonjs/xhrHttpClient.js +5 -3
  150. package/dist/commonjs/xhrHttpClient.js.map +1 -1
  151. package/dist/esm/accessTokenCache.js +0 -2
  152. package/dist/esm/accessTokenCache.js.map +1 -1
  153. package/dist/esm/client/clientHelpers.js +4 -3
  154. package/dist/esm/client/clientHelpers.js.map +1 -1
  155. package/dist/esm/client/getClient.js +9 -7
  156. package/dist/esm/client/getClient.js.map +1 -1
  157. package/dist/esm/client/operationOptionHelpers.js +7 -6
  158. package/dist/esm/client/operationOptionHelpers.js.map +1 -1
  159. package/dist/esm/client/restError.js +4 -2
  160. package/dist/esm/client/restError.js.map +1 -1
  161. package/dist/esm/client/sendRequest.js +18 -19
  162. package/dist/esm/client/sendRequest.js.map +1 -1
  163. package/dist/esm/client/urlHelpers.js +2 -1
  164. package/dist/esm/client/urlHelpers.js.map +1 -1
  165. package/dist/esm/fetchHttpClient.js +20 -26
  166. package/dist/esm/fetchHttpClient.js.map +1 -1
  167. package/dist/esm/httpHeaders.js +2 -2
  168. package/dist/esm/httpHeaders.js.map +1 -1
  169. package/dist/esm/nodeHttpClient.js +20 -18
  170. package/dist/esm/nodeHttpClient.js.map +1 -1
  171. package/dist/esm/pipeline.js +3 -3
  172. package/dist/esm/pipeline.js.map +1 -1
  173. package/dist/esm/pipelineRequest.js +8 -25
  174. package/dist/esm/pipelineRequest.js.map +1 -1
  175. package/dist/esm/policies/bearerTokenAuthenticationPolicy.js +3 -7
  176. package/dist/esm/policies/bearerTokenAuthenticationPolicy.js.map +1 -1
  177. package/dist/esm/policies/defaultRetryPolicy.js +2 -1
  178. package/dist/esm/policies/defaultRetryPolicy.js.map +1 -1
  179. package/dist/esm/policies/exponentialRetryPolicy.js +3 -5
  180. package/dist/esm/policies/exponentialRetryPolicy.js.map +1 -1
  181. package/dist/esm/policies/formDataPolicy.js +1 -1
  182. package/dist/esm/policies/formDataPolicy.js.map +1 -1
  183. package/dist/esm/policies/logPolicy.js +2 -1
  184. package/dist/esm/policies/logPolicy.js.map +1 -1
  185. package/dist/esm/policies/multipartPolicy.js +3 -2
  186. package/dist/esm/policies/multipartPolicy.js.map +1 -1
  187. package/dist/esm/policies/proxyPolicy.js +4 -3
  188. package/dist/esm/policies/proxyPolicy.js.map +1 -1
  189. package/dist/esm/policies/retryPolicy.js +3 -2
  190. package/dist/esm/policies/retryPolicy.js.map +1 -1
  191. package/dist/esm/policies/systemErrorRetryPolicy.js +3 -5
  192. package/dist/esm/policies/systemErrorRetryPolicy.js.map +1 -1
  193. package/dist/esm/policies/throttlingRetryPolicy.js +2 -1
  194. package/dist/esm/policies/throttlingRetryPolicy.js.map +1 -1
  195. package/dist/esm/policies/tracingPolicy.js +3 -2
  196. package/dist/esm/policies/tracingPolicy.js.map +1 -1
  197. package/dist/esm/restError.js +11 -31
  198. package/dist/esm/restError.js.map +1 -1
  199. package/dist/esm/retryStrategies/exponentialRetryStrategy.js +3 -2
  200. package/dist/esm/retryStrategies/exponentialRetryStrategy.js.map +1 -1
  201. package/dist/esm/tracing/tracingClient.js +3 -7
  202. package/dist/esm/tracing/tracingClient.js.map +1 -1
  203. package/dist/esm/tracing/tracingContext.js +0 -1
  204. package/dist/esm/tracing/tracingContext.js.map +1 -1
  205. package/dist/esm/util/aborterUtils.js +3 -2
  206. package/dist/esm/util/aborterUtils.js.map +1 -1
  207. package/dist/esm/util/checkEnvironment.js +7 -6
  208. package/dist/esm/util/checkEnvironment.js.map +1 -1
  209. package/dist/esm/util/concat.js +35 -17
  210. package/dist/esm/util/concat.js.map +1 -1
  211. package/dist/esm/util/createAbortablePromise.js +6 -6
  212. package/dist/esm/util/createAbortablePromise.js.map +1 -1
  213. package/dist/esm/util/delay.js +2 -2
  214. package/dist/esm/util/delay.js.map +1 -1
  215. package/dist/esm/util/file.js +5 -22
  216. package/dist/esm/util/file.js.map +1 -1
  217. package/dist/esm/util/helpers.js +4 -4
  218. package/dist/esm/util/helpers.js.map +1 -1
  219. package/dist/esm/util/sanitizer.js +1 -7
  220. package/dist/esm/util/sanitizer.js.map +1 -1
  221. package/dist/esm/util/tokenCycler.js +6 -7
  222. package/dist/esm/util/tokenCycler.js.map +1 -1
  223. package/dist/esm/util/uuidUtils.js +2 -1
  224. package/dist/esm/util/uuidUtils.js.map +1 -1
  225. package/dist/esm/xhrHttpClient.js +5 -3
  226. package/dist/esm/xhrHttpClient.js.map +1 -1
  227. package/dist/react-native/accessTokenCache.js +0 -2
  228. package/dist/react-native/accessTokenCache.js.map +1 -1
  229. package/dist/react-native/client/clientHelpers.js +4 -3
  230. package/dist/react-native/client/clientHelpers.js.map +1 -1
  231. package/dist/react-native/client/getClient.js +9 -7
  232. package/dist/react-native/client/getClient.js.map +1 -1
  233. package/dist/react-native/client/operationOptionHelpers.js +7 -6
  234. package/dist/react-native/client/operationOptionHelpers.js.map +1 -1
  235. package/dist/react-native/client/restError.js +4 -2
  236. package/dist/react-native/client/restError.js.map +1 -1
  237. package/dist/react-native/client/sendRequest.js +18 -19
  238. package/dist/react-native/client/sendRequest.js.map +1 -1
  239. package/dist/react-native/client/urlHelpers.js +2 -1
  240. package/dist/react-native/client/urlHelpers.js.map +1 -1
  241. package/dist/react-native/fetchHttpClient.js +20 -26
  242. package/dist/react-native/fetchHttpClient.js.map +1 -1
  243. package/dist/react-native/httpHeaders.js +2 -2
  244. package/dist/react-native/httpHeaders.js.map +1 -1
  245. package/dist/react-native/nodeHttpClient.js +20 -18
  246. package/dist/react-native/nodeHttpClient.js.map +1 -1
  247. package/dist/react-native/pipeline.js +3 -3
  248. package/dist/react-native/pipeline.js.map +1 -1
  249. package/dist/react-native/pipelineRequest.js +8 -25
  250. package/dist/react-native/pipelineRequest.js.map +1 -1
  251. package/dist/react-native/policies/bearerTokenAuthenticationPolicy.js +3 -7
  252. package/dist/react-native/policies/bearerTokenAuthenticationPolicy.js.map +1 -1
  253. package/dist/react-native/policies/defaultRetryPolicy.js +2 -1
  254. package/dist/react-native/policies/defaultRetryPolicy.js.map +1 -1
  255. package/dist/react-native/policies/exponentialRetryPolicy.js +3 -5
  256. package/dist/react-native/policies/exponentialRetryPolicy.js.map +1 -1
  257. package/dist/react-native/policies/formDataPolicy.js +1 -1
  258. package/dist/react-native/policies/formDataPolicy.js.map +1 -1
  259. package/dist/react-native/policies/logPolicy.js +2 -1
  260. package/dist/react-native/policies/logPolicy.js.map +1 -1
  261. package/dist/react-native/policies/multipartPolicy.js +3 -2
  262. package/dist/react-native/policies/multipartPolicy.js.map +1 -1
  263. package/dist/react-native/policies/proxyPolicy.js +4 -3
  264. package/dist/react-native/policies/proxyPolicy.js.map +1 -1
  265. package/dist/react-native/policies/retryPolicy.js +3 -2
  266. package/dist/react-native/policies/retryPolicy.js.map +1 -1
  267. package/dist/react-native/policies/systemErrorRetryPolicy.js +3 -5
  268. package/dist/react-native/policies/systemErrorRetryPolicy.js.map +1 -1
  269. package/dist/react-native/policies/throttlingRetryPolicy.js +2 -1
  270. package/dist/react-native/policies/throttlingRetryPolicy.js.map +1 -1
  271. package/dist/react-native/policies/tracingPolicy.js +3 -2
  272. package/dist/react-native/policies/tracingPolicy.js.map +1 -1
  273. package/dist/react-native/restError.js +11 -31
  274. package/dist/react-native/restError.js.map +1 -1
  275. package/dist/react-native/retryStrategies/exponentialRetryStrategy.js +3 -2
  276. package/dist/react-native/retryStrategies/exponentialRetryStrategy.js.map +1 -1
  277. package/dist/react-native/tracing/tracingClient.js +3 -7
  278. package/dist/react-native/tracing/tracingClient.js.map +1 -1
  279. package/dist/react-native/tracing/tracingContext.js +0 -1
  280. package/dist/react-native/tracing/tracingContext.js.map +1 -1
  281. package/dist/react-native/util/aborterUtils.js +3 -2
  282. package/dist/react-native/util/aborterUtils.js.map +1 -1
  283. package/dist/react-native/util/checkEnvironment.js +7 -6
  284. package/dist/react-native/util/checkEnvironment.js.map +1 -1
  285. package/dist/react-native/util/concat.js +35 -17
  286. package/dist/react-native/util/concat.js.map +1 -1
  287. package/dist/react-native/util/createAbortablePromise.js +6 -6
  288. package/dist/react-native/util/createAbortablePromise.js.map +1 -1
  289. package/dist/react-native/util/delay.js +2 -2
  290. package/dist/react-native/util/delay.js.map +1 -1
  291. package/dist/react-native/util/file.js +5 -22
  292. package/dist/react-native/util/file.js.map +1 -1
  293. package/dist/react-native/util/helpers.js +4 -4
  294. package/dist/react-native/util/helpers.js.map +1 -1
  295. package/dist/react-native/util/sanitizer.js +1 -7
  296. package/dist/react-native/util/sanitizer.js.map +1 -1
  297. package/dist/react-native/util/tokenCycler.js +6 -7
  298. package/dist/react-native/util/tokenCycler.js.map +1 -1
  299. package/dist/react-native/util/userAgentPlatform-react-native.mjs.map +1 -1
  300. package/dist/react-native/util/userAgentPlatform.js +2 -1
  301. package/dist/react-native/xhrHttpClient.js +5 -3
  302. package/dist/react-native/xhrHttpClient.js.map +1 -1
  303. package/package.json +2 -2
@@ -1,5 +1,6 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
+ var _a, _b, _c, _d;
3
4
  /**
4
5
  * A constant that indicates whether the environment the code is running is a Web Browser.
5
6
  */
@@ -9,10 +10,10 @@ export const isBrowser = typeof window !== "undefined" && typeof window.document
9
10
  * A constant that indicates whether the environment the code is running is a Web Worker.
10
11
  */
11
12
  export const isWebWorker = typeof self === "object" &&
12
- typeof self?.importScripts === "function" &&
13
- (self.constructor?.name === "DedicatedWorkerGlobalScope" ||
14
- self.constructor?.name === "ServiceWorkerGlobalScope" ||
15
- self.constructor?.name === "SharedWorkerGlobalScope");
13
+ typeof (self === null || self === void 0 ? void 0 : self.importScripts) === "function" &&
14
+ (((_a = self.constructor) === null || _a === void 0 ? void 0 : _a.name) === "DedicatedWorkerGlobalScope" ||
15
+ ((_b = self.constructor) === null || _b === void 0 ? void 0 : _b.name) === "ServiceWorkerGlobalScope" ||
16
+ ((_c = self.constructor) === null || _c === void 0 ? void 0 : _c.name) === "SharedWorkerGlobalScope");
16
17
  /**
17
18
  * A constant that indicates whether the environment the code is running is Bun.sh.
18
19
  */
@@ -28,7 +29,7 @@ export const isDeno = typeof Deno !== "undefined" &&
28
29
  */
29
30
  export const isNodeLike = typeof globalThis.process !== "undefined" &&
30
31
  Boolean(globalThis.process.version) &&
31
- Boolean(globalThis.process.versions?.node);
32
+ Boolean((_d = globalThis.process.versions) === null || _d === void 0 ? void 0 : _d.node);
32
33
  /**
33
34
  * A constant that indicates whether the environment the code is running is a Node.js compatible environment.
34
35
  * @deprecated Use `isNodeLike` instead.
@@ -42,5 +43,5 @@ export const isNodeRuntime = isNodeLike && !isBun && !isDeno;
42
43
  * A constant that indicates whether the environment the code is running is in React-Native.
43
44
  */
44
45
  // https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
45
- export const isReactNative = typeof navigator !== "undefined" && navigator?.product === "ReactNative";
46
+ export const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
46
47
  //# sourceMappingURL=checkEnvironment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkEnvironment.js","sourceRoot":"","sources":["../../../src/util/checkEnvironment.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAiBlC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Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\ndeclare global {\n interface DenoGlobal {\n version: {\n deno: string;\n };\n }\n\n interface BunGlobal {\n version: string;\n }\n\n const Deno: DenoGlobal;\n const Bun: BunGlobal;\n}\n\n/**\n * A constant that indicates whether the environment the code is running is a Web Browser.\n */\n// eslint-disable-next-line @azure/azure-sdk/ts-no-window\nexport const isBrowser = typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is a Web Worker.\n */\nexport const isWebWorker =\n typeof self === \"object\" &&\n typeof (self as any)?.importScripts === \"function\" &&\n (self.constructor?.name === \"DedicatedWorkerGlobalScope\" ||\n self.constructor?.name === \"ServiceWorkerGlobalScope\" ||\n self.constructor?.name === \"SharedWorkerGlobalScope\");\n\n/**\n * A constant that indicates whether the environment the code is running is Bun.sh.\n */\nexport const isBun = typeof Bun !== \"undefined\" && typeof Bun.version !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is Deno.\n */\nexport const isDeno =\n typeof Deno !== \"undefined\" &&\n typeof Deno.version !== \"undefined\" &&\n typeof Deno.version.deno !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is a Node.js compatible environment.\n */\nexport const isNodeLike =\n typeof globalThis.process !== \"undefined\" &&\n Boolean(globalThis.process.version) &&\n Boolean(globalThis.process.versions?.node);\n\n/**\n * A constant that indicates whether the environment the code is running is a Node.js compatible environment.\n * @deprecated Use `isNodeLike` instead.\n */\nexport const isNode = isNodeLike;\n\n/**\n * A constant that indicates whether the environment the code is running is Node.JS.\n */\nexport const isNodeRuntime = isNodeLike && !isBun && !isDeno;\n\n/**\n * A constant that indicates whether the environment the code is running is in React-Native.\n */\n// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js\nexport const isReactNative =\n typeof navigator !== \"undefined\" && navigator?.product === \"ReactNative\";\n"]}
1
+ {"version":3,"file":"checkEnvironment.js","sourceRoot":"","sources":["../../../src/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AAM,CAAC;AAE7D;;GAEG;AACH,4GAA4G;AAC5G,MAAM,CAAC,MAAM,aAAa,GACxB,OAAO,SAAS,KAAK,WAAW,IAAI,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,MAAK,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\ndeclare global {\n interface DenoGlobal {\n version: {\n deno: string;\n };\n }\n\n interface BunGlobal {\n version: string;\n }\n\n const Deno: DenoGlobal;\n const Bun: BunGlobal;\n}\n\n/**\n * A constant that indicates whether the environment the code is running is a Web Browser.\n */\n// eslint-disable-next-line @azure/azure-sdk/ts-no-window\nexport const isBrowser = typeof window !== \"undefined\" && typeof window.document !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is a Web Worker.\n */\nexport const isWebWorker =\n typeof self === \"object\" &&\n typeof (self as any)?.importScripts === \"function\" &&\n (self.constructor?.name === \"DedicatedWorkerGlobalScope\" ||\n self.constructor?.name === \"ServiceWorkerGlobalScope\" ||\n self.constructor?.name === \"SharedWorkerGlobalScope\");\n\n/**\n * A constant that indicates whether the environment the code is running is Bun.sh.\n */\nexport const isBun = typeof Bun !== \"undefined\" && typeof Bun.version !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is Deno.\n */\nexport const isDeno =\n typeof Deno !== \"undefined\" &&\n typeof Deno.version !== \"undefined\" &&\n typeof Deno.version.deno !== \"undefined\";\n\n/**\n * A constant that indicates whether the environment the code is running is a Node.js compatible environment.\n */\nexport const isNodeLike =\n typeof globalThis.process !== \"undefined\" &&\n Boolean(globalThis.process.version) &&\n Boolean(globalThis.process.versions?.node);\n\n/**\n * A constant that indicates whether the environment the code is running is a Node.js compatible environment.\n * @deprecated Use `isNodeLike` instead.\n */\nexport const isNode = isNodeLike;\n\n/**\n * A constant that indicates whether the environment the code is running is Node.JS.\n */\nexport const isNodeRuntime = isNodeLike && !isBun && !isDeno;\n\n/**\n * A constant that indicates whether the environment the code is running is in React-Native.\n */\n// https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js\nexport const isReactNative =\n typeof navigator !== \"undefined\" && navigator?.product === \"ReactNative\";\n"]}
@@ -1,22 +1,25 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT license.
3
+ import { __asyncGenerator, __asyncValues, __await } from "tslib";
3
4
  import { Readable } from "stream";
4
5
  import { isBlob } from "./typeGuards.js";
5
6
  import { getRawContent } from "./file.js";
6
- async function* streamAsyncIterator() {
7
- const reader = this.getReader();
8
- try {
9
- while (true) {
10
- const { done, value } = await reader.read();
11
- if (done) {
12
- return;
7
+ function streamAsyncIterator() {
8
+ return __asyncGenerator(this, arguments, function* streamAsyncIterator_1() {
9
+ const reader = this.getReader();
10
+ try {
11
+ while (true) {
12
+ const { done, value } = yield __await(reader.read());
13
+ if (done) {
14
+ return yield __await(void 0);
15
+ }
16
+ yield yield __await(value);
13
17
  }
14
- yield value;
15
18
  }
16
- }
17
- finally {
18
- reader.releaseLock();
19
- }
19
+ finally {
20
+ reader.releaseLock();
21
+ }
22
+ });
20
23
  }
21
24
  function makeAsyncIterable(webStream) {
22
25
  if (!webStream[Symbol.asyncIterator]) {
@@ -58,12 +61,27 @@ function toStream(source) {
58
61
  export async function concat(sources) {
59
62
  return function () {
60
63
  const streams = sources.map((x) => (typeof x === "function" ? x() : x)).map(toStream);
61
- return Readable.from((async function* () {
62
- for (const stream of streams) {
63
- for await (const chunk of stream) {
64
- yield chunk;
64
+ return Readable.from((function () {
65
+ return __asyncGenerator(this, arguments, function* () {
66
+ var _a, e_1, _b, _c;
67
+ for (const stream of streams) {
68
+ try {
69
+ for (var _d = true, stream_1 = (e_1 = void 0, __asyncValues(stream)), stream_1_1; stream_1_1 = yield __await(stream_1.next()), _a = stream_1_1.done, !_a; _d = true) {
70
+ _c = stream_1_1.value;
71
+ _d = false;
72
+ const chunk = _c;
73
+ yield yield __await(chunk);
74
+ }
75
+ }
76
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
77
+ finally {
78
+ try {
79
+ if (!_d && !_a && (_b = stream_1.return)) yield __await(_b.call(stream_1));
80
+ }
81
+ finally { if (e_1) throw e_1.error; }
82
+ }
65
83
  }
66
- }
84
+ });
67
85
  })());
68
86
  };
69
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"concat.js","sourceRoot":"","sources":["../../../src/util/concat.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,KAAK,SAAS,CAAC,CAAC,mBAAmB;IAGjC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO;YACT,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAI,SAAc;IAC1C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QACrC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;QACtB,SAAS,CAAC,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CACvB,MAA0D;IAE1D,IAAI,MAAM,YAAY,cAAc,EAAE,CAAC;QACrC,iBAAiB,CAAa,MAAM,CAAC,CAAC;QACtC,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CACf,MAA8E;IAE9E,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5C,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;SAAM,CAAC;QACN,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AASD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAgD;IAEhD,OAAO;QACL,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEtF,OAAO,QAAQ,CAAC,IAAI,CAClB,CAAC,KAAK,SAAS,CAAC;YACd,KAAK,MAAM,MAAM,IAAI,OAAkC,EAAE,CAAC;gBACxD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;oBACjC,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC,CAAC,EAAE,CACL,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Readable } from \"stream\";\nimport type { ReadableStream as AsyncIterableReadableStream } from \"stream/web\";\nimport { isBlob } from \"./typeGuards.js\";\nimport { getRawContent } from \"./file.js\";\n\nasync function* streamAsyncIterator(\n this: ReadableStream<Uint8Array>,\n): AsyncIterableIterator<Uint8Array> {\n const reader = this.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n return;\n }\n\n yield value;\n }\n } finally {\n reader.releaseLock();\n }\n}\n\nfunction makeAsyncIterable<T>(webStream: any): asserts webStream is AsyncIterableReadableStream<T> {\n if (!webStream[Symbol.asyncIterator]) {\n webStream[Symbol.asyncIterator] = streamAsyncIterator.bind(webStream);\n }\n\n if (!webStream.values) {\n webStream.values = streamAsyncIterator.bind(webStream);\n }\n}\n\nfunction ensureNodeStream(\n stream: ReadableStream<Uint8Array> | NodeJS.ReadableStream,\n): NodeJS.ReadableStream {\n if (stream instanceof ReadableStream) {\n makeAsyncIterable<Uint8Array>(stream);\n return Readable.fromWeb(stream);\n } else {\n return stream;\n }\n}\n\nfunction toStream(\n source: ReadableStream<Uint8Array> | NodeJS.ReadableStream | Uint8Array | Blob,\n): NodeJS.ReadableStream {\n if (source instanceof Uint8Array) {\n return Readable.from(Buffer.from(source));\n } else if (isBlob(source)) {\n return toStream(getRawContent(source));\n } else {\n return ensureNodeStream(source);\n }\n}\n\n/**\n * Accepted binary data types for concat\n *\n * @internal\n */\nexport type ConcatSource = ReadableStream<Uint8Array> | NodeJS.ReadableStream | Uint8Array | Blob;\n\n/**\n * Utility function that concatenates a set of binary inputs into one combined output.\n *\n * @param sources - array of sources for the concatenation\n * @returns - in Node, a (() =\\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.\n * In browser, returns a `Blob` representing all the concatenated inputs.\n *\n * @internal\n */\nexport async function concat(\n sources: (ConcatSource | (() => ConcatSource))[],\n): Promise<(() => NodeJS.ReadableStream) | Blob> {\n return function () {\n const streams = sources.map((x) => (typeof x === \"function\" ? x() : x)).map(toStream);\n\n return Readable.from(\n (async function* () {\n for (const stream of streams as NodeJS.ReadableStream[]) {\n for await (const chunk of stream) {\n yield chunk;\n }\n }\n })(),\n );\n };\n}\n"]}
1
+ {"version":3,"file":"concat.js","sourceRoot":"","sources":["../../../src/util/concat.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,SAAgB,mBAAmB;;QAGjC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,IAAI,CAAC;YACH,OAAO,IAAI,EAAE,CAAC;gBACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,cAAM,MAAM,CAAC,IAAI,EAAE,CAAA,CAAC;gBAC5C,IAAI,IAAI,EAAE,CAAC;oBACT,6BAAO;gBACT,CAAC;gBAED,oBAAM,KAAK,CAAA,CAAC;YACd,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CAAA;AAED,SAAS,iBAAiB,CAAI,SAAc;IAC1C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;QACrC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;QACtB,SAAS,CAAC,MAAM,GAAG,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CACvB,MAA0D;IAE1D,IAAI,MAAM,YAAY,cAAc,EAAE,CAAC;QACrC,iBAAiB,CAAa,MAAM,CAAC,CAAC;QACtC,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CACf,MAA8E;IAE9E,IAAI,MAAM,YAAY,UAAU,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5C,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1B,OAAO,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;SAAM,CAAC;QACN,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AASD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAgD;IAEhD,OAAO;QACL,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEtF,OAAO,QAAQ,CAAC,IAAI,CAClB,CAAC;;;gBACC,KAAK,MAAM,MAAM,IAAI,OAAkC,EAAE,CAAC;;wBACxD,KAA0B,eAAA,0BAAA,cAAA,MAAM,CAAA,CAAA,YAAA,qFAAE,CAAC;4BAAT,sBAAM;4BAAN,WAAM;4BAArB,MAAM,KAAK,KAAA,CAAA;4BACpB,oBAAM,KAAK,CAAA,CAAC;wBACd,CAAC;;;;;;;;;gBACH,CAAC;YACH,CAAC;SAAA,CAAC,EAAE,CACL,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { Readable } from \"stream\";\nimport type { ReadableStream as AsyncIterableReadableStream } from \"stream/web\";\nimport { isBlob } from \"./typeGuards.js\";\nimport { getRawContent } from \"./file.js\";\n\nasync function* streamAsyncIterator(\n this: ReadableStream<Uint8Array>,\n): AsyncIterableIterator<Uint8Array> {\n const reader = this.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n return;\n }\n\n yield value;\n }\n } finally {\n reader.releaseLock();\n }\n}\n\nfunction makeAsyncIterable<T>(webStream: any): asserts webStream is AsyncIterableReadableStream<T> {\n if (!webStream[Symbol.asyncIterator]) {\n webStream[Symbol.asyncIterator] = streamAsyncIterator.bind(webStream);\n }\n\n if (!webStream.values) {\n webStream.values = streamAsyncIterator.bind(webStream);\n }\n}\n\nfunction ensureNodeStream(\n stream: ReadableStream<Uint8Array> | NodeJS.ReadableStream,\n): NodeJS.ReadableStream {\n if (stream instanceof ReadableStream) {\n makeAsyncIterable<Uint8Array>(stream);\n return Readable.fromWeb(stream);\n } else {\n return stream;\n }\n}\n\nfunction toStream(\n source: ReadableStream<Uint8Array> | NodeJS.ReadableStream | Uint8Array | Blob,\n): NodeJS.ReadableStream {\n if (source instanceof Uint8Array) {\n return Readable.from(Buffer.from(source));\n } else if (isBlob(source)) {\n return toStream(getRawContent(source));\n } else {\n return ensureNodeStream(source);\n }\n}\n\n/**\n * Accepted binary data types for concat\n *\n * @internal\n */\nexport type ConcatSource = ReadableStream<Uint8Array> | NodeJS.ReadableStream | Uint8Array | Blob;\n\n/**\n * Utility function that concatenates a set of binary inputs into one combined output.\n *\n * @param sources - array of sources for the concatenation\n * @returns - in Node, a (() =\\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.\n * In browser, returns a `Blob` representing all the concatenated inputs.\n *\n * @internal\n */\nexport async function concat(\n sources: (ConcatSource | (() => ConcatSource))[],\n): Promise<(() => NodeJS.ReadableStream) | Blob> {\n return function () {\n const streams = sources.map((x) => (typeof x === \"function\" ? x() : x)).map(toStream);\n\n return Readable.from(\n (async function* () {\n for (const stream of streams as NodeJS.ReadableStream[]) {\n for await (const chunk of stream) {\n yield chunk;\n }\n }\n })(),\n );\n };\n}\n"]}
@@ -8,20 +8,20 @@ import { AbortError } from "../abort-controller/AbortError.js";
8
8
  * @returns A promise that can be aborted.
9
9
  */
10
10
  export function createAbortablePromise(buildPromise, options) {
11
- const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options ?? {};
11
+ const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options !== null && options !== void 0 ? options : {};
12
12
  return new Promise((resolve, reject) => {
13
13
  function rejectOnAbort() {
14
- reject(new AbortError(abortErrorMsg ?? "The operation was aborted."));
14
+ reject(new AbortError(abortErrorMsg !== null && abortErrorMsg !== void 0 ? abortErrorMsg : "The operation was aborted."));
15
15
  }
16
16
  function removeListeners() {
17
- abortSignal?.removeEventListener("abort", onAbort);
17
+ abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener("abort", onAbort);
18
18
  }
19
19
  function onAbort() {
20
- cleanupBeforeAbort?.();
20
+ cleanupBeforeAbort === null || cleanupBeforeAbort === void 0 ? void 0 : cleanupBeforeAbort();
21
21
  removeListeners();
22
22
  rejectOnAbort();
23
23
  }
24
- if (abortSignal?.aborted) {
24
+ if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
25
25
  return rejectOnAbort();
26
26
  }
27
27
  try {
@@ -36,7 +36,7 @@ export function createAbortablePromise(buildPromise, options) {
36
36
  catch (err) {
37
37
  reject(err);
38
38
  }
39
- abortSignal?.addEventListener("abort", onAbort);
39
+ abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener("abort", onAbort);
40
40
  });
41
41
  }
42
42
  //# sourceMappingURL=createAbortablePromise.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createAbortablePromise.js","sourceRoot":"","sources":["../../../src/util/createAbortablePromise.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAW/D;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAGS,EACT,OAAuC;IAEvC,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,SAAS,aAAa;YACpB,MAAM,CAAC,IAAI,UAAU,CAAC,aAAa,IAAI,4BAA4B,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,SAAS,eAAe;YACtB,WAAW,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;QACD,SAAS,OAAO;YACd,kBAAkB,EAAE,EAAE,CAAC;YACvB,eAAe,EAAE,CAAC;YAClB,aAAa,EAAE,CAAC;QAClB,CAAC;QACD,IAAI,WAAW,EAAE,OAAO,EAAE,CAAC;YACzB,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,CAAC;YACH,YAAY,CACV,CAAC,CAAC,EAAE,EAAE;gBACJ,eAAe,EAAE,CAAC;gBAClB,OAAO,CAAC,CAAC,CAAC,CAAC;YACb,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;gBACJ,eAAe,EAAE,CAAC;gBAClB,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,WAAW,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport { AbortOptions } from \"./aborterUtils.js\";\n\n/**\n * Options for the createAbortablePromise function.\n */\nexport interface CreateAbortablePromiseOptions extends AbortOptions {\n /** A function to be called if the promise was aborted */\n cleanupBeforeAbort?: () => void;\n}\n\n/**\n * Creates an abortable promise.\n * @param buildPromise - A function that takes the resolve and reject functions as parameters.\n * @param options - The options for the abortable promise.\n * @returns A promise that can be aborted.\n */\nexport function createAbortablePromise<T>(\n buildPromise: (\n resolve: (value: T | PromiseLike<T>) => void,\n reject: (reason?: any) => void,\n ) => void,\n options?: CreateAbortablePromiseOptions,\n): Promise<T> {\n const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options ?? {};\n return new Promise((resolve, reject) => {\n function rejectOnAbort(): void {\n reject(new AbortError(abortErrorMsg ?? \"The operation was aborted.\"));\n }\n function removeListeners(): void {\n abortSignal?.removeEventListener(\"abort\", onAbort);\n }\n function onAbort(): void {\n cleanupBeforeAbort?.();\n removeListeners();\n rejectOnAbort();\n }\n if (abortSignal?.aborted) {\n return rejectOnAbort();\n }\n try {\n buildPromise(\n (x) => {\n removeListeners();\n resolve(x);\n },\n (x) => {\n removeListeners();\n reject(x);\n },\n );\n } catch (err) {\n reject(err);\n }\n abortSignal?.addEventListener(\"abort\", onAbort);\n });\n}\n"]}
1
+ {"version":3,"file":"createAbortablePromise.js","sourceRoot":"","sources":["../../../src/util/createAbortablePromise.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAW/D;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAGS,EACT,OAAuC;IAEvC,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,SAAS,aAAa;YACpB,MAAM,CAAC,IAAI,UAAU,CAAC,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,4BAA4B,CAAC,CAAC,CAAC;QACxE,CAAC;QACD,SAAS,eAAe;YACtB,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;QACD,SAAS,OAAO;YACd,kBAAkB,aAAlB,kBAAkB,uBAAlB,kBAAkB,EAAI,CAAC;YACvB,eAAe,EAAE,CAAC;YAClB,aAAa,EAAE,CAAC;QAClB,CAAC;QACD,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,EAAE,CAAC;YACzB,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,CAAC;YACH,YAAY,CACV,CAAC,CAAC,EAAE,EAAE;gBACJ,eAAe,EAAE,CAAC;gBAClB,OAAO,CAAC,CAAC,CAAC,CAAC;YACb,CAAC,EACD,CAAC,CAAC,EAAE,EAAE;gBACJ,eAAe,EAAE,CAAC;gBAClB,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,CAAC,CAAC;QACd,CAAC;QACD,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport { AbortOptions } from \"./aborterUtils.js\";\n\n/**\n * Options for the createAbortablePromise function.\n */\nexport interface CreateAbortablePromiseOptions extends AbortOptions {\n /** A function to be called if the promise was aborted */\n cleanupBeforeAbort?: () => void;\n}\n\n/**\n * Creates an abortable promise.\n * @param buildPromise - A function that takes the resolve and reject functions as parameters.\n * @param options - The options for the abortable promise.\n * @returns A promise that can be aborted.\n */\nexport function createAbortablePromise<T>(\n buildPromise: (\n resolve: (value: T | PromiseLike<T>) => void,\n reject: (reason?: any) => void,\n ) => void,\n options?: CreateAbortablePromiseOptions,\n): Promise<T> {\n const { cleanupBeforeAbort, abortSignal, abortErrorMsg } = options ?? {};\n return new Promise((resolve, reject) => {\n function rejectOnAbort(): void {\n reject(new AbortError(abortErrorMsg ?? \"The operation was aborted.\"));\n }\n function removeListeners(): void {\n abortSignal?.removeEventListener(\"abort\", onAbort);\n }\n function onAbort(): void {\n cleanupBeforeAbort?.();\n removeListeners();\n rejectOnAbort();\n }\n if (abortSignal?.aborted) {\n return rejectOnAbort();\n }\n try {\n buildPromise(\n (x) => {\n removeListeners();\n resolve(x);\n },\n (x) => {\n removeListeners();\n reject(x);\n },\n );\n } catch (err) {\n reject(err);\n }\n abortSignal?.addEventListener(\"abort\", onAbort);\n });\n}\n"]}
@@ -10,13 +10,13 @@ const StandardAbortMessage = "The delay was aborted.";
10
10
  */
11
11
  export function delay(timeInMs, options) {
12
12
  let token;
13
- const { abortSignal, abortErrorMsg } = options ?? {};
13
+ const { abortSignal, abortErrorMsg } = options !== null && options !== void 0 ? options : {};
14
14
  return createAbortablePromise((resolve) => {
15
15
  token = setTimeout(resolve, timeInMs);
16
16
  }, {
17
17
  cleanupBeforeAbort: () => clearTimeout(token),
18
18
  abortSignal,
19
- abortErrorMsg: abortErrorMsg ?? StandardAbortMessage,
19
+ abortErrorMsg: abortErrorMsg !== null && abortErrorMsg !== void 0 ? abortErrorMsg : StandardAbortMessage,
20
20
  });
21
21
  }
22
22
  //# sourceMappingURL=delay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../src/util/delay.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAOtD;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,QAAgB,EAAE,OAAsB;IAC5D,IAAI,KAAoC,CAAC;IACzC,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IACrD,OAAO,sBAAsB,CAC3B,CAAC,OAAO,EAAE,EAAE;QACV,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,EACD;QACE,kBAAkB,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC;QAC7C,WAAW;QACX,aAAa,EAAE,aAAa,IAAI,oBAAoB;KACrD,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortOptions } from \"./aborterUtils.js\";\nimport { createAbortablePromise } from \"./createAbortablePromise.js\";\n\nconst StandardAbortMessage = \"The delay was aborted.\";\n\n/**\n * Options for support abort functionality for the delay method\n */\nexport interface DelayOptions extends AbortOptions {}\n\n/**\n * A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.\n * @param timeInMs - The number of milliseconds to be delayed.\n * @param options - The options for delay - currently abort options\n * @returns Promise that is resolved after timeInMs\n */\nexport function delay(timeInMs: number, options?: DelayOptions): Promise<void> {\n let token: ReturnType<typeof setTimeout>;\n const { abortSignal, abortErrorMsg } = options ?? {};\n return createAbortablePromise(\n (resolve) => {\n token = setTimeout(resolve, timeInMs);\n },\n {\n cleanupBeforeAbort: () => clearTimeout(token),\n abortSignal,\n abortErrorMsg: abortErrorMsg ?? StandardAbortMessage,\n },\n );\n}\n"]}
1
+ {"version":3,"file":"delay.js","sourceRoot":"","sources":["../../../src/util/delay.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAOtD;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,QAAgB,EAAE,OAAsB;IAC5D,IAAI,KAAoC,CAAC;IACzC,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,CAAC;IACrD,OAAO,sBAAsB,CAC3B,CAAC,OAAO,EAAE,EAAE;QACV,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,EACD;QACE,kBAAkB,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC;QAC7C,WAAW;QACX,aAAa,EAAE,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,oBAAoB;KACrD,CACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortOptions } from \"./aborterUtils.js\";\nimport { createAbortablePromise } from \"./createAbortablePromise.js\";\n\nconst StandardAbortMessage = \"The delay was aborted.\";\n\n/**\n * Options for support abort functionality for the delay method\n */\nexport interface DelayOptions extends AbortOptions {}\n\n/**\n * A wrapper for setTimeout that resolves a promise after timeInMs milliseconds.\n * @param timeInMs - The number of milliseconds to be delayed.\n * @param options - The options for delay - currently abort options\n * @returns Promise that is resolved after timeInMs\n */\nexport function delay(timeInMs: number, options?: DelayOptions): Promise<void> {\n let token: ReturnType<typeof setTimeout>;\n const { abortSignal, abortErrorMsg } = options ?? {};\n return createAbortablePromise(\n (resolve) => {\n token = setTimeout(resolve, timeInMs);\n },\n {\n cleanupBeforeAbort: () => clearTimeout(token),\n abortSignal,\n abortErrorMsg: abortErrorMsg ?? StandardAbortMessage,\n },\n );\n}\n"]}
@@ -64,22 +64,14 @@ export function getRawContent(blob) {
64
64
  * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
65
65
  */
66
66
  export function createFileFromStream(stream, name, options = {}) {
67
- return {
68
- ...unimplementedMethods,
69
- type: options.type ?? "",
70
- lastModified: options.lastModified ?? new Date().getTime(),
71
- webkitRelativePath: options.webkitRelativePath ?? "",
72
- size: options.size ?? -1,
73
- name,
74
- stream: () => {
67
+ var _a, _b, _c, _d;
68
+ return Object.assign(Object.assign({}, unimplementedMethods), { type: (_a = options.type) !== null && _a !== void 0 ? _a : "", lastModified: (_b = options.lastModified) !== null && _b !== void 0 ? _b : new Date().getTime(), webkitRelativePath: (_c = options.webkitRelativePath) !== null && _c !== void 0 ? _c : "", size: (_d = options.size) !== null && _d !== void 0 ? _d : -1, name, stream: () => {
75
69
  const s = stream();
76
70
  if (isNodeReadableStream(s)) {
77
71
  throw new Error("Not supported: a Node stream was provided as input to createFileFromStream.");
78
72
  }
79
73
  return s;
80
- },
81
- [rawContent]: stream,
82
- };
74
+ }, [rawContent]: stream });
83
75
  }
84
76
  /**
85
77
  * Create an object that implements the File interface. This object is intended to be
@@ -93,18 +85,9 @@ export function createFileFromStream(stream, name, options = {}) {
93
85
  * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
94
86
  */
95
87
  export function createFile(content, name, options = {}) {
88
+ var _a, _b, _c;
96
89
  if (isNode) {
97
- return {
98
- ...unimplementedMethods,
99
- type: options.type ?? "",
100
- lastModified: options.lastModified ?? new Date().getTime(),
101
- webkitRelativePath: options.webkitRelativePath ?? "",
102
- size: content.byteLength,
103
- name,
104
- arrayBuffer: async () => content.buffer,
105
- stream: () => new Blob([content]).stream(),
106
- [rawContent]: () => content,
107
- };
90
+ return Object.assign(Object.assign({}, unimplementedMethods), { type: (_a = options.type) !== null && _a !== void 0 ? _a : "", lastModified: (_b = options.lastModified) !== null && _b !== void 0 ? _b : new Date().getTime(), webkitRelativePath: (_c = options.webkitRelativePath) !== null && _c !== void 0 ? _c : "", size: content.byteLength, name, arrayBuffer: async () => content.buffer, stream: () => new Blob([content]).stream(), [rawContent]: () => content });
108
91
  }
109
92
  else {
110
93
  return new File([content], name, options);
@@ -1 +1 @@
1
- {"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAi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AAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;YACJ,CAAC;YAED,OAAO,CAAC,CAAC;QACX,CAAC;QACD,CAAC,UAAU,CAAC,EAAE,MAAM;KACA,CAAC;AACzB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,OAAmB,EACnB,IAAY,EACZ,UAA6B,EAAE;IAE/B,IAAI,MAAM,EAAE,CAAC;QACX,OAAO;YACL,GAAG,oBAAoB;YACvB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,EAAE;YACxB,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC1D,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,EAAE;YACpD,IAAI,EAAE,OAAO,CAAC,UAAU;YACxB,IAAI;YACJ,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM;YACvC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE;YAC1C,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO;SACP,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { isNode } from \"./checkEnvironment.js\";\nimport { isNodeReadableStream } from \"./typeGuards.js\";\n\n/**\n * Options passed into createFile specifying metadata about the file.\n */\nexport interface CreateFileOptions {\n /**\n * The MIME type of the file.\n */\n type?: string;\n\n /**\n * Last modified time of the file as a UNIX timestamp.\n * This will default to the current date.\n */\n lastModified?: number;\n\n /**\n * relative path of this file when uploading a directory.\n */\n webkitRelativePath?: string;\n}\n\n/**\n * Extra options for createFile when a stream is being passed in.\n */\nexport interface CreateFileFromStreamOptions extends CreateFileOptions {\n /**\n * Size of the file represented by the stream in bytes.\n *\n * This will be used by the pipeline when calculating the Content-Length header\n * for the overall request.\n */\n size?: number;\n}\n\nconst unimplementedMethods = {\n arrayBuffer: () => {\n throw new Error(\"Not implemented\");\n },\n slice: () => {\n throw new Error(\"Not implemented\");\n },\n text: () => {\n throw new Error(\"Not implemented\");\n },\n};\n\n/**\n * Private symbol used as key on objects created using createFile containing the\n * original source of the file object.\n *\n * This is used in Node to access the original Node stream without using Blob#stream, which\n * returns a web stream. This is done to avoid a couple of bugs to do with Blob#stream and\n * Readable#to/fromWeb in Node versions we support:\n * - https://github.com/nodejs/node/issues/42694 (fixed in Node 18.14)\n * - https://github.com/nodejs/node/issues/48916 (fixed in Node 20.6)\n *\n * Once these versions are no longer supported, we may be able to stop doing this.\n *\n * @internal\n */\nconst rawContent: unique symbol = Symbol(\"rawContent\");\n\n/**\n * Type signature of a blob-like object with a raw content property.\n */\ninterface RawContent {\n [rawContent](): Uint8Array | NodeJS.ReadableStream | ReadableStream<Uint8Array>;\n}\n\nfunction hasRawContent(x: unknown): x is RawContent {\n return typeof (x as RawContent)[rawContent] === \"function\";\n}\n\n/**\n * Extract the raw content from a given blob-like object. If the input was created using createFile\n * or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.\n * For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.\n *\n * @internal\n */\nexport function getRawContent(\n blob: Blob,\n): NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array {\n if (hasRawContent(blob)) {\n return blob[rawContent]();\n } else {\n return blob.stream();\n }\n}\n\n/**\n * Create an object that implements the File interface. This object is intended to be\n * passed into RequestBodyType.formData, and is not guaranteed to work as expected in\n * other situations.\n *\n * Use this function to:\n * - Create a File object for use in RequestBodyType.formData in environments where the\n * global File object is unavailable.\n * - Create a File-like object from a readable stream without reading the stream into memory.\n *\n * @param stream - the content of the file as a callback returning a stream. When a File object made using createFile is\n * passed in a request's form data map, the stream will not be read into memory\n * and instead will be streamed when the request is made. In the event of a retry, the\n * stream needs to be read again, so this callback SHOULD return a fresh stream if possible.\n * @param name - the name of the file.\n * @param options - optional metadata about the file, e.g. file name, file size, MIME type.\n */\nexport function createFileFromStream(\n stream: () => ReadableStream<Uint8Array> | NodeJS.ReadableStream,\n name: string,\n options: CreateFileFromStreamOptions = {},\n): File {\n return {\n ...unimplementedMethods,\n type: options.type ?? \"\",\n lastModified: options.lastModified ?? new Date().getTime(),\n webkitRelativePath: options.webkitRelativePath ?? \"\",\n size: options.size ?? -1,\n name,\n stream: () => {\n const s = stream();\n if (isNodeReadableStream(s)) {\n throw new Error(\n \"Not supported: a Node stream was provided as input to createFileFromStream.\",\n );\n }\n\n return s;\n },\n [rawContent]: stream,\n } as File & RawContent;\n}\n\n/**\n * Create an object that implements the File interface. This object is intended to be\n * passed into RequestBodyType.formData, and is not guaranteed to work as expected in\n * other situations.\n *\n * Use this function create a File object for use in RequestBodyType.formData in environments where the global File object is unavailable.\n *\n * @param content - the content of the file as a Uint8Array in memory.\n * @param name - the name of the file.\n * @param options - optional metadata about the file, e.g. file name, file size, MIME type.\n */\nexport function createFile(\n content: Uint8Array,\n name: string,\n options: CreateFileOptions = {},\n): File {\n if (isNode) {\n return {\n ...unimplementedMethods,\n type: options.type ?? \"\",\n lastModified: options.lastModified ?? new Date().getTime(),\n webkitRelativePath: options.webkitRelativePath ?? \"\",\n size: content.byteLength,\n name,\n arrayBuffer: async () => content.buffer,\n stream: () => new Blob([content]).stream(),\n [rawContent]: () => content,\n } as File & RawContent;\n } else {\n return new File([content], name, options);\n }\n}\n"]}
1
+ {"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB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I,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5B,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;YACJ,CAAC;YAED,OAAO,CAAC,CAAC;QACX,CAAC,EACD,CAAC,UAAU,CAAC,EAAE,MAAM,GACA,CAAC;AACzB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,OAAmB,EACnB,IAAY,EACZ,UAA6B,EAAE;;IAE/B,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,gCACF,oBAAoB,KACvB,IAAI,EAAE,MAAA,OAAO,CAAC,IAAI,mCAAI,EAAE,EACxB,YAAY,EAAE,MAAA,OAAO,CAAC,YAAY,mCAAI,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,EAC1D,kBAAkB,EAAE,MAAA,OAAO,CAAC,kBAAkB,mCAAI,EAAE,EACpD,IAAI,EAAE,OAAO,CAAC,UAAU,EACxB,IAAI,EACJ,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EACvC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,EAC1C,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,OAAO,GACP,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { isNode } from \"./checkEnvironment.js\";\nimport { isNodeReadableStream } from \"./typeGuards.js\";\n\n/**\n * Options passed into createFile specifying metadata about the file.\n */\nexport interface CreateFileOptions {\n /**\n * The MIME type of the file.\n */\n type?: string;\n\n /**\n * Last modified time of the file as a UNIX timestamp.\n * This will default to the current date.\n */\n lastModified?: number;\n\n /**\n * relative path of this file when uploading a directory.\n */\n webkitRelativePath?: string;\n}\n\n/**\n * Extra options for createFile when a stream is being passed in.\n */\nexport interface CreateFileFromStreamOptions extends CreateFileOptions {\n /**\n * Size of the file represented by the stream in bytes.\n *\n * This will be used by the pipeline when calculating the Content-Length header\n * for the overall request.\n */\n size?: number;\n}\n\nconst unimplementedMethods = {\n arrayBuffer: () => {\n throw new Error(\"Not implemented\");\n },\n slice: () => {\n throw new Error(\"Not implemented\");\n },\n text: () => {\n throw new Error(\"Not implemented\");\n },\n};\n\n/**\n * Private symbol used as key on objects created using createFile containing the\n * original source of the file object.\n *\n * This is used in Node to access the original Node stream without using Blob#stream, which\n * returns a web stream. This is done to avoid a couple of bugs to do with Blob#stream and\n * Readable#to/fromWeb in Node versions we support:\n * - https://github.com/nodejs/node/issues/42694 (fixed in Node 18.14)\n * - https://github.com/nodejs/node/issues/48916 (fixed in Node 20.6)\n *\n * Once these versions are no longer supported, we may be able to stop doing this.\n *\n * @internal\n */\nconst rawContent: unique symbol = Symbol(\"rawContent\");\n\n/**\n * Type signature of a blob-like object with a raw content property.\n */\ninterface RawContent {\n [rawContent](): Uint8Array | NodeJS.ReadableStream | ReadableStream<Uint8Array>;\n}\n\nfunction hasRawContent(x: unknown): x is RawContent {\n return typeof (x as RawContent)[rawContent] === \"function\";\n}\n\n/**\n * Extract the raw content from a given blob-like object. If the input was created using createFile\n * or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.\n * For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.\n *\n * @internal\n */\nexport function getRawContent(\n blob: Blob,\n): NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array {\n if (hasRawContent(blob)) {\n return blob[rawContent]();\n } else {\n return blob.stream();\n }\n}\n\n/**\n * Create an object that implements the File interface. This object is intended to be\n * passed into RequestBodyType.formData, and is not guaranteed to work as expected in\n * other situations.\n *\n * Use this function to:\n * - Create a File object for use in RequestBodyType.formData in environments where the\n * global File object is unavailable.\n * - Create a File-like object from a readable stream without reading the stream into memory.\n *\n * @param stream - the content of the file as a callback returning a stream. When a File object made using createFile is\n * passed in a request's form data map, the stream will not be read into memory\n * and instead will be streamed when the request is made. In the event of a retry, the\n * stream needs to be read again, so this callback SHOULD return a fresh stream if possible.\n * @param name - the name of the file.\n * @param options - optional metadata about the file, e.g. file name, file size, MIME type.\n */\nexport function createFileFromStream(\n stream: () => ReadableStream<Uint8Array> | NodeJS.ReadableStream,\n name: string,\n options: CreateFileFromStreamOptions = {},\n): File {\n return {\n ...unimplementedMethods,\n type: options.type ?? \"\",\n lastModified: options.lastModified ?? new Date().getTime(),\n webkitRelativePath: options.webkitRelativePath ?? \"\",\n size: options.size ?? -1,\n name,\n stream: () => {\n const s = stream();\n if (isNodeReadableStream(s)) {\n throw new Error(\n \"Not supported: a Node stream was provided as input to createFileFromStream.\",\n );\n }\n\n return s;\n },\n [rawContent]: stream,\n } as File & RawContent;\n}\n\n/**\n * Create an object that implements the File interface. This object is intended to be\n * passed into RequestBodyType.formData, and is not guaranteed to work as expected in\n * other situations.\n *\n * Use this function create a File object for use in RequestBodyType.formData in environments where the global File object is unavailable.\n *\n * @param content - the content of the file as a Uint8Array in memory.\n * @param name - the name of the file.\n * @param options - optional metadata about the file, e.g. file name, file size, MIME type.\n */\nexport function createFile(\n content: Uint8Array,\n name: string,\n options: CreateFileOptions = {},\n): File {\n if (isNode) {\n return {\n ...unimplementedMethods,\n type: options.type ?? \"\",\n lastModified: options.lastModified ?? new Date().getTime(),\n webkitRelativePath: options.webkitRelativePath ?? \"\",\n size: content.byteLength,\n name,\n arrayBuffer: async () => content.buffer,\n stream: () => new Blob([content]).stream(),\n [rawContent]: () => content,\n } as File & RawContent;\n } else {\n return new File([content], name, options);\n }\n}\n"]}
@@ -16,10 +16,10 @@ export function delay(delayInMs, value, options) {
16
16
  let timer = undefined;
17
17
  let onAborted = undefined;
18
18
  const rejectOnAbort = () => {
19
- return reject(new AbortError(options?.abortErrorMsg ? options?.abortErrorMsg : StandardAbortMessage));
19
+ return reject(new AbortError((options === null || options === void 0 ? void 0 : options.abortErrorMsg) ? options === null || options === void 0 ? void 0 : options.abortErrorMsg : StandardAbortMessage));
20
20
  };
21
21
  const removeListeners = () => {
22
- if (options?.abortSignal && onAborted) {
22
+ if ((options === null || options === void 0 ? void 0 : options.abortSignal) && onAborted) {
23
23
  options.abortSignal.removeEventListener("abort", onAborted);
24
24
  }
25
25
  };
@@ -30,14 +30,14 @@ export function delay(delayInMs, value, options) {
30
30
  removeListeners();
31
31
  return rejectOnAbort();
32
32
  };
33
- if (options?.abortSignal && options.abortSignal.aborted) {
33
+ if ((options === null || options === void 0 ? void 0 : options.abortSignal) && options.abortSignal.aborted) {
34
34
  return rejectOnAbort();
35
35
  }
36
36
  timer = setTimeout(() => {
37
37
  removeListeners();
38
38
  resolve(value);
39
39
  }, delayInMs);
40
- if (options?.abortSignal) {
40
+ if (options === null || options === void 0 ? void 0 : options.abortSignal) {
41
41
  options.abortSignal.addEventListener("abort", onAborted);
42
42
  }
43
43
  });
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/util/helpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAI/D,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CACnB,SAAiB,EACjB,KAAS,EACT,OAGC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,KAAK,GAA8C,SAAS,CAAC;QACjE,IAAI,SAAS,GAA6B,SAAS,CAAC;QAEpD,MAAM,aAAa,GAAG,GAAS,EAAE;YAC/B,OAAO,MAAM,CACX,IAAI,UAAU,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,oBAAoB,CAAC,CACvF,CAAC;QACJ,CAAC,CAAC;QAEF,MAAM,eAAe,GAAG,GAAS,EAAE;YACjC,IAAI,OAAO,EAAE,WAAW,IAAI,SAAS,EAAE,CAAC;gBACtC,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC,CAAC;QAEF,SAAS,GAAG,GAAS,EAAE;YACrB,IAAI,KAAK,EAAE,CAAC;gBACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YACD,eAAe,EAAE,CAAC;YAClB,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC,CAAC;QAEF,IAAI,OAAO,EAAE,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YACxD,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC;QAED,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,eAAe,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,EAAE,SAAS,CAAC,CAAC;QAEd,IAAI,OAAO,EAAE,WAAW,EAAE,CAAC;YACzB,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA0B,EAC1B,UAAkB;IAElB,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;QAAE,OAAO;IACrC,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport { PipelineResponse } from \"../interfaces.js\";\n\nconst StandardAbortMessage = \"The operation was aborted.\";\n\n/**\n * A wrapper for setTimeout that resolves a promise after delayInMs milliseconds.\n * @param delayInMs - The number of milliseconds to be delayed.\n * @param value - The value to be resolved with after a timeout of t milliseconds.\n * @param options - The options for delay - currently abort options\n * - abortSignal - The abortSignal associated with containing operation.\n * - abortErrorMsg - The abort error message associated with containing operation.\n * @returns Resolved promise\n */\nexport function delay<T>(\n delayInMs: number,\n value?: T,\n options?: {\n abortSignal?: AbortSignalLike;\n abortErrorMsg?: string;\n },\n): Promise<T | void> {\n return new Promise((resolve, reject) => {\n let timer: ReturnType<typeof setTimeout> | undefined = undefined;\n let onAborted: (() => void) | undefined = undefined;\n\n const rejectOnAbort = (): void => {\n return reject(\n new AbortError(options?.abortErrorMsg ? options?.abortErrorMsg : StandardAbortMessage),\n );\n };\n\n const removeListeners = (): void => {\n if (options?.abortSignal && onAborted) {\n options.abortSignal.removeEventListener(\"abort\", onAborted);\n }\n };\n\n onAborted = (): void => {\n if (timer) {\n clearTimeout(timer);\n }\n removeListeners();\n return rejectOnAbort();\n };\n\n if (options?.abortSignal && options.abortSignal.aborted) {\n return rejectOnAbort();\n }\n\n timer = setTimeout(() => {\n removeListeners();\n resolve(value);\n }, delayInMs);\n\n if (options?.abortSignal) {\n options.abortSignal.addEventListener(\"abort\", onAborted);\n }\n });\n}\n\n/**\n * @internal\n * @returns the parsed value or undefined if the parsed value is invalid.\n */\nexport function parseHeaderValueAsNumber(\n response: PipelineResponse,\n headerName: string,\n): number | undefined {\n const value = response.headers.get(headerName);\n if (!value) return;\n const valueAsNum = Number(value);\n if (Number.isNaN(valueAsNum)) return;\n return valueAsNum;\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/util/helpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,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AAS,CAAC,CAAC;QAEd,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAE,CAAC;YACzB,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA0B,EAC1B,UAAkB;IAElB,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;QAAE,OAAO;IACrC,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport { PipelineResponse } from \"../interfaces.js\";\n\nconst StandardAbortMessage = \"The operation was aborted.\";\n\n/**\n * A wrapper for setTimeout that resolves a promise after delayInMs milliseconds.\n * @param delayInMs - The number of milliseconds to be delayed.\n * @param value - The value to be resolved with after a timeout of t milliseconds.\n * @param options - The options for delay - currently abort options\n * - abortSignal - The abortSignal associated with containing operation.\n * - abortErrorMsg - The abort error message associated with containing operation.\n * @returns Resolved promise\n */\nexport function delay<T>(\n delayInMs: number,\n value?: T,\n options?: {\n abortSignal?: AbortSignalLike;\n abortErrorMsg?: string;\n },\n): Promise<T | void> {\n return new Promise((resolve, reject) => {\n let timer: ReturnType<typeof setTimeout> | undefined = undefined;\n let onAborted: (() => void) | undefined = undefined;\n\n const rejectOnAbort = (): void => {\n return reject(\n new AbortError(options?.abortErrorMsg ? options?.abortErrorMsg : StandardAbortMessage),\n );\n };\n\n const removeListeners = (): void => {\n if (options?.abortSignal && onAborted) {\n options.abortSignal.removeEventListener(\"abort\", onAborted);\n }\n };\n\n onAborted = (): void => {\n if (timer) {\n clearTimeout(timer);\n }\n removeListeners();\n return rejectOnAbort();\n };\n\n if (options?.abortSignal && options.abortSignal.aborted) {\n return rejectOnAbort();\n }\n\n timer = setTimeout(() => {\n removeListeners();\n resolve(value);\n }, delayInMs);\n\n if (options?.abortSignal) {\n options.abortSignal.addEventListener(\"abort\", onAborted);\n }\n });\n}\n\n/**\n * @internal\n * @returns the parsed value or undefined if the parsed value is invalid.\n */\nexport function parseHeaderValueAsNumber(\n response: PipelineResponse,\n headerName: string,\n): number | undefined {\n const value = response.headers.get(headerName);\n if (!value) return;\n const valueAsNum = Number(value);\n if (Number.isNaN(valueAsNum)) return;\n return valueAsNum;\n}\n"]}
@@ -49,8 +49,6 @@ const defaultAllowedQueryParameters = ["api-version"];
49
49
  * @internal
50
50
  */
51
51
  export class Sanitizer {
52
- allowedHeaderNames;
53
- allowedQueryParameters;
54
52
  constructor({ additionalAllowedHeaderNames: allowedHeaderNames = [], additionalAllowedQueryParameters: allowedQueryParameters = [], } = {}) {
55
53
  allowedHeaderNames = defaultAllowedHeaderNames.concat(allowedHeaderNames);
56
54
  allowedQueryParameters = defaultAllowedQueryParameters.concat(allowedQueryParameters);
@@ -62,11 +60,7 @@ export class Sanitizer {
62
60
  return JSON.stringify(obj, (key, value) => {
63
61
  // Ensure Errors include their interesting non-enumerable members
64
62
  if (value instanceof Error) {
65
- return {
66
- ...value,
67
- name: value.name,
68
- message: value.message,
69
- };
63
+ return Object.assign(Object.assign({}, value), { name: value.name, message: value.message });
70
64
  }
71
65
  if (key === "headers") {
72
66
  return this.sanitizeHeaders(value);
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizer.js","sourceRoot":"","sources":["../../../src/util/sanitizer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAiB,QAAQ,EAAE,MAAM,aAAa,CAAC;A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C;QACf,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAE3B,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,KAAK,CAAC;QACf,CAAC;QAED,KAAK,MAAM,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,YAAY,EAAE,CAAC;YACrC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;gBACxD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { UnknownObject, isObject } from \"./object.js\";\n\n/**\n * @internal\n */\nexport interface SanitizerOptions {\n /**\n * Header names whose values will be logged when logging is enabled.\n * Defaults include a list of well-known safe headers. Any headers\n * specified in this field will be added to that list. Any other values will\n * be written to logs as \"REDACTED\".\n */\n additionalAllowedHeaderNames?: string[];\n\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: string[];\n}\n\nconst RedactedString = \"REDACTED\";\n\n// Make sure this list is up-to-date with the one under core/logger/Readme#Keyconcepts\nconst defaultAllowedHeaderNames = [\n \"x-ms-client-request-id\",\n \"x-ms-return-client-request-id\",\n \"x-ms-useragent\",\n \"x-ms-correlation-request-id\",\n \"x-ms-request-id\",\n \"client-request-id\",\n \"ms-cv\",\n \"return-client-request-id\",\n \"traceparent\",\n\n \"Access-Control-Allow-Credentials\",\n \"Access-Control-Allow-Headers\",\n \"Access-Control-Allow-Methods\",\n \"Access-Control-Allow-Origin\",\n \"Access-Control-Expose-Headers\",\n \"Access-Control-Max-Age\",\n \"Access-Control-Request-Headers\",\n \"Access-Control-Request-Method\",\n \"Origin\",\n\n \"Accept\",\n \"Accept-Encoding\",\n \"Cache-Control\",\n \"Connection\",\n \"Content-Length\",\n \"Content-Type\",\n \"Date\",\n \"ETag\",\n \"Expires\",\n \"If-Match\",\n \"If-Modified-Since\",\n \"If-None-Match\",\n \"If-Unmodified-Since\",\n \"Last-Modified\",\n \"Pragma\",\n \"Request-Id\",\n \"Retry-After\",\n \"Server\",\n \"Transfer-Encoding\",\n \"User-Agent\",\n \"WWW-Authenticate\",\n];\n\nconst defaultAllowedQueryParameters: string[] = [\"api-version\"];\n\n/**\n * @internal\n */\nexport class Sanitizer {\n private allowedHeaderNames: Set<string>;\n private allowedQueryParameters: Set<string>;\n\n constructor({\n additionalAllowedHeaderNames: allowedHeaderNames = [],\n additionalAllowedQueryParameters: allowedQueryParameters = [],\n }: SanitizerOptions = {}) {\n allowedHeaderNames = defaultAllowedHeaderNames.concat(allowedHeaderNames);\n allowedQueryParameters = defaultAllowedQueryParameters.concat(allowedQueryParameters);\n\n this.allowedHeaderNames = new Set(allowedHeaderNames.map((n) => n.toLowerCase()));\n this.allowedQueryParameters = new Set(allowedQueryParameters.map((p) => p.toLowerCase()));\n }\n\n public sanitize(obj: unknown): string {\n const seen = new Set<unknown>();\n return JSON.stringify(\n obj,\n (key: string, value: unknown) => {\n // Ensure Errors include their interesting non-enumerable members\n if (value instanceof Error) {\n return {\n ...value,\n name: value.name,\n message: value.message,\n };\n }\n\n if (key === \"headers\") {\n return this.sanitizeHeaders(value as UnknownObject);\n } else if (key === \"url\") {\n return this.sanitizeUrl(value as string);\n } else if (key === \"query\") {\n return this.sanitizeQuery(value as UnknownObject);\n } else if (key === \"body\") {\n // Don't log the request body\n return undefined;\n } else if (key === \"response\") {\n // Don't log response again\n return undefined;\n } else if (key === \"operationSpec\") {\n // When using sendOperationRequest, the request carries a massive\n // field with the autorest spec. No need to log it.\n return undefined;\n } else if (Array.isArray(value) || isObject(value)) {\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n seen.add(value);\n }\n\n return value;\n },\n 2,\n );\n }\n\n private sanitizeHeaders(obj: UnknownObject): UnknownObject {\n const sanitized: UnknownObject = {};\n for (const key of Object.keys(obj)) {\n if (this.allowedHeaderNames.has(key.toLowerCase())) {\n sanitized[key] = obj[key];\n } else {\n sanitized[key] = RedactedString;\n }\n }\n return sanitized;\n }\n\n private sanitizeQuery(value: UnknownObject): UnknownObject {\n if (typeof value !== \"object\" || value === null) {\n return value;\n }\n\n const sanitized: UnknownObject = {};\n\n for (const k of Object.keys(value)) {\n if (this.allowedQueryParameters.has(k.toLowerCase())) {\n sanitized[k] = value[k];\n } else {\n sanitized[k] = RedactedString;\n }\n }\n\n return sanitized;\n }\n\n private sanitizeUrl(value: string): string {\n if (typeof value !== \"string\" || value === null) {\n return value;\n }\n\n const url = new URL(value);\n\n if (!url.search) {\n return value;\n }\n\n for (const [key] of url.searchParams) {\n if (!this.allowedQueryParameters.has(key.toLowerCase())) {\n url.searchParams.set(key, RedactedString);\n }\n }\n\n return url.toString();\n }\n}\n"]}
1
+ {"version":3,"file":"sanitizer.js","sourceRoot":"","sources":["../../../src/util/sanitizer.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAiB,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqBtD,MAAM,cAAc,GAAG,UAAU,CAAC;AAElC,sFAAsF;AACtF,MAAM,yBAAyB,GAAG;IAChC,wBAAwB;IACxB,+BAA+B;IAC/B,gBAAgB;IAChB,6BAA6B;IAC7B,iBAAiB;IACjB,mBAAmB;IACnB,OAAO;IACP,0BAA0B;IAC1B,aAAa;IAEb,kCAAkC;IAClC,8BAA8B;IAC9B,8BAA8B;IAC9B,6BAA6B;IAC7B,+BAA+B;IAC/B,wBAAwB;IACxB,gCAAgC;IAChC,+BAA+B;IAC/B,QAAQ;IAER,QAAQ;IACR,iBAAiB;IACjB,eAAe;IACf,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,MAAM;IACN,MA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yright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { UnknownObject, isObject } from \"./object.js\";\n\n/**\n * @internal\n */\nexport interface SanitizerOptions {\n /**\n * Header names whose values will be logged when logging is enabled.\n * Defaults include a list of well-known safe headers. Any headers\n * specified in this field will be added to that list. Any other values will\n * be written to logs as \"REDACTED\".\n */\n additionalAllowedHeaderNames?: string[];\n\n /**\n * Query string names whose values will be logged when logging is enabled. By default no\n * query string values are logged.\n */\n additionalAllowedQueryParameters?: string[];\n}\n\nconst RedactedString = \"REDACTED\";\n\n// Make sure this list is up-to-date with the one under core/logger/Readme#Keyconcepts\nconst defaultAllowedHeaderNames = [\n \"x-ms-client-request-id\",\n \"x-ms-return-client-request-id\",\n \"x-ms-useragent\",\n \"x-ms-correlation-request-id\",\n \"x-ms-request-id\",\n \"client-request-id\",\n \"ms-cv\",\n \"return-client-request-id\",\n \"traceparent\",\n\n \"Access-Control-Allow-Credentials\",\n \"Access-Control-Allow-Headers\",\n \"Access-Control-Allow-Methods\",\n \"Access-Control-Allow-Origin\",\n \"Access-Control-Expose-Headers\",\n \"Access-Control-Max-Age\",\n \"Access-Control-Request-Headers\",\n \"Access-Control-Request-Method\",\n \"Origin\",\n\n \"Accept\",\n \"Accept-Encoding\",\n \"Cache-Control\",\n \"Connection\",\n \"Content-Length\",\n \"Content-Type\",\n \"Date\",\n \"ETag\",\n \"Expires\",\n \"If-Match\",\n \"If-Modified-Since\",\n \"If-None-Match\",\n \"If-Unmodified-Since\",\n \"Last-Modified\",\n \"Pragma\",\n \"Request-Id\",\n \"Retry-After\",\n \"Server\",\n \"Transfer-Encoding\",\n \"User-Agent\",\n \"WWW-Authenticate\",\n];\n\nconst defaultAllowedQueryParameters: string[] = [\"api-version\"];\n\n/**\n * @internal\n */\nexport class Sanitizer {\n private allowedHeaderNames: Set<string>;\n private allowedQueryParameters: Set<string>;\n\n constructor({\n additionalAllowedHeaderNames: allowedHeaderNames = [],\n additionalAllowedQueryParameters: allowedQueryParameters = [],\n }: SanitizerOptions = {}) {\n allowedHeaderNames = defaultAllowedHeaderNames.concat(allowedHeaderNames);\n allowedQueryParameters = defaultAllowedQueryParameters.concat(allowedQueryParameters);\n\n this.allowedHeaderNames = new Set(allowedHeaderNames.map((n) => n.toLowerCase()));\n this.allowedQueryParameters = new Set(allowedQueryParameters.map((p) => p.toLowerCase()));\n }\n\n public sanitize(obj: unknown): string {\n const seen = new Set<unknown>();\n return JSON.stringify(\n obj,\n (key: string, value: unknown) => {\n // Ensure Errors include their interesting non-enumerable members\n if (value instanceof Error) {\n return {\n ...value,\n name: value.name,\n message: value.message,\n };\n }\n\n if (key === \"headers\") {\n return this.sanitizeHeaders(value as UnknownObject);\n } else if (key === \"url\") {\n return this.sanitizeUrl(value as string);\n } else if (key === \"query\") {\n return this.sanitizeQuery(value as UnknownObject);\n } else if (key === \"body\") {\n // Don't log the request body\n return undefined;\n } else if (key === \"response\") {\n // Don't log response again\n return undefined;\n } else if (key === \"operationSpec\") {\n // When using sendOperationRequest, the request carries a massive\n // field with the autorest spec. No need to log it.\n return undefined;\n } else if (Array.isArray(value) || isObject(value)) {\n if (seen.has(value)) {\n return \"[Circular]\";\n }\n seen.add(value);\n }\n\n return value;\n },\n 2,\n );\n }\n\n private sanitizeHeaders(obj: UnknownObject): UnknownObject {\n const sanitized: UnknownObject = {};\n for (const key of Object.keys(obj)) {\n if (this.allowedHeaderNames.has(key.toLowerCase())) {\n sanitized[key] = obj[key];\n } else {\n sanitized[key] = RedactedString;\n }\n }\n return sanitized;\n }\n\n private sanitizeQuery(value: UnknownObject): UnknownObject {\n if (typeof value !== \"object\" || value === null) {\n return value;\n }\n\n const sanitized: UnknownObject = {};\n\n for (const k of Object.keys(value)) {\n if (this.allowedQueryParameters.has(k.toLowerCase())) {\n sanitized[k] = value[k];\n } else {\n sanitized[k] = RedactedString;\n }\n }\n\n return sanitized;\n }\n\n private sanitizeUrl(value: string): string {\n if (typeof value !== \"string\" || value === null) {\n return value;\n }\n\n const url = new URL(value);\n\n if (!url.search) {\n return value;\n }\n\n for (const [key] of url.searchParams) {\n if (!this.allowedQueryParameters.has(key.toLowerCase())) {\n url.searchParams.set(key, RedactedString);\n }\n }\n\n return url.toString();\n }\n}\n"]}
@@ -25,7 +25,7 @@ async function beginRefresh(getAccessToken, retryIntervalInMs, refreshTimeout) {
25
25
  try {
26
26
  return await getAccessToken();
27
27
  }
28
- catch {
28
+ catch (_a) {
29
29
  return null;
30
30
  }
31
31
  }
@@ -63,10 +63,7 @@ export function createTokenCycler(credential, tokenCyclerOptions) {
63
63
  let refreshWorker = null;
64
64
  let token = null;
65
65
  let tenantId;
66
- const options = {
67
- ...DEFAULT_CYCLER_OPTIONS,
68
- ...tokenCyclerOptions,
69
- };
66
+ const options = Object.assign(Object.assign({}, DEFAULT_CYCLER_OPTIONS), tokenCyclerOptions);
70
67
  /**
71
68
  * This little holder defines several predicates that we use to construct
72
69
  * the rules of refreshing the token.
@@ -83,8 +80,9 @@ export function createTokenCycler(credential, tokenCyclerOptions) {
83
80
  * window and not already refreshing)
84
81
  */
85
82
  get shouldRefresh() {
83
+ var _a;
86
84
  return (!cycler.isRefreshing &&
87
- (token?.expiresOnTimestamp ?? 0) - options.refreshWindowInMs < Date.now());
85
+ ((_a = token === null || token === void 0 ? void 0 : token.expiresOnTimestamp) !== null && _a !== void 0 ? _a : 0) - options.refreshWindowInMs < Date.now());
88
86
  },
89
87
  /**
90
88
  * Produces true if the cycler MUST refresh (null or nearly-expired
@@ -99,6 +97,7 @@ export function createTokenCycler(credential, tokenCyclerOptions) {
99
97
  * running.
100
98
  */
101
99
  function refresh(scopes, getTokenOptions) {
100
+ var _a;
102
101
  if (!cycler.isRefreshing) {
103
102
  // We bind `scopes` here to avoid passing it around a lot
104
103
  const tryGetAccessToken = () => credential.getToken(scopes, getTokenOptions);
@@ -106,7 +105,7 @@ export function createTokenCycler(credential, tokenCyclerOptions) {
106
105
  // before the refresh can be considered done.
107
106
  refreshWorker = beginRefresh(tryGetAccessToken, options.retryIntervalInMs,
108
107
  // If we don't have a token, then we should timeout immediately
109
- token?.expiresOnTimestamp ?? Date.now())
108
+ (_a = token === null || token === void 0 ? void 0 : token.expiresOnTimestamp) !== null && _a !== void 0 ? _a : Date.now())
110
109
  .then((_token) => {
111
110
  refreshWorker = null;
112
111
  token = _token;
@@ -1 +1 @@
1
- {"version":3,"file":"tokenCycler.js","sourceRoot":"","sources":["../../../src/util/tokenCycler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAkCrC,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAuB;IACxD,uBAAuB,EAAE,IAAI,EAAE,0DAA0D;IACzF,iBAAiB,EAAE,IAAI,EAAE,kCAAkC;IAC3D,iBAAiB,EAAE,IAAI,GAAG,EAAE,GAAG,CAAC,EAAE,oCAAoC;CACvE,CAAC;AAEF;;;;;;;;;GASG;AACH,KAAK,UAAU,YAAY,CACzB,cAAiD,EACjD,iBAAyB,EACzB,cAAsB;IAEtB,4EAA4E;IAC5E,eAAe;IACf,KAAK,UAAU,iBAAiB;QAC9B,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,cAAc,EAAE,CAAC;YAChC,IAAI,CAAC;gBACH,OAAO,MAAM,cAAc,EAAE,CAAC;YAChC,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,UAAU,GAAG,MAAM,cAAc,EAAE,CAAC;YAE1C,6CAA6C;YAC7C,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;gBACxB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;YACrD,CAAC;YAED,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IAED,IAAI,KAAK,GAAuB,MAAM,iBAAiB,EAAE,CAAC;IAE1D,OAAO,KAAK,KAAK,IAAI,EAAE,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D;YAC/D,KAAK,EAAE,kBAAkB,IAAI,IAAI,CAAC,GAAG,EAAE,CACxC;iBACE,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBACf,aAAa,GAAG,IAAI,CAAC;gBACrB,KAAK,GAAG,MAAM,CAAC;gBACf,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;gBACpC,OAAO,KAAK,CAAC;YACf,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;gBAChB,sEAAsE;gBACtE,qEAAqE;gBACrE,mBAAmB;gBACnB,aAAa,GAAG,IAAI,CAAC;gBACrB,KAAK,GAAG,IAAI,CAAC;gBACb,QAAQ,GAAG,SAAS,CAAC;gBACrB,MAAM,MAAM,CAAC;YACf,CAAC,CAAC,CAAC;QACP,CAAC;QAED,OAAO,aAAqC,CAAC;IAC/C,CAAC;IAED,OAAO,KAAK,EAAE,MAAyB,EAAE,YAA6B,EAAwB,EAAE;QAC9F,EAAE;QACF,gBAAgB;QAChB,+DAA+D;QAC/D,6CAA6C;QAC7C,+DAA+D;QAC/D,yCAAyC;QACzC,6DAA6D;QAC7D,YAAY;QACZ,EAAE;QAEF,0EAA0E;QAC1E,kHAAkH;QAClH,oDAAoD;QACpD,MAAM,WAAW,GACf,QAAQ,KAAK,YAAY,CAAC,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC;QAE3F,IAAI,WAAW;YAAE,OAAO,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAEtD,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;YACzB,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,KAAoB,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken, GetTokenOptions, TokenCredential } from \"../auth/tokenCredential.js\";\nimport { delay } from \"./helpers.js\";\n\n/**\n * A function that gets a promise of an access token and allows providing\n * options.\n *\n * @param options - the options to pass to the underlying token provider\n */\nexport type AccessTokenGetter = (\n scopes: string | string[],\n options: GetTokenOptions,\n) => Promise<AccessToken>;\n\nexport interface TokenCyclerOptions {\n /**\n * The window of time before token expiration during which the token will be\n * considered unusable due to risk of the token expiring before sending the\n * request.\n *\n * This will only become meaningful if the refresh fails for over\n * (refreshWindow - forcedRefreshWindow) milliseconds.\n */\n forcedRefreshWindowInMs: number;\n /**\n * Interval in milliseconds to retry failed token refreshes.\n */\n retryIntervalInMs: number;\n /**\n * The window of time before token expiration during which\n * we will attempt to refresh the token.\n */\n refreshWindowInMs: number;\n}\n\n// Default options for the cycler if none are provided\nexport const DEFAULT_CYCLER_OPTIONS: TokenCyclerOptions = {\n forcedRefreshWindowInMs: 1000, // Force waiting for a refresh 1s before the token expires\n retryIntervalInMs: 3000, // Allow refresh attempts every 3s\n refreshWindowInMs: 1000 * 60 * 2, // Start refreshing 2m before expiry\n};\n\n/**\n * Converts an an unreliable access token getter (which may resolve with null)\n * into an AccessTokenGetter by retrying the unreliable getter in a regular\n * interval.\n *\n * @param getAccessToken - A function that produces a promise of an access token that may fail by returning null.\n * @param retryIntervalInMs - The time (in milliseconds) to wait between retry attempts.\n * @param refreshTimeout - The timestamp after which the refresh attempt will fail, throwing an exception.\n * @returns - A promise that, if it resolves, will resolve with an access token.\n */\nasync function beginRefresh(\n getAccessToken: () => Promise<AccessToken | null>,\n retryIntervalInMs: number,\n refreshTimeout: number,\n): Promise<AccessToken> {\n // This wrapper handles exceptions gracefully as long as we haven't exceeded\n // the timeout.\n async function tryGetAccessToken(): Promise<AccessToken | null> {\n if (Date.now() < refreshTimeout) {\n try {\n return await getAccessToken();\n } catch {\n return null;\n }\n } else {\n const finalToken = await getAccessToken();\n\n // Timeout is up, so throw if it's still null\n if (finalToken === null) {\n throw new Error(\"Failed to refresh access token.\");\n }\n\n return finalToken;\n }\n }\n\n let token: AccessToken | null = await tryGetAccessToken();\n\n while (token === null) {\n await delay(retryIntervalInMs);\n\n token = await tryGetAccessToken();\n }\n\n return token;\n}\n\n/**\n * Creates a token cycler from a credential, scopes, and optional settings.\n *\n * A token cycler represents a way to reliably retrieve a valid access token\n * from a TokenCredential. It will handle initializing the token, refreshing it\n * when it nears expiration, and synchronizes refresh attempts to avoid\n * concurrency hazards.\n *\n * @param credential - the underlying TokenCredential that provides the access\n * token\n * @param tokenCyclerOptions - optionally override default settings for the cycler\n *\n * @returns - a function that reliably produces a valid access token\n */\nexport function createTokenCycler(\n credential: TokenCredential,\n tokenCyclerOptions?: Partial<TokenCyclerOptions>,\n): AccessTokenGetter {\n let refreshWorker: Promise<AccessToken> | null = null;\n let token: AccessToken | null = null;\n let tenantId: string | undefined;\n\n const options = {\n ...DEFAULT_CYCLER_OPTIONS,\n ...tokenCyclerOptions,\n };\n\n /**\n * This little holder defines several predicates that we use to construct\n * the rules of refreshing the token.\n */\n const cycler = {\n /**\n * Produces true if a refresh job is currently in progress.\n */\n get isRefreshing(): boolean {\n return refreshWorker !== null;\n },\n /**\n * Produces true if the cycler SHOULD refresh (we are within the refresh\n * window and not already refreshing)\n */\n get shouldRefresh(): boolean {\n return (\n !cycler.isRefreshing &&\n (token?.expiresOnTimestamp ?? 0) - options.refreshWindowInMs < Date.now()\n );\n },\n /**\n * Produces true if the cycler MUST refresh (null or nearly-expired\n * token).\n */\n get mustRefresh(): boolean {\n return (\n token === null || token.expiresOnTimestamp - options.forcedRefreshWindowInMs < Date.now()\n );\n },\n };\n\n /**\n * Starts a refresh job or returns the existing job if one is already\n * running.\n */\n function refresh(\n scopes: string | string[],\n getTokenOptions: GetTokenOptions,\n ): Promise<AccessToken> {\n if (!cycler.isRefreshing) {\n // We bind `scopes` here to avoid passing it around a lot\n const tryGetAccessToken = (): Promise<AccessToken | null> =>\n credential.getToken(scopes, getTokenOptions);\n\n // Take advantage of promise chaining to insert an assignment to `token`\n // before the refresh can be considered done.\n refreshWorker = beginRefresh(\n tryGetAccessToken,\n options.retryIntervalInMs,\n // If we don't have a token, then we should timeout immediately\n token?.expiresOnTimestamp ?? Date.now(),\n )\n .then((_token) => {\n refreshWorker = null;\n token = _token;\n tenantId = getTokenOptions.tenantId;\n return token;\n })\n .catch((reason) => {\n // We also should reset the refresher if we enter a failed state. All\n // existing awaiters will throw, but subsequent requests will start a\n // new retry chain.\n refreshWorker = null;\n token = null;\n tenantId = undefined;\n throw reason;\n });\n }\n\n return refreshWorker as Promise<AccessToken>;\n }\n\n return async (scopes: string | string[], tokenOptions: GetTokenOptions): Promise<AccessToken> => {\n //\n // Simple rules:\n // - If we MUST refresh, then return the refresh task, blocking\n // the pipeline until a token is available.\n // - If we SHOULD refresh, then run refresh but don't return it\n // (we can still use the cached token).\n // - Return the token, since it's fine if we didn't return in\n // step 1.\n //\n\n // If the tenantId passed in token options is different to the one we have\n // Or if we are in claim challenge and the token was rejected and a new access token need to be issued, we need to\n // refresh the token with the new tenantId or token.\n const mustRefresh =\n tenantId !== tokenOptions.tenantId || Boolean(tokenOptions.claims) || cycler.mustRefresh;\n\n if (mustRefresh) return refresh(scopes, tokenOptions);\n\n if (cycler.shouldRefresh) {\n refresh(scopes, tokenOptions);\n }\n\n return token as AccessToken;\n };\n}\n"]}
1
+ {"version":3,"file":"tokenCycler.js","sourceRoot":"","sources":["../../../src/util/tokenCycler.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAkCrC,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAuB;IACxD,uBAAuB,EAAE,IAAI,EAAE,0DAA0D;IACzF,iBAAiB,EAAE,IAAI,EAAE,kCAAkC;IAC3D,iBAAiB,EAAE,IAAI,GAAG,EAAE,GAAG,CAAC,EAAE,oCAAoC;CACvE,CAAC;AAEF;;;;;;;;;GASG;AACH,KAAK,UAAU,YAAY,CACzB,cAAiD,EACjD,i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AAE;QACF,gBAAgB;QAChB,+DAA+D;QAC/D,6CAA6C;QAC7C,+DAA+D;QAC/D,yCAAyC;QACzC,6DAA6D;QAC7D,YAAY;QACZ,EAAE;QAEF,0EAA0E;QAC1E,kHAAkH;QAClH,oDAAoD;QACpD,MAAM,WAAW,GACf,QAAQ,KAAK,YAAY,CAAC,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC;QAE3F,IAAI,WAAW;YAAE,OAAO,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAEtD,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;YACzB,OAAO,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,KAAoB,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { AccessToken, GetTokenOptions, TokenCredential } from \"../auth/tokenCredential.js\";\nimport { delay } from \"./helpers.js\";\n\n/**\n * A function that gets a promise of an access token and allows providing\n * options.\n *\n * @param options - the options to pass to the underlying token provider\n */\nexport type AccessTokenGetter = (\n scopes: string | string[],\n options: GetTokenOptions,\n) => Promise<AccessToken>;\n\nexport interface TokenCyclerOptions {\n /**\n * The window of time before token expiration during which the token will be\n * considered unusable due to risk of the token expiring before sending the\n * request.\n *\n * This will only become meaningful if the refresh fails for over\n * (refreshWindow - forcedRefreshWindow) milliseconds.\n */\n forcedRefreshWindowInMs: number;\n /**\n * Interval in milliseconds to retry failed token refreshes.\n */\n retryIntervalInMs: number;\n /**\n * The window of time before token expiration during which\n * we will attempt to refresh the token.\n */\n refreshWindowInMs: number;\n}\n\n// Default options for the cycler if none are provided\nexport const DEFAULT_CYCLER_OPTIONS: TokenCyclerOptions = {\n forcedRefreshWindowInMs: 1000, // Force waiting for a refresh 1s before the token expires\n retryIntervalInMs: 3000, // Allow refresh attempts every 3s\n refreshWindowInMs: 1000 * 60 * 2, // Start refreshing 2m before expiry\n};\n\n/**\n * Converts an an unreliable access token getter (which may resolve with null)\n * into an AccessTokenGetter by retrying the unreliable getter in a regular\n * interval.\n *\n * @param getAccessToken - A function that produces a promise of an access token that may fail by returning null.\n * @param retryIntervalInMs - The time (in milliseconds) to wait between retry attempts.\n * @param refreshTimeout - The timestamp after which the refresh attempt will fail, throwing an exception.\n * @returns - A promise that, if it resolves, will resolve with an access token.\n */\nasync function beginRefresh(\n getAccessToken: () => Promise<AccessToken | null>,\n retryIntervalInMs: number,\n refreshTimeout: number,\n): Promise<AccessToken> {\n // This wrapper handles exceptions gracefully as long as we haven't exceeded\n // the timeout.\n async function tryGetAccessToken(): Promise<AccessToken | null> {\n if (Date.now() < refreshTimeout) {\n try {\n return await getAccessToken();\n } catch {\n return null;\n }\n } else {\n const finalToken = await getAccessToken();\n\n // Timeout is up, so throw if it's still null\n if (finalToken === null) {\n throw new Error(\"Failed to refresh access token.\");\n }\n\n return finalToken;\n }\n }\n\n let token: AccessToken | null = await tryGetAccessToken();\n\n while (token === null) {\n await delay(retryIntervalInMs);\n\n token = await tryGetAccessToken();\n }\n\n return token;\n}\n\n/**\n * Creates a token cycler from a credential, scopes, and optional settings.\n *\n * A token cycler represents a way to reliably retrieve a valid access token\n * from a TokenCredential. It will handle initializing the token, refreshing it\n * when it nears expiration, and synchronizes refresh attempts to avoid\n * concurrency hazards.\n *\n * @param credential - the underlying TokenCredential that provides the access\n * token\n * @param tokenCyclerOptions - optionally override default settings for the cycler\n *\n * @returns - a function that reliably produces a valid access token\n */\nexport function createTokenCycler(\n credential: TokenCredential,\n tokenCyclerOptions?: Partial<TokenCyclerOptions>,\n): AccessTokenGetter {\n let refreshWorker: Promise<AccessToken> | null = null;\n let token: AccessToken | null = null;\n let tenantId: string | undefined;\n\n const options = {\n ...DEFAULT_CYCLER_OPTIONS,\n ...tokenCyclerOptions,\n };\n\n /**\n * This little holder defines several predicates that we use to construct\n * the rules of refreshing the token.\n */\n const cycler = {\n /**\n * Produces true if a refresh job is currently in progress.\n */\n get isRefreshing(): boolean {\n return refreshWorker !== null;\n },\n /**\n * Produces true if the cycler SHOULD refresh (we are within the refresh\n * window and not already refreshing)\n */\n get shouldRefresh(): boolean {\n return (\n !cycler.isRefreshing &&\n (token?.expiresOnTimestamp ?? 0) - options.refreshWindowInMs < Date.now()\n );\n },\n /**\n * Produces true if the cycler MUST refresh (null or nearly-expired\n * token).\n */\n get mustRefresh(): boolean {\n return (\n token === null || token.expiresOnTimestamp - options.forcedRefreshWindowInMs < Date.now()\n );\n },\n };\n\n /**\n * Starts a refresh job or returns the existing job if one is already\n * running.\n */\n function refresh(\n scopes: string | string[],\n getTokenOptions: GetTokenOptions,\n ): Promise<AccessToken> {\n if (!cycler.isRefreshing) {\n // We bind `scopes` here to avoid passing it around a lot\n const tryGetAccessToken = (): Promise<AccessToken | null> =>\n credential.getToken(scopes, getTokenOptions);\n\n // Take advantage of promise chaining to insert an assignment to `token`\n // before the refresh can be considered done.\n refreshWorker = beginRefresh(\n tryGetAccessToken,\n options.retryIntervalInMs,\n // If we don't have a token, then we should timeout immediately\n token?.expiresOnTimestamp ?? Date.now(),\n )\n .then((_token) => {\n refreshWorker = null;\n token = _token;\n tenantId = getTokenOptions.tenantId;\n return token;\n })\n .catch((reason) => {\n // We also should reset the refresher if we enter a failed state. All\n // existing awaiters will throw, but subsequent requests will start a\n // new retry chain.\n refreshWorker = null;\n token = null;\n tenantId = undefined;\n throw reason;\n });\n }\n\n return refreshWorker as Promise<AccessToken>;\n }\n\n return async (scopes: string | string[], tokenOptions: GetTokenOptions): Promise<AccessToken> => {\n //\n // Simple rules:\n // - If we MUST refresh, then return the refresh task, blocking\n // the pipeline until a token is available.\n // - If we SHOULD refresh, then run refresh but don't return it\n // (we can still use the cached token).\n // - Return the token, since it's fine if we didn't return in\n // step 1.\n //\n\n // If the tenantId passed in token options is different to the one we have\n // Or if we are in claim challenge and the token was rejected and a new access token need to be issued, we need to\n // refresh the token with the new tenantId or token.\n const mustRefresh =\n tenantId !== tokenOptions.tenantId || Boolean(tokenOptions.claims) || cycler.mustRefresh;\n\n if (mustRefresh) return refresh(scopes, tokenOptions);\n\n if (cycler.shouldRefresh) {\n refresh(scopes, tokenOptions);\n }\n\n return token as AccessToken;\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"userAgentPlatform-react-native.mjs","sourceRoot":"","sources":["../../../src/util/userAgentPlatform-react-native.mts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,6DAA6D;AAC7D,gBAAgB;AAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;AAElD;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAwB;IAC9D,IAAI,QAAQ,CAAC,SAAS,EAAE,kBAAkB,EAAE,CAAC;QAC3C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,SAAS,CAAC,kBAAkB,CAAC;QACtE,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n/* @ts-ignore */\nconst { Platform } = await import(\"react-native\");\n\n/**\n * @internal\n */\nexport function getHeaderName(): string {\n return \"x-ms-useragent\";\n}\n\n/**\n * @internal\n */\nexport function setPlatformSpecificData(map: Map<string, string>): void {\n if (Platform.constants?.reactNativeVersion) {\n const { major, minor, patch } = Platform.constants.reactNativeVersion;\n map.set(\"react-native\", `${major}.${minor}.${patch}`);\n }\n map.set(\"OS\", `${Platform.OS}-${Platform.Version}`);\n}\n"]}
1
+ {"version":3,"file":"userAgentPlatform-react-native.mjs","sourceRoot":"","sources":["../../../src/util/userAgentPlatform-react-native.mts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,6DAA6D;AAC7D,gBAAgB;AAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC;AAElD;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAwB;;IAC9D,IAAI,MAAA,QAAQ,CAAC,SAAS,0CAAE,kBAAkB,EAAE,CAAC;QAC3C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,QAAQ,CAAC,SAAS,CAAC,kBAAkB,CAAC;QACtE,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,EAAE,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n/* @ts-ignore */\nconst { Platform } = await import(\"react-native\");\n\n/**\n * @internal\n */\nexport function getHeaderName(): string {\n return \"x-ms-useragent\";\n}\n\n/**\n * @internal\n */\nexport function setPlatformSpecificData(map: Map<string, string>): void {\n if (Platform.constants?.reactNativeVersion) {\n const { major, minor, patch } = Platform.constants.reactNativeVersion;\n map.set(\"react-native\", `${major}.${minor}.${patch}`);\n }\n map.set(\"OS\", `${Platform.OS}-${Platform.Version}`);\n}\n"]}
@@ -13,7 +13,8 @@ export function getHeaderName() {
13
13
  * @internal
14
14
  */
15
15
  export function setPlatformSpecificData(map) {
16
- if (Platform.constants?.reactNativeVersion) {
16
+ var _a;
17
+ if ((_a = Platform.constants) === null || _a === void 0 ? void 0 : _a.reactNativeVersion) {
17
18
  const { major, minor, patch } = Platform.constants.reactNativeVersion;
18
19
  map.set("react-native", `${major}.${minor}.${patch}`);
19
20
  }