← Public packages
@kentcdodds/pie-night
Pie night sign-ups: hosts start an event, guests add the pies they are bringing and watch the list fill in live. Installable, with optional push notifications.
Files
pie-night (agent notes)
Internet-visible package app. src/app.ts is the fetch handler
(kody.app.entry); static files are kody.app.assets in public/. One
optional credential slot, webPush (signing, provider web-push).
Layout
- Pages:
/(home, or a 302 to the home-redirect event unless?home),/new(create; needs Kody sign-in),/e/:code(canonical slug 302s),/e/:slug/admin,/e/:slug/og.png?v=<version>(immutable whenvmatches),/e/:slug/manifest.webmanifest,/offline,/sw.js(withService-Worker-Allowed),/favicon.svg,/manifest.webmanifest,/robots.txt(Disallow all, pages sendnoindex). - API:
GET /api/me;POST /api/events(signed in; 10/user/day, 50 per user);/api/e/:slugGET,/piesGET|POST,/pies/:uuidPATCH|DELETE(anyone),/presence,/push({subscription, host},{check, endpoint},{off, endpoint}),/admin/{state,event,reset,restore/:uuid,hosts,test-push}(hosts only). Old/api/pies*and/api/presencemap to the home-redirect event so cached single-event pages keep working. - Hosts: the event creator, its co-hosts, or a member of the owning org
(
X-Kody-Visitor.role). Login link:/-/auth/login?app=<leaf>&return_to=.... src/store.ts: SQL tablespies(keyed bynight),events(slug PK,night,versionbumps on every edit),event_presence,push_subs(event + endpoint; max 500 per event). Reset writes a newnight.migrateLegacymoves the old single-event storage keys (event,admin_usernames) into a named event, reusing itsnightso no pie rows move; the old keys stay untouched.src/pies.ts: pure helpers (limits, slugs, themes, parsing, formatting).src/page.ts: HTML for every page;src/art.ts: the pie SVGs.src/og.ts: Satori (asm yoga, no wasm: the Kody runtime refuses WebAssembly) lays out text to SVG paths;src/raster.tsis a small pure-JS rasterizer that fills them onto the pre-rendered background insrc/og-bg.ts. Fonts are subset TTFs insrc/fonts.ts(scripts/embed-fonts.mjs). In-memory cache of 40 renders; the?v=version makes CDN caching safe.src/push.ts+src/push-crypto.ts: RFC 8291 aes128gcm, VAPID JWT signed bycredential('webPush').sign(...). Only known push hosts. 404/410 removes the subscription. Sends after the response viactx.waitUntil.src/sw.ts: service worker (offline shell, network-first pages and pie lists with one retry on TypeError, cache-first assets with content-type checks, push + notificationclick).public/pwa.jsregisters it (off on localhost unless?sw=1), shows the Refresh bar only while a waiting worker differs from the controller, posts bothSKIP_WAITINGshapes, reloads oncontrollerchangewith a 4s fallback.public/app.js(event page),public/home.js(home, create, not found),public/styles.css(themes viabody[data-theme], dark viaprefers-color-scheme). BumpASSET_VERSIONinsrc/app.tswhen any of these or the service worker change.- Exports:
.(read one event's pies),./setup-push,./migrate,./settings(home redirect). Storage is per caller, so these only touch the caller's own install. scripts/render-assets.mjs: icons, badge, fallbackpublic/og.png, the share background, and.kody/icon.png(needsplaywright-core).- Tests:
node --test test/.
Edge cases
- Never put the street address in the app or its share preview.
- Max 200 pies per night; fields capped at 60/80/140 chars. Push: a pie add notifies every subscriber of that event except the adding device.
Batches and presence
POST /api/e/:slug/pies:{ who, pies: [{ pie, note }], website? }. Max 6 filled rows; blank rows skipped. Legacy single{ who, pie, note }still accepted. One batch uses one write-rate-limit hit; SQL inserts all rows in one statement.- The browser groups by case-insensitive, whitespace-collapsed family name.
POST /api/e/:slug/presence:{ sid, name, typing? }or{ sid, leave: true }. Random per-tab sid (not saved), heartbeats every 10s (25s while the socket is live), TTL 40s, hidden tabs leave. Public names are explicitly self-chosen and not authentication. Anonymous visitors show a pie/leaf avatar. Presence gets a separate rate-limit bucket (300/IP per 10 min, 20k total/hour), not the pie-write bucket. Old rows pruned as soon as they pass the 40s TTL (which pushes a presence update); active list capped at 40.
Realtime
- Manifest:
kody.app.realtime = { anonymous: "receive" }. Changing this changes the capability fingerprint and needs owner approval athttps://kody.codes/@<owner>/pie-night/approve-capabilities. Until approved, anonymous/wsupgrades are refused and the browser stays on polling. - Browser connects to
<base>/ws/<event slug>(one facet per event), sendskody:pingevery 25s, reconnects with exponential backoff (max 60s). Receive mode means visitors never send app messages over the socket. - Server calls
runtime.realtime.broadcast({ data, facet: slug })after every HTTP write:{type:'pies', change:'added'|'edited'|'removed'|'restored', from, who, items, ids, pies},{type:'event', event, pies?},{type:'presence', people}. Broadcast errors are caught so writes never fail because of realtime. Payloads over ~48 KB droppiesand setrefetch: true; clients then GET/api/e/:slug/pies. fromis the first 8 chars of the sender tab id (x-pie-tabheader) so the sender does not toast itself. Live clients poll every 60s and heartbeat every 25s as a safety net.