UNPKG

chromiumly

Version:

A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.

164 lines 5.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Chromiumly = exports.ChromiumRoute = void 0; const gotenberg_1 = require("./gotenberg"); /** * Enum representing the available Chromium routes for conversion. * @enum {string} */ var ChromiumRoute; (function (ChromiumRoute) { ChromiumRoute["URL"] = "url"; ChromiumRoute["HTML"] = "html"; ChromiumRoute["MARKDOWN"] = "markdown"; })(ChromiumRoute || (exports.ChromiumRoute = ChromiumRoute = {})); /** * Enum representing the available routes for the PDF engine. * @enum {string} */ var PdfEngineRoute; (function (PdfEngineRoute) { PdfEngineRoute["CONVERT"] = "convert"; PdfEngineRoute["MERGE"] = "merge"; PdfEngineRoute["READ_METADATA"] = "metadata/read"; PdfEngineRoute["WRITE_METADATA"] = "metadata/write"; PdfEngineRoute["SPLIT"] = "split"; PdfEngineRoute["FLATTEN"] = "flatten"; PdfEngineRoute["ENCRYPT"] = "encrypt"; PdfEngineRoute["EMBED"] = "embed"; })(PdfEngineRoute || (PdfEngineRoute = {})); /** * Enum representing the available routes for LibreOffice. * @enum {string} */ var LibreOfficeRoute; (function (LibreOfficeRoute) { LibreOfficeRoute["CONVERT"] = "convert"; })(LibreOfficeRoute || (LibreOfficeRoute = {})); /** * Class providing constants and routes for interacting with the Gotenberg service and related engines. */ class Chromiumly { /** * The Gotenberg service endpoint. * @type {string} */ static gotenbergEndpoint = gotenberg_1.Gotenberg.endpoint; /** * The username for basic authentication with the Gotenberg service. * @type {string | undefined} */ static gotenbergApiBasicAuthUsername = gotenberg_1.Gotenberg.username; /** * The password for basic authentication with the Gotenberg service. * @type {string | undefined} */ static gotenbergApiBasicAuthPassword = gotenberg_1.Gotenberg.password; /** * Custom HTTP headers to be sent with each request. * @type {Record<string, string> | undefined} */ static customHttpHeaders; /** * The path for Chromium-related conversions. * @type {string} */ static CHROMIUM_CONVERT_PATH = 'forms/chromium/convert'; /** * The path for Chromium-related screenshots. * @type {string} */ static CHROMIUM_SCREENSHOT_PATH = 'forms/chromium/screenshot'; /** * The path for PDF engine-related operations. * @type {string} */ static PDF_ENGINES_PATH = 'forms/pdfengines'; /** * The path for LibreOffice-related conversions. * @type {string} */ static LIBRE_OFFICE_PATH = 'forms/libreoffice'; /** * Routes for Chromium conversions. * @type {Object} */ static CHROMIUM_ROUTES = { url: ChromiumRoute.URL, html: ChromiumRoute.HTML, markdown: ChromiumRoute.MARKDOWN }; /** * Routes for PDF engine operations. * @type {Object} */ static PDF_ENGINE_ROUTES = { convert: PdfEngineRoute.CONVERT, merge: PdfEngineRoute.MERGE, readMetadata: PdfEngineRoute.READ_METADATA, writeMetadata: PdfEngineRoute.WRITE_METADATA, split: PdfEngineRoute.SPLIT, flatten: PdfEngineRoute.FLATTEN, encrypt: PdfEngineRoute.ENCRYPT, embed: PdfEngineRoute.EMBED }; /** * Routes for LibreOffice conversions. * @type {Object} */ static LIBRE_OFFICE_ROUTES = { convert: LibreOfficeRoute.CONVERT }; /** * Configures the Gotenberg service endpoint and other optional parameters. * @param {Object} config - Configuration object. * @param {string} config.endpoint - The Gotenberg service endpoint. * @param {string} [config.username] - The username for basic authentication. * @param {string} [config.password] - The password for basic authentication. * @param {Record<string, string>} [config.customHttpHeaders] - Custom HTTP headers to be sent with each request. */ static configure(config) { this.gotenbergEndpoint = config.endpoint; if (config.username !== undefined) { this.gotenbergApiBasicAuthUsername = config.username; } if (config.password !== undefined) { this.gotenbergApiBasicAuthPassword = config.password; } if (config.customHttpHeaders !== undefined) { this.customHttpHeaders = config.customHttpHeaders; } } /** * Gets the Gotenberg service endpoint. * @returns {string} */ static getGotenbergEndpoint() { if (!this.gotenbergEndpoint) throw new Error('Gotenberg endpoint is not set. Please ensure that the Gotenberg service endpoint is configured correctly in your environment variables or through the configure method.'); return this.gotenbergEndpoint; } /** * Gets the username for basic authentication. * @returns {string | undefined} */ static getGotenbergApiBasicAuthUsername() { return this.gotenbergApiBasicAuthUsername; } /** * Gets the password for basic authentication. * @returns {string | undefined} */ static getGotenbergApiBasicAuthPassword() { return this.gotenbergApiBasicAuthPassword; } /** * Gets the custom HTTP headers. * @returns {Record<string, string> | undefined} */ static getCustomHttpHeaders() { return this.customHttpHeaders; } } exports.Chromiumly = Chromiumly; //# sourceMappingURL=main.config.js.map