UNPKG

@mamoorali295/rbac

Version:

Complete RBAC (Role-Based Access Control) system for Node.js with Express middleware, NestJS integration, GraphQL support, MongoDB & PostgreSQL support, modern admin dashboard, TypeScript support, and dynamic permission management

78 lines (77 loc) 2.18 kB
import { DynamicModule } from '@nestjs/common'; import { RBACConfig } from '../types'; export interface RbacModuleOptions extends RBACConfig { global?: boolean; } /** * NestJS module for RBAC integration. * Provides guards, services, and configuration for role-based access control. * * @example * ```typescript * // Basic configuration * @Module({ * imports: [ * RbacModule.forRoot({ * database: { * type: 'mongodb', * connection: mongooseConnection * }, * authAdapter: async (req) => ({ user_id: req.user.id }), * defaultRole: 'user' * }) * ] * }) * export class AppModule {} * * // Global configuration (available in all modules) * @Module({ * imports: [ * RbacModule.forRoot({ * global: true, * database: { * type: 'postgresql', * connection: pgPool * }, * authAdapter: async (req) => ({ user_id: req.user.id }), * defaultRole: 'user' * }) * ] * }) * export class AppModule {} * * // Async configuration * @Module({ * imports: [ * RbacModule.forRootAsync({ * useFactory: async (configService: ConfigService) => ({ * database: { * type: 'mongodb', * connection: await createMongoConnection(configService.get('MONGO_URL')) * }, * authAdapter: async (req) => ({ user_id: req.user.id }), * defaultRole: configService.get('DEFAULT_ROLE', 'user') * }), * inject: [ConfigService] * }) * ] * }) * export class AppModule {} * ``` */ export declare class RbacModule { /** * Creates a dynamic module with RBAC configuration. * Initializes the RBAC system and provides guards and services. */ static forRoot(options: RbacModuleOptions): DynamicModule; /** * Creates a dynamic module with async RBAC configuration. * Useful when configuration depends on other services or external resources. */ static forRootAsync(options: { useFactory: (...args: any[]) => Promise<RbacModuleOptions> | RbacModuleOptions; inject?: any[]; global?: boolean; }): DynamicModule; }