#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
Portal data layer — mock backend & handover
The mocks here are for Storybook and tests — the running portal hits the
real network. Every screen fetches real HTTP requests through a thin typed API
layer; in Storybook (via msw-storybook-addon, see .storybook/preview.tsx)
and in vitest those requests are intercepted by MSW and
answered with fixture data.
One deliberate in-app exception: api/demoData.ts can answer apiClient
calls from these same handlers while explicitly enabled (the onboarding tour
does this so views render populated). No service worker, no interception —
msw and the fixtures load lazily on first enable and stop answering on
disable.
The three layers
view (useAsync) ──► api/<surface>.ts ──► httpJson(fetch) ──► real backend (app)
(the contract) └► MSW handler (Storybook/tests) ──► fixture builder
api/<surface>.ts— thin, typedhttpJsonwrappers plus the canonical TS types and app-owned constants. This is the backend contract. Each function documents its endpoint (method, path, query params) and its response type. Nothing else in the app issues fetches, and nothing in the app imports frommocks/.mocks/handlers/<surface>.ts— MSW handlers that answer those endpoints withmocks/<surface>.tsfixtures. Registered inmocks/handlers/index.ts.mocks/<surface>.ts— fixture builders only, importing their types fromapi/<surface>.ts(mocks depend on the contract, never the reverse).
api/http.ts is the single fetch wrapper (sets headers, throws HttpError on
non-2xx). Views consume via useAsync() + useSectionFlags() (hooks/useAsync.ts).
Conventions (consistent across every surface)
- Tier: tier-specific endpoints take
?tier=free|pro|enterprise. The view passesuseTier().tierand refetches on change (useAsync(fn, [tier])). - Latency: handlers
await delay(120)to exercise loading/skeleton states. - Read-only today: surfaces are GET-driven. The few writes (mark-all-read, op run) exist; composer "Deploy", connect-source wizard, and create-key are demo shells (local state, no submit endpoint yet) — wire these to real POSTs during backend integration.
Implementing a surface against the real backend
- Make
httpJsonhit your API origin (add abaseURL/proxy inapi/http.ts) and match the response shapes inapi/<surface>.ts(the exported types are the spec). - Keep the surface's handler in
mocks/handlers/in sync — Storybook and the tests still answer through it.
Endpoint catalogue
| Surface | Method & path | Query | API fn | Response type |
|---|---|---|---|---|
| Home | GET /v1/home/kpis |
tier |
fetchHomeKpis |
KpiEntry[] |
| Home | GET /v1/analytics/usage |
— | fetchUsageSeries |
UsageSeriesResponse |
| Home | GET /v1/activity |
— | fetchRecentActivity |
ActivityEvent[] |
| Home | GET /v1/regions/health |
— | fetchRegionHealth |
RegionHealth[] |
| Users | GET /v1/users |
tier |
fetchUsers |
UsersResponse |
| Documents | GET /v1/documents |
tier |
fetchDocuments |
DocumentsResponse |
| Pipelines | GET /v1/pipelines · POST /v1/pipelines/:id/promote-to-policy |
tier |
fetchPipelines · promoteToPolicy |
PipelinesResponse |
| Policies | GET/POST /api/v1/policies · GET/DELETE /api/v1/policies/{id} · POST /api/v1/policies/{id}/run |
— | fetchPolicies · savePolicy · deletePolicy · runPolicy |
PoliciesResponse · Policy |
| Sources | GET /v1/sources |
tier |
fetchSources |
SourcesResponse |
| Components | GET /v1/components |
tier |
fetchComponents |
ComponentsResponse |
| Infrastructure | GET/POST /api/v1/proprietary/ui-data/infrastructure/api-keys · DELETE …/api-keys/{id} |
— | fetchApiKeys · createApiKey · revokeApiKey |
ApiKeysResponse · CreatedApiKey |
| Infrastructure | GET /api/v1/proprietary/ui-data/infrastructure/audit-log |
tier |
fetchAuditLog |
AuditLogResponse |
| Infrastructure | GET /api/v1/proprietary/ui-data/audit-export |
format, fields |
exportAuditLog |
CSV/JSON blob |
| Usage & Billing | GET /v1/billing/usage |
— | fetchBillingUsage |
UsageSeriesResponse |
| Usage & Billing | GET /v1/billing/summary |
tier |
fetchBillingSummary |
BillingSummary |
| Usage & Billing | GET /v1/billing/plans |
— | fetchPlanOptions |
PlanOption[] |
| Usage & Billing | GET /v1/billing/history |
tier |
fetchBillingHistory |
BillingHistoryRow[] |
| Developer Docs | GET /v1/docs/nav |
— | fetchDocsNav |
DocsNavSection[] |
| Editor | GET /v1/editor/deployment |
tier |
fetchEditorDeployment |
EditorDeploymentResponse |
| Settings | GET /v1/settings |
tier |
fetchSettings |
UserSettings |
| Notifications | GET /v1/notifications · POST /v1/notifications/mark-all-read |
— | — | Notification[] |
| Ops | GET /v1/ops/featured · POST /v1/ops/:opId/run |
— | — | — |
| Assistant | GET /v1/assistant/suggestions · POST /v1/assistant/messages |
— | — | — |
| Search | GET /v1/search/quick-actions |
— | — | — |
Catalogue generated from
mocks/handlers/*.ts. Theapi/<surface>.tsJSDoc on each function is the authoritative per-endpoint reference.Policies targets the real backend base
/api/v1/policies(Stirling'sPolicyController) rather than the mock/v1/...convention — its contract mirrors the live policy engine.