@aglyn/tenant-runtime 1.0.0-beta.203 → 1.0.0-beta.204

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/tenant-runtime",
3
- "version": "1.0.0-beta.203",
3
+ "version": "1.0.0-beta.204",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,8 +25,8 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.0.0-beta.203",
29
- "@aglyn/tenant-data-admin": "1.0.0-beta.203",
28
+ "@aglyn/aglyn": "1.0.0-beta.204",
29
+ "@aglyn/tenant-data-admin": "1.0.0-beta.204",
30
30
  "@swc/helpers": "0.5.23"
31
31
  },
32
32
  "peerDependencies": {
@@ -150,7 +150,18 @@ import { collectSocialImageFacts } from "./social-image-facts.js";
150
150
  socialImages: card.socialImages,
151
151
  // The designated screen's host variables, and its layout's, fill in
152
152
  // from this site, as the built-in author page's already do (AGL-2883).
153
- host: host
153
+ host: host,
154
+ // Named as the author template it is if the page review holds it
155
+ // (AGL-3374); without it the site's built-in author page serves.
156
+ page: {
157
+ template: {
158
+ role: 'entry',
159
+ route: '/author/:slug',
160
+ collectionName: 'Authors',
161
+ entryPath: `/author/${content.slug}`,
162
+ fallback: 'built-in-design'
163
+ }
164
+ }
154
165
  }));
155
166
  if (!nodes) return null;
