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

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