push to maple-street

This commit is contained in:
Tiel Coder
2026-11-20 04:07:02 +00:00
parent 2cec220a24
commit 5adf1cef1f
345 changed files with 86105 additions and 1079 deletions
+189
View File
@@ -0,0 +1,189 @@
/**
* Email templates — unit E3 (ARCHITECTURE §6.3).
*
* Pure: no DB, no transport. Rendering happens at **enqueue** time
* (`payload_json` is fully merged then, per §4), so what the outbox stores is
* exactly what will be sent — auditable and replayable.
*
* Every interpolated value is HTML-escaped: names, role names and locations are
* admin/volunteer-supplied data, and an email client will happily render
* injected markup.
*/
/** Everything one assignment.published email needs, already resolved. */
export interface AssignmentEmailContext {
volunteerFirstName: string;
roleName: string;
serviceName: string;
/** e.g. "Sunday, Nov 22" in the church timezone. */
occursOnLabel: string;
/** e.g. "9:00 AM". */
startTimeLabel: string;
/** e.g. "8:15 AM" — null when the role has no call-time offset. */
callTimeLabel: string | null;
location: string;
confirmUrl: string;
declineUrl: string;
}
export interface RenderedEmail {
subject: string;
html: string;
text: string;
}
/** Escape text for safe interpolation into HTML. */
export function escapeHtml(value: string): string {
return value
.replaceAll("&", "&")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#39;");
}
const CALL_TIME_UNSET = "Check the schedule for your call time";
/** The assignment.published email: role, date, call time, confirm/decline. */
export function renderAssignmentPublishedEmail(
ctx: AssignmentEmailContext,
): RenderedEmail {
return renderAssignmentEmail(ctx, `You're on ${ctx.roleName} — ${ctx.occursOnLabel}`);
}
/** A reminder for the same assignment (E7): same body, reminder subject. */
export function renderAssignmentReminderEmail(
ctx: AssignmentEmailContext,
): RenderedEmail {
return renderAssignmentEmail(
ctx,
`Reminder: ${ctx.roleName} on ${ctx.occursOnLabel}`,
);
}
export interface EventReminderContext {
volunteerFirstName: string;
/** "Photographer", "Second shooter" or "Editor". */
roleLabel: string;
eventTitle: string;
eventType: string;
occursOnLabel: string;
startTimeLabel: string;
location: string;
eventUrl: string;
/** Days before the event the message is sent — "2" reads "in 2 days". */
leadDays: number;
}
/** The one-off event reminder (photo shoot): date, time, place, brief link. */
export function renderEventReminderEmail(
ctx: EventReminderContext,
): RenderedEmail {
const firstName = escapeHtml(ctx.volunteerFirstName);
const roleLabel = escapeHtml(ctx.roleLabel);
const title = escapeHtml(ctx.eventTitle);
const type = escapeHtml(ctx.eventType);
const occursOn = escapeHtml(ctx.occursOnLabel);
const startTime = escapeHtml(ctx.startTimeLabel);
const location = escapeHtml(ctx.location);
const eventUrl = escapeHtml(ctx.eventUrl);
const lead =
ctx.leadDays === 0
? "today"
: ctx.leadDays === 1
? "tomorrow"
: `in ${ctx.leadDays} days`;
const subject = `Reminder: ${ctx.eventTitle} — ${ctx.occursOnLabel}`;
const html = `<!doctype html>
<html>
<body style="font-family: system-ui, sans-serif; line-height: 1.5; color: #111827;">
<h1 style="font-size: 20px;">${firstName}, you're shooting ${title} ${escapeHtml(lead)}</h1>
<p>
${title} (${type})<br />
${occursOn} at ${startTime}<br />
${location}<br />
You're on as ${roleLabel}.
</p>
<p>
<a href="${eventUrl}" style="display:inline-block;padding:10px 16px;background:#932822;color:#fff;border-radius:6px;text-decoration:none;">Open the event brief</a>
</p>
<p style="font-size: 12px; color: #6b7280;">
Check the brief for what to capture and where to deliver the files. If you
can no longer make it, tell the team as soon as you can so a replacement
can be found.
</p>
<p style="font-size: 12px; color: #6b7280;">Media Team Hub · Glenloch</p>
</body>
</html>`;
const text = [
`${ctx.volunteerFirstName}, you're shooting ${ctx.eventTitle} ${lead}`,
"",
`${ctx.eventTitle} (${ctx.eventType})`,
`${ctx.occursOnLabel} at ${ctx.startTimeLabel}`,
ctx.location,
`You're on as ${ctx.roleLabel}.`,
"",
`Brief: ${ctx.eventUrl}`,
"",
"If you can no longer make it, tell the team so a replacement can be found.",
].join("\n");
return { subject, html, text };
}
function renderAssignmentEmail(
ctx: AssignmentEmailContext,
subject: string,
): RenderedEmail {
const callTime = ctx.callTimeLabel ?? CALL_TIME_UNSET;
const firstName = escapeHtml(ctx.volunteerFirstName);
const roleName = escapeHtml(ctx.roleName);
const serviceName = escapeHtml(ctx.serviceName);
const occursOn = escapeHtml(ctx.occursOnLabel);
const startTime = escapeHtml(ctx.startTimeLabel);
const callTimeHtml = escapeHtml(callTime);
const location = escapeHtml(ctx.location);
const confirmUrl = escapeHtml(ctx.confirmUrl);
const declineUrl = escapeHtml(ctx.declineUrl);
const html = `<!doctype html>
<html>
<body style="font-family: system-ui, sans-serif; line-height: 1.5; color: #111827;">
<h1 style="font-size: 20px;">${firstName}, you're on ${roleName}</h1>
<p>
${serviceName}<br />
${occursOn} at ${startTime}<br />
Call time: ${callTimeHtml}<br />
${location}
</p>
<p>
<a href="${confirmUrl}" style="display:inline-block;padding:10px 16px;background:#932822;color:#fff;border-radius:6px;text-decoration:none;">Confirm</a>
&nbsp;
<a href="${declineUrl}" style="display:inline-block;padding:10px 16px;border:1px solid #6b7280;color:#111827;border-radius:6px;text-decoration:none;">Can't make it</a>
</p>
<p style="font-size: 12px; color: #6b7280;">
No login needed — the links above are single-use. If you can't serve,
please decline so a coordinator can find cover.
</p>
<p style="font-size: 12px; color: #6b7280;">Media Team Hub · Glenloch</p>
</body>
</html>`;
const text = [
`${ctx.volunteerFirstName}, you're on ${ctx.roleName}`,
"",
ctx.serviceName,
`${ctx.occursOnLabel} at ${ctx.startTimeLabel}`,
`Call time: ${callTime}`,
ctx.location,
"",
"Confirm: " + ctx.confirmUrl,
"Can't make it: " + ctx.declineUrl,
"",
"No login needed — the links are single-use.",
].join("\n");
return { subject, html, text };
}