eggi-ai-db-schema-2 0.1.1
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/CHANGELOG.md +750 -0
- package/README.md +660 -0
- package/dist/config/database.d.ts +28 -0
- package/dist/config/database.d.ts.map +1 -0
- package/dist/config/database.js +72 -0
- package/dist/config/database.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/database-service.d.ts +714 -0
- package/dist/lib/database-service.d.ts.map +1 -0
- package/dist/lib/database-service.js +1394 -0
- package/dist/lib/database-service.js.map +1 -0
- package/dist/lib/db-types.d.ts +167 -0
- package/dist/lib/db-types.d.ts.map +1 -0
- package/dist/lib/db-types.js +28 -0
- package/dist/lib/db-types.js.map +1 -0
- package/dist/lib/db.d.ts +58 -0
- package/dist/lib/db.d.ts.map +1 -0
- package/dist/lib/db.js +292 -0
- package/dist/lib/db.js.map +1 -0
- package/dist/lib/index.d.ts +11 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +26 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/pg-client.d.ts +50 -0
- package/dist/lib/pg-client.d.ts.map +1 -0
- package/dist/lib/pg-client.js +106 -0
- package/dist/lib/pg-client.js.map +1 -0
- package/dist/lib/schema.d.ts +298 -0
- package/dist/lib/schema.d.ts.map +1 -0
- package/dist/lib/schema.js +12 -0
- package/dist/lib/schema.js.map +1 -0
- package/dist/migration-manager.d.ts +49 -0
- package/dist/migration-manager.d.ts.map +1 -0
- package/dist/migration-manager.js +282 -0
- package/dist/migration-manager.js.map +1 -0
- package/dist/queries/minimal-connections.d.ts +31 -0
- package/dist/queries/minimal-connections.d.ts.map +1 -0
- package/dist/queries/minimal-connections.js +143 -0
- package/dist/queries/minimal-connections.js.map +1 -0
- package/dist/schema.ts +340 -0
- package/dist/seed.d.ts +8 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +40 -0
- package/dist/seed.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/types.d.ts +77 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +3 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/authenticated-user-operations.d.ts +110 -0
- package/dist/utils/authenticated-user-operations.d.ts.map +1 -0
- package/dist/utils/authenticated-user-operations.js +292 -0
- package/dist/utils/authenticated-user-operations.js.map +1 -0
- package/dist/utils/authentication-operations.d.ts +48 -0
- package/dist/utils/authentication-operations.d.ts.map +1 -0
- package/dist/utils/authentication-operations.js +172 -0
- package/dist/utils/authentication-operations.js.map +1 -0
- package/dist/utils/company-mapping-job-operations.d.ts +103 -0
- package/dist/utils/company-mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/company-mapping-job-operations.js +413 -0
- package/dist/utils/company-mapping-job-operations.js.map +1 -0
- package/dist/utils/company-sheet-upload-operations.d.ts +53 -0
- package/dist/utils/company-sheet-upload-operations.d.ts.map +1 -0
- package/dist/utils/company-sheet-upload-operations.js +135 -0
- package/dist/utils/company-sheet-upload-operations.js.map +1 -0
- package/dist/utils/contact-operations.d.ts +70 -0
- package/dist/utils/contact-operations.d.ts.map +1 -0
- package/dist/utils/contact-operations.js +294 -0
- package/dist/utils/contact-operations.js.map +1 -0
- package/dist/utils/forager-linkedin-operations.d.ts +74 -0
- package/dist/utils/forager-linkedin-operations.d.ts.map +1 -0
- package/dist/utils/forager-linkedin-operations.js +778 -0
- package/dist/utils/forager-linkedin-operations.js.map +1 -0
- package/dist/utils/ghost-genius-linkedin-operations.d.ts +23 -0
- package/dist/utils/ghost-genius-linkedin-operations.d.ts.map +1 -0
- package/dist/utils/ghost-genius-linkedin-operations.js +282 -0
- package/dist/utils/ghost-genius-linkedin-operations.js.map +1 -0
- package/dist/utils/index.d.ts +29 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +77 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/introduction-request-operations.d.ts +160 -0
- package/dist/utils/introduction-request-operations.d.ts.map +1 -0
- package/dist/utils/introduction-request-operations.js +492 -0
- package/dist/utils/introduction-request-operations.js.map +1 -0
- package/dist/utils/invitation-operations.d.ts +141 -0
- package/dist/utils/invitation-operations.d.ts.map +1 -0
- package/dist/utils/invitation-operations.js +749 -0
- package/dist/utils/invitation-operations.js.map +1 -0
- package/dist/utils/linkedin-account-operations.d.ts +45 -0
- package/dist/utils/linkedin-account-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-account-operations.js +279 -0
- package/dist/utils/linkedin-account-operations.js.map +1 -0
- package/dist/utils/linkedin-account-relationship-operations.d.ts +77 -0
- package/dist/utils/linkedin-account-relationship-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-account-relationship-operations.js +274 -0
- package/dist/utils/linkedin-account-relationship-operations.js.map +1 -0
- package/dist/utils/linkedin-data-operations.d.ts +102 -0
- package/dist/utils/linkedin-data-operations.d.ts.map +1 -0
- package/dist/utils/linkedin-data-operations.js +613 -0
- package/dist/utils/linkedin-data-operations.js.map +1 -0
- package/dist/utils/linkedin-identifier-utils.d.ts +31 -0
- package/dist/utils/linkedin-identifier-utils.d.ts.map +1 -0
- package/dist/utils/linkedin-identifier-utils.js +63 -0
- package/dist/utils/linkedin-identifier-utils.js.map +1 -0
- package/dist/utils/linkedin-profile-cache.d.ts +131 -0
- package/dist/utils/linkedin-profile-cache.d.ts.map +1 -0
- package/dist/utils/linkedin-profile-cache.js +418 -0
- package/dist/utils/linkedin-profile-cache.js.map +1 -0
- package/dist/utils/llm-inference-job-operations.d.ts +116 -0
- package/dist/utils/llm-inference-job-operations.d.ts.map +1 -0
- package/dist/utils/llm-inference-job-operations.js +267 -0
- package/dist/utils/llm-inference-job-operations.js.map +1 -0
- package/dist/utils/mapping-job-operations.d.ts +272 -0
- package/dist/utils/mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/mapping-job-operations.js +833 -0
- package/dist/utils/mapping-job-operations.js.map +1 -0
- package/dist/utils/mapping-operations.d.ts +80 -0
- package/dist/utils/mapping-operations.d.ts.map +1 -0
- package/dist/utils/mapping-operations.js +318 -0
- package/dist/utils/mapping-operations.js.map +1 -0
- package/dist/utils/on-demand-mapping-operations.d.ts +199 -0
- package/dist/utils/on-demand-mapping-operations.d.ts.map +1 -0
- package/dist/utils/on-demand-mapping-operations.js +728 -0
- package/dist/utils/on-demand-mapping-operations.js.map +1 -0
- package/dist/utils/onboarding-operations.d.ts +53 -0
- package/dist/utils/onboarding-operations.d.ts.map +1 -0
- package/dist/utils/onboarding-operations.js +223 -0
- package/dist/utils/onboarding-operations.js.map +1 -0
- package/dist/utils/organization-assignment-job-operations.d.ts +258 -0
- package/dist/utils/organization-assignment-job-operations.d.ts.map +1 -0
- package/dist/utils/organization-assignment-job-operations.js +881 -0
- package/dist/utils/organization-assignment-job-operations.js.map +1 -0
- package/dist/utils/organization-assignment-operations.d.ts +59 -0
- package/dist/utils/organization-assignment-operations.d.ts.map +1 -0
- package/dist/utils/organization-assignment-operations.js +130 -0
- package/dist/utils/organization-assignment-operations.js.map +1 -0
- package/dist/utils/organization-operations.d.ts +284 -0
- package/dist/utils/organization-operations.d.ts.map +1 -0
- package/dist/utils/organization-operations.js +1030 -0
- package/dist/utils/organization-operations.js.map +1 -0
- package/dist/utils/organization-relationship-operations.d.ts +79 -0
- package/dist/utils/organization-relationship-operations.d.ts.map +1 -0
- package/dist/utils/organization-relationship-operations.js +294 -0
- package/dist/utils/organization-relationship-operations.js.map +1 -0
- package/dist/utils/quota-operations.d.ts +107 -0
- package/dist/utils/quota-operations.d.ts.map +1 -0
- package/dist/utils/quota-operations.js +692 -0
- package/dist/utils/quota-operations.js.map +1 -0
- package/dist/utils/recursive-mapping-job-operations.d.ts +42 -0
- package/dist/utils/recursive-mapping-job-operations.d.ts.map +1 -0
- package/dist/utils/recursive-mapping-job-operations.js +169 -0
- package/dist/utils/recursive-mapping-job-operations.js.map +1 -0
- package/dist/utils/relationship-operations.d.ts +130 -0
- package/dist/utils/relationship-operations.d.ts.map +1 -0
- package/dist/utils/relationship-operations.js +329 -0
- package/dist/utils/relationship-operations.js.map +1 -0
- package/dist/utils/sales-pipeline-operations.d.ts +163 -0
- package/dist/utils/sales-pipeline-operations.d.ts.map +1 -0
- package/dist/utils/sales-pipeline-operations.js +725 -0
- package/dist/utils/sales-pipeline-operations.js.map +1 -0
- package/dist/utils/skills-operations.d.ts +117 -0
- package/dist/utils/skills-operations.d.ts.map +1 -0
- package/dist/utils/skills-operations.js +487 -0
- package/dist/utils/skills-operations.js.map +1 -0
- package/dist/utils/subscription-operations.d.ts +123 -0
- package/dist/utils/subscription-operations.d.ts.map +1 -0
- package/dist/utils/subscription-operations.js +391 -0
- package/dist/utils/subscription-operations.js.map +1 -0
- package/dist/utils/unipile-account-operations.d.ts +96 -0
- package/dist/utils/unipile-account-operations.d.ts.map +1 -0
- package/dist/utils/unipile-account-operations.js +255 -0
- package/dist/utils/unipile-account-operations.js.map +1 -0
- package/dist/utils/user-industry-operations.d.ts +80 -0
- package/dist/utils/user-industry-operations.d.ts.map +1 -0
- package/dist/utils/user-industry-operations.js +237 -0
- package/dist/utils/user-industry-operations.js.map +1 -0
- package/dist/utils/user-operations.d.ts +87 -0
- package/dist/utils/user-operations.d.ts.map +1 -0
- package/dist/utils/user-operations.js +212 -0
- package/dist/utils/user-operations.js.map +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contact-operations.d.ts","sourceRoot":"","sources":["../../src/utils/contact-operations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,KAAK,W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E,qBAAqB,EAAE,GACxC,OAAO,CAAC,WAAW,EAAE,CAAC,CAyDxB;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,EAChC,gBAAgB,EAAE,qBAAqB,EAAE,GACxC,OAAO,CAAC,WAAW,EAAE,CAAC,CA0FxB;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,EAChC,OAAO,EAAE,MAAM,EAAE,GAChB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAqChC"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* =============================================================================
|
|
4
|
+
* CONTACT OPERATIONS UTILITIES
|
|
5
|
+
* =============================================================================
|
|
6
|
+
* Utility functions for creating and managing user contact information
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.createContactInfo = createContactInfo;
|
|
43
|
+
exports.upsertContactInfo = upsertContactInfo;
|
|
44
|
+
exports.batchCreateContactInfos = batchCreateContactInfos;
|
|
45
|
+
exports.batchUpsertContactInfos = batchUpsertContactInfos;
|
|
46
|
+
exports.getBatchUserEmails = getBatchUserEmails;
|
|
47
|
+
const pg_client_1 = require("../lib/pg-client");
|
|
48
|
+
// =============================================================================
|
|
49
|
+
// CONTACT INFO OPERATIONS
|
|
50
|
+
// =============================================================================
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new contact info record for a user
|
|
53
|
+
*
|
|
54
|
+
* @param data - Contact info creation data
|
|
55
|
+
* @returns Promise resolving to the created contact info
|
|
56
|
+
*/
|
|
57
|
+
async function createContactInfo(db, data) {
|
|
58
|
+
if (!data.userId || !data.type || !data.value) {
|
|
59
|
+
throw new Error("Missing required fields: userId, type, and value are required");
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const { queryOne } = await Promise.resolve().then(() => __importStar(require("../lib/pg-client")));
|
|
63
|
+
const sql = `
|
|
64
|
+
INSERT INTO public.contact_infos (user_id, type, value, source, metadata, created_at)
|
|
65
|
+
VALUES ($1, $2, $3, $4, $5, NOW())
|
|
66
|
+
RETURNING id, user_id, type, value, source, metadata, created_at
|
|
67
|
+
`;
|
|
68
|
+
// Normalize email values to lowercase to prevent duplicates
|
|
69
|
+
const normalizedValue = data.type === "EMAIL" ? data.value.toLowerCase().trim() : data.value.trim();
|
|
70
|
+
const result = await queryOne(db, sql, [
|
|
71
|
+
data.userId,
|
|
72
|
+
data.type,
|
|
73
|
+
normalizedValue,
|
|
74
|
+
data.source || "MANUAL",
|
|
75
|
+
JSON.stringify(data.metadata || {}),
|
|
76
|
+
]);
|
|
77
|
+
if (!result) {
|
|
78
|
+
throw new Error("Failed to create contact info");
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof Error && error.message.includes("unique constraint")) {
|
|
84
|
+
throw new Error(`Contact info already exists: ${data.type} - ${data.value} for user ${data.userId}`);
|
|
85
|
+
}
|
|
86
|
+
throw new Error(`Failed to create contact info: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Creates or updates a contact info record (upsert)
|
|
91
|
+
*
|
|
92
|
+
* @param data - Contact info data
|
|
93
|
+
* @returns Promise resolving to the created or updated contact info
|
|
94
|
+
*/
|
|
95
|
+
async function upsertContactInfo(db, data) {
|
|
96
|
+
if (!data.userId || !data.type || !data.value) {
|
|
97
|
+
throw new Error("Missing required fields: userId, type, and value are required");
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
// Import query helper
|
|
101
|
+
const { queryOne } = await Promise.resolve().then(() => __importStar(require("../lib/pg-client")));
|
|
102
|
+
// Normalize email values to lowercase to prevent duplicates
|
|
103
|
+
const normalizedValue = data.type === "EMAIL" ? data.value.toLowerCase().trim() : data.value.trim();
|
|
104
|
+
// Native SQL implementation with UPSERT
|
|
105
|
+
const result = await queryOne(db, `INSERT INTO public.contact_infos (user_id, type, value, source, metadata, created_at)
|
|
106
|
+
VALUES ($1, $2, $3, $4, $5, NOW())
|
|
107
|
+
ON CONFLICT (type, value, source)
|
|
108
|
+
DO UPDATE SET
|
|
109
|
+
user_id = EXCLUDED.user_id,
|
|
110
|
+
metadata = EXCLUDED.metadata
|
|
111
|
+
RETURNING id, user_id, type, value, source, metadata, created_at`, [
|
|
112
|
+
data.userId,
|
|
113
|
+
data.type,
|
|
114
|
+
normalizedValue,
|
|
115
|
+
data.source || "MANUAL",
|
|
116
|
+
JSON.stringify(data.metadata || {}),
|
|
117
|
+
]);
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
throw new Error(`Failed to upsert contact info: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Removed unused contact info management functions:
|
|
125
|
+
// - updateContactInfo
|
|
126
|
+
// - deleteContactInfo
|
|
127
|
+
// These were not used in any consumers
|
|
128
|
+
// Removed unused contact info query functions:
|
|
129
|
+
// - getContactInfosForUser
|
|
130
|
+
// - getUserWithContacts
|
|
131
|
+
// - searchContactInfos
|
|
132
|
+
// - findUsersByContactInfo
|
|
133
|
+
// These were not used in any consumers
|
|
134
|
+
/**
|
|
135
|
+
* Batch creates contact infos for multiple users
|
|
136
|
+
*
|
|
137
|
+
* @param contactInfosData - Array of contact info creation data
|
|
138
|
+
* @returns Promise resolving to array of created contact infos
|
|
139
|
+
*/
|
|
140
|
+
async function batchCreateContactInfos(db, contactInfosData) {
|
|
141
|
+
if (contactInfosData.length === 0) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
// Validate all data first
|
|
145
|
+
contactInfosData.forEach((data, index) => {
|
|
146
|
+
if (!data.userId || !data.type || !data.value) {
|
|
147
|
+
throw new Error(`Invalid contact info at index ${index}: userId, type, and value are required`);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
try {
|
|
151
|
+
const results = [];
|
|
152
|
+
// Process in batches to avoid query size limits
|
|
153
|
+
const batchSize = 100;
|
|
154
|
+
for (let i = 0; i < contactInfosData.length; i += batchSize) {
|
|
155
|
+
const batch = contactInfosData.slice(i, i + batchSize);
|
|
156
|
+
// Build VALUES clause for batch insert
|
|
157
|
+
const values = [];
|
|
158
|
+
const params = [];
|
|
159
|
+
let paramIndex = 1;
|
|
160
|
+
batch.forEach(data => {
|
|
161
|
+
values.push(`($${paramIndex}, $${paramIndex + 1}, $${paramIndex + 2}, $${paramIndex + 3}, $${paramIndex + 4}, NOW())`);
|
|
162
|
+
params.push(data.userId, data.type, data.value.trim(), data.source || "MANUAL", JSON.stringify(data.metadata || {}));
|
|
163
|
+
paramIndex += 5;
|
|
164
|
+
});
|
|
165
|
+
const sql = `
|
|
166
|
+
INSERT INTO public.contact_infos (user_id, type, value, source, metadata, created_at)
|
|
167
|
+
VALUES ${values.join(", ")}
|
|
168
|
+
RETURNING id, user_id, type, value, source, metadata, created_at
|
|
169
|
+
`;
|
|
170
|
+
const batchResults = await (0, pg_client_1.query)(db, sql, params);
|
|
171
|
+
results.push(...batchResults);
|
|
172
|
+
}
|
|
173
|
+
return results;
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
throw new Error(`Failed to batch create contact infos: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Batch upserts contact infos (create or update)
|
|
181
|
+
*
|
|
182
|
+
* @param contactInfosData - Array of contact info data
|
|
183
|
+
* @returns Promise resolving to array of upserted contact infos
|
|
184
|
+
*/
|
|
185
|
+
async function batchUpsertContactInfos(db, contactInfosData) {
|
|
186
|
+
if (contactInfosData.length === 0) {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
// Validate all data first
|
|
190
|
+
contactInfosData.forEach((data, index) => {
|
|
191
|
+
if (!data.userId || !data.type || !data.value) {
|
|
192
|
+
throw new Error(`Invalid contact info at index ${index}: userId, type, and value are required`);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
try {
|
|
196
|
+
const results = [];
|
|
197
|
+
// Process in batches to avoid query size limits
|
|
198
|
+
const batchSize = 100;
|
|
199
|
+
for (let i = 0; i < contactInfosData.length; i += batchSize) {
|
|
200
|
+
const batch = contactInfosData.slice(i, i + batchSize);
|
|
201
|
+
// Build VALUES clause for batch upsert
|
|
202
|
+
const values = [];
|
|
203
|
+
const params = [];
|
|
204
|
+
let paramIndex = 1;
|
|
205
|
+
batch.forEach(data => {
|
|
206
|
+
// Normalize email values to lowercase to prevent duplicates
|
|
207
|
+
const normalizedValue = data.type === "EMAIL" ? data.value.toLowerCase().trim() : data.value.trim();
|
|
208
|
+
values.push(`($${paramIndex}, $${paramIndex + 1}, $${paramIndex + 2}, $${paramIndex + 3}, $${paramIndex + 4}, NOW())`);
|
|
209
|
+
params.push(data.userId, data.type, normalizedValue, data.source || "LINKEDIN", JSON.stringify(data.metadata || {}));
|
|
210
|
+
paramIndex += 5;
|
|
211
|
+
});
|
|
212
|
+
const sql = `
|
|
213
|
+
INSERT INTO public.contact_infos (user_id, type, value, source, metadata, created_at)
|
|
214
|
+
VALUES ${values.join(", ")}
|
|
215
|
+
ON CONFLICT (type, value, source)
|
|
216
|
+
DO UPDATE SET
|
|
217
|
+
user_id = EXCLUDED.user_id,
|
|
218
|
+
metadata = EXCLUDED.metadata
|
|
219
|
+
RETURNING id, user_id, type, value, source, metadata, created_at
|
|
220
|
+
`;
|
|
221
|
+
const batchResults = await (0, pg_client_1.query)(db, sql, params);
|
|
222
|
+
results.push(...batchResults);
|
|
223
|
+
}
|
|
224
|
+
return results;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
console.error("❌ Batch upsert failed, falling back to individual upserts", {
|
|
228
|
+
error: error instanceof Error ? error.message : String(error),
|
|
229
|
+
contactInfoCount: contactInfosData.length,
|
|
230
|
+
});
|
|
231
|
+
// Fallback: Try individual upserts to isolate which record is problematic
|
|
232
|
+
const results = [];
|
|
233
|
+
for (const contactData of contactInfosData) {
|
|
234
|
+
try {
|
|
235
|
+
const result = await upsertContactInfo(db, contactData);
|
|
236
|
+
results.push(result);
|
|
237
|
+
}
|
|
238
|
+
catch (individualError) {
|
|
239
|
+
console.error("⚠️ Individual contact info upsert failed", {
|
|
240
|
+
contactInfo: contactData,
|
|
241
|
+
error: individualError instanceof Error ? individualError.message : String(individualError),
|
|
242
|
+
});
|
|
243
|
+
// Continue with other contact info instead of failing completely
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (results.length === 0) {
|
|
247
|
+
throw new Error(`Failed to batch upsert contact infos: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
248
|
+
}
|
|
249
|
+
return results;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Batch fetch email addresses for multiple users
|
|
254
|
+
* Returns a Map of userId -> array of email addresses
|
|
255
|
+
*
|
|
256
|
+
* @param db - Database connection
|
|
257
|
+
* @param userIds - Array of user IDs to fetch emails for
|
|
258
|
+
* @returns Map<userId, emails[]>
|
|
259
|
+
*/
|
|
260
|
+
async function getBatchUserEmails(db, userIds) {
|
|
261
|
+
if (userIds.length === 0) {
|
|
262
|
+
return new Map();
|
|
263
|
+
}
|
|
264
|
+
// Create placeholders for the IN clause
|
|
265
|
+
const placeholders = userIds.map((_, i) => `$${i + 1}`).join(", ");
|
|
266
|
+
const sql = `
|
|
267
|
+
SELECT user_id, value as email
|
|
268
|
+
FROM public.contact_infos
|
|
269
|
+
WHERE user_id IN (${placeholders})
|
|
270
|
+
AND type = 'EMAIL'
|
|
271
|
+
`;
|
|
272
|
+
const results = await (0, pg_client_1.query)(db, sql, userIds);
|
|
273
|
+
// Group by user ID with deduplication
|
|
274
|
+
// Use Set to ensure unique emails per user (same email can exist with different sources)
|
|
275
|
+
const emailsMap = new Map();
|
|
276
|
+
for (const result of results) {
|
|
277
|
+
const existingSet = emailsMap.get(result.user_id);
|
|
278
|
+
if (!existingSet) {
|
|
279
|
+
emailsMap.set(result.user_id, [result.email]);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
// Only add if not already present (case-sensitive comparison)
|
|
283
|
+
if (!existingSet.includes(result.email)) {
|
|
284
|
+
existingSet.push(result.email);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return emailsMap;
|
|
289
|
+
}
|
|
290
|
+
// Removed unused contact info analytics and maintenance functions:
|
|
291
|
+
// - getContactInfoStatsForUser
|
|
292
|
+
// - deduplicateContactInfosForUser
|
|
293
|
+
// These were not used in any consumers
|
|
294
|
+
//# sourceMappingURL=contact-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contact-operations.js","sourceRoot":"","sources":["../../src/utils/contact-operations.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDH,8CA2CC;AAQD,8CAyCC;AAoBD,0DA4DC;AAQD,0DA6FC;AAUD,gDAwCC;AAtXD,gDAAyC;AAyCzC,gFAAgF;AAChF,0BAA0B;AAC1B,gFAAgF;AAEhF;;;;;GAKG;AACI,KAAK,UAAU,iBAAiB,CACrC,EAAgC,EAChC,IAA2B;IAE3B,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;IACnF,CAAC;IAED,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,GAAG,wDAAa,kBAAkB,GAAC,CAAC;QACtD,MAAM,GAAG,GAAG;;;;KAIX,CAAC;QAEF,4DAA4D;QAC5D,MAAM,eAAe,GACnB,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,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CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAChD,CAAC;aAAM,CAAC;YACN,8DAA8D;YAC9D,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,mEAAmE;AACnE,+BAA+B;AAC/B,mCAAmC;AACnC,uCAAuC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forager-based LinkedIn Account Operations
|
|
3
|
+
*
|
|
4
|
+
* Migrated to native PostgreSQL queries for better performance and flexibility.
|
|
5
|
+
* All functions maintain the same interface for backward compatibility.
|
|
6
|
+
*/
|
|
7
|
+
import { Pool, PoolClient } from "pg";
|
|
8
|
+
import { LinkedInAccount, FindOrCreateResult } from "../lib/db-types";
|
|
9
|
+
import { User } from "../lib/schema";
|
|
10
|
+
type Database = Pool | PoolClient;
|
|
11
|
+
/**
|
|
12
|
+
* LinkedIn account with computed profile_picture_url
|
|
13
|
+
* (COALESCE of profile_image_cloudfront_url and profile_picture_url)
|
|
14
|
+
*/
|
|
15
|
+
export interface LinkedInAccountResult extends Omit<LinkedInAccount, "profile_image_cloudfront_url"> {
|
|
16
|
+
profile_picture_url: string | null;
|
|
17
|
+
profile_image_cloudfront_url: null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* LinkedIn account with associated user
|
|
21
|
+
*/
|
|
22
|
+
export interface LinkedInAccountWithUser {
|
|
23
|
+
account: LinkedInAccountResult;
|
|
24
|
+
user: User | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Find LinkedIn account by Forager ID (primary matching method)
|
|
28
|
+
*/
|
|
29
|
+
export declare function findLinkedInAccountByForagerId(db: Database, foragerId: number): Promise<LinkedInAccountResult | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Find LinkedIn account by public identifier (fallback method)
|
|
32
|
+
*/
|
|
33
|
+
export declare function findLinkedInAccountByPublicIdentifier(db: Database, publicIdentifier: string): Promise<LinkedInAccountResult | null>;
|
|
34
|
+
/**
|
|
35
|
+
* Find LinkedIn account by any identifier (Forager ID, public identifier, or ACoA)
|
|
36
|
+
* Priority: forager_id > public_identifier > linkedin_identifier_acoa
|
|
37
|
+
*/
|
|
38
|
+
export declare function findLinkedInAccountByAnyIdentifier(db: Database, identifier: string | number): Promise<LinkedInAccountResult | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Find or create LinkedIn account by Forager ID
|
|
41
|
+
*/
|
|
42
|
+
export declare function findOrCreateLinkedInAccountByForagerId(db: Database, foragerId: number, publicIdentifier?: string, linkedinIdentifierAcoa?: string, userId?: number): Promise<FindOrCreateResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Find LinkedIn account with associated user by Forager ID
|
|
45
|
+
*/
|
|
46
|
+
export declare function findLinkedInAccountWithUserByForagerId(db: Database, foragerId: number): Promise<LinkedInAccountWithUser | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Update LinkedIn account profile data by Forager ID
|
|
49
|
+
*/
|
|
50
|
+
export declare function updateLinkedInAccountProfileByForagerId(db: Database, foragerId: number, profileData: {
|
|
51
|
+
firstName?: string;
|
|
52
|
+
lastName?: string;
|
|
53
|
+
headline?: string;
|
|
54
|
+
summary?: string;
|
|
55
|
+
location?: string;
|
|
56
|
+
profilePictureUrl?: string;
|
|
57
|
+
followerCount?: number;
|
|
58
|
+
connectionsCount?: number;
|
|
59
|
+
}): Promise<LinkedInAccountResult>;
|
|
60
|
+
/**
|
|
61
|
+
* Update LinkedIn account ACoA identifier by Forager ID
|
|
62
|
+
*/
|
|
63
|
+
export declare function updateLinkedInAccountAcoaIdentifierByForagerId(db: Database, foragerId: number, linkedinIdentifierAcoa: string): Promise<LinkedInAccountResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Update LinkedIn account ACoA identifier by Forager ID with change detection
|
|
66
|
+
* Returns whether the value actually changed
|
|
67
|
+
*/
|
|
68
|
+
export declare function updateLinkedInAccountAcoaIdentifierByForagerIdWithChangeDetection(db: Database, foragerId: number, linkedinIdentifierAcoa: string): Promise<{
|
|
69
|
+
account: LinkedInAccountResult;
|
|
70
|
+
wasChanged: boolean;
|
|
71
|
+
oldValue: string | null;
|
|
72
|
+
}>;
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=forager-linkedin-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forager-linkedin-operations.d.ts","sourceRoot":"","sources":["../../src/utils/forager-linkedin-operations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAmBrC,KAAK,QAAQ,GAAG,IAAI,GAAG,UAAU,CAAC;AAclC;;;GAGG;AACH,MAAM,WAAW,qBACf,SAAQ,IAAI,CAAC,eAAe,EAAE,8BAA8B,CAAC;IAC7D,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,4BAA4B,EAAE,IAAI,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,qBAAqB,CAAC;IAC/B,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;CACnB;AAmCD;;GAEG;AACH,wBAAsB,8BAA8B,CAClD,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,qBAAqB,GAAG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