UNPKG

@5minds/processcube_engine

Version:

The ProcessCube Engine. Stores and executes BPMNs.

323 lines • 11.3 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; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ajv_1 = __importDefault(require("ajv")); const fs_1 = __importDefault(require("fs")); const nconf_1 = __importDefault(require("nconf")); const uuid = __importStar(require("uuid")); const processcube_engine_sdk_1 = require("@5minds/processcube_engine_sdk"); let initialized = false; const logger = new processcube_engine_sdk_1.Logger('engine:configuration'); const schema = { type: 'object', properties: { application: { type: 'object', properties: { name: { type: 'string' }, id: { type: 'string' }, touchFileOnReady: { type: ['null', 'string'] }, defaultResponseLimit: { type: 'number' }, }, additionalProperties: false, }, extensions: { type: 'object', properties: { include: { type: 'array', items: { type: ['string'], }, }, exclude: { type: 'array', items: { type: ['string'], }, }, }, additionalProperties: false, }, httpServer: { type: 'object', properties: { port: { type: ['number', 'string'] }, host: { type: 'string' }, allowedCorsOrigins: { type: 'array', items: { type: ['string'], }, }, // Used exclusively for docker defaultPort: { type: ['number', 'string'] }, }, required: ['port', 'host'], additionalProperties: false, }, httpClient: { type: 'object', properties: { allowUnauthorizedCertificates: { type: 'boolean' }, }, additionalProperties: false, }, iam: { type: 'object', properties: { baseUrl: { type: 'string' }, allowAnonymousRootAccess: { type: 'boolean' }, rootAccessToken: { type: 'string' }, }, required: ['baseUrl'], additionalProperties: false, }, tls: { type: 'object', properties: { useWindowsTrustStore: { type: 'boolean' }, }, additionalProperties: false, }, runtimeExpressions: { type: 'object', properties: { timeoutInMiliseconds: { type: 'integer', minimum: 100 }, workerPoolSize: { type: 'integer', minimum: 1 }, }, additionalProperties: false, }, database: { type: 'object', properties: { username: { type: ['null', 'string'] }, password: { type: ['null', 'string'] }, database: { type: ['null', 'string'] }, host: { type: ['null', 'string'] }, port: { type: ['null', 'number'] }, dialect: { type: ['null', 'string'] }, storage: { type: ['null', 'string'] }, supportBigNumbers: { type: 'boolean' }, resetPasswordRequestTimeToLive: { type: 'number' }, logging: { type: 'boolean' }, schema: { type: ['null', 'string'] }, compressProcessTokens: { type: 'boolean' }, pool: { type: 'object', properties: { max: { type: 'number' }, maxForExternalTasks: { type: 'number' }, maxForQueryRequests: { type: 'number' }, maxForProcessExecution: { type: 'number' }, }, additionalProperties: false, }, retry: { type: 'object', properties: { maxDuration: { type: ['string', 'number'] }, }, required: ['maxDuration'], additionalProperties: false, }, dialectOptions: { type: 'object', }, }, required: ['username', 'password', 'host', 'port', 'dialect'], additionalProperties: false, }, logging: { type: 'object', properties: { minLogLevel: { type: 'string', enum: ['', 'trace', 'debug', 'info', 'warn', 'error'] }, }, additionalProperties: false, }, extraInfo: { type: 'object', additionalProperties: true, }, }, required: ['httpServer', 'iam', 'database'], additionalProperties: true, }; function validateConfiguration() { const ajv = new ajv_1.default({ strict: false, allowUnionTypes: true, allErrors: true }); const userConfige = nconf_1.default.get(); const validate = ajv.compile(schema); const valid = validate(userConfige); if (!valid) { const formattedErrors = validate.errors.map((error) => { if (error.message === 'must NOT have additional properties') { return `Parameter \`${error.instancePath}\`: Unknown key \`${error.params.additionalProperty}\``; } return `Parameter \`${error.instancePath}\`: ${error.message}`; }); const containsCriticalErrors = validate.errors.some((error) => error.message != 'must NOT have additional properties'); if (containsCriticalErrors) { logger.error('The given engine configuration is invalid', formattedErrors); process.exit(1); } logger.warn('The engine configuration contains some unknown additional keys', formattedErrors); } } const Configuration = { initialize: (configPath, releaseChannel) => { if (!fs_1.default.existsSync(configPath)) { throw new processcube_engine_sdk_1.InternalServerError(`Failure in setup: The provided config path '${configPath}' does not exist.`, 'setup'); } nconf_1.default .argv() .env({ separator: '__', parseValues: true, transform: (setting) => { if (setting.key === 'extensions__include' || setting.key === 'extensions__exclude') { setting.value = setting.value?.split(','); } return setting; }, }) .file({ file: configPath }) .defaults({ application: { id: process.env.engineId ?? uuid.v4(), name: '5Minds Engine', defaultResponseLimit: 1000, touchFileOnReady: null, }, extensions: {}, httpServer: { host: '0.0.0.0', port: getDefaultPort(releaseChannel), allowedCorsOrigins: ['*'], }, httpClient: { allowUnauthorizedCertificates: false, }, tls: { useWindowsTrustStore: true, }, logging: { minLogLevel: 'debug', }, runtimeExpressions: { timeoutInMiliseconds: 6000, workerPoolSize: 4, }, database: { username: null, password: null, database: null, host: null, port: null, dialect: 'sqlite', storage: 'atlasengine.sqlite', supportBigNumbers: true, resetPasswordRequestTimeToLive: 12, logging: false, }, iam: { baseUrl: 'http://localhost:11560/', allowAnonymousRootAccess: true, }, extraInfo: {}, }); validateConfiguration(); initialized = true; }, get: (key) => { if (!initialized) { Configuration.initialize(process.env.CONFIG_PATH, process.env.NODE_ENV); } return nconf_1.default.get(key); }, application: () => { return Configuration.get('application'); }, extensions: () => { return Configuration.get('extensions'); }, httpServer: () => { return Configuration.get('httpServer'); }, httpClient: () => { return Configuration.get('httpClient'); }, tls: () => { return Configuration.get('tls'); }, logging: () => { return Configuration.get('logging'); }, runtimeExpressions: () => { return Configuration.get('runtimeExpressions'); }, database: () => { return Configuration.get('database'); }, iam: () => { return Configuration.get('iam'); }, custom: () => { return Configuration.get('extraInfo'); }, }; function getDefaultPort(releaseChannel) { const defaultPort = parseInt(process.env.httpServer__defaultPort); if (!Number.isNaN(defaultPort)) { return defaultPort; } switch (releaseChannel.toLowerCase()) { case 'dev': case 'develop': case 'development': return 10590; case 'alpha': return 10580; case 'beta': return 10570; case 'stable': default: return 10560; } } exports.default = Configuration; //# sourceMappingURL=Configurator.js.map