@typespec/ts-http-runtime 0.1.0-alpha.20250325.2 → 0.2.0-alpha.20250326.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/dist/browser/auth/credentials.d.ts +77 -0
  2. package/dist/browser/auth/credentials.js +27 -0
  3. package/dist/browser/auth/credentials.js.map +1 -0
  4. package/dist/browser/auth/oauth2Flows.d.ts +57 -0
  5. package/dist/browser/{abort-controller/AbortSignalLike.js → auth/oauth2Flows.js} +1 -1
  6. package/dist/browser/auth/oauth2Flows.js.map +1 -0
  7. package/dist/browser/auth/schemes.d.ts +53 -0
  8. package/dist/{esm/abort-controller/AbortSignalLike.js → browser/auth/schemes.js} +1 -1
  9. package/dist/browser/auth/schemes.js.map +1 -0
  10. package/dist/browser/client/clientHelpers.d.ts +1 -20
  11. package/dist/browser/client/clientHelpers.js +21 -30
  12. package/dist/browser/client/clientHelpers.js.map +1 -1
  13. package/dist/browser/client/common.d.ts +13 -15
  14. package/dist/browser/client/common.js.map +1 -1
  15. package/dist/browser/client/getClient.d.ts +1 -9
  16. package/dist/browser/client/getClient.js +8 -16
  17. package/dist/browser/client/getClient.js.map +1 -1
  18. package/dist/browser/constants.js +1 -1
  19. package/dist/browser/constants.js.map +1 -1
  20. package/dist/browser/index.d.ts +3 -3
  21. package/dist/browser/index.js +2 -2
  22. package/dist/browser/index.js.map +1 -1
  23. package/dist/browser/interfaces.d.ts +10 -2
  24. package/dist/browser/interfaces.js.map +1 -1
  25. package/dist/browser/pipelineRequest.d.ts +1 -2
  26. package/dist/browser/pipelineRequest.js.map +1 -1
  27. package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
  28. package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
  29. package/dist/browser/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
  30. package/dist/browser/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
  31. package/dist/browser/policies/auth/basicAuthenticationPolicy.js +31 -0
  32. package/dist/browser/policies/auth/basicAuthenticationPolicy.js.map +1 -0
  33. package/dist/browser/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
  34. package/dist/browser/policies/auth/bearerAuthenticationPolicy.js +31 -0
  35. package/dist/browser/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
  36. package/dist/browser/policies/auth/checkInsecureConnection.d.ts +9 -0
  37. package/dist/browser/policies/auth/checkInsecureConnection.js +50 -0
  38. package/dist/browser/policies/auth/checkInsecureConnection.js.map +1 -0
  39. package/dist/browser/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
  40. package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js +31 -0
  41. package/dist/browser/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
  42. package/dist/browser/util/aborterUtils.d.ts +3 -4
  43. package/dist/browser/util/aborterUtils.js.map +1 -1
  44. package/dist/browser/util/helpers.d.ts +1 -2
  45. package/dist/browser/util/helpers.js.map +1 -1
  46. package/dist/commonjs/auth/credentials.d.ts +77 -0
  47. package/dist/commonjs/auth/credentials.js +33 -0
  48. package/dist/commonjs/auth/credentials.js.map +1 -0
  49. package/dist/commonjs/auth/oauth2Flows.d.ts +57 -0
  50. package/dist/commonjs/{abort-controller/AbortSignalLike.js → auth/oauth2Flows.js} +1 -1
  51. package/dist/commonjs/auth/oauth2Flows.js.map +1 -0
  52. package/dist/commonjs/auth/schemes.d.ts +53 -0
  53. package/dist/commonjs/auth/schemes.js +5 -0
  54. package/dist/commonjs/auth/schemes.js.map +1 -0
  55. package/dist/commonjs/client/clientHelpers.d.ts +1 -20
  56. package/dist/commonjs/client/clientHelpers.js +21 -31
  57. package/dist/commonjs/client/clientHelpers.js.map +1 -1
  58. package/dist/commonjs/client/common.d.ts +13 -15
  59. package/dist/commonjs/client/common.js.map +1 -1
  60. package/dist/commonjs/client/getClient.d.ts +1 -9
  61. package/dist/commonjs/client/getClient.js +8 -16
  62. package/dist/commonjs/client/getClient.js.map +1 -1
  63. package/dist/commonjs/constants.js +1 -1
  64. package/dist/commonjs/constants.js.map +1 -1
  65. package/dist/commonjs/index.d.ts +3 -3
  66. package/dist/commonjs/index.js +4 -5
  67. package/dist/commonjs/index.js.map +1 -1
  68. package/dist/commonjs/interfaces.d.ts +10 -2
  69. package/dist/commonjs/interfaces.js.map +1 -1
  70. package/dist/commonjs/pipelineRequest.d.ts +1 -2
  71. package/dist/commonjs/pipelineRequest.js.map +1 -1
  72. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
  73. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js +35 -0
  74. package/dist/commonjs/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
  75. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
  76. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js +35 -0
  77. package/dist/commonjs/policies/auth/basicAuthenticationPolicy.js.map +1 -0
  78. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
  79. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js +35 -0
  80. package/dist/commonjs/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
  81. package/dist/commonjs/policies/auth/checkInsecureConnection.d.ts +9 -0
  82. package/dist/commonjs/policies/auth/checkInsecureConnection.js +53 -0
  83. package/dist/commonjs/policies/auth/checkInsecureConnection.js.map +1 -0
  84. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
  85. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js +35 -0
  86. package/dist/commonjs/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
  87. package/dist/commonjs/util/aborterUtils.d.ts +3 -4
  88. package/dist/commonjs/util/aborterUtils.js.map +1 -1
  89. package/dist/commonjs/util/helpers.d.ts +1 -2
  90. package/dist/commonjs/util/helpers.js.map +1 -1
  91. package/dist/esm/auth/credentials.d.ts +77 -0
  92. package/dist/esm/auth/credentials.js +27 -0
  93. package/dist/esm/auth/credentials.js.map +1 -0
  94. package/dist/esm/auth/oauth2Flows.d.ts +57 -0
  95. package/dist/{react-native/abort-controller/AbortSignalLike.js → esm/auth/oauth2Flows.js} +1 -1
  96. package/dist/esm/auth/oauth2Flows.js.map +1 -0
  97. package/dist/esm/auth/schemes.d.ts +53 -0
  98. package/dist/esm/auth/schemes.js +4 -0
  99. package/dist/esm/auth/schemes.js.map +1 -0
  100. package/dist/esm/client/clientHelpers.d.ts +1 -20
  101. package/dist/esm/client/clientHelpers.js +21 -30
  102. package/dist/esm/client/clientHelpers.js.map +1 -1
  103. package/dist/esm/client/common.d.ts +13 -15
  104. package/dist/esm/client/common.js.map +1 -1
  105. package/dist/esm/client/getClient.d.ts +1 -9
  106. package/dist/esm/client/getClient.js +8 -16
  107. package/dist/esm/client/getClient.js.map +1 -1
  108. package/dist/esm/constants.js +1 -1
  109. package/dist/esm/constants.js.map +1 -1
  110. package/dist/esm/index.d.ts +3 -3
  111. package/dist/esm/index.js +2 -2
  112. package/dist/esm/index.js.map +1 -1
  113. package/dist/esm/interfaces.d.ts +10 -2
  114. package/dist/esm/interfaces.js.map +1 -1
  115. package/dist/esm/pipelineRequest.d.ts +1 -2
  116. package/dist/esm/pipelineRequest.js.map +1 -1
  117. package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
  118. package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
  119. package/dist/esm/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
  120. package/dist/esm/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
  121. package/dist/esm/policies/auth/basicAuthenticationPolicy.js +31 -0
  122. package/dist/esm/policies/auth/basicAuthenticationPolicy.js.map +1 -0
  123. package/dist/esm/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
  124. package/dist/esm/policies/auth/bearerAuthenticationPolicy.js +31 -0
  125. package/dist/esm/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
  126. package/dist/esm/policies/auth/checkInsecureConnection.d.ts +9 -0
  127. package/dist/esm/policies/auth/checkInsecureConnection.js +50 -0
  128. package/dist/esm/policies/auth/checkInsecureConnection.js.map +1 -0
  129. package/dist/esm/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
  130. package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js +31 -0
  131. package/dist/esm/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
  132. package/dist/esm/util/aborterUtils.d.ts +3 -4
  133. package/dist/esm/util/aborterUtils.js.map +1 -1
  134. package/dist/esm/util/helpers.d.ts +1 -2
  135. package/dist/esm/util/helpers.js.map +1 -1
  136. package/dist/react-native/auth/credentials.d.ts +77 -0
  137. package/dist/react-native/auth/credentials.js +27 -0
  138. package/dist/react-native/auth/credentials.js.map +1 -0
  139. package/dist/react-native/auth/oauth2Flows.d.ts +57 -0
  140. package/dist/react-native/auth/oauth2Flows.js +4 -0
  141. package/dist/react-native/auth/oauth2Flows.js.map +1 -0
  142. package/dist/react-native/auth/schemes.d.ts +53 -0
  143. package/dist/react-native/auth/schemes.js +4 -0
  144. package/dist/react-native/auth/schemes.js.map +1 -0
  145. package/dist/react-native/client/clientHelpers.d.ts +1 -20
  146. package/dist/react-native/client/clientHelpers.js +21 -30
  147. package/dist/react-native/client/clientHelpers.js.map +1 -1
  148. package/dist/react-native/client/common.d.ts +13 -15
  149. package/dist/react-native/client/common.js.map +1 -1
  150. package/dist/react-native/client/getClient.d.ts +1 -9
  151. package/dist/react-native/client/getClient.js +8 -16
  152. package/dist/react-native/client/getClient.js.map +1 -1
  153. package/dist/react-native/constants.js +1 -1
  154. package/dist/react-native/constants.js.map +1 -1
  155. package/dist/react-native/index.d.ts +3 -3
  156. package/dist/react-native/index.js +2 -2
  157. package/dist/react-native/index.js.map +1 -1
  158. package/dist/react-native/interfaces.d.ts +10 -2
  159. package/dist/react-native/interfaces.js.map +1 -1
  160. package/dist/react-native/pipelineRequest.d.ts +1 -2
  161. package/dist/react-native/pipelineRequest.js.map +1 -1
  162. package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.d.ts +30 -0
  163. package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js +31 -0
  164. package/dist/react-native/policies/auth/apiKeyAuthenticationPolicy.js.map +1 -0
  165. package/dist/react-native/policies/auth/basicAuthenticationPolicy.d.ts +30 -0
  166. package/dist/react-native/policies/auth/basicAuthenticationPolicy.js +31 -0
  167. package/dist/react-native/policies/auth/basicAuthenticationPolicy.js.map +1 -0
  168. package/dist/react-native/policies/auth/bearerAuthenticationPolicy.d.ts +30 -0
  169. package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js +31 -0
  170. package/dist/react-native/policies/auth/bearerAuthenticationPolicy.js.map +1 -0
  171. package/dist/react-native/policies/auth/checkInsecureConnection.d.ts +9 -0
  172. package/dist/react-native/policies/auth/checkInsecureConnection.js +50 -0
  173. package/dist/react-native/policies/auth/checkInsecureConnection.js.map +1 -0
  174. package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.d.ts +31 -0
  175. package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js +31 -0
  176. package/dist/react-native/policies/auth/oauth2AuthenticationPolicy.js.map +1 -0
  177. package/dist/react-native/util/aborterUtils.d.ts +3 -4
  178. package/dist/react-native/util/aborterUtils.js.map +1 -1
  179. package/dist/react-native/util/helpers.d.ts +1 -2
  180. package/dist/react-native/util/helpers.js.map +1 -1
  181. package/package.json +1 -1
  182. package/dist/browser/abort-controller/AbortSignalLike.d.ts +0 -19
  183. package/dist/browser/abort-controller/AbortSignalLike.js.map +0 -1
  184. package/dist/browser/accessTokenCache.d.ts +0 -40
  185. package/dist/browser/accessTokenCache.js +0 -32
  186. package/dist/browser/accessTokenCache.js.map +0 -1
  187. package/dist/browser/auth/keyCredential.d.ts +0 -16
  188. package/dist/browser/auth/keyCredential.js +0 -12
  189. package/dist/browser/auth/keyCredential.js.map +0 -1
  190. package/dist/browser/auth/tokenCredential.d.ts +0 -71
  191. package/dist/browser/auth/tokenCredential.js +0 -19
  192. package/dist/browser/auth/tokenCredential.js.map +0 -1
  193. package/dist/browser/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
  194. package/dist/browser/client/keyCredentialAuthenticationPolicy.js +0 -16
  195. package/dist/browser/client/keyCredentialAuthenticationPolicy.js.map +0 -1
  196. package/dist/browser/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
  197. package/dist/browser/policies/bearerTokenAuthenticationPolicy.js +0 -107
  198. package/dist/browser/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
  199. package/dist/browser/util/tokenCycler.d.ts +0 -45
  200. package/dist/browser/util/tokenCycler.js +0 -162
  201. package/dist/browser/util/tokenCycler.js.map +0 -1
  202. package/dist/commonjs/abort-controller/AbortSignalLike.d.ts +0 -19
  203. package/dist/commonjs/abort-controller/AbortSignalLike.js.map +0 -1
  204. package/dist/commonjs/accessTokenCache.d.ts +0 -40
  205. package/dist/commonjs/accessTokenCache.js +0 -36
  206. package/dist/commonjs/accessTokenCache.js.map +0 -1
  207. package/dist/commonjs/auth/keyCredential.d.ts +0 -16
  208. package/dist/commonjs/auth/keyCredential.js +0 -15
  209. package/dist/commonjs/auth/keyCredential.js.map +0 -1
  210. package/dist/commonjs/auth/tokenCredential.d.ts +0 -71
  211. package/dist/commonjs/auth/tokenCredential.js +0 -22
  212. package/dist/commonjs/auth/tokenCredential.js.map +0 -1
  213. package/dist/commonjs/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
  214. package/dist/commonjs/client/keyCredentialAuthenticationPolicy.js +0 -20
  215. package/dist/commonjs/client/keyCredentialAuthenticationPolicy.js.map +0 -1
  216. package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
  217. package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js +0 -111
  218. package/dist/commonjs/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
  219. package/dist/commonjs/util/tokenCycler.d.ts +0 -45
  220. package/dist/commonjs/util/tokenCycler.js +0 -166
  221. package/dist/commonjs/util/tokenCycler.js.map +0 -1
  222. package/dist/esm/abort-controller/AbortSignalLike.d.ts +0 -19
  223. package/dist/esm/abort-controller/AbortSignalLike.js.map +0 -1
  224. package/dist/esm/accessTokenCache.d.ts +0 -40
  225. package/dist/esm/accessTokenCache.js +0 -32
  226. package/dist/esm/accessTokenCache.js.map +0 -1
  227. package/dist/esm/auth/keyCredential.d.ts +0 -16
  228. package/dist/esm/auth/keyCredential.js +0 -12
  229. package/dist/esm/auth/keyCredential.js.map +0 -1
  230. package/dist/esm/auth/tokenCredential.d.ts +0 -71
  231. package/dist/esm/auth/tokenCredential.js +0 -19
  232. package/dist/esm/auth/tokenCredential.js.map +0 -1
  233. package/dist/esm/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
  234. package/dist/esm/client/keyCredentialAuthenticationPolicy.js +0 -16
  235. package/dist/esm/client/keyCredentialAuthenticationPolicy.js.map +0 -1
  236. package/dist/esm/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
  237. package/dist/esm/policies/bearerTokenAuthenticationPolicy.js +0 -107
  238. package/dist/esm/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
  239. package/dist/esm/util/tokenCycler.d.ts +0 -45
  240. package/dist/esm/util/tokenCycler.js +0 -162
  241. package/dist/esm/util/tokenCycler.js.map +0 -1
  242. package/dist/react-native/abort-controller/AbortSignalLike.d.ts +0 -19
  243. package/dist/react-native/abort-controller/AbortSignalLike.js.map +0 -1
  244. package/dist/react-native/accessTokenCache.d.ts +0 -40
  245. package/dist/react-native/accessTokenCache.js +0 -32
  246. package/dist/react-native/accessTokenCache.js.map +0 -1
  247. package/dist/react-native/auth/keyCredential.d.ts +0 -16
  248. package/dist/react-native/auth/keyCredential.js +0 -12
  249. package/dist/react-native/auth/keyCredential.js.map +0 -1
  250. package/dist/react-native/auth/tokenCredential.d.ts +0 -71
  251. package/dist/react-native/auth/tokenCredential.js +0 -19
  252. package/dist/react-native/auth/tokenCredential.js.map +0 -1
  253. package/dist/react-native/client/keyCredentialAuthenticationPolicy.d.ts +0 -8
  254. package/dist/react-native/client/keyCredentialAuthenticationPolicy.js +0 -16
  255. package/dist/react-native/client/keyCredentialAuthenticationPolicy.js.map +0 -1
  256. package/dist/react-native/policies/bearerTokenAuthenticationPolicy.d.ts +0 -99
  257. package/dist/react-native/policies/bearerTokenAuthenticationPolicy.js +0 -107
  258. package/dist/react-native/policies/bearerTokenAuthenticationPolicy.js.map +0 -1
  259. package/dist/react-native/util/tokenCycler.d.ts +0 -45
  260. package/dist/react-native/util/tokenCycler.js +0 -162
  261. package/dist/react-native/util/tokenCycler.js.map +0 -1
