@liam-public/cms-contracts
v0.1.0
Published
Zod-typed list/CRUD API contract for CMS resources — shared by the frontend DataProvider and backend handlers; emits OpenAPI 3.1.
Readme
@liam-public/cms-contracts
The list/CRUD API contract a CMS frontend and backend share — one Zod source of truth, so the
@liam-public/browser-react-data DataProvider and the backend handlers can't drift.
Exports
listQuerySchema— the query params a list endpoint must accept (page,pageSize,sort,order, + filters), with coercion + defaults.listResponseSchema(item)— the{ data, total }envelope.TOTAL_COUNT_HEADER(x-total-count).errorResponseSchema+ERROR_CODES/ERROR_STATUS— the canonical error body and code→HTTP-status map, aligned with@liam-workspace/platformdomain errors.defineResource({ name, item, create, update })+resourceEndpoints(resource)— declare a resource once; get its five typed REST endpoints.toOpenApi(resources, info?)— emit an OpenAPI 3.1 document (the spec backends implement). Requires zod ≥ 4 (z.toJSONSchema), evaluated lazily.
Usage
import { defineResource, toOpenApi } from '@liam-public/cms-contracts'
import { z } from 'zod'
export const articles = defineResource({
name: 'articles',
item: z.object({ id: z.string(), title: z.string(), publishedAt: z.string() }),
create: z.object({ title: z.string().min(1) }),
update: z.object({ title: z.string().min(1).optional() }),
})
// Backend: validate handlers against `articles.create` / `listQuerySchema`.
// Frontend: the DataProvider's `articles` resource returns `z.infer<typeof articles.item>`.
// Docs/codegen: `toOpenApi([articles])` → an OpenAPI 3.1 spec.zod is a peer dependency (^3.23 || ^4); OpenAPI emission needs zod 4.
