@mondaydotcomorg/monday-authorization 3.5.1 → 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-127d99a
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 +90 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/authorization-attributes-ms-service.js +351 -0
- package/dist/authorization-attributes-service.d.ts +26 -47
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +33 -171
- package/dist/authorization-attributes-sns-service.d.ts +90 -0
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/authorization-attributes-sns-service.js +217 -0
- package/dist/authorization-middleware.d.ts +2 -2
- package/dist/authorization-middleware.d.ts.map +1 -1
- package/dist/authorization-service.d.ts +3 -3
- package/dist/authorization-service.d.ts.map +1 -1
- package/dist/base-attribute-assignment.d.ts +18 -0
- package/dist/base-attribute-assignment.d.ts.map +1 -0
- package/dist/base-attribute-assignment.js +43 -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 +14 -0
- package/dist/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/entity-attribute-assignment.js +24 -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 +9 -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 +90 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-ms-service.mjs +349 -0
- package/dist/esm/authorization-attributes-service.d.ts +26 -47
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +33 -167
- package/dist/esm/authorization-attributes-sns-service.d.ts +90 -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/authorization-middleware.d.ts +2 -2
- package/dist/esm/authorization-middleware.d.ts.map +1 -1
- package/dist/esm/authorization-service.d.ts +3 -3
- package/dist/esm/authorization-service.d.ts.map +1 -1
- package/dist/esm/base-attribute-assignment.d.ts +18 -0
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/base-attribute-assignment.mjs +41 -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 +14 -0
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/entity-attribute-assignment.mjs +22 -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 +7 -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/index.d.ts +9 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +7 -0
- package/dist/esm/prometheus-service.d.ts +1 -2
- package/dist/esm/prometheus-service.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.d.ts +24 -0
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/resource-attribute-assignment.mjs +34 -0
- package/dist/esm/resource-attributes-constants.d.ts +15 -0
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
- package/dist/esm/resource-attributes-constants.mjs +25 -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 +27 -12
- 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 +56 -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/types/general.d.ts +1 -2
- package/dist/esm/types/general.d.ts.map +1 -1
- 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 +117 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/prometheus-service.d.ts +1 -2
- package/dist/prometheus-service.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.d.ts +24 -0
- package/dist/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/resource-attribute-assignment.js +36 -0
- package/dist/resource-attributes-constants.d.ts +15 -0
- package/dist/resource-attributes-constants.d.ts.map +1 -0
- package/dist/resource-attributes-constants.js +28 -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 +27 -12
- 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 +56 -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/types/general.d.ts +1 -2
- package/dist/types/general.d.ts.map +1 -1
- package/dist/utils/validation.d.ts +45 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +119 -0
- package/package.json +3 -2
- package/src/authorization-attributes-ms-service.ts +513 -0
- package/src/authorization-attributes-service.ts +35 -222
- package/src/authorization-attributes-sns-service.ts +312 -0
- package/src/authorization-middleware.ts +2 -2
- package/src/authorization-service.ts +4 -4
- package/src/base-attribute-assignment.ts +55 -0
- package/src/constants/sns.ts +19 -2
- package/src/entity-attribute-assignment.ts +21 -0
- package/src/entity-attributes-constants.ts +7 -0
- package/src/errors/argument-error.ts +7 -0
- package/src/index.ts +9 -0
- package/src/prometheus-service.ts +1 -3
- package/src/resource-attribute-assignment.ts +43 -0
- package/src/resource-attributes-constants.ts +35 -0
- package/src/testKit/index.ts +5 -5
- package/src/types/authorization-attributes-contracts.ts +36 -11
- package/src/types/authorization-attributes-service.interface.ts +101 -0
- package/src/types/general.ts +3 -2
- package/src/utils/validation.ts +114 -0
package/dist/constants/sns.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
1
|
+
export declare enum SnsTopicType {
|
|
2
|
+
RESOURCE = "resource",
|
|
3
|
+
ENTITY = "entity"
|
|
4
|
+
}
|
|
5
|
+
export declare const RESOURCE_SNS_ARN_ENV_VAR_NAME = "SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES";
|
|
6
|
+
export declare const RESOURCE_SNS_DEV_TEST_NAME = "arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local";
|
|
7
|
+
export declare const ENTITY_SNS_ARN_ENV_VAR_NAME = "SHARED_AUTHORIZATION_SNS_ENDPOINT_ENTITY_ATTRIBUTES";
|
|
8
|
+
export declare const ENTITY_SNS_DEV_TEST_NAME = "arn:aws:sns:us-east-1:000000000000:monday-authorization-entity-attributes-sns-local";
|
|
3
9
|
export declare const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = "resourceAttributeModification";
|
|
10
|
+
export declare const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = "entityAttributeModification";
|
|
4
11
|
export declare const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
12
|
+
export declare const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
13
|
+
export declare const SNS_ARN_ENV_VAR_NAME = "SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES";
|
|
14
|
+
export declare const SNS_DEV_TEST_NAME = "arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local";
|
|
5
15
|
//# 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,
|
|
1
|
+
{"version":3,"file":"sns.d.ts","sourceRoot":"","sources":["../../src/constants/sns.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,QAAQ,aAAa;IACrB,MAAM,WAAW;CAClB;AAGD,eAAO,MAAM,6BAA6B,0DAA0D,CAAC;AACrG,eAAO,MAAM,0BAA0B,0FACkD,CAAC;AAG1F,eAAO,MAAM,2BAA2B,wDAAwD,CAAC;AACjG,eAAO,MAAM,wBAAwB,wFACkD,CAAC;AACxF,eAAO,MAAM,qDAAqD,kCAAkC,CAAC;AACrG,eAAO,MAAM,mDAAmD,gCAAgC,CAAC;AACjG,eAAO,MAAM,oDAAoD,MAAM,CAAC;AACxE,eAAO,MAAM,kDAAkD,MAAM,CAAC;AAGtE,eAAO,MAAM,oBAAoB,0DAAgC,CAAC;AAClE,eAAO,MAAM,iBAAiB,0FAA6B,CAAC"}
|
package/dist/constants/sns.js
CHANGED
|
@@ -1,11 +1,31 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.SnsTopicType = void 0;
|
|
4
|
+
(function (SnsTopicType) {
|
|
5
|
+
SnsTopicType["RESOURCE"] = "resource";
|
|
6
|
+
SnsTopicType["ENTITY"] = "entity";
|
|
7
|
+
})(exports.SnsTopicType || (exports.SnsTopicType = {}));
|
|
8
|
+
// Resource SNS constants
|
|
9
|
+
const RESOURCE_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES';
|
|
10
|
+
const RESOURCE_SNS_DEV_TEST_NAME = 'arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local';
|
|
11
|
+
// Entity SNS constants
|
|
12
|
+
const ENTITY_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_ENTITY_ATTRIBUTES';
|
|
13
|
+
const ENTITY_SNS_DEV_TEST_NAME = 'arn:aws:sns:us-east-1:000000000000:monday-authorization-entity-attributes-sns-local';
|
|
5
14
|
const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'resourceAttributeModification';
|
|
15
|
+
const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'entityAttributeModification';
|
|
6
16
|
const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
17
|
+
const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
|
|
18
|
+
// Legacy exports for backward compatibility
|
|
19
|
+
const SNS_ARN_ENV_VAR_NAME = RESOURCE_SNS_ARN_ENV_VAR_NAME;
|
|
20
|
+
const SNS_DEV_TEST_NAME = RESOURCE_SNS_DEV_TEST_NAME;
|
|
7
21
|
|
|
22
|
+
exports.ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE;
|
|
8
23
|
exports.ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE;
|
|
24
|
+
exports.ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND;
|
|
25
|
+
exports.ENTITY_SNS_ARN_ENV_VAR_NAME = ENTITY_SNS_ARN_ENV_VAR_NAME;
|
|
26
|
+
exports.ENTITY_SNS_DEV_TEST_NAME = ENTITY_SNS_DEV_TEST_NAME;
|
|
9
27
|
exports.RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND;
|
|
28
|
+
exports.RESOURCE_SNS_ARN_ENV_VAR_NAME = RESOURCE_SNS_ARN_ENV_VAR_NAME;
|
|
29
|
+
exports.RESOURCE_SNS_DEV_TEST_NAME = RESOURCE_SNS_DEV_TEST_NAME;
|
|
10
30
|
exports.SNS_ARN_ENV_VAR_NAME = SNS_ARN_ENV_VAR_NAME;
|
|
11
31
|
exports.SNS_DEV_TEST_NAME = SNS_DEV_TEST_NAME;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EntityType } from './entity-attributes-constants';
|
|
2
|
+
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
|
+
export declare class EntityAttributeAssignment extends BaseAttributeAssignment<number, EntityType> {
|
|
4
|
+
readonly entityId: number;
|
|
5
|
+
readonly entityType: EntityType;
|
|
6
|
+
constructor(entityId: number, entityType: string, attributeKey: string, attributeValue: string);
|
|
7
|
+
/**
|
|
8
|
+
* Compares two assignments for equality
|
|
9
|
+
* @param other Another EntityAttributeAssignment instance
|
|
10
|
+
* @returns true if all properties are equal
|
|
11
|
+
*/
|
|
12
|
+
equals(other: EntityAttributeAssignment): boolean;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=entity-attribute-assignment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-attribute-assignment.d.ts","sourceRoot":"","sources":["../src/entity-attribute-assignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,qBAAa,yBAA0B,SAAQ,uBAAuB,CAAC,MAAM,EAAE,UAAU,CAAC;IACxF,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,UAAU,EAAE,UAAU,CAAC;gBAE3B,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAK9F;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO;CAGlD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const entityAttributesConstants = require('./entity-attributes-constants.js');
|
|
4
|
+
const baseAttributeAssignment = require('./base-attribute-assignment.js');
|
|
5
|
+
|
|
6
|
+
class EntityAttributeAssignment extends baseAttributeAssignment.BaseAttributeAssignment {
|
|
7
|
+
entityId;
|
|
8
|
+
entityType;
|
|
9
|
+
constructor(entityId, entityType, attributeKey, attributeValue) {
|
|
10
|
+
super(entityId, entityType, attributeKey, attributeValue, Object.values(entityAttributesConstants.ENTITY_TYPES), 'entityId', 'entityType');
|
|
11
|
+
this.entityId = entityId;
|
|
12
|
+
this.entityType = this.type;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Compares two assignments for equality
|
|
16
|
+
* @param other Another EntityAttributeAssignment instance
|
|
17
|
+
* @returns true if all properties are equal
|
|
18
|
+
*/
|
|
19
|
+
equals(other) {
|
|
20
|
+
return super.equals(other);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.EntityAttributeAssignment = EntityAttributeAssignment;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-attributes-constants.d.ts","sourceRoot":"","sources":["../src/entity-attributes-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"argument-error.d.ts","sourceRoot":"","sources":["../../src/errors/argument-error.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
class ArgumentError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'ArgumentError';
|
|
7
|
+
Object.setPrototypeOf(this, ArgumentError.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
exports.ArgumentError = ArgumentError;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
2
|
+
import { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
3
|
+
import { EntityType, ResourceAttributeOperation, EntityAttributeOperation } from './types/authorization-attributes-contracts';
|
|
4
|
+
import { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
5
|
+
import { Resource } from './types/general';
|
|
6
|
+
/**
|
|
7
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
8
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
9
|
+
*/
|
|
10
|
+
export declare class AuthorizationAttributesMsService implements IAuthorizationAttributesService {
|
|
11
|
+
private static LOG_TAG;
|
|
12
|
+
private static httpClient;
|
|
13
|
+
/**
|
|
14
|
+
* Creates or updates resource attributes synchronously.
|
|
15
|
+
* @param accountId The account ID
|
|
16
|
+
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
17
|
+
* @returns Promise<void>
|
|
18
|
+
*/
|
|
19
|
+
upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Deletes specific attributes from a resource synchronously.
|
|
22
|
+
* @param accountId The account ID
|
|
23
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
24
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
25
|
+
* @returns Promise<void>
|
|
26
|
+
*/
|
|
27
|
+
deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Creates or updates entity attributes synchronously.
|
|
30
|
+
* @param accountId The account ID
|
|
31
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
32
|
+
* @returns Promise<void>
|
|
33
|
+
*/
|
|
34
|
+
upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Deletes specific attributes from an entity synchronously.
|
|
37
|
+
* @param accountId The account ID
|
|
38
|
+
* @param entityType The entity type
|
|
39
|
+
* @param entityId The entity ID
|
|
40
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
41
|
+
* @returns Promise<void>
|
|
42
|
+
*/
|
|
43
|
+
deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Updates resource attributes (batch operations).
|
|
46
|
+
* Note: MS service does not support batch operations directly.
|
|
47
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
48
|
+
* @param accountId The account ID
|
|
49
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
50
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
51
|
+
* @param resourceAttributeOperations Array of operations to perform
|
|
52
|
+
* @returns Promise<ResourceAttributesOperation[]> Array of processed operations
|
|
53
|
+
*/
|
|
54
|
+
updateResourceAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Updates entity attributes (batch operations).
|
|
57
|
+
* Note: MS service does not support batch operations directly.
|
|
58
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
59
|
+
* @param accountId The account ID
|
|
60
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
61
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
62
|
+
* @param entityAttributeOperations Array of operations to perform
|
|
63
|
+
* @returns Promise<EntityAttributesOperation[]> Array of processed operations
|
|
64
|
+
*/
|
|
65
|
+
updateEntityAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Replaces path template parameters with actual values
|
|
68
|
+
* @param template Path template with placeholders like {accountId}
|
|
69
|
+
* @param params Object with parameter names and values
|
|
70
|
+
* @returns Path with all placeholders replaced
|
|
71
|
+
*/
|
|
72
|
+
private static replacePathParams;
|
|
73
|
+
/**
|
|
74
|
+
* Generic helper for executing delete requests
|
|
75
|
+
*/
|
|
76
|
+
private static executeDeleteRequest;
|
|
77
|
+
/**
|
|
78
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
79
|
+
*/
|
|
80
|
+
private static getRequestHeaders;
|
|
81
|
+
/**
|
|
82
|
+
* Validates that all messages are instances of the specified message class
|
|
83
|
+
*/
|
|
84
|
+
private static validateMessages;
|
|
85
|
+
/**
|
|
86
|
+
* Generic helper for executing upsert requests
|
|
87
|
+
*/
|
|
88
|
+
private static executeUpsertRequest;
|
|
89
|
+
}
|
|
90
|
+
//# 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":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAEL,UAAU,EACV,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,4CAA4C,CAAC;AAMpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAW3C;;;GAGG;AACH,qBAAa,gCAAiC,YAAW,+BAA+B;IACtF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IACvD,OAAO,CAAC,MAAM,CAAC,UAAU,CAAqD;IAC9E;;;;;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;IAyBhB;;;;;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,GAAG,MAAM,EAC/B,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;IA0EzC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA+ChC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAsD/B;;OAEG;mBACkB,oBAAoB;CA0E1C"}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { Api } from '@mondaydotcomorg/trident-backend-api';
|
|
2
|
+
import { signAuthorizationHeader } from '@mondaydotcomorg/monday-jwt';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { ResourceAttributeAssignment } from './resource-attribute-assignment.mjs';
|
|
5
|
+
import { EntityAttributeAssignment } from './entity-attribute-assignment.mjs';
|
|
6
|
+
import { AttributeOperation } from './types/authorization-attributes-contracts.mjs';
|
|
7
|
+
import { ArgumentError } from './errors/argument-error.mjs';
|
|
8
|
+
import { logger, AuthorizationInternalService } from './authorization-internal-service.mjs';
|
|
9
|
+
import { getAttributionsFromApi } from './attributions-service.mjs';
|
|
10
|
+
import { APP_NAME } from './constants.mjs';
|
|
11
|
+
import { ValidationUtils } from './utils/validation.mjs';
|
|
12
|
+
|
|
13
|
+
const INTERNAL_APP_NAME = 'internal_ms';
|
|
14
|
+
const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
|
|
15
|
+
const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
|
|
16
|
+
const UPSERT_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity';
|
|
17
|
+
const DELETE_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity/{entityType}/{entityId}';
|
|
18
|
+
/**
|
|
19
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
20
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
21
|
+
*/
|
|
22
|
+
class AuthorizationAttributesMsService {
|
|
23
|
+
static LOG_TAG = 'authorization_attributes_ms';
|
|
24
|
+
static httpClient = Api.getPart('httpClient');
|
|
25
|
+
/**
|
|
26
|
+
* Creates or updates resource attributes synchronously.
|
|
27
|
+
* @param accountId The account ID
|
|
28
|
+
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
29
|
+
* @returns Promise<void>
|
|
30
|
+
*/
|
|
31
|
+
async upsertResourceAttributes(accountId, resourceAttributeAssignments, _appName, _callerActionIdentifier) {
|
|
32
|
+
return AuthorizationAttributesMsService.executeUpsertRequest(accountId, resourceAttributeAssignments, UPSERT_RESOURCE_ATTRIBUTES_PATH, 'resourceAttributeAssignments', ResourceAttributeAssignment, 'resource', 'upsertResourceAttributesSync');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Deletes specific attributes from a resource synchronously.
|
|
36
|
+
* @param accountId The account ID
|
|
37
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
38
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
39
|
+
* @returns Promise<void>
|
|
40
|
+
*/
|
|
41
|
+
async deleteResourceAttributes(accountId, resource, attributeKeys, _appName, _callerActionIdentifier) {
|
|
42
|
+
// Validate resource object
|
|
43
|
+
if (!resource || typeof resource !== 'object') {
|
|
44
|
+
throw new ArgumentError('resource must be an object');
|
|
45
|
+
}
|
|
46
|
+
if (!resource.id) {
|
|
47
|
+
throw new ArgumentError('resource.id is required');
|
|
48
|
+
}
|
|
49
|
+
ValidationUtils.validateInteger(resource.id, 'resource.id');
|
|
50
|
+
ValidationUtils.validateString(resource.type, 'resource.type');
|
|
51
|
+
return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_RESOURCE_ATTRIBUTES_PATH, {
|
|
52
|
+
resourceType: resource.type,
|
|
53
|
+
resourceId: resource.id,
|
|
54
|
+
}, attributeKeys, 'resource', 'deleteResourceAttributesSync', { resource });
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates or updates entity attributes synchronously.
|
|
58
|
+
* @param accountId The account ID
|
|
59
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
60
|
+
* @returns Promise<void>
|
|
61
|
+
*/
|
|
62
|
+
async upsertEntityAttributes(accountId, entityAttributeAssignments, _appName, _callerActionIdentifier) {
|
|
63
|
+
return AuthorizationAttributesMsService.executeUpsertRequest(accountId, entityAttributeAssignments, UPSERT_ENTITY_ATTRIBUTES_PATH, 'entityAttributeAssignments', EntityAttributeAssignment, 'entity', 'upsertEntityAttributesSync');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Deletes specific attributes from an entity synchronously.
|
|
67
|
+
* @param accountId The account ID
|
|
68
|
+
* @param entityType The entity type
|
|
69
|
+
* @param entityId The entity ID
|
|
70
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
71
|
+
* @returns Promise<void>
|
|
72
|
+
*/
|
|
73
|
+
async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, _appName, _callerActionIdentifier) {
|
|
74
|
+
if (!entityType || typeof entityType !== 'string' || entityType.trim() === '') {
|
|
75
|
+
throw new ArgumentError(`entityType must be a non-empty string, got: ${entityType}`);
|
|
76
|
+
}
|
|
77
|
+
ValidationUtils.validateInteger(entityId, 'entityId');
|
|
78
|
+
return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_ENTITY_ATTRIBUTES_PATH, {
|
|
79
|
+
entityType,
|
|
80
|
+
entityId,
|
|
81
|
+
}, attributeKeys, 'entity', 'deleteEntityAttributesSync', { entityType, entityId });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Updates resource attributes (batch operations).
|
|
85
|
+
* Note: MS service does not support batch operations directly.
|
|
86
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
87
|
+
* @param accountId The account ID
|
|
88
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
89
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
90
|
+
* @param resourceAttributeOperations Array of operations to perform
|
|
91
|
+
* @returns Promise<ResourceAttributesOperation[]> Array of processed operations
|
|
92
|
+
*/
|
|
93
|
+
async updateResourceAttributes(accountId, _appName, _callerActionIdentifier, resourceAttributeOperations) {
|
|
94
|
+
const processedOperations = [];
|
|
95
|
+
for (const operation of resourceAttributeOperations) {
|
|
96
|
+
if (operation.operationType === AttributeOperation.UPSERT) {
|
|
97
|
+
if (!operation.resourceId) {
|
|
98
|
+
throw new ArgumentError('resourceId is required for upsert operation');
|
|
99
|
+
}
|
|
100
|
+
await this.upsertResourceAttributes(accountId, [
|
|
101
|
+
new ResourceAttributeAssignment(operation.resourceId, operation.resourceType, operation.key, operation.value || ''),
|
|
102
|
+
]);
|
|
103
|
+
processedOperations.push(operation);
|
|
104
|
+
}
|
|
105
|
+
else if (operation.operationType === AttributeOperation.DELETE) {
|
|
106
|
+
if (!operation.resourceId) {
|
|
107
|
+
throw new ArgumentError('resourceId is required for delete operation');
|
|
108
|
+
}
|
|
109
|
+
await this.deleteResourceAttributes(accountId, {
|
|
110
|
+
type: operation.resourceType,
|
|
111
|
+
id: operation.resourceId,
|
|
112
|
+
}, [operation.key]);
|
|
113
|
+
processedOperations.push(operation);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return processedOperations;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Updates entity attributes (batch operations).
|
|
120
|
+
* Note: MS service does not support batch operations directly.
|
|
121
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
122
|
+
* @param accountId The account ID
|
|
123
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
124
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
125
|
+
* @param entityAttributeOperations Array of operations to perform
|
|
126
|
+
* @returns Promise<EntityAttributesOperation[]> Array of processed operations
|
|
127
|
+
*/
|
|
128
|
+
async updateEntityAttributes(accountId, _appName, _callerActionIdentifier, entityAttributeOperations) {
|
|
129
|
+
const processedOperations = [];
|
|
130
|
+
for (const operation of entityAttributeOperations) {
|
|
131
|
+
if (operation.operationType === 'upsert') {
|
|
132
|
+
await this.upsertEntityAttributes(accountId, [
|
|
133
|
+
new EntityAttributeAssignment(operation.entityId, operation.entityType, operation.key, operation.value || ''),
|
|
134
|
+
]);
|
|
135
|
+
processedOperations.push(operation);
|
|
136
|
+
}
|
|
137
|
+
else if (operation.operationType === 'delete') {
|
|
138
|
+
await this.deleteEntityAttributes(accountId, operation.entityType, operation.entityId, [operation.key]);
|
|
139
|
+
processedOperations.push(operation);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return processedOperations;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Replaces path template parameters with actual values
|
|
146
|
+
* @param template Path template with placeholders like {accountId}
|
|
147
|
+
* @param params Object with parameter names and values
|
|
148
|
+
* @returns Path with all placeholders replaced
|
|
149
|
+
*/
|
|
150
|
+
static replacePathParams(template, params) {
|
|
151
|
+
let path = template;
|
|
152
|
+
for (const [key, value] of Object.entries(params)) {
|
|
153
|
+
path = path.replace(`{${key}}`, String(value));
|
|
154
|
+
}
|
|
155
|
+
return path;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Generic helper for executing delete requests
|
|
159
|
+
*/
|
|
160
|
+
static async executeDeleteRequest(accountId, pathTemplate, pathParams, keys, logPrefix, methodName, context = {}) {
|
|
161
|
+
// Validate inputs
|
|
162
|
+
ValidationUtils.validateInteger(accountId, 'accountId');
|
|
163
|
+
ValidationUtils.validateArray(keys, 'attributeKeys');
|
|
164
|
+
if (!keys.length) {
|
|
165
|
+
logger.warn({ tag: this.LOG_TAG, accountId, ...pathParams }, `${methodName} called with empty keys array`);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// Validate all keys are strings
|
|
169
|
+
ValidationUtils.validateStringArray(keys, 'attributeKeys');
|
|
170
|
+
// Build request body
|
|
171
|
+
const requestBody = {
|
|
172
|
+
keys,
|
|
173
|
+
};
|
|
174
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
175
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
176
|
+
}
|
|
177
|
+
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId, ...pathParams });
|
|
178
|
+
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
179
|
+
try {
|
|
180
|
+
logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Deleting ${logPrefix} attributes`);
|
|
181
|
+
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
182
|
+
url: {
|
|
183
|
+
appName: APP_NAME,
|
|
184
|
+
path,
|
|
185
|
+
},
|
|
186
|
+
method: 'DELETE',
|
|
187
|
+
headers,
|
|
188
|
+
body: JSON.stringify(requestBody),
|
|
189
|
+
}, {
|
|
190
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
191
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
192
|
+
});
|
|
193
|
+
logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Successfully deleted ${logPrefix} attributes`);
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
logger.error({
|
|
197
|
+
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
198
|
+
method: methodName,
|
|
199
|
+
accountId,
|
|
200
|
+
...pathParams,
|
|
201
|
+
...context,
|
|
202
|
+
error: err instanceof Error ? err.message : String(err),
|
|
203
|
+
}, `Failed in ${methodName}`);
|
|
204
|
+
throw err;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
209
|
+
*/
|
|
210
|
+
static getRequestHeaders(accountId, userId) {
|
|
211
|
+
const headers = {
|
|
212
|
+
'Content-Type': 'application/json',
|
|
213
|
+
};
|
|
214
|
+
// Generate Authorization token
|
|
215
|
+
const authToken = signAuthorizationHeader({
|
|
216
|
+
appName: INTERNAL_APP_NAME,
|
|
217
|
+
accountId,
|
|
218
|
+
userId,
|
|
219
|
+
});
|
|
220
|
+
headers.Authorization = authToken;
|
|
221
|
+
// Add attribution headers if available
|
|
222
|
+
const attributionHeaders = getAttributionsFromApi();
|
|
223
|
+
for (const key in attributionHeaders) {
|
|
224
|
+
if (Object.prototype.hasOwnProperty.call(attributionHeaders, key)) {
|
|
225
|
+
headers[key] = attributionHeaders[key];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// Add X-REQUEST-ID if available from context
|
|
229
|
+
try {
|
|
230
|
+
const tridentContext = Api.getPart('context');
|
|
231
|
+
if (tridentContext?.runtimeAttributions) {
|
|
232
|
+
const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
233
|
+
if (outgoingHeaders) {
|
|
234
|
+
const attributionHeadersMap = {};
|
|
235
|
+
for (const [key, value] of outgoingHeaders) {
|
|
236
|
+
attributionHeadersMap[key] = value;
|
|
237
|
+
}
|
|
238
|
+
if (attributionHeadersMap['x-request-id']) {
|
|
239
|
+
headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
// Silently fail if context is not available
|
|
246
|
+
logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, error }, 'Failed to get request ID from context');
|
|
247
|
+
}
|
|
248
|
+
// Add X-REQUEST-START timestamp
|
|
249
|
+
headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
|
|
250
|
+
return headers;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Validates that all messages are instances of the specified message class
|
|
254
|
+
*/
|
|
255
|
+
static validateMessages(attributesMessages, messageClass) {
|
|
256
|
+
// Validate messageClass is a function using Zod
|
|
257
|
+
const classSchema = z.custom(value => typeof value === 'function', {
|
|
258
|
+
message: 'messageClass must be a class/constructor function',
|
|
259
|
+
});
|
|
260
|
+
try {
|
|
261
|
+
classSchema.parse(messageClass);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (error instanceof z.ZodError) {
|
|
265
|
+
const firstError = error.issues[0];
|
|
266
|
+
throw new ArgumentError(firstError.message);
|
|
267
|
+
}
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
const className = messageClass.name || 'ResourceAttributeAssignment';
|
|
271
|
+
// First validate it's an array
|
|
272
|
+
ValidationUtils.validateArray(attributesMessages, 'attributesMessages');
|
|
273
|
+
// Then use Zod to validate each item is an instance of the class
|
|
274
|
+
const schema = z.array(z.any()).refine(items => {
|
|
275
|
+
for (let i = 0; i < items.length; i++) {
|
|
276
|
+
if (!(items[i] instanceof messageClass)) {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return true;
|
|
281
|
+
}, {
|
|
282
|
+
message: `All attributesMessages must be instances of ${className}`,
|
|
283
|
+
});
|
|
284
|
+
try {
|
|
285
|
+
schema.parse(attributesMessages);
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (error instanceof z.ZodError) {
|
|
289
|
+
// Find the first invalid index for a more specific error message
|
|
290
|
+
const invalidIndex = attributesMessages.findIndex(item => !(item instanceof messageClass));
|
|
291
|
+
if (invalidIndex !== -1) {
|
|
292
|
+
throw new ArgumentError(`All attributesMessages must be instances of ${className}, but item at index ${invalidIndex} is not`);
|
|
293
|
+
}
|
|
294
|
+
const firstError = error.issues[0];
|
|
295
|
+
throw new ArgumentError(firstError.message);
|
|
296
|
+
}
|
|
297
|
+
throw error;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Generic helper for executing upsert requests
|
|
302
|
+
*/
|
|
303
|
+
static async executeUpsertRequest(accountId, assignments, pathTemplate, requestBodyKey, assignmentClass, logPrefix, methodName) {
|
|
304
|
+
// Validate inputs
|
|
305
|
+
ValidationUtils.validateInteger(accountId, 'accountId');
|
|
306
|
+
ValidationUtils.validateArray(assignments, 'assignments');
|
|
307
|
+
if (!assignments.length) {
|
|
308
|
+
logger.warn({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId }, `${methodName} called with empty array`);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// Validate all assignments are instances of the correct class
|
|
312
|
+
AuthorizationAttributesMsService.validateMessages(assignments, assignmentClass);
|
|
313
|
+
const requestBody = requestBodyKey === 'resourceAttributeAssignments'
|
|
314
|
+
? { resourceAttributeAssignments: assignments }
|
|
315
|
+
: { entityAttributeAssignments: assignments };
|
|
316
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
317
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
318
|
+
}
|
|
319
|
+
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId });
|
|
320
|
+
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
321
|
+
try {
|
|
322
|
+
logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
|
|
323
|
+
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
324
|
+
url: {
|
|
325
|
+
appName: APP_NAME,
|
|
326
|
+
path,
|
|
327
|
+
},
|
|
328
|
+
method: 'POST',
|
|
329
|
+
headers,
|
|
330
|
+
body: JSON.stringify(requestBody),
|
|
331
|
+
}, {
|
|
332
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
333
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
334
|
+
});
|
|
335
|
+
logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
|
|
336
|
+
}
|
|
337
|
+
catch (err) {
|
|
338
|
+
logger.error({
|
|
339
|
+
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
340
|
+
method: methodName,
|
|
341
|
+
accountId,
|
|
342
|
+
error: err instanceof Error ? err.message : String(err),
|
|
343
|
+
}, `Failed in ${methodName}`);
|
|
344
|
+
throw err;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export { AuthorizationAttributesMsService };
|