@elevasis/core 0.21.0 → 0.23.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.
Files changed (132) hide show
  1. package/dist/index.d.ts +2518 -2169
  2. package/dist/index.js +2495 -1095
  3. package/dist/knowledge/index.d.ts +706 -1044
  4. package/dist/knowledge/index.js +9 -9
  5. package/dist/organization-model/index.d.ts +2518 -2169
  6. package/dist/organization-model/index.js +2495 -1095
  7. package/dist/test-utils/index.d.ts +826 -1014
  8. package/dist/test-utils/index.js +1894 -1032
  9. package/package.json +3 -3
  10. package/src/__tests__/template-core-compatibility.test.ts +11 -79
  11. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +852 -397
  12. package/src/auth/multi-tenancy/permissions.ts +20 -8
  13. package/src/business/README.md +2 -2
  14. package/src/business/acquisition/api-schemas.test.ts +175 -2
  15. package/src/business/acquisition/api-schemas.ts +132 -16
  16. package/src/business/acquisition/build-templates.test.ts +4 -4
  17. package/src/business/acquisition/build-templates.ts +72 -30
  18. package/src/business/acquisition/crm-state-actions.test.ts +13 -11
  19. package/src/business/acquisition/index.ts +12 -0
  20. package/src/business/acquisition/types.ts +7 -3
  21. package/src/business/clients/api-schemas.test.ts +115 -0
  22. package/src/business/clients/api-schemas.ts +158 -0
  23. package/src/business/clients/index.ts +1 -0
  24. package/src/business/deals/api-schemas.ts +8 -0
  25. package/src/business/index.ts +5 -2
  26. package/src/business/projects/types.ts +19 -0
  27. package/src/execution/engine/__tests__/fixtures/test-agents.ts +10 -8
  28. package/src/execution/engine/agent/core/__tests__/agent.test.ts +16 -12
  29. package/src/execution/engine/agent/core/__tests__/error-passthrough.test.ts +4 -3
  30. package/src/execution/engine/agent/core/types.ts +25 -15
  31. package/src/execution/engine/agent/index.ts +6 -4
  32. package/src/execution/engine/agent/reasoning/__tests__/request-builder.test.ts +24 -18
  33. package/src/execution/engine/index.ts +3 -0
  34. package/src/execution/engine/workflow/types.ts +9 -2
  35. package/src/knowledge/README.md +8 -7
  36. package/src/knowledge/__tests__/queries.test.ts +74 -73
  37. package/src/knowledge/format.ts +10 -9
  38. package/src/knowledge/index.ts +1 -1
  39. package/src/knowledge/published.ts +1 -1
  40. package/src/knowledge/queries.ts +26 -25
  41. package/src/organization-model/README.md +73 -26
  42. package/src/organization-model/__tests__/content-kinds-registry.test.ts +210 -0
  43. package/src/organization-model/__tests__/defaults.test.ts +76 -96
  44. package/src/organization-model/__tests__/domains/actions.test.ts +56 -0
  45. package/src/organization-model/__tests__/domains/customers.test.ts +299 -295
  46. package/src/organization-model/__tests__/domains/entities.test.ts +56 -0
  47. package/src/organization-model/__tests__/domains/goals.test.ts +493 -479
  48. package/src/organization-model/__tests__/domains/identity.test.ts +280 -279
  49. package/src/organization-model/__tests__/domains/navigation.test.ts +268 -212
  50. package/src/organization-model/__tests__/domains/offerings.test.ts +414 -419
  51. package/src/organization-model/__tests__/domains/policies.test.ts +323 -0
  52. package/src/organization-model/__tests__/domains/resource-mappings.test.ts +271 -271
  53. package/src/organization-model/__tests__/domains/resources.test.ts +310 -0
  54. package/src/organization-model/__tests__/domains/roles.test.ts +463 -347
  55. package/src/organization-model/__tests__/domains/statuses.test.ts +246 -243
  56. package/src/organization-model/__tests__/domains/systems.test.ts +209 -0
  57. package/src/organization-model/__tests__/flatten-additive-merge.test.ts +361 -0
  58. package/src/organization-model/__tests__/foundation.test.ts +74 -102
  59. package/src/organization-model/__tests__/get-resources-for-system.test.ts +144 -0
  60. package/src/organization-model/__tests__/graph.test.ts +899 -71
  61. package/src/organization-model/__tests__/knowledge.test.ts +209 -49
  62. package/src/organization-model/__tests__/lookup-helpers.test.ts +438 -0
  63. package/src/organization-model/__tests__/migration-helpers.test.ts +591 -0
  64. package/src/organization-model/__tests__/prospecting-ssot.test.ts +36 -27
  65. package/src/organization-model/__tests__/recursive-system-schema.test.ts +520 -0
  66. package/src/organization-model/__tests__/resolve.test.ts +174 -23
  67. package/src/organization-model/__tests__/schema.test.ts +291 -114
  68. package/src/organization-model/__tests__/surface-projection.test.ts +207 -97
  69. package/src/organization-model/catalogs/lead-gen.ts +144 -0
  70. package/src/organization-model/content-kinds/config.ts +36 -0
  71. package/src/organization-model/content-kinds/index.ts +74 -0
  72. package/src/organization-model/content-kinds/pipeline.ts +68 -0
  73. package/src/organization-model/content-kinds/registry.ts +44 -0
  74. package/src/organization-model/content-kinds/status.ts +71 -0
  75. package/src/organization-model/content-kinds/template.ts +83 -0
  76. package/src/organization-model/content-kinds/types.ts +117 -0
  77. package/src/organization-model/contracts.ts +13 -3
  78. package/src/organization-model/defaults.ts +499 -86
  79. package/src/organization-model/domains/actions.ts +239 -0
  80. package/src/organization-model/domains/customers.ts +78 -75
  81. package/src/organization-model/domains/entities.ts +144 -0
  82. package/src/organization-model/domains/goals.ts +83 -80
  83. package/src/organization-model/domains/knowledge.ts +76 -17
  84. package/src/organization-model/domains/navigation.ts +107 -384
  85. package/src/organization-model/domains/offerings.ts +71 -66
  86. package/src/organization-model/domains/policies.ts +102 -0
  87. package/src/organization-model/domains/projects.ts +14 -48
  88. package/src/organization-model/domains/prospecting.ts +62 -181
  89. package/src/organization-model/domains/resources.ts +145 -0
  90. package/src/organization-model/domains/roles.ts +96 -55
  91. package/src/organization-model/domains/sales.ts +10 -219
  92. package/src/organization-model/domains/shared.ts +57 -57
  93. package/src/organization-model/domains/statuses.ts +339 -130
  94. package/src/organization-model/domains/systems.ts +203 -0
  95. package/src/organization-model/foundation.ts +54 -67
  96. package/src/organization-model/graph/build.ts +682 -54
  97. package/src/organization-model/graph/link.ts +1 -1
  98. package/src/organization-model/graph/schema.ts +24 -9
  99. package/src/organization-model/graph/types.ts +20 -7
  100. package/src/organization-model/helpers.ts +231 -26
  101. package/src/organization-model/icons.ts +1 -0
  102. package/src/organization-model/index.ts +118 -5
  103. package/src/organization-model/migration-helpers.ts +249 -0
  104. package/src/organization-model/organization-graph.mdx +16 -15
  105. package/src/organization-model/organization-model.mdx +111 -44
  106. package/src/organization-model/published.ts +172 -19
  107. package/src/organization-model/resolve.ts +117 -54
  108. package/src/organization-model/schema.ts +654 -112
  109. package/src/organization-model/surface-projection.ts +116 -122
  110. package/src/organization-model/types.ts +146 -20
  111. package/src/platform/api/types.ts +38 -35
  112. package/src/platform/constants/versions.ts +1 -1
  113. package/src/platform/registry/__tests__/command-view.test.ts +6 -8
  114. package/src/platform/registry/__tests__/resource-link.test.ts +13 -8
  115. package/src/platform/registry/__tests__/resource-registry.integration.test.ts +16 -31
  116. package/src/platform/registry/__tests__/resource-registry.nested-systems.test.ts +245 -0
  117. package/src/platform/registry/__tests__/resource-registry.test.ts +2053 -2005
  118. package/src/platform/registry/__tests__/validation.test.ts +1347 -1086
  119. package/src/platform/registry/index.ts +14 -0
  120. package/src/platform/registry/resource-registry.ts +52 -2
  121. package/src/platform/registry/serialization.ts +241 -202
  122. package/src/platform/registry/serialized-types.ts +1 -0
  123. package/src/platform/registry/types.ts +411 -361
  124. package/src/platform/registry/validation.ts +745 -513
  125. package/src/projects/api-schemas.ts +290 -267
  126. package/src/reference/_generated/contracts.md +853 -397
  127. package/src/reference/glossary.md +23 -18
  128. package/src/supabase/database.types.ts +181 -0
  129. package/src/test-utils/test-utils.test.ts +1 -6
  130. package/src/organization-model/__tests__/domains/operations.test.ts +0 -203
  131. package/src/organization-model/domains/features.ts +0 -31
  132. package/src/organization-model/domains/operations.ts +0 -85
