chromiumly
Version:
A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.
41 lines (40 loc) • 2.59 kB
TypeScript
import { DownloadFrom, DownloadFromEntry, PathLikeOrReadStream, WebhookOptions } from './types';
/**
* Utility class for common tasks related to the Gotenberg service.
*/
export declare class GotenbergUtils {
static normalizeDownloadFrom(downloadFrom: DownloadFrom): DownloadFromEntry[];
static buildWebhookHeaders(options?: WebhookOptions): Record<string, string> | undefined;
private static buildRequestHeaders;
/**
* Asserts that a condition is true; otherwise, throws an error with the specified message.
*
* @param {boolean} condition - The condition to assert.
* @param {string} message - The error message to throw if the condition is false.
* @throws {Error} Throws an error with the specified message if the condition is false.
*/
static assert(condition: boolean, message: string): asserts condition;
/**
* Performs a POST request to the specified Gotenberg endpoint with the provided FormData.
*
* @param {string} endpoint - The Gotenberg endpoint URL.
* @param {FormData} data - The FormData object to be sent in the POST request.
* @param {string} [username] - The username for basic authentication.
* @param {string} [password] - The password for basic authentication.
* @param {Record<string, string>} [customHttpHeaders] - Custom HTTP headers to be sent with the request.
* @param {string} [apiKey] - The API key for X-Api-Key authentication. When set, takes precedence over basic auth.
* @returns {Promise<Buffer>} A Promise that resolves to the response body as a buffer.
* @throws {Error} Throws an error if the HTTP response status is not OK.
*/
static fetch(endpoint: string, data: FormData, username?: string, password?: string, customHttpHeaders?: Record<string, string>, apiKey?: string, requestHttpHeaders?: Record<string, string>): Promise<Buffer>;
static fetchWithoutBody(endpoint: string, method: 'GET' | 'HEAD', username?: string, password?: string, customHttpHeaders?: Record<string, string>, apiKey?: string): Promise<Buffer>;
/**
* Adds a file to the FormData object.
*
* @param {FormData} data - The FormData object to which the file will be added.
* @param {PathLikeOrReadStream} file - The file to be added (either a PathLike or a ReadStream).
* @param {string} name - The name to be used for the file in the FormData.
* @returns {Promise<void>} A Promise that resolves once the file has been added.
*/
static addFile(data: FormData, file: PathLikeOrReadStream, name: string): Promise<void>;
}