@elevasis/core 0.26.0 → 0.27.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 (34) hide show
  1. package/dist/index.d.ts +5 -5
  2. package/dist/index.js +209 -173
  3. package/dist/knowledge/index.d.ts +21 -21
  4. package/dist/organization-model/index.d.ts +5 -5
  5. package/dist/organization-model/index.js +209 -173
  6. package/dist/test-utils/index.d.ts +2 -2
  7. package/dist/test-utils/index.js +182 -126
  8. package/package.json +1 -1
  9. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +976 -1063
  10. package/src/business/acquisition/api-schemas.test.ts +1962 -1841
  11. package/src/business/acquisition/api-schemas.ts +1461 -1464
  12. package/src/business/acquisition/crm-next-action.test.ts +45 -25
  13. package/src/business/acquisition/crm-next-action.ts +227 -220
  14. package/src/business/acquisition/crm-priority.test.ts +41 -8
  15. package/src/business/acquisition/crm-priority.ts +365 -349
  16. package/src/business/acquisition/crm-state-actions.test.ts +208 -153
  17. package/src/business/acquisition/derive-actions.test.ts +90 -13
  18. package/src/business/acquisition/derive-actions.ts +8 -139
  19. package/src/business/acquisition/ontology-validation.ts +72 -158
  20. package/src/business/pdf/sections/investment.ts +1 -1
  21. package/src/business/pdf/sections/summary-investment.ts +1 -1
  22. package/src/execution/engine/tools/tool-maps.ts +872 -831
  23. package/src/organization-model/__tests__/cross-ref.test.ts +167 -0
  24. package/src/organization-model/__tests__/published-zero-leak.test.ts +60 -1
  25. package/src/organization-model/__tests__/resolve.test.ts +1 -1
  26. package/src/organization-model/__tests__/schema-refinements.test.ts +72 -0
  27. package/src/organization-model/cross-ref.ts +175 -0
  28. package/src/organization-model/domains/branding.ts +6 -6
  29. package/src/organization-model/domains/sales.test.ts +104 -218
  30. package/src/organization-model/domains/sales.ts +212 -375
  31. package/src/organization-model/index.ts +1 -0
  32. package/src/organization-model/schema-refinements.ts +667 -0
  33. package/src/organization-model/schema.ts +8 -715
  34. package/src/reference/_generated/contracts.md +976 -1063
