@memberjunction/actions-bizapps-social
Version:
Social Media Actions for MemberJunction - Twitter, LinkedIn, Facebook, Instagram, TikTok, YouTube, HootSuite, Buffer
230 lines • 6.15 kB
TypeScript
import { BaseSocialMediaAction, MediaFile, SocialPost, SearchParams, SocialAnalytics } from '../../base/base-social.action';
import { AxiosInstance, AxiosError } from 'axios';
import { ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
/**
* Base class for all Facebook actions.
* Handles Facebook-specific authentication, API interactions, and rate limiting.
* Uses Facebook Graph API v18.0 with OAuth 2.0.
*/
export declare abstract class FacebookBaseAction extends BaseSocialMediaAction {
/**
* Internal method that must be implemented by derived action classes
*/
protected abstract InternalRunAction(params: RunActionParams): Promise<ActionResultSimple>;
protected get platformName(): string;
protected get apiBaseUrl(): string;
/**
* API version for cleaner URL building
*/
protected get apiVersion(): string;
/**
* Axios instance for making HTTP requests
*/
private _axiosInstance;
/**
* Get or create axios instance with interceptors
*/
protected get axiosInstance(): AxiosInstance;
/**
* Check if error is a Facebook rate limit error
*/
private isFacebookRateLimitError;
/**
* Extract wait time from Facebook rate limit error
*/
private extractRateLimitWaitTime;
/**
* Refresh the access token using the refresh token
* Note: Facebook uses long-lived tokens that last 60 days
*/
protected refreshAccessToken(): Promise<void>;
/**
* Get the authenticated user's pages
*/
protected getUserPages(): Promise<FacebookPage[]>;
/**
* Get page access token for a specific page
*/
protected getPageAccessToken(pageId: string): Promise<string>;
/**
* Upload media to Facebook
*/
protected uploadSingleMedia(file: MediaFile): Promise<string>;
/**
* Upload media to a specific page
*/
protected uploadMediaToPage(pageId: string, file: MediaFile): Promise<string>;
/**
* Validate media file meets Facebook requirements
*/
protected validateMediaFile(file: MediaFile): void;
/**
* Create a post on Facebook
*/
protected createPost(pageId: string, postData: CreatePostData): Promise<FacebookPost>;
/**
* Get a specific post
*/
protected getPost(postId: string): Promise<FacebookPost>;
/**
* Get posts from a page
*/
protected getPagePosts(pageId: string, params?: GetPagePostsParams): Promise<FacebookPost[]>;
/**
* Get paginated results from Facebook
*/
protected getPaginatedResults<T>(url: string, params?: Record<string, any>, maxResults?: number): Promise<T[]>;
/**
* Get default fields for post queries
*/
protected getPostFields(): string;
/**
* Convert Facebook post to common format
*/
protected normalizePost(fbPost: FacebookPost): SocialPost;
/**
* Extract analytics from Facebook post
*/
private extractPostAnalytics;
/**
* Normalize Facebook analytics to common format
*/
protected normalizeAnalytics(fbMetrics: any): SocialAnalytics;
/**
* Search for posts - implemented in search action
*/
protected searchPosts(params: SearchParams): Promise<SocialPost[]>;
/**
* Handle Facebook-specific errors
*/
protected handleFacebookError(error: AxiosError): never;
/**
* Parse Facebook-specific rate limit headers
*/
protected parseRateLimitHeaders(headers: any): {
remaining: number;
reset: Date;
limit: number;
} | null;
}
/**
* Facebook-specific interfaces
*/
export interface FacebookPage {
id: string;
name: string;
access_token: string;
category: string;
picture?: {
data: {
url: string;
};
};
}
export interface CreatePostData {
message?: string;
link?: string;
place?: string;
tags?: string[];
privacy?: {
value: 'EVERYONE' | 'ALL_FRIENDS' | 'FRIENDS_OF_FRIENDS' | 'SELF';
};
attached_media?: Array<{
media_fbid: string;
}>;
scheduled_publish_time?: number;
published?: boolean;
backdated_time?: number;
backdated_time_granularity?: 'year' | 'month' | 'day' | 'hour' | 'minute';
}
export interface FacebookPost {
id: string;
message?: string;
story?: string;
created_time: string;
updated_time: string;
from?: {
id: string;
name: string;
};
permalink_url?: string;
attachments?: {
data: Array<{
type: string;
title?: string;
description?: string;
url?: string;
media?: {
image?: {
src: string;
width: number;
height: number;
};
source?: string;
};
}>;
};
shares?: {
count: number;
};
reactions?: {
summary: {
total_count: number;
};
};
comments?: {
summary: {
total_count: number;
};
};
insights?: {
data: Array<{
name: string;
values: Array<{
value: number;
}>;
}>;
};
}
export interface GetPagePostsParams {
since?: Date;
until?: Date;
limit?: number;
published?: boolean;
}
export interface FacebookInsight {
name: string;
period: string;
values: Array<{
value: number | Record<string, number>;
end_time?: string;
}>;
title?: string;
description?: string;
}
export interface FacebookComment {
id: string;
message: string;
created_time: string;
from: {
id: string;
name: string;
};
like_count: number;
comment_count?: number;
parent?: {
id: string;
};
}
export interface FacebookAlbum {
id: string;
name: string;
description?: string;
link: string;
cover_photo?: {
id: string;
};
count: number;
created_time: string;
}
//# sourceMappingURL=facebook-base.action.d.ts.map