@elevasis/core 0.12.0 → 0.13.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/test-utils/index.d.ts +17 -12
- package/dist/test-utils/index.js +19 -0
- package/package.json +1 -1
- package/src/auth/multi-tenancy/credentials/__tests__/encryption.test.ts +217 -216
- package/src/auth/multi-tenancy/credentials/server/encryption.ts +5 -19
- package/src/auth/multi-tenancy/credentials/server/kek-loader.ts +3 -13
- package/src/auth/multi-tenancy/permissions.ts +12 -5
- package/src/business/acquisition/activity-events.ts +142 -0
- package/src/business/acquisition/api-schemas.ts +694 -689
- package/src/business/acquisition/derive-actions.ts +90 -0
- package/src/business/acquisition/index.ts +111 -109
- package/src/execution/engine/index.ts +434 -434
- package/src/execution/engine/tools/integration/server/adapters/apify/__tests__/apify-run-actor.integration.test.ts +1 -2
- package/src/execution/engine/tools/integration/server/adapters/attio/__tests__/attio-crud.integration.test.ts +0 -1
- package/src/execution/engine/tools/lead-service-types.ts +882 -879
- package/src/execution/engine/tools/registry.ts +699 -700
- package/src/execution/engine/tools/tool-maps.ts +777 -780
- package/src/organization-model/organization-graph.mdx +2 -2
- package/src/platform/constants/versions.ts +1 -1
- package/src/scaffold-registry/index.ts +10 -9
- package/src/scaffold-registry/schema.ts +68 -62
- package/src/supabase/database.types.ts +9 -7
- package/src/test-utils/rls/RLSTestContext.ts +585 -553
|
@@ -1,885 +1,888 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lead Service Types
|
|
3
|
-
* CRUD operation types for the acquisition platform (lists, companies, contacts, deals)
|
|
4
|
-
*
|
|
5
|
-
* Implementation: apps/api/src/acquisition/lead-service.ts (LeadService class)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { Json } from '../../../supabase'
|
|
9
|
-
|
|
10
|
-
// Re-export acquisition domain types from the authoritative source
|
|
11
|
-
import type {
|
|
12
|
-
AcqList,
|
|
13
|
-
AcqCompany,
|
|
14
|
-
AcqContact,
|
|
15
|
-
AcqDealTask,
|
|
16
|
-
AcqDealTaskKind,
|
|
17
|
-
CompanyListStage,
|
|
18
|
-
ContactListStage,
|
|
19
|
-
ListConfig,
|
|
20
|
-
ListTelemetry
|
|
21
|
-
} from '../../../business/acquisition/types'
|
|
22
|
-
|
|
23
|
-
export type {
|
|
24
|
-
AcqList,
|
|
25
|
-
AcqCompany,
|
|
26
|
-
AcqContact,
|
|
27
|
-
AcqDealTask,
|
|
28
|
-
AcqDealTaskKind,
|
|
29
|
-
CompanyListStage,
|
|
30
|
-
ContactListStage,
|
|
31
|
-
ListConfig,
|
|
32
|
-
ListTelemetry
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Pagination types
|
|
36
|
-
export interface PaginationParams {
|
|
37
|
-
limit: number
|
|
38
|
-
offset: number
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface PaginatedResult<T> {
|
|
42
|
-
data: T[]
|
|
43
|
-
total: number
|
|
44
|
-
limit: number
|
|
45
|
-
offset: number
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// List params
|
|
49
|
-
export interface CreateListParams {
|
|
50
|
-
organizationId: string
|
|
51
|
-
name: string
|
|
52
|
-
description?: string
|
|
53
|
-
type?: string
|
|
54
|
-
batchIds?: string[]
|
|
55
|
-
instantlyCampaignId?: string
|
|
56
|
-
status?: string
|
|
57
|
-
metadata?: Record<string, unknown>
|
|
58
|
-
config?: ListConfig
|
|
59
|
-
}
|
|
60
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Lead Service Types
|
|
3
|
+
* CRUD operation types for the acquisition platform (lists, companies, contacts, deals)
|
|
4
|
+
*
|
|
5
|
+
* Implementation: apps/api/src/acquisition/lead-service.ts (LeadService class)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Json } from '../../../supabase'
|
|
9
|
+
|
|
10
|
+
// Re-export acquisition domain types from the authoritative source
|
|
11
|
+
import type {
|
|
12
|
+
AcqList,
|
|
13
|
+
AcqCompany,
|
|
14
|
+
AcqContact,
|
|
15
|
+
AcqDealTask,
|
|
16
|
+
AcqDealTaskKind,
|
|
17
|
+
CompanyListStage,
|
|
18
|
+
ContactListStage,
|
|
19
|
+
ListConfig,
|
|
20
|
+
ListTelemetry
|
|
21
|
+
} from '../../../business/acquisition/types'
|
|
22
|
+
|
|
23
|
+
export type {
|
|
24
|
+
AcqList,
|
|
25
|
+
AcqCompany,
|
|
26
|
+
AcqContact,
|
|
27
|
+
AcqDealTask,
|
|
28
|
+
AcqDealTaskKind,
|
|
29
|
+
CompanyListStage,
|
|
30
|
+
ContactListStage,
|
|
31
|
+
ListConfig,
|
|
32
|
+
ListTelemetry
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Pagination types
|
|
36
|
+
export interface PaginationParams {
|
|
37
|
+
limit: number
|
|
38
|
+
offset: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface PaginatedResult<T> {
|
|
42
|
+
data: T[]
|
|
43
|
+
total: number
|
|
44
|
+
limit: number
|
|
45
|
+
offset: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// List params
|
|
49
|
+
export interface CreateListParams {
|
|
50
|
+
organizationId: string
|
|
51
|
+
name: string
|
|
52
|
+
description?: string
|
|
53
|
+
type?: string
|
|
54
|
+
batchIds?: string[]
|
|
55
|
+
instantlyCampaignId?: string
|
|
56
|
+
status?: string
|
|
57
|
+
metadata?: Record<string, unknown>
|
|
58
|
+
config?: ListConfig
|
|
59
|
+
}
|
|
60
|
+
|
|
61
61
|
export interface UpdateListParams {
|
|
62
62
|
name?: string
|
|
63
63
|
description?: string
|
|
64
64
|
status?: string
|
|
65
65
|
batchIds?: string[]
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
// Company params
|
|
69
|
-
export interface CreateCompanyParams {
|
|
70
|
-
organizationId: string
|
|
71
|
-
name: string
|
|
72
|
-
domain?: string
|
|
73
|
-
linkedinUrl?: string
|
|
74
|
-
website?: string
|
|
75
|
-
numEmployees?: number
|
|
76
|
-
foundedYear?: number
|
|
77
|
-
locationCity?: string
|
|
78
|
-
locationState?: string
|
|
79
|
-
category?: string
|
|
80
|
-
source?: string
|
|
81
|
-
batchId?: string
|
|
82
|
-
verticalResearch?: string
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface UpdateCompanyParams {
|
|
86
|
-
name?: string
|
|
87
|
-
domain?: string
|
|
88
|
-
linkedinUrl?: string
|
|
89
|
-
website?: string
|
|
90
|
-
numEmployees?: number
|
|
91
|
-
foundedYear?: number
|
|
92
|
-
locationCity?: string
|
|
93
|
-
locationState?: string
|
|
94
|
-
category?: string
|
|
95
|
-
segment?: string
|
|
96
|
-
pipelineStatus?: Record<string, unknown>
|
|
97
|
-
enrichmentData?: Record<string, unknown>
|
|
98
|
-
source?: string
|
|
99
|
-
batchId?: string
|
|
100
|
-
status?: 'active' | 'invalid'
|
|
101
|
-
verticalResearch?: string | null
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export type UpsertCompanyParams = CreateCompanyParams
|
|
105
|
-
// Upsert by domain - uses same fields as create
|
|
106
|
-
|
|
107
|
-
export interface CompanyFilters {
|
|
108
|
-
listId?: string // Filter to companies in a specific list (via acq_list_companies)
|
|
109
|
-
search?: string
|
|
110
|
-
domain?: string
|
|
111
|
-
website?: string
|
|
112
|
-
segment?: string
|
|
113
|
-
category?: string
|
|
114
|
-
pipelineStatus?: Record<string, unknown>
|
|
115
|
-
/** Exclude companies whose pipeline_status contains this value (PostgREST NOT contains) */
|
|
116
|
-
pipelineStatusNot?: Record<string, unknown>
|
|
117
|
-
batchId?: string
|
|
118
|
-
status?: 'active' | 'invalid'
|
|
119
|
-
includeAll?: boolean
|
|
120
|
-
excludeColumns?: Array<'enrichmentData' | 'pipelineStatus'>
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Contact params
|
|
124
|
-
export interface CreateContactParams {
|
|
125
|
-
organizationId: string
|
|
126
|
-
email: string
|
|
127
|
-
companyId?: string
|
|
128
|
-
firstName?: string
|
|
129
|
-
lastName?: string
|
|
130
|
-
linkedinUrl?: string
|
|
131
|
-
title?: string
|
|
132
|
-
source?: string
|
|
133
|
-
sourceId?: string
|
|
134
|
-
batchId?: string
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface UpdateContactParams {
|
|
138
|
-
companyId?: string
|
|
139
|
-
emailValid?: 'VALID' | 'INVALID' | 'RISKY' | 'UNKNOWN'
|
|
140
|
-
firstName?: string
|
|
141
|
-
lastName?: string
|
|
142
|
-
linkedinUrl?: string
|
|
143
|
-
title?: string
|
|
144
|
-
headline?: string
|
|
145
|
-
filterReason?: string
|
|
146
|
-
openingLine?: string
|
|
147
|
-
pipelineStatus?: Record<string, unknown>
|
|
148
|
-
enrichmentData?: Record<string, unknown>
|
|
149
|
-
status?: 'active' | 'invalid'
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export type UpsertContactParams = CreateContactParams
|
|
153
|
-
// Upsert by email - uses same fields as create
|
|
154
|
-
|
|
155
|
-
export interface ContactFilters {
|
|
156
|
-
listId?: string // Filter to contacts in a specific list (via acq_list_members)
|
|
157
|
-
search?: string
|
|
158
|
-
openingLineIsNull?: boolean // Filter to contacts without personalization
|
|
159
|
-
pipelineStatus?: Record<string, unknown>
|
|
160
|
-
batchId?: string
|
|
161
|
-
contactStatus?: 'active' | 'invalid' // Filter by contact status (soft-delete flag)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Deal params (for acq_deals table)
|
|
165
|
-
export interface UpsertDealParams {
|
|
166
|
-
organizationId: string
|
|
167
|
-
/** Contact email — dedupe key together with organization_id */
|
|
168
|
-
contactEmail: string
|
|
169
|
-
/** Optional contact ID for foreign key join */
|
|
170
|
-
contactId?: string
|
|
171
|
-
/** Campaign list that generated this deal (FK to acq_lists) */
|
|
172
|
-
sourceListId?: string
|
|
173
|
-
/** Deal origin: 'instantly', 'referral', 'inbound', 'manual' */
|
|
174
|
-
sourceType?: 'instantly' | 'referral' | 'inbound' | 'manual'
|
|
175
|
-
/** Optional discovery data JSONB to set on upsert */
|
|
176
|
-
discoveryData?: unknown
|
|
177
|
-
/** Optional proposal data JSONB to set on upsert */
|
|
178
|
-
proposalData?: unknown
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export interface UpdateDiscoveryDataParams {
|
|
182
|
-
organizationId: string
|
|
183
|
-
contactEmail: string
|
|
184
|
-
discoveryData: unknown
|
|
185
|
-
submittedBy?: string
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export interface UpdateProposalDataParams {
|
|
189
|
-
organizationId: string
|
|
190
|
-
contactEmail: string
|
|
191
|
-
proposalData: unknown
|
|
192
|
-
proposalPdfUrl?: string
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
| '
|
|
262
|
-
| '
|
|
263
|
-
| '
|
|
264
|
-
| '
|
|
265
|
-
| '
|
|
266
|
-
| '
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
67
|
+
|
|
68
|
+
// Company params
|
|
69
|
+
export interface CreateCompanyParams {
|
|
70
|
+
organizationId: string
|
|
71
|
+
name: string
|
|
72
|
+
domain?: string
|
|
73
|
+
linkedinUrl?: string
|
|
74
|
+
website?: string
|
|
75
|
+
numEmployees?: number
|
|
76
|
+
foundedYear?: number
|
|
77
|
+
locationCity?: string
|
|
78
|
+
locationState?: string
|
|
79
|
+
category?: string
|
|
80
|
+
source?: string
|
|
81
|
+
batchId?: string
|
|
82
|
+
verticalResearch?: string
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface UpdateCompanyParams {
|
|
86
|
+
name?: string
|
|
87
|
+
domain?: string
|
|
88
|
+
linkedinUrl?: string
|
|
89
|
+
website?: string
|
|
90
|
+
numEmployees?: number
|
|
91
|
+
foundedYear?: number
|
|
92
|
+
locationCity?: string
|
|
93
|
+
locationState?: string
|
|
94
|
+
category?: string
|
|
95
|
+
segment?: string
|
|
96
|
+
pipelineStatus?: Record<string, unknown>
|
|
97
|
+
enrichmentData?: Record<string, unknown>
|
|
98
|
+
source?: string
|
|
99
|
+
batchId?: string
|
|
100
|
+
status?: 'active' | 'invalid'
|
|
101
|
+
verticalResearch?: string | null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type UpsertCompanyParams = CreateCompanyParams
|
|
105
|
+
// Upsert by domain - uses same fields as create
|
|
106
|
+
|
|
107
|
+
export interface CompanyFilters {
|
|
108
|
+
listId?: string // Filter to companies in a specific list (via acq_list_companies)
|
|
109
|
+
search?: string
|
|
110
|
+
domain?: string
|
|
111
|
+
website?: string
|
|
112
|
+
segment?: string
|
|
113
|
+
category?: string
|
|
114
|
+
pipelineStatus?: Record<string, unknown>
|
|
115
|
+
/** Exclude companies whose pipeline_status contains this value (PostgREST NOT contains) */
|
|
116
|
+
pipelineStatusNot?: Record<string, unknown>
|
|
117
|
+
batchId?: string
|
|
118
|
+
status?: 'active' | 'invalid'
|
|
119
|
+
includeAll?: boolean
|
|
120
|
+
excludeColumns?: Array<'enrichmentData' | 'pipelineStatus'>
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Contact params
|
|
124
|
+
export interface CreateContactParams {
|
|
125
|
+
organizationId: string
|
|
126
|
+
email: string
|
|
127
|
+
companyId?: string
|
|
128
|
+
firstName?: string
|
|
129
|
+
lastName?: string
|
|
130
|
+
linkedinUrl?: string
|
|
131
|
+
title?: string
|
|
132
|
+
source?: string
|
|
133
|
+
sourceId?: string
|
|
134
|
+
batchId?: string
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface UpdateContactParams {
|
|
138
|
+
companyId?: string
|
|
139
|
+
emailValid?: 'VALID' | 'INVALID' | 'RISKY' | 'UNKNOWN'
|
|
140
|
+
firstName?: string
|
|
141
|
+
lastName?: string
|
|
142
|
+
linkedinUrl?: string
|
|
143
|
+
title?: string
|
|
144
|
+
headline?: string
|
|
145
|
+
filterReason?: string
|
|
146
|
+
openingLine?: string
|
|
147
|
+
pipelineStatus?: Record<string, unknown>
|
|
148
|
+
enrichmentData?: Record<string, unknown>
|
|
149
|
+
status?: 'active' | 'invalid'
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export type UpsertContactParams = CreateContactParams
|
|
153
|
+
// Upsert by email - uses same fields as create
|
|
154
|
+
|
|
155
|
+
export interface ContactFilters {
|
|
156
|
+
listId?: string // Filter to contacts in a specific list (via acq_list_members)
|
|
157
|
+
search?: string
|
|
158
|
+
openingLineIsNull?: boolean // Filter to contacts without personalization
|
|
159
|
+
pipelineStatus?: Record<string, unknown>
|
|
160
|
+
batchId?: string
|
|
161
|
+
contactStatus?: 'active' | 'invalid' // Filter by contact status (soft-delete flag)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Deal params (for acq_deals table)
|
|
165
|
+
export interface UpsertDealParams {
|
|
166
|
+
organizationId: string
|
|
167
|
+
/** Contact email — dedupe key together with organization_id */
|
|
168
|
+
contactEmail: string
|
|
169
|
+
/** Optional contact ID for foreign key join */
|
|
170
|
+
contactId?: string
|
|
171
|
+
/** Campaign list that generated this deal (FK to acq_lists) */
|
|
172
|
+
sourceListId?: string
|
|
173
|
+
/** Deal origin: 'instantly', 'referral', 'inbound', 'manual' */
|
|
174
|
+
sourceType?: 'instantly' | 'referral' | 'inbound' | 'manual'
|
|
175
|
+
/** Optional discovery data JSONB to set on upsert */
|
|
176
|
+
discoveryData?: unknown
|
|
177
|
+
/** Optional proposal data JSONB to set on upsert */
|
|
178
|
+
proposalData?: unknown
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface UpdateDiscoveryDataParams {
|
|
182
|
+
organizationId: string
|
|
183
|
+
contactEmail: string
|
|
184
|
+
discoveryData: unknown
|
|
185
|
+
submittedBy?: string
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface UpdateProposalDataParams {
|
|
189
|
+
organizationId: string
|
|
190
|
+
contactEmail: string
|
|
191
|
+
proposalData: unknown
|
|
192
|
+
proposalPdfUrl?: string
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export interface MarkProposalSentParams {
|
|
196
|
+
organizationId: string
|
|
197
|
+
contactEmail: string
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export interface MarkProposalReviewedParams {
|
|
201
|
+
organizationId: string
|
|
202
|
+
contactEmail: string
|
|
203
|
+
reviewedBy: string
|
|
204
|
+
proposalData?: unknown
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface UpdateCloseLostReasonParams {
|
|
208
|
+
organizationId: string
|
|
209
|
+
dealId: string
|
|
210
|
+
reason: string
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export interface UpdateFeesParams {
|
|
214
|
+
organizationId: string
|
|
215
|
+
contactEmail?: string
|
|
216
|
+
dealId?: string
|
|
217
|
+
initialFee?: number
|
|
218
|
+
monthlyFee?: number
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface TransitionItemParams {
|
|
222
|
+
organizationId: string
|
|
223
|
+
dealId: string
|
|
224
|
+
pipelineKey: string
|
|
225
|
+
stageKey: string
|
|
226
|
+
stateKey?: string | null
|
|
227
|
+
reason?: string
|
|
228
|
+
expectedUpdatedAt?: string
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface SetContactNurtureParams {
|
|
232
|
+
organizationId: string
|
|
233
|
+
contactEmail: string
|
|
234
|
+
nurture?: boolean
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface DeactivateContactsByCompanyParams {
|
|
238
|
+
organizationId: string
|
|
239
|
+
companyId: string
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface DeactivateContactsByCompanyResult {
|
|
243
|
+
deactivated: number
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface CancelSchedulesAndHitlByEmailParams {
|
|
247
|
+
organizationId: string
|
|
248
|
+
email: string
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface CancelHitlByDealIdParams {
|
|
252
|
+
organizationId: string
|
|
253
|
+
dealId: string
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface ClearDealFieldsParams {
|
|
257
|
+
organizationId: string
|
|
258
|
+
contactEmail?: string
|
|
259
|
+
dealId?: string
|
|
260
|
+
fields: (
|
|
261
|
+
| 'proposalPdfUrl'
|
|
262
|
+
| 'proposalGeneratedAt'
|
|
263
|
+
| 'initialFee'
|
|
264
|
+
| 'monthlyFee'
|
|
265
|
+
| 'closedLostReason'
|
|
266
|
+
| 'closedLostAt'
|
|
267
|
+
| 'discoveryData'
|
|
268
|
+
| 'discoverySubmittedAt'
|
|
269
|
+
)[]
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export interface DeleteDealParams {
|
|
273
|
+
organizationId: string
|
|
274
|
+
dealId: string
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface GetDealByIdParams {
|
|
278
|
+
dealId: string
|
|
279
|
+
organizationId: string
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export interface GetContactByIdParams {
|
|
283
|
+
contactId: string
|
|
284
|
+
organizationId: string
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface GetCompanyByIdParams {
|
|
288
|
+
companyId: string
|
|
289
|
+
organizationId: string
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Social monitoring params (acq_social_posts table)
|
|
293
|
+
export interface UpsertSocialPostParams {
|
|
294
|
+
organizationId: string
|
|
295
|
+
platform: string
|
|
296
|
+
platformPostId: string
|
|
297
|
+
authorName: string
|
|
298
|
+
authorUrl?: string | null
|
|
299
|
+
postTitle: string
|
|
300
|
+
postText: string
|
|
301
|
+
postUrl: string
|
|
302
|
+
engagementCount?: number
|
|
303
|
+
commentsCount?: number
|
|
304
|
+
postedAt: string
|
|
305
|
+
metadata?: Record<string, unknown>
|
|
306
|
+
relevanceScore?: number
|
|
307
|
+
matchedKeywords?: string[]
|
|
308
|
+
matchedQuery?: string | null
|
|
309
|
+
initialDraft?: string | null
|
|
310
|
+
finalResponse?: string | null
|
|
311
|
+
sourceCategory?: string | null
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface UpsertSocialPostsParams {
|
|
315
|
+
organizationId: string
|
|
316
|
+
posts: Omit<UpsertSocialPostParams, 'organizationId'>[]
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface UpsertSocialPostsResult {
|
|
320
|
+
inserted: number
|
|
321
|
+
duplicatesSkipped: number
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export interface AcqDeal {
|
|
325
|
+
id: string
|
|
326
|
+
organizationId: string
|
|
327
|
+
contactEmail: string
|
|
328
|
+
pipelineKey: string
|
|
329
|
+
stageKey?: string | null
|
|
330
|
+
stateKey?: string | null
|
|
331
|
+
discoveryData?: Json | null
|
|
332
|
+
proposalData?: Json | null
|
|
333
|
+
proposalSentAt?: string | null
|
|
334
|
+
proposalPdfUrl?: string | null
|
|
335
|
+
signatureEnvelopeId?: string | null
|
|
336
|
+
sourceListId?: string | null
|
|
337
|
+
sourceType?: string | null
|
|
338
|
+
activityLog: DealActivityEntry[]
|
|
339
|
+
createdAt: Date
|
|
340
|
+
updatedAt: Date
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface DealActivityEntry {
|
|
344
|
+
type: string
|
|
345
|
+
title: string
|
|
346
|
+
description?: string
|
|
347
|
+
payload?: Record<string, unknown>
|
|
348
|
+
occurredAt: string
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export interface AcqDealNote {
|
|
352
|
+
id: string
|
|
353
|
+
dealId: string
|
|
354
|
+
organizationId: string
|
|
355
|
+
authorUserId: string | null
|
|
356
|
+
body: string
|
|
357
|
+
createdAt: string
|
|
358
|
+
updatedAt: string
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export interface CreateDealNoteParams {
|
|
362
|
+
organizationId: string
|
|
363
|
+
dealId: string
|
|
364
|
+
body: string
|
|
365
|
+
authorUserId?: string
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface ListDealNotesParams {
|
|
369
|
+
organizationId: string
|
|
370
|
+
dealId: string
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface CreateDealTaskParams {
|
|
374
|
+
organizationId: string
|
|
375
|
+
dealId: string
|
|
376
|
+
title: string
|
|
377
|
+
description?: string | null
|
|
378
|
+
kind?: AcqDealTaskKind
|
|
379
|
+
dueAt?: string | null
|
|
380
|
+
assigneeUserId?: string | null
|
|
381
|
+
createdByUserId?: string | null
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface ListDealTasksParams {
|
|
385
|
+
organizationId: string
|
|
386
|
+
dealId: string
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export interface ListDealTasksDueParams {
|
|
390
|
+
organizationId: string
|
|
391
|
+
assigneeUserId?: string | null
|
|
392
|
+
/** Window filter: 'overdue' = past due, 'today' = due today only, 'today_and_overdue' (default) = both, 'upcoming' = future */
|
|
393
|
+
window?: 'overdue' | 'today' | 'today_and_overdue' | 'upcoming'
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface CompleteDealTaskParams {
|
|
397
|
+
organizationId: string
|
|
398
|
+
taskId: string
|
|
399
|
+
completedByUserId: string | null
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export interface RecordDealActivityParams {
|
|
403
|
+
organizationId: string
|
|
404
|
+
dealId: string
|
|
405
|
+
type: string
|
|
406
|
+
title: string
|
|
407
|
+
description?: string
|
|
408
|
+
payload?: Record<string, unknown>
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// Deal analytics types (for /meta status and platform-status workflow)
|
|
412
|
+
|
|
413
|
+
export interface DealStageSummary {
|
|
414
|
+
stage: string
|
|
415
|
+
count: number
|
|
416
|
+
oldestUpdatedAt: string | null
|
|
417
|
+
newestUpdatedAt: string | null
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export interface StaleDeal {
|
|
421
|
+
id: string
|
|
422
|
+
contactEmail: string
|
|
423
|
+
stageKey: string
|
|
424
|
+
updatedAt: string
|
|
425
|
+
daysStale: number
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export interface DealPipelineAnalytics {
|
|
429
|
+
totalDeals: number
|
|
430
|
+
stageSummary: DealStageSummary[]
|
|
431
|
+
staleDeals: StaleDeal[]
|
|
432
|
+
recentActivity: AcqDeal[]
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
export interface DealAnalyticsParams {
|
|
436
|
+
organizationId: string
|
|
437
|
+
recentLimit?: number
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export interface DealFilters {
|
|
441
|
+
stage?: string
|
|
442
|
+
search?: string
|
|
443
|
+
limit?: number
|
|
444
|
+
offset?: number
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export interface AddContactsToListParams {
|
|
448
|
+
organizationId: string
|
|
449
|
+
listId: string
|
|
450
|
+
contactIds: string[]
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export interface AddContactsToListResult {
|
|
454
|
+
added: number
|
|
455
|
+
alreadyExisted: number
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// List config/progress/executions params
|
|
459
|
+
export interface UpdateListConfigParams {
|
|
460
|
+
organizationId: string
|
|
461
|
+
listId: string
|
|
462
|
+
/** Deep-partial patch — any subtree that is present is replaced at that level. */
|
|
463
|
+
configPatch: Record<string, unknown>
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export interface UpdateCompanyStageParams {
|
|
467
|
+
organizationId: string
|
|
468
|
+
listId: string
|
|
469
|
+
companyId: string
|
|
470
|
+
stage: CompanyListStage
|
|
471
|
+
executionId?: string
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export interface UpdateContactStageParams {
|
|
475
|
+
organizationId: string
|
|
476
|
+
listId: string
|
|
477
|
+
contactId: string
|
|
478
|
+
stage: ContactListStage
|
|
479
|
+
executionId?: string
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
export interface AddCompaniesToListParams {
|
|
483
|
+
organizationId: string
|
|
484
|
+
listId: string
|
|
485
|
+
companyIds: string[]
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export interface AddCompaniesToListResult {
|
|
489
|
+
added: number
|
|
490
|
+
alreadyExisted: number
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
export interface RemoveCompaniesFromListParams {
|
|
494
|
+
organizationId: string
|
|
495
|
+
listId: string
|
|
496
|
+
companyIds: string[]
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export interface RemoveCompaniesFromListResult {
|
|
500
|
+
removed: number
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export interface RecordListExecutionParams {
|
|
504
|
+
organizationId: string
|
|
505
|
+
listId: string
|
|
506
|
+
executionId: string
|
|
507
|
+
configSnapshot?: Record<string, unknown>
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
export interface ListExecutionSummary {
|
|
511
|
+
executionId: string
|
|
512
|
+
resourceId: string
|
|
513
|
+
status: string
|
|
514
|
+
createdAt: string
|
|
515
|
+
completedAt: string | null
|
|
516
|
+
durationMs: number | null
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Bulk import (contacts)
|
|
520
|
+
export interface BulkImportParams {
|
|
521
|
+
organizationId: string
|
|
522
|
+
contacts: CreateContactParams[]
|
|
523
|
+
listId?: string
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export interface BulkImportResult {
|
|
527
|
+
created: number
|
|
528
|
+
updated: number
|
|
529
|
+
errors: Array<{ email: string; error: string }>
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// Bulk import (companies)
|
|
533
|
+
export interface BulkImportCompanyEntry {
|
|
534
|
+
name: string
|
|
535
|
+
domain: string
|
|
536
|
+
website?: string
|
|
537
|
+
locationCity?: string
|
|
538
|
+
locationState?: string
|
|
539
|
+
category?: string
|
|
540
|
+
source?: string
|
|
541
|
+
enrichmentData?: Record<string, unknown>
|
|
542
|
+
pipelineStatus?: Record<string, unknown>
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export interface BulkImportCompaniesParams {
|
|
546
|
+
organizationId: string
|
|
547
|
+
batchId: string
|
|
548
|
+
companies: BulkImportCompanyEntry[]
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
export interface BulkImportCompaniesResult {
|
|
552
|
+
created: number
|
|
553
|
+
skipped: number
|
|
554
|
+
errors: Array<{ companyName: string; error: string }>
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Lead Service interface for acquisition platform tools.
|
|
559
|
+
* Provides CRUD operations for lists, companies, and contacts.
|
|
560
|
+
*
|
|
561
|
+
* Implementation: apps/api/src/acquisition/lead-service.ts (LeadService class)
|
|
562
|
+
*
|
|
563
|
+
* Multi-tenancy: All operations require organizationId for tenant isolation.
|
|
564
|
+
* All queries are filtered by organizationId via RLS policies.
|
|
565
|
+
*/
|
|
566
|
+
export interface ILeadService {
|
|
567
|
+
// List operations
|
|
568
|
+
/**
|
|
569
|
+
* Create a new list
|
|
570
|
+
* @see LeadService.createList (apps/api/src/acquisition/lead-service.ts)
|
|
571
|
+
*/
|
|
572
|
+
createList(params: CreateListParams): Promise<AcqList>
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* Update an existing list
|
|
576
|
+
* @see LeadService.updateList (apps/api/src/acquisition/lead-service.ts)
|
|
577
|
+
*/
|
|
578
|
+
updateList(id: string, params: UpdateListParams): Promise<AcqList>
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Delete a list
|
|
582
|
+
* @see LeadService.deleteList (apps/api/src/acquisition/lead-service.ts)
|
|
583
|
+
*/
|
|
584
|
+
deleteList(id: string, organizationId: string): Promise<void>
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Add contacts to a list (upsert — idempotent on re-runs)
|
|
588
|
+
* @see LeadService.addContactsToList (apps/api/src/business/acquisition/lead-service.ts)
|
|
589
|
+
*/
|
|
590
|
+
addContactsToList(params: AddContactsToListParams): Promise<AddContactsToListResult>
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* List all lists for an organization
|
|
594
|
+
* @see LeadService.listLists (apps/api/src/acquisition/lead-service.ts)
|
|
595
|
+
*/
|
|
596
|
+
listLists(organizationId: string): Promise<AcqList[]>
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Get a single list by ID.
|
|
600
|
+
*/
|
|
601
|
+
getList(id: string, organizationId: string): Promise<AcqList | null>
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Deep-merge patch the jsonb `config` column. Patch keys at any depth
|
|
605
|
+
* replace the corresponding subtree.
|
|
606
|
+
*/
|
|
607
|
+
updateListConfig(params: UpdateListConfigParams): Promise<AcqList>
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Add companies to a list via the acq_list_companies junction.
|
|
611
|
+
* Idempotent on (list_id, company_id).
|
|
612
|
+
*/
|
|
613
|
+
addCompaniesToList(params: AddCompaniesToListParams): Promise<AddCompaniesToListResult>
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Remove companies from a list (delete junction rows only — company rows untouched).
|
|
617
|
+
*/
|
|
618
|
+
removeCompaniesFromList(params: RemoveCompaniesFromListParams): Promise<RemoveCompaniesFromListResult>
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Live org-wide list telemetry — computed on demand from acq_companies
|
|
622
|
+
* and acq_contacts joined through the acq_list_companies / acq_list_members
|
|
623
|
+
* junctions. Replaces the batch-scoped getBatchTelemetry.
|
|
624
|
+
*/
|
|
625
|
+
getListsTelemetry(organizationId: string): Promise<ListTelemetry[]>
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* Single live rollup read from list junction stage columns.
|
|
629
|
+
*/
|
|
630
|
+
getListProgress(listId: string, organizationId: string): Promise<ListTelemetry | null>
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Advance a company row within a list's explicit stage journey.
|
|
634
|
+
*/
|
|
635
|
+
updateCompanyStage(params: UpdateCompanyStageParams): Promise<void>
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Advance a contact row within a list's explicit stage journey.
|
|
639
|
+
*/
|
|
640
|
+
updateContactStage(params: UpdateContactStageParams): Promise<void>
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Per-list execution history — reads via the feature-owned
|
|
644
|
+
* acq_list_executions junction, joined to execution_logs for details.
|
|
645
|
+
*/
|
|
646
|
+
getListExecutions(listId: string, organizationId: string): Promise<ListExecutionSummary[]>
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Write a junction row linking (listId, executionId). Called by the
|
|
650
|
+
* workflow layer at execution start in Step 4. No-op if the row exists.
|
|
651
|
+
*/
|
|
652
|
+
recordListExecution(params: RecordListExecutionParams): Promise<void>
|
|
653
|
+
|
|
654
|
+
// Company operations
|
|
655
|
+
/**
|
|
656
|
+
* Create a new company
|
|
657
|
+
* @see LeadService.createCompany (apps/api/src/acquisition/lead-service.ts)
|
|
658
|
+
*/
|
|
659
|
+
createCompany(params: CreateCompanyParams): Promise<AcqCompany>
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Update an existing company
|
|
663
|
+
* @see LeadService.updateCompany (apps/api/src/acquisition/lead-service.ts)
|
|
664
|
+
*/
|
|
665
|
+
updateCompany(id: string, params: UpdateCompanyParams): Promise<AcqCompany>
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Upsert a company by domain
|
|
669
|
+
* @see LeadService.upsertCompany (apps/api/src/acquisition/lead-service.ts)
|
|
670
|
+
*/
|
|
671
|
+
upsertCompany(params: UpsertCompanyParams): Promise<AcqCompany>
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Get a company by ID
|
|
675
|
+
* @see LeadService.getCompany (apps/api/src/acquisition/lead-service.ts)
|
|
676
|
+
*/
|
|
677
|
+
getCompany(id: string, organizationId: string): Promise<AcqCompany | null>
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* List companies with optional filters
|
|
681
|
+
* @see LeadService.listCompanies (apps/api/src/acquisition/lead-service.ts)
|
|
682
|
+
*/
|
|
683
|
+
listCompanies(organizationId: string, filters: CompanyFilters): Promise<AcqCompany[]>
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Delete a company
|
|
687
|
+
* @see LeadService.deleteCompany (apps/api/src/acquisition/lead-service.ts)
|
|
688
|
+
*/
|
|
689
|
+
deleteCompany(id: string, organizationId: string): Promise<void>
|
|
690
|
+
|
|
691
|
+
// Contact operations
|
|
692
|
+
/**
|
|
693
|
+
* Create a new contact
|
|
694
|
+
* @see LeadService.createContact (apps/api/src/acquisition/lead-service.ts)
|
|
695
|
+
*/
|
|
696
|
+
createContact(params: CreateContactParams): Promise<AcqContact>
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Update an existing contact
|
|
700
|
+
* @see LeadService.updateContact (apps/api/src/acquisition/lead-service.ts)
|
|
701
|
+
*/
|
|
702
|
+
updateContact(id: string, params: UpdateContactParams): Promise<AcqContact>
|
|
703
|
+
|
|
704
|
+
/**
|
|
705
|
+
* Upsert a contact by email
|
|
706
|
+
* @see LeadService.upsertContact (apps/api/src/acquisition/lead-service.ts)
|
|
707
|
+
*/
|
|
708
|
+
upsertContact(params: UpsertContactParams): Promise<AcqContact>
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Get a contact by ID
|
|
712
|
+
* @see LeadService.getContact (apps/api/src/acquisition/lead-service.ts)
|
|
713
|
+
*/
|
|
714
|
+
getContact(id: string, organizationId: string): Promise<AcqContact | null>
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* List contacts with pagination and filters
|
|
718
|
+
* @see LeadService.listContacts (apps/api/src/acquisition/lead-service.ts)
|
|
719
|
+
*/
|
|
720
|
+
listContacts(
|
|
721
|
+
organizationId: string,
|
|
722
|
+
filters: ContactFilters,
|
|
723
|
+
pagination: PaginationParams
|
|
724
|
+
): Promise<PaginatedResult<AcqContact>>
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Delete a contact
|
|
728
|
+
* @see LeadService.deleteContact (apps/api/src/acquisition/lead-service.ts)
|
|
729
|
+
*/
|
|
730
|
+
deleteContact(id: string, organizationId: string): Promise<void>
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Bulk import contacts
|
|
734
|
+
* @see LeadService.bulkImportContacts (apps/api/src/acquisition/lead-service.ts)
|
|
735
|
+
*/
|
|
736
|
+
bulkImportContacts(params: BulkImportParams): Promise<BulkImportResult>
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Bulk import companies with domain dedup (skips existing domains).
|
|
740
|
+
* Inserts in batches using Supabase bulk insert + ON CONFLICT.
|
|
741
|
+
* @see LeadService.bulkImportCompanies (apps/api/src/business/acquisition/lead-service.ts)
|
|
742
|
+
*/
|
|
743
|
+
bulkImportCompanies(params: BulkImportCompaniesParams): Promise<BulkImportCompaniesResult>
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Deactivate all active contacts belonging to a company.
|
|
747
|
+
* Used by qualification workflow to cascade company disqualification to contacts.
|
|
748
|
+
*/
|
|
749
|
+
deactivateContactsByCompany(params: DeactivateContactsByCompanyParams): Promise<DeactivateContactsByCompanyResult>
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Get a contact by email address
|
|
753
|
+
* Used for looking up existing leads when they reply to outreach
|
|
754
|
+
* @see LeadService.getContactByEmail (apps/api/src/acquisition/lead-service.ts)
|
|
755
|
+
*/
|
|
756
|
+
getContactByEmail(email: string, organizationId: string): Promise<AcqContact | null>
|
|
757
|
+
|
|
758
|
+
// Deal operations (acq_deals table)
|
|
759
|
+
/**
|
|
760
|
+
* Upsert a deal by Attio Deal ID
|
|
761
|
+
* Creates or updates acq_deals record linking Attio Deal to Supabase
|
|
762
|
+
* @see LeadService.upsertDeal (apps/api/src/acquisition/lead-service.ts)
|
|
763
|
+
*/
|
|
764
|
+
upsertDeal(params: UpsertDealParams): Promise<AcqDeal>
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Get a deal by contact email
|
|
768
|
+
* Used for looking up existing deals when leads book via email (fallback lookup)
|
|
769
|
+
* @see LeadService.getDealByEmail (apps/api/src/acquisition/lead-service.ts)
|
|
770
|
+
*/
|
|
771
|
+
getDealByEmail(email: string, organizationId: string): Promise<AcqDeal | null>
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Get a deal by SignatureAPI envelope ID
|
|
775
|
+
* Used by webhook handler to find deal when contract is signed
|
|
776
|
+
* @see LeadService.getDealByEnvelopeId (apps/api/src/acquisition/lead-service.ts)
|
|
777
|
+
*/
|
|
778
|
+
getDealByEnvelopeId(envelopeId: string, organizationId: string): Promise<AcqDeal | null>
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* Update deal with signature envelope ID
|
|
782
|
+
* Called when proposal is sent via SignatureAPI
|
|
783
|
+
* @see LeadService.updateDealEnvelopeId (apps/api/src/acquisition/lead-service.ts)
|
|
784
|
+
*/
|
|
785
|
+
updateDealEnvelopeId(dealId: string, envelopeId: string, organizationId: string): Promise<AcqDeal | null>
|
|
786
|
+
|
|
787
|
+
// Deal-sync operations (mirror deal-sync.ts utilities as server-side methods)
|
|
788
|
+
|
|
789
|
+
getDealById(params: GetDealByIdParams): Promise<AcqDeal | null>
|
|
790
|
+
|
|
791
|
+
getContactById(params: GetContactByIdParams): Promise<AcqContact | null>
|
|
792
|
+
|
|
793
|
+
getCompanyById(params: GetCompanyByIdParams): Promise<AcqCompany | null>
|
|
794
|
+
|
|
795
|
+
updateDiscoveryData(params: UpdateDiscoveryDataParams): Promise<void>
|
|
796
|
+
|
|
797
|
+
updateProposalData(params: UpdateProposalDataParams): Promise<void>
|
|
798
|
+
|
|
799
|
+
markProposalSent(params: MarkProposalSentParams): Promise<void>
|
|
800
|
+
|
|
801
|
+
markProposalReviewed(params: MarkProposalReviewedParams): Promise<void>
|
|
802
|
+
|
|
803
|
+
updateCloseLostReason(params: UpdateCloseLostReasonParams): Promise<void>
|
|
804
|
+
|
|
805
|
+
updateFees(params: UpdateFeesParams): Promise<void>
|
|
806
|
+
|
|
807
|
+
transitionItem(params: TransitionItemParams): Promise<void>
|
|
808
|
+
|
|
809
|
+
setContactNurture(params: SetContactNurtureParams): Promise<void>
|
|
810
|
+
|
|
811
|
+
cancelSchedulesAndHitlByEmail(
|
|
812
|
+
params: CancelSchedulesAndHitlByEmailParams
|
|
813
|
+
): Promise<{ schedulesCancelled: number; hitlDeleted: number }>
|
|
814
|
+
|
|
815
|
+
cancelHitlByDealId(params: CancelHitlByDealIdParams): Promise<{ hitlDeleted: number }>
|
|
816
|
+
|
|
817
|
+
clearDealFields(params: ClearDealFieldsParams): Promise<void>
|
|
818
|
+
|
|
819
|
+
deleteDeal(params: DeleteDealParams): Promise<void>
|
|
820
|
+
|
|
821
|
+
listDeals(organizationId: string, filters?: DealFilters): Promise<AcqDeal[]>
|
|
822
|
+
|
|
823
|
+
getDealPipelineAnalytics(organizationId: string, recentLimit?: number): Promise<DealPipelineAnalytics>
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Deep-merge enrichment data into a company or contact record.
|
|
827
|
+
* Merges per source key rather than wholesale replacing the JSONB object.
|
|
828
|
+
* @see LeadService.mergeEnrichmentData (apps/api/src/business/acquisition/lead-service.ts)
|
|
829
|
+
*/
|
|
830
|
+
mergeEnrichmentData(
|
|
831
|
+
id: string,
|
|
832
|
+
orgId: string,
|
|
833
|
+
table: 'acq_companies' | 'acq_contacts',
|
|
834
|
+
data: Record<string, unknown>
|
|
835
|
+
): Promise<void>
|
|
836
|
+
|
|
837
|
+
// Deal note operations (acq_deal_notes table)
|
|
838
|
+
/**
|
|
839
|
+
* Create a human-authored note on a deal
|
|
840
|
+
* @see LeadService.createDealNote (apps/api/src/business/acquisition/lead-service.ts)
|
|
841
|
+
*/
|
|
842
|
+
createDealNote(params: CreateDealNoteParams): Promise<AcqDealNote>
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* List notes for a deal, ordered by created_at DESC
|
|
846
|
+
* @see LeadService.listDealNotes (apps/api/src/business/acquisition/lead-service.ts)
|
|
847
|
+
*/
|
|
848
|
+
listDealNotes(params: ListDealNotesParams): Promise<AcqDealNote[]>
|
|
849
|
+
|
|
850
|
+
// Deal task operations (acq_deal_tasks table)
|
|
851
|
+
/**
|
|
852
|
+
* Creates a new task attached to a deal.
|
|
853
|
+
* @see LeadService.createDealTask (apps/api/src/business/acquisition/lead-service.ts)
|
|
854
|
+
*/
|
|
855
|
+
createDealTask(params: CreateDealTaskParams): Promise<AcqDealTask>
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Lists all tasks for a given deal, ordered by due date.
|
|
859
|
+
* @see LeadService.listDealTasks (apps/api/src/business/acquisition/lead-service.ts)
|
|
860
|
+
*/
|
|
861
|
+
listDealTasks(params: ListDealTasksParams): Promise<AcqDealTask[]>
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Lists open (uncompleted) tasks within a date window across all deals.
|
|
865
|
+
* @see LeadService.listDealTasksDue (apps/api/src/business/acquisition/lead-service.ts)
|
|
866
|
+
*/
|
|
867
|
+
listDealTasksDue(params: ListDealTasksDueParams): Promise<AcqDealTask[]>
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Marks a task as completed.
|
|
871
|
+
* @see LeadService.completeDealTask (apps/api/src/business/acquisition/lead-service.ts)
|
|
872
|
+
*/
|
|
873
|
+
completeDealTask(params: CompleteDealTaskParams): Promise<AcqDealTask>
|
|
874
|
+
|
|
875
|
+
/**
|
|
876
|
+
* Record a deal activity entry by deal ID.
|
|
877
|
+
* Generic method for any activity type — used by SDK workflows.
|
|
878
|
+
* @see LeadService.recordDealActivity (apps/api/src/business/acquisition/lead-service.ts)
|
|
879
|
+
*/
|
|
880
|
+
recordDealActivity(params: RecordDealActivityParams): Promise<void>
|
|
881
|
+
|
|
882
|
+
// Social monitoring operations (acq_social_posts table)
|
|
883
|
+
/**
|
|
884
|
+
* Bulk upsert social posts (deduplicate by platform + platform_post_id)
|
|
885
|
+
* @see LeadService.upsertSocialPosts (apps/api/src/business/acquisition/lead-service.ts)
|
|
886
|
+
*/
|
|
887
|
+
upsertSocialPosts(params: UpsertSocialPostsParams): Promise<UpsertSocialPostsResult>
|
|
888
|
+
}
|