Papers

Barkpark runnable snippets

Every file in this directory is a single, self-contained TypeScript example. Type-checked as part of docs CI (tsc --noEmit) and included verbatim in MDX guides via Fumadocs' include directive.

Authoring contract

  • Valid TypeScript/TSX, passes tsc --noEmit against js/tsconfig.base.json (strict: true, noUncheckedIndexedAccess: true, exactOptionalPropertyTypes: true).
  • Imports only from @barkpark/*, next/*, react, and the Node standard library. No imports between snippets.
  • First block comment is the "expected output" — concrete enough to smoke-test end-to-end. _meta.json duplicates this in structured form.
  • Each file exports a single function (or App Router convention: GET / POST / default).

Required env vars

Snippets assume a Phoenix API at https://cms.example.com and:

VarPurpose
BARKPARK_TOKENread-tier bearer token
BARKPARK_SERVER_TOKENserver-only bearer token
BARKPARK_PREVIEW_SECRETdraft-mode HMAC secret
BARKPARK_WEBHOOK_SECRETwebhook HMAC secret

Type-check the whole directory

cd js
pnpm typecheck      # runs turbo across all workspace packages, incl. docs

Index

FilePurpose
01-create-document.tsTransaction: create draft, then publish
02-query-with-filters.tsDocsBuilder: where / order / limit / findOne
03-listen-for-updates.tsAsync-iterate client.listen() SSE events
04-mutate-optimistic.tsxClient form with useOptimisticDocument
05-publish-unpublish.tsdefineActions publish + unpublish round-trip
06-server-component-fetch.tsxApp Router RSC via barkparkFetch
07-server-action-mutate.tsx'use server' module wiring defineActions
08-revalidate-on-webhook.tsWebhook route: HMAC + dedup + revalidate