@elsikora/nestjs-crud-automator 1.16.0-dev.1 → 1.17.0-dev.1
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 +43 -0
- package/dist/cjs/class/api/authorization/engine.class.d.ts +8 -0
- package/dist/cjs/class/api/authorization/engine.class.js +92 -0
- package/dist/cjs/class/api/authorization/engine.class.js.map +1 -0
- package/dist/cjs/class/api/authorization/guard.class.d.ts +13 -0
- package/dist/cjs/class/api/authorization/guard.class.js +79 -0
- package/dist/cjs/class/api/authorization/guard.class.js.map +1 -0
- package/dist/cjs/class/api/authorization/index.d.ts +3 -0
- package/dist/cjs/class/api/authorization/policy/base.class.d.ts +37 -0
- package/dist/cjs/class/api/authorization/policy/base.class.js +68 -0
- package/dist/cjs/class/api/authorization/policy/base.class.js.map +1 -0
- package/dist/cjs/class/api/authorization/policy/discovery-service.class.d.ts +10 -0
- package/dist/cjs/class/api/authorization/policy/discovery-service.class.js +53 -0
- package/dist/cjs/class/api/authorization/policy/discovery-service.class.js.map +1 -0
- package/dist/cjs/class/api/authorization/policy/executor.class.d.ts +8 -0
- package/dist/cjs/class/api/authorization/policy/executor.class.js +43 -0
- package/dist/cjs/class/api/authorization/policy/executor.class.js.map +1 -0
- package/dist/cjs/class/api/authorization/policy/index.d.ts +4 -0
- package/dist/cjs/class/api/authorization/policy/registry.class.d.ts +26 -0
- package/dist/cjs/class/api/authorization/policy/registry.class.js +151 -0
- package/dist/cjs/class/api/authorization/policy/registry.class.js.map +1 -0
- package/dist/cjs/class/api/service-base.class.d.ts +2 -2
- package/dist/cjs/class/api/service-base.class.js.map +1 -1
- package/dist/cjs/class/index.d.ts +1 -0
- package/dist/cjs/constant/authorization/index.d.ts +3 -0
- package/dist/cjs/constant/authorization/metadata/decision.constant.d.ts +3 -0
- package/dist/cjs/constant/authorization/metadata/decision.constant.js +9 -0
- package/dist/cjs/constant/authorization/metadata/decision.constant.js.map +1 -0
- package/dist/cjs/constant/authorization/metadata/index.d.ts +1 -0
- package/dist/cjs/constant/authorization/policy/decorator.constant.d.ts +4 -0
- package/dist/cjs/constant/authorization/policy/decorator.constant.js +11 -0
- package/dist/cjs/constant/authorization/policy/decorator.constant.js.map +1 -0
- package/dist/cjs/constant/authorization/policy/index.d.ts +1 -0
- package/dist/cjs/constant/authorization/token/index.d.ts +1 -0
- package/dist/cjs/constant/authorization/token/registry.constant.d.ts +1 -0
- package/dist/cjs/constant/authorization/token/registry.constant.js +7 -0
- package/dist/cjs/constant/authorization/token/registry.constant.js.map +1 -0
- package/dist/cjs/constant/decorator/api/controller.constant.d.ts +2 -0
- package/dist/cjs/constant/decorator/api/controller.constant.js +4 -0
- package/dist/cjs/constant/decorator/api/controller.constant.js.map +1 -1
- package/dist/cjs/constant/index.d.ts +1 -0
- package/dist/cjs/decorator/api/authorization/index.d.ts +1 -0
- package/dist/cjs/decorator/api/authorization/policy.decorator.d.ts +9 -0
- package/dist/cjs/decorator/api/authorization/policy.decorator.js +25 -0
- package/dist/cjs/decorator/api/authorization/policy.decorator.js.map +1 -0
- package/dist/cjs/decorator/api/controller/index.d.ts +1 -0
- package/dist/cjs/decorator/api/controller/securable.decorator.d.ts +6 -0
- package/dist/cjs/decorator/api/controller/securable.decorator.js +17 -0
- package/dist/cjs/decorator/api/controller/securable.decorator.js.map +1 -0
- package/dist/cjs/decorator/api/index.d.ts +1 -0
- package/dist/cjs/decorator/api/method.decorator.js +7 -1
- package/dist/cjs/decorator/api/method.decorator.js.map +1 -1
- package/dist/cjs/enum/authorization/effect.enum.d.ts +4 -0
- package/dist/cjs/enum/authorization/effect.enum.js +8 -0
- package/dist/cjs/enum/authorization/effect.enum.js.map +1 -0
- package/dist/cjs/enum/authorization/index.d.ts +2 -0
- package/dist/cjs/enum/authorization/policy/index.d.ts +1 -0
- package/dist/cjs/enum/authorization/policy/on-type.enum.d.ts +3 -0
- package/dist/cjs/enum/authorization/policy/on-type.enum.js +7 -0
- package/dist/cjs/enum/authorization/policy/on-type.enum.js.map +1 -0
- package/dist/cjs/enum/index.d.ts +1 -0
- package/dist/cjs/external/tslib/tslib.es6.js +5 -0
- package/dist/cjs/external/tslib/tslib.es6.js.map +1 -1
- package/dist/cjs/factory/api/controller.factory.js +63 -28
- package/dist/cjs/factory/api/controller.factory.js.map +1 -1
- package/dist/cjs/index.js +60 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interface/api-authentication-request.interface.d.ts +3 -0
- package/dist/cjs/interface/authorization/decision.interface.d.ts +17 -0
- package/dist/cjs/interface/authorization/engine.interface.d.ts +6 -0
- package/dist/cjs/interface/authorization/evaluate-options.interface.d.ts +9 -0
- package/dist/cjs/interface/authorization/index.d.ts +7 -0
- package/dist/cjs/interface/authorization/policy/index.d.ts +3 -0
- package/dist/cjs/interface/authorization/policy/interface.d.ts +9 -0
- package/dist/cjs/interface/authorization/policy/registry.interface.d.ts +10 -0
- package/dist/cjs/interface/authorization/policy/subscriber/context.interface.d.ts +9 -0
- package/dist/cjs/interface/authorization/policy/subscriber/index.d.ts +5 -0
- package/dist/cjs/interface/authorization/policy/subscriber/interface.d.ts +14 -0
- package/dist/cjs/interface/authorization/policy/subscriber/properties.interface.d.ts +7 -0
- package/dist/cjs/interface/authorization/policy/subscriber/registration.interface.d.ts +9 -0
- package/dist/cjs/interface/authorization/policy/subscriber/rule.interface.d.ts +13 -0
- package/dist/cjs/interface/authorization/rule/context.interface.d.ts +6 -0
- package/dist/cjs/interface/authorization/rule/index.d.ts +2 -0
- package/dist/cjs/interface/authorization/rule/interface.d.ts +15 -0
- package/dist/cjs/interface/authorization/scope.interface.d.ts +5 -0
- package/dist/cjs/interface/authorization/subject.interface.d.ts +6 -0
- package/dist/cjs/interface/class/api/subscriber/route-execution-context-data.interface.d.ts +7 -1
- package/dist/cjs/interface/index.d.ts +1 -0
- package/dist/cjs/module/api/authorization.module.d.ts +7 -0
- package/dist/cjs/module/api/authorization.module.js +39 -0
- package/dist/cjs/module/api/authorization.module.js.map +1 -0
- package/dist/cjs/module/api/index.d.ts +2 -0
- package/dist/cjs/module/{api-subscriber.module.js → api/subscriber.module.js} +3 -3
- package/dist/cjs/module/api/subscriber.module.js.map +1 -0
- package/dist/cjs/module/index.d.ts +1 -1
- package/dist/cjs/type/class/api/authorization/guard-request.type.d.ts +7 -0
- package/dist/cjs/type/class/api/authorization/index.d.ts +4 -0
- package/dist/cjs/type/class/api/authorization/policy/hook/index.d.ts +2 -0
- package/dist/cjs/type/class/api/authorization/policy/hook/result.type.d.ts +8 -0
- package/dist/cjs/type/class/api/authorization/policy/hook/type.d.ts +5 -0
- package/dist/cjs/type/class/api/authorization/policy/index.d.ts +2 -0
- package/dist/cjs/type/class/api/authorization/policy/policy-subscriber-rule-result.type.d.ts +3 -0
- package/dist/cjs/type/class/api/authorization/rule/condition.type.d.ts +3 -0
- package/dist/cjs/type/class/api/authorization/rule/index.d.ts +4 -0
- package/dist/cjs/type/class/api/authorization/rule/result-transform.type.d.ts +4 -0
- package/dist/cjs/type/class/api/authorization/rule/scope-resolver.type.d.ts +4 -0
- package/dist/cjs/type/class/api/authorization/rule/transform-payload.type.d.ts +3 -0
- package/dist/cjs/type/class/api/authorization/scope-where.type.d.ts +3 -0
- package/dist/cjs/type/class/api/subscriber/route/after/create-context.type.d.ts +1 -1
- package/dist/cjs/type/class/api/subscriber/route/after/delete-context.type.d.ts +1 -1
- package/dist/cjs/type/class/api/subscriber/route/after/get/context.type.d.ts +1 -1
- package/dist/cjs/type/class/api/subscriber/route/after/get/list-context.type.d.ts +2 -1
- package/dist/cjs/type/class/api/subscriber/route/after/get/many-context.type.d.ts +1 -1
- package/dist/cjs/type/class/api/subscriber/route/after/update-context.type.d.ts +1 -1
- package/dist/cjs/type/index.d.ts +1 -0
- package/dist/cjs/utility/api/controller/apply-metadata.utility.js +3 -5
- package/dist/cjs/utility/api/controller/apply-metadata.utility.js.map +1 -1
- package/dist/cjs/utility/authorization/decision/apply-result.utility.d.ts +12 -0
- package/dist/cjs/utility/authorization/decision/apply-result.utility.js +27 -0
- package/dist/cjs/utility/authorization/decision/apply-result.utility.js.map +1 -0
- package/dist/cjs/utility/authorization/decision/attach-resource.utility.d.ts +11 -0
- package/dist/cjs/utility/authorization/decision/attach-resource.utility.js +20 -0
- package/dist/cjs/utility/authorization/decision/attach-resource.utility.js.map +1 -0
- package/dist/cjs/utility/authorization/decision/index.d.ts +3 -0
- package/dist/cjs/utility/authorization/decision/resolve-from-request.utility.d.ts +12 -0
- package/dist/cjs/utility/authorization/decision/resolve-from-request.utility.js +22 -0
- package/dist/cjs/utility/authorization/decision/resolve-from-request.utility.js.map +1 -0
- package/dist/cjs/utility/authorization/index.d.ts +3 -0
- package/dist/cjs/utility/authorization/scope/index.d.ts +1 -0
- package/dist/cjs/utility/authorization/scope/merge/index.d.ts +1 -0
- package/dist/cjs/utility/authorization/scope/merge/where.utility.d.ts +10 -0
- package/dist/cjs/utility/authorization/scope/merge/where.utility.js +32 -0
- package/dist/cjs/utility/authorization/scope/merge/where.utility.js.map +1 -0
- package/dist/cjs/utility/authorization/subject/index.d.ts +1 -0
- package/dist/cjs/utility/authorization/subject/resolve-default-subject.utility.d.ts +7 -0
- package/dist/cjs/utility/authorization/subject/resolve-default-subject.utility.js +52 -0
- package/dist/cjs/utility/authorization/subject/resolve-default-subject.utility.js.map +1 -0
- package/dist/cjs/utility/index.d.ts +1 -0
- package/dist/esm/class/api/authorization/engine.class.d.ts +8 -0
- package/dist/esm/class/api/authorization/engine.class.js +92 -0
- package/dist/esm/class/api/authorization/engine.class.js.map +1 -0
- package/dist/esm/class/api/authorization/guard.class.d.ts +13 -0
- package/dist/esm/class/api/authorization/guard.class.js +79 -0
- package/dist/esm/class/api/authorization/guard.class.js.map +1 -0
- package/dist/esm/class/api/authorization/index.d.ts +3 -0
- package/dist/esm/class/api/authorization/policy/base.class.d.ts +37 -0
- package/dist/esm/class/api/authorization/policy/base.class.js +66 -0
- package/dist/esm/class/api/authorization/policy/base.class.js.map +1 -0
- package/dist/esm/class/api/authorization/policy/discovery-service.class.d.ts +10 -0
- package/dist/esm/class/api/authorization/policy/discovery-service.class.js +53 -0
- package/dist/esm/class/api/authorization/policy/discovery-service.class.js.map +1 -0
- package/dist/esm/class/api/authorization/policy/executor.class.d.ts +8 -0
- package/dist/esm/class/api/authorization/policy/executor.class.js +41 -0
- package/dist/esm/class/api/authorization/policy/executor.class.js.map +1 -0
- package/dist/esm/class/api/authorization/policy/index.d.ts +4 -0
- package/dist/esm/class/api/authorization/policy/registry.class.d.ts +26 -0
- package/dist/esm/class/api/authorization/policy/registry.class.js +148 -0
- package/dist/esm/class/api/authorization/policy/registry.class.js.map +1 -0
- package/dist/esm/class/api/service-base.class.d.ts +2 -2
- package/dist/esm/class/api/service-base.class.js.map +1 -1
- package/dist/esm/class/index.d.ts +1 -0
- package/dist/esm/constant/authorization/index.d.ts +3 -0
- package/dist/esm/constant/authorization/metadata/decision.constant.d.ts +3 -0
- package/dist/esm/constant/authorization/metadata/decision.constant.js +7 -0
- package/dist/esm/constant/authorization/metadata/decision.constant.js.map +1 -0
- package/dist/esm/constant/authorization/metadata/index.d.ts +1 -0
- package/dist/esm/constant/authorization/policy/decorator.constant.d.ts +4 -0
- package/dist/esm/constant/authorization/policy/decorator.constant.js +9 -0
- package/dist/esm/constant/authorization/policy/decorator.constant.js.map +1 -0
- package/dist/esm/constant/authorization/policy/index.d.ts +1 -0
- package/dist/esm/constant/authorization/token/index.d.ts +1 -0
- package/dist/esm/constant/authorization/token/registry.constant.d.ts +1 -0
- package/dist/esm/constant/authorization/token/registry.constant.js +5 -0
- package/dist/esm/constant/authorization/token/registry.constant.js.map +1 -0
- package/dist/esm/constant/decorator/api/controller.constant.d.ts +2 -0
- package/dist/esm/constant/decorator/api/controller.constant.js +4 -0
- package/dist/esm/constant/decorator/api/controller.constant.js.map +1 -1
- package/dist/esm/constant/index.d.ts +1 -0
- package/dist/esm/decorator/api/authorization/index.d.ts +1 -0
- package/dist/esm/decorator/api/authorization/policy.decorator.d.ts +9 -0
- package/dist/esm/decorator/api/authorization/policy.decorator.js +23 -0
- package/dist/esm/decorator/api/authorization/policy.decorator.js.map +1 -0
- package/dist/esm/decorator/api/controller/index.d.ts +1 -0
- package/dist/esm/decorator/api/controller/securable.decorator.d.ts +6 -0
- package/dist/esm/decorator/api/controller/securable.decorator.js +15 -0
- package/dist/esm/decorator/api/controller/securable.decorator.js.map +1 -0
- package/dist/esm/decorator/api/index.d.ts +1 -0
- package/dist/esm/decorator/api/method.decorator.js +7 -1
- package/dist/esm/decorator/api/method.decorator.js.map +1 -1
- package/dist/esm/enum/authorization/effect.enum.d.ts +4 -0
- package/dist/esm/enum/authorization/effect.enum.js +8 -0
- package/dist/esm/enum/authorization/effect.enum.js.map +1 -0
- package/dist/esm/enum/authorization/index.d.ts +2 -0
- package/dist/esm/enum/authorization/policy/index.d.ts +1 -0
- package/dist/esm/enum/authorization/policy/on-type.enum.d.ts +3 -0
- package/dist/esm/enum/authorization/policy/on-type.enum.js +7 -0
- package/dist/esm/enum/authorization/policy/on-type.enum.js.map +1 -0
- package/dist/esm/enum/index.d.ts +1 -0
- package/dist/esm/external/tslib/tslib.es6.js +5 -1
- package/dist/esm/external/tslib/tslib.es6.js.map +1 -1
- package/dist/esm/factory/api/controller.factory.js +63 -28
- package/dist/esm/factory/api/controller.factory.js.map +1 -1
- package/dist/esm/index.js +20 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interface/api-authentication-request.interface.d.ts +3 -0
- package/dist/esm/interface/authorization/decision.interface.d.ts +17 -0
- package/dist/esm/interface/authorization/engine.interface.d.ts +6 -0
- package/dist/esm/interface/authorization/evaluate-options.interface.d.ts +9 -0
- package/dist/esm/interface/authorization/index.d.ts +7 -0
- package/dist/esm/interface/authorization/policy/index.d.ts +3 -0
- package/dist/esm/interface/authorization/policy/interface.d.ts +9 -0
- package/dist/esm/interface/authorization/policy/registry.interface.d.ts +10 -0
- package/dist/esm/interface/authorization/policy/subscriber/context.interface.d.ts +9 -0
- package/dist/esm/interface/authorization/policy/subscriber/index.d.ts +5 -0
- package/dist/esm/interface/authorization/policy/subscriber/interface.d.ts +14 -0
- package/dist/esm/interface/authorization/policy/subscriber/properties.interface.d.ts +7 -0
- package/dist/esm/interface/authorization/policy/subscriber/registration.interface.d.ts +9 -0
- package/dist/esm/interface/authorization/policy/subscriber/rule.interface.d.ts +13 -0
- package/dist/esm/interface/authorization/rule/context.interface.d.ts +6 -0
- package/dist/esm/interface/authorization/rule/index.d.ts +2 -0
- package/dist/esm/interface/authorization/rule/interface.d.ts +15 -0
- package/dist/esm/interface/authorization/scope.interface.d.ts +5 -0
- package/dist/esm/interface/authorization/subject.interface.d.ts +6 -0
- package/dist/esm/interface/class/api/subscriber/route-execution-context-data.interface.d.ts +7 -1
- package/dist/esm/interface/index.d.ts +1 -0
- package/dist/esm/module/api/authorization.module.d.ts +7 -0
- package/dist/esm/module/api/authorization.module.js +39 -0
- package/dist/esm/module/api/authorization.module.js.map +1 -0
- package/dist/esm/module/api/index.d.ts +2 -0
- package/dist/esm/module/{api-subscriber.module.js → api/subscriber.module.js} +3 -3
- package/dist/esm/module/api/subscriber.module.js.map +1 -0
- package/dist/esm/module/index.d.ts +1 -1
- package/dist/esm/type/class/api/authorization/guard-request.type.d.ts +7 -0
- package/dist/esm/type/class/api/authorization/index.d.ts +4 -0
- package/dist/esm/type/class/api/authorization/policy/hook/index.d.ts +2 -0
- package/dist/esm/type/class/api/authorization/policy/hook/result.type.d.ts +8 -0
- package/dist/esm/type/class/api/authorization/policy/hook/type.d.ts +5 -0
- package/dist/esm/type/class/api/authorization/policy/index.d.ts +2 -0
- package/dist/esm/type/class/api/authorization/policy/policy-subscriber-rule-result.type.d.ts +3 -0
- package/dist/esm/type/class/api/authorization/rule/condition.type.d.ts +3 -0
- package/dist/esm/type/class/api/authorization/rule/index.d.ts +4 -0
- package/dist/esm/type/class/api/authorization/rule/result-transform.type.d.ts +4 -0
- package/dist/esm/type/class/api/authorization/rule/scope-resolver.type.d.ts +4 -0
- package/dist/esm/type/class/api/authorization/rule/transform-payload.type.d.ts +3 -0
- package/dist/esm/type/class/api/authorization/scope-where.type.d.ts +3 -0
- package/dist/esm/type/class/api/subscriber/route/after/create-context.type.d.ts +1 -1
- package/dist/esm/type/class/api/subscriber/route/after/delete-context.type.d.ts +1 -1
- package/dist/esm/type/class/api/subscriber/route/after/get/context.type.d.ts +1 -1
- package/dist/esm/type/class/api/subscriber/route/after/get/list-context.type.d.ts +2 -1
- package/dist/esm/type/class/api/subscriber/route/after/get/many-context.type.d.ts +1 -1
- package/dist/esm/type/class/api/subscriber/route/after/update-context.type.d.ts +1 -1
- package/dist/esm/type/index.d.ts +1 -0
- package/dist/esm/utility/api/controller/apply-metadata.utility.js +3 -5
- package/dist/esm/utility/api/controller/apply-metadata.utility.js.map +1 -1
- package/dist/esm/utility/authorization/decision/apply-result.utility.d.ts +12 -0
- package/dist/esm/utility/authorization/decision/apply-result.utility.js +25 -0
- package/dist/esm/utility/authorization/decision/apply-result.utility.js.map +1 -0
- package/dist/esm/utility/authorization/decision/attach-resource.utility.d.ts +11 -0
- package/dist/esm/utility/authorization/decision/attach-resource.utility.js +18 -0
- package/dist/esm/utility/authorization/decision/attach-resource.utility.js.map +1 -0
- package/dist/esm/utility/authorization/decision/index.d.ts +3 -0
- package/dist/esm/utility/authorization/decision/resolve-from-request.utility.d.ts +12 -0
- package/dist/esm/utility/authorization/decision/resolve-from-request.utility.js +20 -0
- package/dist/esm/utility/authorization/decision/resolve-from-request.utility.js.map +1 -0
- package/dist/esm/utility/authorization/index.d.ts +3 -0
- package/dist/esm/utility/authorization/scope/index.d.ts +1 -0
- package/dist/esm/utility/authorization/scope/merge/index.d.ts +1 -0
- package/dist/esm/utility/authorization/scope/merge/where.utility.d.ts +10 -0
- package/dist/esm/utility/authorization/scope/merge/where.utility.js +30 -0
- package/dist/esm/utility/authorization/scope/merge/where.utility.js.map +1 -0
- package/dist/esm/utility/authorization/subject/index.d.ts +1 -0
- package/dist/esm/utility/authorization/subject/resolve-default-subject.utility.d.ts +7 -0
- package/dist/esm/utility/authorization/subject/resolve-default-subject.utility.js +50 -0
- package/dist/esm/utility/authorization/subject/resolve-default-subject.utility.js.map +1 -0
- package/dist/esm/utility/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/cjs/module/api-subscriber.module.js.map +0 -1
- package/dist/esm/module/api-subscriber.module.js.map +0 -1
- /package/dist/cjs/module/{api-subscriber.module.d.ts → api/subscriber.module.d.ts} +0 -0
- /package/dist/esm/module/{api-subscriber.module.d.ts → api/subscriber.module.d.ts} +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ApiSubscriberBase } from '../../subscriber/base.class.js';
|
|
2
|
+
import { EAuthorizationEffect } from '../../../../enum/authorization/effect.enum.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Base class for all authorization policies. It mirrors ApiFunctionSubscriberBase
|
|
6
|
+
* and provides helper methods to create allow/deny rules that are later executed by the policy executor.
|
|
7
|
+
* @template E - Entity type extending IApiBaseEntity
|
|
8
|
+
*/
|
|
9
|
+
class ApiAuthorizationPolicyBase extends ApiSubscriberBase {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an ALLOW rule with optional overrides.
|
|
12
|
+
* @param {Omit<IApiAuthorizationPolicySubscriberRule<E>, "effect">} [rule] - Rule fields to merge.
|
|
13
|
+
* @returns {IApiAuthorizationPolicySubscriberRule<E>} Allow rule.
|
|
14
|
+
*/
|
|
15
|
+
allow(rule = {}) {
|
|
16
|
+
return {
|
|
17
|
+
effect: EAuthorizationEffect.ALLOW,
|
|
18
|
+
...rule,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Helper that creates an allow rule conditioned on the subject having at least one of the provided roles.
|
|
23
|
+
* @param {Array<string>} roles - Roles that grant access.
|
|
24
|
+
* @param {Omit<IApiAuthorizationPolicySubscriberRule<E>, "effect">} [rule] - Optional overrides.
|
|
25
|
+
* @returns {IApiAuthorizationPolicySubscriberRule<E>} Allow rule targeting the given roles.
|
|
26
|
+
*/
|
|
27
|
+
allowForRoles(roles, rule = {}) {
|
|
28
|
+
return this.allow({
|
|
29
|
+
condition: ({ subject }) => roles.some((role) => subject.roles.includes(role)),
|
|
30
|
+
...rule,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates a DENY rule with optional overrides.
|
|
35
|
+
* @param {Omit<IApiAuthorizationPolicySubscriberRule<E>, "effect">} [rule] - Rule fields to merge.
|
|
36
|
+
* @returns {IApiAuthorizationPolicySubscriberRule<E>} Deny rule.
|
|
37
|
+
*/
|
|
38
|
+
deny(rule = {}) {
|
|
39
|
+
return {
|
|
40
|
+
effect: EAuthorizationEffect.DENY,
|
|
41
|
+
...rule,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Helper that scopes data access to the owner identified by a field.
|
|
46
|
+
* Automatically handles relations by using nested id structure.
|
|
47
|
+
* @param {keyof E} [ownerField] - Entity field used to match the subject id, defaults to ownerId.
|
|
48
|
+
* @param {Omit<IApiAuthorizationPolicySubscriberRule<E>, "effect">} [rule] - Optional overrides.
|
|
49
|
+
* @returns {IApiAuthorizationPolicySubscriberRule<E>} Allow rule with owner scope.
|
|
50
|
+
*/
|
|
51
|
+
scopeToOwner(ownerField = "ownerId", rule = {}) {
|
|
52
|
+
return this.allow({
|
|
53
|
+
scope: ({ subject }) => {
|
|
54
|
+
return {
|
|
55
|
+
where: {
|
|
56
|
+
[ownerField]: { id: subject.id },
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
...rule,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { ApiAuthorizationPolicyBase };
|
|
66
|
+
//# sourceMappingURL=base.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.class.js","sources":["../../../../../../../src/class/api/authorization/policy/base.class.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAQA;;;;AAIG;AACG,MAAgB,0BAAqD,SAAQ,iBAAiB,CAAA;AACnG;;;;AAIG;IACO,KAAK,CAAI,OAAoE,EAAiE,EAAA;QACvJ,OAAO;YACN,MAAM,EAAE,oBAAoB,CAAC,KAAK;AAClC,YAAA,GAAG,IAAI;SACP;IACF;AAEA;;;;;AAKG;AACO,IAAA,aAAa,CAAI,KAAoB,EAAE,IAAA,GAAoE,EAAiE,EAAA;QACrL,OAAO,IAAI,CAAC,KAAK,CAAC;YACjB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAmC,KAAK,KAAK,CAAC,IAAI,CAAC,CAAC,IAAY,KAAK,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvH,YAAA,GAAG,IAAI;AACP,SAAA,CAAC;IACH;AAEA;;;;AAIG;IACO,IAAI,CAAI,OAAoE,EAAiE,EAAA;QACtJ,OAAO;YACN,MAAM,EAAE,oBAAoB,CAAC,IAAI;AACjC,YAAA,GAAG,IAAI;SACP;IACF;AAEA;;;;;;AAMG;AACO,IAAA,YAAY,CAAI,UAAA,GAAsB,SAAoB,EAAE,OAAoE,EAAiE,EAAA;QAC1M,OAAO,IAAI,CAAC,KAAK,CAAC;AACjB,YAAA,KAAK,EAAE,CAAC,EAAE,OAAO,EAAmC,KAAI;gBACvD,OAAO;AACN,oBAAA,KAAK,EAAE;wBACN,CAAC,UAAoB,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE;AACnB,qBAAA;iBACxB;YACF,CAAC;AACD,YAAA,GAAG,IAAI;AACP,SAAA,CAAC;IACH;AACA;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { DiscoveryService } from "@nestjs/core";
|
|
3
|
+
import { ApiAuthorizationPolicyRegistry } from './registry.class';
|
|
4
|
+
export declare class ApiAuthorizationPolicyDiscoveryService implements OnModuleInit {
|
|
5
|
+
private readonly discoveryService;
|
|
6
|
+
private readonly registry;
|
|
7
|
+
constructor(discoveryService: DiscoveryService, registry: ApiAuthorizationPolicyRegistry);
|
|
8
|
+
onModuleInit(): void;
|
|
9
|
+
private isPolicyWrapper;
|
|
10
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { __decorate, __metadata } from '../../../../external/tslib/tslib.es6.js';
|
|
2
|
+
import { AUTHORIZATION_POLICY_DECORATOR_CONSTANT } from '../../../../constant/authorization/policy/decorator.constant.js';
|
|
3
|
+
import { Injectable } from '@nestjs/common';
|
|
4
|
+
import { DiscoveryService } from '@nestjs/core';
|
|
5
|
+
import { LoggerUtility } from '../../../../utility/logger.utility.js';
|
|
6
|
+
import { ApiAuthorizationPolicyBase } from './base.class.js';
|
|
7
|
+
import { ApiAuthorizationPolicyRegistry } from './registry.class.js';
|
|
8
|
+
|
|
9
|
+
const policyDiscoveryLogger = LoggerUtility.getLogger("ApiAuthorizationPolicyDiscoveryService");
|
|
10
|
+
let ApiAuthorizationPolicyDiscoveryService = class ApiAuthorizationPolicyDiscoveryService {
|
|
11
|
+
discoveryService;
|
|
12
|
+
registry;
|
|
13
|
+
constructor(discoveryService, registry) {
|
|
14
|
+
this.discoveryService = discoveryService;
|
|
15
|
+
this.registry = registry;
|
|
16
|
+
}
|
|
17
|
+
onModuleInit() {
|
|
18
|
+
policyDiscoveryLogger.verbose("Starting authorization policy discovery...");
|
|
19
|
+
const providers = this.discoveryService.getProviders();
|
|
20
|
+
const policyProviders = providers.filter((wrapper) => this.isPolicyWrapper(wrapper));
|
|
21
|
+
for (const wrapper of policyProviders) {
|
|
22
|
+
if (!wrapper.metatype) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const metadata = Reflect.getMetadata(AUTHORIZATION_POLICY_DECORATOR_CONSTANT.METADATA_KEY, wrapper.metatype);
|
|
26
|
+
const properties = metadata;
|
|
27
|
+
if (!properties) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const policyId = properties.policyId ?? `${properties.entity.name?.toLowerCase() ?? "unknown"}${AUTHORIZATION_POLICY_DECORATOR_CONSTANT.DEFAULT_POLICY_ID_SUFFIX}`;
|
|
31
|
+
this.registry.registerSubscriber({
|
|
32
|
+
description: properties.description,
|
|
33
|
+
entity: properties.entity,
|
|
34
|
+
policyId,
|
|
35
|
+
priority: properties.priority ?? 0,
|
|
36
|
+
subscriber: wrapper.instance,
|
|
37
|
+
});
|
|
38
|
+
policyDiscoveryLogger.verbose(`Registered authorization policy ${wrapper.name ?? properties.entity.name ?? "UnknownPolicy"} for entity ${properties.entity.name ?? "UnknownEntity"} with priority ${properties.priority ?? 0}`);
|
|
39
|
+
}
|
|
40
|
+
policyDiscoveryLogger.verbose(`Authorization policy discovery finished. Registered ${policyProviders.length} providers.`);
|
|
41
|
+
}
|
|
42
|
+
isPolicyWrapper(wrapper) {
|
|
43
|
+
return Boolean(wrapper.instance && wrapper.metatype && wrapper.instance instanceof ApiAuthorizationPolicyBase && Reflect.hasMetadata(AUTHORIZATION_POLICY_DECORATOR_CONSTANT.METADATA_KEY, wrapper.metatype));
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
ApiAuthorizationPolicyDiscoveryService = __decorate([
|
|
47
|
+
Injectable(),
|
|
48
|
+
__metadata("design:paramtypes", [DiscoveryService,
|
|
49
|
+
ApiAuthorizationPolicyRegistry])
|
|
50
|
+
], ApiAuthorizationPolicyDiscoveryService);
|
|
51
|
+
|
|
52
|
+
export { ApiAuthorizationPolicyDiscoveryService };
|
|
53
|
+
//# sourceMappingURL=discovery-service.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discovery-service.class.js","sources":["../../../../../../../src/class/api/authorization/policy/discovery-service.class.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;AAYA,MAAM,qBAAqB,GAAkB,aAAa,CAA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qB,CAAC,OAAO,CAAC,CAAA,gCAAA,EAAmC,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,eAAe,CAAA,YAAA,EAAe,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,eAAe,CAAA,eAAA,EAAkB,UAAU,CAAC,QAAQ,IAAI,CAAC,CAAA,CAAE,CAAC;QAChO;QAEA,qBAAqB,CAAC,OAAO,CAAC,CAAA,oDAAA,EAAuD,eAAe,CAAC,MAAM,CAAA,WAAA,CAAa,CAAC;IAC1H;AAEQ,IAAA,eAAe,CAAC,OAAwB,EAAA;AAC/C,QAAA,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,YAAY,0BAA0B,IAAI,OAAO,CAAC,WAAW,CAAC,uCAAuC,CAAC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9M;;AAzCY,sCAAsC,GAAA,UAAA,CAAA;AADlD,IAAA,UAAU,EAAE;qCAGwB,gBAAgB;QACxB,8BAA8B,CAAA;AAH9C,CAAA,EAAA,sCAAsC,CA0ClD;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IApiBaseEntity } from '../../../../interface/api-base-entity.interface';
|
|
2
|
+
import type { IApiAuthorizationPolicySubscriber, IApiAuthorizationPolicySubscriberContext, IApiAuthorizationPolicySubscriberRule } from '../../../../interface/authorization/policy/subscriber/index';
|
|
3
|
+
import type { TApiAuthorizationPolicyHookResult } from '../../../../type/class/api/authorization/policy/hook/index';
|
|
4
|
+
export declare class ApiAuthorizationPolicyExecutor {
|
|
5
|
+
static execute<E extends IApiBaseEntity, TAction extends string>(subscriber: IApiAuthorizationPolicySubscriber<E>, action: TAction, context: IApiAuthorizationPolicySubscriberContext<E>): Promise<Array<IApiAuthorizationPolicySubscriberRule<E, TApiAuthorizationPolicyHookResult<TAction, E>>>>;
|
|
6
|
+
private static normalizeRuleResult;
|
|
7
|
+
private static resolveRouteType;
|
|
8
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { EApiAuthorizationPolicyOnType } from '../../../../enum/authorization/policy/on-type.enum.js';
|
|
2
|
+
import { EApiRouteType } from '../../../../enum/decorator/api/route-type.enum.js';
|
|
3
|
+
import { CapitalizeString } from '../../../../utility/capitalize-string.utility.js';
|
|
4
|
+
import { LoggerUtility } from '../../../../utility/logger.utility.js';
|
|
5
|
+
|
|
6
|
+
const policyExecutorLogger = LoggerUtility.getLogger("ApiAuthorizationPolicyExecutor");
|
|
7
|
+
class ApiAuthorizationPolicyExecutor {
|
|
8
|
+
static async execute(subscriber, action, context) {
|
|
9
|
+
const routeType = context.routeType ?? this.resolveRouteType(action);
|
|
10
|
+
if (routeType) {
|
|
11
|
+
const hookName = `on${EApiAuthorizationPolicyOnType.BEFORE}${CapitalizeString(routeType)}`;
|
|
12
|
+
const hook = subscriber[hookName];
|
|
13
|
+
if (typeof hook === "function") {
|
|
14
|
+
policyExecutorLogger.verbose(`Executing authorization policy hook ${hookName} from ${subscriber.constructor.name} for action "${action}"`);
|
|
15
|
+
const typedHook = hook;
|
|
16
|
+
const result = typedHook.call(subscriber, context);
|
|
17
|
+
return this.normalizeRuleResult(await result);
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
if (typeof subscriber.getCustomActionRule !== "function") {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const customActionHook = subscriber.getCustomActionRule.bind(subscriber);
|
|
25
|
+
const customResult = customActionHook(action, context);
|
|
26
|
+
return this.normalizeRuleResult(await customResult);
|
|
27
|
+
}
|
|
28
|
+
static normalizeRuleResult(result) {
|
|
29
|
+
if (Array.isArray(result)) {
|
|
30
|
+
return result.filter((rule) => rule != null);
|
|
31
|
+
}
|
|
32
|
+
return result ? [result] : [];
|
|
33
|
+
}
|
|
34
|
+
static resolveRouteType(action) {
|
|
35
|
+
const routeTypes = Object.values(EApiRouteType);
|
|
36
|
+
return routeTypes.find((routeType) => routeType === action);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { ApiAuthorizationPolicyExecutor };
|
|
41
|
+
//# sourceMappingURL=executor.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.class.js","sources":["../../../../../../../src/class/api/authorization/policy/executor.class.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAUA,MAAM,oBAAoB,GAAkB,aAAa,CAAC,SAAS,CAAC,gCAAgC,CAAC;MAIxF,8BAA8B,CAAA;IACnC,aAAa,OAAO,CAAmD,UAAgD,EAAE,MAAe,EAAE,OAAoD,EAAA;AACpM,QAAA,MAAM,SAAS,GAA8B,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;QAE/F,IAAI,SAAS,EAAE;AACd,YAAA,MAAM,QAAQ,GAAW,CAAA,EAAA,EAAK,6BAA6B,CAAC,MAAM,CAAA,EAAG,gBAAgB,CAAC,SAAS,CAAC,CAAA,CAAE;AAClG,YAAA,MAAM,IAAI,GAAY,UAAU,CAAC,QAAsD,CAAC;AAExF,YAAA,IAAI,OAAO,IAAI,KAAK,UAAU,EAAE;AAC/B,gBAAA,oBAAoB,CAAC,OAAO,CAAC,CAAA,oCAAA,EAAuC,QAAQ,CAAA,MAAA,EAAS,UAAU,CAAC,WAAW,CAAC,IAAI,CAAA,aAAA,EAAgB,MAAM,CAAA,CAAA,CAAG,CAAC;gBAC1I,MAAM,SAAS,GAAqH,IAAwH;gBAC5P,MAAM,MAAM,GAA2D,SAAS,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC;AAE1G,gBAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,MAAM,CAAC;YAC9C;AAEA,YAAA,OAAO,EAAE;QACV;AAEA,QAAA,IAAI,OAAO,UAAU,CAAC,mBAAmB,KAAK,UAAU,EAAE;AACzD,YAAA,OAAO,EAAE;QACV;QAEA,MAAM,gBAAgB,GAA+I,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAA+I;QAElW,MAAM,YAAY,GAA2D,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC;AAE9G,QAAA,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,YAAY,CAAC;IACpD;IAEQ,OAAO,mBAAmB,CAA8B,MAAyD,EAAA;AACxH,QAAA,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AAC1B,YAAA,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,IAAoE,KAA0D,IAAI,IAAI,IAAI,CAAC;QAClK;QAEA,OAAO,MAAM,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE;IAC9B;IAEQ,OAAO,gBAAgB,CAAC,MAAc,EAAA;QAC7C,MAAM,UAAU,GAAkB,MAAM,CAAC,MAAM,CAAC,aAAa,CAAkB;AAE/E,QAAA,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,SAAiB,KAAK,SAAS,KAAK,MAAM,CAA8B;IACjG;AACA;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ApiAuthorizationPolicyBase } from './base.class';
|
|
2
|
+
export { ApiAuthorizationPolicyDiscoveryService } from './discovery-service.class';
|
|
3
|
+
export { ApiAuthorizationPolicyExecutor } from './executor.class';
|
|
4
|
+
export { ApiAuthorizationPolicyRegistry } from './registry.class';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IApiBaseEntity } from '../../../../interface/api-base-entity.interface';
|
|
2
|
+
import type { IApiAuthorizationPolicy, IApiAuthorizationPolicyRegistry, IApiAuthorizationPolicySubscriberRegistration } from '../../../../interface/authorization/index';
|
|
3
|
+
import type { TApiAuthorizationPolicyHookResult } from '../../../../type/class/api/authorization/policy/hook/index';
|
|
4
|
+
type TEntityConstructor<E extends IApiBaseEntity> = new () => E;
|
|
5
|
+
export declare class ApiAuthorizationPolicyRegistry implements IApiAuthorizationPolicyRegistry {
|
|
6
|
+
private readonly LEGACY_POLICIES;
|
|
7
|
+
private readonly POLICY_CACHE;
|
|
8
|
+
private readonly POLICY_REGISTRATIONS_BY_ENTITY;
|
|
9
|
+
private readonly POLICY_REGISTRATIONS_BY_ID;
|
|
10
|
+
constructor();
|
|
11
|
+
buildAggregatedPolicy<E extends IApiBaseEntity, TAction extends string>(entity: TEntityConstructor<E>, action: TAction): Promise<IApiAuthorizationPolicy<E, TApiAuthorizationPolicyHookResult<TAction, E>> | undefined>;
|
|
12
|
+
clear(): void;
|
|
13
|
+
registerPolicy<E extends IApiBaseEntity, R>(policy: IApiAuthorizationPolicy<E, R>): void;
|
|
14
|
+
registerSubscriber<E extends IApiBaseEntity>(registration: IApiAuthorizationPolicySubscriberRegistration<E>): void;
|
|
15
|
+
private cachePolicy;
|
|
16
|
+
private createCacheKey;
|
|
17
|
+
private getEntityName;
|
|
18
|
+
private invalidateCacheForEntity;
|
|
19
|
+
private normalizeRule;
|
|
20
|
+
private resolvePolicyId;
|
|
21
|
+
private resolveRouteType;
|
|
22
|
+
private setLegacyPolicy;
|
|
23
|
+
private toBasePolicy;
|
|
24
|
+
}
|
|
25
|
+
export declare const apiAuthorizationPolicyRegistry: ApiAuthorizationPolicyRegistry;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { AUTHORIZATION_POLICY_DECORATOR_CONSTANT } from '../../../../constant/authorization/policy/decorator.constant.js';
|
|
2
|
+
import { EApiRouteType } from '../../../../enum/decorator/api/route-type.enum.js';
|
|
3
|
+
import { GenerateEntityInformation } from '../../../../utility/generate-entity-information.utility.js';
|
|
4
|
+
import { LoggerUtility } from '../../../../utility/logger.utility.js';
|
|
5
|
+
import { ApiAuthorizationPolicyExecutor } from './executor.class.js';
|
|
6
|
+
|
|
7
|
+
const policyRegistryLogger = LoggerUtility.getLogger("ApiAuthorizationPolicyRegistry");
|
|
8
|
+
class ApiAuthorizationPolicyRegistry {
|
|
9
|
+
LEGACY_POLICIES;
|
|
10
|
+
POLICY_CACHE;
|
|
11
|
+
POLICY_REGISTRATIONS_BY_ENTITY;
|
|
12
|
+
POLICY_REGISTRATIONS_BY_ID;
|
|
13
|
+
constructor() {
|
|
14
|
+
this.LEGACY_POLICIES = new Map();
|
|
15
|
+
this.POLICY_CACHE = new Map();
|
|
16
|
+
this.POLICY_REGISTRATIONS_BY_ENTITY = new Map();
|
|
17
|
+
this.POLICY_REGISTRATIONS_BY_ID = new Map();
|
|
18
|
+
}
|
|
19
|
+
async buildAggregatedPolicy(entity, action) {
|
|
20
|
+
const entityName = this.getEntityName(entity);
|
|
21
|
+
const cacheKey = this.createCacheKey(entity, action);
|
|
22
|
+
policyRegistryLogger.debug(`Building aggregated policy for entity "${entityName}" action "${action}" (cache key: ${cacheKey})`);
|
|
23
|
+
const cachedPolicy = this.POLICY_CACHE.get(cacheKey);
|
|
24
|
+
if (cachedPolicy) {
|
|
25
|
+
policyRegistryLogger.debug(`Returning cached policy for "${cacheKey}"`);
|
|
26
|
+
return cachedPolicy;
|
|
27
|
+
}
|
|
28
|
+
const legacyPolicy = this.LEGACY_POLICIES.get(cacheKey);
|
|
29
|
+
if (legacyPolicy) {
|
|
30
|
+
policyRegistryLogger.debug(`Returning legacy policy for "${cacheKey}"`);
|
|
31
|
+
this.cachePolicy(cacheKey, legacyPolicy);
|
|
32
|
+
return legacyPolicy;
|
|
33
|
+
}
|
|
34
|
+
const registrations = this.POLICY_REGISTRATIONS_BY_ENTITY.get(entityName);
|
|
35
|
+
policyRegistryLogger.debug(`Found ${registrations?.length ?? 0} registration(s) for entity "${entityName}"`);
|
|
36
|
+
policyRegistryLogger.debug(`All registered entities: [${[...this.POLICY_REGISTRATIONS_BY_ENTITY.keys()].join(", ")}]`);
|
|
37
|
+
if (!registrations?.length) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const entityMetadata = GenerateEntityInformation(entity);
|
|
41
|
+
const routeType = this.resolveRouteType(action);
|
|
42
|
+
const aggregatedRules = [];
|
|
43
|
+
for (const registration of registrations) {
|
|
44
|
+
const context = {
|
|
45
|
+
action,
|
|
46
|
+
entity,
|
|
47
|
+
entityMetadata,
|
|
48
|
+
routeType,
|
|
49
|
+
};
|
|
50
|
+
const rules = await ApiAuthorizationPolicyExecutor.execute(registration.subscriber, action, context);
|
|
51
|
+
if (rules.length === 0) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const normalizedRules = rules.map((rule) => this.normalizeRule(registration.policyId, registration.priority ?? 0, rule, action));
|
|
55
|
+
aggregatedRules.push(...normalizedRules);
|
|
56
|
+
}
|
|
57
|
+
if (aggregatedRules.length === 0) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
aggregatedRules.sort((a, b) => b.priority - a.priority);
|
|
61
|
+
const policyDescription = registrations.find((registration) => Boolean(registration.description))?.description;
|
|
62
|
+
const policy = {
|
|
63
|
+
action,
|
|
64
|
+
description: policyDescription,
|
|
65
|
+
entity,
|
|
66
|
+
policyId: this.resolvePolicyId(entity),
|
|
67
|
+
rules: aggregatedRules,
|
|
68
|
+
};
|
|
69
|
+
this.cachePolicy(cacheKey, policy);
|
|
70
|
+
return policy;
|
|
71
|
+
}
|
|
72
|
+
clear() {
|
|
73
|
+
this.LEGACY_POLICIES.clear();
|
|
74
|
+
this.POLICY_CACHE.clear();
|
|
75
|
+
this.POLICY_REGISTRATIONS_BY_ENTITY.clear();
|
|
76
|
+
this.POLICY_REGISTRATIONS_BY_ID.clear();
|
|
77
|
+
}
|
|
78
|
+
registerPolicy(policy) {
|
|
79
|
+
const cacheKey = this.createCacheKey(policy.entity, policy.action);
|
|
80
|
+
this.setLegacyPolicy(cacheKey, policy);
|
|
81
|
+
}
|
|
82
|
+
registerSubscriber(registration) {
|
|
83
|
+
const normalizedRegistration = {
|
|
84
|
+
description: registration.description,
|
|
85
|
+
entity: registration.entity,
|
|
86
|
+
policyId: registration.policyId,
|
|
87
|
+
priority: registration.priority ?? 0,
|
|
88
|
+
subscriber: registration.subscriber,
|
|
89
|
+
};
|
|
90
|
+
const entityName = this.getEntityName(normalizedRegistration.entity);
|
|
91
|
+
policyRegistryLogger.verbose(`Registering policy subscriber for entity "${entityName}" with policyId "${normalizedRegistration.policyId}" and priority ${normalizedRegistration.priority}`);
|
|
92
|
+
this.POLICY_REGISTRATIONS_BY_ID.set(normalizedRegistration.policyId, normalizedRegistration);
|
|
93
|
+
const entityRegistrations = this.POLICY_REGISTRATIONS_BY_ENTITY.get(entityName) ?? [];
|
|
94
|
+
entityRegistrations.push(normalizedRegistration);
|
|
95
|
+
entityRegistrations.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
96
|
+
this.POLICY_REGISTRATIONS_BY_ENTITY.set(entityName, entityRegistrations);
|
|
97
|
+
policyRegistryLogger.debug(`Total registrations for entity "${entityName}": ${entityRegistrations.length}`);
|
|
98
|
+
this.invalidateCacheForEntity(entityName);
|
|
99
|
+
}
|
|
100
|
+
cachePolicy(cacheKey, policy) {
|
|
101
|
+
this.POLICY_CACHE.set(cacheKey, this.toBasePolicy(policy));
|
|
102
|
+
}
|
|
103
|
+
createCacheKey(entity, action) {
|
|
104
|
+
return `${this.getEntityName(entity)}::${action.toLowerCase()}`;
|
|
105
|
+
}
|
|
106
|
+
getEntityName(entity) {
|
|
107
|
+
return (entity.name ?? "UnknownResource").toLowerCase();
|
|
108
|
+
}
|
|
109
|
+
invalidateCacheForEntity(entityName) {
|
|
110
|
+
for (const cacheKey of this.POLICY_CACHE.keys()) {
|
|
111
|
+
if (cacheKey.startsWith(`${entityName}::`)) {
|
|
112
|
+
this.POLICY_CACHE.delete(cacheKey);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
normalizeRule(policyId, subscriberPriority, rule, action) {
|
|
117
|
+
const rulePriority = rule.priority ?? 0;
|
|
118
|
+
return {
|
|
119
|
+
action,
|
|
120
|
+
condition: rule.condition,
|
|
121
|
+
description: rule.description,
|
|
122
|
+
effect: rule.effect,
|
|
123
|
+
policyId,
|
|
124
|
+
priority: subscriberPriority + rulePriority,
|
|
125
|
+
resultTransform: rule.resultTransform,
|
|
126
|
+
scope: rule.scope,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
resolvePolicyId(entity) {
|
|
130
|
+
return `${this.getEntityName(entity)}${AUTHORIZATION_POLICY_DECORATOR_CONSTANT.DEFAULT_POLICY_ID_SUFFIX}`;
|
|
131
|
+
}
|
|
132
|
+
resolveRouteType(action) {
|
|
133
|
+
const routeTypes = Object.values(EApiRouteType);
|
|
134
|
+
return routeTypes.find((routeType) => routeType === action);
|
|
135
|
+
}
|
|
136
|
+
setLegacyPolicy(cacheKey, policy) {
|
|
137
|
+
const normalizedPolicy = this.toBasePolicy(policy);
|
|
138
|
+
this.LEGACY_POLICIES.set(cacheKey, normalizedPolicy);
|
|
139
|
+
this.POLICY_CACHE.set(cacheKey, normalizedPolicy);
|
|
140
|
+
}
|
|
141
|
+
toBasePolicy(policy) {
|
|
142
|
+
return policy;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const apiAuthorizationPolicyRegistry = new ApiAuthorizationPolicyRegistry();
|
|
146
|
+
|
|
147
|
+
export { ApiAuthorizationPolicyRegistry, apiAuthorizationPolicyRegistry };
|
|
148
|
+
//# sourceMappingURL=registry.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.class.js","sources":["../../../../../../../src/class/api/authorization/policy/registry.class.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAYA,MAAM,oBAAoB,GAAkB,aAAa,CAAC,SAAS,CAAC,gCAAgC,CAAC;MAIxF,8BAA8B,CAAA;AACzB,IAAA,eAAe;AAEf,IAAA,YAAY;AAEZ,IAAA,8BAA8B;AAE9B,IAAA,0BAA0B;AAE3C,IAAA,WAAA,GAAA;AACC,QAAA,IAAI,CAAC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AAqC,EAAA;AACtF,QAAA,OAAO,MAAqE;IAC7E;AACA;AAEM,MAAM,8BAA8B,GAAmC,IAAI,8BAA8B;;;;"}
|
|
@@ -8,9 +8,9 @@ import type { EntityManager } from "typeorm";
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class ApiServiceBase<E> {
|
|
10
10
|
create(properties: TApiFunctionCreateProperties<E>, eventManager?: EntityManager): Promise<E>;
|
|
11
|
-
delete(criteria: TApiFunctionDeleteCriteria<E>, eventManager?: EntityManager): Promise<void>;
|
|
11
|
+
delete(criteria: Array<TApiFunctionDeleteCriteria<E>> | TApiFunctionDeleteCriteria<E>, eventManager?: EntityManager): Promise<void>;
|
|
12
12
|
get(properties: TApiFunctionGetProperties<E>, eventManager?: EntityManager): Promise<E>;
|
|
13
13
|
getList(properties: TApiFunctionGetListProperties<E>, eventManager?: EntityManager): Promise<IApiGetListResponseResult<E>>;
|
|
14
14
|
getMany(properties: TApiFunctionGetManyProperties<E>, eventManager?: EntityManager): Promise<Array<E>>;
|
|
15
|
-
update(criteria: TApiFunctionUpdateCriteria<E>, properties: TApiFunctionUpdateProperties<E>, eventManager?: EntityManager): Promise<E>;
|
|
15
|
+
update(criteria: Array<TApiFunctionUpdateCriteria<E>> | TApiFunctionUpdateCriteria<E>, properties: TApiFunctionUpdateProperties<E>, eventManager?: EntityManager): Promise<E>;
|
|
16
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-base.class.js","sources":["../../../../../src/class/api/service-base.class.ts"],"sourcesContent":[null],"names":[],"mappings":"AAKA;;;;AAIG;MACU,cAAc,CAAA;IAC1B,MAAM,CAAC,UAA2C,EAAE,YAA4B,EAAA;AAI/E,QAAA,OAAO,OAAO,CAAC,OAAO,CAAC,EAAO,CAAC;IAChC;IAEA,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"service-base.class.js","sources":["../../../../../src/class/api/service-base.class.ts"],"sourcesContent":[null],"names":[],"mappings":"AAKA;;;;AAIG;MACU,cAAc,CAAA;IAC1B,MAAM,CAAC,UAA2C,EAAE,YAA4B,EAAA;AAI/E,QAAA,OAAO,OAAO,CAAC,OAAO,CAAC,EAAO,CAAC;IAChC;IAEA,MAAM,CAAC,QAA8E,EAAE,YAA4B,EAAA;AAIlH,QAAA,OAAO,OAAO,CAAC,OAAO,EAAE;IACzB;;IAGA,GAAG,CAAC,UAAwC,EAAE,YAA4B,EAAA;AAIzE,QAAA,OAAO,OAAO,CAAC,OAAO,CAAC,EAAO,CAAC;IAChC;IAEA,OAAO,CAAC,UAA4C,EAAE,YAA4B,EAAA;AAIjF,QAAA,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAA6C,CAAC;IAC3F;IAEA,OAAO,CAAC,UAA4C,EAAE,YAA4B,EAAA;AAIjF,QAAA,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3B;AAEA,IAAA,MAAM,CAAC,QAA8E,EAAE,UAA2C,EAAE,YAA4B,EAAA;AAK/J,QAAA,OAAO,OAAO,CAAC,OAAO,CAAC,EAAO,CAAC;IAChC;AACA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision.constant.js","sources":["../../../../../../src/constant/authorization/metadata/decision.constant.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAM,oBAAoB,GAAW,4BAA4B;AAE1D,MAAM,wCAAwC,GAEjD;AACH,IAAA,WAAW,EAAE,oBAAoB;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AUTHORIZATION_DECISION_METADATA_CONSTANT } from './decision.constant';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const POLICY_METADATA_KEY = "API_AUTHORIZATION_POLICY_METADATA_KEY";
|
|
2
|
+
const DEFAULT_POLICY_ID_SUFFIX = ".authorization.policy";
|
|
3
|
+
const AUTHORIZATION_POLICY_DECORATOR_CONSTANT = {
|
|
4
|
+
DEFAULT_POLICY_ID_SUFFIX,
|
|
5
|
+
METADATA_KEY: POLICY_METADATA_KEY,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { AUTHORIZATION_POLICY_DECORATOR_CONSTANT };
|
|
9
|
+
//# sourceMappingURL=decorator.constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.constant.js","sources":["../../../../../../src/constant/authorization/policy/decorator.constant.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAM,mBAAmB,GAAW,uCAAuC;AAC3E,MAAM,wBAAwB,GAAW,uBAAuB;AAEzD,MAAM,uCAAuC,GAGhD;IACH,wBAAwB;AACxB,IAAA,YAAY,EAAE,mBAAmB;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AUTHORIZATION_POLICY_DECORATOR_CONSTANT } from './decorator.constant';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AUTHORIZATION_POLICY_REGISTRY_TOKEN } from './registry.constant';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AUTHORIZATION_POLICY_REGISTRY_TOKEN: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.constant.js","sources":["../../../../../../src/constant/authorization/token/registry.constant.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAM,qBAAqB,GAAW,mCAAmC;AAElE,MAAM,mCAAmC,GAAW;;;;"}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
const RESERVED_METHOD_PREFIX = "";
|
|
2
2
|
const OBSERVABLE_METADATA_KEY = "API_CONTROLLER_OBSERVABLE_METADATA_KEY";
|
|
3
|
+
const SECURABLE_METADATA_KEY = "API_CONTROLLER_SECURABLE_METADATA_KEY";
|
|
4
|
+
const ENTITY_METADATA_KEY = "API_CONTROLLER_ENTITY_METADATA_KEY";
|
|
3
5
|
const CONTROLLER_API_DECORATOR_CONSTANT = {
|
|
6
|
+
ENTITY_METADATA_KEY,
|
|
4
7
|
OBSERVABLE_METADATA_KEY,
|
|
5
8
|
RESERVED_METHOD_PREFIX,
|
|
9
|
+
SECURABLE_METADATA_KEY,
|
|
6
10
|
};
|
|
7
11
|
|
|
8
12
|
export { CONTROLLER_API_DECORATOR_CONSTANT };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.constant.js","sources":["../../../../../../src/constant/decorator/api/controller.constant.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAW,EAAE;AACzC,MAAM,uBAAuB,GAAW,wCAAwC;
|
|
1
|
+
{"version":3,"file":"controller.constant.js","sources":["../../../../../../src/constant/decorator/api/controller.constant.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAW,EAAE;AACzC,MAAM,uBAAuB,GAAW,wCAAwC;AAChF,MAAM,sBAAsB,GAAW,uCAAuC;AAC9E,MAAM,mBAAmB,GAAW,oCAAoC;AAEjE,MAAM,iCAAiC,GAK1C;IACH,mBAAmB;IACnB,uBAAuB;IACvB,sBAAsB;IACtB,sBAAsB;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ApiAuthorizationPolicy } from './policy.decorator';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { IApiBaseEntity } from '../../../interface/api-base-entity.interface';
|
|
2
|
+
import type { IApiAuthorizationPolicySubscriberProperties } from '../../../interface/authorization/policy/subscriber/properties.interface';
|
|
3
|
+
/**
|
|
4
|
+
* Decorator that registers a class as an authorization policy for a specific entity.
|
|
5
|
+
* @template E - Entity type extending IApiBaseEntity
|
|
6
|
+
* @param {IApiAuthorizationPolicySubscriberProperties<E>} properties - Policy properties.
|
|
7
|
+
* @returns {ClassDecorator} Class decorator registering metadata for discovery.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ApiAuthorizationPolicy<E extends IApiBaseEntity>(properties: IApiAuthorizationPolicySubscriberProperties<E>): ClassDecorator;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AUTHORIZATION_POLICY_DECORATOR_CONSTANT } from '../../../constant/authorization/policy/decorator.constant.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decorator that registers a class as an authorization policy for a specific entity.
|
|
5
|
+
* @template E - Entity type extending IApiBaseEntity
|
|
6
|
+
* @param {IApiAuthorizationPolicySubscriberProperties<E>} properties - Policy properties.
|
|
7
|
+
* @returns {ClassDecorator} Class decorator registering metadata for discovery.
|
|
8
|
+
*/
|
|
9
|
+
function ApiAuthorizationPolicy(properties) {
|
|
10
|
+
const normalizedPolicyId = properties.policyId ?? `${properties.entity.name?.toLowerCase() ?? "unknown"}${AUTHORIZATION_POLICY_DECORATOR_CONSTANT.DEFAULT_POLICY_ID_SUFFIX}`;
|
|
11
|
+
const metadata = {
|
|
12
|
+
description: properties.description,
|
|
13
|
+
entity: properties.entity,
|
|
14
|
+
policyId: normalizedPolicyId,
|
|
15
|
+
priority: properties.priority ?? 0,
|
|
16
|
+
};
|
|
17
|
+
return (target) => {
|
|
18
|
+
Reflect.defineMetadata(AUTHORIZATION_POLICY_DECORATOR_CONSTANT.METADATA_KEY, metadata, target);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { ApiAuthorizationPolicy };
|
|
23
|
+
//# sourceMappingURL=policy.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.decorator.js","sources":["../../../../../../src/decorator/api/authorization/policy.decorator.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA;;;;;AAKG;AACG,SAAU,sBAAsB,CAA2B,UAA0D,EAAA;IAC1H,MAAM,kBAAkB,GAAW,UAAU,CAAC,QAAQ,IAAI,CAAA,EAAG,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,SAAS,GAAG,uCAAuC,CAAC,wBAAwB,CAAA,CAAE;AAEpL,IAAA,MAAM,QAAQ,GAAmD;QAChE,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,MAAM,EAAE,UAAU,CAAC,MAAM;AACzB,QAAA,QAAQ,EAAE,kBAAkB;AAC5B,QAAA,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,CAAC;KAClC;IAED,OAAO,CAAC,MAAc,KAAI;QACzB,OAAO,CAAC,cAAc,CAAC,uCAAuC,CAAC,YAAY,EAAE,QAAQ,EAAE,MAAM,CAAC;AAC/F,IAAA,CAAC;AACF;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decorator that marks a controller as securable, enabling automatic RBAC guard application.
|
|
3
|
+
* Without this decorator the authorization guard short-circuits and controller methods remain unsecured.
|
|
4
|
+
* @returns {ClassDecorator} Class decorator that enables authorization for the controller.
|
|
5
|
+
*/
|
|
6
|
+
export declare function ApiControllerSecurable(): ClassDecorator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CONTROLLER_API_DECORATOR_CONSTANT } from '../../../constant/decorator/api/controller.constant.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decorator that marks a controller as securable, enabling automatic RBAC guard application.
|
|
5
|
+
* Without this decorator the authorization guard short-circuits and controller methods remain unsecured.
|
|
6
|
+
* @returns {ClassDecorator} Class decorator that enables authorization for the controller.
|
|
7
|
+
*/
|
|
8
|
+
function ApiControllerSecurable() {
|
|
9
|
+
return (target) => {
|
|
10
|
+
Reflect.defineMetadata(CONTROLLER_API_DECORATOR_CONSTANT.SECURABLE_METADATA_KEY, true, target);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { ApiControllerSecurable };
|
|
15
|
+
//# sourceMappingURL=securable.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"securable.decorator.js","sources":["../../../../../../src/decorator/api/controller/securable.decorator.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;AAIG;SACa,sBAAsB,GAAA;IACrC,OAAO,CAAC,MAAc,KAAI;QACzB,OAAO,CAAC,cAAc,CAAC,iCAAiC,CAAC,sBAAsB,EAAE,IAAI,EAAE,MAAM,CAAC;AAC/F,IAAA,CAAC;AACF;;;;"}
|