@mondaydotcomorg/monday-authorization 3.0.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-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +2 -15
- package/dist/authorization-service.js +2 -2
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +12 -0
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +3 -16
- package/dist/esm/authorization-service.mjs +2 -2
- package/dist/esm/constants.d.ts +3 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.mjs +12 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/roles-service.d.ts +45 -0
- package/dist/esm/roles-service.d.ts.map +1 -0
- package/dist/esm/roles-service.mjs +110 -0
- package/dist/esm/types/roles.d.ts +38 -0
- package/dist/esm/types/roles.d.ts.map +1 -0
- package/dist/esm/types/roles.mjs +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/roles-service.d.ts +45 -0
- package/dist/roles-service.d.ts.map +1 -0
- package/dist/roles-service.js +112 -0
- package/dist/types/roles.d.ts +38 -0
- package/dist/types/roles.d.ts.map +1 -0
- package/dist/types/roles.js +7 -0
- 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
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAW3C,qBAAa,8BAA8B;IACzC,OAAO,CAAC,MAAM,CAAC,OAAO,CAA8B;IACpD,OAAO,CAAC,MAAM,CAAC,SAAS,CAGb;IACX,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACS,UAAU,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAqBnF;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,GAC1D,OAAO,CAAC,yBAAyB,CAAC;IA6BrC;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,yBAAyB,CAAC;IAkCrC;;;;;;;UAOM;IACA,6BAA6B,CACjC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,2BAA2B,EAAE,GACzD,OAAO,CAAC,2BAA2B,EAAE,CAAC;YAY3B,oBAAoB;IA4BlC,OAAO,CAAC,MAAM,CAAC,cAAc;IAe7B;;;;;;;OAOG;IACG,kCAAkC,IAAI,OAAO,CAAC,OAAO,CAAC;CAoB7D"}
|
|
@@ -13,19 +13,6 @@ const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
|
13
13
|
|
|
14
14
|
const chunk__default = /*#__PURE__*/_interopDefault(chunk);
|
|
15
15
|
|
|
16
|
-
function getDefaultFetchOptions() {
|
|
17
|
-
return {
|
|
18
|
-
retryPolicy: {
|
|
19
|
-
useRetries: true,
|
|
20
|
-
maxRetries: 3,
|
|
21
|
-
retryDelayMS: 10,
|
|
22
|
-
},
|
|
23
|
-
logPolicy: {
|
|
24
|
-
logErrors: 'error',
|
|
25
|
-
logRequests: 'info',
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
16
|
class AuthorizationAttributesService {
|
|
30
17
|
static LOG_TAG = 'authorization_attributes';
|
|
31
18
|
static API_PATHS = {
|
|
@@ -48,11 +35,11 @@ class AuthorizationAttributesService {
|
|
|
48
35
|
}
|
|
49
36
|
}
|
|
50
37
|
if (!fetchOptions) {
|
|
51
|
-
fetchOptions =
|
|
38
|
+
fetchOptions = constants.DEFAULT_FETCH_OPTIONS;
|
|
52
39
|
}
|
|
53
40
|
else {
|
|
54
41
|
fetchOptions = {
|
|
55
|
-
...
|
|
42
|
+
...constants.DEFAULT_FETCH_OPTIONS,
|
|
56
43
|
...fetchOptions,
|
|
57
44
|
};
|
|
58
45
|
}
|
|
@@ -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;
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
|
|
2
|
+
import { FetcherConfig } from '@mondaydotcomorg/trident-backend-api';
|
|
1
3
|
export declare const APP_NAME = "authorization";
|
|
2
4
|
export declare const ERROR_MESSAGES: {
|
|
3
5
|
readonly HTTP_CLIENT_NOT_INITIALIZED: "MondayAuthorization: HTTP client is not initialized";
|
|
4
6
|
readonly REQUEST_FAILED: (method: string, status: number, reason: string) => string;
|
|
5
7
|
};
|
|
8
|
+
export declare const DEFAULT_FETCH_OPTIONS: RecursivePartial<FetcherConfig>;
|
|
6
9
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AAExC,eAAO,MAAM,cAAc;;sCAEA,MAAM,UAAU,MAAM,UAAU,MAAM;CAEvD,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AAExC,eAAO,MAAM,cAAc;;sCAEA,MAAM,UAAU,MAAM,UAAU,MAAM;CAEvD,CAAC;AAEX,eAAO,MAAM,qBAAqB,EAAE,gBAAgB,CAAC,aAAa,CAUjE,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -5,6 +5,18 @@ const ERROR_MESSAGES = {
|
|
|
5
5
|
HTTP_CLIENT_NOT_INITIALIZED: 'MondayAuthorization: HTTP client is not initialized',
|
|
6
6
|
REQUEST_FAILED: (method, status, reason) => `MondayAuthorization: [${method}] request failed with status ${status} with reason: ${reason}`,
|
|
7
7
|
};
|
|
8
|
+
const DEFAULT_FETCH_OPTIONS = {
|
|
9
|
+
retryPolicy: {
|
|
10
|
+
useRetries: true,
|
|
11
|
+
maxRetries: 3,
|
|
12
|
+
retryDelayMS: 10,
|
|
13
|
+
},
|
|
14
|
+
logPolicy: {
|
|
15
|
+
logErrors: 'error',
|
|
16
|
+
logRequests: 'info',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
8
19
|
|
|
9
20
|
exports.APP_NAME = APP_NAME;
|
|
21
|
+
exports.DEFAULT_FETCH_OPTIONS = DEFAULT_FETCH_OPTIONS;
|
|
10
22
|
exports.ERROR_MESSAGES = ERROR_MESSAGES;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../../src/authorization-attributes-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../../src/authorization-attributes-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAW3C,qBAAa,8BAA8B;IACzC,OAAO,CAAC,MAAM,CAAC,OAAO,CAA8B;IACpD,OAAO,CAAC,MAAM,CAAC,SAAS,CAGb;IACX,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACS,UAAU,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAqBnF;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,GAC1D,OAAO,CAAC,yBAAyB,CAAC;IA6BrC;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,yBAAyB,CAAC;IAkCrC;;;;;;;UAOM;IACA,6BAA6B,CACjC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,2BAA2B,EAAE,GACzD,OAAO,CAAC,2BAA2B,EAAE,CAAC;YAY3B,oBAAoB;IA4BlC,OAAO,CAAC,MAAM,CAAC,cAAc;IAe7B;;;;;;;OAOG;IACG,kCAAkC,IAAI,OAAO,CAAC,OAAO,CAAC;CAoB7D"}
|
|
@@ -5,21 +5,8 @@ import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
|
|
|
5
5
|
import { logger } from './authorization-internal-service.mjs';
|
|
6
6
|
import { getAttributionsFromApi } from './attributions-service.mjs';
|
|
7
7
|
import { ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE, RESOURCE_ATTRIBUTES_SNS_ARN_SECRET_NAME, RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND } from './constants/sns.mjs';
|
|
8
|
-
import { ERROR_MESSAGES, APP_NAME } from './constants.mjs';
|
|
8
|
+
import { ERROR_MESSAGES, DEFAULT_FETCH_OPTIONS, APP_NAME } from './constants.mjs';
|
|
9
9
|
|
|
10
|
-
function getDefaultFetchOptions() {
|
|
11
|
-
return {
|
|
12
|
-
retryPolicy: {
|
|
13
|
-
useRetries: true,
|
|
14
|
-
maxRetries: 3,
|
|
15
|
-
retryDelayMS: 10,
|
|
16
|
-
},
|
|
17
|
-
logPolicy: {
|
|
18
|
-
logErrors: 'error',
|
|
19
|
-
logRequests: 'info',
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
10
|
class AuthorizationAttributesService {
|
|
24
11
|
static LOG_TAG = 'authorization_attributes';
|
|
25
12
|
static API_PATHS = {
|
|
@@ -42,11 +29,11 @@ class AuthorizationAttributesService {
|
|
|
42
29
|
}
|
|
43
30
|
}
|
|
44
31
|
if (!fetchOptions) {
|
|
45
|
-
fetchOptions =
|
|
32
|
+
fetchOptions = DEFAULT_FETCH_OPTIONS;
|
|
46
33
|
}
|
|
47
34
|
else {
|
|
48
35
|
fetchOptions = {
|
|
49
|
-
...
|
|
36
|
+
...DEFAULT_FETCH_OPTIONS,
|
|
50
37
|
...fetchOptions,
|
|
51
38
|
};
|
|
52
39
|
}
|
|
@@ -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 };
|
package/dist/esm/constants.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
|
|
2
|
+
import { FetcherConfig } from '@mondaydotcomorg/trident-backend-api';
|
|
1
3
|
export declare const APP_NAME = "authorization";
|
|
2
4
|
export declare const ERROR_MESSAGES: {
|
|
3
5
|
readonly HTTP_CLIENT_NOT_INITIALIZED: "MondayAuthorization: HTTP client is not initialized";
|
|
4
6
|
readonly REQUEST_FAILED: (method: string, status: number, reason: string) => string;
|
|
5
7
|
};
|
|
8
|
+
export declare const DEFAULT_FETCH_OPTIONS: RecursivePartial<FetcherConfig>;
|
|
6
9
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AAExC,eAAO,MAAM,cAAc;;sCAEA,MAAM,UAAU,MAAM,UAAU,MAAM;CAEvD,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AAExC,eAAO,MAAM,cAAc;;sCAEA,MAAM,UAAU,MAAM,UAAU,MAAM;CAEvD,CAAC;AAEX,eAAO,MAAM,qBAAqB,EAAE,gBAAgB,CAAC,aAAa,CAUjE,CAAC"}
|
package/dist/esm/constants.mjs
CHANGED
|
@@ -3,5 +3,16 @@ const ERROR_MESSAGES = {
|
|
|
3
3
|
HTTP_CLIENT_NOT_INITIALIZED: 'MondayAuthorization: HTTP client is not initialized',
|
|
4
4
|
REQUEST_FAILED: (method, status, reason) => `MondayAuthorization: [${method}] request failed with status ${status} with reason: ${reason}`,
|
|
5
5
|
};
|
|
6
|
+
const DEFAULT_FETCH_OPTIONS = {
|
|
7
|
+
retryPolicy: {
|
|
8
|
+
useRetries: true,
|
|
9
|
+
maxRetries: 3,
|
|
10
|
+
retryDelayMS: 10,
|
|
11
|
+
},
|
|
12
|
+
logPolicy: {
|
|
13
|
+
logErrors: 'error',
|
|
14
|
+
logRequests: 'info',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
6
17
|
|
|
7
|
-
export { APP_NAME, ERROR_MESSAGES };
|
|
18
|
+
export { APP_NAME, DEFAULT_FETCH_OPTIONS, ERROR_MESSAGES };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export declare function init(options?: InitOptions): Promise<void>;
|
|
|
10
10
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './authorization-middleware';
|
|
11
11
|
export { AuthorizationService, AuthorizeResponse } from './authorization-service';
|
|
12
12
|
export { AuthorizationAttributesService } from './authorization-attributes-service';
|
|
13
|
+
export { RolesService } from './roles-service';
|
|
13
14
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
|
14
15
|
export { Translation, ScopedAction, ScopedActionResponseObject, ScopedActionPermit, } from './types/scoped-actions-contracts';
|
|
16
|
+
export { CustomRole, BasicRole, RoleType, RoleCreateRequest, RoleUpdateRequest, RolesResponse } from './types/roles';
|
|
15
17
|
export { TestKit };
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;CACjD;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBAcnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;CACjD;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBAcnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErH,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -5,6 +5,8 @@ import * as testKit_index from './testKit/index.mjs';
|
|
|
5
5
|
export { testKit_index as TestKit };
|
|
6
6
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware } from './authorization-middleware.mjs';
|
|
7
7
|
export { AuthorizationAttributesService } from './authorization-attributes-service.mjs';
|
|
8
|
+
export { RolesService } from './roles-service.mjs';
|
|
9
|
+
export { RoleType } from './types/roles.mjs';
|
|
8
10
|
|
|
9
11
|
async function init(options = {}) {
|
|
10
12
|
if (options.prometheus) {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FetcherConfig, HttpClient } from '@mondaydotcomorg/trident-backend-api';
|
|
2
|
+
import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
|
|
3
|
+
import { RoleCreateRequest, RolesResponse, RoleUpdateRequest } from './types/roles';
|
|
4
|
+
export declare class RolesService {
|
|
5
|
+
private httpClient;
|
|
6
|
+
private fetchOptions;
|
|
7
|
+
private attributionHeaders;
|
|
8
|
+
/**
|
|
9
|
+
* Public constructor to create the AuthorizationAttributesService instance.
|
|
10
|
+
* @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
|
|
11
|
+
* @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
|
|
12
|
+
*/
|
|
13
|
+
constructor(httpClient?: HttpClient, fetchOptions?: RecursivePartial<FetcherConfig>);
|
|
14
|
+
/**
|
|
15
|
+
* Get all roles for an account
|
|
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.
|
|
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.
|
|
19
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
42
|
+
updateCustomRole(accountId: number, updateRequests: RoleUpdateRequest[]): Promise<RolesResponse>;
|
|
43
|
+
private sendRoleRequest;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=roles-service.d.ts.map
|
|
@@ -0,0 +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;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"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Api } from '@mondaydotcomorg/trident-backend-api';
|
|
2
|
+
import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
|
|
3
|
+
import { getAttributionsFromApi } from './attributions-service.mjs';
|
|
4
|
+
import { ERROR_MESSAGES, DEFAULT_FETCH_OPTIONS, APP_NAME } from './constants.mjs';
|
|
5
|
+
|
|
6
|
+
const API_PATH = '/roles/account/{accountId}';
|
|
7
|
+
class RolesService {
|
|
8
|
+
httpClient;
|
|
9
|
+
fetchOptions;
|
|
10
|
+
attributionHeaders;
|
|
11
|
+
/**
|
|
12
|
+
* Public constructor to create the AuthorizationAttributesService instance.
|
|
13
|
+
* @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
|
|
14
|
+
* @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
|
|
15
|
+
*/
|
|
16
|
+
constructor(httpClient, fetchOptions) {
|
|
17
|
+
if (!httpClient) {
|
|
18
|
+
httpClient = Api.getPart('httpClient');
|
|
19
|
+
if (!httpClient) {
|
|
20
|
+
throw new Error(ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!fetchOptions) {
|
|
24
|
+
fetchOptions = DEFAULT_FETCH_OPTIONS;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
fetchOptions = {
|
|
28
|
+
...DEFAULT_FETCH_OPTIONS,
|
|
29
|
+
...fetchOptions,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
this.httpClient = httpClient;
|
|
33
|
+
this.fetchOptions = fetchOptions;
|
|
34
|
+
this.attributionHeaders = getAttributionsFromApi();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get all roles for an account
|
|
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
|
+
* @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
|
+
*/
|
|
42
|
+
async getRoles(accountId, resourceTypes, style = 'A') {
|
|
43
|
+
return await this.sendRoleRequest('GET', accountId, {}, { resourceTypes, style });
|
|
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
|
+
*/
|
|
52
|
+
async createCustomRole(accountId, roles) {
|
|
53
|
+
if (roles.length === 0) {
|
|
54
|
+
throw new Error('Roles array cannot be empty');
|
|
55
|
+
}
|
|
56
|
+
return await this.sendRoleRequest('PUT', accountId, {
|
|
57
|
+
customRoles: roles,
|
|
58
|
+
});
|
|
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
|
+
*/
|
|
66
|
+
async deleteCustomRole(accountId, roleIds) {
|
|
67
|
+
return await this.sendRoleRequest('DELETE', accountId, {
|
|
68
|
+
ids: roleIds,
|
|
69
|
+
});
|
|
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
|
+
*/
|
|
77
|
+
async updateCustomRole(accountId, updateRequests) {
|
|
78
|
+
return await this.sendRoleRequest('PATCH', accountId, {
|
|
79
|
+
customRoles: updateRequests,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async sendRoleRequest(method, accountId, body, additionalQueryParams = {}, style = 'A') {
|
|
83
|
+
try {
|
|
84
|
+
return await this.httpClient.fetch({
|
|
85
|
+
url: {
|
|
86
|
+
appName: APP_NAME,
|
|
87
|
+
path: API_PATH.replace('{accountId}', accountId.toString()),
|
|
88
|
+
},
|
|
89
|
+
query: {
|
|
90
|
+
style: style,
|
|
91
|
+
...additionalQueryParams,
|
|
92
|
+
},
|
|
93
|
+
method,
|
|
94
|
+
headers: {
|
|
95
|
+
'Content-Type': 'application/json',
|
|
96
|
+
...this.attributionHeaders,
|
|
97
|
+
},
|
|
98
|
+
body: method === 'GET' ? undefined : body,
|
|
99
|
+
}, this.fetchOptions);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (err instanceof HttpFetcherError) {
|
|
103
|
+
throw new Error(ERROR_MESSAGES.REQUEST_FAILED('sendRoleRequest', err.status, err.message));
|
|
104
|
+
}
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export { RolesService };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare enum RoleType {
|
|
2
|
+
CUSTOM = "custom_role",
|
|
3
|
+
BASIC = "basic_role"
|
|
4
|
+
}
|
|
5
|
+
export interface CustomRole {
|
|
6
|
+
id?: number;
|
|
7
|
+
name: string;
|
|
8
|
+
resourceType: string;
|
|
9
|
+
resourceId: number;
|
|
10
|
+
basicRoleId: number;
|
|
11
|
+
basicRoleType: RoleType;
|
|
12
|
+
}
|
|
13
|
+
export interface BasicRole {
|
|
14
|
+
id: number;
|
|
15
|
+
resourceType: string;
|
|
16
|
+
roleType: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RolesResponse {
|
|
20
|
+
customRoles: CustomRole[];
|
|
21
|
+
basicRoles?: BasicRole[];
|
|
22
|
+
}
|
|
23
|
+
export interface RoleCreateRequest {
|
|
24
|
+
name: string;
|
|
25
|
+
resourceType: string;
|
|
26
|
+
resourceId: number;
|
|
27
|
+
sourceRole: {
|
|
28
|
+
id: number;
|
|
29
|
+
type: RoleType;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface RoleUpdateRequest {
|
|
33
|
+
id: number;
|
|
34
|
+
updateAttributes: {
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../../src/types/roles.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,MAAM,gBAAgB;IACtB,KAAK,eAAe;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,QAAQ,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE;QACV,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,QAAQ,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export declare function init(options?: InitOptions): Promise<void>;
|
|
|
10
10
|
export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './authorization-middleware';
|
|
11
11
|
export { AuthorizationService, AuthorizeResponse } from './authorization-service';
|
|
12
12
|
export { AuthorizationAttributesService } from './authorization-attributes-service';
|
|
13
|
+
export { RolesService } from './roles-service';
|
|
13
14
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
|
14
15
|
export { Translation, ScopedAction, ScopedActionResponseObject, ScopedActionPermit, } from './types/scoped-actions-contracts';
|
|
16
|
+
export { CustomRole, BasicRole, RoleType, RoleCreateRequest, RoleUpdateRequest, RolesResponse } from './types/roles';
|
|
15
17
|
export { TestKit };
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;CACjD;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBAcnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;CACjD;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBAcnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,EACL,WAAW,EACX,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErH,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,8 @@ const authorizationService = require('./authorization-service.js');
|
|
|
5
5
|
const testKit_index = require('./testKit/index.js');
|
|
6
6
|
const authorizationMiddleware = require('./authorization-middleware.js');
|
|
7
7
|
const authorizationAttributesService = require('./authorization-attributes-service.js');
|
|
8
|
+
const rolesService = require('./roles-service.js');
|
|
9
|
+
const types_roles = require('./types/roles.js');
|
|
8
10
|
|
|
9
11
|
async function init(options = {}) {
|
|
10
12
|
if (options.prometheus) {
|
|
@@ -26,4 +28,9 @@ exports.authorizationCheckMiddleware = authorizationMiddleware.authorizationChec
|
|
|
26
28
|
exports.getAuthorizationMiddleware = authorizationMiddleware.getAuthorizationMiddleware;
|
|
27
29
|
exports.skipAuthorizationMiddleware = authorizationMiddleware.skipAuthorizationMiddleware;
|
|
28
30
|
exports.AuthorizationAttributesService = authorizationAttributesService.AuthorizationAttributesService;
|
|
31
|
+
exports.RolesService = rolesService.RolesService;
|
|
32
|
+
Object.defineProperty(exports, 'RoleType', {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: () => types_roles.RoleType
|
|
35
|
+
});
|
|
29
36
|
exports.init = init;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FetcherConfig, HttpClient } from '@mondaydotcomorg/trident-backend-api';
|
|
2
|
+
import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
|
|
3
|
+
import { RoleCreateRequest, RolesResponse, RoleUpdateRequest } from './types/roles';
|
|
4
|
+
export declare class RolesService {
|
|
5
|
+
private httpClient;
|
|
6
|
+
private fetchOptions;
|
|
7
|
+
private attributionHeaders;
|
|
8
|
+
/**
|
|
9
|
+
* Public constructor to create the AuthorizationAttributesService instance.
|
|
10
|
+
* @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
|
|
11
|
+
* @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
|
|
12
|
+
*/
|
|
13
|
+
constructor(httpClient?: HttpClient, fetchOptions?: RecursivePartial<FetcherConfig>);
|
|
14
|
+
/**
|
|
15
|
+
* Get all roles for an account
|
|
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.
|
|
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.
|
|
19
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
42
|
+
updateCustomRole(accountId: number, updateRequests: RoleUpdateRequest[]): Promise<RolesResponse>;
|
|
43
|
+
private sendRoleRequest;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=roles-service.d.ts.map
|
|
@@ -0,0 +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;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"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const tridentBackendApi = require('@mondaydotcomorg/trident-backend-api');
|
|
4
|
+
const mondayFetchApi = require('@mondaydotcomorg/monday-fetch-api');
|
|
5
|
+
const attributionsService = require('./attributions-service.js');
|
|
6
|
+
const constants = require('./constants.js');
|
|
7
|
+
|
|
8
|
+
const API_PATH = '/roles/account/{accountId}';
|
|
9
|
+
class RolesService {
|
|
10
|
+
httpClient;
|
|
11
|
+
fetchOptions;
|
|
12
|
+
attributionHeaders;
|
|
13
|
+
/**
|
|
14
|
+
* Public constructor to create the AuthorizationAttributesService instance.
|
|
15
|
+
* @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
|
|
16
|
+
* @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
|
|
17
|
+
*/
|
|
18
|
+
constructor(httpClient, fetchOptions) {
|
|
19
|
+
if (!httpClient) {
|
|
20
|
+
httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
21
|
+
if (!httpClient) {
|
|
22
|
+
throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!fetchOptions) {
|
|
26
|
+
fetchOptions = constants.DEFAULT_FETCH_OPTIONS;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
fetchOptions = {
|
|
30
|
+
...constants.DEFAULT_FETCH_OPTIONS,
|
|
31
|
+
...fetchOptions,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
this.httpClient = httpClient;
|
|
35
|
+
this.fetchOptions = fetchOptions;
|
|
36
|
+
this.attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get all roles for an account
|
|
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
|
+
* @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
|
+
*/
|
|
44
|
+
async getRoles(accountId, resourceTypes, style = 'A') {
|
|
45
|
+
return await this.sendRoleRequest('GET', accountId, {}, { resourceTypes, style });
|
|
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
|
+
*/
|
|
54
|
+
async createCustomRole(accountId, roles) {
|
|
55
|
+
if (roles.length === 0) {
|
|
56
|
+
throw new Error('Roles array cannot be empty');
|
|
57
|
+
}
|
|
58
|
+
return await this.sendRoleRequest('PUT', accountId, {
|
|
59
|
+
customRoles: roles,
|
|
60
|
+
});
|
|
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
|
+
*/
|
|
68
|
+
async deleteCustomRole(accountId, roleIds) {
|
|
69
|
+
return await this.sendRoleRequest('DELETE', accountId, {
|
|
70
|
+
ids: roleIds,
|
|
71
|
+
});
|
|
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
|
+
*/
|
|
79
|
+
async updateCustomRole(accountId, updateRequests) {
|
|
80
|
+
return await this.sendRoleRequest('PATCH', accountId, {
|
|
81
|
+
customRoles: updateRequests,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async sendRoleRequest(method, accountId, body, additionalQueryParams = {}, style = 'A') {
|
|
85
|
+
try {
|
|
86
|
+
return await this.httpClient.fetch({
|
|
87
|
+
url: {
|
|
88
|
+
appName: constants.APP_NAME,
|
|
89
|
+
path: API_PATH.replace('{accountId}', accountId.toString()),
|
|
90
|
+
},
|
|
91
|
+
query: {
|
|
92
|
+
style: style,
|
|
93
|
+
...additionalQueryParams,
|
|
94
|
+
},
|
|
95
|
+
method,
|
|
96
|
+
headers: {
|
|
97
|
+
'Content-Type': 'application/json',
|
|
98
|
+
...this.attributionHeaders,
|
|
99
|
+
},
|
|
100
|
+
body: method === 'GET' ? undefined : body,
|
|
101
|
+
}, this.fetchOptions);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
if (err instanceof mondayFetchApi.HttpFetcherError) {
|
|
105
|
+
throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('sendRoleRequest', err.status, err.message));
|
|
106
|
+
}
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
exports.RolesService = RolesService;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare enum RoleType {
|
|
2
|
+
CUSTOM = "custom_role",
|
|
3
|
+
BASIC = "basic_role"
|
|
4
|
+
}
|
|
5
|
+
export interface CustomRole {
|
|
6
|
+
id?: number;
|
|
7
|
+
name: string;
|
|
8
|
+
resourceType: string;
|
|
9
|
+
resourceId: number;
|
|
10
|
+
basicRoleId: number;
|
|
11
|
+
basicRoleType: RoleType;
|
|
12
|
+
}
|
|
13
|
+
export interface BasicRole {
|
|
14
|
+
id: number;
|
|
15
|
+
resourceType: string;
|
|
16
|
+
roleType: string;
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RolesResponse {
|
|
20
|
+
customRoles: CustomRole[];
|
|
21
|
+
basicRoles?: BasicRole[];
|
|
22
|
+
}
|
|
23
|
+
export interface RoleCreateRequest {
|
|
24
|
+
name: string;
|
|
25
|
+
resourceType: string;
|
|
26
|
+
resourceId: number;
|
|
27
|
+
sourceRole: {
|
|
28
|
+
id: number;
|
|
29
|
+
type: RoleType;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface RoleUpdateRequest {
|
|
33
|
+
id: number;
|
|
34
|
+
updateAttributes: {
|
|
35
|
+
name: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/types/roles.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,MAAM,gBAAgB;IACtB,KAAK,eAAe;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,QAAQ,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE;QACV,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,QAAQ,CAAC;KAChB,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH"}
|