@flusys/nestjs-iam 7.0.2 → 8.0.0-beta.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.
Files changed (173) hide show
  1. package/config/index.d.ts +3 -3
  2. package/controllers/action.controller.d.ts +4 -4
  3. package/controllers/company-action-permission.controller.d.ts +2 -2
  4. package/controllers/index.d.ts +6 -6
  5. package/controllers/my-permission.controller.d.ts +3 -3
  6. package/controllers/role-permission.controller.d.ts +4 -4
  7. package/controllers/role.controller.d.ts +2 -2
  8. package/controllers/user-action-permission.controller.d.ts +4 -4
  9. package/docs/iam-swagger.config.d.ts +2 -2
  10. package/docs/index.d.ts +1 -1
  11. package/dtos/action.dto.d.ts +2 -2
  12. package/dtos/index.d.ts +3 -3
  13. package/entities/action.entity.d.ts +2 -2
  14. package/entities/index.d.ts +11 -11
  15. package/entities/permission-with-company.entity.d.ts +1 -1
  16. package/entities/role-with-company.entity.d.ts +1 -1
  17. package/entities/role.entity.d.ts +1 -1
  18. package/entities/user-iam-permission.entity.d.ts +1 -1
  19. package/enums/index.d.ts +4 -4
  20. package/fesm/284.js +1262 -0
  21. package/fesm/867.js +3699 -0
  22. package/fesm/chunks/364.js +86 -0
  23. package/fesm/config/index.js +133 -3
  24. package/fesm/controllers/index.js +18 -7
  25. package/fesm/docs/index.js +240 -1
  26. package/fesm/dtos/index.js +1090 -3
  27. package/fesm/entities/index.js +670 -31
  28. package/fesm/enums/index.js +97 -4
  29. package/fesm/helpers/index.js +125 -2
  30. package/fesm/index.js +806 -11
  31. package/fesm/interfaces/index.js +17 -3
  32. package/fesm/modules/index.js +259 -1
  33. package/fesm/runtime.js +134 -0
  34. package/fesm/services/index.js +43 -6
  35. package/fesm/types/index.js +15 -1
  36. package/helpers/company-access.helper.d.ts +2 -2
  37. package/helpers/index.d.ts +2 -2
  38. package/helpers/permission-mode.helper.d.ts +1 -1
  39. package/index.d.ts +11 -11
  40. package/interfaces/action.interface.d.ts +2 -2
  41. package/interfaces/iam-module-options.interface.d.ts +3 -3
  42. package/interfaces/index.d.ts +3 -3
  43. package/modules/iam.module.d.ts +2 -2
  44. package/modules/index.d.ts +1 -1
  45. package/package.json +30 -37
  46. package/services/action.service.d.ts +9 -9
  47. package/services/iam-config.service.d.ts +4 -4
  48. package/services/iam-datasource.service.d.ts +3 -3
  49. package/services/index.d.ts +6 -6
  50. package/services/permission-cache.service.d.ts +5 -5
  51. package/services/permission.service.d.ts +4 -4
  52. package/services/role.service.d.ts +8 -8
  53. package/types/index.d.ts +1 -1
  54. package/cjs/config/event-actions.js +0 -36
  55. package/cjs/config/iam.constants.js +0 -11
  56. package/cjs/config/index.js +0 -20
  57. package/cjs/config/message-keys.js +0 -71
  58. package/cjs/controllers/action.controller.js +0 -174
  59. package/cjs/controllers/action.controller.spec.js +0 -79
  60. package/cjs/controllers/company-action-permission.controller.js +0 -119
  61. package/cjs/controllers/company-action-permission.controller.spec.js +0 -65
  62. package/cjs/controllers/index.js +0 -23
  63. package/cjs/controllers/my-permission.controller.js +0 -147
  64. package/cjs/controllers/my-permission.controller.spec.js +0 -128
  65. package/cjs/controllers/role-permission.controller.js +0 -191
  66. package/cjs/controllers/role-permission.controller.spec.js +0 -140
  67. package/cjs/controllers/role.controller.js +0 -102
  68. package/cjs/controllers/role.controller.spec.js +0 -86
  69. package/cjs/controllers/user-action-permission.controller.js +0 -129
  70. package/cjs/controllers/user-action-permission.controller.spec.js +0 -68
  71. package/cjs/docs/iam-swagger.config.js +0 -209
  72. package/cjs/docs/iam-swagger.config.spec.js +0 -99
  73. package/cjs/docs/index.js +0 -18
  74. package/cjs/dtos/action.dto.js +0 -282
  75. package/cjs/dtos/index.js +0 -21
  76. package/cjs/dtos/permission.dto.js +0 -637
  77. package/cjs/dtos/role.dto.js +0 -155
  78. package/cjs/entities/action.entity.js +0 -138
  79. package/cjs/entities/index.js +0 -80
  80. package/cjs/entities/index.spec.js +0 -56
  81. package/cjs/entities/permission-base.entity.js +0 -107
  82. package/cjs/entities/permission-with-company.entity.js +0 -100
  83. package/cjs/entities/role-base.entity.js +0 -80
  84. package/cjs/entities/role-with-company.entity.js +0 -55
  85. package/cjs/entities/role.entity.js +0 -25
  86. package/cjs/entities/user-iam-permission.entity.js +0 -43
  87. package/cjs/enums/action-type.enum.js +0 -22
  88. package/cjs/enums/iam-entity-type.enum.js +0 -17
  89. package/cjs/enums/iam-permission-type.enum.js +0 -17
  90. package/cjs/enums/index.js +0 -21
  91. package/cjs/enums/permission-type.enum.js +0 -16
  92. package/cjs/helpers/company-access.helper.js +0 -23
  93. package/cjs/helpers/company-access.helper.spec.js +0 -68
  94. package/cjs/helpers/index.js +0 -19
  95. package/cjs/helpers/permission-mode.helper.js +0 -49
  96. package/cjs/helpers/permission-mode.helper.spec.js +0 -54
  97. package/cjs/index.js +0 -28
  98. package/cjs/interfaces/action.interface.js +0 -4
  99. package/cjs/interfaces/iam-module-options.interface.js +0 -4
  100. package/cjs/interfaces/index.js +0 -20
  101. package/cjs/interfaces/role.interface.js +0 -7
  102. package/cjs/modules/iam.module.js +0 -186
  103. package/cjs/modules/iam.module.spec.js +0 -282
  104. package/cjs/modules/index.js +0 -18
  105. package/cjs/services/action.service.js +0 -337
  106. package/cjs/services/action.service.spec.js +0 -351
  107. package/cjs/services/iam-config.service.js +0 -87
  108. package/cjs/services/iam-config.service.spec.js +0 -110
  109. package/cjs/services/iam-datasource.service.js +0 -129
  110. package/cjs/services/iam-datasource.service.spec.js +0 -110
  111. package/cjs/services/index.js +0 -23
  112. package/cjs/services/permission-cache.service.js +0 -544
  113. package/cjs/services/permission-cache.service.spec.js +0 -718
  114. package/cjs/services/permission.service.js +0 -914
  115. package/cjs/services/permission.service.spec.js +0 -918
  116. package/cjs/services/role.service.js +0 -224
  117. package/cjs/services/role.service.spec.js +0 -347
  118. package/cjs/types/index.js +0 -18
  119. package/cjs/types/logic-node.type.js +0 -30
  120. package/fesm/config/event-actions.js +0 -15
  121. package/fesm/config/iam.constants.js +0 -1
  122. package/fesm/config/message-keys.js +0 -35
  123. package/fesm/controllers/action.controller.js +0 -164
  124. package/fesm/controllers/action.controller.spec.js +0 -75
  125. package/fesm/controllers/company-action-permission.controller.js +0 -109
  126. package/fesm/controllers/company-action-permission.controller.spec.js +0 -61
  127. package/fesm/controllers/my-permission.controller.js +0 -137
  128. package/fesm/controllers/my-permission.controller.spec.js +0 -124
  129. package/fesm/controllers/role-permission.controller.js +0 -181
  130. package/fesm/controllers/role-permission.controller.spec.js +0 -136
  131. package/fesm/controllers/role.controller.js +0 -92
  132. package/fesm/controllers/role.controller.spec.js +0 -82
  133. package/fesm/controllers/user-action-permission.controller.js +0 -119
  134. package/fesm/controllers/user-action-permission.controller.spec.js +0 -64
  135. package/fesm/docs/iam-swagger.config.js +0 -199
  136. package/fesm/docs/iam-swagger.config.spec.js +0 -95
  137. package/fesm/dtos/action.dto.js +0 -252
  138. package/fesm/dtos/permission.dto.js +0 -571
  139. package/fesm/dtos/role.dto.js +0 -134
  140. package/fesm/entities/action.entity.js +0 -128
  141. package/fesm/entities/index.spec.js +0 -52
  142. package/fesm/entities/permission-base.entity.js +0 -100
  143. package/fesm/entities/permission-with-company.entity.js +0 -90
  144. package/fesm/entities/role-base.entity.js +0 -70
  145. package/fesm/entities/role-with-company.entity.js +0 -45
  146. package/fesm/entities/role.entity.js +0 -15
  147. package/fesm/entities/user-iam-permission.entity.js +0 -33
  148. package/fesm/enums/action-type.enum.js +0 -12
  149. package/fesm/enums/iam-entity-type.enum.js +0 -7
  150. package/fesm/enums/iam-permission-type.enum.js +0 -7
  151. package/fesm/enums/permission-type.enum.js +0 -6
  152. package/fesm/helpers/company-access.helper.js +0 -18
  153. package/fesm/helpers/company-access.helper.spec.js +0 -64
  154. package/fesm/helpers/permission-mode.helper.js +0 -49
  155. package/fesm/helpers/permission-mode.helper.spec.js +0 -50
  156. package/fesm/interfaces/action.interface.js +0 -3
  157. package/fesm/interfaces/iam-module-options.interface.js +0 -3
  158. package/fesm/interfaces/role.interface.js +0 -4
  159. package/fesm/modules/iam.module.js +0 -176
  160. package/fesm/modules/iam.module.spec.js +0 -278
  161. package/fesm/services/action.service.js +0 -327
  162. package/fesm/services/action.service.spec.js +0 -347
  163. package/fesm/services/iam-config.service.js +0 -77
  164. package/fesm/services/iam-config.service.spec.js +0 -106
  165. package/fesm/services/iam-datasource.service.js +0 -78
  166. package/fesm/services/iam-datasource.service.spec.js +0 -106
  167. package/fesm/services/permission-cache.service.js +0 -527
  168. package/fesm/services/permission-cache.service.spec.js +0 -714
  169. package/fesm/services/permission.service.js +0 -904
  170. package/fesm/services/permission.service.spec.js +0 -914
  171. package/fesm/services/role.service.js +0 -214
  172. package/fesm/services/role.service.spec.js +0 -343
  173. package/fesm/types/logic-node.type.js +0 -27
