@aglyn/aglyn 1.23.1 → 1.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/package.json +11 -11
  2. package/src/lib/app-utils/activity-labels.js +4 -1
  3. package/src/lib/app-utils/activity-labels.js.map +1 -1
  4. package/src/lib/app-utils/activity-presenter.d.ts +11 -0
  5. package/src/lib/app-utils/activity-presenter.js +9 -0
  6. package/src/lib/app-utils/activity-presenter.js.map +1 -1
  7. package/src/lib/app-utils/activity-search.d.ts +1 -0
  8. package/src/lib/app-utils/activity-search.js +1 -0
  9. package/src/lib/app-utils/activity-search.js.map +1 -1
  10. package/src/lib/app-utils/agent-api-catalog.d.ts +18 -0
  11. package/src/lib/app-utils/agent-api-catalog.js +8 -1
  12. package/src/lib/app-utils/agent-api-catalog.js.map +1 -1
  13. package/src/lib/app-utils/binding-token-catalog.d.ts +15 -0
  14. package/src/lib/app-utils/binding-token-catalog.js +16 -0
  15. package/src/lib/app-utils/binding-token-catalog.js.map +1 -1
  16. package/src/lib/app-utils/business-details.d.ts +5 -0
  17. package/src/lib/app-utils/business-details.js +4 -0
  18. package/src/lib/app-utils/business-details.js.map +1 -1
  19. package/src/lib/app-utils/connector-discovery.d.ts +80 -0
  20. package/src/lib/app-utils/connector-discovery.js +107 -0
  21. package/src/lib/app-utils/connector-discovery.js.map +1 -0
  22. package/src/lib/app-utils/crm.d.ts +17 -30
  23. package/src/lib/app-utils/crm.js +139 -3
  24. package/src/lib/app-utils/crm.js.map +1 -1
  25. package/src/lib/app-utils/docs-help-sections.generated.js +5 -1
  26. package/src/lib/app-utils/docs-help-sections.generated.js.map +1 -1
  27. package/src/lib/app-utils/docs-help.generated.d.ts +5 -5
  28. package/src/lib/app-utils/docs-help.generated.js +12 -3
  29. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  30. package/src/lib/app-utils/docs-index.generated.js +149 -9
  31. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  32. package/src/lib/app-utils/entity-picker-context.d.ts +6 -0
  33. package/src/lib/app-utils/entity-picker-context.js.map +1 -1
  34. package/src/lib/app-utils/expand-repeatables.js +25 -2
  35. package/src/lib/app-utils/expand-repeatables.js.map +1 -1
  36. package/src/lib/app-utils/host-tokens.d.ts +17 -0
  37. package/src/lib/app-utils/host-tokens.js +18 -0
  38. package/src/lib/app-utils/host-tokens.js.map +1 -1
  39. package/src/lib/app-utils/native-app-association.d.ts +9 -5
  40. package/src/lib/app-utils/native-app-association.js +10 -5
  41. package/src/lib/app-utils/native-app-association.js.map +1 -1
  42. package/src/lib/app-utils/native-nav.js +1 -1
  43. package/src/lib/app-utils/native-nav.js.map +1 -1
  44. package/src/lib/app-utils/organizations.js +4 -2
  45. package/src/lib/app-utils/organizations.js.map +1 -1
  46. package/src/lib/app-utils/plan-entitlements.d.ts +227 -36
  47. package/src/lib/app-utils/plan-entitlements.js +335 -43
  48. package/src/lib/app-utils/plan-entitlements.js.map +1 -1
  49. package/src/lib/app-utils/plugin-release-flags.generated.js +2 -2
  50. package/src/lib/app-utils/plugin-release-flags.generated.js.map +1 -1
  51. package/src/lib/app-utils/reusable-component-keys.d.ts +9 -0
  52. package/src/lib/app-utils/reusable-component-keys.js +9 -0
  53. package/src/lib/app-utils/reusable-component-keys.js.map +1 -1
  54. package/src/lib/app-utils/server.d.ts +1 -0
  55. package/src/lib/app-utils/server.js +1 -0
  56. package/src/lib/app-utils/server.js.map +1 -1
  57. package/src/lib/app-utils/sign-in-visibility.d.ts +78 -0
  58. package/src/lib/app-utils/sign-in-visibility.js +79 -0
  59. package/src/lib/app-utils/sign-in-visibility.js.map +1 -0
  60. package/src/lib/app-utils/site-live-url.d.ts +4 -1
  61. package/src/lib/app-utils/site-live-url.js +17 -3
  62. package/src/lib/app-utils/site-live-url.js.map +1 -1
  63. package/src/lib/app-utils/usage-level.d.ts +50 -0
  64. package/src/lib/app-utils/usage-level.js +94 -0
  65. package/src/lib/app-utils/usage-level.js.map +1 -0
  66. package/src/lib/foundation/definitions/org-billing.types.d.ts +24 -2
  67. package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
  68. package/src/lib/plugin-manager/plugin-contact-capture.d.ts +2 -0
  69. package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
@@ -9,6 +9,12 @@ export interface EntityOption {
9
9
  * name rather than the id still matches by the name.
10
10
  */
11
11
  name?: string;
12
+ /**
13
+ * For an entity's FIELD (`entityFields`), the named type it holds where it
14
+ * has one: `icon` for a record's icon (AGL-4190), which only an Icon
15
+ * picker may bind.
16
+ */
17
+ customType?: string;
12
18
  }
13
19
  /**
14
20
  * Edit-time option lists for id-based entity pickers in component
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/entity-picker-context.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// Same placement rationale as screen-link-context.ts: lives in\n// @aglyn/aglyn without a 'use client' banner so canvas-rendering surfaces\n// share one module graph.\nimport { createContext } from 'react'\n\nexport interface EntityOption {\n /** Stable document id — the persisted reference (AGL-343/344). */\n id: string\n /** Current display name, resolved at edit time. */\n label: string\n /**\n * The entity's own name, where `label` says more than it (AGL-4047): two\n * of one name are labelled apart by their owner, and a node that stored the\n * name rather than the id still matches by the name.\n */\n name?: string\n}\n\n/**\n * Edit-time option lists for id-based entity pickers in component\n * attributes — every kind a plugin declares (a site's products, its forms,\n * the organization's datasets…). Names are display-only; nodes persist the id, so renames never break references —\n * the same contract as {@link ScreenLinkContext}. Provided by the\n * console's besigner/preview surfaces; absent on the tenant (the tenant\n * only resolves ids, never lists them).\n */\n/**\n * A kind of entity a picker lists, as the plugin that keeps it declares it\n * (`plugin-manager/plugin-entity-pickers`): `products`, `forms`, `datasets`…\n * Open, because the kinds are the plugins' to add (AGL-3080).\n */\nexport type EntityPickerKind = string\n\n/**\n * How much an empty list is worth believing.\n *\n * Every one of these renders as a dropdown with no entries, and an author\n * looking at four identical empty dropdowns cannot tell \"this site has no\n * forms yet\" from \"the read failed\" from \"this editor never lists forms at\n * all\". Only the first of those is a fact about their site; the other two\n * are the picker being broken, and a picker that cannot say which it is\n * sends the author looking for a form they already made.\n *\n * - `unavailable` — no provider is mounted, so nothing on this surface can\n * list entities. The tenant, and any editor outside a host.\n * - `loading` — a read is open or about to be, and no answer has arrived.\n * Also the state of a list nothing has asked for yet: demand is declared\n * on the same commit that would display it, so \"not asked\" and \"asked,\n * unanswered\" are the same beat.\n * - `ready` — the read settled. An empty list here IS the site's answer.\n * - `error` — the read failed. Empty means nothing.\n */\nexport type EntityListState = 'unavailable' | 'loading' | 'ready' | 'error'\n\n/**\n * How many documents a picker BROWSES.\n *\n * A picker is not a catalog viewer. It is a dropdown on a besigner surface\n * where the author is placing one element, and no table in the console offers\n * a page past `TABLE_PAGE_SIZE_OPTIONS` — a dropdown is the smaller surface of\n * the two, not the larger.\n *\n * The middle of that range rather than its floor: a table has a pager under it\n * and a dropdown does not, so the page a reader cannot advance is worth more\n * rows than the one they can.\n *\n * What makes this size SAFE is that browsing is the only job it does. A stored\n * value is named by {@link EntityPickerContextValue.resolve} — one keyed read\n * for the one document, exact at any catalog size — so nothing here has to be\n * wide enough to contain whatever an author picked last month. A window that\n * carried both jobs would have to be, and would still render a bound element\n * as unbound past its own width; widening this cannot fix that, only make it\n * rarer and more expensive.\n */\nexport const ENTITY_PICKER_BROWSE_LIMIT = 25\n\n/**\n * How many documents a server-side name search may return.\n *\n * The same size as the browse window, for the same reason: a reader who has\n * typed a query and still faces 25 rows narrows it further rather than\n * scrolling. Only the kinds in {@link EntityPickerContextValue.searchable}\n * spend this at all.\n */\nexport const ENTITY_PICKER_SEARCH_LIMIT = 25\n\nexport interface EntityPickerContextValue {\n /**\n * Each kind's browse list, id-first: the site's products for a\n * `PRODUCT_SELECT`, its form entities for a `FORM_SELECT`, and every other\n * kind a plugin declares, keyed by the kind.\n */\n options?: Readonly<Partial<Record<EntityPickerKind, EntityOption[]>>>\n /**\n * The fields an entity's documents declare, keyed by kind and then by\n * entity id, in the order the entity declares them: id = the stable field\n * id a node persists, label = its current display name (AGL-556).\n *\n * Only kinds whose documents carry a field model appear. Two surfaces read\n * it: a field picker that maps a value onto one of an entity's fields (a\n * form field's \"Maps to schema field\"), and the insert-token menu inside a\n * repeat, which offers `{{item.<field>}}` for each field of the entity the\n * repeat names (see `RepeatSource.entityKind`).\n */\n entityFields?: Partial<\n Record<EntityPickerKind, Readonly<Record<string, EntityOption[]>>>\n >\n /**\n * Declare that a picker of this kind is on screen (AGL-703).\n *\n * The provider reads these lists from Firestore, and it used to read ALL of\n * them the moment the besigner opened — up to 300 products, 200 catalog\n * collections, 200 categories and 200 datasets, on a site with a real\n * catalog, for pickers most editing sessions never open. Nothing about\n * moving a heading needs the product list.\n *\n * So the lists are demand-driven now, and the demand signal is the thing\n * that would DISPLAY one: a selected node whose schema declares a\n * `PRODUCT_SELECT`, a repeat bound to a dataset. Call this when that is\n * true and read the list on the render after; until then the list is\n * absent, exactly as it is for the beat before any listener syncs.\n *\n * Optional, and absent on the tenant — which resolves ids and never lists\n * them, so nothing there has a picker to ask for.\n */\n request?: (kind: EntityPickerKind) => void\n /**\n * Per-kind read state, so a picker can say WHY it has nothing to offer.\n * A kind the provider omits reads as `loading`; see {@link entityListState}.\n */\n status?: Partial<Record<EntityPickerKind, EntityListState>>\n /**\n * The browse window came back FULL for this kind, so the list above is a\n * page of the site's catalog and not the whole of it.\n *\n * Measured with a probe — the read asks for one document past\n * {@link ENTITY_PICKER_BROWSE_LIMIT} and the extra one is never offered —\n * so this is a fact about the collection rather than a guess from the\n * window being exactly full.\n *\n * A picker owes the reader this sentence for the same reason the inbox's\n * form filter does: \"not in the picker\" and \"does not exist\" are the same\n * empty dropdown, and only one of them is a fact about their site.\n */\n truncated?: Partial<Record<EntityPickerKind, boolean>>\n /**\n * This kind's documents carry the name-search keys, so a typed query\n * reaches the WHOLE collection rather than only the browse window.\n *\n * True for a kind its declaration marks `searchable`, whose documents carry\n * `nameTokens`/`nameLower` from the owner's own write path —\n * `hosts/{host}/resources` deliberately does not stamp them. A picker for a\n * kind that is absent here must say its search covers the window only —\n * claiming otherwise would let an unfound entity read as a nonexistent one.\n */\n searchable?: Partial<Record<EntityPickerKind, boolean>>\n /**\n * Narrow this kind's offered list to what somebody typed.\n *\n * Matching is the provider's, not the dropdown's: it is the only side that\n * can merge the window's own matches with the ones a server query found\n * past it, and it uses `scoreMatch` so a query matches a word ANYWHERE in a\n * name — the same rule the switchers and global search follow.\n *\n * Passing an empty string restores the browse window.\n */\n search?: (kind: EntityPickerKind, text: string) => void\n /**\n * Resolve ONE stored id to its current name, whatever the browse window\n * holds.\n *\n * Deliberately NOT a job for the browse list, though a bulk read could do\n * both. Sharing one read makes the list's width the limit on which stored\n * values can be named, and past that width a picker renders a bound element\n * as UNBOUND rather than as its label — an empty control on an element that\n * is set, which an author repairs by picking again. That is how a correct\n * reference gets replaced with a different one.\n *\n * One keyed `getDoc` for one document instead: exact at any catalog size,\n * and asked for only when a node actually carries a value. Results land in\n * {@link resolved} and are never re-read.\n */\n resolve?: (kind: EntityPickerKind, id: string) => void\n /**\n * What {@link resolve} found, keyed by kind and then by id.\n *\n * Three states, and the picker renders a different label for each: an\n * `EntityOption` is the resolved name, `null` is a settled read that found\n * NO such document, and an absent key is a resolution still in flight.\n * Absent must never render as missing — a picker that flashed \"unavailable\"\n * over every live reference for the beat before its read landed would teach\n * authors to ignore the one warning that matters.\n */\n resolved?: Partial<\n Record<EntityPickerKind, Readonly<Record<string, EntityOption | null>>>\n >\n}\n\n/**\n * What the picker for `kind` should believe about its own emptiness.\n *\n * `request` is the \"a provider is mounted\" signal — it is the one member the\n * contract already says is absent wherever nothing lists entities — so a\n * surface with no provider resolves to `unavailable` rather than passing an\n * empty list off as the site's answer.\n */\nexport function entityListState(\n context: EntityPickerContextValue | undefined,\n kind: EntityPickerKind,\n): EntityListState {\n if (!context?.request) return 'unavailable'\n return context.status?.[kind] ?? 'loading'\n}\n\n/**\n * The id whose label a picker still needs a keyed read to learn, if any.\n *\n * Part of the contract rather than of one screen, because two surfaces ask\n * it — the attributes panel about a node's picker value, and the insert-token\n * menu about the dataset a repeat is bound to — and an answer that differed\n * between them would be a second keyed read for a document one of them\n * already had.\n *\n * Four cases resolve to \"ask nobody\", and each is a read not spent: there is\n * no value; the browse window already carries it, which is the common case on\n * a small site; a resolution has already answered, including the answer that\n * the document is gone; or the browse read has not settled, so the window may\n * be about to supply it for free.\n *\n * The last is the one worth stating. Asking while the listener is still\n * loading would spend a keyed read on nearly every picker on every site,\n * which is the cost splitting these two jobs exists to remove rather than to\n * move.\n */\nexport function entityValueNeedsResolution(\n context: EntityPickerContextValue | undefined,\n kind: EntityPickerKind,\n value: unknown,\n): string | undefined {\n const id = typeof value === 'string' ? value.trim() : ''\n if (!id || !context?.resolve) return undefined\n if ((context.options?.[kind] ?? []).some((entity) => entity.id === id)) return undefined\n if (id in (context.resolved?.[kind] ?? {})) return undefined\n if (entityListState(context, kind) !== 'ready') return undefined\n return id\n}\n\nexport const EntityPickerContext = createContext<EntityPickerContextValue>({})\nEntityPickerContext.displayName = 'EntityPickerContext'\n"],"names":["createContext","ENTITY_PICKER_BROWSE_LIMIT","ENTITY_PICKER_SEARCH_LIMIT","entityListState","context","kind","request","status","entityValueNeedsResolution","value","id","trim","resolve","undefined","options","some","entity","resolved","EntityPickerContext","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD,+DAA+D;AAC/D,0EAA0E;AAC1E,0BAA0B;AAC1B,SAASA,aAAa,QAAQ,QAAO;AAmDrC;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,MAAMC,6BAA6B,GAAE;AAE5C;;;;;;;CAOC,GACD,OAAO,MAAMC,6BAA6B,GAAE;AAkH5C;;;;;;;CAOC,GACD,OAAO,SAASC,gBACdC,OAA6C,EAC7CC,IAAsB;;QAGfD;IADP,IAAI,EAACA,2BAAAA,QAASE,OAAO,GAAE,OAAO;IAC9B,gBAAOF,kBAAAA,QAAQG,MAAM,qBAAdH,eAAgB,CAACC,KAAK,mBAAI;AACnC;AAEA;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASG,2BACdJ,OAA6C,EAC7CC,IAAsB,EACtBI,KAAc;;QAITL,kBACMA;IAHX,MAAMM,KAAK,OAAOD,UAAU,WAAWA,MAAME,IAAI,KAAK;IACtD,IAAI,CAACD,MAAM,EAACN,2BAAAA,QAASQ,OAAO,GAAE,OAAOC;IACrC,IAAI,UAACT,mBAAAA,QAAQU,OAAO,qBAAfV,gBAAiB,CAACC,KAAK,mBAAI,EAAE,EAAEU,IAAI,CAAC,CAACC,SAAWA,OAAON,EAAE,KAAKA,KAAK,OAAOG;IAC/E,IAAIH,iBAAON,oBAAAA,QAAQa,QAAQ,qBAAhBb,iBAAkB,CAACC,KAAK,oBAAI,CAAC,IAAI,OAAOQ;IACnD,IAAIV,gBAAgBC,SAASC,UAAU,SAAS,OAAOQ;IACvD,OAAOH;AACT;AAEA,OAAO,MAAMQ,sBAAsBlB,cAAwC,CAAC,GAAE;AAC9EkB,oBAAoBC,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/entity-picker-context.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// Same placement rationale as screen-link-context.ts: lives in\n// @aglyn/aglyn without a 'use client' banner so canvas-rendering surfaces\n// share one module graph.\nimport { createContext } from 'react'\n\nexport interface EntityOption {\n /** Stable document id — the persisted reference (AGL-343/344). */\n id: string\n /** Current display name, resolved at edit time. */\n label: string\n /**\n * The entity's own name, where `label` says more than it (AGL-4047): two\n * of one name are labelled apart by their owner, and a node that stored the\n * name rather than the id still matches by the name.\n */\n name?: string\n /**\n * For an entity's FIELD (`entityFields`), the named type it holds where it\n * has one: `icon` for a record's icon (AGL-4190), which only an Icon\n * picker may bind.\n */\n customType?: string\n}\n\n/**\n * Edit-time option lists for id-based entity pickers in component\n * attributes — every kind a plugin declares (a site's products, its forms,\n * the organization's datasets…). Names are display-only; nodes persist the id, so renames never break references —\n * the same contract as {@link ScreenLinkContext}. Provided by the\n * console's besigner/preview surfaces; absent on the tenant (the tenant\n * only resolves ids, never lists them).\n */\n/**\n * A kind of entity a picker lists, as the plugin that keeps it declares it\n * (`plugin-manager/plugin-entity-pickers`): `products`, `forms`, `datasets`…\n * Open, because the kinds are the plugins' to add (AGL-3080).\n */\nexport type EntityPickerKind = string\n\n/**\n * How much an empty list is worth believing.\n *\n * Every one of these renders as a dropdown with no entries, and an author\n * looking at four identical empty dropdowns cannot tell \"this site has no\n * forms yet\" from \"the read failed\" from \"this editor never lists forms at\n * all\". Only the first of those is a fact about their site; the other two\n * are the picker being broken, and a picker that cannot say which it is\n * sends the author looking for a form they already made.\n *\n * - `unavailable` — no provider is mounted, so nothing on this surface can\n * list entities. The tenant, and any editor outside a host.\n * - `loading` — a read is open or about to be, and no answer has arrived.\n * Also the state of a list nothing has asked for yet: demand is declared\n * on the same commit that would display it, so \"not asked\" and \"asked,\n * unanswered\" are the same beat.\n * - `ready` — the read settled. An empty list here IS the site's answer.\n * - `error` — the read failed. Empty means nothing.\n */\nexport type EntityListState = 'unavailable' | 'loading' | 'ready' | 'error'\n\n/**\n * How many documents a picker BROWSES.\n *\n * A picker is not a catalog viewer. It is a dropdown on a besigner surface\n * where the author is placing one element, and no table in the console offers\n * a page past `TABLE_PAGE_SIZE_OPTIONS` — a dropdown is the smaller surface of\n * the two, not the larger.\n *\n * The middle of that range rather than its floor: a table has a pager under it\n * and a dropdown does not, so the page a reader cannot advance is worth more\n * rows than the one they can.\n *\n * What makes this size SAFE is that browsing is the only job it does. A stored\n * value is named by {@link EntityPickerContextValue.resolve} — one keyed read\n * for the one document, exact at any catalog size — so nothing here has to be\n * wide enough to contain whatever an author picked last month. A window that\n * carried both jobs would have to be, and would still render a bound element\n * as unbound past its own width; widening this cannot fix that, only make it\n * rarer and more expensive.\n */\nexport const ENTITY_PICKER_BROWSE_LIMIT = 25\n\n/**\n * How many documents a server-side name search may return.\n *\n * The same size as the browse window, for the same reason: a reader who has\n * typed a query and still faces 25 rows narrows it further rather than\n * scrolling. Only the kinds in {@link EntityPickerContextValue.searchable}\n * spend this at all.\n */\nexport const ENTITY_PICKER_SEARCH_LIMIT = 25\n\nexport interface EntityPickerContextValue {\n /**\n * Each kind's browse list, id-first: the site's products for a\n * `PRODUCT_SELECT`, its form entities for a `FORM_SELECT`, and every other\n * kind a plugin declares, keyed by the kind.\n */\n options?: Readonly<Partial<Record<EntityPickerKind, EntityOption[]>>>\n /**\n * The fields an entity's documents declare, keyed by kind and then by\n * entity id, in the order the entity declares them: id = the stable field\n * id a node persists, label = its current display name (AGL-556).\n *\n * Only kinds whose documents carry a field model appear. Two surfaces read\n * it: a field picker that maps a value onto one of an entity's fields (a\n * form field's \"Maps to schema field\"), and the insert-token menu inside a\n * repeat, which offers `{{item.<field>}}` for each field of the entity the\n * repeat names (see `RepeatSource.entityKind`).\n */\n entityFields?: Partial<\n Record<EntityPickerKind, Readonly<Record<string, EntityOption[]>>>\n >\n /**\n * Declare that a picker of this kind is on screen (AGL-703).\n *\n * The provider reads these lists from Firestore, and it used to read ALL of\n * them the moment the besigner opened — up to 300 products, 200 catalog\n * collections, 200 categories and 200 datasets, on a site with a real\n * catalog, for pickers most editing sessions never open. Nothing about\n * moving a heading needs the product list.\n *\n * So the lists are demand-driven now, and the demand signal is the thing\n * that would DISPLAY one: a selected node whose schema declares a\n * `PRODUCT_SELECT`, a repeat bound to a dataset. Call this when that is\n * true and read the list on the render after; until then the list is\n * absent, exactly as it is for the beat before any listener syncs.\n *\n * Optional, and absent on the tenant — which resolves ids and never lists\n * them, so nothing there has a picker to ask for.\n */\n request?: (kind: EntityPickerKind) => void\n /**\n * Per-kind read state, so a picker can say WHY it has nothing to offer.\n * A kind the provider omits reads as `loading`; see {@link entityListState}.\n */\n status?: Partial<Record<EntityPickerKind, EntityListState>>\n /**\n * The browse window came back FULL for this kind, so the list above is a\n * page of the site's catalog and not the whole of it.\n *\n * Measured with a probe — the read asks for one document past\n * {@link ENTITY_PICKER_BROWSE_LIMIT} and the extra one is never offered —\n * so this is a fact about the collection rather than a guess from the\n * window being exactly full.\n *\n * A picker owes the reader this sentence for the same reason the inbox's\n * form filter does: \"not in the picker\" and \"does not exist\" are the same\n * empty dropdown, and only one of them is a fact about their site.\n */\n truncated?: Partial<Record<EntityPickerKind, boolean>>\n /**\n * This kind's documents carry the name-search keys, so a typed query\n * reaches the WHOLE collection rather than only the browse window.\n *\n * True for a kind its declaration marks `searchable`, whose documents carry\n * `nameTokens`/`nameLower` from the owner's own write path —\n * `hosts/{host}/resources` deliberately does not stamp them. A picker for a\n * kind that is absent here must say its search covers the window only —\n * claiming otherwise would let an unfound entity read as a nonexistent one.\n */\n searchable?: Partial<Record<EntityPickerKind, boolean>>\n /**\n * Narrow this kind's offered list to what somebody typed.\n *\n * Matching is the provider's, not the dropdown's: it is the only side that\n * can merge the window's own matches with the ones a server query found\n * past it, and it uses `scoreMatch` so a query matches a word ANYWHERE in a\n * name — the same rule the switchers and global search follow.\n *\n * Passing an empty string restores the browse window.\n */\n search?: (kind: EntityPickerKind, text: string) => void\n /**\n * Resolve ONE stored id to its current name, whatever the browse window\n * holds.\n *\n * Deliberately NOT a job for the browse list, though a bulk read could do\n * both. Sharing one read makes the list's width the limit on which stored\n * values can be named, and past that width a picker renders a bound element\n * as UNBOUND rather than as its label — an empty control on an element that\n * is set, which an author repairs by picking again. That is how a correct\n * reference gets replaced with a different one.\n *\n * One keyed `getDoc` for one document instead: exact at any catalog size,\n * and asked for only when a node actually carries a value. Results land in\n * {@link resolved} and are never re-read.\n */\n resolve?: (kind: EntityPickerKind, id: string) => void\n /**\n * What {@link resolve} found, keyed by kind and then by id.\n *\n * Three states, and the picker renders a different label for each: an\n * `EntityOption` is the resolved name, `null` is a settled read that found\n * NO such document, and an absent key is a resolution still in flight.\n * Absent must never render as missing — a picker that flashed \"unavailable\"\n * over every live reference for the beat before its read landed would teach\n * authors to ignore the one warning that matters.\n */\n resolved?: Partial<\n Record<EntityPickerKind, Readonly<Record<string, EntityOption | null>>>\n >\n}\n\n/**\n * What the picker for `kind` should believe about its own emptiness.\n *\n * `request` is the \"a provider is mounted\" signal — it is the one member the\n * contract already says is absent wherever nothing lists entities — so a\n * surface with no provider resolves to `unavailable` rather than passing an\n * empty list off as the site's answer.\n */\nexport function entityListState(\n context: EntityPickerContextValue | undefined,\n kind: EntityPickerKind,\n): EntityListState {\n if (!context?.request) return 'unavailable'\n return context.status?.[kind] ?? 'loading'\n}\n\n/**\n * The id whose label a picker still needs a keyed read to learn, if any.\n *\n * Part of the contract rather than of one screen, because two surfaces ask\n * it — the attributes panel about a node's picker value, and the insert-token\n * menu about the dataset a repeat is bound to — and an answer that differed\n * between them would be a second keyed read for a document one of them\n * already had.\n *\n * Four cases resolve to \"ask nobody\", and each is a read not spent: there is\n * no value; the browse window already carries it, which is the common case on\n * a small site; a resolution has already answered, including the answer that\n * the document is gone; or the browse read has not settled, so the window may\n * be about to supply it for free.\n *\n * The last is the one worth stating. Asking while the listener is still\n * loading would spend a keyed read on nearly every picker on every site,\n * which is the cost splitting these two jobs exists to remove rather than to\n * move.\n */\nexport function entityValueNeedsResolution(\n context: EntityPickerContextValue | undefined,\n kind: EntityPickerKind,\n value: unknown,\n): string | undefined {\n const id = typeof value === 'string' ? value.trim() : ''\n if (!id || !context?.resolve) return undefined\n if ((context.options?.[kind] ?? []).some((entity) => entity.id === id)) return undefined\n if (id in (context.resolved?.[kind] ?? {})) return undefined\n if (entityListState(context, kind) !== 'ready') return undefined\n return id\n}\n\nexport const EntityPickerContext = createContext<EntityPickerContextValue>({})\nEntityPickerContext.displayName = 'EntityPickerContext'\n"],"names":["createContext","ENTITY_PICKER_BROWSE_LIMIT","ENTITY_PICKER_SEARCH_LIMIT","entityListState","context","kind","request","status","entityValueNeedsResolution","value","id","trim","resolve","undefined","options","some","entity","resolved","EntityPickerContext","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD,+DAA+D;AAC/D,0EAA0E;AAC1E,0BAA0B;AAC1B,SAASA,aAAa,QAAQ,QAAO;AAyDrC;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,MAAMC,6BAA6B,GAAE;AAE5C;;;;;;;CAOC,GACD,OAAO,MAAMC,6BAA6B,GAAE;AAkH5C;;;;;;;CAOC,GACD,OAAO,SAASC,gBACdC,OAA6C,EAC7CC,IAAsB;;QAGfD;IADP,IAAI,EAACA,2BAAAA,QAASE,OAAO,GAAE,OAAO;IAC9B,gBAAOF,kBAAAA,QAAQG,MAAM,qBAAdH,eAAgB,CAACC,KAAK,mBAAI;AACnC;AAEA;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,SAASG,2BACdJ,OAA6C,EAC7CC,IAAsB,EACtBI,KAAc;;QAITL,kBACMA;IAHX,MAAMM,KAAK,OAAOD,UAAU,WAAWA,MAAME,IAAI,KAAK;IACtD,IAAI,CAACD,MAAM,EAACN,2BAAAA,QAASQ,OAAO,GAAE,OAAOC;IACrC,IAAI,UAACT,mBAAAA,QAAQU,OAAO,qBAAfV,gBAAiB,CAACC,KAAK,mBAAI,EAAE,EAAEU,IAAI,CAAC,CAACC,SAAWA,OAAON,EAAE,KAAKA,KAAK,OAAOG;IAC/E,IAAIH,iBAAON,oBAAAA,QAAQa,QAAQ,qBAAhBb,iBAAkB,CAACC,KAAK,oBAAI,CAAC,IAAI,OAAOQ;IACnD,IAAIV,gBAAgBC,SAASC,UAAU,SAAS,OAAOQ;IACvD,OAAOH;AACT;AAEA,OAAO,MAAMQ,sBAAsBlB,cAAwC,CAAC,GAAE;AAC9EkB,oBAAoBC,WAAW,GAAG"}
@@ -24,7 +24,27 @@ import { readYesNoValue } from "./reusable-prop-values.js";
24
24
  * the depth guard, so cycles can't recurse.
