@tomei/mailer 0.7.1 → 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.
Files changed (50) hide show
  1. package/.gitlab-ci.yml +16 -16
  2. package/.husky/commit-msg +15 -15
  3. package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.d.ts +1 -0
  4. package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.js +47 -0
  5. package/dist/__tests__/unit/infrastructure/repositories/file-system-mail-log.repository.spec.js.map +1 -0
  6. package/dist/src/core/entity/email-log.entity.d.ts +35 -0
  7. package/dist/src/core/entity/email-log.entity.js +43 -0
  8. package/dist/src/core/entity/email-log.entity.js.map +1 -0
  9. package/dist/src/core/enum/email-status.enum.d.ts +5 -0
  10. package/dist/src/core/enum/email-status.enum.js +10 -0
  11. package/dist/src/core/enum/email-status.enum.js.map +1 -0
  12. package/dist/src/core/index.d.ts +4 -0
  13. package/dist/src/core/index.js +8 -0
  14. package/dist/src/core/index.js.map +1 -0
  15. package/dist/src/core/interface/email-log.interface.d.ts +18 -0
  16. package/dist/src/core/interface/email-log.interface.js +3 -0
  17. package/dist/src/core/interface/email-log.interface.js.map +1 -0
  18. package/dist/src/core/interface/i-email-repository.d.ts +16 -0
  19. package/dist/src/core/interface/i-email-repository.js +3 -0
  20. package/dist/src/core/interface/i-email-repository.js.map +1 -0
  21. package/dist/src/domain/repositories/mail-log.repository.d.ts +4 -0
  22. package/dist/src/domain/repositories/mail-log.repository.js +3 -0
  23. package/dist/src/domain/repositories/mail-log.repository.js.map +1 -0
  24. package/dist/src/infrastructure/repositories/file-system-mail-log.repository.d.ts +5 -0
  25. package/dist/src/infrastructure/repositories/file-system-mail-log.repository.js +26 -0
  26. package/dist/src/infrastructure/repositories/file-system-mail-log.repository.js.map +1 -0
  27. package/dist/src/interfaces/EmailLog.d.ts +39 -0
  28. package/dist/src/interfaces/EmailLog.js +45 -0
  29. package/dist/src/interfaces/EmailLog.js.map +1 -0
  30. package/dist/src/interfaces/IEmailRepository.d.ts +13 -0
  31. package/dist/src/interfaces/IEmailRepository.js +10 -0
  32. package/dist/src/interfaces/IEmailRepository.js.map +1 -0
  33. package/dist/src/interfaces/index.d.ts +2 -0
  34. package/dist/src/interfaces/index.js +5 -0
  35. package/dist/src/interfaces/index.js.map +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/eslint.config.mjs +58 -58
  38. package/package.json +47 -47
  39. package/sonar-project.properties +12 -12
  40. package/src/enum/email-status.enum.ts +4 -4
  41. package/src/enum/index.ts +1 -1
  42. package/src/interfaces/EmailLog.ts +91 -0
  43. package/src/interfaces/IEmailRepository.ts +18 -0
  44. package/src/interfaces/index.ts +2 -0
  45. package/src/interfaces/log-transaction-options.interface.ts +18 -18
  46. package/src/interfaces/mail-config.interface.ts +8 -8
  47. package/src/interfaces/mail-log.interface.ts +12 -12
  48. package/src/mailer/index.ts +2 -2
  49. package/src/mailer/mailer.base.ts +110 -110
  50. package/src/mailer/smtp-mailer.ts +121 -121