@@ -1,199 +0,0 @@
1
- import { IAMPermissionMode } from '../enums/permission-type.enum';
2
- /** Auth-related tags that should always be excluded from IAM API docs */ const AUTH_RELATED_TAGS = [
3
- 'Authentication',
4
- 'Users',
5
- 'Companies',
6
- 'Branches',
7
- 'User Permissions',
8
- 'Company Selection'
9
- ];
10
- export function iamSwaggerConfig(enableCompanyFeature = false, permissionMode = IAMPermissionMode.FULL, databaseMode = 'single') {
11
- const multiTenantNote = databaseMode === 'multi-tenant' ? `\n> **Multi-Tenant Mode**: Include \`x-tenant-id\` header to target a specific tenant database.\n` : '';
12
- const excludeSchemaProperties = enableCompanyFeature ? [] : [
13
- // DTOs with companyId and branchId
14
- {
15
- schemaName: 'AssignUserActionsDto',
16
- properties: [
17
- 'companyId',
18
- 'branchId'
19
- ]
20
- },
21
- {
22
- schemaName: 'AssignUserRolesDto',
23
- properties: [
24
- 'companyId',
25
- 'branchId'
26
- ]
27
- },
28
- {
29
- schemaName: 'GetUserActionsDto',
30
- properties: [
31
- 'companyId',
32
- 'branchId'
33
- ]
34
- },
35
- {
36
- schemaName: 'GetUserRolesDto',
37
- properties: [
38
- 'companyId',
39
- 'branchId'
40
- ]
41
- },
42
- {
43
- schemaName: 'ActionTreeForPermissionDto',
44
- properties: [
45
- 'companyId'
46
- ]
47
- },
48
- // Response DTOs with branchId
49
- {
50
- schemaName: 'UserActionResponseDto',
51
- properties: [
52
- 'branchId'
53
- ]
54
- },
55
- {
56
- schemaName: 'UserRoleResponseDto',
57
- properties: [
58
- 'branchId'
59
- ]
60
- },
61
- // Company-related DTOs (entire schemas hidden via tag exclusion, but just in case)
62
- {
63
- schemaName: 'AssignCompanyActionsDto',
64
- properties: [
65
- 'companyId'
66
- ]
67
- },
68
- {
69
- schemaName: 'CompanyActionResponseDto',
70
- properties: [
71
- 'companyId'
72
- ]
73
- }
74
- ];
75
- // Hide query parameters for GET endpoints when company feature is disabled
76
- const excludeQueryParameters = enableCompanyFeature ? [] : [
77
- {
78
- pathPattern: '/iam/permissions/user-actions/*',
79
- method: 'get',
80
- parameters: [
81
- 'companyId',
82
- 'branchId'
83
- ]
84
- },
85
- {
86
- pathPattern: '/iam/permissions/user-roles/*',
87
- method: 'get',
88
- parameters: [
89
- 'companyId',
90
- 'branchId'
91
- ]
92
- }
93
- ];
94
- // Build exclude tags list: always exclude Auth tags + conditionally exclude based on permission mode
95
- const excludeTags = [
96
- ...AUTH_RELATED_TAGS
97
- ];
98
- // Hide company-related IAM endpoints when company feature is disabled
99
- if (!enableCompanyFeature) {
100
- excludeTags.push('IAM - Company Action Permissions');
101
- }
102
- // Conditionally exclude endpoints based on permission mode
103
- if (permissionMode === IAMPermissionMode.RBAC) {
104
- // RBAC only - hide direct user action endpoints
105
- excludeTags.push('IAM - Permissions (Direct)');
106
- } else if (permissionMode === IAMPermissionMode.DIRECT) {
107
- // Direct only - hide RBAC endpoints
108
- excludeTags.push('IAM - Permissions (RBAC)');
109
- excludeTags.push('IAM - Roles'); // Roles are only used in RBAC
110
- }
111
- return {
112
- title: 'IAM API',
113
- description: `
114
- ## Identity & Access Management API
115
- ${multiTenantNote}
116
- Advanced permission system with flexible modes: RBAC, Direct Permissions, or both.
117
-
118
- ### Current Configuration
119
- - **Permission Mode**: ${permissionMode === IAMPermissionMode.RBAC ? '**RBAC** (Role-Based Access Control)' : permissionMode === IAMPermissionMode.DIRECT ? '**DIRECT** (Direct User Permissions)' : '**FULL** (RBAC + Direct)'}${enableCompanyFeature ? '\n- **Company Feature**: Enabled (Multi-tenant with company/branch scoping)' : '\n- **Company Feature**: Disabled'}
120
-
121
- ### Features Based on Mode
122
-
123
- ${permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL ? `#### RBAC Features (Active)
124
- - **Roles**: Create company-scoped roles${enableCompanyFeature ? ' (auto-filtered by user company)' : ''}
125
- - **Role-Actions**: Assign actions to roles
126
- - **User-Roles**: Assign roles to users${enableCompanyFeature ? ' at branch level' : ''}
127
- ` : ''}${permissionMode === IAMPermissionMode.DIRECT || permissionMode === IAMPermissionMode.FULL ? `#### Direct Permission Features (Active)
128
- - **User-Actions**: Direct action assignment to users${enableCompanyFeature ? ' at branch level' : ''}
129
- ` : ''}${enableCompanyFeature ? `#### Company Features (Active)
130
- - **Company-Action Whitelist**: Control which actions are available per company
131
- - **Branch-Based Scoping**: Permissions scoped to specific branches
132
- - **Auto-Filtering**: Roles automatically filtered by user's company
133
- - **Action Tree Filtering**: Available actions filtered by company whitelist
134
- ` : ''}
135
- ### Core Concepts
136
-
137
- #### Actions
138
- Represent permissions in the system. Can be hierarchical.
139
-
140
- **Action Types:**
141
- - \`menu\` - Menu visibility (actions with type='menu' are used as menus)
142
- - \`endpoint\` - API endpoint access
143
- - \`frontend\` - Frontend feature toggles
144
- ${permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL ? `
145
- #### Roles
146
- Collections of actions that can be assigned to users.${enableCompanyFeature ? ' Scoped to companies.' : ' Global across the system.'}
147
- ` : ''}${enableCompanyFeature ? `
148
- #### Company-Action Whitelist
149
- Controls which actions are available to a company. Users/roles can only use whitelisted actions.
150
-
151
- **Flow:**
152
- 1. Admin assigns actions to company (whitelist)
153
- 2. Only whitelisted actions appear in permission assignment UIs
154
- 3. Users/roles cannot be assigned non-whitelisted actions
155
- ` : ''}
156
- ### Permission Resolution
157
-
158
- ${permissionMode === IAMPermissionMode.FULL ? `1. **Company-Action Whitelist** - Filter by company (if enabled)
159
- 2. **UserAction (DENY)** - Explicit denials take precedence
160
- 3. **UserAction (GRANT)** - Direct user grants
161
- 4. **UserRole → RoleAction** - Inherited from assigned roles
162
- 5. **Action Permission Logic** - Complex AND/OR rules` : permissionMode === IAMPermissionMode.RBAC ? `1. **Company-Action Whitelist** - Filter by company (if enabled)
163
- 2. **UserRole → RoleAction** - Actions inherited from roles
164
- 3. **Action Permission Logic** - Complex AND/OR rules` : `1. **Company-Action Whitelist** - Filter by company (if enabled)
165
- 2. **UserAction (DENY)** - Explicit denials take precedence
166
- 3. **UserAction (GRANT)** - Direct user grants
167
- 4. **Action Permission Logic** - Complex AND/OR rules`}
168
-
169
- ### API Endpoints Summary
170
-
171
- #### Available Endpoints
172
- - ✅ **Actions**: CRUD operations, tree view${enableCompanyFeature ? ', filtered tree for permissions' : ''}${permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL ? `
173
- - ✅ **Roles**: CRUD operations${enableCompanyFeature ? ' (auto-filtered by company)' : ''}
174
- - ✅ **Role-Actions**: Assign actions to roles, get role actions
175
- - ✅ **User-Roles**: Assign roles to users, get user roles` : `
176
- - ❌ **Roles**: Disabled (RBAC mode not active)`}${permissionMode === IAMPermissionMode.DIRECT || permissionMode === IAMPermissionMode.FULL ? `
177
- - ✅ **User-Actions**: Direct action assignment to users` : `
178
- - ❌ **User-Actions**: Disabled (DIRECT mode not active)`}${enableCompanyFeature ? `
179
- - ✅ **Company-Actions**: Whitelist actions for companies` : `
180
- - ❌ **Company-Actions**: Disabled (company feature not enabled)`}
181
- - ✅ **My Permissions**: Get current user's complete permissions (includes menu-type actions)
182
-
183
- ### Best Practices
184
-
185
- 1. **Action Codes**: Use meaningful codes like \`user.create\`, \`order.view\`
186
- 2. **Hierarchical Actions**: Group related actions (use parentId for hierarchy)${permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL ? `
187
- 3. **Role Design**: Create roles for common permission patterns` : ''}${permissionMode === IAMPermissionMode.DIRECT || permissionMode === IAMPermissionMode.FULL ? `
188
- ${permissionMode === IAMPermissionMode.FULL ? '4' : '3'}. **Direct Actions**: Use sparingly for exceptions` : ''}${enableCompanyFeature ? `
189
- ${permissionMode === IAMPermissionMode.FULL ? '5' : '4'}. **Company Whitelisting**: Set up action whitelist before assigning permissions
190
- ${permissionMode === IAMPermissionMode.FULL ? '6' : '5'}. **Branch Scoping**: Use branches for location-based access control` : ''}
191
- `,
192
- version: '1.0',
193
- path: 'api/docs/iam',
194
- bearerAuth: true,
195
- excludeSchemaProperties,
196
- excludeTags,
197
- excludeQueryParameters
198
- };
199
- }
@@ -1,95 +0,0 @@
1
- import { iamSwaggerConfig } from './iam-swagger.config';
2
- import { IAMPermissionMode } from '../enums/permission-type.enum';
3
- describe('iamSwaggerConfig', ()=>{
4
- it('should default to company disabled, FULL mode, single database', ()=>{
5
- const config = iamSwaggerConfig();
6
- expect(config.title).toBe('IAM API');
7
- expect(config.path).toBe('api/docs/iam');
8
- expect(config.bearerAuth).toBe(true);
9
- // enableCompanyFeature defaults to false, so company-scoped exclusions apply
10
- expect(config.excludeSchemaProperties?.length).toBeGreaterThan(0);
11
- expect(config.excludeQueryParameters?.length).toBeGreaterThan(0);
12
- expect(config.description).not.toContain('Multi-Tenant Mode');
13
- });
14
- it('should always exclude auth-related tags regardless of configuration', ()=>{
15
- const config = iamSwaggerConfig(true, IAMPermissionMode.FULL);
16
- expect(config.excludeTags).toEqual(expect.arrayContaining([
17
- 'Authentication',
18
- 'Users',
19
- 'Companies',
20
- 'Branches'
21
- ]));
22
- });
23
- it('should exclude company-scoped schema properties and query params when company feature is off', ()=>{
24
- const config = iamSwaggerConfig(false);
25
- expect(config.excludeSchemaProperties).toEqual(expect.arrayContaining([
26
- expect.objectContaining({
27
- schemaName: 'AssignUserActionsDto',
28
- properties: [
29
- 'companyId',
30
- 'branchId'
31
- ]
32
- })
33
- ]));
34
- expect(config.excludeQueryParameters).toEqual(expect.arrayContaining([
35
- expect.objectContaining({
36
- pathPattern: '/iam/permissions/user-actions/*',
37
- method: 'get'
38
- })
39
- ]));
40
- expect(config.excludeTags).toContain('IAM - Company Action Permissions');
41
- });
42
- it('should not exclude company-scoped schema properties, query params, or tags when company feature is on', ()=>{
43
- const config = iamSwaggerConfig(true);
44
- expect(config.excludeSchemaProperties).toEqual([]);
45
- expect(config.excludeQueryParameters).toEqual([]);
46
- expect(config.excludeTags).not.toContain('IAM - Company Action Permissions');
47
- });
48
- it('should hide DIRECT-mode tags in RBAC mode', ()=>{
49
- const config = iamSwaggerConfig(false, IAMPermissionMode.RBAC);
50
- expect(config.excludeTags).toContain('IAM - Permissions (Direct)');
51
- expect(config.excludeTags).not.toContain('IAM - Permissions (RBAC)');
52
- expect(config.excludeTags).not.toContain('IAM - Roles');
53
- });
54
- it('should hide RBAC-mode tags (including Roles) in DIRECT mode', ()=>{
55
- const config = iamSwaggerConfig(false, IAMPermissionMode.DIRECT);
56
- expect(config.excludeTags).toContain('IAM - Permissions (RBAC)');
57
- expect(config.excludeTags).toContain('IAM - Roles');
58
- expect(config.excludeTags).not.toContain('IAM - Permissions (Direct)');
59
- });
60
- it('should hide neither RBAC nor DIRECT tags in FULL mode', ()=>{
61
- const config = iamSwaggerConfig(false, IAMPermissionMode.FULL);
62
- expect(config.excludeTags).not.toContain('IAM - Permissions (RBAC)');
63
- expect(config.excludeTags).not.toContain('IAM - Permissions (Direct)');
64
- expect(config.excludeTags).not.toContain('IAM - Roles');
65
- });
66
- it('should mention multi-tenant mode in the description only for multi-tenant database mode', ()=>{
67
- const multiTenant = iamSwaggerConfig(false, IAMPermissionMode.FULL, 'multi-tenant');
68
- const single = iamSwaggerConfig(false, IAMPermissionMode.FULL, 'single');
69
- expect(multiTenant.description).toContain('Multi-Tenant Mode');
70
- expect(single.description).not.toContain('Multi-Tenant Mode');
71
- });
72
- it('should describe RBAC as active and DIRECT as disabled in the endpoints summary for RBAC mode', ()=>{
73
- const config = iamSwaggerConfig(false, IAMPermissionMode.RBAC);
74
- expect(config.description).toContain('**Roles**: CRUD operations');
75
- expect(config.description).toContain('❌ **User-Actions**: Disabled (DIRECT mode not active)');
76
- });
77
- it('should describe DIRECT as active and Roles as disabled in the endpoints summary for DIRECT mode', ()=>{
78
- const config = iamSwaggerConfig(false, IAMPermissionMode.DIRECT);
79
- expect(config.description).toContain('✅ **User-Actions**: Direct action assignment to users');
80
- expect(config.description).toContain('❌ **Roles**: Disabled (RBAC mode not active)');
81
- });
82
- it('should describe company features as active only when company feature is enabled', ()=>{
83
- const withCompany = iamSwaggerConfig(true, IAMPermissionMode.FULL);
84
- const withoutCompany = iamSwaggerConfig(false, IAMPermissionMode.FULL);
85
- expect(withCompany.description).toContain('Company Features (Active)');
86
- expect(withCompany.description).toContain('✅ **Company-Actions**: Whitelist actions for companies');
87
- expect(withoutCompany.description).not.toContain('Company Features (Active)');
88
- expect(withoutCompany.description).toContain('❌ **Company-Actions**: Disabled (company feature not enabled)');
89
- });
90
- it('should describe the current permission mode label correctly for each mode', ()=>{
91
- expect(iamSwaggerConfig(false, IAMPermissionMode.RBAC).description).toContain('**RBAC** (Role-Based Access Control)');
92
- expect(iamSwaggerConfig(false, IAMPermissionMode.DIRECT).description).toContain('**DIRECT** (Direct User Permissions)');
93
- expect(iamSwaggerConfig(false, IAMPermissionMode.FULL).description).toContain('**FULL** (RBAC + Direct)');
94
- });
95
- });
@@ -1,252 +0,0 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _ts_decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- 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;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- function _ts_metadata(k, v) {
21
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22
- }
23
- import { IdentityResponseDto } from '@flusys/nestjs-shared/dtos';
24
- import { ApiProperty, PartialType } from '@nestjs/swagger';
25
- import { Expose } from 'class-transformer';
26
- import { IsBoolean, IsEnum, IsInt, IsNotEmpty, IsOptional, IsString, IsUUID, MaxLength } from 'class-validator';
27
- import { ActionType } from '../enums';
28
- import { LogicNode } from '../types';
29
- export class CreateActionDto {
30
- constructor(){
31
- _define_property(this, "name", void 0);
32
- _define_property(this, "description", void 0);
33
- _define_property(this, "code", void 0);
34
- _define_property(this, "actionType", void 0);
35
- _define_property(this, "permissionLogic", void 0);
36
- _define_property(this, "parentId", void 0);
37
- _define_property(this, "serial", void 0);
38
- _define_property(this, "isActive", void 0);
39
- }
40
- }
41
- _ts_decorate([
42
- ApiProperty({
43
- description: 'Action name',
44
- example: 'View Users'
45
- }),
46
- IsString(),
47
- IsNotEmpty(),
48
- MaxLength(255),
49
- _ts_metadata("design:type", String)
50
- ], CreateActionDto.prototype, "name", void 0);
51
- _ts_decorate([
52
- ApiProperty({
53
- description: 'Action description',
54
- example: 'Permission to view user list',
55
- required: false
56
- }),
57
- IsString(),
58
- IsOptional(),
59
- MaxLength(500),
60
- _ts_metadata("design:type", String)
61
- ], CreateActionDto.prototype, "description", void 0);
62
- _ts_decorate([
63
- ApiProperty({
64
- description: 'Unique code for programmatic reference',
65
- example: 'user.view',
66
- required: false
67
- }),
68
- IsString(),
69
- IsOptional(),
70
- MaxLength(255),
71
- _ts_metadata("design:type", String)
72
- ], CreateActionDto.prototype, "code", void 0);
73
- _ts_decorate([
74
- ApiProperty({
75
- description: 'Action type (backend for API endpoints, frontend for UI features)',
76
- enum: ActionType,
77
- example: ActionType.BACKEND,
78
- default: ActionType.BACKEND,
79
- required: false
80
- }),
81
- IsEnum(ActionType),
82
- IsOptional(),
83
- _ts_metadata("design:type", typeof ActionType === "undefined" ? Object : ActionType)
84
- ], CreateActionDto.prototype, "actionType", void 0);
85
- _ts_decorate([
86
- ApiProperty({
87
- description: 'Permission logic (AND/OR rules)',
88
- required: false
89
- }),
90
- IsOptional(),
91
- _ts_metadata("design:type", typeof LogicNode === "undefined" ? Object : LogicNode)
92
- ], CreateActionDto.prototype, "permissionLogic", void 0);
93
- _ts_decorate([
94
- ApiProperty({
95
- description: 'Parent action ID for hierarchy',
96
- example: '123e4567-e89b-12d3-a456-426614174000',
97
- required: false
98
- }),
99
- IsUUID(),
100
- IsOptional(),
101
- _ts_metadata("design:type", String)
102
- ], CreateActionDto.prototype, "parentId", void 0);
103
- _ts_decorate([
104
- ApiProperty({
105
- description: 'Display order',
106
- required: false
107
- }),
108
- IsInt(),
109
- IsOptional(),
110
- _ts_metadata("design:type", Number)
111
- ], CreateActionDto.prototype, "serial", void 0);
112
- _ts_decorate([
113
- ApiProperty({
114
- description: 'Active status',
115
- default: true,
116
- required: false
117
- }),
118
- IsBoolean(),
119
- IsOptional(),
120
- _ts_metadata("design:type", Boolean)
121
- ], CreateActionDto.prototype, "isActive", void 0);
122
- export class UpdateActionDto extends PartialType(CreateActionDto) {
123
- constructor(...args){
124
- super(...args), _define_property(this, "id", void 0);
125
- }
126
- }
127
- _ts_decorate([
128
- ApiProperty({
129
- description: 'Action ID',
130
- example: '123e4567-e89b-12d3-a456-426614174000'
131
- }),
132
- IsUUID(),
133
- IsNotEmpty(),
134
- _ts_metadata("design:type", String)
135
- ], UpdateActionDto.prototype, "id", void 0);
136
- export class ActionResponseDto extends IdentityResponseDto {
137
- constructor(...args){
138
- 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, "parentId", void 0), _define_property(this, "serial", void 0), _define_property(this, "isActive", void 0);
139
- }
140
- }
141
- _ts_decorate([
142
- Expose(),
143
- ApiProperty(),
144
- _ts_metadata("design:type", Boolean)
145
- ], ActionResponseDto.prototype, "readOnly", void 0);
146
- _ts_decorate([
147
- Expose(),
148
- ApiProperty(),
149
- _ts_metadata("design:type", String)
150
- ], ActionResponseDto.prototype, "name", void 0);
151
- _ts_decorate([
152
- Expose(),
153
- ApiProperty(),
154
- _ts_metadata("design:type", Object)
155
- ], ActionResponseDto.prototype, "description", void 0);
156
- _ts_decorate([
157
- Expose(),
158
- ApiProperty(),
159
- _ts_metadata("design:type", Object)
160
- ], ActionResponseDto.prototype, "code", void 0);
161
- _ts_decorate([
162
- Expose(),
163
- ApiProperty({
164
- enum: ActionType
165
- }),
166
- _ts_metadata("design:type", typeof ActionType === "undefined" ? Object : ActionType)
167
- ], ActionResponseDto.prototype, "actionType", void 0);
168
- _ts_decorate([
169
- Expose(),
170
- ApiProperty(),
171
- _ts_metadata("design:type", Object)
172
- ], ActionResponseDto.prototype, "permissionLogic", void 0);
173
- _ts_decorate([
174
- Expose(),
175
- ApiProperty(),
176
- _ts_metadata("design:type", Object)
177
- ], ActionResponseDto.prototype, "parentId", void 0);
178
- _ts_decorate([
179
- Expose(),
180
- ApiProperty(),
181
- _ts_metadata("design:type", Object)
182
- ], ActionResponseDto.prototype, "serial", void 0);
183
- _ts_decorate([
184
- Expose(),
185
- ApiProperty(),
186
- _ts_metadata("design:type", Boolean)
187
- ], ActionResponseDto.prototype, "isActive", void 0);
188
- export class ActionTreeDto extends ActionResponseDto {
189
- constructor(...args){
190
- super(...args), _define_property(this, "children", void 0);
191
- }
192
- }
193
- _ts_decorate([
194
- Expose(),
195
- ApiProperty({
196
- type: ()=>[
197
- ActionTreeDto
198
- ]
199
- }),
200
- _ts_metadata("design:type", Array)
201
- ], ActionTreeDto.prototype, "children", void 0);
202
- export class ActionTreeForPermissionDto {
203
- constructor(){
204
- _define_property(this, "companyId", void 0);
205
- }
206
- }
207
- _ts_decorate([
208
- ApiProperty({
209
- description: 'Company to scope the action whitelist to. Defaults to the current user session company when omitted.',
210
- required: false
211
- }),
212
- IsUUID(),
213
- IsOptional(),
214
- _ts_metadata("design:type", String)
215
- ], ActionTreeForPermissionDto.prototype, "companyId", void 0);
216
- export class ActionTreeQueryDto {
217
- constructor(){
218
- _define_property(this, "search", void 0);
219
- _define_property(this, "isActive", void 0);
220
- _define_property(this, "withDeleted", void 0);
221
- }
222
- }
223
- _ts_decorate([
224
- ApiProperty({
225
- description: 'Search by name or code',
226
- example: 'user',
227
- required: false
228
- }),
229
- IsString(),
230
- IsOptional(),
231
- _ts_metadata("design:type", String)
232
- ], ActionTreeQueryDto.prototype, "search", void 0);
233
- _ts_decorate([
234
- ApiProperty({
235
- description: 'Filter by active status',
236
- example: true,
237
- required: false
238
- }),
239
- IsBoolean(),
240
- IsOptional(),
241
- _ts_metadata("design:type", Boolean)
242
- ], ActionTreeQueryDto.prototype, "isActive", void 0);
243
- _ts_decorate([
244
- ApiProperty({
245
- description: 'Include deleted actions',
246
- default: false,
247
- required: false
248
- }),
249
- IsBoolean(),
250
- IsOptional(),
251
- _ts_metadata("design:type", Boolean)
252
- ], ActionTreeQueryDto.prototype, "withDeleted", void 0);