@elevasis/core 0.15.0 → 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 (88) hide show
  1. package/dist/index.d.ts +1718 -19
  2. package/dist/index.js +369 -25
  3. package/dist/organization-model/index.d.ts +1718 -19
  4. package/dist/organization-model/index.js +369 -25
  5. package/dist/test-utils/index.d.ts +1108 -371
  6. package/dist/test-utils/index.js +357 -17
  7. package/package.json +5 -1
  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 +1109 -882
  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 +13 -4
  16. package/src/business/acquisition/api-schemas.test.ts +315 -4
  17. package/src/business/acquisition/api-schemas.ts +122 -8
  18. package/src/business/acquisition/build-templates.ts +44 -0
  19. package/src/business/acquisition/crm-next-action.test.ts +262 -0
  20. package/src/business/acquisition/crm-next-action.ts +220 -0
  21. package/src/business/acquisition/crm-priority.test.ts +216 -0
  22. package/src/business/acquisition/crm-priority.ts +349 -0
  23. package/src/business/acquisition/crm-state-actions.test.ts +151 -160
  24. package/src/business/acquisition/deal-ownership.test.ts +351 -0
  25. package/src/business/acquisition/deal-ownership.ts +120 -0
  26. package/src/business/acquisition/derive-actions.test.ts +101 -37
  27. package/src/business/acquisition/derive-actions.ts +102 -87
  28. package/src/business/acquisition/index.ts +10 -0
  29. package/src/business/acquisition/types.ts +400 -366
  30. package/src/business/crm/api-schemas.ts +40 -0
  31. package/src/business/crm/index.ts +1 -0
  32. package/src/business/deals/api-schemas.ts +79 -0
  33. package/src/business/deals/index.ts +1 -0
  34. package/src/business/projects/types.ts +124 -88
  35. package/src/execution/core/runner-types.ts +61 -80
  36. package/src/execution/engine/index.ts +4 -3
  37. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-tools.ts +105 -104
  38. package/src/execution/engine/tools/integration/server/adapters/instantly/instantly-tools.ts +1474 -1473
  39. package/src/execution/engine/tools/integration/server/adapters/millionverifier/millionverifier-tools.ts +103 -102
  40. package/src/execution/engine/tools/integration/server/adapters/signature-api/signature-api-tools.ts +182 -179
  41. package/src/execution/engine/tools/integration/server/adapters/stripe/stripe-tools.ts +310 -309
  42. package/src/execution/engine/tools/integration/tool.ts +255 -253
  43. package/src/execution/engine/tools/lead-service-types.ts +939 -924
  44. package/src/execution/engine/tools/messages.ts +43 -0
  45. package/src/execution/engine/tools/platform/acquisition/list-tools.ts +6 -5
  46. package/src/execution/engine/tools/platform/acquisition/types.ts +5 -2
  47. package/src/execution/engine/tools/platform/email/types.ts +97 -96
  48. package/src/execution/engine/tools/registry.ts +4 -3
  49. package/src/execution/engine/tools/tool-maps.ts +3 -1
  50. package/src/execution/engine/tools/types.ts +234 -233
  51. package/src/execution/engine/workflow/types.ts +195 -193
  52. package/src/execution/external/api-schemas.ts +40 -0
  53. package/src/execution/external/index.ts +1 -0
  54. package/src/knowledge/README.md +32 -0
  55. package/src/knowledge/__tests__/queries.test.ts +504 -0
  56. package/src/knowledge/format.ts +99 -0
  57. package/src/knowledge/index.ts +5 -0
  58. package/src/knowledge/queries.ts +256 -0
  59. package/src/organization-model/__tests__/defaults.test.ts +172 -172
  60. package/src/organization-model/__tests__/foundation.test.ts +7 -7
  61. package/src/organization-model/__tests__/icons.test.ts +27 -0
  62. package/src/organization-model/__tests__/knowledge.test.ts +214 -0
  63. package/src/organization-model/contracts.ts +17 -15
  64. package/src/organization-model/defaults.ts +74 -19
  65. package/src/organization-model/domains/knowledge.ts +53 -0
  66. package/src/organization-model/domains/navigation.ts +416 -399
  67. package/src/organization-model/domains/prospecting.ts +204 -1
  68. package/src/organization-model/domains/sales.test.ts +29 -0
  69. package/src/organization-model/domains/sales.ts +102 -0
  70. package/src/organization-model/domains/shared.ts +6 -5
  71. package/src/organization-model/foundation.ts +10 -6
  72. package/src/organization-model/graph/build.ts +209 -182
  73. package/src/organization-model/graph/schema.ts +37 -34
  74. package/src/organization-model/graph/types.ts +47 -31
  75. package/src/organization-model/icons.ts +81 -0
  76. package/src/organization-model/index.ts +8 -3
  77. package/src/organization-model/organization-model.mdx +1 -1
  78. package/src/organization-model/published.ts +103 -86
  79. package/src/organization-model/schema.ts +90 -85
  80. package/src/organization-model/types.ts +42 -35
  81. package/src/platform/constants/versions.ts +1 -1
  82. package/src/platform/index.ts +23 -27
  83. package/src/platform/registry/index.ts +0 -4
  84. package/src/platform/registry/resource-registry.ts +0 -77
  85. package/src/platform/registry/serialized-types.ts +148 -219
  86. package/src/platform/registry/stats-types.ts +60 -60
  87. package/src/reference/_generated/contracts.md +829 -595
  88. package/src/supabase/database.types.ts +2978 -2958
