@contentgrowth/content-emailing 0.7.5 → 0.7.6
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/index.cjs +85 -42
- package/dist/backend/index.cjs.map +1 -1
- package/dist/backend/index.js +85 -42
- package/dist/backend/index.js.map +1 -1
- package/dist/backend/routes/index.cjs +87 -42
- package/dist/backend/routes/index.cjs.map +1 -1
- package/dist/backend/routes/index.d.cts +10 -6
- package/dist/backend/routes/index.d.ts +10 -6
- package/dist/backend/routes/index.js +86 -42
- package/dist/backend/routes/index.js.map +1 -1
- package/dist/index.cjs +85 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +85 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -30,11 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
var routes_exports = {};
|
|
31
31
|
__export(routes_exports, {
|
|
32
32
|
createEmailRoutes: () => createEmailRoutes,
|
|
33
|
+
createLogRoutes: () => createLogRoutes,
|
|
33
34
|
createTemplateRoutes: () => createTemplateRoutes,
|
|
34
35
|
createTrackingRoutes: () => createTrackingRoutes
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(routes_exports);
|
|
37
|
-
var
|
|
38
|
+
var import_hono4 = require("hono");
|
|
38
39
|
|
|
39
40
|
// src/backend/routes/templates.js
|
|
40
41
|
var import_hono = require("hono");
|
|
@@ -1096,71 +1097,81 @@ var EmailService = class {
|
|
|
1096
1097
|
};
|
|
1097
1098
|
|
|
1098
1099
|
// src/backend/routes/templates.js
|
|
1099
|
-
function createTemplateRoutes(
|
|
1100
|
+
function createTemplateRoutes(config = {}) {
|
|
1100
1101
|
const app = new import_hono.Hono();
|
|
1101
|
-
|
|
1102
|
-
|
|
1102
|
+
app.get("/", async (c) => {
|
|
1103
|
+
const emailService = new EmailService(c.env, config);
|
|
1103
1104
|
try {
|
|
1104
1105
|
const templates = await emailService.getAllTemplates();
|
|
1105
|
-
return c.json(
|
|
1106
|
+
return c.json(templates);
|
|
1106
1107
|
} catch (err) {
|
|
1107
|
-
return c.json({
|
|
1108
|
+
return c.json({ error: err.message }, 500);
|
|
1108
1109
|
}
|
|
1109
1110
|
});
|
|
1110
|
-
app.get("
|
|
1111
|
+
app.get("/:id", async (c) => {
|
|
1112
|
+
const emailService = new EmailService(c.env, config);
|
|
1111
1113
|
try {
|
|
1112
1114
|
const template = await emailService.getTemplate(c.req.param("id"));
|
|
1113
|
-
if (!template) return c.json({
|
|
1114
|
-
return c.json(
|
|
1115
|
+
if (!template) return c.json({ error: "Template not found" }, 404);
|
|
1116
|
+
return c.json(template);
|
|
1115
1117
|
} catch (err) {
|
|
1116
|
-
return c.json({
|
|
1118
|
+
return c.json({ error: err.message }, 500);
|
|
1117
1119
|
}
|
|
1118
1120
|
});
|
|
1119
|
-
app.post("/
|
|
1121
|
+
app.post("/", async (c) => {
|
|
1122
|
+
const emailService = new EmailService(c.env, config);
|
|
1120
1123
|
try {
|
|
1121
1124
|
const data = await c.req.json();
|
|
1122
|
-
|
|
1123
|
-
|
|
1125
|
+
let userId = "admin";
|
|
1126
|
+
const user = c.get("dbUser") || c.get("user");
|
|
1127
|
+
if (user && user.id) userId = user.id;
|
|
1128
|
+
if (!data.template_id || !data.subject_template) {
|
|
1129
|
+
return c.json({ error: "Missing required fields (template_id, subject_template)" }, 400);
|
|
1130
|
+
}
|
|
1131
|
+
const result = await emailService.saveTemplate(data, userId);
|
|
1132
|
+
return c.json({ success: true, message: "Template saved", result });
|
|
1124
1133
|
} catch (err) {
|
|
1125
|
-
return c.json({
|
|
1134
|
+
return c.json({ error: err.message }, 500);
|
|
1126
1135
|
}
|
|
1127
1136
|
});
|
|
1128
|
-
app.
|
|
1137
|
+
app.post("/send-test", async (c) => {
|
|
1138
|
+
const emailService = new EmailService(c.env, config);
|
|
1139
|
+
try {
|
|
1140
|
+
const { template_id, to, variables } = await c.req.json();
|
|
1141
|
+
let tid = template_id;
|
|
1142
|
+
if (!tid || !to) {
|
|
1143
|
+
return c.json({ error: "Missing required fields (template_id, to)" }, 400);
|
|
1144
|
+
}
|
|
1145
|
+
const user = c.get("dbUser") || c.get("user");
|
|
1146
|
+
const recipientUserId = user?.id || null;
|
|
1147
|
+
const result = await emailService.sendViaTemplate(tid, variables || {}, {
|
|
1148
|
+
to,
|
|
1149
|
+
profile: "test",
|
|
1150
|
+
recipientUserId
|
|
1151
|
+
});
|
|
1152
|
+
return c.json({ success: true, result });
|
|
1153
|
+
} catch (err) {
|
|
1154
|
+
return c.json({ error: `Failed to send test email: ${err.message}` }, 500);
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
app.delete("/:id", async (c) => {
|
|
1158
|
+
const emailService = new EmailService(c.env, config);
|
|
1129
1159
|
try {
|
|
1130
1160
|
await emailService.deleteTemplate(c.req.param("id"));
|
|
1131
1161
|
return c.json({ success: true, message: "Template deleted" });
|
|
1132
1162
|
} catch (err) {
|
|
1133
|
-
return c.json({
|
|
1163
|
+
return c.json({ error: err.message }, 500);
|
|
1134
1164
|
}
|
|
1135
1165
|
});
|
|
1136
|
-
app.post("
|
|
1166
|
+
app.post("/:id/preview", async (c) => {
|
|
1167
|
+
const emailService = new EmailService(c.env, config);
|
|
1137
1168
|
try {
|
|
1138
1169
|
const id = c.req.param("id");
|
|
1139
1170
|
const data = await c.req.json();
|
|
1140
1171
|
const result = await emailService.renderTemplate(id, data);
|
|
1141
1172
|
return c.json({ success: true, preview: result });
|
|
1142
1173
|
} catch (err) {
|
|
1143
|
-
return c.json({
|
|
1144
|
-
}
|
|
1145
|
-
});
|
|
1146
|
-
app.post("/templates/:id/test", async (c) => {
|
|
1147
|
-
try {
|
|
1148
|
-
const id = c.req.param("id");
|
|
1149
|
-
const { to, data } = await c.req.json();
|
|
1150
|
-
const { subject, html, plainText } = await emailService.renderTemplate(id, data);
|
|
1151
|
-
const result = await emailService.sendEmail({
|
|
1152
|
-
to,
|
|
1153
|
-
subject: `[TEST] ${subject}`,
|
|
1154
|
-
html,
|
|
1155
|
-
text: plainText
|
|
1156
|
-
});
|
|
1157
|
-
if (result.success) {
|
|
1158
|
-
return c.json({ success: true, message: "Test email sent" });
|
|
1159
|
-
} else {
|
|
1160
|
-
return c.json({ success: false, error: result.error }, 500);
|
|
1161
|
-
}
|
|
1162
|
-
} catch (err) {
|
|
1163
|
-
return c.json({ success: false, error: err.message }, 500);
|
|
1174
|
+
return c.json({ error: err.message }, 500);
|
|
1164
1175
|
}
|
|
1165
1176
|
});
|
|
1166
1177
|
return app;
|
|
@@ -1341,16 +1352,50 @@ function createTrackingRoutes(env, config = {}) {
|
|
|
1341
1352
|
return app;
|
|
1342
1353
|
}
|
|
1343
1354
|
|
|
1344
|
-
// src/backend/routes/
|
|
1345
|
-
|
|
1355
|
+
// src/backend/routes/logs.js
|
|
1356
|
+
var import_hono3 = require("hono");
|
|
1357
|
+
function createLogRoutes(config = {}) {
|
|
1346
1358
|
const app = new import_hono3.Hono();
|
|
1347
|
-
app.
|
|
1348
|
-
|
|
1359
|
+
app.get("/", async (c) => {
|
|
1360
|
+
const limit = Math.min(parseInt(c.req.query("limit") || "50"), 100);
|
|
1361
|
+
const offset = parseInt(c.req.query("offset") || "0");
|
|
1362
|
+
const env = c.env;
|
|
1363
|
+
try {
|
|
1364
|
+
const table = `${config.emailTablePrefix || "system_email_"}logs`;
|
|
1365
|
+
const { results } = await env.DB.prepare(`
|
|
1366
|
+
SELECT * FROM ${table}
|
|
1367
|
+
ORDER BY created_at DESC
|
|
1368
|
+
LIMIT ? OFFSET ?
|
|
1369
|
+
`).bind(limit, offset).all();
|
|
1370
|
+
const countResult = await env.DB.prepare(`SELECT COUNT(*) as exact_count FROM ${table}`).first();
|
|
1371
|
+
return c.json({
|
|
1372
|
+
logs: results.map((row) => ({
|
|
1373
|
+
...row,
|
|
1374
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : null
|
|
1375
|
+
})),
|
|
1376
|
+
total: countResult.exact_count,
|
|
1377
|
+
limit,
|
|
1378
|
+
offset
|
|
1379
|
+
});
|
|
1380
|
+
} catch (error) {
|
|
1381
|
+
console.error("Failed to fetch logs:", error);
|
|
1382
|
+
return c.json({ error: "Failed to fetch logs" }, 500);
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
return app;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
// src/backend/routes/index.js
|
|
1389
|
+
function createEmailRoutes(config = {}, cacheProvider = null) {
|
|
1390
|
+
const app = new import_hono4.Hono();
|
|
1391
|
+
app.route("/templates", createTemplateRoutes(config, cacheProvider));
|
|
1392
|
+
app.route("/logs", createLogRoutes(config));
|
|
1349
1393
|
return app;
|
|
1350
1394
|
}
|
|
1351
1395
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1352
1396
|
0 && (module.exports = {
|
|
1353
1397
|
createEmailRoutes,
|
|
1398
|
+
createLogRoutes,
|
|
1354
1399
|
createTemplateRoutes,
|
|
1355
1400
|
createTrackingRoutes
|
|
1356
1401
|
});
|