@azure/core-rest-pipeline 1.19.2-alpha.20250417.3 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (433) hide show
  1. package/dist/browser/constants.js +1 -1
  2. package/dist/browser/constants.js.map +1 -1
  3. package/dist/browser/createPipelineFromOptions.js +2 -0
  4. package/dist/browser/createPipelineFromOptions.js.map +1 -1
  5. package/dist/browser/defaultHttpClient.d.ts +1 -1
  6. package/dist/browser/defaultHttpClient.js +21 -3
  7. package/dist/browser/defaultHttpClient.js.map +1 -0
  8. package/dist/browser/httpHeaders.js +2 -80
  9. package/dist/browser/httpHeaders.js.map +1 -1
  10. package/dist/browser/index.d.ts +1 -2
  11. package/dist/browser/index.js +1 -1
  12. package/dist/browser/index.js.map +1 -1
  13. package/dist/browser/interfaces.d.ts +11 -0
  14. package/dist/browser/interfaces.js.map +1 -1
  15. package/dist/browser/pipeline.js +2 -253
  16. package/dist/browser/pipeline.js.map +1 -1
  17. package/dist/browser/pipelineRequest.d.ts +11 -0
  18. package/dist/browser/pipelineRequest.js +5 -28
  19. package/dist/browser/pipelineRequest.js.map +1 -1
  20. package/dist/browser/policies/agentPolicy.js +3 -11
  21. package/dist/browser/policies/agentPolicy.js.map +1 -1
  22. package/dist/browser/policies/decompressResponsePolicy.d.ts +8 -4
  23. package/dist/browser/policies/decompressResponsePolicy.js +8 -7
  24. package/dist/browser/policies/decompressResponsePolicy.js.map +1 -0
  25. package/dist/browser/policies/defaultRetryPolicy.js +3 -12
  26. package/dist/browser/policies/defaultRetryPolicy.js.map +1 -1
  27. package/dist/browser/policies/exponentialRetryPolicy.js +3 -10
  28. package/dist/browser/policies/exponentialRetryPolicy.js.map +1 -1
  29. package/dist/browser/policies/formDataPolicy.js +3 -85
  30. package/dist/browser/policies/formDataPolicy.js.map +1 -1
  31. package/dist/browser/policies/logPolicy.js +3 -21
  32. package/dist/browser/policies/logPolicy.js.map +1 -1
  33. package/dist/browser/policies/multipartPolicy.js +12 -95
  34. package/dist/browser/policies/multipartPolicy.js.map +1 -1
  35. package/dist/browser/policies/proxyPolicy.d.ts +26 -2
  36. package/dist/browser/policies/proxyPolicy.js +26 -2
  37. package/dist/browser/policies/proxyPolicy.js.map +1 -0
  38. package/dist/browser/policies/redirectPolicy.js +3 -38
  39. package/dist/browser/policies/redirectPolicy.js.map +1 -1
  40. package/dist/browser/policies/retryPolicy.d.ts +59 -1
  41. package/dist/browser/policies/retryPolicy.js +5 -94
  42. package/dist/browser/policies/retryPolicy.js.map +1 -1
  43. package/dist/browser/policies/systemErrorRetryPolicy.js +3 -13
  44. package/dist/browser/policies/systemErrorRetryPolicy.js.map +1 -1
  45. package/dist/browser/policies/throttlingRetryPolicy.js +3 -11
  46. package/dist/browser/policies/throttlingRetryPolicy.js.map +1 -1
  47. package/dist/browser/policies/tlsPolicy.js +3 -11
  48. package/dist/browser/policies/tlsPolicy.js.map +1 -1
  49. package/dist/browser/policies/tracingPolicy.js +1 -1
  50. package/dist/browser/policies/tracingPolicy.js.map +1 -1
  51. package/dist/browser/policies/wrapAbortSignalLikePolicy.d.ts +10 -0
  52. package/dist/browser/policies/wrapAbortSignalLikePolicy.js +30 -0
  53. package/dist/browser/policies/wrapAbortSignalLikePolicy.js.map +1 -0
  54. package/dist/browser/restError.js +8 -27
  55. package/dist/browser/restError.js.map +1 -1
  56. package/dist/browser/util/file.d.ts +28 -2
  57. package/dist/browser/util/file.js +9 -4
  58. package/dist/browser/util/file.js.map +1 -1
  59. package/dist/browser/util/tokenCycler.js +1 -1
  60. package/dist/browser/util/tokenCycler.js.map +1 -1
  61. package/dist/browser/util/wrapAbortSignal.d.ts +12 -0
  62. package/dist/browser/util/wrapAbortSignal.js +31 -0
  63. package/dist/browser/util/wrapAbortSignal.js.map +1 -0
  64. package/dist/commonjs/constants.js +1 -1
  65. package/dist/commonjs/constants.js.map +1 -1
  66. package/dist/commonjs/createPipelineFromOptions.js +2 -0
  67. package/dist/commonjs/createPipelineFromOptions.js.map +1 -1
  68. package/dist/commonjs/defaultHttpClient.js +20 -2
  69. package/dist/commonjs/defaultHttpClient.js.map +1 -1
  70. package/dist/commonjs/httpHeaders.js +2 -80
  71. package/dist/commonjs/httpHeaders.js.map +1 -1
  72. package/dist/commonjs/index.d.ts +1 -2
  73. package/dist/commonjs/index.js.map +1 -1
  74. package/dist/commonjs/interfaces.d.ts +11 -0
  75. package/dist/commonjs/interfaces.js.map +1 -1
  76. package/dist/commonjs/pipeline.js +2 -253
  77. package/dist/commonjs/pipeline.js.map +1 -1
  78. package/dist/commonjs/pipelineRequest.d.ts +11 -0
  79. package/dist/commonjs/pipelineRequest.js +5 -28
  80. package/dist/commonjs/pipelineRequest.js.map +1 -1
  81. package/dist/commonjs/policies/agentPolicy.js +3 -11
  82. package/dist/commonjs/policies/agentPolicy.js.map +1 -1
  83. package/dist/commonjs/policies/decompressResponsePolicy.js +3 -11
  84. package/dist/commonjs/policies/decompressResponsePolicy.js.map +1 -1
  85. package/dist/commonjs/policies/defaultRetryPolicy.js +3 -12
  86. package/dist/commonjs/policies/defaultRetryPolicy.js.map +1 -1
  87. package/dist/commonjs/policies/exponentialRetryPolicy.js +3 -10
  88. package/dist/commonjs/policies/exponentialRetryPolicy.js.map +1 -1
  89. package/dist/commonjs/policies/formDataPolicy.js +3 -85
  90. package/dist/commonjs/policies/formDataPolicy.js.map +1 -1
  91. package/dist/commonjs/policies/logPolicy.js +3 -21
  92. package/dist/commonjs/policies/logPolicy.js.map +1 -1
  93. package/dist/commonjs/policies/multipartPolicy.js +12 -95
  94. package/dist/commonjs/policies/multipartPolicy.js.map +1 -1
  95. package/dist/commonjs/policies/proxyPolicy.d.ts +0 -6
  96. package/dist/commonjs/policies/proxyPolicy.js +5 -169
  97. package/dist/commonjs/policies/proxyPolicy.js.map +1 -1
  98. package/dist/commonjs/policies/redirectPolicy.js +3 -38
  99. package/dist/commonjs/policies/redirectPolicy.js.map +1 -1
  100. package/dist/commonjs/policies/retryPolicy.d.ts +59 -1
  101. package/dist/commonjs/policies/retryPolicy.js +5 -94
  102. package/dist/commonjs/policies/retryPolicy.js.map +1 -1
  103. package/dist/commonjs/policies/systemErrorRetryPolicy.js +3 -13
  104. package/dist/commonjs/policies/systemErrorRetryPolicy.js.map +1 -1
  105. package/dist/commonjs/policies/throttlingRetryPolicy.js +3 -11
  106. package/dist/commonjs/policies/throttlingRetryPolicy.js.map +1 -1
  107. package/dist/commonjs/policies/tlsPolicy.js +3 -11
  108. package/dist/commonjs/policies/tlsPolicy.js.map +1 -1
  109. package/dist/commonjs/policies/tracingPolicy.js +2 -2
  110. package/dist/commonjs/policies/tracingPolicy.js.map +1 -1
  111. package/dist/commonjs/policies/wrapAbortSignalLikePolicy.d.ts +10 -0
  112. package/dist/commonjs/policies/wrapAbortSignalLikePolicy.js +34 -0
  113. package/dist/commonjs/policies/wrapAbortSignalLikePolicy.js.map +1 -0
  114. package/dist/commonjs/restError.js +8 -27
  115. package/dist/commonjs/restError.js.map +1 -1
  116. package/dist/commonjs/tsdoc-metadata.json +1 -1
  117. package/dist/commonjs/util/file.d.ts +28 -2
  118. package/dist/commonjs/util/file.js +10 -4
  119. package/dist/commonjs/util/file.js.map +1 -1
  120. package/dist/commonjs/util/tokenCycler.js +2 -2
  121. package/dist/commonjs/util/tokenCycler.js.map +1 -1
  122. package/dist/commonjs/util/wrapAbortSignal.d.ts +12 -0
  123. package/dist/commonjs/util/wrapAbortSignal.js +34 -0
  124. package/dist/commonjs/util/wrapAbortSignal.js.map +1 -0
  125. package/dist/esm/constants.js +1 -1
  126. package/dist/esm/constants.js.map +1 -1
  127. package/dist/esm/createPipelineFromOptions.js +2 -0
  128. package/dist/esm/createPipelineFromOptions.js.map +1 -1
  129. package/dist/esm/defaultHttpClient.js +20 -2
  130. package/dist/esm/defaultHttpClient.js.map +1 -1
  131. package/dist/esm/httpHeaders.js +2 -80
  132. package/dist/esm/httpHeaders.js.map +1 -1
  133. package/dist/esm/index.d.ts +1 -2
  134. package/dist/esm/index.js +1 -1
  135. package/dist/esm/index.js.map +1 -1
  136. package/dist/esm/interfaces.d.ts +11 -0
  137. package/dist/esm/interfaces.js.map +1 -1
  138. package/dist/esm/pipeline.js +2 -253
  139. package/dist/esm/pipeline.js.map +1 -1
  140. package/dist/esm/pipelineRequest.d.ts +11 -0
  141. package/dist/esm/pipelineRequest.js +5 -28
  142. package/dist/esm/pipelineRequest.js.map +1 -1
  143. package/dist/esm/policies/agentPolicy.js +3 -11
  144. package/dist/esm/policies/agentPolicy.js.map +1 -1
  145. package/dist/esm/policies/decompressResponsePolicy.js +3 -11
  146. package/dist/esm/policies/decompressResponsePolicy.js.map +1 -1
  147. package/dist/esm/policies/defaultRetryPolicy.js +3 -12
  148. package/dist/esm/policies/defaultRetryPolicy.js.map +1 -1
  149. package/dist/esm/policies/exponentialRetryPolicy.js +3 -10
  150. package/dist/esm/policies/exponentialRetryPolicy.js.map +1 -1
  151. package/dist/esm/policies/formDataPolicy.js +3 -85
  152. package/dist/esm/policies/formDataPolicy.js.map +1 -1
  153. package/dist/esm/policies/logPolicy.js +3 -21
  154. package/dist/esm/policies/logPolicy.js.map +1 -1
  155. package/dist/esm/policies/multipartPolicy.js +12 -95
  156. package/dist/esm/policies/multipartPolicy.js.map +1 -1
  157. package/dist/esm/policies/proxyPolicy.d.ts +0 -6
  158. package/dist/esm/policies/proxyPolicy.js +4 -167
  159. package/dist/esm/policies/proxyPolicy.js.map +1 -1
  160. package/dist/esm/policies/redirectPolicy.js +3 -38
  161. package/dist/esm/policies/redirectPolicy.js.map +1 -1
  162. package/dist/esm/policies/retryPolicy.d.ts +59 -1
  163. package/dist/esm/policies/retryPolicy.js +5 -94
  164. package/dist/esm/policies/retryPolicy.js.map +1 -1
  165. package/dist/esm/policies/systemErrorRetryPolicy.js +3 -13
  166. package/dist/esm/policies/systemErrorRetryPolicy.js.map +1 -1
  167. package/dist/esm/policies/throttlingRetryPolicy.js +3 -11
  168. package/dist/esm/policies/throttlingRetryPolicy.js.map +1 -1
  169. package/dist/esm/policies/tlsPolicy.js +3 -11
  170. package/dist/esm/policies/tlsPolicy.js.map +1 -1
  171. package/dist/esm/policies/tracingPolicy.js +1 -1
  172. package/dist/esm/policies/tracingPolicy.js.map +1 -1
  173. package/dist/esm/policies/wrapAbortSignalLikePolicy.d.ts +10 -0
  174. package/dist/esm/policies/wrapAbortSignalLikePolicy.js +30 -0
  175. package/dist/esm/policies/wrapAbortSignalLikePolicy.js.map +1 -0
  176. package/dist/esm/restError.js +8 -27
  177. package/dist/esm/restError.js.map +1 -1
  178. package/dist/esm/util/file.d.ts +28 -2
  179. package/dist/esm/util/file.js +9 -4
  180. package/dist/esm/util/file.js.map +1 -1
  181. package/dist/esm/util/tokenCycler.js +1 -1
  182. package/dist/esm/util/tokenCycler.js.map +1 -1
  183. package/dist/esm/util/wrapAbortSignal.d.ts +12 -0
  184. package/dist/esm/util/wrapAbortSignal.js +31 -0
  185. package/dist/esm/util/wrapAbortSignal.js.map +1 -0
  186. package/dist/react-native/constants.js +1 -1
  187. package/dist/react-native/constants.js.map +1 -1
  188. package/dist/react-native/createPipelineFromOptions.js +2 -0
  189. package/dist/react-native/createPipelineFromOptions.js.map +1 -1
  190. package/dist/react-native/defaultHttpClient.d.ts +1 -1
  191. package/dist/react-native/defaultHttpClient.js +21 -3
  192. package/dist/react-native/defaultHttpClient.js.map +1 -0
  193. package/dist/react-native/httpHeaders.js +2 -80
  194. package/dist/react-native/httpHeaders.js.map +1 -1
  195. package/dist/react-native/index.d.ts +1 -2
  196. package/dist/react-native/index.js +1 -1
  197. package/dist/react-native/index.js.map +1 -1
  198. package/dist/react-native/interfaces.d.ts +11 -0
  199. package/dist/react-native/interfaces.js.map +1 -1
  200. package/dist/react-native/pipeline.js +2 -253
  201. package/dist/react-native/pipeline.js.map +1 -1
  202. package/dist/react-native/pipelineRequest.d.ts +11 -0
  203. package/dist/react-native/pipelineRequest.js +5 -28
  204. package/dist/react-native/pipelineRequest.js.map +1 -1
  205. package/dist/react-native/policies/agentPolicy.js +3 -11
  206. package/dist/react-native/policies/agentPolicy.js.map +1 -1
  207. package/dist/react-native/policies/decompressResponsePolicy.js +3 -11
  208. package/dist/react-native/policies/decompressResponsePolicy.js.map +1 -1
  209. package/dist/react-native/policies/defaultRetryPolicy.js +3 -12
  210. package/dist/react-native/policies/defaultRetryPolicy.js.map +1 -1
  211. package/dist/react-native/policies/exponentialRetryPolicy.js +3 -10
  212. package/dist/react-native/policies/exponentialRetryPolicy.js.map +1 -1
  213. package/dist/react-native/policies/formDataPolicy.js +3 -85
  214. package/dist/react-native/policies/formDataPolicy.js.map +1 -1
  215. package/dist/react-native/policies/logPolicy.js +3 -21
  216. package/dist/react-native/policies/logPolicy.js.map +1 -1
  217. package/dist/react-native/policies/multipartPolicy.js +12 -95
  218. package/dist/react-native/policies/multipartPolicy.js.map +1 -1
  219. package/dist/react-native/policies/proxyPolicy.d.ts +26 -2
  220. package/dist/react-native/policies/proxyPolicy.js +26 -2
  221. package/dist/react-native/policies/proxyPolicy.js.map +1 -0
  222. package/dist/react-native/policies/redirectPolicy.js +3 -38
  223. package/dist/react-native/policies/redirectPolicy.js.map +1 -1
  224. package/dist/react-native/policies/retryPolicy.d.ts +59 -1
  225. package/dist/react-native/policies/retryPolicy.js +5 -94
  226. package/dist/react-native/policies/retryPolicy.js.map +1 -1
  227. package/dist/react-native/policies/systemErrorRetryPolicy.js +3 -13
  228. package/dist/react-native/policies/systemErrorRetryPolicy.js.map +1 -1
  229. package/dist/react-native/policies/throttlingRetryPolicy.js +3 -11
  230. package/dist/react-native/policies/throttlingRetryPolicy.js.map +1 -1
  231. package/dist/react-native/policies/tlsPolicy.js +3 -11
  232. package/dist/react-native/policies/tlsPolicy.js.map +1 -1
  233. package/dist/react-native/policies/tracingPolicy.js +1 -1
  234. package/dist/react-native/policies/tracingPolicy.js.map +1 -1
  235. package/dist/react-native/policies/wrapAbortSignalLikePolicy.d.ts +10 -0
  236. package/dist/react-native/policies/wrapAbortSignalLikePolicy.js +30 -0
  237. package/dist/react-native/policies/wrapAbortSignalLikePolicy.js.map +1 -0
  238. package/dist/react-native/restError.js +8 -27
  239. package/dist/react-native/restError.js.map +1 -1
  240. package/dist/react-native/util/file.d.ts +28 -2
  241. package/dist/react-native/util/file.js +9 -4
  242. package/dist/react-native/util/file.js.map +1 -1
  243. package/dist/react-native/util/tokenCycler.js +1 -1
  244. package/dist/react-native/util/tokenCycler.js.map +1 -1
  245. package/dist/react-native/util/wrapAbortSignal.d.ts +12 -0
  246. package/dist/react-native/util/wrapAbortSignal.js +31 -0
  247. package/dist/react-native/util/wrapAbortSignal.js.map +1 -0
  248. package/package.json +5 -6
  249. package/dist/browser/accessTokenCache.d.ts +0 -40
  250. package/dist/browser/accessTokenCache.js +0 -32
  251. package/dist/browser/accessTokenCache.js.map +0 -1
  252. package/dist/browser/defaultHttpClient-browser.mjs.map +0 -1
  253. package/dist/browser/fetchHttpClient.d.ts +0 -7
  254. package/dist/browser/fetchHttpClient.js +0 -256
  255. package/dist/browser/fetchHttpClient.js.map +0 -1
  256. package/dist/browser/nodeHttpClient.d.ts +0 -9
  257. package/dist/browser/nodeHttpClient.js +0 -348
  258. package/dist/browser/nodeHttpClient.js.map +0 -1
  259. package/dist/browser/policies/decompressResponsePolicy-browser.mjs.map +0 -1
  260. package/dist/browser/policies/proxyPolicy-browser.mjs.map +0 -1
  261. package/dist/browser/policies/proxyPolicy.common.d.ts +0 -15
  262. package/dist/browser/policies/proxyPolicy.common.js +0 -24
  263. package/dist/browser/policies/proxyPolicy.common.js.map +0 -1
  264. package/dist/browser/retryStrategies/exponentialRetryStrategy.d.ts +0 -40
  265. package/dist/browser/retryStrategies/exponentialRetryStrategy.js +0 -64
  266. package/dist/browser/retryStrategies/exponentialRetryStrategy.js.map +0 -1
  267. package/dist/browser/retryStrategies/retryStrategy.d.ts +0 -61
  268. package/dist/browser/retryStrategies/retryStrategy.js +0 -4
  269. package/dist/browser/retryStrategies/retryStrategy.js.map +0 -1
  270. package/dist/browser/retryStrategies/throttlingRetryStrategy.d.ts +0 -9
  271. package/dist/browser/retryStrategies/throttlingRetryStrategy.js +0 -74
  272. package/dist/browser/retryStrategies/throttlingRetryStrategy.js.map +0 -1
  273. package/dist/browser/util/concat-browser.mjs.map +0 -1
  274. package/dist/browser/util/concat.common.d.ts +0 -18
  275. package/dist/browser/util/concat.common.js +0 -45
  276. package/dist/browser/util/concat.common.js.map +0 -1
  277. package/dist/browser/util/concat.d.ts +0 -2
  278. package/dist/browser/util/concat.js +0 -4
  279. package/dist/browser/util/helpers.d.ts +0 -21
  280. package/dist/browser/util/helpers.js +0 -58
  281. package/dist/browser/util/helpers.js.map +0 -1
  282. package/dist/browser/util/inspect-browser.mjs.map +0 -1
  283. package/dist/browser/util/inspect.common.d.ts +0 -2
  284. package/dist/browser/util/inspect.common.js +0 -4
  285. package/dist/browser/util/inspect.common.js.map +0 -1
  286. package/dist/browser/util/inspect.d.ts +0 -2
  287. package/dist/browser/util/inspect.js +0 -4
  288. package/dist/browser/util/sanitizer.d.ts +0 -30
  289. package/dist/browser/util/sanitizer.js +0 -139
  290. package/dist/browser/util/sanitizer.js.map +0 -1
  291. package/dist/browser/util/typeGuards.d.ts +0 -5
  292. package/dist/browser/util/typeGuards.js +0 -17
  293. package/dist/browser/util/typeGuards.js.map +0 -1
  294. package/dist/browser/xhrHttpClient.d.ts +0 -7
  295. package/dist/browser/xhrHttpClient.js +0 -167
  296. package/dist/browser/xhrHttpClient.js.map +0 -1
  297. package/dist/commonjs/accessTokenCache.d.ts +0 -40
  298. package/dist/commonjs/accessTokenCache.js +0 -36
  299. package/dist/commonjs/accessTokenCache.js.map +0 -1
  300. package/dist/commonjs/fetchHttpClient.d.ts +0 -7
  301. package/dist/commonjs/fetchHttpClient.js +0 -259
  302. package/dist/commonjs/fetchHttpClient.js.map +0 -1
  303. package/dist/commonjs/nodeHttpClient.d.ts +0 -9
  304. package/dist/commonjs/nodeHttpClient.js +0 -353
  305. package/dist/commonjs/nodeHttpClient.js.map +0 -1
  306. package/dist/commonjs/policies/proxyPolicy.common.d.ts +0 -15
  307. package/dist/commonjs/policies/proxyPolicy.common.js +0 -30
  308. package/dist/commonjs/policies/proxyPolicy.common.js.map +0 -1
  309. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.d.ts +0 -40
  310. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js +0 -69
  311. package/dist/commonjs/retryStrategies/exponentialRetryStrategy.js.map +0 -1
  312. package/dist/commonjs/retryStrategies/retryStrategy.d.ts +0 -61
  313. package/dist/commonjs/retryStrategies/retryStrategy.js +0 -5
  314. package/dist/commonjs/retryStrategies/retryStrategy.js.map +0 -1
  315. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.d.ts +0 -9
  316. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js +0 -78
  317. package/dist/commonjs/retryStrategies/throttlingRetryStrategy.js.map +0 -1
  318. package/dist/commonjs/util/concat.common.d.ts +0 -18
  319. package/dist/commonjs/util/concat.common.js +0 -48
  320. package/dist/commonjs/util/concat.common.js.map +0 -1
  321. package/dist/commonjs/util/concat.d.ts +0 -17
  322. package/dist/commonjs/util/concat.js +0 -91
  323. package/dist/commonjs/util/concat.js.map +0 -1
  324. package/dist/commonjs/util/helpers.d.ts +0 -21
  325. package/dist/commonjs/util/helpers.js +0 -62
  326. package/dist/commonjs/util/helpers.js.map +0 -1
  327. package/dist/commonjs/util/inspect.common.d.ts +0 -2
  328. package/dist/commonjs/util/inspect.common.js +0 -7
  329. package/dist/commonjs/util/inspect.common.js.map +0 -1
  330. package/dist/commonjs/util/inspect.d.ts +0 -2
  331. package/dist/commonjs/util/inspect.js +0 -8
  332. package/dist/commonjs/util/inspect.js.map +0 -1
  333. package/dist/commonjs/util/sanitizer.d.ts +0 -30
  334. package/dist/commonjs/util/sanitizer.js +0 -143
  335. package/dist/commonjs/util/sanitizer.js.map +0 -1
  336. package/dist/commonjs/util/typeGuards.d.ts +0 -5
  337. package/dist/commonjs/util/typeGuards.js +0 -23
  338. package/dist/commonjs/util/typeGuards.js.map +0 -1
  339. package/dist/commonjs/xhrHttpClient.d.ts +0 -7
  340. package/dist/commonjs/xhrHttpClient.js +0 -170
  341. package/dist/commonjs/xhrHttpClient.js.map +0 -1
  342. package/dist/esm/accessTokenCache.d.ts +0 -40
  343. package/dist/esm/accessTokenCache.js +0 -32
  344. package/dist/esm/accessTokenCache.js.map +0 -1
  345. package/dist/esm/fetchHttpClient.d.ts +0 -7
  346. package/dist/esm/fetchHttpClient.js +0 -256
  347. package/dist/esm/fetchHttpClient.js.map +0 -1
  348. package/dist/esm/nodeHttpClient.d.ts +0 -9
  349. package/dist/esm/nodeHttpClient.js +0 -348
  350. package/dist/esm/nodeHttpClient.js.map +0 -1
  351. package/dist/esm/policies/proxyPolicy.common.d.ts +0 -15
  352. package/dist/esm/policies/proxyPolicy.common.js +0 -24
  353. package/dist/esm/policies/proxyPolicy.common.js.map +0 -1
  354. package/dist/esm/retryStrategies/exponentialRetryStrategy.d.ts +0 -40
  355. package/dist/esm/retryStrategies/exponentialRetryStrategy.js +0 -64
  356. package/dist/esm/retryStrategies/exponentialRetryStrategy.js.map +0 -1
  357. package/dist/esm/retryStrategies/retryStrategy.d.ts +0 -61
  358. package/dist/esm/retryStrategies/retryStrategy.js +0 -4
  359. package/dist/esm/retryStrategies/retryStrategy.js.map +0 -1
  360. package/dist/esm/retryStrategies/throttlingRetryStrategy.d.ts +0 -9
  361. package/dist/esm/retryStrategies/throttlingRetryStrategy.js +0 -74
  362. package/dist/esm/retryStrategies/throttlingRetryStrategy.js.map +0 -1
  363. package/dist/esm/util/concat.common.d.ts +0 -18
  364. package/dist/esm/util/concat.common.js +0 -45
  365. package/dist/esm/util/concat.common.js.map +0 -1
  366. package/dist/esm/util/concat.d.ts +0 -17
  367. package/dist/esm/util/concat.js +0 -88
  368. package/dist/esm/util/concat.js.map +0 -1
  369. package/dist/esm/util/helpers.d.ts +0 -21
  370. package/dist/esm/util/helpers.js +0 -58
  371. package/dist/esm/util/helpers.js.map +0 -1
  372. package/dist/esm/util/inspect.common.d.ts +0 -2
  373. package/dist/esm/util/inspect.common.js +0 -4
  374. package/dist/esm/util/inspect.common.js.map +0 -1
  375. package/dist/esm/util/inspect.d.ts +0 -2
  376. package/dist/esm/util/inspect.js +0 -5
  377. package/dist/esm/util/inspect.js.map +0 -1
  378. package/dist/esm/util/sanitizer.d.ts +0 -30
  379. package/dist/esm/util/sanitizer.js +0 -139
  380. package/dist/esm/util/sanitizer.js.map +0 -1
  381. package/dist/esm/util/typeGuards.d.ts +0 -5
  382. package/dist/esm/util/typeGuards.js +0 -17
  383. package/dist/esm/util/typeGuards.js.map +0 -1
  384. package/dist/esm/xhrHttpClient.d.ts +0 -7
  385. package/dist/esm/xhrHttpClient.js +0 -167
  386. package/dist/esm/xhrHttpClient.js.map +0 -1
  387. package/dist/react-native/accessTokenCache.d.ts +0 -40
  388. package/dist/react-native/accessTokenCache.js +0 -32
  389. package/dist/react-native/accessTokenCache.js.map +0 -1
  390. package/dist/react-native/defaultHttpClient-react-native.mjs.map +0 -1
  391. package/dist/react-native/fetchHttpClient.d.ts +0 -7
  392. package/dist/react-native/fetchHttpClient.js +0 -256
  393. package/dist/react-native/fetchHttpClient.js.map +0 -1
  394. package/dist/react-native/nodeHttpClient.d.ts +0 -9
  395. package/dist/react-native/nodeHttpClient.js +0 -348
  396. package/dist/react-native/nodeHttpClient.js.map +0 -1
  397. package/dist/react-native/policies/proxyPolicy-react-native.mjs.map +0 -1
  398. package/dist/react-native/policies/proxyPolicy.common.d.ts +0 -15
  399. package/dist/react-native/policies/proxyPolicy.common.js +0 -24
  400. package/dist/react-native/policies/proxyPolicy.common.js.map +0 -1
  401. package/dist/react-native/retryStrategies/exponentialRetryStrategy.d.ts +0 -40
  402. package/dist/react-native/retryStrategies/exponentialRetryStrategy.js +0 -64
  403. package/dist/react-native/retryStrategies/exponentialRetryStrategy.js.map +0 -1
  404. package/dist/react-native/retryStrategies/retryStrategy.d.ts +0 -61
  405. package/dist/react-native/retryStrategies/retryStrategy.js +0 -4
  406. package/dist/react-native/retryStrategies/retryStrategy.js.map +0 -1
  407. package/dist/react-native/retryStrategies/throttlingRetryStrategy.d.ts +0 -9
  408. package/dist/react-native/retryStrategies/throttlingRetryStrategy.js +0 -74
  409. package/dist/react-native/retryStrategies/throttlingRetryStrategy.js.map +0 -1
  410. package/dist/react-native/util/concat-react-native.mjs.map +0 -1
  411. package/dist/react-native/util/concat.common.d.ts +0 -18
  412. package/dist/react-native/util/concat.common.js +0 -45
  413. package/dist/react-native/util/concat.common.js.map +0 -1
  414. package/dist/react-native/util/concat.d.ts +0 -2
  415. package/dist/react-native/util/concat.js +0 -4
  416. package/dist/react-native/util/helpers.d.ts +0 -21
  417. package/dist/react-native/util/helpers.js +0 -58
  418. package/dist/react-native/util/helpers.js.map +0 -1
  419. package/dist/react-native/util/inspect-react-native.mjs.map +0 -1
  420. package/dist/react-native/util/inspect.common.d.ts +0 -2
  421. package/dist/react-native/util/inspect.common.js +0 -4
  422. package/dist/react-native/util/inspect.common.js.map +0 -1
  423. package/dist/react-native/util/inspect.d.ts +0 -2
  424. package/dist/react-native/util/inspect.js +0 -4
  425. package/dist/react-native/util/sanitizer.d.ts +0 -30
  426. package/dist/react-native/util/sanitizer.js +0 -139
  427. package/dist/react-native/util/sanitizer.js.map +0 -1
  428. package/dist/react-native/util/typeGuards.d.ts +0 -5
  429. package/dist/react-native/util/typeGuards.js +0 -17
  430. package/dist/react-native/util/typeGuards.js.map +0 -1
  431. package/dist/react-native/xhrHttpClient.d.ts +0 -7
  432. package/dist/react-native/xhrHttpClient.js +0 -167
  433. package/dist/react-native/xhrHttpClient.js.map +0 -1
