business-as-code 2.1.1 → 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 +18 -0
- package/README.md +2 -0
- package/package.json +7 -4
- 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/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/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 -87
- 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/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/dist/vision.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vision statement definition
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Define a business vision statement with timeframe and success indicators
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const vision = Vision({
|
|
10
|
-
* statement: 'To become the world\'s most trusted widget platform',
|
|
11
|
-
* timeframe: '5 years',
|
|
12
|
-
* successIndicators: [
|
|
13
|
-
* '10M+ active users',
|
|
14
|
-
* 'Present in 50+ countries',
|
|
15
|
-
* 'Industry-leading NPS score',
|
|
16
|
-
* '$1B+ annual revenue',
|
|
17
|
-
* ],
|
|
18
|
-
* })
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export function Vision(definition) {
|
|
22
|
-
// Validate required fields
|
|
23
|
-
if (!definition.statement) {
|
|
24
|
-
throw new Error('Vision statement is required');
|
|
25
|
-
}
|
|
26
|
-
// Return validated vision definition
|
|
27
|
-
return {
|
|
28
|
-
...definition,
|
|
29
|
-
successIndicators: definition.successIndicators || [],
|
|
30
|
-
metadata: definition.metadata || {},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Check if a success indicator has been achieved
|
|
35
|
-
*/
|
|
36
|
-
export function checkIndicator(vision, indicator, currentMetrics) {
|
|
37
|
-
// Simple check - would need more sophisticated parsing in production
|
|
38
|
-
return Object.entries(currentMetrics).some(([key, value]) => {
|
|
39
|
-
return indicator.toLowerCase().includes(key.toLowerCase()) && Boolean(value);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Calculate vision progress based on achieved indicators
|
|
44
|
-
*/
|
|
45
|
-
export function calculateProgress(vision, currentMetrics) {
|
|
46
|
-
if (!vision.successIndicators || vision.successIndicators.length === 0) {
|
|
47
|
-
return 0;
|
|
48
|
-
}
|
|
49
|
-
const achieved = vision.successIndicators.filter(indicator => checkIndicator(vision, indicator, currentMetrics)).length;
|
|
50
|
-
return (achieved / vision.successIndicators.length) * 100;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Validate vision definition
|
|
54
|
-
*/
|
|
55
|
-
export function validateVision(vision) {
|
|
56
|
-
const errors = [];
|
|
57
|
-
if (!vision.statement) {
|
|
58
|
-
errors.push('Vision statement is required');
|
|
59
|
-
}
|
|
60
|
-
if (vision.statement && vision.statement.length < 10) {
|
|
61
|
-
errors.push('Vision statement should be at least 10 characters');
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
valid: errors.length === 0,
|
|
65
|
-
errors,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=vision.js.map
|
package/dist/vision.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vision.js","sourceRoot":"","sources":["../src/vision.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CAAC,UAA4B;IACjD,2BAA2B;IAC3B,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,qCAAqC;IACrC,OAAO;QACL,GAAG,UAAU;QACb,iBAAiB,EAAE,UAAU,CAAC,iBAAiB,IAAI,EAAE;QACrD,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,EAAE;KACpC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAwB,EACxB,SAAiB,EACjB,cAAgD;IAEhD,qEAAqE;IACrE,OAAO,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QAC1D,OAAO,SAAS,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAA;IAC9E,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAwB,EACxB,cAAgD;IAEhD,IAAI,CAAC,MAAM,CAAC,iBAAiB,IAAI,MAAM,CAAC,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvE,OAAO,CAAC,CAAA;IACV,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAC3D,cAAc,CAAC,MAAM,EAAE,SAAS,EAAE,cAAc,CAAC,CAClD,CAAC,MAAM,CAAA;IAER,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,GAAG,CAAA;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,MAAwB;IACrD,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACtB,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAA;IAC7C,CAAC;IAED,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAA;IAClE,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;KACP,CAAA;AACH,CAAC"}
|
package/dist/workflow.d.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workflow definition (automation sequences)
|
|
3
|
-
*/
|
|
4
|
-
import type { WorkflowDefinition, WorkflowAction, WorkflowTrigger } from './types.js';
|
|
5
|
-
/**
|
|
6
|
-
* Define an automated workflow with triggers and actions
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* const workflow = Workflow({
|
|
11
|
-
* name: 'New Customer Welcome',
|
|
12
|
-
* description: 'Automated welcome sequence for new customers',
|
|
13
|
-
* trigger: {
|
|
14
|
-
* type: 'event',
|
|
15
|
-
* event: 'Customer.created',
|
|
16
|
-
* },
|
|
17
|
-
* actions: [
|
|
18
|
-
* {
|
|
19
|
-
* order: 1,
|
|
20
|
-
* type: 'send',
|
|
21
|
-
* description: 'Send welcome email',
|
|
22
|
-
* params: {
|
|
23
|
-
* template: 'welcome_email',
|
|
24
|
-
* to: '{{customer.email}}',
|
|
25
|
-
* },
|
|
26
|
-
* },
|
|
27
|
-
* {
|
|
28
|
-
* order: 2,
|
|
29
|
-
* type: 'create',
|
|
30
|
-
* description: 'Create onboarding task',
|
|
31
|
-
* params: {
|
|
32
|
-
* type: 'Task',
|
|
33
|
-
* title: 'Onboard {{customer.name}}',
|
|
34
|
-
* assignee: 'customer_success_team',
|
|
35
|
-
* },
|
|
36
|
-
* },
|
|
37
|
-
* {
|
|
38
|
-
* order: 3,
|
|
39
|
-
* type: 'wait',
|
|
40
|
-
* description: 'Wait 24 hours',
|
|
41
|
-
* params: {
|
|
42
|
-
* duration: '24 hours',
|
|
43
|
-
* },
|
|
44
|
-
* },
|
|
45
|
-
* {
|
|
46
|
-
* order: 4,
|
|
47
|
-
* type: 'notify',
|
|
48
|
-
* description: 'Send setup reminder',
|
|
49
|
-
* params: {
|
|
50
|
-
* channel: 'email',
|
|
51
|
-
* message: 'Reminder to complete setup',
|
|
52
|
-
* },
|
|
53
|
-
* condition: 'customer.setupCompleted === false',
|
|
54
|
-
* },
|
|
55
|
-
* ],
|
|
56
|
-
* })
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
export declare function Workflow(definition: WorkflowDefinition): WorkflowDefinition;
|
|
60
|
-
/**
|
|
61
|
-
* Get actions in execution order
|
|
62
|
-
*/
|
|
63
|
-
export declare function getActionsInOrder(workflow: WorkflowDefinition): WorkflowAction[];
|
|
64
|
-
/**
|
|
65
|
-
* Get actions by type
|
|
66
|
-
*/
|
|
67
|
-
export declare function getActionsByType(workflow: WorkflowDefinition, type: WorkflowAction['type']): WorkflowAction[];
|
|
68
|
-
/**
|
|
69
|
-
* Get conditional actions
|
|
70
|
-
*/
|
|
71
|
-
export declare function getConditionalActions(workflow: WorkflowDefinition): WorkflowAction[];
|
|
72
|
-
/**
|
|
73
|
-
* Add action to workflow
|
|
74
|
-
*/
|
|
75
|
-
export declare function addAction(workflow: WorkflowDefinition, action: WorkflowAction): WorkflowDefinition;
|
|
76
|
-
/**
|
|
77
|
-
* Remove action from workflow
|
|
78
|
-
*/
|
|
79
|
-
export declare function removeAction(workflow: WorkflowDefinition, order: number): WorkflowDefinition;
|
|
80
|
-
/**
|
|
81
|
-
* Update action in workflow
|
|
82
|
-
*/
|
|
83
|
-
export declare function updateAction(workflow: WorkflowDefinition, order: number, updates: Partial<WorkflowAction>): WorkflowDefinition;
|
|
84
|
-
/**
|
|
85
|
-
* Check if trigger is event-based
|
|
86
|
-
*/
|
|
87
|
-
export declare function isEventTrigger(trigger: WorkflowTrigger): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Check if trigger is schedule-based
|
|
90
|
-
*/
|
|
91
|
-
export declare function isScheduleTrigger(trigger: WorkflowTrigger): boolean;
|
|
92
|
-
/**
|
|
93
|
-
* Check if trigger is webhook-based
|
|
94
|
-
*/
|
|
95
|
-
export declare function isWebhookTrigger(trigger: WorkflowTrigger): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Parse wait duration to milliseconds
|
|
98
|
-
*/
|
|
99
|
-
export declare function parseWaitDuration(duration: string): number;
|
|
100
|
-
/**
|
|
101
|
-
* Evaluate condition (simple implementation)
|
|
102
|
-
*/
|
|
103
|
-
export declare function evaluateCondition(condition: string, context: Record<string, unknown>): boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Fill template with context values
|
|
106
|
-
*/
|
|
107
|
-
export declare function fillTemplate(template: string, context: Record<string, unknown>): string;
|
|
108
|
-
/**
|
|
109
|
-
* Validate workflow definition
|
|
110
|
-
*/
|
|
111
|
-
export declare function validateWorkflow(workflow: WorkflowDefinition): {
|
|
112
|
-
valid: boolean;
|
|
113
|
-
errors: string[];
|
|
114
|
-
};
|
|
115
|
-
//# sourceMappingURL=workflow.d.ts.map
|
package/dist/workflow.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.ts","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAErF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,kBAAkB,GAAG,kBAAkB,CAc3E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,cAAc,EAAE,CAEhF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,kBAAkB,EAC5B,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,GAC3B,cAAc,EAAE,CAElB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,cAAc,EAAE,CAEpF;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,kBAAkB,EAAE,MAAM,EAAE,cAAc,GAAG,kBAAkB,CAKlG;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,GAAG,kBAAkB,CAK5F;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,kBAAkB,EAC5B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAC/B,kBAAkB,CASpB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEhE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAElE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CA+B1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAgB9F;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAKvF;AASD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA2CnG"}
|
package/dist/workflow.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Workflow definition (automation sequences)
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Define an automated workflow with triggers and actions
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* const workflow = Workflow({
|
|
10
|
-
* name: 'New Customer Welcome',
|
|
11
|
-
* description: 'Automated welcome sequence for new customers',
|
|
12
|
-
* trigger: {
|
|
13
|
-
* type: 'event',
|
|
14
|
-
* event: 'Customer.created',
|
|
15
|
-
* },
|
|
16
|
-
* actions: [
|
|
17
|
-
* {
|
|
18
|
-
* order: 1,
|
|
19
|
-
* type: 'send',
|
|
20
|
-
* description: 'Send welcome email',
|
|
21
|
-
* params: {
|
|
22
|
-
* template: 'welcome_email',
|
|
23
|
-
* to: '{{customer.email}}',
|
|
24
|
-
* },
|
|
25
|
-
* },
|
|
26
|
-
* {
|
|
27
|
-
* order: 2,
|
|
28
|
-
* type: 'create',
|
|
29
|
-
* description: 'Create onboarding task',
|
|
30
|
-
* params: {
|
|
31
|
-
* type: 'Task',
|
|
32
|
-
* title: 'Onboard {{customer.name}}',
|
|
33
|
-
* assignee: 'customer_success_team',
|
|
34
|
-
* },
|
|
35
|
-
* },
|
|
36
|
-
* {
|
|
37
|
-
* order: 3,
|
|
38
|
-
* type: 'wait',
|
|
39
|
-
* description: 'Wait 24 hours',
|
|
40
|
-
* params: {
|
|
41
|
-
* duration: '24 hours',
|
|
42
|
-
* },
|
|
43
|
-
* },
|
|
44
|
-
* {
|
|
45
|
-
* order: 4,
|
|
46
|
-
* type: 'notify',
|
|
47
|
-
* description: 'Send setup reminder',
|
|
48
|
-
* params: {
|
|
49
|
-
* channel: 'email',
|
|
50
|
-
* message: 'Reminder to complete setup',
|
|
51
|
-
* },
|
|
52
|
-
* condition: 'customer.setupCompleted === false',
|
|
53
|
-
* },
|
|
54
|
-
* ],
|
|
55
|
-
* })
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export function Workflow(definition) {
|
|
59
|
-
if (!definition.name) {
|
|
60
|
-
throw new Error('Workflow name is required');
|
|
61
|
-
}
|
|
62
|
-
if (!definition.trigger) {
|
|
63
|
-
throw new Error('Workflow trigger is required');
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
...definition,
|
|
67
|
-
actions: definition.actions || [],
|
|
68
|
-
metadata: definition.metadata || {},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Get actions in execution order
|
|
73
|
-
*/
|
|
74
|
-
export function getActionsInOrder(workflow) {
|
|
75
|
-
return [...(workflow.actions || [])].sort((a, b) => a.order - b.order);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Get actions by type
|
|
79
|
-
*/
|
|
80
|
-
export function getActionsByType(workflow, type) {
|
|
81
|
-
return workflow.actions?.filter(action => action.type === type) || [];
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Get conditional actions
|
|
85
|
-
*/
|
|
86
|
-
export function getConditionalActions(workflow) {
|
|
87
|
-
return workflow.actions?.filter(action => action.condition) || [];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Add action to workflow
|
|
91
|
-
*/
|
|
92
|
-
export function addAction(workflow, action) {
|
|
93
|
-
return {
|
|
94
|
-
...workflow,
|
|
95
|
-
actions: [...(workflow.actions || []), action],
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Remove action from workflow
|
|
100
|
-
*/
|
|
101
|
-
export function removeAction(workflow, order) {
|
|
102
|
-
return {
|
|
103
|
-
...workflow,
|
|
104
|
-
actions: workflow.actions?.filter(a => a.order !== order),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Update action in workflow
|
|
109
|
-
*/
|
|
110
|
-
export function updateAction(workflow, order, updates) {
|
|
111
|
-
const actions = workflow.actions?.map(action => action.order === order ? { ...action, ...updates } : action);
|
|
112
|
-
return {
|
|
113
|
-
...workflow,
|
|
114
|
-
actions,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Check if trigger is event-based
|
|
119
|
-
*/
|
|
120
|
-
export function isEventTrigger(trigger) {
|
|
121
|
-
return trigger.type === 'event';
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Check if trigger is schedule-based
|
|
125
|
-
*/
|
|
126
|
-
export function isScheduleTrigger(trigger) {
|
|
127
|
-
return trigger.type === 'schedule';
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Check if trigger is webhook-based
|
|
131
|
-
*/
|
|
132
|
-
export function isWebhookTrigger(trigger) {
|
|
133
|
-
return trigger.type === 'webhook';
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Parse wait duration to milliseconds
|
|
137
|
-
*/
|
|
138
|
-
export function parseWaitDuration(duration) {
|
|
139
|
-
const match = duration.match(/(\d+)\s*(ms|millisecond|milliseconds|s|second|seconds|m|minute|minutes|h|hour|hours|d|day|days)/);
|
|
140
|
-
if (!match)
|
|
141
|
-
return 0;
|
|
142
|
-
const value = parseInt(match[1] || '0', 10);
|
|
143
|
-
const unit = match[2];
|
|
144
|
-
switch (unit) {
|
|
145
|
-
case 'ms':
|
|
146
|
-
case 'millisecond':
|
|
147
|
-
case 'milliseconds':
|
|
148
|
-
return value;
|
|
149
|
-
case 's':
|
|
150
|
-
case 'second':
|
|
151
|
-
case 'seconds':
|
|
152
|
-
return value * 1000;
|
|
153
|
-
case 'm':
|
|
154
|
-
case 'minute':
|
|
155
|
-
case 'minutes':
|
|
156
|
-
return value * 60 * 1000;
|
|
157
|
-
case 'h':
|
|
158
|
-
case 'hour':
|
|
159
|
-
case 'hours':
|
|
160
|
-
return value * 60 * 60 * 1000;
|
|
161
|
-
case 'd':
|
|
162
|
-
case 'day':
|
|
163
|
-
case 'days':
|
|
164
|
-
return value * 24 * 60 * 60 * 1000;
|
|
165
|
-
default:
|
|
166
|
-
return 0;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Evaluate condition (simple implementation)
|
|
171
|
-
*/
|
|
172
|
-
export function evaluateCondition(condition, context) {
|
|
173
|
-
// This is a simplified implementation
|
|
174
|
-
// In production, use a proper expression evaluator
|
|
175
|
-
try {
|
|
176
|
-
// Replace variable references with actual values
|
|
177
|
-
let expression = condition;
|
|
178
|
-
for (const [key, value] of Object.entries(context)) {
|
|
179
|
-
const regex = new RegExp(`\\b${key}\\b`, 'g');
|
|
180
|
-
expression = expression.replace(regex, JSON.stringify(value));
|
|
181
|
-
}
|
|
182
|
-
// Evaluate the expression (unsafe in production - use a proper evaluator)
|
|
183
|
-
return Boolean(eval(expression));
|
|
184
|
-
}
|
|
185
|
-
catch {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Fill template with context values
|
|
191
|
-
*/
|
|
192
|
-
export function fillTemplate(template, context) {
|
|
193
|
-
return template.replace(/\{\{([^}]+)\}\}/g, (_, path) => {
|
|
194
|
-
const value = getNestedValue(context, path.trim());
|
|
195
|
-
return String(value ?? '');
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Get nested value from object by path
|
|
200
|
-
*/
|
|
201
|
-
function getNestedValue(obj, path) {
|
|
202
|
-
return path.split('.').reduce((acc, part) => acc?.[part], obj);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Validate workflow definition
|
|
206
|
-
*/
|
|
207
|
-
export function validateWorkflow(workflow) {
|
|
208
|
-
const errors = [];
|
|
209
|
-
if (!workflow.name) {
|
|
210
|
-
errors.push('Workflow name is required');
|
|
211
|
-
}
|
|
212
|
-
if (!workflow.trigger) {
|
|
213
|
-
errors.push('Workflow trigger is required');
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
if (workflow.trigger.type === 'event' && !workflow.trigger.event) {
|
|
217
|
-
errors.push('Event trigger must specify an event name');
|
|
218
|
-
}
|
|
219
|
-
if (workflow.trigger.type === 'schedule' && !workflow.trigger.schedule) {
|
|
220
|
-
errors.push('Schedule trigger must specify a schedule expression');
|
|
221
|
-
}
|
|
222
|
-
if (workflow.trigger.type === 'webhook' && !workflow.trigger.webhook) {
|
|
223
|
-
errors.push('Webhook trigger must specify a webhook URL');
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (workflow.actions) {
|
|
227
|
-
const orders = new Set();
|
|
228
|
-
for (const action of workflow.actions) {
|
|
229
|
-
if (!action.type) {
|
|
230
|
-
errors.push(`Action at order ${action.order} must have a type`);
|
|
231
|
-
}
|
|
232
|
-
if (orders.has(action.order)) {
|
|
233
|
-
errors.push(`Duplicate action order: ${action.order}`);
|
|
234
|
-
}
|
|
235
|
-
orders.add(action.order);
|
|
236
|
-
// Validate action-specific requirements
|
|
237
|
-
if (action.type === 'wait' && !action.params?.duration) {
|
|
238
|
-
errors.push(`Wait action at order ${action.order} must specify duration`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
valid: errors.length === 0,
|
|
244
|
-
errors,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
//# sourceMappingURL=workflow.js.map
|
package/dist/workflow.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.js","sourceRoot":"","sources":["../src/workflow.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,MAAM,UAAU,QAAQ,CAAC,UAA8B;IACrD,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAC9C,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,OAAO;QACL,GAAG,UAAU;QACb,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,EAAE;QACjC,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,EAAE;KACpC,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAA4B;IAC5D,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,K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AM,CAAC,KAAK,EAAE,CAAC,CAAA;YACxD,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAExB,wCAAwC;YACxC,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;gBACvD,MAAM,CAAC,IAAI,CAAC,wBAAwB,MAAM,CAAC,KAAK,wBAAwB,CAAC,CAAA;YAC3E,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;KACP,CAAA;AACH,CAAC"}
|
package/src/business.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
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
|
-
}
|
package/src/dollar.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* $ - Business operations helper
|
|
3
|
-
*
|
|
4
|
-
* Provides convenient functions for common business calculations and formatting
|
|
5
|
-
*/
|
|
6
|
-
import { formatCurrency, calculateGrowthRate, calculateGrossMargin, calculateROI, calculateCAC, calculateBurnRate, calculateRunway, } from './financials.js';
|
|
7
|
-
/**
|
|
8
|
-
* Create a business operations helper with context
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* import { $ } from 'business-as-code'
|
|
13
|
-
*
|
|
14
|
-
* // Format currency
|
|
15
|
-
* console.log($.format(1234.56)) // "$1,234.56"
|
|
16
|
-
* console.log($.format(1000, 'EUR')) // "€1,000"
|
|
17
|
-
*
|
|
18
|
-
* // Calculate percentage
|
|
19
|
-
* console.log($.percent(25, 100)) // 25
|
|
20
|
-
*
|
|
21
|
-
* // Calculate growth
|
|
22
|
-
* console.log($.growth(120, 100)) // 20
|
|
23
|
-
*
|
|
24
|
-
* // Calculate margin
|
|
25
|
-
* console.log($.margin(100, 60)) // 40
|
|
26
|
-
*
|
|
27
|
-
* // Calculate ROI
|
|
28
|
-
* console.log($.roi(150, 100)) // 50
|
|
29
|
-
*
|
|
30
|
-
* // Calculate LTV
|
|
31
|
-
* console.log($.ltv(100, 12, 24)) // 28800
|
|
32
|
-
*
|
|
33
|
-
* // Calculate CAC
|
|
34
|
-
* console.log($.cac(10000, 100)) // 100
|
|
35
|
-
*
|
|
36
|
-
* // Calculate burn rate
|
|
37
|
-
* console.log($.burnRate(100000, 70000, 3)) // 10000
|
|
38
|
-
*
|
|
39
|
-
* // Calculate runway
|
|
40
|
-
* console.log($.runway(100000, 10000)) // 10
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export function createBusinessOperations(initialContext) {
|
|
44
|
-
const context = initialContext || {};
|
|
45
|
-
return {
|
|
46
|
-
format: (amount, currency) => {
|
|
47
|
-
return formatCurrency(amount, currency || context.business?.metadata?.currency || 'USD');
|
|
48
|
-
},
|
|
49
|
-
percent: (value, total) => {
|
|
50
|
-
if (total === 0)
|
|
51
|
-
return 0;
|
|
52
|
-
return (value / total) * 100;
|
|
53
|
-
},
|
|
54
|
-
growth: (current, previous) => {
|
|
55
|
-
return calculateGrowthRate(current, previous);
|
|
56
|
-
},
|
|
57
|
-
margin: (revenue, cost) => {
|
|
58
|
-
return calculateGrossMargin(revenue, cost);
|
|
59
|
-
},
|
|
60
|
-
roi: (gain, cost) => {
|
|
61
|
-
return calculateROI(gain, cost);
|
|
62
|
-
},
|
|
63
|
-
ltv: (averageValue, frequency, lifetime) => {
|
|
64
|
-
// frequency = purchases per year, lifetime = years
|
|
65
|
-
const annualValue = averageValue * frequency;
|
|
66
|
-
return annualValue * lifetime;
|
|
67
|
-
},
|
|
68
|
-
cac: (marketingSpend, newCustomers) => {
|
|
69
|
-
return calculateCAC(marketingSpend, newCustomers);
|
|
70
|
-
},
|
|
71
|
-
burnRate: (cashStart, cashEnd, months) => {
|
|
72
|
-
return calculateBurnRate(cashStart, cashEnd, months);
|
|
73
|
-
},
|
|
74
|
-
runway: (cash, burnRate) => {
|
|
75
|
-
return calculateRunway(cash, burnRate);
|
|
76
|
-
},
|
|
77
|
-
context,
|
|
78
|
-
log: (event, data) => {
|
|
79
|
-
console.log(`[Business Event] ${event}`, data || '');
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Default business operations instance
|
|
85
|
-
*/
|
|
86
|
-
export const $ = createBusinessOperations();
|
|
87
|
-
/**
|
|
88
|
-
* Update business context
|
|
89
|
-
*/
|
|
90
|
-
export function updateContext(updates) {
|
|
91
|
-
Object.assign($.context, updates);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Get current business context
|
|
95
|
-
*/
|
|
96
|
-
export function getContext() {
|
|
97
|
-
return $.context;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Reset business context
|
|
101
|
-
*/
|
|
102
|
-
export function resetContext() {
|
|
103
|
-
Object.keys($.context).forEach(key => {
|
|
104
|
-
delete $.context[key];
|
|
105
|
-
});
|
|
106
|
-
}
|