@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.
Files changed (68) hide show
  1. package/dist/index.d.ts +1662 -23
  2. package/dist/index.js +171 -24
  3. package/dist/organization-model/index.d.ts +1662 -23
  4. package/dist/organization-model/index.js +171 -24
  5. package/dist/test-utils/index.d.ts +711 -10
  6. package/dist/test-utils/index.js +159 -16
  7. package/package.json +7 -3
  8. package/src/__tests__/publish.test.ts +14 -13
  9. package/src/__tests__/template-core-compatibility.test.ts +4 -4
  10. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +305 -201
  11. package/src/auth/multi-tenancy/index.ts +3 -0
  12. package/src/auth/multi-tenancy/theme-presets.ts +45 -0
  13. package/src/auth/multi-tenancy/types.ts +57 -83
  14. package/src/auth/multi-tenancy/users/api-schemas.ts +165 -194
  15. package/src/business/acquisition/activity-events.ts +1 -1
  16. package/src/business/acquisition/api-schemas.ts +1196 -1177
  17. package/src/business/acquisition/crm-state-actions.test.ts +139 -139
  18. package/src/business/acquisition/types.ts +381 -390
  19. package/src/business/crm/api-schemas.ts +40 -0
  20. package/src/business/crm/index.ts +1 -0
  21. package/src/business/deals/api-schemas.ts +79 -0
  22. package/src/business/deals/index.ts +1 -0
  23. package/src/business/projects/types.ts +124 -88
  24. package/src/execution/core/runner-types.ts +61 -80
  25. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-tools.ts +105 -104
  26. package/src/execution/engine/tools/integration/server/adapters/instantly/instantly-tools.ts +1474 -1473
  27. package/src/execution/engine/tools/integration/server/adapters/millionverifier/millionverifier-tools.ts +103 -102
  28. package/src/execution/engine/tools/integration/server/adapters/signature-api/signature-api-tools.ts +182 -179
  29. package/src/execution/engine/tools/integration/server/adapters/stripe/stripe-tools.ts +310 -309
  30. package/src/execution/engine/tools/integration/tool.ts +255 -253
  31. package/src/execution/engine/tools/lead-service-types.ts +895 -894
  32. package/src/execution/engine/tools/messages.ts +43 -0
  33. package/src/execution/engine/tools/platform/acquisition/types.ts +2 -1
  34. package/src/execution/engine/tools/platform/email/types.ts +97 -96
  35. package/src/execution/engine/tools/types.ts +234 -233
  36. package/src/execution/engine/workflow/types.ts +195 -193
  37. package/src/execution/external/api-schemas.ts +40 -0
  38. package/src/execution/external/index.ts +1 -0
  39. package/src/knowledge/README.md +32 -0
  40. package/src/knowledge/__tests__/queries.test.ts +504 -0
  41. package/src/knowledge/format.ts +99 -0
  42. package/src/knowledge/index.ts +5 -0
  43. package/src/knowledge/queries.ts +256 -0
  44. package/src/organization-model/__tests__/defaults.test.ts +172 -172
  45. package/src/organization-model/__tests__/foundation.test.ts +7 -7
  46. package/src/organization-model/__tests__/icons.test.ts +27 -0
  47. package/src/organization-model/__tests__/knowledge.test.ts +214 -0
  48. package/src/organization-model/contracts.ts +17 -15
  49. package/src/organization-model/defaults.ts +74 -19
  50. package/src/organization-model/domains/knowledge.ts +53 -0
  51. package/src/organization-model/domains/navigation.ts +416 -399
  52. package/src/organization-model/domains/shared.ts +6 -5
  53. package/src/organization-model/foundation.ts +10 -6
  54. package/src/organization-model/graph/build.ts +209 -182
  55. package/src/organization-model/graph/schema.ts +37 -34
  56. package/src/organization-model/graph/types.ts +47 -31
  57. package/src/organization-model/icons.ts +81 -0
  58. package/src/organization-model/index.ts +8 -3
  59. package/src/organization-model/organization-model.mdx +1 -1
  60. package/src/organization-model/published.ts +103 -86
  61. package/src/organization-model/schema.ts +90 -85
  62. package/src/organization-model/types.ts +40 -33
  63. package/src/platform/index.ts +23 -27
  64. package/src/platform/registry/index.ts +0 -4
  65. package/src/platform/registry/resource-registry.ts +0 -77
  66. package/src/platform/registry/serialized-types.ts +148 -219
  67. package/src/platform/registry/stats-types.ts +60 -60
  68. 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 external/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
- })
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
+ })