business-as-code 2.0.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/dist/canvas/activities.d.ts +19 -0
- package/dist/canvas/activities.d.ts.map +1 -0
- package/dist/canvas/activities.js +20 -0
- package/dist/canvas/activities.js.map +1 -0
- package/dist/canvas/channels.d.ts +20 -0
- package/dist/canvas/channels.d.ts.map +1 -0
- package/dist/canvas/channels.js +21 -0
- package/dist/canvas/channels.js.map +1 -0
- package/dist/canvas/relationships.d.ts +20 -0
- package/dist/canvas/relationships.d.ts.map +1 -0
- package/dist/canvas/relationships.js +21 -0
- package/dist/canvas/relationships.js.map +1 -0
- package/dist/canvas/resources.d.ts +20 -0
- package/dist/canvas/resources.d.ts.map +1 -0
- package/dist/canvas/resources.js +30 -0
- package/dist/canvas/resources.js.map +1 -0
- package/dist/canvas/revenue.d.ts +22 -0
- package/dist/canvas/revenue.d.ts.map +1 -0
- package/dist/canvas/revenue.js +30 -0
- package/dist/canvas/revenue.js.map +1 -0
- package/dist/canvas/segments.d.ts +20 -0
- package/dist/canvas/segments.d.ts.map +1 -0
- package/dist/canvas/segments.js +28 -0
- package/dist/canvas/segments.js.map +1 -0
- package/dist/canvas/types.d.ts +232 -0
- package/dist/canvas/types.d.ts.map +1 -0
- package/dist/canvas/types.js +8 -0
- package/dist/canvas/types.js.map +1 -0
- package/dist/canvas/value.d.ts +20 -0
- package/dist/canvas/value.d.ts.map +1 -0
- package/dist/canvas/value.js +21 -0
- package/dist/canvas/value.js.map +1 -0
- package/dist/entities/planning.d.ts +0 -87
- package/examples/basic-usage.js +282 -0
- package/package.json +13 -14
- package/src/business.js +108 -0
- package/src/canvas/activities.ts +32 -0
- package/src/canvas/canvas.ts +482 -0
- package/src/canvas/channels.ts +34 -0
- package/src/canvas/costs.ts +43 -0
- package/src/canvas/economics.ts +99 -0
- package/src/canvas/index.ts +206 -0
- package/src/canvas/partnerships.ts +34 -0
- package/src/canvas/projections.ts +141 -0
- package/src/canvas/relationships.ts +34 -0
- package/src/canvas/resources.ts +43 -0
- package/src/canvas/revenue.ts +56 -0
- package/src/canvas/segments.ts +42 -0
- package/src/canvas/types.ts +363 -0
- package/src/canvas/value.ts +34 -0
- package/src/dollar.js +106 -0
- package/src/entities/assets.js +322 -0
- package/src/entities/business.js +369 -0
- package/src/entities/communication.js +254 -0
- package/src/entities/customers.js +988 -0
- package/src/entities/financials.js +931 -0
- package/src/entities/goals.js +799 -0
- package/src/entities/index.js +197 -0
- package/src/entities/legal.js +300 -0
- package/src/entities/market.js +300 -0
- package/src/entities/marketing.js +1156 -0
- package/src/entities/offerings.js +726 -0
- package/src/entities/operations.js +786 -0
- package/src/entities/organization.js +806 -0
- package/src/entities/partnerships.js +299 -0
- package/src/entities/planning.js +270 -0
- package/src/entities/projects.js +348 -0
- package/src/entities/risk.js +292 -0
- package/src/entities/sales.js +1247 -0
- package/src/financials.js +296 -0
- package/src/goals.js +214 -0
- package/src/index.js +131 -0
- package/src/index.test.js +274 -0
- package/src/kpis.js +231 -0
- package/src/metrics.js +324 -0
- package/src/okrs.js +268 -0
- package/src/organization.js +172 -0
- package/src/process.js +240 -0
- package/src/product.js +144 -0
- package/src/queries.js +414 -0
- package/src/roles.js +254 -0
- package/src/service.js +139 -0
- package/src/types.js +4 -0
- package/src/vision.js +67 -0
- package/src/workflow.js +246 -0
- package/tests/canvas.test.ts +842 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value Propositions
|
|
3
|
+
*
|
|
4
|
+
* Functions for creating and working with value propositions.
|
|
5
|
+
*/
|
|
6
|
+
import type { ValueProposition, ValueType } from './types.js';
|
|
7
|
+
export interface CreateValuePropositionInput {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
valueType?: ValueType;
|
|
11
|
+
benefits?: string[];
|
|
12
|
+
targetSegments?: string[];
|
|
13
|
+
quantifiedValue?: string;
|
|
14
|
+
segmentFit?: Record<string, number>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a value proposition
|
|
18
|
+
*/
|
|
19
|
+
export declare function createValueProposition(input: CreateValuePropositionInput): ValueProposition;
|
|
20
|
+
//# sourceMappingURL=value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../src/canvas/value.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE7D,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACpC;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,GAAG,gBAAgB,CAY3F"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value Propositions
|
|
3
|
+
*
|
|
4
|
+
* Functions for creating and working with value propositions.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Create a value proposition
|
|
8
|
+
*/
|
|
9
|
+
export function createValueProposition(input) {
|
|
10
|
+
const { name, description, valueType, benefits = [], targetSegments, quantifiedValue, segmentFit } = input;
|
|
11
|
+
return {
|
|
12
|
+
name,
|
|
13
|
+
description,
|
|
14
|
+
valueType,
|
|
15
|
+
benefits,
|
|
16
|
+
targetSegments,
|
|
17
|
+
quantifiedValue,
|
|
18
|
+
segmentFit,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value.js","sourceRoot":"","sources":["../../src/canvas/value.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAkC;IACvE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,cAAc,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;IAE1G,OAAO;QACL,IAAI;QACJ,WAAW;QACX,SAAS;QACT,QAAQ;QACR,cAAc;QACd,eAAe;QACf,UAAU;KACX,CAAA;AACH,CAAC"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { Noun } from 'ai-database';
|
|
2
|
-
/**
|
|
3
|
-
* Planning Entities
|
|
4
|
-
* Issue, Plan - Planning-focused abstractions for tracking work
|
|
5
|
-
*
|
|
6
|
-
* These complement the execution-focused Task in digital-tasks
|
|
7
|
-
* and the project management entities in projects.ts
|
|
8
|
-
*
|
|
9
|
-
* Key distinction:
|
|
10
|
-
* - Task (digital-tasks): Function execution with workers, queues, runtime
|
|
11
|
-
* - Task (projects.ts): Project management work item
|
|
12
|
-
* - Issue (planning.ts): Planning-focused with design, acceptance criteria, notes
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* WorkItem - A planning-focused work item (ticket/issue)
|
|
16
|
-
*
|
|
17
|
-
* Models the full lifecycle of work from ideation through completion:
|
|
18
|
-
* - What: title, description
|
|
19
|
-
* - Why: context, business value
|
|
20
|
-
* - How: design (implementation approach)
|
|
21
|
-
* - Done: acceptance criteria
|
|
22
|
-
* - Context: notes (session handoff, progress tracking)
|
|
23
|
-
*
|
|
24
|
-
* This abstraction is backend-agnostic and can be implemented by:
|
|
25
|
-
* - beads (SQLite) - maps to beads Issue
|
|
26
|
-
* - Linear - maps to Linear Issue
|
|
27
|
-
* - GitHub Issues
|
|
28
|
-
* - Jira - maps to Jira Issue/Ticket
|
|
29
|
-
* - etc.
|
|
30
|
-
*
|
|
31
|
-
* Note: Distinct from entities/risk.ts Issue which represents
|
|
32
|
-
* operational/business issues (problems requiring resolution).
|
|
33
|
-
* WorkItem represents planned development work.
|
|
34
|
-
*/
|
|
35
|
-
export declare const WorkItem: Noun;
|
|
36
|
-
/**
|
|
37
|
-
* Comment - A comment on an issue
|
|
38
|
-
*/
|
|
39
|
-
export declare const Comment: Noun;
|
|
40
|
-
/**
|
|
41
|
-
* Event - An audit trail event on an issue
|
|
42
|
-
*/
|
|
43
|
-
export declare const Event: Noun;
|
|
44
|
-
/**
|
|
45
|
-
* WorkItemComment - Alias for Comment (for clarity)
|
|
46
|
-
*/
|
|
47
|
-
export declare const WorkItemComment: Noun;
|
|
48
|
-
/**
|
|
49
|
-
* WorkItemEvent - Alias for Event (for clarity)
|
|
50
|
-
*/
|
|
51
|
-
export declare const WorkItemEvent: Noun;
|
|
52
|
-
/**
|
|
53
|
-
* Plan - A high-level planning document that generates issues
|
|
54
|
-
*
|
|
55
|
-
* Bridges Strategy → Plan → Issues → Tasks
|
|
56
|
-
*
|
|
57
|
-
* A Plan captures:
|
|
58
|
-
* - Goals and objectives
|
|
59
|
-
* - Constraints and assumptions
|
|
60
|
-
* - Design decisions
|
|
61
|
-
* - Issue breakdown
|
|
62
|
-
*/
|
|
63
|
-
export declare const Plan: Noun;
|
|
64
|
-
/**
|
|
65
|
-
* Dependency types for issue relationships
|
|
66
|
-
*/
|
|
67
|
-
export declare const DependencyTypes: {
|
|
68
|
-
/** Hard blocker - issue A blocks issue B from starting */
|
|
69
|
-
readonly blocks: "blocks";
|
|
70
|
-
/** Soft link - issues are related but not blocking */
|
|
71
|
-
readonly related: "related";
|
|
72
|
-
/** Hierarchical - epic/subtask relationship */
|
|
73
|
-
readonly parentChild: "parent-child";
|
|
74
|
-
/** Provenance - issue B discovered while working on A */
|
|
75
|
-
readonly discoveredFrom: "discovered-from";
|
|
76
|
-
};
|
|
77
|
-
export type DependencyType = (typeof DependencyTypes)[keyof typeof DependencyTypes];
|
|
78
|
-
export declare const PlanningEntities: {
|
|
79
|
-
WorkItem: Noun;
|
|
80
|
-
WorkItemComment: Noun;
|
|
81
|
-
WorkItemEvent: Noun;
|
|
82
|
-
Comment: Noun;
|
|
83
|
-
Event: Noun;
|
|
84
|
-
Plan: Noun;
|
|
85
|
-
};
|
|
86
|
-
export default PlanningEntities;
|
|
87
|
-
//# sourceMappingURL=planning.d.ts.map
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic usage example for business-as-code
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to define business entities, goals, products,
|
|
5
|
+
* KPIs, OKRs, and calculate financial metrics.
|
|
6
|
+
*/
|
|
7
|
+
import { Business, Vision, Goals, Product, Service, Process, Workflow, kpis, okrs, financials, $, } from '../src/index.js';
|
|
8
|
+
// Define your business
|
|
9
|
+
const company = Business({
|
|
10
|
+
name: 'Acme Corp',
|
|
11
|
+
description: 'Building the future of widgets',
|
|
12
|
+
industry: 'Technology',
|
|
13
|
+
mission: 'To make widgets accessible to everyone',
|
|
14
|
+
values: ['Innovation', 'Customer Focus', 'Integrity'],
|
|
15
|
+
targetMarket: 'SMB and Enterprise',
|
|
16
|
+
foundedAt: new Date('2020-01-01'),
|
|
17
|
+
teamSize: 50,
|
|
18
|
+
structure: {
|
|
19
|
+
departments: [
|
|
20
|
+
{
|
|
21
|
+
name: 'Engineering',
|
|
22
|
+
head: 'Jane Smith',
|
|
23
|
+
members: ['Alice', 'Bob', 'Charlie'],
|
|
24
|
+
budget: 2000000,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'Sales',
|
|
28
|
+
head: 'John Doe',
|
|
29
|
+
members: ['David', 'Eve'],
|
|
30
|
+
budget: 1000000,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
// Define vision
|
|
36
|
+
const vision = Vision({
|
|
37
|
+
statement: 'To become the world\'s most trusted widget platform',
|
|
38
|
+
timeframe: '5 years',
|
|
39
|
+
successIndicators: [
|
|
40
|
+
'10M+ active users',
|
|
41
|
+
'Present in 50+ countries',
|
|
42
|
+
'Industry-leading NPS score',
|
|
43
|
+
'$1B+ annual revenue',
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
// Define goals
|
|
47
|
+
const goals = Goals([
|
|
48
|
+
{
|
|
49
|
+
name: 'Launch MVP',
|
|
50
|
+
description: 'Ship minimum viable product to early customers',
|
|
51
|
+
category: 'strategic',
|
|
52
|
+
targetDate: new Date('2024-06-30'),
|
|
53
|
+
owner: 'Product Team',
|
|
54
|
+
metrics: ['User signups', 'Feature completion rate'],
|
|
55
|
+
status: 'in-progress',
|
|
56
|
+
progress: 65,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'Achieve Product-Market Fit',
|
|
60
|
+
description: 'Validate product value with target customers',
|
|
61
|
+
category: 'strategic',
|
|
62
|
+
targetDate: new Date('2024-12-31'),
|
|
63
|
+
owner: 'CEO',
|
|
64
|
+
metrics: ['NPS > 50', 'Churn < 5%', '100+ paying customers'],
|
|
65
|
+
status: 'in-progress',
|
|
66
|
+
progress: 30,
|
|
67
|
+
dependencies: ['Launch MVP'],
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
70
|
+
// Define products
|
|
71
|
+
const product = Product({
|
|
72
|
+
name: 'Widget Pro',
|
|
73
|
+
description: 'Enterprise-grade widget management platform',
|
|
74
|
+
category: 'SaaS',
|
|
75
|
+
targetSegment: 'Enterprise',
|
|
76
|
+
valueProposition: 'Reduce widget management costs by 50%',
|
|
77
|
+
pricingModel: 'subscription',
|
|
78
|
+
price: 99,
|
|
79
|
+
currency: 'USD',
|
|
80
|
+
cogs: 20,
|
|
81
|
+
features: [
|
|
82
|
+
'Unlimited widgets',
|
|
83
|
+
'Advanced analytics',
|
|
84
|
+
'API access',
|
|
85
|
+
'24/7 support',
|
|
86
|
+
],
|
|
87
|
+
roadmap: [
|
|
88
|
+
{
|
|
89
|
+
name: 'Mobile app',
|
|
90
|
+
description: 'Native iOS and Android apps',
|
|
91
|
+
targetDate: new Date('2024-09-01'),
|
|
92
|
+
priority: 'high',
|
|
93
|
+
status: 'in-progress',
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
// Define services
|
|
98
|
+
const service = Service({
|
|
99
|
+
name: 'Widget Consulting',
|
|
100
|
+
description: 'Expert widget implementation and optimization',
|
|
101
|
+
category: 'Consulting',
|
|
102
|
+
targetSegment: 'Enterprise',
|
|
103
|
+
valueProposition: 'Get expert help implementing widgets in 2 weeks',
|
|
104
|
+
pricingModel: 'fixed',
|
|
105
|
+
price: 5000,
|
|
106
|
+
currency: 'USD',
|
|
107
|
+
deliveryTime: '2 weeks',
|
|
108
|
+
sla: {
|
|
109
|
+
uptime: 99.9,
|
|
110
|
+
responseTime: '< 24 hours',
|
|
111
|
+
supportHours: 'Business hours (9-5 EST)',
|
|
112
|
+
penalties: '10% refund per day of delay',
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
// Define a business process
|
|
116
|
+
const process = Process({
|
|
117
|
+
name: 'Customer Onboarding',
|
|
118
|
+
description: 'Process for onboarding new customers',
|
|
119
|
+
category: 'core',
|
|
120
|
+
owner: 'Customer Success Team',
|
|
121
|
+
steps: [
|
|
122
|
+
{
|
|
123
|
+
order: 1,
|
|
124
|
+
name: 'Welcome Email',
|
|
125
|
+
description: 'Send personalized welcome email',
|
|
126
|
+
responsible: 'CS Manager',
|
|
127
|
+
duration: '5 minutes',
|
|
128
|
+
automationLevel: 'automated',
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
order: 2,
|
|
132
|
+
name: 'Initial Setup Call',
|
|
133
|
+
description: 'Schedule and conduct setup call',
|
|
134
|
+
responsible: 'CS Rep',
|
|
135
|
+
duration: '30 minutes',
|
|
136
|
+
automationLevel: 'manual',
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
inputs: ['Customer Information', 'Subscription Plan'],
|
|
140
|
+
outputs: ['Configured Account', 'Training Materials'],
|
|
141
|
+
});
|
|
142
|
+
// Define a workflow
|
|
143
|
+
const workflow = Workflow({
|
|
144
|
+
name: 'New Customer Welcome',
|
|
145
|
+
description: 'Automated welcome sequence for new customers',
|
|
146
|
+
trigger: {
|
|
147
|
+
type: 'event',
|
|
148
|
+
event: 'Customer.created',
|
|
149
|
+
},
|
|
150
|
+
actions: [
|
|
151
|
+
{
|
|
152
|
+
order: 1,
|
|
153
|
+
type: 'send',
|
|
154
|
+
description: 'Send welcome email',
|
|
155
|
+
params: {
|
|
156
|
+
template: 'welcome_email',
|
|
157
|
+
to: '{{customer.email}}',
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
order: 2,
|
|
162
|
+
type: 'create',
|
|
163
|
+
description: 'Create onboarding task',
|
|
164
|
+
params: {
|
|
165
|
+
type: 'Task',
|
|
166
|
+
title: 'Onboard {{customer.name}}',
|
|
167
|
+
assignee: 'customer_success_team',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
});
|
|
172
|
+
// Track KPIs
|
|
173
|
+
const kpiList = kpis([
|
|
174
|
+
{
|
|
175
|
+
name: 'Monthly Recurring Revenue',
|
|
176
|
+
description: 'Total predictable revenue per month',
|
|
177
|
+
category: 'financial',
|
|
178
|
+
unit: 'USD',
|
|
179
|
+
target: 100000,
|
|
180
|
+
current: 85000,
|
|
181
|
+
frequency: 'monthly',
|
|
182
|
+
dataSource: 'Billing System',
|
|
183
|
+
formula: 'SUM(active_subscriptions.price)',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: 'Customer Churn Rate',
|
|
187
|
+
description: 'Percentage of customers lost per month',
|
|
188
|
+
category: 'customer',
|
|
189
|
+
unit: 'percent',
|
|
190
|
+
target: 5,
|
|
191
|
+
current: 3.2,
|
|
192
|
+
frequency: 'monthly',
|
|
193
|
+
dataSource: 'CRM',
|
|
194
|
+
formula: '(churned_customers / total_customers) * 100',
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'Net Promoter Score',
|
|
198
|
+
description: 'Customer satisfaction and loyalty metric',
|
|
199
|
+
category: 'customer',
|
|
200
|
+
unit: 'score',
|
|
201
|
+
target: 50,
|
|
202
|
+
current: 48,
|
|
203
|
+
frequency: 'quarterly',
|
|
204
|
+
dataSource: 'Survey Platform',
|
|
205
|
+
},
|
|
206
|
+
]);
|
|
207
|
+
// Define OKRs
|
|
208
|
+
const okrList = okrs([
|
|
209
|
+
{
|
|
210
|
+
objective: 'Achieve Product-Market Fit',
|
|
211
|
+
description: 'Validate that our product solves a real problem for customers',
|
|
212
|
+
period: 'Q2 2024',
|
|
213
|
+
owner: 'CEO',
|
|
214
|
+
keyResults: [
|
|
215
|
+
{
|
|
216
|
+
description: 'Increase Net Promoter Score',
|
|
217
|
+
metric: 'NPS',
|
|
218
|
+
startValue: 40,
|
|
219
|
+
targetValue: 60,
|
|
220
|
+
currentValue: 52,
|
|
221
|
+
unit: 'score',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
description: 'Reduce monthly churn rate',
|
|
225
|
+
metric: 'Churn Rate',
|
|
226
|
+
startValue: 8,
|
|
227
|
+
targetValue: 4,
|
|
228
|
+
currentValue: 5.5,
|
|
229
|
+
unit: 'percent',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
description: 'Achieve customer retention',
|
|
233
|
+
metric: 'Customers with 3+ months',
|
|
234
|
+
startValue: 50,
|
|
235
|
+
targetValue: 200,
|
|
236
|
+
currentValue: 125,
|
|
237
|
+
unit: 'customers',
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
status: 'on-track',
|
|
241
|
+
confidence: 75,
|
|
242
|
+
},
|
|
243
|
+
]);
|
|
244
|
+
// Calculate financials
|
|
245
|
+
const metrics = financials({
|
|
246
|
+
revenue: 1000000,
|
|
247
|
+
cogs: 300000,
|
|
248
|
+
operatingExpenses: 500000,
|
|
249
|
+
currency: 'USD',
|
|
250
|
+
period: 'monthly',
|
|
251
|
+
});
|
|
252
|
+
// Use $ helper for calculations
|
|
253
|
+
console.log('\n=== Business Operations with $ ===');
|
|
254
|
+
console.log('Format currency:', $.format(1234.56));
|
|
255
|
+
console.log('Calculate percentage:', $.percent(25, 100));
|
|
256
|
+
console.log('Calculate growth:', $.growth(120, 100));
|
|
257
|
+
console.log('Calculate margin:', $.margin(100, 60));
|
|
258
|
+
console.log('Calculate ROI:', $.roi(150, 100));
|
|
259
|
+
console.log('Calculate LTV:', $.ltv(100, 12, 24));
|
|
260
|
+
console.log('Calculate CAC:', $.cac(10000, 100));
|
|
261
|
+
console.log('Calculate burn rate:', $.burnRate(100000, 70000, 3));
|
|
262
|
+
console.log('Calculate runway:', $.runway(100000, 10000));
|
|
263
|
+
// Display results
|
|
264
|
+
console.log('\n=== Business Summary ===');
|
|
265
|
+
console.log(`Company: ${company.name}`);
|
|
266
|
+
console.log(`Mission: ${company.mission}`);
|
|
267
|
+
console.log(`Team Size: ${company.teamSize}`);
|
|
268
|
+
console.log(`\nVision: ${vision.statement}`);
|
|
269
|
+
console.log(`Timeframe: ${vision.timeframe}`);
|
|
270
|
+
console.log(`\nGoals: ${goals.length}`);
|
|
271
|
+
console.log(`Products: ${product.name} - ${$.format(product.price)} ${product.pricingModel}`);
|
|
272
|
+
console.log(`Services: ${service.name} - ${$.format(service.price)} ${service.pricingModel}`);
|
|
273
|
+
console.log(`\nKPIs: ${kpiList.length}`);
|
|
274
|
+
console.log(`OKRs: ${okrList.length}`);
|
|
275
|
+
console.log(`\n=== Financial Metrics ===`);
|
|
276
|
+
console.log(`Revenue: ${$.format(metrics.revenue)}`);
|
|
277
|
+
console.log(`Gross Profit: ${$.format(metrics.grossProfit)}`);
|
|
278
|
+
console.log(`Gross Margin: ${metrics.grossMargin.toFixed(1)}%`);
|
|
279
|
+
console.log(`Operating Income: ${$.format(metrics.operatingIncome)}`);
|
|
280
|
+
console.log(`Operating Margin: ${metrics.operatingMargin.toFixed(1)}%`);
|
|
281
|
+
console.log(`Net Income: ${$.format(metrics.netIncome)}`);
|
|
282
|
+
console.log(`Net Margin: ${metrics.netMargin.toFixed(1)}%`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "business-as-code",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Primitives for expressing business logic and processes as code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,18 +11,9 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsc",
|
|
16
|
-
"dev": "tsc --watch",
|
|
17
|
-
"test": "vitest",
|
|
18
|
-
"typecheck": "tsc --noEmit",
|
|
19
|
-
"lint": "eslint .",
|
|
20
|
-
"clean": "rm -rf dist"
|
|
21
|
-
},
|
|
22
14
|
"dependencies": {
|
|
23
|
-
"ai-database": "2.
|
|
24
|
-
"ai-functions": "2.
|
|
25
|
-
"rpc.do": "^0.1.0"
|
|
15
|
+
"ai-database": "2.1.3",
|
|
16
|
+
"ai-functions": "2.1.3"
|
|
26
17
|
},
|
|
27
18
|
"keywords": [
|
|
28
19
|
"business",
|
|
@@ -30,5 +21,13 @@
|
|
|
30
21
|
"code",
|
|
31
22
|
"primitives"
|
|
32
23
|
],
|
|
33
|
-
"license": "MIT"
|
|
34
|
-
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"dev": "tsc --watch",
|
|
28
|
+
"test": "vitest",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"lint": "eslint .",
|
|
31
|
+
"clean": "rm -rf dist"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/business.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Business entity definition
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Define a business entity with organizational structure, mission, and values
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const acme = Business({
|
|
10
|
+
* name: 'Acme Corp',
|
|
11
|
+
* description: 'Building the future of widgets',
|
|
12
|
+
* industry: 'Technology',
|
|
13
|
+
* mission: 'To make widgets accessible to everyone',
|
|
14
|
+
* values: ['Innovation', 'Customer Focus', 'Integrity'],
|
|
15
|
+
* targetMarket: 'SMB and Enterprise',
|
|
16
|
+
* foundedAt: new Date('2020-01-01'),
|
|
17
|
+
* teamSize: 50,
|
|
18
|
+
* structure: {
|
|
19
|
+
* departments: [
|
|
20
|
+
* {
|
|
21
|
+
* name: 'Engineering',
|
|
22
|
+
* head: 'Jane Smith',
|
|
23
|
+
* members: ['Alice', 'Bob', 'Charlie'],
|
|
24
|
+
* budget: 2000000,
|
|
25
|
+
* },
|
|
26
|
+
* {
|
|
27
|
+
* name: 'Sales',
|
|
28
|
+
* head: 'John Doe',
|
|
29
|
+
* members: ['David', 'Eve'],
|
|
30
|
+
* budget: 1000000,
|
|
31
|
+
* },
|
|
32
|
+
* ],
|
|
33
|
+
* },
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function Business(definition) {
|
|
38
|
+
// Validate required fields
|
|
39
|
+
if (!definition.name) {
|
|
40
|
+
throw new Error('Business name is required');
|
|
41
|
+
}
|
|
42
|
+
// Return validated business definition
|
|
43
|
+
return {
|
|
44
|
+
...definition,
|
|
45
|
+
foundedAt: definition.foundedAt || new Date(),
|
|
46
|
+
teamSize: definition.teamSize || 0,
|
|
47
|
+
values: definition.values || [],
|
|
48
|
+
metadata: definition.metadata || {},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get total budget across all departments
|
|
53
|
+
*/
|
|
54
|
+
export function getTotalBudget(business) {
|
|
55
|
+
if (!business.structure?.departments)
|
|
56
|
+
return 0;
|
|
57
|
+
return business.structure.departments.reduce((total, dept) => {
|
|
58
|
+
return total + (dept.budget || 0);
|
|
59
|
+
}, 0);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get total team size across all departments
|
|
63
|
+
*/
|
|
64
|
+
export function getTotalTeamSize(business) {
|
|
65
|
+
if (!business.structure?.departments)
|
|
66
|
+
return business.teamSize || 0;
|
|
67
|
+
return business.structure.departments.reduce((total, dept) => {
|
|
68
|
+
return total + (dept.members?.length || 0);
|
|
69
|
+
}, 0);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get department by name
|
|
73
|
+
*/
|
|
74
|
+
export function getDepartment(business, name) {
|
|
75
|
+
return business.structure?.departments?.find(d => d.name === name);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get team by name
|
|
79
|
+
*/
|
|
80
|
+
export function getTeam(business, name) {
|
|
81
|
+
return business.structure?.teams?.find(t => t.name === name);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Validate business definition
|
|
85
|
+
*/
|
|
86
|
+
export function validateBusiness(business) {
|
|
87
|
+
const errors = [];
|
|
88
|
+
if (!business.name) {
|
|
89
|
+
errors.push('Business name is required');
|
|
90
|
+
}
|
|
91
|
+
if (business.teamSize && business.teamSize < 0) {
|
|
92
|
+
errors.push('Team size cannot be negative');
|
|
93
|
+
}
|
|
94
|
+
if (business.structure?.departments) {
|
|
95
|
+
for (const dept of business.structure.departments) {
|
|
96
|
+
if (!dept.name) {
|
|
97
|
+
errors.push('Department name is required');
|
|
98
|
+
}
|
|
99
|
+
if (dept.budget && dept.budget < 0) {
|
|
100
|
+
errors.push(`Department ${dept.name} budget cannot be negative`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
valid: errors.length === 0,
|
|
106
|
+
errors,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Key Activities
|
|
3
|
+
*
|
|
4
|
+
* Functions for creating and working with key activities.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { KeyActivity, ActivityCategory } from './types.js'
|
|
8
|
+
|
|
9
|
+
export interface CreateKeyActivityInput {
|
|
10
|
+
name: string
|
|
11
|
+
category: ActivityCategory
|
|
12
|
+
description?: string
|
|
13
|
+
resources?: string[]
|
|
14
|
+
metrics?: string[]
|
|
15
|
+
uptime?: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a key activity
|
|
20
|
+
*/
|
|
21
|
+
export function createKeyActivity(input: CreateKeyActivityInput): KeyActivity {
|
|
22
|
+
const { name, category, description, resources, metrics, uptime } = input
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
name,
|
|
26
|
+
category,
|
|
27
|
+
description,
|
|
28
|
+
resources,
|
|
29
|
+
metrics,
|
|
30
|
+
uptime,
|
|
31
|
+
}
|
|
32
|
+
}
|