@aglyn/aglyn 1.0.0-beta.143 → 1.0.0-beta.145

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.
@@ -61,6 +61,16 @@ export declare function normalizeScreenSlug(input: string | null | undefined): s
61
61
  * app owns. `/search` matches `app/[host]/[scheme]/search`; the other three are the
62
62
  * middleware matcher's exclusions, so no host rewrite happens at all and
63
63
  * the path is parsed as `[host]` with an empty slug.
64
+ * - `aglyn-preview` — the same mechanism as `search`, one route over
65
+ * (AGL-3205). The live-site preview of an unpublished collection entry is
66
+ * a rewrite to `app/[host]/[scheme]/aglyn-preview/[...slug]`, because it
67
+ * must be a DIFFERENT Next route from the ISR-cached catch-all; a static
68
+ * folder wins over the optional catch-all beside it, so `/aglyn-preview/x`
69
+ * would reach the preview page and 404 rather than render a screen. The
70
+ * bare `/aglyn-preview` would in fact still serve — the preview route's
71
+ * catch-all is required, not optional — and it is reserved anyway for the
72
+ * reason given below about child paths: a child only exists when its
73
+ * parent is published, and this rule refuses the parent.
64
74
  *
65
75
  * NOT reserved, and deliberately so, because measuring found them fine:
