@mondaydotcomorg/monday-authorization 3.5.1 → 3.5.2-feat-shaime-support-entity-attributes-4-ddec1d3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/authorization-attributes-ms-service.d.ts +88 -0
  2. package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
  3. package/dist/authorization-attributes-ms-service.js +290 -0
  4. package/dist/authorization-attributes-service.d.ts +25 -47
  5. package/dist/authorization-attributes-service.d.ts.map +1 -1
  6. package/dist/authorization-attributes-service.js +32 -171
  7. package/dist/authorization-attributes-sns-service.d.ts +91 -0
  8. package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
  9. package/dist/authorization-attributes-sns-service.js +217 -0
  10. package/dist/base-attribute-assignment.d.ts +20 -0
  11. package/dist/base-attribute-assignment.d.ts.map +1 -0
  12. package/dist/base-attribute-assignment.js +36 -0
  13. package/dist/constants/sns.d.ts +12 -2
  14. package/dist/constants/sns.d.ts.map +1 -1
  15. package/dist/constants/sns.js +22 -2
  16. package/dist/entity-attribute-assignment.d.ts +20 -0
  17. package/dist/entity-attribute-assignment.d.ts.map +1 -0
  18. package/dist/entity-attribute-assignment.js +32 -0
  19. package/dist/entity-attributes-constants.d.ts +7 -0
  20. package/dist/entity-attributes-constants.d.ts.map +1 -0
  21. package/dist/entity-attributes-constants.js +11 -0
  22. package/dist/errors/argument-error.d.ts +4 -0
  23. package/dist/errors/argument-error.d.ts.map +1 -0
  24. package/dist/errors/argument-error.js +11 -0
  25. package/dist/esm/authorization-attributes-ms-service.d.ts +88 -0
  26. package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
  27. package/dist/esm/authorization-attributes-ms-service.mjs +288 -0
  28. package/dist/esm/authorization-attributes-service.d.ts +25 -47
  29. package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
  30. package/dist/esm/authorization-attributes-service.mjs +32 -167
  31. package/dist/esm/authorization-attributes-sns-service.d.ts +91 -0
  32. package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
  33. package/dist/esm/authorization-attributes-sns-service.mjs +211 -0
  34. package/dist/esm/base-attribute-assignment.d.ts +20 -0
  35. package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
  36. package/dist/esm/base-attribute-assignment.mjs +30 -0
  37. package/dist/esm/constants/sns.d.ts +12 -2
  38. package/dist/esm/constants/sns.d.ts.map +1 -1
  39. package/dist/esm/constants/sns.mjs +17 -3
  40. package/dist/esm/entity-attribute-assignment.d.ts +20 -0
  41. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
  42. package/dist/esm/entity-attribute-assignment.mjs +30 -0
  43. package/dist/esm/entity-attributes-constants.d.ts +7 -0
  44. package/dist/esm/entity-attributes-constants.d.ts.map +1 -0
  45. package/dist/esm/entity-attributes-constants.mjs +9 -0
  46. package/dist/esm/errors/argument-error.d.ts +4 -0
  47. package/dist/esm/errors/argument-error.d.ts.map +1 -0
  48. package/dist/esm/errors/argument-error.mjs +9 -0
  49. package/dist/esm/resource-attribute-assignment.d.ts +20 -0
  50. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
  51. package/dist/esm/resource-attribute-assignment.mjs +30 -0
  52. package/dist/esm/resource-attributes-constants.d.ts +25 -0
  53. package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
  54. package/dist/esm/resource-attributes-constants.mjs +28 -0
  55. package/dist/esm/testKit/index.d.ts +4 -4
  56. package/dist/esm/testKit/index.d.ts.map +1 -1
  57. package/dist/esm/types/authorization-attributes-contracts.d.ts +26 -11
  58. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  59. package/dist/esm/types/authorization-attributes-contracts.mjs +6 -6
  60. package/dist/esm/types/authorization-attributes-service.interface.d.ts +57 -0
  61. package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -0
  62. package/dist/esm/types/authorization-attributes-service.interface.mjs +1 -0
  63. package/dist/esm/utils/validation.d.ts +45 -0
  64. package/dist/esm/utils/validation.d.ts.map +1 -0
  65. package/dist/esm/utils/validation.mjs +152 -0
  66. package/dist/resource-attribute-assignment.d.ts +20 -0
  67. package/dist/resource-attribute-assignment.d.ts.map +1 -0
  68. package/dist/resource-attribute-assignment.js +32 -0
  69. package/dist/resource-attributes-constants.d.ts +25 -0
  70. package/dist/resource-attributes-constants.d.ts.map +1 -0
  71. package/dist/resource-attributes-constants.js +31 -0
  72. package/dist/testKit/index.d.ts +4 -4
  73. package/dist/testKit/index.d.ts.map +1 -1
  74. package/dist/types/authorization-attributes-contracts.d.ts +26 -11
  75. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  76. package/dist/types/authorization-attributes-contracts.js +5 -5
  77. package/dist/types/authorization-attributes-service.interface.d.ts +57 -0
  78. package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -0
  79. package/dist/types/authorization-attributes-service.interface.js +1 -0
  80. package/dist/utils/validation.d.ts +45 -0
  81. package/dist/utils/validation.d.ts.map +1 -0
  82. package/dist/utils/validation.js +158 -0
  83. package/package.json +3 -1
  84. package/src/authorization-attributes-ms-service.ts +438 -0
  85. package/src/authorization-attributes-service.ts +34 -222
  86. package/src/authorization-attributes-sns-service.ts +312 -0
  87. package/src/base-attribute-assignment.ts +46 -0
  88. package/src/constants/sns.ts +19 -2
  89. package/src/entity-attribute-assignment.ts +30 -0
  90. package/src/entity-attributes-constants.ts +7 -0
  91. package/src/errors/argument-error.ts +7 -0
  92. package/src/resource-attribute-assignment.ts +38 -0
  93. package/src/resource-attributes-constants.ts +27 -0
  94. package/src/testKit/index.ts +5 -5
  95. package/src/types/authorization-attributes-contracts.ts +34 -11
  96. package/src/types/authorization-attributes-service.interface.ts +101 -0
  97. package/src/utils/validation.ts +171 -0
