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