chromiumly
Version:
A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.
155 lines • 5.04 kB
JavaScript
;
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 || (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 {
/**
* 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;
/**
* The Gotenberg service endpoint.
* @type {string}
*/
Chromiumly.gotenbergEndpoint = gotenberg_1.Gotenberg.endpoint;
/**
* The username for basic authentication with the Gotenberg service.
* @type {string | undefined}
*/
Chromiumly.gotenbergApiBasicAuthUsername = gotenberg_1.Gotenberg.username;
/**
* The password for basic authentication with the Gotenberg service.
* @type {string | undefined}
*/
Chromiumly.gotenbergApiBasicAuthPassword = gotenberg_1.Gotenberg.password;
/**
* The path for Chromium-related conversions.
* @type {string}
*/
Chromiumly.CHROMIUM_CONVERT_PATH = 'forms/chromium/convert';
/**
* The path for Chromium-related screenshots.
* @type {string}
*/
Chromiumly.CHROMIUM_SCREENSHOT_PATH = 'forms/chromium/screenshot';
/**
* The path for PDF engine-related operations.
* @type {string}
*/
Chromiumly.PDF_ENGINES_PATH = 'forms/pdfengines';
/**
* The path for LibreOffice-related conversions.
* @type {string}
*/
Chromiumly.LIBRE_OFFICE_PATH = 'forms/libreoffice';
/**
* Routes for Chromium conversions.
* @type {Object}
*/
Chromiumly.CHROMIUM_ROUTES = {
url: ChromiumRoute.URL,
html: ChromiumRoute.HTML,
markdown: ChromiumRoute.MARKDOWN
};
/**
* Routes for PDF engine operations.
* @type {Object}
*/
Chromiumly.PDF_ENGINE_ROUTES = {
convert: PdfEngineRoute.CONVERT,
merge: PdfEngineRoute.MERGE,
readMetadata: PdfEngineRoute.READ_METADATA,
writeMetadata: PdfEngineRoute.WRITE_METADATA,
split: PdfEngineRoute.SPLIT,
flatten: PdfEngineRoute.FLATTEN
};
/**
* Routes for LibreOffice conversions.
* @type {Object}
*/
Chromiumly.LIBRE_OFFICE_ROUTES = {
convert: LibreOfficeRoute.CONVERT
};
//# sourceMappingURL=main.config.js.map