@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.js
CHANGED
|
@@ -1344,75 +1344,85 @@ var EmailService = class {
|
|
|
1344
1344
|
};
|
|
1345
1345
|
|
|
1346
1346
|
// src/backend/routes/index.js
|
|
1347
|
-
import { Hono as
|
|
1347
|
+
import { Hono as Hono4 } from "hono";
|
|
1348
1348
|
|
|
1349
1349
|
// src/backend/routes/templates.js
|
|
1350
1350
|
import { Hono } from "hono";
|
|
1351
|
-
function createTemplateRoutes(
|
|
1351
|
+
function createTemplateRoutes(config = {}) {
|
|
1352
1352
|
const app = new Hono();
|
|
1353
|
-
|
|
1354
|
-
|
|
1353
|
+
app.get("/", async (c) => {
|
|
1354
|
+
const emailService = new EmailService(c.env, config);
|
|
1355
1355
|
try {
|
|
1356
1356
|
const templates = await emailService.getAllTemplates();
|
|
1357
|
-
return c.json(
|
|
1357
|
+
return c.json(templates);
|
|
1358
1358
|
} catch (err) {
|
|
1359
|
-
return c.json({
|
|
1359
|
+
return c.json({ error: err.message }, 500);
|
|
1360
1360
|
}
|
|
1361
1361
|
});
|
|
1362
|
-
app.get("
|
|
1362
|
+
app.get("/:id", async (c) => {
|
|
1363
|
+
const emailService = new EmailService(c.env, config);
|
|
1363
1364
|
try {
|
|
1364
1365
|
const template = await emailService.getTemplate(c.req.param("id"));
|
|
1365
|
-
if (!template) return c.json({
|
|
1366
|
-
return c.json(
|
|
1366
|
+
if (!template) return c.json({ error: "Template not found" }, 404);
|
|
1367
|
+
return c.json(template);
|
|
1367
1368
|
} catch (err) {
|
|
1368
|
-
return c.json({
|
|
1369
|
+
return c.json({ error: err.message }, 500);
|
|
1369
1370
|
}
|
|
1370
1371
|
});
|
|
1371
|
-
app.post("/
|
|
1372
|
+
app.post("/", async (c) => {
|
|
1373
|
+
const emailService = new EmailService(c.env, config);
|
|
1372
1374
|
try {
|
|
1373
1375
|
const data = await c.req.json();
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
+
let userId = "admin";
|
|
1377
|
+
const user = c.get("dbUser") || c.get("user");
|
|
1378
|
+
if (user && user.id) userId = user.id;
|
|
1379
|
+
if (!data.template_id || !data.subject_template) {
|
|
1380
|
+
return c.json({ error: "Missing required fields (template_id, subject_template)" }, 400);
|
|
1381
|
+
}
|
|
1382
|
+
const result = await emailService.saveTemplate(data, userId);
|
|
1383
|
+
return c.json({ success: true, message: "Template saved", result });
|
|
1376
1384
|
} catch (err) {
|
|
1377
|
-
return c.json({
|
|
1385
|
+
return c.json({ error: err.message }, 500);
|
|
1378
1386
|
}
|
|
1379
1387
|
});
|
|
1380
|
-
app.
|
|
1388
|
+
app.post("/send-test", async (c) => {
|
|
1389
|
+
const emailService = new EmailService(c.env, config);
|
|
1390
|
+
try {
|
|
1391
|
+
const { template_id, to, variables } = await c.req.json();
|
|
1392
|
+
let tid = template_id;
|
|
1393
|
+
if (!tid || !to) {
|
|
1394
|
+
return c.json({ error: "Missing required fields (template_id, to)" }, 400);
|
|
1395
|
+
}
|
|
1396
|
+
const user = c.get("dbUser") || c.get("user");
|
|
1397
|
+
const recipientUserId = user?.id || null;
|
|
1398
|
+
const result = await emailService.sendViaTemplate(tid, variables || {}, {
|
|
1399
|
+
to,
|
|
1400
|
+
profile: "test",
|
|
1401
|
+
recipientUserId
|
|
1402
|
+
});
|
|
1403
|
+
return c.json({ success: true, result });
|
|
1404
|
+
} catch (err) {
|
|
1405
|
+
return c.json({ error: `Failed to send test email: ${err.message}` }, 500);
|
|
1406
|
+
}
|
|
1407
|
+
});
|
|
1408
|
+
app.delete("/:id", async (c) => {
|
|
1409
|
+
const emailService = new EmailService(c.env, config);
|
|
1381
1410
|
try {
|
|
1382
1411
|
await emailService.deleteTemplate(c.req.param("id"));
|
|
1383
1412
|
return c.json({ success: true, message: "Template deleted" });
|
|
1384
1413
|
} catch (err) {
|
|
1385
|
-
return c.json({
|
|
1414
|
+
return c.json({ error: err.message }, 500);
|
|
1386
1415
|
}
|
|
1387
1416
|
});
|
|
1388
|
-
app.post("
|
|
1417
|
+
app.post("/:id/preview", async (c) => {
|
|
1418
|
+
const emailService = new EmailService(c.env, config);
|
|
1389
1419
|
try {
|
|
1390
1420
|
const id = c.req.param("id");
|
|
1391
1421
|
const data = await c.req.json();
|
|
1392
1422
|
const result = await emailService.renderTemplate(id, data);
|
|
1393
1423
|
return c.json({ success: true, preview: result });
|
|
1394
1424
|
} catch (err) {
|
|
1395
|
-
return c.json({
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1398
|
-
app.post("/templates/:id/test", async (c) => {
|
|
1399
|
-
try {
|
|
1400
|
-
const id = c.req.param("id");
|
|
1401
|
-
const { to, data } = await c.req.json();
|
|
1402
|
-
const { subject, html, plainText } = await emailService.renderTemplate(id, data);
|
|
1403
|
-
const result = await emailService.sendEmail({
|
|
1404
|
-
to,
|
|
1405
|
-
subject: `[TEST] ${subject}`,
|
|
1406
|
-
html,
|
|
1407
|
-
text: plainText
|
|
1408
|
-
});
|
|
1409
|
-
if (result.success) {
|
|
1410
|
-
return c.json({ success: true, message: "Test email sent" });
|
|
1411
|
-
} else {
|
|
1412
|
-
return c.json({ success: false, error: result.error }, 500);
|
|
1413
|
-
}
|
|
1414
|
-
} catch (err) {
|
|
1415
|
-
return c.json({ success: false, error: err.message }, 500);
|
|
1425
|
+
return c.json({ error: err.message }, 500);
|
|
1416
1426
|
}
|
|
1417
1427
|
});
|
|
1418
1428
|
return app;
|
|
@@ -1593,11 +1603,44 @@ function createTrackingRoutes(env, config = {}) {
|
|
|
1593
1603
|
return app;
|
|
1594
1604
|
}
|
|
1595
1605
|
|
|
1596
|
-
// src/backend/routes/
|
|
1597
|
-
|
|
1606
|
+
// src/backend/routes/logs.js
|
|
1607
|
+
import { Hono as Hono3 } from "hono";
|
|
1608
|
+
function createLogRoutes(config = {}) {
|
|
1598
1609
|
const app = new Hono3();
|
|
1599
|
-
app.
|
|
1600
|
-
|
|
1610
|
+
app.get("/", async (c) => {
|
|
1611
|
+
const limit = Math.min(parseInt(c.req.query("limit") || "50"), 100);
|
|
1612
|
+
const offset = parseInt(c.req.query("offset") || "0");
|
|
1613
|
+
const env = c.env;
|
|
1614
|
+
try {
|
|
1615
|
+
const table = `${config.emailTablePrefix || "system_email_"}logs`;
|
|
1616
|
+
const { results } = await env.DB.prepare(`
|
|
1617
|
+
SELECT * FROM ${table}
|
|
1618
|
+
ORDER BY created_at DESC
|
|
1619
|
+
LIMIT ? OFFSET ?
|
|
1620
|
+
`).bind(limit, offset).all();
|
|
1621
|
+
const countResult = await env.DB.prepare(`SELECT COUNT(*) as exact_count FROM ${table}`).first();
|
|
1622
|
+
return c.json({
|
|
1623
|
+
logs: results.map((row) => ({
|
|
1624
|
+
...row,
|
|
1625
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : null
|
|
1626
|
+
})),
|
|
1627
|
+
total: countResult.exact_count,
|
|
1628
|
+
limit,
|
|
1629
|
+
offset
|
|
1630
|
+
});
|
|
1631
|
+
} catch (error) {
|
|
1632
|
+
console.error("Failed to fetch logs:", error);
|
|
1633
|
+
return c.json({ error: "Failed to fetch logs" }, 500);
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
return app;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
// src/backend/routes/index.js
|
|
1640
|
+
function createEmailRoutes(config = {}, cacheProvider = null) {
|
|
1641
|
+
const app = new Hono4();
|
|
1642
|
+
app.route("/templates", createTemplateRoutes(config, cacheProvider));
|
|
1643
|
+
app.route("/logs", createLogRoutes(config));
|
|
1601
1644
|
return app;
|
|
1602
1645
|
}
|
|
1603
1646
|
|