@elevasis/core 0.22.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 (112) hide show
  1. package/dist/index.d.ts +2330 -2391
  2. package/dist/index.js +2322 -1147
  3. package/dist/knowledge/index.d.ts +702 -1136
  4. package/dist/knowledge/index.js +9 -9
  5. package/dist/organization-model/index.d.ts +2330 -2391
  6. package/dist/organization-model/index.js +2322 -1147
  7. package/dist/test-utils/index.d.ts +703 -1106
  8. package/dist/test-utils/index.js +1735 -1089
  9. package/package.json +1 -1
  10. package/src/__tests__/template-core-compatibility.test.ts +11 -79
  11. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +360 -98
  12. package/src/business/acquisition/api-schemas.test.ts +2 -2
  13. package/src/business/acquisition/api-schemas.ts +7 -9
  14. package/src/business/acquisition/build-templates.test.ts +4 -4
  15. package/src/business/acquisition/build-templates.ts +72 -30
  16. package/src/business/acquisition/crm-state-actions.test.ts +13 -11
  17. package/src/business/acquisition/types.ts +7 -3
  18. package/src/execution/engine/agent/core/types.ts +1 -1
  19. package/src/execution/engine/workflow/types.ts +2 -2
  20. package/src/knowledge/README.md +8 -7
  21. package/src/knowledge/__tests__/queries.test.ts +74 -73
  22. package/src/knowledge/format.ts +10 -9
  23. package/src/knowledge/index.ts +1 -1
  24. package/src/knowledge/published.ts +1 -1
  25. package/src/knowledge/queries.ts +26 -25
  26. package/src/organization-model/README.md +66 -26
  27. package/src/organization-model/__tests__/content-kinds-registry.test.ts +210 -0
  28. package/src/organization-model/__tests__/defaults.test.ts +72 -98
  29. package/src/organization-model/__tests__/domains/actions.test.ts +56 -0
  30. package/src/organization-model/__tests__/domains/customers.test.ts +299 -295
  31. package/src/organization-model/__tests__/domains/entities.test.ts +56 -0
  32. package/src/organization-model/__tests__/domains/goals.test.ts +493 -479
  33. package/src/organization-model/__tests__/domains/identity.test.ts +280 -279
  34. package/src/organization-model/__tests__/domains/navigation.test.ts +268 -212
  35. package/src/organization-model/__tests__/domains/offerings.test.ts +414 -419
  36. package/src/organization-model/__tests__/domains/policies.test.ts +323 -0
  37. package/src/organization-model/__tests__/domains/resource-mappings.test.ts +271 -271
  38. package/src/organization-model/__tests__/domains/resources.test.ts +159 -37
  39. package/src/organization-model/__tests__/domains/roles.test.ts +147 -86
  40. package/src/organization-model/__tests__/domains/statuses.test.ts +246 -243
  41. package/src/organization-model/__tests__/domains/systems.test.ts +67 -51
  42. package/src/organization-model/__tests__/flatten-additive-merge.test.ts +361 -0
  43. package/src/organization-model/__tests__/foundation.test.ts +74 -102
  44. package/src/organization-model/__tests__/get-resources-for-system.test.ts +144 -0
  45. package/src/organization-model/__tests__/graph.test.ts +899 -71
  46. package/src/organization-model/__tests__/knowledge.test.ts +173 -52
  47. package/src/organization-model/__tests__/lookup-helpers.test.ts +438 -0
  48. package/src/organization-model/__tests__/migration-helpers.test.ts +591 -0
  49. package/src/organization-model/__tests__/prospecting-ssot.test.ts +36 -27
  50. package/src/organization-model/__tests__/recursive-system-schema.test.ts +520 -0
  51. package/src/organization-model/__tests__/resolve.test.ts +174 -23
  52. package/src/organization-model/__tests__/schema.test.ts +291 -114
  53. package/src/organization-model/__tests__/surface-projection.test.ts +207 -97
  54. package/src/organization-model/catalogs/lead-gen.ts +144 -0
  55. package/src/organization-model/content-kinds/config.ts +36 -0
  56. package/src/organization-model/content-kinds/index.ts +74 -0
  57. package/src/organization-model/content-kinds/pipeline.ts +68 -0
  58. package/src/organization-model/content-kinds/registry.ts +44 -0
  59. package/src/organization-model/content-kinds/status.ts +71 -0
  60. package/src/organization-model/content-kinds/template.ts +83 -0
  61. package/src/organization-model/content-kinds/types.ts +117 -0
  62. package/src/organization-model/contracts.ts +13 -3
  63. package/src/organization-model/defaults.ts +488 -96
  64. package/src/organization-model/domains/actions.ts +239 -0
  65. package/src/organization-model/domains/customers.ts +78 -75
  66. package/src/organization-model/domains/entities.ts +144 -0
  67. package/src/organization-model/domains/goals.ts +83 -80
  68. package/src/organization-model/domains/knowledge.ts +74 -16
  69. package/src/organization-model/domains/navigation.ts +107 -384
  70. package/src/organization-model/domains/offerings.ts +71 -66
  71. package/src/organization-model/domains/policies.ts +102 -0
  72. package/src/organization-model/domains/projects.ts +14 -48
  73. package/src/organization-model/domains/prospecting.ts +62 -181
  74. package/src/organization-model/domains/resources.ts +81 -24
  75. package/src/organization-model/domains/roles.ts +13 -10
  76. package/src/organization-model/domains/sales.ts +10 -219
  77. package/src/organization-model/domains/shared.ts +57 -57
  78. package/src/organization-model/domains/statuses.ts +339 -130
  79. package/src/organization-model/domains/systems.ts +186 -29
  80. package/src/organization-model/foundation.ts +54 -67
  81. package/src/organization-model/graph/build.ts +682 -54
  82. package/src/organization-model/graph/link.ts +1 -1
  83. package/src/organization-model/graph/schema.ts +24 -9
  84. package/src/organization-model/graph/types.ts +20 -7
  85. package/src/organization-model/helpers.ts +231 -26
  86. package/src/organization-model/index.ts +116 -5
  87. package/src/organization-model/migration-helpers.ts +249 -0
  88. package/src/organization-model/organization-graph.mdx +16 -15
  89. package/src/organization-model/organization-model.mdx +89 -41
  90. package/src/organization-model/published.ts +120 -18
  91. package/src/organization-model/resolve.ts +117 -54
  92. package/src/organization-model/schema.ts +561 -140
  93. package/src/organization-model/surface-projection.ts +116 -122
  94. package/src/organization-model/types.ts +102 -21
  95. package/src/platform/constants/versions.ts +1 -1
  96. package/src/platform/registry/__tests__/command-view.test.ts +6 -8
  97. package/src/platform/registry/__tests__/resource-link.test.ts +13 -8
  98. package/src/platform/registry/__tests__/resource-registry.integration.test.ts +16 -31
  99. package/src/platform/registry/__tests__/resource-registry.nested-systems.test.ts +245 -0
  100. package/src/platform/registry/__tests__/resource-registry.test.ts +9 -7
  101. package/src/platform/registry/__tests__/validation.test.ts +15 -11
  102. package/src/platform/registry/resource-registry.ts +20 -8
  103. package/src/platform/registry/serialization.ts +7 -7
  104. package/src/platform/registry/types.ts +3 -3
  105. package/src/platform/registry/validation.ts +17 -15
  106. package/src/reference/_generated/contracts.md +362 -99
  107. package/src/reference/glossary.md +18 -18
  108. package/src/supabase/database.types.ts +60 -0
  109. package/src/test-utils/test-utils.test.ts +1 -6
  110. package/src/organization-model/__tests__/domains/operations.test.ts +0 -203
  111. package/src/organization-model/domains/features.ts +0 -31
  112. 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>