ztechno_core 0.0.75 → 0.0.77
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/lib/mail_service.d.ts +8 -8
- package/lib/mail_service.js +17 -17
- package/lib/typings/mail_types.d.ts +1 -0
- package/package.json +1 -1
package/lib/mail_service.d.ts
CHANGED
|
@@ -16,6 +16,14 @@ export declare class ZMailService {
|
|
|
16
16
|
* @param opt - Configuration options for the mail service including authentication, sender email, and SQL service
|
|
17
17
|
*/
|
|
18
18
|
constructor(opt: MailServiceOptions);
|
|
19
|
+
/**
|
|
20
|
+
* Fetches the content of a template file from the filesystem
|
|
21
|
+
* @param template - Path to the template file to read
|
|
22
|
+
* @returns Promise that resolves to the template content as a string
|
|
23
|
+
* @throws Will throw an error if the file cannot be read
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
private fetchTemplate;
|
|
19
27
|
/**
|
|
20
28
|
* Checks if an email is allowed to be sent by verifying it's not blacklisted
|
|
21
29
|
* @param mailOpts - Mail options containing the recipient email to check
|
|
@@ -53,14 +61,6 @@ export declare class ZMailService {
|
|
|
53
61
|
* @returns Promise that resolves to mail response
|
|
54
62
|
*/
|
|
55
63
|
sendAdvanced(mailOpts: ZMailSendOptTemplate): Promise<any>;
|
|
56
|
-
/**
|
|
57
|
-
* Fetches the content of a template file from the filesystem
|
|
58
|
-
* @param template - Path to the template file to read
|
|
59
|
-
* @returns Promise that resolves to the template content as a string
|
|
60
|
-
* @throws Will throw an error if the file cannot be read
|
|
61
|
-
* @private
|
|
62
|
-
*/
|
|
63
|
-
private fetchTemplate;
|
|
64
64
|
/**
|
|
65
65
|
* Injects variables into a body string by replacing placeholder tokens
|
|
66
66
|
* @param body - The string content where variables should be injected
|
package/lib/mail_service.js
CHANGED
|
@@ -22,6 +22,23 @@ class ZMailService {
|
|
|
22
22
|
constructor(opt) {
|
|
23
23
|
this.opt = opt;
|
|
24
24
|
this.blacklistOrm = new mail_blacklist_orm_1.ZMailBlacklistOrm(opt);
|
|
25
|
+
this.opt.dirTemplate = path_1.default.isAbsolute(this.opt.dirTemplate || '')
|
|
26
|
+
? this.opt.dirTemplate
|
|
27
|
+
: path_1.default.join(process.cwd(), this.opt.dirTemplate || '');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Fetches the content of a template file from the filesystem
|
|
31
|
+
* @param template - Path to the template file to read
|
|
32
|
+
* @returns Promise that resolves to the template content as a string
|
|
33
|
+
* @throws Will throw an error if the file cannot be read
|
|
34
|
+
* @private
|
|
35
|
+
*/
|
|
36
|
+
async fetchTemplate(template) {
|
|
37
|
+
const filepath = path_1.default.join(this.opt.dirTemplate, template);
|
|
38
|
+
if (fs_1.default.existsSync(filepath)) {
|
|
39
|
+
return await promises_1.default.readFile(filepath, { encoding: 'utf-8' });
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Template file not found: ${filepath}`);
|
|
25
42
|
}
|
|
26
43
|
/**
|
|
27
44
|
* Checks if an email is allowed to be sent by verifying it's not blacklisted
|
|
@@ -93,23 +110,6 @@ class ZMailService {
|
|
|
93
110
|
}
|
|
94
111
|
return await this.send(opts);
|
|
95
112
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Fetches the content of a template file from the filesystem
|
|
98
|
-
* @param template - Path to the template file to read
|
|
99
|
-
* @returns Promise that resolves to the template content as a string
|
|
100
|
-
* @throws Will throw an error if the file cannot be read
|
|
101
|
-
* @private
|
|
102
|
-
*/
|
|
103
|
-
async fetchTemplate(template) {
|
|
104
|
-
if (fs_1.default.existsSync(template)) {
|
|
105
|
-
return await promises_1.default.readFile(template, { encoding: 'utf-8' });
|
|
106
|
-
}
|
|
107
|
-
const altPath = path_1.default.join(process.cwd(), template);
|
|
108
|
-
if (fs_1.default.existsSync(altPath)) {
|
|
109
|
-
return await promises_1.default.readFile(altPath, { encoding: 'utf-8' });
|
|
110
|
-
}
|
|
111
|
-
throw new Error(`Template file not found: ${template} altPath also not found: ${altPath}`);
|
|
112
|
-
}
|
|
113
113
|
/**
|
|
114
114
|
* Injects variables into a body string by replacing placeholder tokens
|
|
115
115
|
* @param body - The string content where variables should be injected
|