business-as-code 0.2.1 → 2.0.1

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 +9 -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
package/src/okrs.ts ADDED
@@ -0,0 +1,325 @@
1
+ /**
2
+ * Objectives and Key Results (OKRs) management
3
+ */
4
+
5
+ import type { OKRDefinition, KeyResult } from './types.js'
6
+
7
+ /**
8
+ * Define Objectives and Key Results for goal tracking
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const quarterlyOKRs = okrs([
13
+ * {
14
+ * objective: 'Achieve Product-Market Fit',
15
+ * description: 'Validate that our product solves a real problem for customers',
16
+ * period: 'Q2 2024',
17
+ * owner: 'CEO',
18
+ * keyResults: [
19
+ * {
20
+ * description: 'Increase Net Promoter Score',
21
+ * metric: 'NPS',
22
+ * startValue: 40,
23
+ * targetValue: 60,
24
+ * currentValue: 52,
25
+ * unit: 'score',
26
+ * progress: 60,
27
+ * },
28
+ * {
29
+ * description: 'Reduce monthly churn rate',
30
+ * metric: 'Churn Rate',
31
+ * startValue: 8,
32
+ * targetValue: 4,
33
+ * currentValue: 5.5,
34
+ * unit: 'percent',
35
+ * progress: 62.5,
36
+ * },
37
+ * {
38
+ * description: 'Achieve customer retention',
39
+ * metric: 'Customers with 3+ months',
40
+ * startValue: 50,
41
+ * targetValue: 200,
42
+ * currentValue: 125,
43
+ * unit: 'customers',
44
+ * progress: 50,
45
+ * },
46
+ * ],
47
+ * status: 'on-track',
48
+ * confidence: 75,
49
+ * },
50
+ * ])
51
+ * ```
52
+ */
53
+ export function okrs(definitions: OKRDefinition[]): OKRDefinition[] {
54
+ return definitions.map(okr => validateAndNormalizeOKR(okr))
55
+ }
56
+
57
+ /**
58
+ * Define a single OKR
59
+ */
60
+ export function okr(definition: OKRDefinition): OKRDefinition {
61
+ return validateAndNormalizeOKR(definition)
62
+ }
63
+
64
+ /**
65
+ * Validate and normalize an OKR definition
66
+ */
67
+ function validateAndNormalizeOKR(okr: OKRDefinition): OKRDefinition {
68
+ if (!okr.objective) {
69
+ throw new Error('OKR objective is required')
70
+ }
71
+
72
+ // Calculate progress for key results if not set
73
+ const keyResults = okr.keyResults?.map(kr => ({
74
+ ...kr,
75
+ progress: kr.progress ?? calculateKeyResultProgress(kr),
76
+ }))
77
+
78
+ return {
79
+ ...okr,
80
+ keyResults,
81
+ status: okr.status || 'not-started',
82
+ confidence: okr.confidence ?? calculateConfidence(keyResults || []),
83
+ metadata: okr.metadata || {},
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Calculate key result progress
89
+ */
90
+ export function calculateKeyResultProgress(kr: KeyResult): number {
91
+ if (kr.currentValue === undefined || kr.startValue === undefined) return 0
92
+
93
+ const total = kr.targetValue - kr.startValue
94
+ if (total === 0) return 100
95
+
96
+ const current = kr.currentValue - kr.startValue
97
+ const progress = (current / total) * 100
98
+
99
+ return Math.max(0, Math.min(100, progress))
100
+ }
101
+
102
+ /**
103
+ * Calculate overall OKR progress
104
+ */
105
+ export function calculateOKRProgress(okr: OKRDefinition): number {
106
+ if (!okr.keyResults || okr.keyResults.length === 0) return 0
107
+
108
+ const totalProgress = okr.keyResults.reduce((sum, kr) => {
109
+ return sum + (kr.progress ?? calculateKeyResultProgress(kr))
110
+ }, 0)
111
+
112
+ return totalProgress / okr.keyResults.length
113
+ }
114
+
115
+ /**
116
+ * Calculate confidence score based on key results
117
+ */
118
+ export function calculateConfidence(keyResults: KeyResult[]): number {
119
+ if (keyResults.length === 0) return 0
120
+
121
+ const totalProgress = keyResults.reduce((sum, kr) => {
122
+ return sum + (kr.progress ?? calculateKeyResultProgress(kr))
123
+ }, 0)
124
+
125
+ const avgProgress = totalProgress / keyResults.length
126
+
127
+ // Confidence tends to be slightly lower than actual progress
128
+ return Math.max(0, Math.min(100, avgProgress - 10))
129
+ }
130
+
131
+ /**
132
+ * Update key result current value
133
+ */
134
+ export function updateKeyResult(
135
+ okr: OKRDefinition,
136
+ krDescription: string,
137
+ currentValue: number
138
+ ): OKRDefinition {
139
+ const keyResults = okr.keyResults?.map(kr => {
140
+ if (kr.description === krDescription) {
141
+ const updatedKR = { ...kr, currentValue }
142
+ return {
143
+ ...updatedKR,
144
+ progress: calculateKeyResultProgress(updatedKR),
145
+ }
146
+ }
147
+ return kr
148
+ })
149
+
150
+ // Recalculate overall status and confidence
151
+ const progress = calculateOKRProgress({ ...okr, keyResults })
152
+ const status = determineOKRStatus(progress, okr.confidence || 0)
153
+
154
+ return {
155
+ ...okr,
156
+ keyResults,
157
+ status,
158
+ confidence: calculateConfidence(keyResults || []),
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Determine OKR status based on progress and confidence
164
+ */
165
+ function determineOKRStatus(
166
+ progress: number,
167
+ confidence: number
168
+ ): OKRDefinition['status'] {
169
+ if (progress === 0) return 'not-started'
170
+ if (progress === 100) return 'completed'
171
+ if (confidence < 50 || progress < 30) return 'at-risk'
172
+ return 'on-track'
173
+ }
174
+
175
+ /**
176
+ * Check if key result is on track
177
+ */
178
+ export function isKeyResultOnTrack(kr: KeyResult): boolean {
179
+ const progress = kr.progress ?? calculateKeyResultProgress(kr)
180
+ return progress >= 70
181
+ }
182
+
183
+ /**
184
+ * Check if OKR is on track
185
+ */
186
+ export function isOKROnTrack(okr: OKRDefinition): boolean {
187
+ const progress = calculateOKRProgress(okr)
188
+ return progress >= 70 && (okr.confidence ?? 0) >= 60
189
+ }
190
+
191
+ /**
192
+ * Get key results that are on track
193
+ */
194
+ export function getKeyResultsOnTrack(okr: OKRDefinition): KeyResult[] {
195
+ return okr.keyResults?.filter(isKeyResultOnTrack) || []
196
+ }
197
+
198
+ /**
199
+ * Get key results that are at risk
200
+ */
201
+ export function getKeyResultsAtRisk(okr: OKRDefinition): KeyResult[] {
202
+ return okr.keyResults?.filter(kr => !isKeyResultOnTrack(kr)) || []
203
+ }
204
+
205
+ /**
206
+ * Get OKRs by owner
207
+ */
208
+ export function getOKRsByOwner(okrs: OKRDefinition[], owner: string): OKRDefinition[] {
209
+ return okrs.filter(okr => okr.owner === owner)
210
+ }
211
+
212
+ /**
213
+ * Get OKRs by period
214
+ */
215
+ export function getOKRsByPeriod(okrs: OKRDefinition[], period: string): OKRDefinition[] {
216
+ return okrs.filter(okr => okr.period === period)
217
+ }
218
+
219
+ /**
220
+ * Get OKRs by status
221
+ */
222
+ export function getOKRsByStatus(
223
+ okrs: OKRDefinition[],
224
+ status: OKRDefinition['status']
225
+ ): OKRDefinition[] {
226
+ return okrs.filter(okr => okr.status === status)
227
+ }
228
+
229
+ /**
230
+ * Calculate success rate across all OKRs
231
+ */
232
+ export function calculateSuccessRate(okrs: OKRDefinition[]): number {
233
+ if (okrs.length === 0) return 0
234
+
235
+ const avgProgress = okrs.reduce((sum, okr) => {
236
+ return sum + calculateOKRProgress(okr)
237
+ }, 0) / okrs.length
238
+
239
+ return avgProgress
240
+ }
241
+
242
+ /**
243
+ * Format key result for display
244
+ */
245
+ export function formatKeyResult(kr: KeyResult): string {
246
+ const progress = kr.progress ?? calculateKeyResultProgress(kr)
247
+ const current = kr.currentValue ?? kr.startValue ?? 0
248
+ const target = kr.targetValue
249
+
250
+ return `${kr.description}: ${current}/${target} ${kr.unit || ''} (${progress.toFixed(0)}%)`
251
+ }
252
+
253
+ /**
254
+ * Compare OKR performance between periods
255
+ */
256
+ export function compareOKRPerformance(
257
+ current: OKRDefinition,
258
+ previous: OKRDefinition
259
+ ): {
260
+ progressDelta: number
261
+ confidenceDelta: number
262
+ improved: boolean
263
+ } {
264
+ const currentProgress = calculateOKRProgress(current)
265
+ const previousProgress = calculateOKRProgress(previous)
266
+ const progressDelta = currentProgress - previousProgress
267
+
268
+ const currentConfidence = current.confidence ?? 0
269
+ const previousConfidence = previous.confidence ?? 0
270
+ const confidenceDelta = currentConfidence - previousConfidence
271
+
272
+ const improved = progressDelta > 0 && confidenceDelta >= 0
273
+
274
+ return { progressDelta, confidenceDelta, improved }
275
+ }
276
+
277
+ /**
278
+ * Validate OKR definitions
279
+ */
280
+ export function validateOKRs(okrs: OKRDefinition[]): { valid: boolean; errors: string[] } {
281
+ const errors: string[] = []
282
+
283
+ for (const okr of okrs) {
284
+ if (!okr.objective) {
285
+ errors.push('OKR objective is required')
286
+ }
287
+
288
+ if (okr.objective && okr.objective.length < 10) {
289
+ errors.push(`OKR objective "${okr.objective}" should be at least 10 characters`)
290
+ }
291
+
292
+ if (okr.confidence !== undefined && (okr.confidence < 0 || okr.confidence > 100)) {
293
+ errors.push(`OKR "${okr.objective}" confidence must be between 0 and 100`)
294
+ }
295
+
296
+ if (okr.keyResults) {
297
+ if (okr.keyResults.length === 0) {
298
+ errors.push(`OKR "${okr.objective}" must have at least one key result`)
299
+ }
300
+
301
+ if (okr.keyResults.length > 5) {
302
+ errors.push(`OKR "${okr.objective}" should have no more than 5 key results`)
303
+ }
304
+
305
+ for (const kr of okr.keyResults) {
306
+ if (!kr.description) {
307
+ errors.push(`Key result in OKR "${okr.objective}" must have a description`)
308
+ }
309
+
310
+ if (!kr.metric) {
311
+ errors.push(`Key result "${kr.description}" must have a metric`)
312
+ }
313
+
314
+ if (kr.progress !== undefined && (kr.progress < 0 || kr.progress > 100)) {
315
+ errors.push(`Key result "${kr.description}" progress must be between 0 and 100`)
316
+ }
317
+ }
318
+ }
319
+ }
320
+
321
+ return {
322
+ valid: errors.length === 0,
323
+ errors,
324
+ }
325
+ }