feat(forms): server actions, Zod schemas, and dynamic answer validation (Phase 2)

- lib/validations.ts: form field/array schemas (8 field types,
  duplicate-key and select-options refinements) and create/update/
  status/submit/link envelope schemas; slug immutable on update
- lib/forms-schema.ts: pure parseFormSchema + validateAnswers; unknown
  answer keys are discarded so a caller cannot inject arbitrary jsonb
- lib/actions/forms.ts: create/update/setStatus/delete/list/results/
  CSV export (forms.manage via user_has_permission + RLS), submitForm
  (service-client read+write, visibility + waiver consent enforced,
  schema/legal/version snapshot, IP/UA capture), and
  linkSubmissionsForMember (manual admin link; auto path is Phase 5)
- updateForm bumps a published waiver's version on legal/schema change
  (non-blocking; existing submissions stay valid against their snapshot)
- deleteForm refuses when submissions exist (immutable records)
- types/database.ts: type user_has_permission/user_effective_roles
  (stale since migration 023)
- __tests__/forms.test.ts (14); API_REFERENCE + HANDOFF updated

285/285 tests, build clean. No deploy.
This commit is contained in:
Moheeb Zara
2026-05-16 14:51:20 -07:00
parent 66dd9b7ec0
commit 897fa30ec1
8 changed files with 819 additions and 4 deletions
+5
View File
@@ -1576,6 +1576,11 @@ export type Database = {
Args: { allowed_roles: string[]; sid: string; uid: string }
Returns: boolean
}
user_effective_roles: { Args: { uid: string; sid: string }; Returns: string[] }
user_has_permission: {
Args: { uid: string; sid: string; perm: string }
Returns: boolean
}
}
Enums: {
area_lead_status: "active" | "vacant" | "handoff"