package/eslint.config.mjs CHANGED
@@ -1,58 +1,58 @@
1
- import eslintPlugin from "@typescript-eslint/eslint-plugin";
2
- import parser from "@typescript-eslint/parser";
3
- import importPlugin from 'eslint-plugin-import'
4
- import path from 'path';
5
- import { fileURLToPath } from 'url';
6
-
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = path.dirname(__filename);
9
-
10
- export default [
11
- {
12
- languageOptions: {
13
- parser: parser,
14
- ecmaVersion: "latest", // Allows modern ECMAScript features
15
- sourceType: "module", // Allows for the use of imports
16
- parserOptions: {
17
- tsconfigRootDir: __dirname,
18
- project: './tsconfig.json'
19
- },
20
- },
21
- plugins: {
22
- "@typescript-eslint": eslintPlugin,
23
- import: importPlugin
24
- },
25
- rules: {
26
- "no-console": "off",
27
- "@typescript-eslint/no-explicit-any": "off",
28
- "@typescript-eslint/no-var-requires": "off",
29
- "@typescript-eslint/explicit-module-boundary-types": "off",
30
- "import/prefer-default-export": "off",
31
- "@typescript-eslint/no-unused-vars": "warn",
32
- "no-useless-catch": "off",
33
- "@typescript-eslint/no-non-null-assertion": "off",
34
- "@typescript-eslint/no-empty-function": "off",
35
- "@typescript-eslint/no-empty-interface": "off",
36
- "@typescript-eslint/no-inferrable-types": "off",
37
- "@typescript-eslint/no-namespace": "off",
38
- "@typescript-eslint/no-use-before-define": "off",
39
- "@typescript-eslint/no-unsafe-assignment": "off",
40
- "@typescript-eslint/no-unsafe-call": "off",
41
- "@typescript-eslint/no-unsafe-member-access": "off",
42
- "@typescript-eslint/no-unsafe-return": "off",
43
- "@typescript-eslint/restrict-template-expressions": "off",
44
- "no-useless-escape": "off",
45
- "import/no-relative-parent-imports": "error", // Enforce relative imports only
46
- "import/no-absolute-path": "error", // Block absolute imports outside aliases
47
- "import/no-unresolved": ["error", { commonjs: true }],
48
- },
49
- settings: {
50
- "import/resolver": {
51
- typescript: {
52
- alwaysTryTypes: true,
53
- }
54
- }
55
- },
56
- ignores: ["node_modules", "dist/**/*", "eslint.config.mjs"],
57
- },
58
- ];
1
+ import eslintPlugin from "@typescript-eslint/eslint-plugin";
2
+ import parser from "@typescript-eslint/parser";
3
+ import importPlugin from 'eslint-plugin-import'
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+
10
+ export default [
11
+ {
12
+ languageOptions: {
13
+ parser: parser,
14
+ ecmaVersion: "latest", // Allows modern ECMAScript features
15
+ sourceType: "module", // Allows for the use of imports
16
+ parserOptions: {
17
+ tsconfigRootDir: __dirname,
18
+ project: './tsconfig.json'
19
+ },
20
+ },
21
+ plugins: {
22
+ "@typescript-eslint": eslintPlugin,
23
+ import: importPlugin
24
+ },
25
+ rules: {
26
+ "no-console": "off",
27
+ "@typescript-eslint/no-explicit-any": "off",
28
+ "@typescript-eslint/no-var-requires": "off",
29
+ "@typescript-eslint/explicit-module-boundary-types": "off",
30
+ "import/prefer-default-export": "off",
31
+ "@typescript-eslint/no-unused-vars": "warn",
32
+ "no-useless-catch": "off",
33
+ "@typescript-eslint/no-non-null-assertion": "off",
34
+ "@typescript-eslint/no-empty-function": "off",
35
+ "@typescript-eslint/no-empty-interface": "off",
36
+ "@typescript-eslint/no-inferrable-types": "off",
37
+ "@typescript-eslint/no-namespace": "off",
38
+ "@typescript-eslint/no-use-before-define": "off",
39
+ "@typescript-eslint/no-unsafe-assignment": "off",
40
+ "@typescript-eslint/no-unsafe-call": "off",
41
+ "@typescript-eslint/no-unsafe-member-access": "off",
42
+ "@typescript-eslint/no-unsafe-return": "off",
43
+ "@typescript-eslint/restrict-template-expressions": "off",
44
+ "no-useless-escape": "off",
45
+ "import/no-relative-parent-imports": "error", // Enforce relative imports only
46
+ "import/no-absolute-path": "error", // Block absolute imports outside aliases
47
+ "import/no-unresolved": ["error", { commonjs: true }],
48
+ },
49
+ settings: {
50
+ "import/resolver": {
51
+ typescript: {
52
+ alwaysTryTypes: true,
53
+ }
54
+ }
55
+ },
56
+ ignores: ["node_modules", "dist/**/*", "eslint.config.mjs"],
57
+ },
58
+ ];
package/package.json CHANGED
@@ -1,47 +1,47 @@
1
- {
2
- "name": "@tomei/mailer",
3
- "version": "0.7.1",
4
- "description": "Tomei Mailer Package",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "start:dev": "tsc -w",
8
- "build": "tsc",
9
- "format": "prettier --write \"src/**/*.ts\"",
10
- "lint": "npx eslint . --fix",
11
- "test": "jest --forceExit --detectOpenHandles",
12
- "prepare": "husky"
13
- },
14
- "author": "Tomei",
15
- "license": "ISC",
16
- "devDependencies": {
17
- "@commitlint/cli": "^19.8.1",
18
- "@commitlint/config-conventional": "^19.8.1",
19
- "@eslint/js": "^9.35.0",
20
- "@tsconfig/node18": "^18.2.4",
21
- "@types/jest": "^30.0.0",
22
- "@types/node": "^24.5.2",
23
- "@types/nodemailer": "^7.0.1",
24
- "@typescript-eslint/eslint-plugin": "^8.44.0",
25
- "@typescript-eslint/parser": "^8.44.0",
26
- "eslint": "^9.35.0",
27
- "eslint-config-prettier": "^10.1.8",
28
- "eslint-plugin-import": "^2.32.0",
29
- "eslint-plugin-prettier": "^5.5.4",
30
- "globals": "^16.4.0",
31
- "husky": "^9.1.7",
32
- "jest": "^30.1.3",
33
- "nodemailer-mock": "^2.0.9",
34
- "prettier": "^3.6.2",
35
- "ts-jest": "^29.4.3",
36
- "ts-node": "^10.9.2",
37
- "tsc-watch": "^7.1.1",
38
- "typescript": "^5.9.2"
39
- },
40
- "publishConfig": {
41
- "access": "public"
42
- },
43
- "peerDependencies": {
44
- "@tomei/config": "^0.3.22",
45
- "nodemailer": "^7.0.6"
46
- }
47
- }
1
+ {
2
+ "name": "@tomei/mailer",
3
+ "version": "0.10.0-dev.1",
4
+ "description": "Tomei Mailer Package",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "start:dev": "tsc -w",
8
+ "build": "tsc",
9
+ "format": "prettier --write \"src/**/*.ts\"",
10
+ "lint": "npx eslint . --fix",
11
+ "test": "jest --forceExit --detectOpenHandles",
12
+ "prepare": "husky"
13
+ },
14
+ "author": "Tomei",
15
+ "license": "ISC",
16
+ "devDependencies": {
17
+ "@commitlint/cli": "^19.8.1",
18
+ "@commitlint/config-conventional": "^19.8.1",
19
+ "@eslint/js": "^9.35.0",
20
+ "@tsconfig/node18": "^18.2.4",
21
+ "@types/jest": "^30.0.0",
22
+ "@types/node": "^24.5.2",
23
+ "@types/nodemailer": "^7.0.1",
24
+ "@typescript-eslint/eslint-plugin": "^8.44.0",
25
+ "@typescript-eslint/parser": "^8.44.0",
26
+ "eslint": "^9.35.0",
27
+ "eslint-config-prettier": "^10.1.8",
28
+ "eslint-plugin-import": "^2.32.0",
29
+ "eslint-plugin-prettier": "^5.5.4",
30
+ "globals": "^16.4.0",
31
+ "husky": "^9.1.7",
32
+ "jest": "^30.1.3",
33
+ "nodemailer-mock": "^2.0.9",
34
+ "prettier": "^3.6.2",
35
+ "ts-jest": "^29.4.3",
36
+ "ts-node": "^10.9.2",
37
+ "tsc-watch": "^7.1.1",
38
+ "typescript": "^5.9.2"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "peerDependencies": {
44
+ "@tomei/config": "^0.3.22",
45
+ "nodemailer": "^7.0.6"
46
+ }
47
+ }
@@ -1,13 +1,13 @@
1
- sonar.projectKey=all-tomei-projects_mailer
2
- sonar.organization=all-tomei-projects
3
-
4
- # This is the name and version displayed in the SonarCloud UI.
5
- #sonar.projectName=Mailer
6
- #sonar.projectVersion=1.0
7
-
8
-
9
- # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
10
- #sonar.sources=.
11
-
12
- # Encoding of the source code. Default is default system encoding
1
+ sonar.projectKey=all-tomei-projects_mailer
2
+ sonar.organization=all-tomei-projects
3
+
4
+ # This is the name and version displayed in the SonarCloud UI.
5
+ #sonar.projectName=Mailer
6
+ #sonar.projectVersion=1.0
7
+
8
+
9
+ # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
10
+ #sonar.sources=.
11
+
12
+ # Encoding of the source code. Default is default system encoding
13
13
  #sonar.sourceEncoding=UTF-8
