@nordsym/apiclaw 1.5.17 → 1.5.19

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 (228) hide show
  1. package/convex/http.js.map +1 -1
  2. package/convex/http.ts +516 -0
  3. package/dist/analytics.d.ts +0 -4
  4. package/dist/analytics.d.ts.map +1 -1
  5. package/dist/analytics.js +0 -1
  6. package/dist/analytics.js.map +1 -1
  7. package/dist/bin.js +1 -1
  8. package/dist/cli/commands/mcp-install.d.ts.map +1 -1
  9. package/dist/cli/commands/mcp-install.js +8 -87
  10. package/dist/cli/commands/mcp-install.js.map +1 -1
  11. package/dist/cli/index.js +0 -7
  12. package/dist/credentials.d.ts.map +1 -1
  13. package/dist/credentials.js +38 -43
  14. package/dist/credentials.js.map +1 -1
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +82 -191
  17. package/dist/discovery.js.map +1 -1
  18. package/dist/http-api.d.ts.map +1 -1
  19. package/dist/http-api.js +33 -17
  20. package/dist/http-api.js.map +1 -1
  21. package/dist/proxy.js +1 -1
  22. package/dist/proxy.js.map +1 -1
  23. package/landing/next-env.d.ts +0 -1
  24. package/landing/src/app/api/auth/magic-link/route.ts +1 -1
  25. package/landing/src/app/auth/verify/page.tsx +0 -6
  26. package/landing/src/app/dashboard/verify/page.tsx +0 -6
  27. package/landing/src/app/join/page.tsx +0 -6
  28. package/landing/src/app/layout.tsx +2 -2
  29. package/landing/src/app/login/page.tsx +1 -1
  30. package/landing/src/app/mou/[partnerId]/page.tsx +0 -6
  31. package/landing/src/app/page.tsx +18 -39
  32. package/landing/src/app/providers/dashboard/[apiId]/actions/[actionId]/edit/page.tsx +0 -6
  33. package/landing/src/app/providers/dashboard/[apiId]/actions/new/page.tsx +0 -5
  34. package/landing/src/app/providers/dashboard/[apiId]/actions/page.tsx +0 -5
  35. package/landing/src/app/providers/dashboard/[apiId]/direct-call/page.tsx +1 -6
  36. package/landing/src/app/providers/dashboard/[apiId]/page.tsx +0 -5
  37. package/landing/src/app/providers/dashboard/[apiId]/test/page.tsx +0 -5
  38. package/landing/src/app/providers/dashboard/layout.tsx +6 -6
  39. package/landing/src/app/providers/dashboard/login/page.tsx +1 -1
  40. package/landing/src/app/providers/dashboard/page.tsx +1 -1
  41. package/landing/src/app/providers/dashboard/verify/page.tsx +0 -6
  42. package/landing/src/app/providers/layout.tsx +1 -1
  43. package/landing/src/app/upgrade/page.tsx +0 -6
  44. package/landing/src/app/workspace/page.tsx +0 -6
  45. package/landing/src/components/HeroTabs.tsx +2 -2
  46. package/landing/src/components/{Workspace.tsx → ProviderDashboard.tsx} +2 -2
  47. package/landing/src/components/VideoDemo.tsx +10 -21
  48. package/landing/src/lib/mock-data.ts +1 -1
  49. package/landing/src/lib/stats.json +1 -1
  50. package/package.json +3 -8
  51. package/src/analytics.ts +0 -5
  52. package/src/bin.ts +1 -1
  53. package/src/cli/commands/mcp-install.ts +8 -90
  54. package/src/cli/index.ts +0 -8
  55. package/src/credentials.ts +39 -44
  56. package/src/discovery.ts +82 -191
  57. package/src/http-api.ts +34 -18
  58. package/src/proxy.ts +1 -1
  59. package/APILAYER_STATUS_2026-03-24.md +0 -38
  60. package/CHANGELOG-WHITELIST-V2.md +0 -269
  61. package/HIVR-WHITELIST-STATUS.md +0 -205
  62. package/HIVR-WHITELIST.md +0 -148
  63. package/TERMINOLOGY-AUDIT.md +0 -99
  64. package/TERMINOLOGY-FIXED.md +0 -74
  65. package/VIDEO-DEMO-GUIDE.md +0 -82
  66. package/WHITELIST-ARCHITECTURE.md +0 -379
  67. package/api/discover.ts +0 -71
  68. package/api/health.ts +0 -20
  69. package/convex/adminActivate.d.ts +0 -3
  70. package/convex/adminActivate.js +0 -47
  71. package/convex/adminStats.d.ts +0 -3
  72. package/convex/adminStats.js +0 -42
  73. package/convex/agents.d.ts +0 -54
  74. package/convex/agents.js +0 -499
  75. package/convex/analytics.d.ts +0 -5
  76. package/convex/analytics.js +0 -166
  77. package/convex/billing.d.ts +0 -88
  78. package/convex/billing.js +0 -655
  79. package/convex/capabilities.d.ts +0 -9
  80. package/convex/capabilities.js +0 -145
  81. package/convex/chains.d.ts +0 -67
  82. package/convex/chains.js +0 -1042
  83. package/convex/credits.d.ts +0 -25
  84. package/convex/credits.js +0 -186
  85. package/convex/crons.d.ts +0 -3
  86. package/convex/crons.js +0 -17
  87. package/convex/directCall.d.ts +0 -72
  88. package/convex/directCall.js +0 -627
  89. package/convex/earnProgress.d.ts +0 -58
  90. package/convex/earnProgress.js +0 -649
  91. package/convex/email.d.ts +0 -14
  92. package/convex/email.js +0 -300
  93. package/convex/feedback.d.ts +0 -7
  94. package/convex/feedback.js +0 -227
  95. package/convex/http.d.ts +0 -3
  96. package/convex/http.js +0 -910
  97. package/convex/logs.d.ts +0 -38
  98. package/convex/logs.js +0 -487
  99. package/convex/mou.d.ts +0 -6
  100. package/convex/mou.js +0 -82
  101. package/convex/providerKeys.d.ts +0 -31
  102. package/convex/providerKeys.js +0 -257
  103. package/convex/providers.d.ts +0 -29
  104. package/convex/providers.js +0 -756
  105. package/convex/purchases.d.ts +0 -7
  106. package/convex/purchases.js +0 -157
  107. package/convex/ratelimit.d.ts +0 -4
  108. package/convex/ratelimit.js +0 -91
  109. package/convex/searchLogs.d.ts +0 -4
  110. package/convex/searchLogs.js +0 -129
  111. package/convex/spendAlerts.d.ts +0 -36
  112. package/convex/spendAlerts.js +0 -380
  113. package/convex/stripeActions.d.ts +0 -19
  114. package/convex/stripeActions.js +0 -411
  115. package/convex/teams.d.ts +0 -21
  116. package/convex/teams.js +0 -215
  117. package/convex/telemetry.d.ts +0 -4
  118. package/convex/telemetry.js +0 -74
  119. package/convex/usage.d.ts +0 -27
  120. package/convex/usage.js +0 -229
  121. package/convex/waitlist.d.ts +0 -4
  122. package/convex/waitlist.js +0 -49
  123. package/convex/webhooks.d.ts +0 -12
  124. package/convex/webhooks.js +0 -410
  125. package/convex/workspaces.d.ts +0 -29
  126. package/convex/workspaces.js +0 -880
  127. package/direct-test.mjs +0 -51
  128. package/dist/access-control.d.ts +0 -45
  129. package/dist/access-control.d.ts.map +0 -1
  130. package/dist/access-control.js +0 -142
  131. package/dist/access-control.js.map +0 -1
  132. package/dist/chain-types.d.ts +0 -187
  133. package/dist/chain-types.d.ts.map +0 -1
  134. package/dist/chain-types.js +0 -33
  135. package/dist/chain-types.js.map +0 -1
  136. package/dist/convex/adminActivate.js +0 -46
  137. package/dist/convex/adminStats.js +0 -41
  138. package/dist/convex/agents.js +0 -498
  139. package/dist/convex/analytics.js +0 -165
  140. package/dist/convex/billing.js +0 -654
  141. package/dist/convex/capabilities.js +0 -144
  142. package/dist/convex/chains.js +0 -1041
  143. package/dist/convex/credits.js +0 -185
  144. package/dist/convex/crons.js +0 -16
  145. package/dist/convex/directCall.js +0 -626
  146. package/dist/convex/earnProgress.js +0 -648
  147. package/dist/convex/email.js +0 -299
  148. package/dist/convex/feedback.js +0 -226
  149. package/dist/convex/http.js +0 -909
  150. package/dist/convex/logs.js +0 -486
  151. package/dist/convex/mou.js +0 -81
  152. package/dist/convex/providerKeys.js +0 -256
  153. package/dist/convex/providers.js +0 -755
  154. package/dist/convex/purchases.js +0 -156
  155. package/dist/convex/ratelimit.js +0 -90
  156. package/dist/convex/schema.js +0 -709
  157. package/dist/convex/searchLogs.js +0 -128
  158. package/dist/convex/spendAlerts.js +0 -379
  159. package/dist/convex/stripeActions.js +0 -410
  160. package/dist/convex/teams.js +0 -214
  161. package/dist/convex/telemetry.js +0 -73
  162. package/dist/convex/usage.js +0 -228
  163. package/dist/convex/waitlist.js +0 -48
  164. package/dist/convex/webhooks.js +0 -409
  165. package/dist/convex/workspaces.js +0 -879
  166. package/dist/hivr-whitelist.d.ts +0 -18
  167. package/dist/hivr-whitelist.d.ts.map +0 -1
  168. package/dist/hivr-whitelist.js +0 -95
  169. package/dist/hivr-whitelist.js.map +0 -1
  170. package/dist/http-server-minimal.d.ts +0 -7
  171. package/dist/http-server-minimal.d.ts.map +0 -1
  172. package/dist/http-server-minimal.js +0 -126
  173. package/dist/http-server-minimal.js.map +0 -1
  174. package/dist/product-whitelist.d.ts +0 -37
  175. package/dist/product-whitelist.d.ts.map +0 -1
  176. package/dist/product-whitelist.js +0 -203
  177. package/dist/product-whitelist.js.map +0 -1
  178. package/dist/src/analytics.js +0 -129
  179. package/dist/src/bin.js +0 -17
  180. package/dist/src/capability-router.js +0 -240
  181. package/dist/src/chainExecutor.js +0 -451
  182. package/dist/src/chainResolver.js +0 -518
  183. package/dist/src/cli/commands/doctor.js +0 -324
  184. package/dist/src/cli/commands/mcp-install.js +0 -255
  185. package/dist/src/cli/commands/restore.js +0 -259
  186. package/dist/src/cli/commands/setup.js +0 -205
  187. package/dist/src/cli/commands/uninstall.js +0 -188
  188. package/dist/src/cli/index.js +0 -111
  189. package/dist/src/cli.js +0 -302
  190. package/dist/src/confirmation.js +0 -240
  191. package/dist/src/credentials.js +0 -357
  192. package/dist/src/credits.js +0 -260
  193. package/dist/src/crypto.js +0 -66
  194. package/dist/src/discovery.js +0 -504
  195. package/dist/src/enterprise/env.js +0 -123
  196. package/dist/src/enterprise/script-generator.js +0 -460
  197. package/dist/src/execute-dynamic.js +0 -473
  198. package/dist/src/execute.js +0 -1727
  199. package/dist/src/index.js +0 -2062
  200. package/dist/src/metered.js +0 -80
  201. package/dist/src/open-apis.js +0 -276
  202. package/dist/src/proxy.js +0 -28
  203. package/dist/src/session.js +0 -86
  204. package/dist/src/stripe.js +0 -407
  205. package/dist/src/telemetry.js +0 -49
  206. package/dist/src/types.js +0 -2
  207. package/dist/src/utils/backup.js +0 -181
  208. package/dist/src/utils/config.js +0 -220
  209. package/dist/src/utils/os.js +0 -105
  210. package/dist/src/utils/paths.js +0 -159
  211. package/landing/pages/api/discover.ts +0 -43
  212. package/landing/pages/api/health.ts +0 -20
  213. package/scripts/test-whitelist-v2.sh +0 -128
  214. package/src/access-control.ts +0 -174
  215. package/src/hivr-whitelist.ts +0 -110
  216. package/src/http-server-minimal.ts +0 -154
  217. package/src/product-whitelist.ts +0 -246
  218. package/test-actual-handlers.ts +0 -92
  219. package/test-apilayer-all-14.ts +0 -249
  220. package/test-apilayer-fixed.ts +0 -248
  221. package/test-direct-endpoints.ts +0 -174
  222. package/test-exact-endpoints.ts +0 -144
  223. package/test-final.ts +0 -83
  224. package/test-full-routing.ts +0 -100
  225. package/test-handlers-correct.ts +0 -217
  226. package/test-numverify-key.ts +0 -41
  227. package/test-via-handlers.ts +0 -92
  228. package/test-worldnews.mjs +0 -26
