@mondaydotcomorg/monday-authorization 3.5.1-fix-authorize-profile-picker-7481de0 → 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/authorization-service.d.ts.map +1 -1
- package/dist/authorization-service.js +7 -34
- 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/authorization-service.d.ts.map +1 -1
- package/dist/esm/authorization-service.mjs +7 -34
- 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/authorization-service.ts +11 -71
- 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,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const utils_validation = require('./utils/validation.js');
|
|
4
|
+
const isEqual = require('lodash/isEqual.js');
|
|
5
|
+
|
|
6
|
+
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
7
|
+
|
|
8
|
+
const isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Base class for attribute assignments (Resource or Entity)
|
|
12
|
+
* Provides common validation and functionality
|
|
13
|
+
*/
|
|
14
|
+
class BaseAttributeAssignment {
|
|
15
|
+
id;
|
|
16
|
+
type;
|
|
17
|
+
attributeKey;
|
|
18
|
+
attributeValue;
|
|
19
|
+
constructor(id, type, attributeKey, attributeValue, validTypes, idFieldName, typeFieldName) {
|
|
20
|
+
const validated = utils_validation.ValidationUtils.validateAssignment({ id, type, attributeKey, attributeValue }, validTypes, { id: idFieldName, type: typeFieldName });
|
|
21
|
+
this.id = validated.id;
|
|
22
|
+
this.type = validated.type;
|
|
23
|
+
this.attributeKey = validated.attributeKey;
|
|
24
|
+
this.attributeValue = validated.attributeValue;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Compares two assignments for equality
|
|
28
|
+
* @param other Another assignment instance
|
|
29
|
+
* @returns true if all properties are equal
|
|
30
|
+
*/
|
|
31
|
+
equals(other) {
|
|
32
|
+
return isEqual__default.default(this, other);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
exports.BaseAttributeAssignment = BaseAttributeAssignment;
|
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,20 @@
|
|
|
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
|
+
toDataTransferObject(): {
|
|
8
|
+
entityId: number;
|
|
9
|
+
entityType: EntityType;
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Compares two assignments for equality
|
|
15
|
+
* @param other Another EntityAttributeAssignment instance
|
|
16
|
+
* @returns true if all properties are equal
|
|
17
|
+
*/
|
|
18
|
+
equals(other: EntityAttributeAssignment): boolean;
|
|
19
|
+
}
|
|
20
|
+
//# 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;IAM9F,oBAAoB;;;;;;IAQpB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO;CAGlD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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, entityAttributesConstants.ENTITY_TYPES, 'entityId', 'entityType');
|
|
11
|
+
this.entityId = entityId;
|
|
12
|
+
this.entityType = this.type;
|
|
13
|
+
}
|
|
14
|
+
toDataTransferObject() {
|
|
15
|
+
return {
|
|
16
|
+
entityId: this.entityId,
|
|
17
|
+
entityType: this.entityType,
|
|
18
|
+
key: this.attributeKey,
|
|
19
|
+
value: this.attributeValue,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compares two assignments for equality
|
|
24
|
+
* @param other Another EntityAttributeAssignment instance
|
|
25
|
+
* @returns true if all properties are equal
|
|
26
|
+
*/
|
|
27
|
+
equals(other) {
|
|
28
|
+
return super.equals(other);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
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,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED,eAAO,MAAM,YAAY,uBAA2C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
exports.EntityType = void 0;
|
|
4
|
+
(function (EntityType) {
|
|
5
|
+
EntityType["User"] = "user";
|
|
6
|
+
EntityType["Team"] = "team";
|
|
7
|
+
EntityType["Account"] = "account";
|
|
8
|
+
})(exports.EntityType || (exports.EntityType = {}));
|
|
9
|
+
const ENTITY_TYPES = Object.freeze(Object.values(exports.EntityType));
|
|
10
|
+
|
|
11
|
+
exports.ENTITY_TYPES = ENTITY_TYPES;
|
|
@@ -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,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,288 @@
|
|
|
1
|
+
import { Api } from '@mondaydotcomorg/trident-backend-api';
|
|
2
|
+
import { signAuthorizationHeader } from '@mondaydotcomorg/monday-jwt';
|
|
3
|
+
import { ResourceAttributeAssignment } from './resource-attribute-assignment.mjs';
|
|
4
|
+
import { EntityAttributeAssignment } from './entity-attribute-assignment.mjs';
|
|
5
|
+
import { AttributeOperation } from './types/authorization-attributes-contracts.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
|
+
|
|
12
|
+
const INTERNAL_APP_NAME = 'internal_ms';
|
|
13
|
+
const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
|
|
14
|
+
const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
|
|
15
|
+
const UPSERT_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity';
|
|
16
|
+
const DELETE_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity/{entityType}/{entityId}';
|
|
17
|
+
/**
|
|
18
|
+
* Service class for managing resource attributes in the authorization microservice.
|
|
19
|
+
* Provides synchronous HTTP operations to create/update and delete attributes on resources.
|
|
20
|
+
*/
|
|
21
|
+
class AuthorizationAttributesMsService {
|
|
22
|
+
static LOG_TAG = 'authorization_attributes_ms';
|
|
23
|
+
static httpClient = Api.getPart('httpClient') ?? null;
|
|
24
|
+
static destroyHttpClient() {
|
|
25
|
+
AuthorizationAttributesMsService.httpClient = null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates or updates resource attributes synchronously.
|
|
29
|
+
* @param accountId The account ID
|
|
30
|
+
* @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
|
|
31
|
+
* @returns Promise<void>
|
|
32
|
+
*/
|
|
33
|
+
async upsertResourceAttributes(accountId, resourceAttributeAssignments, _appName, _callerActionIdentifier) {
|
|
34
|
+
return AuthorizationAttributesMsService.executeUpsertRequest(accountId, resourceAttributeAssignments, UPSERT_RESOURCE_ATTRIBUTES_PATH, 'resourceAttributeAssignments', ResourceAttributeAssignment, 'resource', 'upsertResourceAttributes');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Deletes specific attributes from a resource synchronously.
|
|
38
|
+
* @param accountId The account ID
|
|
39
|
+
* @param resource Object with resourceType (string) and resourceId (number)
|
|
40
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
41
|
+
* @returns Promise<void>
|
|
42
|
+
*/
|
|
43
|
+
async deleteResourceAttributes(accountId, resource, attributeKeys, _appName, _callerActionIdentifier) {
|
|
44
|
+
ValidationUtils.validateResource(resource);
|
|
45
|
+
ValidationUtils.validateStringArray(attributeKeys);
|
|
46
|
+
return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_RESOURCE_ATTRIBUTES_PATH, {
|
|
47
|
+
resourceType: resource.type,
|
|
48
|
+
resourceId: resource.id,
|
|
49
|
+
}, attributeKeys, 'resource', 'deleteResourceAttributesSync', { resource });
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates or updates entity attributes synchronously.
|
|
53
|
+
* @param accountId The account ID
|
|
54
|
+
* @param entityAttributeAssignments Array of EntityAttributeAssignment objects
|
|
55
|
+
* @returns Promise<void>
|
|
56
|
+
*/
|
|
57
|
+
async upsertEntityAttributes(accountId, entityAttributeAssignments, _appName, _callerActionIdentifier) {
|
|
58
|
+
return AuthorizationAttributesMsService.executeUpsertRequest(accountId, entityAttributeAssignments, UPSERT_ENTITY_ATTRIBUTES_PATH, 'entityAttributeAssignments', EntityAttributeAssignment, 'entity', 'upsertEntityAttributesSync');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Deletes specific attributes from an entity synchronously.
|
|
62
|
+
* @param accountId The account ID
|
|
63
|
+
* @param entityType The entity type
|
|
64
|
+
* @param entityId The entity ID
|
|
65
|
+
* @param attributeKeys Array of attribute key strings to delete
|
|
66
|
+
* @returns Promise<void>
|
|
67
|
+
*/
|
|
68
|
+
async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, _appName, _callerActionIdentifier) {
|
|
69
|
+
if (!entityType || typeof entityType !== 'string' || entityType.trim() === '') {
|
|
70
|
+
throw new ArgumentError(`entityType must be a non-empty string, got: ${entityType}`);
|
|
71
|
+
}
|
|
72
|
+
ValidationUtils.validateInteger(entityId);
|
|
73
|
+
return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_ENTITY_ATTRIBUTES_PATH, {
|
|
74
|
+
entityType,
|
|
75
|
+
entityId,
|
|
76
|
+
}, attributeKeys, 'entity', 'deleteEntityAttributesSync', { entityType, entityId });
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Updates resource attributes (batch operations).
|
|
80
|
+
* Note: MS service does not support batch operations directly.
|
|
81
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
82
|
+
* @param accountId The account ID
|
|
83
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
84
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
85
|
+
* @param resourceAttributeOperations Array of operations to perform
|
|
86
|
+
* @returns Promise<ResourceAttributesOperation[]> Array of processed operations
|
|
87
|
+
*/
|
|
88
|
+
async updateResourceAttributes(accountId, _appName, _callerActionIdentifier, resourceAttributeOperations) {
|
|
89
|
+
const processedOperations = [];
|
|
90
|
+
for (const operation of resourceAttributeOperations) {
|
|
91
|
+
if (operation.operationType === AttributeOperation.UPSERT) {
|
|
92
|
+
if (!operation.resourceId) {
|
|
93
|
+
throw new ArgumentError('resourceId is required for upsert operation');
|
|
94
|
+
}
|
|
95
|
+
await this.upsertResourceAttributes(accountId, [
|
|
96
|
+
new ResourceAttributeAssignment(operation.resourceId, operation.resourceType, operation.key, operation.value || ''),
|
|
97
|
+
]);
|
|
98
|
+
processedOperations.push(operation);
|
|
99
|
+
}
|
|
100
|
+
else if (operation.operationType === AttributeOperation.DELETE) {
|
|
101
|
+
if (!operation.resourceId) {
|
|
102
|
+
throw new ArgumentError('resourceId is required for delete operation');
|
|
103
|
+
}
|
|
104
|
+
await this.deleteResourceAttributes(accountId, {
|
|
105
|
+
type: operation.resourceType,
|
|
106
|
+
id: operation.resourceId,
|
|
107
|
+
}, [operation.key]);
|
|
108
|
+
processedOperations.push(operation);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return processedOperations;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Updates entity attributes (batch operations).
|
|
115
|
+
* Note: MS service does not support batch operations directly.
|
|
116
|
+
* This method processes operations sequentially using upsert/delete methods.
|
|
117
|
+
* @param accountId The account ID
|
|
118
|
+
* @param appName App name (required for interface compatibility, but not used in MS service)
|
|
119
|
+
* @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
|
|
120
|
+
* @param entityAttributeOperations Array of operations to perform
|
|
121
|
+
* @returns Promise<EntityAttributesOperation[]> Array of processed operations
|
|
122
|
+
*/
|
|
123
|
+
async updateEntityAttributes(accountId, _appName, _callerActionIdentifier, entityAttributeOperations) {
|
|
124
|
+
const processedOperations = [];
|
|
125
|
+
for (const operation of entityAttributeOperations) {
|
|
126
|
+
if (operation.operationType === 'upsert') {
|
|
127
|
+
await this.upsertEntityAttributes(accountId, [
|
|
128
|
+
new EntityAttributeAssignment(operation.entityId, operation.entityType, operation.key, operation.value || ''),
|
|
129
|
+
]);
|
|
130
|
+
processedOperations.push(operation);
|
|
131
|
+
}
|
|
132
|
+
else if (operation.operationType === 'delete') {
|
|
133
|
+
await this.deleteEntityAttributes(accountId, operation.entityType, operation.entityId, [operation.key]);
|
|
134
|
+
processedOperations.push(operation);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return processedOperations;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Replaces path template parameters with actual values
|
|
141
|
+
* @param template Path template with placeholders like {accountId}
|
|
142
|
+
* @param params Object with parameter names and values
|
|
143
|
+
* @returns Path with all placeholders replaced
|
|
144
|
+
*/
|
|
145
|
+
static replacePathParams(template, params) {
|
|
146
|
+
let path = template;
|
|
147
|
+
for (const [key, value] of Object.entries(params)) {
|
|
148
|
+
path = path.replace(`{${key}}`, String(value));
|
|
149
|
+
}
|
|
150
|
+
return path;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Generic helper for executing delete requests
|
|
154
|
+
*/
|
|
155
|
+
static async executeDeleteRequest(accountId, pathTemplate, pathParams, keys, logPrefix, methodName, context = {}) {
|
|
156
|
+
// Validate inputs
|
|
157
|
+
ValidationUtils.validateInteger(accountId);
|
|
158
|
+
ValidationUtils.validateStringArray(keys);
|
|
159
|
+
if (!keys.length) {
|
|
160
|
+
logger.warn({ tag: this.LOG_TAG, accountId, ...pathParams }, `${methodName} called with empty keys array`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const requestBody = { keys };
|
|
164
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
165
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
166
|
+
}
|
|
167
|
+
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId, ...pathParams });
|
|
168
|
+
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
169
|
+
try {
|
|
170
|
+
logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Deleting ${logPrefix} attributes`);
|
|
171
|
+
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
172
|
+
url: {
|
|
173
|
+
appName: APP_NAME,
|
|
174
|
+
path,
|
|
175
|
+
},
|
|
176
|
+
method: 'DELETE',
|
|
177
|
+
headers,
|
|
178
|
+
body: JSON.stringify(requestBody),
|
|
179
|
+
}, {
|
|
180
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
181
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
182
|
+
});
|
|
183
|
+
logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Successfully deleted ${logPrefix} attributes`);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
logger.error({
|
|
187
|
+
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
188
|
+
method: methodName,
|
|
189
|
+
accountId,
|
|
190
|
+
...pathParams,
|
|
191
|
+
...context,
|
|
192
|
+
error: err instanceof Error ? err.message : String(err),
|
|
193
|
+
}, `Failed in ${methodName}`);
|
|
194
|
+
throw err;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Gets request headers including Authorization, Content-Type, and optional attribution headers
|
|
199
|
+
*/
|
|
200
|
+
static getRequestHeaders(accountId, userId) {
|
|
201
|
+
const headers = {
|
|
202
|
+
'Content-Type': 'application/json',
|
|
203
|
+
};
|
|
204
|
+
// Generate Authorization token
|
|
205
|
+
const authToken = signAuthorizationHeader({
|
|
206
|
+
appName: INTERNAL_APP_NAME,
|
|
207
|
+
accountId,
|
|
208
|
+
userId,
|
|
209
|
+
});
|
|
210
|
+
headers.Authorization = authToken;
|
|
211
|
+
// Add attribution headers if available
|
|
212
|
+
const attributionHeaders = getAttributionsFromApi();
|
|
213
|
+
for (const key in attributionHeaders) {
|
|
214
|
+
if (Object.prototype.hasOwnProperty.call(attributionHeaders, key)) {
|
|
215
|
+
headers[key] = attributionHeaders[key];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// Add X-REQUEST-ID if available from context
|
|
219
|
+
try {
|
|
220
|
+
const tridentContext = Api.getPart('context');
|
|
221
|
+
if (tridentContext?.runtimeAttributions) {
|
|
222
|
+
const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
|
|
223
|
+
if (outgoingHeaders) {
|
|
224
|
+
const attributionHeadersMap = {};
|
|
225
|
+
for (const [key, value] of outgoingHeaders) {
|
|
226
|
+
attributionHeadersMap[key] = value;
|
|
227
|
+
}
|
|
228
|
+
if (attributionHeadersMap['x-request-id']) {
|
|
229
|
+
headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
// Silently fail if context is not available
|
|
236
|
+
logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, error }, 'Failed to get request ID from context');
|
|
237
|
+
}
|
|
238
|
+
// Add X-REQUEST-START timestamp
|
|
239
|
+
headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
|
|
240
|
+
return headers;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Generic helper for executing upsert requests
|
|
244
|
+
*/
|
|
245
|
+
static async executeUpsertRequest(accountId, assignments, pathTemplate, requestBodyKey, assignmentClass, logPrefix, methodName) {
|
|
246
|
+
ValidationUtils.validateInteger(accountId);
|
|
247
|
+
ValidationUtils.validateArrayTypeOf(assignments, assignmentClass);
|
|
248
|
+
if (!assignments.length) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const assignmentDto = assignments.map(assignment => assignment.toDataTransferObject());
|
|
252
|
+
const requestBody = requestBodyKey === 'resourceAttributeAssignments'
|
|
253
|
+
? { resourceAttributeAssignments: assignmentDto }
|
|
254
|
+
: { entityAttributeAssignments: assignmentDto };
|
|
255
|
+
if (!AuthorizationAttributesMsService.httpClient) {
|
|
256
|
+
throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
|
|
257
|
+
}
|
|
258
|
+
const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId });
|
|
259
|
+
const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
|
|
260
|
+
try {
|
|
261
|
+
logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
|
|
262
|
+
await AuthorizationAttributesMsService.httpClient.fetch({
|
|
263
|
+
url: {
|
|
264
|
+
appName: APP_NAME,
|
|
265
|
+
path,
|
|
266
|
+
},
|
|
267
|
+
method: 'POST',
|
|
268
|
+
headers,
|
|
269
|
+
body: JSON.stringify(requestBody),
|
|
270
|
+
}, {
|
|
271
|
+
timeout: AuthorizationInternalService.getRequestTimeout(),
|
|
272
|
+
retryPolicy: AuthorizationInternalService.getRetriesPolicy(),
|
|
273
|
+
});
|
|
274
|
+
logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
logger.error({
|
|
278
|
+
tag: AuthorizationAttributesMsService.LOG_TAG,
|
|
279
|
+
method: methodName,
|
|
280
|
+
accountId,
|
|
281
|
+
error: err instanceof Error ? err.message : String(err),
|
|
282
|
+
}, `Failed in ${methodName}`);
|
|
283
|
+
throw err;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export { AuthorizationAttributesMsService };
|