business-as-code 2.1.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/.turbo/turbo-build.log +4 -5
  2. package/CHANGELOG.md +53 -0
  3. package/README.md +2 -0
  4. package/dist/dollar.d.ts.map +1 -1
  5. package/dist/dollar.js +2 -2
  6. package/dist/dollar.js.map +1 -1
  7. package/dist/entities/organization.d.ts +4 -0
  8. package/dist/entities/organization.d.ts.map +1 -1
  9. package/dist/entities/organization.js +27 -18
  10. package/dist/entities/organization.js.map +1 -1
  11. package/dist/entities/planning.d.ts +87 -0
  12. package/dist/finance/account.d.ts +44 -0
  13. package/dist/finance/account.d.ts.map +1 -0
  14. package/dist/finance/account.js +6 -0
  15. package/dist/finance/account.js.map +1 -0
  16. package/dist/finance/authority.d.ts +78 -0
  17. package/dist/finance/authority.d.ts.map +1 -0
  18. package/dist/finance/authority.js +27 -0
  19. package/dist/finance/authority.js.map +1 -0
  20. package/dist/finance/card.d.ts +36 -0
  21. package/dist/finance/card.d.ts.map +1 -0
  22. package/dist/finance/card.js +6 -0
  23. package/dist/finance/card.js.map +1 -0
  24. package/dist/finance/identity.d.ts +30 -0
  25. package/dist/finance/identity.d.ts.map +1 -0
  26. package/dist/finance/identity.js +8 -0
  27. package/dist/finance/identity.js.map +1 -0
  28. package/dist/finance/index.d.ts +36 -0
  29. package/dist/finance/index.d.ts.map +1 -0
  30. package/dist/finance/index.js +22 -0
  31. package/dist/finance/index.js.map +1 -0
  32. package/dist/finance/ledger.d.ts +24 -0
  33. package/dist/finance/ledger.d.ts.map +1 -0
  34. package/dist/finance/ledger.js +8 -0
  35. package/dist/finance/ledger.js.map +1 -0
  36. package/dist/finance/merchant.d.ts +129 -0
  37. package/dist/finance/merchant.d.ts.map +1 -0
  38. package/dist/finance/merchant.js +21 -0
  39. package/dist/finance/merchant.js.map +1 -0
  40. package/dist/finance/outcome-contract.d.ts +139 -0
  41. package/dist/finance/outcome-contract.d.ts.map +1 -0
  42. package/dist/finance/outcome-contract.js +27 -0
  43. package/dist/finance/outcome-contract.js.map +1 -0
  44. package/dist/finance/port.d.ts +121 -0
  45. package/dist/finance/port.d.ts.map +1 -0
  46. package/dist/finance/port.js +10 -0
  47. package/dist/finance/port.js.map +1 -0
  48. package/dist/finance/pricing.d.ts +154 -0
  49. package/dist/finance/pricing.d.ts.map +1 -0
  50. package/dist/finance/pricing.js +79 -0
  51. package/dist/finance/pricing.js.map +1 -0
  52. package/dist/finance/proof-predicate.d.ts +92 -0
  53. package/dist/finance/proof-predicate.d.ts.map +1 -0
  54. package/dist/finance/proof-predicate.js +80 -0
  55. package/dist/finance/proof-predicate.js.map +1 -0
  56. package/dist/finance/refund.d.ts +44 -0
  57. package/dist/finance/refund.d.ts.map +1 -0
  58. package/dist/finance/refund.js +41 -0
  59. package/dist/finance/refund.js.map +1 -0
  60. package/dist/finance/sla.d.ts +25 -0
  61. package/dist/finance/sla.d.ts.map +1 -0
  62. package/dist/finance/sla.js +7 -0
  63. package/dist/finance/sla.js.map +1 -0
  64. package/dist/finance/types.d.ts +79 -0
  65. package/dist/finance/types.d.ts.map +1 -0
  66. package/dist/finance/types.js +8 -0
  67. package/dist/{canvas → finance}/types.js.map +1 -1
  68. package/dist/goals.d.ts +19 -0
  69. package/dist/goals.d.ts.map +1 -1
  70. package/dist/goals.js +81 -12
  71. package/dist/goals.js.map +1 -1
  72. package/dist/index.d.ts +12 -8
  73. package/dist/index.d.ts.map +1 -1
  74. package/dist/index.js +19 -7
  75. package/dist/index.js.map +1 -1
  76. package/dist/kpis.d.ts +19 -0
  77. package/dist/kpis.d.ts.map +1 -1
  78. package/dist/kpis.js +71 -6
  79. package/dist/kpis.js.map +1 -1
  80. package/dist/metrics.d.ts.map +1 -1
  81. package/dist/metrics.js +29 -24
  82. package/dist/metrics.js.map +1 -1
  83. package/dist/okrs.d.ts +34 -0
  84. package/dist/okrs.d.ts.map +1 -1
  85. package/dist/okrs.js +135 -13
  86. package/dist/okrs.js.map +1 -1
  87. package/dist/organization.d.ts.map +1 -1
  88. package/dist/organization.js +11 -11
  89. package/dist/organization.js.map +1 -1
  90. package/dist/process.d.ts.map +1 -1
  91. package/dist/process.js +13 -12
  92. package/dist/process.js.map +1 -1
  93. package/dist/product.d.ts.map +1 -1
  94. package/dist/product.js +9 -9
  95. package/dist/product.js.map +1 -1
  96. package/dist/queries.d.ts.map +1 -1
  97. package/dist/queries.js +194 -32
  98. package/dist/queries.js.map +1 -1
  99. package/dist/roles.d.ts +25 -31
  100. package/dist/roles.d.ts.map +1 -1
  101. package/dist/roles.js +37 -10
  102. package/dist/roles.js.map +1 -1
  103. package/dist/workflow.d.ts.map +1 -1
  104. package/dist/workflow.js +13 -12
  105. package/dist/workflow.js.map +1 -1
  106. package/package.json +20 -13
  107. package/src/dollar.ts +5 -2
  108. package/src/entities/organization.ts +31 -18
  109. package/src/finance/account.ts +48 -0
  110. package/src/finance/authority.ts +42 -0
  111. package/src/finance/card.ts +38 -0
  112. package/src/finance/identity.ts +31 -0
  113. package/src/finance/index.ts +117 -0
  114. package/src/finance/ledger.ts +26 -0
  115. package/src/finance/merchant.ts +127 -0
  116. package/src/finance/outcome-contract.ts +157 -0
  117. package/src/finance/port.ts +144 -0
  118. package/src/finance/pricing.ts +197 -0
  119. package/src/finance/proof-predicate.ts +106 -0
  120. package/src/finance/refund.ts +52 -0
  121. package/src/finance/sla.ts +33 -0
  122. package/src/finance/types.ts +75 -0
  123. package/src/goals.ts +78 -12
  124. package/src/index.ts +48 -18
  125. package/src/kpis.ts +62 -8
  126. package/src/metrics.ts +92 -79
  127. package/src/okrs.ts +120 -20
  128. package/src/organization.ts +12 -15
  129. package/src/process.ts +11 -12
  130. package/src/product.ts +8 -9
  131. package/src/queries.ts +238 -75
  132. package/src/roles.ts +62 -61
  133. package/src/workflow.ts +22 -15
  134. package/test/business.test.ts +282 -0
  135. package/test/dollar.test.ts +270 -0
  136. package/test/entities.test.ts +628 -0
  137. package/test/financials.test.ts +539 -0
  138. package/test/goals.test.ts +451 -0
  139. package/{src → test}/index.test.ts +1 -1
  140. package/test/kpis.test.ts +440 -0
  141. package/test/metrics.test.ts +744 -0
  142. package/test/okrs.test.ts +741 -0
  143. package/test/organization.test.ts +548 -0
  144. package/test/process.test.ts +503 -0
  145. package/test/product.test.ts +430 -0
  146. package/test/queries.test.ts +556 -0
  147. package/test/roles.test.ts +546 -0
  148. package/test/service.test.ts +450 -0
  149. package/test/types.test.ts +1141 -0
  150. package/test/vision.test.ts +214 -0
  151. package/test/workflow.test.ts +501 -0
  152. package/vitest.config.ts +47 -0
  153. package/LICENSE +0 -21
  154. package/dist/canvas/activities.d.ts +0 -19
  155. package/dist/canvas/activities.d.ts.map +0 -1
  156. package/dist/canvas/activities.js +0 -20
  157. package/dist/canvas/activities.js.map +0 -1
  158. package/dist/canvas/channels.d.ts +0 -20
  159. package/dist/canvas/channels.d.ts.map +0 -1
  160. package/dist/canvas/channels.js +0 -21
  161. package/dist/canvas/channels.js.map +0 -1
  162. package/dist/canvas/relationships.d.ts +0 -20
  163. package/dist/canvas/relationships.d.ts.map +0 -1
  164. package/dist/canvas/relationships.js +0 -21
  165. package/dist/canvas/relationships.js.map +0 -1
  166. package/dist/canvas/resources.d.ts +0 -20
  167. package/dist/canvas/resources.d.ts.map +0 -1
  168. package/dist/canvas/resources.js +0 -30
  169. package/dist/canvas/resources.js.map +0 -1
  170. package/dist/canvas/revenue.d.ts +0 -22
  171. package/dist/canvas/revenue.d.ts.map +0 -1
  172. package/dist/canvas/revenue.js +0 -30
  173. package/dist/canvas/revenue.js.map +0 -1
  174. package/dist/canvas/segments.d.ts +0 -20
  175. package/dist/canvas/segments.d.ts.map +0 -1
  176. package/dist/canvas/segments.js +0 -28
  177. package/dist/canvas/segments.js.map +0 -1
  178. package/dist/canvas/types.d.ts +0 -232
  179. package/dist/canvas/types.d.ts.map +0 -1
  180. package/dist/canvas/types.js +0 -8
  181. package/dist/canvas/value.d.ts +0 -20
  182. package/dist/canvas/value.d.ts.map +0 -1
  183. package/dist/canvas/value.js +0 -21
  184. package/dist/canvas/value.js.map +0 -1
  185. package/src/business.js +0 -108
  186. package/src/canvas/activities.ts +0 -32
  187. package/src/canvas/canvas.ts +0 -482
  188. package/src/canvas/channels.ts +0 -34
  189. package/src/canvas/costs.ts +0 -43
  190. package/src/canvas/economics.ts +0 -99
  191. package/src/canvas/index.ts +0 -206
  192. package/src/canvas/partnerships.ts +0 -34
  193. package/src/canvas/projections.ts +0 -141
  194. package/src/canvas/relationships.ts +0 -34
  195. package/src/canvas/resources.ts +0 -43
  196. package/src/canvas/revenue.ts +0 -56
  197. package/src/canvas/segments.ts +0 -42
  198. package/src/canvas/types.ts +0 -363
  199. package/src/canvas/value.ts +0 -34
  200. package/src/dollar.js +0 -106
  201. package/src/entities/assets.js +0 -322
  202. package/src/entities/business.js +0 -369
  203. package/src/entities/communication.js +0 -254
  204. package/src/entities/customers.js +0 -988
  205. package/src/entities/financials.js +0 -931
  206. package/src/entities/goals.js +0 -799
  207. package/src/entities/index.js +0 -197
  208. package/src/entities/legal.js +0 -300
  209. package/src/entities/market.js +0 -300
  210. package/src/entities/marketing.js +0 -1156
  211. package/src/entities/offerings.js +0 -726
  212. package/src/entities/operations.js +0 -786
  213. package/src/entities/organization.js +0 -806
  214. package/src/entities/partnerships.js +0 -299
  215. package/src/entities/planning.js +0 -270
  216. package/src/entities/projects.js +0 -348
  217. package/src/entities/risk.js +0 -292
  218. package/src/entities/sales.js +0 -1247
  219. package/src/financials.js +0 -296
  220. package/src/goals.js +0 -214
  221. package/src/index.js +0 -131
  222. package/src/index.test.js +0 -274
  223. package/src/kpis.js +0 -231
  224. package/src/metrics.js +0 -324
  225. package/src/okrs.js +0 -268
  226. package/src/organization.js +0 -172
  227. package/src/process.js +0 -240
  228. package/src/product.js +0 -144
  229. package/src/queries.js +0 -414
  230. package/src/roles.js +0 -254
  231. package/src/service.js +0 -139
  232. package/src/types.js +0 -4
  233. package/src/vision.js +0 -67
  234. package/src/workflow.js +0 -246
  235. package/tests/canvas.test.ts +0 -842
