@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/.husky/pre-commit
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env sh
|
|
2
|
-
. "$(dirname -- "$0")/_/husky.sh"
|
|
3
|
-
|
|
4
|
-
npm run lint
|
|
5
|
-
npm run format
|
|
6
|
-
npm run build
|
|
7
|
-
git add .
|
|
8
|
-
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
. "$(dirname -- "$0")/_/husky.sh"
|
|
3
|
+
|
|
4
|
+
npm run lint
|
|
5
|
+
npm run format
|
|
6
|
+
npm run build
|
|
7
|
+
git add .
|
|
8
|
+
|
package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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
|
package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailLog = exports.EmailStatus = void 0;
|
|
4
|
+
var email_status_enum_1 = require("./enum/email-status.enum");
|
|
5
|
+
Object.defineProperty(exports, "EmailStatus", { enumerable: true, get: function () { return email_status_enum_1.EmailStatus; } });
|
|
6
|
+
var email_log_entity_1 = require("./entity/email-log.entity");
|
|
7
|
+
Object.defineProperty(exports, "EmailLog", { enumerable: true, get: function () { return email_log_entity_1.EmailLog; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/index.ts"],"names":[],"mappings":";;;AAAA,8DAAuD;AAA9C,gHAAA,WAAW,OAAA;AAGpB,8DAAqD;AAA5C,4GAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EmailStatus } from "../enum/email-status.enum";
|
|
2
|
+
export interface EmailLogInterface {
|
|
3
|
+
id: string;
|
|
4
|
+
recipient: string;
|
|
5
|
+
subject: string;
|
|
6
|
+
emailType: string;
|
|
7
|
+
bodyHtml: string;
|
|
8
|
+
bodyText: string;
|
|
9
|
+
payload: string;
|
|
10
|
+
status: EmailStatus;
|
|
11
|
+
error?: string;
|
|
12
|
+
sentAt: Date;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
updatedAt?: Date;
|
|
15
|
+
resentFromId?: string;
|
|
16
|
+
resendMethod?: string;
|
|
17
|
+
resentById?: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-log.interface.js","sourceRoot":"","sources":["../../../../src/core/interface/email-log.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EmailLogInterface } from "./email-log.interface";
|
|
2
|
+
import { EmailStatus } from "../enum/email-status.enum";
|
|
3
|
+
export interface EmailFilters {
|
|
4
|
+
status?: EmailStatus;
|
|
5
|
+
search?: string;
|
|
6
|
+
startDate?: Date;
|
|
7
|
+
endDate?: Date;
|
|
8
|
+
emailType?: string;
|
|
9
|
+
resentFromId?: string;
|
|
10
|
+
resendMethod?: string;
|
|
11
|
+
resentById?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface IEmailRepository {
|
|
14
|
+
list(): Promise<EmailLogInterface[]>;
|
|
15
|
+
list(filters: EmailFilters): Promise<EmailLogInterface[]>;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-email-repository.js","sourceRoot":"","sources":["../../../../src/core/interface/i-email-repository.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mail-log.repository.js","sourceRoot":"","sources":["../../../../src/domain/repositories/mail-log.repository.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IMailLog } from '../../interfaces/mail-log.interface';
|
|
2
|
+
import { IMailLogRepository } from '../../domain/repositories/mail-log.repository';
|
|
3
|
+
export declare class FileSystemMailLogRepository implements IMailLogRepository {
|
|
4
|
+
save(mailLogOptions: IMailLog): void;
|
|
5
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileSystemMailLogRepository = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
class FileSystemMailLogRepository {
|
|
7
|
+
save(mailLogOptions) {
|
|
8
|
+
try {
|
|
9
|
+
const logFolderPath = path.join(process.cwd(), 'mail-log');
|
|
10
|
+
if (!fs.existsSync(logFolderPath)) {
|
|
11
|
+
fs.mkdirSync(logFolderPath);
|
|
12
|
+
}
|
|
13
|
+
const currentDate = new Date();
|
|
14
|
+
const formattedDate = currentDate.toISOString().slice(0, 10);
|
|
15
|
+
const logFileName = `${formattedDate}.log`;
|
|
16
|
+
const logFilePath = path.join(logFolderPath, logFileName);
|
|
17
|
+
const stringData = JSON.stringify(mailLogOptions);
|
|
18
|
+
fs.appendFileSync(logFilePath, '\n' + stringData);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
throw new Error('Error occurred while logging mail');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.FileSystemMailLogRepository = FileSystemMailLogRepository;
|
|
26
|
+
//# sourceMappingURL=file-system-mail-log.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-system-mail-log.repository.js","sourceRoot":"","sources":["../../../../src/infrastructure/repositories/file-system-mail-log.repository.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAI7B,MAAa,2BAA2B;IACtC,IAAI,CAAC,cAAwB;QAC3B,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;YAE3D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;gBAClC,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;YAC9B,CAAC;YAED,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;YAE/B,MAAM,aAAa,GAAG,WAAW,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC7D,MAAM,WAAW,GAAG,GAAG,aAAa,MAAM,CAAC;YAC3C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,CAAC;YAC1D,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;YAElD,EAAE,CAAC,cAAc,CAAC,WAAW,EAAE,IAAI,GAAG,UAAU,CAAC,CAAC;QACpD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AArBD,kEAqBC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type EmailStatus = '
|
|
2
|
-
export
|
|
1
|
+
export type EmailStatus = 'pending' | 'success' | 'failed';
|
|
2
|
+
export interface EmailLogProps {
|
|
3
3
|
id: string;
|
|
4
4
|
recipient: string;
|
|
5
5
|
subject: string;
|
|
@@ -7,33 +7,33 @@ export declare class EmailLog {
|
|
|
7
7
|
bodyHtml: string;
|
|
8
8
|
bodyText: string;
|
|
9
9
|
payload: string;
|
|
10
|
-
|
|
10
|
+
status?: string;
|
|
11
11
|
error?: string;
|
|
12
|
-
sentAt
|
|
13
|
-
createdAt
|
|
12
|
+
sentAt?: Date;
|
|
13
|
+
createdAt?: Date;
|
|
14
14
|
updatedAt?: Date;
|
|
15
15
|
resentFromId?: string;
|
|
16
16
|
resendMethod?: string;
|
|
17
17
|
resentById?: string;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
}
|
|
19
|
+
export declare class EmailLog {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly recipient: string;
|
|
22
|
+
readonly subject: string;
|
|
23
|
+
readonly emailType: string;
|
|
24
|
+
readonly bodyHtml: string;
|
|
25
|
+
readonly bodyText: string;
|
|
26
|
+
readonly payload: string;
|
|
27
|
+
error?: string;
|
|
28
|
+
readonly sentAt: Date;
|
|
29
|
+
readonly createdAt: Date;
|
|
30
|
+
updatedAt?: Date;
|
|
31
|
+
readonly resentFromId?: string;
|
|
32
|
+
readonly resendMethod?: string;
|
|
33
|
+
readonly resentById?: string;
|
|
34
|
+
private _status;
|
|
35
|
+
constructor(props: EmailLogProps);
|
|
35
36
|
get status(): EmailStatus;
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
updateStatus(newStatus: EmailStatus): void;
|
|
37
|
+
updateStatus(status: EmailStatus | string): void;
|
|
38
|
+
private normalizeStatus;
|
|
39
39
|
}
|
|
@@ -2,50 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EmailLog = void 0;
|
|
4
4
|
class EmailLog {
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
21
|
-
const initialStatus = ((_c = params.status) !== null && _c !== void 0 ? _c : 'pending');
|
|
22
|
-
this._status = EmailLog.normalizeStatus(initialStatus);
|
|
5
|
+
constructor(props) {
|
|
6
|
+
this.id = props.id;
|
|
7
|
+
this.recipient = props.recipient;
|
|
8
|
+
this.subject = props.subject;
|
|
9
|
+
this.emailType = props.emailType;
|
|
10
|
+
this.bodyHtml = props.bodyHtml;
|
|
11
|
+
this.bodyText = props.bodyText;
|
|
12
|
+
this.payload = props.payload;
|
|
13
|
+
this.sentAt = props.sentAt || new Date();
|
|
14
|
+
this.createdAt = props.createdAt || new Date();
|
|
15
|
+
this.updatedAt = props.updatedAt;
|
|
16
|
+
this.resentFromId = props.resentFromId;
|
|
17
|
+
this.resendMethod = props.resendMethod;
|
|
18
|
+
this.resentById = props.resentById;
|
|
19
|
+
this.error = props.error;
|
|
20
|
+
this._status = this.normalizeStatus(props.status);
|
|
23
21
|
}
|
|
24
22
|
get status() {
|
|
25
23
|
return this._status;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
static normalizeStatus(s) {
|
|
32
|
-
const lower = (s !== null && s !== void 0 ? s : '').toLowerCase();
|
|
33
|
-
if (lower === 'success' || lower === 'failed' || lower === 'pending') {
|
|
34
|
-
return lower;
|
|
25
|
+
updateStatus(status) {
|
|
26
|
+
const normalized = this.normalizeStatus(status);
|
|
27
|
+
if (this._status === normalized) {
|
|
28
|
+
return;
|
|
35
29
|
}
|
|
36
|
-
throw new Error(`Invalid EmailStatus value: ${s}`);
|
|
37
|
-
}
|
|
38
|
-
updateStatus(newStatus) {
|
|
39
|
-
const normalized = EmailLog.normalizeStatus(newStatus);
|
|
40
30
|
if (this._status !== 'pending') {
|
|
41
|
-
throw new Error(`Invalid status transition:
|
|
42
|
-
}
|
|
43
|
-
if (normalized !== 'success' && normalized !== 'failed') {
|
|
44
|
-
throw new Error(`Invalid target status: ${normalized}. Must be 'success' or 'failed'`);
|
|
31
|
+
throw new Error(`Invalid status transition: cannot change from '${this._status}' to '${normalized}'`);
|
|
45
32
|
}
|
|
46
33
|
this._status = normalized;
|
|
47
34
|
this.updatedAt = new Date();
|
|
48
35
|
}
|
|
36
|
+
normalizeStatus(status) {
|
|
37
|
+
const s = (status || 'pending').toLowerCase();
|
|
38
|
+
if (s === 'pending' || s === 'success' || s === 'failed') {
|
|
39
|
+
return s;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Invalid EmailStatus value: ${status}`);
|
|
42
|
+
}
|
|
49
43
|
}
|
|
50
44
|
exports.EmailLog = EmailLog;
|
|
51
45
|
//# sourceMappingURL=EmailLog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailLog.js","sourceRoot":"","sources":["../../../src/interfaces/EmailLog.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"EmailLog.js","sourceRoot":"","sources":["../../../src/interfaces/EmailLog.ts"],"names":[],"mappings":";;;AAoBA,MAAa,QAAQ;IAqBnB,YAAY,KAAoB;QAC9B,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAE7B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACzC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QAEjC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;QACvC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC;QACvC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;QAEnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,YAAY,CAAC,MAA4B;QAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAEhD,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YAChC,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CACb,kDAAkD,IAAI,CAAC,OAAO,SAAS,UAAU,GAAG,CACrF,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC9B,CAAC;IAEO,eAAe,CAAC,MAAe;QACrC,MAAM,CAAC,GAAG,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;QAC9C,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;YACzD,OAAO,CAAgB,CAAC;QAC1B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AAtED,4BAsEC"}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { EmailLog, EmailStatus } from './EmailLog';
|
|
2
|
+
export declare class MailFilter {
|
|
3
|
+
status?: EmailStatus;
|
|
4
|
+
recipient?: string;
|
|
5
|
+
subject?: string;
|
|
6
|
+
fromDate?: Date;
|
|
7
|
+
toDate?: Date;
|
|
8
|
+
hasValue(): boolean;
|
|
9
|
+
}
|
|
2
10
|
export interface IEmailRepository {
|
|
3
11
|
listAll(): Promise<EmailLog[]>;
|
|
4
|
-
|
|
5
|
-
findByRecipient(recipient: string): Promise<EmailLog[]>;
|
|
12
|
+
listWithFilter(filter: MailFilter): Promise<EmailLog[]>;
|
|
6
13
|
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MailFilter = void 0;
|
|
4
|
+
class MailFilter {
|
|
5
|
+
hasValue() {
|
|
6
|
+
return Object.values(this).some((value) => value);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.MailFilter = MailFilter;
|
|
3
10
|
//# sourceMappingURL=IEmailRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IEmailRepository.js","sourceRoot":"","sources":["../../../src/interfaces/IEmailRepository.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"IEmailRepository.js","sourceRoot":"","sources":["../../../src/interfaces/IEmailRepository.ts"],"names":[],"mappings":";;;AAEA,MAAa,UAAU;IAOrB,QAAQ;QACN,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;CACF;AAVD,gCAUC"}
|
|
@@ -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';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EmailLog = void 0;
|
|
3
|
+
exports.MailFilter = exports.EmailLog = void 0;
|
|
4
4
|
var EmailLog_1 = require("./EmailLog");
|
|
5
5
|
Object.defineProperty(exports, "EmailLog", { enumerable: true, get: function () { return EmailLog_1.EmailLog; } });
|
|
6
|
+
var IEmailRepository_1 = require("./IEmailRepository");
|
|
7
|
+
Object.defineProperty(exports, "MailFilter", { enumerable: true, get: function () { return IEmailRepository_1.MailFilter; } });
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAGA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAGA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,uDAAkE;AAAvC,8GAAA,UAAU,OAAA"}
|