@elevasis/core 0.12.0 → 0.14.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 (50) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +9 -2
  3. package/dist/organization-model/index.d.ts +1 -1
  4. package/dist/organization-model/index.js +9 -2
  5. package/dist/test-utils/index.d.ts +480 -389
  6. package/dist/test-utils/index.js +28 -2
  7. package/package.json +1 -1
  8. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +2324 -0
  9. package/src/auth/multi-tenancy/credentials/__tests__/encryption.test.ts +217 -216
  10. package/src/auth/multi-tenancy/credentials/server/encryption.ts +5 -19
  11. package/src/auth/multi-tenancy/credentials/server/kek-loader.ts +3 -13
  12. package/src/auth/multi-tenancy/permissions.ts +12 -5
  13. package/src/business/acquisition/activity-events.test.ts +250 -0
  14. package/src/business/acquisition/activity-events.ts +84 -0
  15. package/src/business/acquisition/api-schemas.test.ts +1180 -0
  16. package/src/business/acquisition/api-schemas.ts +456 -235
  17. package/src/business/acquisition/crm-state-actions.test.ts +160 -0
  18. package/src/business/acquisition/derive-actions.test.ts +518 -0
  19. package/src/business/acquisition/derive-actions.ts +103 -0
  20. package/src/business/acquisition/index.ts +51 -11
  21. package/src/business/acquisition/stateful.ts +30 -0
  22. package/src/business/acquisition/types.ts +44 -77
  23. package/src/execution/engine/index.ts +4 -1
  24. package/src/execution/engine/tools/integration/server/adapters/apify/__tests__/apify-run-actor.integration.test.ts +1 -2
  25. package/src/execution/engine/tools/integration/server/adapters/attio/__tests__/attio-crud.integration.test.ts +363 -361
  26. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/get-record/index.test.ts +162 -186
  27. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/list-records/index.test.ts +316 -338
  28. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-adapter.ts +204 -210
  29. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.test.ts +88 -0
  30. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.ts +141 -134
  31. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/utils/types.ts +76 -75
  32. package/src/execution/engine/tools/integration/service.test.ts +34 -9
  33. package/src/execution/engine/tools/integration/service.ts +6 -3
  34. package/src/execution/engine/tools/lead-service-types.ts +90 -30
  35. package/src/execution/engine/tools/platform/acquisition/types.ts +266 -260
  36. package/src/execution/engine/tools/registry.ts +5 -4
  37. package/src/execution/engine/tools/tool-maps.ts +43 -21
  38. package/src/execution/engine/workflow/types.ts +11 -0
  39. package/src/organization-model/contracts.ts +4 -4
  40. package/src/organization-model/domains/navigation.ts +62 -62
  41. package/src/organization-model/domains/sales.ts +272 -0
  42. package/src/organization-model/organization-graph.mdx +2 -2
  43. package/src/organization-model/published.ts +21 -21
  44. package/src/organization-model/resolve.ts +21 -8
  45. package/src/platform/constants/versions.ts +1 -1
  46. package/src/reference/_generated/contracts.md +2324 -0
  47. package/src/scaffold-registry/index.ts +10 -9
  48. package/src/scaffold-registry/schema.ts +68 -62
  49. package/src/supabase/database.types.ts +2958 -2884
  50. package/src/test-utils/rls/RLSTestContext.ts +585 -553
@@ -14,11 +14,14 @@ import type {
14
14
  AcqContact,
15
15
  AcqDealTask,
16
16
  AcqDealTaskKind,
17
- CompanyListStage,
18
- ContactListStage,
19
- ListConfig,
20
- ListTelemetry
17
+ ListStatus,
18
+ ScrapingConfig,
19
+ IcpRubric,
20
+ PipelineConfig,
21
+ ListTelemetry,
22
+ DealDetail
21
23
  } from '../../../business/acquisition/types'
24
+ import type { ListProgress } from '../../../business/acquisition/api-schemas'
22
25
 
