@aglyn/aglyn 1.0.0-beta.219 → 1.0.0-beta.221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/package.json +12 -12
  2. package/src/lib/app-utils/actions.d.ts +1 -59
  3. package/src/lib/app-utils/actions.js +7 -72
  4. package/src/lib/app-utils/actions.js.map +1 -1
  5. package/src/lib/app-utils/consent-groups.d.ts +1 -1
  6. package/src/lib/app-utils/consent-groups.js.map +1 -1
  7. package/src/lib/app-utils/console-routes.d.ts +0 -36
  8. package/src/lib/app-utils/console-routes.js +2 -37
  9. package/src/lib/app-utils/console-routes.js.map +1 -1
  10. package/src/lib/app-utils/contacts.d.ts +1 -1
  11. package/src/lib/app-utils/contacts.js.map +1 -1
  12. package/src/lib/app-utils/container-membership.d.ts +93 -0
  13. package/src/lib/app-utils/container-membership.js +165 -0
  14. package/src/lib/app-utils/container-membership.js.map +1 -0
  15. package/src/lib/app-utils/crm-task-reminders.d.ts +23 -6
  16. package/src/lib/app-utils/crm-task-reminders.js +32 -11
  17. package/src/lib/app-utils/crm-task-reminders.js.map +1 -1
  18. package/src/lib/app-utils/crm.d.ts +24 -4
  19. package/src/lib/app-utils/crm.js +23 -0
  20. package/src/lib/app-utils/crm.js.map +1 -1
  21. package/src/lib/app-utils/csv-upload.d.ts +1 -1
  22. package/src/lib/app-utils/csv-upload.js +1 -1
  23. package/src/lib/app-utils/csv-upload.js.map +1 -1
  24. package/src/lib/app-utils/{dataset-csv.d.ts → csv.d.ts} +10 -43
  25. package/src/lib/app-utils/{dataset-csv.js → csv.js} +10 -81
  26. package/src/lib/app-utils/csv.js.map +1 -0
  27. package/src/lib/app-utils/datasets.d.ts +0 -19
  28. package/src/lib/app-utils/datasets.js +0 -13
  29. package/src/lib/app-utils/datasets.js.map +1 -1
  30. package/src/lib/app-utils/docs-help.generated.d.ts +4 -4
  31. package/src/lib/app-utils/docs-help.generated.js +5 -0
  32. package/src/lib/app-utils/docs-help.generated.js.map +1 -1
  33. package/src/lib/app-utils/docs-index.generated.js +71 -36
  34. package/src/lib/app-utils/docs-index.generated.js.map +1 -1
  35. package/src/lib/app-utils/dynamic-list-rule.js +3 -3
  36. package/src/lib/app-utils/dynamic-list-rule.js.map +1 -1
  37. package/src/lib/app-utils/email-text.d.ts +80 -0
  38. package/src/lib/app-utils/email-text.js +189 -0
  39. package/src/lib/app-utils/email-text.js.map +1 -0
  40. package/src/lib/app-utils/{list-assignment-policy.d.ts → enrollment-basis.d.ts} +4 -0
  41. package/src/lib/app-utils/{list-assignment-policy.js → enrollment-basis.js} +5 -1
  42. package/src/lib/app-utils/enrollment-basis.js.map +1 -0
  43. package/src/lib/app-utils/expand-repeatables.js +4 -4
  44. package/src/lib/app-utils/expand-repeatables.js.map +1 -1
  45. package/src/lib/app-utils/forms.js +2 -2
  46. package/src/lib/app-utils/forms.js.map +1 -1
  47. package/src/lib/app-utils/health-report.d.ts +2 -3
  48. package/src/lib/app-utils/health-report.js +30 -6
  49. package/src/lib/app-utils/health-report.js.map +1 -1
  50. package/src/lib/app-utils/inbound-mail-domain.d.ts +27 -0
  51. package/src/lib/app-utils/inbound-mail-domain.js +31 -0
  52. package/src/lib/app-utils/inbound-mail-domain.js.map +1 -0
  53. package/src/lib/app-utils/leaving-notice.d.ts +96 -0
  54. package/src/lib/app-utils/leaving-notice.js +157 -0
  55. package/src/lib/app-utils/leaving-notice.js.map +1 -0
  56. package/src/lib/app-utils/lockdown.d.ts +11 -0
  57. package/src/lib/app-utils/lockdown.js +33 -3
  58. package/src/lib/app-utils/lockdown.js.map +1 -1
  59. package/src/lib/app-utils/member-email-aliases.d.ts +25 -0
  60. package/src/lib/app-utils/member-email-aliases.js +29 -0
  61. package/src/lib/app-utils/member-email-aliases.js.map +1 -1
  62. package/src/lib/app-utils/notifications.d.ts +69 -0
  63. package/src/lib/app-utils/notifications.js +119 -0
  64. package/src/lib/app-utils/notifications.js.map +1 -1
  65. package/src/lib/app-utils/operator-alerts.d.ts +15 -1
  66. package/src/lib/app-utils/operator-alerts.js +64 -10
  67. package/src/lib/app-utils/operator-alerts.js.map +1 -1
  68. package/src/lib/app-utils/plan-entitlements.d.ts +164 -178
  69. package/src/lib/app-utils/plan-entitlements.js +200 -224
  70. package/src/lib/app-utils/plan-entitlements.js.map +1 -1
  71. package/src/lib/app-utils/platform-marketing-consent.d.ts +56 -2
  72. package/src/lib/app-utils/platform-marketing-consent.js +6 -5
  73. package/src/lib/app-utils/platform-marketing-consent.js.map +1 -1
  74. package/src/lib/app-utils/plugin-starter-templates.generated.d.ts +12 -0
  75. package/src/lib/app-utils/plugin-starter-templates.generated.js +711 -0
  76. package/src/lib/app-utils/plugin-starter-templates.generated.js.map +1 -0
  77. package/src/lib/app-utils/repeat-query.d.ts +56 -0
  78. package/src/lib/app-utils/{dataset-query.js → repeat-query.js} +16 -16
  79. package/src/lib/app-utils/repeat-query.js.map +1 -0
  80. package/src/lib/app-utils/screen-link-context-value.d.ts +7 -0
  81. package/src/lib/app-utils/screen-link-context-value.js.map +1 -1
  82. package/src/lib/app-utils/screen-link-context.js +14 -2
  83. package/src/lib/app-utils/screen-link-context.js.map +1 -1
  84. package/src/lib/app-utils/screen-route.d.ts +3 -0
  85. package/src/lib/app-utils/screen-route.js +6 -1
  86. package/src/lib/app-utils/screen-route.js.map +1 -1
  87. package/src/lib/app-utils/server.d.ts +7 -9
  88. package/src/lib/app-utils/server.js +18 -26
  89. package/src/lib/app-utils/server.js.map +1 -1
  90. package/src/lib/app-utils/starter-template-nodes.d.ts +137 -0
  91. package/src/lib/app-utils/starter-template-nodes.js +129 -0
  92. package/src/lib/app-utils/starter-template-nodes.js.map +1 -0
  93. package/src/lib/app-utils/starter-templates.d.ts +11 -34
  94. package/src/lib/app-utils/starter-templates.js +19 -230
  95. package/src/lib/app-utils/starter-templates.js.map +1 -1
  96. package/src/lib/app-utils/{email-topics.d.ts → subscription-topics.d.ts} +64 -48
  97. package/src/lib/app-utils/{email-topics.js → subscription-topics.js} +39 -109
  98. package/src/lib/app-utils/subscription-topics.js.map +1 -0
  99. package/src/lib/app-utils/usage-budget.d.ts +73 -188
  100. package/src/lib/app-utils/usage-budget.js +58 -194
  101. package/src/lib/app-utils/usage-budget.js.map +1 -1
  102. package/src/lib/app-utils/utm-attribution.d.ts +1 -1
  103. package/src/lib/app-utils/utm-attribution.js +1 -1
  104. package/src/lib/app-utils/utm-attribution.js.map +1 -1
  105. package/src/lib/app-utils/{campaign-touch.d.ts → utm-touch.d.ts} +21 -13
  106. package/src/lib/app-utils/{campaign-touch.js → utm-touch.js} +30 -22
  107. package/src/lib/app-utils/utm-touch.js.map +1 -0
  108. package/src/lib/app-utils/variables.d.ts +9 -9
  109. package/src/lib/app-utils/variables.js.map +1 -1
  110. package/src/lib/app-utils/visitor-record-ceiling.d.ts +32 -0
  111. package/src/lib/app-utils/visitor-record-ceiling.js +39 -0
  112. package/src/lib/app-utils/visitor-record-ceiling.js.map +1 -1
  113. package/src/lib/foundation/definitions/org-billing.types.d.ts +2 -2
  114. package/src/lib/foundation/definitions/org-billing.types.js.map +1 -1
  115. package/src/lib/plugin-manager/feature-plugins.d.ts +80 -79
  116. package/src/lib/plugin-manager/feature-plugins.js +22 -35
  117. package/src/lib/plugin-manager/feature-plugins.js.map +1 -1
  118. package/src/lib/plugin-manager/first-party-plugins.generated.d.ts +18 -1
  119. package/src/lib/plugin-manager/first-party-plugins.generated.js +62 -2
  120. package/src/lib/plugin-manager/first-party-plugins.generated.js.map +1 -1
  121. package/src/lib/plugin-manager/index.d.ts +0 -1
  122. package/src/lib/plugin-manager/index.js +0 -1
  123. package/src/lib/plugin-manager/index.js.map +1 -1
  124. package/src/lib/plugin-manager/plugin-contact-capture.d.ts +9 -4
  125. package/src/lib/plugin-manager/plugin-contact-capture.js.map +1 -1
  126. package/src/lib/plugin-manager/plugin-containers.d.ts +68 -0
  127. package/src/lib/plugin-manager/plugin-containers.generated.d.ts +10 -0
  128. package/src/lib/plugin-manager/plugin-containers.generated.js +20 -0
  129. package/src/lib/plugin-manager/plugin-containers.generated.js.map +1 -0
  130. package/src/lib/plugin-manager/plugin-containers.js +27 -0
  131. package/src/lib/plugin-manager/plugin-containers.js.map +1 -0
  132. package/src/lib/plugin-manager/plugin-entitlements.d.ts +8 -0
  133. package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
  134. package/src/lib/plugin-manager/plugin-membership-detach.js +1 -1
  135. package/src/lib/plugin-manager/plugin-membership-detach.js.map +1 -1
  136. package/src/lib/plugin-manager/plugin-record-email-state.d.ts +69 -0
  137. package/src/lib/plugin-manager/plugin-record-email-state.js +32 -0
  138. package/src/lib/plugin-manager/plugin-record-email-state.js.map +1 -1
  139. package/src/lib/plugin-manager/plugin-record-lists.d.ts +115 -0
  140. package/src/lib/plugin-manager/plugin-record-lists.js +75 -0
  141. package/src/lib/plugin-manager/plugin-record-lists.js.map +1 -0
  142. package/src/lib/plugin-manager/plugin-record-timeline.d.ts +42 -8
  143. package/src/lib/plugin-manager/plugin-record-timeline.js.map +1 -1
  144. package/src/lib/plugin-manager/plugin-server-steps.d.ts +170 -0
  145. package/src/lib/plugin-manager/plugin-server-steps.js +116 -0
  146. package/src/lib/plugin-manager/plugin-server-steps.js.map +1 -0
  147. package/src/lib/plugin-manager/plugin-site-beacons.d.ts +71 -0
  148. package/src/lib/plugin-manager/plugin-site-beacons.js +54 -0
  149. package/src/lib/plugin-manager/plugin-site-beacons.js.map +1 -0
  150. package/src/lib/plugin-manager/plugin-subscription-topics.generated.d.ts +11 -0
  151. package/src/lib/plugin-manager/plugin-subscription-topics.generated.js +41 -0
  152. package/src/lib/plugin-manager/plugin-subscription-topics.generated.js.map +1 -0
  153. package/src/lib/plugin-manager/plugin-usage-axes.d.ts +212 -0
  154. package/src/lib/plugin-manager/plugin-usage-axes.js +82 -3
  155. package/src/lib/plugin-manager/plugin-usage-axes.js.map +1 -1
  156. package/src/lib/plugin-manager/plugin-usage-meters.d.ts +108 -0
  157. package/src/lib/plugin-manager/plugin-usage-meters.js +105 -0
  158. package/src/lib/plugin-manager/plugin-usage-meters.js.map +1 -0
  159. package/src/lib/plugin-manager/usage-alert-contributors.d.ts +76 -6
  160. package/src/lib/plugin-manager/usage-alert-contributors.js +23 -10
  161. package/src/lib/plugin-manager/usage-alert-contributors.js.map +1 -1
  162. package/src/lib/app-utils/assist-credits.d.ts +0 -482
  163. package/src/lib/app-utils/assist-credits.js +0 -510
  164. package/src/lib/app-utils/assist-credits.js.map +0 -1
  165. package/src/lib/app-utils/campaign-membership.d.ts +0 -121
  166. package/src/lib/app-utils/campaign-membership.js +0 -189
  167. package/src/lib/app-utils/campaign-membership.js.map +0 -1
  168. package/src/lib/app-utils/campaign-touch.js.map +0 -1
  169. package/src/lib/app-utils/console-record-links.d.ts +0 -84
  170. package/src/lib/app-utils/console-record-links.js +0 -76
  171. package/src/lib/app-utils/console-record-links.js.map +0 -1
  172. package/src/lib/app-utils/crm-booking.d.ts +0 -75
  173. package/src/lib/app-utils/crm-booking.js +0 -133
  174. package/src/lib/app-utils/crm-booking.js.map +0 -1
  175. package/src/lib/app-utils/crm-inbound.d.ts +0 -245
  176. package/src/lib/app-utils/crm-inbound.js +0 -407
  177. package/src/lib/app-utils/crm-inbound.js.map +0 -1
  178. package/src/lib/app-utils/crm-reports.d.ts +0 -479
  179. package/src/lib/app-utils/crm-reports.js +0 -680
  180. package/src/lib/app-utils/crm-reports.js.map +0 -1
  181. package/src/lib/app-utils/dataset-csv.js.map +0 -1
  182. package/src/lib/app-utils/dataset-query.d.ts +0 -57
  183. package/src/lib/app-utils/dataset-query.js.map +0 -1
  184. package/src/lib/app-utils/email-topics.js.map +0 -1
  185. package/src/lib/app-utils/list-assignment-policy.js.map +0 -1
  186. package/src/lib/plugin-manager/plugin-metered-lines.d.ts +0 -97
  187. package/src/lib/plugin-manager/plugin-metered-lines.js +0 -123
  188. package/src/lib/plugin-manager/plugin-metered-lines.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/aglyn",
