@logto/connector-aws-ses 1.1.2 → 1.2.1

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.
@@ -1,58 +0,0 @@
1
- import { C as CredentialsProviderError } from './index-s7VGoewj.js';
2
- import { readFileSync } from 'fs';
3
- import '@logto/connector-kit';
4
- import 'zod';
5
- import 'os';
6
- import 'path';
7
- import 'crypto';
8
- import 'buffer';
9
- import 'stream';
10
- import 'http';
11
- import 'https';
12
- import 'http2';
13
- import 'util';
14
- import 'process';
15
-
16
- const fromWebToken = (init) => async () => {
17
- init.logger?.debug("@aws-sdk/credential-provider-web-identity", "fromWebToken");
18
- const { roleArn, roleSessionName, webIdentityToken, providerId, policyArns, policy, durationSeconds } = init;
19
- let { roleAssumerWithWebIdentity } = init;
20
- if (!roleAssumerWithWebIdentity) {
21
- const { getDefaultRoleAssumerWithWebIdentity } = await import('./loadSts-_S-bg8by.js');
22
- roleAssumerWithWebIdentity = getDefaultRoleAssumerWithWebIdentity({
23
- ...init.clientConfig,
24
- credentialProviderLogger: init.logger,
25
- parentClientConfig: init.parentClientConfig,
26
- }, init.clientPlugins);
27
- }
28
- return roleAssumerWithWebIdentity({
29
- RoleArn: roleArn,
30
- RoleSessionName: roleSessionName ?? `aws-sdk-js-session-${Date.now()}`,
31
- WebIdentityToken: webIdentityToken,
32
- ProviderId: providerId,
33
- PolicyArns: policyArns,
34
- Policy: policy,
35
- DurationSeconds: durationSeconds,
36
- });
37
- };
38
-
39
- const ENV_TOKEN_FILE = "AWS_WEB_IDENTITY_TOKEN_FILE";
40
- const ENV_ROLE_ARN = "AWS_ROLE_ARN";
41
- const ENV_ROLE_SESSION_NAME = "AWS_ROLE_SESSION_NAME";
42
- const fromTokenFile = (init = {}) => async () => {
43
- init.logger?.debug("@aws-sdk/credential-provider-web-identity", "fromTokenFile");
44
- const webIdentityTokenFile = init?.webIdentityTokenFile ?? process.env[ENV_TOKEN_FILE];
45
- const roleArn = init?.roleArn ?? process.env[ENV_ROLE_ARN];
46
- const roleSessionName = init?.roleSessionName ?? process.env[ENV_ROLE_SESSION_NAME];
47
- if (!webIdentityTokenFile || !roleArn) {
48
- throw new CredentialsProviderError("Web identity configuration not specified");
49
- }
50
- return fromWebToken({
51
- ...init,
52
- webIdentityToken: readFileSync(webIdentityTokenFile, { encoding: "ascii" }),
53
- roleArn,
54
- roleSessionName,
55
- })();
56
- };
57
-
58
- export { fromTokenFile, fromWebToken };
@@ -1,77 +0,0 @@
1
- import 'os';
2
- import 'path';
3
- import { C as CredentialsProviderError, g as getProfileName } from './index-s7VGoewj.js';
4
- import 'crypto';
5
- import 'fs';
6
- import { p as parseKnownFiles } from './parseKnownFiles-DjQIrDWV.js';
7
- import { exec } from 'child_process';
8
- import { promisify } from 'util';
9
- import '@logto/connector-kit';
10
- import 'zod';
11
- import 'buffer';
12
- import 'stream';
13
- import 'http';
14
- import 'https';
15
- import 'http2';
16
- import 'process';
17
-
18
- const getValidatedProcessCredentials = (profileName, data) => {
19
- if (data.Version !== 1) {
20
- throw Error(`Profile ${profileName} credential_process did not return Version 1.`);
21
- }
22
- if (data.AccessKeyId === undefined || data.SecretAccessKey === undefined) {
23
- throw Error(`Profile ${profileName} credential_process returned invalid credentials.`);
24
- }
25
- if (data.Expiration) {
26
- const currentTime = new Date();
27
- const expireTime = new Date(data.Expiration);
28
- if (expireTime < currentTime) {
29
- throw Error(`Profile ${profileName} credential_process returned expired credentials.`);
30
- }
31
- }
32
- return {
33
- accessKeyId: data.AccessKeyId,
34
- secretAccessKey: data.SecretAccessKey,
35
- ...(data.SessionToken && { sessionToken: data.SessionToken }),
36
- ...(data.Expiration && { expiration: new Date(data.Expiration) }),
37
- ...(data.CredentialScope && { credentialScope: data.CredentialScope }),
38
- };
39
- };
40
-
41
- const resolveProcessCredentials = async (profileName, profiles) => {
42
- const profile = profiles[profileName];
43
- if (profiles[profileName]) {
44
- const credentialProcess = profile["credential_process"];
45
- if (credentialProcess !== undefined) {
46
- const execPromise = promisify(exec);
47
- try {
48
- const { stdout } = await execPromise(credentialProcess);
49
- let data;
50
- try {
51
- data = JSON.parse(stdout.trim());
52
- }
53
- catch {
54
- throw Error(`Profile ${profileName} credential_process returned invalid JSON.`);
55
- }
56
- return getValidatedProcessCredentials(profileName, data);
57
- }
58
- catch (error) {
59
- throw new CredentialsProviderError(error.message);
60
- }
61
- }
62
- else {
63
- throw new CredentialsProviderError(`Profile ${profileName} did not contain credential_process.`);
64
- }
65
- }
66
- else {
67
- throw new CredentialsProviderError(`Profile ${profileName} could not be found in shared credentials file.`);
68
- }
69
- };
70
-
71
- const fromProcess = (init = {}) => async () => {
72
- init.logger?.debug("@aws-sdk/credential-provider-process", "fromProcess");
73
- const profiles = await parseKnownFiles(init);
74
- return resolveProcessCredentials(getProfileName(init), profiles);
75
- };
76
-
77
- export { fromProcess };
@@ -1,218 +0,0 @@
1
- import { f as fromArrayBuffer, h as streamCollector, C as CredentialsProviderError, H as HttpRequest, N as NodeHttpHandler } from './index-s7VGoewj.js';
2
- import 'http2';
3
- import { Readable } from 'stream';
4
- import fs from 'fs/promises';
5
- import 'buffer';
6
- import 'http';
7
- import 'https';
8
- import { TextDecoder } from 'util';
9
- import { p as parseRfc3339DateTime } from './date-utils-vaX2R5qo.js';
10
- import '@logto/connector-kit';
11
- import 'zod';
12
- import 'os';
13
- import 'path';
14
- import 'crypto';
15
- import 'fs';
16
- import 'process';
17
-
18
- const ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED = "The stream has already been transformed.";
19
- const sdkStreamMixin = (stream) => {
20
- if (!(stream instanceof Readable)) {
21
- const name = stream?.__proto__?.constructor?.name || stream;
22
- throw new Error(`Unexpected stream implementation, expect Stream.Readable instance, got ${name}`);
23
- }
24
- let transformed = false;
25
- const transformToByteArray = async () => {
26
- if (transformed) {
27
- throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED);
28
- }
29
- transformed = true;
30
- return await streamCollector(stream);
31
- };
32
- return Object.assign(stream, {
33
- transformToByteArray,
34
- transformToString: async (encoding) => {
35
- const buf = await transformToByteArray();
36
- if (encoding === undefined || Buffer.isEncoding(encoding)) {
37
- return fromArrayBuffer(buf.buffer, buf.byteOffset, buf.byteLength).toString(encoding);
38
- }
39
- else {
40
- const decoder = new TextDecoder(encoding);
41
- return decoder.decode(buf);
42
- }
43
- },
44
- transformToWebStream: () => {
45
- if (transformed) {
46
- throw new Error(ERR_MSG_STREAM_HAS_BEEN_TRANSFORMED);
47
- }
48
- if (stream.readableFlowing !== null) {
49
- throw new Error("The stream has been consumed by other callbacks.");
50
- }
51
- if (typeof Readable.toWeb !== "function") {
52
- throw new Error("Readable.toWeb() is not supported. Please make sure you are using Node.js >= 17.0.0, or polyfill is available.");
53
- }
54
- transformed = true;
55
- return Readable.toWeb(stream);
56
- },
57
- });
58
- };
59
-
60
- const ECS_CONTAINER_HOST = "169.254.170.2";
61
- const EKS_CONTAINER_HOST_IPv4 = "169.254.170.23";
62
- const EKS_CONTAINER_HOST_IPv6 = "[fd00:ec2::23]";
63
- const checkUrl = (url) => {
64
- if (url.protocol === "https:") {
65
- return;
66
- }
67
- if (url.hostname === ECS_CONTAINER_HOST ||
68
- url.hostname === EKS_CONTAINER_HOST_IPv4 ||
69
- url.hostname === EKS_CONTAINER_HOST_IPv6) {
70
- return;
71
- }
72
- if (url.hostname.includes("[")) {
73
- if (url.hostname === "[::1]" || url.hostname === "[0000:0000:0000:0000:0000:0000:0000:0001]") {
74
- return;
75
- }
76
- }
77
- else {
78
- if (url.hostname === "localhost") {
79
- return;
80
- }
81
- const ipComponents = url.hostname.split(".");
82
- const inRange = (component) => {
83
- const num = parseInt(component, 10);
84
- return 0 <= num && num <= 255;
85
- };
86
- if (ipComponents[0] === "127" &&
87
- inRange(ipComponents[1]) &&
88
- inRange(ipComponents[2]) &&
89
- inRange(ipComponents[3]) &&
90
- ipComponents.length === 4) {
91
- return;
92
- }
93
- }
94
- throw new CredentialsProviderError(`URL not accepted. It must either be HTTPS or match one of the following:
95
- - loopback CIDR 127.0.0.0/8 or [::1/128]
96
- - ECS container host 169.254.170.2
97
- - EKS container host 169.254.170.23 or [fd00:ec2::23]`);
98
- };
99
-
100
- function createGetRequest(url) {
101
- return new HttpRequest({
102
- protocol: url.protocol,
103
- hostname: url.hostname,
104
- port: Number(url.port),
105
- path: url.pathname,
106
- query: Array.from(url.searchParams.entries()).reduce((acc, [k, v]) => {
107
- acc[k] = v;
108
- return acc;
109
- }, {}),
110
- fragment: url.hash,
111
- });
112
- }
113
- async function getCredentials(response) {
114
- const contentType = response?.headers["content-type"] ?? response?.headers["Content-Type"] ?? "";
115
- if (!contentType.includes("json")) {
116
- console.warn("HTTP credential provider response header content-type was not application/json. Observed: " + contentType + ".");
117
- }
118
- const stream = sdkStreamMixin(response.body);
119
- const str = await stream.transformToString();
120
- if (response.statusCode === 200) {
121
- const parsed = JSON.parse(str);
122
- if (typeof parsed.AccessKeyId !== "string" ||
123
- typeof parsed.SecretAccessKey !== "string" ||
124
- typeof parsed.Token !== "string" ||
125
- typeof parsed.Expiration !== "string") {
126
- throw new CredentialsProviderError("HTTP credential provider response not of the required format, an object matching: " +
127
- "{ AccessKeyId: string, SecretAccessKey: string, Token: string, Expiration: string(rfc3339) }");
128
- }
129
- return {
130
- accessKeyId: parsed.AccessKeyId,
131
- secretAccessKey: parsed.SecretAccessKey,
132
- sessionToken: parsed.Token,
133
- expiration: parseRfc3339DateTime(parsed.Expiration),
134
- };
135
- }
136
- if (response.statusCode >= 400 && response.statusCode < 500) {
137
- let parsedBody = {};
138
- try {
139
- parsedBody = JSON.parse(str);
140
- }
141
- catch (e) { }
142
- throw Object.assign(new CredentialsProviderError(`Server responded with status: ${response.statusCode}`), {
143
- Code: parsedBody.Code,
144
- Message: parsedBody.Message,
145
- });
146
- }
147
- throw new CredentialsProviderError(`Server responded with status: ${response.statusCode}`);
148
- }
149
-
150
- const retryWrapper = (toRetry, maxRetries, delayMs) => {
151
- return async () => {
152
- for (let i = 0; i < maxRetries; ++i) {
153
- try {
154
- return await toRetry();
155
- }
156
- catch (e) {
157
- await new Promise((resolve) => setTimeout(resolve, delayMs));
158
- }
159
- }
160
- return await toRetry();
161
- };
162
- };
163
-
164
- const AWS_CONTAINER_CREDENTIALS_RELATIVE_URI = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
165
- const DEFAULT_LINK_LOCAL_HOST = "http://169.254.170.2";
166
- const AWS_CONTAINER_CREDENTIALS_FULL_URI = "AWS_CONTAINER_CREDENTIALS_FULL_URI";
167
- const AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE = "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE";
168
- const AWS_CONTAINER_AUTHORIZATION_TOKEN = "AWS_CONTAINER_AUTHORIZATION_TOKEN";
169
- const fromHttp = (options) => {
170
- options.logger?.debug("@aws-sdk/credential-provider-http", "fromHttp");
171
- let host;
172
- const relative = options.awsContainerCredentialsRelativeUri ?? process.env[AWS_CONTAINER_CREDENTIALS_RELATIVE_URI];
173
- const full = options.awsContainerCredentialsFullUri ?? process.env[AWS_CONTAINER_CREDENTIALS_FULL_URI];
174
- const token = options.awsContainerAuthorizationToken ?? process.env[AWS_CONTAINER_AUTHORIZATION_TOKEN];
175
- const tokenFile = options.awsContainerAuthorizationTokenFile ?? process.env[AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE];
176
- if (relative && full) {
177
- console.warn("AWS SDK HTTP credentials provider:", "you have set both awsContainerCredentialsRelativeUri and awsContainerCredentialsFullUri.");
178
- console.warn("awsContainerCredentialsFullUri will take precedence.");
179
- }
180
- if (token && tokenFile) {
181
- console.warn("AWS SDK HTTP credentials provider:", "you have set both awsContainerAuthorizationToken and awsContainerAuthorizationTokenFile.");
182
- console.warn("awsContainerAuthorizationToken will take precedence.");
183
- }
184
- if (full) {
185
- host = full;
186
- }
187
- else if (relative) {
188
- host = `${DEFAULT_LINK_LOCAL_HOST}${relative}`;
189
- }
190
- else {
191
- throw new CredentialsProviderError(`No HTTP credential provider host provided.
192
- Set AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI.`);
193
- }
194
- const url = new URL(host);
195
- checkUrl(url);
196
- const requestHandler = new NodeHttpHandler({
197
- requestTimeout: options.timeout ?? 1000,
198
- connectionTimeout: options.timeout ?? 1000,
199
- });
200
- return retryWrapper(async () => {
201
- const request = createGetRequest(url);
202
- if (token) {
203
- request.headers.Authorization = token;
204
- }
205
- else if (tokenFile) {
206
- request.headers.Authorization = (await fs.readFile(tokenFile)).toString();
207
- }
208
- try {
209
- const result = await requestHandler.handle(request);
210
- return getCredentials(result.response);
211
- }
212
- catch (e) {
213
- throw new CredentialsProviderError(String(e));
214
- }
215
- }, options.maxRetries ?? 3, options.timeout ?? 1000);
216
- };
217
-
218
- export { fromHttp };
@@ -1,160 +0,0 @@
1
- import 'os';
2
- import 'path';
3
- import { C as CredentialsProviderError, g as getProfileName } from './index-s7VGoewj.js';
4
- import 'crypto';
5
- import 'fs';
6
- import { p as parseKnownFiles } from './parseKnownFiles-DjQIrDWV.js';
7
- import '@logto/connector-kit';
8
- import 'zod';
9
- import 'buffer';
10
- import 'stream';
11
- import 'http';
12
- import 'https';
13
- import 'http2';
14
- import 'util';
15
- import 'process';
16
-
17
- const resolveCredentialSource = (credentialSource, profileName) => {
18
- const sourceProvidersMap = {
19
- EcsContainer: (options) => import('./index-BoQzAHHB.js').then(({ fromContainerMetadata }) => fromContainerMetadata(options)),
20
- Ec2InstanceMetadata: (options) => import('./index-BoQzAHHB.js').then(({ fromInstanceMetadata }) => fromInstanceMetadata(options)),
21
- Environment: (options) => import('./index-CMob0Rvo.js').then(({ fromEnv }) => fromEnv(options)),
22
- };
23
- if (credentialSource in sourceProvidersMap) {
24
- return sourceProvidersMap[credentialSource];
25
- }
26
- else {
27
- throw new CredentialsProviderError(`Unsupported credential source in profile ${profileName}. Got ${credentialSource}, ` +
28
- `expected EcsContainer or Ec2InstanceMetadata or Environment.`);
29
- }
30
- };
31
-
32
- const isAssumeRoleProfile = (arg) => Boolean(arg) &&
33
- typeof arg === "object" &&
34
- typeof arg.role_arn === "string" &&
35
- ["undefined", "string"].indexOf(typeof arg.role_session_name) > -1 &&
36
- ["undefined", "string"].indexOf(typeof arg.external_id) > -1 &&
37
- ["undefined", "string"].indexOf(typeof arg.mfa_serial) > -1 &&
38
- (isAssumeRoleWithSourceProfile(arg) || isAssumeRoleWithProviderProfile(arg));
39
- const isAssumeRoleWithSourceProfile = (arg) => typeof arg.source_profile === "string" && typeof arg.credential_source === "undefined";
40
- const isAssumeRoleWithProviderProfile = (arg) => typeof arg.credential_source === "string" && typeof arg.source_profile === "undefined";
41
- const resolveAssumeRoleCredentials = async (profileName, profiles, options, visitedProfiles = {}) => {
42
- options.logger?.debug("@aws-sdk/credential-provider-ini", "resolveAssumeRoleCredentials (STS)");
43
- const data = profiles[profileName];
44
- if (!options.roleAssumer) {
45
- const { getDefaultRoleAssumer } = await import('./loadSts-CqVZgkwk.js');
46
- options.roleAssumer = getDefaultRoleAssumer({
47
- ...options.clientConfig,
48
- credentialProviderLogger: options.logger,
49
- parentClientConfig: options?.parentClientConfig,
50
- }, options.clientPlugins);
51
- }
52
- const { source_profile } = data;
53
- if (source_profile && source_profile in visitedProfiles) {
54
- throw new CredentialsProviderError(`Detected a cycle attempting to resolve credentials for profile` +
55
- ` ${getProfileName(options)}. Profiles visited: ` +
56
- Object.keys(visitedProfiles).join(", "), false);
57
- }
58
- const sourceCredsProvider = source_profile
59
- ? resolveProfileData(source_profile, profiles, options, {
60
- ...visitedProfiles,
61
- [source_profile]: true,
62
- })
63
- : (await resolveCredentialSource(data.credential_source, profileName)(options))();
64
- const params = {
65
- RoleArn: data.role_arn,
66
- RoleSessionName: data.role_session_name || `aws-sdk-js-${Date.now()}`,
67
- ExternalId: data.external_id,
68
- DurationSeconds: parseInt(data.duration_seconds || "3600", 10),
69
- };
70
- const { mfa_serial } = data;
71
- if (mfa_serial) {
72
- if (!options.mfaCodeProvider) {
73
- throw new CredentialsProviderError(`Profile ${profileName} requires multi-factor authentication, but no MFA code callback was provided.`, false);
74
- }
75
- params.SerialNumber = mfa_serial;
76
- params.TokenCode = await options.mfaCodeProvider(mfa_serial);
77
- }
78
- const sourceCreds = await sourceCredsProvider;
79
- return options.roleAssumer(sourceCreds, params);
80
- };
81
-
82
- const isProcessProfile = (arg) => Boolean(arg) && typeof arg === "object" && typeof arg.credential_process === "string";
83
- const resolveProcessCredentials = async (options, profile) => import('./index-DIAzYdwQ.js').then(({ fromProcess }) => fromProcess({
84
- ...options,
85
- profile,
86
- })());
87
-
88
- const resolveSsoCredentials = async (profile, options = {}) => {
89
- const { fromSSO } = await import('./index-BjiMjUem.js');
90
- return fromSSO({
91
- profile,
92
- logger: options.logger,
93
- })();
94
- };
95
- const isSsoProfile = (arg) => arg &&
96
- (typeof arg.sso_start_url === "string" ||
97
- typeof arg.sso_account_id === "string" ||
98
- typeof arg.sso_session === "string" ||
99
- typeof arg.sso_region === "string" ||
100
- typeof arg.sso_role_name === "string");
101
-
102
- const isStaticCredsProfile = (arg) => Boolean(arg) &&
103
- typeof arg === "object" &&
104
- typeof arg.aws_access_key_id === "string" &&
105
- typeof arg.aws_secret_access_key === "string" &&
106
- ["undefined", "string"].indexOf(typeof arg.aws_session_token) > -1;
107
- const resolveStaticCredentials = (profile, options) => {
108
- options?.logger?.debug("@aws-sdk/credential-provider-ini", "resolveStaticCredentials");
109
- return Promise.resolve({
110
- accessKeyId: profile.aws_access_key_id,
111
- secretAccessKey: profile.aws_secret_access_key,
112
- sessionToken: profile.aws_session_token,
113
- credentialScope: profile.aws_credential_scope,
114
- });
115
- };
116
-
117
- const isWebIdentityProfile = (arg) => Boolean(arg) &&
118
- typeof arg === "object" &&
119
- typeof arg.web_identity_token_file === "string" &&
120
- typeof arg.role_arn === "string" &&
121
- ["undefined", "string"].indexOf(typeof arg.role_session_name) > -1;
122
- const resolveWebIdentityCredentials = async (profile, options) => import('./index-Cq0GQt9c.js').then(({ fromTokenFile }) => fromTokenFile({
123
- webIdentityTokenFile: profile.web_identity_token_file,
124
- roleArn: profile.role_arn,
125
- roleSessionName: profile.role_session_name,
126
- roleAssumerWithWebIdentity: options.roleAssumerWithWebIdentity,
127
- logger: options.logger,
128
- parentClientConfig: options.parentClientConfig,
129
- })());
130
-
131
- const resolveProfileData = async (profileName, profiles, options, visitedProfiles = {}) => {
132
- const data = profiles[profileName];
133
- if (Object.keys(visitedProfiles).length > 0 && isStaticCredsProfile(data)) {
134
- return resolveStaticCredentials(data, options);
135
- }
136
- if (isAssumeRoleProfile(data)) {
137
- return resolveAssumeRoleCredentials(profileName, profiles, options, visitedProfiles);
138
- }
139
- if (isStaticCredsProfile(data)) {
140
- return resolveStaticCredentials(data, options);
141
- }
142
- if (isWebIdentityProfile(data)) {
143
- return resolveWebIdentityCredentials(data, options);
144
- }
145
- if (isProcessProfile(data)) {
146
- return resolveProcessCredentials(options, profileName);
147
- }
148
- if (isSsoProfile(data)) {
149
- return await resolveSsoCredentials(profileName, options);
150
- }
151
- throw new CredentialsProviderError(`Profile ${profileName} could not be found or parsed in shared credentials file.`);
152
- };
153
-
154
- const fromIni = (init = {}) => async () => {
155
- init.logger?.debug("@aws-sdk/credential-provider-ini", "fromIni");
156
- const profiles = await parseKnownFiles(init);
157
- return resolveProfileData(getProfileName(init), profiles, init);
158
- };
159
-
160
- export { fromIni };
@@ -1,14 +0,0 @@
1
- export { a as credentialsTreatedAsExpired, c as credentialsWillNeedRefresh, d as defaultProvider } from './index-s7VGoewj.js';
2
- import '@logto/connector-kit';
3
- import 'zod';
4
- import 'os';
5
- import 'path';
6
- import 'crypto';
7
- import 'fs';
8
- import 'buffer';
9
- import 'stream';
10
- import 'http';
11
- import 'https';
12
- import 'http2';
13
- import 'util';
14
- import 'process';