linkedin-secret-sauce 0.3.18 → 0.3.20
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.
|
@@ -4,22 +4,52 @@ exports.parseCompany = parseCompany;
|
|
|
4
4
|
const image_parser_1 = require("./image-parser");
|
|
5
5
|
function parseCompany(raw) {
|
|
6
6
|
const r = raw;
|
|
7
|
+
// LinkedIn API returns nested structure with data + included array
|
|
8
|
+
const data = r?.data || r;
|
|
9
|
+
const included = Array.isArray(r?.included) ? r.included : [];
|
|
10
|
+
// Find MiniCompany in included array (contains name, logo, universalName)
|
|
11
|
+
const miniCompany = included.find(it => String(it?.entityUrn || '').includes('fs_miniCompany') ||
|
|
12
|
+
String(it?.$type || '').includes('MiniCompany'));
|
|
13
|
+
// Extract company ID from multiple possible locations
|
|
14
|
+
const extractId = (obj) => {
|
|
15
|
+
if (!obj)
|
|
16
|
+
return '';
|
|
17
|
+
const id = String(obj.id ?? obj.entityUrn ?? obj.objectUrn ?? '');
|
|
18
|
+
// Handle all URN formats: fs_miniCompany, fs_company, fsd_company
|
|
19
|
+
return id.replace(/^urn:li:(?:fsd_|fs_)?(?:miniCompany|company):/i, '');
|
|
20
|
+
};
|
|
21
|
+
// Priority: data.entityUrn > miniCompany.objectUrn > miniCompany.entityUrn > data.id
|
|
22
|
+
const companyId = extractId(data) || extractId(miniCompany) || extractId(r);
|
|
7
23
|
const company = {
|
|
8
|
-
companyId
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
companyId,
|
|
25
|
+
universalName: (miniCompany?.universalName || data?.universalName || r?.universalName),
|
|
26
|
+
name: (miniCompany?.name || data?.name || r?.name),
|
|
27
|
+
websiteUrl: (data?.websiteUrl || r?.websiteUrl),
|
|
28
|
+
description: (data?.description || r?.description),
|
|
29
|
+
sizeLabel: (typeof data?.employeeCountRange === 'string' ? data.employeeCountRange :
|
|
30
|
+
data?.employeeCountRange?.localizedName) ||
|
|
31
|
+
(typeof r?.employeeCountRange === 'string' ? r.employeeCountRange :
|
|
32
|
+
r?.employeeCountRange?.localizedName),
|
|
33
|
+
headquarters: data?.basicCompanyInfo?.headquarters ||
|
|
34
|
+
r?.headquarterLocation?.defaultLocalizedName ||
|
|
17
35
|
r?.headquarter?.defaultLocalizedName,
|
|
36
|
+
companyType: (data?.companyType || r?.companyType),
|
|
37
|
+
industries: (data?.industries || r?.industries),
|
|
38
|
+
specialties: (data?.specialties || r?.specialties),
|
|
39
|
+
foundedYear: data?.foundedDate?.year ||
|
|
40
|
+
r?.foundedOn?.year,
|
|
18
41
|
logoUrl: undefined,
|
|
19
42
|
coverUrl: undefined,
|
|
20
43
|
};
|
|
21
|
-
|
|
22
|
-
const
|
|
44
|
+
// Extract logo - check miniCompany first, then data, then root
|
|
45
|
+
const logoVector = miniCompany?.logo?.vectorImage ||
|
|
46
|
+
miniCompany?.logo ||
|
|
47
|
+
data?.logo?.vectorImage ||
|
|
48
|
+
r?.logo?.vectorImage ||
|
|
49
|
+
r?.logoV2?.vectorImage;
|
|
50
|
+
const coverVector = data?.coverPhoto?.vectorImage ||
|
|
51
|
+
r?.coverPhoto?.vectorImage ||
|
|
52
|
+
r?.backgroundImage?.vectorImage;
|
|
23
53
|
const logoUrl = (0, image_parser_1.selectBestImageUrl)(logoVector);
|
|
24
54
|
const coverUrl = (0, image_parser_1.selectBestImageUrl)(coverVector);
|
|
25
55
|
if (logoUrl)
|
|
@@ -5,7 +5,22 @@ const image_parser_1 = require("./image-parser");
|
|
|
5
5
|
function parseFullProfile(rawResponse, vanity) {
|
|
6
6
|
const rr = rawResponse;
|
|
7
7
|
const included = Array.isArray(rr?.included) ? rr.included : [];
|
|
8
|
-
|
|
8
|
+
// FIX: Match profile by publicIdentifier to handle edge case where LinkedIn API
|
|
9
|
+
// returns multiple profiles (e.g., authenticated user + requested profile)
|
|
10
|
+
const identity = included.find((it) => {
|
|
11
|
+
const rec = it;
|
|
12
|
+
const isProfile = String(rec?.$type || '').includes('identity.profile.Profile');
|
|
13
|
+
if (!isProfile)
|
|
14
|
+
return false;
|
|
15
|
+
// Match by publicIdentifier if vanity was provided
|
|
16
|
+
if (vanity) {
|
|
17
|
+
const pubId = rec.publicIdentifier?.toLowerCase();
|
|
18
|
+
const requestedVanity = String(vanity).toLowerCase();
|
|
19
|
+
return pubId === requestedVanity;
|
|
20
|
+
}
|
|
21
|
+
// Fallback: if no vanity to match, return first profile (legacy behavior for getProfileByUrn)
|
|
22
|
+
return true;
|
|
23
|
+
}) || {};
|
|
9
24
|
const profile = {
|
|
10
25
|
vanity,
|
|
11
26
|
publicIdentifier: identity.publicIdentifier,
|