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.
- package/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/package.json +16 -13
- package/src/dollar.ts +5 -2
- package/src/entities/organization.ts +31 -18
- package/src/goals.ts +78 -12
- package/src/index.ts +48 -18
- package/src/kpis.ts +62 -8
- package/src/metrics.ts +92 -79
- package/src/okrs.ts +120 -20
- package/src/organization.ts +12 -15
- package/src/process.ts +11 -12
- package/src/product.ts +8 -9
- package/src/queries.ts +238 -75
- package/src/roles.ts +62 -61
- package/src/workflow.ts +22 -15
- package/test/business.test.ts +282 -0
- package/test/dollar.test.ts +270 -0
- package/test/entities.test.ts +628 -0
- package/test/financials.test.ts +539 -0
- package/test/goals.test.ts +451 -0
- package/{src → test}/index.test.ts +1 -1
- package/test/kpis.test.ts +440 -0
- package/test/metrics.test.ts +744 -0
- package/test/okrs.test.ts +741 -0
- package/test/organization.test.ts +548 -0
- package/test/process.test.ts +503 -0
- package/test/product.test.ts +430 -0
- package/test/queries.test.ts +556 -0
- package/test/roles.test.ts +546 -0
- package/test/service.test.ts +450 -0
- package/test/types.test.ts +1141 -0
- package/test/vision.test.ts +214 -0
- package/test/workflow.test.ts +501 -0
- package/vitest.config.ts +47 -0
- package/.turbo/turbo-build.log +0 -5
- package/LICENSE +0 -21
- package/dist/business.d.ts +0 -62
- package/dist/business.d.ts.map +0 -1
- package/dist/business.js +0 -109
- package/dist/business.js.map +0 -1
- package/dist/canvas/activities.d.ts +0 -19
- package/dist/canvas/activities.d.ts.map +0 -1
- package/dist/canvas/activities.js +0 -20
- package/dist/canvas/activities.js.map +0 -1
- package/dist/canvas/channels.d.ts +0 -20
- package/dist/canvas/channels.d.ts.map +0 -1
- package/dist/canvas/channels.js +0 -21
- package/dist/canvas/channels.js.map +0 -1
- package/dist/canvas/relationships.d.ts +0 -20
- package/dist/canvas/relationships.d.ts.map +0 -1
- package/dist/canvas/relationships.js +0 -21
- package/dist/canvas/relationships.js.map +0 -1
- package/dist/canvas/resources.d.ts +0 -20
- package/dist/canvas/resources.d.ts.map +0 -1
- package/dist/canvas/resources.js +0 -30
- package/dist/canvas/resources.js.map +0 -1
- package/dist/canvas/revenue.d.ts +0 -22
- package/dist/canvas/revenue.d.ts.map +0 -1
- package/dist/canvas/revenue.js +0 -30
- package/dist/canvas/revenue.js.map +0 -1
- package/dist/canvas/segments.d.ts +0 -20
- package/dist/canvas/segments.d.ts.map +0 -1
- package/dist/canvas/segments.js +0 -28
- package/dist/canvas/segments.js.map +0 -1
- package/dist/canvas/types.d.ts +0 -232
- package/dist/canvas/types.d.ts.map +0 -1
- package/dist/canvas/types.js +0 -8
- package/dist/canvas/types.js.map +0 -1
- package/dist/canvas/value.d.ts +0 -20
- package/dist/canvas/value.d.ts.map +0 -1
- package/dist/canvas/value.js +0 -21
- package/dist/canvas/value.js.map +0 -1
- package/dist/dollar.d.ts +0 -60
- package/dist/dollar.d.ts.map +0 -1
- package/dist/dollar.js +0 -107
- package/dist/dollar.js.map +0 -1
- package/dist/entities/assets.d.ts +0 -21
- package/dist/entities/assets.d.ts.map +0 -1
- package/dist/entities/assets.js +0 -323
- package/dist/entities/assets.js.map +0 -1
- package/dist/entities/business.d.ts +0 -36
- package/dist/entities/business.d.ts.map +0 -1
- package/dist/entities/business.js +0 -370
- package/dist/entities/business.js.map +0 -1
- package/dist/entities/communication.d.ts +0 -21
- package/dist/entities/communication.d.ts.map +0 -1
- package/dist/entities/communication.js +0 -255
- package/dist/entities/communication.js.map +0 -1
- package/dist/entities/customers.d.ts +0 -58
- package/dist/entities/customers.d.ts.map +0 -1
- package/dist/entities/customers.js +0 -989
- package/dist/entities/customers.js.map +0 -1
- package/dist/entities/financials.d.ts +0 -59
- package/dist/entities/financials.d.ts.map +0 -1
- package/dist/entities/financials.js +0 -932
- package/dist/entities/financials.js.map +0 -1
- package/dist/entities/goals.d.ts +0 -58
- package/dist/entities/goals.d.ts.map +0 -1
- package/dist/entities/goals.js +0 -800
- package/dist/entities/goals.js.map +0 -1
- package/dist/entities/index.d.ts +0 -299
- package/dist/entities/index.d.ts.map +0 -1
- package/dist/entities/index.js +0 -198
- package/dist/entities/index.js.map +0 -1
- package/dist/entities/legal.d.ts +0 -21
- package/dist/entities/legal.d.ts.map +0 -1
- package/dist/entities/legal.js +0 -301
- package/dist/entities/legal.js.map +0 -1
- package/dist/entities/market.d.ts +0 -21
- package/dist/entities/market.d.ts.map +0 -1
- package/dist/entities/market.js +0 -301
- package/dist/entities/market.js.map +0 -1
- package/dist/entities/marketing.d.ts +0 -67
- package/dist/entities/marketing.d.ts.map +0 -1
- package/dist/entities/marketing.js +0 -1157
- package/dist/entities/marketing.js.map +0 -1
- package/dist/entities/offerings.d.ts +0 -51
- package/dist/entities/offerings.d.ts.map +0 -1
- package/dist/entities/offerings.js +0 -727
- package/dist/entities/offerings.js.map +0 -1
- package/dist/entities/operations.d.ts +0 -58
- package/dist/entities/operations.d.ts.map +0 -1
- package/dist/entities/operations.js +0 -787
- package/dist/entities/operations.js.map +0 -1
- package/dist/entities/organization.d.ts +0 -57
- package/dist/entities/organization.d.ts.map +0 -1
- package/dist/entities/organization.js +0 -807
- package/dist/entities/organization.js.map +0 -1
- package/dist/entities/partnerships.d.ts +0 -21
- package/dist/entities/partnerships.d.ts.map +0 -1
- package/dist/entities/partnerships.js +0 -300
- package/dist/entities/partnerships.js.map +0 -1
- package/dist/entities/planning.d.ts +0 -0
- package/dist/entities/planning.d.ts.map +0 -1
- package/dist/entities/planning.js +0 -271
- package/dist/entities/planning.js.map +0 -1
- package/dist/entities/projects.d.ts +0 -25
- package/dist/entities/projects.d.ts.map +0 -1
- package/dist/entities/projects.js +0 -349
- package/dist/entities/projects.js.map +0 -1
- package/dist/entities/risk.d.ts +0 -21
- package/dist/entities/risk.d.ts.map +0 -1
- package/dist/entities/risk.js +0 -293
- package/dist/entities/risk.js.map +0 -1
- package/dist/entities/sales.d.ts +0 -72
- package/dist/entities/sales.d.ts.map +0 -1
- package/dist/entities/sales.js +0 -1248
- package/dist/entities/sales.js.map +0 -1
- package/dist/financials.d.ts +0 -130
- package/dist/financials.d.ts.map +0 -1
- package/dist/financials.js +0 -297
- package/dist/financials.js.map +0 -1
- package/dist/goals.d.ts +0 -87
- package/dist/goals.d.ts.map +0 -1
- package/dist/goals.js +0 -215
- package/dist/goals.js.map +0 -1
- package/dist/index.d.ts +0 -97
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -132
- package/dist/index.js.map +0 -1
- package/dist/kpis.d.ts +0 -118
- package/dist/kpis.d.ts.map +0 -1
- package/dist/kpis.js +0 -232
- package/dist/kpis.js.map +0 -1
- package/dist/metrics.d.ts +0 -448
- package/dist/metrics.d.ts.map +0 -1
- package/dist/metrics.js +0 -325
- package/dist/metrics.js.map +0 -1
- package/dist/okrs.d.ts +0 -123
- package/dist/okrs.d.ts.map +0 -1
- package/dist/okrs.js +0 -269
- package/dist/okrs.js.map +0 -1
- package/dist/organization.d.ts +0 -585
- package/dist/organization.d.ts.map +0 -1
- package/dist/organization.js +0 -173
- package/dist/organization.js.map +0 -1
- package/dist/process.d.ts +0 -112
- package/dist/process.d.ts.map +0 -1
- package/dist/process.js +0 -241
- package/dist/process.js.map +0 -1
- package/dist/product.d.ts +0 -85
- package/dist/product.d.ts.map +0 -1
- package/dist/product.js +0 -145
- package/dist/product.js.map +0 -1
- package/dist/queries.d.ts +0 -304
- package/dist/queries.d.ts.map +0 -1
- package/dist/queries.js +0 -415
- package/dist/queries.js.map +0 -1
- package/dist/roles.d.ts +0 -340
- package/dist/roles.d.ts.map +0 -1
- package/dist/roles.js +0 -255
- package/dist/roles.js.map +0 -1
- package/dist/service.d.ts +0 -61
- package/dist/service.d.ts.map +0 -1
- package/dist/service.js +0 -140
- package/dist/service.js.map +0 -1
- package/dist/types.d.ts +0 -459
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/vision.d.ts +0 -38
- package/dist/vision.d.ts.map +0 -1
- package/dist/vision.js +0 -68
- package/dist/vision.js.map +0 -1
- package/dist/workflow.d.ts +0 -115
- package/dist/workflow.d.ts.map +0 -1
- package/dist/workflow.js +0 -247
- package/dist/workflow.js.map +0 -1
- package/src/business.js +0 -108
- package/src/canvas/activities.ts +0 -32
- package/src/canvas/canvas.ts +0 -482
- package/src/canvas/channels.ts +0 -34
- package/src/canvas/costs.ts +0 -43
- package/src/canvas/economics.ts +0 -99
- package/src/canvas/index.ts +0 -206
- package/src/canvas/partnerships.ts +0 -34
- package/src/canvas/projections.ts +0 -141
- package/src/canvas/relationships.ts +0 -34
- package/src/canvas/resources.ts +0 -43
- package/src/canvas/revenue.ts +0 -56
- package/src/canvas/segments.ts +0 -42
- package/src/canvas/types.ts +0 -363
- package/src/canvas/value.ts +0 -34
- package/src/dollar.js +0 -106
- package/src/entities/assets.js +0 -322
- package/src/entities/business.js +0 -369
- package/src/entities/communication.js +0 -254
- package/src/entities/customers.js +0 -988
- package/src/entities/financials.js +0 -931
- package/src/entities/goals.js +0 -799
- package/src/entities/index.js +0 -197
- package/src/entities/legal.js +0 -300
- package/src/entities/market.js +0 -300
- package/src/entities/marketing.js +0 -1156
- package/src/entities/offerings.js +0 -726
- package/src/entities/operations.js +0 -786
- package/src/entities/organization.js +0 -806
- package/src/entities/partnerships.js +0 -299
- package/src/entities/planning.js +0 -270
- package/src/entities/projects.js +0 -348
- package/src/entities/risk.js +0 -292
- package/src/entities/sales.js +0 -1247
- package/src/financials.js +0 -296
- package/src/goals.js +0 -214
- package/src/index.js +0 -131
- package/src/index.test.js +0 -274
- package/src/kpis.js +0 -231
- package/src/metrics.js +0 -324
- package/src/okrs.js +0 -268
- package/src/organization.js +0 -172
- package/src/process.js +0 -240
- package/src/product.js +0 -144
- package/src/queries.js +0 -414
- package/src/roles.js +0 -254
- package/src/service.js +0 -139
- package/src/types.js +0 -4
- package/src/vision.js +0 -67
- package/src/workflow.js +0 -246
- 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
|
+
})
|
package/vitest.config.ts
ADDED
|
@@ -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/.turbo/turbo-build.log
DELETED
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.
|
package/dist/business.d.ts
DELETED
|
@@ -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
|
package/dist/business.d.ts.map
DELETED
|
@@ -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"}
|