@application-kit/authorization 0.0.0 → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # @application-kit/authorization
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4bcfbde: Вход `/nest`: `AuthorizationModule.forRoot({ grants })` — динамический модуль с `AbilityFactory` (токен `ABILITY_FACTORY`),
8
+ картой грантов `ABILITY_GRANTS`, pino-логгером `AUTHORIZATION_LOGGER` и глобальным `PoliciesGuard` (`APP_GUARD`);
9
+ экспортирует `ABILITY_FACTORY`, `ABILITY_GRANTS`, `AbilityFactory`. Ручная проводка провайдеров в приложении больше не нужна.
10
+ `PoliciesGuard` получает `Reflector` по явному токену — модуль собирается и без `emitDecoratorMetadata`.
11
+
12
+ ## 0.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - 85addee: Первый выпуск: реестры ролей и subject'ов для module augmentation, `buildAbilityFor` и `composeAbilityGrants` (корень,
17
+ изоморфно, только `@casl/ability`); `PoliciesGuard`, `CheckPolicies`, `permitAuthenticated`, `Public`, `AbilityFactory`,
18
+ токены и pino-логгер `AuthorizationLogger` (вход `/nest`). Guard не зависит от `@nestjs/graphql`.
package/README.md CHANGED
@@ -55,16 +55,15 @@ const ability = buildAbilityFor({ role: 'EDITOR' }, grants)
55
55
  - `Public()`, `IS_PUBLIC_KEY` — открытый обработчик; ключ читает и guard аутентификации приложения.
56
56
  - `AbilityFactory` — ability актора по карте грантов.
57
57
 
58
- Провайдеры токенов приносит приложение:
58
+ Собирает механизм `AuthorizationModule.forRoot({ grants })`: фабрика ability, логгер и глобальный guard (`APP_GUARD`)
59
+ провайдятся пакетом, приложение приносит только карту грантов. Наружу модуль отдаёт `ABILITY_FACTORY`, `ABILITY_GRANTS`
60
+ и `AbilityFactory` — для кода, который строит ability актора сам (например, резолвер, отдающий её клиенту).
59
61
 
60
62
  ```ts
61
- providers: [
62
- AbilityFactory,
63
- { provide: ABILITY_FACTORY, useExisting: AbilityFactory },
64
- { provide: ABILITY_GRANTS, useValue: grants },
65
- { provide: AUTHORIZATION_LOGGER, useClass: AuthorizationLogger },
66
- { provide: APP_GUARD, useClass: PoliciesGuard },
67
- ]
63
+ @Module({
64
+ imports: [AuthorizationModule.forRoot({ grants })],
65
+ })
66
+ export class AppModule {}
68
67
  ```
69
68
 
70
69
  `AuthorizationLogger` — pino-логгер пакета с контекстом `AuthorizationLogger`; собирается из глобального
