@mondaydotcomorg/monday-authorization 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-ade64f6 → 3.6.0-feat-shaime-support-entity-attributes-1-4c8e283

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 (125) hide show
  1. package/dist/authorization-attributes-service.d.ts +47 -26
  2. package/dist/authorization-attributes-service.d.ts.map +1 -1
  3. package/dist/authorization-attributes-service.js +172 -33
  4. package/dist/authorization-middleware.d.ts +2 -2
  5. package/dist/authorization-middleware.d.ts.map +1 -1
  6. package/dist/authorization-service.d.ts +3 -3
  7. package/dist/authorization-service.d.ts.map +1 -1
  8. package/dist/base-attribute-assignment.d.ts +6 -5
  9. package/dist/base-attribute-assignment.d.ts.map +1 -1
  10. package/dist/base-attribute-assignment.js +8 -17
  11. package/dist/constants/sns.d.ts +2 -12
  12. package/dist/constants/sns.d.ts.map +1 -1
  13. package/dist/constants/sns.js +2 -22
  14. package/dist/entity-attribute-assignment.d.ts +4 -2
  15. package/dist/entity-attribute-assignment.d.ts.map +1 -1
  16. package/dist/entity-attribute-assignment.js +13 -4
  17. package/dist/entity-attributes-constants.d.ts +6 -6
  18. package/dist/entity-attributes-constants.d.ts.map +1 -1
  19. package/dist/entity-attributes-constants.js +7 -5
  20. package/dist/errors/argument-error.d.ts.map +1 -1
  21. package/dist/errors/argument-error.js +0 -1
  22. package/dist/esm/authorization-attributes-service.d.ts +47 -26
  23. package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
  24. package/dist/esm/authorization-attributes-service.mjs +168 -33
  25. package/dist/esm/authorization-middleware.d.ts +2 -2
  26. package/dist/esm/authorization-middleware.d.ts.map +1 -1
  27. package/dist/esm/authorization-service.d.ts +3 -3
  28. package/dist/esm/authorization-service.d.ts.map +1 -1
  29. package/dist/esm/base-attribute-assignment.d.ts +6 -5
  30. package/dist/esm/base-attribute-assignment.d.ts.map +1 -1
  31. package/dist/esm/base-attribute-assignment.mjs +4 -17
  32. package/dist/esm/constants/sns.d.ts +2 -12
  33. package/dist/esm/constants/sns.d.ts.map +1 -1
  34. package/dist/esm/constants/sns.mjs +3 -17
  35. package/dist/esm/entity-attribute-assignment.d.ts +4 -2
  36. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
  37. package/dist/esm/entity-attribute-assignment.mjs +13 -4
  38. package/dist/esm/entity-attributes-constants.d.ts +6 -6
  39. package/dist/esm/entity-attributes-constants.d.ts.map +1 -1
  40. package/dist/esm/entity-attributes-constants.mjs +8 -6
  41. package/dist/esm/errors/argument-error.d.ts.map +1 -1
  42. package/dist/esm/errors/argument-error.mjs +0 -1
  43. package/dist/esm/index.d.ts +0 -9
  44. package/dist/esm/index.d.ts.map +1 -1
  45. package/dist/esm/index.mjs +0 -7
  46. package/dist/esm/prometheus-service.d.ts +2 -1
  47. package/dist/esm/prometheus-service.d.ts.map +1 -1
  48. package/dist/esm/resource-attribute-assignment.d.ts +4 -2
  49. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
  50. package/dist/esm/resource-attribute-assignment.mjs +11 -2
  51. package/dist/esm/resource-attributes-constants.d.ts +21 -11
  52. package/dist/esm/resource-attributes-constants.d.ts.map +1 -1
  53. package/dist/esm/resource-attributes-constants.mjs +17 -14
  54. package/dist/esm/testKit/index.d.ts +4 -4
  55. package/dist/esm/testKit/index.d.ts.map +1 -1
  56. package/dist/esm/types/authorization-attributes-contracts.d.ts +5 -4
  57. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  58. package/dist/esm/types/authorization-attributes-service.interface.d.ts +7 -20
  59. package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -1
  60. package/dist/esm/types/general.d.ts +2 -1
  61. package/dist/esm/types/general.d.ts.map +1 -1
  62. package/dist/esm/utils/assigment-schema.d.ts +29 -0
  63. package/dist/esm/utils/assigment-schema.d.ts.map +1 -0
  64. package/dist/esm/utils/assigment-schema.mjs +29 -0
  65. package/dist/esm/utils/validation.d.ts +13 -38
  66. package/dist/esm/utils/validation.d.ts.map +1 -1
  67. package/dist/esm/utils/validation.mjs +38 -97
  68. package/dist/index.d.ts +0 -9
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +0 -15
  71. package/dist/prometheus-service.d.ts +2 -1
  72. package/dist/prometheus-service.d.ts.map +1 -1
  73. package/dist/resource-attribute-assignment.d.ts +4 -2
  74. package/dist/resource-attribute-assignment.d.ts.map +1 -1
  75. package/dist/resource-attribute-assignment.js +11 -2
  76. package/dist/resource-attributes-constants.d.ts +21 -11
  77. package/dist/resource-attributes-constants.d.ts.map +1 -1
  78. package/dist/resource-attributes-constants.js +16 -13
  79. package/dist/testKit/index.d.ts +4 -4
  80. package/dist/testKit/index.d.ts.map +1 -1
  81. package/dist/types/authorization-attributes-contracts.d.ts +5 -4
  82. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  83. package/dist/types/authorization-attributes-service.interface.d.ts +7 -20
  84. package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -1
  85. package/dist/types/general.d.ts +2 -1
  86. package/dist/types/general.d.ts.map +1 -1
  87. package/dist/utils/assigment-schema.d.ts +29 -0
  88. package/dist/utils/assigment-schema.d.ts.map +1 -0
  89. package/dist/utils/assigment-schema.js +36 -0
  90. package/dist/utils/validation.d.ts +13 -38
  91. package/dist/utils/validation.d.ts.map +1 -1
  92. package/dist/utils/validation.js +42 -97
  93. package/package.json +3 -3
  94. package/src/authorization-attributes-service.ts +223 -35
  95. package/src/authorization-middleware.ts +2 -2
  96. package/src/authorization-service.ts +4 -4
  97. package/src/base-attribute-assignment.ts +10 -35
  98. package/src/constants/sns.ts +2 -19
  99. package/src/entity-attribute-assignment.ts +17 -5
  100. package/src/entity-attributes-constants.ts +6 -6
  101. package/src/errors/argument-error.ts +0 -1
  102. package/src/index.ts +0 -9
  103. package/src/prometheus-service.ts +3 -1
  104. package/src/resource-attribute-assignment.ts +19 -12
  105. package/src/resource-attributes-constants.ts +15 -23
  106. package/src/testKit/index.ts +5 -5
  107. package/src/types/authorization-attributes-contracts.ts +5 -5
  108. package/src/types/authorization-attributes-service.interface.ts +12 -38
  109. package/src/types/general.ts +2 -3
  110. package/src/utils/assigment-schema.ts +29 -0
  111. package/src/utils/validation.ts +41 -92
  112. package/dist/authorization-attributes-ms-service.d.ts +0 -90
  113. package/dist/authorization-attributes-ms-service.d.ts.map +0 -1
  114. package/dist/authorization-attributes-ms-service.js +0 -369
  115. package/dist/authorization-attributes-sns-service.d.ts +0 -90
  116. package/dist/authorization-attributes-sns-service.d.ts.map +0 -1
  117. package/dist/authorization-attributes-sns-service.js +0 -217
  118. package/dist/esm/authorization-attributes-ms-service.d.ts +0 -90
  119. package/dist/esm/authorization-attributes-ms-service.d.ts.map +0 -1
  120. package/dist/esm/authorization-attributes-ms-service.mjs +0 -367
  121. package/dist/esm/authorization-attributes-sns-service.d.ts +0 -90
  122. package/dist/esm/authorization-attributes-sns-service.d.ts.map +0 -1
  123. package/dist/esm/authorization-attributes-sns-service.mjs +0 -211
  124. package/src/authorization-attributes-ms-service.ts +0 -531
  125. package/src/authorization-attributes-sns-service.ts +0 -312
