fix(andreknie.de): harden personal data lifecycle

This commit is contained in:
2026-07-28 11:13:27 +02:00
parent 772a63c622
commit b31da6175a
11 changed files with 276 additions and 124 deletions
@@ -9,6 +9,18 @@ const BASE_URL = process.env.BASE_URL || 'https://andreknie.de'
let transporter = null
export class MailerNotReadyError extends Error {
constructor() {
super('Mailer ist nicht konfiguriert.')
this.name = 'MailerNotReadyError'
this.code = 'MAILER_NOT_READY'
}
}
export function isMailerReady() {
return Boolean(SMTP_HOST && SMTP_USER && SMTP_PASS)
}
function getTransporter() {
if (!transporter && SMTP_HOST && SMTP_USER && SMTP_PASS) {
transporter = nodemailer.createTransport({
@@ -23,10 +35,7 @@ function getTransporter() {
export async function sendConfirmationEmail(to, type, token) {
const t = getTransporter()
if (!t) {
console.log(`[Mailer] SMTP not configured. Would send ${type} confirmation to ${to}`)
return
}
if (!t) throw new MailerNotReadyError()
const confirmUrl = `${BASE_URL}/api/${type}/confirm/${token}`
const subjects = {
@@ -45,10 +54,7 @@ export async function sendConfirmationEmail(to, type, token) {
export async function sendStakeholderNotification(type, data) {
const t = getTransporter()
if (!t) {
console.log(`[Mailer] SMTP not configured. Would notify stakeholder about ${type}`)
return
}
if (!t) throw new MailerNotReadyError()
const subjects = {
contact: `Neue Kontaktanfrage von ${data.name}`,
@@ -80,11 +86,7 @@ export async function sendSpeakerCv(to, lead, pdfPath) {
const t = getTransporter()
const pdfMissing = !pdfPath || !existsSync(pdfPath)
if (!t) {
console.log(`[Mailer] SMTP not configured. Would send speaker CV to ${to} (pdfMissing=${pdfMissing})`)
await notifyStakeholderSpeakerCv(lead, pdfMissing)
return { sent: false, pdfMissing }
}
if (!t) throw new MailerNotReadyError()
if (!pdfMissing) {
await t.sendMail({
@@ -112,10 +114,7 @@ async function notifyStakeholderSpeakerCv(lead, pdfMissing) {
: 'CV wurde automatisch an den Anfragenden gesendet.',
].join('\n')
if (!t) {
console.log(`[Mailer] SMTP not configured. Would notify stakeholder about speaker-cv lead:\n${body}`)
return
}
if (!t) throw new MailerNotReadyError()
await t.sendMail({
from: SMTP_USER,