@mondaydotcomorg/monday-authorization 3.5.0-feat-use-profile-for-graph-can-action-in-scope-f1451ab → 3.5.0-feat-shaime-support-entity-attributes-in-authorization-sdk-397ce54

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.
Files changed (60) hide show
  1. package/dist/authorization-attributes-ms-service.d.ts +37 -0
  2. package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
  3. package/dist/authorization-attributes-ms-service.js +232 -0
  4. package/dist/authorization-attributes-service.d.ts +45 -1
  5. package/dist/authorization-attributes-service.d.ts.map +1 -1
  6. package/dist/authorization-attributes-service.js +262 -0
  7. package/dist/clients/graph-api.d.ts.map +1 -1
  8. package/dist/clients/graph-api.js +0 -1
  9. package/dist/constants.d.ts +0 -3
  10. package/dist/constants.d.ts.map +1 -1
  11. package/dist/constants.js +0 -4
  12. package/dist/errors/argument-error.d.ts +4 -0
  13. package/dist/errors/argument-error.d.ts.map +1 -0
  14. package/dist/errors/argument-error.js +11 -0
  15. package/dist/esm/authorization-attributes-ms-service.d.ts +37 -0
  16. package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
  17. package/dist/esm/authorization-attributes-ms-service.mjs +230 -0
  18. package/dist/esm/authorization-attributes-service.d.ts +45 -1
  19. package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
  20. package/dist/esm/authorization-attributes-service.mjs +263 -1
  21. package/dist/esm/clients/graph-api.d.ts.map +1 -1
  22. package/dist/esm/clients/graph-api.mjs +1 -2
  23. package/dist/esm/constants.d.ts +0 -3
  24. package/dist/esm/constants.d.ts.map +1 -1
  25. package/dist/esm/constants.mjs +1 -5
  26. package/dist/esm/errors/argument-error.d.ts +4 -0
  27. package/dist/esm/errors/argument-error.d.ts.map +1 -0
  28. package/dist/esm/errors/argument-error.mjs +9 -0
  29. package/dist/esm/index.d.ts +5 -0
  30. package/dist/esm/index.d.ts.map +1 -1
  31. package/dist/esm/index.mjs +4 -0
  32. package/dist/esm/resource-attribute-assignment.d.ts +25 -0
  33. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
  34. package/dist/esm/resource-attribute-assignment.mjs +60 -0
  35. package/dist/esm/resource-attributes-constants.d.ts +25 -0
  36. package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
  37. package/dist/esm/resource-attributes-constants.mjs +25 -0
  38. package/dist/esm/types/authorization-attributes-contracts.d.ts +19 -3
  39. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  40. package/dist/index.d.ts +5 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +9 -0
  43. package/dist/resource-attribute-assignment.d.ts +25 -0
  44. package/dist/resource-attribute-assignment.d.ts.map +1 -0
  45. package/dist/resource-attribute-assignment.js +62 -0
  46. package/dist/resource-attributes-constants.d.ts +25 -0
  47. package/dist/resource-attributes-constants.d.ts.map +1 -0
  48. package/dist/resource-attributes-constants.js +28 -0
  49. package/dist/types/authorization-attributes-contracts.d.ts +19 -3
  50. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  51. package/package.json +1 -1
  52. package/src/authorization-attributes-ms-service.ts +327 -0
  53. package/src/authorization-attributes-service.ts +325 -0
  54. package/src/clients/graph-api.ts +1 -2
  55. package/src/constants.ts +0 -4
  56. package/src/errors/argument-error.ts +8 -0
  57. package/src/index.ts +16 -0
  58. package/src/resource-attribute-assignment.ts +70 -0
  59. package/src/resource-attributes-constants.ts +27 -0
  60. package/src/types/authorization-attributes-contracts.ts +49 -3
