@mondart/nestjs-common-module-iam 2.0.0 → 3.1.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/dist/constants/iam-decorator-key.const.d.ts +7 -4
- package/dist/constants/iam-decorator-key.const.d.ts.map +1 -1
- package/dist/constants/iam-decorator-key.const.js +8 -5
- package/dist/constants/iam-decorator-key.const.js.map +1 -1
- package/dist/decorators/allow-iam.decorator.d.ts +3 -0
- package/dist/decorators/allow-iam.decorator.d.ts.map +1 -0
- package/dist/decorators/allow-iam.decorator.js +8 -0
- package/dist/decorators/allow-iam.decorator.js.map +1 -0
- package/dist/decorators/iam-entity-access.decorator.d.ts +4 -0
- package/dist/decorators/iam-entity-access.decorator.d.ts.map +1 -0
- package/dist/decorators/iam-entity-access.decorator.js +10 -0
- package/dist/decorators/iam-entity-access.decorator.js.map +1 -0
- package/dist/decorators/public-iam.decorators.d.ts +2 -0
- package/dist/decorators/public-iam.decorators.d.ts.map +1 -0
- package/dist/decorators/public-iam.decorators.js +8 -0
- package/dist/decorators/public-iam.decorators.js.map +1 -0
- package/dist/guards/iam-context.guard.d.ts +3 -4
- package/dist/guards/iam-context.guard.d.ts.map +1 -1
- package/dist/guards/iam-context.guard.js +25 -86
- package/dist/guards/iam-context.guard.js.map +1 -1
- package/dist/helpers/user-owner.helper.d.ts +12 -0
- package/dist/helpers/user-owner.helper.d.ts.map +1 -0
- package/dist/helpers/user-owner.helper.js +55 -0
- package/dist/helpers/user-owner.helper.js.map +1 -0
- package/dist/iam-context.module.d.ts +3 -0
- package/dist/iam-context.module.d.ts.map +1 -1
- package/dist/iam-context.module.js +45 -11
- package/dist/iam-context.module.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces/iam-context-options.interface.d.ts +27 -0
- package/dist/interfaces/iam-context-options.interface.d.ts.map +1 -0
- package/dist/interfaces/iam-context-options.interface.js +18 -0
- package/dist/interfaces/iam-context-options.interface.js.map +1 -0
- package/dist/interfaces/iam-entity-access.interface.d.ts +39 -0
- package/dist/interfaces/iam-entity-access.interface.d.ts.map +1 -0
- package/dist/interfaces/iam-entity-access.interface.js +3 -0
- package/dist/interfaces/iam-entity-access.interface.js.map +1 -0
- package/dist/pipes/iam-find-one-query-scope.pipe.d.ts +10 -0
- package/dist/pipes/iam-find-one-query-scope.pipe.d.ts.map +1 -0
- package/dist/pipes/{iam-paginate-query.pipe.js → iam-find-one-query-scope.pipe.js} +22 -24
- package/dist/pipes/iam-find-one-query-scope.pipe.js.map +1 -0
- package/dist/pipes/iam-paginate-query-scope.pipe.d.ts +11 -0
- package/dist/pipes/iam-paginate-query-scope.pipe.d.ts.map +1 -0
- package/dist/pipes/iam-paginate-query-scope.pipe.js +48 -0
- package/dist/pipes/iam-paginate-query-scope.pipe.js.map +1 -0
- package/dist/services/iam-entity-access.service.d.ts +22 -0
- package/dist/services/iam-entity-access.service.d.ts.map +1 -0
- package/dist/services/iam-entity-access.service.js +250 -0
- package/dist/services/iam-entity-access.service.js.map +1 -0
- package/dist/types/iam-entity-access.type.d.ts +19 -0
- package/dist/types/iam-entity-access.type.d.ts.map +1 -0
- package/dist/types/iam-entity-access.type.js +4 -0
- package/dist/types/iam-entity-access.type.js.map +1 -0
- package/package.json +16 -3
- package/dist/decorators/get-owner-id.decorator.d.ts +0 -2
- package/dist/decorators/get-owner-id.decorator.d.ts.map +0 -1
- package/dist/decorators/get-owner-id.decorator.js +0 -13
- package/dist/decorators/get-owner-id.decorator.js.map +0 -1
- package/dist/decorators/iam-public.decorator.d.ts +0 -2
- package/dist/decorators/iam-public.decorator.d.ts.map +0 -1
- package/dist/decorators/iam-public.decorator.js +0 -8
- package/dist/decorators/iam-public.decorator.js.map +0 -1
- package/dist/decorators/owns-entity.decorator.d.ts +0 -14
- package/dist/decorators/owns-entity.decorator.d.ts.map +0 -1
- package/dist/decorators/owns-entity.decorator.js +0 -8
- package/dist/decorators/owns-entity.decorator.js.map +0 -1
- package/dist/decorators/set-iam-route-user-type.decorator.d.ts +0 -3
- package/dist/decorators/set-iam-route-user-type.decorator.d.ts.map +0 -1
- package/dist/decorators/set-iam-route-user-type.decorator.js +0 -8
- package/dist/decorators/set-iam-route-user-type.decorator.js.map +0 -1
- package/dist/pipes/iam-paginate-query.pipe.d.ts +0 -8
- package/dist/pipes/iam-paginate-query.pipe.d.ts.map +0 -1
- package/dist/pipes/iam-paginate-query.pipe.js.map +0 -1
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export declare const IAM_PUBLIC_ROUTE = "
|
|
2
|
-
export declare const IAM_ROUTE_USER_TYPE = "
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
1
|
+
export declare const IAM_PUBLIC_ROUTE = "iam_public_route";
|
|
2
|
+
export declare const IAM_ROUTE_USER_TYPE = "iam_route_user_type";
|
|
3
|
+
export declare const IAM_ENTITY_ACCESS_KEY = "iam_entity_access";
|
|
4
|
+
export declare const IAM_ENTITY_SCOPE_KEY = "iam_entity_scope";
|
|
5
|
+
export declare const IAM_REQUEST_USER_TYPE_KEY = "__iam_user_type";
|
|
6
|
+
export declare const IAM_REQUEST_ENTITY_SCOPE_OPTIONS_KEY = "__iam_entity_scope_options";
|
|
7
|
+
export declare const IAM_QUERY_SCOPE_WHERE_KEY = "iamWhere";
|
|
5
8
|
//# sourceMappingURL=iam-decorator-key.const.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iam-decorator-key.const.d.ts","sourceRoot":"","sources":["../../src/constants/iam-decorator-key.const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"iam-decorator-key.const.d.ts","sourceRoot":"","sources":["../../src/constants/iam-decorator-key.const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAEzD,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AAEvD,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAC3D,eAAO,MAAM,oCAAoC,+BACnB,CAAC;AAE/B,eAAO,MAAM,yBAAyB,aAAa,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.IAM_PUBLIC_ROUTE = '
|
|
5
|
-
exports.IAM_ROUTE_USER_TYPE = '
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
3
|
+
exports.IAM_QUERY_SCOPE_WHERE_KEY = exports.IAM_REQUEST_ENTITY_SCOPE_OPTIONS_KEY = exports.IAM_REQUEST_USER_TYPE_KEY = exports.IAM_ENTITY_SCOPE_KEY = exports.IAM_ENTITY_ACCESS_KEY = exports.IAM_ROUTE_USER_TYPE = exports.IAM_PUBLIC_ROUTE = void 0;
|
|
4
|
+
exports.IAM_PUBLIC_ROUTE = 'iam_public_route';
|
|
5
|
+
exports.IAM_ROUTE_USER_TYPE = 'iam_route_user_type';
|
|
6
|
+
exports.IAM_ENTITY_ACCESS_KEY = 'iam_entity_access';
|
|
7
|
+
exports.IAM_ENTITY_SCOPE_KEY = 'iam_entity_scope';
|
|
8
|
+
exports.IAM_REQUEST_USER_TYPE_KEY = '__iam_user_type';
|
|
9
|
+
exports.IAM_REQUEST_ENTITY_SCOPE_OPTIONS_KEY = '__iam_entity_scope_options';
|
|
10
|
+
exports.IAM_QUERY_SCOPE_WHERE_KEY = 'iamWhere';
|
|
8
11
|
//# sourceMappingURL=iam-decorator-key.const.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iam-decorator-key.const.js","sourceRoot":"","sources":["../../src/constants/iam-decorator-key.const.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,
|
|
1
|
+
{"version":3,"file":"iam-decorator-key.const.js","sourceRoot":"","sources":["../../src/constants/iam-decorator-key.const.ts"],"names":[],"mappings":";;;AAAa,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AACtC,QAAA,mBAAmB,GAAG,qBAAqB,CAAC;AAE5C,QAAA,qBAAqB,GAAG,mBAAmB,CAAC;AAC5C,QAAA,oBAAoB,GAAG,kBAAkB,CAAC;AAE1C,QAAA,yBAAyB,GAAG,iBAAiB,CAAC;AAC9C,QAAA,oCAAoC,GAC/C,4BAA4B,CAAC;AAElB,QAAA,yBAAyB,GAAG,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allow-iam.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/allow-iam.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D,eAAO,MAAM,QAAQ,GAAI,GAAG,WAAW,eAAe,EAAE,qDACX,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AllowIam = void 0;
|
|
4
|
+
const iam_decorator_key_const_1 = require("../constants/iam-decorator-key.const");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const AllowIam = (...userTypes) => (0, common_1.SetMetadata)(iam_decorator_key_const_1.IAM_ROUTE_USER_TYPE, userTypes);
|
|
7
|
+
exports.AllowIam = AllowIam;
|
|
8
|
+
//# sourceMappingURL=allow-iam.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"allow-iam.decorator.js","sourceRoot":"","sources":["../../src/decorators/allow-iam.decorator.ts"],"names":[],"mappings":";;;AAAA,kFAA2E;AAC3E,2CAA6C;AAGtC,MAAM,QAAQ,GAAG,CAAC,GAAG,SAA4B,EAAE,EAAE,CAC1D,IAAA,oBAAW,EAAC,6CAAmB,EAAE,SAAS,CAAC,CAAC;AADjC,QAAA,QAAQ,YACyB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ApplyIamEntityScopeOptions, RequireIamEntityAccessOptions } from '../interfaces/iam-entity-access.interface';
|
|
2
|
+
export declare const RequireIamEntityAccess: <T = any>(options: RequireIamEntityAccessOptions<T>) => import("@nestjs/common").CustomDecorator<string>;
|
|
3
|
+
export declare const ApplyIamEntityScope: <T = any>(options?: ApplyIamEntityScopeOptions<T>) => import("@nestjs/common").CustomDecorator<string>;
|
|
4
|
+
//# sourceMappingURL=iam-entity-access.decorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-entity-access.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/iam-entity-access.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC9B,MAAM,2CAA2C,CAAC;AAMnD,eAAO,MAAM,sBAAsB,GAAI,CAAC,GAAG,GAAG,EAC5C,SAAS,6BAA6B,CAAC,CAAC,CAAC,qDACK,CAAC;AAEjD,eAAO,MAAM,mBAAmB,GAAI,CAAC,GAAG,GAAG,EACzC,UAAS,0BAA0B,CAAC,CAAC,CAAM,qDACE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApplyIamEntityScope = exports.RequireIamEntityAccess = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const iam_decorator_key_const_1 = require("../constants/iam-decorator-key.const");
|
|
6
|
+
const RequireIamEntityAccess = (options) => (0, common_1.SetMetadata)(iam_decorator_key_const_1.IAM_ENTITY_ACCESS_KEY, options);
|
|
7
|
+
exports.RequireIamEntityAccess = RequireIamEntityAccess;
|
|
8
|
+
const ApplyIamEntityScope = (options = {}) => (0, common_1.SetMetadata)(iam_decorator_key_const_1.IAM_ENTITY_SCOPE_KEY, options);
|
|
9
|
+
exports.ApplyIamEntityScope = ApplyIamEntityScope;
|
|
10
|
+
//# sourceMappingURL=iam-entity-access.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-entity-access.decorator.js","sourceRoot":"","sources":["../../src/decorators/iam-entity-access.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAK7C,kFAG8C;AAEvC,MAAM,sBAAsB,GAAG,CACpC,OAAyC,EACzC,EAAE,CAAC,IAAA,oBAAW,EAAC,+CAAqB,EAAE,OAAO,CAAC,CAAC;AAFpC,QAAA,sBAAsB,0BAEc;AAE1C,MAAM,mBAAmB,GAAG,CACjC,UAAyC,EAAE,EAC3C,EAAE,CAAC,IAAA,oBAAW,EAAC,8CAAoB,EAAE,OAAO,CAAC,CAAC;AAFnC,QAAA,mBAAmB,uBAEgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-iam.decorators.d.ts","sourceRoot":"","sources":["../../src/decorators/public-iam.decorators.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,wDAA4C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PublicIam = void 0;
|
|
4
|
+
const iam_decorator_key_const_1 = require("../constants/iam-decorator-key.const");
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
const PublicIam = () => (0, common_1.SetMetadata)(iam_decorator_key_const_1.IAM_PUBLIC_ROUTE, true);
|
|
7
|
+
exports.PublicIam = PublicIam;
|
|
8
|
+
//# sourceMappingURL=public-iam.decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-iam.decorators.js","sourceRoot":"","sources":["../../src/decorators/public-iam.decorators.ts"],"names":[],"mappings":";;;AAAA,kFAAwE;AACxE,2CAA6C;AAEtC,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,0CAAgB,EAAE,IAAI,CAAC,CAAC;AAAtD,QAAA,SAAS,aAA6C"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { CanActivate, ExecutionContext } from '@nestjs/common';
|
|
2
2
|
import { Reflector } from '@nestjs/core';
|
|
3
|
-
import {
|
|
3
|
+
import { IamEntityAccessService } from '../services/iam-entity-access.service';
|
|
4
4
|
export declare class IamContextGuard implements CanActivate {
|
|
5
5
|
private readonly reflector;
|
|
6
|
-
private readonly
|
|
7
|
-
constructor(reflector: Reflector,
|
|
6
|
+
private readonly iamEntityAccessService;
|
|
7
|
+
constructor(reflector: Reflector, iamEntityAccessService: IamEntityAccessService);
|
|
8
8
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
9
|
-
private checkOwnership;
|
|
10
9
|
}
|
|
11
10
|
//# sourceMappingURL=iam-context.guard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iam-context.guard.d.ts","sourceRoot":"","sources":["../../src/guards/iam-context.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,
|
|
1
|
+
{"version":3,"file":"iam-context.guard.d.ts","sourceRoot":"","sources":["../../src/guards/iam-context.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAWzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAM/E,qBACa,eAAgB,YAAW,WAAW;IAE/C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,sBAAsB;gBADtB,SAAS,EAAE,SAAS,EACpB,sBAAsB,EAAE,sBAAsB;IAG3D,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAwE/D"}
|
|
@@ -8,117 +8,56 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
12
|
exports.IamContextGuard = void 0;
|
|
16
13
|
const common_1 = require("@nestjs/common");
|
|
17
14
|
const core_1 = require("@nestjs/core");
|
|
18
15
|
const nestjs_common_module_core_1 = require("@mondart/nestjs-common-module-core");
|
|
19
16
|
const iam_decorator_key_const_1 = require("../constants/iam-decorator-key.const");
|
|
20
|
-
const
|
|
21
|
-
const owns_entity_decorator_1 = require("../decorators/owns-entity.decorator");
|
|
22
|
-
const constants_1 = require("@nestjs/common/constants");
|
|
23
|
-
const typeorm_1 = require("@nestjs/typeorm");
|
|
24
|
-
const typeorm_2 = require("typeorm");
|
|
17
|
+
const iam_entity_access_service_1 = require("../services/iam-entity-access.service");
|
|
25
18
|
let IamContextGuard = class IamContextGuard {
|
|
26
|
-
constructor(reflector,
|
|
19
|
+
constructor(reflector, iamEntityAccessService) {
|
|
27
20
|
this.reflector = reflector;
|
|
28
|
-
this.
|
|
21
|
+
this.iamEntityAccessService = iamEntityAccessService;
|
|
29
22
|
}
|
|
30
23
|
async canActivate(context) {
|
|
24
|
+
if (context.getType() !== 'http') {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
31
27
|
const request = context.switchToHttp().getRequest();
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
if (iaPublicRoute)
|
|
28
|
+
const isPublicRoute = this.reflector.getAllAndOverride(iam_decorator_key_const_1.IAM_PUBLIC_ROUTE, [context.getHandler(), context.getClass()]);
|
|
29
|
+
if (isPublicRoute) {
|
|
35
30
|
return true;
|
|
36
|
-
|
|
31
|
+
}
|
|
32
|
+
const iamContext = (0, nestjs_common_module_core_1.getIamContext)(request);
|
|
33
|
+
const allowedUserTypes = this.reflector.getAllAndOverride(iam_decorator_key_const_1.IAM_ROUTE_USER_TYPE, [
|
|
37
34
|
context.getHandler(),
|
|
38
35
|
context.getClass(),
|
|
39
36
|
]) || [];
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
throw new common_1.ForbiddenException();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (userType.includes(iam_user_type_enum_1.IamUserTypeEnum.USER) ||
|
|
49
|
-
userType.includes(iam_user_type_enum_1.IamUserTypeEnum.GUEST)) {
|
|
50
|
-
const options = this.reflector.getAllAndOverride(owns_entity_decorator_1.OWNS_ENTITY_KEY, [context.getHandler(), context.getClass()]);
|
|
51
|
-
if (options) {
|
|
52
|
-
const isOwner = await this.checkOwnership(options.entity.name, options.entityPropertyKey, options.requestEntityId(request), Array.isArray(options.ownerConditions)
|
|
53
|
-
? options.ownerConditions?.map((condition) => ({
|
|
54
|
-
ownerPropertyKey: condition.ownerPropertyKey,
|
|
55
|
-
ownerEntityId: condition.ownerEntityId(request),
|
|
56
|
-
}))
|
|
57
|
-
: {
|
|
58
|
-
ownerPropertyKey: options.ownerConditions
|
|
59
|
-
.ownerPropertyKey,
|
|
60
|
-
ownerEntityId: options.ownerConditions.ownerEntityId(request),
|
|
61
|
-
});
|
|
62
|
-
const controllerPath = this.reflector.getAllAndOverride(constants_1.PATH_METADATA, [
|
|
63
|
-
context.getHandler(),
|
|
64
|
-
context.getClass(),
|
|
65
|
-
]) ?? '';
|
|
66
|
-
if (!isOwner) {
|
|
67
|
-
throw new common_1.ForbiddenException(`You do not own this ${controllerPath}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
37
|
+
const currentUserType = this.iamEntityAccessService.resolveUserType(iamContext, allowedUserTypes);
|
|
38
|
+
request[iam_decorator_key_const_1.IAM_REQUEST_USER_TYPE_KEY] = currentUserType;
|
|
39
|
+
if (!allowedUserTypes.includes(currentUserType)) {
|
|
73
40
|
throw new common_1.ForbiddenException();
|
|
74
41
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (!entityId)
|
|
79
|
-
return true;
|
|
80
|
-
const queryRunner = this.dataSource.createQueryRunner();
|
|
81
|
-
await queryRunner.connect();
|
|
82
|
-
await queryRunner.startTransaction('READ UNCOMMITTED');
|
|
83
|
-
try {
|
|
84
|
-
const entityManager = queryRunner.manager;
|
|
85
|
-
const isExists = await entityManager.getRepository(entity).exists({
|
|
86
|
-
where: {
|
|
87
|
-
[entityPropertyKey]: entityId,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
if (!isExists) {
|
|
91
|
-
throw new common_1.NotFoundException(nestjs_common_module_core_1.MessageFormatter.replace(nestjs_common_module_core_1.SharedMessages.RESOURCE_NOT_FOUND, 'Cart'));
|
|
92
|
-
}
|
|
93
|
-
let where = {
|
|
94
|
-
[entityPropertyKey]: entityId,
|
|
95
|
-
};
|
|
96
|
-
where = Array.isArray(ownerConditoions)
|
|
97
|
-
? ownerConditoions?.reduce((acc, curr) => {
|
|
98
|
-
acc[curr.ownerPropertyKey] = curr.ownerEntityId || (0, typeorm_2.IsNull)();
|
|
99
|
-
return acc;
|
|
100
|
-
}, where)
|
|
101
|
-
: where;
|
|
102
|
-
const isBlongeToOwner = await entityManager.getRepository(entity).exists({
|
|
103
|
-
where: where,
|
|
104
|
-
});
|
|
105
|
-
await queryRunner.commitTransaction();
|
|
106
|
-
return isBlongeToOwner;
|
|
42
|
+
const scopeOptions = this.reflector.getAllAndOverride(iam_decorator_key_const_1.IAM_ENTITY_SCOPE_KEY, [context.getHandler(), context.getClass()]);
|
|
43
|
+
if (scopeOptions) {
|
|
44
|
+
request[iam_decorator_key_const_1.IAM_REQUEST_ENTITY_SCOPE_OPTIONS_KEY] = scopeOptions;
|
|
107
45
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
46
|
+
const entityAccessOptions = this.reflector.getAllAndOverride(iam_decorator_key_const_1.IAM_ENTITY_ACCESS_KEY, [context.getHandler(), context.getClass()]);
|
|
47
|
+
if (!entityAccessOptions) {
|
|
48
|
+
return true;
|
|
111
49
|
}
|
|
112
|
-
|
|
113
|
-
|
|
50
|
+
const hasAccess = await this.iamEntityAccessService.hasEntityAccess(entityAccessOptions, request, iamContext, currentUserType);
|
|
51
|
+
if (!hasAccess) {
|
|
52
|
+
throw new common_1.ForbiddenException(`You do not have access to this ${entityAccessOptions.resourceName ?? 'resource'}`);
|
|
114
53
|
}
|
|
54
|
+
return true;
|
|
115
55
|
}
|
|
116
56
|
};
|
|
117
57
|
exports.IamContextGuard = IamContextGuard;
|
|
118
58
|
exports.IamContextGuard = IamContextGuard = __decorate([
|
|
119
59
|
(0, common_1.Injectable)(),
|
|
120
|
-
__param(1, (0, typeorm_1.InjectDataSource)()),
|
|
121
60
|
__metadata("design:paramtypes", [core_1.Reflector,
|
|
122
|
-
|
|
61
|
+
iam_entity_access_service_1.IamEntityAccessService])
|
|
123
62
|
], IamContextGuard);
|
|
124
63
|
//# sourceMappingURL=iam-context.guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iam-context.guard.js","sourceRoot":"","sources":["../../src/guards/iam-context.guard.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iam-context.guard.js","sourceRoot":"","sources":["../../src/guards/iam-context.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,uCAAyC;AACzC,kFAAmE;AACnE,kFAO8C;AAE9C,qFAA+E;AAOxE,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YACmB,SAAoB,EACpB,sBAA8C;QAD9C,cAAS,GAAT,SAAS,CAAW;QACpB,2BAAsB,GAAtB,sBAAsB,CAAwB;IAC9D,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,IAAI,OAAO,CAAC,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;YACjC,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEpD,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CACpD,0CAAgB,EAChB,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAC3C,CAAC;QAEF,IAAI,aAAa,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,UAAU,GAAG,IAAA,yCAAa,EAAC,OAAO,CAAC,CAAC;QAE1C,MAAM,gBAAgB,GACpB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAoB,6CAAmB,EAAE;YACvE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACnB,CAAC,IAAI,EAAE,CAAC;QAEX,MAAM,eAAe,GAAG,IAAI,CAAC,sBAAsB,CAAC,eAAe,CACjE,UAAU,EACV,gBAAgB,CACjB,CAAC;QAEF,OAAO,CAAC,mDAAyB,CAAC,GAAG,eAAe,CAAC;QAErD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YAChD,MAAM,IAAI,2BAAkB,EAAE,CAAC;QACjC,CAAC;QAED,MAAM,YAAY,GAChB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAC9B,8CAAoB,EACpB,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAC3C,CAAC;QAEJ,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,CAAC,8DAAoC,CAAC,GAAG,YAAY,CAAC;QAC/D,CAAC;QAED,MAAM,mBAAmB,GACvB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAC9B,+CAAqB,EACrB,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAC3C,CAAC;QAEJ,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,eAAe,CACjE,mBAAmB,EACnB,OAAO,EACP,UAAU,EACV,eAAe,CAChB,CAAC;QAEF,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,2BAAkB,CAC1B,kCACE,mBAAmB,CAAC,YAAY,IAAI,UACtC,EAAE,CACH,CAAC;QACJ,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA9EY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;qCAGmB,gBAAS;QACI,kDAAsB;GAHtD,eAAe,CA8E3B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AccessValueCast, EntityAccessBranch } from '../types/iam-entity-access.type';
|
|
2
|
+
import { EntityFieldMatch } from '../interfaces/iam-entity-access.interface';
|
|
3
|
+
export declare const byIam: <T = any>(field: keyof T & string, iamPath: string, cast?: AccessValueCast) => EntityAccessBranch<T>;
|
|
4
|
+
export declare const byReq: <T = any>(field: keyof T & string, reqPath: string, cast?: AccessValueCast) => EntityAccessBranch<T>;
|
|
5
|
+
export declare const matchIam: <T = any>(field: keyof T & string, iamPath: string, cast?: AccessValueCast) => EntityFieldMatch<T>;
|
|
6
|
+
export declare const matchReq: <T = any>(field: keyof T & string, reqPath: string, cast?: AccessValueCast) => EntityFieldMatch<T>;
|
|
7
|
+
export declare const allOf: <T = any>(...matches: EntityFieldMatch<T>[]) => EntityAccessBranch<T>;
|
|
8
|
+
export declare const nullFields: <T = any>(...fields: (keyof T & string)[]) => EntityAccessBranch<T>;
|
|
9
|
+
export declare const unowned: <T = any>(...fields: (keyof T & string)[]) => EntityAccessBranch<T>;
|
|
10
|
+
export declare const userAuditAccess: <T = any>(createdField?: keyof T & string, updatedField?: keyof T & string) => EntityAccessBranch<T>[];
|
|
11
|
+
export declare const agentAuditAccess: <T = any>(createdField?: keyof T & string, updatedField?: keyof T & string) => EntityAccessBranch<T>[];
|
|
12
|
+
//# sourceMappingURL=user-owner.helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-owner.helper.d.ts","sourceRoot":"","sources":["../../src/helpers/user-owner.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,kBAAkB,EACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAK7E,eAAO,MAAM,KAAK,GAAI,CAAC,GAAG,GAAG,EAC3B,OAAO,MAAM,CAAC,GAAG,MAAM,EACvB,SAAS,MAAM,EACf,OAAO,eAAe,KACrB,kBAAkB,CAAC,CAAC,CAQrB,CAAC;AAKH,eAAO,MAAM,KAAK,GAAI,CAAC,GAAG,GAAG,EAC3B,OAAO,MAAM,CAAC,GAAG,MAAM,EACvB,SAAS,MAAM,EACf,OAAO,eAAe,KACrB,kBAAkB,CAAC,CAAC,CAQrB,CAAC;AAKH,eAAO,MAAM,QAAQ,GAAI,CAAC,GAAG,GAAG,EAC9B,OAAO,MAAM,CAAC,GAAG,MAAM,EACvB,SAAS,MAAM,EACf,OAAO,eAAe,KACrB,gBAAgB,CAAC,CAAC,CAInB,CAAC;AAEH,eAAO,MAAM,QAAQ,GAAI,CAAC,GAAG,GAAG,EAC9B,OAAO,MAAM,CAAC,GAAG,MAAM,EACvB,SAAS,MAAM,EACf,OAAO,eAAe,KACrB,gBAAgB,CAAC,CAAC,CAInB,CAAC;AAEH,eAAO,MAAM,KAAK,GAAI,CAAC,GAAG,GAAG,EAC3B,GAAG,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAAE,KAChC,kBAAkB,CAAC,CAAC,CAErB,CAAC;AAKH,eAAO,MAAM,UAAU,GAAI,CAAC,GAAG,GAAG,EAChC,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,KAC9B,kBAAkB,CAAC,CAAC,CAErB,CAAC;AAKH,eAAO,MAAM,OAAO,GATO,CAAC,mBACf,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,KAC9B,kBAAkB,CAAC,CAAC,CAOU,CAAC;AAQlC,eAAO,MAAM,eAAe,GAAI,CAAC,GAAG,GAAG,EACrC,eAAc,MAAM,CAAC,GAAG,MAA4C,EACpE,eAAc,MAAM,CAAC,GAAG,MAA4C,KACnE,kBAAkB,CAAC,CAAC,CAAC,EAGvB,CAAC;AAKF,eAAO,MAAM,gBAAgB,GAAI,CAAC,GAAG,GAAG,EACtC,eAAc,MAAM,CAAC,GAAG,MAA6C,EACrE,eAAc,MAAM,CAAC,GAAG,MAA6C,KACpE,kBAAkB,CAAC,CAAC,CAAC,EAGvB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.agentAuditAccess = exports.userAuditAccess = exports.unowned = exports.nullFields = exports.allOf = exports.matchReq = exports.matchIam = exports.byReq = exports.byIam = void 0;
|
|
4
|
+
const byIam = (field, iamPath, cast) => ({
|
|
5
|
+
all: [
|
|
6
|
+
{
|
|
7
|
+
field,
|
|
8
|
+
valueFrom: `iam.${iamPath}`,
|
|
9
|
+
cast,
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
});
|
|
13
|
+
exports.byIam = byIam;
|
|
14
|
+
const byReq = (field, reqPath, cast) => ({
|
|
15
|
+
all: [
|
|
16
|
+
{
|
|
17
|
+
field,
|
|
18
|
+
valueFrom: `req.${reqPath}`,
|
|
19
|
+
cast,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
exports.byReq = byReq;
|
|
24
|
+
const matchIam = (field, iamPath, cast) => ({
|
|
25
|
+
field,
|
|
26
|
+
valueFrom: `iam.${iamPath}`,
|
|
27
|
+
cast,
|
|
28
|
+
});
|
|
29
|
+
exports.matchIam = matchIam;
|
|
30
|
+
const matchReq = (field, reqPath, cast) => ({
|
|
31
|
+
field,
|
|
32
|
+
valueFrom: `req.${reqPath}`,
|
|
33
|
+
cast,
|
|
34
|
+
});
|
|
35
|
+
exports.matchReq = matchReq;
|
|
36
|
+
const allOf = (...matches) => ({
|
|
37
|
+
all: matches,
|
|
38
|
+
});
|
|
39
|
+
exports.allOf = allOf;
|
|
40
|
+
const nullFields = (...fields) => ({
|
|
41
|
+
nullFields: fields,
|
|
42
|
+
});
|
|
43
|
+
exports.nullFields = nullFields;
|
|
44
|
+
exports.unowned = exports.nullFields;
|
|
45
|
+
const userAuditAccess = (createdField = 'createdByUser', updatedField = 'updatedByUser') => [
|
|
46
|
+
(0, exports.byIam)(createdField, 'userId', 'string'),
|
|
47
|
+
(0, exports.byIam)(updatedField, 'userId', 'string'),
|
|
48
|
+
];
|
|
49
|
+
exports.userAuditAccess = userAuditAccess;
|
|
50
|
+
const agentAuditAccess = (createdField = 'createdByAdmin', updatedField = 'updatedByAdmin') => [
|
|
51
|
+
(0, exports.byIam)(createdField, 'agentId', 'string'),
|
|
52
|
+
(0, exports.byIam)(updatedField, 'agentId', 'string'),
|
|
53
|
+
];
|
|
54
|
+
exports.agentAuditAccess = agentAuditAccess;
|
|
55
|
+
//# sourceMappingURL=user-owner.helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-owner.helper.js","sourceRoot":"","sources":["../../src/helpers/user-owner.helper.ts"],"names":[],"mappings":";;;AASO,MAAM,KAAK,GAAG,CACnB,KAAuB,EACvB,OAAe,EACf,IAAsB,EACC,EAAE,CAAC,CAAC;IAC3B,GAAG,EAAE;QACH;YACE,KAAK;YACL,SAAS,EAAE,OAAO,OAAO,EAAqB;YAC9C,IAAI;SACL;KACF;CACF,CAAC,CAAC;AAZU,QAAA,KAAK,SAYf;AAKI,MAAM,KAAK,GAAG,CACnB,KAAuB,EACvB,OAAe,EACf,IAAsB,EACC,EAAE,CAAC,CAAC;IAC3B,GAAG,EAAE;QACH;YACE,KAAK;YACL,SAAS,EAAE,OAAO,OAAO,EAAqB;YAC9C,IAAI;SACL;KACF;CACF,CAAC,CAAC;AAZU,QAAA,KAAK,SAYf;AAKI,MAAM,QAAQ,GAAG,CACtB,KAAuB,EACvB,OAAe,EACf,IAAsB,EACD,EAAE,CAAC,CAAC;IACzB,KAAK;IACL,SAAS,EAAE,OAAO,OAAO,EAAqB;IAC9C,IAAI;CACL,CAAC,CAAC;AARU,QAAA,QAAQ,YAQlB;AAEI,MAAM,QAAQ,GAAG,CACtB,KAAuB,EACvB,OAAe,EACf,IAAsB,EACD,EAAE,CAAC,CAAC;IACzB,KAAK;IACL,SAAS,EAAE,OAAO,OAAO,EAAqB;IAC9C,IAAI;CACL,CAAC,CAAC;AARU,QAAA,QAAQ,YAQlB;AAEI,MAAM,KAAK,GAAG,CACnB,GAAG,OAA8B,EACV,EAAE,CAAC,CAAC;IAC3B,GAAG,EAAE,OAAO;CACb,CAAC,CAAC;AAJU,QAAA,KAAK,SAIf;AAKI,MAAM,UAAU,GAAG,CACxB,GAAG,MAA4B,EACR,EAAE,CAAC,CAAC;IAC3B,UAAU,EAAE,MAAM;CACnB,CAAC,CAAC;AAJU,QAAA,UAAU,cAIpB;AAKU,QAAA,OAAO,GAAG,kBAAU,CAAC;AAQ3B,MAAM,eAAe,GAAG,CAC7B,eAAiC,eAAmC,EACpE,eAAiC,eAAmC,EAC3C,EAAE,CAAC;IAC5B,IAAA,aAAK,EAAI,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC;IAC1C,IAAA,aAAK,EAAI,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC;CAC3C,CAAC;AANW,QAAA,eAAe,mBAM1B;AAKK,MAAM,gBAAgB,GAAG,CAC9B,eAAiC,gBAAoC,EACrE,eAAiC,gBAAoC,EAC5C,EAAE,CAAC;IAC5B,IAAA,aAAK,EAAI,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC;IAC3C,IAAA,aAAK,EAAI,YAAY,EAAE,SAAS,EAAE,QAAQ,CAAC;CAC5C,CAAC;AANW,QAAA,gBAAgB,oBAM3B"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { IamContextModuleOptions } from './interfaces/iam-context-options.interface';
|
|
1
3
|
export declare class IamContextModule {
|
|
4
|
+
static forRoot(options?: IamContextModuleOptions): DynamicModule;
|
|
2
5
|
}
|
|
3
6
|
//# sourceMappingURL=iam-context.module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iam-context.module.d.ts","sourceRoot":"","sources":["../src/iam-context.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iam-context.module.d.ts","sourceRoot":"","sources":["../src/iam-context.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAkB,MAAM,gBAAgB,CAAC;AAO/D,OAAO,EAGL,uBAAuB,EACxB,MAAM,4CAA4C,CAAC;AAEpD,qBAEa,gBAAgB;IAC3B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAE,uBAA4B,GAAG,aAAa;CAmCrE"}
|
|
@@ -5,22 +5,56 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
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
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var IamContextModule_1;
|
|
8
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
10
|
exports.IamContextModule = void 0;
|
|
10
11
|
const common_1 = require("@nestjs/common");
|
|
11
|
-
const iam_context_guard_1 = require("./guards/iam-context.guard");
|
|
12
12
|
const core_1 = require("@nestjs/core");
|
|
13
|
-
|
|
13
|
+
const iam_context_guard_1 = require("./guards/iam-context.guard");
|
|
14
|
+
const iam_entity_access_service_1 = require("./services/iam-entity-access.service");
|
|
15
|
+
const iam_find_one_query_scope_pipe_1 = require("./pipes/iam-find-one-query-scope.pipe");
|
|
16
|
+
const iam_paginate_query_scope_pipe_1 = require("./pipes/iam-paginate-query-scope.pipe");
|
|
17
|
+
const iam_context_options_interface_1 = require("./interfaces/iam-context-options.interface");
|
|
18
|
+
let IamContextModule = IamContextModule_1 = class IamContextModule {
|
|
19
|
+
static forRoot(options = {}) {
|
|
20
|
+
return {
|
|
21
|
+
module: IamContextModule_1,
|
|
22
|
+
providers: [
|
|
23
|
+
{
|
|
24
|
+
provide: iam_context_options_interface_1.IAM_CONTEXT_MODULE_OPTIONS,
|
|
25
|
+
useValue: {
|
|
26
|
+
...iam_context_options_interface_1.DEFAULT_IAM_CONTEXT_MODULE_OPTIONS,
|
|
27
|
+
...options,
|
|
28
|
+
controllers: {
|
|
29
|
+
...iam_context_options_interface_1.DEFAULT_IAM_CONTEXT_MODULE_OPTIONS.controllers,
|
|
30
|
+
...options.controllers,
|
|
31
|
+
},
|
|
32
|
+
entityAccess: {
|
|
33
|
+
...iam_context_options_interface_1.DEFAULT_IAM_CONTEXT_MODULE_OPTIONS.entityAccess,
|
|
34
|
+
...options.entityAccess,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
iam_entity_access_service_1.IamEntityAccessService,
|
|
39
|
+
iam_find_one_query_scope_pipe_1.IamFindOneQueryScopePipe,
|
|
40
|
+
iam_paginate_query_scope_pipe_1.IamPaginateQueryScopePipe,
|
|
41
|
+
{
|
|
42
|
+
provide: core_1.APP_GUARD,
|
|
43
|
+
useClass: iam_context_guard_1.IamContextGuard,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
exports: [
|
|
47
|
+
iam_context_options_interface_1.IAM_CONTEXT_MODULE_OPTIONS,
|
|
48
|
+
iam_entity_access_service_1.IamEntityAccessService,
|
|
49
|
+
iam_find_one_query_scope_pipe_1.IamFindOneQueryScopePipe,
|
|
50
|
+
iam_paginate_query_scope_pipe_1.IamPaginateQueryScopePipe,
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
14
54
|
};
|
|
15
55
|
exports.IamContextModule = IamContextModule;
|
|
16
|
-
exports.IamContextModule = IamContextModule = __decorate([
|
|
17
|
-
(0, common_1.
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
provide: core_1.APP_GUARD,
|
|
21
|
-
useClass: iam_context_guard_1.IamContextGuard,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
})
|
|
56
|
+
exports.IamContextModule = IamContextModule = IamContextModule_1 = __decorate([
|
|
57
|
+
(0, common_1.Global)(),
|
|
58
|
+
(0, common_1.Module)({})
|
|
25
59
|
], IamContextModule);
|
|
26
60
|
//# sourceMappingURL=iam-context.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iam-context.module.js","sourceRoot":"","sources":["../src/iam-context.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"iam-context.module.js","sourceRoot":"","sources":["../src/iam-context.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+D;AAC/D,uCAAyC;AAEzC,kEAA6D;AAC7D,oFAA8E;AAC9E,yFAAiF;AACjF,yFAAkF;AAClF,8FAIoD;AAI7C,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IAC3B,MAAM,CAAC,OAAO,CAAC,UAAmC,EAAE;QAClD,OAAO;YACL,MAAM,EAAE,kBAAgB;YACxB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,0DAA0B;oBACnC,QAAQ,EAAE;wBACR,GAAG,kEAAkC;wBACrC,GAAG,OAAO;wBACV,WAAW,EAAE;4BACX,GAAG,kEAAkC,CAAC,WAAW;4BACjD,GAAG,OAAO,CAAC,WAAW;yBACvB;wBACD,YAAY,EAAE;4BACZ,GAAG,kEAAkC,CAAC,YAAY;4BAClD,GAAG,OAAO,CAAC,YAAY;yBACxB;qBACF;iBACF;gBACD,kDAAsB;gBACtB,wDAAwB;gBACxB,yDAAyB;gBACzB;oBACE,OAAO,EAAE,gBAAS;oBAClB,QAAQ,EAAE,mCAAe;iBAC1B;aACF;YACD,OAAO,EAAE;gBACP,0DAA0B;gBAC1B,kDAAsB;gBACtB,wDAAwB;gBACxB,yDAAyB;aAC1B;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AApCY,4CAAgB;2BAAhB,gBAAgB;IAF5B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,gBAAgB,CAoC5B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
export * from './decorators/
|
|
2
|
-
export * from './decorators/iam-
|
|
3
|
-
export * from './decorators/
|
|
4
|
-
export * from './decorators/set-iam-route-user-type.decorator';
|
|
1
|
+
export * from './decorators/public-iam.decorators';
|
|
2
|
+
export * from './decorators/iam-entity-access.decorator';
|
|
3
|
+
export * from './decorators/allow-iam.decorator';
|
|
5
4
|
export * from './enums/iam-user-type.enum';
|
|
6
5
|
export * from './guards/iam-context.guard';
|
|
7
|
-
export * from './
|
|
6
|
+
export * from './helpers/user-owner.helper';
|
|
7
|
+
export * from './interfaces/iam-entity-access.interface';
|
|
8
|
+
export * from './interfaces/iam-context-options.interface';
|
|
9
|
+
export * from './types/iam-entity-access.type';
|
|
10
|
+
export * from './pipes/iam-paginate-query-scope.pipe';
|
|
11
|
+
export * from './pipes/iam-find-one-query-scope.pipe';
|
|
12
|
+
export * from './services/iam-entity-access.service';
|
|
8
13
|
export * from './iam-context.module';
|
|
9
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,kCAAkC,CAAC;AACjD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uCAAuC,CAAC;AACtD,cAAc,uCAAuC,CAAC;AACtD,cAAc,sCAAsC,CAAC;AACrD,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -14,12 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./decorators/
|
|
18
|
-
__exportStar(require("./decorators/iam-
|
|
19
|
-
__exportStar(require("./decorators/
|
|
20
|
-
__exportStar(require("./decorators/set-iam-route-user-type.decorator"), exports);
|
|
17
|
+
__exportStar(require("./decorators/public-iam.decorators"), exports);
|
|
18
|
+
__exportStar(require("./decorators/iam-entity-access.decorator"), exports);
|
|
19
|
+
__exportStar(require("./decorators/allow-iam.decorator"), exports);
|
|
21
20
|
__exportStar(require("./enums/iam-user-type.enum"), exports);
|
|
22
21
|
__exportStar(require("./guards/iam-context.guard"), exports);
|
|
23
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./helpers/user-owner.helper"), exports);
|
|
23
|
+
__exportStar(require("./interfaces/iam-entity-access.interface"), exports);
|
|
24
|
+
__exportStar(require("./interfaces/iam-context-options.interface"), exports);
|
|
25
|
+
__exportStar(require("./types/iam-entity-access.type"), exports);
|
|
26
|
+
__exportStar(require("./pipes/iam-paginate-query-scope.pipe"), exports);
|
|
27
|
+
__exportStar(require("./pipes/iam-find-one-query-scope.pipe"), exports);
|
|
28
|
+
__exportStar(require("./services/iam-entity-access.service"), exports);
|
|
24
29
|
__exportStar(require("./iam-context.module"), exports);
|
|
25
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qEAAmD;AACnD,2EAAyD;AACzD,mEAAiD;AACjD,6DAA2C;AAC3C,6DAA2C;AAC3C,8DAA4C;AAC5C,2EAAyD;AACzD,6EAA2D;AAC3D,iEAA+C;AAC/C,wEAAsD;AACtD,wEAAsD;AACtD,uEAAqD;AACrD,uDAAqC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { EntityTarget } from 'typeorm';
|
|
3
|
+
import { IamUserTypeEnum } from '../enums/iam-user-type.enum';
|
|
4
|
+
import { ApplyIamEntityScopeOptions, EntityAccessByRole } from './iam-entity-access.interface';
|
|
5
|
+
export type IamControllerMatcher = string | Type<any>;
|
|
6
|
+
export interface IamEntityAccessPreset<T = any> {
|
|
7
|
+
entity: EntityTarget<T>;
|
|
8
|
+
access?: EntityAccessByRole<T>;
|
|
9
|
+
scope?: Partial<ApplyIamEntityScopeOptions<T>>;
|
|
10
|
+
resourceName?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IamContextModuleOptions {
|
|
13
|
+
defaultAllowedUserTypes?: IamUserTypeEnum[];
|
|
14
|
+
allowRoutesWithoutIamDecorator?: boolean;
|
|
15
|
+
controllers?: {
|
|
16
|
+
select?: IamControllerMatcher[];
|
|
17
|
+
ignore?: IamControllerMatcher[];
|
|
18
|
+
};
|
|
19
|
+
entityAccess?: {
|
|
20
|
+
defaultAccess?: EntityAccessByRole<any>;
|
|
21
|
+
defaultScope?: Partial<ApplyIamEntityScopeOptions<any>>;
|
|
22
|
+
presets?: IamEntityAccessPreset<any>[];
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare const IAM_CONTEXT_MODULE_OPTIONS: unique symbol;
|
|
26
|
+
export declare const DEFAULT_IAM_CONTEXT_MODULE_OPTIONS: Required<Pick<IamContextModuleOptions, 'defaultAllowedUserTypes' | 'allowRoutesWithoutIamDecorator'>> & Omit<IamContextModuleOptions, 'defaultAllowedUserTypes' | 'allowRoutesWithoutIamDecorator'>;
|
|
27
|
+
//# sourceMappingURL=iam-context-options.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-context-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/iam-context-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EACnB,MAAM,+BAA+B,CAAC;AAEvC,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;AAEtD,MAAM,WAAW,qBAAqB,CAAC,CAAC,GAAG,GAAG;IAC5C,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAKxB,MAAM,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAK/B,KAAK,CAAC,EAAE,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAC;IAE/C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IAItC,uBAAuB,CAAC,EAAE,eAAe,EAAE,CAAC;IAM5C,8BAA8B,CAAC,EAAE,OAAO,CAAC;IAWzC,WAAW,CAAC,EAAE;QACZ,MAAM,CAAC,EAAE,oBAAoB,EAAE,CAAC;QAChC,MAAM,CAAC,EAAE,oBAAoB,EAAE,CAAC;KACjC,CAAC;IAEF,YAAY,CAAC,EAAE;QAIb,aAAa,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC,CAAC;QAKxC,YAAY,CAAC,EAAE,OAAO,CAAC,0BAA0B,CAAC,GAAG,CAAC,CAAC,CAAC;QAKxD,OAAO,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC;KACxC,CAAC;CACH;AAED,eAAO,MAAM,0BAA0B,eAAuC,CAAC;AAE/E,eAAO,MAAM,kCAAkC,EAAE,QAAQ,CACvD,IAAI,CACF,uBAAuB,EACvB,yBAAyB,GAAG,gCAAgC,CAC7D,CACF,GACC,IAAI,CACF,uBAAuB,EACvB,yBAAyB,GAAG,gCAAgC,CAa/D,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_IAM_CONTEXT_MODULE_OPTIONS = exports.IAM_CONTEXT_MODULE_OPTIONS = void 0;
|
|
4
|
+
exports.IAM_CONTEXT_MODULE_OPTIONS = Symbol('IAM_CONTEXT_MODULE_OPTIONS');
|
|
5
|
+
exports.DEFAULT_IAM_CONTEXT_MODULE_OPTIONS = {
|
|
6
|
+
defaultAllowedUserTypes: [],
|
|
7
|
+
allowRoutesWithoutIamDecorator: false,
|
|
8
|
+
controllers: {
|
|
9
|
+
select: [],
|
|
10
|
+
ignore: [],
|
|
11
|
+
},
|
|
12
|
+
entityAccess: {
|
|
13
|
+
defaultAccess: undefined,
|
|
14
|
+
defaultScope: undefined,
|
|
15
|
+
presets: [],
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=iam-context-options.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iam-context-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/iam-context-options.interface.ts"],"names":[],"mappings":";;;AAsEa,QAAA,0BAA0B,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAC;AAElE,QAAA,kCAAkC,GASzC;IACJ,uBAAuB,EAAE,EAAE;IAC3B,8BAA8B,EAAE,KAAK;IACrC,WAAW,EAAE;QACX,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE;KACX;IACD,YAAY,EAAE;QACZ,aAAa,EAAE,SAAS;QACxB,YAAY,EAAE,SAAS;QACvB,OAAO,EAAE,EAAE;KACZ;CACF,CAAC"}
|