@hasna/contacts 0.6.3 → 0.6.5
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/cli/index.js +1629 -3851
- package/dist/db/companies.d.ts.map +1 -1
- package/dist/db/contacts.d.ts +0 -4
- package/dist/db/contacts.d.ts.map +1 -1
- package/dist/db/database.d.ts.map +1 -1
- package/dist/db/tags.d.ts.map +1 -1
- package/dist/index.d.ts +1 -33
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +91 -1550
- package/dist/mcp/index.js +81 -1938
- package/dist/server/index.js +12 -326
- package/dist/server/serve.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -6
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/dist/db/coordination.d.ts +0 -30
- package/dist/db/coordination.d.ts.map +0 -1
- package/dist/db/documents.d.ts +0 -37
- package/dist/db/documents.d.ts.map +0 -1
- package/dist/db/field-history.d.ts +0 -17
- package/dist/db/field-history.d.ts.map +0 -1
- package/dist/db/freshness.d.ts +0 -24
- package/dist/db/freshness.d.ts.map +0 -1
- package/dist/db/graph.d.ts +0 -21
- package/dist/db/graph.d.ts.map +0 -1
- package/dist/db/health.d.ts +0 -40
- package/dist/db/health.d.ts.map +0 -1
- package/dist/db/identity.d.ts +0 -32
- package/dist/db/identity.d.ts.map +0 -1
- package/dist/db/job-history.d.ts +0 -29
- package/dist/db/job-history.d.ts.map +0 -1
- package/dist/db/learnings.d.ts +0 -43
- package/dist/db/learnings.d.ts.map +0 -1
- package/dist/db/org-chart.d.ts +0 -37
- package/dist/db/org-chart.d.ts.map +0 -1
- package/dist/db/signals.d.ts +0 -18
- package/dist/db/signals.d.ts.map +0 -1
- package/dist/lib/context.d.ts +0 -5
- package/dist/lib/context.d.ts.map +0 -1
- package/dist/lib/document-scanner.d.ts +0 -8
- package/dist/lib/document-scanner.d.ts.map +0 -1
- package/dist/lib/embeddings.d.ts +0 -9
- package/dist/lib/embeddings.d.ts.map +0 -1
- package/dist/lib/freshness.d.ts +0 -19
- package/dist/lib/freshness.d.ts.map +0 -1
- package/dist/lib/images.d.ts +0 -30
- package/dist/lib/images.d.ts.map +0 -1
- package/dist/lib/learning-maintenance.d.ts +0 -8
- package/dist/lib/learning-maintenance.d.ts.map +0 -1
- package/dist/lib/meeting-capture.d.ts +0 -15
- package/dist/lib/meeting-capture.d.ts.map +0 -1
- package/dist/lib/signals.d.ts +0 -9
- package/dist/lib/signals.d.ts.map +0 -1
- package/dist/lib/signature-parser.d.ts +0 -36
- package/dist/lib/signature-parser.d.ts.map +0 -1
- package/dist/lib/vault.d.ts +0 -15
- package/dist/lib/vault.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __returnValue = (v) => v;
|
|
4
|
+
function __exportSetter(name, newValue) {
|
|
5
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
6
|
+
}
|
|
3
7
|
var __export = (target, all) => {
|
|
4
8
|
for (var name in all)
|
|
5
9
|
__defProp(target, name, {
|
|
6
10
|
get: all[name],
|
|
7
11
|
enumerable: true,
|
|
8
12
|
configurable: true,
|
|
9
|
-
set: (
|
|
13
|
+
set: __exportSetter.bind(all, name)
|
|
10
14
|
});
|
|
11
15
|
};
|
|
12
16
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
@@ -407,177 +411,6 @@ var init_database = __esm(() => {
|
|
|
407
411
|
deal_id TEXT REFERENCES deals(id) ON DELETE SET NULL,
|
|
408
412
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
409
413
|
);
|
|
410
|
-
`,
|
|
411
|
-
`
|
|
412
|
-
-- CON-00069: temporal field history
|
|
413
|
-
CREATE TABLE IF NOT EXISTS contact_field_history (
|
|
414
|
-
id TEXT PRIMARY KEY,
|
|
415
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
416
|
-
field_name TEXT NOT NULL,
|
|
417
|
-
old_value TEXT,
|
|
418
|
-
new_value TEXT,
|
|
419
|
-
valid_from TEXT NOT NULL DEFAULT (datetime('now')),
|
|
420
|
-
source TEXT,
|
|
421
|
-
confidence TEXT NOT NULL DEFAULT 'imported' CHECK(confidence IN ('verified','inferred','imported','stale')),
|
|
422
|
-
created_by TEXT,
|
|
423
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
424
|
-
);
|
|
425
|
-
|
|
426
|
-
-- CON-00070: job history
|
|
427
|
-
CREATE TABLE IF NOT EXISTS job_history (
|
|
428
|
-
id TEXT PRIMARY KEY,
|
|
429
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
430
|
-
company_id TEXT REFERENCES companies(id) ON DELETE SET NULL,
|
|
431
|
-
company_name TEXT NOT NULL,
|
|
432
|
-
title TEXT,
|
|
433
|
-
start_date TEXT,
|
|
434
|
-
end_date TEXT,
|
|
435
|
-
is_current INTEGER NOT NULL DEFAULT 0,
|
|
436
|
-
inferred INTEGER NOT NULL DEFAULT 0,
|
|
437
|
-
source TEXT,
|
|
438
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
439
|
-
);
|
|
440
|
-
|
|
441
|
-
-- CON-00071: learnings
|
|
442
|
-
CREATE TABLE IF NOT EXISTS contact_learnings (
|
|
443
|
-
id TEXT PRIMARY KEY,
|
|
444
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
445
|
-
content TEXT NOT NULL,
|
|
446
|
-
type TEXT NOT NULL DEFAULT 'fact' CHECK(type IN ('preference','fact','inference','warning','signal')),
|
|
447
|
-
confidence INTEGER NOT NULL DEFAULT 70 CHECK(confidence BETWEEN 0 AND 100),
|
|
448
|
-
importance INTEGER NOT NULL DEFAULT 5 CHECK(importance BETWEEN 1 AND 10),
|
|
449
|
-
learned_by TEXT,
|
|
450
|
-
session_id TEXT,
|
|
451
|
-
visibility TEXT NOT NULL DEFAULT 'shared' CHECK(visibility IN ('private','shared','human')),
|
|
452
|
-
tags TEXT NOT NULL DEFAULT '[]',
|
|
453
|
-
confirmed_count INTEGER NOT NULL DEFAULT 0,
|
|
454
|
-
contradicts_id TEXT REFERENCES contact_learnings(id) ON DELETE SET NULL,
|
|
455
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
456
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
457
|
-
);
|
|
458
|
-
|
|
459
|
-
-- CON-00072: coordination
|
|
460
|
-
CREATE TABLE IF NOT EXISTS contact_locks (
|
|
461
|
-
id TEXT PRIMARY KEY,
|
|
462
|
-
contact_id TEXT NOT NULL UNIQUE REFERENCES contacts(id) ON DELETE CASCADE,
|
|
463
|
-
agent_name TEXT NOT NULL,
|
|
464
|
-
reason TEXT,
|
|
465
|
-
acquired_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
466
|
-
expires_at TEXT NOT NULL,
|
|
467
|
-
session_id TEXT
|
|
468
|
-
);
|
|
469
|
-
CREATE TABLE IF NOT EXISTS contact_agent_activity (
|
|
470
|
-
id TEXT PRIMARY KEY,
|
|
471
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
472
|
-
agent_name TEXT NOT NULL,
|
|
473
|
-
action TEXT NOT NULL,
|
|
474
|
-
details TEXT,
|
|
475
|
-
session_id TEXT,
|
|
476
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
477
|
-
);
|
|
478
|
-
|
|
479
|
-
-- CON-00073: relationship graph extra columns
|
|
480
|
-
ALTER TABLE contact_relationships ADD COLUMN strength_score INTEGER NOT NULL DEFAULT 50;
|
|
481
|
-
ALTER TABLE contact_relationships ADD COLUMN interaction_count INTEGER NOT NULL DEFAULT 0;
|
|
482
|
-
ALTER TABLE contact_relationships ADD COLUMN last_interaction TEXT;
|
|
483
|
-
ALTER TABLE contact_relationships ADD COLUMN relationship_status TEXT NOT NULL DEFAULT 'stable' CHECK(relationship_status IN ('warming','stable','cooling','ghost'));
|
|
484
|
-
|
|
485
|
-
-- CON-00074: identity resolution
|
|
486
|
-
CREATE TABLE IF NOT EXISTS contact_identities (
|
|
487
|
-
id TEXT PRIMARY KEY,
|
|
488
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
489
|
-
system TEXT NOT NULL,
|
|
490
|
-
external_id TEXT NOT NULL,
|
|
491
|
-
external_url TEXT,
|
|
492
|
-
confidence TEXT NOT NULL DEFAULT 'inferred' CHECK(confidence IN ('verified','inferred')),
|
|
493
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
494
|
-
UNIQUE(system, external_id)
|
|
495
|
-
);
|
|
496
|
-
ALTER TABLE contacts ADD COLUMN canonical_id TEXT;
|
|
497
|
-
|
|
498
|
-
-- CON-00076: relationship signals
|
|
499
|
-
ALTER TABLE contacts ADD COLUMN relationship_health INTEGER NOT NULL DEFAULT 50;
|
|
500
|
-
ALTER TABLE contacts ADD COLUMN avg_response_hours REAL;
|
|
501
|
-
ALTER TABLE contacts ADD COLUMN preferred_channel TEXT;
|
|
502
|
-
ALTER TABLE contacts ADD COLUMN engagement_status TEXT NOT NULL DEFAULT 'new' CHECK(engagement_status IN ('warming','stable','cooling','ghost','new'));
|
|
503
|
-
ALTER TABLE contacts ADD COLUMN interaction_count_30d INTEGER NOT NULL DEFAULT 0;
|
|
504
|
-
ALTER TABLE contacts ADD COLUMN interaction_count_90d INTEGER NOT NULL DEFAULT 0;
|
|
505
|
-
|
|
506
|
-
-- CON-00079: freshness scoring
|
|
507
|
-
CREATE TABLE IF NOT EXISTS contact_field_confidence (
|
|
508
|
-
id TEXT PRIMARY KEY,
|
|
509
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
510
|
-
field_name TEXT NOT NULL,
|
|
511
|
-
confidence TEXT NOT NULL DEFAULT 'imported' CHECK(confidence IN ('verified','inferred','imported','stale')),
|
|
512
|
-
source TEXT,
|
|
513
|
-
last_verified_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
514
|
-
UNIQUE(contact_id, field_name)
|
|
515
|
-
);
|
|
516
|
-
|
|
517
|
-
-- CON-00080: org chart
|
|
518
|
-
CREATE TABLE IF NOT EXISTS org_chart_edges (
|
|
519
|
-
id TEXT PRIMARY KEY,
|
|
520
|
-
company_id TEXT NOT NULL REFERENCES companies(id) ON DELETE CASCADE,
|
|
521
|
-
contact_a_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
522
|
-
contact_b_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
523
|
-
edge_type TEXT NOT NULL CHECK(edge_type IN ('reports_to','manages','collaborates_with','peer')),
|
|
524
|
-
inferred INTEGER NOT NULL DEFAULT 0,
|
|
525
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
526
|
-
UNIQUE(company_id, contact_a_id, contact_b_id, edge_type)
|
|
527
|
-
);
|
|
528
|
-
CREATE TABLE IF NOT EXISTS deal_contact_roles (
|
|
529
|
-
id TEXT PRIMARY KEY,
|
|
530
|
-
deal_id TEXT NOT NULL REFERENCES deals(id) ON DELETE CASCADE,
|
|
531
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
532
|
-
account_role TEXT NOT NULL CHECK(account_role IN ('economic_buyer','technical_evaluator','champion','blocker','influencer','user','sponsor','other')),
|
|
533
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
534
|
-
UNIQUE(deal_id, contact_id)
|
|
535
|
-
);
|
|
536
|
-
|
|
537
|
-
-- CON-00075: embeddings
|
|
538
|
-
CREATE TABLE IF NOT EXISTS contact_embeddings (
|
|
539
|
-
contact_id TEXT PRIMARY KEY REFERENCES contacts(id) ON DELETE CASCADE,
|
|
540
|
-
embedding TEXT NOT NULL,
|
|
541
|
-
model TEXT NOT NULL DEFAULT 'tfidf',
|
|
542
|
-
embedded_text TEXT,
|
|
543
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
544
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
545
|
-
);
|
|
546
|
-
`,
|
|
547
|
-
`
|
|
548
|
-
ALTER TABLE contacts ADD COLUMN sensitivity TEXT NOT NULL DEFAULT 'normal' CHECK(sensitivity IN ('normal','confidential','restricted'));
|
|
549
|
-
|
|
550
|
-
CREATE TABLE IF NOT EXISTS contact_documents (
|
|
551
|
-
id TEXT PRIMARY KEY,
|
|
552
|
-
contact_id TEXT NOT NULL REFERENCES contacts(id) ON DELETE CASCADE,
|
|
553
|
-
doc_type TEXT NOT NULL,
|
|
554
|
-
label TEXT,
|
|
555
|
-
encrypted_value TEXT NOT NULL,
|
|
556
|
-
iv TEXT NOT NULL,
|
|
557
|
-
encrypted_file_path TEXT,
|
|
558
|
-
metadata TEXT NOT NULL DEFAULT '{}',
|
|
559
|
-
expires_at TEXT,
|
|
560
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
561
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
562
|
-
);
|
|
563
|
-
|
|
564
|
-
CREATE TABLE IF NOT EXISTS contact_health (
|
|
565
|
-
id TEXT PRIMARY KEY,
|
|
566
|
-
contact_id TEXT NOT NULL UNIQUE REFERENCES contacts(id) ON DELETE CASCADE,
|
|
567
|
-
blood_type TEXT,
|
|
568
|
-
allergies TEXT NOT NULL DEFAULT '[]',
|
|
569
|
-
medical_conditions TEXT NOT NULL DEFAULT '[]',
|
|
570
|
-
medications TEXT NOT NULL DEFAULT '[]',
|
|
571
|
-
emergency_contacts TEXT NOT NULL DEFAULT '[]',
|
|
572
|
-
health_insurance_provider TEXT,
|
|
573
|
-
health_insurance_id TEXT,
|
|
574
|
-
primary_physician TEXT,
|
|
575
|
-
primary_physician_phone TEXT,
|
|
576
|
-
organ_donor INTEGER NOT NULL DEFAULT 0,
|
|
577
|
-
notes TEXT,
|
|
578
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
579
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
580
|
-
);
|
|
581
414
|
`
|
|
582
415
|
];
|
|
583
416
|
});
|
|
@@ -664,7 +497,6 @@ __export(exports_contacts, {
|
|
|
664
497
|
getContactProjectIds: () => getContactProjectIds,
|
|
665
498
|
getContactByEmail: () => getContactByEmail,
|
|
666
499
|
getContact: () => getContact,
|
|
667
|
-
findOrCreateContact: () => findOrCreateContact,
|
|
668
500
|
deleteContact: () => deleteContact,
|
|
669
501
|
createContact: () => createContact,
|
|
670
502
|
autoLinkContactToCompany: () => autoLinkContactToCompany,
|
|
@@ -682,7 +514,6 @@ function rowToContact(row) {
|
|
|
682
514
|
follow_up_at: row.follow_up_at ?? null,
|
|
683
515
|
archived: !!row.archived,
|
|
684
516
|
project_id: row.project_id ?? null,
|
|
685
|
-
sensitivity: row.sensitivity ?? "normal",
|
|
686
517
|
do_not_contact: !!row.do_not_contact,
|
|
687
518
|
priority: row.priority ?? 3,
|
|
688
519
|
timezone: row.timezone ?? null
|
|
@@ -770,8 +601,8 @@ function createContact(input, db) {
|
|
|
770
601
|
const firstName = input.first_name ?? "";
|
|
771
602
|
const lastName = input.last_name ?? "";
|
|
772
603
|
const displayName = input.display_name ?? (firstName || lastName ? `${firstName} ${lastName}`.trim() : "Unnamed Contact");
|
|
773
|
-
d.run(`INSERT INTO contacts (id, first_name, last_name, display_name, nickname, avatar_url, notes, birthday, company_id, job_title, source, custom_fields, last_contacted_at, website, preferred_contact_method, status, follow_up_at, project_id,
|
|
774
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
604
|
+
d.run(`INSERT INTO contacts (id, first_name, last_name, display_name, nickname, avatar_url, notes, birthday, company_id, job_title, source, custom_fields, last_contacted_at, website, preferred_contact_method, status, follow_up_at, project_id, do_not_contact, priority, timezone, created_at, updated_at)
|
|
605
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
775
606
|
id,
|
|
776
607
|
firstName,
|
|
777
608
|
lastName,
|
|
@@ -790,7 +621,6 @@ function createContact(input, db) {
|
|
|
790
621
|
input.status ?? "active",
|
|
791
622
|
input.follow_up_at ?? null,
|
|
792
623
|
input.project_id ?? null,
|
|
793
|
-
input.sensitivity ?? "normal",
|
|
794
624
|
input.do_not_contact ? 1 : 0,
|
|
795
625
|
input.priority ?? 3,
|
|
796
626
|
input.timezone ?? null,
|
|
@@ -839,7 +669,6 @@ function listContacts(opts = {}, db) {
|
|
|
839
669
|
order_by = "display_name",
|
|
840
670
|
order_dir = "asc",
|
|
841
671
|
include_dnc = false,
|
|
842
|
-
include_restricted = false,
|
|
843
672
|
priority_min,
|
|
844
673
|
updated_since
|
|
845
674
|
} = opts;
|
|
@@ -850,9 +679,6 @@ function listContacts(opts = {}, db) {
|
|
|
850
679
|
if (!include_dnc) {
|
|
851
680
|
conditions.push("c.do_not_contact = 0");
|
|
852
681
|
}
|
|
853
|
-
if (!include_restricted) {
|
|
854
|
-
conditions.push("c.sensitivity != 'restricted'");
|
|
855
|
-
}
|
|
856
682
|
if (company_id) {
|
|
857
683
|
conditions.push("c.company_id = ?");
|
|
858
684
|
params.push(company_id);
|
|
@@ -981,10 +807,6 @@ function updateContact(id, input, db) {
|
|
|
981
807
|
setClauses.push("project_id = ?");
|
|
982
808
|
params.push(input.project_id);
|
|
983
809
|
}
|
|
984
|
-
if (input.sensitivity !== undefined) {
|
|
985
|
-
setClauses.push("sensitivity = ?");
|
|
986
|
-
params.push(input.sensitivity);
|
|
987
|
-
}
|
|
988
810
|
if (input.do_not_contact !== undefined) {
|
|
989
811
|
setClauses.push("do_not_contact = ?");
|
|
990
812
|
params.push(input.do_not_contact ? 1 : 0);
|
|
@@ -1032,26 +854,26 @@ function searchContacts(query, db) {
|
|
|
1032
854
|
const ftsRows = d.query(`
|
|
1033
855
|
SELECT c.* FROM contacts c
|
|
1034
856
|
JOIN contacts_fts fts ON fts.id = c.id
|
|
1035
|
-
WHERE contacts_fts MATCH ? AND c.archived = 0
|
|
857
|
+
WHERE contacts_fts MATCH ? AND c.archived = 0
|
|
1036
858
|
ORDER BY rank
|
|
1037
859
|
LIMIT 50
|
|
1038
860
|
`).all(`"${query.replace(/"/g, '""')}"*`);
|
|
1039
861
|
const emailRows = d.query(`
|
|
1040
862
|
SELECT DISTINCT c.* FROM contacts c
|
|
1041
863
|
JOIN emails e ON e.contact_id = c.id
|
|
1042
|
-
WHERE e.address LIKE ? AND c.archived = 0
|
|
864
|
+
WHERE e.address LIKE ? AND c.archived = 0
|
|
1043
865
|
LIMIT 20
|
|
1044
866
|
`).all(`%${query}%`);
|
|
1045
867
|
const phoneRows = d.query(`
|
|
1046
868
|
SELECT DISTINCT c.* FROM contacts c
|
|
1047
869
|
JOIN phones p ON p.contact_id = c.id
|
|
1048
|
-
WHERE p.number LIKE ? AND c.archived = 0
|
|
870
|
+
WHERE p.number LIKE ? AND c.archived = 0
|
|
1049
871
|
LIMIT 20
|
|
1050
872
|
`).all(`%${query}%`);
|
|
1051
873
|
const companyRows = d.query(`
|
|
1052
874
|
SELECT DISTINCT c.* FROM contacts c
|
|
1053
875
|
JOIN companies co ON co.id = c.company_id
|
|
1054
|
-
WHERE co.name LIKE ? AND c.archived = 0
|
|
876
|
+
WHERE co.name LIKE ? AND c.archived = 0
|
|
1055
877
|
LIMIT 20
|
|
1056
878
|
`).all(`%${query}%`);
|
|
1057
879
|
const seen = new Set;
|
|
@@ -1204,25 +1026,6 @@ function listColdContacts(days, db) {
|
|
|
1204
1026
|
LIMIT 100`).all(`-${days}`);
|
|
1205
1027
|
return rows.map((row) => loadContactDetails(d, rowToContact(row)));
|
|
1206
1028
|
}
|
|
1207
|
-
async function findOrCreateContact(input, db) {
|
|
1208
|
-
const d = db || getDatabase();
|
|
1209
|
-
const emailAddresses = (input.emails ?? []).map((e) => e.address);
|
|
1210
|
-
for (const addr of emailAddresses) {
|
|
1211
|
-
const emailRow = d.query(`SELECT contact_id FROM emails WHERE LOWER(address) = LOWER(?) AND contact_id IS NOT NULL LIMIT 1`).get(addr);
|
|
1212
|
-
if (emailRow) {
|
|
1213
|
-
return { contact: getContact(emailRow.contact_id, d), created: false };
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
const nameQuery = input.display_name ?? (input.first_name || input.last_name ? `${input.first_name ?? ""} ${input.last_name ?? ""}`.trim() : null);
|
|
1217
|
-
if (nameQuery) {
|
|
1218
|
-
const results = searchContacts(nameQuery, d);
|
|
1219
|
-
if (results.length > 0 && results[0]) {
|
|
1220
|
-
return { contact: results[0], created: false };
|
|
1221
|
-
}
|
|
1222
|
-
}
|
|
1223
|
-
const contact = createContact(input, d);
|
|
1224
|
-
return { contact, created: true };
|
|
1225
|
-
}
|
|
1226
1029
|
function autoLinkContactToCompany(contactId, db) {
|
|
1227
1030
|
const d = db || getDatabase();
|
|
1228
1031
|
const row = d.query(`SELECT * FROM contacts WHERE id = ?`).get(contactId);
|
|
@@ -1273,96 +1076,6 @@ var init_contacts = __esm(() => {
|
|
|
1273
1076
|
init_activity();
|
|
1274
1077
|
});
|
|
1275
1078
|
|
|
1276
|
-
// src/db/events.ts
|
|
1277
|
-
var exports_events = {};
|
|
1278
|
-
__export(exports_events, {
|
|
1279
|
-
logEvent: () => logEvent,
|
|
1280
|
-
listEvents: () => listEvents,
|
|
1281
|
-
getEvent: () => getEvent,
|
|
1282
|
-
deleteEvent: () => deleteEvent
|
|
1283
|
-
});
|
|
1284
|
-
function rowToEvent(row) {
|
|
1285
|
-
let contact_ids = [];
|
|
1286
|
-
try {
|
|
1287
|
-
contact_ids = JSON.parse(row.contact_ids);
|
|
1288
|
-
} catch {
|
|
1289
|
-
contact_ids = [];
|
|
1290
|
-
}
|
|
1291
|
-
return {
|
|
1292
|
-
id: row.id,
|
|
1293
|
-
title: row.title,
|
|
1294
|
-
type: row.type,
|
|
1295
|
-
event_date: row.event_date,
|
|
1296
|
-
duration_min: row.duration_min,
|
|
1297
|
-
contact_ids,
|
|
1298
|
-
company_id: row.company_id,
|
|
1299
|
-
notes: row.notes,
|
|
1300
|
-
outcome: row.outcome,
|
|
1301
|
-
deal_id: row.deal_id,
|
|
1302
|
-
created_at: row.created_at
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
function logEvent(input, db) {
|
|
1306
|
-
const d = db || getDatabase();
|
|
1307
|
-
const id = uuid();
|
|
1308
|
-
const timestamp = now();
|
|
1309
|
-
d.run(`INSERT INTO events (id, title, type, event_date, duration_min, contact_ids, company_id, notes, outcome, deal_id, created_at)
|
|
1310
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
1311
|
-
id,
|
|
1312
|
-
input.title,
|
|
1313
|
-
input.type ?? "meeting",
|
|
1314
|
-
input.event_date,
|
|
1315
|
-
input.duration_min ?? null,
|
|
1316
|
-
JSON.stringify(input.contact_ids ?? []),
|
|
1317
|
-
input.company_id ?? null,
|
|
1318
|
-
input.notes ?? null,
|
|
1319
|
-
input.outcome ?? null,
|
|
1320
|
-
input.deal_id ?? null,
|
|
1321
|
-
timestamp
|
|
1322
|
-
]);
|
|
1323
|
-
return rowToEvent(d.query(`SELECT * FROM events WHERE id = ?`).get(id));
|
|
1324
|
-
}
|
|
1325
|
-
function getEvent(id, db) {
|
|
1326
|
-
const d = db || getDatabase();
|
|
1327
|
-
const row = d.query(`SELECT * FROM events WHERE id = ?`).get(id);
|
|
1328
|
-
return row ? rowToEvent(row) : null;
|
|
1329
|
-
}
|
|
1330
|
-
function listEvents(opts = {}, db) {
|
|
1331
|
-
const d = db || getDatabase();
|
|
1332
|
-
const conditions = [];
|
|
1333
|
-
const params = [];
|
|
1334
|
-
if (opts.contact_id) {
|
|
1335
|
-
conditions.push("contact_ids LIKE ?");
|
|
1336
|
-
params.push(`%${opts.contact_id}%`);
|
|
1337
|
-
}
|
|
1338
|
-
if (opts.company_id) {
|
|
1339
|
-
conditions.push("company_id = ?");
|
|
1340
|
-
params.push(opts.company_id);
|
|
1341
|
-
}
|
|
1342
|
-
if (opts.type) {
|
|
1343
|
-
conditions.push("type = ?");
|
|
1344
|
-
params.push(opts.type);
|
|
1345
|
-
}
|
|
1346
|
-
if (opts.date_from) {
|
|
1347
|
-
conditions.push("event_date >= ?");
|
|
1348
|
-
params.push(opts.date_from);
|
|
1349
|
-
}
|
|
1350
|
-
if (opts.date_to) {
|
|
1351
|
-
conditions.push("event_date <= ?");
|
|
1352
|
-
params.push(opts.date_to);
|
|
1353
|
-
}
|
|
1354
|
-
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
1355
|
-
const rows = d.query(`SELECT * FROM events ${where} ORDER BY event_date DESC`).all(...params);
|
|
1356
|
-
return rows.map(rowToEvent);
|
|
1357
|
-
}
|
|
1358
|
-
function deleteEvent(id, db) {
|
|
1359
|
-
const d = db || getDatabase();
|
|
1360
|
-
d.run(`DELETE FROM events WHERE id = ?`, [id]);
|
|
1361
|
-
}
|
|
1362
|
-
var init_events = __esm(() => {
|
|
1363
|
-
init_database();
|
|
1364
|
-
});
|
|
1365
|
-
|
|
1366
1079
|
// src/index.ts
|
|
1367
1080
|
init_database();
|
|
1368
1081
|
init_contacts();
|
|
@@ -1617,7 +1330,6 @@ function listCompanyEmployees(companyId, db) {
|
|
|
1617
1330
|
follow_up_at: r.follow_up_at ?? null,
|
|
1618
1331
|
archived: !!r.archived,
|
|
1619
1332
|
project_id: r.project_id ?? null,
|
|
1620
|
-
sensitivity: r.sensitivity ?? "normal",
|
|
1621
1333
|
do_not_contact: !!r.do_not_contact,
|
|
1622
1334
|
priority: r.priority ?? 3,
|
|
1623
1335
|
timezone: r.timezone ?? null
|
|
@@ -1748,7 +1460,6 @@ function listContactsByTag(tagId, db) {
|
|
|
1748
1460
|
follow_up_at: r.follow_up_at ?? null,
|
|
1749
1461
|
archived: !!r.archived,
|
|
1750
1462
|
project_id: r.project_id ?? null,
|
|
1751
|
-
sensitivity: r.sensitivity ?? "normal",
|
|
1752
1463
|
do_not_contact: !!r.do_not_contact,
|
|
1753
1464
|
priority: r.priority ?? 3,
|
|
1754
1465
|
timezone: r.timezone ?? null
|
|
@@ -2542,10 +2253,86 @@ function getDealsByStage(db) {
|
|
|
2542
2253
|
}
|
|
2543
2254
|
return result;
|
|
2544
2255
|
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2256
|
+
// src/db/events.ts
|
|
2257
|
+
init_database();
|
|
2258
|
+
function rowToEvent(row) {
|
|
2259
|
+
let contact_ids = [];
|
|
2260
|
+
try {
|
|
2261
|
+
contact_ids = JSON.parse(row.contact_ids);
|
|
2262
|
+
} catch {
|
|
2263
|
+
contact_ids = [];
|
|
2264
|
+
}
|
|
2265
|
+
return {
|
|
2266
|
+
id: row.id,
|
|
2267
|
+
title: row.title,
|
|
2268
|
+
type: row.type,
|
|
2269
|
+
event_date: row.event_date,
|
|
2270
|
+
duration_min: row.duration_min,
|
|
2271
|
+
contact_ids,
|
|
2272
|
+
company_id: row.company_id,
|
|
2273
|
+
notes: row.notes,
|
|
2274
|
+
outcome: row.outcome,
|
|
2275
|
+
deal_id: row.deal_id,
|
|
2276
|
+
created_at: row.created_at
|
|
2277
|
+
};
|
|
2278
|
+
}
|
|
2279
|
+
function logEvent(input, db) {
|
|
2280
|
+
const d = db || getDatabase();
|
|
2281
|
+
const id = uuid();
|
|
2282
|
+
const timestamp = now();
|
|
2283
|
+
d.run(`INSERT INTO events (id, title, type, event_date, duration_min, contact_ids, company_id, notes, outcome, deal_id, created_at)
|
|
2284
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
2285
|
+
id,
|
|
2286
|
+
input.title,
|
|
2287
|
+
input.type ?? "meeting",
|
|
2288
|
+
input.event_date,
|
|
2289
|
+
input.duration_min ?? null,
|
|
2290
|
+
JSON.stringify(input.contact_ids ?? []),
|
|
2291
|
+
input.company_id ?? null,
|
|
2292
|
+
input.notes ?? null,
|
|
2293
|
+
input.outcome ?? null,
|
|
2294
|
+
input.deal_id ?? null,
|
|
2295
|
+
timestamp
|
|
2296
|
+
]);
|
|
2297
|
+
return rowToEvent(d.query(`SELECT * FROM events WHERE id = ?`).get(id));
|
|
2298
|
+
}
|
|
2299
|
+
function getEvent(id, db) {
|
|
2300
|
+
const d = db || getDatabase();
|
|
2301
|
+
const row = d.query(`SELECT * FROM events WHERE id = ?`).get(id);
|
|
2302
|
+
return row ? rowToEvent(row) : null;
|
|
2303
|
+
}
|
|
2304
|
+
function listEvents(opts = {}, db) {
|
|
2305
|
+
const d = db || getDatabase();
|
|
2306
|
+
const conditions = [];
|
|
2307
|
+
const params = [];
|
|
2308
|
+
if (opts.contact_id) {
|
|
2309
|
+
conditions.push("contact_ids LIKE ?");
|
|
2310
|
+
params.push(`%${opts.contact_id}%`);
|
|
2311
|
+
}
|
|
2312
|
+
if (opts.company_id) {
|
|
2313
|
+
conditions.push("company_id = ?");
|
|
2314
|
+
params.push(opts.company_id);
|
|
2315
|
+
}
|
|
2316
|
+
if (opts.type) {
|
|
2317
|
+
conditions.push("type = ?");
|
|
2318
|
+
params.push(opts.type);
|
|
2319
|
+
}
|
|
2320
|
+
if (opts.date_from) {
|
|
2321
|
+
conditions.push("event_date >= ?");
|
|
2322
|
+
params.push(opts.date_from);
|
|
2323
|
+
}
|
|
2324
|
+
if (opts.date_to) {
|
|
2325
|
+
conditions.push("event_date <= ?");
|
|
2326
|
+
params.push(opts.date_to);
|
|
2327
|
+
}
|
|
2328
|
+
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
2329
|
+
const rows = d.query(`SELECT * FROM events ${where} ORDER BY event_date DESC`).all(...params);
|
|
2330
|
+
return rows.map(rowToEvent);
|
|
2331
|
+
}
|
|
2332
|
+
function deleteEvent(id, db) {
|
|
2333
|
+
const d = db || getDatabase();
|
|
2334
|
+
d.run(`DELETE FROM events WHERE id = ?`, [id]);
|
|
2335
|
+
}
|
|
2549
2336
|
// src/db/notes.ts
|
|
2550
2337
|
init_types();
|
|
2551
2338
|
init_database();
|
|
@@ -3744,1176 +3531,6 @@ async function pullGoogleContactsAsInputs(opts = {}) {
|
|
|
3744
3531
|
|
|
3745
3532
|
// src/index.ts
|
|
3746
3533
|
init_types();
|
|
3747
|
-
|
|
3748
|
-
// src/db/field-history.ts
|
|
3749
|
-
init_database();
|
|
3750
|
-
function recordFieldChange(contactId, fieldName, oldValue, newValue, source, createdBy, db) {
|
|
3751
|
-
const _db2 = db || getDatabase();
|
|
3752
|
-
_db2.query(`INSERT INTO contact_field_history(id,contact_id,field_name,old_value,new_value,valid_from,source,created_by,created_at) VALUES(?,?,?,?,?,?,?,?,?)`).run(uuid(), contactId, fieldName, oldValue != null ? String(oldValue) : null, newValue != null ? String(newValue) : null, now(), source || null, createdBy || null, now());
|
|
3753
|
-
}
|
|
3754
|
-
function getFieldHistory(contactId, fieldName, db) {
|
|
3755
|
-
const _db2 = db || getDatabase();
|
|
3756
|
-
if (fieldName) {
|
|
3757
|
-
return _db2.query(`SELECT * FROM contact_field_history WHERE contact_id=? AND field_name=? ORDER BY valid_from DESC`).all(contactId, fieldName);
|
|
3758
|
-
}
|
|
3759
|
-
return _db2.query(`SELECT * FROM contact_field_history WHERE contact_id=? ORDER BY valid_from DESC`).all(contactId);
|
|
3760
|
-
}
|
|
3761
|
-
function getContactAt(contactId, timestamp, db) {
|
|
3762
|
-
const _db2 = db || getDatabase();
|
|
3763
|
-
const rows = _db2.query(`SELECT field_name, new_value FROM contact_field_history WHERE contact_id=? AND valid_from<=? ORDER BY valid_from ASC`).all(contactId, timestamp);
|
|
3764
|
-
const result = {};
|
|
3765
|
-
for (const r of rows) {
|
|
3766
|
-
if (r.new_value != null)
|
|
3767
|
-
result[r.field_name] = r.new_value;
|
|
3768
|
-
}
|
|
3769
|
-
return result;
|
|
3770
|
-
}
|
|
3771
|
-
// src/db/job-history.ts
|
|
3772
|
-
init_database();
|
|
3773
|
-
function rowToJob(r) {
|
|
3774
|
-
return { ...r, is_current: !!r["is_current"], inferred: !!r["inferred"] };
|
|
3775
|
-
}
|
|
3776
|
-
function addJobEntry(contactId, input, db) {
|
|
3777
|
-
const _db2 = db || getDatabase();
|
|
3778
|
-
if (input.is_current) {
|
|
3779
|
-
_db2.query(`UPDATE job_history SET is_current=0, end_date=COALESCE(end_date,?) WHERE contact_id=? AND is_current=1`).run(new Date().toISOString().slice(0, 10), contactId);
|
|
3780
|
-
}
|
|
3781
|
-
const id = uuid();
|
|
3782
|
-
_db2.query(`INSERT INTO job_history(id,contact_id,company_id,company_name,title,start_date,end_date,is_current,inferred,source,created_at) VALUES(?,?,?,?,?,?,?,?,?,?,?)`).run(id, contactId, input.company_id || null, input.company_name, input.title || null, input.start_date || null, input.end_date || null, input.is_current ? 1 : 0, input.inferred ? 1 : 0, input.source || null, now());
|
|
3783
|
-
return rowToJob(_db2.query(`SELECT * FROM job_history WHERE id=?`).get(id));
|
|
3784
|
-
}
|
|
3785
|
-
function getJobHistory(contactId, db) {
|
|
3786
|
-
const _db2 = db || getDatabase();
|
|
3787
|
-
return _db2.query(`SELECT * FROM job_history WHERE contact_id=? ORDER BY is_current DESC, start_date DESC`).all(contactId).map(rowToJob);
|
|
3788
|
-
}
|
|
3789
|
-
function getCurrentRole(contactId, db) {
|
|
3790
|
-
const _db2 = db || getDatabase();
|
|
3791
|
-
const r = _db2.query(`SELECT * FROM job_history WHERE contact_id=? AND is_current=1`).get(contactId);
|
|
3792
|
-
return r ? rowToJob(r) : null;
|
|
3793
|
-
}
|
|
3794
|
-
function getPreviousEmployers(contactId, db) {
|
|
3795
|
-
const _db2 = db || getDatabase();
|
|
3796
|
-
return _db2.query(`SELECT * FROM job_history WHERE contact_id=? AND is_current=0 ORDER BY start_date DESC`).all(contactId).map(rowToJob);
|
|
3797
|
-
}
|
|
3798
|
-
// src/db/learnings.ts
|
|
3799
|
-
init_database();
|
|
3800
|
-
function rowToLearning(r) {
|
|
3801
|
-
return { ...r, tags: JSON.parse(r["tags"] || "[]") };
|
|
3802
|
-
}
|
|
3803
|
-
function saveLearning(contactId, input, db) {
|
|
3804
|
-
const _db2 = db || getDatabase();
|
|
3805
|
-
const id = uuid();
|
|
3806
|
-
_db2.query(`INSERT INTO contact_learnings(id,contact_id,content,type,confidence,importance,learned_by,session_id,visibility,tags,created_at,updated_at) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)`).run(id, contactId, input.content, input.type || "fact", input.confidence ?? 70, input.importance ?? 5, input.learned_by || null, input.session_id || null, input.visibility || "shared", JSON.stringify(input.tags || []), now(), now());
|
|
3807
|
-
return rowToLearning(_db2.query(`SELECT * FROM contact_learnings WHERE id=?`).get(id));
|
|
3808
|
-
}
|
|
3809
|
-
function getLearnings(contactId, opts = {}, db) {
|
|
3810
|
-
const _db2 = db || getDatabase();
|
|
3811
|
-
let sql = `SELECT * FROM contact_learnings WHERE contact_id=?`;
|
|
3812
|
-
const params = [contactId];
|
|
3813
|
-
if (opts.type) {
|
|
3814
|
-
sql += ` AND type=?`;
|
|
3815
|
-
params.push(opts.type);
|
|
3816
|
-
}
|
|
3817
|
-
if (opts.min_importance) {
|
|
3818
|
-
sql += ` AND importance>=?`;
|
|
3819
|
-
params.push(opts.min_importance);
|
|
3820
|
-
}
|
|
3821
|
-
if (opts.visibility) {
|
|
3822
|
-
sql += ` AND visibility=?`;
|
|
3823
|
-
params.push(opts.visibility);
|
|
3824
|
-
}
|
|
3825
|
-
sql += ` ORDER BY importance DESC, confidence DESC`;
|
|
3826
|
-
return _db2.query(sql).all(...params).map(rowToLearning);
|
|
3827
|
-
}
|
|
3828
|
-
function searchLearnings(query, opts = {}, db) {
|
|
3829
|
-
const _db2 = db || getDatabase();
|
|
3830
|
-
let sql = `SELECT * FROM contact_learnings WHERE content LIKE ?`;
|
|
3831
|
-
const params = [`%${query}%`];
|
|
3832
|
-
if (opts.type) {
|
|
3833
|
-
sql += ` AND type=?`;
|
|
3834
|
-
params.push(opts.type);
|
|
3835
|
-
}
|
|
3836
|
-
if (opts.contact_id) {
|
|
3837
|
-
sql += ` AND contact_id=?`;
|
|
3838
|
-
params.push(opts.contact_id);
|
|
3839
|
-
}
|
|
3840
|
-
sql += ` ORDER BY importance DESC, confidence DESC LIMIT 50`;
|
|
3841
|
-
return _db2.query(sql).all(...params).map(rowToLearning);
|
|
3842
|
-
}
|
|
3843
|
-
function confirmLearning(learningId, _agentName, db) {
|
|
3844
|
-
const _db2 = db || getDatabase();
|
|
3845
|
-
_db2.query(`UPDATE contact_learnings SET confirmed_count=confirmed_count+1, confidence=MIN(100,confidence+10), updated_at=? WHERE id=?`).run(now(), learningId);
|
|
3846
|
-
}
|
|
3847
|
-
function decayLearnings(db) {
|
|
3848
|
-
const _db2 = db || getDatabase();
|
|
3849
|
-
const cutoff = new Date(Date.now() - 30 * 86400000).toISOString();
|
|
3850
|
-
const result = _db2.query(`UPDATE contact_learnings SET confidence=MAX(10,confidence-5), updated_at=? WHERE confirmed_count=0 AND created_at<? AND confidence>10`).run(now(), cutoff);
|
|
3851
|
-
return result.changes || 0;
|
|
3852
|
-
}
|
|
3853
|
-
function deleteLearning(learningId, db) {
|
|
3854
|
-
const _db2 = db || getDatabase();
|
|
3855
|
-
_db2.query(`DELETE FROM contact_learnings WHERE id=?`).run(learningId);
|
|
3856
|
-
}
|
|
3857
|
-
// src/db/coordination.ts
|
|
3858
|
-
init_database();
|
|
3859
|
-
function acquireLock(contactId, agentName, ttlSeconds = 300, reason, sessionId, db) {
|
|
3860
|
-
const _db2 = db || getDatabase();
|
|
3861
|
-
cleanExpiredLocks(_db2);
|
|
3862
|
-
const existing = _db2.query(`SELECT * FROM contact_locks WHERE contact_id=?`).get(contactId);
|
|
3863
|
-
if (existing)
|
|
3864
|
-
return { acquired: false, held_by: existing.agent_name, lock: existing };
|
|
3865
|
-
const id = uuid();
|
|
3866
|
-
const expiresAt = new Date(Date.now() + ttlSeconds * 1000).toISOString();
|
|
3867
|
-
_db2.query(`INSERT INTO contact_locks(id,contact_id,agent_name,reason,acquired_at,expires_at,session_id) VALUES(?,?,?,?,?,?,?)`).run(id, contactId, agentName, reason || null, now(), expiresAt, sessionId || null);
|
|
3868
|
-
return {
|
|
3869
|
-
acquired: true,
|
|
3870
|
-
lock: _db2.query(`SELECT * FROM contact_locks WHERE id=?`).get(id)
|
|
3871
|
-
};
|
|
3872
|
-
}
|
|
3873
|
-
function releaseLock(contactId, agentName, db) {
|
|
3874
|
-
const _db2 = db || getDatabase();
|
|
3875
|
-
const result = _db2.query(`DELETE FROM contact_locks WHERE contact_id=? AND agent_name=?`).run(contactId, agentName);
|
|
3876
|
-
return (result.changes || 0) > 0;
|
|
3877
|
-
}
|
|
3878
|
-
function checkLock(contactId, db) {
|
|
3879
|
-
const _db2 = db || getDatabase();
|
|
3880
|
-
cleanExpiredLocks(_db2);
|
|
3881
|
-
return _db2.query(`SELECT * FROM contact_locks WHERE contact_id=?`).get(contactId);
|
|
3882
|
-
}
|
|
3883
|
-
function cleanExpiredLocks(db) {
|
|
3884
|
-
const _db2 = db || getDatabase();
|
|
3885
|
-
_db2.query(`DELETE FROM contact_locks WHERE expires_at<?`).run(now());
|
|
3886
|
-
}
|
|
3887
|
-
function logAgentActivity(contactId, agentName, action, details, sessionId, db) {
|
|
3888
|
-
const _db2 = db || getDatabase();
|
|
3889
|
-
_db2.query(`INSERT INTO contact_agent_activity(id,contact_id,agent_name,action,details,session_id,created_at) VALUES(?,?,?,?,?,?,?)`).run(uuid(), contactId, agentName, action, details || null, sessionId || null, now());
|
|
3890
|
-
}
|
|
3891
|
-
function getAgentActivity(contactId, limit = 20, db) {
|
|
3892
|
-
const _db2 = db || getDatabase();
|
|
3893
|
-
return _db2.query(`SELECT * FROM contact_agent_activity WHERE contact_id=? ORDER BY created_at DESC LIMIT ?`).all(contactId, limit);
|
|
3894
|
-
}
|
|
3895
|
-
// src/db/graph.ts
|
|
3896
|
-
init_database();
|
|
3897
|
-
function computeRelationshipStrength(contactId, db) {
|
|
3898
|
-
const _db2 = db || getDatabase();
|
|
3899
|
-
const contact = _db2.query(`SELECT last_contacted_at, interaction_count_30d, interaction_count_90d FROM contacts WHERE id=?`).get(contactId);
|
|
3900
|
-
if (!contact)
|
|
3901
|
-
return 0;
|
|
3902
|
-
let score = 50;
|
|
3903
|
-
if (contact.last_contacted_at) {
|
|
3904
|
-
const days = Math.floor((Date.now() - new Date(contact.last_contacted_at).getTime()) / 86400000);
|
|
3905
|
-
score += days < 7 ? 30 : days < 30 ? 20 : days < 90 ? 5 : -20;
|
|
3906
|
-
} else {
|
|
3907
|
-
score -= 20;
|
|
3908
|
-
}
|
|
3909
|
-
score += Math.min(20, (contact.interaction_count_30d || 0) * 4);
|
|
3910
|
-
return Math.max(0, Math.min(100, score));
|
|
3911
|
-
}
|
|
3912
|
-
function findWarmPath(fromContactId, toContactId, db) {
|
|
3913
|
-
const _db2 = db || getDatabase();
|
|
3914
|
-
const visited = new Set([fromContactId]);
|
|
3915
|
-
const queue = [{ id: fromContactId, path: [] }];
|
|
3916
|
-
while (queue.length) {
|
|
3917
|
-
const item = queue.shift();
|
|
3918
|
-
const { id, path } = item;
|
|
3919
|
-
if (id === toContactId)
|
|
3920
|
-
return path;
|
|
3921
|
-
if (path.length >= 4)
|
|
3922
|
-
continue;
|
|
3923
|
-
const neighbors = _db2.query(`SELECT cr.*, c.display_name FROM contact_relationships cr JOIN contacts c ON (CASE WHEN cr.contact_a_id=? THEN cr.contact_b_id ELSE cr.contact_a_id END)=c.id WHERE (cr.contact_a_id=? OR cr.contact_b_id=?) LIMIT 20`).all(id, id, id);
|
|
3924
|
-
for (const n of neighbors) {
|
|
3925
|
-
const nextId = n.contact_a_id === id ? n.contact_b_id : n.contact_a_id;
|
|
3926
|
-
if (visited.has(nextId))
|
|
3927
|
-
continue;
|
|
3928
|
-
visited.add(nextId);
|
|
3929
|
-
queue.push({
|
|
3930
|
-
id: nextId,
|
|
3931
|
-
path: [
|
|
3932
|
-
...path,
|
|
3933
|
-
{ contact_id: nextId, display_name: n.display_name, strength: n.strength_score || 50 }
|
|
3934
|
-
]
|
|
3935
|
-
});
|
|
3936
|
-
}
|
|
3937
|
-
}
|
|
3938
|
-
return [];
|
|
3939
|
-
}
|
|
3940
|
-
function findConnectionsAtCompany(companyId, db) {
|
|
3941
|
-
const _db2 = db || getDatabase();
|
|
3942
|
-
return _db2.query(`SELECT c.id as contact_id, c.display_name, c.job_title, c.relationship_health as strength FROM contacts c WHERE c.company_id=? AND c.archived=0 ORDER BY c.relationship_health DESC`).all(companyId);
|
|
3943
|
-
}
|
|
3944
|
-
function detectCoolingRelationships(db) {
|
|
3945
|
-
const _db2 = db || getDatabase();
|
|
3946
|
-
const cutoff = new Date(Date.now() - 45 * 86400000).toISOString();
|
|
3947
|
-
return _db2.query(`SELECT id as contact_id, display_name, CAST((julianday('now') - julianday(last_contacted_at)) AS INTEGER) as days_since FROM contacts WHERE last_contacted_at IS NOT NULL AND last_contacted_at < ? AND engagement_status != 'ghost' AND archived=0 ORDER BY last_contacted_at ASC LIMIT 50`).all(cutoff);
|
|
3948
|
-
}
|
|
3949
|
-
// src/db/identity.ts
|
|
3950
|
-
init_database();
|
|
3951
|
-
function addIdentity(contactId, system, externalId, externalUrl, confidence = "inferred", db) {
|
|
3952
|
-
const _db2 = db || getDatabase();
|
|
3953
|
-
const id = uuid();
|
|
3954
|
-
_db2.query(`INSERT OR REPLACE INTO contact_identities(id,contact_id,system,external_id,external_url,confidence,created_at) VALUES(?,?,?,?,?,?,?)`).run(id, contactId, system, externalId, externalUrl || null, confidence, now());
|
|
3955
|
-
return _db2.query(`SELECT * FROM contact_identities WHERE id=?`).get(id);
|
|
3956
|
-
}
|
|
3957
|
-
function resolveIdentity(system, externalId, db) {
|
|
3958
|
-
const _db2 = db || getDatabase();
|
|
3959
|
-
const row = _db2.query(`SELECT c.id, c.display_name FROM contacts c JOIN contact_identities ci ON c.id=ci.contact_id WHERE ci.system=? AND ci.external_id=?`).get(system, externalId);
|
|
3960
|
-
return row || null;
|
|
3961
|
-
}
|
|
3962
|
-
function resolveByPartial(partial, db) {
|
|
3963
|
-
const _db2 = db || getDatabase();
|
|
3964
|
-
const matches = new Map;
|
|
3965
|
-
const addMatch = (id, name, title, score, reason) => {
|
|
3966
|
-
const existing = matches.get(id);
|
|
3967
|
-
if (existing) {
|
|
3968
|
-
existing.confidence_score = Math.min(100, existing.confidence_score + score);
|
|
3969
|
-
existing.match_reasons.push(reason);
|
|
3970
|
-
} else {
|
|
3971
|
-
matches.set(id, {
|
|
3972
|
-
contact: { id, display_name: name, job_title: title },
|
|
3973
|
-
confidence_score: score,
|
|
3974
|
-
match_reasons: [reason]
|
|
3975
|
-
});
|
|
3976
|
-
}
|
|
3977
|
-
};
|
|
3978
|
-
if (partial.email) {
|
|
3979
|
-
const rows = _db2.query(`SELECT c.id, c.display_name, c.job_title FROM contacts c JOIN emails e ON c.id=e.contact_id WHERE LOWER(e.address)=LOWER(?)`).all(partial.email);
|
|
3980
|
-
rows.forEach((r) => addMatch(r.id, r.display_name, r.job_title, 90, `email match: ${partial.email}`));
|
|
3981
|
-
}
|
|
3982
|
-
if (partial.linkedin_url) {
|
|
3983
|
-
const rows = _db2.query(`SELECT c.id, c.display_name, c.job_title FROM contacts c JOIN social_profiles sp ON c.id=sp.contact_id WHERE sp.platform='linkedin' AND sp.url LIKE ?`).all(`%${partial.linkedin_url.split("/").pop()}%`);
|
|
3984
|
-
rows.forEach((r) => addMatch(r.id, r.display_name, r.job_title, 85, `linkedin match`));
|
|
3985
|
-
}
|
|
3986
|
-
if (partial.name) {
|
|
3987
|
-
const rows = _db2.query(`SELECT id, display_name, job_title FROM contacts WHERE display_name LIKE ? AND archived=0 LIMIT 10`).all(`%${partial.name}%`);
|
|
3988
|
-
rows.forEach((r) => addMatch(r.id, r.display_name, r.job_title, 40, `name match: ${partial.name}`));
|
|
3989
|
-
}
|
|
3990
|
-
return Array.from(matches.values()).sort((a, b) => b.confidence_score - a.confidence_score);
|
|
3991
|
-
}
|
|
3992
|
-
function getIdentities(contactId, db) {
|
|
3993
|
-
const _db2 = db || getDatabase();
|
|
3994
|
-
return _db2.query(`SELECT * FROM contact_identities WHERE contact_id=? ORDER BY created_at DESC`).all(contactId);
|
|
3995
|
-
}
|
|
3996
|
-
// src/db/org-chart.ts
|
|
3997
|
-
init_database();
|
|
3998
|
-
function addOrgChartEdge(companyId, contactAId, contactBId, edgeType, inferred = false, db) {
|
|
3999
|
-
const _db2 = db || getDatabase();
|
|
4000
|
-
const id = uuid();
|
|
4001
|
-
_db2.query(`INSERT OR IGNORE INTO org_chart_edges(id,company_id,contact_a_id,contact_b_id,edge_type,inferred,created_at) VALUES(?,?,?,?,?,?,?)`).run(id, companyId, contactAId, contactBId, edgeType, inferred ? 1 : 0, now());
|
|
4002
|
-
return _db2.query(`SELECT * FROM org_chart_edges WHERE company_id=? AND contact_a_id=? AND contact_b_id=? AND edge_type=?`).get(companyId, contactAId, contactBId, edgeType);
|
|
4003
|
-
}
|
|
4004
|
-
function listOrgChart(companyId, db) {
|
|
4005
|
-
const _db2 = db || getDatabase();
|
|
4006
|
-
return _db2.query(`SELECT oe.*, ca.display_name as contact_a_name, cb.display_name as contact_b_name FROM org_chart_edges oe JOIN contacts ca ON oe.contact_a_id=ca.id JOIN contacts cb ON oe.contact_b_id=cb.id WHERE oe.company_id=?`).all(companyId);
|
|
4007
|
-
}
|
|
4008
|
-
function setDealContactRole(dealId, contactId, accountRole, db) {
|
|
4009
|
-
const _db2 = db || getDatabase();
|
|
4010
|
-
const id = uuid();
|
|
4011
|
-
_db2.query(`INSERT OR REPLACE INTO deal_contact_roles(id,deal_id,contact_id,account_role,created_at) VALUES(?,?,?,?,?)`).run(id, dealId, contactId, accountRole, now());
|
|
4012
|
-
return _db2.query(`SELECT * FROM deal_contact_roles WHERE deal_id=? AND contact_id=?`).get(dealId, contactId);
|
|
4013
|
-
}
|
|
4014
|
-
function getDealTeam(dealId, db) {
|
|
4015
|
-
const _db2 = db || getDatabase();
|
|
4016
|
-
return _db2.query(`SELECT dr.*, c.display_name, c.job_title FROM deal_contact_roles dr JOIN contacts c ON dr.contact_id=c.id WHERE dr.deal_id=?`).all(dealId);
|
|
4017
|
-
}
|
|
4018
|
-
function getCoverageGaps(companyId, db) {
|
|
4019
|
-
const _db2 = db || getDatabase();
|
|
4020
|
-
const total = _db2.query(`SELECT COUNT(*) c FROM contacts WHERE company_id=? AND archived=0`).get(companyId).c;
|
|
4021
|
-
const hasManager = _db2.query(`SELECT COUNT(*) c FROM org_chart_edges WHERE company_id=? AND edge_type='manages'`).get(companyId).c > 0;
|
|
4022
|
-
const hasEco = _db2.query(`SELECT COUNT(*) c FROM deal_contact_roles dr JOIN deals d ON dr.deal_id=d.id WHERE d.company_id=? AND dr.account_role='economic_buyer'`).get(companyId).c > 0;
|
|
4023
|
-
const hasTech = _db2.query(`SELECT COUNT(*) c FROM deal_contact_roles dr JOIN deals d ON dr.deal_id=d.id WHERE d.company_id=? AND dr.account_role='technical_evaluator'`).get(companyId).c > 0;
|
|
4024
|
-
const missing = [
|
|
4025
|
-
!hasManager && "org chart relationships",
|
|
4026
|
-
!hasEco && "economic buyer",
|
|
4027
|
-
!hasTech && "technical evaluator"
|
|
4028
|
-
].filter(Boolean);
|
|
4029
|
-
return {
|
|
4030
|
-
total_contacts: total,
|
|
4031
|
-
has_manager: hasManager,
|
|
4032
|
-
has_technical: hasTech,
|
|
4033
|
-
has_economic_buyer: hasEco,
|
|
4034
|
-
suggestion: missing.length ? `Missing: ${missing.join(", ")}` : "Good coverage"
|
|
4035
|
-
};
|
|
4036
|
-
}
|
|
4037
|
-
// src/db/signals.ts
|
|
4038
|
-
init_database();
|
|
4039
|
-
function getRelationshipSignals(contactId, db) {
|
|
4040
|
-
const _db2 = db || getDatabase();
|
|
4041
|
-
const row = _db2.query(`SELECT id as contact_id, display_name, last_contacted_at, interaction_count_30d, engagement_status, relationship_health FROM contacts WHERE id=?`).get(contactId);
|
|
4042
|
-
if (!row)
|
|
4043
|
-
return [];
|
|
4044
|
-
const daysSince = row.last_contacted_at ? Math.floor((Date.now() - new Date(row.last_contacted_at).getTime()) / 86400000) : null;
|
|
4045
|
-
const signals = [];
|
|
4046
|
-
const cnt = row.interaction_count_30d || 0;
|
|
4047
|
-
const health = row.relationship_health ?? 50;
|
|
4048
|
-
if (daysSince === null || daysSince > 180) {
|
|
4049
|
-
signals.push({ ...row, signal_type: "ghost", days_since_contact: daysSince, reason: "No contact in 180+ days or never contacted" });
|
|
4050
|
-
} else if (daysSince > 60 && cnt === 0) {
|
|
4051
|
-
signals.push({ ...row, signal_type: "cooling", days_since_contact: daysSince, reason: `No contact in ${daysSince} days, no recent interactions` });
|
|
4052
|
-
} else if (cnt > 3 && health > 70) {
|
|
4053
|
-
signals.push({ ...row, signal_type: "warming", days_since_contact: daysSince, reason: `${cnt} interactions in last 30 days, health score ${health}` });
|
|
4054
|
-
} else {
|
|
4055
|
-
signals.push({ ...row, signal_type: "healthy", days_since_contact: daysSince, reason: `Last contact ${daysSince}d ago, ${cnt} interactions in 30d` });
|
|
4056
|
-
}
|
|
4057
|
-
return signals;
|
|
4058
|
-
}
|
|
4059
|
-
function getGhostContacts(db) {
|
|
4060
|
-
const _db2 = db || getDatabase();
|
|
4061
|
-
const rows = _db2.query(`SELECT id as contact_id, display_name, last_contacted_at, interaction_count_30d, engagement_status, relationship_health FROM contacts WHERE (last_contacted_at IS NULL OR julianday('now') - julianday(last_contacted_at) > 180) AND archived=0 ORDER BY last_contacted_at ASC LIMIT 50`).all();
|
|
4062
|
-
return rows.map((r) => ({
|
|
4063
|
-
...r,
|
|
4064
|
-
signal_type: "ghost",
|
|
4065
|
-
days_since_contact: r.last_contacted_at ? Math.floor((Date.now() - new Date(r.last_contacted_at).getTime()) / 86400000) : null,
|
|
4066
|
-
reason: "No contact in 180+ days or never contacted"
|
|
4067
|
-
}));
|
|
4068
|
-
}
|
|
4069
|
-
function getWarmingContacts(db) {
|
|
4070
|
-
const _db2 = db || getDatabase();
|
|
4071
|
-
const rows = _db2.query(`SELECT id as contact_id, display_name, last_contacted_at, interaction_count_30d, engagement_status, relationship_health FROM contacts WHERE interaction_count_30d > 2 AND relationship_health > 60 AND archived=0 ORDER BY relationship_health DESC LIMIT 50`).all();
|
|
4072
|
-
return rows.map((r) => ({
|
|
4073
|
-
...r,
|
|
4074
|
-
signal_type: "warming",
|
|
4075
|
-
days_since_contact: r.last_contacted_at ? Math.floor((Date.now() - new Date(r.last_contacted_at).getTime()) / 86400000) : null,
|
|
4076
|
-
reason: `${r.interaction_count_30d} interactions in last 30 days`
|
|
4077
|
-
}));
|
|
4078
|
-
}
|
|
4079
|
-
function recomputeAllSignals(db) {
|
|
4080
|
-
const _db2 = db || getDatabase();
|
|
4081
|
-
_db2.query(`
|
|
4082
|
-
UPDATE contacts SET
|
|
4083
|
-
engagement_status = CASE
|
|
4084
|
-
WHEN interaction_count_30d > 3 THEN 'warm'
|
|
4085
|
-
WHEN last_contacted_at IS NULL OR julianday('now') - julianday(last_contacted_at) > 180 THEN 'ghost'
|
|
4086
|
-
WHEN julianday('now') - julianday(last_contacted_at) > 60 THEN 'cooling'
|
|
4087
|
-
ELSE 'active'
|
|
4088
|
-
END,
|
|
4089
|
-
updated_at = datetime('now')
|
|
4090
|
-
WHERE archived = 0
|
|
4091
|
-
`).run();
|
|
4092
|
-
const result = _db2.query(`SELECT changes() as n`).get();
|
|
4093
|
-
return { updated: result?.n ?? 0 };
|
|
4094
|
-
}
|
|
4095
|
-
// src/db/freshness.ts
|
|
4096
|
-
init_database();
|
|
4097
|
-
var SCORED_FIELDS = ["display_name", "job_title", "company_id", "emails", "phones", "last_contacted_at"];
|
|
4098
|
-
function getFreshnessScore(contactId, db) {
|
|
4099
|
-
const _db2 = db || getDatabase();
|
|
4100
|
-
const contact = _db2.query(`SELECT * FROM contacts WHERE id=?`).get(contactId);
|
|
4101
|
-
if (!contact)
|
|
4102
|
-
throw new Error(`Contact not found: ${contactId}`);
|
|
4103
|
-
let historyRows = [];
|
|
4104
|
-
try {
|
|
4105
|
-
historyRows = _db2.query(`SELECT field_name, new_value, source, created_at FROM contact_field_history WHERE contact_id=? ORDER BY created_at DESC`).all(contactId);
|
|
4106
|
-
} catch {}
|
|
4107
|
-
let verifiedRows = [];
|
|
4108
|
-
try {
|
|
4109
|
-
verifiedRows = _db2.query(`SELECT field_name, verified_at, source FROM field_verifications WHERE contact_id=?`).all(contactId);
|
|
4110
|
-
} catch {}
|
|
4111
|
-
const verifiedMap = new Map(verifiedRows.map((r) => [r.field_name, r]));
|
|
4112
|
-
const historyMap = new Map;
|
|
4113
|
-
for (const r of historyRows) {
|
|
4114
|
-
if (!historyMap.has(r.field_name))
|
|
4115
|
-
historyMap.set(r.field_name, r);
|
|
4116
|
-
}
|
|
4117
|
-
const fields = SCORED_FIELDS.map((field) => {
|
|
4118
|
-
let value = null;
|
|
4119
|
-
if (field === "emails") {
|
|
4120
|
-
const emailRow = _db2.query(`SELECT address FROM emails WHERE contact_id=? LIMIT 1`).get(contactId);
|
|
4121
|
-
value = emailRow?.address ?? null;
|
|
4122
|
-
} else if (field === "phones") {
|
|
4123
|
-
const phoneRow = _db2.query(`SELECT number FROM phones WHERE contact_id=? LIMIT 1`).get(contactId);
|
|
4124
|
-
value = phoneRow?.number ?? null;
|
|
4125
|
-
} else {
|
|
4126
|
-
value = contact[field] != null ? String(contact[field]) : null;
|
|
4127
|
-
}
|
|
4128
|
-
const verified = verifiedMap.get(field);
|
|
4129
|
-
const history = historyMap.get(field);
|
|
4130
|
-
let confidence = "unknown";
|
|
4131
|
-
let days_old = null;
|
|
4132
|
-
let last_verified_at = null;
|
|
4133
|
-
let source = null;
|
|
4134
|
-
if (verified) {
|
|
4135
|
-
confidence = "verified";
|
|
4136
|
-
last_verified_at = verified.verified_at;
|
|
4137
|
-
source = verified.source;
|
|
4138
|
-
days_old = Math.floor((Date.now() - new Date(verified.verified_at).getTime()) / 86400000);
|
|
4139
|
-
} else if (history) {
|
|
4140
|
-
confidence = history.source === "import" ? "imported" : "inferred";
|
|
4141
|
-
last_verified_at = history.created_at;
|
|
4142
|
-
source = history.source;
|
|
4143
|
-
days_old = Math.floor((Date.now() - new Date(history.created_at).getTime()) / 86400000);
|
|
4144
|
-
if (days_old > 365)
|
|
4145
|
-
confidence = "stale";
|
|
4146
|
-
} else if (value) {
|
|
4147
|
-
confidence = "inferred";
|
|
4148
|
-
}
|
|
4149
|
-
return { field_name: field, value, last_verified_at, source, confidence, days_old };
|
|
4150
|
-
});
|
|
4151
|
-
const fieldScore = fields.reduce((acc, f) => {
|
|
4152
|
-
if (!f.value)
|
|
4153
|
-
return acc;
|
|
4154
|
-
if (f.confidence === "verified")
|
|
4155
|
-
return acc + 20;
|
|
4156
|
-
if (f.confidence === "imported" || f.confidence === "inferred")
|
|
4157
|
-
return acc + 10;
|
|
4158
|
-
return acc + 5;
|
|
4159
|
-
}, 0);
|
|
4160
|
-
const overall_score = Math.min(100, fieldScore);
|
|
4161
|
-
return {
|
|
4162
|
-
contact_id: contactId,
|
|
4163
|
-
overall_score,
|
|
4164
|
-
fields,
|
|
4165
|
-
stale_fields: fields.filter((f) => f.confidence === "stale" || !f.value && f.field_name !== "phones").map((f) => f.field_name),
|
|
4166
|
-
verified_fields: fields.filter((f) => f.confidence === "verified").map((f) => f.field_name)
|
|
4167
|
-
};
|
|
4168
|
-
}
|
|
4169
|
-
function getStaleContacts(threshold = 40, db) {
|
|
4170
|
-
const _db2 = db || getDatabase();
|
|
4171
|
-
const rows = _db2.query(`SELECT * FROM (
|
|
4172
|
-
SELECT c.id as contact_id, c.display_name,
|
|
4173
|
-
(CASE WHEN c.job_title IS NOT NULL THEN 15 ELSE 0 END +
|
|
4174
|
-
CASE WHEN c.company_id IS NOT NULL THEN 15 ELSE 0 END +
|
|
4175
|
-
CASE WHEN c.last_contacted_at IS NOT NULL THEN 20 ELSE 0 END +
|
|
4176
|
-
CASE WHEN EXISTS(SELECT 1 FROM emails WHERE contact_id=c.id) THEN 20 ELSE 0 END +
|
|
4177
|
-
CASE WHEN EXISTS(SELECT 1 FROM phones WHERE contact_id=c.id) THEN 15 ELSE 0 END +
|
|
4178
|
-
CASE WHEN c.notes IS NOT NULL THEN 10 ELSE 0 END +
|
|
4179
|
-
CASE WHEN EXISTS(SELECT 1 FROM contact_tags WHERE contact_id=c.id) THEN 5 ELSE 0 END
|
|
4180
|
-
) as score
|
|
4181
|
-
FROM contacts c WHERE c.archived=0
|
|
4182
|
-
) WHERE score < ? ORDER BY score ASC LIMIT 100`).all(threshold);
|
|
4183
|
-
return rows;
|
|
4184
|
-
}
|
|
4185
|
-
function markFieldVerified(contactId, fieldName, source, db) {
|
|
4186
|
-
const _db2 = db || getDatabase();
|
|
4187
|
-
try {
|
|
4188
|
-
_db2.query(`INSERT OR REPLACE INTO field_verifications(contact_id,field_name,verified_at,source) VALUES(?,?,?,?)`).run(contactId, fieldName, now(), source || null);
|
|
4189
|
-
} catch {
|
|
4190
|
-
_db2.query(`INSERT INTO activity_log(id,contact_id,action,details,created_at) VALUES(?,?,?,?,?)`).run(crypto.randomUUID(), contactId, "field.verified", JSON.stringify({ field_name: fieldName, source }), now());
|
|
4191
|
-
}
|
|
4192
|
-
}
|
|
4193
|
-
// src/lib/context.ts
|
|
4194
|
-
init_database();
|
|
4195
|
-
init_contacts();
|
|
4196
|
-
function getContactCard(contactId, db) {
|
|
4197
|
-
const _db2 = db || getDatabase();
|
|
4198
|
-
const c = getContact(contactId, _db2);
|
|
4199
|
-
const emails = c.emails;
|
|
4200
|
-
const phones = c.phones;
|
|
4201
|
-
const company = c.company;
|
|
4202
|
-
return {
|
|
4203
|
-
id: c.id,
|
|
4204
|
-
display_name: c.display_name,
|
|
4205
|
-
job_title: c.job_title,
|
|
4206
|
-
company: company?.name,
|
|
4207
|
-
primary_email: emails?.find((e) => e.is_primary)?.address || emails?.[0]?.address,
|
|
4208
|
-
primary_phone: phones?.find((p) => p.is_primary)?.number || phones?.[0]?.number
|
|
4209
|
-
};
|
|
4210
|
-
}
|
|
4211
|
-
function getContactBrief(contactId, taskContext, db) {
|
|
4212
|
-
const _db2 = db || getDatabase();
|
|
4213
|
-
const c = getContact(contactId, _db2);
|
|
4214
|
-
const notes = listNotes(contactId, _db2).slice(0, 3);
|
|
4215
|
-
const learnings = getLearnings(contactId, { min_importance: 7 }, _db2).slice(0, 5);
|
|
4216
|
-
const ctx = (taskContext ?? "").toLowerCase();
|
|
4217
|
-
const lastContactedAt = c.last_contacted_at;
|
|
4218
|
-
const daysSince = lastContactedAt ? Math.floor((Date.now() - new Date(lastContactedAt).getTime()) / 86400000) : null;
|
|
4219
|
-
const company = c.company;
|
|
4220
|
-
const brief = {
|
|
4221
|
-
id: c.id,
|
|
4222
|
-
display_name: c.display_name,
|
|
4223
|
-
job_title: c.job_title,
|
|
4224
|
-
company: company?.name,
|
|
4225
|
-
status: c.status,
|
|
4226
|
-
last_contacted: daysSince !== null ? `${daysSince}d ago` : "never",
|
|
4227
|
-
relationship_health: c.relationship_health,
|
|
4228
|
-
engagement_status: c.engagement_status,
|
|
4229
|
-
preferred_contact: c.preferred_contact_method || c.preferred_channel
|
|
4230
|
-
};
|
|
4231
|
-
if (ctx.includes("meeting") || ctx.includes("call") || ctx.includes("prep")) {
|
|
4232
|
-
brief.recent_notes = notes.map((n) => ({ date: n.created_at?.slice(0, 10), content: n.body }));
|
|
4233
|
-
brief.key_learnings = learnings.map((l) => l.content);
|
|
4234
|
-
}
|
|
4235
|
-
if (ctx.includes("outreach") || ctx.includes("email")) {
|
|
4236
|
-
brief.preferred_channel = c.preferred_channel;
|
|
4237
|
-
brief.follow_up_at = c.follow_up_at;
|
|
4238
|
-
}
|
|
4239
|
-
if (ctx.includes("deal")) {
|
|
4240
|
-
const dealCompany = c.company;
|
|
4241
|
-
brief.company_details = dealCompany ? { name: dealCompany.name, domain: dealCompany.domain } : null;
|
|
4242
|
-
}
|
|
4243
|
-
if (learnings.length)
|
|
4244
|
-
brief.top_learnings = learnings.map((l) => l.content);
|
|
4245
|
-
return brief;
|
|
4246
|
-
}
|
|
4247
|
-
async function assembleContext(contactIds, format = "meeting_prep", db) {
|
|
4248
|
-
const _db2 = db || getDatabase();
|
|
4249
|
-
const briefs = contactIds.map((id) => {
|
|
4250
|
-
try {
|
|
4251
|
-
return getContactBrief(id, format, _db2);
|
|
4252
|
-
} catch {
|
|
4253
|
-
return { id, error: "not found" };
|
|
4254
|
-
}
|
|
4255
|
-
});
|
|
4256
|
-
return { format, contact_count: contactIds.length, assembled_at: new Date().toISOString(), contacts: briefs };
|
|
4257
|
-
}
|
|
4258
|
-
// src/lib/embeddings.ts
|
|
4259
|
-
init_database();
|
|
4260
|
-
function tokenize(text) {
|
|
4261
|
-
return text.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter((t) => t.length > 2);
|
|
4262
|
-
}
|
|
4263
|
-
function buildTfIdf(tokens) {
|
|
4264
|
-
const freq = new Map;
|
|
4265
|
-
for (const t of tokens)
|
|
4266
|
-
freq.set(t, (freq.get(t) || 0) + 1);
|
|
4267
|
-
const max = Math.max(...freq.values(), 1);
|
|
4268
|
-
const result = new Map;
|
|
4269
|
-
freq.forEach((v, k) => result.set(k, v / max));
|
|
4270
|
-
return result;
|
|
4271
|
-
}
|
|
4272
|
-
function cosineSimilarity(a, b) {
|
|
4273
|
-
let dot = 0, normA = 0, normB = 0;
|
|
4274
|
-
a.forEach((v, k) => {
|
|
4275
|
-
if (b.has(k))
|
|
4276
|
-
dot += v * b.get(k);
|
|
4277
|
-
normA += v * v;
|
|
4278
|
-
});
|
|
4279
|
-
b.forEach((v) => normB += v * v);
|
|
4280
|
-
return normA && normB ? dot / (Math.sqrt(normA) * Math.sqrt(normB)) : 0;
|
|
4281
|
-
}
|
|
4282
|
-
function buildContactEmbeddingText(contact) {
|
|
4283
|
-
const tags = contact.tags ?? [];
|
|
4284
|
-
const socialProfiles = contact.social_profiles ?? [];
|
|
4285
|
-
const company = contact.company;
|
|
4286
|
-
const parts = [
|
|
4287
|
-
contact.display_name,
|
|
4288
|
-
contact.job_title,
|
|
4289
|
-
contact.notes,
|
|
4290
|
-
company?.name,
|
|
4291
|
-
company?.industry,
|
|
4292
|
-
...tags.map((t) => t.name),
|
|
4293
|
-
...socialProfiles.map((s) => s.platform)
|
|
4294
|
-
].filter(Boolean);
|
|
4295
|
-
return parts.join(" ");
|
|
4296
|
-
}
|
|
4297
|
-
async function embedContact(contactId, db) {
|
|
4298
|
-
const { getContact: getContact2 } = await Promise.resolve().then(() => (init_contacts(), exports_contacts));
|
|
4299
|
-
const _db2 = db || getDatabase();
|
|
4300
|
-
const contact = getContact2(contactId, _db2);
|
|
4301
|
-
const text = buildContactEmbeddingText(contact);
|
|
4302
|
-
const tokens = tokenize(text);
|
|
4303
|
-
const tfidf = buildTfIdf(tokens);
|
|
4304
|
-
const embedding = JSON.stringify(Array.from(tfidf.entries()).sort((a, b) => b[1] - a[1]).slice(0, 100));
|
|
4305
|
-
_db2.query(`INSERT OR REPLACE INTO contact_embeddings(contact_id, embedding, model, embedded_text, created_at, updated_at) VALUES(?,?,'tfidf',?,?,?)`).run(contactId, embedding, text.slice(0, 500), now(), now());
|
|
4306
|
-
}
|
|
4307
|
-
async function embedAllContacts(db) {
|
|
4308
|
-
const _db2 = db || getDatabase();
|
|
4309
|
-
const contacts = _db2.query(`SELECT id FROM contacts WHERE archived=0`).all();
|
|
4310
|
-
for (const c of contacts) {
|
|
4311
|
-
try {
|
|
4312
|
-
await embedContact(c.id, _db2);
|
|
4313
|
-
} catch {}
|
|
4314
|
-
}
|
|
4315
|
-
return contacts.length;
|
|
4316
|
-
}
|
|
4317
|
-
function semanticSearch(query, limit = 10, db) {
|
|
4318
|
-
const _db2 = db || getDatabase();
|
|
4319
|
-
const queryTokens = buildTfIdf(tokenize(query));
|
|
4320
|
-
let embeddings = [];
|
|
4321
|
-
try {
|
|
4322
|
-
embeddings = _db2.query(`SELECT contact_id, embedding FROM contact_embeddings`).all();
|
|
4323
|
-
} catch {
|
|
4324
|
-
return [];
|
|
4325
|
-
}
|
|
4326
|
-
const results = embeddings.map((e) => {
|
|
4327
|
-
try {
|
|
4328
|
-
const emb = new Map(JSON.parse(e.embedding));
|
|
4329
|
-
return { contact_id: e.contact_id, score: cosineSimilarity(queryTokens, emb) };
|
|
4330
|
-
} catch {
|
|
4331
|
-
return { contact_id: e.contact_id, score: 0 };
|
|
4332
|
-
}
|
|
4333
|
-
}).filter((r) => r.score > 0).sort((a, b) => b.score - a.score).slice(0, limit);
|
|
4334
|
-
return results;
|
|
4335
|
-
}
|
|
4336
|
-
// src/lib/signature-parser.ts
|
|
4337
|
-
function parseEmailSignature(text) {
|
|
4338
|
-
const result = {};
|
|
4339
|
-
const phoneMatch = text.match(/(\+?[\d\s\-\(\)]{7,20})/);
|
|
4340
|
-
if (phoneMatch)
|
|
4341
|
-
result.phone = phoneMatch[1]?.trim();
|
|
4342
|
-
const emailMatch = text.match(/[\w.+-]+@[\w-]+\.[a-z]{2,}/i);
|
|
4343
|
-
if (emailMatch)
|
|
4344
|
-
result.email = emailMatch[0];
|
|
4345
|
-
const linkedinMatch = text.match(/(?:linkedin\.com\/in\/)([\w-]+)/i);
|
|
4346
|
-
if (linkedinMatch)
|
|
4347
|
-
result.linkedin = `https://linkedin.com/in/${linkedinMatch[1]}`;
|
|
4348
|
-
const websiteMatch = text.match(/https?:\/\/(?!linkedin)(?!twitter)[\w.-]+\.[a-z]{2,}/i);
|
|
4349
|
-
if (websiteMatch)
|
|
4350
|
-
result.website = websiteMatch[0];
|
|
4351
|
-
const lines = text.split(`
|
|
4352
|
-
`).map((l) => l.trim()).filter((l) => l.length > 2 && l.length < 80);
|
|
4353
|
-
if (lines[0])
|
|
4354
|
-
result.name = lines[0];
|
|
4355
|
-
for (const line of lines.slice(1)) {
|
|
4356
|
-
if (line.match(/\b(CEO|CTO|VP|Director|Manager|Engineer|Partner|Associate|Consultant|Analyst|President|Founder)\b/i)) {
|
|
4357
|
-
result.title = line;
|
|
4358
|
-
} else if (!result.company && line.match(/^[A-Z][A-Za-z\s,\.]+$/) && !line.includes("@")) {
|
|
4359
|
-
result.company = line;
|
|
4360
|
-
}
|
|
4361
|
-
}
|
|
4362
|
-
return result;
|
|
4363
|
-
}
|
|
4364
|
-
function extractContactsFromEmailThread(participants) {
|
|
4365
|
-
return participants.map((p) => {
|
|
4366
|
-
const sig = p.signature ? parseEmailSignature(p.signature) : {};
|
|
4367
|
-
const name = p.name || sig.name || p.email.split("@")[0] || "Unknown";
|
|
4368
|
-
const contact = {
|
|
4369
|
-
display_name: name,
|
|
4370
|
-
emails: [{ address: p.email, type: "work", is_primary: true }],
|
|
4371
|
-
source: "import"
|
|
4372
|
-
};
|
|
4373
|
-
if (sig.title)
|
|
4374
|
-
contact.job_title = sig.title;
|
|
4375
|
-
if (sig.phone)
|
|
4376
|
-
contact.phones = [{ number: sig.phone, type: "work", is_primary: true }];
|
|
4377
|
-
if (sig.linkedin)
|
|
4378
|
-
contact.social_profiles = [{ platform: "linkedin", url: sig.linkedin, is_primary: true }];
|
|
4379
|
-
if (sig.website)
|
|
4380
|
-
contact.website = sig.website;
|
|
4381
|
-
return contact;
|
|
4382
|
-
});
|
|
4383
|
-
}
|
|
4384
|
-
// src/lib/meeting-capture.ts
|
|
4385
|
-
init_database();
|
|
4386
|
-
async function ingestMeetingParticipants(event, db) {
|
|
4387
|
-
const { findOrCreateContact: findOrCreateContact2 } = await Promise.resolve().then(() => (init_contacts(), exports_contacts));
|
|
4388
|
-
const { logEvent: logEvent2 } = await Promise.resolve().then(() => (init_events(), exports_events));
|
|
4389
|
-
const _db2 = db || getDatabase();
|
|
4390
|
-
let created = 0;
|
|
4391
|
-
let updated = 0;
|
|
4392
|
-
const ids = [];
|
|
4393
|
-
for (const a of event.attendees) {
|
|
4394
|
-
try {
|
|
4395
|
-
const nameParts = a.name.split(" ");
|
|
4396
|
-
const result = await findOrCreateContact2({
|
|
4397
|
-
display_name: a.name,
|
|
4398
|
-
first_name: nameParts[0],
|
|
4399
|
-
last_name: nameParts.slice(1).join(" ") || undefined,
|
|
4400
|
-
emails: [{ address: a.email, type: "work", is_primary: true }],
|
|
4401
|
-
source: "import"
|
|
4402
|
-
}, _db2);
|
|
4403
|
-
ids.push(result.contact.id);
|
|
4404
|
-
if (result.created)
|
|
4405
|
-
created++;
|
|
4406
|
-
else
|
|
4407
|
-
updated++;
|
|
4408
|
-
} catch {}
|
|
4409
|
-
}
|
|
4410
|
-
if (ids.length) {
|
|
4411
|
-
try {
|
|
4412
|
-
logEvent2({
|
|
4413
|
-
title: event.title,
|
|
4414
|
-
type: "meeting",
|
|
4415
|
-
event_date: event.event_date,
|
|
4416
|
-
contact_ids: ids,
|
|
4417
|
-
notes: event.context
|
|
4418
|
-
}, _db2);
|
|
4419
|
-
} catch {}
|
|
4420
|
-
}
|
|
4421
|
-
return { created, updated, contact_ids: ids };
|
|
4422
|
-
}
|
|
4423
|
-
|
|
4424
|
-
// src/index.ts
|
|
4425
|
-
init_contacts();
|
|
4426
|
-
|
|
4427
|
-
// src/lib/images.ts
|
|
4428
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync2, copyFileSync, unlinkSync, readdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
4429
|
-
import { join as join3, extname, basename } from "path";
|
|
4430
|
-
var IMAGES_DIR = join3(process.env["HOME"] || "~", ".contacts", "images");
|
|
4431
|
-
function ensureImagesDir() {
|
|
4432
|
-
if (!existsSync3(IMAGES_DIR))
|
|
4433
|
-
mkdirSync2(IMAGES_DIR, { recursive: true });
|
|
4434
|
-
}
|
|
4435
|
-
function getImagesDir() {
|
|
4436
|
-
ensureImagesDir();
|
|
4437
|
-
return IMAGES_DIR;
|
|
4438
|
-
}
|
|
4439
|
-
function saveImage(entityId, source, options) {
|
|
4440
|
-
ensureImagesDir();
|
|
4441
|
-
deleteImage(entityId);
|
|
4442
|
-
const base64Match = source.match(/^data:image\/(\w+);base64,(.+)$/s);
|
|
4443
|
-
if (base64Match) {
|
|
4444
|
-
const ext2 = base64Match[1] === "jpeg" ? "jpg" : base64Match[1];
|
|
4445
|
-
const data = Buffer.from(base64Match[2], "base64");
|
|
4446
|
-
const filename2 = `${entityId}.${ext2}`;
|
|
4447
|
-
writeFileSync(join3(IMAGES_DIR, filename2), data);
|
|
4448
|
-
return filename2;
|
|
4449
|
-
}
|
|
4450
|
-
if (!existsSync3(source) && /^[A-Za-z0-9+/=\n\r]+$/.test(source.trim()) && source.length > 100) {
|
|
4451
|
-
const ext2 = options?.format || "jpg";
|
|
4452
|
-
const data = Buffer.from(source.trim(), "base64");
|
|
4453
|
-
const filename2 = `${entityId}.${ext2}`;
|
|
4454
|
-
writeFileSync(join3(IMAGES_DIR, filename2), data);
|
|
4455
|
-
return filename2;
|
|
4456
|
-
}
|
|
4457
|
-
if (!existsSync3(source)) {
|
|
4458
|
-
throw new Error(`Image file not found: ${source}`);
|
|
4459
|
-
}
|
|
4460
|
-
const ext = extname(source).slice(1).toLowerCase() || "jpg";
|
|
4461
|
-
const validExts = ["jpg", "jpeg", "png", "gif", "webp", "svg", "avif", "ico"];
|
|
4462
|
-
if (!validExts.includes(ext)) {
|
|
4463
|
-
throw new Error(`Unsupported image format: ${ext}. Supported: ${validExts.join(", ")}`);
|
|
4464
|
-
}
|
|
4465
|
-
const filename = `${entityId}.${ext === "jpeg" ? "jpg" : ext}`;
|
|
4466
|
-
copyFileSync(source, join3(IMAGES_DIR, filename));
|
|
4467
|
-
return filename;
|
|
4468
|
-
}
|
|
4469
|
-
function getImagePath(entityId) {
|
|
4470
|
-
ensureImagesDir();
|
|
4471
|
-
const files = readdirSync(IMAGES_DIR);
|
|
4472
|
-
const match = files.find((f) => f.startsWith(`${entityId}.`));
|
|
4473
|
-
return match ? join3(IMAGES_DIR, match) : null;
|
|
4474
|
-
}
|
|
4475
|
-
function getImageAsBase64(entityId) {
|
|
4476
|
-
const path = getImagePath(entityId);
|
|
4477
|
-
if (!path)
|
|
4478
|
-
return null;
|
|
4479
|
-
const ext = extname(path).slice(1);
|
|
4480
|
-
const mime = ext === "jpg" ? "image/jpeg" : ext === "svg" ? "image/svg+xml" : `image/${ext}`;
|
|
4481
|
-
const data = readFileSync2(path);
|
|
4482
|
-
return `data:${mime};base64,${data.toString("base64")}`;
|
|
4483
|
-
}
|
|
4484
|
-
function deleteImage(entityId) {
|
|
4485
|
-
ensureImagesDir();
|
|
4486
|
-
const files = readdirSync(IMAGES_DIR);
|
|
4487
|
-
let deleted = false;
|
|
4488
|
-
for (const f of files) {
|
|
4489
|
-
if (f.startsWith(`${entityId}.`)) {
|
|
4490
|
-
unlinkSync(join3(IMAGES_DIR, f));
|
|
4491
|
-
deleted = true;
|
|
4492
|
-
}
|
|
4493
|
-
}
|
|
4494
|
-
return deleted;
|
|
4495
|
-
}
|
|
4496
|
-
function listImages() {
|
|
4497
|
-
ensureImagesDir();
|
|
4498
|
-
const files = readdirSync(IMAGES_DIR).filter((f) => !f.startsWith("."));
|
|
4499
|
-
return files.map((f) => ({
|
|
4500
|
-
entity_id: basename(f, extname(f)),
|
|
4501
|
-
filename: f,
|
|
4502
|
-
path: join3(IMAGES_DIR, f)
|
|
4503
|
-
}));
|
|
4504
|
-
}
|
|
4505
|
-
// src/lib/vault.ts
|
|
4506
|
-
import { existsSync as existsSync4, readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync as mkdirSync3, unlinkSync as unlinkSync2 } from "fs";
|
|
4507
|
-
import { join as join4 } from "path";
|
|
4508
|
-
import { createCipheriv, createDecipheriv, randomBytes, pbkdf2Sync, createHash } from "crypto";
|
|
4509
|
-
var VAULT_DIR = join4(process.env["HOME"] || "~", ".contacts");
|
|
4510
|
-
var VAULT_CONFIG = join4(VAULT_DIR, "vault.json");
|
|
4511
|
-
var VAULT_SESSION = join4(VAULT_DIR, ".vault-session");
|
|
4512
|
-
var DOCUMENTS_DIR = join4(VAULT_DIR, "documents");
|
|
4513
|
-
var SESSION_TTL_MS = 30 * 60 * 1000;
|
|
4514
|
-
var _derivedKey = null;
|
|
4515
|
-
function deriveKey(passphrase, salt) {
|
|
4516
|
-
return pbkdf2Sync(passphrase, salt, 1e5, 32, "sha512");
|
|
4517
|
-
}
|
|
4518
|
-
function saveSession(key) {
|
|
4519
|
-
const session = {
|
|
4520
|
-
key: key.toString("hex"),
|
|
4521
|
-
expires_at: new Date(Date.now() + SESSION_TTL_MS).toISOString()
|
|
4522
|
-
};
|
|
4523
|
-
writeFileSync2(VAULT_SESSION, JSON.stringify(session), { mode: 384 });
|
|
4524
|
-
}
|
|
4525
|
-
function loadSession() {
|
|
4526
|
-
if (!existsSync4(VAULT_SESSION))
|
|
4527
|
-
return null;
|
|
4528
|
-
try {
|
|
4529
|
-
const session = JSON.parse(readFileSync3(VAULT_SESSION, "utf-8"));
|
|
4530
|
-
if (new Date(session.expires_at).getTime() < Date.now()) {
|
|
4531
|
-
try {
|
|
4532
|
-
unlinkSync2(VAULT_SESSION);
|
|
4533
|
-
} catch {}
|
|
4534
|
-
return null;
|
|
4535
|
-
}
|
|
4536
|
-
return Buffer.from(session.key, "hex");
|
|
4537
|
-
} catch {
|
|
4538
|
-
return null;
|
|
4539
|
-
}
|
|
4540
|
-
}
|
|
4541
|
-
function clearSession() {
|
|
4542
|
-
try {
|
|
4543
|
-
if (existsSync4(VAULT_SESSION))
|
|
4544
|
-
unlinkSync2(VAULT_SESSION);
|
|
4545
|
-
} catch {}
|
|
4546
|
-
}
|
|
4547
|
-
function initVault(passphrase) {
|
|
4548
|
-
if (!existsSync4(VAULT_DIR))
|
|
4549
|
-
mkdirSync3(VAULT_DIR, { recursive: true });
|
|
4550
|
-
if (!existsSync4(DOCUMENTS_DIR))
|
|
4551
|
-
mkdirSync3(DOCUMENTS_DIR, { recursive: true });
|
|
4552
|
-
const salt = randomBytes(32);
|
|
4553
|
-
const key = deriveKey(passphrase, salt);
|
|
4554
|
-
const keyHash = createHash("sha256").update(key).digest("hex");
|
|
4555
|
-
const config = { salt: salt.toString("hex"), key_hash: keyHash, created_at: new Date().toISOString() };
|
|
4556
|
-
writeFileSync2(VAULT_CONFIG, JSON.stringify(config, null, 2));
|
|
4557
|
-
_derivedKey = key;
|
|
4558
|
-
saveSession(key);
|
|
4559
|
-
}
|
|
4560
|
-
function isVaultInitialized() {
|
|
4561
|
-
return existsSync4(VAULT_CONFIG);
|
|
4562
|
-
}
|
|
4563
|
-
function unlockVault(passphrase) {
|
|
4564
|
-
if (!existsSync4(VAULT_CONFIG))
|
|
4565
|
-
throw new Error("Vault not initialized. Run 'contacts vault init' first.");
|
|
4566
|
-
const config = JSON.parse(readFileSync3(VAULT_CONFIG, "utf-8"));
|
|
4567
|
-
const salt = Buffer.from(config.salt, "hex");
|
|
4568
|
-
const key = deriveKey(passphrase, salt);
|
|
4569
|
-
const keyHash = createHash("sha256").update(key).digest("hex");
|
|
4570
|
-
if (keyHash !== config.key_hash)
|
|
4571
|
-
return false;
|
|
4572
|
-
_derivedKey = key;
|
|
4573
|
-
saveSession(key);
|
|
4574
|
-
return true;
|
|
4575
|
-
}
|
|
4576
|
-
function lockVault() {
|
|
4577
|
-
_derivedKey = null;
|
|
4578
|
-
clearSession();
|
|
4579
|
-
}
|
|
4580
|
-
function isVaultUnlocked() {
|
|
4581
|
-
if (_derivedKey)
|
|
4582
|
-
return true;
|
|
4583
|
-
const sessionKey = loadSession();
|
|
4584
|
-
if (sessionKey) {
|
|
4585
|
-
_derivedKey = sessionKey;
|
|
4586
|
-
return true;
|
|
4587
|
-
}
|
|
4588
|
-
return false;
|
|
4589
|
-
}
|
|
4590
|
-
function requireVault() {
|
|
4591
|
-
if (_derivedKey)
|
|
4592
|
-
return _derivedKey;
|
|
4593
|
-
const sessionKey = loadSession();
|
|
4594
|
-
if (sessionKey) {
|
|
4595
|
-
_derivedKey = sessionKey;
|
|
4596
|
-
return _derivedKey;
|
|
4597
|
-
}
|
|
4598
|
-
throw new Error("Vault is locked. Unlock with 'contacts vault unlock --passphrase <pass>' or vault_unlock MCP tool first.");
|
|
4599
|
-
}
|
|
4600
|
-
function encrypt(plaintext) {
|
|
4601
|
-
const key = requireVault();
|
|
4602
|
-
const iv = randomBytes(16);
|
|
4603
|
-
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
4604
|
-
let encrypted = cipher.update(plaintext, "utf8", "hex");
|
|
4605
|
-
encrypted += cipher.final("hex");
|
|
4606
|
-
const authTag = cipher.getAuthTag().toString("hex");
|
|
4607
|
-
return { ciphertext: encrypted + ":" + authTag, iv: iv.toString("hex") };
|
|
4608
|
-
}
|
|
4609
|
-
function decrypt(ciphertext, iv) {
|
|
4610
|
-
const key = requireVault();
|
|
4611
|
-
const [encData, authTag] = ciphertext.split(":");
|
|
4612
|
-
if (!encData || !authTag)
|
|
4613
|
-
throw new Error("Invalid ciphertext format");
|
|
4614
|
-
const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(iv, "hex"));
|
|
4615
|
-
decipher.setAuthTag(Buffer.from(authTag, "hex"));
|
|
4616
|
-
let decrypted = decipher.update(encData, "hex", "utf8");
|
|
4617
|
-
decrypted += decipher.final("utf8");
|
|
4618
|
-
return decrypted;
|
|
4619
|
-
}
|
|
4620
|
-
function encryptFile(sourcePath, entityId) {
|
|
4621
|
-
const key = requireVault();
|
|
4622
|
-
if (!existsSync4(DOCUMENTS_DIR))
|
|
4623
|
-
mkdirSync3(DOCUMENTS_DIR, { recursive: true });
|
|
4624
|
-
const data = readFileSync3(sourcePath);
|
|
4625
|
-
const iv = randomBytes(16);
|
|
4626
|
-
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
4627
|
-
const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
4628
|
-
const authTag = cipher.getAuthTag();
|
|
4629
|
-
const destPath = join4(DOCUMENTS_DIR, `${entityId}.enc`);
|
|
4630
|
-
const output = Buffer.concat([iv, authTag, encrypted]);
|
|
4631
|
-
writeFileSync2(destPath, output);
|
|
4632
|
-
return destPath;
|
|
4633
|
-
}
|
|
4634
|
-
function decryptFile(encPath) {
|
|
4635
|
-
const key = requireVault();
|
|
4636
|
-
const data = readFileSync3(encPath);
|
|
4637
|
-
const iv = data.subarray(0, 16);
|
|
4638
|
-
const authTag = data.subarray(16, 32);
|
|
4639
|
-
const encrypted = data.subarray(32);
|
|
4640
|
-
const decipher = createDecipheriv("aes-256-gcm", key, iv);
|
|
4641
|
-
decipher.setAuthTag(authTag);
|
|
4642
|
-
return Buffer.concat([decipher.update(encrypted), decipher.final()]);
|
|
4643
|
-
}
|
|
4644
|
-
function getDocumentsDir() {
|
|
4645
|
-
if (!existsSync4(DOCUMENTS_DIR))
|
|
4646
|
-
mkdirSync3(DOCUMENTS_DIR, { recursive: true });
|
|
4647
|
-
return DOCUMENTS_DIR;
|
|
4648
|
-
}
|
|
4649
|
-
// src/db/documents.ts
|
|
4650
|
-
init_database();
|
|
4651
|
-
import { existsSync as existsSync5, unlinkSync as unlinkSync3 } from "fs";
|
|
4652
|
-
var DOCUMENT_TYPES = [
|
|
4653
|
-
"passport",
|
|
4654
|
-
"national_id",
|
|
4655
|
-
"tax_id",
|
|
4656
|
-
"ssn",
|
|
4657
|
-
"drivers_license",
|
|
4658
|
-
"bank_account",
|
|
4659
|
-
"visa",
|
|
4660
|
-
"insurance",
|
|
4661
|
-
"contract",
|
|
4662
|
-
"certificate",
|
|
4663
|
-
"medical_record",
|
|
4664
|
-
"prescription",
|
|
4665
|
-
"allergy_list",
|
|
4666
|
-
"vaccination",
|
|
4667
|
-
"blood_type",
|
|
4668
|
-
"health_insurance",
|
|
4669
|
-
"medical_condition",
|
|
4670
|
-
"emergency_contact_medical",
|
|
4671
|
-
"other"
|
|
4672
|
-
];
|
|
4673
|
-
function addDocument(input, db) {
|
|
4674
|
-
requireVault();
|
|
4675
|
-
const _db2 = db || getDatabase();
|
|
4676
|
-
const id = uuid();
|
|
4677
|
-
const { ciphertext, iv } = encrypt(input.value);
|
|
4678
|
-
let encFilePath = null;
|
|
4679
|
-
if (input.file_path) {
|
|
4680
|
-
encFilePath = encryptFile(input.file_path, id);
|
|
4681
|
-
}
|
|
4682
|
-
_db2.query(`INSERT INTO contact_documents (id, contact_id, doc_type, label, encrypted_value, iv, encrypted_file_path, metadata, expires_at, created_at, updated_at) VALUES (?,?,?,?,?,?,?,?,?,?,?)`).run(id, input.contact_id, input.doc_type, input.label ?? null, ciphertext, iv, encFilePath, JSON.stringify(input.metadata || {}), input.expires_at ?? null, now(), now());
|
|
4683
|
-
return getDocument(id, _db2);
|
|
4684
|
-
}
|
|
4685
|
-
function getDocument(id, db) {
|
|
4686
|
-
requireVault();
|
|
4687
|
-
const _db2 = db || getDatabase();
|
|
4688
|
-
const row = _db2.query(`SELECT * FROM contact_documents WHERE id = ?`).get(id);
|
|
4689
|
-
if (!row)
|
|
4690
|
-
throw new Error(`Document not found: ${id}`);
|
|
4691
|
-
return rowToDoc(row);
|
|
4692
|
-
}
|
|
4693
|
-
function listDocuments(contactId, db) {
|
|
4694
|
-
const _db2 = db || getDatabase();
|
|
4695
|
-
const rows = _db2.query(`SELECT id, doc_type, label, encrypted_file_path, expires_at, created_at FROM contact_documents WHERE contact_id = ? ORDER BY created_at DESC`).all(contactId);
|
|
4696
|
-
return rows.map((r) => ({
|
|
4697
|
-
id: r.id,
|
|
4698
|
-
doc_type: r.doc_type,
|
|
4699
|
-
label: r.label,
|
|
4700
|
-
has_file: !!r.encrypted_file_path,
|
|
4701
|
-
expires_at: r.expires_at,
|
|
4702
|
-
created_at: r.created_at
|
|
4703
|
-
}));
|
|
4704
|
-
}
|
|
4705
|
-
function deleteDocument(id, db) {
|
|
4706
|
-
const _db2 = db || getDatabase();
|
|
4707
|
-
const row = _db2.query(`SELECT encrypted_file_path FROM contact_documents WHERE id = ?`).get(id);
|
|
4708
|
-
if (row?.encrypted_file_path && existsSync5(row.encrypted_file_path)) {
|
|
4709
|
-
try {
|
|
4710
|
-
unlinkSync3(row.encrypted_file_path);
|
|
4711
|
-
} catch {}
|
|
4712
|
-
}
|
|
4713
|
-
_db2.query(`DELETE FROM contact_documents WHERE id = ?`).run(id);
|
|
4714
|
-
}
|
|
4715
|
-
function rowToDoc(row) {
|
|
4716
|
-
return {
|
|
4717
|
-
id: row.id,
|
|
4718
|
-
contact_id: row.contact_id,
|
|
4719
|
-
doc_type: row.doc_type,
|
|
4720
|
-
label: row.label,
|
|
4721
|
-
value: decrypt(row.encrypted_value, row.iv),
|
|
4722
|
-
has_file: !!row.encrypted_file_path,
|
|
4723
|
-
metadata: JSON.parse(row.metadata || "{}"),
|
|
4724
|
-
expires_at: row.expires_at,
|
|
4725
|
-
created_at: row.created_at,
|
|
4726
|
-
updated_at: row.updated_at
|
|
4727
|
-
};
|
|
4728
|
-
}
|
|
4729
|
-
// src/db/health.ts
|
|
4730
|
-
init_database();
|
|
4731
|
-
function setHealthData(contactId, input, db) {
|
|
4732
|
-
requireVault();
|
|
4733
|
-
const _db2 = db || getDatabase();
|
|
4734
|
-
const existing = _db2.query(`SELECT id FROM contact_health WHERE contact_id = ?`).get(contactId);
|
|
4735
|
-
if (existing) {
|
|
4736
|
-
const sets = [];
|
|
4737
|
-
const params = [];
|
|
4738
|
-
if (input.blood_type !== undefined) {
|
|
4739
|
-
sets.push("blood_type = ?");
|
|
4740
|
-
params.push(input.blood_type);
|
|
4741
|
-
}
|
|
4742
|
-
if (input.allergies !== undefined) {
|
|
4743
|
-
sets.push("allergies = ?");
|
|
4744
|
-
params.push(JSON.stringify(input.allergies));
|
|
4745
|
-
}
|
|
4746
|
-
if (input.medical_conditions !== undefined) {
|
|
4747
|
-
sets.push("medical_conditions = ?");
|
|
4748
|
-
params.push(JSON.stringify(input.medical_conditions));
|
|
4749
|
-
}
|
|
4750
|
-
if (input.medications !== undefined) {
|
|
4751
|
-
sets.push("medications = ?");
|
|
4752
|
-
params.push(JSON.stringify(input.medications));
|
|
4753
|
-
}
|
|
4754
|
-
if (input.emergency_contacts !== undefined) {
|
|
4755
|
-
sets.push("emergency_contacts = ?");
|
|
4756
|
-
params.push(JSON.stringify(input.emergency_contacts));
|
|
4757
|
-
}
|
|
4758
|
-
if (input.health_insurance_provider !== undefined) {
|
|
4759
|
-
sets.push("health_insurance_provider = ?");
|
|
4760
|
-
params.push(input.health_insurance_provider);
|
|
4761
|
-
}
|
|
4762
|
-
if (input.health_insurance_id !== undefined) {
|
|
4763
|
-
sets.push("health_insurance_id = ?");
|
|
4764
|
-
params.push(input.health_insurance_id);
|
|
4765
|
-
}
|
|
4766
|
-
if (input.primary_physician !== undefined) {
|
|
4767
|
-
sets.push("primary_physician = ?");
|
|
4768
|
-
params.push(input.primary_physician);
|
|
4769
|
-
}
|
|
4770
|
-
if (input.primary_physician_phone !== undefined) {
|
|
4771
|
-
sets.push("primary_physician_phone = ?");
|
|
4772
|
-
params.push(input.primary_physician_phone);
|
|
4773
|
-
}
|
|
4774
|
-
if (input.organ_donor !== undefined) {
|
|
4775
|
-
sets.push("organ_donor = ?");
|
|
4776
|
-
params.push(input.organ_donor ? 1 : 0);
|
|
4777
|
-
}
|
|
4778
|
-
if (input.notes !== undefined) {
|
|
4779
|
-
sets.push("notes = ?");
|
|
4780
|
-
params.push(input.notes);
|
|
4781
|
-
}
|
|
4782
|
-
if (sets.length) {
|
|
4783
|
-
sets.push("updated_at = ?");
|
|
4784
|
-
params.push(now());
|
|
4785
|
-
params.push(contactId);
|
|
4786
|
-
_db2.query(`UPDATE contact_health SET ${sets.join(", ")} WHERE contact_id = ?`).run(...params);
|
|
4787
|
-
}
|
|
4788
|
-
} else {
|
|
4789
|
-
const id = uuid();
|
|
4790
|
-
_db2.query(`INSERT INTO contact_health (id, contact_id, blood_type, allergies, medical_conditions, medications, emergency_contacts, health_insurance_provider, health_insurance_id, primary_physician, primary_physician_phone, organ_donor, notes, created_at, updated_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`).run(id, contactId, input.blood_type ?? null, JSON.stringify(input.allergies || []), JSON.stringify(input.medical_conditions || []), JSON.stringify(input.medications || []), JSON.stringify(input.emergency_contacts || []), input.health_insurance_provider ?? null, input.health_insurance_id ?? null, input.primary_physician ?? null, input.primary_physician_phone ?? null, input.organ_donor ? 1 : 0, input.notes ?? null, now(), now());
|
|
4791
|
-
}
|
|
4792
|
-
return getHealthData(contactId, _db2);
|
|
4793
|
-
}
|
|
4794
|
-
function getHealthData(contactId, db) {
|
|
4795
|
-
requireVault();
|
|
4796
|
-
const _db2 = db || getDatabase();
|
|
4797
|
-
const row = _db2.query(`SELECT * FROM contact_health WHERE contact_id = ?`).get(contactId);
|
|
4798
|
-
if (!row)
|
|
4799
|
-
return null;
|
|
4800
|
-
return {
|
|
4801
|
-
id: row.id,
|
|
4802
|
-
contact_id: row.contact_id,
|
|
4803
|
-
blood_type: row.blood_type,
|
|
4804
|
-
allergies: JSON.parse(row.allergies || "[]"),
|
|
4805
|
-
medical_conditions: JSON.parse(row.medical_conditions || "[]"),
|
|
4806
|
-
medications: JSON.parse(row.medications || "[]"),
|
|
4807
|
-
emergency_contacts: JSON.parse(row.emergency_contacts || "[]"),
|
|
4808
|
-
health_insurance_provider: row.health_insurance_provider,
|
|
4809
|
-
health_insurance_id: row.health_insurance_id,
|
|
4810
|
-
primary_physician: row.primary_physician,
|
|
4811
|
-
primary_physician_phone: row.primary_physician_phone,
|
|
4812
|
-
organ_donor: !!row.organ_donor,
|
|
4813
|
-
notes: row.notes,
|
|
4814
|
-
created_at: row.created_at,
|
|
4815
|
-
updated_at: row.updated_at
|
|
4816
|
-
};
|
|
4817
|
-
}
|
|
4818
|
-
function deleteHealthData(contactId, db) {
|
|
4819
|
-
const _db2 = db || getDatabase();
|
|
4820
|
-
_db2.query(`DELETE FROM contact_health WHERE contact_id = ?`).run(contactId);
|
|
4821
|
-
}
|
|
4822
|
-
// src/lib/document-scanner.ts
|
|
4823
|
-
import { readFileSync as readFileSync4, existsSync as existsSync6 } from "fs";
|
|
4824
|
-
import { extname as extname2 } from "path";
|
|
4825
|
-
async function scanDocument(imageSource, docType) {
|
|
4826
|
-
const apiKey = process.env["OPENAI_API_KEY"];
|
|
4827
|
-
if (!apiKey) {
|
|
4828
|
-
throw new Error("OPENAI_API_KEY not set. Set it in ~/.secrets or environment to use document scanning.");
|
|
4829
|
-
}
|
|
4830
|
-
let imageData;
|
|
4831
|
-
if (imageSource.startsWith("data:image/")) {
|
|
4832
|
-
imageData = imageSource;
|
|
4833
|
-
} else if (existsSync6(imageSource)) {
|
|
4834
|
-
const buffer = readFileSync4(imageSource);
|
|
4835
|
-
const ext = extname2(imageSource).slice(1).toLowerCase();
|
|
4836
|
-
const mime = ext === "jpg" || ext === "jpeg" ? "image/jpeg" : ext === "png" ? "image/png" : ext === "webp" ? "image/webp" : ext === "gif" ? "image/gif" : "image/jpeg";
|
|
4837
|
-
imageData = `data:${mime};base64,${buffer.toString("base64")}`;
|
|
4838
|
-
} else if (/^[A-Za-z0-9+/=\n\r]+$/.test(imageSource.trim()) && imageSource.length > 100) {
|
|
4839
|
-
imageData = `data:image/jpeg;base64,${imageSource.trim()}`;
|
|
4840
|
-
} else {
|
|
4841
|
-
throw new Error(`Image source not found or invalid: ${imageSource.slice(0, 50)}...`);
|
|
4842
|
-
}
|
|
4843
|
-
const typeHint = docType ? ` This is a ${docType} document.` : "";
|
|
4844
|
-
const prompt = `Extract all text and structured data from this document image.${typeHint} Return a JSON object with these fields:
|
|
4845
|
-
- document_type: detected type (passport, national_id, drivers_license, tax_document, medical_record, prescription, insurance_card, bank_statement, visa, certificate, contract, other)
|
|
4846
|
-
- full_name: full name as shown
|
|
4847
|
-
- date_of_birth: in YYYY-MM-DD format if visible
|
|
4848
|
-
- document_number: main ID/document number
|
|
4849
|
-
- issuing_country: country code or name
|
|
4850
|
-
- issue_date: in YYYY-MM-DD format if visible
|
|
4851
|
-
- expiry_date: in YYYY-MM-DD format if visible
|
|
4852
|
-
- address: full address if visible
|
|
4853
|
-
- nationality: if visible
|
|
4854
|
-
- gender: if visible
|
|
4855
|
-
- mrz_code: Machine Readable Zone text if this is a passport/ID with MRZ
|
|
4856
|
-
- phone: any phone numbers visible
|
|
4857
|
-
- email: any email addresses visible
|
|
4858
|
-
- additional_fields: object with any other visible structured data
|
|
4859
|
-
- raw_text: all visible text transcribed
|
|
4860
|
-
|
|
4861
|
-
Only include fields that are actually visible in the document. Return valid JSON only.`;
|
|
4862
|
-
const response = await fetch("https://api.openai.com/v1/chat/completions", {
|
|
4863
|
-
method: "POST",
|
|
4864
|
-
headers: {
|
|
4865
|
-
Authorization: `Bearer ${apiKey}`,
|
|
4866
|
-
"Content-Type": "application/json"
|
|
4867
|
-
},
|
|
4868
|
-
body: JSON.stringify({
|
|
4869
|
-
model: "gpt-4o",
|
|
4870
|
-
messages: [
|
|
4871
|
-
{
|
|
4872
|
-
role: "user",
|
|
4873
|
-
content: [
|
|
4874
|
-
{ type: "text", text: prompt },
|
|
4875
|
-
{ type: "image_url", image_url: { url: imageData, detail: "high" } }
|
|
4876
|
-
]
|
|
4877
|
-
}
|
|
4878
|
-
],
|
|
4879
|
-
max_tokens: 2000,
|
|
4880
|
-
temperature: 0
|
|
4881
|
-
})
|
|
4882
|
-
});
|
|
4883
|
-
if (!response.ok) {
|
|
4884
|
-
const err = await response.text();
|
|
4885
|
-
throw new Error(`OpenAI API error: ${response.status} \u2014 ${err}`);
|
|
4886
|
-
}
|
|
4887
|
-
const data = await response.json();
|
|
4888
|
-
const content = data.choices?.[0]?.message?.content || "";
|
|
4889
|
-
const jsonMatch = content.match(/```json\s*([\s\S]*?)```/) || content.match(/\{[\s\S]*\}/);
|
|
4890
|
-
if (!jsonMatch) {
|
|
4891
|
-
return { fields: {}, raw_text: content, document_type: docType || "unknown", confidence: 0.3 };
|
|
4892
|
-
}
|
|
4893
|
-
try {
|
|
4894
|
-
const parsed = JSON.parse(jsonMatch[1] || jsonMatch[0]);
|
|
4895
|
-
const { document_type, raw_text, additional_fields, ...mainFields } = parsed;
|
|
4896
|
-
const fields = {};
|
|
4897
|
-
for (const [k, v] of Object.entries(mainFields)) {
|
|
4898
|
-
if (v && typeof v === "string")
|
|
4899
|
-
fields[k] = v;
|
|
4900
|
-
}
|
|
4901
|
-
if (additional_fields && typeof additional_fields === "object") {
|
|
4902
|
-
for (const [k, v] of Object.entries(additional_fields)) {
|
|
4903
|
-
if (v && typeof v === "string")
|
|
4904
|
-
fields[k] = v;
|
|
4905
|
-
}
|
|
4906
|
-
}
|
|
4907
|
-
return {
|
|
4908
|
-
fields,
|
|
4909
|
-
raw_text: raw_text || content,
|
|
4910
|
-
document_type: document_type || docType || "unknown",
|
|
4911
|
-
confidence: Object.keys(fields).length > 3 ? 0.9 : Object.keys(fields).length > 0 ? 0.7 : 0.3
|
|
4912
|
-
};
|
|
4913
|
-
} catch {
|
|
4914
|
-
return { fields: {}, raw_text: content, document_type: docType || "unknown", confidence: 0.3 };
|
|
4915
|
-
}
|
|
4916
|
-
}
|
|
4917
3534
|
export {
|
|
4918
3535
|
updateVendorCommunication,
|
|
4919
3536
|
updateTag,
|
|
@@ -4924,47 +3541,29 @@ export {
|
|
|
4924
3541
|
updateContact,
|
|
4925
3542
|
updateCompany,
|
|
4926
3543
|
updateApplication,
|
|
4927
|
-
unlockVault,
|
|
4928
3544
|
unarchiveContact,
|
|
4929
3545
|
unarchiveCompany,
|
|
4930
|
-
setHealthData,
|
|
4931
|
-
setDealContactRole,
|
|
4932
|
-
semanticSearch,
|
|
4933
|
-
searchLearnings,
|
|
4934
3546
|
searchGoogleContacts,
|
|
4935
3547
|
searchContacts,
|
|
4936
3548
|
searchCompanies,
|
|
4937
|
-
scanDocument,
|
|
4938
|
-
saveLearning,
|
|
4939
|
-
saveImage,
|
|
4940
3549
|
runConnector,
|
|
4941
|
-
resolveIdentity,
|
|
4942
|
-
resolveByPartial,
|
|
4943
3550
|
resetDatabase,
|
|
4944
|
-
requireVault,
|
|
4945
3551
|
removeTagFromContact,
|
|
4946
3552
|
removeTagFromCompany,
|
|
4947
3553
|
removeOrgMember,
|
|
4948
3554
|
removeContactFromGroup,
|
|
4949
3555
|
removeCompanyFromGroup,
|
|
4950
|
-
releaseLock,
|
|
4951
|
-
recordFieldChange,
|
|
4952
|
-
recomputeAllSignals,
|
|
4953
3556
|
readConnectorTokens,
|
|
4954
3557
|
pushContactToGoogle,
|
|
4955
3558
|
pullGoogleContactsAsInputs,
|
|
4956
3559
|
parseName,
|
|
4957
3560
|
parseLinkedIn,
|
|
4958
|
-
parseEmailSignature,
|
|
4959
3561
|
parseAddressHeader,
|
|
4960
3562
|
mergeContacts,
|
|
4961
3563
|
markFollowUpDone,
|
|
4962
|
-
markFieldVerified,
|
|
4963
3564
|
logVendorCommunication,
|
|
4964
3565
|
logEvent,
|
|
4965
|
-
logAgentActivity,
|
|
4966
3566
|
logActivity,
|
|
4967
|
-
lockVault,
|
|
4968
3567
|
listVendorCommunications,
|
|
4969
3568
|
listTags,
|
|
4970
3569
|
listRelationships,
|
|
@@ -4975,18 +3574,15 @@ export {
|
|
|
4975
3574
|
listOverdueTasks,
|
|
4976
3575
|
listOrgMembersForContact,
|
|
4977
3576
|
listOrgMembers,
|
|
4978
|
-
listOrgChart,
|
|
4979
3577
|
listNotesForContactAtCompany,
|
|
4980
3578
|
listNotes,
|
|
4981
3579
|
listMissingInvoices,
|
|
4982
|
-
listImages,
|
|
4983
3580
|
listGroupsForContact,
|
|
4984
3581
|
listGroupsForCompany,
|
|
4985
3582
|
listGroups,
|
|
4986
3583
|
listGoogleContacts,
|
|
4987
3584
|
listFollowUpDue,
|
|
4988
3585
|
listEvents,
|
|
4989
|
-
listDocuments,
|
|
4990
3586
|
listDeals,
|
|
4991
3587
|
listContactsInGroup,
|
|
4992
3588
|
listContactsByTag,
|
|
@@ -5000,91 +3596,48 @@ export {
|
|
|
5000
3596
|
listColdContacts,
|
|
5001
3597
|
listApplications,
|
|
5002
3598
|
listActivity,
|
|
5003
|
-
isVaultUnlocked,
|
|
5004
|
-
isVaultInitialized,
|
|
5005
|
-
initVault,
|
|
5006
|
-
ingestMeetingParticipants,
|
|
5007
3599
|
importToApple,
|
|
5008
3600
|
importFromCsv,
|
|
5009
3601
|
importContacts,
|
|
5010
3602
|
googlePersonToContactInput,
|
|
5011
|
-
getWarmingContacts,
|
|
5012
3603
|
getUpcomingItems,
|
|
5013
3604
|
getTagByName,
|
|
5014
3605
|
getTag,
|
|
5015
|
-
getStaleContacts,
|
|
5016
|
-
getRelationshipSignals,
|
|
5017
3606
|
getRelationship,
|
|
5018
|
-
getPreviousEmployers,
|
|
5019
3607
|
getOrgMember,
|
|
5020
3608
|
getNote,
|
|
5021
3609
|
getNetworkStats,
|
|
5022
|
-
getLearnings,
|
|
5023
|
-
getJobHistory,
|
|
5024
|
-
getImagesDir,
|
|
5025
|
-
getImagePath,
|
|
5026
|
-
getImageAsBase64,
|
|
5027
|
-
getIdentities,
|
|
5028
|
-
getHealthData,
|
|
5029
3610
|
getGroup,
|
|
5030
|
-
getGhostContacts,
|
|
5031
|
-
getFreshnessScore,
|
|
5032
|
-
getFieldHistory,
|
|
5033
3611
|
getEvent,
|
|
5034
3612
|
getEntityTeam,
|
|
5035
|
-
getDocumentsDir,
|
|
5036
|
-
getDocument,
|
|
5037
3613
|
getDealsByStage,
|
|
5038
|
-
getDealTeam,
|
|
5039
3614
|
getDeal,
|
|
5040
3615
|
getDatabase,
|
|
5041
|
-
getCurrentRole,
|
|
5042
|
-
getCoverageGaps,
|
|
5043
3616
|
getContactTimeline,
|
|
5044
3617
|
getContactTask,
|
|
5045
|
-
getContactCard,
|
|
5046
3618
|
getContactByEmail,
|
|
5047
|
-
getContactBrief,
|
|
5048
|
-
getContactAt,
|
|
5049
3619
|
getContact,
|
|
5050
3620
|
getConnectorTokenPath,
|
|
5051
3621
|
getCompany,
|
|
5052
3622
|
getApplication,
|
|
5053
|
-
getAgentActivity,
|
|
5054
3623
|
getActivity,
|
|
5055
3624
|
generateBrief,
|
|
5056
|
-
findWarmPath,
|
|
5057
|
-
findOrCreateContact,
|
|
5058
|
-
findConnectionsAtCompany,
|
|
5059
3625
|
extractContactsFromGmail,
|
|
5060
|
-
extractContactsFromEmailThread,
|
|
5061
3626
|
exportFromApple,
|
|
5062
3627
|
exportContacts,
|
|
5063
|
-
encryptFile,
|
|
5064
|
-
encrypt,
|
|
5065
|
-
embedContact,
|
|
5066
|
-
embedAllContacts,
|
|
5067
3628
|
domainToCompany,
|
|
5068
|
-
detectCoolingRelationships,
|
|
5069
3629
|
deleteVendorCommunication,
|
|
5070
3630
|
deleteTag,
|
|
5071
3631
|
deleteRelationship,
|
|
5072
3632
|
deleteNote,
|
|
5073
|
-
deleteLearning,
|
|
5074
|
-
deleteImage,
|
|
5075
|
-
deleteHealthData,
|
|
5076
3633
|
deleteGroup,
|
|
5077
3634
|
deleteEvent,
|
|
5078
|
-
deleteDocument,
|
|
5079
3635
|
deleteDeal,
|
|
5080
3636
|
deleteContactTask,
|
|
5081
3637
|
deleteContact,
|
|
5082
3638
|
deleteCompanyRelationship,
|
|
5083
3639
|
deleteCompany,
|
|
5084
3640
|
deleteApplication,
|
|
5085
|
-
decryptFile,
|
|
5086
|
-
decrypt,
|
|
5087
|
-
decayLearnings,
|
|
5088
3641
|
createTag,
|
|
5089
3642
|
createRelationship,
|
|
5090
3643
|
createGroup,
|
|
@@ -5095,33 +3648,21 @@ export {
|
|
|
5095
3648
|
createCompany,
|
|
5096
3649
|
createApplication,
|
|
5097
3650
|
contactToGoogleArgs,
|
|
5098
|
-
confirmLearning,
|
|
5099
|
-
computeRelationshipStrength,
|
|
5100
|
-
cleanExpiredLocks,
|
|
5101
|
-
checkLock,
|
|
5102
3651
|
checkEscalations,
|
|
5103
|
-
buildContactEmbeddingText,
|
|
5104
3652
|
autoLinkContactToCompany,
|
|
5105
3653
|
auditContact,
|
|
5106
|
-
assembleContext,
|
|
5107
3654
|
archiveContact,
|
|
5108
3655
|
archiveCompany,
|
|
5109
3656
|
addTagToContact,
|
|
5110
3657
|
addTagToCompany,
|
|
5111
3658
|
addPhoneToContact,
|
|
5112
3659
|
addOrgMember,
|
|
5113
|
-
addOrgChartEdge,
|
|
5114
3660
|
addNote,
|
|
5115
|
-
addJobEntry,
|
|
5116
|
-
addIdentity,
|
|
5117
3661
|
addEmailToContact,
|
|
5118
|
-
addDocument,
|
|
5119
3662
|
addContactToGroup,
|
|
5120
3663
|
addCompanyToGroup,
|
|
5121
|
-
acquireLock,
|
|
5122
3664
|
TagNotFoundError,
|
|
5123
3665
|
DuplicateTagNameError,
|
|
5124
|
-
DOCUMENT_TYPES,
|
|
5125
3666
|
ContactNotFoundError,
|
|
5126
3667
|
ConnectorNotInstalledError,
|
|
5127
3668
|
ConnectorAuthError,
|