Prerequisites
- Node.js 18.18+ (lib targets 18 / 20 / 22)
- TypeScript 5.0+ recommended
- Postgres 14+ (for production with RLS) —
better-sqlite3works for tests if you don't need the RLS layer - NestJS 10 or 11 (only required for the
nest-warden/nestjsmodule) - TypeORM 0.3 (only required for the
nest-warden/typeormmodule)
Install
pnpm add nest-warden @casl/ability
The @casl/ability peer dependency is always required — nest-warden builds on CASL's rule index and mongoQueryMatcher.
Adapters
The NestJS and TypeORM modules are optional peers — only install the ones you need.
pnpm add nest-warden @casl/ability \
@nestjs/common @nestjs/core typeorm pg \
reflect-metadata rxjs
TypeScript configuration
The library is published as ESM with CommonJS fallback. For consumers using TypeScript:
"moduleResolution": "Bundler"(TypeScript 5.0+) or"moduleResolution": "NodeNext"for the resolver to find the subpath exports (nest-warden/nestjs,nest-warden/typeorm)."target": "ES2022"or higher."experimentalDecorators": trueand"emitDecoratorMetadata": trueif you're using NestJS or TypeORM with the included decorators.
Verify the install
Quick smoke test:
import { TenantAbilityBuilder, createMongoAbility } from 'nest-warden';
const builder = new TenantAbilityBuilder(createMongoAbility, {
tenantId: 'demo',
subjectId: 'me',
roles: ['admin'],
});
builder.can('read', 'Merchant');
const ability = builder.build();
console.log(ability.can('read', { __caslSubjectType__: 'Merchant', tenantId: 'demo' }));
// → true
If that prints true, the install is correct.