@wizeline/access-decision-manager
Version:
An implementation of the Voter pattern for determining access rights
38 lines • 1.8 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const affirmative_1 = __importDefault(require("./strategy/affirmative"));
class AccessDecisionManager {
constructor(user, voters, context, options = { strategy: affirmative_1.default }) {
this.context = context;
this.user = user;
this.voters = voters;
this.options = options;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
isGranted(attribute, subject) {
return __awaiter(this, void 0, void 0, function* () {
const relevantVoters = this.voters.filter((voter) => {
try {
return voter.supports(attribute, subject, this.context);
}
catch (error) {
return false;
}
});
return this.options.strategy(relevantVoters, attribute, subject, this.user, this.context);
});
}
}
exports.default = AccessDecisionManager;
//# sourceMappingURL=access-decision-manager.js.map