@mondaydotcomorg/monday-authorization 2.1.1-feature-bashanye-remove-authorization-url-secret-usage.04a9d3c → 3.0.0-feature-bashanye-create-custom-roles-sdk.9c70903

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.
@@ -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;AAwB3C,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;IA+BrC;;;;;;;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"}
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 = getDefaultFetchOptions();
38
+ fetchOptions = constants.DEFAULT_FETCH_OPTIONS;
52
39
  }
53
40
  else {
54
41
  fetchOptions = {
55
- ...getDefaultFetchOptions(),
42
+ ...constants.DEFAULT_FETCH_OPTIONS,
56
43
  ...fetchOptions,
57
44
  };
58
45
  }
@@ -99,6 +86,9 @@ class AuthorizationAttributesService {
99
86
  */
100
87
  async deleteResourceAttributes(accountId, resource, attributeKeys) {
101
88
  const attributionHeaders = attributionsService.getAttributionsFromApi();
89
+ if (!resource.id) {
90
+ throw new Error('Resource ID is required');
91
+ }
102
92
  try {
103
93
  return await this.httpClient.fetch({
104
94
  url: {
@@ -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/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;AAwB3C,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;IA+BrC;;;;;;;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"}
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 = getDefaultFetchOptions();
32
+ fetchOptions = DEFAULT_FETCH_OPTIONS;
46
33
  }
47
34
  else {
48
35
  fetchOptions = {
49
- ...getDefaultFetchOptions(),
36
+ ...DEFAULT_FETCH_OPTIONS,
50
37
  ...fetchOptions,
51
38
  };
52
39
  }
@@ -93,6 +80,9 @@ class AuthorizationAttributesService {
93
80
  */
94
81
  async deleteResourceAttributes(accountId, resource, attributeKeys) {
95
82
  const attributionHeaders = getAttributionsFromApi();
83
+ if (!resource.id) {
84
+ throw new Error('Resource ID is required');
85
+ }
96
86
  try {
97
87
  return await this.httpClient.fetch({
98
88
  url: {
@@ -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"}
@@ -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 };
@@ -0,0 +1,25 @@
1
+ import { FetcherConfig, HttpClient } from '@mondaydotcomorg/trident-backend-api';
2
+ import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
3
+ import { CustomRole, RolesResponse, RoleUpdate } from './types/roles';
4
+ export declare class CustomRoles {
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
+ * @returns - The roles for the account, both basic and custom roles. Note that role ids are in A style and not B style.
18
+ */
19
+ getRoles(accountId: number, resourceTypes: string[]): Promise<RolesResponse>;
20
+ createCustomRole(accountId: number, roles: CustomRole[]): Promise<RolesResponse>;
21
+ deleteCustomRole(accountId: number, roleIds: number[]): Promise<RolesResponse>;
22
+ updateCustomRole(accountId: number, updateRequests: RoleUpdate[]): Promise<RolesResponse>;
23
+ private sendRoleRequest;
24
+ }
25
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAEvF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMpE,qBAAa,WAAW;IACtB,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;;;;OAIG;IACG,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAI5E,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAkBhF,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAM9E,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;YAMjF,eAAe;CA4B9B"}
@@ -0,0 +1,100 @@
1
+ import { Api } from '@mondaydotcomorg/trident-backend-api';
2
+ import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
3
+ import { ERROR_MESSAGES, DEFAULT_FETCH_OPTIONS, APP_NAME } from './constants.mjs';
4
+ import { getAttributionsFromApi } from './attributions-service.mjs';
5
+
6
+ const API_PATH = '/roles/account/{accountId}';
7
+ const STYLE = 'A';
8
+ class CustomRoles {
9
+ httpClient;
10
+ fetchOptions;
11
+ attributionHeaders;
12
+ /**
13
+ * Public constructor to create the AuthorizationAttributesService instance.
14
+ * @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
15
+ * @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
16
+ */
17
+ constructor(httpClient, fetchOptions) {
18
+ if (!httpClient) {
19
+ httpClient = Api.getPart('httpClient');
20
+ if (!httpClient) {
21
+ throw new Error(ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
22
+ }
23
+ }
24
+ if (!fetchOptions) {
25
+ fetchOptions = DEFAULT_FETCH_OPTIONS;
26
+ }
27
+ else {
28
+ fetchOptions = {
29
+ ...DEFAULT_FETCH_OPTIONS,
30
+ ...fetchOptions,
31
+ };
32
+ }
33
+ this.httpClient = httpClient;
34
+ this.fetchOptions = fetchOptions;
35
+ this.attributionHeaders = getAttributionsFromApi();
36
+ }
37
+ /**
38
+ * Get all roles for an account
39
+ * @param accountId - The account ID
40
+ * @returns - The roles for the account, both basic and custom roles. Note that role ids are in A style and not B style.
41
+ */
42
+ async getRoles(accountId, resourceTypes) {
43
+ return await this.sendRoleRequest('GET', accountId, {}, { resourceTypes: resourceTypes.join(',') });
44
+ }
45
+ async createCustomRole(accountId, roles) {
46
+ if (roles.length === 0) {
47
+ throw new Error('Roles array cannot be empty');
48
+ }
49
+ const serializedRoles = roles.map(role => ({
50
+ "name": role.name,
51
+ "resourceType": role.resourceType,
52
+ "resourceId": role.resourceId,
53
+ "sourceRole": {
54
+ "id": role.basicRoleId,
55
+ "type": role.basicRoleType,
56
+ }
57
+ }));
58
+ return await this.sendRoleRequest('PUT', accountId, {
59
+ customRoles: serializedRoles,
60
+ });
61
+ }
62
+ async deleteCustomRole(accountId, roleIds) {
63
+ return await this.sendRoleRequest('DELETE', accountId, {
64
+ ids: roleIds,
65
+ });
66
+ }
67
+ async updateCustomRole(accountId, updateRequests) {
68
+ return await this.sendRoleRequest('PATCH', accountId, {
69
+ customRoles: updateRequests,
70
+ });
71
+ }
72
+ async sendRoleRequest(method, accountId, body, additionalQueryParams = {}) {
73
+ try {
74
+ return await this.httpClient.fetch({
75
+ url: {
76
+ appName: APP_NAME,
77
+ path: API_PATH.replace('{accountId}', accountId.toString()),
78
+ },
79
+ query: {
80
+ style: STYLE,
81
+ ...additionalQueryParams,
82
+ },
83
+ method,
84
+ headers: {
85
+ 'Content-Type': 'application/json',
86
+ ...this.attributionHeaders,
87
+ },
88
+ body: body ? body : undefined,
89
+ }, this.fetchOptions);
90
+ }
91
+ catch (err) {
92
+ if (err instanceof HttpFetcherError) {
93
+ throw new Error(ERROR_MESSAGES.REQUEST_FAILED('sendRoleRequest', err.status, err.message));
94
+ }
95
+ throw err;
96
+ }
97
+ }
98
+ }
99
+
100
+ export { CustomRoles };
@@ -0,0 +1,29 @@
1
+ export interface CustomRole {
2
+ id?: number;
3
+ name: string;
4
+ resourceType: string;
5
+ resourceId: number;
6
+ basicRoleId: number;
7
+ basicRoleType: RoleType;
8
+ }
9
+ export interface BasicRole {
10
+ id: number;
11
+ resourceType: string;
12
+ roleType: string;
13
+ name: string;
14
+ }
15
+ export interface RolesResponse {
16
+ customRoles: CustomRole[];
17
+ basicRoles?: BasicRole[];
18
+ }
19
+ export declare enum RoleType {
20
+ CUSTOM = "custom_role",
21
+ BASIC = "basic_role"
22
+ }
23
+ export interface RoleUpdate {
24
+ id: number;
25
+ updatedAttributes: {
26
+ name: string;
27
+ };
28
+ }
29
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../../src/types/roles.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,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,CAAA;CAC1B;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,oBAAY,QAAQ;IAChB,MAAM,gBAAgB;IACtB,KAAK,eAAe;CACvB;AAED,MAAM,WAAW,UAAU;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,iBAAiB,EAAE;QACf,IAAI,EAAE,MAAM,CAAC;KAChB,CAAA;CACJ"}
@@ -0,0 +1,7 @@
1
+ var RoleType;
2
+ (function (RoleType) {
3
+ RoleType["CUSTOM"] = "custom_role";
4
+ RoleType["BASIC"] = "basic_role";
5
+ })(RoleType || (RoleType = {}));
6
+
7
+ export { RoleType };
@@ -0,0 +1,25 @@
1
+ import { FetcherConfig, HttpClient } from '@mondaydotcomorg/trident-backend-api';
2
+ import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
3
+ import { CustomRole, RolesResponse, RoleUpdate } from './types/roles';
4
+ export declare class CustomRoles {
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
+ * @returns - The roles for the account, both basic and custom roles. Note that role ids are in A style and not B style.
18
+ */
19
+ getRoles(accountId: number, resourceTypes: string[]): Promise<RolesResponse>;
20
+ createCustomRole(accountId: number, roles: CustomRole[]): Promise<RolesResponse>;
21
+ deleteCustomRole(accountId: number, roleIds: number[]): Promise<RolesResponse>;
22
+ updateCustomRole(accountId: number, updateRequests: RoleUpdate[]): Promise<RolesResponse>;
23
+ private sendRoleRequest;
24
+ }
25
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../src/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAEvF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMpE,qBAAa,WAAW;IACtB,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;;;;OAIG;IACG,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAI5E,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAkBhF,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAM9E,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;YAMjF,eAAe;CA4B9B"}
package/dist/roles.js ADDED
@@ -0,0 +1,102 @@
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 constants = require('./constants.js');
6
+ const attributionsService = require('./attributions-service.js');
7
+
8
+ const API_PATH = '/roles/account/{accountId}';
9
+ const STYLE = 'A';
10
+ class CustomRoles {
11
+ httpClient;
12
+ fetchOptions;
13
+ attributionHeaders;
14
+ /**
15
+ * Public constructor to create the AuthorizationAttributesService instance.
16
+ * @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
17
+ * @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
18
+ */
19
+ constructor(httpClient, fetchOptions) {
20
+ if (!httpClient) {
21
+ httpClient = tridentBackendApi.Api.getPart('httpClient');
22
+ if (!httpClient) {
23
+ throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
24
+ }
25
+ }
26
+ if (!fetchOptions) {
27
+ fetchOptions = constants.DEFAULT_FETCH_OPTIONS;
28
+ }
29
+ else {
30
+ fetchOptions = {
31
+ ...constants.DEFAULT_FETCH_OPTIONS,
32
+ ...fetchOptions,
33
+ };
34
+ }
35
+ this.httpClient = httpClient;
36
+ this.fetchOptions = fetchOptions;
37
+ this.attributionHeaders = attributionsService.getAttributionsFromApi();
38
+ }
39
+ /**
40
+ * Get all roles for an account
41
+ * @param accountId - The account ID
42
+ * @returns - The roles for the account, both basic and custom roles. Note that role ids are in A style and not B style.
43
+ */
44
+ async getRoles(accountId, resourceTypes) {
45
+ return await this.sendRoleRequest('GET', accountId, {}, { resourceTypes: resourceTypes.join(',') });
46
+ }
47
+ async createCustomRole(accountId, roles) {
48
+ if (roles.length === 0) {
49
+ throw new Error('Roles array cannot be empty');
50
+ }
51
+ const serializedRoles = roles.map(role => ({
52
+ "name": role.name,
53
+ "resourceType": role.resourceType,
54
+ "resourceId": role.resourceId,
55
+ "sourceRole": {
56
+ "id": role.basicRoleId,
57
+ "type": role.basicRoleType,
58
+ }
59
+ }));
60
+ return await this.sendRoleRequest('PUT', accountId, {
61
+ customRoles: serializedRoles,
62
+ });
63
+ }
64
+ async deleteCustomRole(accountId, roleIds) {
65
+ return await this.sendRoleRequest('DELETE', accountId, {
66
+ ids: roleIds,
67
+ });
68
+ }
69
+ async updateCustomRole(accountId, updateRequests) {
70
+ return await this.sendRoleRequest('PATCH', accountId, {
71
+ customRoles: updateRequests,
72
+ });
73
+ }
74
+ async sendRoleRequest(method, accountId, body, additionalQueryParams = {}) {
75
+ try {
76
+ return await this.httpClient.fetch({
77
+ url: {
78
+ appName: constants.APP_NAME,
79
+ path: API_PATH.replace('{accountId}', accountId.toString()),
80
+ },
81
+ query: {
82
+ style: STYLE,
83
+ ...additionalQueryParams,
84
+ },
85
+ method,
86
+ headers: {
87
+ 'Content-Type': 'application/json',
88
+ ...this.attributionHeaders,
89
+ },
90
+ body: body ? body : undefined,
91
+ }, this.fetchOptions);
92
+ }
93
+ catch (err) {
94
+ if (err instanceof mondayFetchApi.HttpFetcherError) {
95
+ throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('sendRoleRequest', err.status, err.message));
96
+ }
97
+ throw err;
98
+ }
99
+ }
100
+ }
101
+
102
+ exports.CustomRoles = CustomRoles;
@@ -0,0 +1,29 @@
1
+ export interface CustomRole {
2
+ id?: number;
3
+ name: string;
4
+ resourceType: string;
5
+ resourceId: number;
6
+ basicRoleId: number;
7
+ basicRoleType: RoleType;
8
+ }
9
+ export interface BasicRole {
10
+ id: number;
11
+ resourceType: string;
12
+ roleType: string;
13
+ name: string;
14
+ }
15
+ export interface RolesResponse {
16
+ customRoles: CustomRole[];
17
+ basicRoles?: BasicRole[];
18
+ }
19
+ export declare enum RoleType {
20
+ CUSTOM = "custom_role",
21
+ BASIC = "basic_role"
22
+ }
23
+ export interface RoleUpdate {
24
+ id: number;
25
+ updatedAttributes: {
26
+ name: string;
27
+ };
28
+ }
29
+ //# sourceMappingURL=roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.d.ts","sourceRoot":"","sources":["../../src/types/roles.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,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,CAAA;CAC1B;AAED,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC1B,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,oBAAY,QAAQ;IAChB,MAAM,gBAAgB;IACtB,KAAK,eAAe;CACvB;AAED,MAAM,WAAW,UAAU;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,iBAAiB,EAAE;QACf,IAAI,EAAE,MAAM,CAAC;KAChB,CAAA;CACJ"}
@@ -0,0 +1,7 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ exports.RoleType = void 0;
4
+ (function (RoleType) {
5
+ RoleType["CUSTOM"] = "custom_role";
6
+ RoleType["BASIC"] = "basic_role";
7
+ })(exports.RoleType || (exports.RoleType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mondaydotcomorg/monday-authorization",
3
- "version": "2.1.1-feature-bashanye-remove-authorization-url-secret-usage.04a9d3c",
3
+ "version": "3.0.0-feature-bashanye-create-custom-roles-sdk.9c70903",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "BSD-3-Clause",