@tomei/mailer 0.7.1-dev.2 → 0.10.0-dev.1
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.
- package/.husky/pre-commit +8 -8
- package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.d.ts +1 -0
- package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.js +47 -0
- package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.js.map +1 -0
- package/dist/src/core/entity/email-log.entity.d.ts +35 -0
- package/dist/src/core/entity/email-log.entity.js +43 -0
- package/dist/src/core/entity/email-log.entity.js.map +1 -0
- package/dist/src/core/enum/email-status.enum.d.ts +5 -0
- package/dist/src/core/enum/email-status.enum.js +10 -0
- package/dist/src/core/enum/email-status.enum.js.map +1 -0
- package/dist/src/core/index.d.ts +4 -0
- package/dist/src/core/index.js +8 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/interface/email-log.interface.d.ts +18 -0
- package/dist/src/core/interface/email-log.interface.js +3 -0
- package/dist/src/core/interface/email-log.interface.js.map +1 -0
- package/dist/src/core/interface/i-email-repository.d.ts +16 -0
- package/dist/src/core/interface/i-email-repository.js +3 -0
- package/dist/src/core/interface/i-email-repository.js.map +1 -0
- package/dist/src/domain/repositories/mail-log.repository.d.ts +4 -0
- package/dist/src/domain/repositories/mail-log.repository.js +3 -0
- package/dist/src/domain/repositories/mail-log.repository.js.map +1 -0
- package/dist/src/infrastructure/repositories/file-system-mail-log.repository.d.ts +5 -0
- package/dist/src/infrastructure/repositories/file-system-mail-log.repository.js +26 -0
- package/dist/src/infrastructure/repositories/file-system-mail-log.repository.js.map +1 -0
- package/dist/src/interfaces/EmailLog.d.ts +25 -25
- package/dist/src/interfaces/EmailLog.js +28 -34
- package/dist/src/interfaces/EmailLog.js.map +1 -1
- package/dist/src/interfaces/IEmailRepository.d.ts +9 -2
- package/dist/src/interfaces/IEmailRepository.js +7 -0
- package/dist/src/interfaces/IEmailRepository.js.map +1 -1
- package/dist/src/interfaces/index.d.ts +1 -1
- package/dist/src/interfaces/index.js +3 -1
- package/dist/src/interfaces/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/interfaces/EmailLog.ts +60 -62
- package/src/interfaces/IEmailRepository.ts +13 -2
- package/src/interfaces/index.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type EmailStatus = '
|
|
1
|
+
export type EmailStatus = 'pending' | 'success' | 'failed';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export interface EmailLogProps {
|
|
4
4
|
id: string;
|
|
5
5
|
recipient: string;
|
|
6
6
|
subject: string;
|
|
@@ -8,86 +8,84 @@ export class EmailLog {
|
|
|
8
8
|
bodyHtml: string;
|
|
9
9
|
bodyText: string;
|
|
10
10
|
payload: string;
|
|
11
|
-
|
|
11
|
+
status?: string;
|
|
12
12
|
error?: string;
|
|
13
|
-
sentAt
|
|
14
|
-
createdAt
|
|
13
|
+
sentAt?: Date;
|
|
14
|
+
createdAt?: Date;
|
|
15
15
|
updatedAt?: Date;
|
|
16
16
|
resentFromId?: string;
|
|
17
17
|
resendMethod?: string;
|
|
18
18
|
resentById?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class EmailLog {
|
|
22
|
+
public readonly id: string;
|
|
23
|
+
public readonly recipient: string;
|
|
24
|
+
public readonly subject: string;
|
|
25
|
+
public readonly emailType: string;
|
|
26
|
+
public readonly bodyHtml: string;
|
|
27
|
+
public readonly bodyText: string;
|
|
28
|
+
public readonly payload: string;
|
|
29
|
+
|
|
30
|
+
public error?: string;
|
|
31
|
+
|
|
32
|
+
public readonly sentAt: Date;
|
|
33
|
+
public readonly createdAt: Date;
|
|
34
|
+
public updatedAt?: Date;
|
|
35
|
+
|
|
36
|
+
public readonly resentFromId?: string;
|
|
37
|
+
public readonly resendMethod?: string;
|
|
38
|
+
public readonly resentById?: string;
|
|
39
|
+
|
|
40
|
+
private _status: EmailStatus;
|
|
41
|
+
|
|
42
|
+
constructor(props: EmailLogProps) {
|
|
43
|
+
this.id = props.id;
|
|
44
|
+
this.recipient = props.recipient;
|
|
45
|
+
this.subject = props.subject;
|
|
46
|
+
this.emailType = props.emailType;
|
|
47
|
+
this.bodyHtml = props.bodyHtml;
|
|
48
|
+
this.bodyText = props.bodyText;
|
|
49
|
+
this.payload = props.payload;
|
|
50
|
+
|
|
51
|
+
this.sentAt = props.sentAt || new Date();
|
|
52
|
+
this.createdAt = props.createdAt || new Date();
|
|
53
|
+
this.updatedAt = props.updatedAt;
|
|
19
54
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
bodyText: string;
|
|
27
|
-
payload: string;
|
|
28
|
-
status?: EmailStatus;
|
|
29
|
-
error?: string;
|
|
30
|
-
sentAt?: Date;
|
|
31
|
-
createdAt?: Date;
|
|
32
|
-
updatedAt?: Date;
|
|
33
|
-
resentFromId?: string;
|
|
34
|
-
resendMethod?: string;
|
|
35
|
-
resentById?: string;
|
|
36
|
-
}) {
|
|
37
|
-
this.id = params.id;
|
|
38
|
-
this.recipient = params.recipient;
|
|
39
|
-
this.subject = params.subject;
|
|
40
|
-
this.emailType = params.emailType;
|
|
41
|
-
this.bodyHtml = params.bodyHtml;
|
|
42
|
-
this.bodyText = params.bodyText;
|
|
43
|
-
this.payload = params.payload;
|
|
44
|
-
this.error = params.error;
|
|
45
|
-
this.sentAt = params.sentAt ?? new Date();
|
|
46
|
-
this.createdAt = params.createdAt ?? new Date();
|
|
47
|
-
this.updatedAt = params.updatedAt;
|
|
48
|
-
this.resentFromId = params.resentFromId;
|
|
49
|
-
this.resendMethod = params.resendMethod;
|
|
50
|
-
this.resentById = params.resentById;
|
|
51
|
-
|
|
52
|
-
// Ensure stored status is lowercase and valid
|
|
53
|
-
const initialStatus = (params.status ?? 'pending') as string;
|
|
54
|
-
this._status = EmailLog.normalizeStatus(initialStatus);
|
|
55
|
+
this.resentFromId = props.resentFromId;
|
|
56
|
+
this.resendMethod = props.resendMethod;
|
|
57
|
+
this.resentById = props.resentById;
|
|
58
|
+
|
|
59
|
+
this.error = props.error;
|
|
60
|
+
this._status = this.normalizeStatus(props.status);
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
// Enforce lowercase when reading
|
|
58
63
|
get status(): EmailStatus {
|
|
59
64
|
return this._status;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this._status = EmailLog.normalizeStatus(value as string);
|
|
65
|
-
this.updatedAt = new Date();
|
|
66
|
-
}
|
|
67
|
+
public updateStatus(status: EmailStatus | string): void {
|
|
68
|
+
const normalized = this.normalizeStatus(status);
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const lower = (s ?? '').toLowerCase();
|
|
71
|
-
if (lower === 'success' || lower === 'failed' || lower === 'pending') {
|
|
72
|
-
return lower as EmailStatus;
|
|
70
|
+
if (this._status === normalized) {
|
|
71
|
+
return;
|
|
73
72
|
}
|
|
74
|
-
throw new Error(`Invalid EmailStatus value: ${s}`);
|
|
75
|
-
}
|
|
76
73
|
|
|
77
|
-
// Only allow transitions from pending -> success|failed
|
|
78
|
-
updateStatus(newStatus: EmailStatus): void {
|
|
79
|
-
const normalized = EmailLog.normalizeStatus(newStatus as string);
|
|
80
74
|
if (this._status !== 'pending') {
|
|
81
75
|
throw new Error(
|
|
82
|
-
`Invalid status transition:
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
if (normalized !== 'success' && normalized !== 'failed') {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Invalid target status: ${normalized}. Must be 'success' or 'failed'`,
|
|
76
|
+
`Invalid status transition: cannot change from '${this._status}' to '${normalized}'`,
|
|
88
77
|
);
|
|
89
78
|
}
|
|
79
|
+
|
|
90
80
|
this._status = normalized;
|
|
91
81
|
this.updatedAt = new Date();
|
|
92
82
|
}
|
|
83
|
+
|
|
84
|
+
private normalizeStatus(status?: string): EmailStatus {
|
|
85
|
+
const s = (status || 'pending').toLowerCase();
|
|
86
|
+
if (s === 'pending' || s === 'success' || s === 'failed') {
|
|
87
|
+
return s as EmailStatus;
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`Invalid EmailStatus value: ${status}`);
|
|
90
|
+
}
|
|
93
91
|
}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { EmailLog, EmailStatus } from './EmailLog';
|
|
2
2
|
|
|
3
|
+
export class MailFilter {
|
|
4
|
+
status?: EmailStatus;
|
|
5
|
+
recipient?: string;
|
|
6
|
+
subject?: string;
|
|
7
|
+
fromDate?: Date;
|
|
8
|
+
toDate?: Date;
|
|
9
|
+
|
|
10
|
+
hasValue(): boolean {
|
|
11
|
+
return Object.values(this).some((value) => value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
3
15
|
export interface IEmailRepository {
|
|
4
16
|
listAll(): Promise<EmailLog[]>;
|
|
5
|
-
|
|
6
|
-
findByRecipient(recipient: string): Promise<EmailLog[]>;
|
|
17
|
+
listWithFilter(filter: MailFilter): Promise<EmailLog[]>;
|
|
7
18
|
}
|
package/src/interfaces/index.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { ILogTransactionOption } from './log-transaction-options.interface';
|
|
|
2
2
|
export { IMailLog } from './mail-log.interface';
|
|
3
3
|
export { ISendMailConfig } from './mail-config.interface';
|
|
4
4
|
export { EmailLog } from './EmailLog';
|
|
5
|
-
export { IEmailRepository } from './IEmailRepository';
|
|
5
|
+
export { IEmailRepository, MailFilter } from './IEmailRepository';
|