@tomei/mailer 1.0.1 → 1.1.0-test.2

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 (53) hide show
  1. package/.gitlab-ci.yml +237 -16
  2. package/.husky/commit-msg +15 -15
  3. package/.husky/pre-commit +0 -0
  4. package/dist/src/interfaces/mail-config.interface.d.ts +1 -0
  5. package/dist/src/mailer/helpers/helpers.spec.js +31 -0
  6. package/dist/src/mailer/helpers/helpers.spec.js.map +1 -0
  7. package/dist/src/mailer/index.d.ts +1 -1
  8. package/dist/src/mailer/index.js.map +1 -1
  9. package/dist/src/mailer/mailer.base.d.ts +3 -0
  10. package/dist/src/mailer/mailer.base.js +3 -0
  11. package/dist/src/mailer/mailer.base.js.map +1 -1
  12. package/dist/src/mailer/smtp-mailer.js +12 -0
  13. package/dist/src/mailer/smtp-mailer.js.map +1 -1
  14. package/dist/tsconfig.tsbuildinfo +1 -1
  15. package/eslint.config.mjs +58 -58
  16. package/jest.config.js +3 -0
  17. package/package.json +47 -47
  18. package/sonar-project.properties +12 -12
  19. package/src/enum/email-status.enum.ts +4 -4
  20. package/src/enum/index.ts +1 -1
  21. package/src/interfaces/EmailLog.ts +91 -91
  22. package/src/interfaces/IEmailRepository.ts +15 -15
  23. package/src/interfaces/log-transaction-options.interface.ts +18 -18
  24. package/src/interfaces/mail-config.interface.ts +9 -8
  25. package/src/interfaces/mail-log.interface.ts +12 -12
  26. package/src/mailer/helpers/helpers.spec.ts +32 -0
  27. package/src/mailer/index.ts +2 -2
  28. package/src/mailer/mailer.base.ts +123 -110
  29. package/src/mailer/smtp-mailer.ts +142 -121
  30. package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.js +0 -47
  31. package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.js.map +0 -1
  32. package/dist/src/core/entity/email-log.entity.d.ts +0 -35
  33. package/dist/src/core/entity/email-log.entity.js +0 -43
  34. package/dist/src/core/entity/email-log.entity.js.map +0 -1
  35. package/dist/src/core/enum/email-status.enum.d.ts +0 -5
  36. package/dist/src/core/enum/email-status.enum.js +0 -10
  37. package/dist/src/core/enum/email-status.enum.js.map +0 -1
  38. package/dist/src/core/index.d.ts +0 -4
  39. package/dist/src/core/index.js +0 -8
  40. package/dist/src/core/index.js.map +0 -1
  41. package/dist/src/core/interface/email-log.interface.d.ts +0 -18
  42. package/dist/src/core/interface/email-log.interface.js +0 -3
  43. package/dist/src/core/interface/email-log.interface.js.map +0 -1
  44. package/dist/src/core/interface/i-email-repository.d.ts +0 -16
  45. package/dist/src/core/interface/i-email-repository.js +0 -3
  46. package/dist/src/core/interface/i-email-repository.js.map +0 -1
  47. package/dist/src/domain/repositories/mail-log.repository.d.ts +0 -4
  48. package/dist/src/domain/repositories/mail-log.repository.js +0 -3
  49. package/dist/src/domain/repositories/mail-log.repository.js.map +0 -1
  50. package/dist/src/infrastructure/repositories/file-system-mail-log.repository.d.ts +0 -5
  51. package/dist/src/infrastructure/repositories/file-system-mail-log.repository.js +0 -26
  52. package/dist/src/infrastructure/repositories/file-system-mail-log.repository.js.map +0 -1
  53. /package/dist/{__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.d.ts → src/mailer/helpers/helpers.spec.d.ts} +0 -0
