@elevasis/core 0.15.1 → 0.16.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.
- package/dist/index.d.ts +1662 -23
- package/dist/index.js +171 -24
- package/dist/organization-model/index.d.ts +1662 -23
- package/dist/organization-model/index.js +171 -24
- package/dist/test-utils/index.d.ts +711 -10
- package/dist/test-utils/index.js +159 -16
- package/package.json +7 -3
- package/src/__tests__/publish.test.ts +14 -13
- package/src/__tests__/template-core-compatibility.test.ts +4 -4
- package/src/_gen/__tests__/__snapshots__/contracts.md.snap +305 -201
- package/src/auth/multi-tenancy/index.ts +3 -0
- package/src/auth/multi-tenancy/theme-presets.ts +45 -0
- package/src/auth/multi-tenancy/types.ts +57 -83
- package/src/auth/multi-tenancy/users/api-schemas.ts +165 -194
- package/src/business/acquisition/activity-events.ts +1 -1
- package/src/business/acquisition/api-schemas.ts +1196 -1177
- package/src/business/acquisition/crm-state-actions.test.ts +139 -139
- package/src/business/acquisition/types.ts +381 -390
- package/src/business/crm/api-schemas.ts +40 -0
- package/src/business/crm/index.ts +1 -0
- package/src/business/deals/api-schemas.ts +79 -0
- package/src/business/deals/index.ts +1 -0
- package/src/business/projects/types.ts +124 -88
- package/src/execution/core/runner-types.ts +61 -80
- package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-tools.ts +105 -104
- package/src/execution/engine/tools/integration/server/adapters/instantly/instantly-tools.ts +1474 -1473
- package/src/execution/engine/tools/integration/server/adapters/millionverifier/millionverifier-tools.ts +103 -102
- package/src/execution/engine/tools/integration/server/adapters/signature-api/signature-api-tools.ts +182 -179
- package/src/execution/engine/tools/integration/server/adapters/stripe/stripe-tools.ts +310 -309
- package/src/execution/engine/tools/integration/tool.ts +255 -253
- package/src/execution/engine/tools/lead-service-types.ts +895 -894
- package/src/execution/engine/tools/messages.ts +43 -0
- package/src/execution/engine/tools/platform/acquisition/types.ts +2 -1
- package/src/execution/engine/tools/platform/email/types.ts +97 -96
- package/src/execution/engine/tools/types.ts +234 -233
- package/src/execution/engine/workflow/types.ts +195 -193
- package/src/execution/external/api-schemas.ts +40 -0
- package/src/execution/external/index.ts +1 -0
- package/src/knowledge/README.md +32 -0
- package/src/knowledge/__tests__/queries.test.ts +504 -0
- package/src/knowledge/format.ts +99 -0
- package/src/knowledge/index.ts +5 -0
- package/src/knowledge/queries.ts +256 -0
- package/src/organization-model/__tests__/defaults.test.ts +172 -172
- package/src/organization-model/__tests__/foundation.test.ts +7 -7
- package/src/organization-model/__tests__/icons.test.ts +27 -0
- package/src/organization-model/__tests__/knowledge.test.ts +214 -0
- package/src/organization-model/contracts.ts +17 -15
- package/src/organization-model/defaults.ts +74 -19
- package/src/organization-model/domains/knowledge.ts +53 -0
- package/src/organization-model/domains/navigation.ts +416 -399
- package/src/organization-model/domains/shared.ts +6 -5
- package/src/organization-model/foundation.ts +10 -6
- package/src/organization-model/graph/build.ts +209 -182
- package/src/organization-model/graph/schema.ts +37 -34
- package/src/organization-model/graph/types.ts +47 -31
- package/src/organization-model/icons.ts +81 -0
- package/src/organization-model/index.ts +8 -3
- package/src/organization-model/organization-model.mdx +1 -1
- package/src/organization-model/published.ts +103 -86
- package/src/organization-model/schema.ts +90 -85
- package/src/organization-model/types.ts +40 -33
- package/src/platform/index.ts +23 -27
- package/src/platform/registry/index.ts +0 -4
- package/src/platform/registry/resource-registry.ts +0 -77
- package/src/platform/registry/serialized-types.ts +148 -219
- package/src/platform/registry/stats-types.ts +60 -60
- package/src/reference/_generated/contracts.md +1265 -1154
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { DEFAULT_ORGANIZATION_MODEL_SALES, LEAD_GEN_PIPELINE_DEFINITIONS } from '../../organization-model/domains/sales'
|
|
3
|
-
import { ActivityEventSchema } from './activity-events'
|
|
4
|
-
import { DealStageSchema, TransitionItemRequestSchema } from './api-schemas'
|
|
5
|
-
import { deriveActions } from './derive-actions'
|
|
6
|
-
import type { DealStage } from './types'
|
|
7
|
-
|
|
8
|
-
const DEAL_STAGES = [
|
|
9
|
-
'interested',
|
|
10
|
-
'proposal',
|
|
11
|
-
'closing',
|
|
12
|
-
'closed_won',
|
|
13
|
-
'closed_lost',
|
|
14
|
-
'nurturing'
|
|
15
|
-
] as const satisfies readonly DealStage[]
|
|
16
|
-
|
|
17
|
-
function deal(stageKey: string | null, stateKey: string | null = null): Parameters<typeof deriveActions>[0] {
|
|
18
|
-
return { stage_key: stageKey, state_key: stateKey } as Parameters<typeof deriveActions>[0]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe('CRM deal action derivation', () => {
|
|
22
|
-
it('derives the exact base actions for interested deals', () => {
|
|
23
|
-
expect(deriveActions(deal('interested'))).toEqual([
|
|
24
|
-
{ key: 'move_to_proposal', label: 'Move to Proposal' },
|
|
25
|
-
{ key: 'move_to_closed_lost', label: 'Close Lost' },
|
|
26
|
-
{ key: 'move_to_nurturing', label: 'Move to Nurturing' }
|
|
27
|
-
])
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it.each([
|
|
31
|
-
['discovery_replied', { key: 'send_link', label: 'Send Booking Link' }],
|
|
32
|
-
['discovery_link_sent', { key: 'send_nudge', label: 'Send Nudge' }],
|
|
33
|
-
['discovery_booking_cancelled', { key: 'rebook', label: 'Rebook' }]
|
|
34
|
-
] as const)('adds the expected workflow action for interested/%s', (stateKey, expectedAction) => {
|
|
35
|
-
const expected = [
|
|
36
|
-
{ key: 'move_to_proposal', label: 'Move to Proposal' },
|
|
37
|
-
{ key: 'move_to_closed_lost', label: 'Close Lost' },
|
|
38
|
-
{ key: 'move_to_nurturing', label: 'Move to Nurturing' },
|
|
39
|
-
expectedAction
|
|
40
|
-
]
|
|
41
|
-
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { DEFAULT_ORGANIZATION_MODEL_SALES, LEAD_GEN_PIPELINE_DEFINITIONS } from '../../organization-model/domains/sales'
|
|
3
|
+
import { ActivityEventSchema } from './activity-events'
|
|
4
|
+
import { DealStageSchema, TransitionItemRequestSchema } from './api-schemas'
|
|
5
|
+
import { deriveActions } from './derive-actions'
|
|
6
|
+
import type { DealStage } from './types'
|
|
7
|
+
|
|
8
|
+
const DEAL_STAGES = [
|
|
9
|
+
'interested',
|
|
10
|
+
'proposal',
|
|
11
|
+
'closing',
|
|
12
|
+
'closed_won',
|
|
13
|
+
'closed_lost',
|
|
14
|
+
'nurturing'
|
|
15
|
+
] as const satisfies readonly DealStage[]
|
|
16
|
+
|
|
17
|
+
function deal(stageKey: string | null, stateKey: string | null = null): Parameters<typeof deriveActions>[0] {
|
|
18
|
+
return { stage_key: stageKey, state_key: stateKey } as Parameters<typeof deriveActions>[0]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('CRM deal action derivation', () => {
|
|
22
|
+
it('derives the exact base actions for interested deals', () => {
|
|
23
|
+
expect(deriveActions(deal('interested'))).toEqual([
|
|
24
|
+
{ key: 'move_to_proposal', label: 'Move to Proposal' },
|
|
25
|
+
{ key: 'move_to_closed_lost', label: 'Close Lost' },
|
|
26
|
+
{ key: 'move_to_nurturing', label: 'Move to Nurturing' }
|
|
27
|
+
])
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it.each([
|
|
31
|
+
['discovery_replied', { key: 'send_link', label: 'Send Booking Link' }],
|
|
32
|
+
['discovery_link_sent', { key: 'send_nudge', label: 'Send Nudge' }],
|
|
33
|
+
['discovery_booking_cancelled', { key: 'rebook', label: 'Rebook' }]
|
|
34
|
+
] as const)('adds the expected workflow action for interested/%s', (stateKey, expectedAction) => {
|
|
35
|
+
const expected = [
|
|
36
|
+
{ key: 'move_to_proposal', label: 'Move to Proposal' },
|
|
37
|
+
{ key: 'move_to_closed_lost', label: 'Close Lost' },
|
|
38
|
+
{ key: 'move_to_nurturing', label: 'Move to Nurturing' },
|
|
39
|
+
expectedAction
|
|
40
|
+
]
|
|
41
|
+
|
|
42
42
|
expect(deriveActions(deal('interested', stateKey))).toEqual(expected)
|
|
43
43
|
})
|
|
44
44
|
|
|
@@ -51,101 +51,101 @@ describe('CRM deal action derivation', () => {
|
|
|
51
51
|
{ key: 'mark_no_show', label: 'Mark No-Show' }
|
|
52
52
|
])
|
|
53
53
|
})
|
|
54
|
-
|
|
55
|
-
it('derives exact proposal and closing transitions', () => {
|
|
56
|
-
expect(deriveActions(deal('proposal'))).toEqual([
|
|
57
|
-
{ key: 'move_to_closing', label: 'Move to Closing' },
|
|
58
|
-
{ key: 'move_to_closed_lost', label: 'Close Lost' },
|
|
59
|
-
{ key: 'move_to_nurturing', label: 'Move to Nurturing' }
|
|
60
|
-
])
|
|
61
|
-
|
|
62
|
-
expect(deriveActions(deal('closing'))).toEqual([
|
|
63
|
-
{ key: 'move_to_closed_won', label: 'Close Won' },
|
|
64
|
-
{ key: 'move_to_closed_lost', label: 'Close Lost' },
|
|
65
|
-
{ key: 'move_to_nurturing', label: 'Move to Nurturing' }
|
|
66
|
-
])
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it.each(['closed_won', 'closed_lost', 'nurturing', 'legacy_stage', null] as const)(
|
|
70
|
-
'derives no actions for terminal or non-canonical stage %s',
|
|
71
|
-
(stageKey) => {
|
|
72
|
-
expect(deriveActions(deal(stageKey))).toEqual([])
|
|
73
|
-
}
|
|
74
|
-
)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
describe('ActivityEventSchema', () => {
|
|
78
|
-
const timestamp = '2026-04-27T12:34:56.000Z'
|
|
79
|
-
|
|
80
|
-
// Platform events only (8 members). Domain events (reply_received, booking_nudge_sent, etc.)
|
|
81
|
-
// live in
|
|
82
|
-
// See Open Decision #5 in crm-action-system.mdx for rationale.
|
|
83
|
-
it.each([
|
|
84
|
-
[{ type: 'stage_change', timestamp, stageBefore: 'interested', stageAfter: 'proposal', reason: 'qualified' }],
|
|
85
|
-
[{ type: 'state_change', timestamp, stateBefore: null, stateAfter: 'discovery_replied' }],
|
|
86
|
-
[{ type: 'action_taken', timestamp, actionKey: 'send_link', payload: { channel: 'email' } }],
|
|
87
|
-
[{ type: 'approval_created', timestamp, commandId: 'cmd_123', dealStageBefore: 'proposal' }],
|
|
88
|
-
[{ type: 'approval_resolved', timestamp, commandId: 'cmd_123', resolution: 'superseded' }],
|
|
89
|
-
[{ type: 'approval_stale', timestamp, commandId: 'cmd_123', dealStageAfter: 'closing' }],
|
|
90
|
-
[{ type: 'task_created', timestamp, taskId: 'task_123' }],
|
|
91
|
-
[{ type: 'deal_created', timestamp }]
|
|
92
|
-
])('accepts expected %s events', (event) => {
|
|
93
|
-
expect(ActivityEventSchema.safeParse(event).success).toBe(true)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it.each([
|
|
97
|
-
[{ type: 'deal_created', timestamp: 'not-a-date' }],
|
|
98
|
-
[{ type: 'unknown_event', timestamp }],
|
|
99
|
-
[{ type: 'stage_change', timestamp, stageBefore: 'interested' }],
|
|
100
|
-
[{ type: 'approval_resolved', timestamp, commandId: 'cmd_123', resolution: 'approved' }],
|
|
101
|
-
[{ type: 'booking_nudge_sent', timestamp, followupDay: '2' }],
|
|
102
|
-
[{ type: 'action_taken', timestamp }]
|
|
103
|
-
])('rejects malformed event payload %o', (event) => {
|
|
104
|
-
expect(ActivityEventSchema.safeParse(event).success).toBe(false)
|
|
105
|
-
})
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
describe('CRM stage and transition vocabulary contracts', () => {
|
|
109
|
-
it('keeps DealStage, DealStageSchema, and the default sales pipeline stages aligned', () => {
|
|
110
|
-
const defaultPipeline = DEFAULT_ORGANIZATION_MODEL_SALES.pipelines.find(
|
|
111
|
-
(pipeline) => pipeline.id === DEFAULT_ORGANIZATION_MODEL_SALES.defaultPipelineId
|
|
112
|
-
)
|
|
113
|
-
const defaultSalesStages = defaultPipeline?.stages
|
|
114
|
-
.toSorted((left, right) => left.order - right.order)
|
|
115
|
-
.map((stage) => stage.id)
|
|
116
|
-
|
|
117
|
-
expect(defaultSalesStages).toEqual([...DEAL_STAGES])
|
|
118
|
-
expect(DealStageSchema.options).toEqual([...DEAL_STAGES])
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('accepts every canonical CRM deal stage in transition requests', () => {
|
|
122
|
-
for (const stageKey of DEAL_STAGES) {
|
|
123
|
-
expect(
|
|
124
|
-
TransitionItemRequestSchema.safeParse({
|
|
125
|
-
pipelineKey: DEFAULT_ORGANIZATION_MODEL_SALES.defaultPipelineId,
|
|
126
|
-
stageKey,
|
|
127
|
-
stateKey: null,
|
|
128
|
-
expectedUpdatedAt: '2026-04-27T12:34:56.000Z'
|
|
129
|
-
}).success
|
|
130
|
-
).toBe(true)
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it('accepts canonical lead-gen stage/state pairs in transition requests', () => {
|
|
135
|
-
for (const pipelineDefinitions of Object.values(LEAD_GEN_PIPELINE_DEFINITIONS)) {
|
|
136
|
-
for (const pipeline of pipelineDefinitions) {
|
|
137
|
-
for (const stage of pipeline.stages) {
|
|
138
|
-
for (const state of stage.states) {
|
|
139
|
-
expect(
|
|
140
|
-
TransitionItemRequestSchema.safeParse({
|
|
141
|
-
pipelineKey: pipeline.pipelineKey,
|
|
142
|
-
stageKey: stage.stageKey,
|
|
143
|
-
stateKey: state.stateKey
|
|
144
|
-
}).success
|
|
145
|
-
).toBe(true)
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
})
|
|
151
|
-
})
|
|
54
|
+
|
|
55
|
+
it('derives exact proposal and closing transitions', () => {
|
|
56
|
+
expect(deriveActions(deal('proposal'))).toEqual([
|
|
57
|
+
{ key: 'move_to_closing', label: 'Move to Closing' },
|
|
58
|
+
{ key: 'move_to_closed_lost', label: 'Close Lost' },
|
|
59
|
+
{ key: 'move_to_nurturing', label: 'Move to Nurturing' }
|
|
60
|
+
])
|
|
61
|
+
|
|
62
|
+
expect(deriveActions(deal('closing'))).toEqual([
|
|
63
|
+
{ key: 'move_to_closed_won', label: 'Close Won' },
|
|
64
|
+
{ key: 'move_to_closed_lost', label: 'Close Lost' },
|
|
65
|
+
{ key: 'move_to_nurturing', label: 'Move to Nurturing' }
|
|
66
|
+
])
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it.each(['closed_won', 'closed_lost', 'nurturing', 'legacy_stage', null] as const)(
|
|
70
|
+
'derives no actions for terminal or non-canonical stage %s',
|
|
71
|
+
(stageKey) => {
|
|
72
|
+
expect(deriveActions(deal(stageKey))).toEqual([])
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('ActivityEventSchema', () => {
|
|
78
|
+
const timestamp = '2026-04-27T12:34:56.000Z'
|
|
79
|
+
|
|
80
|
+
// Platform events only (8 members). Domain events (reply_received, booking_nudge_sent, etc.)
|
|
81
|
+
// live in @repo/elevasis-operations as CrmDomainActivityEventSchema.
|
|
82
|
+
// See Open Decision #5 in crm-action-system.mdx for rationale.
|
|
83
|
+
it.each([
|
|
84
|
+
[{ type: 'stage_change', timestamp, stageBefore: 'interested', stageAfter: 'proposal', reason: 'qualified' }],
|
|
85
|
+
[{ type: 'state_change', timestamp, stateBefore: null, stateAfter: 'discovery_replied' }],
|
|
86
|
+
[{ type: 'action_taken', timestamp, actionKey: 'send_link', payload: { channel: 'email' } }],
|
|
87
|
+
[{ type: 'approval_created', timestamp, commandId: 'cmd_123', dealStageBefore: 'proposal' }],
|
|
88
|
+
[{ type: 'approval_resolved', timestamp, commandId: 'cmd_123', resolution: 'superseded' }],
|
|
89
|
+
[{ type: 'approval_stale', timestamp, commandId: 'cmd_123', dealStageAfter: 'closing' }],
|
|
90
|
+
[{ type: 'task_created', timestamp, taskId: 'task_123' }],
|
|
91
|
+
[{ type: 'deal_created', timestamp }]
|
|
92
|
+
])('accepts expected %s events', (event) => {
|
|
93
|
+
expect(ActivityEventSchema.safeParse(event).success).toBe(true)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it.each([
|
|
97
|
+
[{ type: 'deal_created', timestamp: 'not-a-date' }],
|
|
98
|
+
[{ type: 'unknown_event', timestamp }],
|
|
99
|
+
[{ type: 'stage_change', timestamp, stageBefore: 'interested' }],
|
|
100
|
+
[{ type: 'approval_resolved', timestamp, commandId: 'cmd_123', resolution: 'approved' }],
|
|
101
|
+
[{ type: 'booking_nudge_sent', timestamp, followupDay: '2' }],
|
|
102
|
+
[{ type: 'action_taken', timestamp }]
|
|
103
|
+
])('rejects malformed event payload %o', (event) => {
|
|
104
|
+
expect(ActivityEventSchema.safeParse(event).success).toBe(false)
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('CRM stage and transition vocabulary contracts', () => {
|
|
109
|
+
it('keeps DealStage, DealStageSchema, and the default sales pipeline stages aligned', () => {
|
|
110
|
+
const defaultPipeline = DEFAULT_ORGANIZATION_MODEL_SALES.pipelines.find(
|
|
111
|
+
(pipeline) => pipeline.id === DEFAULT_ORGANIZATION_MODEL_SALES.defaultPipelineId
|
|
112
|
+
)
|
|
113
|
+
const defaultSalesStages = defaultPipeline?.stages
|
|
114
|
+
.toSorted((left, right) => left.order - right.order)
|
|
115
|
+
.map((stage) => stage.id)
|
|
116
|
+
|
|
117
|
+
expect(defaultSalesStages).toEqual([...DEAL_STAGES])
|
|
118
|
+
expect(DealStageSchema.options).toEqual([...DEAL_STAGES])
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('accepts every canonical CRM deal stage in transition requests', () => {
|
|
122
|
+
for (const stageKey of DEAL_STAGES) {
|
|
123
|
+
expect(
|
|
124
|
+
TransitionItemRequestSchema.safeParse({
|
|
125
|
+
pipelineKey: DEFAULT_ORGANIZATION_MODEL_SALES.defaultPipelineId,
|
|
126
|
+
stageKey,
|
|
127
|
+
stateKey: null,
|
|
128
|
+
expectedUpdatedAt: '2026-04-27T12:34:56.000Z'
|
|
129
|
+
}).success
|
|
130
|
+
).toBe(true)
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('accepts canonical lead-gen stage/state pairs in transition requests', () => {
|
|
135
|
+
for (const pipelineDefinitions of Object.values(LEAD_GEN_PIPELINE_DEFINITIONS)) {
|
|
136
|
+
for (const pipeline of pipelineDefinitions) {
|
|
137
|
+
for (const stage of pipeline.stages) {
|
|
138
|
+
for (const state of stage.states) {
|
|
139
|
+
expect(
|
|
140
|
+
TransitionItemRequestSchema.safeParse({
|
|
141
|
+
pipelineKey: pipeline.pipelineKey,
|
|
142
|
+
stageKey: stage.stageKey,
|
|
143
|
+
stateKey: state.stateKey
|
|
144
|
+
}).success
|
|
145
|
+
).toBe(true)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
})
|