variants.ts
Language TypeScript1.9 KB48 lines
/*** One rendered page per viewer. Runtime-neutral, so the Worker and the local* push both use it and cannot drift apart.** Pre-rendered rather than filtered per request: The deployed board's whole shape* is "the cron does the work, a request is a KV read and nothing else"; see the* header of apps/worker/src/index.ts. Rendering per request would put page* assembly on the request path for a page that is a snapshot anyway. So every* variant is built at sync time and a request picks one.** Variants and not one page, because access control cannot live in the* browser. Anything sent to a browser has been disclosed, whatever the markup* says about it; `hidden` is styling.*/import { MERIDIAN_PEOPLE } from '../../../config/meridian-people.js'import type { Snapshot, Headline } from './collect.js'import type { HistoryRow } from './history.js'import type { Briefings } from './briefings.js'import { render } from './render.js'import { allViewers } from './viewer.js'/** KV key for a variant. Kept in one place so the writer and reader agree. */export function variantKey(viewerKey: string): string {return `dashboard:html:${viewerKey}`}/*** Every page a sync needs to produce, keyed by viewer.** Always includes `company`, which is what an address the roster does not know* receives. Without it an unrecognised sign-in would have nothing to be served* and would fall through to whatever the caller decided, and the safe default* has to exist here rather than being remembered at each call site.*/export function renderVariants(snap: Snapshot,h: Headline,history: HistoryRow[],day: string,briefings: Briefings | null,): Map<string, string> {const out = new Map<string, string>()for (const viewer of allViewers(MERIDIAN_PEOPLE)) {out.set(viewer.key, render(snap, h, history, day, briefings, viewer))}return out}