postiz/libraries/nestjs-libraries/src/integrations/social/social.integrations.interfa...

135 lines
3.1 KiB
TypeScript

import { Integration } from '@prisma/client';
export interface ClientInformation {
client_id: string;
client_secret: string;
instanceUrl: string;
}
export interface IAuthenticator {
authenticate(
params: {
code: string;
codeVerifier: string;
refresh?: string;
},
clientInformation?: ClientInformation
): Promise<AuthTokenDetails | string>;
refreshToken(refreshToken: string): Promise<AuthTokenDetails>;
reConnect?(
id: string,
requiredId: string,
accessToken: string
): Promise<AuthTokenDetails>;
generateAuthUrl(
clientInformation?: ClientInformation
): Promise<GenerateAuthUrlResponse>;
analytics?(
id: string,
accessToken: string,
date: number
): Promise<AnalyticsData[]>;
changeNickname?(
id: string,
accessToken: string,
name: string
): Promise<{ name: string }>;
changeProfilePicture?(
id: string,
accessToken: string,
url: string
): Promise<{ url: string }>;
}
export interface AnalyticsData {
label: string;
data: Array<{ total: string; date: string }>;
percentageChange: number;
}
export type GenerateAuthUrlResponse = {
url: string;
codeVerifier: string;
state: string;
};
export type AuthTokenDetails = {
id: string;
name: string;
error?: string;
accessToken: string; // The obtained access token
refreshToken?: string; // The refresh token, if applicable
expiresIn?: number; // The duration in seconds for which the access token is valid
picture?: string;
username: string;
additionalSettings?: {
title: string;
description: string;
type: 'checkbox' | 'text' | 'textarea';
value: any;
regex?: string;
}[];
};
export interface ISocialMediaIntegration {
post(
id: string,
accessToken: string,
postDetails: PostDetails[],
integration: Integration
): Promise<PostResponse[]>; // Schedules a new post
}
export type PostResponse = {
id: string; // The db internal id of the post
postId: string; // The ID of the scheduled post returned by the platform
releaseURL: string; // The URL of the post on the platform
status: string; // Status of the operation or initial post status
};
export type PostDetails<T = any> = {
id: string;
message: string;
settings: T;
media?: MediaContent[];
poll?: PollDetails;
};
export type PollDetails = {
options: string[]; // Array of poll options
duration: number; // Duration in hours for which the poll will be active
};
export type MediaContent = {
type: 'image' | 'video'; // Type of the media content
path: string;
alt?: string;
thumbnail?: string;
thumbnailTimestamp?: number;
};
export interface SocialProvider
extends IAuthenticator,
ISocialMediaIntegration {
identifier: string;
refreshWait?: boolean;
convertToJPEG?: boolean;
isWeb3?: boolean;
customFields?: () => Promise<
{
key: string;
label: string;
defaultValue?: string;
validation: string;
type: 'text' | 'password';
}[]
>;
name: string;
toolTip?: string;
oneTimeToken?: boolean;
isBetweenSteps: boolean;
scopes: string[];
externalUrl?: (
url: string
) => Promise<{ client_id: string; client_secret: string }>;
}