@aglyn/plugins-logic 1.0.0-beta.229 → 1.0.0-beta.231
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/lib/components/host-functions-card.component.js +69 -11
- package/src/lib/components/host-functions-card.component.js.map +1 -1
- package/src/lib/components/host-reference-health-card.component.d.ts +2 -0
- package/src/lib/components/host-reference-health-card.component.js +11 -2
- package/src/lib/components/host-reference-health-card.component.js.map +1 -1
- package/src/lib/components/host-variables-card.component.js +36 -0
- package/src/lib/components/host-variables-card.component.js.map +1 -1
- package/src/lib/components/logic-console-page.js +2 -1
- package/src/lib/components/logic-console-page.js.map +1 -1
- package/src/lib/components/logic-zones.d.ts +75 -0
- package/src/lib/components/logic-zones.js +21 -0
- package/src/lib/components/logic-zones.js.map +1 -0
- package/src/lib/plugin.d.ts +1 -0
- package/src/lib/plugin.js +32 -0
- package/src/lib/plugin.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/host-reference-health-card.component.tsx"],"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'use client'\n\nimport { pluginDocsHelp, scopeTokensForHost } from '@aglyn/aglyn'\nimport { pluginContainerKind } from '@aglyn/aglyn/plugin-manager/plugin-containers'\nimport { auditHostReferences } from '../model'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { Alert, Chip, Stack, Typography } from '@mui/material'\nimport { collection, query, where } from 'firebase/firestore'\nimport { useMemo } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useOrgDataScope,\n} from '@aglyn/tenant-feature-instance'\n/*\n * The MODULE, not the barrel, for the two PURE helpers — the specs that render\n * this card mock `@aglyn/tenant-feature-instance` wholesale to stage their\n * Firestore hooks, and a query builder imported through that barrel disappears\n * under the mock. Neither of these is a hook.\n */\nimport {\n ceilingedWindow,\n collectionCeiling,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport {\n pluginRecordListQuery,\n pluginRecordsFromRows,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\n\nexport interface HostReferenceHealthCardProps {\n hostId: string\n}\n\n/**\n * How much of each collection the audit judges against.\n *\n * Thirteen collections at this ceiling is what an open of this page costs, so\n * the number is a bill as much as a bound. It is stated once because every one\n * of those windows has to agree: the audit compares references drawn from\n * three of them against names drawn from the other ten, and a wider window on\n * one side than the other would report the difference as broken wiring.\n */\nconst REFERENCE_CEILING = 100\n\n/**\n * Reference health (wave v7): id references are rename-safe (AGL-261)\n * but not delete-safe — this card cross-checks every automation,\n * workflow, and computed-variable reference against what still exists\n * and lists the dangling ones, so broken wiring surfaces here instead\n * of failing silently on a visitor's pageview.\n */\nexport function HostReferenceHealthCard(props: HostReferenceHealthCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n // The org lookup is async (AGL-1061). `dataScope` is null until it\n // settles — and stays null for a host with no owning org — so the two\n // org-data queries below simply are not issued rather than falling back\n // to a host path (AGL-1050).\n const { scope: dataScope } = useOrgDataScope({ hostId })\n\n /*\n * ORDERED AND CEILINGED (AGL-2501), the same decision the actions and\n * workflows cards reached.\n *\n * `limit(100)` alone is answered in DOCUMENT-ID order, so an unnamed window\n * is a pseudo-random hundred — and on THIS card that is worse than a\n * mis-drawn list. The audit asks whether a reference resolves and answers\n * from the windows, so a workflow that exists but falls outside the\n * `workflows` hundred is indistinguishable from one that was deleted, and\n * the card reports live wiring as broken. `collectionCeiling` does not\n * change WHICH hundred — document-id order is what a bare cap returns\n * anyway. What it changes is that the order is NAMED, which is what makes\n * the probe row meaningful and catches the obvious next edit: ordering on\n * `name` would HIDE every row written without one rather than mis-sort\n * anything.\n */\n const useHostCollection = (name: string) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const { data } = useFirestoreCollection<any>(\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, name),\n REFERENCE_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n // Memoised so the window keeps one identity while the rows do. The audit\n // below is eleven set builds and a sweep of three collections; a fresh\n // `slice` every render would re-run all of it every render.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMemo(() => ceilingedWindow<any>(data, REFERENCE_CEILING), [data])\n }\n const actionDocs = useHostCollection('actions')\n const workflowDocs = useHostCollection('workflows')\n const variableDocs = useHostCollection('variables')\n const functionDocs = useHostCollection('functions')\n const overlayDocs = useHostCollection('overlays')\n const webhookDocs = useHostCollection('webhooks')\n // New reference kinds (AGL-345): screen links, commerce entities.\n const screenDocs = useHostCollection('screens')\n const productDocs = useHostCollection('products')\n const collectionDocs = useHostCollection('collections')\n const categoryDocs = useHostCollection('productCategories')\n // Scoped (AGL-1044) — see the note in host-actions-card: an unfiltered\n // list is rejected, not filtered.\n // Scoped to the HOST, not the viewer (AGL-1044): the audit speaks for this host, so it must judge against what THIS host can reach — an org-wide\n // admin would otherwise be offered org records that resolve to nothing at\n // render time. Filtering by the host's tokens also satisfies the\n // AGL-1041 rules, since they are a subset of any viewer's who can reach\n // this host at all.\n // Memoised: this is a listener DEPENDENCY, and a fresh array each\n // render tears the subscription down and clears its data every time.\n const scopeTokens = useMemo(() => scopeTokensForHost(hostId), [hostId])\n /*\n * The datasets are the data plugin's, listed through the source it\n * publishes (AGL-3080): the ones shared with THIS site, which is the set a\n * step on this site can reach. Shaped as the other windows are, so the\n * audit reads every known set the same way.\n */\n const datasetOrgId = dataScope?.[1] ?? null\n const { data: datasetRead } = useFirestoreCollection<any>(\n () =>\n datasetOrgId\n ? pluginRecordListQuery('dataset', firestore, {\n orgId: datasetOrgId,\n hostId,\n limit: REFERENCE_CEILING + 1,\n })\n : null,\n [firestore, datasetOrgId, hostId],\n { idField: '$id' },\n )\n const datasetDocs = useMemo(() => {\n const { rows, truncated } = ceilingedWindow<any>(datasetRead, REFERENCE_CEILING)\n return {\n rows: pluginRecordsFromRows('dataset', rows).map((dataset) => ({\n $id: dataset.id,\n name: dataset.name,\n })),\n truncated,\n }\n }, [datasetRead])\n /*\n * The campaign containers an \"Assign to a campaign\" step runs against\n * (AGL-3052): the `campaign` container kind, read where its declaration\n * says they are stored, and nothing where no plugin keeps the kind. They\n * are the org's, and the audit judges against the ones placed on THIS\n * site, by the same host tokens as the datasets above.\n */\n const campaignCollection = pluginContainerKind('campaign')?.orgCollection\n const { data: campaignRead } = useFirestoreCollection<any>(\n () =>\n dataScope && campaignCollection\n ? collectionCeiling(\n query(\n collection(firestore, dataScope[0], dataScope[1], campaignCollection),\n where('visibleTo', 'array-contains-any', scopeTokens),\n ),\n REFERENCE_CEILING,\n )\n : null,\n [firestore, dataScope, scopeTokens, campaignCollection],\n { idField: '$id' },\n )\n const campaignDocs = useMemo(\n () => ceilingedWindow<any>(campaignRead, REFERENCE_CEILING),\n [campaignRead],\n )\n const { data: listRead } = useFirestoreCollection<any>(\n () =>\n dataScope\n ? collectionCeiling(\n collection(firestore, dataScope[0], dataScope[1], 'lists'),\n REFERENCE_CEILING,\n )\n : null,\n [firestore, dataScope],\n { idField: '$id' },\n )\n const listDocs = useMemo(\n () => ceilingedWindow<any>(listRead, REFERENCE_CEILING),\n [listRead],\n )\n\n /**\n * At least one collection holds more than the audit read.\n *\n * The verdict this card renders is computed entirely from the windows, so a\n * ceiling that bit anywhere makes both halves of it unsafe: a reference into\n * the unread part of a `known` collection is reported broken, and a\n * reference held by an unread action, workflow or variable is not checked at\n * all. Neither shows up as a gap in the list, which is why it has to be said\n * outright.\n */\n const truncated = [\n actionDocs,\n workflowDocs,\n variableDocs,\n functionDocs,\n campaignDocs,\n overlayDocs,\n webhookDocs,\n screenDocs,\n productDocs,\n collectionDocs,\n categoryDocs,\n datasetDocs,\n listDocs,\n ].some((window) => window.truncated)\n\n const issues = useMemo(() => {\n const alive = (docs: any[] | undefined) =>\n (docs ?? []).filter((doc: any) => !doc.deletedAt)\n const knownSet = (docs: any[] | undefined, nameKey = 'name') => {\n const set = new Set<string>()\n for (const doc of alive(docs)) {\n set.add(doc.$id)\n const name = doc[nameKey]\n if (typeof name === 'string' && name.trim()) set.add(name.trim())\n }\n return set\n }\n return auditHostReferences({\n actions: alive(actionDocs.rows),\n workflows: alive(workflowDocs.rows),\n variables: alive(variableDocs.rows),\n known: {\n workflows: knownSet(workflowDocs.rows),\n functions: knownSet(functionDocs.rows),\n datasets: knownSet(datasetDocs.rows),\n lists: knownSet(listDocs.rows),\n campaigns: knownSet(campaignDocs.rows),\n overlays: knownSet(overlayDocs.rows),\n webhooks: knownSet(webhookDocs.rows),\n screens: knownSet(screenDocs.rows, 'displayName'),\n products: knownSet(productDocs.rows),\n collections: knownSet(collectionDocs.rows),\n categories: knownSet(categoryDocs.rows),\n },\n })\n }, [\n actionDocs,\n workflowDocs,\n variableDocs,\n functionDocs,\n datasetDocs,\n listDocs,\n campaignDocs,\n overlayDocs,\n webhookDocs,\n screenDocs,\n productDocs,\n collectionDocs,\n categoryDocs,\n ])\n\n return (\n <CardDisplay\n header={'Reference health'}\n help={pluginDocsHelp('bindings', { anchor: '#where-used--safety' })}\n contentGutterX\n contentGutterY\n contentBordered=\"all\"\n >\n <Stack spacing={1}>\n {truncated ? (\n <Alert severity=\"info\">\n {`Audited against the first ${REFERENCE_CEILING} rows of each ` +\n 'collection, ordered by id. At least one of them holds more, ' +\n 'so a step pointing past that window is listed here as broken ' +\n 'when it is not, and a step held past it is not checked at all.'}\n </Alert>\n ) : null}\n {issues.length === 0 ? (\n <Alert severity=\"success\">\n {truncated\n ? 'Every reference the audit read resolves.'\n : 'Every automation, workflow, and variable reference resolves.'}\n </Alert>\n ) : (\n <Stack spacing={1}>\n <Alert severity=\"warning\">\n {`${issues.length} broken reference${\n issues.length === 1 ? '' : 's'\n } — these steps do nothing until re-pointed or removed.`}\n </Alert>\n {issues.map((issue, index) => (\n <Stack\n key={`${issue.sourceId}:${index}`}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n <Chip size=\"small\" label={issue.source} />\n <Typography variant=\"body2\" noWrap sx={{ maxWidth: '40%' }}>\n {issue.sourceName}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`→ missing ${issue.refType} `}\n </Typography>\n <Typography\n variant=\"caption\"\n color=\"error\"\n sx={{ fontFamily: 'monospace' }}\n >\n {issue.missing || '(empty)'}\n </Typography>\n </Stack>\n ))}\n </Stack>\n )}\n </Stack>\n </CardDisplay>\n )\n}\nHostReferenceHealthCard.displayName = 'HostReferenceHealthCard'\n\nexport default HostReferenceHealthCard\n"],"names":["pluginDocsHelp","scopeTokensForHost","pluginContainerKind","auditHostReferences","CardDisplay","Alert","Chip","Stack","Typography","collection","query","where","useMemo","useFirestore","useFirestoreCollection","useOrgDataScope","ceilingedWindow","collectionCeiling","pluginRecordListQuery","pluginRecordsFromRows","REFERENCE_CEILING","HostReferenceHealthCard","props","hostId","firestore","scope","dataScope","useHostCollection","name","data","idField","actionDocs","workflowDocs","variableDocs","functionDocs","overlayDocs","webhookDocs","screenDocs","productDocs","collectionDocs","categoryDocs","scopeTokens","datasetOrgId","datasetRead","orgId","limit","datasetDocs","rows","truncated","map","dataset","$id","id","campaignCollection","orgCollection","campaignRead","campaignDocs","listRead","listDocs","some","window","issues","alive","docs","filter","doc","deletedAt","knownSet","nameKey","set","Set","add","trim","actions","workflows","variables","known","functions","datasets","lists","campaigns","overlays","webhooks","screens","products","collections","categories","header","help","anchor","contentGutterX","contentGutterY","contentBordered","spacing","severity","length","issue","index","direction","sx","alignItems","size","label","source","variant","noWrap","maxWidth","sourceName","color","refType","fontFamily","missing","sour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AE3B,KAAC9F;wCAAK+F,MAAK;wCAAQC,OAAON,MAAMO,MAAM;;kDACtC,KAAC/F;wCAAWgG,SAAQ;wCAAQC,MAAM;wCAACN,IAAI;4CAAEO,UAAU;wCAAM;kDACtDV,MAAMW,UAAU;;kDAEnB,KAACnG;wCAAWgG,SAAQ;wCAAUI,OAAM;kDACjC,CAAC,UAAU,EAAEZ,MAAMa,OAAO,CAAC,CAAC,CAAC;;kDAEhC,KAACrG;wCACCgG,SAAQ;wCACRI,OAAM;wCACNT,IAAI;4CAAEW,YAAY;wCAAY;kDAE7Bd,MAAMe,OAAO,IAAI;;;+BAjBf,GAAGf,MAAMgB,QAAQ,CAAC,CAAC,EAAEf,OAAO;;;;;;AA0BjD;AACA5E,wBAAwB4F,WAAW,GAAG;AAEtC,eAAe5F,wBAAuB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/host-reference-health-card.component.tsx"],"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'use client'\n\nimport { pluginDocsHelp, scopeTokensForHost } from '@aglyn/aglyn'\nimport { pluginContainerKind } from '@aglyn/aglyn/plugin-manager/plugin-containers'\nimport { auditHostReferences } from '../model'\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { useConsoleWidgetSlot } from '@aglyn/aglyn/app-utils/console-widget-slot-context'\nimport { LOGIC_REFERENCE_ISSUE_ZONE } from './logic-zones'\nimport { Alert, Chip, Stack, Typography } from '@mui/material'\nimport { collection, query, where } from 'firebase/firestore'\nimport { useMemo } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useOrgDataScope,\n} from '@aglyn/tenant-feature-instance'\n/*\n * The MODULE, not the barrel, for the two PURE helpers — the specs that render\n * this card mock `@aglyn/tenant-feature-instance` wholesale to stage their\n * Firestore hooks, and a query builder imported through that barrel disappears\n * under the mock. Neither of these is a hook.\n */\nimport {\n ceilingedWindow,\n collectionCeiling,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport {\n pluginRecordListQuery,\n pluginRecordsFromRows,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\n\nexport interface HostReferenceHealthCardProps {\n hostId: string\n /** The org the page names (AGL-3603), handed to the zone on each issue. */\n orgId?: string\n}\n\n/**\n * How much of each collection the audit judges against.\n *\n * Thirteen collections at this ceiling is what an open of this page costs, so\n * the number is a bill as much as a bound. It is stated once because every one\n * of those windows has to agree: the audit compares references drawn from\n * three of them against names drawn from the other ten, and a wider window on\n * one side than the other would report the difference as broken wiring.\n */\nconst REFERENCE_CEILING = 100\n\n/**\n * Reference health (wave v7): id references are rename-safe (AGL-261)\n * but not delete-safe — this card cross-checks every automation,\n * workflow, and computed-variable reference against what still exists\n * and lists the dangling ones, so broken wiring surfaces here instead\n * of failing silently on a visitor's pageview.\n */\nexport function HostReferenceHealthCard(props: HostReferenceHealthCardProps) {\n const { hostId, orgId } = props\n const firestore = useFirestore()\n /** The shell's zone renderer (AGL-3603); `null` outside the console shell. */\n const ExtensionZone = useConsoleWidgetSlot()\n // The org lookup is async (AGL-1061). `dataScope` is null until it\n // settles — and stays null for a host with no owning org — so the two\n // org-data queries below simply are not issued rather than falling back\n // to a host path (AGL-1050).\n const { scope: dataScope } = useOrgDataScope({ hostId })\n\n /*\n * ORDERED AND CEILINGED (AGL-2501), the same decision the actions and\n * workflows cards reached.\n *\n * `limit(100)` alone is answered in DOCUMENT-ID order, so an unnamed window\n * is a pseudo-random hundred — and on THIS card that is worse than a\n * mis-drawn list. The audit asks whether a reference resolves and answers\n * from the windows, so a workflow that exists but falls outside the\n * `workflows` hundred is indistinguishable from one that was deleted, and\n * the card reports live wiring as broken. `collectionCeiling` does not\n * change WHICH hundred — document-id order is what a bare cap returns\n * anyway. What it changes is that the order is NAMED, which is what makes\n * the probe row meaningful and catches the obvious next edit: ordering on\n * `name` would HIDE every row written without one rather than mis-sort\n * anything.\n */\n const useHostCollection = (name: string) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const { data } = useFirestoreCollection<any>(\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, name),\n REFERENCE_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n // Memoised so the window keeps one identity while the rows do. The audit\n // below is eleven set builds and a sweep of three collections; a fresh\n // `slice` every render would re-run all of it every render.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useMemo(() => ceilingedWindow<any>(data, REFERENCE_CEILING), [data])\n }\n const actionDocs = useHostCollection('actions')\n const workflowDocs = useHostCollection('workflows')\n const variableDocs = useHostCollection('variables')\n const functionDocs = useHostCollection('functions')\n const overlayDocs = useHostCollection('overlays')\n const webhookDocs = useHostCollection('webhooks')\n // New reference kinds (AGL-345): screen links, commerce entities.\n const screenDocs = useHostCollection('screens')\n const productDocs = useHostCollection('products')\n const collectionDocs = useHostCollection('collections')\n const categoryDocs = useHostCollection('productCategories')\n // Scoped (AGL-1044) — see the note in host-actions-card: an unfiltered\n // list is rejected, not filtered.\n // Scoped to the HOST, not the viewer (AGL-1044): the audit speaks for this host, so it must judge against what THIS host can reach — an org-wide\n // admin would otherwise be offered org records that resolve to nothing at\n // render time. Filtering by the host's tokens also satisfies the\n // AGL-1041 rules, since they are a subset of any viewer's who can reach\n // this host at all.\n // Memoised: this is a listener DEPENDENCY, and a fresh array each\n // render tears the subscription down and clears its data every time.\n const scopeTokens = useMemo(() => scopeTokensForHost(hostId), [hostId])\n /*\n * The datasets are the data plugin's, listed through the source it\n * publishes (AGL-3080): the ones shared with THIS site, which is the set a\n * step on this site can reach. Shaped as the other windows are, so the\n * audit reads every known set the same way.\n */\n const datasetOrgId = dataScope?.[1] ?? null\n const { data: datasetRead } = useFirestoreCollection<any>(\n () =>\n datasetOrgId\n ? pluginRecordListQuery('dataset', firestore, {\n orgId: datasetOrgId,\n hostId,\n limit: REFERENCE_CEILING + 1,\n })\n : null,\n [firestore, datasetOrgId, hostId],\n { idField: '$id' },\n )\n const datasetDocs = useMemo(() => {\n const { rows, truncated } = ceilingedWindow<any>(datasetRead, REFERENCE_CEILING)\n return {\n rows: pluginRecordsFromRows('dataset', rows).map((dataset) => ({\n $id: dataset.id,\n name: dataset.name,\n })),\n truncated,\n }\n }, [datasetRead])\n /*\n * The campaign containers an \"Assign to a campaign\" step runs against\n * (AGL-3052): the `campaign` container kind, read where its declaration\n * says they are stored, and nothing where no plugin keeps the kind. They\n * are the org's, and the audit judges against the ones placed on THIS\n * site, by the same host tokens as the datasets above.\n */\n const campaignCollection = pluginContainerKind('campaign')?.orgCollection\n const { data: campaignRead } = useFirestoreCollection<any>(\n () =>\n dataScope && campaignCollection\n ? collectionCeiling(\n query(\n collection(firestore, dataScope[0], dataScope[1], campaignCollection),\n where('visibleTo', 'array-contains-any', scopeTokens),\n ),\n REFERENCE_CEILING,\n )\n : null,\n [firestore, dataScope, scopeTokens, campaignCollection],\n { idField: '$id' },\n )\n const campaignDocs = useMemo(\n () => ceilingedWindow<any>(campaignRead, REFERENCE_CEILING),\n [campaignRead],\n )\n const { data: listRead } = useFirestoreCollection<any>(\n () =>\n dataScope\n ? collectionCeiling(\n collection(firestore, dataScope[0], dataScope[1], 'lists'),\n REFERENCE_CEILING,\n )\n : null,\n [firestore, dataScope],\n { idField: '$id' },\n )\n const listDocs = useMemo(\n () => ceilingedWindow<any>(listRead, REFERENCE_CEILING),\n [listRead],\n )\n\n /**\n * At least one collection holds more than the audit read.\n *\n * The verdict this card renders is computed entirely from the windows, so a\n * ceiling that bit anywhere makes both halves of it unsafe: a reference into\n * the unread part of a `known` collection is reported broken, and a\n * reference held by an unread action, workflow or variable is not checked at\n * all. Neither shows up as a gap in the list, which is why it has to be said\n * outright.\n */\n const truncated = [\n actionDocs,\n workflowDocs,\n variableDocs,\n functionDocs,\n campaignDocs,\n overlayDocs,\n webhookDocs,\n screenDocs,\n productDocs,\n collectionDocs,\n categoryDocs,\n datasetDocs,\n listDocs,\n ].some((window) => window.truncated)\n\n const issues = useMemo(() => {\n const alive = (docs: any[] | undefined) =>\n (docs ?? []).filter((doc: any) => !doc.deletedAt)\n const knownSet = (docs: any[] | undefined, nameKey = 'name') => {\n const set = new Set<string>()\n for (const doc of alive(docs)) {\n set.add(doc.$id)\n const name = doc[nameKey]\n if (typeof name === 'string' && name.trim()) set.add(name.trim())\n }\n return set\n }\n return auditHostReferences({\n actions: alive(actionDocs.rows),\n workflows: alive(workflowDocs.rows),\n variables: alive(variableDocs.rows),\n known: {\n workflows: knownSet(workflowDocs.rows),\n functions: knownSet(functionDocs.rows),\n datasets: knownSet(datasetDocs.rows),\n lists: knownSet(listDocs.rows),\n campaigns: knownSet(campaignDocs.rows),\n overlays: knownSet(overlayDocs.rows),\n webhooks: knownSet(webhookDocs.rows),\n screens: knownSet(screenDocs.rows, 'displayName'),\n products: knownSet(productDocs.rows),\n collections: knownSet(collectionDocs.rows),\n categories: knownSet(categoryDocs.rows),\n },\n })\n }, [\n actionDocs,\n workflowDocs,\n variableDocs,\n functionDocs,\n datasetDocs,\n listDocs,\n campaignDocs,\n overlayDocs,\n webhookDocs,\n screenDocs,\n productDocs,\n collectionDocs,\n categoryDocs,\n ])\n\n return (\n <CardDisplay\n header={'Reference health'}\n help={pluginDocsHelp('bindings', { anchor: '#where-used--safety' })}\n contentGutterX\n contentGutterY\n contentBordered=\"all\"\n >\n <Stack spacing={1}>\n {truncated ? (\n <Alert severity=\"info\">\n {`Audited against the first ${REFERENCE_CEILING} rows of each ` +\n 'collection, ordered by id. At least one of them holds more, ' +\n 'so a step pointing past that window is listed here as broken ' +\n 'when it is not, and a step held past it is not checked at all.'}\n </Alert>\n ) : null}\n {issues.length === 0 ? (\n <Alert severity=\"success\">\n {truncated\n ? 'Every reference the audit read resolves.'\n : 'Every automation, workflow, and variable reference resolves.'}\n </Alert>\n ) : (\n <Stack spacing={1}>\n <Alert severity=\"warning\">\n {`${issues.length} broken reference${\n issues.length === 1 ? '' : 's'\n } — these steps do nothing until re-pointed or removed.`}\n </Alert>\n {issues.map((issue, index) => (\n <Stack\n key={`${issue.sourceId}:${index}`}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n <Chip size=\"small\" label={issue.source} />\n <Typography variant=\"body2\" noWrap sx={{ maxWidth: '40%' }}>\n {issue.sourceName}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`→ missing ${issue.refType} `}\n </Typography>\n <Typography\n variant=\"caption\"\n color=\"error\"\n sx={{ fontFamily: 'monospace' }}\n >\n {issue.missing || '(empty)'}\n </Typography>\n {/* What other plugins offer for one broken reference (AGL-3603). */}\n {ExtensionZone ? (\n <ExtensionZone\n slot={LOGIC_REFERENCE_ISSUE_ZONE.id}\n hostId={hostId}\n orgId={orgId}\n issue={issue}\n />\n ) : null}\n </Stack>\n ))}\n </Stack>\n )}\n </Stack>\n </CardDisplay>\n )\n}\nHostReferenceHealthCard.displayName = 'HostReferenceHealthCard'\n\nexport default HostReferenceHealthCard\n"],"names":["pluginDocsHelp","scopeTokensForHost","pluginContainerKind","auditHostReferences","CardDisplay","useConsoleWidgetSlot","LOGIC_REFERENCE_ISSUE_ZONE","Alert","Chip","Stack","Typography","collection","query","where","useMemo","useFirestore","useFirestoreCollection","useOrgDataScope","ceilingedWindow","collectionCeiling","pluginRecordListQuery","pluginRecordsFromRows","REFERENCE_CEILING","HostReferenceHealthCard","props","hostId","orgId","firestore","ExtensionZone","scope","dataScope","useHostCollection","name","data","idField","actionDocs","workflowDocs","variableDocs","functionDocs","overlayDocs","webhookDocs","screenDocs","productDocs","collectionDocs","categoryDocs","scopeTokens","datasetOrgId","datasetRead","limit","datasetDocs","rows","truncated","map","dataset","$id","id","campaignCollection","orgCollection","campaignRead","campaignDocs","listRead","listDocs","some","window","issues","alive","docs","filter","doc","deletedAt","knownSet","nameKey","set","Set","add","trim","actions","workflows","variables","known","functions","datasets","lists","campaigns","overlays","webhooks","screens","products","collections","categories","header","help","anchor","contentGutterX","contentGutterY","contentBordered","spacing","severity","length","issue","index","direction","sx","alignItems","size","label","source","variant","noWrap","maxWidth","sourceName","color","refType","fontFamily","missing","slot","sourceId","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SAASA,cAAc,EAAEC,kBAAkB,QAAQ,eAAc;AACjE,SAASC,mBAAmB,QAAQ,gDAA+C;AACnF,SAASC,mBAAmB,QAAQ,oBAAU;AAC9C,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,oBAAoB,QAAQ,qDAAoD;AACzF,SAASC,0BAA0B,QAAQ,mBAAe;AAC1D,SAASC,KAAK,EAAEC,IAAI,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AAC9D,SAASC,UAAU,EAAEC,KAAK,EAAEC,KAAK,QAAQ,qBAAoB;AAC7D,SAASC,OAAO,QAAQ,QAAO;AAC/B,SACEC,YAAY,EACZC,sBAAsB,EACtBC,eAAe,QACV,iCAAgC;AACvC;;;;;CAKC,GACD,SACEC,eAAe,EACfC,iBAAiB,QACZ,+DAA8D;AACrE,SACEC,qBAAqB,EACrBC,qBAAqB,QAChB,kDAAiD;AAQxD;;;;;;;;CAQC,GACD,MAAMC,oBAAoB;AAE1B;;;;;;CAMC,GACD,OAAO,SAASC,wBAAwBC,KAAmC;;QAqG9CtB;IApG3B,MAAM,EAAEuB,MAAM,EAAEC,KAAK,EAAE,GAAGF;IAC1B,MAAMG,YAAYZ;IAClB,4EAA4E,GAC5E,MAAMa,gBAAgBvB;IACtB,mEAAmE;IACnE,sEAAsE;IACtE,wEAAwE;IACxE,6BAA6B;IAC7B,MAAM,EAAEwB,OAAOC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BAA0B,EAAE3E,kBAAkB,cAAc,CAAC,GAC7D,iEACA,kEACA;qBAEF;gBACH0C,OAAOkC,MAAM,KAAK,kBACjB,KAAC3F;oBAAM0F,UAAS;8BACb9C,YACG,6CACA;mCAGN,MAAC1C;oBAAMuF,SAAS;;sCACd,KAACzF;4BAAM0F,UAAS;sCACb,GAAGjC,OAAOkC,MAAM,CAAC,iBAAiB,EACjClC,OAAOkC,MAAM,KAAK,IAAI,KAAK,IAC5B,sDAAsD,CAAC;;wBAEzDlC,OAAOZ,GAAG,CAAC,CAAC+C,OAAOC,sBAClB,MAAC3F;gCAEC4F,WAAU;gCACVL,SAAS;gCACTM,IAAI;oCAAEC,YAAY;gCAAS;;kDAE3B,KAAC/F;wCAAKgG,MAAK;wCAAQC,OAAON,MAAMO,MAAM;;kDACtC,KAAChG;wCAAWiG,SAAQ;wCAAQC,MAAM;wCAACN,IAAI;4CAAEO,UAAU;wCAAM;kDACtDV,MAAMW,UAAU;;kDAEnB,KAACpG;wCAAWiG,SAAQ;wCAAUI,OAAM;kDACjC,CAAC,UAAU,EAAEZ,MAAMa,OAAO,CAAC,CAAC,CAAC;;kDAEhC,KAACtG;wCACCiG,SAAQ;wCACRI,OAAM;wCACNT,IAAI;4CAAEW,YAAY;wCAAY;kDAE7Bd,MAAMe,OAAO,IAAI;;oCAGnBtF,8BACC,KAACA;wCACCuF,MAAM7G,2BAA2BiD,EAAE;wCACnC9B,QAAQA;wCACRC,OAAOA;wCACPyE,OAAOA;yCAEP;;+BA3BC,GAAGA,MAAMiB,QAAQ,CAAC,CAAC,EAAEhB,OAAO;;;;;;AAmCjD;AACA7E,wBAAwB8F,WAAW,GAAG;AAEtC,eAAe9F,wBAAuB"}
|
|
@@ -36,6 +36,8 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
36
36
|
import { useFirestore, useFirestoreCollection, useHostResourceApi, useUser, writeGuardedBySeed } from "@aglyn/tenant-feature-instance";
|
|
37
37
|
import { writeSiteWideChange } from "@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change";
|
|
38
38
|
import WhereUsedDialog from "./where-used-dialog.component.js";
|
|
39
|
+
import { useConsoleWidgetSlot } from "@aglyn/aglyn/app-utils/console-widget-slot-context";
|
|
40
|
+
import { HOST_LOGIC_ZONE } from "./logic-zones.js";
|
|
39
41
|
import { fetchWhereUsed, summarizeDependents } from "@aglyn/aglyn/app-utils/where-used";
|
|
40
42
|
/**
|
|
41
43
|
* How many variables the card reads.
|
|
@@ -174,6 +176,7 @@ import { fetchWhereUsed, summarizeDependents } from "@aglyn/aglyn/app-utils/wher
|
|
|
174
176
|
});
|
|
175
177
|
const { rows: readVariables, truncated: variablesTruncated } = ceilingedWindow(variableDocs, VARIABLE_CEILING);
|
|
176
178
|
const [draft, setDraft] = useState(null);
|
|
179
|
+
/** The shell's zone renderer (AGL-3603); `null` outside the console shell. */ const ExtensionZone = useConsoleWidgetSlot();
|
|
177
180
|
/**
|
|
178
181
|
* The editor has been opened at least once in this session.
|
|
179
182
|
*
|
|
@@ -280,6 +283,31 @@ import { fetchWhereUsed, summarizeDependents } from "@aglyn/aglyn/app-utils/wher
|
|
|
280
283
|
variableCountEpoch
|
|
281
284
|
]);
|
|
282
285
|
const variableCount = serverVariableCount != null ? serverVariableCount : variables.length;
|
|
286
|
+
/*
|
|
287
|
+
* Opens a variable another plugin proposed (AGL-3603) as Add variable opens
|
|
288
|
+
* one — the plan's cap asked first — unsaved. Save is the only write.
|
|
289
|
+
*/ const propose = useCallback((proposal)=>{
|
|
290
|
+
if (proposal.kind !== 'variable') return false;
|
|
291
|
+
const quota = checkQuota(org, 'variablesPerHost', variableCount);
|
|
292
|
+
if (!quota.allowed) {
|
|
293
|
+
enqueueSnackbar(`Variable limit reached (${quota.limit}) — upgrade in Billing`, {
|
|
294
|
+
variant: 'warning',
|
|
295
|
+
persist: false
|
|
296
|
+
});
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
setDraft(_extends({
|
|
300
|
+
id: null
|
|
301
|
+
}, proposal.variable, {
|
|
302
|
+
workflowId: '',
|
|
303
|
+
workflowName: ''
|
|
304
|
+
}));
|
|
305
|
+
return true;
|
|
306
|
+
}, [
|
|
307
|
+
org,
|
|
308
|
+
variableCount,
|
|
309
|
+
enqueueSnackbar
|
|
310
|
+
]);
|
|
283
311
|
const validName = VARIABLE_NAME_PATTERN.test((_ref = draft == null ? void 0 : draft.name) != null ? _ref : '');
|
|
284
312
|
// Case-insensitive (AGL-185): names must stay unambiguous for legacy
|
|
285
313
|
// {{name}} token resolution and picker display.
|
|
@@ -427,6 +455,14 @@ import { fetchWhereUsed, summarizeDependents } from "@aglyn/aglyn/app-utils/wher
|
|
|
427
455
|
help: pluginDocsHelp('bindings', {
|
|
428
456
|
anchor: '#typed-variables'
|
|
429
457
|
}),
|
|
458
|
+
// Another way to start a variable (AGL-3603), in the card's header.
|
|
459
|
+
actions: ExtensionZone ? /*#__PURE__*/ _jsx(ExtensionZone, {
|
|
460
|
+
slot: HOST_LOGIC_ZONE.id,
|
|
461
|
+
hostId: hostId,
|
|
462
|
+
orgId: org == null ? void 0 : org.$id,
|
|
463
|
+
kind: "variable",
|
|
464
|
+
propose: propose
|
|
465
|
+
}) : null,
|
|
430
466
|
contentGutterX: true,
|
|
431
467
|
contentGutterY: true,
|
|
432
468
|
children: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/host-variables-card.component.tsx"],"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'use client'\n\nimport {\n type AglynOrgBilling,\n checkQuota,\n formatVariableValue,\n HOST_VARIABLE_TYPE_LABELS,\n type HostVariable,\n type HostVariableType,\n pluginDocsHelp,\n VARIABLE_NAME_PATTERN,\n} from '@aglyn/aglyn'\n/*\n * The MODULE, not the barrel, for the two PURE helpers. Every spec that renders\n * this card mocks `@aglyn/tenant-feature-instance` wholesale to stage its\n * Firestore hooks, and a query builder imported through that barrel disappears\n * under the mock — which fails as \"not a function\" in the component rather than\n * as anything about the test's subject. Neither of these is a hook.\n */\nimport {\n ceilingedWindow,\n collectionCeiling,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport {\n pluginRecordListQuery,\n pluginRecordsFromRows,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\nimport { CardDisplay, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { TABLE_PAGE_SIZE_DEFAULT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { Timestamp } from '@aglyn/shared-util-timestamp'\nimport {\n Alert,\n Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { collection, doc, getCountFromServer } from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useHostResourceApi,\n useUser,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { writeSiteWideChange } from '@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change'\nimport WhereUsedDialog from './where-used-dialog.component'\nimport {\n fetchWhereUsed,\n summarizeDependents,\n type WhereUsedResult,\n} from '@aglyn/aglyn/app-utils/where-used'\n\n/**\n * How many variables the card reads.\n *\n * A CEILING, not a page size — see the query, which explains why this list\n * cannot be paged by the server without making the duplicate-name check lie.\n */\nconst VARIABLE_CEILING = 100\n\n/**\n * How many workflows the computed-variable picker offers.\n *\n * Paid for only while the editor is open, which is what makes a ceiling this\n * size affordable: it is one reader mid-edit rather than every visitor to the\n * page.\n */\nconst WORKFLOW_OPTION_CEILING = 100\n\nexport interface HostVariablesCardProps {\n hostId: string\n /** Resolved entitlement source for quota checks (AGL-395). */\n org?: Partial<AglynOrgBilling>\n}\n\ninterface VariableDraft {\n /** Computed-source workflow doc id (AGL-261); name is the display hint. */\n workflowId: string\n id: string | null\n name: string\n type: HostVariableType\n value: string\n /** Workflow (by name) computing this variable at render (AGL-129). */\n workflowName: string\n}\n\n/** Per-type value editor: mirrors the mockup's type list. */\nfunction VariableValueField(props: {\n draft: VariableDraft\n onChange: (value: string) => void\n}) {\n const { draft, onChange } = props\n switch (draft.type) {\n case 'boolean':\n return (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Switch\n checked={draft.value === 'true'}\n onChange={(event) =>\n onChange(event.target.checked ? 'true' : 'false')\n }\n />\n <Typography variant=\"body2\">\n {draft.value === 'true' ? 'True' : 'False'}\n </Typography>\n </Stack>\n )\n case 'date':\n case 'time':\n return (\n <TextField\n label=\"Value\"\n type={draft.type}\n value={draft.value}\n onChange={(event) => onChange(event.target.value)}\n size=\"small\"\n slotProps={{ inputLabel: { shrink: true } }}\n />\n )\n case 'number':\n return (\n <TextField\n label=\"Value\"\n value={draft.value}\n onChange={(event) =>\n onChange(event.target.value.replace(/[^0-9.eE+-]/g, ''))\n }\n size=\"small\"\n />\n )\n case 'dictionary':\n case 'collection':\n return (\n <TextField\n label=\"Value (JSON)\"\n placeholder={\n draft.type === 'dictionary' ? '{\"key\": \"value\"}' : '[\"a\", \"b\"]'\n }\n value={draft.value}\n onChange={(event) => onChange(event.target.value)}\n size=\"small\"\n multiline\n minRows={3}\n />\n )\n default:\n return (\n <TextField\n label=\"Value\"\n value={draft.value}\n onChange={(event) => onChange(event.target.value)}\n size=\"small\"\n multiline\n />\n )\n }\n}\n\n/**\n * Host variables (Component Builder, AGL-91): the mockup's Edit Variable\n * dialog — name + typed value — persisted to `hosts/{hostId}/variables`.\n * Any string prop can reference a variable with `{{name}}`; the org\n * compose pipeline resolves it at render. Soft delete keeps old tokens\n * rendering literally rather than breaking published pages.\n */\nexport function HostVariablesCard(props: HostVariablesCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const createHostResource = useHostResourceApi()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n const { org } = props\n // Where-used dependents dialog (AGL-187).\n const [usage, setUsage] = useState<{\n name: string\n result: WhereUsedResult\n } | null>(null)\n const [usageLoading, setUsageLoading] = useState<string | null>(null)\n const {\n data: variableDocs,\n status: variablesStatus,\n /**\n * The rows this editor is seeded from are unconfirmed by the server\n * (AGL-1358). Editing copies a whole stored variable into `draft` and\n * writes all of it back, so `merge: true` protects nothing — every field\n * is in the payload. `value` is the literal every `{{name}}` binding on\n * every published page resolves to, and `workflowId` is what rebinds a\n * computed variable to its source (AGL-261), so a cached seed can point\n * a live binding back at a value or a workflow the author replaced.\n */\n fromCache: variablesFromCache,\n } = useFirestoreCollection<any>(\n /*\n * ORDERED AND CEILINGED, deliberately not paged by the query (AGL-2501).\n *\n * `limit(100)` alone is answered in DOCUMENT-ID order, so the window is a\n * pseudo-random hundred that the `localeCompare` below arranges into a\n * convincing A-to-Z list. `variablesPerHost` runs to 5,000, so a Scale\n * site with three hundred variables sees a hundred of them and nothing\n * said so.\n *\n * `collectionCeiling` does not change WHICH hundred — document-id order is\n * what the bare cap already returned. What it changes is that the order is\n * NAMED, so the obvious next edit is caught: ordering on `name` would not\n * mis-sort this list, it would HIDE from it every variable written without\n * one, and `/api/hosts/resources` validates no field for presence while\n * `IMPORTABLE_FIELDS.variables` copies a name only if the exported\n * document carried it. The document name cannot be absent.\n *\n * The QUERY is not paged because `nameTaken` below tests the draft against\n * these rows. Case-insensitive uniqueness is what keeps legacy `{{name}}`\n * token resolution unambiguous (AGL-185), and on a ten-row server page\n * that check would compare a new variable against a tenth of the site and\n * cheerfully create the duplicate it exists to prevent.\n *\n * The check is still only as complete as the ceiling, and that is now\n * SAID rather than assumed: the notice under the list appears exactly when\n * the probe finds a variable this card did not read.\n */\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, 'variables'),\n VARIABLE_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n const { rows: readVariables, truncated: variablesTruncated } =\n ceilingedWindow<any>(variableDocs, VARIABLE_CEILING)\n const [draft, setDraft] = useState<VariableDraft | null>(null)\n /**\n * The editor has been opened at least once in this session.\n *\n * A LATCH rather than `draft` itself, because the workflow picker below keys its\n * listeners on it. Tracking the dialog would tear that subscription down\n * on Cancel and pay for them again on the next Edit, so a merchant working\n * through ten variables would buy the same window ten times — worse than\n * the mount-time read this replaces. Latched, a reader who never edits pays\n * nothing and a reader who edits pays once.\n */\n const [editorOpened, setEditorOpened] = useState(false)\n if (draft && !editorOpened) setEditorOpened(true)\n /*\n * Workflow picker options (AGL-261): computed variables reference the\n * workflow by doc id instead of a typed name. The workflows are the\n * workflows plugin's, listed through the source it publishes (AGL-3080).\n *\n * READ WHEN THE EDITOR OPENS, not when the card mounts (AGL-2501). Nothing\n * outside the dialog below touches these rows — the table shows a computed\n * variable's stored `workflowName`, never a name looked up here — so an\n * unconditional listener would charge every visitor to this page for a\n * hundred workflows to fill a select most of them never see.\n *\n * Ceilinged and ordered for the same reason as the variables above: a bare\n * `limit` is answered in document-id order, so the `localeCompare` below\n * would arrange a pseudo-random hundred into a convincing alphabet and a\n * workflow past it could not be picked, with nothing saying why.\n */\n const { data: workflowDocs } = useFirestoreCollection<any>(\n () =>\n editorOpened\n ? pluginRecordListQuery('workflow', firestore, {\n hostId,\n limit: WORKFLOW_OPTION_CEILING + 1,\n })\n : null,\n [firestore, hostId, editorOpened],\n { idField: '$id' },\n )\n const { rows: readWorkflows, truncated: workflowOptionsTruncated } =\n ceilingedWindow<any>(workflowDocs, WORKFLOW_OPTION_CEILING)\n // Sorting the whole ceiling, not a page of it. The workflows plugin answers\n // live, named workflows only.\n const workflowOptions = pluginRecordsFromRows('workflow', readWorkflows)\n .map((workflow) => ({ id: workflow.id, name: workflow.name }))\n .sort((a, b) => a.name.localeCompare(b.name))\n /*\n * Sorting is safe HERE in a way it is not on a paged list: these rows are\n * the whole collection below the ceiling, not a slice of one, so the order\n * on screen is the order of everything the card holds.\n */\n const variables = useMemo(\n () =>\n readVariables\n .filter((variable: any) => !variable.deletedAt)\n .sort((a: any, b: any) =>\n String(a.name ?? '').localeCompare(String(b.name ?? '')),\n ),\n [readVariables],\n )\n // The page is a SLICE, because the rows are already in hand and `nameTaken`\n // needs all of them. What the card lacked was not a cheaper read but a\n // control: a hundred variables rendered as one wall.\n const [page, setPage] = useState(0)\n const [pageSize, setPageSize] = useState(TABLE_PAGE_SIZE_DEFAULT)\n const visibleVariables = useMemo(\n () => variables.slice(page * pageSize, page * pageSize + pageSize),\n [variables, page, pageSize],\n )\n /**\n * The variable HEAD-COUNT is a server aggregate, not the length of the\n * capped listener (AGL-1716, the AGL-1706 shape).\n *\n * The listener is `limit(100)` and `variables.length` was handed to\n * `checkQuota(org, 'variablesPerHost', …)`. The bands are 3 / 25 / 100 /\n * 1,000 / 5,000, so the window ties Pro's 100 and hides Business's 1,000\n * and Scale's 5,000 entirely: on those plans the gate compared 100 against\n * thousands and could never refuse, while `api/hosts/resources` counted\n * the collection and did. The card offered headroom that did not exist and\n * then failed the create.\n *\n * UNFILTERED, matching the enforcing route: it runs a plain\n * `collection('variables').count()` for this quota — its `softDeletes`\n * branch governs only the flat per-host webhook cap — so a soft-deleted\n * variable has always counted toward `variablesPerHost` server-side while\n * this card excluded it. The card now asks the route's question in the\n * route's terms, which is the only thing that makes a console gate a\n * useful prediction of the route's verdict.\n *\n * THE LIST KEEPS ITS CAP. Only a create moves the number (deletes here are\n * soft, and the route counts them), so that is where it is re-read.\n */\n const [variableCountEpoch, setVariableCountEpoch] = useState(0)\n const [serverVariableCount, setServerVariableCount] = useState<number | null>(\n null,\n )\n useEffect(() => {\n let active = true\n void getCountFromServer(collection(firestore, 'hosts', hostId, 'variables'))\n .then((snapshot) => {\n if (active) setServerVariableCount(snapshot.data().count)\n })\n .catch(() => {\n // Falls back to the loaded rows below — a LOWER bound, and this\n // card's prior behaviour. Deliberately not 0: `checkQuota` answers\n // from whatever it is handed, and 0 used is a confident wrong\n // number in the flattering direction.\n })\n return () => {\n active = false\n }\n }, [firestore, hostId, variableCountEpoch])\n const variableCount = serverVariableCount ?? variables.length\n\n const validName = VARIABLE_NAME_PATTERN.test(draft?.name ?? '')\n // Case-insensitive (AGL-185): names must stay unambiguous for legacy\n // {{name}} token resolution and picker display.\n const nameTaken = Boolean(\n draft &&\n variables.some(\n (variable: any) =>\n String(variable.name ?? '').toLowerCase() ===\n draft.name.trim().toLowerCase() && variable.$id !== draft.id,\n ),\n )\n\n const handleSave = useCallback(async () => {\n if (!draft || !validName || nameTaken) return\n const fields = {\n name: draft.name,\n type: draft.type,\n value: draft.value,\n workflowId: draft.workflowId.trim(),\n workflowName: draft.workflowName.trim(),\n }\n try {\n if (draft.id) {\n /**\n * Edit stays client-direct (no quota consumed) — and is refused when\n * its seed was never confirmed by the server (AGL-1358). `merge:\n * true` protects nothing here: `fields` is every editable key of the\n * stored row, copied off the listener whether or not it was touched.\n *\n * The guard WRAPS the write. An early return is a shape you can keep\n * while losing the protection; here the write is only reachable\n * through the verdict.\n */\n const verdict = await writeGuardedBySeed(\n {\n subject: 'variable',\n unreadable: variablesStatus === 'error',\n fromCache: variablesFromCache,\n },\n async () => {\n await writeSiteWideChange({\n firestore,\n user,\n hostId,\n write: (batch) =>\n batch.set(\n doc(firestore, 'hosts', hostId, 'variables', draft.id),\n { ...fields, updatedAt: Timestamp.now() },\n { merge: true },\n ),\n })\n },\n )\n // Before `setDraft(null)`, so a refusal keeps the dialog open with\n // what was typed. A save that silently does nothing sends the user\n // back to retype a form that will be refused again just as quietly.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n } else {\n // New variable rides the quota-enforcing resources API (AGL-473).\n await createHostResource({ hostId, resource: 'variable', data: fields })\n // A create moves the count and the aggregate is a one-shot — the\n // listener refreshes the ROWS for free, the count has to be asked\n // again or the cap drifts stale for the rest of the session.\n setVariableCountEpoch((epoch) => epoch + 1)\n }\n setDraft(null)\n enqueueSnackbar(\n `Saved — use {{${draft.name}}} in any text to bind it`,\n { variant: 'success', persist: false },\n )\n } catch (error: any) {\n console.error(error)\n enqueueSnackbar(error?.message ?? 'An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n }, [\n user,\n draft,\n validName,\n nameTaken,\n firestore,\n hostId,\n createHostResource,\n enqueueSnackbar,\n variablesStatus,\n variablesFromCache,\n ])\n\n const handleShowUsage = useCallback(\n (variable: any) => async () => {\n setUsageLoading(variable.$id)\n const result = await fetchWhereUsed(user as any, {\n hostId,\n kind: 'variable',\n id: variable.$id,\n name: variable.name,\n })\n setUsageLoading(null)\n setUsage({ name: variable.name, result })\n },\n [user, hostId],\n )\n\n const handleDelete = useCallback(\n (variable: any) => async () => {\n // Real dependents warning (AGL-187) instead of the generic copy.\n const scan = await fetchWhereUsed(user as any, {\n hostId,\n kind: 'variable',\n id: variable.$id,\n name: variable.name,\n })\n const confirmed = await confirm({\n title: 'Delete this variable?',\n description: scan.total\n ? `\"${variable.name}\" is used in ${summarizeDependents(scan)}. ` +\n 'Those bindings will render as empty or literal tokens after ' +\n 'the next publish.'\n : `\"${variable.name}\" is not referenced by any published ` +\n 'page, layout, or workflow.',\n confirmationText: 'Delete',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n await writeSiteWideChange({\n firestore,\n user,\n hostId,\n write: (batch) =>\n batch.update(\n doc(firestore, 'hosts', hostId, 'variables', variable.$id),\n { deletedAt: Timestamp.now() },\n ),\n })\n enqueueSnackbar('Variable deleted', {\n variant: 'success',\n persist: false,\n })\n },\n [user, confirm, firestore, hostId, enqueueSnackbar],\n )\n\n return (\n <CardDisplay\n header={'Variables'}\n help={pluginDocsHelp('bindings', { anchor: '#typed-variables' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1}>\n {variables.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Define typed values once and bind them anywhere with ' +\n '{{name}} — change the variable, every page updates on the ' +\n 'next publish.'}\n </Typography>\n ) : (\n visibleVariables.map((variable: any) => (\n <Stack\n key={variable.$id}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {`{{${variable.name}}}`}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {`${HOST_VARIABLE_TYPE_LABELS[variable.type as HostVariableType] ?? variable.type} · ${\n formatVariableValue(variable as HostVariable) || '—'\n }`}\n </Typography>\n </Stack>\n <Button\n size=\"small\"\n disabled={usageLoading === variable.$id}\n onClick={handleShowUsage(variable)}\n >\n {usageLoading === variable.$id ? 'Scanning…' : 'Usage'}\n </Button>\n <Button\n size=\"small\"\n onClick={() =>\n setDraft({\n id: variable.$id,\n name: variable.name ?? '',\n type: variable.type ?? 'text',\n value: variable.value ?? '',\n workflowId: variable.workflowId ?? '',\n workflowName: variable.workflowName ?? '',\n })\n }\n >\n {'Edit'}\n </Button>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={handleDelete(variable)}\n >\n {'Delete'}\n </Button>\n </Stack>\n ))\n )}\n {variables.length === 0 ? null : (\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={visibleVariables.length}\n // The variables the card HOLDS. Not `variableCount`, which is the\n // site's total including soft-deleted rows and answers the quota's\n // question rather than the reader's.\n count={variables.length}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n )}\n {variablesTruncated ? (\n <Alert severity=\"info\">\n {`Showing ${VARIABLE_CEILING} variables, ordered by id. This site ` +\n 'has more — the duplicate-name check below only covers the ' +\n 'ones listed here, so a name may already be taken by one that ' +\n 'is not.'}\n </Alert>\n ) : null}\n <Button\n size=\"small\"\n color=\"primary\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => {\n // Plan cap (AGL-99): dark-launch — plan-less workspaces uncapped.\n // The site's variables, not this page of them (AGL-1716).\n const quota = checkQuota(org, 'variablesPerHost', variableCount)\n if (!quota.allowed) {\n return void enqueueSnackbar(\n `Variable limit reached (${quota.limit}) — upgrade in Billing`,\n { variant: 'warning', persist: false },\n )\n }\n setDraft({\n id: null,\n name: '',\n type: 'text',\n value: '',\n workflowId: '',\n workflowName: '',\n })\n }}\n >\n {'Add variable'}\n </Button>\n </Stack>\n <Dialog\n open={Boolean(draft)}\n onClose={() => setDraft(null)}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>\n {draft?.id ? 'Edit Variable' : 'Add Variable'}\n </DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2, pt: 1 }}\n >\n <TextField\n label=\"Name\"\n helperText={\n nameTaken\n ? 'A variable with this name already exists'\n : 'Used to identify the variable'\n }\n error={(Boolean(draft?.name) && !validName) || nameTaken}\n value={draft?.name ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? {\n ...prev,\n name: event.target.value.replace(\n /[^a-zA-Z0-9_]/g,\n '',\n ),\n }\n : prev,\n )\n }\n size=\"small\"\n autoFocus\n sx={{ mt: 1 }}\n />\n <TextField\n label=\"Type\"\n value={draft?.type ?? 'text'}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? {\n ...prev,\n type: event.target.value as HostVariableType,\n value: '',\n }\n : prev,\n )\n }\n size=\"small\"\n select\n >\n {Object.entries(HOST_VARIABLE_TYPE_LABELS).map(\n ([value, label]) => (\n <MenuItem key={value} value={value}>\n {label}\n </MenuItem>\n ),\n )}\n </TextField>\n {draft ? (\n <VariableValueField\n draft={draft}\n onChange={(value) =>\n setDraft((prev) => (prev ? { ...prev, value } : prev))\n }\n />\n ) : null}\n <TextField\n select\n label=\"Computed from workflow (optional)\"\n helperText={\n workflowOptionsTruncated\n ? `Showing ${WORKFLOW_OPTION_CEILING} workflows, ordered by ` +\n 'id. This site has more, so one of them is not offered here.'\n : 'Pick a workflow — its result becomes this ' +\n 'variable\\u2019s value at render; the value above is the ' +\n 'fallback (AGL-129)'\n }\n value={\n draft?.workflowId ||\n workflowOptions.find(\n (option) => option.name === draft?.workflowName,\n )?.id ||\n ''\n }\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? {\n ...prev,\n workflowId: event.target.value,\n workflowName:\n workflowOptions.find(\n (option) => option.id === event.target.value,\n )?.name ?? '',\n }\n : prev,\n )\n }\n size=\"small\"\n >\n <MenuItem value=\"\">{'None'}</MenuItem>\n {workflowOptions.map((option) => (\n <MenuItem key={option.id} value={option.id}>\n {option.name}\n </MenuItem>\n ))}\n </TextField>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDraft(null)}>{'Cancel'}</Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!validName || nameTaken}\n onClick={handleSave}\n >\n {'Save variable'}\n </Button>\n </DialogActions>\n </Dialog>\n <WhereUsedDialog\n hostId={hostId}\n usage={usage}\n onClose={() => setUsage(null)}\n />\n </CardDisplay>\n )\n}\nHostVariablesCard.displayName = 'HostVariablesCard'\n\nexport default HostVariablesCard\n"],"names":["checkQuota","formatVariableValue","HOST_VARIABLE_TYPE_LABELS","pluginDocsHelp","VARIABLE_NAME_PATTERN","ceilingedWindow","collectionCeiling","pluginRecordListQuery","pluginRecordsFromRows","CardDisplay","useConfirmationContext","ListPagination","TABLE_PAGE_SIZE_DEFAULT","useSnackbar","Timestamp","Alert","Button","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","Stack","Switch","TextField","Typography","collection","doc","getCountFromServer","useCallback","useEffect","useMemo","useState","useFirestore","useFirestoreCollection","useHostResourceApi","useUser","writeGuardedBySeed","writeSiteWideChange","WhereUsedDialog","fetchWhereUsed","summarizeDependents","VARIABLE_CEILING","WORKFLOW_OPTION_CEILING","VariableValueField","props","draft","onChange","type","direction","spacing","sx","alignItems","checked","value","event","target","variant","label","size","slotProps","inputLabel","shrink","replace","placeholder","multiline","minRows","HostVariablesCard","workflowOptions","hostId","firestore","data","user","createHostResource","enqueueSnackbar","confirm","org","usage","setUsage","usageLoading","setUsageLoading","variableDocs","status","variablesStatus","fromCache","variablesFromCache","idField","rows","readVariables","truncated","variablesTruncated","setDraft","editorOpened","setEditorOpened","workflowDocs","limit","readWorkflows","workflowOptionsTruncated","map","workflow","id","name","sort","a","b","localeCompare","variables","filter","variable","deletedAt","String","page","setPage","pageSize","setPageSize","visibleVariables","slice","variableCountEpoch","setVariableCountEpoch","serverVariableCount","setServerVariableCount","active","then","snapshot","count","catch","variableCount","length","validName","test","nameTaken","Boolean","some","toLowerCase","trim","$id","handleSave","fields","workflowId","workflowName","verdict","subject","unreadable","write","batch","set","updatedAt","now","merge","ok","message","persist","resource","epoch","error","console","allowDuplicate","handleShowUsage","result","kind","handleDelete","scan","confirmed","title","description","total","confirmationText","confirmationButtonProps","color","update","header","help","anchor","contentGutterX","contentGutterY","flex","minWidth","noWrap","disabled","onClick","rowCount","onPageChange","onPageSizeChange","severity","alignSelf","quota","allowed","open","onClose","maxWidth","fullWidth","display","flexDirection","gap","pt","helperText","prev","autoFocus","mt","select","Object","entries","find","option","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAEEA,UAAU,EACVC,mBAAmB,EACnBC,yBAAyB,EAGzBC,cAAc,EACdC,qBAAqB,QAChB,eAAc;AACrB;;;;;;CAMC,GACD,SACEC,eAAe,EACfC,iBAAiB,QACZ,+DAA8D;AACrE,SACEC,qBAAqB,EACrBC,qBAAqB,QAChB,kDAAiD;AACxD,SAASC,WAAW,EAAEC,sBAAsB,QAAQ,uBAAsB;AAC1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CAENW,OACER,CAAAA,yBAAAA,MAAO4F,UAAU,OACjBtE,wBAAAA,gBAAgBsI,IAAI,CAClB,CAACC,SAAWA,OAAOtG,IAAI,MAAKvD,yBAAAA,MAAO6F,YAAY,uBADjDvE,sBAEGgC,EAAE,KACL;gCAEFrD,UAAU,CAACQ,QACToC,SAAS,CAACyG;;4CAMAhI;+CALRgI,OACI,aACKA;4CACH1D,YAAYnF,MAAMC,MAAM,CAACF,KAAK;4CAC9BqF,YAAY,WACVvE,wBAAAA,gBAAgBsI,IAAI,CAClB,CAACC,SAAWA,OAAOvG,EAAE,KAAK7C,MAAMC,MAAM,CAACF,KAAK,sBAD9Cc,sBAEGiC,IAAI,mBAAI;6CAEf+F;;gCAGRzI,MAAK;;kDAEL,KAACtC;wCAASiC,OAAM;kDAAI;;oCACnBc,gBAAgB8B,GAAG,CAAC,CAACyG,uBACpB,KAACtL;4CAAyBiC,OAAOqJ,OAAOvG,EAAE;sDACvCuG,OAAOtG,IAAI;2CADCsG,OAAOvG,EAAE;;;;;kCAM9B,MAAClF;;0CACC,KAACF;gCAAOmK,SAAS,IAAMxF,SAAS;0CAAQ;;0CACxC,KAAC3E;gCACCyC,SAAQ;gCACR+G,OAAM;gCACNU,UAAU,CAAClD,aAAaE;gCACxBiD,SAAS3C;0CAER;;;;;;0BAIP,KAACjG;gBACC8B,QAAQA;gBACRQ,OAAOA;gBACP+G,SAAS,IAAM9G,SAAS;;;;AAIhC;AACAX,kBAAkByI,WAAW,GAAG;AAEhC,eAAezI,kBAAiB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/host-variables-card.component.tsx"],"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'use client'\n\nimport {\n type AglynOrgBilling,\n checkQuota,\n formatVariableValue,\n HOST_VARIABLE_TYPE_LABELS,\n type HostVariable,\n type HostVariableType,\n pluginDocsHelp,\n VARIABLE_NAME_PATTERN,\n} from '@aglyn/aglyn'\n/*\n * The MODULE, not the barrel, for the two PURE helpers. Every spec that renders\n * this card mocks `@aglyn/tenant-feature-instance` wholesale to stage its\n * Firestore hooks, and a query builder imported through that barrel disappears\n * under the mock — which fails as \"not a function\" in the component rather than\n * as anything about the test's subject. Neither of these is a hook.\n */\nimport {\n ceilingedWindow,\n collectionCeiling,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport {\n pluginRecordListQuery,\n pluginRecordsFromRows,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\nimport { CardDisplay, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport { TABLE_PAGE_SIZE_DEFAULT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport { Timestamp } from '@aglyn/shared-util-timestamp'\nimport {\n Alert,\n Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { collection, doc, getCountFromServer } from 'firebase/firestore'\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useHostResourceApi,\n useUser,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { writeSiteWideChange } from '@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change'\nimport WhereUsedDialog from './where-used-dialog.component'\nimport { useConsoleWidgetSlot } from '@aglyn/aglyn/app-utils/console-widget-slot-context'\nimport { HOST_LOGIC_ZONE, type LogicProposal } from './logic-zones'\nimport {\n fetchWhereUsed,\n summarizeDependents,\n type WhereUsedResult,\n} from '@aglyn/aglyn/app-utils/where-used'\n\n/**\n * How many variables the card reads.\n *\n * A CEILING, not a page size — see the query, which explains why this list\n * cannot be paged by the server without making the duplicate-name check lie.\n */\nconst VARIABLE_CEILING = 100\n\n/**\n * How many workflows the computed-variable picker offers.\n *\n * Paid for only while the editor is open, which is what makes a ceiling this\n * size affordable: it is one reader mid-edit rather than every visitor to the\n * page.\n */\nconst WORKFLOW_OPTION_CEILING = 100\n\nexport interface HostVariablesCardProps {\n hostId: string\n /** Resolved entitlement source for quota checks (AGL-395). */\n org?: Partial<AglynOrgBilling>\n}\n\ninterface VariableDraft {\n /** Computed-source workflow doc id (AGL-261); name is the display hint. */\n workflowId: string\n id: string | null\n name: string\n type: HostVariableType\n value: string\n /** Workflow (by name) computing this variable at render (AGL-129). */\n workflowName: string\n}\n\n/** Per-type value editor: mirrors the mockup's type list. */\nfunction VariableValueField(props: {\n draft: VariableDraft\n onChange: (value: string) => void\n}) {\n const { draft, onChange } = props\n switch (draft.type) {\n case 'boolean':\n return (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Switch\n checked={draft.value === 'true'}\n onChange={(event) =>\n onChange(event.target.checked ? 'true' : 'false')\n }\n />\n <Typography variant=\"body2\">\n {draft.value === 'true' ? 'True' : 'False'}\n </Typography>\n </Stack>\n )\n case 'date':\n case 'time':\n return (\n <TextField\n label=\"Value\"\n type={draft.type}\n value={draft.value}\n onChange={(event) => onChange(event.target.value)}\n size=\"small\"\n slotProps={{ inputLabel: { shrink: true } }}\n />\n )\n case 'number':\n return (\n <TextField\n label=\"Value\"\n value={draft.value}\n onChange={(event) =>\n onChange(event.target.value.replace(/[^0-9.eE+-]/g, ''))\n }\n size=\"small\"\n />\n )\n case 'dictionary':\n case 'collection':\n return (\n <TextField\n label=\"Value (JSON)\"\n placeholder={\n draft.type === 'dictionary' ? '{\"key\": \"value\"}' : '[\"a\", \"b\"]'\n }\n value={draft.value}\n onChange={(event) => onChange(event.target.value)}\n size=\"small\"\n multiline\n minRows={3}\n />\n )\n default:\n return (\n <TextField\n label=\"Value\"\n value={draft.value}\n onChange={(event) => onChange(event.target.value)}\n size=\"small\"\n multiline\n />\n )\n }\n}\n\n/**\n * Host variables (Component Builder, AGL-91): the mockup's Edit Variable\n * dialog — name + typed value — persisted to `hosts/{hostId}/variables`.\n * Any string prop can reference a variable with `{{name}}`; the org\n * compose pipeline resolves it at render. Soft delete keeps old tokens\n * rendering literally rather than breaking published pages.\n */\nexport function HostVariablesCard(props: HostVariablesCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const createHostResource = useHostResourceApi()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n const { org } = props\n // Where-used dependents dialog (AGL-187).\n const [usage, setUsage] = useState<{\n name: string\n result: WhereUsedResult\n } | null>(null)\n const [usageLoading, setUsageLoading] = useState<string | null>(null)\n const {\n data: variableDocs,\n status: variablesStatus,\n /**\n * The rows this editor is seeded from are unconfirmed by the server\n * (AGL-1358). Editing copies a whole stored variable into `draft` and\n * writes all of it back, so `merge: true` protects nothing — every field\n * is in the payload. `value` is the literal every `{{name}}` binding on\n * every published page resolves to, and `workflowId` is what rebinds a\n * computed variable to its source (AGL-261), so a cached seed can point\n * a live binding back at a value or a workflow the author replaced.\n */\n fromCache: variablesFromCache,\n } = useFirestoreCollection<any>(\n /*\n * ORDERED AND CEILINGED, deliberately not paged by the query (AGL-2501).\n *\n * `limit(100)` alone is answered in DOCUMENT-ID order, so the window is a\n * pseudo-random hundred that the `localeCompare` below arranges into a\n * convincing A-to-Z list. `variablesPerHost` runs to 5,000, so a Scale\n * site with three hundred variables sees a hundred of them and nothing\n * said so.\n *\n * `collectionCeiling` does not change WHICH hundred — document-id order is\n * what the bare cap already returned. What it changes is that the order is\n * NAMED, so the obvious next edit is caught: ordering on `name` would not\n * mis-sort this list, it would HIDE from it every variable written without\n * one, and `/api/hosts/resources` validates no field for presence while\n * `IMPORTABLE_FIELDS.variables` copies a name only if the exported\n * document carried it. The document name cannot be absent.\n *\n * The QUERY is not paged because `nameTaken` below tests the draft against\n * these rows. Case-insensitive uniqueness is what keeps legacy `{{name}}`\n * token resolution unambiguous (AGL-185), and on a ten-row server page\n * that check would compare a new variable against a tenth of the site and\n * cheerfully create the duplicate it exists to prevent.\n *\n * The check is still only as complete as the ceiling, and that is now\n * SAID rather than assumed: the notice under the list appears exactly when\n * the probe finds a variable this card did not read.\n */\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, 'variables'),\n VARIABLE_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n const { rows: readVariables, truncated: variablesTruncated } =\n ceilingedWindow<any>(variableDocs, VARIABLE_CEILING)\n const [draft, setDraft] = useState<VariableDraft | null>(null)\n\n /** The shell's zone renderer (AGL-3603); `null` outside the console shell. */\n const ExtensionZone = useConsoleWidgetSlot()\n /**\n * The editor has been opened at least once in this session.\n *\n * A LATCH rather than `draft` itself, because the workflow picker below keys its\n * listeners on it. Tracking the dialog would tear that subscription down\n * on Cancel and pay for them again on the next Edit, so a merchant working\n * through ten variables would buy the same window ten times — worse than\n * the mount-time read this replaces. Latched, a reader who never edits pays\n * nothing and a reader who edits pays once.\n */\n const [editorOpened, setEditorOpened] = useState(false)\n if (draft && !editorOpened) setEditorOpened(true)\n /*\n * Workflow picker options (AGL-261): computed variables reference the\n * workflow by doc id instead of a typed name. The workflows are the\n * workflows plugin's, listed through the source it publishes (AGL-3080).\n *\n * READ WHEN THE EDITOR OPENS, not when the card mounts (AGL-2501). Nothing\n * outside the dialog below touches these rows — the table shows a computed\n * variable's stored `workflowName`, never a name looked up here — so an\n * unconditional listener would charge every visitor to this page for a\n * hundred workflows to fill a select most of them never see.\n *\n * Ceilinged and ordered for the same reason as the variables above: a bare\n * `limit` is answered in document-id order, so the `localeCompare` below\n * would arrange a pseudo-random hundred into a convincing alphabet and a\n * workflow past it could not be picked, with nothing saying why.\n */\n const { data: workflowDocs } = useFirestoreCollection<any>(\n () =>\n editorOpened\n ? pluginRecordListQuery('workflow', firestore, {\n hostId,\n limit: WORKFLOW_OPTION_CEILING + 1,\n })\n : null,\n [firestore, hostId, editorOpened],\n { idField: '$id' },\n )\n const { rows: readWorkflows, truncated: workflowOptionsTruncated } =\n ceilingedWindow<any>(workflowDocs, WORKFLOW_OPTION_CEILING)\n // Sorting the whole ceiling, not a page of it. The workflows plugin answers\n // live, named workflows only.\n const workflowOptions = pluginRecordsFromRows('workflow', readWorkflows)\n .map((workflow) => ({ id: workflow.id, name: workflow.name }))\n .sort((a, b) => a.name.localeCompare(b.name))\n /*\n * Sorting is safe HERE in a way it is not on a paged list: these rows are\n * the whole collection below the ceiling, not a slice of one, so the order\n * on screen is the order of everything the card holds.\n */\n const variables = useMemo(\n () =>\n readVariables\n .filter((variable: any) => !variable.deletedAt)\n .sort((a: any, b: any) =>\n String(a.name ?? '').localeCompare(String(b.name ?? '')),\n ),\n [readVariables],\n )\n // The page is a SLICE, because the rows are already in hand and `nameTaken`\n // needs all of them. What the card lacked was not a cheaper read but a\n // control: a hundred variables rendered as one wall.\n const [page, setPage] = useState(0)\n const [pageSize, setPageSize] = useState(TABLE_PAGE_SIZE_DEFAULT)\n const visibleVariables = useMemo(\n () => variables.slice(page * pageSize, page * pageSize + pageSize),\n [variables, page, pageSize],\n )\n /**\n * The variable HEAD-COUNT is a server aggregate, not the length of the\n * capped listener (AGL-1716, the AGL-1706 shape).\n *\n * The listener is `limit(100)` and `variables.length` was handed to\n * `checkQuota(org, 'variablesPerHost', …)`. The bands are 3 / 25 / 100 /\n * 1,000 / 5,000, so the window ties Pro's 100 and hides Business's 1,000\n * and Scale's 5,000 entirely: on those plans the gate compared 100 against\n * thousands and could never refuse, while `api/hosts/resources` counted\n * the collection and did. The card offered headroom that did not exist and\n * then failed the create.\n *\n * UNFILTERED, matching the enforcing route: it runs a plain\n * `collection('variables').count()` for this quota — its `softDeletes`\n * branch governs only the flat per-host webhook cap — so a soft-deleted\n * variable has always counted toward `variablesPerHost` server-side while\n * this card excluded it. The card now asks the route's question in the\n * route's terms, which is the only thing that makes a console gate a\n * useful prediction of the route's verdict.\n *\n * THE LIST KEEPS ITS CAP. Only a create moves the number (deletes here are\n * soft, and the route counts them), so that is where it is re-read.\n */\n const [variableCountEpoch, setVariableCountEpoch] = useState(0)\n const [serverVariableCount, setServerVariableCount] = useState<number | null>(\n null,\n )\n useEffect(() => {\n let active = true\n void getCountFromServer(collection(firestore, 'hosts', hostId, 'variables'))\n .then((snapshot) => {\n if (active) setServerVariableCount(snapshot.data().count)\n })\n .catch(() => {\n // Falls back to the loaded rows below — a LOWER bound, and this\n // card's prior behaviour. Deliberately not 0: `checkQuota` answers\n // from whatever it is handed, and 0 used is a confident wrong\n // number in the flattering direction.\n })\n return () => {\n active = false\n }\n }, [firestore, hostId, variableCountEpoch])\n const variableCount = serverVariableCount ?? variables.length\n /*\n * Opens a variable another plugin proposed (AGL-3603) as Add variable opens\n * one — the plan's cap asked first — unsaved. Save is the only write.\n */\n const propose = useCallback(\n (proposal: LogicProposal) => {\n if (proposal.kind !== 'variable') return false\n const quota = checkQuota(org, 'variablesPerHost', variableCount)\n if (!quota.allowed) {\n enqueueSnackbar(`Variable limit reached (${quota.limit}) — upgrade in Billing`, {\n variant: 'warning',\n persist: false,\n })\n return false\n }\n setDraft({ id: null, ...proposal.variable, workflowId: '', workflowName: '' })\n return true\n },\n [org, variableCount, enqueueSnackbar],\n )\n\n const validName = VARIABLE_NAME_PATTERN.test(draft?.name ?? '')\n // Case-insensitive (AGL-185): names must stay unambiguous for legacy\n // {{name}} token resolution and picker display.\n const nameTaken = Boolean(\n draft &&\n variables.some(\n (variable: any) =>\n String(variable.name ?? '').toLowerCase() ===\n draft.name.trim().toLowerCase() && variable.$id !== draft.id,\n ),\n )\n\n const handleSave = useCallback(async () => {\n if (!draft || !validName || nameTaken) return\n const fields = {\n name: draft.name,\n type: draft.type,\n value: draft.value,\n workflowId: draft.workflowId.trim(),\n workflowName: draft.workflowName.trim(),\n }\n try {\n if (draft.id) {\n /**\n * Edit stays client-direct (no quota consumed) — and is refused when\n * its seed was never confirmed by the server (AGL-1358). `merge:\n * true` protects nothing here: `fields` is every editable key of the\n * stored row, copied off the listener whether or not it was touched.\n *\n * The guard WRAPS the write. An early return is a shape you can keep\n * while losing the protection; here the write is only reachable\n * through the verdict.\n */\n const verdict = await writeGuardedBySeed(\n {\n subject: 'variable',\n unreadable: variablesStatus === 'error',\n fromCache: variablesFromCache,\n },\n async () => {\n await writeSiteWideChange({\n firestore,\n user,\n hostId,\n write: (batch) =>\n batch.set(\n doc(firestore, 'hosts', hostId, 'variables', draft.id),\n { ...fields, updatedAt: Timestamp.now() },\n { merge: true },\n ),\n })\n },\n )\n // Before `setDraft(null)`, so a refusal keeps the dialog open with\n // what was typed. A save that silently does nothing sends the user\n // back to retype a form that will be refused again just as quietly.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n } else {\n // New variable rides the quota-enforcing resources API (AGL-473).\n await createHostResource({ hostId, resource: 'variable', data: fields })\n // A create moves the count and the aggregate is a one-shot — the\n // listener refreshes the ROWS for free, the count has to be asked\n // again or the cap drifts stale for the rest of the session.\n setVariableCountEpoch((epoch) => epoch + 1)\n }\n setDraft(null)\n enqueueSnackbar(\n `Saved — use {{${draft.name}}} in any text to bind it`,\n { variant: 'success', persist: false },\n )\n } catch (error: any) {\n console.error(error)\n enqueueSnackbar(error?.message ?? 'An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n }, [\n user,\n draft,\n validName,\n nameTaken,\n firestore,\n hostId,\n createHostResource,\n enqueueSnackbar,\n variablesStatus,\n variablesFromCache,\n ])\n\n const handleShowUsage = useCallback(\n (variable: any) => async () => {\n setUsageLoading(variable.$id)\n const result = await fetchWhereUsed(user as any, {\n hostId,\n kind: 'variable',\n id: variable.$id,\n name: variable.name,\n })\n setUsageLoading(null)\n setUsage({ name: variable.name, result })\n },\n [user, hostId],\n )\n\n const handleDelete = useCallback(\n (variable: any) => async () => {\n // Real dependents warning (AGL-187) instead of the generic copy.\n const scan = await fetchWhereUsed(user as any, {\n hostId,\n kind: 'variable',\n id: variable.$id,\n name: variable.name,\n })\n const confirmed = await confirm({\n title: 'Delete this variable?',\n description: scan.total\n ? `\"${variable.name}\" is used in ${summarizeDependents(scan)}. ` +\n 'Those bindings will render as empty or literal tokens after ' +\n 'the next publish.'\n : `\"${variable.name}\" is not referenced by any published ` +\n 'page, layout, or workflow.',\n confirmationText: 'Delete',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n await writeSiteWideChange({\n firestore,\n user,\n hostId,\n write: (batch) =>\n batch.update(\n doc(firestore, 'hosts', hostId, 'variables', variable.$id),\n { deletedAt: Timestamp.now() },\n ),\n })\n enqueueSnackbar('Variable deleted', {\n variant: 'success',\n persist: false,\n })\n },\n [user, confirm, firestore, hostId, enqueueSnackbar],\n )\n\n return (\n <CardDisplay\n header={'Variables'}\n help={pluginDocsHelp('bindings', { anchor: '#typed-variables' })}\n // Another way to start a variable (AGL-3603), in the card's header.\n actions={\n ExtensionZone ? (\n <ExtensionZone\n slot={HOST_LOGIC_ZONE.id}\n hostId={hostId}\n orgId={org?.$id}\n kind=\"variable\"\n propose={propose}\n />\n ) : null\n }\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1}>\n {variables.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Define typed values once and bind them anywhere with ' +\n '{{name}} — change the variable, every page updates on the ' +\n 'next publish.'}\n </Typography>\n ) : (\n visibleVariables.map((variable: any) => (\n <Stack\n key={variable.$id}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {`{{${variable.name}}}`}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {`${HOST_VARIABLE_TYPE_LABELS[variable.type as HostVariableType] ?? variable.type} · ${\n formatVariableValue(variable as HostVariable) || '—'\n }`}\n </Typography>\n </Stack>\n <Button\n size=\"small\"\n disabled={usageLoading === variable.$id}\n onClick={handleShowUsage(variable)}\n >\n {usageLoading === variable.$id ? 'Scanning…' : 'Usage'}\n </Button>\n <Button\n size=\"small\"\n onClick={() =>\n setDraft({\n id: variable.$id,\n name: variable.name ?? '',\n type: variable.type ?? 'text',\n value: variable.value ?? '',\n workflowId: variable.workflowId ?? '',\n workflowName: variable.workflowName ?? '',\n })\n }\n >\n {'Edit'}\n </Button>\n <Button\n size=\"small\"\n color=\"error\"\n onClick={handleDelete(variable)}\n >\n {'Delete'}\n </Button>\n </Stack>\n ))\n )}\n {variables.length === 0 ? null : (\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={visibleVariables.length}\n // The variables the card HOLDS. Not `variableCount`, which is the\n // site's total including soft-deleted rows and answers the quota's\n // question rather than the reader's.\n count={variables.length}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n )}\n {variablesTruncated ? (\n <Alert severity=\"info\">\n {`Showing ${VARIABLE_CEILING} variables, ordered by id. This site ` +\n 'has more — the duplicate-name check below only covers the ' +\n 'ones listed here, so a name may already be taken by one that ' +\n 'is not.'}\n </Alert>\n ) : null}\n <Button\n size=\"small\"\n color=\"primary\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={() => {\n // Plan cap (AGL-99): dark-launch — plan-less workspaces uncapped.\n // The site's variables, not this page of them (AGL-1716).\n const quota = checkQuota(org, 'variablesPerHost', variableCount)\n if (!quota.allowed) {\n return void enqueueSnackbar(\n `Variable limit reached (${quota.limit}) — upgrade in Billing`,\n { variant: 'warning', persist: false },\n )\n }\n setDraft({\n id: null,\n name: '',\n type: 'text',\n value: '',\n workflowId: '',\n workflowName: '',\n })\n }}\n >\n {'Add variable'}\n </Button>\n </Stack>\n <Dialog\n open={Boolean(draft)}\n onClose={() => setDraft(null)}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>\n {draft?.id ? 'Edit Variable' : 'Add Variable'}\n </DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 2, pt: 1 }}\n >\n <TextField\n label=\"Name\"\n helperText={\n nameTaken\n ? 'A variable with this name already exists'\n : 'Used to identify the variable'\n }\n error={(Boolean(draft?.name) && !validName) || nameTaken}\n value={draft?.name ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? {\n ...prev,\n name: event.target.value.replace(\n /[^a-zA-Z0-9_]/g,\n '',\n ),\n }\n : prev,\n )\n }\n size=\"small\"\n autoFocus\n sx={{ mt: 1 }}\n />\n <TextField\n label=\"Type\"\n value={draft?.type ?? 'text'}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? {\n ...prev,\n type: event.target.value as HostVariableType,\n value: '',\n }\n : prev,\n )\n }\n size=\"small\"\n select\n >\n {Object.entries(HOST_VARIABLE_TYPE_LABELS).map(\n ([value, label]) => (\n <MenuItem key={value} value={value}>\n {label}\n </MenuItem>\n ),\n )}\n </TextField>\n {draft ? (\n <VariableValueField\n draft={draft}\n onChange={(value) =>\n setDraft((prev) => (prev ? { ...prev, value } : prev))\n }\n />\n ) : null}\n <TextField\n select\n label=\"Computed from workflow (optional)\"\n helperText={\n workflowOptionsTruncated\n ? `Showing ${WORKFLOW_OPTION_CEILING} workflows, ordered by ` +\n 'id. This site has more, so one of them is not offered here.'\n : 'Pick a workflow — its result becomes this ' +\n 'variable\\u2019s value at render; the value above is the ' +\n 'fallback (AGL-129)'\n }\n value={\n draft?.workflowId ||\n workflowOptions.find(\n (option) => option.name === draft?.workflowName,\n )?.id ||\n ''\n }\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? {\n ...prev,\n workflowId: event.target.value,\n workflowName:\n workflowOptions.find(\n (option) => option.id === event.target.value,\n )?.name ?? '',\n }\n : prev,\n )\n }\n size=\"small\"\n >\n <MenuItem value=\"\">{'None'}</MenuItem>\n {workflowOptions.map((option) => (\n <MenuItem key={option.id} value={option.id}>\n {option.name}\n </MenuItem>\n ))}\n </TextField>\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDraft(null)}>{'Cancel'}</Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!validName || nameTaken}\n onClick={handleSave}\n >\n {'Save variable'}\n </Button>\n </DialogActions>\n </Dialog>\n <WhereUsedDialog\n hostId={hostId}\n usage={usage}\n onClose={() => setUsage(null)}\n />\n </CardDisplay>\n )\n}\nHostVariablesCard.displayName = 'HostVariablesCard'\n\nexport default HostVariablesCard\n"],"names":["checkQuota","formatVariableValue","HOST_VARIABLE_TYPE_LABELS","pluginDocsHelp","VARIABLE_NAME_PATTERN","ceilingedWindow","collectionCeiling","pluginRecordListQuery","pluginRecordsFromRows","CardDisplay","useConfirmationContext","ListPagination","TABLE_PAGE_SIZE_DEFAULT","useSnackbar","Timestamp","Alert","Button","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","Stack","Switch","TextField","Typography","collection","doc","getCountFromServer","useCallback","useEffect","useMemo","useState","useFirestore","useFirestoreCollection","useHostResourceApi","useUser","writeGuardedBySeed","writeSiteWideChange","WhereUsedDialog","useConsoleWidgetSlot","HOST_LOGIC_ZONE","fetchWhereUsed","summarizeDependents","VARIABLE_CEILING","WORKFLOW_OPTION_CEILING","VariableValueField","props","draft","onChange","type","direction","spacing","sx","alignItems","checked","value","event","target","variant","label","size","slotProps","inputLabel","shrink","replace","placeholder","multiline","minRows","HostVariablesCard","workflowOptions","hostId","firestore","data","user","createHostResource","enqueueSnackbar","confirm","org","usage","setUsage","usageLoading","setUsageLoading","variableDocs","status","variablesStatus","fromCache","variablesFromCache","idField","rows","readVariables","truncated","variablesTruncated","setDraft","ExtensionZone","editorOpened","setEditorOpened","workflowDocs","limit","readWorkflows","workflowOptionsTruncated","map","workflow","id","name","sort","a","b","localeCompare","variables","filter","variable","deletedAt","String","page","setPage","pageSize","setPageSize","visibleVariables","slice","variableCountEpoch","setVariableCountEpoch","serverVariableCount","setServerVariableCount","active","then","snapshot","count","catch","variableCount","length","propose","proposal","kind","quota","allowed","persist","workflowId","workflowName","validName","test","nameTaken","Boolean","some","toLowerCase","trim","$id","handleSave","fields","verdict","subject","unreadable","write","batch","set","updatedAt","now","merge","ok","message","resource","epoch","error","console","allowDuplicate","handleShowUsage","result","handleDelete","scan","confirmed","title","description","total","confirmationText","confirmationButtonProps","color","update","header","help","anchor","actions","slot","orgId","contentGutterX","contentGutterY","flex","minWidth","noWrap","disabled","onClick","rowCount","onPageChange","onPageSizeChange","severity","alignSelf","open","onClose","maxWidth","fullWidth","display","flexDirection","gap","pt","helperText","prev","autoFocus","mt","select","Object","entries","find","option","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAEEA,UAAU,EACVC,mBAAmB,EACnBC,yBAAyB,EAGzBC,cAAc,EACdC,qBAAqB,QAChB,eAAc;AACrB;;;;;;CAMC,GACD,SACEC,eAAe,EACfC,iBAAiB,QACZ,+DAA8D;AACrE,SACEC,qBAAqB,EACrBC,qBAAqB,QAChB,kDAAiD;AACxD,SAASC,WAAW,EAAEC,sBAAsB,QAAQ,uBAAsB;AAC1E,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SAASC,uBAAuB,QAAQ,8CAA6C;AACrF,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,SAAS,QAAQ,+BAA8B;AACxD,SACEC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,UAAU,EAAEC,GAAG,EAAEC,kBAAkB,QAAQ,qBAAoB;AACxE,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EA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AG;AAEhC,eAAe/I,kBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/logic-console-page.tsx"],"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'use client'\n\nimport type { ConsolePluginPageProps } from '@aglyn/aglyn'\nimport { GridItems } from '@aglyn/shared-ui-jsx'\nimport HostFunctionsCard from './host-functions-card.component'\nimport HostReferenceHealthCard from './host-reference-health-card.component'\nimport HostVariablesCard from './host-variables-card.component'\n\n/**\n * Logic page (AGL-91/92 → AGL-395): variables + no-code functions and the\n * reference-integrity audit, owned by the logic plugin and rendered by the\n * shell's generic plugin route. The org doc (resolved by the shell)\n * flows into the variable/function cards for their per-plan quota checks.\n */\nexport function LogicConsolePage(props: ConsolePluginPageProps) {\n const { hostId, org } = props\n return (\n <GridItems\n masonry\n spacing={3}\n items={[\n {\n size: { xs: 12, md: 6 },\n children: <HostVariablesCard hostId={hostId} org={org} />,\n },\n {\n size: { xs: 12, md: 6 },\n children: <HostFunctionsCard hostId={hostId} org={org} />,\n },\n {\n // Broken-wiring audit (wave v7).\n size: { xs: 12 },\n children: <HostReferenceHealthCard hostId={hostId} />,\n },\n ]}\n />\n )\n}\nLogicConsolePage.displayName = 'LogicConsolePage'\n\nexport default LogicConsolePage\n"],"names":["GridItems","HostFunctionsCard","HostReferenceHealthCard","HostVariablesCard","LogicConsolePage","props","hostId","org","masonry","spacing","items","size","xs","md","children","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAGA,SAASA,SAAS,QAAQ,uBAAsB;AAChD,OAAOC,uBAAuB,qCAAiC;AAC/D,OAAOC,6BAA6B,4CAAwC;AAC5E,OAAOC,uBAAuB,qCAAiC;AAE/D;;;;;CAKC,GACD,OAAO,SAASC,iBAAiBC,KAA6B;IAC5D,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAE,GAAGF;IACxB,qBACE,KAACL;QACCQ,OAAO;QACPC,SAAS;QACTC,OAAO;YACL;gBACEC,MAAM;oBAAEC,IAAI;oBAAIC,IAAI;gBAAE;gBACtBC,wBAAU,KAACX;oBAAkBG,QAAQA;oBAAQC,KAAKA;;YACpD;YACA;gBACEI,MAAM;oBAAEC,IAAI;oBAAIC,IAAI;gBAAE;gBACtBC,wBAAU,KAACb;oBAAkBK,QAAQA;oBAAQC,KAAKA;;YACpD;YACA;gBACE,iCAAiC;gBACjCI,MAAM;oBAAEC,IAAI;gBAAG;gBACfE,wBAAU,KAACZ;oBAAwBI,QAAQA;;
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/logic-console-page.tsx"],"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'use client'\n\nimport type { ConsolePluginPageProps } from '@aglyn/aglyn'\nimport { GridItems } from '@aglyn/shared-ui-jsx'\nimport HostFunctionsCard from './host-functions-card.component'\nimport HostReferenceHealthCard from './host-reference-health-card.component'\nimport HostVariablesCard from './host-variables-card.component'\n\n/**\n * Logic page (AGL-91/92 → AGL-395): variables + no-code functions and the\n * reference-integrity audit, owned by the logic plugin and rendered by the\n * shell's generic plugin route. The org doc (resolved by the shell)\n * flows into the variable/function cards for their per-plan quota checks.\n */\nexport function LogicConsolePage(props: ConsolePluginPageProps) {\n const { hostId, org } = props\n return (\n <GridItems\n masonry\n spacing={3}\n items={[\n {\n size: { xs: 12, md: 6 },\n children: <HostVariablesCard hostId={hostId} org={org} />,\n },\n {\n size: { xs: 12, md: 6 },\n children: <HostFunctionsCard hostId={hostId} org={org} />,\n },\n {\n // Broken-wiring audit (wave v7).\n size: { xs: 12 },\n children: <HostReferenceHealthCard hostId={hostId} orgId={org?.$id} />,\n },\n ]}\n />\n )\n}\nLogicConsolePage.displayName = 'LogicConsolePage'\n\nexport default LogicConsolePage\n"],"names":["GridItems","HostFunctionsCard","HostReferenceHealthCard","HostVariablesCard","LogicConsolePage","props","hostId","org","masonry","spacing","items","size","xs","md","children","orgId","$id","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAGA,SAASA,SAAS,QAAQ,uBAAsB;AAChD,OAAOC,uBAAuB,qCAAiC;AAC/D,OAAOC,6BAA6B,4CAAwC;AAC5E,OAAOC,uBAAuB,qCAAiC;AAE/D;;;;;CAKC,GACD,OAAO,SAASC,iBAAiBC,KAA6B;IAC5D,MAAM,EAAEC,MAAM,EAAEC,GAAG,EAAE,GAAGF;IACxB,qBACE,KAACL;QACCQ,OAAO;QACPC,SAAS;QACTC,OAAO;YACL;gBACEC,MAAM;oBAAEC,IAAI;oBAAIC,IAAI;gBAAE;gBACtBC,wBAAU,KAACX;oBAAkBG,QAAQA;oBAAQC,KAAKA;;YACpD;YACA;gBACEI,MAAM;oBAAEC,IAAI;oBAAIC,IAAI;gBAAE;gBACtBC,wBAAU,KAACb;oBAAkBK,QAAQA;oBAAQC,KAAKA;;YACpD;YACA;gBACE,iCAAiC;gBACjCI,MAAM;oBAAEC,IAAI;gBAAG;gBACfE,wBAAU,KAACZ;oBAAwBI,QAAQA;oBAAQS,KAAK,EAAER,uBAAAA,IAAKS,GAAG;;YACpE;SACD;;AAGP;AACAZ,iBAAiBa,WAAW,GAAG;AAE/B,eAAeb,iBAAgB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import type { HostFunction, HostVariableType } from '@aglyn/aglyn';
|
|
18
|
+
import type { ReferenceIssue } from '../model/reference-audit';
|
|
19
|
+
/**
|
|
20
|
+
* What another plugin may put in front of the logic editors (AGL-3603): a
|
|
21
|
+
* function to open in the Functions editor, or a variable to open in the
|
|
22
|
+
* Variables editor. Either opens UNSAVED; the editor's own Save is the only
|
|
23
|
+
* write, and a person makes it, or does not.
|
|
24
|
+
*/
|
|
25
|
+
export type LogicProposal = {
|
|
26
|
+
kind: 'function';
|
|
27
|
+
/** The saved function the proposal changes, or `null` for a new one. */
|
|
28
|
+
functionId: string | null;
|
|
29
|
+
definition: HostFunction;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'variable';
|
|
32
|
+
variable: {
|
|
33
|
+
name: string;
|
|
34
|
+
type: HostVariableType;
|
|
35
|
+
value: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Beside Add function on the Functions card and Add variable on the
|
|
40
|
+
* Variables card: another way to start one. `kind` says which card the zone
|
|
41
|
+
* is drawn on; `propose` opens a proposal of that kind in the card's editor,
|
|
42
|
+
* unsaved, and answers `false` for one of the other kind or one the card
|
|
43
|
+
* cannot open (its plan cap reached, say).
|
|
44
|
+
*/
|
|
45
|
+
export interface HostLogicZoneProps {
|
|
46
|
+
hostId: string;
|
|
47
|
+
/** The org the page names; `undefined` while it resolves or where none is handed. */
|
|
48
|
+
orgId: string | undefined;
|
|
49
|
+
kind: 'function' | 'variable';
|
|
50
|
+
propose: (proposal: LogicProposal) => boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Inside the editor of one SAVED function. A widget here reads the function
|
|
54
|
+
* as it is stored; `propose` replaces what the editor holds with a changed
|
|
55
|
+
* definition, unsaved, which the editor's Save writes.
|
|
56
|
+
*/
|
|
57
|
+
export interface LogicFunctionEditorZoneProps {
|
|
58
|
+
hostId: string;
|
|
59
|
+
orgId: string | undefined;
|
|
60
|
+
/** The function the editor has open, as it is stored. */
|
|
61
|
+
target: {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
};
|
|
65
|
+
propose: (proposal: LogicProposal) => boolean;
|
|
66
|
+
}
|
|
67
|
+
/** One broken reference on the Reference health card. A widget here reads it and changes nothing. */
|
|
68
|
+
export interface LogicReferenceIssueZoneProps {
|
|
69
|
+
hostId: string;
|
|
70
|
+
orgId: string | undefined;
|
|
71
|
+
issue: ReferenceIssue;
|
|
72
|
+
}
|
|
73
|
+
export declare const HOST_LOGIC_ZONE: import("@aglyn/aglyn/plugin-manager/plugin-zones").PluginZone<HostLogicZoneProps>;
|
|
74
|
+
export declare const LOGIC_FUNCTION_EDITOR_ZONE: import("@aglyn/aglyn/plugin-manager/plugin-zones").PluginZone<LogicFunctionEditorZoneProps>;
|
|
75
|
+
export declare const LOGIC_REFERENCE_ISSUE_ZONE: import("@aglyn/aglyn/plugin-manager/plugin-zones").PluginZone<LogicReferenceIssueZoneProps>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ import { definePluginZone } from "@aglyn/aglyn/plugin-manager/plugin-zones";
|
|
17
|
+
export const HOST_LOGIC_ZONE = definePluginZone('hostLogic');
|
|
18
|
+
export const LOGIC_FUNCTION_EDITOR_ZONE = definePluginZone('logicFunctionEditor');
|
|
19
|
+
export const LOGIC_REFERENCE_ISSUE_ZONE = definePluginZone('logicReferenceIssue');
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=logic-zones.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/logic-zones.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 { HostFunction, HostVariableType } from '@aglyn/aglyn'\nimport { definePluginZone } from '@aglyn/aglyn/plugin-manager/plugin-zones'\nimport type { ReferenceIssue } from '../model/reference-audit'\n\n/**\n * What another plugin may put in front of the logic editors (AGL-3603): a\n * function to open in the Functions editor, or a variable to open in the\n * Variables editor. Either opens UNSAVED; the editor's own Save is the only\n * write, and a person makes it, or does not.\n */\nexport type LogicProposal =\n | {\n kind: 'function'\n /** The saved function the proposal changes, or `null` for a new one. */\n functionId: string | null\n definition: HostFunction\n }\n | {\n kind: 'variable'\n variable: { name: string; type: HostVariableType; value: string }\n }\n\n/**\n * Beside Add function on the Functions card and Add variable on the\n * Variables card: another way to start one. `kind` says which card the zone\n * is drawn on; `propose` opens a proposal of that kind in the card's editor,\n * unsaved, and answers `false` for one of the other kind or one the card\n * cannot open (its plan cap reached, say).\n */\nexport interface HostLogicZoneProps {\n hostId: string\n /** The org the page names; `undefined` while it resolves or where none is handed. */\n orgId: string | undefined\n kind: 'function' | 'variable'\n propose: (proposal: LogicProposal) => boolean\n}\n\n/**\n * Inside the editor of one SAVED function. A widget here reads the function\n * as it is stored; `propose` replaces what the editor holds with a changed\n * definition, unsaved, which the editor's Save writes.\n */\nexport interface LogicFunctionEditorZoneProps {\n hostId: string\n orgId: string | undefined\n /** The function the editor has open, as it is stored. */\n target: { id: string; name: string }\n propose: (proposal: LogicProposal) => boolean\n}\n\n/** One broken reference on the Reference health card. A widget here reads it and changes nothing. */\nexport interface LogicReferenceIssueZoneProps {\n hostId: string\n orgId: string | undefined\n issue: ReferenceIssue\n}\n\nexport const HOST_LOGIC_ZONE = definePluginZone<HostLogicZoneProps>('hostLogic')\n\nexport const LOGIC_FUNCTION_EDITOR_ZONE =\n definePluginZone<LogicFunctionEditorZoneProps>('logicFunctionEditor')\n\nexport const LOGIC_REFERENCE_ISSUE_ZONE =\n definePluginZone<LogicReferenceIssueZoneProps>('logicReferenceIssue')\n"],"names":["definePluginZone","HOST_LOGIC_ZONE","LOGIC_FUNCTION_EDITOR_ZONE","LOGIC_REFERENCE_ISSUE_ZONE"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAGD,SAASA,gBAAgB,QAAQ,2CAA0C;AAwD3E,OAAO,MAAMC,kBAAkBD,iBAAqC,aAAY;AAEhF,OAAO,MAAME,6BACXF,iBAA+C,uBAAsB;AAEvE,OAAO,MAAMG,6BACXH,iBAA+C,uBAAsB"}
|
package/src/lib/plugin.d.ts
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* also drawn in the zone the Automation page hosts for a workflow's usage.
|
|
24
24
|
*/
|
|
25
25
|
export declare function registerLogicConsole(): void;
|
|
26
|
+
export type { HostLogicZoneProps, LogicFunctionEditorZoneProps, LogicProposal, LogicReferenceIssueZoneProps, } from './components/logic-zones';
|
|
26
27
|
export { default as HostVariablesCard } from './components/host-variables-card.component';
|
|
27
28
|
export type { HostVariablesCardProps } from './components/host-variables-card.component';
|
|
28
29
|
export { default as HostFunctionsCard } from './components/host-functions-card.component';
|
package/src/lib/plugin.js
CHANGED
|
@@ -19,6 +19,8 @@ import { lazy } from "react";
|
|
|
19
19
|
import HostFunctionsCard from "./components/host-functions-card.component.js";
|
|
20
20
|
import HostVariablesCard from "./components/host-variables-card.component.js";
|
|
21
21
|
import { BUNDLE_ID } from "./constants/bundle-common.js";
|
|
22
|
+
import { registerPluginZone } from "@aglyn/aglyn/plugin-manager/plugin-zones";
|
|
23
|
+
import { HOST_LOGIC_ZONE, LOGIC_FUNCTION_EDITOR_ZONE, LOGIC_REFERENCE_ISSUE_ZONE } from "./components/logic-zones.js";
|
|
22
24
|
/** Code-split: the Logic console page only loads when opened. */ const LogicConsolePage = lazy(()=>import("./components/logic-console-page.js"));
|
|
23
25
|
/** The dependents dialog, loaded where the Automation page draws its zone. */ const WhereUsedDialog = lazy(()=>import("./components/where-used-dialog.component.js"));
|
|
24
26
|
/**
|
|
@@ -29,6 +31,36 @@ import { BUNDLE_ID } from "./constants/bundle-common.js";
|
|
|
29
31
|
* (always-on; the surface is not release-flagged). Its dependents dialog is
|
|
30
32
|
* also drawn in the zone the Automation page hosts for a workflow's usage.
|
|
31
33
|
*/ export function registerLogicConsole() {
|
|
34
|
+
// The zones the Functions & Variables page draws in its own layouts
|
|
35
|
+
// (AGL-3603): one control in each card's header, one inside a saved
|
|
36
|
+
// function's editor, one on each broken reference.
|
|
37
|
+
registerPluginZone({
|
|
38
|
+
zone: HOST_LOGIC_ZONE,
|
|
39
|
+
label: 'Functions & Variables actions',
|
|
40
|
+
surface: 'console',
|
|
41
|
+
layout: 'bare',
|
|
42
|
+
description: 'In the header of the Functions card and of the Variables card: another way to start one. `kind` names the card; `propose` opens a proposal of that kind in the card’s editor, unsaved, and answers `false` when it cannot. A widget here writes nothing.'
|
|
43
|
+
}, {
|
|
44
|
+
pluginId: BUNDLE_ID
|
|
45
|
+
});
|
|
46
|
+
registerPluginZone({
|
|
47
|
+
zone: LOGIC_FUNCTION_EDITOR_ZONE,
|
|
48
|
+
label: 'A function’s editor',
|
|
49
|
+
surface: 'console',
|
|
50
|
+
layout: 'bare',
|
|
51
|
+
description: 'Inside the editor of one saved function. A widget here reads the function as it is stored; `propose` replaces what the editor holds, unsaved, and the editor’s Save is the only write.'
|
|
52
|
+
}, {
|
|
53
|
+
pluginId: BUNDLE_ID
|
|
54
|
+
});
|
|
55
|
+
registerPluginZone({
|
|
56
|
+
zone: LOGIC_REFERENCE_ISSUE_ZONE,
|
|
57
|
+
label: 'A broken reference',
|
|
58
|
+
surface: 'console',
|
|
59
|
+
layout: 'bare',
|
|
60
|
+
description: 'On each broken reference the Reference health card lists. A widget here reads the issue — what holds the reference, and what it points at that is gone — and changes nothing.'
|
|
61
|
+
}, {
|
|
62
|
+
pluginId: BUNDLE_ID
|
|
63
|
+
});
|
|
32
64
|
Aglyn.registerConsoleExtension({
|
|
33
65
|
// Variables/functions cards (AGL-419): the besigner functions
|
|
34
66
|
// drawer renders them through the 'besignerFunctions' slot.
|