@@ -1,218 +1,104 @@
1
- import { describe, it, expect } from 'vitest'
2
- import {
3
- CRM_PIPELINE_DEFINITION,
4
- CRM_DISCOVERY_REPLIED_STATE,
5
- CRM_DISCOVERY_LINK_SENT_STATE,
6
- CRM_DISCOVERY_NUDGING_STATE,
7
- CRM_DISCOVERY_BOOKING_CANCELLED_STATE,
8
- CRM_REPLY_SENT_STATE,
9
- CRM_FOLLOWUP_1_SENT_STATE,
10
- CRM_FOLLOWUP_2_SENT_STATE,
11
- CRM_FOLLOWUP_3_SENT_STATE,
12
- CRM_PRIORITY_BUCKETS,
13
- DEFAULT_CRM_PRIORITY_RULE_CONFIG,
14
- getValidStatesForStage,
15
- findPipeline,
16
- ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE,
17
- ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE,
18
- LEAD_GEN_PIPELINE_DEFINITIONS
19
- } from './sales'
20
-
21
- describe('CRM_PIPELINE_DEFINITION', () => {
22
- it('has pipelineKey "crm"', () => {
23
- expect(CRM_PIPELINE_DEFINITION.pipelineKey).toBe('crm')
24
- })
25
-
26
- it('has entityKey "crm.deal"', () => {
27
- expect(CRM_PIPELINE_DEFINITION.entityKey).toBe('crm.deal')
28
- })
29
-
30
- it('has exactly 6 stages', () => {
31
- expect(CRM_PIPELINE_DEFINITION.stages).toHaveLength(6)
32
- })
33
-
34
- it('stage keys are interested, proposal, closing, closed_won, closed_lost, nurturing in order', () => {
35
- const keys = CRM_PIPELINE_DEFINITION.stages.map((s) => s.stageKey)
36
- expect(keys).toEqual(['interested', 'proposal', 'closing', 'closed_won', 'closed_lost', 'nurturing'])
37
- })
38
-
39
- it('interested stage has exactly 8 states', () => {
40
- const interested = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'interested')
41
- expect(interested?.states).toHaveLength(8)
42
- })
43
-
44
- it('interested stage contains all 8 expected state constants', () => {
45
- const interested = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'interested')!
46
- const stateKeys = interested.states.map((s) => s.stateKey)
47
- expect(stateKeys).toContain(CRM_DISCOVERY_REPLIED_STATE.stateKey)
48
- expect(stateKeys).toContain(CRM_DISCOVERY_LINK_SENT_STATE.stateKey)
49
- expect(stateKeys).toContain(CRM_DISCOVERY_NUDGING_STATE.stateKey)
50
- expect(stateKeys).toContain(CRM_DISCOVERY_BOOKING_CANCELLED_STATE.stateKey)
51
- expect(stateKeys).toContain(CRM_REPLY_SENT_STATE.stateKey)
52
- expect(stateKeys).toContain(CRM_FOLLOWUP_1_SENT_STATE.stateKey)
53
- expect(stateKeys).toContain(CRM_FOLLOWUP_2_SENT_STATE.stateKey)
54
- expect(stateKeys).toContain(CRM_FOLLOWUP_3_SENT_STATE.stateKey)
55
- })
56
-
57
- it('interested stage states reference the exported constants by identity', () => {
58
- const interested = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'interested')!
59
- expect(interested.states).toContain(CRM_DISCOVERY_REPLIED_STATE)
60
- expect(interested.states).toContain(CRM_FOLLOWUP_3_SENT_STATE)
61
- })
62
-
63
- it.each(['proposal', 'closing', 'closed_won', 'closed_lost', 'nurturing'])(
64
- '%s stage has an empty states array',
65
- (stageKey) => {
66
- const stage = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === stageKey)
67
- expect(stage).toBeDefined()
68
- expect(stage?.states).toHaveLength(0)
69
- }
70
- )
71
-
72
- it('closed_won stage has empty states array', () => {
73
- const stage = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'closed_won')
74
- expect(stage?.states).toEqual([])
75
- })
76
-
77
- it('closed_lost stage has empty states array', () => {
78
- const stage = CRM_PIPELINE_DEFINITION.stages.find((s) => s.stageKey === 'closed_lost')
79
- expect(stage?.states).toEqual([])
80
- })
81
- })
82
-
83
- describe('CRM state constant shapes', () => {
84
- it('CRM_DISCOVERY_REPLIED_STATE has correct stateKey and label', () => {
85
- expect(CRM_DISCOVERY_REPLIED_STATE).toEqual({ stateKey: 'discovery_replied', label: 'Discovery Replied' })
86
- })
87
-
88
- it('CRM_FOLLOWUP_1_SENT_STATE has correct stateKey and label', () => {
89
- expect(CRM_FOLLOWUP_1_SENT_STATE).toEqual({ stateKey: 'followup_1_sent', label: 'Follow-up 1 Sent' })
90
- })
91
-
92
- it('CRM_FOLLOWUP_2_SENT_STATE has correct stateKey and label', () => {
93
- expect(CRM_FOLLOWUP_2_SENT_STATE).toEqual({ stateKey: 'followup_2_sent', label: 'Follow-up 2 Sent' })
94
- })
95
-
96
- it('CRM_FOLLOWUP_3_SENT_STATE has correct stateKey and label', () => {
97
- expect(CRM_FOLLOWUP_3_SENT_STATE).toEqual({ stateKey: 'followup_3_sent', label: 'Follow-up 3 Sent' })
98
- })
99
- })
100
-
101
- describe('DEFAULT_CRM_PRIORITY_RULE_CONFIG', () => {
102
- it('defines the canonical CRM priority buckets in sort order', () => {
103
- expect(CRM_PRIORITY_BUCKETS.map((bucket) => bucket.bucketKey)).toEqual([
104
- 'needs_response',
105
- 'follow_up_due',
106
- 'waiting',
107
- 'stale',
108
- 'closed_low'
109
- ])
110
- expect(CRM_PRIORITY_BUCKETS.map((bucket) => bucket.rank)).toEqual([10, 20, 30, 40, 50])
111
- })
112
-
113
- it('includes display metadata for each bucket', () => {
114
- for (const bucket of CRM_PRIORITY_BUCKETS) {
115
- expect(bucket.label).toEqual(expect.any(String))
116
- expect(bucket.rank).toEqual(expect.any(Number))
117
- expect(bucket.color).toEqual(expect.any(String))
118
- }
119
- })
120
-
121
- it('maps CRM states and closed stages into priority rules', () => {
122
- expect(DEFAULT_CRM_PRIORITY_RULE_CONFIG.closedStageKeys).toEqual(['closed_won', 'closed_lost'])
123
- expect(DEFAULT_CRM_PRIORITY_RULE_CONFIG.followUpAfterDaysByStateKey.discovery_link_sent).toBe(3)
124
- expect(DEFAULT_CRM_PRIORITY_RULE_CONFIG.staleAfterDays).toBeGreaterThan(0)
125
- })
126
- })
127
-
128
- describe('getValidStatesForStage', () => {
129
- it('returns all 8 states for the interested stage', () => {
130
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'interested')
131
- expect(states).toHaveLength(8)
132
- expect(states.map((s) => s.stateKey)).toContain('discovery_replied')
133
- expect(states.map((s) => s.stateKey)).toContain('followup_3_sent')
134
- })
135
-
136
- it('returns empty array for the proposal stage (no states defined)', () => {
137
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'proposal')
138
- expect(states).toEqual([])
139
- })
140
-
141
- it('returns empty array for the closing stage (no states defined)', () => {
142
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'closing')
143
- expect(states).toEqual([])
144
- })
145
-
146
- it('returns empty array for closed_won stage', () => {
147
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'closed_won')
148
- expect(states).toEqual([])
149
- })
150
-
151
- it('returns empty array for closed_lost stage', () => {
152
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'closed_lost')
153
- expect(states).toEqual([])
154
- })
155
-
156
- it('returns empty array for nurturing stage (no states defined)', () => {
157
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'nurturing')
158
- expect(states).toEqual([])
159
- })
160
-
161
- it('returns empty array for an unknown stage key', () => {
162
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'unknown_stage')
163
- expect(states).toEqual([])
164
- })
165
-
166
- it('returns empty array for an empty string stage key', () => {
167
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, '')
168
- expect(states).toEqual([])
169
- })
170
-
171
- it('is case-sensitive — "Interested" does not match "interested"', () => {
172
- const states = getValidStatesForStage(CRM_PIPELINE_DEFINITION, 'Interested')
173
- expect(states).toEqual([])
174
- })
175
-
176
- it('works with the lead-gen member pipeline for known stage', () => {
177
- const states = getValidStatesForStage(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE, 'outreach')
178
- expect(states.length).toBeGreaterThan(0)
179
- expect(states.map((s) => s.stateKey)).toContain('personalized')
180
- })
181
-
182
- it('works with the lead-gen member pipeline for unknown stage', () => {
183
- const states = getValidStatesForStage(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE, 'nonexistent')
184
- expect(states).toEqual([])
185
- })
186
- })
187
-
188
- describe('findPipeline', () => {
189
- it('finds a pipeline by pipelineKey when present', () => {
190
- const found = findPipeline(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member'], 'lead-gen')
191
- expect(found).toBe(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE)
192
- })
193
-
194
- it('returns undefined for an unknown pipelineKey', () => {
195
- const found = findPipeline(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member'], 'crm')
196
- expect(found).toBeUndefined()
197
- })
198
-
199
- it('returns undefined for an empty array', () => {
200
- const found = findPipeline([], 'lead-gen')
201
- expect(found).toBeUndefined()
202
- })
203
- })
204
-
205
- describe('LEAD_GEN_PIPELINE_DEFINITIONS', () => {
206
- it('has entries for acq.list-member and acq.list-company', () => {
207
- expect(LEAD_GEN_PIPELINE_DEFINITIONS).toHaveProperty('acq.list-member')
208
- expect(LEAD_GEN_PIPELINE_DEFINITIONS).toHaveProperty('acq.list-company')
209
- })
210
-
211
- it('acq.list-member entry contains the ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE', () => {
212
- expect(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member']).toContain(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE)
213
- })
214
-
215
- it('acq.list-company entry contains the ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE', () => {
216
- expect(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-company']).toContain(ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE)
217
- })
218
- })
1
+ import { describe, expect, it } from 'vitest'
2
+ import {
3
+ ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE,
4
+ ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE,
5
+ LEAD_GEN_PIPELINE_DEFINITIONS,
6
+ findPipeline,
7
+ getValidStatesForStage,
8
+ type StatefulPipelineDefinition
9
+ } from './sales'
10
+
11
+ const TEST_CRM_PIPELINE: StatefulPipelineDefinition = {
12
+ pipelineKey: 'crm',
13
+ label: 'CRM',
14
+ entityKey: 'crm.deal',
15
+ stages: [
16
+ {
17
+ stageKey: 'interested',
18
+ label: 'Interested',
19
+ color: 'blue',
20
+ states: [
21
+ { stateKey: 'discovery_replied', label: 'Discovery Replied' },
22
+ { stateKey: 'discovery_link_sent', label: 'Discovery Link Sent' }
23
+ ]
24
+ },
25
+ { stageKey: 'proposal', label: 'Proposal', color: 'yellow', states: [] }
26
+ ]
27
+ }
28
+
29
+ describe('sales domain published surface', () => {
30
+ it('does not export Elevasis CRM runtime constants from the generic core sales domain', async () => {
31
+ const sales = await import('./sales')
32
+
33
+ expect(Object.keys(sales)).not.toEqual(
34
+ expect.arrayContaining([
35
+ 'CRM_PIPELINE_DEFINITION',
36
+ 'CRM_DISCOVERY_REPLIED_STATE',
37
+ 'CRM_PRIORITY_BUCKETS',
38
+ 'DEFAULT_CRM_PRIORITY_RULE_CONFIG',
39
+ 'DEFAULT_CRM_NEXT_ACTION_RULE_CONFIG'
40
+ ])
41
+ )
42
+ })
43
+ })
44
+
45
+ describe('getValidStatesForStage', () => {
46
+ it('returns states for a known stage from a caller-supplied pipeline definition', () => {
47
+ const states = getValidStatesForStage(TEST_CRM_PIPELINE, 'interested')
48
+
49
+ expect(states).toEqual([
50
+ { stateKey: 'discovery_replied', label: 'Discovery Replied' },
51
+ { stateKey: 'discovery_link_sent', label: 'Discovery Link Sent' }
52
+ ])
53
+ })
54
+
55
+ it('returns empty array for a stage with no states', () => {
56
+ expect(getValidStatesForStage(TEST_CRM_PIPELINE, 'proposal')).toEqual([])
57
+ })
58
+
59
+ it('returns empty array for an unknown stage key', () => {
60
+ expect(getValidStatesForStage(TEST_CRM_PIPELINE, 'unknown_stage')).toEqual([])
61
+ })
62
+
63
+ it('is case-sensitive', () => {
64
+ expect(getValidStatesForStage(TEST_CRM_PIPELINE, 'Interested')).toEqual([])
65
+ })
66
+
67
+ it('works with the lead-gen member pipeline for known stage', () => {
68
+ const states = getValidStatesForStage(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE, 'outreach')
69
+ expect(states.length).toBeGreaterThan(0)
70
+ expect(states.map((s) => s.stateKey)).toContain('personalized')
71
+ })
72
+ })
73
+
74
+ describe('findPipeline', () => {
75
+ it('finds a pipeline by pipelineKey when present', () => {
76
+ const found = findPipeline(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member'], 'lead-gen')
77
+ expect(found).toBe(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE)
78
+ })
79
+
80
+ it('returns undefined for an unknown pipelineKey', () => {
81
+ const found = findPipeline(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member'], 'crm')
82
+ expect(found).toBeUndefined()
83
+ })
84
+
85
+ it('returns undefined for an empty array', () => {
86
+ const found = findPipeline([], 'lead-gen')
87
+ expect(found).toBeUndefined()
88
+ })
89
+ })
90
+
91
+ describe('LEAD_GEN_PIPELINE_DEFINITIONS', () => {
92
+ it('has entries for acq.list-member and acq.list-company', () => {
93
+ expect(LEAD_GEN_PIPELINE_DEFINITIONS).toHaveProperty('acq.list-member')
94
+ expect(LEAD_GEN_PIPELINE_DEFINITIONS).toHaveProperty('acq.list-company')
95
+ })
96
+
97
+ it('acq.list-member entry contains the ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE', () => {
98
+ expect(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-member']).toContain(ACQ_LIST_MEMBERS_LEAD_GEN_PIPELINE)
99
+ })
100
+
101
+ it('acq.list-company entry contains the ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE', () => {
102
+ expect(LEAD_GEN_PIPELINE_DEFINITIONS['acq.list-company']).toContain(ACQ_LIST_COMPANIES_LEAD_GEN_PIPELINE)
103
+ })
104
+ })