@contentgrowth/content-emailing 0.7.8 → 0.8.0

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.
@@ -3,62 +3,6 @@ import { Hono as Hono5 } from "hono";
3
3
 
4
4
  // src/backend/routes/settings.js
5
5
  import { Hono } from "hono";
6
- function createSettingsRoutes(config = {}) {
7
- const app = new Hono();
8
- const tableName = config.tableName || "system_settings";
9
- const keyPrefix = config.keyPrefix || "system_email.";
10
- const getSettings = async (db) => {
11
- try {
12
- const { results } = await db.prepare(`SELECT * FROM ${tableName} WHERE key LIKE ?`).bind(`${keyPrefix}%`).all();
13
- const settings = {};
14
- for (const row of results) {
15
- const cleanKey = row.key.slice(keyPrefix.length);
16
- settings[cleanKey] = row.value;
17
- }
18
- return settings;
19
- } catch (e) {
20
- console.warn(`[Settings] Failed to fetch from ${tableName}:`, e.message);
21
- return {};
22
- }
23
- };
24
- app.get("/", async (c) => {
25
- try {
26
- const settings = await getSettings(c.env.DB);
27
- return c.json(settings);
28
- } catch (error) {
29
- console.error("Failed to fetch settings:", error);
30
- return c.json({ error: error.message }, 500);
31
- }
32
- });
33
- app.post("/", async (c) => {
34
- try {
35
- const body = await c.req.json();
36
- const db = c.env.DB;
37
- const updates = Object.entries(body).map(([k, v]) => ({
38
- key: `${keyPrefix}${k}`,
39
- value: v
40
- }));
41
- if (updates.length === 0) return c.json({ success: true });
42
- const stmt = db.prepare(`
43
- INSERT INTO ${tableName} (key, value, updated_at)
44
- VALUES (?, ?, strftime('%s', 'now'))
45
- ON CONFLICT(key) DO UPDATE SET
46
- value = excluded.value,
47
- updated_at = excluded.updated_at
48
- `);
49
- const batch = updates.map((u) => stmt.bind(u.key, u.value === void 0 || u.value === null ? "" : String(u.value)));
50
- await db.batch(batch);
51
- return c.json({ success: true });
52
- } catch (error) {
53
- console.error("Failed to save settings:", error);
54
- return c.json({ error: error.message }, 500);
55
- }
56
- });
57
- return app;
58
- }
59
-
60
- // src/backend/routes/templates.js
61
- import { Hono as Hono2 } from "hono";
62
6
 
63
7
  // src/backend/EmailService.js
64
8
  import { marked } from "marked";
@@ -1135,7 +1079,93 @@ var EmailService = class {
1135
1079
  }
1136
1080
  };
1137
1081
 
1082
+ // src/backend/routes/settings.js
1083
+ function createSettingsRoutes(config = {}) {
1084
+ const app = new Hono();
1085
+ const tableName = config.tableName || "system_settings";
1086
+ const keyPrefix = config.keyPrefix || "system_email.";
1087
+ const getSettings = async (db) => {
1088
+ try {
1089
+ const { results } = await db.prepare(`SELECT * FROM ${tableName} WHERE key LIKE ?`).bind(`${keyPrefix}%`).all();
1090
+ const settings = {};
1091
+ for (const row of results) {
1092
+ const cleanKey = row.key.slice(keyPrefix.length);
1093
+ settings[cleanKey] = row.value;
1094
+ }
1095
+ return settings;
1096
+ } catch (e) {
1097
+ console.warn(`[Settings] Failed to fetch from ${tableName}:`, e.message);
1098
+ return {};
1099
+ }
1100
+ };
1101
+ app.get("/", async (c) => {
1102
+ try {
1103
+ const settings = await getSettings(c.env.DB);
1104
+ return c.json(settings);
1105
+ } catch (error) {
1106
+ console.error("Failed to fetch settings:", error);
1107
+ return c.json({ error: error.message }, 500);
1108
+ }
1109
+ });
1110
+ app.post("/", async (c) => {
1111
+ try {
1112
+ const body = await c.req.json();
1113
+ const db = c.env.DB;
1114
+ const updates = Object.entries(body).map(([k, v]) => ({
1115
+ key: `${keyPrefix}${k}`,
1116
+ value: v
1117
+ }));
1118
+ if (updates.length === 0) return c.json({ success: true });
1119
+ const stmt = db.prepare(`
1120
+ INSERT INTO ${tableName} (key, value, updated_at)
1121
+ VALUES (?, ?, strftime('%s', 'now'))
1122
+ ON CONFLICT(key) DO UPDATE SET
1123
+ value = excluded.value,
1124
+ updated_at = excluded.updated_at
1125
+ `);
1126
+ const batch = updates.map((u) => stmt.bind(u.key, u.value === void 0 || u.value === null ? "" : String(u.value)));
1127
+ await db.batch(batch);
1128
+ return c.json({ success: true });
1129
+ } catch (error) {
1130
+ console.error("Failed to save settings:", error);
1131
+ return c.json({ error: error.message }, 500);
1132
+ }
1133
+ });
1134
+ app.post("/test", async (c) => {
1135
+ try {
1136
+ const settings = await c.req.json();
1137
+ const user = c.get("dbUser") || c.get("user");
1138
+ if (!user || !user.email) {
1139
+ return c.json({ error: "User email not found for testing" }, 400);
1140
+ }
1141
+ const emailService = new EmailService(c.env, {
1142
+ ...config,
1143
+ settingsLoader: async () => settings
1144
+ });
1145
+ const result = await emailService.sendEmail({
1146
+ to: user.email,
1147
+ subject: "Test Email Configuration",
1148
+ html: "<h1>It Works!</h1><p>Your email settings are configured correctly.</p>",
1149
+ text: "It Works! Your email settings are configured correctly.",
1150
+ profile: "system",
1151
+ // Use system defaults logic in service, but our loader overrides it
1152
+ userId: user.id
1153
+ });
1154
+ if (result.success) {
1155
+ return c.json({ success: true, message: `Test email sent to ${user.email}` });
1156
+ } else {
1157
+ return c.json({ success: false, error: result.error || "Failed to send test email" }, 400);
1158
+ }
1159
+ } catch (error) {
1160
+ console.error("Test settings failed:", error);
1161
+ return c.json({ error: error.message }, 500);
1162
+ }
1163
+ });
1164
+ return app;
1165
+ }
1166
+
1138
1167
  // src/backend/routes/templates.js
1168
+ import { Hono as Hono2 } from "hono";
1139
1169
  function createTemplateRoutes(config = {}) {
1140
1170
  const app = new Hono2();
1141
1171
  app.get("/", async (c) => {