UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

174 lines (173 loc) 4.02 kB
/** * A strategy for posting messages to Bluesky. */ export class BlueskyStrategy { /** * Creates a new instance. * @param {BlueskyOptions} options Options for the instance. * @throws {Error} When options are missing. */ constructor(options: BlueskyOptions); /** * Maximum length of a Bluesky post in characters. * @type {number} * @const */ MAX_MESSAGE_LENGTH: number; /** * The ID of the strategy. * @type {string} * @readonly */ readonly id: string; /** * The display name of the strategy. * @type {string} * @readonly */ readonly name: string; /** * Calculates the length of a message according to Bluesky's algorithm. * All URLs are counted as 27 characters, all other Unicode characters as is. * @param {string} message The message to calculate the length of. * @returns {number} The calculated length of the message. */ calculateMessageLength(message: string): number; /** * Posts a message to Bluesky. * @param {string} message The message to post. * @param {PostOptions} [postOptions] Additional options for the post. * @returns {Promise<BlueskyCreateRecordResponse>} A promise that resolves with the post data. */ post(message: string, postOptions?: PostOptions): Promise<BlueskyCreateRecordResponse>; /** * Extracts a URL from a Bluesky API response. * @param {BlueskyCreateRecordResponse} response The response from the Bluesky post request. * @returns {string} The URL for the Bluesky post. */ getUrlFromResponse(response: BlueskyCreateRecordResponse): string; #private; } export type PostOptions = import("../types.js").PostOptions; export type BlueskyOptions = { /** * The username to post with. */ identifier: string; /** * The application password to use. */ password: string; /** * The host domain for the Bluesky instance. */ host: string; }; export type BlueskySession = { /** * The access JWT for the session. */ accessJwt: string; /** * The refresh JWT for the session. */ refreshJwt: string; /** * Indicates if the session is active. */ active: boolean; /** * The DID of the session. */ did: string; }; export type BlueskyImage = { /** * The alt text for the image. */ alt: string; /** * The image data. */ image: { $type: string; ref: { $link: string; }; mimeType: string; size: number; }; }; export type BlueskyPostBody = { /** * The DID of the user. */ repo: string; /** * The collection type (always "app.bsky.feed.post"). */ collection: string; /** * The post record. */ record: { $type: string; text: string; facets: Array<Object>; createdAt: string; embed?: { /** * The type of embedded content. */ $type: string; /** * The images to embed. */ images?: Object[] | undefined; } | undefined; }; }; export type BlueskyCreateRecordResponse = { /** * The CID of the post. */ cid: string; /** * The commit information. */ commit: { cid: string; rev: string; }; /** * The URI of the post. */ uri: string; /** * The validation status of the post. */ validationStatus: string; }; export type BlueskyErrorResponse = { /** * The type of error. */ error: string; /** * The error message. */ message: string; }; export type BlueskyUploadBlobResponse = { /** * The blob data */ blob: { $type: "blob"; ref: { $link: string; }; mimeType: string; size: number; }; };