@mondaydotcomorg/monday-authorization 3.5.1 → 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-e355942

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