PR: #448: feat(perf): consume team + record bootstrap endpoints [Story-1780] by @ankitmaheshwari-com
View PR →
Story-1780

Consume the team + record bootstrap endpoints

The Settings → firm → team page used to fan out three server prefetches (members, seats & billing, firm roles) on every render; the matter record page fanned out three to four (matter, participants, documents, saved views). The backend (pramaan-functions Story-1779) now exposes one aggregate per page, so this change collapses each page to a single round-trip while keeping the exact same client hooks and props — the data just arrives composed.

What changed

Team: 3 fetches → 1

team/page.tsx calls membersGateway.teamBootstrap() once, then seeds the three existing per-resource caches with setQueryData under the generated appListMembersQueryKey / appGetSeatsAndBillingQueryKey / appListFirmRolesQueryKey. The client hooks (useAppListMembers etc.) hydrate warm — no refetch flash.

Invitations untouched

invitations + invitationReconciliation stay browser→Clerk exactly as before — the producer deliberately excluded them from the aggregate, so they remain separate prefetches running in parallel with the one bootstrap call.

Record: 3–4 fetches → 1

record/page.tsx calls mattersGateway.recordBootstrap(id) once. matter / participants.items / documents.documents pass straight to LiveMatterDocumentsPage as props; the matter is the anchor, so a 404 here still renders notFound() via orNotFound.

Saved views degrade gracefully

savedViews seeds appListDocumentSavedViewsQueryKey only when savedViewsAvailable is true. When the backend's best-effort saved-views sub-query degraded, the page skips seeding so the client hook refetches live rather than hydrating a misleading empty list.

Trust boundary (HR-21 / HR-22)

Both new gateway methods fetch as unknown and pass through assertContract against the generated teamBootstrapResponseSchema / recordBootstrapResponseSchema before any caller trusts the payload. Types and Zod schemas come only from src/gen, synced from pramaan-functions main (5776381) as the first commit of this PR. A drifted aggregate logs api_contract_violation and throws.

Where it lives

Verify

pnpm lint
pnpm test
pnpm build

Files changed

29 file(s), +2970 / -60 lines

Path Role + -
openapi/app-api.jsonConfig+250-0
src/app/[locale]/(workspace)/matters/[matterId]/record/page.tsxApp route+21-22
src/app/[locale]/(workspace)/settings/firm/team/page.tsxApp route+20-18
src/gen/client/appGetRecordBootstrap.tsGenerated contract+63-0
src/gen/client/appGetTeamBootstrap.tsGenerated contract+56-0
src/gen/client/index.tsGenerated contract+2-0
src/gen/hooks/index.tsGenerated contract+16-0
src/gen/hooks/useAppGetRecordBootstrap.tsGenerated contract+130-0
src/gen/hooks/useAppGetRecordBootstrapSuspense.tsGenerated contract+129-0
src/gen/hooks/useAppGetTeamBootstrap.tsGenerated contract+118-0
src/gen/hooks/useAppGetTeamBootstrapSuspense.tsGenerated contract+117-0
src/gen/index.tsGenerated contract+66-0
src/gen/schemas/recordBootstrapResponse.jsonGenerated contract+884-0
src/gen/schemas/teamBootstrapResponse.jsonGenerated contract+338-0
src/gen/types/AppGetRecordBootstrap.tsGenerated contract+69-0
src/gen/types/AppGetTeamBootstrap.tsGenerated contract+61-0
src/gen/types/RecordBootstrapResponse.tsGenerated contract+42-0
src/gen/types/TeamBootstrapResponse.tsGenerated contract+31-0
src/gen/types/index.tsGenerated contract+25-0
src/gen/zod/appGetRecordBootstrapSchema.tsGenerated contract+88-0
src/gen/zod/appGetTeamBootstrapSchema.tsGenerated contract+83-0
src/gen/zod/index.tsGenerated contract+23-0
src/gen/zod/recordBootstrapResponseSchema.tsGenerated contract+47-0
src/gen/zod/teamBootstrapResponseSchema.tsGenerated contract+36-0
src/lib/matters/gateway.tsLibrary+22-0
src/lib/members/gateway.tsLibrary+24-0
tests/unit/matter-documents-route.test.tsxTest+15-20
tests/unit/record-bootstrap-contract.test.tsTest+128-0
tests/unit/team-bootstrap-contract.test.tsTest+66-0