@@ -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,7 @@
1
+ export declare enum EntityType {
2
+ User = "user",
3
+ Team = "team",
4
+ Account = "account"
5
+ }
6
+ export declare const ENTITY_TYPES: readonly EntityType[];
7
+ //# sourceMappingURL=entity-attributes-constants.d.ts.map
@@ -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,4 @@
1
+ export declare class ArgumentError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ //# sourceMappingURL=argument-error.d.ts.map
@@ -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 };
@@ -1,54 +1,32 @@
1
- import { FetcherConfig, HttpClient } from '@mondaydotcomorg/trident-backend-api';
2
- import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
3
- import { ResourceAttributeAssignment, ResourceAttributeResponse, ResourceAttributesOperation } from './types/authorization-attributes-contracts';
4
- import { Resource } from './types/general';
1
+ import { AuthorizationAttributesService as IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
2
+ /**
3
+ * Main service class for managing resource and entity attributes.
4
+ * Provides access to both direct (MS) and SNS operations.
5
+ *
6
+ * @example
7
+ * const service = new AuthorizationAttributesService();
8
+ *
9
+ * // Use direct operations
10
+ * await service.direct().upsertResourceAttributes(accountId, assignments);
11
+ *
12
+ * // Use SNS operations
13
+ * await service.sns().upsertResourceAttributes(accountId, assignments, appName, actionId);
14
+ * ```
15
+ */
5
16
  export declare class AuthorizationAttributesService {
6
- private static LOG_TAG;
7
- private static API_PATHS;
8
- private httpClient;
9
- private fetchOptions;
10
- private snsArn;
17
+ private _directService;
18
+ private _snsService;
11
19
  /**
12
- * Public constructor to create the AuthorizationAttributesService instance.
13
- * @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
14
- * @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
20
+ * Gets the direct (MS) service instance.
21
+ * Initializes the service on first access (lazy initialization).
22
+ * @returns IAuthorizationAttributesService instance
15
23
  */
16
- constructor(httpClient?: HttpClient, fetchOptions?: RecursivePartial<FetcherConfig>);
24
+ direct(): IAuthorizationAttributesService;
17
25
  /**
18
- * Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
19
- * @param accountId
20
- * @param resourceAttributeAssignments - Array of resource (resourceType, resourceId) and attribute (key, value) pairs to upsert in the authorization MS.
21
- * e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
22
- * @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
26
+ * Gets the SNS service instance.
27
+ * Initializes the service on first access (lazy initialization).
28
+ * @returns IAuthorizationAttributesService instance
23
29
  */
24
- upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[]): Promise<ResourceAttributeResponse>;
25
- /**
26
- * Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
27
- * @param accountId
28
- * @param resource - The resource (resourceType, resourceId) to delete the attributes for.
29
- * @param attributeKeys - Array of attribute keys to delete for the resource.
30
- * @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
31
- */
32
- deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[]): Promise<ResourceAttributeResponse>;
33
- /**
34
- * Async function, this function only send the updates request to SNS and return before the change actually took place
35
- * @param accountId
36
- * @param appName - App name of the calling app
37
- * @param callerActionIdentifier - action identifier
38
- * @param resourceAttributeOperations - Array of operations to do on resource attributes.
39
- * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
40
- * */
41
- updateResourceAttributesAsync(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributesOperation[]): Promise<ResourceAttributesOperation[]>;
42
- private sendSingleSnsMessage;
43
- private static getSnsTopicArn;
44
- /**
45
- * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
46
- * This function can be used as health check for services that updating resource attributes in async is crucial.
47
- * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
48
- * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
49
- * However, this is the best we can do without actually push dummy messages to the SNS.
50
- * @return {Promise<boolean>} - true if succeeded
51
- */
52
- asyncResourceAttributesHealthCheck(): Promise<boolean>;
30
+ sns(): IAuthorizationAttributesService;
53
31
  }