@@ -0,0 +1,501 @@
1
+ /**
2
+ * Tests for workflow.ts - Workflow definition and automation sequences
3
+ */
4
+
5
+ import { describe, it, expect } from 'vitest'
6
+ import {
7
+ Workflow,
8
+ getActionsInOrder,
9
+ getActionsByType,
10
+ getConditionalActions,
11
+ addAction,
12
+ removeAction,
13
+ updateAction,
14
+ isEventTrigger,
15
+ isScheduleTrigger,
16
+ isWebhookTrigger,
17
+ parseWaitDuration,
18
+ evaluateCondition,
19
+ fillTemplate,
20
+ validateWorkflow,
21
+ } from '../src/workflow.js'
22
+ import type { WorkflowDefinition, WorkflowAction, WorkflowTrigger } from '../src/types.js'
23
+
24
+ describe('Workflow', () => {
25
+ describe('Workflow()', () => {
26
+ it('should create a workflow with required fields', () => {
27
+ const workflow = Workflow({
28
+ name: 'Test Workflow',
29
+ trigger: { type: 'event', event: 'user.created' },
30
+ })
31
+
32
+ expect(workflow.name).toBe('Test Workflow')
33
+ expect(workflow.trigger.type).toBe('event')
34
+ expect(workflow.actions).toEqual([])
35
+ expect(workflow.metadata).toEqual({})
36
+ })
37
+
38
+ it('should create a workflow with all fields', () => {
39
+ const workflow = Workflow({
40
+ name: 'Welcome Flow',
41
+ description: 'Welcomes new users',
42
+ trigger: { type: 'event', event: 'user.created' },
43
+ actions: [
44
+ { order: 1, type: 'send', description: 'Send email' },
45
+ { order: 2, type: 'create', description: 'Create task' },
46
+ ],
47
+ metadata: { version: 1 },
48
+ })
49
+
50
+ expect(workflow.name).toBe('Welcome Flow')
51
+ expect(workflow.description).toBe('Welcomes new users')
52
+ expect(workflow.actions).toHaveLength(2)
53
+ expect(workflow.metadata).toEqual({ version: 1 })
54
+ })
55
+
56
+ it('should throw error if name is missing', () => {
57
+ expect(() =>
58
+ Workflow({
59
+ name: '',
60
+ trigger: { type: 'event' },
61
+ })
62
+ ).toThrow('Workflow name is required')
63
+ })
64
+
65
+ it('should throw error if trigger is missing', () => {
66
+ expect(() =>
67
+ Workflow({
68
+ name: 'Test',
69
+ trigger: undefined as unknown as WorkflowTrigger,
70
+ })
71
+ ).toThrow('Workflow trigger is required')
72
+ })
73
+ })
74
+
75
+ describe('getActionsInOrder()', () => {
76
+ const workflow = Workflow({
77
+ name: 'Test',
78
+ trigger: { type: 'manual' },
79
+ actions: [
80
+ { order: 3, type: 'notify', description: 'Third' },
81
+ { order: 1, type: 'send', description: 'First' },
82
+ { order: 2, type: 'create', description: 'Second' },
83
+ ],
84
+ })
85
+
86
+ it('should return actions sorted by order', () => {
87
+ const sorted = getActionsInOrder(workflow)
88
+
89
+ expect(sorted[0]?.order).toBe(1)
90
+ expect(sorted[0]?.description).toBe('First')
91
+ expect(sorted[1]?.order).toBe(2)
92
+ expect(sorted[2]?.order).toBe(3)
93
+ })
94
+
95
+ it('should handle workflow with no actions', () => {
96
+ const emptyWorkflow = Workflow({
97
+ name: 'Empty',
98
+ trigger: { type: 'manual' },
99
+ })
100
+
101
+ const sorted = getActionsInOrder(emptyWorkflow)
102
+ expect(sorted).toEqual([])
103
+ })
104
+ })
105
+
106
+ describe('getActionsByType()', () => {
107
+ const workflow = Workflow({
108
+ name: 'Test',
109
+ trigger: { type: 'manual' },
110
+ actions: [
111
+ { order: 1, type: 'send', description: 'Send 1' },
112
+ { order: 2, type: 'create', description: 'Create 1' },
113
+ { order: 3, type: 'send', description: 'Send 2' },
114
+ { order: 4, type: 'notify', description: 'Notify 1' },
115
+ ],
116
+ })
117
+
118
+ it('should filter actions by type', () => {
119
+ const sendActions = getActionsByType(workflow, 'send')
120
+
121
+ expect(sendActions).toHaveLength(2)
122
+ expect(sendActions[0]?.description).toBe('Send 1')
123
+ expect(sendActions[1]?.description).toBe('Send 2')
124
+ })
125
+
126
+ it('should return empty array for non-existent type', () => {
127
+ const deleteActions = getActionsByType(workflow, 'delete')
128
+ expect(deleteActions).toHaveLength(0)
129
+ })
130
+ })
131
+
132
+ describe('getConditionalActions()', () => {
133
+ const workflow = Workflow({
134
+ name: 'Test',
135
+ trigger: { type: 'manual' },
136
+ actions: [
137
+ { order: 1, type: 'send', description: 'Always runs' },
138
+ {
139
+ order: 2,
140
+ type: 'notify',
141
+ description: 'Conditional',
142
+ condition: 'user.premium === true',
143
+ },
144
+ {
145
+ order: 3,
146
+ type: 'create',
147
+ description: 'Also conditional',
148
+ condition: 'order.total > 100',
149
+ },
150
+ ],
151
+ })
152
+
153
+ it('should return only conditional actions', () => {
154
+ const conditional = getConditionalActions(workflow)
155
+
156
+ expect(conditional).toHaveLength(2)
157
+ expect(conditional[0]?.description).toBe('Conditional')
158
+ expect(conditional[1]?.description).toBe('Also conditional')
159
+ })
160
+
161
+ it('should return empty array if no conditional actions', () => {
162
+ const simpleWorkflow = Workflow({
163
+ name: 'Simple',
164
+ trigger: { type: 'manual' },
165
+ actions: [{ order: 1, type: 'send', description: 'Always' }],
166
+ })
167
+
168
+ const conditional = getConditionalActions(simpleWorkflow)
169
+ expect(conditional).toHaveLength(0)
170
+ })
171
+ })
172
+
173
+ describe('addAction()', () => {
174
+ it('should add action to workflow', () => {
175
+ const workflow = Workflow({
176
+ name: 'Test',
177
+ trigger: { type: 'manual' },
178
+ actions: [{ order: 1, type: 'send', description: 'First' }],
179
+ })
180
+
181
+ const updated = addAction(workflow, { order: 2, type: 'notify', description: 'Second' })
182
+
183
+ expect(updated.actions).toHaveLength(2)
184
+ expect(updated.actions?.[1]?.order).toBe(2)
185
+ })
186
+
187
+ it('should add action to empty workflow', () => {
188
+ const workflow = Workflow({
189
+ name: 'Test',
190
+ trigger: { type: 'manual' },
191
+ })
192
+
193
+ const updated = addAction(workflow, { order: 1, type: 'send', description: 'First' })
194
+
195
+ expect(updated.actions).toHaveLength(1)
196
+ })
197
+ })
198
+
199
+ describe('removeAction()', () => {
200
+ const workflow = Workflow({
201
+ name: 'Test',
202
+ trigger: { type: 'manual' },
203
+ actions: [
204
+ { order: 1, type: 'send', description: 'First' },
205
+ { order: 2, type: 'create', description: 'Second' },
206
+ { order: 3, type: 'notify', description: 'Third' },
207
+ ],
208
+ })
209
+
210
+ it('should remove action by order', () => {
211
+ const updated = removeAction(workflow, 2)
212
+
213
+ expect(updated.actions).toHaveLength(2)
214
+ expect(updated.actions?.find((a) => a.order === 2)).toBeUndefined()
215
+ })
216
+
217
+ it('should handle removing non-existent action', () => {
218
+ const updated = removeAction(workflow, 99)
219
+ expect(updated.actions).toHaveLength(3)
220
+ })
221
+ })
222
+
223
+ describe('updateAction()', () => {
224
+ const workflow = Workflow({
225
+ name: 'Test',
226
+ trigger: { type: 'manual' },
227
+ actions: [
228
+ { order: 1, type: 'send', description: 'Original' },
229
+ { order: 2, type: 'create', description: 'Second' },
230
+ ],
231
+ })
232
+
233
+ it('should update action properties', () => {
234
+ const updated = updateAction(workflow, 1, { description: 'Updated', type: 'notify' })
235
+
236
+ const action = updated.actions?.find((a) => a.order === 1)
237
+ expect(action?.description).toBe('Updated')
238
+ expect(action?.type).toBe('notify')
239
+ })
240
+
241
+ it('should not affect other actions', () => {
242
+ const updated = updateAction(workflow, 1, { description: 'Updated' })
243
+
244
+ const secondAction = updated.actions?.find((a) => a.order === 2)
245
+ expect(secondAction?.description).toBe('Second')
246
+ })
247
+
248
+ it('should handle updating non-existent action', () => {
249
+ const updated = updateAction(workflow, 99, { description: 'Updated' })
250
+ expect(updated.actions).toHaveLength(2)
251
+ })
252
+ })
253
+
254
+ describe('Trigger type checkers', () => {
255
+ it('isEventTrigger should identify event triggers', () => {
256
+ expect(isEventTrigger({ type: 'event', event: 'user.created' })).toBe(true)
257
+ expect(isEventTrigger({ type: 'schedule' })).toBe(false)
258
+ })
259
+
260
+ it('isScheduleTrigger should identify schedule triggers', () => {
261
+ expect(isScheduleTrigger({ type: 'schedule', schedule: '0 9 * * *' })).toBe(true)
262
+ expect(isScheduleTrigger({ type: 'event' })).toBe(false)
263
+ })
264
+
265
+ it('isWebhookTrigger should identify webhook triggers', () => {
266
+ expect(isWebhookTrigger({ type: 'webhook', webhook: 'https://example.com' })).toBe(true)
267
+ expect(isWebhookTrigger({ type: 'manual' })).toBe(false)
268
+ })
269
+ })
270
+
271
+ describe('parseWaitDuration()', () => {
272
+ it('should parse milliseconds', () => {
273
+ expect(parseWaitDuration('100 ms')).toBe(100)
274
+ expect(parseWaitDuration('500 milliseconds')).toBe(500)
275
+ })
276
+
277
+ it('should parse seconds', () => {
278
+ expect(parseWaitDuration('30 seconds')).toBe(30000)
279
+ expect(parseWaitDuration('1 second')).toBe(1000)
280
+ expect(parseWaitDuration('5 s')).toBe(5000)
281
+ })
282
+
283
+ it('should parse minutes', () => {
284
+ expect(parseWaitDuration('5 minutes')).toBe(300000)
285
+ expect(parseWaitDuration('1 minute')).toBe(60000)
286
+ expect(parseWaitDuration('10 m')).toBe(600000)
287
+ })
288
+
289
+ it('should parse hours', () => {
290
+ expect(parseWaitDuration('2 hours')).toBe(7200000)
291
+ expect(parseWaitDuration('1 hour')).toBe(3600000)
292
+ expect(parseWaitDuration('24 h')).toBe(86400000)
293
+ })
294
+
295
+ it('should parse days', () => {
296
+ expect(parseWaitDuration('1 day')).toBe(86400000)
297
+ expect(parseWaitDuration('7 days')).toBe(604800000)
298
+ expect(parseWaitDuration('2 d')).toBe(172800000)
299
+ })
300
+
301
+ it('should return 0 for invalid format', () => {
302
+ expect(parseWaitDuration('invalid')).toBe(0)
303
+ expect(parseWaitDuration('')).toBe(0)
304
+ expect(parseWaitDuration('minutes')).toBe(0)
305
+ })
306
+ })
307
+
308
+ describe('evaluateCondition()', () => {
309
+ it('should evaluate simple equality', () => {
310
+ expect(evaluateCondition('active === true', { active: true })).toBe(true)
311
+ expect(evaluateCondition('active === false', { active: true })).toBe(false)
312
+ })
313
+
314
+ it('should evaluate comparisons', () => {
315
+ expect(evaluateCondition('amount > 100', { amount: 150 })).toBe(true)
316
+ expect(evaluateCondition('amount > 100', { amount: 50 })).toBe(false)
317
+ expect(evaluateCondition('count >= 5', { count: 5 })).toBe(true)
318
+ })
319
+
320
+ it('should handle missing context variables', () => {
321
+ expect(evaluateCondition('missing === true', {})).toBe(false)
322
+ })
323
+
324
+ it('should evaluate string comparisons', () => {
325
+ expect(evaluateCondition('status === "active"', { status: 'active' })).toBe(true)
326
+ })
327
+
328
+ it('should return false for invalid conditions', () => {
329
+ expect(evaluateCondition('invalid syntax {{}}', {})).toBe(false)
330
+ })
331
+ })
332
+
333
+ describe('fillTemplate()', () => {
334
+ it('should fill simple templates', () => {
335
+ const result = fillTemplate('Hello {{name}}!', { name: 'Alice' })
336
+ expect(result).toBe('Hello Alice!')
337
+ })
338
+
339
+ it('should fill multiple placeholders', () => {
340
+ const result = fillTemplate('{{greeting}} {{name}}, you have {{count}} messages', {
341
+ greeting: 'Hello',
342
+ name: 'Bob',
343
+ count: 5,
344
+ })
345
+ expect(result).toBe('Hello Bob, you have 5 messages')
346
+ })
347
+
348
+ it('should handle nested paths', () => {
349
+ const result = fillTemplate('Welcome {{user.name}}!', {
350
+ user: { name: 'Charlie' },
351
+ })
352
+ expect(result).toBe('Welcome Charlie!')
353
+ })
354
+
355
+ it('should handle deeply nested paths', () => {
356
+ const result = fillTemplate('Order: {{order.customer.name}}', {
357
+ order: { customer: { name: 'Acme Corp' } },
358
+ })
359
+ expect(result).toBe('Order: Acme Corp')
360
+ })
361
+
362
+ it('should replace missing values with empty string', () => {
363
+ const result = fillTemplate('Hello {{missing}}!', {})
364
+ expect(result).toBe('Hello !')
365
+ })
366
+
367
+ it('should handle template with no placeholders', () => {
368
+ const result = fillTemplate('No placeholders here', { value: 'test' })
369
+ expect(result).toBe('No placeholders here')
370
+ })
371
+
372
+ it('should handle whitespace in placeholders', () => {
373
+ const result = fillTemplate('Hello {{ name }}!', { name: 'Alice' })
374
+ expect(result).toBe('Hello Alice!')
375
+ })
376
+ })
377
+
378
+ describe('validateWorkflow()', () => {
379
+ it('should validate valid workflow', () => {
380
+ const workflow: WorkflowDefinition = {
381
+ name: 'Valid Workflow',
382
+ trigger: { type: 'event', event: 'user.created' },
383
+ actions: [
384
+ { order: 1, type: 'send', description: 'Send email' },
385
+ { order: 2, type: 'notify', description: 'Notify admin' },
386
+ ],
387
+ }
388
+
389
+ const result = validateWorkflow(workflow)
390
+ expect(result.valid).toBe(true)
391
+ expect(result.errors).toHaveLength(0)
392
+ })
393
+
394
+ it('should fail if name is missing', () => {
395
+ const workflow: WorkflowDefinition = {
396
+ name: '',
397
+ trigger: { type: 'event' },
398
+ }
399
+
400
+ const result = validateWorkflow(workflow)
401
+ expect(result.valid).toBe(false)
402
+ expect(result.errors).toContain('Workflow name is required')
403
+ })
404
+
405
+ it('should fail if trigger is missing', () => {
406
+ const workflow = {
407
+ name: 'Test',
408
+ trigger: undefined,
409
+ } as unknown as WorkflowDefinition
410
+
411
+ const result = validateWorkflow(workflow)
412
+ expect(result.valid).toBe(false)
413
+ expect(result.errors).toContain('Workflow trigger is required')
414
+ })
415
+
416
+ it('should fail if event trigger has no event', () => {
417
+ const workflow: WorkflowDefinition = {
418
+ name: 'Test',
419
+ trigger: { type: 'event' },
420
+ }
421
+
422
+ const result = validateWorkflow(workflow)
423
+ expect(result.valid).toBe(false)
424
+ expect(result.errors).toContain('Event trigger must specify an event name')
425
+ })
426
+
427
+ it('should fail if schedule trigger has no schedule', () => {
428
+ const workflow: WorkflowDefinition = {
429
+ name: 'Test',
430
+ trigger: { type: 'schedule' },
431
+ }
432
+
433
+ const result = validateWorkflow(workflow)
434
+ expect(result.valid).toBe(false)
435
+ expect(result.errors).toContain('Schedule trigger must specify a schedule expression')
436
+ })
437
+
438
+ it('should fail if webhook trigger has no webhook URL', () => {
439
+ const workflow: WorkflowDefinition = {
440
+ name: 'Test',
441
+ trigger: { type: 'webhook' },
442
+ }
443
+
444
+ const result = validateWorkflow(workflow)
445
+ expect(result.valid).toBe(false)
446
+ expect(result.errors).toContain('Webhook trigger must specify a webhook URL')
447
+ })
448
+
449
+ it('should fail if action has no type', () => {
450
+ const workflow: WorkflowDefinition = {
451
+ name: 'Test',
452
+ trigger: { type: 'manual' },
453
+ actions: [{ order: 1, type: '' as WorkflowAction['type'], description: 'No type' }],
454
+ }
455
+
456
+ const result = validateWorkflow(workflow)
457
+ expect(result.valid).toBe(false)
458
+ expect(result.errors).toContain('Action at order 1 must have a type')
459
+ })
460
+
461
+ it('should fail for duplicate action orders', () => {
462
+ const workflow: WorkflowDefinition = {
463
+ name: 'Test',
464
+ trigger: { type: 'manual' },
465
+ actions: [
466
+ { order: 1, type: 'send', description: 'First' },
467
+ { order: 1, type: 'notify', description: 'Duplicate' },
468
+ ],
469
+ }
470
+
471
+ const result = validateWorkflow(workflow)
472
+ expect(result.valid).toBe(false)
473
+ expect(result.errors).toContain('Duplicate action order: 1')
474
+ })
475
+
476
+ it('should fail if wait action has no duration', () => {
477
+ const workflow: WorkflowDefinition = {
478
+ name: 'Test',
479
+ trigger: { type: 'manual' },
480
+ actions: [{ order: 1, type: 'wait', description: 'Wait without duration' }],
481
+ }
482
+
483
+ const result = validateWorkflow(workflow)
484
+ expect(result.valid).toBe(false)
485
+ expect(result.errors).toContain('Wait action at order 1 must specify duration')
486
+ })
487
+
488
+ it('should pass for wait action with duration', () => {
489
+ const workflow: WorkflowDefinition = {
490
+ name: 'Test',
491
+ trigger: { type: 'manual' },
492
+ actions: [
493
+ { order: 1, type: 'wait', description: 'Wait', params: { duration: '5 minutes' } },
494
+ ],
495
+ }
496
+
497
+ const result = validateWorkflow(workflow)
498
+ expect(result.valid).toBe(true)
499
+ })
500
+ })
501
+ })
@@ -0,0 +1,47 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ // CRITICAL: Limit concurrency to prevent resource exhaustion
6
+ maxConcurrency: 1,
7
+ maxWorkers: 1,
8
+ minWorkers: 1,
9
+ fileParallelism: false,
10
+
11
+ globals: false,
12
+ environment: 'node',
13
+ include: ['src/**/*.test.ts', 'test/**/*.test.ts'],
14
+ exclude: ['node_modules/**', 'dist/**'],
15
+ testTimeout: 30000,
16
+ hookTimeout: 15000,
17
+
18
+ // Run tests sequentially with better memory isolation
19
+ pool: 'forks',
20
+ poolOptions: {
21
+ forks: {
22
+ singleFork: true,
23
+ },
24
+ },
25
+
26
+ // Server deps configuration for node compatibility
27
+ server: {
28
+ deps: {
29
+ inline: [/org\.ai/, /digital-workers/, /ai-database/, /ai-functions/],
30
+ },
31
+ },
32
+
33
+ // Coverage configuration
34
+ coverage: {
35
+ provider: 'v8',
36
+ reporter: ['text', 'json', 'html'],
37
+ include: ['src/**/*.ts'],
38
+ exclude: ['**/*.test.ts', '**/__tests__/**', '**/node_modules/**'],
39
+ thresholds: {
40
+ statements: 65,
41
+ branches: 60,
42
+ functions: 60,
43
+ lines: 65,
44
+ },
45
+ },
46
+ },
47
+ })
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 .org.ai
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,19 +0,0 @@
1
- /**
2
- * Key Activities
3
- *
4
- * Functions for creating and working with key activities.
5
- */
6
- import type { KeyActivity, ActivityCategory } from './types.js';
7
- export interface CreateKeyActivityInput {
8
- name: string;
9
- category: ActivityCategory;
10
- description?: string;
11
- resources?: string[];
12
- metrics?: string[];
13
- uptime?: number;
14
- }
15
- /**
16
- * Create a key activity
17
- */
18
- export declare function createKeyActivity(input: CreateKeyActivityInput): KeyActivity;
19
- //# sourceMappingURL=activities.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/canvas/activities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE/D,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,WAAW,CAW5E"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Key Activities
3
- *
4
- * Functions for creating and working with key activities.
5
- */
6
- /**
7
- * Create a key activity
8
- */
9
- export function createKeyActivity(input) {
10
- const { name, category, description, resources, metrics, uptime } = input;
11
- return {
12
- name,
13
- category,
14
- description,
15
- resources,
16
- metrics,
17
- uptime,
18
- };
19
- }
20
- //# sourceMappingURL=activities.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"activities.js","sourceRoot":"","sources":["../../src/canvas/activities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,KAAK,CAAA;IAEzE,OAAO;QACL,IAAI;QACJ,QAAQ;QACR,WAAW;QACX,SAAS;QACT,OAAO;QACP,MAAM;KACP,CAAA;AACH,CAAC"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Channels
3
- *
4
- * Functions for creating and working with channels.
5
- */
6
- import type { Channel, ChannelType, ChannelPhase } from './types.js';
7
- export interface CreateChannelInput {
8
- name: string;
9
- type: ChannelType;
10
- phases?: ChannelPhase[];
11
- costPerAcquisition?: number;
12
- partnerType?: string;
13
- revenueShare?: number;
14
- conversionRate?: number;
15
- }
16
- /**
17
- * Create a channel
18
- */
19
- export declare function createChannel(input: CreateChannelInput): Channel;
20
- //# sourceMappingURL=channels.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"channels.d.ts","sourceRoot":"","sources":["../../src/canvas/channels.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEpE,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,CAAA;IACjB,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;IACvB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAYhE"}
@@ -1,21 +0,0 @@
1
- /**
2
- * Channels
3
- *
4
- * Functions for creating and working with channels.
5
- */
6
- /**
7
- * Create a channel
8
- */
9
- export function createChannel(input) {
10
- const { name, type, phases, costPerAcquisition, partnerType, revenueShare, conversionRate } = input;
11
- return {
12
- name,
13
- type,
14
- phases,
15
- costPerAcquisition,
16
- partnerType,
17
- revenueShare,
18
- conversionRate,
19
- };
20
- }
21
- //# sourceMappingURL=channels.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"channels.js","sourceRoot":"","sources":["../../src/canvas/channels.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,KAAK,CAAA;IAEnG,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,kBAAkB;QAClB,WAAW;QACX,YAAY;QACZ,cAAc;KACf,CAAA;AACH,CAAC"}
@@ -1,20 +0,0 @@
1
- /**
2
- * Customer Relationships
3
- *
4
- * Functions for creating and working with customer relationships.
5
- */
6
- import type { CustomerRelationship, RelationshipType } from './types.js';
7
- export interface CreateCustomerRelationshipInput {
8
- name: string;
9
- type: RelationshipType;
10
- segment?: string;
11
- touchFrequency?: string;
12
- automationLevel?: number;
13
- supportChannels?: string[];
14
- platforms?: string[];
15
- }
16
- /**
17
- * Create a customer relationship
18
- */
19
- export declare function createCustomerRelationship(input: CreateCustomerRelationshipInput): CustomerRelationship;
20
- //# sourceMappingURL=relationships.d.ts.map