Skip to content

Commit fb3effe

Browse files
authored
Merge pull request #133 from accounts-js/remove-email-server
Remove emailjs dependency
2 parents 55adc07 + 3bdb602 commit fb3effe

File tree

7 files changed

+41
-108
lines changed

7 files changed

+41
-108
lines changed

packages/password/__tests__/accounts-password.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ describe('AccountsPassword', () => {
335335
password.setStore({ findUserByEmail, addEmailVerificationToken } as any);
336336
password.server = {
337337
prepareMail,
338-
email: { sendMail },
338+
options: { sendMail },
339339
sanitizeUser,
340340
} as any;
341341
set(password.server, 'options.emailTemplates', {});
@@ -354,7 +354,7 @@ describe('AccountsPassword', () => {
354354
password.setStore({ findUserByEmail, addEmailVerificationToken } as any);
355355
password.server = {
356356
prepareMail,
357-
email: { sendMail },
357+
options: { sendMail },
358358
sanitizeUser,
359359
} as any;
360360
set(password.server, 'options.emailTemplates', {});
@@ -399,7 +399,7 @@ describe('AccountsPassword', () => {
399399
password.setStore({ findUserByEmail, addResetPasswordToken } as any);
400400
password.server = {
401401
prepareMail,
402-
email: { sendMail },
402+
options: { sendMail },
403403
sanitizeUser,
404404
getFirstUserEmail,
405405
} as any;
@@ -436,7 +436,7 @@ describe('AccountsPassword', () => {
436436
password.setStore({ findUserByEmail, addResetPasswordToken } as any);
437437
password.server = {
438438
prepareMail,
439-
email: { sendMail },
439+
options: { sendMail },
440440
sanitizeUser,
441441
getFirstUserEmail,
442442
} as any;

packages/password/src/accounts-password.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ export default class AccountsPassword implements AuthService {
276276
this.server.options.emailTemplates.from
277277
);
278278

279-
await this.server.email.sendMail(resetPasswordMail);
279+
await this.server.options.sendMail(resetPasswordMail);
280280
}
281281

282282
/**
@@ -307,7 +307,7 @@ export default class AccountsPassword implements AuthService {
307307
this.server.options.emailTemplates.from
308308
);
309309

310-
await this.server.email.sendMail(resetPasswordMail);
310+
await this.server.options.sendMail(resetPasswordMail);
311311
}
312312

313313
/**
@@ -335,7 +335,7 @@ export default class AccountsPassword implements AuthService {
335335
this.server.options.emailTemplates.from
336336
);
337337

338-
await this.server.email.sendMail(enrollmentMail);
338+
await this.server.options.sendMail(enrollmentMail);
339339
}
340340

341341
/**

packages/server/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"babel-polyfill": "^6.23.0",
5353
"bcryptjs": "^2.4.0",
5454
"crypto": "^0.0.3",
55-
"emailjs": "^1.0.8",
5655
"jsonwebtoken": "^7.2.1",
5756
"jwt-decode": "^2.1.0",
5857
"lodash": "^4.16.4"

packages/server/src/accounts-server.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ import {
1313
HookListener,
1414
} from '@accounts/common';
1515
import config from './config';
16-
import { generateAccessToken, generateRefreshToken } from './tokens';
17-
import Email, {
16+
import {
17+
generateAccessToken,
18+
generateRefreshToken,
19+
} from './tokens';
20+
import {
1821
emailTemplates,
19-
EmailConnector,
2022
EmailTemplateType,
23+
sendMail,
2124
} from './email';
2225
import {
2326
AccountsServerOptions,
@@ -45,6 +48,7 @@ const defaultOptions = {
4548
},
4649
emailTemplates,
4750
userObjectSanitizer: (user: UserObjectType) => user,
51+
sendMail,
4852
};
4953

5054
export type RemoveListnerHandle = () => EventEmitter;
@@ -66,7 +70,6 @@ export const ServerHooks = {
6670

6771
export class AccountsServer {
6872
public options: AccountsServerOptions;
69-
public email: EmailConnector;
7073
private services: { [key: string]: AuthService };
7174
private db: DBInterface;
7275
private hooks: EventEmitter;
@@ -88,11 +91,6 @@ export class AccountsServer {
8891
this.services[service].server = this;
8992
}
9093

91-
// Initialize emails
92-
this.email = this.options.sendMail
93-
? { sendMail: this.options.sendMail }
94-
: new Email(this.options.email);
95-
9694
// Initialize hooks
9795
this.hooks = new EventEmitter();
9896
}

packages/server/src/email.ts

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as emailServer from 'emailjs';
2-
import { Client } from 'emailjs'; // tslint:disable-line no-duplicate-imports
31
import { UserObjectType } from '@accounts/common';
42

53
export interface EmailTemplateType {
@@ -37,40 +35,13 @@ export const emailTemplates = {
3735
},
3836
};
3937

40-
export interface EmailConnector {
41-
sendMail(mail: object): Promise<object>;
42-
}
43-
44-
class Email {
45-
private server: Client;
46-
47-
constructor(emailConfig: object) {
48-
if (emailConfig) {
49-
this.server = emailServer.connect(emailConfig);
50-
}
51-
}
52-
53-
public sendMail(mail: object): Promise<object> {
54-
return new Promise((resolve, reject) => {
55-
// If no configuration for email just warn the user
56-
if (!this.server) {
57-
// tslint:disable-next-line no-console
58-
console.warn(
59-
'No configuration for email, you must set an email configuration'
60-
);
61-
// tslint:disable-next-line no-console
62-
console.log(mail);
63-
resolve();
64-
return;
65-
}
66-
this.server.send(mail, (err: object, message: object) => {
67-
if (err) {
68-
return reject(err);
69-
}
70-
return resolve(message);
71-
});
72-
});
73-
}
74-
}
38+
export type SendMailType = (mail: object) => Promise<void>;
7539

76-
export default Email;
40+
export const sendMail = async (mail: object): Promise<void> => {
41+
// tslint:disable-next-line no-console
42+
console.warn(
43+
'No configuration for email, you must set an email configuration'
44+
);
45+
// tslint:disable-next-line no-console
46+
console.log(mail);
47+
}

packages/server/src/types.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { UserObjectType, CreateUserType, SessionType } from '@accounts/common';
2-
import { EmailTemplatesType, EmailTemplateType } from './email';
2+
import { EmailTemplatesType, EmailTemplateType, SendMailType } from './email';
33
import { AccountsServer } from './accounts-server';
44

55
export interface AuthService {
@@ -31,10 +31,6 @@ export type PrepareMailFunction = (
3131

3232
export type EmailType = EmailTemplateType & { to: string };
3333

34-
export type SendMailFunction = (
35-
emailConfig: EmailType | object
36-
) => Promise<object>;
37-
3834
export interface AccountsServerOptions {
3935
db: DBInterface;
4036
tokenSecret: string;
@@ -56,7 +52,7 @@ export interface AccountsServerOptions {
5652
resumeSessionValidator?: ResumeSessionValidator;
5753
siteUrl?: string;
5854
prepareMail?: PrepareMailFunction;
59-
sendMail?: SendMailFunction;
55+
sendMail?: SendMailType;
6056
// https://github.com/eleith/emailjs#emailserverconnectoptions
6157
email?: object;
6258
}

packages/server/yarn.lock

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616
version "8.0.47"
1717
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.47.tgz#968e596f91acd59069054558a00708c445ca30c2"
1818

19-
addressparser@^0.3.2:
20-
version "0.3.2"
21-
resolved "https://registry.yarnpkg.com/addressparser/-/addressparser-0.3.2.tgz#59873f35e8fcf6c7361c10239261d76e15348bb2"
22-
23-
addressparser@~0.2.0:
24-
version "0.2.1"
25-
resolved "https://registry.yarnpkg.com/addressparser/-/addressparser-0.2.1.tgz#d11a5b2eeda04cfefebdf3196c10ae13db6cd607"
26-
2719
ansi-regex@^2.0.0:
2820
version "2.1.1"
2921
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
@@ -102,8 +94,8 @@ [email protected]:
10294
hoek "2.x.x"
10395

10496
brace-expansion@^1.1.7:
105-
version "1.1.8"
106-
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292"
97+
version "1.1.11"
98+
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
10799
dependencies:
108100
balanced-match "^1.0.0"
109101
concat-map "0.0.1"
@@ -112,10 +104,6 @@ [email protected]:
112104
version "1.0.1"
113105
resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819"
114106

115-
116-
version "1.1.0"
117-
resolved "https://registry.yarnpkg.com/bufferjs/-/bufferjs-1.1.0.tgz#095ffa39c5e6b40a2178a1169c9effc584a73201"
118-
119107
caseless@~0.11.0:
120108
version "0.11.0"
121109
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.11.0.tgz#715b96ea9841593cc33067923f5ec60ebda4f7d7"
@@ -199,23 +187,6 @@ [email protected]:
199187
base64url "^2.0.0"
200188
safe-buffer "^5.0.1"
201189

202-
emailjs@^1.0.8:
203-
version "1.0.12"
204-
resolved "https://registry.yarnpkg.com/emailjs/-/emailjs-1.0.12.tgz#bd6559c51c4963125218626da098be722f7a1c72"
205-
dependencies:
206-
addressparser "^0.3.2"
207-
mimelib "0.2.14"
208-
moment "2.15.2"
209-
starttls "1.0.1"
210-
optionalDependencies:
211-
bufferjs "1.1.0"
212-
213-
encoding@~0.1:
214-
version "0.1.12"
215-
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
216-
dependencies:
217-
iconv-lite "~0.4.13"
218-
219190
escape-string-regexp@^1.0.2:
220191
version "1.0.5"
221192
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
@@ -311,9 +282,16 @@ http-signature@~1.1.0:
311282
jsprim "^1.2.2"
312283
sshpk "^1.7.0"
313284

314-
iconv-lite@~0.4.13:
315-
version "0.4.13"
316-
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2"
285+
inflight@^1.0.4:
286+
version "1.0.6"
287+
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
288+
dependencies:
289+
once "^1.3.0"
290+
wrappy "1"
291+
292+
inherits@2:
293+
version "2.0.3"
294+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
317295

318296
inflight@^1.0.4:
319297
version "1.0.6"
@@ -449,12 +427,11 @@ mime-types@^2.1.12, mime-types@~2.1.7:
449427
dependencies:
450428
mime-db "~1.30.0"
451429

452-
453-
version "0.2.14"
454-
resolved "https://registry.yarnpkg.com/mimelib/-/mimelib-0.2.14.tgz#2a1aa724bd190b85bd526e6317ab6106edfd6831"
430+
minimatch@^3.0.4:
431+
version "3.0.4"
432+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
455433
dependencies:
456-
addressparser "~0.2.0"
457-
encoding "~0.1"
434+
brace-expansion "^1.1.7"
458435

459436
minimatch@^3.0.4:
460437
version "3.0.4"
@@ -466,10 +443,6 @@ [email protected]:
466443
version "1.2.0"
467444
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
468445

469-
470-
version "2.15.2"
471-
resolved "https://registry.yarnpkg.com/moment/-/moment-2.15.2.tgz#1bfdedf6a6e345f322fe956d5df5bd08a8ce84dc"
472-
473446
474447
version "2.11.2"
475448
resolved "https://registry.yarnpkg.com/moment/-/moment-2.11.2.tgz#87968e5f95ac038c2e42ac959c75819cd3f52901"
@@ -577,10 +550,6 @@ sshpk@^1.7.0:
577550
jsbn "~0.1.0"
578551
tweetnacl "~0.14.0"
579552

580-
581-
version "1.0.1"
582-
resolved "https://registry.yarnpkg.com/starttls/-/starttls-1.0.1.tgz#e6081c25de6b178f5a75f8f271c1487449183b42"
583-
584553
stringstream@~0.0.4:
585554
version "0.0.5"
586555
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"

0 commit comments

Comments
 (0)