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
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# business-as-code
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
Primitives for expressing business logic, strategy, and operations as code. Define your entire business model—from vision and goals to products, services, processes, KPIs, OKRs, and financials—in a declarative, type-safe way.
|
|
4
6
|
|
|
5
7
|
## Installation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "business-as-code",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Primitives for expressing business logic and processes as code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,23 +11,26 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"dev": "tsc --watch",
|
|
17
|
+
"test": "vitest run",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint .",
|
|
20
|
+
"clean": "rm -rf dist"
|
|
21
|
+
},
|
|
14
22
|
"dependencies": {
|
|
15
|
-
"ai-database": "2.
|
|
16
|
-
"ai-functions": "2.
|
|
23
|
+
"ai-database": "2.3.0",
|
|
24
|
+
"ai-functions": "2.3.0",
|
|
25
|
+
"digital-workers": "2.3.0",
|
|
26
|
+
"org.ai": "0.0.1"
|
|
17
27
|
},
|
|
28
|
+
"devDependencies": {},
|
|
18
29
|
"keywords": [
|
|
19
30
|
"business",
|
|
20
31
|
"logic",
|
|
21
32
|
"code",
|
|
22
33
|
"primitives"
|
|
23
34
|
],
|
|
24
|
-
"license": "MIT"
|
|
25
|
-
|
|
26
|
-
"build": "tsc",
|
|
27
|
-
"dev": "tsc --watch",
|
|
28
|
-
"test": "vitest",
|
|
29
|
-
"typecheck": "tsc --noEmit",
|
|
30
|
-
"lint": "eslint .",
|
|
31
|
-
"clean": "rm -rf dist"
|
|
32
|
-
}
|
|
33
|
-
}
|
|
35
|
+
"license": "MIT"
|
|
36
|
+
}
|
package/src/dollar.ts
CHANGED
|
@@ -57,7 +57,10 @@ export function createBusinessOperations(initialContext?: BusinessContext): Busi
|
|
|
57
57
|
|
|
58
58
|
return {
|
|
59
59
|
format: (amount: number, currency?: Currency) => {
|
|
60
|
-
return formatCurrency(
|
|
60
|
+
return formatCurrency(
|
|
61
|
+
amount,
|
|
62
|
+
currency || (context.business?.metadata?.['currency'] as Currency) || 'USD'
|
|
63
|
+
)
|
|
61
64
|
},
|
|
62
65
|
|
|
63
66
|
percent: (value: number, total: number) => {
|
|
@@ -126,7 +129,7 @@ export function getContext(): BusinessContext {
|
|
|
126
129
|
* Reset business context
|
|
127
130
|
*/
|
|
128
131
|
export function resetContext(): void {
|
|
129
|
-
Object.keys($.context).forEach(key => {
|
|
132
|
+
Object.keys($.context).forEach((key) => {
|
|
130
133
|
delete $.context[key]
|
|
131
134
|
})
|
|
132
135
|
}
|
|
@@ -3,10 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Organizational hierarchy: Organization, Department, Team, Position, Role.
|
|
5
5
|
*
|
|
6
|
+
* Uses digital-workers Worker type for position holders.
|
|
7
|
+
*
|
|
6
8
|
* @packageDocumentation
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
import type { Noun } from 'ai-database'
|
|
12
|
+
import type { Worker as DigitalWorker, WorkerRef } from 'digital-workers'
|
|
13
|
+
|
|
14
|
+
// Re-export for convenience
|
|
15
|
+
export type { DigitalWorker, WorkerRef }
|
|
10
16
|
|
|
11
17
|
// =============================================================================
|
|
12
18
|
// Organization
|
|
@@ -109,23 +115,9 @@ export const Organization: Noun = {
|
|
|
109
115
|
},
|
|
110
116
|
},
|
|
111
117
|
|
|
112
|
-
actions: [
|
|
113
|
-
'create',
|
|
114
|
-
'update',
|
|
115
|
-
'restructure',
|
|
116
|
-
'merge',
|
|
117
|
-
'split',
|
|
118
|
-
'archive',
|
|
119
|
-
],
|
|
118
|
+
actions: ['create', 'update', 'restructure', 'merge', 'split', 'archive'],
|
|
120
119
|
|
|
121
|
-
events: [
|
|
122
|
-
'created',
|
|
123
|
-
'updated',
|
|
124
|
-
'restructured',
|
|
125
|
-
'merged',
|
|
126
|
-
'split',
|
|
127
|
-
'archived',
|
|
128
|
-
],
|
|
120
|
+
events: ['created', 'updated', 'restructured', 'merged', 'split', 'archived'],
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
// =============================================================================
|
|
@@ -164,7 +156,18 @@ export const Department: Noun = {
|
|
|
164
156
|
type: 'string',
|
|
165
157
|
optional: true,
|
|
166
158
|
description: 'Department type',
|
|
167
|
-
examples: [
|
|
159
|
+
examples: [
|
|
160
|
+
'engineering',
|
|
161
|
+
'product',
|
|
162
|
+
'design',
|
|
163
|
+
'marketing',
|
|
164
|
+
'sales',
|
|
165
|
+
'operations',
|
|
166
|
+
'finance',
|
|
167
|
+
'hr',
|
|
168
|
+
'legal',
|
|
169
|
+
'support',
|
|
170
|
+
],
|
|
168
171
|
},
|
|
169
172
|
|
|
170
173
|
// Budget
|
|
@@ -440,7 +443,17 @@ export const Position: Noun = {
|
|
|
440
443
|
type: 'string',
|
|
441
444
|
optional: true,
|
|
442
445
|
description: 'Job level',
|
|
443
|
-
examples: [
|
|
446
|
+
examples: [
|
|
447
|
+
'intern',
|
|
448
|
+
'junior',
|
|
449
|
+
'mid',
|
|
450
|
+
'senior',
|
|
451
|
+
'staff',
|
|
452
|
+
'principal',
|
|
453
|
+
'director',
|
|
454
|
+
'vp',
|
|
455
|
+
'c-level',
|
|
456
|
+
],
|
|
444
457
|
},
|
|
445
458
|
track: {
|
|
446
459
|
type: 'string',
|
package/src/goals.ts
CHANGED
|
@@ -1,8 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Business goals definition and tracking
|
|
3
|
+
*
|
|
4
|
+
* Uses org.ai Goal types for standardized goal definitions across the ecosystem.
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
import type { GoalDefinition } from './types.js'
|
|
8
|
+
import type {
|
|
9
|
+
Goal as OrgGoal,
|
|
10
|
+
Goals as OrgGoals,
|
|
11
|
+
GoalStatus,
|
|
12
|
+
GoalCategory,
|
|
13
|
+
GoalPriority,
|
|
14
|
+
} from 'org.ai'
|
|
15
|
+
|
|
16
|
+
// Re-export org.ai goal types for convenience
|
|
17
|
+
export type { OrgGoal, OrgGoals, GoalStatus, GoalCategory, GoalPriority }
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Convert a business-as-code GoalDefinition to an org.ai Goal
|
|
21
|
+
*
|
|
22
|
+
* @param definition - Business goal definition
|
|
23
|
+
* @param id - Unique identifier for the goal
|
|
24
|
+
* @returns org.ai Goal object
|
|
25
|
+
*/
|
|
26
|
+
export function toOrgGoal(definition: GoalDefinition, id: string): OrgGoal {
|
|
27
|
+
const result: OrgGoal = {
|
|
28
|
+
id,
|
|
29
|
+
name: definition.name,
|
|
30
|
+
description: definition.description || definition.name,
|
|
31
|
+
target: 100,
|
|
32
|
+
progress: definition.progress || 0,
|
|
33
|
+
status: definition.status || 'not-started',
|
|
34
|
+
}
|
|
35
|
+
if (definition.targetDate) {
|
|
36
|
+
result.targetDate = definition.targetDate
|
|
37
|
+
result.deadline = definition.targetDate
|
|
38
|
+
}
|
|
39
|
+
if (definition.owner) result.owner = definition.owner
|
|
40
|
+
if (definition.category) result.category = definition.category
|
|
41
|
+
if (definition.metrics) result.metrics = definition.metrics
|
|
42
|
+
if (definition.dependencies) result.dependencies = definition.dependencies
|
|
43
|
+
if (definition.metadata) result.metadata = definition.metadata
|
|
44
|
+
return result
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Convert an org.ai Goal to a business-as-code GoalDefinition
|
|
49
|
+
*
|
|
50
|
+
* @param goal - org.ai Goal object
|
|
51
|
+
* @returns Business goal definition
|
|
52
|
+
*/
|
|
53
|
+
export function fromOrgGoal(goal: OrgGoal): GoalDefinition {
|
|
54
|
+
const result: GoalDefinition = {
|
|
55
|
+
name: goal.name,
|
|
56
|
+
progress: typeof goal.progress === 'number' ? goal.progress : 0,
|
|
57
|
+
}
|
|
58
|
+
if (goal.description) result.description = goal.description
|
|
59
|
+
const cat = goal.category
|
|
60
|
+
if (cat) result.category = cat as NonNullable<GoalDefinition['category']>
|
|
61
|
+
if (goal.targetDate) result.targetDate = goal.targetDate
|
|
62
|
+
else if (goal.deadline) result.targetDate = goal.deadline
|
|
63
|
+
if (goal.owner) result.owner = goal.owner
|
|
64
|
+
if (goal.metrics) result.metrics = goal.metrics
|
|
65
|
+
const st = goal.status
|
|
66
|
+
if (st) result.status = st as NonNullable<GoalDefinition['status']>
|
|
67
|
+
if (goal.dependencies) result.dependencies = goal.dependencies
|
|
68
|
+
if (goal.metadata) result.metadata = goal.metadata
|
|
69
|
+
return result
|
|
70
|
+
}
|
|
6
71
|
|
|
7
72
|
/**
|
|
8
73
|
* Define a business goal with metrics and tracking
|
|
@@ -35,7 +100,7 @@ import type { GoalDefinition } from './types.js'
|
|
|
35
100
|
* ```
|
|
36
101
|
*/
|
|
37
102
|
export function Goals(definitions: GoalDefinition[]): GoalDefinition[] {
|
|
38
|
-
return definitions.map(goal => validateAndNormalizeGoal(goal))
|
|
103
|
+
return definitions.map((goal) => validateAndNormalizeGoal(goal))
|
|
39
104
|
}
|
|
40
105
|
|
|
41
106
|
/**
|
|
@@ -73,20 +138,21 @@ export function updateProgress(goal: GoalDefinition, progress: number): GoalDefi
|
|
|
73
138
|
}
|
|
74
139
|
|
|
75
140
|
// Auto-update status based on progress
|
|
76
|
-
let status
|
|
141
|
+
let status: GoalDefinition['status']
|
|
77
142
|
if (progress === 0) {
|
|
78
143
|
status = 'not-started'
|
|
79
144
|
} else if (progress === 100) {
|
|
80
145
|
status = 'completed'
|
|
81
|
-
} else
|
|
146
|
+
} else {
|
|
82
147
|
status = 'in-progress'
|
|
83
148
|
}
|
|
84
149
|
|
|
85
|
-
|
|
150
|
+
const result: GoalDefinition = {
|
|
86
151
|
...goal,
|
|
87
152
|
progress,
|
|
88
|
-
status,
|
|
89
153
|
}
|
|
154
|
+
if (status !== undefined) result.status = status
|
|
155
|
+
return result
|
|
90
156
|
}
|
|
91
157
|
|
|
92
158
|
/**
|
|
@@ -125,7 +191,7 @@ export function getGoalsByCategory(
|
|
|
125
191
|
goals: GoalDefinition[],
|
|
126
192
|
category: GoalDefinition['category']
|
|
127
193
|
): GoalDefinition[] {
|
|
128
|
-
return goals.filter(g => g.category === category)
|
|
194
|
+
return goals.filter((g) => g.category === category)
|
|
129
195
|
}
|
|
130
196
|
|
|
131
197
|
/**
|
|
@@ -135,14 +201,14 @@ export function getGoalsByStatus(
|
|
|
135
201
|
goals: GoalDefinition[],
|
|
136
202
|
status: GoalDefinition['status']
|
|
137
203
|
): GoalDefinition[] {
|
|
138
|
-
return goals.filter(g => g.status === status)
|
|
204
|
+
return goals.filter((g) => g.status === status)
|
|
139
205
|
}
|
|
140
206
|
|
|
141
207
|
/**
|
|
142
208
|
* Get goals by owner
|
|
143
209
|
*/
|
|
144
210
|
export function getGoalsByOwner(goals: GoalDefinition[], owner: string): GoalDefinition[] {
|
|
145
|
-
return goals.filter(g => g.owner === owner)
|
|
211
|
+
return goals.filter((g) => g.owner === owner)
|
|
146
212
|
}
|
|
147
213
|
|
|
148
214
|
/**
|
|
@@ -159,7 +225,7 @@ export function calculateOverallProgress(goals: GoalDefinition[]): number {
|
|
|
159
225
|
* Check for circular dependencies
|
|
160
226
|
*/
|
|
161
227
|
export function hasCircularDependencies(goals: GoalDefinition[]): boolean {
|
|
162
|
-
const goalMap = new Map(goals.map(g => [g.name, g]))
|
|
228
|
+
const goalMap = new Map(goals.map((g) => [g.name, g]))
|
|
163
229
|
|
|
164
230
|
function checkCircular(goalName: string, visited = new Set<string>()): boolean {
|
|
165
231
|
if (visited.has(goalName)) return true
|
|
@@ -178,14 +244,14 @@ export function hasCircularDependencies(goals: GoalDefinition[]): boolean {
|
|
|
178
244
|
return false
|
|
179
245
|
}
|
|
180
246
|
|
|
181
|
-
return goals.some(goal => checkCircular(goal.name))
|
|
247
|
+
return goals.some((goal) => checkCircular(goal.name))
|
|
182
248
|
}
|
|
183
249
|
|
|
184
250
|
/**
|
|
185
251
|
* Get goals in dependency order
|
|
186
252
|
*/
|
|
187
253
|
export function sortByDependencies(goals: GoalDefinition[]): GoalDefinition[] {
|
|
188
|
-
const goalMap = new Map(goals.map(g => [g.name, g]))
|
|
254
|
+
const goalMap = new Map(goals.map((g) => [g.name, g]))
|
|
189
255
|
const sorted: GoalDefinition[] = []
|
|
190
256
|
const visited = new Set<string>()
|
|
191
257
|
|
|
@@ -230,7 +296,7 @@ export function validateGoals(goals: GoalDefinition[]): { valid: boolean; errors
|
|
|
230
296
|
}
|
|
231
297
|
|
|
232
298
|
if (goal.dependencies) {
|
|
233
|
-
const goalNames = new Set(goals.map(g => g.name))
|
|
299
|
+
const goalNames = new Set(goals.map((g) => g.name))
|
|
234
300
|
for (const dep of goal.dependencies) {
|
|
235
301
|
if (!goalNames.has(dep)) {
|
|
236
302
|
errors.push(`Goal ${goal.name} depends on unknown goal: ${dep}`)
|
package/src/index.ts
CHANGED
|
@@ -114,12 +114,7 @@ export {
|
|
|
114
114
|
} from './business.js'
|
|
115
115
|
|
|
116
116
|
// Export vision functions
|
|
117
|
-
export {
|
|
118
|
-
Vision,
|
|
119
|
-
checkIndicator,
|
|
120
|
-
calculateProgress,
|
|
121
|
-
validateVision,
|
|
122
|
-
} from './vision.js'
|
|
117
|
+
export { Vision, checkIndicator, calculateProgress, validateVision } from './vision.js'
|
|
123
118
|
|
|
124
119
|
// Export goal functions
|
|
125
120
|
export {
|
|
@@ -136,6 +131,22 @@ export {
|
|
|
136
131
|
hasCircularDependencies,
|
|
137
132
|
sortByDependencies,
|
|
138
133
|
validateGoals,
|
|
134
|
+
// org.ai conversions
|
|
135
|
+
toOrgGoal,
|
|
136
|
+
fromOrgGoal,
|
|
137
|
+
} from './goals.js'
|
|
138
|
+
|
|
139
|
+
// Re-export org.ai goal types
|
|
140
|
+
export type {
|
|
141
|
+
OrgGoal,
|
|
142
|
+
OrgGoals,
|
|
143
|
+
GoalStatus,
|
|
144
|
+
GoalCategory,
|
|
145
|
+
GoalPriority,
|
|
146
|
+
// Aliased versions for backward compatibility
|
|
147
|
+
GoalStatus as OrgGoalStatus,
|
|
148
|
+
GoalCategory as OrgGoalCategory,
|
|
149
|
+
GoalPriority as OrgGoalPriority,
|
|
139
150
|
} from './goals.js'
|
|
140
151
|
|
|
141
152
|
// Export product functions
|
|
@@ -218,8 +229,14 @@ export {
|
|
|
218
229
|
formatValue,
|
|
219
230
|
comparePerformance,
|
|
220
231
|
validateKPIs,
|
|
232
|
+
// org.ai conversions
|
|
233
|
+
toOrgKPI,
|
|
234
|
+
fromOrgKPI,
|
|
221
235
|
} from './kpis.js'
|
|
222
236
|
|
|
237
|
+
// Re-export org.ai KPI types
|
|
238
|
+
export type { OrgKPI, KPICategory, KPITrend, KPIFrequency, KPIHistoryEntry } from './kpis.js'
|
|
239
|
+
|
|
223
240
|
// Export OKR functions
|
|
224
241
|
export {
|
|
225
242
|
okrs,
|
|
@@ -239,8 +256,16 @@ export {
|
|
|
239
256
|
formatKeyResult,
|
|
240
257
|
compareOKRPerformance,
|
|
241
258
|
validateOKRs,
|
|
259
|
+
// org.ai conversions
|
|
260
|
+
toOrgOKR,
|
|
261
|
+
fromOrgOKR,
|
|
262
|
+
toOrgKeyResult,
|
|
263
|
+
fromOrgKeyResult,
|
|
242
264
|
} from './okrs.js'
|
|
243
265
|
|
|
266
|
+
// Re-export org.ai OKR types
|
|
267
|
+
export type { OrgOKR, OrgKeyResult, OKRStatus, KeyResultStatus } from './okrs.js'
|
|
268
|
+
|
|
244
269
|
// Export financial functions
|
|
245
270
|
export {
|
|
246
271
|
financials,
|
|
@@ -272,13 +297,7 @@ export {
|
|
|
272
297
|
} from './financials.js'
|
|
273
298
|
|
|
274
299
|
// Export $ helper and context management
|
|
275
|
-
export {
|
|
276
|
-
$,
|
|
277
|
-
createBusinessOperations,
|
|
278
|
-
updateContext,
|
|
279
|
-
getContext,
|
|
280
|
-
resetContext,
|
|
281
|
-
} from './dollar.js'
|
|
300
|
+
export { $, createBusinessOperations, updateContext, getContext, resetContext } from './dollar.js'
|
|
282
301
|
|
|
283
302
|
// Export SaaS metrics
|
|
284
303
|
export type {
|
|
@@ -419,8 +438,15 @@ export type {
|
|
|
419
438
|
AssigneeRef,
|
|
420
439
|
TaskRoutingRule,
|
|
421
440
|
WorkflowRole,
|
|
441
|
+
// Re-exported from org.ai and digital-workers
|
|
442
|
+
OrgRole,
|
|
443
|
+
OrgRoleType,
|
|
444
|
+
RoleWorkerType,
|
|
422
445
|
} from './roles.js'
|
|
423
446
|
|
|
447
|
+
// Re-export Worker types from digital-workers via roles.ts
|
|
448
|
+
export type { Worker, WorkerRef } from './roles.js'
|
|
449
|
+
|
|
424
450
|
export {
|
|
425
451
|
StandardBusinessRoles,
|
|
426
452
|
createBusinessRole,
|
|
@@ -431,6 +457,9 @@ export {
|
|
|
431
457
|
findRoleForTask,
|
|
432
458
|
createTaskAssignment,
|
|
433
459
|
transitionTaskStatus,
|
|
460
|
+
// Conversion helpers
|
|
461
|
+
workerRefToAssignee,
|
|
462
|
+
assigneeToWorkerRef,
|
|
434
463
|
} from './roles.js'
|
|
435
464
|
|
|
436
465
|
// Export organization (full hierarchy to FGA/RBAC)
|
|
@@ -455,11 +484,7 @@ export type {
|
|
|
455
484
|
ResolvedPermissions,
|
|
456
485
|
} from './organization.js'
|
|
457
486
|
|
|
458
|
-
export {
|
|
459
|
-
resolvePermissions,
|
|
460
|
-
getApprovalChainForRequest,
|
|
461
|
-
findManager,
|
|
462
|
-
} from './organization.js'
|
|
487
|
+
export { resolvePermissions, getApprovalChainForRequest, findManager } from './organization.js'
|
|
463
488
|
|
|
464
489
|
// =============================================================================
|
|
465
490
|
// Entity Definitions (Noun pattern with Properties, Actions, Events)
|
|
@@ -528,3 +553,8 @@ export {
|
|
|
528
553
|
Entities,
|
|
529
554
|
type BusinessEntityCategory,
|
|
530
555
|
} from './entities/index.js'
|
|
556
|
+
|
|
557
|
+
// =============================================================================
|
|
558
|
+
// Business Model Canvas (TODO: implement canvas module)
|
|
559
|
+
// =============================================================================
|
|
560
|
+
// Canvas functionality is planned but not yet implemented
|
package/src/kpis.ts
CHANGED
|
@@ -1,8 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Key Performance Indicators (KPIs) management
|
|
3
|
+
*
|
|
4
|
+
* Uses org.ai KPI types for standardized KPI definitions across the ecosystem.
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
7
|
import type { KPIDefinition, TimePeriod } from './types.js'
|
|
8
|
+
import type { KPI as OrgKPI, KPICategory, KPITrend, KPIFrequency, KPIHistoryEntry } from 'org.ai'
|
|
9
|
+
|
|
10
|
+
// Re-export org.ai KPI types for convenience
|
|
11
|
+
export type { OrgKPI, KPICategory, KPITrend, KPIFrequency, KPIHistoryEntry }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Convert a business-as-code KPIDefinition to an org.ai KPI
|
|
15
|
+
*
|
|
16
|
+
* @param definition - Business KPI definition
|
|
17
|
+
* @param id - Unique identifier for the KPI
|
|
18
|
+
* @returns org.ai KPI object
|
|
19
|
+
*/
|
|
20
|
+
export function toOrgKPI(definition: KPIDefinition, id: string): OrgKPI {
|
|
21
|
+
const result: OrgKPI = {
|
|
22
|
+
id,
|
|
23
|
+
name: definition.name,
|
|
24
|
+
value: definition.current ?? 0,
|
|
25
|
+
target: definition.target ?? 0,
|
|
26
|
+
unit: definition.unit || '',
|
|
27
|
+
}
|
|
28
|
+
if (definition.description !== undefined) result.description = definition.description
|
|
29
|
+
if (definition.current !== undefined) result.current = definition.current
|
|
30
|
+
if (definition.category !== undefined) result.category = definition.category as KPICategory
|
|
31
|
+
if (definition.frequency !== undefined) result.frequency = definition.frequency as KPIFrequency
|
|
32
|
+
if (definition.dataSource !== undefined) result.dataSource = definition.dataSource
|
|
33
|
+
if (definition.formula !== undefined) result.formula = definition.formula
|
|
34
|
+
if (definition.metadata !== undefined) result.metadata = definition.metadata
|
|
35
|
+
return result
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Convert an org.ai KPI to a business-as-code KPIDefinition
|
|
40
|
+
*
|
|
41
|
+
* @param kpi - org.ai KPI object
|
|
42
|
+
* @returns Business KPI definition
|
|
43
|
+
*/
|
|
44
|
+
export function fromOrgKPI(kpi: OrgKPI): KPIDefinition {
|
|
45
|
+
const result: KPIDefinition = {
|
|
46
|
+
name: kpi.name,
|
|
47
|
+
unit: kpi.unit,
|
|
48
|
+
}
|
|
49
|
+
if (kpi.description !== undefined) result.description = kpi.description
|
|
50
|
+
const cat = kpi.category
|
|
51
|
+
if (cat !== undefined) result.category = cat as NonNullable<KPIDefinition['category']>
|
|
52
|
+
if (typeof kpi.target === 'number') result.target = kpi.target
|
|
53
|
+
if (typeof kpi.value === 'number') result.current = kpi.value
|
|
54
|
+
else if (typeof kpi.current === 'number') result.current = kpi.current
|
|
55
|
+
if (kpi.frequency !== undefined) result.frequency = kpi.frequency as TimePeriod
|
|
56
|
+
if (kpi.dataSource !== undefined) result.dataSource = kpi.dataSource
|
|
57
|
+
if (kpi.formula !== undefined) result.formula = kpi.formula
|
|
58
|
+
if (kpi.metadata !== undefined) result.metadata = kpi.metadata
|
|
59
|
+
return result
|
|
60
|
+
}
|
|
6
61
|
|
|
7
62
|
/**
|
|
8
63
|
* Define Key Performance Indicators for tracking business metrics
|
|
@@ -46,7 +101,7 @@ import type { KPIDefinition, TimePeriod } from './types.js'
|
|
|
46
101
|
* ```
|
|
47
102
|
*/
|
|
48
103
|
export function kpis(definitions: KPIDefinition[]): KPIDefinition[] {
|
|
49
|
-
return definitions.map(kpi => validateAndNormalizeKPI(kpi))
|
|
104
|
+
return definitions.map((kpi) => validateAndNormalizeKPI(kpi))
|
|
50
105
|
}
|
|
51
106
|
|
|
52
107
|
/**
|
|
@@ -88,7 +143,7 @@ export function meetsTarget(kpi: KPIDefinition): boolean {
|
|
|
88
143
|
if (kpi.target === undefined || kpi.current === undefined) return false
|
|
89
144
|
|
|
90
145
|
// For metrics where lower is better (like churn rate)
|
|
91
|
-
const lowerIsBetter = ['churn', 'cost', 'time', 'error', 'downtime'].some(term =>
|
|
146
|
+
const lowerIsBetter = ['churn', 'cost', 'time', 'error', 'downtime'].some((term) =>
|
|
92
147
|
kpi.name.toLowerCase().includes(term)
|
|
93
148
|
)
|
|
94
149
|
|
|
@@ -126,14 +181,14 @@ export function getKPIsByCategory(
|
|
|
126
181
|
kpis: KPIDefinition[],
|
|
127
182
|
category: KPIDefinition['category']
|
|
128
183
|
): KPIDefinition[] {
|
|
129
|
-
return kpis.filter(k => k.category === category)
|
|
184
|
+
return kpis.filter((k) => k.category === category)
|
|
130
185
|
}
|
|
131
186
|
|
|
132
187
|
/**
|
|
133
188
|
* Get KPIs by frequency
|
|
134
189
|
*/
|
|
135
190
|
export function getKPIsByFrequency(kpis: KPIDefinition[], frequency: TimePeriod): KPIDefinition[] {
|
|
136
|
-
return kpis.filter(k => k.frequency === frequency)
|
|
191
|
+
return kpis.filter((k) => k.frequency === frequency)
|
|
137
192
|
}
|
|
138
193
|
|
|
139
194
|
/**
|
|
@@ -147,7 +202,7 @@ export function getKPIsOnTarget(kpis: KPIDefinition[]): KPIDefinition[] {
|
|
|
147
202
|
* Get KPIs that don't meet their targets
|
|
148
203
|
*/
|
|
149
204
|
export function getKPIsOffTarget(kpis: KPIDefinition[]): KPIDefinition[] {
|
|
150
|
-
return kpis.filter(kpi => !meetsTarget(kpi))
|
|
205
|
+
return kpis.filter((kpi) => !meetsTarget(kpi))
|
|
151
206
|
}
|
|
152
207
|
|
|
153
208
|
/**
|
|
@@ -235,11 +290,10 @@ export function comparePerformance(
|
|
|
235
290
|
}
|
|
236
291
|
|
|
237
292
|
const change = current.current - previous.current
|
|
238
|
-
const changePercent =
|
|
239
|
-
previous.current !== 0 ? (change / previous.current) * 100 : 0
|
|
293
|
+
const changePercent = previous.current !== 0 ? (change / previous.current) * 100 : 0
|
|
240
294
|
|
|
241
295
|
// Determine if change is an improvement
|
|
242
|
-
const lowerIsBetter = ['churn', 'cost', 'time', 'error', 'downtime'].some(term =>
|
|
296
|
+
const lowerIsBetter = ['churn', 'cost', 'time', 'error', 'downtime'].some((term) =>
|
|
243
297
|
current.name.toLowerCase().includes(term)
|
|
244
298
|
)
|
|
245
299
|
|