@@ -0,0 +1,31 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { stringToUint8Array, uint8ArrayToString } from "../../util/bytesEncoding.js";
4
+ import { ensureSecureConnection } from "./checkInsecureConnection.js";
5
+ /**
6
+ * Name of the Basic Authentication Policy
7
+ */
8
+ export const basicAuthenticationPolicyName = "bearerAuthenticationPolicy";
9
+ /**
10
+ * Gets a pipeline policy that adds basic authentication to requests
11
+ */
12
+ export function basicAuthenticationPolicy(options) {
13
+ return {
14
+ name: basicAuthenticationPolicyName,
15
+ async sendRequest(request, next) {
16
+ var _a, _b;
17
+ // Ensure allowInsecureConnection is explicitly set when sending request to non-https URLs
18
+ ensureSecureConnection(request, options);
19
+ const scheme = (_b = ((_a = request.authSchemes) !== null && _a !== void 0 ? _a : options.authSchemes)) === null || _b === void 0 ? void 0 : _b.find((x) => x.kind === "http" && x.scheme === "basic");
20
+ // Skip adding authentication header if no basic authentication scheme is found
21
+ if (!scheme) {
22
+ return next(request);
23
+ }
24
+ const { username, password } = options.credential;
25
+ const headerValue = uint8ArrayToString(stringToUint8Array(`${username}:${password}`, "utf-8"), "base64");
26
+ request.headers.set("Authorization", `Basic ${headerValue}`);
27
+ return next(request);
28
+ },
29
+ };
30
+ }
31
+ //# sourceMappingURL=basicAuthenticationPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basicAuthenticationPolicy.js","sourceRoot":"","sources":["../../../../src/policies/auth/basicAuthenticationPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,4BAA4B,CAAC;AAqB1E;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAyC;IAEzC,OAAO;QACL,IAAI,EAAE,6BAA6B;QACnC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;;YAC3D,0FAA0F;YAC1F,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAEzC,MAAM,MAAM,GAAG,MAAA,CAAC,MAAA,OAAO,CAAC,WAAW,mCAAI,OAAO,CAAC,WAAW,CAAC,0CAAE,IAAI,CAC/D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,MAAM,KAAK,OAAO,CACjD,CAAC;YAEF,+EAA+E;YAC/E,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YAED,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;YAClD,MAAM,WAAW,GAAG,kBAAkB,CACpC,kBAAkB,CAAC,GAAG,QAAQ,IAAI,QAAQ,EAAE,EAAE,OAAO,CAAC,EACtD,QAAQ,CACT,CAAC;YACF,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,SAAS,WAAW,EAAE,CAAC,CAAC;YAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BasicCredential } from \"../../auth/credentials.js\";\nimport type { AuthScheme } from \"../../auth/schemes.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../../interfaces.js\";\nimport type { PipelinePolicy } from \"../../pipeline.js\";\nimport { stringToUint8Array, uint8ArrayToString } from \"../../util/bytesEncoding.js\";\nimport { ensureSecureConnection } from \"./checkInsecureConnection.js\";\n\n/**\n * Name of the Basic Authentication Policy\n */\nexport const basicAuthenticationPolicyName = \"bearerAuthenticationPolicy\";\n\n/**\n * Options for configuring the basic authentication policy\n */\nexport interface BasicAuthenticationPolicyOptions {\n /**\n * The credential used to authenticate requests\n */\n credential: BasicCredential;\n /**\n * Optional authentication schemes to use. If not provided, schemes from the request will be used.\n */\n authSchemes?: AuthScheme[];\n /**\n * Allows for connecting to HTTP endpoints instead of enforcing HTTPS.\n * CAUTION: Never use this option in production.\n */\n allowInsecureConnection?: boolean;\n}\n\n/**\n * Gets a pipeline policy that adds basic authentication to requests\n */\nexport function basicAuthenticationPolicy(\n options: BasicAuthenticationPolicyOptions,\n): PipelinePolicy {\n return {\n name: basicAuthenticationPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n // Ensure allowInsecureConnection is explicitly set when sending request to non-https URLs\n ensureSecureConnection(request, options);\n\n const scheme = (request.authSchemes ?? options.authSchemes)?.find(\n (x) => x.kind === \"http\" && x.scheme === \"basic\",\n );\n\n // Skip adding authentication header if no basic authentication scheme is found\n if (!scheme) {\n return next(request);\n }\n\n const { username, password } = options.credential;\n const headerValue = uint8ArrayToString(\n stringToUint8Array(`${username}:${password}`, \"utf-8\"),\n \"base64\",\n );\n request.headers.set(\"Authorization\", `Basic ${headerValue}`);\n return next(request);\n },\n };\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import type { BearerTokenCredential } from "../../auth/credentials.js";
2
+ import type { AuthScheme } from "../../auth/schemes.js";
3
+ import type { PipelinePolicy } from "../../pipeline.js";
4
+ /**
5
+ * Name of the Bearer Authentication Policy
6
+ */
7
+ export declare const bearerAuthenticationPolicyName = "bearerAuthenticationPolicy";
8
+ /**
9
+ * Options for configuring the bearer authentication policy
10
+ */
11
+ export interface BearerAuthenticationPolicyOptions {
12
+ /**
13
+ * The BearerTokenCredential implementation that can supply the bearer token.
14
+ */
15
+ credential: BearerTokenCredential;
16
+ /**
17
+ * Optional authentication schemes to use. If not provided, schemes from the request will be used.
18
+ */
19
+ authSchemes?: AuthScheme[];
20
+ /**
21
+ * Allows for connecting to HTTP endpoints instead of enforcing HTTPS.
22
+ * CAUTION: Never use this option in production.
23
+ */
24
+ allowInsecureConnection?: boolean;
25
+ }
26
+ /**
27
+ * Gets a pipeline policy that adds bearer token authentication to requests
28
+ */
29
+ export declare function bearerAuthenticationPolicy(options: BearerAuthenticationPolicyOptions): PipelinePolicy;
30
+ //# sourceMappingURL=bearerAuthenticationPolicy.d.ts.map
@@ -0,0 +1,31 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { ensureSecureConnection } from "./checkInsecureConnection.js";
4
+ /**
5
+ * Name of the Bearer Authentication Policy
6
+ */
7
+ export const bearerAuthenticationPolicyName = "bearerAuthenticationPolicy";
8
+ /**
9
+ * Gets a pipeline policy that adds bearer token authentication to requests
10
+ */
11
+ export function bearerAuthenticationPolicy(options) {
12
+ return {
13
+ name: bearerAuthenticationPolicyName,
14
+ async sendRequest(request, next) {
15
+ var _a, _b;
16
+ // Ensure allowInsecureConnection is explicitly set when sending request to non-https URLs
17
+ ensureSecureConnection(request, options);
18
+ const scheme = (_b = ((_a = request.authSchemes) !== null && _a !== void 0 ? _a : options.authSchemes)) === null || _b === void 0 ? void 0 : _b.find((x) => x.kind === "http" && x.scheme === "bearer");
19
+ // Skip adding authentication header if no bearer authentication scheme is found
20
+ if (!scheme) {
21
+ return next(request);
22
+ }
23
+ const token = await options.credential.getBearerToken({
24
+ abortSignal: request.abortSignal,
25
+ });
26
+ request.headers.set("Authorization", `Bearer ${token}`);
27
+ return next(request);
28
+ },
29
+ };
30
+ }
31
+ //# sourceMappingURL=bearerAuthenticationPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bearerAuthenticationPolicy.js","sourceRoot":"","sources":["../../../../src/policies/auth/bearerAuthenticationPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAMlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,4BAA4B,CAAC;AAqB3E;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAA0C;IAE1C,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;;YAC3D,0FAA0F;YAC1F,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAEzC,MAAM,MAAM,GAAG,MAAA,CAAC,MAAA,OAAO,CAAC,WAAW,mCAAI,OAAO,CAAC,WAAW,CAAC,0CAAE,IAAI,CAC/D,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,MAAM,KAAK,QAAQ,CAClD,CAAC;YAEF,gFAAgF;YAChF,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YAED,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC;gBACpD,WAAW,EAAE,OAAO,CAAC,WAAW;aACjC,CAAC,CAAC;YACH,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { BearerTokenCredential } from \"../../auth/credentials.js\";\nimport type { AuthScheme } from \"../../auth/schemes.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../../interfaces.js\";\nimport type { PipelinePolicy } from \"../../pipeline.js\";\nimport { ensureSecureConnection } from \"./checkInsecureConnection.js\";\n\n/**\n * Name of the Bearer Authentication Policy\n */\nexport const bearerAuthenticationPolicyName = \"bearerAuthenticationPolicy\";\n\n/**\n * Options for configuring the bearer authentication policy\n */\nexport interface BearerAuthenticationPolicyOptions {\n /**\n * The BearerTokenCredential implementation that can supply the bearer token.\n */\n credential: BearerTokenCredential;\n /**\n * Optional authentication schemes to use. If not provided, schemes from the request will be used.\n */\n authSchemes?: AuthScheme[];\n /**\n * Allows for connecting to HTTP endpoints instead of enforcing HTTPS.\n * CAUTION: Never use this option in production.\n */\n allowInsecureConnection?: boolean;\n}\n\n/**\n * Gets a pipeline policy that adds bearer token authentication to requests\n */\nexport function bearerAuthenticationPolicy(\n options: BearerAuthenticationPolicyOptions,\n): PipelinePolicy {\n return {\n name: bearerAuthenticationPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n // Ensure allowInsecureConnection is explicitly set when sending request to non-https URLs\n ensureSecureConnection(request, options);\n\n const scheme = (request.authSchemes ?? options.authSchemes)?.find(\n (x) => x.kind === \"http\" && x.scheme === \"bearer\",\n );\n\n // Skip adding authentication header if no bearer authentication scheme is found\n if (!scheme) {\n return next(request);\n }\n\n const token = await options.credential.getBearerToken({\n abortSignal: request.abortSignal,\n });\n request.headers.set(\"Authorization\", `Bearer ${token}`);\n return next(request);\n },\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { PipelineRequest } from "../../interfaces.js";
2
+ /**
3
+ * Ensures that authentication is only allowed over HTTPS unless explicitly allowed.
4
+ * Throws an error if the connection is not secure and not explicitly allowed.
5
+ */
6
+ export declare function ensureSecureConnection(request: PipelineRequest, options: {
7
+ allowInsecureConnection?: boolean;
8
+ }): void;
9
+ //# sourceMappingURL=checkInsecureConnection.d.ts.map
@@ -0,0 +1,50 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { logger } from "../../log.js";
4
+ // Ensure the warining is only emitted once
5
+ let insecureConnectionWarningEmmitted = false;
6
+ /**
7
+ * Checks if the request is allowed to be sent over an insecure connection.
8
+ *
9
+ * A request is allowed to be sent over an insecure connection when:
10
+ * - The `allowInsecureConnection` option is set to `true`.
11
+ * - The request has the `allowInsecureConnection` property set to `true`.
12
+ * - The request is being sent to `localhost` or `127.0.0.1`
13
+ */
14
+ function allowInsecureConnection(request, options) {
15
+ if (options.allowInsecureConnection && request.allowInsecureConnection) {
16
+ const url = new URL(request.url);
17
+ if (url.hostname === "localhost" || url.hostname === "127.0.0.1") {
18
+ return true;
19
+ }
20
+ }
21
+ return false;
22
+ }
23
+ /**
24
+ * Logs a warning about sending a bearer token over an insecure connection.
25
+ *
26
+ * This function will emit a node warning once, but log the warning every time.
27
+ */
28
+ function emitInsecureConnectionWarning() {
29
+ const warning = "Sending bearer token over insecure transport. Assume any token issued is compromised.";
30
+ logger.warning(warning);
31
+ if (typeof (process === null || process === void 0 ? void 0 : process.emitWarning) === "function" && !insecureConnectionWarningEmmitted) {
32
+ insecureConnectionWarningEmmitted = true;
33
+ process.emitWarning(warning);
34
+ }
35
+ }
36
+ /**
37
+ * Ensures that authentication is only allowed over HTTPS unless explicitly allowed.
38
+ * Throws an error if the connection is not secure and not explicitly allowed.
39
+ */
40
+ export function ensureSecureConnection(request, options) {
41
+ if (!request.url.toLowerCase().startsWith("https://")) {
42
+ if (allowInsecureConnection(request, options)) {
43
+ emitInsecureConnectionWarning();
44
+ }
45
+ else {
46
+ throw new Error("Authentication is not permitted for non-TLS protected (non-https) URLs when allowInsecureConnection is false.");
47
+ }
48
+ }
49
+ }
50
+ //# sourceMappingURL=checkInsecureConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkInsecureConnection.js","sourceRoot":"","sources":["../../../../src/policies/auth/checkInsecureConnection.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAEtC,2CAA2C;AAC3C,IAAI,iCAAiC,GAAG,KAAK,CAAC;AAE9C;;;;;;;GAOG;AACH,SAAS,uBAAuB,CAC9B,OAAwB,EACxB,OAA8C;IAE9C,IAAI,OAAO,CAAC,uBAAuB,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC;QACvE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjC,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YACjE,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,SAAS,6BAA6B;IACpC,MAAM,OAAO,GACX,uFAAuF,CAAC;IAE1F,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAExB,IAAI,OAAO,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAA,KAAK,UAAU,IAAI,CAAC,iCAAiC,EAAE,CAAC;QACrF,iCAAiC,GAAG,IAAI,CAAC;QACzC,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,OAAwB,EACxB,OAA8C;IAE9C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACtD,IAAI,uBAAuB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;YAC9C,6BAA6B,EAAE,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CACb,+GAA+G,CAChH,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelineRequest } from \"../../interfaces.js\";\nimport { logger } from \"../../log.js\";\n\n// Ensure the warining is only emitted once\nlet insecureConnectionWarningEmmitted = false;\n\n/**\n * Checks if the request is allowed to be sent over an insecure connection.\n *\n * A request is allowed to be sent over an insecure connection when:\n * - The `allowInsecureConnection` option is set to `true`.\n * - The request has the `allowInsecureConnection` property set to `true`.\n * - The request is being sent to `localhost` or `127.0.0.1`\n */\nfunction allowInsecureConnection(\n request: PipelineRequest,\n options: { allowInsecureConnection?: boolean },\n): boolean {\n if (options.allowInsecureConnection && request.allowInsecureConnection) {\n const url = new URL(request.url);\n if (url.hostname === \"localhost\" || url.hostname === \"127.0.0.1\") {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * Logs a warning about sending a bearer token over an insecure connection.\n *\n * This function will emit a node warning once, but log the warning every time.\n */\nfunction emitInsecureConnectionWarning(): void {\n const warning =\n \"Sending bearer token over insecure transport. Assume any token issued is compromised.\";\n\n logger.warning(warning);\n\n if (typeof process?.emitWarning === \"function\" && !insecureConnectionWarningEmmitted) {\n insecureConnectionWarningEmmitted = true;\n process.emitWarning(warning);\n }\n}\n\n/**\n * Ensures that authentication is only allowed over HTTPS unless explicitly allowed.\n * Throws an error if the connection is not secure and not explicitly allowed.\n */\nexport function ensureSecureConnection(\n request: PipelineRequest,\n options: { allowInsecureConnection?: boolean },\n): void {\n if (!request.url.toLowerCase().startsWith(\"https://\")) {\n if (allowInsecureConnection(request, options)) {\n emitInsecureConnectionWarning();\n } else {\n throw new Error(\n \"Authentication is not permitted for non-TLS protected (non-https) URLs when allowInsecureConnection is false.\",\n );\n }\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import type { OAuth2Flow } from "../../auth/oauth2Flows.js";
2
+ import type { OAuth2TokenCredential } from "../../auth/credentials.js";
3
+ import type { AuthScheme } from "../../auth/schemes.js";
4
+ import type { PipelinePolicy } from "../../pipeline.js";
5
+ /**
6
+ * Name of the OAuth2 Authentication Policy
7
+ */
8
+ export declare const oauth2AuthenticationPolicyName = "oauth2AuthenticationPolicy";
9
+ /**
10
+ * Options for configuring the OAuth2 authentication policy
11
+ */
12
+ export interface OAuth2AuthenticationPolicyOptions<TFlows extends OAuth2Flow> {
13
+ /**
14
+ * The OAuth2TokenCredential implementation that can supply the bearer token.
15
+ */
16
+ credential: OAuth2TokenCredential<TFlows>;
17
+ /**
18
+ * Optional authentication schemes to use. If not provided, schemes from the request will be used.
19
+ */
20
+ authSchemes?: AuthScheme[];
21
+ /**
22
+ * Allows for connecting to HTTP endpoints instead of enforcing HTTPS.
23
+ * CAUTION: Never use this option in production.
24
+ */
25
+ allowInsecureConnection?: boolean;
26
+ }
27
+ /**
28
+ * Gets a pipeline policy that adds authorization header from OAuth2 schemes
29
+ */
30
+ export declare function oauth2AuthenticationPolicy<TFlows extends OAuth2Flow>(options: OAuth2AuthenticationPolicyOptions<TFlows>): PipelinePolicy;
31
+ //# sourceMappingURL=oauth2AuthenticationPolicy.d.ts.map
@@ -0,0 +1,31 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { ensureSecureConnection } from "./checkInsecureConnection.js";
4
+ /**
5
+ * Name of the OAuth2 Authentication Policy
6
+ */
7
+ export const oauth2AuthenticationPolicyName = "oauth2AuthenticationPolicy";
8
+ /**
9
+ * Gets a pipeline policy that adds authorization header from OAuth2 schemes
10
+ */
11
+ export function oauth2AuthenticationPolicy(options) {
12
+ return {
13
+ name: oauth2AuthenticationPolicyName,
14
+ async sendRequest(request, next) {
15
+ var _a, _b;
16
+ // Ensure allowInsecureConnection is explicitly set when sending request to non-https URLs
17
+ ensureSecureConnection(request, options);
18
+ const scheme = (_b = ((_a = request.authSchemes) !== null && _a !== void 0 ? _a : options.authSchemes)) === null || _b === void 0 ? void 0 : _b.find((x) => x.kind === "oauth2");
19
+ // Skip adding authentication header if no OAuth2 authentication scheme is found
20
+ if (!scheme) {
21
+ return next(request);
22
+ }
23
+ const token = await options.credential.getOAuth2Token(scheme.flows, {
24
+ abortSignal: request.abortSignal,
25
+ });
26
+ request.headers.set("Authorization", `Bearer ${token}`);
27
+ return next(request);
28
+ },
29
+ };
30
+ }
31
+ //# sourceMappingURL=oauth2AuthenticationPolicy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2AuthenticationPolicy.js","sourceRoot":"","sources":["../../../../src/policies/auth/oauth2AuthenticationPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAOlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,4BAA4B,CAAC;AAqB3E;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,OAAkD;IAElD,OAAO;QACL,IAAI,EAAE,8BAA8B;QACpC,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;;YAC3D,0FAA0F;YAC1F,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAEzC,MAAM,MAAM,GAAG,MAAA,CAAC,MAAA,OAAO,CAAC,WAAW,mCAAI,OAAO,CAAC,WAAW,CAAC,0CAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;YAE9F,gFAAgF;YAChF,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,CAAC;YACD,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,KAAiB,EAAE;gBAC9E,WAAW,EAAE,OAAO,CAAC,WAAW;aACjC,CAAC,CAAC;YACH,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,KAAK,EAAE,CAAC,CAAC;YACxD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OAuth2Flow } from \"../../auth/oauth2Flows.js\";\nimport type { OAuth2TokenCredential } from \"../../auth/credentials.js\";\nimport type { AuthScheme } from \"../../auth/schemes.js\";\nimport type { PipelineRequest, PipelineResponse, SendRequest } from \"../../interfaces.js\";\nimport type { PipelinePolicy } from \"../../pipeline.js\";\nimport { ensureSecureConnection } from \"./checkInsecureConnection.js\";\n\n/**\n * Name of the OAuth2 Authentication Policy\n */\nexport const oauth2AuthenticationPolicyName = \"oauth2AuthenticationPolicy\";\n\n/**\n * Options for configuring the OAuth2 authentication policy\n */\nexport interface OAuth2AuthenticationPolicyOptions<TFlows extends OAuth2Flow> {\n /**\n * The OAuth2TokenCredential implementation that can supply the bearer token.\n */\n credential: OAuth2TokenCredential<TFlows>;\n /**\n * Optional authentication schemes to use. If not provided, schemes from the request will be used.\n */\n authSchemes?: AuthScheme[];\n /**\n * Allows for connecting to HTTP endpoints instead of enforcing HTTPS.\n * CAUTION: Never use this option in production.\n */\n allowInsecureConnection?: boolean;\n}\n\n/**\n * Gets a pipeline policy that adds authorization header from OAuth2 schemes\n */\nexport function oauth2AuthenticationPolicy<TFlows extends OAuth2Flow>(\n options: OAuth2AuthenticationPolicyOptions<TFlows>,\n): PipelinePolicy {\n return {\n name: oauth2AuthenticationPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n // Ensure allowInsecureConnection is explicitly set when sending request to non-https URLs\n ensureSecureConnection(request, options);\n\n const scheme = (request.authSchemes ?? options.authSchemes)?.find((x) => x.kind === \"oauth2\");\n\n // Skip adding authentication header if no OAuth2 authentication scheme is found\n if (!scheme) {\n return next(request);\n }\n const token = await options.credential.getOAuth2Token(scheme.flows as TFlows[], {\n abortSignal: request.abortSignal,\n });\n request.headers.set(\"Authorization\", `Bearer ${token}`);\n return next(request);\n },\n };\n}\n"]}
@@ -1,4 +1,3 @@
1
- import type { AbortSignalLike } from "../abort-controller/AbortSignalLike.js";
2
1
  /**
3
2
  * Options related to abort controller.
4
3
  */
