@elevasis/core 0.27.0 → 0.29.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 (38) hide show
  1. package/dist/index.d.ts +146 -89
  2. package/dist/index.js +116 -46
  3. package/dist/knowledge/index.d.ts +21 -21
  4. package/dist/organization-model/index.d.ts +146 -89
  5. package/dist/organization-model/index.js +116 -46
  6. package/dist/test-utils/index.d.ts +20 -17
  7. package/dist/test-utils/index.js +22 -20
  8. package/package.json +1 -1
  9. package/src/business/acquisition/api-schemas.test.ts +59 -8
  10. package/src/business/acquisition/api-schemas.ts +10 -5
  11. package/src/business/acquisition/build-templates.test.ts +187 -240
  12. package/src/business/acquisition/build-templates.ts +87 -98
  13. package/src/business/acquisition/types.ts +390 -389
  14. package/src/execution/engine/index.ts +6 -4
  15. package/src/execution/engine/tools/lead-service-types.ts +63 -34
  16. package/src/execution/engine/tools/platform/acquisition/types.ts +7 -8
  17. package/src/execution/engine/tools/registry.ts +6 -4
  18. package/src/execution/engine/tools/tool-maps.ts +23 -1
  19. package/src/organization-model/__tests__/define-domain-record.test.ts +289 -0
  20. package/src/organization-model/__tests__/om-spine-doc-contract.test.ts +56 -0
  21. package/src/organization-model/domains/actions.ts +13 -0
  22. package/src/organization-model/domains/customers.ts +95 -78
  23. package/src/organization-model/domains/entities.ts +157 -144
  24. package/src/organization-model/domains/goals.ts +100 -83
  25. package/src/organization-model/domains/knowledge.ts +106 -93
  26. package/src/organization-model/domains/offerings.ts +88 -71
  27. package/src/organization-model/domains/policies.ts +115 -102
  28. package/src/organization-model/domains/prospecting.ts +2 -327
  29. package/src/organization-model/domains/roles.ts +109 -96
  30. package/src/organization-model/domains/statuses.ts +351 -339
  31. package/src/organization-model/domains/systems.ts +176 -164
  32. package/src/organization-model/helpers.ts +331 -306
  33. package/src/organization-model/index.ts +42 -0
  34. package/src/organization-model/migration-helpers.ts +16 -12
  35. package/src/organization-model/published.ts +27 -2
  36. package/src/platform/constants/versions.ts +1 -1
  37. package/src/reference/_generated/contracts.md +376 -352
  38. package/src/supabase/database.types.ts +3 -0
@@ -1,7 +1,6 @@
1
1
  import { z } from 'zod'
2
2
  import { UuidSchema, NonEmptyStringSchema } from '../../platform/utils/validation'
3
3
  import { CredentialRequirementSchema, RecordColumnConfigSchema } from '../../organization-model/domains/prospecting'
4
- import { isProspectingBuildTemplateId } from './build-templates'
5
4
  export { CrmPriorityBucketKeySchema, CrmPriorityBucketOverrideSchema, CrmPriorityOverrideSchema } from './crm-priority'
6
5
  export type { CrmPriorityBucketOverride, CrmPriorityOverride, ResolvedCrmPriorityRuleConfig } from './crm-priority'
7
6
 
@@ -508,12 +507,15 @@ export const PipelineStageSchema = z.object({
508
507
  order: z.number().int().optional()
509
508
  })
510
509
 
510
+ export const DataModeSchema = z.enum(['mock', 'live'])
511
+
511
512
  /**
512
513
  * Pipeline presentation contract stored in `acq_lists.pipeline_config` jsonb.
513
514
  * `stages[].key` validates against the catalog; the rest is presentation only.
514
515
  */
515
516
  export const PipelineConfigSchema = z.object({
516
- stages: z.array(PipelineStageSchema).optional()
517
+ stages: z.array(PipelineStageSchema).optional(),
518
+ dataMode: DataModeSchema.optional()
517
519
  })
518
520
 
519
521
  export const BuildPlanSnapshotStepSchema = z
@@ -584,9 +586,10 @@ export const AcqListMetadataSchema = z
584
586
  })
585
587
  .catchall(z.unknown())
586
588
 
