@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
|
@@ -2,6 +2,11 @@ import { Api } from '@mondaydotcomorg/trident-backend-api';
|
|
|
2
2
|
import { signAuthorizationHeader } from '@mondaydotcomorg/monday-jwt';
|
|
3
3
|
import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
|
|
4
4
|
import { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
5
|
+
import {
|
|
6
|
+
EntityAttributeAssignment,
|
|
7
|
+
EntityType,
|
|
8
|
+
EntityAttributeKeyType,
|
|
9
|
+
} from './types/authorization-attributes-contracts';
|
|
5
10
|
import { ArgumentError } from './errors/argument-error';
|
|
6
11
|
import { AuthorizationInternalService, logger } from './authorization-internal-service';
|
|
7
12
|
import { getAttributionsFromApi } from './attributions-service';
|
|
@@ -10,6 +15,8 @@ import { APP_NAME } from './constants';
|
|
|
10
15
|
const INTERNAL_APP_NAME = 'internal_ms';
|
|
11
16
|
const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
|
|
12
17
|
const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
|
|
18
|
+
const UPSERT_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity';
|
|
19
|
+
const DELETE_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity/{entityType}/{entityId}';
|
|
13
20
|
|
|
14
21
|
interface Resource {
|
|
15
22
|
resourceType: string;
|
|
@@ -25,6 +32,15 @@ interface UpsertRequestBody {
|
|
|
25
32
|
}[];
|
|
26
33
|
}
|
|
27
34
|
|
|
35
|
+
interface UpsertEntityRequestBody {
|
|
36
|
+
entityAttributeAssignments: {
|
|
37
|
+
entityId: number;
|
|
38
|
+
entityType: string;
|
|
39
|
+
key: string;
|
|
40
|
+
value: string;
|
|
41
|
+
}[];
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
interface DeleteRequestBody {
|
|
29
45
|
keys: string[];
|
|
30
46
|
}
|
|
@@ -319,4 +335,234 @@ export class AuthorizationAttributesMsService {
|
|
|
319
335
|
throw err;
|
|
320
336
|
}
|
|
321
337
|
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Creates or updates entity attributes synchronously.
|
|
341
|
+
* @param accountId The account ID
|
|
342
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
343
|
+
* @returns Promise<void>
|
|
344
|
+
*/
|
|
345
|
+
static async upsertEntityAttributesSync(
|
|
346
|
+
accountId: number,
|
|
347
|
+
entityAttributeAssignments: EntityAttributeAssignment[]
|
|
348
|
+
): Promise<void> {
|
|
349
|
+
// Skip HTTP requests in test environment
|
|
350
|
+
if (process.env.NODE_ENV === 'test') {
|
|
351
|
+
logger.debug(
|
|
352
|
+
{ tag: this.LOG_TAG, accountId, count: entityAttributeAssignments.length },
|
|
353
|
+
'Skipping upsertEntityAttributesSync in test environment'
|
|
354
|
+
);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Validate inputs
|
|
359
|
+
if (!Number.isInteger(accountId)) {
|
|
360
|
+
throw new ArgumentError(`accountId must be an integer, got: ${accountId}`);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (!Array.isArray(entityAttributeAssignments)) {
|
|
364
|
+
throw new ArgumentError('entityAttributeAssignments must be an array');
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (entityAttributeAssignments.length === 0) {
|
|
368
|
+
logger.warn({ tag: this.LOG_TAG, accountId }, 'upsertEntityAttributesSync called with empty array');
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Validate each assignment
|
|
373
|
+
for (let i = 0; i < entityAttributeAssignments.length; i++) {
|
|
374
|
+
const assignment = entityAttributeAssignments[i];
|
|
375
|
+
if (!assignment.entityId || typeof assignment.entityId !== 'number') {
|
|
376
|
+
throw new ArgumentError(`entityAttributeAssignments[${i}].entityId is required and must be a number`);
|
|
377
|
+
}
|
|
378
|
+
if (!assignment.entityType || typeof assignment.entityType !== 'string') {
|
|
379
|
+
throw new ArgumentError(`entityAttributeAssignments[${i}].entityType is required and must be a string`);
|
|
380
|
+
}
|
|
381
|
+
if (!assignment.key || typeof assignment.key !== 'string') {
|
|
382
|
+
throw new ArgumentError(`entityAttributeAssignments[${i}].key is required and must be a string`);
|
|
383
|
+
}
|
|
384
|
+
if (assignment.value === undefined || typeof assignment.value !== 'string') {
|
|
385
|
+
throw new ArgumentError(`entityAttributeAssignments[${i}].value is required and must be a string`);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Build request body
|
|
390
|
+
const requestBody: UpsertEntityRequestBody = {
|
|
391
|
+
entityAttributeAssignments: entityAttributeAssignments.map(assignment => ({
|
|
392
|
+
entityId: assignment.entityId,
|
|
393
|
+
entityType: assignment.entityType,
|
|
394
|
+
key: assignment.key,
|
|
395
|
+
value: assignment.value,
|
|
396
|
+
})),
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
const httpClient = Api.getPart('httpClient');
|
|
400
|
+
if (!httpClient) {
|
|
401
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
402
|
+
}
|
|
403
|
+
const path = UPSERT_ENTITY_ATTRIBUTES_PATH.replace('{accountId}', accountId.toString());
|
|
404
|
+
const headers = this.getRequestHeaders(accountId);
|
|
405
|
+
|
|
406
|
+
try {
|
|
407
|
+
logger.info(
|
|
408
|
+
{ tag: this.LOG_TAG, accountId, count: entityAttributeAssignments.length },
|
|
409
|
+
'Upserting entity attributes'
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
await httpClient.fetch(
|
|
413
|
+
{
|
|
414
|
+
url: {
|
|
415
|
+
appName: APP_NAME,
|
|
416
|
+
path,
|
|
417
|
+
},
|
|
418
|
+
method: 'POST',
|
|
419
|
+
headers,
|
|
420
|
+
body: JSON.stringify(requestBody),
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
424
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
425
|
+
}
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
logger.info(
|
|
429
|
+
{ tag: this.LOG_TAG, accountId, count: entityAttributeAssignments.length },
|
|
430
|
+
'Successfully upserted entity attributes'
|
|
431
|
+
);
|
|
432
|
+
} catch (err) {
|
|
433
|
+
logger.error(
|
|
434
|
+
{
|
|
435
|
+
tag: this.LOG_TAG,
|
|
436
|
+
accountId,
|
|
437
|
+
method: 'upsertEntityAttributesSync',
|
|
438
|
+
error: err instanceof Error ? err.message : String(err),
|
|
439
|
+
},
|
|
440
|
+
'Failed to upsert entity attributes'
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
if (err instanceof HttpFetcherError) {
|
|
444
|
+
throw new Error(
|
|
445
|
+
`AuthorizationAttributesMsService: [upsertEntityAttributesSync] request failed with status ${err.status}: ${err.message}`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
throw err;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Deletes specific attributes from an entity synchronously.
|
|
454
|
+
* @param accountId The account ID
|
|
455
|
+
* @param entityType The entity type
|
|
456
|
+
* @param entityId The entity ID
|
|
457
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
458
|
+
* @returns Promise<void>
|
|
459
|
+
*/
|
|
460
|
+
static async deleteEntityAttributesSync(
|
|
461
|
+
accountId: number,
|
|
462
|
+
entityType: EntityType,
|
|
463
|
+
entityId: number,
|
|
464
|
+
attributeKeys: EntityAttributeKeyType[]
|
|
465
|
+
): Promise<void> {
|
|
466
|
+
// Skip HTTP requests in test environment
|
|
467
|
+
if (process.env.NODE_ENV === 'test') {
|
|
468
|
+
logger.debug(
|
|
469
|
+
{ tag: this.LOG_TAG, accountId, entityType, entityId, attributeKeys },
|
|
470
|
+
'Skipping deleteEntityAttributesSync in test environment'
|
|
471
|
+
);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// Validate inputs
|
|
476
|
+
if (!Number.isInteger(accountId)) {
|
|
477
|
+
throw new ArgumentError(`accountId must be an integer, got: ${accountId}`);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (!entityType || typeof entityType !== 'string') {
|
|
481
|
+
throw new ArgumentError(`entityType must be a string, got: ${typeof entityType}`);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (!Number.isInteger(entityId)) {
|
|
485
|
+
throw new ArgumentError(`entityId must be an integer, got: ${entityId}`);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (!Array.isArray(attributeKeys)) {
|
|
489
|
+
throw new ArgumentError('attributeKeys must be an array');
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (attributeKeys.length === 0) {
|
|
493
|
+
logger.warn(
|
|
494
|
+
{ tag: this.LOG_TAG, accountId, entityType, entityId },
|
|
495
|
+
'deleteEntityAttributesSync called with empty keys array'
|
|
496
|
+
);
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Validate all keys are strings
|
|
501
|
+
for (let i = 0; i < attributeKeys.length; i++) {
|
|
502
|
+
if (typeof attributeKeys[i] !== 'string') {
|
|
503
|
+
throw new ArgumentError(`All attributeKeys must be strings, but item at index ${i} is not`);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Build request body
|
|
508
|
+
const requestBody: DeleteRequestBody = {
|
|
509
|
+
keys: attributeKeys,
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
const httpClient = Api.getPart('httpClient');
|
|
513
|
+
if (!httpClient) {
|
|
514
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
515
|
+
}
|
|
516
|
+
const path = DELETE_ENTITY_ATTRIBUTES_PATH.replace('{accountId}', accountId.toString())
|
|
517
|
+
.replace('{entityType}', entityType)
|
|
518
|
+
.replace('{entityId}', entityId.toString());
|
|
519
|
+
const headers = this.getRequestHeaders(accountId);
|
|
520
|
+
|
|
521
|
+
try {
|
|
522
|
+
logger.info(
|
|
523
|
+
{ tag: this.LOG_TAG, accountId, entityType, entityId, keys: attributeKeys },
|
|
524
|
+
'Deleting entity attributes'
|
|
525
|
+
);
|
|
526
|
+
|
|
527
|
+
await httpClient.fetch(
|
|
528
|
+
{
|
|
529
|
+
url: {
|
|
530
|
+
appName: APP_NAME,
|
|
531
|
+
path,
|
|
532
|
+
},
|
|
533
|
+
method: 'DELETE',
|
|
534
|
+
headers,
|
|
535
|
+
body: JSON.stringify(requestBody),
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
539
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
540
|
+
}
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
logger.info(
|
|
544
|
+
{ tag: this.LOG_TAG, accountId, entityType, entityId, keys: attributeKeys },
|
|
545
|
+
'Successfully deleted entity attributes'
|
|
546
|
+
);
|
|
547
|
+
} catch (err) {
|
|
548
|
+
logger.error(
|
|
549
|
+
{
|
|
550
|
+
tag: this.LOG_TAG,
|
|
551
|
+
accountId,
|
|
552
|
+
method: 'deleteEntityAttributesSync',
|
|
553
|
+
entityType,
|
|
554
|
+
entityId,
|
|
555
|
+
error: err instanceof Error ? err.message : String(err),
|
|
556
|
+
},
|
|
557
|
+
'Failed to delete entity attributes'
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
if (err instanceof HttpFetcherError) {
|
|
561
|
+
throw new Error(
|
|
562
|
+
`AuthorizationAttributesMsService: [deleteEntityAttributesSync] request failed with status ${err.status}: ${err.message}`
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
throw err;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
322
568
|
}
|