@aglyn/aglyn 1.0.0-beta.211 → 1.0.0-beta.212

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-contributions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * What a plugin contributes, and where (AGL-3116).\n *\n * A plugin loads only where something uses it. Installing one loads nothing:\n * a published page fetches a plugin's code when the page places one of its\n * elements or the site runs one of its features, and a console screen\n * fetches it when the screen renders one of its slots or routes, or when the\n * plugin draws something the shell renders on every screen.\n *\n * The loaders cannot learn that by running a plugin, because running it is\n * the cost being avoided. So each plugin DECLARES its contributions:\n * first-party plugins in `plugins.config.json`, marketplace plugins in the\n * manifest they publish (`contributes`). The declaration is the whole of what\n * a loader reads, and it is data: this module is dependency-free so the\n * server, both apps, the verifier and the build tools share one reading.\n *\n * A declared surface only narrows where to look. Presence is the rule: a\n * plugin that declares a component loads on the pages that place it, not on\n * every page of the site that installed it.\n *\n * ## A plugin that declares nothing\n *\n * Every marketplace version published before this contract has no\n * `contributes`. Such a plugin keeps working under one default:\n *\n * - **On a published page it loads only where its element is placed**: a\n * node whose `pluginId` names the plugin (its manifest id or its listing\n * id). That is the one presence signal a page carries without running the\n * bundle, and it is the only way a page can show an element the plugin\n * registers. A site runtime of an undeclared plugin does not load, and the\n * publish pipeline refuses a bundle that registers one without declaring\n * it, so the only plugins this default governs are the ones already\n * published.\n * - **In the console it loads with the workspace shell**, as it always did,\n * because a nav tab or a provider is only discoverable by running\n * `register()`. Nothing on a published page depends on this.\n */\n\n/** What a plugin adds to a published site. */\nexport interface PluginSiteContributions {\n /**\n * Canvas component ids the plugin registers: the elements a page places. A\n * published page loads the plugin only when its node tree places one.\n */\n components?: string[]\n /**\n * Site features: runtimes the plugin mounts on every page of a site that\n * switched it on (an announcement bar, an experiment runner), named by the\n * `runtimeId` it registers. A plugin with a feature loads on every page of\n * such a site, which is what a feature is.\n */\n features?: string[]\n}\n\n/** What a plugin adds to the console. */\nexport interface PluginConsoleContributions {\n /**\n * The widget slots its widgets fill: the `CONSOLE_WIDGET_SLOTS` zones, the\n * panels the shell draws as slots (the assistant dock `assistPanel`, the\n * besigner's `besignerInspector`), and zones another plugin hosts. A screen\n * that renders one of them loads the plugin.\n */\n slots?: string[]\n /** Site-level console routes it serves (`/forms`), beneath `/hosts/[host]`. */\n routes?: string[]\n /** Organization-level console routes it serves (`/outreach`). */\n orgRoutes?: string[]\n /**\n * The shell draws something of it on every screen of a workspace: a nav\n * tab, an organization tab, a staff tab or a provider. Such a plugin loads\n * with the shell, because every screen renders it.\n */\n shell?: boolean\n}\n\nexport interface PluginContributions {\n site?: PluginSiteContributions\n console?: PluginConsoleContributions\n}\n\n/** Bound on each declared list, so a manifest cannot hand a loader a novel. */\nexport const PLUGIN_MAX_CONTRIBUTIONS = 128\n\n/**\n * A component, feature or slot id: an identifier with the separators ids in\n * the platform use (`muiTypography`, `marketplacePlugin`, `ai.assist`).\n */\nconst CONTRIBUTION_ID = /^[A-Za-z_][A-Za-z0-9_.:-]{0,79}$/\n\n/**\n * A console route: one or more path segments, as a nav item's `href` names\n * them. Never a URL, never `..`.\n */\nconst CONTRIBUTION_ROUTE = /^(\\/[A-Za-z0-9_-]+){1,8}$/\n\ntype Sanitized =\n | { ok: true; contributions: PluginContributions }\n | { ok: false; error: string }\n\n/**\n * Validates a declared `contributes` block.\n *\n * Malformed input is REFUSED rather than trimmed: a loader reads this to\n * decide where a plugin runs, so a declaration that silently lost an entry\n * would stop the plugin loading where it is used, and nobody would see why.\n * Duplicates are collapsed and empty lists dropped, because neither changes\n * what the declaration means.\n *\n * `{}` is valid and means \"contributes nothing anywhere\", which is a\n * different statement from an absent block (see the module note).\n */\nexport function sanitizePluginContributions(input: unknown): Sanitized {\n if (!isPlainObject(input)) {\n return { ok: false, error: 'contributes must be an object' }\n }\n const out: PluginContributions = {}\n for (const key of Object.keys(input)) {\n if (key !== 'site' && key !== 'console') {\n return { ok: false, error: `contributes.${key} is not a known surface` }\n }\n }\n\n if (input['site'] !== undefined) {\n const site = input['site']\n if (!isPlainObject(site)) {\n return { ok: false, error: 'contributes.site must be an object' }\n }\n const next: PluginSiteContributions = {}\n for (const key of Object.keys(site)) {\n if (key !== 'components' && key !== 'features') {\n return { ok: false, error: `contributes.site.${key} is not a known contribution` }\n }\n const list = idList(site[key], `contributes.site.${key}`, CONTRIBUTION_ID)\n if (list.ok === false) return { ok: false, error: list.error }\n if (list.values.length) next[key] = list.values\n }\n if (Object.keys(next).length) out.site = next\n }\n\n if (input['console'] !== undefined) {\n const consoleInput = input['console']\n if (!isPlainObject(consoleInput)) {\n return { ok: false, error: 'contributes.console must be an object' }\n }\n const next: PluginConsoleContributions = {}\n for (const key of Object.keys(consoleInput)) {\n if (key === 'shell') {\n if (typeof consoleInput['shell'] !== 'boolean') {\n return { ok: false, error: 'contributes.console.shell must be true or false' }\n }\n if (consoleInput['shell']) next.shell = true\n continue\n }\n if (key !== 'slots' && key !== 'routes' && key !== 'orgRoutes') {\n return {\n ok: false,\n error: `contributes.console.${key} is not a known contribution`,\n }\n }\n const list = idList(\n consoleInput[key],\n `contributes.console.${key}`,\n key === 'slots' ? CONTRIBUTION_ID : CONTRIBUTION_ROUTE,\n )\n if (list.ok === false) return { ok: false, error: list.error }\n if (list.values.length) next[key] = list.values\n }\n if (Object.keys(next).length) out.console = next\n }\n\n return { ok: true, contributions: out }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction idList(\n value: unknown,\n where: string,\n pattern: RegExp,\n): { ok: true; values: string[] } | { ok: false; error: string } {\n if (!Array.isArray(value)) return { ok: false, error: `${where} must be a list` }\n if (value.length > PLUGIN_MAX_CONTRIBUTIONS) {\n return { ok: false, error: `${where} lists more than ${PLUGIN_MAX_CONTRIBUTIONS}` }\n }\n const values: string[] = []\n for (const entry of value) {\n if (typeof entry !== 'string' || !pattern.test(entry)) {\n return { ok: false, error: `${where} has an invalid entry \"${String(entry)}\"` }\n }\n if (!values.includes(entry)) values.push(entry)\n }\n return { ok: true, values }\n}\n\n/**\n * A declared `contributes` block as a loader may trust it: the sanitized\n * block, or `undefined` for one that is absent or does not validate.\n *\n * Loaders read this from stored documents (a pinned version's manifest), and\n * a malformed stored block is treated as UNDECLARED — the default applies —\n * never as \"contributes nothing\", which would stop a plugin that is in use.\n */\nexport function readPluginContributions(\n input: unknown,\n): PluginContributions | undefined {\n if (input === undefined || input === null) return undefined\n const verdict = sanitizePluginContributions(input)\n return verdict.ok ? verdict.contributions : undefined\n}\n\n/**\n * What the surface a plugin is being registered into actually uses\n * (AGL-3141).\n *\n * The loaders carry this from the surface that computed it to each plugin's\n * register function, unchanged. A plugin that can register a part of itself\n * reads it; one that cannot ignores it, and the platform's behavior is the\n * same either way.\n *\n * An absent field means \"everything of that kind\". A surface that cannot say\n * what it uses must be handed all of it, because an element the surface\n * places and the set omits has no registered component and renders NOTHING,\n * silently (the blank-canvas invariant, AGL-52). Narrowing is an optimization\n * and must fail toward the whole.\n */\nexport interface PluginUse {\n /**\n * Canvas component ids the surface places, read from the FULL composed\n * document the way `pagePresence` reads it — withheld lazy-panel subtrees\n * included, because an element inside a panel the visitor opens later is\n * still this page's element.\n */\n componentIds?: readonly string[]\n}\n\n/** A node as presence reads it: the two ids a placed element carries. */\nexport interface PresenceNode {\n componentId?: string\n pluginId?: string\n}\n\n/** What a published page places: its component ids and the plugin ids stamped on its nodes. */\nexport interface PagePresence {\n componentIds: ReadonlySet<string>\n pluginIds: ReadonlySet<string>\n}\n\n/**\n * The component ids and plugin ids a node tree places.\n *\n * Read from the FULL composed document — layouts, grafted reusable\n * components and withheld lazy panels included — because an element inside\n * a panel the visitor opens later is still this page's element.\n */\nexport function pagePresence(\n nodes: Record<string, PresenceNode | null | undefined> | null | undefined,\n): PagePresence {\n const componentIds = new Set<string>()\n const pluginIds = new Set<string>()\n for (const node of Object.values(nodes ?? {})) {\n if (typeof node?.componentId === 'string' && node.componentId) {\n componentIds.add(node.componentId)\n }\n if (typeof node?.pluginId === 'string' && node.pluginId) {\n pluginIds.add(node.pluginId)\n }\n }\n return { componentIds, pluginIds }\n}\n\n/** A plugin as the presence rules see it. */\nexport interface PresenceSubject {\n /** The plugin's own id (a manifest `id`, or a first-party catalog id). */\n pluginId?: string\n /** A marketplace plugin's listing id, which its elements may carry instead. */\n listingId?: string\n /** Its declaration; `undefined` when it declares nothing. */\n contributes?: PluginContributions\n}\n\n/**\n * Whether a published page uses a plugin, so the page must load it.\n *\n * - An element of it is placed: a node stamped with the plugin's id, or,\n * for a declared plugin, a node whose component id it declares.\n * - It declares a site feature. The caller only asks about plugins the site\n * has switched on, and a feature runs on every page of such a site.\n *\n * A plugin that declares nothing is present only through its stamped\n * elements — the default in the module note.\n */\nexport function isPluginUsedOnPage(\n subject: PresenceSubject,\n page: PagePresence,\n): boolean {\n if (subject.pluginId && page.pluginIds.has(subject.pluginId)) return true\n if (subject.listingId && page.pluginIds.has(subject.listingId)) return true\n const site = subject.contributes?.site\n if (!site) return false\n if (site.features?.length) return true\n return (site.components ?? []).some((id) => page.componentIds.has(id))\n}\n\n/**\n * Where a plugin's console code loads, resolved with the default applied: a\n * plugin that declares nothing loads with the shell, as it always did.\n */\nexport interface ConsoleLoadPoints {\n shell: boolean\n slots: readonly string[]\n routes: readonly string[]\n orgRoutes: readonly string[]\n}\n\nexport function consoleLoadPoints(\n contributes: PluginContributions | undefined,\n): ConsoleLoadPoints {\n if (!contributes) return { shell: true, slots: [], routes: [], orgRoutes: [] }\n const declared = contributes.console ?? {}\n return {\n shell: Boolean(declared.shell),\n slots: declared.slots ?? [],\n routes: declared.routes ?? [],\n orgRoutes: declared.orgRoutes ?? [],\n }\n}\n\n/**\n * Whether a declared route serves `href`: the route itself, or a path beneath\n * it on a segment boundary, the way the shell's page resolver matches a nav\n * item that owns its subtree. `/products` serves `/products/orders` and never\n * `/products-archive`.\n */\nexport function routeServes(route: string, href: string): boolean {\n return href === route || href.startsWith(`${route}/`)\n}\n\n/**\n * A place in the console that loads plugins, as the surface drawing it names\n * itself (AGL-3142).\n *\n * - `shell`: the workspace chrome every screen has. It draws whatever a\n * plugin adds to every screen — a nav tab, an organization tab, a staff\n * tab, a provider — so a plugin that declares any of those loads here, and\n * so does one that declares nothing at all.\n * - `slots`: the zones a screen renders. The zones it names, not the plugins\n * it expects in them: a screen must never hold a plugin id.\n * - `route`: the path the reader has open, plugin-relative (`/products`,\n * `/products/orders`), on the level its route tree serves — `site` beneath\n * `/hosts/[host]`, `org` beneath the organization.\n */\nexport type ConsoleLoadWhere =\n | { at: 'shell' }\n | { at: 'slots'; slots: readonly string[] }\n | { at: 'route'; href: string; level: 'site' | 'org' }\n\n/**\n * Whether a console surface uses a plugin, so it must load it.\n *\n * The console twin of {@link isPluginUsedOnPage}, and the same rule: a\n * declaration says where a plugin's code belongs, and the surface that draws\n * that place is the one that fetches it. A screen asks about the zones it\n * renders and the path it serves; it never asks about a plugin by name.\n *\n * A plugin that declares nothing loads with the shell — the default in the\n * module note, and the reason the shell branch reads\n * {@link consoleLoadPoints} rather than the raw block. Its nav tab or its\n * provider is only discoverable by running `register()`, so narrowing it\n * anywhere else would take a tab away with no way to notice.\n */\nexport function isPluginUsedInConsole(\n contributes: PluginContributions | undefined,\n where: ConsoleLoadWhere,\n): boolean {\n const points = consoleLoadPoints(contributes)\n if (where.at === 'shell') return points.shell\n if (where.at === 'slots') {\n return points.slots.some((slot) => where.slots.includes(slot))\n }\n const routes = where.level === 'org' ? points.orgRoutes : points.routes\n return routes.some((route) => routeServes(route, where.href))\n}\n"],"names":["PLUGIN_MAX_CONTRIBUTIONS","CONTRIBUTION_ID","CONTRIBUTION_ROUTE","sanitizePluginContributions","input","isPlainObject","ok","error","out","key","Object","keys","undefined","site","next","list","idList","values","length","consoleInput","shell","console","contributions","value","Boolean","Array","isArray","where","pattern","entry","test","String","includes","push","readPluginContributions","verdict","pagePresence","nodes","componentIds","Set","pluginIds","node","componentId","add","pluginId","isPluginUsedOnPage","subject","page","has","listingId","contributes","features","components","some","id","consoleLoadPoints","declared","slots","routes","orgRoutes","routeServes","route","href","startsWith","isPluginUsedInConsole","points","at","slot","level"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCC,GAED,4CAA4C,GA0C5C,6EAA6E,GAC7E,OAAO,MAAMA,2BAA2B,IAAG;AAE3C;;;CAGC,GACD,MAAMC,kBAAkB;AAExB;;;CAGC,GACD,MAAMC,qBAAqB;AAM3B;;;;;;;;;;;CAWC,GACD,OAAO,SAASC,4BAA4BC,KAAc;IACxD,IAAI,CAACC,cAAcD,QAAQ;QACzB,OAAO;YAAEE,IAAI;YAAOC,OAAO;QAAgC;IAC7D;IACA,MAAMC,MAA2B,CAAC;IAClC,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACP,OAAQ;QACpC,IAAIK,QAAQ,UAAUA,QAAQ,WAAW;YACvC,OAAO;gBAAEH,IAAI;gBAAOC,OAAO,CAAC,YAAY,EAAEE,IAAI,uBAAuB,CAAC;YAAC;QACzE;IACF;IAEA,IAAIL,KAAK,CAAC,OAAO,KAAKQ,WAAW;QAC/B,MAAMC,OAAOT,KAAK,CAAC,OAAO;QAC1B,IAAI,CAACC,cAAcQ,OAAO;YACxB,OAAO;gBAAEP,IAAI;gBAAOC,OAAO;YAAqC;QAClE;QACA,MAAM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AAO;QAAE9B,OAAO;QAAMqC,OAAO,EAAE;QAAEC,QAAQ,EAAE;QAAEC,WAAW,EAAE;IAAC;IAC7E,MAAMH,YAAWN,uBAAAA,YAAY7B,OAAO,YAAnB6B,uBAAuB,CAAC;IACzC,OAAO;QACL9B,OAAOI,QAAQgC,SAASpC,KAAK;QAC7BqC,KAAK,GAAED,kBAAAA,SAASC,KAAK,YAAdD,kBAAkB,EAAE;QAC3BE,MAAM,GAAEF,mBAAAA,SAASE,MAAM,YAAfF,mBAAmB,EAAE;QAC7BG,SAAS,GAAEH,sBAAAA,SAASG,SAAS,YAAlBH,sBAAsB,EAAE;IACrC;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASI,YAAYC,KAAa,EAAEC,IAAY;IACrD,OAAOA,SAASD,SAASC,KAAKC,UAAU,CAAC,GAAGF,MAAM,CAAC,CAAC;AACtD;AAqBA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASG,sBACdd,WAA4C,EAC5CvB,KAAuB;IAEvB,MAAMsC,SAASV,kBAAkBL;IACjC,IAAIvB,MAAMuC,EAAE,KAAK,SAAS,OAAOD,OAAO7C,KAAK;IAC7C,IAAIO,MAAMuC,EAAE,KAAK,SAAS;QACxB,OAAOD,OAAOR,KAAK,CAACJ,IAAI,CAAC,CAACc,OAASxC,MAAM8B,KAAK,CAACzB,QAAQ,CAACmC;IAC1D;IACA,MAAMT,SAAS/B,MAAMyC,KAAK,KAAK,QAAQH,OAAON,SAAS,GAAGM,OAAOP,MAAM;IACvE,OAAOA,OAAOL,IAAI,CAAC,CAACQ,QAAUD,YAAYC,OAAOlC,MAAMmC,IAAI;AAC7D"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/plugin-manager/plugin-contributions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * What a plugin contributes, and where (AGL-3116).\n *\n * A plugin loads only where something uses it. Installing one loads nothing:\n * a published page fetches a plugin's code when the page places one of its\n * elements or the site runs one of its features, and a console screen\n * fetches it when the screen renders one of its slots or routes, or when the\n * plugin draws something the shell renders on every screen.\n *\n * The loaders cannot learn that by running a plugin, because running it is\n * the cost being avoided. So each plugin DECLARES its contributions:\n * first-party plugins in `plugins.config.json`, marketplace plugins in the\n * manifest they publish (`contributes`). The declaration is the whole of what\n * a loader reads, and it is data: this module is dependency-free so the\n * server, both apps, the verifier and the build tools share one reading.\n *\n * A declared surface only narrows where to look. Presence is the rule: a\n * plugin that declares a component loads on the pages that place it, not on\n * every page of the site that installed it.\n *\n * ## A plugin that declares nothing\n *\n * Every marketplace version published before this contract has no\n * `contributes`. Such a plugin keeps working under one default:\n *\n * - **On a published page it loads only where its element is placed**: a\n * node whose `pluginId` names the plugin (its manifest id or its listing\n * id). That is the one presence signal a page carries without running the\n * bundle, and it is the only way a page can show an element the plugin\n * registers. A site runtime of an undeclared plugin does not load, and the\n * publish pipeline refuses a bundle that registers one without declaring\n * it, so the only plugins this default governs are the ones already\n * published.\n * - **In the console it loads with the workspace shell**, as it always did,\n * because a nav tab or a provider is only discoverable by running\n * `register()`. Nothing on a published page depends on this.\n */\n\n/** What a plugin adds to a published site. */\nexport interface PluginSiteContributions {\n /**\n * Canvas component ids the plugin registers: the elements a page places. A\n * published page loads the plugin only when its node tree places one.\n */\n components?: string[]\n /**\n * Site features: runtimes the plugin mounts on every page of a site that\n * switched it on (an announcement bar, an experiment runner), named by the\n * `runtimeId` it registers. A plugin with a feature loads on every page of\n * such a site, which is what a feature is.\n */\n features?: string[]\n /**\n * The elements that run a site function in the visitor's browser (AGL-3393),\n * each keyed by its component id and naming the prop that holds the\n * function's name. Compose hands such a node the function's definition and\n * the site variables it reads; no other node is given either.\n *\n * Declared DATA rather than read off a registered schema: compose runs where\n * no plugin code loads — the tenant's server components — so the only thing\n * it can consult is a declaration. A first-party plugin declares it in\n * `plugins.config.json`, a marketplace plugin in its manifest, and both reach\n * compose as the same map. Every key must also be one of `components`.\n */\n functionBindings?: Record<string, string>\n}\n\n/** What a plugin adds to the console. */\nexport interface PluginConsoleContributions {\n /**\n * The widget slots its widgets fill: the `CONSOLE_WIDGET_SLOTS` zones, the\n * panels the shell draws as slots (the assistant dock `assistPanel`, the\n * besigner's `besignerInspector`), and zones another plugin hosts. A screen\n * that renders one of them loads the plugin.\n */\n slots?: string[]\n /** Site-level console routes it serves (`/forms`), beneath `/hosts/[host]`. */\n routes?: string[]\n /** Organization-level console routes it serves (`/outreach`). */\n orgRoutes?: string[]\n /**\n * The shell draws something of it on every screen of a workspace: a nav\n * tab, an organization tab, a staff tab or a provider. Such a plugin loads\n * with the shell, because every screen renders it.\n */\n shell?: boolean\n}\n\nexport interface PluginContributions {\n site?: PluginSiteContributions\n console?: PluginConsoleContributions\n}\n\n/** Bound on each declared list, so a manifest cannot hand a loader a novel. */\nexport const PLUGIN_MAX_CONTRIBUTIONS = 128\n\n/**\n * A component, feature or slot id: an identifier with the separators ids in\n * the platform use (`muiTypography`, `marketplacePlugin`, `ai.assist`).\n */\nconst CONTRIBUTION_ID = /^[A-Za-z_][A-Za-z0-9_.:-]{0,79}$/\n\n/**\n * A console route: one or more path segments, as a nav item's `href` names\n * them. Never a URL, never `..`.\n */\nconst CONTRIBUTION_ROUTE = /^(\\/[A-Za-z0-9_-]+){1,8}$/\n\n/** A prop name a function binding may name: a plain identifier. */\nconst BINDING_PROP = /^[A-Za-z_$][A-Za-z0-9_$]{0,63}$/\n\ntype Sanitized =\n | { ok: true; contributions: PluginContributions }\n | { ok: false; error: string }\n\n/**\n * Validates a declared `contributes` block.\n *\n * Malformed input is REFUSED rather than trimmed: a loader reads this to\n * decide where a plugin runs, so a declaration that silently lost an entry\n * would stop the plugin loading where it is used, and nobody would see why.\n * Duplicates are collapsed and empty lists dropped, because neither changes\n * what the declaration means.\n *\n * `{}` is valid and means \"contributes nothing anywhere\", which is a\n * different statement from an absent block (see the module note).\n */\nexport function sanitizePluginContributions(input: unknown): Sanitized {\n if (!isPlainObject(input)) {\n return { ok: false, error: 'contributes must be an object' }\n }\n const out: PluginContributions = {}\n for (const key of Object.keys(input)) {\n if (key !== 'site' && key !== 'console') {\n return { ok: false, error: `contributes.${key} is not a known surface` }\n }\n }\n\n if (input['site'] !== undefined) {\n const site = input['site']\n if (!isPlainObject(site)) {\n return { ok: false, error: 'contributes.site must be an object' }\n }\n const next: PluginSiteContributions = {}\n for (const key of Object.keys(site)) {\n if (key === 'functionBindings') continue\n if (key !== 'components' && key !== 'features') {\n return { ok: false, error: `contributes.site.${key} is not a known contribution` }\n }\n const list = idList(site[key], `contributes.site.${key}`, CONTRIBUTION_ID)\n if (list.ok === false) return { ok: false, error: list.error }\n if (list.values.length) next[key] = list.values\n }\n if (site['functionBindings'] !== undefined) {\n const bindings = functionBindingMap(\n site['functionBindings'],\n next.components ?? [],\n )\n if (bindings.ok === false) return { ok: false, error: bindings.error }\n if (Object.keys(bindings.value).length) {\n next.functionBindings = bindings.value\n }\n }\n if (Object.keys(next).length) out.site = next\n }\n\n if (input['console'] !== undefined) {\n const consoleInput = input['console']\n if (!isPlainObject(consoleInput)) {\n return { ok: false, error: 'contributes.console must be an object' }\n }\n const next: PluginConsoleContributions = {}\n for (const key of Object.keys(consoleInput)) {\n if (key === 'shell') {\n if (typeof consoleInput['shell'] !== 'boolean') {\n return { ok: false, error: 'contributes.console.shell must be true or false' }\n }\n if (consoleInput['shell']) next.shell = true\n continue\n }\n if (key !== 'slots' && key !== 'routes' && key !== 'orgRoutes') {\n return {\n ok: false,\n error: `contributes.console.${key} is not a known contribution`,\n }\n }\n const list = idList(\n consoleInput[key],\n `contributes.console.${key}`,\n key === 'slots' ? CONTRIBUTION_ID : CONTRIBUTION_ROUTE,\n )\n if (list.ok === false) return { ok: false, error: list.error }\n if (list.values.length) next[key] = list.values\n }\n if (Object.keys(next).length) out.console = next\n }\n\n return { ok: true, contributions: out }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction idList(\n value: unknown,\n where: string,\n pattern: RegExp,\n): { ok: true; values: string[] } | { ok: false; error: string } {\n if (!Array.isArray(value)) return { ok: false, error: `${where} must be a list` }\n if (value.length > PLUGIN_MAX_CONTRIBUTIONS) {\n return { ok: false, error: `${where} lists more than ${PLUGIN_MAX_CONTRIBUTIONS}` }\n }\n const values: string[] = []\n for (const entry of value) {\n if (typeof entry !== 'string' || !pattern.test(entry)) {\n return { ok: false, error: `${where} has an invalid entry \"${String(entry)}\"` }\n }\n if (!values.includes(entry)) values.push(entry)\n }\n return { ok: true, values }\n}\n\n/**\n * `contributes.site.functionBindings`, validated against the components the\n * same block declares: a binding on an element the plugin does not register\n * would hand a function's definition, and the variable values it reads, to\n * whichever element happens to own that id.\n */\nfunction functionBindingMap(\n value: unknown,\n components: readonly string[],\n): { ok: true; value: Record<string, string> } | { ok: false; error: string } {\n const where = 'contributes.site.functionBindings'\n if (!isPlainObject(value)) {\n return { ok: false, error: `${where} must be an object` }\n }\n const entries = Object.entries(value)\n if (entries.length > PLUGIN_MAX_CONTRIBUTIONS) {\n return { ok: false, error: `${where} lists more than ${PLUGIN_MAX_CONTRIBUTIONS}` }\n }\n const out: Record<string, string> = {}\n for (const [componentId, prop] of entries) {\n if (!components.includes(componentId)) {\n return {\n ok: false,\n error: `${where} names \"${componentId}\", which contributes.site.components does not declare`,\n }\n }\n if (typeof prop !== 'string' || !BINDING_PROP.test(prop)) {\n return {\n ok: false,\n error: `${where}.${componentId} must name a prop, not \"${String(prop)}\"`,\n }\n }\n out[componentId] = prop\n }\n return { ok: true, value: out }\n}\n\n/**\n * A declared `contributes` block as a loader may trust it: the sanitized\n * block, or `undefined` for one that is absent or does not validate.\n *\n * Loaders read this from stored documents (a pinned version's manifest), and\n * a malformed stored block is treated as UNDECLARED — the default applies —\n * never as \"contributes nothing\", which would stop a plugin that is in use.\n */\nexport function readPluginContributions(\n input: unknown,\n): PluginContributions | undefined {\n if (input === undefined || input === null) return undefined\n const verdict = sanitizePluginContributions(input)\n return verdict.ok ? verdict.contributions : undefined\n}\n\n/**\n * What the surface a plugin is being registered into actually uses\n * (AGL-3141).\n *\n * The loaders carry this from the surface that computed it to each plugin's\n * register function, unchanged. A plugin that can register a part of itself\n * reads it; one that cannot ignores it, and the platform's behavior is the\n * same either way.\n *\n * An absent field means \"everything of that kind\". A surface that cannot say\n * what it uses must be handed all of it, because an element the surface\n * places and the set omits has no registered component and renders NOTHING,\n * silently (the blank-canvas invariant, AGL-52). Narrowing is an optimization\n * and must fail toward the whole.\n */\nexport interface PluginUse {\n /**\n * Canvas component ids the surface places, read from the FULL composed\n * document the way `pagePresence` reads it — withheld lazy-panel subtrees\n * included, because an element inside a panel the visitor opens later is\n * still this page's element.\n */\n componentIds?: readonly string[]\n}\n\n/** A node as presence reads it: the two ids a placed element carries. */\nexport interface PresenceNode {\n componentId?: string\n pluginId?: string\n}\n\n/** What a published page places: its component ids and the plugin ids stamped on its nodes. */\nexport interface PagePresence {\n componentIds: ReadonlySet<string>\n pluginIds: ReadonlySet<string>\n}\n\n/**\n * The component ids and plugin ids a node tree places.\n *\n * Read from the FULL composed document — layouts, grafted reusable\n * components and withheld lazy panels included — because an element inside\n * a panel the visitor opens later is still this page's element.\n */\nexport function pagePresence(\n nodes: Record<string, PresenceNode | null | undefined> | null | undefined,\n): PagePresence {\n const componentIds = new Set<string>()\n const pluginIds = new Set<string>()\n for (const node of Object.values(nodes ?? {})) {\n if (typeof node?.componentId === 'string' && node.componentId) {\n componentIds.add(node.componentId)\n }\n if (typeof node?.pluginId === 'string' && node.pluginId) {\n pluginIds.add(node.pluginId)\n }\n }\n return { componentIds, pluginIds }\n}\n\n/** A plugin as the presence rules see it. */\nexport interface PresenceSubject {\n /** The plugin's own id (a manifest `id`, or a first-party catalog id). */\n pluginId?: string\n /** A marketplace plugin's listing id, which its elements may carry instead. */\n listingId?: string\n /** Its declaration; `undefined` when it declares nothing. */\n contributes?: PluginContributions\n}\n\n/**\n * Whether a published page uses a plugin, so the page must load it.\n *\n * - An element of it is placed: a node stamped with the plugin's id, or,\n * for a declared plugin, a node whose component id it declares.\n * - It declares a site feature. The caller only asks about plugins the site\n * has switched on, and a feature runs on every page of such a site.\n *\n * A plugin that declares nothing is present only through its stamped\n * elements — the default in the module note.\n */\nexport function isPluginUsedOnPage(\n subject: PresenceSubject,\n page: PagePresence,\n): boolean {\n if (subject.pluginId && page.pluginIds.has(subject.pluginId)) return true\n if (subject.listingId && page.pluginIds.has(subject.listingId)) return true\n const site = subject.contributes?.site\n if (!site) return false\n if (site.features?.length) return true\n return (site.components ?? []).some((id) => page.componentIds.has(id))\n}\n\n/**\n * Function bindings (AGL-3393): component id → the prop naming the site\n * function that element runs.\n */\nexport type FunctionBindings = Readonly<Record<string, string>>\n\n/**\n * The function bindings a set of plugins declares, merged into one map.\n *\n * Where two plugins bind the same component id the FIRST one listed wins, so a\n * caller that passes first-party declarations ahead of marketplace ones keeps\n * a marketplace manifest from rebinding a first-party element. Marketplace ids\n * are namespaced by their publisher (see {@link isNamespacedComponentId}), so\n * a collision is a mistake, never a feature.\n */\nexport function mergeFunctionBindings(\n ...sources: ReadonlyArray<\n FunctionBindings | { contributes?: PluginContributions } | null | undefined\n >\n): FunctionBindings {\n const merged: Record<string, string> = {}\n for (const source of sources) {\n if (!source) continue\n const declared: FunctionBindings | undefined =\n 'contributes' in source\n ? (source.contributes as PluginContributions | undefined)?.site\n ?.functionBindings\n : (source as FunctionBindings)\n for (const [componentId, prop] of Object.entries(declared ?? {})) {\n if (typeof prop !== 'string') continue\n if (!Object.prototype.hasOwnProperty.call(merged, componentId)) {\n merged[componentId] = prop\n }\n }\n }\n return merged\n}\n\n/**\n * Whether a component id belongs to a marketplace plugin's namespace\n * (AGL-3387): `<publisher handle>.<plugin id>.<role>`. A `.` is reserved for\n * those ids — no first-party component carries one, which the manifest\n * generator enforces — so compose can tell, without loading anything, that a\n * tree places an element only an installed plugin can declare.\n */\nexport function isNamespacedComponentId(componentId: unknown): boolean {\n return typeof componentId === 'string' && componentId.includes('.')\n}\n\n/**\n * Where a plugin's console code loads, resolved with the default applied: a\n * plugin that declares nothing loads with the shell, as it always did.\n */\nexport interface ConsoleLoadPoints {\n shell: boolean\n slots: readonly string[]\n routes: readonly string[]\n orgRoutes: readonly string[]\n}\n\nexport function consoleLoadPoints(\n contributes: PluginContributions | undefined,\n): ConsoleLoadPoints {\n if (!contributes) return { shell: true, slots: [], routes: [], orgRoutes: [] }\n const declared = contributes.console ?? {}\n return {\n shell: Boolean(declared.shell),\n slots: declared.slots ?? [],\n routes: declared.routes ?? [],\n orgRoutes: declared.orgRoutes ?? [],\n }\n}\n\n/**\n * Whether a declared route serves `href`: the route itself, or a path beneath\n * it on a segment boundary, the way the shell's page resolver matches a nav\n * item that owns its subtree. `/products` serves `/products/orders` and never\n * `/products-archive`.\n */\nexport function routeServes(route: string, href: string): boolean {\n return href === route || href.startsWith(`${route}/`)\n}\n\n/**\n * A place in the console that loads plugins, as the surface drawing it names\n * itself (AGL-3142).\n *\n * - `shell`: the workspace chrome every screen has. It draws whatever a\n * plugin adds to every screen — a nav tab, an organization tab, a staff\n * tab, a provider — so a plugin that declares any of those loads here, and\n * so does one that declares nothing at all.\n * - `slots`: the zones a screen renders. The zones it names, not the plugins\n * it expects in them: a screen must never hold a plugin id.\n * - `route`: the path the reader has open, plugin-relative (`/products`,\n * `/products/orders`), on the level its route tree serves — `site` beneath\n * `/hosts/[host]`, `org` beneath the organization.\n */\nexport type ConsoleLoadWhere =\n | { at: 'shell' }\n | { at: 'slots'; slots: readonly string[] }\n | { at: 'route'; href: string; level: 'site' | 'org' }\n\n/**\n * Whether a console surface uses a plugin, so it must load it.\n *\n * The console twin of {@link isPluginUsedOnPage}, and the same rule: a\n * declaration says where a plugin's code belongs, and the surface that draws\n * that place is the one that fetches it. A screen asks about the zones it\n * renders and the path it serves; it never asks about a plugin by name.\n *\n * A plugin that declares nothing loads with the shell — the default in the\n * module note, and the reason the shell branch reads\n * {@link consoleLoadPoints} rather than the raw block. Its nav tab or its\n * provider is only discoverable by running `register()`, so narrowing it\n * anywhere else would take a tab away with no way to notice.\n */\nexport function isPluginUsedInConsole(\n contributes: PluginContributions | undefined,\n where: ConsoleLoadWhere,\n): boolean {\n const points = consoleLoadPoints(contributes)\n if (where.at === 'shell') return points.shell\n if (where.at === 'slots') {\n return points.slots.some((slot) => where.slots.includes(slot))\n }\n const routes = where.level === 'org' ? points.orgRoutes : points.routes\n return routes.some((route) => routeServes(route, where.href))\n}\n"],"names":["PLUGIN_MAX_CONTRIBUTIONS","CONTRIBUTION_ID","CONTRIBUTION_ROUTE","BINDING_PROP","sanitizePluginContributions","input","isPlainObject","ok","error","out","key","Object","keys","undefined","site","next","list","idList","values","length","bindings","functionBindingMap","components","value","functionBindings","consoleInput","shell","console","contributions","Boolean","Array","isArray","where","pattern","entry","test","String","includes","push","entries","componentId","prop","readPluginContributions","verdict","pagePresence","nodes","componentIds","Set","pluginIds","node","add","pluginId","isPluginUsedOnPage","subject","page","has","listingId","contributes","features","some","id","mergeFunctionBindings","sources","merged","source","declared","prototype","hasOwnProperty","call","isNamespacedComponentId","consoleLoadPoints","slots","routes","orgRoutes","routeServes","route","href","startsWith","isPluginUsedInConsole","points","at","slot","level"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCC,GAED,4CAA4C,GAuD5C,6EAA6E,GAC7E,OAAO,MAAMA,2BAA2B,IAAG;AAE3C;;;CAGC,GACD,MAAMC,kBAAkB;AAExB;;;CAGC,GACD,MAAMC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