business-as-code 0.2.1 → 2.0.2

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.
Files changed (190) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +17 -0
  3. package/IMPLEMENTATION.md +226 -0
  4. package/README.md +1133 -193
  5. package/dist/business.d.ts +62 -0
  6. package/dist/business.d.ts.map +1 -0
  7. package/dist/business.js +109 -0
  8. package/dist/business.js.map +1 -0
  9. package/dist/dollar.d.ts +60 -0
  10. package/dist/dollar.d.ts.map +1 -0
  11. package/dist/dollar.js +107 -0
  12. package/dist/dollar.js.map +1 -0
  13. package/dist/entities/assets.d.ts +21 -0
  14. package/dist/entities/assets.d.ts.map +1 -0
  15. package/dist/entities/assets.js +323 -0
  16. package/dist/entities/assets.js.map +1 -0
  17. package/dist/entities/business.d.ts +36 -0
  18. package/dist/entities/business.d.ts.map +1 -0
  19. package/dist/entities/business.js +370 -0
  20. package/dist/entities/business.js.map +1 -0
  21. package/dist/entities/communication.d.ts +21 -0
  22. package/dist/entities/communication.d.ts.map +1 -0
  23. package/dist/entities/communication.js +255 -0
  24. package/dist/entities/communication.js.map +1 -0
  25. package/dist/entities/customers.d.ts +58 -0
  26. package/dist/entities/customers.d.ts.map +1 -0
  27. package/dist/entities/customers.js +989 -0
  28. package/dist/entities/customers.js.map +1 -0
  29. package/dist/entities/financials.d.ts +59 -0
  30. package/dist/entities/financials.d.ts.map +1 -0
  31. package/dist/entities/financials.js +932 -0
  32. package/dist/entities/financials.js.map +1 -0
  33. package/dist/entities/goals.d.ts +58 -0
  34. package/dist/entities/goals.d.ts.map +1 -0
  35. package/dist/entities/goals.js +800 -0
  36. package/dist/entities/goals.js.map +1 -0
  37. package/dist/entities/index.d.ts +299 -0
  38. package/dist/entities/index.d.ts.map +1 -0
  39. package/dist/entities/index.js +198 -0
  40. package/dist/entities/index.js.map +1 -0
  41. package/dist/entities/legal.d.ts +21 -0
  42. package/dist/entities/legal.d.ts.map +1 -0
  43. package/dist/entities/legal.js +301 -0
  44. package/dist/entities/legal.js.map +1 -0
  45. package/dist/entities/market.d.ts +21 -0
  46. package/dist/entities/market.d.ts.map +1 -0
  47. package/dist/entities/market.js +301 -0
  48. package/dist/entities/market.js.map +1 -0
  49. package/dist/entities/marketing.d.ts +67 -0
  50. package/dist/entities/marketing.d.ts.map +1 -0
  51. package/dist/entities/marketing.js +1157 -0
  52. package/dist/entities/marketing.js.map +1 -0
  53. package/dist/entities/offerings.d.ts +51 -0
  54. package/dist/entities/offerings.d.ts.map +1 -0
  55. package/dist/entities/offerings.js +727 -0
  56. package/dist/entities/offerings.js.map +1 -0
  57. package/dist/entities/operations.d.ts +58 -0
  58. package/dist/entities/operations.d.ts.map +1 -0
  59. package/dist/entities/operations.js +787 -0
  60. package/dist/entities/operations.js.map +1 -0
  61. package/dist/entities/organization.d.ts +57 -0
  62. package/dist/entities/organization.d.ts.map +1 -0
  63. package/dist/entities/organization.js +807 -0
  64. package/dist/entities/organization.js.map +1 -0
  65. package/dist/entities/partnerships.d.ts +21 -0
  66. package/dist/entities/partnerships.d.ts.map +1 -0
  67. package/dist/entities/partnerships.js +300 -0
  68. package/dist/entities/partnerships.js.map +1 -0
  69. package/dist/entities/planning.d.ts +87 -0
  70. package/dist/entities/planning.d.ts.map +1 -0
  71. package/dist/entities/planning.js +271 -0
  72. package/dist/entities/planning.js.map +1 -0
  73. package/dist/entities/projects.d.ts +25 -0
  74. package/dist/entities/projects.d.ts.map +1 -0
  75. package/dist/entities/projects.js +349 -0
  76. package/dist/entities/projects.js.map +1 -0
  77. package/dist/entities/risk.d.ts +21 -0
  78. package/dist/entities/risk.d.ts.map +1 -0
  79. package/dist/entities/risk.js +293 -0
  80. package/dist/entities/risk.js.map +1 -0
  81. package/dist/entities/sales.d.ts +72 -0
  82. package/dist/entities/sales.d.ts.map +1 -0
  83. package/dist/entities/sales.js +1248 -0
  84. package/dist/entities/sales.js.map +1 -0
  85. package/dist/financials.d.ts +130 -0
  86. package/dist/financials.d.ts.map +1 -0
  87. package/dist/financials.js +297 -0
  88. package/dist/financials.js.map +1 -0
  89. package/dist/goals.d.ts +87 -0
  90. package/dist/goals.d.ts.map +1 -0
  91. package/dist/goals.js +215 -0
  92. package/dist/goals.js.map +1 -0
  93. package/dist/index.d.ts +97 -4
  94. package/dist/index.d.ts.map +1 -0
  95. package/dist/index.js +131 -1079
  96. package/dist/index.js.map +1 -1
  97. package/dist/kpis.d.ts +118 -0
  98. package/dist/kpis.d.ts.map +1 -0
  99. package/dist/kpis.js +232 -0
  100. package/dist/kpis.js.map +1 -0
  101. package/dist/metrics.d.ts +448 -0
  102. package/dist/metrics.d.ts.map +1 -0
  103. package/dist/metrics.js +325 -0
  104. package/dist/metrics.js.map +1 -0
  105. package/dist/okrs.d.ts +123 -0
  106. package/dist/okrs.d.ts.map +1 -0
  107. package/dist/okrs.js +269 -0
  108. package/dist/okrs.js.map +1 -0
  109. package/dist/organization.d.ts +585 -0
  110. package/dist/organization.d.ts.map +1 -0
  111. package/dist/organization.js +173 -0
  112. package/dist/organization.js.map +1 -0
  113. package/dist/process.d.ts +112 -0
  114. package/dist/process.d.ts.map +1 -0
  115. package/dist/process.js +241 -0
  116. package/dist/process.js.map +1 -0
  117. package/dist/product.d.ts +85 -0
  118. package/dist/product.d.ts.map +1 -0
  119. package/dist/product.js +145 -0
  120. package/dist/product.js.map +1 -0
  121. package/dist/queries.d.ts +304 -0
  122. package/dist/queries.d.ts.map +1 -0
  123. package/dist/queries.js +415 -0
  124. package/dist/queries.js.map +1 -0
  125. package/dist/roles.d.ts +340 -0
  126. package/dist/roles.d.ts.map +1 -0
  127. package/dist/roles.js +255 -0
  128. package/dist/roles.js.map +1 -0
  129. package/dist/service.d.ts +61 -0
  130. package/dist/service.d.ts.map +1 -0
  131. package/dist/service.js +140 -0
  132. package/dist/service.js.map +1 -0
  133. package/dist/types.d.ts +459 -0
  134. package/dist/types.d.ts.map +1 -0
  135. package/dist/types.js +5 -0
  136. package/dist/types.js.map +1 -0
  137. package/dist/vision.d.ts +38 -0
  138. package/dist/vision.d.ts.map +1 -0
  139. package/dist/vision.js +68 -0
  140. package/dist/vision.js.map +1 -0
  141. package/dist/workflow.d.ts +115 -0
  142. package/dist/workflow.d.ts.map +1 -0
  143. package/dist/workflow.js +247 -0
  144. package/dist/workflow.js.map +1 -0
  145. package/examples/basic-usage.ts +307 -0
  146. package/package.json +19 -60
  147. package/src/business.ts +121 -0
  148. package/src/dollar.ts +132 -0
  149. package/src/entities/assets.ts +332 -0
  150. package/src/entities/business.ts +406 -0
  151. package/src/entities/communication.ts +264 -0
  152. package/src/entities/customers.ts +1072 -0
  153. package/src/entities/financials.ts +1011 -0
  154. package/src/entities/goals.ts +871 -0
  155. package/src/entities/index.ts +383 -0
  156. package/src/entities/legal.ts +310 -0
  157. package/src/entities/market.ts +310 -0
  158. package/src/entities/marketing.ts +1249 -0
  159. package/src/entities/offerings.ts +789 -0
  160. package/src/entities/operations.ts +861 -0
  161. package/src/entities/organization.ts +876 -0
  162. package/src/entities/partnerships.ts +309 -0
  163. package/src/entities/planning.ts +307 -0
  164. package/src/entities/projects.ts +360 -0
  165. package/src/entities/risk.ts +302 -0
  166. package/src/entities/sales.ts +1352 -0
  167. package/src/financials.ts +352 -0
  168. package/src/goals.ts +250 -0
  169. package/src/index.test.ts +336 -0
  170. package/src/index.ts +530 -0
  171. package/src/kpis.ts +275 -0
  172. package/src/metrics.ts +825 -0
  173. package/src/okrs.ts +325 -0
  174. package/src/organization.ts +909 -0
  175. package/src/process.ts +272 -0
  176. package/src/product.ts +178 -0
  177. package/src/queries.ts +767 -0
  178. package/src/roles.ts +686 -0
  179. package/src/service.ts +164 -0
  180. package/src/types.ts +493 -0
  181. package/src/vision.ts +88 -0
  182. package/src/workflow.ts +280 -0
  183. package/tsconfig.json +9 -0
  184. package/dist/loaders/index.d.ts +0 -174
  185. package/dist/loaders/index.js +0 -366
  186. package/dist/loaders/index.js.map +0 -1
  187. package/dist/schema/index.d.ts +0 -146
  188. package/dist/schema/index.js +0 -716
  189. package/dist/schema/index.js.map +0 -1
  190. package/dist/types-CJ9eGS_C.d.ts +0 -86
