Skip to content

refactor(registration): align questions payload with EVENT_REGISTRATION_QUESTIONS - #63

Merged
Ardnived merged 3 commits into
mainfrom
refactor/registration-questions-contract
Jul 20, 2026
Merged

Ardnived merged 3 commits into
mainfrom
refactor/registration-questions-contract

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

  • Aligns the widget's registration questions payload with SahajCloud's newly-enforced EVENT_REGISTRATION_QUESTIONS contract (sydevs/SahajCloud#594): keys must be one of the five known question names and values must be strings, otherwise POST /events/:id/register now returns 400.
  • The key set is derived from the synced CMS type Event['registrationQuestions'] — not a hardcoded list — and pinned with a compile-time satisfies guard, so a future pnpm types:cms resync that adds or drops a question fails the build rather than silently drifting.
  • Net input hardening: the old z.record(z.string()) let arbitrary keys (including __proto__) pass client validation onto the wire; the tightened schema rejects unknown keys / non-string values client-side, mirroring the server.

Changes

  • src/types/event.ts — derive RegistrationQuestionName from Event['registrationQuestions']; guard RegistrationQuestionsSchema with satisfies Record<RegistrationQuestionName, z.ZodTypeAny>; expose REGISTRATION_QUESTION_NAMES + RegistrationQuestionNameSchema, both derived from that schema's shape (one guarded source of truth).
  • src/types/registration.ts — questions: z.record(RegistrationQuestionNameSchema, z.string()).optional().
  • src/views/RegistrationView/RegistrationView.tsx, src/components/organisms/RegistrationForm/RegistrationForm.tsx — narrow the questions type from string[] to RegistrationQuestionName[] so register(\questions.`)` stays type-checked against the tightened schema (runtime behaviour unchanged — same ordered subset of enabled questions).
  • src/types/payload/payload-types.ts — pnpm types:cms resync from SahajCloud main (committed separately as chore(types)); this refreshes the generated Event['registrationQuestions'] type the derivation reads from.
  • Tests — contract coverage in event.test.ts / registration.test.ts.

Verification

  • Lint: ✓ No errors (pnpm lint)
  • Types: ✓ Clean (pnpm typecheck)
  • Tests: ✓ Unit lane green — 248/248 (pnpm test:run)
  • Build: ✓ Covered by CI (no build-affecting runtime change)

Confirmation of the ticket's questions (issue #60)

  1. Keys — only the five names can reach questions: they come from enabledQuestions(event), which iterates the CMS boolean set; now also enforced at the zod boundary.
  2. Values — always strings (text / textarea fields); enforced by z.string().
  3. Unanswered enabled questions — the form submits '' (not an omitted key); SahajCloud accepts empty strings and drops blanks from the notification email. Covered by a test.
  4. Stale generated types — resynced here. Note Registration.questions is still a loose Payload JSON field in the generated types even after #594 (only its doc comment updated), so the derivation reads from Event['registrationQuestions'] instead — which carries the five typed keys.

Notes for reviewer

  • The payload-types.ts resync is large and cross-collection (locale enums, Region.eventDefaults removal, etc.) but it is generated, typechecks cleanly, and we reference none of the removed/renamed fields. Bundled here by request; it could alternatively land as its own chore(types) PR.
  • Optional follow-up: public/locales/*/events.json still carries stale questions.* label keys (aspirations, experience, referral, questions) that can no longer render now that only the five canonical names are emitted — safe to prune across locales separately.

Closes #60

🤖 Generated with Claude Code

Ardnived and others added 3 commits July 20, 2026 13:27
Regenerated via `pnpm types:cms`. SahajCloud main has advanced broadly since
the last sync — this refreshes ~20 interfaces (locale enums now include en-AU/
hu/nl and pt-BR casing, Region.eventDefaults dropped, User/Frame/Form/Client
shape updates, and the Registration.questions doc comment now names the
EVENT_REGISTRATION_QUESTIONS keys).

Typechecks cleanly; we don't reference any of the removed/renamed fields. Done
here so #60 can derive the registration-question key set from the freshly
synced Event['registrationQuestions'].

Refs #60

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…on keys

The registration `questions` payload was typed loosely as
`z.record(z.string())`. SahajCloud now validates it (PR sydevs/SahajCloud#594):
keys must be EVENT_REGISTRATION_QUESTIONS members and values strings, else the
register endpoint 400s. Align the client to that contract before it ships.

- Derive `RegistrationQuestionName` from the synced `Event['registrationQuestions']`
  CMS type (not a hardcoded list). A `satisfies Record<RegistrationQuestionName, …>`
  on `RegistrationQuestionsSchema` fails the build if a `types:cms` resync adds or
  drops a question, and `REGISTRATION_QUESTION_NAMES` / `RegistrationQuestionNameSchema`
  derive from that schema's shape — one guarded source of truth.
- Tighten `RegistrationSchema.questions` to `z.record(RegistrationQuestionNameSchema,
  z.string())`, which rejects unknown keys / non-string values client-side, mirroring
  the server.
- Narrow `enabledQuestions()` and the RegistrationForm `questions` prop from
  `string[]` to `RegistrationQuestionName[]` so `register(\`questions.<name>\`)` stays
  type-checked against the tightened schema (behaviour unchanged — same ordered subset).
- Cover the contract in the type tests: valid subset, empty-string answer (an
  enabled-but-unanswered question), omitted questions, unknown key, non-string value.

Closes #60

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Per the /simplify pass: `REGISTRATION_QUESTION_NAMES` *is* `Object.keys(
RegistrationQuestionsSchema.shape)`, so asserting them equal compared a value to
itself and could never fail. The concrete-list assertion already pins the key
set + order.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 70f9a3b
Status: ✅  Deploy successful!
Preview URL: https://a16e8e76.sahajatlas.pages.dev
Branch Preview URL: https://refactor-registration-questi.sahajatlas.pages.dev

View logs

@Ardnived
Ardnived merged commit 644f83a into main Jul 20, 2026
4 checks passed
@Ardnived
Ardnived deleted the refactor/registration-questions-contract branch July 20, 2026 23:43
Ardnived added a commit that referenced this pull request Jul 21, 2026
Reconcile with two PRs that landed on main during this branch's Adjust phase:

- #63 refactor(registration): align questions payload with
  EVENT_REGISTRATION_QUESTIONS — took its tightened `questions` typing
  (`z.record(RegistrationQuestionNameSchema, z.string())`) and the
  `RegistrationQuestionName[]` prop narrowing on RegistrationForm/RegistrationView,
  and took its fresh SahajCloud-main `payload-types.ts` resync over this branch's
  local-seed sync. Kept this branch's removal of the mailing-list `subscribe`
  field (1f0b768) — dropped #63's adjacent re-introduction of it. Updated the
  RegistrationForm "With questions" story to pass CMS question keys
  (referralSource, priorExperience) instead of free-text labels.
- #59 docs(skills): workflow parity — merged cleanly with this branch's
  renamed molecules list in CLAUDE.md.

Lean gate green after merge: lint + typecheck + 309 unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confirm registration questions payload keys align with SahajCloud's EVENT_REGISTRATION_QUESTIONS

1 participant