@aglyn/aglyn 1.0.0-beta.232 → 1.0.0-beta.233

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/admin-audit-index.d.ts +3 -1
  3. package/src/lib/app-utils/admin-audit-index.js +9 -1
  4. package/src/lib/app-utils/admin-audit-index.js.map +1 -1
  5. package/src/lib/app-utils/analytics-summary.d.ts +95 -0
  6. package/src/lib/app-utils/analytics-summary.js +113 -0
  7. package/src/lib/app-utils/analytics-summary.js.map +1 -0
  8. package/src/lib/app-utils/artifact-list-keys.js +12 -0
  9. package/src/lib/app-utils/artifact-list-keys.js.map +1 -1
  10. package/src/lib/app-utils/artifact-list-queries.d.ts +16 -0
  11. package/src/lib/app-utils/artifact-list-queries.js +122 -4
  12. package/src/lib/app-utils/artifact-list-queries.js.map +1 -1
  13. package/src/lib/app-utils/crm.d.ts +30 -2
  14. package/src/lib/app-utils/crm.js +77 -15
  15. package/src/lib/app-utils/crm.js.map +1 -1
  16. package/src/lib/app-utils/docs-help.generated.d.ts +17 -5
  17. package/src/lib/app-utils/docs-help.generated.js +35 -1
  18. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  19. package/src/lib/app-utils/docs-index.generated.js +139 -6
  20. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  21. package/src/lib/app-utils/lockdown.js +1 -1
  22. package/src/lib/app-utils/lockdown.js.map +1 -1
  23. package/src/lib/app-utils/message-search.js +5 -2
  24. package/src/lib/app-utils/message-search.js.map +1 -1
  25. package/src/lib/app-utils/name-search.js +15 -3
  26. package/src/lib/app-utils/name-search.js.map +1 -1
  27. package/src/lib/app-utils/screen-analytics-aggregate.d.ts +70 -0
  28. package/src/lib/app-utils/screen-analytics-aggregate.js +82 -0
  29. package/src/lib/app-utils/screen-analytics-aggregate.js.map +1 -0
  30. package/src/lib/app-utils/screen-kind.d.ts +25 -0
  31. package/src/lib/app-utils/screen-kind.js +25 -0
  32. package/src/lib/app-utils/screen-kind.js.map +1 -0
  33. package/src/lib/app-utils/screen-route.d.ts +1 -5
  34. package/src/lib/app-utils/screen-route.js +2 -4
  35. package/src/lib/app-utils/screen-route.js.map +1 -1
  36. package/src/lib/app-utils/site-journey-steps.d.ts +38 -0
  37. package/src/lib/app-utils/site-journey-steps.js +54 -0
  38. package/src/lib/app-utils/site-journey-steps.js.map +1 -0
  39. package/src/lib/app-utils/site-journey.d.ts +2 -22
  40. package/src/lib/app-utils/site-journey.js +2 -32
  41. package/src/lib/app-utils/site-journey.js.map +1 -1
  42. package/src/lib/plugin-manager/first-party-plugins.generated.js +20 -2
  43. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  44. package/src/lib/plugin-manager/plugin-checkout-credits.d.ts +288 -0
  45. package/src/lib/plugin-manager/plugin-checkout-credits.js +196 -0
  46. package/src/lib/plugin-manager/plugin-checkout-credits.js.map +1 -0
  47. package/src/lib/plugin-manager/plugin-shipping-rates.d.ts +10 -0
  48. package/src/lib/plugin-manager/plugin-shipping-rates.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/screen-route.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HOST_ERROR_SCREEN_SLOTS, type ScreenUid } from '../foundation'\nimport { collectionListUrl } from './collection-entries'\nimport { ENTRY_PREVIEW_ROUTE_SEGMENT } from './entry-preview-link'\nimport { LEAVING_NOTICE_ROUTE_SEGMENT } from './leaving-notice'\nimport { PLATFORM_BRAND_NAME } from './platform-brand'\nimport {\n formatCollectionLinkValue,\n formatEntryLinkValue,\n formatFeedLinkValue,\n parseEntryLinkValue,\n} from './screen-link-value'\n\n/**\n * Route path of a host's root screen. The tenant matcher joins the catch-all\n * segments and collapses an empty one to this value (`load-page-data.ts`:\n * `slugSegments.length ? slugSegments.join('/') : SCREEN_ROOT_PATH`), so the\n * root is `'/'` and every other path is slash-joined segments WITHOUT a\n * leading slash (`about`, later `company/about`).\n */\nexport const SCREEN_ROOT_PATH = '/'\n\n/**\n * Normalizes user slug input into the routing-map path format described on\n * {@link SCREEN_ROOT_PATH}. `'/'` normalizes to the root path; anything else\n * becomes a single lowercase url-safe segment.\n *\n * Returns `undefined` for EMPTY input and for anything that sanitizes away\n * (`'###'`) — the two cases are deliberately the same answer, and the caller\n * decides what it means. In the Screens page's slug field an empty string\n * means \"no address typed\"; in a starter template it meant \"home\". Two\n * meanings for one value is what made AGL-1575 possible, so this function\n * refuses to pick one: a caller that wants the root must say `'/'`.\n *\n * This docstring used to claim empty input normalized to the root, which the\n * code has never done (see the spec, which asserts the `undefined`). A fix\n * written against the docstring instead of the behaviour would have shipped\n * broken; if you are here to make the code match the comment, do not.\n */\nexport function normalizeScreenSlug(\n input: string | null | undefined,\n): string | undefined {\n const trimmed = (input ?? '').trim()\n if (!trimmed) return undefined\n if (trimmed === SCREEN_ROOT_PATH) return SCREEN_ROOT_PATH\n\n const segment = trimmed\n .toLowerCase()\n .replace(/^\\/+|\\/+$/g, '')\n .replace(/\\s+/g, '-')\n .replace(/[^a-z0-9-_]/g, '')\n .replace(/-{2,}/g, '-')\n .replace(/^-+|-+$/g, '')\n\n return segment || undefined\n}\n\n/**\n * Route segments the published site CANNOT serve, whatever the routing map\n * says (AGL-2076).\n *\n * Every entry was measured against production on 2026-08-19 with a fresh\n * `x-vercel-cache: MISS`, because a stale negative always passes. Two\n * mechanisms, both of which resolve ahead of `[host]/[scheme]/[[...slug]]`:\n *\n * - `404`, `500` — Next emits `pages/404.html` and `pages/500.html` even for\n * an app-router-only build, and the deployed filesystem answers them as\n * static files (`content-disposition: inline; filename=\"404\"`,\n * `accept-ranges`, an `etag`, and no `x-nextjs-prerender`). The tenant\n * middleware's own CSP headers are on those responses, so the middleware\n * ran and its rewrite still lost. There is no rewrite this app can write\n * that beats them, which is why the honest fix is to refuse the slug at\n * authoring time rather than to keep promising an address that is dead.\n * - `search`, `api`, `_next`, `_static` — routes and exclusions the tenant\n * app owns. `/search` matches `app/[host]/[scheme]/search`; the other three are the\n * middleware matcher's exclusions, so no host rewrite happens at all and\n * the path is parsed as `[host]` with an empty slug.\n * - `aglyn-preview` — the same mechanism as `search`, one route over\n * (AGL-3205). The live-site preview of an unpublished collection entry is\n * a rewrite to `app/[host]/[scheme]/aglyn-preview/[...slug]`, because it\n * must be a DIFFERENT Next route from the ISR-cached catch-all; a static\n * folder wins over the optional catch-all beside it, so `/aglyn-preview/x`\n * would reach the preview page and 404 rather than render a screen. The\n * bare `/aglyn-preview` would in fact still serve — the preview route's\n * catch-all is required, not optional — and it is reserved anyway for the\n * reason given below about child paths: a child's path is composed from\n * its parent's slug, and this rule refuses that slug.\n * - `_aglyn` — the platform's own pages on every site, the leaving notice\n * at `/_aglyn/leaving` first (AGL-3452). The middleware rewrites that path\n * to an api route before the catch-all could see it.\n *\n * NOT reserved, and deliberately so, because measuring found them fine:\n * `401`, `403`, `503` (`/401` returns 200 through the catch-all — two of the\n * four designed error screens have always been viewable at their slugs, which\n * is what made the `404` case look like a Next.js defect), and `index`.\n *\n * `fonts` and `examples` USED to be dead for the third reason and are not\n * here: they were exclusions inherited from the Vercel platforms starter kit\n * for directories `apps/tenant/public` has never contained. They are given\n * back rather than reserved — see the matcher in `apps/tenant/middleware.ts`.\n */\nexport const RESERVED_SCREEN_ROUTE_SEGMENTS: readonly string[] = [\n '404',\n '500',\n 'search',\n ENTRY_PREVIEW_ROUTE_SEGMENT,\n 'api',\n '_next',\n '_static',\n LEAVING_NOTICE_ROUTE_SEGMENT,\n]\n\n/**\n * The reserved segment a routing-map path would collide with, or `undefined`\n * when the path is servable. The segment rather than a boolean, so a refusal\n * can name what it is refusing over.\n *\n * Reads the FIRST segment only. For `api`/`_next`/`_static` that is exactly\n * right — the middleware excludes the whole subtree, so `api/docs` is as dead\n * as `api`. For `404`/`500`/`search` it over-refuses in principle (`/404/why`\n * would serve), and that is deliberate: a child path is composed from its\n * PARENT's slug, the parent would have to hold `404`, and this same rule\n * refuses that slug wherever one is typed. A second list to express a case\n * that cannot arise would be a second list to keep correct.\n *\n * Takes a composed routing-map path (`about`, `company/about`, `'/'`), not a\n * raw slug field — `'/'` is the home screen and is never reserved.\n */\nexport function reservedScreenRouteSegment(\n path: string | null | undefined,\n): string | undefined {\n if (!path || path === SCREEN_ROOT_PATH) return undefined\n const [first] = path.replace(/^\\/+/, '').split('/')\n return RESERVED_SCREEN_ROUTE_SEGMENTS.includes(first) ? first : undefined\n}\n\n/**\n * The refusal an author reads when {@link reservedScreenRouteSegment} names a\n * segment. One sentence, in one place, because the Screens page, the version\n * view and the besigner all have to say the same thing — three surfaces\n * wording a platform constraint three ways is how AGL-2093's precheck drifted.\n */\nexport function reservedScreenRouteMessage(segment: string): string {\n return `\"/${segment}\" is a reserved address on every ${PLATFORM_BRAND_NAME} site — pick another slug`\n}\n\n/**\n * Does a raw slug value carry a path separator the one segment it describes\n * cannot hold (AGL-2572)?\n *\n * {@link normalizeScreenSlug} answers with a SINGLE segment, and it gets there\n * by deleting every character outside `[a-z0-9-_]` — an interior `/` included.\n * Whitespace becomes a `-`, but a `/` becomes nothing at all, so\n * `alternatives/webflow` normalizes to `alternativeswebflow` and the two words\n * are stored glued. Nothing about that is visible: the field accepts the\n * keystroke, the composed path reads plausibly, and the screen ends up\n * answering an address nobody typed. Two screens on `aglyn-marketing` carry a\n * slug of that shape.\n *\n * So the separator is a question a slug field asks BEFORE normalizing, and the\n * answer is a refusal rather than a silent repair — the caller cannot know\n * which segment the author meant, and guessing is how the glue happened.\n *\n * LEADING and TRAILING slashes are not separators here. `normalizeScreenSlug`\n * strips them deliberately (`/about/` → `about`), an author typing an address\n * writes them without meaning a hierarchy, and refusing them would reject a\n * value the normalizer has always handled correctly. `'/'` alone is the home\n * page and is never a separator.\n */\nexport function screenSlugHasPathSeparator(\n input: string | null | undefined,\n): boolean {\n const trimmed = (input ?? '').trim()\n if (!trimmed || trimmed === SCREEN_ROOT_PATH) return false\n return trimmed.replace(/^\\/+|\\/+$/g, '').includes('/')\n}\n\n/**\n * The refusal an author reads when {@link screenSlugHasPathSeparator} answers\n * true. One sentence, in one place, for the same reason\n * {@link reservedScreenRouteMessage} is: the Screens page, the version view\n * and the besigner all take a slug, and a constraint worded three ways drifts\n * into three different constraints.\n *\n * It names the alternative, because a `/` in this field almost always means\n * \"nest me\" and the hierarchy is what actually composes the longer path.\n */\nexport const SCREEN_SLUG_PATH_SEPARATOR_MESSAGE =\n 'A slug is one path segment — remove the \"/\" and nest the page under a ' +\n 'parent page instead'\n\n/**\n * `kind` of a page GROUP (AGL-3463): a folder in the Pages list that holds\n * pages and is not one.\n *\n * A group has no slug, no versions and no address. It is never routed, never\n * published or scheduled, and it contributes NOTHING to its descendants'\n * paths — a page inside a group composes exactly as if it sat at the group's\n * own level, so moving a page into or out of a group at that level leaves its\n * URL untouched. A group nested in a group behaves the same way.\n *\n * It has to be a declared kind rather than \"a parent with no slug\", because a\n * slugless parent already means something: an unpublished page, and\n * {@link composeScreenRoutePath} refuses every path beneath one. Pages under\n * a slugless parent keep the addresses they already have, but no page there\n * can be published, which is the opposite of what a folder is for.\n *\n * A group is not a page, so it is in {@link screenClaimsToBeAPage}'s list and\n * spends none of the plan's page allowance. That is safe for the reasons the\n * other non-page kinds are: `kind` is stamped at create by\n * /api/hosts/resources and frozen against the client by the rules, no route\n * converts a group into anything else, and the serve path refuses a non-page\n * claim — so a group can never be laundered into a page it did not pay for,\n * and the flat {@link NON_PAGE_SCREEN_MAX_PER_HOST} bounds how many exist.\n */\nexport const SCREEN_KIND_GROUP = 'group'\n\n/** Minimal screen shape the hierarchy helpers need. */\nexport interface ScreenRouteNode {\n slug?: string\n parentId?: ScreenUid\n /**\n * The screen's `kind`. Read here for ONE value, {@link SCREEN_KIND_GROUP}:\n * a group contributes nothing to a path, where a slugless page breaks it.\n * A caller that leaves this out makes every group look like an unpublished\n * page — build nodes with {@link toScreenRouteNode} so it cannot.\n */\n kind?: string\n}\n\n/**\n * The {@link ScreenRouteNode} of a screen document: the three fields path\n * composition reads, and nothing else. Every surface that composes paths\n * builds its map through this, because a map built from `{ slug, parentId }`\n * alone silently reads a group as an unpublished page and unroutes every page\n * inside it (AGL-3463).\n */\nexport function toScreenRouteNode(screen: {\n slug?: unknown\n parentId?: unknown\n kind?: unknown\n}): ScreenRouteNode {\n const node: ScreenRouteNode = {}\n if (typeof screen.slug === 'string') node.slug = screen.slug\n if (typeof screen.parentId === 'string' && screen.parentId) {\n node.parentId = screen.parentId\n }\n if (typeof screen.kind === 'string') node.kind = screen.kind\n return node\n}\n\n/** Is this screen a page group ({@link SCREEN_KIND_GROUP})? */\nexport function isScreenGroup(\n screen: { kind?: unknown } | null | undefined,\n): boolean {\n return screen?.kind === SCREEN_KIND_GROUP\n}\n\n/** Defensive cap: parent chains deeper than this are treated as invalid. */\nconst MAX_SCREEN_DEPTH = 32\n\n/**\n * Composes a screen's routing-map path from its own slug plus its ancestor\n * chain: parent `company` + own `about` → `company/about`. Root (`'/'`)\n * segments contribute nothing, so children of the home screen sit at the\n * top level, and GROUP ancestors contribute nothing either (AGL-3463) — they\n * are passed through as if the screen sat at the group's own level.\n *\n * Returns `undefined` when the screen is itself a group, when it (or any\n * non-group ancestor) has no slug, when its own slug is `'/'` while it has a\n * non-group ancestor, or when the chain has a cycle / exceeds\n * {@link MAX_SCREEN_DEPTH}.\n */\nexport function composeScreenRoutePath(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): string | undefined {\n // A group is never an address, whatever else its document says.\n if (isScreenGroup(screensById[screenId])) return undefined\n const segments: string[] = []\n const visited = new Set<ScreenUid>()\n let currentId: ScreenUid | undefined = screenId\n let isHomePage = false\n\n while (currentId) {\n if (visited.has(currentId) || visited.size >= MAX_SCREEN_DEPTH) {\n return undefined\n }\n visited.add(currentId)\n const screen = screensById[currentId]\n if (isScreenGroup(screen)) {\n // No segment, and no slug required: a group does not gate the pages\n // inside it. Its own slug, if a stray one exists, is ignored.\n currentId = screen?.parentId\n continue\n }\n if (!screen?.slug) return undefined\n // The home screen's segment is empty (children of home sit at the top\n // level), but a screen can't itself be the home page AND sit under\n // another page. Groups above it are fine — they are not levels.\n if (isHomePage) return undefined\n if (screen.slug === SCREEN_ROOT_PATH) {\n if (currentId === screenId) isHomePage = true\n } else {\n segments.unshift(screen.slug)\n }\n currentId = screen.parentId\n }\n\n if (!segments.length) return isHomePage ? SCREEN_ROOT_PATH : undefined\n return segments.join('/')\n}\n\n/**\n * The nearest ancestor that is NOT a group — the screen whose level a page\n * actually composes its path at — or `undefined` for the top level\n * (AGL-3463). Two placements with the same answer compose the same path,\n * which is what makes moving a page into or out of a group at that level a\n * move that cannot change its URL.\n */\nexport function screenRouteParentId(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): ScreenUid | undefined {\n const visited = new Set<ScreenUid>([screenId])\n let currentId = screensById[screenId]?.parentId\n while (currentId && !visited.has(currentId)) {\n visited.add(currentId)\n const screen = screensById[currentId]\n if (!isScreenGroup(screen)) return currentId\n currentId = screen?.parentId\n }\n return undefined\n}\n\n/**\n * Where each child of a group goes when the group is deleted: one level up,\n * under the group's own parent (AGL-3463). A child id → its next `parentId`\n * (`undefined` for the top level).\n *\n * Only DIRECT children move; grandchildren ride along under them. Because a\n * group contributes nothing to a path, the children's composed paths are the\n * same before and after, so deleting a group never touches the routing map.\n * Answers `{}` for a screen that is not a group — deleting a page is a\n * different act with a different consequence for what sits under it.\n */\nexport function screenGroupDissolveMoves(\n groupId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): Record<ScreenUid, ScreenUid | undefined> {\n const group = screensById[groupId]\n if (!isScreenGroup(group)) return {}\n const nextParentId = group?.parentId\n const moves: Record<ScreenUid, ScreenUid | undefined> = {}\n for (const [id, screen] of Object.entries(screensById)) {\n if (id !== groupId && screen?.parentId === groupId) {\n moves[id] = nextParentId\n }\n }\n return moves\n}\n\n/**\n * All screens whose parent chain passes through `screenId` (children,\n * grandchildren, …). Used to cascade routing-map rewrites when a screen's\n * slug or parent changes.\n */\nexport function collectScreenDescendantIds(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): ScreenUid[] {\n const childrenByParent = new Map<ScreenUid, ScreenUid[]>()\n for (const [id, screen] of Object.entries(screensById)) {\n if (!screen?.parentId) continue\n const siblings = childrenByParent.get(screen.parentId) ?? []\n siblings.push(id)\n childrenByParent.set(screen.parentId, siblings)\n }\n const result: ScreenUid[] = []\n const queue = [...(childrenByParent.get(screenId) ?? [])]\n while (queue.length) {\n const id = queue.shift() as ScreenUid\n if (result.includes(id)) continue\n result.push(id)\n queue.push(...(childrenByParent.get(id) ?? []))\n }\n return result\n}\n\n/**\n * True when making `nextParentId` the parent of `screenId` would create a\n * loop — i.e. the candidate parent is the screen itself or one of its own\n * descendants.\n */\nexport function wouldCreateScreenCycle(\n screenId: ScreenUid,\n nextParentId: ScreenUid | undefined,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): boolean {\n if (!nextParentId) return false\n if (nextParentId === screenId) return true\n return collectScreenDescendantIds(screenId, screensById).includes(\n nextParentId,\n )\n}\n\n/** What {@link buildScreenRouteEntries} needs besides the candidate tree. */\nexport interface BuildScreenRouteEntriesOptions {\n /**\n * Is this call a PUBLISH of the screen it names, or only a move? (AGL-2571)\n *\n * An entry in the host's `screens` map is the whole of what makes a path\n * reachable, so writing one IS publishing — there is no second switch.\n * Assigning a parent to an unpublished screen that merely CARRIED a slug\n * would otherwise register it in the map, and the besigner toolbar, which\n * reads the map, would offer `Unpublish` and a `Live` link for a screen\n * nobody published, with no `publishedAt` and a 404 at the address.\n *\n * `true` lets the NAMED screen take an entry it does not have yet. It never\n * does that for a descendant: publishing a parent is not publishing the\n * drafts beneath it, which would put them live with no `publishedAt` and\n * nobody having asked. `false` restricts the write to entries that already\n * exist, so a move rewrites what is live and puts nothing new there.\n *\n * Defaults to `true`, which is what the publish buttons mean.\n */\n publish?: boolean\n /**\n * The screens map as it stands BEFORE this change (AGL-3463).\n *\n * A descendant follows a change to its ancestors only while it is ATTACHED:\n * its routing entry is the path it composes in this tree. One that kept its\n * address when its chain stopped resolving — its parent unpublished with\n * the slug cleared, deleted, or moved under a page with no slug — is\n * DETACHED, and a later publish or rename of that parent must not move it\n * somewhere new. Only the tree before the change can tell the two apart;\n * the candidate tree already composes the new path for both.\n */\n currentById: Record<ScreenUid, ScreenRouteNode | undefined>\n}\n\n/**\n * Routing-map entries to SET for a screen plus its descendants under a\n * candidate screens map. Callers apply the result in one write so slug and\n * parent changes cascade atomically.\n *\n * ## It never removes a route (AGL-3463)\n *\n * The answer holds paths only — no removals, ever. The routing map is the\n * whole of what makes a page reachable, so a removal computed here would take\n * a live page off the site as a side effect of a move, a rename or an\n * unpublish of something ABOVE it, with nobody having asked for that page to\n * go. Each of these therefore keeps the route it has:\n *\n * - a live screen whose chain no longer composes — moved under a page with\n * no slug, or its parent's slug cleared — keeps serving where it is;\n * - a DETACHED descendant (see\n * {@link BuildScreenRouteEntriesOptions.currentById}) stays where it is\n * when its ancestors change again;\n * - a group, which never composes a path, is never written.\n *\n * Taking a page off the site is a separate act on that page alone\n * (`unpublishScreenRoute`), so the only page that can stop resolving is the\n * one somebody pointed at.\n *\n * See {@link BuildScreenRouteEntriesOptions.publish} for the difference\n * between publishing a screen and merely moving one.\n */\nexport function buildScreenRouteEntries(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n routingMap: Record<ScreenUid, string> | null | undefined,\n options: BuildScreenRouteEntriesOptions,\n): Record<ScreenUid, string> {\n const { publish = true, currentById } = options\n const entries: Record<ScreenUid, string> = {}\n const routedPath = (id: ScreenUid) => {\n const path = routingMap?.[id]\n return typeof path === 'string' && path ? path : undefined\n }\n\n // The named screen: rewritten when it is live, registered when this is its\n // publish, and left exactly as it is when its new chain does not compose.\n const ownPath = composeScreenRoutePath(screenId, screensById)\n if (ownPath && (routedPath(screenId) !== undefined || publish)) {\n entries[screenId] = ownPath\n }\n\n for (const id of collectScreenDescendantIds(screenId, screensById)) {\n const live = routedPath(id)\n // A draft below a published parent stays a draft.\n if (live === undefined) continue\n // Detached: its address is not the one its chain composes today.\n if (composeScreenRoutePath(id, currentById) !== live) continue\n const path = composeScreenRoutePath(id, screensById)\n if (path) entries[id] = path\n }\n return entries\n}\n\n/** A page below another that is live at an address of its own. */\nexport interface LiveScreenDescendant {\n id: ScreenUid\n /** Its routing-map path (`company/about`, or `'/'` for the home page). */\n path: string\n}\n\n/**\n * Every descendant of `screenId` with a routing entry, ordered by address\n * (AGL-3463) — the pages that STAY LIVE when `screenId` is unpublished or\n * deleted, because neither act ever removes more than the one entry\n * ({@link buildScreenRouteEntries}).\n *\n * The unpublish and delete confirmations list these, so whoever takes a\n * parent down knows which pages below it keep serving and can take them\n * down separately if that is what they meant. Groups are walked through and\n * never listed: a group is not a page.\n */\nexport function liveScreenDescendants(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n routingMap: Record<ScreenUid, unknown> | null | undefined,\n): LiveScreenDescendant[] {\n const live: LiveScreenDescendant[] = []\n for (const id of collectScreenDescendantIds(screenId, screensById)) {\n const path = routingMap?.[id]\n if (typeof path !== 'string' || !path) continue\n if (isScreenGroup(screensById[id])) continue\n live.push({ id, path })\n }\n return live.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))\n}\n\n/**\n * Looks up which screen currently owns a routing path, for sibling-slug\n * uniqueness checks before publishing.\n */\nexport function findScreenIdByRoutePath(\n screens: Record<ScreenUid, string> | null | undefined,\n path: string,\n): ScreenUid | undefined {\n if (!screens) return undefined\n const entry = Object.entries(screens).find(([, value]) => value === path)\n return entry?.[0]\n}\n\n/**\n * The screen a publish at `path` would collide with, or `undefined` when the\n * address is free to take (AGL-3408).\n *\n * {@link findScreenIdByRoutePath} with one exception: the placeholder home\n * page a site is created with (`host.defaultHomeScreenId`) does not block the\n * site root. It holds `/` only so a new site never answers its own address\n * with a 404, and the first real page published there replaces it — the\n * publish seam removes its entry in the same write. It still blocks any other\n * path it has been moved to, and no other screen is ever passed over.\n *\n * Every publish surface's conflict check reads this rather than the raw owner,\n * so \"is this address taken?\" has one answer across them.\n */\nexport function blockingRouteOwner(\n screens: Record<ScreenUid, string> | null | undefined,\n path: string,\n defaultHomeScreenId?: string | null,\n): ScreenUid | undefined {\n const owner = findScreenIdByRoutePath(screens, path)\n if (owner && path === SCREEN_ROOT_PATH && owner === defaultHomeScreenId) {\n return undefined\n }\n return owner\n}\n\n/** Human-facing URL for a routing-map path (`'/'` stays `/`, `about` → `/about`). */\nexport function screenRoutePathToUrl(path: string): string {\n return path === SCREEN_ROOT_PATH ? SCREEN_ROOT_PATH : `/${path}`\n}\n\n/**\n * The routing-map path a page's URL path names — the inverse of\n * {@link screenRoutePathToUrl}: `/about` → `about`, `/company/about/` →\n * `company/about`, `/` and `''` → `/` (AGL-3461).\n *\n * For a door that knows the address a visitor was on and needs the screen\n * that served it: the host's routing map answers with no read. A query string\n * or a fragment is dropped; a value that is not a site-relative path answers\n * `undefined` rather than a routing key nobody wrote.\n */\nexport function screenRoutePathFromUrl(\n urlPath: string | null | undefined,\n): string | undefined {\n const raw = String(urlPath ?? '').trim()\n if (!raw) return SCREEN_ROOT_PATH\n if (!raw.startsWith('/') || raw.startsWith('//')) return undefined\n const bare = raw.split(/[?#]/)[0].replace(/^\\/+|\\/+$/g, '')\n return bare ? bare : SCREEN_ROOT_PATH\n}\n\n/**\n * A screen's OWN slug segment, read back off its composed routing-map path\n * (`company/about` → `about`) — the inverse of the one step\n * {@link composeScreenRoutePath} adds for this screen (AGL-2572).\n *\n * The slug field holds one segment; the routing map holds the whole composed\n * path. A field that seeds itself from the map therefore has to take the last\n * segment, and the besigner's seeded the whole path instead. Its value then\n * went through {@link normalizeScreenSlug}, which DELETES an interior `/`\n * rather than separating on it, so `alternatives/webflow` came back as the\n * glued `alternativeswebflow` and was stored as the screen's own slug —\n * without anyone typing it. Two screens on `aglyn-marketing` carry a slug of\n * that shape.\n *\n * Not a general path parser: it answers only \"which segment is this screen's\n * own\", which is always the last one.\n */\nexport function ownScreenSlugFromRoutePath(\n path: string | null | undefined,\n): string | undefined {\n if (!path) return undefined\n if (path === SCREEN_ROOT_PATH) return SCREEN_ROOT_PATH\n const segments = path.split('/').filter(Boolean)\n return segments[segments.length - 1]\n}\n\n/** What a screen is ACTUALLY served at, where that is not its own slug. */\nexport interface LinkableScreenRouteSources {\n /**\n * screen id → the routing-map path the screen really answers on, for\n * screens routed by something other than their own slug. Today that is a\n * content collection's LIST template: `/{collectionSlug}` renders it\n * (`composeCollectionTemplatePage`), whatever slug it was published under.\n * Applied LAST, so it also un-drops a screen named in `unrouted`.\n */\n routedElsewhere?: Record<string, string> | null | undefined\n /**\n * Screen ids that serve NO address of their own — a collection ENTRY\n * template (AGL-1267), commerce's PDP/catalog templates (AGL-1270), a\n * screen that says `kind: 'template'` (AGL-1400). The tenant router drops\n * these before matching, so their routing-map path is a 404.\n */\n unrouted?: Iterable<string> | null | undefined\n /**\n * collection id → collection slug, for every CONTENT collection with a slug\n * (AGL-2799): the collections whose listing `/{collectionSlug}` serves. Each\n * becomes a link target of its own, keyed by `formatCollectionLinkValue`,\n * so a link can name a blog's listing whether or not a list template screen\n * renders it.\n */\n collectionListings?: Record<string, string> | null | undefined\n /**\n * entry key (`entry:<collectionId>/<entryId>`) → the entry's path, for the\n * entries a page references (AGL-3118). Unlike every other source, this one\n * is not the whole site: a renderer reads only the entries its own links\n * name, so an entry key missing here means \"not asked for\", and\n * `screenRoutesAnswerFor` judges entry links only against a map that has\n * some.\n */\n entryRoutes?: Record<string, string> | null | undefined\n}\n\n/**\n * Where a collection's RSS feed is served, in the routing map's own format\n * (no leading slash): `blog/rss.xml` for the collection at `/blog`.\n */\nexport function collectionFeedRoutePath(collectionSlug: string): string {\n const listing = collectionListUrl({ collectionSlug }).replace(/^\\/+|\\/+$/g, '')\n return `${listing}/rss.xml`\n}\n\n/**\n * Where a collection ENTRY is served, in the routing map's own format (no\n * leading slash): `blog/hello` for the entry slugged `hello` in the\n * collection at `/blog` — the `/{collection}/{entry}` shape\n * `parseCollectionRoute` reads back.\n */\nexport function collectionEntryRoutePath(\n collectionSlug: string,\n entrySlug: string,\n): string {\n const listing = collectionListUrl({ collectionSlug }).replace(/^\\/+|\\/+$/g, '')\n return `${listing}/${entrySlug.trim().replace(/^\\/+|\\/+$/g, '')}`\n}\n\n/**\n * The routing map as a LINK TARGET table (AGL-1998).\n *\n * The host's `screens` map is written by publishing, one entry per screen\n * under its own composed slug, and the tenant router then edits it at serve\n * time: template screens are dropped (see {@link LinkableScreenRouteSources})\n * and a collection's list template is reached at `/{collectionSlug}` instead.\n * Everything that RESOLVES a screen link — `resolveScreenHref` on the live\n * site, the besigner's screen picker, every `Link`-typed component prop — was\n * reading the raw map, so the two surfaces disagreed with the router in both\n * directions at once:\n *\n * - `/blog` was UNOFFERABLE. The blog's list template is published under\n * `blog-list-template` and serves `/blog`, so no screen link on aglyn.com\n * could point at the site's own blog index.\n * - Every template screen was offered at a path that 404s, and an author who\n * picked one got a dead anchor that looks exactly like a live one.\n *\n * So the map every linking surface reads is derived here, from the same two\n * facts the router uses, and the picker can no longer offer a path the router\n * would refuse.\n *\n * A content collection's LISTING is a target in its own right (AGL-2799),\n * keyed `collection:<collectionId>` beside the screen ids. Its path comes from\n * `collectionListUrl`, the builder the pager, the canonical link and the\n * sitemap already share, so a link cannot give a listing an address the rest\n * of the site does not; and because the key is the collection's id rather than\n * its slug, renaming the slug moves every link to it on the next render. A\n * collection that is gone, or that has lost its slug, has no entry — the same\n * absence `isScreenLinkBroken` reads as a dead target.\n *\n * A raw map with no source given comes back unchanged; an absent map with no\n * overrides and no listings stays absent, because `undefined` means \"nothing\n * resolves yet\" to {@link ScreenLinkContext} and `{}` would mean \"resolved:\n * nowhere\".\n */\nexport function linkableScreenRoutes(\n screens: Record<ScreenUid, string> | null | undefined,\n sources: LinkableScreenRouteSources = {},\n): Record<ScreenUid, string> | undefined {\n const { routedElsewhere, unrouted, collectionListings, entryRoutes } = sources\n const overrides = Object.entries(routedElsewhere ?? {})\n const listings = Object.entries(collectionListings ?? {})\n const entries = Object.entries(entryRoutes ?? {})\n if (!screens && !overrides.length && !listings.length && !entries.length) {\n return undefined\n }\n const next: Record<ScreenUid, string> = { ...(screens ?? {}) }\n for (const id of unrouted ?? []) delete next[id]\n for (const [collectionId, collectionSlug] of listings) {\n const slug =\n typeof collectionSlug === 'string'\n ? collectionSlug.trim().replace(/^\\/+|\\/+$/g, '')\n : ''\n if (!collectionId.trim() || !slug) continue\n // Built by the one listing-URL builder, then stored in the map's own\n // format: no leading slash, which `resolveScreenHref` puts back.\n next[formatCollectionLinkValue(collectionId)] = collectionListUrl({\n collectionSlug: slug,\n }).replace(/^\\/+/, '')\n // The feed hangs off the same listing (AGL-3118), so it follows the same\n // rename and disappears with the same collection.\n next[formatFeedLinkValue(collectionId)] = collectionFeedRoutePath(slug)\n }\n for (const [key, path] of entries) {\n // Only well-formed entry keys, stored under their canonical spelling: this\n // source must not be able to plant a screen id or a listing key the other\n // sources own.\n const entry = parseEntryLinkValue(key)\n if (!entry) continue\n const normalized =\n typeof path === 'string' ? path.trim().replace(/^\\/+|\\/+$/g, '') : ''\n if (!normalized) continue\n next[formatEntryLinkValue(entry.collectionId, entry.entryId)] = normalized\n }\n for (const [id, path] of overrides) {\n // A collection slug (`blog`) arrives in the map's own format already, but\n // the same fact is spelled `/blog` in half the places it is read from, and\n // a stored `/blog` would resolve to `//blog` — an absolute URL to the host\n // `blog`, i.e. off the site entirely.\n const normalized =\n typeof path === 'string' && path !== SCREEN_ROOT_PATH\n ? path.replace(/^\\/+|\\/+$/g, '')\n : path\n if (!normalized) continue\n next[id] = normalized\n }\n return next\n}\n\n/**\n * `kind` of a besigner email document (AGL-395): a screen authored on the\n * Emails page and sent by a campaign, never served at a URL.\n */\nexport const SCREEN_KIND_EMAIL = 'email'\n\n/**\n * `kind` of a collection ENTRY template (AGL-1400): a screen that composes\n * `/{collection}/{entry}` for every entry and has no address of its own.\n *\n * The value exists so that \"is this screen a page?\" stops being a JOIN.\n * Four issues (AGL-1173, AGL-1383, AGL-1387, AGL-1390) were the same sentence\n * at different depths because the answer was derived from a mutable field on a\n * DIFFERENT document — a collection's `entryScreenId` — and every new way to\n * edit that pointer was a new bypass of `screensPerHost`. Here the fact is a\n * property of the screen, server-stamped by /api/hosts/screens and frozen in\n * the rules exactly as `kind: 'email'` has been since AGL-1383.\n *\n * NOT a collection's LIST template. `/{collectionSlug}` renders that exact\n * screen with its entries, so it is a designed reachable page and AGL-1387\n * made it count; converting one would take the page off the site.\n */\nexport const SCREEN_KIND_TEMPLATE = 'template'\n\n/**\n * `kind` of a designed ERROR screen (AGL-2092): the screen a host assigns to\n * one of `errorScreens`' four status slots, rendered on paths that did not\n * match — and so, like an entry template, at no address of its own.\n *\n * the decision on 2026-08-18 was that these must not spend the plan's screen\n * allowance, for the reason AGL-1173 excluded an entry template: the governing\n * question is whether the screen occupies a URL of its own, and a 404 body does\n * not. (A collection's LIST template does — `/{collectionSlug}` renders that\n * exact screen — which is why AGL-1387 left it counting.)\n *\n * ## This value does NOT get `kind: 'template'`'s trust\n *\n * `billableScreenIds` short-circuits on `SCREEN_KIND_TEMPLATE` BEFORE it\n * consults the routing map, because a template is routed on purpose. An error\n * screen is not, so it deliberately falls through to the ordinary rule and\n * **the routing map outranks this field**: a screen still published at an\n * address of its own counts, whatever it says about itself. That is the whole\n * migration story for the error screens that already exist — see\n * {@link ERROR_SCREEN_MAX_PER_HOST}.\n *\n * Stamped only by /api/hosts/screens, as part of binding the screen to a slot,\n * and frozen against the client by the same rule that has frozen `kind` since\n * AGL-1383. Nothing about that is new for this value; what IS new is that the\n * stamp is BOUNDED, because unlike a template there is no natural limit on how\n * many screens somebody would like to declare as error pages.\n */\nexport const SCREEN_KIND_ERROR = 'error'\n\n/**\n * How many screens one host may hold with `kind: 'error'` (AGL-2092).\n *\n * An exclusion the metered party can ask for is a free-screen generator unless\n * something bounds it, and the four bindings in `HostErrorScreens` are the\n * bound: at most one exempt screen per error slot. It is `.length` of the slot\n * list rather than a literal `4` so the two can never disagree.\n *\n * Checked in TWO places, and the second is the one that makes the number true\n * (AGL-2093). At the moment of the STAMP, against the post-state — the\n * AGL-1390 shape, which produces the refusal worth reading because it can name\n * the four slots. And inside `billableScreenIds` itself, where a live error\n * screen past this bound is counted as an ordinary page: the stamp is not the\n * only writer, and a crafted import bundle carrying `kind: 'error'` on all 200\n * of its screens passed no bound at all until the rule owned one. An exclusion\n * enforced only at the write paths somebody remembered is the sentence this arc\n * has now repeated six times.\n *\n * The tempting alternative is to enforce \"bound to a slot\" as an\n * invariant, promoting a screen back to a page whenever its slot is cleared;\n * that is AGL-1390's refuse-the-clear bug wearing a different hat, because\n * promotion raises the count and a host at its cap could then never unassign an\n * error screen. So clearing a slot is always allowed and leaves the screen an\n * error screen — unbilled, unrouted, and one deliberate click from being a page\n * again — and what is bounded is how many of them can exist at once.\n */\nexport const ERROR_SCREEN_MAX_PER_HOST = HOST_ERROR_SCREEN_SLOTS.length\n\n/** The two self-describing fields {@link screenClaimsToBeAPage} reads. */\nexport interface ScreenPageClaim {\n kind?: string\n deletedAt?: unknown\n}\n\n/**\n * Whether a screen document claims to be a page of the site at all (AGL-1383).\n *\n * Four things say it is not: `deletedAt` (soft-deleted — delete stamps the\n * field rather than removing the doc), `kind: 'email'` (an Emails-page\n * document, which has no URL and is rendered only by the campaign sender,\n * straight off the doc), `kind: 'template'` (a collection entry template,\n * which composes `/{collection}/{entry}` and has no address of its own —\n * AGL-1400), `kind: 'error'` (a screen assigned to one of the host's four\n * error slots, rendered on paths that matched nothing — AGL-2092) and\n * `kind: 'group'` (a folder of pages with no address, slug or content of its\n * own — AGL-3463). All five are also the exclusions `countBillableScreens`\n * subtracts before enforcing `screensPerHost`, and since AGL-1400 they are the\n * WHOLE of that subtraction: the count reads no other collection.\n *\n * Adding the fourth and fifth needed no edit to `billableScreenIds` and no edit to\n * `nonPageScreenIds`, which is the property AGL-1439 wrote them for: the\n * routing-map override applies to a new non-page `kind` by default, and the\n * flat infrastructure cap is the complement, so there is no second list to\n * remember. Only `kind: 'template'` is named anywhere else, because only it\n * opts OUT of the routing-map override.\n *\n * That is exactly why this is ONE function with TWO callers rather than two\n * matching filters. Both fields are ordinary client-writable fields on\n * `hosts/{hostId}/screens/{screenId}`, and until AGL-1383 only the count read\n * them: an editor on a Free site could `updateDoc(screenRef, {kind: 'email'})`\n * and the screen stopped counting against the plan while the routing map still\n * pointed at it and the runtime still served it — a live page, for free. An\n * exclusion is only sound if an excluded screen genuinely is not a page, so the\n * serve path asks this question too, and flipping either field now costs the\n * page instead of the plan.\n *\n * A CLAIM, not the answer, for the two fields a client can still reach: the\n * routing map decides reachability, and `countBillableScreens` trusts\n * `deletedAt` / `kind: 'email'` only for screens the map does not route.\n * `kind: 'error'` is in the client-can-still-reach group for counting purposes\n * even though no client writes it either: an error screen that is ALSO\n * published at an address is a page somebody is using as a page, so the map\n * outranks the stamp and it counts. Serving is the other way round — see\n * `getScreen`, which returns error screens rather than 404ing them, because\n * refusing would break the customer's own designed error page without closing\n * anything (they are already paying for it if it is routed).\n *\n * `kind: 'template'` is the exception, and the reason it can be one is that no\n * client writes it — /api/hosts/screens stamps it, demotion lowers the count\n * and promotion is checked exactly like a create, so there is no toggle to\n * launder. A template is ROUTED on purpose (publishing is how the compose\n * pipeline picks it up), which is why the map cannot be the arbiter for it.\n */\nexport function screenClaimsToBeAPage(\n screen: ScreenPageClaim | null | undefined,\n): boolean {\n if (!screen) return false\n return (\n screen.deletedAt == null &&\n screen.kind !== SCREEN_KIND_EMAIL &&\n screen.kind !== SCREEN_KIND_TEMPLATE &&\n screen.kind !== SCREEN_KIND_ERROR &&\n screen.kind !== SCREEN_KIND_GROUP\n )\n}\n\n/**\n * One screen, reduced to the two things {@link billableScreenIds} asks about.\n *\n * Rows rather than a query (AGL-1390) because the enforcement points ask about\n * a state that does not exist yet: a promotion is checked against the count it\n * WOULD leave behind. A function that does its own reads can only answer for\n * the present. `readScreenSources` in /api/hosts/resources is the reader.\n */\nexport interface BillableScreenSource {\n id: string\n kind?: unknown\n deletedAt?: unknown\n}\n\n/**\n * A host's `screens` routing map (screen id → route path) as\n * `publishScreenRoute` writes it. Only membership is read, never the path.\n */\nexport type ScreenRoutingMap = Record<string, unknown> | null | undefined\n\n/**\n * WHICH screens spend the plan's screen allowance (AGL-1173).\n *\n * The ids rather than the count, because an enforcement point that cannot name\n * the screen it is refusing over is a refusal the person reading it cannot act\n * on.\n *\n * A plain `screens.count()` charged for three things the subscriber never\n * chose to author, and the screens list — which filters them out — then\n * disagreed with the server about how much of the plan was used:\n *\n * - **Soft-deleted screens.** Delete stamps `deletedAt` rather than\n * removing the doc, so deleting a screen never freed a slot. On the free\n * plan (5 screens) that was a dead end with no way out from the UI.\n * - **Email screens** (`kind: 'email'`), which live on the Emails page and\n * were already excluded from the list count but not from enforcement.\n * - **A collection's ENTRY template** — one screen serving every entry at no\n * URL of its own. Adding a blog cost two of the free plan's five screens\n * before the first page existed.\n *\n * ## Why it lives HERE, next to the predicate (AGL-2093)\n *\n * It was in /api/hosts/resources, and the console's Screens page — which runs\n * the same rule as a precheck before it lets somebody add a page — could not\n * import it from there (that module reaches `@aglyn/aglyn/server`, which pulls\n * `node:stream` in through the API adapter). So the page restated it, and the\n * restatement drifted: it never learned the error-screen bound below, and on a\n * host holding five `kind: 'error'` screens the console offered room the API\n * then refused. A precheck that warns on a different number than the API\n * enforces is worse than no precheck at all, and a rule that has to be\n * restated to be reused will be restated wrongly eventually. One function, two\n * callers.\n *\n * ## ONE document answers it now (AGL-1400)\n *\n * The third exclusion used to be a JOIN: the count read the `collections`\n * collection and subtracted whatever screen ids the template pointers named.\n * That shape produced four issues in one arc, because the other side of the\n * join is editable and each new way to edit it was a new bypass — AGL-1173\n * created the exclusion, AGL-1383 froze the two fields the screen itself\n * carried, AGL-1387 found the list template was a page after all, and AGL-1390\n * found the pointer could be toggled to mint permanent slots and had to move\n * the write server-side and evaluate the cap against the post-state.\n *\n * Since AGL-1400 an entry template says so on its own document\n * (`kind: 'template'`), stamped by /api/hosts/screens and frozen in the rules\n * exactly as `kind: 'email'` is. So this reads the `screens` collection and\n * nothing else: the pointer is a pointer again, freely writable, and it excuses\n * nothing. `screenClaimsToBeAPage` is the whole rule, which is the property\n * that keeps the count and the serve path (`getScreen`) from ever disagreeing.\n *\n * What did NOT change is what anybody pays. A collection's LIST template stays\n * a page — `/{collectionSlug}` renders that exact screen (AGL-1387) — so it is\n * never stamped and still counts, and an entry template stays excluded\n * (AGL-1173's charge is not reinstated).\n *\n * ## The routing map outranks the document, and ONLY ADDS (AGL-1383, AGL-1445)\n *\n * `deletedAt` and `kind: 'email'` are ordinary client-writable fields on the\n * screen's OWN document, and the party they are subtracted on behalf of is the\n * party being metered. `updateDoc(screenRef, {kind: 'email'})` — one write, no\n * route change — used to take a live page off a Free plan's five and leave it\n * serving, because nothing else read either field. So for those two the\n * document's account of itself is consulted only for screens the routing map\n * does not route: **a routed screen counts, whatever it says about itself**.\n *\n * The converse is NOT true and must not become true, which is AGL-1445's\n * settlement. An unrouted screen with no slug — a draft, or an orphan left\n * behind by an unpublish — serves nothing, and it still counts:\n *\n * - `screensPerHost` is a CREATE-TIME gate. /api/hosts/resources counts and\n * refuses; `report-usage` re-measures monthly but RECORDS rather than\n * enforces. The create is the only door.\n * - A screen is born unrouted, and publishing is a separate later act — a\n * client `updateDoc` on the host's `screens` map (`publishScreenRoute`),\n * gated on `canPublishHostContent` and on nothing else.\n *\n * So subtracting unrouted screens would not make the count fairer, it would\n * make every create free — the new document is unrouted by construction — and\n * leave the publishes that follow ungated. A Free site would hold unlimited\n * pages. AGL-1445's option 2 (server-stamping a non-page `kind` on orphans by\n * a sweep) lands in the same place unless the promotion BACK passes a gate,\n * and for an orphan the promotion is the publish. `kind: 'template'` can be\n * trusted precisely because its promotion is `convertScreenKind`, checked\n * exactly like a create; there is no equivalent door in front of the routing\n * map. The price is one slot until somebody deletes the orphan, which is one\n * click and which the Screens page lists like any other row —\n * `unrouted-screen-counts.spec.ts` pins it at the enforcement point.\n *\n * `kind: 'template'` is deliberately outside the map's override, and it is the\n * one value that can be. A template is routed ON PURPOSE — publishing is how\n * the compose pipeline picks it up, and AGL-1267 drops it from routing when the\n * request arrives — so the map cannot be the arbiter for it. What makes\n * trusting it safe is that no client writes it: the demotion that sets it\n * always succeeds (it lowers the count) and the promotion that clears it is\n * checked exactly like a create (it raises it), so there is no toggle to run a\n * loop through.\n */\nexport function billableScreenIds(\n screens: ReadonlyArray<BillableScreenSource>,\n routingMap?: ScreenRoutingMap,\n): Set<string> {\n const routed = new Set(Object.keys(routingMap ?? {}))\n const exemptErrors = exemptErrorScreenIds(screens)\n const billable = new Set<string>()\n for (const screen of screens) {\n if (screen.kind === SCREEN_KIND_TEMPLATE) continue\n const claimsToBeAPage = screenClaimsToBeAPage({\n kind: screen.kind as string,\n deletedAt: screen.deletedAt,\n })\n // A `kind: 'error'` screen OVER the slot bound is a page again (AGL-2093).\n const exemptionSpent =\n screen.kind === SCREEN_KIND_ERROR &&\n screen.deletedAt == null &&\n !exemptErrors.has(screen.id)\n if (routed.has(screen.id) || claimsToBeAPage || exemptionSpent) {\n billable.add(screen.id)\n }\n }\n return billable\n}\n\n/**\n * The live `kind: 'error'` screens whose billing exemption actually HOLDS —\n * at most {@link ERROR_SCREEN_MAX_PER_HOST} of them (AGL-2093).\n *\n * ## Why the bound lives here and not at one endpoint\n *\n * AGL-2092 introduced the exemption and bounded it at four — one per\n * `HostErrorScreens` slot — by checking the post-state at the moment\n * /api/hosts/screens STAMPS the kind. That made the claim true of the assign\n * route and false end to end, because the stamp is not the only writer:\n * `SITE_EXPORT_FIELDS.screens` carries `kind`, so a hand-edited bundle could\n * declare `kind: 'error'` on all 200 of its screens and /api/hosts/import\n * excluded every one of them from `screensPerHost` — never passing the bound,\n * never binding a slot. N unbilled screens, one file.\n *\n * That is the arc's fifth repetition of one sentence (AGL-1173, AGL-1383,\n * AGL-1387, AGL-1390, AGL-1400): *an exclusion enforced at a write path is\n * enforced only at the write paths somebody remembered.* So the bound moves\n * into the rule the enforcement points SHARE. However a screen came to say\n * `kind: 'error'` — assign, import, or the next writer — a host gets four\n * unbilled ones and the rest spend the plan's allowance exactly as pages do.\n *\n * ## Which four\n *\n * The lowest ids, sorted. The choice is arbitrary and the DETERMINISM is not:\n * every enforcement point models a post-state by re-running this over a\n * different row set, and a rule that picked \"the first four encountered\" would\n * hand two callers different answers for the same host. The SIZE of the exempt\n * set never depends on the order — it is `min(live errors, 4)` — so only which\n * ids a refusal message names can move, never whether one is refused.\n *\n * Tombstones are excluded for `nonPageScreenIds`' reason: a cap counting\n * soft-deleted rows is AGL-1173's bug one cap over, where deleting an error\n * screen never frees its slot.\n *\n * The stamp-time bound in /api/hosts/screens is deliberately KEPT. It is the\n * better refusal — it names the four slots and arrives before the write — and\n * this is the backstop under it, so no writer can mint a fifth unbilled error\n * screen even by a path that never consults it.\n */\nexport function exemptErrorScreenIds(\n screens: ReadonlyArray<BillableScreenSource>,\n): Set<string> {\n const live: Array<string> = []\n for (const screen of screens) {\n if (screen.kind !== SCREEN_KIND_ERROR) continue\n if (screen.deletedAt != null) continue\n live.push(screen.id)\n }\n if (live.length <= ERROR_SCREEN_MAX_PER_HOST) return new Set(live)\n return new Set(live.sort().slice(0, ERROR_SCREEN_MAX_PER_HOST))\n}\n\n/**\n * The screens the flat platform cap bounds (AGL-1399, AGL-1439): LIVE documents\n * that are not billable pages — the exact complement of {@link billableScreenIds}.\n *\n * ## Why the complement, and not `kind === 'email' || kind === 'template'`\n *\n * Both issues are one sentence — *a `kind` value that excludes a document from\n * billing, declarable by the metered party* — and a cap that enumerated the two\n * values would be correct until the third arrived, which is how this arc has\n * already gone four times (AGL-1173, AGL-1383, AGL-1387, AGL-1390). Written as\n * the complement, a new non-page `kind` is bounded by the act of adding it to\n * `screenClaimsToBeAPage`: there is no second list to remember.\n *\n * Two properties fall out of taking the complement rather than negating the\n * predicate directly:\n *\n * - **A soft-deleted screen is in NEITHER set.** Delete stamps `deletedAt`\n * rather than removing the doc, and a cap that counted tombstones would be\n * the AGL-1173 bug one cap over — deleting an email document would never free\n * a slot, and a host at the cap could never author another.\n * - **A ROUTED email document counts once, against the plan.** The routing map\n * outranks the document (AGL-1383), so such a screen is a page somebody is\n * already paying for; charging it to the infrastructure cap as well would be\n * counting one document twice. The two sets partition the live screens.\n *\n * Taking the complement is also what makes AGL-2093's bound arrive here for\n * free: an error screen past `ERROR_SCREEN_MAX_PER_HOST` becomes billable\n * above, so it leaves this set in the same act. The partition holds — every\n * live screen is in exactly one of the two — and the fifth error screen is\n * bounded by the PLAN rather than by the flat 5,000, which is the stronger of\n * the two numbers on every finite tier.\n */\nexport function nonPageScreenIds(\n screens: ReadonlyArray<BillableScreenSource>,\n routingMap?: ScreenRoutingMap,\n): Set<string> {\n const billable = billableScreenIds(screens, routingMap)\n const nonPage = new Set<string>()\n for (const screen of screens) {\n if (screen.deletedAt != null) continue\n if (!billable.has(screen.id)) nonPage.add(screen.id)\n }\n return nonPage\n}\n\n/**\n * How many LIVE screen documents a host may hold that are NOT billable pages —\n * email documents, entry templates, and whatever non-page `kind` comes next\n * (AGL-1399, AGL-1439).\n *\n * ## Why a flat number and not a plan dimension\n *\n * Every exclusion `screenClaimsToBeAPage` names is declared by the party being\n * metered: `kind: 'email'` is on the create allow-list because the email\n * composer must send it, and AGL-1400 gave `kind: 'template'` the same\n * billing-excluding meaning. So `POST /api/hosts/resources` with\n * `kind: 'email'` created a document that no cap counted, without limit, on a\n * free plan — unbounded Firestore documents rather than a bypass of anything we\n * sell. AGL-1439 is the same sentence one value over, and a cap enumerating the\n * two values would leave the hole open for the third.\n *\n * The shape is `WEBHOOK_MAX_PER_HOST`'s (AGL-1360): no `OrgEntitlements` key, no\n * variation by plan, counted from a server read at the create path. An\n * `emailDocumentsPerHost` would have been a **pricing** decision — a number the\n * price list has to explain and support has to defend — for a limit whose only\n * job is to bound infrastructure. This is not the charge AGL-1173 removed and it\n * does not reinstate it: nothing here is billable, and `screensPerHost` counts\n * exactly what it counted yesterday.\n *\n * ## Why 5,000\n *\n * Sized to the heaviest library anybody could plausibly author, not to what\n * exists: production's busiest host holds FOUR non-page screens (one email,\n * three entry templates) across five hosts, so any bar sized to today's data\n * would be meaningless. The real quantity is campaigns, which accumulate and are\n * never deleted — a DAILY newsletter reaches 5,000 after thirteen years, and a\n * thrice-weekly one after thirty-two. Entry templates contribute one per\n * collection, so tens at the outside. Nothing a real customer does approaches\n * this, which is the property that matters: the failure mode of a too-low flat\n * cap is blocking legitimate work with an error the price list cannot explain.\n *\n * A cheaper bound is not worth much either. What the number defends against is a\n * script in a loop, and a loop stopped at 5,000 documents is stopped. It also\n * bounds the cost of the count itself — `countBillableScreens` scans the screens\n * collection on every create at one billed read per document (AGL-1440), and\n * before this cap that scan had no ceiling at all.\n */\nexport const NON_PAGE_SCREEN_MAX_PER_HOST = 5000\n"],"names":["HOST_ERROR_SCREEN_SLOTS","collectionListUrl","ENTRY_PREVIEW_ROUTE_SEGMENT","LEAVING_NOTICE_ROUTE_SEGMENT","PLATFORM_BRAND_NAME","formatCollectionLinkValue","formatEntryLinkValue","formatFeedLinkValue","parseEntryLinkValue","SCREEN_ROOT_PATH","normalizeScreenSlug","input","trimmed","trim","undefined","segment","toLowerCase","replace","RESERVED_SCREEN_ROUTE_SEGMENTS","reservedScreenRouteSegment","path","first","split","includes","reservedScreenRouteMessage","screenSlugHasPathSeparator","SCREEN_SLUG_PATH_SEPARATOR_MESSAGE","SCREEN_KIND_GROUP","toScreenRouteNode","screen","node","slug","parentId","kind","isScreenGroup","MAX_SCREEN_DEPTH","composeScreenRoutePath","screenId","screensById","segments","visited","Set","currentId","isHomePage","has","size","add","unshift","length","join","screenRouteParentId","screenGroupDissolveMoves","groupId","group","nextParentId","moves","id","Object","entries","collectScreenDescendantIds","childrenByParent","Map","siblings","get","push","set","result","queue","shift","wouldCreateScreenCycle","buildScreenRouteEntries","routingMap","options","publish","currentById","routedPath","ownPath","live","liveScreenDescendants","sort","a","b","findScreenIdByRoutePath","screens","entry","find","value","blockingRouteOwner","defaultHomeScreenId","owner","screenRoutePathToUrl","screenRoutePathFromUrl","urlPath","raw","String","startsWith","bare","ownScreenSlugFromRoutePath","filter","Boolean","collectionFeedRoutePath","collectionSlug","listing","collectionEntryRoutePath","entrySlug","linkableScreenRoutes","sources","routedElsewhere","unrouted","collectionListings","entryRoutes","overrides","listings","next","collectionId","key","normalized","entryId","SCREEN_KIND_EMAIL","SCREEN_KIND_TEMPLATE","SCREEN_KIND_ERROR","ERROR_SCREEN_MAX_PER_HOST","screenClaimsToBeAPage","deletedAt","billableScreenIds","routed","keys","exemptErrors","exemptErrorScreenIds","billable","claimsToBeAPage","exemptionSpent","slice","nonPageScreenIds","nonPage","NON_PAGE_SCREEN_MAX_PER_HOST"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,uBAAuB,QAAwB,yBAAe;AACvE,SAASC,iBAAiB,QAAQ,0BAAsB;AACxD,SAASC,2BAA2B,QAAQ,0BAAsB;AAClE,SAASC,4BAA4B,QAAQ,sBAAkB;AAC/D,SAASC,mBAAmB,QAAQ,sBAAkB;AACtD,SACEC,yBAAyB,EACzBC,oBAAoB,EACpBC,mBAAmB,EACnBC,mBAAmB,QACd,yBAAqB;AAE5B;;;;;;CAMC,GACD,OAAO,MAAMC,mBAAmB,IAA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6B;IAE7B,MAAM0D,WAAWL,kBAAkBzC,SAASZ;IAC5C,MAAM+D,UAAU,IAAI7F;IACpB,KAAK,MAAMZ,UAAUsD,QAAS;QAC5B,IAAItD,OAAO8F,SAAS,IAAI,MAAM;QAC9B,IAAI,CAACM,SAASrF,GAAG,CAACf,OAAO2B,EAAE,GAAG8E,QAAQxF,GAAG,CAACjB,OAAO2B,EAAE;IACrD;IACA,OAAO8E;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCC,GACD,OAAO,MAAMC,+BAA+B,KAAI"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/screen-route.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HOST_ERROR_SCREEN_SLOTS, type ScreenUid } from '../foundation'\nimport { collectionListUrl } from './collection-entries'\nimport { ENTRY_PREVIEW_ROUTE_SEGMENT } from './entry-preview-link'\nimport { LEAVING_NOTICE_ROUTE_SEGMENT } from './leaving-notice'\nimport { PLATFORM_BRAND_NAME } from './platform-brand'\nimport { SCREEN_KIND_EMAIL } from './screen-kind'\nimport {\n formatCollectionLinkValue,\n formatEntryLinkValue,\n formatFeedLinkValue,\n parseEntryLinkValue,\n} from './screen-link-value'\n\n/**\n * Route path of a host's root screen. The tenant matcher joins the catch-all\n * segments and collapses an empty one to this value (`load-page-data.ts`:\n * `slugSegments.length ? slugSegments.join('/') : SCREEN_ROOT_PATH`), so the\n * root is `'/'` and every other path is slash-joined segments WITHOUT a\n * leading slash (`about`, later `company/about`).\n */\nexport const SCREEN_ROOT_PATH = '/'\n\n/**\n * Normalizes user slug input into the routing-map path format described on\n * {@link SCREEN_ROOT_PATH}. `'/'` normalizes to the root path; anything else\n * becomes a single lowercase url-safe segment.\n *\n * Returns `undefined` for EMPTY input and for anything that sanitizes away\n * (`'###'`) — the two cases are deliberately the same answer, and the caller\n * decides what it means. In the Screens page's slug field an empty string\n * means \"no address typed\"; in a starter template it meant \"home\". Two\n * meanings for one value is what made AGL-1575 possible, so this function\n * refuses to pick one: a caller that wants the root must say `'/'`.\n *\n * This docstring used to claim empty input normalized to the root, which the\n * code has never done (see the spec, which asserts the `undefined`). A fix\n * written against the docstring instead of the behaviour would have shipped\n * broken; if you are here to make the code match the comment, do not.\n */\nexport function normalizeScreenSlug(\n input: string | null | undefined,\n): string | undefined {\n const trimmed = (input ?? '').trim()\n if (!trimmed) return undefined\n if (trimmed === SCREEN_ROOT_PATH) return SCREEN_ROOT_PATH\n\n const segment = trimmed\n .toLowerCase()\n .replace(/^\\/+|\\/+$/g, '')\n .replace(/\\s+/g, '-')\n .replace(/[^a-z0-9-_]/g, '')\n .replace(/-{2,}/g, '-')\n .replace(/^-+|-+$/g, '')\n\n return segment || undefined\n}\n\n/**\n * Route segments the published site CANNOT serve, whatever the routing map\n * says (AGL-2076).\n *\n * Every entry was measured against production on 2026-08-19 with a fresh\n * `x-vercel-cache: MISS`, because a stale negative always passes. Two\n * mechanisms, both of which resolve ahead of `[host]/[scheme]/[[...slug]]`:\n *\n * - `404`, `500` — Next emits `pages/404.html` and `pages/500.html` even for\n * an app-router-only build, and the deployed filesystem answers them as\n * static files (`content-disposition: inline; filename=\"404\"`,\n * `accept-ranges`, an `etag`, and no `x-nextjs-prerender`). The tenant\n * middleware's own CSP headers are on those responses, so the middleware\n * ran and its rewrite still lost. There is no rewrite this app can write\n * that beats them, which is why the honest fix is to refuse the slug at\n * authoring time rather than to keep promising an address that is dead.\n * - `search`, `api`, `_next`, `_static` — routes and exclusions the tenant\n * app owns. `/search` matches `app/[host]/[scheme]/search`; the other three are the\n * middleware matcher's exclusions, so no host rewrite happens at all and\n * the path is parsed as `[host]` with an empty slug.\n * - `aglyn-preview` — the same mechanism as `search`, one route over\n * (AGL-3205). The live-site preview of an unpublished collection entry is\n * a rewrite to `app/[host]/[scheme]/aglyn-preview/[...slug]`, because it\n * must be a DIFFERENT Next route from the ISR-cached catch-all; a static\n * folder wins over the optional catch-all beside it, so `/aglyn-preview/x`\n * would reach the preview page and 404 rather than render a screen. The\n * bare `/aglyn-preview` would in fact still serve — the preview route's\n * catch-all is required, not optional — and it is reserved anyway for the\n * reason given below about child paths: a child's path is composed from\n * its parent's slug, and this rule refuses that slug.\n * - `_aglyn` — the platform's own pages on every site, the leaving notice\n * at `/_aglyn/leaving` first (AGL-3452). The middleware rewrites that path\n * to an api route before the catch-all could see it.\n *\n * NOT reserved, and deliberately so, because measuring found them fine:\n * `401`, `403`, `503` (`/401` returns 200 through the catch-all — two of the\n * four designed error screens have always been viewable at their slugs, which\n * is what made the `404` case look like a Next.js defect), and `index`.\n *\n * `fonts` and `examples` USED to be dead for the third reason and are not\n * here: they were exclusions inherited from the Vercel platforms starter kit\n * for directories `apps/tenant/public` has never contained. They are given\n * back rather than reserved — see the matcher in `apps/tenant/middleware.ts`.\n */\nexport const RESERVED_SCREEN_ROUTE_SEGMENTS: readonly string[] = [\n '404',\n '500',\n 'search',\n ENTRY_PREVIEW_ROUTE_SEGMENT,\n 'api',\n '_next',\n '_static',\n LEAVING_NOTICE_ROUTE_SEGMENT,\n]\n\n/**\n * The reserved segment a routing-map path would collide with, or `undefined`\n * when the path is servable. The segment rather than a boolean, so a refusal\n * can name what it is refusing over.\n *\n * Reads the FIRST segment only. For `api`/`_next`/`_static` that is exactly\n * right — the middleware excludes the whole subtree, so `api/docs` is as dead\n * as `api`. For `404`/`500`/`search` it over-refuses in principle (`/404/why`\n * would serve), and that is deliberate: a child path is composed from its\n * PARENT's slug, the parent would have to hold `404`, and this same rule\n * refuses that slug wherever one is typed. A second list to express a case\n * that cannot arise would be a second list to keep correct.\n *\n * Takes a composed routing-map path (`about`, `company/about`, `'/'`), not a\n * raw slug field — `'/'` is the home screen and is never reserved.\n */\nexport function reservedScreenRouteSegment(\n path: string | null | undefined,\n): string | undefined {\n if (!path || path === SCREEN_ROOT_PATH) return undefined\n const [first] = path.replace(/^\\/+/, '').split('/')\n return RESERVED_SCREEN_ROUTE_SEGMENTS.includes(first) ? first : undefined\n}\n\n/**\n * The refusal an author reads when {@link reservedScreenRouteSegment} names a\n * segment. One sentence, in one place, because the Screens page, the version\n * view and the besigner all have to say the same thing — three surfaces\n * wording a platform constraint three ways is how AGL-2093's precheck drifted.\n */\nexport function reservedScreenRouteMessage(segment: string): string {\n return `\"/${segment}\" is a reserved address on every ${PLATFORM_BRAND_NAME} site — pick another slug`\n}\n\n/**\n * Does a raw slug value carry a path separator the one segment it describes\n * cannot hold (AGL-2572)?\n *\n * {@link normalizeScreenSlug} answers with a SINGLE segment, and it gets there\n * by deleting every character outside `[a-z0-9-_]` — an interior `/` included.\n * Whitespace becomes a `-`, but a `/` becomes nothing at all, so\n * `alternatives/webflow` normalizes to `alternativeswebflow` and the two words\n * are stored glued. Nothing about that is visible: the field accepts the\n * keystroke, the composed path reads plausibly, and the screen ends up\n * answering an address nobody typed. Two screens on `aglyn-marketing` carry a\n * slug of that shape.\n *\n * So the separator is a question a slug field asks BEFORE normalizing, and the\n * answer is a refusal rather than a silent repair — the caller cannot know\n * which segment the author meant, and guessing is how the glue happened.\n *\n * LEADING and TRAILING slashes are not separators here. `normalizeScreenSlug`\n * strips them deliberately (`/about/` → `about`), an author typing an address\n * writes them without meaning a hierarchy, and refusing them would reject a\n * value the normalizer has always handled correctly. `'/'` alone is the home\n * page and is never a separator.\n */\nexport function screenSlugHasPathSeparator(\n input: string | null | undefined,\n): boolean {\n const trimmed = (input ?? '').trim()\n if (!trimmed || trimmed === SCREEN_ROOT_PATH) return false\n return trimmed.replace(/^\\/+|\\/+$/g, '').includes('/')\n}\n\n/**\n * The refusal an author reads when {@link screenSlugHasPathSeparator} answers\n * true. One sentence, in one place, for the same reason\n * {@link reservedScreenRouteMessage} is: the Screens page, the version view\n * and the besigner all take a slug, and a constraint worded three ways drifts\n * into three different constraints.\n *\n * It names the alternative, because a `/` in this field almost always means\n * \"nest me\" and the hierarchy is what actually composes the longer path.\n */\nexport const SCREEN_SLUG_PATH_SEPARATOR_MESSAGE =\n 'A slug is one path segment — remove the \"/\" and nest the page under a ' +\n 'parent page instead'\n\n/**\n * `kind` of a page GROUP (AGL-3463): a folder in the Pages list that holds\n * pages and is not one.\n *\n * A group has no slug, no versions and no address. It is never routed, never\n * published or scheduled, and it contributes NOTHING to its descendants'\n * paths — a page inside a group composes exactly as if it sat at the group's\n * own level, so moving a page into or out of a group at that level leaves its\n * URL untouched. A group nested in a group behaves the same way.\n *\n * It has to be a declared kind rather than \"a parent with no slug\", because a\n * slugless parent already means something: an unpublished page, and\n * {@link composeScreenRoutePath} refuses every path beneath one. Pages under\n * a slugless parent keep the addresses they already have, but no page there\n * can be published, which is the opposite of what a folder is for.\n *\n * A group is not a page, so it is in {@link screenClaimsToBeAPage}'s list and\n * spends none of the plan's page allowance. That is safe for the reasons the\n * other non-page kinds are: `kind` is stamped at create by\n * /api/hosts/resources and frozen against the client by the rules, no route\n * converts a group into anything else, and the serve path refuses a non-page\n * claim — so a group can never be laundered into a page it did not pay for,\n * and the flat {@link NON_PAGE_SCREEN_MAX_PER_HOST} bounds how many exist.\n */\nexport const SCREEN_KIND_GROUP = 'group'\n\n/** Minimal screen shape the hierarchy helpers need. */\nexport interface ScreenRouteNode {\n slug?: string\n parentId?: ScreenUid\n /**\n * The screen's `kind`. Read here for ONE value, {@link SCREEN_KIND_GROUP}:\n * a group contributes nothing to a path, where a slugless page breaks it.\n * A caller that leaves this out makes every group look like an unpublished\n * page — build nodes with {@link toScreenRouteNode} so it cannot.\n */\n kind?: string\n}\n\n/**\n * The {@link ScreenRouteNode} of a screen document: the three fields path\n * composition reads, and nothing else. Every surface that composes paths\n * builds its map through this, because a map built from `{ slug, parentId }`\n * alone silently reads a group as an unpublished page and unroutes every page\n * inside it (AGL-3463).\n */\nexport function toScreenRouteNode(screen: {\n slug?: unknown\n parentId?: unknown\n kind?: unknown\n}): ScreenRouteNode {\n const node: ScreenRouteNode = {}\n if (typeof screen.slug === 'string') node.slug = screen.slug\n if (typeof screen.parentId === 'string' && screen.parentId) {\n node.parentId = screen.parentId\n }\n if (typeof screen.kind === 'string') node.kind = screen.kind\n return node\n}\n\n/** Is this screen a page group ({@link SCREEN_KIND_GROUP})? */\nexport function isScreenGroup(\n screen: { kind?: unknown } | null | undefined,\n): boolean {\n return screen?.kind === SCREEN_KIND_GROUP\n}\n\n/** Defensive cap: parent chains deeper than this are treated as invalid. */\nconst MAX_SCREEN_DEPTH = 32\n\n/**\n * Composes a screen's routing-map path from its own slug plus its ancestor\n * chain: parent `company` + own `about` → `company/about`. Root (`'/'`)\n * segments contribute nothing, so children of the home screen sit at the\n * top level, and GROUP ancestors contribute nothing either (AGL-3463) — they\n * are passed through as if the screen sat at the group's own level.\n *\n * Returns `undefined` when the screen is itself a group, when it (or any\n * non-group ancestor) has no slug, when its own slug is `'/'` while it has a\n * non-group ancestor, or when the chain has a cycle / exceeds\n * {@link MAX_SCREEN_DEPTH}.\n */\nexport function composeScreenRoutePath(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): string | undefined {\n // A group is never an address, whatever else its document says.\n if (isScreenGroup(screensById[screenId])) return undefined\n const segments: string[] = []\n const visited = new Set<ScreenUid>()\n let currentId: ScreenUid | undefined = screenId\n let isHomePage = false\n\n while (currentId) {\n if (visited.has(currentId) || visited.size >= MAX_SCREEN_DEPTH) {\n return undefined\n }\n visited.add(currentId)\n const screen = screensById[currentId]\n if (isScreenGroup(screen)) {\n // No segment, and no slug required: a group does not gate the pages\n // inside it. Its own slug, if a stray one exists, is ignored.\n currentId = screen?.parentId\n continue\n }\n if (!screen?.slug) return undefined\n // The home screen's segment is empty (children of home sit at the top\n // level), but a screen can't itself be the home page AND sit under\n // another page. Groups above it are fine — they are not levels.\n if (isHomePage) return undefined\n if (screen.slug === SCREEN_ROOT_PATH) {\n if (currentId === screenId) isHomePage = true\n } else {\n segments.unshift(screen.slug)\n }\n currentId = screen.parentId\n }\n\n if (!segments.length) return isHomePage ? SCREEN_ROOT_PATH : undefined\n return segments.join('/')\n}\n\n/**\n * The nearest ancestor that is NOT a group — the screen whose level a page\n * actually composes its path at — or `undefined` for the top level\n * (AGL-3463). Two placements with the same answer compose the same path,\n * which is what makes moving a page into or out of a group at that level a\n * move that cannot change its URL.\n */\nexport function screenRouteParentId(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): ScreenUid | undefined {\n const visited = new Set<ScreenUid>([screenId])\n let currentId = screensById[screenId]?.parentId\n while (currentId && !visited.has(currentId)) {\n visited.add(currentId)\n const screen = screensById[currentId]\n if (!isScreenGroup(screen)) return currentId\n currentId = screen?.parentId\n }\n return undefined\n}\n\n/**\n * Where each child of a group goes when the group is deleted: one level up,\n * under the group's own parent (AGL-3463). A child id → its next `parentId`\n * (`undefined` for the top level).\n *\n * Only DIRECT children move; grandchildren ride along under them. Because a\n * group contributes nothing to a path, the children's composed paths are the\n * same before and after, so deleting a group never touches the routing map.\n * Answers `{}` for a screen that is not a group — deleting a page is a\n * different act with a different consequence for what sits under it.\n */\nexport function screenGroupDissolveMoves(\n groupId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): Record<ScreenUid, ScreenUid | undefined> {\n const group = screensById[groupId]\n if (!isScreenGroup(group)) return {}\n const nextParentId = group?.parentId\n const moves: Record<ScreenUid, ScreenUid | undefined> = {}\n for (const [id, screen] of Object.entries(screensById)) {\n if (id !== groupId && screen?.parentId === groupId) {\n moves[id] = nextParentId\n }\n }\n return moves\n}\n\n/**\n * All screens whose parent chain passes through `screenId` (children,\n * grandchildren, …). Used to cascade routing-map rewrites when a screen's\n * slug or parent changes.\n */\nexport function collectScreenDescendantIds(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): ScreenUid[] {\n const childrenByParent = new Map<ScreenUid, ScreenUid[]>()\n for (const [id, screen] of Object.entries(screensById)) {\n if (!screen?.parentId) continue\n const siblings = childrenByParent.get(screen.parentId) ?? []\n siblings.push(id)\n childrenByParent.set(screen.parentId, siblings)\n }\n const result: ScreenUid[] = []\n const queue = [...(childrenByParent.get(screenId) ?? [])]\n while (queue.length) {\n const id = queue.shift() as ScreenUid\n if (result.includes(id)) continue\n result.push(id)\n queue.push(...(childrenByParent.get(id) ?? []))\n }\n return result\n}\n\n/**\n * True when making `nextParentId` the parent of `screenId` would create a\n * loop — i.e. the candidate parent is the screen itself or one of its own\n * descendants.\n */\nexport function wouldCreateScreenCycle(\n screenId: ScreenUid,\n nextParentId: ScreenUid | undefined,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): boolean {\n if (!nextParentId) return false\n if (nextParentId === screenId) return true\n return collectScreenDescendantIds(screenId, screensById).includes(\n nextParentId,\n )\n}\n\n/** What {@link buildScreenRouteEntries} needs besides the candidate tree. */\nexport interface BuildScreenRouteEntriesOptions {\n /**\n * Is this call a PUBLISH of the screen it names, or only a move? (AGL-2571)\n *\n * An entry in the host's `screens` map is the whole of what makes a path\n * reachable, so writing one IS publishing — there is no second switch.\n * Assigning a parent to an unpublished screen that merely CARRIED a slug\n * would otherwise register it in the map, and the besigner toolbar, which\n * reads the map, would offer `Unpublish` and a `Live` link for a screen\n * nobody published, with no `publishedAt` and a 404 at the address.\n *\n * `true` lets the NAMED screen take an entry it does not have yet. It never\n * does that for a descendant: publishing a parent is not publishing the\n * drafts beneath it, which would put them live with no `publishedAt` and\n * nobody having asked. `false` restricts the write to entries that already\n * exist, so a move rewrites what is live and puts nothing new there.\n *\n * Defaults to `true`, which is what the publish buttons mean.\n */\n publish?: boolean\n /**\n * The screens map as it stands BEFORE this change (AGL-3463).\n *\n * A descendant follows a change to its ancestors only while it is ATTACHED:\n * its routing entry is the path it composes in this tree. One that kept its\n * address when its chain stopped resolving — its parent unpublished with\n * the slug cleared, deleted, or moved under a page with no slug — is\n * DETACHED, and a later publish or rename of that parent must not move it\n * somewhere new. Only the tree before the change can tell the two apart;\n * the candidate tree already composes the new path for both.\n */\n currentById: Record<ScreenUid, ScreenRouteNode | undefined>\n}\n\n/**\n * Routing-map entries to SET for a screen plus its descendants under a\n * candidate screens map. Callers apply the result in one write so slug and\n * parent changes cascade atomically.\n *\n * ## It never removes a route (AGL-3463)\n *\n * The answer holds paths only — no removals, ever. The routing map is the\n * whole of what makes a page reachable, so a removal computed here would take\n * a live page off the site as a side effect of a move, a rename or an\n * unpublish of something ABOVE it, with nobody having asked for that page to\n * go. Each of these therefore keeps the route it has:\n *\n * - a live screen whose chain no longer composes — moved under a page with\n * no slug, or its parent's slug cleared — keeps serving where it is;\n * - a DETACHED descendant (see\n * {@link BuildScreenRouteEntriesOptions.currentById}) stays where it is\n * when its ancestors change again;\n * - a group, which never composes a path, is never written.\n *\n * Taking a page off the site is a separate act on that page alone\n * (`unpublishScreenRoute`), so the only page that can stop resolving is the\n * one somebody pointed at.\n *\n * See {@link BuildScreenRouteEntriesOptions.publish} for the difference\n * between publishing a screen and merely moving one.\n */\nexport function buildScreenRouteEntries(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n routingMap: Record<ScreenUid, string> | null | undefined,\n options: BuildScreenRouteEntriesOptions,\n): Record<ScreenUid, string> {\n const { publish = true, currentById } = options\n const entries: Record<ScreenUid, string> = {}\n const routedPath = (id: ScreenUid) => {\n const path = routingMap?.[id]\n return typeof path === 'string' && path ? path : undefined\n }\n\n // The named screen: rewritten when it is live, registered when this is its\n // publish, and left exactly as it is when its new chain does not compose.\n const ownPath = composeScreenRoutePath(screenId, screensById)\n if (ownPath && (routedPath(screenId) !== undefined || publish)) {\n entries[screenId] = ownPath\n }\n\n for (const id of collectScreenDescendantIds(screenId, screensById)) {\n const live = routedPath(id)\n // A draft below a published parent stays a draft.\n if (live === undefined) continue\n // Detached: its address is not the one its chain composes today.\n if (composeScreenRoutePath(id, currentById) !== live) continue\n const path = composeScreenRoutePath(id, screensById)\n if (path) entries[id] = path\n }\n return entries\n}\n\n/** A page below another that is live at an address of its own. */\nexport interface LiveScreenDescendant {\n id: ScreenUid\n /** Its routing-map path (`company/about`, or `'/'` for the home page). */\n path: string\n}\n\n/**\n * Every descendant of `screenId` with a routing entry, ordered by address\n * (AGL-3463) — the pages that STAY LIVE when `screenId` is unpublished or\n * deleted, because neither act ever removes more than the one entry\n * ({@link buildScreenRouteEntries}).\n *\n * The unpublish and delete confirmations list these, so whoever takes a\n * parent down knows which pages below it keep serving and can take them\n * down separately if that is what they meant. Groups are walked through and\n * never listed: a group is not a page.\n */\nexport function liveScreenDescendants(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n routingMap: Record<ScreenUid, unknown> | null | undefined,\n): LiveScreenDescendant[] {\n const live: LiveScreenDescendant[] = []\n for (const id of collectScreenDescendantIds(screenId, screensById)) {\n const path = routingMap?.[id]\n if (typeof path !== 'string' || !path) continue\n if (isScreenGroup(screensById[id])) continue\n live.push({ id, path })\n }\n return live.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))\n}\n\n/**\n * Looks up which screen currently owns a routing path, for sibling-slug\n * uniqueness checks before publishing.\n */\nexport function findScreenIdByRoutePath(\n screens: Record<ScreenUid, string> | null | undefined,\n path: string,\n): ScreenUid | undefined {\n if (!screens) return undefined\n const entry = Object.entries(screens).find(([, value]) => value === path)\n return entry?.[0]\n}\n\n/**\n * The screen a publish at `path` would collide with, or `undefined` when the\n * address is free to take (AGL-3408).\n *\n * {@link findScreenIdByRoutePath} with one exception: the placeholder home\n * page a site is created with (`host.defaultHomeScreenId`) does not block the\n * site root. It holds `/` only so a new site never answers its own address\n * with a 404, and the first real page published there replaces it — the\n * publish seam removes its entry in the same write. It still blocks any other\n * path it has been moved to, and no other screen is ever passed over.\n *\n * Every publish surface's conflict check reads this rather than the raw owner,\n * so \"is this address taken?\" has one answer across them.\n */\nexport function blockingRouteOwner(\n screens: Record<ScreenUid, string> | null | undefined,\n path: string,\n defaultHomeScreenId?: string | null,\n): ScreenUid | undefined {\n const owner = findScreenIdByRoutePath(screens, path)\n if (owner && path === SCREEN_ROOT_PATH && owner === defaultHomeScreenId) {\n return undefined\n }\n return owner\n}\n\n/** Human-facing URL for a routing-map path (`'/'` stays `/`, `about` → `/about`). */\nexport function screenRoutePathToUrl(path: string): string {\n return path === SCREEN_ROOT_PATH ? SCREEN_ROOT_PATH : `/${path}`\n}\n\n/**\n * The routing-map path a page's URL path names — the inverse of\n * {@link screenRoutePathToUrl}: `/about` → `about`, `/company/about/` →\n * `company/about`, `/` and `''` → `/` (AGL-3461).\n *\n * For a door that knows the address a visitor was on and needs the screen\n * that served it: the host's routing map answers with no read. A query string\n * or a fragment is dropped; a value that is not a site-relative path answers\n * `undefined` rather than a routing key nobody wrote.\n */\nexport function screenRoutePathFromUrl(\n urlPath: string | null | undefined,\n): string | undefined {\n const raw = String(urlPath ?? '').trim()\n if (!raw) return SCREEN_ROOT_PATH\n if (!raw.startsWith('/') || raw.startsWith('//')) return undefined\n const bare = raw.split(/[?#]/)[0].replace(/^\\/+|\\/+$/g, '')\n return bare ? bare : SCREEN_ROOT_PATH\n}\n\n/**\n * A screen's OWN slug segment, read back off its composed routing-map path\n * (`company/about` → `about`) — the inverse of the one step\n * {@link composeScreenRoutePath} adds for this screen (AGL-2572).\n *\n * The slug field holds one segment; the routing map holds the whole composed\n * path. A field that seeds itself from the map therefore has to take the last\n * segment, and the besigner's seeded the whole path instead. Its value then\n * went through {@link normalizeScreenSlug}, which DELETES an interior `/`\n * rather than separating on it, so `alternatives/webflow` came back as the\n * glued `alternativeswebflow` and was stored as the screen's own slug —\n * without anyone typing it. Two screens on `aglyn-marketing` carry a slug of\n * that shape.\n *\n * Not a general path parser: it answers only \"which segment is this screen's\n * own\", which is always the last one.\n */\nexport function ownScreenSlugFromRoutePath(\n path: string | null | undefined,\n): string | undefined {\n if (!path) return undefined\n if (path === SCREEN_ROOT_PATH) return SCREEN_ROOT_PATH\n const segments = path.split('/').filter(Boolean)\n return segments[segments.length - 1]\n}\n\n/** What a screen is ACTUALLY served at, where that is not its own slug. */\nexport interface LinkableScreenRouteSources {\n /**\n * screen id → the routing-map path the screen really answers on, for\n * screens routed by something other than their own slug. Today that is a\n * content collection's LIST template: `/{collectionSlug}` renders it\n * (`composeCollectionTemplatePage`), whatever slug it was published under.\n * Applied LAST, so it also un-drops a screen named in `unrouted`.\n */\n routedElsewhere?: Record<string, string> | null | undefined\n /**\n * Screen ids that serve NO address of their own — a collection ENTRY\n * template (AGL-1267), commerce's PDP/catalog templates (AGL-1270), a\n * screen that says `kind: 'template'` (AGL-1400). The tenant router drops\n * these before matching, so their routing-map path is a 404.\n */\n unrouted?: Iterable<string> | null | undefined\n /**\n * collection id → collection slug, for every CONTENT collection with a slug\n * (AGL-2799): the collections whose listing `/{collectionSlug}` serves. Each\n * becomes a link target of its own, keyed by `formatCollectionLinkValue`,\n * so a link can name a blog's listing whether or not a list template screen\n * renders it.\n */\n collectionListings?: Record<string, string> | null | undefined\n /**\n * entry key (`entry:<collectionId>/<entryId>`) → the entry's path, for the\n * entries a page references (AGL-3118). Unlike every other source, this one\n * is not the whole site: a renderer reads only the entries its own links\n * name, so an entry key missing here means \"not asked for\", and\n * `screenRoutesAnswerFor` judges entry links only against a map that has\n * some.\n */\n entryRoutes?: Record<string, string> | null | undefined\n}\n\n/**\n * Where a collection's RSS feed is served, in the routing map's own format\n * (no leading slash): `blog/rss.xml` for the collection at `/blog`.\n */\nexport function collectionFeedRoutePath(collectionSlug: string): string {\n const listing = collectionListUrl({ collectionSlug }).replace(/^\\/+|\\/+$/g, '')\n return `${listing}/rss.xml`\n}\n\n/**\n * Where a collection ENTRY is served, in the routing map's own format (no\n * leading slash): `blog/hello` for the entry slugged `hello` in the\n * collection at `/blog` — the `/{collection}/{entry}` shape\n * `parseCollectionRoute` reads back.\n */\nexport function collectionEntryRoutePath(\n collectionSlug: string,\n entrySlug: string,\n): string {\n const listing = collectionListUrl({ collectionSlug }).replace(/^\\/+|\\/+$/g, '')\n return `${listing}/${entrySlug.trim().replace(/^\\/+|\\/+$/g, '')}`\n}\n\n/**\n * The routing map as a LINK TARGET table (AGL-1998).\n *\n * The host's `screens` map is written by publishing, one entry per screen\n * under its own composed slug, and the tenant router then edits it at serve\n * time: template screens are dropped (see {@link LinkableScreenRouteSources})\n * and a collection's list template is reached at `/{collectionSlug}` instead.\n * Everything that RESOLVES a screen link — `resolveScreenHref` on the live\n * site, the besigner's screen picker, every `Link`-typed component prop — was\n * reading the raw map, so the two surfaces disagreed with the router in both\n * directions at once:\n *\n * - `/blog` was UNOFFERABLE. The blog's list template is published under\n * `blog-list-template` and serves `/blog`, so no screen link on aglyn.com\n * could point at the site's own blog index.\n * - Every template screen was offered at a path that 404s, and an author who\n * picked one got a dead anchor that looks exactly like a live one.\n *\n * So the map every linking surface reads is derived here, from the same two\n * facts the router uses, and the picker can no longer offer a path the router\n * would refuse.\n *\n * A content collection's LISTING is a target in its own right (AGL-2799),\n * keyed `collection:<collectionId>` beside the screen ids. Its path comes from\n * `collectionListUrl`, the builder the pager, the canonical link and the\n * sitemap already share, so a link cannot give a listing an address the rest\n * of the site does not; and because the key is the collection's id rather than\n * its slug, renaming the slug moves every link to it on the next render. A\n * collection that is gone, or that has lost its slug, has no entry — the same\n * absence `isScreenLinkBroken` reads as a dead target.\n *\n * A raw map with no source given comes back unchanged; an absent map with no\n * overrides and no listings stays absent, because `undefined` means \"nothing\n * resolves yet\" to {@link ScreenLinkContext} and `{}` would mean \"resolved:\n * nowhere\".\n */\nexport function linkableScreenRoutes(\n screens: Record<ScreenUid, string> | null | undefined,\n sources: LinkableScreenRouteSources = {},\n): Record<ScreenUid, string> | undefined {\n const { routedElsewhere, unrouted, collectionListings, entryRoutes } = sources\n const overrides = Object.entries(routedElsewhere ?? {})\n const listings = Object.entries(collectionListings ?? {})\n const entries = Object.entries(entryRoutes ?? {})\n if (!screens && !overrides.length && !listings.length && !entries.length) {\n return undefined\n }\n const next: Record<ScreenUid, string> = { ...(screens ?? {}) }\n for (const id of unrouted ?? []) delete next[id]\n for (const [collectionId, collectionSlug] of listings) {\n const slug =\n typeof collectionSlug === 'string'\n ? collectionSlug.trim().replace(/^\\/+|\\/+$/g, '')\n : ''\n if (!collectionId.trim() || !slug) continue\n // Built by the one listing-URL builder, then stored in the map's own\n // format: no leading slash, which `resolveScreenHref` puts back.\n next[formatCollectionLinkValue(collectionId)] = collectionListUrl({\n collectionSlug: slug,\n }).replace(/^\\/+/, '')\n // The feed hangs off the same listing (AGL-3118), so it follows the same\n // rename and disappears with the same collection.\n next[formatFeedLinkValue(collectionId)] = collectionFeedRoutePath(slug)\n }\n for (const [key, path] of entries) {\n // Only well-formed entry keys, stored under their canonical spelling: this\n // source must not be able to plant a screen id or a listing key the other\n // sources own.\n const entry = parseEntryLinkValue(key)\n if (!entry) continue\n const normalized =\n typeof path === 'string' ? path.trim().replace(/^\\/+|\\/+$/g, '') : ''\n if (!normalized) continue\n next[formatEntryLinkValue(entry.collectionId, entry.entryId)] = normalized\n }\n for (const [id, path] of overrides) {\n // A collection slug (`blog`) arrives in the map's own format already, but\n // the same fact is spelled `/blog` in half the places it is read from, and\n // a stored `/blog` would resolve to `//blog` — an absolute URL to the host\n // `blog`, i.e. off the site entirely.\n const normalized =\n typeof path === 'string' && path !== SCREEN_ROOT_PATH\n ? path.replace(/^\\/+|\\/+$/g, '')\n : path\n if (!normalized) continue\n next[id] = normalized\n }\n return next\n}\n\nexport { SCREEN_KIND_EMAIL } from './screen-kind'\n\n/**\n * `kind` of a collection ENTRY template (AGL-1400): a screen that composes\n * `/{collection}/{entry}` for every entry and has no address of its own.\n *\n * The value exists so that \"is this screen a page?\" stops being a JOIN.\n * Four issues (AGL-1173, AGL-1383, AGL-1387, AGL-1390) were the same sentence\n * at different depths because the answer was derived from a mutable field on a\n * DIFFERENT document — a collection's `entryScreenId` — and every new way to\n * edit that pointer was a new bypass of `screensPerHost`. Here the fact is a\n * property of the screen, server-stamped by /api/hosts/screens and frozen in\n * the rules exactly as `kind: 'email'` has been since AGL-1383.\n *\n * NOT a collection's LIST template. `/{collectionSlug}` renders that exact\n * screen with its entries, so it is a designed reachable page and AGL-1387\n * made it count; converting one would take the page off the site.\n */\nexport const SCREEN_KIND_TEMPLATE = 'template'\n\n/**\n * `kind` of a designed ERROR screen (AGL-2092): the screen a host assigns to\n * one of `errorScreens`' four status slots, rendered on paths that did not\n * match — and so, like an entry template, at no address of its own.\n *\n * the decision on 2026-08-18 was that these must not spend the plan's screen\n * allowance, for the reason AGL-1173 excluded an entry template: the governing\n * question is whether the screen occupies a URL of its own, and a 404 body does\n * not. (A collection's LIST template does — `/{collectionSlug}` renders that\n * exact screen — which is why AGL-1387 left it counting.)\n *\n * ## This value does NOT get `kind: 'template'`'s trust\n *\n * `billableScreenIds` short-circuits on `SCREEN_KIND_TEMPLATE` BEFORE it\n * consults the routing map, because a template is routed on purpose. An error\n * screen is not, so it deliberately falls through to the ordinary rule and\n * **the routing map outranks this field**: a screen still published at an\n * address of its own counts, whatever it says about itself. That is the whole\n * migration story for the error screens that already exist — see\n * {@link ERROR_SCREEN_MAX_PER_HOST}.\n *\n * Stamped only by /api/hosts/screens, as part of binding the screen to a slot,\n * and frozen against the client by the same rule that has frozen `kind` since\n * AGL-1383. Nothing about that is new for this value; what IS new is that the\n * stamp is BOUNDED, because unlike a template there is no natural limit on how\n * many screens somebody would like to declare as error pages.\n */\nexport const SCREEN_KIND_ERROR = 'error'\n\n/**\n * How many screens one host may hold with `kind: 'error'` (AGL-2092).\n *\n * An exclusion the metered party can ask for is a free-screen generator unless\n * something bounds it, and the four bindings in `HostErrorScreens` are the\n * bound: at most one exempt screen per error slot. It is `.length` of the slot\n * list rather than a literal `4` so the two can never disagree.\n *\n * Checked in TWO places, and the second is the one that makes the number true\n * (AGL-2093). At the moment of the STAMP, against the post-state — the\n * AGL-1390 shape, which produces the refusal worth reading because it can name\n * the four slots. And inside `billableScreenIds` itself, where a live error\n * screen past this bound is counted as an ordinary page: the stamp is not the\n * only writer, and a crafted import bundle carrying `kind: 'error'` on all 200\n * of its screens passed no bound at all until the rule owned one. An exclusion\n * enforced only at the write paths somebody remembered is the sentence this arc\n * has now repeated six times.\n *\n * The tempting alternative is to enforce \"bound to a slot\" as an\n * invariant, promoting a screen back to a page whenever its slot is cleared;\n * that is AGL-1390's refuse-the-clear bug wearing a different hat, because\n * promotion raises the count and a host at its cap could then never unassign an\n * error screen. So clearing a slot is always allowed and leaves the screen an\n * error screen — unbilled, unrouted, and one deliberate click from being a page\n * again — and what is bounded is how many of them can exist at once.\n */\nexport const ERROR_SCREEN_MAX_PER_HOST = HOST_ERROR_SCREEN_SLOTS.length\n\n/** The two self-describing fields {@link screenClaimsToBeAPage} reads. */\nexport interface ScreenPageClaim {\n kind?: string\n deletedAt?: unknown\n}\n\n/**\n * Whether a screen document claims to be a page of the site at all (AGL-1383).\n *\n * Four things say it is not: `deletedAt` (soft-deleted — delete stamps the\n * field rather than removing the doc), `kind: 'email'` (an Emails-page\n * document, which has no URL and is rendered only by the campaign sender,\n * straight off the doc), `kind: 'template'` (a collection entry template,\n * which composes `/{collection}/{entry}` and has no address of its own —\n * AGL-1400), `kind: 'error'` (a screen assigned to one of the host's four\n * error slots, rendered on paths that matched nothing — AGL-2092) and\n * `kind: 'group'` (a folder of pages with no address, slug or content of its\n * own — AGL-3463). All five are also the exclusions `countBillableScreens`\n * subtracts before enforcing `screensPerHost`, and since AGL-1400 they are the\n * WHOLE of that subtraction: the count reads no other collection.\n *\n * Adding the fourth and fifth needed no edit to `billableScreenIds` and no edit to\n * `nonPageScreenIds`, which is the property AGL-1439 wrote them for: the\n * routing-map override applies to a new non-page `kind` by default, and the\n * flat infrastructure cap is the complement, so there is no second list to\n * remember. Only `kind: 'template'` is named anywhere else, because only it\n * opts OUT of the routing-map override.\n *\n * That is exactly why this is ONE function with TWO callers rather than two\n * matching filters. Both fields are ordinary client-writable fields on\n * `hosts/{hostId}/screens/{screenId}`, and until AGL-1383 only the count read\n * them: an editor on a Free site could `updateDoc(screenRef, {kind: 'email'})`\n * and the screen stopped counting against the plan while the routing map still\n * pointed at it and the runtime still served it — a live page, for free. An\n * exclusion is only sound if an excluded screen genuinely is not a page, so the\n * serve path asks this question too, and flipping either field now costs the\n * page instead of the plan.\n *\n * A CLAIM, not the answer, for the two fields a client can still reach: the\n * routing map decides reachability, and `countBillableScreens` trusts\n * `deletedAt` / `kind: 'email'` only for screens the map does not route.\n * `kind: 'error'` is in the client-can-still-reach group for counting purposes\n * even though no client writes it either: an error screen that is ALSO\n * published at an address is a page somebody is using as a page, so the map\n * outranks the stamp and it counts. Serving is the other way round — see\n * `getScreen`, which returns error screens rather than 404ing them, because\n * refusing would break the customer's own designed error page without closing\n * anything (they are already paying for it if it is routed).\n *\n * `kind: 'template'` is the exception, and the reason it can be one is that no\n * client writes it — /api/hosts/screens stamps it, demotion lowers the count\n * and promotion is checked exactly like a create, so there is no toggle to\n * launder. A template is ROUTED on purpose (publishing is how the compose\n * pipeline picks it up), which is why the map cannot be the arbiter for it.\n */\nexport function screenClaimsToBeAPage(\n screen: ScreenPageClaim | null | undefined,\n): boolean {\n if (!screen) return false\n return (\n screen.deletedAt == null &&\n screen.kind !== SCREEN_KIND_EMAIL &&\n screen.kind !== SCREEN_KIND_TEMPLATE &&\n screen.kind !== SCREEN_KIND_ERROR &&\n screen.kind !== SCREEN_KIND_GROUP\n )\n}\n\n/**\n * One screen, reduced to the two things {@link billableScreenIds} asks about.\n *\n * Rows rather than a query (AGL-1390) because the enforcement points ask about\n * a state that does not exist yet: a promotion is checked against the count it\n * WOULD leave behind. A function that does its own reads can only answer for\n * the present. `readScreenSources` in /api/hosts/resources is the reader.\n */\nexport interface BillableScreenSource {\n id: string\n kind?: unknown\n deletedAt?: unknown\n}\n\n/**\n * A host's `screens` routing map (screen id → route path) as\n * `publishScreenRoute` writes it. Only membership is read, never the path.\n */\nexport type ScreenRoutingMap = Record<string, unknown> | null | undefined\n\n/**\n * WHICH screens spend the plan's screen allowance (AGL-1173).\n *\n * The ids rather than the count, because an enforcement point that cannot name\n * the screen it is refusing over is a refusal the person reading it cannot act\n * on.\n *\n * A plain `screens.count()` charged for three things the subscriber never\n * chose to author, and the screens list — which filters them out — then\n * disagreed with the server about how much of the plan was used:\n *\n * - **Soft-deleted screens.** Delete stamps `deletedAt` rather than\n * removing the doc, so deleting a screen never freed a slot. On the free\n * plan (5 screens) that was a dead end with no way out from the UI.\n * - **Email screens** (`kind: 'email'`), which live on the Emails page and\n * were already excluded from the list count but not from enforcement.\n * - **A collection's ENTRY template** — one screen serving every entry at no\n * URL of its own. Adding a blog cost two of the free plan's five screens\n * before the first page existed.\n *\n * ## Why it lives HERE, next to the predicate (AGL-2093)\n *\n * It was in /api/hosts/resources, and the console's Screens page — which runs\n * the same rule as a precheck before it lets somebody add a page — could not\n * import it from there (that module reaches `@aglyn/aglyn/server`, which pulls\n * `node:stream` in through the API adapter). So the page restated it, and the\n * restatement drifted: it never learned the error-screen bound below, and on a\n * host holding five `kind: 'error'` screens the console offered room the API\n * then refused. A precheck that warns on a different number than the API\n * enforces is worse than no precheck at all, and a rule that has to be\n * restated to be reused will be restated wrongly eventually. One function, two\n * callers.\n *\n * ## ONE document answers it now (AGL-1400)\n *\n * The third exclusion used to be a JOIN: the count read the `collections`\n * collection and subtracted whatever screen ids the template pointers named.\n * That shape produced four issues in one arc, because the other side of the\n * join is editable and each new way to edit it was a new bypass — AGL-1173\n * created the exclusion, AGL-1383 froze the two fields the screen itself\n * carried, AGL-1387 found the list template was a page after all, and AGL-1390\n * found the pointer could be toggled to mint permanent slots and had to move\n * the write server-side and evaluate the cap against the post-state.\n *\n * Since AGL-1400 an entry template says so on its own document\n * (`kind: 'template'`), stamped by /api/hosts/screens and frozen in the rules\n * exactly as `kind: 'email'` is. So this reads the `screens` collection and\n * nothing else: the pointer is a pointer again, freely writable, and it excuses\n * nothing. `screenClaimsToBeAPage` is the whole rule, which is the property\n * that keeps the count and the serve path (`getScreen`) from ever disagreeing.\n *\n * What did NOT change is what anybody pays. A collection's LIST template stays\n * a page — `/{collectionSlug}` renders that exact screen (AGL-1387) — so it is\n * never stamped and still counts, and an entry template stays excluded\n * (AGL-1173's charge is not reinstated).\n *\n * ## The routing map outranks the document, and ONLY ADDS (AGL-1383, AGL-1445)\n *\n * `deletedAt` and `kind: 'email'` are ordinary client-writable fields on the\n * screen's OWN document, and the party they are subtracted on behalf of is the\n * party being metered. `updateDoc(screenRef, {kind: 'email'})` — one write, no\n * route change — used to take a live page off a Free plan's five and leave it\n * serving, because nothing else read either field. So for those two the\n * document's account of itself is consulted only for screens the routing map\n * does not route: **a routed screen counts, whatever it says about itself**.\n *\n * The converse is NOT true and must not become true, which is AGL-1445's\n * settlement. An unrouted screen with no slug — a draft, or an orphan left\n * behind by an unpublish — serves nothing, and it still counts:\n *\n * - `screensPerHost` is a CREATE-TIME gate. /api/hosts/resources counts and\n * refuses; `report-usage` re-measures monthly but RECORDS rather than\n * enforces. The create is the only door.\n * - A screen is born unrouted, and publishing is a separate later act — a\n * client `updateDoc` on the host's `screens` map (`publishScreenRoute`),\n * gated on `canPublishHostContent` and on nothing else.\n *\n * So subtracting unrouted screens would not make the count fairer, it would\n * make every create free — the new document is unrouted by construction — and\n * leave the publishes that follow ungated. A Free site would hold unlimited\n * pages. AGL-1445's option 2 (server-stamping a non-page `kind` on orphans by\n * a sweep) lands in the same place unless the promotion BACK passes a gate,\n * and for an orphan the promotion is the publish. `kind: 'template'` can be\n * trusted precisely because its promotion is `convertScreenKind`, checked\n * exactly like a create; there is no equivalent door in front of the routing\n * map. The price is one slot until somebody deletes the orphan, which is one\n * click and which the Screens page lists like any other row —\n * `unrouted-screen-counts.spec.ts` pins it at the enforcement point.\n *\n * `kind: 'template'` is deliberately outside the map's override, and it is the\n * one value that can be. A template is routed ON PURPOSE — publishing is how\n * the compose pipeline picks it up, and AGL-1267 drops it from routing when the\n * request arrives — so the map cannot be the arbiter for it. What makes\n * trusting it safe is that no client writes it: the demotion that sets it\n * always succeeds (it lowers the count) and the promotion that clears it is\n * checked exactly like a create (it raises it), so there is no toggle to run a\n * loop through.\n */\nexport function billableScreenIds(\n screens: ReadonlyArray<BillableScreenSource>,\n routingMap?: ScreenRoutingMap,\n): Set<string> {\n const routed = new Set(Object.keys(routingMap ?? {}))\n const exemptErrors = exemptErrorScreenIds(screens)\n const billable = new Set<string>()\n for (const screen of screens) {\n if (screen.kind === SCREEN_KIND_TEMPLATE) continue\n const claimsToBeAPage = screenClaimsToBeAPage({\n kind: screen.kind as string,\n deletedAt: screen.deletedAt,\n })\n // A `kind: 'error'` screen OVER the slot bound is a page again (AGL-2093).\n const exemptionSpent =\n screen.kind === SCREEN_KIND_ERROR &&\n screen.deletedAt == null &&\n !exemptErrors.has(screen.id)\n if (routed.has(screen.id) || claimsToBeAPage || exemptionSpent) {\n billable.add(screen.id)\n }\n }\n return billable\n}\n\n/**\n * The live `kind: 'error'` screens whose billing exemption actually HOLDS —\n * at most {@link ERROR_SCREEN_MAX_PER_HOST} of them (AGL-2093).\n *\n * ## Why the bound lives here and not at one endpoint\n *\n * AGL-2092 introduced the exemption and bounded it at four — one per\n * `HostErrorScreens` slot — by checking the post-state at the moment\n * /api/hosts/screens STAMPS the kind. That made the claim true of the assign\n * route and false end to end, because the stamp is not the only writer:\n * `SITE_EXPORT_FIELDS.screens` carries `kind`, so a hand-edited bundle could\n * declare `kind: 'error'` on all 200 of its screens and /api/hosts/import\n * excluded every one of them from `screensPerHost` — never passing the bound,\n * never binding a slot. N unbilled screens, one file.\n *\n * That is the arc's fifth repetition of one sentence (AGL-1173, AGL-1383,\n * AGL-1387, AGL-1390, AGL-1400): *an exclusion enforced at a write path is\n * enforced only at the write paths somebody remembered.* So the bound moves\n * into the rule the enforcement points SHARE. However a screen came to say\n * `kind: 'error'` — assign, import, or the next writer — a host gets four\n * unbilled ones and the rest spend the plan's allowance exactly as pages do.\n *\n * ## Which four\n *\n * The lowest ids, sorted. The choice is arbitrary and the DETERMINISM is not:\n * every enforcement point models a post-state by re-running this over a\n * different row set, and a rule that picked \"the first four encountered\" would\n * hand two callers different answers for the same host. The SIZE of the exempt\n * set never depends on the order — it is `min(live errors, 4)` — so only which\n * ids a refusal message names can move, never whether one is refused.\n *\n * Tombstones are excluded for `nonPageScreenIds`' reason: a cap counting\n * soft-deleted rows is AGL-1173's bug one cap over, where deleting an error\n * screen never frees its slot.\n *\n * The stamp-time bound in /api/hosts/screens is deliberately KEPT. It is the\n * better refusal — it names the four slots and arrives before the write — and\n * this is the backstop under it, so no writer can mint a fifth unbilled error\n * screen even by a path that never consults it.\n */\nexport function exemptErrorScreenIds(\n screens: ReadonlyArray<BillableScreenSource>,\n): Set<string> {\n const live: Array<string> = []\n for (const screen of screens) {\n if (screen.kind !== SCREEN_KIND_ERROR) continue\n if (screen.deletedAt != null) continue\n live.push(screen.id)\n }\n if (live.length <= ERROR_SCREEN_MAX_PER_HOST) return new Set(live)\n return new Set(live.sort().slice(0, ERROR_SCREEN_MAX_PER_HOST))\n}\n\n/**\n * The screens the flat platform cap bounds (AGL-1399, AGL-1439): LIVE documents\n * that are not billable pages — the exact complement of {@link billableScreenIds}.\n *\n * ## Why the complement, and not `kind === 'email' || kind === 'template'`\n *\n * Both issues are one sentence — *a `kind` value that excludes a document from\n * billing, declarable by the metered party* — and a cap that enumerated the two\n * values would be correct until the third arrived, which is how this arc has\n * already gone four times (AGL-1173, AGL-1383, AGL-1387, AGL-1390). Written as\n * the complement, a new non-page `kind` is bounded by the act of adding it to\n * `screenClaimsToBeAPage`: there is no second list to remember.\n *\n * Two properties fall out of taking the complement rather than negating the\n * predicate directly:\n *\n * - **A soft-deleted screen is in NEITHER set.** Delete stamps `deletedAt`\n * rather than removing the doc, and a cap that counted tombstones would be\n * the AGL-1173 bug one cap over — deleting an email document would never free\n * a slot, and a host at the cap could never author another.\n * - **A ROUTED email document counts once, against the plan.** The routing map\n * outranks the document (AGL-1383), so such a screen is a page somebody is\n * already paying for; charging it to the infrastructure cap as well would be\n * counting one document twice. The two sets partition the live screens.\n *\n * Taking the complement is also what makes AGL-2093's bound arrive here for\n * free: an error screen past `ERROR_SCREEN_MAX_PER_HOST` becomes billable\n * above, so it leaves this set in the same act. The partition holds — every\n * live screen is in exactly one of the two — and the fifth error screen is\n * bounded by the PLAN rather than by the flat 5,000, which is the stronger of\n * the two numbers on every finite tier.\n */\nexport function nonPageScreenIds(\n screens: ReadonlyArray<BillableScreenSource>,\n routingMap?: ScreenRoutingMap,\n): Set<string> {\n const billable = billableScreenIds(screens, routingMap)\n const nonPage = new Set<string>()\n for (const screen of screens) {\n if (screen.deletedAt != null) continue\n if (!billable.has(screen.id)) nonPage.add(screen.id)\n }\n return nonPage\n}\n\n/**\n * How many LIVE screen documents a host may hold that are NOT billable pages —\n * email documents, entry templates, and whatever non-page `kind` comes next\n * (AGL-1399, AGL-1439).\n *\n * ## Why a flat number and not a plan dimension\n *\n * Every exclusion `screenClaimsToBeAPage` names is declared by the party being\n * metered: `kind: 'email'` is on the create allow-list because the email\n * composer must send it, and AGL-1400 gave `kind: 'template'` the same\n * billing-excluding meaning. So `POST /api/hosts/resources` with\n * `kind: 'email'` created a document that no cap counted, without limit, on a\n * free plan — unbounded Firestore documents rather than a bypass of anything we\n * sell. AGL-1439 is the same sentence one value over, and a cap enumerating the\n * two values would leave the hole open for the third.\n *\n * The shape is `WEBHOOK_MAX_PER_HOST`'s (AGL-1360): no `OrgEntitlements` key, no\n * variation by plan, counted from a server read at the create path. An\n * `emailDocumentsPerHost` would have been a **pricing** decision — a number the\n * price list has to explain and support has to defend — for a limit whose only\n * job is to bound infrastructure. This is not the charge AGL-1173 removed and it\n * does not reinstate it: nothing here is billable, and `screensPerHost` counts\n * exactly what it counted yesterday.\n *\n * ## Why 5,000\n *\n * Sized to the heaviest library anybody could plausibly author, not to what\n * exists: production's busiest host holds FOUR non-page screens (one email,\n * three entry templates) across five hosts, so any bar sized to today's data\n * would be meaningless. The real quantity is campaigns, which accumulate and are\n * never deleted — a DAILY newsletter reaches 5,000 after thirteen years, and a\n * thrice-weekly one after thirty-two. Entry templates contribute one per\n * collection, so tens at the outside. Nothing a real customer does approaches\n * this, which is the property that matters: the failure mode of a too-low flat\n * cap is blocking legitimate work with an error the price list cannot explain.\n *\n * A cheaper bound is not worth much either. What the number defends against is a\n * script in a loop, and a loop stopped at 5,000 documents is stopped. It also\n * bounds the cost of the count itself — `countBillableScreens` scans the screens\n * collection on every create at one billed read per document (AGL-1440), and\n * before this cap that scan had no ceiling at all.\n */\nexport const NON_PAGE_SCREEN_MAX_PER_HOST = 5000\n"],"names":["HOST_ERROR_SCREEN_SLOTS","collectionListUrl","ENTRY_PREVIEW_ROUTE_SEGMENT","LEAVING_NOTICE_ROUTE_SEGMENT","PLATFORM_BRAND_NAME","SCREEN_KIND_EMAIL","formatCollectionLinkValue","formatEntryLinkValue","formatFeedLinkValue","parseEntryLinkValue","SCREEN_ROOT_PATH","normalizeScreenSlug","input","trimmed","trim","undefined","segment","toLowerCase","replace","RESERVED_SCREEN_ROUTE_SEGMENTS","reservedScreenRouteSegment","path","first","split","includes","reservedScreenRouteMessage","screenSlugHasPathSeparator","SCREEN_SLUG_PATH_SEPARATOR_MESSAGE","SCREEN_KIND_GROUP","toScreenRouteNode","screen","node","slug","parentId","kind","isScreenGroup","MAX_SCREEN_DEPTH","composeScreenRoutePath","screenId","screensById","segments","visited","Set","currentId","isHomePage","has","size","add","unshift","length","join","screenRouteParentId","screenGroupDissolveMoves","groupId","group","nextParentId","moves","id","Object","entries","collectScreenDescendantIds","childrenByParent","Map","siblings","get","push","set","result","queue","shift","wouldCreateScreenCycle","buildScreenRouteEntries","routingMap","options","publish","currentById","routedPath","ownPath","live","liveScreenDescendants","sort","a","b","findScreenIdByRoutePath","screens","entry","find","value","blockingRouteOwner","defaultHomeScreenId","owner","screenRoutePathToUrl","screenRoutePathFromUrl","urlPath","raw","String","startsWith","bare","ownScreenSlugFromRoutePath","filter","Boolean","collectionFeedRoutePath","collectionSlug","listing","collectionEntryRoutePath","entrySlug","linkableScreenRoutes","sources","routedElsewhere","unrouted","collectionListings","entryRoutes","overrides","listings","next","collectionId","key","normalized","entryId","SCREEN_KIND_TEMPLATE","SCREEN_KIND_ERROR","ERROR_SCREEN_MAX_PER_HOST","screenClaimsToBeAPage","deletedAt","billableScreenIds","routed","keys","exemptErrors","exemptErrorScreenIds","billable","claimsToBeAPage","exemptionSpent","slice","nonPageScreenIds","nonPage","NON_PAGE_SCREEN_MAX_PER_HOST"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,uBAAuB,QAAwB,yBAAe;AACvE,SAASC,iBAAiB,QAAQ,0BAAsB;AACxD,SAASC,2BAA2B,QAAQ,0BAAsB;AAClE,SAASC,4BAA4B,QAAQ,sBAAkB;AAC/D,SAASC,mBAAmB,QAAQ,sBAAkB;AACtD,SAASC,iBAAiB,QAAQ,mBAAe;AACjD,SACEC,yBAAyB,EACzBC,oBAAoB,EACpBC,mBAAmB,EACnBC,mBAAmB,QACd,yBAAqB;AAE5B;;;;;;CAMC,GACD,OAAO,MAAMC,mBAAmB,IAAG;AAEnC;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASC,oBACdC,KAAgC;IAEhC,MAAMC,UAAU,CAACD,gBAAAA,QAAS,IAAIE,IAAI;IAClC,IAAI,CAACD,SAAS,OAAOE;IACrB,IAAIF,YAAYH,kBAAkB,OAAOA;IAEzC,MAAMM,UAAUH,QACbI,WAAW,GACXC,OAAO,CAAC,cAAc,IACtBA,OAAO,CAAC,QAAQ,KAChBA,OAAO,CAAC,gBAAgB,IACxBA,OAAO,CAAC,UAAU,KAClBA,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,MAAMC,+BAA+B,KAAI"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * What a step can be — only what the platform already sees happen.
19
+ *
20
+ * - `page`: a page was viewed; key = the path.
21
+ * - `form`: a form was submitted successfully; key = the form id.
22
+ * - `booking`: a booking was made (a free one confirmed, or a paid one's
23
+ * payment settled); key = the service id.
24
+ * - `cart`: a product was added to the cart; key = the product id.
25
+ * - `order`: a storefront order was placed and paid; no key.
26
+ * - `overlay`: an announcement bar or popup was clicked; key = the overlay id.
27
+ * - `event`: a custom event an interaction fired; key = the event name.
28
+ * - `email`: a person the visit identified opened or clicked an email the
29
+ * site sent them; key = `opened` or `clicked`. Recorded by the SERVER from
30
+ * the delivery log, never by a page: a browser that sends one is refused.
31
+ */
32
+ export declare const SITE_JOURNEY_STEP_TYPES: readonly ["page", "form", "booking", "cart", "order", "overlay", "event", "email"];
33
+ export type SiteJourneyStepType = (typeof SITE_JOURNEY_STEP_TYPES)[number];
34
+ export declare function isSiteJourneyStepType(value: unknown): value is SiteJourneyStepType;
35
+ /** The keys an `email` step carries. */
36
+ export declare const SITE_JOURNEY_EMAIL_KEYS: readonly ["opened", "clicked"];
37
+ /** The longest key a step carries; longer keys are cut. */
38
+ export declare const SITE_JOURNEY_KEY_MAX = 200;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Aglyn LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */ /*
17
+ * A visit's step vocabulary (AGL-3605), as a leaf: what a journey step may
18
+ * be and carry. `site-journey.ts` re-exports it beside the recorder; the
19
+ * funnels' model reads it from here, so the model stays free of the
20
+ * beacon (and the DOM it reaches) and can be read by the native apps.
21
+ */ /**
22
+ * What a step can be — only what the platform already sees happen.
23
+ *
24
+ * - `page`: a page was viewed; key = the path.
25
+ * - `form`: a form was submitted successfully; key = the form id.
26
+ * - `booking`: a booking was made (a free one confirmed, or a paid one's
27
+ * payment settled); key = the service id.
28
+ * - `cart`: a product was added to the cart; key = the product id.
29
+ * - `order`: a storefront order was placed and paid; no key.
30
+ * - `overlay`: an announcement bar or popup was clicked; key = the overlay id.
31
+ * - `event`: a custom event an interaction fired; key = the event name.
32
+ * - `email`: a person the visit identified opened or clicked an email the
33
+ * site sent them; key = `opened` or `clicked`. Recorded by the SERVER from
34
+ * the delivery log, never by a page: a browser that sends one is refused.
35
+ */ export const SITE_JOURNEY_STEP_TYPES = [
36
+ 'page',
37
+ 'form',
38
+ 'booking',
39
+ 'cart',
40
+ 'order',
41
+ 'overlay',
42
+ 'event',
43
+ 'email'
44
+ ];
45
+ export function isSiteJourneyStepType(value) {
46
+ return typeof value === 'string' && SITE_JOURNEY_STEP_TYPES.includes(value);
47
+ }
48
+ /** The keys an `email` step carries. */ export const SITE_JOURNEY_EMAIL_KEYS = [
49
+ 'opened',
50
+ 'clicked'
51
+ ];
52
+ /** The longest key a step carries; longer keys are cut. */ export const SITE_JOURNEY_KEY_MAX = 200;
53
+
54
+ //# sourceMappingURL=site-journey-steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/site-journey-steps.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * A visit's step vocabulary (AGL-3605), as a leaf: what a journey step may\n * be and carry. `site-journey.ts` re-exports it beside the recorder; the\n * funnels' model reads it from here, so the model stays free of the\n * beacon (and the DOM it reaches) and can be read by the native apps.\n */\n\n/**\n * What a step can be — only what the platform already sees happen.\n *\n * - `page`: a page was viewed; key = the path.\n * - `form`: a form was submitted successfully; key = the form id.\n * - `booking`: a booking was made (a free one confirmed, or a paid one's\n * payment settled); key = the service id.\n * - `cart`: a product was added to the cart; key = the product id.\n * - `order`: a storefront order was placed and paid; no key.\n * - `overlay`: an announcement bar or popup was clicked; key = the overlay id.\n * - `event`: a custom event an interaction fired; key = the event name.\n * - `email`: a person the visit identified opened or clicked an email the\n * site sent them; key = `opened` or `clicked`. Recorded by the SERVER from\n * the delivery log, never by a page: a browser that sends one is refused.\n */\nexport const SITE_JOURNEY_STEP_TYPES = [\n 'page',\n 'form',\n 'booking',\n 'cart',\n 'order',\n 'overlay',\n 'event',\n 'email',\n] as const\n\nexport type SiteJourneyStepType = (typeof SITE_JOURNEY_STEP_TYPES)[number]\n\nexport function isSiteJourneyStepType(value: unknown): value is SiteJourneyStepType {\n return (\n typeof value === 'string' &&\n (SITE_JOURNEY_STEP_TYPES as readonly string[]).includes(value)\n )\n}\n\n/** The keys an `email` step carries. */\nexport const SITE_JOURNEY_EMAIL_KEYS = ['opened', 'clicked'] as const\n\n/** The longest key a step carries; longer keys are cut. */\nexport const SITE_JOURNEY_KEY_MAX = 200\n"],"names":["SITE_JOURNEY_STEP_TYPES","isSiteJourneyStepType","value","includes","SITE_JOURNEY_EMAIL_KEYS","SITE_JOURNEY_KEY_MAX"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;CAKC,GAED;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMA,0BAA0B;IACrC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAS;AAIV,OAAO,SAASC,sBAAsBC,KAAc;IAClD,OACE,OAAOA,UAAU,YACjB,AAACF,wBAA8CG,QAAQ,CAACD;AAE5D;AAEA,sCAAsC,GACtC,OAAO,MAAME,0BAA0B;IAAC;IAAU;CAAU,CAAS;AAErE,yDAAyD,GACzD,OAAO,MAAMC,uBAAuB,IAAG"}
@@ -14,6 +14,8 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { type SiteJourneyStepType } from './site-journey-steps';
18
+ export { SITE_JOURNEY_EMAIL_KEYS, SITE_JOURNEY_KEY_MAX, SITE_JOURNEY_STEP_TYPES, type SiteJourneyStepType, isSiteJourneyStepType, } from './site-journey-steps';
17
19
  /**
18
20
  * A VISIT'S STEPS, IN ORDER (AGL-3605): the one per-visit record the site
19
21
  * collector keeps, so a funnel can ask "of the visits that did A, how many
@@ -63,28 +65,8 @@
63
65
  */
64
66
  /** The body field that marks a collector beacon as a journey step. */
65
67
  export declare const SITE_JOURNEY_BEACON_FIELD = "journey";
66
- /**
67
- * What a step can be — only what the platform already sees happen.
68
- *
69
- * - `page`: a page was viewed; key = the path.
70
- * - `form`: a form was submitted successfully; key = the form id.
71
- * - `booking`: a booking was made (a free one confirmed, or a paid one's
72
- * payment settled); key = the service id.
73
- * - `cart`: a product was added to the cart; key = the product id.
74
- * - `order`: a storefront order was placed and paid; no key.
75
- * - `overlay`: an announcement bar or popup was clicked; key = the overlay id.
76
- * - `event`: a custom event an interaction fired; key = the event name.
77
- * - `email`: a person the visit identified opened or clicked an email the
78
- * site sent them; key = `opened` or `clicked`. Recorded by the SERVER from
79
- * the delivery log, never by a page: a browser that sends one is refused.
80
- */
81
- export declare const SITE_JOURNEY_STEP_TYPES: readonly ["page", "form", "booking", "cart", "order", "overlay", "event", "email"];
82
- export type SiteJourneyStepType = (typeof SITE_JOURNEY_STEP_TYPES)[number];
83
- export declare function isSiteJourneyStepType(value: unknown): value is SiteJourneyStepType;
84
68
  /** The step types only the server records; a page's beacon naming one is refused. */
85
69
  export declare const SITE_JOURNEY_SERVER_STEP_TYPES: ReadonlySet<SiteJourneyStepType>;
86
- /** The keys an `email` step carries. */
87
- export declare const SITE_JOURNEY_EMAIL_KEYS: readonly ["opened", "clicked"];
88
70
  /**
89
71
  * The body field an identifying door (a form submission) carries the visit
90
72
  * id under, so the server can tie the visit to the person the door verified.
@@ -93,8 +75,6 @@ export declare const SITE_JOURNEY_EMAIL_KEYS: readonly ["opened", "clicked"];
93
75
  export declare const SITE_JOURNEY_SUBMISSION_FIELD = "journey";
94
76
  /** The most steps one visit records. A visit past it records nothing more. */
95
77
  export declare const SITE_JOURNEY_MAX_STEPS = 60;
96
- /** The longest key a step carries; longer keys are cut. */
97
- export declare const SITE_JOURNEY_KEY_MAX = 200;
98
78
  /** A visit id's shape: 22 URL-safe characters (128 random bits). */
99
79
  export declare const SITE_JOURNEY_ID_PATTERN: RegExp;
100
80
  /** Whether a host document asks for journeys to be recorded. */
@@ -15,6 +15,8 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
15
15
  * See the License for the specific language governing permissions and
16
16
  * limitations under the License.
17
17
  */ import { sendAnalyticsBeacon } from "./analytics-beacon.js";
18
+ import { SITE_JOURNEY_KEY_MAX, isSiteJourneyStepType } from "./site-journey-steps.js";
19
+ export { SITE_JOURNEY_EMAIL_KEYS, SITE_JOURNEY_KEY_MAX, SITE_JOURNEY_STEP_TYPES, isSiteJourneyStepType } from "./site-journey-steps.js";
18
20
  /**
19
21
  * A VISIT'S STEPS, IN ORDER (AGL-3605): the one per-visit record the site
20
22
  * collector keeps, so a funnel can ask "of the visits that did A, how many
@@ -62,47 +64,15 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
62
64
  * page's measurement mount imports it (the AGL-1550 independence rule), and
63
65
  * plugins report their steps here without knowing who counts them.
64
66
  */ /** The body field that marks a collector beacon as a journey step. */ export const SITE_JOURNEY_BEACON_FIELD = 'journey';
65
- /**
66
- * What a step can be — only what the platform already sees happen.
67
- *
68
- * - `page`: a page was viewed; key = the path.
69
- * - `form`: a form was submitted successfully; key = the form id.
70
- * - `booking`: a booking was made (a free one confirmed, or a paid one's
71
- * payment settled); key = the service id.
72
- * - `cart`: a product was added to the cart; key = the product id.
73
- * - `order`: a storefront order was placed and paid; no key.
74
- * - `overlay`: an announcement bar or popup was clicked; key = the overlay id.
75
- * - `event`: a custom event an interaction fired; key = the event name.
76
- * - `email`: a person the visit identified opened or clicked an email the
77
- * site sent them; key = `opened` or `clicked`. Recorded by the SERVER from
78
- * the delivery log, never by a page: a browser that sends one is refused.
79
- */ export const SITE_JOURNEY_STEP_TYPES = [
80
- 'page',
81
- 'form',
82
- 'booking',
83
- 'cart',
84
- 'order',
85
- 'overlay',
86
- 'event',
87
- 'email'
88
- ];
89
- export function isSiteJourneyStepType(value) {
90
- return typeof value === 'string' && SITE_JOURNEY_STEP_TYPES.includes(value);
91
- }
92
67
  /** The step types only the server records; a page's beacon naming one is refused. */ export const SITE_JOURNEY_SERVER_STEP_TYPES = new Set([
93
68
  'email'
94
69
  ]);
95
- /** The keys an `email` step carries. */ export const SITE_JOURNEY_EMAIL_KEYS = [
96
- 'opened',
97
- 'clicked'
98
- ];
99
70
  /**
100
71
  * The body field an identifying door (a form submission) carries the visit
101
72
  * id under, so the server can tie the visit to the person the door verified.
102
73
  * See {@link siteJourneyField}.
103
74
  */ export const SITE_JOURNEY_SUBMISSION_FIELD = 'journey';
104
75
  /** The most steps one visit records. A visit past it records nothing more. */ export const SITE_JOURNEY_MAX_STEPS = 60;
105
- /** The longest key a step carries; longer keys are cut. */ export const SITE_JOURNEY_KEY_MAX = 200;
106
76
  /** A visit id's shape: 22 URL-safe characters (128 random bits). */ export const SITE_JOURNEY_ID_PATTERN = /^[A-Za-z0-9_-]{22}$/;
107
77
  const STORAGE_KEY = 'aglyn-journey';
108
78
  /** Whether a host document asks for journeys to be recorded. */ export function hostRecordsJourneys(host) {