Skip to content

Commit f245572

Browse files
authored
Merge pull request #34 from mtrezza/fix
Add CI and README improvement
2 parents ce10b72 + 225082d commit f245572

File tree

4 files changed

+1714
-220
lines changed

4 files changed

+1714
-220
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,69 @@ on:
66
pull_request:
77
branches:
88
- '**'
9+
env:
10+
NODE_VERSION: 14.16.1
911
jobs:
10-
build:
12+
check-circular:
13+
name: Circular Dependencies
14+
timeout-minutes: 5
15+
runs-on: ubuntu-18.04
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Use Node.js ${{ matrix.NODE_VERSION }}
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.NODE_VERSION }}
22+
- name: Cache Node.js modules
23+
uses: actions/cache@v2
24+
with:
25+
path: ~/.npm
26+
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
27+
restore-keys: |
28+
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
29+
- name: Install dependencies
30+
run: npm ci
31+
- run: npm run madge:circular
32+
check-lint:
33+
name: Lint
34+
timeout-minutes: 5
35+
runs-on: ubuntu-18.04
36+
steps:
37+
- uses: actions/checkout@v2
38+
- name: Use Node.js ${{ matrix.NODE_VERSION }}
39+
uses: actions/setup-node@v1
40+
with:
41+
node-version: ${{ matrix.node-version }}
42+
- name: Cache Node.js modules
43+
uses: actions/cache@v2
44+
with:
45+
path: ~/.npm
46+
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
47+
restore-keys: |
48+
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
49+
- name: Install dependencies
50+
run: npm ci
51+
- run: npm run lint
52+
check-tests:
53+
name: Tests
54+
timeout-minutes: 5
1155
runs-on: ubuntu-18.04
12-
timeout-minutes: 30
1356
steps:
1457
- uses: actions/checkout@v2
1558
- name: Use Node.js
1659
uses: actions/setup-node@v1
1760
with:
18-
node-version: '10.14'
61+
node-version: ${{ matrix.NODE_VERSION }}
1962
- name: Cache Node.js modules
2063
uses: actions/cache@v2
2164
with:
2265
path: ~/.npm
23-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
66+
key: ${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
2467
restore-keys: |
25-
${{ runner.os }}-
68+
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
2669
- run: npm ci
2770
- run: npm run lint
2871
- run: npm test
2972
env:
3073
CI: true
31-
- run: bash <(curl -s https://codecov.io/bash)
74+
- run: bash <(curl -s https://codecov.io/bash)

README.md

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ The Parse Server API Mail Adapter enables Parse Server to send emails using any
2121
- [Cloud Code](#cloud-code)
2222
- [Example](#example)
2323
- [Parameters](#parameters)
24+
- [Supported APIs](#supported-apis)
25+
- [Providers](#providers)
26+
- [Example for Mailgun](#example-for-mailgun)
27+
- [Custom API](#custom-api)
2428
- [Need help?](#need-help)
2529

2630
# Installation
@@ -54,14 +58,14 @@ You can modify the script to use any other API you like or debug-step through th
5458
An example configuration to add the API Mail Adapter to Parse Server could look like this:
5559
5660
```js
57-
// Declare a mail client
61+
// Configure mail client
5862
const mailgun = require('mailgun.js');
5963
const mailgunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
6064
const mailgunDomain = process.env.MAILGUN_DOMAIN;
6165
6266
// Configure Parse Server
6367
const server = new ParseServer({
64-
...otherOptions,
68+
...otherServerOptions,
6569
6670
emailAdapter: {
6771
module: 'parse-server-api-mail-adapter',
@@ -85,7 +89,7 @@ const server = new ParseServer({
8589
htmlPath: './files/verification_email.html')
8690
},
8791
// A custom email template that can be used when sending emails
88-
// from Cloud Code; the template name can be choosen freely; it
92+
// from Cloud Code; the template name can be chosen freely; it
8993
// is possible to add various custom templates.
9094
customEmail: {
9195
subjectPath: './files/custom_email_subject.txt'),
@@ -119,7 +123,7 @@ const server = new ParseServer({
119123
}
120124
}
121125
},
122-
// The asynronous callback that contains the composed email payload to
126+
// The asynchronous callback that contains the composed email payload to
123127
// be passed on to an 3rd party API and optional meta data. The payload
124128
// may need to be converted specifically for the API; conversion for
125129
// common APIs is conveniently available in the `ApiPayloadConverter`.
@@ -174,9 +178,9 @@ Localization allows to use a specific template depending on the user locale. To
174178

175179
The locale returned by `localeCallback` will be used to look for locale-specific template files. If the callback returns an invalid locale or nothing at all (`undefined`), localization will be ignored and the default files will be used.
176180

177-
The locale-specific files are placed in subfolders with the name of either the whole locale (e.g. `de-AT`), or only the language (e.g. `de`). The locale has to be in format `[language]-[country]` as specified in [IETF BCP 47](https://tools.ietf.org/html/bcp47), e.g. `de-AT`.
181+
The locale-specific files are placed in sub-folders with the name of either the whole locale (e.g. `de-AT`), or only the language (e.g. `de`). The locale has to be in format `[language]-[country]` as specified in [IETF BCP 47](https://tools.ietf.org/html/bcp47), e.g. `de-AT`.
178182

179-
Localized files are placed in subfolders of the given path, for example:
183+
Localized files are placed in sub-folders of the given path, for example:
180184
```js
181185
base/
182186
├── example.html // default file
@@ -221,7 +225,77 @@ Parse.Cloud.sendEmail({
221225
| `extra` | `Object` | yes | `{}` | `{ key: value }` | Any additional variables to pass to the mail provider API. |
222226
| `user` | `Parse.User` | yes | `undefined` | - | The Parse User that the is the recipient of the email. |
223227

228+
# Supported APIs
229+
230+
This adapter supports any REST API by adapting the API payload in the adapter configuration `apiCallback` according to the API specification.
231+
232+
## Providers
233+
234+
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:
235+
236+
- [Mailgun](https://www.mailgun.com)
237+
238+
If the provider you are using is not already supported, please feel free to open a PR.
239+
240+
### Example for Mailgun
241+
242+
This is an example for the Mailgun client:
243+
244+
```js
245+
// Configure mail client
246+
const mailgun = require('mailgun.js');
247+
const mailgunClient = mailgun.client({ username: 'api', key: process.env.MAILGUN_API_KEY });
248+
const mailgunDomain = process.env.MAILGUN_DOMAIN;
249+
250+
// Configure Parse Server
251+
const server = new ParseServer({
252+
...otherServerOptions,
253+
254+
emailAdapter: {
255+
module: 'parse-server-api-mail-adapter',
256+
options: {
257+
... otherAdapterOptions,
224258

259+
apiCallback: async ({ payload, locale }) => {
260+
const mailgunPayload = ApiPayloadConverter.mailgun(payload);
261+
await mailgunClient.messages.create(mailgunDomain, mailgunPayload);
262+
}
263+
}
264+
}
265+
});
266+
```
267+
268+
## Custom API
269+
270+
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.
271+
272+
```js
273+
// Configure mail client
274+
const customMail = require('customMail.js');
275+
const customMailClient = customMail.configure({ ... });
276+
277+
// Configure Parse Server
278+
const server = new ParseServer({
279+
...otherOptions,
280+
281+
emailAdapter: {
282+
module: 'parse-server-api-mail-adapter',
283+
options: {
284+
... otherOptions,
285+
286+
apiCallback: async ({ payload, locale }) => {
287+
const customPayload = {
288+
customFrom: payload.from,
289+
customTo: payload.to,
290+
customSubject: payload.subject,
291+
customText: payload.text
292+
};
293+
await customMailClient.sendEmail(customPayload);
294+
}
295+
}
296+
}
297+
});
298+
```
225299

226300
# Need help?
227301

0 commit comments

Comments
 (0)