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.
124 lines • 5.37 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SecurityProviderOptions = void 0;
const secure_password_1 = __importDefault(require("secure-password"));
const FS_1 = require("../filesystem/FS");
const path_1 = require("path");
const ms_1 = __importDefault(require("ms"));
class SecurityProviderOptions {
constructor(options, entities) {
this.options = options;
this.entities = entities;
}
get name() {
var _a;
return (_a = this.options.name) !== null && _a !== void 0 ? _a : 'default';
}
get algorithm() {
var _a;
return (_a = this.options.algorithm) !== null && _a !== void 0 ? _a : 'argon2id';
}
get userEntity() {
return this.entities.user;
}
get expireInMS() {
const value = this.options.expire;
if (typeof value === 'undefined') {
return -1;
}
else if (typeof value === 'number') {
return value;
}
return ms_1.default(value);
}
get loginUrl() {
var _a, _b;
return (_b = (_a = this.options.url) === null || _a === void 0 ? void 0 : _a.login) !== null && _b !== void 0 ? _b : '/login';
}
get logoutUrl() {
var _a, _b;
return (_b = (_a = this.options.url) === null || _a === void 0 ? void 0 : _a.logout) !== null && _b !== void 0 ? _b : '/logout';
}
get loginRedirectUrl() {
var _a, _b;
return (_b = (_a = this.options.redirect) === null || _a === void 0 ? void 0 : _a.login) !== null && _b !== void 0 ? _b : '/';
}
get logoutRedirectUrl() {
var _a, _b;
return (_b = (_a = this.options.redirect) === null || _a === void 0 ? void 0 : _a.logout) !== null && _b !== void 0 ? _b : '/';
}
get failedRedirectUrl() {
var _a, _b;
return (_b = (_a = this.options.redirect) === null || _a === void 0 ? void 0 : _a.failed) !== null && _b !== void 0 ? _b : '/';
}
get forbiddenRedirectUrl() {
var _a, _b;
return (_b = (_a = this.options.redirect) === null || _a === void 0 ? void 0 : _a.forbidden) !== null && _b !== void 0 ? _b : '/';
}
get memLimit() {
var _a, _b;
return (_b = (_a = this.options.argon) === null || _a === void 0 ? void 0 : _a.memLimit) !== null && _b !== void 0 ? _b : secure_password_1.default.MEMLIMIT_DEFAULT;
}
get opsLimit() {
var _a, _b;
return (_b = (_a = this.options.argon) === null || _a === void 0 ? void 0 : _a.opsLimit) !== null && _b !== void 0 ? _b : secure_password_1.default.OPSLIMIT_DEFAULT;
}
get saltRounds() {
var _a, _b;
return (_b = (_a = this.options.bcrypt) === null || _a === void 0 ? void 0 : _a.saltRounds) !== null && _b !== void 0 ? _b : 12;
}
get identifierColumn() {
var _a, _b;
return (_b = (_a = this.options.table) === null || _a === void 0 ? void 0 : _a.identifierColumn) !== null && _b !== void 0 ? _b : 'id';
}
get passwordColumn() {
var _a, _b;
return (_b = (_a = this.options.table) === null || _a === void 0 ? void 0 : _a.passwordColumn) !== null && _b !== void 0 ? _b : 'password';
}
get usernameField() {
var _a, _b;
return (_b = (_a = this.options.fields) === null || _a === void 0 ? void 0 : _a.username) !== null && _b !== void 0 ? _b : 'username';
}
get passwordField() {
var _a, _b;
return (_b = (_a = this.options.fields) === null || _a === void 0 ? void 0 : _a.password) !== null && _b !== void 0 ? _b : 'password';
}
get storeType() {
var _a;
return (_a = this.options.store) === null || _a === void 0 ? void 0 : _a.type;
}
get responseType() {
var _a;
return (_a = this.options.responseType) !== null && _a !== void 0 ? _a : 'redirect';
}
get storePrefix() {
var _a, _b, _c;
const defaultPrefix = 'zen_';
return ((_a = this.options.store) === null || _a === void 0 ? void 0 : _a.type) === 'redis'
? (_c = (_b = this.options.store) === null || _b === void 0 ? void 0 : _b.prefix) !== null && _c !== void 0 ? _c : defaultPrefix
: defaultPrefix;
}
get redisKeepTTL() {
var _a, _b, _c;
const defaultValue = false;
return ((_a = this.options.store) === null || _a === void 0 ? void 0 : _a.type) === 'redis'
? (_c = (_b = this.options.store) === null || _b === void 0 ? void 0 : _b.keepTTL) !== null && _c !== void 0 ? _c : defaultValue
: defaultValue;
}
get dbStoreEntity() {
var _a;
return (_a = this.entities.dbStore) !== null && _a !== void 0 ? _a : null;
}
get fileStoreFolder() {
var _a, _b, _c;
const defaultValue = path_1.join(FS_1.fs.appDir(), 'session');
return ((_a = this.options.store) === null || _a === void 0 ? void 0 : _a.type) === 'file'
? (_c = (_b = this.options.store) === null || _b === void 0 ? void 0 : _b.folder) !== null && _c !== void 0 ? _c : defaultValue
: defaultValue;
}
}
exports.SecurityProviderOptions = SecurityProviderOptions;
//# sourceMappingURL=SecurityProviderOptions.js.map