@@ -0,0 +1,1352 @@
1
+ /**
2
+ * Sales Entity Types (Nouns)
3
+ *
4
+ * Sales and revenue: Deal, Pipeline, Stage, Contract, Subscription, Order, Quote.
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+
9
+ import type { Noun } from 'ai-database'
10
+
11
+ // =============================================================================
12
+ // Deal (Opportunity)
13
+ // =============================================================================
14
+
15
+ /**
16
+ * Deal entity
17
+ *
18
+ * Represents a sales opportunity/deal.
19
+ */
20
+ export const Deal: Noun = {
21
+ singular: 'deal',
22
+ plural: 'deals',
23
+ description: 'A sales opportunity or deal',
24
+
25
+ properties: {
26
+ // Identity
27
+ name: {
28
+ type: 'string',
29
+ description: 'Deal name',
30
+ },
31
+ description: {
32
+ type: 'string',
33
+ optional: true,
34
+ description: 'Deal description',
35
+ },
36
+
37
+ // Value
38
+ amount: {
39
+ type: 'number',
40
+ optional: true,
41
+ description: 'Deal amount',
42
+ },
43
+ currency: {
44
+ type: 'string',
45
+ optional: true,
46
+ description: 'Currency code',
47
+ },
48
+ recurringAmount: {
49
+ type: 'number',
50
+ optional: true,
51
+ description: 'Recurring amount (MRR/ARR)',
52
+ },
53
+ oneTimeAmount: {
54
+ type: 'number',
55
+ optional: true,
56
+ description: 'One-time amount',
57
+ },
58
+
59
+ // Pipeline
60
+ stage: {
61
+ type: 'string',
62
+ description: 'Current stage',
63
+ examples: ['lead', 'qualified', 'discovery', 'demo', 'proposal', 'negotiation', 'closed-won', 'closed-lost'],
64
+ },
65
+ probability: {
66
+ type: 'number',
67
+ optional: true,
68
+ description: 'Win probability (0-100)',
69
+ },
70
+ weightedAmount: {
71
+ type: 'number',
72
+ optional: true,
73
+ description: 'Weighted deal value',
74
+ },
75
+
76
+ // Type
77
+ type: {
78
+ type: 'string',
79
+ optional: true,
80
+ description: 'Deal type',
81
+ examples: ['new-business', 'expansion', 'renewal', 'upsell', 'cross-sell'],
82
+ },
83
+
84
+ // Timeline
85
+ expectedCloseDate: {
86
+ type: 'date',
87
+ optional: true,
88
+ description: 'Expected close date',
89
+ },
90
+ actualCloseDate: {
91
+ type: 'date',
92
+ optional: true,
93
+ description: 'Actual close date',
94
+ },
95
+ createdAt: {
96
+ type: 'datetime',
97
+ optional: true,
98
+ description: 'Created date',
99
+ },
100
+ lastActivityAt: {
101
+ type: 'datetime',
102
+ optional: true,
103
+ description: 'Last activity date',
104
+ },
105
+
106
+ // Source
107
+ source: {
108
+ type: 'string',
109
+ optional: true,
110
+ description: 'Lead source',
111
+ examples: ['inbound', 'outbound', 'referral', 'partner', 'marketing', 'event'],
112
+ },
113
+ campaignId: {
114
+ type: 'string',
115
+ optional: true,
116
+ description: 'Source campaign',
117
+ },
118
+
119
+ // Competition
120
+ competitors: {
121
+ type: 'string',
122
+ array: true,
123
+ optional: true,
124
+ description: 'Competitors in deal',
125
+ },
126
+
127
+ // Loss reason
128
+ lossReason: {
129
+ type: 'string',
130
+ optional: true,
131
+ description: 'Reason for loss',
132
+ examples: ['price', 'features', 'competitor', 'timing', 'budget', 'no-decision', 'champion-left'],
133
+ },
134
+ lossNotes: {
135
+ type: 'string',
136
+ optional: true,
137
+ description: 'Loss details',
138
+ },
139
+
140
+ // Forecast
141
+ forecastCategory: {
142
+ type: 'string',
143
+ optional: true,
144
+ description: 'Forecast category',
145
+ examples: ['pipeline', 'best-case', 'commit', 'closed'],
146
+ },
147
+
148
+ // Priority
149
+ priority: {
150
+ type: 'string',
151
+ optional: true,
152
+ description: 'Deal priority',
153
+ examples: ['critical', 'high', 'medium', 'low'],
154
+ },
155
+
156
+ // Status
157
+ status: {
158
+ type: 'string',
159
+ description: 'Deal status',
160
+ examples: ['open', 'won', 'lost', 'archived'],
161
+ },
162
+ },
163
+
164
+ relationships: {
165
+ customer: {
166
+ type: 'Customer',
167
+ required: false,
168
+ description: 'Customer',
169
+ },
170
+ account: {
171
+ type: 'Account',
172
+ required: false,
173
+ description: 'Account',
174
+ },
175
+ contacts: {
176
+ type: 'Contact[]',
177
+ description: 'Deal contacts',
178
+ },
179
+ owner: {
180
+ type: 'Worker',
181
+ required: false,
182
+ description: 'Deal owner',
183
+ },
184
+ pipeline: {
185
+ type: 'Pipeline',
186
+ required: false,
187
+ description: 'Pipeline',
188
+ },
189
+ products: {
190
+ type: 'Product[]',
191
+ description: 'Products in deal',
192
+ },
193
+ quotes: {
194
+ type: 'Quote[]',
195
+ description: 'Quotes',
196
+ },
197
+ contract: {
198
+ type: 'Contract',
199
+ required: false,
200
+ description: 'Resulting contract',
201
+ },
202
+ interactions: {
203
+ type: 'Interaction[]',
204
+ description: 'Deal activities',
205
+ },
206
+ },
207
+
208
+ actions: [
209
+ 'create',
210
+ 'update',
211
+ 'qualify',
212
+ 'advance',
213
+ 'setStage',
214
+ 'assignOwner',
215
+ 'addProduct',
216
+ 'removeProduct',
217
+ 'createQuote',
218
+ 'win',
219
+ 'lose',
220
+ 'reopen',
221
+ 'archive',
222
+ ],
223
+
224
+ events: [
225
+ 'created',
226
+ 'updated',
227
+ 'qualified',
228
+ 'stageChanged',
229
+ 'ownerAssigned',
230
+ 'productAdded',
231
+ 'productRemoved',
232
+ 'quoteCreated',
233
+ 'won',
234
+ 'lost',
235
+ 'reopened',
236
+ 'archived',
237
+ ],
238
+ }
239
+
240
+ // =============================================================================
241
+ // Pipeline
242
+ // =============================================================================
243
+
244
+ /**
245
+ * Pipeline entity
246
+ *
247
+ * Represents a sales pipeline.
248
+ */
249
+ export const Pipeline: Noun = {
250
+ singular: 'pipeline',
251
+ plural: 'pipelines',
252
+ description: 'A sales pipeline',
253
+
254
+ properties: {
255
+ // Identity
256
+ name: {
257
+ type: 'string',
258
+ description: 'Pipeline name',
259
+ },
260
+ description: {
261
+ type: 'string',
262
+ optional: true,
263
+ description: 'Pipeline description',
264
+ },
265
+
266
+ // Type
267
+ type: {
268
+ type: 'string',
269
+ optional: true,
270
+ description: 'Pipeline type',
271
+ examples: ['sales', 'renewal', 'expansion', 'partnership'],
272
+ },
273
+
274
+ // Default
275
+ isDefault: {
276
+ type: 'boolean',
277
+ optional: true,
278
+ description: 'Is default pipeline',
279
+ },
280
+
281
+ // Metrics
282
+ dealCount: {
283
+ type: 'number',
284
+ optional: true,
285
+ description: 'Number of deals',
286
+ },
287
+ totalValue: {
288
+ type: 'number',
289
+ optional: true,
290
+ description: 'Total pipeline value',
291
+ },
292
+ weightedValue: {
293
+ type: 'number',
294
+ optional: true,
295
+ description: 'Weighted pipeline value',
296
+ },
297
+ avgDealSize: {
298
+ type: 'number',
299
+ optional: true,
300
+ description: 'Average deal size',
301
+ },
302
+ avgCycleTime: {
303
+ type: 'number',
304
+ optional: true,
305
+ description: 'Average cycle time (days)',
306
+ },
307
+ winRate: {
308
+ type: 'number',
309
+ optional: true,
310
+ description: 'Win rate percentage',
311
+ },
312
+ currency: {
313
+ type: 'string',
314
+ optional: true,
315
+ description: 'Currency code',
316
+ },
317
+
318
+ // Status
319
+ status: {
320
+ type: 'string',
321
+ description: 'Pipeline status',
322
+ examples: ['active', 'inactive', 'archived'],
323
+ },
324
+ },
325
+
326
+ relationships: {
327
+ stages: {
328
+ type: 'Stage[]',
329
+ description: 'Pipeline stages',
330
+ },
331
+ deals: {
332
+ type: 'Deal[]',
333
+ description: 'Deals in pipeline',
334
+ },
335
+ team: {
336
+ type: 'Team',
337
+ required: false,
338
+ description: 'Sales team',
339
+ },
340
+ },
341
+
342
+ actions: [
343
+ 'create',
344
+ 'update',
345
+ 'addStage',
346
+ 'removeStage',
347
+ 'reorderStages',
348
+ 'setDefault',
349
+ 'archive',
350
+ ],
351
+
352
+ events: [
353
+ 'created',
354
+ 'updated',
355
+ 'stageAdded',
356
+ 'stageRemoved',
357
+ 'stagesReordered',
358
+ 'defaultSet',
359
+ 'archived',
360
+ ],
361
+ }
362
+
363
+ // =============================================================================
364
+ // Stage
365
+ // =============================================================================
366
+
367
+ /**
368
+ * Stage entity
369
+ *
370
+ * Represents a stage in a sales pipeline.
371
+ */
372
+ export const Stage: Noun = {
373
+ singular: 'stage',
374
+ plural: 'stages',
375
+ description: 'A stage in a sales pipeline',
376
+
377
+ properties: {
378
+ // Identity
379
+ name: {
380
+ type: 'string',
381
+ description: 'Stage name',
382
+ },
383
+ description: {
384
+ type: 'string',
385
+ optional: true,
386
+ description: 'Stage description',
387
+ },
388
+
389
+ // Order
390
+ order: {
391
+ type: 'number',
392
+ description: 'Stage order',
393
+ },
394
+
395
+ // Probability
396
+ probability: {
397
+ type: 'number',
398
+ optional: true,
399
+ description: 'Win probability at this stage',
400
+ },
401
+
402
+ // Type
403
+ type: {
404
+ type: 'string',
405
+ optional: true,
406
+ description: 'Stage type',
407
+ examples: ['open', 'won', 'lost'],
408
+ },
409
+
410
+ // Requirements
411
+ requirements: {
412
+ type: 'string',
413
+ array: true,
414
+ optional: true,
415
+ description: 'Requirements to enter stage',
416
+ },
417
+ exitCriteria: {
418
+ type: 'string',
419
+ array: true,
420
+ optional: true,
421
+ description: 'Criteria to exit stage',
422
+ },
423
+
424
+ // Metrics
425
+ dealCount: {
426
+ type: 'number',
427
+ optional: true,
428
+ description: 'Deals in this stage',
429
+ },
430
+ avgTimeInStage: {
431
+ type: 'number',
432
+ optional: true,
433
+ description: 'Average days in stage',
434
+ },
435
+ conversionRate: {
436
+ type: 'number',
437
+ optional: true,
438
+ description: 'Conversion to next stage',
439
+ },
440
+
441
+ // Automation
442
+ rottenAfterDays: {
443
+ type: 'number',
444
+ optional: true,
445
+ description: 'Days until deal is considered stale',
446
+ },
447
+ },
448
+
449
+ relationships: {
450
+ pipeline: {
451
+ type: 'Pipeline',
452
+ description: 'Parent pipeline',
453
+ },
454
+ deals: {
455
+ type: 'Deal[]',
456
+ description: 'Deals in this stage',
457
+ },
458
+ },
459
+
460
+ actions: [
461
+ 'create',
462
+ 'update',
463
+ 'move',
464
+ 'delete',
465
+ ],
466
+
467
+ events: [
468
+ 'created',
469
+ 'updated',
470
+ 'moved',
471
+ 'deleted',
472
+ ],
473
+ }
474
+
475
+ // =============================================================================
476
+ // Contract
477
+ // =============================================================================
478
+
479
+ /**
480
+ * Contract entity
481
+ *
482
+ * Represents a sales/service contract.
483
+ */
484
+ export const Contract: Noun = {
485
+ singular: 'contract',
486
+ plural: 'contracts',
487
+ description: 'A sales or service contract',
488
+
489
+ properties: {
490
+ // Identity
491
+ name: {
492
+ type: 'string',
493
+ description: 'Contract name',
494
+ },
495
+ number: {
496
+ type: 'string',
497
+ optional: true,
498
+ description: 'Contract number',
499
+ },
500
+ description: {
501
+ type: 'string',
502
+ optional: true,
503
+ description: 'Contract description',
504
+ },
505
+
506
+ // Type
507
+ type: {
508
+ type: 'string',
509
+ description: 'Contract type',
510
+ examples: ['subscription', 'service', 'license', 'maintenance', 'support', 'msa', 'sow'],
511
+ },
512
+
513
+ // Value
514
+ totalValue: {
515
+ type: 'number',
516
+ optional: true,
517
+ description: 'Total contract value',
518
+ },
519
+ recurringValue: {
520
+ type: 'number',
521
+ optional: true,
522
+ description: 'Recurring value (ARR)',
523
+ },
524
+ currency: {
525
+ type: 'string',
526
+ optional: true,
527
+ description: 'Currency code',
528
+ },
529
+
530
+ // Term
531
+ startDate: {
532
+ type: 'date',
533
+ description: 'Start date',
534
+ },
535
+ endDate: {
536
+ type: 'date',
537
+ optional: true,
538
+ description: 'End date',
539
+ },
540
+ term: {
541
+ type: 'number',
542
+ optional: true,
543
+ description: 'Term in months',
544
+ },
545
+ autoRenew: {
546
+ type: 'boolean',
547
+ optional: true,
548
+ description: 'Auto-renew enabled',
549
+ },
550
+ renewalNoticeDays: {
551
+ type: 'number',
552
+ optional: true,
553
+ description: 'Days notice for renewal',
554
+ },
555
+
556
+ // Billing
557
+ billingFrequency: {
558
+ type: 'string',
559
+ optional: true,
560
+ description: 'Billing frequency',
561
+ examples: ['monthly', 'quarterly', 'annually', 'one-time'],
562
+ },
563
+ paymentTerms: {
564
+ type: 'string',
565
+ optional: true,
566
+ description: 'Payment terms',
567
+ examples: ['net-15', 'net-30', 'net-45', 'net-60', 'due-on-receipt'],
568
+ },
569
+
570
+ // Documents
571
+ documentUrl: {
572
+ type: 'url',
573
+ optional: true,
574
+ description: 'Contract document URL',
575
+ },
576
+ signedDate: {
577
+ type: 'date',
578
+ optional: true,
579
+ description: 'Date signed',
580
+ },
581
+
582
+ // Status
583
+ status: {
584
+ type: 'string',
585
+ description: 'Contract status',
586
+ examples: ['draft', 'pending-signature', 'active', 'expiring', 'expired', 'renewed', 'terminated', 'cancelled'],
587
+ },
588
+ },
589
+
590
+ relationships: {
591
+ customer: {
592
+ type: 'Customer',
593
+ required: false,
594
+ description: 'Customer',
595
+ },
596
+ account: {
597
+ type: 'Account',
598
+ required: false,
599
+ description: 'Account',
600
+ },
601
+ deal: {
602
+ type: 'Deal',
603
+ required: false,
604
+ description: 'Source deal',
605
+ },
606
+ owner: {
607
+ type: 'Worker',
608
+ required: false,
609
+ description: 'Contract owner',
610
+ },
611
+ subscriptions: {
612
+ type: 'Subscription[]',
613
+ description: 'Contract subscriptions',
614
+ },
615
+ lineItems: {
616
+ type: 'ContractLineItem[]',
617
+ description: 'Contract line items',
618
+ },
619
+ renewedFrom: {
620
+ type: 'Contract',
621
+ required: false,
622
+ description: 'Previous contract (if renewal)',
623
+ },
624
+ renewedTo: {
625
+ type: 'Contract',
626
+ required: false,
627
+ description: 'Renewal contract',
628
+ },
629
+ },
630
+
631
+ actions: [
632
+ 'create',
633
+ 'update',
634
+ 'send',
635
+ 'sign',
636
+ 'activate',
637
+ 'amend',
638
+ 'renew',
639
+ 'terminate',
640
+ 'cancel',
641
+ 'archive',
642
+ ],
643
+
644
+ events: [
645
+ 'created',
646
+ 'updated',
647
+ 'sent',
648
+ 'signed',
649
+ 'activated',
650
+ 'amended',
651
+ 'renewed',
652
+ 'expiring',
653
+ 'expired',
654
+ 'terminated',
655
+ 'cancelled',
656
+ 'archived',
657
+ ],
658
+ }
659
+
660
+ // =============================================================================
661
+ // Subscription
662
+ // =============================================================================
663
+
664
+ /**
665
+ * Subscription entity
666
+ *
667
+ * Represents a customer subscription.
668
+ */
669
+ export const Subscription: Noun = {
670
+ singular: 'subscription',
671
+ plural: 'subscriptions',
672
+ description: 'A customer subscription',
673
+
674
+ properties: {
675
+ // Value
676
+ mrr: {
677
+ type: 'number',
678
+ optional: true,
679
+ description: 'Monthly recurring revenue',
680
+ },
681
+ arr: {
682
+ type: 'number',
683
+ optional: true,
684
+ description: 'Annual recurring revenue',
685
+ },
686
+ quantity: {
687
+ type: 'number',
688
+ optional: true,
689
+ description: 'Quantity/seats',
690
+ },
691
+ unitPrice: {
692
+ type: 'number',
693
+ optional: true,
694
+ description: 'Price per unit',
695
+ },
696
+ currency: {
697
+ type: 'string',
698
+ optional: true,
699
+ description: 'Currency code',
700
+ },
701
+
702
+ // Plan
703
+ planId: {
704
+ type: 'string',
705
+ optional: true,
706
+ description: 'Plan ID',
707
+ },
708
+ planName: {
709
+ type: 'string',
710
+ optional: true,
711
+ description: 'Plan name',
712
+ },
713
+
714
+ // Billing
715
+ billingPeriod: {
716
+ type: 'string',
717
+ optional: true,
718
+ description: 'Billing period',
719
+ examples: ['monthly', 'quarterly', 'annually'],
720
+ },
721
+ billingAnchor: {
722
+ type: 'number',
723
+ optional: true,
724
+ description: 'Billing anchor day',
725
+ },
726
+ currentPeriodStart: {
727
+ type: 'date',
728
+ optional: true,
729
+ description: 'Current period start',
730
+ },
731
+ currentPeriodEnd: {
732
+ type: 'date',
733
+ optional: true,
734
+ description: 'Current period end',
735
+ },
736
+
737
+ // Dates
738
+ startDate: {
739
+ type: 'date',
740
+ description: 'Start date',
741
+ },
742
+ endDate: {
743
+ type: 'date',
744
+ optional: true,
745
+ description: 'End date',
746
+ },
747
+ cancelledAt: {
748
+ type: 'datetime',
749
+ optional: true,
750
+ description: 'Cancellation date',
751
+ },
752
+ cancelAtPeriodEnd: {
753
+ type: 'boolean',
754
+ optional: true,
755
+ description: 'Cancel at period end',
756
+ },
757
+
758
+ // Trial
759
+ trialStart: {
760
+ type: 'date',
761
+ optional: true,
762
+ description: 'Trial start date',
763
+ },
764
+ trialEnd: {
765
+ type: 'date',
766
+ optional: true,
767
+ description: 'Trial end date',
768
+ },
769
+
770
+ // Discount
771
+ discountPercent: {
772
+ type: 'number',
773
+ optional: true,
774
+ description: 'Discount percentage',
775
+ },
776
+ discountAmount: {
777
+ type: 'number',
778
+ optional: true,
779
+ description: 'Discount amount',
780
+ },
781
+
782
+ // External
783
+ stripeSubscriptionId: {
784
+ type: 'string',
785
+ optional: true,
786
+ description: 'Stripe subscription ID',
787
+ },
788
+
789
+ // Status
790
+ status: {
791
+ type: 'string',
792
+ description: 'Subscription status',
793
+ examples: ['trialing', 'active', 'past-due', 'paused', 'cancelled', 'expired'],
794
+ },
795
+ },
796
+
797
+ relationships: {
798
+ customer: {
799
+ type: 'Customer',
800
+ description: 'Customer',
801
+ },
802
+ product: {
803
+ type: 'Product',
804
+ required: false,
805
+ description: 'Product',
806
+ },
807
+ pricingPlan: {
808
+ type: 'PricingPlan',
809
+ required: false,
810
+ description: 'Pricing plan',
811
+ },
812
+ contract: {
813
+ type: 'Contract',
814
+ required: false,
815
+ description: 'Associated contract',
816
+ },
817
+ invoices: {
818
+ type: 'Invoice[]',
819
+ description: 'Invoices',
820
+ },
821
+ },
822
+
823
+ actions: [
824
+ 'create',
825
+ 'update',
826
+ 'activate',
827
+ 'upgrade',
828
+ 'downgrade',
829
+ 'addQuantity',
830
+ 'removeQuantity',
831
+ 'pause',
832
+ 'resume',
833
+ 'cancel',
834
+ 'reactivate',
835
+ ],
836
+
837
+ events: [
838
+ 'created',
839
+ 'updated',
840
+ 'activated',
841
+ 'upgraded',
842
+ 'downgraded',
843
+ 'quantityChanged',
844
+ 'paused',
845
+ 'resumed',
846
+ 'cancelled',
847
+ 'reactivated',
848
+ 'renewed',
849
+ 'expired',
850
+ ],
851
+ }
852
+
853
+ // =============================================================================
854
+ // Quote
855
+ // =============================================================================
856
+
857
+ /**
858
+ * Quote entity
859
+ *
860
+ * Represents a sales quote/proposal.
861
+ */
862
+ export const Quote: Noun = {
863
+ singular: 'quote',
864
+ plural: 'quotes',
865
+ description: 'A sales quote or proposal',
866
+
867
+ properties: {
868
+ // Identity
869
+ number: {
870
+ type: 'string',
871
+ description: 'Quote number',
872
+ },
873
+ name: {
874
+ type: 'string',
875
+ optional: true,
876
+ description: 'Quote name',
877
+ },
878
+
879
+ // Value
880
+ subtotal: {
881
+ type: 'number',
882
+ optional: true,
883
+ description: 'Subtotal',
884
+ },
885
+ discount: {
886
+ type: 'number',
887
+ optional: true,
888
+ description: 'Discount amount',
889
+ },
890
+ discountPercent: {
891
+ type: 'number',
892
+ optional: true,
893
+ description: 'Discount percentage',
894
+ },
895
+ tax: {
896
+ type: 'number',
897
+ optional: true,
898
+ description: 'Tax amount',
899
+ },
900
+ total: {
901
+ type: 'number',
902
+ description: 'Total amount',
903
+ },
904
+ currency: {
905
+ type: 'string',
906
+ optional: true,
907
+ description: 'Currency code',
908
+ },
909
+
910
+ // Recurring
911
+ mrr: {
912
+ type: 'number',
913
+ optional: true,
914
+ description: 'Monthly recurring',
915
+ },
916
+ arr: {
917
+ type: 'number',
918
+ optional: true,
919
+ description: 'Annual recurring',
920
+ },
921
+
922
+ // Validity
923
+ validFrom: {
924
+ type: 'date',
925
+ optional: true,
926
+ description: 'Valid from date',
927
+ },
928
+ validUntil: {
929
+ type: 'date',
930
+ optional: true,
931
+ description: 'Valid until date',
932
+ },
933
+
934
+ // Terms
935
+ terms: {
936
+ type: 'string',
937
+ optional: true,
938
+ description: 'Terms and conditions',
939
+ },
940
+ notes: {
941
+ type: 'string',
942
+ optional: true,
943
+ description: 'Notes',
944
+ },
945
+
946
+ // Documents
947
+ documentUrl: {
948
+ type: 'url',
949
+ optional: true,
950
+ description: 'Quote document URL',
951
+ },
952
+
953
+ // Status
954
+ status: {
955
+ type: 'string',
956
+ description: 'Quote status',
957
+ examples: ['draft', 'sent', 'viewed', 'accepted', 'rejected', 'expired', 'superseded'],
958
+ },
959
+ },
960
+
961
+ relationships: {
962
+ deal: {
963
+ type: 'Deal',
964
+ required: false,
965
+ description: 'Associated deal',
966
+ },
967
+ customer: {
968
+ type: 'Customer',
969
+ required: false,
970
+ description: 'Customer',
971
+ },
972
+ account: {
973
+ type: 'Account',
974
+ required: false,
975
+ description: 'Account',
976
+ },
977
+ contact: {
978
+ type: 'Contact',
979
+ required: false,
980
+ description: 'Primary contact',
981
+ },
982
+ createdBy: {
983
+ type: 'Worker',
984
+ required: false,
985
+ description: 'Created by',
986
+ },
987
+ lineItems: {
988
+ type: 'QuoteLineItem[]',
989
+ description: 'Quote line items',
990
+ },
991
+ },
992
+
993
+ actions: [
994
+ 'create',
995
+ 'update',
996
+ 'send',
997
+ 'accept',
998
+ 'reject',
999
+ 'expire',
1000
+ 'duplicate',
1001
+ 'convertToOrder',
1002
+ 'archive',
1003
+ ],
1004
+
1005
+ events: [
1006
+ 'created',
1007
+ 'updated',
1008
+ 'sent',
1009
+ 'viewed',
1010
+ 'accepted',
1011
+ 'rejected',
1012
+ 'expired',
1013
+ 'duplicated',
1014
+ 'converted',
1015
+ 'archived',
1016
+ ],
1017
+ }
1018
+
1019
+ // =============================================================================
1020
+ // Order
1021
+ // =============================================================================
1022
+
1023
+ /**
1024
+ * Order entity
1025
+ *
1026
+ * Represents a sales order.
1027
+ */
1028
+ export const Order: Noun = {
1029
+ singular: 'order',
1030
+ plural: 'orders',
1031
+ description: 'A sales order',
1032
+
1033
+ properties: {
1034
+ // Identity
1035
+ number: {
1036
+ type: 'string',
1037
+ description: 'Order number',
1038
+ },
1039
+
1040
+ // Value
1041
+ subtotal: {
1042
+ type: 'number',
1043
+ optional: true,
1044
+ description: 'Subtotal',
1045
+ },
1046
+ discount: {
1047
+ type: 'number',
1048
+ optional: true,
1049
+ description: 'Discount amount',
1050
+ },
1051
+ tax: {
1052
+ type: 'number',
1053
+ optional: true,
1054
+ description: 'Tax amount',
1055
+ },
1056
+ shipping: {
1057
+ type: 'number',
1058
+ optional: true,
1059
+ description: 'Shipping amount',
1060
+ },
1061
+ total: {
1062
+ type: 'number',
1063
+ description: 'Total amount',
1064
+ },
1065
+ currency: {
1066
+ type: 'string',
1067
+ optional: true,
1068
+ description: 'Currency code',
1069
+ },
1070
+
1071
+ // Dates
1072
+ orderedAt: {
1073
+ type: 'datetime',
1074
+ description: 'Order date',
1075
+ },
1076
+ fulfilledAt: {
1077
+ type: 'datetime',
1078
+ optional: true,
1079
+ description: 'Fulfillment date',
1080
+ },
1081
+
1082
+ // Billing
1083
+ billingAddress: {
1084
+ type: 'json',
1085
+ optional: true,
1086
+ description: 'Billing address',
1087
+ },
1088
+ shippingAddress: {
1089
+ type: 'json',
1090
+ optional: true,
1091
+ description: 'Shipping address',
1092
+ },
1093
+
1094
+ // Payment
1095
+ paymentStatus: {
1096
+ type: 'string',
1097
+ optional: true,
1098
+ description: 'Payment status',
1099
+ examples: ['pending', 'paid', 'partial', 'refunded', 'failed'],
1100
+ },
1101
+ paymentMethod: {
1102
+ type: 'string',
1103
+ optional: true,
1104
+ description: 'Payment method',
1105
+ },
1106
+
1107
+ // Fulfillment
1108
+ fulfillmentStatus: {
1109
+ type: 'string',
1110
+ optional: true,
1111
+ description: 'Fulfillment status',
1112
+ examples: ['unfulfilled', 'partial', 'fulfilled', 'shipped', 'delivered'],
1113
+ },
1114
+
1115
+ // Notes
1116
+ notes: {
1117
+ type: 'string',
1118
+ optional: true,
1119
+ description: 'Order notes',
1120
+ },
1121
+
1122
+ // Status
1123
+ status: {
1124
+ type: 'string',
1125
+ description: 'Order status',
1126
+ examples: ['pending', 'confirmed', 'processing', 'completed', 'cancelled', 'refunded'],
1127
+ },
1128
+ },
1129
+
1130
+ relationships: {
1131
+ customer: {
1132
+ type: 'Customer',
1133
+ description: 'Customer',
1134
+ },
1135
+ quote: {
1136
+ type: 'Quote',
1137
+ required: false,
1138
+ description: 'Source quote',
1139
+ },
1140
+ lineItems: {
1141
+ type: 'OrderLineItem[]',
1142
+ description: 'Order line items',
1143
+ },
1144
+ invoices: {
1145
+ type: 'Invoice[]',
1146
+ description: 'Invoices',
1147
+ },
1148
+ },
1149
+
1150
+ actions: [
1151
+ 'create',
1152
+ 'update',
1153
+ 'confirm',
1154
+ 'fulfill',
1155
+ 'ship',
1156
+ 'deliver',
1157
+ 'cancel',
1158
+ 'refund',
1159
+ ],
1160
+
1161
+ events: [
1162
+ 'created',
1163
+ 'updated',
1164
+ 'confirmed',
1165
+ 'fulfilled',
1166
+ 'shipped',
1167
+ 'delivered',
1168
+ 'cancelled',
1169
+ 'refunded',
1170
+ ],
1171
+ }
1172
+
1173
+ // =============================================================================
1174
+ // Invoice
1175
+ // =============================================================================
1176
+
1177
+ /**
1178
+ * Invoice entity
1179
+ *
1180
+ * Represents an invoice.
1181
+ */
1182
+ export const Invoice: Noun = {
1183
+ singular: 'invoice',
1184
+ plural: 'invoices',
1185
+ description: 'An invoice',
1186
+
1187
+ properties: {
1188
+ // Identity
1189
+ number: {
1190
+ type: 'string',
1191
+ description: 'Invoice number',
1192
+ },
1193
+
1194
+ // Value
1195
+ subtotal: {
1196
+ type: 'number',
1197
+ optional: true,
1198
+ description: 'Subtotal',
1199
+ },
1200
+ discount: {
1201
+ type: 'number',
1202
+ optional: true,
1203
+ description: 'Discount amount',
1204
+ },
1205
+ tax: {
1206
+ type: 'number',
1207
+ optional: true,
1208
+ description: 'Tax amount',
1209
+ },
1210
+ total: {
1211
+ type: 'number',
1212
+ description: 'Total amount',
1213
+ },
1214
+ amountDue: {
1215
+ type: 'number',
1216
+ optional: true,
1217
+ description: 'Amount due',
1218
+ },
1219
+ amountPaid: {
1220
+ type: 'number',
1221
+ optional: true,
1222
+ description: 'Amount paid',
1223
+ },
1224
+ currency: {
1225
+ type: 'string',
1226
+ optional: true,
1227
+ description: 'Currency code',
1228
+ },
1229
+
1230
+ // Dates
1231
+ issueDate: {
1232
+ type: 'date',
1233
+ description: 'Issue date',
1234
+ },
1235
+ dueDate: {
1236
+ type: 'date',
1237
+ optional: true,
1238
+ description: 'Due date',
1239
+ },
1240
+ paidAt: {
1241
+ type: 'datetime',
1242
+ optional: true,
1243
+ description: 'Payment date',
1244
+ },
1245
+
1246
+ // Payment
1247
+ paymentTerms: {
1248
+ type: 'string',
1249
+ optional: true,
1250
+ description: 'Payment terms',
1251
+ },
1252
+ paymentMethod: {
1253
+ type: 'string',
1254
+ optional: true,
1255
+ description: 'Payment method',
1256
+ },
1257
+
1258
+ // Documents
1259
+ documentUrl: {
1260
+ type: 'url',
1261
+ optional: true,
1262
+ description: 'Invoice document URL',
1263
+ },
1264
+
1265
+ // External
1266
+ stripeInvoiceId: {
1267
+ type: 'string',
1268
+ optional: true,
1269
+ description: 'Stripe invoice ID',
1270
+ },
1271
+
1272
+ // Status
1273
+ status: {
1274
+ type: 'string',
1275
+ description: 'Invoice status',
1276
+ examples: ['draft', 'sent', 'paid', 'partial', 'overdue', 'void', 'uncollectible'],
1277
+ },
1278
+ },
1279
+
1280
+ relationships: {
1281
+ customer: {
1282
+ type: 'Customer',
1283
+ description: 'Customer',
1284
+ },
1285
+ subscription: {
1286
+ type: 'Subscription',
1287
+ required: false,
1288
+ description: 'Subscription',
1289
+ },
1290
+ order: {
1291
+ type: 'Order',
1292
+ required: false,
1293
+ description: 'Order',
1294
+ },
1295
+ contract: {
1296
+ type: 'Contract',
1297
+ required: false,
1298
+ description: 'Contract',
1299
+ },
1300
+ lineItems: {
1301
+ type: 'InvoiceLineItem[]',
1302
+ description: 'Invoice line items',
1303
+ },
1304
+ payments: {
1305
+ type: 'Payment[]',
1306
+ description: 'Payments',
1307
+ },
1308
+ },
1309
+
1310
+ actions: [
1311
+ 'create',
1312
+ 'update',
1313
+ 'send',
1314
+ 'recordPayment',
1315
+ 'markPaid',
1316
+ 'void',
1317
+ 'writeOff',
1318
+ ],
1319
+
1320
+ events: [
1321
+ 'created',
1322
+ 'updated',
1323
+ 'sent',
1324
+ 'viewed',
1325
+ 'paid',
1326
+ 'partialPayment',
1327
+ 'overdue',
1328
+ 'voided',
1329
+ 'writtenOff',
1330
+ ],
1331
+ }
1332
+
1333
+ // =============================================================================
1334
+ // Exports
1335
+ // =============================================================================
1336
+
1337
+ export const SalesEntities = {
1338
+ Deal,
1339
+ Pipeline,
1340
+ Stage,
1341
+ Contract,
1342
+ Subscription,
1343
+ Quote,
1344
+ Order,
1345
+ Invoice,
1346
+ }
1347
+
1348
+ export const SalesCategories = {
1349
+ pipeline: ['Deal', 'Pipeline', 'Stage'],
1350
+ agreements: ['Contract', 'Subscription'],
1351
+ transactions: ['Quote', 'Order', 'Invoice'],
1352
+ } as const