@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
90 lines (89 loc) • 3.69 kB
JavaScript
;
/**
* @fileoverview Role-Based Access Control (RBAC) system for Node.js applications.
*
* This package provides a complete RBAC solution with:
* - Express middleware for authentication and authorization
* - NestJS decorators, guards, and modules for framework integration
* - GraphQL directives and resolvers for GraphQL APIs
* - Automatic permission inference from routes
* - Admin dashboard for user and role management
* - Multi-database support (MongoDB & PostgreSQL)
* - TypeScript support with full type definitions
*
* @author Muhammad Mamoor Ali - sheikh295
* @version 2.0.0
* @license MIT
*
* @example
* ```typescript
* // Express usage
* import { RBAC } from '@mamoorali295/rbac';
*
* RBAC.init({
* database: { type: 'mongodb', connection: mongoose.connection },
* authAdapter: async (req) => ({ user_id: req.user.id }),
* defaultRole: 'user'
* });
*
* app.get('/api/billing', RBAC.checkPermissions(), handler);
*
* // NestJS usage
* import { RbacModule, CheckPermissions, PermissionsGuard } from '@mamoorali295/rbac/nestjs';
*
* @Module({
* imports: [RbacModule.forRoot({ database: { type: 'mongodb', connection: mongooseConnection } })]
* })
* export class AppModule {}
*
* @Controller('billing')
* @UseGuards(PermissionsGuard)
* export class BillingController {
* @Get('invoices')
* @CheckPermissions()
* getInvoices() { ... }
* }
*
* // GraphQL usage
* import { AuthDirective, rbacResolvers } from '@mamoorali295/rbac/graphql';
*
* const server = new ApolloServer({
* typeDefs,
* resolvers: rbacResolvers,
* schemaDirectives: { auth: AuthDirective }
* });
* ```
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.featureController = exports.userRoleController = exports.RBAC = void 0;
/** Main RBAC system instance */
var RBAC_1 = require("./RBAC");
Object.defineProperty(exports, "RBAC", { enumerable: true, get: function () { return RBAC_1.RBAC; } });
/** TypeScript type definitions */
__exportStar(require("./types"), exports);
/** Database controllers for safe advanced operations */
var userrole_controller_1 = require("./mongo/controllers/userrole.controller");
Object.defineProperty(exports, "userRoleController", { enumerable: true, get: function () { return userrole_controller_1.userRoleController; } });
var feature_controller_1 = require("./mongo/controllers/feature.controller");
Object.defineProperty(exports, "featureController", { enumerable: true, get: function () { return feature_controller_1.featureController; } });
/** NestJS integration - Import from '@mamoorali295/rbac/nestjs' */
// Note: NestJS integration is available via separate import: require('@mamoorali295/rbac/nestjs')
/** GraphQL integration - Import from '@mamoorali295/rbac/graphql' */
// Note: GraphQL integration is available via separate import: require('@mamoorali295/rbac/graphql')
/** Default export - RBAC system instance */
const RBAC_2 = require("./RBAC");
exports.default = RBAC_2.RBAC;