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/dist/index.js CHANGED
@@ -1,172 +1,1080 @@
1
- // src/business.ts
2
- function Business(config) {
3
- const experiments = [];
4
- const state = {
5
- isLaunched: false,
6
- isExecuting: false,
7
- metrics: {}
1
+ // src/schema/domains/admin.ts
2
+ var Users = {
3
+ slug: "users",
4
+ group: "Admin",
5
+ titleField: "email",
6
+ fields: [
7
+ { name: "email", type: "email", required: true, unique: true },
8
+ { name: "name", type: "text" },
9
+ { name: "avatar", type: "image" },
10
+ { name: "role", type: "status", options: ["admin", "user", "viewer"] }
11
+ ]
12
+ };
13
+ var Orgs = {
14
+ slug: "orgs",
15
+ group: "Admin",
16
+ titleField: "name",
17
+ fields: [
18
+ { name: "name", type: "text", required: true },
19
+ { name: "slug", type: "text", required: true, unique: true },
20
+ { name: "logo", type: "image" },
21
+ { name: "domain", type: "text" }
22
+ ]
23
+ };
24
+ var ServiceAccounts = {
25
+ slug: "service-accounts",
26
+ group: "Admin",
27
+ titleField: "name",
28
+ fields: [
29
+ { name: "name", type: "text", required: true },
30
+ { name: "org", type: "ref", config: { relationTo: "orgs" } },
31
+ { name: "apiKey", type: "text", unique: true },
32
+ { name: "scopes", type: "array" }
33
+ ]
34
+ };
35
+ var adminNouns = [Users, Orgs, ServiceAccounts];
36
+
37
+ // src/schema/domains/business.ts
38
+ var Businesses = {
39
+ slug: "businesses",
40
+ group: "Business",
41
+ titleField: "name",
42
+ fields: [
43
+ { name: "name", type: "text", required: true },
44
+ { name: "legalName", type: "text" },
45
+ { name: "type", type: "status", options: ["LLC", "Corporation", "Partnership", "Sole Proprietorship", "Nonprofit"] },
46
+ { name: "status", type: "status", options: ["Active", "Inactive", "Dissolved"] },
47
+ { name: "foundedDate", type: "date" },
48
+ { name: "website", type: "url" },
49
+ { name: "description", type: "rich" }
50
+ ]
51
+ };
52
+ var Goals = {
53
+ slug: "goals",
54
+ group: "Business",
55
+ titleField: "name",
56
+ fields: [
57
+ { name: "name", type: "text", required: true },
58
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
59
+ { name: "type", type: "status", options: ["Revenue", "Growth", "Retention", "Efficiency", "Quality"] },
60
+ { name: "targetValue", type: "number" },
61
+ { name: "currentValue", type: "number" },
62
+ { name: "unit", type: "text" },
63
+ { name: "deadline", type: "date" },
64
+ { name: "status", type: "status", options: ["Not Started", "In Progress", "At Risk", "Achieved"] }
65
+ ]
66
+ };
67
+ var Metrics = {
68
+ slug: "metrics",
69
+ group: "Business",
70
+ titleField: "name",
71
+ fields: [
72
+ { name: "name", type: "text", required: true },
73
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
74
+ { name: "type", type: "status", options: ["KPI", "OKR", "North Star", "Health", "Vanity"] },
75
+ { name: "value", type: "number" },
76
+ { name: "unit", type: "text" },
77
+ { name: "frequency", type: "status", options: ["Real-time", "Daily", "Weekly", "Monthly", "Quarterly"] }
78
+ ]
79
+ };
80
+ var Teams = {
81
+ slug: "teams",
82
+ group: "Business",
83
+ titleField: "name",
84
+ fields: [
85
+ { name: "name", type: "text", required: true },
86
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
87
+ { name: "type", type: "status", options: ["Engineering", "Product", "Design", "Marketing", "Sales", "Support", "Operations", "Finance", "HR", "Legal"] },
88
+ { name: "description", type: "text" }
89
+ ]
90
+ };
91
+ var Processes = {
92
+ slug: "processes",
93
+ group: "Business",
94
+ titleField: "name",
95
+ fields: [
96
+ { name: "name", type: "text", required: true },
97
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
98
+ { name: "type", type: "status", options: ["Core", "Support", "Management"] },
99
+ { name: "owner", type: "ref", config: { relationTo: "teams" } },
100
+ { name: "description", type: "rich" },
101
+ { name: "status", type: "status", options: ["Draft", "Active", "Deprecated"] }
102
+ ]
103
+ };
104
+ var businessNouns = [Businesses, Goals, Metrics, Teams, Processes];
105
+
106
+ // src/schema/domains/product.ts
107
+ var Products = {
108
+ slug: "products",
109
+ group: "Product",
110
+ titleField: "name",
111
+ fields: [
112
+ { name: "name", type: "text", required: true },
113
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
114
+ { name: "type", type: "status", options: ["API", "App", "CLI", "SDK", "MCP", "Agent", "Dataset", "DataFeed", "Function", "Database", "Queue", "Storage", "Cache", "Platform"] },
115
+ { name: "description", type: "text" },
116
+ { name: "isActive", type: "boolean" },
117
+ { name: "stripeProductId", type: "text", unique: true }
118
+ ]
119
+ };
120
+ var Services = {
121
+ slug: "services",
122
+ group: "Product",
123
+ titleField: "name",
124
+ fields: [
125
+ { name: "name", type: "text", required: true },
126
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
127
+ { name: "type", type: "status", options: ["Consulting", "Implementation", "Training", "Support", "Managed"] },
128
+ { name: "description", type: "text" },
129
+ { name: "hourlyRate", type: "money" },
130
+ { name: "isActive", type: "boolean" }
131
+ ]
132
+ };
133
+ var Offers = {
134
+ slug: "offers",
135
+ group: "Product",
136
+ titleField: "name",
137
+ fields: [
138
+ { name: "name", type: "text", required: true },
139
+ { name: "products", type: "ref", config: { relationTo: "products", hasMany: true } },
140
+ { name: "type", type: "status", options: ["Trial", "Freemium", "Subscription", "One-time", "Usage-based"] },
141
+ { name: "description", type: "text" },
142
+ { name: "isActive", type: "boolean" }
143
+ ]
144
+ };
145
+ var Prices = {
146
+ slug: "prices",
147
+ group: "Product",
148
+ titleField: "name",
149
+ fields: [
150
+ { name: "name", type: "text", required: true },
151
+ { name: "offer", type: "ref", config: { relationTo: "offers" } },
152
+ { name: "amount", type: "money", required: true },
153
+ { name: "currency", type: "status", options: ["USD", "EUR", "GBP", "JPY"] },
154
+ { name: "interval", type: "status", options: ["once", "day", "week", "month", "year"] },
155
+ { name: "stripePriceId", type: "text", unique: true },
156
+ { name: "isActive", type: "boolean" }
157
+ ]
158
+ };
159
+ var Features = {
160
+ slug: "features",
161
+ group: "Product",
162
+ titleField: "name",
163
+ fields: [
164
+ { name: "name", type: "text", required: true },
165
+ { name: "product", type: "ref", config: { relationTo: "products" } },
166
+ { name: "description", type: "text" },
167
+ { name: "type", type: "status", options: ["Core", "Premium", "Enterprise", "Add-on"] },
168
+ { name: "status", type: "status", options: ["Planned", "In Development", "Beta", "GA", "Deprecated"] }
169
+ ]
170
+ };
171
+ var productNouns = [Products, Services, Offers, Prices, Features];
172
+
173
+ // src/schema/domains/success.ts
174
+ var Customers = {
175
+ slug: "customers",
176
+ group: "Success",
177
+ titleField: "name",
178
+ fields: [
179
+ { name: "name", type: "text", required: true },
180
+ { name: "type", type: "status", options: ["Business", "Developer", "Consumer", "Professional"], required: true },
181
+ { name: "user", type: "ref", config: { relationTo: "users" } },
182
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
183
+ { name: "company", type: "text" },
184
+ { name: "email", type: "email" },
185
+ { name: "stripeCustomerId", type: "text", unique: true },
186
+ { name: "status", type: "status", options: ["Active", "Churned", "Paused"] },
187
+ { name: "healthScore", type: "score" }
188
+ ]
189
+ };
190
+ var Contacts = {
191
+ slug: "contacts",
192
+ group: "Success",
193
+ titleField: "name",
194
+ fields: [
195
+ { name: "name", type: "text", required: true },
196
+ { name: "customer", type: "ref", config: { relationTo: "customers" } },
197
+ { name: "email", type: "email" },
198
+ { name: "phone", type: "text" },
199
+ { name: "title", type: "text" },
200
+ { name: "role", type: "status", options: ["Decision Maker", "Influencer", "Champion", "End User", "Billing"] },
201
+ { name: "isPrimary", type: "boolean" }
202
+ ]
203
+ };
204
+ var Subscriptions = {
205
+ slug: "subscriptions",
206
+ group: "Success",
207
+ titleField: "id",
208
+ fields: [
209
+ { name: "customer", type: "ref", config: { relationTo: "customers" }, required: true },
210
+ { name: "offer", type: "ref", config: { relationTo: "offers" } },
211
+ { name: "price", type: "ref", config: { relationTo: "prices" } },
212
+ { name: "status", type: "status", options: ["Active", "Past Due", "Canceled", "Paused", "Trialing"] },
213
+ { name: "stripeSubscriptionId", type: "text", unique: true },
214
+ { name: "currentPeriodStart", type: "date" },
215
+ { name: "currentPeriodEnd", type: "date" },
216
+ { name: "canceledAt", type: "date" }
217
+ ]
218
+ };
219
+ var successNouns = [Customers, Contacts, Subscriptions];
220
+
221
+ // src/schema/domains/sales.ts
222
+ var Deals = {
223
+ slug: "deals",
224
+ group: "Sales",
225
+ titleField: "name",
226
+ fields: [
227
+ { name: "name", type: "text", required: true },
228
+ { name: "customer", type: "ref", config: { relationTo: "customers" } },
229
+ { name: "contact", type: "ref", config: { relationTo: "contacts" } },
230
+ { name: "value", type: "money" },
231
+ { name: "stage", type: "status", options: ["Qualification", "Discovery", "Proposal", "Negotiation", "Closed Won", "Closed Lost"] },
232
+ { name: "probability", type: "score" },
233
+ { name: "expectedCloseDate", type: "date" },
234
+ { name: "actualCloseDate", type: "date" },
235
+ { name: "lostReason", type: "text" }
236
+ ]
237
+ };
238
+ var Quotes = {
239
+ slug: "quotes",
240
+ group: "Sales",
241
+ titleField: "name",
242
+ fields: [
243
+ { name: "name", type: "text", required: true },
244
+ { name: "deal", type: "ref", config: { relationTo: "deals" } },
245
+ { name: "customer", type: "ref", config: { relationTo: "customers" } },
246
+ { name: "total", type: "money", required: true },
247
+ { name: "status", type: "status", options: ["Draft", "Sent", "Viewed", "Accepted", "Rejected", "Expired"] },
248
+ { name: "validUntil", type: "date" },
249
+ { name: "terms", type: "rich" }
250
+ ]
251
+ };
252
+ var Proposals = {
253
+ slug: "proposals",
254
+ group: "Sales",
255
+ titleField: "name",
256
+ fields: [
257
+ { name: "name", type: "text", required: true },
258
+ { name: "deal", type: "ref", config: { relationTo: "deals" } },
259
+ { name: "customer", type: "ref", config: { relationTo: "customers" } },
260
+ { name: "content", type: "rich" },
261
+ { name: "status", type: "status", options: ["Draft", "In Review", "Sent", "Accepted", "Rejected"] },
262
+ { name: "sentAt", type: "date" }
263
+ ]
264
+ };
265
+ var salesNouns = [Deals, Quotes, Proposals];
266
+
267
+ // src/schema/domains/marketing.ts
268
+ var Leads = {
269
+ slug: "leads",
270
+ group: "Marketing",
271
+ titleField: "email",
272
+ fields: [
273
+ { name: "email", type: "email", required: true },
274
+ { name: "name", type: "text" },
275
+ { name: "company", type: "text" },
276
+ { name: "title", type: "text" },
277
+ { name: "source", type: "status", options: ["Website", "Referral", "Event", "Ads", "Content", "Outbound", "Partner"] },
278
+ { name: "status", type: "status", options: ["New", "Contacted", "Qualified", "Unqualified", "Converted"] },
279
+ { name: "score", type: "score" },
280
+ { name: "convertedTo", type: "ref", config: { relationTo: "customers" } }
281
+ ]
282
+ };
283
+ var Brands = {
284
+ slug: "brands",
285
+ group: "Marketing",
286
+ titleField: "name",
287
+ fields: [
288
+ { name: "name", type: "text", required: true },
289
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
290
+ { name: "tagline", type: "text" },
291
+ { name: "description", type: "rich" },
292
+ { name: "logo", type: "image" },
293
+ { name: "primaryColor", type: "text" },
294
+ { name: "secondaryColor", type: "text" }
295
+ ]
296
+ };
297
+ var Domains = {
298
+ slug: "domains",
299
+ group: "Marketing",
300
+ titleField: "domain",
301
+ fields: [
302
+ { name: "domain", type: "text", required: true, unique: true },
303
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
304
+ { name: "brand", type: "ref", config: { relationTo: "brands" } },
305
+ { name: "type", type: "status", options: ["Primary", "Redirect", "Vanity", "Product"] },
306
+ { name: "status", type: "status", options: ["Active", "Pending", "Expired"] },
307
+ { name: "registrar", type: "text" },
308
+ { name: "expiresAt", type: "date" }
309
+ ]
310
+ };
311
+ var Competitors = {
312
+ slug: "competitors",
313
+ group: "Marketing",
314
+ titleField: "name",
315
+ fields: [
316
+ { name: "name", type: "text", required: true },
317
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
318
+ { name: "website", type: "url" },
319
+ { name: "description", type: "text" },
320
+ { name: "strengths", type: "rich" },
321
+ { name: "weaknesses", type: "rich" },
322
+ { name: "threat", type: "status", options: ["Low", "Medium", "High", "Critical"] }
323
+ ]
324
+ };
325
+ var marketingNouns = [Leads, Brands, Domains, Competitors];
326
+
327
+ // src/schema/domains/work.ts
328
+ var Projects = {
329
+ slug: "projects",
330
+ group: "Work",
331
+ titleField: "name",
332
+ fields: [
333
+ { name: "name", type: "text", required: true },
334
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
335
+ { name: "team", type: "ref", config: { relationTo: "teams" } },
336
+ { name: "description", type: "rich" },
337
+ { name: "status", type: "status", options: ["Planning", "Active", "On Hold", "Completed", "Archived"] },
338
+ { name: "startDate", type: "date" },
339
+ { name: "targetDate", type: "date" },
340
+ { name: "completedDate", type: "date" }
341
+ ]
342
+ };
343
+ var Tasks = {
344
+ slug: "tasks",
345
+ group: "Work",
346
+ titleField: "title",
347
+ fields: [
348
+ { name: "title", type: "text", required: true },
349
+ { name: "project", type: "ref", config: { relationTo: "projects" } },
350
+ { name: "assignee", type: "ref", config: { relationTo: "users" } },
351
+ { name: "description", type: "rich" },
352
+ { name: "status", type: "status", options: ["Backlog", "Todo", "In Progress", "In Review", "Done"] },
353
+ { name: "priority", type: "status", options: ["Low", "Medium", "High", "Urgent"] },
354
+ { name: "dueDate", type: "date" },
355
+ { name: "estimatedHours", type: "number" },
356
+ { name: "actualHours", type: "number" }
357
+ ]
358
+ };
359
+ var Issues = {
360
+ slug: "issues",
361
+ group: "Work",
362
+ titleField: "title",
363
+ fields: [
364
+ { name: "title", type: "text", required: true },
365
+ { name: "project", type: "ref", config: { relationTo: "projects" } },
366
+ { name: "reporter", type: "ref", config: { relationTo: "users" } },
367
+ { name: "assignee", type: "ref", config: { relationTo: "users" } },
368
+ { name: "description", type: "rich" },
369
+ { name: "type", type: "status", options: ["Bug", "Feature", "Task", "Epic", "Story"] },
370
+ { name: "status", type: "status", options: ["Open", "In Progress", "Resolved", "Closed"] },
371
+ { name: "priority", type: "status", options: ["Low", "Medium", "High", "Critical"] }
372
+ ]
373
+ };
374
+ var Workflows = {
375
+ slug: "workflows",
376
+ group: "Work",
377
+ titleField: "name",
378
+ fields: [
379
+ { name: "name", type: "text", required: true },
380
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
381
+ { name: "description", type: "text" },
382
+ { name: "trigger", type: "status", options: ["Manual", "Schedule", "Event", "Webhook"] },
383
+ { name: "status", type: "status", options: ["Draft", "Active", "Paused", "Archived"] }
384
+ ]
385
+ };
386
+ var Roles = {
387
+ slug: "roles",
388
+ group: "Work",
389
+ titleField: "name",
390
+ fields: [
391
+ { name: "name", type: "text", required: true },
392
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
393
+ { name: "team", type: "ref", config: { relationTo: "teams" } },
394
+ { name: "description", type: "text" },
395
+ { name: "level", type: "status", options: ["Individual Contributor", "Lead", "Manager", "Director", "VP", "C-Level"] }
396
+ ]
397
+ };
398
+ var Agents = {
399
+ slug: "agents",
400
+ group: "Work",
401
+ titleField: "name",
402
+ fields: [
403
+ { name: "name", type: "text", required: true },
404
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
405
+ { name: "role", type: "ref", config: { relationTo: "roles" } },
406
+ { name: "type", type: "status", options: ["AI", "Human", "Hybrid"] },
407
+ { name: "status", type: "status", options: ["Active", "Paused", "Retired"] },
408
+ { name: "capabilities", type: "array" }
409
+ ]
410
+ };
411
+ var workNouns = [Projects, Tasks, Issues, Workflows, Roles, Agents];
412
+
413
+ // src/schema/domains/financial.ts
414
+ var Invoices = {
415
+ slug: "invoices",
416
+ group: "Financial",
417
+ titleField: "number",
418
+ fields: [
419
+ { name: "number", type: "text", required: true, unique: true },
420
+ { name: "customer", type: "ref", config: { relationTo: "customers" } },
421
+ { name: "subscription", type: "ref", config: { relationTo: "subscriptions" } },
422
+ { name: "total", type: "money", required: true },
423
+ { name: "tax", type: "money" },
424
+ { name: "status", type: "status", options: ["Draft", "Sent", "Paid", "Void", "Uncollectible"] },
425
+ { name: "dueDate", type: "date" },
426
+ { name: "paidAt", type: "date" },
427
+ { name: "stripeInvoiceId", type: "text", unique: true }
428
+ ]
429
+ };
430
+ var Payments = {
431
+ slug: "payments",
432
+ group: "Financial",
433
+ titleField: "id",
434
+ fields: [
435
+ { name: "customer", type: "ref", config: { relationTo: "customers" } },
436
+ { name: "invoice", type: "ref", config: { relationTo: "invoices" } },
437
+ { name: "amount", type: "money", required: true },
438
+ { name: "currency", type: "status", options: ["USD", "EUR", "GBP", "JPY"] },
439
+ { name: "status", type: "status", options: ["Pending", "Succeeded", "Failed", "Refunded"] },
440
+ { name: "method", type: "status", options: ["Card", "ACH", "Wire", "Check"] },
441
+ { name: "stripePaymentId", type: "text", unique: true }
442
+ ]
443
+ };
444
+ var Refunds = {
445
+ slug: "refunds",
446
+ group: "Financial",
447
+ titleField: "id",
448
+ fields: [
449
+ { name: "payment", type: "ref", config: { relationTo: "payments" }, required: true },
450
+ { name: "amount", type: "money", required: true },
451
+ { name: "reason", type: "status", options: ["Duplicate", "Fraudulent", "Customer Request", "Product Issue"] },
452
+ { name: "status", type: "status", options: ["Pending", "Succeeded", "Failed"] },
453
+ { name: "notes", type: "text" }
454
+ ]
455
+ };
456
+ var ChartOfAccounts = {
457
+ slug: "chart-of-accounts",
458
+ group: "Financial",
459
+ titleField: "name",
460
+ fields: [
461
+ { name: "code", type: "text", required: true, unique: true },
462
+ { name: "name", type: "text", required: true },
463
+ { name: "type", type: "status", options: ["Asset", "Liability", "Equity", "Revenue", "Expense"], required: true },
464
+ { name: "subtype", type: "text" },
465
+ { name: "description", type: "text" },
466
+ { name: "isActive", type: "boolean" }
467
+ ]
468
+ };
469
+ var JournalEntries = {
470
+ slug: "journal-entries",
471
+ group: "Financial",
472
+ titleField: "reference",
473
+ fields: [
474
+ { name: "reference", type: "text", required: true },
475
+ { name: "date", type: "date", required: true },
476
+ { name: "description", type: "text" },
477
+ { name: "debitAccount", type: "ref", config: { relationTo: "chart-of-accounts" } },
478
+ { name: "creditAccount", type: "ref", config: { relationTo: "chart-of-accounts" } },
479
+ { name: "amount", type: "money", required: true },
480
+ { name: "status", type: "status", options: ["Draft", "Posted", "Voided"] }
481
+ ]
482
+ };
483
+ var financialNouns = [Invoices, Payments, Refunds, ChartOfAccounts, JournalEntries];
484
+
485
+ // src/schema/domains/communications.ts
486
+ var Channels = {
487
+ slug: "channels",
488
+ group: "Communications",
489
+ titleField: "name",
490
+ fields: [
491
+ { name: "name", type: "text", required: true },
492
+ { name: "type", type: "status", options: ["Email", "SMS", "Slack", "Discord", "WhatsApp", "In-App", "Push"] },
493
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
494
+ { name: "isActive", type: "boolean" },
495
+ { name: "config", type: "text" }
496
+ ]
497
+ };
498
+ var Messages = {
499
+ slug: "messages",
500
+ group: "Communications",
501
+ titleField: "subject",
502
+ fields: [
503
+ { name: "subject", type: "text" },
504
+ { name: "body", type: "rich", required: true },
505
+ { name: "channel", type: "ref", config: { relationTo: "channels" } },
506
+ { name: "from", type: "text" },
507
+ { name: "to", type: "text", required: true },
508
+ { name: "status", type: "status", options: ["Draft", "Queued", "Sent", "Delivered", "Bounced", "Failed"] },
509
+ { name: "sentAt", type: "date" },
510
+ { name: "openedAt", type: "date" },
511
+ { name: "clickedAt", type: "date" }
512
+ ]
513
+ };
514
+ var Sequences = {
515
+ slug: "sequences",
516
+ group: "Communications",
517
+ titleField: "name",
518
+ fields: [
519
+ { name: "name", type: "text", required: true },
520
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
521
+ { name: "type", type: "status", options: ["Onboarding", "Nurture", "Re-engagement", "Upsell", "Support"] },
522
+ { name: "status", type: "status", options: ["Draft", "Active", "Paused", "Archived"] },
523
+ { name: "description", type: "text" }
524
+ ]
525
+ };
526
+ var Templates = {
527
+ slug: "templates",
528
+ group: "Communications",
529
+ titleField: "name",
530
+ fields: [
531
+ { name: "name", type: "text", required: true },
532
+ { name: "channel", type: "ref", config: { relationTo: "channels" } },
533
+ { name: "subject", type: "text" },
534
+ { name: "body", type: "rich", required: true },
535
+ { name: "type", type: "status", options: ["Transactional", "Marketing", "System"] },
536
+ { name: "isActive", type: "boolean" }
537
+ ]
538
+ };
539
+ var Posts = {
540
+ slug: "posts",
541
+ group: "Communications",
542
+ titleField: "title",
543
+ fields: [
544
+ { name: "title", type: "text", required: true },
545
+ { name: "content", type: "rich", required: true },
546
+ { name: "author", type: "ref", config: { relationTo: "users" } },
547
+ { name: "business", type: "ref", config: { relationTo: "businesses" } },
548
+ { name: "status", type: "status", options: ["Draft", "Scheduled", "Published", "Archived"] },
549
+ { name: "publishedAt", type: "date" },
550
+ { name: "channels", type: "ref", config: { relationTo: "channels", hasMany: true } }
551
+ ]
552
+ };
553
+ var communicationsNouns = [Channels, Messages, Sequences, Templates, Posts];
554
+
555
+ // src/schema/index.ts
556
+ var defaultBusinessSchema = {
557
+ name: "default",
558
+ version: "1.0.0",
559
+ description: "Default business schema with all standard domains",
560
+ domains: {
561
+ admin: adminNouns,
562
+ business: businessNouns,
563
+ product: productNouns,
564
+ success: successNouns,
565
+ sales: salesNouns,
566
+ marketing: marketingNouns,
567
+ work: workNouns,
568
+ financial: financialNouns,
569
+ communications: communicationsNouns
570
+ }
571
+ };
572
+ function getAllNouns(schema) {
573
+ const nouns = [];
574
+ for (const domain of Object.values(schema.domains)) {
575
+ if (domain) {
576
+ nouns.push(...domain);
577
+ }
578
+ }
579
+ return nouns;
580
+ }
581
+ function getDomainNouns(schema, domain) {
582
+ return schema.domains[domain] || [];
583
+ }
584
+ function findNounBySlug(schema, slug) {
585
+ for (const domain of Object.values(schema.domains)) {
586
+ if (domain) {
587
+ const noun = domain.find((n) => n.slug === slug);
588
+ if (noun) return noun;
589
+ }
590
+ }
591
+ return void 0;
592
+ }
593
+ function getDomains(schema) {
594
+ return Object.keys(schema.domains);
595
+ }
596
+ function mergeSchemas(base, extension) {
597
+ const merged = {
598
+ name: extension.name || base.name,
599
+ version: extension.version || base.version,
600
+ description: extension.description || base.description,
601
+ domains: { ...base.domains }
8
602
  };
9
- const business = {
10
- ...config,
11
- addExperiment(experiment) {
12
- experiments.push(experiment);
13
- },
14
- async launch() {
15
- if (state.isLaunched) {
16
- return;
603
+ if (extension.domains) {
604
+ for (const [domain, nouns] of Object.entries(extension.domains)) {
605
+ if (nouns) {
606
+ const existing = merged.domains[domain] || [];
607
+ const existingSlugs = new Set(existing.map((n) => n.slug));
608
+ const newNouns = nouns.filter((n) => !existingSlugs.has(n.slug));
609
+ const overrides = nouns.filter((n) => existingSlugs.has(n.slug));
610
+ merged.domains[domain] = [
611
+ ...existing.filter((n) => !overrides.find((o) => o.slug === n.slug)),
612
+ ...overrides,
613
+ ...newNouns
614
+ ];
17
615
  }
18
- if (business.workflows) {
19
- for (const workflowKey in business.workflows) {
20
- const workflow = business.workflows[workflowKey];
616
+ }
617
+ }
618
+ return merged;
619
+ }
620
+ function createMinimalSchema(domains, options) {
621
+ const schema = {
622
+ name: options?.name || "minimal",
623
+ version: options?.version || "1.0.0",
624
+ domains: {}
625
+ };
626
+ for (const domain of domains) {
627
+ schema.domains[domain] = defaultBusinessSchema.domains[domain];
628
+ }
629
+ return schema;
630
+ }
631
+ function validateSchema(schema) {
632
+ const errors = [];
633
+ if (!schema.name) {
634
+ errors.push("Schema must have a name");
635
+ }
636
+ if (!schema.version) {
637
+ errors.push("Schema must have a version");
638
+ }
639
+ const allSlugs = /* @__PURE__ */ new Set();
640
+ for (const [domain, nouns] of Object.entries(schema.domains)) {
641
+ if (nouns) {
642
+ for (const noun of nouns) {
643
+ if (!noun.slug) {
644
+ errors.push(`Noun in domain '${domain}' is missing a slug`);
645
+ } else if (allSlugs.has(noun.slug)) {
646
+ errors.push(`Duplicate slug '${noun.slug}' found in domain '${domain}'`);
647
+ } else {
648
+ allSlugs.add(noun.slug);
21
649
  }
22
- }
23
- if (business.agents) {
24
- for (const agentKey in business.agents) {
25
- const agent = business.agents[agentKey];
650
+ if (!noun.fields || noun.fields.length === 0) {
651
+ errors.push(`Noun '${noun.slug}' has no fields`);
26
652
  }
27
653
  }
28
- state.isLaunched = true;
29
- },
30
- async execute() {
31
- if (state.isExecuting) {
32
- return;
33
- }
34
- if (!state.isLaunched) {
35
- await business.launch();
36
- }
37
- state.isExecuting = true;
38
- try {
39
- if (business.workflows) {
40
- for (const workflowKey in business.workflows) {
41
- const workflow = business.workflows[workflowKey];
42
- await workflow.execute();
43
- }
44
- }
45
- for (const experiment of experiments) {
46
- await experiment.start();
47
- }
48
- } finally {
49
- state.isExecuting = false;
654
+ }
655
+ }
656
+ return errors;
657
+ }
658
+
659
+ // src/loaders/mdx.ts
660
+ import { parseMDXAsync, extractNodesByName } from "db.sb";
661
+ function nodeToNounSchema(node) {
662
+ const fields = [];
663
+ if (node.children) {
664
+ for (const child of node.children) {
665
+ if (typeof child === "object" && "__dsl" in child) {
666
+ const fieldNode = child;
667
+ fields.push({
668
+ name: fieldNode.name,
669
+ type: fieldNode.type,
670
+ required: fieldNode.props.required,
671
+ unique: fieldNode.props.unique,
672
+ config: fieldNode.props
673
+ });
50
674
  }
51
675
  }
676
+ }
677
+ return {
678
+ slug: node.props.slug || node.name,
679
+ group: node.props.group,
680
+ titleField: node.props.titleField || node.props.useAsTitle,
681
+ fields
52
682
  };
53
- return business;
54
683
  }
55
-
56
- // src/experiment.ts
57
- function Experiment(config) {
58
- const state = {
59
- isRunning: false,
60
- startTime: null,
61
- endTime: null,
62
- variantData: {}
684
+ async function loadFromMDX(source, options = {}) {
685
+ const ast = await parseMDXAsync(source, options.context || "app");
686
+ const name = ast.props.name || "unnamed";
687
+ const version = ast.props.version || "1.0.0";
688
+ const description = ast.props.description;
689
+ const nounNodes = extractNodesByName(ast, "noun");
690
+ const domains = {};
691
+ for (const node of nounNodes) {
692
+ const noun = nodeToNounSchema(node);
693
+ const group = noun.group?.toLowerCase() || "business";
694
+ if (!domains[group]) {
695
+ domains[group] = [];
696
+ }
697
+ domains[group].push(noun);
698
+ }
699
+ return {
700
+ name,
701
+ version,
702
+ description,
703
+ domains
63
704
  };
64
- for (const variantKey in config.variants) {
65
- state.variantData[variantKey] = {
66
- metrics: config.metrics.reduce((acc, metric) => {
67
- acc[metric] = [];
68
- return acc;
69
- }, {}),
70
- sampleCount: 0
71
- };
72
- }
73
- const experiment = {
74
- ...config,
75
- async start() {
76
- if (state.isRunning) {
77
- return;
78
- }
79
- state.isRunning = true;
80
- state.startTime = /* @__PURE__ */ new Date();
81
- for (const variantKey in experiment.variants) {
82
- const variant = experiment.variants[variantKey];
83
- if (typeof variant.workflow === "string") {
84
- }
85
- if (typeof variant.agent === "string") {
86
- }
87
- if (typeof variant.function === "string") {
88
- }
705
+ }
706
+ async function loadNounFromMDX(source, options = {}) {
707
+ const ast = await parseMDXAsync(source, options.context || "noun");
708
+ if (ast.name !== "noun") {
709
+ const nounNodes = extractNodesByName(ast, "noun");
710
+ if (nounNodes.length === 0) {
711
+ throw new Error("No Noun definition found in MDX");
712
+ }
713
+ return nodeToNounSchema(nounNodes[0]);
714
+ }
715
+ return nodeToNounSchema(ast);
716
+ }
717
+ async function loadNounsFromMDX(source, options = {}) {
718
+ const ast = await parseMDXAsync(source, options.context || "app");
719
+ const nounNodes = extractNodesByName(ast, "noun");
720
+ return nounNodes.map(nodeToNounSchema);
721
+ }
722
+
723
+ // src/loaders/yaml.ts
724
+ import YAML from "yaml";
725
+ function parseFieldShorthand(name, value) {
726
+ if (typeof value === "object") {
727
+ return { ...value, name };
728
+ }
729
+ const parts = value.split(" ");
730
+ const field = { name, type: "text" };
731
+ for (const part of parts) {
732
+ if (part === "required") {
733
+ field.required = true;
734
+ } else if (part === "unique") {
735
+ field.unique = true;
736
+ } else if (part.includes(":")) {
737
+ const [type, options] = part.split(":");
738
+ field.type = type;
739
+ if (type === "status" || type === "select") {
740
+ field.options = options.split("|");
741
+ } else if (type === "ref") {
742
+ field.to = options;
89
743
  }
90
- },
91
- async stop() {
92
- if (!state.isRunning) {
93
- return;
744
+ } else {
745
+ field.type = part;
746
+ }
747
+ }
748
+ return field;
749
+ }
750
+ function parseNoun(data) {
751
+ const fields = [];
752
+ if (data.fields) {
753
+ if (Array.isArray(data.fields)) {
754
+ for (const field of data.fields) {
755
+ fields.push(field);
94
756
  }
95
- state.isRunning = false;
96
- state.endTime = /* @__PURE__ */ new Date();
97
- },
98
- async analyze() {
99
- if (state.isRunning) {
100
- await experiment.stop();
757
+ } else {
758
+ for (const [name, value] of Object.entries(data.fields)) {
759
+ fields.push(parseFieldShorthand(name, value));
101
760
  }
102
- const variantPerformance = {};
103
- for (const variantKey in state.variantData) {
104
- const variantData = state.variantData[variantKey];
105
- const metrics = {};
106
- for (const metricKey in variantData.metrics) {
107
- const values = variantData.metrics[metricKey];
108
- if (values.length > 0) {
109
- metrics[metricKey] = values.reduce((sum, value) => sum + value, 0) / values.length;
110
- } else {
111
- metrics[metricKey] = 0;
112
- }
113
- }
114
- variantPerformance[variantKey] = {
115
- metrics,
116
- sampleSize: variantData.sampleCount
117
- };
761
+ }
762
+ }
763
+ return {
764
+ slug: data.slug || data.name?.toLowerCase().replace(/\s+/g, "-"),
765
+ group: data.group,
766
+ titleField: data.titleField || data.useAsTitle,
767
+ fields
768
+ };
769
+ }
770
+ function loadFromYAML(source, _options = {}) {
771
+ const data = YAML.parse(source);
772
+ const schema = {
773
+ name: data.name || "unnamed",
774
+ version: data.version || "1.0.0",
775
+ description: data.description,
776
+ domains: {}
777
+ };
778
+ if (data.domains) {
779
+ for (const [domain, nouns] of Object.entries(data.domains)) {
780
+ if (Array.isArray(nouns)) {
781
+ schema.domains[domain] = nouns.map(parseNoun);
118
782
  }
119
- let winner;
120
- let highestScore = -Infinity;
121
- const primaryMetric = experiment.metrics[0];
122
- for (const variantKey in variantPerformance) {
123
- const performance = variantPerformance[variantKey];
124
- const score = performance.metrics[primaryMetric] || 0;
125
- if (score > highestScore) {
126
- highestScore = score;
127
- winner = variantKey;
128
- }
783
+ }
784
+ }
785
+ if (data.nouns) {
786
+ for (const nounData of data.nouns) {
787
+ const noun = parseNoun(nounData);
788
+ const domain = noun.group?.toLowerCase() || "business";
789
+ if (!schema.domains[domain]) {
790
+ schema.domains[domain] = [];
129
791
  }
130
- const insights = [
131
- `Experiment ran for ${state.startTime && state.endTime ? Math.round((state.endTime.getTime() - state.startTime.getTime()) / (1e3 * 60 * 60 * 24)) : "unknown"} days`,
132
- winner ? `Variant "${winner}" performed best on primary metric "${primaryMetric}"` : "No clear winner determined"
133
- ];
134
- return {
135
- variantPerformance,
136
- winner,
137
- confidence: 0.95,
138
- // Placeholder - would calculate actual confidence in real implementation
139
- insights
140
- };
792
+ schema.domains[domain].push(noun);
141
793
  }
142
- };
143
- return experiment;
794
+ }
795
+ return schema;
796
+ }
797
+ function loadNounFromYAML(source, _options = {}) {
798
+ const data = YAML.parse(source);
799
+ return parseNoun(data);
800
+ }
801
+ function loadNounsFromYAML(source, _options = {}) {
802
+ const data = YAML.parse(source);
803
+ if (Array.isArray(data)) {
804
+ return data.map(parseNoun);
805
+ }
806
+ if (data.nouns) {
807
+ return data.nouns.map(parseNoun);
808
+ }
809
+ return [parseNoun(data)];
810
+ }
811
+ function toYAML(schema) {
812
+ return YAML.stringify({
813
+ name: schema.name,
814
+ version: schema.version,
815
+ description: schema.description,
816
+ domains: schema.domains
817
+ });
818
+ }
819
+ function nounToYAML(noun) {
820
+ return YAML.stringify(noun);
144
821
  }
145
822
 
146
- // src/models/lean-canvas.ts
147
- function LeanCanvas(config) {
823
+ // src/loaders/json.ts
824
+ function parseFieldShorthand2(name, value) {
825
+ if (typeof value === "object") {
826
+ return { ...value, name };
827
+ }
828
+ const parts = value.split(" ");
829
+ const field = { name, type: "text" };
830
+ for (const part of parts) {
831
+ if (part === "required") {
832
+ field.required = true;
833
+ } else if (part === "unique") {
834
+ field.unique = true;
835
+ } else if (part.includes(":")) {
836
+ const [type, options] = part.split(":");
837
+ field.type = type;
838
+ if (type === "status" || type === "select") {
839
+ field.options = options.split("|");
840
+ } else if (type === "ref") {
841
+ field.to = options;
842
+ }
843
+ } else {
844
+ field.type = part;
845
+ }
846
+ }
847
+ return field;
848
+ }
849
+ function parseNoun2(data) {
850
+ const fields = [];
851
+ if (data.fields) {
852
+ if (Array.isArray(data.fields)) {
853
+ for (const field of data.fields) {
854
+ fields.push(field);
855
+ }
856
+ } else {
857
+ for (const [name, value] of Object.entries(data.fields)) {
858
+ fields.push(parseFieldShorthand2(name, value));
859
+ }
860
+ }
861
+ }
148
862
  return {
149
- ...config
863
+ slug: data.slug || data.name?.toLowerCase().replace(/\s+/g, "-"),
864
+ group: data.group,
865
+ titleField: data.titleField || data.useAsTitle,
866
+ fields
150
867
  };
151
868
  }
152
-
153
- // src/models/story-brand.ts
154
- function StoryBrand(config) {
155
- return {
156
- ...config
869
+ function loadFromJSON(source, _options = {}) {
870
+ const data = JSON.parse(source);
871
+ const schema = {
872
+ name: data.name || "unnamed",
873
+ version: data.version || "1.0.0",
874
+ description: data.description,
875
+ domains: {}
157
876
  };
877
+ if (data.domains) {
878
+ for (const [domain, nouns] of Object.entries(data.domains)) {
879
+ if (Array.isArray(nouns)) {
880
+ schema.domains[domain] = nouns.map(parseNoun2);
881
+ }
882
+ }
883
+ }
884
+ if (data.nouns) {
885
+ for (const nounData of data.nouns) {
886
+ const noun = parseNoun2(nounData);
887
+ const domain = noun.group?.toLowerCase() || "business";
888
+ if (!schema.domains[domain]) {
889
+ schema.domains[domain] = [];
890
+ }
891
+ schema.domains[domain].push(noun);
892
+ }
893
+ }
894
+ return schema;
895
+ }
896
+ function loadNounFromJSON(source, _options = {}) {
897
+ const data = JSON.parse(source);
898
+ return parseNoun2(data);
899
+ }
900
+ function loadNounsFromJSON(source, _options = {}) {
901
+ const data = JSON.parse(source);
902
+ if (Array.isArray(data)) {
903
+ return data.map(parseNoun2);
904
+ }
905
+ if (data.nouns) {
906
+ return data.nouns.map(parseNoun2);
907
+ }
908
+ return [parseNoun2(data)];
909
+ }
910
+ function toJSON(schema, pretty = true) {
911
+ return JSON.stringify(
912
+ {
913
+ name: schema.name,
914
+ version: schema.version,
915
+ description: schema.description,
916
+ domains: schema.domains
917
+ },
918
+ null,
919
+ pretty ? 2 : void 0
920
+ );
921
+ }
922
+ function nounToJSON(noun, pretty = true) {
923
+ return JSON.stringify(noun, null, pretty ? 2 : void 0);
158
924
  }
159
925
 
160
- // src/models/value-proposition.ts
161
- function ValueProposition(config) {
926
+ // src/loaders/index.ts
927
+ function detectFormat(source) {
928
+ const trimmed = source.trim();
929
+ if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
930
+ return "json";
931
+ }
932
+ if (trimmed.includes("<") && trimmed.includes(">")) {
933
+ return "mdx";
934
+ }
935
+ return "yaml";
936
+ }
937
+ async function load(source, options = {}) {
938
+ const format = options.format || detectFormat(source);
939
+ let schema;
940
+ switch (format) {
941
+ case "mdx":
942
+ schema = await loadFromMDX(source, options);
943
+ break;
944
+ case "yaml":
945
+ schema = loadFromYAML(source, options);
946
+ break;
947
+ case "json":
948
+ schema = loadFromJSON(source, options);
949
+ break;
950
+ default:
951
+ throw new Error(`Unsupported format: ${format}`);
952
+ }
162
953
  return {
163
- ...config
954
+ schema,
955
+ format
164
956
  };
165
957
  }
958
+ async function loadNoun(source, options = {}) {
959
+ const format = options.format || detectFormat(source);
960
+ switch (format) {
961
+ case "mdx":
962
+ return loadNounFromMDX(source, options);
963
+ case "yaml":
964
+ return loadNounFromYAML(source, options);
965
+ case "json":
966
+ return loadNounFromJSON(source, options);
967
+ default:
968
+ throw new Error(`Unsupported format: ${format}`);
969
+ }
970
+ }
971
+ async function loadNouns(source, options = {}) {
972
+ const format = options.format || detectFormat(source);
973
+ switch (format) {
974
+ case "mdx":
975
+ return loadNounsFromMDX(source, options);
976
+ case "yaml":
977
+ return loadNounsFromYAML(source, options);
978
+ case "json":
979
+ return loadNounsFromJSON(source, options);
980
+ default:
981
+ throw new Error(`Unsupported format: ${format}`);
982
+ }
983
+ }
984
+ function serialize(schema, format = "yaml") {
985
+ switch (format) {
986
+ case "yaml":
987
+ return toYAML(schema);
988
+ case "json":
989
+ return toJSON(schema);
990
+ default:
991
+ throw new Error(`Unsupported format: ${format}`);
992
+ }
993
+ }
994
+ function serializeNoun(noun, format = "yaml") {
995
+ switch (format) {
996
+ case "yaml":
997
+ return nounToYAML(noun);
998
+ case "json":
999
+ return nounToJSON(noun);
1000
+ default:
1001
+ throw new Error(`Unsupported format: ${format}`);
1002
+ }
1003
+ }
166
1004
  export {
167
- Business,
168
- Experiment,
169
- LeanCanvas,
170
- StoryBrand,
171
- ValueProposition
1005
+ Agents,
1006
+ Brands,
1007
+ Businesses,
1008
+ Channels,
1009
+ ChartOfAccounts,
1010
+ Competitors,
1011
+ Contacts,
1012
+ Customers,
1013
+ Deals,
1014
+ Domains,
1015
+ Features,
1016
+ Goals,
1017
+ Invoices,
1018
+ Issues,
1019
+ JournalEntries,
1020
+ Leads,
1021
+ Messages,
1022
+ Metrics,
1023
+ Offers,
1024
+ Orgs,
1025
+ Payments,
1026
+ Posts,
1027
+ Prices,
1028
+ Processes,
1029
+ Products,
1030
+ Projects,
1031
+ Proposals,
1032
+ Quotes,
1033
+ Refunds,
1034
+ Roles,
1035
+ Sequences,
1036
+ ServiceAccounts,
1037
+ Services,
1038
+ Subscriptions,
1039
+ Tasks,
1040
+ Teams,
1041
+ Templates,
1042
+ Users,
1043
+ Workflows,
1044
+ adminNouns,
1045
+ businessNouns,
1046
+ communicationsNouns,
1047
+ createMinimalSchema,
1048
+ defaultBusinessSchema,
1049
+ financialNouns,
1050
+ findNounBySlug,
1051
+ getAllNouns,
1052
+ getDomainNouns,
1053
+ getDomains,
1054
+ load,
1055
+ loadFromJSON,
1056
+ loadFromMDX,
1057
+ loadFromYAML,
1058
+ loadNoun,
1059
+ loadNounFromJSON,
1060
+ loadNounFromMDX,
1061
+ loadNounFromYAML,
1062
+ loadNouns,
1063
+ loadNounsFromJSON,
1064
+ loadNounsFromMDX,
1065
+ loadNounsFromYAML,
1066
+ marketingNouns,
1067
+ mergeSchemas,
1068
+ nounToJSON,
1069
+ nounToYAML,
1070
+ productNouns,
1071
+ salesNouns,
1072
+ serialize,
1073
+ serializeNoun,
1074
+ successNouns,
1075
+ toJSON,
1076
+ toYAML,
1077
+ validateSchema,
1078
+ workNouns
172
1079
  };
1080
+ //# sourceMappingURL=index.js.map