Repository navigation
feat(emails): scheduled registration digests + session reminders - #596
Merged
Merged
Conversation
…atermark Schema for the scheduled notification job (#589): - Registrations.remindersUnsubscribedAt — set by the unsubscribe link; the reminder job skips a registration whose value is set (leaves the record). - Registrations.reminderLog — per-(registration, occurrence) exactly-once ledger, mirroring the Events notificationLog pattern. - Managers.lastRegistrationDigestSentAt — per-manager digest watermark. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Session-reminder chrome (subject/heading/intro/footer, unsubscribe CTA) and the unsubscribe landing-page copy, added to EMAIL_STRING_DEFAULTS and the emails translations group so both render in the registration's stored locale. Reuses the existing when/where/contact/CTA labels. The manager digest email is Atlas project brand + English (like EventRegistrationEmail), so it needs no keys. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
HMAC-SHA256 token over { registrationId }, signed with the Payload secret,
mirroring eventVerification/token.ts. No expiry: a reminder link may be clicked
weeks into a course, and unsubscribing is narrow + idempotent, so a replayed or
aged link can't harm — only the named registration is ever affected, and a
forged/altered id fails the signature check. buildUnsubscribeEmailLink points at
the /registrations/unsubscribe page (mutation runs on POST, not on GET).
Refs #589
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Registrant-facing reminder, a sibling of the confirmation sharing EmailLayout + the lifted StackedDetailRow + BrandButton. States the single upcoming occurrence (occurrenceLine / buildReminderEmailDetails), no session count, no ICS, and a footer unsubscribe link. sendSessionReminder mirrors sendRegistrationConfirmation (client brand, localized copy, Reply-To) and throws on failure so the job owns the retry policy. Lifts the confirmation's local label-above-value DetailRow into EmailLayout as StackedDetailRow (its own comment invited this once a second template needed it); rendered output is unchanged (email-templates unit suite still green). Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Manager-facing digest listing new registrations grouped by event — one email per recipient per period, not one per registration. Reuses EmailLayout + SectionHeading and the Sahaj Atlas project brand (internal notice, never client-branded), the manager-notice counterpart to EventRegistrationEmail. sendRegistrationDigest stubs non-email channels like the immediate notification and throws on failure so the digest job keeps the watermark on retry. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two tasks in one folder, both on the hourly nightly queue via exclusive concurrency: - SendSessionReminders (hourly): reminds each subscribed registration ~24h before a session. Enumerates occurrences from buildRRuleTemporal (exclusions applied), reminds for the single startingAt session or the whole series, dedups via the per-registration reminderLog ledger, skips unsubscribed/unpublished/trashed. Worst-case < 1h off "24h before" (documented in the module comment). - SendRegistrationDigests (daily 07:00 UTC; weekly on Monday): batches new registrations per manager, grouped by event, using the lastRegistrationDigestSentAt watermark for exactly-once. No empty digests; deterministic anchors. Registrations are read at depth 0 with users batch-loaded to avoid the #541 virtual-field N+1. Registers both slugs in the jobs barrel (picked up by payload.config.ts + testHelpers) and regenerates the task types. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Logged-out /registrations/unsubscribe page mirroring the event-verify flow: the signed token is the sole gate (invalid → 404), a GET shows a confirm button, and the mutation runs only on the POST server action — so an email link-scanner can't auto-unsubscribe. Sets remindersUnsubscribedAt (stops the reminder job) without touching the registration; idempotent, so a replayed link is safe. All copy renders in the registration's stored locale. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Additive: managers.last_registration_digest_sent_at, registrations. reminders_unsubscribed_at + reminder_log, and the two new job-slug enum values. DROP COLUMNs appear only in down() (rollback). Applies in-process on deploy. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Unit: unsubscribe-token forgery/replay/no-expiry, reminder-ledger coercion, and the reminder/digest email renders + occurrenceLine formatting. Int (via emailTestAdapter, deterministic — no wall-clock dependence): the reminder job's send + dedup-on-rerun + startingAt-single-session + unsubscribe/unpublished skips, and the digest job's grouped-per-event send + watermark dedup + Immediate unaffected + no-empty-digest + Monday-only weekly anchor. Adds a `req.context.now` clock seam to both handlers so the 24h window and the weekly anchor test deterministically. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Reuse the shared @/lib/utilities/relationId in both jobs (dropped two local copies). - Extract formatTimeSpan in registrationDetails, shared by timeSpan + occurrenceLine (removes the duplicated DST-safe span logic). - SendSessionReminders now reads registrations at depth 0 and batch-loads users, matching the digest job — avoids populating user/client for registrations with no reminder due and eliminates the double client load. Skipped: sharing PAGINATION_LIMIT across the two jobs (over-coupling a one-liner); lifting the unsubscribe CardShell to share with events/verify (outside this diff). Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- email.md: SessionReminderEmail + RegistrationDigestEmail rows, StackedDetailRow in the EmailLayout exports + guest-email note. - architecture.md: RegistrationNotifications scheduled-jobs section. - project-structure.md: unsubscribe token/url in the src/lib/registrations domain. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Extract the duplicated loadUsers into a shared job helper (introduced during the /simplify efficiency pass, so the simplify agents didn't see it). - Add a digest int test pinning the intended spec separation: a registrant's reminder-unsubscribe does NOT hide their registration from the manager digest (unsubscribe covers reminders only, per #589). Dismissed review findings (verified against source/spec): - send-then-persist ordering (reminder ledger / digest watermark) is the same accepted at-least-once trade-off as ExpireEvents; persist-then-send would risk missing a send. Normal re-runs/retries are dedup-proven by the int specs. - digest correctly omits _status / remindersUnsubscribedAt filters: it's the batched manager notification (unsubscribe is registrant-reminder-only), and filtering _status would miss real registrations for later-unpublished events. - recipient-null watermark stall is unreachable (managers are auth users with a required email; pickChannel falls back to it). Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-596
July 20, 2026 21:01
Destroyed
|
🚅 Deployed to the SahajCloud-pr-596 environment in sahajcloud
|
…ifications-scheduled
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-596
July 20, 2026 23:28
Destroyed
preview-reminder-digest-emails.ts drives the real sendSessionReminder / sendRegistrationDigest paths through a stub payload + Ethereal transport, so the subject/From/Reply-To/HTML/text match what the jobs send. Covers online/offline, locale fallback, branded/unbranded reminders, and daily/weekly digests. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- Include each registrant's registration-question answers (the digest job now loads `questions` and resolves them via buildRegistrationAnswers). - Give each registration its own white card (name, contact, chosen session, answers) so they're visually distinct in a busy digest. - Drop the redundant per-event count — the cards are the count; keep the grand total in the intro. Branded, ruled per-event headings as scan anchors. - Preview script: answers on every scenario + a high-volume weekly stress case (~35 registrations across 7 events) to gauge readability at scale. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Collapse each registration's name + email + chosen session onto one row (bold name · email · session) instead of stacking name and contact on separate lines — saves a row per registration, tightening high-volume digests. Answers unchanged; plain-text was already single-line. Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The bare per-registration date (the registrant's startingAt session) read ambiguously — it could be mistaken for a signup date. Prefix it with "Attending" in both the HTML and plain-text parts so it's self-explanatory, and its absence reads correctly as "no specific session chosen". Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The digest session date now uses a short form ("5 Aug 2025" via new
formatShortDate) instead of the long "Tuesday, 5 August 2025", tightening each
registration's identity line. formatShortDate wraps the existing private short
formatter and is exported alongside formatLongDate.
Refs #589
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Preview stress generator: fold the parallel event-title + count arrays into one
array of { title, count } objects (removes the index-sync risk).
Refs #589
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Refs #589 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-596
July 21, 2026 18:00
Destroyed
This was referenced Jul 22, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Daily/Weekly Summaryrecipients) and registrant session reminders (~24h before each session, with an unsubscribe link).reminderLogledger for reminders, a per-managerlastRegistrationDigestSentAtwatermark for digests.Design decisions (delegated by the ticket)
0 * * * *), so the notice always lands 23–24h before a session — worst-case deviation < 1h. Digests ride a coarser anchor: daily 07:00 UTC, weekly on Monday 07:00 UTC (deterministic). Documented in each job's module comment.Immediate/Never).registrationIdand the action is idempotent/non-destructive, so a link stays valid across a 12-week course.The digest email
Grouped by event, one email per manager per period. Each registration is a card — an inline identity line (name · email · "Attending ") plus the registrant's answers to the event's registration questions — with a compact date (
formatShortDate→ "5 Aug 2025"). No per-event count line; a grand total sits in the intro. Manager-facing, so it's Atlas-branded and English (not client-branded/localized).Changes
src/jobs/RegistrationNotifications/—SendSessionReminders(hourly) +SendRegistrationDigests(daily/weekly) +reminderLedger+ sharedloadUsers; registered viasrc/jobs/index.ts.src/emails/—SessionReminderEmail(client-branded, single occurrence, no ICS) +RegistrationDigestEmail(Atlas brand, grouped cards + answers); lifts the confirmation'sStackedDetailRowintoEmailLayout; addsformatShortDate.src/lib/notifications/—sendSessionReminder+sendRegistrationDigest+occurrenceLine/buildReminderEmailDetails.src/lib/registrations/—unsubscribeToken(HMAC, no expiry) +unsubscribeUrl.src/app/(frontend)/registrations/unsubscribe/— public page + server action + card (GET confirms, POST mutates; localized).src/collections/{Managers,Registrations}— watermark, reminder ledger, unsubscribe state.scripts/preview-reminder-digest-emails.ts— Ethereal preview for both emails (incl. a high-volume digest fixture).Migration
src/migrations/20260720_195203_registration_notifications.tsmanagers.last_registration_digest_sent_at,registrations.reminders_unsubscribed_at+reminder_log, and twopayload_jobstask-slug enum values. Existing rows unaffected (nullable columns).down()drops the columns and reverts the enums.Test Results
formatShortDate, email renders incl. digest answers/identity, occurrence formatting)startingAt+ unsubscribe/unpublished skips; digest grouping + answers + watermark + Immediate-unaffected + no-empty-digest + Monday-only weekly anchor + unsubscribe-separationNotes for reviewer
ExpireEvents): a normal re-run/retry sends nothing (dedup-proven by int specs); the only duplicate is the inherent window where a send succeeds but the mark write fails — persist-then-send would instead risk missing a send.remindersUnsubscribedAt— per the ticket, the unsubscribe link covers registrant reminders only, not manager notifications (pinned by a dedicated int test).Manual verification
pnpm payload jobs:run --queue nightly) with a published sahaj-atlas event whose next session is <24h away and a subscribed registration → registrant gets one reminder; the unsubscribe link opens the localized page and stops further reminders.Daily Summaryand new registrations → one grouped digest at the 07:00 UTC run. Preview both emails locally withpnpm tsx scripts/preview-reminder-digest-emails.ts.Closes #589
🤖 Generated with Claude Code