@flusys/nestjs-iam 4.1.1 → 5.0.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 +87 -369
- package/cjs/config/message-keys.js +7 -49
- package/cjs/controllers/company-action-permission.controller.js +19 -18
- package/cjs/controllers/my-permission.controller.js +1 -4
- package/cjs/controllers/role-permission.controller.js +30 -20
- package/cjs/controllers/user-action-permission.controller.js +16 -11
- package/cjs/docs/iam-swagger.config.js +3 -2
- package/cjs/dtos/action.dto.js +0 -16
- package/cjs/dtos/permission.dto.js +4 -19
- package/cjs/dtos/role.dto.js +0 -16
- package/cjs/entities/action-base.entity.js +3 -8
- package/cjs/entities/permission-base.entity.js +1 -7
- package/cjs/entities/role-base.entity.js +1 -7
- package/cjs/services/action.service.js +1 -2
- package/cjs/services/permission.service.js +7 -14
- package/cjs/services/role.service.js +0 -1
- package/config/message-keys.d.ts +4 -84
- package/controllers/company-action-permission.controller.d.ts +3 -3
- package/controllers/role-permission.controller.d.ts +4 -4
- package/controllers/user-action-permission.controller.d.ts +3 -3
- package/docs/iam-swagger.config.d.ts +1 -1
- package/dtos/action.dto.d.ts +0 -2
- package/dtos/permission.dto.d.ts +1 -3
- package/dtos/role.dto.d.ts +0 -2
- package/entities/action-base.entity.d.ts +0 -1
- package/entities/permission-base.entity.d.ts +0 -1
- package/entities/role-base.entity.d.ts +0 -1
- package/fesm/config/message-keys.js +7 -44
- package/fesm/controllers/company-action-permission.controller.js +22 -21
- package/fesm/controllers/my-permission.controller.js +2 -5
- package/fesm/controllers/role-permission.controller.js +33 -23
- package/fesm/controllers/user-action-permission.controller.js +19 -14
- package/fesm/docs/iam-swagger.config.js +3 -2
- package/fesm/dtos/action.dto.js +0 -16
- package/fesm/dtos/permission.dto.js +4 -19
- package/fesm/dtos/role.dto.js +0 -16
- package/fesm/entities/action-base.entity.js +4 -9
- package/fesm/entities/permission-base.entity.js +1 -7
- package/fesm/entities/role-base.entity.js +1 -7
- package/fesm/services/action.service.js +1 -2
- package/fesm/services/permission.service.js +7 -14
- package/fesm/services/role.service.js +0 -1
- package/interfaces/action.interface.d.ts +0 -1
- package/interfaces/role.interface.d.ts +0 -1
- package/package.json +3 -3
|
@@ -546,19 +546,11 @@ _ts_decorate([
|
|
|
546
546
|
], MyPermissionsResponseDto.prototype, "cachedEndpoints", void 0);
|
|
547
547
|
export class PermissionOperationResultDto {
|
|
548
548
|
constructor(){
|
|
549
|
-
_define_property(this, "success", void 0);
|
|
550
549
|
_define_property(this, "added", void 0);
|
|
551
550
|
_define_property(this, "removed", void 0);
|
|
552
|
-
_define_property(this, "
|
|
553
|
-
_define_property(this, "messageKey", void 0);
|
|
551
|
+
_define_property(this, "total", void 0);
|
|
554
552
|
}
|
|
555
553
|
}
|
|
556
|
-
_ts_decorate([
|
|
557
|
-
ApiProperty({
|
|
558
|
-
description: 'Whether the operation succeeded'
|
|
559
|
-
}),
|
|
560
|
-
_ts_metadata("design:type", Boolean)
|
|
561
|
-
], PermissionOperationResultDto.prototype, "success", void 0);
|
|
562
554
|
_ts_decorate([
|
|
563
555
|
ApiProperty({
|
|
564
556
|
description: 'Number of permissions added'
|
|
@@ -573,14 +565,7 @@ _ts_decorate([
|
|
|
573
565
|
], PermissionOperationResultDto.prototype, "removed", void 0);
|
|
574
566
|
_ts_decorate([
|
|
575
567
|
ApiProperty({
|
|
576
|
-
description: '
|
|
568
|
+
description: 'Number of permissions requested'
|
|
577
569
|
}),
|
|
578
|
-
_ts_metadata("design:type",
|
|
579
|
-
], PermissionOperationResultDto.prototype, "
|
|
580
|
-
_ts_decorate([
|
|
581
|
-
ApiPropertyOptional({
|
|
582
|
-
description: 'Translation key for localization',
|
|
583
|
-
example: 'permission.process.success'
|
|
584
|
-
}),
|
|
585
|
-
_ts_metadata("design:type", String)
|
|
586
|
-
], PermissionOperationResultDto.prototype, "messageKey", void 0);
|
|
570
|
+
_ts_metadata("design:type", Number)
|
|
571
|
+
], PermissionOperationResultDto.prototype, "total", void 0);
|
package/fesm/dtos/role.dto.js
CHANGED
|
@@ -29,7 +29,6 @@ export class CreateRoleDto {
|
|
|
29
29
|
_define_property(this, "companyId", void 0);
|
|
30
30
|
_define_property(this, "isActive", void 0);
|
|
31
31
|
_define_property(this, "serial", void 0);
|
|
32
|
-
_define_property(this, "metadata", void 0);
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
_ts_decorate([
|
|
@@ -82,14 +81,6 @@ _ts_decorate([
|
|
|
82
81
|
IsOptional(),
|
|
83
82
|
_ts_metadata("design:type", Number)
|
|
84
83
|
], CreateRoleDto.prototype, "serial", void 0);
|
|
85
|
-
_ts_decorate([
|
|
86
|
-
ApiProperty({
|
|
87
|
-
description: 'Additional metadata',
|
|
88
|
-
required: false
|
|
89
|
-
}),
|
|
90
|
-
IsOptional(),
|
|
91
|
-
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
92
|
-
], CreateRoleDto.prototype, "metadata", void 0);
|
|
93
84
|
export class UpdateRoleDto extends PartialType(CreateRoleDto) {
|
|
94
85
|
constructor(...args){
|
|
95
86
|
super(...args), _define_property(this, "id", void 0);
|
|
@@ -113,7 +104,6 @@ export class RoleResponseDto {
|
|
|
113
104
|
_define_property(this, "companyId", void 0);
|
|
114
105
|
_define_property(this, "isActive", void 0);
|
|
115
106
|
_define_property(this, "serial", void 0);
|
|
116
|
-
_define_property(this, "metadata", void 0);
|
|
117
107
|
_define_property(this, "createdAt", void 0);
|
|
118
108
|
_define_property(this, "updatedAt", void 0);
|
|
119
109
|
_define_property(this, "deletedAt", void 0);
|
|
@@ -150,12 +140,6 @@ _ts_decorate([
|
|
|
150
140
|
ApiProperty(),
|
|
151
141
|
_ts_metadata("design:type", Object)
|
|
152
142
|
], RoleResponseDto.prototype, "serial", void 0);
|
|
153
|
-
_ts_decorate([
|
|
154
|
-
ApiProperty({
|
|
155
|
-
required: false
|
|
156
|
-
}),
|
|
157
|
-
_ts_metadata("design:type", Object)
|
|
158
|
-
], RoleResponseDto.prototype, "metadata", void 0);
|
|
159
143
|
_ts_decorate([
|
|
160
144
|
ApiProperty(),
|
|
161
145
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
@@ -20,7 +20,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
20
20
|
function _ts_metadata(k, v) {
|
|
21
21
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
22
|
}
|
|
23
|
-
import { Identity } from '@flusys/nestjs-shared';
|
|
23
|
+
import { getJsonColumnType, Identity } from '@flusys/nestjs-shared';
|
|
24
24
|
import { Column, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
|
25
25
|
import { ActionType } from '../enums';
|
|
26
26
|
/**
|
|
@@ -28,7 +28,7 @@ import { ActionType } from '../enums';
|
|
|
28
28
|
* Core action fields for all actions
|
|
29
29
|
*/ export class ActionBase extends Identity {
|
|
30
30
|
constructor(...args){
|
|
31
|
-
super(...args), _define_property(this, "readOnly", void 0), _define_property(this, "name", void 0), _define_property(this, "description", void 0), _define_property(this, "code", void 0), _define_property(this, "actionType", void 0), _define_property(this, "permissionLogic", void 0), _define_property(this, "serial", void 0), _define_property(this, "isActive", void 0), _define_property(this, "parent", void 0), _define_property(this, "parentId", void 0), _define_property(this, "children", void 0)
|
|
31
|
+
super(...args), _define_property(this, "readOnly", void 0), _define_property(this, "name", void 0), _define_property(this, "description", void 0), _define_property(this, "code", void 0), _define_property(this, "actionType", void 0), _define_property(this, "permissionLogic", void 0), _define_property(this, "serial", void 0), _define_property(this, "isActive", void 0), _define_property(this, "parent", void 0), _define_property(this, "parentId", void 0), _define_property(this, "children", void 0);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
_ts_decorate([
|
|
@@ -76,7 +76,8 @@ _ts_decorate([
|
|
|
76
76
|
_ts_metadata("design:type", typeof ActionType === "undefined" ? Object : ActionType)
|
|
77
77
|
], ActionBase.prototype, "actionType", void 0);
|
|
78
78
|
_ts_decorate([
|
|
79
|
-
Column(
|
|
79
|
+
Column({
|
|
80
|
+
type: getJsonColumnType(),
|
|
80
81
|
nullable: true,
|
|
81
82
|
name: 'permission_logic'
|
|
82
83
|
}),
|
|
@@ -120,9 +121,3 @@ _ts_decorate([
|
|
|
120
121
|
OneToMany('Action', 'parent'),
|
|
121
122
|
_ts_metadata("design:type", Array)
|
|
122
123
|
], ActionBase.prototype, "children", void 0);
|
|
123
|
-
_ts_decorate([
|
|
124
|
-
Column('simple-json', {
|
|
125
|
-
nullable: true
|
|
126
|
-
}),
|
|
127
|
-
_ts_metadata("design:type", Object)
|
|
128
|
-
], ActionBase.prototype, "metadata", void 0);
|
|
@@ -46,7 +46,7 @@ export var IamEntityType = /*#__PURE__*/ function(IamEntityType) {
|
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
48
|
constructor(...args){
|
|
49
|
-
super(...args), _define_property(this, "permissionType", void 0), _define_property(this, "sourceType", void 0), _define_property(this, "sourceId", void 0), _define_property(this, "targetType", void 0), _define_property(this, "targetId", void 0), _define_property(this, "userId", void 0), _define_property(this, "validFrom", void 0), _define_property(this, "validUntil", void 0), _define_property(this, "reason", void 0)
|
|
49
|
+
super(...args), _define_property(this, "permissionType", void 0), _define_property(this, "sourceType", void 0), _define_property(this, "sourceId", void 0), _define_property(this, "targetType", void 0), _define_property(this, "targetId", void 0), _define_property(this, "userId", void 0), _define_property(this, "validFrom", void 0), _define_property(this, "validUntil", void 0), _define_property(this, "reason", void 0);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
_ts_decorate([
|
|
@@ -118,9 +118,3 @@ _ts_decorate([
|
|
|
118
118
|
}),
|
|
119
119
|
_ts_metadata("design:type", Object)
|
|
120
120
|
], PermissionBase.prototype, "reason", void 0);
|
|
121
|
-
_ts_decorate([
|
|
122
|
-
Column('simple-json', {
|
|
123
|
-
nullable: true
|
|
124
|
-
}),
|
|
125
|
-
_ts_metadata("design:type", Object)
|
|
126
|
-
], PermissionBase.prototype, "metadata", void 0);
|
|
@@ -27,7 +27,7 @@ import { Column } from 'typeorm';
|
|
|
27
27
|
* Core role fields - always included regardless of company feature
|
|
28
28
|
*/ export class RoleBase extends Identity {
|
|
29
29
|
constructor(...args){
|
|
30
|
-
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)
|
|
30
|
+
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);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
_ts_decorate([
|
|
@@ -71,9 +71,3 @@ _ts_decorate([
|
|
|
71
71
|
}),
|
|
72
72
|
_ts_metadata("design:type", Object)
|
|
73
73
|
], RoleBase.prototype, "serial", void 0);
|
|
74
|
-
_ts_decorate([
|
|
75
|
-
Column('simple-json', {
|
|
76
|
-
nullable: true
|
|
77
|
-
}),
|
|
78
|
-
_ts_metadata("design:type", Object)
|
|
79
|
-
], RoleBase.prototype, "metadata", void 0);
|
|
@@ -85,7 +85,6 @@ export class ActionService extends RequestScopedApiService {
|
|
|
85
85
|
serial: entity.serial,
|
|
86
86
|
isActive: entity.isActive,
|
|
87
87
|
parentId: entity.parentId,
|
|
88
|
-
metadata: entity.metadata,
|
|
89
88
|
createdAt: entity.createdAt,
|
|
90
89
|
updatedAt: entity.updatedAt,
|
|
91
90
|
deletedAt: entity.deletedAt,
|
|
@@ -99,7 +98,7 @@ export class ActionService extends RequestScopedApiService {
|
|
|
99
98
|
throw new BadRequestException({
|
|
100
99
|
message: `User is required for ${methodName}`,
|
|
101
100
|
messageKey: PERMISSION_OPERATION_MESSAGES.USER_REQUIRED,
|
|
102
|
-
|
|
101
|
+
messageVariables: {
|
|
103
102
|
method: methodName
|
|
104
103
|
}
|
|
105
104
|
});
|
|
@@ -25,10 +25,10 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
import { IAM_MODE_MESSAGES, PERMISSION_OPERATION_MESSAGES } from '../config';
|
|
29
28
|
import { LogAction } from '@flusys/nestjs-shared';
|
|
30
29
|
import { BadRequestException, ConflictException, Inject, Injectable, Scope } from '@nestjs/common';
|
|
31
30
|
import { In, IsNull } from 'typeorm';
|
|
31
|
+
import { IAM_MODE_MESSAGES, PERMISSION_OPERATION_MESSAGES } from '../config';
|
|
32
32
|
import { AssignCompanyActionsDto, AssignRoleActionsDto, AssignUserActionsDto, AssignUserRolesDto, PermissionAction } from '../dtos/permission.dto';
|
|
33
33
|
import { Action } from '../entities/action.entity';
|
|
34
34
|
import { UserIamPermissionWithCompany } from '../entities/permission-with-company.entity';
|
|
@@ -255,8 +255,8 @@ export class PermissionService {
|
|
|
255
255
|
});
|
|
256
256
|
removed = result.affected || 0;
|
|
257
257
|
}
|
|
258
|
-
|
|
259
|
-
return this.buildOperationResult(dto.items.length, added, removed
|
|
258
|
+
await this.invalidateRoleMembersCache(dto.roleId);
|
|
259
|
+
return this.buildOperationResult(dto.items.length, added, removed);
|
|
260
260
|
}
|
|
261
261
|
async getRoleActions(roleId) {
|
|
262
262
|
const permissionRepo = await this.getPermissionRepository();
|
|
@@ -301,8 +301,6 @@ export class PermissionService {
|
|
|
301
301
|
const { toAdd: itemsToAdd, toRemove: itemsToRemove } = this.splitItemsByAction(dto.items);
|
|
302
302
|
let added = 0;
|
|
303
303
|
let removed = 0;
|
|
304
|
-
let removedRoleActions = 0;
|
|
305
|
-
let removedUserActions = 0;
|
|
306
304
|
await dataSource.transaction(async (manager)=>{
|
|
307
305
|
const transactionalPermissionRepo = manager.getRepository(permissionRepo.target);
|
|
308
306
|
if (itemsToAdd.length > 0) {
|
|
@@ -312,13 +310,10 @@ export class PermissionService {
|
|
|
312
310
|
const actionIdsToRemove = itemsToRemove.map((item)=>item.id);
|
|
313
311
|
const cascadeResult = await this.removeCompanyActionsWithCascade(manager, dto.companyId, actionIdsToRemove);
|
|
314
312
|
removed = cascadeResult.removedCompanyActions;
|
|
315
|
-
removedRoleActions = cascadeResult.removedRoleActions;
|
|
316
|
-
removedUserActions = cascadeResult.removedUserActions;
|
|
317
313
|
}
|
|
318
314
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
return this.buildOperationResult(dto.items.length, added, removed, `.${cascadeInfo} Invalidated ${affectedCacheEntries} cache entries.`);
|
|
315
|
+
await this.invalidateCompanyMembersCache(dto.companyId);
|
|
316
|
+
return this.buildOperationResult(dto.items.length, added, removed);
|
|
322
317
|
}
|
|
323
318
|
async addCompanyActions(permissionRepo, companyId, actionIds) {
|
|
324
319
|
const existingPermissions = await permissionRepo.find({
|
|
@@ -722,13 +717,11 @@ export class PermissionService {
|
|
|
722
717
|
toRemove: items.filter((item)=>item.action === PermissionAction.REMOVE)
|
|
723
718
|
};
|
|
724
719
|
}
|
|
725
|
-
/** Build standard operation result DTO */ buildOperationResult(
|
|
720
|
+
/** Build standard operation result DTO */ buildOperationResult(_totalItems, added, removed) {
|
|
726
721
|
return {
|
|
727
|
-
success: true,
|
|
728
722
|
added,
|
|
729
723
|
removed,
|
|
730
|
-
|
|
731
|
-
messageKey: PERMISSION_OPERATION_MESSAGES.PROCESS_SUCCESS
|
|
724
|
+
total: _totalItems
|
|
732
725
|
};
|
|
733
726
|
}
|
|
734
727
|
/** Get role IDs assigned to a user (merges company-wide + branch-specific roles) */ async getUserRoleIds(userId, branchId, companyId) {
|
|
@@ -102,7 +102,6 @@ export class RoleService extends RequestScopedApiService {
|
|
|
102
102
|
isActive: entity.isActive,
|
|
103
103
|
serial: entity.serial,
|
|
104
104
|
companyId: ('companyId' in entity ? entity.companyId : null) ?? null,
|
|
105
|
-
metadata: entity.metadata,
|
|
106
105
|
createdAt: entity.createdAt,
|
|
107
106
|
updatedAt: entity.updatedAt,
|
|
108
107
|
deletedAt: entity.deletedAt,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flusys/nestjs-iam",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Identity and Access Management (IAM) module for NestJS applications",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "fesm/index.js",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"express": "^4.18.0"
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
|
-
"@flusys/nestjs-core": "
|
|
94
|
-
"@flusys/nestjs-shared": "
|
|
93
|
+
"@flusys/nestjs-core": "5.0.1",
|
|
94
|
+
"@flusys/nestjs-shared": "5.0.1"
|
|
95
95
|
}
|
|
96
96
|
}
|