anote-server-libs 0.11.3 → 0.11.5
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.
|
@@ -57,7 +57,7 @@ END`)
|
|
|
57
57
|
if (migrations.find(migration => migration.state !== 0))
|
|
58
58
|
process.exit(4);
|
|
59
59
|
fs.readdir(migrationsPath, (_, files) => {
|
|
60
|
-
|
|
60
|
+
let migrationsAvailable = files
|
|
61
61
|
.filter(file => /[0-9]+\.sql/.test(file))
|
|
62
62
|
.map(file => parseInt(file.split('.sql')[0], 10))
|
|
63
63
|
.filter(file => file > 0)
|
|
@@ -73,15 +73,19 @@ END`)
|
|
|
73
73
|
const minAvailableId = migrationsAvailable.length > 0 ? migrationsAvailable[0].id : 0;
|
|
74
74
|
const maxAvailableId = migrationsAvailable.length > 0 ? migrationsAvailable[migrationsAvailable.length - 1].id : Infinity;
|
|
75
75
|
migrations = migrations.filter(m => m.id >= minAvailableId && m.id <= maxAvailableId);
|
|
76
|
-
if (onlyAboveOrEquals)
|
|
76
|
+
if (onlyAboveOrEquals) {
|
|
77
77
|
migrations = migrations.filter(m => m.id >= onlyAboveOrEquals);
|
|
78
|
-
|
|
78
|
+
migrationsAvailable = migrationsAvailable.filter(m => m.id >= onlyAboveOrEquals);
|
|
79
|
+
}
|
|
80
|
+
if (onlyBelow) {
|
|
79
81
|
migrations = migrations.filter(m => m.id < onlyBelow);
|
|
82
|
+
migrationsAvailable = migrationsAvailable.filter(m => m.id < onlyBelow);
|
|
83
|
+
}
|
|
80
84
|
if (migrationsAvailable.length === 0 && migrations.length === 0)
|
|
81
85
|
process.exit(5);
|
|
82
86
|
if (migrationsAvailable.length && migrationsAvailable.length !== (migrationsAvailable[migrationsAvailable.length - 1].id - migrationsAvailable[0].id + 1))
|
|
83
87
|
process.exit(5);
|
|
84
|
-
let highestCommon =
|
|
88
|
+
let highestCommon = 0;
|
|
85
89
|
while (highestCommon < migrations.length && highestCommon < migrationsAvailable.length
|
|
86
90
|
&& migrations[highestCommon].hash === migrationsAvailable[highestCommon].hash)
|
|
87
91
|
highestCommon++;
|
|
@@ -58,7 +58,7 @@ END`)])).then(() => {
|
|
|
58
58
|
if(migrations.find(migration => migration.state !== 0)) process.exit(4); // Have to fix manually
|
|
59
59
|
// Read the new ones
|
|
60
60
|
fs.readdir(migrationsPath, (_, files) => {
|
|
61
|
-
|
|
61
|
+
let migrationsAvailable = files
|
|
62
62
|
.filter(file => /[0-9]+\.sql/.test(file))
|
|
63
63
|
.map(file => parseInt(file.split('.sql')[0], 10))
|
|
64
64
|
.filter(file => file > 0)
|
|
@@ -74,11 +74,11 @@ END`)])).then(() => {
|
|
|
74
74
|
const minAvailableId = migrationsAvailable.length > 0 ? migrationsAvailable[0].id : 0;
|
|
75
75
|
const maxAvailableId = migrationsAvailable.length > 0 ? migrationsAvailable[migrationsAvailable.length - 1].id : Infinity;
|
|
76
76
|
migrations = migrations.filter(m => m.id >= minAvailableId && m.id <= maxAvailableId);
|
|
77
|
-
if(onlyAboveOrEquals) migrations = migrations.filter(m => m.id >= onlyAboveOrEquals);
|
|
78
|
-
if(onlyBelow) migrations = migrations.filter(m => m.id < onlyBelow);
|
|
77
|
+
if(onlyAboveOrEquals) { migrations = migrations.filter(m => m.id >= onlyAboveOrEquals); migrationsAvailable = migrationsAvailable.filter(m => m.id >= onlyAboveOrEquals); }
|
|
78
|
+
if(onlyBelow) { migrations = migrations.filter(m => m.id < onlyBelow); migrationsAvailable = migrationsAvailable.filter(m => m.id < onlyBelow); }
|
|
79
79
|
if(migrationsAvailable.length === 0 && migrations.length === 0) process.exit(5);
|
|
80
80
|
if(migrationsAvailable.length && migrationsAvailable.length !== (migrationsAvailable[migrationsAvailable.length - 1].id - migrationsAvailable[0].id + 1)) process.exit(5);
|
|
81
|
-
let highestCommon =
|
|
81
|
+
let highestCommon = 0;
|
|
82
82
|
while(highestCommon < migrations.length && highestCommon < migrationsAvailable.length
|
|
83
83
|
&& migrations[highestCommon].hash === migrationsAvailable[highestCommon].hash)
|
|
84
84
|
highestCommon++;
|
package/package.json
CHANGED
package/services/utils.js
CHANGED
|
@@ -15,7 +15,6 @@ exports.readEmailTemplates = readEmailTemplates;
|
|
|
15
15
|
exports.replacePlaceholders = replacePlaceholders;
|
|
16
16
|
exports.getHtmlReplaced = getHtmlReplaced;
|
|
17
17
|
exports.getEmailTitle = getEmailTitle;
|
|
18
|
-
exports.getEmailTranslation = getEmailTranslation;
|
|
19
18
|
const fs = require("fs");
|
|
20
19
|
function atob(str) {
|
|
21
20
|
return Buffer.from(str, 'base64').toString('binary');
|
|
@@ -238,6 +237,7 @@ function getHtml(template, translationKeyValue) {
|
|
|
238
237
|
const replacer = (_, key) => replacePlaceholders(translationKeyValue, key.split('.'), 0) ?? '';
|
|
239
238
|
template = template.replace(pattern, replacer);
|
|
240
239
|
template = template.replace(pattern, replacer);
|
|
240
|
+
template = template.replace(pattern, replacer);
|
|
241
241
|
template = template.replace(new RegExp('\\[\\[\\s*([a-zA-Z._0-9:]+)\\s*\\]\\]', 'g'), (_, key) => {
|
|
242
242
|
const keyParts = key.split(':');
|
|
243
243
|
return (replacePlaceholders(translationKeyValue, keyParts[1].split('.'), 0) || [])
|
|
@@ -251,14 +251,14 @@ function getHtml(template, translationKeyValue) {
|
|
|
251
251
|
});
|
|
252
252
|
return template;
|
|
253
253
|
}
|
|
254
|
-
function getHtmlReplaced(config, templates, key, lang, defaultTemplateTranslations = {}, envSpecificTranslations, extraData, newPage) {
|
|
255
|
-
const name = config.app.name;
|
|
254
|
+
function getHtmlReplaced(config, templates, key, lang, defaultTemplateTranslations = {}, projectSpecificTranslations = {}, envSpecificTranslations, extraData, newPage) {
|
|
256
255
|
const defaultTranslations = defaultTemplateTranslations?.[lang] || defaultTemplateTranslations?.[0] || {};
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
const projectSpecificTrans = projectSpecificTranslations?.[config.app.product]?.[lang]?.[key] || projectSpecificTranslations?.[config.app.name]?.[0]?.[key] || {};
|
|
257
|
+
const envSpecificTrans = envSpecificTranslations?.[config.app.name]?.[lang]?.[key] || envSpecificTranslations?.[config.app.name]?.[0]?.[key] || {};
|
|
258
|
+
extraData = Object.fromEntries(Object.entries(extraData || {}).map(([k, v]) => [k, `{{${v}}}`]));
|
|
260
259
|
const translationKeyValue = {
|
|
261
260
|
...defaultTranslations,
|
|
261
|
+
...projectSpecificTrans,
|
|
262
262
|
...envSpecificTrans,
|
|
263
263
|
...extraData,
|
|
264
264
|
domain: config.frontend,
|
|
@@ -279,11 +279,10 @@ function getHtmlReplaced(config, templates, key, lang, defaultTemplateTranslatio
|
|
|
279
279
|
}
|
|
280
280
|
return html;
|
|
281
281
|
}
|
|
282
|
-
function getEmailTitle(key, lang,
|
|
282
|
+
function getEmailTitle(config, key, lang, defaultTitles = {}, projectSpecificTitles = {}, envSpecificTitles = {}, extraData = {}) {
|
|
283
283
|
const pattern = new RegExp('{{\\s*([a-zA-Z._0-9]+)\\s*}}', 'g');
|
|
284
|
-
const title =
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return translationKeyValue?.[lang]?.[key] ?? translationKeyValue?.[defaultLang]?.[key];
|
|
284
|
+
const title = envSpecificTitles?.[config.app.name]?.[lang]?.[key]
|
|
285
|
+
|| projectSpecificTitles?.[config.app.product]?.[lang]?.[key]
|
|
286
|
+
|| defaultTitles?.[lang]?.[key];
|
|
287
|
+
return title?.replace(pattern, (_, placeholderKey) => extraData?.[placeholderKey] || config.app.emailConfig?.[placeholderKey] || placeholderKey);
|
|
289
288
|
}
|
package/services/utils.ts
CHANGED
|
@@ -215,6 +215,7 @@ function getHtml(template: string, translationKeyValue: Record<string, any>): st
|
|
|
215
215
|
const replacer = (_: string, key: string) => replacePlaceholders(translationKeyValue, key.split('.'), 0) ?? '';
|
|
216
216
|
template = template.replace(pattern, replacer);
|
|
217
217
|
template = template.replace(pattern, replacer);
|
|
218
|
+
template = template.replace(pattern, replacer);
|
|
218
219
|
template = template.replace(new RegExp('\\[\\[\\s*([a-zA-Z._0-9:]+)\\s*\\]\\]', 'g'), (_, key) => {
|
|
219
220
|
const keyParts = key.split(':');
|
|
220
221
|
return (replacePlaceholders(translationKeyValue, keyParts[1].split('.'), 0) || [])
|
|
@@ -229,14 +230,22 @@ function getHtml(template: string, translationKeyValue: Record<string, any>): st
|
|
|
229
230
|
return template;
|
|
230
231
|
}
|
|
231
232
|
|
|
232
|
-
export function getHtmlReplaced(config:
|
|
233
|
-
|
|
233
|
+
export function getHtmlReplaced(config: {frontend: string, app: {product: string, name: string, emailConfig: Record<string, any>}},
|
|
234
|
+
templates: Record<string, string>,
|
|
235
|
+
key: string, lang: number,
|
|
236
|
+
defaultTemplateTranslations: Record<number, {[key: string]: string}> = {},
|
|
237
|
+
projectSpecificTranslations: Record<string, Record<number, {[key: string]: string}>> = {},
|
|
238
|
+
envSpecificTranslations?: Record<string, Record<number, {[key: string]: string}>>,
|
|
239
|
+
extraData?: Record<string, any>,
|
|
240
|
+
newPage?: boolean): string {
|
|
234
241
|
const defaultTranslations = defaultTemplateTranslations?.[lang] || defaultTemplateTranslations?.[0] || {};
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
242
|
+
const projectSpecificTrans = projectSpecificTranslations?.[config.app.product]?.[lang]?.[key] || projectSpecificTranslations?.[config.app.name]?.[0]?.[key] || {};
|
|
243
|
+
const envSpecificTrans = envSpecificTranslations?.[config.app.name]?.[lang]?.[key] || envSpecificTranslations?.[config.app.name]?.[0]?.[key] || {};
|
|
244
|
+
// Add {{}} around all extraData values so that they will be auto translated in the template if needed
|
|
245
|
+
extraData = Object.fromEntries(Object.entries(extraData || {}).map(([k, v]) => [k, `{{${v}}}`]));
|
|
238
246
|
const translationKeyValue = {
|
|
239
247
|
...defaultTranslations,
|
|
248
|
+
...projectSpecificTrans,
|
|
240
249
|
...envSpecificTrans,
|
|
241
250
|
...extraData,
|
|
242
251
|
domain: config.frontend,
|
|
@@ -258,12 +267,15 @@ export function getHtmlReplaced(config: Record<string, any>, templates: Record<s
|
|
|
258
267
|
return html;
|
|
259
268
|
}
|
|
260
269
|
|
|
261
|
-
export function getEmailTitle(
|
|
270
|
+
export function getEmailTitle(config: {frontend: string, app: {product: string, name: string, emailConfig: Record<string, any>}},
|
|
271
|
+
key: string, lang: number,
|
|
272
|
+
defaultTitles: Record<number, {[key: string]: string}> = {},
|
|
273
|
+
projectSpecificTitles: Record<string, Record<number, {[key: string]: string}>> = {},
|
|
274
|
+
envSpecificTitles: Record<string, Record<number, {[key: string]: string}>> = {},
|
|
275
|
+
extraData: Record<string, string> = {}): string | undefined {
|
|
262
276
|
const pattern = new RegExp('{{\\s*([a-zA-Z._0-9]+)\\s*}}', 'g');
|
|
263
|
-
const title =
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
export function getEmailTranslation(key: string, lang: number, translationKeyValue: Record<number, any>, defaultLang: number = 0): string | undefined {
|
|
268
|
-
return translationKeyValue?.[lang]?.[key] ?? translationKeyValue?.[defaultLang]?.[key];
|
|
277
|
+
const title = envSpecificTitles?.[config.app.name]?.[lang]?.[key]
|
|
278
|
+
|| projectSpecificTitles?.[config.app.product]?.[lang]?.[key]
|
|
279
|
+
|| defaultTitles?.[lang]?.[key];
|
|
280
|
+
return title?.replace(pattern, (_: string, placeholderKey: string) => extraData?.[placeholderKey] || config.app.emailConfig?.[placeholderKey] || placeholderKey);
|
|
269
281
|
}
|