@aglyn/plugins-workflows 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-workflows",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,17 +25,17 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.7.0",
29
- "@aglyn/shared-data-mdi": "1.7.0",
30
- "@aglyn/shared-ui-jsx": "1.7.0",
31
- "@aglyn/shared-ui-next": "1.7.0",
32
- "@aglyn/shared-ui-snackstack": "1.7.0",
33
- "@aglyn/shared-util-email": "1.7.0",
34
- "@aglyn/shared-util-http": "1.7.0",
35
- "@aglyn/shared-util-timestamp": "1.7.0",
36
- "@aglyn/tenant-data-admin": "1.7.0",
37
- "@aglyn/tenant-feature-instance": "1.7.0",
38
- "@aglyn/tenant-runtime": "1.7.0",
28
+ "@aglyn/aglyn": "1.9.0",
29
+ "@aglyn/shared-data-mdi": "1.9.0",
30
+ "@aglyn/shared-ui-jsx": "1.9.0",
31
+ "@aglyn/shared-ui-next": "1.9.0",
32
+ "@aglyn/shared-ui-snackstack": "1.9.0",
33
+ "@aglyn/shared-util-email": "1.9.0",
34
+ "@aglyn/shared-util-http": "1.9.0",
35
+ "@aglyn/shared-util-timestamp": "1.9.0",
36
+ "@aglyn/tenant-data-admin": "1.9.0",
37
+ "@aglyn/tenant-feature-instance": "1.9.0",
38
+ "@aglyn/tenant-runtime": "1.9.0",
39
39
  "@swc/helpers": "0.5.23"
40
40
  },
