linkedin-api-voyager 1.3.0 → 1.3.2
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/README.md +232 -133
- package/lib/company.d.ts +1 -0
- package/lib/company.js +40 -0
- package/lib/config.d.ts +20 -0
- package/lib/config.js +94 -0
- package/{src/index.ts → lib/index.d.ts} +1 -1
- package/lib/index.js +22 -0
- package/lib/posts.d.ts +12 -0
- package/lib/posts.js +134 -0
- package/lib/search.d.ts +3 -0
- package/lib/search.js +184 -0
- 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 +45 -0
- package/lib/utils.js +606 -0
- package/package.json +11 -4
- package/src/account.ts +0 -116
- package/src/company.ts +0 -33
- package/src/config.ts +0 -109
- package/src/linkedin.ts +0 -0
- package/src/posts.ts +0 -71
- package/src/search.ts +0 -183
- package/src/utils.ts +0 -213
- package/tsconfig.json +0 -10
package/src/account.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { fetchData } from "./config";
|
|
2
|
-
import {
|
|
3
|
-
extractDataWithReferences,
|
|
4
|
-
extractFields,
|
|
5
|
-
extractFieldsFromIncluded,
|
|
6
|
-
mergeExtraFields,
|
|
7
|
-
} from "./utils";
|
|
8
|
-
|
|
9
|
-
export const getProfile = async (identifier: string) => {
|
|
10
|
-
const response = await fetchData(
|
|
11
|
-
`/identity/profiles/${identifier}/profileView`
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const data = response.data;
|
|
15
|
-
const dataResult: any[] = response?.included;
|
|
16
|
-
|
|
17
|
-
const getEntityByUrn = (urn: string) =>
|
|
18
|
-
dataResult.find((item) => item.entityUrn === urn);
|
|
19
|
-
|
|
20
|
-
const keyProfile = getEntityByUrn(data?.["*profile"]);
|
|
21
|
-
if (!keyProfile) throw new Error("Key profile not found");
|
|
22
|
-
|
|
23
|
-
const miniProfile = getEntityByUrn(keyProfile?.["*miniProfile"]);
|
|
24
|
-
if (!miniProfile) throw new Error("Mini profile not found");
|
|
25
|
-
|
|
26
|
-
const profile = {
|
|
27
|
-
// id_urn: keyProfile.entityUrn?.split("urn:li:fs_profile:")[1] || null,
|
|
28
|
-
publicIdentifier: miniProfile?.publicIdentifier || null,
|
|
29
|
-
firstName: keyProfile.firstName || null,
|
|
30
|
-
lastName: keyProfile.lastName || null,
|
|
31
|
-
fullName: `${keyProfile.firstName || ""} ${keyProfile.lastName || ""}`,
|
|
32
|
-
birthDate: keyProfile.birthDate
|
|
33
|
-
? JSON.stringify({
|
|
34
|
-
month: keyProfile.birthDate.month,
|
|
35
|
-
day: keyProfile.birthDate.day,
|
|
36
|
-
})
|
|
37
|
-
: null,
|
|
38
|
-
profilePicture: miniProfile.picture
|
|
39
|
-
? `${miniProfile.picture.rootUrl}${
|
|
40
|
-
miniProfile.picture.artifacts[
|
|
41
|
-
miniProfile.picture.artifacts.length - 1
|
|
42
|
-
]?.fileIdentifyingUrlPathSegment
|
|
43
|
-
}`
|
|
44
|
-
: null,
|
|
45
|
-
backgroundPicture: miniProfile.backgroundImage
|
|
46
|
-
? `${miniProfile.backgroundImage.rootUrl}${
|
|
47
|
-
miniProfile.backgroundImage.artifacts[
|
|
48
|
-
miniProfile.backgroundImage.artifacts.length - 1
|
|
49
|
-
]?.fileIdentifyingUrlPathSegment
|
|
50
|
-
}`
|
|
51
|
-
: null,
|
|
52
|
-
location: {
|
|
53
|
-
country: keyProfile.locationName || null,
|
|
54
|
-
city: keyProfile.geoLocationName || null,
|
|
55
|
-
},
|
|
56
|
-
address: keyProfile.address || null,
|
|
57
|
-
industry: keyProfile.industryName || null,
|
|
58
|
-
headline: keyProfile.headline || null,
|
|
59
|
-
summary: keyProfile.summary || null,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
return profile;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const getProfissionalExperiences = async (identifier: string) => {
|
|
66
|
-
const response = await fetchData(
|
|
67
|
-
`/identity/profiles/${identifier}/positions`
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
let { data, included } = response;
|
|
71
|
-
const elements = data["*elements"] as string[];
|
|
72
|
-
|
|
73
|
-
// Usar a nova função para resolver referências automaticamente
|
|
74
|
-
const dataExperiences = extractDataWithReferences(elements, included);
|
|
75
|
-
|
|
76
|
-
// Extrair campos específicos do included
|
|
77
|
-
const extraFields = extractFieldsFromIncluded(included, ["universalName"]);
|
|
78
|
-
|
|
79
|
-
// Mapeamento de campos
|
|
80
|
-
const fieldsMap = {
|
|
81
|
-
id: "entityUrn",
|
|
82
|
-
title: "title",
|
|
83
|
-
companyName: "company.miniCompany.name",
|
|
84
|
-
companyUrn: "companyUrn",
|
|
85
|
-
companyEmployeeCount: "company.employeeCountRange",
|
|
86
|
-
companyIndustries: "company.miniCompany.industries",
|
|
87
|
-
description: "description",
|
|
88
|
-
location: "locationName",
|
|
89
|
-
geoLocation: "geoLocationName",
|
|
90
|
-
timePeriod: "timePeriod",
|
|
91
|
-
startDate: "timePeriod.startDate",
|
|
92
|
-
endDate: "timePeriod.endDate",
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// Aplicar mapeamento aos dados resolvidos
|
|
96
|
-
const mappedExperiences = extractFields(dataExperiences, fieldsMap);
|
|
97
|
-
|
|
98
|
-
// Associar campos extras
|
|
99
|
-
const experiencesWithExtras = mergeExtraFields(
|
|
100
|
-
mappedExperiences,
|
|
101
|
-
extraFields,
|
|
102
|
-
"companyUrn"
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
// Ordenar: sem endDate (ativo) primeiro, depois do mais recente ao mais antigo
|
|
106
|
-
return experiencesWithExtras.sort((a, b) => {
|
|
107
|
-
if (!a.endDate && b.endDate) return -1;
|
|
108
|
-
if (a.endDate && !b.endDate) return 1;
|
|
109
|
-
if (!a.endDate && !b.endDate) return 0;
|
|
110
|
-
|
|
111
|
-
const yearDiff = (b.endDate.year || 0) - (a.endDate.year || 0);
|
|
112
|
-
if (yearDiff !== 0) return yearDiff;
|
|
113
|
-
|
|
114
|
-
return (b.endDate.month || 0) - (a.endDate.month || 0);
|
|
115
|
-
});
|
|
116
|
-
};
|
package/src/company.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { fetchData } from "./config";
|
|
2
|
-
import { extractDataWithReferences, extractFields } from "./utils";
|
|
3
|
-
|
|
4
|
-
export const getCompany = async (identifier: string) => {
|
|
5
|
-
const response = await fetchData(
|
|
6
|
-
`/organization/companies?decorationId=com.linkedin.voyager.deco.organization.web.WebFullCompanyMain-12&q=universalName&universalName=${identifier}`
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
const data = extractDataWithReferences(
|
|
10
|
-
response.data["*elements"],
|
|
11
|
-
response.included
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
const fieldsMap = {
|
|
15
|
-
id: "entityUrn",
|
|
16
|
-
name: "name",
|
|
17
|
-
description: "description",
|
|
18
|
-
username: "universalName",
|
|
19
|
-
companyPageUrl: "companyPageUrl",
|
|
20
|
-
staffCount: "staffCount",
|
|
21
|
-
url: "url",
|
|
22
|
-
companyIndustries: "*companyIndustries[0].localizedName",
|
|
23
|
-
location: "locationName",
|
|
24
|
-
jobSearchPageUrl: "jobSearchPageUrl",
|
|
25
|
-
phone: "phone",
|
|
26
|
-
followerCount: "followingInfo.followerCount",
|
|
27
|
-
backgroundCoverImage: "backgroundCoverImage.image",
|
|
28
|
-
logo: "logo.image",
|
|
29
|
-
permissions: "permissions",
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
return extractFields(data, fieldsMap)[0];
|
|
33
|
-
};
|
package/src/config.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
import * as os from "os";
|
|
3
|
-
import * as fs from "fs-extra";
|
|
4
|
-
import axios from "axios";
|
|
5
|
-
|
|
6
|
-
export const COOKIE_FILE_PATH = "linkedin_cookies.json";
|
|
7
|
-
|
|
8
|
-
export const API_BASE_URL = "https://www.linkedin.com/voyager/api";
|
|
9
|
-
export const AUTH_BASE_URL = "https://www.linkedin.com";
|
|
10
|
-
|
|
11
|
-
// Interface para os cookies
|
|
12
|
-
interface LinkedInCookies {
|
|
13
|
-
JSESSIONID: string;
|
|
14
|
-
li_at: string;
|
|
15
|
-
timestamp: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Função para salvar cookies no arquivo JSON
|
|
19
|
-
export const saveCookies = async (
|
|
20
|
-
JSESSIONID: string,
|
|
21
|
-
li_at: string
|
|
22
|
-
): Promise<void> => {
|
|
23
|
-
try {
|
|
24
|
-
const cookies: LinkedInCookies = {
|
|
25
|
-
JSESSIONID,
|
|
26
|
-
li_at,
|
|
27
|
-
timestamp: Date.now(),
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
await fs.ensureFile(COOKIE_FILE_PATH);
|
|
31
|
-
await fs.writeJson(COOKIE_FILE_PATH, cookies, { spaces: 2 });
|
|
32
|
-
console.log(`Cookies salvos em: ${COOKIE_FILE_PATH}`);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
console.error("Erro ao salvar cookies:", error);
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// Função para carregar cookies do arquivo JSON
|
|
40
|
-
export const loadCookies = async (): Promise<LinkedInCookies | null> => {
|
|
41
|
-
try {
|
|
42
|
-
const exists = await fs.pathExists(COOKIE_FILE_PATH);
|
|
43
|
-
if (!exists) {
|
|
44
|
-
console.log("Arquivo de cookies não encontrado");
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const cookies = await fs.readJson(COOKIE_FILE_PATH);
|
|
49
|
-
|
|
50
|
-
// Verificar se os cookies têm a estrutura esperada
|
|
51
|
-
if (!cookies.JSESSIONID || !cookies.li_at) {
|
|
52
|
-
console.log("Cookies inválidos encontrados no arquivo");
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log(`Cookies carregados de: ${COOKIE_FILE_PATH}`);
|
|
57
|
-
return cookies;
|
|
58
|
-
} catch (error) {
|
|
59
|
-
console.error("Erro ao carregar cookies:", error);
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Função para criar cliente com cookies automáticos
|
|
65
|
-
export const Client = async (providedCookies?: {
|
|
66
|
-
JSESSIONID: string;
|
|
67
|
-
li_at: string;
|
|
68
|
-
}): Promise<ReturnType<typeof api>> => {
|
|
69
|
-
let cookiesToUse: { JSESSIONID: string; li_at: string };
|
|
70
|
-
const savedCookies = await loadCookies();
|
|
71
|
-
|
|
72
|
-
if (savedCookies) {
|
|
73
|
-
cookiesToUse = {
|
|
74
|
-
JSESSIONID: savedCookies.JSESSIONID,
|
|
75
|
-
li_at: savedCookies.li_at,
|
|
76
|
-
};
|
|
77
|
-
} else {
|
|
78
|
-
if (providedCookies) {
|
|
79
|
-
await saveCookies(providedCookies.JSESSIONID, providedCookies.li_at);
|
|
80
|
-
cookiesToUse = providedCookies;
|
|
81
|
-
} else {
|
|
82
|
-
throw new Error("Nenhum cookie válido fornecido");
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return api({
|
|
87
|
-
JSESSIONID: parseInt(cookiesToUse.JSESSIONID),
|
|
88
|
-
li_at: cookiesToUse.li_at,
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const api = ({ JSESSIONID, li_at }: { li_at: string; JSESSIONID: number }) => {
|
|
93
|
-
return axios.create({
|
|
94
|
-
baseURL: API_BASE_URL,
|
|
95
|
-
headers: {
|
|
96
|
-
"accept-language":
|
|
97
|
-
"pt-BR,pt;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5",
|
|
98
|
-
accept: "application/vnd.linkedin.normalized+json+2.1",
|
|
99
|
-
cookie: `li_at=${li_at}; JSESSIONID="ajax:${JSESSIONID}"`,
|
|
100
|
-
"csrf-token": `ajax:${JSESSIONID}`,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export const fetchData = async (endpoint: string) => {
|
|
106
|
-
const api = await Client();
|
|
107
|
-
const response = await api.get(endpoint);
|
|
108
|
-
return response.data;
|
|
109
|
-
};
|
package/src/linkedin.ts
DELETED
|
File without changes
|
package/src/posts.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { fetchData } from "./config";
|
|
2
|
-
import { extractFields } from "./utils";
|
|
3
|
-
|
|
4
|
-
export const getCommentsByPostUrl = async (
|
|
5
|
-
url: string,
|
|
6
|
-
start: number = 0,
|
|
7
|
-
limit: number = 50,
|
|
8
|
-
accumulatedComments: any[] = []
|
|
9
|
-
): Promise<any[]> => {
|
|
10
|
-
const postID = url.match(/activity-(\d+)/)?.[1];
|
|
11
|
-
|
|
12
|
-
const response = await fetchData(
|
|
13
|
-
`/graphql?includeWebMetadata=false&queryId=voyagerSocialDashComments.95ed44bc87596acce7c460c70934d0ff&variables=(count:${limit},start:${start},numReplies:1,socialDetailUrn:urn%3Ali%3Afsd_socialDetail%3A%28urn%3Ali%3Aactivity%${postID}%2Curn%3Ali%3Aactivity%3A${postID}%2Curn%3Ali%3AhighlightedReply%3A-%29,sortOrder:RELEVANCE)`
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const elements = response.data?.data?.socialDashCommentsBySocialDetail?.[
|
|
17
|
-
"*elements"
|
|
18
|
-
] as string[];
|
|
19
|
-
|
|
20
|
-
// Se não há elementos, retorna os comentários acumulados
|
|
21
|
-
if (!elements || elements.length === 0) {
|
|
22
|
-
// console.log(
|
|
23
|
-
// "✅ Busca finalizada. Total de comentários:",
|
|
24
|
-
// accumulatedComments.length
|
|
25
|
-
// );
|
|
26
|
-
return accumulatedComments;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const data =
|
|
30
|
-
response.included?.filter((item: any) =>
|
|
31
|
-
elements.includes(item.entityUrn)
|
|
32
|
-
) || [];
|
|
33
|
-
|
|
34
|
-
// Mapeamento melhorado dos campos
|
|
35
|
-
const fieldsMap = {
|
|
36
|
-
id: "entityUrn",
|
|
37
|
-
createdAt: "createdAt",
|
|
38
|
-
isAuthor: "commenter.author",
|
|
39
|
-
name: "commenter.title.text",
|
|
40
|
-
headline: "commenter.subtitle",
|
|
41
|
-
profileUrl: "commenter.navigationUrl",
|
|
42
|
-
comment: "commentary.text",
|
|
43
|
-
permalink: "permalink",
|
|
44
|
-
image:
|
|
45
|
-
"commenter.image.attributes.0.detailData.nonEntityProfilePicture.vectorImage",
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const currentComments = extractFields(data, fieldsMap);
|
|
49
|
-
const allComments = [...accumulatedComments, ...currentComments];
|
|
50
|
-
|
|
51
|
-
// console.log(
|
|
52
|
-
// `🔍 Encontrados ${elements.length} comentários (Total: ${allComments.length})`
|
|
53
|
-
// );
|
|
54
|
-
|
|
55
|
-
// Continua a busca se há mais elementos
|
|
56
|
-
if (elements.length > 0) {
|
|
57
|
-
return await getCommentsByPostUrl(
|
|
58
|
-
url,
|
|
59
|
-
start + elements.length,
|
|
60
|
-
limit,
|
|
61
|
-
allComments
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Se retornou menos que o limite, chegou ao fim
|
|
66
|
-
return allComments;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const getPosts = async () => {
|
|
70
|
-
return [];
|
|
71
|
-
};
|
package/src/search.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { Client as ClientState } from "./config";
|
|
2
|
-
|
|
3
|
-
// Constantes
|
|
4
|
-
const MAX_SEARCH_COUNT = 25;
|
|
5
|
-
const MAX_REPEATED_REQUESTS = 40;
|
|
6
|
-
|
|
7
|
-
// Interfaces
|
|
8
|
-
export interface SearchParams {
|
|
9
|
-
count?: string;
|
|
10
|
-
filters?: string;
|
|
11
|
-
origin?: string;
|
|
12
|
-
q?: string;
|
|
13
|
-
start?: number;
|
|
14
|
-
queryContext?: string;
|
|
15
|
-
[key: string]: any; // Para permitir parâmetros adicionais
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface SearchElement {
|
|
19
|
-
[key: string]: any; // Estrutura flexível para elementos de busca
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface SearchDataElement {
|
|
23
|
-
elements: SearchElement[];
|
|
24
|
-
extendedElements?: SearchElement[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface SearchResponse {
|
|
28
|
-
data: {
|
|
29
|
-
elements: SearchDataElement[];
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface SearchOptions {
|
|
34
|
-
limit?: number;
|
|
35
|
-
results?: SearchElement[];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Função utilitária para criar query string
|
|
39
|
-
const createQueryString = (params: Record<string, any>): string => {
|
|
40
|
-
return Object.entries(params)
|
|
41
|
-
.map(
|
|
42
|
-
([key, value]) =>
|
|
43
|
-
`${encodeURIComponent(key)}=${encodeURIComponent(value)}`
|
|
44
|
-
)
|
|
45
|
-
.join("&");
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// Função utilitária para fazer fetch (assumindo que existe uma função _fetch no client)
|
|
49
|
-
const fetchData = async (endpoint: string): Promise<SearchResponse> => {
|
|
50
|
-
const api = await ClientState();
|
|
51
|
-
const response = await api.get(endpoint);
|
|
52
|
-
return response.data;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Função principal de busca
|
|
56
|
-
export const search = async (
|
|
57
|
-
params: SearchParams,
|
|
58
|
-
options: SearchOptions = {}
|
|
59
|
-
): Promise<SearchElement[]> => {
|
|
60
|
-
const { limit, results = [] } = options;
|
|
61
|
-
|
|
62
|
-
// Determinar o count baseado no limite
|
|
63
|
-
const count = limit && limit <= MAX_SEARCH_COUNT ? limit : MAX_SEARCH_COUNT;
|
|
64
|
-
|
|
65
|
-
// Parâmetros padrão
|
|
66
|
-
const defaultParams: SearchParams = {
|
|
67
|
-
count: count.toString(),
|
|
68
|
-
filters: "List()",
|
|
69
|
-
origin: "GLOBAL_SEARCH_HEADER",
|
|
70
|
-
q: "all",
|
|
71
|
-
start: results.length,
|
|
72
|
-
queryContext:
|
|
73
|
-
"List(spellCorrectionEnabled->true,relatedSearchesEnabled->true,kcardTypes->PROFILE|COMPANY)",
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
// Mesclar parâmetros padrão com os fornecidos
|
|
77
|
-
const mergedParams = { ...defaultParams, ...params };
|
|
78
|
-
|
|
79
|
-
// Fazer a requisição
|
|
80
|
-
const endpoint = `/search/blended?${createQueryString(mergedParams)}`;
|
|
81
|
-
|
|
82
|
-
const response = await fetchData(endpoint);
|
|
83
|
-
|
|
84
|
-
// Processar os dados da resposta
|
|
85
|
-
const newElements: SearchElement[] = [];
|
|
86
|
-
|
|
87
|
-
if (response.data && response.data.elements) {
|
|
88
|
-
for (let i = 0; i < response.data.elements.length; i++) {
|
|
89
|
-
if (response.data.elements[i].elements) {
|
|
90
|
-
newElements.push(...response.data.elements[i].elements);
|
|
91
|
-
}
|
|
92
|
-
// Comentário: não tenho certeza do que extendedElements geralmente se refere
|
|
93
|
-
// - busca por palavra-chave retorna um único trabalho?
|
|
94
|
-
// if (response.data.elements[i].extendedElements) {
|
|
95
|
-
// newElements.push(...response.data.elements[i].extendedElements);
|
|
96
|
-
// }
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Adicionar novos elementos aos resultados
|
|
101
|
-
const updatedResults = [...results, ...newElements];
|
|
102
|
-
|
|
103
|
-
// Sempre cortar os resultados, não importa o que a requisição retorna
|
|
104
|
-
const trimmedResults = limit
|
|
105
|
-
? updatedResults.slice(0, limit)
|
|
106
|
-
: updatedResults;
|
|
107
|
-
|
|
108
|
-
// Caso base da recursão
|
|
109
|
-
const shouldStop =
|
|
110
|
-
(limit !== undefined &&
|
|
111
|
-
(trimmedResults.length >= limit || // se nossos resultados excedem o limite definido
|
|
112
|
-
trimmedResults.length / count >= MAX_REPEATED_REQUESTS)) ||
|
|
113
|
-
newElements.length === 0;
|
|
114
|
-
|
|
115
|
-
if (shouldStop) {
|
|
116
|
-
return trimmedResults;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Chamada recursiva
|
|
120
|
-
return search(params, {
|
|
121
|
-
limit,
|
|
122
|
-
results: trimmedResults,
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// Função auxiliar para busca simples (não recursiva)
|
|
127
|
-
// export const searchSingle = async (
|
|
128
|
-
// client: ClientState,
|
|
129
|
-
// params: SearchParams
|
|
130
|
-
// ): Promise<SearchElement[]> => {
|
|
131
|
-
// return search(client, params, { limit: MAX_SEARCH_COUNT });
|
|
132
|
-
// };
|
|
133
|
-
|
|
134
|
-
// // Função para busca com limite específico
|
|
135
|
-
// export const searchWithLimit = async (
|
|
136
|
-
// client: ClientState,
|
|
137
|
-
// params: SearchParams,
|
|
138
|
-
// limit: number
|
|
139
|
-
// ): Promise<SearchElement[]> => {
|
|
140
|
-
// return search(client, params, { limit });
|
|
141
|
-
// };
|
|
142
|
-
|
|
143
|
-
// // Função para busca de pessoas
|
|
144
|
-
// export const searchPeople = async (
|
|
145
|
-
// client: ClientState,
|
|
146
|
-
// query: string,
|
|
147
|
-
// limit?: number
|
|
148
|
-
// ): Promise<SearchElement[]> => {
|
|
149
|
-
// const params: SearchParams = {
|
|
150
|
-
// keywords: query,
|
|
151
|
-
// filters: "List(resultType->PEOPLE)",
|
|
152
|
-
// };
|
|
153
|
-
|
|
154
|
-
// return search(client, params, { limit });
|
|
155
|
-
// };
|
|
156
|
-
|
|
157
|
-
// // Função para busca de empresas
|
|
158
|
-
// export const searchCompanies = async (
|
|
159
|
-
// client: ClientState,
|
|
160
|
-
// query: string,
|
|
161
|
-
// limit?: number
|
|
162
|
-
// ): Promise<SearchElement[]> => {
|
|
163
|
-
// const params: SearchParams = {
|
|
164
|
-
// keywords: query,
|
|
165
|
-
// filters: "List(resultType->COMPANIES)",
|
|
166
|
-
// };
|
|
167
|
-
|
|
168
|
-
// return search(client, params, { limit });
|
|
169
|
-
// };
|
|
170
|
-
|
|
171
|
-
// // Função para busca de empregos
|
|
172
|
-
// export const searchJobs = async (
|
|
173
|
-
// client: ClientState,
|
|
174
|
-
// query: string,
|
|
175
|
-
// limit?: number
|
|
176
|
-
// ): Promise<SearchElement[]> => {
|
|
177
|
-
// const params: SearchParams = {
|
|
178
|
-
// keywords: query,
|
|
179
|
-
// filters: "List(resultType->JOBS)",
|
|
180
|
-
// };
|
|
181
|
-
|
|
182
|
-
// return search(client, params, { limit });
|
|
183
|
-
// };
|