@mondaydotcomorg/monday-authorization 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-a77c130 → 3.6.0-feat-shaime-support-entity-attributes-1-f58d933

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 +171 -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 -8
  15. package/dist/entity-attribute-assignment.d.ts.map +1 -1
  16. package/dist/entity-attribute-assignment.js +5 -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 +167 -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 -8
  36. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
  37. package/dist/esm/entity-attribute-assignment.mjs +5 -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 -8
  49. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
  50. package/dist/esm/resource-attribute-assignment.mjs +3 -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 -8
  74. package/dist/resource-attribute-assignment.d.ts.map +1 -1
  75. package/dist/resource-attribute-assignment.js +3 -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 +222 -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 +9 -6
  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 +11 -13
  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 -352
  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 -350
  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 -514
  125. package/src/authorization-attributes-sns-service.ts +0 -312
@@ -1,211 +0,0 @@
1
- import chunk from 'lodash/chunk.js';
2
- import { sendToSns, getTopicAttributes } from '@mondaydotcomorg/monday-sns';
3
- import { AttributeOperation } from './types/authorization-attributes-contracts.mjs';
4
- import { logger } from './authorization-internal-service.mjs';
5
- import { SnsTopicType, ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE, RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE, ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, RESOURCE_SNS_ARN_ENV_VAR_NAME, RESOURCE_SNS_DEV_TEST_NAME, ENTITY_SNS_ARN_ENV_VAR_NAME, ENTITY_SNS_DEV_TEST_NAME } from './constants/sns.mjs';
6
-
7
- /**
8
- * Service class for managing resource attributes asynchronously via SNS.
9
- * Provides asynchronous operations to create/update and delete attributes on resources.
10
- */
11
- class AuthorizationAttributesSnsService {
12
- static LOG_TAG = 'authorization_attributes';
13
- resourceSnsArn;
14
- entitySnsArn;
15
- /**
16
- * Public constructor to create the AuthorizationAttributesSnsService instance.
17
- */
18
- constructor() {
19
- this.resourceSnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.RESOURCE);
20
- this.entitySnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.ENTITY);
21
- }
22
- /**
23
- * Async function to upsert resource attributes using SNS.
24
- * Sends the updates request to SNS and returns before the change actually took place.
25
- * @param accountId The account ID
26
- * @param appName App name of the calling app
27
- * @param callerActionIdentifier Action identifier
28
- * @param resourceAttributeAssignments Array of resource attribute assignments to upsert
29
- * @return Promise with array of sent operations
30
- */
31
- async upsertResourceAttributes(accountId, resourceAttributeAssignments, appName, callerActionIdentifier) {
32
- if (!appName || !callerActionIdentifier) {
33
- throw new Error('appName and callerActionIdentifier are required for SNS service');
34
- }
35
- const operations = resourceAttributeAssignments.map(assignment => ({
36
- ...assignment,
37
- operationType: AttributeOperation.UPSERT,
38
- }));
39
- return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
40
- }
41
- /**
42
- * Async function to delete resource attributes using SNS.
43
- * Sends the updates request to SNS and returns before the change actually took place.
44
- * @param accountId The account ID
45
- * @param appName App name of the calling app
46
- * @param callerActionIdentifier Action identifier
47
- * @param resource The resource (resourceType, resourceId)
48
- * @param attributeKeys Array of attribute keys to delete
49
- * @return Promise with array of sent operations
50
- */
51
- async deleteResourceAttributes(accountId, resource, attributeKeys, appName, callerActionIdentifier) {
52
- if (!appName || !callerActionIdentifier) {
53
- throw new Error('appName and callerActionIdentifier are required for SNS service');
54
- }
55
- const operations = attributeKeys.map(key => ({
56
- resourceType: resource.type,
57
- resourceId: resource.id,
58
- key,
59
- operationType: AttributeOperation.DELETE,
60
- }));
61
- return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
62
- }
63
- /**
64
- * Async function to upsert entity attributes using SNS.
65
- * Sends the updates request to SNS and returns before the change actually took place.
66
- * @param accountId The account ID
67
- * @param appName App name of the calling app
68
- * @param callerActionIdentifier Action identifier
69
- * @param entityAttributeAssignments Array of entity attribute assignments to upsert
70
- * @return Promise with array of sent operations
71
- */
72
- async upsertEntityAttributes(accountId, entityAttributeAssignments, appName, callerActionIdentifier) {
73
- if (!appName || !callerActionIdentifier) {
74
- throw new Error('appName and callerActionIdentifier are required for SNS service');
75
- }
76
- const operations = entityAttributeAssignments.map(assignment => {
77
- return {
78
- entityId: assignment.entityId,
79
- entityType: assignment.entityType,
80
- key: assignment.attributeKey,
81
- value: assignment.attributeValue,
82
- operationType: AttributeOperation.UPSERT,
83
- };
84
- });
85
- return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
86
- }
87
- /**
88
- * Async function to delete entity attributes using SNS.
89
- * Sends the updates request to SNS and returns before the change actually took place.
90
- * @param accountId The account ID
91
- * @param appName App name of the calling app
92
- * @param callerActionIdentifier Action identifier
93
- * @param entityType The entity type
94
- * @param entityId The entity ID
95
- * @param attributeKeys Array of attribute keys to delete
96
- * @return Promise with array of sent operations
97
- */
98
- async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, appName, callerActionIdentifier) {
99
- if (!appName || !callerActionIdentifier) {
100
- throw new Error('appName and callerActionIdentifier are required for SNS service');
101
- }
102
- const operations = attributeKeys.map(key => ({
103
- entityType: entityType,
104
- entityId,
105
- key,
106
- operationType: AttributeOperation.DELETE,
107
- }));
108
- return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
109
- }
110
- /**
111
- * Async function, this function only send the updates request to SNS and return before the change actually took place
112
- * @param accountId
113
- * @param appName - App name of the calling app
114
- * @param callerActionIdentifier - action identifier
115
- * @param resourceAttributeOperations - Array of operations to do on resource attributes.
116
- * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
117
- * */
118
- async updateResourceAttributes(accountId, appName, callerActionIdentifier, resourceAttributeOperations) {
119
- const topicArn = this.resourceSnsArn;
120
- const sendToSnsPromises = [];
121
- const operationChucks = chunk(resourceAttributeOperations, ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
122
- for (const operationsChunk of operationChucks) {
123
- sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk, RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, 'Authorization resource attributes async update: failed to send operations to SNS'));
124
- }
125
- return (await Promise.all(sendToSnsPromises)).flat();
126
- }
127
- /**
128
- * Async function, this function only send the updates request to SNS and return before the change actually took place
129
- * @param accountId
130
- * @param appName - App name of the calling app
131
- * @param callerActionIdentifier - action identifier
132
- * @param entityAttributeOperations - Array of operations to do on entity attributes.
133
- * @return {Promise<EntityAttributeOperation[]>} Array of sent operations
134
- * */
135
- async updateEntityAttributes(accountId, appName, callerActionIdentifier, entityAttributeOperations) {
136
- const topicArn = this.entitySnsArn;
137
- const sendToSnsPromises = [];
138
- const operationChucks = chunk(entityAttributeOperations, ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
139
- for (const operationsChunk of operationChucks) {
140
- sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk, ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, 'Authorization entity attributes async update: failed to send operations to SNS'));
141
- }
142
- return (await Promise.all(sendToSnsPromises)).flat();
143
- }
144
- async sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations, kind, errorLogMessage) {
145
- const payload = {
146
- kind,
147
- payload: {
148
- accountId: accountId,
149
- callerAppName: appName,
150
- callerActionIdentifier: callerActionIdentifier,
151
- operations: operations,
152
- },
153
- };
154
- try {
155
- await sendToSns(payload, topicArn);
156
- return operations;
157
- }
158
- catch (error) {
159
- logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, errorLogMessage);
160
- return [];
161
- }
162
- }
163
- static getSnsTopicArn(type) {
164
- let envVarName;
165
- let devTestName;
166
- switch (type) {
167
- case SnsTopicType.ENTITY:
168
- envVarName = ENTITY_SNS_ARN_ENV_VAR_NAME;
169
- devTestName = ENTITY_SNS_DEV_TEST_NAME;
170
- break;
171
- default:
172
- // Default to resource SNS constants
173
- envVarName = RESOURCE_SNS_ARN_ENV_VAR_NAME;
174
- devTestName = RESOURCE_SNS_DEV_TEST_NAME;
175
- break;
176
- }
177
- const arnFromEnv = process.env[envVarName];
178
- if (arnFromEnv) {
179
- return arnFromEnv;
180
- }
181
- if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
182
- return devTestName;
183
- }
184
- throw new Error(`Unable to get ${type} sns topic arn from env variable`);
185
- }
186
- /**
187
- * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
188
- * This function can be used as health check for services that updating resource attributes in async is crucial.
189
- * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
190
- * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
191
- * However, this is the best we can do without actually push dummy messages to the SNS.
192
- * @return {Promise<boolean>} - true if succeeded
193
- */
194
- async asyncResourceAttributesHealthCheck() {
195
- try {
196
- const requestedTopicArn = this.resourceSnsArn;
197
- const attributes = await getTopicAttributes(requestedTopicArn);
198
- const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
199
- if (!isHealthy) {
200
- logger.error({ requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesSnsService.LOG_TAG }, 'authorization-attributes-service failed in health check');
201
- }
202
- return isHealthy;
203
- }
204
- catch (error) {
205
- logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, 'authorization-attributes-service got error during health check');
206
- return false;
207
- }
208
- }
209
- }
210
-
211
- export { AuthorizationAttributesSnsService };