UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

112 lines (111 loc) 3.64 kB
/** * @fileoverview The client API. * @author Nicholas C. Zakas */ /** @typedef {import("./types.js").Strategy} Strategy */ /** @typedef {import("./types.js").PostOptions} PostOptions */ /** @typedef {import("./types.js").PostToOptions} PostToOptions */ /** @typedef {import("./types.js").PostToEntry} PostToEntry */ /** * @typedef {Object} ClientOptions * @property {Array<Strategy>} strategies An array of strategies to use. */ /** * Represents a successful response. */ export class SuccessResponse { /** * Creates a new instance. * @param {string} name The name of the strategy that produced this response. * @param {Object} response The response. * @param {string} [url] The URL of the posted message, if applicable. */ constructor(name: string, response: Object, url?: string); /** * Indicates success. * @type {boolean} * @const */ ok: boolean; /** * The name of the strategy that produced this response. * @type {string} */ name: string; /** * The message posted. * @type {Object} */ response: Object; /** * The URL of the posted message, if applicable. * @type {string|undefined} */ url: string | undefined; } /** * Represents a failure response. */ export class FailureResponse { /** * Creates a new instance. * @param {string} name The name of the strategy that produced this response. * @param {Object} reason The reason for failure. */ constructor(name: string, reason: Object); /** * Indicates failure. * @type {boolean} * @const */ ok: boolean; /** * The name of the strategy that produced this response. * @type {string} */ name: string; /** * The error or response. * @type {Object} */ reason: Object; } /** * Represents a client that can post messages using different strategies. */ export class Client { /** * Creates a new instance. * @param {ClientOptions} options Options for the instance. * @throws {TypeError} When options are missing or invalid. */ constructor(options: ClientOptions); /** * Posts a message using all strategies. * @param {string} message The message to post. * @param {PostOptions} [postOptions] Additional options for the post. * @returns {Promise<Array<SuccessResponse|FailureResponse>>} A promise that resolves with an array of results. */ post(message: string, postOptions?: PostOptions): Promise<Array<SuccessResponse | FailureResponse>>; /** * Posts messages using specific strategies. * @param {Array<PostToEntry>} entries An array of messages and their target strategies. * @param {PostToOptions} [postOptions] Additional options for the post. * @returns {Promise<Array<SuccessResponse|FailureResponse>>} A promise that resolves with an array of results. * @throws {TypeError} When `entries` is not an array. * @throws {TypeError} When `entries` is an empty array. * @throws {Error} When a strategy ID doesn't match any registered strategy. */ postTo(entries: Array<PostToEntry>, postOptions?: PostToOptions): Promise<Array<SuccessResponse | FailureResponse>>; #private; } export type Strategy = import("./types.js").Strategy; export type PostOptions = import("./types.js").PostOptions; export type PostToOptions = import("./types.js").PostToOptions; export type PostToEntry = import("./types.js").PostToEntry; export type ClientOptions = { /** * An array of strategies to use. */ strategies: Array<Strategy>; };