@mondaydotcomorg/monday-authorization 3.5.1 → 3.5.2-feat-shaime-support-entity-attributes-4-ddec1d3
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 +88 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/authorization-attributes-ms-service.js +290 -0
- package/dist/authorization-attributes-service.d.ts +25 -47
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +32 -171
- package/dist/authorization-attributes-sns-service.d.ts +91 -0
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/authorization-attributes-sns-service.js +217 -0
- package/dist/base-attribute-assignment.d.ts +20 -0
- package/dist/base-attribute-assignment.d.ts.map +1 -0
- package/dist/base-attribute-assignment.js +36 -0
- package/dist/constants/sns.d.ts +12 -2
- package/dist/constants/sns.d.ts.map +1 -1
- package/dist/constants/sns.js +22 -2
- package/dist/entity-attribute-assignment.d.ts +20 -0
- package/dist/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/entity-attribute-assignment.js +32 -0
- package/dist/entity-attributes-constants.d.ts +7 -0
- package/dist/entity-attributes-constants.d.ts.map +1 -0
- package/dist/entity-attributes-constants.js +11 -0
- package/dist/errors/argument-error.d.ts +4 -0
- package/dist/errors/argument-error.d.ts.map +1 -0
- package/dist/errors/argument-error.js +11 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts +88 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-ms-service.mjs +288 -0
- package/dist/esm/authorization-attributes-service.d.ts +25 -47
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +32 -167
- package/dist/esm/authorization-attributes-sns-service.d.ts +91 -0
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-sns-service.mjs +211 -0
- package/dist/esm/base-attribute-assignment.d.ts +20 -0
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/base-attribute-assignment.mjs +30 -0
- package/dist/esm/constants/sns.d.ts +12 -2
- package/dist/esm/constants/sns.d.ts.map +1 -1
- package/dist/esm/constants/sns.mjs +17 -3
- package/dist/esm/entity-attribute-assignment.d.ts +20 -0
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/entity-attribute-assignment.mjs +30 -0
- package/dist/esm/entity-attributes-constants.d.ts +7 -0
- package/dist/esm/entity-attributes-constants.d.ts.map +1 -0
- package/dist/esm/entity-attributes-constants.mjs +9 -0
- package/dist/esm/errors/argument-error.d.ts +4 -0
- package/dist/esm/errors/argument-error.d.ts.map +1 -0
- package/dist/esm/errors/argument-error.mjs +9 -0
- package/dist/esm/resource-attribute-assignment.d.ts +20 -0
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/resource-attribute-assignment.mjs +30 -0
- package/dist/esm/resource-attributes-constants.d.ts +25 -0
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
- package/dist/esm/resource-attributes-constants.mjs +28 -0
- package/dist/esm/testKit/index.d.ts +4 -4
- package/dist/esm/testKit/index.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.d.ts +26 -11
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.mjs +6 -6
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +57 -0
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -0
- package/dist/esm/types/authorization-attributes-service.interface.mjs +1 -0
- package/dist/esm/utils/validation.d.ts +45 -0
- package/dist/esm/utils/validation.d.ts.map +1 -0
- package/dist/esm/utils/validation.mjs +152 -0
- package/dist/resource-attribute-assignment.d.ts +20 -0
- package/dist/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/resource-attribute-assignment.js +32 -0
- package/dist/resource-attributes-constants.d.ts +25 -0
- package/dist/resource-attributes-constants.d.ts.map +1 -0
- package/dist/resource-attributes-constants.js +31 -0
- package/dist/testKit/index.d.ts +4 -4
- package/dist/testKit/index.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.d.ts +26 -11
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.js +5 -5
- package/dist/types/authorization-attributes-service.interface.d.ts +57 -0
- package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -0
- package/dist/types/authorization-attributes-service.interface.js +1 -0
- package/dist/utils/validation.d.ts +45 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +158 -0
- package/package.json +3 -1
- package/src/authorization-attributes-ms-service.ts +438 -0
- package/src/authorization-attributes-service.ts +34 -222
- package/src/authorization-attributes-sns-service.ts +312 -0
- package/src/base-attribute-assignment.ts +46 -0
- package/src/constants/sns.ts +19 -2
- package/src/entity-attribute-assignment.ts +30 -0
- package/src/entity-attributes-constants.ts +7 -0
- package/src/errors/argument-error.ts +7 -0
- package/src/resource-attribute-assignment.ts +38 -0
- package/src/resource-attributes-constants.ts +27 -0
- package/src/testKit/index.ts +5 -5
- package/src/types/authorization-attributes-contracts.ts +34 -11
- package/src/types/authorization-attributes-service.interface.ts +101 -0
- package/src/utils/validation.ts +171 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
2
|
+
import { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
3
|
+
import { ResourceAttributeOperation, EntityAttributeOperation } from './types/authorization-attributes-contracts';
|
|
4
|
+
import { EntityType } from './entity-attributes-constants';
|
|
5
|
+
import { AuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
6
|
+
import { Resource } from './types/general';
|
|
7
|
+
/**
|
|
8
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
9
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
10
|
+
*/
|
|
11
|
+
export declare class AuthorizationAttributesMsService implements AuthorizationAttributesService {
|
|
12
|
+
private static LOG_TAG;
|
|
13
|
+
private static httpClient;
|
|
14
|
+
static destroyHttpClient(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Creates or updates resource attributes synchronously.
|
|
17
|
+
* @param accountId The account ID
|
|
18
|
+
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
19
|
+
* @returns Promise<void>
|
|
20
|
+
*/
|
|
21
|
+
upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Deletes specific attributes from a resource synchronously.
|
|
24
|
+
* @param accountId The account ID
|
|
25
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
26
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
27
|
+
* @returns Promise<void>
|
|
28
|
+
*/
|
|
29
|
+
deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates or updates entity attributes synchronously.
|
|
32
|
+
* @param accountId The account ID
|
|
33
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
34
|
+
* @returns Promise<void>
|
|
35
|
+
*/
|
|
36
|
+
upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Deletes specific attributes from an entity synchronously.
|
|
39
|
+
* @param accountId The account ID
|
|
40
|
+
* @param entityType The entity type
|
|
41
|
+
* @param entityId The entity ID
|
|
42
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
43
|
+
* @returns Promise<void>
|
|
44
|
+
*/
|
|
45
|
+
deleteEntityAttributes(accountId: number, entityType: EntityType, entityId: number, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Updates resource attributes (batch operations).
|
|
48
|
+
* Note: MS service does not support batch operations directly.
|
|
49
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
50
|
+
* @param accountId The account ID
|
|
51
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
52
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
53
|
+
* @param resourceAttributeOperations Array of operations to perform
|
|
54
|
+
* @returns Promise<ResourceAttributesOperation[]> Array of processed operations
|
|
55
|
+
*/
|
|
56
|
+
updateResourceAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
|
|
57
|
+
/**
|
|
58
|
+
* Updates entity attributes (batch operations).
|
|
59
|
+
* Note: MS service does not support batch operations directly.
|
|
60
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
61
|
+
* @param accountId The account ID
|
|
62
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
63
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
64
|
+
* @param entityAttributeOperations Array of operations to perform
|
|
65
|
+
* @returns Promise<EntityAttributesOperation[]> Array of processed operations
|
|
66
|
+
*/
|
|
67
|
+
updateEntityAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Replaces path template parameters with actual values
|
|
70
|
+
* @param template Path template with placeholders like {accountId}
|
|
71
|
+
* @param params Object with parameter names and values
|
|
72
|
+
* @returns Path with all placeholders replaced
|
|
73
|
+
*/
|
|
74
|
+
private static replacePathParams;
|
|
75
|
+
/**
|
|
76
|
+
* Generic helper for executing delete requests
|
|
77
|
+
*/
|
|
78
|
+
private static executeDeleteRequest;
|
|
79
|
+
/**
|
|
80
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
81
|
+
*/
|
|
82
|
+
private static getRequestHeaders;
|
|
83
|
+
/**
|
|
84
|
+
* Generic helper for executing upsert requests
|
|
85
|
+
*/
|
|
86
|
+
private static executeUpsertRequest;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=authorization-attributes-ms-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-attributes-ms-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-ms-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAEL,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAM3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,oDAAoD,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAY3C;;;GAGG;AACH,qBAAa,gCAAiC,YAAW,8BAA8B;IACrF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IACvD,OAAO,CAAC,MAAM,CAAC,UAAU,CAAwD;WAEnE,iBAAiB,IAAI,IAAI;IAIvC;;;;;OAKG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,EAC3D,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAiBhB;;;;;OAKG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,EACvD,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;OAOG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAoBhB;;;;;;;;;OASG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,EAC/B,2BAA2B,EAAE,0BAA0B,EAAE,GACxD,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAoCxC;;;;;;;;;OASG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,EAC/B,yBAAyB,EAAE,wBAAwB,EAAE,GACpD,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAiBtC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAQhC;;OAEG;mBACkB,oBAAoB;IAmEzC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA+ChC;;OAEG;mBACkB,oBAAoB;CAkE1C"}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const tridentBackendApi = require('@mondaydotcomorg/trident-backend-api');
|
|
4
|
+
const mondayJwt = require('@mondaydotcomorg/monday-jwt');
|
|
5
|
+
const resourceAttributeAssignment = require('./resource-attribute-assignment.js');
|
|
6
|
+
const entityAttributeAssignment = require('./entity-attribute-assignment.js');
|
|
7
|
+
const types_authorizationAttributesContracts = require('./types/authorization-attributes-contracts.js');
|
|
8
|
+
const errors_argumentError = require('./errors/argument-error.js');
|
|
9
|
+
const authorizationInternalService = require('./authorization-internal-service.js');
|
|
10
|
+
const attributionsService = require('./attributions-service.js');
|
|
11
|
+
const constants = require('./constants.js');
|
|
12
|
+
const utils_validation = require('./utils/validation.js');
|
|
13
|
+
|
|
14
|
+
const INTERNAL_APP_NAME = 'internal_ms';
|
|
15
|
+
const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
|
|
16
|
+
const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
|
|
17
|
+
const UPSERT_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity';
|
|
18
|
+
const DELETE_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity/{entityType}/{entityId}';
|
|
19
|
+
/**
|
|
20
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
21
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
22
|
+
*/
|
|
23
|
+
class AuthorizationAttributesMsService {
|
|
24
|
+
static LOG_TAG = 'authorization_attributes_ms';
|
|
25
|
+
static httpClient = tridentBackendApi.Api.getPart('httpClient') ?? null;
|
|
26
|
+
static destroyHttpClient() {
|
|
27
|
+
AuthorizationAttributesMsService.httpClient = null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates or updates resource attributes synchronously.
|
|
31
|
+
* @param accountId The account ID
|
|
32
|
+
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
33
|
+
* @returns Promise<void>
|
|
34
|
+
*/
|
|
35
|
+
async upsertResourceAttributes(accountId, resourceAttributeAssignments, _appName, _callerActionIdentifier) {
|
|
36
|
+
return AuthorizationAttributesMsService.executeUpsertRequest(accountId, resourceAttributeAssignments, UPSERT_RESOURCE_ATTRIBUTES_PATH, 'resourceAttributeAssignments', resourceAttributeAssignment.ResourceAttributeAssignment, 'resource', 'upsertResourceAttributes');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Deletes specific attributes from a resource synchronously.
|
|
40
|
+
* @param accountId The account ID
|
|
41
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
42
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
43
|
+
* @returns Promise<void>
|
|
44
|
+
*/
|
|
45
|
+
async deleteResourceAttributes(accountId, resource, attributeKeys, _appName, _callerActionIdentifier) {
|
|
46
|
+
utils_validation.ValidationUtils.validateResource(resource);
|
|
47
|
+
utils_validation.ValidationUtils.validateStringArray(attributeKeys);
|
|
48
|
+
return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_RESOURCE_ATTRIBUTES_PATH, {
|
|
49
|
+
resourceType: resource.type,
|
|
50
|
+
resourceId: resource.id,
|
|
51
|
+
}, attributeKeys, 'resource', 'deleteResourceAttributesSync', { resource });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates or updates entity attributes synchronously.
|
|
55
|
+
* @param accountId The account ID
|
|
56
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
57
|
+
* @returns Promise<void>
|
|
58
|
+
*/
|
|
59
|
+
async upsertEntityAttributes(accountId, entityAttributeAssignments, _appName, _callerActionIdentifier) {
|
|
60
|
+
return AuthorizationAttributesMsService.executeUpsertRequest(accountId, entityAttributeAssignments, UPSERT_ENTITY_ATTRIBUTES_PATH, 'entityAttributeAssignments', entityAttributeAssignment.EntityAttributeAssignment, 'entity', 'upsertEntityAttributesSync');
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Deletes specific attributes from an entity synchronously.
|
|
64
|
+
* @param accountId The account ID
|
|
65
|
+
* @param entityType The entity type
|
|
66
|
+
* @param entityId The entity ID
|
|
67
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
68
|
+
* @returns Promise<void>
|
|
69
|
+
*/
|
|
70
|
+
async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, _appName, _callerActionIdentifier) {
|
|
71
|
+
if (!entityType || typeof entityType !== 'string' || entityType.trim() === '') {
|
|
72
|
+
throw new errors_argumentError.ArgumentError(`entityType must be a non-empty string, got: ${entityType}`);
|
|
73
|
+
}
|
|
74
|
+
utils_validation.ValidationUtils.validateInteger(entityId);
|
|
75
|
+
return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_ENTITY_ATTRIBUTES_PATH, {
|
|
76
|
+
entityType,
|
|
77
|
+
entityId,
|
|
78
|
+
}, attributeKeys, 'entity', 'deleteEntityAttributesSync', { entityType, entityId });
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Updates resource attributes (batch operations).
|
|
82
|
+
* Note: MS service does not support batch operations directly.
|
|
83
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
84
|
+
* @param accountId The account ID
|
|
85
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
86
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
87
|
+
* @param resourceAttributeOperations Array of operations to perform
|
|
88
|
+
* @returns Promise<ResourceAttributesOperation[]> Array of processed operations
|
|
89
|
+
*/
|
|
90
|
+
async updateResourceAttributes(accountId, _appName, _callerActionIdentifier, resourceAttributeOperations) {
|
|
91
|
+
const processedOperations = [];
|
|
92
|
+
for (const operation of resourceAttributeOperations) {
|
|
93
|
+
if (operation.operationType === types_authorizationAttributesContracts.AttributeOperation.UPSERT) {
|
|
94
|
+
if (!operation.resourceId) {
|
|
95
|
+
throw new errors_argumentError.ArgumentError('resourceId is required for upsert operation');
|
|
96
|
+
}
|
|
97
|
+
await this.upsertResourceAttributes(accountId, [
|
|
98
|
+
new resourceAttributeAssignment.ResourceAttributeAssignment(operation.resourceId, operation.resourceType, operation.key, operation.value || ''),
|
|
99
|
+
]);
|
|
100
|
+
processedOperations.push(operation);
|
|
101
|
+
}
|
|
102
|
+
else if (operation.operationType === types_authorizationAttributesContracts.AttributeOperation.DELETE) {
|
|
103
|
+
if (!operation.resourceId) {
|
|
104
|
+
throw new errors_argumentError.ArgumentError('resourceId is required for delete operation');
|
|
105
|
+
}
|
|
106
|
+
await this.deleteResourceAttributes(accountId, {
|
|
107
|
+
type: operation.resourceType,
|
|
108
|
+
id: operation.resourceId,
|
|
109
|
+
}, [operation.key]);
|
|
110
|
+
processedOperations.push(operation);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return processedOperations;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Updates entity attributes (batch operations).
|
|
117
|
+
* Note: MS service does not support batch operations directly.
|
|
118
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
119
|
+
* @param accountId The account ID
|
|
120
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
121
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
122
|
+
* @param entityAttributeOperations Array of operations to perform
|
|
123
|
+
* @returns Promise<EntityAttributesOperation[]> Array of processed operations
|
|
124
|
+
*/
|
|
125
|
+
async updateEntityAttributes(accountId, _appName, _callerActionIdentifier, entityAttributeOperations) {
|
|
126
|
+
const processedOperations = [];
|
|
127
|
+
for (const operation of entityAttributeOperations) {
|
|
128
|
+
if (operation.operationType === 'upsert') {
|
|
129
|
+
await this.upsertEntityAttributes(accountId, [
|
|
130
|
+
new entityAttributeAssignment.EntityAttributeAssignment(operation.entityId, operation.entityType, operation.key, operation.value || ''),
|
|
131
|
+
]);
|
|
132
|
+
processedOperations.push(operation);
|
|
133
|
+
}
|
|
134
|
+
else if (operation.operationType === 'delete') {
|
|
135
|
+
await this.deleteEntityAttributes(accountId, operation.entityType, operation.entityId, [operation.key]);
|
|
136
|
+
processedOperations.push(operation);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return processedOperations;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Replaces path template parameters with actual values
|
|
143
|
+
* @param template Path template with placeholders like {accountId}
|
|
144
|
+
* @param params Object with parameter names and values
|
|
145
|
+
* @returns Path with all placeholders replaced
|
|
146
|
+
*/
|
|
147
|
+
static replacePathParams(template, params) {
|
|
148
|
+
let path = template;
|
|
149
|
+
for (const [key, value] of Object.entries(params)) {
|
|
150
|
+
path = path.replace(`{${key}}`, String(value));
|
|
151
|
+
}
|
|
152
|
+
return path;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Generic helper for executing delete requests
|
|
156
|
+
*/
|
|
157
|
+
static async executeDeleteRequest(accountId, pathTemplate, pathParams, keys, logPrefix, methodName, context = {}) {
|
|
158
|
+
// Validate inputs
|
|
159
|
+
utils_validation.ValidationUtils.validateInteger(accountId);
|
|
160
|
+
utils_validation.ValidationUtils.validateStringArray(keys);
|
|
161
|
+
if (!keys.length) {
|
|
162
|
+
authorizationInternalService.logger.warn({ tag: this.LOG_TAG, accountId, ...pathParams }, `${methodName} called with empty keys array`);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const requestBody = { keys };
|
|
166
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
167
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
168
|
+
}
|
|
169
|
+
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId, ...pathParams });
|
|
170
|
+
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
171
|
+
try {
|
|
172
|
+
authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Deleting ${logPrefix} attributes`);
|
|
173
|
+
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
174
|
+
url: {
|
|
175
|
+
appName: constants.APP_NAME,
|
|
176
|
+
path,
|
|
177
|
+
},
|
|
178
|
+
method: 'DELETE',
|
|
179
|
+
headers,
|
|
180
|
+
body: JSON.stringify(requestBody),
|
|
181
|
+
}, {
|
|
182
|
+
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
183
|
+
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
184
|
+
});
|
|
185
|
+
authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Successfully deleted ${logPrefix} attributes`);
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
authorizationInternalService.logger.error({
|
|
189
|
+
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
190
|
+
method: methodName,
|
|
191
|
+
accountId,
|
|
192
|
+
...pathParams,
|
|
193
|
+
...context,
|
|
194
|
+
error: err instanceof Error ? err.message : String(err),
|
|
195
|
+
}, `Failed in ${methodName}`);
|
|
196
|
+
throw err;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
201
|
+
*/
|
|
202
|
+
static getRequestHeaders(accountId, userId) {
|
|
203
|
+
const headers = {
|
|
204
|
+
'Content-Type': 'application/json',
|
|
205
|
+
};
|
|
206
|
+
// Generate Authorization token
|
|
207
|
+
const authToken = mondayJwt.signAuthorizationHeader({
|
|
208
|
+
appName: INTERNAL_APP_NAME,
|
|
209
|
+
accountId,
|
|
210
|
+
userId,
|
|
211
|
+
});
|
|
212
|
+
headers.Authorization = authToken;
|
|
213
|
+
// Add attribution headers if available
|
|
214
|
+
const attributionHeaders = attributionsService.getAttributionsFromApi();
|
|
215
|
+
for (const key in attributionHeaders) {
|
|
216
|
+
if (Object.prototype.hasOwnProperty.call(attributionHeaders, key)) {
|
|
217
|
+
headers[key] = attributionHeaders[key];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Add X-REQUEST-ID if available from context
|
|
221
|
+
try {
|
|
222
|
+
const tridentContext = tridentBackendApi.Api.getPart('context');
|
|
223
|
+
if (tridentContext?.runtimeAttributions) {
|
|
224
|
+
const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
225
|
+
if (outgoingHeaders) {
|
|
226
|
+
const attributionHeadersMap = {};
|
|
227
|
+
for (const [key, value] of outgoingHeaders) {
|
|
228
|
+
attributionHeadersMap[key] = value;
|
|
229
|
+
}
|
|
230
|
+
if (attributionHeadersMap['x-request-id']) {
|
|
231
|
+
headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
// Silently fail if context is not available
|
|
238
|
+
authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, error }, 'Failed to get request ID from context');
|
|
239
|
+
}
|
|
240
|
+
// Add X-REQUEST-START timestamp
|
|
241
|
+
headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
|
|
242
|
+
return headers;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Generic helper for executing upsert requests
|
|
246
|
+
*/
|
|
247
|
+
static async executeUpsertRequest(accountId, assignments, pathTemplate, requestBodyKey, assignmentClass, logPrefix, methodName) {
|
|
248
|
+
utils_validation.ValidationUtils.validateInteger(accountId);
|
|
249
|
+
utils_validation.ValidationUtils.validateArrayTypeOf(assignments, assignmentClass);
|
|
250
|
+
if (!assignments.length) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const assignmentDto = assignments.map(assignment => assignment.toDataTransferObject());
|
|
254
|
+
const requestBody = requestBodyKey === 'resourceAttributeAssignments'
|
|
255
|
+
? { resourceAttributeAssignments: assignmentDto }
|
|
256
|
+
: { entityAttributeAssignments: assignmentDto };
|
|
257
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
258
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
259
|
+
}
|
|
260
|
+
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId });
|
|
261
|
+
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
262
|
+
try {
|
|
263
|
+
authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
|
|
264
|
+
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
265
|
+
url: {
|
|
266
|
+
appName: constants.APP_NAME,
|
|
267
|
+
path,
|
|
268
|
+
},
|
|
269
|
+
method: 'POST',
|
|
270
|
+
headers,
|
|
271
|
+
body: JSON.stringify(requestBody),
|
|
272
|
+
}, {
|
|
273
|
+
timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
|
|
274
|
+
retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
|
|
275
|
+
});
|
|
276
|
+
authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
|
|
277
|
+
}
|
|
278
|
+
catch (err) {
|
|
279
|
+
authorizationInternalService.logger.error({
|
|
280
|
+
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
281
|
+
method: methodName,
|
|
282
|
+
accountId,
|
|
283
|
+
error: err instanceof Error ? err.message : String(err),
|
|
284
|
+
}, `Failed in ${methodName}`);
|
|
285
|
+
throw err;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
exports.AuthorizationAttributesMsService = AuthorizationAttributesMsService;
|
|
@@ -1,54 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AuthorizationAttributesService as IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
2
|
+
/**
|
|
3
|
+
* Main service class for managing resource and entity attributes.
|
|
4
|
+
* Provides access to both direct (MS) and SNS operations.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const service = new AuthorizationAttributesService();
|
|
8
|
+
*
|
|
9
|
+
* // Use direct operations
|
|
10
|
+
* await service.direct().upsertResourceAttributes(accountId, assignments);
|
|
11
|
+
*
|
|
12
|
+
* // Use SNS operations
|
|
13
|
+
* await service.sns().upsertResourceAttributes(accountId, assignments, appName, actionId);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
5
16
|
export declare class AuthorizationAttributesService {
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
private httpClient;
|
|
9
|
-
private fetchOptions;
|
|
10
|
-
private snsArn;
|
|
17
|
+
private _directService;
|
|
18
|
+
private _snsService;
|
|
11
19
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @
|
|
20
|
+
* Gets the direct (MS) service instance.
|
|
21
|
+
* Initializes the service on first access (lazy initialization).
|
|
22
|
+
* @returns IAuthorizationAttributesService instance
|
|
15
23
|
*/
|
|
16
|
-
|
|
24
|
+
direct(): IAuthorizationAttributesService;
|
|
17
25
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
21
|
-
* e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
|
|
22
|
-
* @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
|
|
26
|
+
* Gets the SNS service instance.
|
|
27
|
+
* Initializes the service on first access (lazy initialization).
|
|
28
|
+
* @returns IAuthorizationAttributesService instance
|
|
23
29
|
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
|
|
27
|
-
* @param accountId
|
|
28
|
-
* @param resource - The resource (resourceType, resourceId) to delete the attributes for.
|
|
29
|
-
* @param attributeKeys - Array of attribute keys to delete for the resource.
|
|
30
|
-
* @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
|
|
31
|
-
*/
|
|
32
|
-
deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[]): Promise<ResourceAttributeResponse>;
|
|
33
|
-
/**
|
|
34
|
-
* Async function, this function only send the updates request to SNS and return before the change actually took place
|
|
35
|
-
* @param accountId
|
|
36
|
-
* @param appName - App name of the calling app
|
|
37
|
-
* @param callerActionIdentifier - action identifier
|
|
38
|
-
* @param resourceAttributeOperations - Array of operations to do on resource attributes.
|
|
39
|
-
* @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
|
|
40
|
-
* */
|
|
41
|
-
updateResourceAttributesAsync(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributesOperation[]): Promise<ResourceAttributesOperation[]>;
|
|
42
|
-
private sendSingleSnsMessage;
|
|
43
|
-
private static getSnsTopicArn;
|
|
44
|
-
/**
|
|
45
|
-
* Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
|
|
46
|
-
* This function can be used as health check for services that updating resource attributes in async is crucial.
|
|
47
|
-
* Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
|
|
48
|
-
* errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
|
|
49
|
-
* However, this is the best we can do without actually push dummy messages to the SNS.
|
|
50
|
-
* @return {Promise<boolean>} - true if succeeded
|
|
51
|
-
*/
|
|
52
|
-
asyncResourceAttributesHealthCheck(): Promise<boolean>;
|
|
30
|
+
sns(): IAuthorizationAttributesService;
|
|
53
31
|
}
|
|
54
32
|
//# sourceMappingURL=authorization-attributes-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,IAAI,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAEvI;;;;;;;;;;;;;GAaG;AACH,qBAAa,8BAA8B;IACzC,OAAO,CAAC,cAAc,CAAiD;IACvE,OAAO,CAAC,WAAW,CAAkD;IAErE;;;;OAIG;IACH,MAAM,IAAI,+BAA+B;IAOzC;;;;OAIG;IACH,GAAG,IAAI,+BAA+B;CAMvC"}
|