1 Commits

Author SHA1 Message Date
bb856083ad feat(insights-edge): add session replay (rrweb), paid-tier gated
Adopts rrweb + rrweb-player (MIT, vendored as prebuilt UMD bundles via
scripts/vendor-rrweb.mjs, see NOTICE) to add cookieless session replay to
Railyard Insights, gated behind the existing Dodo paid tier.

- src/replay/config.mjs: per-site settings with privacy-first floors/defaults
  (off by default, sample rate, maskAllInputs, maskTextSelector, per-session
  byte/duration caps, monthly session cap) — every cap is clamped server-side
  regardless of what a site's stored config asks for.
- src/replay/ingest.mjs: POST /api/replay chunk ingestion — bot/DNT/GPC drop,
  paid-tier + enabled gate, hostname check, and all caps enforced again on
  the server (not just trusted from the client).
- src/replay/store.mjs: D1 replay_sessions metadata + R2 event chunks
  (<siteKey>/<sessionId>/<seq>.json); wired into the existing site-delete
  flow so deleting a site removes its sessions too.
- src/replay/tracker.mjs, routes.mjs, pages.mjs: the opt-in /replay.js tag,
  the dashboard's settings + session list + player pages (matching the
  existing Insights dashboard design), and the events API — all behind the
  same private dashboard token, so a site owner can only ever see and play
  back their own site's sessions.
- wrangler.jsonc: new R2 binding (railyard-insights-replay).

Tests: 23 new (config validation/clamping, ingestion caps, dashboard auth
scoping, a regression test for the vendored player's actual constructor
shape) + existing 52, all 75 passing. Verified end-to-end locally with
wrangler dev + a real browser: recorded a session, played it back with
rrweb-player, screenshots in /tmp/railyard-replay-*.png.

No deploy, no merge to railyard main from this commit alone (see
plans/railyard.md for the deploy/rollback steps).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 03:06:17 +03:00