@@ -1,4 +1,4 @@
1
- export enum EmailStatus {
2
- Sent = 'Sent',
3
- Failed = 'Failed',
4
- }
1
+ export enum EmailStatus {
2
+ Sent = 'Sent',
3
+ Failed = 'Failed',
4
+ }
package/src/enum/index.ts CHANGED
@@ -1 +1 @@
1
- export { EmailStatus } from './email-status.enum';
1
+ export { EmailStatus } from './email-status.enum';
@@ -0,0 +1,91 @@
1
+ export type EmailStatus = 'pending' | 'success' | 'failed';
2
+
3
+ export interface EmailLogProps {
4
+ id: string;
5
+ recipient: string;
6
+ subject: string;
7
+ emailType: string;
8
+ bodyHtml: string;
9
+ bodyText: string;
10
+ payload: string;
11
+ status?: string;
12
+ error?: string;
13
+ sentAt?: Date;
14
+ createdAt?: Date;
15
+ updatedAt?: Date;
16
+ resentFromId?: string;
17
+ resendMethod?: string;
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;
54
+
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);
61
+ }
62
+
63
+ get status(): EmailStatus {
64
+ return this._status;
65
+ }
66
+
67
+ public updateStatus(status: EmailStatus | string): void {
68
+ const normalized = this.normalizeStatus(status);
69
+
70
+ if (this._status === normalized) {
71
+ return;
72
+ }
73
+
74
+ if (this._status !== 'pending') {
75
+ throw new Error(
76
+ `Invalid status transition: cannot change from '${this._status}' to '${normalized}'`,
77
+ );
78
+ }
79
+
80
+ this._status = normalized;
81
+ this.updatedAt = new Date();
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
+ }
91
+ }
@@ -0,0 +1,18 @@
1
+ import { EmailLog, EmailStatus } from './EmailLog';
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
+
15
+ export interface IEmailRepository {
16
+ listAll(): Promise<EmailLog[]>;
17
+ listWithFilter(filter: MailFilter): Promise<EmailLog[]>;
18
+ }
@@ -1,3 +1,5 @@
1
1
  export { ILogTransactionOption } from './log-transaction-options.interface';
