business-as-code 0.0.2 → 0.2.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/README.md +209 -379
- package/dist/index.d.ts +4 -146
- package/dist/index.js +1051 -143
- package/dist/index.js.map +1 -0
- package/dist/loaders/index.d.ts +174 -0
- package/dist/loaders/index.js +366 -0
- package/dist/loaders/index.js.map +1 -0
- package/dist/schema/index.d.ts +146 -0
- package/dist/schema/index.js +716 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/types-CJ9eGS_C.d.ts +86 -0
- package/package.json +55 -36
package/README.md
CHANGED
|
@@ -1,431 +1,261 @@
|
|
|
1
|
+
# business-as-code
|
|
2
|
+
|
|
1
3
|
[](https://www.npmjs.com/package/business-as-code)
|
|
2
|
-
[](https://www.npmjs.com/package/business-as-code)
|
|
3
4
|
[](https://opensource.org/licenses/MIT)
|
|
4
|
-
[](https://www.typescriptlang.org/)
|
|
5
|
-
[](https://discord.gg/tafnNeUQdm)
|
|
6
|
-
[](https://github.com/drivly/ai/issues)
|
|
7
|
-
[](https://github.com/drivly/ai)
|
|
8
|
-
|
|
9
|
-
# business-as-code
|
|
10
5
|
|
|
11
|
-
>
|
|
6
|
+
> Define, launch, experiment, iterate, and grow your business entirely in code
|
|
12
7
|
|
|
13
8
|
## Overview
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
This paradigm builds upon core primitives like Functions, Workflows, and Agents, allowing complex business logic, processes, and even autonomous operations to be codified. By treating the business itself as a software system, we unlock unprecedented levels of agility, transparency, experimentation, and optimization.
|
|
18
|
-
|
|
19
|
-
Drawing inspiration from the principles outlined in the [Manifesto](/docs/manifesto) and leveraging the foundational [Primitives](/docs/primitives) of the [.do](https://dotdo.ai) ecosystem, `business-as-code` provides the framework to transform strategic objectives into measurable outcomes through code.
|
|
20
|
-
|
|
21
|
-
## Declarative vs. Imperative Approaches
|
|
22
|
-
|
|
23
|
-
The `business-as-code` package supports two complementary approaches to defining and executing business logic:
|
|
24
|
-
|
|
25
|
-
### Declarative Approach
|
|
26
|
-
|
|
27
|
-
Define your business at a high level using objectives and key results (OKRs). The system, powered by AI, determines the optimal implementation strategy. This approach is ideal for setting strategic direction and allowing flexibility in execution.
|
|
28
|
-
|
|
29
|
-
```typescript
|
|
30
|
-
import { Business } from 'business-as-code'
|
|
31
|
-
|
|
32
|
-
const myBusiness = Business({
|
|
33
|
-
name: 'TechInnovators',
|
|
34
|
-
vision: 'Democratize AI for small businesses',
|
|
35
|
-
objectives: {
|
|
36
|
-
customerSuccess: {
|
|
37
|
-
description: 'Create delighted customers who achieve their goals',
|
|
38
|
-
keyResults: [
|
|
39
|
-
'Achieve 95% customer satisfaction score by Q4',
|
|
40
|
-
'Reduce average support ticket resolution time by 30% within 6 months',
|
|
41
|
-
'Increase customer retention rate to 85% year-over-year',
|
|
42
|
-
]
|
|
43
|
-
},
|
|
44
|
-
productInnovation: {
|
|
45
|
-
description: 'Continuously deliver cutting-edge AI solutions',
|
|
46
|
-
keyResults: [
|
|
47
|
-
'Launch 3 new major features based on customer feedback this year',
|
|
48
|
-
'Secure 2 patents for novel AI algorithms',
|
|
49
|
-
'Increase R&D investment by 15% annually',
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
// More objectives...
|
|
53
|
-
}
|
|
54
|
-
})
|
|
10
|
+
`business-as-code` provides a schema-first approach to defining business entities. Write your business model in MDX, YAML, or JSON, and use it across different platforms.
|
|
55
11
|
|
|
56
|
-
|
|
57
|
-
|
|
12
|
+
```
|
|
13
|
+
business-as-code (portable schema layer)
|
|
14
|
+
↓
|
|
15
|
+
┌───┴───┐
|
|
16
|
+
↓ ↓
|
|
17
|
+
Startups.Studio Platform.do
|
|
18
|
+
(AI startups) (Enterprise)
|
|
58
19
|
```
|
|
59
20
|
|
|
60
|
-
|
|
21
|
+
This is the **schema definition layer** - it defines what your business entities look like. It works alongside runtime packages like [agents.do](https://agents.do), [workflows.do](https://workflows.do), and [humans.do](https://humans.do) which handle the actual business operations.
|
|
61
22
|
|
|
62
|
-
|
|
23
|
+
## Installation
|
|
63
24
|
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
name: 'CustomerOnboarding',
|
|
69
|
-
|
|
70
|
-
onCustomerSignup: async ({ ai, api, db, event }) => {
|
|
71
|
-
const { name, email, company } = event
|
|
72
|
-
|
|
73
|
-
// Step 1: Enrich contact details using Integrations.do
|
|
74
|
-
const enrichedContact = await api.apollo.search({ name, email, company })
|
|
75
|
-
|
|
76
|
-
// Step 2: Analyze company background using Functions.do
|
|
77
|
-
const companyProfile = await ai.researchCompany({ company: enrichedContact.companyName || company })
|
|
78
|
-
|
|
79
|
-
// Step 3: Personalize welcome email using Functions.do
|
|
80
|
-
const welcomeEmail = await ai.personalizeWelcomeEmail({
|
|
81
|
-
name,
|
|
82
|
-
companyProfile
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
// Step 4: Send email using Integrations.do
|
|
86
|
-
await api.sendgrid.sendEmail({
|
|
87
|
-
to: email,
|
|
88
|
-
subject: 'Welcome to TechInnovators!', // Hardcoded name for example clarity
|
|
89
|
-
body: welcomeEmail.content
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
// Step 5: Create user record in Database.do
|
|
93
|
-
await db.users.create({
|
|
94
|
-
name,
|
|
95
|
-
email,
|
|
96
|
-
company: enrichedContact.companyName || company,
|
|
97
|
-
enrichedData: enrichedContact
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
// Step 6: Notify team via Slack using Integrations.do
|
|
101
|
-
await api.slack.postMessage({
|
|
102
|
-
channel: '#signups',
|
|
103
|
-
content: `New signup: ${name} from ${company}`,
|
|
104
|
-
})
|
|
105
|
-
}
|
|
106
|
-
})
|
|
25
|
+
```bash
|
|
26
|
+
npm install business-as-code
|
|
27
|
+
# or
|
|
28
|
+
pnpm add business-as-code
|
|
107
29
|
```
|
|
108
30
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
The true power emerges when combining both approaches. Define high-level business goals declaratively, and implement specific, critical processes imperatively within the same framework.
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
const combinedBusiness = Business({
|
|
115
|
-
name: 'HybridSolutions',
|
|
116
|
-
vision: '...',
|
|
117
|
-
objectives: { /* ... */ },
|
|
118
|
-
|
|
119
|
-
// Define specific workflows imperatively
|
|
120
|
-
workflows: {
|
|
121
|
-
customerOnboarding, // Reuse the imperative workflow defined above
|
|
122
|
-
// Add other critical workflows...
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
// Define autonomous agents
|
|
126
|
-
agents: {
|
|
127
|
-
// Agents can leverage both declarative goals and imperative workflows
|
|
128
|
-
}
|
|
129
|
-
})
|
|
31
|
+
## Quick Start
|
|
130
32
|
|
|
131
|
-
|
|
132
|
-
// while respecting the defined imperative workflows.
|
|
133
|
-
await combinedBusiness.launch()
|
|
134
|
-
```
|
|
33
|
+
### Use the Default Business Schema
|
|
135
34
|
|
|
136
|
-
|
|
35
|
+
The package includes a comprehensive default schema with 40+ business entities across 9 domains:
|
|
137
36
|
|
|
138
|
-
|
|
37
|
+
```typescript
|
|
38
|
+
import { defaultBusinessSchema, getAllNouns } from 'business-as-code'
|
|
139
39
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
40
|
+
// Get all nouns from the default business schema
|
|
41
|
+
const nouns = getAllNouns(defaultBusinessSchema)
|
|
42
|
+
console.log(`${nouns.length} nouns loaded`)
|
|
143
43
|
|
|
144
|
-
|
|
44
|
+
// Access specific noun schemas directly
|
|
45
|
+
import { Customers, Products, Invoices, Projects, Teams } from 'business-as-code'
|
|
46
|
+
```
|
|
145
47
|
|
|
146
|
-
|
|
48
|
+
### Define Custom Business in MDX
|
|
147
49
|
|
|
148
|
-
|
|
50
|
+
MDX provides the most expressive way to define business entities with JSX-like syntax:
|
|
149
51
|
|
|
150
52
|
```typescript
|
|
151
|
-
import {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
name
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
character: 'Project Managers',
|
|
174
|
-
problem: 'Overwhelmed by complexity and delays',
|
|
175
|
-
plan: 'Implement AgileAI for streamlined workflows',
|
|
176
|
-
success: 'Effortless project delivery and happy teams',
|
|
177
|
-
failure: 'Continued chaos and missed deadlines',
|
|
178
|
-
}),
|
|
179
|
-
// Add other relevant model components...
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
workflows: { /* ... */ },
|
|
183
|
-
agents: { /* ... */ },
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
await myStartup.launch()
|
|
53
|
+
import { loadFromMDX, mergeSchemas, defaultBusinessSchema } from 'business-as-code'
|
|
54
|
+
|
|
55
|
+
const mdx = `
|
|
56
|
+
<Business name="My SaaS">
|
|
57
|
+
<Noun name="Tenant" group="Admin">
|
|
58
|
+
<Name text required />
|
|
59
|
+
<Subdomain text unique />
|
|
60
|
+
<Plan status="free|pro|enterprise" />
|
|
61
|
+
<Owner user />
|
|
62
|
+
</Noun>
|
|
63
|
+
|
|
64
|
+
<Noun name="Feature" group="Product">
|
|
65
|
+
<Name text required />
|
|
66
|
+
<Description rich />
|
|
67
|
+
<Tier status="free|pro|enterprise" />
|
|
68
|
+
<Enabled boolean />
|
|
69
|
+
</Noun>
|
|
70
|
+
</Business>
|
|
71
|
+
`
|
|
72
|
+
|
|
73
|
+
const customSchema = await loadFromMDX(mdx)
|
|
74
|
+
const fullSchema = mergeSchemas(defaultBusinessSchema, customSchema)
|
|
187
75
|
```
|
|
188
76
|
|
|
189
|
-
|
|
77
|
+
### Define Custom Business in YAML
|
|
190
78
|
|
|
191
|
-
|
|
79
|
+
YAML is ideal for configuration files and version control:
|
|
192
80
|
|
|
193
81
|
```typescript
|
|
194
|
-
import {
|
|
195
|
-
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const { email } = event
|
|
222
|
-
await api.auth.createAccount({ email })
|
|
223
|
-
await api.sendgrid.sendEmail({ to: email, template: 'quick_welcome' })
|
|
224
|
-
// ... fewer steps than control
|
|
225
|
-
}
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
metrics: ['signupConversionRate', 'timeToSignup'],
|
|
230
|
-
trafficSplit: { control: 0.5, simplified: 0.5 },
|
|
231
|
-
targetObjective: experimentalBusiness.objectives.userAcquisition,
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
// Add the experiment to the business definition
|
|
235
|
-
experimentalBusiness.addExperiment(onboardingExperiment)
|
|
236
|
-
|
|
237
|
-
// Launch the business with the experiment running
|
|
238
|
-
await experimentalBusiness.launch()
|
|
239
|
-
|
|
240
|
-
// Later, analyze results (assuming analysis functions exist)
|
|
241
|
-
// const results = await experimentalBusiness.analyzeExperiment('Onboarding Flow Test')
|
|
242
|
-
// console.log(results)
|
|
82
|
+
import { loadFromYAML } from 'business-as-code'
|
|
83
|
+
|
|
84
|
+
const yaml = `
|
|
85
|
+
name: My SaaS
|
|
86
|
+
version: 1.0.0
|
|
87
|
+
|
|
88
|
+
domains:
|
|
89
|
+
admin:
|
|
90
|
+
- name: Tenant
|
|
91
|
+
titleField: name
|
|
92
|
+
fields:
|
|
93
|
+
name: text required
|
|
94
|
+
subdomain: text unique
|
|
95
|
+
plan: status:free|pro|enterprise
|
|
96
|
+
owner: ref:users
|
|
97
|
+
|
|
98
|
+
product:
|
|
99
|
+
- name: Feature
|
|
100
|
+
titleField: name
|
|
101
|
+
fields:
|
|
102
|
+
name: text required
|
|
103
|
+
description: rich
|
|
104
|
+
tier: status:free|pro|enterprise
|
|
105
|
+
enabled: boolean
|
|
106
|
+
`
|
|
107
|
+
|
|
108
|
+
const schema = loadFromYAML(yaml)
|
|
243
109
|
```
|
|
244
110
|
|
|
245
|
-
|
|
111
|
+
### Define Custom Business in JSON
|
|
246
112
|
|
|
247
|
-
|
|
113
|
+
JSON works well for programmatic generation and API responses:
|
|
248
114
|
|
|
249
115
|
```typescript
|
|
250
|
-
import {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
// If visitor shows interest (e.g., downloads whitepaper)
|
|
265
|
-
if (event.action === 'download_whitepaper') {
|
|
266
|
-
const leadData = await api.hubspot.findContact({ email: event.email }) // Use Integrations.do
|
|
267
|
-
if (!leadData) {
|
|
268
|
-
await api.hubspot.createContact({ email: event.email, name: event.name })
|
|
269
|
-
await api.slack.postMessage({ channel: '#leads', content: `New lead: ${event.name} (${event.email})`})
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
})
|
|
274
|
-
|
|
275
|
-
// Example: Customer Support Agent
|
|
276
|
-
const supportAgent = Agent({
|
|
277
|
-
name: 'SupportAgent',
|
|
278
|
-
goal: 'Resolve customer support tickets efficiently and effectively',
|
|
279
|
-
keyResults: [
|
|
280
|
-
'Maintain average first response time under 1 hour',
|
|
281
|
-
'Achieve customer satisfaction score (CSAT) of 90%+'
|
|
282
|
-
],
|
|
283
|
-
onTicketReceived: async ({ ai, api, db, ticket }) => {
|
|
284
|
-
// Analyze ticket content
|
|
285
|
-
const analysis = await ai.analyzeSupportTicket({ content: ticket.description })
|
|
286
|
-
|
|
287
|
-
// Find relevant documentation using Functions.do
|
|
288
|
-
const relevantDocs = await ai.findRelevantDocs({ query: analysis.topic })
|
|
289
|
-
|
|
290
|
-
// Draft response
|
|
291
|
-
const draftResponse = await ai.draftSupportResponse({
|
|
292
|
-
query: ticket.description,
|
|
293
|
-
context: relevantDocs
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
// Post response (or assign to human if needed)
|
|
297
|
-
await api.zendesk.updateTicket({ id: ticket.id, comment: draftResponse.content })
|
|
298
|
-
}
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
// Define the complete SaaS business
|
|
302
|
-
const saasCompany = Business({
|
|
303
|
-
name: 'DataInsights',
|
|
304
|
-
vision: 'Make data analytics accessible to non-technical teams',
|
|
305
|
-
|
|
306
|
-
objectives: {
|
|
307
|
-
growth: {
|
|
308
|
-
description: 'Achieve market leadership in SMB analytics',
|
|
309
|
-
keyResults: [
|
|
310
|
-
'Acquire 1000 paying customers by end of year',
|
|
311
|
-
'Reach $1M ARR within 18 months',
|
|
312
|
-
]
|
|
313
|
-
},
|
|
314
|
-
product: {
|
|
315
|
-
description: 'Deliver an intuitive and powerful analytics platform',
|
|
316
|
-
keyResults: [
|
|
317
|
-
'Achieve a Net Promoter Score (NPS) of 50+',
|
|
318
|
-
'Reduce onboarding time to under 30 minutes',
|
|
319
|
-
]
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
// Integrate defined workflows
|
|
324
|
-
workflows: {
|
|
325
|
-
leadGeneration,
|
|
326
|
-
customerOnboarding, // Reuse from earlier example
|
|
327
|
-
// Add billing, feature-request workflows etc.
|
|
328
|
-
},
|
|
329
|
-
|
|
330
|
-
// Integrate defined agents
|
|
331
|
-
agents: {
|
|
332
|
-
supportAgent,
|
|
333
|
-
// Add sales outreach agent, data analysis agent etc.
|
|
334
|
-
},
|
|
335
|
-
|
|
336
|
-
// Define the core data model using Database.do concepts
|
|
337
|
-
dataModel: {
|
|
338
|
-
users: Database.collection({ /* ... schema ... */ }),
|
|
339
|
-
organizations: Database.collection({ /* ... schema ... */ }),
|
|
340
|
-
datasets: Database.collection({ /* ... schema ... */ }),
|
|
341
|
-
reports: Database.collection({ /* ... schema ... */ }),
|
|
342
|
-
// Define relationships, indexes etc.
|
|
343
|
-
},
|
|
344
|
-
|
|
345
|
-
// Define core functions the business relies on
|
|
346
|
-
functions: {
|
|
347
|
-
// Example: A function to generate insights from data
|
|
348
|
-
generateReportInsights: Function({
|
|
349
|
-
name: 'GenerateReportInsights',
|
|
350
|
-
input: { reportId: 'string' },
|
|
351
|
-
output: { insights: 'string[]' },
|
|
352
|
-
run: async ({ input, ai, db }) => {
|
|
353
|
-
const reportData = await db.reports.find({ id: input.reportId })
|
|
354
|
-
// Complex AI logic to derive insights...
|
|
355
|
-
const insights = await ai.analyzeDataAndGenerateInsights({ data: reportData })
|
|
356
|
-
return { insights }
|
|
116
|
+
import { loadFromJSON } from 'business-as-code'
|
|
117
|
+
|
|
118
|
+
const json = {
|
|
119
|
+
name: "My SaaS",
|
|
120
|
+
version: "1.0.0",
|
|
121
|
+
domains: {
|
|
122
|
+
admin: [{
|
|
123
|
+
name: "Tenant",
|
|
124
|
+
titleField: "name",
|
|
125
|
+
fields: {
|
|
126
|
+
name: "text required",
|
|
127
|
+
subdomain: "text unique",
|
|
128
|
+
plan: "status:free|pro|enterprise"
|
|
357
129
|
}
|
|
358
|
-
}
|
|
359
|
-
// Add other core business functions
|
|
130
|
+
}]
|
|
360
131
|
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
// Launch the business operations
|
|
364
|
-
await saasCompany.launch()
|
|
132
|
+
}
|
|
365
133
|
|
|
366
|
-
|
|
134
|
+
const schema = loadFromJSON(JSON.stringify(json))
|
|
367
135
|
```
|
|
368
136
|
|
|
369
|
-
##
|
|
137
|
+
## Domains
|
|
138
|
+
|
|
139
|
+
The default business schema includes these domains:
|
|
140
|
+
|
|
141
|
+
| Domain | Nouns | Description |
|
|
142
|
+
|--------|-------|-------------|
|
|
143
|
+
| **Admin** | Users, Orgs, ServiceAccounts | System administration |
|
|
144
|
+
| **Business** | Businesses, Goals, Metrics, Teams, Processes | Core business entities |
|
|
145
|
+
| **Product** | Products, Services, Offers, Prices, Features | Product catalog |
|
|
146
|
+
| **Success** | Customers, Contacts, Subscriptions | Customer success |
|
|
147
|
+
| **Sales** | Deals, Quotes, Proposals | Sales pipeline |
|
|
148
|
+
| **Marketing** | Leads, Brands, Domains, Competitors | Marketing & branding |
|
|
149
|
+
| **Work** | Projects, Tasks, Issues, Workflows, Roles, Agents | Work management |
|
|
150
|
+
| **Financial** | Invoices, Payments, Refunds, ChartOfAccounts, JournalEntries | Accounting |
|
|
151
|
+
| **Communications** | Channels, Messages, Sequences, Templates, Posts | Messaging |
|
|
152
|
+
|
|
153
|
+
## Field Types
|
|
154
|
+
|
|
155
|
+
### Primitive Types
|
|
156
|
+
| Type | Description | Example |
|
|
157
|
+
|------|-------------|---------|
|
|
158
|
+
| `text` | Single-line text | `name: text` |
|
|
159
|
+
| `rich` | Rich text / markdown | `description: rich` |
|
|
160
|
+
| `number` | Numeric value | `count: number` |
|
|
161
|
+
| `boolean` | True/false checkbox | `isActive: boolean` |
|
|
162
|
+
| `date` | Date picker | `createdAt: date` |
|
|
163
|
+
|
|
164
|
+
### Semantic Types (with validation)
|
|
165
|
+
| Type | Description | Example |
|
|
166
|
+
|------|-------------|---------|
|
|
167
|
+
| `email` | Email address | `email: email` |
|
|
168
|
+
| `url` | Valid URL | `website: url` |
|
|
169
|
+
| `phone` | Phone number | `phone: phone` |
|
|
170
|
+
| `slug` | URL-safe slug | `slug: slug` |
|
|
171
|
+
|
|
172
|
+
### Business Types
|
|
173
|
+
| Type | Description | Example |
|
|
174
|
+
|------|-------------|---------|
|
|
175
|
+
| `money` | Currency amount | `price: money` |
|
|
176
|
+
| `score` | 0-100 value | `health: score` |
|
|
177
|
+
| `status:a\|b\|c` | Select options | `status: status:active\|inactive` |
|
|
178
|
+
|
|
179
|
+
### Relationship Types
|
|
180
|
+
| Type | Description | Example |
|
|
181
|
+
|------|-------------|---------|
|
|
182
|
+
| `ref:collection` | Reference to another noun | `customer: ref:customers` |
|
|
183
|
+
| `user` | Reference to users | `owner: user` |
|
|
184
|
+
|
|
185
|
+
### Modifiers
|
|
186
|
+
| Modifier | Description | Example |
|
|
187
|
+
|----------|-------------|---------|
|
|
188
|
+
| `required` | Field must have value | `name: text required` |
|
|
189
|
+
| `unique` | Value must be unique | `slug: text unique` |
|
|
190
|
+
|
|
191
|
+
## API Reference
|
|
192
|
+
|
|
193
|
+
### Schema Functions
|
|
370
194
|
|
|
371
|
-
|
|
195
|
+
```typescript
|
|
196
|
+
import {
|
|
197
|
+
defaultBusinessSchema, // The complete default schema
|
|
198
|
+
getAllNouns, // Get all nouns as flat array
|
|
199
|
+
getDomainNouns, // Get nouns for a specific domain
|
|
200
|
+
getDomains, // Get list of all domain names
|
|
201
|
+
findNounBySlug, // Find a noun by its slug
|
|
202
|
+
mergeSchemas, // Merge two schemas together
|
|
203
|
+
validateSchema, // Validate a schema structure
|
|
204
|
+
createMinimalSchema, // Create empty schema scaffold
|
|
205
|
+
} from 'business-as-code'
|
|
206
|
+
```
|
|
372
207
|
|
|
373
|
-
|
|
208
|
+
### Loaders
|
|
374
209
|
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
210
|
+
```typescript
|
|
211
|
+
import {
|
|
212
|
+
load, // Auto-detect format and load
|
|
213
|
+
loadFromMDX, // Load from MDX source
|
|
214
|
+
loadFromYAML, // Load from YAML source
|
|
215
|
+
loadFromJSON, // Load from JSON source
|
|
216
|
+
loadNoun, // Load a single noun definition
|
|
217
|
+
loadNouns, // Load multiple noun definitions
|
|
218
|
+
} from 'business-as-code'
|
|
381
219
|
```
|
|
382
220
|
|
|
383
|
-
###
|
|
384
|
-
|
|
385
|
-
1. **Import necessary components**: Start by importing `Business` and other primitives like `Workflow`, `Agent`, or `Function` as needed.
|
|
386
|
-
2. **Define your Business**: Use the `Business()` constructor, providing a name, vision, and objectives.
|
|
387
|
-
3. **Codify Components**: Define your core workflows, agents, data models, and functions using the respective primitives.
|
|
388
|
-
4. **Integrate Components**: Add your defined workflows, agents, etc., into the `Business` definition.
|
|
389
|
-
5. **Launch**: Call the `.launch()` method on your business instance to start its operations.
|
|
221
|
+
### Serializers
|
|
390
222
|
|
|
391
223
|
```typescript
|
|
392
|
-
import {
|
|
393
|
-
|
|
394
|
-
//
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
keyResults: ['Successfully automate task X by end of Q3']
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
// Add simple workflows or functions if needed
|
|
405
|
-
})
|
|
224
|
+
import {
|
|
225
|
+
serialize, // Serialize schema to YAML or JSON
|
|
226
|
+
toYAML, // Serialize to YAML string
|
|
227
|
+
toJSON, // Serialize to JSON string
|
|
228
|
+
serializeNoun, // Serialize single noun
|
|
229
|
+
nounToYAML, // Noun to YAML
|
|
230
|
+
nounToJSON, // Noun to JSON
|
|
231
|
+
} from 'business-as-code'
|
|
232
|
+
```
|
|
406
233
|
|
|
407
|
-
|
|
408
|
-
async function start() {
|
|
409
|
-
await mySimpleBusiness.launch()
|
|
410
|
-
console.log('Business launched!')
|
|
411
|
-
}
|
|
234
|
+
### Types
|
|
412
235
|
|
|
413
|
-
|
|
236
|
+
```typescript
|
|
237
|
+
import type {
|
|
238
|
+
BusinessSchema, // Complete business schema
|
|
239
|
+
BusinessDomain, // Domain name type
|
|
240
|
+
NounSchema, // Individual noun definition
|
|
241
|
+
FieldSchema, // Field definition
|
|
242
|
+
FieldType, // Field type union
|
|
243
|
+
LoaderOptions, // Options for loaders
|
|
244
|
+
LoadResult, // Result from load operations
|
|
245
|
+
} from 'business-as-code'
|
|
414
246
|
```
|
|
415
247
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
## License
|
|
248
|
+
## Integration
|
|
419
249
|
|
|
420
|
-
|
|
250
|
+
`business-as-code` provides the schema layer that integrates with the broader .do ecosystem:
|
|
421
251
|
|
|
422
|
-
|
|
252
|
+
- **[db.sb](https://db.sb)** - Database runtime that executes these schemas
|
|
253
|
+
- **[Startups.Studio](https://startups.studio)** - AI-operated autonomous startups
|
|
254
|
+
- **[Platform.do](https://platform.do)** - Enterprise business platform
|
|
255
|
+
- **[agents.do](https://agents.do)** - AI agents for business operations
|
|
256
|
+
- **[workflows.do](https://workflows.do)** - Business process automation
|
|
257
|
+
- **[humans.do](https://humans.do)** - Human role definitions
|
|
423
258
|
|
|
424
|
-
|
|
259
|
+
## License
|
|
425
260
|
|
|
426
|
-
|
|
427
|
-
- [functions.do](https://www.npmjs.com/package/functions.do) - AI-powered Functions-as-a-Service.
|
|
428
|
-
- [workflows.do](https://www.npmjs.com/package/workflows.do) - Elegant business process orchestration.
|
|
429
|
-
- [agents.do](https://www.npmjs.com/package/agents.do) - Autonomous AI workers.
|
|
430
|
-
- [database.do](https://www.npmjs.com/package/database.do) - AI Native Data Access.
|
|
431
|
-
- Other `.do` services as needed (Events, Analytics, etc.)
|
|
261
|
+
MIT
|