-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters