Repository navigation
refactor(events): collapse duplicated encodings across the verification lifecycle - #638
Merged
Ardnived merged 4 commits intoAug 19, 2026
Merged
Conversation
Five simplifications across the verification lifecycle, all removing a second encoding of a fact the stage table already knows: - `relationId` had two implementations; 7 of 10 call sites imported the one that can't parse a string id. Consolidated onto the complete one. - Every stage now declares an `attention` level. The sidebar bucket, the admin notice severity and the quality-check skip derive from it instead of each keeping their own per-stage table; `bucketForEvent`'s `default:` case (which silently labelled unfamiliar stages "verified") is gone, and the three tables that remain are exhaustive Records. - Deleted the `eventVerification` barrel (no importers) and the `UNMANAGED_STAGES` / `daysUntilUnpublish` exports nothing outside the module read. - `DAY_MS` is declared once in `lib/utilities/time` rather than inline in nine modules. - `addMonths` clamped: 31 Aug + 6 months was rolling into 3 March, so a finished event's retention ran a few days long. Co-Authored-By: Claude Opus 5 <[email protected]>
There were three near-identical hand-rolled HMAC token modules — eventVerification/token, registrations/unsubscribeToken, and the generic utilities/signedToken written for #625 — with the same twenty lines of crypto and subtly different validity checks. The two older ones are now thin wrappers that supply their claims, TTL and `kind`. Beyond the duplication, this closes a real gap: all four link kinds are signed with the same Payload secret, and only the envelope's `kind` discriminator (which the two older modules lacked) stops a token issued for one link from being replayed against another. Pinned by a test. `signToken` gains `ttlMs: null` for never-expiring tokens, which is what the unsubscribe link needs — it may legitimately be clicked months into a course, and the action it authorizes is narrow and idempotent. Existing verify / unsubscribe links in already-sent emails stop validating, since the envelope shape changed. Accepted: the events being reminded about are re-notified on the job's next run. Co-Authored-By: Claude Opus 5 <[email protected]>
`notificationLog` was a bare JSON array with a hand-written narrower (`Array.isArray(value) ? value as Entry[] : []`) — a cast, not a check, so a malformed entry landed in the column and every reader had to hope. It now carries a JSON Schema, which Payload uses to generate `Event['notificationLog']` AND to reject a bad write with a ValidationError. The stored shape is unchanged (still a bare array), so no data migration is needed. Adopted from the approach in #618, which this supersedes. The schema's enums are derived from VERIFICATION_STAGES and, for the two unions declared in an email template, from a `completeList` helper that makes an incomplete restatement a compile error — the types are imported type-only, so no react-email code reaches the admin client bundle. A pair of assignments in the unit spec fails to compile if the schema and the hand-written entry types drift apart; both guards were verified by mutation, as was the validation itself (an int case asserts a missing key, an undeclared key and an out-of-enum value are all rejected). Registrations.reminderLog is the same pattern and has NOT followed — its comments now say so rather than claiming a mirror that no longer holds. Co-Authored-By: Claude Opus 5 <[email protected]>
… go quiet `db:migrate` and `db:migrations:create` were aliases for `payload migrate` and `payload migrate:create`, and `payload` was a passthrough to a binary pnpm already resolves from node_modules/.bin. Three names for two commands meant docs used them interchangeably, and whenever a command failed the wrapper looked like the suspect. All removed; everything is `pnpm payload <command>`. The wrappers were never the problem. Three real causes, each traced to library source and now written up in .claude/rules/migrations.md: - Dev email calls `nodemailer.createTestAccount()` — a live request to ethereal.email — on every config load, so on every CLI invocation. When it fails the adapter throws, and payload's `bin.js` runs the CLI under a bare `void start()` with no `.catch()`, so the process dies with exit 0 and NO output. This is the intermittent one: `pnpm payload migrate:status` alternates between a full table and zero lines on successive runs. Documented, not yet fixed — killing the network call costs the ethereal preview URL, so it needs a decision first. - `generate:types` logs "Compiling TS types…" then returns early and silently when the compiled output matches the file on disk. Silence means "no schema change", not a hang. - A `src/migrations/index.ts` referencing a missing migration file breaks EVERY payload command, because payload.config.ts imports the index for `prodMigrations` and the index statically imports all 44 files. The ERR_MODULE_NOT_FOUND sits at the top of a long stack trace, so it scrolls away — and vanishes entirely when piped through head/tail. Co-Authored-By: Claude Opus 5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-638 environment in sahajcloud
|
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-638
August 14, 2026 22:36
Destroyed
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.
Follow-up to #624→#626: a simplification pass over the verification lifecycle those PRs touched. No behaviour changes except where noted — the point is to collapse places where one fact was encoded twice and could drift.
Stacked on
feat/event-feedback(#626), so it needs the stack to merge first.What changed
One
relationId. There were two implementations; 7 of 10 call sites imported the one that can't parse a string id. The complete one now lives inlib/utilities/relationIdand everything points at it. Latent bug: insyncVerificationOnSavea manager id that arrived as a string read as "no manager", i.e. pre-adoption.One attention level per stage. The sidebar bucket, the admin notice severity and the quality-check skip each kept their own per-stage table. Every stage now declares an
attention(ok/due/urgent/unpublished/ended) and the three consumers derive from it.bucketForEvent'sdefault:case — which had silently labelled the newunverified/deniedstages "verified" until #624 patched it — is gone, and the tables that remain are exhaustiveRecords, so a new stage is a compile error rather than a wrong colour.One HMAC token module.
eventVerification/token,registrations/unsubscribeTokenand the genericutilities/signedTokenfrom #625 were three copies of the same twenty lines with subtly different validity checks. The two older ones are now thin wrappers supplying their claims, TTL andkind.This closes a real gap rather than just deduplicating: all four link kinds are signed with the same Payload secret, and only the envelope's
kinddiscriminator — which the two older modules lacked — stops a token issued for one link being replayed against another. Pinned by a test.signTokengainsttlMs: nullfor the unsubscribe link, which may legitimately be clicked months into a course and authorizes a narrow idempotent action.notificationLoggets a JSON Schema. It was a bare array with a hand-written narrower —Array.isArray(value) ? value as Entry[] : []— which is a cast, not a check, so a malformed entry landed in the column and every reader had to hope. Payload now generatesEvent['notificationLog']from the schema and rejects bad writes with aValidationError. Stored shape is unchanged (still a bare array), so there is no data migration.This supersedes #618, now closed — same approach (array root, entry union keyed on
kind), plus enums derived fromVERIFICATION_STAGESand acompleteListhelper that makes an incomplete restatement of the two email-template unions a compile error. Those imports are type-only, so no react-email reaches the admin client bundle.Registrations.reminderLogis the same pattern and deliberately has not followed; its comments now say so instead of claiming a mirror that no longer holds.Smaller things. Deleted the
eventVerificationbarrel (no importers) and theUNMANAGED_STAGES/daysUntilUnpublishexports nothing outside the module read.DAY_MSdeclared once instead of inline in nine modules.addMonthsclamped — 31 Aug + 6 months was rolling into 3 March, so a finished event's retention ran a few days long.Payload CLI wiring
Separate commit, prompted by "these commands just exit without feedback".
db:migrate,db:migrations:createand thepayloadpassthrough are removed — pnpm already resolvespayloadfromnode_modules/.bin, so three names for two commands bought nothing and made the wrapper look like the suspect whenever a command failed. Everything ispnpm payload <command>; docs, skills and the permission allowlist swept to match.The wrappers were never the cause. Three real ones, each traced to library source and written up in
.claude/rules/migrations.md:nodemailerAdapter({})with notransportOptionsmeanscreateTestAccount()— a live HTTPS request — runs before any command does work. When it fails the adapter throws, and payload'sbin.jsruns the CLI under a barevoid start()with no.catch(), so the process dies with exit 0 and no output.pnpm payload migrate:statusalternates between a full table and zero lines on successive runs. Documented, not fixed — removing the network call costs the ethereal preview URL, so it needs a decision.generate:typessilence is success. It diffs against the file on disk and returns early when identical, before the "Types written" log.src/migrations/index.tsbreaks every payload command — the config imports it forprodMigrationsand it statically imports all 44 files. TheERR_MODULE_NOT_FOUNDis at the top of a long trace, so it scrolls away and vanishes entirely when piped throughhead/tail.Verification
lint,typecheck,typecheck:tests, 1182 unit tests, and 67 integration tests acrossevent-verification,expire-events,atlas-sidebarandevent-submissions— all green.Four assertions here could have passed vacuously, so each was flipped once to confirm it fails: the
addMonthsclamp (2027-03-03vs2027-02-28), thecompleteListexhaustiveness guard (droppingurgentis a compile error), the schema/hand-written-type drift guard, and the schema validation itself — an integration case asserts a missing required key, an undeclared key and an out-of-enum value are each rejected.🤖 Generated with Claude Code