3
- "version": "1.0.0-beta.219",
3
+ "version": "1.0.0-beta.221",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -33,16 +33,16 @@
33
33
  "./package.json": "./package.json"
34
34
  },
35
35
  "dependencies": {
36
- "@aglyn/shared-data-enums": "1.0.0-beta.219",
37
- "@aglyn/shared-data-mdi": "1.0.0-beta.219",
38
- "@aglyn/shared-data-types": "1.0.0-beta.219",
39
- "@aglyn/shared-util-email": "1.0.0-beta.219",
40
- "@aglyn/shared-util-first-touch": "1.0.0-beta.219",
41
- "@aglyn/shared-util-http": "1.0.0-beta.219",
42
- "@aglyn/shared-util-logger": "1.0.0-beta.219",
43
- "@aglyn/shared-util-timestamp": "1.0.0-beta.219",
44
- "@aglyn/shared-util-tools": "1.0.0-beta.219",
45
- "@aglyn/shared-util-vendor": "1.0.0-beta.219",
36
+ "@aglyn/shared-data-enums": "1.0.0-beta.221",
37
+ "@aglyn/shared-data-mdi": "1.0.0-beta.221",
38
+ "@aglyn/shared-data-types": "1.0.0-beta.221",
39
+ "@aglyn/shared-util-email": "1.0.0-beta.221",
40
+ "@aglyn/shared-util-first-touch": "1.0.0-beta.221",
41
+ "@aglyn/shared-util-http": "1.0.0-beta.221",
42
+ "@aglyn/shared-util-logger": "1.0.0-beta.221",
43
+ "@aglyn/shared-util-timestamp": "1.0.0-beta.221",
44
+ "@aglyn/shared-util-tools": "1.0.0-beta.221",
45
+ "@aglyn/shared-util-vendor": "1.0.0-beta.221",
46
46
  "@data-driven-forms/react-form-renderer": "^4.2.0",
47
47
  "@msgpack/msgpack": "^3.1.3",
48
48
  "@types/unist": "^3.0.3",
@@ -58,7 +58,7 @@
58
58
  "@mui/material": "^9.3.1",
59
59
  "@mui/system": "^9.2.0",
60
60
  "firebase": "^12.18.0",
61
- "next": "16.3.3",
61
+ "next": "^16.3.3",
62
62
  "react": "^19.2.8"
63
63
  },