156
167
  /*
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/tenant/runtime/src/lib/compose-author-page.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 * as Aglyn from '@aglyn/aglyn/server'\nimport buildAuthorPageNodes from './author-page-nodes'\nimport { resolveBuiltInPageLayoutId } from './built-in-page-layout'\nimport composeScreenNodes, {\n composeNodesWithChrome,\n} from './compose-screen-nodes'\nimport type { AuthorContent } from './get-author-content'\nimport getScreen from './get-screen'\nimport { collectSocialImageFacts } from './social-image-facts'\n\n/**\n * The host field naming the screen every author page renders through\n * (AGL-2518).\n *\n * ## Why the HOST and not the author\n *\n * A collection names its own list and entry templates because a site\n * legitimately designs its changelog differently from its blog. Author pages\n * are not like that: they are one page shape repeated per person, and letting\n * each author record name its own template would mean a masthead where the\n * design changes as the reader clicks between colleagues — plus a template\n * picker on a form whose whole subject is a byline.\n *\n * ## Why a SCREEN and not a layout\n *\n * The opposite call from `builtInPageLayoutId` (AGL-2513), and for the reason\n * that comment gives in reverse. Search results have no design worth\n * authoring — the platform composes the body and the site only chooses the\n * chrome around it. An author page has: a portrait, a bio, a role, links, and\n * a listing whose cards a designer wants to match the blog's. That is a page,\n * so the author designs it as one, with `{{author.*}}` tokens and the same\n * Collection entries block every list template uses.\n *\n * Unset is the ordinary case rather than a misconfiguration, and it renders\n * the built-in body — bylines link to this address, so it must always answer.\n */\nexport const AUTHOR_PAGE_SCREEN_FIELD = 'authorScreenId' as const\n\n/**\n * The pseudo-collection an author page's entries block resolves against.\n *\n * The compose pipeline keys entry sources by collection slug, and this page\n * has no single collection — it mixes them. Its entries are handed over\n * already in hand (`ComposeCollectionContext.entries`), which is a path that\n * never touches Firestore, so the key only has to be a name that no real\n * collection can take: a collection slug is a URL segment, and this is not a\n * legal one.\n *\n * It never reaches a URL. Every entry on this page carries its OWN\n * `collectionSlug` out of the read that found it, and `collectionEntryTokens`\n * prefers that — which is the whole reason a cross-collection listing can\n * build correct `entry.url`s at all.\n */\nexport const AUTHOR_ENTRIES_SOURCE_SLUG = '__author__'\n\n/** What the author route renders. */\nexport interface ComposedAuthorPage {\n /** The template screen doc, when one is designated; null for the built-in. */\n screen: Record<string, any> | null\n nodes: Record<string, any>\n /**\n * The current pair of each picture the head's card may name (AGL-2850): the\n * author's share card, then their portrait. Read in the composition's\n * batch, and absent when it answered for neither.\n */\n socialImageFacts?: Aglyn.SocialImageAssetFacts\n}\n\n/** The tokens and entry context both compose paths share. */\nfunction authorComposeContext(content: AuthorContent) {\n const address = content.author\n ? { author: content.author }\n : { authorName: content.slug }\n const pager = Aglyn.contentAuthorPaginationLinks({\n ...address,\n page: content.page,\n totalPages: content.totalPages,\n })\n return {\n /**\n * The pictures the head builds the card from, in its order: the share\n * card, then the portrait (AGL-2850). The author head reads the record\n * alone and never the site default, so the host's image is not one.\n */\n cardImages: [content.author?.seoImage, content.author?.image],\n tokens: {\n ...Aglyn.contentAuthorTokens(content.author, {\n entryCount: content.totalEntries,\n }),\n // The byline falls back to the raw segment for an unknown author, so a\n // heading bound to `{{author.name}}` prints something either way.\n 'author.name': content.name,\n // Named `pagination.*` rather than `author.page*`, so a designer who has\n // already built a pager on a collection list template rebuilds nothing\n // here — and so the two pagers cannot drift into two spellings of the\n // same four values. The edges are the empty string, which is what makes\n // an unconditional binding correct on page 1 of 1.\n 'pagination.page': String(pager.page),\n 'pagination.totalPages': String(pager.totalPages),\n 'pagination.prevUrl': pager.prevUrl,\n 'pagination.nextUrl': pager.nextUrl,\n } as Record<string, string>,\n collection: {\n slug: AUTHOR_ENTRIES_SOURCE_SLUG,\n // The slug above is a key, not an address (AGL-2524) — so a block that\n // would build a URL out of it resolves nothing instead.\n routeless: true,\n // Already narrowed to this author AND to this page's window by the\n // loader, for the reason the category route states: a page count\n // computed over the whole set advertises pages that render empty.\n entries: content.entries,\n categories: content.categories,\n page: content.page,\n },\n }\n}\n\n/**\n * An author page composed through the screen the host designated (AGL-2518).\n *\n * The `composeCollectionTemplatePage` shape: the screen goes through the\n * NORMAL published pipeline — theme, shared layout, reusable components,\n * Collection entries blocks — with `{{author.*}}` and `{{pagination.*}}`\n * substituted and Author Profile blocks filled from the record.\n *\n * Returns null when no screen is designated, or when the designated one has\n * been deleted, so the caller falls through to the built-in body rather than\n * serving a 404 for a page a byline links to.\n */\nexport async function composeAuthorTemplatePage(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237); UTC when a site has not\n * named one. Resolved once by the caller that holds the org and the host.\n */\n timeZone?: string\n host: any\n content: AuthorContent\n}): Promise<ComposedAuthorPage | null> {\n const { hostId, host, content } = options\n const screenId = String(host?.[AUTHOR_PAGE_SCREEN_FIELD] ?? '').trim()\n if (!screenId) return null\n try {\n // `allowTemplate`, exactly as a collection template is read: the screen is\n // deliberately not servable at an address of its own, and this is the\n // composition it exists for.\n const templateRes = await getScreen({\n hostId,\n screenId,\n allowTemplate: true,\n })\n if (!templateRes.screen) return null\n const { cardImages, tokens, collection } = authorComposeContext(content)\n const card = collectSocialImageFacts(cardImages)\n const nodes = await composeScreenNodes({\n // The site's zone (AGL-3237). This is the TEMPLATE path, which\n // composes through `composeScreenNodes` rather than\n // `composeNodesWithChrome` — and that difference is why the first two\n // passes at this fix reached every page except the one the bug was\n // reported on.\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n screenId,\n screen: templateRes.screen,\n tokens,\n collection,\n socialImages: card.socialImages,\n // The designated screen's host variables, and its layout's, fill in\n // from this site, as the built-in author page's already do (AGL-2883).\n host: host as Aglyn.HostTokenSource,\n })\n if (!nodes) return null\n /*\n The screen document travels UNCHANGED, and deliberately carries no\n composed SEO.\n\n A collection template composes the entry's title and cover into\n `screen.seo` because `page.tsx` reads that on its way to the head. An\n author page does not take that path: its head branch has the author\n RECORD in hand and builds the title, description and portrait from it\n directly, before the screen branch is ever reached. Writing a second,\n unread copy here would be a value that looks authoritative, is dead, and\n goes stale the first time the head's rule changes — which is how a\n template's stored title came to name every post in a collection\n (AGL-1345).\n */\n return {\n screen: templateRes.screen as Record<string, any>,\n nodes: Aglyn.expandContentAuthorProfile(nodes, content.author),\n ...card.collected(),\n }\n } catch (error) {\n console.error('author template composition failed', error)\n return null\n }\n}\n\n/**\n * The built-in author page (AGL-2518) — the body this file's own nodes build,\n * grafted into the site's shared layout so it carries the same header, nav and\n * footer as the posts it links to.\n *\n * Which layout is the host's to choose (`resolveBuiltInPageLayoutId`), shared\n * with site search so the two platform-built pages of a site cannot end up in\n * different chrome.\n *\n * Fail-open to `null`, and the route then renders the body with no chrome at\n * all. A person's page must not be the page that 500s because a layout was\n * deleted.\n */\nexport async function composeAuthorFallbackPage(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237); UTC when a site has not\n * named one. Resolved once by the caller that holds the org and the host.\n */\n timeZone?: string\n host: any\n content: AuthorContent\n}): Promise<ComposedAuthorPage | null> {\n const { hostId, host, content } = options\n try {\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host })\n const { cardImages, tokens, collection } = authorComposeContext(content)\n const card = collectSocialImageFacts(cardImages)\n const nodes = await composeNodesWithChrome({\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n layoutId,\n socialImages: card.socialImages,\n screenNodes: buildAuthorPageNodes({\n slug: content.slug,\n name: content.name,\n author: content.author,\n hasEntries: content.entries.length > 0,\n page: content.page,\n perPage: content.perPage,\n totalPages: content.totalPages,\n }),\n tokens,\n collection,\n host: host as Aglyn.HostTokenSource,\n })\n return nodes ? { screen: null, nodes, ...card.collected() } : null\n } catch (error) {\n console.error('author page composition failed', error)\n return null\n }\n}\n\nexport default composeAuthorTemplatePage\n"],"names":["Aglyn","buildAuthorPageNodes","resolveBuiltInPageLayoutId","composeScreenNodes","composeNodesWithChrome","getScreen","collectSocialImageFacts","AUTHOR_PAGE_SCREEN_FIELD","AUTHOR_ENTRIES_SOURCE_SLUG","authorComposeContext","content","address","author","authorName","slug","pager","contentAuthorPaginationLinks","page","totalPages","cardImages","seoImage","image","tokens","contentAuthorTokens","entryCount","totalEntries","name","String","prevUrl","nextUrl","collection","routeless","entries","categories","composeAuthorTemplatePage","options","hostId","host","screenId","trim","templateRes","allowTemplate","screen","card","nodes","timeZone","socialImages","expandContentAuthorProfile","collected","error","console","composeAuthorFallbackPage","layoutId","screenNodes","hasEntries","length","perPage"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAC5C,OAAOC,0BAA0B,yBAAqB;AACtD,SAASC,0BAA0B,QAAQ,4BAAwB;AACnE,OAAOC,sBACLC,sBAAsB,QACjB,4BAAwB;AAE/B,OAAOC,eAAe,kBAAc;AACpC,SAASC,uBAAuB,QAAQ,0BAAsB;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,MAAMC,2BAA2B,iBAAyB;AAEjE;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,6BAA6B,aAAY;AAetD,2DAA2D,GAC3D,SAASC,qBAAqBC,OAAsB;QAenCA,iBAA0BA;IAdzC,MAAMC,UAAUD,QAAQE,MAAM,GAC1B;QAAEA,QAAQF,QAAQE,MAAM;IAAC,IACzB;QAAEC,YAAYH,QAAQI,IAAI;IAAC;IAC/B,MAAMC,QAAQf,MAAMgB,4BAA4B,CAAC,aAC5CL;QACHM,MAAMP,QAAQO,IAAI;QAClBC,YAAYR,QAAQQ,UAAU;;IAEhC,OAAO;QACL;;;;KAIC,GACDC,YAAY;aAACT,kBAAAA,QAAQE,MAAM,qBAAdF,gBAAgBU,QAAQ;aAAEV,mBAAAA,QAAQE,MAAM,qBAAdF,iBAAgBW,KAAK;SAAC;QAC7DC,QAAQ,aACHtB,MAAMuB,mBAAmB,CAACb,QAAQE,MAAM,EAAE;YAC3CY,YAAYd,QAAQe,YAAY;QAClC;YACA,uEAAuE;YACvE,kEAAkE;YAClE,eAAef,QAAQgB,IAAI;YAC3B,yEAAyE;YACzE,uEAAuE;YACvE,sEAAsE;YACtE,wEAAwE;YACxE,mDAAmD;YACnD,mBA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OlC,QAAQE,MAAM;WAC1D+B,KAAKK,SAAS;IAErB,EAAE,OAAOC,OAAO;QACdC,QAAQD,KAAK,CAAC,sCAAsCA;QACpD,OAAO;IACT;AACF;AAEA;;;;;;;;;;;;CAYC,GACD,OAAO,eAAeE,0BAA0BhB,OAS/C;IACC,MAAM,EAAEC,MAAM,EAAEC,IAAI,EAAE3B,OAAO,EAAE,GAAGyB;IAClC,IAAI;QACF,MAAMiB,WAAW,MAAMlD,2BAA2B;YAAEkC;YAAQC;QAAK;QACjE,MAAM,EAAElB,UAAU,EAAEG,MAAM,EAAEQ,UAAU,EAAE,GAAGrB,qBAAqBC;QAChE,MAAMiC,OAAOrC,wBAAwBa;QACrC,MAAMyB,QAAQ,MAAMxC,uBAAuB,aACrC+B,QAAQU,QAAQ,GAAG;YAAEA,UAAUV,QAAQU,QAAQ;QAAC,IAAI,CAAC;YACzDT;YACAgB;YACAN,cAAcH,KAAKG,YAAY;YAC/BO,aAAapD,qBAAqB;gBAChCa,MAAMJ,QAAQI,IAAI;gBAClBY,MAAMhB,QAAQgB,IAAI;gBAClBd,QAAQF,QAAQE,MAAM;gBACtB0C,YAAY5C,QAAQsB,OAAO,CAACuB,MAAM,GAAG;gBACrCtC,MAAMP,QAAQO,IAAI;gBAClBuC,SAAS9C,QAAQ8C,OAAO;gBACxBtC,YAAYR,QAAQQ,UAAU;YAChC;YACAI;YACAQ;YACAO,MAAMA;;QAER,OAAOO,QAAQ;YAAEF,QAAQ;YAAME;WAAUD,KAAKK,SAAS,MAAO;IAChE,EAAE,OAAOC,OAAO;QACdC,QAAQD,KAAK,CAAC,kCAAkCA;QAChD,OAAO;IACT;AACF;AAEA,eAAef,0BAAyB"}
1
+ {"version":3,"sources":["../../../../../../libs/tenant/runtime/src/lib/compose-author-page.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 * as Aglyn from '@aglyn/aglyn/server'\nimport buildAuthorPageNodes from './author-page-nodes'\nimport { resolveBuiltInPageLayoutId } from './built-in-page-layout'\nimport composeScreenNodes, {\n composeNodesWithChrome,\n} from './compose-screen-nodes'\nimport type { AuthorContent } from './get-author-content'\nimport getScreen from './get-screen'\nimport { collectSocialImageFacts } from './social-image-facts'\n\n/**\n * The host field naming the screen every author page renders through\n * (AGL-2518).\n *\n * ## Why the HOST and not the author\n *\n * A collection names its own list and entry templates because a site\n * legitimately designs its changelog differently from its blog. Author pages\n * are not like that: they are one page shape repeated per person, and letting\n * each author record name its own template would mean a masthead where the\n * design changes as the reader clicks between colleagues — plus a template\n * picker on a form whose whole subject is a byline.\n *\n * ## Why a SCREEN and not a layout\n *\n * The opposite call from `builtInPageLayoutId` (AGL-2513), and for the reason\n * that comment gives in reverse. Search results have no design worth\n * authoring — the platform composes the body and the site only chooses the\n * chrome around it. An author page has: a portrait, a bio, a role, links, and\n * a listing whose cards a designer wants to match the blog's. That is a page,\n * so the author designs it as one, with `{{author.*}}` tokens and the same\n * Collection entries block every list template uses.\n *\n * Unset is the ordinary case rather than a misconfiguration, and it renders\n * the built-in body — bylines link to this address, so it must always answer.\n */\nexport const AUTHOR_PAGE_SCREEN_FIELD = 'authorScreenId' as const\n\n/**\n * The pseudo-collection an author page's entries block resolves against.\n *\n * The compose pipeline keys entry sources by collection slug, and this page\n * has no single collection — it mixes them. Its entries are handed over\n * already in hand (`ComposeCollectionContext.entries`), which is a path that\n * never touches Firestore, so the key only has to be a name that no real\n * collection can take: a collection slug is a URL segment, and this is not a\n * legal one.\n *\n * It never reaches a URL. Every entry on this page carries its OWN\n * `collectionSlug` out of the read that found it, and `collectionEntryTokens`\n * prefers that — which is the whole reason a cross-collection listing can\n * build correct `entry.url`s at all.\n */\nexport const AUTHOR_ENTRIES_SOURCE_SLUG = '__author__'\n\n/** What the author route renders. */\nexport interface ComposedAuthorPage {\n /** The template screen doc, when one is designated; null for the built-in. */\n screen: Record<string, any> | null\n nodes: Record<string, any>\n /**\n * The current pair of each picture the head's card may name (AGL-2850): the\n * author's share card, then their portrait. Read in the composition's\n * batch, and absent when it answered for neither.\n */\n socialImageFacts?: Aglyn.SocialImageAssetFacts\n}\n\n/** The tokens and entry context both compose paths share. */\nfunction authorComposeContext(content: AuthorContent) {\n const address = content.author\n ? { author: content.author }\n : { authorName: content.slug }\n const pager = Aglyn.contentAuthorPaginationLinks({\n ...address,\n page: content.page,\n totalPages: content.totalPages,\n })\n return {\n /**\n * The pictures the head builds the card from, in its order: the share\n * card, then the portrait (AGL-2850). The author head reads the record\n * alone and never the site default, so the host's image is not one.\n */\n cardImages: [content.author?.seoImage, content.author?.image],\n tokens: {\n ...Aglyn.contentAuthorTokens(content.author, {\n entryCount: content.totalEntries,\n }),\n // The byline falls back to the raw segment for an unknown author, so a\n // heading bound to `{{author.name}}` prints something either way.\n 'author.name': content.name,\n // Named `pagination.*` rather than `author.page*`, so a designer who has\n // already built a pager on a collection list template rebuilds nothing\n // here — and so the two pagers cannot drift into two spellings of the\n // same four values. The edges are the empty string, which is what makes\n // an unconditional binding correct on page 1 of 1.\n 'pagination.page': String(pager.page),\n 'pagination.totalPages': String(pager.totalPages),\n 'pagination.prevUrl': pager.prevUrl,\n 'pagination.nextUrl': pager.nextUrl,\n } as Record<string, string>,\n collection: {\n slug: AUTHOR_ENTRIES_SOURCE_SLUG,\n // The slug above is a key, not an address (AGL-2524) — so a block that\n // would build a URL out of it resolves nothing instead.\n routeless: true,\n // Already narrowed to this author AND to this page's window by the\n // loader, for the reason the category route states: a page count\n // computed over the whole set advertises pages that render empty.\n entries: content.entries,\n categories: content.categories,\n page: content.page,\n },\n }\n}\n\n/**\n * An author page composed through the screen the host designated (AGL-2518).\n *\n * The `composeCollectionTemplatePage` shape: the screen goes through the\n * NORMAL published pipeline — theme, shared layout, reusable components,\n * Collection entries blocks — with `{{author.*}}` and `{{pagination.*}}`\n * substituted and Author Profile blocks filled from the record.\n *\n * Returns null when no screen is designated, or when the designated one has\n * been deleted, so the caller falls through to the built-in body rather than\n * serving a 404 for a page a byline links to.\n */\nexport async function composeAuthorTemplatePage(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237); UTC when a site has not\n * named one. Resolved once by the caller that holds the org and the host.\n */\n timeZone?: string\n host: any\n content: AuthorContent\n}): Promise<ComposedAuthorPage | null> {\n const { hostId, host, content } = options\n const screenId = String(host?.[AUTHOR_PAGE_SCREEN_FIELD] ?? '').trim()\n if (!screenId) return null\n try {\n // `allowTemplate`, exactly as a collection template is read: the screen is\n // deliberately not servable at an address of its own, and this is the\n // composition it exists for.\n const templateRes = await getScreen({\n hostId,\n screenId,\n allowTemplate: true,\n })\n if (!templateRes.screen) return null\n const { cardImages, tokens, collection } = authorComposeContext(content)\n const card = collectSocialImageFacts(cardImages)\n const nodes = await composeScreenNodes({\n // The site's zone (AGL-3237). This is the TEMPLATE path, which\n // composes through `composeScreenNodes` rather than\n // `composeNodesWithChrome` — and that difference is why the first two\n // passes at this fix reached every page except the one the bug was\n // reported on.\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n screenId,\n screen: templateRes.screen,\n tokens,\n collection,\n socialImages: card.socialImages,\n // The designated screen's host variables, and its layout's, fill in\n // from this site, as the built-in author page's already do (AGL-2883).\n host: host as Aglyn.HostTokenSource,\n // Named as the author template it is if the page review holds it\n // (AGL-3374); without it the site's built-in author page serves.\n page: {\n template: {\n role: 'entry',\n route: '/author/:slug',\n collectionName: 'Authors',\n entryPath: `/author/${content.slug}`,\n fallback: 'built-in-design',\n },\n },\n })\n if (!nodes) return null\n /*\n The screen document travels UNCHANGED, and deliberately carries no\n composed SEO.\n\n A collection template composes the entry's title and cover into\n `screen.seo` because `page.tsx` reads that on its way to the head. An\n author page does not take that path: its head branch has the author\n RECORD in hand and builds the title, description and portrait from it\n directly, before the screen branch is ever reached. Writing a second,\n unread copy here would be a value that looks authoritative, is dead, and\n goes stale the first time the head's rule changes — which is how a\n template's stored title came to name every post in a collection\n (AGL-1345).\n */\n return {\n screen: templateRes.screen as Record<string, any>,\n nodes: Aglyn.expandContentAuthorProfile(nodes, content.author),\n ...card.collected(),\n }\n } catch (error) {\n console.error('author template composition failed', error)\n return null\n }\n}\n\n/**\n * The built-in author page (AGL-2518) — the body this file's own nodes build,\n * grafted into the site's shared layout so it carries the same header, nav and\n * footer as the posts it links to.\n *\n * Which layout is the host's to choose (`resolveBuiltInPageLayoutId`), shared\n * with site search so the two platform-built pages of a site cannot end up in\n * different chrome.\n *\n * Fail-open to `null`, and the route then renders the body with no chrome at\n * all. A person's page must not be the page that 500s because a layout was\n * deleted.\n */\nexport async function composeAuthorFallbackPage(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237); UTC when a site has not\n * named one. Resolved once by the caller that holds the org and the host.\n */\n timeZone?: string\n host: any\n content: AuthorContent\n}): Promise<ComposedAuthorPage | null> {\n const { hostId, host, content } = options\n try {\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host })\n const { cardImages, tokens, collection } = authorComposeContext(content)\n const card = collectSocialImageFacts(cardImages)\n const nodes = await composeNodesWithChrome({\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n layoutId,\n socialImages: card.socialImages,\n screenNodes: buildAuthorPageNodes({\n slug: content.slug,\n name: content.name,\n author: content.author,\n hasEntries: content.entries.length > 0,\n page: content.page,\n perPage: content.perPage,\n totalPages: content.totalPages,\n }),\n tokens,\n collection,\n host: host as Aglyn.HostTokenSource,\n })\n return nodes ? { screen: null, nodes, ...card.collected() } : null\n } catch (error) {\n console.error('author page composition failed', error)\n return null\n }\n}\n\nexport default composeAuthorTemplatePage\n"],"names":["Aglyn","buildAuthorPageNodes","resolveBuiltInPageLayoutId","composeScreenNodes","composeNodesWithChrome","getScreen","collectSocialImageFacts","AUTHOR_PAGE_SCREEN_FIELD","AUTHOR_ENTRIES_SOURCE_SLUG","authorComposeContext","content","address","author","authorName","slug","pager","contentAuthorPaginationLinks","page","totalPages","cardImages","seoImage","image","tokens","contentAuthorTokens","entryCount","totalEntries","name","String","prevUrl","nextUrl","collection","routeless","entries","categories","composeAuthorTemplatePage","options","hostId","host","screenId","trim","templateRes","allowTemplate","screen","card","nodes","timeZone","socialImages","template","role","route","collectionName","entryPath","fallback","expandContentAuthorProfile","collected","error","console","composeAuthorFallbackPage","layoutId","screenNodes","hasEntries","length","perPage"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAC5C,OAAOC,0BAA0B,yBAAqB;AACtD,SAASC,0BAA0B,QAAQ,4BAAwB;AACnE,OAAOC,sBACLC,sBAAsB,QACjB,4BAAwB;AAE/B,OAAOC,eAAe,kBAAc;AACpC,SAASC,uBAAuB,QAAQ,0BAAsB;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,MAAMC,2BAA2B,iBAAyB;AAEjE;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMC,6BAA6B,aAAY;AAetD,2DAA2D,GAC3D,SAASC,qBAAqBC,OAAsB;QAenCA,iBAA0BA;IAdzC,MAAMC,UAAUD,QAAQE,MAAM,GAC1B;QAAEA,QAAQF,QAAQE,MAAM;IAAC,IACzB;QAAEC,YAAYH,QAAQI,IAAI;IAAC;IAC/B,MAAMC,QAAQf,MAAMgB,4BAA4B,CAAC,aAC5CL;QACHM,MAAMP,QAAQO,IAAI;QAClBC,YAAYR,QAAQQ,UAAU;;IAEhC,OAAO;QACL;;;;KAIC,GACDC,YAAY;aAACT,kBAAAA,QAAQE,MAAM,qBAAdF,gBAAgBU,QAAQ;aAAEV,mBAAAA,QAAQE,MAAM,qBAAdF,iBA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C,SAASpD,QAAQoD,OAAO;gBACxB5C,YAAYR,QAAQQ,UAAU;YAChC;YACAI;YACAQ;YACAO,MAAMA;;QAER,OAAOO,QAAQ;YAAEF,QAAQ;YAAME;WAAUD,KAAKW,SAAS,MAAO;IAChE,EAAE,OAAOC,OAAO;QACdC,QAAQD,KAAK,CAAC,kCAAkCA;QAChD,OAAO;IACT;AACF;AAEA,eAAerB,0BAAyB"}
@@ -126,6 +126,18 @@ import { collectSocialImageFacts } from "./social-image-facts.js";
126
126
  // layout's — fill in as they do on every other page (AGL-2883).
127
127
  host: options.host,
128
128
  tokens,
129
+ // What this template is, for naming it if the page review holds it
130
+ // (AGL-3374): its route pattern, its collection and the entry shown.
131
+ // Without it the route falls back to the built-in design.
132
+ page: {
133
+ template: {
134
+ role: kind,
135
+ route: kind === 'entry' ? `/${collection.slug}/:slug` : `/${collection.slug}`,
136
+ collectionName: collection.displayName || collection.slug,
137
+ entryPath: entry ? `/${collection.slug}/${entry.slug}` : null,
138
+ fallback: 'built-in-design'
139
+ }
140
+ },
129
141
  // List pages hand their already-fetched entries to the Collection
130
142
  // entries block; entry pages carry the routed entry (AGL-582, Related
131
143
  // posts) and let blocks fetch entry lists on demand (e.g. a "More
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/tenant/runtime/src/lib/compose-collection-page.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 * as Aglyn from '@aglyn/aglyn/server'\nimport buildCollectionFallbackNodes from './collection-fallback-nodes'\nimport composeScreenNodes, {\n composeNodesWithChrome,\n} from './compose-screen-nodes'\nimport { resolveBuiltInPageLayoutId } from './built-in-page-layout'\nimport type { CollectionContent } from './get-collection-content'\nimport getScreen from './get-screen'\nimport { collectSocialImageFacts } from './social-image-facts'\n\ntype CollectionDoc = NonNullable<CollectionContent['collection']>\n\n/**\n * Which template screen a collection route renders through (AGL-551):\n * `/{collection}` uses `listScreenId`, `/{collection}/{entry}` uses\n * `entryScreenId` — falling back to the legacy AGL-105 `templateScreenId`\n * so existing blogs keep rendering. `undefined` means no template is set\n * and the designed built-in fallback applies.\n */\nexport function resolveCollectionTemplateScreenId(\n collection: Pick<\n CollectionDoc,\n 'listScreenId' | 'entryScreenId' | 'templateScreenId'\n >,\n kind: 'list' | 'entry',\n): string | undefined {\n if (kind === 'list') return collection.listScreenId || undefined\n return collection.entryScreenId || collection.templateScreenId || undefined\n}\n\n/**\n * Page-level `{{collection.*}}` tokens for template screens (AGL-551), plus\n * the routed category (AGL-1321) so a list template can name what it is\n * showing — \"Guides\" rather than a heading that says \"Blog\" on every filtered\n * URL. Both category tokens resolve to the empty string on the unfiltered\n * listing, which is what makes them safe to bind unconditionally.\n *\n * `{{pagination.*}}` follows the same design (AGL-1386). One static list\n * screen serves the bare listing, every `/page/{n}` and every\n * `/category/{slug}`, so a hand-built pager on it renders identically on all\n * of them: \"Older →\" on a category that has one page, pointing at a URL that\n * dropped the filter. The URLs come from `collectionPaginationLinks`, which\n * builds them through the shared listing-URL builder (so they carry the\n * category) and resolves the EDGES TO THE EMPTY STRING — no previous page,\n * no `prevUrl`. There is no runtime conditional to hide a link with (the\n * `condition` field on nodes is editor-side field visibility, not a render\n * gate), so the empty string is what makes an unconditional binding correct\n * on every route: a link whose href does not resolve renders as an inert\n * placeholder of the same element (AGL-1268/1357).\n *\n * This SURFACES what the platform already computes — the built-in fallback\n * pager reads the same function, so the two cannot drift.\n */\nexport function collectionTokens(\n collection: Pick<CollectionDoc, 'displayName' | 'slug'>,\n category?: CollectionContent['category'],\n pagination?: CollectionContent['pagination'],\n): Record<string, string> {\n // An unpaginated listing is page 1 of 1 — both URLs empty, which reads as\n // the honest \"nowhere to page to\" rather than a broken link.\n const pager = Aglyn.collectionPaginationLinks({\n collectionSlug: collection.slug,\n ...(category?.slug ? { categorySlug: category.slug } : {}),\n page: pagination?.page,\n ...(pagination?.totalPages === undefined\n ? {}\n : { totalPages: pagination.totalPages }),\n // Only a LISTING has cursors, so passing them is also what tells the\n // builder this is a listing and not an inert entry route (AGL-3219).\n ...(pagination\n ? {\n nextCursor: pagination.nextCursor ?? '',\n prevCursor: pagination.prevCursor ?? '',\n }\n : {}),\n })\n return {\n 'collection.name': collection.displayName,\n 'collection.slug': collection.slug,\n 'collection.category': category?.name ?? '',\n 'collection.categorySlug': category?.slug ?? '',\n 'pagination.page': String(pager.page),\n 'pagination.totalPages': String(pager.totalPages),\n 'pagination.prevUrl': pager.prevUrl,\n 'pagination.nextUrl': pager.nextUrl,\n }\n}\n\nexport interface ComposedCollectionPage {\n /** Template screen doc with the entry/collection SEO merged in. */\n screen: Record<string, any>\n nodes: Record<string, any>\n /**\n * The current pair of each asset the head's card may name (AGL-2850): the\n * entry's cover, the template's image, the site default. Read in the\n * composition's batch, and absent when it answered for none of them.\n */\n socialImageFacts?: Aglyn.SocialImageAssetFacts\n}\n\n/**\n * Renders a collection route through its designated template screen\n * (AGL-551), the same mechanism as commerce PDP/collection templates: the\n * screen composes through the NORMAL published pipeline — theme, shared\n * layout, reusable components — with `{{entry.*}}`/`{{collection.*}}`\n * tokens substituted and Collection entries blocks expanded. Returns null\n * when no template is designated (or it fails to compose) so the caller\n * falls through to the designed built-in fallback.\n */\nexport async function composeCollectionTemplatePage(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237); UTC when a site has not\n * named one. Resolved once by the caller that holds the org and the host.\n */\n timeZone?: string\n content: CollectionContent\n /**\n * The site, whose default card the head falls back to after the entry's\n * cover and the template's image (AGL-2850). Its document is read in this\n * page's batch with theirs.\n */\n host?: Aglyn.AglynHost | null\n}): Promise<ComposedCollectionPage | null> {\n const { hostId, content } = options\n const collection = content.collection\n if (!collection) return null\n const kind = content.entry ? 'entry' : 'list'\n const screenId = resolveCollectionTemplateScreenId(collection, kind)\n if (!screenId) return null\n\n // The one read that WANTS a template document (AGL-1400): this is the\n // composition it exists for, with `{{entry.*}}` substituted against the\n // routed entry. Every path-resolving caller leaves the flag off and gets the\n // 404 a template deserves at an address of its own.\n const templateRes = await getScreen({ hostId, screenId, allowTemplate: true })\n if (!templateRes.screen) return null\n\n const entry = content.entry\n const tokens = entry\n ? {\n ...collectionTokens(collection),\n // Category names resolve against the collection's taxonomy\n // (AGL-582): `categoryId` lookup first, legacy string fallback.\n ...Aglyn.collectionEntryTokens(\n entry,\n collection.slug,\n collection.categories,\n options.timeZone,\n ),\n }\n : collectionTokens(collection, content.category, content.pagination)\n // The head's card on this page, in its order: the entry's cover, the\n // template's own image, then the site default (AGL-2850).\n const card = collectSocialImageFacts([\n entry?.coverImage,\n (templateRes.screen as any).seo?.image,\n options.host?.seo?.image,\n ])\n const nodes = await composeScreenNodes({\n // The site's zone (AGL-3237). This is the TEMPLATE path, which\n // composes through `composeScreenNodes` rather than\n // `composeNodesWithChrome` — and that difference is why the first two\n // passes at this fix reached every page except the one the bug was\n // reported on.\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n screenId,\n screen: templateRes.screen,\n socialImages: card.socialImages,\n // The site the template renders for, so its host variables — and its\n // layout's — fill in as they do on every other page (AGL-2883).\n host: options.host,\n tokens,\n // List pages hand their already-fetched entries to the Collection\n // entries block; entry pages carry the routed entry (AGL-582, Related\n // posts) and let blocks fetch entry lists on demand (e.g. a \"More\n // posts\" section on the article template). The category taxonomy\n // rides along so `{{entry.category}}` resolves inside the blocks.\n collection: entry\n ? { slug: collection.slug, entry, categories: collection.categories }\n : {\n slug: collection.slug,\n // Already filtered to the routed category (AGL-1321) — the block\n // repeats what the ROUTE resolved, so a designer-pinned\n // `filterCategory` on the block narrows it further rather than\n // fighting it.\n entries: content.entries,\n categories: collection.categories,\n ...(content.pagination?.page\n ? { page: content.pagination.page }\n : {}),\n ...(content.category ? { categorySlug: content.category.slug } : {}),\n // The read's own bound (AGL-1516), which has to travel WITH the\n // filtered entries above: once `content.entries` has been narrowed\n // to a category, nothing downstream can tell a complete read from a\n // truncated one by counting it.\n ...(content.entriesReachedBound\n ? { entriesReachedBound: true }\n : {}),\n // Where those entries start (AGL-3213): a listing page past the\n // cached read's bound holds its own window, not the collection\n // from the top, and the block has to window from the same origin.\n ...(content.pagination?.windowStart\n ? { windowStart: content.pagination.windowStart }\n : {}),\n },\n })\n if (!nodes) return null\n\n const screenSeo = (templateRes.screen as any).seo ?? {}\n const seo = entry\n ? // Entry metadata drives the head (AGL-117 merge; AGL-582 overrides).\n {\n ...screenSeo,\n title: entry.seoTitle || entry.title,\n description: entry.seoDescription || entry.excerpt || undefined,\n // The image and its companions move as ONE group (AGL-2417). The\n // spread above carries the SCREEN's `imageWidth`/`imageHeight`/\n // `imageAlt`, so an entry that supplies its own cover was describing\n // it with the screen default's size and — once alts existed — with\n // the screen default's DESCRIPTION: a sentence about a picture this\n // card does not show, delivered to the reader least able to check.\n // When the entry wins, its own companions win with it.\n ...(entry.coverImage\n ? {\n image: entry.coverImage,\n imageWidth: undefined,\n imageHeight: undefined,\n imageAlt: entry.coverImageAlt || undefined,\n }\n : { image: screenSeo.image || undefined }),\n }\n : // A LIST passes its screen's own SEO through UNTOUCHED (AGL-1345).\n //\n // This used to default `title` to `collection.displayName`, which reads\n // like a harmless fallback and is not: it made an authored title\n // indistinguishable from a generated one by the time the head was built.\n // The title rule (AGL-1341) turns on exactly that distinction — an\n // authored title renders VERBATIM, a name joins the site title — so a\n // consumer reading this could only choose between dropping the site\n // title off every untitled list (\"Changelog\") or ignoring the author's\n // title on every titled one (\"Changelog – Acme\" over the sentence they\n // wrote). The collection name is still the fallback; it just belongs to\n // the title resolver, as the page's `name`, alongside every other\n // surface's fallback rather than baked into stored SEO here.\n screenSeo\n return {\n screen: { ...(templateRes.screen as any), seo },\n nodes,\n ...card.collected(),\n }\n}\n\n/**\n * The designed built-in rendering (AGL-551): when a collection has no\n * template screen, its routes still compose through the site's theme and\n * the host's default shared layout (the home screen's layout) instead of\n * the old unthemed article. Fail-open — any error returns null and the\n * caller keeps the legacy plain rendering.\n */\nexport async function composeCollectionFallbackPage(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237); UTC when a site has not\n * named one. Resolved once by the caller that holds the org and the host.\n */\n timeZone?: string\n host: Aglyn.AglynHost\n content: CollectionContent\n}): Promise<Omit<ComposedCollectionPage, 'screen'> | null> {\n const { hostId, host, content } = options\n const collection = content.collection\n if (!collection) return null\n try {\n // The layout for a page the platform composed rather than the author\n // (AGL-2513). Still the home screen's layout by default — the rule this\n // branch has always followed — but the host can now name a different one,\n // and site search reads the same setting so the two built-in pages of a\n // site cannot end up in different chrome.\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host })\n const screenNodes = buildCollectionFallbackNodes({\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n collection,\n entries: content.entries,\n entry: content.entry,\n pagination: content.pagination,\n category: content.category,\n // The cover resolves through `resolveMediaSrc` (AGL-1407), and an\n // org-scoped reference has to name the site asking or a site-restricted\n // asset will not serve.\n hostId,\n })\n // The head's card on a page with no template: the entry's cover, then the\n // site default (AGL-2850).\n const card = collectSocialImageFacts([\n content.entry?.coverImage,\n host?.seo?.image,\n ])\n const nodes = await composeNodesWithChrome({\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n layoutId,\n screenNodes,\n socialImages: card.socialImages,\n // The layout's host variables fill in from this site (AGL-2883).\n host,\n // Entry routes resolve with an EMPTY entries list (the loader only\n // fetched the one entry), so hand the routed entry over and let the\n // Related posts block fetch the list on demand (AGL-582); list\n // routes keep their already-fetched entries. Categories ride along\n // for `categoryId` → name resolution.\n collection: content.entry\n ? {\n slug: collection.slug,\n entry: content.entry,\n categories: collection.categories,\n }\n : {\n slug: collection.slug,\n entries: content.entries,\n categories: collection.categories,\n ...(content.pagination?.page\n ? { page: content.pagination.page }\n : {}),\n ...(content.category\n ? { categorySlug: content.category.slug }\n : {}),\n // Same fact, same reason as the template path above (AGL-1516).\n ...(content.entriesReachedBound\n ? { entriesReachedBound: true }\n : {}),\n // Same window, same reason as the template path above (AGL-3213).\n ...(content.pagination?.windowStart\n ? { windowStart: content.pagination.windowStart }\n : {}),\n },\n })\n return nodes ? { nodes, ...card.collected() } : null\n } catch (error) {\n console.error(error)\n return null\n }\n}\n\nexport default composeCollectionTemplatePage\n"],"names":["Aglyn","buildCollectionFallbackNodes","composeScreenNodes","composeNodesWithChrome","resolveBuiltInPageLayoutId","getScreen","collectSocialImageFacts","resolveCollectionTemplateScreenId","collection","kind","listScreenId","undefined","entryScreenId","templateScreenId","collectionTokens","category","pagination","pager","collectionPaginationLinks","collectionSlug","slug","categorySlug","page","totalPages","nextCursor","prevCursor","displayName","name","String","prevUrl","nextUrl","composeCollectionTemplatePage","options","content","hostId","entry","screenId","templateRes","allowTemplate","screen","tokens","collectionEntryTokens","categories","timeZone","card","coverImage","seo","image","host","nodes","socialImages","entries","entriesReachedBound","windowStart","screenSeo","title","seoTitle","description","seoDescription","excerpt","imageWidth","imageHeight","imageAlt","coverImageAlt","collected","composeCollectionFallbackPage","layoutId","screenNodes","error","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAC5C,OAAOC,kCAAkC,iCAA6B;AACtE,OAAOC,sBACLC,sBAAsB,QACjB,4BAAwB;AAC/B,SAASC,0BAA0B,QAAQ,4BAAwB;AAEnE,OAAOC,eAAe,kBAAc;AACpC,SAASC,uBAAuB,QAAQ,0BAAsB;AAI9D;;;;;;CAMC,GACD,OAAO,SAASC,kCACdC,UAGC,EACDC,IAAsB;IAEtB,IAAIA,SAAS,QAAQ,OAAOD,WAAWE,YAAY,IAAIC;IACvD,OAAOH,WAAWI,aAAa,I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AO;gBACxBT,YAAYlC,WAAWkC,UAAU;eAC7BT,EAAAA,sBAAAA,QAAQjB,UAAU,qBAAlBiB,oBAAoBX,IAAI,IACxB;gBAAEA,MAAMW,QAAQjB,UAAU,CAACM,IAAI;YAAC,IAChC,CAAC,GACDW,QAAQlB,QAAQ,GAChB;gBAAEM,cAAcY,QAAQlB,QAAQ,CAACK,IAAI;YAAC,IACtC,CAAC,GAEDa,QAAQmB,mBAAmB,GAC3B;gBAAEA,qBAAqB;YAAK,IAC5B,CAAC,GAEDnB,EAAAA,uBAAAA,QAAQjB,UAAU,qBAAlBiB,qBAAoBoB,WAAW,IAC/B;gBAAEA,aAAapB,QAAQjB,UAAU,CAACqC,WAAW;YAAC,IAC9C,CAAC;;QAGb,OAAOJ,QAAQ;YAAEA;WAAUL,KAAKoB,SAAS,MAAO;IAClD,EAAE,OAAOI,OAAO;QACdC,QAAQD,KAAK,CAACA;QACd,OAAO;IACT;AACF;AAEA,eAAerC,8BAA6B"}
1
+ {"version":3,"sources":["../../../../../../libs/tenant/runtime/src/lib/compose-collection-page.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 * as Aglyn from '@aglyn/aglyn/server'\nimport buildCollectionFallbackNodes from './collection-fallback-nodes'\nimport composeScreenNodes, {\n composeNodesWithChrome,\n} from './compose-screen-nodes'\nimport { resolveBuiltInPageLayoutId } from './built-in-page-layout'\nimport type { CollectionContent } from './get-collection-content'\nimport getScreen from './get-screen'\nimport { collectSocialImageFacts } from './social-image-facts'\n\ntype CollectionDoc = NonNullable<CollectionContent['collection']>\n\n/**\n * Which template screen a collection route renders through (AGL-551):\n * `/{collection}` uses `listScreenId`, `/{collection}/{entry}` uses\n * `entryScreenId` — falling back to the legacy AGL-105 `templateScreenId`\n * so existing blogs keep rendering. `undefined` means no template is set\n * and the designed built-in fallback applies.\n */\nexport function resolveCollectionTemplateScreenId(\n collection: Pick<\n CollectionDoc,\n 'listScreenId' | 'entryScreenId' | 'templateScreenId'\n >,\n kind: 'list' | 'entry',\n): string | undefined {\n if (kind === 'list') return collection.listScreenId || undefined\n return collection.entryScreenId || collection.templateScreenId || undefined\n}\n\n/**\n * Page-level `{{collection.*}}` tokens for template screens (AGL-551), plus\n * the routed category (AGL-1321) so a list template can name what it is\n * showing — \"Guides\" rather than a heading that says \"Blog\" on every filtered\n * URL. Both category tokens resolve to the empty string on the unfiltered\n * listing, which is what makes them safe to bind unconditionally.\n *\n * `{{pagination.*}}` follows the same design (AGL-1386). One static list\n * screen serves the bare listing, every `/page/{n}` and every\n * `/category/{slug}`, so a hand-built pager on it renders identically on all\n * of them: \"Older →\" on a category that has one page, pointing at a URL that\n * dropped the filter. The URLs come from `collectionPaginationLinks`, which\n * builds them through the shared listing-URL builder (so they carry the\n * category) and resolves the EDGES TO THE EMPTY STRING — no previous page,\n * no `prevUrl`. There is no runtime conditional to hide a link with (the\n * `condition` field on nodes is editor-side field visibility, not a render\n * gate), so the empty string is what makes an unconditional binding correct\n * on every route: a link whose href does not resolve renders as an inert\n * placeholder of the same element (AGL-1268/1357).\n *\n * This SURFACES what the platform already computes — the built-in fallback\n * pager reads the same function, so the two cannot drift.\n */\nexport function collectionTokens(\n collection: Pick<CollectionDoc, 'displayName' | 'slug'>,\n category?: CollectionContent['category'],\n pagination?: CollectionContent['pagination'],\n): Record<string, string> {\n // An unpaginated listing is page 1 of 1 — both URLs empty, which reads as\n // the honest \"nowhere to page to\" rather than a broken link.\n const pager = Aglyn.collectionPaginationLinks({\n collectionSlug: collection.slug,\n ...(category?.slug ? { categorySlug: category.slug } : {}),\n page: pagination?.page,\n ...(pagination?.totalPages === undefined\n ? {}\n : { totalPages: pagination.totalPages }),\n // Only a LISTING has cursors, so passing them is also what tells the\n // builder this is a listing and not an inert entry route (AGL-3219).\n ...(pagination\n ? {\n nextCursor: pagination.nextCursor ?? '',\n prevCursor: pagination.prevCursor ?? '',\n }\n : {}),\n })\n return {\n 'collection.name': collection.displayName,\n 'collection.slug': collection.slug,\n 'collection.category': category?.name ?? '',\n 'collection.categorySlug': category?.slug ?? '',\n 'pagination.page': String(pager.page),\n 'pagination.totalPages': String(pager.totalPages),\n 'pagination.prevUrl': pager.prevUrl,\n 'pagination.nextUrl': pager.nextUrl,\n }\n}\n\nexport interface ComposedCollectionPage {\n /** Template screen doc with the entry/collection SEO merged in. */\n screen: Record<string, any>\n nodes: Record<string, any>\n /**\n * The current pair of each asset the head's card may name (AGL-2850): the\n * entry's cover, the template's image, the site default. Read in the\n * composition's batch, and absent when it answered for none of them.\n */\n socialImageFacts?: Aglyn.SocialImageAssetFacts\n}\n\n/**\n * Renders a collection route through its designated template screen\n * (AGL-551), the same mechanism as commerce PDP/collection templates: the\n * screen composes through the NORMAL published pipeline — theme, shared\n * layout, reusable components — with `{{entry.*}}`/`{{collection.*}}`\n * tokens substituted and Collection entries blocks expanded. Returns null\n * when no template is designated (or it fails to compose) so the caller\n * falls through to the designed built-in fallback.\n */\nexport async function composeCollectionTemplatePage(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237); UTC when a site has not\n * named one. Resolved once by the caller that holds the org and the host.\n */\n timeZone?: string\n content: CollectionContent\n /**\n * The site, whose default card the head falls back to after the entry's\n * cover and the template's image (AGL-2850). Its document is read in this\n * page's batch with theirs.\n */\n host?: Aglyn.AglynHost | null\n}): Promise<ComposedCollectionPage | null> {\n const { hostId, content } = options\n const collection = content.collection\n if (!collection) return null\n const kind = content.entry ? 'entry' : 'list'\n const screenId = resolveCollectionTemplateScreenId(collection, kind)\n if (!screenId) return null\n\n // The one read that WANTS a template document (AGL-1400): this is the\n // composition it exists for, with `{{entry.*}}` substituted against the\n // routed entry. Every path-resolving caller leaves the flag off and gets the\n // 404 a template deserves at an address of its own.\n const templateRes = await getScreen({ hostId, screenId, allowTemplate: true })\n if (!templateRes.screen) return null\n\n const entry = content.entry\n const tokens = entry\n ? {\n ...collectionTokens(collection),\n // Category names resolve against the collection's taxonomy\n // (AGL-582): `categoryId` lookup first, legacy string fallback.\n ...Aglyn.collectionEntryTokens(\n entry,\n collection.slug,\n collection.categories,\n options.timeZone,\n ),\n }\n : collectionTokens(collection, content.category, content.pagination)\n // The head's card on this page, in its order: the entry's cover, the\n // template's own image, then the site default (AGL-2850).\n const card = collectSocialImageFacts([\n entry?.coverImage,\n (templateRes.screen as any).seo?.image,\n options.host?.seo?.image,\n ])\n const nodes = await composeScreenNodes({\n // The site's zone (AGL-3237). This is the TEMPLATE path, which\n // composes through `composeScreenNodes` rather than\n // `composeNodesWithChrome` — and that difference is why the first two\n // passes at this fix reached every page except the one the bug was\n // reported on.\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n screenId,\n screen: templateRes.screen,\n socialImages: card.socialImages,\n // The site the template renders for, so its host variables — and its\n // layout's — fill in as they do on every other page (AGL-2883).\n host: options.host,\n tokens,\n // What this template is, for naming it if the page review holds it\n // (AGL-3374): its route pattern, its collection and the entry shown.\n // Without it the route falls back to the built-in design.\n page: {\n template: {\n role: kind,\n route: kind === 'entry' ? `/${collection.slug}/:slug` : `/${collection.slug}`,\n collectionName: collection.displayName || collection.slug,\n entryPath: entry ? `/${collection.slug}/${entry.slug}` : null,\n fallback: 'built-in-design',\n },\n },\n // List pages hand their already-fetched entries to the Collection\n // entries block; entry pages carry the routed entry (AGL-582, Related\n // posts) and let blocks fetch entry lists on demand (e.g. a \"More\n // posts\" section on the article template). The category taxonomy\n // rides along so `{{entry.category}}` resolves inside the blocks.\n collection: entry\n ? { slug: collection.slug, entry, categories: collection.categories }\n : {\n slug: collection.slug,\n // Already filtered to the routed category (AGL-1321) — the block\n // repeats what the ROUTE resolved, so a designer-pinned\n // `filterCategory` on the block narrows it further rather than\n // fighting it.\n entries: content.entries,\n categories: collection.categories,\n ...(content.pagination?.page\n ? { page: content.pagination.page }\n : {}),\n ...(content.category ? { categorySlug: content.category.slug } : {}),\n // The read's own bound (AGL-1516), which has to travel WITH the\n // filtered entries above: once `content.entries` has been narrowed\n // to a category, nothing downstream can tell a complete read from a\n // truncated one by counting it.\n ...(content.entriesReachedBound\n ? { entriesReachedBound: true }\n : {}),\n // Where those entries start (AGL-3213): a listing page past the\n // cached read's bound holds its own window, not the collection\n // from the top, and the block has to window from the same origin.\n ...(content.pagination?.windowStart\n ? { windowStart: content.pagination.windowStart }\n : {}),\n },\n })\n if (!nodes) return null\n\n const screenSeo = (templateRes.screen as any).seo ?? {}\n const seo = entry\n ? // Entry metadata drives the head (AGL-117 merge; AGL-582 overrides).\n {\n ...screenSeo,\n title: entry.seoTitle || entry.title,\n description: entry.seoDescription || entry.excerpt || undefined,\n // The image and its companions move as ONE group (AGL-2417). The\n // spread above carries the SCREEN's `imageWidth`/`imageHeight`/\n // `imageAlt`, so an entry that supplies its own cover was describing\n // it with the screen default's size and — once alts existed — with\n // the screen default's DESCRIPTION: a sentence about a picture this\n // card does not show, delivered to the reader least able to check.\n // When the entry wins, its own companions win with it.\n ...(entry.coverImage\n ? {\n image: entry.coverImage,\n imageWidth: undefined,\n imageHeight: undefined,\n imageAlt: entry.coverImageAlt || undefined,\n }\n : { image: screenSeo.image || undefined }),\n }\n : // A LIST passes its screen's own SEO through UNTOUCHED (AGL-1345).\n //\n // This used to default `title` to `collection.displayName`, which reads\n // like a harmless fallback and is not: it made an authored title\n // indistinguishable from a generated one by the time the head was built.\n // The title rule (AGL-1341) turns on exactly that distinction — an\n // authored title renders VERBATIM, a name joins the site title — so a\n // consumer reading this could only choose between dropping the site\n // title off every untitled list (\"Changelog\") or ignoring the author's\n // title on every titled one (\"Changelog – Acme\" over the sentence they\n // wrote). The collection name is still the fallback; it just belongs to\n // the title resolver, as the page's `name`, alongside every other\n // surface's fallback rather than baked into stored SEO here.\n screenSeo\n return {\n screen: { ...(templateRes.screen as any), seo },\n nodes,\n ...card.collected(),\n }\n}\n\n/**\n * The designed built-in rendering (AGL-551): when a collection has no\n * template screen, its routes still compose through the site's theme and\n * the host's default shared layout (the home screen's layout) instead of\n * the old unthemed article. Fail-open — any error returns null and the\n * caller keeps the legacy plain rendering.\n */\nexport async function composeCollectionFallbackPage(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237); UTC when a site has not\n * named one. Resolved once by the caller that holds the org and the host.\n */\n timeZone?: string\n host: Aglyn.AglynHost\n content: CollectionContent\n}): Promise<Omit<ComposedCollectionPage, 'screen'> | null> {\n const { hostId, host, content } = options\n const collection = content.collection\n if (!collection) return null\n try {\n // The layout for a page the platform composed rather than the author\n // (AGL-2513). Still the home screen's layout by default — the rule this\n // branch has always followed — but the host can now name a different one,\n // and site search reads the same setting so the two built-in pages of a\n // site cannot end up in different chrome.\n const layoutId = await resolveBuiltInPageLayoutId({ hostId, host })\n const screenNodes = buildCollectionFallbackNodes({\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n collection,\n entries: content.entries,\n entry: content.entry,\n pagination: content.pagination,\n category: content.category,\n // The cover resolves through `resolveMediaSrc` (AGL-1407), and an\n // org-scoped reference has to name the site asking or a site-restricted\n // asset will not serve.\n hostId,\n })\n // The head's card on a page with no template: the entry's cover, then the\n // site default (AGL-2850).\n const card = collectSocialImageFacts([\n content.entry?.coverImage,\n host?.seo?.image,\n ])\n const nodes = await composeNodesWithChrome({\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n layoutId,\n screenNodes,\n socialImages: card.socialImages,\n // The layout's host variables fill in from this site (AGL-2883).\n host,\n // Entry routes resolve with an EMPTY entries list (the loader only\n // fetched the one entry), so hand the routed entry over and let the\n // Related posts block fetch the list on demand (AGL-582); list\n // routes keep their already-fetched entries. Categories ride along\n // for `categoryId` → name resolution.\n collection: content.entry\n ? {\n slug: collection.slug,\n entry: content.entry,\n categories: collection.categories,\n }\n : {\n slug: collection.slug,\n entries: content.entries,\n categories: collection.categories,\n ...(content.pagination?.page\n ? { page: content.pagination.page }\n : {}),\n ...(content.category\n ? { categorySlug: content.category.slug }\n : {}),\n // Same fact, same reason as the template path above (AGL-1516).\n ...(content.entriesReachedBound\n ? { entriesReachedBound: true }\n : {}),\n // Same window, same reason as the template path above (AGL-3213).\n ...(content.pagination?.windowStart\n ? { windowStart: content.pagination.windowStart }\n : {}),\n },\n })\n return nodes ? { nodes, ...card.collected() } : null\n } catch (error) {\n console.error(error)\n return null\n }\n}\n\nexport default composeCollectionTemplatePage\n"],"names":["Aglyn","buildCollectionFallbackNodes","composeScreenNodes","composeNodesWithChrome","resolveBuiltInPageLayoutId","getScreen","collectSocialImageFacts","resolveCollectionTemplateScreenId","collection","kind","listScreenId","undefined","entryScreenId","templateScreenId","collectionTokens","category","pagination","pager","collectionPaginationLinks","collectionSlug","slug","categorySlug","page","totalPages","nextCursor","prevCursor","displayName","name","String","prevUrl","nextUrl","composeCollectionTemplatePage","options","content","hostId","entry","screenId","templateRes","allowTemplate","screen","tokens","collectionEntryTokens","categories","timeZone","card","coverImage","seo","image","host","nodes","socialImages","template","role","route","collectionName","entryPath","fallback","entries","entriesReachedBound","windowStart","screenSeo","title","seoTitle","description","seoDescription","excerpt","imageWidth","imageHeight","imageAlt","coverImageAlt","collected","composeCollectionFallbackPage","layoutId","screenNodes","error","console"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAC5C,OAAOC,kCAAkC,iCAA6B;AACtE,OAAOC,sBACLC,sBAAsB,QACjB,4BAAwB;AAC/B,SAASC,0BAA0B,QAAQ,4BAAwB;AAEnE,OAAOC,eAAe,kBAAc;AACpC,SAASC,uBAAuB,QAAQ,0BAAsB;AAI9D;;;;;;CAMC,GACD,OAAO,SAASC,kCACdC,UAG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,yBAAAA,YAAAA,KAAMF,GAAG,qBAATE,UAAWD,KAAK;SACjB;QACD,MAAME,QAAQ,MAAM9C,uBAAuB,aACrC6B,QAAQW,QAAQ,GAAG;YAAEA,UAAUX,QAAQW,QAAQ;QAAC,IAAI,CAAC;YACzDT;YACAsC;YACAC;YACAvB,cAAcN,KAAKM,YAAY;YAC/B,iEAAiE;YACjEF;YACA,mEAAmE;YACnE,oEAAoE;YACpE,+DAA+D;YAC/D,mEAAmE;YACnE,sCAAsC;YACtCxC,YAAYyB,QAAQE,KAAK,GACrB;gBACEf,MAAMZ,WAAWY,IAAI;gBACrBe,OAAOF,QAAQE,KAAK;gBACpBO,YAAYlC,WAAWkC,UAAU;YACnC,IACA;gBACEtB,MAAMZ,WAAWY,IAAI;gBACrBqC,SAASxB,QAAQwB,OAAO;gBACxBf,YAAYlC,WAAWkC,UAAU;eAC7BT,EAAAA,sBAAAA,QAAQjB,UAAU,qBAAlBiB,oBAAoBX,IAAI,IACxB;gBAAEA,MAAMW,QAAQjB,UAAU,CAACM,IAAI;YAAC,IAChC,CAAC,GACDW,QAAQlB,QAAQ,GAChB;gBAAEM,cAAcY,QAAQlB,QAAQ,CAACK,IAAI;YAAC,IACtC,CAAC,GAEDa,QAAQyB,mBAAmB,GAC3B;gBAAEA,qBAAqB;YAAK,IAC5B,CAAC,GAEDzB,EAAAA,uBAAAA,QAAQjB,UAAU,qBAAlBiB,qBAAoB0B,WAAW,IAC/B;gBAAEA,aAAa1B,QAAQjB,UAAU,CAAC2C,WAAW;YAAC,IAC9C,CAAC;;QAGb,OAAOV,QAAQ;YAAEA;WAAUL,KAAK0B,SAAS,MAAO;IAClD,EAAE,OAAOI,OAAO;QACdC,QAAQD,KAAK,CAACA;QACd,OAAO;IACT;AACF;AAEA,eAAe3C,8BAA6B"}
@@ -155,6 +155,33 @@ export declare function composeNodesWithChrome(options: {
155
155
  */
156
156
  socialImages?: ComposeSocialImages;
157
157
  }): Promise<Record<string, any>>;
158
+ /**
159
+ * What the caller knows about the page it is composing, for the page review
160
+ * to NAME it when it holds or flags it (AGL-3374). Never read to decide
161
+ * whether the page serves.
162
+ */
163
+ export interface ComposePageContext {
164
+ /**
165
+ * A template composed against a routed listing or entry: the route pattern
166
+ * it serves (`/videos`, `/videos/:slug`), the collection it renders, the
167
+ * address being shown, and what a visitor gets when it has no clean
168
+ * version (`built-in-design` for a content collection, whose routes fall
169
+ * back to it; `not-found` for a store template, which has none).
170
+ */
171
+ template?: {
172
+ role: 'list' | 'entry';
173
+ route: string;
174
+ collectionName?: string | null;
175
+ entryPath?: string | null;
176
+ fallback?: 'built-in-design' | 'not-found';
177
+ } | null;
178
+ /** An experiment variant's version of the page. */
179
+ variant?: {
180
+ experimentId: string;
181
+ variantId: string;
182
+ name?: string | null;
183
+ } | null;
184
+ }
158
185
  /**
159
186
  * Full published-render composition for one screen (extracted for AGL-87 so
160
187
  * the SSG path and the password-unlock API build identical trees): applies
@@ -194,5 +221,7 @@ export declare function composeScreenNodes(options: {
194
221
  * than falling back again.
195
222
  */
196
223
  pageReviewFallback?: boolean;
224
+ /** What this page is, for naming it if the page review holds it (AGL-3374). */
225
+ page?: ComposePageContext;
197
226
  }): Promise<Record<string, any> | null>;
198
227
  export default composeScreenNodes;
@@ -469,13 +469,72 @@ import { stampFormDatasetBindings } from "./stamp-form-dataset-bindings.js";
469
469
  }
470
470
  return applyMediaAssetFacts(denormalized, facts);
471
471
  }
472
+ /**
473
+ * The page's own nodes and those of every layout and reusable component
474
+ * composed into it, for the page review to say WHICH one carries flagged
475
+ * content (AGL-3374). Read only when a review row is filed: the layout
476
+ * versions and the component definitions are the cached reads the compose
477
+ * already made.
478
+ */ async function composedPageParts(options) {
479
+ const parts = [
480
+ {
481
+ type: 'screen',
482
+ id: options.screenId,
483
+ nodes: options.screenNodes
484
+ }
485
+ ];
486
+ const seen = new Set();
487
+ let layoutId = options.layoutId ? String(options.layoutId) : undefined;
488
+ while(layoutId && !seen.has(layoutId) && seen.size < Aglyn.MAX_LAYOUT_CHAIN_DEPTH){
489
+ var _ref;
490
+ var _layoutRes_version;
491
+ seen.add(layoutId);
492
+ const layoutRes = await getPublishedLayoutVersion({
493
+ hostId: options.hostId,
494
+ layoutId
495
+ });
496
+ const layout = layoutRes == null ? void 0 : layoutRes.layout;
497
+ parts.push({
498
+ type: 'layout',
499
+ id: layoutId,
500
+ name: typeof (layout == null ? void 0 : layout.displayName) === 'string' ? layout.displayName : null,
501
+ nodes: (_ref = layoutRes == null ? void 0 : (_layoutRes_version = layoutRes.version) == null ? void 0 : _layoutRes_version.nodes) != null ? _ref : {}
502
+ });
503
+ layoutId = (layout == null ? void 0 : layout.layoutId) ? String(layout.layoutId) : undefined;
504
+ }
505
+ // Only the components this page actually renders, followed through
506
+ // components that nest others, so an unused one is never blamed.
507
+ const { definitions } = await getComponents({
508
+ hostId: options.hostId
509
+ });
510
+ const used = new Set();
511
+ let frontier = parts.map((part)=>part.nodes);
512
+ while(frontier.length){
513
+ const next = [];
514
+ for (const [id, definition] of Object.entries(definitions)){
515
+ if (used.has(id)) continue;
516
+ if (frontier.some((nodes)=>Aglyn.nodesReferenceComponent(nodes, id))) {
517
+ used.add(id);
518
+ next.push(definition.nodes);
519
+ parts.push({
520
+ type: 'component',
521
+ id,
522
+ nodes: definition.nodes
523
+ });
524
+ }
525
+ }
526
+ frontier = next;
527
+ }
528
+ return parts;
529
+ }
472
530
  /**
473
531
  * Full published-render composition for one screen (extracted for AGL-87 so
474
532
  * the SSG path and the password-unlock API build identical trees): applies
475
533
  * a due publish schedule, loads the version, composes the shared layout
476
534
  * chrome, grafts reusable components, and denormalizes.
477
535
  */ export async function composeScreenNodes(options) {
478
- var _ref, _options_versionId;
536
+ var _ref, _options_versionId, _ref1, _ref2;
537
+ var _options_page, _options_page1;
479
538
  const { hostId, screenId, screen } = options;
480
539
  const effectiveVersionId = options.versionId ? null : await applyDuePublishSchedule({
481
540
  hostId,
@@ -566,11 +625,31 @@ import { stampFormDatasetBindings } from "./stamp-form-dataset-bindings.js";
566
625
  * A held version serves the last version this page served clean, screened
567
626
  * again, or nothing.
568
627
  */ const nodes = await composed;
628
+ const version = versionRes.version;
569
629
  const review = await reviewHostedPage({
570
630
  hostId,
571
631
  screenId,
572
632
  versionId,
573
- nodes
633
+ nodes,
634
+ // Named by what it is, not only its id (AGL-3374).
635
+ page: {
636
+ screen: {
637
+ displayName: screen.displayName,
638
+ name: screen.name,
639
+ kind: screen.kind
640
+ },
641
+ template: (_ref1 = (_options_page = options.page) == null ? void 0 : _options_page.template) != null ? _ref1 : null,
642
+ variant: (_ref2 = (_options_page1 = options.page) == null ? void 0 : _options_page1.variant) != null ? _ref2 : null,
643
+ parts: ()=>{
644
+ var _ref;
645
+ return composedPageParts({
646
+ hostId,
647
+ screenId,
648
+ screenNodes: (_ref = version == null ? void 0 : version.nodes) != null ? _ref : {},
649
+ layoutId: version && 'layoutId' in version ? version.layoutId : screen.layoutId
650
+ });
651
+ }
652
+ }
574
653
  });
575
654
  if (review.outcome === 'serve') {
576
655
  // Only the PUBLISHED version is the page's last clean one; a variant or
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/tenant/runtime/src/lib/compose-screen-nodes.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 * as Aglyn from '@aglyn/aglyn/server'\n// By path: the overlay is server-only, and every `@aglyn/aglyn` barrel\n// re-exports `app-utils/server` into published pages.\nimport {\n applyMediaAssetFacts,\n mediaAssetRefs,\n} from '@aglyn/aglyn/app-utils/media-asset-facts'\nimport {\n recordServedPageVersion,\n reviewHostedPage,\n servedPageVersion,\n} from '@aglyn/tenant-data-admin/server/hosted-page-review'\nimport applyDuePublishSchedule from './apply-publish-schedule'\nimport getComponents from './get-components'\nimport getDatasets from './get-datasets'\nimport getForms from './get-forms'\nimport getMediaAssetFacts from './get-media-asset-facts'\nimport {\n getPublishedCollectionSource,\n type PublishedCollectionSource,\n} from './get-collection-content'\nimport getPluginInstalls from './get-plugin-installs'\nimport getVariables, { getFunctions, getWorkflows } from './get-variables'\nimport getPublishedLayoutVersion from './get-layout-version'\nimport getScreenVersion from './get-screen-version'\nimport {\n type ComposeSocialImages,\n socialImageAssetFacts,\n socialImageRefs,\n} from './social-image-facts'\nimport { stampFormDatasetBindings } from './stamp-form-dataset-bindings'\n\n/**\n * Content-collection context for a compose (AGL-551): the collection the\n * route resolved (list/entry template screens). `entries` rides along when\n * the route already fetched them (list pages); blocks bound to other\n * collections — or to this one when `entries` is absent — fetch on demand.\n */\nexport interface ComposeCollectionContext {\n slug: string\n entries?: Aglyn.CollectionEntryRecord[]\n /**\n * The entry being rendered (AGL-582, entry-template screens / entry\n * fallback) — the Related posts block resolves against it.\n */\n entry?: Aglyn.CollectionEntryRecord | null\n /**\n * The routed collection's category taxonomy (AGL-582): entry\n * `categoryId`s resolve to display names against it during expansion.\n */\n categories?: Aglyn.CollectionCategory[]\n /**\n * The list page the URL asked for (AGL-1321). Fills in an entries block\n * that declares `perPage` but no `page` — design time cannot know which\n * page a visitor is on.\n */\n page?: number\n /**\n * The category segment the URL filtered on (AGL-1321); marks the current\n * pill in a Category Pills block. `entries` arrives already filtered.\n */\n categorySlug?: string\n /**\n * Whether the read behind `entries` stopped at its `.limit()` (AGL-1516).\n * Travels with the entries because the search boxes downstream have to say\n * what they actually searched, and — with the liveness gate and the route's\n * category filter both in between — `entries.length` no longer tells them.\n */\n entriesReachedBound?: boolean\n /**\n * Where `entries` begins in the collection's own order (AGL-3213).\n *\n * Zero for every listing served from the cached read. A page past that\n * read's bound carries only its own ten entries, and the block windows\n * `[(page - 1) * perPage, …)` — so without this it would slice from an\n * offset its own array never reaches and render an empty listing.\n */\n windowStart?: number\n /**\n * Whether {@link slug} is a cache KEY rather than an address (AGL-2524).\n *\n * The author page mixes collections, and the compose pipeline keys entry\n * sources by collection slug — so it hands over a synthetic one\n * (`AUTHOR_ENTRIES_SOURCE_SLUG`) with its entries already in hand. That is\n * harmless for the entries block, whose every row carries its OWN\n * `collectionSlug` and builds `entry.url` from it, and for the search box,\n * whose index is built the same way.\n *\n * It is NOT harmless for anything that builds a URL from the source's slug\n * itself. Set this and such a block resolves nothing rather than pointing\n * readers at `/{synthetic}/…`.\n */\n routeless?: boolean\n}\n\ninterface CollectionBlockScan {\n slugs: Set<string>\n hasRelated: boolean\n hasCategories: boolean\n hasSearch: boolean\n}\n\n/**\n * Which collections does this tree ask for (AGL-1152)?\n *\n * Extracted so the PREFETCH below and the expansion that consumes it read the\n * tree through one function rather than two copies of the same predicate. A\n * divergence between them is not a type error — it is a slug prefetched and\n * never awaited, or (worse) a slug the prefetch missed that then pays the full\n * serial read anyway — so there is deliberately no second implementation to\n * drift.\n */\nfunction scanCollectionBlocks(\n nodes: Record<string, any>,\n collection?: ComposeCollectionContext,\n): CollectionBlockScan {\n const slugs = new Set<string>()\n let hasRelated = false\n let hasCategories = false\n let hasSearch = false\n for (const node of Object.values(nodes)) {\n if (node?.componentId === Aglyn.COLLECTION_ENTRIES_COMPONENT_ID) {\n const slug =\n String(node?.props?.collectionSlug ?? '').trim() || collection?.slug\n if (slug) slugs.add(slug)\n }\n // Category pills (AGL-1321) need only the taxonomy, but it rides on the\n // same source, so they count as a reason to resolve one.\n if (node?.componentId === Aglyn.COLLECTION_CATEGORIES_COMPONENT_ID) {\n const slug =\n String(node?.props?.collectionSlug ?? '').trim() || collection?.slug\n if (slug) {\n hasCategories = true\n slugs.add(slug)\n }\n }\n // The standalone toolbar search box (AGL-1516, Figma 494:1220) needs the\n // collection's entries to index, and rides the same source the listing\n // beside it was built from — one read, one answer.\n if (node?.componentId === Aglyn.COLLECTION_SEARCH_COMPONENT_ID) {\n const slug =\n String(node?.props?.collectionSlug ?? '').trim() || collection?.slug\n if (slug) {\n hasSearch = true\n slugs.add(slug)\n }\n }\n // Related posts (AGL-582) always resolve against the ROUTED collection\n // — they only mean something with a current entry in context.\n if (\n node?.componentId === Aglyn.COLLECTION_RELATED_COMPONENT_ID &&\n collection?.slug &&\n collection.entry\n ) {\n hasRelated = true\n slugs.add(collection.slug)\n }\n }\n return { slugs, hasRelated, hasCategories, hasSearch }\n}\n\n/**\n * Issue the collection reads AS SOON AS THE SCREEN NODES EXIST (AGL-1152).\n *\n * `getPublishedCollectionSource` is three SEQUENTIAL round trips —\n * `findContentCollection`, then `listLiveEntries`, then `attachEntryAuthors`\n * — and until this existed it ran after the chrome bundle had already been\n * awaited, so a page carrying a Collection entries block paid the whole thing\n * as a serial tail on the compose phase. Measured on the tenant: a page with\n * no collection block composes in ~20 ms, one with a block in ~572 ms, and the\n * tree work itself accounts for under 2 ms of that at 50 entries. The gap is\n * this read, waiting for reads it shares nothing with.\n *\n * Same shape as `screenDatasetsPromise` directly below, and the same caveat\n * applies: the SCREEN's own nodes are a fast path, NOT the correctness gate. A\n * collection block can arrive from a layout or a grafted reusable component,\n * neither of which exists yet at this point, so the real scan still runs\n * against the composed tree and still fetches anything this missed.\n *\n * The ROUTED collection is deliberately excluded when its entries are already\n * in hand: the expansion below answers that slug from `collection.entries`\n * without reading at all, so prefetching it would buy a read nobody awaits.\n */\nfunction prefetchCollectionSources(\n hostId: string,\n screenNodes: Record<string, any>,\n collection?: ComposeCollectionContext,\n): Record<string, Promise<PublishedCollectionSource>> {\n const prefetched: Record<\n string,\n Promise<PublishedCollectionSource>\n > = {}\n for (const slug of scanCollectionBlocks(screenNodes, collection).slugs) {\n if (slug === collection?.slug && collection.entries) continue\n const pending = getPublishedCollectionSource({\n hostId,\n collectionSlug: slug,\n })\n // Marked handled the moment it exists, for the reason `composed` is in\n // `composeScreenNodes`: a tree that turns out not to need this slug never\n // awaits it, and an unawaited rejection takes the process down rather than\n // failing this one read. The real await below still sees the rejection.\n void pending.catch(() => undefined)\n prefetched[slug] = pending\n }\n return prefetched\n}\n\n/**\n * Expands Collection entries blocks (AGL-551) against their collections'\n * published entries, and Related posts blocks (AGL-582) against the routed\n * entry. Fetches lazily — screens without the blocks cost nothing — and\n * fails open on lookup errors like every other compose stage.\n */\nasync function expandCollectionEntryBlocks(\n hostId: string,\n nodes: Record<string, any>,\n collection?: ComposeCollectionContext,\n prefetched?: Record<string, Promise<PublishedCollectionSource>>,\n /** The site's zone (AGL-3237); UTC when a site has not named one. */\n timeZone?: string,\n): Promise<Record<string, any>> {\n const { slugs, hasRelated, hasCategories, hasSearch } = scanCollectionBlocks(\n nodes,\n collection,\n )\n if (!slugs.size) return nodes\n const sources: Record<string, Aglyn.CollectionEntriesSource> = {}\n await Promise.all(\n [...slugs].map(async (slug) => {\n // The routed collection rides its already-fetched entries +\n // categories (AGL-582); other collections fetch both on demand.\n if (slug === collection?.slug && collection.entries) {\n sources[slug] = {\n slug,\n entries: collection.entries,\n categories: collection.categories,\n // Only the ROUTED collection carries the URL's page (AGL-1321) — a\n // block bound to another collection must not inherit it.\n ...(collection.page ? { page: collection.page } : {}),\n // ...nor its bound (AGL-1516): this is a fact about the read the\n // route already performed, and it describes only that collection.\n ...(collection.entriesReachedBound ? { reachedBound: true } : {}),\n // ...nor where its window starts (AGL-3213), for the same reason:\n // it is a fact about the read this route performed.\n ...(collection.windowStart\n ? { windowStart: collection.windowStart }\n : {}),\n }\n return\n }\n // The prefetch when this slug was visible on the screen's own nodes;\n // a live read when it only appeared after layout/component grafting.\n const fetched = await (prefetched?.[slug] ??\n getPublishedCollectionSource({ hostId, collectionSlug: slug }))\n sources[slug] = {\n slug,\n entries: fetched.entries,\n categories:\n slug === collection?.slug && collection.categories\n ? collection.categories\n : fetched.categories,\n ...(fetched.reachedBound ? { reachedBound: true } : {}),\n }\n }),\n )\n const expanded = Aglyn.expandCollectionEntries(\n nodes,\n sources,\n collection?.slug,\n timeZone,\n )\n const withCategories = hasCategories\n ? Aglyn.expandCollectionCategories(\n expanded,\n sources,\n /*\n No DEFAULT collection for the pills on a routeless page (AGL-2524).\n\n Category pills are the one block that builds its links from the\n SOURCE's slug — `/{slug}/category/{x}` — because a category is a\n filter on one collection's own listing. On the author page that slug\n is synthetic, so an unbound pills block stamped links to a route that\n does not exist.\n\n Rendering nothing is the honest answer rather than a fallback. The\n page spans every collection, and there is no\n `/author/{slug}/category/{x}` for a pill to lead to; the only real\n destination would be some collection's listing, which drops the\n author the reader is looking at. A pills block that NAMES a\n collection is unaffected and still resolves that collection's own\n taxonomy — \"browse the blog by category\", which is a sensible thing\n to put beside an archive.\n */\n collection?.routeless ? undefined : collection?.slug,\n collection?.categorySlug,\n )\n : expanded\n const withSearch = hasSearch\n ? Aglyn.expandCollectionSearch(\n withCategories,\n sources,\n collection?.slug,\n timeZone,\n )\n : withCategories\n if (!hasRelated || !collection?.entry) return withSearch\n return Aglyn.expandCollectionRelated(\n withSearch,\n sources[collection.slug],\n collection.entry,\n timeZone,\n )\n}\n\n/**\n * Shared post-version composition (AGL-551, extracted from\n * `composeScreenNodes`): layout chrome, reusable components, repeatables,\n * collection entries, bindings, function definitions, plugin installs,\n * named tokens, denormalize, and last the current facts of each placed image\n * and film, and of the social card the page is shared as. The screen path and\n * the collection-fallback\n * path (which has no screen doc) build identical trees through this one\n * pipeline.\n */\nexport async function composeNodesWithChrome(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237) — `resolveSiteTimeZone` of\n * the org and the host, resolved ONCE by the caller that holds both.\n *\n * A string rather than the two documents, because the value has to be\n * identical on the server render and the client re-render, and the surest\n * way to guarantee that is for only one place to decide it. Absent is UTC,\n * which is what every site rendered before this existed.\n */\n timeZone?: string\n /**\n * The layout binding, or a PROMISE of it.\n *\n * The unresolved form exists for the same reason `screenNodes` accepts one\n * (AGL-1428): the binding may live on the version document (key-present\n * wins over the screen's), and awaiting the version before this call would\n * put every host-scoped read back behind it. Only the layout-chain walk\n * consumes the binding, so it alone waits; the rest of the chrome bundle\n * still starts immediately.\n */\n layoutId?:\n | string\n | null\n | Promise<string | null | undefined>\n /**\n * The screen's values for the properties of the layouts it renders inside\n * (AGL-2893), keyed by layout id — or a PROMISE of them, for the reason\n * `layoutId` accepts one: they live on the version document beside the\n * binding. Absent, every layout renders its properties' defaults.\n */\n layoutPropValues?:\n | Aglyn.AglynScreenVersion['layoutPropValues']\n | null\n | Promise<Aglyn.AglynScreenVersion['layoutPropValues'] | null | undefined>\n /**\n * The screen's per-page restyling of its layouts' elements (AGL-3286),\n * keyed by layout id then layout node id — or a PROMISE of it, for the same\n * reason as `layoutPropValues`, beside which it is stored. Absent, every\n * layout renders with its own styling.\n */\n layoutStyleOverrides?:\n | Aglyn.AglynScreenVersion['layoutStyleOverrides']\n | null\n | Promise<\n Aglyn.AglynScreenVersion['layoutStyleOverrides'] | null | undefined\n >\n /**\n * The screen's own nodes, or a PROMISE of them (AGL-1428).\n *\n * Accepting the unresolved form is what lets `composeScreenNodes` hand the\n * version read over before it has finished, so the host-scoped reads below\n * — none of which look at these nodes — overlap it instead of queueing\n * behind it. Passing a resolved value behaves exactly as before, which is\n * what every other caller does.\n */\n screenNodes: Record<string, any> | Promise<Record<string, any>>\n /** Entry-template tokens (AGL-105) substituted before denormalize. */\n tokens?: Record<string, string>\n /** Routed content collection (AGL-551) for Collection entries blocks. */\n collection?: ComposeCollectionContext\n /**\n * The host document, for `host.*` tokens (AGL-1022).\n *\n * Passed in rather than read here: every caller already holds it, and\n * `composeScreenNodes` was the largest single render phase before AGL-1225\n * cut it to one round trip — adding a read back would spend that win on\n * data we already have in hand.\n */\n host?: Aglyn.HostTokenSource | null\n /**\n * The social card the head shares this page as (AGL-2850). The documents of\n * the assets it names are read in the same batch as the images and films\n * the tree places.\n */\n socialImages?: ComposeSocialImages\n}): Promise<Record<string, any>> {\n const { hostId, layoutId } = options\n\n /**\n * The layout chain, innermost first (AGL-703).\n *\n * A layout may itself render inside another layout, so this walks the\n * `layoutId` pointers rather than reading one. Fetching is sequential\n * because each step's parent is only known once the previous layout\n * document is in hand — but the walk is short by construction\n * (MAX_LAYOUT_CHAIN_DEPTH) and every layout is already a cached read.\n *\n * `seen` stops a cycle from looping forever. Stored data can hold one\n * even though both the console and `canNestLayout` refuse to create it:\n * the API, a script, or a restored backup can all write a layout\n * document directly, and a render must degrade rather than hang.\n */\n const walkLayoutChain = async () => {\n const chain: Aglyn.LayoutChainEntry[] = []\n const seen = new Set<string>()\n const boundLayoutId = await layoutId\n let currentLayoutId = boundLayoutId ? String(boundLayoutId) : undefined\n while (\n currentLayoutId &&\n !seen.has(currentLayoutId) &&\n chain.length < Aglyn.MAX_LAYOUT_CHAIN_DEPTH\n ) {\n seen.add(currentLayoutId)\n const layoutRes = await getPublishedLayoutVersion({\n hostId,\n layoutId: currentLayoutId,\n })\n // The version's declared properties travel with its nodes (AGL-2893):\n // they are applied to this layout alone, with the screen's values for\n // this layout, before the screen is grafted into its slot.\n chain.push({\n layoutId: currentLayoutId,\n nodes: layoutRes?.version?.nodes as any,\n props: (layoutRes?.version as Aglyn.AglynLayoutVersion | undefined)\n ?.props,\n })\n const parentId = (layoutRes?.layout as any)?.layoutId\n currentLayoutId = parentId ? String(parentId) : undefined\n }\n return chain\n }\n\n /**\n * ONE round-trip stage instead of three (AGL-1225).\n *\n * This used to be `await layout walk` → `await getComponents` → `await\n * Promise.all([five reads])`: three sequential waits, where only the first\n * has any reason to be sequential. Every one of the other six reads takes\n * `hostId` and nothing else — none of them consumes the layout chain — so\n * they were waiting on a walk whose result they never look at.\n *\n * The walk stays internally sequential because it genuinely is: each step's\n * parent id is only known once the previous layout document is in hand. It\n * just no longer gates anything else. The critical path becomes the walk\n * alone rather than walk + components + bulk.\n *\n * Measured budget that motivated this (production, `/product/besigner`):\n * `composeScreenNodes` was the largest single phase at 1577 ms cold and\n * consistently ~1.4-1.6 s warm too, so this is not cold-start cost. The\n * existing `AGL-1152:render` timing line reports `composeScreenNodes` as a\n * phase, so the effect of this shows up there directly — no new\n * instrumentation, and a regression would be visible in the same place.\n */\n /**\n * Does the SCREEN itself repeat over a dataset (AGL-1440)?\n *\n * Asked as soon as the nodes are in hand — which since AGL-1428 is after\n * the fan-out has been ISSUED rather than before — so the overwhelmingly\n * common case still keeps the AGL-1225 shape: a page that repeats almost\n * always says so on its own document, and its datasets read goes out\n * alongside the remaining chrome reads instead of after them.\n *\n * It is deliberately NOT the correctness gate — a repeatable can arrive from\n * a layout or a grafted reusable component, neither of which exists yet. The\n * gate is re-asked against the composed tree after grafting, which is the\n * exact input `expandRepeatables` reads.\n */\n /*\n * ISSUE THE HOST-SCOPED READS FIRST, THEN AWAIT THE NODES (AGL-1428).\n *\n * Every read in this bundle is keyed by `hostId` (and `layoutId`) alone —\n * none of them reads `screenNodes` — so starting them before the nodes are\n * in hand lets `composeScreenNodes`' version read overlap them rather than\n * run ahead of them. `Promise.all` is created BEFORE the `await` below on\n * purpose: that is the line that makes the two independent, and moving the\n * await above it silently gives the whole saving back.\n *\n * `getDatasets` is the one read that genuinely depends on the nodes, so it\n * cannot join the bundle. It does not have to wait for the bundle either —\n * it is issued the moment the nodes resolve and awaited after, so it still\n * overlaps whatever is left of the chrome reads instead of costing the\n * extra serial round trip that dropping it from the batch would imply.\n */\n const chromeBundle = Promise.all([\n walkLayoutChain(),\n getComponents({ hostId }),\n // Host variable + function bindings (AGL-91/93): {{name}} and\n // {{fn:name(args)}} in string props resolve to values; unknown tokens\n // and failed runs stay literal.\n Promise.all([\n getVariables({ hostId }),\n getFunctions({ hostId }),\n getWorkflows({ hostId }),\n getPluginInstalls({ hostId }),\n ]),\n ])\n const screenNodes = await options.screenNodes\n const screenDatasetKeys = Aglyn.repeatDatasetKeys(screenNodes)\n const screenDatasetsPromise = screenDatasetKeys.length\n ? getDatasets({ hostId, keys: screenDatasetKeys })\n : undefined\n // Does the SCREEN itself place a form entity? Gated and re-asked exactly\n // like the datasets read beside it (AGL-1440): most pages carry no form, and\n // the ones that do usually say so on their own document, so the read goes\n // out here alongside the chrome reads instead of as a serial tail. It is not\n // the correctness gate — a placed form can arrive from a layout or a grafted\n // component — so the composed tree is asked again below.\n const screenFormsPromise = Aglyn.placesFormEntity(screenNodes)\n ? getForms({ hostId })\n : undefined\n // Issued HERE, beside the datasets read and before the chrome bundle is\n // awaited, so the collection read overlaps it instead of trailing it.\n const prefetchedSources = prefetchCollectionSources(\n hostId,\n screenNodes,\n options.collection,\n )\n const [layoutChain, componentsRes, bulk] = await chromeBundle\n const [rawVariables, functions, workflows, pluginInstalls] = bulk\n const screenDatasets = await screenDatasetsPromise\n // Settled by now: it is read off the same version document the layout\n // binding the walk above waited on came from.\n const layoutPropValues = await options.layoutPropValues\n const layoutStyleOverrides = await options.layoutStyleOverrides\n\n const composedNodes = Aglyn.composeLayoutChainWithProps(\n layoutChain as any,\n screenNodes as any,\n layoutPropValues,\n layoutStyleOverrides,\n )\n const graftedComponents = Aglyn.composeReusableComponentNodes(\n composedNodes as any,\n componentsRes.definitions as any,\n )\n /*\n * PLACED FORMS RESOLVE AGAINST THEIR ENTITY (`docs/specs/reusable-forms.md`).\n *\n * A form node bound to `hosts/{hostId}/forms/{formId}` renders that entity's\n * published design, so a form is edited once and every page placing it\n * follows. Without this the entity's tree was written on every publish and\n * read by nothing: the fields had to be redrawn per page, and the two copies\n * diverged the moment either was touched.\n *\n * The gate is the COMPONENT-grafted tree, not the screen's own nodes, for\n * the reason the repeatables gate below states: a form placed inside a\n * layout or a shared component does not exist in `screenNodes`, and a page\n * that renders one would silently keep its stale inline copy.\n *\n * The second graft re-runs the component expansion deliberately. Instances\n * already expanded are skipped by their own prefix, so the repeat costs a\n * scan, and passing BOTH placement kinds is what expands a reusable\n * component nested inside a form's design — which the first pass could not\n * have seen, because that subtree was not in the tree yet.\n */\n const forms =\n (await screenFormsPromise)?.forms ??\n (Aglyn.placesFormEntity(graftedComponents as any)\n ? (await getForms({ hostId })).forms\n : undefined)\n const grafted = forms\n ? Aglyn.composeReusableComponentNodes(\n graftedComponents as any,\n componentsRes.definitions as any,\n [Aglyn.placedFormPlacement(forms as any)],\n )\n : graftedComponents\n // Computed variables (AGL-129): workflow-backed values resolve once per\n // compose; failures keep each variable's stored fallback.\n const variables = Aglyn.resolveComputedVariables(\n rawVariables,\n functions,\n workflows,\n )\n // Repeatables (AGL-103) expand after grafting (so they work inside\n // reusable components) and before bindings (so {{name}} tokens inside\n // cloned items still resolve).\n //\n // Only the datasets this tree repeats over are read (AGL-1440), and the tree\n // asked is the composed one — after grafting — because that is the map the\n // expansion reads: a repeatable living in a layout or a reusable component\n // is invisible in `screenNodes`, and reading only the screen's keys would\n // silently render one template row where the author put a list. The\n // screen's own keys were issued beside the chrome reads above; a key only a\n // layout or a component adds is read here, for that key alone.\n const datasetKeys = Aglyn.repeatDatasetKeys(grafted as any)\n const unreadDatasetKeys = datasetKeys.filter(\n (key) => !screenDatasetKeys.includes(key),\n )\n const datasets = unreadDatasetKeys.length\n ? {\n ...screenDatasets,\n ...(await getDatasets({ hostId, keys: unreadDatasetKeys })),\n }\n : screenDatasets\n const repeated = Aglyn.expandRepeatables(grafted as any, datasets)\n // Collection entries blocks (AGL-551) expand alongside repeatables:\n // per-entry {{entry.*}} tokens substitute inside the clones here, while\n // page-level tokens wait for resolveNamedTokens below.\n const withEntries = await expandCollectionEntryBlocks(\n hostId,\n repeated,\n options.collection,\n prefetchedSources,\n options.timeZone,\n )\n // Entry Meta blocks (AGL-1385): fill in the routed entry's date/category/\n // tags. Needs no source fetch — the routed entry and its taxonomy are\n // already in hand — so it sits outside `expandCollectionEntryBlocks`, which\n // returns early when no block asks for a collection read. AFTER it, so the\n // per-entry clones it just produced already carry their own resolved values\n // and are skipped.\n const withEntryMeta = Aglyn.expandCollectionEntryMeta(\n withEntries as any,\n options.collection?.entry,\n options.collection?.categories,\n options.timeZone,\n )\n // Entry Author cards (AGL-2486): the same fill, one block over. Its values\n // come off the author RECORD the routed entry resolved to, which the\n // collection read has already attached, so this costs nothing either.\n const withEntryAuthor = Aglyn.expandCollectionEntryAuthor(\n withEntryMeta as any,\n options.collection?.entry,\n )\n const bound = Aglyn.resolveNodesBindings(\n withEntryAuthor as any,\n variables,\n functions,\n )\n // Host variables (AGL-1022): `{{host.*}}` resolves from the INSTALLING\n // site, late — at render, never at install — so a rebrand propagates to\n // every artifact that names the host instead of hard-coding it. Same\n // registry the email path uses, so a token means one thing in both.\n const withHostTokens = Aglyn.resolveNodesHostTokens(\n bound as any,\n options.host,\n )\n // Function widgets run client-side: embed their definitions (AGL-93), and\n // beside each the site variables that function reads and no others\n // (AGL-3202).\n const withFunctions = Aglyn.attachFunctionDefinitions(\n withHostTokens,\n functions,\n variables,\n )\n // Marketplace plugins (AGL-45): stamp each marketplacePlugin node with its\n // pinned install (version/sha256/capabilities) + kill-switch state.\n const nodes = Aglyn.attachPluginInstalls(withFunctions, pluginInstalls)\n // Entry-template tokens (AGL-105): {{entry.*}} from the rendered entry.\n const finalNodes = Aglyn.resolveNamedTokens(nodes as any, options.tokens)\n // The document's one `main` landmark (AGL-2486). LAST, so it reads the tree\n // the page actually ships — a slot grafted from a layout chain, an element\n // an author chose — rather than the screen as stored.\n const withLandmark = Aglyn.stampDocumentLandmark(finalNodes as any)\n // Each form's dataset binding, signed so the submit route can trust it\n // (AGL-2773). Read off THIS tree, the one the page ships, so a form grafted\n // from a layout, a component or a form entity is signed as it renders; and\n // after every stage that rewrites props, so nothing changes what the\n // signature covers.\n const withFormBindings = stampFormDatasetBindings(withLandmark, hostId)\n const denormalized = Aglyn.canvas.processNodesToDenormalized(\n withFormBindings as any,\n )\n /*\n * WHAT EACH PLACED IMAGE AND FILM IS NOW (AGL-2807, AGL-2833).\n *\n * An image's pixel pair and a film's length, shape and poster come from the\n * asset's DAM document as it is now, not as it was when it was picked. LAST,\n * on the tree the page ships, because an asset can arrive from any stage\n * above: a layout, a component, a form, a repeated row, a collection entry,\n * a binding.\n *\n * ONE read for all of them, issued once the tree is final rather than beside\n * the chrome reads. A read issued there could only cover the screen's own\n * placements, and nearly every layout places an image the screen does not\n * (a logo, a footer mark), so it would buy a second read on almost every\n * page. The late read costs its own round trip after the chrome reads, paid\n * each time a page is composed, which for a published page is its ISR\n * regeneration. A tree with no library asset, on a page whose social card\n * names none, issues none.\n *\n * THE SOCIAL CARD'S ASSETS JOIN THE SAME READ (AGL-2850), ahead of the\n * placements. A placement the cap leaves out keeps its pick-time pair, which\n * for an image is a reservation the decoded picture corrects. Nothing\n * corrects a card's pair, because a crawler lays the card out from it before\n * fetching the image, and a card names at most three documents.\n */\n const socialImages = options.socialImages\n const cardRefs = socialImages ? socialImageRefs(socialImages.images) : []\n const refs = mediaAssetRefs(denormalized)\n if (!refs.length && !cardRefs.length) return denormalized\n const facts = await getMediaAssetFacts({\n hostId,\n refs: [...cardRefs, ...refs],\n })\n if (socialImages) {\n const cardFacts = socialImageAssetFacts(socialImages.images, facts)\n if (cardFacts) socialImages.onFacts(cardFacts)\n }\n return applyMediaAssetFacts(denormalized, facts)\n}\n\n/**\n * Full published-render composition for one screen (extracted for AGL-87 so\n * the SSG path and the password-unlock API build identical trees): applies\n * a due publish schedule, loads the version, composes the shared layout\n * chrome, grafts reusable components, and denormalizes.\n */\nexport async function composeScreenNodes(options: {\n hostId: string\n screenId: string\n screen: Aglyn.AglynScreen\n /** Entry-template tokens (AGL-105) substituted before denormalize. */\n tokens?: Record<string, string>\n /** Routed content collection (AGL-551) for Collection entries blocks. */\n collection?: ComposeCollectionContext\n /**\n * Compose a specific version instead of the published one (AGL-253):\n * experiment variants point at versions; schedules don't apply.\n */\n versionId?: string\n /** The host document, for `host.*` tokens (AGL-1022). */\n host?: Aglyn.HostTokenSource | null\n /**\n * The zone this site's dates read in (AGL-3237) — `resolveSiteTimeZone` of\n * the org and the host, resolved ONCE by the caller that holds both.\n *\n * A string rather than the two documents, because the value has to be\n * identical on the server render and the client re-render, and the surest\n * way to guarantee that is for only one place to decide it. Absent is UTC,\n * which is what every site rendered before this existed.\n */\n timeZone?: string\n /** The social card the head shares this page as (AGL-2850). */\n socialImages?: ComposeSocialImages\n /**\n * Internal: `false` when this compose IS the fallback to a held page's\n * last clean version, so a fallback that holds too serves nothing rather\n * than falling back again.\n */\n pageReviewFallback?: boolean\n}): Promise<Record<string, any> | null> {\n const { hostId, screenId, screen } = options\n\n const effectiveVersionId = options.versionId\n ? null\n : await applyDuePublishSchedule({\n hostId,\n collectionName: 'screens',\n docId: screenId,\n parent: screen,\n })\n const versionId = (options.versionId ??\n effectiveVersionId ??\n screen.versionId) as string\n\n /*\n * OVERLAP THE VERSION READ WITH THE CHROME BUNDLE (AGL-1428).\n *\n * `composeNodesWithChrome`'s reads are keyed by `hostId`/`layoutId`, both\n * of which are in hand here, so the version read no longer has to finish\n * before they start. Handing the promise over instead of the resolved\n * value is the whole change: it is `composeNodesWithChrome` that decides\n * when it actually needs the nodes.\n *\n * The `versionId`-less screen still exits BEFORE anything is issued, so a\n * screen that has never been published costs no reads. What remains is the\n * narrow case of a `versionId` that points at a missing or unreadable\n * version document — a data-integrity fault rather than a routing outcome\n * — and that one now pays for a chrome bundle it discards. That is the\n * deliberate trade: one wasted bundle on a broken screen, against the\n * version read hiding under the chrome reads on every render that works.\n */\n if (!versionId) return null\n\n const versionPromise = getScreenVersion({ hostId, screenId, versionId })\n\n /*\n * NEITHER DERIVED PROMISE MAY REJECT ON ITS OWN.\n *\n * `composed` is discarded on every failure path below, and a rejected\n * promise nobody awaited is an unhandled rejection — which in Node takes\n * the whole render process down instead of letting this 404. So the nodes\n * handed to the compose absorb the failure (an empty tree it will never be\n * asked for), and `composed` gets a rejection handler attached the moment\n * it exists rather than at the point we decide to drop it. The real error\n * still propagates, from the `await versionPromise` below, exactly where it\n * did when this function awaited the version directly.\n */\n const composed = composeNodesWithChrome({\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n // Version-first (key-present wins, null = explicitly no layout), screen\n // fallback — resolved as a promise so only the layout-chain walk waits on\n // the version read; the rest of the chrome bundle keeps the AGL-1428\n // overlap. A failed version read falls back to the screen binding; the\n // whole compose is discarded on that path anyway.\n layoutId: versionPromise.then(\n (res) =>\n res.version && 'layoutId' in res.version\n ? ((res.version as Aglyn.AglynScreenVersion).layoutId as\n | string\n | null)\n : (screen.layoutId as string | undefined),\n () => screen.layoutId as string | undefined,\n ),\n // The screen's values for its layouts' properties (AGL-2893), beside the\n // binding on the same document; a failed read renders the defaults.\n layoutPropValues: versionPromise.then(\n (res) =>\n (res.version as Aglyn.AglynScreenVersion | undefined)?.layoutPropValues,\n () => undefined,\n ),\n // …and its per-page restyling of their elements (AGL-3286), from the same\n // document; a failed read renders the layouts' own styling.\n layoutStyleOverrides: versionPromise.then(\n (res) =>\n (res.version as Aglyn.AglynScreenVersion | undefined)\n ?.layoutStyleOverrides,\n () => undefined,\n ),\n screenNodes: versionPromise.then(\n (res) => (res.version?.nodes ?? {}) as any,\n () => ({}) as any,\n ),\n tokens: options.tokens,\n collection: options.collection,\n host: options.host,\n socialImages: options.socialImages,\n })\n void composed.catch(() => undefined)\n\n const versionRes = await versionPromise\n if (versionRes.error || !versionRes.version) return null\n\n /*\n * THE PAGE PHISHING REVIEW (AGL-3356).\n *\n * Every way a page goes live — a toolbar publish, a versions-panel\n * publish, a scheduled publish, a component or form promoted under it, an\n * experiment variant, an edit to the live version in place — meets here,\n * with the page exactly as a visitor will receive it. So this is where a\n * page that links to a brand's lookalike, asks for a password or a card\n * in a field of its own, or (for a new workspace) dresses a brand's\n * sign-in is held rather than served. See `hosted-page-review.ts`.\n *\n * A held version serves the last version this page served clean, screened\n * again, or nothing.\n */\n const nodes = await composed\n const review = await reviewHostedPage({\n hostId,\n screenId,\n versionId,\n nodes,\n })\n if (review.outcome === 'serve') {\n // Only the PUBLISHED version is the page's last clean one; a variant or\n // a pinned version is not what the page serves.\n if (nodes && !options.versionId) {\n await recordServedPageVersion(hostId, screenId, versionId)\n }\n return nodes\n }\n if (options.pageReviewFallback === false) return null\n const previous = await servedPageVersion(hostId, screenId)\n if (!previous || previous === versionId) return null\n return composeScreenNodes({\n ...options,\n versionId: previous,\n pageReviewFallback: false,\n })\n}\n\nexport default composeScreenNodes\n"],"names":["Aglyn","applyMediaAssetFacts","mediaAssetRefs","recordServedPageVersion","reviewHostedPage","servedPageVersion","applyDuePublishSchedule","getComponents","getDatasets","getForms","getMediaAssetFacts","getPublishedCollectionSource","getPluginInstalls","getVariables","getFunctions","getWorkflows","getPublishedLayoutVersion","getScreenVersion","socialImageAssetFacts","socialImageRefs","stampFormDatasetBindings","scanCollectionBlocks","nodes","collection","slugs","Set","hasRelated","hasCategories","hasSearch","node","Object","values","componentId","COLLECTION_ENTRIES_COMPONENT_ID","slug","String","props","collectionSlug","trim","add","COLLECTION_CATEGORIES_COMPONENT_ID","COLLECTION_SEARCH_COMPONENT_ID","COLLECTION_RELATED_COMPONENT_ID","entry","prefetchCollectionSources","hostId","screenNodes","prefetched","entries","pending","catch","undefined","expandCollectionEntryBlocks","timeZone","size","sources","Promise","all","map","categories","page","entriesReachedBound","reachedBound","windowStart","fetched","expanded","expandCollectionEntries","withCategories","expandCollectionCategories","routeless","categorySlug","withSearch","expandCollectionSearch","expandCollectionRelated","composeNodesWithChrome","options","layoutId","walkLayoutChain","chain","seen","boundLayoutId","currentLayoutId","has","length","MAX_LAYOUT_CHAIN_DEPTH","layoutRes","push","version","parentId","layout","chromeBundle","screenDatasetKeys","repeatDatasetKeys","screenDatasetsPromise","keys","screenFormsPromise","placesFormEntity","prefetchedSources","layoutChain","componentsRes","bulk","rawVariables","functions","workflows","pluginInstalls","screenDatasets","layoutPropValues","layoutStyleOverrides","composedNodes","composeLayoutChainWithProps","graftedComponents","composeReusableComponentNodes","definitions","forms","grafted","placedFormPlacement","variables","resolveComputedVariables","datasetKeys","unreadDatasetKeys","filter","key","includes","datasets","repeated","expandRepeatables","withEntries","withEntryMeta","expandCollectionEntryMeta","withEntryAuthor","expandCollectionEntryAuthor","bound","resolveNodesBindings","withHostTokens","resolveNodesHostTokens","host","withFunctions","attachFunctionDefinitions","attachPluginInstalls","finalNodes","resolveNamedTokens","tokens","withLandmark","stampDocumentLandmark","withFormBindings","denormalized","canvas","processNodesToDenormalized","socialImages","cardRefs","images","refs","facts","cardFacts","onFacts","composeScreenNodes","screenId","screen","effectiveVersionId","versionId","collectionName","docId","parent","versionPromise","composed","then","res","versionRes","error","review","outcome","pageReviewFallback","previous"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAC5C,uEAAuE;AACvE,sDAAsD;AACtD,SACEC,oBAAoB,EACpBC,cAAc,QACT,2CAA0C;AACjD,SACEC,uBAAuB,EACvBC,gBAAgB,EAChBC,iBAAiB,QACZ,qDAAoD;AAC3D,OAAOC,6BAA6B,8BAA0B;AAC9D,OAAOC,mBAAmB,sBAAkB;AAC5C,OAAOC,iBAAiB,oBAAgB;AACxC,OAAOC,cAAc,iBAAa;AAClC,OAAOC,wBAAwB,6BAAyB;AACxD,SACEC,4BAA4B,QAEvB,8BAA0B;AACjC,OAAOC,uBAAuB,2BAAuB;AACrD,OAAOC,gBAAgBC,YAAY,EAAEC,YAAY,QAAQ,qBAAiB;AAC1E,OAAOC,+BAA+B,0BAAsB;AAC5D,OAAOC,sBAAsB,0BAAsB;AACnD,SAEEC,qBAAqB,EACrBC,eAAe,QACV,0BAAsB;AAC7B,SAASC,wBAAwB,QAAQ,mCAA+B;AAwExE;;;;;;;;;CASC,GACD,SAASC,qBACPC,KAA0B,EAC1BC,UAAqC;IAErC,MAAMC,QAAQ,IAAIC;IAClB,IAAIC,aAAa;IACjB,IAAIC,gBAAgB;IACpB,IAAIC,YAAY;IAChB,KAAK,MAAMC,QAAQC,OAAOC,MAAM,CAACT,OAAQ;QACvC,IAAIO,CAAAA,wBAAAA,KAAMG,WAAW,MAAKhC,MAAMiC,+BAA+B,EAAE;;gBAEtDJ;YADT,MAAMK,OACJC,eAAON,yBA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,iBAAiB;QACpCyC;QACA+G;QACAG;QACAzI;IACF;IACA,IAAImJ,OAAOC,OAAO,KAAK,SAAS;QAC9B,wEAAwE;QACxE,gDAAgD;QAChD,IAAIpJ,SAAS,CAACqD,QAAQoF,SAAS,EAAE;YAC/B,MAAM5J,wBAAwB0C,QAAQ+G,UAAUG;QAClD;QACA,OAAOzI;IACT;IACA,IAAIqD,QAAQgG,kBAAkB,KAAK,OAAO,OAAO;IACjD,MAAMC,WAAW,MAAMvK,kBAAkBwC,QAAQ+G;IACjD,IAAI,CAACgB,YAAYA,aAAab,WAAW,OAAO;IAChD,OAAOJ,mBAAmB,aACrBhF;QACHoF,WAAWa;QACXD,oBAAoB;;AAExB;AAEA,eAAehB,mBAAkB"}
1
+ {"version":3,"sources":["../../../../../../libs/tenant/runtime/src/lib/compose-screen-nodes.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 * as Aglyn from '@aglyn/aglyn/server'\n// By path: the overlay is server-only, and every `@aglyn/aglyn` barrel\n// re-exports `app-utils/server` into published pages.\nimport {\n applyMediaAssetFacts,\n mediaAssetRefs,\n} from '@aglyn/aglyn/app-utils/media-asset-facts'\nimport {\n recordServedPageVersion,\n reviewHostedPage,\n servedPageVersion,\n} from '@aglyn/tenant-data-admin/server/hosted-page-review'\nimport type { HostedPagePart } from '@aglyn/tenant-data-admin/server/held-page-subject'\nimport applyDuePublishSchedule from './apply-publish-schedule'\nimport getComponents from './get-components'\nimport getDatasets from './get-datasets'\nimport getForms from './get-forms'\nimport getMediaAssetFacts from './get-media-asset-facts'\nimport {\n getPublishedCollectionSource,\n type PublishedCollectionSource,\n} from './get-collection-content'\nimport getPluginInstalls from './get-plugin-installs'\nimport getVariables, { getFunctions, getWorkflows } from './get-variables'\nimport getPublishedLayoutVersion from './get-layout-version'\nimport getScreenVersion from './get-screen-version'\nimport {\n type ComposeSocialImages,\n socialImageAssetFacts,\n socialImageRefs,\n} from './social-image-facts'\nimport { stampFormDatasetBindings } from './stamp-form-dataset-bindings'\n\n/**\n * Content-collection context for a compose (AGL-551): the collection the\n * route resolved (list/entry template screens). `entries` rides along when\n * the route already fetched them (list pages); blocks bound to other\n * collections — or to this one when `entries` is absent — fetch on demand.\n */\nexport interface ComposeCollectionContext {\n slug: string\n entries?: Aglyn.CollectionEntryRecord[]\n /**\n * The entry being rendered (AGL-582, entry-template screens / entry\n * fallback) — the Related posts block resolves against it.\n */\n entry?: Aglyn.CollectionEntryRecord | null\n /**\n * The routed collection's category taxonomy (AGL-582): entry\n * `categoryId`s resolve to display names against it during expansion.\n */\n categories?: Aglyn.CollectionCategory[]\n /**\n * The list page the URL asked for (AGL-1321). Fills in an entries block\n * that declares `perPage` but no `page` — design time cannot know which\n * page a visitor is on.\n */\n page?: number\n /**\n * The category segment the URL filtered on (AGL-1321); marks the current\n * pill in a Category Pills block. `entries` arrives already filtered.\n */\n categorySlug?: string\n /**\n * Whether the read behind `entries` stopped at its `.limit()` (AGL-1516).\n * Travels with the entries because the search boxes downstream have to say\n * what they actually searched, and — with the liveness gate and the route's\n * category filter both in between — `entries.length` no longer tells them.\n */\n entriesReachedBound?: boolean\n /**\n * Where `entries` begins in the collection's own order (AGL-3213).\n *\n * Zero for every listing served from the cached read. A page past that\n * read's bound carries only its own ten entries, and the block windows\n * `[(page - 1) * perPage, …)` — so without this it would slice from an\n * offset its own array never reaches and render an empty listing.\n */\n windowStart?: number\n /**\n * Whether {@link slug} is a cache KEY rather than an address (AGL-2524).\n *\n * The author page mixes collections, and the compose pipeline keys entry\n * sources by collection slug — so it hands over a synthetic one\n * (`AUTHOR_ENTRIES_SOURCE_SLUG`) with its entries already in hand. That is\n * harmless for the entries block, whose every row carries its OWN\n * `collectionSlug` and builds `entry.url` from it, and for the search box,\n * whose index is built the same way.\n *\n * It is NOT harmless for anything that builds a URL from the source's slug\n * itself. Set this and such a block resolves nothing rather than pointing\n * readers at `/{synthetic}/…`.\n */\n routeless?: boolean\n}\n\ninterface CollectionBlockScan {\n slugs: Set<string>\n hasRelated: boolean\n hasCategories: boolean\n hasSearch: boolean\n}\n\n/**\n * Which collections does this tree ask for (AGL-1152)?\n *\n * Extracted so the PREFETCH below and the expansion that consumes it read the\n * tree through one function rather than two copies of the same predicate. A\n * divergence between them is not a type error — it is a slug prefetched and\n * never awaited, or (worse) a slug the prefetch missed that then pays the full\n * serial read anyway — so there is deliberately no second implementation to\n * drift.\n */\nfunction scanCollectionBlocks(\n nodes: Record<string, any>,\n collection?: ComposeCollectionContext,\n): CollectionBlockScan {\n const slugs = new Set<string>()\n let hasRelated = false\n let hasCategories = false\n let hasSearch = false\n for (const node of Object.values(nodes)) {\n if (node?.componentId === Aglyn.COLLECTION_ENTRIES_COMPONENT_ID) {\n const slug =\n String(node?.props?.collectionSlug ?? '').trim() || collection?.slug\n if (slug) slugs.add(slug)\n }\n // Category pills (AGL-1321) need only the taxonomy, but it rides on the\n // same source, so they count as a reason to resolve one.\n if (node?.componentId === Aglyn.COLLECTION_CATEGORIES_COMPONENT_ID) {\n const slug =\n String(node?.props?.collectionSlug ?? '').trim() || collection?.slug\n if (slug) {\n hasCategories = true\n slugs.add(slug)\n }\n }\n // The standalone toolbar search box (AGL-1516, Figma 494:1220) needs the\n // collection's entries to index, and rides the same source the listing\n // beside it was built from — one read, one answer.\n if (node?.componentId === Aglyn.COLLECTION_SEARCH_COMPONENT_ID) {\n const slug =\n String(node?.props?.collectionSlug ?? '').trim() || collection?.slug\n if (slug) {\n hasSearch = true\n slugs.add(slug)\n }\n }\n // Related posts (AGL-582) always resolve against the ROUTED collection\n // — they only mean something with a current entry in context.\n if (\n node?.componentId === Aglyn.COLLECTION_RELATED_COMPONENT_ID &&\n collection?.slug &&\n collection.entry\n ) {\n hasRelated = true\n slugs.add(collection.slug)\n }\n }\n return { slugs, hasRelated, hasCategories, hasSearch }\n}\n\n/**\n * Issue the collection reads AS SOON AS THE SCREEN NODES EXIST (AGL-1152).\n *\n * `getPublishedCollectionSource` is three SEQUENTIAL round trips —\n * `findContentCollection`, then `listLiveEntries`, then `attachEntryAuthors`\n * — and until this existed it ran after the chrome bundle had already been\n * awaited, so a page carrying a Collection entries block paid the whole thing\n * as a serial tail on the compose phase. Measured on the tenant: a page with\n * no collection block composes in ~20 ms, one with a block in ~572 ms, and the\n * tree work itself accounts for under 2 ms of that at 50 entries. The gap is\n * this read, waiting for reads it shares nothing with.\n *\n * Same shape as `screenDatasetsPromise` directly below, and the same caveat\n * applies: the SCREEN's own nodes are a fast path, NOT the correctness gate. A\n * collection block can arrive from a layout or a grafted reusable component,\n * neither of which exists yet at this point, so the real scan still runs\n * against the composed tree and still fetches anything this missed.\n *\n * The ROUTED collection is deliberately excluded when its entries are already\n * in hand: the expansion below answers that slug from `collection.entries`\n * without reading at all, so prefetching it would buy a read nobody awaits.\n */\nfunction prefetchCollectionSources(\n hostId: string,\n screenNodes: Record<string, any>,\n collection?: ComposeCollectionContext,\n): Record<string, Promise<PublishedCollectionSource>> {\n const prefetched: Record<\n string,\n Promise<PublishedCollectionSource>\n > = {}\n for (const slug of scanCollectionBlocks(screenNodes, collection).slugs) {\n if (slug === collection?.slug && collection.entries) continue\n const pending = getPublishedCollectionSource({\n hostId,\n collectionSlug: slug,\n })\n // Marked handled the moment it exists, for the reason `composed` is in\n // `composeScreenNodes`: a tree that turns out not to need this slug never\n // awaits it, and an unawaited rejection takes the process down rather than\n // failing this one read. The real await below still sees the rejection.\n void pending.catch(() => undefined)\n prefetched[slug] = pending\n }\n return prefetched\n}\n\n/**\n * Expands Collection entries blocks (AGL-551) against their collections'\n * published entries, and Related posts blocks (AGL-582) against the routed\n * entry. Fetches lazily — screens without the blocks cost nothing — and\n * fails open on lookup errors like every other compose stage.\n */\nasync function expandCollectionEntryBlocks(\n hostId: string,\n nodes: Record<string, any>,\n collection?: ComposeCollectionContext,\n prefetched?: Record<string, Promise<PublishedCollectionSource>>,\n /** The site's zone (AGL-3237); UTC when a site has not named one. */\n timeZone?: string,\n): Promise<Record<string, any>> {\n const { slugs, hasRelated, hasCategories, hasSearch } = scanCollectionBlocks(\n nodes,\n collection,\n )\n if (!slugs.size) return nodes\n const sources: Record<string, Aglyn.CollectionEntriesSource> = {}\n await Promise.all(\n [...slugs].map(async (slug) => {\n // The routed collection rides its already-fetched entries +\n // categories (AGL-582); other collections fetch both on demand.\n if (slug === collection?.slug && collection.entries) {\n sources[slug] = {\n slug,\n entries: collection.entries,\n categories: collection.categories,\n // Only the ROUTED collection carries the URL's page (AGL-1321) — a\n // block bound to another collection must not inherit it.\n ...(collection.page ? { page: collection.page } : {}),\n // ...nor its bound (AGL-1516): this is a fact about the read the\n // route already performed, and it describes only that collection.\n ...(collection.entriesReachedBound ? { reachedBound: true } : {}),\n // ...nor where its window starts (AGL-3213), for the same reason:\n // it is a fact about the read this route performed.\n ...(collection.windowStart\n ? { windowStart: collection.windowStart }\n : {}),\n }\n return\n }\n // The prefetch when this slug was visible on the screen's own nodes;\n // a live read when it only appeared after layout/component grafting.\n const fetched = await (prefetched?.[slug] ??\n getPublishedCollectionSource({ hostId, collectionSlug: slug }))\n sources[slug] = {\n slug,\n entries: fetched.entries,\n categories:\n slug === collection?.slug && collection.categories\n ? collection.categories\n : fetched.categories,\n ...(fetched.reachedBound ? { reachedBound: true } : {}),\n }\n }),\n )\n const expanded = Aglyn.expandCollectionEntries(\n nodes,\n sources,\n collection?.slug,\n timeZone,\n )\n const withCategories = hasCategories\n ? Aglyn.expandCollectionCategories(\n expanded,\n sources,\n /*\n No DEFAULT collection for the pills on a routeless page (AGL-2524).\n\n Category pills are the one block that builds its links from the\n SOURCE's slug — `/{slug}/category/{x}` — because a category is a\n filter on one collection's own listing. On the author page that slug\n is synthetic, so an unbound pills block stamped links to a route that\n does not exist.\n\n Rendering nothing is the honest answer rather than a fallback. The\n page spans every collection, and there is no\n `/author/{slug}/category/{x}` for a pill to lead to; the only real\n destination would be some collection's listing, which drops the\n author the reader is looking at. A pills block that NAMES a\n collection is unaffected and still resolves that collection's own\n taxonomy — \"browse the blog by category\", which is a sensible thing\n to put beside an archive.\n */\n collection?.routeless ? undefined : collection?.slug,\n collection?.categorySlug,\n )\n : expanded\n const withSearch = hasSearch\n ? Aglyn.expandCollectionSearch(\n withCategories,\n sources,\n collection?.slug,\n timeZone,\n )\n : withCategories\n if (!hasRelated || !collection?.entry) return withSearch\n return Aglyn.expandCollectionRelated(\n withSearch,\n sources[collection.slug],\n collection.entry,\n timeZone,\n )\n}\n\n/**\n * Shared post-version composition (AGL-551, extracted from\n * `composeScreenNodes`): layout chrome, reusable components, repeatables,\n * collection entries, bindings, function definitions, plugin installs,\n * named tokens, denormalize, and last the current facts of each placed image\n * and film, and of the social card the page is shared as. The screen path and\n * the collection-fallback\n * path (which has no screen doc) build identical trees through this one\n * pipeline.\n */\nexport async function composeNodesWithChrome(options: {\n hostId: string\n /**\n * The zone this site's dates read in (AGL-3237) — `resolveSiteTimeZone` of\n * the org and the host, resolved ONCE by the caller that holds both.\n *\n * A string rather than the two documents, because the value has to be\n * identical on the server render and the client re-render, and the surest\n * way to guarantee that is for only one place to decide it. Absent is UTC,\n * which is what every site rendered before this existed.\n */\n timeZone?: string\n /**\n * The layout binding, or a PROMISE of it.\n *\n * The unresolved form exists for the same reason `screenNodes` accepts one\n * (AGL-1428): the binding may live on the version document (key-present\n * wins over the screen's), and awaiting the version before this call would\n * put every host-scoped read back behind it. Only the layout-chain walk\n * consumes the binding, so it alone waits; the rest of the chrome bundle\n * still starts immediately.\n */\n layoutId?:\n | string\n | null\n | Promise<string | null | undefined>\n /**\n * The screen's values for the properties of the layouts it renders inside\n * (AGL-2893), keyed by layout id — or a PROMISE of them, for the reason\n * `layoutId` accepts one: they live on the version document beside the\n * binding. Absent, every layout renders its properties' defaults.\n */\n layoutPropValues?:\n | Aglyn.AglynScreenVersion['layoutPropValues']\n | null\n | Promise<Aglyn.AglynScreenVersion['layoutPropValues'] | null | undefined>\n /**\n * The screen's per-page restyling of its layouts' elements (AGL-3286),\n * keyed by layout id then layout node id — or a PROMISE of it, for the same\n * reason as `layoutPropValues`, beside which it is stored. Absent, every\n * layout renders with its own styling.\n */\n layoutStyleOverrides?:\n | Aglyn.AglynScreenVersion['layoutStyleOverrides']\n | null\n | Promise<\n Aglyn.AglynScreenVersion['layoutStyleOverrides'] | null | undefined\n >\n /**\n * The screen's own nodes, or a PROMISE of them (AGL-1428).\n *\n * Accepting the unresolved form is what lets `composeScreenNodes` hand the\n * version read over before it has finished, so the host-scoped reads below\n * — none of which look at these nodes — overlap it instead of queueing\n * behind it. Passing a resolved value behaves exactly as before, which is\n * what every other caller does.\n */\n screenNodes: Record<string, any> | Promise<Record<string, any>>\n /** Entry-template tokens (AGL-105) substituted before denormalize. */\n tokens?: Record<string, string>\n /** Routed content collection (AGL-551) for Collection entries blocks. */\n collection?: ComposeCollectionContext\n /**\n * The host document, for `host.*` tokens (AGL-1022).\n *\n * Passed in rather than read here: every caller already holds it, and\n * `composeScreenNodes` was the largest single render phase before AGL-1225\n * cut it to one round trip — adding a read back would spend that win on\n * data we already have in hand.\n */\n host?: Aglyn.HostTokenSource | null\n /**\n * The social card the head shares this page as (AGL-2850). The documents of\n * the assets it names are read in the same batch as the images and films\n * the tree places.\n */\n socialImages?: ComposeSocialImages\n}): Promise<Record<string, any>> {\n const { hostId, layoutId } = options\n\n /**\n * The layout chain, innermost first (AGL-703).\n *\n * A layout may itself render inside another layout, so this walks the\n * `layoutId` pointers rather than reading one. Fetching is sequential\n * because each step's parent is only known once the previous layout\n * document is in hand — but the walk is short by construction\n * (MAX_LAYOUT_CHAIN_DEPTH) and every layout is already a cached read.\n *\n * `seen` stops a cycle from looping forever. Stored data can hold one\n * even though both the console and `canNestLayout` refuse to create it:\n * the API, a script, or a restored backup can all write a layout\n * document directly, and a render must degrade rather than hang.\n */\n const walkLayoutChain = async () => {\n const chain: Aglyn.LayoutChainEntry[] = []\n const seen = new Set<string>()\n const boundLayoutId = await layoutId\n let currentLayoutId = boundLayoutId ? String(boundLayoutId) : undefined\n while (\n currentLayoutId &&\n !seen.has(currentLayoutId) &&\n chain.length < Aglyn.MAX_LAYOUT_CHAIN_DEPTH\n ) {\n seen.add(currentLayoutId)\n const layoutRes = await getPublishedLayoutVersion({\n hostId,\n layoutId: currentLayoutId,\n })\n // The version's declared properties travel with its nodes (AGL-2893):\n // they are applied to this layout alone, with the screen's values for\n // this layout, before the screen is grafted into its slot.\n chain.push({\n layoutId: currentLayoutId,\n nodes: layoutRes?.version?.nodes as any,\n props: (layoutRes?.version as Aglyn.AglynLayoutVersion | undefined)\n ?.props,\n })\n const parentId = (layoutRes?.layout as any)?.layoutId\n currentLayoutId = parentId ? String(parentId) : undefined\n }\n return chain\n }\n\n /**\n * ONE round-trip stage instead of three (AGL-1225).\n *\n * This used to be `await layout walk` → `await getComponents` → `await\n * Promise.all([five reads])`: three sequential waits, where only the first\n * has any reason to be sequential. Every one of the other six reads takes\n * `hostId` and nothing else — none of them consumes the layout chain — so\n * they were waiting on a walk whose result they never look at.\n *\n * The walk stays internally sequential because it genuinely is: each step's\n * parent id is only known once the previous layout document is in hand. It\n * just no longer gates anything else. The critical path becomes the walk\n * alone rather than walk + components + bulk.\n *\n * Measured budget that motivated this (production, `/product/besigner`):\n * `composeScreenNodes` was the largest single phase at 1577 ms cold and\n * consistently ~1.4-1.6 s warm too, so this is not cold-start cost. The\n * existing `AGL-1152:render` timing line reports `composeScreenNodes` as a\n * phase, so the effect of this shows up there directly — no new\n * instrumentation, and a regression would be visible in the same place.\n */\n /**\n * Does the SCREEN itself repeat over a dataset (AGL-1440)?\n *\n * Asked as soon as the nodes are in hand — which since AGL-1428 is after\n * the fan-out has been ISSUED rather than before — so the overwhelmingly\n * common case still keeps the AGL-1225 shape: a page that repeats almost\n * always says so on its own document, and its datasets read goes out\n * alongside the remaining chrome reads instead of after them.\n *\n * It is deliberately NOT the correctness gate — a repeatable can arrive from\n * a layout or a grafted reusable component, neither of which exists yet. The\n * gate is re-asked against the composed tree after grafting, which is the\n * exact input `expandRepeatables` reads.\n */\n /*\n * ISSUE THE HOST-SCOPED READS FIRST, THEN AWAIT THE NODES (AGL-1428).\n *\n * Every read in this bundle is keyed by `hostId` (and `layoutId`) alone —\n * none of them reads `screenNodes` — so starting them before the nodes are\n * in hand lets `composeScreenNodes`' version read overlap them rather than\n * run ahead of them. `Promise.all` is created BEFORE the `await` below on\n * purpose: that is the line that makes the two independent, and moving the\n * await above it silently gives the whole saving back.\n *\n * `getDatasets` is the one read that genuinely depends on the nodes, so it\n * cannot join the bundle. It does not have to wait for the bundle either —\n * it is issued the moment the nodes resolve and awaited after, so it still\n * overlaps whatever is left of the chrome reads instead of costing the\n * extra serial round trip that dropping it from the batch would imply.\n */\n const chromeBundle = Promise.all([\n walkLayoutChain(),\n getComponents({ hostId }),\n // Host variable + function bindings (AGL-91/93): {{name}} and\n // {{fn:name(args)}} in string props resolve to values; unknown tokens\n // and failed runs stay literal.\n Promise.all([\n getVariables({ hostId }),\n getFunctions({ hostId }),\n getWorkflows({ hostId }),\n getPluginInstalls({ hostId }),\n ]),\n ])\n const screenNodes = await options.screenNodes\n const screenDatasetKeys = Aglyn.repeatDatasetKeys(screenNodes)\n const screenDatasetsPromise = screenDatasetKeys.length\n ? getDatasets({ hostId, keys: screenDatasetKeys })\n : undefined\n // Does the SCREEN itself place a form entity? Gated and re-asked exactly\n // like the datasets read beside it (AGL-1440): most pages carry no form, and\n // the ones that do usually say so on their own document, so the read goes\n // out here alongside the chrome reads instead of as a serial tail. It is not\n // the correctness gate — a placed form can arrive from a layout or a grafted\n // component — so the composed tree is asked again below.\n const screenFormsPromise = Aglyn.placesFormEntity(screenNodes)\n ? getForms({ hostId })\n : undefined\n // Issued HERE, beside the datasets read and before the chrome bundle is\n // awaited, so the collection read overlaps it instead of trailing it.\n const prefetchedSources = prefetchCollectionSources(\n hostId,\n screenNodes,\n options.collection,\n )\n const [layoutChain, componentsRes, bulk] = await chromeBundle\n const [rawVariables, functions, workflows, pluginInstalls] = bulk\n const screenDatasets = await screenDatasetsPromise\n // Settled by now: it is read off the same version document the layout\n // binding the walk above waited on came from.\n const layoutPropValues = await options.layoutPropValues\n const layoutStyleOverrides = await options.layoutStyleOverrides\n\n const composedNodes = Aglyn.composeLayoutChainWithProps(\n layoutChain as any,\n screenNodes as any,\n layoutPropValues,\n layoutStyleOverrides,\n )\n const graftedComponents = Aglyn.composeReusableComponentNodes(\n composedNodes as any,\n componentsRes.definitions as any,\n )\n /*\n * PLACED FORMS RESOLVE AGAINST THEIR ENTITY (`docs/specs/reusable-forms.md`).\n *\n * A form node bound to `hosts/{hostId}/forms/{formId}` renders that entity's\n * published design, so a form is edited once and every page placing it\n * follows. Without this the entity's tree was written on every publish and\n * read by nothing: the fields had to be redrawn per page, and the two copies\n * diverged the moment either was touched.\n *\n * The gate is the COMPONENT-grafted tree, not the screen's own nodes, for\n * the reason the repeatables gate below states: a form placed inside a\n * layout or a shared component does not exist in `screenNodes`, and a page\n * that renders one would silently keep its stale inline copy.\n *\n * The second graft re-runs the component expansion deliberately. Instances\n * already expanded are skipped by their own prefix, so the repeat costs a\n * scan, and passing BOTH placement kinds is what expands a reusable\n * component nested inside a form's design — which the first pass could not\n * have seen, because that subtree was not in the tree yet.\n */\n const forms =\n (await screenFormsPromise)?.forms ??\n (Aglyn.placesFormEntity(graftedComponents as any)\n ? (await getForms({ hostId })).forms\n : undefined)\n const grafted = forms\n ? Aglyn.composeReusableComponentNodes(\n graftedComponents as any,\n componentsRes.definitions as any,\n [Aglyn.placedFormPlacement(forms as any)],\n )\n : graftedComponents\n // Computed variables (AGL-129): workflow-backed values resolve once per\n // compose; failures keep each variable's stored fallback.\n const variables = Aglyn.resolveComputedVariables(\n rawVariables,\n functions,\n workflows,\n )\n // Repeatables (AGL-103) expand after grafting (so they work inside\n // reusable components) and before bindings (so {{name}} tokens inside\n // cloned items still resolve).\n //\n // Only the datasets this tree repeats over are read (AGL-1440), and the tree\n // asked is the composed one — after grafting — because that is the map the\n // expansion reads: a repeatable living in a layout or a reusable component\n // is invisible in `screenNodes`, and reading only the screen's keys would\n // silently render one template row where the author put a list. The\n // screen's own keys were issued beside the chrome reads above; a key only a\n // layout or a component adds is read here, for that key alone.\n const datasetKeys = Aglyn.repeatDatasetKeys(grafted as any)\n const unreadDatasetKeys = datasetKeys.filter(\n (key) => !screenDatasetKeys.includes(key),\n )\n const datasets = unreadDatasetKeys.length\n ? {\n ...screenDatasets,\n ...(await getDatasets({ hostId, keys: unreadDatasetKeys })),\n }\n : screenDatasets\n const repeated = Aglyn.expandRepeatables(grafted as any, datasets)\n // Collection entries blocks (AGL-551) expand alongside repeatables:\n // per-entry {{entry.*}} tokens substitute inside the clones here, while\n // page-level tokens wait for resolveNamedTokens below.\n const withEntries = await expandCollectionEntryBlocks(\n hostId,\n repeated,\n options.collection,\n prefetchedSources,\n options.timeZone,\n )\n // Entry Meta blocks (AGL-1385): fill in the routed entry's date/category/\n // tags. Needs no source fetch — the routed entry and its taxonomy are\n // already in hand — so it sits outside `expandCollectionEntryBlocks`, which\n // returns early when no block asks for a collection read. AFTER it, so the\n // per-entry clones it just produced already carry their own resolved values\n // and are skipped.\n const withEntryMeta = Aglyn.expandCollectionEntryMeta(\n withEntries as any,\n options.collection?.entry,\n options.collection?.categories,\n options.timeZone,\n )\n // Entry Author cards (AGL-2486): the same fill, one block over. Its values\n // come off the author RECORD the routed entry resolved to, which the\n // collection read has already attached, so this costs nothing either.\n const withEntryAuthor = Aglyn.expandCollectionEntryAuthor(\n withEntryMeta as any,\n options.collection?.entry,\n )\n const bound = Aglyn.resolveNodesBindings(\n withEntryAuthor as any,\n variables,\n functions,\n )\n // Host variables (AGL-1022): `{{host.*}}` resolves from the INSTALLING\n // site, late — at render, never at install — so a rebrand propagates to\n // every artifact that names the host instead of hard-coding it. Same\n // registry the email path uses, so a token means one thing in both.\n const withHostTokens = Aglyn.resolveNodesHostTokens(\n bound as any,\n options.host,\n )\n // Function widgets run client-side: embed their definitions (AGL-93), and\n // beside each the site variables that function reads and no others\n // (AGL-3202).\n const withFunctions = Aglyn.attachFunctionDefinitions(\n withHostTokens,\n functions,\n variables,\n )\n // Marketplace plugins (AGL-45): stamp each marketplacePlugin node with its\n // pinned install (version/sha256/capabilities) + kill-switch state.\n const nodes = Aglyn.attachPluginInstalls(withFunctions, pluginInstalls)\n // Entry-template tokens (AGL-105): {{entry.*}} from the rendered entry.\n const finalNodes = Aglyn.resolveNamedTokens(nodes as any, options.tokens)\n // The document's one `main` landmark (AGL-2486). LAST, so it reads the tree\n // the page actually ships — a slot grafted from a layout chain, an element\n // an author chose — rather than the screen as stored.\n const withLandmark = Aglyn.stampDocumentLandmark(finalNodes as any)\n // Each form's dataset binding, signed so the submit route can trust it\n // (AGL-2773). Read off THIS tree, the one the page ships, so a form grafted\n // from a layout, a component or a form entity is signed as it renders; and\n // after every stage that rewrites props, so nothing changes what the\n // signature covers.\n const withFormBindings = stampFormDatasetBindings(withLandmark, hostId)\n const denormalized = Aglyn.canvas.processNodesToDenormalized(\n withFormBindings as any,\n )\n /*\n * WHAT EACH PLACED IMAGE AND FILM IS NOW (AGL-2807, AGL-2833).\n *\n * An image's pixel pair and a film's length, shape and poster come from the\n * asset's DAM document as it is now, not as it was when it was picked. LAST,\n * on the tree the page ships, because an asset can arrive from any stage\n * above: a layout, a component, a form, a repeated row, a collection entry,\n * a binding.\n *\n * ONE read for all of them, issued once the tree is final rather than beside\n * the chrome reads. A read issued there could only cover the screen's own\n * placements, and nearly every layout places an image the screen does not\n * (a logo, a footer mark), so it would buy a second read on almost every\n * page. The late read costs its own round trip after the chrome reads, paid\n * each time a page is composed, which for a published page is its ISR\n * regeneration. A tree with no library asset, on a page whose social card\n * names none, issues none.\n *\n * THE SOCIAL CARD'S ASSETS JOIN THE SAME READ (AGL-2850), ahead of the\n * placements. A placement the cap leaves out keeps its pick-time pair, which\n * for an image is a reservation the decoded picture corrects. Nothing\n * corrects a card's pair, because a crawler lays the card out from it before\n * fetching the image, and a card names at most three documents.\n */\n const socialImages = options.socialImages\n const cardRefs = socialImages ? socialImageRefs(socialImages.images) : []\n const refs = mediaAssetRefs(denormalized)\n if (!refs.length && !cardRefs.length) return denormalized\n const facts = await getMediaAssetFacts({\n hostId,\n refs: [...cardRefs, ...refs],\n })\n if (socialImages) {\n const cardFacts = socialImageAssetFacts(socialImages.images, facts)\n if (cardFacts) socialImages.onFacts(cardFacts)\n }\n return applyMediaAssetFacts(denormalized, facts)\n}\n\n/**\n * What the caller knows about the page it is composing, for the page review\n * to NAME it when it holds or flags it (AGL-3374). Never read to decide\n * whether the page serves.\n */\nexport interface ComposePageContext {\n /**\n * A template composed against a routed listing or entry: the route pattern\n * it serves (`/videos`, `/videos/:slug`), the collection it renders, the\n * address being shown, and what a visitor gets when it has no clean\n * version (`built-in-design` for a content collection, whose routes fall\n * back to it; `not-found` for a store template, which has none).\n */\n template?: {\n role: 'list' | 'entry'\n route: string\n collectionName?: string | null\n entryPath?: string | null\n fallback?: 'built-in-design' | 'not-found'\n } | null\n /** An experiment variant's version of the page. */\n variant?: { experimentId: string; variantId: string; name?: string | null } | null\n}\n\n/**\n * The page's own nodes and those of every layout and reusable component\n * composed into it, for the page review to say WHICH one carries flagged\n * content (AGL-3374). Read only when a review row is filed: the layout\n * versions and the component definitions are the cached reads the compose\n * already made.\n */\nasync function composedPageParts(options: {\n hostId: string\n screenId: string\n screenNodes: Record<string, any>\n layoutId: string | null | undefined\n}): Promise<HostedPagePart[]> {\n const parts: HostedPagePart[] = [\n { type: 'screen', id: options.screenId, nodes: options.screenNodes },\n ]\n const seen = new Set<string>()\n let layoutId = options.layoutId ? String(options.layoutId) : undefined\n while (layoutId && !seen.has(layoutId) && seen.size < Aglyn.MAX_LAYOUT_CHAIN_DEPTH) {\n seen.add(layoutId)\n const layoutRes = await getPublishedLayoutVersion({ hostId: options.hostId, layoutId })\n const layout = layoutRes?.layout as { displayName?: unknown; layoutId?: unknown } | undefined\n parts.push({\n type: 'layout',\n id: layoutId,\n name: typeof layout?.displayName === 'string' ? layout.displayName : null,\n nodes: layoutRes?.version?.nodes ?? {},\n })\n layoutId = layout?.layoutId ? String(layout.layoutId) : undefined\n }\n // Only the components this page actually renders, followed through\n // components that nest others, so an unused one is never blamed.\n const { definitions } = await getComponents({ hostId: options.hostId })\n const used = new Set<string>()\n let frontier = parts.map((part) => part.nodes as Record<string, any>)\n while (frontier.length) {\n const next: Record<string, any>[] = []\n for (const [id, definition] of Object.entries(definitions)) {\n if (used.has(id)) continue\n if (frontier.some((nodes) => Aglyn.nodesReferenceComponent(nodes, id))) {\n used.add(id)\n next.push(definition.nodes as Record<string, any>)\n parts.push({ type: 'component', id, nodes: definition.nodes })\n }\n }\n frontier = next\n }\n return parts\n}\n\n/**\n * Full published-render composition for one screen (extracted for AGL-87 so\n * the SSG path and the password-unlock API build identical trees): applies\n * a due publish schedule, loads the version, composes the shared layout\n * chrome, grafts reusable components, and denormalizes.\n */\nexport async function composeScreenNodes(options: {\n hostId: string\n screenId: string\n screen: Aglyn.AglynScreen\n /** Entry-template tokens (AGL-105) substituted before denormalize. */\n tokens?: Record<string, string>\n /** Routed content collection (AGL-551) for Collection entries blocks. */\n collection?: ComposeCollectionContext\n /**\n * Compose a specific version instead of the published one (AGL-253):\n * experiment variants point at versions; schedules don't apply.\n */\n versionId?: string\n /** The host document, for `host.*` tokens (AGL-1022). */\n host?: Aglyn.HostTokenSource | null\n /**\n * The zone this site's dates read in (AGL-3237) — `resolveSiteTimeZone` of\n * the org and the host, resolved ONCE by the caller that holds both.\n *\n * A string rather than the two documents, because the value has to be\n * identical on the server render and the client re-render, and the surest\n * way to guarantee that is for only one place to decide it. Absent is UTC,\n * which is what every site rendered before this existed.\n */\n timeZone?: string\n /** The social card the head shares this page as (AGL-2850). */\n socialImages?: ComposeSocialImages\n /**\n * Internal: `false` when this compose IS the fallback to a held page's\n * last clean version, so a fallback that holds too serves nothing rather\n * than falling back again.\n */\n pageReviewFallback?: boolean\n /** What this page is, for naming it if the page review holds it (AGL-3374). */\n page?: ComposePageContext\n}): Promise<Record<string, any> | null> {\n const { hostId, screenId, screen } = options\n\n const effectiveVersionId = options.versionId\n ? null\n : await applyDuePublishSchedule({\n hostId,\n collectionName: 'screens',\n docId: screenId,\n parent: screen,\n })\n const versionId = (options.versionId ??\n effectiveVersionId ??\n screen.versionId) as string\n\n /*\n * OVERLAP THE VERSION READ WITH THE CHROME BUNDLE (AGL-1428).\n *\n * `composeNodesWithChrome`'s reads are keyed by `hostId`/`layoutId`, both\n * of which are in hand here, so the version read no longer has to finish\n * before they start. Handing the promise over instead of the resolved\n * value is the whole change: it is `composeNodesWithChrome` that decides\n * when it actually needs the nodes.\n *\n * The `versionId`-less screen still exits BEFORE anything is issued, so a\n * screen that has never been published costs no reads. What remains is the\n * narrow case of a `versionId` that points at a missing or unreadable\n * version document — a data-integrity fault rather than a routing outcome\n * — and that one now pays for a chrome bundle it discards. That is the\n * deliberate trade: one wasted bundle on a broken screen, against the\n * version read hiding under the chrome reads on every render that works.\n */\n if (!versionId) return null\n\n const versionPromise = getScreenVersion({ hostId, screenId, versionId })\n\n /*\n * NEITHER DERIVED PROMISE MAY REJECT ON ITS OWN.\n *\n * `composed` is discarded on every failure path below, and a rejected\n * promise nobody awaited is an unhandled rejection — which in Node takes\n * the whole render process down instead of letting this 404. So the nodes\n * handed to the compose absorb the failure (an empty tree it will never be\n * asked for), and `composed` gets a rejection handler attached the moment\n * it exists rather than at the point we decide to drop it. The real error\n * still propagates, from the `await versionPromise` below, exactly where it\n * did when this function awaited the version directly.\n */\n const composed = composeNodesWithChrome({\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n hostId,\n // Version-first (key-present wins, null = explicitly no layout), screen\n // fallback — resolved as a promise so only the layout-chain walk waits on\n // the version read; the rest of the chrome bundle keeps the AGL-1428\n // overlap. A failed version read falls back to the screen binding; the\n // whole compose is discarded on that path anyway.\n layoutId: versionPromise.then(\n (res) =>\n res.version && 'layoutId' in res.version\n ? ((res.version as Aglyn.AglynScreenVersion).layoutId as\n | string\n | null)\n : (screen.layoutId as string | undefined),\n () => screen.layoutId as string | undefined,\n ),\n // The screen's values for its layouts' properties (AGL-2893), beside the\n // binding on the same document; a failed read renders the defaults.\n layoutPropValues: versionPromise.then(\n (res) =>\n (res.version as Aglyn.AglynScreenVersion | undefined)?.layoutPropValues,\n () => undefined,\n ),\n // …and its per-page restyling of their elements (AGL-3286), from the same\n // document; a failed read renders the layouts' own styling.\n layoutStyleOverrides: versionPromise.then(\n (res) =>\n (res.version as Aglyn.AglynScreenVersion | undefined)\n ?.layoutStyleOverrides,\n () => undefined,\n ),\n screenNodes: versionPromise.then(\n (res) => (res.version?.nodes ?? {}) as any,\n () => ({}) as any,\n ),\n tokens: options.tokens,\n collection: options.collection,\n host: options.host,\n socialImages: options.socialImages,\n })\n void composed.catch(() => undefined)\n\n const versionRes = await versionPromise\n if (versionRes.error || !versionRes.version) return null\n\n /*\n * THE PAGE PHISHING REVIEW (AGL-3356).\n *\n * Every way a page goes live — a toolbar publish, a versions-panel\n * publish, a scheduled publish, a component or form promoted under it, an\n * experiment variant, an edit to the live version in place — meets here,\n * with the page exactly as a visitor will receive it. So this is where a\n * page that links to a brand's lookalike, asks for a password or a card\n * in a field of its own, or (for a new workspace) dresses a brand's\n * sign-in is held rather than served. See `hosted-page-review.ts`.\n *\n * A held version serves the last version this page served clean, screened\n * again, or nothing.\n */\n const nodes = await composed\n const version = versionRes.version as Aglyn.AglynScreenVersion\n const review = await reviewHostedPage({\n hostId,\n screenId,\n versionId,\n nodes,\n // Named by what it is, not only its id (AGL-3374).\n page: {\n screen: {\n displayName: (screen as { displayName?: unknown }).displayName,\n name: (screen as { name?: unknown }).name,\n kind: (screen as { kind?: unknown }).kind,\n },\n template: options.page?.template ?? null,\n variant: options.page?.variant ?? null,\n parts: () =>\n composedPageParts({\n hostId,\n screenId,\n screenNodes: (version?.nodes ?? {}) as Record<string, any>,\n layoutId:\n version && 'layoutId' in version\n ? (version.layoutId as string | null)\n : (screen.layoutId as string | undefined),\n }),\n },\n })\n if (review.outcome === 'serve') {\n // Only the PUBLISHED version is the page's last clean one; a variant or\n // a pinned version is not what the page serves.\n if (nodes && !options.versionId) {\n await recordServedPageVersion(hostId, screenId, versionId)\n }\n return nodes\n }\n if (options.pageReviewFallback === false) return null\n const previous = await servedPageVersion(hostId, screenId)\n if (!previous || previous === versionId) return null\n return composeScreenNodes({\n ...options,\n versionId: previous,\n pageReviewFallback: false,\n })\n}\n\nexport default composeScreenNodes\n"],"names":["Aglyn","applyMediaAssetFacts","mediaAssetRefs","recordServedPageVersion","reviewHostedPage","servedPageVersion","applyDuePublishSchedule","getComponents","getDatasets","getForms","getMediaAssetFacts","getPublishedCollectionSource","getPluginInstalls","getVariables","getFunctions","getWorkflows","getPublishedLayoutVersion","getScreenVersion","socialImageAssetFacts","socialImageRefs","stampFormDatasetBindings","scanCollectionBlocks","nodes","collection","slugs","Set","hasRelated","hasCategories","hasSearch","node","Object","values","componentId","COLLECTION_ENTRIES_COMPONENT_ID","slug","String","props","collectionSlug","trim","add","COLLECTION_CATEGORIES_COMPONENT_ID","COLLECTION_SEARCH_COMPONENT_ID","COLLECTION_RELATED_COMPONENT_ID","entry","prefetchCollectionSources","hostId","screenNodes","prefetched","entries","pending","catch","undefined","expandCollectionEntryBlocks","timeZone","size","sources","Promise","all","map","categories","page","entriesReachedBound","reachedBound","windowStart","fetched","expanded","expandCollectionEntries","withCategories","expandCollectionCategories","routeless","categorySlug","withSearch","expandCollectionSearch","expandCollectionRelated","composeNodesWithChrome","options","layoutId","walkLayoutChain","chain","seen","boundLayoutId","currentLayoutId","has","length","MAX_LAYOUT_CHAIN_DEPTH","layoutRes","push","version","parentId","layout","chromeBundle","screenDatasetKeys","repeatDatasetKeys","screenDatasetsPromise","keys","screenFormsPromise","placesFormEntity","prefetchedSources","layoutChain","componentsRes","bulk","rawVariables","functions","workflows","pluginInstalls","screenDatasets","layoutPropValues","layoutStyleOverrides","composedNodes","composeLayoutChainWithProps","graftedComponents","composeReusableComponentNodes","definitions","forms","grafted","placedFormPlacement","variables","resolveComputedVariables","datasetKeys","unreadDatasetKeys","filter","key","includes","datasets","repeated","expandRepeatables","withEntries","withEntryMeta","expandCollectionEntryMeta","withEntryAuthor","expandCollectionEntryAuthor","bound","resolveNodesBindings","withHostTokens","resolveNodesHostTokens","host","withFunctions","attachFunctionDefinitions","attachPluginInstalls","finalNodes","resolveNamedTokens","tokens","withLandmark","stampDocumentLandmark","withFormBindings","denormalized","canvas","processNodesToDenormalized","socialImages","cardRefs","images","refs","facts","cardFacts","onFacts","composedPageParts","parts","type","id","screenId","name","displayName","used","frontier","part","next","definition","some","nodesReferenceComponent","composeScreenNodes","screen","effectiveVersionId","versionId","collectionName","docId","parent","versionPromise","composed","then","res","versionRes","error","review","kind","template","variant","outcome","pageReviewFallback","previous"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,YAAYA,WAAW,sBAAqB;AAC5C,uEAAuE;AACvE,sDAAsD;AACtD,SACEC,oBAAoB,EACpBC,cAAc,QACT,2CAA0C;AACjD,SACEC,uBAAuB,EACvBC,gBAAgB,EAChBC,iBAAiB,QACZ,qDAAoD;AAE3D,OAAOC,6BAA6B,8BAA0B;AAC9D,OAAOC,mBAAmB,sBAAkB;AAC5C,OAAOC,iBAAiB,oBAAgB;AACxC,OAAOC,cAAc,iBAAa;AAClC,OAAOC,wBAAwB,6BAAyB;AACxD,SACEC,4BAA4B,QAEvB,8BAA0B;AACjC,OAAOC,uBAAuB,2BAAuB;AACrD,OAAOC,gBAAgBC,YAAY,EAAEC,YAAY,QAAQ,qBAAiB;AAC1E,OAAOC,+B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