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
package/src/financials.js DELETED
@@ -1,296 +0,0 @@
1
- /**
2
- * Financial metrics and calculations
3
- */
4
- /**
5
- * Calculate financial metrics from basic inputs
6
- *
7
- * @example
8
- * ```ts
9
- * const metrics = financials({
10
- * revenue: 1000000,
11
- * cogs: 300000,
12
- * operatingExpenses: 500000,
13
- * currency: 'USD',
14
- * period: 'monthly',
15
- * })
16
- *
17
- * console.log(metrics.grossMargin) // 70%
18
- * console.log(metrics.operatingMargin) // 20%
19
- * console.log(metrics.netMargin) // 20%
20
- * ```
21
- */
22
- export function financials(metrics) {
23
- const revenue = metrics.revenue || 0;
24
- const cogs = metrics.cogs || 0;
25
- const operatingExpenses = metrics.operatingExpenses || 0;
26
- // Calculate derived metrics
27
- const grossProfit = revenue - cogs;
28
- const grossMargin = revenue > 0 ? (grossProfit / revenue) * 100 : 0;
29
- const operatingIncome = grossProfit - operatingExpenses;
30
- const operatingMargin = revenue > 0 ? (operatingIncome / revenue) * 100 : 0;
31
- const netIncome = metrics.netIncome ?? operatingIncome;
32
- const netMargin = revenue > 0 ? (netIncome / revenue) * 100 : 0;
33
- // EBITDA (simplified - would need D&A for accurate calculation)
34
- const ebitda = metrics.ebitda ?? operatingIncome;
35
- const ebitdaMargin = revenue > 0 ? (ebitda / revenue) * 100 : 0;
36
- return {
37
- ...metrics,
38
- revenue,
39
- cogs,
40
- grossProfit,
41
- grossMargin,
42
- operatingExpenses,
43
- operatingIncome,
44
- operatingMargin,
45
- netIncome,
46
- netMargin,
47
- ebitda,
48
- ebitdaMargin,
49
- currency: metrics.currency || 'USD',
50
- period: metrics.period || 'monthly',
51
- };
52
- }
53
- /**
54
- * Calculate gross margin
55
- */
56
- export function calculateGrossMargin(revenue, cogs) {
57
- if (revenue === 0)
58
- return 0;
59
- return ((revenue - cogs) / revenue) * 100;
60
- }
61
- /**
62
- * Calculate operating margin
63
- */
64
- export function calculateOperatingMargin(revenue, cogs, operatingExpenses) {
65
- if (revenue === 0)
66
- return 0;
67
- const operatingIncome = revenue - cogs - operatingExpenses;
68
- return (operatingIncome / revenue) * 100;
69
- }
70
- /**
71
- * Calculate net margin
72
- */
73
- export function calculateNetMargin(revenue, netIncome) {
74
- if (revenue === 0)
75
- return 0;
76
- return (netIncome / revenue) * 100;
77
- }
78
- /**
79
- * Calculate EBITDA margin
80
- */
81
- export function calculateEBITDAMargin(revenue, ebitda) {
82
- if (revenue === 0)
83
- return 0;
84
- return (ebitda / revenue) * 100;
85
- }
86
- /**
87
- * Calculate burn rate (monthly cash burn)
88
- */
89
- export function calculateBurnRate(cashStart, cashEnd, months) {
90
- if (months === 0)
91
- return 0;
92
- return (cashStart - cashEnd) / months;
93
- }
94
- /**
95
- * Calculate runway (months until cash runs out)
96
- */
97
- export function calculateRunway(cash, monthlyBurnRate) {
98
- if (monthlyBurnRate === 0)
99
- return Infinity;
100
- if (monthlyBurnRate < 0)
101
- return Infinity; // Company is profitable
102
- return cash / monthlyBurnRate;
103
- }
104
- /**
105
- * Calculate customer acquisition cost (CAC)
106
- */
107
- export function calculateCAC(marketingSpend, newCustomers) {
108
- if (newCustomers === 0)
109
- return 0;
110
- return marketingSpend / newCustomers;
111
- }
112
- /**
113
- * Calculate customer lifetime value (LTV)
114
- */
115
- export function calculateLTV(averageRevenuePerCustomer, averageCustomerLifetimeMonths, grossMarginPercent) {
116
- return averageRevenuePerCustomer * averageCustomerLifetimeMonths * (grossMarginPercent / 100);
117
- }
118
- /**
119
- * Calculate LTV:CAC ratio
120
- */
121
- export function calculateLTVtoCAC(ltv, cac) {
122
- if (cac === 0)
123
- return 0;
124
- return ltv / cac;
125
- }
126
- /**
127
- * Calculate payback period (months to recover CAC)
128
- */
129
- export function calculatePaybackPeriod(cac, monthlyRevPerCustomer) {
130
- if (monthlyRevPerCustomer === 0)
131
- return 0;
132
- return cac / monthlyRevPerCustomer;
133
- }
134
- /**
135
- * Calculate annual recurring revenue (ARR)
136
- */
137
- export function calculateARR(mrr) {
138
- return mrr * 12;
139
- }
140
- /**
141
- * Calculate monthly recurring revenue (MRR)
142
- */
143
- export function calculateMRR(arr) {
144
- return arr / 12;
145
- }
146
- /**
147
- * Calculate revenue growth rate
148
- */
149
- export function calculateGrowthRate(currentRevenue, previousRevenue) {
150
- if (previousRevenue === 0)
151
- return 0;
152
- return ((currentRevenue - previousRevenue) / previousRevenue) * 100;
153
- }
154
- /**
155
- * Calculate compound annual growth rate (CAGR)
156
- */
157
- export function calculateCAGR(beginningValue, endingValue, years) {
158
- if (beginningValue === 0 || years === 0)
159
- return 0;
160
- return (Math.pow(endingValue / beginningValue, 1 / years) - 1) * 100;
161
- }
162
- /**
163
- * Calculate return on investment (ROI)
164
- */
165
- export function calculateROI(gain, cost) {
166
- if (cost === 0)
167
- return 0;
168
- return ((gain - cost) / cost) * 100;
169
- }
170
- /**
171
- * Calculate return on equity (ROE)
172
- */
173
- export function calculateROE(netIncome, shareholderEquity) {
174
- if (shareholderEquity === 0)
175
- return 0;
176
- return (netIncome / shareholderEquity) * 100;
177
- }
178
- /**
179
- * Calculate return on assets (ROA)
180
- */
181
- export function calculateROA(netIncome, totalAssets) {
182
- if (totalAssets === 0)
183
- return 0;
184
- return (netIncome / totalAssets) * 100;
185
- }
186
- /**
187
- * Calculate quick ratio (liquidity)
188
- */
189
- export function calculateQuickRatio(currentAssets, inventory, currentLiabilities) {
190
- if (currentLiabilities === 0)
191
- return 0;
192
- return (currentAssets - inventory) / currentLiabilities;
193
- }
194
- /**
195
- * Calculate current ratio (liquidity)
196
- */
197
- export function calculateCurrentRatio(currentAssets, currentLiabilities) {
198
- if (currentLiabilities === 0)
199
- return 0;
200
- return currentAssets / currentLiabilities;
201
- }
202
- /**
203
- * Calculate debt-to-equity ratio
204
- */
205
- export function calculateDebtToEquity(totalDebt, totalEquity) {
206
- if (totalEquity === 0)
207
- return 0;
208
- return totalDebt / totalEquity;
209
- }
210
- /**
211
- * Format currency value
212
- */
213
- export function formatCurrency(amount, currency = 'USD') {
214
- const symbol = getCurrencySymbol(currency);
215
- const formatted = Math.abs(amount).toLocaleString(undefined, {
216
- minimumFractionDigits: 0,
217
- maximumFractionDigits: 2,
218
- });
219
- const sign = amount < 0 ? '-' : '';
220
- return `${sign}${symbol}${formatted}`;
221
- }
222
- /**
223
- * Get currency symbol
224
- */
225
- function getCurrencySymbol(currency) {
226
- const symbols = {
227
- USD: '$',
228
- EUR: '€',
229
- GBP: '£',
230
- JPY: '¥',
231
- CNY: '¥',
232
- CAD: 'C$',
233
- AUD: 'A$',
234
- };
235
- return symbols[currency] || currency + ' ';
236
- }
237
- /**
238
- * Create a financial statement
239
- */
240
- export function createStatement(type, period, lineItems, currency = 'USD') {
241
- return {
242
- type,
243
- period,
244
- lineItems,
245
- currency,
246
- };
247
- }
248
- /**
249
- * Get line item from financial statement
250
- */
251
- export function getLineItem(statement, name) {
252
- return statement.lineItems[name] || 0;
253
- }
254
- /**
255
- * Compare financial metrics between periods
256
- */
257
- export function compareMetrics(current, previous) {
258
- const comparison = {};
259
- const keys = [
260
- 'revenue',
261
- 'grossProfit',
262
- 'operatingIncome',
263
- 'netIncome',
264
- 'ebitda',
265
- ];
266
- for (const key of keys) {
267
- const currentVal = current[key] || 0;
268
- const previousVal = previous[key] || 0;
269
- const change = currentVal - previousVal;
270
- const changePercent = previousVal !== 0 ? (change / previousVal) * 100 : 0;
271
- comparison[key] = { change, changePercent };
272
- }
273
- return comparison;
274
- }
275
- /**
276
- * Validate financial metrics
277
- */
278
- export function validateFinancials(metrics) {
279
- const errors = [];
280
- if (metrics.revenue && metrics.revenue < 0) {
281
- errors.push('Revenue cannot be negative');
282
- }
283
- if (metrics.cogs && metrics.cogs < 0) {
284
- errors.push('COGS cannot be negative');
285
- }
286
- if (metrics.operatingExpenses && metrics.operatingExpenses < 0) {
287
- errors.push('Operating expenses cannot be negative');
288
- }
289
- if (metrics.revenue && metrics.cogs && metrics.cogs > metrics.revenue) {
290
- errors.push('COGS cannot exceed revenue');
291
- }
292
- return {
293
- valid: errors.length === 0,
294
- errors,
295
- };
296
- }
package/src/goals.js DELETED
@@ -1,214 +0,0 @@
1
- /**
2
- * Business goals definition and tracking
3
- */
4
- /**
5
- * Define a business goal with metrics and tracking
6
- *
7
- * @example
8
- * ```ts
9
- * const goals = Goals([
10
- * {
11
- * name: 'Launch MVP',
12
- * description: 'Ship minimum viable product to early customers',
13
- * category: 'strategic',
14
- * targetDate: new Date('2024-06-30'),
15
- * owner: 'Product Team',
16
- * metrics: ['User signups', 'Feature completion rate'],
17
- * status: 'in-progress',
18
- * progress: 65,
19
- * },
20
- * {
21
- * name: 'Achieve Product-Market Fit',
22
- * description: 'Validate product value with target customers',
23
- * category: 'strategic',
24
- * targetDate: new Date('2024-12-31'),
25
- * owner: 'CEO',
26
- * metrics: ['NPS > 50', 'Churn < 5%', '100+ paying customers'],
27
- * status: 'in-progress',
28
- * progress: 30,
29
- * dependencies: ['Launch MVP'],
30
- * },
31
- * ])
32
- * ```
33
- */
34
- export function Goals(definitions) {
35
- return definitions.map(goal => validateAndNormalizeGoal(goal));
36
- }
37
- /**
38
- * Define a single goal
39
- */
40
- export function Goal(definition) {
41
- return validateAndNormalizeGoal(definition);
42
- }
43
- /**
44
- * Validate and normalize a goal definition
45
- */
46
- function validateAndNormalizeGoal(goal) {
47
- if (!goal.name) {
48
- throw new Error('Goal name is required');
49
- }
50
- return {
51
- ...goal,
52
- category: goal.category || 'operational',
53
- status: goal.status || 'not-started',
54
- progress: goal.progress || 0,
55
- metrics: goal.metrics || [],
56
- dependencies: goal.dependencies || [],
57
- metadata: goal.metadata || {},
58
- };
59
- }
60
- /**
61
- * Update goal progress
62
- */
63
- export function updateProgress(goal, progress) {
64
- if (progress < 0 || progress > 100) {
65
- throw new Error('Progress must be between 0 and 100');
66
- }
67
- // Auto-update status based on progress
68
- let status = goal.status;
69
- if (progress === 0) {
70
- status = 'not-started';
71
- }
72
- else if (progress === 100) {
73
- status = 'completed';
74
- }
75
- else if (progress > 0) {
76
- status = 'in-progress';
77
- }
78
- return {
79
- ...goal,
80
- progress,
81
- status,
82
- };
83
- }
84
- /**
85
- * Mark goal as at-risk
86
- */
87
- export function markAtRisk(goal) {
88
- return {
89
- ...goal,
90
- status: 'at-risk',
91
- };
92
- }
93
- /**
94
- * Mark goal as completed
95
- */
96
- export function complete(goal) {
97
- return {
98
- ...goal,
99
- status: 'completed',
100
- progress: 100,
101
- };
102
- }
103
- /**
104
- * Check if goal is overdue
105
- */
106
- export function isOverdue(goal) {
107
- if (!goal.targetDate)
108
- return false;
109
- return new Date() > goal.targetDate && goal.status !== 'completed';
110
- }
111
- /**
112
- * Get goals by category
113
- */
114
- export function getGoalsByCategory(goals, category) {
115
- return goals.filter(g => g.category === category);
116
- }
117
- /**
118
- * Get goals by status
119
- */
120
- export function getGoalsByStatus(goals, status) {
121
- return goals.filter(g => g.status === status);
122
- }
123
- /**
124
- * Get goals by owner
125
- */
126
- export function getGoalsByOwner(goals, owner) {
127
- return goals.filter(g => g.owner === owner);
128
- }
129
- /**
130
- * Calculate overall progress across all goals
131
- */
132
- export function calculateOverallProgress(goals) {
133
- if (goals.length === 0)
134
- return 0;
135
- const totalProgress = goals.reduce((sum, goal) => sum + (goal.progress || 0), 0);
136
- return totalProgress / goals.length;
137
- }
138
- /**
139
- * Check for circular dependencies
140
- */
141
- export function hasCircularDependencies(goals) {
142
- const goalMap = new Map(goals.map(g => [g.name, g]));
143
- function checkCircular(goalName, visited = new Set()) {
144
- if (visited.has(goalName))
145
- return true;
146
- const goal = goalMap.get(goalName);
147
- if (!goal || !goal.dependencies)
148
- return false;
149
- visited.add(goalName);
150
- for (const dep of goal.dependencies) {
151
- if (checkCircular(dep, new Set(visited))) {
152
- return true;
153
- }
154
- }
155
- return false;
156
- }
157
- return goals.some(goal => checkCircular(goal.name));
158
- }
159
- /**
160
- * Get goals in dependency order
161
- */
162
- export function sortByDependencies(goals) {
163
- const goalMap = new Map(goals.map(g => [g.name, g]));
164
- const sorted = [];
165
- const visited = new Set();
166
- function visit(goalName) {
167
- if (visited.has(goalName))
168
- return;
169
- const goal = goalMap.get(goalName);
170
- if (!goal)
171
- return;
172
- visited.add(goalName);
173
- // Visit dependencies first
174
- if (goal.dependencies) {
175
- for (const dep of goal.dependencies) {
176
- visit(dep);
177
- }
178
- }
179
- sorted.push(goal);
180
- }
181
- for (const goal of goals) {
182
- visit(goal.name);
183
- }
184
- return sorted;
185
- }
186
- /**
187
- * Validate goals
188
- */
189
- export function validateGoals(goals) {
190
- const errors = [];
191
- for (const goal of goals) {
192
- if (!goal.name) {
193
- errors.push('Goal name is required');
194
- }
195
- if (goal.progress && (goal.progress < 0 || goal.progress > 100)) {
196
- errors.push(`Goal ${goal.name} progress must be between 0 and 100`);
197
- }
198
- if (goal.dependencies) {
199
- const goalNames = new Set(goals.map(g => g.name));
200
- for (const dep of goal.dependencies) {
201
- if (!goalNames.has(dep)) {
202
- errors.push(`Goal ${goal.name} depends on unknown goal: ${dep}`);
203
- }
204
- }
205
- }
206
- }
207
- if (hasCircularDependencies(goals)) {
208
- errors.push('Circular dependencies detected in goals');
209
- }
210
- return {
211
- valid: errors.length === 0,
212
- errors,
213
- };
214
- }
package/src/index.js DELETED
@@ -1,131 +0,0 @@
1
- /**
2
- * business-as-code - Primitives for expressing business logic and processes as code
3
- *
4
- * This package provides primitives for defining business entities, goals, products,
5
- * services, processes, workflows, KPIs, OKRs, and financial metrics.
6
- *
7
- * @example
8
- * ```ts
9
- * import { Business, Product, Goals, kpis, okrs, financials, $ } from 'business-as-code'
10
- *
11
- * // Define your business
12
- * const company = Business({
13
- * name: 'Acme Corp',
14
- * mission: 'To make widgets accessible to everyone',
15
- * values: ['Innovation', 'Customer Focus', 'Integrity'],
16
- * })
17
- *
18
- * // Define products
19
- * const product = Product({
20
- * name: 'Widget Pro',
21
- * pricingModel: 'subscription',
22
- * price: 99,
23
- * cogs: 20,
24
- * })
25
- *
26
- * // Define goals
27
- * const goals = Goals([
28
- * {
29
- * name: 'Launch MVP',
30
- * category: 'strategic',
31
- * status: 'in-progress',
32
- * progress: 65,
33
- * },
34
- * ])
35
- *
36
- * // Track KPIs
37
- * const kpiList = kpis([
38
- * {
39
- * name: 'Monthly Recurring Revenue',
40
- * category: 'financial',
41
- * target: 100000,
42
- * current: 85000,
43
- * },
44
- * ])
45
- *
46
- * // Define OKRs
47
- * const okrList = okrs([
48
- * {
49
- * objective: 'Achieve Product-Market Fit',
50
- * keyResults: [
51
- * {
52
- * description: 'Increase NPS',
53
- * metric: 'NPS',
54
- * targetValue: 60,
55
- * currentValue: 52,
56
- * },
57
- * ],
58
- * },
59
- * ])
60
- *
61
- * // Calculate financials
62
- * const metrics = financials({
63
- * revenue: 1000000,
64
- * cogs: 300000,
65
- * operatingExpenses: 500000,
66
- * })
67
- *
68
- * // Use $ helper for calculations
69
- * console.log($.format(1234.56)) // "$1,234.56"
70
- * console.log($.growth(120, 100)) // 20
71
- * console.log($.margin(100, 60)) // 40
72
- * ```
73
- *
74
- * @packageDocumentation
75
- */
76
- // Export business entity functions
77
- export { Business, getTotalBudget, getTotalTeamSize, getDepartment, getTeam, validateBusiness, } from './business.js';
78
- // Export vision functions
79
- export { Vision, checkIndicator, calculateProgress, validateVision, } from './vision.js';
80
- // Export goal functions
81
- export { Goals, Goal, updateProgress, markAtRisk, complete, isOverdue, getGoalsByCategory, getGoalsByStatus, getGoalsByOwner, calculateOverallProgress, hasCircularDependencies, sortByDependencies, validateGoals, } from './goals.js';
82
- // Export product functions
83
- export { Product, calculateGrossMargin, calculateGrossProfit, getRoadmapByStatus, getRoadmapByPriority, getOverdueRoadmapItems, updateRoadmapItem, addFeature, removeFeature, validateProduct, } from './product.js';
84
- // Export service functions
85
- export { Service, calculateHourlyPrice, calculateMonthlyRetainer, checkSLAUptime, parseDeliveryTimeToDays, estimateCompletionDate, calculateValueBasedPrice, validateService, } from './service.js';
86
- // Export process functions
87
- export { Process, getStepsInOrder, getStepsByAutomationLevel, calculateTotalDuration, formatDuration, calculateAutomationPercentage, getMetric, meetsTarget, calculateMetricAchievement, updateMetric, addStep, removeStep, validateProcess, } from './process.js';
88
- // Export workflow functions
89
- export { Workflow, getActionsInOrder, getActionsByType, getConditionalActions, addAction, removeAction, updateAction, isEventTrigger, isScheduleTrigger, isWebhookTrigger, parseWaitDuration, evaluateCondition, fillTemplate, validateWorkflow, } from './workflow.js';
90
- // Export KPI functions
91
- export { kpis, kpi, calculateAchievement, meetsTarget as kpiMeetsTarget, updateCurrent, updateTarget, getKPIsByCategory, getKPIsByFrequency, getKPIsOnTarget, getKPIsOffTarget, calculateHealthScore, groupByCategory, calculateVariance, calculateVariancePercentage, formatValue, comparePerformance, validateKPIs, } from './kpis.js';
92
- // Export OKR functions
93
- export { okrs, okr, calculateKeyResultProgress, calculateOKRProgress, calculateConfidence, updateKeyResult, isKeyResultOnTrack, isOKROnTrack, getKeyResultsOnTrack, getKeyResultsAtRisk, getOKRsByOwner, getOKRsByPeriod, getOKRsByStatus, calculateSuccessRate, formatKeyResult, compareOKRPerformance, validateOKRs, } from './okrs.js';
94
- // Export financial functions
95
- export { financials, calculateGrossMargin as calculateFinancialGrossMargin, calculateOperatingMargin, calculateNetMargin, calculateEBITDAMargin, calculateBurnRate, calculateRunway, calculateCAC, calculateLTV, calculateLTVtoCAC, calculatePaybackPeriod, calculateARR, calculateMRR, calculateGrowthRate, calculateCAGR, calculateROI, calculateROE, calculateROA, calculateQuickRatio, calculateCurrentRatio, calculateDebtToEquity, formatCurrency, createStatement, getLineItem, compareMetrics, validateFinancials, } from './financials.js';
96
- // Export $ helper and context management
97
- export { $, createBusinessOperations, updateContext, getContext, resetContext, } from './dollar.js';
98
- export {
99
- // SaaS Metric Calculation functions (produce structured SaaS metric objects)
100
- calculateMRR as calculateMRRMetric, calculateARRFromMRR as calculateARRMetric, calculateNRR as calculateNRRMetric, calculateGRR as calculateGRRMetric, calculateCACMetric, calculateLTVMetric, calculateLTVtoCACRatio, calculateQuickRatioMetric, calculateMagicNumberMetric, calculateBurnMultipleMetric, calculateRuleOf40Metric, calculateGrowthRates, calculateChurnMetrics,
101
- // Time-series aggregation
102
- aggregateTimeSeries, createMetricPeriod, } from './metrics.js';
103
- export {
104
- // Standard definitions
105
- StandardDimensions, StandardMeasures, CalculatedMetrics,
106
- // Builders
107
- query, QueryBuilder, view, ViewBuilder, dashboard, DashboardBuilder,
108
- // Pre-built queries
109
- MrrOverview, ArrBySegment, CohortRetention, UnitEconomics, RevenueByChannel, GrowthMetrics,
110
- // Pre-built dashboards
111
- ExecutiveDashboard, } from './queries.js';
112
- export { StandardBusinessRoles, createBusinessRole, hasPermission, canHandleTask, canApproveRequest, canDelegateTask, findRoleForTask, createTaskAssignment, transitionTaskStatus, } from './roles.js';
113
- export { resolvePermissions, getApprovalChainForRequest, findManager, } from './organization.js';
114
- // =============================================================================
115
- // Entity Definitions (Noun pattern with Properties, Actions, Events)
116
- // =============================================================================
117
- export {
118
- // Business
119
- Business as BusinessEntity, Vision as VisionEntity, Value as ValueEntity, BusinessEntities, BusinessCategories,
120
- // Organization
121
- Organization as OrganizationEntity, Department as DepartmentEntity, Team as TeamEntity, Position as PositionEntity, Role as RoleEntity, Worker as WorkerEntity, OrganizationEntities, OrganizationCategories,
122
- // Goals
123
- Goal as GoalEntity, OKR as OKREntity, KeyResult as KeyResultEntity, KPI as KPIEntity, Metric as MetricEntity, Initiative as InitiativeEntity, GoalEntities, GoalCategories,
124
- // Offerings
125
- Product as ProductEntity, Service as ServiceEntity, Feature as FeatureEntity, PricingPlan as PricingPlanEntity, RoadmapItem as RoadmapItemEntity, OfferingEntities, OfferingCategories,
126
- // Operations
127
- Process as ProcessEntity, ProcessStep as ProcessStepEntity, Workflow as WorkflowEntity, WorkflowAction as WorkflowActionEntity, WorkflowRun as WorkflowRunEntity, Policy as PolicyEntity, OperationsEntities, OperationsCategories,
128
- // Financials
129
- Budget as BudgetEntity, Revenue as RevenueEntity, Expense as ExpenseEntity, Investment as InvestmentEntity, FinancialPeriod as FinancialPeriodEntity, Forecast as ForecastEntity, FinancialEntities, FinancialCategories,
130
- // All
131
- AllBusinessEntities, BusinessEntityCategories, Entities, } from './entities/index.js';