@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
|
@@ -30,15 +30,72 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var routes_exports = {};
|
|
31
31
|
__export(routes_exports, {
|
|
32
32
|
createEmailRoutes: () => createEmailRoutes,
|
|
33
|
-
createLogRoutes: () =>
|
|
34
|
-
|
|
33
|
+
createLogRoutes: () => createLogRoutes2,
|
|
34
|
+
createSettingsRoutes: () => createSettingsRoutes,
|
|
35
|
+
createTemplateRoutes: () => createTemplateRoutes2,
|
|
35
36
|
createTrackingRoutes: () => createTrackingRoutes
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(routes_exports);
|
|
38
|
-
var
|
|
39
|
+
var import_hono5 = require("hono");
|
|
39
40
|
|
|
40
|
-
// src/backend/routes/
|
|
41
|
+
// src/backend/routes/settings.js
|
|
41
42
|
var import_hono = require("hono");
|
|
43
|
+
function createSettingsRoutes(config = {}) {
|
|
44
|
+
const app = new import_hono.Hono();
|
|
45
|
+
const tableName = config.tableName || "system_settings";
|
|
46
|
+
const keyPrefix = config.keyPrefix || "system_email.";
|
|
47
|
+
const getSettings = async (db) => {
|
|
48
|
+
try {
|
|
49
|
+
const { results } = await db.prepare(`SELECT * FROM ${tableName} WHERE key LIKE ?`).bind(`${keyPrefix}%`).all();
|
|
50
|
+
const settings = {};
|
|
51
|
+
for (const row of results) {
|
|
52
|
+
const cleanKey = row.key.slice(keyPrefix.length);
|
|
53
|
+
settings[cleanKey] = row.value;
|
|
54
|
+
}
|
|
55
|
+
return settings;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.warn(`[Settings] Failed to fetch from ${tableName}:`, e.message);
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
app.get("/", async (c) => {
|
|
62
|
+
try {
|
|
63
|
+
const settings = await getSettings(c.env.DB);
|
|
64
|
+
return c.json(settings);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error("Failed to fetch settings:", error);
|
|
67
|
+
return c.json({ error: error.message }, 500);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
app.post("/", async (c) => {
|
|
71
|
+
try {
|
|
72
|
+
const body = await c.req.json();
|
|
73
|
+
const db = c.env.DB;
|
|
74
|
+
const updates = Object.entries(body).map(([k, v]) => ({
|
|
75
|
+
key: `${keyPrefix}${k}`,
|
|
76
|
+
value: v
|
|
77
|
+
}));
|
|
78
|
+
if (updates.length === 0) return c.json({ success: true });
|
|
79
|
+
const stmt = db.prepare(`
|
|
80
|
+
INSERT INTO ${tableName} (key, value, updated_at)
|
|
81
|
+
VALUES (?, ?, strftime('%s', 'now'))
|
|
82
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
83
|
+
value = excluded.value,
|
|
84
|
+
updated_at = excluded.updated_at
|
|
85
|
+
`);
|
|
86
|
+
const batch = updates.map((u) => stmt.bind(u.key, u.value === void 0 || u.value === null ? "" : String(u.value)));
|
|
87
|
+
await db.batch(batch);
|
|
88
|
+
return c.json({ success: true });
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error("Failed to save settings:", error);
|
|
91
|
+
return c.json({ error: error.message }, 500);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
return app;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/backend/routes/templates.js
|
|
98
|
+
var import_hono2 = require("hono");
|
|
42
99
|
|
|
43
100
|
// src/backend/EmailService.js
|
|
44
101
|
var import_marked = require("marked");
|
|
@@ -519,6 +576,9 @@ var EmailService = class {
|
|
|
519
576
|
// Updater function to save settings to backend
|
|
520
577
|
// Signature: async (profile, tenantId, settings) => void
|
|
521
578
|
settingsUpdater: config.settingsUpdater || null,
|
|
579
|
+
// Settings configuration
|
|
580
|
+
settingsTableName: config.settingsTableName || "system_settings",
|
|
581
|
+
settingsKeyPrefix: config.settingsKeyPrefix || "system_email.",
|
|
522
582
|
// Branding configuration for email templates
|
|
523
583
|
branding: {
|
|
524
584
|
brandName: config.branding?.brandName || "Your App",
|
|
@@ -567,6 +627,22 @@ var EmailService = class {
|
|
|
567
627
|
console.warn("[EmailService] settingsLoader failed:", e);
|
|
568
628
|
}
|
|
569
629
|
}
|
|
630
|
+
if (!settings && profile === "system" && this.db) {
|
|
631
|
+
try {
|
|
632
|
+
const tableName = this.config.settingsTableName;
|
|
633
|
+
const prefix = this.config.settingsKeyPrefix;
|
|
634
|
+
const { results } = await this.db.prepare(`SELECT * FROM ${tableName} WHERE key LIKE ?`).bind(`${prefix}%`).all();
|
|
635
|
+
if (results && results.length > 0) {
|
|
636
|
+
settings = {};
|
|
637
|
+
for (const row of results) {
|
|
638
|
+
const cleanKey = row.key.slice(prefix.length);
|
|
639
|
+
settings[cleanKey] = row.value;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
} catch (e) {
|
|
643
|
+
console.warn("[EmailService] Failed to load settings from DB:", e.message);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
570
646
|
if (settings) {
|
|
571
647
|
if (this.cache && this.cache.putSettings) {
|
|
572
648
|
try {
|
|
@@ -1097,8 +1173,8 @@ var EmailService = class {
|
|
|
1097
1173
|
};
|
|
1098
1174
|
|
|
1099
1175
|
// src/backend/routes/templates.js
|
|
1100
|
-
function
|
|
1101
|
-
const app = new
|
|
1176
|
+
function createTemplateRoutes2(config = {}) {
|
|
1177
|
+
const app = new import_hono2.Hono();
|
|
1102
1178
|
app.get("/", async (c) => {
|
|
1103
1179
|
const emailService = new EmailService(c.env, config);
|
|
1104
1180
|
try {
|
|
@@ -1178,7 +1254,7 @@ function createTemplateRoutes(config = {}) {
|
|
|
1178
1254
|
}
|
|
1179
1255
|
|
|
1180
1256
|
// src/backend/routes/tracking.js
|
|
1181
|
-
var
|
|
1257
|
+
var import_hono3 = require("hono");
|
|
1182
1258
|
var TRACKING_PIXEL = new Uint8Array([
|
|
1183
1259
|
71,
|
|
1184
1260
|
73,
|
|
@@ -1224,7 +1300,7 @@ var TRACKING_PIXEL = new Uint8Array([
|
|
|
1224
1300
|
59
|
|
1225
1301
|
]);
|
|
1226
1302
|
function createTrackingRoutes(env, config = {}) {
|
|
1227
|
-
const app = new
|
|
1303
|
+
const app = new import_hono3.Hono();
|
|
1228
1304
|
const db = env.DB;
|
|
1229
1305
|
const tablePrefix = config.emailTablePrefix || config.tableNamePrefix || "system_email_";
|
|
1230
1306
|
app.get("/track/open/:token", async (c) => {
|
|
@@ -1353,9 +1429,9 @@ function createTrackingRoutes(env, config = {}) {
|
|
|
1353
1429
|
}
|
|
1354
1430
|
|
|
1355
1431
|
// src/backend/routes/logs.js
|
|
1356
|
-
var
|
|
1357
|
-
function
|
|
1358
|
-
const app = new
|
|
1432
|
+
var import_hono4 = require("hono");
|
|
1433
|
+
function createLogRoutes2(config = {}) {
|
|
1434
|
+
const app = new import_hono4.Hono();
|
|
1359
1435
|
app.get("/", async (c) => {
|
|
1360
1436
|
const limit = Math.min(parseInt(c.req.query("limit") || "50"), 100);
|
|
1361
1437
|
const offset = parseInt(c.req.query("offset") || "0");
|
|
@@ -1387,15 +1463,21 @@ function createLogRoutes(config = {}) {
|
|
|
1387
1463
|
|
|
1388
1464
|
// src/backend/routes/index.js
|
|
1389
1465
|
function createEmailRoutes(config = {}, cacheProvider = null) {
|
|
1390
|
-
const app = new
|
|
1466
|
+
const app = new import_hono5.Hono();
|
|
1391
1467
|
app.route("/templates", createTemplateRoutes(config, cacheProvider));
|
|
1392
1468
|
app.route("/logs", createLogRoutes(config));
|
|
1469
|
+
app.route("/settings", createSettingsRoutes({
|
|
1470
|
+
...config,
|
|
1471
|
+
tableName: config.settingsTableName || "system_settings",
|
|
1472
|
+
keyPrefix: config.settingsKeyPrefix || "system_email."
|
|
1473
|
+
}));
|
|
1393
1474
|
return app;
|
|
1394
1475
|
}
|
|
1395
1476
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1396
1477
|
0 && (module.exports = {
|
|
1397
1478
|
createEmailRoutes,
|
|
1398
1479
|
createLogRoutes,
|
|
1480
|
+
createSettingsRoutes,
|
|
1399
1481
|
createTemplateRoutes,
|
|
1400
1482
|
createTrackingRoutes
|
|
1401
1483
|
});
|