@mondaydotcomorg/monday-authorization 3.5.0-upgrade-observability-kit-2ebbd01 → 3.5.1-feat-shaime-support-entity-attributes-in-authorization-sdk-59162a3
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/attributions-service.d.ts.map +1 -1
- package/dist/attributions-service.js +1 -0
- package/dist/authorization-attributes-ms-service.d.ts +67 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/authorization-attributes-ms-service.js +256 -0
- package/dist/authorization-attributes-sns-service.d.ts +85 -0
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/authorization-attributes-sns-service.js +203 -0
- 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/clients/graph-api.d.ts.map +1 -1
- package/dist/clients/graph-api.js +1 -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/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -0
- package/dist/entity-attribute-assignment.d.ts +24 -0
- package/dist/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/entity-attribute-assignment.js +36 -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/attributions-service.d.ts.map +1 -1
- package/dist/esm/attributions-service.mjs +1 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts +67 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-ms-service.mjs +254 -0
- package/dist/esm/authorization-attributes-sns-service.d.ts +85 -0
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-sns-service.mjs +197 -0
- 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/clients/graph-api.d.ts.map +1 -1
- package/dist/esm/clients/graph-api.mjs +2 -1
- 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/constants.d.ts +3 -0
- package/dist/esm/constants.d.ts.map +1 -1
- package/dist/esm/constants.mjs +5 -1
- package/dist/esm/entity-attribute-assignment.d.ts +24 -0
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/entity-attribute-assignment.mjs +34 -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 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +7 -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 +25 -0
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
- package/dist/esm/resource-attributes-constants.mjs +25 -0
- package/dist/esm/roles-service.d.ts +1 -1
- package/dist/esm/roles-service.mjs +1 -1
- package/dist/esm/types/authorization-attributes-contracts.d.ts +36 -4
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.mjs +6 -1
- package/dist/esm/utils/path-utils.d.ts +8 -0
- package/dist/esm/utils/path-utils.d.ts.map +1 -0
- package/dist/esm/utils/path-utils.mjs +15 -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 +75 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -2
- 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 +25 -0
- package/dist/resource-attributes-constants.d.ts.map +1 -0
- package/dist/resource-attributes-constants.js +28 -0
- package/dist/roles-service.d.ts +1 -1
- package/dist/roles-service.js +1 -1
- package/dist/types/authorization-attributes-contracts.d.ts +36 -4
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.js +5 -0
- package/dist/utils/path-utils.d.ts +8 -0
- package/dist/utils/path-utils.d.ts.map +1 -0
- package/dist/utils/path-utils.js +17 -0
- package/dist/utils/validation.d.ts +45 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +77 -0
- package/package.json +2 -2
- package/src/attributions-service.ts +4 -0
- package/src/authorization-attributes-ms-service.ts +400 -0
- package/src/authorization-attributes-sns-service.ts +290 -0
- package/src/base-attribute-assignment.ts +56 -0
- package/src/clients/graph-api.ts +2 -1
- package/src/constants/sns.ts +19 -2
- package/src/constants.ts +4 -0
- package/src/entity-attribute-assignment.ts +43 -0
- package/src/entity-attributes-constants.ts +7 -0
- package/src/errors/argument-error.ts +7 -0
- package/src/index.ts +18 -1
- package/src/resource-attribute-assignment.ts +43 -0
- package/src/resource-attributes-constants.ts +26 -0
- package/src/roles-service.ts +1 -1
- package/src/types/authorization-attributes-contracts.ts +56 -3
- package/src/utils/path-utils.ts +14 -0
- package/src/utils/validation.ts +84 -0
- package/dist/authorization-attributes-service.d.ts +0 -54
- package/dist/authorization-attributes-service.d.ts.map +0 -1
- package/dist/authorization-attributes-service.js +0 -186
- package/dist/esm/authorization-attributes-service.d.ts +0 -54
- package/dist/esm/authorization-attributes-service.d.ts.map +0 -1
- package/dist/esm/authorization-attributes-service.mjs +0 -180
- package/src/authorization-attributes-service.ts +0 -234
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const utils_validation = require('./utils/validation.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Base class for attribute assignments (Resource or Entity)
|
|
7
|
+
* Provides common validation and functionality
|
|
8
|
+
*/
|
|
9
|
+
class BaseAttributeAssignment {
|
|
10
|
+
id;
|
|
11
|
+
type;
|
|
12
|
+
attributeKey;
|
|
13
|
+
attributeValue;
|
|
14
|
+
constructor(id, type, attributeKey, attributeValue, validTypes, idFieldName, typeFieldName) {
|
|
15
|
+
// Validate id
|
|
16
|
+
utils_validation.ValidationUtils.validateInteger(id, idFieldName);
|
|
17
|
+
// Validate type
|
|
18
|
+
this.type = utils_validation.ValidationUtils.validateEnum(type, validTypes, typeFieldName);
|
|
19
|
+
// Validate attributeKey
|
|
20
|
+
utils_validation.ValidationUtils.validateString(attributeKey, 'attributeKey');
|
|
21
|
+
// Validate attributeValue
|
|
22
|
+
utils_validation.ValidationUtils.validateString(attributeValue, 'attributeValue');
|
|
23
|
+
this.id = id;
|
|
24
|
+
this.attributeKey = attributeKey;
|
|
25
|
+
this.attributeValue = attributeValue;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compares two assignments for equality
|
|
29
|
+
* @param other Another assignment instance
|
|
30
|
+
* @returns true if all properties are equal
|
|
31
|
+
*/
|
|
32
|
+
equals(other) {
|
|
33
|
+
if (!(other instanceof this.constructor)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return (this.id === other.id &&
|
|
37
|
+
this.type === other.type &&
|
|
38
|
+
this.attributeKey === other.attributeKey &&
|
|
39
|
+
this.attributeValue === other.attributeValue);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.BaseAttributeAssignment = BaseAttributeAssignment;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph-api.d.ts","sourceRoot":"","sources":["../../src/clients/graph-api.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,0BAA0B,EAG3B,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAEL,sBAAsB,EAMvB,MAAM,0BAA0B,CAAC;AAQlC;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;;IAezC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAyB/B;;OAEG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"graph-api.d.ts","sourceRoot":"","sources":["../../src/clients/graph-api.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,0BAA0B,EAG3B,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAEL,sBAAsB,EAMvB,MAAM,0BAA0B,CAAC;AAQlC;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;;IAezC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAyB/B;;OAEG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAiCzG;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAiC1B;;OAEG;IACG,gBAAgB,CACpB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,YAAY,EAAE,GAC5B,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAMxC,OAAO,CAAC,MAAM,CAAC,iBAAiB;CAWjC"}
|
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;
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
|
|
|
2
2
|
import { FetcherConfig } from '@mondaydotcomorg/trident-backend-api';
|
|
3
3
|
export declare const APP_NAME = "authorization";
|
|
4
4
|
export declare const GRAPH_APP_NAME = "authorization-graph";
|
|
5
|
+
export declare enum GraphApiProfile {
|
|
6
|
+
PERMISSION = "authorization-graph-permission"
|
|
7
|
+
}
|
|
5
8
|
export declare const ERROR_MESSAGES: {
|
|
6
9
|
readonly HTTP_CLIENT_NOT_INITIALIZED: "MondayAuthorization: HTTP client is not initialized";
|
|
7
10
|
readonly REQUEST_FAILED: (method: string, status: number, reason: string) => string;
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AACxC,eAAO,MAAM,cAAc,wBAAwB,CAAC;AAEpD,eAAO,MAAM,cAAc;;sCAEA,MAAM,UAAU,MAAM,UAAU,MAAM;CAEvD,CAAC;AAEX,eAAO,MAAM,qBAAqB,EAAE,gBAAgB,CAAC,aAAa,CAUjE,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AACxC,eAAO,MAAM,cAAc,wBAAwB,CAAC;AAEpD,oBAAY,eAAe;IACzB,UAAU,mCAAmC;CAC9C;AAED,eAAO,MAAM,cAAc;;sCAEA,MAAM,UAAU,MAAM,UAAU,MAAM;CAEvD,CAAC;AAEX,eAAO,MAAM,qBAAqB,EAAE,gBAAgB,CAAC,aAAa,CAUjE,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -2,6 +2,10 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const APP_NAME = 'authorization';
|
|
4
4
|
const GRAPH_APP_NAME = 'authorization-graph';
|
|
5
|
+
exports.GraphApiProfile = void 0;
|
|
6
|
+
(function (GraphApiProfile) {
|
|
7
|
+
GraphApiProfile["PERMISSION"] = "authorization-graph-permission";
|
|
8
|
+
})(exports.GraphApiProfile || (exports.GraphApiProfile = {}));
|
|
5
9
|
const ERROR_MESSAGES = {
|
|
6
10
|
HTTP_CLIENT_NOT_INITIALIZED: 'MondayAuthorization: HTTP client is not initialized',
|
|
7
11
|
REQUEST_FAILED: (method, status, reason) => `MondayAuthorization: [${method}] request failed with status ${status} with reason: ${reason}`,
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
* Converts the assignment to hash format with camelCase keys
|
|
9
|
+
* @returns Object with camelCase keys: { entityId, entityType, key, value }
|
|
10
|
+
*/
|
|
11
|
+
toH(): {
|
|
12
|
+
entityId: number;
|
|
13
|
+
entityType: string;
|
|
14
|
+
key: string;
|
|
15
|
+
value: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Compares two assignments for equality
|
|
19
|
+
* @param other Another EntityAttributeAssignment instance
|
|
20
|
+
* @returns true if all properties are equal
|
|
21
|
+
*/
|
|
22
|
+
equals(other: EntityAttributeAssignment): boolean;
|
|
23
|
+
}
|
|
24
|
+
//# 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;IAc9F;;;OAGG;IACH,GAAG,IAAI;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAS3E;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO;CAGlD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
* Converts the assignment to hash format with camelCase keys
|
|
16
|
+
* @returns Object with camelCase keys: { entityId, entityType, key, value }
|
|
17
|
+
*/
|
|
18
|
+
toH() {
|
|
19
|
+
return {
|
|
20
|
+
entityId: this.entityId,
|
|
21
|
+
entityType: this.entityType,
|
|
22
|
+
key: this.attributeKey,
|
|
23
|
+
value: this.attributeValue,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compares two assignments for equality
|
|
28
|
+
* @param other Another EntityAttributeAssignment instance
|
|
29
|
+
* @returns true if all properties are equal
|
|
30
|
+
*/
|
|
31
|
+
equals(other) {
|
|
32
|
+
return super.equals(other);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributions-service.d.ts","sourceRoot":"","sources":["../../src/attributions-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAStF,oBAAY,eAAe;IACzB,YAAY,iBAAiB;IAC7B,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,GAAG,QAAQ;CACZ;AAED,wBAAgB,UAAU,mFAiBzB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAEtE;AAED,wBAAgB,sBAAsB,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"attributions-service.d.ts","sourceRoot":"","sources":["../../src/attributions-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAStF,oBAAY,eAAe;IACzB,YAAY,iBAAiB;IAC7B,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,GAAG,QAAQ;CACZ;AAED,wBAAgB,UAAU,mFAiBzB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAEtE;AAED,wBAAgB,sBAAsB,IAAI;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAyClE"}
|
|
@@ -44,6 +44,7 @@ function getAttributionsFromApi() {
|
|
|
44
44
|
const { runtimeAttributions } = tridentContext;
|
|
45
45
|
const runtimeAttributionsOutgoingHeaders = runtimeAttributions?.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
46
46
|
if (!runtimeAttributionsOutgoingHeaders) {
|
|
47
|
+
logger.info({ tag: 'authorization-service', runtimeAttributionsOutgoingHeaders }, 'No runtime attributions outgoing headers');
|
|
47
48
|
return callerAppNameFromSdk;
|
|
48
49
|
}
|
|
49
50
|
const attributionsHeaders = Object.fromEntries(runtimeAttributionsOutgoingHeaders);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
2
|
+
import { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
3
|
+
import { EntityType, EntityAttributeKeyType } from './types/authorization-attributes-contracts';
|
|
4
|
+
interface Resource {
|
|
5
|
+
resourceType: string;
|
|
6
|
+
resourceId: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
10
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
11
|
+
*/
|
|
12
|
+
export declare class AuthorizationAttributesMsService {
|
|
13
|
+
private static LOG_TAG;
|
|
14
|
+
/**
|
|
15
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
16
|
+
*/
|
|
17
|
+
private static getRequestHeaders;
|
|
18
|
+
/**
|
|
19
|
+
* Validates that all messages are instances of the specified message class
|
|
20
|
+
*/
|
|
21
|
+
private static validateMessages;
|
|
22
|
+
/**
|
|
23
|
+
* Handles request errors with consistent logging and error formatting
|
|
24
|
+
*/
|
|
25
|
+
private static handleRequestError;
|
|
26
|
+
/**
|
|
27
|
+
* Generic helper for executing upsert requests
|
|
28
|
+
*/
|
|
29
|
+
private static executeUpsertRequest;
|
|
30
|
+
/**
|
|
31
|
+
* Generic helper for executing delete requests
|
|
32
|
+
*/
|
|
33
|
+
private static executeDeleteRequest;
|
|
34
|
+
/**
|
|
35
|
+
* Creates or updates resource attributes synchronously.
|
|
36
|
+
* @param accountId The account ID
|
|
37
|
+
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
38
|
+
* @returns Promise<void>
|
|
39
|
+
*/
|
|
40
|
+
static upsertResourceAttributesSync(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[]): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Deletes specific attributes from a resource synchronously.
|
|
43
|
+
* @param accountId The account ID
|
|
44
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
45
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
46
|
+
* @returns Promise<void>
|
|
47
|
+
*/
|
|
48
|
+
static deleteResourceAttributesSync(accountId: number, resource: Resource, attributeKeys: string[]): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Creates or updates entity attributes synchronously.
|
|
51
|
+
* @param accountId The account ID
|
|
52
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
53
|
+
* @returns Promise<void>
|
|
54
|
+
*/
|
|
55
|
+
static upsertEntityAttributesSync(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[]): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Deletes specific attributes from an entity synchronously.
|
|
58
|
+
* @param accountId The account ID
|
|
59
|
+
* @param entityType The entity type
|
|
60
|
+
* @param entityId The entity ID
|
|
61
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
62
|
+
* @returns Promise<void>
|
|
63
|
+
*/
|
|
64
|
+
static deleteEntityAttributesSync(accountId: number, entityType: EntityType, entityId: number, attributeKeys: EntityAttributeKeyType[]): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
67
|
+
//# 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,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC;AAchG,UAAU,QAAQ;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAwBD;;;GAGG;AACH,qBAAa,gCAAgC;IAC3C,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IAEvD;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA+ChC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAiB/B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAmBjC;;OAEG;mBACkB,oBAAoB;IA0EzC;;OAEG;mBACkB,oBAAoB;IAmEzC;;;;;OAKG;WACU,4BAA4B,CACvC,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,GAC1D,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;OAMG;WACU,4BAA4B,CACvC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,IAAI,CAAC;IAsBhB;;;;;OAKG;WACU,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,GACtD,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;OAOG;WACU,0BAA0B,CACrC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,sBAAsB,EAAE,GACtC,OAAO,CAAC,IAAI,CAAC;CAmBjB"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { Api } 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.mjs';
|
|
5
|
+
import { EntityAttributeAssignment } from './entity-attribute-assignment.mjs';
|
|
6
|
+
import { ArgumentError } from './errors/argument-error.mjs';
|
|
7
|
+
import { logger, AuthorizationInternalService } from './authorization-internal-service.mjs';
|
|
8
|
+
import { getAttributionsFromApi } from './attributions-service.mjs';
|
|
9
|
+
import { APP_NAME } from './constants.mjs';
|
|
10
|
+
import { ValidationUtils } from './utils/validation.mjs';
|
|
11
|
+
import { replacePathParams } from './utils/path-utils.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
|
+
/**
|
|
25
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
26
|
+
*/
|
|
27
|
+
static getRequestHeaders(accountId, userId) {
|
|
28
|
+
const headers = {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
};
|
|
31
|
+
// Generate Authorization token
|
|
32
|
+
const authToken = signAuthorizationHeader({
|
|
33
|
+
appName: INTERNAL_APP_NAME,
|
|
34
|
+
accountId,
|
|
35
|
+
userId,
|
|
36
|
+
});
|
|
37
|
+
headers.Authorization = authToken;
|
|
38
|
+
// Add attribution headers if available
|
|
39
|
+
const attributionHeaders = getAttributionsFromApi();
|
|
40
|
+
for (const key in attributionHeaders) {
|
|
41
|
+
if (Object.prototype.hasOwnProperty.call(attributionHeaders, key)) {
|
|
42
|
+
headers[key] = attributionHeaders[key];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Add X-REQUEST-ID if available from context
|
|
46
|
+
try {
|
|
47
|
+
const tridentContext = Api.getPart('context');
|
|
48
|
+
if (tridentContext?.runtimeAttributions) {
|
|
49
|
+
const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
50
|
+
if (outgoingHeaders) {
|
|
51
|
+
const attributionHeadersMap = {};
|
|
52
|
+
for (const [key, value] of outgoingHeaders) {
|
|
53
|
+
attributionHeadersMap[key] = value;
|
|
54
|
+
}
|
|
55
|
+
if (attributionHeadersMap['x-request-id']) {
|
|
56
|
+
headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
// Silently fail if context is not available
|
|
63
|
+
logger.debug({ tag: this.LOG_TAG, error }, 'Failed to get request ID from context');
|
|
64
|
+
}
|
|
65
|
+
// Add X-REQUEST-START timestamp
|
|
66
|
+
headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
|
|
67
|
+
return headers;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Validates that all messages are instances of the specified message class
|
|
71
|
+
*/
|
|
72
|
+
static validateMessages(attributesMessages, messageClass) {
|
|
73
|
+
if (typeof messageClass !== 'function') {
|
|
74
|
+
throw new ArgumentError('messageClass must be a class/constructor function');
|
|
75
|
+
}
|
|
76
|
+
ValidationUtils.validateArray(attributesMessages, 'attributesMessages');
|
|
77
|
+
for (let i = 0; i < attributesMessages.length; i++) {
|
|
78
|
+
if (!(attributesMessages[i] instanceof messageClass)) {
|
|
79
|
+
const className = messageClass.name || 'ResourceAttributeAssignment';
|
|
80
|
+
throw new ArgumentError(`All attributesMessages must be instances of ${className}, but item at index ${i} is not`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Handles request errors with consistent logging and error formatting
|
|
86
|
+
*/
|
|
87
|
+
static handleRequestError(err, methodName, context) {
|
|
88
|
+
logger.error({
|
|
89
|
+
tag: this.LOG_TAG,
|
|
90
|
+
method: methodName,
|
|
91
|
+
...context,
|
|
92
|
+
error: err instanceof Error ? err.message : String(err),
|
|
93
|
+
}, `Failed in ${methodName}`);
|
|
94
|
+
if (err instanceof HttpFetcherError) {
|
|
95
|
+
throw new Error(`AuthorizationAttributesMsService: [${methodName}] request failed with status ${err.status}: ${err.message}`);
|
|
96
|
+
}
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generic helper for executing upsert requests
|
|
101
|
+
*/
|
|
102
|
+
static async executeUpsertRequest(accountId, assignments, pathTemplate, requestBodyKey, assignmentClass, logPrefix, methodName) {
|
|
103
|
+
// Skip HTTP requests in test environment
|
|
104
|
+
if (process.env.NODE_ENV === 'test') {
|
|
105
|
+
logger.debug({ tag: this.LOG_TAG, accountId, count: assignments.length }, `Skipping ${methodName} in test environment`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
// Validate inputs
|
|
109
|
+
ValidationUtils.validateInteger(accountId, 'accountId');
|
|
110
|
+
ValidationUtils.validateArray(assignments, 'assignments');
|
|
111
|
+
if (assignments.length === 0) {
|
|
112
|
+
logger.warn({ tag: this.LOG_TAG, accountId }, `${methodName} called with empty array`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
// Validate all assignments are instances of the correct class
|
|
116
|
+
this.validateMessages(assignments, assignmentClass);
|
|
117
|
+
// Convert assignments to hash format
|
|
118
|
+
const assignmentsHash = assignments.map(assignment => assignment.toH());
|
|
119
|
+
// Build request body
|
|
120
|
+
const requestBody = requestBodyKey === 'resourceAttributeAssignments'
|
|
121
|
+
? { resourceAttributeAssignments: assignmentsHash }
|
|
122
|
+
: { entityAttributeAssignments: assignmentsHash };
|
|
123
|
+
const httpClient = Api.getPart('httpClient');
|
|
124
|
+
if (!httpClient) {
|
|
125
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
126
|
+
}
|
|
127
|
+
const path = replacePathParams(pathTemplate, { accountId });
|
|
128
|
+
const headers = this.getRequestHeaders(accountId);
|
|
129
|
+
try {
|
|
130
|
+
logger.info({ tag: this.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
|
|
131
|
+
await httpClient.fetch({
|
|
132
|
+
url: {
|
|
133
|
+
appName: APP_NAME,
|
|
134
|
+
path,
|
|
135
|
+
},
|
|
136
|
+
method: 'POST',
|
|
137
|
+
headers,
|
|
138
|
+
body: JSON.stringify(requestBody),
|
|
139
|
+
}, {
|
|
140
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
141
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
142
|
+
});
|
|
143
|
+
logger.info({ tag: this.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
this.handleRequestError(err, methodName, { accountId });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Generic helper for executing delete requests
|
|
151
|
+
*/
|
|
152
|
+
static async executeDeleteRequest(accountId, pathTemplate, pathParams, keys, logPrefix, methodName, context = {}) {
|
|
153
|
+
// Skip HTTP requests in test environment
|
|
154
|
+
if (process.env.NODE_ENV === 'test') {
|
|
155
|
+
logger.debug({ tag: this.LOG_TAG, accountId, ...pathParams, keys }, `Skipping ${methodName} in test environment`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// Validate inputs
|
|
159
|
+
ValidationUtils.validateInteger(accountId, 'accountId');
|
|
160
|
+
ValidationUtils.validateArray(keys, 'attributeKeys');
|
|
161
|
+
if (keys.length === 0) {
|
|
162
|
+
logger.warn({ tag: this.LOG_TAG, accountId, ...pathParams }, `${methodName} called with empty keys array`);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// Validate all keys are strings
|
|
166
|
+
ValidationUtils.validateStringArray(keys, 'attributeKeys');
|
|
167
|
+
// Build request body
|
|
168
|
+
const requestBody = {
|
|
169
|
+
keys,
|
|
170
|
+
};
|
|
171
|
+
const httpClient = Api.getPart('httpClient');
|
|
172
|
+
if (!httpClient) {
|
|
173
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
174
|
+
}
|
|
175
|
+
const path = replacePathParams(pathTemplate, { accountId, ...pathParams });
|
|
176
|
+
const headers = this.getRequestHeaders(accountId);
|
|
177
|
+
try {
|
|
178
|
+
logger.info({ tag: this.LOG_TAG, accountId, ...pathParams, keys }, `Deleting ${logPrefix} attributes`);
|
|
179
|
+
await httpClient.fetch({
|
|
180
|
+
url: {
|
|
181
|
+
appName: APP_NAME,
|
|
182
|
+
path,
|
|
183
|
+
},
|
|
184
|
+
method: 'DELETE',
|
|
185
|
+
headers,
|
|
186
|
+
body: JSON.stringify(requestBody),
|
|
187
|
+
}, {
|
|
188
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
189
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
190
|
+
});
|
|
191
|
+
logger.info({ tag: this.LOG_TAG, accountId, ...pathParams, keys }, `Successfully deleted ${logPrefix} attributes`);
|
|
192
|
+
}
|
|
193
|
+
catch (err) {
|
|
194
|
+
this.handleRequestError(err, methodName, { accountId, ...pathParams, ...context });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Creates or updates resource attributes synchronously.
|
|
199
|
+
* @param accountId The account ID
|
|
200
|
+
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
201
|
+
* @returns Promise<void>
|
|
202
|
+
*/
|
|
203
|
+
static async upsertResourceAttributesSync(accountId, resourceAttributeAssignments) {
|
|
204
|
+
return this.executeUpsertRequest(accountId, resourceAttributeAssignments, UPSERT_RESOURCE_ATTRIBUTES_PATH, 'resourceAttributeAssignments', ResourceAttributeAssignment, 'resource', 'upsertResourceAttributesSync');
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Deletes specific attributes from a resource synchronously.
|
|
208
|
+
* @param accountId The account ID
|
|
209
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
210
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
211
|
+
* @returns Promise<void>
|
|
212
|
+
*/
|
|
213
|
+
static async deleteResourceAttributesSync(accountId, resource, attributeKeys) {
|
|
214
|
+
// Validate resource object
|
|
215
|
+
if (!resource || typeof resource !== 'object') {
|
|
216
|
+
throw new ArgumentError('resource must be an object');
|
|
217
|
+
}
|
|
218
|
+
ValidationUtils.validateInteger(resource.resourceId, 'resource.resourceId');
|
|
219
|
+
ValidationUtils.validateString(resource.resourceType, 'resource.resourceType');
|
|
220
|
+
return this.executeDeleteRequest(accountId, DELETE_RESOURCE_ATTRIBUTES_PATH, {
|
|
221
|
+
resourceType: resource.resourceType,
|
|
222
|
+
resourceId: resource.resourceId,
|
|
223
|
+
}, attributeKeys, 'resource', 'deleteResourceAttributesSync', { resource });
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Creates or updates entity attributes synchronously.
|
|
227
|
+
* @param accountId The account ID
|
|
228
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
229
|
+
* @returns Promise<void>
|
|
230
|
+
*/
|
|
231
|
+
static async upsertEntityAttributesSync(accountId, entityAttributeAssignments) {
|
|
232
|
+
return this.executeUpsertRequest(accountId, entityAttributeAssignments, UPSERT_ENTITY_ATTRIBUTES_PATH, 'entityAttributeAssignments', EntityAttributeAssignment, 'entity', 'upsertEntityAttributesSync');
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Deletes specific attributes from an entity synchronously.
|
|
236
|
+
* @param accountId The account ID
|
|
237
|
+
* @param entityType The entity type
|
|
238
|
+
* @param entityId The entity ID
|
|
239
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
240
|
+
* @returns Promise<void>
|
|
241
|
+
*/
|
|
242
|
+
static async deleteEntityAttributesSync(accountId, entityType, entityId, attributeKeys) {
|
|
243
|
+
if (!entityType || typeof entityType !== 'string' || entityType.trim() === '') {
|
|
244
|
+
throw new ArgumentError(`entityType must be a non-empty string, got: ${entityType}`);
|
|
245
|
+
}
|
|
246
|
+
ValidationUtils.validateInteger(entityId, 'entityId');
|
|
247
|
+
return this.executeDeleteRequest(accountId, DELETE_ENTITY_ATTRIBUTES_PATH, {
|
|
248
|
+
entityType,
|
|
249
|
+
entityId,
|
|
250
|
+
}, attributeKeys, 'entity', 'deleteEntityAttributesSync', { entityType, entityId });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { AuthorizationAttributesMsService };
|