@spillway-cms/client
v0.1.26
Published
Typed fetch client for the Spillway CMS public content API: pages as resolved block data, entities, collections, menus, search, media, previews, webhook verification and member sign-in through the site's OpenID Connect provider. No dependencies; runs in N
Readme
@spillway-cms/client
A typed, dependency-free fetch client for the Spillway CMS public content API. Runs in Node 18+, edge runtimes and browsers. MIT licensed.
import { createClient } from '@spillway-cms/client';
const spillway = createClient({ baseUrl: 'https://cms.example.org' });
const page = await spillway.render('/about'); // resolved blocks, SEO, menus, cache tags
const posts = await spillway.collection('stories', { filters: [{ field: 'category', op: 'eq', value: 'news' }] });
const menu = await spillway.menu('main', { path: '/about' });render,page,entity,collection,menu,site,search,media,paths; errors areSpillwayErrorwith the API's status and code.- Previews:
previewFromRequest(req, { secret })reads a release share link (?release=&token=, or the former?workstream=) or thespillway_previewcookie;client.withPreview(state)sends it. A draft preview (preview: true) counts only from a cookie signed with your preview secret (previewCookieValue(state, { secret }), HMAC-SHA256 with an expiry), never from?preview=1on a page.checkPreviewRequestandsafeRedirectUrlare the checks a preview route makes. @spillway-cms/client/webhook:readWebhook(request, secret)verifies Spillway's signed publish webhooks with Web Crypto;affectedByWebhook(payload)lists the paths and cache tags to purge.@spillway-cms/client/members: sign a site's members in through its OpenID Connect provider (authorization code with PKCE,stateandnonce, the ID token verified against the site's keys) and keep the session in anHttpOnlycookie sealed with AES-GCM:createMemberAuth({ issuer, clientId, redirectUri, secret })withsignIn,callback,session(refreshes when due) andsignOut;memberClient(client, session)reads members-only pages with the member's access token. Web Crypto only.
Full documentation: docs/adapters.md and docs/api.md ("Headless") in the Spillway repository.