@@ -4,23 +4,15 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.tlsPolicyName = void 0;
6
6
  exports.tlsPolicy = tlsPolicy;
7
+ const policies_1 = require("@typespec/ts-http-runtime/internal/policies");
7
8
  /**
8
9
  * Name of the TLS Policy
9
10
  */
10
- exports.tlsPolicyName = "tlsPolicy";
11
+ exports.tlsPolicyName = policies_1.tlsPolicyName;
11
12
  /**
12
13
  * Gets a pipeline policy that adds the client certificate to the HttpClient agent for authentication.
13
14
  */
14
15
  function tlsPolicy(tlsSettings) {
15
- return {
16
- name: exports.tlsPolicyName,
17
- sendRequest: async (req, next) => {
18
- // Users may define a request tlsSettings, honor those over the client level one
19
- if (!req.tlsSettings) {
20
- req.tlsSettings = tlsSettings;
21
- }
22
- return next(req);
23
- },
24
- };
16
+ return (0, policies_1.tlsPolicy)(tlsSettings);
25
17
  }
26
18
  //# sourceMappingURL=tlsPolicy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tlsPolicy.js","sourceRoot":"","sources":["../../../src/policies/tlsPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAalC,8BAWC;AAnBD;;GAEG;AACU,QAAA,aAAa,GAAG,WAAW,CAAC;AAEzC;;GAEG;AACH,SAAgB,SAAS,CAAC,WAAyB;IACjD,OAAO;QACL,IAAI,EAAE,qBAAa;QACnB,WAAW,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;YAC/B,gFAAgF;YAChF,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;gBACrB,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;YAChC,CAAC;YACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport type { TlsSettings } from \"../interfaces.js\";\n\n/**\n * Name of the TLS Policy\n */\nexport const tlsPolicyName = \"tlsPolicy\";\n\n/**\n * Gets a pipeline policy that adds the client certificate to the HttpClient agent for authentication.\n */\nexport function tlsPolicy(tlsSettings?: TlsSettings): PipelinePolicy {\n return {\n name: tlsPolicyName,\n sendRequest: async (req, next) => {\n // Users may define a request tlsSettings, honor those over the client level one\n if (!req.tlsSettings) {\n req.tlsSettings = tlsSettings;\n }\n return next(req);\n },\n };\n}\n"]}