@@ -0,0 +1,8 @@
1
+ import type { DynamicModule } from '@nestjs/common';
2
+ import type { AbilityGrantMap } from '../types/ability-grant.js';
3
+ export interface AuthorizationModuleOptionsInterface {
4
+ readonly grants: AbilityGrantMap;
5
+ }
6
+ export declare class AuthorizationModule {
7
+ static forRoot(options: AuthorizationModuleOptionsInterface): DynamicModule;
8
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AuthorizationModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const core_1 = require("@nestjs/core");
12
+ const ability_factory_js_1 = require("./ability.factory.js");
13
+ const authorization_logger_js_1 = require("./authorization-logger.js");
14
+ const constants_js_1 = require("./constants.js");
15
+ const policies_guard_js_1 = require("./policies.guard.js");
16
+ let AuthorizationModule = class AuthorizationModule {
17
+ static forRoot(options) {
18
+ return {
19
+ exports: [constants_js_1.ABILITY_FACTORY, constants_js_1.ABILITY_GRANTS, ability_factory_js_1.AbilityFactory],
20
+ module: this,
21
+ providers: [
22
+ ability_factory_js_1.AbilityFactory,
23
+ { provide: constants_js_1.ABILITY_FACTORY, useExisting: ability_factory_js_1.AbilityFactory },
24
+ { provide: constants_js_1.ABILITY_GRANTS, useValue: options.grants },
25
+ { provide: constants_js_1.AUTHORIZATION_LOGGER, useClass: authorization_logger_js_1.AuthorizationLogger },
26
+ policies_guard_js_1.PoliciesGuard,
27
+ { provide: core_1.APP_GUARD, useExisting: policies_guard_js_1.PoliciesGuard },
28
+ ],
29
+ };
30
+ }
31
+ };
32
+ exports.AuthorizationModule = AuthorizationModule;
33
+ exports.AuthorizationModule = AuthorizationModule = __decorate([
34
+ (0, common_1.Module)({})
35
+ ], AuthorizationModule);
@@ -1,6 +1,7 @@
1
1
  export * from './ability.factory.js';
2
2
  export * from './authorization-logger.js';
3
3
  export * from './authorization-logger.interface.js';
4
+ export * from './authorization.module.js';
4
5
  export * from './check-policies.decorator.js';
5
6
  export * from './constants.js';
6
7
  export * from './policies.guard.js';
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./ability.factory.js"), exports);
18
18
  __exportStar(require("./authorization-logger.js"), exports);
19
19
  __exportStar(require("./authorization-logger.interface.js"), exports);
20
+ __exportStar(require("./authorization.module.js"), exports);
20
21
  __exportStar(require("./check-policies.decorator.js"), exports);
21
22
  __exportStar(require("./constants.js"), exports);
22
23
  __exportStar(require("./policies.guard.js"), exports);
@@ -72,6 +72,7 @@ let PoliciesGuard = class PoliciesGuard {
72
72
  exports.PoliciesGuard = PoliciesGuard;
73
73
  exports.PoliciesGuard = PoliciesGuard = __decorate([
74
74
  (0, common_1.Injectable)(),
75
+ __param(0, (0, common_1.Inject)(core_1.Reflector)),
75
76
  __param(1, (0, common_1.Inject)(constants_js_1.ABILITY_FACTORY)),
76
77
  __param(2, (0, common_1.Inject)(constants_js_1.AUTHORIZATION_LOGGER)),
77
78
  __metadata("design:paramtypes", [core_1.Reflector, Function, Object])
@@ -0,0 +1,8 @@
1
+ import type { DynamicModule } from '@nestjs/common';
2
+ import type { AbilityGrantMap } from '../types/ability-grant.js';
3
+ export interface AuthorizationModuleOptionsInterface {
4
+ readonly grants: AbilityGrantMap;
5
+ }
6
+ export declare class AuthorizationModule {
7
+ static forRoot(options: AuthorizationModuleOptionsInterface): DynamicModule;
8
+ }
@@ -0,0 +1,32 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Module } from '@nestjs/common';
8
+ import { APP_GUARD } from '@nestjs/core';
9
+ import { AbilityFactory } from './ability.factory.js';
10
+ import { AuthorizationLogger } from './authorization-logger.js';
11
+ import { ABILITY_FACTORY, ABILITY_GRANTS, AUTHORIZATION_LOGGER } from './constants.js';
12
+ import { PoliciesGuard } from './policies.guard.js';
13
+ let AuthorizationModule = class AuthorizationModule {
14
+ static forRoot(options) {
15
+ return {
16
+ exports: [ABILITY_FACTORY, ABILITY_GRANTS, AbilityFactory],
17
+ module: this,
18
+ providers: [
19
+ AbilityFactory,
20
+ { provide: ABILITY_FACTORY, useExisting: AbilityFactory },
21
+ { provide: ABILITY_GRANTS, useValue: options.grants },
22
+ { provide: AUTHORIZATION_LOGGER, useClass: AuthorizationLogger },
23
+ PoliciesGuard,
24
+ { provide: APP_GUARD, useExisting: PoliciesGuard },
25
+ ],
26
+ };
27
+ }
28
+ };
29
+ AuthorizationModule = __decorate([
30
+ Module({})
31
+ ], AuthorizationModule);
32
+ export { AuthorizationModule };
@@ -1,6 +1,7 @@
1
1
  export * from './ability.factory.js';
2
2
  export * from './authorization-logger.js';
3
3
  export * from './authorization-logger.interface.js';
4
+ export * from './authorization.module.js';
4
5
  export * from './check-policies.decorator.js';
5
6
  export * from './constants.js';
6
7
  export * from './policies.guard.js';
@@ -1,6 +1,7 @@
1
1
  export * from './ability.factory.js';
2
2
  export * from './authorization-logger.js';
3
3
  export * from './authorization-logger.interface.js';
4
+ export * from './authorization.module.js';
4
5
  export * from './check-policies.decorator.js';
5
6
  export * from './constants.js';
6
7
  export * from './policies.guard.js';
@@ -68,6 +68,7 @@ let PoliciesGuard = class PoliciesGuard {
68
68
  };
69
69
  PoliciesGuard = __decorate([
70
70
  Injectable(),
71
+ __param(0, Inject(Reflector)),
71
72
  __param(1, Inject(ABILITY_FACTORY)),
72
73
  __param(2, Inject(AUTHORIZATION_LOGGER)),
73
74
  __metadata("design:paramtypes", [Reflector, Function, Object])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@application-kit/authorization",
3
- "version": "0.0.0",
3
+ "version": "0.2.0",
4
4
  "description": "Авторизация на CASL для NestJS и браузера: реестры subject'ов и ролей, ability из грантов модулей, глобальный guard политик",
5
5
  "keywords": [
6
6
  "authorization",