/** * What one stored subscription's reminder should say. * * Since reminders became personal (lib/reminder.ts), each subscription carries * the notification text its own browser composed — already in the user's * language, naming their deck when their notes could carry it. Older records * (or a browser that never refreshed) have none, so the operator's generic * default from the environment is the fallback. Kept in its own module so both * the sender and the test suite can exercise it without sending anything. */ /** The operator's fallback, from PUSH_REMINDER_* (see .env.example). */ export const DEFAULT_REMINDER = { title: "Time to review", body: "Your decks are waiting — a few due cards keep the streak alive.", url: "/", }; function text(value) { return typeof value === "string" ? value.trim() : ""; } export function reminderPayload(entry, defaults = DEFAULT_REMINDER) { const fallback = { title: text(defaults?.title) || DEFAULT_REMINDER.title, body: text(defaults?.body) || DEFAULT_REMINDER.body, url: text(defaults?.url) || DEFAULT_REMINDER.url, }; const message = entry?.message; if (!message || typeof message !== "object") return fallback; const title = text(message.title); const body = text(message.body); if (!title || !body) return fallback; const url = text(message.url); return { title, body, url: url.startsWith("/") ? url : fallback.url }; }