1
+ {"version":3,"file":"tlsPolicy.js","sourceRoot":"","sources":["../../../src/policies/tlsPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAkBlC,8BAEC;AAfD,0EAGqD;AAErD;;GAEG;AACU,QAAA,aAAa,GAAG,wBAAgB,CAAC;AAE9C;;GAEG;AACH,SAAgB,SAAS,CAAC,WAAyB;IACjD,OAAO,IAAA,oBAAY,EAAC,WAAW,CAAC,CAAC;AACnC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport type { TlsSettings } from \"../interfaces.js\";\n\nimport {\n tlsPolicy as tspTlsPolicy,\n tlsPolicyName as tspTlsPolicyName,\n} from \"@typespec/ts-http-runtime/internal/policies\";\n\n/**\n * Name of the TLS Policy\n */\nexport const tlsPolicyName = tspTlsPolicyName;\n\n/**\n * Gets a pipeline policy that adds the client certificate to the HttpClient agent for authentication.\n */\nexport function tlsPolicy(tlsSettings?: TlsSettings): PipelinePolicy {\n return tspTlsPolicy(tlsSettings);\n}\n"]}
@@ -10,7 +10,7 @@ const userAgent_js_1 = require("../util/userAgent.js");
10
10
  const log_js_1 = require("../log.js");
