@contentgrowth/content-emailing 0.8.0 → 0.8.1

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.
@@ -1541,7 +1541,7 @@ function createTemplateRoutes(config = {}) {
1541
1541
  app.post("/send-test", async (c) => {
1542
1542
  const emailService = new EmailService(c.env, config);
1543
1543
  try {
1544
- const { template_id, to, variables } = await c.req.json();
1544
+ const { template_id, to, variables, profile = "system", tenantId } = await c.req.json();
1545
1545
  let tid = template_id;
1546
1546
  if (!tid || !to) {
1547
1547
  return c.json({ error: "Missing required fields (template_id, to)" }, 400);
@@ -1550,11 +1550,16 @@ function createTemplateRoutes(config = {}) {
1550
1550
  const recipientUserId = user?.id || null;
1551
1551
  const result = await emailService.sendViaTemplate(tid, variables || {}, {
1552
1552
  to,
1553
- profile: "test",
1553
+ profile,
1554
+ tenantId,
1554
1555
  recipientUserId
1555
1556
  });
1557
+ if (!result.success) {
1558
+ return c.json({ error: result.error || "Failed to send test email" }, 400);
1559
+ }
1556
1560
  return c.json({ success: true, result });
1557
1561
  } catch (err) {
1562
+ console.error("[TemplateRoutes] Send test error:", err);
1558
1563
  return c.json({ error: `Failed to send test email: ${err.message}` }, 500);
1559
1564
  }
1560
1565
  });