Skip to content

Commit 06638bf

Browse files
committed
remove emailjs dependency
1 parent 3e51440 commit 06638bf

File tree

6 files changed

+81
-107
lines changed

6 files changed

+81
-107
lines changed

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: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import {
1717
generateAccessToken,
1818
generateRefreshToken,
1919
} from './tokens';
20-
import Email, {
20+
import {
2121
emailTemplates,
22-
EmailConnector,
2322
EmailTemplateType,
23+
sendMail,
2424
} from './email';
2525
import {
2626
AccountsServerOptions,
@@ -48,6 +48,7 @@ const defaultOptions = {
4848
},
4949
emailTemplates,
5050
userObjectSanitizer: (user: UserObjectType) => user,
51+
sendMail,
5152
};
5253

5354
export type RemoveListnerHandle = () => EventEmitter;
@@ -69,7 +70,6 @@ export const ServerHooks = {
6970

7071
export class AccountsServer {
7172
public options: AccountsServerOptions;
72-
public email: EmailConnector;
7373
private services: { [key: string]: AuthService };
7474
private db: DBInterface;
7575
private hooks: EventEmitter;
@@ -91,11 +91,6 @@ export class AccountsServer {
9191
this.services[service].server = this;
9292
}
9393

94-
// Initialize emails
95-
this.email = this.options.sendMail
96-
? { sendMail: this.options.sendMail }
97-
: new Email(this.options.email);
98-
9994
// Initialize hooks
10095
this.hooks = new EventEmitter();
10196
}

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: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
# yarn lockfile v1
33

44

5-
"@accounts/common@^0.1.0":
6-
version "0.1.0-alpha.b5d6f4ab"
7-
resolved "https://registry.yarnpkg.com/@accounts/common/-/common-0.1.0-alpha.b5d6f4ab.tgz#ed1ddb111a4a2b022e49933755b85e945f0097ed"
8-
dependencies:
9-
lodash "^4.16.4"
10-
115
"@types/jsonwebtoken@^7.2.3":
126
version "7.2.3"
137
resolved "https://registry.yarnpkg.com/@types/jsonwebtoken/-/jsonwebtoken-7.2.3.tgz#483c8f39945e1e6d308dcc51fd4aeca5208d4dca"
@@ -22,14 +16,6 @@
2216
version "8.0.47"
2317
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.47.tgz#968e596f91acd59069054558a00708c445ca30c2"
2418

25-
addressparser@^0.3.2:
26-
version "0.3.2"
27-
resolved "https://registry.yarnpkg.com/addressparser/-/addressparser-0.3.2.tgz#59873f35e8fcf6c7361c10239261d76e15348bb2"
28-
29-
addressparser@~0.2.0:
30-
version "0.2.1"
31-
resolved "https://registry.yarnpkg.com/addressparser/-/addressparser-0.2.1.tgz#d11a5b2eeda04cfefebdf3196c10ae13db6cd607"
32-
3319
ansi-regex@^2.0.0:
3420
version "2.1.1"
3521
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"
@@ -83,6 +69,10 @@ babel-runtime@^6.26.0:
8369
core-js "^2.4.0"
8470
regenerator-runtime "^0.11.0"
8571

72+
balanced-match@^1.0.0:
73+
version "1.0.0"
74+
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
75+
8676
[email protected], base64url@^2.0.0:
8777
version "2.0.0"
8878
resolved "https://registry.yarnpkg.com/base64url/-/base64url-2.0.0.tgz#eac16e03ea1438eff9423d69baa36262ed1f70bb"
@@ -103,14 +93,17 @@ [email protected]:
10393
dependencies:
10494
hoek "2.x.x"
10595

96+
brace-expansion@^1.1.7:
97+
version "1.1.11"
98+
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
99+
dependencies:
100+
balanced-match "^1.0.0"
101+
concat-map "0.0.1"
102+
106103
107104
version "1.0.1"
108105
resolved "https://registry.yarnpkg.com/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz#f8e71132f7ffe6e01a5c9697a4c6f3e48d5cc819"
109106

110-
111-
version "1.1.0"
112-
resolved "https://registry.yarnpkg.com/bufferjs/-/bufferjs-1.1.0.tgz#095ffa39c5e6b40a2178a1169c9effc584a73201"
113-
114107
caseless@~0.11.0:
115108
version "0.11.0"
116109
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.11.0.tgz#715b96ea9841593cc33067923f5ec60ebda4f7d7"
@@ -135,6 +128,10 @@ commander@^2.9.0:
135128
version "2.11.0"
136129
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
137130

131+
132+
version "0.0.1"
133+
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
134+
138135
core-js@^2.4.0:
139136
version "2.4.1"
140137
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.4.1.tgz#4de911e667b0eae9124e34254b53aea6fc618d3e"
@@ -190,23 +187,6 @@ [email protected]:
190187
base64url "^2.0.0"
191188
safe-buffer "^5.0.1"
192189

193-
emailjs@^1.0.8:
194-
version "1.0.12"
195-
resolved "https://registry.yarnpkg.com/emailjs/-/emailjs-1.0.12.tgz#bd6559c51c4963125218626da098be722f7a1c72"
196-
dependencies:
197-
addressparser "^0.3.2"
198-
mimelib "0.2.14"
199-
moment "2.15.2"
200-
starttls "1.0.1"
201-
optionalDependencies:
202-
bufferjs "1.1.0"
203-
204-
encoding@~0.1:
205-
version "0.1.12"
206-
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
207-
dependencies:
208-
iconv-lite "~0.4.13"
209-
210190
escape-string-regexp@^1.0.2:
211191
version "1.0.5"
212192
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
@@ -235,6 +215,10 @@ form-data@~2.1.1:
235215
combined-stream "^1.0.5"
236216
mime-types "^2.1.12"
237217

218+
fs.realpath@^1.0.0:
219+
version "1.0.0"
220+
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
221+
238222
generate-function@^2.0.0:
239223
version "2.0.0"
240224
resolved "https://registry.yarnpkg.com/generate-function/-/generate-function-2.0.0.tgz#6858fe7c0969b7d4e9093337647ac79f60dfbe74"
@@ -251,6 +235,17 @@ getpass@^0.1.1:
251235
dependencies:
252236
assert-plus "^1.0.0"
253237

238+
glob@^7.0.5:
239+
version "7.1.2"
240+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
241+
dependencies:
242+
fs.realpath "^1.0.0"
243+
inflight "^1.0.4"
244+
inherits "2"
245+
minimatch "^3.0.4"
246+
once "^1.3.0"
247+
path-is-absolute "^1.0.0"
248+
254249
har-validator@~2.0.6:
255250
version "2.0.6"
256251
resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-2.0.6.tgz#cdcbc08188265ad119b6a5a7c8ab70eecfb5d27d"
@@ -287,9 +282,16 @@ http-signature@~1.1.0:
287282
jsprim "^1.2.2"
288283
sshpk "^1.7.0"
289284

290-
iconv-lite@~0.4.13:
291-
version "0.4.13"
292-
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"
293295

294296
is-my-json-valid@^2.12.4:
295297
version "2.16.1"
@@ -414,21 +416,16 @@ mime-types@^2.1.12, mime-types@~2.1.7:
414416
dependencies:
415417
mime-db "~1.30.0"
416418

417-
418-
version "0.2.14"
419-
resolved "https://registry.yarnpkg.com/mimelib/-/mimelib-0.2.14.tgz#2a1aa724bd190b85bd526e6317ab6106edfd6831"
419+
minimatch@^3.0.4:
420+
version "3.0.4"
421+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
420422
dependencies:
421-
addressparser "~0.2.0"
422-
encoding "~0.1"
423+
brace-expansion "^1.1.7"
423424

424425
425426
version "1.2.0"
426427
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
427428

428-
429-
version "2.15.2"
430-
resolved "https://registry.yarnpkg.com/moment/-/moment-2.15.2.tgz#1bfdedf6a6e345f322fe956d5df5bd08a8ce84dc"
431-
432429
433430
version "2.11.2"
434431
resolved "https://registry.yarnpkg.com/moment/-/moment-2.11.2.tgz#87968e5f95ac038c2e42ac959c75819cd3f52901"
@@ -441,6 +438,16 @@ oauth-sign@~0.8.1:
441438
version "0.8.2"
442439
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
443440

441+
once@^1.3.0:
442+
version "1.4.0"
443+
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
444+
dependencies:
445+
wrappy "1"
446+
447+
path-is-absolute@^1.0.0:
448+
version "1.0.1"
449+
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
450+
444451
pinkie-promise@^2.0.0:
445452
version "2.0.1"
446453
resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa"
@@ -492,6 +499,12 @@ [email protected]:
492499
tunnel-agent "~0.4.1"
493500
uuid "^3.0.0"
494501

502+
rimraf@^2.6.2:
503+
version "2.6.2"
504+
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"
505+
dependencies:
506+
glob "^7.0.5"
507+
495508
safe-buffer@^5.0.1:
496509
version "5.0.1"
497510
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7"
@@ -520,10 +533,6 @@ sshpk@^1.7.0:
520533
jsbn "~0.1.0"
521534
tweetnacl "~0.14.0"
522535

523-
524-
version "1.0.1"
525-
resolved "https://registry.yarnpkg.com/starttls/-/starttls-1.0.1.tgz#e6081c25de6b178f5a75f8f271c1487449183b42"
526-
527536
stringstream@~0.0.4:
528537
version "0.0.5"
529538
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"
@@ -570,6 +579,10 @@ [email protected]:
570579
core-util-is "1.0.2"
571580
extsprintf "^1.2.0"
572581

582+
wrappy@1:
583+
version "1.0.2"
584+
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
585+
573586
xtend@^4.0.0, xtend@^4.0.1:
574587
version "4.0.1"
575588
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"

0 commit comments

Comments
 (0)