25
25
  */ const ITEM_TOKEN_PATTERN = /\{\{\s*item\.([A-Za-z][A-Za-z0-9_]*)(?:\.([A-Za-z][A-Za-z0-9_]*))?\s*\}\}/g;
26
26
  /** Hard bound on rows a single repeatable renders, before `repeatLimit`. */ export const REPEAT_MAX_RECORDS = 100;
27
- const displayValue = (value)=>Array.isArray(value) ? value.join(', ') : String(value);
27
+ /**
28
+ * A plain object's part a token can name (AGL-4190): `{{item.icon.iconPath}}`
29
+ * reads the `iconPath` of a record's icon. Only text and numbers are parts;
30
+ * anything else is not something a page can print.
31
+ */ function plainObjectPart(value, key) {
32
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
33
+ if (!Object.prototype.hasOwnProperty.call(value, key)) return null;
34
+ const part = value[key];
35
+ return typeof part === 'string' || typeof part === 'number' ? String(part) : null;
36
+ }
37
+ /**
38
+ * A field's value as page text. A list is its entries, comma-joined. A map
39
+ * that names an icon (`{ iconId, iconPath }`, AGL-4190) is the icon's id,
40
+ * which is what an Icon element's icon holds; any other map is nothing,
41
+ * rather than the `[object Object]` a page would otherwise print.
42
+ */ const displayValue = (value)=>{
43
+ var _plainObjectPart;
44
+ if (Array.isArray(value)) return value.join(', ');
45
+ if (value && typeof value === 'object') return (_plainObjectPart = plainObjectPart(value, 'iconId')) != null ? _plainObjectPart : '';
46
+ return String(value);
47
+ };
28
48
  /** Resolves `{{item.ref.field}}`: FKey(s) → target document field value. */ function resolveReferenceHop(context, fieldId, targetFieldId) {
29
49
  var _context_model_references, _context_model, _context_datasetsByKey;
30
50
  const targetKey = (_context_model = context.model) == null ? void 0 : (_context_model_references = _context_model.references) == null ? void 0 : _context_model_references[fieldId];
@@ -48,7 +68,10 @@ function substituteValue(value, context) {
48
68
  const unresolved = (token)=>context.missing === 'empty' ? '' : token;
49
69
  return value.replace(ITEM_TOKEN_PATTERN, (token, field, hop)=>{
50
70
  if (hop) {
51
- const resolved = resolveReferenceHop(context, field, hop);
71
+ var _resolveReferenceHop;
72
+ // A reference's target field first (AGL-180); otherwise a part of
73
+ // the field's own map, such as an icon's path (AGL-4190).
74
+ const resolved = (_resolveReferenceHop = resolveReferenceHop(context, field, hop)) != null ? _resolveReferenceHop : plainObjectPart(record[field], hop);
52
75
  return resolved != null ? resolved : unresolved(token);
53
76
  }
54
77
  return record[field] != null ? displayValue(record[field]) : unresolved(token);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/expand-repeatables.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 type { AglynNodeSchema, NodeId } from '../foundation'\nimport {\n applyRepeatQuery,\n parseRepeatFilter,\n parseRepeatSort,\n} from './repeat-query'\nimport {\n NODE_HIDE_IF_PROP,\n NODE_HIDE_UNLESS_PROP,\n} from './reusable-component-keys'\nimport { readYesNoValue } from './reusable-prop-values'\n\n/** Namespaces cloned template ids per container/record. */\nexport const REPEAT_NODE_ID_PREFIX = 'rep__'\n\n/**\n * `{{item.field}}` token, plus an optional single reference hop\n * (`{{item.author.name}}`, AGL-180). One hop only — the pattern itself is\n * the depth guard, so cycles can't recurse.\n */\nconst ITEM_TOKEN_PATTERN =\n /\\{\\{\\s*item\\.([A-Za-z][A-Za-z0-9_]*)(?:\\.([A-Za-z][A-Za-z0-9_]*))?\\s*\\}\\}/g\n\n/** Hard bound on rows a single repeatable renders, before `repeatLimit`. */\nexport const REPEAT_MAX_RECORDS = 100\n\n/**\n * What the expansion reads of the rows' field model (AGL-177, AGL-180): which\n * fields are references, each with the key its target's rows are answered\n * under (`datasetsByKey`). The model itself is the plugin's that keeps the\n * rows, and it states this much of it when it hands the rows over\n * (`plugin-manager/repeat-rows`, `repeat-sources`); a field it does not name\n * here hops nowhere, and its token is left as written.\n */\nexport interface RepeatRowsModel {\n /** Reference field id → the key of the rows it points into. */\n references?: Readonly<Record<string, string>>\n}\n\nexport interface RepeatableDataset {\n /**\n * Row value maps, in display order. Rows carry `$id` (needed to resolve\n * incoming references); values may be typed (AGL-177), stringified at\n * substitution.\n */\n records: Array<Record<string, unknown>>\n /** The rows' references; required for reference-hop bindings. */\n model?: RepeatRowsModel\n}\n\ninterface SubstituteContext {\n record: Record<string, unknown>\n /** The repeated rows' references (AGL-180). */\n model?: RepeatRowsModel\n /** All host datasets keyed by id (and name) for hop resolution. */\n datasetsByKey?: Record<string, RepeatableDataset | undefined>\n /**\n * What a token whose field the record leaves empty becomes: `'token'` keeps\n * it as written (the besigner's canvas, where an author edits the template),\n * `'empty'` prints nothing (a rendered page, AGL-3616). A published page\n * never shows a visitor `{{item.venue}}` because one record has no venue.\n */\n missing?: 'token' | 'empty'\n}\n\nconst displayValue = (value: unknown): string =>\n Array.isArray(value) ? value.join(', ') : String(value)\n\n/** Resolves `{{item.ref.field}}`: FKey(s) → target document field value. */\nfunction resolveReferenceHop(\n context: SubstituteContext,\n fieldId: string,\n targetFieldId: string,\n): string | null {\n const targetKey = context.model?.references?.[fieldId]\n if (!targetKey) return null\n const target = context.datasetsByKey?.[targetKey]\n if (!target) return null\n const keys = context.record[fieldId]\n const ids = Array.isArray(keys) ? keys : keys != null ? [keys] : []\n const resolved = ids\n .map((id) => {\n const match = target.records.find((row) => row['$id'] === id)\n const value = match?.[targetFieldId]\n return value != null ? displayValue(value) : null\n })\n .filter((value): value is string => value != null)\n return resolved.length ? resolved.join(', ') : null\n}\n\nfunction substituteValue(\n value: unknown,\n context: SubstituteContext,\n): unknown {\n const { record } = context\n if (typeof value === 'string') {\n const unresolved = (token: string) =>\n context.missing === 'empty' ? '' : token\n return value.replace(\n ITEM_TOKEN_PATTERN,\n (token, field: string, hop?: string) => {\n if (hop) {\n const resolved = resolveReferenceHop(context, field, hop)\n return resolved != null ? resolved : unresolved(token)\n }\n return record[field] != null\n ? displayValue(record[field])\n : unresolved(token)\n },\n )\n }\n if (Array.isArray(value)) {\n return value.map((entry) => substituteValue(entry, context))\n }\n if (value && typeof value === 'object') {\n const next: Record<string, unknown> = {}\n for (const [key, entry] of Object.entries(value)) {\n next[key] = substituteValue(entry, context)\n }\n return next\n }\n return value\n}\n\n/** A text that is nothing but `{{item.*}}` tokens: a binding, not words. */\nconst WHOLE_BINDING = new RegExp(\n `^\\\\s*(?:${ITEM_TOKEN_PATTERN.source}\\\\s*)+$`,\n)\n\n/**\n * Whether a copy's element is a binding its record left empty (AGL-3616):\n * its text, `children`, or its picture, `src`, was only `{{item.*}}` tokens\n * and they printed nothing. The copy leaves the element out rather than\n * drawing an empty line (an eyebrow with no venue) or an empty frame (a card\n * whose record has no photo, AGL-3912), and a record that fills the field\n * draws it.\n */\nfunction isEmptyBinding(\n template: Record<string, unknown> | undefined,\n substituted: Record<string, unknown>,\n): boolean {\n return (['children', 'src'] as const).some((prop) => {\n const text = template?.[prop]\n if (typeof text !== 'string' || !WHOLE_BINDING.test(text)) return false\n const printed = substituted[prop]\n return typeof printed === 'string' && printed.trim() === ''\n })\n}\n\n/** One `{{item.*}}` token anywhere, without the global pattern's `lastIndex`. */\nconst ITEM_TOKEN_ANYWHERE = new RegExp(ITEM_TOKEN_PATTERN.source)\n\n/** Whether `text` holds a `{{item.*}}` token. */\nconst namesItemToken = (text: string): boolean => ITEM_TOKEN_ANYWHERE.test(text)\n\n/**\n * Whether a copy's element asks to be left out of it (AGL-4212): its\n * `hideIf` or `hideUnless` was bound to a `{{item.*}}` token, and this\n * record's value says so — `hideIf` a yes, `hideUnless` a no, an empty field\n * included. An owner's reply block bound `hideUnless: '{{item.reply}}'`\n * draws on the reviews that have one and on no other. A directive bound to\n * anything else is not the record's to answer, and is left to the graft and\n * the host prune that read it.\n */\nfunction isHiddenByRecord(\n template: Record<string, unknown> | undefined,\n substituted: Record<string, unknown>,\n): boolean {\n const reads = (prop: string, hiddenWhen: boolean) => {\n const bound = template?.[prop]\n return (\n typeof bound === 'string' &&\n namesItemToken(bound) &&\n readYesNoValue(substituted[prop]) === hiddenWhen\n )\n }\n return reads(NODE_HIDE_IF_PROP, true) || reads(NODE_HIDE_UNLESS_PROP, false)\n}\n\n/**\n * The prop a repeat over a plugin connection's synced record persists under\n * (AGL-4212): `<pluginIdentity>/<connectionId>` repeats once per item of the\n * record, `<pluginIdentity>/<connectionId>/fields` once for its summary\n * fields. Persisted — never rename.\n */\nexport const REPEAT_CONNECTION_PROP = 'repeatConnection'\n\n/**\n * What {@link repeatKey} puts before a {@link REPEAT_CONNECTION_PROP} value,\n * so a connection's key and a dataset's never name the same rows, and the\n * server's repeat-rows contract can route each to the plugin that answers it.\n */\nexport const REPEAT_CONNECTION_KEY_PREFIX = 'connection:'\n\n/**\n * The key a node repeats over, trimmed, or `''` when it repeats over nothing:\n * its `repeatDataset`, else {@link REPEAT_CONNECTION_KEY_PREFIX} and its\n * {@link REPEAT_CONNECTION_PROP} (AGL-4212).\n *\n * The one predicate every repeat question is asked through: the expansion, the\n * datasets-read gate below, the reusable-component graft that moves a\n * placement's repeat onto the element it becomes, and the besigner's preview\n * and badge. Two copies of it are how a `.trim()` on one side and not the\n * other becomes an empty list on a customer's page.\n */\nexport const repeatKey = (node: unknown): string => {\n const props = (node as { props?: Record<string, unknown> } | null)?.props\n const dataset = props?.['repeatDataset']\n const key = typeof dataset === 'string' ? dataset.trim() : ''\n if (key) return key\n const connection = props?.[REPEAT_CONNECTION_PROP]\n const value = typeof connection === 'string' ? connection.trim() : ''\n return value ? `${REPEAT_CONNECTION_KEY_PREFIX}${value}` : ''\n}\n\n/**\n * Makes an element that holds children repeat ITSELF, once per record, instead\n * of what is inside it (AGL-3111): a card whose contents are the design, rather\n * than a list whose contents are the item.\n *\n * Persisted in screen, layout and component documents — never rename. `'true'`\n * counts too, because a switch round-tripped through a text-shaped store comes\n * back as the string.\n */\nexport const REPEAT_SELF_PROP = 'repeatSelf'\n\n/**\n * Every prop that directs a repeat. They are instructions to the composition,\n * never attributes of the element: the expansion consumes them from every node\n * it expands and every copy it makes, so a published element never carries\n * one. Persisted — never rename.\n */\nexport const REPEAT_DIRECTIVE_PROPS: readonly string[] = [\n 'repeatDataset',\n REPEAT_CONNECTION_PROP,\n 'repeatLimit',\n 'repeatFilter',\n 'repeatSort',\n REPEAT_SELF_PROP,\n]\n\n/**\n * What a repeating node copies once per record (AGL-3111).\n *\n * - `children` — what is inside it. The node stays one element around the\n * copies: the list, grid or gallery they fill. This is how a Stack has\n * always repeated (AGL-103), and a stored Stack names neither scope.\n * - `self` — the node itself, with everything inside it. What a leaf and a\n * component instance repeat, and what any element carrying\n * {@link REPEAT_SELF_PROP} repeats.\n */\nexport type RepeatScope = 'self' | 'children'\n\n/**\n * Which scope a repeating node has, read off the node alone so the published\n * page's composition and the besigner decide it identically.\n *\n * {@link REPEAT_SELF_PROP} decides it whenever the node carries one, which is\n * every repeat the Attributes panel writes. Without one the node's own shape\n * decides, and it decides CONSERVATIVELY: anything that holds a child list —\n * a Stack, empty or not — keeps repeating its children, and only a node with\n * no child list at all repeats itself. A stored repeat predates the prop, so\n * this branch is the one that has to render it unchanged, and an author who\n * named a dataset before filling the container in would otherwise come back to\n * a hundred empty copies of it.\n *\n * A component instance never reaches that branch: the graft stamps the prop on\n * the element it becomes, whose children are the component's own.\n */\nexport function repeatScope(node: unknown): RepeatScope {\n const { props, nodes } = (node ?? {}) as {\n props?: Record<string, unknown>\n nodes?: unknown\n }\n // `'true'`/`'false'` too: a switch round-tripped through a text-shaped\n // store comes back as the string it was written as.\n const self = props?.[REPEAT_SELF_PROP]\n if (self === true || self === 'true') return 'self'\n if (self === false || self === 'false') return 'children'\n return Array.isArray(nodes) ? 'children' : 'self'\n}\n\n/**\n * One record's values put into `{{item.field}}` tokens, anywhere in a props\n * map — the substitution {@link expandRepeatables} makes on every copy it\n * builds, for a caller that already knows which record it is rendering.\n *\n * The besigner's canvas is that caller (AGL-3111): the element an author\n * edits IS the first copy, so it draws with the first record's values while\n * the node it saves keeps the tokens. Exported rather than reimplemented\n * because a canvas that resolved a token differently from the page would be\n * showing the author a page that does not exist.\n */\nexport function substituteRecordTokens<T>(\n props: T,\n context: {\n record: Record<string, unknown>\n /** The repeated rows' references (AGL-180). */\n model?: RepeatRowsModel\n /** Rows by key, for a one-hop reference (AGL-180). */\n datasetsByKey?: Record<string, RepeatableDataset | undefined>\n },\n): T {\n return substituteValue(props, context) as T\n}\n\n/**\n * The one record a whole page is rendered for (AGL-3475): a record template's\n * routed record, in the shape a repeat hands each of its copies.\n */\nexport interface PageRecordScope {\n record: Record<string, unknown>\n /** The record's references (AGL-180). */\n model?: RepeatRowsModel\n /** Rows by key, for a one-hop reference (AGL-180). */\n datasetsByKey?: Record<string, RepeatableDataset | undefined>\n}\n\n/**\n * Every node's props with the page's record put into its `{{item.field}}`\n * tokens — the substitution a repeat makes on each copy, made once over a\n * page that renders one record (AGL-3475).\n *\n * Run AFTER {@link expandRepeatables}: a repeat inside the page has already\n * spent its own `{{item.*}}` tokens on its own rows by then, so what is left\n * is the page's. A token naming a field the record leaves empty prints\n * nothing, exactly as in a repeat (AGL-3616). Returns the input when there is\n * no record.\n */\nexport function substituteNodesRecordTokens<N>(\n nodes: Record<NodeId, N>,\n scope: PageRecordScope | null | undefined,\n): Record<NodeId, N> {\n if (!scope) return nodes\n const next: Record<NodeId, N> = {}\n for (const [id, node] of Object.entries(nodes) as Array<[NodeId, N]>) {\n const props = (node as { props?: unknown })?.props\n next[id] = props\n ? ({\n ...node,\n props: substituteValue(props, { ...scope, missing: 'empty' }),\n } as N)\n : node\n }\n return next\n}\n\n/**\n * The page's record put into each repeat's FILTER, before the repeats expand\n * (AGL-3475): on a record template, `category == {{item.category}}` lists the\n * other records in the routed record's category. Only `repeatFilter` is\n * touched — everything else inside a repeat is its template, whose\n * `{{item.*}}` belongs to its own rows. Returns the input when there is no\n * record or no filter names one.\n */\nexport function substituteRepeatFilterRecordTokens<N>(\n nodes: Record<NodeId, N>,\n scope: PageRecordScope | null | undefined,\n): Record<NodeId, N> {\n if (!scope) return nodes\n let next: Record<NodeId, N> | null = null\n for (const [id, node] of Object.entries(nodes) as Array<[NodeId, N]>) {\n const props = (node as { props?: Record<string, unknown> })?.props\n const filter = props?.['repeatFilter']\n if (typeof filter !== 'string' || !filter.includes('{{')) continue\n next ??= { ...nodes }\n next[id] = {\n ...node,\n props: { ...props, repeatFilter: substituteValue(filter, scope) },\n } as N\n }\n return next ?? nodes\n}\n\n/** The node minus its repeat directives, or the node itself when it has none. */\nexport function withoutRepeatDirective<N>(node: N): N {\n const props = (node as { props?: Record<string, unknown> })?.props\n if (!props || !REPEAT_DIRECTIVE_PROPS.some((key) => key in props)) {\n return node\n }\n const kept = { ...props }\n for (const key of REPEAT_DIRECTIVE_PROPS) delete kept[key]\n return { ...node, props: kept }\n}\n\n/**\n * The records a repeating node renders, in order (AGL-181): its filter and sort\n * evaluated over the rows, then its limit, never past\n * {@link REPEAT_MAX_RECORDS}. An unparseable filter or sort fails open.\n *\n * Shared by the expansion and the besigner's canvas preview and badge, so the\n * canvas can never show a copy or a count the published page does not.\n */\nexport function repeatedRecords(\n node: unknown,\n dataset: RepeatableDataset | undefined,\n): Array<Record<string, unknown>> {\n const props = ((node as { props?: unknown })?.props ?? {}) as Record<\n string,\n unknown\n >\n const where = parseRepeatFilter(String(props['repeatFilter'] ?? ''))\n const orderBy = parseRepeatSort(String(props['repeatSort'] ?? ''))\n const limit = Number(props['repeatLimit'])\n return applyRepeatQuery(dataset?.records ?? [], {\n ...(where ? { where: [where] } : {}),\n ...(orderBy ? { orderBy } : {}),\n }).slice(\n 0,\n Number.isFinite(limit) && limit > 0\n ? Math.min(limit, REPEAT_MAX_RECORDS)\n : REPEAT_MAX_RECORDS,\n )\n}\n\n/**\n * Does this tree contain anything {@link expandRepeatables} would expand —\n * or, with no rows, empty?\n *\n * The rows read is the largest on the render path — up to two pages of\n * {@link REPEAT_MAX_RECORDS} records for every key a page repeats over — and a\n * page that repeats over nothing should pay none of it (AGL-1440).\n *\n * Any gate on that read has to ask EXACTLY the question the expansion asks,\n * which is why this and {@link repeatKeys} share the one predicate\n * `expandRepeatables` looks keys up with, {@link repeatKey}. A gate that is\n * even slightly stricter than the expansion is not a saving: it is a published\n * page whose repeat never reaches the expansion at all, and so goes out as\n * its raw template — `{{item.*}}` tokens and all — where the author put a list.\n */\nexport function hasRepeatableNodes(\n nodes: Record<NodeId, unknown> | null | undefined,\n): boolean {\n if (!nodes) return false\n return Object.values(nodes).some((node) => repeatKey(node) !== '')\n}\n\n/**\n * Every key this tree repeats over, exactly as {@link expandRepeatables} looks\n * it up — sorted and without repeats.\n *\n * What the tenant compose asks the repeat-rows contract for\n * (`plugin-manager/repeat-rows.ts`), so a page loads the rows it renders and\n * not everything its site may see. Built on the same predicate as\n * {@link hasRepeatableNodes} for the reason given there.\n */\nexport function repeatKeys(\n nodes: Record<NodeId, unknown> | null | undefined,\n): string[] {\n const keys = new Set<string>()\n for (const node of Object.values(nodes ?? {})) {\n const key = repeatKey(node)\n if (key) keys.add(key)\n }\n return [...keys].sort()\n}\n\n/**\n * Repeats (AGL-103, AGL-3111): any node carrying `props.repeatDataset` (a\n * dataset id or display name), or `props.repeatConnection` (a plugin\n * connection's synced record, AGL-4212), renders once per record, with\n * `{{item.field}}` tokens in the copied string props replaced by the record's\n * values. A field the record leaves empty prints nothing — never the raw\n * token — and an element whose whole text is such a binding is left out of\n * that copy (AGL-3616: a tour date with no venue drew `{{ITEM.VENUE}}` as its\n * eyebrow on a published site). The besigner's canvas keeps the tokens of\n * the template an author edits ({@link substituteRecordTokens}).\n *\n * What is copied is the node's {@link repeatScope}:\n *\n * - `children` — its children are the item template. The node stays, and its\n * child list becomes the copies, record by record. Its own props are not the\n * template, so no token in them is substituted.\n * - `self` — the node and everything inside it are the template. The copies\n * take the node's place in its parent's child list, and every prop in the\n * subtree is substituted, the node's own included.\n *\n * - Copy ids are namespaced `rep__{repeatId}__{index}__…` — the repeat's own\n * id, then the template node's — so repeats never collide, including inside\n * grafted reusable components. A self-scoped node's first copy is\n * `rep__{id}__0__{id}`. Run this AFTER `composeReusableComponentNodes` and\n * BEFORE binding resolution.\n * - Rows are the node's {@link repeatedRecords}, looked up under its\n * {@link repeatKey}.\n * - An element of a copy whose `hideIf` / `hideUnless` is bound to a\n * `{{item.*}}` token is left out of that copy, with everything inside it,\n * when the record's value says so (AGL-4212).\n * - The repeat directives ({@link REPEAT_DIRECTIVE_PROPS}) are consumed: every\n * node this expands, and every copy it makes, comes out without them.\n * - Repeats do not nest. A repeat inside another repeat's template is copied\n * with its directives consumed, so it renders once in each copy.\n * - No rows renders ZERO copies (AGL-3496): a `children` repeat keeps its\n * element with an empty child list, a `self` repeat leaves its parent's\n * list. That covers a filter matching nothing, an empty dataset, and a key\n * the rows answer nothing under — a deleted or unshared dataset, or no rows\n * map at all — because the template drawn without a record is its literal\n * `{{item.*}}` tokens, printed to every visitor. Never a throw: a dataset\n * going away empties a list, it does not take the page down.\n * - An empty template, or a self-scoped node its parent does not list (the\n * document root, say), has nothing to copy or nowhere to put copies, and is\n * left as written.\n * - Inputs are never mutated; templates stay in the map unreferenced.\n *\n * This is the PUBLISHED page's composition. The besigner's canvas keeps the\n * template on screen whatever the rows say — it is what an author edits — and\n * flags a repeat with no rows on its badge instead ({@link repeatedRecords}\n * is the count both read).\n */\nexport function expandRepeatables<N extends AglynNodeSchema = AglynNodeSchema>(\n nodes: Record<NodeId, N>,\n datasetsByKey: Record<string, RepeatableDataset | undefined> | undefined,\n): Record<NodeId, N> {\n const rowsByKey = datasetsByKey ?? {}\n const repeatIds = Object.entries(nodes).filter(\n ([, node]) => repeatKey(node) !== '',\n )\n if (!repeatIds.length) return nodes\n\n const next: Record<NodeId, N> = { ...nodes }\n for (const [repeatId, repeated] of repeatIds) {\n const dataset = rowsByKey[repeatKey(repeated)]\n const records = repeatedRecords(repeated, dataset)\n const self = repeatScope(repeated) === 'self'\n // The copies' parent: the node itself, or — for a self-scoped node — the\n // parent whose child list the copies take its place in, read from `next`\n // so two self-scoped siblings both land in the list the other has left.\n const parentId = (self ? repeated.parentId : repeatId) as NodeId\n const siblings = next[parentId]?.nodes\n const slot = Array.isArray(siblings)\n ? (siblings as NodeId[]).indexOf(repeatId)\n : -1\n const templateIds = self\n ? [repeatId]\n : Array.isArray(repeated.nodes)\n ? (repeated.nodes as NodeId[])\n : []\n next[repeatId] = withoutRepeatDirective(next[repeatId])\n if (!templateIds.length || (self && slot < 0)) continue\n if (!records.length) {\n // Zero copies (AGL-3496). The template is a design, not content: drawn\n // without a record it prints `{{item.name}}` to every visitor.\n if (self) {\n const listed = [...(next[parentId].nodes as NodeId[])]\n listed.splice(slot, 1)\n next[parentId] = { ...next[parentId], nodes: listed }\n } else {\n next[repeatId] = { ...next[repeatId], nodes: [] }\n }\n continue\n }\n\n const copyIds: NodeId[] = []\n records.forEach((record, index) => {\n const prefix = `${REPEAT_NODE_ID_PREFIX}${repeatId}__${index}__`\n const prefixId = (id: NodeId) => `${prefix}${id}`\n // Whether the copy drew the node: an element whose whole text is a\n // binding this record leaves empty is left out of it (AGL-3616).\n const cloneSubtree = (id: NodeId, clonedParentId: NodeId): boolean => {\n const node = nodes[id]\n if (!node) return false\n const props = substituteValue(node.props ?? {}, {\n record,\n model: dataset?.model,\n datasetsByKey: rowsByKey,\n missing: 'empty',\n }) as Record<string, unknown>\n const template = node.props as Record<string, unknown> | undefined\n if (\n isEmptyBinding(template, props) ||\n isHiddenByRecord(template, props)\n ) {\n return false\n }\n // Read, so not carried: a copy is drawn or left out, and the\n // directive that decided it has nothing left to say.\n for (const prop of [NODE_HIDE_IF_PROP, NODE_HIDE_UNLESS_PROP]) {\n const bound = template?.[prop]\n if (typeof bound === 'string' && namesItemToken(bound)) {\n delete props[prop]\n }\n }\n const clonedChildren = Array.isArray(node.nodes)\n ? (node.nodes as NodeId[])\n : undefined\n const drawn = clonedChildren?.filter((childId) =>\n cloneSubtree(childId, prefixId(id)),\n )\n next[prefixId(id)] = withoutRepeatDirective({\n ...node,\n $id: prefixId(id),\n parentId: clonedParentId,\n props: props as any,\n ...(drawn && {\n nodes: drawn.map((childId) => prefixId(childId)),\n }),\n })\n return true\n }\n for (const templateId of templateIds) {\n if (cloneSubtree(templateId, parentId)) {\n copyIds.push(prefixId(templateId))\n }\n }\n })\n if (self) {\n const listed = [...(next[parentId].nodes as NodeId[])]\n listed.splice(slot, 1, ...copyIds)\n next[parentId] = { ...next[parentId], nodes: listed }\n } else {\n next[repeatId] = { ...next[repeatId], nodes: copyIds }\n }\n }\n return next\n}\n\nexport default expandRepeatables\n"],"names":["applyRepeatQuery","parseRepeatFilter","parseRepeatSort","NODE_HIDE_IF_PROP","NODE_HIDE_UNLESS_PROP","readYesNoValue","REPEAT_NODE_ID_PREFIX","ITEM_TOKEN_PATTERN","REPEAT_MAX_RECORDS","displayValue","value","Array","isArray","join","String","resolveReferenceHop","context","fieldId","targetFieldId","targetKey","model","references","target","datasetsByKey","keys","record","ids","resolved","map","id","match","records","find","row","filter","length","substituteValue","unresolved","token","missing","replace","field","hop","entry","next","key","Object","entries","WHOLE_BINDING","RegExp","source","isEmptyBinding","template","substituted","some","prop","text","test","printed","trim","ITEM_TOKEN_ANYWHERE","namesItemToken","isHiddenByRecord","reads","hiddenWhen","bound","REPEAT_CONNECTION_PROP","REPEAT_CONNECTION_KEY_PREFIX","repeatKey","node","props","dataset","connection","REPEAT_SELF_PROP","REPEAT_DIRECTIVE_PROPS","repeatScope","nodes","self","substituteRecordTokens","substituteNodesRecordTokens","scope","substituteRepeatFilterRecordTokens","includes","repeatFilter","withoutRepeatDirective","kept","repeatedRecords","where","orderBy","limit","Number","slice","isFinite","Math","min","hasRepeatableNodes","values","repeatKeys","Set","add","sort","expandRepeatables","rowsByKey","repeatIds","repeatId","repeated","parentId","siblings","slot","indexOf","templateIds","listed","splice","copyIds","forEach","index","prefix","prefixId","cloneSubtree","clonedParentId","clonedChildren","undefined","drawn","childId","$id","templateId","push"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,gBAAgB,EAChBC,iBAAiB,EACjBC,eAAe,QACV,oBAAgB;AACvB,SACEC,iBAAiB,EACjBC,qBAAqB,QAChB,+BAA2B;AAClC,SAASC,cAAc,QAAQ,4BAAwB;AAEvD,yDAAyD,GACzD,OAAO,MAAMC,wBAAwB,QAAO;AAE5C;;;;CAIC,GACD,MAAMC,qBACJ;AAEF,0EAA0E,GAC1E,OAAO,MAAMC,qBAAqB,IAAG;AAyCrC,MAAMC,eAAe,CAACC,QACpBC,MAAMC,OAAO,CAACF,SAASA,MAAMG,IAAI,CAAC,QAAQC,OAAOJ;AAEnD,0EAA0E,GAC1E,SAASK,oBACPC,OAA0B,EAC1BC,OAAe,EACfC,aAAqB;QAEHF,2BAAAA,gBAEHA;IAFf,MAAMG,aAAYH,iBAAAA,QAAQI,KAAK,sBAAbJ,4BAAAA,eAAeK,UAAU,qBAAzBL,yBAA2B,CAACC,QAAQ;IACtD,IAAI,CAACE,WAAW,OAAO;IACvB,MAAMG,UAASN,yBAAAA,QAAQO,aAAa,qBAArBP,sBA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AAK;aAAc;YACtDmC,OAAOC,MAAM,CAACJ,MAAM,MAAMK;YAC1BrE,IAAI,CAAC8D,SAAS,GAAG,aAAK9D,IAAI,CAAC8D,SAAS;gBAAE9B,OAAOmC;;QAC/C,OAAO;YACLnE,IAAI,CAAC4D,SAAS,GAAG,aAAK5D,IAAI,CAAC4D,SAAS;gBAAE5B,OAAOqC;;QAC/C;IACF;IACA,OAAOrE;AACT;AAEA,eAAeyD,kBAAiB"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/expand-repeatables.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 type { AglynNodeSchema, NodeId } from '../foundation'\nimport {\n applyRepeatQuery,\n parseRepeatFilter,\n parseRepeatSort,\n} from './repeat-query'\nimport {\n NODE_HIDE_IF_PROP,\n NODE_HIDE_UNLESS_PROP,\n} from './reusable-component-keys'\nimport { readYesNoValue } from './reusable-prop-values'\n\n/** Namespaces cloned template ids per container/record. */\nexport const REPEAT_NODE_ID_PREFIX = 'rep__'\n\n/**\n * `{{item.field}}` token, plus an optional single reference hop\n * (`{{item.author.name}}`, AGL-180). One hop only — the pattern itself is\n * the depth guard, so cycles can't recurse.\n */\nconst ITEM_TOKEN_PATTERN =\n /\\{\\{\\s*item\\.([A-Za-z][A-Za-z0-9_]*)(?:\\.([A-Za-z][A-Za-z0-9_]*))?\\s*\\}\\}/g\n\n/** Hard bound on rows a single repeatable renders, before `repeatLimit`. */\nexport const REPEAT_MAX_RECORDS = 100\n\n/**\n * What the expansion reads of the rows' field model (AGL-177, AGL-180): which\n * fields are references, each with the key its target's rows are answered\n * under (`datasetsByKey`). The model itself is the plugin's that keeps the\n * rows, and it states this much of it when it hands the rows over\n * (`plugin-manager/repeat-rows`, `repeat-sources`); a field it does not name\n * here hops nowhere, and its token is left as written.\n */\nexport interface RepeatRowsModel {\n /** Reference field id → the key of the rows it points into. */\n references?: Readonly<Record<string, string>>\n}\n\nexport interface RepeatableDataset {\n /**\n * Row value maps, in display order. Rows carry `$id` (needed to resolve\n * incoming references); values may be typed (AGL-177), stringified at\n * substitution.\n */\n records: Array<Record<string, unknown>>\n /** The rows' references; required for reference-hop bindings. */\n model?: RepeatRowsModel\n}\n\ninterface SubstituteContext {\n record: Record<string, unknown>\n /** The repeated rows' references (AGL-180). */\n model?: RepeatRowsModel\n /** All host datasets keyed by id (and name) for hop resolution. */\n datasetsByKey?: Record<string, RepeatableDataset | undefined>\n /**\n * What a token whose field the record leaves empty becomes: `'token'` keeps\n * it as written (the besigner's canvas, where an author edits the template),\n * `'empty'` prints nothing (a rendered page, AGL-3616). A published page\n * never shows a visitor `{{item.venue}}` because one record has no venue.\n */\n missing?: 'token' | 'empty'\n}\n\n/**\n * A plain object's part a token can name (AGL-4190): `{{item.icon.iconPath}}`\n * reads the `iconPath` of a record's icon. Only text and numbers are parts;\n * anything else is not something a page can print.\n */\nfunction plainObjectPart(value: unknown, key: string): string | null {\n if (!value || typeof value !== 'object' || Array.isArray(value)) return null\n if (!Object.prototype.hasOwnProperty.call(value, key)) return null\n const part = (value as Record<string, unknown>)[key]\n return typeof part === 'string' || typeof part === 'number' ? String(part) : null\n}\n\n/**\n * A field's value as page text. A list is its entries, comma-joined. A map\n * that names an icon (`{ iconId, iconPath }`, AGL-4190) is the icon's id,\n * which is what an Icon element's icon holds; any other map is nothing,\n * rather than the `[object Object]` a page would otherwise print.\n */\nconst displayValue = (value: unknown): string => {\n if (Array.isArray(value)) return value.join(', ')\n if (value && typeof value === 'object') return plainObjectPart(value, 'iconId') ?? ''\n return String(value)\n}\n\n/** Resolves `{{item.ref.field}}`: FKey(s) → target document field value. */\nfunction resolveReferenceHop(\n context: SubstituteContext,\n fieldId: string,\n targetFieldId: string,\n): string | null {\n const targetKey = context.model?.references?.[fieldId]\n if (!targetKey) return null\n const target = context.datasetsByKey?.[targetKey]\n if (!target) return null\n const keys = context.record[fieldId]\n const ids = Array.isArray(keys) ? keys : keys != null ? [keys] : []\n const resolved = ids\n .map((id) => {\n const match = target.records.find((row) => row['$id'] === id)\n const value = match?.[targetFieldId]\n return value != null ? displayValue(value) : null\n })\n .filter((value): value is string => value != null)\n return resolved.length ? resolved.join(', ') : null\n}\n\nfunction substituteValue(\n value: unknown,\n context: SubstituteContext,\n): unknown {\n const { record } = context\n if (typeof value === 'string') {\n const unresolved = (token: string) =>\n context.missing === 'empty' ? '' : token\n return value.replace(\n ITEM_TOKEN_PATTERN,\n (token, field: string, hop?: string) => {\n if (hop) {\n // A reference's target field first (AGL-180); otherwise a part of\n // the field's own map, such as an icon's path (AGL-4190).\n const resolved =\n resolveReferenceHop(context, field, hop) ??\n plainObjectPart(record[field], hop)\n return resolved != null ? resolved : unresolved(token)\n }\n return record[field] != null\n ? displayValue(record[field])\n : unresolved(token)\n },\n )\n }\n if (Array.isArray(value)) {\n return value.map((entry) => substituteValue(entry, context))\n }\n if (value && typeof value === 'object') {\n const next: Record<string, unknown> = {}\n for (const [key, entry] of Object.entries(value)) {\n next[key] = substituteValue(entry, context)\n }\n return next\n }\n return value\n}\n\n/** A text that is nothing but `{{item.*}}` tokens: a binding, not words. */\nconst WHOLE_BINDING = new RegExp(\n `^\\\\s*(?:${ITEM_TOKEN_PATTERN.source}\\\\s*)+$`,\n)\n\n/**\n * Whether a copy's element is a binding its record left empty (AGL-3616):\n * its text, `children`, or its picture, `src`, was only `{{item.*}}` tokens\n * and they printed nothing. The copy leaves the element out rather than\n * drawing an empty line (an eyebrow with no venue) or an empty frame (a card\n * whose record has no photo, AGL-3912), and a record that fills the field\n * draws it.\n */\nfunction isEmptyBinding(\n template: Record<string, unknown> | undefined,\n substituted: Record<string, unknown>,\n): boolean {\n return (['children', 'src'] as const).some((prop) => {\n const text = template?.[prop]\n if (typeof text !== 'string' || !WHOLE_BINDING.test(text)) return false\n const printed = substituted[prop]\n return typeof printed === 'string' && printed.trim() === ''\n })\n}\n\n/** One `{{item.*}}` token anywhere, without the global pattern's `lastIndex`. */\nconst ITEM_TOKEN_ANYWHERE = new RegExp(ITEM_TOKEN_PATTERN.source)\n\n/** Whether `text` holds a `{{item.*}}` token. */\nconst namesItemToken = (text: string): boolean => ITEM_TOKEN_ANYWHERE.test(text)\n\n/**\n * Whether a copy's element asks to be left out of it (AGL-4212): its\n * `hideIf` or `hideUnless` was bound to a `{{item.*}}` token, and this\n * record's value says so — `hideIf` a yes, `hideUnless` a no, an empty field\n * included. An owner's reply block bound `hideUnless: '{{item.reply}}'`\n * draws on the reviews that have one and on no other. A directive bound to\n * anything else is not the record's to answer, and is left to the graft and\n * the host prune that read it.\n */\nfunction isHiddenByRecord(\n template: Record<string, unknown> | undefined,\n substituted: Record<string, unknown>,\n): boolean {\n const reads = (prop: string, hiddenWhen: boolean) => {\n const bound = template?.[prop]\n return (\n typeof bound === 'string' &&\n namesItemToken(bound) &&\n readYesNoValue(substituted[prop]) === hiddenWhen\n )\n }\n return reads(NODE_HIDE_IF_PROP, true) || reads(NODE_HIDE_UNLESS_PROP, false)\n}\n\n/**\n * The prop a repeat over a plugin connection's synced record persists under\n * (AGL-4212): `<pluginIdentity>/<connectionId>` repeats once per item of the\n * record, `<pluginIdentity>/<connectionId>/fields` once for its summary\n * fields. Persisted — never rename.\n */\nexport const REPEAT_CONNECTION_PROP = 'repeatConnection'\n\n/**\n * What {@link repeatKey} puts before a {@link REPEAT_CONNECTION_PROP} value,\n * so a connection's key and a dataset's never name the same rows, and the\n * server's repeat-rows contract can route each to the plugin that answers it.\n */\nexport const REPEAT_CONNECTION_KEY_PREFIX = 'connection:'\n\n/**\n * The key a node repeats over, trimmed, or `''` when it repeats over nothing:\n * its `repeatDataset`, else {@link REPEAT_CONNECTION_KEY_PREFIX} and its\n * {@link REPEAT_CONNECTION_PROP} (AGL-4212).\n *\n * The one predicate every repeat question is asked through: the expansion, the\n * datasets-read gate below, the reusable-component graft that moves a\n * placement's repeat onto the element it becomes, and the besigner's preview\n * and badge. Two copies of it are how a `.trim()` on one side and not the\n * other becomes an empty list on a customer's page.\n */\nexport const repeatKey = (node: unknown): string => {\n const props = (node as { props?: Record<string, unknown> } | null)?.props\n const dataset = props?.['repeatDataset']\n const key = typeof dataset === 'string' ? dataset.trim() : ''\n if (key) return key\n const connection = props?.[REPEAT_CONNECTION_PROP]\n const value = typeof connection === 'string' ? connection.trim() : ''\n return value ? `${REPEAT_CONNECTION_KEY_PREFIX}${value}` : ''\n}\n\n/**\n * Makes an element that holds children repeat ITSELF, once per record, instead\n * of what is inside it (AGL-3111): a card whose contents are the design, rather\n * than a list whose contents are the item.\n *\n * Persisted in screen, layout and component documents — never rename. `'true'`\n * counts too, because a switch round-tripped through a text-shaped store comes\n * back as the string.\n */\nexport const REPEAT_SELF_PROP = 'repeatSelf'\n\n/**\n * Every prop that directs a repeat. They are instructions to the composition,\n * never attributes of the element: the expansion consumes them from every node\n * it expands and every copy it makes, so a published element never carries\n * one. Persisted — never rename.\n */\nexport const REPEAT_DIRECTIVE_PROPS: readonly string[] = [\n 'repeatDataset',\n REPEAT_CONNECTION_PROP,\n 'repeatLimit',\n 'repeatFilter',\n 'repeatSort',\n REPEAT_SELF_PROP,\n]\n\n/**\n * What a repeating node copies once per record (AGL-3111).\n *\n * - `children` — what is inside it. The node stays one element around the\n * copies: the list, grid or gallery they fill. This is how a Stack has\n * always repeated (AGL-103), and a stored Stack names neither scope.\n * - `self` — the node itself, with everything inside it. What a leaf and a\n * component instance repeat, and what any element carrying\n * {@link REPEAT_SELF_PROP} repeats.\n */\nexport type RepeatScope = 'self' | 'children'\n\n/**\n * Which scope a repeating node has, read off the node alone so the published\n * page's composition and the besigner decide it identically.\n *\n * {@link REPEAT_SELF_PROP} decides it whenever the node carries one, which is\n * every repeat the Attributes panel writes. Without one the node's own shape\n * decides, and it decides CONSERVATIVELY: anything that holds a child list —\n * a Stack, empty or not — keeps repeating its children, and only a node with\n * no child list at all repeats itself. A stored repeat predates the prop, so\n * this branch is the one that has to render it unchanged, and an author who\n * named a dataset before filling the container in would otherwise come back to\n * a hundred empty copies of it.\n *\n * A component instance never reaches that branch: the graft stamps the prop on\n * the element it becomes, whose children are the component's own.\n */\nexport function repeatScope(node: unknown): RepeatScope {\n const { props, nodes } = (node ?? {}) as {\n props?: Record<string, unknown>\n nodes?: unknown\n }\n // `'true'`/`'false'` too: a switch round-tripped through a text-shaped\n // store comes back as the string it was written as.\n const self = props?.[REPEAT_SELF_PROP]\n if (self === true || self === 'true') return 'self'\n if (self === false || self === 'false') return 'children'\n return Array.isArray(nodes) ? 'children' : 'self'\n}\n\n/**\n * One record's values put into `{{item.field}}` tokens, anywhere in a props\n * map — the substitution {@link expandRepeatables} makes on every copy it\n * builds, for a caller that already knows which record it is rendering.\n *\n * The besigner's canvas is that caller (AGL-3111): the element an author\n * edits IS the first copy, so it draws with the first record's values while\n * the node it saves keeps the tokens. Exported rather than reimplemented\n * because a canvas that resolved a token differently from the page would be\n * showing the author a page that does not exist.\n */\nexport function substituteRecordTokens<T>(\n props: T,\n context: {\n record: Record<string, unknown>\n /** The repeated rows' references (AGL-180). */\n model?: RepeatRowsModel\n /** Rows by key, for a one-hop reference (AGL-180). */\n datasetsByKey?: Record<string, RepeatableDataset | undefined>\n },\n): T {\n return substituteValue(props, context) as T\n}\n\n/**\n * The one record a whole page is rendered for (AGL-3475): a record template's\n * routed record, in the shape a repeat hands each of its copies.\n */\nexport interface PageRecordScope {\n record: Record<string, unknown>\n /** The record's references (AGL-180). */\n model?: RepeatRowsModel\n /** Rows by key, for a one-hop reference (AGL-180). */\n datasetsByKey?: Record<string, RepeatableDataset | undefined>\n}\n\n/**\n * Every node's props with the page's record put into its `{{item.field}}`\n * tokens — the substitution a repeat makes on each copy, made once over a\n * page that renders one record (AGL-3475).\n *\n * Run AFTER {@link expandRepeatables}: a repeat inside the page has already\n * spent its own `{{item.*}}` tokens on its own rows by then, so what is left\n * is the page's. A token naming a field the record leaves empty prints\n * nothing, exactly as in a repeat (AGL-3616). Returns the input when there is\n * no record.\n */\nexport function substituteNodesRecordTokens<N>(\n nodes: Record<NodeId, N>,\n scope: PageRecordScope | null | undefined,\n): Record<NodeId, N> {\n if (!scope) return nodes\n const next: Record<NodeId, N> = {}\n for (const [id, node] of Object.entries(nodes) as Array<[NodeId, N]>) {\n const props = (node as { props?: unknown })?.props\n next[id] = props\n ? ({\n ...node,\n props: substituteValue(props, { ...scope, missing: 'empty' }),\n } as N)\n : node\n }\n return next\n}\n\n/**\n * The page's record put into each repeat's FILTER, before the repeats expand\n * (AGL-3475): on a record template, `category == {{item.category}}` lists the\n * other records in the routed record's category. Only `repeatFilter` is\n * touched — everything else inside a repeat is its template, whose\n * `{{item.*}}` belongs to its own rows. Returns the input when there is no\n * record or no filter names one.\n */\nexport function substituteRepeatFilterRecordTokens<N>(\n nodes: Record<NodeId, N>,\n scope: PageRecordScope | null | undefined,\n): Record<NodeId, N> {\n if (!scope) return nodes\n let next: Record<NodeId, N> | null = null\n for (const [id, node] of Object.entries(nodes) as Array<[NodeId, N]>) {\n const props = (node as { props?: Record<string, unknown> })?.props\n const filter = props?.['repeatFilter']\n if (typeof filter !== 'string' || !filter.includes('{{')) continue\n next ??= { ...nodes }\n next[id] = {\n ...node,\n props: { ...props, repeatFilter: substituteValue(filter, scope) },\n } as N\n }\n return next ?? nodes\n}\n\n/** The node minus its repeat directives, or the node itself when it has none. */\nexport function withoutRepeatDirective<N>(node: N): N {\n const props = (node as { props?: Record<string, unknown> })?.props\n if (!props || !REPEAT_DIRECTIVE_PROPS.some((key) => key in props)) {\n return node\n }\n const kept = { ...props }\n for (const key of REPEAT_DIRECTIVE_PROPS) delete kept[key]\n return { ...node, props: kept }\n}\n\n/**\n * The records a repeating node renders, in order (AGL-181): its filter and sort\n * evaluated over the rows, then its limit, never past\n * {@link REPEAT_MAX_RECORDS}. An unparseable filter or sort fails open.\n *\n * Shared by the expansion and the besigner's canvas preview and badge, so the\n * canvas can never show a copy or a count the published page does not.\n */\nexport function repeatedRecords(\n node: unknown,\n dataset: RepeatableDataset | undefined,\n): Array<Record<string, unknown>> {\n const props = ((node as { props?: unknown })?.props ?? {}) as Record<\n string,\n unknown\n >\n const where = parseRepeatFilter(String(props['repeatFilter'] ?? ''))\n const orderBy = parseRepeatSort(String(props['repeatSort'] ?? ''))\n const limit = Number(props['repeatLimit'])\n return applyRepeatQuery(dataset?.records ?? [], {\n ...(where ? { where: [where] } : {}),\n ...(orderBy ? { orderBy } : {}),\n }).slice(\n 0,\n Number.isFinite(limit) && limit > 0\n ? Math.min(limit, REPEAT_MAX_RECORDS)\n : REPEAT_MAX_RECORDS,\n )\n}\n\n/**\n * Does this tree contain anything {@link expandRepeatables} would expand —\n * or, with no rows, empty?\n *\n * The rows read is the largest on the render path — up to two pages of\n * {@link REPEAT_MAX_RECORDS} records for every key a page repeats over — and a\n * page that repeats over nothing should pay none of it (AGL-1440).\n *\n * Any gate on that read has to ask EXACTLY the question the expansion asks,\n * which is why this and {@link repeatKeys} share the one predicate\n * `expandRepeatables` looks keys up with, {@link repeatKey}. A gate that is\n * even slightly stricter than the expansion is not a saving: it is a published\n * page whose repeat never reaches the expansion at all, and so goes out as\n * its raw template — `{{item.*}}` tokens and all — where the author put a list.\n */\nexport function hasRepeatableNodes(\n nodes: Record<NodeId, unknown> | null | undefined,\n): boolean {\n if (!nodes) return false\n return Object.values(nodes).some((node) => repeatKey(node) !== '')\n}\n\n/**\n * Every key this tree repeats over, exactly as {@link expandRepeatables} looks\n * it up — sorted and without repeats.\n *\n * What the tenant compose asks the repeat-rows contract for\n * (`plugin-manager/repeat-rows.ts`), so a page loads the rows it renders and\n * not everything its site may see. Built on the same predicate as\n * {@link hasRepeatableNodes} for the reason given there.\n */\nexport function repeatKeys(\n nodes: Record<NodeId, unknown> | null | undefined,\n): string[] {\n const keys = new Set<string>()\n for (const node of Object.values(nodes ?? {})) {\n const key = repeatKey(node)\n if (key) keys.add(key)\n }\n return [...keys].sort()\n}\n\n/**\n * Repeats (AGL-103, AGL-3111): any node carrying `props.repeatDataset` (a\n * dataset id or display name), or `props.repeatConnection` (a plugin\n * connection's synced record, AGL-4212), renders once per record, with\n * `{{item.field}}` tokens in the copied string props replaced by the record's\n * values. A field the record leaves empty prints nothing — never the raw\n * token — and an element whose whole text is such a binding is left out of\n * that copy (AGL-3616: a tour date with no venue drew `{{ITEM.VENUE}}` as its\n * eyebrow on a published site). The besigner's canvas keeps the tokens of\n * the template an author edits ({@link substituteRecordTokens}).\n *\n * What is copied is the node's {@link repeatScope}:\n *\n * - `children` — its children are the item template. The node stays, and its\n * child list becomes the copies, record by record. Its own props are not the\n * template, so no token in them is substituted.\n * - `self` — the node and everything inside it are the template. The copies\n * take the node's place in its parent's child list, and every prop in the\n * subtree is substituted, the node's own included.\n *\n * - Copy ids are namespaced `rep__{repeatId}__{index}__…` — the repeat's own\n * id, then the template node's — so repeats never collide, including inside\n * grafted reusable components. A self-scoped node's first copy is\n * `rep__{id}__0__{id}`. Run this AFTER `composeReusableComponentNodes` and\n * BEFORE binding resolution.\n * - Rows are the node's {@link repeatedRecords}, looked up under its\n * {@link repeatKey}.\n * - An element of a copy whose `hideIf` / `hideUnless` is bound to a\n * `{{item.*}}` token is left out of that copy, with everything inside it,\n * when the record's value says so (AGL-4212).\n * - The repeat directives ({@link REPEAT_DIRECTIVE_PROPS}) are consumed: every\n * node this expands, and every copy it makes, comes out without them.\n * - Repeats do not nest. A repeat inside another repeat's template is copied\n * with its directives consumed, so it renders once in each copy.\n * - No rows renders ZERO copies (AGL-3496): a `children` repeat keeps its\n * element with an empty child list, a `self` repeat leaves its parent's\n * list. That covers a filter matching nothing, an empty dataset, and a key\n * the rows answer nothing under — a deleted or unshared dataset, or no rows\n * map at all — because the template drawn without a record is its literal\n * `{{item.*}}` tokens, printed to every visitor. Never a throw: a dataset\n * going away empties a list, it does not take the page down.\n * - An empty template, or a self-scoped node its parent does not list (the\n * document root, say), has nothing to copy or nowhere to put copies, and is\n * left as written.\n * - Inputs are never mutated; templates stay in the map unreferenced.\n *\n * This is the PUBLISHED page's composition. The besigner's canvas keeps the\n * template on screen whatever the rows say — it is what an author edits — and\n * flags a repeat with no rows on its badge instead ({@link repeatedRecords}\n * is the count both read).\n */\nexport function expandRepeatables<N extends AglynNodeSchema = AglynNodeSchema>(\n nodes: Record<NodeId, N>,\n datasetsByKey: Record<string, RepeatableDataset | undefined> | undefined,\n): Record<NodeId, N> {\n const rowsByKey = datasetsByKey ?? {}\n const repeatIds = Object.entries(nodes).filter(\n ([, node]) => repeatKey(node) !== '',\n )\n if (!repeatIds.length) return nodes\n\n const next: Record<NodeId, N> = { ...nodes }\n for (const [repeatId, repeated] of repeatIds) {\n const dataset = rowsByKey[repeatKey(repeated)]\n const records = repeatedRecords(repeated, dataset)\n const self = repeatScope(repeated) === 'self'\n // The copies' parent: the node itself, or — for a self-scoped node — the\n // parent whose child list the copies take its place in, read from `next`\n // so two self-scoped siblings both land in the list the other has left.\n const parentId = (self ? repeated.parentId : repeatId) as NodeId\n const siblings = next[parentId]?.nodes\n const slot = Array.isArray(siblings)\n ? (siblings as NodeId[]).indexOf(repeatId)\n : -1\n const templateIds = self\n ? [repeatId]\n : Array.isArray(repeated.nodes)\n ? (repeated.nodes as NodeId[])\n : []\n next[repeatId] = withoutRepeatDirective(next[repeatId])\n if (!templateIds.length || (self && slot < 0)) continue\n if (!records.length) {\n // Zero copies (AGL-3496). The template is a design, not content: drawn\n // without a record it prints `{{item.name}}` to every visitor.\n if (self) {\n const listed = [...(next[parentId].nodes as NodeId[])]\n listed.splice(slot, 1)\n next[parentId] = { ...next[parentId], nodes: listed }\n } else {\n next[repeatId] = { ...next[repeatId], nodes: [] }\n }\n continue\n }\n\n const copyIds: NodeId[] = []\n records.forEach((record, index) => {\n const prefix = `${REPEAT_NODE_ID_PREFIX}${repeatId}__${index}__`\n const prefixId = (id: NodeId) => `${prefix}${id}`\n // Whether the copy drew the node: an element whose whole text is a\n // binding this record leaves empty is left out of it (AGL-3616).\n const cloneSubtree = (id: NodeId, clonedParentId: NodeId): boolean => {\n const node = nodes[id]\n if (!node) return false\n const props = substituteValue(node.props ?? {}, {\n record,\n model: dataset?.model,\n datasetsByKey: rowsByKey,\n missing: 'empty',\n }) as Record<string, unknown>\n const template = node.props as Record<string, unknown> | undefined\n if (\n isEmptyBinding(template, props) ||\n isHiddenByRecord(template, props)\n ) {\n return false\n }\n // Read, so not carried: a copy is drawn or left out, and the\n // directive that decided it has nothing left to say.\n for (const prop of [NODE_HIDE_IF_PROP, NODE_HIDE_UNLESS_PROP]) {\n const bound = template?.[prop]\n if (typeof bound === 'string' && namesItemToken(bound)) {\n delete props[prop]\n }\n }\n const clonedChildren = Array.isArray(node.nodes)\n ? (node.nodes as NodeId[])\n : undefined\n const drawn = clonedChildren?.filter((childId) =>\n cloneSubtree(childId, prefixId(id)),\n )\n next[prefixId(id)] = withoutRepeatDirective({\n ...node,\n $id: prefixId(id),\n parentId: clonedParentId,\n props: props as any,\n ...(drawn && {\n nodes: drawn.map((childId) => prefixId(childId)),\n }),\n })\n return true\n }\n for (const templateId of templateIds) {\n if (cloneSubtree(templateId, parentId)) {\n copyIds.push(prefixId(templateId))\n }\n }\n })\n if (self) {\n const listed = [...(next[parentId].nodes as NodeId[])]\n listed.splice(slot, 1, ...copyIds)\n next[parentId] = { ...next[parentId], nodes: listed }\n } else {\n next[repeatId] = { ...next[repeatId], nodes: copyIds }\n }\n }\n return next\n}\n\nexport default expandRepeatables\n"],"names":["applyRepeatQuery","parseRepeatFilter","parseRepeatSort","NODE_HIDE_IF_PROP","NODE_HIDE_UNLESS_PROP","readYesNoValue","REPEAT_NODE_ID_PREFIX","ITEM_TOKEN_PATTERN","REPEAT_MAX_RECORDS","plainObjectPart","value","key","Array","isArray","Object","prototype","hasOwnProperty","call","part","String","displayValue","join","resolveReferenceHop","context","fieldId","targetFieldId","targetKey","model","references","target","datasetsByKey","keys","record","ids","resolved","map","id","match","records","find","row","filter","length","substituteValue","unresolved","token","missing","replace","field","hop","entry","next","entries","WHOLE_BINDING","RegExp","source","isEmptyBinding","template","substituted","some","prop","text","test","printed","trim","ITEM_TOKEN_ANYWHERE","namesItemToken","isHiddenByRecord","reads","hiddenWhen","bound","REPEAT_CONNECTION_PROP","REPEAT_CONNECTION_KEY_PREFIX","repeatKey","node","props","dataset","connection","REPEAT_SELF_PROP","REPEAT_DIRECTIVE_PROPS","repeatScope","nodes","self","substituteRecordTokens","substituteNodesRecordTokens","scope","substituteRepeatFilterRecordTokens","includes","repeatFilter","withoutRepeatDirective","kept","repeatedRecords","where","orderBy","limit","Number","slice","isFinite","Math","min","hasRepeatableNodes","values","repeatKeys","Set","add","sort","expandRepeatables","rowsByKey","repeatIds","repeatId","repeated","parentId","siblings","slot","indexOf","templateIds","listed","splice","copyIds","forEach","index","prefix","prefixId","cloneSubtree","clonedParentId","clonedChildren","undefined","drawn","childId","$id","templateId","push"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,gBAAgB,EAChBC,iBAAiB,EACjBC,eAAe,QACV,oBAAgB;AACvB,SACEC,iBAAiB,EACjBC,qBAAqB,QAChB,+BAA2B;AAClC,SAASC,cAAc,QAAQ,4BAAwB;AAEvD,yDAAyD,GACzD,OAAO,MAAMC,wBAAwB,QAAO;AAE5C;;;;CAIC,GACD,MAAMC,qBACJ;AAEF,0EAA0E,GAC1E,OAAO,MAAMC,qBAAqB,IAAG;AAyCrC;;;;CAIC,GACD,SAASC,gBAAgBC,KAAc,EAAEC,GAAW;IAClD,IAAI,CAACD,SAAS,OAAOA,UAAU,YAAYE,MAAMC,OAAO,CAACH,QAAQ,OAAO;IACxE,IAAI,CAACI,OAAOC,SAAS,CAACC,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C7D,qDAAqD;gBACrD,KAAK,MAAMf,QAAQ;oBAACzD;oBAAmBC;iBAAsB,CAAE;oBAC7D,MAAMkE,QAAQb,4BAAAA,QAAU,CAACG,KAAK;oBAC9B,IAAI,OAAOU,UAAU,YAAYJ,eAAeI,QAAQ;wBACtD,OAAOK,KAAK,CAACf,KAAK;oBACpB;gBACF;gBACA,MAAMiE,iBAAiBjH,MAAMC,OAAO,CAAC6D,KAAKO,KAAK,IAC1CP,KAAKO,KAAK,GACX6C;gBACJ,MAAMC,QAAQF,kCAAAA,eAAgBpF,MAAM,CAAC,CAACuF,UACpCL,aAAaK,SAASN,SAAStF;gBAEjCe,IAAI,CAACuE,SAAStF,IAAI,GAAGqD,uBAAuB,aACvCf;oBACHuD,KAAKP,SAAStF;oBACd2E,UAAUa;oBACVjD,OAAOA;mBACHoD,SAAS;oBACX9C,OAAO8C,MAAM5F,GAAG,CAAC,CAAC6F,UAAYN,SAASM;gBACzC;gBAEF,OAAO;YACT;YACA,KAAK,MAAME,cAAcf,YAAa;gBACpC,IAAIQ,aAAaO,YAAYnB,WAAW;oBACtCO,QAAQa,IAAI,CAACT,SAASQ;gBACxB;YACF;QACF;QACA,IAAIhD,MAAM;YACR,MAAMkC,SAAS;mBAAKjE,IAAI,CAAC4D,SAAS,CAAC9B,KAAK;aAAc;YACtDmC,OAAOC,MAAM,CAACJ,MAAM,MAAMK;YAC1BnE,IAAI,CAAC4D,SAAS,GAAG,aAAK5D,IAAI,CAAC4D,SAAS;gBAAE9B,OAAOmC;;QAC/C,OAAO;YACLjE,IAAI,CAAC0D,SAAS,GAAG,aAAK1D,IAAI,CAAC0D,SAAS;gBAAE5B,OAAOqC;;QAC/C;IACF;IACA,OAAOnE;AACT;AAEA,eAAeuD,kBAAiB"}
@@ -244,6 +244,23 @@ export declare function describeHostTokens(host: HostTokenSource | null | undefi
244
244
  value?: string;
245
245
  set: boolean;
246
246
  }>;
247
+ /** One row of {@link describeHostTokens} as plain data: the definition without its resolvers. */
248
+ export interface HostTokenPreviewRow {
249
+ key: string;
250
+ type: HostTokenType;
251
+ label: string;
252
+ description: string;
253
+ whenEmpty: HostTokenEmptyBehaviour;
254
+ token: string;
255
+ value?: string;
256
+ set: boolean;
257
+ }
258
+ /**
259
+ * {@link describeHostTokens} without the resolvers, so it can travel as data:
260
+ * the native apps' Business details card lists "What your pages can use"
261
+ * from it, and replays these answers in their tests (AGL-4136).
262
+ */
263
+ export declare function hostTokenPreview(host: HostTokenSource | null | undefined): HostTokenPreviewRow[];
247
264
  /**
248
265
  * The `host.*` values as a merge-token map, for surfaces that already have a
249
266
  * token substituter of their own.
@@ -416,6 +416,24 @@ function logo(host) {
416
416
  });
417
417
  });
418
418
  }
419
+ /**
420
+ * {@link describeHostTokens} without the resolvers, so it can travel as data:
421
+ * the native apps' Business details card lists "What your pages can use"
422
+ * from it, and replays these answers in their tests (AGL-4136).
423
+ */ export function hostTokenPreview(host) {
424
+ return describeHostTokens(host).map(({ key, type, label, description, whenEmpty, token, value, set })=>_extends({
425
+ key,
426
+ type,
427
+ label,
428
+ description,
429
+ whenEmpty,
430
+ token
431
+ }, value === undefined ? {} : {
432
+ value
433
+ }, {
434
+ set
435
+ }));
436
+ }
419
437
  /**
420
438
  * The `host.*` values as a merge-token map, for surfaces that already have a
421
439
  * token substituter of their own.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/host-tokens.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 { structuredAddressLine } from './business-profile'\nimport { siteProfileUrls, type HostSeoEntity } from './content-authors'\nimport { hostPublicOrigin } from './host-naming'\nimport { normalizeAreaServed } from './local-business'\n\n/**\n * Host variables — publisher templates that fill themselves in (AGL-1022).\n *\n * A publisher writing an email template cannot reference the installing site,\n * so every install begins with the same chore: swap the placeholder logo, fix\n * the business name, correct the links. Miss one and the site sends an email\n * carrying someone else's branding.\n *\n * `host.*` gives artifacts a way to NAME the host instead of hard-coding it.\n * The author writes `{{host.businessName}}`; the installing site fills it in,\n * and it stays filled in when that site rebrands.\n *\n * ## The namespace IS the security boundary\n *\n * This is publisher-authored content resolving against tenant data, so the\n * registry is CLOSED and each token reads through a hand-written function\n * rather than a path into the document. That is the whole design: a token\n * cannot address `stripeAccountId`, or `memberRoles`, or anything else, because\n * there is no path syntax to express it — `host.` is followed by a key that\n * either appears in {@link HOST_TOKENS} or resolves to nothing at all. Adding a\n * token is a deliberate edit here, reviewable as a diff.\n *\n * A path-based registry (\"allow `host.seo.title`\") would have been shorter and\n * is the version to refuse: allowlisting prefixes is how a namespace grows a\n * hole, and the first `host.orgId` would be a data leak with a plausible commit\n * message.\n *\n * ## Resolve LATE\n *\n * At render and at send, never at install. Freezing values into the artifact\n * would make a rebrand stop propagating silently — the site would keep sending\n * last year's business name from a template nobody remembers is a template.\n *\n * ## Every token defines what \"empty\" does\n *\n * A site with no logo must produce something deliberate. Never an empty image,\n * and never the literal `{{host.logo}}` reaching a visitor — a leaked token is\n * the most embarrassing possible failure for a feature whose entire purpose is\n * to stop templates looking unfinished.\n */\n\n/**\n * What a token yields, so a renderer knows how to place it and the authoring\n * surface can refuse it in the wrong slot.\n *\n * `text` is the only type safe to drop into arbitrary copy. The others carry a\n * shape a slot has to understand — an `image` in a paragraph is a URL sitting\n * in the middle of a sentence, which is exactly the \"fails in a sent email\"\n * outcome this typing exists to move to authoring time.\n */\nexport type HostTokenType = 'text' | 'url' | 'email' | 'image' | 'address'\n\n/** What a renderer should do when a token resolves to nothing. */\nexport type HostTokenEmptyBehaviour =\n /** Render nothing in its place; the surrounding copy still makes sense. */\n | 'blank'\n /**\n * The block holding it should be dropped entirely. An `<img src=\"\">` is a\n * broken-image icon in every mail client, which is worse than no logo.\n */\n | 'omit-block'\n\n/** The site fields a token may read. A closed, explicit surface. */\nexport interface HostTokenSource {\n displayName?: string\n logoUrl?: string\n logoDarkUrl?: string\n subdomain?: string\n cname?: string\n /**\n * The one-block copies of the email and address, and the social links\n * (AGL-1022). Setup → Business profile writes the email and address to `seo.entity`\n * and mirrors them here (AGL-4136), so these are what a token reads when\n * the entity has none: a site saved before that, or by the native apps.\n */\n business?: {\n supportEmail?: string\n address?: string\n socialLinks?: Array<{ label?: string; url?: string }>\n }\n /**\n * The business's facts as Setup → Business profile and SEO → Local business store\n * them (AGL-4136): the name, slogan, phone, email, structured address, the\n * profiles it claims and the areas it serves.\n */\n seo?: {\n entity?: Pick<\n HostSeoEntity,\n | 'name'\n | 'logo'\n | 'slogan'\n | 'email'\n | 'telephone'\n | 'address'\n | 'sameAs'\n | 'areaServed'\n >\n }\n}\n\nexport interface HostTokenDefinition {\n /** The key after `host.` */\n key: string\n type: HostTokenType\n label: string\n description: string\n /** Reads the value. Hand-written per token — never a path into the document. */\n resolve: (host: HostTokenSource) => string | undefined\n /**\n * A deliberate second choice when `resolve` finds nothing.\n *\n * Not a nicety: \"fall back to the business name\" is what turns a missing logo\n * from a hole in the page into a wordmark, which is what a careful designer\n * would have done by hand.\n */\n fallback?: (host: HostTokenSource) => string | undefined\n whenEmpty: HostTokenEmptyBehaviour\n}\n\nconst trimmed = (value: unknown): string | undefined => {\n const text = typeof value === 'string' ? value.trim() : ''\n return text || undefined\n}\n\n/**\n * The site's public URL.\n *\n * A custom domain wins when connected, because that is the address the site is\n * actually known by — a template linking to the aglyn.app subdomain of a site\n * with its own domain is technically correct and reads as a mistake.\n */\nfunction siteUrl(host: HostTokenSource): string | undefined {\n const custom = trimmed(host.cname)\n if (custom) return `https://${custom.replace(/^https?:\\/\\//, '')}`\n // `hostPublicOrigin`, not a fourth hand-rolled apex (AGL-2195). The cname\n // branch stays here because this one strips a scheme the token source may\n // carry; the subdomain branch has no such difference and had none — it was\n // the same two lines with `aglyn.app` written in, so an operator's own apex\n // was honoured everywhere except in the tokens a template renders.\n return hostPublicOrigin({ subdomain: trimmed(host.subdomain) })\n}\n\nfunction businessName(host: HostTokenSource): string | undefined {\n return trimmed(host.seo?.entity?.name) ?? trimmed(host.displayName)\n}\n\nfunction logo(host: HostTokenSource): string | undefined {\n return trimmed(host.logoUrl) ?? trimmed(host.seo?.entity?.logo)\n}\n\n/**\n * A phone number as a `tel:` link (AGL-4136): everything but its digits and\n * a leading `+` removed, so `+1 (512) 555-0100` dials `tel:+15125550100`.\n * Nothing when the number holds no digit, so a Call button never links to a\n * bare `tel:`.\n */\nexport function telephoneHref(phone: unknown): string | undefined {\n const text = trimmed(phone)\n if (!text) return undefined\n const digits = text.replace(/\\D+/g, '')\n if (!digits) return undefined\n return `tel:${text.startsWith('+') ? '+' : ''}${digits}`\n}\n\n/**\n * The social networks a page can link by name (AGL-4136), each with the\n * hostnames its profile addresses are served from. A hostname matches itself\n * and any subdomain of itself, so `www.` and `m.` addresses are the same\n * profile. X keeps `twitter.com`, because a link saved before the rename is\n * still the same account.\n */\nconst SOCIAL_NETWORK_HOSTS = {\n facebook: ['facebook.com', 'fb.com'],\n instagram: ['instagram.com'],\n x: ['x.com', 'twitter.com'],\n linkedin: ['linkedin.com'],\n youtube: ['youtube.com', 'youtu.be'],\n tiktok: ['tiktok.com'],\n} as const\n\nexport type HostSocialNetwork = keyof typeof SOCIAL_NETWORK_HOSTS\n\n/**\n * The site's profile on one network: the first of the profiles it claims\n * (`siteProfileUrls`, the entity's `sameAs` and then Setup → Business profile's\n * social links, https only) served from that network's hostname. Matched by\n * HOSTNAME rather than by the link's label, because the label is free text\n * and the address is what a visitor is sent to.\n */\nexport function siteSocialProfileUrl(\n host: HostTokenSource | null | undefined,\n network: HostSocialNetwork,\n): string | undefined {\n const hosts: readonly string[] = SOCIAL_NETWORK_HOSTS[network]\n for (const value of siteProfileUrls(host)) {\n let hostname: string\n try {\n hostname = new URL(value).hostname.toLowerCase()\n } catch {\n continue\n }\n if (hosts.some((name) => hostname === name || hostname.endsWith(`.${name}`))) {\n return value\n }\n }\n return undefined\n}\n\n/** The areas served, as SEO → Local business stores and the structured data publishes them. */\nfunction areasServed(host: HostTokenSource): string[] {\n return normalizeAreaServed(host.seo?.entity?.areaServed)\n}\n\n/** One social network's profile link as a token: a URL, dropped where the site has none. */\nfunction socialToken(\n network: HostSocialNetwork,\n key: string,\n name: string,\n): HostTokenDefinition {\n return {\n key,\n type: 'url',\n label: `${name} link`,\n description: `The address of the site’s ${name} profile, from Setup → Business profile.`,\n resolve: (host) => siteSocialProfileUrl(host, network),\n whenEmpty: 'omit-block',\n }\n}\n\n/**\n * The closed registry.\n *\n * Ordered as an author would look for them. Every entry is reachable from a\n * field a site can actually set — a token that can never resolve is worse than\n * an absent one, because it teaches people the feature does not work.\n */\nexport const HOST_TOKENS: Record<string, HostTokenDefinition> = {\n businessName: {\n key: 'businessName',\n type: 'text',\n label: 'Business name',\n description:\n 'The business name from Setup → Business profile, or the site’s name when none is set.',\n resolve: businessName,\n whenEmpty: 'blank',\n },\n slogan: {\n key: 'slogan',\n type: 'text',\n label: 'Slogan',\n description: 'A short line about the business, from Setup → Business profile.',\n resolve: (host) => trimmed(host.seo?.entity?.slogan),\n whenEmpty: 'blank',\n },\n logo: {\n key: 'logo',\n type: 'image',\n label: 'Logo',\n description: 'The site’s logo image.',\n resolve: logo,\n // No image: the block is dropped and the business name carries the brand\n // instead, which is what the block was for.\n whenEmpty: 'omit-block',\n },\n logoDark: {\n key: 'logoDark',\n type: 'image',\n label: 'Logo for dark backgrounds',\n description:\n 'The logo to show on a dark background. The site’s logo when it has no dark one.',\n // The pair a header toggles by color scheme (AGL-4119): a site with one\n // logo shows it in both schemes, and one with none shows neither.\n resolve: (host) => trimmed(host.logoDarkUrl) ?? logo(host),\n whenEmpty: 'omit-block',\n },\n url: {\n key: 'url',\n type: 'url',\n label: 'Site address',\n description: 'The site’s public URL — its custom domain when connected.',\n resolve: siteUrl,\n whenEmpty: 'blank',\n },\n phone: {\n key: 'phone',\n type: 'text',\n label: 'Phone',\n description: 'The business’s phone number, as entered on Setup → Business profile.',\n resolve: (host) => trimmed(host.seo?.entity?.telephone),\n whenEmpty: 'omit-block',\n },\n phoneLink: {\n key: 'phoneLink',\n type: 'url',\n label: 'Phone link',\n description:\n 'The phone number as a tel: link, for a Call button’s link. Dropped when the site has no phone.',\n resolve: (host) => telephoneHref(host.seo?.entity?.telephone),\n whenEmpty: 'omit-block',\n },\n /*\n The key keeps its old name, because pages and emails already say\n `{{host.supportEmail}}`. What it reads is the site's one email (AGL-4136):\n the one Setup → Business profile saves to the entity, else the one-block copy a\n site saved before that.\n */\n supportEmail: {\n key: 'supportEmail',\n type: 'email',\n label: 'Email',\n description: 'The email address visitors write to, from Setup → Business profile.',\n resolve: (host) => siteContactEmail(host) ?? undefined,\n whenEmpty: 'omit-block',\n },\n address: {\n key: 'address',\n type: 'address',\n label: 'Postal address',\n description:\n 'The business’s postal address from Setup → Business profile, as one block of text.',\n // The structured address, formatted the one way it is formatted\n // everywhere (AGL-4136), else the one-block copy as it was typed —\n // line breaks kept, because a document prints it a line per line.\n resolve: (host) =>\n trimmed(structuredAddressLine(host.seo?.entity?.address)) ??\n trimmed(host.business?.address),\n whenEmpty: 'omit-block',\n },\n mainArea: {\n key: 'mainArea',\n type: 'text',\n label: 'Main area',\n description:\n 'The first area served, by its place name: San Antonio, for “San Antonio, TX”. From SEO → Local business.',\n // The text before the first comma, so the token reads in a sentence —\n // \"across San Antonio and surrounding areas\" — and a page that already\n // says the place name can switch to it without a visible change.\n resolve: (host) => trimmed(areasServed(host)[0]?.split(',')[0]),\n whenEmpty: 'blank',\n },\n areasServed: {\n key: 'areasServed',\n type: 'text',\n label: 'Areas served',\n description:\n 'Every area served, in order, separated by commas. From SEO → Local business.',\n resolve: (host) => trimmed(areasServed(host).join(', ')),\n whenEmpty: 'blank',\n },\n socialLinks: {\n key: 'socialLinks',\n type: 'text',\n label: 'Social links',\n description: 'The site’s social profiles, as a list of labeled links.',\n // Rendered as text here so a token in copy degrades to something readable;\n // a link to one profile is that network's own token below (AGL-4136).\n resolve: (host) => {\n const links = host.business?.socialLinks ?? []\n const labels = links\n .map((link) => trimmed(link?.label) ?? trimmed(link?.url))\n .filter((label): label is string => Boolean(label))\n return labels.length ? labels.join(' · ') : undefined\n },\n whenEmpty: 'omit-block',\n },\n /*\n One link per common network (AGL-4136), so a page's social icons link\n the site's own profiles from Setup → Business profile instead of a hand-made\n variable per network.\n */\n facebookUrl: socialToken('facebook', 'facebookUrl', 'Facebook'),\n instagramUrl: socialToken('instagram', 'instagramUrl', 'Instagram'),\n xUrl: socialToken('x', 'xUrl', 'X'),\n linkedinUrl: socialToken('linkedin', 'linkedinUrl', 'LinkedIn'),\n youtubeUrl: socialToken('youtube', 'youtubeUrl', 'YouTube'),\n tiktokUrl: socialToken('tiktok', 'tiktokUrl', 'TikTok'),\n}\n\n/**\n * The registry's entry for `key`, or undefined when it declares none.\n *\n * An OWN entry only. `HOST_TOKENS` is an object literal, so a bare index also\n * finds the `Object.prototype` members — `constructor`, `toString`, `valueOf` —\n * and every one of those names matches {@link HOST_TOKEN_PATTERN}. Read that\n * way, `{{host.constructor}}` answers the `Object` function where a definition\n * belongs, and calling its `resolve` throws in the middle of a render. A name\n * the registry does not declare resolves to nothing, whatever the name is.\n */\nexport function hostTokenDefinition(\n key: string,\n): HostTokenDefinition | undefined {\n return Object.prototype.hasOwnProperty.call(HOST_TOKENS, key)\n ? HOST_TOKENS[key]\n : undefined\n}\n\n/**\n * `{{host.key}}` — whitespace-tolerant, and deliberately NOT dotted beyond one\n * segment. `host.a.b` does not match, so there is no path syntax to abuse.\n */\nexport const HOST_TOKEN_PATTERN = /\\{\\{\\s*host\\.([a-zA-Z][a-zA-Z0-9_]*)\\s*\\}\\}/g\n\n/**\n * Whether a value is exactly one image token, like `{{host.logo}}`: what a\n * picture's `src` may be when it is the installing site's own logo. It becomes\n * that site's stored value at render, so it names nothing of the publisher's.\n */\nexport function isHostImageToken(value: string): boolean {\n const keys = hostTokensIn(value)\n return (\n keys.length === 1 &&\n value.replace(HOST_TOKEN_PATTERN, '').trim() === '' &&\n hostTokenDefinition(keys[0])?.type === 'image'\n )\n}\n\n/** Every `host.*` token in a string, in order, including unknown ones. */\nexport function hostTokensIn(text: string): string[] {\n if (typeof text !== 'string' || !text.includes('{{')) return []\n const keys: string[] = []\n for (const match of text.matchAll(HOST_TOKEN_PATTERN)) keys.push(match[1])\n return keys\n}\n\n/** The resolved value of one token, or undefined when the site has none. */\nexport function resolveHostToken(\n key: string,\n host: HostTokenSource | null | undefined,\n): string | undefined {\n const definition = hostTokenDefinition(key)\n if (!definition || !host) return undefined\n return definition.resolve(host) ?? definition.fallback?.(host)\n}\n\n/**\n * Replaces every `host.*` token with the installing site's value.\n *\n * An unresolved token — unknown key, or a site that has not set the field —\n * renders EMPTY, never the literal. Leaking `{{host.logo}}` into a sent email\n * is the failure this feature exists to prevent, so it cannot be the fallback\n * for the feature's own gaps. The authoring-time check\n * ({@link validateHostTokens}) is where a typo is meant to be caught, while the\n * writer can still fix it.\n */\nexport function resolveHostTokens(\n text: string,\n host: HostTokenSource | null | undefined,\n): string {\n if (typeof text !== 'string' || !text.includes('{{')) return text\n return text.replace(HOST_TOKEN_PATTERN, (_token, key) =>\n resolveHostToken(String(key), host) ?? '',\n )\n}\n\nexport interface HostTokenIssue {\n key: string\n /**\n * `unknown` — no such token; it will render empty.\n * `wrong-slot` — the token's type cannot be placed here.\n */\n kind: 'unknown' | 'wrong-slot'\n message: string\n}\n\n/**\n * Authoring-time check: catch a token before it reaches a visitor.\n *\n * The two things worth failing on are a typo (which would silently render\n * nothing) and a type mismatch (an image URL dropped into a sentence). Both are\n * invisible at authoring time without this and obvious afterwards, which is the\n * wrong way round for something that ends up in a sent email.\n *\n * `allow` names the types this slot can take. Omit it for free text, where only\n * `text` and the string-ish types make sense.\n */\nexport function validateHostTokens(\n text: string,\n options?: { allow?: readonly HostTokenType[] },\n): HostTokenIssue[] {\n const allow = options?.allow ?? ['text', 'url', 'email', 'address']\n const issues: HostTokenIssue[] = []\n const seen = new Set<string>()\n for (const key of hostTokensIn(text)) {\n if (seen.has(key)) continue\n seen.add(key)\n const definition = hostTokenDefinition(key)\n if (!definition) {\n issues.push({\n key,\n kind: 'unknown',\n message:\n `There is no host variable called \"${key}\". It will render as ` +\n 'nothing. Available: ' +\n Object.keys(HOST_TOKENS).join(', ') +\n '.',\n })\n continue\n }\n if (!allow.includes(definition.type)) {\n issues.push({\n key,\n kind: 'wrong-slot',\n message:\n `\"${definition.label}\" is ${\n definition.type === 'image' ? 'an image' : `a ${definition.type}`\n }, so it cannot go here. Put it in a slot that takes ` +\n `${definition.type === 'image' ? 'an image' : `a ${definition.type}`}.`,\n })\n }\n }\n return issues\n}\n\n/**\n * Whether a block containing these tokens should be dropped for this site.\n *\n * The other half of \"every token needs a defined empty behaviour\": a logo block\n * on a site with no logo should not render an empty image, and the renderer\n * cannot know that from the resolved string alone — `''` is both \"no value\" and\n * \"a value that happens to be empty\". Asking here keeps the rule with the\n * token definition rather than spread across the surfaces that render it.\n */\nexport function shouldOmitBlock(\n text: string,\n host: HostTokenSource | null | undefined,\n): boolean {\n for (const key of hostTokensIn(text)) {\n const definition = hostTokenDefinition(key)\n if (!definition || definition.whenEmpty !== 'omit-block') continue\n if (!resolveHostToken(key, host)) return true\n }\n return false\n}\n\n/**\n * Every token with its resolved value for one site, for an authoring picker\n * that shows what each will actually produce here.\n *\n * A picker listing token names alone makes the author guess; showing the value\n * this site would render is what turns \"is it businessName or business_name\"\n * into a question nobody has to ask.\n */\nexport function describeHostTokens(\n host: HostTokenSource | null | undefined,\n): Array<HostTokenDefinition & { token: string; value?: string; set: boolean }> {\n return Object.values(HOST_TOKENS).map((definition) => {\n const value = resolveHostToken(definition.key, host)\n return {\n ...definition,\n token: `{{host.${definition.key}}}`,\n value,\n set: Boolean(value),\n }\n })\n}\n\n/**\n * The `host.*` values as a merge-token map, for surfaces that already have a\n * token substituter of their own.\n *\n * This is how EMAIL gets host variables without the email library depending on\n * this one: `substituteMergeTokens` already matches `{{a.b}}`, so a caller\n * spreads this into the merge map it was passing anyway. One registry, two\n * surfaces, no second substitution engine to drift.\n *\n * Every registered token appears, INCLUDING the ones this site has not set —\n * as `''`. Omitting them would leave `{{host.supportEmail}}` for the generic\n * catch-all to blank, which works today and works by accident: the moment a\n * surface without that catch-all uses this map, the literal token ships.\n */\nexport function hostTokenMerge(\n host: HostTokenSource | null | undefined,\n): Record<string, string> {\n const merge: Record<string, string> = {}\n for (const key of Object.keys(HOST_TOKENS)) {\n merge[`host.${key}`] = resolveHostToken(key, host) ?? ''\n }\n return merge\n}\n\n/**\n * The email address a visitor writes to the business at: the one Setup →\n * Business saves (`seo.entity.email`), else the one-block copy a site saved\n * before that (`business.supportEmail`). Null when the site has neither. One\n * answer for every place that names it: the `{{host.supportEmail}}` token\n * and so the email footer, the waiver consent, the quote and invoice PDFs,\n * the Reply-To of the quote email (AGL-4097), and the address a refused form\n * or sign-up offers instead (AGL-4136). Trimmed, not validated; a caller\n * putting it in a header checks it is an address.\n */\nexport function siteContactEmail(\n host:\n | {\n seo?: { entity?: { email?: unknown } | null } | null\n business?: { supportEmail?: unknown } | null\n }\n | null\n | undefined,\n): string | null {\n const text = (value: unknown) => (typeof value === 'string' ? value.trim().slice(0, 320) : '')\n return text(host?.seo?.entity?.email) || text(host?.business?.supportEmail) || null\n}\n\n/**\n * Resolves `host.*` tokens across every string prop of a normalized node map.\n *\n * Mirrors `resolveNodesBindings` deliberately — same shallow-copy discipline,\n * same string-props-only rule — so a screen and an email resolve the same token\n * to the same value. The issue's warning is the reason: two resolvers drift,\n * and then the same token means different things depending on where an author\n * typed it.\n *\n * Returns the input untouched when the site has nothing to substitute, so a\n * binding-free tree costs one `Object.entries`.\n */\nexport function resolveNodesHostTokens<T extends Record<string, any>>(\n nodes: T,\n host: HostTokenSource | null | undefined,\n): T {\n if (!nodes) return nodes\n let changed = false\n const next: Record<string, any> = {}\n for (const [id, node] of Object.entries(nodes)) {\n const props = node?.props\n if (!props) {\n next[id] = node\n continue\n }\n let nodeChanged = false\n const nextProps: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(props)) {\n if (typeof value === 'string' && value.includes('{{')) {\n const resolved = resolveHostTokens(value, host)\n nextProps[key] = resolved\n if (resolved !== value) nodeChanged = true\n } else {\n nextProps[key] = value\n }\n }\n next[id] = nodeChanged ? { ...node, props: nextProps } : node\n changed = changed || nodeChanged\n }\n return (changed ? next : nodes) as T\n}\n"],"names":["structuredAddressLine","siteProfileUrls","hostPublicOrigin","normalizeAreaServed","trimmed","value","text","trim","undefined","siteUrl","host","custom","cname","replace","subdomain","businessName","seo","entity","name","displayName","logo","logoUrl","telephoneHref","phone","digits","startsWith","SOCIAL_NETWORK_HOSTS","facebook","instagram","x","linkedin","youtube","tiktok","siteSocialProfileUrl","network","hosts","hostname","URL","toLowerCase","some","endsWith","areasServed","areaServed","socialToken","key","type","label","description","resolve","whenEmpty","HOST_TOKENS","slogan","logoDark","logoDarkUrl","url","telephone","phoneLink","supportEmail","siteContactEmail","address","business","mainArea","split","join","socialLinks","links","labels","map","link","filter","Boolean","length","facebookUrl","instagramUrl","xUrl","linkedinUrl","youtubeUrl","tiktokUrl","hostTokenDefinition","Object","prototype","hasOwnProperty","call","HOST_TOKEN_PATTERN","isHostImageToken","keys","hostTokensIn","includes","match","matchAll","push","resolveHostToken","definition","fallback","resolveHostTokens","_token","String","validateHostTokens","options","allow","issues","seen","Set","has","add","kind","message","shouldOmitBlock","describeHostTokens","values","token","set","hostTokenMerge","merge","slice","email","resolveNodesHostTokens","nodes","changed","next","id","node","entries","props","nodeChanged","nextProps","resolved"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,wB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O,SAAS2D,uBACdC,KAAQ,EACR3G,IAAwC;IAExC,IAAI,CAAC2G,OAAO,OAAOA;IACnB,IAAIC,UAAU;IACd,MAAMC,OAA4B,CAAC;IACnC,KAAK,MAAM,CAACC,IAAIC,KAAK,IAAI1C,OAAO2C,OAAO,CAACL,OAAQ;QAC9C,MAAMM,QAAQF,wBAAAA,KAAME,KAAK;QACzB,IAAI,CAACA,OAAO;YACVJ,IAAI,CAACC,GAAG,GAAGC;YACX;QACF;QACA,IAAIG,cAAc;QAClB,MAAMC,YAAqC,CAAC;QAC5C,KAAK,MAAM,CAACjF,KAAKvC,MAAM,IAAI0E,OAAO2C,OAAO,CAACC,OAAQ;YAChD,IAAI,OAAOtH,UAAU,YAAYA,MAAMkF,QAAQ,CAAC,OAAO;gBACrD,MAAMuC,WAAWhC,kBAAkBzF,OAAOK;gBAC1CmH,SAAS,CAACjF,IAAI,GAAGkF;gBACjB,IAAIA,aAAazH,OAAOuH,cAAc;YACxC,OAAO;gBACLC,SAAS,CAACjF,IAAI,GAAGvC;YACnB;QACF;QACAkH,IAAI,CAACC,GAAG,GAAGI,cAAc,aAAKH;YAAME,OAAOE;aAAcJ;QACzDH,UAAUA,WAAWM;IACvB;IACA,OAAQN,UAAUC,OAAOF;AAC3B"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/host-tokens.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 { structuredAddressLine } from './business-profile'\nimport { siteProfileUrls, type HostSeoEntity } from './content-authors'\nimport { hostPublicOrigin } from './host-naming'\nimport { normalizeAreaServed } from './local-business'\n\n/**\n * Host variables — publisher templates that fill themselves in (AGL-1022).\n *\n * A publisher writing an email template cannot reference the installing site,\n * so every install begins with the same chore: swap the placeholder logo, fix\n * the business name, correct the links. Miss one and the site sends an email\n * carrying someone else's branding.\n *\n * `host.*` gives artifacts a way to NAME the host instead of hard-coding it.\n * The author writes `{{host.businessName}}`; the installing site fills it in,\n * and it stays filled in when that site rebrands.\n *\n * ## The namespace IS the security boundary\n *\n * This is publisher-authored content resolving against tenant data, so the\n * registry is CLOSED and each token reads through a hand-written function\n * rather than a path into the document. That is the whole design: a token\n * cannot address `stripeAccountId`, or `memberRoles`, or anything else, because\n * there is no path syntax to express it — `host.` is followed by a key that\n * either appears in {@link HOST_TOKENS} or resolves to nothing at all. Adding a\n * token is a deliberate edit here, reviewable as a diff.\n *\n * A path-based registry (\"allow `host.seo.title`\") would have been shorter and\n * is the version to refuse: allowlisting prefixes is how a namespace grows a\n * hole, and the first `host.orgId` would be a data leak with a plausible commit\n * message.\n *\n * ## Resolve LATE\n *\n * At render and at send, never at install. Freezing values into the artifact\n * would make a rebrand stop propagating silently — the site would keep sending\n * last year's business name from a template nobody remembers is a template.\n *\n * ## Every token defines what \"empty\" does\n *\n * A site with no logo must produce something deliberate. Never an empty image,\n * and never the literal `{{host.logo}}` reaching a visitor — a leaked token is\n * the most embarrassing possible failure for a feature whose entire purpose is\n * to stop templates looking unfinished.\n */\n\n/**\n * What a token yields, so a renderer knows how to place it and the authoring\n * surface can refuse it in the wrong slot.\n *\n * `text` is the only type safe to drop into arbitrary copy. The others carry a\n * shape a slot has to understand — an `image` in a paragraph is a URL sitting\n * in the middle of a sentence, which is exactly the \"fails in a sent email\"\n * outcome this typing exists to move to authoring time.\n */\nexport type HostTokenType = 'text' | 'url' | 'email' | 'image' | 'address'\n\n/** What a renderer should do when a token resolves to nothing. */\nexport type HostTokenEmptyBehaviour =\n /** Render nothing in its place; the surrounding copy still makes sense. */\n | 'blank'\n /**\n * The block holding it should be dropped entirely. An `<img src=\"\">` is a\n * broken-image icon in every mail client, which is worse than no logo.\n */\n | 'omit-block'\n\n/** The site fields a token may read. A closed, explicit surface. */\nexport interface HostTokenSource {\n displayName?: string\n logoUrl?: string\n logoDarkUrl?: string\n subdomain?: string\n cname?: string\n /**\n * The one-block copies of the email and address, and the social links\n * (AGL-1022). Setup → Business profile writes the email and address to `seo.entity`\n * and mirrors them here (AGL-4136), so these are what a token reads when\n * the entity has none: a site saved before that, or by the native apps.\n */\n business?: {\n supportEmail?: string\n address?: string\n socialLinks?: Array<{ label?: string; url?: string }>\n }\n /**\n * The business's facts as Setup → Business profile and SEO → Local business store\n * them (AGL-4136): the name, slogan, phone, email, structured address, the\n * profiles it claims and the areas it serves.\n */\n seo?: {\n entity?: Pick<\n HostSeoEntity,\n | 'name'\n | 'logo'\n | 'slogan'\n | 'email'\n | 'telephone'\n | 'address'\n | 'sameAs'\n | 'areaServed'\n >\n }\n}\n\nexport interface HostTokenDefinition {\n /** The key after `host.` */\n key: string\n type: HostTokenType\n label: string\n description: string\n /** Reads the value. Hand-written per token — never a path into the document. */\n resolve: (host: HostTokenSource) => string | undefined\n /**\n * A deliberate second choice when `resolve` finds nothing.\n *\n * Not a nicety: \"fall back to the business name\" is what turns a missing logo\n * from a hole in the page into a wordmark, which is what a careful designer\n * would have done by hand.\n */\n fallback?: (host: HostTokenSource) => string | undefined\n whenEmpty: HostTokenEmptyBehaviour\n}\n\nconst trimmed = (value: unknown): string | undefined => {\n const text = typeof value === 'string' ? value.trim() : ''\n return text || undefined\n}\n\n/**\n * The site's public URL.\n *\n * A custom domain wins when connected, because that is the address the site is\n * actually known by — a template linking to the aglyn.app subdomain of a site\n * with its own domain is technically correct and reads as a mistake.\n */\nfunction siteUrl(host: HostTokenSource): string | undefined {\n const custom = trimmed(host.cname)\n if (custom) return `https://${custom.replace(/^https?:\\/\\//, '')}`\n // `hostPublicOrigin`, not a fourth hand-rolled apex (AGL-2195). The cname\n // branch stays here because this one strips a scheme the token source may\n // carry; the subdomain branch has no such difference and had none — it was\n // the same two lines with `aglyn.app` written in, so an operator's own apex\n // was honoured everywhere except in the tokens a template renders.\n return hostPublicOrigin({ subdomain: trimmed(host.subdomain) })\n}\n\nfunction businessName(host: HostTokenSource): string | undefined {\n return trimmed(host.seo?.entity?.name) ?? trimmed(host.displayName)\n}\n\nfunction logo(host: HostTokenSource): string | undefined {\n return trimmed(host.logoUrl) ?? trimmed(host.seo?.entity?.logo)\n}\n\n/**\n * A phone number as a `tel:` link (AGL-4136): everything but its digits and\n * a leading `+` removed, so `+1 (512) 555-0100` dials `tel:+15125550100`.\n * Nothing when the number holds no digit, so a Call button never links to a\n * bare `tel:`.\n */\nexport function telephoneHref(phone: unknown): string | undefined {\n const text = trimmed(phone)\n if (!text) return undefined\n const digits = text.replace(/\\D+/g, '')\n if (!digits) return undefined\n return `tel:${text.startsWith('+') ? '+' : ''}${digits}`\n}\n\n/**\n * The social networks a page can link by name (AGL-4136), each with the\n * hostnames its profile addresses are served from. A hostname matches itself\n * and any subdomain of itself, so `www.` and `m.` addresses are the same\n * profile. X keeps `twitter.com`, because a link saved before the rename is\n * still the same account.\n */\nconst SOCIAL_NETWORK_HOSTS = {\n facebook: ['facebook.com', 'fb.com'],\n instagram: ['instagram.com'],\n x: ['x.com', 'twitter.com'],\n linkedin: ['linkedin.com'],\n youtube: ['youtube.com', 'youtu.be'],\n tiktok: ['tiktok.com'],\n} as const\n\nexport type HostSocialNetwork = keyof typeof SOCIAL_NETWORK_HOSTS\n\n/**\n * The site's profile on one network: the first of the profiles it claims\n * (`siteProfileUrls`, the entity's `sameAs` and then Setup → Business profile's\n * social links, https only) served from that network's hostname. Matched by\n * HOSTNAME rather than by the link's label, because the label is free text\n * and the address is what a visitor is sent to.\n */\nexport function siteSocialProfileUrl(\n host: HostTokenSource | null | undefined,\n network: HostSocialNetwork,\n): string | undefined {\n const hosts: readonly string[] = SOCIAL_NETWORK_HOSTS[network]\n for (const value of siteProfileUrls(host)) {\n let hostname: string\n try {\n hostname = new URL(value).hostname.toLowerCase()\n } catch {\n continue\n }\n if (hosts.some((name) => hostname === name || hostname.endsWith(`.${name}`))) {\n return value\n }\n }\n return undefined\n}\n\n/** The areas served, as SEO → Local business stores and the structured data publishes them. */\nfunction areasServed(host: HostTokenSource): string[] {\n return normalizeAreaServed(host.seo?.entity?.areaServed)\n}\n\n/** One social network's profile link as a token: a URL, dropped where the site has none. */\nfunction socialToken(\n network: HostSocialNetwork,\n key: string,\n name: string,\n): HostTokenDefinition {\n return {\n key,\n type: 'url',\n label: `${name} link`,\n description: `The address of the site’s ${name} profile, from Setup → Business profile.`,\n resolve: (host) => siteSocialProfileUrl(host, network),\n whenEmpty: 'omit-block',\n }\n}\n\n/**\n * The closed registry.\n *\n * Ordered as an author would look for them. Every entry is reachable from a\n * field a site can actually set — a token that can never resolve is worse than\n * an absent one, because it teaches people the feature does not work.\n */\nexport const HOST_TOKENS: Record<string, HostTokenDefinition> = {\n businessName: {\n key: 'businessName',\n type: 'text',\n label: 'Business name',\n description:\n 'The business name from Setup → Business profile, or the site’s name when none is set.',\n resolve: businessName,\n whenEmpty: 'blank',\n },\n slogan: {\n key: 'slogan',\n type: 'text',\n label: 'Slogan',\n description: 'A short line about the business, from Setup → Business profile.',\n resolve: (host) => trimmed(host.seo?.entity?.slogan),\n whenEmpty: 'blank',\n },\n logo: {\n key: 'logo',\n type: 'image',\n label: 'Logo',\n description: 'The site’s logo image.',\n resolve: logo,\n // No image: the block is dropped and the business name carries the brand\n // instead, which is what the block was for.\n whenEmpty: 'omit-block',\n },\n logoDark: {\n key: 'logoDark',\n type: 'image',\n label: 'Logo for dark backgrounds',\n description:\n 'The logo to show on a dark background. The site’s logo when it has no dark one.',\n // The pair a header toggles by color scheme (AGL-4119): a site with one\n // logo shows it in both schemes, and one with none shows neither.\n resolve: (host) => trimmed(host.logoDarkUrl) ?? logo(host),\n whenEmpty: 'omit-block',\n },\n url: {\n key: 'url',\n type: 'url',\n label: 'Site address',\n description: 'The site’s public URL — its custom domain when connected.',\n resolve: siteUrl,\n whenEmpty: 'blank',\n },\n phone: {\n key: 'phone',\n type: 'text',\n label: 'Phone',\n description: 'The business’s phone number, as entered on Setup → Business profile.',\n resolve: (host) => trimmed(host.seo?.entity?.telephone),\n whenEmpty: 'omit-block',\n },\n phoneLink: {\n key: 'phoneLink',\n type: 'url',\n label: 'Phone link',\n description:\n 'The phone number as a tel: link, for a Call button’s link. Dropped when the site has no phone.',\n resolve: (host) => telephoneHref(host.seo?.entity?.telephone),\n whenEmpty: 'omit-block',\n },\n /*\n The key keeps its old name, because pages and emails already say\n `{{host.supportEmail}}`. What it reads is the site's one email (AGL-4136):\n the one Setup → Business profile saves to the entity, else the one-block copy a\n site saved before that.\n */\n supportEmail: {\n key: 'supportEmail',\n type: 'email',\n label: 'Email',\n description: 'The email address visitors write to, from Setup → Business profile.',\n resolve: (host) => siteContactEmail(host) ?? undefined,\n whenEmpty: 'omit-block',\n },\n address: {\n key: 'address',\n type: 'address',\n label: 'Postal address',\n description:\n 'The business’s postal address from Setup → Business profile, as one block of text.',\n // The structured address, formatted the one way it is formatted\n // everywhere (AGL-4136), else the one-block copy as it was typed —\n // line breaks kept, because a document prints it a line per line.\n resolve: (host) =>\n trimmed(structuredAddressLine(host.seo?.entity?.address)) ??\n trimmed(host.business?.address),\n whenEmpty: 'omit-block',\n },\n mainArea: {\n key: 'mainArea',\n type: 'text',\n label: 'Main area',\n description:\n 'The first area served, by its place name: San Antonio, for “San Antonio, TX”. From SEO → Local business.',\n // The text before the first comma, so the token reads in a sentence —\n // \"across San Antonio and surrounding areas\" — and a page that already\n // says the place name can switch to it without a visible change.\n resolve: (host) => trimmed(areasServed(host)[0]?.split(',')[0]),\n whenEmpty: 'blank',\n },\n areasServed: {\n key: 'areasServed',\n type: 'text',\n label: 'Areas served',\n description:\n 'Every area served, in order, separated by commas. From SEO → Local business.',\n resolve: (host) => trimmed(areasServed(host).join(', ')),\n whenEmpty: 'blank',\n },\n socialLinks: {\n key: 'socialLinks',\n type: 'text',\n label: 'Social links',\n description: 'The site’s social profiles, as a list of labeled links.',\n // Rendered as text here so a token in copy degrades to something readable;\n // a link to one profile is that network's own token below (AGL-4136).\n resolve: (host) => {\n const links = host.business?.socialLinks ?? []\n const labels = links\n .map((link) => trimmed(link?.label) ?? trimmed(link?.url))\n .filter((label): label is string => Boolean(label))\n return labels.length ? labels.join(' · ') : undefined\n },\n whenEmpty: 'omit-block',\n },\n /*\n One link per common network (AGL-4136), so a page's social icons link\n the site's own profiles from Setup → Business profile instead of a hand-made\n variable per network.\n */\n facebookUrl: socialToken('facebook', 'facebookUrl', 'Facebook'),\n instagramUrl: socialToken('instagram', 'instagramUrl', 'Instagram'),\n xUrl: socialToken('x', 'xUrl', 'X'),\n linkedinUrl: socialToken('linkedin', 'linkedinUrl', 'LinkedIn'),\n youtubeUrl: socialToken('youtube', 'youtubeUrl', 'YouTube'),\n tiktokUrl: socialToken('tiktok', 'tiktokUrl', 'TikTok'),\n}\n\n/**\n * The registry's entry for `key`, or undefined when it declares none.\n *\n * An OWN entry only. `HOST_TOKENS` is an object literal, so a bare index also\n * finds the `Object.prototype` members — `constructor`, `toString`, `valueOf` —\n * and every one of those names matches {@link HOST_TOKEN_PATTERN}. Read that\n * way, `{{host.constructor}}` answers the `Object` function where a definition\n * belongs, and calling its `resolve` throws in the middle of a render. A name\n * the registry does not declare resolves to nothing, whatever the name is.\n */\nexport function hostTokenDefinition(\n key: string,\n): HostTokenDefinition | undefined {\n return Object.prototype.hasOwnProperty.call(HOST_TOKENS, key)\n ? HOST_TOKENS[key]\n : undefined\n}\n\n/**\n * `{{host.key}}` — whitespace-tolerant, and deliberately NOT dotted beyond one\n * segment. `host.a.b` does not match, so there is no path syntax to abuse.\n */\nexport const HOST_TOKEN_PATTERN = /\\{\\{\\s*host\\.([a-zA-Z][a-zA-Z0-9_]*)\\s*\\}\\}/g\n\n/**\n * Whether a value is exactly one image token, like `{{host.logo}}`: what a\n * picture's `src` may be when it is the installing site's own logo. It becomes\n * that site's stored value at render, so it names nothing of the publisher's.\n */\nexport function isHostImageToken(value: string): boolean {\n const keys = hostTokensIn(value)\n return (\n keys.length === 1 &&\n value.replace(HOST_TOKEN_PATTERN, '').trim() === '' &&\n hostTokenDefinition(keys[0])?.type === 'image'\n )\n}\n\n/** Every `host.*` token in a string, in order, including unknown ones. */\nexport function hostTokensIn(text: string): string[] {\n if (typeof text !== 'string' || !text.includes('{{')) return []\n const keys: string[] = []\n for (const match of text.matchAll(HOST_TOKEN_PATTERN)) keys.push(match[1])\n return keys\n}\n\n/** The resolved value of one token, or undefined when the site has none. */\nexport function resolveHostToken(\n key: string,\n host: HostTokenSource | null | undefined,\n): string | undefined {\n const definition = hostTokenDefinition(key)\n if (!definition || !host) return undefined\n return definition.resolve(host) ?? definition.fallback?.(host)\n}\n\n/**\n * Replaces every `host.*` token with the installing site's value.\n *\n * An unresolved token — unknown key, or a site that has not set the field —\n * renders EMPTY, never the literal. Leaking `{{host.logo}}` into a sent email\n * is the failure this feature exists to prevent, so it cannot be the fallback\n * for the feature's own gaps. The authoring-time check\n * ({@link validateHostTokens}) is where a typo is meant to be caught, while the\n * writer can still fix it.\n */\nexport function resolveHostTokens(\n text: string,\n host: HostTokenSource | null | undefined,\n): string {\n if (typeof text !== 'string' || !text.includes('{{')) return text\n return text.replace(HOST_TOKEN_PATTERN, (_token, key) =>\n resolveHostToken(String(key), host) ?? '',\n )\n}\n\nexport interface HostTokenIssue {\n key: string\n /**\n * `unknown` — no such token; it will render empty.\n * `wrong-slot` — the token's type cannot be placed here.\n */\n kind: 'unknown' | 'wrong-slot'\n message: string\n}\n\n/**\n * Authoring-time check: catch a token before it reaches a visitor.\n *\n * The two things worth failing on are a typo (which would silently render\n * nothing) and a type mismatch (an image URL dropped into a sentence). Both are\n * invisible at authoring time without this and obvious afterwards, which is the\n * wrong way round for something that ends up in a sent email.\n *\n * `allow` names the types this slot can take. Omit it for free text, where only\n * `text` and the string-ish types make sense.\n */\nexport function validateHostTokens(\n text: string,\n options?: { allow?: readonly HostTokenType[] },\n): HostTokenIssue[] {\n const allow = options?.allow ?? ['text', 'url', 'email', 'address']\n const issues: HostTokenIssue[] = []\n const seen = new Set<string>()\n for (const key of hostTokensIn(text)) {\n if (seen.has(key)) continue\n seen.add(key)\n const definition = hostTokenDefinition(key)\n if (!definition) {\n issues.push({\n key,\n kind: 'unknown',\n message:\n `There is no host variable called \"${key}\". It will render as ` +\n 'nothing. Available: ' +\n Object.keys(HOST_TOKENS).join(', ') +\n '.',\n })\n continue\n }\n if (!allow.includes(definition.type)) {\n issues.push({\n key,\n kind: 'wrong-slot',\n message:\n `\"${definition.label}\" is ${\n definition.type === 'image' ? 'an image' : `a ${definition.type}`\n }, so it cannot go here. Put it in a slot that takes ` +\n `${definition.type === 'image' ? 'an image' : `a ${definition.type}`}.`,\n })\n }\n }\n return issues\n}\n\n/**\n * Whether a block containing these tokens should be dropped for this site.\n *\n * The other half of \"every token needs a defined empty behaviour\": a logo block\n * on a site with no logo should not render an empty image, and the renderer\n * cannot know that from the resolved string alone — `''` is both \"no value\" and\n * \"a value that happens to be empty\". Asking here keeps the rule with the\n * token definition rather than spread across the surfaces that render it.\n */\nexport function shouldOmitBlock(\n text: string,\n host: HostTokenSource | null | undefined,\n): boolean {\n for (const key of hostTokensIn(text)) {\n const definition = hostTokenDefinition(key)\n if (!definition || definition.whenEmpty !== 'omit-block') continue\n if (!resolveHostToken(key, host)) return true\n }\n return false\n}\n\n/**\n * Every token with its resolved value for one site, for an authoring picker\n * that shows what each will actually produce here.\n *\n * A picker listing token names alone makes the author guess; showing the value\n * this site would render is what turns \"is it businessName or business_name\"\n * into a question nobody has to ask.\n */\nexport function describeHostTokens(\n host: HostTokenSource | null | undefined,\n): Array<HostTokenDefinition & { token: string; value?: string; set: boolean }> {\n return Object.values(HOST_TOKENS).map((definition) => {\n const value = resolveHostToken(definition.key, host)\n return {\n ...definition,\n token: `{{host.${definition.key}}}`,\n value,\n set: Boolean(value),\n }\n })\n}\n\n/** One row of {@link describeHostTokens} as plain data: the definition without its resolvers. */\nexport interface HostTokenPreviewRow {\n key: string\n type: HostTokenType\n label: string\n description: string\n whenEmpty: HostTokenEmptyBehaviour\n token: string\n value?: string\n set: boolean\n}\n\n/**\n * {@link describeHostTokens} without the resolvers, so it can travel as data:\n * the native apps' Business details card lists \"What your pages can use\"\n * from it, and replays these answers in their tests (AGL-4136).\n */\nexport function hostTokenPreview(\n host: HostTokenSource | null | undefined,\n): HostTokenPreviewRow[] {\n return describeHostTokens(host).map(\n ({ key, type, label, description, whenEmpty, token, value, set }) => ({\n key,\n type,\n label,\n description,\n whenEmpty,\n token,\n ...(value === undefined ? {} : { value }),\n set,\n }),\n )\n}\n\n/**\n * The `host.*` values as a merge-token map, for surfaces that already have a\n * token substituter of their own.\n *\n * This is how EMAIL gets host variables without the email library depending on\n * this one: `substituteMergeTokens` already matches `{{a.b}}`, so a caller\n * spreads this into the merge map it was passing anyway. One registry, two\n * surfaces, no second substitution engine to drift.\n *\n * Every registered token appears, INCLUDING the ones this site has not set —\n * as `''`. Omitting them would leave `{{host.supportEmail}}` for the generic\n * catch-all to blank, which works today and works by accident: the moment a\n * surface without that catch-all uses this map, the literal token ships.\n */\nexport function hostTokenMerge(\n host: HostTokenSource | null | undefined,\n): Record<string, string> {\n const merge: Record<string, string> = {}\n for (const key of Object.keys(HOST_TOKENS)) {\n merge[`host.${key}`] = resolveHostToken(key, host) ?? ''\n }\n return merge\n}\n\n/**\n * The email address a visitor writes to the business at: the one Setup →\n * Business saves (`seo.entity.email`), else the one-block copy a site saved\n * before that (`business.supportEmail`). Null when the site has neither. One\n * answer for every place that names it: the `{{host.supportEmail}}` token\n * and so the email footer, the waiver consent, the quote and invoice PDFs,\n * the Reply-To of the quote email (AGL-4097), and the address a refused form\n * or sign-up offers instead (AGL-4136). Trimmed, not validated; a caller\n * putting it in a header checks it is an address.\n */\nexport function siteContactEmail(\n host:\n | {\n seo?: { entity?: { email?: unknown } | null } | null\n business?: { supportEmail?: unknown } | null\n }\n | null\n | undefined,\n): string | null {\n const text = (value: unknown) => (typeof value === 'string' ? value.trim().slice(0, 320) : '')\n return text(host?.seo?.entity?.email) || text(host?.business?.supportEmail) || null\n}\n\n/**\n * Resolves `host.*` tokens across every string prop of a normalized node map.\n *\n * Mirrors `resolveNodesBindings` deliberately — same shallow-copy discipline,\n * same string-props-only rule — so a screen and an email resolve the same token\n * to the same value. The issue's warning is the reason: two resolvers drift,\n * and then the same token means different things depending on where an author\n * typed it.\n *\n * Returns the input untouched when the site has nothing to substitute, so a\n * binding-free tree costs one `Object.entries`.\n */\nexport function resolveNodesHostTokens<T extends Record<string, any>>(\n nodes: T,\n host: HostTokenSource | null | undefined,\n): T {\n if (!nodes) return nodes\n let changed = false\n const next: Record<string, any> = {}\n for (const [id, node] of Object.entries(nodes)) {\n const props = node?.props\n if (!props) {\n next[id] = node\n continue\n }\n let nodeChanged = false\n const nextProps: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(props)) {\n if (typeof value === 'string' && value.includes('{{')) {\n const resolved = resolveHostTokens(value, host)\n nextProps[key] = resolved\n if (resolved !== value) nodeChanged = true\n } else {\n nextProps[key] = value\n }\n }\n next[id] = nodeChanged ? { ...node, props: nextProps } : node\n changed = changed || nodeChanged\n }\n return (changed ? next : nodes) as T\n}\n"],"names":["structuredAddressLine","siteProfileUrls","hostPublicOrigin","normalizeAreaServed","trimmed","value","text","trim","undefined","siteUrl","host","custom","cname","replace","subdomain","businessName","seo","entity","name","displayName","logo","logoUrl","telephoneHref","phone","digits","startsWith","SOCIAL_NETWORK_HOSTS","facebook","instagram","x","linkedin","youtube","tiktok","siteSocialProfileUrl","network","hosts","hostname","URL","toLowerCase","some","endsWith","areasServed","areaServed","socialToken","key","type","label","description","resolve","whenEmpty","HOST_TOKENS","slogan","logoDark","logoDarkUrl","url","telephone","phoneLink","supportEmail","siteContactEmail","address","business","mainArea","split","join","socialLinks","links","labels","map","link","filter","Boolean","length","facebookUrl","instagramUrl","xUrl","linkedinUrl","youtubeUrl","tiktokUrl","hostTokenDefinition","Object","prototype","hasOwnProperty","call","HOST_TOKEN_PATTERN","isHostImageToken","keys","hostTokensIn","includes","match","matchAll","push","resolveHostToken","definition","fallback","resolveHostTokens","_token","String","validateHostTokens","options","allow","issues","seen","Set","has","add","kind","message","shouldOmitBlock","describeHostTokens","values","token","set","hostTokenPreview","hostTokenMerge","merge","slice","email","resolveNodesHostTokens","nodes","changed","next","id","node","entries","props","nodeChanged","nextProps","resolved"],"mappings":";AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,qBAAqB,QAAQ,wBAAoB;AAC1D,SAASC,eAAe,QAA4B,uBAAmB;AACvE,SAASC,gBAAgB,QAAQ,mBAAe;AAChD,SAASC,mBAAmB,QAAQ,sBAAkB;AAyHtD,MAAMC,UAAU,CAACC;IACf,MAAMC,OAAO,OAAOD,UAAU,WAAWA,MAAME,IAAI,KAAK;IACxD,OAAOD,QAAQE;AACjB;AAEA;;;;;;CAMC,GACD,SAASC,QAAQC,IAAqB;IACpC,MAAMC,SAASP,QAAQM,KAAKE,KAAK;IACjC,IAAID,QAAQ,OAAO,CAAC,QAAQ,EAAEA,OAAOE,OAAO,CAAC,gBAAgB,KAAK;IAClE,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,4EAA4E;IAC5E,mEAAmE;IACnE,OAAOX,iBAAiB;QAAEY,WAAWV,QAAQM,KAAKI,SAAS;IAAE;AAC/D;AAEA,SAASC,aAAaL,IAAqB;QAClCN;QAAQM,kBAAAA;IAAf,QAAON,WAAAA,SAAQM,YAAAA,KAAKM,GAAG,sBAARN,mBAAAA,UAAUO,MAAM,qBAAhBP,iBAAkBQ,IAAI,aAA9Bd,WAAmCA,QAAQM,KAAKS,WAAW;AACpE;AAEA,SAASC,KAAKV,IAAqB;QAC1BN;QAAiCM,kBAAAA;IAAxC,QAAON,WAAAA,QAAQM,KAAKW,OAAO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MwC,WAAWjC,kBAAkBzF,OAAOK;gBAC1CoH,SAAS,CAAClF,IAAI,GAAGmF;gBACjB,IAAIA,aAAa1H,OAAOwH,cAAc;YACxC,OAAO;gBACLC,SAAS,CAAClF,IAAI,GAAGvC;YACnB;QACF;QACAmH,IAAI,CAACC,GAAG,GAAGI,cAAc,aAAKH;YAAME,OAAOE;aAAcJ;QACzDH,UAAUA,WAAWM;IACvB;IACA,OAAQN,UAAUC,OAAOF;AAC3B"}
@@ -32,8 +32,10 @@ export declare function nativeAppAssociationRoute(pathname: string): string | nu
32
32
  * auth session opens them for the app, and a universal link there would loop
33
33
  * back into the app), the native hand-off and other `/auth` pages, the
34
34
  * sign-out page, the site admin bar's connect page, a plugin's public
35
- * device pages and a site's photo link (`/p/<linkId>`, opened on a phone
36
- * by someone with no account). The sections the apps finish natively are
35
+ * device pages, a site's photo link (`/p/<linkId>`, opened on a phone
36
+ * by someone with no account) and the connector consent page
37
+ * (`/oauth/authorize`, AGL-4225), which an app such as Claude opens in the
38
+ * browser and expects to finish there. The sections the apps finish natively are
37
39
  * {@link NATIVE_AUTH_LINK_SEGMENTS}.
38
40
  *
39
41
  * The rest of the console's top-level sections (`admin`, `billing`,
@@ -47,9 +49,11 @@ export declare const NATIVE_WEB_ONLY_TOP_LEVEL_SEGMENTS: readonly string[];
47
49
  /**
48
50
  * The pre-sign-in sections whose exact page the apps finish natively: sign-up
49
51
  * (with its `?plan=`), an emailed verification link, an emailed password
50
- * reset and account recovery (`AuthFlow.swift`; Android's console intent
51
- * filter lists the same four paths). Only the page itself opens the app;
52
- * anything under it stays in the browser, where the console handles it.
52
+ * reset and account recovery (`AuthFlow.swift`, `AuthFlow.kt`). Only the page
53
+ * itself opens the app; anything under it stays in the browser, where the
54
+ * console handles it. Android's App Link filter claims the same console paths
55
+ * as {@link consoleAppLinksComponents}, refusing each exclusion in its manifest
56
+ * (`native-app-association.spec.ts` holds the two together, AGL-4059).
53
57
  */
54
58
  export declare const NATIVE_AUTH_LINK_SEGMENTS: readonly string[];
55
59
  /** One `applinks` component: a URL path pattern, optionally excluded. */