File tree 5 files changed +59
-2
lines changed
5 files changed +59
-2
lines changed Original file line number Diff line number Diff line change @@ -932,6 +932,15 @@ const rolesRes = await descopeClient.management.role.loadAll();
932
932
rolesRes .data .forEach ((role ) => {
933
933
// do something
934
934
});
935
+
936
+ // Search roles
937
+ const rolesRes = await descopeClient .management .role .search ({
938
+ tenantIds: [' t1' , ' t2' ],
939
+ roleNames: [' role1' ],
940
+ });
941
+ rolesRes .data .forEach ((role ) => {
942
+ // do something
943
+ });
935
944
```
936
945
937
946
### Query SSO Groups
Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ export default {
100
100
update : '/v1/mgmt/role/update' ,
101
101
delete : '/v1/mgmt/role/delete' ,
102
102
loadAll : '/v1/mgmt/role/all' ,
103
+ search : '/v1/mgmt/role/search' ,
103
104
} ,
104
105
flow : {
105
106
list : '/v1/mgmt/flow/list' ,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { SdkResponse } from '@descope/core-js-sdk';
2
2
import withManagement from '.' ;
3
3
import apiPaths from './paths' ;
4
4
import { mockCoreSdk , mockHttpClient } from './testutils' ;
5
- import { Role } from './types' ;
5
+ import { Role , RoleSearchOptions } from './types' ;
6
6
7
7
const management = withManagement ( mockCoreSdk , 'key' ) ;
8
8
@@ -157,4 +157,36 @@ describe('Management Role', () => {
157
157
} ) ;
158
158
} ) ;
159
159
} ) ;
160
+
161
+ describe ( 'search' , ( ) => {
162
+ it ( 'should send the correct request and receive correct response' , async ( ) => {
163
+ const httpResponse = {
164
+ ok : true ,
165
+ json : ( ) => mockAllRolesResponse ,
166
+ clone : ( ) => ( {
167
+ json : ( ) => Promise . resolve ( mockAllRolesResponse ) ,
168
+ } ) ,
169
+ status : 200 ,
170
+ } ;
171
+ mockHttpClient . post . mockResolvedValue ( httpResponse ) ;
172
+ const req : RoleSearchOptions = {
173
+ tenantIds : [ 't' ] ,
174
+ roleNames : [ 'r' ] ,
175
+ roleNameLike : 'x' ,
176
+ permissionNames : [ 'p' ] ,
177
+ } ;
178
+ const resp : SdkResponse < Role [ ] > = await management . role . search ( req ) ;
179
+
180
+ expect ( mockHttpClient . post ) . toHaveBeenCalledWith ( apiPaths . role . search , req , {
181
+ token : 'key' ,
182
+ } ) ;
183
+
184
+ expect ( resp ) . toEqual ( {
185
+ code : 200 ,
186
+ data : mockRoles ,
187
+ ok : true ,
188
+ response : httpResponse ,
189
+ } ) ;
190
+ } ) ;
191
+ } ) ;
160
192
} ) ;
Original file line number Diff line number Diff line change 1
1
import { SdkResponse , transformResponse } from '@descope/core-js-sdk' ;
2
2
import { CoreSdk } from '../types' ;
3
3
import apiPaths from './paths' ;
4
- import { Role } from './types' ;
4
+ import { Role , RoleSearchOptions } from './types' ;
5
5
6
6
type MultipleRoleResponse = {
7
7
roles : Role [ ] ;
@@ -46,6 +46,13 @@ const withRole = (sdk: CoreSdk, managementKey?: string) => ({
46
46
} ) ,
47
47
( data ) => data . roles ,
48
48
) ,
49
+ search : ( options : RoleSearchOptions ) : Promise < SdkResponse < Role [ ] > > =>
50
+ transformResponse < MultipleRoleResponse , Role [ ] > (
51
+ sdk . httpClient . post ( apiPaths . role . search , options , {
52
+ token : managementKey ,
53
+ } ) ,
54
+ ( data ) => data . roles ,
55
+ ) ,
49
56
} ) ;
50
57
51
58
export default withRole ;
Original file line number Diff line number Diff line change @@ -236,6 +236,14 @@ export type Role = {
236
236
tenantId ?: string ;
237
237
} ;
238
238
239
+ /** Search roles based on the parameters */
240
+ export type RoleSearchOptions = {
241
+ tenantIds ?: string [ ] ;
242
+ roleNames ?: string [ ] ;
243
+ roleNameLike ?: string ; // Search roles where name contains this - case insensitive
244
+ permissionNames ?: string [ ] ;
245
+ } ;
246
+
239
247
/** Represents a group in a project. It has an id and display name and a list of group members. */
240
248
export type Group = {
241
249
id : string ;
You can’t perform that action at this time.
0 commit comments