import { MayBePromise } from "./types/utils.js"; import { UpdateMap } from "./types/gumroad.js"; import { API, APIOptions } from "./api.js"; //#region src/gumroad.d.ts /** An interface representing options for {@link Gumroad} constructor */ interface GumroadOptions extends APIOptions {} /** Represents context for handler */ type Context = { /** The data for current context */ data: UpdateMap[T]; /** The {@link API} */ api: API; /** Type of current update name */ type: T; /** Can be used to read and write custom variables in handlers */ vars: Record; }; /** A handler for update */ type Handler = ( /** Context for the current update */ ctx: Context, /** When invoked and awaited, it triggers the next corresponding handler */ next: () => Promise) => MayBePromise; /** An error handler */ type ErrorHandler = (err: Error, ctx: Context) => MayBePromise; declare class Gumroad extends API { /** Record of events for handling pings */ private _events; /** The error handler for the pings handlers */ private _errorHandler; /** * Registers an error handler for pings errors * Note that if an error handler was previously set using this method, it will overwrite that. * Only one handler can be registered * * @param handler An error handling function */ onError(handler: ErrorHandler): this; /** * Calls error handler * * @param err The `Error` object * @param context The {@link Context} */ private _handleError; /** * Registers an handler for ping * * @param update_name The name of update * @param handlers A function for handling the ping */ on(update_name: T, ...handlers: Handler[]): this; /** * Compose * * @param handlers The handlers * @param errorHandler The error handler * * @returns A function which can be used to dispatch events */ private _compose; /** * Dispatches an event * * @param update_name The name of update (event) * @param payload The payload for context */ private _dispatch; /** * Formats the payload data from gumroad ping * * @param payload The payload data * * @returns The same reference to the payload data but formatted */ private _formatPayload; /** * Handles a post request from gumroad ping * * @param request The `Request` object * @param update_name The name of update * * @returns On success, a `Response` object with 200 status code */ handle(request: Request, update_name: T): Promise; } //#endregion export { Context, ErrorHandler, Gumroad, GumroadOptions, Handler }; //# sourceMappingURL=gumroad.d.ts.map