@mondaydotcomorg/monday-authorization 3.5.0-feat-shaime-support-entity-attributes-in-authorization-sdk-a98616f → 3.5.0-feat-shaime-support-entity-attributes-in-authorization-sdk-8d846f1
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/dist/authorization-attributes-ms-service.d.ts +17 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -1
- package/dist/authorization-attributes-ms-service.js +165 -0
- package/dist/authorization-attributes-service.d.ts +52 -66
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +105 -353
- package/dist/constants/sns.d.ts +2 -0
- package/dist/constants/sns.d.ts.map +1 -1
- package/dist/constants/sns.js +4 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts +17 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-ms-service.mjs +165 -0
- package/dist/esm/authorization-attributes-service.d.ts +52 -66
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +107 -355
- package/dist/esm/constants/sns.d.ts +2 -0
- package/dist/esm/constants/sns.d.ts.map +1 -1
- package/dist/esm/constants/sns.mjs +3 -1
- package/dist/esm/types/authorization-attributes-contracts.d.ts +16 -0
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.mjs +6 -1
- package/dist/types/authorization-attributes-contracts.d.ts +16 -0
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.js +5 -0
- package/package.json +1 -1
- package/src/authorization-attributes-ms-service.ts +246 -0
- package/src/authorization-attributes-service.ts +147 -426
- package/src/constants/sns.ts +2 -0
- package/src/types/authorization-attributes-contracts.ts +20 -0
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
3
|
const chunk = require('lodash/chunk.js');
|
|
4
|
-
const tridentBackendApi = require('@mondaydotcomorg/trident-backend-api');
|
|
5
4
|
const mondaySns = require('@mondaydotcomorg/monday-sns');
|
|
6
|
-
const
|
|
5
|
+
const types_authorizationAttributesContracts = require('./types/authorization-attributes-contracts.js');
|
|
7
6
|
const authorizationInternalService = require('./authorization-internal-service.js');
|
|
8
|
-
const attributionsService = require('./attributions-service.js');
|
|
9
7
|
const constants_sns = require('./constants/sns.js');
|
|
10
|
-
const constants = require('./constants.js');
|
|
11
8
|
|
|
12
9
|
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
13
10
|
|
|
@@ -15,104 +12,83 @@ const chunk__default = /*#__PURE__*/_interopDefault(chunk);
|
|
|
15
12
|
|
|
16
13
|
class AuthorizationAttributesService {
|
|
17
14
|
static LOG_TAG = 'authorization_attributes';
|
|
18
|
-
static API_PATHS = {
|
|
19
|
-
UPSERT_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource',
|
|
20
|
-
DELETE_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource/{resourceType}/{resourceId}',
|
|
21
|
-
UPSERT_ENTITY_ATTRIBUTES: '/attributes/{accountId}/entity',
|
|
22
|
-
DELETE_ENTITY_ATTRIBUTES: '/attributes/{accountId}/entity/{entityType}/{entityId}',
|
|
23
|
-
};
|
|
24
|
-
httpClient;
|
|
25
|
-
fetchOptions;
|
|
26
15
|
snsArn;
|
|
27
16
|
/**
|
|
28
17
|
* Public constructor to create the AuthorizationAttributesService instance.
|
|
29
|
-
* @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
|
|
30
|
-
* @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
|
|
31
18
|
*/
|
|
32
|
-
constructor(
|
|
33
|
-
if (!httpClient) {
|
|
34
|
-
httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
35
|
-
if (!httpClient) {
|
|
36
|
-
throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (!fetchOptions) {
|
|
40
|
-
fetchOptions = constants.DEFAULT_FETCH_OPTIONS;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
fetchOptions = {
|
|
44
|
-
...constants.DEFAULT_FETCH_OPTIONS,
|
|
45
|
-
...fetchOptions,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
this.httpClient = httpClient;
|
|
49
|
-
this.fetchOptions = fetchOptions;
|
|
19
|
+
constructor() {
|
|
50
20
|
this.snsArn = AuthorizationAttributesService.getSnsTopicArn();
|
|
51
21
|
}
|
|
52
22
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @param
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
23
|
+
* Async function to upsert resource attributes using SNS.
|
|
24
|
+
* Sends the updates request to SNS and returns before the change actually took place.
|
|
25
|
+
* @param accountId The account ID
|
|
26
|
+
* @param appName App name of the calling app
|
|
27
|
+
* @param callerActionIdentifier Action identifier
|
|
28
|
+
* @param resourceAttributeAssignments Array of resource attribute assignments to upsert
|
|
29
|
+
* @return Promise with array of sent operations
|
|
58
30
|
*/
|
|
59
|
-
async
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
path: AuthorizationAttributesService.API_PATHS.UPSERT_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString()),
|
|
66
|
-
},
|
|
67
|
-
method: 'POST',
|
|
68
|
-
headers: {
|
|
69
|
-
'Content-Type': 'application/json',
|
|
70
|
-
...attributionHeaders,
|
|
71
|
-
},
|
|
72
|
-
body: JSON.stringify({ resourceAttributeAssignments }),
|
|
73
|
-
}, this.fetchOptions);
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
if (err instanceof mondayFetchApi.HttpFetcherError) {
|
|
77
|
-
throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('upsertResourceAttributes', err.status, err.message));
|
|
78
|
-
}
|
|
79
|
-
throw err;
|
|
80
|
-
}
|
|
31
|
+
async upsertResourceAttributesAsync(accountId, appName, callerActionIdentifier, resourceAttributeAssignments) {
|
|
32
|
+
const operations = resourceAttributeAssignments.map(assignment => ({
|
|
33
|
+
...assignment,
|
|
34
|
+
operationType: types_authorizationAttributesContracts.ResourceAttributeOperationEnum.UPSERT,
|
|
35
|
+
}));
|
|
36
|
+
return this.updateResourceAttributesAsync(accountId, appName, callerActionIdentifier, operations);
|
|
81
37
|
}
|
|
82
38
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
87
|
-
* @
|
|
39
|
+
* Async function to delete resource attributes using SNS.
|
|
40
|
+
* Sends the updates request to SNS and returns before the change actually took place.
|
|
41
|
+
* @param accountId The account ID
|
|
42
|
+
* @param appName App name of the calling app
|
|
43
|
+
* @param callerActionIdentifier Action identifier
|
|
44
|
+
* @param resource The resource (resourceType, resourceId)
|
|
45
|
+
* @param attributeKeys Array of attribute keys to delete
|
|
46
|
+
* @return Promise with array of sent operations
|
|
88
47
|
*/
|
|
89
|
-
async
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
48
|
+
async deleteResourceAttributesAsync(accountId, appName, callerActionIdentifier, resource, attributeKeys) {
|
|
49
|
+
const operations = attributeKeys.map(key => ({
|
|
50
|
+
resourceType: resource.type,
|
|
51
|
+
resourceId: resource.id,
|
|
52
|
+
key,
|
|
53
|
+
operationType: types_authorizationAttributesContracts.ResourceAttributeOperationEnum.DELETE,
|
|
54
|
+
}));
|
|
55
|
+
return this.updateResourceAttributesAsync(accountId, appName, callerActionIdentifier, operations);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Async function to upsert entity attributes using SNS.
|
|
59
|
+
* Sends the updates request to SNS and returns before the change actually took place.
|
|
60
|
+
* @param accountId The account ID
|
|
61
|
+
* @param appName App name of the calling app
|
|
62
|
+
* @param callerActionIdentifier Action identifier
|
|
63
|
+
* @param entityAttributeAssignments Array of entity attribute assignments to upsert
|
|
64
|
+
* @return Promise with array of sent operations
|
|
65
|
+
*/
|
|
66
|
+
async upsertEntityAttributesAsync(accountId, appName, callerActionIdentifier, entityAttributeAssignments) {
|
|
67
|
+
const operations = entityAttributeAssignments.map(assignment => ({
|
|
68
|
+
...assignment,
|
|
69
|
+
operationType: types_authorizationAttributesContracts.EntityAttributeOperationEnum.UPSERT,
|
|
70
|
+
}));
|
|
71
|
+
return this.updateEntityAttributesAsync(accountId, appName, callerActionIdentifier, operations);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Async function to delete entity attributes using SNS.
|
|
75
|
+
* Sends the updates request to SNS and returns before the change actually took place.
|
|
76
|
+
* @param accountId The account ID
|
|
77
|
+
* @param appName App name of the calling app
|
|
78
|
+
* @param callerActionIdentifier Action identifier
|
|
79
|
+
* @param entityType The entity type
|
|
80
|
+
* @param entityId The entity ID
|
|
81
|
+
* @param attributeKeys Array of attribute keys to delete
|
|
82
|
+
* @return Promise with array of sent operations
|
|
83
|
+
*/
|
|
84
|
+
async deleteEntityAttributesAsync(accountId, appName, callerActionIdentifier, entityType, entityId, attributeKeys) {
|
|
85
|
+
const operations = attributeKeys.map(key => ({
|
|
86
|
+
entityType: entityType,
|
|
87
|
+
entityId,
|
|
88
|
+
key,
|
|
89
|
+
operationType: types_authorizationAttributesContracts.EntityAttributeOperationEnum.DELETE,
|
|
90
|
+
}));
|
|
91
|
+
return this.updateEntityAttributesAsync(accountId, appName, callerActionIdentifier, operations);
|
|
116
92
|
}
|
|
117
93
|
/**
|
|
118
94
|
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
@@ -127,11 +103,28 @@ class AuthorizationAttributesService {
|
|
|
127
103
|
const sendToSnsPromises = [];
|
|
128
104
|
const operationChucks = chunk__default.default(resourceAttributeOperations, constants_sns.ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
|
|
129
105
|
for (const operationsChunk of operationChucks) {
|
|
130
|
-
sendToSnsPromises.push(this.
|
|
106
|
+
sendToSnsPromises.push(this.sendSingleResourceSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk));
|
|
107
|
+
}
|
|
108
|
+
return (await Promise.all(sendToSnsPromises)).flat();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
112
|
+
* @param accountId
|
|
113
|
+
* @param appName - App name of the calling app
|
|
114
|
+
* @param callerActionIdentifier - action identifier
|
|
115
|
+
* @param entityAttributeOperations - Array of operations to do on entity attributes.
|
|
116
|
+
* @return {Promise<EntityAttributesOperation[]>} Array of sent operations
|
|
117
|
+
* */
|
|
118
|
+
async updateEntityAttributesAsync(accountId, appName, callerActionIdentifier, entityAttributeOperations) {
|
|
119
|
+
const topicArn = this.snsArn;
|
|
120
|
+
const sendToSnsPromises = [];
|
|
121
|
+
const operationChucks = chunk__default.default(entityAttributeOperations, constants_sns.ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
|
|
122
|
+
for (const operationsChunk of operationChucks) {
|
|
123
|
+
sendToSnsPromises.push(this.sendSingleEntitySnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk));
|
|
131
124
|
}
|
|
132
125
|
return (await Promise.all(sendToSnsPromises)).flat();
|
|
133
126
|
}
|
|
134
|
-
async
|
|
127
|
+
async sendSingleResourceSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations) {
|
|
135
128
|
const payload = {
|
|
136
129
|
kind: constants_sns.RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
137
130
|
payload: {
|
|
@@ -150,6 +143,25 @@ class AuthorizationAttributesService {
|
|
|
150
143
|
return [];
|
|
151
144
|
}
|
|
152
145
|
}
|
|
146
|
+
async sendSingleEntitySnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations) {
|
|
147
|
+
const payload = {
|
|
148
|
+
kind: constants_sns.ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
149
|
+
payload: {
|
|
150
|
+
accountId: accountId,
|
|
151
|
+
callerAppName: appName,
|
|
152
|
+
callerActionIdentifier: callerActionIdentifier,
|
|
153
|
+
operations: operations,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
try {
|
|
157
|
+
await mondaySns.sendToSns(payload, topicArn);
|
|
158
|
+
return operations;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesService.LOG_TAG }, 'Authorization entity attributes async update: failed to send operations to SNS');
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
153
165
|
static getSnsTopicArn() {
|
|
154
166
|
const arnFromEnv = process.env[constants_sns.SNS_ARN_ENV_VAR_NAME];
|
|
155
167
|
if (arnFromEnv) {
|
|
@@ -183,266 +195,6 @@ class AuthorizationAttributesService {
|
|
|
183
195
|
return false;
|
|
184
196
|
}
|
|
185
197
|
}
|
|
186
|
-
/**
|
|
187
|
-
* Validates resource attribute assignments array
|
|
188
|
-
*/
|
|
189
|
-
static validateResourceAttributeAssignments(assignments) {
|
|
190
|
-
if (!Array.isArray(assignments)) {
|
|
191
|
-
throw new Error('resourceAttributeAssignments must be an array');
|
|
192
|
-
}
|
|
193
|
-
if (assignments.length === 0) {
|
|
194
|
-
throw new Error('resourceAttributeAssignments must contain at least 1 item');
|
|
195
|
-
}
|
|
196
|
-
if (assignments.length > 100) {
|
|
197
|
-
throw new Error('resourceAttributeAssignments must contain at most 100 items');
|
|
198
|
-
}
|
|
199
|
-
for (let i = 0; i < assignments.length; i++) {
|
|
200
|
-
const assignment = assignments[i];
|
|
201
|
-
if (!assignment.resourceId || typeof assignment.resourceId !== 'number') {
|
|
202
|
-
throw new Error(`resourceAttributeAssignments[${i}].resourceId is required and must be a number`);
|
|
203
|
-
}
|
|
204
|
-
if (!assignment.resourceType || typeof assignment.resourceType !== 'string') {
|
|
205
|
-
throw new Error(`resourceAttributeAssignments[${i}].resourceType is required and must be a string`);
|
|
206
|
-
}
|
|
207
|
-
if (!assignment.key || typeof assignment.key !== 'string') {
|
|
208
|
-
throw new Error(`resourceAttributeAssignments[${i}].key is required and must be a string`);
|
|
209
|
-
}
|
|
210
|
-
if (assignment.value === undefined || typeof assignment.value !== 'string') {
|
|
211
|
-
throw new Error(`resourceAttributeAssignments[${i}].value is required and must be a string`);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Validates entity attribute assignments array
|
|
217
|
-
*/
|
|
218
|
-
static validateEntityAttributeAssignments(assignments) {
|
|
219
|
-
if (!Array.isArray(assignments)) {
|
|
220
|
-
throw new Error('entityAttributeAssignments must be an array');
|
|
221
|
-
}
|
|
222
|
-
if (assignments.length === 0) {
|
|
223
|
-
throw new Error('entityAttributeAssignments must contain at least 1 item');
|
|
224
|
-
}
|
|
225
|
-
if (assignments.length > 100) {
|
|
226
|
-
throw new Error('entityAttributeAssignments must contain at most 100 items');
|
|
227
|
-
}
|
|
228
|
-
for (let i = 0; i < assignments.length; i++) {
|
|
229
|
-
const assignment = assignments[i];
|
|
230
|
-
if (!assignment.entityId || typeof assignment.entityId !== 'number') {
|
|
231
|
-
throw new Error(`entityAttributeAssignments[${i}].entityId is required and must be a number`);
|
|
232
|
-
}
|
|
233
|
-
if (!assignment.entityType || typeof assignment.entityType !== 'string') {
|
|
234
|
-
throw new Error(`entityAttributeAssignments[${i}].entityType is required and must be a string`);
|
|
235
|
-
}
|
|
236
|
-
if (!assignment.key || typeof assignment.key !== 'string') {
|
|
237
|
-
throw new Error(`entityAttributeAssignments[${i}].key is required and must be a string`);
|
|
238
|
-
}
|
|
239
|
-
if (assignment.value === undefined || typeof assignment.value !== 'string') {
|
|
240
|
-
throw new Error(`entityAttributeAssignments[${i}].value is required and must be a string`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Upsert resource attributes synchronously.
|
|
246
|
-
* Matches API endpoint: POST /attributes/:accountId/resource
|
|
247
|
-
* @param accountId The account ID
|
|
248
|
-
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects (1-100 items)
|
|
249
|
-
* @returns Promise with response containing affected attributes
|
|
250
|
-
*/
|
|
251
|
-
static async upsertResourceAttributesSync(accountId, resourceAttributeAssignments) {
|
|
252
|
-
// Validate inputs
|
|
253
|
-
if (!Number.isInteger(accountId)) {
|
|
254
|
-
throw new Error(`accountId must be an integer, got: ${accountId}`);
|
|
255
|
-
}
|
|
256
|
-
AuthorizationAttributesService.validateResourceAttributeAssignments(resourceAttributeAssignments);
|
|
257
|
-
const httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
258
|
-
if (!httpClient) {
|
|
259
|
-
throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
260
|
-
}
|
|
261
|
-
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
262
|
-
const path = AuthorizationAttributesService.API_PATHS.UPSERT_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString());
|
|
263
|
-
try {
|
|
264
|
-
return await httpClient.fetch({
|
|
265
|
-
url: {
|
|
266
|
-
appName: constants.APP_NAME,
|
|
267
|
-
path,
|
|
268
|
-
},
|
|
269
|
-
method: 'POST',
|
|
270
|
-
headers: {
|
|
271
|
-
'Content-Type': 'application/json',
|
|
272
|
-
...attributionHeaders,
|
|
273
|
-
},
|
|
274
|
-
body: JSON.stringify({ resourceAttributeAssignments }),
|
|
275
|
-
}, {
|
|
276
|
-
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
277
|
-
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
catch (err) {
|
|
281
|
-
if (err instanceof mondayFetchApi.HttpFetcherError) {
|
|
282
|
-
throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('upsertResourceAttributesSync', err.status, err.message));
|
|
283
|
-
}
|
|
284
|
-
throw err;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Delete resource attributes synchronously.
|
|
289
|
-
* Matches API endpoint: DELETE /attributes/:accountId/resource/:resourceType/:resourceId
|
|
290
|
-
* @param accountId The account ID
|
|
291
|
-
* @param resourceType The resource type
|
|
292
|
-
* @param resourceId The resource ID
|
|
293
|
-
* @param keys Array of attribute keys to delete
|
|
294
|
-
* @returns Promise with response containing affected attributes
|
|
295
|
-
*/
|
|
296
|
-
static async deleteResourceAttributesSync(accountId, resourceType, resourceId, keys) {
|
|
297
|
-
// Validate inputs
|
|
298
|
-
if (!Number.isInteger(accountId)) {
|
|
299
|
-
throw new Error(`accountId must be an integer, got: ${accountId}`);
|
|
300
|
-
}
|
|
301
|
-
if (!resourceType || typeof resourceType !== 'string') {
|
|
302
|
-
throw new Error(`resourceType must be a string, got: ${typeof resourceType}`);
|
|
303
|
-
}
|
|
304
|
-
if (!Number.isInteger(resourceId)) {
|
|
305
|
-
throw new Error(`resourceId must be an integer, got: ${resourceId}`);
|
|
306
|
-
}
|
|
307
|
-
if (!Array.isArray(keys)) {
|
|
308
|
-
throw new Error('keys must be an array');
|
|
309
|
-
}
|
|
310
|
-
if (keys.length === 0) {
|
|
311
|
-
throw new Error('keys must contain at least 1 item');
|
|
312
|
-
}
|
|
313
|
-
const httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
314
|
-
if (!httpClient) {
|
|
315
|
-
throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
316
|
-
}
|
|
317
|
-
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
318
|
-
const path = AuthorizationAttributesService.API_PATHS.DELETE_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString())
|
|
319
|
-
.replace('{resourceType}', resourceType)
|
|
320
|
-
.replace('{resourceId}', resourceId.toString());
|
|
321
|
-
try {
|
|
322
|
-
return await httpClient.fetch({
|
|
323
|
-
url: {
|
|
324
|
-
appName: constants.APP_NAME,
|
|
325
|
-
path,
|
|
326
|
-
},
|
|
327
|
-
method: 'DELETE',
|
|
328
|
-
headers: {
|
|
329
|
-
'Content-Type': 'application/json',
|
|
330
|
-
...attributionHeaders,
|
|
331
|
-
},
|
|
332
|
-
body: JSON.stringify({ keys }),
|
|
333
|
-
}, {
|
|
334
|
-
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
335
|
-
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
catch (err) {
|
|
339
|
-
if (err instanceof mondayFetchApi.HttpFetcherError) {
|
|
340
|
-
throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('deleteResourceAttributesSync', err.status, err.message));
|
|
341
|
-
}
|
|
342
|
-
throw err;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Upsert entity attributes synchronously.
|
|
347
|
-
* Matches API endpoint: POST /attributes/:accountId/entity
|
|
348
|
-
* @param accountId The account ID
|
|
349
|
-
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects (1-100 items)
|
|
350
|
-
* @returns Promise with response containing affected attributes
|
|
351
|
-
*/
|
|
352
|
-
static async upsertEntityAttributesSync(accountId, entityAttributeAssignments) {
|
|
353
|
-
// Validate inputs
|
|
354
|
-
if (!Number.isInteger(accountId)) {
|
|
355
|
-
throw new Error(`accountId must be an integer, got: ${accountId}`);
|
|
356
|
-
}
|
|
357
|
-
AuthorizationAttributesService.validateEntityAttributeAssignments(entityAttributeAssignments);
|
|
358
|
-
const httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
359
|
-
if (!httpClient) {
|
|
360
|
-
throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
361
|
-
}
|
|
362
|
-
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
363
|
-
const path = AuthorizationAttributesService.API_PATHS.UPSERT_ENTITY_ATTRIBUTES.replace('{accountId}', accountId.toString());
|
|
364
|
-
try {
|
|
365
|
-
return await httpClient.fetch({
|
|
366
|
-
url: {
|
|
367
|
-
appName: constants.APP_NAME,
|
|
368
|
-
path,
|
|
369
|
-
},
|
|
370
|
-
method: 'POST',
|
|
371
|
-
headers: {
|
|
372
|
-
'Content-Type': 'application/json',
|
|
373
|
-
...attributionHeaders,
|
|
374
|
-
},
|
|
375
|
-
body: JSON.stringify({ entityAttributeAssignments }),
|
|
376
|
-
}, {
|
|
377
|
-
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
378
|
-
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
catch (err) {
|
|
382
|
-
if (err instanceof mondayFetchApi.HttpFetcherError) {
|
|
383
|
-
throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('upsertEntityAttributesSync', err.status, err.message));
|
|
384
|
-
}
|
|
385
|
-
throw err;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Delete entity attributes synchronously.
|
|
390
|
-
* Matches API endpoint: DELETE /attributes/:accountId/entity/:entityType/:entityId
|
|
391
|
-
* @param accountId The account ID
|
|
392
|
-
* @param entityType The entity type
|
|
393
|
-
* @param entityId The entity ID
|
|
394
|
-
* @param keys Array of attribute keys to delete
|
|
395
|
-
* @returns Promise with response containing affected attributes
|
|
396
|
-
*/
|
|
397
|
-
static async deleteEntityAttributesSync(accountId, entityType, entityId, keys) {
|
|
398
|
-
// Validate inputs
|
|
399
|
-
if (!Number.isInteger(accountId)) {
|
|
400
|
-
throw new Error(`accountId must be an integer, got: ${accountId}`);
|
|
401
|
-
}
|
|
402
|
-
if (!entityType || typeof entityType !== 'string') {
|
|
403
|
-
throw new Error(`entityType must be a string, got: ${typeof entityType}`);
|
|
404
|
-
}
|
|
405
|
-
if (!Number.isInteger(entityId)) {
|
|
406
|
-
throw new Error(`entityId must be an integer, got: ${entityId}`);
|
|
407
|
-
}
|
|
408
|
-
if (!Array.isArray(keys)) {
|
|
409
|
-
throw new Error('keys must be an array');
|
|
410
|
-
}
|
|
411
|
-
if (keys.length === 0) {
|
|
412
|
-
throw new Error('keys must contain at least 1 item');
|
|
413
|
-
}
|
|
414
|
-
const httpClient = tridentBackendApi.Api.getPart('httpClient');
|
|
415
|
-
if (!httpClient) {
|
|
416
|
-
throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
|
|
417
|
-
}
|
|
418
|
-
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
419
|
-
const path = AuthorizationAttributesService.API_PATHS.DELETE_ENTITY_ATTRIBUTES.replace('{accountId}', accountId.toString())
|
|
420
|
-
.replace('{entityType}', entityType)
|
|
421
|
-
.replace('{entityId}', entityId.toString());
|
|
422
|
-
try {
|
|
423
|
-
return await httpClient.fetch({
|
|
424
|
-
url: {
|
|
425
|
-
appName: constants.APP_NAME,
|
|
426
|
-
path,
|
|
427
|
-
},
|
|
428
|
-
method: 'DELETE',
|
|
429
|
-
headers: {
|
|
430
|
-
'Content-Type': 'application/json',
|
|
431
|
-
...attributionHeaders,
|
|
432
|
-
},
|
|
433
|
-
body: JSON.stringify({ keys }),
|
|
434
|
-
}, {
|
|
435
|
-
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
436
|
-
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
catch (err) {
|
|
440
|
-
if (err instanceof mondayFetchApi.HttpFetcherError) {
|
|
441
|
-
throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('deleteEntityAttributesSync', err.status, err.message));
|
|
442
|
-
}
|
|
443
|
-
throw err;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
198
|
}
|
|
447
199
|
|
|
448
200
|
exports.AuthorizationAttributesService = AuthorizationAttributesService;
|
package/dist/constants/sns.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const SNS_ARN_ENV_VAR_NAME = "SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES";
|
|
2
2
|
export declare const SNS_DEV_TEST_NAME = "arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local";
|
|
3
3
|
export declare const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = "resourceAttributeModification";
|
|
4
|
+
export declare const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = "entityAttributeModification";
|
|
4
5
|
export declare const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
6
|
+
export declare const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
5
7
|
//# sourceMappingURL=sns.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sns.d.ts","sourceRoot":"","sources":["../../src/constants/sns.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,0DAA0D,CAAC;AAC5F,eAAO,MAAM,iBAAiB,0FAC2D,CAAC;AAC1F,eAAO,MAAM,qDAAqD,kCAAkC,CAAC;AACrG,eAAO,MAAM,oDAAoD,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"sns.d.ts","sourceRoot":"","sources":["../../src/constants/sns.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,0DAA0D,CAAC;AAC5F,eAAO,MAAM,iBAAiB,0FAC2D,CAAC;AAC1F,eAAO,MAAM,qDAAqD,kCAAkC,CAAC;AACrG,eAAO,MAAM,mDAAmD,gCAAgC,CAAC;AACjG,eAAO,MAAM,oDAAoD,MAAM,CAAC;AACxE,eAAO,MAAM,kDAAkD,MAAM,CAAC"}
|
package/dist/constants/sns.js
CHANGED
|
@@ -3,9 +3,13 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
3
3
|
const SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES';
|
|
4
4
|
const SNS_DEV_TEST_NAME = 'arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local';
|
|
5
5
|
const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'resourceAttributeModification';
|
|
6
|
+
const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'entityAttributeModification';
|
|
6
7
|
const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
8
|
+
const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
7
9
|
|
|
10
|
+
exports.ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE;
|
|
8
11
|
exports.ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE;
|
|
12
|
+
exports.ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND;
|
|
9
13
|
exports.RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND;
|
|
10
14
|
exports.SNS_ARN_ENV_VAR_NAME = SNS_ARN_ENV_VAR_NAME;
|
|
11
15
|
exports.SNS_DEV_TEST_NAME = SNS_DEV_TEST_NAME;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
2
|
+
import { EntityAttributeAssignment, EntityType, EntityAttributeKeyType } from './types/authorization-attributes-contracts';
|
|
2
3
|
interface Resource {
|
|
3
4
|
resourceType: string;
|
|
4
5
|
resourceId: number;
|
|
@@ -32,6 +33,22 @@ export declare class AuthorizationAttributesMsService {
|
|
|
32
33
|
* @returns Promise<void>
|
|
33
34
|
*/
|
|
34
35
|
static deleteResourceAttributesSync(accountId: number, resource: Resource, attributeKeys: string[]): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates or updates entity attributes synchronously.
|
|
38
|
+
* @param accountId The account ID
|
|
39
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
40
|
+
* @returns Promise<void>
|
|
41
|
+
*/
|
|
42
|
+
static upsertEntityAttributesSync(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[]): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Deletes specific attributes from an entity synchronously.
|
|
45
|
+
* @param accountId The account ID
|
|
46
|
+
* @param entityType The entity type
|
|
47
|
+
* @param entityId The entity ID
|
|
48
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
49
|
+
* @returns Promise<void>
|
|
50
|
+
*/
|
|
51
|
+
static deleteEntityAttributesSync(accountId: number, entityType: EntityType, entityId: number, attributeKeys: EntityAttributeKeyType[]): Promise<void>;
|
|
35
52
|
}
|
|
36
53
|
export {};
|
|
37
54
|
//# sourceMappingURL=authorization-attributes-ms-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-ms-service.d.ts","sourceRoot":"","sources":["../../src/authorization-attributes-ms-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"authorization-attributes-ms-service.d.ts","sourceRoot":"","sources":["../../src/authorization-attributes-ms-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EACL,yBAAyB,EACzB,UAAU,EACV,sBAAsB,EACvB,MAAM,4CAA4C,CAAC;AAYpD,UAAU,QAAQ;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAwBD;;;GAGG;AACH,qBAAa,gCAAgC;IAC3C,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IAEvD;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA+ChC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAmB/B;;;;;OAKG;WACU,4BAA4B,CACvC,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,GAC1D,OAAO,CAAC,IAAI,CAAC;IAwFhB;;;;;;OAMG;WACU,4BAA4B,CACvC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC;IAwGhB;;;;;OAKG;WACU,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,GACtD,OAAO,CAAC,IAAI,CAAC;IAwGhB;;;;;;;OAOG;WACU,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,sBAAsB,EAAE,GACtC,OAAO,CAAC,IAAI,CAAC;CAuGjB"}
|