41
41
  "peerDependencies": {
@@ -16,7 +16,7 @@
16
16
  */ 'use client';
17
17
  import { _ as _extends } from "@swc/helpers/_/_extends";
18
18
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
- import { checkEntitlement, createResourceUid, pluginDocsHelp } from "@aglyn/aglyn";
19
+ import { checkEntitlement, createResourceUid, planLabelGrantingFeature, pluginDocsHelp } from "@aglyn/aglyn";
20
20
  import { CardDisplay, useConfirmationContext } from "@aglyn/shared-ui-jsx";
21
21
  import { hostPublicOrigin } from "@aglyn/aglyn/app-utils/host-naming";
22
22
  import { useSnackbar } from "@aglyn/shared-ui-snackstack";
@@ -58,7 +58,7 @@ function generateSecret() {
58
58
  * (`/api/hooks/{hostId}/{hookId}`, secret-verified, run a workflow with
59
59
  * the payload in scope). Business tier.
60
60
  */ export function HostWebhooksCard(props) {
61
- var _hostPublicOrigin, _ref, _ref1, _ref2, _ref3, _ref4;
61
+ var _hostPublicOrigin, _planLabelGrantingFeature, _ref, _ref1, _ref2, _ref3, _ref4;
62
62
  const { hostId, org } = props;
63
63
  const firestore = useFirestore();
64
64
  const { enqueueSnackbar } = useSnackbar();
@@ -123,7 +123,8 @@ function generateSecret() {
123
123
  const siteBase = (_hostPublicOrigin = hostPublicOrigin(host)) != null ? _hostPublicOrigin : '';
124
124
  const handleAdd = useCallback(()=>{
125
125
  if (!checkEntitlement(org, 'webhooks')) {
126
- return void enqueueSnackbar('Webhooks require a Business plan — see Billing to upgrade', {
126
+ var _planLabelGrantingFeature;
127
+ return void enqueueSnackbar(`Webhooks require the ${(_planLabelGrantingFeature = planLabelGrantingFeature('webhooks')) != null ? _planLabelGrantingFeature : 'Pro'} plan — see Billing to upgrade`, {
127
128
  variant: 'warning',
128
129
  persist: false
129
130
  });
@@ -240,7 +241,7 @@ function generateSecret() {
240
241
  /*#__PURE__*/ _jsx(Typography, {
241
242
  variant: "body2",
242
243
  color: "text.secondary",
243
- children: 'Send signed JSON to outside systems from the actions builder, ' + 'or accept calls that run a workflow. Business plans.'
244
+ children: 'Send signed JSON to outside systems from the actions builder, ' + 'or accept calls that run a workflow. Included from ' + `${(_planLabelGrantingFeature = planLabelGrantingFeature('webhooks')) != null ? _planLabelGrantingFeature : 'Pro'}.`
244
245
  }),
245
246
  webhooks.map((hook)=>/*#__PURE__*/ _jsxs(Stack, {
246
247
  direction: "row",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/workflows/src/lib/components/host-webhooks-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 checkEntitlement,\n createResourceUid,\n pluginDocsHelp,\n} from '@aglyn/aglyn'\nimport { CardDisplay, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport { hostPublicOrigin } from '@aglyn/aglyn/app-utils/host-naming'\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 TextField,\n Typography,\n} from '@mui/material'\nimport { collection, doc, updateDoc } from 'firebase/firestore'\nimport { useCallback, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useFirestoreDoc,\n useHostResourceApi,\n} from '@aglyn/tenant-feature-instance'\n/*\n * The MODULE, not the barrel, for the two PURE helpers — the specs that render\n * this card mock `@aglyn/tenant-feature-instance` wholesale to stage their\n * Firestore hooks, and a query builder imported through that barrel disappears\n * under the mock. Neither of these is a hook.\n */\nimport {\n ceilingedWindow,\n collectionCeiling,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport { WEBHOOK_URL_PATTERN, maskedWebhookUrl } from '../model/webhooks'\nimport { WEBHOOK_MAX_PER_HOST } from '@aglyn/aglyn/plugin-manager/plugin-host-resources'\n\n/**\n * How many webhook documents the card reads.\n *\n * Above `WEBHOOK_MAX_PER_HOST` on purpose. The cap counts LIVE hooks and the\n * collection keeps soft-deleted ones, so a site that has created and deleted\n * its five several times holds more documents than it may have hooks.\n */\nconst WEBHOOK_CEILING = 20\n\n/**\n * How many workflows the inbound-endpoint 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 operator mid-edit rather than every visitor to\n * the page.\n */\nconst WORKFLOW_OPTION_CEILING = 100\n\nfunction generateSecret(): string {\n const bytes = new Uint8Array(24)\n crypto.getRandomValues(bytes)\n return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join(\n '',\n )\n}\n\ninterface WebhookDraft {\n id: string | null\n name: string\n direction: 'outbound' | 'inbound'\n url: string\n workflowName: string\n secret: string\n}\n\n/**\n * Webhooks manager (AGL-149): outbound targets (used by the actions\n * builder's \"Send a webhook\" step, HMAC-signed) and inbound endpoints\n * (`/api/hooks/{hostId}/{hookId}`, secret-verified, run a workflow with\n * the payload in scope). Business tier.\n */\nexport function HostWebhooksCard(props: {\n hostId: string\n org?: Partial<AglynOrgBilling>\n}) {\n const { hostId, org } = props\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n const createResource = useHostResourceApi()\n\n\n const [draft, setDraft] = useState<WebhookDraft | 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 actions 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 * ORDERED AND CEILINGED (AGL-2501). A bare `limit` is answered in\n * DOCUMENT-ID order, so an unnamed window is an arbitrary twenty that the\n * `localeCompare` below would arrange alphabetically. `collectionCeiling`\n * does not change WHICH twenty; it NAMES the order, and the probe row it\n * adds is what lets the card say when the ceiling bites.\n */\n const { data: webhookRead } = useFirestoreCollection<any>(\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, 'webhooks'),\n WEBHOOK_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n const { rows: readWebhooks, truncated: webhooksTruncated } =\n ceilingedWindow<any>(webhookRead, WEBHOOK_CEILING)\n /*\n * READ WHEN THE EDITOR OPENS, not when the card mounts. The only thing that\n * consumes these rows is the inbound-endpoint select inside the dialog — the\n * table renders a hook's stored `workflowName` — so an unconditional\n * listener would charge every visitor to this page a hundred workflows to\n * fill a control most of them never see, and one that only appears for the\n * inbound half of the form at that.\n */\n const { data: workflowRead } = 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>(workflowRead, WORKFLOW_OPTION_CEILING)\n const { data: host } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId),\n [firestore, hostId],\n { idField: '$id' },\n )\n // Sorting the whole ceiling, not a page of it.\n const webhooks = [...readWebhooks]\n .filter((hook: any) => !hook.deletedAt)\n .sort((a: any, b: any) =>\n String(a.name ?? '').localeCompare(String(b.name ?? '')),\n )\n const workflowNames = readWorkflows\n .filter((workflow: any) => !workflow.deletedAt && workflow.name)\n .map((workflow: any) => workflow.name as string)\n .sort()\n // `hostPublicOrigin` (AGL-2195) — this base is printed into the webhook\n // sample payload an operator copies into a third-party system.\n const siteBase = hostPublicOrigin(host) ?? ''\n\n const handleAdd = useCallback(() => {\n if (!checkEntitlement(org, 'webhooks')) {\n return void enqueueSnackbar(\n 'Webhooks require a Business plan — see Billing to upgrade',\n { variant: 'warning', persist: false },\n )\n }\n // An affordance, NOT the limit (AGL-1360). `webhooks` comes from a\n // Firestore listener and the console runs `persistentLocalCache`, so this\n // count can be arbitrarily stale — it is here to fail fast when it\n // happens to be right, never to authorise the create. The cap that holds\n // is counted server-side in /api/hosts/resources.\n if (webhooks.length >= WEBHOOK_MAX_PER_HOST) {\n return void enqueueSnackbar(\n `Webhooks are capped at ${WEBHOOK_MAX_PER_HOST} per site`,\n { variant: 'warning', persist: false },\n )\n }\n setDraft({\n id: null,\n name: '',\n direction: 'outbound',\n url: '',\n workflowName: '',\n secret: generateSecret(),\n })\n }, [org, webhooks.length, enqueueSnackbar])\n\n const handleSave = useCallback(async () => {\n if (!draft || !draft.name.trim()) return\n if (draft.direction === 'outbound') {\n if (!WEBHOOK_URL_PATTERN.test(draft.url.trim())) {\n return void enqueueSnackbar(\n 'Outbound URLs must be public https addresses',\n { variant: 'warning', persist: false },\n )\n }\n } else if (!draft.workflowName.trim()) {\n return void enqueueSnackbar('Pick the workflow this endpoint runs', {\n variant: 'warning',\n persist: false,\n })\n }\n try {\n // Creates go through /api/hosts/resources (AGL-1360), which counts the\n // live webhooks with the Admin SDK before allowing one more; Firestore\n // rules deny client `create` on this collection. The card has no edit\n // path — every save is a create — so there is no update branch here.\n await createResource({\n hostId,\n resource: 'webhook',\n id: createResourceUid(),\n data: {\n name: draft.name.trim().slice(0, 60),\n direction: draft.direction,\n ...(draft.direction === 'outbound'\n ? { url: draft.url.trim() }\n : { workflowName: draft.workflowName.trim() }),\n secret: draft.secret,\n enabled: true,\n },\n })\n setDraft(null)\n enqueueSnackbar('Webhook saved', { variant: 'success', persist: false })\n } catch (error: any) {\n console.error(error)\n // The route's message is the useful one — it names the cap, the\n // entitlement or the role that refused.\n enqueueSnackbar(error?.message || 'An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n }, [draft, createResource, hostId, enqueueSnackbar])\n\n const handleDelete = useCallback(\n (hook: any) => async () => {\n const confirmed = await confirm({\n title: 'Delete this webhook?',\n description: `\"${hook.name}\" stops ${\n hook.direction === 'outbound' ? 'delivering' : 'accepting calls'\n } immediately.`,\n confirmationText: 'Delete',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n await updateDoc(doc(firestore, 'hosts', hostId, 'webhooks', hook.$id), {\n deletedAt: Timestamp.now(),\n })\n },\n [confirm, firestore, hostId],\n )\n\n return (\n <CardDisplay\n header={'Webhooks'}\n help={pluginDocsHelp('webhooks', { anchor: '#outbound-webhooks' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Send signed JSON to outside systems from the actions builder, ' +\n 'or accept calls that run a workflow. Business plans.'}\n </Typography>\n {webhooks.map((hook: any) => (\n <Stack\n key={hook.$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 {hook.name}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {hook.direction === 'outbound'\n ? `outbound · ${maskedWebhookUrl(hook.url)}`\n : `inbound · ${siteBase}/api/hooks/${hostId}/${hook.$id}` +\n ` → ${hook.workflowName}`}\n </Typography>\n </Stack>\n {hook.direction === 'inbound' ? (\n <Button\n size=\"small\"\n onClick={() => {\n void navigator.clipboard.writeText(\n `${siteBase}/api/hooks/${hostId}/${hook.$id}`,\n )\n enqueueSnackbar(\n 'Endpoint URL copied — send the secret in x-aglyn-secret',\n { variant: 'success', persist: false },\n )\n }}\n >\n {'Copy URL'}\n </Button>\n ) : null}\n <Button\n size=\"small\"\n onClick={() => {\n void navigator.clipboard.writeText(hook.secret ?? '')\n enqueueSnackbar('Secret copied', {\n variant: 'success',\n persist: false,\n })\n }}\n >\n {'Secret'}\n </Button>\n <Button size=\"small\" color=\"error\" onClick={handleDelete(hook)}>\n {'Delete'}\n </Button>\n </Stack>\n ))}\n {webhooksTruncated ? (\n <Alert severity=\"info\">\n {`Showing the first ${WEBHOOK_CEILING} webhook documents on this ` +\n 'site, ordered by id. There are more, so a hook may be missing ' +\n 'from this list.'}\n </Alert>\n ) : null}\n <Button\n size=\"small\"\n color=\"primary\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={handleAdd}\n >\n {'Add webhook'}\n </Button>\n </Stack>\n\n <Dialog\n open={Boolean(draft)}\n onClose={() => setDraft(null)}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>{'Add webhook'}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 1.5, pt: 1 }}\n >\n <TextField\n label=\"Name\"\n value={draft?.name ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, name: event.target.value } : prev,\n )\n }\n size=\"small\"\n autoFocus\n sx={{ mt: 1 }}\n />\n <TextField\n select\n label=\"Direction\"\n value={draft?.direction ?? 'outbound'}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? { ...prev, direction: event.target.value as any }\n : prev,\n )\n }\n size=\"small\"\n >\n <MenuItem value=\"outbound\">\n {'Outbound — send data to a URL'}\n </MenuItem>\n <MenuItem value=\"inbound\">\n {'Inbound — receive data, run a workflow'}\n </MenuItem>\n </TextField>\n {draft?.direction === 'outbound' ? (\n <TextField\n label=\"Delivery URL\"\n placeholder=\"https://example.com/hooks/aglyn\"\n value={draft?.url ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, url: event.target.value } : prev,\n )\n }\n size=\"small\"\n />\n ) : (\n <TextField\n select\n label=\"Workflow to run\"\n helperText={\n workflowOptionsTruncated\n ? `Showing ${WORKFLOW_OPTION_CEILING} workflows, ordered ` +\n 'by id. This site has more, so one of them is not ' +\n 'offered here.'\n : undefined\n }\n value={draft?.workflowName ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, workflowName: event.target.value } : prev,\n )\n }\n size=\"small\"\n >\n {workflowNames.map((name) => (\n <MenuItem key={name} value={name}>\n {name}\n </MenuItem>\n ))}\n </TextField>\n )}\n <TextField\n label=\"Secret\"\n helperText={\n draft?.direction === 'outbound'\n ? 'Signs deliveries (X-Aglyn-Signature, HMAC-SHA256)'\n : 'Callers send this in the x-aglyn-secret header'\n }\n value={draft?.secret ?? ''}\n size=\"small\"\n slotProps={{ input: { readOnly: true } }}\n />\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDraft(null)}>{'Cancel'}</Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!draft?.name.trim()}\n onClick={handleSave}\n >\n {'Save webhook'}\n </Button>\n </DialogActions>\n </Dialog>\n </CardDisplay>\n )\n}\nHostWebhooksCard.displayName = 'HostWebhooksCard'\n\nexport default HostWebhooksCard\n"],"names":["checkEntitlement","createResourceUid","pluginDocsHelp","CardDisplay","useConfirmationContext","hostPublicOrigin","useSnackbar","Timestamp","Alert","Button","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","Stack","TextField","Typography","collection","doc","updateDoc","useCallback","useState","useFirestore","useFirestoreCollection","useFirestoreDoc","useHostResourceApi","ceilingedWindow","collectionCeiling","WEBHOOK_URL_PATTERN","maskedWebhookUrl","WEBHOOK_MAX_PER_HOST","WEBHOOK_CEILING","WORKFLOW_OPTION_CEILING","generateSecret","bytes","Uint8Array","crypto","getRandomValues","Array","from","byte","toString","padStart","join","HostWebhooksCard","props","hostId","org","firestore","enqueueSnackbar","confirm","createResource","draft","setDraft","editorOpened","setEditorOpened","data","webhookRead","idField","rows","readWebhooks","truncated","webhooksTruncated","workflowRead","readWorkflows","workflowOptionsTruncated","host","webhooks","filter","hook","deletedAt","sort","a","b","String","name","localeCompare","workflowNames","workflow","map","siteBase","handleAdd","variant","persist","length","id","direction","url","workflowName","secret","handleSave","trim","test","resource","slice","enabled","error","console","message","allowDuplicate","handleDelete","confirmed","title","description","confirmationText","confirmationButtonProps","color","then","catch","$id","now","header","help","anchor","contentGutterX","contentGutterY","spacing","sx","alignItems","flex","minWidth","noWrap","size","onClick","navigator","clipboard","writeText","severity","alignSelf","open","Boolean","onClose","maxWidth","fullWidth","display","flexDirection","gap","pt","label","value","onChange","event","prev","target","autoFocus","mt","select","placeholder","helperText","undefined","slotProps","input","readOnly","disabled","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAEEA,gBAAgB,EAChBC,iBAAiB,EACjBC,cAAc,QACT,eAAc;AACrB,SAASC,WAAW,EAAEC,sBAAsB,QAAQ,uBAAsB;AAC1E,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,SAAS,QAAQ,+BAA8B;AACxD,SACEC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,QAAQ,EACRC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,UAAU,EAAEC,GAAG,EAAEC,SAAS,QAAQ,qBAAoB;AAC/D,SAASC,WAAW,EAAEC,QAAQ,QAAQ,QAAO;AAC7C,SACEC,YAAY,EACZC,sBAAsB,EACtBC,eAAe,EACfC,kBAAkB,QACb,iCAAgC;AACvC;;;;;CAKC,GACD,SACEC,eAAe,EACfC,iBAAiB,QACZ,+DAA8D;AACrE,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,uBAAmB;AACzE,SAASC,oBAAoB,QAAQ,oDAAmD;AAExF;;;;;;CAMC,GACD,MAAMC,kBAAkB;AAExB;;;;;;CAMC,GACD,MAAMC,0BAA0B;AAEhC,SAASC;IACP,MAAMC,QAAQ,IAAIC,WAAW;IAC7BC,OAAOC,eAAe,CAACH;IACvB,OAAOI,MAAMC,IAAI,CAACL,OAAO,CAACM,OAASA,KAAKC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CACzE;AAEJ;AAWA;;;;;CAKC,GACD,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AAK,2BACpB,KAACvE;gCACC2H,OAAM;gCACNS,aAAY;gCACZR,KAAK,WAAEvF,yBAAAA,MAAOmC,GAAG,oBAAI;gCACrBqD,UAAU,CAACC,QACTxF,SAAS,CAACyF,OACRA,OAAO,aAAKA;4CAAMvD,KAAKsD,MAAME,MAAM,CAACJ,KAAK;6CAAKG;gCAGlDpB,MAAK;+CAGP,KAAC3G;gCACCmI,MAAM;gCACNR,OAAM;gCACNU,YACEnF,2BACI,CAAC,QAAQ,EAAEjC,wBAAwB,oBAAoB,CAAC,GACxD,sDACA,kBACAqH;gCAENV,KAAK,WAAEvF,yBAAAA,MAAOoC,YAAY,oBAAI;gCAC9BoD,UAAU,CAACC,QACTxF,SAAS,CAACyF,OACRA,OAAO,aAAKA;4CAAMtD,cAAcqD,MAAME,MAAM,CAACJ,KAAK;6CAAKG;gCAG3DpB,MAAK;0CAEJ7C,cAAcE,GAAG,CAAC,CAACJ,qBAClB,KAAC9D;wCAAoB8H,OAAOhE;kDACzBA;uCADYA;;0CAMrB,KAAC5D;gCACC2H,OAAM;gCACNU,YACEhG,CAAAA,yBAAAA,MAAOkC,SAAS,MAAK,aACjB,sDACA;gCAENqD,KAAK,WAAEvF,yBAAAA,MAAOqC,MAAM,oBAAI;gCACxBiC,MAAK;gCACL4B,WAAW;oCAAEC,OAAO;wCAAEC,UAAU;oCAAK;gCAAE;;;;kCAG3C,MAAC9I;;0CACC,KAACF;gCAAOmH,SAAS,IAAMtE,SAAS;0CAAQ;;0CACxC,KAAC7C;gCACC0E,SAAQ;gCACRwB,OAAM;gCACN+C,UAAU,EAACrG,yBAAAA,MAAOuB,IAAI,CAACgB,IAAI;gCAC3BgC,SAASjC;0CAER;;;;;;;;AAMb;AACA9C,iBAAiB8G,WAAW,GAAG;AAE/B,eAAe9G,iBAAgB"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/workflows/src/lib/components/host-webhooks-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 checkEntitlement,\n createResourceUid,\n planLabelGrantingFeature,\n pluginDocsHelp,\n} from '@aglyn/aglyn'\nimport { CardDisplay, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport { hostPublicOrigin } from '@aglyn/aglyn/app-utils/host-naming'\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 TextField,\n Typography,\n} from '@mui/material'\nimport { collection, doc, updateDoc } from 'firebase/firestore'\nimport { useCallback, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useFirestoreDoc,\n useHostResourceApi,\n} from '@aglyn/tenant-feature-instance'\n/*\n * The MODULE, not the barrel, for the two PURE helpers — the specs that render\n * this card mock `@aglyn/tenant-feature-instance` wholesale to stage their\n * Firestore hooks, and a query builder imported through that barrel disappears\n * under the mock. Neither of these is a hook.\n */\nimport {\n ceilingedWindow,\n collectionCeiling,\n} from '@aglyn/tenant-feature-instance/hooks/host-collection-queries'\nimport { WEBHOOK_URL_PATTERN, maskedWebhookUrl } from '../model/webhooks'\nimport { WEBHOOK_MAX_PER_HOST } from '@aglyn/aglyn/plugin-manager/plugin-host-resources'\n\n/**\n * How many webhook documents the card reads.\n *\n * Above `WEBHOOK_MAX_PER_HOST` on purpose. The cap counts LIVE hooks and the\n * collection keeps soft-deleted ones, so a site that has created and deleted\n * its five several times holds more documents than it may have hooks.\n */\nconst WEBHOOK_CEILING = 20\n\n/**\n * How many workflows the inbound-endpoint 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 operator mid-edit rather than every visitor to\n * the page.\n */\nconst WORKFLOW_OPTION_CEILING = 100\n\nfunction generateSecret(): string {\n const bytes = new Uint8Array(24)\n crypto.getRandomValues(bytes)\n return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join(\n '',\n )\n}\n\ninterface WebhookDraft {\n id: string | null\n name: string\n direction: 'outbound' | 'inbound'\n url: string\n workflowName: string\n secret: string\n}\n\n/**\n * Webhooks manager (AGL-149): outbound targets (used by the actions\n * builder's \"Send a webhook\" step, HMAC-signed) and inbound endpoints\n * (`/api/hooks/{hostId}/{hookId}`, secret-verified, run a workflow with\n * the payload in scope). Business tier.\n */\nexport function HostWebhooksCard(props: {\n hostId: string\n org?: Partial<AglynOrgBilling>\n}) {\n const { hostId, org } = props\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n const createResource = useHostResourceApi()\n\n\n const [draft, setDraft] = useState<WebhookDraft | 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 actions 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 * ORDERED AND CEILINGED (AGL-2501). A bare `limit` is answered in\n * DOCUMENT-ID order, so an unnamed window is an arbitrary twenty that the\n * `localeCompare` below would arrange alphabetically. `collectionCeiling`\n * does not change WHICH twenty; it NAMES the order, and the probe row it\n * adds is what lets the card say when the ceiling bites.\n */\n const { data: webhookRead } = useFirestoreCollection<any>(\n () =>\n collectionCeiling(\n collection(firestore, 'hosts', hostId, 'webhooks'),\n WEBHOOK_CEILING,\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n const { rows: readWebhooks, truncated: webhooksTruncated } =\n ceilingedWindow<any>(webhookRead, WEBHOOK_CEILING)\n /*\n * READ WHEN THE EDITOR OPENS, not when the card mounts. The only thing that\n * consumes these rows is the inbound-endpoint select inside the dialog — the\n * table renders a hook's stored `workflowName` — so an unconditional\n * listener would charge every visitor to this page a hundred workflows to\n * fill a control most of them never see, and one that only appears for the\n * inbound half of the form at that.\n */\n const { data: workflowRead } = 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>(workflowRead, WORKFLOW_OPTION_CEILING)\n const { data: host } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId),\n [firestore, hostId],\n { idField: '$id' },\n )\n // Sorting the whole ceiling, not a page of it.\n const webhooks = [...readWebhooks]\n .filter((hook: any) => !hook.deletedAt)\n .sort((a: any, b: any) =>\n String(a.name ?? '').localeCompare(String(b.name ?? '')),\n )\n const workflowNames = readWorkflows\n .filter((workflow: any) => !workflow.deletedAt && workflow.name)\n .map((workflow: any) => workflow.name as string)\n .sort()\n // `hostPublicOrigin` (AGL-2195) — this base is printed into the webhook\n // sample payload an operator copies into a third-party system.\n const siteBase = hostPublicOrigin(host) ?? ''\n\n const handleAdd = useCallback(() => {\n if (!checkEntitlement(org, 'webhooks')) {\n return void enqueueSnackbar(\n `Webhooks require the ${\n planLabelGrantingFeature('webhooks') ?? 'Pro'\n } plan — see Billing to upgrade`,\n { variant: 'warning', persist: false },\n )\n }\n // An affordance, NOT the limit (AGL-1360). `webhooks` comes from a\n // Firestore listener and the console runs `persistentLocalCache`, so this\n // count can be arbitrarily stale — it is here to fail fast when it\n // happens to be right, never to authorise the create. The cap that holds\n // is counted server-side in /api/hosts/resources.\n if (webhooks.length >= WEBHOOK_MAX_PER_HOST) {\n return void enqueueSnackbar(\n `Webhooks are capped at ${WEBHOOK_MAX_PER_HOST} per site`,\n { variant: 'warning', persist: false },\n )\n }\n setDraft({\n id: null,\n name: '',\n direction: 'outbound',\n url: '',\n workflowName: '',\n secret: generateSecret(),\n })\n }, [org, webhooks.length, enqueueSnackbar])\n\n const handleSave = useCallback(async () => {\n if (!draft || !draft.name.trim()) return\n if (draft.direction === 'outbound') {\n if (!WEBHOOK_URL_PATTERN.test(draft.url.trim())) {\n return void enqueueSnackbar(\n 'Outbound URLs must be public https addresses',\n { variant: 'warning', persist: false },\n )\n }\n } else if (!draft.workflowName.trim()) {\n return void enqueueSnackbar('Pick the workflow this endpoint runs', {\n variant: 'warning',\n persist: false,\n })\n }\n try {\n // Creates go through /api/hosts/resources (AGL-1360), which counts the\n // live webhooks with the Admin SDK before allowing one more; Firestore\n // rules deny client `create` on this collection. The card has no edit\n // path — every save is a create — so there is no update branch here.\n await createResource({\n hostId,\n resource: 'webhook',\n id: createResourceUid(),\n data: {\n name: draft.name.trim().slice(0, 60),\n direction: draft.direction,\n ...(draft.direction === 'outbound'\n ? { url: draft.url.trim() }\n : { workflowName: draft.workflowName.trim() }),\n secret: draft.secret,\n enabled: true,\n },\n })\n setDraft(null)\n enqueueSnackbar('Webhook saved', { variant: 'success', persist: false })\n } catch (error: any) {\n console.error(error)\n // The route's message is the useful one — it names the cap, the\n // entitlement or the role that refused.\n enqueueSnackbar(error?.message || 'An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n }\n }, [draft, createResource, hostId, enqueueSnackbar])\n\n const handleDelete = useCallback(\n (hook: any) => async () => {\n const confirmed = await confirm({\n title: 'Delete this webhook?',\n description: `\"${hook.name}\" stops ${\n hook.direction === 'outbound' ? 'delivering' : 'accepting calls'\n } immediately.`,\n confirmationText: 'Delete',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n await updateDoc(doc(firestore, 'hosts', hostId, 'webhooks', hook.$id), {\n deletedAt: Timestamp.now(),\n })\n },\n [confirm, firestore, hostId],\n )\n\n return (\n <CardDisplay\n header={'Webhooks'}\n help={pluginDocsHelp('webhooks', { anchor: '#outbound-webhooks' })}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Send signed JSON to outside systems from the actions builder, ' +\n 'or accept calls that run a workflow. Included from ' +\n `${planLabelGrantingFeature('webhooks') ?? 'Pro'}.`}\n </Typography>\n {webhooks.map((hook: any) => (\n <Stack\n key={hook.$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 {hook.name}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {hook.direction === 'outbound'\n ? `outbound · ${maskedWebhookUrl(hook.url)}`\n : `inbound · ${siteBase}/api/hooks/${hostId}/${hook.$id}` +\n ` → ${hook.workflowName}`}\n </Typography>\n </Stack>\n {hook.direction === 'inbound' ? (\n <Button\n size=\"small\"\n onClick={() => {\n void navigator.clipboard.writeText(\n `${siteBase}/api/hooks/${hostId}/${hook.$id}`,\n )\n enqueueSnackbar(\n 'Endpoint URL copied — send the secret in x-aglyn-secret',\n { variant: 'success', persist: false },\n )\n }}\n >\n {'Copy URL'}\n </Button>\n ) : null}\n <Button\n size=\"small\"\n onClick={() => {\n void navigator.clipboard.writeText(hook.secret ?? '')\n enqueueSnackbar('Secret copied', {\n variant: 'success',\n persist: false,\n })\n }}\n >\n {'Secret'}\n </Button>\n <Button size=\"small\" color=\"error\" onClick={handleDelete(hook)}>\n {'Delete'}\n </Button>\n </Stack>\n ))}\n {webhooksTruncated ? (\n <Alert severity=\"info\">\n {`Showing the first ${WEBHOOK_CEILING} webhook documents on this ` +\n 'site, ordered by id. There are more, so a hook may be missing ' +\n 'from this list.'}\n </Alert>\n ) : null}\n <Button\n size=\"small\"\n color=\"primary\"\n sx={{ alignSelf: 'flex-start' }}\n onClick={handleAdd}\n >\n {'Add webhook'}\n </Button>\n </Stack>\n\n <Dialog\n open={Boolean(draft)}\n onClose={() => setDraft(null)}\n maxWidth=\"xs\"\n fullWidth\n >\n <DialogTitle>{'Add webhook'}</DialogTitle>\n <DialogContent\n sx={{ display: 'flex', flexDirection: 'column', gap: 1.5, pt: 1 }}\n >\n <TextField\n label=\"Name\"\n value={draft?.name ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, name: event.target.value } : prev,\n )\n }\n size=\"small\"\n autoFocus\n sx={{ mt: 1 }}\n />\n <TextField\n select\n label=\"Direction\"\n value={draft?.direction ?? 'outbound'}\n onChange={(event) =>\n setDraft((prev) =>\n prev\n ? { ...prev, direction: event.target.value as any }\n : prev,\n )\n }\n size=\"small\"\n >\n <MenuItem value=\"outbound\">\n {'Outbound — send data to a URL'}\n </MenuItem>\n <MenuItem value=\"inbound\">\n {'Inbound — receive data, run a workflow'}\n </MenuItem>\n </TextField>\n {draft?.direction === 'outbound' ? (\n <TextField\n label=\"Delivery URL\"\n placeholder=\"https://example.com/hooks/aglyn\"\n value={draft?.url ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, url: event.target.value } : prev,\n )\n }\n size=\"small\"\n />\n ) : (\n <TextField\n select\n label=\"Workflow to run\"\n helperText={\n workflowOptionsTruncated\n ? `Showing ${WORKFLOW_OPTION_CEILING} workflows, ordered ` +\n 'by id. This site has more, so one of them is not ' +\n 'offered here.'\n : undefined\n }\n value={draft?.workflowName ?? ''}\n onChange={(event) =>\n setDraft((prev) =>\n prev ? { ...prev, workflowName: event.target.value } : prev,\n )\n }\n size=\"small\"\n >\n {workflowNames.map((name) => (\n <MenuItem key={name} value={name}>\n {name}\n </MenuItem>\n ))}\n </TextField>\n )}\n <TextField\n label=\"Secret\"\n helperText={\n draft?.direction === 'outbound'\n ? 'Signs deliveries (X-Aglyn-Signature, HMAC-SHA256)'\n : 'Callers send this in the x-aglyn-secret header'\n }\n value={draft?.secret ?? ''}\n size=\"small\"\n slotProps={{ input: { readOnly: true } }}\n />\n </DialogContent>\n <DialogActions>\n <Button onClick={() => setDraft(null)}>{'Cancel'}</Button>\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={!draft?.name.trim()}\n onClick={handleSave}\n >\n {'Save webhook'}\n </Button>\n </DialogActions>\n </Dialog>\n </CardDisplay>\n )\n}\nHostWebhooksCard.displayName = 'HostWebhooksCard'\n\nexport default HostWebhooksCard\n"],"names":["checkEntitlement","createResourceUid","planLabelGrantingFeature","pluginDocsHelp","CardDisplay","useConfirmationContext","hostPublicOrigin","useSnackbar","Timestamp","Alert","Button","Dialog","DialogActions","DialogContent","DialogTitle","MenuItem","Stack","TextField","Typography","collection","doc","updateDoc","useCallback","useState","useFirestore","useFirestoreCollection","useFirestoreDoc","useHostResourceApi","ceilingedWindow","collectionCeiling","WEBHOOK_URL_PATTERN","maskedWebhookUrl","WEBHOOK_MAX_PER_HOST","WEBHOOK_CEILING","WORKFLOW_OPTION_CEILING","generateSecret","bytes","Uint8Array","crypto","getRandomValues","Array","from","byte","toString","padStart","join","HostWebhooksCard","props","hostId","org","firestore","enqueueSnackbar","confirm","createResource","draft","setDraft","editorOpened","setEditorOpened","data","webhookRead","idField","rows","readWebhooks","truncated","webhooksTruncated","workflowRead","readWorkflows","workflowOptionsTruncated","host","webhooks","filter","hook","deletedAt","sort","a","b","String","name","localeCompare","workflowNames","workflow","map","siteBase","handleAdd","variant","persist","length","id","direction","url","workflowName","secret","handleSave","trim","test","resource","slice","enabled","error","console","message","allowDuplicate","handleDelete","confirmed","title","description","confirmationText","confirmationButtonProps","color","then","catch","$id","now","header","help","anchor","contentGutterX","contentGutterY","spacing","sx","alignItems","flex","minWidth","noWrap","size","onClick","navigator","clipboard","writeText","severity","alignSelf","open","Boolean","onClose","maxWidth","fullWidth","display","flexDirection","gap","pt","label","value","onChange","event","prev","target","autoFocus","mt","select","placeholder","helperText","undefined","slotProps","input","readOnly","disabled","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAEEA,gBAAgB,EAChBC,iBAAiB,EACjBC,wBAAwB,EACxBC,cAAc,QACT,eAAc;AACrB,SAASC,WAAW,EAAEC,sBAAsB,QAAQ,uBAAsB;AAC1E,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,SAAS,QAAQ,+BAA8B;AACxD,SACEC,KAAK,EACLC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,aAAa,EACbC,WAAW,EACXC,QAAQ,EACRC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,UAAU,EAAEC,GAAG,EAAEC,SAAS,QAAQ,qBAAoB;AAC/D,SAASC,WAAW,EAAEC,QAAQ,QAAQ,QAAO;AAC7C,SACEC,YAAY,EACZC,sBAAsB,EACtBC,eAAe,EACfC,kBAAkB,QACb,iCAAgC;AACvC;;;;;CAKC,GACD,SACEC,eAAe,EACfC,iBAAiB,QACZ,+DAA8D;AACrE,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,uBAAmB;AACzE,SAASC,oBAAoB,QAAQ,oDAAmD;AAExF;;;;;;CAMC,GACD,MAAMC,kBAAkB;AAExB;;;;;;CAMC,GACD,MAAMC,0BAA0B;AAEhC,SAASC;IACP,MAAMC,QAAQ,IAAIC,WAAW;IAC7BC,OAAOC,eAAe,CAACH;IACvB,OAAOI,MAAMC,IAAI,CAACL,OAAO,CAACM,OAASA,KAAKC,QAAQ,CAAC,IAAIC,QAAQ,CAAC,GAAG,MAAMC,IAAI,CACzE;AAEJ;AAWA;;;;;CAKC,GACD,OAAO,SAASC,iBAAiBC,KAGhC;QA6EkBzC,mBA8GJJ;IA1Lb,MAAM,EAAE8C,MAAM,EAAEC,GAAG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@swc/helpers/_/_extends";
18
18
  import { isDeferrableSendResult, isEmailConfigured, sendEmail, sendFailureReason } from "@aglyn/shared-util-email";
19
19
  import { enrollListMember, filterSendableForHost, firebaseAdmin, flowEmailRefusal, getOrgForHost, hostDisplayName, hostSendingIdentity, meterHostEmail, notifyHostManagers, consentGroupForSite, resolveOrgIdForHost } from "@aglyn/tenant-data-admin";
20
20
  import { activitySearchTokens } from "@aglyn/aglyn/app-utils/activity-search";
21
+ // By its own module, as `run-event-workflows.ts` reads it.
22
+ import { runOverageSold } from "@aglyn/aglyn/app-utils/plan-entitlements";
21
23
  import { visibleToHost } from "@aglyn/aglyn/app-utils/scope-tokens";
22
24
  import { triggerFilterProblem } from "@aglyn/aglyn/app-utils/site-interactions";
23
25
  // The person behind an address, and their filing under a campaign, through
@@ -293,7 +295,8 @@ export function makeWorkflowContextLoader(hostRef) {
293
295
  } else if (step.type === 'webhookPost') {
294
296
  var _ref3;
295
297
  var _step_webhookId, _step_webhookName;
296
- if (!env.webhooksAllowed) return failed('webhooks require a Business plan');
298
+ // Pro since pricing v4 (AGL-4126), Business before it.
299
+ if (!env.webhooksAllowed) return failed('webhooks require a Pro plan');
297
300
  // Id-first lookup (AGL-261); the name query is the legacy path.
298
301
  const hookDoc = ((_step_webhookId = step.webhookId) == null ? void 0 : _step_webhookId.trim()) ? await hostRef.collection('webhooks').doc(step.webhookId.trim()).get() : (await hostRef.collection('webhooks').where('name', '==', (_ref3 = (_step_webhookName = step.webhookName) == null ? void 0 : _step_webhookName.trim()) != null ? _ref3 : '').limit(1).get()).docs[0];
299
302
  const hook = (hookDoc == null ? void 0 : hookDoc.exists) ? hookDoc.data() : undefined;
@@ -1206,13 +1209,16 @@ export function makeWorkflowContextLoader(hostRef) {
1206
1209
  const used = await runsUsedThisMonth(meter);
1207
1210
  // Asked as "would it go over", the question this gate has always
1208
1211
  // asked — so a counter that reads as no number refuses nothing, as
1209
- // before, rather than refusing everything.
1210
- runSite = actions.length > 0 && !(used + actions.length > limit);
1212
+ // before, rather than refusing everything. Past the band is a wall only
1213
+ // where the plan sells no runs past it (pricing v4, `runOverageSold`).
1214
+ runSite = actions.length > 0 && (!(used + actions.length > limit) || runOverageSold(org));
1211
1215
  /*
1212
1216
  * Only for the organization the site belongs to NOW: the automations
1213
1217
  * were found through the site's org, and a site that changed hands
1214
1218
  * between the two reads runs none of its old organization's.
1215
- */ runOrg = Boolean(placed) && (placed == null ? void 0 : placed.orgId) === (owner == null ? void 0 : owner.orgId) && !(used + (runSite ? actions.length : 0) + ((_ref2 = placed == null ? void 0 : placed.docs.length) != null ? _ref2 : 0) > limit);
1219
+ */ runOrg = Boolean(placed) && (placed == null ? void 0 : placed.orgId) === (owner == null ? void 0 : owner.orgId) && (!(used + (runSite ? actions.length : 0) + ((_ref2 = placed == null ? void 0 : placed.docs.length) != null ? _ref2 : 0) > limit) || // Org automations run past the band on the same terms as the
1220
+ // site's actions (pricing v4, `runOverageSold`).
1221
+ runOverageSold(org));
1216
1222
  if (!runSite && !runOrg) return alerts;
1217
1223
  }
1218
1224
  const env = {
@@ -1374,7 +1380,9 @@ export function makeWorkflowContextLoader(hostRef) {
1374
1380
  webhooksAllowed = checkEntitlement(org, 'webhooks');
1375
1381
  const limit = resolveOrgEntitlements(org).actionRunsPerMonth;
1376
1382
  const used = await runsUsedThisMonth(meter);
1377
- if (used + 1 > limit) return skipped('allowance', limit);
1383
+ if (used + 1 > limit && !runOverageSold(org)) {
1384
+ return skipped('allowance', limit);
1385
+ }
1378
1386
  }
1379
1387
  const env = {
1380
1388
  hostId,