@elevasis/core 0.14.0 → 0.15.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.
@@ -1,103 +1,113 @@
1
- import { z } from 'zod'
2
- import type { AcqDealRow } from './types'
3
-
4
- export interface Action {
5
- key: string
6
- label: string
7
- payloadSchema?: z.ZodTypeAny
8
- }
9
-
10
- export interface ActionDef {
11
- key: string
12
- label: string
13
- isAvailableFor: (deal: AcqDealRow) => boolean
14
- workflowId: string
15
- payloadSchema?: z.ZodTypeAny
16
- }
17
-
18
- export const SendReplyActionPayloadSchema = z
19
- .object({
20
- replyBody: z.string().trim().min(1).max(10000)
21
- })
22
- .strict()
23
-
24
- export const DEFAULT_CRM_ACTIONS: ActionDef[] = [
25
- {
26
- key: 'move_to_proposal',
27
- label: 'Move to Proposal',
28
- isAvailableFor: (deal) => deal.stage_key === 'interested',
29
- workflowId: 'move_to_proposal-workflow'
30
- },
31
- {
32
- key: 'move_to_closing',
33
- label: 'Move to Closing',
34
- isAvailableFor: (deal) => deal.stage_key === 'proposal',
35
- workflowId: 'move_to_closing-workflow'
36
- },
37
- {
38
- key: 'move_to_closed_won',
39
- label: 'Close Won',
40
- isAvailableFor: (deal) => deal.stage_key === 'closing',
41
- workflowId: 'move_to_closed_won-workflow'
42
- },
43
- {
44
- key: 'move_to_closed_lost',
45
- label: 'Close Lost',
46
- isAvailableFor: (deal) =>
47
- deal.stage_key === 'interested' || deal.stage_key === 'proposal' || deal.stage_key === 'closing',
48
- workflowId: 'move_to_closed_lost-workflow'
49
- },
50
- {
51
- key: 'move_to_nurturing',
52
- label: 'Move to Nurturing',
53
- isAvailableFor: (deal) =>
54
- deal.stage_key === 'interested' || deal.stage_key === 'proposal' || deal.stage_key === 'closing',
55
- workflowId: 'move_to_nurturing-workflow'
56
- },
57
- {
58
- key: 'send_reply',
59
- label: 'Send Reply',
60
- isAvailableFor: (deal) =>
61
- deal.stage_key === 'interested' &&
62
- (deal.state_key === 'discovery_replied' ||
63
- deal.state_key === 'discovery_link_sent' ||
64
- deal.state_key === 'discovery_nudging'),
65
- workflowId: 'crm-send-reply-workflow',
66
- payloadSchema: SendReplyActionPayloadSchema
67
- },
68
- {
69
- key: 'send_link',
70
- label: 'Send Booking Link',
71
- isAvailableFor: (deal) => deal.stage_key === 'interested' && deal.state_key === 'discovery_replied',
72
- workflowId: 'crm-send-booking-link-workflow'
73
- },
74
- {
75
- key: 'send_nudge',
76
- label: 'Send Nudge',
77
- isAvailableFor: (deal) =>
78
- deal.stage_key === 'interested' &&
79
- (deal.state_key === 'discovery_link_sent' || deal.state_key === 'discovery_nudging'),
80
- workflowId: 'crm-send-nudge-workflow'
81
- },
82
- {
83
- key: 'mark_no_show',
84
- label: 'Mark No-Show',
85
- isAvailableFor: (deal) => deal.stage_key === 'interested' && deal.state_key === 'discovery_nudging',
86
- // Mirrors the auto-timeout precedent in operations/sales/crm/pipeline/timeout-actions.ts:
87
- // both manual-click and timeout move the deal to closed_lost. The action_taken activity
88
- // event captures operator intent and distinguishes the manual variant from the timed one.
89
- workflowId: 'mark_no_show-workflow'
90
- },
91
- {
92
- key: 'rebook',
93
- label: 'Rebook',
94
- isAvailableFor: (deal) => deal.stage_key === 'interested' && deal.state_key === 'discovery_booking_cancelled',
95
- workflowId: 'crm-rebook-workflow'
96
- }
97
- ]
98
-
99
- export function deriveActions(deal: AcqDealRow, actions: ActionDef[] = DEFAULT_CRM_ACTIONS): Action[] {
100
- return actions
101
- .filter((a) => a.isAvailableFor(deal))
102
- .map(({ key, label, payloadSchema }) => ({ key, label, payloadSchema }))
103
- }
1
+ import { z } from 'zod'
2
+ import {
3
+ CRM_DISCOVERY_BOOKING_CANCELLED_STATE,
4
+ CRM_DISCOVERY_LINK_SENT_STATE,
5
+ CRM_DISCOVERY_NUDGING_STATE,
6
+ CRM_DISCOVERY_REPLIED_STATE
7
+ } from '@repo/core/organization-model'
8
+ import type { AcqDealRow } from './types'
9
+
10
+ export interface Action {
11
+ key: string
12
+ label: string
13
+ payloadSchema?: z.ZodTypeAny
14
+ }
15
+
16
+ export interface ActionDef {
17
+ key: string
18
+ label: string
19
+ isAvailableFor: (deal: AcqDealRow) => boolean
20
+ workflowId: string
21
+ payloadSchema?: z.ZodTypeAny
22
+ }
23
+
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
+ {
64
+ key: 'send_reply',
65
+ label: 'Send Reply',
66
+ isAvailableFor: (deal) =>
67
+ deal.stage_key === 'interested' &&
68
+ (deal.state_key === CRM_DISCOVERY_REPLIED_STATE.stateKey ||
69
+ deal.state_key === CRM_DISCOVERY_LINK_SENT_STATE.stateKey ||
70
+ 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[] {
110
+ return actions
111
+ .filter((a) => a.isAvailableFor(deal))
112
+ .map(({ key, label, payloadSchema }) => ({ key, label, payloadSchema }))
113
+ }
@@ -1,149 +1,153 @@
1
- export * from './types'
2
- export * from './activity-events'
3
- export * from './derive-actions'
4
- export * from './stateful'
5
- // Export api-schemas selectively to avoid re-exporting names already defined in types.ts
6
- // (DealStage, AcqDealTaskKind are declared as union types there; api-schemas re-infers them from Zod)
7
- export {
8
- AcqCompanyStatusSchema,
9
- AcqContactStatusSchema,
10
- AcqEmailValidSchema,
11
- CompanyIdParamsSchema,
12
- ContactIdParamsSchema,
13
- ListCompaniesQuerySchema,
14
- ListContactsQuerySchema,
15
- CreateCompanyRequestSchema,
16
- UpdateCompanyRequestSchema,
17
- CreateContactRequestSchema,
18
- UpdateContactRequestSchema,
19
- AcqCompanyResponseSchema,
20
- AcqCompanyListResponseSchema,
21
- AcqContactResponseSchema,
22
- AcqContactListResponseSchema,
23
- AcqCompanySchemas,
24
- AcqContactSchemas,
25
- DealStageSchema,
26
- AcqDealTaskKindSchema,
27
- DealIdParamsSchema,
28
- DealTaskIdParamsSchema,
29
- ListDealsQuerySchema,
30
- ListDealTasksDueQuerySchema,
31
- CreateDealNoteRequestSchema,
32
- CreateDealTaskRequestSchema,
33
- TransitionItemRequestSchema,
34
- ExecuteActionParamsSchema,
35
- ExecuteActionRequestSchema,
36
- DealContactSummarySchema,
37
- DealListItemSchema,
38
- DealListResponseSchema,
39
- DealDetailResponseSchema,
40
- DealNoteResponseSchema,
41
- DealNoteListResponseSchema,
42
- DealTaskResponseSchema,
43
- DealTaskListResponseSchema,
44
- DealSchemas,
45
- ListStatusSchema,
46
- ScrapingConfigSchema,
47
- IcpRubricSchema,
48
- PipelineStageSchema,
49
- PipelineConfigSchema,
50
- ListStageCountsSchema,
51
- ListTelemetrySchema,
52
- ListIdParamsSchema,
53
- CreateListRequestSchema,
54
- UpdateListRequestSchema,
55
- UpdateListStatusRequestSchema,
56
- UpdateListConfigRequestSchema,
57
- AddCompaniesToListRequestSchema,
58
- RemoveCompaniesFromListRequestSchema,
59
- AddContactsToListRequestSchema,
60
- RecordListExecutionRequestSchema,
61
- AcqListResponseSchema,
62
- AcqListListResponseSchema,
63
- ListTelemetryResponseSchema,
64
- ListTelemetryListResponseSchema,
65
- ListExecutionSummarySchema,
66
- ListExecutionsResponseSchema,
67
- ListStageProgressSchema,
68
- ListProgressResponseSchema,
69
- AcqListSchemas,
70
- AcqSubstrateSchemas,
71
- AcqArtifactOwnerKindSchema,
72
- ListArtifactsQuerySchema,
73
- CreateArtifactRequestSchema,
74
- AcqArtifactResponseSchema,
75
- AcqArtifactListResponseSchema,
76
- ListMembersQuerySchema,
77
- MemberIdParamsSchema,
78
- AcqListMemberContactSummarySchema,
79
- AcqListMemberResponseSchema,
80
- AcqListMembersResponseSchema,
81
- ListCompanyIdParamsSchema,
82
- AcqListCompanyResponseSchema,
83
- type AcqArtifactOwnerKind,
84
- type ListArtifactsQuery,
85
- type CreateArtifactRequest,
86
- type AcqArtifactResponse,
87
- type AcqArtifactListResponse,
88
- type ListMembersQuery,
89
- type MemberIdParams,
90
- type AcqListMemberContactSummary,
91
- type AcqListMemberResponse,
92
- type AcqListMembersResponse,
93
- type ListCompanyIdParams,
94
- type AcqListCompanyResponse,
95
- type CompanyIdParams,
96
- type ContactIdParams,
97
- type ListCompaniesQuery,
98
- type ListContactsQuery,
99
- type CreateCompanyRequest,
100
- type UpdateCompanyRequest,
101
- type CreateContactRequest,
102
- type UpdateContactRequest,
103
- type AcqCompanyResponse,
104
- type AcqCompanyListResponse,
105
- type AcqContactResponse,
106
- type AcqContactListResponse,
107
- type AcqCompanyStatus,
108
- type AcqContactStatus,
109
- type AcqEmailValid,
110
- type DealIdParams,
111
- type DealTaskIdParams,
112
- type ListDealsQuery,
113
- type ListDealTasksDueQuery,
114
- type CreateDealNoteRequest,
115
- type CreateDealTaskRequest,
116
- type TransitionItemRequest,
117
- type ExecuteActionParams,
118
- type ExecuteActionRequest,
119
- type DealListResponse,
120
- type DealDetailResponse,
121
- type DealNoteResponse,
122
- type DealNoteListResponse,
123
- type DealTaskResponse,
124
- type DealTaskListResponse,
125
- type ListStatus,
126
- type ScrapingConfig,
127
- type IcpRubric,
128
- type PipelineStage,
129
- type PipelineConfig,
130
- type ListStageCountsInput,
131
- type ListTelemetryInput,
132
- type ListIdParams,
133
- type CreateListRequest,
134
- type UpdateListRequest,
135
- type UpdateListStatusRequest,
136
- type UpdateListConfigRequest,
137
- type AddCompaniesToListRequest,
138
- type RemoveCompaniesFromListRequest,
139
- type AddContactsToListRequest,
140
- type RecordListExecutionRequest,
141
- type AcqListResponse,
142
- type AcqListListResponse,
143
- type ListTelemetryResponse,
144
- type ListTelemetryListResponse,
145
- type ListExecutionSummaryInput,
146
- type ListExecutionsResponse,
147
- type ListStageProgress,
148
- type ListProgress
149
- } from './api-schemas'
1
+ export * from './types'
2
+ export * from './activity-events'
3
+ export * from './derive-actions'
4
+ export * from './stateful'
5
+ // Export api-schemas selectively to avoid re-exporting names already defined in types.ts
6
+ // (DealStage, AcqDealTaskKind are declared as union types there; api-schemas re-infers them from Zod)
7
+ export {
8
+ AcqCompanyStatusSchema,
9
+ AcqContactStatusSchema,
10
+ AcqEmailValidSchema,
11
+ CompanyIdParamsSchema,
12
+ ContactIdParamsSchema,
13
+ ListCompaniesQuerySchema,
14
+ ListContactsQuerySchema,
15
+ CreateCompanyRequestSchema,
16
+ UpdateCompanyRequestSchema,
17
+ CreateContactRequestSchema,
18
+ UpdateContactRequestSchema,
19
+ AcqCompanyResponseSchema,
20
+ AcqCompanyListResponseSchema,
21
+ AcqContactResponseSchema,
22
+ AcqContactListResponseSchema,
23
+ AcqCompanySchemas,
24
+ AcqContactSchemas,
25
+ DealStageSchema,
26
+ AcqDealTaskKindSchema,
27
+ DealIdParamsSchema,
28
+ DealTaskIdParamsSchema,
29
+ ListDealsQuerySchema,
30
+ ListDealTasksDueQuerySchema,
31
+ CreateDealNoteRequestSchema,
32
+ CreateDealTaskRequestSchema,
33
+ TransitionItemRequestSchema,
34
+ TransitionDealStateRequestSchema,
35
+ ExecuteActionParamsSchema,
36
+ ExecuteActionRequestSchema,
37
+ DealContactSummarySchema,
38
+ DealListItemSchema,
39
+ DealListResponseSchema,
40
+ DealDetailResponseSchema,
41
+ DealNoteResponseSchema,
42
+ DealNoteListResponseSchema,
43
+ DealTaskResponseSchema,
44
+ DealTaskListResponseSchema,
45
+ DealSchemas,
46
+ ListStatusSchema,
47
+ ScrapingConfigSchema,
48
+ IcpRubricSchema,
49
+ PipelineStageSchema,
50
+ PipelineConfigSchema,
51
+ ProcessingStageStatusSchema,
52
+ ListStageCountsSchema,
53
+ ListTelemetrySchema,
54
+ ListIdParamsSchema,
55
+ CreateListRequestSchema,
56
+ UpdateListRequestSchema,
57
+ UpdateListStatusRequestSchema,
58
+ UpdateListConfigRequestSchema,
59
+ AddCompaniesToListRequestSchema,
60
+ RemoveCompaniesFromListRequestSchema,
61
+ AddContactsToListRequestSchema,
62
+ RecordListExecutionRequestSchema,
63
+ AcqListResponseSchema,
64
+ AcqListListResponseSchema,
65
+ ListTelemetryResponseSchema,
66
+ ListTelemetryListResponseSchema,
67
+ ListExecutionSummarySchema,
68
+ ListExecutionsResponseSchema,
69
+ ListStageProgressSchema,
70
+ ListProgressResponseSchema,
71
+ AcqListSchemas,
72
+ AcqSubstrateSchemas,
73
+ AcqArtifactOwnerKindSchema,
74
+ ListArtifactsQuerySchema,
75
+ CreateArtifactRequestSchema,
76
+ AcqArtifactResponseSchema,
77
+ AcqArtifactListResponseSchema,
78
+ ListMembersQuerySchema,
79
+ MemberIdParamsSchema,
80
+ AcqListMemberContactSummarySchema,
81
+ AcqListMemberResponseSchema,
82
+ AcqListMembersResponseSchema,
83
+ ListCompanyIdParamsSchema,
84
+ AcqListCompanyResponseSchema,
85
+ type AcqArtifactOwnerKind,
86
+ type ListArtifactsQuery,
87
+ type CreateArtifactRequest,
88
+ type AcqArtifactResponse,
89
+ type AcqArtifactListResponse,
90
+ type ListMembersQuery,
91
+ type MemberIdParams,
92
+ type AcqListMemberContactSummary,
93
+ type AcqListMemberResponse,
94
+ type AcqListMembersResponse,
95
+ type ListCompanyIdParams,
96
+ type AcqListCompanyResponse,
97
+ type CompanyIdParams,
98
+ type ContactIdParams,
99
+ type ListCompaniesQuery,
100
+ type ListContactsQuery,
101
+ type CreateCompanyRequest,
102
+ type UpdateCompanyRequest,
103
+ type CreateContactRequest,
104
+ type UpdateContactRequest,
105
+ type AcqCompanyResponse,
106
+ type AcqCompanyListResponse,
107
+ type AcqContactResponse,
108
+ type AcqContactListResponse,
109
+ type AcqCompanyStatus,
110
+ type AcqContactStatus,
111
+ type AcqEmailValid,
112
+ type DealIdParams,
113
+ type DealTaskIdParams,
114
+ type ListDealsQuery,
115
+ type ListDealTasksDueQuery,
116
+ type CreateDealNoteRequest,
117
+ type CreateDealTaskRequest,
118
+ type TransitionItemRequest,
119
+ type TransitionDealStateRequest,
120
+ type ExecuteActionParams,
121
+ type ExecuteActionRequest,
122
+ type DealListResponse,
123
+ type DealDetailResponse,
124
+ type DealNoteResponse,
125
+ type DealNoteListResponse,
126
+ type DealTaskResponse,
127
+ type DealTaskListResponse,
128
+ type ListStatus,
129
+ type ScrapingConfig,
130
+ type IcpRubric,
131
+ type PipelineStage,
132
+ type PipelineConfig,
133
+ type ProcessingStageStatus,
134
+ type ListStageCountsInput,
135
+ type ListTelemetryInput,
136
+ type ListIdParams,
137
+ type CreateListRequest,
138
+ type UpdateListRequest,
139
+ type UpdateListStatusRequest,
140
+ type UpdateListConfigRequest,
141
+ type AddCompaniesToListRequest,
142
+ type RemoveCompaniesFromListRequest,
143
+ type AddContactsToListRequest,
144
+ type RecordListExecutionRequest,
145
+ type AcqListResponse,
146
+ type AcqListListResponse,
147
+ type ListTelemetryResponse,
148
+ type ListTelemetryListResponse,
149
+ type ListExecutionSummaryInput,
150
+ type ListExecutionsResponse,
151
+ type ListStageProgress,
152
+ type ListProgress
153
+ } from './api-schemas'
@@ -341,9 +341,10 @@ export interface AcqDealTask {
341
341
  // ─── Progress / Telemetry Types ──────────────────────────────────────────────
342
342
 
343
343
  /**
344
- * Live-scan aggregate telemetry for a single list, computed on demand from
345
- * the list junction tables and current contact deliverability state.
346
- */
344
+ * Live-scan aggregate telemetry for a single list, computed on demand from
345
+ * the list junction tables and current contact deliverability state.
346
+ * `stageCounts` are attempted counts from list-row processing_state.
347
+ */
347
348
  export interface ListTelemetry {
348
349
  listId: string
349
350
  totalCompanies: number
@@ -18,10 +18,10 @@ import type {
18
18
  ScrapingConfig,
19
19
  IcpRubric,
20
20
  PipelineConfig,
21
- ListTelemetry,
22
- DealDetail
23
- } from '../../../business/acquisition/types'
24
- import type { ListProgress } from '../../../business/acquisition/api-schemas'
21
+ ListTelemetry,
22
+ DealDetail
23
+ } from '../../../business/acquisition/types'
24
+ import type { ListProgress, ProcessingStageStatus } from '../../../business/acquisition/api-schemas'
25
25
 
26
26
  export type {
27
27
  AcqList,
@@ -32,8 +32,9 @@ export type {
32
32
  ListStatus,
33
33
  ScrapingConfig,
34
34
  IcpRubric,
35
- PipelineConfig,
36
- ListTelemetry,
35
+ PipelineConfig,
36
+ ProcessingStageStatus,
37
+ ListTelemetry,
37
38
  DealDetail,
38
39
  ListProgress
39
40
  }
@@ -501,21 +502,23 @@ export interface UpdateListConfigParams {
501
502
  pipelineConfig?: PipelineConfig
502
503
  }
503
504
 
504
- export interface UpdateCompanyStageParams {
505
- organizationId: string
506
- listId: string
507
- companyId: string
508
- stage: string
509
- executionId?: string
510
- }
511
-
512
- export interface UpdateContactStageParams {
513
- organizationId: string
514
- listId: string
515
- contactId: string
516
- stage: string
517
- executionId?: string
518
- }
505
+ export interface UpdateCompanyStageParams {
506
+ organizationId: string
507
+ listId: string
508
+ companyId: string
509
+ stage: string
510
+ status?: ProcessingStageStatus
511
+ executionId?: string
512
+ }
513
+
514
+ export interface UpdateContactStageParams {
515
+ organizationId: string
516
+ listId: string
517
+ contactId: string
518
+ stage: string
519
+ status?: ProcessingStageStatus
520
+ executionId?: string
521
+ }
519
522
 
520
523
  export interface AddCompaniesToListParams {
521
524
  organizationId: string