587
- export const ProspectingBuildTemplateIdSchema = z.string().trim().min(1).max(100).refine(isProspectingBuildTemplateId, {
588
- message: 'buildTemplateId must match a known prospecting build template'
589
- })
589
+ // Build-template IDs are tenant-owned OM catalog entries. Published core only
590
+ // validates the transport shape; API/services validate membership against the
591
+ // tenant's resolved Organization Model before creating or changing snapshots.
592
+ export const ProspectingBuildTemplateIdSchema = z.string().trim().min(1).max(100)
590
593
 
591
594
  // ---------------------------------------------------------------------------
592
595
  // List telemetry / progress schemas
@@ -1360,6 +1363,7 @@ export const AcqListSchemas = {
1360
1363
  ScrapingConfig: ScrapingConfigSchema,
1361
1364
  IcpRubric: IcpRubricSchema,
1362
1365
  PipelineConfig: PipelineConfigSchema,
1366
+ DataMode: DataModeSchema,
1363
1367
  PipelineStage: PipelineStageSchema,
1364
1368
  BuildPlanSnapshot: BuildPlanSnapshotSchema,
1365
1369
  BuildPlanSnapshotStep: BuildPlanSnapshotStepSchema,
@@ -1459,6 +1463,7 @@ export type ListStatus = z.infer<typeof ListStatusSchema>
1459
1463
  export type ScrapingConfig = z.infer<typeof ScrapingConfigSchema>
1460
1464
  export type IcpRubric = z.infer<typeof IcpRubricSchema>
1461
1465
  export type PipelineStage = z.infer<typeof PipelineStageSchema>
1466
+ export type DataMode = z.infer<typeof DataModeSchema>
1462
1467
  export type PipelineConfig = z.infer<typeof PipelineConfigSchema>
1463
1468
  export type BuildPlanSnapshotStep = z.infer<typeof BuildPlanSnapshotStepSchema>
1464
1469
  export type BuildPlanSnapshot = z.infer<typeof BuildPlanSnapshotSchema>
@@ -1,240 +1,187 @@
1
- import { describe, expect, it } from 'vitest'
2
- import {
3
- DEFAULT_PROSPECTING_BUILD_TEMPLATE_ID,
4
- PROSPECTING_BUILD_TEMPLATE_OPTIONS,
5
- createBuildPlanSnapshotFromTemplateId,
6
- isProspectingBuildTemplateId
7
- } from './build-templates'
8
-
9
- // ---------------------------------------------------------------------------
10
- // isProspectingBuildTemplateId
11
- // ---------------------------------------------------------------------------
12
-
13
- describe('isProspectingBuildTemplateId', () => {
14
- it('returns true for every id in PROSPECTING_BUILD_TEMPLATE_OPTIONS', () => {
15
- for (const option of PROSPECTING_BUILD_TEMPLATE_OPTIONS) {
16
- expect(isProspectingBuildTemplateId(option.id)).toBe(true)
17
- }
18
- })
19
-
20
- it('returns true for the known "local-services" template id', () => {
21
- expect(isProspectingBuildTemplateId('local-services')).toBe(true)
22
- })
23
-
24
- it('returns true for the known "dtc-subscription-apollo-clickup" template id', () => {
25
- expect(isProspectingBuildTemplateId('dtc-subscription-apollo-clickup')).toBe(true)
26
- })
27
-
28
- it('returns false for an unknown string', () => {
29
- expect(isProspectingBuildTemplateId('not-a-template')).toBe(false)
30
- })
31
-
32
- it('returns false for an empty string', () => {
33
- expect(isProspectingBuildTemplateId('')).toBe(false)
34
- })
35
-
36
- it('returns false for a partial id match', () => {
37
- expect(isProspectingBuildTemplateId('local')).toBe(false)
38
- expect(isProspectingBuildTemplateId('dtc-subscription')).toBe(false)
39
- })
40
-
41
- it('returns false for a whitespace-padded id', () => {
42
- expect(isProspectingBuildTemplateId(' local-services ')).toBe(false)
43
- })
44
-
45
- it('verifies PROSPECTING_BUILD_TEMPLATE_OPTIONS contains at least two entries', () => {
46
- expect(PROSPECTING_BUILD_TEMPLATE_OPTIONS.length).toBeGreaterThanOrEqual(2)
47
- })
48
-
49
- it('verifies DEFAULT_PROSPECTING_BUILD_TEMPLATE_ID is itself a valid template id', () => {
50
- expect(isProspectingBuildTemplateId(DEFAULT_PROSPECTING_BUILD_TEMPLATE_ID)).toBe(true)
51
- })
52
- })
53
-
54
- // ---------------------------------------------------------------------------
55
- // createBuildPlanSnapshotFromTemplateId — unknown id
56
- // ---------------------------------------------------------------------------
57
-
58
- describe('createBuildPlanSnapshotFromTemplateId — unknown id', () => {
59
- it('returns null for an unknown template id', () => {
60
- expect(createBuildPlanSnapshotFromTemplateId('not-a-template')).toBeNull()
61
- })
62
-
63
- it('returns null for an empty string', () => {
64
- expect(createBuildPlanSnapshotFromTemplateId('')).toBeNull()
65
- })
66
- })
67
-
68
- // ---------------------------------------------------------------------------
69
- // createBuildPlanSnapshotFromTemplateId — "local-services"
70
- // ---------------------------------------------------------------------------
71
-
72
- describe('createBuildPlanSnapshotFromTemplateId — "local-services"', () => {
73
- const snapshot = createBuildPlanSnapshotFromTemplateId('local-services')
74
-
75
- it('returns a non-null snapshot', () => {
76
- expect(snapshot).not.toBeNull()
77
- })
78
-
79
- it('preserves the template id in the snapshot', () => {
80
- expect(snapshot?.templateId).toBe('local-services')
81
- })
82
-
83
- it('includes a non-empty templateLabel', () => {
84
- expect(snapshot?.templateLabel).toBeTruthy()
85
- })
86
-
87
- it('produces a steps array with length matching the catalog (7 steps)', () => {
88
- expect(snapshot?.steps).toHaveLength(7)
89
- })
90
-
91
- it('every step has required fields: id, label, primaryEntity, outputs, stageKey, dependencyMode, actionKey', () => {
92
- for (const step of snapshot?.steps ?? []) {
93
- expect(step.id).toBeTruthy()
94
- expect(step.label).toBeTruthy()
95
- expect(['company', 'contact']).toContain(step.primaryEntity)
96
- expect(step.outputs.length).toBeGreaterThanOrEqual(1)
97
- expect(step.stageKey).toBeTruthy()
98
- expect(step.dependencyMode).toBe('per-record-eligibility')
99
- expect(step.actionKey).toBeTruthy()
100
- }
101
- })
102
-
103
- it('every step has positive defaultBatchSize and maxBatchSize', () => {
104
- for (const step of snapshot?.steps ?? []) {
105
- expect(step.defaultBatchSize).toBeGreaterThan(0)
106
- expect(step.maxBatchSize).toBeGreaterThanOrEqual(step.defaultBatchSize)
107
- }
108
- })
109
-
110
- it('steps with declared dependsOn in the catalog have dependsOn in the snapshot', () => {
111
- const withDeps = snapshot?.steps.filter((step) => step.dependsOn !== undefined) ?? []
112
- expect(withDeps.length).toBeGreaterThan(0)
113
- for (const step of withDeps) {
114
- expect(Array.isArray(step.dependsOn)).toBe(true)
115
- expect((step.dependsOn ?? []).length).toBeGreaterThan(0)
116
- }
117
- })
118
-
119
- it('the first step (source-companies) has no dependsOn', () => {
120
- const first = snapshot?.steps[0]
121
- expect(first?.id).toBe('source-companies')
122
- expect(first?.dependsOn).toBeUndefined()
123
- })
124
-
125
- it('outputs arrays are copies (mutation does not affect subsequent calls)', () => {
126
- const snapshotA = createBuildPlanSnapshotFromTemplateId('local-services')
127
- const snapshotB = createBuildPlanSnapshotFromTemplateId('local-services')
128
- snapshotA?.steps[0]?.outputs.push('export' as never)
129
- expect(snapshotB?.steps[0]?.outputs).not.toContain('export')
130
- })
131
- })
132
-
133
- // ---------------------------------------------------------------------------
134
- // createBuildPlanSnapshotFromTemplateId — "dtc-subscription-apollo-clickup"
135
- // ---------------------------------------------------------------------------
136
-
137
- describe('createBuildPlanSnapshotFromTemplateId — "dtc-subscription-apollo-clickup"', () => {
138
- const snapshot = createBuildPlanSnapshotFromTemplateId('dtc-subscription-apollo-clickup')
139
-
140
- it('returns a non-null snapshot', () => {
141
- expect(snapshot).not.toBeNull()
142
- })
143
-
144
- it('preserves the template id in the snapshot', () => {
145
- expect(snapshot?.templateId).toBe('dtc-subscription-apollo-clickup')
146
- })
147
-
148
- it('produces a steps array with length matching the catalog (6 steps)', () => {
149
- expect(snapshot?.steps).toHaveLength(6)
150
- })
151
-
152
- it('every step has required fields: id, label, primaryEntity, outputs, stageKey, dependencyMode, actionKey', () => {
153
- for (const step of snapshot?.steps ?? []) {
154
- expect(step.id).toBeTruthy()
155
- expect(step.label).toBeTruthy()
156
- expect(['company', 'contact']).toContain(step.primaryEntity)
157
- expect(step.outputs.length).toBeGreaterThanOrEqual(1)
158
- expect(step.stageKey).toBeTruthy()
159
- expect(step.dependencyMode).toBe('per-record-eligibility')
160
- expect(step.actionKey).toBeTruthy()
161
- }
162
- })
163
-
164
- it('every step has positive defaultBatchSize and maxBatchSize', () => {
165
- for (const step of snapshot?.steps ?? []) {
166
- expect(step.defaultBatchSize).toBeGreaterThan(0)
167
- expect(step.maxBatchSize).toBeGreaterThanOrEqual(step.defaultBatchSize)
168
- }
169
- })
170
-
171
- it('the first step (import-apollo-search) has no dependsOn', () => {
172
- const first = snapshot?.steps[0]
173
- expect(first?.id).toBe('import-apollo-search')
174
- expect(first?.dependsOn).toBeUndefined()
175
- })
176
-
177
- it('the first step outputs both company and contact', () => {
178
- const first = snapshot?.steps[0]
179
- expect(first?.outputs).toContain('company')
180
- expect(first?.outputs).toContain('contact')
181
- })
182
-
183
- it('preserves Apollo credential requirements for source import and decision-maker enrichment', () => {
184
- const importApolloSearch = snapshot?.steps.find((step) => step.id === 'import-apollo-search')
185
- const enrichDecisionMakers = snapshot?.steps.find((step) => step.id === 'enrich-decision-makers')
186
-
187
- const expectedRequirement = {
188
- key: 'apollo',
189
- provider: 'apollo',
190
- credentialType: 'api-key-secret',
191
- label: 'Apollo API key',
192
- required: true,
193
- selectionMode: 'single',
194
- inputPath: 'credential'
195
- }
196
-
197
- expect(importApolloSearch?.credentialRequirements).toEqual([expectedRequirement])
198
- expect(enrichDecisionMakers?.credentialRequirements).toEqual([expectedRequirement])
199
- })
200
-
201
- it('the final step (review-and-export) outputs export', () => {
202
- const last = snapshot?.steps[snapshot.steps.length - 1]
203
- expect(last?.id).toBe('review-and-export')
204
- expect(last?.outputs).toContain('export')
205
- })
206
-
207
- it('preserves contact records metadata for the company-owned decision-maker step', () => {
208
- const decisionMakers = snapshot?.steps.find((step) => step.id === 'enrich-decision-makers')
209
- expect(decisionMakers).toMatchObject({
210
- primaryEntity: 'company',
211
- recordEntity: 'contact',
212
- stageKey: 'decision-makers-enriched'
213
- })
214
- expect(decisionMakers?.recordColumns?.contact?.length).toBeGreaterThan(0)
215
- })
216
-
217
- it('steps with descriptions in the catalog include description in the snapshot', () => {
218
- const withDesc = snapshot?.steps.filter((step) => step.description !== undefined) ?? []
219
- expect(withDesc.length).toBeGreaterThan(0)
220
- for (const step of withDesc) {
221
- expect(typeof step.description).toBe('string')
222
- expect(step.description!.length).toBeGreaterThan(0)
223
- }
224
- })
225
- })
226
-
227
- // ---------------------------------------------------------------------------
228
- // Snapshot shape contract — applies to every valid template id
229
- // ---------------------------------------------------------------------------
230
-
231
- describe('createBuildPlanSnapshotFromTemplateId — shape contract for all templates', () => {
232
- it('returns a snapshot for every id that isProspectingBuildTemplateId reports valid', () => {
233
- for (const option of PROSPECTING_BUILD_TEMPLATE_OPTIONS) {
234
- const snapshot = createBuildPlanSnapshotFromTemplateId(option.id)
235
- expect(snapshot).not.toBeNull()
236
- expect(snapshot?.templateId).toBe(option.id)
237
- expect(snapshot?.steps.length).toBeGreaterThan(0)
238
- }
239
- })
240
- })
1
+ import { describe, expect, it } from 'vitest'
2
+ import type { ProspectingBuildTemplate } from '../../organization-model/domains/prospecting'
3
+ import {
4
+ createBuildPlanSnapshotFromTemplate,
5
+ createBuildPlanSnapshotFromTemplateId,
6
+ getProspectingBuildTemplateOptions,
7
+ isProspectingBuildTemplateId
8
+ } from './build-templates'
9
+
10
+ const templates: ProspectingBuildTemplate[] = [
11
+ {
12
+ id: 'source-and-qualify',
13
+ label: 'Source and Qualify',
14
+ description: 'Source companies, analyze websites, and qualify fit.',
15
+ steps: [
16
+ {
17
+ id: 'source-companies',
18
+ label: 'Companies found',
19
+ primaryEntity: 'company',
20
+ outputs: ['company'],
21
+ stageKey: 'populated',
22
+ dependencyMode: 'per-record-eligibility',
23
+ actionKey: 'lead-gen.company.source',
24
+ defaultBatchSize: 100,
25
+ maxBatchSize: 250,
26
+ recordColumns: {
27
+ company: [{ key: 'name', label: 'Company', path: 'company.name' }]
28
+ }
29
+ },
30
+ {
31
+ id: 'qualify-companies',
32
+ label: 'Companies qualified',
33
+ description: 'Score companies against the active ICP.',
34
+ primaryEntity: 'company',
35
+ outputs: ['company'],
36
+ stageKey: 'qualified',
37
+ dependsOn: ['source-companies'],
38
+ dependencyMode: 'per-record-eligibility',
39
+ actionKey: 'lead-gen.company.qualify',
40
+ defaultBatchSize: 50,
41
+ maxBatchSize: 100
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ id: 'export-ready',
47
+ label: 'Export Ready',
48
+ steps: [
49
+ {
50
+ id: 'review-and-export',
51
+ label: 'Reviewed and exported',
52
+ primaryEntity: 'company',
53
+ outputs: ['export'],
54
+ stageKey: 'uploaded',
55
+ recordsStageKey: 'uploaded',
56
+ recordSourceStageKey: 'qualified',
57
+ dependencyMode: 'per-record-eligibility',
58
+ actionKey: 'lead-gen.export.list',
59
+ defaultBatchSize: 25,
60
+ maxBatchSize: 100,
61
+ credentialRequirements: [
62
+ {
63
+ key: 'export',
64
+ provider: 'export-provider',
65
+ credentialType: 'api-key-secret',
66
+ label: 'Export API token',
67
+ required: true,
68
+ selectionMode: 'single',
69
+ inputPath: 'credential',
70
+ verifyOnRun: true
71
+ }
72
+ ]
73
+ }
74
+ ]
75
+ }
76
+ ]
77
+
78
+ describe('getProspectingBuildTemplateOptions', () => {
79
+ it('projects option metadata from caller-supplied templates', () => {
80
+ expect(getProspectingBuildTemplateOptions(templates)).toEqual([
81
+ {
82
+ id: 'source-and-qualify',
83
+ label: 'Source and Qualify',
84
+ description: 'Source companies, analyze websites, and qualify fit.'
85
+ },
86
+ {
87
+ id: 'export-ready',
88
+ label: 'Export Ready',
89
+ description: undefined
90
+ }
91
+ ])
92
+ })
93
+ })
94
+
95
+ describe('isProspectingBuildTemplateId', () => {
96
+ it('checks membership against caller-supplied templates', () => {
97
+ expect(isProspectingBuildTemplateId('source-and-qualify', templates)).toBe(true)
98
+ expect(isProspectingBuildTemplateId('not-a-template', templates)).toBe(false)
99
+ })
100
+
101
+ it('has no published default template catalog', () => {
102
+ expect(isProspectingBuildTemplateId('source-and-qualify')).toBe(false)
103
+ })
104
+ })
105
+
106
+ describe('createBuildPlanSnapshotFromTemplate', () => {
107
+ it('creates an immutable build-plan snapshot shape from a supplied template', () => {
108
+ const snapshot = createBuildPlanSnapshotFromTemplate(templates[0]!)
109
+
110
+ expect(snapshot).toMatchObject({
111
+ templateId: 'source-and-qualify',
112
+ templateLabel: 'Source and Qualify',
113
+ steps: [
114
+ {
115
+ id: 'source-companies',
116
+ label: 'Companies found',
117
+ primaryEntity: 'company',
118
+ outputs: ['company'],
119
+ stageKey: 'populated',
120
+ recordsStageKey: 'populated',
121
+ recordSourceStageKey: 'populated',
122
+ dependencyMode: 'per-record-eligibility',
123
+ actionKey: 'lead-gen.company.source',
124
+ defaultBatchSize: 100,
125
+ maxBatchSize: 250,
126
+ recordColumns: {
127
+ company: [{ key: 'name', label: 'Company', path: 'company.name' }]
128
+ }
129
+ },
130
+ {
131
+ id: 'qualify-companies',
132
+ dependsOn: ['source-companies'],
133
+ description: 'Score companies against the active ICP.'
134
+ }
135
+ ]
136
+ })
137
+ })
138
+
139
+ it('copies array/object fields so subsequent snapshots are isolated', () => {
140
+ const snapshotA = createBuildPlanSnapshotFromTemplate(templates[0]!)
141
+ const snapshotB = createBuildPlanSnapshotFromTemplate(templates[0]!)
142
+
143
+ snapshotA.steps[0]?.outputs.push('export')
144
+ snapshotA.steps[0]?.recordColumns?.company?.push({ key: 'domain', label: 'Domain', path: 'company.domain' })
145
+
146
+ expect(snapshotB.steps[0]?.outputs).toEqual(['company'])
147
+ expect(snapshotB.steps[0]?.recordColumns?.company).toEqual([
148
+ { key: 'name', label: 'Company', path: 'company.name' }
149
+ ])
150
+ })
151
+
152
+ it('preserves credential requirements and explicit record stage fields', () => {
153
+ const snapshot = createBuildPlanSnapshotFromTemplate(templates[1]!)
154
+
155
+ expect(snapshot.steps[0]).toMatchObject({
156
+ id: 'review-and-export',
157
+ recordsStageKey: 'uploaded',
158
+ recordSourceStageKey: 'qualified',
159
+ credentialRequirements: [
160
+ {
161
+ key: 'export',
162
+ provider: 'export-provider',
163
+ credentialType: 'api-key-secret',
164
+ label: 'Export API token',
165
+ required: true,
166
+ selectionMode: 'single',
167
+ inputPath: 'credential',
168
+ verifyOnRun: true
169
+ }
170
+ ]
171
+ })
172
+ })
173
+ })
174
+
175
+ describe('createBuildPlanSnapshotFromTemplateId', () => {
176
+ it('creates snapshots from caller-supplied template catalogs', () => {
177
+ const snapshot = createBuildPlanSnapshotFromTemplateId('export-ready', templates)
178
+
179
+ expect(snapshot?.templateId).toBe('export-ready')
180
+ expect(snapshot?.steps).toHaveLength(1)
181
+ })
182
+
183
+ it('returns null for unknown ids or when no template catalog is supplied', () => {
184
+ expect(createBuildPlanSnapshotFromTemplateId('not-a-template', templates)).toBeNull()
185
+ expect(createBuildPlanSnapshotFromTemplateId('source-and-qualify')).toBeNull()
186
+ })
187
+ })