66
76
  * `401`, `403`, `503` (`/401` returns 200 through the catch-all — two of the
@@ -16,6 +16,7 @@ import { _ as _extends } from "@swc/helpers/_/_extends";
16
16
  * limitations under the License.
17
17
  */ import { HOST_ERROR_SCREEN_SLOTS } from "../foundation/index.js";
18
18
  import { collectionListUrl } from "./collection-entries.js";
19
+ import { ENTRY_PREVIEW_ROUTE_SEGMENT } from "./entry-preview-link.js";
19
20
  import { PLATFORM_BRAND_NAME } from "./platform-brand.js";
20
21
  import { formatCollectionLinkValue, formatEntryLinkValue, formatFeedLinkValue, parseEntryLinkValue } from "./screen-link-value.js";
21
22
  /**
@@ -68,6 +69,16 @@ import { formatCollectionLinkValue, formatEntryLinkValue, formatFeedLinkValue, p
68
69
  * app owns. `/search` matches `app/[host]/[scheme]/search`; the other three are the
69
70
  * middleware matcher's exclusions, so no host rewrite happens at all and
70
71
  * the path is parsed as `[host]` with an empty slug.
72
+ * - `aglyn-preview` — the same mechanism as `search`, one route over
73
+ * (AGL-3205). The live-site preview of an unpublished collection entry is
74
+ * a rewrite to `app/[host]/[scheme]/aglyn-preview/[...slug]`, because it
75
+ * must be a DIFFERENT Next route from the ISR-cached catch-all; a static
76
+ * folder wins over the optional catch-all beside it, so `/aglyn-preview/x`
77
+ * would reach the preview page and 404 rather than render a screen. The
78
+ * bare `/aglyn-preview` would in fact still serve — the preview route's
79
+ * catch-all is required, not optional — and it is reserved anyway for the
80
+ * reason given below about child paths: a child only exists when its
81
+ * parent is published, and this rule refuses the parent.
71
82
  *
72
83
  * NOT reserved, and deliberately so, because measuring found them fine:
73
84
  * `401`, `403`, `503` (`/401` returns 200 through the catch-all — two of the
@@ -82,6 +93,7 @@ import { formatCollectionLinkValue, formatEntryLinkValue, formatFeedLinkValue, p
82
93
  '404',
83
94
  '500',
84
95
  'search',
96
+ ENTRY_PREVIEW_ROUTE_SEGMENT,
85
97
  'api',
86
98
  '_next',
87
99
  '_static'
@@ -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 { 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 *\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 'api',\n '_next',\n '_static',\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 only exists when its\n * PARENT screen is published, the parent would sit at `404`, and this same\n * rule refuses that. A second list to express a case that cannot arise would\n * 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 screen under a ' +\n 'parent screen instead'\n\n/** Minimal screen shape the hierarchy helpers need. */\nexport interface ScreenRouteNode {\n slug?: string\n parentId?: ScreenUid\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. Returns `undefined` when the screen (or any ancestor) has no\n * slug, when the screen's own slug is `'/'` while it has a parent, or when\n * the chain has a cycle / exceeds {@link MAX_SCREEN_DEPTH}.\n */\nexport function composeScreenRoutePath(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): string | undefined {\n const segments: string[] = []\n const visited = new Set<ScreenUid>()\n let currentId: ScreenUid | undefined = screenId\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 (!screen?.slug) return undefined\n if (screen.slug === SCREEN_ROOT_PATH) {\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 have a parent.\n if (currentId === screenId && screen.parentId) return undefined\n } else {\n segments.unshift(screen.slug)\n }\n currentId = screen.parentId\n }\n\n if (!segments.length) {\n return screensById[screenId]?.slug === SCREEN_ROOT_PATH\n ? SCREEN_ROOT_PATH\n : undefined\n }\n return segments.join('/')\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/** How {@link buildScreenRouteEntries} treats a screen with no entry today. */\nexport interface BuildScreenRouteEntriesOptions {\n /**\n * Is this call a PUBLISH, 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. This\n * function is used for both, and until now it could not tell them apart: it\n * wrote a path for every screen in the subtree whose slug chain happened to\n * resolve, whether or not anyone had asked for that screen to go live.\n *\n * What that produced on `aglyn-marketing`: assigning a parent to an\n * unpublished screen that merely CARRIED a slug registered it in the map,\n * and the besigner toolbar — which reads the map — then offered `Unpublish`\n * and an enabled `Live` link for a screen nobody had published, with no\n * `publishedAt` on the document and a 404 at the address.\n *\n * `false` therefore restricts the write to entries that ALREADY exist:\n * paths are rewritten, broken ones are removed, and nothing new goes live.\n * A move is not an activation.\n *\n * Defaults to `true`, which is what the publish buttons mean.\n */\n publish?: boolean\n}\n\n/**\n * Routing-map entries for a screen plus all its descendants under a\n * candidate screens map: a composed path sets the entry, `null` marks an\n * existing entry whose chain no longer resolves for removal. Callers apply\n * the result in one write so slug/parent changes cascade atomically.\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 | null> {\n const { publish = true } = options\n const entries: Record<ScreenUid, string | null> = {}\n const ids = [screenId, ...collectScreenDescendantIds(screenId, screensById)]\n for (const id of ids) {\n const routed = routingMap?.[id] !== undefined\n const path = composeScreenRoutePath(id, screensById)\n if (path) {\n // A move rewrites what is live; it never puts something new there.\n if (routed || publish) entries[id] = path\n } else if (routed) entries[id] = null\n }\n return entries\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/** 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 * 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) and `kind: 'error'` (a screen assigned to one of the host's four\n * error slots, rendered on paths that matched nothing — AGL-2092). All four\n * are also the exclusions `countBillableScreens` subtracts before enforcing\n * `screensPerHost`, and since AGL-1400 they are the WHOLE of that subtraction:\n * the count reads no other collection.\n *\n * Adding the fourth 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 )\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","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","MAX_SCREEN_DEPTH","composeScreenRoutePath","screenId","screensById","segments","visited","Set","currentId","has","size","add","screen","slug","parentId","unshift","length","join","collectScreenDescendantIds","childrenByParent","Map","id","Object","entries","siblings","get","push","set","result","queue","shift","wouldCreateScreenCycle","nextParentId","buildScreenRouteEntries","routingMap","options","publish","ids","routed","findScreenIdByRoutePath","screens","entry","find","value","screenRoutePathToUrl","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","kind","billableScreenIds","keys","exemptErrors","exemptErrorScreenIds","billable","claimsToBeAPage","exemptionSpent","live","sort","slice","nonPageScreenIds","nonPage","NON_PAGE_SCREEN_MAX_PER_HOST"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SA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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 { 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 only exists when its\n * parent is published, and this rule refuses the parent.\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]\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 only exists when its\n * PARENT screen is published, the parent would sit at `404`, and this same\n * rule refuses that. A second list to express a case that cannot arise would\n * 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 screen under a ' +\n 'parent screen instead'\n\n/** Minimal screen shape the hierarchy helpers need. */\nexport interface ScreenRouteNode {\n slug?: string\n parentId?: ScreenUid\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. Returns `undefined` when the screen (or any ancestor) has no\n * slug, when the screen's own slug is `'/'` while it has a parent, or when\n * the chain has a cycle / exceeds {@link MAX_SCREEN_DEPTH}.\n */\nexport function composeScreenRoutePath(\n screenId: ScreenUid,\n screensById: Record<ScreenUid, ScreenRouteNode | undefined>,\n): string | undefined {\n const segments: string[] = []\n const visited = new Set<ScreenUid>()\n let currentId: ScreenUid | undefined = screenId\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 (!screen?.slug) return undefined\n if (screen.slug === SCREEN_ROOT_PATH) {\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 have a parent.\n if (currentId === screenId && screen.parentId) return undefined\n } else {\n segments.unshift(screen.slug)\n }\n currentId = screen.parentId\n }\n\n if (!segments.length) {\n return screensById[screenId]?.slug === SCREEN_ROOT_PATH\n ? SCREEN_ROOT_PATH\n : undefined\n }\n return segments.join('/')\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/** How {@link buildScreenRouteEntries} treats a screen with no entry today. */\nexport interface BuildScreenRouteEntriesOptions {\n /**\n * Is this call a PUBLISH, 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. This\n * function is used for both, and until now it could not tell them apart: it\n * wrote a path for every screen in the subtree whose slug chain happened to\n * resolve, whether or not anyone had asked for that screen to go live.\n *\n * What that produced on `aglyn-marketing`: assigning a parent to an\n * unpublished screen that merely CARRIED a slug registered it in the map,\n * and the besigner toolbar — which reads the map — then offered `Unpublish`\n * and an enabled `Live` link for a screen nobody had published, with no\n * `publishedAt` on the document and a 404 at the address.\n *\n * `false` therefore restricts the write to entries that ALREADY exist:\n * paths are rewritten, broken ones are removed, and nothing new goes live.\n * A move is not an activation.\n *\n * Defaults to `true`, which is what the publish buttons mean.\n */\n publish?: boolean\n}\n\n/**\n * Routing-map entries for a screen plus all its descendants under a\n * candidate screens map: a composed path sets the entry, `null` marks an\n * existing entry whose chain no longer resolves for removal. Callers apply\n * the result in one write so slug/parent changes cascade atomically.\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 | null> {\n const { publish = true } = options\n const entries: Record<ScreenUid, string | null> = {}\n const ids = [screenId, ...collectScreenDescendantIds(screenId, screensById)]\n for (const id of ids) {\n const routed = routingMap?.[id] !== undefined\n const path = composeScreenRoutePath(id, screensById)\n if (path) {\n // A move rewrites what is live; it never puts something new there.\n if (routed || publish) entries[id] = path\n } else if (routed) entries[id] = null\n }\n return entries\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/** 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 * 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) and `kind: 'error'` (a screen assigned to one of the host's four\n * error slots, rendered on paths that matched nothing — AGL-2092). All four\n * are also the exclusions `countBillableScreens` subtracts before enforcing\n * `screensPerHost`, and since AGL-1400 they are the WHOLE of that subtraction:\n * the count reads no other collection.\n *\n * Adding the fourth 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 )\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","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","MAX_SCREEN_DEPTH","composeScreenRoutePath","screenId","screensById","segments","visited","Set","currentId","has","size","add","screen","slug","parentId","unshift","length","join","collectScreenDescendantIds","childrenByParent","Map","id","Object","entries","siblings","get","push","set","result","queue","shift","wouldCreateScreenCycle","nextParentId","buildScreenRouteEntries","routingMap","options","publish","ids","routed","findScreenIdByRoutePath","screens","entry","find","value","screenRoutePathToUrl","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","kind","billableScreenIds","keys","exemptErrors","exemptErrorScreenIds","billable","claimsToBeAPage","exemptionSpent","live","sort","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,mBAAmB,QAAQ,sBAAkB;AACtD,SACEC,yBAAyB,EACzBC,oBAAoB,EACpBC,mB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,iBACJnE,OAAO4D,IAAI,KAAKJ,qBAChBxD,OAAO2D,SAAS,IAAI,QACpB,CAACI,aAAalE,GAAG,CAACG,OAAOS,EAAE;QAC7B,IAAIiB,OAAO7B,GAAG,CAACG,OAAOS,EAAE,KAAKyD,mBAAmBC,gBAAgB;YAC9DF,SAASlE,GAAG,CAACC,OAAOS,EAAE;QACxB;IACF;IACA,OAAOwD;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCC,GACD,OAAO,SAASD,qBACdpC,OAA4C;IAE5C,MAAMwC,OAAsB,EAAE;IAC9B,KAAK,MAAMpE,UAAU4B,QAAS;QAC5B,IAAI5B,OAAO4D,IAAI,KAAKJ,mBAAmB;QACvC,IAAIxD,OAAO2D,SAAS,IAAI,MAAM;QAC9BS,KAAKtD,IAAI,CAACd,OAAOS,EAAE;IACrB;IACA,IAAI2D,KAAKhE,MAAM,IAAIqD,2BAA2B,OAAO,IAAI9D,IAAIyE;IAC7D,OAAO,IAAIzE,IAAIyE,KAAKC,IAAI,GAAGC,KAAK,CAAC,GAAGb;AACtC;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,SAASc,iBACd3C,OAA4C,EAC5CN,UAA6B;IAE7B,MAAM2C,WAAWJ,kBAAkBjC,SAASN;IAC5C,MAAMkD,UAAU,IAAI7E;IACpB,KAAK,MAAMK,UAAU4B,QAAS;QAC5B,IAAI5B,OAAO2D,SAAS,IAAI,MAAM;QAC9B,IAAI,CAACM,SAASpE,GAAG,CAACG,OAAOS,EAAE,GAAG+D,QAAQzE,GAAG,CAACC,OAAOS,EAAE;IACrD;IACA,OAAO+D;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCC,GACD,OAAO,MAAMC,+BAA+B,KAAI"}
@@ -82,5 +82,23 @@ export interface WistiaPlayerOptions {
82
82
  * `autoPlay=false` rather than leaving the option out: an option in the embed
83
83
  * overrides the media's own settings in the Wistia account, and those may be
84
84
  * set to autoplay.
85
+ *
86
+ * ## The corners belong to the page (AGL-3209)
87
+ *
88
+ * `roundedPlayer=false` is stated on every address, and is not an option a
89
+ * caller may turn back on. Wistia's rounded chrome rounds and clips INSIDE the
90
+ * frame, where the document's own canvas is white: on a dark page the corner
91
+ * arcs and the clip's antialiased edge composite as a white ring around the
92
+ * film rather than as the page behind them.
93
+ *
94
+ * Measured on 2026-09-21 against the live videos page, whose background is
95
+ * `rgb(42 52 64)` and whose film is `rgb(22 30 52)`: the frame's first column
96
+ * read `rgb(137 141 152)` and its top-left corner `rgb(195 198 201)` —
97
+ * lighter than either, so painted rather than blended. With the option off
98
+ * the same pixels are the film.
99
+ *
100
+ * The shape is the placement's to decide in any case: `VideoPlayerFrame` takes
101
+ * a `radius` from the element's own control and puts it on the frame, which a
102
+ * second rounding inside the frame can only fight.
85
103
  */
86
104
  export declare function wistiaPlayerSrc(value: unknown, options?: WistiaPlayerOptions): string | undefined;
@@ -104,11 +104,30 @@
104
104
  * `autoPlay=false` rather than leaving the option out: an option in the embed
105
105
  * overrides the media's own settings in the Wistia account, and those may be
106
106
  * set to autoplay.
107
+ *
108
+ * ## The corners belong to the page (AGL-3209)
109
+ *
110
+ * `roundedPlayer=false` is stated on every address, and is not an option a
111
+ * caller may turn back on. Wistia's rounded chrome rounds and clips INSIDE the
112
+ * frame, where the document's own canvas is white: on a dark page the corner
113
+ * arcs and the clip's antialiased edge composite as a white ring around the
114
+ * film rather than as the page behind them.
115
+ *
116
+ * Measured on 2026-09-21 against the live videos page, whose background is
117
+ * `rgb(42 52 64)` and whose film is `rgb(22 30 52)`: the frame's first column
118
+ * read `rgb(137 141 152)` and its top-left corner `rgb(195 198 201)` —
119
+ * lighter than either, so painted rather than blended. With the option off
120
+ * the same pixels are the film.
121
+ *
122
+ * The shape is the placement's to decide in any case: `VideoPlayerFrame` takes
123
+ * a `radius` from the element's own control and puts it on the frame, which a
124
+ * second rounding inside the frame can only fight.
107
125
  */ export function wistiaPlayerSrc(value, options = {}) {
108
126
  const embedUrl = wistiaEmbedUrl(value);
109
127
  if (!embedUrl) return undefined;
110
128
  const params = new URLSearchParams({
111
- autoPlay: options.autoPlay === false ? 'false' : 'true'
129
+ autoPlay: options.autoPlay === false ? 'false' : 'true',
130
+ roundedPlayer: 'false'
112
131
  });
113
132
  if (options.doNotTrack) params.set('doNotTrack', 'true');
114
133
  if (options.muted) params.set('muted', 'true');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/wistia-embed.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 Wistia video, as the Video element plays it (AGL-2826).\n *\n * ## Only the media id survives\n *\n * An author pastes whatever link Wistia showed them. That string never reaches\n * a frame: every builder below reads the media's hashed id out of it and\n * rebuilds the address, so the only frame this module can produce is on\n * {@link WISTIA_PLAYER_ORIGIN}. That closed set is what lets the tenant's\n * `frame-src` name the origin for every site, and it is the rule\n * `parseVideoEmbedSrc` already holds YouTube and Vimeo to.\n *\n * ## The iframe embed, not the player script\n *\n * Wistia offers two embeds. The script embed runs Wistia's JavaScript in the\n * page itself, so every site would need `connect-src`, `img-src` and\n * `media-src` grants for Wistia's hosts, and the player's storage and beacons\n * would run as the site. The iframe embed runs all of that inside a document on\n * Wistia's origin, under Wistia's own policy: the page needs one `frame-src`\n * entry, and whatever the player stores is keyed to Wistia inside the site's\n * partition rather than written as the site.\n *\n * Measured on 2026-09-10: `fast.wistia.net/embed/iframe/{id}` answers 200 with\n * no redirect, so no second origin is involved in loading the frame.\n */\n\n/** The only origin a Wistia player frame is ever loaded from. */\nexport const WISTIA_PLAYER_ORIGIN = 'https://fast.wistia.net'\n\n/** A hashed id: ten lowercase letters and digits, e.g. `e4a27b971d`. */\nconst HASHED_ID = /^[a-z0-9]{10}$/\n\n/**\n * The paths a Wistia link carries a media id in. Wistia's oEmbed endpoint\n * matches on the path rather than the host, and so does this; the host is\n * checked separately by {@link isWistiaHostname}.\n */\nconst MEDIA_ID_PATHS: readonly RegExp[] = [\n // A media page: `https://acme.wistia.com/medias/{id}`, and its `/manage`.\n /^\\/medias\\/([^/]+)(?:\\/manage)?\\/?$/,\n // The short form of the same page.\n /^\\/m\\/([^/]+)\\/?$/,\n // An iframe embed's own address.\n /^\\/embed\\/iframe\\/([^/]+)\\/?$/,\n // A script embed's media address, with or without its `.jsonp` suffix.\n /^\\/embed\\/medias\\/([^/.]+)(?:\\.jsonp?)?\\/?$/,\n]\n\n/**\n * Whether a hostname is Wistia's. Exact or dot-anchored matches only, so\n * `wistia.com.example.net` and `notwistia.com` are refused.\n */\nfunction isWistiaHostname(hostname: string): boolean {\n return ['wistia.com', 'wistia.net', 'wi.st'].some(\n (domain) => hostname === domain || hostname.endsWith(`.${domain}`),\n )\n}\n\n/**\n * The hashed id a Wistia link names, or `undefined` for anything else.\n *\n * A share link (`/s/{slug}`) names no id and is refused rather than guessed\n * at, as is a value that is not an http(s) URL.\n */\nexport function wistiaMediaId(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n let url: URL\n try {\n url = new URL(value.trim())\n } catch {\n return undefined\n }\n if (url.protocol !== 'https:' && url.protocol !== 'http:') return undefined\n if (!isWistiaHostname(url.hostname)) return undefined\n for (const pattern of MEDIA_ID_PATHS) {\n const id = pattern.exec(url.pathname)?.[1]\n if (id && HASHED_ID.test(id)) return id\n }\n return undefined\n}\n\n/**\n * The player page for a Wistia link, with no per-visit options: what\n * `VideoObject.embedUrl` names.\n */\nexport function wistiaEmbedUrl(value: unknown): string | undefined {\n const id = wistiaMediaId(value)\n return id ? `${WISTIA_PLAYER_ORIGIN}/embed/iframe/${id}` : undefined\n}\n\nexport interface WistiaPlayerOptions {\n /**\n * Start playing as soon as the player is ready. On unless this is exactly\n * `false`; see {@link wistiaPlayerSrc} for which frame turns it off.\n */\n autoPlay?: boolean\n /**\n * Ask Wistia not to record the viewing session (its `doNotTrack` embed\n * option). The element sets it for every visitor whose analytics consent is\n * not on record.\n */\n doNotTrack?: boolean\n /** Start without sound. */\n muted?: boolean\n /** Restart at the end (`endVideoBehavior=loop`). */\n loop?: boolean\n}\n\n/**\n * The address of a Wistia player frame.\n *\n * `autoPlay` is on by default, because the usual frame is the one a visitor's\n * press loads: it exists only because somebody pressed play, and a second play\n * button inside the player would ask them twice.\n *\n * The frame a page loads before anyone has pressed anything (\"Load the player\n * with the page\", AGL-2962) passes `autoPlay: false`. The address then says\n * `autoPlay=false` rather than leaving the option out: an option in the embed\n * overrides the media's own settings in the Wistia account, and those may be\n * set to autoplay.\n */\nexport function wistiaPlayerSrc(\n value: unknown,\n options: WistiaPlayerOptions = {},\n): string | undefined {\n const embedUrl = wistiaEmbedUrl(value)\n if (!embedUrl) return undefined\n const params = new URLSearchParams({\n autoPlay: options.autoPlay === false ? 'false' : 'true',\n })\n if (options.doNotTrack) params.set('doNotTrack', 'true')\n if (options.muted) params.set('muted', 'true')\n if (options.loop) params.set('endVideoBehavior', 'loop')\n return `${embedUrl}?${params.toString()}`\n}\n"],"names":["WISTIA_PLAYER_ORIGIN","HASHED_ID","MEDIA_ID_PATHS","isWistiaHostname","hostname","some","domain","endsWith","wistiaMediaId","value","undefined","url","URL","trim","protocol","pattern","id","exec","pathname","test","wistiaEmbedUrl","wistiaPlayerSrc","options","embedUrl","params","URLSearchParams","autoPlay","doNotTrack","set","muted","loop","toString"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GAED,+DAA+D,GAC/D,OAAO,MA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,KAAK,QAAQ,UAAU;IACnD;IACA,IAAIJ,QAAQK,UAAU,EAAEH,OAAOI,GAAG,CAAC,cAAc;IACjD,IAAIN,QAAQO,KAAK,EAAEL,OAAOI,GAAG,CAAC,SAAS;IACvC,IAAIN,QAAQQ,IAAI,EAAEN,OAAOI,GAAG,CAAC,oBAAoB;IACjD,OAAO,GAAGL,SAAS,CAAC,EAAEC,OAAOO,QAAQ,IAAI;AAC3C"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/wistia-embed.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 Wistia video, as the Video element plays it (AGL-2826).\n *\n * ## Only the media id survives\n *\n * An author pastes whatever link Wistia showed them. That string never reaches\n * a frame: every builder below reads the media's hashed id out of it and\n * rebuilds the address, so the only frame this module can produce is on\n * {@link WISTIA_PLAYER_ORIGIN}. That closed set is what lets the tenant's\n * `frame-src` name the origin for every site, and it is the rule\n * `parseVideoEmbedSrc` already holds YouTube and Vimeo to.\n *\n * ## The iframe embed, not the player script\n *\n * Wistia offers two embeds. The script embed runs Wistia's JavaScript in the\n * page itself, so every site would need `connect-src`, `img-src` and\n * `media-src` grants for Wistia's hosts, and the player's storage and beacons\n * would run as the site. The iframe embed runs all of that inside a document on\n * Wistia's origin, under Wistia's own policy: the page needs one `frame-src`\n * entry, and whatever the player stores is keyed to Wistia inside the site's\n * partition rather than written as the site.\n *\n * Measured on 2026-09-10: `fast.wistia.net/embed/iframe/{id}` answers 200 with\n * no redirect, so no second origin is involved in loading the frame.\n */\n\n/** The only origin a Wistia player frame is ever loaded from. */\nexport const WISTIA_PLAYER_ORIGIN = 'https://fast.wistia.net'\n\n/** A hashed id: ten lowercase letters and digits, e.g. `e4a27b971d`. */\nconst HASHED_ID = /^[a-z0-9]{10}$/\n\n/**\n * The paths a Wistia link carries a media id in. Wistia's oEmbed endpoint\n * matches on the path rather than the host, and so does this; the host is\n * checked separately by {@link isWistiaHostname}.\n */\nconst MEDIA_ID_PATHS: readonly RegExp[] = [\n // A media page: `https://acme.wistia.com/medias/{id}`, and its `/manage`.\n /^\\/medias\\/([^/]+)(?:\\/manage)?\\/?$/,\n // The short form of the same page.\n /^\\/m\\/([^/]+)\\/?$/,\n // An iframe embed's own address.\n /^\\/embed\\/iframe\\/([^/]+)\\/?$/,\n // A script embed's media address, with or without its `.jsonp` suffix.\n /^\\/embed\\/medias\\/([^/.]+)(?:\\.jsonp?)?\\/?$/,\n]\n\n/**\n * Whether a hostname is Wistia's. Exact or dot-anchored matches only, so\n * `wistia.com.example.net` and `notwistia.com` are refused.\n */\nfunction isWistiaHostname(hostname: string): boolean {\n return ['wistia.com', 'wistia.net', 'wi.st'].some(\n (domain) => hostname === domain || hostname.endsWith(`.${domain}`),\n )\n}\n\n/**\n * The hashed id a Wistia link names, or `undefined` for anything else.\n *\n * A share link (`/s/{slug}`) names no id and is refused rather than guessed\n * at, as is a value that is not an http(s) URL.\n */\nexport function wistiaMediaId(value: unknown): string | undefined {\n if (typeof value !== 'string') return undefined\n let url: URL\n try {\n url = new URL(value.trim())\n } catch {\n return undefined\n }\n if (url.protocol !== 'https:' && url.protocol !== 'http:') return undefined\n if (!isWistiaHostname(url.hostname)) return undefined\n for (const pattern of MEDIA_ID_PATHS) {\n const id = pattern.exec(url.pathname)?.[1]\n if (id && HASHED_ID.test(id)) return id\n }\n return undefined\n}\n\n/**\n * The player page for a Wistia link, with no per-visit options: what\n * `VideoObject.embedUrl` names.\n */\nexport function wistiaEmbedUrl(value: unknown): string | undefined {\n const id = wistiaMediaId(value)\n return id ? `${WISTIA_PLAYER_ORIGIN}/embed/iframe/${id}` : undefined\n}\n\nexport interface WistiaPlayerOptions {\n /**\n * Start playing as soon as the player is ready. On unless this is exactly\n * `false`; see {@link wistiaPlayerSrc} for which frame turns it off.\n */\n autoPlay?: boolean\n /**\n * Ask Wistia not to record the viewing session (its `doNotTrack` embed\n * option). The element sets it for every visitor whose analytics consent is\n * not on record.\n */\n doNotTrack?: boolean\n /** Start without sound. */\n muted?: boolean\n /** Restart at the end (`endVideoBehavior=loop`). */\n loop?: boolean\n}\n\n/**\n * The address of a Wistia player frame.\n *\n * `autoPlay` is on by default, because the usual frame is the one a visitor's\n * press loads: it exists only because somebody pressed play, and a second play\n * button inside the player would ask them twice.\n *\n * The frame a page loads before anyone has pressed anything (\"Load the player\n * with the page\", AGL-2962) passes `autoPlay: false`. The address then says\n * `autoPlay=false` rather than leaving the option out: an option in the embed\n * overrides the media's own settings in the Wistia account, and those may be\n * set to autoplay.\n *\n * ## The corners belong to the page (AGL-3209)\n *\n * `roundedPlayer=false` is stated on every address, and is not an option a\n * caller may turn back on. Wistia's rounded chrome rounds and clips INSIDE the\n * frame, where the document's own canvas is white: on a dark page the corner\n * arcs and the clip's antialiased edge composite as a white ring around the\n * film rather than as the page behind them.\n *\n * Measured on 2026-09-21 against the live videos page, whose background is\n * `rgb(42 52 64)` and whose film is `rgb(22 30 52)`: the frame's first column\n * read `rgb(137 141 152)` and its top-left corner `rgb(195 198 201)` —\n * lighter than either, so painted rather than blended. With the option off\n * the same pixels are the film.\n *\n * The shape is the placement's to decide in any case: `VideoPlayerFrame` takes\n * a `radius` from the element's own control and puts it on the frame, which a\n * second rounding inside the frame can only fight.\n */\nexport function wistiaPlayerSrc(\n value: unknown,\n options: WistiaPlayerOptions = {},\n): string | undefined {\n const embedUrl = wistiaEmbedUrl(value)\n if (!embedUrl) return undefined\n const params = new URLSearchParams({\n autoPlay: options.autoPlay === false ? 'false' : 'true',\n roundedPlayer: 'false',\n })\n if (options.doNotTrack) params.set('doNotTrack', 'true')\n if (options.muted) params.set('muted', 'true')\n if (options.loop) params.set('endVideoBehavior', 'loop')\n return `${embedUrl}?${params.toString()}`\n}\n"],"names":["WISTIA_PLAYER_ORIGIN","HASHED_ID","MEDIA_ID_PATHS","isWistiaHostname","hostname","some","domain","endsWith","wistiaMediaId","value","undefined","url","URL","trim","protocol","pattern","id","exec","pathname","test","wistiaEmbedUrl","wistiaPlayerSrc","options","embedUrl","params","URLSearchParams","autoPlay","roundedPlayer","doNotTrack","set","muted","loop","toString"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GAED,+DAA+D,GAC/D,OAAO,MAAMA,uBAAuB,0BAAyB;AAE7D,sEAAsE,GACtE,MAAMC,YAAY;AAElB;;;;CAIC,GACD,MAAMC,iBAAoC;IACxC,0EAA0E;IAC1E;IACA,mCAAmC;IACnC;IACA,iCAAiC;IACjC;IACA,uEAAuE;IACvE;CACD;AAED;;;CAGC,GACD,SAASC,iBAAiBC,QAAgB;IACxC,OAAO;QAAC;QAAc;QAAc;KAAQ,CAACC,IAAI,CAC/C,CAACC,SAAWF,aAAaE,UAAUF,SAASG,QAAQ,CAAC,CAAC,CAAC,EAAED,QAAQ;AAErE;AAEA;;;;;CAKC,GACD,OAAO,SAASE,cAAcC,KAAc;IAC1C,IAAI,OAAOA,UAAU,UAAU,OAAOC;IACtC,IAAIC;IACJ,IAAI;QACFA,MAAM,IAAIC,IAAIH,MAAMI,IAAI;IAC1B,EAAE,eAAM;QACN,OAAOH;IACT;IACA,IAAIC,IAAIG,QAAQ,KAAK,YAAYH,IAAIG,QAAQ,KAAK,SAAS,OAAOJ;IAClE,IAAI,CAACP,iBAAiBQ,IAAIP,QAAQ,GAAG,OAAOM;IAC5C,KAAK,MAAMK,WAAWb,eAAgB;YACzBa;QAAX,MAAMC,MAAKD,gBAAAA,QAAQE,IAAI,CAACN,IAAIO,QAAQ,sBAAzBH,aAA4B,CAAC,EAAE;QAC1C,IAAIC,MAAMf,UAAUkB,IAAI,CAACH,KAAK,OAAOA;IACvC;IACA,OAAON;AACT;AAEA;;;CAGC,GACD,OAAO,SAASU,eAAeX,KAAc;IAC3C,MAAMO,KAAKR,cAAcC;IACzB,OAAOO,KAAK,GAAGhB,qBAAqB,cAAc,EAAEgB,IAAI,GAAGN;AAC7D;AAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GACD,OAAO,SAASW,gBACdZ,KAAc,EACda,UAA+B,CAAC,CAAC;IAEjC,MAAMC,WAAWH,eAAeX;IAChC,IAAI,CAACc,UAAU,OAAOb;IACtB,MAAMc,SAAS,IAAIC,gBAAgB;QACjCC,UAAUJ,QAAQI,QAAQ,KAAK,QAAQ,UAAU;QACjDC,eAAe;IACjB;IACA,IAAIL,QAAQM,UAAU,EAAEJ,OAAOK,GAAG,CAAC,cAAc;IACjD,IAAIP,QAAQQ,KAAK,EAAEN,OAAOK,GAAG,CAAC,SAAS;IACvC,IAAIP,QAAQS,IAAI,EAAEP,OAAOK,GAAG,CAAC,oBAAoB;IACjD,OAAO,GAAGN,SAAS,CAAC,EAAEC,OAAOQ,QAAQ,IAAI;AAC3C"}
@@ -268,6 +268,48 @@ export interface ConsoleNavSection {
268
268
  * the sales suite built on that list starts at Starter.
269
269
  */
270
270
  featureFlag?: keyof OrgFeatureFlags;
271
+ /**
272
+ * Permission key gating THIS section, when the surface is open to every
273
+ * member and part of it is not (AGL-3080). Omit to inherit the
274
+ * extension's and the nav item's, which is the common case.
275
+ *
276
+ * The third gate, composed the way the other two are: ANDed with what the
277
+ * extension and the nav item already require, so a section can only ever
278
+ * be narrower than the surface holding it. A section this refuses is not
279
+ * drawn in the rail at all — unlike a `featureFlag` refusal, which draws
280
+ * locked and links to the notice that sells it, because a permission is
281
+ * not something the reader can buy — and a deep link to it is answered
282
+ * with the shell's refusal instead of its body. One verdict, both places.
283
+ *
284
+ * ⚠️ NOT a replacement for the server's rule. The rules and the plugin's
285
+ * own handlers enforce this regardless of what renders; this keeps a
286
+ * reader from being offered a page that is about to refuse them.
287
+ *
288
+ * The case it exists for is a hub most of a workspace uses and whose
289
+ * seller half only a publisher does: the Marketplace's browse, installed
290
+ * and licences sections are every member's, and listings, upload, sales
291
+ * and payouts read the organization's revenue.
292
+ */
293
+ permission?: string;
294
+ /**
295
+ * Query keys that land a BARE hub URL on this section instead of on the
296
+ * first one the reader may open (AGL-3080).
297
+ *
298
+ * The case it exists for is a return URL held by somebody else. Stripe
299
+ * bakes `?connect=` into account-onboarding links and `?purchase=` into
300
+ * checkout sessions, so a seller part-way through onboarding is carrying
301
+ * one right now — in a third party's records, not ours, and unfixable from
302
+ * this side once it lands somewhere that means nothing to them. A seller
303
+ * coming back from Connect wants Payouts; a buyer coming back from
304
+ * checkout wants what they now own.
305
+ *
306
+ * The key's VALUE is not read, only its presence: these are markers, and a
307
+ * marker nothing routes on still survives the hop, which is what makes it
308
+ * safe for anyone to add one. The gates still apply — a section this
309
+ * claims but the reader may not open is not landed on, and the bare rule
310
+ * takes over.
311
+ */
312
+ landsOnQuery?: readonly string[];
271
313
  }
272
314
  /** A {@link ConsoleNavSection} with the shell's answers filled in. */
273
315
  export interface ResolvedConsoleNavSection {
@@ -286,6 +328,18 @@ export interface ResolvedConsoleNavSection {
286
328
  * workspace would be the AGL-1380 defect in a new place.
287
329
  */
288
330
  locked?: boolean;
331
+ /**
332
+ * True when this section's own `permission` refuses this reader
333
+ * (AGL-3080) — the reason it is not `visible`, kept apart from the
334
+ * release flag's so a deep link is answered with the refusal that
335
+ * applies rather than with "coming soon". Never true while the member
336
+ * read is pending: the permission map answers as an admin's until it
337
+ * lands, so an unsettled read is neither a grant nor a refusal.
338
+ */
339
+ refused?: boolean;
340
+ /** The section's declared {@link ConsoleNavSection.landsOnQuery}, carried
341
+ * through so the shell's landing rule can read it (AGL-3080). */
342
+ landsOnQuery?: readonly string[];
289
343
  }
290
344
  export interface ConsoleNavItem {
291
345
  label: string;