@anievo-id/rbac-evolution-nestjs 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/index.cjs +24 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -8
- package/dist/index.d.ts +66 -8
- package/dist/index.js +25 -9
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -82,6 +82,21 @@ export class ArticlesController {
|
|
|
82
82
|
`@Require*()` decorator, `@UseGuards(RbacGuard)`, or `globalGuard: true`.
|
|
83
83
|
- The `Rbac` engine is injectable with `@Inject(RBAC)`.
|
|
84
84
|
|
|
85
|
+
## Typed names
|
|
86
|
+
|
|
87
|
+
Pass your `createRbac<AppRbac>()` type to `createRbacDecorators()`, and typos become compile errors:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
export const { RequirePermissions, RequireRoles } = createRbacDecorators<AppRbac>()
|
|
91
|
+
|
|
92
|
+
class ArticlesController {
|
|
93
|
+
@Put(':id') @RequirePermissions('articles.edit') update() {} // ok
|
|
94
|
+
@Delete(':id') @RequirePermissions('articles.edti') remove() {} // type error
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The top-level decorators still accept any string.
|
|
99
|
+
|
|
85
100
|
## Errors
|
|
86
101
|
|
|
87
102
|
| Situation | Exception | Body |
|
package/dist/index.cjs
CHANGED
|
@@ -164,23 +164,39 @@ function appendRequirement(requirement) {
|
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
166
|
var requirementDecorator = (requirement) => common.applyDecorators(appendRequirement(requirement), common.UseGuards(exports.RbacGuard));
|
|
167
|
-
function
|
|
167
|
+
function requirePermissions(...args) {
|
|
168
168
|
const { names, options } = rbacEvolution.splitRequirementArgs(args);
|
|
169
169
|
return requirementDecorator(rbacEvolution.permissionRequirement(names, options));
|
|
170
170
|
}
|
|
171
|
-
function
|
|
172
|
-
return
|
|
171
|
+
function canAny(...names) {
|
|
172
|
+
return requirePermissions(...names, { any: true });
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
return
|
|
174
|
+
function canAll(...names) {
|
|
175
|
+
return requirePermissions(...names);
|
|
176
176
|
}
|
|
177
|
-
function
|
|
177
|
+
function requireRoles(...args) {
|
|
178
178
|
const { names, options } = rbacEvolution.splitRequirementArgs(args);
|
|
179
179
|
return requirementDecorator(rbacEvolution.roleRequirement(names, options));
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function requireRoleOrPermission(...names) {
|
|
182
182
|
return requirementDecorator(rbacEvolution.roleOrPermissionRequirement(names));
|
|
183
183
|
}
|
|
184
|
+
function createRbacDecorators() {
|
|
185
|
+
const decorators = {
|
|
186
|
+
RequirePermissions: requirePermissions,
|
|
187
|
+
RequireRoles: requireRoles,
|
|
188
|
+
RequireRoleOrPermission: requireRoleOrPermission,
|
|
189
|
+
CanAny: canAny,
|
|
190
|
+
CanAll: canAll
|
|
191
|
+
};
|
|
192
|
+
return decorators;
|
|
193
|
+
}
|
|
194
|
+
var defaults = createRbacDecorators();
|
|
195
|
+
var RequirePermissions = defaults.RequirePermissions;
|
|
196
|
+
var CanAny = defaults.CanAny;
|
|
197
|
+
var CanAll = defaults.CanAll;
|
|
198
|
+
var RequireRoles = defaults.RequireRoles;
|
|
199
|
+
var RequireRoleOrPermission = defaults.RequireRoleOrPermission;
|
|
184
200
|
var CurrentRbac = common.createParamDecorator(
|
|
185
201
|
(_data, context) => getRbac(context)
|
|
186
202
|
);
|
|
@@ -195,6 +211,7 @@ exports.RbacGuardMissingError = RbacGuardMissingError;
|
|
|
195
211
|
exports.RequirePermissions = RequirePermissions;
|
|
196
212
|
exports.RequireRoleOrPermission = RequireRoleOrPermission;
|
|
197
213
|
exports.RequireRoles = RequireRoles;
|
|
214
|
+
exports.createRbacDecorators = createRbacDecorators;
|
|
198
215
|
exports.getRbac = getRbac;
|
|
199
216
|
//# sourceMappingURL=index.cjs.map
|
|
200
217
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context.ts","../src/tokens.ts","../src/guard.ts","../src/module.ts","../src/decorators.ts"],"names":["RbacGuard","UnauthorizedException","UNAUTHENTICATED_MESSAGE","satisfiesRequirement","ForbiddenException","REQUIREMENT_MESSAGES","Injectable","Reflector","RbacModule","APP_GUARD","Global","Module","applyDecorators","UseGuards","splitRequirementArgs","permissionRequirement","roleRequirement","roleOrPermissionRequirement","createParamDecorator"],"mappings":";;;;;;;;;;;;;;;;;;AAGO,IAAM,qBAAA,GAAN,cAAoC,KAAA,CAAM;AAAA,EACtC,IAAA,GAAO,oBAAA;AAAA,EAEhB,WAAA,GAAc;AACZ,IAAA,KAAA;AAAA,MACE;AAAA,KAEF;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,uBAAA;AAAA,EACd;AACF;AAGA,IAAM,QAAA,uBAAe,OAAA,EAAoC;AAMlD,SAAS,WAAW,OAAA,EAA+C;AACxE,EAAA,IAAI,GAAA;AACJ,EAAA,QAAQ,OAAA,CAAQ,SAAgB;AAAG,IACjC,KAAK,MAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,YAAA,EAAa,CAAE,UAAA,EAAW;AACxC,MAAA;AAAA,IACF,KAAK,KAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,WAAA,EAAY,CAAE,UAAA,EAAW;AACvC,MAAA;AAAA,IACF,KAAK,IAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,UAAA,EAAW,CAAE,SAAA,EAAU;AACrC,MAAA;AAAA,IACF;AACE,MAAA,GAAA,GAAM,OAAA,CAAQ,cAAc,CAAC,CAAA;AAAA;AAEjC,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,OAAO,GAAA,GAAM,MAAA;AACzD;AAEO,SAAS,YAAY,GA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W,OAAA,CAAQ,WAAA,CAAY,iBAAA,EAAmB,MAAM,KAAuC,EAAC;AACtG,IAAA,OAAA,CAAQ,eAAe,iBAAA,EAAmB,CAAC,GAAG,OAAA,EAAS,WAAW,GAAG,MAAM,CAAA;AAAA,EAC7E,CAAA;AACF;AAEA,IAAM,oBAAA,GAAuB,CAAC,WAAA,KAC5BI,sBAAA,CAAgB,kBAAkB,WAAW,CAAA,EAAGC,gBAAA,CAAUb,iBAAS,CAAC,CAAA;AAU/D,SAAS,sBAAsB,IAAA,EAA2D;AAC/F,EAAA,MAAM,EAAE,KAAA,EAAO,OAAA,EAAQ,GAAIc,mCAAmD,IAAI,CAAA;AAClF,EAAA,OAAO,oBAAA,CAAqBC,mCAAA,CAAsB,KAAA,EAAO,OAAO,CAAC,CAAA;AACnE;AAOO,SAAS,UAAU,KAAA,EAA2B;AACnD,EAAA,OAAO,mBAAmB,GAAG,KAAA,EAAO,EAAE,GAAA,EAAK,MAAM,CAAA;AACnD;AAOO,SAAS,UAAU,KAAA,EAA2B;AACnD,EAAA,OAAO,kBAAA,CAAmB,GAAG,KAAK,CAAA;AACpC;AAQO,SAAS,gBAAgB,IAAA,EAAqD;AACnF,EAAA,MAAM,EAAE,KAAA,EAAO,OAAA,EAAQ,GAAID,mCAA6C,IAAI,CAAA;AAC5E,EAAA,OAAO,oBAAA,CAAqBE,6BAAA,CAAgB,KAAA,EAAO,OAAO,CAAC,CAAA;AAC7D;AAQO,SAAS,2BAA2B,KAAA,EAA2B;AACpE,EAAA,OAAO,oBAAA,CAAqBC,yCAAA,CAA4B,KAAK,CAAC,CAAA;AAChE;AAaO,IAAM,WAAA,GAAwCC,2BAAA;AAAA,EACnD,CAAC,KAAA,EAAgB,OAAA,KAAkD,OAAA,CAAQ,OAAO;AACpF","file":"index.cjs","sourcesContent":["import type { SubjectRbac } from '@anievo-id/rbac-evolution'\nimport type { ExecutionContext } from '@nestjs/common'\n\nexport class RbacGuardMissingError extends Error {\n readonly code = 'RBAC_GUARD_MISSING'\n\n constructor() {\n super(\n '`@CurrentRbac()` was used but `RbacGuard` did not run for this route. Add a `@Require*()` decorator, ' +\n '`@UseGuards(RbacGuard)`, or `RbacModule.forRoot({ globalGuard: true })`.',\n )\n this.name = 'RbacGuardMissingError'\n }\n}\n\n/** Per-request resolved `SubjectRbac` (`null` for guests), keyed by the request/client/context object. */\nconst resolved = new WeakMap<object, SubjectRbac | null>()\n\n/**\n * The object that identifies the current request: the HTTP request, the RPC context, the WebSocket client,\n * or (for GraphQL and other context types) the third handler argument.\n */\nexport function requestKey(context: ExecutionContext): object | undefined {\n let key: unknown\n switch (context.getType<string>()) {\n case 'http':\n key = context.switchToHttp().getRequest()\n break\n case 'rpc':\n key = context.switchToRpc().getContext()\n break\n case 'ws':\n key = context.switchToWs().getClient()\n break\n default:\n key = context.getArgByIndex(2)\n }\n return typeof key === 'object' && key !== null ? key : undefined\n}\n\nexport function hasResolved(key: object): boolean {\n return resolved.has(key)\n}\n\nexport function getResolved(key: object): SubjectRbac | null | undefined {\n return resolved.get(key)\n}\n\nexport function setResolved(key: object, rbac: SubjectRbac | null): void {\n resolved.set(key, rbac)\n}\n\n/**\n * Returns the `SubjectRbac` that `RbacGuard` resolved for this execution context (`null` for guests).\n * Throws {@link RbacGuardMissingError} when the guard has not run.\n */\nexport function getRbac(context: ExecutionContext): SubjectRbac | null {\n const key = requestKey(context)\n if (key === undefined || !resolved.has(key)) throw new RbacGuardMissingError()\n return resolved.get(key) ?? null\n}\n","/** Injection token for the resolved {@link RbacModuleOptions}. */\nexport const RBAC_MODULE_OPTIONS = Symbol.for('rbac-evolution:nestjs:options')\n\n/** Injection token for the `Rbac` engine passed to `RbacModule.forRoot({ rbac })`. */\nexport const RBAC = Symbol.for('rbac-evolution:nestjs:rbac')\n\n/** Metadata key under which `@Require*` decorators store their requirements. */\nexport const RBAC_REQUIREMENTS = 'rbac-evolution:requirements'\n","import {\n type RbacRequirement,\n REQUIREMENT_MESSAGES,\n satisfiesRequirement,\n type SubjectRbac,\n UNAUTHENTICATED_MESSAGE,\n} from '@anievo-id/rbac-evolution'\nimport {\n type CanActivate,\n type ExecutionContext,\n ForbiddenException,\n Inject,\n Injectable,\n UnauthorizedException,\n} from '@nestjs/common'\nimport { Reflector } from '@nestjs/core'\nimport { getResolved, hasResolved, requestKey, setResolved } from './context'\nimport type { RbacModuleOptions } from './options'\nimport { RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS } from './tokens'\n\n/** Handlers already enforced for a request — the guard may run twice (global + `@UseGuards`). */\nconst enforced = new WeakMap<object, Set<unknown>>()\n\n/**\n * Only HTTP requests and RPC messages get a fresh key object per call. A WebSocket client or a\n * GraphQL context lives across many calls, so caching or skipping checks by it would let a denied\n * client through on its next message.\n */\nconst isPerCall = (context: ExecutionContext): boolean => ['http', 'rpc'].includes(context.getType<string>())\n\n/**\n * Resolves the current subject (once per request) and enforces the `@RequirePermissions()`,\n * `@RequireRoles()` and `@RequireRoleOrPermission()` metadata of the class and the handler.\n *\n * - no subject → `UnauthorizedException` `401 { error: 'UNAUTHENTICATED', message }`\n * - missing access → `ForbiddenException` `403 { error: 'FORBIDDEN', reason, message }`\n *\n * Bodies are identical to `@anievo-id/rbac-evolution-express`.\n */\n@Injectable()\nexport class RbacGuard implements CanActivate {\n // Explicit tokens: the package is built with esbuild, which does not emit `design:paramtypes`.\n constructor(\n @Inject(Reflector) private readonly reflector: Reflector,\n @Inject(RBAC_MODULE_OPTIONS) private readonly options: RbacModuleOptions,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const key = requestKey(context)\n const perCall = isPerCall(context)\n const rbac = await this.resolve(context, key, perCall)\n\n const handler = context.getHandler()\n if (perCall && key !== undefined && enforced.get(key)?.has(handler)) return true\n\n const requirements = [\n ...(this.reflector.get<RbacRequirement[] | undefined>(RBAC_REQUIREMENTS, context.getClass()) ?? []),\n ...(this.reflector.get<RbacRequirement[] | undefined>(RBAC_REQUIREMENTS, handler) ?? []),\n ]\n if (requirements.length === 0) return true\n\n if (rbac === null) {\n throw new UnauthorizedException({ error: 'UNAUTHENTICATED', message: UNAUTHENTICATED_MESSAGE })\n }\n\n for (const requirement of requirements) {\n if (!(await satisfiesRequirement(rbac, requirement))) {\n throw new ForbiddenException({\n error: 'FORBIDDEN',\n reason: requirement.kind,\n message: REQUIREMENT_MESSAGES[requirement.kind],\n ...(this.options.exposeRequirements && { required: requirement.requirements }),\n })\n }\n }\n // Mark as enforced only once every requirement passed.\n if (perCall && key !== undefined) enforced.set(key, (enforced.get(key) ?? new Set<unknown>()).add(handler))\n return true\n }\n\n private async resolve(context: ExecutionContext, key: object | undefined, perCall: boolean): Promise<SubjectRbac | null> {\n if (perCall && key !== undefined && hasResolved(key)) return getResolved(key) ?? null\n\n const { rbac, getSubject, guard, team } = this.options\n const subject = await getSubject(context)\n let result: SubjectRbac | null = null\n if (subject) {\n const teamId = team ? await team(context) : undefined\n result = rbac.for(subject, {\n ...(guard !== undefined && { guard }),\n ...(teamId !== undefined && { team: teamId }),\n })\n }\n if (key !== undefined) setResolved(key, result)\n return result\n }\n}\n","import { type DynamicModule, Global, Module, type Provider } from '@nestjs/common'\nimport { APP_GUARD } from '@nestjs/core'\nimport { RbacGuard } from './guard'\nimport type { RbacModuleAsyncConfig, RbacModuleConfig, RbacModuleOptions } from './options'\nimport { RBAC, RBAC_MODULE_OPTIONS } from './tokens'\n\nfunction build(optionsProvider: Provider, globalGuard: boolean, imports: DynamicModule['imports'] = []): DynamicModule {\n return {\n module: RbacModule,\n global: true,\n imports,\n providers: [\n optionsProvider,\n { provide: RBAC, useFactory: (options: RbacModuleOptions) => options.rbac, inject: [RBAC_MODULE_OPTIONS] },\n RbacGuard,\n ...(globalGuard ? [{ provide: APP_GUARD, useClass: RbacGuard }] : []),\n ],\n exports: [RBAC_MODULE_OPTIONS, RBAC, RbacGuard],\n }\n}\n\n/**\n * Registers rbac-evolution in a Nest application (global module).\n *\n * ```ts\n * @Module({\n * imports: [\n * RbacModule.forRoot({\n * rbac,\n * getSubject: (ctx) => {\n * const user = ctx.switchToHttp().getRequest().user\n * return user ? { type: 'user', id: user.id } : null\n * },\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n@Global()\n@Module({})\nexport class RbacModule {\n static forRoot(config: RbacModuleConfig): DynamicModule {\n const { globalGuard = false, ...options } = config\n return build({ provide: RBAC_MODULE_OPTIONS, useValue: options }, globalGuard)\n }\n\n /** Like {@link forRoot}, with options built by a factory (e.g. from a `ConfigService`). */\n static forRootAsync(config: RbacModuleAsyncConfig): DynamicModule {\n return build(\n { provide: RBAC_MODULE_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },\n config.globalGuard ?? false,\n config.imports ?? [],\n )\n }\n}\n","import 'reflect-metadata'\nimport { applyDecorators, createParamDecorator, type ExecutionContext, UseGuards } from '@nestjs/common'\nimport { getRbac } from './context'\nimport { RbacGuard } from './guard'\nimport {\n type PermissionRequirementOptions,\n permissionRequirement,\n type RbacRequirement,\n type RequirementNames,\n roleOrPermissionRequirement,\n roleRequirement,\n type RoleRequirementOptions,\n splitRequirementArgs,\n type SubjectRbac,\n} from '@anievo-id/rbac-evolution'\nimport { RBAC_REQUIREMENTS } from './tokens'\n\ntype ClassOrMethodDecorator = <T>(\n target: object,\n propertyKey?: string | symbol | undefined,\n descriptor?: TypedPropertyDescriptor<T> | undefined,\n) => void\n\n/** Appends a requirement (stacked decorators all apply), unlike `SetMetadata` which overwrites. */\nfunction appendRequirement(requirement: RbacRequirement): ClassOrMethodDecorator {\n return (target, _propertyKey, descriptor) => {\n const holder: object = descriptor?.value !== undefined ? (descriptor.value as object) : target\n const current = (Reflect.getMetadata(RBAC_REQUIREMENTS, holder) as RbacRequirement[] | undefined) ?? []\n Reflect.defineMetadata(RBAC_REQUIREMENTS, [...current, requirement], holder)\n }\n}\n\nconst requirementDecorator = (requirement: RbacRequirement) =>\n applyDecorators(appendRequirement(requirement), UseGuards(RbacGuard))\n\n/**\n * Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.\n *\n * - `@RequirePermissions('edit articles')`\n * - `@RequirePermissions('edit articles|delete articles')` — any of them\n * - `@RequirePermissions('edit articles', 'publish articles')` — all of them\n * - `@RequirePermissions('a', 'b', { any: true })` — any of them\n */\nexport function RequirePermissions(...args: (RequirementNames | PermissionRequirementOptions)[]) {\n const { names, options } = splitRequirementArgs<PermissionRequirementOptions>(args)\n return requirementDecorator(permissionRequirement(names, options))\n}\n\n/**\n * spatie v8.5 `canAny()`: passes with ANY of the listed permissions.\n *\n * - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`\n */\nexport function CanAny(...names: RequirementNames[]) {\n return RequirePermissions(...names, { any: true })\n}\n\n/**\n * spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means \"a or b\".\n *\n * - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`\n */\nexport function CanAll(...names: RequirementNames[]) {\n return RequirePermissions(...names)\n}\n\n/**\n * Requires roles, like spatie's `role:` middleware.\n *\n * - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them\n * - `@RequireRoles('admin', 'editor', { all: true })` — all of them\n */\nexport function RequireRoles(...args: (RequirementNames | RoleRequirementOptions)[]) {\n const { names, options } = splitRequirementArgs<RoleRequirementOptions>(args)\n return requirementDecorator(roleRequirement(names, options))\n}\n\n/**\n * Passes when the subject has ANY of the names as a role OR as a permission,\n * like spatie's `role_or_permission:` middleware.\n *\n * - `@RequireRoleOrPermission('admin|edit articles')`\n */\nexport function RequireRoleOrPermission(...names: RequirementNames[]) {\n return requirementDecorator(roleOrPermissionRequirement(names))\n}\n\n/**\n * Injects the current subject's `SubjectRbac` (`null` for guests), as resolved by `RbacGuard`.\n *\n * ```ts\n * @Get('me/permissions')\n * @UseGuards(RbacGuard)\n * snapshot(@CurrentRbac() rbac: SubjectRbac | null) {\n * return rbac?.snapshot() ?? null\n * }\n * ```\n */\nexport const CurrentRbac: () => ParameterDecorator = createParamDecorator(\n (_data: unknown, context: ExecutionContext): SubjectRbac | null => getRbac(context),\n)\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/context.ts","../src/tokens.ts","../src/guard.ts","../src/module.ts","../src/decorators.ts"],"names":["RbacGuard","UnauthorizedException","UNAUTHENTICATED_MESSAGE","satisfiesRequirement","ForbiddenException","REQUIREMENT_MESSAGES","Injectable","Reflector","RbacModule","APP_GUARD","Global","Module","applyDecorators","UseGuards","splitRequirementArgs","permissionRequirement","roleRequirement","roleOrPermissionRequirement","createParamDecorator"],"mappings":";;;;;;;;;;;;;;;;;;AAGO,IAAM,qBAAA,GAAN,cAAoC,KAAA,CAAM;AAAA,EACtC,IAAA,GAAO,oBAAA;AAAA,EAEhB,WAAA,GAAc;AACZ,IAAA,KAAA;AAAA,MACE;AAAA,KAEF;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,uBAAA;AAAA,EACd;AACF;AAGA,IAAM,QAAA,uBAAe,OAAA,EAAoC;AAMlD,SAAS,WAAW,OAAA,EAA+C;AACxE,EAAA,IAAI,GAAA;AACJ,EAAA,QAAQ,OAAA,CAAQ,SAAgB;AAAG,IACjC,KAAK,MAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,YAAA,EAAa,CAAE,UAAA,EAAW;AACxC,MAAA;AAAA,IACF,KAAK,KAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,WAAA,EAAY,CAAE,UAAA,EAAW;AACvC,MAAA;AAAA,IACF,KAAK,IAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,UAAA,EAAW,CAAE,SAAA,EAAU;AACrC,MAAA;AAAA,IACF;AACE,MAAA,GAAA,GAAM,OAAA,CAAQ,cAAc,CAAC,CAAA;AAAA;AAEjC,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,OAAO,GAAA,GAAM,MAAA;AACzD;AAEO,SAAS,YAAY,GAAA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OAAO,UAAA;AACT;AAEA,IAAM,WAAW,oBAAA,EAAqB;AAW/B,IAAM,qBAA2D,QAAA,CAAS;AAO1E,IAAM,SAAmC,QAAA,CAAS;AAOlD,IAAM,SAAmC,QAAA,CAAS;AAQlD,IAAM,eAA+C,QAAA,CAAS;AAQ9D,IAAM,0BAAqE,QAAA,CAAS;AAapF,IAAM,WAAA,GAAwCC,2BAAA;AAAA,EACnD,CAAC,KAAA,EAAgB,OAAA,KAAkD,OAAA,CAAQ,OAAO;AACpF","file":"index.cjs","sourcesContent":["import type { SubjectRbac } from '@anievo-id/rbac-evolution'\nimport type { ExecutionContext } from '@nestjs/common'\n\nexport class RbacGuardMissingError extends Error {\n readonly code = 'RBAC_GUARD_MISSING'\n\n constructor() {\n super(\n '`@CurrentRbac()` was used but `RbacGuard` did not run for this route. Add a `@Require*()` decorator, ' +\n '`@UseGuards(RbacGuard)`, or `RbacModule.forRoot({ globalGuard: true })`.',\n )\n this.name = 'RbacGuardMissingError'\n }\n}\n\n/** Per-request resolved `SubjectRbac` (`null` for guests), keyed by the request/client/context object. */\nconst resolved = new WeakMap<object, SubjectRbac | null>()\n\n/**\n * The object that identifies the current request: the HTTP request, the RPC context, the WebSocket client,\n * or (for GraphQL and other context types) the third handler argument.\n */\nexport function requestKey(context: ExecutionContext): object | undefined {\n let key: unknown\n switch (context.getType<string>()) {\n case 'http':\n key = context.switchToHttp().getRequest()\n break\n case 'rpc':\n key = context.switchToRpc().getContext()\n break\n case 'ws':\n key = context.switchToWs().getClient()\n break\n default:\n key = context.getArgByIndex(2)\n }\n return typeof key === 'object' && key !== null ? key : undefined\n}\n\nexport function hasResolved(key: object): boolean {\n return resolved.has(key)\n}\n\nexport function getResolved(key: object): SubjectRbac | null | undefined {\n return resolved.get(key)\n}\n\nexport function setResolved(key: object, rbac: SubjectRbac | null): void {\n resolved.set(key, rbac)\n}\n\n/**\n * Returns the `SubjectRbac` that `RbacGuard` resolved for this execution context (`null` for guests).\n * Throws {@link RbacGuardMissingError} when the guard has not run.\n */\nexport function getRbac(context: ExecutionContext): SubjectRbac | null {\n const key = requestKey(context)\n if (key === undefined || !resolved.has(key)) throw new RbacGuardMissingError()\n return resolved.get(key) ?? null\n}\n","/** Injection token for the resolved {@link RbacModuleOptions}. */\nexport const RBAC_MODULE_OPTIONS = Symbol.for('rbac-evolution:nestjs:options')\n\n/** Injection token for the `Rbac` engine passed to `RbacModule.forRoot({ rbac })`. */\nexport const RBAC = Symbol.for('rbac-evolution:nestjs:rbac')\n\n/** Metadata key under which `@Require*` decorators store their requirements. */\nexport const RBAC_REQUIREMENTS = 'rbac-evolution:requirements'\n","import {\n type RbacRequirement,\n REQUIREMENT_MESSAGES,\n satisfiesRequirement,\n type SubjectRbac,\n UNAUTHENTICATED_MESSAGE,\n} from '@anievo-id/rbac-evolution'\nimport {\n type CanActivate,\n type ExecutionContext,\n ForbiddenException,\n Inject,\n Injectable,\n UnauthorizedException,\n} from '@nestjs/common'\nimport { Reflector } from '@nestjs/core'\nimport { getResolved, hasResolved, requestKey, setResolved } from './context'\nimport type { RbacModuleOptions } from './options'\nimport { RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS } from './tokens'\n\n/** Handlers already enforced for a request — the guard may run twice (global + `@UseGuards`). */\nconst enforced = new WeakMap<object, Set<unknown>>()\n\n/**\n * Only HTTP requests and RPC messages get a fresh key object per call. A WebSocket client or a\n * GraphQL context lives across many calls, so caching or skipping checks by it would let a denied\n * client through on its next message.\n */\nconst isPerCall = (context: ExecutionContext): boolean => ['http', 'rpc'].includes(context.getType<string>())\n\n/**\n * Resolves the current subject (once per request) and enforces the `@RequirePermissions()`,\n * `@RequireRoles()` and `@RequireRoleOrPermission()` metadata of the class and the handler.\n *\n * - no subject → `UnauthorizedException` `401 { error: 'UNAUTHENTICATED', message }`\n * - missing access → `ForbiddenException` `403 { error: 'FORBIDDEN', reason, message }`\n *\n * Bodies are identical to `@anievo-id/rbac-evolution-express`.\n */\n@Injectable()\nexport class RbacGuard implements CanActivate {\n // Explicit tokens: the package is built with esbuild, which does not emit `design:paramtypes`.\n constructor(\n @Inject(Reflector) private readonly reflector: Reflector,\n @Inject(RBAC_MODULE_OPTIONS) private readonly options: RbacModuleOptions,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const key = requestKey(context)\n const perCall = isPerCall(context)\n const rbac = await this.resolve(context, key, perCall)\n\n const handler = context.getHandler()\n if (perCall && key !== undefined && enforced.get(key)?.has(handler)) return true\n\n const requirements = [\n ...(this.reflector.get<RbacRequirement[] | undefined>(RBAC_REQUIREMENTS, context.getClass()) ?? []),\n ...(this.reflector.get<RbacRequirement[] | undefined>(RBAC_REQUIREMENTS, handler) ?? []),\n ]\n if (requirements.length === 0) return true\n\n if (rbac === null) {\n throw new UnauthorizedException({ error: 'UNAUTHENTICATED', message: UNAUTHENTICATED_MESSAGE })\n }\n\n for (const requirement of requirements) {\n if (!(await satisfiesRequirement(rbac, requirement))) {\n throw new ForbiddenException({\n error: 'FORBIDDEN',\n reason: requirement.kind,\n message: REQUIREMENT_MESSAGES[requirement.kind],\n ...(this.options.exposeRequirements && { required: requirement.requirements }),\n })\n }\n }\n // Mark as enforced only once every requirement passed.\n if (perCall && key !== undefined) enforced.set(key, (enforced.get(key) ?? new Set<unknown>()).add(handler))\n return true\n }\n\n private async resolve(context: ExecutionContext, key: object | undefined, perCall: boolean): Promise<SubjectRbac | null> {\n if (perCall && key !== undefined && hasResolved(key)) return getResolved(key) ?? null\n\n const { rbac, getSubject, guard, team } = this.options\n const subject = await getSubject(context)\n let result: SubjectRbac | null = null\n if (subject) {\n const teamId = team ? await team(context) : undefined\n result = rbac.for(subject, {\n ...(guard !== undefined && { guard }),\n ...(teamId !== undefined && { team: teamId }),\n })\n }\n if (key !== undefined) setResolved(key, result)\n return result\n }\n}\n","import { type DynamicModule, Global, Module, type Provider } from '@nestjs/common'\nimport { APP_GUARD } from '@nestjs/core'\nimport { RbacGuard } from './guard'\nimport type { RbacModuleAsyncConfig, RbacModuleConfig, RbacModuleOptions } from './options'\nimport { RBAC, RBAC_MODULE_OPTIONS } from './tokens'\n\nfunction build(optionsProvider: Provider, globalGuard: boolean, imports: DynamicModule['imports'] = []): DynamicModule {\n return {\n module: RbacModule,\n global: true,\n imports,\n providers: [\n optionsProvider,\n { provide: RBAC, useFactory: (options: RbacModuleOptions) => options.rbac, inject: [RBAC_MODULE_OPTIONS] },\n RbacGuard,\n ...(globalGuard ? [{ provide: APP_GUARD, useClass: RbacGuard }] : []),\n ],\n exports: [RBAC_MODULE_OPTIONS, RBAC, RbacGuard],\n }\n}\n\n/**\n * Registers rbac-evolution in a Nest application (global module).\n *\n * ```ts\n * @Module({\n * imports: [\n * RbacModule.forRoot({\n * rbac,\n * getSubject: (ctx) => {\n * const user = ctx.switchToHttp().getRequest().user\n * return user ? { type: 'user', id: user.id } : null\n * },\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n@Global()\n@Module({})\nexport class RbacModule {\n static forRoot(config: RbacModuleConfig): DynamicModule {\n const { globalGuard = false, ...options } = config\n return build({ provide: RBAC_MODULE_OPTIONS, useValue: options }, globalGuard)\n }\n\n /** Like {@link forRoot}, with options built by a factory (e.g. from a `ConfigService`). */\n static forRootAsync(config: RbacModuleAsyncConfig): DynamicModule {\n return build(\n { provide: RBAC_MODULE_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },\n config.globalGuard ?? false,\n config.imports ?? [],\n )\n }\n}\n","import 'reflect-metadata'\nimport { applyDecorators, createParamDecorator, type ExecutionContext, UseGuards } from '@nestjs/common'\nimport { getRbac } from './context'\nimport { RbacGuard } from './guard'\nimport {\n type DefaultRbacTypes,\n type PermissionName,\n type PermissionRequirementOptions,\n permissionRequirement,\n type RbacRequirement,\n type RbacTypeConfig,\n type RequirementArgs,\n type RequirementNames,\n type RoleName,\n roleOrPermissionRequirement,\n roleRequirement,\n type RoleRequirementOptions,\n splitRequirementArgs,\n type SubjectRbac,\n} from '@anievo-id/rbac-evolution'\nimport { RBAC_REQUIREMENTS } from './tokens'\n\ntype ClassOrMethodDecorator = <T>(\n target: object,\n propertyKey?: string | symbol | undefined,\n descriptor?: TypedPropertyDescriptor<T> | undefined,\n) => void\n\n/** Appends a requirement (stacked decorators all apply), unlike `SetMetadata` which overwrites. */\nfunction appendRequirement(requirement: RbacRequirement): ClassOrMethodDecorator {\n return (target, _propertyKey, descriptor) => {\n const holder: object = descriptor?.value !== undefined ? (descriptor.value as object) : target\n const current = (Reflect.getMetadata(RBAC_REQUIREMENTS, holder) as RbacRequirement[] | undefined) ?? []\n Reflect.defineMetadata(RBAC_REQUIREMENTS, [...current, requirement], holder)\n }\n}\n\n/** The decorator every `@Require*()` / `@Can*()` factory returns (usable on classes and methods). */\nexport type RbacDecorator = ReturnType<typeof applyDecorators>\n\nconst requirementDecorator = (requirement: RbacRequirement): RbacDecorator =>\n applyDecorators(appendRequirement(requirement), UseGuards(RbacGuard))\n\n// Untyped implementations (plain `string` names, spread-friendly). The exported decorators add typed signatures.\nfunction requirePermissions(...args: (RequirementNames | PermissionRequirementOptions)[]): RbacDecorator {\n const { names, options } = splitRequirementArgs<PermissionRequirementOptions>(args)\n return requirementDecorator(permissionRequirement(names, options))\n}\n\nfunction canAny(...names: RequirementNames[]): RbacDecorator {\n return requirePermissions(...names, { any: true })\n}\n\nfunction canAll(...names: RequirementNames[]): RbacDecorator {\n return requirePermissions(...names)\n}\n\nfunction requireRoles(...args: (RequirementNames | RoleRequirementOptions)[]): RbacDecorator {\n const { names, options } = splitRequirementArgs<RoleRequirementOptions>(args)\n return requirementDecorator(roleRequirement(names, options))\n}\n\nfunction requireRoleOrPermission(...names: RequirementNames[]): RbacDecorator {\n return requirementDecorator(roleOrPermissionRequirement(names))\n}\n\n/**\n * The requirement decorators, with names checked against `T` (see `createRbacDecorators`).\n * With the default `T`, any name is accepted. In both cases a call without names, or with options\n * that are not the last argument, is a type error.\n */\nexport interface RbacDecorators<T extends RbacTypeConfig = DefaultRbacTypes> {\n /**\n * Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.\n *\n * - `@RequirePermissions('edit articles')`\n * - `@RequirePermissions('edit articles|delete articles')` — any of them\n * - `@RequirePermissions('edit articles', 'publish articles')` — all of them\n * - `@RequirePermissions('a', 'b', { any: true })` — any of them\n */\n RequirePermissions: <const A extends readonly (RequirementNames | PermissionRequirementOptions)[]>(\n ...args: A & RequirementArgs<A, PermissionName<T>, PermissionRequirementOptions>\n ) => RbacDecorator\n /**\n * Requires roles, like spatie's `role:` middleware.\n *\n * - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them\n * - `@RequireRoles('admin', 'editor', { all: true })` — all of them\n */\n RequireRoles: <const A extends readonly (RequirementNames | RoleRequirementOptions)[]>(\n ...args: A & RequirementArgs<A, RoleName<T>, RoleRequirementOptions>\n ) => RbacDecorator\n /**\n * Passes when the subject has ANY of the names as a role OR as a permission,\n * like spatie's `role_or_permission:` middleware.\n *\n * - `@RequireRoleOrPermission('admin|edit articles')`\n */\n RequireRoleOrPermission: <const A extends readonly RequirementNames[]>(\n ...names: A & RequirementArgs<A, PermissionName<T> | RoleName<T>, never>\n ) => RbacDecorator\n /**\n * spatie v8.5 `canAny()`: passes with ANY of the listed permissions.\n *\n * - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`\n */\n CanAny: <const A extends readonly RequirementNames[]>(\n ...names: A & RequirementArgs<A, PermissionName<T>, never>\n ) => RbacDecorator\n /**\n * spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means \"a or b\".\n *\n * - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`\n */\n CanAll: <const A extends readonly RequirementNames[]>(\n ...names: A & RequirementArgs<A, PermissionName<T>, never>\n ) => RbacDecorator\n}\n\n/**\n * Returns the requirement decorators with names checked against your typed names\n * (the same `T` as `createRbac<T>(...)`). Runtime behaviour is the same as the top-level decorators.\n *\n * ```ts\n * type AppTypes = { permissions: 'edit articles' | 'delete articles'; roles: 'admin' | 'writer' }\n * export const { RequirePermissions, RequireRoles } = createRbacDecorators<AppTypes>()\n *\n * @RequirePermissions('edit articles') // ok\n * @RequirePermissions('edit artcles') // type error\n * ```\n */\nexport function createRbacDecorators<T extends RbacTypeConfig = DefaultRbacTypes>(): RbacDecorators<T> {\n const decorators = {\n RequirePermissions: requirePermissions,\n RequireRoles: requireRoles,\n RequireRoleOrPermission: requireRoleOrPermission,\n CanAny: canAny,\n CanAll: canAll,\n } satisfies Record<keyof RbacDecorators, unknown>\n return decorators as unknown as RbacDecorators<T>\n}\n\nconst defaults = createRbacDecorators()\n\n/**\n * Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.\n * Accepts any name; for typed names use `createRbacDecorators<T>()`.\n *\n * - `@RequirePermissions('edit articles')`\n * - `@RequirePermissions('edit articles|delete articles')` — any of them\n * - `@RequirePermissions('edit articles', 'publish articles')` — all of them\n * - `@RequirePermissions('a', 'b', { any: true })` — any of them\n */\nexport const RequirePermissions: RbacDecorators['RequirePermissions'] = defaults.RequirePermissions\n\n/**\n * spatie v8.5 `canAny()`: passes with ANY of the listed permissions.\n *\n * - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`\n */\nexport const CanAny: RbacDecorators['CanAny'] = defaults.CanAny\n\n/**\n * spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means \"a or b\".\n *\n * - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`\n */\nexport const CanAll: RbacDecorators['CanAll'] = defaults.CanAll\n\n/**\n * Requires roles, like spatie's `role:` middleware.\n *\n * - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them\n * - `@RequireRoles('admin', 'editor', { all: true })` — all of them\n */\nexport const RequireRoles: RbacDecorators['RequireRoles'] = defaults.RequireRoles\n\n/**\n * Passes when the subject has ANY of the names as a role OR as a permission,\n * like spatie's `role_or_permission:` middleware.\n *\n * - `@RequireRoleOrPermission('admin|edit articles')`\n */\nexport const RequireRoleOrPermission: RbacDecorators['RequireRoleOrPermission'] = defaults.RequireRoleOrPermission\n\n/**\n * Injects the current subject's `SubjectRbac` (`null` for guests), as resolved by `RbacGuard`.\n *\n * ```ts\n * @Get('me/permissions')\n * @UseGuards(RbacGuard)\n * snapshot(@CurrentRbac() rbac: SubjectRbac | null) {\n * return rbac?.snapshot() ?? null\n * }\n * ```\n */\nexport const CurrentRbac: () => ParameterDecorator = createParamDecorator(\n (_data: unknown, context: ExecutionContext): SubjectRbac | null => getRbac(context),\n)\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExecutionContext, ModuleMetadata, FactoryProvider, DynamicModule, CanActivate } from '@nestjs/common';
|
|
2
|
-
import { Rbac, Subject, TeamId, RequirementNames, PermissionRequirementOptions, RoleRequirementOptions, SubjectRbac } from '@anievo-id/rbac-evolution';
|
|
1
|
+
import { ExecutionContext, ModuleMetadata, FactoryProvider, DynamicModule, CanActivate, applyDecorators } from '@nestjs/common';
|
|
2
|
+
import { Rbac, Subject, TeamId, RbacTypeConfig, DefaultRbacTypes, RequirementNames, PermissionRequirementOptions, RequirementArgs, PermissionName, RoleRequirementOptions, RoleName, SubjectRbac } from '@anievo-id/rbac-evolution';
|
|
3
3
|
export { PermissionRequirementOptions, RbacRequirement, RequirementKind, RequirementNames, RoleRequirementOptions } from '@anievo-id/rbac-evolution';
|
|
4
4
|
import { Reflector } from '@nestjs/core';
|
|
5
5
|
|
|
@@ -79,41 +79,99 @@ declare class RbacGuard implements CanActivate {
|
|
|
79
79
|
private resolve;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** The decorator every `@Require*()` / `@Can*()` factory returns (usable on classes and methods). */
|
|
83
|
+
type RbacDecorator = ReturnType<typeof applyDecorators>;
|
|
84
|
+
/**
|
|
85
|
+
* The requirement decorators, with names checked against `T` (see `createRbacDecorators`).
|
|
86
|
+
* With the default `T`, any name is accepted. In both cases a call without names, or with options
|
|
87
|
+
* that are not the last argument, is a type error.
|
|
88
|
+
*/
|
|
89
|
+
interface RbacDecorators<T extends RbacTypeConfig = DefaultRbacTypes> {
|
|
90
|
+
/**
|
|
91
|
+
* Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.
|
|
92
|
+
*
|
|
93
|
+
* - `@RequirePermissions('edit articles')`
|
|
94
|
+
* - `@RequirePermissions('edit articles|delete articles')` — any of them
|
|
95
|
+
* - `@RequirePermissions('edit articles', 'publish articles')` — all of them
|
|
96
|
+
* - `@RequirePermissions('a', 'b', { any: true })` — any of them
|
|
97
|
+
*/
|
|
98
|
+
RequirePermissions: <const A extends readonly (RequirementNames | PermissionRequirementOptions)[]>(...args: A & RequirementArgs<A, PermissionName<T>, PermissionRequirementOptions>) => RbacDecorator;
|
|
99
|
+
/**
|
|
100
|
+
* Requires roles, like spatie's `role:` middleware.
|
|
101
|
+
*
|
|
102
|
+
* - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them
|
|
103
|
+
* - `@RequireRoles('admin', 'editor', { all: true })` — all of them
|
|
104
|
+
*/
|
|
105
|
+
RequireRoles: <const A extends readonly (RequirementNames | RoleRequirementOptions)[]>(...args: A & RequirementArgs<A, RoleName<T>, RoleRequirementOptions>) => RbacDecorator;
|
|
106
|
+
/**
|
|
107
|
+
* Passes when the subject has ANY of the names as a role OR as a permission,
|
|
108
|
+
* like spatie's `role_or_permission:` middleware.
|
|
109
|
+
*
|
|
110
|
+
* - `@RequireRoleOrPermission('admin|edit articles')`
|
|
111
|
+
*/
|
|
112
|
+
RequireRoleOrPermission: <const A extends readonly RequirementNames[]>(...names: A & RequirementArgs<A, PermissionName<T> | RoleName<T>, never>) => RbacDecorator;
|
|
113
|
+
/**
|
|
114
|
+
* spatie v8.5 `canAny()`: passes with ANY of the listed permissions.
|
|
115
|
+
*
|
|
116
|
+
* - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`
|
|
117
|
+
*/
|
|
118
|
+
CanAny: <const A extends readonly RequirementNames[]>(...names: A & RequirementArgs<A, PermissionName<T>, never>) => RbacDecorator;
|
|
119
|
+
/**
|
|
120
|
+
* spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means "a or b".
|
|
121
|
+
*
|
|
122
|
+
* - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`
|
|
123
|
+
*/
|
|
124
|
+
CanAll: <const A extends readonly RequirementNames[]>(...names: A & RequirementArgs<A, PermissionName<T>, never>) => RbacDecorator;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns the requirement decorators with names checked against your typed names
|
|
128
|
+
* (the same `T` as `createRbac<T>(...)`). Runtime behaviour is the same as the top-level decorators.
|
|
129
|
+
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* type AppTypes = { permissions: 'edit articles' | 'delete articles'; roles: 'admin' | 'writer' }
|
|
132
|
+
* export const { RequirePermissions, RequireRoles } = createRbacDecorators<AppTypes>()
|
|
133
|
+
*
|
|
134
|
+
* @RequirePermissions('edit articles') // ok
|
|
135
|
+
* @RequirePermissions('edit artcles') // type error
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function createRbacDecorators<T extends RbacTypeConfig = DefaultRbacTypes>(): RbacDecorators<T>;
|
|
82
139
|
/**
|
|
83
140
|
* Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.
|
|
141
|
+
* Accepts any name; for typed names use `createRbacDecorators<T>()`.
|
|
84
142
|
*
|
|
85
143
|
* - `@RequirePermissions('edit articles')`
|
|
86
144
|
* - `@RequirePermissions('edit articles|delete articles')` — any of them
|
|
87
145
|
* - `@RequirePermissions('edit articles', 'publish articles')` — all of them
|
|
88
146
|
* - `@RequirePermissions('a', 'b', { any: true })` — any of them
|
|
89
147
|
*/
|
|
90
|
-
declare
|
|
148
|
+
declare const RequirePermissions: RbacDecorators['RequirePermissions'];
|
|
91
149
|
/**
|
|
92
150
|
* spatie v8.5 `canAny()`: passes with ANY of the listed permissions.
|
|
93
151
|
*
|
|
94
152
|
* - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`
|
|
95
153
|
*/
|
|
96
|
-
declare
|
|
154
|
+
declare const CanAny: RbacDecorators['CanAny'];
|
|
97
155
|
/**
|
|
98
156
|
* spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means "a or b".
|
|
99
157
|
*
|
|
100
158
|
* - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`
|
|
101
159
|
*/
|
|
102
|
-
declare
|
|
160
|
+
declare const CanAll: RbacDecorators['CanAll'];
|
|
103
161
|
/**
|
|
104
162
|
* Requires roles, like spatie's `role:` middleware.
|
|
105
163
|
*
|
|
106
164
|
* - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them
|
|
107
165
|
* - `@RequireRoles('admin', 'editor', { all: true })` — all of them
|
|
108
166
|
*/
|
|
109
|
-
declare
|
|
167
|
+
declare const RequireRoles: RbacDecorators['RequireRoles'];
|
|
110
168
|
/**
|
|
111
169
|
* Passes when the subject has ANY of the names as a role OR as a permission,
|
|
112
170
|
* like spatie's `role_or_permission:` middleware.
|
|
113
171
|
*
|
|
114
172
|
* - `@RequireRoleOrPermission('admin|edit articles')`
|
|
115
173
|
*/
|
|
116
|
-
declare
|
|
174
|
+
declare const RequireRoleOrPermission: RbacDecorators['RequireRoleOrPermission'];
|
|
117
175
|
/**
|
|
118
176
|
* Injects the current subject's `SubjectRbac` (`null` for guests), as resolved by `RbacGuard`.
|
|
119
177
|
*
|
|
@@ -144,4 +202,4 @@ declare const RBAC: unique symbol;
|
|
|
144
202
|
/** Metadata key under which `@Require*` decorators store their requirements. */
|
|
145
203
|
declare const RBAC_REQUIREMENTS = "rbac-evolution:requirements";
|
|
146
204
|
|
|
147
|
-
export { CanAll, CanAny, CurrentRbac, RBAC, RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS, RbacGuard, RbacGuardMissingError, RbacModule, type RbacModuleAsyncConfig, type RbacModuleConfig, type RbacModuleOptions, RequirePermissions, RequireRoleOrPermission, RequireRoles, getRbac };
|
|
205
|
+
export { CanAll, CanAny, CurrentRbac, RBAC, RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS, type RbacDecorator, type RbacDecorators, RbacGuard, RbacGuardMissingError, RbacModule, type RbacModuleAsyncConfig, type RbacModuleConfig, type RbacModuleOptions, RequirePermissions, RequireRoleOrPermission, RequireRoles, createRbacDecorators, getRbac };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExecutionContext, ModuleMetadata, FactoryProvider, DynamicModule, CanActivate } from '@nestjs/common';
|
|
2
|
-
import { Rbac, Subject, TeamId, RequirementNames, PermissionRequirementOptions, RoleRequirementOptions, SubjectRbac } from '@anievo-id/rbac-evolution';
|
|
1
|
+
import { ExecutionContext, ModuleMetadata, FactoryProvider, DynamicModule, CanActivate, applyDecorators } from '@nestjs/common';
|
|
2
|
+
import { Rbac, Subject, TeamId, RbacTypeConfig, DefaultRbacTypes, RequirementNames, PermissionRequirementOptions, RequirementArgs, PermissionName, RoleRequirementOptions, RoleName, SubjectRbac } from '@anievo-id/rbac-evolution';
|
|
3
3
|
export { PermissionRequirementOptions, RbacRequirement, RequirementKind, RequirementNames, RoleRequirementOptions } from '@anievo-id/rbac-evolution';
|
|
4
4
|
import { Reflector } from '@nestjs/core';
|
|
5
5
|
|
|
@@ -79,41 +79,99 @@ declare class RbacGuard implements CanActivate {
|
|
|
79
79
|
private resolve;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
/** The decorator every `@Require*()` / `@Can*()` factory returns (usable on classes and methods). */
|
|
83
|
+
type RbacDecorator = ReturnType<typeof applyDecorators>;
|
|
84
|
+
/**
|
|
85
|
+
* The requirement decorators, with names checked against `T` (see `createRbacDecorators`).
|
|
86
|
+
* With the default `T`, any name is accepted. In both cases a call without names, or with options
|
|
87
|
+
* that are not the last argument, is a type error.
|
|
88
|
+
*/
|
|
89
|
+
interface RbacDecorators<T extends RbacTypeConfig = DefaultRbacTypes> {
|
|
90
|
+
/**
|
|
91
|
+
* Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.
|
|
92
|
+
*
|
|
93
|
+
* - `@RequirePermissions('edit articles')`
|
|
94
|
+
* - `@RequirePermissions('edit articles|delete articles')` — any of them
|
|
95
|
+
* - `@RequirePermissions('edit articles', 'publish articles')` — all of them
|
|
96
|
+
* - `@RequirePermissions('a', 'b', { any: true })` — any of them
|
|
97
|
+
*/
|
|
98
|
+
RequirePermissions: <const A extends readonly (RequirementNames | PermissionRequirementOptions)[]>(...args: A & RequirementArgs<A, PermissionName<T>, PermissionRequirementOptions>) => RbacDecorator;
|
|
99
|
+
/**
|
|
100
|
+
* Requires roles, like spatie's `role:` middleware.
|
|
101
|
+
*
|
|
102
|
+
* - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them
|
|
103
|
+
* - `@RequireRoles('admin', 'editor', { all: true })` — all of them
|
|
104
|
+
*/
|
|
105
|
+
RequireRoles: <const A extends readonly (RequirementNames | RoleRequirementOptions)[]>(...args: A & RequirementArgs<A, RoleName<T>, RoleRequirementOptions>) => RbacDecorator;
|
|
106
|
+
/**
|
|
107
|
+
* Passes when the subject has ANY of the names as a role OR as a permission,
|
|
108
|
+
* like spatie's `role_or_permission:` middleware.
|
|
109
|
+
*
|
|
110
|
+
* - `@RequireRoleOrPermission('admin|edit articles')`
|
|
111
|
+
*/
|
|
112
|
+
RequireRoleOrPermission: <const A extends readonly RequirementNames[]>(...names: A & RequirementArgs<A, PermissionName<T> | RoleName<T>, never>) => RbacDecorator;
|
|
113
|
+
/**
|
|
114
|
+
* spatie v8.5 `canAny()`: passes with ANY of the listed permissions.
|
|
115
|
+
*
|
|
116
|
+
* - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`
|
|
117
|
+
*/
|
|
118
|
+
CanAny: <const A extends readonly RequirementNames[]>(...names: A & RequirementArgs<A, PermissionName<T>, never>) => RbacDecorator;
|
|
119
|
+
/**
|
|
120
|
+
* spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means "a or b".
|
|
121
|
+
*
|
|
122
|
+
* - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`
|
|
123
|
+
*/
|
|
124
|
+
CanAll: <const A extends readonly RequirementNames[]>(...names: A & RequirementArgs<A, PermissionName<T>, never>) => RbacDecorator;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Returns the requirement decorators with names checked against your typed names
|
|
128
|
+
* (the same `T` as `createRbac<T>(...)`). Runtime behaviour is the same as the top-level decorators.
|
|
129
|
+
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* type AppTypes = { permissions: 'edit articles' | 'delete articles'; roles: 'admin' | 'writer' }
|
|
132
|
+
* export const { RequirePermissions, RequireRoles } = createRbacDecorators<AppTypes>()
|
|
133
|
+
*
|
|
134
|
+
* @RequirePermissions('edit articles') // ok
|
|
135
|
+
* @RequirePermissions('edit artcles') // type error
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function createRbacDecorators<T extends RbacTypeConfig = DefaultRbacTypes>(): RbacDecorators<T>;
|
|
82
139
|
/**
|
|
83
140
|
* Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.
|
|
141
|
+
* Accepts any name; for typed names use `createRbacDecorators<T>()`.
|
|
84
142
|
*
|
|
85
143
|
* - `@RequirePermissions('edit articles')`
|
|
86
144
|
* - `@RequirePermissions('edit articles|delete articles')` — any of them
|
|
87
145
|
* - `@RequirePermissions('edit articles', 'publish articles')` — all of them
|
|
88
146
|
* - `@RequirePermissions('a', 'b', { any: true })` — any of them
|
|
89
147
|
*/
|
|
90
|
-
declare
|
|
148
|
+
declare const RequirePermissions: RbacDecorators['RequirePermissions'];
|
|
91
149
|
/**
|
|
92
150
|
* spatie v8.5 `canAny()`: passes with ANY of the listed permissions.
|
|
93
151
|
*
|
|
94
152
|
* - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`
|
|
95
153
|
*/
|
|
96
|
-
declare
|
|
154
|
+
declare const CanAny: RbacDecorators['CanAny'];
|
|
97
155
|
/**
|
|
98
156
|
* spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means "a or b".
|
|
99
157
|
*
|
|
100
158
|
* - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`
|
|
101
159
|
*/
|
|
102
|
-
declare
|
|
160
|
+
declare const CanAll: RbacDecorators['CanAll'];
|
|
103
161
|
/**
|
|
104
162
|
* Requires roles, like spatie's `role:` middleware.
|
|
105
163
|
*
|
|
106
164
|
* - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them
|
|
107
165
|
* - `@RequireRoles('admin', 'editor', { all: true })` — all of them
|
|
108
166
|
*/
|
|
109
|
-
declare
|
|
167
|
+
declare const RequireRoles: RbacDecorators['RequireRoles'];
|
|
110
168
|
/**
|
|
111
169
|
* Passes when the subject has ANY of the names as a role OR as a permission,
|
|
112
170
|
* like spatie's `role_or_permission:` middleware.
|
|
113
171
|
*
|
|
114
172
|
* - `@RequireRoleOrPermission('admin|edit articles')`
|
|
115
173
|
*/
|
|
116
|
-
declare
|
|
174
|
+
declare const RequireRoleOrPermission: RbacDecorators['RequireRoleOrPermission'];
|
|
117
175
|
/**
|
|
118
176
|
* Injects the current subject's `SubjectRbac` (`null` for guests), as resolved by `RbacGuard`.
|
|
119
177
|
*
|
|
@@ -144,4 +202,4 @@ declare const RBAC: unique symbol;
|
|
|
144
202
|
/** Metadata key under which `@Require*` decorators store their requirements. */
|
|
145
203
|
declare const RBAC_REQUIREMENTS = "rbac-evolution:requirements";
|
|
146
204
|
|
|
147
|
-
export { CanAll, CanAny, CurrentRbac, RBAC, RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS, RbacGuard, RbacGuardMissingError, RbacModule, type RbacModuleAsyncConfig, type RbacModuleConfig, type RbacModuleOptions, RequirePermissions, RequireRoleOrPermission, RequireRoles, getRbac };
|
|
205
|
+
export { CanAll, CanAny, CurrentRbac, RBAC, RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS, type RbacDecorator, type RbacDecorators, RbacGuard, RbacGuardMissingError, RbacModule, type RbacModuleAsyncConfig, type RbacModuleConfig, type RbacModuleOptions, RequirePermissions, RequireRoleOrPermission, RequireRoles, createRbacDecorators, getRbac };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Injectable, Inject, Global, Module, createParamDecorator, UnauthorizedException, ForbiddenException, applyDecorators, UseGuards } from '@nestjs/common';
|
|
2
2
|
import { Reflector, APP_GUARD } from '@nestjs/core';
|
|
3
|
-
import { UNAUTHENTICATED_MESSAGE, satisfiesRequirement, REQUIREMENT_MESSAGES,
|
|
3
|
+
import { UNAUTHENTICATED_MESSAGE, satisfiesRequirement, REQUIREMENT_MESSAGES, roleOrPermissionRequirement, splitRequirementArgs, roleRequirement, permissionRequirement } from '@anievo-id/rbac-evolution';
|
|
4
4
|
import 'reflect-metadata';
|
|
5
5
|
|
|
6
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -162,27 +162,43 @@ function appendRequirement(requirement) {
|
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
var requirementDecorator = (requirement) => applyDecorators(appendRequirement(requirement), UseGuards(RbacGuard));
|
|
165
|
-
function
|
|
165
|
+
function requirePermissions(...args) {
|
|
166
166
|
const { names, options } = splitRequirementArgs(args);
|
|
167
167
|
return requirementDecorator(permissionRequirement(names, options));
|
|
168
168
|
}
|
|
169
|
-
function
|
|
170
|
-
return
|
|
169
|
+
function canAny(...names) {
|
|
170
|
+
return requirePermissions(...names, { any: true });
|
|
171
171
|
}
|
|
172
|
-
function
|
|
173
|
-
return
|
|
172
|
+
function canAll(...names) {
|
|
173
|
+
return requirePermissions(...names);
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function requireRoles(...args) {
|
|
176
176
|
const { names, options } = splitRequirementArgs(args);
|
|
177
177
|
return requirementDecorator(roleRequirement(names, options));
|
|
178
178
|
}
|
|
179
|
-
function
|
|
179
|
+
function requireRoleOrPermission(...names) {
|
|
180
180
|
return requirementDecorator(roleOrPermissionRequirement(names));
|
|
181
181
|
}
|
|
182
|
+
function createRbacDecorators() {
|
|
183
|
+
const decorators = {
|
|
184
|
+
RequirePermissions: requirePermissions,
|
|
185
|
+
RequireRoles: requireRoles,
|
|
186
|
+
RequireRoleOrPermission: requireRoleOrPermission,
|
|
187
|
+
CanAny: canAny,
|
|
188
|
+
CanAll: canAll
|
|
189
|
+
};
|
|
190
|
+
return decorators;
|
|
191
|
+
}
|
|
192
|
+
var defaults = createRbacDecorators();
|
|
193
|
+
var RequirePermissions = defaults.RequirePermissions;
|
|
194
|
+
var CanAny = defaults.CanAny;
|
|
195
|
+
var CanAll = defaults.CanAll;
|
|
196
|
+
var RequireRoles = defaults.RequireRoles;
|
|
197
|
+
var RequireRoleOrPermission = defaults.RequireRoleOrPermission;
|
|
182
198
|
var CurrentRbac = createParamDecorator(
|
|
183
199
|
(_data, context) => getRbac(context)
|
|
184
200
|
);
|
|
185
201
|
|
|
186
|
-
export { CanAll, CanAny, CurrentRbac, RBAC, RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS, RbacGuard, RbacGuardMissingError, RbacModule, RequirePermissions, RequireRoleOrPermission, RequireRoles, getRbac };
|
|
202
|
+
export { CanAll, CanAny, CurrentRbac, RBAC, RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS, RbacGuard, RbacGuardMissingError, RbacModule, RequirePermissions, RequireRoleOrPermission, RequireRoles, createRbacDecorators, getRbac };
|
|
187
203
|
//# sourceMappingURL=index.js.map
|
|
188
204
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/context.ts","../src/tokens.ts","../src/guard.ts","../src/module.ts","../src/decorators.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGO,IAAM,qBAAA,GAAN,cAAoC,KAAA,CAAM;AAAA,EACtC,IAAA,GAAO,oBAAA;AAAA,EAEhB,WAAA,GAAc;AACZ,IAAA,KAAA;AAAA,MACE;AAAA,KAEF;AACA,IAAA,IAAA,CAAK,IAAA,GAAO,uBAAA;AAAA,EACd;AACF;AAGA,IAAM,QAAA,uBAAe,OAAA,EAAoC;AAMlD,SAAS,WAAW,OAAA,EAA+C;AACxE,EAAA,IAAI,GAAA;AACJ,EAAA,QAAQ,OAAA,CAAQ,SAAgB;AAAG,IACjC,KAAK,MAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,YAAA,EAAa,CAAE,UAAA,EAAW;AACxC,MAAA;AAAA,IACF,KAAK,KAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,WAAA,EAAY,CAAE,UAAA,EAAW;AACvC,MAAA;AAAA,IACF,KAAK,IAAA;AACH,MAAA,GAAA,GAAM,OAAA,CAAQ,UAAA,EAAW,CAAE,SAAA,EAAU;AACrC,MAAA;AAAA,IACF;AACE,MAAA,GAAA,GAAM,OAAA,CAAQ,cAAc,CAAC,CAAA;AAAA;AAEjC,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,OAAO,GAAA,GAAM,MAAA;AACzD;AAEO,SAAS,YAAY,GAAA,EAAsB;AAChD,EAAA,OAAO,QAAA,CAAS,IAAI,GAAG,CAAA;AACzB;AAEO,SAAS,YAAY,GAAA,EAA6C;AACvE,EAAA,OAAO,QAAA,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A,EAC7E,CAAA;AACF;AAEA,IAAM,oBAAA,GAAuB,CAAC,WAAA,KAC5B,eAAA,CAAgB,kBAAkB,WAAW,CAAA,EAAG,SAAA,CAAU,SAAS,CAAC,CAAA;AAU/D,SAAS,sBAAsB,IAAA,EAA2D;AAC/F,EAAA,MAAM,EAAE,KAAA,EAAO,OAAA,EAAQ,GAAI,qBAAmD,IAAI,CAAA;AAClF,EAAA,OAAO,oBAAA,CAAqB,qBAAA,CAAsB,KAAA,EAAO,OAAO,CAAC,CAAA;AACnE;AAOO,SAAS,UAAU,KAAA,EAA2B;AACnD,EAAA,OAAO,mBAAmB,GAAG,KAAA,EAAO,EAAE,GAAA,EAAK,MAAM,CAAA;AACnD;AAOO,SAAS,UAAU,KAAA,EAA2B;AACnD,EAAA,OAAO,kBAAA,CAAmB,GAAG,KAAK,CAAA;AACpC;AAQO,SAAS,gBAAgB,IAAA,EAAqD;AACnF,EAAA,MAAM,EAAE,KAAA,EAAO,OAAA,EAAQ,GAAI,qBAA6C,IAAI,CAAA;AAC5E,EAAA,OAAO,oBAAA,CAAqB,eAAA,CAAgB,KAAA,EAAO,OAAO,CAAC,CAAA;AAC7D;AAQO,SAAS,2BAA2B,KAAA,EAA2B;AACpE,EAAA,OAAO,oBAAA,CAAqB,2BAAA,CAA4B,KAAK,CAAC,CAAA;AAChE;AAaO,IAAM,WAAA,GAAwC,oBAAA;AAAA,EACnD,CAAC,KAAA,EAAgB,OAAA,KAAkD,OAAA,CAAQ,OAAO;AACpF","file":"index.js","sourcesContent":["import type { SubjectRbac } from '@anievo-id/rbac-evolution'\nimport type { ExecutionContext } from '@nestjs/common'\n\nexport class RbacGuardMissingError extends Error {\n readonly code = 'RBAC_GUARD_MISSING'\n\n constructor() {\n super(\n '`@CurrentRbac()` was used but `RbacGuard` did not run for this route. Add a `@Require*()` decorator, ' +\n '`@UseGuards(RbacGuard)`, or `RbacModule.forRoot({ globalGuard: true })`.',\n )\n this.name = 'RbacGuardMissingError'\n }\n}\n\n/** Per-request resolved `SubjectRbac` (`null` for guests), keyed by the request/client/context object. */\nconst resolved = new WeakMap<object, SubjectRbac | null>()\n\n/**\n * The object that identifies the current request: the HTTP request, the RPC context, the WebSocket client,\n * or (for GraphQL and other context types) the third handler argument.\n */\nexport function requestKey(context: ExecutionContext): object | undefined {\n let key: unknown\n switch (context.getType<string>()) {\n case 'http':\n key = context.switchToHttp().getRequest()\n break\n case 'rpc':\n key = context.switchToRpc().getContext()\n break\n case 'ws':\n key = context.switchToWs().getClient()\n break\n default:\n key = context.getArgByIndex(2)\n }\n return typeof key === 'object' && key !== null ? key : undefined\n}\n\nexport function hasResolved(key: object): boolean {\n return resolved.has(key)\n}\n\nexport function getResolved(key: object): SubjectRbac | null | undefined {\n return resolved.get(key)\n}\n\nexport function setResolved(key: object, rbac: SubjectRbac | null): void {\n resolved.set(key, rbac)\n}\n\n/**\n * Returns the `SubjectRbac` that `RbacGuard` resolved for this execution context (`null` for guests).\n * Throws {@link RbacGuardMissingError} when the guard has not run.\n */\nexport function getRbac(context: ExecutionContext): SubjectRbac | null {\n const key = requestKey(context)\n if (key === undefined || !resolved.has(key)) throw new RbacGuardMissingError()\n return resolved.get(key) ?? null\n}\n","/** Injection token for the resolved {@link RbacModuleOptions}. */\nexport const RBAC_MODULE_OPTIONS = Symbol.for('rbac-evolution:nestjs:options')\n\n/** Injection token for the `Rbac` engine passed to `RbacModule.forRoot({ rbac })`. */\nexport const RBAC = Symbol.for('rbac-evolution:nestjs:rbac')\n\n/** Metadata key under which `@Require*` decorators store their requirements. */\nexport const RBAC_REQUIREMENTS = 'rbac-evolution:requirements'\n","import {\n type RbacRequirement,\n REQUIREMENT_MESSAGES,\n satisfiesRequirement,\n type SubjectRbac,\n UNAUTHENTICATED_MESSAGE,\n} from '@anievo-id/rbac-evolution'\nimport {\n type CanActivate,\n type ExecutionContext,\n ForbiddenException,\n Inject,\n Injectable,\n UnauthorizedException,\n} from '@nestjs/common'\nimport { Reflector } from '@nestjs/core'\nimport { getResolved, hasResolved, requestKey, setResolved } from './context'\nimport type { RbacModuleOptions } from './options'\nimport { RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS } from './tokens'\n\n/** Handlers already enforced for a request — the guard may run twice (global + `@UseGuards`). */\nconst enforced = new WeakMap<object, Set<unknown>>()\n\n/**\n * Only HTTP requests and RPC messages get a fresh key object per call. A WebSocket client or a\n * GraphQL context lives across many calls, so caching or skipping checks by it would let a denied\n * client through on its next message.\n */\nconst isPerCall = (context: ExecutionContext): boolean => ['http', 'rpc'].includes(context.getType<string>())\n\n/**\n * Resolves the current subject (once per request) and enforces the `@RequirePermissions()`,\n * `@RequireRoles()` and `@RequireRoleOrPermission()` metadata of the class and the handler.\n *\n * - no subject → `UnauthorizedException` `401 { error: 'UNAUTHENTICATED', message }`\n * - missing access → `ForbiddenException` `403 { error: 'FORBIDDEN', reason, message }`\n *\n * Bodies are identical to `@anievo-id/rbac-evolution-express`.\n */\n@Injectable()\nexport class RbacGuard implements CanActivate {\n // Explicit tokens: the package is built with esbuild, which does not emit `design:paramtypes`.\n constructor(\n @Inject(Reflector) private readonly reflector: Reflector,\n @Inject(RBAC_MODULE_OPTIONS) private readonly options: RbacModuleOptions,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const key = requestKey(context)\n const perCall = isPerCall(context)\n const rbac = await this.resolve(context, key, perCall)\n\n const handler = context.getHandler()\n if (perCall && key !== undefined && enforced.get(key)?.has(handler)) return true\n\n const requirements = [\n ...(this.reflector.get<RbacRequirement[] | undefined>(RBAC_REQUIREMENTS, context.getClass()) ?? []),\n ...(this.reflector.get<RbacRequirement[] | undefined>(RBAC_REQUIREMENTS, handler) ?? []),\n ]\n if (requirements.length === 0) return true\n\n if (rbac === null) {\n throw new UnauthorizedException({ error: 'UNAUTHENTICATED', message: UNAUTHENTICATED_MESSAGE })\n }\n\n for (const requirement of requirements) {\n if (!(await satisfiesRequirement(rbac, requirement))) {\n throw new ForbiddenException({\n error: 'FORBIDDEN',\n reason: requirement.kind,\n message: REQUIREMENT_MESSAGES[requirement.kind],\n ...(this.options.exposeRequirements && { required: requirement.requirements }),\n })\n }\n }\n // Mark as enforced only once every requirement passed.\n if (perCall && key !== undefined) enforced.set(key, (enforced.get(key) ?? new Set<unknown>()).add(handler))\n return true\n }\n\n private async resolve(context: ExecutionContext, key: object | undefined, perCall: boolean): Promise<SubjectRbac | null> {\n if (perCall && key !== undefined && hasResolved(key)) return getResolved(key) ?? null\n\n const { rbac, getSubject, guard, team } = this.options\n const subject = await getSubject(context)\n let result: SubjectRbac | null = null\n if (subject) {\n const teamId = team ? await team(context) : undefined\n result = rbac.for(subject, {\n ...(guard !== undefined && { guard }),\n ...(teamId !== undefined && { team: teamId }),\n })\n }\n if (key !== undefined) setResolved(key, result)\n return result\n }\n}\n","import { type DynamicModule, Global, Module, type Provider } from '@nestjs/common'\nimport { APP_GUARD } from '@nestjs/core'\nimport { RbacGuard } from './guard'\nimport type { RbacModuleAsyncConfig, RbacModuleConfig, RbacModuleOptions } from './options'\nimport { RBAC, RBAC_MODULE_OPTIONS } from './tokens'\n\nfunction build(optionsProvider: Provider, globalGuard: boolean, imports: DynamicModule['imports'] = []): DynamicModule {\n return {\n module: RbacModule,\n global: true,\n imports,\n providers: [\n optionsProvider,\n { provide: RBAC, useFactory: (options: RbacModuleOptions) => options.rbac, inject: [RBAC_MODULE_OPTIONS] },\n RbacGuard,\n ...(globalGuard ? [{ provide: APP_GUARD, useClass: RbacGuard }] : []),\n ],\n exports: [RBAC_MODULE_OPTIONS, RBAC, RbacGuard],\n }\n}\n\n/**\n * Registers rbac-evolution in a Nest application (global module).\n *\n * ```ts\n * @Module({\n * imports: [\n * RbacModule.forRoot({\n * rbac,\n * getSubject: (ctx) => {\n * const user = ctx.switchToHttp().getRequest().user\n * return user ? { type: 'user', id: user.id } : null\n * },\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n@Global()\n@Module({})\nexport class RbacModule {\n static forRoot(config: RbacModuleConfig): DynamicModule {\n const { globalGuard = false, ...options } = config\n return build({ provide: RBAC_MODULE_OPTIONS, useValue: options }, globalGuard)\n }\n\n /** Like {@link forRoot}, with options built by a factory (e.g. from a `ConfigService`). */\n static forRootAsync(config: RbacModuleAsyncConfig): DynamicModule {\n return build(\n { provide: RBAC_MODULE_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },\n config.globalGuard ?? false,\n config.imports ?? [],\n )\n }\n}\n","import 'reflect-metadata'\nimport { applyDecorators, createParamDecorator, type ExecutionContext, UseGuards } from '@nestjs/common'\nimport { getRbac } from './context'\nimport { RbacGuard } from './guard'\nimport {\n type PermissionRequirementOptions,\n permissionRequirement,\n type RbacRequirement,\n type RequirementNames,\n roleOrPermissionRequirement,\n roleRequirement,\n type RoleRequirementOptions,\n splitRequirementArgs,\n type SubjectRbac,\n} from '@anievo-id/rbac-evolution'\nimport { RBAC_REQUIREMENTS } from './tokens'\n\ntype ClassOrMethodDecorator = <T>(\n target: object,\n propertyKey?: string | symbol | undefined,\n descriptor?: TypedPropertyDescriptor<T> | undefined,\n) => void\n\n/** Appends a requirement (stacked decorators all apply), unlike `SetMetadata` which overwrites. */\nfunction appendRequirement(requirement: RbacRequirement): ClassOrMethodDecorator {\n return (target, _propertyKey, descriptor) => {\n const holder: object = descriptor?.value !== undefined ? (descriptor.value as object) : target\n const current = (Reflect.getMetadata(RBAC_REQUIREMENTS, holder) as RbacRequirement[] | undefined) ?? []\n Reflect.defineMetadata(RBAC_REQUIREMENTS, [...current, requirement], holder)\n }\n}\n\nconst requirementDecorator = (requirement: RbacRequirement) =>\n applyDecorators(appendRequirement(requirement), UseGuards(RbacGuard))\n\n/**\n * Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.\n *\n * - `@RequirePermissions('edit articles')`\n * - `@RequirePermissions('edit articles|delete articles')` — any of them\n * - `@RequirePermissions('edit articles', 'publish articles')` — all of them\n * - `@RequirePermissions('a', 'b', { any: true })` — any of them\n */\nexport function RequirePermissions(...args: (RequirementNames | PermissionRequirementOptions)[]) {\n const { names, options } = splitRequirementArgs<PermissionRequirementOptions>(args)\n return requirementDecorator(permissionRequirement(names, options))\n}\n\n/**\n * spatie v8.5 `canAny()`: passes with ANY of the listed permissions.\n *\n * - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`\n */\nexport function CanAny(...names: RequirementNames[]) {\n return RequirePermissions(...names, { any: true })\n}\n\n/**\n * spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means \"a or b\".\n *\n * - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`\n */\nexport function CanAll(...names: RequirementNames[]) {\n return RequirePermissions(...names)\n}\n\n/**\n * Requires roles, like spatie's `role:` middleware.\n *\n * - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them\n * - `@RequireRoles('admin', 'editor', { all: true })` — all of them\n */\nexport function RequireRoles(...args: (RequirementNames | RoleRequirementOptions)[]) {\n const { names, options } = splitRequirementArgs<RoleRequirementOptions>(args)\n return requirementDecorator(roleRequirement(names, options))\n}\n\n/**\n * Passes when the subject has ANY of the names as a role OR as a permission,\n * like spatie's `role_or_permission:` middleware.\n *\n * - `@RequireRoleOrPermission('admin|edit articles')`\n */\nexport function RequireRoleOrPermission(...names: RequirementNames[]) {\n return requirementDecorator(roleOrPermissionRequirement(names))\n}\n\n/**\n * Injects the current subject's `SubjectRbac` (`null` for guests), as resolved by `RbacGuard`.\n *\n * ```ts\n * @Get('me/permissions')\n * @UseGuards(RbacGuard)\n * snapshot(@CurrentRbac() rbac: SubjectRbac | null) {\n * return rbac?.snapshot() ?? null\n * }\n * ```\n */\nexport const CurrentRbac: () => ParameterDecorator = createParamDecorator(\n (_data: unknown, context: ExecutionContext): SubjectRbac | null => getRbac(context),\n)\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/context.ts","../src/tokens.ts","../src/guard.ts","../src/module.ts","../src/decorators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,EAAA,OAAO,oBAAA,CAAqB,qBAAA,CAAsB,KAAA,EAAO,OAAO,CAAC,CAAA;AACnE;AAEA,SAAS,UAAU,KAAA,EAA0C;AAC3D,EAAA,OAAO,mBAAmB,GAAG,KAAA,EAAO,EAAE,GAAA,EAAK,MAAM,CAAA;AACnD;AAEA,SAAS,UAAU,KAAA,EAA0C;AAC3D,EAAA,OAAO,kBAAA,CAAmB,GAAG,KAAK,CAAA;AACpC;AAEA,SAAS,gBAAgB,IAAA,EAAoE;AAC3F,EAAA,MAAM,EAAE,KAAA,EAAO,OAAA,EAAQ,GAAI,qBAA6C,IAAI,CAAA;AAC5E,EAAA,OAAO,oBAAA,CAAqB,eAAA,CAAgB,KAAA,EAAO,OAAO,CAAC,CAAA;AAC7D;AAEA,SAAS,2BAA2B,KAAA,EAA0C;AAC5E,EAAA,OAAO,oBAAA,CAAqB,2BAAA,CAA4B,KAAK,CAAC,CAAA;AAChE;AAmEO,SAAS,oBAAA,GAAuF;AACrG,EAAA,MAAM,UAAA,GAAa;AAAA,IACjB,kBAAA,EAAoB,kBAAA;AAAA,IACpB,YAAA,EAAc,YAAA;AAAA,IACd,uBAAA,EAAyB,uBAAA;AAAA,IACzB,MAAA,EAAQ,MAAA;AAAA,IACR,MAAA,EAAQ;AAAA,GACV;AACA,EAAA,OAAO,UAAA;AACT;AAEA,IAAM,WAAW,oBAAA,EAAqB;AAW/B,IAAM,qBAA2D,QAAA,CAAS;AAO1E,IAAM,SAAmC,QAAA,CAAS;AAOlD,IAAM,SAAmC,QAAA,CAAS;AAQlD,IAAM,eAA+C,QAAA,CAAS;AAQ9D,IAAM,0BAAqE,QAAA,CAAS;AAapF,IAAM,WAAA,GAAwC,oBAAA;AAAA,EACnD,CAAC,KAAA,EAAgB,OAAA,KAAkD,OAAA,CAAQ,OAAO;AACpF","file":"index.js","sourcesContent":["import type { SubjectRbac } from '@anievo-id/rbac-evolution'\nimport type { ExecutionContext } from '@nestjs/common'\n\nexport class RbacGuardMissingError extends Error {\n readonly code = 'RBAC_GUARD_MISSING'\n\n constructor() {\n super(\n '`@CurrentRbac()` was used but `RbacGuard` did not run for this route. Add a `@Require*()` decorator, ' +\n '`@UseGuards(RbacGuard)`, or `RbacModule.forRoot({ globalGuard: true })`.',\n )\n this.name = 'RbacGuardMissingError'\n }\n}\n\n/** Per-request resolved `SubjectRbac` (`null` for guests), keyed by the request/client/context object. */\nconst resolved = new WeakMap<object, SubjectRbac | null>()\n\n/**\n * The object that identifies the current request: the HTTP request, the RPC context, the WebSocket client,\n * or (for GraphQL and other context types) the third handler argument.\n */\nexport function requestKey(context: ExecutionContext): object | undefined {\n let key: unknown\n switch (context.getType<string>()) {\n case 'http':\n key = context.switchToHttp().getRequest()\n break\n case 'rpc':\n key = context.switchToRpc().getContext()\n break\n case 'ws':\n key = context.switchToWs().getClient()\n break\n default:\n key = context.getArgByIndex(2)\n }\n return typeof key === 'object' && key !== null ? key : undefined\n}\n\nexport function hasResolved(key: object): boolean {\n return resolved.has(key)\n}\n\nexport function getResolved(key: object): SubjectRbac | null | undefined {\n return resolved.get(key)\n}\n\nexport function setResolved(key: object, rbac: SubjectRbac | null): void {\n resolved.set(key, rbac)\n}\n\n/**\n * Returns the `SubjectRbac` that `RbacGuard` resolved for this execution context (`null` for guests).\n * Throws {@link RbacGuardMissingError} when the guard has not run.\n */\nexport function getRbac(context: ExecutionContext): SubjectRbac | null {\n const key = requestKey(context)\n if (key === undefined || !resolved.has(key)) throw new RbacGuardMissingError()\n return resolved.get(key) ?? null\n}\n","/** Injection token for the resolved {@link RbacModuleOptions}. */\nexport const RBAC_MODULE_OPTIONS = Symbol.for('rbac-evolution:nestjs:options')\n\n/** Injection token for the `Rbac` engine passed to `RbacModule.forRoot({ rbac })`. */\nexport const RBAC = Symbol.for('rbac-evolution:nestjs:rbac')\n\n/** Metadata key under which `@Require*` decorators store their requirements. */\nexport const RBAC_REQUIREMENTS = 'rbac-evolution:requirements'\n","import {\n type RbacRequirement,\n REQUIREMENT_MESSAGES,\n satisfiesRequirement,\n type SubjectRbac,\n UNAUTHENTICATED_MESSAGE,\n} from '@anievo-id/rbac-evolution'\nimport {\n type CanActivate,\n type ExecutionContext,\n ForbiddenException,\n Inject,\n Injectable,\n UnauthorizedException,\n} from '@nestjs/common'\nimport { Reflector } from '@nestjs/core'\nimport { getResolved, hasResolved, requestKey, setResolved } from './context'\nimport type { RbacModuleOptions } from './options'\nimport { RBAC_MODULE_OPTIONS, RBAC_REQUIREMENTS } from './tokens'\n\n/** Handlers already enforced for a request — the guard may run twice (global + `@UseGuards`). */\nconst enforced = new WeakMap<object, Set<unknown>>()\n\n/**\n * Only HTTP requests and RPC messages get a fresh key object per call. A WebSocket client or a\n * GraphQL context lives across many calls, so caching or skipping checks by it would let a denied\n * client through on its next message.\n */\nconst isPerCall = (context: ExecutionContext): boolean => ['http', 'rpc'].includes(context.getType<string>())\n\n/**\n * Resolves the current subject (once per request) and enforces the `@RequirePermissions()`,\n * `@RequireRoles()` and `@RequireRoleOrPermission()` metadata of the class and the handler.\n *\n * - no subject → `UnauthorizedException` `401 { error: 'UNAUTHENTICATED', message }`\n * - missing access → `ForbiddenException` `403 { error: 'FORBIDDEN', reason, message }`\n *\n * Bodies are identical to `@anievo-id/rbac-evolution-express`.\n */\n@Injectable()\nexport class RbacGuard implements CanActivate {\n // Explicit tokens: the package is built with esbuild, which does not emit `design:paramtypes`.\n constructor(\n @Inject(Reflector) private readonly reflector: Reflector,\n @Inject(RBAC_MODULE_OPTIONS) private readonly options: RbacModuleOptions,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const key = requestKey(context)\n const perCall = isPerCall(context)\n const rbac = await this.resolve(context, key, perCall)\n\n const handler = context.getHandler()\n if (perCall && key !== undefined && enforced.get(key)?.has(handler)) return true\n\n const requirements = [\n ...(this.reflector.get<RbacRequirement[] | undefined>(RBAC_REQUIREMENTS, context.getClass()) ?? []),\n ...(this.reflector.get<RbacRequirement[] | undefined>(RBAC_REQUIREMENTS, handler) ?? []),\n ]\n if (requirements.length === 0) return true\n\n if (rbac === null) {\n throw new UnauthorizedException({ error: 'UNAUTHENTICATED', message: UNAUTHENTICATED_MESSAGE })\n }\n\n for (const requirement of requirements) {\n if (!(await satisfiesRequirement(rbac, requirement))) {\n throw new ForbiddenException({\n error: 'FORBIDDEN',\n reason: requirement.kind,\n message: REQUIREMENT_MESSAGES[requirement.kind],\n ...(this.options.exposeRequirements && { required: requirement.requirements }),\n })\n }\n }\n // Mark as enforced only once every requirement passed.\n if (perCall && key !== undefined) enforced.set(key, (enforced.get(key) ?? new Set<unknown>()).add(handler))\n return true\n }\n\n private async resolve(context: ExecutionContext, key: object | undefined, perCall: boolean): Promise<SubjectRbac | null> {\n if (perCall && key !== undefined && hasResolved(key)) return getResolved(key) ?? null\n\n const { rbac, getSubject, guard, team } = this.options\n const subject = await getSubject(context)\n let result: SubjectRbac | null = null\n if (subject) {\n const teamId = team ? await team(context) : undefined\n result = rbac.for(subject, {\n ...(guard !== undefined && { guard }),\n ...(teamId !== undefined && { team: teamId }),\n })\n }\n if (key !== undefined) setResolved(key, result)\n return result\n }\n}\n","import { type DynamicModule, Global, Module, type Provider } from '@nestjs/common'\nimport { APP_GUARD } from '@nestjs/core'\nimport { RbacGuard } from './guard'\nimport type { RbacModuleAsyncConfig, RbacModuleConfig, RbacModuleOptions } from './options'\nimport { RBAC, RBAC_MODULE_OPTIONS } from './tokens'\n\nfunction build(optionsProvider: Provider, globalGuard: boolean, imports: DynamicModule['imports'] = []): DynamicModule {\n return {\n module: RbacModule,\n global: true,\n imports,\n providers: [\n optionsProvider,\n { provide: RBAC, useFactory: (options: RbacModuleOptions) => options.rbac, inject: [RBAC_MODULE_OPTIONS] },\n RbacGuard,\n ...(globalGuard ? [{ provide: APP_GUARD, useClass: RbacGuard }] : []),\n ],\n exports: [RBAC_MODULE_OPTIONS, RBAC, RbacGuard],\n }\n}\n\n/**\n * Registers rbac-evolution in a Nest application (global module).\n *\n * ```ts\n * @Module({\n * imports: [\n * RbacModule.forRoot({\n * rbac,\n * getSubject: (ctx) => {\n * const user = ctx.switchToHttp().getRequest().user\n * return user ? { type: 'user', id: user.id } : null\n * },\n * }),\n * ],\n * })\n * export class AppModule {}\n * ```\n */\n@Global()\n@Module({})\nexport class RbacModule {\n static forRoot(config: RbacModuleConfig): DynamicModule {\n const { globalGuard = false, ...options } = config\n return build({ provide: RBAC_MODULE_OPTIONS, useValue: options }, globalGuard)\n }\n\n /** Like {@link forRoot}, with options built by a factory (e.g. from a `ConfigService`). */\n static forRootAsync(config: RbacModuleAsyncConfig): DynamicModule {\n return build(\n { provide: RBAC_MODULE_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },\n config.globalGuard ?? false,\n config.imports ?? [],\n )\n }\n}\n","import 'reflect-metadata'\nimport { applyDecorators, createParamDecorator, type ExecutionContext, UseGuards } from '@nestjs/common'\nimport { getRbac } from './context'\nimport { RbacGuard } from './guard'\nimport {\n type DefaultRbacTypes,\n type PermissionName,\n type PermissionRequirementOptions,\n permissionRequirement,\n type RbacRequirement,\n type RbacTypeConfig,\n type RequirementArgs,\n type RequirementNames,\n type RoleName,\n roleOrPermissionRequirement,\n roleRequirement,\n type RoleRequirementOptions,\n splitRequirementArgs,\n type SubjectRbac,\n} from '@anievo-id/rbac-evolution'\nimport { RBAC_REQUIREMENTS } from './tokens'\n\ntype ClassOrMethodDecorator = <T>(\n target: object,\n propertyKey?: string | symbol | undefined,\n descriptor?: TypedPropertyDescriptor<T> | undefined,\n) => void\n\n/** Appends a requirement (stacked decorators all apply), unlike `SetMetadata` which overwrites. */\nfunction appendRequirement(requirement: RbacRequirement): ClassOrMethodDecorator {\n return (target, _propertyKey, descriptor) => {\n const holder: object = descriptor?.value !== undefined ? (descriptor.value as object) : target\n const current = (Reflect.getMetadata(RBAC_REQUIREMENTS, holder) as RbacRequirement[] | undefined) ?? []\n Reflect.defineMetadata(RBAC_REQUIREMENTS, [...current, requirement], holder)\n }\n}\n\n/** The decorator every `@Require*()` / `@Can*()` factory returns (usable on classes and methods). */\nexport type RbacDecorator = ReturnType<typeof applyDecorators>\n\nconst requirementDecorator = (requirement: RbacRequirement): RbacDecorator =>\n applyDecorators(appendRequirement(requirement), UseGuards(RbacGuard))\n\n// Untyped implementations (plain `string` names, spread-friendly). The exported decorators add typed signatures.\nfunction requirePermissions(...args: (RequirementNames | PermissionRequirementOptions)[]): RbacDecorator {\n const { names, options } = splitRequirementArgs<PermissionRequirementOptions>(args)\n return requirementDecorator(permissionRequirement(names, options))\n}\n\nfunction canAny(...names: RequirementNames[]): RbacDecorator {\n return requirePermissions(...names, { any: true })\n}\n\nfunction canAll(...names: RequirementNames[]): RbacDecorator {\n return requirePermissions(...names)\n}\n\nfunction requireRoles(...args: (RequirementNames | RoleRequirementOptions)[]): RbacDecorator {\n const { names, options } = splitRequirementArgs<RoleRequirementOptions>(args)\n return requirementDecorator(roleRequirement(names, options))\n}\n\nfunction requireRoleOrPermission(...names: RequirementNames[]): RbacDecorator {\n return requirementDecorator(roleOrPermissionRequirement(names))\n}\n\n/**\n * The requirement decorators, with names checked against `T` (see `createRbacDecorators`).\n * With the default `T`, any name is accepted. In both cases a call without names, or with options\n * that are not the last argument, is a type error.\n */\nexport interface RbacDecorators<T extends RbacTypeConfig = DefaultRbacTypes> {\n /**\n * Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.\n *\n * - `@RequirePermissions('edit articles')`\n * - `@RequirePermissions('edit articles|delete articles')` — any of them\n * - `@RequirePermissions('edit articles', 'publish articles')` — all of them\n * - `@RequirePermissions('a', 'b', { any: true })` — any of them\n */\n RequirePermissions: <const A extends readonly (RequirementNames | PermissionRequirementOptions)[]>(\n ...args: A & RequirementArgs<A, PermissionName<T>, PermissionRequirementOptions>\n ) => RbacDecorator\n /**\n * Requires roles, like spatie's `role:` middleware.\n *\n * - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them\n * - `@RequireRoles('admin', 'editor', { all: true })` — all of them\n */\n RequireRoles: <const A extends readonly (RequirementNames | RoleRequirementOptions)[]>(\n ...args: A & RequirementArgs<A, RoleName<T>, RoleRequirementOptions>\n ) => RbacDecorator\n /**\n * Passes when the subject has ANY of the names as a role OR as a permission,\n * like spatie's `role_or_permission:` middleware.\n *\n * - `@RequireRoleOrPermission('admin|edit articles')`\n */\n RequireRoleOrPermission: <const A extends readonly RequirementNames[]>(\n ...names: A & RequirementArgs<A, PermissionName<T> | RoleName<T>, never>\n ) => RbacDecorator\n /**\n * spatie v8.5 `canAny()`: passes with ANY of the listed permissions.\n *\n * - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`\n */\n CanAny: <const A extends readonly RequirementNames[]>(\n ...names: A & RequirementArgs<A, PermissionName<T>, never>\n ) => RbacDecorator\n /**\n * spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means \"a or b\".\n *\n * - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`\n */\n CanAll: <const A extends readonly RequirementNames[]>(\n ...names: A & RequirementArgs<A, PermissionName<T>, never>\n ) => RbacDecorator\n}\n\n/**\n * Returns the requirement decorators with names checked against your typed names\n * (the same `T` as `createRbac<T>(...)`). Runtime behaviour is the same as the top-level decorators.\n *\n * ```ts\n * type AppTypes = { permissions: 'edit articles' | 'delete articles'; roles: 'admin' | 'writer' }\n * export const { RequirePermissions, RequireRoles } = createRbacDecorators<AppTypes>()\n *\n * @RequirePermissions('edit articles') // ok\n * @RequirePermissions('edit artcles') // type error\n * ```\n */\nexport function createRbacDecorators<T extends RbacTypeConfig = DefaultRbacTypes>(): RbacDecorators<T> {\n const decorators = {\n RequirePermissions: requirePermissions,\n RequireRoles: requireRoles,\n RequireRoleOrPermission: requireRoleOrPermission,\n CanAny: canAny,\n CanAll: canAll,\n } satisfies Record<keyof RbacDecorators, unknown>\n return decorators as unknown as RbacDecorators<T>\n}\n\nconst defaults = createRbacDecorators()\n\n/**\n * Requires permissions, like spatie's `permission:` middleware. Works on controllers and handlers.\n * Accepts any name; for typed names use `createRbacDecorators<T>()`.\n *\n * - `@RequirePermissions('edit articles')`\n * - `@RequirePermissions('edit articles|delete articles')` — any of them\n * - `@RequirePermissions('edit articles', 'publish articles')` — all of them\n * - `@RequirePermissions('a', 'b', { any: true })` — any of them\n */\nexport const RequirePermissions: RbacDecorators['RequirePermissions'] = defaults.RequirePermissions\n\n/**\n * spatie v8.5 `canAny()`: passes with ANY of the listed permissions.\n *\n * - `@CanAny('edit articles', 'publish articles')`, `@CanAny(['edit articles', 'publish articles'])`\n */\nexport const CanAny: RbacDecorators['CanAny'] = defaults.CanAny\n\n/**\n * spatie v8.5 `canAll()`: requires EVERY listed entry. A `'a|b'` entry still means \"a or b\".\n *\n * - `@CanAll('edit articles', 'publish articles')`, `@CanAll(['edit articles', 'publish|review'])`\n */\nexport const CanAll: RbacDecorators['CanAll'] = defaults.CanAll\n\n/**\n * Requires roles, like spatie's `role:` middleware.\n *\n * - `@RequireRoles('admin')`, `@RequireRoles('admin|editor')`, `@RequireRoles('admin', 'editor')` — any of them\n * - `@RequireRoles('admin', 'editor', { all: true })` — all of them\n */\nexport const RequireRoles: RbacDecorators['RequireRoles'] = defaults.RequireRoles\n\n/**\n * Passes when the subject has ANY of the names as a role OR as a permission,\n * like spatie's `role_or_permission:` middleware.\n *\n * - `@RequireRoleOrPermission('admin|edit articles')`\n */\nexport const RequireRoleOrPermission: RbacDecorators['RequireRoleOrPermission'] = defaults.RequireRoleOrPermission\n\n/**\n * Injects the current subject's `SubjectRbac` (`null` for guests), as resolved by `RbacGuard`.\n *\n * ```ts\n * @Get('me/permissions')\n * @UseGuards(RbacGuard)\n * snapshot(@CurrentRbac() rbac: SubjectRbac | null) {\n * return rbac?.snapshot() ?? null\n * }\n * ```\n */\nexport const CurrentRbac: () => ParameterDecorator = createParamDecorator(\n (_data: unknown, context: ExecutionContext): SubjectRbac | null => getRbac(context),\n)\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anievo-id/rbac-evolution-nestjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "NestJS module, guard & decorators for rbac-evolution.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "AniEvo-ID (https://github.com/AniEvo-ID)",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@anievo-id/rbac-evolution": "^0.
|
|
51
|
+
"@anievo-id/rbac-evolution": "^0.8.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@nestjs/common": "^10.0.0 || ^11.0.0 || ^12.0.0",
|