@zyther/tzmail 0.1.3 → 0.5.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.
- package/README.md +412 -79
- package/dist/core/enums/theme.enum.d.ts +11 -1
- package/dist/core/enums/theme.enum.d.ts.map +1 -1
- package/dist/core/enums/theme.enum.js +10 -0
- package/dist/core/interfaces/email.interface.d.ts +95 -5
- package/dist/core/interfaces/email.interface.d.ts.map +1 -1
- package/dist/core/interfaces/template.interface.d.ts +12 -1
- package/dist/core/interfaces/template.interface.d.ts.map +1 -1
- package/dist/factories/email-factory.d.ts +32 -6
- package/dist/factories/email-factory.d.ts.map +1 -1
- package/dist/factories/email-factory.js +110 -6
- package/dist/factories/template-factory.d.ts.map +1 -1
- package/dist/factories/template-factory.js +170 -60
- package/dist/index.d.ts +16 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/providers/mailgun.transport.d.ts +10 -0
- package/dist/providers/mailgun.transport.d.ts.map +1 -0
- package/dist/providers/mailgun.transport.js +85 -0
- package/dist/providers/nodemailer.transport.d.ts +11 -0
- package/dist/providers/nodemailer.transport.d.ts.map +1 -0
- package/dist/providers/nodemailer.transport.js +23 -0
- package/dist/providers/provider-utils.d.ts +17 -0
- package/dist/providers/provider-utils.d.ts.map +1 -0
- package/dist/providers/provider-utils.js +89 -0
- package/dist/providers/provider.interface.d.ts +30 -0
- package/dist/providers/provider.interface.d.ts.map +1 -0
- package/dist/providers/provider.interface.js +2 -0
- package/dist/providers/sendgrid.transport.d.ts +10 -0
- package/dist/providers/sendgrid.transport.d.ts.map +1 -0
- package/dist/providers/sendgrid.transport.js +76 -0
- package/dist/queues/bullmq-email-queue.d.ts +153 -0
- package/dist/queues/bullmq-email-queue.d.ts.map +1 -0
- package/dist/queues/bullmq-email-queue.js +292 -0
- package/dist/services/attachment.service.d.ts +15 -37
- package/dist/services/attachment.service.d.ts.map +1 -1
- package/dist/services/attachment.service.js +58 -46
- package/dist/services/email.service.d.ts +22 -22
- package/dist/services/email.service.d.ts.map +1 -1
- package/dist/services/email.service.js +117 -33
- package/dist/services/template.service.d.ts +24 -111
- package/dist/services/template.service.d.ts.map +1 -1
- package/dist/services/template.service.js +273 -362
- package/dist/templates/base/color-accessibility.d.ts +4 -0
- package/dist/templates/base/color-accessibility.d.ts.map +1 -0
- package/dist/templates/base/color-accessibility.js +38 -0
- package/dist/templates/base/template-builder.d.ts +4 -1
- package/dist/templates/base/template-builder.d.ts.map +1 -1
- package/dist/templates/base/template-builder.js +276 -527
- package/dist/templates/themes/aurora.theme.d.ts +12 -0
- package/dist/templates/themes/aurora.theme.d.ts.map +1 -0
- package/dist/templates/themes/aurora.theme.js +88 -0
- package/dist/templates/themes/corporate.theme.d.ts +2 -1
- package/dist/templates/themes/corporate.theme.d.ts.map +1 -1
- package/dist/templates/themes/corporate.theme.js +139 -102
- package/dist/templates/themes/editorial.theme.d.ts +12 -0
- package/dist/templates/themes/editorial.theme.d.ts.map +1 -0
- package/dist/templates/themes/editorial.theme.js +90 -0
- package/dist/templates/themes/forest.theme.d.ts +12 -0
- package/dist/templates/themes/forest.theme.d.ts.map +1 -0
- package/dist/templates/themes/forest.theme.js +89 -0
- package/dist/templates/themes/glass.theme.d.ts +12 -0
- package/dist/templates/themes/glass.theme.d.ts.map +1 -0
- package/dist/templates/themes/glass.theme.js +88 -0
- package/dist/templates/themes/lavender.theme.d.ts +12 -0
- package/dist/templates/themes/lavender.theme.d.ts.map +1 -0
- package/dist/templates/themes/lavender.theme.js +91 -0
- package/dist/templates/themes/midnight.theme.d.ts +12 -0
- package/dist/templates/themes/midnight.theme.d.ts.map +1 -0
- package/dist/templates/themes/midnight.theme.js +91 -0
- package/dist/templates/themes/minimal.theme.d.ts +2 -1
- package/dist/templates/themes/minimal.theme.d.ts.map +1 -1
- package/dist/templates/themes/minimal.theme.js +142 -107
- package/dist/templates/themes/modern.theme.d.ts +2 -1
- package/dist/templates/themes/modern.theme.d.ts.map +1 -1
- package/dist/templates/themes/modern.theme.js +109 -74
- package/dist/templates/themes/monokai.theme.d.ts +2 -1
- package/dist/templates/themes/monokai.theme.d.ts.map +1 -1
- package/dist/templates/themes/monokai.theme.js +102 -66
- package/dist/templates/themes/neobrutal.theme.d.ts +12 -0
- package/dist/templates/themes/neobrutal.theme.d.ts.map +1 -0
- package/dist/templates/themes/neobrutal.theme.js +91 -0
- package/dist/templates/themes/ocean.theme.d.ts +12 -0
- package/dist/templates/themes/ocean.theme.d.ts.map +1 -0
- package/dist/templates/themes/ocean.theme.js +90 -0
- package/dist/templates/themes/pastel.theme.d.ts +12 -0
- package/dist/templates/themes/pastel.theme.d.ts.map +1 -0
- package/dist/templates/themes/pastel.theme.js +89 -0
- package/dist/templates/themes/sunset.theme.d.ts +12 -0
- package/dist/templates/themes/sunset.theme.d.ts.map +1 -0
- package/dist/templates/themes/sunset.theme.js +90 -0
- package/dist/templates/themes/system.theme.d.ts +2 -1
- package/dist/templates/themes/system.theme.d.ts.map +1 -1
- package/dist/templates/themes/system.theme.js +81 -47
- package/dist/templates/themes/theme.interface.d.ts +48 -0
- package/dist/templates/themes/theme.interface.d.ts.map +1 -1
- package/package.json +36 -14
- package/src/core/enums/template-part.enum.ts +7 -0
- package/src/core/enums/theme.enum.ts +18 -0
- package/src/core/interfaces/email.interface.ts +116 -0
- package/src/core/interfaces/template.interface.ts +71 -0
- package/src/factories/email-factory.ts +208 -0
- package/src/factories/template-factory.ts +201 -0
- package/src/index.ts +53 -0
- package/src/providers/mailgun.transport.ts +80 -0
- package/src/providers/nodemailer.transport.ts +20 -0
- package/src/providers/provider-utils.ts +91 -0
- package/src/providers/provider.interface.ts +26 -0
- package/src/providers/sendgrid.transport.ts +80 -0
- package/src/queues/bullmq-email-queue.ts +418 -0
- package/src/services/attachment.service.ts +98 -0
- package/src/services/email.service.ts +151 -0
- package/src/services/template.service.ts +431 -0
- package/src/templates/base/color-accessibility.ts +31 -0
- package/src/templates/base/template-builder.ts +438 -0
- package/src/templates/themes/aurora.theme.ts +91 -0
- package/src/templates/themes/corporate.theme.ts +156 -0
- package/src/templates/themes/editorial.theme.ts +93 -0
- package/src/templates/themes/forest.theme.ts +92 -0
- package/src/templates/themes/glass.theme.ts +91 -0
- package/src/templates/themes/lavender.theme.ts +94 -0
- package/src/templates/themes/midnight.theme.ts +94 -0
- package/src/templates/themes/minimal.theme.ts +158 -0
- package/src/templates/themes/modern.theme.ts +124 -0
- package/src/templates/themes/monokai.theme.ts +117 -0
- package/src/templates/themes/neobrutal.theme.ts +94 -0
- package/src/templates/themes/ocean.theme.ts +93 -0
- package/src/templates/themes/pastel.theme.ts +92 -0
- package/src/templates/themes/sunset.theme.ts +93 -0
- package/src/templates/themes/system.theme.ts +92 -0
- package/src/templates/themes/theme.interface.ts +95 -0
- package/src/tests/template.service.test.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITemplate } from
|
|
1
|
+
import { ITemplate } from './template.interface';
|
|
2
2
|
export interface IEmailOptions {
|
|
3
3
|
to: string | string[];
|
|
4
4
|
subject: string;
|
|
@@ -7,6 +7,8 @@ export interface IEmailOptions {
|
|
|
7
7
|
bcc?: string | string[];
|
|
8
8
|
attachments?: IAttachment[];
|
|
9
9
|
template?: ITemplate;
|
|
10
|
+
/** Primitive named values interpolated into `{{variable}}` placeholders. */
|
|
11
|
+
templateData?: Record<string, unknown>;
|
|
10
12
|
text?: string;
|
|
11
13
|
html?: string;
|
|
12
14
|
}
|
|
@@ -17,14 +19,102 @@ export interface IAttachment {
|
|
|
17
19
|
contentType?: string;
|
|
18
20
|
cid?: string;
|
|
19
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Typed outcome of an email attempt. `success` is true only when the transport
|
|
24
|
+
* did not report rejected recipients. `partial` means that at least one
|
|
25
|
+
* recipient was accepted and at least one rejected; a failure result must not
|
|
26
|
+
* be interpreted as successful delivery. `error` retains the original thrown
|
|
27
|
+
* validation, rendering or transport error, when present.
|
|
28
|
+
*/
|
|
29
|
+
export interface IEmailSendResult {
|
|
30
|
+
success: boolean;
|
|
31
|
+
status: 'success' | 'partial' | 'failure';
|
|
32
|
+
messageId?: string;
|
|
33
|
+
response?: string;
|
|
34
|
+
accepted?: Array<string | {
|
|
35
|
+
address: string;
|
|
36
|
+
name: string;
|
|
37
|
+
}>;
|
|
38
|
+
rejected?: Array<string | {
|
|
39
|
+
address: string;
|
|
40
|
+
name: string;
|
|
41
|
+
}>;
|
|
42
|
+
error?: unknown;
|
|
43
|
+
errorStage?: 'validation' | 'render' | 'smtp' | 'provider';
|
|
44
|
+
}
|
|
45
|
+
export type IEmailAuth = {
|
|
46
|
+
user: string;
|
|
47
|
+
pass: string;
|
|
48
|
+
type?: 'login' | 'Login' | 'LOGIN';
|
|
49
|
+
} | {
|
|
50
|
+
user: string;
|
|
51
|
+
type: 'oauth2' | 'OAuth2' | 'OAUTH2';
|
|
52
|
+
clientId?: string;
|
|
53
|
+
clientSecret?: string;
|
|
54
|
+
refreshToken?: string;
|
|
55
|
+
accessToken?: string;
|
|
56
|
+
accessUrl?: string;
|
|
57
|
+
expires?: number;
|
|
58
|
+
timeout?: number;
|
|
59
|
+
privateKey?: string | {
|
|
60
|
+
key: string;
|
|
61
|
+
passphrase: string;
|
|
62
|
+
};
|
|
63
|
+
serviceClient?: string;
|
|
64
|
+
provisionCallback?: (user: string, renew: boolean, callback: (error: Error | null, accessToken: string, expires: number) => void) => void;
|
|
65
|
+
} | {
|
|
66
|
+
user: string;
|
|
67
|
+
pass: string;
|
|
68
|
+
type: 'custom' | 'Custom' | 'CUSTOM';
|
|
69
|
+
method: string;
|
|
70
|
+
};
|
|
20
71
|
export interface IEmailConfig {
|
|
21
72
|
host: string;
|
|
22
73
|
port: number;
|
|
23
74
|
secure: boolean;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
75
|
+
/** Reuse SMTP connections; set true with pool sizing for sustained throughput. */
|
|
76
|
+
pool?: boolean;
|
|
77
|
+
maxConnections?: number;
|
|
78
|
+
maxMessages?: number;
|
|
79
|
+
/** Shared rate limiter window and message limit (requires pool: true). */
|
|
80
|
+
rateDelta?: number;
|
|
81
|
+
rateLimit?: number;
|
|
82
|
+
connectionTimeout?: number;
|
|
83
|
+
greetingTimeout?: number;
|
|
84
|
+
socketTimeout?: number;
|
|
85
|
+
auth: IEmailAuth;
|
|
86
|
+
defaultFrom?: string;
|
|
87
|
+
}
|
|
88
|
+
/** SendGrid Web API v3 settings. API keys should come from a secret manager. */
|
|
89
|
+
export interface ISendGridConfig {
|
|
90
|
+
apiKey: string;
|
|
91
|
+
defaultFrom: string;
|
|
92
|
+
/** Optional API base URL, for example the regional EU API endpoint. */
|
|
93
|
+
apiUrl?: string;
|
|
94
|
+
requestTimeoutMs?: number;
|
|
95
|
+
/** Optional per-attachment memory guard; API attachments are encoded in memory. */
|
|
96
|
+
maxAttachmentBytes?: number;
|
|
97
|
+
}
|
|
98
|
+
/** Mailgun Messages API settings. */
|
|
99
|
+
export interface IMailgunConfig {
|
|
100
|
+
apiKey: string;
|
|
101
|
+
domain: string;
|
|
102
|
+
defaultFrom: string;
|
|
103
|
+
region?: 'us' | 'eu';
|
|
104
|
+
/** Optional custom API base URL, useful for regional or controlled endpoints. */
|
|
105
|
+
apiUrl?: string;
|
|
106
|
+
requestTimeoutMs?: number;
|
|
107
|
+
/** Optional per-attachment memory guard; API attachments are uploaded in memory. */
|
|
108
|
+
maxAttachmentBytes?: number;
|
|
109
|
+
}
|
|
110
|
+
/** Amazon SES v2 settings; when credentials are omitted, the AWS SDK default credential chain is used. */
|
|
111
|
+
export interface IAmazonSesConfig {
|
|
112
|
+
region: string;
|
|
28
113
|
defaultFrom?: string;
|
|
114
|
+
credentials?: {
|
|
115
|
+
accessKeyId: string;
|
|
116
|
+
secretAccessKey: string;
|
|
117
|
+
sessionToken?: string;
|
|
118
|
+
};
|
|
29
119
|
}
|
|
30
120
|
//# sourceMappingURL=email.interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.interface.d.ts","sourceRoot":"","sources":["../../../src/core/interfaces/email.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"email.interface.d.ts","sourceRoot":"","sources":["../../../src/core/interfaces/email.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CA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AAM,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,gFAAgF;AAChF,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mFAAmF;IACnF,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,qCAAqC;AACrC,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IACrB,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,oFAAoF;IACpF,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,0GAA0G;AAC1G,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE;QACZ,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH"}
|
|
@@ -7,6 +7,14 @@ export interface ITemplate {
|
|
|
7
7
|
render(data: any): Promise<string>;
|
|
8
8
|
}
|
|
9
9
|
export interface ITemplateConfig {
|
|
10
|
+
/** BCP 47 language tag written to the generated document; defaults to en. */
|
|
11
|
+
language?: string;
|
|
12
|
+
/** Text direction for right-to-left or automatic-script content; defaults to ltr. */
|
|
13
|
+
direction?: 'ltr' | 'rtl' | 'auto';
|
|
14
|
+
/** Hidden inbox preview text shown beside the subject; limited to 500 characters. */
|
|
15
|
+
preheader?: string;
|
|
16
|
+
/** Decoration for generated footer links; defaults to none. Set to underline when desired. */
|
|
17
|
+
linkDecoration?: 'none' | 'underline';
|
|
10
18
|
header?: IHeaderConfig;
|
|
11
19
|
body?: IBodyConfig;
|
|
12
20
|
footer?: IFooterConfig;
|
|
@@ -17,6 +25,7 @@ export interface ITemplateConfig {
|
|
|
17
25
|
export interface IBodyConfig {
|
|
18
26
|
title?: string;
|
|
19
27
|
message?: string;
|
|
28
|
+
/** HTML intencionalmente confiável; os demais campos textuais são escapados pelo renderer. */
|
|
20
29
|
content?: string;
|
|
21
30
|
buttonText?: string;
|
|
22
31
|
buttonUrl?: string;
|
|
@@ -45,11 +54,13 @@ export interface IFooterConfig {
|
|
|
45
54
|
url: string;
|
|
46
55
|
}>;
|
|
47
56
|
socialLinks?: Array<{
|
|
48
|
-
platform: 'facebook' | 'twitter' | 'linkedin' | 'github' | 'instagram' | 'youtube' | 'tiktok' | 'pinterest' | 'reddit' | '
|
|
57
|
+
platform: 'facebook' | 'twitter' | 'linkedin' | 'github' | 'instagram' | 'youtube' | 'tiktok' | 'pinterest' | 'reddit' | 'gitlab' | 'stackoverflow' | 'medium' | 'dribbble' | 'behance' | 'telegram';
|
|
49
58
|
url: string;
|
|
50
59
|
}>;
|
|
51
60
|
copyrightText?: string;
|
|
52
61
|
unsubscribeText?: string;
|
|
62
|
+
/** URL opcional do link de cancelamento; sem ela, o texto é exibido sem href fictício. */
|
|
63
|
+
unsubscribeUrl?: string;
|
|
53
64
|
backgroundColor?: string;
|
|
54
65
|
textColor?: string;
|
|
55
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.interface.d.ts","sourceRoot":"","sources":["../../../src/core/interfaces/template.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,WAAW,SAA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EAAE;QACL,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;KACrC,CAAC;IACF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,CAAC,CAAC;IACH,WAAW,CAAC,EAAE,KAAK,CAAC;QAClB,QAAQ,EAAE,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,eAAe,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;QACrM,GAAG,EAAE,MAAM,CAAC;KACb,CAAC,CAAC;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,0FAA0F;IAC1F,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -1,19 +1,42 @@
|
|
|
1
|
-
import { IEmailConfig, IEmailOptions } from '../core/interfaces/email.interface';
|
|
2
|
-
import { TemplateService } from '../services/template.service';
|
|
3
|
-
import { AttachmentService } from '../services/attachment.service';
|
|
1
|
+
import { IAmazonSesConfig, IEmailConfig, IEmailOptions, IEmailSendResult, IMailgunConfig, ISendGridConfig } from '../core/interfaces/email.interface';
|
|
2
|
+
import { ITemplateServiceOptions, TemplateService } from '../services/template.service';
|
|
3
|
+
import { AttachmentService, IAttachmentServiceOptions } from '../services/attachment.service';
|
|
4
4
|
import { ThemeType } from '../core/enums/theme.enum';
|
|
5
5
|
import { ITemplateConfig } from '../core/interfaces/template.interface';
|
|
6
|
+
import { IEmailTransport } from '../providers/provider.interface';
|
|
7
|
+
import { BullMQEmailQueue, IBullMQEmailQueueConfig } from '../queues/bullmq-email-queue';
|
|
6
8
|
export declare class EmailFactory {
|
|
7
|
-
private static instance
|
|
9
|
+
private static instance?;
|
|
10
|
+
private static singletonFingerprint?;
|
|
8
11
|
private emailService;
|
|
9
12
|
private templateService;
|
|
10
13
|
private attachmentService;
|
|
11
14
|
private constructor();
|
|
12
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Returns the process singleton. A later call with different settings fails
|
|
17
|
+
* explicitly rather than silently continuing with the first configuration.
|
|
18
|
+
*/
|
|
19
|
+
static initialize(config: IEmailConfig, templateOptions?: ITemplateServiceOptions, attachmentOptions?: IAttachmentServiceOptions): EmailFactory;
|
|
20
|
+
/** Creates an independent factory instance without changing the singleton. */
|
|
21
|
+
static create(config: IEmailConfig, templateOptions?: ITemplateServiceOptions, attachmentOptions?: IAttachmentServiceOptions): EmailFactory;
|
|
22
|
+
/** Creates an independent SendGrid Web API v3 client; no provider state is shared between instances. */
|
|
23
|
+
static createSendGrid(config: ISendGridConfig, templateOptions?: ITemplateServiceOptions, attachmentOptions?: IAttachmentServiceOptions): EmailFactory;
|
|
24
|
+
/** Creates an independent Mailgun Messages API client. */
|
|
25
|
+
static createMailgun(config: IMailgunConfig, templateOptions?: ITemplateServiceOptions, attachmentOptions?: IAttachmentServiceOptions): EmailFactory;
|
|
26
|
+
/** Creates an Amazon SES v2 transport using the AWS SDK credential provider chain unless credentials are supplied. */
|
|
27
|
+
static createSES(config: IAmazonSesConfig, templateOptions?: ITemplateServiceOptions, attachmentOptions?: IAttachmentServiceOptions): EmailFactory;
|
|
28
|
+
/** Creates an instance around a user-supplied transport adapter. */
|
|
29
|
+
static createWithTransport(transport: IEmailTransport, defaultFrom?: string, templateOptions?: ITemplateServiceOptions, attachmentOptions?: IAttachmentServiceOptions): EmailFactory;
|
|
30
|
+
/** Creates an optional Redis-backed BullMQ producer/worker integration. */
|
|
31
|
+
static createBullMQQueue(config: IBullMQEmailQueueConfig): BullMQEmailQueue;
|
|
13
32
|
static getInstance(): EmailFactory;
|
|
14
|
-
sendEmail(options: IEmailOptions): Promise<
|
|
33
|
+
sendEmail(options: IEmailOptions): Promise<IEmailSendResult>;
|
|
15
34
|
getTemplateService(): TemplateService;
|
|
16
35
|
getAttachmentService(): AttachmentService;
|
|
36
|
+
/** Verify connectivity when supported by the selected transport; API transports may not provide a safe check. */
|
|
37
|
+
verifyTransport(): Promise<true>;
|
|
38
|
+
/** Release pooled SMTP connections and the template cache cleanup timer. */
|
|
39
|
+
close(): void;
|
|
17
40
|
previewTemplate(themeType: ThemeType, variant: 'light' | 'dark', config: ITemplateConfig, data: any): Promise<string>;
|
|
18
41
|
getThemeInfo(themeType: ThemeType): {
|
|
19
42
|
name: string;
|
|
@@ -27,8 +50,11 @@ export declare class EmailFactory {
|
|
|
27
50
|
totalTemplates: number;
|
|
28
51
|
cachedTemplates: number;
|
|
29
52
|
totalHits: number;
|
|
53
|
+
cacheRequests: number;
|
|
30
54
|
templatesByTheme: Record<ThemeType, number>;
|
|
31
55
|
cacheHitRate: number;
|
|
32
56
|
};
|
|
57
|
+
/** Hashes canonicalized settings so credentials are never exposed in errors/logs. */
|
|
58
|
+
private static fingerprint;
|
|
33
59
|
}
|
|
34
60
|
//# sourceMappingURL=email-factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email-factory.d.ts","sourceRoot":"","sources":["../../src/factories/email-factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"email-factory.d.ts","sourceRoot":"","sources":["../../src/factories/email-factory.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,gBAA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AyB,GAAG,YAAY;IAIpJ,sHAAsH;IACtH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,gBAAgB,EAAE,eAAe,CAAC,EAAE,uBAAuB,EAAE,iBAAiB,CAAC,EAAE,yBAAyB,GAAG,YAAY;IA2BlJ,oEAAoE;IACpE,MAAM,CAAC,mBAAmB,CACxB,SAAS,EAAE,eAAe,EAC1B,WAAW,CAAC,EAAE,MAAM,EACpB,eAAe,CAAC,EAAE,uBAAuB,EACzC,iBAAiB,CAAC,EAAE,yBAAyB,GAC5C,YAAY;IAIf,2EAA2E;IAC3E,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,gBAAgB;IAI3E,MAAM,CAAC,WAAW,IAAI,YAAY;IAO5B,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIlE,kBAAkB,IAAI,eAAe;IAIrC,oBAAoB,IAAI,iBAAiB;IAIzC,iHAAiH;IAC3G,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAItC,4EAA4E;IAC5E,KAAK,IAAI,IAAI;IASP,eAAe,CACnB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,GAAG,MAAM,EACzB,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,MAAM,CAAC;IAIlB,YAAY,CAAC,SAAS,EAAE,SAAS;;;;;;;IAIjC,UAAU;IAIV,gBAAgB;;;;;;;;IAIhB,qFAAqF;IACrF,OAAO,CAAC,MAAM,CAAC,WAAW;CAyB3B"}
|
|
@@ -4,23 +4,83 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.EmailFactory = void 0;
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
const module_1 = require("module");
|
|
7
9
|
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
8
10
|
const email_service_1 = require("../services/email.service");
|
|
9
11
|
const template_service_1 = require("../services/template.service");
|
|
10
12
|
const attachment_service_1 = require("../services/attachment.service");
|
|
13
|
+
const nodemailer_transport_1 = require("../providers/nodemailer.transport");
|
|
14
|
+
const sendgrid_transport_1 = require("../providers/sendgrid.transport");
|
|
15
|
+
const mailgun_transport_1 = require("../providers/mailgun.transport");
|
|
16
|
+
const bullmq_email_queue_1 = require("../queues/bullmq-email-queue");
|
|
17
|
+
const loadOptionalModule = (0, module_1.createRequire)(__filename);
|
|
11
18
|
class EmailFactory {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
static instance;
|
|
20
|
+
static singletonFingerprint;
|
|
21
|
+
emailService;
|
|
22
|
+
templateService;
|
|
23
|
+
attachmentService;
|
|
24
|
+
constructor(transport, defaultFrom, templateOptions, attachmentOptions, errorStage = 'smtp') {
|
|
25
|
+
this.emailService = new email_service_1.EmailService(transport, defaultFrom, errorStage);
|
|
15
26
|
this.templateService = new template_service_1.TemplateService(templateOptions);
|
|
16
|
-
this.attachmentService = new attachment_service_1.AttachmentService();
|
|
27
|
+
this.attachmentService = new attachment_service_1.AttachmentService(attachmentOptions);
|
|
17
28
|
}
|
|
18
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Returns the process singleton. A later call with different settings fails
|
|
31
|
+
* explicitly rather than silently continuing with the first configuration.
|
|
32
|
+
*/
|
|
33
|
+
static initialize(config, templateOptions, attachmentOptions) {
|
|
34
|
+
const fingerprint = this.fingerprint(config, templateOptions, attachmentOptions);
|
|
19
35
|
if (!this.instance) {
|
|
20
|
-
this.instance = new EmailFactory(config, templateOptions);
|
|
36
|
+
this.instance = new EmailFactory(new nodemailer_transport_1.NodemailerTransport(nodemailer_1.default.createTransport(config)), config.defaultFrom, templateOptions, attachmentOptions);
|
|
37
|
+
this.singletonFingerprint = fingerprint;
|
|
38
|
+
}
|
|
39
|
+
else if (this.singletonFingerprint !== fingerprint) {
|
|
40
|
+
throw new Error('EmailFactory is already initialized with a different configuration; use EmailFactory.create() for an independent instance.');
|
|
21
41
|
}
|
|
22
42
|
return this.instance;
|
|
23
43
|
}
|
|
44
|
+
/** Creates an independent factory instance without changing the singleton. */
|
|
45
|
+
static create(config, templateOptions, attachmentOptions) {
|
|
46
|
+
return new EmailFactory(new nodemailer_transport_1.NodemailerTransport(nodemailer_1.default.createTransport(config)), config.defaultFrom, templateOptions, attachmentOptions);
|
|
47
|
+
}
|
|
48
|
+
/** Creates an independent SendGrid Web API v3 client; no provider state is shared between instances. */
|
|
49
|
+
static createSendGrid(config, templateOptions, attachmentOptions) {
|
|
50
|
+
return new EmailFactory(new sendgrid_transport_1.SendGridTransport(config), config.defaultFrom, templateOptions, attachmentOptions, 'provider');
|
|
51
|
+
}
|
|
52
|
+
/** Creates an independent Mailgun Messages API client. */
|
|
53
|
+
static createMailgun(config, templateOptions, attachmentOptions) {
|
|
54
|
+
return new EmailFactory(new mailgun_transport_1.MailgunTransport(config), config.defaultFrom, templateOptions, attachmentOptions, 'provider');
|
|
55
|
+
}
|
|
56
|
+
/** Creates an Amazon SES v2 transport using the AWS SDK credential provider chain unless credentials are supplied. */
|
|
57
|
+
static createSES(config, templateOptions, attachmentOptions) {
|
|
58
|
+
if (!config.region.trim())
|
|
59
|
+
throw new Error('Amazon SES region is required');
|
|
60
|
+
let awsSes;
|
|
61
|
+
try {
|
|
62
|
+
awsSes = loadOptionalModule('@aws-sdk/client-sesv2');
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
throw new Error('Amazon SES support requires optional package @aws-sdk/client-sesv2. Install it with: npm install @aws-sdk/client-sesv2', { cause: error });
|
|
66
|
+
}
|
|
67
|
+
const sesClient = new awsSes.SESv2Client({
|
|
68
|
+
region: config.region,
|
|
69
|
+
...(config.credentials ? { credentials: config.credentials } : {})
|
|
70
|
+
});
|
|
71
|
+
const transporter = nodemailer_1.default.createTransport({
|
|
72
|
+
SES: { sesClient, SendEmailCommand: awsSes.SendEmailCommand }
|
|
73
|
+
});
|
|
74
|
+
return new EmailFactory(new nodemailer_transport_1.NodemailerTransport(transporter, () => sesClient.destroy?.()), config.defaultFrom, templateOptions, attachmentOptions, 'provider');
|
|
75
|
+
}
|
|
76
|
+
/** Creates an instance around a user-supplied transport adapter. */
|
|
77
|
+
static createWithTransport(transport, defaultFrom, templateOptions, attachmentOptions) {
|
|
78
|
+
return new EmailFactory(transport, defaultFrom, templateOptions, attachmentOptions, 'provider');
|
|
79
|
+
}
|
|
80
|
+
/** Creates an optional Redis-backed BullMQ producer/worker integration. */
|
|
81
|
+
static createBullMQQueue(config) {
|
|
82
|
+
return new bullmq_email_queue_1.BullMQEmailQueue(config);
|
|
83
|
+
}
|
|
24
84
|
static getInstance() {
|
|
25
85
|
if (!this.instance) {
|
|
26
86
|
throw new Error('EmailFactory not initialized. Call initialize() first.');
|
|
@@ -36,6 +96,19 @@ class EmailFactory {
|
|
|
36
96
|
getAttachmentService() {
|
|
37
97
|
return this.attachmentService;
|
|
38
98
|
}
|
|
99
|
+
/** Verify connectivity when supported by the selected transport; API transports may not provide a safe check. */
|
|
100
|
+
async verifyTransport() {
|
|
101
|
+
return this.emailService.verify();
|
|
102
|
+
}
|
|
103
|
+
/** Release pooled SMTP connections and the template cache cleanup timer. */
|
|
104
|
+
close() {
|
|
105
|
+
this.emailService.close();
|
|
106
|
+
this.templateService.dispose();
|
|
107
|
+
if (EmailFactory.instance === this) {
|
|
108
|
+
EmailFactory.instance = undefined;
|
|
109
|
+
EmailFactory.singletonFingerprint = undefined;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
39
112
|
async previewTemplate(themeType, variant, config, data) {
|
|
40
113
|
return this.templateService.previewTemplate(themeType, variant, config, data);
|
|
41
114
|
}
|
|
@@ -48,5 +121,36 @@ class EmailFactory {
|
|
|
48
121
|
getTemplateStats() {
|
|
49
122
|
return this.templateService.getTemplateStats();
|
|
50
123
|
}
|
|
124
|
+
/** Hashes canonicalized settings so credentials are never exposed in errors/logs. */
|
|
125
|
+
static fingerprint(config, templateOptions, attachmentOptions) {
|
|
126
|
+
const canonicalize = (value, ancestors = new Set()) => {
|
|
127
|
+
if (value === undefined)
|
|
128
|
+
return 'undefined';
|
|
129
|
+
if (value === null || typeof value !== 'object') {
|
|
130
|
+
if (typeof value === 'function')
|
|
131
|
+
return `function:${value.toString()}`;
|
|
132
|
+
if (typeof value === 'bigint')
|
|
133
|
+
return `bigint:${value.toString()}`;
|
|
134
|
+
return JSON.stringify(value) ?? String(value);
|
|
135
|
+
}
|
|
136
|
+
if (ancestors.has(value))
|
|
137
|
+
return '[Circular]';
|
|
138
|
+
ancestors.add(value);
|
|
139
|
+
let result;
|
|
140
|
+
if (Array.isArray(value)) {
|
|
141
|
+
result = `[${value.map((item) => canonicalize(item, ancestors)).join(',')}]`;
|
|
142
|
+
}
|
|
143
|
+
else if (value instanceof Date) {
|
|
144
|
+
result = `date:${value.toISOString()}`;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
result = `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonicalize(value[key], ancestors)}`).join(',')}}`;
|
|
148
|
+
}
|
|
149
|
+
ancestors.delete(value);
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
const serialized = `${canonicalize(config)}|${canonicalize(templateOptions)}|${canonicalize(attachmentOptions)}`;
|
|
153
|
+
return (0, crypto_1.createHash)('sha256').update(serialized).digest('hex');
|
|
154
|
+
}
|
|
51
155
|
}
|
|
52
156
|
exports.EmailFactory = EmailFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template-factory.d.ts","sourceRoot":"","sources":["../../src/factories/template-factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"template-factory.d.ts","sourceRoot":"","sources":["../../src/factories/template-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AA0F7D,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,CAgBlB;IAEH,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,SAAS;IAgE1G,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IACzD,MAAM,CAAC,UAAU,IAAI,SAAS,EAAE;IAEhC,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE;CAsBrG"}
|