Gate Warden is a lightweight access control library that supports ACL, RBAC, and ABAC models. It is designed to manage and enforce permissions for users and entities in a flexible and extensible way.
Install the library using npm or yarn:
npm i @wxn0brp/gate-warden
See Docs
The GateWarden class is the main entry point for checking access permissions.
import { GateWarden } from "@wxn0brp/gate-warden";
import { Valthera } from "@wxn0brp/db";
const wardenString = new GateWarden("dir");
// or
const wardenDB = new GateWarden(new Valthera("dir"));
const hasAccess = await warden.hasAccess("userId", "entityId", 0b001);
console.log(`Access granted: ${hasAccess}`);
The UserManager class provides methods to manage users.
import { UserManager } from "@wxn0brp/gate-warden";
const userManager = new UserManager(db);
// Create a new user
await userManager.createUser({ _id: "userId", roles: ["roleId"] });
// Update user attributes
await userManager.updateAttributes("userId", { key: "value" });
The WardenManager class provides methods to manage roles and rules.
import { WardenManager } from "@wxn0brp/gate-warden";
const wardenManager = new WardenManager(db);
// Add a new role
await wardenManager.addRole({ _id: "roleId", name: "Admin" });
// Add an ACL rule
await wardenManager.addACLRule("entityId", 0b001, "userId");
// Add an ABAC rule
await wardenManager.addABACRule("entityId", 0b001, { attrib: { isAdmin: true } });
Set the debugLog level in GateWarden to enable debug messages:
0: No logs1: Basic logs2: Detailed logsThis project is licensed under the MIT License. See the LICENSE file for details.