UNPKG

chromiumly

Version:

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

90 lines 3.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Gotenberg = void 0; const tslib_1 = require("tslib"); // Suppress warnings about missing environment variables (optional) process.env.SUPPRESS_NO_CONFIG_WARNING = 'y'; const path = tslib_1.__importStar(require("path")); // Load environment variables from .env file (optional) let dotenv; try { // eslint-disable-next-line @typescript-eslint/no-require-imports dotenv = require('dotenv'); } catch (_a) { // Ignore error if dotenv is not available } // Load endpoint from environment-specific file (e.g., .env.production) if dotenv is available if (dotenv) { const envFile = `.env.${process.env.NODE_ENV}`; const envFileFallback = '.env'; const dotenvConfig = dotenv.config({ path: path.resolve(envFile) }); // Fallback to loading the default environment file. if (dotenvConfig.error) { dotenv.config({ path: path.resolve(envFileFallback) }); } } let config; const loadConfig = () => { try { // eslint-disable-next-line @typescript-eslint/no-require-imports config = require('config'); } catch (error) { // Ignore error if the config module is not available or if a warning is present if (error instanceof Error && error.message.includes('WARNING')) { return; } } }; // Temporarily suppress warnings during configuration loading const _consoleError = console.error; // eslint-disable-next-line @typescript-eslint/no-explicit-any console.error = (message, ...optionalParams) => { if (typeof message === 'string' && message.includes('WARNING')) { return; } else { _consoleError.apply(console, [message, ...optionalParams]); } }; loadConfig(); // Restore console.error after suppressing warnings console.error = _consoleError; /** * Class representing configuration for interacting with Gotenberg service. */ class Gotenberg { /** * The endpoint for the Gotenberg service. * @type {string | undefined} */ static get endpoint() { const hasEndpoint = config === null || config === void 0 ? void 0 : config.has('gotenberg.endpoint'); return hasEndpoint ? config === null || config === void 0 ? void 0 : config.get('gotenberg.endpoint') : process.env.GOTENBERG_ENDPOINT; } /** * The username for basic authentication with the Gotenberg service. * @type {string | undefined} */ static get username() { const hasUsername = config === null || config === void 0 ? void 0 : config.has('gotenberg.api.basicAuth.username'); return hasUsername ? config === null || config === void 0 ? void 0 : config.get('gotenberg.api.basicAuth.username') : process.env.GOTENBERG_API_BASIC_AUTH_USERNAME; } /** * The password for basic authentication with the Gotenberg service. * @type {string | undefined} */ static get password() { const hasPassword = config === null || config === void 0 ? void 0 : config.has('gotenberg.api.basicAuth.password'); return hasPassword ? config === null || config === void 0 ? void 0 : config.get('gotenberg.api.basicAuth.password') : process.env.GOTENBERG_API_BASIC_AUTH_PASSWORD; } } exports.Gotenberg = Gotenberg; //# sourceMappingURL=gotenberg.js.map