business-as-code 2.1.3 → 2.3.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 (260) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +2 -0
  3. package/package.json +16 -13
  4. package/src/dollar.ts +5 -2
  5. package/src/entities/organization.ts +31 -18
  6. package/src/goals.ts +78 -12
  7. package/src/index.ts +48 -18
  8. package/src/kpis.ts +62 -8
  9. package/src/metrics.ts +92 -79
  10. package/src/okrs.ts +120 -20
  11. package/src/organization.ts +12 -15
  12. package/src/process.ts +11 -12
  13. package/src/product.ts +8 -9
  14. package/src/queries.ts +238 -75
  15. package/src/roles.ts +62 -61
  16. package/src/workflow.ts +22 -15
  17. package/test/business.test.ts +282 -0
  18. package/test/dollar.test.ts +270 -0
  19. package/test/entities.test.ts +628 -0
  20. package/test/financials.test.ts +539 -0
  21. package/test/goals.test.ts +451 -0
  22. package/{src → test}/index.test.ts +1 -1
  23. package/test/kpis.test.ts +440 -0
  24. package/test/metrics.test.ts +744 -0
  25. package/test/okrs.test.ts +741 -0
  26. package/test/organization.test.ts +548 -0
  27. package/test/process.test.ts +503 -0
  28. package/test/product.test.ts +430 -0
  29. package/test/queries.test.ts +556 -0
  30. package/test/roles.test.ts +546 -0
  31. package/test/service.test.ts +450 -0
  32. package/test/types.test.ts +1141 -0
  33. package/test/vision.test.ts +214 -0
  34. package/test/workflow.test.ts +501 -0
  35. package/vitest.config.ts +47 -0
  36. package/.turbo/turbo-build.log +0 -5
  37. package/LICENSE +0 -21
  38. package/dist/business.d.ts +0 -62
  39. package/dist/business.d.ts.map +0 -1
  40. package/dist/business.js +0 -109
  41. package/dist/business.js.map +0 -1
  42. package/dist/canvas/activities.d.ts +0 -19
  43. package/dist/canvas/activities.d.ts.map +0 -1
  44. package/dist/canvas/activities.js +0 -20
  45. package/dist/canvas/activities.js.map +0 -1
  46. package/dist/canvas/channels.d.ts +0 -20
  47. package/dist/canvas/channels.d.ts.map +0 -1
  48. package/dist/canvas/channels.js +0 -21
  49. package/dist/canvas/channels.js.map +0 -1
  50. package/dist/canvas/relationships.d.ts +0 -20
  51. package/dist/canvas/relationships.d.ts.map +0 -1
  52. package/dist/canvas/relationships.js +0 -21
  53. package/dist/canvas/relationships.js.map +0 -1
  54. package/dist/canvas/resources.d.ts +0 -20
  55. package/dist/canvas/resources.d.ts.map +0 -1
  56. package/dist/canvas/resources.js +0 -30
  57. package/dist/canvas/resources.js.map +0 -1
  58. package/dist/canvas/revenue.d.ts +0 -22
  59. package/dist/canvas/revenue.d.ts.map +0 -1
  60. package/dist/canvas/revenue.js +0 -30
  61. package/dist/canvas/revenue.js.map +0 -1
  62. package/dist/canvas/segments.d.ts +0 -20
  63. package/dist/canvas/segments.d.ts.map +0 -1
  64. package/dist/canvas/segments.js +0 -28
  65. package/dist/canvas/segments.js.map +0 -1
  66. package/dist/canvas/types.d.ts +0 -232
  67. package/dist/canvas/types.d.ts.map +0 -1
  68. package/dist/canvas/types.js +0 -8
  69. package/dist/canvas/types.js.map +0 -1
  70. package/dist/canvas/value.d.ts +0 -20
  71. package/dist/canvas/value.d.ts.map +0 -1
  72. package/dist/canvas/value.js +0 -21
  73. package/dist/canvas/value.js.map +0 -1
  74. package/dist/dollar.d.ts +0 -60
  75. package/dist/dollar.d.ts.map +0 -1
  76. package/dist/dollar.js +0 -107
  77. package/dist/dollar.js.map +0 -1
  78. package/dist/entities/assets.d.ts +0 -21
  79. package/dist/entities/assets.d.ts.map +0 -1
  80. package/dist/entities/assets.js +0 -323
  81. package/dist/entities/assets.js.map +0 -1
  82. package/dist/entities/business.d.ts +0 -36
  83. package/dist/entities/business.d.ts.map +0 -1
  84. package/dist/entities/business.js +0 -370
  85. package/dist/entities/business.js.map +0 -1
  86. package/dist/entities/communication.d.ts +0 -21
  87. package/dist/entities/communication.d.ts.map +0 -1
  88. package/dist/entities/communication.js +0 -255
  89. package/dist/entities/communication.js.map +0 -1
  90. package/dist/entities/customers.d.ts +0 -58
  91. package/dist/entities/customers.d.ts.map +0 -1
  92. package/dist/entities/customers.js +0 -989
  93. package/dist/entities/customers.js.map +0 -1
  94. package/dist/entities/financials.d.ts +0 -59
  95. package/dist/entities/financials.d.ts.map +0 -1
  96. package/dist/entities/financials.js +0 -932
  97. package/dist/entities/financials.js.map +0 -1
  98. package/dist/entities/goals.d.ts +0 -58
  99. package/dist/entities/goals.d.ts.map +0 -1
  100. package/dist/entities/goals.js +0 -800
  101. package/dist/entities/goals.js.map +0 -1
  102. package/dist/entities/index.d.ts +0 -299
  103. package/dist/entities/index.d.ts.map +0 -1
  104. package/dist/entities/index.js +0 -198
  105. package/dist/entities/index.js.map +0 -1
  106. package/dist/entities/legal.d.ts +0 -21
  107. package/dist/entities/legal.d.ts.map +0 -1
  108. package/dist/entities/legal.js +0 -301
  109. package/dist/entities/legal.js.map +0 -1
  110. package/dist/entities/market.d.ts +0 -21
  111. package/dist/entities/market.d.ts.map +0 -1
  112. package/dist/entities/market.js +0 -301
  113. package/dist/entities/market.js.map +0 -1
  114. package/dist/entities/marketing.d.ts +0 -67
  115. package/dist/entities/marketing.d.ts.map +0 -1
  116. package/dist/entities/marketing.js +0 -1157
  117. package/dist/entities/marketing.js.map +0 -1
  118. package/dist/entities/offerings.d.ts +0 -51
  119. package/dist/entities/offerings.d.ts.map +0 -1
  120. package/dist/entities/offerings.js +0 -727
  121. package/dist/entities/offerings.js.map +0 -1
  122. package/dist/entities/operations.d.ts +0 -58
  123. package/dist/entities/operations.d.ts.map +0 -1
  124. package/dist/entities/operations.js +0 -787
  125. package/dist/entities/operations.js.map +0 -1
  126. package/dist/entities/organization.d.ts +0 -57
  127. package/dist/entities/organization.d.ts.map +0 -1
  128. package/dist/entities/organization.js +0 -807
  129. package/dist/entities/organization.js.map +0 -1
  130. package/dist/entities/partnerships.d.ts +0 -21
  131. package/dist/entities/partnerships.d.ts.map +0 -1
  132. package/dist/entities/partnerships.js +0 -300
  133. package/dist/entities/partnerships.js.map +0 -1
  134. package/dist/entities/planning.d.ts +0 -0
  135. package/dist/entities/planning.d.ts.map +0 -1
  136. package/dist/entities/planning.js +0 -271
  137. package/dist/entities/planning.js.map +0 -1
  138. package/dist/entities/projects.d.ts +0 -25
  139. package/dist/entities/projects.d.ts.map +0 -1
  140. package/dist/entities/projects.js +0 -349
  141. package/dist/entities/projects.js.map +0 -1
  142. package/dist/entities/risk.d.ts +0 -21
  143. package/dist/entities/risk.d.ts.map +0 -1
  144. package/dist/entities/risk.js +0 -293
  145. package/dist/entities/risk.js.map +0 -1
  146. package/dist/entities/sales.d.ts +0 -72
  147. package/dist/entities/sales.d.ts.map +0 -1
  148. package/dist/entities/sales.js +0 -1248
  149. package/dist/entities/sales.js.map +0 -1
  150. package/dist/financials.d.ts +0 -130
  151. package/dist/financials.d.ts.map +0 -1
  152. package/dist/financials.js +0 -297
  153. package/dist/financials.js.map +0 -1
  154. package/dist/goals.d.ts +0 -87
  155. package/dist/goals.d.ts.map +0 -1
  156. package/dist/goals.js +0 -215
  157. package/dist/goals.js.map +0 -1
  158. package/dist/index.d.ts +0 -97
  159. package/dist/index.d.ts.map +0 -1
  160. package/dist/index.js +0 -132
  161. package/dist/index.js.map +0 -1
  162. package/dist/kpis.d.ts +0 -118
  163. package/dist/kpis.d.ts.map +0 -1
  164. package/dist/kpis.js +0 -232
  165. package/dist/kpis.js.map +0 -1
  166. package/dist/metrics.d.ts +0 -448
  167. package/dist/metrics.d.ts.map +0 -1
  168. package/dist/metrics.js +0 -325
  169. package/dist/metrics.js.map +0 -1
  170. package/dist/okrs.d.ts +0 -123
  171. package/dist/okrs.d.ts.map +0 -1
  172. package/dist/okrs.js +0 -269
  173. package/dist/okrs.js.map +0 -1
  174. package/dist/organization.d.ts +0 -585
  175. package/dist/organization.d.ts.map +0 -1
  176. package/dist/organization.js +0 -173
  177. package/dist/organization.js.map +0 -1
  178. package/dist/process.d.ts +0 -112
  179. package/dist/process.d.ts.map +0 -1
  180. package/dist/process.js +0 -241
  181. package/dist/process.js.map +0 -1
  182. package/dist/product.d.ts +0 -85
  183. package/dist/product.d.ts.map +0 -1
  184. package/dist/product.js +0 -145
  185. package/dist/product.js.map +0 -1
  186. package/dist/queries.d.ts +0 -304
  187. package/dist/queries.d.ts.map +0 -1
  188. package/dist/queries.js +0 -415
  189. package/dist/queries.js.map +0 -1
  190. package/dist/roles.d.ts +0 -340
  191. package/dist/roles.d.ts.map +0 -1
  192. package/dist/roles.js +0 -255
  193. package/dist/roles.js.map +0 -1
  194. package/dist/service.d.ts +0 -61
  195. package/dist/service.d.ts.map +0 -1
  196. package/dist/service.js +0 -140
  197. package/dist/service.js.map +0 -1
  198. package/dist/types.d.ts +0 -459
  199. package/dist/types.d.ts.map +0 -1
  200. package/dist/types.js +0 -5
  201. package/dist/types.js.map +0 -1
  202. package/dist/vision.d.ts +0 -38
  203. package/dist/vision.d.ts.map +0 -1
  204. package/dist/vision.js +0 -68
  205. package/dist/vision.js.map +0 -1
  206. package/dist/workflow.d.ts +0 -115
  207. package/dist/workflow.d.ts.map +0 -1
  208. package/dist/workflow.js +0 -247
  209. package/dist/workflow.js.map +0 -1
  210. package/src/business.js +0 -108
  211. package/src/canvas/activities.ts +0 -32
  212. package/src/canvas/canvas.ts +0 -482
  213. package/src/canvas/channels.ts +0 -34
  214. package/src/canvas/costs.ts +0 -43
  215. package/src/canvas/economics.ts +0 -99
  216. package/src/canvas/index.ts +0 -206
  217. package/src/canvas/partnerships.ts +0 -34
  218. package/src/canvas/projections.ts +0 -141
  219. package/src/canvas/relationships.ts +0 -34
  220. package/src/canvas/resources.ts +0 -43
  221. package/src/canvas/revenue.ts +0 -56
  222. package/src/canvas/segments.ts +0 -42
  223. package/src/canvas/types.ts +0 -363
  224. package/src/canvas/value.ts +0 -34
  225. package/src/dollar.js +0 -106
  226. package/src/entities/assets.js +0 -322
  227. package/src/entities/business.js +0 -369
  228. package/src/entities/communication.js +0 -254
  229. package/src/entities/customers.js +0 -988
  230. package/src/entities/financials.js +0 -931
  231. package/src/entities/goals.js +0 -799
  232. package/src/entities/index.js +0 -197
  233. package/src/entities/legal.js +0 -300
  234. package/src/entities/market.js +0 -300
  235. package/src/entities/marketing.js +0 -1156
  236. package/src/entities/offerings.js +0 -726
  237. package/src/entities/operations.js +0 -786
  238. package/src/entities/organization.js +0 -806
  239. package/src/entities/partnerships.js +0 -299
  240. package/src/entities/planning.js +0 -270
  241. package/src/entities/projects.js +0 -348
  242. package/src/entities/risk.js +0 -292
  243. package/src/entities/sales.js +0 -1247
  244. package/src/financials.js +0 -296
  245. package/src/goals.js +0 -214
  246. package/src/index.js +0 -131
  247. package/src/index.test.js +0 -274
  248. package/src/kpis.js +0 -231
  249. package/src/metrics.js +0 -324
  250. package/src/okrs.js +0 -268
  251. package/src/organization.js +0 -172
  252. package/src/process.js +0 -240
  253. package/src/product.js +0 -144
  254. package/src/queries.js +0 -414
  255. package/src/roles.js +0 -254
  256. package/src/service.js +0 -139
  257. package/src/types.js +0 -4
  258. package/src/vision.js +0 -67
  259. package/src/workflow.js +0 -246
  260. 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
