-
-
Notifications
You must be signed in to change notification settings - Fork 20
feat: add AWS SES payload adapter #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6c017b6
feat: A SES provider
woutercouvaras 8b85e2d
fix: updated SES example
woutercouvaras dad785f
fix: linting issue addressed
woutercouvaras a9c95f2
fix: reset param names to match sendMail metchod
woutercouvaras f8bcc1d
feat: test for ses converter
woutercouvaras f622669
fix: updates to ses converter as caught by tests
woutercouvaras 792f685
fix: requested updates
woutercouvaras cdea2d4
fix: requested updates
woutercouvaras 45d0732
updated readme as requested
woutercouvaras 4532af1
fix: use strict camel case and remove unecessary empty string check
woutercouvaras 57b3ec4
Update README.md
mtrezza 1aac6b9
Update README.md
mtrezza 061854a
fix: updated credential definition
woutercouvaras 601a5fb
Update README.md
mtrezza 827de2c
fix: removed uncessary space
woutercouvaras 0026d8d
fix: removed optional chaining for old node version support
woutercouvaras be70238
updated lock file from install
woutercouvaras f229698
Merge branch 'ses-provider' of github.com:woutercouvaras/parse-server…
woutercouvaras db25d7a
refactor payload converter
mtrezza 360c773
more refactor
mtrezza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -227,8 +227,8 @@ Parse.Cloud.sendEmail({ | |
|
|
||
| | Parameter | Type | Optional | Default Value | Example Value | Description | | ||
| |----------------|--------------|----------|---------------|-----------------------------|------------------------------------------------------------------------------------------------| | ||
| | `sender` | `String` | | - | `[email protected]` | The email sender address; overrides the sender address specified in the adapter configuration. | | ||
| | `recipient` | `String` | | - | `[email protected]` | The email recipient; if set overrides the email address of the `user`. | | ||
| | `from` | `String` | | - | `[email protected]` | The email sender address; overrides the sender address specified in the adapter configuration. | | ||
| | `to` | `String` | | - | `[email protected]` | The email recipient; if set overrides the email address of the `user`. | | ||
| | `subject` | `String` | | - | `Welcome` | The email subject. | | ||
| | `text` | `String` | | - | `Thank you for signing up!` | The plain-text email content. | | ||
| | `html` | `String` | yes | `undefined` | `<html>...</html>` | The HTML email content. | | ||
|
|
@@ -246,6 +246,7 @@ This adapter supports any REST API by adapting the API payload in the adapter co | |
| For convenience, support for common APIs is already built into this adapter and available via the `ApiPayloadConverter`. The following is a list of currently supported API providers: | ||
|
|
||
| - [Mailgun](https://www.mailgun.com) | ||
| - [AWS SES - v3 SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-ses/index.html) | ||
|
|
||
| If the provider you are using is not already supported, please feel free to open a PR. | ||
|
|
||
|
|
@@ -277,6 +278,59 @@ const server = new ParseServer({ | |
| }); | ||
| ``` | ||
|
|
||
| ### Example for AWS SES v3 sdk | ||
woutercouvaras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This is an example for the SES client for the **v3 SDK**. Please note that v2 works quite differently: | ||
woutercouvaras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```js | ||
| // Configure mail client | ||
| const { SES, SendEmailCommand } = require("@aws-sdk/client-ses"); | ||
|
|
||
| // `fromInstanceMetadata` is for dynamically getting credentials via IMDS on your AWS instance | ||
| // `fromEnv` grabs your credentials from environment variables (I use this method for testing and the former for production) | ||
| const { fromInstanceMetadata, fromEnv } = require("@aws-sdk/credential-providers"); | ||
woutercouvaras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| let awsCredsProvider; | ||
| if (process.env.NODE_ENV && process.env.NODE_ENV === "production") { | ||
| awsCredsProvider = fromInstanceMetadata(); | ||
| } else { | ||
| awsCredsProvider = fromEnv(); | ||
| } | ||
|
|
||
| // `awsCredsProvider` returns a promise, once resolved, you get your credentials | ||
woutercouvaras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const getCreds = async () => { | ||
| return await awsCredsProvider(); | ||
| }; | ||
woutercouvaras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Perhaps there's a better way to do this. Top level await will be amazing. | ||
woutercouvaras marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| getCreds().then(credentials => { | ||
| const sesClient = new SES({ | ||
| // credentials from `awsCredsProvider` provider | ||
| credentials, | ||
| region: 'eu-west-1', | ||
| apiVersion: '2010-12-01' | ||
| }); | ||
|
|
||
| // Configure Parse Server | ||
| const server = new ParseServer({ | ||
| ...otherServerOptions, | ||
|
|
||
| emailAdapter: { | ||
| module: 'parse-server-api-mail-adapter', | ||
| options: { | ||
| ... otherAdapterOptions, | ||
|
|
||
| apiCallback: async ({ payload, locale }) => { | ||
| const awsSESPayload = ApiPayloadConverter.awsSES(payload); | ||
| const command = new SendEmailCommand(awsSESPayload); | ||
| await sesClient.send(command); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| }) | ||
| ``` | ||
|
|
||
| ## Custom API | ||
|
|
||
| This is an example of how the API payload can be adapted in the adapter configuration `apiCallback` according to a custom email provider's API specification. | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.