UNPKG

@villedemontreal/jwt-validator

Version:
135 lines 3.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.configs = exports.Configs = void 0; const os = require("os"); const path = require("path"); const constants_1 = require("./constants"); /** * Lib configs */ class Configs { constructor() { /** * The endpoint to query the public keys */ this._endpoint = constants_1.constants.default.endpoint; /** * The parameters to query the public keys */ this._fetchKeysParameters = constants_1.constants.default.fetchKeysParameters; /** * Cache duration */ this._cacheDuration = constants_1.constants.default.cacheDuration; this.libRoot = path.normalize(path.join(__dirname, '../../..')); this.isWindows = os.platform() === 'win32'; // eslint-disable-next-line @typescript-eslint/no-require-imports const sourcePackageJson = require(path.join(constants_1.constants.appRoot, 'package.json')); this._sourceProjectName = sourcePackageJson?.name ? sourcePackageJson.name : ''; } /** * Get the host to query the public keys * @return {string} host */ getHost() { if (!this._host) { throw new Error(`The "host" must be set!`); } return this._host; } /** * Get the endpoint to query the public keys * @return {string} endpoint */ getEndpoint() { return this._endpoint; } /** * Get the parameters to query the public keys * @return {string} fetchKeysParameters */ getFetchKeysParameters() { return this._fetchKeysParameters; } /** * Get the cache duration in seconds * @return {number} cacheDuration */ getCacheDuration() { return this._cacheDuration; } /** * Set the host to query the public keys * @param {string} host * @return */ setHost(host) { this._host = host; } /** * Set the endpoint to query the public keys * @param {string} endpoint * @return */ setEndpoint(endpoint) { this._endpoint = endpoint; } /** * Set the paramters to query the public keys * @param {string} fetchKeysParameters * @return */ setFetchKeysParameters(fetchKeysParameters) { this._fetchKeysParameters = fetchKeysParameters; } /** * Get the cache duration in seconds * @param {number} cacheDuration * @return */ setCacheDuration(cacheDuration) { this._cacheDuration = cacheDuration; } /** * The Logger creator */ get loggerCreator() { if (!this._loggerCreator) { throw new Error(`The Logger Creator HAS to be set as a configuration`); } return this._loggerCreator; } /** * Sets the Logger creator. */ setLoggerCreator(loggerCreator) { this._loggerCreator = loggerCreator; } /** * Sets the Correlation Id provider. */ setCorrelationIdProvider(correlationIdProvider) { this._correlationIdProvider = correlationIdProvider; } /** * Get the source project name where this library is imported * * @return {*} {string} * @memberof Configs */ getSourceProjectName() { return this._sourceProjectName; } /** * The Correlation Id provider */ get correlationIdProvider() { if (!this._correlationIdProvider) { throw new Error(`The Correlation Id provider HAS to be set as a configuration! Please call the init(...) fonction first.`); } return this._correlationIdProvider; } } exports.Configs = Configs; exports.configs = new Configs(); //# sourceMappingURL=configs.js.map