Skip to content

Commit a241a3d

Browse files
Add network sync:
syncNetwork, pollNetwork, network.* webhooks
1 parent 98f6b26 commit a241a3d

8 files changed

Lines changed: 127 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@linkedapi/node",
3-
"version": "2.2.1",
3+
"version": "2.3.0",
44
"description": "Control your LinkedIn accounts and retrieve real-time data, all through this Node.js SDK.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/core/operation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const OPERATION_NAME = {
1818
sendMessage: 'sendMessage',
1919
syncConversation: 'syncConversation',
2020
syncInbox: 'syncInbox',
21+
syncNetwork: 'syncNetwork',
2122
manageConversation: 'manageConversation',
2223
checkConnectionStatus: 'checkConnectionStatus',
2324
sendConnectionRequest: 'sendConnectionRequest',

src/index.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
SendMessage,
3636
SyncConversation,
3737
SyncInbox,
38+
SyncNetwork,
3839
WithdrawConnectionRequest,
3940
} from './operations';
4041
import {
@@ -49,6 +50,8 @@ import {
4950
TInboxPollResult,
5051
TLinkedApiActionErrorType,
5152
TLinkedApiErrorType,
53+
TNetworkPollRequest,
54+
TNetworkPollResult,
5255
} from './types';
5356
import type { TLinkedApiConfig } from './types/config';
5457
import type { TLinkedApiResponse } from './types/responses';
@@ -102,6 +105,7 @@ class LinkedApi {
102105
this.sendMessage = new SendMessage(this.httpClient);
103106
this.syncConversation = new SyncConversation(this.httpClient);
104107
this.syncInbox = new SyncInbox(this.httpClient);
108+
this.syncNetwork = new SyncNetwork(this.httpClient);
105109
this.manageConversation = new ManageConversation(this.httpClient);
106110
this.checkConnectionStatus = new CheckConnectionStatus(this.httpClient);
107111
this.sendConnectionRequest = new SendConnectionRequest(this.httpClient);
@@ -138,6 +142,7 @@ class LinkedApi {
138142
this.sendMessage,
139143
this.syncConversation,
140144
this.syncInbox,
145+
this.syncNetwork,
141146
this.manageConversation,
142147
this.checkConnectionStatus,
143148
this.sendConnectionRequest,
@@ -288,6 +293,27 @@ class LinkedApi {
288293
*/
289294
public syncInbox: SyncInbox;
290295

296+
/**
297+
* Enable whole-network monitoring for standard LinkedIn.
298+
*
299+
* This method enables background monitoring of your LinkedIn network, preparing it for future
300+
* polling with {@link pollNetwork}. Once enabled, connection activity across your network is
301+
* monitored: accepted connections, newly added connections, and received connection requests.
302+
* This action takes no parameters and returns no data.
303+
*
304+
* @param params - No parameters are required
305+
* @returns Promise resolving to the sync action
306+
*
307+
* @example
308+
* ```typescript
309+
* const workflow = await linkedapi.syncNetwork.execute({});
310+
*
311+
* await linkedapi.syncNetwork.result(workflow.workflowId);
312+
* console.log("Network monitoring enabled and ready for polling");
313+
* ```
314+
*/
315+
public syncNetwork: SyncNetwork;
316+
291317
/**
292318
* Manage a standard LinkedIn conversation thread.
293319
*
@@ -547,6 +573,53 @@ class LinkedApi {
547573
};
548574
}
549575

576+
/**
577+
* Poll the monitored network to retrieve connection activity events.
578+
*
579+
* This method reads network events from the network previously enabled for monitoring via
580+
* {@link syncNetwork}, using a direct HTTP request. It returns events across the whole monitored
581+
* network, newest-first. You can optionally filter by `since` timestamp and event `type`.
582+
*
583+
* @param request - Optional filters: `since` timestamp and `type`
584+
* @returns Promise resolving to a response containing the network events
585+
*
586+
* @example
587+
* ```typescript
588+
* const pollResponse = await linkedapi.pollNetwork({
589+
* type: "connectionAccepted",
590+
* since: "2025-01-01T00:00:00Z",
591+
* });
592+
*
593+
* if (pollResponse.data) {
594+
* pollResponse.data.events.forEach((event) => {
595+
* console.log(`${event.type} ${event.personUrl} at ${event.detectedAt}`);
596+
* });
597+
* } else {
598+
* console.error("Polling failed:", pollResponse.errors);
599+
* }
600+
* ```
601+
*/
602+
public async pollNetwork(
603+
request: TNetworkPollRequest = {},
604+
): Promise<TMappedResponse<TNetworkPollResult>> {
605+
const response = await this.httpClient.post<TNetworkPollResult>('/network/poll', request);
606+
if (response.success && response.result) {
607+
return {
608+
data: response.result,
609+
errors: [],
610+
};
611+
}
612+
return {
613+
data: undefined,
614+
errors: [
615+
{
616+
type: response.error?.type as TLinkedApiActionErrorType,
617+
message: response.error?.message ?? '',
618+
},
619+
],
620+
};
621+
}
622+
550623
/**
551624
* Retrieve detailed information about a LinkedIn person profile.
552625
*

src/operations/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export * from './sync-conversation';
99
export * from './nv-sync-conversation';
1010
export * from './sync-inbox';
1111
export * from './nv-sync-inbox';
12+
export * from './sync-network';
1213
export * from './manage-conversation';
1314
export * from './nv-manage-conversation';
1415
export * from './nv-fetch-person';

src/operations/sync-network.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Operation, TOperationName } from '../core';
2+
import { VoidWorkflowMapper } from '../mappers';
3+
import { TSyncNetworkParams } from '../types';
4+
5+
export class SyncNetwork extends Operation<TSyncNetworkParams, void> {
6+
public override readonly operationName: TOperationName = 'syncNetwork';
7+
protected override readonly mapper = new VoidWorkflowMapper<TSyncNetworkParams>('st.syncNetwork');
8+
}

src/types/actions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './company';
33
export * from './connection';
44
export * from './job';
55
export * from './message';
6+
export * from './network';
67
export * from './person';
78
export * from './post';
89
export * from './search-companies';

src/types/actions/network.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { TBaseActionParams } from '../params';
2+
3+
export interface TSyncNetworkParams extends TBaseActionParams {}
4+
5+
export interface TNetworkPollRequest {
6+
since?: string;
7+
type?: TNetworkEventType;
8+
}
9+
10+
export interface TNetworkEvent {
11+
id: string;
12+
type: TNetworkEventType;
13+
personUrl: string;
14+
detectedAt: string;
15+
}
16+
17+
export interface TNetworkPollResult {
18+
events: TNetworkEvent[];
19+
}
20+
21+
export const NETWORK_EVENT_TYPE = {
22+
connectionAccepted: 'connectionAccepted',
23+
connectionAdded: 'connectionAdded',
24+
connectionRequestReceived: 'connectionRequestReceived',
25+
} as const;
26+
export type TNetworkEventType = (typeof NETWORK_EVENT_TYPE)[keyof typeof NETWORK_EVENT_TYPE];

src/types/webhooks.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export type TWebhookEventType =
1212
| 'account.deleted'
1313
| 'inbox.messageReceived'
1414
| 'inbox.messageSent'
15+
| 'network.connectionAccepted'
16+
| 'network.connectionAdded'
17+
| 'network.connectionRequestReceived'
1518
| 'webhook.test';
1619

1720
export type TWebhookDeliveryStatus = 'pending' | 'delivering' | 'success' | 'failed';
@@ -97,6 +100,18 @@ export interface TInboxMessageWebhookEvent extends TWebhookEventBase {
97100
};
98101
}
99102

103+
export interface TNetworkWebhookEvent extends TWebhookEventBase {
104+
type:
105+
| 'network.connectionAccepted'
106+
| 'network.connectionAdded'
107+
| 'network.connectionRequestReceived';
108+
data: {
109+
accountId: string;
110+
personUrl: string;
111+
detectedAt: string;
112+
};
113+
}
114+
100115
export interface TWebhookTestEvent extends TWebhookEventBase {
101116
type: 'webhook.test';
102117
data: {
@@ -108,4 +123,5 @@ export type TWebhookEvent =
108123
| TWorkflowWebhookEvent
109124
| TAccountWebhookEvent
110125
| TInboxMessageWebhookEvent
126+
| TNetworkWebhookEvent
111127
| TWebhookTestEvent;

0 commit comments

Comments
 (0)