@openclaw/amazon-bedrock-provider 2026.6.5 → 2026.6.6-beta.2

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 (127) hide show
  1. package/dist/bedrock-options.js +1 -0
  2. package/dist/discovery.js +19 -12
  3. package/dist/provider-policy-api.js +1 -1
  4. package/dist/register.sync.runtime.js +58 -21
  5. package/dist/stream.runtime.js +110 -48
  6. package/dist/thinking-policy.js +81 -7
  7. package/node_modules/@aws-sdk/credential-provider-env/package.json +6 -6
  8. package/node_modules/@aws-sdk/credential-provider-http/package.json +8 -8
  9. package/node_modules/@aws-sdk/credential-provider-ini/package.json +14 -14
  10. package/node_modules/@aws-sdk/credential-provider-login/package.json +7 -7
  11. package/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js +12 -1
  12. package/node_modules/@aws-sdk/credential-provider-node/dist-es/runtime/memoize-chain.js +12 -1
  13. package/node_modules/@aws-sdk/credential-provider-node/package.json +12 -12
  14. package/node_modules/@aws-sdk/credential-provider-process/package.json +6 -6
  15. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/LICENSE +201 -0
  16. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/README.md +62 -0
  17. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +156 -0
  18. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/constants.js +2 -0
  19. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromEnvSigningName.js +16 -0
  20. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromSso.js +80 -0
  21. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/fromStatic.js +8 -0
  22. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/getNewSsoOidcToken.js +11 -0
  23. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/getSsoOidcClient.js +10 -0
  24. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/index.js +4 -0
  25. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/nodeProvider.js +5 -0
  26. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/validateTokenExpiry.js +7 -0
  27. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/validateTokenKey.js +7 -0
  28. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-es/writeSSOTokenToFile.js +8 -0
  29. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/constants.d.ts +8 -0
  30. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromEnvSigningName.d.ts +18 -0
  31. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromSso.d.ts +12 -0
  32. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/fromStatic.d.ts +9 -0
  33. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/getNewSsoOidcToken.d.ts +8 -0
  34. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/getSsoOidcClient.d.ts +7 -0
  35. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/index.d.ts +4 -0
  36. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/nodeProvider.d.ts +18 -0
  37. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/constants.d.ts +3 -0
  38. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromEnvSigningName.d.ts +11 -0
  39. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromSso.d.ts +14 -0
  40. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/fromStatic.d.ts +12 -0
  41. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/getNewSsoOidcToken.d.ts +11 -0
  42. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/getSsoOidcClient.d.ts +7 -0
  43. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/index.d.ts +4 -0
  44. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/nodeProvider.d.ts +5 -0
  45. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/validateTokenExpiry.d.ts +2 -0
  46. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/validateTokenKey.d.ts +5 -0
  47. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/ts3.4/writeSSOTokenToFile.d.ts +5 -0
  48. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/validateTokenExpiry.d.ts +5 -0
  49. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/validateTokenKey.d.ts +4 -0
  50. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/dist-types/writeSSOTokenToFile.d.ts +5 -0
  51. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +69 -0
  52. package/node_modules/@aws-sdk/credential-provider-sso/package.json +8 -8
  53. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +7 -7
  54. package/node_modules/@aws-sdk/eventstream-handler-node/package.json +5 -5
  55. package/node_modules/@aws-sdk/middleware-eventstream/package.json +5 -5
  56. package/node_modules/@aws-sdk/middleware-websocket/package.json +8 -8
  57. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +99 -106
  58. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +62 -120
  59. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +55 -86
  60. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +73 -104
  61. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +102 -185
  62. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/auth/httpAuthSchemeProvider.js +4 -5
  63. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/endpoint/bdd.js +21 -57
  64. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/runtimeConfig.browser.js +1 -2
  65. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/runtimeConfig.js +2 -4
  66. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/schemas/schemas_0.js +73 -41
  67. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/auth/httpAuthSchemeProvider.js +4 -5
  68. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/endpoint/bdd.js +20 -52
  69. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/runtimeConfig.browser.js +1 -2
  70. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/runtimeConfig.js +2 -4
  71. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/schemas/schemas_0.js +36 -59
  72. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/auth/httpAuthSchemeProvider.js +4 -5
  73. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/endpoint/bdd.js +17 -45
  74. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/runtimeConfig.browser.js +1 -2
  75. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/runtimeConfig.js +2 -4
  76. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/schemas/schemas_0.js +32 -32
  77. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/auth/httpAuthSchemeProvider.js +4 -5
  78. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/endpoint/bdd.js +17 -45
  79. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/runtimeConfig.browser.js +1 -2
  80. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/runtimeConfig.js +2 -4
  81. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/schemas/schemas_0.js +50 -50
  82. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/auth/httpAuthSchemeProvider.js +4 -5
  83. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/defaultRoleAssumers.js +1 -1
  84. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/endpoint/bdd.js +34 -96
  85. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/runtimeConfig.browser.js +1 -2
  86. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/runtimeConfig.js +3 -6
  87. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/schemas/schemas_0.js +63 -80
  88. package/node_modules/@aws-sdk/nested-clients/package.json +9 -9
  89. package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +5 -5
  90. package/node_modules/@aws-sdk/types/package.json +3 -3
  91. package/node_modules/@aws-sdk/util-locate-window/package.json +2 -2
  92. package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +39 -22
  93. package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +39 -22
  94. package/node_modules/@smithy/core/dist-es/submodules/retry/middleware-retry/configurations.js +19 -6
  95. package/node_modules/@smithy/core/dist-es/submodules/retry/middleware-retry/retryMiddleware.js +4 -5
  96. package/node_modules/@smithy/core/dist-es/submodules/retry/service-error-classification/constants.js +1 -1
  97. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/ConfiguredRetryStrategy.js +4 -5
  98. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/DefaultRetryToken.js +3 -0
  99. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/StandardRetryStrategy.js +9 -5
  100. package/node_modules/@smithy/core/dist-types/submodules/retry/middleware-retry/configurations.d.ts +4 -1
  101. package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/ConfiguredRetryStrategy.d.ts +1 -2
  102. package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/DefaultRetryToken.d.ts +3 -0
  103. package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/StandardRetryStrategy.d.ts +1 -1
  104. package/node_modules/@smithy/core/package.json +2 -2
  105. package/node_modules/@smithy/credential-provider-imds/dist-cjs/index.js +14 -13
  106. package/node_modules/@smithy/credential-provider-imds/dist-es/fromContainerMetadata.js +14 -13
  107. package/node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/httpRequest.js +2 -2
  108. package/node_modules/@smithy/credential-provider-imds/dist-es/remoteProvider/node-http.js +2 -0
  109. package/node_modules/@smithy/credential-provider-imds/dist-types/remoteProvider/httpRequest.d.ts +1 -1
  110. package/node_modules/@smithy/credential-provider-imds/dist-types/remoteProvider/node-http.d.ts +2 -0
  111. package/node_modules/@smithy/credential-provider-imds/package.json +3 -3
  112. package/node_modules/@smithy/fetch-http-handler/package.json +4 -4
  113. package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +6 -4
  114. package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +7 -6
  115. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +2 -1
  116. package/node_modules/@smithy/node-http-handler/dist-es/node-http2.js +2 -0
  117. package/node_modules/@smithy/node-http-handler/dist-es/node-https.js +2 -0
  118. package/node_modules/@smithy/node-http-handler/dist-types/node-http-handler.d.ts +2 -2
  119. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-handler.d.ts +1 -1
  120. package/node_modules/@smithy/node-http-handler/dist-types/node-http2.d.ts +2 -0
  121. package/node_modules/@smithy/node-http-handler/dist-types/node-https.d.ts +2 -0
  122. package/node_modules/@smithy/node-http-handler/package.json +4 -4
  123. package/node_modules/@smithy/signature-v4/package.json +3 -3
  124. package/node_modules/@smithy/types/dist-types/retry.d.ts +25 -0
  125. package/node_modules/@smithy/types/package.json +1 -1
  126. package/npm-shrinkwrap.json +169 -152
  127. package/package.json +7 -7
