@drax/email-back 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/config/EmailLayoutConfig.js +20 -0
  2. package/dist/config/EmailTransportConfig.js +14 -0
  3. package/dist/factory/EmailLayoutServiceFactory.js +36 -0
  4. package/dist/factory/EmailServiceFactory.js +12 -12
  5. package/dist/factory/EmailTransportServiceFactory.js +46 -0
  6. package/dist/index.js +6 -3
  7. package/dist/services/EmailLayoutService.js +2 -2
  8. package/dist/services/EmailTransportService.js +58 -0
  9. package/package.json +2 -2
  10. package/src/config/EmailLayoutConfig.ts +27 -0
  11. package/src/config/{EmailConfig.ts → EmailTransportConfig.ts} +3 -3
  12. package/src/factory/EmailLayoutServiceFactory.ts +52 -0
  13. package/src/factory/EmailTransportServiceFactory.ts +56 -0
  14. package/src/index.ts +11 -4
  15. package/src/services/EmailLayoutService.ts +2 -2
  16. package/src/services/{EmailService.ts → EmailTransportService.ts} +3 -3
  17. package/test/Email.test.ts +4 -3
  18. package/test/EmailLayout.test.ts +3 -3
  19. package/tsconfig.json +3 -2
  20. package/tsconfig.tsbuildinfo +1 -1
  21. package/types/config/EmailLayoutConfig.d.ts +20 -0
  22. package/types/config/EmailLayoutConfig.d.ts.map +1 -0
  23. package/types/config/EmailTransportConfig.d.ts +14 -0
  24. package/types/config/EmailTransportConfig.d.ts.map +1 -0
  25. package/types/factory/EmailLayoutServiceFactory.d.ts +10 -0
  26. package/types/factory/EmailLayoutServiceFactory.d.ts.map +1 -0
  27. package/types/factory/EmailServiceFactory.d.ts +1 -1
  28. package/types/factory/EmailTransportServiceFactory.d.ts +11 -0
  29. package/types/factory/EmailTransportServiceFactory.d.ts.map +1 -0
  30. package/types/index.d.ts +6 -3
  31. package/types/index.d.ts.map +1 -1
  32. package/types/services/EmailTransportService.d.ts +13 -0
  33. package/types/services/EmailTransportService.d.ts.map +1 -0
  34. package/src/factory/EmailServiceFactory.ts +0 -56
