chromiumly
Version:
A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.
37 lines (36 loc) • 2.05 kB
TypeScript
import { PathLikeOrReadStream } from './types';
/**
* Utility class for common tasks related to the Gotenberg service.
*/
export declare class GotenbergUtils {
/**
* 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 {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 {FormData} data - The FormData object to be sent in the POST request.
* @param {Record<string, string>} customHeaders - List of custom headers to include in the fetch
* @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>): 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>;
}