@contentgrowth/content-emailing 0.7.6 → 0.7.7
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/backend/EmailService.cjs +19 -0
- package/dist/backend/EmailService.cjs.map +1 -1
- package/dist/backend/EmailService.d.cts +2 -0
- package/dist/backend/EmailService.d.ts +2 -0
- package/dist/backend/EmailService.js +19 -0
- package/dist/backend/EmailService.js.map +1 -1
- package/dist/backend/index.cjs +88 -38
- package/dist/backend/index.cjs.map +1 -1
- package/dist/backend/index.d.cts +1 -0
- package/dist/backend/index.d.ts +1 -0
- package/dist/backend/index.js +88 -38
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/routes/index.cjs +94 -12
- package/dist/backend/routes/index.cjs.map +1 -1
- package/dist/backend/routes/index.d.cts +14 -1
- package/dist/backend/routes/index.d.ts +14 -1
- package/dist/backend/routes/index.js +93 -12
- package/dist/backend/routes/index.js.map +1 -1
- package/dist/index.cjs +88 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +88 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -6,3 +6,4 @@ export { createEmailRoutes, createTemplateRoutes, createTrackingRoutes } from '.
|
|
|
6
6
|
export { encodeTrackingLinks, extractVariables, getWebsiteUrl, markdownToPlainText, resetWebsiteUrlCache, wrapInEmailTemplate } from './common/index.cjs';
|
|
7
7
|
import 'react';
|
|
8
8
|
import 'hono';
|
|
9
|
+
import 'hono/types';
|
package/dist/index.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export { createEmailRoutes, createTemplateRoutes, createTrackingRoutes } from '.
|
|
|
6
6
|
export { encodeTrackingLinks, extractVariables, getWebsiteUrl, markdownToPlainText, resetWebsiteUrlCache, wrapInEmailTemplate } from './common/index.js';
|
|
7
7
|
import 'react';
|
|
8
8
|
import 'hono';
|
|
9
|
+
import 'hono/types';
|
package/dist/index.js
CHANGED
|
@@ -766,6 +766,9 @@ var EmailService = class {
|
|
|
766
766
|
// Updater function to save settings to backend
|
|
767
767
|
// Signature: async (profile, tenantId, settings) => void
|
|
768
768
|
settingsUpdater: config.settingsUpdater || null,
|
|
769
|
+
// Settings configuration
|
|
770
|
+
settingsTableName: config.settingsTableName || "system_settings",
|
|
771
|
+
settingsKeyPrefix: config.settingsKeyPrefix || "system_email.",
|
|
769
772
|
// Branding configuration for email templates
|
|
770
773
|
branding: {
|
|
771
774
|
brandName: config.branding?.brandName || "Your App",
|
|
@@ -814,6 +817,22 @@ var EmailService = class {
|
|
|
814
817
|
console.warn("[EmailService] settingsLoader failed:", e);
|
|
815
818
|
}
|
|
816
819
|
}
|
|
820
|
+
if (!settings && profile === "system" && this.db) {
|
|
821
|
+
try {
|
|
822
|
+
const tableName = this.config.settingsTableName;
|
|
823
|
+
const prefix = this.config.settingsKeyPrefix;
|
|
824
|
+
const { results } = await this.db.prepare(`SELECT * FROM ${tableName} WHERE key LIKE ?`).bind(`${prefix}%`).all();
|
|
825
|
+
if (results && results.length > 0) {
|
|
826
|
+
settings = {};
|
|
827
|
+
for (const row of results) {
|
|
828
|
+
const cleanKey = row.key.slice(prefix.length);
|
|
829
|
+
settings[cleanKey] = row.value;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
} catch (e) {
|
|
833
|
+
console.warn("[EmailService] Failed to load settings from DB:", e.message);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
817
836
|
if (settings) {
|
|
818
837
|
if (this.cache && this.cache.putSettings) {
|
|
819
838
|
try {
|
|
@@ -1344,12 +1363,68 @@ var EmailService = class {
|
|
|
1344
1363
|
};
|
|
1345
1364
|
|
|
1346
1365
|
// src/backend/routes/index.js
|
|
1347
|
-
import { Hono as
|
|
1366
|
+
import { Hono as Hono5 } from "hono";
|
|
1348
1367
|
|
|
1349
|
-
// src/backend/routes/
|
|
1368
|
+
// src/backend/routes/settings.js
|
|
1350
1369
|
import { Hono } from "hono";
|
|
1351
|
-
function
|
|
1370
|
+
function createSettingsRoutes(config = {}) {
|
|
1352
1371
|
const app = new Hono();
|
|
1372
|
+
const tableName = config.tableName || "system_settings";
|
|
1373
|
+
const keyPrefix = config.keyPrefix || "system_email.";
|
|
1374
|
+
const getSettings = async (db) => {
|
|
1375
|
+
try {
|
|
1376
|
+
const { results } = await db.prepare(`SELECT * FROM ${tableName} WHERE key LIKE ?`).bind(`${keyPrefix}%`).all();
|
|
1377
|
+
const settings = {};
|
|
1378
|
+
for (const row of results) {
|
|
1379
|
+
const cleanKey = row.key.slice(keyPrefix.length);
|
|
1380
|
+
settings[cleanKey] = row.value;
|
|
1381
|
+
}
|
|
1382
|
+
return settings;
|
|
1383
|
+
} catch (e) {
|
|
1384
|
+
console.warn(`[Settings] Failed to fetch from ${tableName}:`, e.message);
|
|
1385
|
+
return {};
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
app.get("/", async (c) => {
|
|
1389
|
+
try {
|
|
1390
|
+
const settings = await getSettings(c.env.DB);
|
|
1391
|
+
return c.json(settings);
|
|
1392
|
+
} catch (error) {
|
|
1393
|
+
console.error("Failed to fetch settings:", error);
|
|
1394
|
+
return c.json({ error: error.message }, 500);
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
app.post("/", async (c) => {
|
|
1398
|
+
try {
|
|
1399
|
+
const body = await c.req.json();
|
|
1400
|
+
const db = c.env.DB;
|
|
1401
|
+
const updates = Object.entries(body).map(([k, v]) => ({
|
|
1402
|
+
key: `${keyPrefix}${k}`,
|
|
1403
|
+
value: v
|
|
1404
|
+
}));
|
|
1405
|
+
if (updates.length === 0) return c.json({ success: true });
|
|
1406
|
+
const stmt = db.prepare(`
|
|
1407
|
+
INSERT INTO ${tableName} (key, value, updated_at)
|
|
1408
|
+
VALUES (?, ?, strftime('%s', 'now'))
|
|
1409
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
1410
|
+
value = excluded.value,
|
|
1411
|
+
updated_at = excluded.updated_at
|
|
1412
|
+
`);
|
|
1413
|
+
const batch = updates.map((u) => stmt.bind(u.key, u.value === void 0 || u.value === null ? "" : String(u.value)));
|
|
1414
|
+
await db.batch(batch);
|
|
1415
|
+
return c.json({ success: true });
|
|
1416
|
+
} catch (error) {
|
|
1417
|
+
console.error("Failed to save settings:", error);
|
|
1418
|
+
return c.json({ error: error.message }, 500);
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
return app;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
// src/backend/routes/templates.js
|
|
1425
|
+
import { Hono as Hono2 } from "hono";
|
|
1426
|
+
function createTemplateRoutes2(config = {}) {
|
|
1427
|
+
const app = new Hono2();
|
|
1353
1428
|
app.get("/", async (c) => {
|
|
1354
1429
|
const emailService = new EmailService(c.env, config);
|
|
1355
1430
|
try {
|
|
@@ -1429,7 +1504,7 @@ function createTemplateRoutes(config = {}) {
|
|
|
1429
1504
|
}
|
|
1430
1505
|
|
|
1431
1506
|
// src/backend/routes/tracking.js
|
|
1432
|
-
import { Hono as
|
|
1507
|
+
import { Hono as Hono3 } from "hono";
|
|
1433
1508
|
var TRACKING_PIXEL = new Uint8Array([
|
|
1434
1509
|
71,
|
|
1435
1510
|
73,
|
|
@@ -1475,7 +1550,7 @@ var TRACKING_PIXEL = new Uint8Array([
|
|
|
1475
1550
|
59
|
|
1476
1551
|
]);
|
|
1477
1552
|
function createTrackingRoutes(env, config = {}) {
|
|
1478
|
-
const app = new
|
|
1553
|
+
const app = new Hono3();
|
|
1479
1554
|
const db = env.DB;
|
|
1480
1555
|
const tablePrefix = config.emailTablePrefix || config.tableNamePrefix || "system_email_";
|
|
1481
1556
|
app.get("/track/open/:token", async (c) => {
|
|
@@ -1604,43 +1679,18 @@ function createTrackingRoutes(env, config = {}) {
|
|
|
1604
1679
|
}
|
|
1605
1680
|
|
|
1606
1681
|
// src/backend/routes/logs.js
|
|
1607
|
-
import { Hono as
|
|
1608
|
-
function createLogRoutes(config = {}) {
|
|
1609
|
-
const app = new Hono3();
|
|
1610
|
-
app.get("/", async (c) => {
|
|
1611
|
-
const limit = Math.min(parseInt(c.req.query("limit") || "50"), 100);
|
|
1612
|
-
const offset = parseInt(c.req.query("offset") || "0");
|
|
1613
|
-
const env = c.env;
|
|
1614
|
-
try {
|
|
1615
|
-
const table = `${config.emailTablePrefix || "system_email_"}logs`;
|
|
1616
|
-
const { results } = await env.DB.prepare(`
|
|
1617
|
-
SELECT * FROM ${table}
|
|
1618
|
-
ORDER BY created_at DESC
|
|
1619
|
-
LIMIT ? OFFSET ?
|
|
1620
|
-
`).bind(limit, offset).all();
|
|
1621
|
-
const countResult = await env.DB.prepare(`SELECT COUNT(*) as exact_count FROM ${table}`).first();
|
|
1622
|
-
return c.json({
|
|
1623
|
-
logs: results.map((row) => ({
|
|
1624
|
-
...row,
|
|
1625
|
-
metadata: row.metadata ? JSON.parse(row.metadata) : null
|
|
1626
|
-
})),
|
|
1627
|
-
total: countResult.exact_count,
|
|
1628
|
-
limit,
|
|
1629
|
-
offset
|
|
1630
|
-
});
|
|
1631
|
-
} catch (error) {
|
|
1632
|
-
console.error("Failed to fetch logs:", error);
|
|
1633
|
-
return c.json({ error: "Failed to fetch logs" }, 500);
|
|
1634
|
-
}
|
|
1635
|
-
});
|
|
1636
|
-
return app;
|
|
1637
|
-
}
|
|
1682
|
+
import { Hono as Hono4 } from "hono";
|
|
1638
1683
|
|
|
1639
1684
|
// src/backend/routes/index.js
|
|
1640
1685
|
function createEmailRoutes(config = {}, cacheProvider = null) {
|
|
1641
|
-
const app = new
|
|
1686
|
+
const app = new Hono5();
|
|
1642
1687
|
app.route("/templates", createTemplateRoutes(config, cacheProvider));
|
|
1643
1688
|
app.route("/logs", createLogRoutes(config));
|
|
1689
|
+
app.route("/settings", createSettingsRoutes({
|
|
1690
|
+
...config,
|
|
1691
|
+
tableName: config.settingsTableName || "system_settings",
|
|
1692
|
+
keyPrefix: config.settingsKeyPrefix || "system_email."
|
|
1693
|
+
}));
|
|
1644
1694
|
return app;
|
|
1645
1695
|
}
|
|
1646
1696
|
|
|
@@ -2186,7 +2236,7 @@ export {
|
|
|
2186
2236
|
createDOCacheProvider,
|
|
2187
2237
|
createEmailLoggerCallback,
|
|
2188
2238
|
createEmailRoutes,
|
|
2189
|
-
createTemplateRoutes,
|
|
2239
|
+
createTemplateRoutes2 as createTemplateRoutes,
|
|
2190
2240
|
createTrackingRoutes,
|
|
2191
2241
|
encodeTrackingLinks,
|
|
2192
2242
|
extractVariables,
|