54
32
  //# sourceMappingURL=authorization-attributes-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../../src/authorization-attributes-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAY3C,qBAAa,8BAA8B;IACzC,OAAO,CAAC,MAAM,CAAC,OAAO,CAA8B;IACpD,OAAO,CAAC,MAAM,CAAC,SAAS,CAGb;IACX,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACS,UAAU,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAqBnF;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,GAC1D,OAAO,CAAC,yBAAyB,CAAC;IA6BrC;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,yBAAyB,CAAC;IAkCrC;;;;;;;UAOM;IACA,6BAA6B,CACjC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,2BAA2B,EAAE,GACzD,OAAO,CAAC,2BAA2B,EAAE,CAAC;YAY3B,oBAAoB;IA4BlC,OAAO,CAAC,MAAM,CAAC,cAAc;IAW7B;;;;;;;OAOG;IACG,kCAAkC,IAAI,OAAO,CAAC,OAAO,CAAC;CAoB7D"}
1
+ {"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../../src/authorization-attributes-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,IAAI,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAEvI;;;;;;;;;;;;;GAaG;AACH,qBAAa,8BAA8B;IACzC,OAAO,CAAC,cAAc,CAAiD;IACvE,OAAO,CAAC,WAAW,CAAkD;IAErE;;;;OAIG;IACH,MAAM,IAAI,+BAA+B;IAOzC;;;;OAIG;IACH,GAAG,IAAI,+BAA+B;CAMvC"}