@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
package/dist/index.cjs
CHANGED
|
@@ -1394,75 +1394,85 @@ var EmailService = class {
|
|
|
1394
1394
|
};
|
|
1395
1395
|
|
|
1396
1396
|
// src/backend/routes/index.js
|
|
1397
|
-
var
|
|
1397
|
+
var import_hono4 = require("hono");
|
|
1398
1398
|
|
|
1399
1399
|
// src/backend/routes/templates.js
|
|
1400
1400
|
var import_hono = require("hono");
|
|
1401
|
-
function createTemplateRoutes(
|
|
1401
|
+
function createTemplateRoutes(config = {}) {
|
|
1402
1402
|
const app = new import_hono.Hono();
|
|
1403
|
-
|
|
1404
|
-
|
|
1403
|
+
app.get("/", async (c) => {
|
|
1404
|
+
const emailService = new EmailService(c.env, config);
|
|
1405
1405
|
try {
|
|
1406
1406
|
const templates = await emailService.getAllTemplates();
|
|
1407
|
-
return c.json(
|
|
1407
|
+
return c.json(templates);
|
|
1408
1408
|
} catch (err) {
|
|
1409
|
-
return c.json({
|
|
1409
|
+
return c.json({ error: err.message }, 500);
|
|
1410
1410
|
}
|
|
1411
1411
|
});
|
|
1412
|
-
app.get("
|
|
1412
|
+
app.get("/:id", async (c) => {
|
|
1413
|
+
const emailService = new EmailService(c.env, config);
|
|
1413
1414
|
try {
|
|
1414
1415
|
const template = await emailService.getTemplate(c.req.param("id"));
|
|
1415
|
-
if (!template) return c.json({
|
|
1416
|
-
return c.json(
|
|
1416
|
+
if (!template) return c.json({ error: "Template not found" }, 404);
|
|
1417
|
+
return c.json(template);
|
|
1417
1418
|
} catch (err) {
|
|
1418
|
-
return c.json({
|
|
1419
|
+
return c.json({ error: err.message }, 500);
|
|
1419
1420
|
}
|
|
1420
1421
|
});
|
|
1421
|
-
app.post("/
|
|
1422
|
+
app.post("/", async (c) => {
|
|
1423
|
+
const emailService = new EmailService(c.env, config);
|
|
1422
1424
|
try {
|
|
1423
1425
|
const data = await c.req.json();
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
+
let userId = "admin";
|
|
1427
|
+
const user = c.get("dbUser") || c.get("user");
|
|
1428
|
+
if (user && user.id) userId = user.id;
|
|
1429
|
+
if (!data.template_id || !data.subject_template) {
|
|
1430
|
+
return c.json({ error: "Missing required fields (template_id, subject_template)" }, 400);
|
|
1431
|
+
}
|
|
1432
|
+
const result = await emailService.saveTemplate(data, userId);
|
|
1433
|
+
return c.json({ success: true, message: "Template saved", result });
|
|
1426
1434
|
} catch (err) {
|
|
1427
|
-
return c.json({
|
|
1435
|
+
return c.json({ error: err.message }, 500);
|
|
1428
1436
|
}
|
|
1429
1437
|
});
|
|
1430
|
-
app.
|
|
1438
|
+
app.post("/send-test", async (c) => {
|
|
1439
|
+
const emailService = new EmailService(c.env, config);
|
|
1440
|
+
try {
|
|
1441
|
+
const { template_id, to, variables } = await c.req.json();
|
|
1442
|
+
let tid = template_id;
|
|
1443
|
+
if (!tid || !to) {
|
|
1444
|
+
return c.json({ error: "Missing required fields (template_id, to)" }, 400);
|
|
1445
|
+
}
|
|
1446
|
+
const user = c.get("dbUser") || c.get("user");
|
|
1447
|
+
const recipientUserId = user?.id || null;
|
|
1448
|
+
const result = await emailService.sendViaTemplate(tid, variables || {}, {
|
|
1449
|
+
to,
|
|
1450
|
+
profile: "test",
|
|
1451
|
+
recipientUserId
|
|
1452
|
+
});
|
|
1453
|
+
return c.json({ success: true, result });
|
|
1454
|
+
} catch (err) {
|
|
1455
|
+
return c.json({ error: `Failed to send test email: ${err.message}` }, 500);
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
app.delete("/:id", async (c) => {
|
|
1459
|
+
const emailService = new EmailService(c.env, config);
|
|
1431
1460
|
try {
|
|
1432
1461
|
await emailService.deleteTemplate(c.req.param("id"));
|
|
1433
1462
|
return c.json({ success: true, message: "Template deleted" });
|
|
1434
1463
|
} catch (err) {
|
|
1435
|
-
return c.json({
|
|
1464
|
+
return c.json({ error: err.message }, 500);
|
|
1436
1465
|
}
|
|
1437
1466
|
});
|
|
1438
|
-
app.post("
|
|
1467
|
+
app.post("/:id/preview", async (c) => {
|
|
1468
|
+
const emailService = new EmailService(c.env, config);
|
|
1439
1469
|
try {
|
|
1440
1470
|
const id = c.req.param("id");
|
|
1441
1471
|
const data = await c.req.json();
|
|
1442
1472
|
const result = await emailService.renderTemplate(id, data);
|
|
1443
1473
|
return c.json({ success: true, preview: result });
|
|
1444
1474
|
} catch (err) {
|
|
1445
|
-
return c.json({
|
|
1446
|
-
}
|
|
1447
|
-
});
|
|
1448
|
-
app.post("/templates/:id/test", async (c) => {
|
|
1449
|
-
try {
|
|
1450
|
-
const id = c.req.param("id");
|
|
1451
|
-
const { to, data } = await c.req.json();
|
|
1452
|
-
const { subject, html, plainText } = await emailService.renderTemplate(id, data);
|
|
1453
|
-
const result = await emailService.sendEmail({
|
|
1454
|
-
to,
|
|
1455
|
-
subject: `[TEST] ${subject}`,
|
|
1456
|
-
html,
|
|
1457
|
-
text: plainText
|
|
1458
|
-
});
|
|
1459
|
-
if (result.success) {
|
|
1460
|
-
return c.json({ success: true, message: "Test email sent" });
|
|
1461
|
-
} else {
|
|
1462
|
-
return c.json({ success: false, error: result.error }, 500);
|
|
1463
|
-
}
|
|
1464
|
-
} catch (err) {
|
|
1465
|
-
return c.json({ success: false, error: err.message }, 500);
|
|
1475
|
+
return c.json({ error: err.message }, 500);
|
|
1466
1476
|
}
|
|
1467
1477
|
});
|
|
1468
1478
|
return app;
|
|
@@ -1643,11 +1653,44 @@ function createTrackingRoutes(env, config = {}) {
|
|
|
1643
1653
|
return app;
|
|
1644
1654
|
}
|
|
1645
1655
|
|
|
1646
|
-
// src/backend/routes/
|
|
1647
|
-
|
|
1656
|
+
// src/backend/routes/logs.js
|
|
1657
|
+
var import_hono3 = require("hono");
|
|
1658
|
+
function createLogRoutes(config = {}) {
|
|
1648
1659
|
const app = new import_hono3.Hono();
|
|
1649
|
-
app.
|
|
1650
|
-
|
|
1660
|
+
app.get("/", async (c) => {
|
|
1661
|
+
const limit = Math.min(parseInt(c.req.query("limit") || "50"), 100);
|
|
1662
|
+
const offset = parseInt(c.req.query("offset") || "0");
|
|
1663
|
+
const env = c.env;
|
|
1664
|
+
try {
|
|
1665
|
+
const table = `${config.emailTablePrefix || "system_email_"}logs`;
|
|
1666
|
+
const { results } = await env.DB.prepare(`
|
|
1667
|
+
SELECT * FROM ${table}
|
|
1668
|
+
ORDER BY created_at DESC
|
|
1669
|
+
LIMIT ? OFFSET ?
|
|
1670
|
+
`).bind(limit, offset).all();
|
|
1671
|
+
const countResult = await env.DB.prepare(`SELECT COUNT(*) as exact_count FROM ${table}`).first();
|
|
1672
|
+
return c.json({
|
|
1673
|
+
logs: results.map((row) => ({
|
|
1674
|
+
...row,
|
|
1675
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : null
|
|
1676
|
+
})),
|
|
1677
|
+
total: countResult.exact_count,
|
|
1678
|
+
limit,
|
|
1679
|
+
offset
|
|
1680
|
+
});
|
|
1681
|
+
} catch (error) {
|
|
1682
|
+
console.error("Failed to fetch logs:", error);
|
|
1683
|
+
return c.json({ error: "Failed to fetch logs" }, 500);
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
return app;
|
|
1687
|
+
}
|
|
1688
|
+
|
|
1689
|
+
// src/backend/routes/index.js
|
|
1690
|
+
function createEmailRoutes(config = {}, cacheProvider = null) {
|
|
1691
|
+
const app = new import_hono4.Hono();
|
|
1692
|
+
app.route("/templates", createTemplateRoutes(config, cacheProvider));
|
|
1693
|
+
app.route("/logs", createLogRoutes(config));
|
|
1651
1694
|
return app;
|
|
1652
1695
|
}
|
|
1653
1696
|
|