@@ -0,0 +1,20 @@
1
+ var EmailLayoutConfig;
2
+ (function (EmailLayoutConfig) {
3
+ EmailLayoutConfig["bodyStyle"] = "EMAIL_BODYSTYLE";
4
+ EmailLayoutConfig["maxWidth"] = "EMAIL_MAXWIDTH";
5
+ EmailLayoutConfig["headerCentered"] = "EMAIL_HEADER_CENTERED";
6
+ EmailLayoutConfig["headerBgColor"] = "EMAIL_HEADER_BGCOLOR";
7
+ EmailLayoutConfig["headerColor"] = "EMAIL_HEADER_COLOR";
8
+ EmailLayoutConfig["headerImage"] = "EMAIL_HEADER_IMAGE";
9
+ EmailLayoutConfig["headerImageStyle"] = "EMAIL_HEADER_IMAGE_STYLE";
10
+ EmailLayoutConfig["headerTitle"] = "EMAIL_HEADER_TITLE";
11
+ EmailLayoutConfig["headerTitleStyle"] = "EMAIL_HEADER_TITLE_STYLE";
12
+ EmailLayoutConfig["headerLogo"] = "EMAIL_HEADER_LOGO";
13
+ EmailLayoutConfig["headerLogoStyle"] = "EMAIL_HEADER_LOGO_STYLE";
14
+ EmailLayoutConfig["footerBgColor"] = "EMAIL_FOOTER_BGCOLOR";
15
+ EmailLayoutConfig["footerCopyright"] = "EMAIL_FOOTER_COPYRIGHT";
16
+ EmailLayoutConfig["footerContent"] = "EMAIL_FOOTER_CONTENT";
17
+ EmailLayoutConfig["footerUnsubscribe"] = "EMAIL_FOOTER_UNSUBSCRIBE";
18
+ })(EmailLayoutConfig || (EmailLayoutConfig = {}));
19
+ export default EmailLayoutConfig;
20
+ export { EmailLayoutConfig };
@@ -0,0 +1,14 @@
1
+ var EmailTransportConfig;
2
+ (function (EmailTransportConfig) {
3
+ EmailTransportConfig["type"] = "EMAIL_TYPE";
4
+ EmailTransportConfig["service"] = "EMAIL_SERVICE";
5
+ EmailTransportConfig["smtpHost"] = "EMAIL_HOST";
6
+ EmailTransportConfig["smtpPort"] = "EMAIL_PORT";
7
+ EmailTransportConfig["authType"] = "EMAIL_AUTH_TYPE";
8
+ EmailTransportConfig["authUsername"] = "EMAIL_AUTH_USERNAME";
9
+ EmailTransportConfig["authPassword"] = "EMAIL_AUTH_PASSWORD";
10
+ EmailTransportConfig["secure"] = "EMAIL_SECURE";
11
+ EmailTransportConfig["ignoreTLS"] = "EMAIL_IGNORE_TLS";
12
+ })(EmailTransportConfig || (EmailTransportConfig = {}));
13
+ export default EmailTransportConfig;
14
+ export { EmailTransportConfig };
@@ -0,0 +1,36 @@
1
+ import { DraxConfig } from "@drax/common-back";
2
+ import { EmailLayoutService } from '../services/EmailLayoutService.js';
3
+ import EmailLayoutConfig from "../config/EmailLayoutConfig.js";
4
+ class EmailLayoutServiceFactory {
5
+ static get instance() {
6
+ if (!EmailLayoutServiceFactory.service) {
7
+ const options = EmailLayoutServiceFactory.getOptions;
8
+ console.log("IEmailLayout options:", options);
9
+ EmailLayoutServiceFactory.service = new EmailLayoutService(options);
10
+ }
11
+ return EmailLayoutServiceFactory.service;
12
+ }
13
+ static get getOptions() {
14
+ let options;
15
+ options = {
16
+ bodyStyle: DraxConfig.getOrLoad(EmailLayoutConfig.bodyStyle),
17
+ maxWidth: DraxConfig.getOrLoad(EmailLayoutConfig.maxWidth),
18
+ headerCentered: DraxConfig.getOrLoad(EmailLayoutConfig.headerCentered),
19
+ headerBgColor: DraxConfig.getOrLoad(EmailLayoutConfig.headerBgColor),
20
+ headerColor: DraxConfig.getOrLoad(EmailLayoutConfig.headerColor),
21
+ headerImage: DraxConfig.getOrLoad(EmailLayoutConfig.headerImage),
22
+ headerImageStyle: DraxConfig.getOrLoad(EmailLayoutConfig.headerImageStyle),
23
+ headerTitle: DraxConfig.getOrLoad(EmailLayoutConfig.headerTitle),
24
+ headerTitleStyle: DraxConfig.getOrLoad(EmailLayoutConfig.headerTitleStyle),
25
+ headerLogo: DraxConfig.getOrLoad(EmailLayoutConfig.headerLogo),
26
+ headerLogoStyle: DraxConfig.getOrLoad(EmailLayoutConfig.headerLogoStyle),
27
+ footerBgColor: DraxConfig.getOrLoad(EmailLayoutConfig.footerBgColor),
28
+ footerCopyright: DraxConfig.getOrLoad(EmailLayoutConfig.footerCopyright),
29
+ footerContent: DraxConfig.getOrLoad(EmailLayoutConfig.footerContent),
30
+ footerUnsubscribe: DraxConfig.getOrLoad(EmailLayoutConfig.footerUnsubscribe),
31
+ };
32
+ return Object.fromEntries(Object.entries(options).filter(([_, value]) => value !== undefined && value !== null && value !== ''));
33
+ }
34
+ }
35
+ export default EmailLayoutServiceFactory;
36
+ export { EmailLayoutServiceFactory };
@@ -1,6 +1,6 @@
1
1
  import { DraxConfig } from "@drax/common-back";
