Skip to content

Commit

Permalink
SLSCMN-8 email service
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Dec 17, 2023
1 parent fd469be commit 830d5da
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/services/email-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import SQSService from './sqs-service';

/**
* The addresses to which the email should be sent.
*/
export type EmailDestination = {
to: string[];
cc?: string[];
bcc?: string[];
};

/**
* An object containing data to populate the email template. The object keys
* are strings and the values may be strings, numbers, or booleans.
*
* _Example:_
* ```
* {
* name: 'Joe Smith',
* age: 39,
* isEnabled: true
* }
* ```
*/
export type EmailTemplateData = Record<string, string | number | boolean>;

/**
* The `Email` type describes the request to send an email to one or more
* recipients (i.e. destinations).
*/
export type Email = {
destinations: EmailDestination[];
templateName: string;
templateData?: EmailTemplateData;
};

/**
* Sends an email message asynchronously. Provide the `email` and the AWS SQS
* `queueUrl`. The `queueURL` is the LeanStacks Email microservice SQS Queue.
* @param email - The `Email` object describing the email message.
* @param queueUrl - The AWS SQS queue URL for the Email microservice.
*/
const send = async (email: Email, queueUrl: string): Promise<void> => {
await SQSService.sendMessage({
QueueUrl: queueUrl,
MessageBody: JSON.stringify({
data: email.templateData,
destinations: email.destinations,
template: email.templateName,
}),
});
};

/**
* Use the `EmailService` to send an email message. Messages are sent
* asynchronously.
*/
const EmailService = { send };

export default EmailService;
3 changes: 3 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export {
export { default as DynamoService } from './dynamo.service';

export { default as SQSService } from './sqs-service';

export { Email, EmailDestination, EmailTemplateData } from './email-service';
export { default as EmailService } from './email-service';

0 comments on commit 830d5da

Please sign in to comment.