UNPKG

zents

Version:

ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.

86 lines 4.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateConfig = void 0; function validateSecurityConfig(config) { var _a, _b, _c, _d, _e; const errors = []; if (typeof ((_a = config.security) === null || _a === void 0 ? void 0 : _a.secretKey) !== 'string') { errors.push('Property "secretKey" is missing in "config.security". Please create a strong secret key with at least 32 characters'); } else if (config.security.secretKey.length < 32) { errors.push('Property "secretKey" in "config.security" must be at least 32 characters long.'); } if (!Array.isArray((_b = config.security) === null || _b === void 0 ? void 0 : _b.providers) || !config.security.providers.length) { errors.push('Security provider config is missing in "config.security". Please add at least one security provider...'); } else { const providersLen = config.security.providers.length; for (const providerConfig of config.security.providers) { if (providersLen > 1) { if (typeof providerConfig.name !== 'string') { errors.push('A provider needs a name property when using multiple providers.'); } if (typeof ((_c = providerConfig.url) === null || _c === void 0 ? void 0 : _c.login) !== 'string') { errors.push('A provider needs a url.login property when using multiple providers.'); } if (typeof ((_d = providerConfig.url) === null || _d === void 0 ? void 0 : _d.logout) !== 'string') { errors.push('A provider needs a url.logout property when using multiple providers.'); } } if (typeof providerConfig.entity !== 'string') { errors.push('Missing entity property in security provider config.'); } if (providerConfig.store) { if (providerConfig.store.type === 'database') { if (typeof providerConfig.store.entity !== 'string') { errors.push('Missing entity property in security provider store.'); } if (!((_e = config.database) === null || _e === void 0 ? void 0 : _e.enable)) { errors.push('Security provider needs database access. Please enable database support.'); } } else if (providerConfig.store.type === 'file' && typeof providerConfig.store.folder !== 'string') { errors.push('Missing folder property in security provider store. Please provide a absolute path'); } else if (providerConfig.store.type === 'redis' && !config.redis.enable) { errors.push('Security provider needs database access. Please enable database support.'); } } } } return !errors.length ? true : errors; } function validateHTTPSConfig(config) { var _a, _b, _c, _d, _e, _f, _g, _h; const errors = []; const usePem = typeof ((_b = (_a = config.web) === null || _a === void 0 ? void 0 : _a.https) === null || _b === void 0 ? void 0 : _b.key) !== 'undefined' && typeof ((_d = (_c = config.web) === null || _c === void 0 ? void 0 : _c.https) === null || _d === void 0 ? void 0 : _d.cert) !== 'undefined'; const usePfx = typeof ((_f = (_e = config.web) === null || _e === void 0 ? void 0 : _e.https) === null || _f === void 0 ? void 0 : _f.pfx) !== 'undefined' && typeof ((_h = (_g = config.web) === null || _g === void 0 ? void 0 : _g.https) === null || _h === void 0 ? void 0 : _h.passphrase) !== 'undefined'; if (!usePem && !usePfx) { errors.push('Either https.key and https.cert or https.pfx and https.passphrase has to be defined in config when using https server'); } return !errors.length ? true : errors; } function validateConfig(config) { var _a, _b, _c; let errors = []; if ((_a = config.security) === null || _a === void 0 ? void 0 : _a.enable) { const result = validateSecurityConfig(config); if (Array.isArray(result)) { errors = [...errors, ...result]; } } if ((_c = (_b = config.web) === null || _b === void 0 ? void 0 : _b.https) === null || _c === void 0 ? void 0 : _c.enable) { const result = validateHTTPSConfig(config); if (Array.isArray(result)) { errors = [...errors, ...result]; } } return { isValid: !errors.length, errors, }; } exports.validateConfig = validateConfig; //# sourceMappingURL=validateConfig.js.map