23
26
  export type {
24
27
  AcqList,
@@ -26,10 +29,13 @@ export type {
26
29
  AcqContact,
27
30
  AcqDealTask,
28
31
  AcqDealTaskKind,
29
- CompanyListStage,
30
- ContactListStage,
31
- ListConfig,
32
- ListTelemetry
32
+ ListStatus,
33
+ ScrapingConfig,
34
+ IcpRubric,
35
+ PipelineConfig,
36
+ ListTelemetry,
37
+ DealDetail,
38
+ ListProgress
33
39
  }
34
40
 
35
41
  // Pagination types
@@ -53,17 +59,24 @@ export interface CreateListParams {
53
59
  type?: string
54
60
  batchIds?: string[]
55
61
  instantlyCampaignId?: string
56
- status?: string
62
+ status?: ListStatus
57
63
  metadata?: Record<string, unknown>
58
- config?: ListConfig
64
+ scrapingConfig?: ScrapingConfig
65
+ icp?: IcpRubric
66
+ pipelineConfig?: PipelineConfig
59
67
  }
60
68
 
61
- export interface UpdateListParams {
62
- name?: string
63
- description?: string
64
- status?: string
65
- batchIds?: string[]
66
- }
69
+ export interface UpdateListParams {
70
+ name?: string
71
+ description?: string
72
+ batchIds?: string[]
73
+ }
74
+
75
+ export interface UpdateListStatusParams {
76
+ organizationId: string
77
+ listId: string
78
+ status: ListStatus
79
+ }
67
80
 
68
81
  // Company params
69
82
  export interface CreateCompanyParams {
@@ -99,6 +112,12 @@ export interface UpdateCompanyParams {
99
112
  batchId?: string
100
113
  status?: 'active' | 'invalid'
101
114
  verticalResearch?: string | null
115
+ /** Track A: flat qualification score column (null until a scoring rubric is defined) */
116
+ qualificationScore?: number | null
117
+ /** Track A: flat qualification signals jsonb — mirrors the former pipeline_status.qualification shape */
118
+ qualificationSignals?: Record<string, unknown> | null
119
+ /** Track A: key identifying the rubric used for qualification */
120
+ qualificationRubricKey?: string | null
102
121
  }
103
122
 
104
123
  export type UpsertCompanyParams = CreateCompanyParams
@@ -190,7 +209,6 @@ export interface UpdateProposalDataParams {
190
209
  contactEmail: string
191
210
  proposalData: unknown
192
211
  proposalPdfUrl?: string
193
- proposalStatus?: string
194
212
  }
195
213
 
196
214
  export interface MarkProposalSentParams {
@@ -219,10 +237,14 @@ export interface UpdateFeesParams {
219
237
  monthlyFee?: number
220
238
  }
221
239
 
222
- export interface SyncDealStageParams {
240
+ export interface TransitionItemParams {
223
241
  organizationId: string
224
242
  dealId: string
225
- stage: string
243
+ pipelineKey: string
244
+ stageKey: string
245
+ stateKey?: string | null
246
+ reason?: string
247
+ expectedUpdatedAt?: string
226
248
  }
227
249
 
228
250
  export interface SetContactNurtureParams {
@@ -256,7 +278,6 @@ export interface ClearDealFieldsParams {
256
278
  dealId?: string
257
279
  fields: (
258
280
  | 'proposalPdfUrl'
259
- | 'proposalStatus'
260
281
  | 'proposalGeneratedAt'
261
282
  | 'initialFee'
262
283
  | 'monthlyFee'
@@ -323,10 +344,11 @@ export interface AcqDeal {
323
344
  id: string
324
345
  organizationId: string
325
346
  contactEmail: string
326
- cachedStage?: string | null
347
+ pipelineKey: string
348
+ stageKey?: string | null
349
+ stateKey?: string | null
327
350
  discoveryData?: Json | null
328
351
  proposalData?: Json | null
329
- proposalStatus?: string | null
330
352
  proposalSentAt?: string | null
331
353
  proposalPdfUrl?: string | null
332
354
  signatureEnvelopeId?: string | null
@@ -405,6 +427,24 @@ export interface RecordDealActivityParams {
405
427
  payload?: Record<string, unknown>
406
428
  }
407
429
 
430
+ export interface SetDealStateKeyParams {
431
+ organizationId: string
432
+ dealId: string
433
+ stateKey: string
434
+ }
435
+
436
+ export interface TransitionDealParams {
437
+ organizationId: string
438
+ dealId: string
439
+ toStage: string
440
+ toState?: string
441
+ }
442
+
443
+ export interface LoadDealParams {
444
+ organizationId: string
445
+ dealId: string
446
+ }
447
+
408
448
  // Deal analytics types (for /meta status and platform-status workflow)
409
449
 
410
450
  export interface DealStageSummary {
@@ -417,7 +457,7 @@ export interface DealStageSummary {
417
457
  export interface StaleDeal {
418
458
  id: string
419
459
  contactEmail: string
420
- cachedStage: string
460
+ stageKey: string
421
461
  updatedAt: string
422
462
  daysStale: number
423
463
  }
@@ -456,15 +496,16 @@ export interface AddContactsToListResult {
456
496
  export interface UpdateListConfigParams {
457
497
  organizationId: string
458
498
  listId: string
459
- /** Deep-partial patch — any subtree that is present is replaced at that level. */
460
- configPatch: Record<string, unknown>
499
+ scrapingConfig?: ScrapingConfig
500
+ icp?: IcpRubric
501
+ pipelineConfig?: PipelineConfig
461
502
  }
462
503
 
463
504
  export interface UpdateCompanyStageParams {
464
505
  organizationId: string
465
506
  listId: string
466
507
  companyId: string
467
- stage: CompanyListStage
508
+ stage: string
468
509
  executionId?: string
469
510
  }
470
511
 
@@ -472,7 +513,7 @@ export interface UpdateContactStageParams {
472
513
  organizationId: string
473
514
  listId: string
474
515
  contactId: string
475
- stage: ContactListStage
516
+ stage: string
476
517
  executionId?: string
477
518
  }
478
519
 
@@ -622,9 +663,10 @@ export interface ILeadService {
622
663
  getListsTelemetry(organizationId: string): Promise<ListTelemetry[]>
623
664
 
624
665
  /**
625
- * Single live rollup read from list junction stage columns.
666
+ * On-demand progress aggregation: COUNT(*) FILTER over processing_state flags,
667
+ * keyed by the list's pipeline_config.stages[].key (Decision #4 + #7).
626
668
  */
627
- getListProgress(listId: string, organizationId: string): Promise<ListTelemetry | null>
669
+ getListProgress(listId: string, organizationId: string): Promise<ListProgress | null>
628
670
 
629
671
  /**
630
672
  * Advance a company row within a list's explicit stage journey.
@@ -801,7 +843,7 @@ export interface ILeadService {
801
843
 
802
844
  updateFees(params: UpdateFeesParams): Promise<void>
803
845
 
804
- syncDealStage(params: SyncDealStageParams): Promise<void>
846
+ transitionItem(params: TransitionItemParams): Promise<void>
805
847
 
806
848
  setContactNurture(params: SetContactNurtureParams): Promise<void>
807
849
 
@@ -876,6 +918,24 @@ export interface ILeadService {
876
918
  */
877
919
  recordDealActivity(params: RecordDealActivityParams): Promise<void>
878
920
 
921
+ /**
922
+ * Update the state_key on an acq_deals row.
923
+ * @see LeadService.setDealStateKey (apps/api/src/business/acquisition/lead-service.ts)
924
+ */
925
+ setDealStateKey(params: SetDealStateKeyParams): Promise<{ ok: true }>
926
+
927
+ /**
928
+ * Transition a deal to a new stage, resolving pipeline_key automatically.
929
+ * @see LeadService.transitionDeal (apps/api/src/business/acquisition/lead-service.ts)
930
+ */
931
+ transitionDeal(params: TransitionDealParams): Promise<{ deal: AcqDeal }>
932
+
933
+ /**
934
+ * Load a deal with its joined contact and company data.
935
+ * @see LeadService.loadDeal (apps/api/src/business/acquisition/lead-service.ts)
936
+ */
937
+ loadDeal(params: LoadDealParams): Promise<DealDetail | null>
938
+
879
939
  // Social monitoring operations (acq_social_posts table)
880
940
  /**
881
941
  * Bulk upsert social posts (deduplicate by platform + platform_post_id)