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/src/utils.ts DELETED
@@ -1,213 +0,0 @@
1
- export function filterKeys(obj: any, keysToKeep: string[]) {
2
- const filteredObject: any = {};
3
- keysToKeep.forEach((key) => {
4
- if (obj.hasOwnProperty(key)) {
5
- filteredObject[key] = obj[key];
6
- }
7
- });
8
- return filteredObject;
9
- }
10
-
11
- export function filterOutKeys(obj: any, keysToIgnore: string[]) {
12
- const filteredObject: any = {};
13
- Object.keys(obj).forEach((key) => {
14
- if (!keysToIgnore.includes(key)) {
15
- filteredObject[key] = obj[key];
16
- }
17
- });
18
- return filteredObject;
19
- }
20
-
21
- // Nova função para extrair valores de caminhos aninhados
22
- export function getNestedValue(obj: any, path: string): any {
23
- return path.split('.').reduce((current, key) => {
24
- // Lidar com arrays como attributes[0]
25
- if (key.includes('[') && key.includes(']')) {
26
- const [arrayKey, indexStr] = key.split('[');
27
- const index = parseInt(indexStr.replace(']', ''));
28
- return current?.[arrayKey]?.[index];
29
- }
30
- return current?.[key];
31
- }, obj);
32
- }
33
-
34
- // Nova função melhorada para filtrar com caminhos aninhados
35
- export function extractFields(data: any[], fieldsMap: Record<string, string>): any[] {
36
- return data.map(item => {
37
- const extracted: any = {};
38
-
39
- Object.entries(fieldsMap).forEach(([newKey, path]) => {
40
- const value = getNestedValue(item, path);
41
- if (value !== undefined) {
42
- extracted[newKey] = value;
43
- }
44
- });
45
-
46
- return extracted;
47
- });
48
- }
49
-
50
- // Função para debug - mostra a estrutura do objeto
51
- export function debugObjectStructure(obj: any, maxDepth: number = 3, currentDepth: number = 0): void {
52
- if (currentDepth >= maxDepth) return;
53
-
54
- const indent = ' '.repeat(currentDepth);
55
-
56
- if (Array.isArray(obj)) {
57
- console.log(`${indent}Array[${obj.length}]:`);
58
- if (obj.length > 0) {
59
- console.log(`${indent} [0]:`);
60
- debugObjectStructure(obj[0], maxDepth, currentDepth + 2);
61
- }
62
- } else if (obj && typeof obj === 'object') {
63
- Object.keys(obj).slice(0, 10).forEach(key => {
64
- const value = obj[key];
65
- if (typeof value === 'object' && value !== null) {
66
- console.log(`${indent}${key}:`);
67
- debugObjectStructure(value, maxDepth, currentDepth + 1);
68
- } else {
69
- console.log(`${indent}${key}: ${typeof value} = ${String(value).slice(0, 50)}...`);
70
- }
71
- });
72
- }
73
- }
74
-
75
- // Função para resolver referências URN dinamicamente
76
- export function resolveReferences(data: any, included: any[]): any {
77
- if (!data || !included) return data;
78
-
79
- // Criar um mapa de URN para acesso rápido
80
- const urnMap = new Map();
81
- included.forEach(item => {
82
- if (item.entityUrn) {
83
- urnMap.set(item.entityUrn, item);
84
- }
85
- });
86
-
87
- // Função recursiva para resolver referências
88
- function resolveObject(obj: any): any {
89
- if (Array.isArray(obj)) {
90
- return obj.map(item => resolveObject(item));
91
- }
92
-
93
- if (obj && typeof obj === 'object') {
94
- const resolved: any = {};
95
-
96
- Object.entries(obj).forEach(([key, value]) => {
97
- // Detectar chaves que começam com * (referências URN)
98
- if (key.startsWith('*') && typeof value === 'string') {
99
- const referencedData = urnMap.get(value);
100
- if (referencedData) {
101
- // Remover o * e usar como chave
102
- const cleanKey = key.substring(1);
103
- resolved[cleanKey] = resolveObject(referencedData);
104
- } else {
105
- resolved[key] = value; // Manter original se não encontrar
106
- }
107
- }
108
- // Detectar arrays de URNs
109
- else if (Array.isArray(value) && value.length > 0 && typeof value[0] === 'string' && value[0].startsWith('urn:li:')) {
110
- const resolvedArray = value.map(urn => {
111
- const referencedData = urnMap.get(urn);
112
- return referencedData ? resolveObject(referencedData) : urn;
113
- }).filter(item => item !== null);
114
- resolved[key] = resolvedArray;
115
- }
116
- // Recursão para objetos aninhados
117
- else if (value && typeof value === 'object') {
118
- resolved[key] = resolveObject(value);
119
- }
120
- // Valores primitivos
121
- else {
122
- resolved[key] = value;
123
- }
124
- });
125
-
126
- return resolved;
127
- }
128
-
129
- return obj;
130
- }
131
-
132
- return resolveObject(data);
133
- }
134
-
135
- // Função para extrair dados com resolução automática de referências
136
- export function extractDataWithReferences(
137
- elements: string[],
138
- included: any[],
139
- fieldsMap?: Record<string, string>
140
- ): any[] {
141
- // Filtrar dados pelos elementos
142
- const filteredData = included.filter(item =>
143
- elements.includes(item.entityUrn)
144
- );
145
-
146
- // Resolver todas as referências
147
- const resolvedData = filteredData.map(item =>
148
- resolveReferences(item, included)
149
- );
150
-
151
- // Se há mapeamento de campos, aplicar
152
- if (fieldsMap) {
153
- return extractFields(resolvedData, fieldsMap);
154
- }
155
-
156
- return resolvedData;
157
- }
158
-
159
- // Função para debug de estrutura com referências resolvidas
160
- export function debugResolvedStructure(
161
- elements: string[],
162
- included: any[],
163
- maxDepth: number = 2
164
- ): void {
165
- console.log('🔍 Estrutura dos dados com referências resolvidas:');
166
- const resolved = extractDataWithReferences(elements, included);
167
-
168
- if (resolved.length > 0) {
169
- console.log(`📊 Total de itens: ${resolved.length}`);
170
- console.log('📋 Estrutura do primeiro item:');
171
- debugObjectStructure(resolved[0], maxDepth);
172
- }
173
- }
174
-
175
- // Função para extrair campos específicos de todos os objetos no included
176
- export function extractFieldsFromIncluded(
177
- included: any[],
178
- fields: string[]
179
- ): Record<string, any>[] {
180
- return included
181
- .filter(item => fields.some(field => item[field] !== undefined))
182
- .map(item => {
183
- const extracted: any = { entityUrn: item.entityUrn };
184
-
185
- fields.forEach(field => {
186
- if (item[field] !== undefined) {
187
- extracted[field] = item[field];
188
- }
189
- });
190
-
191
- return extracted;
192
- });
193
- }
194
-
195
- // Função para associar dados extras aos dados principais
196
- export function mergeExtraFields(
197
- mainData: any[],
198
- extraData: Record<string, any>[],
199
- matchKey: string = 'companyUrn'
200
- ): any[] {
201
- return mainData.map(item => {
202
- const extraItem = extraData.find(extra =>
203
- item[matchKey] && extra.entityUrn === item[matchKey]
204
- );
205
-
206
- if (extraItem) {
207
- const { entityUrn, ...extraFields } = extraItem;
208
- return { ...item, ...extraFields };
209
- }
210
-
211
- return item;
212
- });
213
- }
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "CommonJS",
5
- "declaration": true,
6
- "outDir": "./lib",
7
- "strict": true
8
- },
9
- "include": ["src/**/*"]
10
- }