business-as-code 0.2.1 → 2.0.2
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +17 -0
- package/IMPLEMENTATION.md +226 -0
- package/README.md +1133 -193
- package/dist/business.d.ts +62 -0
- package/dist/business.d.ts.map +1 -0
- package/dist/business.js +109 -0
- package/dist/business.js.map +1 -0
- package/dist/dollar.d.ts +60 -0
- package/dist/dollar.d.ts.map +1 -0
- package/dist/dollar.js +107 -0
- package/dist/dollar.js.map +1 -0
- package/dist/entities/assets.d.ts +21 -0
- package/dist/entities/assets.d.ts.map +1 -0
- package/dist/entities/assets.js +323 -0
- package/dist/entities/assets.js.map +1 -0
- package/dist/entities/business.d.ts +36 -0
- package/dist/entities/business.d.ts.map +1 -0
- package/dist/entities/business.js +370 -0
- package/dist/entities/business.js.map +1 -0
- package/dist/entities/communication.d.ts +21 -0
- package/dist/entities/communication.d.ts.map +1 -0
- package/dist/entities/communication.js +255 -0
- package/dist/entities/communication.js.map +1 -0
- package/dist/entities/customers.d.ts +58 -0
- package/dist/entities/customers.d.ts.map +1 -0
- package/dist/entities/customers.js +989 -0
- package/dist/entities/customers.js.map +1 -0
- package/dist/entities/financials.d.ts +59 -0
- package/dist/entities/financials.d.ts.map +1 -0
- package/dist/entities/financials.js +932 -0
- package/dist/entities/financials.js.map +1 -0
- package/dist/entities/goals.d.ts +58 -0
- package/dist/entities/goals.d.ts.map +1 -0
- package/dist/entities/goals.js +800 -0
- package/dist/entities/goals.js.map +1 -0
- package/dist/entities/index.d.ts +299 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +198 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/legal.d.ts +21 -0
- package/dist/entities/legal.d.ts.map +1 -0
- package/dist/entities/legal.js +301 -0
- package/dist/entities/legal.js.map +1 -0
- package/dist/entities/market.d.ts +21 -0
- package/dist/entities/market.d.ts.map +1 -0
- package/dist/entities/market.js +301 -0
- package/dist/entities/market.js.map +1 -0
- package/dist/entities/marketing.d.ts +67 -0
- package/dist/entities/marketing.d.ts.map +1 -0
- package/dist/entities/marketing.js +1157 -0
- package/dist/entities/marketing.js.map +1 -0
- package/dist/entities/offerings.d.ts +51 -0
- package/dist/entities/offerings.d.ts.map +1 -0
- package/dist/entities/offerings.js +727 -0
- package/dist/entities/offerings.js.map +1 -0
- package/dist/entities/operations.d.ts +58 -0
- package/dist/entities/operations.d.ts.map +1 -0
- package/dist/entities/operations.js +787 -0
- package/dist/entities/operations.js.map +1 -0
- package/dist/entities/organization.d.ts +57 -0
- package/dist/entities/organization.d.ts.map +1 -0
- package/dist/entities/organization.js +807 -0
- package/dist/entities/organization.js.map +1 -0
- package/dist/entities/partnerships.d.ts +21 -0
- package/dist/entities/partnerships.d.ts.map +1 -0
- package/dist/entities/partnerships.js +300 -0
- package/dist/entities/partnerships.js.map +1 -0
- package/dist/entities/planning.d.ts +87 -0
- package/dist/entities/planning.d.ts.map +1 -0
- package/dist/entities/planning.js +271 -0
- package/dist/entities/planning.js.map +1 -0
- package/dist/entities/projects.d.ts +25 -0
- package/dist/entities/projects.d.ts.map +1 -0
- package/dist/entities/projects.js +349 -0
- package/dist/entities/projects.js.map +1 -0
- package/dist/entities/risk.d.ts +21 -0
- package/dist/entities/risk.d.ts.map +1 -0
- package/dist/entities/risk.js +293 -0
- package/dist/entities/risk.js.map +1 -0
- package/dist/entities/sales.d.ts +72 -0
- package/dist/entities/sales.d.ts.map +1 -0
- package/dist/entities/sales.js +1248 -0
- package/dist/entities/sales.js.map +1 -0
- package/dist/financials.d.ts +130 -0
- package/dist/financials.d.ts.map +1 -0
- package/dist/financials.js +297 -0
- package/dist/financials.js.map +1 -0
- package/dist/goals.d.ts +87 -0
- package/dist/goals.d.ts.map +1 -0
- package/dist/goals.js +215 -0
- package/dist/goals.js.map +1 -0
- package/dist/index.d.ts +97 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +131 -1079
- package/dist/index.js.map +1 -1
- package/dist/kpis.d.ts +118 -0
- package/dist/kpis.d.ts.map +1 -0
- package/dist/kpis.js +232 -0
- package/dist/kpis.js.map +1 -0
- package/dist/metrics.d.ts +448 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +325 -0
- package/dist/metrics.js.map +1 -0
- package/dist/okrs.d.ts +123 -0
- package/dist/okrs.d.ts.map +1 -0
- package/dist/okrs.js +269 -0
- package/dist/okrs.js.map +1 -0
- package/dist/organization.d.ts +585 -0
- package/dist/organization.d.ts.map +1 -0
- package/dist/organization.js +173 -0
- package/dist/organization.js.map +1 -0
- package/dist/process.d.ts +112 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +241 -0
- package/dist/process.js.map +1 -0
- package/dist/product.d.ts +85 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +145 -0
- package/dist/product.js.map +1 -0
- package/dist/queries.d.ts +304 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +415 -0
- package/dist/queries.js.map +1 -0
- package/dist/roles.d.ts +340 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +255 -0
- package/dist/roles.js.map +1 -0
- package/dist/service.d.ts +61 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +140 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +459 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/vision.d.ts +38 -0
- package/dist/vision.d.ts.map +1 -0
- package/dist/vision.js +68 -0
- package/dist/vision.js.map +1 -0
- package/dist/workflow.d.ts +115 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +247 -0
- package/dist/workflow.js.map +1 -0
- package/examples/basic-usage.ts +307 -0
- package/package.json +19 -60
- package/src/business.ts +121 -0
- package/src/dollar.ts +132 -0
- package/src/entities/assets.ts +332 -0
- package/src/entities/business.ts +406 -0
- package/src/entities/communication.ts +264 -0
- package/src/entities/customers.ts +1072 -0
- package/src/entities/financials.ts +1011 -0
- package/src/entities/goals.ts +871 -0
- package/src/entities/index.ts +383 -0
- package/src/entities/legal.ts +310 -0
- package/src/entities/market.ts +310 -0
- package/src/entities/marketing.ts +1249 -0
- package/src/entities/offerings.ts +789 -0
- package/src/entities/operations.ts +861 -0
- package/src/entities/organization.ts +876 -0
- package/src/entities/partnerships.ts +309 -0
- package/src/entities/planning.ts +307 -0
- package/src/entities/projects.ts +360 -0
- package/src/entities/risk.ts +302 -0
- package/src/entities/sales.ts +1352 -0
- package/src/financials.ts +352 -0
- package/src/goals.ts +250 -0
- package/src/index.test.ts +336 -0
- package/src/index.ts +530 -0
- package/src/kpis.ts +275 -0
- package/src/metrics.ts +825 -0
- package/src/okrs.ts +325 -0
- package/src/organization.ts +909 -0
- package/src/process.ts +272 -0
- package/src/product.ts +178 -0
- package/src/queries.ts +767 -0
- package/src/roles.ts +686 -0
- package/src/service.ts +164 -0
- package/src/types.ts +493 -0
- package/src/vision.ts +88 -0
- package/src/workflow.ts +280 -0
- package/tsconfig.json +9 -0
- package/dist/loaders/index.d.ts +0 -174
- package/dist/loaders/index.js +0 -366
- package/dist/loaders/index.js.map +0 -1
- package/dist/schema/index.d.ts +0 -146
- package/dist/schema/index.js +0 -716
- package/dist/schema/index.js.map +0 -1
- package/dist/types-CJ9eGS_C.d.ts +0 -86
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for business-as-code package
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from 'vitest'
|
|
6
|
+
import {
|
|
7
|
+
Business,
|
|
8
|
+
Vision,
|
|
9
|
+
Goals,
|
|
10
|
+
Product,
|
|
11
|
+
Service,
|
|
12
|
+
Process,
|
|
13
|
+
Workflow,
|
|
14
|
+
kpis,
|
|
15
|
+
okrs,
|
|
16
|
+
financials,
|
|
17
|
+
$,
|
|
18
|
+
calculateGrossMargin,
|
|
19
|
+
calculateOverallProgress,
|
|
20
|
+
updateProgress,
|
|
21
|
+
calculateOKRProgress,
|
|
22
|
+
updateKeyResult,
|
|
23
|
+
} from './index.js'
|
|
24
|
+
|
|
25
|
+
describe('Business', () => {
|
|
26
|
+
it('should create a business entity', () => {
|
|
27
|
+
const business = Business({
|
|
28
|
+
name: 'Test Corp',
|
|
29
|
+
mission: 'Test mission',
|
|
30
|
+
values: ['Value 1', 'Value 2'],
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
expect(business.name).toBe('Test Corp')
|
|
34
|
+
expect(business.mission).toBe('Test mission')
|
|
35
|
+
expect(business.values).toEqual(['Value 1', 'Value 2'])
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('should throw error if name is missing', () => {
|
|
39
|
+
expect(() => Business({ name: '' })).toThrow('Business name is required')
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('Vision', () => {
|
|
44
|
+
it('should create a vision statement', () => {
|
|
45
|
+
const vision = Vision({
|
|
46
|
+
statement: 'To be the best',
|
|
47
|
+
timeframe: '5 years',
|
|
48
|
+
successIndicators: ['Indicator 1', 'Indicator 2'],
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
expect(vision.statement).toBe('To be the best')
|
|
52
|
+
expect(vision.timeframe).toBe('5 years')
|
|
53
|
+
expect(vision.successIndicators).toHaveLength(2)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('should throw error if statement is missing', () => {
|
|
57
|
+
expect(() => Vision({ statement: '' })).toThrow('Vision statement is required')
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
describe('Goals', () => {
|
|
62
|
+
it('should create multiple goals', () => {
|
|
63
|
+
const goals = Goals([
|
|
64
|
+
{
|
|
65
|
+
name: 'Goal 1',
|
|
66
|
+
category: 'strategic',
|
|
67
|
+
status: 'in-progress',
|
|
68
|
+
progress: 50,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'Goal 2',
|
|
72
|
+
category: 'operational',
|
|
73
|
+
status: 'not-started',
|
|
74
|
+
progress: 0,
|
|
75
|
+
},
|
|
76
|
+
])
|
|
77
|
+
|
|
78
|
+
expect(goals).toHaveLength(2)
|
|
79
|
+
expect(goals[0]!.name).toBe('Goal 1')
|
|
80
|
+
expect(goals[1]!.name).toBe('Goal 2')
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('should calculate overall progress', () => {
|
|
84
|
+
const goals = Goals([
|
|
85
|
+
{ name: 'Goal 1', progress: 50 },
|
|
86
|
+
{ name: 'Goal 2', progress: 100 },
|
|
87
|
+
])
|
|
88
|
+
|
|
89
|
+
const progress = calculateOverallProgress(goals)
|
|
90
|
+
expect(progress).toBe(75)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('should update goal progress', () => {
|
|
94
|
+
const goal = { name: 'Test', progress: 0, status: 'not-started' as const }
|
|
95
|
+
const updated = updateProgress(goal, 100)
|
|
96
|
+
|
|
97
|
+
expect(updated.progress).toBe(100)
|
|
98
|
+
expect(updated.status).toBe('completed')
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe('Product', () => {
|
|
103
|
+
it('should create a product', () => {
|
|
104
|
+
const product = Product({
|
|
105
|
+
name: 'Test Product',
|
|
106
|
+
price: 100,
|
|
107
|
+
cogs: 30,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
expect(product.name).toBe('Test Product')
|
|
111
|
+
expect(product.price).toBe(100)
|
|
112
|
+
expect(product.cogs).toBe(30)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
it('should calculate gross margin', () => {
|
|
116
|
+
const product = Product({
|
|
117
|
+
name: 'Test Product',
|
|
118
|
+
price: 100,
|
|
119
|
+
cogs: 30,
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const margin = calculateGrossMargin(product)
|
|
123
|
+
expect(margin).toBe(70)
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
describe('Service', () => {
|
|
128
|
+
it('should create a service', () => {
|
|
129
|
+
const service = Service({
|
|
130
|
+
name: 'Test Service',
|
|
131
|
+
pricingModel: 'hourly',
|
|
132
|
+
price: 100,
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
expect(service.name).toBe('Test Service')
|
|
136
|
+
expect(service.pricingModel).toBe('hourly')
|
|
137
|
+
expect(service.price).toBe(100)
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
describe('Process', () => {
|
|
142
|
+
it('should create a process', () => {
|
|
143
|
+
const process = Process({
|
|
144
|
+
name: 'Test Process',
|
|
145
|
+
steps: [
|
|
146
|
+
{
|
|
147
|
+
order: 1,
|
|
148
|
+
name: 'Step 1',
|
|
149
|
+
automationLevel: 'automated',
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
expect(process.name).toBe('Test Process')
|
|
155
|
+
expect(process.steps).toHaveLength(1)
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
describe('Workflow', () => {
|
|
160
|
+
it('should create a workflow', () => {
|
|
161
|
+
const workflow = Workflow({
|
|
162
|
+
name: 'Test Workflow',
|
|
163
|
+
trigger: { type: 'event', event: 'test.event' },
|
|
164
|
+
actions: [
|
|
165
|
+
{
|
|
166
|
+
order: 1,
|
|
167
|
+
type: 'send',
|
|
168
|
+
description: 'Send notification',
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
expect(workflow.name).toBe('Test Workflow')
|
|
174
|
+
expect(workflow.trigger.type).toBe('event')
|
|
175
|
+
expect(workflow.actions).toHaveLength(1)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('should throw error if trigger is missing', () => {
|
|
179
|
+
expect(() =>
|
|
180
|
+
Workflow({
|
|
181
|
+
name: 'Test',
|
|
182
|
+
trigger: undefined as any,
|
|
183
|
+
})
|
|
184
|
+
).toThrow('Workflow trigger is required')
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
describe('KPIs', () => {
|
|
189
|
+
it('should create KPIs', () => {
|
|
190
|
+
const kpiList = kpis([
|
|
191
|
+
{
|
|
192
|
+
name: 'Revenue',
|
|
193
|
+
target: 100000,
|
|
194
|
+
current: 85000,
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'Churn',
|
|
198
|
+
target: 5,
|
|
199
|
+
current: 3.2,
|
|
200
|
+
},
|
|
201
|
+
])
|
|
202
|
+
|
|
203
|
+
expect(kpiList).toHaveLength(2)
|
|
204
|
+
expect(kpiList[0]!.name).toBe('Revenue')
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
describe('OKRs', () => {
|
|
209
|
+
it('should create OKRs', () => {
|
|
210
|
+
const okrList = okrs([
|
|
211
|
+
{
|
|
212
|
+
objective: 'Test Objective',
|
|
213
|
+
keyResults: [
|
|
214
|
+
{
|
|
215
|
+
description: 'KR 1',
|
|
216
|
+
metric: 'test_metric',
|
|
217
|
+
startValue: 0,
|
|
218
|
+
targetValue: 100,
|
|
219
|
+
currentValue: 50,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
},
|
|
223
|
+
])
|
|
224
|
+
|
|
225
|
+
expect(okrList).toHaveLength(1)
|
|
226
|
+
expect(okrList[0]!.objective).toBe('Test Objective')
|
|
227
|
+
expect(okrList[0]!.keyResults).toHaveLength(1)
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
it('should calculate OKR progress', () => {
|
|
231
|
+
const okr = {
|
|
232
|
+
objective: 'Test',
|
|
233
|
+
keyResults: [
|
|
234
|
+
{
|
|
235
|
+
description: 'KR 1',
|
|
236
|
+
metric: 'metric',
|
|
237
|
+
startValue: 0,
|
|
238
|
+
targetValue: 100,
|
|
239
|
+
currentValue: 50,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
description: 'KR 2',
|
|
243
|
+
metric: 'metric',
|
|
244
|
+
startValue: 0,
|
|
245
|
+
targetValue: 100,
|
|
246
|
+
currentValue: 100,
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const progress = calculateOKRProgress(okr)
|
|
252
|
+
expect(progress).toBe(75)
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('should update key result', () => {
|
|
256
|
+
const okr = {
|
|
257
|
+
objective: 'Test',
|
|
258
|
+
keyResults: [
|
|
259
|
+
{
|
|
260
|
+
description: 'KR 1',
|
|
261
|
+
metric: 'metric',
|
|
262
|
+
startValue: 0,
|
|
263
|
+
targetValue: 100,
|
|
264
|
+
currentValue: 50,
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const updated = updateKeyResult(okr, 'KR 1', 75)
|
|
270
|
+
expect(updated.keyResults![0]!.currentValue).toBe(75)
|
|
271
|
+
expect(updated.keyResults![0]!.progress).toBe(75)
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
describe('Financials', () => {
|
|
276
|
+
it('should calculate financial metrics', () => {
|
|
277
|
+
const metrics = financials({
|
|
278
|
+
revenue: 1000000,
|
|
279
|
+
cogs: 300000,
|
|
280
|
+
operatingExpenses: 500000,
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
expect(metrics.revenue).toBe(1000000)
|
|
284
|
+
expect(metrics.grossProfit).toBe(700000)
|
|
285
|
+
expect(metrics.grossMargin).toBe(70)
|
|
286
|
+
expect(metrics.operatingIncome).toBe(200000)
|
|
287
|
+
expect(metrics.operatingMargin).toBe(20)
|
|
288
|
+
})
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
describe('$ Helper', () => {
|
|
292
|
+
it('should format currency', () => {
|
|
293
|
+
const formatted = $.format(1234.56)
|
|
294
|
+
expect(formatted).toMatch(/1,234\.56/)
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
it('should calculate percentage', () => {
|
|
298
|
+
const percent = $.percent(25, 100)
|
|
299
|
+
expect(percent).toBe(25)
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
it('should calculate growth', () => {
|
|
303
|
+
const growth = $.growth(120, 100)
|
|
304
|
+
expect(growth).toBe(20)
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('should calculate margin', () => {
|
|
308
|
+
const margin = $.margin(100, 60)
|
|
309
|
+
expect(margin).toBe(40)
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
it('should calculate ROI', () => {
|
|
313
|
+
const roi = $.roi(150, 100)
|
|
314
|
+
expect(roi).toBe(50)
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
it('should calculate LTV', () => {
|
|
318
|
+
const ltv = $.ltv(100, 12, 2)
|
|
319
|
+
expect(ltv).toBe(2400)
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
it('should calculate CAC', () => {
|
|
323
|
+
const cac = $.cac(10000, 100)
|
|
324
|
+
expect(cac).toBe(100)
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
it('should calculate burn rate', () => {
|
|
328
|
+
const burnRate = $.burnRate(100000, 70000, 3)
|
|
329
|
+
expect(burnRate).toBe(10000)
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
it('should calculate runway', () => {
|
|
333
|
+
const runway = $.runway(100000, 10000)
|
|
334
|
+
expect(runway).toBe(10)
|
|
335
|
+
})
|
|
336
|
+
})
|