UNPKG

@perfood/couch-auth

Version:

Easy and secure authentication for CouchDB/Cloudant. Based on SuperLogin, updated and rewritten in Typescript.

47 lines (46 loc) 1.72 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigHelper = void 0; const util_1 = require("../util"); const default_config_1 = require("./default.config"); class ConfigHelper { constructor(data = {}) { this.config = default_config_1.defaultConfig; // Some extra default settings if no config object is specified if (Object.keys(data).length === 0) { this.config.testMode = { noEmail: true, debugEmail: true }; } else { this.config = (0, util_1.mergeConfig)(this.config, data); this.verifyConfig(); } } /** Verifies the config against some incompatible settings */ verifyConfig() { if (this.config.local?.requireEmailConfirm && !this.config.local.sendConfirmEmail) { throw 'sendConfirmEmail must also be set if requireEmailConfirm is.'; } if (this.config.local?.keepEmailConfirmToken && !this.config.local.sendConfirmEmail) { throw 'sendConfirmEmail must also be set if keepEmailConfirmToken is.'; } if (this.config.security?.iterations) { const itArr = this.config.security.iterations; let prev = 0; for (const pair of itArr) { if (pair.length !== 2 || typeof pair[0] !== 'number' || typeof pair[1] !== 'number' || pair[0] < prev) { throw 'iterations are specified but have invalid format!'; } prev = pair[0]; } } } } exports.ConfigHelper = ConfigHelper;