ztechno_core 0.0.72 → 0.0.75
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.js +13 -2
- package/package.json +1 -1
package/lib/mail_service.js
CHANGED
|
@@ -7,7 +7,9 @@ var __importDefault =
|
|
|
7
7
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
8
8
|
exports.ZMailService = void 0;
|
|
9
9
|
const nodemailer_1 = __importDefault(require('nodemailer'));
|
|
10
|
+
const fs_1 = __importDefault(require('fs'));
|
|
10
11
|
const promises_1 = __importDefault(require('fs/promises'));
|
|
12
|
+
const path_1 = __importDefault(require('path'));
|
|
11
13
|
const mail_blacklist_orm_1 = require('./orm/mail_blacklist_orm');
|
|
12
14
|
class ZMailService {
|
|
13
15
|
get sql() {
|
|
@@ -99,7 +101,14 @@ class ZMailService {
|
|
|
99
101
|
* @private
|
|
100
102
|
*/
|
|
101
103
|
async fetchTemplate(template) {
|
|
102
|
-
|
|
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}`);
|
|
103
112
|
}
|
|
104
113
|
/**
|
|
105
114
|
* Injects variables into a body string by replacing placeholder tokens
|
|
@@ -114,7 +123,9 @@ class ZMailService {
|
|
|
114
123
|
* @private
|
|
115
124
|
*/
|
|
116
125
|
async inject(body, inject) {
|
|
117
|
-
|
|
126
|
+
// Sort variable names by length (longest first) to prevent partial matches
|
|
127
|
+
const sortedKeys = Object.keys(inject ?? {}).sort((a, b) => b.length - a.length);
|
|
128
|
+
sortedKeys.forEach((variableName) => {
|
|
118
129
|
const key = `:${variableName}`;
|
|
119
130
|
while (body.indexOf(key) !== -1) {
|
|
120
131
|
body = body.replace(key, inject[variableName].toString());
|