import { BasePlatform, type ActorConfig } from './base.js';
import type { UnifiedPost } from '../types.js';
export class LinkedInPlatform extends BasePlatform {
readonly config: ActorConfig = {
actorId: 'bebity/linkedin-premium-actor',
platform: 'linkedin',
defaultMaxResults: 30,
};
buildInput(params: Record<string, unknown>): Record<string, unknown> {
const input: Record<string, unknown> = {
maxResults: params.max_results ?? this.config.defaultMaxResults,
};
if (params.profile_urls) {
input.urls = params.profile_urls;
input.action = 'getProfile';
}
if (params.company_urls) {
input.urls = params.company_urls;
input.action = 'getCompanyPosts';
}
if (params.search) {
input.searchTerms = params.search;
input.action = 'searchPosts';
}
return input;
}
normalize(raw: Record<string, unknown>[]): UnifiedPost[] {
return raw.map(item => {
const text = this.safeString(item.text ?? item.commentary ?? item.description ?? '');
return {
id: this.makeId(this.safeString(item.urn ?? item.id ?? item.postId ?? '')),
platform: 'linkedin' as const,
author: {
username: this.safeString(item.authorProfileUrl ?? item.authorUrl ?? ''),
displayName: this.safeString(item.authorName ?? item.author ?? ''),
followers: this.safeNumber(item.authorFollowers ?? item.followersCount),
verified: false,
},
content: text,
url: this.safeString(item.postUrl ?? item.url ?? ''),
timestamp: this.safeDate(item.postedAt ?? item.publishedAt ?? item.date),
engagement: {
likes: this.safeNumber(item.likesCount ?? item.likes ?? item.numLikes),
comments: this.safeNumber(item.commentsCount ?? item.comments ?? item.numComments),
shares: this.safeNumber(item.repostsCount ?? item.shares ?? item.numShares),
views: this.safeNumber(item.viewsCount ?? item.views),
},
hashtags: this.extractHashtags(text),
metadata: {
articleTitle: item.articleTitle,
companyName: item.companyName,
postType: item.type,
},
};
});
}
}