@humanwhocodes/crosspost
Version:
A utility to post across multiple social networks.
226 lines (225 loc) • 5.55 kB
TypeScript
/**
* A strategy for posting messages to LinkedIn.
*/
export class LinkedInStrategy {
/**
* Creates a new instance.
* @param {LinkedInOptions} options Options for the instance.
* @throws {Error} When required options are missing.
*/
constructor(options: LinkedInOptions);
/**
* The ID of the strategy.
* @type {string}
* @readonly
*/
readonly id: string;
/**
* The display name of the strategy.
* @type {string}
* @readonly
*/
readonly name: string;
/**
* Maximum length of a LinkedIn post in characters.
* @type {number}
* @const
*/
MAX_MESSAGE_LENGTH: number;
/**
* Posts a message to LinkedIn.
* @param {string} message The message to post.
* @param {import("../types.js").PostOptions} [postOptions] Additional options for the post.
* @returns {Promise<LinkedInPostResponse>} A promise that resolves with the post data.
* @throws {TypeError} If message is missing.
*/
post(message: string, postOptions?: import("../types.js").PostOptions): Promise<LinkedInPostResponse>;
/**
* Extracts a URL from a LinkedIn API response.
* @param {LinkedInPostResponse} response The response from the LinkedIn API post request.
* @returns {string} The URL for the LinkedIn post.
*/
getUrlFromResponse(response: LinkedInPostResponse): string;
/**
* Calculates the length of a message according to LinkedIn's algorithm.
* All Unicode characters are counted as is.
* @param {string} message The message to calculate the length of.
* @returns {number} The calculated length of the message.
*/
calculateMessageLength(message: string): number;
#private;
}
export type LinkedInOptions = {
/**
* The access token for the LinkedIn API.
*/
accessToken: string;
};
export type LinkedInPostResponse = {
/**
* The URN of the newly created post.
*/
id: string;
};
export type LinkedInUserInfoResponse = {
/**
* The name of the user.
*/
name: string;
/**
* The subject identifier for the user.
*/
sub: string;
/**
* The locale information of the user.
*/
locale: {
country: string;
language: string;
};
/**
* The given name of the user.
*/
given_name: string;
/**
* The family name of the user.
*/
family_name: string;
/**
* The URL of the user's profile picture.
*/
picture: string;
};
export type LinkedInMedia = {
/**
* - The URN of the media asset
*/
media: string;
/**
* - The status of the media (e.g., "READY")
*/
status: string;
/**
* - The title of the media
*/
title: {
attributes?: Object[] | undefined;
text: string;
};
};
export type LinkedInShareContent = {
/**
* - Array of media attachments
*/
media?: LinkedInMedia[] | undefined;
/**
* - The main text content of the post
*/
shareCommentary: {
attributes?: Object[] | undefined;
text: string;
};
/**
* - The type of media being shared (e.g., "VIDEO", "IMAGE", "NONE")
*/
shareMediaCategory: string;
};
export type LinkedInPostBody = {
/**
* - The URN identifier of the post author (person or organization)
*/
author: string;
/**
* - The state of the post (e.g., "PUBLISHED")
*/
lifecycleState: string;
/**
* - The content-specific details of the post
*/
specificContent: Record<"com.linkedin.ugc.ShareContent", LinkedInShareContent>;
/**
* - Visibility settings for the post
*/
visibility: Record<string, string>;
};
export type LinkedInErrorResponse = {
/**
* The type of error detail.
*/
errorDetailType: string;
/**
* The error message.
*/
message: string;
/**
* The details of the error.
*/
errorDetails: {
inputErrors: Array<Object>;
};
/**
* The description of the input error.
*/
description: string;
/**
* The input object.
*/
input: Object;
/**
* The error code.
*/
code: string;
/**
* The HTTP status code.
*/
status: number;
};
export type LinkedInServiceRelationship = {
/**
* The service identifier URN
*/
identifier: string;
/**
* The type of relationship (e.g. "OWNER")
*/
relationshipType: string;
};
export type LinkedInRequestUploadRequestBody = {
/**
* The URN identifier of the owner (organization or person)
*/
owner: string;
/**
* Array of recipe URNs for the upload (e.g. "urn:li:digitalmediaRecipe:feedshare-image")
*/
recipes: string[];
/**
* Array of service relationship objects
*/
serviceRelationships: LinkedInServiceRelationship[];
/**
* Array of supported upload mechanisms (e.g. "SYNCHRONOUS_UPLOAD")
*/
supportedUploadMechanism: string[];
};
export type LinkedInUploadMechanism = {
/**
* The URL to upload the media to.
*/
uploadUrl: string;
/**
* The headers for the upload request.
*/
headers: Record<string, string>;
};
export type LinkedInRequestUploadResponse = {
/**
* The response value object
*/
value: {
mediaArtifact: string;
uploadMechanism: Record<string, LinkedInUploadMechanism>;
asset: string;
assetRealTimeTopic: string;
};
};