@aglyn/plugins-logic 1.0.0-beta.217 → 1.0.0-beta.219
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/README.md +5 -3
- package/package.json +8 -7
- package/src/lib/components/host-variables-card.component.js +1 -1
- package/src/lib/components/host-variables-card.component.js.map +1 -1
- package/src/lib/components/where-used-dialog.component.js +3 -3
- package/src/lib/components/where-used-dialog.component.js.map +1 -1
- package/src/lib/declarations.server.d.ts +25 -0
- package/src/lib/declarations.server.js +36 -0
- package/src/lib/declarations.server.js.map +1 -0
- package/src/lib/model/reference-audit.d.ts +13 -4
- package/src/lib/model/reference-audit.js.map +1 -1
- package/src/lib/server/variable-dependents.d.ts +31 -0
- package/src/lib/server/variable-dependents.js +60 -0
- package/src/lib/server/variable-dependents.js.map +1 -0
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Peer dependencies: `react`, `@mui/material`, `firebase`.
|
|
|
12
12
|
|
|
13
13
|
## What's in it
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Variables and functions resolve when a page renders, through the tenant runtime's compose pipeline, so the plugin adds no element to a published site and registers no API route.
|
|
16
16
|
|
|
17
17
|
**Console** (`registerLogicConsole`, the `console` registrar in `plugins.config.json`):
|
|
18
18
|
|
|
@@ -20,11 +20,13 @@ The plugin is console-only. Variables and functions resolve when a page renders,
|
|
|
20
20
|
- Two widgets in the `besignerFunctions` slot, the variables card and the functions card, which the Besigner's functions drawer draws.
|
|
21
21
|
- A widget in the `workflowUsage` slot: the "where used" dialog, drawn in the zone the Automation page hosts for one workflow's dependents.
|
|
22
22
|
|
|
23
|
+
**Server declarations** (`registerLogicServerDeclarations`, the `serverDeclarations` registrar): a dependents source on the core's `plugin-dependents` seam, which answers the platform's "Used by" scan with the variables computed from a workflow. The workflows plugin asks that scan before a workflow is renamed or deleted, and neither plugin imports the other. The reader loads with the first question.
|
|
24
|
+
|
|
23
25
|
**Exports from `.`**
|
|
24
26
|
|
|
25
27
|
- `registerLogicConsole` and `BUNDLE_ID` (`'logic'`).
|
|
26
28
|
- `HostVariablesCard`, `HostFunctionsCard` and their props types, for an app that opens the cards itself.
|
|
27
|
-
- `auditHostReferences` with `ReferenceIssue`, `ReferenceAuditInput` and `ScreenAuditEntry`: a pure check of every reference an action, workflow, computed variable or screen holds against the ids and names that still exist.
|
|
29
|
+
- `auditHostReferences` with `ReferenceIssue`, `ReferenceAuditInput`, `AuditedWorkflow` and `ScreenAuditEntry`: a pure check of every reference an action, workflow, computed variable or screen holds against the ids and names that still exist.
|
|
28
30
|
- `parseParameterOptions` and `formatParameterOptions`: a function parameter's choice list as one line of text. The grammar itself lives in `@aglyn/aglyn`; these are the function builder's names for it.
|
|
29
31
|
|
|
30
32
|
## Usage
|
|
@@ -45,7 +47,7 @@ import { auditHostReferences, type ReferenceIssue } from '@aglyn/plugins-logic'
|
|
|
45
47
|
|
|
46
48
|
## How it fits
|
|
47
49
|
|
|
48
|
-
A plugin package (`scope:plugin`). It depends on the core (`@aglyn/aglyn`), the tenant client hooks (`@aglyn/tenant-feature-instance`) and generic `@aglyn/shared-*` packages. It imports no other plugin: what it shares with the workflows plugin goes through a core seam and a console zone. The core never imports it; the console reaches it only through the loader manifest and the slots it fills.
|
|
50
|
+
A plugin package (`scope:plugin`). It depends on the core (`@aglyn/aglyn`), the tenant client hooks (`@aglyn/tenant-feature-instance`), the tenant data layer's Admin SDK for its dependents source (`@aglyn/tenant-data-admin`) and generic `@aglyn/shared-*` packages. It imports no other plugin: what it shares with the workflows plugin goes through a core seam and a console zone. The core never imports it; the console reaches it only through the loader manifest and the slots it fills.
|
|
49
51
|
|
|
50
52
|
## License
|
|
51
53
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-logic",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.219",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,12 +25,13 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-data-mdi": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-ui-jsx": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-ui-snackstack": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-util-timestamp": "1.0.0-beta.
|
|
33
|
-
"@aglyn/tenant-
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.219",
|
|
29
|
+
"@aglyn/shared-data-mdi": "1.0.0-beta.219",
|
|
30
|
+
"@aglyn/shared-ui-jsx": "1.0.0-beta.219",
|
|
31
|
+
"@aglyn/shared-ui-snackstack": "1.0.0-beta.219",
|
|
32
|
+
"@aglyn/shared-util-timestamp": "1.0.0-beta.219",
|
|
33
|
+
"@aglyn/tenant-data-admin": "1.0.0-beta.219",
|
|
34
|
+
"@aglyn/tenant-feature-instance": "1.0.0-beta.219",
|
|
34
35
|
"@swc/helpers": "0.5.23"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
@@ -390,7 +390,7 @@ import { fetchWhereUsed, summarizeDependents } from "@aglyn/aglyn/app-utils/wher
|
|
|
390
390
|
});
|
|
391
391
|
const confirmed = await confirm({
|
|
392
392
|
title: 'Delete this variable?',
|
|
393
|
-
description: scan.total ? `"${variable.name}" is used in ${summarizeDependents(scan)}. ` + 'Those bindings will render as empty or literal tokens after ' + 'the next publish.' : `"${variable.name}" is not referenced by any published ` + '
|
|
393
|
+
description: scan.total ? `"${variable.name}" is used in ${summarizeDependents(scan)}. ` + 'Those bindings will render as empty or literal tokens after ' + 'the next publish.' : `"${variable.name}" is not referenced by any published ` + 'page, layout, or workflow.',
|
|
394
394
|
confirmationText: 'Delete',
|
|
395
395
|
confirmationButtonProps: {
|
|
396
396
|
color: 'error'
|
|
@@ -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 { 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.\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 ? collectionCeiling(\n collection(firestore, 'hosts', hostId, 'workflows'),\n WORKFLOW_OPTION_CEILING,\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.\n const workflowOptions = readWorkflows\n .filter((workflow: any) => !workflow.deletedAt && workflow.name)\n .map((workflow: any) => ({\n id: workflow.$id as string,\n name: workflow.name as string,\n }))\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 'screen, 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","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","readWorkflows","workflowOptionsTruncated","filter","workflow","deletedAt","name","map","id","$id","sort","a","b","localeCompare","variables","variable","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","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","limit","open","onClose","maxWidth","fullWidth","display","flexDirection","gap","pt","helperText","prev","autoFocus","mt","select","Object","entries","find","option","displ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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 { 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.\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 ? collectionCeiling(\n collection(firestore, 'hosts', hostId, 'workflows'),\n WORKFLOW_OPTION_CEILING,\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.\n const workflowOptions = readWorkflows\n .filter((workflow: any) => !workflow.deletedAt && workflow.name)\n .map((workflow: any) => ({\n id: workflow.$id as string,\n name: workflow.name as string,\n }))\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","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","readWorkflows","workflowOptionsTruncated","filter","workflow","deletedAt","name","map","id","$id","sort","a","b","localeCompare","variables","variable","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","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","limit","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,yB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6CAAU8I;iCAGlD;0CACJ,MAAC5K;gCACC+K,MAAM;gCACN7I,OAAM;gCACNyI,YACEnG,2BACI,CAAC,QAAQ,EAAErD,wBAAwB,uBAAuB,CAAC,GAC3D,gEACA,+CACA,6DACA;gCAENW,OACER,CAAAA,yBAAAA,MAAO2F,UAAU,OACjBrE,wBAAAA,gBAAgBsI,IAAI,CAClB,CAACC,SAAWA,OAAOvG,IAAI,MAAKtD,yBAAAA,MAAO4F,YAAY,uBADjDtE,sBAEGkC,EAAE,KACL;gCAEFvD,UAAU,CAACQ,QACToC,SAAS,CAACyG;;4CAMAhI;+CALRgI,OACI,aACKA;4CACH3D,YAAYlF,MAAMC,MAAM,CAACF,KAAK;4CAC9BoF,YAAY,WACVtE,wBAAAA,gBAAgBsI,IAAI,CAClB,CAACC,SAAWA,OAAOrG,EAAE,KAAK/C,MAAMC,MAAM,CAACF,KAAK,sBAD9Cc,sBAEGgC,IAAI,mBAAI;6CAEfgG;;gCAGRzI,MAAK;;kDAEL,KAACtC;wCAASiC,OAAM;kDAAI;;oCACnBc,gBAAgBiC,GAAG,CAAC,CAACsG,uBACpB,KAACtL;4CAAyBiC,OAAOqJ,OAAOrG,EAAE;sDACvCqG,OAAOvG,IAAI;2CADCuG,OAAOrG,EAAE;;;;;kCAM9B,MAACpF;;0CACC,KAACF;gCAAOkK,SAAS,IAAMvF,SAAS;0CAAQ;;0CACxC,KAAC3E;gCACCyC,SAAQ;gCACR8G,OAAM;gCACNU,UAAU,CAACjD,aAAaE;gCACxBgD,SAAS3C;0CAER;;;;;;0BAIP,KAAChG;gBACC8B,QAAQA;gBACRQ,OAAOA;gBACP+G,SAAS,IAAM9G,SAAS;;;;AAIhC;AACAX,kBAAkByI,WAAW,GAAG;AAEhC,eAAezI,kBAAiB"}
|
|
@@ -47,7 +47,7 @@ const layoutBesignerHref = (hostId, layoutId, versionId)=>`${hostId}/layouts/${l
|
|
|
47
47
|
children: (usage == null ? void 0 : usage.result.total) === 0 ? /*#__PURE__*/ _jsx(Typography, {
|
|
48
48
|
variant: "body2",
|
|
49
49
|
color: "text.secondary",
|
|
50
|
-
children: 'Not referenced by any published
|
|
50
|
+
children: 'Not referenced by any published page, layout, or workflow. ' + 'Unpublished drafts are not scanned.'
|
|
51
51
|
}) : /*#__PURE__*/ _jsxs(Stack, {
|
|
52
52
|
spacing: 1,
|
|
53
53
|
children: [
|
|
@@ -75,7 +75,7 @@ const layoutBesignerHref = (hostId, layoutId, versionId)=>`${hostId}/layouts/${l
|
|
|
75
75
|
/*#__PURE__*/ _jsx(Typography, {
|
|
76
76
|
variant: "caption",
|
|
77
77
|
color: "text.secondary",
|
|
78
|
-
children: dependent.type + (dependent.via.includes('name') ? ' · legacy token' : '')
|
|
78
|
+
children: (dependent.type === 'screen' ? 'page' : dependent.type) + (dependent.via.includes('name') ? ' · legacy token' : '')
|
|
79
79
|
})
|
|
80
80
|
]
|
|
81
81
|
}, `${dependent.type}-${dependent.id}`);
|
|
@@ -83,7 +83,7 @@ const layoutBesignerHref = (hostId, layoutId, versionId)=>`${hostId}/layouts/${l
|
|
|
83
83
|
(usage == null ? void 0 : usage.result.legacyCount) ? /*#__PURE__*/ _jsx(Typography, {
|
|
84
84
|
variant: "caption",
|
|
85
85
|
color: "warning.main",
|
|
86
|
-
children: 'Legacy tokens reference this by name and break if it is ' + 'renamed — re-publish those
|
|
86
|
+
children: 'Legacy tokens reference this by name and break if it is ' + 'renamed — re-publish those pages to upgrade them.'
|
|
87
87
|
}) : null
|
|
88
88
|
]
|
|
89
89
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/where-used-dialog.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 Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Stack,\n Typography,\n} from '@mui/material'\nimport { AppLink } from '@aglyn/shared-ui-jsx'\nimport { useConsoleHostRoute } from '@aglyn/tenant-feature-instance'\nimport type { WhereUsedResult } from '@aglyn/aglyn/app-utils/where-used'\n\n/**\n * Besigner deep-links for a scanned screen/layout version. The routes live\n * in the console app's table; the patterns are stable, so the plugin builds\n * them directly rather than importing app-only route constants.\n */\nconst screenBesignerHref = (\n // Console route base, not a host doc id (AGL-673).\n hostId: string,\n screenId: string,\n versionId: string,\n) => `${hostId}/screens/${screenId}/versions/${versionId}/besigner`\nconst layoutBesignerHref = (\n hostId: string,\n layoutId: string,\n versionId: string,\n) => `${hostId}/layouts/${layoutId}/versions/${versionId}/besigner`\n\nexport interface WhereUsedDialogProps {\n hostId: string\n usage: { name: string; result: WhereUsedResult } | null\n onClose: () => void\n}\n\n/**\n * Shared dependents dialog (AGL-187/193): where a variable, function, or\n * workflow is referenced — screen/layout rows deep-link into the besigner\n * of the scanned published version; legacy-token references are flagged\n * since renames break them.\n */\nexport function WhereUsedDialog(props: WhereUsedDialogProps) {\n const { hostId, usage, onClose } = props\n const consoleRoute = useConsoleHostRoute(hostId)\n const base = consoleRoute.base\n return (\n <Dialog open={Boolean(usage)} onClose={onClose} maxWidth=\"xs\" fullWidth>\n <DialogTitle>{`Where \"${usage?.name}\" is used`}</DialogTitle>\n <DialogContent>\n {usage?.result.total === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Not referenced by any published
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/components/where-used-dialog.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 Button,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Stack,\n Typography,\n} from '@mui/material'\nimport { AppLink } from '@aglyn/shared-ui-jsx'\nimport { useConsoleHostRoute } from '@aglyn/tenant-feature-instance'\nimport type { WhereUsedResult } from '@aglyn/aglyn/app-utils/where-used'\n\n/**\n * Besigner deep-links for a scanned screen/layout version. The routes live\n * in the console app's table; the patterns are stable, so the plugin builds\n * them directly rather than importing app-only route constants.\n */\nconst screenBesignerHref = (\n // Console route base, not a host doc id (AGL-673).\n hostId: string,\n screenId: string,\n versionId: string,\n) => `${hostId}/screens/${screenId}/versions/${versionId}/besigner`\nconst layoutBesignerHref = (\n hostId: string,\n layoutId: string,\n versionId: string,\n) => `${hostId}/layouts/${layoutId}/versions/${versionId}/besigner`\n\nexport interface WhereUsedDialogProps {\n hostId: string\n usage: { name: string; result: WhereUsedResult } | null\n onClose: () => void\n}\n\n/**\n * Shared dependents dialog (AGL-187/193): where a variable, function, or\n * workflow is referenced — screen/layout rows deep-link into the besigner\n * of the scanned published version; legacy-token references are flagged\n * since renames break them.\n */\nexport function WhereUsedDialog(props: WhereUsedDialogProps) {\n const { hostId, usage, onClose } = props\n const consoleRoute = useConsoleHostRoute(hostId)\n const base = consoleRoute.base\n return (\n <Dialog open={Boolean(usage)} onClose={onClose} maxWidth=\"xs\" fullWidth>\n <DialogTitle>{`Where \"${usage?.name}\" is used`}</DialogTitle>\n <DialogContent>\n {usage?.result.total === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Not referenced by any published page, layout, or workflow. ' +\n 'Unpublished drafts are not scanned.'}\n </Typography>\n ) : (\n <Stack spacing={1}>\n {usage?.result.dependents.map((dependent) => {\n // No resolved base means no valid link — the branch below\n // already renders plain text, which beats a link to nowhere.\n const href =\n base && dependent.versionId && dependent.type === 'screen'\n ? screenBesignerHref(base, dependent.id, dependent.versionId)\n : base && dependent.versionId && dependent.type === 'layout'\n ? layoutBesignerHref(base, dependent.id, dependent.versionId)\n : null\n return (\n <Stack\n key={`${dependent.type}-${dependent.id}`}\n direction=\"row\"\n spacing={1}\n sx={{ justifyContent: 'space-between' }}\n >\n {href ? (\n <AppLink href={href} variant=\"body2\" noWrap>\n {dependent.name}\n </AppLink>\n ) : (\n <Typography variant=\"body2\" noWrap>\n {dependent.name}\n </Typography>\n )}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {/* The stored type stays `screen`; a person reads \"page\". */}\n {(dependent.type === 'screen' ? 'page' : dependent.type) +\n (dependent.via.includes('name') ? ' · legacy token' : '')}\n </Typography>\n </Stack>\n )\n })}\n {usage?.result.legacyCount ? (\n <Typography variant=\"caption\" color=\"warning.main\">\n {'Legacy tokens reference this by name and break if it is ' +\n 'renamed — re-publish those pages to upgrade them.'}\n </Typography>\n ) : null}\n </Stack>\n )}\n </DialogContent>\n <DialogActions>\n <Button onClick={onClose}>{'Close'}</Button>\n </DialogActions>\n </Dialog>\n )\n}\nWhereUsedDialog.displayName = 'WhereUsedDialog'\n\nexport default WhereUsedDialog\n"],"names":["Button","Dialog","DialogActions","DialogContent","DialogTitle","Stack","Typography","AppLink","useConsoleHostRoute","screenBesignerHref","hostId","screenId","versionId","layoutBesignerHref","layoutId","WhereUsedDialog","props","usage","onClose","consoleRoute","base","open","Boolean","maxWidth","fullWidth","name","result","total","variant","color","spacing","dependents","map","dependent","href","type","id","direction","sx","justifyContent","noWrap","via","includes","legacyCount","onClick","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SACEA,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,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D;4BACR,qBACE,MAACP;gCAECgC,WAAU;gCACVP,SAAS;gCACTQ,IAAI;oCAAEC,gBAAgB;gCAAgB;;oCAErCL,qBACC,KAAC3B;wCAAQ2B,MAAMA;wCAAMN,SAAQ;wCAAQY,MAAM;kDACxCP,UAAUR,IAAI;uDAGjB,KAACnB;wCAAWsB,SAAQ;wCAAQY,MAAM;kDAC/BP,UAAUR,IAAI;;kDAGnB,KAACnB;wCAAWsB,SAAQ;wCAAUC,OAAM;kDAEjC,AAACI,CAAAA,UAAUE,IAAI,KAAK,WAAW,SAASF,UAAUE,IAAI,AAAD,IACnDF,CAAAA,UAAUQ,GAAG,CAACC,QAAQ,CAAC,UAAU,oBAAoB,EAAC;;;+BAjBtD,GAAGT,UAAUE,IAAI,CAAC,CAAC,EAAEF,UAAUG,EAAE,EAAE;wBAqB9C;wBACCnB,CAAAA,yBAAAA,MAAOS,MAAM,CAACiB,WAAW,kBACxB,KAACrC;4BAAWsB,SAAQ;4BAAUC,OAAM;sCACjC,6DACC;6BAEF;;;;0BAIV,KAAC3B;0BACC,cAAA,KAACF;oBAAO4C,SAAS1B;8BAAU;;;;;AAInC;AACAH,gBAAgB8B,WAAW,GAAG;AAE9B,eAAe9B,gBAAe"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* The plugin's SERVER declarations: what a server process must know before
|
|
19
|
+
* any surface of the plugin loads.
|
|
20
|
+
*
|
|
21
|
+
* The variables computed from a workflow, which the "Used by" scan asks for
|
|
22
|
+
* when somebody is about to rename or delete one. The reader and the Admin
|
|
23
|
+
* SDK arrive with the first question, not with the boot.
|
|
24
|
+
*/
|
|
25
|
+
export declare function registerLogicServerDeclarations(): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { registerPluginDependentsSource } from "@aglyn/aglyn/plugin-manager/plugin-dependents";
|
|
17
|
+
import { BUNDLE_ID } from "./constants/bundle-common.js";
|
|
18
|
+
/**
|
|
19
|
+
* The plugin's SERVER declarations: what a server process must know before
|
|
20
|
+
* any surface of the plugin loads.
|
|
21
|
+
*
|
|
22
|
+
* The variables computed from a workflow, which the "Used by" scan asks for
|
|
23
|
+
* when somebody is about to rename or delete one. The reader and the Admin
|
|
24
|
+
* SDK arrive with the first question, not with the boot.
|
|
25
|
+
*/ export function registerLogicServerDeclarations() {
|
|
26
|
+
registerPluginDependentsSource({
|
|
27
|
+
kinds: [
|
|
28
|
+
'workflow'
|
|
29
|
+
],
|
|
30
|
+
find: async (request)=>(await import("./server/variable-dependents.js")).findWorkflowDependents(request)
|
|
31
|
+
}, {
|
|
32
|
+
pluginId: BUNDLE_ID
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=declarations.server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/plugins/logic/src/lib/declarations.server.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 { registerPluginDependentsSource } from '@aglyn/aglyn/plugin-manager/plugin-dependents'\nimport { BUNDLE_ID } from './constants/bundle-common'\n\n/**\n * The plugin's SERVER declarations: what a server process must know before\n * any surface of the plugin loads.\n *\n * The variables computed from a workflow, which the \"Used by\" scan asks for\n * when somebody is about to rename or delete one. The reader and the Admin\n * SDK arrive with the first question, not with the boot.\n */\nexport function registerLogicServerDeclarations(): void {\n registerPluginDependentsSource(\n {\n kinds: ['workflow'],\n find: async (request) =>\n (await import('./server/variable-dependents')).findWorkflowDependents(request),\n },\n { pluginId: BUNDLE_ID },\n )\n}\n"],"names":["registerPluginDependentsSource","BUNDLE_ID","registerLogicServerDeclarations","kinds","find","request","findWorkflowDependents","pluginId"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAASA,8BAA8B,QAAQ,gDAA+C;AAC9F,SAASC,SAAS,QAAQ,+BAA2B;AAErD;;;;;;;CAOC,GACD,OAAO,SAASC;IACdF,+BACE;QACEG,OAAO;YAAC;SAAW;QACnBC,MAAM,OAAOC,UACX,AAAC,CAAA,MAAM,MAAM,CAAC,kCAA8B,EAAGC,sBAAsB,CAACD;IAC1E,GACA;QAAEE,UAAUN;IAAU;AAE1B"}
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import type { HostAction } from '@aglyn/aglyn';
|
|
18
18
|
import type { HostVariable } from '@aglyn/aglyn';
|
|
19
|
-
import type { HostWorkflow } from '@aglyn/aglyn';
|
|
20
19
|
/**
|
|
21
20
|
* Reference-integrity audit (wave v7): id references (AGL-261) are
|
|
22
21
|
* rename-safe but not delete-safe — deleting a workflow leaves actions
|
|
@@ -44,13 +43,23 @@ export interface ScreenAuditEntry {
|
|
|
44
43
|
props?: Record<string, unknown>;
|
|
45
44
|
} | undefined>;
|
|
46
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* A stored workflow, as far as the audit reads one: its name and the function
|
|
48
|
+
* each step calls, by id and by the name it had when the step was written.
|
|
49
|
+
*/
|
|
50
|
+
export interface AuditedWorkflow {
|
|
51
|
+
$id: string;
|
|
52
|
+
name?: string;
|
|
53
|
+
steps?: Array<{
|
|
54
|
+
functionId?: string;
|
|
55
|
+
functionName?: string;
|
|
56
|
+
}>;
|
|
57
|
+
}
|
|
47
58
|
export interface ReferenceAuditInput {
|
|
48
59
|
actions?: Array<HostAction & {
|
|
49
60
|
$id: string;
|
|
50
61
|
}>;
|
|
51
|
-
workflows?:
|
|
52
|
-
$id: string;
|
|
53
|
-
}>;
|
|
62
|
+
workflows?: AuditedWorkflow[];
|
|
54
63
|
variables?: Array<HostVariable & {
|
|
55
64
|
$id: string;
|
|
56
65
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/model/reference-audit.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 { HostAction } from '@aglyn/aglyn'\nimport type { HostVariable } from '@aglyn/aglyn'\nimport type { HostWorkflow } from '@aglyn/aglyn'\n\n/**\n * Reference-integrity audit (wave v7): id references (AGL-261) are\n * rename-safe but not delete-safe — deleting a workflow leaves actions\n * pointing at nothing, and the executors fail silently at run time.\n * This pure audit cross-checks every reference an automation, workflow,\n * or computed variable holds against the ids/names that still exist,\n * so the console can surface broken wiring before a visitor hits it.\n */\nexport interface ReferenceIssue {\n /** What holds the broken reference. */\n source: 'action' | 'workflow' | 'variable' | 'screen'\n sourceId: string\n /** Display name of the holder. */\n sourceName: string\n /** What the reference points at (\"workflow\", \"dataset\", …). */\n refType: string\n /** The dangling id or name as stored. */\n missing: string\n}\n\n/** A screen's composed nodes, for canvas-reference auditing (AGL-345). */\nexport interface ScreenAuditEntry {\n $id: string\n name?: string\n nodes: Record<string, { props?: Record<string, unknown> } | undefined>\n}\n\nexport interface ReferenceAuditInput {\n actions?: Array<HostAction & { $id: string }>\n workflows?: Array<HostWorkflow & { $id: string }>\n variables?: Array<HostVariable & { $id: string }>\n /** Screen node maps to scan for entity/screen-link references. */\n screens?: ScreenAuditEntry[]\n /** Known-good targets: doc ids AND display names both resolve. */\n known: {\n workflows?: Set<string>\n functions?: Set<string>\n datasets?: Set<string>\n lists?: Set<string>\n campaigns?: Set<string>\n overlays?: Set<string>\n webhooks?: Set<string>\n /** New reference kinds (AGL-345). */\n screens?: Set<string>\n products?: Set<string>\n collections?: Set<string>\n categories?: Set<string>\n }\n}\n\nconst resolves = (\n known: Set<string> | undefined,\n id?: string,\n name?: string,\n): boolean => {\n const cleanId = id?.trim()\n const cleanName = name?.trim()\n if (!cleanId && !cleanName) return true // Nothing referenced.\n if (!known) return true // Target kind not loaded — don't cry wolf.\n return Boolean(\n (cleanId && known.has(cleanId)) || (cleanName && known.has(cleanName)),\n )\n}\n\nexport function auditHostReferences(\n input: ReferenceAuditInput,\n): ReferenceIssue[] {\n const issues: ReferenceIssue[] = []\n const { known } = input\n\n for (const action of input.actions ?? []) {\n const push = (refType: string, missing: string) =>\n issues.push({\n source: 'action',\n sourceId: action.$id,\n sourceName: action.name ?? action.$id,\n refType,\n missing,\n })\n for (const step of action.steps ?? []) {\n if (step.type === 'runWorkflow') {\n if (!resolves(known.workflows, step.workflowId, step.workflowName)) {\n push('workflow', step.workflowId || step.workflowName || '')\n }\n } else if (\n step.type === 'datasetAppend' ||\n step.type === 'updateDataset'\n ) {\n if (!resolves(known.datasets, step.datasetId, step.datasetName)) {\n push('dataset', step.datasetId || step.datasetName || '')\n }\n } else if (step.type === 'enrollList') {\n if (!resolves(known.lists, step.listId, step.listName)) {\n push('list', step.listId || step.listName || '')\n }\n } else if (step.type === 'assignCampaign') {\n if (!resolves(known.campaigns, step.campaignId, step.campaignName)) {\n push('campaign', step.campaignId || step.campaignName || '')\n }\n } else if (step.type === 'showOverlay') {\n if (!resolves(known.overlays, step.overlayId, step.overlayName)) {\n push('overlay', step.overlayId || step.overlayName || '')\n }\n } else if (step.type === 'webhookPost') {\n if (!resolves(known.webhooks, step.webhookId, step.webhookName)) {\n push('webhook', step.webhookId || step.webhookName || '')\n }\n } else if (step.type === 'redirect') {\n // Screen-id redirects (AGL-339) go stale when the screen is\n // deleted/unpublished.\n if (!resolves(known.screens, (step as any).screenId)) {\n push('screen', (step as any).screenId || '')\n }\n }\n }\n }\n\n for (const workflow of input.workflows ?? []) {\n for (const step of workflow.steps ?? []) {\n if (!resolves(known.functions, step.functionId, step.functionName)) {\n issues.push({\n source: 'workflow',\n sourceId: workflow.$id,\n sourceName: workflow.name ?? workflow.$id,\n refType: 'function',\n missing: step.functionId || step.functionName || '',\n })\n }\n }\n }\n\n for (const variable of input.variables ?? []) {\n if (!resolves(known.workflows, variable.workflowId, variable.workflowName)) {\n issues.push({\n source: 'variable',\n sourceId: variable.$id,\n sourceName: variable.name ?? variable.$id,\n refType: 'workflow',\n missing: variable.workflowId || variable.workflowName || '',\n })\n }\n }\n\n // Canvas node references (AGL-345): screen links, commerce entities,\n // and repeat datasets persisted in component props.\n const NODE_PROP_TARGETS: Array<{\n prop: string\n refType: string\n known: Set<string> | undefined\n }> = [\n { prop: 'screenId', refType: 'screen', known: known.screens },\n { prop: 'productId', refType: 'product', known: known.products },\n { prop: 'collectionId', refType: 'collection', known: known.collections },\n { prop: 'categoryId', refType: 'category', known: known.categories },\n { prop: 'repeatDataset', refType: 'dataset', known: known.datasets },\n ]\n for (const screen of input.screens ?? []) {\n for (const node of Object.values(screen.nodes ?? {})) {\n const props = node?.props ?? {}\n for (const target of NODE_PROP_TARGETS) {\n const value = props[target.prop]\n if (typeof value !== 'string' || !value.trim()) continue\n if (!resolves(target.known, value)) {\n issues.push({\n source: 'screen',\n sourceId: screen.$id,\n sourceName: screen.name ?? screen.$id,\n refType: target.refType,\n missing: value,\n })\n }\n }\n }\n }\n\n return issues\n}\n"],"names":["resolves","known","id","name","cleanId","trim","cleanName","Boolean","has","auditHostReferences","input","issues","action","actions","push","refType","missing","source","sourceId","$id","sourceName","step","steps","type","workflows","workflowId","workflowName","datasets","datasetId","datasetName","lists","listId","listName","campaigns","campaignId","campaignName","overlays","overlayId","overlayName","webhooks","webhookId","webhookName","screens","screenId","workflow","functions","functionId","functionName","variable","variables","NODE_PROP_TARGETS","prop","products","collections","categories","screen","node","Object","values","nodes","props","target","value"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAwDD,MAAMA,WAAW,CACfC,OACAC,IACAC;IAEA,MAAMC,UAAUF,sBAAAA,GAAIG,IAAI;IACxB,MAAMC,YAAYH,wBAAAA,KAAME,IAAI;IAC5B,IAAI,CAACD,WAAW,CAACE,WAAW,OAAO,KAAK,sBAAsB;;IAC9D,IAAI,CAACL,OAAO,OAAO,KAAK,2CAA2C;;IACnE,OA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C,OAAOV,IAAI,CAAC;gBAChC,IAAI,OAAOW,UAAU,YAAY,CAACA,MAAMzD,IAAI,IAAI;gBAChD,IAAI,CAACL,SAAS6D,OAAO5D,KAAK,EAAE6D,QAAQ;wBAIpBP;oBAHd5C,OAAOG,IAAI,CAAC;wBACVG,QAAQ;wBACRC,UAAUqC,OAAOpC,GAAG;wBACpBC,UAAU,GAAEmC,eAAAA,OAAOpD,IAAI,YAAXoD,eAAeA,OAAOpC,GAAG;wBACrCJ,SAAS8C,OAAO9C,OAAO;wBACvBC,SAAS8C;oBACX;gBACF;YACF;QACF;IACF;IAEA,OAAOnD;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/model/reference-audit.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 { HostAction } from '@aglyn/aglyn'\nimport type { HostVariable } from '@aglyn/aglyn'\n\n/**\n * Reference-integrity audit (wave v7): id references (AGL-261) are\n * rename-safe but not delete-safe — deleting a workflow leaves actions\n * pointing at nothing, and the executors fail silently at run time.\n * This pure audit cross-checks every reference an automation, workflow,\n * or computed variable holds against the ids/names that still exist,\n * so the console can surface broken wiring before a visitor hits it.\n */\nexport interface ReferenceIssue {\n /** What holds the broken reference. */\n source: 'action' | 'workflow' | 'variable' | 'screen'\n sourceId: string\n /** Display name of the holder. */\n sourceName: string\n /** What the reference points at (\"workflow\", \"dataset\", …). */\n refType: string\n /** The dangling id or name as stored. */\n missing: string\n}\n\n/** A screen's composed nodes, for canvas-reference auditing (AGL-345). */\nexport interface ScreenAuditEntry {\n $id: string\n name?: string\n nodes: Record<string, { props?: Record<string, unknown> } | undefined>\n}\n\n/**\n * A stored workflow, as far as the audit reads one: its name and the function\n * each step calls, by id and by the name it had when the step was written.\n */\nexport interface AuditedWorkflow {\n $id: string\n name?: string\n steps?: Array<{ functionId?: string; functionName?: string }>\n}\n\nexport interface ReferenceAuditInput {\n actions?: Array<HostAction & { $id: string }>\n workflows?: AuditedWorkflow[]\n variables?: Array<HostVariable & { $id: string }>\n /** Screen node maps to scan for entity/screen-link references. */\n screens?: ScreenAuditEntry[]\n /** Known-good targets: doc ids AND display names both resolve. */\n known: {\n workflows?: Set<string>\n functions?: Set<string>\n datasets?: Set<string>\n lists?: Set<string>\n campaigns?: Set<string>\n overlays?: Set<string>\n webhooks?: Set<string>\n /** New reference kinds (AGL-345). */\n screens?: Set<string>\n products?: Set<string>\n collections?: Set<string>\n categories?: Set<string>\n }\n}\n\nconst resolves = (\n known: Set<string> | undefined,\n id?: string,\n name?: string,\n): boolean => {\n const cleanId = id?.trim()\n const cleanName = name?.trim()\n if (!cleanId && !cleanName) return true // Nothing referenced.\n if (!known) return true // Target kind not loaded — don't cry wolf.\n return Boolean(\n (cleanId && known.has(cleanId)) || (cleanName && known.has(cleanName)),\n )\n}\n\nexport function auditHostReferences(\n input: ReferenceAuditInput,\n): ReferenceIssue[] {\n const issues: ReferenceIssue[] = []\n const { known } = input\n\n for (const action of input.actions ?? []) {\n const push = (refType: string, missing: string) =>\n issues.push({\n source: 'action',\n sourceId: action.$id,\n sourceName: action.name ?? action.$id,\n refType,\n missing,\n })\n for (const step of action.steps ?? []) {\n if (step.type === 'runWorkflow') {\n if (!resolves(known.workflows, step.workflowId, step.workflowName)) {\n push('workflow', step.workflowId || step.workflowName || '')\n }\n } else if (\n step.type === 'datasetAppend' ||\n step.type === 'updateDataset'\n ) {\n if (!resolves(known.datasets, step.datasetId, step.datasetName)) {\n push('dataset', step.datasetId || step.datasetName || '')\n }\n } else if (step.type === 'enrollList') {\n if (!resolves(known.lists, step.listId, step.listName)) {\n push('list', step.listId || step.listName || '')\n }\n } else if (step.type === 'assignCampaign') {\n if (!resolves(known.campaigns, step.campaignId, step.campaignName)) {\n push('campaign', step.campaignId || step.campaignName || '')\n }\n } else if (step.type === 'showOverlay') {\n if (!resolves(known.overlays, step.overlayId, step.overlayName)) {\n push('overlay', step.overlayId || step.overlayName || '')\n }\n } else if (step.type === 'webhookPost') {\n if (!resolves(known.webhooks, step.webhookId, step.webhookName)) {\n push('webhook', step.webhookId || step.webhookName || '')\n }\n } else if (step.type === 'redirect') {\n // Screen-id redirects (AGL-339) go stale when the screen is\n // deleted/unpublished.\n if (!resolves(known.screens, (step as any).screenId)) {\n push('screen', (step as any).screenId || '')\n }\n }\n }\n }\n\n for (const workflow of input.workflows ?? []) {\n for (const step of workflow.steps ?? []) {\n if (!resolves(known.functions, step.functionId, step.functionName)) {\n issues.push({\n source: 'workflow',\n sourceId: workflow.$id,\n sourceName: workflow.name ?? workflow.$id,\n refType: 'function',\n missing: step.functionId || step.functionName || '',\n })\n }\n }\n }\n\n for (const variable of input.variables ?? []) {\n if (!resolves(known.workflows, variable.workflowId, variable.workflowName)) {\n issues.push({\n source: 'variable',\n sourceId: variable.$id,\n sourceName: variable.name ?? variable.$id,\n refType: 'workflow',\n missing: variable.workflowId || variable.workflowName || '',\n })\n }\n }\n\n // Canvas node references (AGL-345): screen links, commerce entities,\n // and repeat datasets persisted in component props.\n const NODE_PROP_TARGETS: Array<{\n prop: string\n refType: string\n known: Set<string> | undefined\n }> = [\n { prop: 'screenId', refType: 'screen', known: known.screens },\n { prop: 'productId', refType: 'product', known: known.products },\n { prop: 'collectionId', refType: 'collection', known: known.collections },\n { prop: 'categoryId', refType: 'category', known: known.categories },\n { prop: 'repeatDataset', refType: 'dataset', known: known.datasets },\n ]\n for (const screen of input.screens ?? []) {\n for (const node of Object.values(screen.nodes ?? {})) {\n const props = node?.props ?? {}\n for (const target of NODE_PROP_TARGETS) {\n const value = props[target.prop]\n if (typeof value !== 'string' || !value.trim()) continue\n if (!resolves(target.known, value)) {\n issues.push({\n source: 'screen',\n sourceId: screen.$id,\n sourceName: screen.name ?? screen.$id,\n refType: target.refType,\n missing: value,\n })\n }\n }\n }\n }\n\n return issues\n}\n"],"names":["resolves","known","id","name","cleanId","trim","cleanName","Boolean","has","auditHostReferences","input","issues","action","actions","push","refType","missing","source","sourceId","$id","sourceName","step","steps","type","workflows","workflowId","workflowName","datasets","datasetId","datasetName","lists","listId","listName","campaigns","campaignId","campaignName","overlays","overlayId","overlayName","webhooks","webhookId","webhookName","screens","screenId","workflow","functions","functionId","functionName","variable","variables","NODE_PROP_TARGETS","prop","products","collections","categories","screen","node","Object","values","nodes","props","target","value"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAiED,MAAMA,WAAW,CACfC,OACAC,IACAC;IAEA,MAAMC,UAAUF,sBAAAA,GAAIG,IAAI;IACxB,MAAMC,YAAYH,wBAAAA,KAAME,IAAI;IAC5B,IAAI,CAACD,WAAW,CAACE,WAAW,OAAO,KAAK,sBAAsB;;IAC9D,IAAI,CAACL,OAAO,OAAO,KAAK,2CAA2C;;IACnE,OAAOM,QACL,AAACH,WAAWH,MAAMO,GAAG,CAACJ,YAAcE,aAAaL,MAAMO,GAAG,CAACF;AAE/D;AAEA,OAAO,SAASG,oBACdC,KAA0B;QAKLA,gBA+CEA,kBAcAA,kBAyBFA;IAzFrB,MAAMC,SAA2B,EAAE;IACnC,MAAM,EAAEV,KAAK,EAAE,GAAGS;IAElB,KAAK,MAAME,WAAUF,iBAAAA,MAAMG,OAAO,YAAbH,iBAAiB,EAAE,CAAE;YASrBE;QARnB,MAAME,OAAO,CAACC,SAAiBC;gBAIfJ;mBAHdD,OAAOG,IAAI,CAAC;gBACVG,QAAQ;gBACRC,UAAUN,OAAOO,GAAG;gBACpBC,UAAU,GAAER,eAAAA,OAAOT,IAAI,YAAXS,eAAeA,OAAOO,GAAG;gBACrCJ;gBACAC;YACF;;QAC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
|
+
* 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 { PluginDependentsAnswer, PluginDependentsRequest } from '@aglyn/aglyn/plugin-manager/plugin-dependents';
|
|
18
|
+
/**
|
|
19
|
+
* Which of a site's variables are computed from a workflow, for the "Used by"
|
|
20
|
+
* scan — what the workflows plugin asks before a workflow is renamed or
|
|
21
|
+
* deleted, since each of these falls back to its stored value once the
|
|
22
|
+
* workflow is gone.
|
|
23
|
+
*
|
|
24
|
+
* A computed variable names its workflow by document id and, as a display
|
|
25
|
+
* hint, by the name it had when it was picked (AGL-261); one computed before
|
|
26
|
+
* ids existed carries the name alone. The id survives a rename, the name does
|
|
27
|
+
* not. A deleted variable is left out.
|
|
28
|
+
*/
|
|
29
|
+
/** How many of a site's variables one scan reads. */
|
|
30
|
+
export declare const WORKFLOW_DEPENDENTS_VARIABLES_READ = 100;
|
|
31
|
+
export declare function findWorkflowDependents(request: PluginDependentsRequest): Promise<PluginDependentsAnswer>;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { firebaseAdmin } from "@aglyn/tenant-data-admin/server/firebase-admin";
|
|
17
|
+
/**
|
|
18
|
+
* Which of a site's variables are computed from a workflow, for the "Used by"
|
|
19
|
+
* scan — what the workflows plugin asks before a workflow is renamed or
|
|
20
|
+
* deleted, since each of these falls back to its stored value once the
|
|
21
|
+
* workflow is gone.
|
|
22
|
+
*
|
|
23
|
+
* A computed variable names its workflow by document id and, as a display
|
|
24
|
+
* hint, by the name it had when it was picked (AGL-261); one computed before
|
|
25
|
+
* ids existed carries the name alone. The id survives a rename, the name does
|
|
26
|
+
* not. A deleted variable is left out.
|
|
27
|
+
*/ /** How many of a site's variables one scan reads. */ export const WORKFLOW_DEPENDENTS_VARIABLES_READ = 100;
|
|
28
|
+
const text = (value)=>typeof value === 'string' ? value.trim() : '';
|
|
29
|
+
export async function findWorkflowDependents(request) {
|
|
30
|
+
const id = request.id.trim();
|
|
31
|
+
const name = text(request.name);
|
|
32
|
+
if (!request.hostId || !id && !name) return {
|
|
33
|
+
dependents: [],
|
|
34
|
+
truncated: false
|
|
35
|
+
};
|
|
36
|
+
// One more than is read, so `truncated` is a fact rather than a guess.
|
|
37
|
+
const snapshot = await firebaseAdmin.app().firestore().collection('hosts').doc(request.hostId).collection('variables').limit(WORKFLOW_DEPENDENTS_VARIABLES_READ + 1).get();
|
|
38
|
+
const dependents = [];
|
|
39
|
+
for (const doc of snapshot.docs.slice(0, WORKFLOW_DEPENDENTS_VARIABLES_READ)){
|
|
40
|
+
var _doc_data;
|
|
41
|
+
const data = (_doc_data = doc.data()) != null ? _doc_data : {};
|
|
42
|
+
if (data['deletedAt'] != null) continue;
|
|
43
|
+
const via = [];
|
|
44
|
+
if (id && text(data['workflowId']) === id) via.push('id');
|
|
45
|
+
if (name && text(data['workflowName']) === name) via.push('name');
|
|
46
|
+
if (!via.length) continue;
|
|
47
|
+
dependents.push({
|
|
48
|
+
type: 'variable',
|
|
49
|
+
id: doc.id,
|
|
50
|
+
name: text(data['name']) || doc.id,
|
|
51
|
+
via
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
dependents,
|
|
56
|
+
truncated: snapshot.size > WORKFLOW_DEPENDENTS_VARIABLES_READ
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=variable-dependents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/logic/src/lib/server/variable-dependents.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 { BindingRefVia } from '@aglyn/aglyn/app-utils/binding-tokens'\nimport type {\n PluginDependent,\n PluginDependentsAnswer,\n PluginDependentsRequest,\n} from '@aglyn/aglyn/plugin-manager/plugin-dependents'\nimport { firebaseAdmin } from '@aglyn/tenant-data-admin/server/firebase-admin'\n\n/**\n * Which of a site's variables are computed from a workflow, for the \"Used by\"\n * scan — what the workflows plugin asks before a workflow is renamed or\n * deleted, since each of these falls back to its stored value once the\n * workflow is gone.\n *\n * A computed variable names its workflow by document id and, as a display\n * hint, by the name it had when it was picked (AGL-261); one computed before\n * ids existed carries the name alone. The id survives a rename, the name does\n * not. A deleted variable is left out.\n */\n\n/** How many of a site's variables one scan reads. */\nexport const WORKFLOW_DEPENDENTS_VARIABLES_READ = 100\n\nconst text = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')\n\nexport async function findWorkflowDependents(\n request: PluginDependentsRequest,\n): Promise<PluginDependentsAnswer> {\n const id = request.id.trim()\n const name = text(request.name)\n if (!request.hostId || (!id && !name)) return { dependents: [], truncated: false }\n // One more than is read, so `truncated` is a fact rather than a guess.\n const snapshot = await firebaseAdmin\n .app()\n .firestore()\n .collection('hosts')\n .doc(request.hostId)\n .collection('variables')\n .limit(WORKFLOW_DEPENDENTS_VARIABLES_READ + 1)\n .get()\n const dependents: PluginDependent[] = []\n for (const doc of snapshot.docs.slice(0, WORKFLOW_DEPENDENTS_VARIABLES_READ)) {\n const data = doc.data() ?? {}\n if (data['deletedAt'] != null) continue\n const via: BindingRefVia[] = []\n if (id && text(data['workflowId']) === id) via.push('id')\n if (name && text(data['workflowName']) === name) via.push('name')\n if (!via.length) continue\n dependents.push({\n type: 'variable',\n id: doc.id,\n name: text(data['name']) || doc.id,\n via,\n })\n }\n return { dependents, truncated: snapshot.size > WORKFLOW_DEPENDENTS_VARIABLES_READ }\n}\n"],"names":["firebaseAdmin","WORKFLOW_DEPENDENTS_VARIABLES_READ","text","value","trim","findWorkflowDependents","request","id","name","hostId","dependents","truncated","snapshot","app","firestore","collection","doc","limit","get","docs","slice","data","via","push","length","type","size"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAQD,SAASA,aAAa,QAAQ,iDAAgD;AAE9E;;;;;;;;;;CAUC,GAED,mDAAmD,GACnD,OAAO,MAAMC,qCAAqC,IAAG;AAErD,MAAMC,OAAO,CAACC,QAA4B,OAAOA,UAAU,WAAWA,MAAMC,IAAI,KAAK;AAErF,OAAO,eAAeC,uBACpBC,OAAgC;IAEhC,MAAMC,KAAKD,QAAQC,EAAE,CAACH,IAAI;IAC1B,MAAMI,OAAON,KAAKI,QAAQE,IAAI;IAC9B,IAAI,CAACF,QAAQG,MAAM,IAAK,C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