mattrguerra/meridian-ops-boardmainPrivate on GitHub, published here in full

variants.ts

Language TypeScript1.9 KB48 lines

apps/dashboard/src/variants.ts

  1. /**
  2. * One rendered page per viewer. Runtime-neutral, so the Worker and the local
  3. * push both use it and cannot drift apart.
  4. *
  5. * Pre-rendered rather than filtered per request: The deployed board's whole shape
  6. * is "the cron does the work, a request is a KV read and nothing else"; see the
  7. * header of apps/worker/src/index.ts. Rendering per request would put page
  8. * assembly on the request path for a page that is a snapshot anyway. So every
  9. * variant is built at sync time and a request picks one.
  10. *
  11. * Variants and not one page, because access control cannot live in the
  12. * browser. Anything sent to a browser has been disclosed, whatever the markup
  13. * says about it; `hidden` is styling.
  14. */
  15. import { MERIDIAN_PEOPLE } from '../../../config/meridian-people.js'
  16. import type { Snapshot, Headline } from './collect.js'
  17. import type { HistoryRow } from './history.js'
  18. import type { Briefings } from './briefings.js'
  19. import { render } from './render.js'
  20. import { allViewers } from './viewer.js'
  21. /** KV key for a variant. Kept in one place so the writer and reader agree. */
  22. export function variantKey(viewerKey: string): string {
  23. return `dashboard:html:${viewerKey}`
  24. }
  25. /**
  26. * Every page a sync needs to produce, keyed by viewer.
  27. *
  28. * Always includes `company`, which is what an address the roster does not know
  29. * receives. Without it an unrecognised sign-in would have nothing to be served
  30. * and would fall through to whatever the caller decided, and the safe default
  31. * has to exist here rather than being remembered at each call site.
  32. */
  33. export function renderVariants(
  34. snap: Snapshot,
  35. h: Headline,
  36. history: HistoryRow[],
  37. day: string,
  38. briefings: Briefings | null,
  39. ): Map<string, string> {
  40. const out = new Map<string, string>()
  41. for (const viewer of allViewers(MERIDIAN_PEOPLE)) {
  42. out.set(viewer.key, render(snap, h, history, day, briefings, viewer))
  43. }
  44. return out
  45. }