@maioradv/nestjs-core 2.1.4 → 2.1.6
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.
|
@@ -7,9 +7,6 @@ exports.EmailBuilder = void 0;
|
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
9
9
|
const promises_1 = require("fs/promises");
|
|
10
|
-
function getNestedValue(obj, path) {
|
|
11
|
-
return path.split('.').reduce((acc, key) => acc?.[key], obj) ?? path;
|
|
12
|
-
}
|
|
13
10
|
class EmailBuilder {
|
|
14
11
|
constructor() {
|
|
15
12
|
this.basePath = (0, path_1.join)(process.cwd(), 'templates', 'email');
|
|
@@ -56,10 +53,13 @@ class EmailBuilder {
|
|
|
56
53
|
if (missing.length > 0)
|
|
57
54
|
throw new Error(`Missing paths: ${missing.join()}`);
|
|
58
55
|
}
|
|
56
|
+
getNestedValue(obj, path) {
|
|
57
|
+
return path.split('.').reduce((acc, key) => acc?.[key], obj) ?? path;
|
|
58
|
+
}
|
|
59
59
|
async initEmail() {
|
|
60
60
|
const [Container, Header, Footer, Body, Labels] = await Promise.all(this.paths().map(path => (0, promises_1.readFile)(path, 'utf-8')));
|
|
61
61
|
const labels = JSON.parse(Labels);
|
|
62
|
-
const subject = getNestedValue(labels, `${this.pattern}.subject`);
|
|
62
|
+
const subject = this.getNestedValue(labels, `${this.pattern}.subject`);
|
|
63
63
|
handlebars_1.default.registerHelper('fullDateTime', function (date, locale) {
|
|
64
64
|
return new Date(date).toLocaleString(locale, { dateStyle: 'full', timeStyle: 'short' });
|
|
65
65
|
});
|
|
@@ -67,7 +67,7 @@ class EmailBuilder {
|
|
|
67
67
|
return condition ? valTrue : valFalse;
|
|
68
68
|
});
|
|
69
69
|
handlebars_1.default.registerHelper('t', (key, options) => {
|
|
70
|
-
const template = getNestedValue(labels, key);
|
|
70
|
+
const template = this.getNestedValue(labels, key);
|
|
71
71
|
if (options.hash && Object.keys(options.hash).length > 0) {
|
|
72
72
|
return template.replace(/\{\{(\w+)\}\}/g, (_, k) => options.hash[k] ?? `{{${k}}}`);
|
|
73
73
|
}
|
|
@@ -85,7 +85,7 @@ class EmailBuilder {
|
|
|
85
85
|
async build(args) {
|
|
86
86
|
const { subject, template } = await this.initEmail();
|
|
87
87
|
return {
|
|
88
|
-
subject
|
|
88
|
+
subject,
|
|
89
89
|
html: template({
|
|
90
90
|
...args,
|
|
91
91
|
locale: this.locale
|