@@ -0,0 +1,239 @@
1
+ import { z } from 'zod'
2
+ import { EntityIdSchema } from './entities'
3
+ import { DescriptionSchema, LabelSchema, ModelIdSchema } from './shared'
4
+
5
+ export const ActionResourceIdSchema = z
6
+ .string()
7
+ .trim()
8
+ .min(1)
9
+ .max(255)
10
+ .regex(/^[A-Za-z0-9]+(?:[-._][A-Za-z0-9]+)*$/, 'Resource IDs must use letters, numbers, -, _, or . separators')
11
+
12
+ export const ActionInvocationKindSchema = z
13
+ .enum(['slash-command', 'mcp-tool', 'api-endpoint', 'script-execution'])
14
+ .meta({ label: 'Invocation kind' })
15
+
16
+ export const ActionIdSchema = ModelIdSchema
17
+
18
+ export const ActionScopeSchema = z.union([
19
+ z.literal('global'),
20
+ z.object({
21
+ domain: ModelIdSchema
22
+ })
23
+ ])
24
+
25
+ export const ActionRefSchema = z.object({
26
+ actionId: ActionIdSchema.meta({ ref: 'action' }),
27
+ intent: z.enum(['exposes', 'consumes']).meta({ label: 'Intent' })
28
+ })
29
+
30
+ export const SlashCommandInvocationSchema = z.object({
31
+ kind: z.literal('slash-command'),
32
+ command: z
33
+ .string()
34
+ .trim()
35
+ .min(1)
36
+ .max(200)
37
+ .regex(/^\/[^\s].*$/, 'Slash commands must start with /'),
38
+ toolFactory: ModelIdSchema.optional()
39
+ })
40
+
41
+ export const McpToolInvocationSchema = z.object({
42
+ kind: z.literal('mcp-tool'),
43
+ server: ModelIdSchema,
44
+ name: ModelIdSchema
45
+ })
46
+
47
+ export const ApiEndpointInvocationSchema = z.object({
48
+ kind: z.literal('api-endpoint'),
49
+ method: z.enum(['GET', 'POST', 'PATCH', 'DELETE']).meta({ label: 'HTTP method' }),
50
+ path: z.string().trim().startsWith('/').max(500),
51
+ requestSchema: ModelIdSchema.optional(),
52
+ responseSchema: ModelIdSchema.optional()
53
+ })
54
+
55
+ export const ScriptExecutionInvocationSchema = z.object({
56
+ kind: z.literal('script-execution'),
57
+ resourceId: ActionResourceIdSchema
58
+ })
59
+
60
+ export const ActionInvocationSchema = z.discriminatedUnion('kind', [
61
+ SlashCommandInvocationSchema,
62
+ McpToolInvocationSchema,
63
+ ApiEndpointInvocationSchema,
64
+ ScriptExecutionInvocationSchema
65
+ ])
66
+
67
+ export const ActionSchema = z.object({
68
+ id: ActionIdSchema,
69
+ /** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
70
+ order: z.number(),
71
+ label: LabelSchema,
72
+ description: DescriptionSchema.optional(),
73
+ scope: ActionScopeSchema.default('global'),
74
+ resourceId: ActionResourceIdSchema.optional(),
75
+ affects: z.array(EntityIdSchema.meta({ ref: 'entity' })).optional(),
76
+ invocations: z.array(ActionInvocationSchema).default([]),
77
+ knowledge: z
78
+ .array(ModelIdSchema.meta({ ref: 'knowledge' }))
79
+ .default([])
80
+ .optional(),
81
+ lifecycle: z
82
+ .enum(['draft', 'beta', 'active', 'deprecated', 'archived'])
83
+ .meta({ label: 'Lifecycle', color: 'teal' })
84
+ .default('active')
85
+ })
86
+
87
+ export const ActionsDomainSchema = z
88
+ .record(z.string(), ActionSchema)
89
+ .refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
90
+ message: 'Each action entry id must match its map key'
91
+ })
92
+ .default({})
93
+
94
+ const LEAD_GEN_ACTION_ENTRY_INPUTS: z.input<typeof ActionSchema>[] = [
95
+ {
96
+ id: 'lead-gen.company.source',
97
+ order: 10,
98
+ label: 'Source companies',
99
+ description: 'Import source companies from a list provider.',
100
+ scope: { domain: 'sales' },
101
+ resourceId: 'lgn-import-workflow',
102
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/companies/source' }]
103
+ },
104
+ {
105
+ id: 'lead-gen.company.apollo-import',
106
+ order: 20,
107
+ label: 'Import from Apollo',
108
+ description: 'Pull companies and seed contact data from an Apollo search or list.',
109
+ scope: { domain: 'sales' },
110
+ resourceId: 'lgn-01c-apollo-import-workflow',
111
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/companies/apollo-import' }]
112
+ },
113
+ {
114
+ id: 'lead-gen.contact.discover',
115
+ order: 30,
116
+ label: 'Discover contact emails',
117
+ description: 'Find email addresses for contacts at qualified companies.',
118
+ scope: { domain: 'sales' },
119
+ resourceId: 'lgn-04-email-discovery-workflow',
120
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/contacts/discover' }]
121
+ },
122
+ {
123
+ id: 'lead-gen.contact.verify-email',
124
+ order: 40,
125
+ label: 'Verify emails',
126
+ description: 'Check email deliverability before outreach.',
127
+ scope: { domain: 'sales' },
128
+ resourceId: 'lgn-05-email-verification-workflow',
129
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/contacts/verify-email' }]
130
+ },
131
+ {
132
+ id: 'lead-gen.company.apify-crawl',
133
+ order: 50,
134
+ label: 'Crawl websites',
135
+ description:
136
+ 'Crawl company websites via Apify and store raw page markdown in enrichmentData.websiteCrawl.pages for downstream LLM analysis.',
137
+ scope: { domain: 'sales' },
138
+ resourceId: 'lgn-02a-apify-website-crawl-workflow',
139
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/companies/apify-crawl' }]
140
+ },
141
+ {
142
+ id: 'lead-gen.company.website-extract',
143
+ order: 60,
144
+ label: 'Extract website signals',
145
+ description: 'Scrape and analyze company websites for qualification signals.',
146
+ scope: { domain: 'sales' },
147
+ resourceId: 'lgn-02-website-extract-workflow',
148
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/companies/website-extract' }]
149
+ },
150
+ {
151
+ id: 'lead-gen.company.qualify',
152
+ order: 70,
153
+ label: 'Qualify companies',
154
+ description: 'Score and filter companies against the ICP rubric.',
155
+ scope: { domain: 'sales' },
156
+ resourceId: 'lgn-03-company-qualification-workflow',
157
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/companies/qualify' }]
158
+ },
159
+ {
160
+ id: 'lead-gen.company.dtc-subscription-qualify',
161
+ order: 80,
162
+ label: 'Qualify DTC subscription fit',
163
+ description: 'Classify subscription potential and consumable-product fit for DTC brands.',
164
+ scope: { domain: 'sales' },
165
+ resourceId: 'lgn-03b-dtc-subscription-score-workflow',
166
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/companies/dtc-subscription-qualify' }]
167
+ },
168
+ {
169
+ id: 'lead-gen.contact.apollo-decision-maker-enrich',
170
+ order: 90,
171
+ label: 'Enrich decision-makers',
172
+ description: 'Find and enrich qualified contacts at qualified companies via Apollo.',
173
+ scope: { domain: 'sales' },
174
+ resourceId: 'lgn-04b-apollo-decision-maker-enrich-workflow',
175
+ invocations: [
176
+ { kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/contacts/apollo-decision-maker-enrich' }
177
+ ]
178
+ },
179
+ {
180
+ id: 'lead-gen.contact.personalize',
181
+ order: 100,
182
+ label: 'Personalize outreach',
183
+ description: 'Generate personalized opening lines for each contact.',
184
+ scope: { domain: 'sales' },
185
+ resourceId: 'ist-personalization-workflow',
186
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/contacts/personalize' }]
187
+ },
188
+ {
189
+ id: 'lead-gen.review.outreach-ready',
190
+ order: 110,
191
+ label: 'Upload to outreach',
192
+ description: 'Upload approved contacts to the outreach sequence after QC review.',
193
+ scope: { domain: 'sales' },
194
+ resourceId: 'ist-upload-contacts-workflow',
195
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/review/outreach-ready' }]
196
+ },
197
+ {
198
+ id: 'lead-gen.export.list',
199
+ order: 120,
200
+ label: 'Export lead list',
201
+ description: 'Export approved leads as a downloadable lead list.',
202
+ scope: { domain: 'sales' },
203
+ resourceId: 'lgn-06-export-list-workflow',
204
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/export/list' }]
205
+ },
206
+ {
207
+ id: 'lead-gen.company.cleanup',
208
+ order: 130,
209
+ label: 'Clean up companies',
210
+ description: 'Remove disqualified or duplicate companies from the list.',
211
+ scope: { domain: 'sales' },
212
+ resourceId: 'lgn-company-cleanup-workflow',
213
+ invocations: [{ kind: 'api-endpoint', method: 'POST', path: '/api/prospecting/companies/cleanup' }]
214
+ }
215
+ ]
216
+
217
+ export const LEAD_GEN_ACTION_ENTRIES: Record<string, z.infer<typeof ActionSchema>> = Object.fromEntries(
218
+ LEAD_GEN_ACTION_ENTRY_INPUTS.map((action) => {
219
+ const parsed = ActionSchema.parse(action)
220
+ return [parsed.id, parsed]
221
+ })
222
+ )
223
+
224
+ export const DEFAULT_ORGANIZATION_MODEL_ACTIONS: z.infer<typeof ActionsDomainSchema> = LEAD_GEN_ACTION_ENTRIES
225
+
226
+ export function findOrganizationActionById(
227
+ id: string,
228
+ actions: z.infer<typeof ActionsDomainSchema> = DEFAULT_ORGANIZATION_MODEL_ACTIONS
229
+ ): z.infer<typeof ActionSchema> | undefined {
230
+ return actions[id]
231
+ }
232
+
233
+ export type ActionId = z.infer<typeof ActionIdSchema>
234
+ export type ActionScope = z.infer<typeof ActionScopeSchema>
235
+ export type ActionRef = z.infer<typeof ActionRefSchema>
236
+ export type ActionInvocationKind = z.infer<typeof ActionInvocationKindSchema>
237
+ export type ActionInvocation = z.infer<typeof ActionInvocationSchema>
238
+ export type Action = z.infer<typeof ActionSchema>
239
+ export type ActionsDomain = z.infer<typeof ActionsDomainSchema>
@@ -1,75 +1,78 @@
1
- import { z } from 'zod'
2
-
3
- // ---------------------------------------------------------------------------
4
- // Firmographics — optional demographic/firmographic filters that describe the
5
- // target customer segment's organizational profile. All fields are optional so
6
- // a segment can declare only the axes relevant to targeting.
7
- // ---------------------------------------------------------------------------
8
-
9
- export const FirmographicsSchema = z.object({
10
- /** Industry vertical (e.g. "Marketing Agency", "Legal", "Real Estate"). */
11
- industry: z.string().trim().max(200).optional(),
12
- /**
13
- * Company headcount band (e.g. "1–10", "11–50", "51–200", "200+").
14
- * Free-form string to accommodate any band notation.
15
- */
16
- companySize: z.string().trim().max(100).optional(),
17
- /**
18
- * Primary geographic region the segment operates in or is targeted from
19
- * (e.g. "North America", "Europe", "Global").
20
- */
21
- region: z.string().trim().max(200).optional()
22
- })
23
-
24
- // ---------------------------------------------------------------------------
25
- // Customer segment schema — one entry per distinct buyer archetype.
26
- // Modeled after Value Proposition Canvas (BMC / VPC) and Business Model Canvas
27
- // customer-segment language. Fields use plain English throughout.
28
- // ---------------------------------------------------------------------------
29
-
30
- export const CustomerSegmentSchema = z.object({
31
- /** Stable unique identifier for the segment (e.g. "segment-smb-agencies"). */
32
- id: z.string().trim().min(1).max(100),
33
- /** Human-readable name shown to agents and in UI (e.g. "SMB Marketing Agencies"). */
34
- name: z.string().trim().max(200).default(''),
35
- /** One or two sentences describing who this segment is. */
36
- description: z.string().trim().max(2000).default(''),
37
- /**
38
- * The primary job(s) this segment is trying to get done — the goal they hire
39
- * a product/service to accomplish. Plain-language narrative or bullet list.
40
- */
41
- jobsToBeDone: z.string().trim().max(2000).default(''),
42
- /**
43
- * Pains — frustrations, obstacles, and risks the segment experiences
44
- * when trying to accomplish their jobs-to-be-done.
45
- */
46
- pains: z.array(z.string().trim().max(500)).default([]),
47
- /**
48
- * Gains — outcomes and benefits the segment desires; positive motivators
49
- * beyond merely resolving pains.
50
- */
51
- gains: z.array(z.string().trim().max(500)).default([]),
52
- /** Firmographic profile for targeting and filtering. */
53
- firmographics: FirmographicsSchema.default({}),
54
- /**
55
- * Value proposition — one or two sentences stating why this organization's
56
- * offering is uniquely suited for this segment's needs.
57
- */
58
- valueProp: z.string().trim().max(2000).default('')
59
- })
60
-
61
- // ---------------------------------------------------------------------------
62
- // Customers domain schema — a collection of customer segments.
63
- // ---------------------------------------------------------------------------
64
-
65
- export const CustomersDomainSchema = z.object({
66
- segments: z.array(CustomerSegmentSchema).default([])
67
- })
68
-
69
- // ---------------------------------------------------------------------------
70
- // Seed empty by default; adapters populate with real segment definitions.
71
- // ---------------------------------------------------------------------------
72
-
73
- export const DEFAULT_ORGANIZATION_MODEL_CUSTOMERS: z.infer<typeof CustomersDomainSchema> = {
74
- segments: []
75
- }
1
+ import { z } from 'zod'
2
+
3
+ // ---------------------------------------------------------------------------
4
+ // Firmographics — optional demographic/firmographic filters that describe the
5
+ // target customer segment's organizational profile. All fields are optional so
6
+ // a segment can declare only the axes relevant to targeting.
7
+ // ---------------------------------------------------------------------------
8
+
9
+ export const FirmographicsSchema = z.object({
10
+ /** Industry vertical (e.g. "Marketing Agency", "Legal", "Real Estate"). */
11
+ industry: z.string().trim().max(200).optional(),
12
+ /**
13
+ * Company headcount band (e.g. "1–10", "11–50", "51–200", "200+").
14
+ * Free-form string to accommodate any band notation.
15
+ */
16
+ companySize: z.string().trim().max(100).optional(),
17
+ /**
18
+ * Primary geographic region the segment operates in or is targeted from
19
+ * (e.g. "North America", "Europe", "Global").
20
+ */
21
+ region: z.string().trim().max(200).optional()
22
+ })
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // Customer segment schema — one entry per distinct buyer archetype.
26
+ // Modeled after Value Proposition Canvas (BMC / VPC) and Business Model Canvas
27
+ // customer-segment language. Fields use plain English throughout.
28
+ // ---------------------------------------------------------------------------
29
+
30
+ export const CustomerSegmentSchema = z.object({
31
+ /** Stable unique identifier for the segment (e.g. "segment-smb-agencies"). */
32
+ id: z.string().trim().min(1).max(100),
33
+ /** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
34
+ order: z.number(),
35
+ /** Human-readable name shown to agents and in UI (e.g. "SMB Marketing Agencies"). */
36
+ name: z.string().trim().max(200).default(''),
37
+ /** One or two sentences describing who this segment is. */
38
+ description: z.string().trim().max(2000).default(''),
39
+ /**
40
+ * The primary job(s) this segment is trying to get done — the goal they hire
41
+ * a product/service to accomplish. Plain-language narrative or bullet list.
42
+ */
43
+ jobsToBeDone: z.string().trim().max(2000).default(''),
44
+ /**
45
+ * Pains — frustrations, obstacles, and risks the segment experiences
46
+ * when trying to accomplish their jobs-to-be-done.
47
+ */
48
+ pains: z.array(z.string().trim().max(500)).default([]),
49
+ /**
50
+ * Gains — outcomes and benefits the segment desires; positive motivators
51
+ * beyond merely resolving pains.
52
+ */
53
+ gains: z.array(z.string().trim().max(500)).default([]),
54
+ /** Firmographic profile for targeting and filtering. */
55
+ firmographics: FirmographicsSchema.default({}),
56
+ /**
57
+ * Value proposition — one or two sentences stating why this organization's
58
+ * offering is uniquely suited for this segment's needs.
59
+ */
60
+ valueProp: z.string().trim().max(2000).default('')
61
+ })
62
+
63
+ // ---------------------------------------------------------------------------
64
+ // Customers domain schema — id-keyed map of customer segments.
65
+ // ---------------------------------------------------------------------------
66
+
67
+ export const CustomersDomainSchema = z
68
+ .record(z.string(), CustomerSegmentSchema)
69
+ .refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
70
+ message: 'Each segment entry id must match its map key'
71
+ })
72
+ .default({})
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Seed — empty by default; adapters populate with real segment definitions.
76
+ // ---------------------------------------------------------------------------
77
+
78
+ export const DEFAULT_ORGANIZATION_MODEL_CUSTOMERS: z.infer<typeof CustomersDomainSchema> = {}
@@ -0,0 +1,144 @@
1
+ import { z } from 'zod'
2
+ import { DescriptionSchema, LabelSchema, ModelIdSchema } from './shared'
3
+
4
+ export const EntityIdSchema = ModelIdSchema
5
+
6
+ export const EntityLinkKindSchema = z
7
+ .enum(['belongs-to', 'has-many', 'has-one', 'many-to-many'])
8
+ .meta({ label: 'Link kind' })
9
+
10
+ export const EntityLinkSchema = z.object({
11
+ toEntity: EntityIdSchema.meta({ ref: 'entity' }),
12
+ kind: EntityLinkKindSchema,
13
+ via: z.string().trim().min(1).max(255).optional(),
14
+ label: LabelSchema.optional()
15
+ })
16
+
17
+ export const EntitySchema = z.object({
18
+ id: EntityIdSchema,
19
+ /** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
20
+ order: z.number(),
21
+ label: LabelSchema,
22
+ description: DescriptionSchema.optional(),
23
+ ownedBySystemId: ModelIdSchema.meta({ ref: 'system' }),
24
+ table: z.string().trim().min(1).max(255).optional(),
25
+ rowSchema: ModelIdSchema.optional(),
26
+ stateCatalogId: ModelIdSchema.optional(),
27
+ links: z.array(EntityLinkSchema).optional()
28
+ })
29
+
30
+ export const EntitiesDomainSchema = z
31
+ .record(z.string(), EntitySchema)
32
+ .refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
33
+ message: 'Each entity entry id must match its map key'
34
+ })
35
+ .default({})
36
+
37
+ const ENTITY_ENTRY_INPUTS: z.input<typeof EntitySchema>[] = [
38
+ {
39
+ id: 'crm.deal',
40
+ order: 10,
41
+ label: 'Deal',
42
+ description: 'A CRM opportunity or sales pipeline record.',
43
+ ownedBySystemId: 'sales.crm',
44
+ table: 'crm_deals',
45
+ stateCatalogId: 'crm.pipeline',
46
+ links: [{ toEntity: 'crm.contact', kind: 'has-many', via: 'deal_contacts', label: 'contacts' }]
47
+ },
48
+ {
49
+ id: 'crm.contact',
50
+ order: 20,
51
+ label: 'CRM Contact',
52
+ description: 'A person associated with a CRM relationship or deal.',
53
+ ownedBySystemId: 'sales.crm',
54
+ table: 'crm_contacts'
55
+ },
56
+ {
57
+ id: 'leadgen.list',
58
+ order: 30,
59
+ label: 'Lead List',
60
+ description: 'A prospecting list that groups companies and contacts for acquisition workflows.',
61
+ ownedBySystemId: 'sales.lead-gen',
62
+ table: 'acq_lists',
63
+ links: [
64
+ { toEntity: 'leadgen.company', kind: 'has-many', via: 'acq_list_companies', label: 'companies' },
65
+ { toEntity: 'leadgen.contact', kind: 'has-many', via: 'acq_list_members', label: 'contacts' }
66
+ ]
67
+ },
68
+ {
69
+ id: 'leadgen.company',
70
+ order: 40,
71
+ label: 'Lead Company',
72
+ description: 'A company record sourced, enriched, and qualified during prospecting.',
73
+ ownedBySystemId: 'sales.lead-gen',
74
+ table: 'acq_list_companies',
75
+ stateCatalogId: 'lead-gen.company',
76
+ links: [
77
+ { toEntity: 'leadgen.list', kind: 'belongs-to', via: 'list_id', label: 'list' },
78
+ { toEntity: 'leadgen.contact', kind: 'has-many', via: 'company_id', label: 'contacts' }
79
+ ]
80
+ },
81
+ {
82
+ id: 'leadgen.contact',
83
+ order: 50,
84
+ label: 'Lead Contact',
85
+ description: 'A prospect contact discovered or enriched during lead generation.',
86
+ ownedBySystemId: 'sales.lead-gen',
87
+ table: 'acq_list_members',
88
+ stateCatalogId: 'lead-gen.contact',
89
+ links: [
90
+ { toEntity: 'leadgen.list', kind: 'belongs-to', via: 'list_id', label: 'list' },
91
+ { toEntity: 'leadgen.company', kind: 'belongs-to', via: 'company_id', label: 'company' }
92
+ ]
93
+ },
94
+ {
95
+ id: 'delivery.project',
96
+ order: 60,
97
+ label: 'Project',
98
+ description: 'A client delivery project.',
99
+ ownedBySystemId: 'projects',
100
+ table: 'projects',
101
+ links: [
102
+ { toEntity: 'delivery.milestone', kind: 'has-many', via: 'project_id', label: 'milestones' },
103
+ { toEntity: 'delivery.task', kind: 'has-many', via: 'project_id', label: 'tasks' }
104
+ ]
105
+ },
106
+ {
107
+ id: 'delivery.milestone',
108
+ order: 70,
109
+ label: 'Milestone',
110
+ description: 'A delivery checkpoint within a project.',
111
+ ownedBySystemId: 'projects',
112
+ table: 'project_milestones',
113
+ links: [
114
+ { toEntity: 'delivery.project', kind: 'belongs-to', via: 'project_id', label: 'project' },
115
+ { toEntity: 'delivery.task', kind: 'has-many', via: 'milestone_id', label: 'tasks' }
116
+ ]
117
+ },
118
+ {
119
+ id: 'delivery.task',
120
+ order: 80,
121
+ label: 'Task',
122
+ description: 'A delivery task that can move through the task status catalog.',
123
+ ownedBySystemId: 'projects',
124
+ table: 'project_tasks',
125
+ stateCatalogId: 'delivery.task',
126
+ links: [
127
+ { toEntity: 'delivery.project', kind: 'belongs-to', via: 'project_id', label: 'project' },
128
+ { toEntity: 'delivery.milestone', kind: 'belongs-to', via: 'milestone_id', label: 'milestone' }
129
+ ]
130
+ }
131
+ ]
132
+
133
+ export const DEFAULT_ORGANIZATION_MODEL_ENTITIES: z.infer<typeof EntitiesDomainSchema> = Object.fromEntries(
134
+ ENTITY_ENTRY_INPUTS.map((entity) => {
135
+ const parsed = EntitySchema.parse(entity)
136
+ return [parsed.id, parsed]
137
+ })
138
+ )
139
+
140
+ export type EntityId = z.infer<typeof EntityIdSchema>
141
+ export type EntityLinkKind = z.infer<typeof EntityLinkKindSchema>
142
+ export type EntityLink = z.infer<typeof EntityLinkSchema>
143
+ export type Entity = z.infer<typeof EntitySchema>
144
+ export type EntitiesDomain = z.infer<typeof EntitiesDomainSchema>