@@ -1,110 +1,123 @@
1
- import { IMailLog } from 'src/interfaces/mail-log.interface';
2
- import { ILogTransactionOption } from '../interfaces/log-transaction-options.interface';
3
- import { ISendMailConfig } from '../interfaces/mail-config.interface';
4
- import * as fs from 'fs';
5
- import * as path from 'path';
6
- import { EmailStatus } from '../enum/email-status.enum';
7
- import { ComponentConfig } from '@tomei/config';
8
-
9
- export abstract class MailerBase {
10
- abstract sendMail(options: any): Promise<any>;
11
-
12
- async send(options: ISendMailConfig): Promise<any> {
13
- // start timer
14
- const start = Date.now();
15
- let status: EmailStatus;
16
-
17
- // send email
18
- try {
19
- await this.sendMail(options);
20
- status = EmailStatus.Sent;
21
- } catch (error) {
22
- status = EmailStatus.Failed;
23
- } finally {
24
- const duration = Date.now() - start;
25
- const isLogEnabled = ComponentConfig.getComponentConfigValue(
26
- '@tomei/mailer',
27
- 'isLogEnabled',
28
- );
29
- if (isLogEnabled) {
30
- MailerBase.log({
31
- duration,
32
- from: options.from,
33
- to:
34
- typeof options.to === 'string' ? options.to : options.to.join(','),
35
- cc:
36
- typeof options.cc === 'string'
37
- ? options.cc
38
- : options.cc
39
- ? options.cc.join(',')
40
- : '',
41
- subject: options.subject,
42
- rawContent: options.html,
43
- date: new Date(),
44
- status: status,
45
- });
46
- }
47
- }
48
- }
49
-
50
- async logTransaction(logOptions: ILogTransactionOption): Promise<void> {
51
- const startTime = new Date().getTime();
52
- let endTime: number;
53
- const options: any = {
54
- from: logOptions.options.from,
55
- to: logOptions.options.to,
56
- subject: logOptions.options.subject,
57
- html: `<div>${JSON.stringify(logOptions.logData)}</div>`,
58
- cc: '',
59
- };
60
- let result: EmailStatus;
61
-
62
- try {
63
- await this.sendMail(options);
64
- result = EmailStatus.Sent;
65
- } catch (error) {
66
- //Retry once
67
- try {
68
- console.info('Retry to send mail');
69
- await this.sendMail(options);
70
- } catch (retryError) {
71
- result = EmailStatus.Failed;
72
- console.error(retryError);
73
- }
74
- } finally {
75
- endTime = new Date().getTime();
76
- const duration = endTime - startTime;
77
- const mailLogOptions: IMailLog = {
78
- duration,
79
- from: options.from,
80
- to: options.to,
81
- cc: '',
82
- subject: options.subject,
83
- rawContent: options.html,
84
- date: new Date(),
85
- status: result,
86
- };
87
- MailerBase.log(mailLogOptions);
88
- }
89
- }
90
-
91
- static log(mailLogOptions: IMailLog): void {
92
- try {
93
- const logFolderPath = path.join(process.cwd(), 'mail-log');
94
-
95
- if (!fs.existsSync(logFolderPath)) {
96
- fs.mkdirSync(logFolderPath);
97
- }
98
-
99
- const currentDate = new Date();
100
- const formattedDate = currentDate.toISOString().slice(0, 10);
101
- const logFileName = `${formattedDate}.log`;
102
- const logFilePath = path.join(logFolderPath, logFileName);
103
- const stringData = JSON.stringify(mailLogOptions);
104
-
105
- fs.appendFileSync(logFilePath, '\n' + stringData);
106
- } catch (error) {
107
- throw new Error('Error occurred while logging mail');
108
- }
109
- }
110
- }
1
+ import { IMailLog } from 'src/interfaces/mail-log.interface';
2
+ import { ILogTransactionOption } from '../interfaces/log-transaction-options.interface';
3
+ import { ISendMailConfig } from '../interfaces/mail-config.interface';
4
+ import * as fs from 'fs';
5
+ import * as path from 'path';
6
+ import { EmailStatus } from '../enum/email-status.enum';
7
+ import { ComponentConfig } from '@tomei/config';
8
+
9
+ export type MailLogDelegate = (
10
+ options: ISendMailConfig,
11
+ status: 'success' | 'failed',
12
+ duration: number,
13
+ error?: any,
14
+ ) => Promise<void> | void;
15
+
16
+ export abstract class MailerBase {
17
+ public static logDelegate?: MailLogDelegate;
18
+
19
+ public static registerLogDelegate(delegate: MailLogDelegate): void {
20
+ MailerBase.logDelegate = delegate;
21
+ }
22
+
23
+ abstract sendMail(options: any): Promise<any>;
24
+
25
+ async send(options: ISendMailConfig): Promise<any> {
26
+ // start timer
27
+ const start = Date.now();
28
+ let status: EmailStatus;
29
+
30
+ // send email
31
+ try {
32
+ await this.sendMail(options);
33
+ status = EmailStatus.Sent;
34
+ } catch (error) {
35
+ status = EmailStatus.Failed;
36
+ } finally {
37
+ const duration = Date.now() - start;
38
+ const isLogEnabled = ComponentConfig.getComponentConfigValue(
39
+ '@tomei/mailer',
40
+ 'isLogEnabled',
41
+ );
42
+ if (isLogEnabled) {
43
+ MailerBase.log({
44
+ duration,
45
+ from: options.from,
46
+ to:
47
+ typeof options.to === 'string' ? options.to : options.to.join(','),
48
+ cc:
49
+ typeof options.cc === 'string'
50
+ ? options.cc
51
+ : options.cc
52
+ ? options.cc.join(',')
53
+ : '',
54
+ subject: options.subject,
55
+ rawContent: options.html,
56
+ date: new Date(),
57
+ status: status,
58
+ });
59
+ }
60
+ }
61
+ }
62
+
63
+ async logTransaction(logOptions: ILogTransactionOption): Promise<void> {
64
+ const startTime = new Date().getTime();
65
+ let endTime: number;
66
+ const options: any = {
67
+ from: logOptions.options.from,
68
+ to: logOptions.options.to,
69
+ subject: logOptions.options.subject,
70
+ html: `<div>${JSON.stringify(logOptions.logData)}</div>`,
71
+ cc: '',
72
+ };
73
+ let result: EmailStatus;
74
+
75
+ try {
76
+ await this.sendMail(options);
77
+ result = EmailStatus.Sent;
78
+ } catch (error) {
79
+ //Retry once
80
+ try {
81
+ console.info('Retry to send mail');
82
+ await this.sendMail(options);
83
+ } catch (retryError) {
84
+ result = EmailStatus.Failed;
85
+ console.error(retryError);
86
+ }
87
+ } finally {
88
+ endTime = new Date().getTime();
89
+ const duration = endTime - startTime;
90
+ const mailLogOptions: IMailLog = {
91
+ duration,
92
+ from: options.from,
93
+ to: options.to,
94
+ cc: '',
95
+ subject: options.subject,
96
+ rawContent: options.html,
97
+ date: new Date(),
98
+ status: result,
99
+ };
100
+ MailerBase.log(mailLogOptions);
101
+ }
102
+ }
103
+
104
+ static log(mailLogOptions: IMailLog): void {
105
+ try {
106
+ const logFolderPath = path.join(process.cwd(), 'mail-log');
107
+
108
+ if (!fs.existsSync(logFolderPath)) {
109
+ fs.mkdirSync(logFolderPath);
110
+ }
111
+
112
+ const currentDate = new Date();
113
+ const formattedDate = currentDate.toISOString().slice(0, 10);
114
+ const logFileName = `${formattedDate}.log`;
115
+ const logFilePath = path.join(logFolderPath, logFileName);
116
+ const stringData = JSON.stringify(mailLogOptions);
117
+
118
+ fs.appendFileSync(logFilePath, '\n' + stringData);
119
+ } catch (error) {
120
+ throw new Error('Error occurred while logging mail');
121
+ }
122
+ }
123
+ }
@@ -1,121 +1,142 @@
1
- import { ComponentConfig } from '@tomei/config';
2
- import { MailerBase } from './mailer.base';
3
- import * as nodemailer from 'nodemailer';
4
- import { ISendMailConfig } from 'src/interfaces/mail-config.interface';
5
-
6
- interface TransportConfig {
7
- host: string;
8
- port: number;
9
- secure: boolean;
10
- auth: {
11
- user: string;
12
- pass: string;
13
- };
14
- tls?: any;
15
- debug?: boolean;
16
- logger?: boolean;
17
- }
18
-
19
- export class SMTPMailer extends MailerBase {
20
- async sendMail(options: ISendMailConfig): Promise<void> {
21
- try {
22
- const host = ComponentConfig.getComponentConfigValue(
23
- '@tomei/mailer',
24
- 'host',
25
- );
26
- const port = ComponentConfig.getComponentConfigValue(
27
- '@tomei/mailer',
28
- 'port',
29
- );
30
- const secure = ComponentConfig.getComponentConfigValue(
31
- '@tomei/mailer',
32
- 'secure',
33
- );
34
- const user = ComponentConfig.getComponentConfigValue(
35
- '@tomei/mailer',
36
- 'user',
37
- );
38
- const pass = ComponentConfig.getComponentConfigValue(
39
- '@tomei/mailer',
40
- 'pass',
41
- );
42
- const tlsOptions = ComponentConfig.getComponentConfigValue(
43
- '@tomei/mailer',
44
- 'tlsOptions',
45
- );
46
- const isMailerDebugEnabled = ComponentConfig.getComponentConfigValue(
47
- '@tomei/mailer',
48
- 'isMailerDebugEnabled',
49
- );
50
- const isMailerLogEnabled = ComponentConfig.getComponentConfigValue(
51
- '@tomei/mailer',
52
- 'isMailerLogEnabled',
53
- );
54
-
55
- const testReceipientEmail = ComponentConfig.getComponentConfigValue(
56
- '@tomei/mailer',
57
- 'testReceipientEmail',
58
- );
59
-
60
- const environment = ComponentConfig.getComponentConfigValue(
61
- '@tomei/mailer',
62
- 'environment',
63
- );
64
-
65
- if (
66
- !host ||
67
- !port ||
68
- !user ||
69
- !pass ||
70
- !environment ||
71
- !testReceipientEmail
72
- ) {
73
- throw new Error(
74
- 'Host, port, user, pass, environment, or test receipient email is not defined in the configuration.',
75
- );
76
- }
77
-
78
- if (environment !== 'production') {
79
- options.to = testReceipientEmail;
80
- }
81
-
82
- const transportConfig: TransportConfig = {
83
- host,
84
- port,
85
- secure,
86
- auth: {
87
- user,
88
- pass,
89
- },
90
- };
91
-
92
- if (tlsOptions) {
93
- transportConfig.tls = tlsOptions;
94
- }
95
-
96
- if (isMailerDebugEnabled) {
97
- transportConfig.debug = true;
98
- }
99
-
100
- if (isMailerLogEnabled) {
101
- transportConfig.logger = true;
102
- }
103
-
104
- const transporter = nodemailer.createTransport(transportConfig);
105
-
106
- await transporter.sendMail({
107
- from: options.from,
108
- to: options.to,
109
- subject: options.subject,
110
- html: options.html,
111
- cc: options.cc,
112
- attachments: options.attachments,
113
- });
114
- } catch (error) {
115
- console.log(error, '<<<<<<<<<< error caught from @tomei/mailer package');
116
- throw error;
117
- }
118
- }
119
- }
120
-
121
- export { nodemailer };
1
+ import { ComponentConfig } from '@tomei/config';
2
+ import { MailerBase } from './mailer.base';
3
+ import * as nodemailer from 'nodemailer';
4
+ import { ISendMailConfig } from 'src/interfaces/mail-config.interface';
5
+
6
+ interface TransportConfig {
7
+ host: string;
8
+ port: number;
9
+ secure: boolean;
10
+ auth: {
11
+ user: string;
12
+ pass: string;
13
+ };
14
+ tls?: any;
15
+ debug?: boolean;
16
+ logger?: boolean;
17
+ }
18
+
19
+ export class SMTPMailer extends MailerBase {
20
+ async sendMail(options: ISendMailConfig): Promise<void> {
21
+ const startTime = Date.now();
22
+ try {
23
+ const host = ComponentConfig.getComponentConfigValue(
24
+ '@tomei/mailer',
25
+ 'host',
26
+ );
27
+ const port = ComponentConfig.getComponentConfigValue(
28
+ '@tomei/mailer',
29
+ 'port',
30
+ );
31
+ const secure = ComponentConfig.getComponentConfigValue(
32
+ '@tomei/mailer',
33
+ 'secure',
34
+ );
35
+ const user = ComponentConfig.getComponentConfigValue(
36
+ '@tomei/mailer',
37
+ 'user',
38
+ );
39
+ const pass = ComponentConfig.getComponentConfigValue(
40
+ '@tomei/mailer',
41
+ 'pass',
42
+ );
43
+ const tlsOptions = ComponentConfig.getComponentConfigValue(
44
+ '@tomei/mailer',
45
+ 'tlsOptions',
46
+ );
47
+ const isMailerDebugEnabled = ComponentConfig.getComponentConfigValue(
48
+ '@tomei/mailer',
49
+ 'isMailerDebugEnabled',
50
+ );
51
+ const isMailerLogEnabled = ComponentConfig.getComponentConfigValue(
52
+ '@tomei/mailer',
53
+ 'isMailerLogEnabled',
54
+ );
55
+
56
+ const testReceipientEmail = ComponentConfig.getComponentConfigValue(
57
+ '@tomei/mailer',
58
+ 'testReceipientEmail',
59
+ );
60
+
61
+ const environment = ComponentConfig.getComponentConfigValue(
62
+ '@tomei/mailer',
63
+ 'environment',
64
+ );
65
+
66
+ if (
67
+ !host ||
68
+ !port ||
69
+ !user ||
70
+ !pass ||
71
+ !environment ||
72
+ !testReceipientEmail
73
+ ) {
74
+ throw new Error(
75
+ 'Host, port, user, pass, environment, or test receipient email is not defined in the configuration.',
76
+ );
77
+ }
78
+
79
+ if (environment !== 'production') {
80
+ options.to = testReceipientEmail;
81
+ }
82
+
83
+ const transportConfig: TransportConfig = {
84
+ host,
85
+ port,
86
+ secure,
87
+ auth: {
88
+ user,
89
+ pass,
90
+ },
91
+ };
92
+
93
+ if (tlsOptions) {
94
+ transportConfig.tls = tlsOptions;
95
+ }
96
+
97
+ if (isMailerDebugEnabled) {
98
+ transportConfig.debug = true;
99
+ }
100
+
101
+ if (isMailerLogEnabled) {
102
+ transportConfig.logger = true;
103
+ }
104
+
105
+ const transporter = nodemailer.createTransport(transportConfig);
106
+
107
+ await transporter.sendMail({
108
+ from: options.from,
109
+ to: options.to,
110
+ subject: options.subject,
111
+ html: options.html,
112
+ cc: options.cc,
113
+ attachments: options.attachments,
114
+ });
115
+
116
+ if (MailerBase.logDelegate) {
117
+ await MailerBase.logDelegate(
118
+ options,
119
+ 'success',
120
+ Date.now() - startTime,
121
+ );
122
+ }
123
+ } catch (error) {
124
+ console.log(error, '<<<<<<<<<< error caught from @tomei/mailer package');
125
+ if (MailerBase.logDelegate) {
126
+ try {
127
+ await MailerBase.logDelegate(
128
+ options,
129
+ 'failed',
130
+ Date.now() - startTime,
131
+ error,
132
+ );
133
+ } catch (logError) {
134
+ console.error('Failed to log email failure:', logError);
135
+ }
136
+ }
137
+ throw error;
138
+ }
139
+ }
140
+ }
141
+
142
+ export { nodemailer };
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const file_system_mail_log_repository_1 = require("../../../../src/infrastructure/repositories/file-system-mail-log.repository");
4
- const email_status_enum_1 = require("../../../../src/enum/email-status.enum");
5
- const fs = require("fs");
6
- const path = require("path");
7
- describe('FileSystemMailLogRepository', () => {
8
- const repository = new file_system_mail_log_repository_1.FileSystemMailLogRepository();
9
- const from = 'test@test.com';
10
- afterEach(() => {
11
- jest.clearAllMocks();
12
- });
13
- describe('save', () => {
14
- const logData = {
15
- duration: 1000,
16
- from: from,
17
- to: 'to@to.com',
18
- cc: '',
19
- subject: 'test email',
20
- rawContent: 'test',
21
- date: new Date(),
22
- status: email_status_enum_1.EmailStatus.Sent,
23
- };
24
- it('should create new log folder if none exist', () => {
25
- jest.spyOn(fs, 'existsSync').mockReturnValueOnce(false);
26
- jest.spyOn(fs, 'mkdirSync').mockReturnValueOnce(undefined);
27
- jest.spyOn(fs, 'appendFileSync').mockReturnValueOnce(undefined);
28
- repository.save(logData);
29
- expect(fs.existsSync).toHaveBeenCalledTimes(1);
30
- expect(fs.existsSync).toHaveBeenCalledWith(path.join(process.cwd(), 'mail-log'));
31
- expect(fs.mkdirSync).toHaveBeenCalledTimes(1);
32
- expect(fs.mkdirSync).toHaveBeenCalledWith(path.join(process.cwd(), 'mail-log'));
33
- expect(fs.appendFileSync).toHaveBeenCalledTimes(1);
34
- });
35
- it('should create new log file in existing log folder', () => {
36
- const existSyncMock = jest
37
- .spyOn(fs, 'existsSync')
38
- .mockReturnValueOnce(true);
39
- jest.spyOn(fs, 'mkdirSync').mockReturnValueOnce(undefined);
40
- jest.spyOn(fs, 'appendFileSync').mockReturnValueOnce(undefined);
41
- repository.save(logData);
42
- expect(existSyncMock).toHaveBeenCalledTimes(1);
43
- expect(fs.mkdirSync).toHaveBeenCalledTimes(0);
44
- });
45
- });
46
- });
47
- //# sourceMappingURL=file-system-mail-log.repository.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-system-mail-log.repository.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.ts"],"names":[],"mappings":";;AAAA,iIAA0H;AAC1H,8EAAqE;AACrE,yBAAyB;AACzB,6BAA6B;AAE7B,QAAQ,CAAC,6BAA6B,EAAE,GAAG,EAAE;IAC3C,MAAM,UAAU,GAAG,IAAI,6DAA2B,EAAE,CAAC;IACrD,MAAM,IAAI,GAAG,eAAe,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;QACpB,MAAM,OAAO,GAAG;YACd,QAAQ,EAAE,IAAI;YACd,IAAI,EAAE,IAAI;YACV,EAAE,EAAE,WAAW;YACf,EAAE,EAAE,EAAE;YACN,OAAO,EAAE,YAAY;YACrB,UAAU,EAAE,MAAM;YAClB,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,MAAM,EAAE,+BAAW,CAAC,IAAI;SACzB,CAAC;QAEF,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;YACpD,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;YACxD,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YAC3D,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,gBAAgB,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YAEhE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEzB,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAC/C,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,oBAAoB,CACxC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CACrC,CAAC;YACF,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAC9C,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,oBAAoB,CACvC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CACrC,CAAC;YACF,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;YAC3D,MAAM,aAAa,GAAG,IAAI;iBACvB,KAAK,CAAC,EAAE,EAAE,YAAY,CAAC;iBACvB,mBAAmB,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YAC3D,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,gBAAgB,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;YAEhE,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAEzB,MAAM,CAAC,aAAa,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAC/C,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,35 +0,0 @@
1
- import { EmailStatus } from "../enum/email-status.enum";
2
- import { EmailLogInterface } from "../interface/email-log.interface";
3
- export declare class EmailLog implements EmailLogInterface {
4
- id: string;
5
- to: string;
6
- subject: string;
7
- body: string;
8
- private _status;
9
- get status(): EmailStatus;
10
- set status(value: EmailStatus);
11
- bodyHtml: string;
12
- bodyText: string;
13
- payload: string;
14
- error?: string;
15
- sentAt: Date;
16
- createdAt: Date;
17
- updatedAt: Date;
18
- recipient: string;
19
- emailType: string;
20
- constructor(params: {
21
- id: string;
22
- to: string;
23
- subject: string;
24
- body: string;
25
- status?: EmailStatus;
26
- error?: string;
27
- sentAt?: Date;
28
- createdAt?: Date;
29
- updatedAt?: Date;
30
- recipient: string;
31
- emailType: string;
32
- });
33
- markAsSent(): void;
34
- markAsFailed(error: string): void;
35
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmailLog = void 0;
4
- const email_status_enum_1 = require("../enum/email-status.enum");
5
- class EmailLog {
6
- get status() {
7
- return this._status;
8
- }
9
- set status(value) {
10
- this._status = value.toLowerCase();
11
- }
12
- constructor(params) {
13
- var _a, _b;
14
- this.id = params.id;
15
- this.to = params.to;
16
- this.subject = params.subject;
17
- this.body = params.body;
18
- this.status = email_status_enum_1.EmailStatus.PENDING;
19
- this.error = params.error;
20
- this.sentAt = (_a = params.sentAt) !== null && _a !== void 0 ? _a : new Date();
21
- this.createdAt = (_b = params.createdAt) !== null && _b !== void 0 ? _b : new Date();
22
- this.updatedAt = params.updatedAt;
23
- this.recipient = params.recipient;
24
- this.emailType = params.emailType;
25
- }
26
- markAsSent() {
27
- if (this._status !== email_status_enum_1.EmailStatus.PENDING) {
28
- throw new Error(`Invalid transition: Cannot mark as sent from status '${this._status}'`);
29
- }
30
- this._status = email_status_enum_1.EmailStatus.SUCCESS;
31
- this.updatedAt = new Date();
32
- }
33
- markAsFailed(error) {
34
- if (this._status !== email_status_enum_1.EmailStatus.PENDING) {
35
- throw new Error(`Invalid transition: Cannot mark as failed from status '${this._status}'`);
36
- }
37
- this._status = email_status_enum_1.EmailStatus.FAILED;
38
- this.error = error;
39
- this.updatedAt = new Date();
40
- }
41
- }
42
- exports.EmailLog = EmailLog;
43
- //# sourceMappingURL=email-log.entity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"email-log.entity.js","sourceRoot":"","sources":["../../../../src/core/entity/email-log.entity.ts"],"names":[],"mappings":";;;AAAA,iEAAwD;AAGxD,MAAa,QAAQ;IAMjB,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;IACD,IAAI,MAAM,CAAC,KAAkB;QACzB,IAAI,CAAC,OAAO,GAAI,KAAgB,CAAC,WAAW,EAAiB,CAAC;IAClE,CAAC;IAWD,YAAY,MAYX;;QACG,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,MAAM,GAAG,+BAAW,CAAC,OAAO,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAA,MAAM,CAAC,MAAM,mCAAI,IAAI,IAAI,EAAE,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,MAAA,MAAM,CAAC,SAAS,mCAAI,IAAI,IAAI,EAAE,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACtC,CAAC;IAED,UAAU;QACN,IAAI,IAAI,CAAC,OAAO,KAAK,+BAAW,CAAC,OAAO,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACX,wDAAwD,IAAI,CAAC,OAAO,GAAG,CAC1E,CAAC;QACN,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,+BAAW,CAAC,OAAO,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAChC,CAAC;IAED,YAAY,CAAC,KAAa;QACtB,IAAI,IAAI,CAAC,OAAO,KAAK,+BAAW,CAAC,OAAO,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACX,0DAA0D,IAAI,CAAC,OAAO,GAAG,CAC5E,CAAC;QACN,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,+BAAW,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAChC,CAAC;CACJ;AApED,4BAoEC"}
@@ -1,5 +0,0 @@
1
- export declare enum EmailStatus {
2
- SUCCESS = "success",
3
- FAILED = "failed",
4
- PENDING = "pending"
5
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmailStatus = void 0;
4
- var EmailStatus;
5
- (function (EmailStatus) {
6
- EmailStatus["SUCCESS"] = "success";
7
- EmailStatus["FAILED"] = "failed";
8
- EmailStatus["PENDING"] = "pending";
9
- })(EmailStatus || (exports.EmailStatus = EmailStatus = {}));
10
- //# sourceMappingURL=email-status.enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"email-status.enum.js","sourceRoot":"","sources":["../../../../src/core/enum/email-status.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAIX;AAJD,WAAY,WAAW;IACnB,kCAAmB,CAAA;IACnB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;AACvB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB"}