@@ -1,369 +0,0 @@
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', '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
- // 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 compatibileAssignments = assignments.map(assignment => {
316
- if (assignment instanceof resourceAttributeAssignment.ResourceAttributeAssignment) {
317
- return {
318
- resourceId: assignment.resourceId,
319
- resourceType: assignment.resourceType,
320
- key: assignment.attributeKey,
321
- value: assignment.attributeValue,
322
- };
323
- }
324
- else {
325
- return {
326
- entityId: assignment.entityId,
327
- entityType: assignment.entityType,
328
- key: assignment.attributeKey,
329
- value: assignment.attributeValue,
330
- };
331
- }
332
- });
333
- const requestBody = requestBodyKey === 'resourceAttributeAssignments'
334
- ? { resourceAttributeAssignments: compatibileAssignments }
335
- : { entityAttributeAssignments: compatibileAssignments };
336
- if (!AuthorizationAttributesMsService.httpClient) {
337
- throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
338
- }
339
- const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId });
340
- const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
341
- try {
342
- authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
343
- await AuthorizationAttributesMsService.httpClient.fetch({
344
- url: {
345
- appName: constants.APP_NAME,
346
- path,
347
- },
348
- method: 'POST',
349
- headers,
350
- body: JSON.stringify(requestBody),
351
- }, {
352
- timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
353
- retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
354
- });
355
- authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
356
- }
357
- catch (err) {
358
- authorizationInternalService.logger.error({
359
- tag: AuthorizationAttributesMsService.LOG_TAG,
360
- method: methodName,
361
- accountId,
362
- error: err instanceof Error ? err.message : String(err),
363
- }, `Failed in ${methodName}`);
364
- throw err;
365
- }
366
- }
367
- }
368
-
369
- exports.AuthorizationAttributesMsService = AuthorizationAttributesMsService;
@@ -1,90 +0,0 @@
1
- import { ResourceAttributeAssignment, ResourceAttributeOperation, EntityAttributeOperation, EntityType } from './types/authorization-attributes-contracts';
2
- import { EntityAttributeAssignment } from './entity-attribute-assignment';
3
- import { Resource } from './types/general';
4
- import { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
5
- /**
6
- * Service class for managing resource attributes asynchronously via SNS.
7
- * Provides asynchronous operations to create/update and delete attributes on resources.
8
- */
9
- export declare class AuthorizationAttributesSnsService implements IAuthorizationAttributesService {
10
- private static LOG_TAG;
11
- private resourceSnsArn;
12
- private entitySnsArn;
13
- /**
14
- * Public constructor to create the AuthorizationAttributesSnsService instance.
15
- */
16
- constructor();
17
- /**
18
- * Async function to upsert resource attributes using SNS.
19
- * Sends the updates request to SNS and returns before the change actually took place.
20
- * @param accountId The account ID
21
- * @param appName App name of the calling app
22
- * @param callerActionIdentifier Action identifier
23
- * @param resourceAttributeAssignments Array of resource attribute assignments to upsert
24
- * @return Promise with array of sent operations
25
- */
26
- upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[], appName?: string, callerActionIdentifier?: string): Promise<ResourceAttributeOperation[]>;
27
- /**
28
- * Async function to delete resource attributes using SNS.
29
- * Sends the updates request to SNS and returns before the change actually took place.
30
- * @param accountId The account ID
31
- * @param appName App name of the calling app
32
- * @param callerActionIdentifier Action identifier
33
- * @param resource The resource (resourceType, resourceId)
34
- * @param attributeKeys Array of attribute keys to delete
35
- * @return Promise with array of sent operations
36
- */
37
- deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<ResourceAttributeOperation[]>;
38
- /**
39
- * Async function to upsert entity attributes using SNS.
40
- * Sends the updates request to SNS and returns before the change actually took place.
41
- * @param accountId The account ID
42
- * @param appName App name of the calling app
43
- * @param callerActionIdentifier Action identifier
44
- * @param entityAttributeAssignments Array of entity attribute assignments to upsert
45
- * @return Promise with array of sent operations
46
- */
47
- upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[], appName?: string, callerActionIdentifier?: string): Promise<EntityAttributeOperation[]>;
48
- /**
49
- * Async function to delete entity attributes using SNS.
50
- * Sends the updates request to SNS and returns before the change actually took place.
51
- * @param accountId The account ID
52
- * @param appName App name of the calling app
53
- * @param callerActionIdentifier Action identifier
54
- * @param entityType The entity type
55
- * @param entityId The entity ID
56
- * @param attributeKeys Array of attribute keys to delete
57
- * @return Promise with array of sent operations
58
- */
59
- deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<EntityAttributeOperation[]>;
60
- /**
61
- * Async function, this function only send the updates request to SNS and return before the change actually took place
62
- * @param accountId
63
- * @param appName - App name of the calling app
64
- * @param callerActionIdentifier - action identifier
65
- * @param resourceAttributeOperations - Array of operations to do on resource attributes.
66
- * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
67
- * */
68
- updateResourceAttributes(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
69
- /**
70
- * Async function, this function only send the updates request to SNS and return before the change actually took place
71
- * @param accountId
72
- * @param appName - App name of the calling app
73
- * @param callerActionIdentifier - action identifier
74
- * @param entityAttributeOperations - Array of operations to do on entity attributes.
75
- * @return {Promise<EntityAttributeOperation[]>} Array of sent operations
76
- * */
77
- updateEntityAttributes(accountId: number, appName: string, callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
78
- private sendSingleSnsMessage;
79
- private static getSnsTopicArn;
80
- /**
81
- * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
82
- * This function can be used as health check for services that updating resource attributes in async is crucial.
83
- * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
84
- * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
85
- * However, this is the best we can do without actually push dummy messages to the SNS.
86
- * @return {Promise<boolean>} - true if succeeded
87
- */
88
- asyncResourceAttributesHealthCheck(): Promise<boolean>;
89
- }
90
- //# sourceMappingURL=authorization-attributes-sns-service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authorization-attributes-sns-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-sns-service.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,EAExB,UAAU,EACX,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAc3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAErG;;;GAGG;AACH,qBAAa,iCAAkC,YAAW,+BAA+B;IACvF,OAAO,CAAC,MAAM,CAAC,OAAO,CAA8B;IACpD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAS;IAE7B;;OAEG;;IAMH;;;;;;;;OAQG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,EAC3D,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAWxC;;;;;;;;;OASG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAgBxC;;;;;;;;OAQG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,EACvD,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAgBtC;;;;;;;;;;OAUG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAgBtC;;;;;;;UAOM;IACA,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,0BAA0B,EAAE,GACxD,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAoBxC;;;;;;;UAOM;IACA,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,yBAAyB,EAAE,wBAAwB,EAAE,GACpD,OAAO,CAAC,wBAAwB,EAAE,CAAC;YAoBxB,oBAAoB;IA2BlC,OAAO,CAAC,MAAM,CAAC,cAAc;IA0B7B;;;;;;;OAOG;IACG,kCAAkC,IAAI,OAAO,CAAC,OAAO,CAAC;CAoB7D"}