/* ===================================================================== lib/supporter-mail.js — Transaktions-E-Mails für den Supporter-Bereich (Resend-Adapter). 1:1 portiert, env.X → process.env.X. ===================================================================== */ export class EmailNotConfiguredError extends Error { constructor() { super("E-Mail-Versand ist noch nicht eingerichtet (RESEND_API_KEY fehlt)."); this.name = "EmailNotConfiguredError"; this.code = "EMAIL_NOT_CONFIGURED"; } } async function send({ to, subject, html }) { if (!process.env.RESEND_API_KEY || !process.env.RESEND_FROM) throw new EmailNotConfiguredError(); const res = await fetch("https://api.resend.com/emails", { method: "POST", headers: { Authorization: `Bearer ${process.env.RESEND_API_KEY}`, "Content-Type": "application/json" }, body: JSON.stringify({ from: process.env.RESEND_FROM, to: [to], subject, html }), }); if (!res.ok) { const text = await res.text().catch(() => ""); throw new Error(`E-Mail-Versand fehlgeschlagen (${res.status}): ${text.slice(0, 300)}`); } return true; } const WRAP = (title, bodyHtml) => `
DogiCrew 🩵
Bestätige deine E-Mail-Adresse mit diesem Code:
${code}
Der Code ist 15 Minuten gültig.
` ), }); } export async function sendLoginCode({ to, name, code }) { return send({ to, subject: "Dein Login-Code — Dogfather Supporter-Bereich", html: WRAP( `Hallo ${name} 👋`, `Dein Login-Code für den Supporter-Bereich:
${code}
Der Code ist 15 Minuten gültig. Hast du das nicht angefordert, ignoriere diese E-Mail.
` ), }); } export async function sendMilestoneUnlocked({ to, name, premiumLabel }) { return send({ to, subject: `Neuer Meilenstein freigeschaltet — ${premiumLabel} 🎉`, html: WRAP( `Glückwunsch, ${name}! 🩵`, `Du hast einen neuen Meilenstein erreicht und kannst jetzt deine Prämie einlösen:
${premiumLabel}
Logge dich in deinen Supporter-Bereich ein, um die Prämie einzulösen.
` ), }); }