UNPKG

chromiumly

Version:

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

122 lines 4.42 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Gotenberg = void 0; // Suppress warnings about missing environment variables (optional) process.env.SUPPRESS_NO_CONFIG_WARNING = 'y'; const path = __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 { // 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?.has('gotenberg.endpoint'); return hasEndpoint ? 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?.has('gotenberg.api.basicAuth.username'); return hasUsername ? 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?.has('gotenberg.api.basicAuth.password'); return hasPassword ? config?.get('gotenberg.api.basicAuth.password') : process.env.GOTENBERG_API_BASIC_AUTH_PASSWORD; } } exports.Gotenberg = Gotenberg; //# sourceMappingURL=gotenberg.js.map