Repository navigation
feat(api): migrate widget intakes to unified form-submissions - #213
Conversation
`pnpm types:cms`, now that SahajCloud#800 is deployed. `Registration`, `UserMessage` and `EventSubmission` are gone; `UserSubmission` carries all four public intakes, told apart by `type`. Two things this sync does NOT do, and both matter to the commits after it. `EventRegistrationResponse` is deleted upstream — the endpoint that returned it no longer exists — and nothing in this repo imported it, so nothing here failed to compile. `EventRegistrationErrorCode` survives, and the codes are unchanged; only where they sit in the body moved, to `errors[].data.code`. ⚠ `pnpm types:openapi`, the other half of the contract step, could not run: it needs `SAHAJCLOUD_DOCS_PASSWORD`, which this environment does not carry. The OpenAPI snapshot is therefore untouched here and stays a step behind. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SrTZTuctcEKzSAkmP6TkYS
Registration and report-an-issue have been failing against the live CMS since
SahajCloud#800 deployed: `main` still posted to `POST /events/:id/register` and
`POST /user-messages`, and both are deleted. A visitor filling in the
registration form got the generic "Something went wrong" panel; an issue report
reached nobody. This is a repair, not a scheduled migration.
Both now create a row on `POST /user-submissions`, told apart by `type`.
**Everything but the typed columns rides as `submissionData: [{ field, value }]`.**
Not an object — the collection bounds the keys per type and answers 400 naming
the offending key, so an object body would fail the whole create. A blank value
is dropped rather than sent: a submission is capped at 40 pairs, and an
untouched textarea is not an answer.
- **Registration** sends `{ type, event, startingAt, senderEmail }` plus `name`,
`locale` and the question answers as pairs. `locale` was a top-level body
field; losing it in the move would have sent every registrant an English
confirmation email regardless of what they registered in.
- **The report** sends a `contact` row, its `subject`, `message` and the five
context values flattened into the same array. It names **no `form`**: a form
would decide the recipient and widen the keys the row may carry, and this
channel has one fixed destination, so it takes the CMS contact address by
omission.
**The refusal stays synchronous, which is the property the form depends on.**
`gateRegistration` is a `beforeValidate` hook, so a full, ended, closed or
external event is refused by the request that tried to register, with the same
four codes as before. Nothing became a background screening.
⚠ **The code moved to `errors[].data.code`, and `asRefusal` still reads both
positions.** Payload's `formatErrors` nests an `APIError` payload under `data`;
the flat position is what the hand-written endpoint built. Dropping either would
turn a whole class of refusal into the generic "try again" sentence, silently —
a spec now reintroduces each half and fails.
One behaviour genuinely changes: a missing event answers 404 with
`event_not_found`, where the old endpoint sent a bare 404. It is not in the
synced union, so the form has no copy for it and falls back to the generic
sentence, as it does for any code this build does not know. It arrives as a
refusal rather than a raw failure, which resets the spent captcha — correct for
an event that has vanished.
`sendUserMessage`, `UserMessageErrorCode` and `UserMessageRefusedError` are
renamed after what they do rather than a collection that no longer exists.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SrTZTuctcEKzSAkmP6TkYS
SahajCloud#800 folded `event-submissions` into `user-submissions`, and its `livePreviewUrl` composes the new slug. The widget still matched the old one. ⚠ **A stale slug here does not fail a build — it fails quietly.** The gate is a string equality in `readLivePreviewParams`, so an unrecognised collection reads as no collection at all: `resolveLivePreviewTarget` finds no document in the path, the controller returns null, and a reviewer opening a proposal gets the ordinary atlas with no sign that anything was refused. Typecheck stayed green through the whole breakage. `boot.test.ts` now lists `event-submissions` among the collections `/preview` must refuse, so the old spelling cannot quietly come back. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SrTZTuctcEKzSAkmP6TkYS
…ing a synchronous email Review found two claims in the first pass that the CMS contradicts, both checked against SahajCloud `main`. **A `contact` row with no `form` is refused today.** `needsForm` makes `form` required for every contact submission — "it has nowhere to go without a form's `recipient`" — and SahajCloud's own integration spec pins this exact body as `['form: This field is required.']`. That is a `ValidationError`, which carries no `errors[].data.code`, so `asRefusal` passes it through and the viewer gets the generic failure. So the report form is NOT repaired by the previous commit, and the changelog said it was. ⚠ The CMS contradicts itself here, which is why this is not fixed on this side: `deliverContact` resolves a form-less row to the system contact address and documents that case as legitimate for this widget, while the validator refuses it. Inventing a form id here would need a `forms` read this client cannot make, and would put the choice of recipient in the browser. The fix belongs in `needsForm`. **The registration confirmation email is a job now.** It was in-request best-effort at the deleted endpoint; `deliverRegistration` moved it, for retries and an activity-log entry per attempt. The row and its `uuid` are still real when the promise resolves — the email is not yet sent. So the "201 means ACCEPTED, not delivered" rule the report has always carried now applies to registration too, and the changelog claimed the opposite. Also sweeps three comments still naming a deleted endpoint or the retired `event-submissions` slug. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SrTZTuctcEKzSAkmP6TkYS
Deploying sahajatlas-design with
|
| Latest commit: |
4204c11
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8bd8a7ff.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://claude-feat-195-user-submiss.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| Latest commit: |
4204c11
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://06f53a14.sahajatlas.pages.dev |
| Branch Preview URL: | https://claude-feat-195-user-submiss.sahajatlas.pages.dev |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is no bigger than the ticket: two call sites re-pointed, the live-preview slug followed, the rest renames. I checked the wire shape against SahajCloud main rather than the PR body, and it holds. The needsForm / deliverContact contradiction is real as described.
Closes #195 is the one shape-level problem. It closes the ticket on merge while report-an-issue stays broken and the opt-in criterion is dropped, and no SahajCloud issue exists for the fix. Drop Closes #195, or file the upstream issue with /workflow:cross-repo-issue.
Findings
- blocker — the fix's only breadcrumb points at the issue this PR closes (
mutate.ts:288). - consider — an over-long registration answer 400s the whole registration (
mutate.ts:200).
What was checked
Against SahajCloud main @ 07e3e40: the registration key set and value bounds (submissionData.ts), the synchronous gate (gateRegistration.ts), the name/locale pairs deliverRegistration reads, collection: 'user-submissions'. All match.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
…imit A registration answer reached `submissionData` unbounded. `RegistrationSchema.questions` is `z.record(name, z.string())` with no ceiling, and the question textarea set no `maxLength`, while SahajCloud bounds one value at `DEFAULT_MAX_VALUE_LENGTH` — none of `experience`, `referral`, `aspirations` or `questions` is in its `VALUE_MAX_LENGTHS` overrides. So a 2001-character answer refused the whole registration as a `ValidationError`, which carries no `errors[].data.code`, so the registrant got the generic panel and lost everything they had typed. `name` rides in the same blob under the same default bound, and was unbounded for the same reason — its regex constrains the alphabet, not the length. The bound goes on the control, not on the wire. The report path next door already draws that line: it clamps `userAgent`, a machine string where truncation costs nothing, and stops the viewer at `REPORT_MESSAGE_MAX` for the message, because silently dropping the end of prose somebody wrote is worse than telling them where the limit is. The same figure now has one definition, `SUBMISSION_VALUE_MAX`, which the report's context clamps already used. Both new assertions were driven red by removing the attribute at its own call site. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01H5CYQN8RchZFbBK9wJaq3P
|
Both review threads answered. One commit pushed: c88cc9a. Adopted — an over-long answer 400s the whole registration. The name and every question answer now stop at Adopted, second route — the fix's only breadcrumb points at the issue this PR closes. One decision waiting on you, which is why that thread stays open: the SahajCloud tracker for Lean gate green — 120 files, 1526 tests. Both new assertions were driven red at their own call sites first. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
The `needsForm` / `deliverContact` contradiction that 400s every report-issue submission had no ticket of its own. Its only breadcrumb named #195, the consumer ticket, which records the client half and cannot hold a fix that belongs in SahajCloud's collection. It is now sydevs/SahajCloud#813, verified against SahajCloud `main` @ `5c835b4`: `needsForm` (`fields.ts:175`) requires `form` for every `contact` row, while `deliverContact.ts:13` calls the form-less fallback to `CONTACT_EMAIL` "load-bearing rather than defensive" for this exact widget, and `user-submissions-create.int.spec.ts:389` pins the refusal. That ticket also records what a naive fix would break: `FORM_BACKED_TYPES` is read twice, once to require a form and once to reject a type that names one, so dropping `contact` from it would start refusing every CMS-authored contact form's own submissions. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_011JgdqxogHAsZXQPFEYgnzX
|
One thread answered, one commit pushed: db8f549. Adopted — go ahead and file the upstream issue. Filed as SahajCloud#813, with the evidence re-verified against SahajCloud One thing that ticket records and the thread did not: No child ticket here: #195 already holds this repo's remaining criteria, and a Lean gate green — 120 files, 1526 tests. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
CI is still red after 3 fix attempts (failing: Smoke). I have stopped retrying. A comment or a push from you starts me again. 🤖 sydevs dispatcher |
The sahajatlas Pages build for 3d8c102 stalled ~38 min and failed with no reproducible cause; the same tree builds cleanly locally (tsc, vite, assert:css, assert:maps). Smoke failed only because no preview existed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
CI is still red after 3 fix attempts (failing: Smoke). I have stopped retrying. A comment or a push from you starts me again. 🤖 sydevs dispatcher |
#213 renamed the live-preview collection `event-submissions` -> `user-submissions` in the same four files this branch rewrites, so both sides made the same rename and only one side may keep its structure. `protocol.ts` keeps this branch's `LIVE_PREVIEW_COLLECTION` const over main's `LivePreviewCollection` type — nothing reads the slug off the URL any more, so the type has no caller. Main's ⚠ on the slug being the CMS's own, and its SahajCloud#800 breadcrumb, are folded into the const's doc. `boot.ts` and its spec keep this branch's session shape. Main renamed the literal inside the `collection` field this branch deletes, so there is nothing of main's left to carry. The spec's collection loop gains `event-submissions`, main's case: the stale spelling opened a session while the field was read, and now no spelling does. `LivePreviewController.tsx` keeps this branch's submission arm. Main's comment there says `/preview` consumes nothing yet and names SahajCloud#723 as the owner — which is what this branch implements. The #723 breadcrumb stays in `protocol.ts`. Generated `src/types/payload/` is byte-identical on both sides: both resynced from the same SahajCloud main. Lean gate green on the merge — 121 files, 1548 tests. `pnpm build` + `pnpm size` green: standalone 295.1 / 308 KiB, embed 297.0 / 308 KiB, loader 2.6 / 3.5 KiB, unchanged. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Y7eKS8HdUiPKbjNhVmy9eR
The note said "the previous entry", but the warning it supersedes sits below, in the [#195] entry. That entry's own replacement text already says "[#213] above", so both now read correctly in a file read top to bottom. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MJVd4rhuSMvgpuDVuUXVAc
The entry explained [#213] by a report naming no form and taking the contact address by omission. The collection refuses such a row now (mutate.ts:308) — the row names the authored form. With no release boundary in this file, a superseded mechanism reads as current, which is the same failure the stale warning above it caused. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MJVd4rhuSMvgpuDVuUXVAc
Summary
POST /user-submissions. Both posted to endpoints SahajCloud#800 deleted, so both have been failing in production.contactrow this widget must send. That fix is now tracked as SahajCloud#813. See Notes.user-submissionsslug. It had been silently resolving to no document at all.Changes
src/config/api/mutate.ts— both mutations onto one path,typediscriminated; free-form values ride assubmissionData: [{ field, value }].sendUserMessage→sendReport.CONTEXT_MAXbecomes the exportedUSER_SUBMISSION_VALUE_MAX, one definition of the collection's per-value bound. The blocker's breadcrumb names SahajCloud#813.USER_SUBMISSIONS_PATH,UserSubmissionResponse(Schema),USER_SUBMISSION_VALUE_MAX, andReportErrorCode/ReportRefusedError→UserSubmissionErrorCode/UserSubmissionError. Those five codes mirror the write-guard plugin'sAntiSpamCode, and that plugin sits above every collection, so they were never report-specific.submissionDatakeeps its name — it builds the collection's own field. The forms and the two intake functions keep theirs.src/components/organisms/RegistrationForm/RegistrationForm.tsx— the name and every question answer stop atUSER_SUBMISSION_VALUE_MAX. An over-long one used to refuse the whole registration as aValidationError, which carries no code, so the registrant lost everything they typed to the generic panel.src/config/live-preview/{protocol,boot}.ts— the/previewboot route's collection slug.docs/rules/data-layer.md— the report path's blocker note names SahajCloud#813 too.src/types/payload/—pnpm types:cmsagainst SahajCloudmain.Preview
Both Cloudflare projects deployed
c88cc9asuccessfully. A new alias follows 3d8c102.Contract impact
Consumes SahajCloud#695 / #800. One open cross-repo blocker, and it is the reason half this PR does not work:
needsForm(src/collections/UserSubmissions/fields.ts) makesformrequired for everycontactrow — "it has nowhere to go without a form'srecipient" — and SahajCloud's own spec pins this exact body as['form: This field is required.'](tests/int/user-submissions-create.int.spec.ts). ButdeliverContact.tsresolves a form-less row to the system contact address and documents that case as legitimate for this widget. The validator and the delivery layer disagree.This ticket's wire contract says "No form reference — recipient falls back to the CMS contact address, as today," which matches the delivery layer, not the validator. The fix belongs in
needsForm. A form id invented here would need aformsread this client cannot make, and would put the choice of recipient in the browser.It is tracked as SahajCloud#813, filed once the reviewer said to. Both breadcrumbs here point at it. That ticket carries the evidence re-verified against SahajCloud
main@5c835b4, and one trap a naive fix would hit:FORM_BACKED_TYPESis read twice — once to require a form, once to reject a type that names one — so droppingcontactfrom it would start refusing every CMS-authored contact form's own submissions.⚠
Closes #195has been removed from this body on purpose. Three of that ticket's acceptance criteria are unmet, so auto-closing #195 on merge would leave the remainder recorded nowhere. #195 stays open to hold it.Test results
pnpm lint && pnpm typecheck && pnpm test:run— 120 files, 1526 tests, re-run on 3d8c102mutate.test.ts26,boot.test.ts18,RegistrationForm.test.tsx2,ReportIssueForm.submit.test.tsx— all passing--full— production build plus size budget (standalone 297.2, loader 2.9, embed 299.5 KiB), measured before the last three commits, none of which adds an importEvery new assertion was driven red before being kept. Each defect was reintroduced at its own site, not near it:
/events/:id/registercontextobjectentryCodestops reading the flat positiontype: 'registration'dropped from the bodyevent-submissionsslugmaxLengthoff the question textareamaxLengthoff the name inputManual verification
Everything below needs a real CMS — every spec here mocks
@payloadcms/sdk, so none of it proves the collection accepts these bodies.registrationrow should exist withname,localeand any answers assubmissionDatapairs.errors[].data.codepath.localepair carries).form— rather than some other way.Notes for reviewer
Three acceptance criteria are not met, and one is out of this repo's reach.
contactrow — blocked upstream on SahajCloud#813, above. The migration ships anyway:main404s and this 400s, so nothing regresses, and the client is then on the right contract for a one-line CMS fix. Say the word if you would rather hold the whole PR until SahajCloud moves.sy-atlas-translationshas no key, and copy is CMS-owned, so I cannot invent one). I did not add an unusedsubscribeparameter for a checkbox that does not exist. Needs a CMS copy key first; happy to do it as a follow-up once the key ships.type: 'proposal'— this repo never posted one. The widget only ever previewedevent-submissions; the create lives CMS-side. What that item actually costs here is the live-preview slug, which is in this PR. No proposal mutation was added.One naming decision is still open, from the review pass on the 17th. The two refusal classes did not merge:
RegistrationRefusedErrornow sits besideUserSubmissionError. Merging their code unions would need CMS copy keys for the guard's codes, whichsy-atlas-translationsdoes not carry, so the asymmetry is deliberate rather than an oversight. Say the word and it goes.⚠
pnpm types:openapi, the second half of the contract step, could not run — it needsSAHAJCLOUD_DOCS_PASSWORD, which this environment does not carry. The OpenAPI snapshot is untouched and stays a step behind.Detail
Typecheck was green through the entire breakage, in both directions. Nothing in this repo imported
EventRegistrationResponse, and the live-preview slug is a bare string equality — so neither the dead endpoints nor the dead collection failed a build. That is why the specs, not the compiler, carry this contract.asRefusalstill reads botherrors[].codeanderrors[].data.code. Everything the widget writes to is collection-backed now, so Payload'sformatErrorsnests it underdata; the flat position is what the deleted endpoint built. Dropping either silently degrades a whole class of refusal to "try again", so both are pinned.One behaviour genuinely changes. A missing event answers 404 with
event_not_found, where the old endpoint sent a bare 404. It is not inEventRegistrationErrorCode, so the form falls back to the generic sentence, as it does for any unknown code — but it arrives as a refusal, which resets the spent captcha. Correct for an event that has vanished.Response schemas pin
doc.idonly, withuuidoptional. The repo's existing rule: pinning a field nothing reads turns a harmless CMS rename into a failed submission for every sender. Nothing consumesuuidyet.The transport shapes stay in
mutate.ts, not insrc/types/.src/types/payload/is generated —pnpm types:cmscurlsresponse-types.tswholesale from SahajCloud, so a hand-written line there is gone on the next sync, and that file is deliberately import-free plain TypeScript so a cross-repo curl of it resolves, which rules out a zod schema outright.src/types/proper holds the domain entities components render;UserSubmissionResponseSchemaandRefusalBodySchemaare wire envelopes with one reader each, beside that reader.The length bound goes on the control, not on the wire, and the report path next door is why both halves of that read the way they do. It clamps
userAgent, a machine string where truncation costs nothing and losing a bug report to a long browser string would be the worst possible trade. It stops the viewer atREPORT_MESSAGE_MAXfor the message, because silently dropping the end of prose somebody wrote is worse than telling them where the limit is. Registration answers are prose, so they get the second treatment.namewas unbounded for the same reason the answers were — its regex constrains the alphabet, not the length — and rides in the same blob under the same default bound, so it is fixed here too.Review passes run:
/code-review high(4 findings, all verified against SahajCloudmainand all fixed — the form blocker, the confirmation-email claim, and three stale comments);/security-review(no findings; it confirmed the Turnstile token stays in the header, the live-preview gate is still an exact-match allowlist behind a verified token, andclientis still withheld);comment-lintclean./pr-review-toolkit:review-pris not installed in this environment, so/code-reviewstood in for it.Part of #195
🤖 Written by the sydevs autonomous loop — see what this is