NestboltNestbolt

@nestbolt/permissions

Installation

Install @nestbolt/permissions and its peer dependencies in your NestJS project.

Install the Package

Install @nestbolt/permissions using your preferred package manager:

npm install @nestbolt/permissions
yarn add @nestbolt/permissions
pnpm add @nestbolt/permissions

Peer Dependencies

The package requires several peer dependencies that are standard in NestJS projects. If you already have a NestJS application with TypeORM configured, you likely have all of them installed.

PackageRequired Version
@nestjs/common^10.0.0 || ^11.0.0
@nestjs/core^10.0.0 || ^11.0.0
@nestjs/typeorm^10.0.0 || ^11.0.0
typeorm^0.3.0
class-validator^0.14.0
class-transformer^0.5.0
reflect-metadata^0.1.13 || ^0.2.0

If any are missing, install them:

npm install @nestjs/common @nestjs/core @nestjs/typeorm typeorm class-validator class-transformer reflect-metadata

Optional Dependencies

Event Emitter

If you want the package to emit lifecycle events (role created, permission attached, cache flushed, etc.), install the NestJS event emitter module:

npm install @nestjs/event-emitter
PackageRequired Version
@nestjs/event-emitter^2.0.0 || ^3.0.0

Then register EventEmitterModule in your AppModule:

import { Module } from "@nestjs/common";
import { EventEmitterModule } from "@nestjs/event-emitter";
import { PermissionsModule } from "@nestbolt/permissions";

@Module({
  imports: [
    EventEmitterModule.forRoot(),
    PermissionsModule.forRoot({
      userRepository: TypeOrmPermissionUserRepository,
    }),
  ],
})
export class AppModule {}

When @nestjs/event-emitter is not installed, the package functions normally but does not emit any events. No configuration change is needed -- event support is detected automatically.

TypeORM Configuration

The package ships with its own TypeORM entities and will register them via TypeOrmModule.forFeature() automatically when you call PermissionsModule.forRoot(). You do not need to manually register the entities.

Make sure your TypeORM connection is configured to synchronize or run migrations for the new tables. If you use synchronize: true in development, the tables will be created automatically:

TypeOrmModule.forRoot({
  type: "postgres",
  host: "localhost",
  port: 5432,
  username: "app",
  password: "secret",
  database: "mydb",
  autoLoadEntities: true,
  synchronize: true, // Only use in development
});

For production, generate and run a migration after installing the package. The package creates the following tables:

  • permissions
  • roles
  • role_has_permissions
  • user_has_roles
  • user_has_permissions

Compatibility

The package is compatible with:

  • NestJS v10 and v11
  • TypeORM v0.3.x
  • Node.js 18+
  • TypeScript 5.x

Next Steps

Once installed, proceed to the Quick Start guide to configure the module and protect your first route.