mirror of
https://github.com/logto-io/logto.git
synced 2025-01-20 21:32:31 -05:00
570a4ea9e2
* feat: create invitation * refactor: update test imports * refactor: update unit tests * refactor: update docs * refactor: update api tests * chore: add changesets * refactor: add comments * refactor: fix swagger check * refactor: keep compatibility
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import type { EmailContent } from '@aws-sdk/client-sesv2';
|
|
import { SendEmailCommand, SESv2Client } from '@aws-sdk/client-sesv2';
|
|
import type { AwsCredentialIdentity } from '@aws-sdk/types';
|
|
import { replaceSendMessageHandlebars, type SendMessagePayload } from '@logto/connector-kit';
|
|
|
|
import type { AwsSesConfig, Template } from './types.js';
|
|
|
|
export const makeClient = (
|
|
accessKeyId: string,
|
|
secretAccessKey: string,
|
|
region: string
|
|
): SESv2Client => {
|
|
const credentials: AwsCredentialIdentity = {
|
|
accessKeyId,
|
|
secretAccessKey,
|
|
};
|
|
|
|
return new SESv2Client({ credentials, region });
|
|
};
|
|
|
|
export const makeEmailContent = (template: Template, payload: SendMessagePayload): EmailContent => {
|
|
return {
|
|
Simple: {
|
|
Subject: { Data: replaceSendMessageHandlebars(template.subject, payload), Charset: 'utf8' },
|
|
Body: {
|
|
Html: {
|
|
Data: replaceSendMessageHandlebars(template.content, payload),
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|
|
|
|
export const makeCommand = (
|
|
config: AwsSesConfig,
|
|
emailContent: EmailContent,
|
|
to: string
|
|
): SendEmailCommand => {
|
|
return new SendEmailCommand({
|
|
Destination: { ToAddresses: [to] },
|
|
Content: emailContent,
|
|
FromEmailAddress: config.emailAddress,
|
|
FromEmailAddressIdentityArn: config.emailAddressIdentityArn,
|
|
FeedbackForwardingEmailAddress: config.feedbackForwardingEmailAddress,
|
|
FeedbackForwardingEmailAddressIdentityArn: config.feedbackForwardingEmailAddressIdentityArn,
|
|
ConfigurationSetName: config.configurationSetName,
|
|
});
|
|
};
|