@flusys/nestjs-iam 0.1.0-alpha.1 → 0.1.0-beta.2
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 +665 -0
- package/cjs/config/iam.constants.js +11 -0
- package/cjs/config/index.js +18 -0
- package/cjs/controllers/action.controller.js +117 -0
- package/cjs/controllers/company-action-permission.controller.js +110 -0
- package/cjs/controllers/index.js +23 -0
- package/cjs/controllers/my-permission.controller.js +90 -0
- package/cjs/controllers/role-permission.controller.js +160 -0
- package/cjs/controllers/role.controller.js +58 -0
- package/cjs/controllers/user-action-permission.controller.js +110 -0
- package/cjs/docs/iam-swagger.config.js +202 -0
- package/cjs/docs/index.js +18 -0
- package/cjs/dtos/action.dto.js +347 -0
- package/cjs/dtos/index.js +21 -0
- package/cjs/dtos/permission.dto.js +554 -0
- package/cjs/dtos/role.dto.js +238 -0
- package/cjs/entities/action-base.entity.js +135 -0
- package/cjs/entities/action.entity.js +28 -0
- package/cjs/entities/index.js +81 -0
- package/cjs/entities/permission-base.entity.js +156 -0
- package/cjs/entities/permission-with-company.entity.js +99 -0
- package/cjs/entities/role-base.entity.js +86 -0
- package/cjs/entities/role-with-company.entity.js +55 -0
- package/cjs/entities/role.entity.js +25 -0
- package/cjs/entities/user-iam-permission.entity.js +57 -0
- package/cjs/enums/action-type.enum.js +22 -0
- package/cjs/enums/index.js +19 -0
- package/cjs/enums/permission-type.enum.js +16 -0
- package/cjs/helpers/index.js +19 -0
- package/cjs/helpers/permission-evaluator.helper.js +175 -0
- package/cjs/helpers/permission-mode.helper.js +49 -0
- package/cjs/index.js +28 -79
- package/cjs/interfaces/action.interface.js +4 -0
- package/cjs/interfaces/iam-module-async-options.interface.js +4 -0
- package/cjs/interfaces/iam-module-options.interface.js +18 -0
- package/cjs/interfaces/index.js +21 -0
- package/cjs/interfaces/role.interface.js +7 -0
- package/cjs/modules/iam.module.js +237 -0
- package/cjs/modules/index.js +18 -0
- package/cjs/services/action.service.js +253 -0
- package/cjs/services/iam-config.service.js +107 -0
- package/cjs/services/iam-datasource.provider.js +205 -0
- package/cjs/services/index.js +23 -0
- package/cjs/services/permission-cache.service.js +308 -0
- package/cjs/services/permission.service.js +1020 -0
- package/cjs/services/role.service.js +181 -0
- package/cjs/types/index.js +18 -0
- package/cjs/types/logic-node.type.js +54 -0
- package/fesm/config/iam.constants.js +1 -0
- package/fesm/config/index.js +1 -0
- package/fesm/controllers/action.controller.js +107 -0
- package/fesm/controllers/company-action-permission.controller.js +100 -0
- package/fesm/controllers/index.js +7 -0
- package/fesm/controllers/my-permission.controller.js +80 -0
- package/fesm/controllers/role-permission.controller.js +150 -0
- package/fesm/controllers/role.controller.js +48 -0
- package/fesm/controllers/user-action-permission.controller.js +100 -0
- package/fesm/docs/iam-swagger.config.js +192 -0
- package/fesm/docs/index.js +1 -0
- package/fesm/dtos/action.dto.js +317 -0
- package/fesm/dtos/index.js +4 -0
- package/fesm/dtos/permission.dto.js +490 -0
- package/fesm/dtos/role.dto.js +214 -0
- package/fesm/entities/action-base.entity.js +128 -0
- package/fesm/entities/action.entity.js +18 -0
- package/fesm/entities/index.js +56 -0
- package/fesm/entities/permission-base.entity.js +138 -0
- package/fesm/entities/permission-with-company.entity.js +89 -0
- package/fesm/entities/role-base.entity.js +79 -0
- package/fesm/entities/role-with-company.entity.js +45 -0
- package/fesm/entities/role.entity.js +15 -0
- package/fesm/entities/user-iam-permission.entity.js +38 -0
- package/fesm/enums/action-type.enum.js +12 -0
- package/fesm/enums/index.js +2 -0
- package/fesm/enums/permission-type.enum.js +6 -0
- package/fesm/helpers/index.js +2 -0
- package/fesm/helpers/permission-evaluator.helper.js +165 -0
- package/fesm/helpers/permission-mode.helper.js +49 -0
- package/fesm/index.js +11 -79
- package/fesm/interfaces/action.interface.js +3 -0
- package/fesm/interfaces/iam-module-async-options.interface.js +3 -0
- package/fesm/interfaces/iam-module-options.interface.js +1 -0
- package/fesm/interfaces/index.js +4 -0
- package/fesm/interfaces/role.interface.js +4 -0
- package/fesm/modules/iam.module.js +227 -0
- package/fesm/modules/index.js +1 -0
- package/fesm/services/action.service.js +243 -0
- package/fesm/services/iam-config.service.js +97 -0
- package/fesm/services/iam-datasource.provider.js +154 -0
- package/fesm/services/index.js +6 -0
- package/fesm/services/permission-cache.service.js +298 -0
- package/fesm/services/permission.service.js +1010 -0
- package/fesm/services/role.service.js +171 -0
- package/fesm/types/index.js +1 -0
- package/fesm/types/logic-node.type.js +36 -0
- package/package.json +25 -25
- package/cjs/config-index.js +0 -1
- package/cjs/controllers-index.js +0 -1
- package/cjs/docs-index.js +0 -79
- package/cjs/dtos-index.js +0 -1
- package/cjs/entities-index.js +0 -1
- package/cjs/enums-index.js +0 -1
- package/cjs/helpers-index.js +0 -1
- package/cjs/interfaces-index.js +0 -1
- package/cjs/modules-index.js +0 -1
- package/cjs/services-index.js +0 -1
- package/cjs/types-index.js +0 -1
- package/fesm/config-index.js +0 -1
- package/fesm/controllers-index.js +0 -1
- package/fesm/docs-index.js +0 -79
- package/fesm/dtos-index.js +0 -1
- package/fesm/entities-index.js +0 -1
- package/fesm/enums-index.js +0 -1
- package/fesm/helpers-index.js +0 -1
- package/fesm/interfaces-index.js +0 -0
- package/fesm/modules-index.js +0 -1
- package/fesm/services-index.js +0 -1
- package/fesm/types-index.js +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "UserIamPermissionWithCompany", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return UserIamPermissionWithCompany;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _typeorm = require("typeorm");
|
|
12
|
+
const _permissionbaseentity = require("./permission-base.entity");
|
|
13
|
+
function _define_property(obj, key, value) {
|
|
14
|
+
if (key in obj) {
|
|
15
|
+
Object.defineProperty(obj, key, {
|
|
16
|
+
value: value,
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
obj[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
27
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
29
|
+
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;
|
|
30
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
|
+
}
|
|
32
|
+
function _ts_metadata(k, v) {
|
|
33
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
34
|
+
}
|
|
35
|
+
let UserIamPermissionWithCompany = class UserIamPermissionWithCompany extends _permissionbaseentity.PermissionBase {
|
|
36
|
+
constructor(...args){
|
|
37
|
+
super(...args), /**
|
|
38
|
+
* Company ID - Company scope for this permission
|
|
39
|
+
* - null: Global permission (not company-specific)
|
|
40
|
+
* - set: Permission belongs to this company
|
|
41
|
+
*/ _define_property(this, "companyId", void 0), /**
|
|
42
|
+
* Branch ID - Branch scope for this permission
|
|
43
|
+
* - null: Company-wide permission (all branches in company)
|
|
44
|
+
* - set: Permission applies only to this specific branch
|
|
45
|
+
*/ _define_property(this, "branchId", void 0);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
_ts_decorate([
|
|
49
|
+
(0, _typeorm.Column)({
|
|
50
|
+
type: 'uuid',
|
|
51
|
+
nullable: true,
|
|
52
|
+
name: 'company_id'
|
|
53
|
+
}),
|
|
54
|
+
_ts_metadata("design:type", Object)
|
|
55
|
+
], UserIamPermissionWithCompany.prototype, "companyId", void 0);
|
|
56
|
+
_ts_decorate([
|
|
57
|
+
(0, _typeorm.Column)({
|
|
58
|
+
type: 'uuid',
|
|
59
|
+
nullable: true,
|
|
60
|
+
name: 'branch_id'
|
|
61
|
+
}),
|
|
62
|
+
_ts_metadata("design:type", Object)
|
|
63
|
+
], UserIamPermissionWithCompany.prototype, "branchId", void 0);
|
|
64
|
+
UserIamPermissionWithCompany = _ts_decorate([
|
|
65
|
+
(0, _typeorm.Entity)({
|
|
66
|
+
name: 'user_iam_permission'
|
|
67
|
+
}),
|
|
68
|
+
(0, _typeorm.Index)([
|
|
69
|
+
'permissionType',
|
|
70
|
+
'sourceId',
|
|
71
|
+
'targetId'
|
|
72
|
+
], {
|
|
73
|
+
unique: true
|
|
74
|
+
}),
|
|
75
|
+
(0, _typeorm.Index)([
|
|
76
|
+
'sourceId',
|
|
77
|
+
'sourceType'
|
|
78
|
+
]),
|
|
79
|
+
(0, _typeorm.Index)([
|
|
80
|
+
'targetId',
|
|
81
|
+
'targetType'
|
|
82
|
+
]),
|
|
83
|
+
(0, _typeorm.Index)([
|
|
84
|
+
'permissionType'
|
|
85
|
+
]),
|
|
86
|
+
(0, _typeorm.Index)([
|
|
87
|
+
'userId'
|
|
88
|
+
]),
|
|
89
|
+
(0, _typeorm.Index)([
|
|
90
|
+
'companyId'
|
|
91
|
+
]),
|
|
92
|
+
(0, _typeorm.Index)([
|
|
93
|
+
'branchId'
|
|
94
|
+
]),
|
|
95
|
+
(0, _typeorm.Index)([
|
|
96
|
+
'companyId',
|
|
97
|
+
'branchId'
|
|
98
|
+
])
|
|
99
|
+
], UserIamPermissionWithCompany);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "RoleBase", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return RoleBase;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _nestjsshared = require("@flusys/nestjs-shared");
|
|
12
|
+
const _typeorm = require("typeorm");
|
|
13
|
+
function _define_property(obj, key, value) {
|
|
14
|
+
if (key in obj) {
|
|
15
|
+
Object.defineProperty(obj, key, {
|
|
16
|
+
value: value,
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
obj[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
27
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
29
|
+
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;
|
|
30
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
|
+
}
|
|
32
|
+
function _ts_metadata(k, v) {
|
|
33
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
34
|
+
}
|
|
35
|
+
let RoleBase = class RoleBase extends _nestjsshared.Identity {
|
|
36
|
+
constructor(...args){
|
|
37
|
+
super(...args), _define_property(this, "readOnly", void 0), _define_property(this, "name", void 0), _define_property(this, "description", void 0), _define_property(this, "isActive", void 0), _define_property(this, "serial", void 0), _define_property(this, "metadata", void 0);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
_ts_decorate([
|
|
41
|
+
(0, _typeorm.Column)({
|
|
42
|
+
type: 'boolean',
|
|
43
|
+
nullable: false,
|
|
44
|
+
default: false,
|
|
45
|
+
name: 'read_only'
|
|
46
|
+
}),
|
|
47
|
+
_ts_metadata("design:type", Boolean)
|
|
48
|
+
], RoleBase.prototype, "readOnly", void 0);
|
|
49
|
+
_ts_decorate([
|
|
50
|
+
(0, _typeorm.Column)({
|
|
51
|
+
type: 'varchar',
|
|
52
|
+
length: 255,
|
|
53
|
+
nullable: false
|
|
54
|
+
}),
|
|
55
|
+
_ts_metadata("design:type", String)
|
|
56
|
+
], RoleBase.prototype, "name", void 0);
|
|
57
|
+
_ts_decorate([
|
|
58
|
+
(0, _typeorm.Column)({
|
|
59
|
+
type: 'varchar',
|
|
60
|
+
length: 500,
|
|
61
|
+
nullable: true
|
|
62
|
+
}),
|
|
63
|
+
_ts_metadata("design:type", Object)
|
|
64
|
+
], RoleBase.prototype, "description", void 0);
|
|
65
|
+
_ts_decorate([
|
|
66
|
+
(0, _typeorm.Column)({
|
|
67
|
+
type: 'boolean',
|
|
68
|
+
nullable: false,
|
|
69
|
+
default: true,
|
|
70
|
+
name: 'is_active'
|
|
71
|
+
}),
|
|
72
|
+
_ts_metadata("design:type", Boolean)
|
|
73
|
+
], RoleBase.prototype, "isActive", void 0);
|
|
74
|
+
_ts_decorate([
|
|
75
|
+
(0, _typeorm.Column)({
|
|
76
|
+
type: 'int',
|
|
77
|
+
nullable: true
|
|
78
|
+
}),
|
|
79
|
+
_ts_metadata("design:type", Object)
|
|
80
|
+
], RoleBase.prototype, "serial", void 0);
|
|
81
|
+
_ts_decorate([
|
|
82
|
+
(0, _typeorm.Column)('simple-json', {
|
|
83
|
+
nullable: true
|
|
84
|
+
}),
|
|
85
|
+
_ts_metadata("design:type", Object)
|
|
86
|
+
], RoleBase.prototype, "metadata", void 0);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "RoleWithCompany", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return RoleWithCompany;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _typeorm = require("typeorm");
|
|
12
|
+
const _rolebaseentity = require("./role-base.entity");
|
|
13
|
+
function _define_property(obj, key, value) {
|
|
14
|
+
if (key in obj) {
|
|
15
|
+
Object.defineProperty(obj, key, {
|
|
16
|
+
value: value,
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
obj[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
27
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
29
|
+
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;
|
|
30
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
31
|
+
}
|
|
32
|
+
function _ts_metadata(k, v) {
|
|
33
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
34
|
+
}
|
|
35
|
+
let RoleWithCompany = class RoleWithCompany extends _rolebaseentity.RoleBase {
|
|
36
|
+
constructor(...args){
|
|
37
|
+
super(...args), _define_property(this, "companyId", void 0);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
_ts_decorate([
|
|
41
|
+
(0, _typeorm.Column)({
|
|
42
|
+
type: 'uuid',
|
|
43
|
+
nullable: true,
|
|
44
|
+
name: 'company_id'
|
|
45
|
+
}),
|
|
46
|
+
_ts_metadata("design:type", Object)
|
|
47
|
+
], RoleWithCompany.prototype, "companyId", void 0);
|
|
48
|
+
RoleWithCompany = _ts_decorate([
|
|
49
|
+
(0, _typeorm.Entity)({
|
|
50
|
+
name: 'role'
|
|
51
|
+
}),
|
|
52
|
+
(0, _typeorm.Index)([
|
|
53
|
+
'companyId'
|
|
54
|
+
])
|
|
55
|
+
], RoleWithCompany);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Role", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Role;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _typeorm = require("typeorm");
|
|
12
|
+
const _rolebaseentity = require("./role-base.entity");
|
|
13
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
14
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
16
|
+
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;
|
|
17
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
18
|
+
}
|
|
19
|
+
let Role = class Role extends _rolebaseentity.RoleBase {
|
|
20
|
+
};
|
|
21
|
+
Role = _ts_decorate([
|
|
22
|
+
(0, _typeorm.Entity)({
|
|
23
|
+
name: 'role'
|
|
24
|
+
})
|
|
25
|
+
], Role);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get IamEntityType () {
|
|
13
|
+
return _permissionbaseentity.IamEntityType;
|
|
14
|
+
},
|
|
15
|
+
get IamPermissionType () {
|
|
16
|
+
return _permissionbaseentity.IamPermissionType;
|
|
17
|
+
},
|
|
18
|
+
get UserIamPermission () {
|
|
19
|
+
return UserIamPermission;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _typeorm = require("typeorm");
|
|
23
|
+
const _permissionbaseentity = require("./permission-base.entity");
|
|
24
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
25
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
+
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;
|
|
28
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
+
}
|
|
30
|
+
let UserIamPermission = class UserIamPermission extends _permissionbaseentity.PermissionBase {
|
|
31
|
+
};
|
|
32
|
+
UserIamPermission = _ts_decorate([
|
|
33
|
+
(0, _typeorm.Entity)({
|
|
34
|
+
name: 'user_iam_permission'
|
|
35
|
+
}),
|
|
36
|
+
(0, _typeorm.Index)([
|
|
37
|
+
'permissionType',
|
|
38
|
+
'sourceId',
|
|
39
|
+
'targetId'
|
|
40
|
+
], {
|
|
41
|
+
unique: true
|
|
42
|
+
}),
|
|
43
|
+
(0, _typeorm.Index)([
|
|
44
|
+
'sourceId',
|
|
45
|
+
'sourceType'
|
|
46
|
+
]),
|
|
47
|
+
(0, _typeorm.Index)([
|
|
48
|
+
'targetId',
|
|
49
|
+
'targetType'
|
|
50
|
+
]),
|
|
51
|
+
(0, _typeorm.Index)([
|
|
52
|
+
'permissionType'
|
|
53
|
+
]),
|
|
54
|
+
(0, _typeorm.Index)([
|
|
55
|
+
'userId'
|
|
56
|
+
])
|
|
57
|
+
], UserIamPermission);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ActionType Enum - Categorizes actions by their usage context
|
|
3
|
+
*
|
|
4
|
+
* - BACKEND: Actions for API endpoint permissions (cached for PermissionGuard)
|
|
5
|
+
* - FRONTEND: Actions for frontend features (returned in my-permissions API)
|
|
6
|
+
* - BOTH: Actions used for both backend and frontend (cached + returned)
|
|
7
|
+
*/ "use strict";
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "ActionType", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return ActionType;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
var ActionType = /*#__PURE__*/ function(ActionType) {
|
|
18
|
+
ActionType["BACKEND"] = "backend";
|
|
19
|
+
ActionType["FRONTEND"] = "frontend";
|
|
20
|
+
ActionType["BOTH"] = "both";
|
|
21
|
+
return ActionType;
|
|
22
|
+
}({});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./action-type.enum"), exports);
|
|
6
|
+
_export_star(require("./permission-type.enum"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "IAMPermissionMode", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return IAMPermissionMode;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var IAMPermissionMode = /*#__PURE__*/ function(IAMPermissionMode) {
|
|
12
|
+
IAMPermissionMode[IAMPermissionMode["RBAC"] = 1] = "RBAC";
|
|
13
|
+
IAMPermissionMode[IAMPermissionMode["DIRECT"] = 2] = "DIRECT";
|
|
14
|
+
IAMPermissionMode[IAMPermissionMode["FULL"] = 3] = "FULL";
|
|
15
|
+
return IAMPermissionMode;
|
|
16
|
+
}({});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./permission-evaluator.helper"), exports);
|
|
6
|
+
_export_star(require("./permission-mode.helper"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "PermissionEvaluatorHelper", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return PermissionEvaluatorHelper;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("@nestjs/common");
|
|
12
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
13
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
15
|
+
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;
|
|
16
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
17
|
+
}
|
|
18
|
+
let PermissionEvaluatorHelper = class PermissionEvaluatorHelper {
|
|
19
|
+
/**
|
|
20
|
+
* Evaluate if user has access based on permission logic
|
|
21
|
+
*
|
|
22
|
+
* @param logic - Permission logic to evaluate
|
|
23
|
+
* @param context - User permission context
|
|
24
|
+
* @returns true if user has access, false otherwise
|
|
25
|
+
*/ evaluate(logic, context) {
|
|
26
|
+
// If no logic defined, access is granted
|
|
27
|
+
if (!logic) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return this.evaluateNode(logic, context);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Evaluate a single logic node
|
|
34
|
+
*/ evaluateNode(node, context) {
|
|
35
|
+
switch(node.type){
|
|
36
|
+
case 'action':
|
|
37
|
+
return this.evaluateAction(node.actionId, context);
|
|
38
|
+
case 'group':
|
|
39
|
+
return this.evaluateGroup(node, context);
|
|
40
|
+
default:
|
|
41
|
+
// Unknown node type, deny access
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Evaluate action permission
|
|
47
|
+
* Priority: Deny > Grant > Inherited
|
|
48
|
+
*/ evaluateAction(actionId, context) {
|
|
49
|
+
// 1. Check explicit deny (highest priority)
|
|
50
|
+
if (context.deniedActionIds.has(actionId)) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
// 2. Check explicit grant
|
|
54
|
+
if (context.grantedActionIds.has(actionId)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
// 3. Check inherited actions (from parent actions)
|
|
58
|
+
if (context.inheritedActionIds?.has(actionId)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
// No permission found
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Evaluate group (AND/OR logic)
|
|
66
|
+
*/ evaluateGroup(node, context) {
|
|
67
|
+
if (!node.children || node.children.length === 0) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const results = node.children.map((child)=>this.evaluateNode(child, context));
|
|
71
|
+
if (node.operator === 'AND') {
|
|
72
|
+
// ALL children must be true
|
|
73
|
+
return results.every((result)=>result === true);
|
|
74
|
+
} else if (node.operator === 'OR') {
|
|
75
|
+
// ANY child must be true
|
|
76
|
+
return results.some((result)=>result === true);
|
|
77
|
+
}
|
|
78
|
+
// Unknown operator, deny access
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Batch evaluate multiple logic nodes
|
|
83
|
+
* Useful for checking multiple permissions at once
|
|
84
|
+
*
|
|
85
|
+
* @param logics - Array of logic nodes to evaluate
|
|
86
|
+
* @param context - User permission context
|
|
87
|
+
* @returns Map of logic ID to evaluation result
|
|
88
|
+
*/ batchEvaluate(logics, context) {
|
|
89
|
+
const results = new Map();
|
|
90
|
+
for (const item of logics){
|
|
91
|
+
results.set(item.id, this.evaluate(item.logic, context));
|
|
92
|
+
}
|
|
93
|
+
return results;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check if user has ANY of the specified actions
|
|
97
|
+
*
|
|
98
|
+
* @param actionIds - Array of action IDs
|
|
99
|
+
* @param context - User permission context
|
|
100
|
+
* @returns true if user has at least one action
|
|
101
|
+
*/ hasAnyAction(actionIds, context) {
|
|
102
|
+
return actionIds.some((actionId)=>this.evaluateAction(actionId, context));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Check if user has ALL of the specified actions
|
|
106
|
+
*
|
|
107
|
+
* @param actionIds - Array of action IDs
|
|
108
|
+
* @param context - User permission context
|
|
109
|
+
* @returns true if user has all actions
|
|
110
|
+
*/ hasAllActions(actionIds, context) {
|
|
111
|
+
return actionIds.every((actionId)=>this.evaluateAction(actionId, context));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Check if user has ANY of the specified roles
|
|
115
|
+
*
|
|
116
|
+
* @param roleIds - Array of role IDs
|
|
117
|
+
* @param context - User permission context
|
|
118
|
+
* @returns true if user has at least one role
|
|
119
|
+
*/ hasAnyRole(roleIds, context) {
|
|
120
|
+
return roleIds.some((roleId)=>context.roleIds.has(roleId));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if user has ALL of the specified roles
|
|
124
|
+
*
|
|
125
|
+
* @param roleIds - Array of role IDs
|
|
126
|
+
* @param context - User permission context
|
|
127
|
+
* @returns true if user has all roles
|
|
128
|
+
*/ hasAllRoles(roleIds, context) {
|
|
129
|
+
return roleIds.every((roleId)=>context.roleIds.has(roleId));
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Simplified evaluation for menu filtering
|
|
133
|
+
* Uses action codes instead of action IDs
|
|
134
|
+
*
|
|
135
|
+
* @param logic - Permission logic to evaluate
|
|
136
|
+
* @param actionCodes - Set of action codes the user has
|
|
137
|
+
* @returns true if user has access, false otherwise
|
|
138
|
+
*/ evaluateLogicNode(logic, actionCodes) {
|
|
139
|
+
if (!logic) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
return this.evaluateNodeSimple(logic, actionCodes);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Simplified node evaluation using codes
|
|
146
|
+
*/ evaluateNodeSimple(node, actionCodes) {
|
|
147
|
+
switch(node.type){
|
|
148
|
+
case 'action':
|
|
149
|
+
// Check if user has action by actionId (which matches action.code)
|
|
150
|
+
return node.actionId ? actionCodes.has(node.actionId) : false;
|
|
151
|
+
case 'group':
|
|
152
|
+
return this.evaluateGroupSimple(node, actionCodes);
|
|
153
|
+
default:
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Simplified group evaluation
|
|
159
|
+
*/ evaluateGroupSimple(node, actionCodes) {
|
|
160
|
+
if (!node.children || node.children.length === 0) {
|
|
161
|
+
// Empty AND = true, Empty OR = false
|
|
162
|
+
return node.operator === 'AND';
|
|
163
|
+
}
|
|
164
|
+
const results = node.children.map((child)=>this.evaluateNodeSimple(child, actionCodes));
|
|
165
|
+
if (node.operator === 'AND') {
|
|
166
|
+
return results.every((result)=>result === true);
|
|
167
|
+
} else if (node.operator === 'OR') {
|
|
168
|
+
return results.some((result)=>result === true);
|
|
169
|
+
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
PermissionEvaluatorHelper = _ts_decorate([
|
|
174
|
+
(0, _common.Injectable)()
|
|
175
|
+
], PermissionEvaluatorHelper);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "PermissionModeHelper", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return PermissionModeHelper;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _permissiontypeenum = require("../enums/permission-type.enum");
|
|
12
|
+
let PermissionModeHelper = class PermissionModeHelper {
|
|
13
|
+
/**
|
|
14
|
+
* Convert permission mode string to enum value
|
|
15
|
+
*
|
|
16
|
+
* @param modeStr - Permission mode string ('FULL', 'RBAC', 'DIRECT')
|
|
17
|
+
* @returns IAMPermissionMode enum value
|
|
18
|
+
* @default IAMPermissionMode.FULL if invalid/missing
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const mode = PermissionModeHelper.fromString('RBAC');
|
|
23
|
+
* // Returns: IAMPermissionMode.RBAC
|
|
24
|
+
*
|
|
25
|
+
* const mode = PermissionModeHelper.fromString(undefined);
|
|
26
|
+
* // Returns: IAMPermissionMode.FULL (default)
|
|
27
|
+
* ```
|
|
28
|
+
*/ static fromString(modeStr) {
|
|
29
|
+
if (!modeStr) {
|
|
30
|
+
return _permissiontypeenum.IAMPermissionMode.FULL;
|
|
31
|
+
}
|
|
32
|
+
const mode = _permissiontypeenum.IAMPermissionMode[modeStr];
|
|
33
|
+
return mode ?? _permissiontypeenum.IAMPermissionMode.FULL;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert enum value to string (for serialization/logging)
|
|
37
|
+
*
|
|
38
|
+
* @param mode - IAMPermissionMode enum value
|
|
39
|
+
* @returns String representation
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const str = PermissionModeHelper.toString(IAMPermissionMode.RBAC);
|
|
44
|
+
* // Returns: 'RBAC'
|
|
45
|
+
* ```
|
|
46
|
+
*/ static toString(mode) {
|
|
47
|
+
return _permissiontypeenum.IAMPermissionMode[mode];
|
|
48
|
+
}
|
|
49
|
+
};
|