@@ -0,0 +1,156 @@
1
+ 'use strict';
2
+
3
+ var client = require('@aws-sdk/core/client');
4
+ var httpAuthSchemes = require('@aws-sdk/core/httpAuthSchemes');
5
+ var config = require('@smithy/core/config');
6
+ var node_fs = require('node:fs');
7
+
8
+ const fromEnvSigningName = ({ logger, signingName } = {}) => async () => {
9
+ logger?.debug?.("@aws-sdk/token-providers - fromEnvSigningName");
10
+ if (!signingName) {
11
+ throw new config.TokenProviderError("Please pass 'signingName' to compute environment variable key", { logger });
12
+ }
13
+ const bearerTokenKey = httpAuthSchemes.getBearerTokenEnvKey(signingName);
14
+ if (!(bearerTokenKey in process.env)) {
15
+ throw new config.TokenProviderError(`Token not present in '${bearerTokenKey}' environment variable`, { logger });
16
+ }
17
+ const token = { token: process.env[bearerTokenKey] };
18
+ client.setTokenFeature(token, "BEARER_SERVICE_ENV_VARS", "3");
19
+ return token;
20
+ };
21
+
22
+ const EXPIRE_WINDOW_MS = 5 * 60 * 1000;
23
+ const REFRESH_MESSAGE = `To refresh this SSO session run 'aws sso login' with the corresponding profile.`;
24
+
25
+ const getSsoOidcClient = async (ssoRegion, init = {}, callerClientConfig) => {
26
+ const { SSOOIDCClient } = await import('@aws-sdk/nested-clients/sso-oidc');
27
+ const coalesce = (prop) => init.clientConfig?.[prop] ?? init.parentClientConfig?.[prop] ?? callerClientConfig?.[prop];
28
+ const ssoOidcClient = new SSOOIDCClient(Object.assign({}, init.clientConfig ?? {}, {
29
+ region: ssoRegion ?? init.clientConfig?.region,
30
+ logger: coalesce("logger"),
31
+ userAgentAppId: coalesce("userAgentAppId"),
32
+ }));
33
+ return ssoOidcClient;
34
+ };
35
+
36
+ const getNewSsoOidcToken = async (ssoToken, ssoRegion, init = {}, callerClientConfig) => {
37
+ const { CreateTokenCommand } = await import('@aws-sdk/nested-clients/sso-oidc');
38
+ const ssoOidcClient = await getSsoOidcClient(ssoRegion, init, callerClientConfig);
39
+ return ssoOidcClient.send(new CreateTokenCommand({
40
+ clientId: ssoToken.clientId,
41
+ clientSecret: ssoToken.clientSecret,
42
+ refreshToken: ssoToken.refreshToken,
43
+ grantType: "refresh_token",
44
+ }));
45
+ };
46
+
47
+ const validateTokenExpiry = (token) => {
48
+ if (token.expiration && token.expiration.getTime() < Date.now()) {
49
+ throw new config.TokenProviderError(`Token is expired. ${REFRESH_MESSAGE}`, false);
50
+ }
51
+ };
52
+
53
+ const validateTokenKey = (key, value, forRefresh = false) => {
54
+ if (typeof value === "undefined") {
55
+ throw new config.TokenProviderError(`Value not present for '${key}' in SSO Token${forRefresh ? ". Cannot refresh" : ""}. ${REFRESH_MESSAGE}`, false);
56
+ }
57
+ };
58
+
59
+ const { writeFile } = node_fs.promises;
60
+ const writeSSOTokenToFile = (id, ssoToken) => {
61
+ const tokenFilepath = config.getSSOTokenFilepath(id);
62
+ const tokenString = JSON.stringify(ssoToken, null, 2);
63
+ return writeFile(tokenFilepath, tokenString);
64
+ };
65
+
66
+ const lastRefreshAttemptTime = new Date(0);
67
+ const fromSso = (init = {}) => async ({ callerClientConfig } = {}) => {
68
+ init.logger?.debug("@aws-sdk/token-providers - fromSso");
69
+ const profiles = await config.parseKnownFiles(init);
70
+ const profileName = config.getProfileName({
71
+ profile: init.profile ?? callerClientConfig?.profile,
72
+ });
73
+ const profile = profiles[profileName];
74
+ if (!profile) {
75
+ throw new config.TokenProviderError(`Profile '${profileName}' could not be found in shared credentials file.`, false);
76
+ }
77
+ else if (!profile["sso_session"]) {
78
+ throw new config.TokenProviderError(`Profile '${profileName}' is missing required property 'sso_session'.`);
79
+ }
80
+ const ssoSessionName = profile["sso_session"];
81
+ const ssoSessions = await config.loadSsoSessionData(init);
82
+ const ssoSession = ssoSessions[ssoSessionName];
83
+ if (!ssoSession) {
84
+ throw new config.TokenProviderError(`Sso session '${ssoSessionName}' could not be found in shared credentials file.`, false);
85
+ }
86
+ for (const ssoSessionRequiredKey of ["sso_start_url", "sso_region"]) {
87
+ if (!ssoSession[ssoSessionRequiredKey]) {
88
+ throw new config.TokenProviderError(`Sso session '${ssoSessionName}' is missing required property '${ssoSessionRequiredKey}'.`, false);
89
+ }
90
+ }
91
+ ssoSession["sso_start_url"];
92
+ const ssoRegion = ssoSession["sso_region"];
93
+ let ssoToken;
94
+ try {
95
+ ssoToken = await config.getSSOTokenFromFile(ssoSessionName);
96
+ }
97
+ catch (e) {
98
+ throw new config.TokenProviderError(`The SSO session token associated with profile=${profileName} was not found or is invalid. ${REFRESH_MESSAGE}`, false);
99
+ }
100
+ validateTokenKey("accessToken", ssoToken.accessToken);
101
+ validateTokenKey("expiresAt", ssoToken.expiresAt);
102
+ const { accessToken, expiresAt } = ssoToken;
103
+ const existingToken = { token: accessToken, expiration: new Date(expiresAt) };
104
+ if (existingToken.expiration.getTime() - Date.now() > EXPIRE_WINDOW_MS) {
105
+ return existingToken;
106
+ }
107
+ if (Date.now() - lastRefreshAttemptTime.getTime() < 30 * 1000) {
108
+ validateTokenExpiry(existingToken);
109
+ return existingToken;
110
+ }
111
+ validateTokenKey("clientId", ssoToken.clientId, true);
112
+ validateTokenKey("clientSecret", ssoToken.clientSecret, true);
113
+ validateTokenKey("refreshToken", ssoToken.refreshToken, true);
114
+ try {
115
+ lastRefreshAttemptTime.setTime(Date.now());
116
+ const newSsoOidcToken = await getNewSsoOidcToken(ssoToken, ssoRegion, init, callerClientConfig);
117
+ validateTokenKey("accessToken", newSsoOidcToken.accessToken);
118
+ validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
119
+ const newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn * 1000);
120
+ try {
121
+ await writeSSOTokenToFile(ssoSessionName, {
122
+ ...ssoToken,
123
+ accessToken: newSsoOidcToken.accessToken,
124
+ expiresAt: newTokenExpiration.toISOString(),
125
+ refreshToken: newSsoOidcToken.refreshToken,
126
+ });
127
+ }
128
+ catch (error) {
129
+ }
130
+ return {
131
+ token: newSsoOidcToken.accessToken,
132
+ expiration: newTokenExpiration,
133
+ };
134
+ }
135
+ catch (error) {
136
+ validateTokenExpiry(existingToken);
137
+ return existingToken;
138
+ }
139
+ };
140
+
141
+ const fromStatic = ({ token, logger }) => async () => {
142
+ logger?.debug("@aws-sdk/token-providers - fromStatic");
143
+ if (!token || !token.token) {
144
+ throw new config.TokenProviderError(`Please pass a valid token to fromStatic`, false);
145
+ }
146
+ return token;
147
+ };
148
+
149
+ const nodeProvider = (init = {}) => config.memoize(config.chain(fromSso(init), async () => {
150
+ throw new config.TokenProviderError("Could not load token from any providers", false);
151
+ }), (token) => token.expiration !== undefined && token.expiration.getTime() - Date.now() < 300000, (token) => token.expiration !== undefined);
152
+
153
+ exports.fromEnvSigningName = fromEnvSigningName;
154
+ exports.fromSso = fromSso;
155
+ exports.fromStatic = fromStatic;
156
+ exports.nodeProvider = nodeProvider;
@@ -0,0 +1,2 @@
1
+ export const EXPIRE_WINDOW_MS = 5 * 60 * 1000;
2
+ export const REFRESH_MESSAGE = `To refresh this SSO session run 'aws sso login' with the corresponding profile.`;
@@ -0,0 +1,16 @@
1
+ import { setTokenFeature } from "@aws-sdk/core/client";
2
+ import { getBearerTokenEnvKey } from "@aws-sdk/core/httpAuthSchemes";
3
+ import { TokenProviderError } from "@smithy/core/config";
4
+ export const fromEnvSigningName = ({ logger, signingName } = {}) => async () => {
5
+ logger?.debug?.("@aws-sdk/token-providers - fromEnvSigningName");
6
+ if (!signingName) {
7
+ throw new TokenProviderError("Please pass 'signingName' to compute environment variable key", { logger });
8
+ }
9
+ const bearerTokenKey = getBearerTokenEnvKey(signingName);
10
+ if (!(bearerTokenKey in process.env)) {
11
+ throw new TokenProviderError(`Token not present in '${bearerTokenKey}' environment variable`, { logger });
12
+ }
13
+ const token = { token: process.env[bearerTokenKey] };
14
+ setTokenFeature(token, "BEARER_SERVICE_ENV_VARS", "3");
15
+ return token;
16
+ };
@@ -0,0 +1,80 @@
1
+ import { getProfileName, getSSOTokenFromFile, loadSsoSessionData, parseKnownFiles, TokenProviderError, } from "@smithy/core/config";
2
+ import { EXPIRE_WINDOW_MS, REFRESH_MESSAGE } from "./constants";
3
+ import { getNewSsoOidcToken } from "./getNewSsoOidcToken";
4
+ import { validateTokenExpiry } from "./validateTokenExpiry";
5
+ import { validateTokenKey } from "./validateTokenKey";
6
+ import { writeSSOTokenToFile } from "./writeSSOTokenToFile";
7
+ const lastRefreshAttemptTime = new Date(0);
8
+ export const fromSso = (init = {}) => async ({ callerClientConfig } = {}) => {
9
+ init.logger?.debug("@aws-sdk/token-providers - fromSso");
10
+ const profiles = await parseKnownFiles(init);
11
+ const profileName = getProfileName({
12
+ profile: init.profile ?? callerClientConfig?.profile,
13
+ });
14
+ const profile = profiles[profileName];
15
+ if (!profile) {
16
+ throw new TokenProviderError(`Profile '${profileName}' could not be found in shared credentials file.`, false);
17
+ }
18
+ else if (!profile["sso_session"]) {
19
+ throw new TokenProviderError(`Profile '${profileName}' is missing required property 'sso_session'.`);
20
+ }
21
+ const ssoSessionName = profile["sso_session"];
22
+ const ssoSessions = await loadSsoSessionData(init);
23
+ const ssoSession = ssoSessions[ssoSessionName];
24
+ if (!ssoSession) {
25
+ throw new TokenProviderError(`Sso session '${ssoSessionName}' could not be found in shared credentials file.`, false);
26
+ }
27
+ for (const ssoSessionRequiredKey of ["sso_start_url", "sso_region"]) {
28
+ if (!ssoSession[ssoSessionRequiredKey]) {
29
+ throw new TokenProviderError(`Sso session '${ssoSessionName}' is missing required property '${ssoSessionRequiredKey}'.`, false);
30
+ }
31
+ }
32
+ const ssoStartUrl = ssoSession["sso_start_url"];
33
+ const ssoRegion = ssoSession["sso_region"];
34
+ let ssoToken;
35
+ try {
36
+ ssoToken = await getSSOTokenFromFile(ssoSessionName);
37
+ }
38
+ catch (e) {
39
+ throw new TokenProviderError(`The SSO session token associated with profile=${profileName} was not found or is invalid. ${REFRESH_MESSAGE}`, false);
40
+ }
41
+ validateTokenKey("accessToken", ssoToken.accessToken);
42
+ validateTokenKey("expiresAt", ssoToken.expiresAt);
43
+ const { accessToken, expiresAt } = ssoToken;
44
+ const existingToken = { token: accessToken, expiration: new Date(expiresAt) };
45
+ if (existingToken.expiration.getTime() - Date.now() > EXPIRE_WINDOW_MS) {
46
+ return existingToken;
47
+ }
48
+ if (Date.now() - lastRefreshAttemptTime.getTime() < 30 * 1000) {
49
+ validateTokenExpiry(existingToken);
50
+ return existingToken;
51
+ }
52
+ validateTokenKey("clientId", ssoToken.clientId, true);
53
+ validateTokenKey("clientSecret", ssoToken.clientSecret, true);
54
+ validateTokenKey("refreshToken", ssoToken.refreshToken, true);
55
+ try {
56
+ lastRefreshAttemptTime.setTime(Date.now());
57
+ const newSsoOidcToken = await getNewSsoOidcToken(ssoToken, ssoRegion, init, callerClientConfig);
58
+ validateTokenKey("accessToken", newSsoOidcToken.accessToken);
59
+ validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
60
+ const newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn * 1000);
61
+ try {
62
+ await writeSSOTokenToFile(ssoSessionName, {
63
+ ...ssoToken,
64
+ accessToken: newSsoOidcToken.accessToken,
65
+ expiresAt: newTokenExpiration.toISOString(),
66
+ refreshToken: newSsoOidcToken.refreshToken,
67
+ });
68
+ }
69
+ catch (error) {
70
+ }
71
+ return {
72
+ token: newSsoOidcToken.accessToken,
73
+ expiration: newTokenExpiration,
74
+ };
75
+ }
76
+ catch (error) {
77
+ validateTokenExpiry(existingToken);
78
+ return existingToken;
79
+ }
80
+ };
@@ -0,0 +1,8 @@
1
+ import { TokenProviderError } from "@smithy/core/config";
2
+ export const fromStatic = ({ token, logger }) => async () => {
3
+ logger?.debug("@aws-sdk/token-providers - fromStatic");
4
+ if (!token || !token.token) {
5
+ throw new TokenProviderError(`Please pass a valid token to fromStatic`, false);
6
+ }
7
+ return token;
8
+ };
@@ -0,0 +1,11 @@
1
+ import { getSsoOidcClient } from "./getSsoOidcClient";
2
+ export const getNewSsoOidcToken = async (ssoToken, ssoRegion, init = {}, callerClientConfig) => {
3
+ const { CreateTokenCommand } = await import("@aws-sdk/nested-clients/sso-oidc");
4
+ const ssoOidcClient = await getSsoOidcClient(ssoRegion, init, callerClientConfig);
5
+ return ssoOidcClient.send(new CreateTokenCommand({
6
+ clientId: ssoToken.clientId,
7
+ clientSecret: ssoToken.clientSecret,
8
+ refreshToken: ssoToken.refreshToken,
9
+ grantType: "refresh_token",
10
+ }));
11
+ };
@@ -0,0 +1,10 @@
1
+ export const getSsoOidcClient = async (ssoRegion, init = {}, callerClientConfig) => {
2
+ const { SSOOIDCClient } = await import("@aws-sdk/nested-clients/sso-oidc");
3
+ const coalesce = (prop) => init.clientConfig?.[prop] ?? init.parentClientConfig?.[prop] ?? callerClientConfig?.[prop];
4
+ const ssoOidcClient = new SSOOIDCClient(Object.assign({}, init.clientConfig ?? {}, {
5
+ region: ssoRegion ?? init.clientConfig?.region,
6
+ logger: coalesce("logger"),
7
+ userAgentAppId: coalesce("userAgentAppId"),
8
+ }));
9
+ return ssoOidcClient;
10
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./fromEnvSigningName";
2
+ export * from "./fromSso";
3
+ export * from "./fromStatic";
4
+ export * from "./nodeProvider";
@@ -0,0 +1,5 @@
1
+ import { chain, memoize, TokenProviderError } from "@smithy/core/config";
2
+ import { fromSso } from "./fromSso";
3
+ export const nodeProvider = (init = {}) => memoize(chain(fromSso(init), async () => {
4
+ throw new TokenProviderError("Could not load token from any providers", false);
5
+ }), (token) => token.expiration !== undefined && token.expiration.getTime() - Date.now() < 300000, (token) => token.expiration !== undefined);
@@ -0,0 +1,7 @@
1
+ import { TokenProviderError } from "@smithy/core/config";
2
+ import { REFRESH_MESSAGE } from "./constants";
3
+ export const validateTokenExpiry = (token) => {
4
+ if (token.expiration && token.expiration.getTime() < Date.now()) {
5
+ throw new TokenProviderError(`Token is expired. ${REFRESH_MESSAGE}`, false);
6
+ }
7
+ };
@@ -0,0 +1,7 @@
1
+ import { TokenProviderError } from "@smithy/core/config";
2
+ import { REFRESH_MESSAGE } from "./constants";
3
+ export const validateTokenKey = (key, value, forRefresh = false) => {
4
+ if (typeof value === "undefined") {
5
+ throw new TokenProviderError(`Value not present for '${key}' in SSO Token${forRefresh ? ". Cannot refresh" : ""}. ${REFRESH_MESSAGE}`, false);
6
+ }
7
+ };
@@ -0,0 +1,8 @@
1
+ import { getSSOTokenFilepath } from "@smithy/core/config";
2
+ import { promises as fsPromises } from "node:fs";
3
+ const { writeFile } = fsPromises;
4
+ export const writeSSOTokenToFile = (id, ssoToken) => {
5
+ const tokenFilepath = getSSOTokenFilepath(id);
6
+ const tokenString = JSON.stringify(ssoToken, null, 2);
7
+ return writeFile(tokenFilepath, tokenString);
8
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The time window (5 mins) that SDK will treat the SSO token expires in before the defined expiration date in token.
3
+ * This is needed because server side may have invalidated the token before the defined expiration date.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare const EXPIRE_WINDOW_MS: number;
8
+ export declare const REFRESH_MESSAGE = "To refresh this SSO session run 'aws sso login' with the corresponding profile.";
@@ -0,0 +1,18 @@
1
+ import type { CredentialProviderOptions, TokenIdentityProvider } from "@aws-sdk/types";
2
+ /**
3
+ * @public
4
+ */
5
+ export interface FromEnvSigningNameInit extends CredentialProviderOptions {
6
+ signingName?: string;
7
+ }
8
+ /**
9
+ * Creates a TokenIdentityProvider that retrieves bearer token from environment variable
10
+ *
11
+ * @param options - Configuration options for the token provider
12
+ * @param options.logger - Optional logger for debug messages
13
+ * @param options.signingName - Service signing name used to determine environment variable key
14
+ * @returns TokenIdentityProvider that provides bearer token from environment variable
15
+ *
16
+ * @public
17
+ */
18
+ export declare const fromEnvSigningName: ({ logger, signingName }?: FromEnvSigningNameInit) => TokenIdentityProvider;
@@ -0,0 +1,12 @@
1
+ import type { CredentialProviderOptions, RuntimeConfigIdentityProvider, TokenIdentity } from "@aws-sdk/types";
2
+ import type { SourceProfileInit } from "@smithy/core/config";
3
+ export interface FromSsoInit extends SourceProfileInit, CredentialProviderOptions {
4
+ /**
5
+ * @see SSOOIDCClientConfig in \@aws-sdk/client-sso-oidc.
6
+ */
7
+ clientConfig?: any;
8
+ }
9
+ /**
10
+ * Creates a token provider that will read from SSO token cache or ssoOidc.createToken() call.
11
+ */
12
+ export declare const fromSso: (init?: FromSsoInit) => RuntimeConfigIdentityProvider<TokenIdentity>;
@@ -0,0 +1,9 @@
1
+ import type { CredentialProviderOptions, TokenIdentity, TokenIdentityProvider } from "@aws-sdk/types";
2
+ export interface FromStaticInit extends CredentialProviderOptions {
3
+ token?: TokenIdentity;
4
+ }
5
+ /**
6
+ * Creates a token provider that will read from static token.
7
+ * @public
8
+ */
9
+ export declare const fromStatic: ({ token, logger }: FromStaticInit) => TokenIdentityProvider;
@@ -0,0 +1,8 @@
1
+ import type { AwsIdentityProperties } from "@aws-sdk/types";
2
+ import type { SSOToken } from "@smithy/core/config";
3
+ import type { FromSsoInit } from "./fromSso";
4
+ /**
5
+ * Returns a new SSO OIDC token from SSOOIDC::createToken() API call.
6
+ * @internal
7
+ */
8
+ export declare const getNewSsoOidcToken: (ssoToken: SSOToken, ssoRegion: string, init?: FromSsoInit, callerClientConfig?: AwsIdentityProperties["callerClientConfig"]) => Promise<import("@aws-sdk/nested-clients/sso-oidc").CreateTokenCommandOutput>;
@@ -0,0 +1,7 @@
1
+ import type { AwsIdentityProperties } from "@aws-sdk/types";
2
+ import type { FromSsoInit } from "./fromSso";
3
+ /**
4
+ * Returns a SSOOIDC client for the given region.
5
+ * @internal
6
+ */
7
+ export declare const getSsoOidcClient: (ssoRegion: string, init?: FromSsoInit, callerClientConfig?: AwsIdentityProperties["callerClientConfig"]) => Promise<import("@aws-sdk/nested-clients/sso-oidc").SSOOIDCClient>;
@@ -0,0 +1,4 @@
1
+ export * from "./fromEnvSigningName";
2
+ export * from "./fromSso";
3
+ export * from "./fromStatic";
4
+ export * from "./nodeProvider";
@@ -0,0 +1,18 @@
1
+ import type { TokenIdentityProvider } from "@aws-sdk/types";
2
+ import type { FromSsoInit } from "./fromSso";
3
+ /**
4
+ * Creates a token provider that will attempt to find token from the
5
+ * following sources (listed in order of precedence):
6
+ * * SSO token from SSO cache or ssoOidc.createToken() call
7
+ *
8
+ * The default token provider is designed to invoke one provider at a time and only
9
+ * continue to the next if no token has been located. It currently has only SSO
10
+ * Token Provider in the chain.
11
+ *
12
+ * @param init Configuration that is passed to each individual
13
+ * provider
14
+ *
15
+ * @see fromSso The function used to source credentials from
16
+ * SSO cache or ssoOidc.createToken() call
17
+ */
18
+ export declare const nodeProvider: (init?: FromSsoInit) => TokenIdentityProvider;
@@ -0,0 +1,3 @@
1
+ export declare const EXPIRE_WINDOW_MS: number;
2
+ export declare const REFRESH_MESSAGE =
3
+ "To refresh this SSO session run 'aws sso login' with the corresponding profile.";
@@ -0,0 +1,11 @@
1
+ import {
2
+ CredentialProviderOptions,
3
+ TokenIdentityProvider,
4
+ } from "@aws-sdk/types";
5
+ export interface FromEnvSigningNameInit extends CredentialProviderOptions {
6
+ signingName?: string;
7
+ }
8
+ export declare const fromEnvSigningName: ({
9
+ logger,
10
+ signingName,
11
+ }?: FromEnvSigningNameInit) => TokenIdentityProvider;
@@ -0,0 +1,14 @@
1
+ import {
2
+ CredentialProviderOptions,
3
+ RuntimeConfigIdentityProvider,
4
+ TokenIdentity,
5
+ } from "@aws-sdk/types";
6
+ import { SourceProfileInit } from "@smithy/core/config";
7
+ export interface FromSsoInit
8
+ extends SourceProfileInit,
9
+ CredentialProviderOptions {
10
+ clientConfig?: any;
11
+ }
12
+ export declare const fromSso: (
13
+ init?: FromSsoInit
14
+ ) => RuntimeConfigIdentityProvider<TokenIdentity>;
@@ -0,0 +1,12 @@
1
+ import {
2
+ CredentialProviderOptions,
3
+ TokenIdentity,
4
+ TokenIdentityProvider,
5
+ } from "@aws-sdk/types";
6
+ export interface FromStaticInit extends CredentialProviderOptions {
7
+ token?: TokenIdentity;
8
+ }
9
+ export declare const fromStatic: ({
10
+ token,
11
+ logger,
12
+ }: FromStaticInit) => TokenIdentityProvider;
@@ -0,0 +1,11 @@
1
+ import { AwsIdentityProperties } from "@aws-sdk/types";
2
+ import { SSOToken } from "@smithy/core/config";
3
+ import { FromSsoInit } from "./fromSso";
4
+ export declare const getNewSsoOidcToken: (
5
+ ssoToken: SSOToken,
6
+ ssoRegion: string,
7
+ init?: FromSsoInit,
8
+ callerClientConfig?: AwsIdentityProperties["callerClientConfig"]
9
+ ) => Promise<
10
+ import("@aws-sdk/nested-clients/sso-oidc").CreateTokenCommandOutput
11
+ >;
@@ -0,0 +1,7 @@
1
+ import { AwsIdentityProperties } from "@aws-sdk/types";
2
+ import { FromSsoInit } from "./fromSso";
3
+ export declare const getSsoOidcClient: (
4
+ ssoRegion: string,
5
+ init?: FromSsoInit,
6
+ callerClientConfig?: AwsIdentityProperties["callerClientConfig"]
7
+ ) => Promise<import("@aws-sdk/nested-clients/sso-oidc").SSOOIDCClient>;
@@ -0,0 +1,4 @@
1
+ export * from "./fromEnvSigningName";
2
+ export * from "./fromSso";
3
+ export * from "./fromStatic";
4
+ export * from "./nodeProvider";
@@ -0,0 +1,5 @@
1
+ import { TokenIdentityProvider } from "@aws-sdk/types";
2
+ import { FromSsoInit } from "./fromSso";
3
+ export declare const nodeProvider: (
4
+ init?: FromSsoInit
5
+ ) => TokenIdentityProvider;
@@ -0,0 +1,2 @@
1
+ import { TokenIdentity } from "@aws-sdk/types";
2
+ export declare const validateTokenExpiry: (token: TokenIdentity) => void;
@@ -0,0 +1,5 @@
1
+ export declare const validateTokenKey: (
2
+ key: string,
3
+ value: unknown,
4
+ forRefresh?: boolean
5
+ ) => void;
@@ -0,0 +1,5 @@
1
+ import { SSOToken } from "@smithy/core/config";
2
+ export declare const writeSSOTokenToFile: (
3
+ id: string,
4
+ ssoToken: SSOToken
5
+ ) => Promise<void>;
@@ -0,0 +1,5 @@
1
+ import type { TokenIdentity } from "@aws-sdk/types";
2
+ /**
3
+ * Throws TokenProviderError is token is expired.
4
+ */
5
+ export declare const validateTokenExpiry: (token: TokenIdentity) => void;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Throws TokenProviderError if value is undefined for key.
3
+ */
4
+ export declare const validateTokenKey: (key: string, value: unknown, forRefresh?: boolean) => void;
@@ -0,0 +1,5 @@
1
+ import type { SSOToken } from "@smithy/core/config";
2
+ /**
3
+ * Writes SSO token to file based on filepath computed from ssoStartUrl or session name.
4
+ */
5
+ export declare const writeSSOTokenToFile: (id: string, ssoToken: SSOToken) => Promise<void>;
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@aws-sdk/token-providers",
3
+ "version": "3.1063.0",
4
+ "description": "A collection of token providers",
5
+ "main": "./dist-cjs/index.js",
6
+ "module": "./dist-es/index.js",
7
+ "scripts": {
8
+ "build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
9
+ "build:cjs": "node ../../scripts/compilation/inline token-providers",
10
+ "build:es": "tsc -p tsconfig.es.json",
11
+ "build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
12
+ "build:types": "tsc -p tsconfig.types.json",
13
+ "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
14
+ "clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
15
+ "extract:docs": "api-extractor run --local",
16
+ "test": "yarn g:vitest run",
17
+ "test:watch": "yarn g:vitest watch",
18
+ "test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
19
+ "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
20
+ },
21
+ "keywords": [
22
+ "aws",
23
+ "token"
24
+ ],
25
+ "sideEffects": false,
26
+ "author": {
27
+ "name": "AWS SDK for JavaScript Team",
28
+ "url": "https://aws.amazon.com/sdk-for-javascript/"
29
+ },
30
+ "license": "Apache-2.0",
31
+ "dependencies": {
32
+ "@aws-sdk/core": "^3.974.18",
33
+ "@aws-sdk/nested-clients": "^3.997.17",
34
+ "@aws-sdk/types": "^3.973.11",
35
+ "@smithy/core": "^3.24.6",
36
+ "@smithy/types": "^4.14.3",
37
+ "tslib": "^2.6.2"
38
+ },
39
+ "devDependencies": {
40
+ "@tsconfig/recommended": "1.0.1",
41
+ "@types/node": "^20.14.8",
42
+ "concurrently": "7.0.0",
43
+ "downlevel-dts": "0.10.1",
44
+ "premove": "4.0.0",
45
+ "typescript": "~5.8.3"
46
+ },
47
+ "types": "./dist-types/index.d.ts",
48
+ "engines": {
49
+ "node": ">=20.0.0"
50
+ },
51
+ "typesVersions": {
52
+ "<4.5": {
53
+ "dist-types/*": [
54
+ "dist-types/ts3.4/*"
55
+ ]
56
+ }
57
+ },
58
+ "files": [
59
+ "dist-*/**"
60
+ ],
61
+ "browser": {},
62
+ "react-native": {},
63
+ "homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages/token-providers",
64
+ "repository": {
65
+ "type": "git",
66
+ "url": "https://github.com/aws/aws-sdk-js-v3.git",
67
+ "directory": "packages/token-providers"
68
+ }
69
+ }