@yimingliao/cms 0.0.46 → 0.0.47
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/dist/server/index.js +28 -21
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -244,7 +244,7 @@ var normalizeCacheKey = (key, delimiter = CACHE_KEY_DELIMITER) => {
|
|
|
244
244
|
|
|
245
245
|
// src/server/infrastructure/cache/create-cache-result.ts
|
|
246
246
|
var DAY = 1e3 * 60 * 60 * 24;
|
|
247
|
-
function createCacheResult(
|
|
247
|
+
function createCacheResult(cache2, logger) {
|
|
248
248
|
return async function cacheResult({
|
|
249
249
|
key: rawKey,
|
|
250
250
|
ttl = DAY,
|
|
@@ -259,13 +259,13 @@ function createCacheResult(cache, logger) {
|
|
|
259
259
|
return load();
|
|
260
260
|
}
|
|
261
261
|
try {
|
|
262
|
-
const cached = await
|
|
262
|
+
const cached = await cache2.get(key);
|
|
263
263
|
if (cached !== void 0) {
|
|
264
264
|
return cached;
|
|
265
265
|
}
|
|
266
266
|
const data = await load();
|
|
267
267
|
if (data !== void 0) {
|
|
268
|
-
await
|
|
268
|
+
await cache2.set(key, data, ttl);
|
|
269
269
|
}
|
|
270
270
|
return data;
|
|
271
271
|
} catch (error) {
|
|
@@ -287,13 +287,13 @@ var lua = `
|
|
|
287
287
|
end
|
|
288
288
|
return current
|
|
289
289
|
`;
|
|
290
|
-
function createIpRateLimiter(
|
|
290
|
+
function createIpRateLimiter(cache2, appName) {
|
|
291
291
|
return async function ipRateLimiter({
|
|
292
292
|
key: rawKey,
|
|
293
293
|
maxAttempts = DEFAULT_MAX_ATTEMPTS,
|
|
294
294
|
timeWindow = DEFAULT_TIME_WINDOW
|
|
295
295
|
}) {
|
|
296
|
-
const secondaryStore =
|
|
296
|
+
const secondaryStore = cache2.store;
|
|
297
297
|
const redis = await secondaryStore.getClient();
|
|
298
298
|
if (!redis) return true;
|
|
299
299
|
const headersStore = await headers();
|
|
@@ -643,23 +643,29 @@ function createSendEmail({
|
|
|
643
643
|
}
|
|
644
644
|
var TEMPLATE_DIR = path.resolve(process.cwd(), "emails");
|
|
645
645
|
var LAYOUT_PATH = path.join(TEMPLATE_DIR, "layout.html");
|
|
646
|
-
var
|
|
646
|
+
var isDev = process.env.NODE_ENV !== "production";
|
|
647
|
+
var cache = /* @__PURE__ */ new Map();
|
|
647
648
|
async function readTemplate(filePath) {
|
|
648
|
-
if (
|
|
649
|
+
if (!isDev && cache.has(filePath)) {
|
|
650
|
+
return cache.get(filePath);
|
|
651
|
+
}
|
|
649
652
|
try {
|
|
650
653
|
const html = await readFile(filePath, "utf8");
|
|
651
|
-
|
|
654
|
+
if (!isDev) cache.set(filePath, html);
|
|
652
655
|
return html;
|
|
653
656
|
} catch (error) {
|
|
654
657
|
throw new Error(`Email template file not found: ${filePath}`);
|
|
655
658
|
}
|
|
656
659
|
}
|
|
657
|
-
function applyReplacements(html, replacements) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
660
|
+
function applyReplacements(html, replacements, logger) {
|
|
661
|
+
return html.replace(/\{\{\{(.*?)\}\}\}/g, (_, key) => {
|
|
662
|
+
const value = replacements[key];
|
|
663
|
+
if (value == null) {
|
|
664
|
+
logger?.warn({ msg: "Email template variable missing", variable: key });
|
|
665
|
+
return "";
|
|
666
|
+
}
|
|
667
|
+
return value;
|
|
668
|
+
});
|
|
663
669
|
}
|
|
664
670
|
function createRenderEmailTemplate({
|
|
665
671
|
storageUrl,
|
|
@@ -670,17 +676,18 @@ function createRenderEmailTemplate({
|
|
|
670
676
|
const contentPath = path.join(TEMPLATE_DIR, `${templateKey}.html`);
|
|
671
677
|
const layoutHtml = await readTemplate(LAYOUT_PATH);
|
|
672
678
|
let contentHtml = await readTemplate(contentPath);
|
|
673
|
-
contentHtml = applyReplacements(
|
|
674
|
-
|
|
675
|
-
...replacements
|
|
676
|
-
|
|
679
|
+
contentHtml = applyReplacements(
|
|
680
|
+
contentHtml,
|
|
681
|
+
{ STORAGE_URL: storageUrl, ...replacements },
|
|
682
|
+
logger
|
|
683
|
+
);
|
|
677
684
|
return layoutHtml.replaceAll("{{{content}}}", contentHtml);
|
|
678
685
|
} catch (error) {
|
|
679
686
|
logger.error({
|
|
680
687
|
msg: "Email template render failed",
|
|
681
688
|
templateKey,
|
|
682
689
|
templateDir: TEMPLATE_DIR,
|
|
683
|
-
error
|
|
690
|
+
error: error instanceof Error ? error.stack : error
|
|
684
691
|
});
|
|
685
692
|
throw new Error(`Email template error: ${templateKey}`);
|
|
686
693
|
}
|
|
@@ -1853,7 +1860,7 @@ var normalizeError = (error, translator) => {
|
|
|
1853
1860
|
function createExecuteAction({
|
|
1854
1861
|
initI18n,
|
|
1855
1862
|
cacheResult,
|
|
1856
|
-
cache,
|
|
1863
|
+
cache: cache2,
|
|
1857
1864
|
logger
|
|
1858
1865
|
}) {
|
|
1859
1866
|
return async function executeAction(fn, options = {}) {
|
|
@@ -1865,7 +1872,7 @@ function createExecuteAction({
|
|
|
1865
1872
|
...options.ttl ? { ttl: options.ttl } : {},
|
|
1866
1873
|
load: async () => fn(translator)
|
|
1867
1874
|
}) : await fn(translator);
|
|
1868
|
-
if (options.type === "command")
|
|
1875
|
+
if (options.type === "command") cache2.clear();
|
|
1869
1876
|
const finalMessage = i18nKey ? translator.t(i18nKey) : message;
|
|
1870
1877
|
return result.success({
|
|
1871
1878
|
...finalMessage ? { message: finalMessage } : {},
|