Skip to content

Commit 80fdb72

Browse files
1.0.2 (#2)
* Fix then mapper * Simplify architecture * 1.0.2
1 parent 1d8cfc5 commit 80fdb72

38 files changed

+1496
-2681
lines changed

README.md

Lines changed: 81 additions & 289 deletions
Large diffs are not rendered by default.

examples/connections.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import LinkedApi from 'linkedapi-node';
1+
import LinkedApi, { LinkedApiError, LinkedApiWorkflowError } from 'linkedapi-node';
22

33
async function connectionsExample(): Promise<void> {
44

55
const linkedapi = new LinkedApi({
6-
accountApiToken: process.env.ACCOUNT_API_TOKEN,
7-
identificationToken: process.env.IDENTIFICATION_TOKEN,
8-
dataApiToken: process.env.DATA_API_TOKEN,
6+
apiToken: process.env.API_TOKEN!,
7+
identificationToken: process.env.IDENTIFICATION_TOKEN!,
98
});
109

1110
try {
@@ -22,10 +21,10 @@ async function connectionsExample(): Promise<void> {
2221
await removeConnection(linkedapi, targetPersonUrl2);
2322

2423
} catch (error) {
25-
if (error instanceof LinkedApi.LinkedApiError) {
24+
if (error instanceof LinkedApiError) {
2625
console.error('🚨 Linked API Error:', error.message);
2726
console.error('📝 Details:', error.details);
28-
} else if (error instanceof LinkedApi.LinkedApiWorkflowError) {
27+
} else if (error instanceof LinkedApiWorkflowError) {
2928
console.error('🚨 Linked API Workflow Error:', error.message);
3029
console.error('🔍 Reason:', error.reason);
3130
} else {
@@ -41,7 +40,7 @@ async function checkConnectionStatus(linkedapi: LinkedApi, personUrl: string): P
4140
personUrl: personUrl,
4241
};
4342

44-
const statusWorkflow = await linkedapi.account.checkConnectionStatus(statusParams);
43+
const statusWorkflow = await linkedapi.checkConnectionStatus(statusParams);
4544
console.log('🔍 Connection status workflow started:', statusWorkflow.workflowId);
4645

4746
const statusResult = await statusWorkflow.result();
@@ -58,7 +57,7 @@ async function sendConnectionRequest(linkedapi: LinkedApi, personUrl: string): P
5857
5958
};
6059

61-
const requestWorkflow = await linkedapi.account.sendConnectionRequest(requestParams);
60+
const requestWorkflow = await linkedapi.sendConnectionRequest(requestParams);
6261
console.log('📤 Send connection request workflow started:', requestWorkflow.workflowId);
6362

6463
await requestWorkflow.result();
@@ -69,7 +68,7 @@ async function sendConnectionRequest(linkedapi: LinkedApi, personUrl: string): P
6968
async function retrievePendingRequests(linkedapi: LinkedApi): Promise<void> {
7069
console.log('\n📋 Retrieving pending connection requests...');
7170

72-
const pendingWorkflow = await linkedapi.account.retrievePendingRequests();
71+
const pendingWorkflow = await linkedapi.retrievePendingRequests();
7372
console.log('📋 Retrieve pending requests workflow started:', pendingWorkflow.workflowId);
7473

7574
const pendingResults = await pendingWorkflow.result();
@@ -91,7 +90,7 @@ async function withdrawConnectionRequest(linkedapi: LinkedApi, personUrl: string
9190
unfollow: true,
9291
};
9392

94-
const withdrawWorkflow = await linkedapi.account.withdrawConnectionRequest(withdrawParams);
93+
const withdrawWorkflow = await linkedapi.withdrawConnectionRequest(withdrawParams);
9594
console.log('🔙 Withdraw connection request workflow started:', withdrawWorkflow.workflowId);
9695

9796
await withdrawWorkflow.result();
@@ -110,7 +109,7 @@ async function retrieveConnections(linkedapi: LinkedApi): Promise<void> {
110109
},
111110
};
112111

113-
const connectionsWorkflow = await linkedapi.account.retrieveConnections(connectionsParams);
112+
const connectionsWorkflow = await linkedapi.retrieveConnections(connectionsParams);
114113
console.log('👥 Retrieve connections workflow started:', connectionsWorkflow.workflowId);
115114

116115
const connectionsResults = await connectionsWorkflow.result();
@@ -132,23 +131,14 @@ async function removeConnection(linkedapi: LinkedApi, personUrl: string): Promis
132131
personUrl: personUrl,
133132
};
134133

135-
const removeWorkflow = await linkedapi.account.removeConnection(removeParams);
134+
const removeWorkflow = await linkedapi.removeConnection(removeParams);
136135
console.log('❌ Remove connection workflow started:', removeWorkflow.workflowId);
137136

138137
await removeWorkflow.result();
139138
console.log('✅ Connection removed successfully');
140139
console.log(' 🔗 No longer connected with this person');
141140
}
142141

143-
async function runExample(): Promise<void> {
144-
try {
145-
await connectionsExample();
146-
} catch (error) {
147-
console.error('💥 Example failed:', error);
148-
process.exit(1);
149-
}
150-
}
151-
152142
if (require.main === module) {
153-
runExample();
143+
connectionsExample();
154144
}

examples/custom-workflow.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1-
import LinkedApi from 'linkedapi-node';
1+
import LinkedApi, { LinkedApiError, LinkedApiWorkflowError } from 'linkedapi-node';
22

33
async function customWorkflowExample(): Promise<void> {
44

55
const linkedapi = new LinkedApi({
6-
accountApiToken: process.env.ACCOUNT_API_TOKEN,
7-
identificationToken: process.env.IDENTIFICATION_TOKEN,
8-
dataApiToken: process.env.DATA_API_TOKEN,
6+
apiToken: process.env.API_TOKEN!,
7+
identificationToken: process.env.IDENTIFICATION_TOKEN!,
98
});
109

1110
try {
1211
console.log('🚀 Linked API custom workflow example starting...');
13-
await accountApiExample(linkedapi);
12+
const customWorkflow = await linkedapi.executeCustomWorkflow({
13+
actionType: 'st.searchPeople',
14+
limit: 5,
15+
filter: {
16+
locations: ["San Francisco"],
17+
},
18+
then: {
19+
actionType: 'st.doForPeople',
20+
then: {
21+
actionType: 'st.openPersonPage',
22+
basicInfo: true,
23+
then: {
24+
actionType: 'st.retrievePersonSkills',
25+
}
26+
}
27+
}
28+
});
29+
console.log('🔍 Workflow started: ', customWorkflow.workflowId);
30+
const result = await customWorkflow.result();
31+
32+
console.log('✅ Custom workflow executed successfully');
33+
console.log('🔍 Result: ', result.completion);
1434
} catch (error) {
15-
if (error instanceof LinkedApi.LinkedApiError) {
35+
if (error instanceof LinkedApiError) {
1636
console.error('🚨 Linked API Error:', error.message);
1737
console.error('📝 Details:', error.details);
18-
} else if (error instanceof LinkedApi.LinkedApiWorkflowError) {
38+
} else if (error instanceof LinkedApiWorkflowError) {
1939
console.error('🚨 Linked API Workflow Error:', error.message);
2040
console.error('🔍 Reason:', error.reason);
2141
} else {
@@ -24,31 +44,6 @@ async function customWorkflowExample(): Promise<void> {
2444
}
2545
}
2646

27-
async function accountApiExample(linkedapi: LinkedApi): Promise<void> {
28-
const customWorkflow = await linkedapi.account.executeCustomWorkflow({
29-
actionType: 'st.searchPeople',
30-
limit: 5,
31-
filter: {
32-
locations: ["San Francisco"],
33-
},
34-
then: {
35-
actionType: 'st.doForPeople',
36-
then: {
37-
actionType: 'st.openPersonPage',
38-
basicInfo: true,
39-
then: {
40-
actionType: 'st.retrievePersonSkills',
41-
}
42-
}
43-
}
44-
});
45-
console.log('🔍 Workflow started: ', customWorkflow.workflowId);
46-
const result = await customWorkflow.result();
47-
48-
console.log('✅ Custom workflow executed successfully');
49-
console.log('🔍 Result: ', result.completion);
50-
}
51-
5247
if (require.main === module) {
5348
customWorkflowExample();
5449
}

examples/fetch-company.ts

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
import LinkedApi from 'linkedapi-node';
1+
import LinkedApi, { LinkedApiError, LinkedApiWorkflowError } from 'linkedapi-node';
22

33
async function fetchCompanyExample(): Promise<void> {
44
const linkedapi = new LinkedApi({
5-
accountApiToken: process.env.ACCOUNT_API_TOKEN,
6-
identificationToken: process.env.IDENTIFICATION_TOKEN,
7-
dataApiToken: process.env.DATA_API_TOKEN,
5+
apiToken: process.env.API_TOKEN!,
6+
identificationToken: process.env.IDENTIFICATION_TOKEN!,
87
});
98

109
try {
1110
console.log('🚀 TypeScript Linked API example starting...');
12-
await accountApiExample(linkedapi);
13-
await accountApiSalesNavigatorExample(linkedapi);
14-
await dataApiExample(linkedapi);
11+
await standardExample(linkedapi);
12+
await salesNavigatorExample(linkedapi);
1513

1614
} catch (error) {
17-
if (error instanceof LinkedApi.LinkedApiError) {
15+
if (error instanceof LinkedApiError) {
1816
console.error('🚨 Linked API Error:', error.message);
1917
console.error('📝 Details:', error.details);
20-
} else if (error instanceof LinkedApi.LinkedApiWorkflowError) {
18+
} else if (error instanceof LinkedApiWorkflowError) {
2119
console.error('🚨 Linked API Workflow Error:', error.message);
2220
console.error('🔍 Reason:', error.reason);
2321
} else {
@@ -26,8 +24,8 @@ async function fetchCompanyExample(): Promise<void> {
2624
}
2725
}
2826

29-
async function accountApiExample(linkedapi: LinkedApi): Promise<void> {
30-
const fetchCompanyWorkflow = await linkedapi.account.fetchCompany({
27+
async function standardExample(linkedapi: LinkedApi): Promise<void> {
28+
const fetchCompanyWorkflow = await linkedapi.fetchCompany({
3129
companyUrl: 'https://www.linkedin.com/company/linkedin/',
3230
retrieveEmployees: true,
3331
retrieveDms: true,
@@ -62,8 +60,8 @@ async function accountApiExample(linkedapi: LinkedApi): Promise<void> {
6260
console.log(`📝 Posts Retrieved: ${company.posts?.length || 0}`);
6361
}
6462

65-
async function accountApiSalesNavigatorExample(linkedapi: LinkedApi): Promise<void> {
66-
const nvCompanyResult = await linkedapi.account.salesNavigatorFetchCompany({
63+
async function salesNavigatorExample(linkedapi: LinkedApi): Promise<void> {
64+
const nvCompanyResult = await linkedapi.salesNavigatorFetchCompany({
6765
companyHashedUrl: 'https://www.linkedin.com/sales/company/1035',
6866
retrieveEmployees: true,
6967
retrieveDms: true,
@@ -93,48 +91,6 @@ async function accountApiSalesNavigatorExample(linkedapi: LinkedApi): Promise<vo
9391
console.log(`🎯 Decision Makers Retrieved: ${nvCompany.dms?.length || 0}`);
9492
}
9593

96-
async function dataApiExample(linkedapi: LinkedApi): Promise<void> {
97-
const dataCompanyResult = await linkedapi.data.fetchCompany({
98-
companyUrl: 'https://www.linkedin.com/sales/company/1337',
99-
retrieveEmployees: true,
100-
retrieveDms: true,
101-
employeeRetrievalConfig: {
102-
limit: 10,
103-
filter: {
104-
position: 'engineer',
105-
locations: ['United States'],
106-
industries: ['Technology', 'Software'],
107-
schools: ['Stanford University', 'MIT'],
108-
yearsOfExperiences: ['threeToFive', 'sixToTen'],
109-
},
110-
},
111-
dmRetrievalConfig: {
112-
limit: 2,
113-
},
114-
});
115-
116-
console.log('🔍 Data API company workflow started: ', dataCompanyResult.workflowId);
117-
const dataCompany = await dataCompanyResult.result();
118-
119-
console.log('✅ Data API company page opened successfully');
120-
console.log(`🏢 Company: ${dataCompany.name}`);
121-
console.log(`📖 Description: ${dataCompany.description}`);
122-
console.log(`📍 Location: ${dataCompany.location}`);
123-
console.log(`🏭 Industry: ${dataCompany.industry}`);
124-
console.log(`👥 Employee Count: ${dataCompany.employeeCount}`);
125-
console.log(`📅 Founded: ${dataCompany.yearFounded}`);
126-
console.log(`👨‍💼 Employees Retrieved: ${dataCompany.employees?.length || 0}`);
127-
}
128-
129-
async function runExample(): Promise<void> {
130-
try {
131-
await fetchCompanyExample();
132-
} catch (error) {
133-
console.error('💥 Example failed:', error);
134-
process.exit(1);
135-
}
136-
}
137-
13894
if (require.main === module) {
139-
runExample();
95+
fetchCompanyExample();
14096
}

examples/fetch-person.ts

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
import LinkedApi from 'linkedapi-node';
1+
import LinkedApi, { LinkedApiError, LinkedApiWorkflowError } from 'linkedapi-node';
22

33
async function fetchPersonExample(): Promise<void> {
44

55
const linkedapi = new LinkedApi({
6-
accountApiToken: process.env.ACCOUNT_API_TOKEN,
7-
identificationToken: process.env.IDENTIFICATION_TOKEN,
8-
dataApiToken: process.env.DATA_API_TOKEN,
6+
apiToken: process.env.API_TOKEN!,
7+
identificationToken: process.env.IDENTIFICATION_TOKEN!,
98
});
109

1110
try {
1211
console.log('🚀 Linked API fetchPerson example starting...');
1312

14-
await accountApiExample(linkedapi);
15-
await salesNavigatorAccountApiExample(linkedapi);
16-
await dataApiExample(linkedapi);
13+
await standardExample(linkedapi);
14+
await salesNavigatorExample(linkedapi);
1715
} catch (error) {
18-
if (error instanceof LinkedApi.LinkedApiError) {
16+
if (error instanceof LinkedApiError) {
1917
console.error('🚨 Linked API Error:', error.message);
2018
console.error('📝 Details:', error.details);
21-
} else if (error instanceof LinkedApi.LinkedApiWorkflowError) {
19+
} else if (error instanceof LinkedApiWorkflowError) {
2220
console.error('🚨 Linked API Workflow Error:', error.message);
2321
console.error('🔍 Reason:', error.reason);
2422
} else {
@@ -27,8 +25,8 @@ async function fetchPersonExample(): Promise<void> {
2725
}
2826
}
2927

30-
async function accountApiExample(linkedapi: LinkedApi): Promise<void> {
31-
const personResult = await linkedapi.account.fetchPerson({
28+
async function standardExample(linkedapi: LinkedApi): Promise<void> {
29+
const personResult = await linkedapi.fetchPerson({
3230
personUrl: 'https://www.linkedin.com/in/example-person/',
3331
retrieveExperience: true,
3432
retrieveEducation: true,
@@ -59,12 +57,12 @@ async function accountApiExample(linkedapi: LinkedApi): Promise<void> {
5957
console.log(`💼 Experiences: ${person.experiences}`);
6058
}
6159

62-
async function salesNavigatorAccountApiExample(linkedapi: LinkedApi): Promise<void> {
60+
async function salesNavigatorExample(linkedapi: LinkedApi): Promise<void> {
6361
const fetchParams = {
6462
personHashedUrl: 'https://www.linkedin.com/in/abc123',
6563
};
6664

67-
const personResult = await linkedapi.account.salesNavigatorFetchPerson(fetchParams);
65+
const personResult = await linkedapi.salesNavigatorFetchPerson(fetchParams);
6866
console.log('🔍 Workflow started: ', personResult.workflowId);
6967
const person = await personResult.result();
7068

@@ -74,47 +72,6 @@ async function salesNavigatorAccountApiExample(linkedapi: LinkedApi): Promise<vo
7472
console.log(`📍 Location: ${person.location}`);
7573
}
7674

77-
async function dataApiExample(linkedapi: LinkedApi): Promise<void> {
78-
const personResult = await linkedapi.data.fetchPerson({
79-
personUrl: 'https://www.linkedin.com/in/example-person/',
80-
retrieveExperience: true,
81-
retrieveEducation: true,
82-
retrieveLanguages: true,
83-
retrieveSkills: true,
84-
retrievePosts: true,
85-
retrieveComments: true,
86-
retrieveReactions: true,
87-
postsRetrievalConfig: {
88-
limit: 5,
89-
since: '2024-01-01',
90-
},
91-
commentRetrievalConfig: {
92-
limit: 5,
93-
},
94-
reactionRetrievalConfig: {
95-
limit: 5,
96-
},
97-
});
98-
console.log('🔍 Workflow started: ', personResult.workflowId);
99-
const person = await personResult.result();
100-
101-
console.log('✅ Person page opened successfully');
102-
console.log(`👤 Name: ${person.name}`);
103-
console.log(`💼 Position: ${person.position} at ${person.companyName}`);
104-
console.log(`📍 Location: ${person.location}`);
105-
console.log(`🌐 Skills: ${person.skills}`);
106-
console.log(`💼 Experiences: ${person.experiences}`);
107-
}
108-
109-
async function runExample(): Promise<void> {
110-
try {
111-
await fetchPersonExample();
112-
} catch (error) {
113-
console.error('💥 Example failed:', error);
114-
process.exit(1);
115-
}
116-
}
117-
11875
if (require.main === module) {
119-
runExample();
120-
}
76+
fetchPersonExample();
77+
}

0 commit comments

Comments
 (0)