This directory contains self-contained TypeScript snippets that showcase how to use the library in different scenarios. Each file can be executed with ts-node (or transpiled to JavaScript) and is fully documented in English.
configuredRBAC.tscreates a reusable RBAC factory configured with logging disabled.roles.tsdefines a role hierarchy with conditional permissions using thewhencallback for additional context checks.index.tsdemonstrates how to instantiate RBAC with the predefined roles and perform permission checks for multiple roles.basicUsage.tsshows a real-world check where user data is passed as context to evaluate permissions.
updateRoles.tsillustrates how to add new roles and merge updates without restarting your application.
mongodbAdapter.tsloads role definitions from MongoDB and performs checks against the retrieved data.mysqlAdapter.tsdoes the same using a MySQL database.postgresAdapter.tsdemonstrates the PostgreSQL adapter with custom column mappings.
multiTenant.tsstores and retrieves tenant-scoped roles using the MongoDB adapter andcreateTenantRBAChelper.
expressMiddleware.tsintegrates RBAC checks into Express routes.fastifyMiddleware.tsadds RBAC validation to Fastify handlers.nestMiddleware.tsshows how to plug RBAC into a NestJS module using middleware.
Each example is intentionally concise and focuses on a single scenario so you can copy the file that best matches your use case and adapt it to your project.