@@ -1,518 +0,0 @@
1
- /**
2
- * APIClaw Chain Resolver
3
- *
4
- * Handles reference resolution between chain steps.
5
- * Supports: $prev, $stepId, $parallel, $chain, $inputs, $forEach
6
- */
7
- // ============================================================================
8
- // REFERENCE PATTERNS
9
- // ============================================================================
10
- // Matches all $references in a string
11
- const REFERENCE_PATTERN = /\$(?:prev|chain|inputs|parallel|forEach|item|index|env|\w+)(?:\[\d+\])?(?:\.[a-zA-Z_][\w]*(?:\[\d+\])?)*|\$\w+(?:\.[a-zA-Z_][\w]*(?:\[\d+\])?)+/g;
12
- // Matches a single complete reference for parsing
13
- const SINGLE_REF_PATTERN = /^\$(\w+)(\[\d+\])?(.*)$/;
14
- // ============================================================================
15
- // REFERENCE EXTRACTION
16
- // ============================================================================
17
- /**
18
- * Extract all $references from a string
19
- */
20
- export function extractReferences(text) {
21
- const matches = text.match(REFERENCE_PATTERN);
22
- if (!matches)
23
- return [];
24
- return matches.map(parseReference).filter((r) => r !== null);
25
- }
26
- /**
27
- * Parse a single reference string into a Reference object
28
- */
29
- export function parseReference(raw) {
30
- const match = raw.match(SINGLE_REF_PATTERN);
31
- if (!match)
32
- return null;
33
- const [, rootName, arrayPart, pathPart] = match;
34
- // Determine reference type
35
- let type;
36
- let stepId;
37
- let arrayIndex;
38
- // Parse array index from root (e.g., $parallel[0])
39
- if (arrayPart) {
40
- arrayIndex = parseInt(arrayPart.slice(1, -1), 10);
41
- }
42
- switch (rootName) {
43
- case 'prev':
44
- type = 'prev';
45
- break;
46
- case 'chain':
47
- type = 'chain';
48
- break;
49
- case 'inputs':
50
- type = 'inputs';
51
- break;
52
- case 'parallel':
53
- type = 'parallel';
54
- break;
55
- case 'forEach':
56
- type = 'forEach';
57
- break;
58
- case 'item':
59
- type = 'item';
60
- break;
61
- case 'index':
62
- type = 'index';
63
- break;
64
- case 'env':
65
- type = 'env';
66
- break;
67
- default:
68
- // It's a step ID reference
69
- type = 'step';
70
- stepId = rootName;
71
- }
72
- // Parse the property path
73
- const path = parsePath(pathPart || '');
74
- return { raw, type, stepId, path, arrayIndex };
75
- }
76
- /**
77
- * Parse a property path like ".output.images[0].url" into ["output", "images", 0, "url"]
78
- */
79
- function parsePath(pathStr) {
80
- if (!pathStr)
81
- return [];
82
- const parts = [];
83
- // Remove leading dot
84
- const cleaned = pathStr.startsWith('.') ? pathStr.slice(1) : pathStr;
85
- // Split by dots and brackets
86
- const segments = cleaned.split(/\.|\[|\]/g).filter(Boolean);
87
- for (const segment of segments) {
88
- // Check if it's a numeric index
89
- if (/^\d+$/.test(segment)) {
90
- parts.push(segment); // Keep as string, will convert during resolution
91
- }
92
- else {
93
- parts.push(segment);
94
- }
95
- }
96
- return parts;
97
- }
98
- // ============================================================================
99
- // REFERENCE RESOLUTION
100
- // ============================================================================
101
- /**
102
- * Resolve a reference to its actual value from context
103
- */
104
- export function resolveReference(ref, context) {
105
- let value;
106
- switch (ref.type) {
107
- case 'prev':
108
- // Get the previous step's result
109
- if (!context.prevStepId) {
110
- throw new ReferenceError(`$prev used but no previous step exists`);
111
- }
112
- value = context.results[context.prevStepId];
113
- break;
114
- case 'step':
115
- // Get a specific step's result
116
- if (!ref.stepId || !(ref.stepId in context.results)) {
117
- throw new ReferenceError(`Step '${ref.stepId}' not found in results`);
118
- }
119
- value = context.results[ref.stepId];
120
- break;
121
- case 'parallel':
122
- // Get parallel execution results
123
- if (!context.parallelResults) {
124
- throw new ReferenceError(`$parallel used but not in parallel context`);
125
- }
126
- if (ref.arrayIndex !== undefined) {
127
- value = context.parallelResults[ref.arrayIndex];
128
- }
129
- else {
130
- value = context.parallelResults;
131
- }
132
- break;
133
- case 'chain':
134
- // Built-in chain variables
135
- value = {
136
- startedAt: context.startedAt,
137
- index: context.currentIndex,
138
- };
139
- break;
140
- case 'inputs':
141
- // Template inputs
142
- if (!context.inputs) {
143
- throw new ReferenceError(`$inputs used but no inputs provided`);
144
- }
145
- value = context.inputs;
146
- break;
147
- case 'forEach':
148
- // forEach accumulated results
149
- value = {
150
- results: context.forEachResults || [],
151
- index: context.forEachIndex,
152
- };
153
- break;
154
- case 'item':
155
- // Current forEach item
156
- if (context.forEachItem === undefined) {
157
- throw new ReferenceError(`$item used but not in forEach loop`);
158
- }
159
- value = context.forEachItem;
160
- break;
161
- case 'index':
162
- // Current forEach index
163
- if (context.forEachIndex === undefined) {
164
- throw new ReferenceError(`$index used but not in forEach loop`);
165
- }
166
- value = context.forEachIndex;
167
- break;
168
- case 'env':
169
- // Environment variables
170
- value = context.env || process.env;
171
- break;
172
- default:
173
- throw new ReferenceError(`Unknown reference type: ${ref.type}`);
174
- }
175
- // Traverse the path
176
- return traversePath(value, ref.path, ref.raw);
177
- }
178
- /**
179
- * Traverse a path through an object/array
180
- */
181
- function traversePath(obj, path, originalRef) {
182
- let current = obj;
183
- for (let i = 0; i < path.length; i++) {
184
- if (current === null || current === undefined) {
185
- const traversed = path.slice(0, i).join('.');
186
- throw new ReferenceError(`Cannot read '${path[i]}' of ${current} at ${originalRef} (traversed: ${traversed})`);
187
- }
188
- const key = path[i];
189
- // Handle array index (stored as string)
190
- if (/^\d+$/.test(key)) {
191
- current = current[parseInt(key, 10)];
192
- }
193
- else {
194
- current = current[key];
195
- }
196
- }
197
- return current;
198
- }
199
- // ============================================================================
200
- // RESOLVE ALL REFERENCES IN PARAMS
201
- // ============================================================================
202
- /**
203
- * Resolve all $references in a params object
204
- * Recursively processes strings, arrays, and nested objects
205
- */
206
- export function resolveReferences(params, context) {
207
- return resolveValue(params, context);
208
- }
209
- /**
210
- * Resolve references in any value type
211
- */
212
- function resolveValue(value, context) {
213
- if (value === null || value === undefined) {
214
- return value;
215
- }
216
- if (typeof value === 'string') {
217
- return resolveStringValue(value, context);
218
- }
219
- if (Array.isArray(value)) {
220
- return value.map(item => resolveValue(item, context));
221
- }
222
- if (typeof value === 'object') {
223
- const resolved = {};
224
- for (const [key, val] of Object.entries(value)) {
225
- resolved[key] = resolveValue(val, context);
226
- }
227
- return resolved;
228
- }
229
- // Primitives (number, boolean) pass through
230
- return value;
231
- }
232
- /**
233
- * Resolve references in a string value
234
- * Handles both full replacement and interpolation
235
- */
236
- function resolveStringValue(str, context) {
237
- const refs = extractReferences(str);
238
- if (refs.length === 0) {
239
- return str;
240
- }
241
- // If the entire string is a single reference, return the resolved value directly
242
- // This preserves types (objects, arrays, numbers)
243
- if (refs.length === 1 && refs[0].raw === str) {
244
- return resolveReference(refs[0], context);
245
- }
246
- // Multiple references or mixed content: interpolate into string
247
- let result = str;
248
- for (const ref of refs) {
249
- const resolved = resolveReference(ref, context);
250
- const stringValue = typeof resolved === 'object' ? JSON.stringify(resolved) : String(resolved);
251
- result = result.replace(ref.raw, stringValue);
252
- }
253
- return result;
254
- }
255
- // ============================================================================
256
- // VALIDATION
257
- // ============================================================================
258
- /**
259
- * Validate all references in a chain before execution
260
- * Checks that referenced steps exist and come before the referencing step
261
- */
262
- export function validateReferences(steps) {
263
- const errors = [];
264
- const warnings = [];
265
- // Build set of step IDs that will exist
266
- const definedSteps = new Set();
267
- const stepOrder = [];
268
- // First pass: collect all step IDs
269
- for (const step of steps) {
270
- if ('parallel' in step) {
271
- for (const ps of step.parallel) {
272
- definedSteps.add(ps.id);
273
- stepOrder.push(ps.id);
274
- }
275
- }
276
- else if ('forEach' in step) {
277
- // forEach generates dynamic IDs
278
- definedSteps.add(step.do.id.replace(/\$index/g, '*'));
279
- }
280
- else if ('if' in step) {
281
- const collectConditional = (s) => {
282
- const arr = Array.isArray(s) ? s : [s];
283
- for (const cs of arr) {
284
- definedSteps.add(cs.id);
285
- stepOrder.push(cs.id);
286
- }
287
- };
288
- collectConditional(step.then);
289
- if (step.else)
290
- collectConditional(step.else);
291
- }
292
- else {
293
- definedSteps.add(step.id);
294
- stepOrder.push(step.id);
295
- }
296
- }
297
- // Second pass: validate references
298
- let currentIndex = 0;
299
- const validateStep = (step, availableSteps, stepIdx) => {
300
- if (!step.params)
301
- return;
302
- const paramStr = JSON.stringify(step.params);
303
- const refs = extractReferences(paramStr);
304
- for (const ref of refs) {
305
- // Validate step references
306
- if (ref.type === 'step' && ref.stepId) {
307
- if (!definedSteps.has(ref.stepId)) {
308
- errors.push({
309
- stepId: step.id,
310
- reference: ref.raw,
311
- message: `References undefined step '${ref.stepId}'`,
312
- });
313
- }
314
- else if (!availableSteps.has(ref.stepId)) {
315
- errors.push({
316
- stepId: step.id,
317
- reference: ref.raw,
318
- message: `References step '${ref.stepId}' which hasn't executed yet`,
319
- });
320
- }
321
- }
322
- // Validate $prev usage
323
- if (ref.type === 'prev' && stepIdx === 0) {
324
- errors.push({
325
- stepId: step.id,
326
- reference: ref.raw,
327
- message: `$prev used in first step (no previous step exists)`,
328
- });
329
- }
330
- // Warn about $parallel outside parallel context
331
- if (ref.type === 'parallel') {
332
- warnings.push({
333
- stepId: step.id,
334
- reference: ref.raw,
335
- message: `$parallel used - ensure this follows a parallel block`,
336
- });
337
- }
338
- // Warn about $item/$index outside forEach
339
- if (ref.type === 'item' || ref.type === 'index') {
340
- warnings.push({
341
- stepId: step.id,
342
- reference: ref.raw,
343
- message: `${ref.raw} used - ensure this is inside a forEach block`,
344
- });
345
- }
346
- }
347
- };
348
- const availableSteps = new Set();
349
- for (const step of steps) {
350
- if ('parallel' in step) {
351
- // Parallel steps can't reference each other
352
- for (const ps of step.parallel) {
353
- validateStep(ps, availableSteps, currentIndex);
354
- }
355
- // After parallel, all are available
356
- for (const ps of step.parallel) {
357
- availableSteps.add(ps.id);
358
- }
359
- }
360
- else if ('forEach' in step) {
361
- validateStep(step.do, availableSteps, currentIndex);
362
- }
363
- else if ('if' in step) {
364
- const validateBranch = (s) => {
365
- const arr = Array.isArray(s) ? s : [s];
366
- for (const cs of arr) {
367
- validateStep(cs, availableSteps, currentIndex);
368
- availableSteps.add(cs.id);
369
- }
370
- };
371
- validateBranch(step.then);
372
- if (step.else)
373
- validateBranch(step.else);
374
- }
375
- else {
376
- validateStep(step, availableSteps, currentIndex);
377
- availableSteps.add(step.id);
378
- }
379
- currentIndex++;
380
- }
381
- return {
382
- valid: errors.length === 0,
383
- errors,
384
- warnings,
385
- };
386
- }
387
- // ============================================================================
388
- // CONDITIONAL EVALUATION
389
- // ============================================================================
390
- /**
391
- * Evaluate a conditional expression string
392
- * Supports: ===, !==, >, <, >=, <=, &&, ||, !
393
- */
394
- export function evaluateCondition(condition, context) {
395
- // First resolve any references in the condition
396
- const resolvedCondition = resolveStringValue(condition, context);
397
- // Simple expression evaluation
398
- // For security, we use a restricted evaluator instead of eval()
399
- try {
400
- return safeEvaluate(resolvedCondition, context);
401
- }
402
- catch (e) {
403
- throw new Error(`Failed to evaluate condition '${condition}': ${e}`);
404
- }
405
- }
406
- /**
407
- * Safe expression evaluator for conditions
408
- * Only allows comparison and logical operators
409
- */
410
- function safeEvaluate(expr, context) {
411
- // Trim whitespace
412
- expr = expr.trim();
413
- // Handle logical operators (lowest precedence)
414
- // Split on || first (lowest precedence)
415
- if (expr.includes('||')) {
416
- const parts = splitOnOperator(expr, '||');
417
- if (parts.length > 1) {
418
- return parts.some(part => safeEvaluate(part, context));
419
- }
420
- }
421
- // Then && (higher precedence than ||)
422
- if (expr.includes('&&')) {
423
- const parts = splitOnOperator(expr, '&&');
424
- if (parts.length > 1) {
425
- return parts.every(part => safeEvaluate(part, context));
426
- }
427
- }
428
- // Handle negation
429
- if (expr.startsWith('!')) {
430
- return !safeEvaluate(expr.slice(1), context);
431
- }
432
- // Handle parentheses
433
- if (expr.startsWith('(') && expr.endsWith(')')) {
434
- return safeEvaluate(expr.slice(1, -1), context);
435
- }
436
- // Handle comparison operators
437
- const comparisons = ['===', '!==', '>=', '<=', '>', '<', '==', '!='];
438
- for (const op of comparisons) {
439
- const idx = expr.indexOf(op);
440
- if (idx !== -1) {
441
- const left = parseValue(expr.slice(0, idx).trim());
442
- const right = parseValue(expr.slice(idx + op.length).trim());
443
- switch (op) {
444
- case '===': return left === right;
445
- case '!==': return left !== right;
446
- case '==': return left == right;
447
- case '!=': return left != right;
448
- case '>': return left > right;
449
- case '<': return left < right;
450
- case '>=': return left >= right;
451
- case '<=': return left <= right;
452
- }
453
- }
454
- }
455
- // If no operators, evaluate as truthy/falsy
456
- return !!parseValue(expr);
457
- }
458
- /**
459
- * Split expression on operator, respecting parentheses
460
- */
461
- function splitOnOperator(expr, op) {
462
- const parts = [];
463
- let depth = 0;
464
- let current = '';
465
- for (let i = 0; i < expr.length; i++) {
466
- const char = expr[i];
467
- if (char === '(')
468
- depth++;
469
- else if (char === ')')
470
- depth--;
471
- if (depth === 0 && expr.slice(i, i + op.length) === op) {
472
- parts.push(current);
473
- current = '';
474
- i += op.length - 1;
475
- }
476
- else {
477
- current += char;
478
- }
479
- }
480
- if (current)
481
- parts.push(current);
482
- return parts;
483
- }
484
- /**
485
- * Parse a value string into its actual type
486
- */
487
- function parseValue(str) {
488
- str = str.trim();
489
- // String literals
490
- if ((str.startsWith('"') && str.endsWith('"')) || (str.startsWith("'") && str.endsWith("'"))) {
491
- return str.slice(1, -1);
492
- }
493
- // Numbers
494
- if (/^-?\d+\.?\d*$/.test(str)) {
495
- return parseFloat(str);
496
- }
497
- // Booleans
498
- if (str === 'true')
499
- return true;
500
- if (str === 'false')
501
- return false;
502
- // Null/undefined
503
- if (str === 'null')
504
- return null;
505
- if (str === 'undefined')
506
- return undefined;
507
- // Already resolved value (from reference resolution)
508
- return str;
509
- }
510
- // ============================================================================
511
- // CUSTOM ERROR CLASS
512
- // ============================================================================
513
- export class ReferenceError extends Error {
514
- constructor(message) {
515
- super(message);
516
- this.name = 'ReferenceError';
517
- }
518
- }