Library for use in multiple ATProto Corkboard clients
README.md

CorkboardCommons #

A framework-independent TypeScript library shared by the Corkboard projects. It is the single home for the code that used to be copied between CorkboardCalAdmin, CorkboardAdminSveltekit, CorkboardFrontend, and CorkboardSvelteKit.

What's here #

Entry point What it is Was duplicated in
@corkboard/commons/lexicons/collections The collection NSIDs + types both admins
@corkboard/commons/lexicons/validators @atproto/lex-document validator from the bundled lexicon JSONs both admins
@corkboard/commons/lexicons/panproto panproto schema for the event lexicon + the structural co-check both admins
@corkboard/commons/lexicons/records create/update/delete/list + blob upload over XRPC both admins
@corkboard/commons/lexicons/import Resolve an at:// / atmo.rsvp event link to its record both admins
@corkboard/commons/rss/parse RSS 2.0 parsing (fast-xml-parser) both admins
@corkboard/commons/rss/http Bounded fetch + HTML-entity helpers both admins
@corkboard/commons/rss/flyer og:image scraping + WebP conversion (sharp) both admins
@corkboard/commons/rss/source panproto source schema for a feed item both admins
@corkboard/commons/atproto Public, unauthenticated XRPC read client (handle/DID → PDS, listRecords, getRecord, getBlob) both frontends
@corkboard/commons/events The event record types + normalization both frontends
@corkboard/commons/sources Source classification: the calendar catalog (hosts → id/label/color) + classifySources both frontends
@corkboard/commons/resolve Follow pointer records to their subject event across accounts both frontends
@corkboard/commons/reposts at.corkboard.alpha.repost resolution both frontends
@corkboard/commons/laughlists town.laugh.user.listitem resolution both frontends
@corkboard/commons/format Date/range formatting both frontends
@corkboard/commons/ics iCalendar (RFC 5545) import/export — "add to calendar" links and .ics prefilling both frontends
@corkboard/commons/cork Procedural cork texture both frontends
@corkboard/commons/dedup Cross-source fingerprint + panproto field diff + merge both admins

The bundled lexicons (community.lexicon.calendar.{event,authFull}, community.lexicon.location.*, at.corkboard.alpha.repost, com.atproto.repo.strongRef) live under src/lexicons/*.json and are the canonical copies; refresh them with goat lex pull (see the repo-root AGENTS.md) and copy the JSONs in here.

What's deliberately excluded #

The Chicago-specific parts of the family live in the sibling package ChicagoCorkCommon (@corkboard/chicago-common): the neighborhood boundary/geocoding code and the off-protocol scrapers (sources/{jungle,activismhub,luma,mediummachine}), which depend on this package.

Beyond that:

  • OAuth client plumbing (lib/auth/*) — the only genuinely framework-coupled part today (Next uses next/headers cookies, SvelteKit its own; the scopes differ per app). Extracting a framework-neutral core (stores + PEM handling + metadata builder, with the app injecting the redirect/scope config) is a good follow-up.
  • App config — lib/config.ts (the PUBLIC_* env) and lib/router.ts (which reads it) stay in the frontends.
  • Feed URL defaults (rss/fetch.ts) — the env var names and default URLs are per-app; the generic fetchFeedText helper is easy to re-add here as a parameterised function if several apps want it.

Layout & build #

src/
  lexicons/   *.json + collections/validators/panproto/records/import
  rss/        parse / http / flyer / source
  atproto.ts events.ts sources.ts resolve.ts reposts.ts laughlists.ts
  format.ts cork.ts dedup.ts ics.ts
scripts/copy-assets.mjs   # tsc doesn't copy imported JSON → copies to dist/
npm install     # runs `prepare` → builds dist/
npm run check   # typecheck only
npm run build   # tsc → dist/ (+ copies the lexicon JSONs)

The build emits plain ESM + .d.ts to dist/. It is consumed by bundlers (Vite, webpack/Turbopack) and by the apps' plain-Node CLIs via tsx; the relative imports are extension-less, so a plain Node ESM consumer would need a bundler/loader (adding .js extensions everywhere is a mechanical follow-up if that is ever needed).

Consuming it #

Add the dependency and swap the import specifiers; the module bodies are byte-identical to the current app copies.

// <app>/package.json
"dependencies": { "@corkboard/commons": "git+https://tangled.org/corkboard.at/CorkboardCommons" }

The package is consumed straight from its git repository (there is no registry publish), so consumers resolve it as a git dependency. Pin to a tag or commit (git+https://tangled.org/corkboard.at/CorkboardCommons#v0.1.0 or …#<sha>) for reproducible installs — a bare git+https://… tracks the default branch HEAD.

Current import (app) New import
@/lib/lexicons/collections (Next) · $lib/lexicons/collections (SvelteKit) @corkboard/commons/lexicons/collections
@/lib/lexicons/validators · $lib/lexicons/validators @corkboard/commons/lexicons/validators
@/lib/lexicons/panproto · $lib/lexicons/panproto @corkboard/commons/lexicons/panproto
@/lib/lexicons/records · $lib/lexicons/records @corkboard/commons/lexicons/records
@/lib/lexicons/import · $lib/lexicons/import @corkboard/commons/lexicons/import
@/lib/rss/* · $lib/rss/* @corkboard/commons/rss/* (except fetch)
@/lib/dedup · $lib/dedup @corkboard/commons/dedup
./atproto ./events ./format ./resolve ./reposts ./laughlists ./cork (frontends) @corkboard/commons/atproto … etc.

Then delete the app-local copies. Files that stay per-app: lib/auth/*, lib/sources/*, lib/config.ts, lib/router.ts, lib/rss/fetch.ts, plus each app's components/routes.

Nix #

fetchNpmDeps resolves dependencies through its own offline npm pass, so it cannot fetch the git dependency on its own — a Nix-packaged app must give it the source. Either point the flake at the same pinned git dep and allow the build to reach the host (so the fetcher can resolve git+https://tangled.org/corkboard.at/…#<sha>), or pass the commons in as a flake input and postPatch/npm link it into node_modules. The git URL must be pinned to a tag/commit regardless — otherwise the derivation hash changes on every fetch. Plan for that before wiring the Nix-packaged apps (CorkboardSvelteKit, CorkboardAdminSveltekit).

Sync policy #

This package is the source of truth. While the apps still carry their copies, treat the commons as authoritative: change it here, then copy the file back out (or, better, wire the app to import from here). The files were lifted verbatim, so diff between src/** here and the app copies should stay empty until each app switches over — the one intentional difference today is the // SPDX-License-Identifier: MPL-2.0 header this package adds to every source file.