+ })
@@ -1,5 +0,0 @@
1
-
2
- 
3
- > business-as-code@2.1.3 build /Users/nathanclevenger/projects/primitives.org.ai/packages/business-as-code
4
- > tsc
5
-
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,62 +0,0 @@
1
- /**
2
- * Business entity definition
3
- */
4
- import type { BusinessDefinition } from './types.js';
5
- /**
6
- * Define a business entity with organizational structure, mission, and values
7
- *
8
- * @example
9
- * ```ts
10
- * const acme = Business({
11
- * name: 'Acme Corp',
12
- * description: 'Building the future of widgets',
13
- * industry: 'Technology',
14
- * mission: 'To make widgets accessible to everyone',
15
- * values: ['Innovation', 'Customer Focus', 'Integrity'],
16
- * targetMarket: 'SMB and Enterprise',
17
- * foundedAt: new Date('2020-01-01'),
18
- * teamSize: 50,
19
- * structure: {
20
- * departments: [
21
- * {
22
- * name: 'Engineering',
23
- * head: 'Jane Smith',
24
- * members: ['Alice', 'Bob', 'Charlie'],
25
- * budget: 2000000,
26
- * },
27
- * {
28
- * name: 'Sales',
29
- * head: 'John Doe',
30
- * members: ['David', 'Eve'],
31
- * budget: 1000000,
32
- * },
33
- * ],
34
- * },
35
- * })
36
- * ```
37
- */
38
- export declare function Business(definition: BusinessDefinition): BusinessDefinition;
39
- /**
40
- * Get total budget across all departments
41
- */
42
- export declare function getTotalBudget(business: BusinessDefinition): number;
43
- /**
44
- * Get total team size across all departments
45
- */
46
- export declare function getTotalTeamSize(business: BusinessDefinition): number;
47
- /**
48
- * Get department by name
49
- */
50
- export declare function getDepartment(business: BusinessDefinition, name: string): import("./types.js").Department | undefined;
51
- /**
52
- * Get team by name
53
- */
54
- export declare function getTeam(business: BusinessDefinition, name: string): import("./types.js").Team | undefined;
55
- /**
56
- * Validate business definition
57
- */
58
- export declare function validateBusiness(business: BusinessDefinition): {
59
- valid: boolean;
60
- errors: string[];
61
- };
62
- //# sourceMappingURL=business.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"business.d.ts","sourceRoot":"","sources":["../src/business.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,kBAAkB,GAAG,kBAAkB,CAc3E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAMnE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAMrE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,+CAEvE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,yCAEjE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA0BnG"}