@@ -5,27 +5,33 @@ import {
55 RoleAssignmentsApi as AutogenRoleAssignmentsApi ,
66 BulkRoleAssignmentReport ,
77 BulkRoleUnAssignmentReport ,
8+ PaginatedResultRoleAssignmentDetailedRead ,
9+ PaginatedResultRoleAssignmentRead ,
810 RoleAssignmentCreate ,
11+ RoleAssignmentDetailedRead ,
912 RoleAssignmentRead ,
1013 RoleAssignmentRemove ,
1114} from '../openapi' ;
1215import { BASE_PATH } from '../openapi/base' ;
1316
14- import { BaseFactsPermitAPI , IPagination , IWaitForSync } from './base' ;
17+ import { BaseFactsPermitAPI , IBasePaginationExtended , IWaitForSync } from './base' ;
1518import { ApiContextLevel , ApiKeyLevel } from './context' ;
1619
1720export {
1821 BulkRoleAssignmentReport ,
1922 BulkRoleUnAssignmentReport ,
23+ PaginatedResultRoleAssignmentDetailedRead ,
24+ PaginatedResultRoleAssignmentRead ,
2025 RoleAssignmentCreate ,
2126 RoleAssignmentRead ,
27+ RoleAssignmentDetailedRead ,
2228 RoleAssignmentRemove ,
2329} from '../openapi' ;
2430
2531/**
2632 * Represents the parameters for listing role assignments.
2733 */
28- export interface IListRoleAssignments extends IPagination {
34+ export interface IBaseListRoleAssignments extends IBasePaginationExtended {
2935 /**
3036 * optional user filter, will only return role assignments granted to this user.
3137 */
@@ -45,8 +51,33 @@ export interface IListRoleAssignments extends IPagination {
4551 * optional resource instance filter, will only return (resource) role assignments granted on that resource instance.
4652 */
4753 resourceInstance ?: string ;
54+
55+ /**
56+ * optional detailed flag, will return detailed role assignments.
57+ */
58+ detailed ?: boolean ;
4859}
4960
61+ type IListRoleAssignmentsIncludeTotalCount = IBaseListRoleAssignments & { includeTotalCount : true } ;
62+
63+ type IListRoleAssignmentsDetailed = IBaseListRoleAssignments & { detailed : true } ;
64+
65+ export type IListRoleAssignments =
66+ | IBaseListRoleAssignments
67+ | IListRoleAssignmentsIncludeTotalCount
68+ | IListRoleAssignmentsDetailed ;
69+
70+ type ReturnListRoleAssignments < T extends IListRoleAssignments > =
71+ T extends IListRoleAssignmentsIncludeTotalCount
72+ ? // with total count
73+ T extends IListRoleAssignmentsDetailed
74+ ? PaginatedResultRoleAssignmentDetailedRead
75+ : PaginatedResultRoleAssignmentRead
76+ : // without total count
77+ T extends IListRoleAssignmentsDetailed
78+ ? RoleAssignmentDetailedRead [ ]
79+ : RoleAssignmentRead [ ] ;
80+
5081/**
5182 * API client for managing role assignments.
5283 */
@@ -59,7 +90,7 @@ export interface IRoleAssignmentsApi extends IWaitForSync {
5990 * @throws {@link PermitApiError } If the API returns an error HTTP status code.
6091 * @throws {@link PermitContextError } If the configured {@link ApiContext} does not match the required endpoint context.
6192 */
62- list ( params : IListRoleAssignments ) : Promise < RoleAssignmentRead [ ] > ;
93+ list < T extends IListRoleAssignments > ( params : T ) : Promise < ReturnListRoleAssignments < T > > ;
6394
6495 /**
6596 * Assigns a role to a user in the scope of a given tenant.
@@ -132,10 +163,29 @@ export class RoleAssignmentsApi extends BaseFactsPermitAPI implements IRoleAssig
132163 * @throws {@link PermitApiError } If the API returns an error HTTP status code.
133164 * @throws {@link PermitContextError } If the configured {@link ApiContext} does not match the required endpoint context.
134165 */
135- public async list ( params : IListRoleAssignments ) : Promise < RoleAssignmentRead [ ] > {
166+ public async list < T extends IListRoleAssignments > (
167+ params : T ,
168+ ) : Promise < ReturnListRoleAssignments < T > > ;
169+ public async list (
170+ params : IListRoleAssignments ,
171+ ) : Promise <
172+ | Array < RoleAssignmentRead >
173+ | Array < RoleAssignmentDetailedRead >
174+ | PaginatedResultRoleAssignmentRead
175+ | PaginatedResultRoleAssignmentDetailedRead
176+ > {
136177 await this . ensureAccessLevel ( ApiKeyLevel . ENVIRONMENT_LEVEL_API_KEY ) ;
137178 await this . ensureContext ( ApiContextLevel . ENVIRONMENT ) ;
138- const { user, tenant, role, resourceInstance, page = 1 , perPage = 100 } = params ;
179+ const {
180+ user,
181+ tenant,
182+ role,
183+ resourceInstance,
184+ page = 1 ,
185+ perPage = 100 ,
186+ detailed,
187+ includeTotalCount,
188+ } = params ;
139189 try {
140190 return (
141191 await this . roleAssignments . listRoleAssignments ( {
@@ -144,8 +194,10 @@ export class RoleAssignmentsApi extends BaseFactsPermitAPI implements IRoleAssig
144194 tenant,
145195 role,
146196 resourceInstance,
197+ detailed,
147198 page,
148199 perPage,
200+ includeTotalCount,
149201 } )
150202 ) . data ;
151203 } catch ( err ) {
0 commit comments