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,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* =============================================================================
|
|
3
|
+
* USER OPERATIONS UTILITIES
|
|
4
|
+
* =============================================================================
|
|
5
|
+
* Utility functions for creating and managing authenticated users
|
|
6
|
+
*/
|
|
7
|
+
import { Pool, PoolClient } from "pg";
|
|
8
|
+
import type { Database } from "../lib/db";
|
|
9
|
+
import { type AuthenticatedUser, type UnipileAccount, type User } from "../lib/schema";
|
|
10
|
+
/**
|
|
11
|
+
* Interface for Cognito user data extracted from post-authentication events
|
|
12
|
+
*/
|
|
13
|
+
export interface CognitoUserData {
|
|
14
|
+
cognitoUserId: string;
|
|
15
|
+
email: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
givenName?: string;
|
|
18
|
+
familyName?: string;
|
|
19
|
+
preferredUsername?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Gets authenticated user record by Cognito ID
|
|
23
|
+
*
|
|
24
|
+
* This function queries the authenticated_users table and returns the authenticated user record.
|
|
25
|
+
*
|
|
26
|
+
* @param cognitoUserId - The Cognito User ID to search for
|
|
27
|
+
* @returns Promise resolving to authenticated user or null if not found
|
|
28
|
+
*/
|
|
29
|
+
export declare function getAuthenticatedUserByCognitoId(db: Database | Pool | PoolClient, cognitoUserId: string): Promise<AuthenticatedUser | null>;
|
|
30
|
+
/**
|
|
31
|
+
* Gets authenticated user record by user ID
|
|
32
|
+
* Used to check if a user has an authenticated account (not a shadow profile)
|
|
33
|
+
* @param db - Database connection
|
|
34
|
+
* @param userId - User ID from users table
|
|
35
|
+
* @returns Authenticated user record or null if user is a shadow profile
|
|
36
|
+
*/
|
|
37
|
+
export declare function getAuthenticatedUserByUserId(db: Database | Pool | PoolClient, userId: number): Promise<AuthenticatedUser | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Gets authenticated user record by email address
|
|
40
|
+
*
|
|
41
|
+
* This function joins authentication.users with contact_infos to find
|
|
42
|
+
* an authenticated user by their email address (case-insensitive).
|
|
43
|
+
*
|
|
44
|
+
* Used for validation checks like:
|
|
45
|
+
* - Preventing duplicate invitations to registered users
|
|
46
|
+
* - Checking if an email is already claimed
|
|
47
|
+
*
|
|
48
|
+
* @param db - Database connection
|
|
49
|
+
* @param email - Email address to search for
|
|
50
|
+
* @returns Authenticated user record with user_id and email, or null if not found
|
|
51
|
+
*/
|
|
52
|
+
export declare function getAuthenticatedUserByEmail(db: Database | Pool | PoolClient, email: string): Promise<{
|
|
53
|
+
auth_user_id: number;
|
|
54
|
+
user_id: number | null;
|
|
55
|
+
email: string;
|
|
56
|
+
} | null>;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the actual user record from users table via Cognito ID
|
|
59
|
+
*
|
|
60
|
+
* This function:
|
|
61
|
+
* 1. Finds authenticated user by Cognito ID
|
|
62
|
+
* 2. Uses authenticated_user.user_id to get the user from users table
|
|
63
|
+
*
|
|
64
|
+
* @param cognitoUserId - The Cognito User ID to search for
|
|
65
|
+
* @returns Promise resolving to user record or null if not found
|
|
66
|
+
*/
|
|
67
|
+
export declare function getUserByCognitoId(db: Database | Pool | PoolClient, cognitoUserId: string): Promise<User | null>;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Use getAuthenticatedUserByCognitoId instead
|
|
70
|
+
*/
|
|
71
|
+
export declare function findUserByCognitoId(db: Database | Pool | PoolClient, cognitoUserId: string): Promise<AuthenticatedUser | null>;
|
|
72
|
+
/**
|
|
73
|
+
* Checks if a user already has a Unipile account for a specific platform
|
|
74
|
+
* @param cognitoUserId - The Cognito User ID
|
|
75
|
+
* @param platformType - The platform to check (e.g., "linkedin")
|
|
76
|
+
* @returns Promise resolving to the existing account or null if not found
|
|
77
|
+
*/
|
|
78
|
+
export declare function getExistingUnipileAccount(db: Database | Pool | PoolClient, cognitoUserId: string, platformType: "linkedin" | "whatsapp" | "twitter" | "instagram" | "facebook"): Promise<UnipileAccount | null>;
|
|
79
|
+
/**
|
|
80
|
+
* Get user by ID
|
|
81
|
+
*
|
|
82
|
+
* @param db - Database instance
|
|
83
|
+
* @param userId - User ID
|
|
84
|
+
* @returns User or null if not found
|
|
85
|
+
*/
|
|
86
|
+
export declare function getUserById(db: Database | Pool | PoolClient, userId: number): Promise<User | null>;
|
|
87
|
+
//# sourceMappingURL=user-operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-operations.d.ts","sourceRoot":"","sources":["../../src/ut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ED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,EAAE,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,EAChC,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAEnC;AAQD;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,EAAE,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,EAChC,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,GAC3E,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAkDhC;AAID;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,EAAE,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,EAChC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAQtB"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* =============================================================================
|
|
4
|
+
* USER OPERATIONS UTILITIES
|
|
5
|
+
* =============================================================================
|
|
6
|
+
* Utility functions for creating and managing authenticated users
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getAuthenticatedUserByCognitoId = getAuthenticatedUserByCognitoId;
|
|
10
|
+
exports.getAuthenticatedUserByUserId = getAuthenticatedUserByUserId;
|
|
11
|
+
exports.getAuthenticatedUserByEmail = getAuthenticatedUserByEmail;
|
|
12
|
+
exports.getUserByCognitoId = getUserByCognitoId;
|
|
13
|
+
exports.findUserByCognitoId = findUserByCognitoId;
|
|
14
|
+
exports.getExistingUnipileAccount = getExistingUnipileAccount;
|
|
15
|
+
exports.getUserById = getUserById;
|
|
16
|
+
const pg_client_1 = require("../lib/pg-client");
|
|
17
|
+
// Removed deprecated import - using Forager-based operations instead
|
|
18
|
+
/**
|
|
19
|
+
* Maps database row (snake_case) to AuthenticatedUser interface (camelCase)
|
|
20
|
+
*/
|
|
21
|
+
function mapToAuthenticatedUser(row) {
|
|
22
|
+
return {
|
|
23
|
+
id: row.id,
|
|
24
|
+
userId: row.user_id,
|
|
25
|
+
cognitoUserId: row.cognito_user_id,
|
|
26
|
+
authProvider: row.auth_provider,
|
|
27
|
+
createdAt: row.created_at,
|
|
28
|
+
contactInfoId: row.contact_info_id,
|
|
29
|
+
isAdmin: row.is_admin ?? false,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Maps database row (snake_case) to User interface (camelCase)
|
|
34
|
+
*/
|
|
35
|
+
function mapToUser(row) {
|
|
36
|
+
return {
|
|
37
|
+
id: row.id,
|
|
38
|
+
givenName: row.given_name,
|
|
39
|
+
familyName: row.family_name,
|
|
40
|
+
summary: row.summary,
|
|
41
|
+
embeddingSummary: row.embedding_summary,
|
|
42
|
+
embedding: row.embedding,
|
|
43
|
+
createdAt: row.created_at,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// createOrUpdateAuthenticatedUser removed - only used in example code, not production
|
|
47
|
+
// Production authentication uses handlePostAuthentication from authentication-operations.ts
|
|
48
|
+
// Legacy function removed - createAuthenticatedUser
|
|
49
|
+
// Use handlePostAuthentication from authentication-operations.ts for production authentication
|
|
50
|
+
/**
|
|
51
|
+
* Gets authenticated user record by Cognito ID
|
|
52
|
+
*
|
|
53
|
+
* This function queries the authenticated_users table and returns the authenticated user record.
|
|
54
|
+
*
|
|
55
|
+
* @param cognitoUserId - The Cognito User ID to search for
|
|
56
|
+
* @returns Promise resolving to authenticated user or null if not found
|
|
57
|
+
*/
|
|
58
|
+
async function getAuthenticatedUserByCognitoId(db, cognitoUserId) {
|
|
59
|
+
const sql = `
|
|
60
|
+
SELECT id, user_id, cognito_user_id, created_at, contact_info_id, auth_provider, is_admin
|
|
61
|
+
FROM authentication.users
|
|
62
|
+
WHERE cognito_user_id = $1
|
|
63
|
+
LIMIT 1
|
|
64
|
+
`;
|
|
65
|
+
const row = await (0, pg_client_1.queryOne)(db, sql, [cognitoUserId]);
|
|
66
|
+
return row ? mapToAuthenticatedUser(row) : null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets authenticated user record by user ID
|
|
70
|
+
* Used to check if a user has an authenticated account (not a shadow profile)
|
|
71
|
+
* @param db - Database connection
|
|
72
|
+
* @param userId - User ID from users table
|
|
73
|
+
* @returns Authenticated user record or null if user is a shadow profile
|
|
74
|
+
*/
|
|
75
|
+
async function getAuthenticatedUserByUserId(db, userId) {
|
|
76
|
+
const sql = `
|
|
77
|
+
SELECT id, user_id, cognito_user_id, created_at, contact_info_id, auth_provider, is_admin
|
|
78
|
+
FROM authentication.users
|
|
79
|
+
WHERE user_id = $1
|
|
80
|
+
LIMIT 1
|
|
81
|
+
`;
|
|
82
|
+
const row = await (0, pg_client_1.queryOne)(db, sql, [userId]);
|
|
83
|
+
return row ? mapToAuthenticatedUser(row) : null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Gets authenticated user record by email address
|
|
87
|
+
*
|
|
88
|
+
* This function joins authentication.users with contact_infos to find
|
|
89
|
+
* an authenticated user by their email address (case-insensitive).
|
|
90
|
+
*
|
|
91
|
+
* Used for validation checks like:
|
|
92
|
+
* - Preventing duplicate invitations to registered users
|
|
93
|
+
* - Checking if an email is already claimed
|
|
94
|
+
*
|
|
95
|
+
* @param db - Database connection
|
|
96
|
+
* @param email - Email address to search for
|
|
97
|
+
* @returns Authenticated user record with user_id and email, or null if not found
|
|
98
|
+
*/
|
|
99
|
+
async function getAuthenticatedUserByEmail(db, email) {
|
|
100
|
+
const emailToCheck = email.toLowerCase().trim();
|
|
101
|
+
const sql = `
|
|
102
|
+
SELECT
|
|
103
|
+
au.id as auth_user_id,
|
|
104
|
+
au.user_id,
|
|
105
|
+
ci.value as email
|
|
106
|
+
FROM authentication.users au
|
|
107
|
+
INNER JOIN public.contact_infos ci ON au.contact_info_id = ci.id
|
|
108
|
+
WHERE ci.type = 'EMAIL'
|
|
109
|
+
AND LOWER(TRIM(ci.value)) = $1
|
|
110
|
+
LIMIT 1
|
|
111
|
+
`;
|
|
112
|
+
return await (0, pg_client_1.queryOne)(db, sql, [emailToCheck]);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Gets the actual user record from users table via Cognito ID
|
|
116
|
+
*
|
|
117
|
+
* This function:
|
|
118
|
+
* 1. Finds authenticated user by Cognito ID
|
|
119
|
+
* 2. Uses authenticated_user.user_id to get the user from users table
|
|
120
|
+
*
|
|
121
|
+
* @param cognitoUserId - The Cognito User ID to search for
|
|
122
|
+
* @returns Promise resolving to user record or null if not found
|
|
123
|
+
*/
|
|
124
|
+
async function getUserByCognitoId(db, cognitoUserId) {
|
|
125
|
+
// First get the authenticated user
|
|
126
|
+
const authenticatedUser = await getAuthenticatedUserByCognitoId(db, cognitoUserId);
|
|
127
|
+
if (!authenticatedUser) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
// Then get the actual user record from users table
|
|
131
|
+
if (!authenticatedUser.userId) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
const sql = `
|
|
135
|
+
SELECT id, given_name, family_name, summary, embedding_summary, embedding, created_at
|
|
136
|
+
FROM public.users
|
|
137
|
+
WHERE id = $1
|
|
138
|
+
LIMIT 1
|
|
139
|
+
`;
|
|
140
|
+
return await (0, pg_client_1.queryOne)(db, sql, [authenticatedUser.userId]);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @deprecated Use getAuthenticatedUserByCognitoId instead
|
|
144
|
+
*/
|
|
145
|
+
async function findUserByCognitoId(db, cognitoUserId) {
|
|
146
|
+
return getAuthenticatedUserByCognitoId(db, cognitoUserId);
|
|
147
|
+
}
|
|
148
|
+
// Legacy function removed - findUserByEmail
|
|
149
|
+
// Email is now stored in the users table, use contact_infos table for email lookups
|
|
150
|
+
// Legacy function removed - updateAuthenticatedUser
|
|
151
|
+
// User information is now in the users table, use the user update functions instead
|
|
152
|
+
/**
|
|
153
|
+
* Checks if a user already has a Unipile account for a specific platform
|
|
154
|
+
* @param cognitoUserId - The Cognito User ID
|
|
155
|
+
* @param platformType - The platform to check (e.g., "linkedin")
|
|
156
|
+
* @returns Promise resolving to the existing account or null if not found
|
|
157
|
+
*/
|
|
158
|
+
async function getExistingUnipileAccount(db, cognitoUserId, platformType) {
|
|
159
|
+
if (!cognitoUserId || !platformType) {
|
|
160
|
+
throw new Error("Missing required fields: cognitoUserId and platformType are required");
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
// Find the authenticated user first
|
|
164
|
+
const authUserSql = `
|
|
165
|
+
SELECT user_id
|
|
166
|
+
FROM authentication.users
|
|
167
|
+
WHERE cognito_user_id = $1
|
|
168
|
+
LIMIT 1
|
|
169
|
+
`;
|
|
170
|
+
const authUser = await (0, pg_client_1.queryOne)(db, authUserSql, [cognitoUserId]);
|
|
171
|
+
if (!authUser || !authUser.user_id) {
|
|
172
|
+
return null; // User not found or not linked to a user record
|
|
173
|
+
}
|
|
174
|
+
// Check for existing Unipile account for this platform through LinkedIn accounts
|
|
175
|
+
const accountSql = `
|
|
176
|
+
SELECT
|
|
177
|
+
ua.id,
|
|
178
|
+
ua.linkedin_account_id,
|
|
179
|
+
ua.unipile_account_id,
|
|
180
|
+
ua.account_type,
|
|
181
|
+
ua.is_active,
|
|
182
|
+
ua.connected_at,
|
|
183
|
+
ua.last_synced_at,
|
|
184
|
+
ua.metadata,
|
|
185
|
+
ua.created_at,
|
|
186
|
+
ua.updated_at
|
|
187
|
+
FROM public.unipile_accounts ua
|
|
188
|
+
INNER JOIN linkedin.accounts la ON ua.linkedin_account_id = la.id
|
|
189
|
+
WHERE la.user_id = $1
|
|
190
|
+
AND ua.is_active = true
|
|
191
|
+
LIMIT 1
|
|
192
|
+
`;
|
|
193
|
+
return await (0, pg_client_1.queryOne)(db, accountSql, [authUser.user_id]);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
throw new Error(`Failed to check existing Unipile account: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// DEPRECATED: upsertLinkedAccount function removed - use Forager-based operations instead
|
|
200
|
+
/**
|
|
201
|
+
* Get user by ID
|
|
202
|
+
*
|
|
203
|
+
* @param db - Database instance
|
|
204
|
+
* @param userId - User ID
|
|
205
|
+
* @returns User or null if not found
|
|
206
|
+
*/
|
|
207
|
+
async function getUserById(db, userId) {
|
|
208
|
+
// Native SQL implementation
|
|
209
|
+
const row = await (0, pg_client_1.queryOne)(db, "SELECT id, given_name, family_name, summary, embedding_summary, embedding, created_at FROM public.users WHERE id = $1 LIMIT 1", [userId]);
|
|
210
|
+
return row ? mapToUser(row) : null;
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=user-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-operations.js","sourceRoot":"","sources":["../../src/utils/user-operations.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAoEH,0EAaC;AASD,oEAaC;AAgBD,kEAuBC;AAYD,gDAoBC;AAKD,kDAKC;AAcD,8DAsDC;AAWD,kCAWC;AA/QD,gDAA4C;AAO5C,qEAAqE;AAErE;;GAEG;AACH,SAAS,sBAAsB,CAAC,GAAQ;IACtC,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,MAAM,EAAE,GAAG,CAAC,OAAO;QACnB,aAAa,EAAE,GAAG,CAAC,eAAe;QAClC,YAAY,EAAE,GAAG,CAAC,aAAa;QAC/B,SAAS,EAAE,GAAG,CAAC,UAAU;QACzB,aAAa,EAAE,GAAG,CAAC,eAAe;QAClC,OAAO,EAAE,GAAG,CAAC,QAAQ,IAAI,KAAK;KAC/B,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,GAAQ;IACzB,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;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AM,UAAU,GAAG;;;;;;;;;;;;;;;;;KAiBlB,CAAC;QAEF,OAAO,MAAM,IAAA,oBAAQ,EAAiB,EAAuB,EAAE,UAAU,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IACjG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,6CAA6C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CACxG,CAAC;IACJ,CAAC;AACH,CAAC;AAED,0FAA0F;AAE1F;;;;;;GAMG;AACI,KAAK,UAAU,WAAW,CAC/B,EAAgC,EAChC,MAAc;IAEd,4BAA4B;IAC5B,MAAM,GAAG,GAAG,MAAM,IAAA,oBAAQ,EACxB,EAAuB,EACvB,+HAA+H,EAC/H,CAAC,MAAM,CAAC,CACT,CAAC;IACF,OAAO,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "eggi-ai-db-schema-2",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Type-safe database schema with native PostgreSQL queries for Eggi.AI with direct RDS connection",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./schema": {
|
|
14
|
+
"types": "./dist/lib/schema.d.ts",
|
|
15
|
+
"import": "./dist/lib/schema.js",
|
|
16
|
+
"require": "./dist/lib/schema.js"
|
|
17
|
+
},
|
|
18
|
+
"./config": {
|
|
19
|
+
"types": "./dist/config/index.d.ts",
|
|
20
|
+
"import": "./dist/config/index.js",
|
|
21
|
+
"require": "./dist/config/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./utils": {
|
|
24
|
+
"types": "./dist/utils/index.d.ts",
|
|
25
|
+
"import": "./dist/utils/index.js",
|
|
26
|
+
"require": "./dist/utils/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/**/*",
|
|
31
|
+
"README.md",
|
|
32
|
+
"CHANGELOG.md"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "npm run clean && tsc",
|
|
40
|
+
"prepare": "npm run build",
|
|
41
|
+
"postbuild": "cp src/lib/schema.ts dist/",
|
|
42
|
+
"prepublishOnly": "npm run build",
|
|
43
|
+
"clean": "rm -rf dist",
|
|
44
|
+
"dev": "tsx src/index.ts",
|
|
45
|
+
"test": "npm run type-check",
|
|
46
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
47
|
+
"type-check": "tsc --noEmit",
|
|
48
|
+
"pack:test": "npm pack --dry-run",
|
|
49
|
+
"migrate:dev:init": "./scripts/migrate.sh dev init",
|
|
50
|
+
"migrate:dev:status": "./scripts/migrate.sh dev status",
|
|
51
|
+
"migrate:dev:apply": "./scripts/migrate.sh dev apply",
|
|
52
|
+
"migrate:dev:rollback": "./scripts/migrate.sh dev rollback",
|
|
53
|
+
"migrate:prod:init": "./scripts/migrate.sh prod init",
|
|
54
|
+
"migrate:prod:status": "./scripts/migrate.sh prod status",
|
|
55
|
+
"migrate:prod:apply": "./scripts/migrate.sh prod apply",
|
|
56
|
+
"migrate:prod:rollback": "./scripts/migrate.sh prod rollback",
|
|
57
|
+
"update-version": "./scripts/update-version.sh",
|
|
58
|
+
"version:patch": "npm version patch",
|
|
59
|
+
"version:minor": "npm version minor",
|
|
60
|
+
"version:major": "npm version major"
|
|
61
|
+
},
|
|
62
|
+
"keywords": [
|
|
63
|
+
"postgres",
|
|
64
|
+
"database",
|
|
65
|
+
"schema",
|
|
66
|
+
"eggi-ai",
|
|
67
|
+
"typescript"
|
|
68
|
+
],
|
|
69
|
+
"author": "Eggi AI Inc",
|
|
70
|
+
"license": "MIT",
|
|
71
|
+
"repository": {
|
|
72
|
+
"type": "git",
|
|
73
|
+
"url": "https://github.com/Eggi-AI-Inc/db-schema.git"
|
|
74
|
+
},
|
|
75
|
+
"homepage": "https://github.com/Eggi-AI-Inc/db-schema#readme",
|
|
76
|
+
"bugs": {
|
|
77
|
+
"url": "https://github.com/Eggi-AI-Inc/db-schema/issues"
|
|
78
|
+
},
|
|
79
|
+
"devDependencies": {
|
|
80
|
+
"@typescript-eslint/eslint-plugin": "^6.13.0",
|
|
81
|
+
"@typescript-eslint/parser": "^6.13.0",
|
|
82
|
+
"eslint": "^8.54.0",
|
|
83
|
+
"prettier": "^3.1.0",
|
|
84
|
+
"tsx": "^4.6.0",
|
|
85
|
+
"typescript": "^5.3.0"
|
|
86
|
+
},
|
|
87
|
+
"dependencies": {
|
|
88
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.883.0",
|
|
89
|
+
"@aws-sdk/client-lambda": "^3.883.0",
|
|
90
|
+
"@aws-sdk/client-secrets-manager": "^3.913.0",
|
|
91
|
+
"@aws-sdk/client-sns": "^3.940.0",
|
|
92
|
+
"@aws-sdk/client-sqs": "^3.940.0",
|
|
93
|
+
"@aws-sdk/credential-provider-node": "^3.470.0",
|
|
94
|
+
"@types/pg": "^8.15.5",
|
|
95
|
+
"dotenv": "^16.3.0",
|
|
96
|
+
"pg": "^8.16.3"
|
|
97
|
+
}
|
|
98
|
+
}
|