linkedin-api-voyager 1.1.0 → 1.3.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/lib/company.js +4 -1
- package/lib/config.js +3 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/posts.d.ts +11 -1
- package/lib/posts.js +83 -6
- package/lib/search.d.ts +3 -26
- package/lib/search.js +163 -112
- package/lib/teste.d.ts +1 -0
- package/lib/teste.js +10 -0
- package/lib/types.d.ts +794 -0
- package/lib/types.js +2 -0
- package/lib/user.d.ts +38 -0
- package/lib/user.js +172 -0
- package/lib/utils.d.ts +35 -0
- package/lib/utils.js +440 -27
- package/package.json +4 -3
- package/lib/account.d.ts +0 -18
- package/lib/account.js +0 -98
- package/lib/linkedin.d.ts +0 -0
- package/lib/linkedin.js +0 -1
package/lib/company.js
CHANGED
|
@@ -32,6 +32,9 @@ const getCompany = (identifier) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
32
32
|
logo: "logo.image",
|
|
33
33
|
permissions: "permissions",
|
|
34
34
|
};
|
|
35
|
-
return (0, utils_1.extractFields)(data, fieldsMap)
|
|
35
|
+
return (0, utils_1.extractFields)(data, fieldsMap).map((item) => {
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
37
|
+
return (Object.assign(Object.assign({}, item), { id: item.id.split(":")[3], backgroundCoverImage: `${(_a = item.backgroundCoverImage) === null || _a === void 0 ? void 0 : _a.rootUrl}${(_d = (_c = (_b = item.backgroundCoverImage) === null || _b === void 0 ? void 0 : _b.artifacts) === null || _c === void 0 ? void 0 : _c.at(-1)) === null || _d === void 0 ? void 0 : _d.fileIdentifyingUrlPathSegment}`, logo: `${(_e = item.logo) === null || _e === void 0 ? void 0 : _e.rootUrl}${(_h = (_g = (_f = item.logo) === null || _f === void 0 ? void 0 : _f.artifacts) === null || _g === void 0 ? void 0 : _g.at(-1)) === null || _h === void 0 ? void 0 : _h.fileIdentifyingUrlPathSegment}` }));
|
|
38
|
+
})[0];
|
|
36
39
|
});
|
|
37
40
|
exports.getCompany = getCompany;
|
package/lib/config.js
CHANGED
|
@@ -25,10 +25,8 @@ const saveCookies = (JSESSIONID, li_at) => __awaiter(void 0, void 0, void 0, fun
|
|
|
25
25
|
};
|
|
26
26
|
yield fs.ensureFile(exports.COOKIE_FILE_PATH);
|
|
27
27
|
yield fs.writeJson(exports.COOKIE_FILE_PATH, cookies, { spaces: 2 });
|
|
28
|
-
console.log(`Cookies salvos em: ${exports.COOKIE_FILE_PATH}`);
|
|
29
28
|
}
|
|
30
29
|
catch (error) {
|
|
31
|
-
console.error("Erro ao salvar cookies:", error);
|
|
32
30
|
throw error;
|
|
33
31
|
}
|
|
34
32
|
});
|
|
@@ -38,21 +36,17 @@ const loadCookies = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
38
36
|
try {
|
|
39
37
|
const exists = yield fs.pathExists(exports.COOKIE_FILE_PATH);
|
|
40
38
|
if (!exists) {
|
|
41
|
-
|
|
42
|
-
return null;
|
|
39
|
+
throw new Error("Arquivo de cookies não encontrado");
|
|
43
40
|
}
|
|
44
41
|
const cookies = yield fs.readJson(exports.COOKIE_FILE_PATH);
|
|
45
42
|
// Verificar se os cookies têm a estrutura esperada
|
|
46
43
|
if (!cookies.JSESSIONID || !cookies.li_at) {
|
|
47
|
-
|
|
48
|
-
return null;
|
|
44
|
+
throw new Error("Cookies inválidos encontrados no arquivo");
|
|
49
45
|
}
|
|
50
|
-
console.log(`Cookies carregados de: ${exports.COOKIE_FILE_PATH}`);
|
|
51
46
|
return cookies;
|
|
52
47
|
}
|
|
53
48
|
catch (error) {
|
|
54
|
-
|
|
55
|
-
return null;
|
|
49
|
+
throw error;
|
|
56
50
|
}
|
|
57
51
|
});
|
|
58
52
|
exports.loadCookies = loadCookies;
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./user"), exports);
|
|
18
18
|
__exportStar(require("./company"), exports);
|
|
19
19
|
__exportStar(require("./posts"), exports);
|
|
20
20
|
__exportStar(require("./search"), exports);
|
package/lib/posts.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const parseResponsePostLinkedin: (response: any, key: string, accumulatedData: any) => any;
|
|
2
|
+
export declare const getCommentsByPostUrl: (url: string, start?: number, limit?: number, accumulatedComments?: unknown[]) => Promise<unknown[]>;
|
|
2
3
|
export declare const getPosts: () => Promise<never[]>;
|
|
4
|
+
export declare const getPostLinkedin: (url: string, commentsCount?: number, likesCount?: number) => Promise<any>;
|
|
5
|
+
export declare const getUserPosts: ({ identifier, start, count, accumulatedPosts, }: {
|
|
6
|
+
identifier: string;
|
|
7
|
+
start?: number;
|
|
8
|
+
count?: number;
|
|
9
|
+
accumulatedPosts?: unknown[];
|
|
10
|
+
}) => Promise<any[]>;
|
|
11
|
+
export declare const helperGetPosts: (response: any, key: string, accumulatedPosts?: any, addFields?: Record<string, string>) => any[];
|
|
12
|
+
export declare const helperGetImageUrl: (item: any) => any;
|
package/lib/posts.js
CHANGED
|
@@ -9,9 +9,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getPosts = exports.getCommentsByPostUrl = void 0;
|
|
12
|
+
exports.helperGetImageUrl = exports.helperGetPosts = exports.getUserPosts = exports.getPostLinkedin = exports.getPosts = exports.getCommentsByPostUrl = exports.parseResponsePostLinkedin = void 0;
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
|
+
const user_1 = require("./user");
|
|
13
15
|
const config_1 = require("./config");
|
|
14
16
|
const utils_1 = require("./utils");
|
|
17
|
+
const parseResponsePostLinkedin = (response, key, accumulatedData) => {
|
|
18
|
+
var _a, _b, _c, _d;
|
|
19
|
+
const elements = (_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b[key]) === null || _c === void 0 ? void 0 : _c["*elements"];
|
|
20
|
+
const data = ((_d = response.included) === null || _d === void 0 ? void 0 : _d.filter((item) => elements.includes(item.entityUrn))) || [];
|
|
21
|
+
if (!elements || elements.length === 0) {
|
|
22
|
+
return accumulatedData;
|
|
23
|
+
}
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
exports.parseResponsePostLinkedin = parseResponsePostLinkedin;
|
|
15
27
|
const getCommentsByPostUrl = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], void 0, function* (url, start = 0, limit = 50, accumulatedComments = []) {
|
|
16
28
|
var _a, _b, _c, _d, _e;
|
|
17
29
|
const postID = (_a = url.match(/activity-(\d+)/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
@@ -19,10 +31,6 @@ const getCommentsByPostUrl = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...
|
|
|
19
31
|
const elements = (_d = (_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.socialDashCommentsBySocialDetail) === null || _d === void 0 ? void 0 : _d["*elements"];
|
|
20
32
|
// Se não há elementos, retorna os comentários acumulados
|
|
21
33
|
if (!elements || elements.length === 0) {
|
|
22
|
-
// console.log(
|
|
23
|
-
// "✅ Busca finalizada. Total de comentários:",
|
|
24
|
-
// accumulatedComments.length
|
|
25
|
-
// );
|
|
26
34
|
return accumulatedComments;
|
|
27
35
|
}
|
|
28
36
|
const data = ((_e = response.included) === null || _e === void 0 ? void 0 : _e.filter((item) => elements.includes(item.entityUrn))) || [];
|
|
@@ -38,7 +46,10 @@ const getCommentsByPostUrl = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...
|
|
|
38
46
|
permalink: "permalink",
|
|
39
47
|
image: "commenter.image.attributes.0.detailData.nonEntityProfilePicture.vectorImage",
|
|
40
48
|
};
|
|
41
|
-
const currentComments = (0, utils_1.extractFields)(data, fieldsMap)
|
|
49
|
+
const currentComments = (0, utils_1.extractFields)(data, fieldsMap).map((comment) => {
|
|
50
|
+
var _a, _b, _c, _d;
|
|
51
|
+
return (Object.assign(Object.assign({}, comment), { image: `${(_a = comment.image) === null || _a === void 0 ? void 0 : _a.rootUrl}${(_d = (_c = (_b = comment.image) === null || _b === void 0 ? void 0 : _b.artifacts) === null || _c === void 0 ? void 0 : _c.at(-1)) === null || _d === void 0 ? void 0 : _d.fileIdentifyingUrlPathSegment}` }));
|
|
52
|
+
});
|
|
42
53
|
const allComments = [...accumulatedComments, ...currentComments];
|
|
43
54
|
// console.log(
|
|
44
55
|
// `🔍 Encontrados ${elements.length} comentários (Total: ${allComments.length})`
|
|
@@ -55,3 +66,69 @@ const getPosts = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
55
66
|
return [];
|
|
56
67
|
});
|
|
57
68
|
exports.getPosts = getPosts;
|
|
69
|
+
const getPostLinkedin = (url_1, ...args_1) => __awaiter(void 0, [url_1, ...args_1], void 0, function* (url, commentsCount = 10, likesCount = 10) {
|
|
70
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
71
|
+
const slugPost = (_a = url.match(/\/posts\/([^\/?]+)/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
72
|
+
const response = yield (0, config_1.fetchData)(`/graphql?includeWebMetadata=false&queryId=voyagerFeedDashUpdates.5cf9b25c46b9d86c224647752f7d6bfd&variables=(commentsCount:${commentsCount},likesCount:${likesCount},includeCommentsFirstReply:true,includeReactions:false,moduleKey:feed-item%3Adesktop,slug:${slugPost})`);
|
|
73
|
+
const posts = (_b = (0, exports.helperGetPosts)(response, "feedDashUpdatesByPostSlug", undefined, { actor: "actor" })) === null || _b === void 0 ? void 0 : _b[0];
|
|
74
|
+
const actor = {
|
|
75
|
+
name: (_d = (_c = posts === null || posts === void 0 ? void 0 : posts.actor) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.text,
|
|
76
|
+
headline: (_f = (_e = posts === null || posts === void 0 ? void 0 : posts.actor) === null || _e === void 0 ? void 0 : _e.description) === null || _f === void 0 ? void 0 : _f.text,
|
|
77
|
+
profileUrl: ((_o = (_m = (_l = (_k = (_j = (_h = (_g = posts === null || posts === void 0 ? void 0 : posts.actor) === null || _g === void 0 ? void 0 : _g.image) === null || _h === void 0 ? void 0 : _h.attributes) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.detailData) === null || _l === void 0 ? void 0 : _l.nonEntityProfilePicture) === null || _m === void 0 ? void 0 : _m.vectorImage) === null || _o === void 0 ? void 0 : _o.rootUrl) +
|
|
78
|
+
((_x = (_w = (_v = (_u = (_t = (_s = (_r = (_q = (_p = posts === null || posts === void 0 ? void 0 : posts.actor) === null || _p === void 0 ? void 0 : _p.image) === null || _q === void 0 ? void 0 : _q.attributes) === null || _r === void 0 ? void 0 : _r[0]) === null || _s === void 0 ? void 0 : _s.detailData) === null || _t === void 0 ? void 0 : _t.nonEntityProfilePicture) === null || _u === void 0 ? void 0 : _u.vectorImage) === null || _v === void 0 ? void 0 : _v.artifacts) === null || _w === void 0 ? void 0 : _w.at(-1)) === null || _x === void 0 ? void 0 : _x.fileIdentifyingUrlPathSegment),
|
|
79
|
+
};
|
|
80
|
+
return Object.assign(Object.assign({}, posts), { actor });
|
|
81
|
+
});
|
|
82
|
+
exports.getPostLinkedin = getPostLinkedin;
|
|
83
|
+
const getUserPosts = (_a) => __awaiter(void 0, [_a], void 0, function* ({ identifier, start = 0, count = 50, accumulatedPosts = [], }) {
|
|
84
|
+
const profileId = yield (0, user_1.extractProfileIdLinkedin)(identifier);
|
|
85
|
+
const response = yield (0, config_1.fetchData)(`graphql?variables=(profileUrn:urn%3Ali%3Afsd_profile%3A${profileId},count:${count},start:${start})&queryId=voyagerFeedDashProfileUpdates.4af00b28d60ed0f1488018948daad822`);
|
|
86
|
+
const parsePosts = (0, exports.helperGetPosts)(response, "feedDashProfileUpdatesByMemberShareFeed", accumulatedPosts);
|
|
87
|
+
return parsePosts;
|
|
88
|
+
});
|
|
89
|
+
exports.getUserPosts = getUserPosts;
|
|
90
|
+
const helperGetPosts = (response, key, accumulatedPosts, addFields) => {
|
|
91
|
+
const data = (0, exports.parseResponsePostLinkedin)(response, key, accumulatedPosts);
|
|
92
|
+
const socialActivityData = response.included.filter((item) => (item === null || item === void 0 ? void 0 : item.$type) === "com.linkedin.voyager.dash.feed.SocialActivityCounts");
|
|
93
|
+
const fieldsMap = Object.assign({ urn: "metadata.backendUrn", postUrl: "socialContent.shareUrl", contentText: "commentary.text.text", tags: "commentary.text.attributesV2", media: "content", dateDescription: "actor.subDescription.text" }, addFields);
|
|
94
|
+
const fieldsSocialActivityCountMap = {
|
|
95
|
+
numLikes: "numLikes",
|
|
96
|
+
numComments: "numComments",
|
|
97
|
+
reactionCounts: "reactionTypeCounts",
|
|
98
|
+
numShares: "numShares",
|
|
99
|
+
urn: "urn",
|
|
100
|
+
};
|
|
101
|
+
const extractPosts = (0, utils_1.extractFields)(data, fieldsMap);
|
|
102
|
+
const extractSocialActivityCount = (0, utils_1.extractFields)(socialActivityData, fieldsSocialActivityCountMap);
|
|
103
|
+
const parsePosts = extractPosts === null || extractPosts === void 0 ? void 0 : extractPosts.map((post) => {
|
|
104
|
+
var _a, _b, _c;
|
|
105
|
+
const socialActivity = extractSocialActivityCount.find((item) => item.urn === post.urn) || {};
|
|
106
|
+
if (socialActivity) {
|
|
107
|
+
const mediaNonNullKeys = Object.fromEntries(Object.entries(post.media).filter(([_, value]) => value !== null));
|
|
108
|
+
let media = {};
|
|
109
|
+
if (mediaNonNullKeys === null || mediaNonNullKeys === void 0 ? void 0 : mediaNonNullKeys.imageComponent) {
|
|
110
|
+
media = Object.assign(Object.assign({}, media), { images: (_b = (_a = mediaNonNullKeys === null || mediaNonNullKeys === void 0 ? void 0 : mediaNonNullKeys.imageComponent) === null || _a === void 0 ? void 0 : _a.images) === null || _b === void 0 ? void 0 : _b.map((item) => (0, exports.helperGetImageUrl)(item)) });
|
|
111
|
+
}
|
|
112
|
+
if (mediaNonNullKeys === null || mediaNonNullKeys === void 0 ? void 0 : mediaNonNullKeys.linkedInVideoComponent) {
|
|
113
|
+
const videoentityUrn = (_c = mediaNonNullKeys === null || mediaNonNullKeys === void 0 ? void 0 : mediaNonNullKeys.linkedInVideoComponent) === null || _c === void 0 ? void 0 : _c["*videoPlayMetadata"];
|
|
114
|
+
const videoActivityData = response.included.filter((item) => (item === null || item === void 0 ? void 0 : item.entityUrn) === videoentityUrn);
|
|
115
|
+
media = Object.assign(Object.assign({}, media), { videoActivityData });
|
|
116
|
+
}
|
|
117
|
+
return Object.assign(Object.assign(Object.assign({}, post), { media }), socialActivity);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
return parsePosts;
|
|
121
|
+
};
|
|
122
|
+
exports.helperGetPosts = helperGetPosts;
|
|
123
|
+
const helperGetImageUrl = (item) => {
|
|
124
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
125
|
+
const keyEntity = ((_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.attributes) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.detailData) === null || _c === void 0 ? void 0 : _c.nonEntityProfilePicture)
|
|
126
|
+
? "nonEntityProfilePicture"
|
|
127
|
+
: "vectorImage";
|
|
128
|
+
const itemImage = (_f = (_e = (_d = item === null || item === void 0 ? void 0 : item.attributes) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.detailData) === null || _f === void 0 ? void 0 : _f[keyEntity];
|
|
129
|
+
const biggestWidth = (_g = itemImage === null || itemImage === void 0 ? void 0 : itemImage.artifacts) === null || _g === void 0 ? void 0 : _g.reduce((max, current) => {
|
|
130
|
+
return current.width > max.width ? current : max;
|
|
131
|
+
}, (_h = itemImage === null || itemImage === void 0 ? void 0 : itemImage.artifacts) === null || _h === void 0 ? void 0 : _h[0]);
|
|
132
|
+
return (itemImage === null || itemImage === void 0 ? void 0 : itemImage.rootUrl) + (biggestWidth === null || biggestWidth === void 0 ? void 0 : biggestWidth.fileIdentifyingUrlPathSegment);
|
|
133
|
+
};
|
|
134
|
+
exports.helperGetImageUrl = helperGetImageUrl;
|
package/lib/search.d.ts
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
origin?: string;
|
|
5
|
-
q?: string;
|
|
6
|
-
start?: number;
|
|
7
|
-
queryContext?: string;
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
export interface SearchElement {
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
}
|
|
13
|
-
export interface SearchDataElement {
|
|
14
|
-
elements: SearchElement[];
|
|
15
|
-
extendedElements?: SearchElement[];
|
|
16
|
-
}
|
|
17
|
-
export interface SearchResponse {
|
|
18
|
-
data: {
|
|
19
|
-
elements: SearchDataElement[];
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export interface SearchOptions {
|
|
23
|
-
limit?: number;
|
|
24
|
-
results?: SearchElement[];
|
|
25
|
-
}
|
|
26
|
-
export declare const search: (params: SearchParams, options?: SearchOptions) => Promise<SearchElement[]>;
|
|
1
|
+
import { ISearchParams, ISearchPeopleParams, ISearchPeopleResponse, SearchResponse } from "./types";
|
|
2
|
+
export declare const search: ({ offset, limit, ...opts }: ISearchParams) => Promise<SearchResponse>;
|
|
3
|
+
export declare function searchPeople(queryOrParams: string | ISearchPeopleParams): Promise<ISearchPeopleResponse>;
|
package/lib/search.js
CHANGED
|
@@ -8,126 +8,177 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
23
|
exports.search = void 0;
|
|
24
|
+
exports.searchPeople = searchPeople;
|
|
25
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
26
|
const config_1 = require("./config");
|
|
27
|
+
const utils_1 = require("./utils");
|
|
14
28
|
// Constantes
|
|
15
29
|
const MAX_SEARCH_COUNT = 25;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const response = yield api.get(endpoint);
|
|
27
|
-
return response.data;
|
|
28
|
-
});
|
|
29
|
-
// Função principal de busca
|
|
30
|
-
const search = (params_1, ...args_1) => __awaiter(void 0, [params_1, ...args_1], void 0, function* (params, options = {}) {
|
|
31
|
-
const { limit, results = [] } = options;
|
|
32
|
-
// Determinar o count baseado no limite
|
|
33
|
-
const count = limit && limit <= MAX_SEARCH_COUNT ? limit : MAX_SEARCH_COUNT;
|
|
34
|
-
// Parâmetros padrão
|
|
35
|
-
const defaultParams = {
|
|
36
|
-
count: count.toString(),
|
|
37
|
-
filters: "List()",
|
|
38
|
-
origin: "GLOBAL_SEARCH_HEADER",
|
|
39
|
-
q: "all",
|
|
40
|
-
start: results.length,
|
|
41
|
-
queryContext: "List(spellCorrectionEnabled->true,relatedSearchesEnabled->true,kcardTypes->PROFILE|COMPANY)",
|
|
30
|
+
const search = (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
var _b, _c, _d, _e, _f;
|
|
32
|
+
var { offset = 0, limit = MAX_SEARCH_COUNT } = _a, opts = __rest(_a, ["offset", "limit"]);
|
|
33
|
+
const response = {
|
|
34
|
+
paging: {
|
|
35
|
+
offset: 0,
|
|
36
|
+
count: 0,
|
|
37
|
+
total: -1,
|
|
38
|
+
},
|
|
39
|
+
results: [],
|
|
42
40
|
};
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
const params = Object.assign({ start: offset, count: Math.min(limit, MAX_SEARCH_COUNT), filters: "List()", origin: "GLOBAL_SEARCH_HEADER" }, opts);
|
|
42
|
+
const keywords = params.query
|
|
43
|
+
? `keywords:${encodeURIComponent(params.query)},`
|
|
44
|
+
: "";
|
|
45
|
+
const uri = `graphql?variables=(start:${params.start},origin:${params.origin},` +
|
|
46
|
+
`query:(${keywords}flagshipSearchIntent:SEARCH_SRP,` +
|
|
47
|
+
`queryParameters:${params.filters},includeFiltersInResponse:false))` +
|
|
48
|
+
`&queryId=voyagerSearchDashClusters.bb967969ef89137e6dec45d038310505`;
|
|
49
|
+
const res = yield (0, config_1.fetchData)(uri);
|
|
50
|
+
const dataClusters = (_c = (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.searchDashClustersByAll;
|
|
51
|
+
if (!dataClusters)
|
|
52
|
+
return response;
|
|
53
|
+
if (dataClusters.$type !== "com.linkedin.restli.common.CollectionResponse") {
|
|
54
|
+
return response;
|
|
55
|
+
}
|
|
56
|
+
response.paging.count = dataClusters.paging.count;
|
|
57
|
+
response.paging.total = dataClusters.paging.total;
|
|
58
|
+
for (const element of (_d = dataClusters.elements) !== null && _d !== void 0 ? _d : []) {
|
|
59
|
+
if (element.$type !==
|
|
60
|
+
"com.linkedin.voyager.dash.search.SearchClusterViewModel") {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
for (const it of (_e = element.items) !== null && _e !== void 0 ? _e : []) {
|
|
64
|
+
if (it.$type !== "com.linkedin.voyager.dash.search.SearchItem") {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const item = it === null || it === void 0 ? void 0 : it.item;
|
|
68
|
+
if (!item)
|
|
69
|
+
continue;
|
|
70
|
+
let entity = item.entityResult;
|
|
71
|
+
if (!entity) {
|
|
72
|
+
const linkedEntityUrn = item["*entityResult"];
|
|
73
|
+
if (!linkedEntityUrn)
|
|
74
|
+
continue;
|
|
75
|
+
entity = (_f = res.included) === null || _f === void 0 ? void 0 : _f.find((e) => e.entityUrn === linkedEntityUrn);
|
|
76
|
+
if (!entity)
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (entity.$type !==
|
|
80
|
+
"com.linkedin.voyager.dash.search.EntityResultViewModel") {
|
|
81
|
+
continue;
|
|
54
82
|
}
|
|
55
|
-
|
|
56
|
-
// - busca por palavra-chave retorna um único trabalho?
|
|
57
|
-
// if (response.data.elements[i].extendedElements) {
|
|
58
|
-
// newElements.push(...response.data.elements[i].extendedElements);
|
|
59
|
-
// }
|
|
83
|
+
response.results.push(entity);
|
|
60
84
|
}
|
|
61
85
|
}
|
|
62
|
-
|
|
63
|
-
const updatedResults = [...results, ...newElements];
|
|
64
|
-
// Sempre cortar os resultados, não importa o que a requisição retorna
|
|
65
|
-
const trimmedResults = limit
|
|
66
|
-
? updatedResults.slice(0, limit)
|
|
67
|
-
: updatedResults;
|
|
68
|
-
// Caso base da recursão
|
|
69
|
-
const shouldStop = (limit !== undefined &&
|
|
70
|
-
(trimmedResults.length >= limit || // se nossos resultados excedem o limite definido
|
|
71
|
-
trimmedResults.length / count >= MAX_REPEATED_REQUESTS)) ||
|
|
72
|
-
newElements.length === 0;
|
|
73
|
-
if (shouldStop) {
|
|
74
|
-
return trimmedResults;
|
|
75
|
-
}
|
|
76
|
-
// Chamada recursiva
|
|
77
|
-
return (0, exports.search)(params, {
|
|
78
|
-
limit,
|
|
79
|
-
results: trimmedResults,
|
|
80
|
-
});
|
|
86
|
+
return response;
|
|
81
87
|
});
|
|
82
88
|
exports.search = search;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
|
|
89
|
+
function searchPeople(queryOrParams) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
92
|
+
const _s = typeof queryOrParams === "string"
|
|
93
|
+
? { query: queryOrParams }
|
|
94
|
+
: queryOrParams, { includePrivateProfiles = true } = _s, params = __rest(_s, ["includePrivateProfiles"]);
|
|
95
|
+
const filters = ["(key:resultType,value:List(PEOPLE))"];
|
|
96
|
+
if (params.connectionOf) {
|
|
97
|
+
filters.push(`(key:connectionOf,value:List(${params.connectionOf}))`);
|
|
98
|
+
}
|
|
99
|
+
if (params.networkDepths) {
|
|
100
|
+
const stringify = params.networkDepths.join(" | ");
|
|
101
|
+
filters.push(`(key:network,value:List(${stringify}))`);
|
|
102
|
+
}
|
|
103
|
+
else if (params.networkDepth) {
|
|
104
|
+
filters.push(`(key:network,value:List(${params.networkDepth}))`);
|
|
105
|
+
}
|
|
106
|
+
if (params.regions) {
|
|
107
|
+
const stringify = params.regions.join(" | ");
|
|
108
|
+
filters.push(`(key:geoUrn,value:List(${stringify}))`);
|
|
109
|
+
}
|
|
110
|
+
if (params.industries) {
|
|
111
|
+
const stringify = params.industries.join(" | ");
|
|
112
|
+
filters.push(`(key:industry,value:List(${stringify}))`);
|
|
113
|
+
}
|
|
114
|
+
if (params.currentCompany) {
|
|
115
|
+
const stringify = params.currentCompany.join(" | ");
|
|
116
|
+
filters.push(`(key:currentCompany,value:List(${stringify}))`);
|
|
117
|
+
}
|
|
118
|
+
if (params.pastCompanies) {
|
|
119
|
+
const stringify = params.pastCompanies.join(" | ");
|
|
120
|
+
filters.push(`(key:pastCompany,value:List(${stringify}))`);
|
|
121
|
+
}
|
|
122
|
+
if (params.profileLanguages) {
|
|
123
|
+
const stringify = params.profileLanguages.join(" | ");
|
|
124
|
+
filters.push(`(key:profileLanguage,value:List(${stringify}))`);
|
|
125
|
+
}
|
|
126
|
+
if (params.nonprofitInterests) {
|
|
127
|
+
const stringify = params.nonprofitInterests.join(" | ");
|
|
128
|
+
filters.push(`(key:nonprofitInterest,value:List(${stringify}))`);
|
|
129
|
+
}
|
|
130
|
+
if (params.schools) {
|
|
131
|
+
const stringify = params.schools.join(" | ");
|
|
132
|
+
filters.push(`(key:schools,value:List(${stringify}))`);
|
|
133
|
+
}
|
|
134
|
+
if (params.serviceCategories) {
|
|
135
|
+
const stringify = params.serviceCategories.join(" | ");
|
|
136
|
+
filters.push(`(key:serviceCategory,value:List(${stringify}))`);
|
|
137
|
+
}
|
|
138
|
+
// `Keywords` filter
|
|
139
|
+
const keywordTitle = (_a = params.keywordTitle) !== null && _a !== void 0 ? _a : params.title;
|
|
140
|
+
if (params.keywordFirstName) {
|
|
141
|
+
filters.push(`(key:firstName,value:List(${params.keywordFirstName}))`);
|
|
142
|
+
}
|
|
143
|
+
if (params.keywordLastName) {
|
|
144
|
+
filters.push(`(key:lastName,value:List(${params.keywordLastName}))`);
|
|
145
|
+
}
|
|
146
|
+
if (keywordTitle) {
|
|
147
|
+
filters.push(`(key:title,value:List(${keywordTitle}))`);
|
|
148
|
+
}
|
|
149
|
+
if (params.keywordCompany) {
|
|
150
|
+
filters.push(`(key:company,value:List(${params.keywordCompany}))`);
|
|
151
|
+
}
|
|
152
|
+
if (params.keywordSchool) {
|
|
153
|
+
filters.push(`(key:school,value:List(${params.keywordSchool}))`);
|
|
154
|
+
}
|
|
155
|
+
const res = yield (0, exports.search)(Object.assign({ offset: params.offset, limit: params.limit, filters: `List(${filters.join(",")})` }, (params.query && { query: params.query })));
|
|
156
|
+
const response = {
|
|
157
|
+
paging: res.paging,
|
|
158
|
+
results: [],
|
|
159
|
+
};
|
|
160
|
+
for (const result of res.results) {
|
|
161
|
+
if (!includePrivateProfiles &&
|
|
162
|
+
((_b = result.entityCustomTrackingInfo) === null || _b === void 0 ? void 0 : _b.memberDistance) === "OUT_OF_NETWORK") {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const urnId = (0, utils_1.getIdFromUrn)((0, utils_1.getUrnFromRawUpdate)(result.entityUrn));
|
|
166
|
+
(0, utils_1.assert)(urnId);
|
|
167
|
+
const name = (_c = result.title) === null || _c === void 0 ? void 0 : _c.text;
|
|
168
|
+
(0, utils_1.assert)(name);
|
|
169
|
+
const url = (_d = result.navigationUrl) === null || _d === void 0 ? void 0 : _d.split("?")[0];
|
|
170
|
+
(0, utils_1.assert)(url);
|
|
171
|
+
response.results.push({
|
|
172
|
+
urnId,
|
|
173
|
+
name,
|
|
174
|
+
url,
|
|
175
|
+
distance: (_e = result.entityCustomTrackingInfo) === null || _e === void 0 ? void 0 : _e.memberDistance,
|
|
176
|
+
headline: (_f = result.primarySubtitle) === null || _f === void 0 ? void 0 : _f.text,
|
|
177
|
+
location: (_g = result.secondarySubtitle) === null || _g === void 0 ? void 0 : _g.text,
|
|
178
|
+
summary: ((_h = result.summary) === null || _h === void 0 ? void 0 : _h.text) || undefined,
|
|
179
|
+
image: ((_r = (_q = (_p = (_o = (_m = (_l = (_k = (_j = result.image) === null || _j === void 0 ? void 0 : _j.attributes) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.detailData) === null || _m === void 0 ? void 0 : _m.nonEntityProfilePicture) === null || _o === void 0 ? void 0 : _o.vectorImage) === null || _p === void 0 ? void 0 : _p.artifacts) === null || _q === void 0 ? void 0 : _q[0]) === null || _r === void 0 ? void 0 : _r.fileIdentifyingUrlPathSegment) || null,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return response;
|
|
183
|
+
});
|
|
184
|
+
}
|
package/lib/teste.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/teste.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const user_1 = require("./user");
|
|
4
|
+
(0, user_1.getUserMiniProfile)("wesbush")
|
|
5
|
+
.then((profile) => {
|
|
6
|
+
console.log("profile: ", profile);
|
|
7
|
+
})
|
|
8
|
+
.catch((error) => {
|
|
9
|
+
console.log("error: ", error);
|
|
10
|
+
});
|