@@ -0,0 +1,327 @@
1
+ import { Api, HttpClient } from '@mondaydotcomorg/trident-backend-api';
2
+ import { signAuthorizationHeader } from '@mondaydotcomorg/monday-jwt';
3
+ import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
4
+ import { ResourceAttributeAssignment } from './resource-attribute-assignment';
5
+ import { ArgumentError } from './errors/argument-error';
6
+ import { logger } from './authorization-internal-service';
7
+ import { getAttributionsFromApi } from './attributions-service';
8
+ import { AuthorizationInternalService } from './authorization-internal-service';
9
+ import { APP_NAME } from './constants';
10
+
11
+ const INTERNAL_APP_NAME = 'internal_ms';
12
+ const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
13
+ const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
14
+
15
+ interface Resource {
16
+ resourceType: string;
17
+ resourceId: number;
18
+ }
19
+
20
+ interface UpsertRequestBody {
21
+ resourceAttributeAssignments: Array<{
22
+ resourceId: number;
23
+ resourceType: string;
24
+ key: string;
25
+ value: string;
26
+ }>;
27
+ }
28
+
29
+ interface DeleteRequestBody {
30
+ keys: string[];
31
+ }
32
+
33
+ /**
34
+ * Service class for managing resource attributes in the authorization microservice.
35
+ * Provides synchronous HTTP operations to create/update and delete attributes on resources.
36
+ */
37
+ export class AuthorizationAttributesMsService {
38
+ private static LOG_TAG = 'authorization_attributes_ms';
39
+
40
+ /**
41
+ * Gets request headers including Authorization, Content-Type, and optional attribution headers
42
+ */
43
+ private static getRequestHeaders(accountId: number, userId?: number): Record<string, string> {
44
+ const headers: Record<string, string> = {
45
+ 'Content-Type': 'application/json',
46
+ };
47
+
48
+ // Generate Authorization token
49
+ const authToken = signAuthorizationHeader({
50
+ appName: INTERNAL_APP_NAME,
51
+ accountId,
52
+ userId,
53
+ });
54
+ headers.Authorization = authToken;
55
+
56
+ // Add attribution headers if available
57
+ const attributionHeaders = getAttributionsFromApi();
58
+ for (const key in attributionHeaders) {
59
+ if (attributionHeaders.hasOwnProperty(key)) {
60
+ headers[key] = attributionHeaders[key];
61
+ }
62
+ }
63
+
64
+ // Add X-REQUEST-ID if available from context
65
+ try {
66
+ const tridentContext = Api.getPart('context');
67
+ if (tridentContext?.runtimeAttributions) {
68
+ const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
69
+ if (outgoingHeaders) {
70
+ const attributionHeadersMap: Record<string, string> = {};
71
+ for (const [key, value] of outgoingHeaders) {
72
+ attributionHeadersMap[key] = value;
73
+ }
74
+ if (attributionHeadersMap['x-request-id']) {
75
+ headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
76
+ }
77
+ }
78
+ }
79
+ } catch (error) {
80
+ // Silently fail if context is not available
81
+ logger.debug({ tag: this.LOG_TAG, error }, 'Failed to get request ID from context');
82
+ }
83
+
84
+ // Add X-REQUEST-START timestamp
85
+ headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
86
+
87
+ return headers;
88
+ }
89
+
90
+ /**
91
+ * Validates that all messages are instances of the specified message class
92
+ */
93
+ private static validateMessages<T>(
94
+ attributesMessages: T[],
95
+ messageClass: new (...args: any[]) => T
96
+ ): void {
97
+ if (typeof messageClass !== 'function') {
98
+ throw new ArgumentError('messageClass must be a class/constructor function');
99
+ }
100
+
101
+ if (!Array.isArray(attributesMessages)) {
102
+ throw new ArgumentError('attributesMessages must be an array');
103
+ }
104
+
105
+ for (let i = 0; i < attributesMessages.length; i++) {
106
+ if (!(attributesMessages[i] instanceof messageClass)) {
107
+ const className = (messageClass as any).name || 'ResourceAttributeAssignment';
108
+ throw new ArgumentError(
109
+ `All attributesMessages must be instances of ${className}, but item at index ${i} is not`
110
+ );
111
+ }
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Creates or updates resource attributes synchronously.
117
+ * @param accountId The account ID
118
+ * @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
119
+ * @returns Promise<void>
120
+ */
121
+ static async upsertResourceAttributesSync(
122
+ accountId: number,
123
+ resourceAttributeAssignments: ResourceAttributeAssignment[]
124
+ ): Promise<void> {
125
+ // Skip HTTP requests in test environment
126
+ if (process.env.NODE_ENV === 'test') {
127
+ logger.debug(
128
+ { tag: this.LOG_TAG, accountId, count: resourceAttributeAssignments.length },
129
+ 'Skipping upsertResourceAttributesSync in test environment'
130
+ );
131
+ return;
132
+ }
133
+
134
+ // Validate inputs
135
+ if (!Number.isInteger(accountId)) {
136
+ throw new ArgumentError(`accountId must be an integer, got: ${accountId}`);
137
+ }
138
+
139
+ if (!Array.isArray(resourceAttributeAssignments)) {
140
+ throw new ArgumentError('resourceAttributeAssignments must be an array');
141
+ }
142
+
143
+ if (resourceAttributeAssignments.length === 0) {
144
+ logger.warn({ tag: this.LOG_TAG, accountId }, 'upsertResourceAttributesSync called with empty array');
145
+ return;
146
+ }
147
+
148
+ // Validate all assignments are instances of ResourceAttributeAssignment
149
+ this.validateMessages(resourceAttributeAssignments, ResourceAttributeAssignment);
150
+
151
+ // Convert assignments to hash format
152
+ const assignmentsHash = resourceAttributeAssignments.map(assignment => assignment.toH());
153
+
154
+ // Build request body
155
+ const requestBody: UpsertRequestBody = {
156
+ resourceAttributeAssignments: assignmentsHash,
157
+ };
158
+
159
+ const httpClient = Api.getPart('httpClient');
160
+ if (!httpClient) {
161
+ throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
162
+ }
163
+ const path = UPSERT_RESOURCE_ATTRIBUTES_PATH.replace('{accountId}', accountId.toString());
164
+ const headers = this.getRequestHeaders(accountId);
165
+
166
+ try {
167
+ logger.info(
168
+ { tag: this.LOG_TAG, accountId, count: resourceAttributeAssignments.length },
169
+ 'Upserting resource attributes'
170
+ );
171
+
172
+ await httpClient.fetch(
173
+ {
174
+ url: {
175
+ appName: APP_NAME,
176
+ path,
177
+ },
178
+ method: 'POST',
179
+ headers,
180
+ body: JSON.stringify(requestBody),
181
+ },
182
+ {
183
+ timeout: AuthorizationInternalService.getRequestTimeout(),
184
+ retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
185
+ }
186
+ );
187
+
188
+ logger.info(
189
+ { tag: this.LOG_TAG, accountId, count: resourceAttributeAssignments.length },
190
+ 'Successfully upserted resource attributes'
191
+ );
192
+ } catch (err) {
193
+ logger.error(
194
+ {
195
+ tag: this.LOG_TAG,
196
+ accountId,
197
+ method: 'upsertResourceAttributesSync',
198
+ error: err instanceof Error ? err.message : String(err),
199
+ },
200
+ 'Failed to upsert resource attributes'
201
+ );
202
+
203
+ if (err instanceof HttpFetcherError) {
204
+ throw new Error(
205
+ `AuthorizationAttributesMsService: [upsertResourceAttributesSync] request failed with status ${err.status}: ${err.message}`
206
+ );
207
+ }
208
+ throw err;
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Deletes specific attributes from a resource synchronously.
214
+ * @param accountId The account ID
215
+ * @param resource Object with resourceType (string) and resourceId (number)
216
+ * @param attributeKeys Array of attribute key strings to delete
217
+ * @returns Promise<void>
218
+ */
219
+ static async deleteResourceAttributesSync(
220
+ accountId: number,
221
+ resource: Resource,
222
+ attributeKeys: string[]
223
+ ): Promise<void> {
224
+ // Skip HTTP requests in test environment
225
+ if (process.env.NODE_ENV === 'test') {
226
+ logger.debug(
227
+ { tag: this.LOG_TAG, accountId, resource, attributeKeys },
228
+ 'Skipping deleteResourceAttributesSync in test environment'
229
+ );
230
+ return;
231
+ }
232
+
233
+ // Validate inputs
234
+ if (!Number.isInteger(accountId)) {
235
+ throw new ArgumentError(`accountId must be an integer, got: ${accountId}`);
236
+ }
237
+
238
+ if (!resource || typeof resource !== 'object') {
239
+ throw new ArgumentError('resource must be an object');
240
+ }
241
+
242
+ if (!Number.isInteger(resource.resourceId)) {
243
+ throw new ArgumentError(`resource.resourceId must be an integer, got: ${resource.resourceId}`);
244
+ }
245
+
246
+ if (typeof resource.resourceType !== 'string') {
247
+ throw new ArgumentError(`resource.resourceType must be a string, got: ${typeof resource.resourceType}`);
248
+ }
249
+
250
+ if (!Array.isArray(attributeKeys)) {
251
+ throw new ArgumentError('attributeKeys must be an array');
252
+ }
253
+
254
+ if (attributeKeys.length === 0) {
255
+ logger.warn({ tag: this.LOG_TAG, accountId, resource }, 'deleteResourceAttributesSync called with empty keys array');
256
+ return;
257
+ }
258
+
259
+ // Validate all keys are strings
260
+ for (let i = 0; i < attributeKeys.length; i++) {
261
+ if (typeof attributeKeys[i] !== 'string') {
262
+ throw new ArgumentError(`All attributeKeys must be strings, but item at index ${i} is not`);
263
+ }
264
+ }
265
+
266
+ // Build request body
267
+ const requestBody: DeleteRequestBody = {
268
+ keys: attributeKeys,
269
+ };
270
+
271
+ const httpClient = Api.getPart('httpClient');
272
+ if (!httpClient) {
273
+ throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
274
+ }
275
+ const path = DELETE_RESOURCE_ATTRIBUTES_PATH.replace('{accountId}', accountId.toString())
276
+ .replace('{resourceType}', resource.resourceType)
277
+ .replace('{resourceId}', resource.resourceId.toString());
278
+ const headers = this.getRequestHeaders(accountId);
279
+
280
+ try {
281
+ logger.info(
282
+ { tag: this.LOG_TAG, accountId, resource, keys: attributeKeys },
283
+ 'Deleting resource attributes'
284
+ );
285
+
286
+ await httpClient.fetch(
287
+ {
288
+ url: {
289
+ appName: APP_NAME,
290
+ path,
291
+ },
292
+ method: 'DELETE',
293
+ headers,
294
+ body: JSON.stringify(requestBody),
295
+ },
296
+ {
297
+ timeout: AuthorizationInternalService.getRequestTimeout(),
298
+ retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
299
+ }
300
+ );
301
+
302
+ logger.info(
303
+ { tag: this.LOG_TAG, accountId, resource, keys: attributeKeys },
304
+ 'Successfully deleted resource attributes'
305
+ );
306
+ } catch (err) {
307
+ logger.error(
308
+ {
309
+ tag: this.LOG_TAG,
310
+ accountId,
311
+ method: 'deleteResourceAttributesSync',
312
+ resource,
313
+ error: err instanceof Error ? err.message : String(err),
314
+ },
315
+ 'Failed to delete resource attributes'
316
+ );
317
+
318
+ if (err instanceof HttpFetcherError) {
319
+ throw new Error(
320
+ `AuthorizationAttributesMsService: [deleteResourceAttributesSync] request failed with status ${err.status}: ${err.message}`
321
+ );
322
+ }
323
+ throw err;
324
+ }
325
+ }
326
+ }
327
+
@@ -6,7 +6,14 @@ import {
6
6
  ResourceAttributeAssignment,
7
7
  ResourceAttributeResponse,
8
8
  ResourceAttributesOperation,
9
+ EntityAttributeAssignment,
10
+ EntityAttributeResponse,
11
+ ResourceType,
12
+ EntityType,
13
+ ResourceAttributeKeyType,
14
+ EntityAttributeKeyType,
9
15
  } from './types/authorization-attributes-contracts';
16
+ import { AuthorizationInternalService } from './authorization-internal-service';
10
17
  import { Resource } from './types/general';
11
18
  import { logger } from './authorization-internal-service';
12
19
  import { getAttributionsFromApi } from './attributions-service';
@@ -24,6 +31,8 @@ export class AuthorizationAttributesService {
24
31
  private static API_PATHS = {
25
32
  UPSERT_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource',
26
33
  DELETE_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource/{resourceType}/{resourceId}',
34
+ UPSERT_ENTITY_ATTRIBUTES: '/attributes/{accountId}/entity',
35
+ DELETE_ENTITY_ATTRIBUTES: '/attributes/{accountId}/entity/{entityType}/{entityId}',
27
36
  } as const;
28
37
  private httpClient: HttpClient;
29
38
  private fetchOptions: RecursivePartial<FetcherConfig>;
@@ -231,4 +240,320 @@ export class AuthorizationAttributesService {
231
240
  return false;
232
241
  }
233
242
  }
243
+
244
+ /**
245
+ * Validates resource attribute assignments array
246
+ */
247
+ private static validateResourceAttributeAssignments(
248
+ assignments: ResourceAttributeAssignment[]
249
+ ): void {
250
+ if (!Array.isArray(assignments)) {
251
+ throw new Error('resourceAttributeAssignments must be an array');
252
+ }
253
+ if (assignments.length === 0) {
254
+ throw new Error('resourceAttributeAssignments must contain at least 1 item');
255
+ }
256
+ if (assignments.length > 100) {
257
+ throw new Error('resourceAttributeAssignments must contain at most 100 items');
258
+ }
259
+ for (let i = 0; i < assignments.length; i++) {
260
+ const assignment = assignments[i];
261
+ if (!assignment.resourceId || typeof assignment.resourceId !== 'number') {
262
+ throw new Error(`resourceAttributeAssignments[${i}].resourceId is required and must be a number`);
263
+ }
264
+ if (!assignment.resourceType || typeof assignment.resourceType !== 'string') {
265
+ throw new Error(`resourceAttributeAssignments[${i}].resourceType is required and must be a string`);
266
+ }
267
+ if (!assignment.key || typeof assignment.key !== 'string') {
268
+ throw new Error(`resourceAttributeAssignments[${i}].key is required and must be a string`);
269
+ }
270
+ if (assignment.value === undefined || typeof assignment.value !== 'string') {
271
+ throw new Error(`resourceAttributeAssignments[${i}].value is required and must be a string`);
272
+ }
273
+ }
274
+ }
275
+
276
+ /**
277
+ * Validates entity attribute assignments array
278
+ */
279
+ private static validateEntityAttributeAssignments(assignments: EntityAttributeAssignment[]): void {
280
+ if (!Array.isArray(assignments)) {
281
+ throw new Error('entityAttributeAssignments must be an array');
282
+ }
283
+ if (assignments.length === 0) {
284
+ throw new Error('entityAttributeAssignments must contain at least 1 item');
285
+ }
286
+ if (assignments.length > 100) {
287
+ throw new Error('entityAttributeAssignments must contain at most 100 items');
288
+ }
289
+ for (let i = 0; i < assignments.length; i++) {
290
+ const assignment = assignments[i];
291
+ if (!assignment.entityId || typeof assignment.entityId !== 'number') {
292
+ throw new Error(`entityAttributeAssignments[${i}].entityId is required and must be a number`);
293
+ }
294
+ if (!assignment.entityType || typeof assignment.entityType !== 'string') {
295
+ throw new Error(`entityAttributeAssignments[${i}].entityType is required and must be a string`);
296
+ }
297
+ if (!assignment.key || typeof assignment.key !== 'string') {
298
+ throw new Error(`entityAttributeAssignments[${i}].key is required and must be a string`);
299
+ }
300
+ if (assignment.value === undefined || typeof assignment.value !== 'string') {
301
+ throw new Error(`entityAttributeAssignments[${i}].value is required and must be a string`);
302
+ }
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Upsert resource attributes synchronously.
308
+ * Matches API endpoint: POST /attributes/:accountId/resource
309
+ * @param accountId The account ID
310
+ * @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects (1-100 items)
311
+ * @returns Promise with response containing affected attributes
312
+ */
313
+ static async upsertResourceAttributesSync(
314
+ accountId: number,
315
+ resourceAttributeAssignments: ResourceAttributeAssignment[]
316
+ ): Promise<ResourceAttributeResponse> {
317
+ // Validate inputs
318
+ if (!Number.isInteger(accountId)) {
319
+ throw new Error(`accountId must be an integer, got: ${accountId}`);
320
+ }
321
+ AuthorizationAttributesService.validateResourceAttributeAssignments(resourceAttributeAssignments);
322
+
323
+ const httpClient = Api.getPart('httpClient');
324
+ if (!httpClient) {
325
+ throw new Error(ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
326
+ }
327
+
328
+ const attributionHeaders = getAttributionsFromApi();
329
+ const path = AuthorizationAttributesService.API_PATHS.UPSERT_RESOURCE_ATTRIBUTES.replace(
330
+ '{accountId}',
331
+ accountId.toString()
332
+ );
333
+
334
+ try {
335
+ return await httpClient.fetch<ResourceAttributeResponse>(
336
+ {
337
+ url: {
338
+ appName: APP_NAME,
339
+ path,
340
+ },
341
+ method: 'POST',
342
+ headers: {
343
+ 'Content-Type': 'application/json',
344
+ ...attributionHeaders,
345
+ },
346
+ body: JSON.stringify({ resourceAttributeAssignments }),
347
+ },
348
+ {
349
+ timeout: AuthorizationInternalService.getRequestTimeout(),
350
+ retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
351
+ }
352
+ );
353
+ } catch (err) {
354
+ if (err instanceof HttpFetcherError) {
355
+ throw new Error(ERROR_MESSAGES.REQUEST_FAILED('upsertResourceAttributesSync', err.status, err.message));
356
+ }
357
+ throw err;
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Delete resource attributes synchronously.
363
+ * Matches API endpoint: DELETE /attributes/:accountId/resource/:resourceType/:resourceId
364
+ * @param accountId The account ID
365
+ * @param resourceType The resource type
366
+ * @param resourceId The resource ID
367
+ * @param keys Array of attribute keys to delete
368
+ * @returns Promise with response containing affected attributes
369
+ */
370
+ static async deleteResourceAttributesSync(
371
+ accountId: number,
372
+ resourceType: ResourceType,
373
+ resourceId: number,
374
+ keys: ResourceAttributeKeyType[]
375
+ ): Promise<ResourceAttributeResponse> {
376
+ // Validate inputs
377
+ if (!Number.isInteger(accountId)) {
378
+ throw new Error(`accountId must be an integer, got: ${accountId}`);
379
+ }
380
+ if (!resourceType || typeof resourceType !== 'string') {
381
+ throw new Error(`resourceType must be a string, got: ${typeof resourceType}`);
382
+ }
383
+ if (!Number.isInteger(resourceId)) {
384
+ throw new Error(`resourceId must be an integer, got: ${resourceId}`);
385
+ }
386
+ if (!Array.isArray(keys)) {
387
+ throw new Error('keys must be an array');
388
+ }
389
+ if (keys.length === 0) {
390
+ throw new Error('keys must contain at least 1 item');
391
+ }
392
+
393
+ const httpClient = Api.getPart('httpClient');
394
+ if (!httpClient) {
395
+ throw new Error(ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
396
+ }
397
+
398
+ const attributionHeaders = getAttributionsFromApi();
399
+ const path = AuthorizationAttributesService.API_PATHS.DELETE_RESOURCE_ATTRIBUTES.replace(
400
+ '{accountId}',
401
+ accountId.toString()
402
+ )
403
+ .replace('{resourceType}', resourceType)
404
+ .replace('{resourceId}', resourceId.toString());
405
+
406
+ try {
407
+ return await httpClient.fetch<ResourceAttributeResponse>(
408
+ {
409
+ url: {
410
+ appName: APP_NAME,
411
+ path,
412
+ },
413
+ method: 'DELETE',
414
+ headers: {
415
+ 'Content-Type': 'application/json',
416
+ ...attributionHeaders,
417
+ },
418
+ body: JSON.stringify({ keys }),
419
+ },
420
+ {
421
+ timeout: AuthorizationInternalService.getRequestTimeout(),
422
+ retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
423
+ }
424
+ );
425
+ } catch (err) {
426
+ if (err instanceof HttpFetcherError) {
427
+ throw new Error(ERROR_MESSAGES.REQUEST_FAILED('deleteResourceAttributesSync', err.status, err.message));
428
+ }
429
+ throw err;
430
+ }
431
+ }
432
+
433
+ /**
434
+ * Upsert entity attributes synchronously.
435
+ * Matches API endpoint: POST /attributes/:accountId/entity
436
+ * @param accountId The account ID
437
+ * @param entityAttributeAssignments Array of EntityAttributeAssignment objects (1-100 items)
438
+ * @returns Promise with response containing affected attributes
439
+ */
440
+ static async upsertEntityAttributesSync(
441
+ accountId: number,
442
+ entityAttributeAssignments: EntityAttributeAssignment[]
443
+ ): Promise<EntityAttributeResponse> {
444
+ // Validate inputs
445
+ if (!Number.isInteger(accountId)) {
446
+ throw new Error(`accountId must be an integer, got: ${accountId}`);
447
+ }
448
+ AuthorizationAttributesService.validateEntityAttributeAssignments(entityAttributeAssignments);
449
+
450
+ const httpClient = Api.getPart('httpClient');
451
+ if (!httpClient) {
452
+ throw new Error(ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
453
+ }
454
+
455
+ const attributionHeaders = getAttributionsFromApi();
456
+ const path = AuthorizationAttributesService.API_PATHS.UPSERT_ENTITY_ATTRIBUTES.replace(
457
+ '{accountId}',
458
+ accountId.toString()
459
+ );
460
+
461
+ try {
462
+ return await httpClient.fetch<EntityAttributeResponse>(
463
+ {
464
+ url: {
465
+ appName: APP_NAME,
466
+ path,
467
+ },
468
+ method: 'POST',
469
+ headers: {
470
+ 'Content-Type': 'application/json',
471
+ ...attributionHeaders,
472
+ },
473
+ body: JSON.stringify({ entityAttributeAssignments }),
474
+ },
475
+ {
476
+ timeout: AuthorizationInternalService.getRequestTimeout(),
477
+ retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
478
+ }
479
+ );
480
+ } catch (err) {
481
+ if (err instanceof HttpFetcherError) {
482
+ throw new Error(ERROR_MESSAGES.REQUEST_FAILED('upsertEntityAttributesSync', err.status, err.message));
483
+ }
484
+ throw err;
485
+ }
486
+ }
487
+
488
+ /**
489
+ * Delete entity attributes synchronously.
490
+ * Matches API endpoint: DELETE /attributes/:accountId/entity/:entityType/:entityId
491
+ * @param accountId The account ID
492
+ * @param entityType The entity type
493
+ * @param entityId The entity ID
494
+ * @param keys Array of attribute keys to delete
495
+ * @returns Promise with response containing affected attributes
496
+ */
497
+ static async deleteEntityAttributesSync(
498
+ accountId: number,
499
+ entityType: EntityType,
500
+ entityId: number,
501
+ keys: EntityAttributeKeyType[]
502
+ ): Promise<EntityAttributeResponse> {
503
+ // Validate inputs
504
+ if (!Number.isInteger(accountId)) {
505
+ throw new Error(`accountId must be an integer, got: ${accountId}`);
506
+ }
507
+ if (!entityType || typeof entityType !== 'string') {
508
+ throw new Error(`entityType must be a string, got: ${typeof entityType}`);
509
+ }
510
+ if (!Number.isInteger(entityId)) {
511
+ throw new Error(`entityId must be an integer, got: ${entityId}`);
512
+ }
513
+ if (!Array.isArray(keys)) {
514
+ throw new Error('keys must be an array');
515
+ }
516
+ if (keys.length === 0) {
517
+ throw new Error('keys must contain at least 1 item');
518
+ }
519
+
520
+ const httpClient = Api.getPart('httpClient');
521
+ if (!httpClient) {
522
+ throw new Error(ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
523
+ }
524
+
525
+ const attributionHeaders = getAttributionsFromApi();
526
+ const path = AuthorizationAttributesService.API_PATHS.DELETE_ENTITY_ATTRIBUTES.replace(
527
+ '{accountId}',
528
+ accountId.toString()
529
+ )
530
+ .replace('{entityType}', entityType)
531
+ .replace('{entityId}', entityId.toString());
532
+
533
+ try {
534
+ return await httpClient.fetch<EntityAttributeResponse>(
535
+ {
536
+ url: {
537
+ appName: APP_NAME,
538
+ path,
539
+ },
540
+ method: 'DELETE',
541
+ headers: {
542
+ 'Content-Type': 'application/json',
543
+ ...attributionHeaders,
544
+ },
545
+ body: JSON.stringify({ keys }),
546
+ },
547
+ {
548
+ timeout: AuthorizationInternalService.getRequestTimeout(),
549
+ retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
550
+ }
551
+ );
552
+ } catch (err) {
553
+ if (err instanceof HttpFetcherError) {
554
+ throw new Error(ERROR_MESSAGES.REQUEST_FAILED('deleteEntityAttributesSync', err.status, err.message));
555
+ }
556
+ throw err;
557
+ }
558
+ }
234
559
  }
@@ -18,7 +18,7 @@ import {
18
18
  GraphPermissionReason,
19
19
  } from '../types/graph-api.types';
20
20
  import { scopeToResource } from '../utils/authorization.utils';
21
- import { GRAPH_APP_NAME, GraphProfile } from '../constants';
21
+ import { GRAPH_APP_NAME } from '../constants';
22
22
  import { handleApiError } from '../utils/api-error-handler';
23
23
 
24
24
  const CAN_ACTION_IN_SCOPE_GRAPH_PATH = '/permissions/is-allowed';
@@ -85,7 +85,6 @@ export class GraphApi {
85
85
  url: {
86
86
  appName: GRAPH_APP_NAME,
87
87
  path: CAN_ACTION_IN_SCOPE_GRAPH_PATH,
88
- profile: GraphProfile.PERMISSION,
89
88
  },
90
89
  method: 'POST',
91
90
  headers: {
package/src/constants.ts CHANGED
@@ -4,10 +4,6 @@ import { FetcherConfig } from '@mondaydotcomorg/trident-backend-api';
4
4
  export const APP_NAME = 'authorization';
5
5
  export const GRAPH_APP_NAME = 'authorization-graph';
6
6
 
7
- export enum GraphProfile {
8
- PERMISSION = 'authorization-graph-permission',
9
- }
10
-
11
7
  export const ERROR_MESSAGES = {
12
8
  HTTP_CLIENT_NOT_INITIALIZED: 'MondayAuthorization: HTTP client is not initialized',
13
9
  REQUEST_FAILED: (method: string, status: number, reason: string) =>