@@ -1,18 +1,19 @@
1
- import { z } from 'zod'
1
+ import { z } from 'zod'
2
2
  import {
3
3
  CRM_DISCOVERY_BOOKING_CANCELLED_STATE,
4
4
  CRM_DISCOVERY_LINK_SENT_STATE,
5
5
  CRM_DISCOVERY_NUDGING_STATE,
6
6
  CRM_DISCOVERY_REPLIED_STATE
7
7
  } from '@repo/core/organization-model'
8
+ import { getDealOwnership, type DealOwnership } from './deal-ownership'
8
9
  import type { AcqDealRow } from './types'
9
-
10
- export interface Action {
11
- key: string
12
- label: string
13
- payloadSchema?: z.ZodTypeAny
14
- }
15
-
10
+
11
+ export interface Action {
12
+ key: string
13
+ label: string
14
+ payloadSchema?: z.ZodTypeAny
15
+ }
16
+
16
17
  export interface ActionDef {
17
18
  key: string
18
19
  label: string
@@ -21,93 +22,107 @@ export interface ActionDef {
21
22
  payloadSchema?: z.ZodTypeAny
22
23
  }
23
24
 
24
- export const SendReplyActionPayloadSchema = z
25
- .object({
26
- replyBody: z.string().trim().min(1).max(10000)
27
- })
28
- .strict()
29
-
30
- export const DEFAULT_CRM_ACTIONS: ActionDef[] = [
31
- {
32
- key: 'move_to_proposal',
33
- label: 'Move to Proposal',
34
- isAvailableFor: (deal) => deal.stage_key === 'interested',
35
- workflowId: 'move_to_proposal-workflow'
36
- },
37
- {
38
- key: 'move_to_closing',
39
- label: 'Move to Closing',
40
- isAvailableFor: (deal) => deal.stage_key === 'proposal',
41
- workflowId: 'move_to_closing-workflow'
42
- },
43
- {
44
- key: 'move_to_closed_won',
45
- label: 'Close Won',
46
- isAvailableFor: (deal) => deal.stage_key === 'closing',
47
- workflowId: 'move_to_closed_won-workflow'
48
- },
49
- {
50
- key: 'move_to_closed_lost',
51
- label: 'Close Lost',
52
- isAvailableFor: (deal) =>
53
- deal.stage_key === 'interested' || deal.stage_key === 'proposal' || deal.stage_key === 'closing',
54
- workflowId: 'move_to_closed_lost-workflow'
55
- },
56
- {
57
- key: 'move_to_nurturing',
58
- label: 'Move to Nurturing',
59
- isAvailableFor: (deal) =>
60
- deal.stage_key === 'interested' || deal.stage_key === 'proposal' || deal.stage_key === 'closing',
61
- workflowId: 'move_to_nurturing-workflow'
62
- },
63
- {
25
+ type DealActionInput = AcqDealRow & {
26
+ ownership?: DealOwnership
27
+ nextAction?: string | null
28
+ }
29
+
30
+ export const SendReplyActionPayloadSchema = z
31
+ .object({
32
+ replyBody: z.string().trim().min(1).max(10000)
33
+ })
34
+ .strict()
35
+
36
+ export const DEFAULT_CRM_ACTIONS: ActionDef[] = [
37
+ {
38
+ key: 'move_to_proposal',
39
+ label: 'Move to Proposal',
40
+ isAvailableFor: (deal) => deal.stage_key === 'interested',
41
+ workflowId: 'move_to_proposal-workflow'
42
+ },
43
+ {
44
+ key: 'move_to_closing',
45
+ label: 'Move to Closing',
46
+ isAvailableFor: (deal) => deal.stage_key === 'proposal',
47
+ workflowId: 'move_to_closing-workflow'
48
+ },
49
+ {
50
+ key: 'move_to_closed_won',
51
+ label: 'Close Won',
52
+ isAvailableFor: (deal) => deal.stage_key === 'closing',
53
+ workflowId: 'move_to_closed_won-workflow'
54
+ },
55
+ {
56
+ key: 'move_to_closed_lost',
57
+ label: 'Close Lost',
58
+ isAvailableFor: (deal) =>
59
+ deal.stage_key === 'interested' || deal.stage_key === 'proposal' || deal.stage_key === 'closing',
60
+ workflowId: 'move_to_closed_lost-workflow'
61
+ },
62
+ {
63
+ key: 'move_to_nurturing',
64
+ label: 'Move to Nurturing',
65
+ isAvailableFor: (deal) =>
66
+ deal.stage_key === 'interested' || deal.stage_key === 'proposal' || deal.stage_key === 'closing',
67
+ workflowId: 'move_to_nurturing-workflow'
68
+ },
69
+ {
64
70
  key: 'send_reply',
65
71
  label: 'Send Reply',
66
72
  isAvailableFor: (deal) =>
67
73
  deal.stage_key === 'interested' &&
74
+ isOurReplyAction(deal) &&
68
75
  (deal.state_key === CRM_DISCOVERY_REPLIED_STATE.stateKey ||
69
76
  deal.state_key === CRM_DISCOVERY_LINK_SENT_STATE.stateKey ||
70
77
  deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey),
71
- workflowId: 'crm-send-reply-workflow',
72
- payloadSchema: SendReplyActionPayloadSchema
73
- },
74
- {
75
- key: 'send_link',
76
- label: 'Send Booking Link',
77
- isAvailableFor: (deal) =>
78
- deal.stage_key === 'interested' && deal.state_key === CRM_DISCOVERY_REPLIED_STATE.stateKey,
79
- workflowId: 'crm-send-booking-link-workflow'
80
- },
81
- {
82
- key: 'send_nudge',
83
- label: 'Send Nudge',
84
- isAvailableFor: (deal) =>
85
- deal.stage_key === 'interested' &&
86
- (deal.state_key === CRM_DISCOVERY_LINK_SENT_STATE.stateKey ||
87
- deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey),
88
- workflowId: 'crm-send-nudge-workflow'
89
- },
90
- {
91
- key: 'mark_no_show',
92
- label: 'Mark No-Show',
93
- isAvailableFor: (deal) =>
94
- deal.stage_key === 'interested' && deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey,
95
- // Mirrors the auto-timeout precedent in operations/sales/crm/pipeline/timeout-actions.ts:
96
- // both manual-click and timeout move the deal to closed_lost. The action_taken activity
97
- // event captures operator intent and distinguishes the manual variant from the timed one.
98
- workflowId: 'mark_no_show-workflow'
99
- },
100
- {
101
- key: 'rebook',
102
- label: 'Rebook',
103
- isAvailableFor: (deal) =>
104
- deal.stage_key === 'interested' && deal.state_key === CRM_DISCOVERY_BOOKING_CANCELLED_STATE.stateKey,
105
- workflowId: 'crm-rebook-workflow'
106
- }
107
- ]
108
-
109
- export function deriveActions(deal: AcqDealRow, actions: ActionDef[] = DEFAULT_CRM_ACTIONS): Action[] {
78
+ workflowId: 'crm-send-reply-workflow',
79
+ payloadSchema: SendReplyActionPayloadSchema
80
+ },
81
+ {
82
+ key: 'send_link',
83
+ label: 'Send Booking Link',
84
+ isAvailableFor: (deal) =>
85
+ deal.stage_key === 'interested' && deal.state_key === CRM_DISCOVERY_REPLIED_STATE.stateKey,
86
+ workflowId: 'crm-send-booking-link-workflow'
87
+ },
88
+ {
89
+ key: 'send_nudge',
90
+ label: 'Send Nudge',
91
+ isAvailableFor: (deal) =>
92
+ deal.stage_key === 'interested' &&
93
+ (deal.state_key === CRM_DISCOVERY_LINK_SENT_STATE.stateKey ||
94
+ deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey),
95
+ workflowId: 'crm-send-nudge-workflow'
96
+ },
97
+ {
98
+ key: 'mark_no_show',
99
+ label: 'Mark No-Show',
100
+ isAvailableFor: (deal) =>
101
+ deal.stage_key === 'interested' && deal.state_key === CRM_DISCOVERY_NUDGING_STATE.stateKey,
102
+ // Mirrors the auto-timeout precedent in operations/sales/crm/pipeline/timeout-actions.ts:
103
+ // both manual-click and timeout move the deal to closed_lost. The action_taken activity
104
+ // event captures operator intent and distinguishes the manual variant from the timed one.
105
+ workflowId: 'mark_no_show-workflow'
106
+ },
107
+ {
108
+ key: 'rebook',
109
+ label: 'Rebook',
110
+ isAvailableFor: (deal) =>
111
+ deal.stage_key === 'interested' && deal.state_key === CRM_DISCOVERY_BOOKING_CANCELLED_STATE.stateKey,
112
+ workflowId: 'crm-rebook-workflow'
113
+ }
114
+ ]
115
+
116
+ export function deriveActions(deal: DealActionInput, actions: ActionDef[] = DEFAULT_CRM_ACTIONS): Action[] {
110
117
  return actions
111
118
  .filter((a) => a.isAvailableFor(deal))
112
119
  .map(({ key, label, payloadSchema }) => ({ key, label, payloadSchema }))
113
120
  }
121
+
122
+ function isOurReplyAction(deal: DealActionInput): boolean {
123
+ if (Object.prototype.hasOwnProperty.call(deal, 'nextAction')) {
124
+ return deal.nextAction === 'send_reply'
125
+ }
126
+
127
+ return (deal.ownership ?? getDealOwnership(deal)) === 'us'
128
+ }
@@ -1,6 +1,10 @@
1
1
  export * from './types'
2
2
  export * from './activity-events'
3
+ export * from './build-templates'
3
4
  export * from './derive-actions'
5
+ export * from './crm-priority'
6
+ export * from './crm-next-action'
7
+ export * from './deal-ownership'
4
8
  export * from './stateful'
5
9
  // Export api-schemas selectively to avoid re-exporting names already defined in types.ts
6
10
  // (DealStage, AcqDealTaskKind are declared as union types there; api-schemas re-infers them from Zod)
@@ -35,6 +39,7 @@ export {
35
39
  ExecuteActionParamsSchema,
36
40
  ExecuteActionRequestSchema,
37
41
  DealContactSummarySchema,
42
+ DealPrioritySchema,
38
43
  DealListItemSchema,
39
44
  DealListResponseSchema,
40
45
  DealDetailResponseSchema,
@@ -48,6 +53,10 @@ export {
48
53
  IcpRubricSchema,
49
54
  PipelineStageSchema,
50
55
  PipelineConfigSchema,
56
+ BuildPlanSnapshotStepSchema,
57
+ BuildPlanSnapshotSchema,
58
+ AcqListMetadataSchema,
59
+ ProspectingBuildTemplateIdSchema,
51
60
  ProcessingStageStatusSchema,
52
61
  ListStageCountsSchema,
53
62
  ListTelemetrySchema,
@@ -119,6 +128,7 @@ export {
119
128
  type TransitionDealStateRequest,
120
129
  type ExecuteActionParams,
121
130
  type ExecuteActionRequest,
131
+ type DealPriorityResponse,
122
132
  type DealListResponse,
123
133
  type DealDetailResponse,
124
134
  type DealNoteResponse,