11
11
  const core_util_1 = require("@azure/core-util");
12
12
  const restError_js_1 = require("../restError.js");
13
- const sanitizer_js_1 = require("../util/sanitizer.js");
13
+ const util_1 = require("@typespec/ts-http-runtime/internal/util");
14
14
  /**
15
15
  * The programmatic identifier of the tracingPolicy.
16
16
  */
@@ -23,7 +23,7 @@ exports.tracingPolicyName = "tracingPolicy";
23
23
  */
24
24
  function tracingPolicy(options = {}) {
25
25
  const userAgentPromise = (0, userAgent_js_1.getUserAgentValue)(options.userAgentPrefix);
26
- const sanitizer = new sanitizer_js_1.Sanitizer({
26
+ const sanitizer = new util_1.Sanitizer({
27
27
  additionalAllowedQueryParameters: options.additionalAllowedQueryParameters,
28
28
  });
29
29
  const tracingClient = tryCreateTracingClient();
@@ -1 +1 @@
1
- {"version":3,"file":"tracingPolicy.js","sourceRoot":"","sources":["../../../src/policies/tracingPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA6ClC,sCA0CC;AArFD,sDAK6B;AAC7B,kDAA8C;AAG9C,uDAAyD;AACzD,sCAAmC;AACnC,gDAA4D;AAC5D,kDAA8C;AAC9C,uDAAiD;AAEjD;;GAEG;AACU,QAAA,iBAAiB,GAAG,eAAe,CAAC;AAmBjD;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,UAAgC,EAAE;IAC9D,MAAM,gBAAgB,GAAG,IAAA,gCAAiB,EAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,IAAI,wBAAS,CAAC;QAC9B,gCAAgC,EAAE,OAAO,CAAC,gCAAgC;KAC3E,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,sBAAsB,EAAE,CAAC;IAE/C,OAAO;QACL,IAAI,EAAE,yBAAiB;QACvB,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;;YAC3D,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YAED,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC;YAEzC,MAAM,cAAc,GAAG;gBACrB,UAAU,EAAE,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC;gBAC9C,aAAa,EAAE,OAAO,CAAC,MAAM;gBAC7B,iBAAiB,EAAE,SAAS;gBAC5B,SAAS,EAAE,OAAO,CAAC,SAAS;aAC7B,CAAC;YACF,IAAI,SAAS,EAAE,CAAC;gBACd,cAAc,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;YAChD,CAAC;YAED,MAAM,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CAAC;IAC5F,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAiB,EAAE,QAA0B;IACvE,IAAI,CAAC;QACH,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QACvD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACjE,IAAI,gBAAgB,EAAE,CAAC;YACrB,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAC;QAC1D,CAAC;QACD,2FAA2F;QAC3F,2CAA2C;QAC3C,sEAAsE;QACtE,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YAC3B,IAAI,CAAC,SAAS,CAAC;gBACb,MAAM,EAAE,OAAO;aAChB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,eAAM,CAAC,OAAO,CAAC,qDAAqD,IAAA,2BAAe,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n type TracingClient,\n type TracingContext,\n type TracingSpan,\n createTracingClient,\n} from \"@azure/core-tracing\";\nimport { SDK_VERSION } from \"../constants.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { getUserAgentValue } from \"../util/userAgent.js\";\nimport { logger } from \"../log.js\";\nimport { getErrorMessage, isError } from \"@azure/core-util\";\nimport { isRestError } from \"../restError.js\";\nimport { Sanitizer } from \"../util/sanitizer.js\";\n\n/**\n * The programmatic identifier of the tracingPolicy.\n */\nexport const tracingPolicyName = \"tracingPolicy\";\n\n/**\n * Options to configure the tracing policy.\n */\nexport interface TracingPolicyOptions {\n /**\n * String prefix to add to the user agent logged as metadata\n * on the generated Span.\n * Defaults to an empty string.\n */\n userAgentPrefix?: string;\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\n/**\n * A simple policy to create OpenTelemetry Spans for each request made by the pipeline\n * that has SpanOptions with a parent.\n * Requests made without a parent Span will not be recorded.\n * @param options - Options to configure the telemetry logged by the tracing policy.\n */\nexport function tracingPolicy(options: TracingPolicyOptions = {}): PipelinePolicy {\n const userAgentPromise = getUserAgentValue(options.userAgentPrefix);\n const sanitizer = new Sanitizer({\n additionalAllowedQueryParameters: options.additionalAllowedQueryParameters,\n });\n const tracingClient = tryCreateTracingClient();\n\n return {\n name: tracingPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (!tracingClient) {\n return next(request);\n }\n\n const userAgent = await userAgentPromise;\n\n const spanAttributes = {\n \"http.url\": sanitizer.sanitizeUrl(request.url),\n \"http.method\": request.method,\n \"http.user_agent\": userAgent,\n requestId: request.requestId,\n };\n if (userAgent) {\n spanAttributes[\"http.user_agent\"] = userAgent;\n }\n\n const { span, tracingContext } = tryCreateSpan(tracingClient, request, spanAttributes) ?? {};\n\n if (!span || !tracingContext) {\n return next(request);\n }\n\n try {\n const response = await tracingClient.withContext(tracingContext, next, request);\n tryProcessResponse(span, response);\n return response;\n } catch (err: any) {\n tryProcessError(span, err);\n throw err;\n }\n },\n };\n}\n\nfunction tryCreateTracingClient(): TracingClient | undefined {\n try {\n return createTracingClient({\n namespace: \"\",\n packageName: \"@azure/core-rest-pipeline\",\n packageVersion: SDK_VERSION,\n });\n } catch (e: unknown) {\n logger.warning(`Error when creating the TracingClient: ${getErrorMessage(e)}`);\n return undefined;\n }\n}\n\nfunction tryCreateSpan(\n tracingClient: TracingClient,\n request: PipelineRequest,\n spanAttributes: Record<string, unknown>,\n): { span: TracingSpan; tracingContext: TracingContext } | undefined {\n try {\n // As per spec, we do not need to differentiate between HTTP and HTTPS in span name.\n const { span, updatedOptions } = tracingClient.startSpan(\n `HTTP ${request.method}`,\n { tracingOptions: request.tracingOptions },\n {\n spanKind: \"client\",\n spanAttributes,\n },\n );\n\n // If the span is not recording, don't do any more work.\n if (!span.isRecording()) {\n span.end();\n return undefined;\n }\n\n // set headers\n const headers = tracingClient.createRequestHeaders(\n updatedOptions.tracingOptions.tracingContext,\n );\n for (const [key, value] of Object.entries(headers)) {\n request.headers.set(key, value);\n }\n return { span, tracingContext: updatedOptions.tracingOptions.tracingContext };\n } catch (e: any) {\n logger.warning(`Skipping creating a tracing span due to an error: ${getErrorMessage(e)}`);\n return undefined;\n }\n}\n\nfunction tryProcessError(span: TracingSpan, error: unknown): void {\n try {\n span.setStatus({\n status: \"error\",\n error: isError(error) ? error : undefined,\n });\n if (isRestError(error) && error.statusCode) {\n span.setAttribute(\"http.status_code\", error.statusCode);\n }\n span.end();\n } catch (e: any) {\n logger.warning(`Skipping tracing span processing due to an error: ${getErrorMessage(e)}`);\n }\n}\n\nfunction tryProcessResponse(span: TracingSpan, response: PipelineResponse): void {\n try {\n span.setAttribute(\"http.status_code\", response.status);\n const serviceRequestId = response.headers.get(\"x-ms-request-id\");\n if (serviceRequestId) {\n span.setAttribute(\"serviceRequestId\", serviceRequestId);\n }\n // Per semantic conventions, only set the status to error if the status code is 4xx or 5xx.\n // Otherwise, the status MUST remain unset.\n // https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status\n if (response.status >= 400) {\n span.setStatus({\n status: \"error\",\n });\n }\n span.end();\n } catch (e: any) {\n logger.warning(`Skipping tracing span processing due to an error: ${getErrorMessage(e)}`);\n }\n}\n"]}
1
+ {"version":3,"file":"tracingPolicy.js","sourceRoot":"","sources":["../../../src/policies/tracingPolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AA6ClC,sCA0CC;AArFD,sDAK6B;AAC7B,kDAA8C;AAG9C,uDAAyD;AACzD,sCAAmC;AACnC,gD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kB,EAAE,gBAAgB,CAAC,CAAC;QAC1D,CAAC;QACD,2FAA2F;QAC3F,2CAA2C;QAC3C,sEAAsE;QACtE,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YAC3B,IAAI,CAAC,SAAS,CAAC;gBACb,MAAM,EAAE,OAAO;aAChB,CAAC,CAAC;QACL,CAAC;QACD,IAAI,CAAC,GAAG,EAAE,CAAC;IACb,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,eAAM,CAAC,OAAO,CAAC,qDAAqD,IAAA,2BAAe,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5F,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport {\n type TracingClient,\n type TracingContext,\n type TracingSpan,\n createTracingClient,\n} from \"@azure/core-tracing\";\nimport { SDK_VERSION } from \"../constants.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../interfaces.js\";\nimport type { PipelinePolicy } from \"../pipeline.js\";\nimport { getUserAgentValue } from \"../util/userAgent.js\";\nimport { logger } from \"../log.js\";\nimport { getErrorMessage, isError } from \"@azure/core-util\";\nimport { isRestError } from \"../restError.js\";\nimport { Sanitizer } from \"@typespec/ts-http-runtime/internal/util\";\n\n/**\n * The programmatic identifier of the tracingPolicy.\n */\nexport const tracingPolicyName = \"tracingPolicy\";\n\n/**\n * Options to configure the tracing policy.\n */\nexport interface TracingPolicyOptions {\n /**\n * String prefix to add to the user agent logged as metadata\n * on the generated Span.\n * Defaults to an empty string.\n */\n userAgentPrefix?: string;\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\n/**\n * A simple policy to create OpenTelemetry Spans for each request made by the pipeline\n * that has SpanOptions with a parent.\n * Requests made without a parent Span will not be recorded.\n * @param options - Options to configure the telemetry logged by the tracing policy.\n */\nexport function tracingPolicy(options: TracingPolicyOptions = {}): PipelinePolicy {\n const userAgentPromise = getUserAgentValue(options.userAgentPrefix);\n const sanitizer = new Sanitizer({\n additionalAllowedQueryParameters: options.additionalAllowedQueryParameters,\n });\n const tracingClient = tryCreateTracingClient();\n\n return {\n name: tracingPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n if (!tracingClient) {\n return next(request);\n }\n\n const userAgent = await userAgentPromise;\n\n const spanAttributes = {\n \"http.url\": sanitizer.sanitizeUrl(request.url),\n \"http.method\": request.method,\n \"http.user_agent\": userAgent,\n requestId: request.requestId,\n };\n if (userAgent) {\n spanAttributes[\"http.user_agent\"] = userAgent;\n }\n\n const { span, tracingContext } = tryCreateSpan(tracingClient, request, spanAttributes) ?? {};\n\n if (!span || !tracingContext) {\n return next(request);\n }\n\n try {\n const response = await tracingClient.withContext(tracingContext, next, request);\n tryProcessResponse(span, response);\n return response;\n } catch (err: any) {\n tryProcessError(span, err);\n throw err;\n }\n },\n };\n}\n\nfunction tryCreateTracingClient(): TracingClient | undefined {\n try {\n return createTracingClient({\n namespace: \"\",\n packageName: \"@azure/core-rest-pipeline\",\n packageVersion: SDK_VERSION,\n });\n } catch (e: unknown) {\n logger.warning(`Error when creating the TracingClient: ${getErrorMessage(e)}`);\n return undefined;\n }\n}\n\nfunction tryCreateSpan(\n tracingClient: TracingClient,\n request: PipelineRequest,\n spanAttributes: Record<string, unknown>,\n): { span: TracingSpan; tracingContext: TracingContext } | undefined {\n try {\n // As per spec, we do not need to differentiate between HTTP and HTTPS in span name.\n const { span, updatedOptions } = tracingClient.startSpan(\n `HTTP ${request.method}`,\n { tracingOptions: request.tracingOptions },\n {\n spanKind: \"client\",\n spanAttributes,\n },\n );\n\n // If the span is not recording, don't do any more work.\n if (!span.isRecording()) {\n span.end();\n return undefined;\n }\n\n // set headers\n const headers = tracingClient.createRequestHeaders(\n updatedOptions.tracingOptions.tracingContext,\n );\n for (const [key, value] of Object.entries(headers)) {\n request.headers.set(key, value);\n }\n return { span, tracingContext: updatedOptions.tracingOptions.tracingContext };\n } catch (e: any) {\n logger.warning(`Skipping creating a tracing span due to an error: ${getErrorMessage(e)}`);\n return undefined;\n }\n}\n\nfunction tryProcessError(span: TracingSpan, error: unknown): void {\n try {\n span.setStatus({\n status: \"error\",\n error: isError(error) ? error : undefined,\n });\n if (isRestError(error) && error.statusCode) {\n span.setAttribute(\"http.status_code\", error.statusCode);\n }\n span.end();\n } catch (e: any) {\n logger.warning(`Skipping tracing span processing due to an error: ${getErrorMessage(e)}`);\n }\n}\n\nfunction tryProcessResponse(span: TracingSpan, response: PipelineResponse): void {\n try {\n span.setAttribute(\"http.status_code\", response.status);\n const serviceRequestId = response.headers.get(\"x-ms-request-id\");\n if (serviceRequestId) {\n span.setAttribute(\"serviceRequestId\", serviceRequestId);\n }\n // Per semantic conventions, only set the status to error if the status code is 4xx or 5xx.\n // Otherwise, the status MUST remain unset.\n // https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status\n if (response.status >= 400) {\n span.setStatus({\n status: \"error\",\n });\n }\n span.end();\n } catch (e: any) {\n logger.warning(`Skipping tracing span processing due to an error: ${getErrorMessage(e)}`);\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { type PipelinePolicy } from "../pipeline.js";
2
+ export declare const wrapAbortSignalLikePolicyName = "wrapAbortSignalLikePolicy";
3
+ /**
4
+ * Policy that ensure that any AbortSignalLike is wrapped in a native AbortSignal for processing by the pipeline.
5
+ * Since the ts-http-runtime expects a native AbortSignal, this policy is used to ensure that any AbortSignalLike is wrapped in a native AbortSignal.
6
+ *
7
+ * @returns - created policy
8
+ */
9
+ export declare function wrapAbortSignalLikePolicy(): PipelinePolicy;
10
+ //# sourceMappingURL=wrapAbortSignalLikePolicy.d.ts.map
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.wrapAbortSignalLikePolicyName = void 0;
6
+ exports.wrapAbortSignalLikePolicy = wrapAbortSignalLikePolicy;
7
+ const wrapAbortSignal_js_1 = require("../util/wrapAbortSignal.js");
8
+ exports.wrapAbortSignalLikePolicyName = "wrapAbortSignalLikePolicy";
9
+ /**
10
+ * Policy that ensure that any AbortSignalLike is wrapped in a native AbortSignal for processing by the pipeline.
11
+ * Since the ts-http-runtime expects a native AbortSignal, this policy is used to ensure that any AbortSignalLike is wrapped in a native AbortSignal.
12
+ *
13
+ * @returns - created policy
14
+ */
15
+ function wrapAbortSignalLikePolicy() {
16
+ return {
17
+ name: exports.wrapAbortSignalLikePolicyName,
18
+ sendRequest: async (request, next) => {
19
+ if (!request.abortSignal) {
20
+ return next(request);
21
+ }
22
+ const { abortSignal, cleanup } = (0, wrapAbortSignal_js_1.wrapAbortSignalLike)(request.abortSignal);
23
+ // eslint-disable-next-line no-param-reassign
24
+ request.abortSignal = abortSignal;
25
+ try {
26
+ return await next(request);
27
+ }
28
+ finally {
29
+ cleanup === null || cleanup === void 0 ? void 0 : cleanup();
30
+ }
31
+ },
32
+ };
33
+ }
34
+ //# sourceMappingURL=wrapAbortSignalLikePolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapAbortSignalLikePolicy.js","sourceRoot":"","sources":["../../../src/policies/wrapAbortSignalLikePolicy.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAalC,8DAkBC;AA5BD,mEAAiE;AAEpD,QAAA,6BAA6B,GAAG,2BAA2B,CAAC;AAEzE;;;;;GAKG;AACH,SAAgB,yBAAyB;IACvC,OAAO;QACL,IAAI,EAAE,qCAA6B;QACnC,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;YACnC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;gBACzB,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YAED,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAA,wCAAmB,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAC1E,6CAA6C;YAC7C,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;YAClC,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7B,CAAC;oBAAS,CAAC;gBACT,OAAO,aAAP,OAAO,uBAAP,OAAO,EAAI,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { type PipelinePolicy } from \"../pipeline.js\";\nimport { wrapAbortSignalLike } from \"../util/wrapAbortSignal.js\";\n\nexport const wrapAbortSignalLikePolicyName = \"wrapAbortSignalLikePolicy\";\n\n/**\n * Policy that ensure that any AbortSignalLike is wrapped in a native AbortSignal for processing by the pipeline.\n * Since the ts-http-runtime expects a native AbortSignal, this policy is used to ensure that any AbortSignalLike is wrapped in a native AbortSignal.\n *\n * @returns - created policy\n */\nexport function wrapAbortSignalLikePolicy(): PipelinePolicy {\n return {\n name: wrapAbortSignalLikePolicyName,\n sendRequest: async (request, next) => {\n if (!request.abortSignal) {\n return next(request);\n }\n\n const { abortSignal, cleanup } = wrapAbortSignalLike(request.abortSignal);\n // eslint-disable-next-line no-param-reassign\n request.abortSignal = abortSignal;\n try {\n return await next(request);\n } finally {\n cleanup?.();\n }\n },\n };\n}\n"]}
@@ -4,35 +4,19 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.RestError = void 0;
6
6
  exports.isRestError = isRestError;
7
- const core_util_1 = require("@azure/core-util");
8
- const inspect_js_1 = require("./util/inspect.js");
9
- const sanitizer_js_1 = require("./util/sanitizer.js");
10
- const errorSanitizer = new sanitizer_js_1.Sanitizer();
7
+ const ts_http_runtime_1 = require("@typespec/ts-http-runtime");
11
8
  /**
12
9
  * A custom error type for failed pipeline requests.
13
10
  */
14
11
  class RestError extends Error {
15
12
  constructor(message, options = {}) {
16
13
  super(message);
17
- this.name = "RestError";
18
- this.code = options.code;
19
- this.statusCode = options.statusCode;
20
- // The request and response may contain sensitive information in the headers or body.
21
- // To help prevent this sensitive information being accidentally logged, the request and response
22
- // properties are marked as non-enumerable here. This prevents them showing up in the output of
23
- // JSON.stringify and console.log.
24
- Object.defineProperty(this, "request", { value: options.request, enumerable: false });
25
- Object.defineProperty(this, "response", { value: options.response, enumerable: false });
26
- // Logging method for util.inspect in Node
27
- Object.defineProperty(this, inspect_js_1.custom, {
28
- value: () => {
29
- // Extract non-enumerable properties and add them back. This is OK since in this output the request and
30
- // response get sanitized.
31
- return `RestError: ${this.message} \n ${errorSanitizer.sanitize(Object.assign(Object.assign({}, this), { request: this.request, response: this.response }))}`;
32
- },
33
- enumerable: false,
34
- });
35
- Object.setPrototypeOf(this, RestError.prototype);
14
+ // what is this??
15
+ // it turns out that you can return from a constructor and it causes
16
+ // calling `new` to return the value you return.
17
+ // this lets us wrap the TypeSpec RestError so that calling this constructor will give you the same type of object as calling the TypeSpec one,
18
+ // even though the constructor signatures (through RestErrorOptions) are slightly different.
19
+ return new ts_http_runtime_1.RestError(message, options);
36
20
  }
37
21
  }
38
22
  exports.RestError = RestError;
@@ -52,9 +36,6 @@ RestError.PARSE_ERROR = "PARSE_ERROR";
52
36
  * @param e - Something caught by a catch clause.
53
37
  */
54
38
  function isRestError(e) {
55
- if (e instanceof RestError) {
56
- return true;
57
- }
58
- return (0, core_util_1.isError)(e) && e.name === "RestError";
39
+ return (0, ts_http_runtime_1.isRestError)(e);
59
40
  }
60
41
  //# sourceMappingURL=restError.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"restError.js","sourceRoot":"","sources":["../../src/restError.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAyGlC,kCAKC;AA5GD,gDAA2C;AAE3C,kDAA2C;AAC3C,sDAAgD;AAEhD,MAAM,cAAc,GAAG,IAAI,wBAAS,EAAE,CAAC;AAwBvC;;GAEG;AACH,MAAa,SAA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CAAC;IACD,OAAO,IAAA,mBAAO,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC;AAC9C,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { isError } from \"@azure/core-util\";\nimport type { PipelineRequest, PipelineResponse } from \"./interfaces.js\";\nimport { custom } from \"./util/inspect.js\";\nimport { Sanitizer } from \"./util/sanitizer.js\";\n\nconst errorSanitizer = new Sanitizer();\n\n/**\n * The options supported by RestError.\n */\nexport interface RestErrorOptions {\n /**\n * The code of the error itself (use statics on RestError if possible.)\n */\n code?: string;\n /**\n * The HTTP status code of the request (if applicable.)\n */\n statusCode?: number;\n /**\n * The request that was made.\n */\n request?: PipelineRequest;\n /**\n * The response received (if any.)\n */\n response?: PipelineResponse;\n}\n\n/**\n * A custom error type for failed pipeline requests.\n */\nexport class RestError extends Error {\n /**\n * Something went wrong when making the request.\n * This means the actual request failed for some reason,\n * such as a DNS issue or the connection being lost.\n */\n static readonly REQUEST_SEND_ERROR: string = \"REQUEST_SEND_ERROR\";\n /**\n * This means that parsing the response from the server failed.\n * It may have been malformed.\n */\n static readonly PARSE_ERROR: string = \"PARSE_ERROR\";\n\n /**\n * The code of the error itself (use statics on RestError if possible.)\n */\n public code?: string;\n /**\n * The HTTP status code of the request (if applicable.)\n */\n public statusCode?: number;\n /**\n * The request that was made.\n * This property is non-enumerable.\n */\n public request?: PipelineRequest;\n /**\n * The response received (if any.)\n * This property is non-enumerable.\n */\n public response?: PipelineResponse;\n /**\n * Bonus property set by the throw site.\n */\n public details?: unknown;\n\n constructor(message: string, options: RestErrorOptions = {}) {\n super(message);\n this.name = \"RestError\";\n this.code = options.code;\n this.statusCode = options.statusCode;\n\n // The request and response may contain sensitive information in the headers or body.\n // To help prevent this sensitive information being accidentally logged, the request and response\n // properties are marked as non-enumerable here. This prevents them showing up in the output of\n // JSON.stringify and console.log.\n Object.defineProperty(this, \"request\", { value: options.request, enumerable: false });\n Object.defineProperty(this, \"response\", { value: options.response, enumerable: false });\n\n // Logging method for util.inspect in Node\n Object.defineProperty(this, custom, {\n value: () => {\n // Extract non-enumerable properties and add them back. This is OK since in this output the request and\n // response get sanitized.\n return `RestError: ${this.message} \\n ${errorSanitizer.sanitize({\n ...this,\n request: this.request,\n response: this.response,\n })}`;\n },\n enumerable: false,\n });\n\n Object.setPrototypeOf(this, RestError.prototype);\n }\n}\n\n/**\n * Typeguard for RestError\n * @param e - Something caught by a catch clause.\n */\nexport function isRestError(e: unknown): e is RestError {\n if (e instanceof RestError) {\n return true;\n }\n return isError(e) && e.name === \"RestError\";\n}\n"]}
1
+ {"version":3,"file":"restError.js","sourceRoot":"","sources":["../../src/restError.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAuFlC,kCAEC;AApFD,+DAGmC;AAwBnC;;GAEG;AACH,MAAa,SAAU,SAAQ,KAAK;IAoClC,YAAY,OAAe,EAAE,UAA4B,EAAE;QACzD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,iBAAiB;QACjB,oEAAoE;QACpE,gDAAgD;QAChD,+IAA+I;QAC/I,4FAA4F;QAC5F,OAAO,IAAI,2BAAY,CAAC,OAAO,EAAE,OAA8B,CAAC,CAAC;IACnE,CAAC;;AA7CH,8BA8CC;AA7CC;;;;GAIG;AACa,4BAAkB,GAAW,oBAAoB,CAAC;AAClE;;;GAGG;AACa,qBAAW,GAAW,aAAa,CAAC;AAqCtD;;;GAGG;AACH,SAAgB,WAAW,CAAC,CAAU;IACpC,OAAO,IAAA,6BAAc,EAAC,CAAC,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequest, PipelineResponse } from \"./interfaces.js\";\n\nimport type { RestErrorOptions as TspRestErrorOptions } from \"@typespec/ts-http-runtime\";\nimport {\n RestError as TspRestError,\n isRestError as tspIsRestError,\n} from \"@typespec/ts-http-runtime\";\n\n/**\n * The options supported by RestError.\n */\nexport interface RestErrorOptions {\n /**\n * The code of the error itself (use statics on RestError if possible.)\n */\n code?: string;\n /**\n * The HTTP status code of the request (if applicable.)\n */\n statusCode?: number;\n /**\n * The request that was made.\n */\n request?: PipelineRequest;\n /**\n * The response received (if any.)\n */\n response?: PipelineResponse;\n}\n\n/**\n * A custom error type for failed pipeline requests.\n */\nexport class RestError extends Error {\n /**\n * Something went wrong when making the request.\n * This means the actual request failed for some reason,\n * such as a DNS issue or the connection being lost.\n */\n static readonly REQUEST_SEND_ERROR: string = \"REQUEST_SEND_ERROR\";\n /**\n * This means that parsing the response from the server failed.\n * It may have been malformed.\n */\n static readonly PARSE_ERROR: string = \"PARSE_ERROR\";\n\n /**\n * The code of the error itself (use statics on RestError if possible.)\n */\n public code?: string;\n /**\n * The HTTP status code of the request (if applicable.)\n */\n public statusCode?: number;\n /**\n * The request that was made.\n * This property is non-enumerable.\n */\n public request?: PipelineRequest;\n /**\n * The response received (if any.)\n * This property is non-enumerable.\n */\n public response?: PipelineResponse;\n /**\n * Bonus property set by the throw site.\n */\n public details?: unknown;\n\n constructor(message: string, options: RestErrorOptions = {}) {\n super(message);\n\n // what is this??\n // it turns out that you can return from a constructor and it causes\n // calling `new` to return the value you return.\n // this lets us wrap the TypeSpec RestError so that calling this constructor will give you the same type of object as calling the TypeSpec one,\n // even though the constructor signatures (through RestErrorOptions) are slightly different.\n return new TspRestError(message, options as TspRestErrorOptions);\n }\n}\n\n/**\n * Typeguard for RestError\n * @param e - Something caught by a catch clause.\n */\nexport function isRestError(e: unknown): e is RestError {\n return tspIsRestError(e);\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.52.4"
8
+ "packageVersion": "7.52.5"
9
9
  }
10
10
  ]
11
11
  }
@@ -28,14 +28,39 @@ export interface CreateFileFromStreamOptions extends CreateFileOptions {
28
28
  */
29
29
  size?: number;
30
30
  }
31
+ /**
32
+ * Private symbol used as key on objects created using createFile containing the
33
+ * original source of the file object.
34
+ *
35
+ * This is used in Node to access the original Node stream without using Blob#stream, which
36
+ * returns a web stream. This is done to avoid a couple of bugs to do with Blob#stream and
37
+ * Readable#to/fromWeb in Node versions we support:
38
+ * - https://github.com/nodejs/node/issues/42694 (fixed in Node 18.14)
39
+ * - https://github.com/nodejs/node/issues/48916 (fixed in Node 20.6)
40
+ *
41
+ * Once these versions are no longer supported, we may be able to stop doing this.
42
+ *
43
+ * @internal
44
+ */
45
+ declare const rawContent: unique symbol;
46
+ /**
47
+ * Type signature of a blob-like object with a raw content property.
48
+ */
49
+ export interface RawContent extends Blob {
50
+ [rawContent](): Uint8Array | NodeJS.ReadableStream | ReadableStream<Uint8Array>;
51
+ }
52
+ /**
53
+ * Type guard to check if a given object is a blob-like object with a raw content property.
54
+ */
55
+ export declare function hasRawContent(x: unknown): x is RawContent;
31
56
  /**
32
57
  * Extract the raw content from a given blob-like object. If the input was created using createFile
33
58
  * or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.
34
- * For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.
59
+ * For true instances of Blob and File, returns the actual blob.
35
60
  *
36
61
  * @internal
37
62
  */
38
- export declare function getRawContent(blob: Blob): NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array;
63
+ export declare function getRawContent(blob: Blob): Blob | NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array;
39
64
  /**
40
65
  * Create an object that implements the File interface. This object is intended to be
41
66
  * passed into RequestBodyType.formData, and is not guaranteed to work as expected in
@@ -66,4 +91,5 @@ export declare function createFileFromStream(stream: () => ReadableStream<Uint8A
66
91
  * @param options - optional metadata about the file, e.g. file name, file size, MIME type.
67
92
  */
68
93
  export declare function createFile(content: Uint8Array, name: string, options?: CreateFileOptions): File;
94
+ export {};
69
95
  //# sourceMappingURL=file.d.ts.map
@@ -2,11 +2,14 @@
2
2
  // Copyright (c) Microsoft Corporation.
3
3
  // Licensed under the MIT License.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.hasRawContent = hasRawContent;
5
6
  exports.getRawContent = getRawContent;
6
7
  exports.createFileFromStream = createFileFromStream;
7
8
  exports.createFile = createFile;
8
9
  const core_util_1 = require("@azure/core-util");
9
- const typeGuards_js_1 = require("./typeGuards.js");
10
+ function isNodeReadableStream(x) {
11
+ return Boolean(x && typeof x["pipe"] === "function");
12
+ }
10
13
  const unimplementedMethods = {
11
14
  arrayBuffer: () => {
12
15
  throw new Error("Not implemented");
@@ -36,13 +39,16 @@ const unimplementedMethods = {
36
39
  * @internal
37
40
  */
38
41
  const rawContent = Symbol("rawContent");
42
+ /**
43
+ * Type guard to check if a given object is a blob-like object with a raw content property.
44
+ */
39
45
  function hasRawContent(x) {
40
46
  return typeof x[rawContent] === "function";
41
47
  }
42
48
  /**
43
49
  * Extract the raw content from a given blob-like object. If the input was created using createFile
44
50
  * or createFileFromStream, the exact content passed into createFile/createFileFromStream will be used.
45
- * For true instances of Blob and File, returns the blob's content as a Web ReadableStream<Uint8Array>.
51
+ * For true instances of Blob and File, returns the actual blob.
46
52
  *
47
53
  * @internal
48
54
  */
@@ -51,7 +57,7 @@ function getRawContent(blob) {
51
57
  return blob[rawContent]();
52
58
  }
53
59
  else {
54
- return blob.stream();
60
+ return blob;
55
61
  }
56
62
  }
57
63
  /**
@@ -75,7 +81,7 @@ function createFileFromStream(stream, name, options = {}) {
75
81
  var _a, _b, _c, _d;
76
82
  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: () => {
77
83
  const s = stream();
78
- if ((0, typeGuards_js_1.isNodeReadableStream)(s)) {
84
+ if (isNodeReadableStream(s)) {
79
85
  throw new Error("Not supported: a Node stream was provided as input to createFileFromStream.");
80
86
  }
81
87
  return s;
@@ -1 +1 @@
1
- {"version":3,"file":"file.js","sourceRoot":"","sources":["../../../src/util/file.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAwFlC,sCAQC;AAmBD,oDAwBC;AAaD,gCAoBC;AA1KD,gDAA8C;AAC9C,mDAAuD;AAoCvD,MAAM,oBAAoB,GAAG;IAC3B,WAAW,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,EAAE,GAAG,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,EAAE,GAAG,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,EAAE,GAAG,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,GAAkB,MAAM,CAAC,YAAY,CAAC,CAAC;AASvD,SAAS,aAAa,CAAC,CAAU;IAC/B,OAAO,OAAQ,CAAgB,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,aAAa,CAC3B,IAAU;IAEV,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;IAC5B,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,oBAAoB,CAClC,MAAgE,EAChE,IAAY,EACZ,UAAuC,EAAE;;IAEzC,OAAO,gCACF,oBAAoB,KACvB,IAAI,EAAE,MAAA,OA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EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { isNodeLike } from \"@azure/core-util\";\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 bytes: () => {\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 (isNodeLike) {\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;;AAmFlC,sCAEC;AASD,sCAQC;AAmBD,oDAwBC;AAaD,gCAoBC;AAhLD,gDAA8C;AAE9C,SAAS,oBAAoB,CAAC,CAAU;IACtC,OAAO,OAAO,CAAC,CAAC,IAAI,OAAQ,CAA2B,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,CAAC;AAClF,CAAC;AAoCD,MAAM,oBAAoB,GAAG;IAC3B,WAAW,EAAE,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,EAAE,GAAG,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,KAAK,EAAE,GAAG,EAAE;QACV,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,EAAE,GAAG,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CACF,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,GAAkB,MAAM,CAAC,YAAY,CAAC,CAAC;AASvD;;GAEG;AACH,SAAgB,aAAa,CAAC,CAAU;IACtC,OAAO,OAAQ,CAAgB,CAAC,UAAU,CAAC,KAAK,UAAU,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,aAAa,CAC3B,IAAU;IAEV,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB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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 { isNodeLike } from \"@azure/core-util\";\n\nfunction isNodeReadableStream(x: unknown): x is NodeJS.ReadableStream {\n return Boolean(x && typeof (x as NodeJS.ReadableStream)[\"pipe\"] === \"function\");\n}\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 bytes: () => {\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 */\nexport interface RawContent extends Blob {\n [rawContent](): Uint8Array | NodeJS.ReadableStream | ReadableStream<Uint8Array>;\n}\n\n/**\n * Type guard to check if a given object is a blob-like object with a raw content property.\n */\nexport function 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 actual blob.\n *\n * @internal\n */\nexport function getRawContent(\n blob: Blob,\n): Blob | NodeJS.ReadableStream | ReadableStream<Uint8Array> | Uint8Array {\n if (hasRawContent(blob)) {\n return blob[rawContent]();\n } else {\n return blob;\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 (isNodeLike) {\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"]}
@@ -4,7 +4,7 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.DEFAULT_CYCLER_OPTIONS = void 0;
6
6
  exports.createTokenCycler = createTokenCycler;
7
- const helpers_js_1 = require("./helpers.js");
7
+ const core_util_1 = require("@azure/core-util");
8
8
  // Default options for the cycler if none are provided
9
9
  exports.DEFAULT_CYCLER_OPTIONS = {
10
10
  forcedRefreshWindowInMs: 1000, // Force waiting for a refresh 1s before the token expires
@@ -44,7 +44,7 @@ async function beginRefresh(getAccessToken, retryIntervalInMs, refreshTimeout) {
44
44
  }
45
45
  let token = await tryGetAccessToken();
46
46
  while (token === null) {
47
- await (0, helpers_js_1.delay)(retryIntervalInMs);
47
+ await (0, core_util_1.delay)(retryIntervalInMs);
48
48
  token = await tryGetAccessToken();
49
49
  }
50
50
  return token;
@@ -1 +1 @@
1
- {"version":3,"file":"tokenCycler.js","sourceRoot":"","sources":["../../../src/util/tokenCycler.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAyGlC,8CA6HC;AAn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soft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\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 if (cycler.isRefreshing) {\n return false;\n }\n if (token?.refreshAfterTimestamp && token.refreshAfterTimestamp < Date.now()) {\n return true;\n }\n\n return (token?.expiresOnTimestamp ?? 0) - options.refreshWindowInMs < Date.now();\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 const hasClaimChallenge = Boolean(tokenOptions.claims);\n const tenantIdChanged = tenantId !== tokenOptions.tenantId;\n\n if (hasClaimChallenge) {\n // If we've received a claim, we know the existing token isn't valid\n // We want to clear it so that that refresh worker won't use the old expiration time as a timeout\n token = null;\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 = tenantIdChanged || hasClaimChallenge || cycler.mustRefresh;\n\n if (mustRefresh) {\n return refresh(scopes, tokenOptions);\n }\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;;;AAyGlC,8CA6HC;AAnOD,gD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poration.\n// Licensed under the MIT License.\n\nimport type { AccessToken, GetTokenOptions, TokenCredential } from \"@azure/core-auth\";\nimport { delay } from \"@azure/core-util\";\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 if (cycler.isRefreshing) {\n return false;\n }\n if (token?.refreshAfterTimestamp && token.refreshAfterTimestamp < Date.now()) {\n return true;\n }\n\n return (token?.expiresOnTimestamp ?? 0) - options.refreshWindowInMs < Date.now();\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 const hasClaimChallenge = Boolean(tokenOptions.claims);\n const tenantIdChanged = tenantId !== tokenOptions.tenantId;\n\n if (hasClaimChallenge) {\n // If we've received a claim, we know the existing token isn't valid\n // We want to clear it so that that refresh worker won't use the old expiration time as a timeout\n token = null;\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 = tenantIdChanged || hasClaimChallenge || cycler.mustRefresh;\n\n if (mustRefresh) {\n return refresh(scopes, tokenOptions);\n }\n\n if (cycler.shouldRefresh) {\n refresh(scopes, tokenOptions);\n }\n\n return token as AccessToken;\n };\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import type { AbortSignalLike } from "@azure/abort-controller";
2
+ /**
3
+ * Creates a native AbortSignal which reflects the state of the provided AbortSignalLike.
4
+ * If the AbortSignalLike is already a native AbortSignal, it is returned as is.
5
+ * @param abortSignalLike - The AbortSignalLike to wrap.
6
+ * @returns - An object containing the native AbortSignal and an optional cleanup function. The cleanup function should be called when the AbortSignal is no longer needed.
7
+ */
8
+ export declare function wrapAbortSignalLike(abortSignalLike: AbortSignalLike): {
9
+ abortSignal: AbortSignal;
10
+ cleanup?: () => void;
11
+ };
12
+ //# sourceMappingURL=wrapAbortSignal.d.ts.map
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.wrapAbortSignalLike = wrapAbortSignalLike;
6
+ /**
7
+ * Creates a native AbortSignal which reflects the state of the provided AbortSignalLike.
8
+ * If the AbortSignalLike is already a native AbortSignal, it is returned as is.
9
+ * @param abortSignalLike - The AbortSignalLike to wrap.
10
+ * @returns - An object containing the native AbortSignal and an optional cleanup function. The cleanup function should be called when the AbortSignal is no longer needed.
11
+ */
12
+ function wrapAbortSignalLike(abortSignalLike) {
13
+ if (abortSignalLike instanceof AbortSignal) {
14
+ return { abortSignal: abortSignalLike };
15
+ }
16
+ if (abortSignalLike.aborted) {
17
+ return { abortSignal: AbortSignal.abort(abortSignalLike.reason) };
18
+ }
19
+ const controller = new AbortController();
20
+ let needsCleanup = true;
21
+ function cleanup() {
22
+ if (needsCleanup) {
23
+ abortSignalLike.removeEventListener("abort", listener);
24
+ needsCleanup = false;
25
+ }
26
+ }
27
+ function listener() {
28
+ controller.abort(abortSignalLike.reason);
29
+ cleanup();
30
+ }
31
+ abortSignalLike.addEventListener("abort", listener);
32
+ return { abortSignal: controller.signal, cleanup };
33
+ }
34
+ //# sourceMappingURL=wrapAbortSignal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapAbortSignal.js","sourceRoot":"","sources":["../../../src/util/wrapAbortSignal.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;AAUlC,kDA2BC;AAjCD;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,eAAgC;IAIlE,IAAI,eAAe,YAAY,WAAW,EAAE,CAAC;QAC3C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;IAC1C,CAAC;IAED,IAAI,eAAe,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,EAAE,WAAW,EAAE,WAAW,CAAC,KAAK,CAAE,eAAuB,CAAC,MAAM,CAAC,EAAE,CAAC;IAC7E,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,IAAI,YAAY,GAAG,IAAI,CAAC;IACxB,SAAS,OAAO;QACd,IAAI,YAAY,EAAE,CAAC;YACjB,eAAe,CAAC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACvD,YAAY,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;IACD,SAAS,QAAQ;QACf,UAAU,CAAC,KAAK,CAAE,eAAuB,CAAC,MAAM,CAAC,CAAC;QAClD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,eAAe,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACpD,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;AACrD,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"@azure/abort-controller\";\n\n/**\n * Creates a native AbortSignal which reflects the state of the provided AbortSignalLike.\n * If the AbortSignalLike is already a native AbortSignal, it is returned as is.\n * @param abortSignalLike - The AbortSignalLike to wrap.\n * @returns - An object containing the native AbortSignal and an optional cleanup function. The cleanup function should be called when the AbortSignal is no longer needed.\n */\nexport function wrapAbortSignalLike(abortSignalLike: AbortSignalLike): {\n abortSignal: AbortSignal;\n cleanup?: () => void;\n} {\n if (abortSignalLike instanceof AbortSignal) {\n return { abortSignal: abortSignalLike };\n }\n\n if (abortSignalLike.aborted) {\n return { abortSignal: AbortSignal.abort((abortSignalLike as any).reason) };\n }\n\n const controller = new AbortController();\n let needsCleanup = true;\n function cleanup(): void {\n if (needsCleanup) {\n abortSignalLike.removeEventListener(\"abort\", listener);\n needsCleanup = false;\n }\n }\n function listener(): void {\n controller.abort((abortSignalLike as any).reason);\n cleanup();\n }\n\n abortSignalLike.addEventListener(\"abort\", listener);\n return { abortSignal: controller.signal, cleanup };\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
- export const SDK_VERSION = "1.19.2";
3
+ export const SDK_VERSION = "1.20.0";
4
4
  export const DEFAULT_RETRY_POLICY_COUNT = 3;
5
5
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAW,QAAQ,CAAC;AAE5C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const SDK_VERSION: string = \"1.19.2\";\n\nexport const DEFAULT_RETRY_POLICY_COUNT = 3;\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,MAAM,CAAC,MAAM,WAAW,GAAW,QAAQ,CAAC;AAE5C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nexport const SDK_VERSION: string = \"1.20.0\";\n\nexport const DEFAULT_RETRY_POLICY_COUNT = 3;\n"]}
@@ -14,6 +14,7 @@ import { setClientRequestIdPolicy } from "./policies/setClientRequestIdPolicy.js
14
14
  import { agentPolicy } from "./policies/agentPolicy.js";
15
15
  import { tlsPolicy } from "./policies/tlsPolicy.js";
16
16
  import { tracingPolicy } from "./policies/tracingPolicy.js";
17
+ import { wrapAbortSignalLikePolicy } from "./policies/wrapAbortSignalLikePolicy.js";
17
18
  /**
18
19
  * Create a new pipeline with a default set of customizable policies.
19
20
  * @param options - Options to configure a custom pipeline.
@@ -31,6 +32,7 @@ export function createPipelineFromOptions(options) {
31
32
  pipeline.addPolicy(proxyPolicy(options.proxyOptions));
32
33
  pipeline.addPolicy(decompressResponsePolicy());
33
34
  }
35
+ pipeline.addPolicy(wrapAbortSignalLikePolicy());
34
36
  pipeline.addPolicy(formDataPolicy(), { beforePolicies: [multipartPolicyName] });
35
37
  pipeline.addPolicy(userAgentPolicy(options.userAgentOptions));
36
38
  pipeline.addPolicy(setClientRequestIdPolicy((_a = options.telemetryOptions) === null || _a === void 0 ? void 0 : _a.clientRequestIdHeaderName));
@@ -1 +1 @@
1
- {"version":3,"file":"createPipelineFromOptions.js","sourceRoot":"","sources":["../../src/createPipelineFromOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAyB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAiB,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAA8B,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EAA+B,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC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,EAAE,CAAC,CAAC;IACjF,QAAQ,CAAC,SAAS,CAAC,aAAa,iCAAM,OAAO,CAAC,gBAAgB,GAAK,OAAO,CAAC,cAAc,EAAG,EAAE;QAC5F,UAAU,EAAE,OAAO;KACpB,CAAC,CAAC;IACH,IAAI,UAAU,EAAE,CAAC;QACf,+DAA+D;QAC/D,kDAAkD;QAClD,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;IAE9E,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { type LogPolicyOptions, logPolicy } from \"./policies/logPolicy.js\";\nimport { type Pipeline, createEmptyPipeline } from \"./pipeline.js\";\nimport type { Agent, PipelineRetryOptions, ProxySettings, TlsSettings } from \"./interfaces.js\";\nimport { type RedirectPolicyOptions, redirectPolicy } from \"./policies/redirectPolicy.js\";\nimport { type UserAgentPolicyOptions, userAgentPolicy } from \"./policies/userAgentPolicy.js\";\nimport { multipartPolicy, multipartPolicyName } from \"./policies/multipartPolicy.js\";\nimport { decompressResponsePolicy } from \"./policies/decompressResponsePolicy.js\";\nimport { defaultRetryPolicy } from \"./policies/defaultRetryPolicy.js\";\nimport { formDataPolicy } from \"./policies/formDataPolicy.js\";\nimport { isNodeLike } from \"@azure/core-util\";\nimport { proxyPolicy } from \"./policies/proxyPolicy.js\";\nimport { setClientRequestIdPolicy } from \"./policies/setClientRequestIdPolicy.js\";\nimport { agentPolicy } from \"./policies/agentPolicy.js\";\nimport { tlsPolicy } from \"./policies/tlsPolicy.js\";\nimport { tracingPolicy } from \"./policies/tracingPolicy.js\";\n\n/**\n * Defines options that are used to configure the HTTP pipeline for\n * an SDK client.\n */\nexport interface PipelineOptions {\n /**\n * Options that control how to retry failed requests.\n */\n retryOptions?: PipelineRetryOptions;\n\n /**\n * Options to configure a proxy for outgoing requests.\n */\n proxyOptions?: ProxySettings;\n\n /** Options for configuring Agent instance for outgoing requests */\n agent?: Agent;\n\n /** Options for configuring TLS authentication */\n tlsOptions?: TlsSettings;\n\n /**\n * Options for how redirect responses are handled.\n */\n redirectOptions?: RedirectPolicyOptions;\n\n /**\n * Options for adding user agent details to outgoing requests.\n */\n userAgentOptions?: UserAgentPolicyOptions;\n\n /**\n * Options for setting common telemetry and tracing info to outgoing requests.\n */\n telemetryOptions?: TelemetryOptions;\n}\n\n/**\n * Defines options that are used to configure common telemetry and tracing info\n */\nexport interface TelemetryOptions {\n /**\n * The name of the header to pass the request ID to.\n */\n clientRequestIdHeaderName?: string;\n}\n\n/**\n * Defines options that are used to configure internal options of\n * the HTTP pipeline for an SDK client.\n */\nexport interface InternalPipelineOptions extends PipelineOptions {\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n}\n\n/**\n * Create a new pipeline with a default set of customizable policies.\n * @param options - Options to configure a custom pipeline.\n */\nexport function createPipelineFromOptions(options: InternalPipelineOptions): Pipeline {\n const pipeline = createEmptyPipeline();\n\n if (isNodeLike) {\n if (options.agent) {\n pipeline.addPolicy(agentPolicy(options.agent));\n }\n if (options.tlsOptions) {\n pipeline.addPolicy(tlsPolicy(options.tlsOptions));\n }\n pipeline.addPolicy(proxyPolicy(options.proxyOptions));\n pipeline.addPolicy(decompressResponsePolicy());\n }\n\n pipeline.addPolicy(formDataPolicy(), { beforePolicies: [multipartPolicyName] });\n pipeline.addPolicy(userAgentPolicy(options.userAgentOptions));\n pipeline.addPolicy(setClientRequestIdPolicy(options.telemetryOptions?.clientRequestIdHeaderName));\n // The multipart policy is added after policies with no phase, so that\n // policies can be added between it and formDataPolicy to modify\n // properties (e.g., making the boundary constant in recorded tests).\n pipeline.addPolicy(multipartPolicy(), { afterPhase: \"Deserialize\" });\n pipeline.addPolicy(defaultRetryPolicy(options.retryOptions), { phase: \"Retry\" });\n pipeline.addPolicy(tracingPolicy({ ...options.userAgentOptions, ...options.loggingOptions }), {\n afterPhase: \"Retry\",\n });\n if (isNodeLike) {\n // Both XHR and Fetch expect to handle redirects automatically,\n // so only include this policy when we're in Node.\n pipeline.addPolicy(redirectPolicy(options.redirectOptions), { afterPhase: \"Retry\" });\n }\n pipeline.addPolicy(logPolicy(options.loggingOptions), { afterPhase: \"Sign\" });\n\n return pipeline;\n}\n"]}
1
+ {"version":3,"file":"createPipelineFromOptions.js","sourceRoot":"","sources":["../../src/createPipelineFromOptions.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAyB,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAiB,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,EAA8B,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC1F,OAAO,EAA+B,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAC7F,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,yBA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,CAAC,gBAAgB,GAAK,OAAO,CAAC,cAAc,EAAG,EAAE;QAC5F,UAAU,EAAE,OAAO;KACpB,CAAC,CAAC;IACH,IAAI,UAAU,EAAE,CAAC;QACf,+DAA+D;QAC/D,kDAAkD;QAClD,QAAQ,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;IAE9E,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { type LogPolicyOptions, logPolicy } from \"./policies/logPolicy.js\";\nimport { type Pipeline, createEmptyPipeline } from \"./pipeline.js\";\nimport type { Agent, PipelineRetryOptions, ProxySettings, TlsSettings } from \"./interfaces.js\";\nimport { type RedirectPolicyOptions, redirectPolicy } from \"./policies/redirectPolicy.js\";\nimport { type UserAgentPolicyOptions, userAgentPolicy } from \"./policies/userAgentPolicy.js\";\nimport { multipartPolicy, multipartPolicyName } from \"./policies/multipartPolicy.js\";\nimport { decompressResponsePolicy } from \"./policies/decompressResponsePolicy.js\";\nimport { defaultRetryPolicy } from \"./policies/defaultRetryPolicy.js\";\nimport { formDataPolicy } from \"./policies/formDataPolicy.js\";\nimport { isNodeLike } from \"@azure/core-util\";\nimport { proxyPolicy } from \"./policies/proxyPolicy.js\";\nimport { setClientRequestIdPolicy } from \"./policies/setClientRequestIdPolicy.js\";\nimport { agentPolicy } from \"./policies/agentPolicy.js\";\nimport { tlsPolicy } from \"./policies/tlsPolicy.js\";\nimport { tracingPolicy } from \"./policies/tracingPolicy.js\";\nimport { wrapAbortSignalLikePolicy } from \"./policies/wrapAbortSignalLikePolicy.js\";\n\n/**\n * Defines options that are used to configure the HTTP pipeline for\n * an SDK client.\n */\nexport interface PipelineOptions {\n /**\n * Options that control how to retry failed requests.\n */\n retryOptions?: PipelineRetryOptions;\n\n /**\n * Options to configure a proxy for outgoing requests.\n */\n proxyOptions?: ProxySettings;\n\n /** Options for configuring Agent instance for outgoing requests */\n agent?: Agent;\n\n /** Options for configuring TLS authentication */\n tlsOptions?: TlsSettings;\n\n /**\n * Options for how redirect responses are handled.\n */\n redirectOptions?: RedirectPolicyOptions;\n\n /**\n * Options for adding user agent details to outgoing requests.\n */\n userAgentOptions?: UserAgentPolicyOptions;\n\n /**\n * Options for setting common telemetry and tracing info to outgoing requests.\n */\n telemetryOptions?: TelemetryOptions;\n}\n\n/**\n * Defines options that are used to configure common telemetry and tracing info\n */\nexport interface TelemetryOptions {\n /**\n * The name of the header to pass the request ID to.\n */\n clientRequestIdHeaderName?: string;\n}\n\n/**\n * Defines options that are used to configure internal options of\n * the HTTP pipeline for an SDK client.\n */\nexport interface InternalPipelineOptions extends PipelineOptions {\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n}\n\n/**\n * Create a new pipeline with a default set of customizable policies.\n * @param options - Options to configure a custom pipeline.\n */\nexport function createPipelineFromOptions(options: InternalPipelineOptions): Pipeline {\n const pipeline = createEmptyPipeline();\n\n if (isNodeLike) {\n if (options.agent) {\n pipeline.addPolicy(agentPolicy(options.agent));\n }\n if (options.tlsOptions) {\n pipeline.addPolicy(tlsPolicy(options.tlsOptions));\n }\n pipeline.addPolicy(proxyPolicy(options.proxyOptions));\n pipeline.addPolicy(decompressResponsePolicy());\n }\n\n pipeline.addPolicy(wrapAbortSignalLikePolicy());\n\n pipeline.addPolicy(formDataPolicy(), { beforePolicies: [multipartPolicyName] });\n pipeline.addPolicy(userAgentPolicy(options.userAgentOptions));\n pipeline.addPolicy(setClientRequestIdPolicy(options.telemetryOptions?.clientRequestIdHeaderName));\n // The multipart policy is added after policies with no phase, so that\n // policies can be added between it and formDataPolicy to modify\n // properties (e.g., making the boundary constant in recorded tests).\n pipeline.addPolicy(multipartPolicy(), { afterPhase: \"Deserialize\" });\n pipeline.addPolicy(defaultRetryPolicy(options.retryOptions), { phase: \"Retry\" });\n pipeline.addPolicy(tracingPolicy({ ...options.userAgentOptions, ...options.loggingOptions }), {\n afterPhase: \"Retry\",\n });\n if (isNodeLike) {\n // Both XHR and Fetch expect to handle redirects automatically,\n // so only include this policy when we're in Node.\n pipeline.addPolicy(redirectPolicy(options.redirectOptions), { afterPhase: \"Retry\" });\n }\n pipeline.addPolicy(logPolicy(options.loggingOptions), { afterPhase: \"Sign\" });\n\n return pipeline;\n}\n"]}