@teleporthq/teleport-plugin-next-workflows 0.43.46 → 0.43.47

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 (103) hide show
  1. package/__tests__/auth-env-secret-preservation.test.ts +35 -0
  2. package/__tests__/auth-nextauth-url.test.ts +28 -0
  3. package/__tests__/auth-session-cost.test.ts +614 -0
  4. package/__tests__/custom-js-params-env-invariance.test.ts +134 -0
  5. package/__tests__/data-node-not-awaited.test.ts +644 -0
  6. package/__tests__/element-trigger-static-attr-replace.test.ts +99 -0
  7. package/__tests__/element-visible-trigger-scoping.test.ts +296 -0
  8. package/__tests__/payment-charge-user-handler-serialization.test.ts +7 -5
  9. package/__tests__/payment-redirect-and-order-notification.test.ts +6 -4
  10. package/__tests__/raw-sql-param-binding.test.ts +82 -0
  11. package/__tests__/reserved-word-state-binding.test.ts +112 -0
  12. package/__tests__/strip-event-handler-attrs.test.ts +59 -0
  13. package/__tests__/workflow-auth-guard.test.ts +277 -0
  14. package/dist/cjs/api-route-generator.d.ts +3 -3
  15. package/dist/cjs/api-route-generator.d.ts.map +1 -1
  16. package/dist/cjs/api-route-generator.js +136 -11
  17. package/dist/cjs/api-route-generator.js.map +1 -1
  18. package/dist/cjs/auth-generator.d.ts +67 -1
  19. package/dist/cjs/auth-generator.d.ts.map +1 -1
  20. package/dist/cjs/auth-generator.js +458 -20
  21. package/dist/cjs/auth-generator.js.map +1 -1
  22. package/dist/cjs/await-result.d.ts +31 -0
  23. package/dist/cjs/await-result.d.ts.map +1 -0
  24. package/dist/cjs/await-result.js +50 -0
  25. package/dist/cjs/await-result.js.map +1 -0
  26. package/dist/cjs/executor-generator.d.ts.map +1 -1
  27. package/dist/cjs/executor-generator.js +150 -1
  28. package/dist/cjs/executor-generator.js.map +1 -1
  29. package/dist/cjs/nodes/account/account-get-current.d.ts.map +1 -1
  30. package/dist/cjs/nodes/account/account-get-current.js +44 -11
  31. package/dist/cjs/nodes/account/account-get-current.js.map +1 -1
  32. package/dist/cjs/nodes/account/account-login.d.ts.map +1 -1
  33. package/dist/cjs/nodes/account/account-login.js +10 -1
  34. package/dist/cjs/nodes/account/account-login.js.map +1 -1
  35. package/dist/cjs/raw-sql-param-binding.d.ts.map +1 -1
  36. package/dist/cjs/raw-sql-param-binding.js +32 -0
  37. package/dist/cjs/raw-sql-param-binding.js.map +1 -1
  38. package/dist/cjs/segment-splitter.d.ts.map +1 -1
  39. package/dist/cjs/segment-splitter.js +15 -7
  40. package/dist/cjs/segment-splitter.js.map +1 -1
  41. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  42. package/dist/cjs/workflow-auth-generator.d.ts +26 -0
  43. package/dist/cjs/workflow-auth-generator.d.ts.map +1 -0
  44. package/dist/cjs/workflow-auth-generator.js +166 -0
  45. package/dist/cjs/workflow-auth-generator.js.map +1 -0
  46. package/dist/cjs/workflow-component-plugin.d.ts.map +1 -1
  47. package/dist/cjs/workflow-component-plugin.js +107 -16
  48. package/dist/cjs/workflow-component-plugin.js.map +1 -1
  49. package/dist/cjs/workflow-project-plugin.d.ts +2 -1
  50. package/dist/cjs/workflow-project-plugin.d.ts.map +1 -1
  51. package/dist/cjs/workflow-project-plugin.js +170 -20
  52. package/dist/cjs/workflow-project-plugin.js.map +1 -1
  53. package/dist/esm/api-route-generator.d.ts +3 -3
  54. package/dist/esm/api-route-generator.d.ts.map +1 -1
  55. package/dist/esm/api-route-generator.js +136 -11
  56. package/dist/esm/api-route-generator.js.map +1 -1
  57. package/dist/esm/auth-generator.d.ts +67 -1
  58. package/dist/esm/auth-generator.d.ts.map +1 -1
  59. package/dist/esm/auth-generator.js +453 -19
  60. package/dist/esm/auth-generator.js.map +1 -1
  61. package/dist/esm/await-result.d.ts +31 -0
  62. package/dist/esm/await-result.d.ts.map +1 -0
  63. package/dist/esm/await-result.js +45 -0
  64. package/dist/esm/await-result.js.map +1 -0
  65. package/dist/esm/executor-generator.d.ts.map +1 -1
  66. package/dist/esm/executor-generator.js +150 -1
  67. package/dist/esm/executor-generator.js.map +1 -1
  68. package/dist/esm/nodes/account/account-get-current.d.ts.map +1 -1
  69. package/dist/esm/nodes/account/account-get-current.js +44 -11
  70. package/dist/esm/nodes/account/account-get-current.js.map +1 -1
  71. package/dist/esm/nodes/account/account-login.d.ts.map +1 -1
  72. package/dist/esm/nodes/account/account-login.js +10 -1
  73. package/dist/esm/nodes/account/account-login.js.map +1 -1
  74. package/dist/esm/raw-sql-param-binding.d.ts.map +1 -1
  75. package/dist/esm/raw-sql-param-binding.js +32 -0
  76. package/dist/esm/raw-sql-param-binding.js.map +1 -1
  77. package/dist/esm/segment-splitter.d.ts.map +1 -1
  78. package/dist/esm/segment-splitter.js +15 -7
  79. package/dist/esm/segment-splitter.js.map +1 -1
  80. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  81. package/dist/esm/workflow-auth-generator.d.ts +26 -0
  82. package/dist/esm/workflow-auth-generator.d.ts.map +1 -0
  83. package/dist/esm/workflow-auth-generator.js +161 -0
  84. package/dist/esm/workflow-auth-generator.js.map +1 -0
  85. package/dist/esm/workflow-component-plugin.d.ts.map +1 -1
  86. package/dist/esm/workflow-component-plugin.js +108 -17
  87. package/dist/esm/workflow-component-plugin.js.map +1 -1
  88. package/dist/esm/workflow-project-plugin.d.ts +2 -1
  89. package/dist/esm/workflow-project-plugin.d.ts.map +1 -1
  90. package/dist/esm/workflow-project-plugin.js +169 -20
  91. package/dist/esm/workflow-project-plugin.js.map +1 -1
  92. package/package.json +4 -4
  93. package/src/api-route-generator.ts +139 -11
  94. package/src/auth-generator.ts +471 -19
  95. package/src/await-result.ts +52 -0
  96. package/src/executor-generator.ts +150 -1
  97. package/src/nodes/account/account-get-current.ts +44 -9
  98. package/src/nodes/account/account-login.ts +12 -1
  99. package/src/raw-sql-param-binding.ts +33 -0
  100. package/src/segment-splitter.ts +15 -7
  101. package/src/workflow-auth-generator.ts +187 -0
  102. package/src/workflow-component-plugin.ts +129 -20
  103. package/src/workflow-project-plugin.ts +186 -19
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-auth-generator.d.ts","sourceRoot":"","sources":["../../src/workflow-auth-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAEnE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,8BAA8B,QAAO,MA2HjD,CAAA;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IAEpC,WAAW,EAAE,MAAM,CAAA;IAEnB,WAAW,EAAE,MAAM,CAAA;IAGnB,SAAS,EAAE,MAAM,CAAA;CAClB;AAID,eAAO,MAAM,0BAA0B,eACzB,sBAAsB,GAAG,SAAS,KAC7C,qBA4BF,CAAA"}
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildWorkflowAuthInjection = exports.generateWorkflowAuthHelperFile = void 0;
4
+ /**
5
+ * The shared, stateless auth guard for generated workflow API routes, emitted
6
+ * once at `utils/workflows/workflow-auth.js`.
7
+ *
8
+ * The policy is baked into each route at build time (from the workflow's page
9
+ * protection + a scan of its graph for user-owned writes), so enforcement is a
10
+ * single local JWT decode — `getToken` reads the session cookie the browser
11
+ * already sends and verifies it with `NEXTAUTH_SECRET`. No DB, no network, no
12
+ * round trip. `next-auth/jwt` is required LAZILY so a project generated without
13
+ * authentication (where the package is absent) never fails to load this file —
14
+ * such projects also carry no protected workflows, so the guard no-ops.
15
+ */
16
+ const generateWorkflowAuthHelperFile = () => {
17
+ return `'use strict';
18
+
19
+ // GENERATED — see generateWorkflowAuthHelperFile in
20
+ // @teleporthq/teleport-plugin-next-workflows/src/workflow-auth-generator.ts.
21
+ //
22
+ // Stateless auth guard for workflow API routes. Each route bakes its own policy
23
+ // (const __WF_AUTH) computed by the GUI mapper from the protection of the
24
+ // page(s) that trigger the workflow plus a graph scan for user-owned writes.
25
+
26
+ function getSessionToken(req) {
27
+ var secret = process.env.NEXTAUTH_SECRET;
28
+ if (!secret) {
29
+ return Promise.resolve(null);
30
+ }
31
+ var getToken;
32
+ try {
33
+ getToken = require('next-auth/jwt').getToken;
34
+ } catch (e) {
35
+ return Promise.resolve(null);
36
+ }
37
+ if (typeof getToken !== 'function') {
38
+ return Promise.resolve(null);
39
+ }
40
+ // Local cookie decode — no DB, no network.
41
+ return Promise.resolve()
42
+ .then(function () { return getToken({ req: req, secret: secret }); })
43
+ .catch(function () { return null; });
44
+ }
45
+
46
+ function sessionUserId(token) {
47
+ if (!token || typeof token !== 'object') {
48
+ return null;
49
+ }
50
+ return token.id != null ? token.id : (token.sub != null ? token.sub : null);
51
+ }
52
+
53
+ function roleOf(token) {
54
+ if (!token || typeof token !== 'object') {
55
+ return null;
56
+ }
57
+ if (typeof token.role === 'string') {
58
+ return token.role;
59
+ }
60
+ if (typeof token.roleName === 'string') {
61
+ return token.roleName;
62
+ }
63
+ if (Array.isArray(token.roles) && token.roles.length > 0 && typeof token.roles[0] === 'string') {
64
+ return token.roles[0];
65
+ }
66
+ return null;
67
+ }
68
+
69
+ // Overwrites context[nodeId] drilled down \`path\` with the session user id.
70
+ function bindPath(root, path, value) {
71
+ if (!root || !path || path.length === 0) {
72
+ return;
73
+ }
74
+ var obj = root;
75
+ for (var i = 0; i < path.length - 1; i++) {
76
+ var key = path[i];
77
+ if (obj[key] == null || typeof obj[key] !== 'object') {
78
+ obj[key] = {};
79
+ }
80
+ obj = obj[key];
81
+ }
82
+ obj[path[path.length - 1]] = value;
83
+ }
84
+
85
+ // Returns null when the request may proceed, or { status, message } to reject.
86
+ // Mutates \`context\` in place to bind user-owned columns to the session user.
87
+ async function guardWorkflowRequest(req, context, policy) {
88
+ if (!policy) {
89
+ return null;
90
+ }
91
+
92
+ // Trusted internal server-to-server calls (e.g. password reset, server jobs)
93
+ // present the app secret in a header; only server code can read
94
+ // NEXTAUTH_SECRET, so a browser cannot forge it. These bypass the check.
95
+ var internal = req && req.headers && req.headers['x-internal-data-secret'];
96
+ if (internal && process.env.NEXTAUTH_SECRET && internal === process.env.NEXTAUTH_SECRET) {
97
+ return null;
98
+ }
99
+
100
+ var token = await getSessionToken(req);
101
+
102
+ if (policy.requiresAuth && !token) {
103
+ return { status: 401, message: 'Unauthenticated' };
104
+ }
105
+
106
+ var roles = policy.allowedRoles || [];
107
+ if (policy.requiresAuth && roles.length > 0) {
108
+ var role = roleOf(token);
109
+ if (!role || roles.indexOf(role) < 0) {
110
+ return { status: 403, message: 'Forbidden' };
111
+ }
112
+ }
113
+
114
+ // Identity binding: force every user-owned column to the AUTHENTICATED session
115
+ // id so a caller can never act on another user's rows. Only when a session is
116
+ // present — a guest keeps their (anonymous) client identity, which is why a
117
+ // guest-capable public write is not blocked here.
118
+ if (policy.userScoped && context) {
119
+ var sid = sessionUserId(token);
120
+ if (sid != null) {
121
+ var bindings = (policy.userScoped && policy.userScoped.bindings) || [];
122
+ for (var i = 0; i < bindings.length; i++) {
123
+ var b = bindings[i];
124
+ if (b && b.nodeId) {
125
+ if (context[b.nodeId] == null || typeof context[b.nodeId] !== 'object') {
126
+ context[b.nodeId] = {};
127
+ }
128
+ bindPath(context[b.nodeId], b.path || [], sid);
129
+ }
130
+ }
131
+ }
132
+ }
133
+
134
+ return null;
135
+ }
136
+
137
+ module.exports = { guardWorkflowRequest: guardWorkflowRequest };
138
+ `;
139
+ };
140
+ exports.generateWorkflowAuthHelperFile = generateWorkflowAuthHelperFile;
141
+ const EMPTY_INJECTION = { requireLine: '', policyConst: '', guardCall: '' };
142
+ const buildWorkflowAuthInjection = (protection) => {
143
+ if (!protection || (!protection.requiresAuth && !protection.userScoped)) {
144
+ return EMPTY_INJECTION;
145
+ }
146
+ // Only the fields the runtime guard reads — `derivedFrom` is build-time only.
147
+ const policy = {
148
+ requiresAuth: !!protection.requiresAuth,
149
+ allowedRoles: protection.allowedRoles || [],
150
+ };
151
+ if (protection.userScoped) {
152
+ policy.userScoped = protection.userScoped;
153
+ }
154
+ return {
155
+ requireLine: `const __wfAuth = require('../../../utils/workflows/workflow-auth');\n`,
156
+ policyConst: `const __WF_AUTH = ${JSON.stringify(policy)};\n`,
157
+ guardCall: `
158
+ const __authError = await __wfAuth.guardWorkflowRequest(req, context, __WF_AUTH);
159
+ if (__authError) {
160
+ res.status(__authError.status).json({ error: __authError.message });
161
+ return;
162
+ }`,
163
+ };
164
+ };
165
+ exports.buildWorkflowAuthInjection = buildWorkflowAuthInjection;
166
+ //# sourceMappingURL=workflow-auth-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-auth-generator.js","sourceRoot":"","sources":["../../src/workflow-auth-generator.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;GAWG;AACI,MAAM,8BAA8B,GAAG,GAAW,EAAE;IACzD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyHR,CAAA;AACD,CAAC,CAAA;AA3HY,QAAA,8BAA8B,kCA2H1C;AAiBD,MAAM,eAAe,GAA0B,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;AAE3F,MAAM,0BAA0B,GAAG,CACxC,UAA8C,EACvB,EAAE;IACzB,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,UAAU,CAAC,YAAY,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;QACvE,OAAO,eAAe,CAAA;KACvB;IAED,8EAA8E;IAC9E,MAAM,MAAM,GAIR;QACF,YAAY,EAAE,CAAC,CAAC,UAAU,CAAC,YAAY;QACvC,YAAY,EAAE,UAAU,CAAC,YAAY,IAAI,EAAE;KAC5C,CAAA;IACD,IAAI,UAAU,CAAC,UAAU,EAAE;QACzB,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,CAAA;KAC1C;IAED,OAAO;QACL,WAAW,EAAE,uEAAuE;QACpF,WAAW,EAAE,qBAAqB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK;QAC7D,SAAS,EAAE;;;;;MAKT;KACH,CAAA;AACH,CAAC,CAAA;AA9BY,QAAA,0BAA0B,8BA8BtC"}
@@ -1 +1 @@
1
- {"version":3,"file":"workflow-component-plugin.d.ts","sourceRoot":"","sources":["../../src/workflow-component-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EAUvB,MAAM,4BAA4B,CAAA;AAcnC,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AA8JD,eAAO,MAAM,wBAAwB,EAAE,sBAAsB,CAAC,oBAAoB,CAycjF,CAAA"}
1
+ {"version":3,"file":"workflow-component-plugin.d.ts","sourceRoot":"","sources":["../../src/workflow-component-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,EAUvB,MAAM,4BAA4B,CAAA;AAenC,UAAU,oBAAoB;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAiLD,eAAO,MAAM,wBAAwB,EAAE,sBAAsB,CAAC,oBAAoB,CAoejF,CAAA"}
@@ -28,6 +28,7 @@ const teleport_types_1 = require("@teleporthq/teleport-types");
28
28
  const types = __importStar(require("@babel/types"));
29
29
  const teleport_shared_1 = require("@teleporthq/teleport-shared");
30
30
  const segment_splitter_1 = require("./segment-splitter");
31
+ const await_result_1 = require("./await-result");
31
32
  const api_route_generator_1 = require("./api-route-generator");
32
33
  const graph_utils_1 = require("./graph-utils");
33
34
  const is_logged_in_gate_1 = require("./is-logged-in-gate");
@@ -70,6 +71,21 @@ const DOM_TO_REACT_EVENT = {
70
71
  dragend: 'onDragEnd',
71
72
  drag: 'onDrag',
72
73
  };
74
+ /**
75
+ * Trigger types that run as LIFECYCLE code (no React event prop) but are still
76
+ * bound to ONE element, so the workflow only belongs on the page that renders
77
+ * it. Returns the DOM id to prune against, or null when the trigger is not
78
+ * element-scoped.
79
+ *
80
+ * Same fallback chain as the element-trigger branch: the HTML id first, the
81
+ * project-document node id only as a last resort.
82
+ */
83
+ const resolveLifecycleTriggerElementId = (triggerType, config) => {
84
+ if (triggerType !== 'event-element-visible') {
85
+ return null;
86
+ }
87
+ return (config.elementHtmlId || config.nodeId) || null;
88
+ };
73
89
  const getReactEventProp = (triggerType, config) => {
74
90
  switch (triggerType) {
75
91
  case 'event-element-clicked':
@@ -183,6 +199,8 @@ const createNextWorkflowPlugin = (config) => {
183
199
  // Classify triggers into element-bound vs lifecycle
184
200
  const elementTriggers = [];
185
201
  const lifecycleWorkflows = [];
202
+ /** Lifecycle workflows bound to one element, for the per-page JSX prune. */
203
+ const lifecycleElementTargets = [];
186
204
  const stateChangeWorkflows = [];
187
205
  const globalStateChangeWorkflows = [];
188
206
  for (const wf of relevantWorkflows) {
@@ -225,6 +243,17 @@ const createNextWorkflowPlugin = (config) => {
225
243
  }
226
244
  else {
227
245
  lifecycleWorkflows.push(wf);
246
+ // An element-scoped LIFECYCLE trigger (element-visible) has no React
247
+ // prop, so it lands here — and `lifecycleWorkflows` was activated
248
+ // unconditionally, bypassing the JSX-presence prune below that is the
249
+ // only thing scoping element workflows to one page. One cookie-consent
250
+ // check therefore shipped into EVERY generated file (17 per page in run
251
+ // a15472af, including 404.js and logo.js, which have no banner at all).
252
+ // Record its target so it is pruned like any other element trigger.
253
+ const lifecycleElementId = resolveLifecycleTriggerElementId(trigger.type, triggerConfig);
254
+ if (lifecycleElementId) {
255
+ lifecycleElementTargets.push({ workflowId: wf.id, elementId: lifecycleElementId });
256
+ }
228
257
  }
229
258
  }
230
259
  // Pre-scan: find which element triggers can be matched to JSX elements
@@ -234,8 +263,13 @@ const createNextWorkflowPlugin = (config) => {
234
263
  let matchedElements = new Map();
235
264
  const matchedElementTriggers = [];
236
265
  const unmatchedElementTriggers = [];
237
- if (returnStatement && returnStatement.argument && elementTriggers.length > 0) {
238
- const targetIds = new Set(elementTriggers.map((t) => t.elementId));
266
+ if (returnStatement &&
267
+ returnStatement.argument &&
268
+ (elementTriggers.length > 0 || lifecycleElementTargets.length > 0)) {
269
+ const targetIds = new Set([
270
+ ...elementTriggers.map((t) => t.elementId),
271
+ ...lifecycleElementTargets.map((t) => t.elementId),
272
+ ]);
239
273
  matchedElements = findJSXElementsById(returnStatement.argument, targetIds);
240
274
  for (const et of elementTriggers) {
241
275
  if (matchedElements.has(et.elementId)) {
@@ -256,6 +290,13 @@ const createNextWorkflowPlugin = (config) => {
256
290
  activeWorkflowIds.add(et.workflow.id);
257
291
  }
258
292
  for (const wf of lifecycleWorkflows) {
293
+ // A lifecycle workflow bound to a specific element is only active on the
294
+ // page that actually renders that element. One with no element target
295
+ // (page-loaded, interval, …) stays unconditionally active.
296
+ const target = lifecycleElementTargets.find((t) => t.workflowId === wf.id);
297
+ if (target && !matchedElements.has(target.elementId)) {
298
+ continue;
299
+ }
259
300
  activeWorkflowIds.add(wf.id);
260
301
  }
261
302
  for (const wf of stateChangeWorkflows) {
@@ -496,7 +537,14 @@ const defaultValueToLiteral = (val) => {
496
537
  }
497
538
  return types.nullLiteral();
498
539
  };
499
- const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
540
+ /**
541
+ * Object key for a state/global-state map that the workflow runtime looks up by
542
+ * the name written in the node config (`config.property`). The key therefore
543
+ * keeps the UIDL spelling ALWAYS — only the value beside it is a binding and
544
+ * gets sanitised. Reserved words are legal unquoted keys (`{ class: ... }`);
545
+ * anything that is not identifier syntax at all is quoted.
546
+ */
547
+ const stateMapKey = (name) => teleport_shared_1.JSIdentifiers.isValidPropertyKeyName(name) ? types.identifier(name) : types.stringLiteral(name);
500
548
  const resolveStateDefinitionKey = (rawName, stateDefinitions) => {
501
549
  if (stateDefinitions[rawName]) {
502
550
  return rawName;
@@ -513,20 +561,29 @@ const injectWorkflowCode = (componentBody, stateDefinitions, matchedTriggers, ma
513
561
  const stateValueProperties = [];
514
562
  for (const [key, def] of Object.entries(stateDefinitions)) {
515
563
  const setterName = teleport_shared_1.StringUtils.createStateStoringFunction(key);
516
- stateSetterProperties.push(types.objectProperty(types.identifier(key), types.identifier(setterName)));
517
- stateTypeProperties.push(types.objectProperty(types.identifier(key), types.stringLiteral(def.type || 'string')));
518
- stateValueProperties.push(types.objectProperty(types.identifier(key), types.identifier(key)));
564
+ // KEY: the name a workflow node's `config.property` is written against —
565
+ // never renamed. VALUE: the React binding declared by `createStateHookAST`,
566
+ // which is sanitised because a UIDL state may legally be called `class`.
567
+ stateSetterProperties.push(types.objectProperty(stateMapKey(key), types.identifier(setterName)));
568
+ stateTypeProperties.push(types.objectProperty(stateMapKey(key), types.stringLiteral(def.type || 'string')));
569
+ stateValueProperties.push(types.objectProperty(stateMapKey(key), types.identifier(teleport_shared_1.JSIdentifiers.createSafeJSIdentifier(key))));
519
570
  }
520
571
  const globalStateStatements = [];
521
572
  if (globalStateDefinitions && Object.keys(globalStateDefinitions).length > 0) {
522
573
  const destructuredProps = [];
523
574
  for (const def of Object.values(globalStateDefinitions)) {
524
- const setterName = `set${capitalize(def.name)}`;
525
- destructuredProps.push(types.objectProperty(types.identifier(def.name), types.identifier(def.name), false, true));
526
- destructuredProps.push(types.objectProperty(types.identifier(setterName), types.identifier(setterName), false, true));
527
- stateSetterProperties.push(types.objectProperty(types.identifier(def.name), types.identifier(setterName)));
528
- stateTypeProperties.push(types.objectProperty(types.identifier(def.name), types.stringLiteral(def.type || 'string')));
529
- stateValueProperties.push(types.objectProperty(types.identifier(def.name), types.identifier(def.name)));
575
+ // `GlobalStateProvider` exposes every entry under its DECLARED name, so
576
+ // the context keys stay raw and only the locals we bind are sanitised.
577
+ // The pattern then reads `{ class: class_ }` — shorthand only when the
578
+ // two coincide, which is the case for every ordinary name.
579
+ const setterKey = teleport_shared_1.StringUtils.createGlobalStateSetterName(def.name);
580
+ const setterName = teleport_shared_1.JSIdentifiers.createSafeJSIdentifier(setterKey);
581
+ const localName = teleport_shared_1.JSIdentifiers.createSafeJSIdentifier(def.name);
582
+ destructuredProps.push(types.objectProperty(stateMapKey(def.name), types.identifier(localName), false, localName === def.name));
583
+ destructuredProps.push(types.objectProperty(stateMapKey(setterKey), types.identifier(setterName), false, setterName === setterKey));
584
+ stateSetterProperties.push(types.objectProperty(stateMapKey(def.name), types.identifier(setterName)));
585
+ stateTypeProperties.push(types.objectProperty(stateMapKey(def.name), types.stringLiteral(def.type || 'string')));
586
+ stateValueProperties.push(types.objectProperty(stateMapKey(def.name), types.identifier(localName)));
530
587
  }
531
588
  // Always destructure refreshGlobalState for refreshFromDataSource support.
532
589
  // If no data source bindings exist, the context won't provide it, but
@@ -689,6 +746,12 @@ const injectWorkflowCode = (componentBody, stateDefinitions, matchedTriggers, ma
689
746
  existingExpr = existingAttr.value.expression;
690
747
  }
691
748
  else {
749
+ // A non-expression event prop (e.g. a stray `onClick=""` authored as a
750
+ // static attr) was never a callable listener — React throws
751
+ // `func.apply is not a function` on dispatch. Replace it with the
752
+ // workflow handler instead of skipping, which used to drop the
753
+ // trigger wiring silently AND ship the crashing prop.
754
+ openingElement.attributes[existingAttrIndex] = types.jSXAttribute(types.jSXIdentifier(reactProp), types.jSXExpressionContainer(wfHandlerExpr));
692
755
  continue;
693
756
  }
694
757
  // (event) => { existingHandler(event); __wfRef.current.elementTriggers[...](event); }
@@ -837,6 +900,9 @@ function __normalizeAdminFormRow(row, defaults) {
837
900
  id: s.id,
838
901
  env: s.env,
839
902
  hasStreamingAI: (0, api_route_generator_1.hasStreamingAINode)(s),
903
+ // Every node in this segment runs fire-and-forget, so the browser
904
+ // dispatches it and carries on instead of waiting for the round trip.
905
+ fireAndForget: (0, await_result_1.isFireAndForgetSegment)(s),
840
906
  nodes: s.nodes.map((n) => ({
841
907
  id: n.id,
842
908
  type: n.type,
@@ -934,8 +1000,26 @@ function __normalizeAdminFormRow(row, defaults) {
934
1000
  lifecycleLines.push(code);
935
1001
  }
936
1002
  }
937
- // Lifecycle triggers
1003
+ // Lifecycle triggers.
1004
+ //
1005
+ // `allWorkflows` here is the already-pruned `activeWorkflows`: a lifecycle
1006
+ // element-visible trigger whose target element is NOT in this component's own
1007
+ // JSX was excluded from it (its `__wfConfig_*` was therefore never declared).
1008
+ // But `generateLifecycleTrigger` emits an IntersectionObserver that resolves
1009
+ // its target at runtime with `document.getElementById(target)` — a
1010
+ // DOCUMENT-WIDE lookup that happily matches an element ANOTHER component
1011
+ // rendered (e.g. the shared "Cookie Consent" banner, which is attached to
1012
+ // ~23 element-visible workflows and would otherwise ship into every product
1013
+ // card). When it fires it calls `__execWf(__wfConfig_<id>, …)` for a config
1014
+ // that was never emitted, throwing `ReferenceError: __wfConfig_… is not
1015
+ // defined` the moment the element scrolls into view. Pruning the handler in
1016
+ // lockstep with the config keeps the two in sync: the workflow still runs in
1017
+ // the component/page that actually renders its target element.
1018
+ const emittedConfigIds = new Set(allWorkflows.map((wf) => wf.id));
938
1019
  for (const wf of lifecycleWorkflows) {
1020
+ if (!emittedConfigIds.has(wf.id)) {
1021
+ continue;
1022
+ }
939
1023
  const safeId = wf.id.replace(/[^a-zA-Z0-9]/g, '_');
940
1024
  const code = generateLifecycleTrigger(wf, safeId);
941
1025
  if (code) {
@@ -1455,16 +1539,23 @@ const generateLifecycleTrigger = (wf, safeId) => {
1455
1539
  ` cleanups.push(function() { Router.events.off('routeChangeComplete', __rc_${safeId}); });`);
1456
1540
  }
1457
1541
  case 'event-element-visible': {
1458
- const nodeId = config.nodeId;
1542
+ // `config.nodeId` is the PROJECT-DOCUMENT node id (`TQ_…`); no element in
1543
+ // the generated app ever carries it. `elementHtmlId` is the real DOM id
1544
+ // (`thq_container_…`), already stamped by `ensure-element-ids` and mapped
1545
+ // into the trigger config — the same fallback chain every other element
1546
+ // trigger uses above. Reading `nodeId` made `getElementById` return null,
1547
+ // so the observer was never constructed and the cookie-consent banner
1548
+ // could never appear on any page (run a15472af: 408 dead lookups).
1549
+ const elementId = (config.elementHtmlId || config.nodeId);
1459
1550
  const threshold = config.threshold || 0;
1460
1551
  const once = config.once;
1461
1552
  return (` // Element visible (${wf.name || wf.id})\n` +
1462
- ` const __visEl_${safeId} = document.getElementById('${nodeId}');\n` +
1553
+ ` const __visEl_${safeId} = document.getElementById('${elementId}');\n` +
1463
1554
  ` if (__visEl_${safeId}) {\n` +
1464
1555
  ` const __obs_${safeId} = new IntersectionObserver(function(entries) {\n` +
1465
1556
  ` entries.forEach(function(entry) {\n` +
1466
1557
  ` if (entry.isIntersecting) {\n` +
1467
- ` const triggerContext = { elementId: '${nodeId}', timestamp: Date.now(), intersectionRatio: entry.intersectionRatio };\n` +
1558
+ ` const triggerContext = { elementId: '${elementId}', timestamp: Date.now(), intersectionRatio: entry.intersectionRatio };\n` +
1468
1559
  ` ${execCall};\n` +
1469
1560
  (once ? ` __obs_${safeId}.disconnect();\n` : '') +
1470
1561
  ` }\n` +