Add email verification, personal calendar feed, and full SEO implementation

- Customer accounts now require email verification (hashed, single-use,
  time-limited tokens) before they can request/confirm bookings, with
  resend flows on login/account/booking widget and rate limiting.
- Admins get a private, rotatable iCalendar (ICS) subscription feed of
  their confirmed bookings and public events, timezone-correct for
  Europe/Berlin including DST, never exposing meeting passwords.
- Adds a full SEO layer: per-page canonical/OG/Twitter metadata with
  CMS-editable overrides and content-derived fallbacks, a dynamic
  sitemap.xml and robots.txt driven by real published content, JSON-LD
  (Organization/LocalBusiness, WebSite, WebPage, BreadcrumbList, Service,
  Event, BlogPosting) that never fabricates data, and a CMS-managed
  redirect table for changed slugs.
- Global ANOUMA-naming audit: the brand name is never used to label
  personal account/calendar areas anywhere in the app, CMS, or emails.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-25 22:57:31 +02:00
co-authored by Claude Sonnet 5
parent 50c39a70e0
commit 1cd15aff25
72 changed files with 2835 additions and 257 deletions
+109
View File
@@ -0,0 +1,109 @@
import type { Payload } from "payload";
import { EVENT_CATEGORIES } from "@/collections/Events";
import type { ICSEvent } from "./ics";
import type { BookingRequest, Customer, Event, Offer } from "@/payload-types";
// A rolling window rather than "everything ever": calendar apps refetch a
// subscribed feed periodically on their own, so this just needs to cover a
// sensible range each time, not paginate an entire history.
const WINDOW_PAST_MS = 30 * 24 * 60 * 60 * 1000;
const WINDOW_FUTURE_MS = 400 * 24 * 60 * 60 * 1000;
/**
* Builds the calendar entries for Anna's personal ICS feed: confirmed
* bookings (never pending ones) plus standalone public events — onsite and
* online alike. Deliberately never includes the meeting password anywhere
* in the output, only a link to the protected join page.
*
* Local API is used with the default overrideAccess: true because this is
* only ever reached after the caller already verified the feed's secret
* token (see app/(frontend)/calendar/[tokenFile]/route.ts) — equivalent
* trust to the existing admin calendar view.
*/
export async function getAdminFeedICSEvents(payload: Payload): Promise<ICSEvent[]> {
const from = new Date(Date.now() - WINDOW_PAST_MS);
const to = new Date(Date.now() + WINDOW_FUTURE_MS);
const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL || "http://localhost:3000";
const domainHost = new URL(serverUrl).host;
const [{ docs: bookings }, { docs: events }, settings] = await Promise.all([
payload.find({
collection: "booking-requests",
where: {
and: [
{ status: { equals: "confirmed" } },
{ date: { greater_than_equal: from.toISOString() } },
{ date: { less_than_equal: to.toISOString() } },
],
},
depth: 2,
limit: 1000,
}),
payload.find({
collection: "events",
where: {
and: [
{ date: { greater_than_equal: from.toISOString() } },
{ date: { less_than_equal: to.toISOString() } },
{ isPrivateBooking: { not_equals: true } },
],
},
depth: 0,
limit: 1000,
}),
payload.findGlobal({ slug: "booking-settings" }),
]);
const addressParts = [settings.locationName, settings.street, [settings.postalCode, settings.city].filter(Boolean).join(" ")].filter(Boolean);
const fullAddress = addressParts.join(", ");
const bookingEvents: ICSEvent[] = (bookings as BookingRequest[]).map((b) => {
const offer = typeof b.offer === "object" ? (b.offer as Offer) : null;
const customer = typeof b.user === "object" ? (b.user as Customer) : null;
const isOnline = b.appointmentType === "online";
const description = [
customer?.name ? `Mit: ${customer.name}` : null,
isOnline ? "Online-Termin" : "Vor-Ort-Termin",
b.userMessage ? `Nachricht: ${b.userMessage}` : null,
]
.filter(Boolean)
.join("\n");
let url: string | undefined;
if (isOnline && b.linkedEvent && typeof b.linkedEvent === "object") {
url = `${serverUrl}/termine/${(b.linkedEvent as Event).slug}/beitreten`;
} else if (!isOnline && fullAddress) {
url = `https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(fullAddress)}`;
}
return {
uid: `booking-${b.id}@${domainHost}`,
start: new Date(b.startTime),
end: new Date(b.endTime),
summary: offer?.title ?? "Termin",
description: description || undefined,
// Vor Ort: vollständige Adresse. Online: literal "Online" — never the
// meeting password, which is intentionally not part of this feed.
location: isOnline ? "Online" : fullAddress || undefined,
url,
};
});
const eventEvents: ICSEvent[] = (events as Event[]).map((e) => {
const isOnline = Boolean(e.isOnline);
const start = new Date(e.startTime || e.date);
const end = new Date(e.endTime || e.startTime || e.date);
return {
uid: `event-${e.id}@${domainHost}`,
start,
end,
summary: e.title,
description: EVENT_CATEGORIES.find((c) => c.value === e.category)?.label,
location: isOnline ? "Online" : e.location || fullAddress || undefined,
url: e.slug ? `${serverUrl}/termine/${e.slug}` : undefined,
};
});
return [...bookingEvents, ...eventEvents];
}
+21
View File
@@ -0,0 +1,21 @@
import { createHash, randomBytes } from "node:crypto";
/**
* Long-lived, random, rotatable secret for a personal calendar-subscription
* URL (/calendar/<token>.ics) — treated like an API key, not a
* short-lived link: only its hash is stored, so a database leak alone
* can't be used to subscribe to anyone's calendar, and rotating it
* (overwriting the stored hash) immediately invalidates the old URL.
*/
export function generateCalendarFeedToken(): string {
return randomBytes(32).toString("hex");
}
export function hashCalendarFeedToken(token: string): string {
return createHash("sha256").update(token).digest("hex");
}
export function calendarFeedUrl(token: string): string {
const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL || "http://localhost:3000";
return `${serverUrl}/calendar/${token}.ics`;
}
+72
View File
@@ -0,0 +1,72 @@
import { BERLIN_VTIMEZONE_LINES, toBerlinICSDateTime, toUTCICSStamp } from "./timezone";
export type ICSEvent = {
uid: string;
start: Date;
end: Date;
summary: string;
description?: string;
location?: string;
url?: string;
};
function escapeICSText(value: string): string {
return value
.replace(/\\/g, "\\\\")
.replace(/;/g, "\\;")
.replace(/,/g, "\\,")
.replace(/\n/g, "\\n");
}
/** RFC 5545 line folding: lines must not exceed 75 octets; continuations start with a single space. */
function foldLine(line: string): string {
const encoder = new TextEncoder();
if (encoder.encode(line).length <= 75) return line;
const chunks: string[] = [];
let current = "";
for (const char of line) {
const candidate = current + char;
if (encoder.encode(candidate).length > 75) {
chunks.push(current);
current = char;
} else {
current = candidate;
}
}
if (current) chunks.push(current);
return chunks.join("\r\n ");
}
/** Builds a complete RFC 5545 VCALENDAR document, Europe/Berlin timezone-aware throughout. */
export function buildICSCalendar(args: { calendarName: string; events: ICSEvent[] }): string {
const lines: string[] = [
"BEGIN:VCALENDAR",
"VERSION:2.0",
"PRODID:-//ANOUMA//Calendar Feed//DE",
"CALSCALE:GREGORIAN",
"METHOD:PUBLISH",
`X-WR-CALNAME:${escapeICSText(args.calendarName)}`,
"X-WR-TIMEZONE:Europe/Berlin",
...BERLIN_VTIMEZONE_LINES,
];
const stamp = toUTCICSStamp(new Date());
for (const ev of args.events) {
lines.push(
"BEGIN:VEVENT",
`UID:${ev.uid}`,
`DTSTAMP:${stamp}`,
`DTSTART;TZID=Europe/Berlin:${toBerlinICSDateTime(ev.start)}`,
`DTEND;TZID=Europe/Berlin:${toBerlinICSDateTime(ev.end)}`,
`SUMMARY:${escapeICSText(ev.summary)}`,
);
if (ev.description) lines.push(`DESCRIPTION:${escapeICSText(ev.description)}`);
if (ev.location) lines.push(`LOCATION:${escapeICSText(ev.location)}`);
if (ev.url) lines.push(`URL:${ev.url}`);
lines.push("STATUS:CONFIRMED", "END:VEVENT");
}
lines.push("END:VCALENDAR");
return lines.map(foldLine).join("\r\n") + "\r\n";
}
+57
View File
@@ -0,0 +1,57 @@
const BERLIN_TZ = "Europe/Berlin";
/**
* Converts a JS Date (a UTC instant) into its Europe/Berlin wall-clock
* representation for iCalendar's local `TZID` date-time form
* (`DTSTART;TZID=Europe/Berlin:YYYYMMDDTHHMMSS`). Uses the ICU timezone
* database via Intl rather than manual UTC+1/+2 arithmetic, so daylight
* saving transitions are always handled correctly — no naive UTC offset
* math that would drift by an hour half the year.
*/
export function toBerlinICSDateTime(date: Date): string {
const parts = new Intl.DateTimeFormat("en-US", {
timeZone: BERLIN_TZ,
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hourCycle: "h23",
}).formatToParts(date);
const get = (type: string) => parts.find((p) => p.type === type)?.value ?? "00";
return `${get("year")}${get("month")}${get("day")}T${get("hour")}${get("minute")}${get("second")}`;
}
/** UTC timestamp form (`YYYYMMDDTHHMMSSZ`) — used only for DTSTAMP, which marks generation time, not a local event time. */
export function toUTCICSStamp(date: Date): string {
return date.toISOString().replace(/[-:]/g, "").split(".")[0] + "Z";
}
/**
* Standard IANA Europe/Berlin VTIMEZONE block (the same one commonly
* embedded by calendar exporters): CEST from the last Sunday in March,
* CET from the last Sunday in October — the actual EU DST rule, not an
* approximation.
*/
export const BERLIN_VTIMEZONE_LINES = [
"BEGIN:VTIMEZONE",
"TZID:Europe/Berlin",
"X-LIC-LOCATION:Europe/Berlin",
"BEGIN:DAYLIGHT",
"TZOFFSETFROM:+0100",
"TZOFFSETTO:+0200",
"TZNAME:CEST",
"DTSTART:19700329T020000",
"RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU",
"END:DAYLIGHT",
"BEGIN:STANDARD",
"TZOFFSETFROM:+0200",
"TZOFFSETTO:+0100",
"TZNAME:CET",
"DTSTART:19701025T030000",
"RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU",
"END:STANDARD",
"END:VTIMEZONE",
];