@mondaydotcomorg/monday-authorization 3.1.0 → 3.1.1-feature-bashanye-fix-platform-url.d268e4c
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 +154 -0
- package/dist/authorization-service.js +2 -2
- package/dist/esm/authorization-service.mjs +2 -2
- package/dist/esm/roles-service.d.ts +21 -1
- package/dist/esm/roles-service.d.ts.map +1 -1
- package/dist/esm/roles-service.mjs +24 -5
- package/dist/roles-service.d.ts +21 -1
- package/dist/roles-service.d.ts.map +1 -1
- package/dist/roles-service.js +24 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -222,3 +222,157 @@ Special notes for asynchronous operations:
|
|
|
222
222
|
2. To update an existing key, just use upsert operation, it'll override previous value.
|
|
223
223
|
3. Requests with a lot of operations might split to chunks that will be consumed either sequence or in parallel, so there might be a timeframe where some of the operations already applied and some not. Eventually all of them will be applied.
|
|
224
224
|
4. If your MS depends on the access to the asynchronous operation, you can use a health check operation `asyncResourceAttributesHealthCheck` that will return false if it can't reach to SNS or can't find the required topic. Note it doesn't check write permissions so make sure your MS have permissions to write to the SNS topic.
|
|
225
|
+
|
|
226
|
+
### Roles API
|
|
227
|
+
|
|
228
|
+
The Roles API allows you to manage roles (both basic and custom) for accounts. Use `RolesService` to retrieve, create, update, and delete roles.
|
|
229
|
+
|
|
230
|
+
#### Get Roles
|
|
231
|
+
|
|
232
|
+
Use `RolesService.getRoles` to retrieve all roles for an account:
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
import { RolesService } from '@mondaydotcomorg/monday-authorization';
|
|
236
|
+
|
|
237
|
+
const rolesService = new RolesService();
|
|
238
|
+
const accountId = 739630;
|
|
239
|
+
const resourceTypes = ['account', 'workspace'];
|
|
240
|
+
const style = 'A'; // or 'B'
|
|
241
|
+
|
|
242
|
+
const rolesResponse = await rolesService.getRoles(accountId, resourceTypes, style);
|
|
243
|
+
// Returns: { customRoles: CustomRole[], basicRoles?: BasicRole[] }
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Parameters:**
|
|
247
|
+
- `accountId` - The account ID
|
|
248
|
+
- `resourceTypes` - Array of resource types to filter roles by (e.g., ['account', 'workspace'])
|
|
249
|
+
- `style` - Deprecated, don't use it. the style of the roles to return, either 'A' or 'B' (default is 'A'). Note that basic role IDs are returned in A style and not B style.
|
|
250
|
+
|
|
251
|
+
#### Create Custom Roles
|
|
252
|
+
|
|
253
|
+
Use `RolesService.createCustomRole` to create custom roles for an account:
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
import { RolesService, RoleType } from '@mondaydotcomorg/monday-authorization';
|
|
257
|
+
|
|
258
|
+
const rolesService = new RolesService();
|
|
259
|
+
const accountId = 739630;
|
|
260
|
+
const customRoles = [
|
|
261
|
+
{
|
|
262
|
+
name: 'Custom Admin Role',
|
|
263
|
+
resourceType: 'workspace',
|
|
264
|
+
resourceId: 123,
|
|
265
|
+
sourceRole: {
|
|
266
|
+
id: 5,
|
|
267
|
+
type: RoleType.BASIC,
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
];
|
|
271
|
+
|
|
272
|
+
const rolesResponse = await rolesService.createCustomRole(accountId, customRoles);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
**Parameters:**
|
|
276
|
+
- `accountId` - The account ID
|
|
277
|
+
- `roles` - Array of `RoleCreateRequest` objects (cannot be empty)
|
|
278
|
+
|
|
279
|
+
#### Update Custom Roles
|
|
280
|
+
|
|
281
|
+
Use `RolesService.updateCustomRole` to update existing custom roles:
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
import { RolesService } from '@mondaydotcomorg/monday-authorization';
|
|
285
|
+
|
|
286
|
+
const rolesService = new RolesService();
|
|
287
|
+
const accountId = 739630;
|
|
288
|
+
const updateRequests = [
|
|
289
|
+
{
|
|
290
|
+
id: 1000,
|
|
291
|
+
updateAttributes: {
|
|
292
|
+
name: 'Updated Custom Role Name',
|
|
293
|
+
},
|
|
294
|
+
},
|
|
295
|
+
];
|
|
296
|
+
|
|
297
|
+
const rolesResponse = await rolesService.updateCustomRole(accountId, updateRequests);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
**Parameters:**
|
|
301
|
+
- `accountId` - The account ID
|
|
302
|
+
- `updateRequests` - Array of `RoleUpdateRequest` objects
|
|
303
|
+
|
|
304
|
+
#### Delete Custom Roles
|
|
305
|
+
|
|
306
|
+
Use `RolesService.deleteCustomRole` to delete custom roles:
|
|
307
|
+
|
|
308
|
+
```ts
|
|
309
|
+
import { RolesService } from '@mondaydotcomorg/monday-authorization';
|
|
310
|
+
|
|
311
|
+
const rolesService = new RolesService();
|
|
312
|
+
const accountId = 739630;
|
|
313
|
+
const roleIds = [1000, 1001, 1002];
|
|
314
|
+
|
|
315
|
+
const rolesResponse = await rolesService.deleteCustomRole(accountId, roleIds);
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
**Parameters:**
|
|
319
|
+
- `accountId` - The account ID
|
|
320
|
+
- `roleIds` - Array of custom role IDs to delete
|
|
321
|
+
|
|
322
|
+
#### Types
|
|
323
|
+
|
|
324
|
+
The following types are available for working with roles:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
import {
|
|
328
|
+
CustomRole,
|
|
329
|
+
BasicRole,
|
|
330
|
+
RoleType,
|
|
331
|
+
RoleCreateRequest,
|
|
332
|
+
RoleUpdateRequest,
|
|
333
|
+
RolesResponse,
|
|
334
|
+
} from '@mondaydotcomorg/monday-authorization';
|
|
335
|
+
|
|
336
|
+
// CustomRole interface
|
|
337
|
+
interface CustomRole {
|
|
338
|
+
id?: number;
|
|
339
|
+
name: string;
|
|
340
|
+
resourceType: string;
|
|
341
|
+
resourceId: number;
|
|
342
|
+
basicRoleId: number;
|
|
343
|
+
basicRoleType: RoleType;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// BasicRole interface
|
|
347
|
+
interface BasicRole {
|
|
348
|
+
id: number;
|
|
349
|
+
resourceType: string;
|
|
350
|
+
roleType: string;
|
|
351
|
+
name: string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// RoleCreateRequest interface
|
|
355
|
+
interface RoleCreateRequest {
|
|
356
|
+
name: string;
|
|
357
|
+
resourceType: string;
|
|
358
|
+
resourceId: number;
|
|
359
|
+
sourceRole: {
|
|
360
|
+
id: number;
|
|
361
|
+
type: RoleType;
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// RoleUpdateRequest interface
|
|
366
|
+
interface RoleUpdateRequest {
|
|
367
|
+
id: number;
|
|
368
|
+
updateAttributes: {
|
|
369
|
+
name: string;
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// RolesResponse interface
|
|
374
|
+
interface RolesResponse {
|
|
375
|
+
customRoles: CustomRole[];
|
|
376
|
+
basicRoles?: BasicRole[];
|
|
377
|
+
}
|
|
378
|
+
```
|
|
@@ -333,10 +333,10 @@ function createAuthorizationParams(resources, action) {
|
|
|
333
333
|
return params;
|
|
334
334
|
}
|
|
335
335
|
function getAuthorizeUrl() {
|
|
336
|
-
return
|
|
336
|
+
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/authorize`;
|
|
337
337
|
}
|
|
338
338
|
function getCanActionsInScopesUrl() {
|
|
339
|
-
return
|
|
339
|
+
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/can_actions_in_scopes`;
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
exports.AuthorizationService = AuthorizationService;
|
|
@@ -325,10 +325,10 @@ function createAuthorizationParams(resources, action) {
|
|
|
325
325
|
return params;
|
|
326
326
|
}
|
|
327
327
|
function getAuthorizeUrl() {
|
|
328
|
-
return
|
|
328
|
+
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/authorize`;
|
|
329
329
|
}
|
|
330
330
|
function getCanActionsInScopesUrl() {
|
|
331
|
-
return
|
|
331
|
+
return `${process.env.MONDAY_INTERNAL_URL}/internal_ms/authorization/can_actions_in_scopes`;
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
export { AuthorizationService, createAuthorizationParams, setIgniteClient, setRedisClient, setRequestFetchOptions };
|
|
@@ -14,11 +14,31 @@ export declare class RolesService {
|
|
|
14
14
|
/**
|
|
15
15
|
* Get all roles for an account
|
|
16
16
|
* @param accountId - The account ID
|
|
17
|
+
* @param style - The style of the roles to return, either 'A' or 'B', default is 'A'. 'B' is not deprecated and only available for backward compatibility.
|
|
17
18
|
* @returns - The roles for the account, both basic and custom roles. Note that basic role ids are returned in A style and not B style.
|
|
18
19
|
*/
|
|
19
|
-
getRoles(accountId: number, resourceTypes: string[]): Promise<RolesResponse>;
|
|
20
|
+
getRoles(accountId: number, resourceTypes: string[], style?: 'A' | 'B'): Promise<RolesResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Create a custom role for an account
|
|
23
|
+
* @param accountId - The account ID
|
|
24
|
+
* @param roles - The roles to create
|
|
25
|
+
* @returns - The created roles
|
|
26
|
+
* Note that basic role ids should be provided in A style and not in B style.
|
|
27
|
+
*/
|
|
20
28
|
createCustomRole(accountId: number, roles: RoleCreateRequest[]): Promise<RolesResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Delete a custom role for an account
|
|
31
|
+
* @param accountId - The account ID
|
|
32
|
+
* @param roleIds - The ids of the roles to delete
|
|
33
|
+
* @returns - The deleted roles. Note that basic role ids should be provided in A style and not in B style.
|
|
34
|
+
*/
|
|
21
35
|
deleteCustomRole(accountId: number, roleIds: number[]): Promise<RolesResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Update a custom role for an account
|
|
38
|
+
* @param accountId - The account ID
|
|
39
|
+
* @param updateRequests - The requests to update the roles
|
|
40
|
+
* @returns - The updated roles. Note that basic role ids should be provided in A style and not in B style.
|
|
41
|
+
*/
|
|
22
42
|
updateCustomRole(accountId: number, updateRequests: RoleUpdateRequest[]): Promise<RolesResponse>;
|
|
23
43
|
private sendRoleRequest;
|
|
24
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles-service.d.ts","sourceRoot":"","sources":["../../src/roles-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"roles-service.d.ts","sourceRoot":"","sources":["../../src/roles-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMlF,qBAAa,YAAY;IACvB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,kBAAkB,CAA4B;IAEtD;;;;OAIG;gBACS,UAAU,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAqBnF;;;;;OAKG;IACG,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,KAAK,GAAE,GAAG,GAAG,GAAS,GAAG,OAAO,CAAC,aAAa,CAAC;IAI1G;;;;;;OAMG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAU7F;;;;;OAKG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAMpF;;;;;OAKG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;YAMxF,eAAe;CAkC9B"}
|
|
@@ -4,7 +4,6 @@ import { getAttributionsFromApi } from './attributions-service.mjs';
|
|
|
4
4
|
import { ERROR_MESSAGES, DEFAULT_FETCH_OPTIONS, APP_NAME } from './constants.mjs';
|
|
5
5
|
|
|
6
6
|
const API_PATH = '/roles/account/{accountId}';
|
|
7
|
-
const A_STYLE_NAME = 'A';
|
|
8
7
|
class RolesService {
|
|
9
8
|
httpClient;
|
|
10
9
|
fetchOptions;
|
|
@@ -37,11 +36,19 @@ class RolesService {
|
|
|
37
36
|
/**
|
|
38
37
|
* Get all roles for an account
|
|
39
38
|
* @param accountId - The account ID
|
|
39
|
+
* @param style - The style of the roles to return, either 'A' or 'B', default is 'A'. 'B' is not deprecated and only available for backward compatibility.
|
|
40
40
|
* @returns - The roles for the account, both basic and custom roles. Note that basic role ids are returned in A style and not B style.
|
|
41
41
|
*/
|
|
42
|
-
async getRoles(accountId, resourceTypes) {
|
|
43
|
-
return await this.sendRoleRequest('GET', accountId, {}, { resourceTypes });
|
|
42
|
+
async getRoles(accountId, resourceTypes, style = 'A') {
|
|
43
|
+
return await this.sendRoleRequest('GET', accountId, {}, { resourceTypes, style });
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a custom role for an account
|
|
47
|
+
* @param accountId - The account ID
|
|
48
|
+
* @param roles - The roles to create
|
|
49
|
+
* @returns - The created roles
|
|
50
|
+
* Note that basic role ids should be provided in A style and not in B style.
|
|
51
|
+
*/
|
|
45
52
|
async createCustomRole(accountId, roles) {
|
|
46
53
|
if (roles.length === 0) {
|
|
47
54
|
throw new Error('Roles array cannot be empty');
|
|
@@ -50,17 +57,29 @@ class RolesService {
|
|
|
50
57
|
customRoles: roles,
|
|
51
58
|
});
|
|
52
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Delete a custom role for an account
|
|
62
|
+
* @param accountId - The account ID
|
|
63
|
+
* @param roleIds - The ids of the roles to delete
|
|
64
|
+
* @returns - The deleted roles. Note that basic role ids should be provided in A style and not in B style.
|
|
65
|
+
*/
|
|
53
66
|
async deleteCustomRole(accountId, roleIds) {
|
|
54
67
|
return await this.sendRoleRequest('DELETE', accountId, {
|
|
55
68
|
ids: roleIds,
|
|
56
69
|
});
|
|
57
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Update a custom role for an account
|
|
73
|
+
* @param accountId - The account ID
|
|
74
|
+
* @param updateRequests - The requests to update the roles
|
|
75
|
+
* @returns - The updated roles. Note that basic role ids should be provided in A style and not in B style.
|
|
76
|
+
*/
|
|
58
77
|
async updateCustomRole(accountId, updateRequests) {
|
|
59
78
|
return await this.sendRoleRequest('PATCH', accountId, {
|
|
60
79
|
customRoles: updateRequests,
|
|
61
80
|
});
|
|
62
81
|
}
|
|
63
|
-
async sendRoleRequest(method, accountId, body, additionalQueryParams = {}) {
|
|
82
|
+
async sendRoleRequest(method, accountId, body, additionalQueryParams = {}, style = 'A') {
|
|
64
83
|
try {
|
|
65
84
|
return await this.httpClient.fetch({
|
|
66
85
|
url: {
|
|
@@ -68,7 +87,7 @@ class RolesService {
|
|
|
68
87
|
path: API_PATH.replace('{accountId}', accountId.toString()),
|
|
69
88
|
},
|
|
70
89
|
query: {
|
|
71
|
-
style:
|
|
90
|
+
style: style,
|
|
72
91
|
...additionalQueryParams,
|
|
73
92
|
},
|
|
74
93
|
method,
|
package/dist/roles-service.d.ts
CHANGED
|
@@ -14,11 +14,31 @@ export declare class RolesService {
|
|
|
14
14
|
/**
|
|
15
15
|
* Get all roles for an account
|
|
16
16
|
* @param accountId - The account ID
|
|
17
|
+
* @param style - The style of the roles to return, either 'A' or 'B', default is 'A'. 'B' is not deprecated and only available for backward compatibility.
|
|
17
18
|
* @returns - The roles for the account, both basic and custom roles. Note that basic role ids are returned in A style and not B style.
|
|
18
19
|
*/
|
|
19
|
-
getRoles(accountId: number, resourceTypes: string[]): Promise<RolesResponse>;
|
|
20
|
+
getRoles(accountId: number, resourceTypes: string[], style?: 'A' | 'B'): Promise<RolesResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Create a custom role for an account
|
|
23
|
+
* @param accountId - The account ID
|
|
24
|
+
* @param roles - The roles to create
|
|
25
|
+
* @returns - The created roles
|
|
26
|
+
* Note that basic role ids should be provided in A style and not in B style.
|
|
27
|
+
*/
|
|
20
28
|
createCustomRole(accountId: number, roles: RoleCreateRequest[]): Promise<RolesResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Delete a custom role for an account
|
|
31
|
+
* @param accountId - The account ID
|
|
32
|
+
* @param roleIds - The ids of the roles to delete
|
|
33
|
+
* @returns - The deleted roles. Note that basic role ids should be provided in A style and not in B style.
|
|
34
|
+
*/
|
|
21
35
|
deleteCustomRole(accountId: number, roleIds: number[]): Promise<RolesResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Update a custom role for an account
|
|
38
|
+
* @param accountId - The account ID
|
|
39
|
+
* @param updateRequests - The requests to update the roles
|
|
40
|
+
* @returns - The updated roles. Note that basic role ids should be provided in A style and not in B style.
|
|
41
|
+
*/
|
|
22
42
|
updateCustomRole(accountId: number, updateRequests: RoleUpdateRequest[]): Promise<RolesResponse>;
|
|
23
43
|
private sendRoleRequest;
|
|
24
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles-service.d.ts","sourceRoot":"","sources":["../src/roles-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"roles-service.d.ts","sourceRoot":"","sources":["../src/roles-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMlF,qBAAa,YAAY;IACvB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,kBAAkB,CAA4B;IAEtD;;;;OAIG;gBACS,UAAU,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAqBnF;;;;;OAKG;IACG,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,KAAK,GAAE,GAAG,GAAG,GAAS,GAAG,OAAO,CAAC,aAAa,CAAC;IAI1G;;;;;;OAMG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAU7F;;;;;OAKG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAMpF;;;;;OAKG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;YAMxF,eAAe;CAkC9B"}
|
package/dist/roles-service.js
CHANGED
|
@@ -6,7 +6,6 @@ const attributionsService = require('./attributions-service.js');
|
|
|
6
6
|
const constants = require('./constants.js');
|
|
7
7
|
|
|
8
8
|
const API_PATH = '/roles/account/{accountId}';
|
|
9
|
-
const A_STYLE_NAME = 'A';
|
|
10
9
|
class RolesService {
|
|
11
10
|
httpClient;
|
|
12
11
|
fetchOptions;
|
|
@@ -39,11 +38,19 @@ class RolesService {
|
|
|
39
38
|
/**
|
|
40
39
|
* Get all roles for an account
|
|
41
40
|
* @param accountId - The account ID
|
|
41
|
+
* @param style - The style of the roles to return, either 'A' or 'B', default is 'A'. 'B' is not deprecated and only available for backward compatibility.
|
|
42
42
|
* @returns - The roles for the account, both basic and custom roles. Note that basic role ids are returned in A style and not B style.
|
|
43
43
|
*/
|
|
44
|
-
async getRoles(accountId, resourceTypes) {
|
|
45
|
-
return await this.sendRoleRequest('GET', accountId, {}, { resourceTypes });
|
|
44
|
+
async getRoles(accountId, resourceTypes, style = 'A') {
|
|
45
|
+
return await this.sendRoleRequest('GET', accountId, {}, { resourceTypes, style });
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a custom role for an account
|
|
49
|
+
* @param accountId - The account ID
|
|
50
|
+
* @param roles - The roles to create
|
|
51
|
+
* @returns - The created roles
|
|
52
|
+
* Note that basic role ids should be provided in A style and not in B style.
|
|
53
|
+
*/
|
|
47
54
|
async createCustomRole(accountId, roles) {
|
|
48
55
|
if (roles.length === 0) {
|
|
49
56
|
throw new Error('Roles array cannot be empty');
|
|
@@ -52,17 +59,29 @@ class RolesService {
|
|
|
52
59
|
customRoles: roles,
|
|
53
60
|
});
|
|
54
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Delete a custom role for an account
|
|
64
|
+
* @param accountId - The account ID
|
|
65
|
+
* @param roleIds - The ids of the roles to delete
|
|
66
|
+
* @returns - The deleted roles. Note that basic role ids should be provided in A style and not in B style.
|
|
67
|
+
*/
|
|
55
68
|
async deleteCustomRole(accountId, roleIds) {
|
|
56
69
|
return await this.sendRoleRequest('DELETE', accountId, {
|
|
57
70
|
ids: roleIds,
|
|
58
71
|
});
|
|
59
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Update a custom role for an account
|
|
75
|
+
* @param accountId - The account ID
|
|
76
|
+
* @param updateRequests - The requests to update the roles
|
|
77
|
+
* @returns - The updated roles. Note that basic role ids should be provided in A style and not in B style.
|
|
78
|
+
*/
|
|
60
79
|
async updateCustomRole(accountId, updateRequests) {
|
|
61
80
|
return await this.sendRoleRequest('PATCH', accountId, {
|
|
62
81
|
customRoles: updateRequests,
|
|
63
82
|
});
|
|
64
83
|
}
|
|
65
|
-
async sendRoleRequest(method, accountId, body, additionalQueryParams = {}) {
|
|
84
|
+
async sendRoleRequest(method, accountId, body, additionalQueryParams = {}, style = 'A') {
|
|
66
85
|
try {
|
|
67
86
|
return await this.httpClient.fetch({
|
|
68
87
|
url: {
|
|
@@ -70,7 +89,7 @@ class RolesService {
|
|
|
70
89
|
path: API_PATH.replace('{accountId}', accountId.toString()),
|
|
71
90
|
},
|
|
72
91
|
query: {
|
|
73
|
-
style:
|
|
92
|
+
style: style,
|
|
74
93
|
...additionalQueryParams,
|
|
75
94
|
},
|
|
76
95
|
method,
|