2
2
  import { EmailService } from '../services/EmailService.js';
3
- import EmailConfig from "../config/EmailConfig";
3
+ import EmailTransportConfig from "../config/EmailTransportConfig";
4
4
  class EmailServiceFactory {
5
5
  static get instance() {
6
6
  if (!EmailServiceFactory.service) {
@@ -11,33 +11,33 @@ class EmailServiceFactory {
11
11
  return EmailServiceFactory.service;
12
12
  }
13
13
  static get getType() {
14
- return DraxConfig.getOrLoad(EmailConfig.type);
14
+ return DraxConfig.getOrLoad(EmailTransportConfig.type);
15
15
  }
16
16
  static get getOptions() {
17
17
  let options;
18
- switch (DraxConfig.getOrLoad(EmailConfig.type)) {
18
+ switch (DraxConfig.getOrLoad(EmailTransportConfig.type)) {
19
19
  case 'smtp':
20
20
  options = {
21
- host: DraxConfig.getOrLoad(EmailConfig.smtpHost),
22
- port: DraxConfig.getOrLoad(EmailConfig.smtpPort),
23
- secure: DraxConfig.getOrLoad(EmailConfig.secure),
24
- ignoreTLS: DraxConfig.getOrLoad(EmailConfig.ignoreTLS),
21
+ host: DraxConfig.getOrLoad(EmailTransportConfig.smtpHost),
22
+ port: DraxConfig.getOrLoad(EmailTransportConfig.smtpPort),
23
+ secure: DraxConfig.getOrLoad(EmailTransportConfig.secure),
24
+ ignoreTLS: DraxConfig.getOrLoad(EmailTransportConfig.ignoreTLS),
25
25
  auth: {
26
- user: DraxConfig.getOrLoad(EmailConfig.authUsername),
27
- pass: DraxConfig.getOrLoad(EmailConfig.authPassword),
26
+ user: DraxConfig.getOrLoad(EmailTransportConfig.authUsername),
27
+ pass: DraxConfig.getOrLoad(EmailTransportConfig.authPassword),
28
28
  },
29
29
  };
30
30
  break;
31
31
  case 'gmail':
32
32
  options = {
33
33
  auth: {
34
- user: DraxConfig.getOrLoad(EmailConfig.authUsername),
35
- pass: DraxConfig.getOrLoad(EmailConfig.authPassword),
34
+ user: DraxConfig.getOrLoad(EmailTransportConfig.authUsername),
35
+ pass: DraxConfig.getOrLoad(EmailTransportConfig.authPassword),
36
36
  }
37
37
  };
38
38
  break;
39
39
  default:
40
- throw new Error(`Unsupported email service type: ${DraxConfig.getOrLoad(EmailConfig.type)}`);
40
+ throw new Error(`Unsupported email service type: ${DraxConfig.getOrLoad(EmailTransportConfig.type)}`);
41
41
  }
42
42
  return options;
43
43
  }
@@ -0,0 +1,46 @@
1
+ import { DraxConfig } from "@drax/common-back";
2
+ import { EmailTransportService } from '../services/EmailTransportService.js';
3
+ import EmailTransportConfig from "../config/EmailTransportConfig.js";
4
+ class EmailTransportServiceFactory {
5
+ static get instance() {
6
+ if (!EmailTransportServiceFactory.service) {
7
+ const type = EmailTransportServiceFactory.getType;
8
+ const options = EmailTransportServiceFactory.getOptions;
9
+ EmailTransportServiceFactory.service = new EmailTransportService(type, options);
10
+ }
11
+ return EmailTransportServiceFactory.service;
12
+ }
13
+ static get getType() {
14
+ return DraxConfig.getOrLoad(EmailTransportConfig.type);
15
+ }
16
+ static get getOptions() {
17
+ let options;
18
+ switch (DraxConfig.getOrLoad(EmailTransportConfig.type)) {
19
+ case 'smtp':
20
+ options = {
21
+ host: DraxConfig.getOrLoad(EmailTransportConfig.smtpHost),
22
+ port: DraxConfig.getOrLoad(EmailTransportConfig.smtpPort),
23
+ secure: DraxConfig.getOrLoad(EmailTransportConfig.secure),
24
+ ignoreTLS: DraxConfig.getOrLoad(EmailTransportConfig.ignoreTLS),
25
+ auth: {
26
+ user: DraxConfig.getOrLoad(EmailTransportConfig.authUsername),
27
+ pass: DraxConfig.getOrLoad(EmailTransportConfig.authPassword),
28
+ },
29
+ };
30
+ break;
31
+ case 'gmail':
32
+ options = {
33
+ auth: {
34
+ user: DraxConfig.getOrLoad(EmailTransportConfig.authUsername),
35
+ pass: DraxConfig.getOrLoad(EmailTransportConfig.authPassword),
36
+ }
37
+ };
38
+ break;
39
+ default:
40
+ throw new Error(`Unsupported email service type: ${DraxConfig.getOrLoad(EmailTransportConfig.type)}`);
41
+ }
42
+ return options;
43
+ }
44
+ }
45
+ export default EmailTransportServiceFactory;
46
+ export { EmailTransportServiceFactory };
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
- import EmailConfig from "./config/EmailConfig.js";
2
- import EmailService from "./services/EmailService.js";
1
+ import EmailTransportConfig from "./config/EmailTransportConfig.js";
2
+ import EmailLayoutConfig from "./config/EmailLayoutConfig.js";
3
+ import EmailTransportService from "./services/EmailTransportService.js";
3
4
  import EmailLayoutService from "./services/EmailLayoutService.js";
4
- export { EmailConfig, EmailService, EmailLayoutService, };
5
+ import EmailTransportServiceFactory from "./factory/EmailTransportServiceFactory.js";
6
+ import EmailLayoutServiceFactory from "./factory/EmailLayoutServiceFactory.js";
7
+ export { EmailTransportConfig, EmailLayoutConfig, EmailTransportServiceFactory, EmailTransportService, EmailLayoutServiceFactory, EmailLayoutService, };
@@ -14,7 +14,7 @@ class EmailLayoutService {
14
14
  headerLogoStyle: "max-height: 50px; display: block; margin: 10px auto;",
15
15
  footerBgColor: "#f4f4f4",
16
16
  footerCopyright: "Your Company. All rights reserved.",
17
- footerContent: "Default footer content",
17
+ footerContent: "",
18
18
  footerUnsubscribe: "",
19
19
  };
20
20
  this.options = { ...defaultOptions, ...options };
@@ -67,7 +67,7 @@ class EmailLayoutService {
67
67
  let footer = `<tr style=" ${this.options.footerBgColor ? 'background-color:' + this.options.footerBgColor : ''}">
68
68
  <td style="text-align: center; padding: 20px; font-size: 12px; color: #888888;">`;
69
69
  if (this.options.footerCopyright) {
70
- footer += ` <p style="margin: 0;">&copy; ${new Date().getFullYear()} ${this.options.footerCopyright}.</p>`;
70
+ footer += ` <p style="margin: 0;">&copy; ${new Date().getFullYear()} ${this.options.footerCopyright}</p>`;
71
71
  }
72
72
  if (this.options.footerContent) {
73
73
  footer += `${this.options.footerContent}`;
@@ -0,0 +1,58 @@
1
+ import nodemailer from 'nodemailer';
2
+ class EmailTransportService {
3
+ constructor(type, config) {
4
+ this.transporterConfig = config;
5
+ switch (type) {
6
+ case 'smtp':
7
+ this.prepareTransportSmtp(config);
8
+ break;
9
+ case 'gmail':
10
+ this.prepareTransportGmail(config);
11
+ break;
12
+ default:
13
+ throw new Error(`Unsupported email service type: ${type}`);
14
+ }
15
+ }
16
+ prepareTransportGmail(config) {
17
+ this.transporter = nodemailer.createTransport({
18
+ service: 'gmail',
19
+ auth: {
20
+ user: config.auth.user,
21
+ pass: config.auth.pass
22
+ }
23
+ });
24
+ }
25
+ prepareTransportSmtp(config) {
26
+ this.transporter = nodemailer.createTransport({
27
+ host: config.host,
28
+ port: config.port,
29
+ secure: config.secure,
30
+ ignoreTLS: config.ignoreTLS,
31
+ auth: (config.auth.user && config.auth.pass) ? {
32
+ type: config.auth.type ? config.auth.type : 'login',
33
+ user: config.auth.user,
34
+ pass: config.auth.pass
35
+ } : null
36
+ });
37
+ }
38
+ sendEmail(options) {
39
+ if (!this.transporter) {
40
+ throw new Error('Transporter is not initialized');
41
+ }
42
+ if (!options.to) {
43
+ throw new Error('No recipient provided');
44
+ }
45
+ if (!options.html && !options.text) {
46
+ throw new Error('Either HTML or TEXT content is required');
47
+ }
48
+ if (!options.subject) {
49
+ throw new Error('No subject provided');
50
+ }
51
+ if (!options.from) {
52
+ options.from = this.transporterConfig.auth.user;
53
+ }
54
+ return this.transporter.sendMail(options);
55
+ }
56
+ }
57
+ export default EmailTransportService;
58
+ export { EmailTransportService };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.9.0",
6
+ "version": "0.10.0",
7
7
  "description": "Email utils across modules",
8
8
  "main": "dist/index.js",
9
9
  "types": "types/index.d.ts",
@@ -38,5 +38,5 @@
38
38
  "typescript": "^5.6.2",
39
39
  "vitest": "^2.1.8"
40
40
  },
41
- "gitHead": "aae0068b0343cbb23e85c2a9ea454e183739a8a7"
41
+ "gitHead": "bc1b8a35563ccffdf7719cfcc588f12df0e012bb"
42
42
  }
@@ -0,0 +1,27 @@
1
+ enum EmailLayoutConfig {
2
+ bodyStyle = "EMAIL_BODYSTYLE",
3
+ maxWidth = "EMAIL_MAXWIDTH",
4
+
5
+ headerCentered = "EMAIL_HEADER_CENTERED",
6
+ headerBgColor = "EMAIL_HEADER_BGCOLOR",
7
+ headerColor = "EMAIL_HEADER_COLOR",
8
+
9
+ headerImage = "EMAIL_HEADER_IMAGE",
10
+ headerImageStyle = "EMAIL_HEADER_IMAGE_STYLE",
11
+
12
+ headerTitle = "EMAIL_HEADER_TITLE",
13
+ headerTitleStyle = "EMAIL_HEADER_TITLE_STYLE",
14
+
15
+ headerLogo = "EMAIL_HEADER_LOGO",
16
+ headerLogoStyle = "EMAIL_HEADER_LOGO_STYLE",
17
+
18
+ footerBgColor = "EMAIL_FOOTER_BGCOLOR",
19
+ footerCopyright = "EMAIL_FOOTER_COPYRIGHT",
20
+ footerContent = "EMAIL_FOOTER_CONTENT",
21
+ footerUnsubscribe = "EMAIL_FOOTER_UNSUBSCRIBE",
22
+
23
+
24
+ }
25
+
26
+ export default EmailLayoutConfig;
27
+ export {EmailLayoutConfig};
@@ -1,4 +1,4 @@
1
- enum EmailConfig {
1
+ enum EmailTransportConfig {
2
2
  type = "EMAIL_TYPE",
3
3
  service = "EMAIL_SERVICE",
4
4
  smtpHost = "EMAIL_HOST",
@@ -10,5 +10,5 @@ enum EmailConfig {
10
10
  ignoreTLS = "EMAIL_IGNORE_TLS",
11
11
  }
12
12
 
13
- export default EmailConfig;
14
- export {EmailConfig};
13
+ export default EmailTransportConfig;
14
+ export {EmailTransportConfig};
@@ -0,0 +1,52 @@
1
+ import {DraxConfig} from "@drax/common-back";
2
+ import {EmailLayoutService} from '../services/EmailLayoutService.js'
3
+ import EmailLayoutConfig from "../config/EmailLayoutConfig.js";
4
+ import type {IEmailLayout} from "../interfaces/IEmailLayout";
5
+
6
+ class EmailLayoutServiceFactory {
7
+ private static service: EmailLayoutService;
8
+
9
+ public static get instance(): EmailLayoutService {
10
+ if (!EmailLayoutServiceFactory.service) {
11
+ const options: IEmailLayout = EmailLayoutServiceFactory.getOptions;
12
+ console.log("IEmailLayout options:", options);
13
+ EmailLayoutServiceFactory.service = new EmailLayoutService(options);
14
+ }
15
+ return EmailLayoutServiceFactory.service;
16
+ }
17
+
18
+ public static get getOptions(): IEmailLayout {
19
+ let options: IEmailLayout;
20
+
21
+ options = {
22
+ bodyStyle: DraxConfig.getOrLoad(EmailLayoutConfig.bodyStyle),
23
+ maxWidth: DraxConfig.getOrLoad(EmailLayoutConfig.maxWidth),
24
+ headerCentered: DraxConfig.getOrLoad(EmailLayoutConfig.headerCentered),
25
+ headerBgColor: DraxConfig.getOrLoad(EmailLayoutConfig.headerBgColor),
26
+ headerColor: DraxConfig.getOrLoad(EmailLayoutConfig.headerColor),
27
+ headerImage: DraxConfig.getOrLoad(EmailLayoutConfig.headerImage),
28
+ headerImageStyle: DraxConfig.getOrLoad(EmailLayoutConfig.headerImageStyle),
29
+ headerTitle: DraxConfig.getOrLoad(EmailLayoutConfig.headerTitle),
30
+ headerTitleStyle: DraxConfig.getOrLoad(EmailLayoutConfig.headerTitleStyle),
31
+ headerLogo: DraxConfig.getOrLoad(EmailLayoutConfig.headerLogo),
32
+ headerLogoStyle: DraxConfig.getOrLoad(EmailLayoutConfig.headerLogoStyle),
33
+ footerBgColor: DraxConfig.getOrLoad(EmailLayoutConfig.footerBgColor),
34
+ footerCopyright: DraxConfig.getOrLoad(EmailLayoutConfig.footerCopyright),
35
+ footerContent: DraxConfig.getOrLoad(EmailLayoutConfig.footerContent),
36
+ footerUnsubscribe: DraxConfig.getOrLoad(EmailLayoutConfig.footerUnsubscribe),
37
+ }
38
+
39
+
40
+ return Object.fromEntries(
41
+ Object.entries(options).filter(([_, value]) =>
42
+ value !== undefined && value !== null && value !== ''
43
+ )
44
+ );
45
+ }
46
+ }
47
+
48
+ export default EmailLayoutServiceFactory
49
+ export {
50
+ EmailLayoutServiceFactory
51
+ }
52
+
@@ -0,0 +1,56 @@
1
+ import {DraxConfig} from "@drax/common-back";
2
+ import {EmailTransportService} from '../services/EmailTransportService.js'
3
+ import EmailTransportConfig from "../config/EmailTransportConfig.js";
4
+ import type {TransportGmailConfig, TransportSmtpConfig} from "../interfaces/ITransportConfig";
5
+
6
+ class EmailTransportServiceFactory {
7
+ private static service: EmailTransportService;
8
+
9
+ public static get instance(): EmailTransportService {
10
+ if (!EmailTransportServiceFactory.service) {
11
+ const type = EmailTransportServiceFactory.getType;
12
+ const options = EmailTransportServiceFactory.getOptions;
13
+ EmailTransportServiceFactory.service = new EmailTransportService(type, options);
14
+ }
15
+ return EmailTransportServiceFactory.service;
16
+ }
17
+
18
+ public static get getType() {
19
+ return DraxConfig.getOrLoad(EmailTransportConfig.type)
20
+ }
21
+
22
+ public static get getOptions() {
23
+ let options: TransportSmtpConfig | TransportGmailConfig;
24
+ switch(DraxConfig.getOrLoad(EmailTransportConfig.type)){
25
+ case 'smtp':
26
+ options = {
27
+ host: DraxConfig.getOrLoad(EmailTransportConfig.smtpHost),
28
+ port: DraxConfig.getOrLoad(EmailTransportConfig.smtpPort),
29
+ secure: DraxConfig.getOrLoad(EmailTransportConfig.secure),
30
+ ignoreTLS: DraxConfig.getOrLoad(EmailTransportConfig.ignoreTLS),
31
+ auth: {
32
+ user: DraxConfig.getOrLoad(EmailTransportConfig.authUsername),
33
+ pass: DraxConfig.getOrLoad(EmailTransportConfig.authPassword),
34
+ },
35
+ }
36
+ break;
37
+ case 'gmail':
38
+ options = {
39
+ auth: {
40
+ user: DraxConfig.getOrLoad(EmailTransportConfig.authUsername),
41
+ pass: DraxConfig.getOrLoad(EmailTransportConfig.authPassword),
42
+ }
43
+ }
44
+ break;
45
+ default:
46
+ throw new Error(`Unsupported email service type: ${DraxConfig.getOrLoad(EmailTransportConfig.type)}`)
47
+ }
48
+ return options;
49
+ }
50
+ }
51
+
52
+ export default EmailTransportServiceFactory
53
+ export {
54
+ EmailTransportServiceFactory
55
+ }
56
+
package/src/index.ts CHANGED
@@ -1,6 +1,10 @@
1
- import EmailConfig from "./config/EmailConfig.js";
2
- import EmailService from "./services/EmailService.js";
1
+ import EmailTransportConfig from "./config/EmailTransportConfig.js";
2
+ import EmailLayoutConfig from "./config/EmailLayoutConfig.js";
3
+ import EmailTransportService from "./services/EmailTransportService.js";
3
4
  import EmailLayoutService from "./services/EmailLayoutService.js";
5
+ import EmailTransportServiceFactory from "./factory/EmailTransportServiceFactory.js";
6
+ import EmailLayoutServiceFactory from "./factory/EmailLayoutServiceFactory.js";
7
+
4
8
  import type {IEmailLayout} from "./interfaces/IEmailLayout"
5
9
  import type {TransportGmailConfig, TransportSmtpConfig} from "./interfaces/ITransportConfig"
6
10
 
@@ -12,7 +16,10 @@ export type {
12
16
 
13
17
 
14
18
  export {
15
- EmailConfig,
16
- EmailService,
19
+ EmailTransportConfig,
20
+ EmailLayoutConfig,
21
+ EmailTransportServiceFactory,
22
+ EmailTransportService,
23
+ EmailLayoutServiceFactory,
17
24
  EmailLayoutService,
18
25
  }
@@ -20,7 +20,7 @@ class EmailLayoutService {
20
20
  headerLogoStyle: "max-height: 50px; display: block; margin: 10px auto;",
21
21
  footerBgColor: "#f4f4f4",
22
22
  footerCopyright: "Your Company. All rights reserved.",
23
- footerContent: "Default footer content",
23
+ footerContent: "",
24
24
  footerUnsubscribe: "",
25
25
  };
26
26
  this.options = { ...defaultOptions, ...options };
@@ -75,7 +75,7 @@ class EmailLayoutService {
75
75
  <td style="text-align: center; padding: 20px; font-size: 12px; color: #888888;">`
76
76
 
77
77
  if (this.options.footerCopyright) {
78
- footer += ` <p style="margin: 0;">&copy; ${new Date().getFullYear()} ${this.options.footerCopyright}.</p>`
78
+ footer += ` <p style="margin: 0;">&copy; ${new Date().getFullYear()} ${this.options.footerCopyright}</p>`
79
79
  }
80
80
 
81
81
  if (this.options.footerContent) {
@@ -4,7 +4,7 @@ import type {Transporter, SendMailOptions} from "nodemailer";
4
4
  import type {TransportGmailConfig, TransportSmtpConfig} from "../interfaces/ITransportConfig";
5
5
 
6
6
 
7
- class EmailService {
7
+ class EmailTransportService {
8
8
 
9
9
  transporter: Transporter;
10
10
  transporterConfig : TransportGmailConfig | TransportSmtpConfig;
@@ -77,5 +77,5 @@ class EmailService {
77
77
 
78
78
  }
79
79
 
80
- export default EmailService
81
- export {EmailService}
80
+ export default EmailTransportService
81
+ export {EmailTransportService}
@@ -2,7 +2,7 @@ import {describe, test} from "vitest";
2
2
  import {EmailLayoutService} from '../src/services/EmailLayoutService.js'
3
3
  import {fileURLToPath} from "url";
4
4
  import path from "path";
5
- import {EmailServiceFactory} from "../src/factory/EmailServiceFactory.js";
5
+ import {EmailTransportServiceFactory} from "../src/factory/EmailTransportServiceFactory";
6
6
 
7
7
 
8
8
  let body = `
@@ -12,6 +12,7 @@ let body = `
12
12
  `
13
13
 
14
14
  //I Need the absolute path of template.pug file in the same directory as this file with nodejs 20 and type module
15
+ //@ts-ignore
15
16
  const __filename = fileURLToPath(import.meta.url);
16
17
  const __dirname = path.dirname(__filename);
17
18
  const templatePath = path.join(__dirname, 'template.pug');
@@ -39,7 +40,7 @@ describe("Email Service", function () {
39
40
  text: ''
40
41
  }
41
42
 
42
- let emailService = EmailServiceFactory.instance
43
+ let emailService = EmailTransportServiceFactory.instance
43
44
 
44
45
  const r = await emailService.sendEmail({
45
46
  from: 'ci.sys.virtual@gmail.com',
@@ -66,7 +67,7 @@ describe("Email Service", function () {
66
67
  })
67
68
 
68
69
 
69
- let emailService = EmailServiceFactory.instance
70
+ let emailService = EmailTransportServiceFactory.instance
70
71
 
71
72
  const r = await emailService.sendEmail({
72
73
  from: 'ci.sys.virtual@gmail.com',
@@ -1,6 +1,6 @@
1
1
  import {describe, test} from "vitest";
2
2
  import {EmailLayoutService} from '../src/services/EmailLayoutService.js'
3
- import {EmailService} from '../src/services/EmailService.js'
3
+ import {EmailTransportService} from '../src/services/EmailTransportService'
4
4
  import previewEmail from 'preview-email';
5
5
  import {fileURLToPath} from "url";
6
6
  import path from "path";
@@ -12,7 +12,7 @@ let body = `
12
12
  <p style="font-size: 16px; line-height: 1.6; color: #555555; margin: 0;">Si tienes alguna duda, no dudes en contactarnos. Estamos aquí para ayudarte.</p>
13
13
  `
14
14
 
15
- //I Need the absolute path of template.pug file in the same directory as this file with nodejs 20 and type module
15
+ //@ts-ignore
16
16
  const __filename = fileURLToPath(import.meta.url);
17
17
  const __dirname = path.dirname(__filename);
18
18
  const templatePath = path.join(__dirname, 'template.pug');
@@ -171,7 +171,7 @@ describe("Email Layout", function () {
171
171
  })
172
172
 
173
173
 
174
- let emailService = new EmailService('gmail', {
174
+ let emailService = new EmailTransportService('gmail', {
175
175
  auth: {
176
176
  user: process.env.EMAIL_AUTH_USERNAME,
177
177
  pass: process.env.EMAIL_AUTH_PASSWORD
package/tsconfig.json CHANGED
@@ -3,9 +3,10 @@
3
3
  "compilerOptions": {
4
4
  "rootDir": "src",
5
5
  "outDir": "dist",
6
- "declarationDir": "./types",
6
+ "declarationDir": "types",
7
+ "module": "ESNext"
7
8
  },
8
- "exclude": ["test", "types","dist"],
9
+ "exclude": ["test", "types","dist","node_modules"],
9
10
  "ts-node": {
10
11
  "esm": true
11
12
  },