Skip to content

Commit 7b45c72

Browse files
author
Sergey Khomushin
committed
create Official EmailJS SDK for Node.js
0 parents  commit 7b45c72

20 files changed

+10603
-0
lines changed

.eslintrc.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = {
2+
env: {
3+
jest: true,
4+
node: true,
5+
es2021: true,
6+
browser: false,
7+
},
8+
plugins: ['@typescript-eslint', 'import'],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/eslint-recommended',
12+
'plugin:@typescript-eslint/recommended',
13+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
14+
'plugin:import/errors',
15+
'plugin:import/warnings',
16+
],
17+
settings: {
18+
'import/resolver': {
19+
node: {
20+
paths: ['src'],
21+
extensions: ['.js', '.ts'],
22+
},
23+
typescript: {
24+
paths: ['src'],
25+
extensions: ['.js', '.ts'],
26+
},
27+
},
28+
},
29+
parser: '@typescript-eslint/parser',
30+
parserOptions: {
31+
ecmaVersion: 'latest',
32+
sourceType: 'module',
33+
project: './tsconfig.json',
34+
},
35+
ignorePatterns: ['.eslintrc.js', 'jest.config.ts', '*.spec.ts'],
36+
rules: {
37+
// sometimes we are sure it is not null
38+
'@typescript-eslint/no-non-null-assertion': 'off',
39+
},
40+
};

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CI
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the master branch
8+
push:
9+
branches: [main]
10+
pull_request:
11+
branches: [main]
12+
13+
# Allows you to run this workflow manually from the Actions tab
14+
workflow_dispatch:
15+
16+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
17+
jobs:
18+
# This workflow contains a single job called "build"
19+
build:
20+
# The type of runner that the job will run on
21+
runs-on: ubuntu-latest
22+
23+
# Steps represent a sequence of tasks that will be executed as part of the job
24+
steps:
25+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26+
- uses: actions/checkout@main
27+
28+
- name: Install modules
29+
run: npm ci
30+
31+
- name: Run tests
32+
run: npm run test
33+
34+
- name: Upload coverage to Codecov
35+
uses: codecov/codecov-action@v3

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Specifies files to intentionally ignore when using Git
2+
# http://git-scm.com/docs/gitignore
3+
4+
node_modules/
5+
coverage/
6+
.idea/
7+
*.swp
8+
.DS_Store
9+
Thumbs.db
10+
11+
# dist files
12+
cjs/
13+
mjs/

.npmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Specifies files to intentionally ignore when using Git
2+
# http://git-scm.com/docs/gitignore
3+
4+
# git ignore
5+
.github/
6+
node_modules/
7+
coverage/
8+
.idea/
9+
*.swp
10+
.DS_Store
11+
Thumbs.db
12+
13+
# dev files
14+
.eslintrc.js
15+
.gitignore
16+
.npmignore
17+
jest.config.ts
18+
set-version.sh
19+
tsconfig.json
20+
21+
# source code files
22+
src/

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2021 EmailJS. https://www.emailjs.com
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Official EmailJS SDK for Node.js
2+
3+
SDK for [EmailJS.com](https://www.emailjs.com) customers.
4+
\
5+
Use you EmailJS account for sending emails.
6+
7+
[![codecov](https://codecov.io/gh/emailjs-com/emailjs-nodejs/branch/main/graph/badge.svg)](https://codecov.io/gh/emailjs-com/emailjs-nodejs)
8+
[![npm version](https://img.shields.io/npm/v/@emailjs/nodejs.svg)](https://www.npmjs.com/package/@emailjs/nodejs)
9+
10+
## Disclaimer
11+
12+
This is a NodeJS-only version, otherwise use
13+
the [REST API](https://www.emailjs.com/docs/rest-api/send/).
14+
15+
## Links
16+
17+
[Official SDK Docs](https://www.emailjs.com/docs)
18+
19+
## Intro
20+
21+
EmailJS helps to send emails directly from your code.
22+
No large knowledge is required – just connect EmailJS to one of the supported
23+
email services, create an email template, and use our SDK
24+
to trigger an email.
25+
26+
## Usage
27+
28+
Install EmailJS SDK using [npm](https://www.npmjs.com/):
29+
30+
```bash
31+
$ npm install @emailjs/nodejs
32+
```
33+
34+
## Examples
35+
36+
### ECMAScript modules
37+
38+
**send email**
39+
40+
```js
41+
import emailjs from '@emailjs/nodejs';
42+
43+
const templateParams = {
44+
name: 'James',
45+
notes: 'Check this out!',
46+
};
47+
48+
emailjs.send('<YOUR_SERVICE_ID>', '<YOUR_TEMPLATE_ID>', templateParams, '<YOUR_PUBLIC_KEY>').then(
49+
(response) => {
50+
console.log('SUCCESS!', response.status, response.text);
51+
},
52+
(err) => {
53+
console.log('FAILED...', err);
54+
},
55+
);
56+
```
57+
58+
**init (optional)**
59+
60+
```js
61+
import emailjs from '@emailjs/nodejs';
62+
63+
// set Public Key as global settings
64+
emailjs.init('<YOUR_PUBLIC_KEY>');
65+
66+
emailjs.send('<YOUR_SERVICE_ID>', '<YOUR_TEMPLATE_ID>').then(
67+
(response) => {
68+
console.log('SUCCESS!', response.status, response.text);
69+
},
70+
(err) => {
71+
console.log('FAILED...', err);
72+
},
73+
);
74+
```
75+
76+
**await/async with EmailJS error handler**
77+
78+
```js
79+
import { send, EmailJSResponseStatus } from '@emailjs/nodejs';
80+
81+
try {
82+
await emailjs.send('<YOUR_SERVICE_ID>', '<YOUR_TEMPLATE_ID>', {}, '<YOUR_PUBLIC_KEY>');
83+
console.log('SUCCESS!');
84+
} catch (err) {
85+
if (err instanceof EmailJSResponseStatus) {
86+
console.log('EMAILJS FAILED...', err);
87+
return;
88+
}
89+
90+
console.log('ERROR', err);
91+
}
92+
```
93+
94+
### CommonJS modules
95+
96+
**send email**
97+
98+
```js
99+
const emailjs = require('@emailjs/nodejs');
100+
101+
var templateParams = {
102+
name: 'James',
103+
notes: 'Check this out!',
104+
};
105+
106+
emailjs.send('<YOUR_SERVICE_ID>', '<YOUR_TEMPLATE_ID>', templateParams).then(
107+
function (response) {
108+
console.log('SUCCESS!', response.status, response.text);
109+
},
110+
function (err) {
111+
console.log('FAILED...', err);
112+
},
113+
);
114+
```

jest.config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { Config } from '@jest/types';
2+
3+
const config: Config.InitialOptions = {
4+
collectCoverage: true,
5+
coverageDirectory: 'coverage',
6+
transform: {
7+
'^.+\\.ts?$': ['ts-jest', {
8+
useESM: true,
9+
diagnostics: {
10+
warnOnly: true,
11+
},
12+
}],
13+
},
14+
testRegex: '((\\.|/)(spec))\\.(ts?)$',
15+
moduleFileExtensions: ['ts', 'js'],
16+
extensionsToTreatAsEsm: ['.ts'],
17+
modulePaths: ['src'],
18+
moduleNameMapper: {
19+
'^(\\.{1,2}/.*)\\.js$': '$1',
20+
'^#app/(.*)\\.js$': '$1',
21+
},
22+
testPathIgnorePatterns: ['/node_modules/'],
23+
testEnvironment: 'node',
24+
preset: 'ts-jest',
25+
};
26+
27+
module.exports = config;

0 commit comments

Comments
 (0)