2
2
  export { IMailLog } from './mail-log.interface';
3
3
  export { ISendMailConfig } from './mail-config.interface';
4
+ export { EmailLog } from './EmailLog';
5
+ export { IEmailRepository, MailFilter } from './IEmailRepository';
@@ -1,18 +1,18 @@
1
- export interface ILogTransactionOption {
2
- options: {
3
- from: string;
4
- to: string;
5
- subject: string;
6
- };
7
- logData: {
8
- systemCode: string;
9
- apiUrl: string;
10
- transactionName: string;
11
- dbName: string;
12
- tableName: string;
13
- dataBefore: string;
14
- dataAfter: string;
15
- performAt: Date;
16
- note: string;
17
- };
18
- }
1
+ export interface ILogTransactionOption {
2
+ options: {
3
+ from: string;
4
+ to: string;
5
+ subject: string;
6
+ };
7
+ logData: {
8
+ systemCode: string;
9
+ apiUrl: string;
10
+ transactionName: string;
11
+ dbName: string;
12
+ tableName: string;
13
+ dataBefore: string;
14
+ dataAfter: string;
15
+ performAt: Date;
16
+ note: string;
17
+ };
18
+ }
@@ -1,8 +1,8 @@
1
- export interface ISendMailConfig {
2
- from: string;
3
- to: string | string[];
4
- cc?: string | string[];
5
- attachments?: any[];
6
- subject: string;
7
- html: any;
8
- }
1
+ export interface ISendMailConfig {
2
+ from: string;
3
+ to: string | string[];
4
+ cc?: string | string[];
5
+ attachments?: any[];
6
+ subject: string;
7
+ html: any;
8
+ }
@@ -1,12 +1,12 @@
1
- import { EmailStatus } from '../enum/email-status.enum';
2
-
3
- export interface IMailLog {
4
- duration: number;
5
- from: string;
6
- to: string;
7
- cc: string;
8
- subject: string;
9
- rawContent: string;
10
- date: Date;
11
- status: EmailStatus;
12
- }
1
+ import { EmailStatus } from '../enum/email-status.enum';
2
+
3
+ export interface IMailLog {
4
+ duration: number;
5
+ from: string;
6
+ to: string;
7
+ cc: string;
8
+ subject: string;
9
+ rawContent: string;
10
+ date: Date;
11
+ status: EmailStatus;
12
+ }
@@ -1,2 +1,2 @@
1
- export { MailerBase } from './mailer.base';
2
- export { SMTPMailer } from './smtp-mailer';
1
+ export { MailerBase } from './mailer.base';
2
+ export { SMTPMailer } from './smtp-mailer';