64
64
  "peerDependenciesMeta": {
@@ -163,18 +163,6 @@ export type HostActionStep = ClientInteractionStep | ServerActionStep;
163
163
  */
164
164
  export declare const FLOW_SUSPENDING_STEP_TYPES: ReadonlySet<HostActionStepType>;
165
165
  export declare function isFlowSuspendingStep(step: HostActionStep): boolean;
166
- /**
167
- * The steps that act on the CRM (AGL-2605) — named as a set because the
168
- * executor dispatches all five to one module and the docs list them as one
169
- * group, and a step added to the union but not here would be a server step
170
- * the executor silently skipped.
171
- */
172
- export declare const CRM_ACTION_STEP_TYPES: ReadonlySet<HostActionStepType>;
173
- /** The CRM steps, as the type the executor narrows to. */
174
- export type CrmActionStep = Extract<HostActionStep, {
175
- type: 'setContactStage' | 'addContactTag' | 'assignContactOwner' | 'createCrmTask' | 'logCrmActivity';
176
- }>;
177
- export declare function isCrmActionStep(step: HostActionStep): step is CrmActionStep;
178
166
  /** Longest tag an automation may write — the console's own tag field cap. */
179
167
  export declare const CONTACT_TAG_MAX_LENGTH = 60;
180
168
  export declare const CRM_ACTION_RECIPE_IDS: readonly ["welcomeNewLead", "followUpWonDeal", "reengageStaleLead", "tagByForm"];
@@ -295,8 +283,6 @@ export interface HostAction extends SiteInteraction<HostActionStep> {
295
283
  */
296
284
  recipe?: CrmActionRecipeId | null;
297
285
  }
298
- /** Custom-event chaining depth cap (mirrors CROSS_MAX_DEPTH). */
299
- export declare const ACTION_MAX_EVENT_DEPTH = 3;
300
286
  /**
301
287
  * The shortest and longest a flow may wait.
302
288
  *
@@ -311,31 +297,6 @@ export declare const ACTION_MAX_EVENT_DEPTH = 3;
311
297
  export declare const FLOW_WAIT_MIN_MINUTES = 1;
312
298
  export declare const FLOW_WAIT_MAX_MINUTES: number;
313
299
  export declare const HOST_ACTION_STEP_LABELS: Record<HostActionStepType, string>;
314
- /**
315
- * Past-tense phrases for a run summary (AGL-2171).
316
- *
317
- * `HOST_ACTION_STEP_LABELS` above names what a step WILL do, in the
318
- * imperative, for a `Do` select — "Send an email". A run history is the
319
- * opposite tense and a different audience: it says what already happened,
320
- * on one line, several steps at a time. `/product/workflows` advertises
321
- * exactly that shape — `Sent email · saved to Leads · webhook 200`.
322
- *
323
- * Two maps rather than one derived from the other, because "Send a webhook
324
- * (Business)" cannot be mechanically turned into "webhook" — the plan
325
- * suffix is part of the picker's label and has no business in a log line.
326
- * Only the steps a SERVER run can perform appear here; the client-side
327
- * steps run in the visitor's browser and never reach the activity write.
328
- */
329
- export declare const HOST_ACTION_STEP_OUTCOMES: Partial<Record<HostActionStepType, string>>;
330
- /**
331
- * One step's line in a run summary, with the detail that makes it useful.
332
- *
333
- * `saved to Leads` beats `saved to dataset`, and `webhook 200` beats
334
- * `webhook` — the status code is the entire reason anyone opens a run
335
- * history after a webhook, and it was being discarded on the line it
336
- * arrived.
337
- */
338
- export declare function describeStepOutcome(type: HostActionStepType, detail?: string): string;
339
300
  /** A whole number of minutes inside the wait band. */
340
301
  export declare function isFlowWaitMinutes(value: unknown): boolean;
341
302
  /** True for a custom (non-built-in) event name an action may fire. */
@@ -345,24 +306,5 @@ export declare function isCustomEventName(event: string): boolean;
345
306
  * Server and console share this so bad steps never persist or run.
346
307
  */
347
308
  export declare function validateHostAction(action: HostAction): string | null;
348
- /**
349
- * Webhooks (AGL-149) at `hosts/{hostId}/webhooks/{id}`. Outbound entries
350
- * are targets a `webhookPost` action step delivers to (HMAC-signed);
351
- * inbound entries mint `/api/hooks/{hostId}/{hookId}` endpoints that run
352
- * a workflow with the posted JSON in scope. Business tier (`webhooks`
353
- * flag); Pro can be enabled per-tenant via entitlement overrides.
354
- */
355
- export interface HostWebhook {
356
- name: string;
357
- direction: 'outbound' | 'inbound';
358
- /** Outbound delivery URL (https only; checked again at send time). */
359
- url?: string;
360
- /** Shared secret: signs outbound bodies, verifies inbound callers. */
361
- secret?: string;
362
- /** Inbound: workflow (by name) enrolled with the payload in scope. */
363
- workflowName?: string;
364
- enabled?: boolean;
365
- }
309
+ /** The most webhooks one site keeps; the site create route enforces it. */
366
310
  export declare const WEBHOOK_MAX_PER_HOST = 5;
367
- /** Outbound URLs must be public https — first-line SSRF guard. */
368
- export declare const WEBHOOK_URL_PATTERN: RegExp;
@@ -54,21 +54,6 @@ import { HOST_EVENT_TYPES } from "./host-events.js";
54
54
  export function isFlowSuspendingStep(step) {
55
55
  return FLOW_SUSPENDING_STEP_TYPES.has(step.type);
56
56
  }
57
- /**
58
- * The steps that act on the CRM (AGL-2605) — named as a set because the
59
- * executor dispatches all five to one module and the docs list them as one
60
- * group, and a step added to the union but not here would be a server step
61
- * the executor silently skipped.
62
- */ export const CRM_ACTION_STEP_TYPES = new Set([
63
- 'setContactStage',
64
- 'addContactTag',
65
- 'assignContactOwner',
66
- 'createCrmTask',
67
- 'logCrmActivity'
68
- ]);
69
- export function isCrmActionStep(step) {
70
- return CRM_ACTION_STEP_TYPES.has(step.type);
71
- }
72
57
  /** Longest tag an automation may write — the console's own tag field cap. */ export const CONTACT_TAG_MAX_LENGTH = 60;
73
58
  /*
74
59
  * THE RECIPES (AGL-2626).
@@ -125,6 +110,11 @@ export const CRM_ACTION_RECIPES = [
125
110
  * The email comes before any wait, which makes it an immediate reply to
126
111
  * what the visitor just did — transactional, sent from the org's own
127
112
  * identity, to the address the event carries.
113
+ *
114
+ * Its words promise no response time. The org hub installs this recipe
115
+ * into a site without its editor opening, so the business never reads
116
+ * the sentence it is sending, and a "within a day" written here would be
117
+ * a commitment made on its behalf that nothing in the run keeps.
128
118
  */ build: ()=>({
129
119
  recipe: 'welcomeNewLead',
130
120
  name: 'Welcome a new lead',
@@ -153,7 +143,7 @@ export const CRM_ACTION_RECIPES = [
153
143
  {
154
144
  type: 'sendEmail',
155
145
  subject: 'Thanks for getting in touch',
156
- body: 'Thanks for reaching out — we have your message, and someone ' + 'from our team will be in touch within a day.'
146
+ body: 'Thanks for reaching out. We have your message and will reply ' + 'to this email address.'
157
147
  },
158
148
  {
159
149
  type: 'addContactTag',
@@ -335,7 +325,6 @@ export function hostActionDocument(action) {
335
325
  ...suspendAt < 0 ? list : list.slice(0, suspendAt)
336
326
  ];
337
327
  }
338
- /** Custom-event chaining depth cap (mirrors CROSS_MAX_DEPTH). */ export const ACTION_MAX_EVENT_DEPTH = 3;
339
328
  /**
340
329
  * The shortest and longest a flow may wait.
341
330
  *
@@ -390,59 +379,6 @@ export const HOST_ACTION_STEP_LABELS = {
390
379
  createCrmTask: 'Create a CRM task',
391
380
  logCrmActivity: 'Log a CRM activity'
392
381
  };
393
- /**
394
- * Past-tense phrases for a run summary (AGL-2171).
395
- *
396
- * `HOST_ACTION_STEP_LABELS` above names what a step WILL do, in the
397
- * imperative, for a `Do` select — "Send an email". A run history is the
398
- * opposite tense and a different audience: it says what already happened,
399
- * on one line, several steps at a time. `/product/workflows` advertises
400
- * exactly that shape — `Sent email · saved to Leads · webhook 200`.
401
- *
402
- * Two maps rather than one derived from the other, because "Send a webhook
403
- * (Business)" cannot be mechanically turned into "webhook" — the plan
404
- * suffix is part of the picker's label and has no business in a log line.
405
- * Only the steps a SERVER run can perform appear here; the client-side
406
- * steps run in the visitor's browser and never reach the activity write.
407
- */ export const HOST_ACTION_STEP_OUTCOMES = {
408
- runWorkflow: 'ran workflow',
409
- siteAlert: 'showed an alert',
410
- customEvent: 'fired an event',
411
- datasetAppend: 'saved to dataset',
412
- updateDataset: 'updated dataset',
413
- webhookPost: 'webhook',
414
- sendEmail: 'sent email',
415
- notifyAdmins: 'notified admins',
416
- enrollList: 'enrolled in list',
417
- assignCampaign: 'assigned to campaign',
418
- wait: 'waiting',
419
- waitForEvent: 'waiting for',
420
- exitFlow: 'ended the flow',
421
- setContactStage: 'set stage',
422
- addContactTag: 'tagged',
423
- assignContactOwner: 'assigned owner',
424
- createCrmTask: 'created task',
425
- logCrmActivity: 'logged activity'
426
- };
427
- /**
428
- * One step's line in a run summary, with the detail that makes it useful.
429
- *
430
- * `saved to Leads` beats `saved to dataset`, and `webhook 200` beats
431
- * `webhook` — the status code is the entire reason anyone opens a run
432
- * history after a webhook, and it was being discarded on the line it
433
- * arrived.
434
- */ export function describeStepOutcome(type, detail) {
435
- var _HOST_ACTION_STEP_OUTCOMES_type;
436
- const base = (_HOST_ACTION_STEP_OUTCOMES_type = HOST_ACTION_STEP_OUTCOMES[type]) != null ? _HOST_ACTION_STEP_OUTCOMES_type : String(type);
437
- const trimmed = detail == null ? void 0 : detail.trim();
438
- if (!trimmed) return base;
439
- if (type === 'datasetAppend' || type === 'updateDataset') {
440
- // `saved to dataset` + `Leads` reads as `saved to Leads`, not
441
- // `saved to dataset Leads`.
442
- return `${base.replace(/ dataset$/, '')} ${trimmed}`;
443
- }
444
- return `${base} ${trimmed}`;
445
- }
446
382
  /** A whole number of minutes inside the wait band. */ export function isFlowWaitMinutes(value) {
447
383
  return Number.isInteger(value) && value >= FLOW_WAIT_MIN_MINUTES && value <= FLOW_WAIT_MAX_MINUTES;
448
384
  }
@@ -565,7 +501,6 @@ export const HOST_ACTION_STEP_LABELS = {
565
501
  }
566
502
  return null;
567
503
  }
568
- export const WEBHOOK_MAX_PER_HOST = 5;
569
- /** Outbound URLs must be public https — first-line SSRF guard. */ export const WEBHOOK_URL_PATTERN = /^https:\/\/(?!localhost)(?!127\.)(?!0\.)(?!10\.)(?!172\.(1[6-9]|2\d|3[01])\.)(?!192\.168\.)(?!169\.254\.)[^\s]+$/i;
504
+ /** The most webhooks one site keeps; the site create route enforces it. */ export const WEBHOOK_MAX_PER_HOST = 5;
570
505
 
571
506
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/actions.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 {\n type ContactLifecycleStage,\n CRM_TASK_MAX_DUE_DAYS,\n type CrmActivityKind,\n type CrmTaskKind,\n isContactLifecycleStage,\n isCrmActivityKind,\n isCrmTaskKind,\n} from './crm-kinds'\nimport {\n type ClientInteractionStep,\n CUSTOM_EVENT_PATTERN,\n type InteractionCondition,\n type InteractionStepGuard,\n type InteractionTrigger,\n type SiteAlert,\n type SiteInteraction,\n type TriggerCombinator,\n validateInteraction,\n} from './site-interactions'\nimport { HOST_EVENT_TYPES } from './host-events'\n\n/**\n * Actions builder (AGL-148): HubSpot-style event → action automation on\n * top of the AGL-128 event triggers. An action listens for a host event\n * (built-in or a custom name fired by another action), optionally filters\n * on the payload, and runs an ordered step list. Pure types + validation\n * here; the executor lives in the workflows plugin, where the I/O is.\n *\n * An action is a SITE INTERACTION (`site-interactions.ts`) with server steps\n * added: its trigger, its conditions, its client steps and its storage are\n * the platform's, and are re-exported here for the readers that take both\n * from this module. What is declared below is the automation's own — the\n * server steps, flows, recipes and webhooks.\n */\nexport * from './site-interactions'\n\n/** The automation's names for the platform's interaction shapes. */\nexport type HostActionTriggerCondition = InteractionCondition\nexport type HostActionTrigger = InteractionTrigger\nexport type HostActionStepGuard = InteractionStepGuard\n/** Alert produced by a `siteAlert` step, surfaced to the emitting client. */\nexport type HostActionAlert = SiteAlert\n\n/**\n * The scope key a resumed flow carries to say the wait ended on the CLOCK\n * rather than on the event it was watching for.\n *\n * This is how a `waitForEvent` gets its timeout branch without a nested step\n * list: the flow resumes either way, and the step after it carries a `when`\n * naming this field. Underscored because it shares a namespace with the\n * event payload's own fields, which are merchant-authored form field names.\n */\nexport const FLOW_TIMED_OUT_FIELD = '_waitTimedOut'\n\n/** The steps an automation adds to the platform's client steps: the server's, run by the workflows plugin. */\ntype ServerActionStep = (\n // Entity references carry a doc id (AGL-261, rename-safe) with the name\n // kept as a display hint; pre-AGL-261 docs have only the name and the\n // executor resolves either.\n | { type: 'runWorkflow'; workflowId?: string; workflowName?: string }\n | { type: 'customEvent'; eventName: string }\n | { type: 'datasetAppend'; datasetId?: string; datasetName?: string }\n | { type: 'webhookPost'; webhookId?: string; webhookName?: string }\n // Server-side steps (AGL-257).\n | {\n type: 'sendEmail'\n subject: string\n body: string\n toField?: string\n /**\n * The stream this message belongs to, so a recipient who left it is not\n * mailed. Absent on every step authored before topics reached the\n * actions editor, which the executor resolves to the default topic.\n */\n topicId?: string\n }\n | { type: 'notifyAdmins'; title: string; body?: string }\n | { type: 'enrollList'; listId?: string; listName?: string }\n | { type: 'updateDataset'; datasetId?: string; datasetName?: string }\n | { type: 'assignCampaign'; campaignId?: string; campaignName?: string }\n /*\n * THE THREE FLOW STEPS.\n *\n * `wait` is the one that matters: without a durable delay an automation is\n * always trigger → immediate actions, so no welcome series, win-back or\n * post-purchase follow-up can exist at all. The other two are what make a\n * delay useful — something to end the flow early, and a wait that ends on\n * an event instead of on the clock.\n *\n * All three are SERVER steps. A delay outlives the page view that started\n * it by days, so the browser that fired the trigger is long gone by the time\n * the flow continues; `hostActionStepsForClient` truncates the client's copy\n * of the step list at the first of these for that reason.\n */\n | {\n type: 'wait'\n /** Whole minutes to hold before the next step. */\n delayMinutes: number\n }\n | {\n type: 'waitForEvent'\n /** The host or custom event that resumes this person's flow. */\n eventName: string\n /**\n * Whole minutes after which the flow continues anyway, with\n * {@link FLOW_TIMED_OUT_FIELD} true in scope. There is always a\n * deadline: a wait with no timeout is an enrollment that lives forever.\n */\n timeoutMinutes: number\n }\n /** Ends the enrollment here. Paired with a `when`, this is the exit branch. */\n | { type: 'exitFlow' }\n /*\n * THE CRM STEPS (AGL-2605).\n *\n * Server steps, every one, because each writes a record only the Admin\n * SDK may write on a visitor's behalf. Each acts on ONE person — the\n * contact the event names, resolved by `contactId` when the payload\n * carries one and by `email` otherwise — and each writes inside the\n * site's own facet or stamps the site's own scope, for the reason\n * `assignCampaign` gives: a contact row is shared by every site in the\n * org, and a stage or a tag is one holder's business record. A step whose\n * event names nobody the site can see does nothing and says so in the run.\n *\n * None of them carries a doc-id reference for the reference audit to\n * check: a stage and a kind are fixed vocabularies, a tag is free text,\n * and an owner is a member who is resolved at run time.\n */\n | { type: 'setContactStage'; lifecycleStage: ContactLifecycleStage }\n | { type: 'addContactTag'; tag: string }\n /**\n * The owner by uid when a member id was typed or a picker wrote the step,\n * by email when an address was typed; the executor resolves either against\n * the org's roster, and only the roster (AGL-2614).\n * Or `roundRobin`, and the owner is the next member of the pool the CRM's\n * settings keep (AGL-2618) — a step that names nobody and hands the\n * choice to the rotation, so a stage change can spread its follow-ups\n * across a team rather than pile them on one rep. The two are exclusive:\n * a rotation step carries no member, and the validator refuses one that\n * names both.\n */\n | {\n type: 'assignContactOwner'\n ownerUid?: string\n ownerEmail?: string\n roundRobin?: boolean\n }\n | {\n type: 'createCrmTask'\n title: string\n kind: CrmTaskKind\n /** Days from the run to the due date; `0` is due today. */\n dueInDays: number\n /**\n * Who gets it — by uid or by an address, both resolved against the\n * roster the way the owner step's are. Neither named, the task goes\n * to the contact's owner, then to nobody.\n */\n assigneeUid?: string\n assigneeEmail?: string\n }\n | { type: 'logCrmActivity'; kind: CrmActivityKind; body: string }\n) & {\n /** See {@link InteractionStepGuard}. Absent means the step always runs. */\n when?: InteractionStepGuard | null\n}\n\n/** A step of an automation: one of the platform's client steps, or one of its server steps. */\nexport type HostActionStep = ClientInteractionStep | ServerActionStep\n\n/**\n * The steps that suspend a run and continue it later, from a job beat.\n *\n * Named as a set rather than checked inline because three surfaces have to\n * agree on it: the executor stops here and writes an enrollment, the client\n * payload is truncated here, and the validator refuses a flow that waits\n * without a person to wait for.\n */\nexport const FLOW_SUSPENDING_STEP_TYPES: ReadonlySet<HostActionStepType> =\n new Set(['wait', 'waitForEvent'] as const)\n\nexport function isFlowSuspendingStep(step: HostActionStep): boolean {\n return FLOW_SUSPENDING_STEP_TYPES.has(step.type)\n}\n\n/**\n * The steps that act on the CRM (AGL-2605) — named as a set because the\n * executor dispatches all five to one module and the docs list them as one\n * group, and a step added to the union but not here would be a server step\n * the executor silently skipped.\n */\nexport const CRM_ACTION_STEP_TYPES: ReadonlySet<HostActionStepType> = new Set([\n 'setContactStage',\n 'addContactTag',\n 'assignContactOwner',\n 'createCrmTask',\n 'logCrmActivity',\n] as const)\n\n/** The CRM steps, as the type the executor narrows to. */\nexport type CrmActionStep = Extract<\n HostActionStep,\n {\n type:\n | 'setContactStage'\n | 'addContactTag'\n | 'assignContactOwner'\n | 'createCrmTask'\n | 'logCrmActivity'\n }\n>\n\nexport function isCrmActionStep(step: HostActionStep): step is CrmActionStep {\n return CRM_ACTION_STEP_TYPES.has(step.type)\n}\n\n/** Longest tag an automation may write — the console's own tag field cap. */\nexport const CONTACT_TAG_MAX_LENGTH = 60\n\n/*\n * THE RECIPES (AGL-2626).\n *\n * A recipe is a ready-to-edit action — a trigger, its conditions and an\n * ordered step list — built from the vocabulary the editor already offers\n * and handed to the editor as a draft. Nothing is written until the person\n * saves, and every field is theirs to change first: the recipe decides\n * where the editor starts, not what the site runs.\n *\n * Defined here, beside the step catalog, rather than in the builder, so the\n * docs page that lists the recipes and the menu that offers them read ONE\n * list, and so a step the catalog renames or retires breaks a recipe at\n * compile time rather than in a menu nobody tests.\n *\n * Definitions only. Three of the four are complete as written. `tagByForm`\n * needs a form, and a form belongs to a site (`hosts/{hostId}/forms`), so\n * the picker that supplies it is the builder's business and host-scoped by\n * nature. That is the seam an org-level mount keeps: the recipes are the\n * same at either level, and only the form picker knows where it is.\n */\nexport const CRM_ACTION_RECIPE_IDS = [\n 'welcomeNewLead',\n 'followUpWonDeal',\n 'reengageStaleLead',\n 'tagByForm',\n] as const\n\nexport type CrmActionRecipeId = (typeof CRM_ACTION_RECIPE_IDS)[number]\n\n/** What a recipe is handed before it builds — today only the form `tagByForm` reads. */\nexport interface CrmActionRecipeInput {\n form?: { id: string; name: string }\n}\n\nexport interface CrmActionRecipe {\n id: CrmActionRecipeId\n /** How the recipe reads in the menu; also the action's starting name. */\n title: string\n /** One sentence under the title. */\n description: string\n /**\n * What must be picked before the recipe can be built. A recipe that needs\n * nothing opens the editor at once; one that needs a form opens a picker\n * first. Built WITHOUT its pick, such a recipe yields an action the\n * validator refuses — a condition with no value — rather than one that\n * saves and then silently matches nothing.\n */\n needs?: 'form'\n /**\n * A fresh action each call, because the draft is edited in place. The\n * action carries `recipe: id` — the provenance is the builder's to stamp,\n * so a writer that saves what it was handed cannot forget it.\n */\n build: (input?: CrmActionRecipeInput) => HostAction\n}\n\n/**\n * How long the stale-lead recipe holds before it decides a lead has gone\n * quiet. A week: long enough that a rep who is working the lead has had a\n * chance to move its stage, short enough that a lead nobody touched is\n * still warm when the reminder lands.\n */\nexport const STALE_LEAD_WAIT_MINUTES = 7 * 24 * 60\n\n/**\n * The tag a form's captures get: the form's own name, cut to the tag cap.\n * The name is what the person calls the form, so it is the tag they would\n * have typed; the editor is open to change it before anything is saved.\n */\nexport function crmRecipeTagForForm(formName: string): string {\n return formName.trim().slice(0, CONTACT_TAG_MAX_LENGTH)\n}\n\nexport const CRM_ACTION_RECIPES: readonly CrmActionRecipe[] = [\n {\n id: 'welcomeNewLead',\n title: 'Welcome a new lead',\n description:\n 'When a form makes a new contact: rotate in an owner, book a call for ' +\n 'tomorrow, send a thank-you, and tag them website.',\n /*\n * The owner first, because the task that follows names no assignee and\n * so goes to whoever owns the contact when it is created — the member\n * the rotation just chose. Round robin rather than a named member: a\n * recipe cannot know who is on the team, and the pool under CRM →\n * Settings is the one place that does. On a workspace with no pool the\n * step fails and the run continues, so the call, the email and the tag\n * still land and the run history says who was not assigned.\n *\n * The email comes before any wait, which makes it an immediate reply to\n * what the visitor just did — transactional, sent from the org's own\n * identity, to the address the event carries.\n */\n build: () => ({\n recipe: 'welcomeNewLead',\n name: 'Welcome a new lead',\n trigger: {\n event: 'contactCreated',\n conditions: [{ field: 'source', op: 'equals', value: 'form' }],\n combinator: 'and',\n },\n steps: [\n { type: 'assignContactOwner', roundRobin: true },\n {\n type: 'createCrmTask',\n title: 'Call the new lead',\n kind: 'call',\n dueInDays: 1,\n },\n {\n type: 'sendEmail',\n subject: 'Thanks for getting in touch',\n body:\n 'Thanks for reaching out — we have your message, and someone ' +\n 'from our team will be in touch within a day.',\n },\n { type: 'addContactTag', tag: 'website' },\n ],\n enabled: true,\n }),\n },\n {\n id: 'followUpWonDeal',\n title: 'Follow up a won deal',\n description:\n 'When a deal is won — which makes the contact a Customer on its own — ' +\n 'book a check-in call a week out.',\n /*\n * No stage step (AGL-2641): the win itself floors the contact at\n * `customer` before `dealWon` is announced, so a step setting the stage\n * here would at best repeat the write and at worst move an evangelist\n * back to customer — a SET, which is what the step is, and not the\n * floor the win applies. The recipe books the follow-up and nothing\n * else.\n */\n build: () => ({\n recipe: 'followUpWonDeal',\n name: 'Follow up a won deal',\n trigger: { event: 'dealWon' },\n steps: [\n {\n type: 'createCrmTask',\n title: 'Check in with the new customer',\n kind: 'call',\n dueInDays: 7,\n },\n ],\n enabled: true,\n }),\n },\n {\n id: 'reengageStaleLead',\n title: 'Re-engage a stale lead',\n description:\n 'When a contact becomes a lead: wait a week, and if their stage has ' +\n 'not moved, book a call to bring them back.',\n /*\n * \"Unless the stage moved on\" is the wait's own event: the flow watches\n * for the next stage change on this person and gives up after a week.\n * Resumed by the clock, the run carries `_waitTimedOut`, and the task\n * step's guard reads it; resumed by the event, the field is absent and\n * the task is skipped — the lead was worked, and nobody is told to\n * re-engage somebody who just moved to Sales qualified.\n */\n build: () => ({\n recipe: 'reengageStaleLead',\n name: 'Re-engage a stale lead',\n trigger: {\n event: 'contactStageChanged',\n conditions: [{ field: 'lifecycleStage', op: 'equals', value: 'lead' }],\n combinator: 'and',\n },\n steps: [\n {\n type: 'waitForEvent',\n eventName: 'contactStageChanged',\n timeoutMinutes: STALE_LEAD_WAIT_MINUTES,\n },\n {\n type: 'createCrmTask',\n title: 'Re-engage a lead that has gone quiet',\n kind: 'call',\n dueInDays: 1,\n when: {\n conditions: [{ field: FLOW_TIMED_OUT_FIELD, op: 'notEmpty' }],\n },\n },\n ],\n enabled: true,\n }),\n },\n {\n id: 'tagByForm',\n title: 'Tag by form',\n description:\n 'When a form you pick makes a new contact: tag them with the form’s ' +\n 'name.',\n needs: 'form',\n build: (input) => {\n const form = input?.form\n return {\n recipe: 'tagByForm',\n name: form ? `Tag ${form.name.trim()} submissions` : 'Tag by form',\n trigger: {\n event: 'contactCreated',\n conditions: [{ field: 'formId', op: 'equals', value: form?.id ?? '' }],\n combinator: 'and',\n },\n steps: [\n { type: 'addContactTag', tag: form ? crmRecipeTagForForm(form.name) : '' },\n ],\n enabled: true,\n }\n },\n },\n]\n\n/** The recipe with this id, or null for a string that names none. */\nexport function crmActionRecipe(id: unknown): CrmActionRecipe | null {\n return CRM_ACTION_RECIPES.find((recipe) => recipe.id === id) ?? null\n}\n\n/**\n * The recipe a STORED action came from, read off its document (AGL-2639).\n *\n * Three answers, and the third is the one that matters. A known id: the\n * action was installed from, or begun as, that recipe. `null`: the action\n * was begun blank, or from a recipe this build no longer knows — the\n * editor wrote the field and said \"no recipe\". `undefined`: the document\n * carries no `recipe` field at all, which is every action saved before the\n * stamp existed. Such an action may well have started from a recipe — the\n * menu opened the editor prefilled long before anything recorded it — so a\n * reader that needs to know whether a site has a recipe treats `undefined`\n * as UNKNOWN, never as absent, and never writes a `null` over it.\n */\nexport function hostActionRecipeId(\n action: { recipe?: unknown } | null | undefined,\n): CrmActionRecipeId | null | undefined {\n const stamp = action?.recipe\n if (stamp === undefined) return undefined\n return crmActionRecipe(stamp)?.id ?? null\n}\n\n/**\n * A HostAction as the document at `hosts/{hostId}/actions/{id}` holds it.\n *\n * Every optional trigger key is written OUT — a boolean cap as `false`, a\n * cleared list as `null` — because the editor saves with a merge-set, and\n * a merge keeps whatever key the payload omits: a frequency cap switched\n * off, left out of the payload, would stay on. The legacy single\n * `condition` is always nulled; `conditions` has been canonical since the\n * list shape arrived and a document that carried both would have the\n * reader pick. Everything else is the action, unchanged.\n *\n * `recipe` rides along only when the action SAYS something about it: an\n * id or `null`. An action that carries no stamp (an older document, edited\n * and saved again) keeps carrying none — see {@link hostActionRecipeId}\n * for why an absent stamp must not become a `null` one.\n */\nexport interface HostActionDocument extends HostAction {\n trigger: HostActionTrigger & {\n oncePerVisitor: boolean\n oncePerSession: boolean\n cooldownMinutes: number | null\n everyTime: boolean\n condition: null\n conditions: HostActionTriggerCondition[] | null\n combinator: TriggerCombinator | null\n }\n enabled: boolean\n}\n\nexport function hostActionDocument(action: HostAction): HostActionDocument {\n const { recipe, ...rest } = action\n const trigger = action.trigger\n return {\n ...rest,\n trigger: {\n ...trigger,\n oncePerVisitor: trigger.oncePerVisitor === true,\n oncePerSession: trigger.oncePerSession === true,\n cooldownMinutes:\n Number(trigger.cooldownMinutes) >= 1 ? Number(trigger.cooldownMinutes) : null,\n everyTime: trigger.everyTime === true,\n condition: null,\n conditions: trigger.conditions ?? null,\n combinator: trigger.combinator ?? null,\n },\n enabled: action.enabled !== false,\n ...(recipe !== undefined ? { recipe } : {}),\n }\n}\n\n/**\n * The step list as the visitor's browser may see it.\n *\n * A client step AFTER a wait must never reach the page. The client engine\n * runs its slice of the list immediately, so shipping the whole list would\n * make \"wait three days, then show the popup\" show the popup at once — the\n * delay would appear to work on the server, be ignored in the browser, and\n * the two halves of one authored flow would disagree about when it happened.\n *\n * Truncating rather than filtering: everything past the first wait belongs to\n * a run that has not happened yet, whichever side would have executed it.\n */\nexport function hostActionStepsForClient(\n steps: readonly HostActionStep[] | undefined | null,\n): HostActionStep[] {\n const list = steps ?? []\n const suspendAt = list.findIndex(isFlowSuspendingStep)\n return [...(suspendAt < 0 ? list : list.slice(0, suspendAt))]\n}\n\nexport type HostActionStepType = HostActionStep['type']\n\n/**\n * `hosts/{hostId}/actions/{id}` doc: a site interaction whose steps may be\n * the automation's server steps as well as the platform's client steps.\n */\nexport interface HostAction extends SiteInteraction<HostActionStep> {\n /**\n * The recipe this action was installed from or begun as (AGL-2639), or\n * `null` for one begun blank. Absent on a document from before the stamp\n * existed — read it through {@link hostActionRecipeId}, which keeps the\n * three cases apart.\n */\n recipe?: CrmActionRecipeId | null\n}\n\n/** Custom-event chaining depth cap (mirrors CROSS_MAX_DEPTH). */\nexport const ACTION_MAX_EVENT_DEPTH = 3\n\n/**\n * The shortest and longest a flow may wait.\n *\n * The floor is a minute because the resume beat runs on a minute, so anything\n * under one is a delay the scheduler cannot honor and would only read as\n * imprecision. The ceiling is ninety days: long enough for the win-back that\n * is the longest sequence anybody writes, and short enough that an enrollment\n * is not an unbounded lease on a document. A person waiting inside a flow is\n * storage the merchant is not looking at, and a wait measured in years is\n * indistinguishable from one nobody will ever collect.\n */\nexport const FLOW_WAIT_MIN_MINUTES = 1\nexport const FLOW_WAIT_MAX_MINUTES = 90 * 24 * 60\n\nexport const HOST_ACTION_STEP_LABELS: Record<HostActionStepType, string> = {\n runWorkflow: 'Run a workflow',\n siteAlert: 'Show a site alert',\n customEvent: 'Fire a custom event',\n datasetAppend: 'Write to a dataset',\n webhookPost: 'Send a webhook (Business)',\n showOverlay: 'Show a popup or bar',\n stickyNav: 'Make navigation sticky',\n addClass: 'Add a CSS class',\n toggleClass: 'Toggle a CSS class',\n removeClass: 'Remove a CSS class',\n showElement: 'Show an element',\n hideElement: 'Hide an element',\n toggleElement: 'Show/hide an element',\n openDrawer: 'Open a drawer',\n closeDrawer: 'Close a drawer',\n toggleDrawer: 'Open/close a drawer',\n openMenu: 'Open a menu',\n closeMenu: 'Close a menu',\n toggleMenu: 'Open/close a menu',\n setAttribute: 'Set an ARIA or data attribute',\n removeAttribute: 'Remove an ARIA or data attribute',\n scrollTo: 'Scroll to element',\n playVideo: 'Play a video',\n showHtml: 'Show custom HTML',\n runJs: 'Run custom JS (Business)',\n redirect: 'Redirect the visitor',\n trackGaEvent: 'Track an analytics event',\n sendEmail: 'Send an email',\n notifyAdmins: 'Notify site admins',\n enrollList: 'Enroll in a list',\n updateDataset: 'Update a dataset record',\n assignCampaign: 'Assign to a campaign',\n wait: 'Wait',\n waitForEvent: 'Wait for something to happen',\n exitFlow: 'End the flow here',\n setContactStage: 'Set the contact’s lifecycle stage',\n addContactTag: 'Tag the contact',\n assignContactOwner: 'Assign the contact an owner',\n createCrmTask: 'Create a CRM task',\n logCrmActivity: 'Log a CRM activity',\n}\n\n/**\n * Past-tense phrases for a run summary (AGL-2171).\n *\n * `HOST_ACTION_STEP_LABELS` above names what a step WILL do, in the\n * imperative, for a `Do` select — \"Send an email\". A run history is the\n * opposite tense and a different audience: it says what already happened,\n * on one line, several steps at a time. `/product/workflows` advertises\n * exactly that shape — `Sent email · saved to Leads · webhook 200`.\n *\n * Two maps rather than one derived from the other, because \"Send a webhook\n * (Business)\" cannot be mechanically turned into \"webhook\" — the plan\n * suffix is part of the picker's label and has no business in a log line.\n * Only the steps a SERVER run can perform appear here; the client-side\n * steps run in the visitor's browser and never reach the activity write.\n */\nexport const HOST_ACTION_STEP_OUTCOMES: Partial<\n Record<HostActionStepType, string>\n> = {\n runWorkflow: 'ran workflow',\n siteAlert: 'showed an alert',\n customEvent: 'fired an event',\n datasetAppend: 'saved to dataset',\n updateDataset: 'updated dataset',\n webhookPost: 'webhook',\n sendEmail: 'sent email',\n notifyAdmins: 'notified admins',\n enrollList: 'enrolled in list',\n assignCampaign: 'assigned to campaign',\n wait: 'waiting',\n waitForEvent: 'waiting for',\n exitFlow: 'ended the flow',\n setContactStage: 'set stage',\n addContactTag: 'tagged',\n assignContactOwner: 'assigned owner',\n createCrmTask: 'created task',\n logCrmActivity: 'logged activity',\n}\n\n/**\n * One step's line in a run summary, with the detail that makes it useful.\n *\n * `saved to Leads` beats `saved to dataset`, and `webhook 200` beats\n * `webhook` — the status code is the entire reason anyone opens a run\n * history after a webhook, and it was being discarded on the line it\n * arrived.\n */\nexport function describeStepOutcome(\n type: HostActionStepType,\n detail?: string,\n): string {\n const base = HOST_ACTION_STEP_OUTCOMES[type] ?? String(type)\n const trimmed = detail?.trim()\n if (!trimmed) return base\n if (type === 'datasetAppend' || type === 'updateDataset') {\n // `saved to dataset` + `Leads` reads as `saved to Leads`, not\n // `saved to dataset Leads`.\n return `${base.replace(/ dataset$/, '')} ${trimmed}`\n }\n return `${base} ${trimmed}`\n}\n\n/** A whole number of minutes inside the wait band. */\nexport function isFlowWaitMinutes(value: unknown): boolean {\n return (\n Number.isInteger(value) &&\n (value as number) >= FLOW_WAIT_MIN_MINUTES &&\n (value as number) <= FLOW_WAIT_MAX_MINUTES\n )\n}\n\n/** True for a custom (non-built-in) event name an action may fire. */\nexport function isCustomEventName(event: string): boolean {\n return (\n !HOST_EVENT_TYPES.includes(event as any) &&\n CUSTOM_EVENT_PATTERN.test(event)\n )\n}\n\n/**\n * Validates an action doc shape; returns a human-readable error or null.\n * Server and console share this so bad steps never persist or run.\n */\nexport function validateHostAction(action: HostAction): string | null {\n if (!action.name?.trim()) return 'Name the action'\n // A stamp is provenance, and provenance naming a recipe that does not\n // exist is a document nothing can read back; `null` and absent both pass.\n if (action.recipe != null && !crmActionRecipe(action.recipe)) {\n return 'Unknown recipe'\n }\n // The trigger, the step guards, the client steps and every declared step's\n // pick are the platform's to check; the server steps are this module's.\n return validateInteraction(action, {\n validateStep: (step, label) => serverStepProblem(step as HostActionStep, label),\n })\n}\n\n/**\n * A server step's own complaint, or null. A `runWorkflow` step's pick is\n * checked with every other declared step's (`interactionSteps` in\n * `plugins.config.json`), by `validateInteraction`.\n */\nfunction serverStepProblem(step: HostActionStep, label: string): string | null {\n if (step.type === 'wait' && !isFlowWaitMinutes(step.delayMinutes)) {\n return `${label}: wait between ${FLOW_WAIT_MIN_MINUTES} minute and ${FLOW_WAIT_MAX_MINUTES} minutes`\n }\n if (step.type === 'waitForEvent') {\n const waited = step.eventName?.trim() ?? ''\n if (\n !waited ||\n (!HOST_EVENT_TYPES.includes(waited as any) && !isCustomEventName(waited))\n ) {\n return `${label}: pick the event to wait for`\n }\n if (!isFlowWaitMinutes(step.timeoutMinutes)) {\n return `${label}: give up after ${FLOW_WAIT_MIN_MINUTES}–${FLOW_WAIT_MAX_MINUTES} minutes`\n }\n }\n if (step.type === 'customEvent') {\n if (!isCustomEventName(step.eventName?.trim() ?? '')) {\n return `${label}: custom event names are 2–40 letters, digits, dashes`\n }\n }\n if (\n step.type === 'datasetAppend' &&\n !step.datasetId?.trim() &&\n !step.datasetName?.trim()\n ) {\n return `${label}: pick a dataset`\n }\n if (\n step.type === 'webhookPost' &&\n !step.webhookId?.trim() &&\n !step.webhookName?.trim()\n ) {\n return `${label}: pick a webhook`\n }\n if (step.type === 'sendEmail') {\n if (!step.subject?.trim()) return `${label}: enter the subject`\n if (!step.body?.trim()) return `${label}: enter the email body`\n }\n if (step.type === 'notifyAdmins' && !step.title?.trim()) {\n return `${label}: enter the notification title`\n }\n if (\n step.type === 'enrollList' &&\n !step.listId?.trim() &&\n !step.listName?.trim()\n ) {\n return `${label}: pick a list`\n }\n if (\n step.type === 'updateDataset' &&\n !step.datasetId?.trim() &&\n !step.datasetName?.trim()\n ) {\n return `${label}: pick a dataset`\n }\n if (\n step.type === 'assignCampaign' &&\n !step.campaignId?.trim() &&\n !step.campaignName?.trim()\n ) {\n return `${label}: pick a campaign`\n }\n // CRM steps (AGL-2605). A stage or a kind outside its vocabulary is\n // refused here rather than stored: the executor treats the value as\n // trusted and would write it into a facet every stage report counts.\n if (\n step.type === 'setContactStage' &&\n !isContactLifecycleStage(step.lifecycleStage)\n ) {\n return `${label}: pick a lifecycle stage`\n }\n if (step.type === 'addContactTag') {\n const tag = step.tag?.trim() ?? ''\n if (!tag) return `${label}: enter the tag`\n if (tag.length > CONTACT_TAG_MAX_LENGTH) {\n return `${label}: tags are at most ${CONTACT_TAG_MAX_LENGTH} characters`\n }\n }\n if (step.type === 'assignContactOwner') {\n const named = Boolean(step.ownerUid?.trim() || step.ownerEmail?.trim())\n if (step.roundRobin === true && named) {\n return `${label}: pick round robin or a member, not both`\n }\n if (\n step.roundRobin !== true &&\n !step.ownerUid?.trim() &&\n !step.ownerEmail?.trim().includes('@')\n ) {\n return `${label}: enter the owner’s email address`\n }\n }\n if (step.type === 'createCrmTask') {\n if (!step.title?.trim()) return `${label}: give the task a title`\n if (!isCrmTaskKind(step.kind)) return `${label}: pick the kind of task`\n if (\n !Number.isInteger(step.dueInDays) ||\n step.dueInDays < 0 ||\n step.dueInDays > CRM_TASK_MAX_DUE_DAYS\n ) {\n return `${label}: due in 0–${CRM_TASK_MAX_DUE_DAYS} days`\n }\n // Optional — but an address that is not one would resolve to nobody at\n // run time, and the task would land unassigned with no word why.\n const assigneeEmail = step.assigneeEmail?.trim() ?? ''\n if (assigneeEmail && !assigneeEmail.includes('@')) {\n return `${label}: enter the assignee’s email address`\n }\n }\n if (step.type === 'logCrmActivity') {\n if (!isCrmActivityKind(step.kind)) {\n return `${label}: pick the kind of activity`\n }\n if (!step.body?.trim()) return `${label}: write what happened`\n }\n return null\n}\n\n/**\n * Webhooks (AGL-149) at `hosts/{hostId}/webhooks/{id}`. Outbound entries\n * are targets a `webhookPost` action step delivers to (HMAC-signed);\n * inbound entries mint `/api/hooks/{hostId}/{hookId}` endpoints that run\n * a workflow with the posted JSON in scope. Business tier (`webhooks`\n * flag); Pro can be enabled per-tenant via entitlement overrides.\n */\nexport interface HostWebhook {\n name: string\n direction: 'outbound' | 'inbound'\n /** Outbound delivery URL (https only; checked again at send time). */\n url?: string\n /** Shared secret: signs outbound bodies, verifies inbound callers. */\n secret?: string\n /** Inbound: workflow (by name) enrolled with the payload in scope. */\n workflowName?: string\n enabled?: boolean\n}\n\nexport const WEBHOOK_MAX_PER_HOST = 5\n\n/** Outbound URLs must be public https — first-line SSRF guard. */\nexport const WEBHOOK_URL_PATTERN =\n /^https:\\/\\/(?!localhost)(?!127\\.)(?!0\\.)(?!10\\.)(?!172\\.(1[6-9]|2\\d|3[01])\\.)(?!192\\.168\\.)(?!169\\.254\\.)[^\\s]+$/i\n\n"],"names":["CRM_TASK_MAX_DUE_DAYS","isContactLifecycleStage","isCrmActivityKind","isCrmTaskKind","CUSTOM_EVENT_PATTERN","validateInteraction","HOST_EVENT_TYPES","FLOW_TIMED_OUT_FIELD","FLOW_SUSPENDING_STEP_TYPES","Set","isFlowSuspendingStep","step","has","type","CRM_ACTION_STEP_TYPES","isCrmActionStep","CONTACT_TAG_MAX_LENGTH","CRM_ACTION_RECIPE_IDS","STALE_LEAD_WAIT_MINUTES","crmRecipeTagForForm","formName","trim","slice","CRM_ACTION_RECIPES","id","title","description","build","recipe","name","trigger","event","conditions","field","op","value","combinator","steps","roundRobin","kind","dueInDays","subject","body","tag","enabled","eventName","timeoutMinutes","when","needs","input","form","crmActionRecipe","find","hostActionRecipeId","action","stamp","undefined","hostActionDocument","rest","oncePerVisitor","oncePerSession","cooldownMinutes","Number","everyTime","condition","hostActionStepsForClient","list","suspendAt","findIndex","ACTION_MAX_EVENT_DEPTH","FLOW_WAIT_MIN_MINUTES","FLOW_WAIT_MAX_MINUTES","HOST_ACTION_STEP_LABELS","runWorkflow","siteAlert","customEvent","datasetAppend","webhookPost","showOverlay","stickyNav","addClass","toggleClass","removeClass","showElement","hideElement","toggleElement","openDrawer","closeDrawer","toggleDrawer","openMenu","closeMenu","toggleMenu","setAttribute","removeAttribute","scrollTo","playVideo","showHtml","runJs","redirect","trackGaEvent","sendEmail","notifyAdmins","enrollList","updateDataset","assignCampaign","wait","waitForEvent","exitFlow","setContactStage","addContactTag","assignContactOwner","createCrmTask","logCrmActivity","HOST_ACTION_STEP_OUTCOMES","describeStepOutcome","detail","base","String","trimmed","replace","isFlowWaitMinutes","isInteger","isCustomEventName","includes","test","validateHostAction","validateStep","label","serverStepProblem","delayMinutes","waited","datasetId","datasetName","webhookId","webhookName","listId","listName","campaignId","campaignName","lifecycleStage","length","named","Boolean","ownerUid","ownerEmail","assigneeEmail","WEBHOOK_MAX_PER_HOST","WEBHOOK_URL_PATTERN"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAEEA,qBAAqB,EAGrBC,uBAAuB,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AAC;QAC3D;QACA,uEAAuE;QACvE,iEAAiE;QACjE,MAAMiJ,0BAAgBtI,sBAAAA,KAAKsI,aAAa,qBAAlBtI,oBAAoBU,IAAI,sBAAM;QACpD,IAAI4H,iBAAiB,CAACA,cAActB,QAAQ,CAAC,MAAM;YACjD,OAAO,GAAGI,MAAM,oCAAoC,CAAC;QACvD;IACF;IACA,IAAIpH,KAAKE,IAAI,KAAK,kBAAkB;YAI7BF;QAHL,IAAI,CAACT,kBAAkBS,KAAK4B,IAAI,GAAG;YACjC,OAAO,GAAGwF,MAAM,2BAA2B,CAAC;QAC9C;QACA,IAAI,GAACpH,cAAAA,KAAK+B,IAAI,qBAAT/B,YAAWU,IAAI,KAAI,OAAO,GAAG0G,MAAM,qBAAqB,CAAC;IAChE;IACA,OAAO;AACT;AAqBA,OAAO,MAAMmB,uBAAuB,EAAC;AAErC,gEAAgE,GAChE,OAAO,MAAMC,sBACX,oHAAmH"}
1
+ {"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/actions.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 {\n type ContactLifecycleStage,\n CRM_TASK_MAX_DUE_DAYS,\n type CrmActivityKind,\n type CrmTaskKind,\n isContactLifecycleStage,\n isCrmActivityKind,\n isCrmTaskKind,\n} from './crm-kinds'\nimport {\n type ClientInteractionStep,\n CUSTOM_EVENT_PATTERN,\n type InteractionCondition,\n type InteractionStepGuard,\n type InteractionTrigger,\n type SiteAlert,\n type SiteInteraction,\n type TriggerCombinator,\n validateInteraction,\n} from './site-interactions'\nimport { HOST_EVENT_TYPES } from './host-events'\n\n/**\n * Actions builder (AGL-148): HubSpot-style event → action automation on\n * top of the AGL-128 event triggers. An action listens for a host event\n * (built-in or a custom name fired by another action), optionally filters\n * on the payload, and runs an ordered step list. Pure types + validation\n * here; the executor lives in the workflows plugin, where the I/O is.\n *\n * An action is a SITE INTERACTION (`site-interactions.ts`) with server steps\n * added: its trigger, its conditions, its client steps and its storage are\n * the platform's, and are re-exported here for the readers that take both\n * from this module. What is declared below is the automation's own — the\n * server steps, flows, recipes and webhooks.\n */\nexport * from './site-interactions'\n\n/** The automation's names for the platform's interaction shapes. */\nexport type HostActionTriggerCondition = InteractionCondition\nexport type HostActionTrigger = InteractionTrigger\nexport type HostActionStepGuard = InteractionStepGuard\n/** Alert produced by a `siteAlert` step, surfaced to the emitting client. */\nexport type HostActionAlert = SiteAlert\n\n/**\n * The scope key a resumed flow carries to say the wait ended on the CLOCK\n * rather than on the event it was watching for.\n *\n * This is how a `waitForEvent` gets its timeout branch without a nested step\n * list: the flow resumes either way, and the step after it carries a `when`\n * naming this field. Underscored because it shares a namespace with the\n * event payload's own fields, which are merchant-authored form field names.\n */\nexport const FLOW_TIMED_OUT_FIELD = '_waitTimedOut'\n\n/** The steps an automation adds to the platform's client steps: the server's, run by the workflows plugin. */\ntype ServerActionStep = (\n // Entity references carry a doc id (AGL-261, rename-safe) with the name\n // kept as a display hint; pre-AGL-261 docs have only the name and the\n // executor resolves either.\n | { type: 'runWorkflow'; workflowId?: string; workflowName?: string }\n | { type: 'customEvent'; eventName: string }\n | { type: 'datasetAppend'; datasetId?: string; datasetName?: string }\n | { type: 'webhookPost'; webhookId?: string; webhookName?: string }\n // Server-side steps (AGL-257).\n | {\n type: 'sendEmail'\n subject: string\n body: string\n toField?: string\n /**\n * The stream this message belongs to, so a recipient who left it is not\n * mailed. Absent on every step authored before topics reached the\n * actions editor, which the executor resolves to the default topic.\n */\n topicId?: string\n }\n | { type: 'notifyAdmins'; title: string; body?: string }\n | { type: 'enrollList'; listId?: string; listName?: string }\n | { type: 'updateDataset'; datasetId?: string; datasetName?: string }\n | { type: 'assignCampaign'; campaignId?: string; campaignName?: string }\n /*\n * THE THREE FLOW STEPS.\n *\n * `wait` is the one that matters: without a durable delay an automation is\n * always trigger → immediate actions, so no welcome series, win-back or\n * post-purchase follow-up can exist at all. The other two are what make a\n * delay useful — something to end the flow early, and a wait that ends on\n * an event instead of on the clock.\n *\n * All three are SERVER steps. A delay outlives the page view that started\n * it by days, so the browser that fired the trigger is long gone by the time\n * the flow continues; `hostActionStepsForClient` truncates the client's copy\n * of the step list at the first of these for that reason.\n */\n | {\n type: 'wait'\n /** Whole minutes to hold before the next step. */\n delayMinutes: number\n }\n | {\n type: 'waitForEvent'\n /** The host or custom event that resumes this person's flow. */\n eventName: string\n /**\n * Whole minutes after which the flow continues anyway, with\n * {@link FLOW_TIMED_OUT_FIELD} true in scope. There is always a\n * deadline: a wait with no timeout is an enrollment that lives forever.\n */\n timeoutMinutes: number\n }\n /** Ends the enrollment here. Paired with a `when`, this is the exit branch. */\n | { type: 'exitFlow' }\n /*\n * THE CRM STEPS (AGL-2605).\n *\n * Server steps, every one, because each writes a record only the Admin\n * SDK may write on a visitor's behalf. Each acts on ONE person — the\n * contact the event names, resolved by `contactId` when the payload\n * carries one and by `email` otherwise — and each writes inside the\n * site's own facet or stamps the site's own scope, for the reason\n * `assignCampaign` gives: a contact row is shared by every site in the\n * org, and a stage or a tag is one holder's business record. A step whose\n * event names nobody the site can see does nothing and says so in the run.\n *\n * None of them carries a doc-id reference for the reference audit to\n * check: a stage and a kind are fixed vocabularies, a tag is free text,\n * and an owner is a member who is resolved at run time.\n */\n | { type: 'setContactStage'; lifecycleStage: ContactLifecycleStage }\n | { type: 'addContactTag'; tag: string }\n /**\n * The owner by uid when a member id was typed or a picker wrote the step,\n * by email when an address was typed; the executor resolves either against\n * the org's roster, and only the roster (AGL-2614).\n * Or `roundRobin`, and the owner is the next member of the pool the CRM's\n * settings keep (AGL-2618) — a step that names nobody and hands the\n * choice to the rotation, so a stage change can spread its follow-ups\n * across a team rather than pile them on one rep. The two are exclusive:\n * a rotation step carries no member, and the validator refuses one that\n * names both.\n */\n | {\n type: 'assignContactOwner'\n ownerUid?: string\n ownerEmail?: string\n roundRobin?: boolean\n }\n | {\n type: 'createCrmTask'\n title: string\n kind: CrmTaskKind\n /** Days from the run to the due date; `0` is due today. */\n dueInDays: number\n /**\n * Who gets it — by uid or by an address, both resolved against the\n * roster the way the owner step's are. Neither named, the task goes\n * to the contact's owner, then to nobody.\n */\n assigneeUid?: string\n assigneeEmail?: string\n }\n | { type: 'logCrmActivity'; kind: CrmActivityKind; body: string }\n) & {\n /** See {@link InteractionStepGuard}. Absent means the step always runs. */\n when?: InteractionStepGuard | null\n}\n\n/** A step of an automation: one of the platform's client steps, or one of its server steps. */\nexport type HostActionStep = ClientInteractionStep | ServerActionStep\n\n/**\n * The steps that suspend a run and continue it later, from a job beat.\n *\n * Named as a set rather than checked inline because three surfaces have to\n * agree on it: the executor stops here and writes an enrollment, the client\n * payload is truncated here, and the validator refuses a flow that waits\n * without a person to wait for.\n */\nexport const FLOW_SUSPENDING_STEP_TYPES: ReadonlySet<HostActionStepType> =\n new Set(['wait', 'waitForEvent'] as const)\n\nexport function isFlowSuspendingStep(step: HostActionStep): boolean {\n return FLOW_SUSPENDING_STEP_TYPES.has(step.type)\n}\n\n/** Longest tag an automation may write — the console's own tag field cap. */\nexport const CONTACT_TAG_MAX_LENGTH = 60\n\n/*\n * THE RECIPES (AGL-2626).\n *\n * A recipe is a ready-to-edit action — a trigger, its conditions and an\n * ordered step list — built from the vocabulary the editor already offers\n * and handed to the editor as a draft. Nothing is written until the person\n * saves, and every field is theirs to change first: the recipe decides\n * where the editor starts, not what the site runs.\n *\n * Defined here, beside the step catalog, rather than in the builder, so the\n * docs page that lists the recipes and the menu that offers them read ONE\n * list, and so a step the catalog renames or retires breaks a recipe at\n * compile time rather than in a menu nobody tests.\n *\n * Definitions only. Three of the four are complete as written. `tagByForm`\n * needs a form, and a form belongs to a site (`hosts/{hostId}/forms`), so\n * the picker that supplies it is the builder's business and host-scoped by\n * nature. That is the seam an org-level mount keeps: the recipes are the\n * same at either level, and only the form picker knows where it is.\n */\nexport const CRM_ACTION_RECIPE_IDS = [\n 'welcomeNewLead',\n 'followUpWonDeal',\n 'reengageStaleLead',\n 'tagByForm',\n] as const\n\nexport type CrmActionRecipeId = (typeof CRM_ACTION_RECIPE_IDS)[number]\n\n/** What a recipe is handed before it builds — today only the form `tagByForm` reads. */\nexport interface CrmActionRecipeInput {\n form?: { id: string; name: string }\n}\n\nexport interface CrmActionRecipe {\n id: CrmActionRecipeId\n /** How the recipe reads in the menu; also the action's starting name. */\n title: string\n /** One sentence under the title. */\n description: string\n /**\n * What must be picked before the recipe can be built. A recipe that needs\n * nothing opens the editor at once; one that needs a form opens a picker\n * first. Built WITHOUT its pick, such a recipe yields an action the\n * validator refuses — a condition with no value — rather than one that\n * saves and then silently matches nothing.\n */\n needs?: 'form'\n /**\n * A fresh action each call, because the draft is edited in place. The\n * action carries `recipe: id` — the provenance is the builder's to stamp,\n * so a writer that saves what it was handed cannot forget it.\n */\n build: (input?: CrmActionRecipeInput) => HostAction\n}\n\n/**\n * How long the stale-lead recipe holds before it decides a lead has gone\n * quiet. A week: long enough that a rep who is working the lead has had a\n * chance to move its stage, short enough that a lead nobody touched is\n * still warm when the reminder lands.\n */\nexport const STALE_LEAD_WAIT_MINUTES = 7 * 24 * 60\n\n/**\n * The tag a form's captures get: the form's own name, cut to the tag cap.\n * The name is what the person calls the form, so it is the tag they would\n * have typed; the editor is open to change it before anything is saved.\n */\nexport function crmRecipeTagForForm(formName: string): string {\n return formName.trim().slice(0, CONTACT_TAG_MAX_LENGTH)\n}\n\nexport const CRM_ACTION_RECIPES: readonly CrmActionRecipe[] = [\n {\n id: 'welcomeNewLead',\n title: 'Welcome a new lead',\n description:\n 'When a form makes a new contact: rotate in an owner, book a call for ' +\n 'tomorrow, send a thank-you, and tag them website.',\n /*\n * The owner first, because the task that follows names no assignee and\n * so goes to whoever owns the contact when it is created — the member\n * the rotation just chose. Round robin rather than a named member: a\n * recipe cannot know who is on the team, and the pool under CRM →\n * Settings is the one place that does. On a workspace with no pool the\n * step fails and the run continues, so the call, the email and the tag\n * still land and the run history says who was not assigned.\n *\n * The email comes before any wait, which makes it an immediate reply to\n * what the visitor just did — transactional, sent from the org's own\n * identity, to the address the event carries.\n *\n * Its words promise no response time. The org hub installs this recipe\n * into a site without its editor opening, so the business never reads\n * the sentence it is sending, and a \"within a day\" written here would be\n * a commitment made on its behalf that nothing in the run keeps.\n */\n build: () => ({\n recipe: 'welcomeNewLead',\n name: 'Welcome a new lead',\n trigger: {\n event: 'contactCreated',\n conditions: [{ field: 'source', op: 'equals', value: 'form' }],\n combinator: 'and',\n },\n steps: [\n { type: 'assignContactOwner', roundRobin: true },\n {\n type: 'createCrmTask',\n title: 'Call the new lead',\n kind: 'call',\n dueInDays: 1,\n },\n {\n type: 'sendEmail',\n subject: 'Thanks for getting in touch',\n body:\n 'Thanks for reaching out. We have your message and will reply ' +\n 'to this email address.',\n },\n { type: 'addContactTag', tag: 'website' },\n ],\n enabled: true,\n }),\n },\n {\n id: 'followUpWonDeal',\n title: 'Follow up a won deal',\n description:\n 'When a deal is won — which makes the contact a Customer on its own — ' +\n 'book a check-in call a week out.',\n /*\n * No stage step (AGL-2641): the win itself floors the contact at\n * `customer` before `dealWon` is announced, so a step setting the stage\n * here would at best repeat the write and at worst move an evangelist\n * back to customer — a SET, which is what the step is, and not the\n * floor the win applies. The recipe books the follow-up and nothing\n * else.\n */\n build: () => ({\n recipe: 'followUpWonDeal',\n name: 'Follow up a won deal',\n trigger: { event: 'dealWon' },\n steps: [\n {\n type: 'createCrmTask',\n title: 'Check in with the new customer',\n kind: 'call',\n dueInDays: 7,\n },\n ],\n enabled: true,\n }),\n },\n {\n id: 'reengageStaleLead',\n title: 'Re-engage a stale lead',\n description:\n 'When a contact becomes a lead: wait a week, and if their stage has ' +\n 'not moved, book a call to bring them back.',\n /*\n * \"Unless the stage moved on\" is the wait's own event: the flow watches\n * for the next stage change on this person and gives up after a week.\n * Resumed by the clock, the run carries `_waitTimedOut`, and the task\n * step's guard reads it; resumed by the event, the field is absent and\n * the task is skipped — the lead was worked, and nobody is told to\n * re-engage somebody who just moved to Sales qualified.\n */\n build: () => ({\n recipe: 'reengageStaleLead',\n name: 'Re-engage a stale lead',\n trigger: {\n event: 'contactStageChanged',\n conditions: [{ field: 'lifecycleStage', op: 'equals', value: 'lead' }],\n combinator: 'and',\n },\n steps: [\n {\n type: 'waitForEvent',\n eventName: 'contactStageChanged',\n timeoutMinutes: STALE_LEAD_WAIT_MINUTES,\n },\n {\n type: 'createCrmTask',\n title: 'Re-engage a lead that has gone quiet',\n kind: 'call',\n dueInDays: 1,\n when: {\n conditions: [{ field: FLOW_TIMED_OUT_FIELD, op: 'notEmpty' }],\n },\n },\n ],\n enabled: true,\n }),\n },\n {\n id: 'tagByForm',\n title: 'Tag by form',\n description:\n 'When a form you pick makes a new contact: tag them with the form’s ' +\n 'name.',\n needs: 'form',\n build: (input) => {\n const form = input?.form\n return {\n recipe: 'tagByForm',\n name: form ? `Tag ${form.name.trim()} submissions` : 'Tag by form',\n trigger: {\n event: 'contactCreated',\n conditions: [{ field: 'formId', op: 'equals', value: form?.id ?? '' }],\n combinator: 'and',\n },\n steps: [\n { type: 'addContactTag', tag: form ? crmRecipeTagForForm(form.name) : '' },\n ],\n enabled: true,\n }\n },\n },\n]\n\n/** The recipe with this id, or null for a string that names none. */\nexport function crmActionRecipe(id: unknown): CrmActionRecipe | null {\n return CRM_ACTION_RECIPES.find((recipe) => recipe.id === id) ?? null\n}\n\n/**\n * The recipe a STORED action came from, read off its document (AGL-2639).\n *\n * Three answers, and the third is the one that matters. A known id: the\n * action was installed from, or begun as, that recipe. `null`: the action\n * was begun blank, or from a recipe this build no longer knows — the\n * editor wrote the field and said \"no recipe\". `undefined`: the document\n * carries no `recipe` field at all, which is every action saved before the\n * stamp existed. Such an action may well have started from a recipe — the\n * menu opened the editor prefilled long before anything recorded it — so a\n * reader that needs to know whether a site has a recipe treats `undefined`\n * as UNKNOWN, never as absent, and never writes a `null` over it.\n */\nexport function hostActionRecipeId(\n action: { recipe?: unknown } | null | undefined,\n): CrmActionRecipeId | null | undefined {\n const stamp = action?.recipe\n if (stamp === undefined) return undefined\n return crmActionRecipe(stamp)?.id ?? null\n}\n\n/**\n * A HostAction as the document at `hosts/{hostId}/actions/{id}` holds it.\n *\n * Every optional trigger key is written OUT — a boolean cap as `false`, a\n * cleared list as `null` — because the editor saves with a merge-set, and\n * a merge keeps whatever key the payload omits: a frequency cap switched\n * off, left out of the payload, would stay on. The legacy single\n * `condition` is always nulled; `conditions` has been canonical since the\n * list shape arrived and a document that carried both would have the\n * reader pick. Everything else is the action, unchanged.\n *\n * `recipe` rides along only when the action SAYS something about it: an\n * id or `null`. An action that carries no stamp (an older document, edited\n * and saved again) keeps carrying none — see {@link hostActionRecipeId}\n * for why an absent stamp must not become a `null` one.\n */\nexport interface HostActionDocument extends HostAction {\n trigger: HostActionTrigger & {\n oncePerVisitor: boolean\n oncePerSession: boolean\n cooldownMinutes: number | null\n everyTime: boolean\n condition: null\n conditions: HostActionTriggerCondition[] | null\n combinator: TriggerCombinator | null\n }\n enabled: boolean\n}\n\nexport function hostActionDocument(action: HostAction): HostActionDocument {\n const { recipe, ...rest } = action\n const trigger = action.trigger\n return {\n ...rest,\n trigger: {\n ...trigger,\n oncePerVisitor: trigger.oncePerVisitor === true,\n oncePerSession: trigger.oncePerSession === true,\n cooldownMinutes:\n Number(trigger.cooldownMinutes) >= 1 ? Number(trigger.cooldownMinutes) : null,\n everyTime: trigger.everyTime === true,\n condition: null,\n conditions: trigger.conditions ?? null,\n combinator: trigger.combinator ?? null,\n },\n enabled: action.enabled !== false,\n ...(recipe !== undefined ? { recipe } : {}),\n }\n}\n\n/**\n * The step list as the visitor's browser may see it.\n *\n * A client step AFTER a wait must never reach the page. The client engine\n * runs its slice of the list immediately, so shipping the whole list would\n * make \"wait three days, then show the popup\" show the popup at once — the\n * delay would appear to work on the server, be ignored in the browser, and\n * the two halves of one authored flow would disagree about when it happened.\n *\n * Truncating rather than filtering: everything past the first wait belongs to\n * a run that has not happened yet, whichever side would have executed it.\n */\nexport function hostActionStepsForClient(\n steps: readonly HostActionStep[] | undefined | null,\n): HostActionStep[] {\n const list = steps ?? []\n const suspendAt = list.findIndex(isFlowSuspendingStep)\n return [...(suspendAt < 0 ? list : list.slice(0, suspendAt))]\n}\n\nexport type HostActionStepType = HostActionStep['type']\n\n/**\n * `hosts/{hostId}/actions/{id}` doc: a site interaction whose steps may be\n * the automation's server steps as well as the platform's client steps.\n */\nexport interface HostAction extends SiteInteraction<HostActionStep> {\n /**\n * The recipe this action was installed from or begun as (AGL-2639), or\n * `null` for one begun blank. Absent on a document from before the stamp\n * existed — read it through {@link hostActionRecipeId}, which keeps the\n * three cases apart.\n */\n recipe?: CrmActionRecipeId | null\n}\n\n/**\n * The shortest and longest a flow may wait.\n *\n * The floor is a minute because the resume beat runs on a minute, so anything\n * under one is a delay the scheduler cannot honor and would only read as\n * imprecision. The ceiling is ninety days: long enough for the win-back that\n * is the longest sequence anybody writes, and short enough that an enrollment\n * is not an unbounded lease on a document. A person waiting inside a flow is\n * storage the merchant is not looking at, and a wait measured in years is\n * indistinguishable from one nobody will ever collect.\n */\nexport const FLOW_WAIT_MIN_MINUTES = 1\nexport const FLOW_WAIT_MAX_MINUTES = 90 * 24 * 60\n\nexport const HOST_ACTION_STEP_LABELS: Record<HostActionStepType, string> = {\n runWorkflow: 'Run a workflow',\n siteAlert: 'Show a site alert',\n customEvent: 'Fire a custom event',\n datasetAppend: 'Write to a dataset',\n webhookPost: 'Send a webhook (Business)',\n showOverlay: 'Show a popup or bar',\n stickyNav: 'Make navigation sticky',\n addClass: 'Add a CSS class',\n toggleClass: 'Toggle a CSS class',\n removeClass: 'Remove a CSS class',\n showElement: 'Show an element',\n hideElement: 'Hide an element',\n toggleElement: 'Show/hide an element',\n openDrawer: 'Open a drawer',\n closeDrawer: 'Close a drawer',\n toggleDrawer: 'Open/close a drawer',\n openMenu: 'Open a menu',\n closeMenu: 'Close a menu',\n toggleMenu: 'Open/close a menu',\n setAttribute: 'Set an ARIA or data attribute',\n removeAttribute: 'Remove an ARIA or data attribute',\n scrollTo: 'Scroll to element',\n playVideo: 'Play a video',\n showHtml: 'Show custom HTML',\n runJs: 'Run custom JS (Business)',\n redirect: 'Redirect the visitor',\n trackGaEvent: 'Track an analytics event',\n sendEmail: 'Send an email',\n notifyAdmins: 'Notify site admins',\n enrollList: 'Enroll in a list',\n updateDataset: 'Update a dataset record',\n assignCampaign: 'Assign to a campaign',\n wait: 'Wait',\n waitForEvent: 'Wait for something to happen',\n exitFlow: 'End the flow here',\n setContactStage: 'Set the contact’s lifecycle stage',\n addContactTag: 'Tag the contact',\n assignContactOwner: 'Assign the contact an owner',\n createCrmTask: 'Create a CRM task',\n logCrmActivity: 'Log a CRM activity',\n}\n\n/** A whole number of minutes inside the wait band. */\nexport function isFlowWaitMinutes(value: unknown): boolean {\n return (\n Number.isInteger(value) &&\n (value as number) >= FLOW_WAIT_MIN_MINUTES &&\n (value as number) <= FLOW_WAIT_MAX_MINUTES\n )\n}\n\n/** True for a custom (non-built-in) event name an action may fire. */\nexport function isCustomEventName(event: string): boolean {\n return (\n !HOST_EVENT_TYPES.includes(event as any) &&\n CUSTOM_EVENT_PATTERN.test(event)\n )\n}\n\n/**\n * Validates an action doc shape; returns a human-readable error or null.\n * Server and console share this so bad steps never persist or run.\n */\nexport function validateHostAction(action: HostAction): string | null {\n if (!action.name?.trim()) return 'Name the action'\n // A stamp is provenance, and provenance naming a recipe that does not\n // exist is a document nothing can read back; `null` and absent both pass.\n if (action.recipe != null && !crmActionRecipe(action.recipe)) {\n return 'Unknown recipe'\n }\n // The trigger, the step guards, the client steps and every declared step's\n // pick are the platform's to check; the server steps are this module's.\n return validateInteraction(action, {\n validateStep: (step, label) => serverStepProblem(step as HostActionStep, label),\n })\n}\n\n/**\n * A server step's own complaint, or null. A `runWorkflow` step's pick is\n * checked with every other declared step's (`interactionSteps` in\n * `plugins.config.json`), by `validateInteraction`.\n */\nfunction serverStepProblem(step: HostActionStep, label: string): string | null {\n if (step.type === 'wait' && !isFlowWaitMinutes(step.delayMinutes)) {\n return `${label}: wait between ${FLOW_WAIT_MIN_MINUTES} minute and ${FLOW_WAIT_MAX_MINUTES} minutes`\n }\n if (step.type === 'waitForEvent') {\n const waited = step.eventName?.trim() ?? ''\n if (\n !waited ||\n (!HOST_EVENT_TYPES.includes(waited as any) && !isCustomEventName(waited))\n ) {\n return `${label}: pick the event to wait for`\n }\n if (!isFlowWaitMinutes(step.timeoutMinutes)) {\n return `${label}: give up after ${FLOW_WAIT_MIN_MINUTES}–${FLOW_WAIT_MAX_MINUTES} minutes`\n }\n }\n if (step.type === 'customEvent') {\n if (!isCustomEventName(step.eventName?.trim() ?? '')) {\n return `${label}: custom event names are 2–40 letters, digits, dashes`\n }\n }\n if (\n step.type === 'datasetAppend' &&\n !step.datasetId?.trim() &&\n !step.datasetName?.trim()\n ) {\n return `${label}: pick a dataset`\n }\n if (\n step.type === 'webhookPost' &&\n !step.webhookId?.trim() &&\n !step.webhookName?.trim()\n ) {\n return `${label}: pick a webhook`\n }\n if (step.type === 'sendEmail') {\n if (!step.subject?.trim()) return `${label}: enter the subject`\n if (!step.body?.trim()) return `${label}: enter the email body`\n }\n if (step.type === 'notifyAdmins' && !step.title?.trim()) {\n return `${label}: enter the notification title`\n }\n if (\n step.type === 'enrollList' &&\n !step.listId?.trim() &&\n !step.listName?.trim()\n ) {\n return `${label}: pick a list`\n }\n if (\n step.type === 'updateDataset' &&\n !step.datasetId?.trim() &&\n !step.datasetName?.trim()\n ) {\n return `${label}: pick a dataset`\n }\n if (\n step.type === 'assignCampaign' &&\n !step.campaignId?.trim() &&\n !step.campaignName?.trim()\n ) {\n return `${label}: pick a campaign`\n }\n // CRM steps (AGL-2605). A stage or a kind outside its vocabulary is\n // refused here rather than stored: the executor treats the value as\n // trusted and would write it into a facet every stage report counts.\n if (\n step.type === 'setContactStage' &&\n !isContactLifecycleStage(step.lifecycleStage)\n ) {\n return `${label}: pick a lifecycle stage`\n }\n if (step.type === 'addContactTag') {\n const tag = step.tag?.trim() ?? ''\n if (!tag) return `${label}: enter the tag`\n if (tag.length > CONTACT_TAG_MAX_LENGTH) {\n return `${label}: tags are at most ${CONTACT_TAG_MAX_LENGTH} characters`\n }\n }\n if (step.type === 'assignContactOwner') {\n const named = Boolean(step.ownerUid?.trim() || step.ownerEmail?.trim())\n if (step.roundRobin === true && named) {\n return `${label}: pick round robin or a member, not both`\n }\n if (\n step.roundRobin !== true &&\n !step.ownerUid?.trim() &&\n !step.ownerEmail?.trim().includes('@')\n ) {\n return `${label}: enter the owner’s email address`\n }\n }\n if (step.type === 'createCrmTask') {\n if (!step.title?.trim()) return `${label}: give the task a title`\n if (!isCrmTaskKind(step.kind)) return `${label}: pick the kind of task`\n if (\n !Number.isInteger(step.dueInDays) ||\n step.dueInDays < 0 ||\n step.dueInDays > CRM_TASK_MAX_DUE_DAYS\n ) {\n return `${label}: due in 0–${CRM_TASK_MAX_DUE_DAYS} days`\n }\n // Optional — but an address that is not one would resolve to nobody at\n // run time, and the task would land unassigned with no word why.\n const assigneeEmail = step.assigneeEmail?.trim() ?? ''\n if (assigneeEmail && !assigneeEmail.includes('@')) {\n return `${label}: enter the assignee’s email address`\n }\n }\n if (step.type === 'logCrmActivity') {\n if (!isCrmActivityKind(step.kind)) {\n return `${label}: pick the kind of activity`\n }\n if (!step.body?.trim()) return `${label}: write what happened`\n }\n return null\n}\n\n/** The most webhooks one site keeps; the site create route enforces it. */\nexport const WEBHOOK_MAX_PER_HOST = 5\n"],"names":["CRM_TASK_MAX_DUE_DAYS","isContactLifecycleStage","isCrmActivityKind","isCrmTaskKind","CUSTOM_EVENT_PATTERN","validateInteraction","HOST_EVENT_TYPES","FLOW_TIMED_OUT_FIELD","FLOW_SUSPENDING_STEP_TYPES","Set","isFlowSuspendingStep","step","has","type","CONTACT_TAG_MAX_LENGTH","CRM_ACTION_RECIPE_IDS","STALE_LEAD_WAIT_MINUTES","crmRecipeTagForForm","formName","trim","slice","CRM_ACTION_RECIPES","id","title","description","build","recipe","name","trigger","event","conditions","field","op","value","combinator","steps","roundRobin","kind","dueInDays","subject","body","tag","enabled","eventName","timeoutMinutes","when","needs","input","form","crmActionRecipe","find","hostActionRecipeId","action","stamp","undefined","hostActionDocument","rest","oncePerVisitor","oncePerSession","cooldownMinutes","Number","everyTime","condition","hostActionStepsForClient","list","suspendAt","findIndex","FLOW_WAIT_MIN_MINUTES","FLOW_WAIT_MAX_MINUTES","HOST_ACTION_STEP_LABELS","runWorkflow","siteAlert","customEvent","datasetAppend","webhookPost","showOverlay","stickyNav","addClass","toggleClass","removeClass","showElement","hideElement","toggleElement","openDrawer","closeDrawer","toggleDrawer","openMenu","closeMenu","toggleMenu","setAttribute","removeAttribute","scrollTo","playVideo","showHtml","runJs","redirect","trackGaEvent","sendEmail","notifyAdmins","enrollList","updateDataset","assignCampaign","wait","waitForEvent","exitFlow","setContactStage","addContactTag","assignContactOwner","createCrmTask","logCrmActivity","isFlowWaitMinutes","isInteger","isCustomEventName","includes","test","validateHostAction","validateStep","label","serverStepProblem","delayMinutes","waited","datasetId","datasetName","webhookId","webhookName","listId","listName","campaignId","campaignName","lifecycleStage","length","named","Boolean","ownerUid","ownerEmail","assigneeEmail","WEBHOOK_MAX_PER_HOST"],"mappings":";;AAAA;;;;;;;;;;;;;;;CAeC,GAED,SAEEA,qBAAqB,EAGrBC,uBAAuB,EACvBC,iBAAiB,EACjBC,aAAa,QACR,iBAAa;AACpB,SAEEC,oBAAoB,EAOpBC,mBAAmB,QACd,yBAAqB;AAC5B,SAASC,gBAAgB,QAAQ,mBAAe;AAEhD;;;;;;;;;;;;CAYC,GACD,cAAc,yBAAqB;AASnC;;;;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AAK2B,SAAS,GAAG,KACjB3B,KAAK2B,SAAS,GAAGtC,uBACjB;YACA,OAAO,GAAGqH,MAAM,WAAW,EAAErH,sBAAsB,KAAK,CAAC;QAC3D;QACA,uEAAuE;QACvE,iEAAiE;QACjE,MAAMuI,0BAAgB5H,sBAAAA,KAAK4H,aAAa,qBAAlB5H,oBAAoBQ,IAAI,sBAAM;QACpD,IAAIoH,iBAAiB,CAACA,cAActB,QAAQ,CAAC,MAAM;YACjD,OAAO,GAAGI,MAAM,oCAAoC,CAAC;QACvD;IACF;IACA,IAAI1G,KAAKE,IAAI,KAAK,kBAAkB;YAI7BF;QAHL,IAAI,CAACT,kBAAkBS,KAAK0B,IAAI,GAAG;YACjC,OAAO,GAAGgF,MAAM,2BAA2B,CAAC;QAC9C;QACA,IAAI,GAAC1G,cAAAA,KAAK6B,IAAI,qBAAT7B,YAAWQ,IAAI,KAAI,OAAO,GAAGkG,MAAM,qBAAqB,CAAC;IAChE;IACA,OAAO;AACT;AAEA,yEAAyE,GACzE,OAAO,MAAMmB,uBAAuB,EAAC"}
@@ -128,7 +128,7 @@
128
128
  * are resolved by different functions on purpose, and neither reads the
129
129
  * other.
130
130
  */
131
- import type { TopicSubscriptionState } from './email-topics';
131
+ import type { TopicSubscriptionState } from './subscription-topics';
132
132
  import { type ScopeToken } from './scope-tokens';
133
133
  /**
134
134
  * The org field holding the declarations: