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.
Files changed (190) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +17 -0
  3. package/IMPLEMENTATION.md +226 -0
  4. package/README.md +1133 -193
  5. package/dist/business.d.ts +62 -0
  6. package/dist/business.d.ts.map +1 -0
  7. package/dist/business.js +109 -0
  8. package/dist/business.js.map +1 -0
  9. package/dist/dollar.d.ts +60 -0
  10. package/dist/dollar.d.ts.map +1 -0
  11. package/dist/dollar.js +107 -0
  12. package/dist/dollar.js.map +1 -0
  13. package/dist/entities/assets.d.ts +21 -0
  14. package/dist/entities/assets.d.ts.map +1 -0
  15. package/dist/entities/assets.js +323 -0
  16. package/dist/entities/assets.js.map +1 -0
  17. package/dist/entities/business.d.ts +36 -0
  18. package/dist/entities/business.d.ts.map +1 -0
  19. package/dist/entities/business.js +370 -0
  20. package/dist/entities/business.js.map +1 -0
  21. package/dist/entities/communication.d.ts +21 -0
  22. package/dist/entities/communication.d.ts.map +1 -0
  23. package/dist/entities/communication.js +255 -0
  24. package/dist/entities/communication.js.map +1 -0
  25. package/dist/entities/customers.d.ts +58 -0
  26. package/dist/entities/customers.d.ts.map +1 -0
  27. package/dist/entities/customers.js +989 -0
  28. package/dist/entities/customers.js.map +1 -0
  29. package/dist/entities/financials.d.ts +59 -0
  30. package/dist/entities/financials.d.ts.map +1 -0
  31. package/dist/entities/financials.js +932 -0
  32. package/dist/entities/financials.js.map +1 -0
  33. package/dist/entities/goals.d.ts +58 -0
  34. package/dist/entities/goals.d.ts.map +1 -0
  35. package/dist/entities/goals.js +800 -0
  36. package/dist/entities/goals.js.map +1 -0
  37. package/dist/entities/index.d.ts +299 -0
  38. package/dist/entities/index.d.ts.map +1 -0
  39. package/dist/entities/index.js +198 -0
  40. package/dist/entities/index.js.map +1 -0
  41. package/dist/entities/legal.d.ts +21 -0
  42. package/dist/entities/legal.d.ts.map +1 -0
  43. package/dist/entities/legal.js +301 -0
  44. package/dist/entities/legal.js.map +1 -0
  45. package/dist/entities/market.d.ts +21 -0
  46. package/dist/entities/market.d.ts.map +1 -0
  47. package/dist/entities/market.js +301 -0
  48. package/dist/entities/market.js.map +1 -0
  49. package/dist/entities/marketing.d.ts +67 -0
  50. package/dist/entities/marketing.d.ts.map +1 -0
  51. package/dist/entities/marketing.js +1157 -0
  52. package/dist/entities/marketing.js.map +1 -0
  53. package/dist/entities/offerings.d.ts +51 -0
  54. package/dist/entities/offerings.d.ts.map +1 -0
  55. package/dist/entities/offerings.js +727 -0
  56. package/dist/entities/offerings.js.map +1 -0
  57. package/dist/entities/operations.d.ts +58 -0
  58. package/dist/entities/operations.d.ts.map +1 -0
  59. package/dist/entities/operations.js +787 -0
  60. package/dist/entities/operations.js.map +1 -0
  61. package/dist/entities/organization.d.ts +57 -0
  62. package/dist/entities/organization.d.ts.map +1 -0
  63. package/dist/entities/organization.js +807 -0
  64. package/dist/entities/organization.js.map +1 -0
  65. package/dist/entities/partnerships.d.ts +21 -0
  66. package/dist/entities/partnerships.d.ts.map +1 -0
  67. package/dist/entities/partnerships.js +300 -0
  68. package/dist/entities/partnerships.js.map +1 -0
  69. package/dist/entities/planning.d.ts +87 -0
  70. package/dist/entities/planning.d.ts.map +1 -0
  71. package/dist/entities/planning.js +271 -0
  72. package/dist/entities/planning.js.map +1 -0
  73. package/dist/entities/projects.d.ts +25 -0
  74. package/dist/entities/projects.d.ts.map +1 -0
  75. package/dist/entities/projects.js +349 -0
  76. package/dist/entities/projects.js.map +1 -0
  77. package/dist/entities/risk.d.ts +21 -0
  78. package/dist/entities/risk.d.ts.map +1 -0
  79. package/dist/entities/risk.js +293 -0
  80. package/dist/entities/risk.js.map +1 -0
  81. package/dist/entities/sales.d.ts +72 -0
  82. package/dist/entities/sales.d.ts.map +1 -0
  83. package/dist/entities/sales.js +1248 -0
  84. package/dist/entities/sales.js.map +1 -0
  85. package/dist/financials.d.ts +130 -0
  86. package/dist/financials.d.ts.map +1 -0
  87. package/dist/financials.js +297 -0
  88. package/dist/financials.js.map +1 -0
  89. package/dist/goals.d.ts +87 -0
  90. package/dist/goals.d.ts.map +1 -0
  91. package/dist/goals.js +215 -0
  92. package/dist/goals.js.map +1 -0
  93. package/dist/index.d.ts +97 -4
  94. package/dist/index.d.ts.map +1 -0
  95. package/dist/index.js +131 -1079
  96. package/dist/index.js.map +1 -1
  97. package/dist/kpis.d.ts +118 -0
  98. package/dist/kpis.d.ts.map +1 -0
  99. package/dist/kpis.js +232 -0
  100. package/dist/kpis.js.map +1 -0
  101. package/dist/metrics.d.ts +448 -0
  102. package/dist/metrics.d.ts.map +1 -0
  103. package/dist/metrics.js +325 -0
  104. package/dist/metrics.js.map +1 -0
  105. package/dist/okrs.d.ts +123 -0
  106. package/dist/okrs.d.ts.map +1 -0
  107. package/dist/okrs.js +269 -0
  108. package/dist/okrs.js.map +1 -0
  109. package/dist/organization.d.ts +585 -0
  110. package/dist/organization.d.ts.map +1 -0
  111. package/dist/organization.js +173 -0
  112. package/dist/organization.js.map +1 -0
  113. package/dist/process.d.ts +112 -0
  114. package/dist/process.d.ts.map +1 -0
  115. package/dist/process.js +241 -0
  116. package/dist/process.js.map +1 -0
  117. package/dist/product.d.ts +85 -0
  118. package/dist/product.d.ts.map +1 -0
  119. package/dist/product.js +145 -0
  120. package/dist/product.js.map +1 -0
  121. package/dist/queries.d.ts +304 -0
  122. package/dist/queries.d.ts.map +1 -0
  123. package/dist/queries.js +415 -0
  124. package/dist/queries.js.map +1 -0
  125. package/dist/roles.d.ts +340 -0
  126. package/dist/roles.d.ts.map +1 -0
  127. package/dist/roles.js +255 -0
  128. package/dist/roles.js.map +1 -0
  129. package/dist/service.d.ts +61 -0
  130. package/dist/service.d.ts.map +1 -0
  131. package/dist/service.js +140 -0
  132. package/dist/service.js.map +1 -0
  133. package/dist/types.d.ts +459 -0
  134. package/dist/types.d.ts.map +1 -0
  135. package/dist/types.js +5 -0
  136. package/dist/types.js.map +1 -0
  137. package/dist/vision.d.ts +38 -0
  138. package/dist/vision.d.ts.map +1 -0
  139. package/dist/vision.js +68 -0
  140. package/dist/vision.js.map +1 -0
  141. package/dist/workflow.d.ts +115 -0
  142. package/dist/workflow.d.ts.map +1 -0
  143. package/dist/workflow.js +247 -0
  144. package/dist/workflow.js.map +1 -0
  145. package/examples/basic-usage.ts +307 -0
  146. package/package.json +19 -60
  147. package/src/business.ts +121 -0
  148. package/src/dollar.ts +132 -0
  149. package/src/entities/assets.ts +332 -0
  150. package/src/entities/business.ts +406 -0
  151. package/src/entities/communication.ts +264 -0
  152. package/src/entities/customers.ts +1072 -0
  153. package/src/entities/financials.ts +1011 -0
  154. package/src/entities/goals.ts +871 -0
  155. package/src/entities/index.ts +383 -0
  156. package/src/entities/legal.ts +310 -0
  157. package/src/entities/market.ts +310 -0
  158. package/src/entities/marketing.ts +1249 -0
  159. package/src/entities/offerings.ts +789 -0
  160. package/src/entities/operations.ts +861 -0
  161. package/src/entities/organization.ts +876 -0
  162. package/src/entities/partnerships.ts +309 -0
  163. package/src/entities/planning.ts +307 -0
  164. package/src/entities/projects.ts +360 -0
  165. package/src/entities/risk.ts +302 -0
  166. package/src/entities/sales.ts +1352 -0
  167. package/src/financials.ts +352 -0
  168. package/src/goals.ts +250 -0
  169. package/src/index.test.ts +336 -0
  170. package/src/index.ts +530 -0
  171. package/src/kpis.ts +275 -0
  172. package/src/metrics.ts +825 -0
  173. package/src/okrs.ts +325 -0
  174. package/src/organization.ts +909 -0
  175. package/src/process.ts +272 -0
  176. package/src/product.ts +178 -0
  177. package/src/queries.ts +767 -0
  178. package/src/roles.ts +686 -0
  179. package/src/service.ts +164 -0
  180. package/src/types.ts +493 -0
  181. package/src/vision.ts +88 -0
  182. package/src/workflow.ts +280 -0
  183. package/tsconfig.json +9 -0
  184. package/dist/loaders/index.d.ts +0 -174
  185. package/dist/loaders/index.js +0 -366
  186. package/dist/loaders/index.js.map +0 -1
  187. package/dist/schema/index.d.ts +0 -146
  188. package/dist/schema/index.js +0 -716
  189. package/dist/schema/index.js.map +0 -1
  190. 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
+ })