@@ -6,7 +5,7 @@ export interface AbortOptions {
6
5
  /**
7
6
  * The abortSignal associated with containing operation.
8
7
  */
9
- abortSignal?: AbortSignalLike;
8
+ abortSignal?: AbortSignal;
10
9
  /**
11
10
  * The abort error message associated with containing operation.
12
11
  */
@@ -16,12 +15,12 @@ export interface AbortOptions {
16
15
  * Represents a function that returns a promise that can be aborted.
17
16
  */
18
17
  export type AbortablePromiseBuilder<T> = (abortOptions: {
19
- abortSignal?: AbortSignalLike;
18
+ abortSignal?: AbortSignal;
20
19
  }) => Promise<T>;
21
20
  /**
22
21
  * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.
23
22
  */
24
23
  export declare function cancelablePromiseRace<T extends unknown[]>(abortablePromiseBuilders: AbortablePromiseBuilder<T[number]>[], options?: {
25
- abortSignal?: AbortSignalLike;
24
+ abortSignal?: AbortSignal;
26
25
  }): Promise<T[number]>;
27
26
  //# sourceMappingURL=aborterUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aborterUtils.js","sourceRoot":"","sources":["../../../src/util/aborterUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAyBlC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,wBAA8D,EAC9D,OAA2C;;IAE3C,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IACtC,SAAS,YAAY;QACnB,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IACD,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CACvB,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CACxE,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACnE,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\n\n/**\n * Options related to abort controller.\n */\nexport interface AbortOptions {\n /**\n * The abortSignal associated with containing operation.\n */\n abortSignal?: AbortSignalLike;\n /**\n * The abort error message associated with containing operation.\n */\n abortErrorMsg?: string;\n}\n\n/**\n * Represents a function that returns a promise that can be aborted.\n */\nexport type AbortablePromiseBuilder<T> = (abortOptions: {\n abortSignal?: AbortSignalLike;\n}) => Promise<T>;\n\n/**\n * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.\n */\nexport async function cancelablePromiseRace<T extends unknown[]>(\n abortablePromiseBuilders: AbortablePromiseBuilder<T[number]>[],\n options?: { abortSignal?: AbortSignalLike },\n): Promise<T[number]> {\n const aborter = new AbortController();\n function abortHandler(): void {\n aborter.abort();\n }\n options?.abortSignal?.addEventListener(\"abort\", abortHandler);\n try {\n return await Promise.race(\n abortablePromiseBuilders.map((p) => p({ abortSignal: aborter.signal })),\n );\n } finally {\n aborter.abort();\n options?.abortSignal?.removeEventListener(\"abort\", abortHandler);\n }\n}\n"]}
1
+ {"version":3,"file":"aborterUtils.js","sourceRoot":"","sources":["../../../src/util/aborterUtils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAuBlC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,wBAA8D,EAC9D,OAAuC;;IAEvC,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IACtC,SAAS,YAAY;QACnB,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;IACD,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,OAAO,MAAM,OAAO,CAAC,IAAI,CACvB,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CACxE,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,0CAAE,mBAAmB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACnE,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Options related to abort controller.\n */\nexport interface AbortOptions {\n /**\n * The abortSignal associated with containing operation.\n */\n abortSignal?: AbortSignal;\n /**\n * The abort error message associated with containing operation.\n */\n abortErrorMsg?: string;\n}\n\n/**\n * Represents a function that returns a promise that can be aborted.\n */\nexport type AbortablePromiseBuilder<T> = (abortOptions: {\n abortSignal?: AbortSignal;\n}) => Promise<T>;\n\n/**\n * promise.race() wrapper that aborts rest of promises as soon as the first promise settles.\n */\nexport async function cancelablePromiseRace<T extends unknown[]>(\n abortablePromiseBuilders: AbortablePromiseBuilder<T[number]>[],\n options?: { abortSignal?: AbortSignal },\n): Promise<T[number]> {\n const aborter = new AbortController();\n function abortHandler(): void {\n aborter.abort();\n }\n options?.abortSignal?.addEventListener(\"abort\", abortHandler);\n try {\n return await Promise.race(\n abortablePromiseBuilders.map((p) => p({ abortSignal: aborter.signal })),\n );\n } finally {\n aborter.abort();\n options?.abortSignal?.removeEventListener(\"abort\", abortHandler);\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- import type { AbortSignalLike } from "../abort-controller/AbortSignalLike.js";
2
1
  import type { PipelineResponse } from "../interfaces.js";
3
2
  /**
4
3
  * A wrapper for setTimeout that resolves a promise after delayInMs milliseconds.
@@ -10,7 +9,7 @@ import type { PipelineResponse } from "../interfaces.js";
10
9
  * @returns Resolved promise
11
10
  */
12
11
  export declare function delay<T>(delayInMs: number, value?: T, options?: {
13
- abortSignal?: AbortSignalLike;
12
+ abortSignal?: AbortSignal;
14
13
  abortErrorMsg?: string;
15
14
  }): Promise<T | void>;
16
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/util/helpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAI/D,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CACnB,SAAiB,EACjB,KAAS,EACT,OAGC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,KAAK,GAA8C,SAAS,CAAC;QACjE,IAAI,SAAS,GAA6B,SAAS,CAAC;QAEpD,MAAM,aAAa,GAAG,GAAS,EAAE;YAC/B,OAAO,MAAM,CACX,IAAI,UAAU,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,EAAC,CAAC,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,CAAC,CAAC,CAAC,oBAAoB,CAAC,CACvF,CAAC;QACJ,CAAC,CAAC;QAEF,MAAM,eAAe,GAAG,GAAS,EAAE;YACjC,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,SAAS,EAAE,CAAC;gBACtC,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC,CAAC;QAEF,SAAS,GAAG,GAAS,EAAE;YACrB,IAAI,KAAK,EAAE,CAAC;gBACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YACD,eAAe,EAAE,CAAC;YAClB,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC,CAAC;QAEF,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YACxD,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC;QAED,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,eAAe,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,EAAE,SAAS,CAAC,CAAC;QAEd,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAE,CAAC;YACzB,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA0B,EAC1B,UAAkB;IAElB,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;QAAE,OAAO;IACrC,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { PipelineResponse } from \"../interfaces.js\";\n\nconst StandardAbortMessage = \"The operation was aborted.\";\n\n/**\n * A wrapper for setTimeout that resolves a promise after delayInMs milliseconds.\n * @param delayInMs - The number of milliseconds to be delayed.\n * @param value - The value to be resolved with after a timeout of t milliseconds.\n * @param options - The options for delay - currently abort options\n * - abortSignal - The abortSignal associated with containing operation.\n * - abortErrorMsg - The abort error message associated with containing operation.\n * @returns Resolved promise\n */\nexport function delay<T>(\n delayInMs: number,\n value?: T,\n options?: {\n abortSignal?: AbortSignalLike;\n abortErrorMsg?: string;\n },\n): Promise<T | void> {\n return new Promise((resolve, reject) => {\n let timer: ReturnType<typeof setTimeout> | undefined = undefined;\n let onAborted: (() => void) | undefined = undefined;\n\n const rejectOnAbort = (): void => {\n return reject(\n new AbortError(options?.abortErrorMsg ? options?.abortErrorMsg : StandardAbortMessage),\n );\n };\n\n const removeListeners = (): void => {\n if (options?.abortSignal && onAborted) {\n options.abortSignal.removeEventListener(\"abort\", onAborted);\n }\n };\n\n onAborted = (): void => {\n if (timer) {\n clearTimeout(timer);\n }\n removeListeners();\n return rejectOnAbort();\n };\n\n if (options?.abortSignal && options.abortSignal.aborted) {\n return rejectOnAbort();\n }\n\n timer = setTimeout(() => {\n removeListeners();\n resolve(value);\n }, delayInMs);\n\n if (options?.abortSignal) {\n options.abortSignal.addEventListener(\"abort\", onAborted);\n }\n });\n}\n\n/**\n * @internal\n * @returns the parsed value or undefined if the parsed value is invalid.\n */\nexport function parseHeaderValueAsNumber(\n response: PipelineResponse,\n headerName: string,\n): number | undefined {\n const value = response.headers.get(headerName);\n if (!value) return;\n const valueAsNum = Number(value);\n if (Number.isNaN(valueAsNum)) return;\n return valueAsNum;\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/util/helpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAG/D,MAAM,oBAAoB,GAAG,4BAA4B,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CACnB,SAAiB,EACjB,KAAS,EACT,OAGC;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,KAAK,GAA8C,SAAS,CAAC;QACjE,IAAI,SAAS,GAA6B,SAAS,CAAC;QAEpD,MAAM,aAAa,GAAG,GAAS,EAAE;YAC/B,OAAO,MAAM,CACX,IAAI,UAAU,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,EAAC,CAAC,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,CAAC,CAAC,CAAC,oBAAoB,CAAC,CACvF,CAAC;QACJ,CAAC,CAAC;QAEF,MAAM,eAAe,GAAG,GAAS,EAAE;YACjC,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,SAAS,EAAE,CAAC;gBACtC,OAAO,CAAC,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC,CAAC;QAEF,SAAS,GAAG,GAAS,EAAE;YACrB,IAAI,KAAK,EAAE,CAAC;gBACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACtB,CAAC;YACD,eAAe,EAAE,CAAC;YAClB,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC,CAAC;QAEF,IAAI,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,KAAI,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;YACxD,OAAO,aAAa,EAAE,CAAC;QACzB,CAAC;QAED,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,eAAe,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,EAAE,SAAS,CAAC,CAAC;QAEd,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,EAAE,CAAC;YACzB,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3D,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,QAA0B,EAC1B,UAAkB;IAElB,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO;IACnB,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACjC,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;QAAE,OAAO;IACrC,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { AbortError } from \"../abort-controller/AbortError.js\";\nimport type { PipelineResponse } from \"../interfaces.js\";\n\nconst StandardAbortMessage = \"The operation was aborted.\";\n\n/**\n * A wrapper for setTimeout that resolves a promise after delayInMs milliseconds.\n * @param delayInMs - The number of milliseconds to be delayed.\n * @param value - The value to be resolved with after a timeout of t milliseconds.\n * @param options - The options for delay - currently abort options\n * - abortSignal - The abortSignal associated with containing operation.\n * - abortErrorMsg - The abort error message associated with containing operation.\n * @returns Resolved promise\n */\nexport function delay<T>(\n delayInMs: number,\n value?: T,\n options?: {\n abortSignal?: AbortSignal;\n abortErrorMsg?: string;\n },\n): Promise<T | void> {\n return new Promise((resolve, reject) => {\n let timer: ReturnType<typeof setTimeout> | undefined = undefined;\n let onAborted: (() => void) | undefined = undefined;\n\n const rejectOnAbort = (): void => {\n return reject(\n new AbortError(options?.abortErrorMsg ? options?.abortErrorMsg : StandardAbortMessage),\n );\n };\n\n const removeListeners = (): void => {\n if (options?.abortSignal && onAborted) {\n options.abortSignal.removeEventListener(\"abort\", onAborted);\n }\n };\n\n onAborted = (): void => {\n if (timer) {\n clearTimeout(timer);\n }\n removeListeners();\n return rejectOnAbort();\n };\n\n if (options?.abortSignal && options.abortSignal.aborted) {\n return rejectOnAbort();\n }\n\n timer = setTimeout(() => {\n removeListeners();\n resolve(value);\n }, delayInMs);\n\n if (options?.abortSignal) {\n options.abortSignal.addEventListener(\"abort\", onAborted);\n }\n });\n}\n\n/**\n * @internal\n * @returns the parsed value or undefined if the parsed value is invalid.\n */\nexport function parseHeaderValueAsNumber(\n response: PipelineResponse,\n headerName: string,\n): number | undefined {\n const value = response.headers.get(headerName);\n if (!value) return;\n const valueAsNum = Number(value);\n if (Number.isNaN(valueAsNum)) return;\n return valueAsNum;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/ts-http-runtime",
3
- "version": "0.1.0-alpha.20250325.2",
3
+ "version": "0.2.0-alpha.20250326.3",
4
4
  "description": "Isomorphic client library for making HTTP requests in node.js and browser.",
5
5
  "sdk-type": "client",
6
6
  "type": "module",
@@ -1,19 +0,0 @@
1
- /**
2
- * Allows the request to be aborted upon firing of the "abort" event.
3
- * Compatible with the browser built-in AbortSignal and common polyfills.
4
- */
5
- export interface AbortSignalLike {
6
- /**
7
- * Indicates if the signal has already been aborted.
8
- */
9
- readonly aborted: boolean;
10
- /**
11
- * Add new "abort" event listener, only support "abort" event.
12
- */
13
- addEventListener(type: "abort", listener: (this: AbortSignalLike, ev: any) => any, options?: any): void;
14
- /**
15
- * Remove "abort" event listener, only support "abort" event.
16
- */
17
- removeEventListener(type: "abort", listener: (this: AbortSignalLike, ev: any) => any, options?: any): void;
18
- }
19
- //# sourceMappingURL=AbortSignalLike.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AbortSignalLike.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortSignalLike.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Allows the request to be aborted upon firing of the \"abort\" event.\n * Compatible with the browser built-in AbortSignal and common polyfills.\n */\nexport interface AbortSignalLike {\n /**\n * Indicates if the signal has already been aborted.\n */\n readonly aborted: boolean;\n /**\n * Add new \"abort\" event listener, only support \"abort\" event.\n */\n addEventListener(\n type: \"abort\",\n listener: (this: AbortSignalLike, ev: any) => any,\n options?: any,\n ): void;\n /**\n * Remove \"abort\" event listener, only support \"abort\" event.\n */\n removeEventListener(\n type: \"abort\",\n listener: (this: AbortSignalLike, ev: any) => any,\n options?: any,\n ): void;\n}\n"]}
@@ -1,40 +0,0 @@
1
- import type { AccessToken } from "./auth/tokenCredential.js";
2
- /**
3
- * Defines the default token refresh buffer duration.
4
- */
5
- export declare const DefaultTokenRefreshBufferMs: number;
6
- /**
7
- * Provides a cache for an AccessToken that was that
8
- * was returned from a TokenCredential.
9
- */
10
- export interface AccessTokenCache {
11
- /**
12
- * Sets the cached token.
13
- *
14
- * @param accessToken - The AccessToken to be cached or null to
15
- * clear the cached token.
16
- */
17
- setCachedToken(accessToken: AccessToken | undefined): void;
18
- /**
19
- * Returns the cached AccessToken or undefined if nothing is cached.
20
- */
21
- getCachedToken(): AccessToken | undefined;
22
- }
23
- /**
24
- * Provides an AccessTokenCache implementation which clears
25
- * the cached AccessToken's after the expiresOnTimestamp has
26
- * passed.
27
- * @internal
28
- */
29
- export declare class ExpiringAccessTokenCache implements AccessTokenCache {
30
- private tokenRefreshBufferMs;
31
- private cachedToken?;
32
- /**
33
- * Constructs an instance of ExpiringAccessTokenCache with
34
- * an optional expiration buffer time.
35
- */
36
- constructor(tokenRefreshBufferMs?: number);
37
- setCachedToken(accessToken: AccessToken | undefined): void;
38
- getCachedToken(): AccessToken | undefined;
39
- }
40
- //# sourceMappingURL=accessTokenCache.d.ts.map
@@ -1,32 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /**
4
- * Defines the default token refresh buffer duration.
5
- */
6
- export const DefaultTokenRefreshBufferMs = 2 * 60 * 1000; // 2 Minutes
7
- /**
8
- * Provides an AccessTokenCache implementation which clears
9
- * the cached AccessToken's after the expiresOnTimestamp has
10
- * passed.
11
- * @internal
12
- */
13
- export class ExpiringAccessTokenCache {
14
- /**
15
- * Constructs an instance of ExpiringAccessTokenCache with
16
- * an optional expiration buffer time.
17
- */
18
- constructor(tokenRefreshBufferMs = DefaultTokenRefreshBufferMs) {
19
- this.tokenRefreshBufferMs = tokenRefreshBufferMs;
20
- }
21
- setCachedToken(accessToken) {
22
- this.cachedToken = accessToken;
23
- }
24
- getCachedToken() {
25
- if (this.cachedToken &&
26
- Date.now() + this.tokenRefreshBufferMs >= this.cachedToken.expiresOnTimestamp) {
27
- this.cachedToken = undefined;
28
- }
29
- return this.cachedToken;
30
- }
31
- }
32
- //# sourceMappingURL=accessTokenCache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accessTokenCache.js","sourceRoot":"","sources":["../../src/accessTokenCache.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAqBtE;;;;;GAKG;AACH,MAAM,OAAO,wBAAwB;IAInC;;;OAGG;IACH,YAAY,uBAA+B,2BAA2B;QACpE,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACnD,CAAC;IAED,cAAc,CAAC,WAAoC;QACjD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED,cAAc;QACZ,IACE,IAAI,CAAC,WAAW;YAChB,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAC7E,CAAC;YACD,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC/B,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AccessToken } from \"./auth/tokenCredential.js\";\n\n/**\n * Defines the default token refresh buffer duration.\n */\nexport const DefaultTokenRefreshBufferMs = 2 * 60 * 1000; // 2 Minutes\n\n/**\n * Provides a cache for an AccessToken that was that\n * was returned from a TokenCredential.\n */\nexport interface AccessTokenCache {\n /**\n * Sets the cached token.\n *\n * @param accessToken - The AccessToken to be cached or null to\n * clear the cached token.\n */\n setCachedToken(accessToken: AccessToken | undefined): void;\n\n /**\n * Returns the cached AccessToken or undefined if nothing is cached.\n */\n getCachedToken(): AccessToken | undefined;\n}\n\n/**\n * Provides an AccessTokenCache implementation which clears\n * the cached AccessToken's after the expiresOnTimestamp has\n * passed.\n * @internal\n */\nexport class ExpiringAccessTokenCache implements AccessTokenCache {\n private tokenRefreshBufferMs: number;\n private cachedToken?: AccessToken;\n\n /**\n * Constructs an instance of ExpiringAccessTokenCache with\n * an optional expiration buffer time.\n */\n constructor(tokenRefreshBufferMs: number = DefaultTokenRefreshBufferMs) {\n this.tokenRefreshBufferMs = tokenRefreshBufferMs;\n }\n\n setCachedToken(accessToken: AccessToken | undefined): void {\n this.cachedToken = accessToken;\n }\n\n getCachedToken(): AccessToken | undefined {\n if (\n this.cachedToken &&\n Date.now() + this.tokenRefreshBufferMs >= this.cachedToken.expiresOnTimestamp\n ) {\n this.cachedToken = undefined;\n }\n\n return this.cachedToken;\n }\n}\n"]}
@@ -1,16 +0,0 @@
1
- /**
2
- * Represents a credential defined by a static API key.
3
- */
4
- export interface KeyCredential {
5
- /**
6
- * The value of the API key represented as a string
7
- */
8
- readonly key: string;
9
- }
10
- /**
11
- * Tests an object to determine whether it implements KeyCredential.
12
- *
13
- * @param credential - The assumed KeyCredential to be tested.
14
- */
15
- export declare function isKeyCredential(credential: unknown): credential is KeyCredential;
16
- //# sourceMappingURL=keyCredential.d.ts.map
@@ -1,12 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { isObjectWithProperties } from "../util/typeGuards.js";
4
- /**
5
- * Tests an object to determine whether it implements KeyCredential.
6
- *
7
- * @param credential - The assumed KeyCredential to be tested.
8
- */
9
- export function isKeyCredential(credential) {
10
- return isObjectWithProperties(credential, ["key"]) && typeof credential.key === "string";
11
- }
12
- //# sourceMappingURL=keyCredential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keyCredential.js","sourceRoot":"","sources":["../../../src/auth/keyCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAY/D;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,UAAmB;IACjD,OAAO,sBAAsB,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,CAAC;AAC3F,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { isObjectWithProperties } from \"../util/typeGuards.js\";\n\n/**\n * Represents a credential defined by a static API key.\n */\nexport interface KeyCredential {\n /**\n * The value of the API key represented as a string\n */\n readonly key: string;\n}\n\n/**\n * Tests an object to determine whether it implements KeyCredential.\n *\n * @param credential - The assumed KeyCredential to be tested.\n */\nexport function isKeyCredential(credential: unknown): credential is KeyCredential {\n return isObjectWithProperties(credential, [\"key\"]) && typeof credential.key === \"string\";\n}\n"]}
@@ -1,71 +0,0 @@
1
- import type { AbortSignalLike } from "../abort-controller/AbortSignalLike.js";
2
- /**
3
- * Represents a credential capable of providing an authentication token.
4
- */
5
- export interface TokenCredential {
6
- /**
7
- * Gets the token provided by this credential.
8
- *
9
- * This method is called automatically by Azure SDK client libraries. You may call this method
10
- * directly, but you must also handle token caching and token refreshing.
11
- *
12
- * @param scopes - The list of scopes for which the token will have access.
13
- * @param options - The options used to configure any requests this
14
- * TokenCredential implementation might make.
15
- */
16
- getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;
17
- }
18
- /**
19
- * Defines options for TokenCredential.getToken.
20
- */
21
- export interface GetTokenOptions {
22
- /**
23
- * The signal which can be used to abort requests.
24
- */
25
- abortSignal?: AbortSignalLike;
26
- /**
27
- * Options used when creating and sending HTTP requests for this operation.
28
- */
29
- requestOptions?: {
30
- /**
31
- * The number of milliseconds a request can take before automatically being terminated.
32
- */
33
- timeout?: number;
34
- };
35
- /**
36
- * Claim details to perform the Continuous Access Evaluation authentication flow
37
- */
38
- claims?: string;
39
- /**
40
- * Indicates whether to enable the Continuous Access Evaluation authentication flow
41
- */
42
- enableCae?: boolean;
43
- /**
44
- * Allows specifying a tenantId. Useful to handle challenges that provide tenant Id hints.
45
- */
46
- tenantId?: string;
47
- }
48
- /**
49
- * Represents an access token with an expiration time.
50
- */
51
- export interface AccessToken {
52
- /**
53
- * The access token returned by the authentication service.
54
- */
55
- token: string;
56
- /**
57
- * The access token's expiration timestamp in milliseconds, UNIX epoch time.
58
- */
59
- expiresOnTimestamp: number;
60
- /**
61
- * The timestamp when the access token should be refreshed, in milliseconds, UNIX epoch time.
62
- */
63
- refreshAfterTimestamp?: number;
64
- }
65
- /**
66
- * Tests an object to determine whether it implements TokenCredential.
67
- *
68
- * @param credential - The assumed TokenCredential to be tested.
69
- */
70
- export declare function isTokenCredential(credential: unknown): credential is TokenCredential;
71
- //# sourceMappingURL=tokenCredential.d.ts.map
@@ -1,19 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /**
4
- * Tests an object to determine whether it implements TokenCredential.
5
- *
6
- * @param credential - The assumed TokenCredential to be tested.
7
- */
8
- export function isTokenCredential(credential) {
9
- // Check for an object with a 'getToken' function and possibly with
10
- // a 'signRequest' function. We do this check to make sure that
11
- // a ServiceClientCredentials implementor (like TokenClientCredentials
12
- // in ms-rest-nodeauth) doesn't get mistaken for a TokenCredential if
13
- // it doesn't actually implement TokenCredential also.
14
- const castCredential = credential;
15
- return (castCredential &&
16
- typeof castCredential.getToken === "function" &&
17
- (castCredential.signRequest === undefined || castCredential.getToken.length > 0));
18
- }
19
- //# sourceMappingURL=tokenCredential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tokenCredential.js","sourceRoot":"","sources":["../../../src/auth/tokenCredential.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AA0ElC;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAmB;IACnD,mEAAmE;IACnE,gEAAgE;IAChE,sEAAsE;IACtE,qEAAqE;IACrE,sDAAsD;IACtD,MAAM,cAAc,GAAG,UAGtB,CAAC;IACF,OAAO,CACL,cAAc;QACd,OAAO,cAAc,CAAC,QAAQ,KAAK,UAAU;QAC7C,CAAC,cAAc,CAAC,WAAW,KAAK,SAAS,IAAI,cAAc,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CACjF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\n\n/**\n * Represents a credential capable of providing an authentication token.\n */\nexport interface TokenCredential {\n /**\n * Gets the token provided by this credential.\n *\n * This method is called automatically by Azure SDK client libraries. You may call this method\n * directly, but you must also handle token caching and token refreshing.\n *\n * @param scopes - The list of scopes for which the token will have access.\n * @param options - The options used to configure any requests this\n * TokenCredential implementation might make.\n */\n getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken | null>;\n}\n\n/**\n * Defines options for TokenCredential.getToken.\n */\nexport interface GetTokenOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: {\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n };\n /**\n * Claim details to perform the Continuous Access Evaluation authentication flow\n */\n claims?: string;\n /**\n * Indicates whether to enable the Continuous Access Evaluation authentication flow\n */\n enableCae?: boolean;\n /**\n * Allows specifying a tenantId. Useful to handle challenges that provide tenant Id hints.\n */\n tenantId?: string;\n}\n\n/**\n * Represents an access token with an expiration time.\n */\nexport interface AccessToken {\n /**\n * The access token returned by the authentication service.\n */\n token: string;\n\n /**\n * The access token's expiration timestamp in milliseconds, UNIX epoch time.\n */\n expiresOnTimestamp: number;\n\n /**\n * The timestamp when the access token should be refreshed, in milliseconds, UNIX epoch time.\n */\n refreshAfterTimestamp?: number;\n\n // UNBRANDED DIFFERENCE: Unbranded Core does not support PoP (\"Proof-of-Presence\") tokens.\n}\n\n/**\n * Tests an object to determine whether it implements TokenCredential.\n *\n * @param credential - The assumed TokenCredential to be tested.\n */\nexport function isTokenCredential(credential: unknown): credential is TokenCredential {\n // Check for an object with a 'getToken' function and possibly with\n // a 'signRequest' function. We do this check to make sure that\n // a ServiceClientCredentials implementor (like TokenClientCredentials\n // in ms-rest-nodeauth) doesn't get mistaken for a TokenCredential if\n // it doesn't actually implement TokenCredential also.\n const castCredential = credential as {\n getToken: unknown;\n signRequest: unknown;\n };\n return (\n castCredential &&\n typeof castCredential.getToken === \"function\" &&\n (castCredential.signRequest === undefined || castCredential.getToken.length > 0)\n );\n}\n"]}
@@ -1,8 +0,0 @@
1
- import type { KeyCredential } from "../auth/keyCredential.js";
2
- import type { PipelinePolicy } from "../pipeline.js";
3
- /**
4
- * The programmatic identifier of the bearerTokenAuthenticationPolicy.
5
- */
6
- export declare const keyCredentialAuthenticationPolicyName = "keyCredentialAuthenticationPolicy";
7
- export declare function keyCredentialAuthenticationPolicy(credential: KeyCredential, apiKeyHeaderName: string): PipelinePolicy;
8
- //# sourceMappingURL=keyCredentialAuthenticationPolicy.d.ts.map
@@ -1,16 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- /**
4
- * The programmatic identifier of the bearerTokenAuthenticationPolicy.
5
- */
6
- export const keyCredentialAuthenticationPolicyName = "keyCredentialAuthenticationPolicy";
7
- export function keyCredentialAuthenticationPolicy(credential, apiKeyHeaderName) {
8
- return {
9
- name: keyCredentialAuthenticationPolicyName,
10
- async sendRequest(request, next) {
11
- request.headers.set(apiKeyHeaderName, credential.key);
12
- return next(request);
13
- },
14
- };
15
- }
16
- //# sourceMappingURL=keyCredentialAuthenticationPolicy.js.map