@mondaydotcomorg/monday-authorization 3.5.0-upgrade-observability-kit-2ebbd01 → 3.5.1-feat-shaime-support-entity-attributes-in-authorization-sdk-59162a3

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 (121) hide show
  1. package/dist/attributions-service.d.ts.map +1 -1
  2. package/dist/attributions-service.js +1 -0
  3. package/dist/authorization-attributes-ms-service.d.ts +67 -0
  4. package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
  5. package/dist/authorization-attributes-ms-service.js +256 -0
  6. package/dist/authorization-attributes-sns-service.d.ts +85 -0
  7. package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
  8. package/dist/authorization-attributes-sns-service.js +203 -0
  9. package/dist/base-attribute-assignment.d.ts +18 -0
  10. package/dist/base-attribute-assignment.d.ts.map +1 -0
  11. package/dist/base-attribute-assignment.js +43 -0
  12. package/dist/clients/graph-api.d.ts.map +1 -1
  13. package/dist/clients/graph-api.js +1 -0
  14. package/dist/constants/sns.d.ts +12 -2
  15. package/dist/constants/sns.d.ts.map +1 -1
  16. package/dist/constants/sns.js +22 -2
  17. package/dist/constants.d.ts +3 -0
  18. package/dist/constants.d.ts.map +1 -1
  19. package/dist/constants.js +4 -0
  20. package/dist/entity-attribute-assignment.d.ts +24 -0
  21. package/dist/entity-attribute-assignment.d.ts.map +1 -0
  22. package/dist/entity-attribute-assignment.js +36 -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/attributions-service.d.ts.map +1 -1
  30. package/dist/esm/attributions-service.mjs +1 -0
  31. package/dist/esm/authorization-attributes-ms-service.d.ts +67 -0
  32. package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
  33. package/dist/esm/authorization-attributes-ms-service.mjs +254 -0
  34. package/dist/esm/authorization-attributes-sns-service.d.ts +85 -0
  35. package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
  36. package/dist/esm/authorization-attributes-sns-service.mjs +197 -0
  37. package/dist/esm/base-attribute-assignment.d.ts +18 -0
  38. package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
  39. package/dist/esm/base-attribute-assignment.mjs +41 -0
  40. package/dist/esm/clients/graph-api.d.ts.map +1 -1
  41. package/dist/esm/clients/graph-api.mjs +2 -1
  42. package/dist/esm/constants/sns.d.ts +12 -2
  43. package/dist/esm/constants/sns.d.ts.map +1 -1
  44. package/dist/esm/constants/sns.mjs +17 -3
  45. package/dist/esm/constants.d.ts +3 -0
  46. package/dist/esm/constants.d.ts.map +1 -1
  47. package/dist/esm/constants.mjs +5 -1
  48. package/dist/esm/entity-attribute-assignment.d.ts +24 -0
  49. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
  50. package/dist/esm/entity-attribute-assignment.mjs +34 -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 -1
  58. package/dist/esm/index.d.ts.map +1 -1
  59. package/dist/esm/index.mjs +7 -1
  60. package/dist/esm/resource-attribute-assignment.d.ts +24 -0
  61. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
  62. package/dist/esm/resource-attribute-assignment.mjs +34 -0
  63. package/dist/esm/resource-attributes-constants.d.ts +25 -0
  64. package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
  65. package/dist/esm/resource-attributes-constants.mjs +25 -0
  66. package/dist/esm/roles-service.d.ts +1 -1
  67. package/dist/esm/roles-service.mjs +1 -1
  68. package/dist/esm/types/authorization-attributes-contracts.d.ts +36 -4
  69. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  70. package/dist/esm/types/authorization-attributes-contracts.mjs +6 -1
  71. package/dist/esm/utils/path-utils.d.ts +8 -0
  72. package/dist/esm/utils/path-utils.d.ts.map +1 -0
  73. package/dist/esm/utils/path-utils.mjs +15 -0
  74. package/dist/esm/utils/validation.d.ts +45 -0
  75. package/dist/esm/utils/validation.d.ts.map +1 -0
  76. package/dist/esm/utils/validation.mjs +75 -0
  77. package/dist/index.d.ts +9 -1
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +15 -2
  80. package/dist/resource-attribute-assignment.d.ts +24 -0
  81. package/dist/resource-attribute-assignment.d.ts.map +1 -0
  82. package/dist/resource-attribute-assignment.js +36 -0
  83. package/dist/resource-attributes-constants.d.ts +25 -0
  84. package/dist/resource-attributes-constants.d.ts.map +1 -0
  85. package/dist/resource-attributes-constants.js +28 -0
  86. package/dist/roles-service.d.ts +1 -1
  87. package/dist/roles-service.js +1 -1
  88. package/dist/types/authorization-attributes-contracts.d.ts +36 -4
  89. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  90. package/dist/types/authorization-attributes-contracts.js +5 -0
  91. package/dist/utils/path-utils.d.ts +8 -0
  92. package/dist/utils/path-utils.d.ts.map +1 -0
  93. package/dist/utils/path-utils.js +17 -0
  94. package/dist/utils/validation.d.ts +45 -0
  95. package/dist/utils/validation.d.ts.map +1 -0
  96. package/dist/utils/validation.js +77 -0
  97. package/package.json +2 -2
  98. package/src/attributions-service.ts +4 -0
  99. package/src/authorization-attributes-ms-service.ts +400 -0
  100. package/src/authorization-attributes-sns-service.ts +290 -0
  101. package/src/base-attribute-assignment.ts +56 -0
  102. package/src/clients/graph-api.ts +2 -1
  103. package/src/constants/sns.ts +19 -2
  104. package/src/constants.ts +4 -0
  105. package/src/entity-attribute-assignment.ts +43 -0
  106. package/src/entity-attributes-constants.ts +7 -0
  107. package/src/errors/argument-error.ts +7 -0
  108. package/src/index.ts +18 -1
  109. package/src/resource-attribute-assignment.ts +43 -0
  110. package/src/resource-attributes-constants.ts +26 -0
  111. package/src/roles-service.ts +1 -1
  112. package/src/types/authorization-attributes-contracts.ts +56 -3
  113. package/src/utils/path-utils.ts +14 -0
  114. package/src/utils/validation.ts +84 -0
  115. package/dist/authorization-attributes-service.d.ts +0 -54
  116. package/dist/authorization-attributes-service.d.ts.map +0 -1
  117. package/dist/authorization-attributes-service.js +0 -186
  118. package/dist/esm/authorization-attributes-service.d.ts +0 -54
  119. package/dist/esm/authorization-attributes-service.d.ts.map +0 -1
  120. package/dist/esm/authorization-attributes-service.mjs +0 -180
  121. package/src/authorization-attributes-service.ts +0 -234
@@ -0,0 +1,290 @@
1
+ import chunk from 'lodash/chunk.js';
2
+ import { getTopicAttributes, sendToSns } from '@mondaydotcomorg/monday-sns';
3
+ import {
4
+ ResourceAttributeAssignment,
5
+ ResourceAttributesOperation,
6
+ EntityAttributesOperation,
7
+ ResourceAttributeOperationEnum,
8
+ EntityAttributeOperationEnum,
9
+ } from './types/authorization-attributes-contracts';
10
+ import { EntityAttributeAssignment } from './entity-attribute-assignment';
11
+ import { Resource } from './types/general';
12
+ import { logger } from './authorization-internal-service';
13
+ import {
14
+ ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
15
+ ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
16
+ RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
17
+ ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
18
+ RESOURCE_SNS_ARN_ENV_VAR_NAME,
19
+ ENTITY_SNS_ARN_ENV_VAR_NAME,
20
+ RESOURCE_SNS_DEV_TEST_NAME,
21
+ ENTITY_SNS_DEV_TEST_NAME,
22
+ SnsTopicType,
23
+ } from './constants/sns';
24
+ import type { TopicAttributesMap } from 'aws-sdk/clients/sns';
25
+
26
+ export class AuthorizationAttributesSnsService {
27
+ private static LOG_TAG = 'authorization_attributes';
28
+ private resourceSnsArn: string;
29
+ private entitySnsArn: string;
30
+
31
+ /**
32
+ * Public constructor to create the AuthorizationAttributesSnsService instance.
33
+ */
34
+ constructor() {
35
+ this.resourceSnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.RESOURCE);
36
+ this.entitySnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.ENTITY);
37
+ }
38
+
39
+ /**
40
+ * Async function to upsert resource attributes using SNS.
41
+ * Sends the updates request to SNS and returns before the change actually took place.
42
+ * @param accountId The account ID
43
+ * @param appName App name of the calling app
44
+ * @param callerActionIdentifier Action identifier
45
+ * @param resourceAttributeAssignments Array of resource attribute assignments to upsert
46
+ * @return Promise with array of sent operations
47
+ */
48
+ async upsertResourceAttributesAsync(
49
+ accountId: number,
50
+ appName: string,
51
+ callerActionIdentifier: string,
52
+ resourceAttributeAssignments: ResourceAttributeAssignment[]
53
+ ): Promise<ResourceAttributesOperation[]> {
54
+ const operations: ResourceAttributesOperation[] = resourceAttributeAssignments.map(assignment => ({
55
+ ...assignment,
56
+ operationType: ResourceAttributeOperationEnum.UPSERT,
57
+ }));
58
+ return this.updateResourceAttributesAsync(accountId, appName, callerActionIdentifier, operations);
59
+ }
60
+
61
+ /**
62
+ * Async function to delete resource attributes using SNS.
63
+ * Sends the updates request to SNS and returns before the change actually took place.
64
+ * @param accountId The account ID
65
+ * @param appName App name of the calling app
66
+ * @param callerActionIdentifier Action identifier
67
+ * @param resource The resource (resourceType, resourceId)
68
+ * @param attributeKeys Array of attribute keys to delete
69
+ * @return Promise with array of sent operations
70
+ */
71
+ async deleteResourceAttributesAsync(
72
+ accountId: number,
73
+ appName: string,
74
+ callerActionIdentifier: string,
75
+ resource: Resource,
76
+ attributeKeys: string[]
77
+ ): Promise<ResourceAttributesOperation[]> {
78
+ const operations: ResourceAttributesOperation[] = attributeKeys.map(key => ({
79
+ resourceType: resource.type,
80
+ resourceId: resource.id!,
81
+ key,
82
+ operationType: ResourceAttributeOperationEnum.DELETE,
83
+ }));
84
+ return this.updateResourceAttributesAsync(accountId, appName, callerActionIdentifier, operations);
85
+ }
86
+
87
+ /**
88
+ * Async function to upsert 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 entityAttributeAssignments Array of entity attribute assignments to upsert
94
+ * @return Promise with array of sent operations
95
+ */
96
+ async upsertEntityAttributesAsync(
97
+ accountId: number,
98
+ appName: string,
99
+ callerActionIdentifier: string,
100
+ entityAttributeAssignments: EntityAttributeAssignment[]
101
+ ): Promise<EntityAttributesOperation[]> {
102
+ const operations: EntityAttributesOperation[] = entityAttributeAssignments.map(assignment => {
103
+ const assignmentData = assignment instanceof EntityAttributeAssignment ? assignment.toH() : assignment;
104
+ return {
105
+ entityId: assignmentData.entityId,
106
+ entityType: assignmentData.entityType as any,
107
+ key: assignmentData.key,
108
+ value: assignmentData.value,
109
+ operationType: EntityAttributeOperationEnum.UPSERT,
110
+ };
111
+ });
112
+ return this.updateEntityAttributesAsync(accountId, appName, callerActionIdentifier, operations);
113
+ }
114
+
115
+ /**
116
+ * Async function to delete entity attributes using SNS.
117
+ * Sends the updates request to SNS and returns before the change actually took place.
118
+ * @param accountId The account ID
119
+ * @param appName App name of the calling app
120
+ * @param callerActionIdentifier Action identifier
121
+ * @param entityType The entity type
122
+ * @param entityId The entity ID
123
+ * @param attributeKeys Array of attribute keys to delete
124
+ * @return Promise with array of sent operations
125
+ */
126
+ async deleteEntityAttributesAsync(
127
+ accountId: number,
128
+ appName: string,
129
+ callerActionIdentifier: string,
130
+ entityType: string,
131
+ entityId: number,
132
+ attributeKeys: string[]
133
+ ): Promise<EntityAttributesOperation[]> {
134
+ const operations: EntityAttributesOperation[] = attributeKeys.map(key => ({
135
+ entityType: entityType as any,
136
+ entityId,
137
+ key,
138
+ operationType: EntityAttributeOperationEnum.DELETE,
139
+ }));
140
+ return this.updateEntityAttributesAsync(accountId, appName, callerActionIdentifier, operations);
141
+ }
142
+
143
+ /**
144
+ * Async function, this function only send the updates request to SNS and return before the change actually took place
145
+ * @param accountId
146
+ * @param appName - App name of the calling app
147
+ * @param callerActionIdentifier - action identifier
148
+ * @param resourceAttributeOperations - Array of operations to do on resource attributes.
149
+ * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
150
+ * */
151
+ async updateResourceAttributesAsync(
152
+ accountId: number,
153
+ appName: string,
154
+ callerActionIdentifier: string,
155
+ resourceAttributeOperations: ResourceAttributesOperation[]
156
+ ): Promise<ResourceAttributesOperation[]> {
157
+ const topicArn: string = this.resourceSnsArn;
158
+ const sendToSnsPromises: Promise<ResourceAttributesOperation[]>[] = [];
159
+ const operationChucks = chunk(resourceAttributeOperations, ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
160
+ for (const operationsChunk of operationChucks) {
161
+ sendToSnsPromises.push(
162
+ this.sendSingleSnsMessage(
163
+ topicArn,
164
+ accountId,
165
+ appName,
166
+ callerActionIdentifier,
167
+ operationsChunk,
168
+ RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
169
+ 'Authorization resource attributes async update: failed to send operations to SNS'
170
+ )
171
+ );
172
+ }
173
+ return (await Promise.all(sendToSnsPromises)).flat();
174
+ }
175
+
176
+ /**
177
+ * Async function, this function only send the updates request to SNS and return before the change actually took place
178
+ * @param accountId
179
+ * @param appName - App name of the calling app
180
+ * @param callerActionIdentifier - action identifier
181
+ * @param entityAttributeOperations - Array of operations to do on entity attributes.
182
+ * @return {Promise<EntityAttributesOperation[]>} Array of sent operations
183
+ * */
184
+ async updateEntityAttributesAsync(
185
+ accountId: number,
186
+ appName: string,
187
+ callerActionIdentifier: string,
188
+ entityAttributeOperations: EntityAttributesOperation[]
189
+ ): Promise<EntityAttributesOperation[]> {
190
+ const topicArn: string = this.entitySnsArn;
191
+ const sendToSnsPromises: Promise<EntityAttributesOperation[]>[] = [];
192
+ const operationChucks = chunk(entityAttributeOperations, ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
193
+ for (const operationsChunk of operationChucks) {
194
+ sendToSnsPromises.push(
195
+ this.sendSingleSnsMessage(
196
+ topicArn,
197
+ accountId,
198
+ appName,
199
+ callerActionIdentifier,
200
+ operationsChunk,
201
+ ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
202
+ 'Authorization entity attributes async update: failed to send operations to SNS'
203
+ )
204
+ );
205
+ }
206
+ return (await Promise.all(sendToSnsPromises)).flat();
207
+ }
208
+
209
+ private async sendSingleSnsMessage<T extends ResourceAttributesOperation | EntityAttributesOperation>(
210
+ topicArn: string,
211
+ accountId: number,
212
+ appName: string,
213
+ callerActionIdentifier: string,
214
+ operations: T[],
215
+ kind: string,
216
+ errorLogMessage: string
217
+ ): Promise<T[]> {
218
+ const payload = {
219
+ kind,
220
+ payload: {
221
+ accountId: accountId,
222
+ callerAppName: appName,
223
+ callerActionIdentifier: callerActionIdentifier,
224
+ operations: operations,
225
+ },
226
+ };
227
+ try {
228
+ await sendToSns(payload, topicArn);
229
+ return operations;
230
+ } catch (error) {
231
+ logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, errorLogMessage);
232
+ return [];
233
+ }
234
+ }
235
+
236
+ private static getSnsTopicArn(type: SnsTopicType): string {
237
+ let envVarName: string;
238
+ let devTestName: string;
239
+
240
+ switch (type) {
241
+ case SnsTopicType.ENTITY:
242
+ envVarName = ENTITY_SNS_ARN_ENV_VAR_NAME;
243
+ devTestName = ENTITY_SNS_DEV_TEST_NAME;
244
+ break;
245
+ default:
246
+ // Default to resource SNS constants
247
+ envVarName = RESOURCE_SNS_ARN_ENV_VAR_NAME;
248
+ devTestName = RESOURCE_SNS_DEV_TEST_NAME;
249
+ break;
250
+ }
251
+
252
+ const arnFromEnv: string | undefined = process.env[envVarName];
253
+ if (arnFromEnv) {
254
+ return arnFromEnv;
255
+ }
256
+ if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
257
+ return devTestName;
258
+ }
259
+ throw new Error(`Unable to get ${type} sns topic arn from env variable`);
260
+ }
261
+
262
+ /**
263
+ * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
264
+ * This function can be used as health check for services that updating resource attributes in async is crucial.
265
+ * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
266
+ * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
267
+ * However, this is the best we can do without actually push dummy messages to the SNS.
268
+ * @return {Promise<boolean>} - true if succeeded
269
+ */
270
+ async asyncResourceAttributesHealthCheck(): Promise<boolean> {
271
+ try {
272
+ const requestedTopicArn: string = this.resourceSnsArn;
273
+ const attributes: TopicAttributesMap = await getTopicAttributes(requestedTopicArn);
274
+ const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
275
+ if (!isHealthy) {
276
+ logger.error(
277
+ { requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesSnsService.LOG_TAG },
278
+ 'authorization-attributes-service failed in health check'
279
+ );
280
+ }
281
+ return isHealthy;
282
+ } catch (error) {
283
+ logger.error(
284
+ { error, tag: AuthorizationAttributesSnsService.LOG_TAG },
285
+ 'authorization-attributes-service got error during health check'
286
+ );
287
+ return false;
288
+ }
289
+ }
290
+ }
@@ -0,0 +1,56 @@
1
+ import { ValidationUtils } from './utils/validation';
2
+
3
+ /**
4
+ * Base class for attribute assignments (Resource or Entity)
5
+ * Provides common validation and functionality
6
+ */
7
+ export abstract class BaseAttributeAssignment<TId extends number, TType extends string> {
8
+ public readonly id: TId;
9
+ public readonly type: TType;
10
+ public readonly attributeKey: string;
11
+ public readonly attributeValue: string;
12
+
13
+ constructor(
14
+ id: TId,
15
+ type: string,
16
+ attributeKey: string,
17
+ attributeValue: string,
18
+ validTypes: readonly string[],
19
+ idFieldName: string,
20
+ typeFieldName: string
21
+ ) {
22
+ // Validate id
23
+ ValidationUtils.validateInteger(id, idFieldName);
24
+
25
+ // Validate type
26
+ this.type = ValidationUtils.validateEnum(type, validTypes as readonly TType[], typeFieldName) as TType;
27
+
28
+ // Validate attributeKey
29
+ ValidationUtils.validateString(attributeKey, 'attributeKey');
30
+
31
+ // Validate attributeValue
32
+ ValidationUtils.validateString(attributeValue, 'attributeValue');
33
+
34
+ this.id = id;
35
+ this.attributeKey = attributeKey;
36
+ this.attributeValue = attributeValue;
37
+ }
38
+
39
+ /**
40
+ * Compares two assignments for equality
41
+ * @param other Another assignment instance
42
+ * @returns true if all properties are equal
43
+ */
44
+ equals(other: BaseAttributeAssignment<TId, TType>): boolean {
45
+ if (!(other instanceof this.constructor)) {
46
+ return false;
47
+ }
48
+ return (
49
+ this.id === other.id &&
50
+ this.type === other.type &&
51
+ this.attributeKey === other.attributeKey &&
52
+ this.attributeValue === other.attributeValue
53
+ );
54
+ }
55
+ }
56
+
@@ -18,7 +18,7 @@ import {
18
18
  GraphPermissionReason,
19
19
  } from '../types/graph-api.types';
20
20
  import { scopeToResource } from '../utils/authorization.utils';
21
- import { GRAPH_APP_NAME } from '../constants';
21
+ import { GRAPH_APP_NAME, GraphApiProfile } from '../constants';
22
22
  import { handleApiError } from '../utils/api-error-handler';
23
23
 
24
24
  const CAN_ACTION_IN_SCOPE_GRAPH_PATH = '/permissions/is-allowed';
@@ -85,6 +85,7 @@ export class GraphApi {
85
85
  url: {
86
86
  appName: GRAPH_APP_NAME,
87
87
  path: CAN_ACTION_IN_SCOPE_GRAPH_PATH,
88
+ profile: GraphApiProfile.PERMISSION,
88
89
  },
89
90
  method: 'POST',
90
91
  headers: {
@@ -1,5 +1,22 @@
1
- export const SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES';
2
- export const SNS_DEV_TEST_NAME =
1
+ export enum SnsTopicType {
2
+ RESOURCE = 'resource',
3
+ ENTITY = 'entity',
4
+ }
5
+
6
+ // Resource SNS constants
7
+ export const RESOURCE_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES';
8
+ export const RESOURCE_SNS_DEV_TEST_NAME =
3
9
  'arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local';
10
+
11
+ // Entity SNS constants
12
+ export const ENTITY_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_ENTITY_ATTRIBUTES';
13
+ export const ENTITY_SNS_DEV_TEST_NAME =
14
+ 'arn:aws:sns:us-east-1:000000000000:monday-authorization-entity-attributes-sns-local';
4
15
  export const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'resourceAttributeModification';
16
+ export const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'entityAttributeModification';
5
17
  export const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
18
+ export const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
19
+
20
+ // Legacy exports for backward compatibility
21
+ export const SNS_ARN_ENV_VAR_NAME = RESOURCE_SNS_ARN_ENV_VAR_NAME;
22
+ export const SNS_DEV_TEST_NAME = RESOURCE_SNS_DEV_TEST_NAME;
package/src/constants.ts CHANGED
@@ -4,6 +4,10 @@ import { FetcherConfig } from '@mondaydotcomorg/trident-backend-api';
4
4
  export const APP_NAME = 'authorization';
5
5
  export const GRAPH_APP_NAME = 'authorization-graph';
6
6
 
7
+ export enum GraphApiProfile {
8
+ PERMISSION = 'authorization-graph-permission',
9
+ }
10
+
7
11
  export const ERROR_MESSAGES = {
8
12
  HTTP_CLIENT_NOT_INITIALIZED: 'MondayAuthorization: HTTP client is not initialized',
9
13
  REQUEST_FAILED: (method: string, status: number, reason: string) =>
@@ -0,0 +1,43 @@
1
+ import { ENTITY_TYPES, EntityType } from './entity-attributes-constants';
2
+ import { BaseAttributeAssignment } from './base-attribute-assignment';
3
+
4
+ export class EntityAttributeAssignment extends BaseAttributeAssignment<number, EntityType> {
5
+ public readonly entityId: number;
6
+ public readonly entityType: EntityType;
7
+
8
+ constructor(entityId: number, entityType: string, attributeKey: string, attributeValue: string) {
9
+ super(
10
+ entityId,
11
+ entityType,
12
+ attributeKey,
13
+ attributeValue,
14
+ Object.values(ENTITY_TYPES),
15
+ 'entityId',
16
+ 'entityType'
17
+ );
18
+ this.entityId = entityId;
19
+ this.entityType = this.type;
20
+ }
21
+
22
+ /**
23
+ * Converts the assignment to hash format with camelCase keys
24
+ * @returns Object with camelCase keys: { entityId, entityType, key, value }
25
+ */
26
+ toH(): { entityId: number; entityType: string; key: string; value: string } {
27
+ return {
28
+ entityId: this.entityId,
29
+ entityType: this.entityType,
30
+ key: this.attributeKey,
31
+ value: this.attributeValue,
32
+ };
33
+ }
34
+
35
+ /**
36
+ * Compares two assignments for equality
37
+ * @param other Another EntityAttributeAssignment instance
38
+ * @returns true if all properties are equal
39
+ */
40
+ equals(other: EntityAttributeAssignment): boolean {
41
+ return super.equals(other);
42
+ }
43
+ }
@@ -0,0 +1,7 @@
1
+ export const ENTITY_TYPES = {
2
+ USER: 'user',
3
+ TEAM: 'team',
4
+ ACCOUNT: 'account',
5
+ } as const;
6
+
7
+ export type EntityType = (typeof ENTITY_TYPES)[keyof typeof ENTITY_TYPES];
@@ -0,0 +1,7 @@
1
+ export class ArgumentError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = 'ArgumentError';
5
+ Object.setPrototypeOf(this, ArgumentError.prototype);
6
+ }
7
+ }
package/src/index.ts CHANGED
@@ -57,7 +57,24 @@ export {
57
57
  skipAuthorizationMiddleware,
58
58
  } from './authorization-middleware';
59
59
  export { AuthorizationService, AuthorizeResponse } from './authorization-service';
60
- export { AuthorizationAttributesService } from './authorization-attributes-service';
60
+ export { AuthorizationAttributesSnsService } from './authorization-attributes-sns-service';
61
+ export { AuthorizationAttributesMsService } from './authorization-attributes-ms-service';
62
+ export { ResourceAttributeAssignment } from './resource-attribute-assignment';
63
+ export { RESOURCE_TYPES, RESOURCE_ATTRIBUTES_CONSTANTS } from './resource-attributes-constants';
64
+ export { EntityAttributeAssignment } from './entity-attribute-assignment';
65
+ export { ENTITY_TYPES } from './entity-attributes-constants';
66
+ export { ArgumentError } from './errors/argument-error';
67
+ export {
68
+ ResourceAttributeResponse,
69
+ EntityAttributeResponse,
70
+ ResourceType,
71
+ EntityAttributeKeyType,
72
+ ResourceAttributeKeyType,
73
+ CommonAttributeKey,
74
+ ResourceAttributeKey,
75
+ EntityAttributeKey,
76
+ } from './types/authorization-attributes-contracts';
77
+ export type { EntityType } from './entity-attributes-constants';
61
78
  export { RolesService } from './roles-service';
62
79
  export { MembershipsService } from './memberships';
63
80
  export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
@@ -0,0 +1,43 @@
1
+ import { RESOURCE_TYPES, ResourceType } from './resource-attributes-constants';
2
+ import { BaseAttributeAssignment } from './base-attribute-assignment';
3
+
4
+ export class ResourceAttributeAssignment extends BaseAttributeAssignment<number, ResourceType> {
5
+ public readonly resourceId: number;
6
+ public readonly resourceType: ResourceType;
7
+
8
+ constructor(resourceId: number, resourceType: string, attributeKey: string, attributeValue: string) {
9
+ super(
10
+ resourceId,
11
+ resourceType,
12
+ attributeKey,
13
+ attributeValue,
14
+ Object.values(RESOURCE_TYPES),
15
+ 'resourceId',
16
+ 'resourceType'
17
+ );
18
+ this.resourceId = resourceId;
19
+ this.resourceType = this.type;
20
+ }
21
+
22
+ /**
23
+ * Converts the assignment to hash format with camelCase keys
24
+ * @returns Object with camelCase keys: { resourceId, resourceType, key, value }
25
+ */
26
+ toH(): { resourceId: number; resourceType: string; key: string; value: string } {
27
+ return {
28
+ resourceId: this.resourceId,
29
+ resourceType: this.resourceType,
30
+ key: this.attributeKey,
31
+ value: this.attributeValue,
32
+ };
33
+ }
34
+
35
+ /**
36
+ * Compares two assignments for equality
37
+ * @param other Another ResourceAttributeAssignment instance
38
+ * @returns true if all properties are equal
39
+ */
40
+ equals(other: ResourceAttributeAssignment): boolean {
41
+ return super.equals(other);
42
+ }
43
+ }
@@ -0,0 +1,26 @@
1
+ export const RESOURCE_TYPES = {
2
+ ACCOUNT: 'account',
3
+ ACCOUNT_PRODUCT: 'account_product',
4
+ WORKSPACE: 'workspace',
5
+ BOARD: 'board',
6
+ ITEM: 'item',
7
+ TEAM: 'team',
8
+ OVERVIEW: 'overview',
9
+ DOCUMENT: 'document',
10
+ CRM: 'crm',
11
+ } as const;
12
+
13
+ export const RESOURCE_ATTRIBUTES_CONSTANTS = {
14
+ ACCOUNT_RESOURCE_ATTRIBUTES: {
15
+ ENABLE_MEMBERS_INVITE_FROM_NON_AUTH_DOMAIN: 'enable_members_invite_from_non_auth_domain',
16
+ },
17
+ WORKSPACE_RESOURCE_ATTRIBUTES: {
18
+ IS_DEFAULT_WORKSPACE: 'is_default_workspace',
19
+ },
20
+ BOARD_RESOURCE_ATTRIBUTES: {
21
+ IS_SYNCABLE_CHILD_ENTITY: 'is_syncable_child_entity',
22
+ SYSTEM_ENTITY_TYPE: 'system_entity_type',
23
+ },
24
+ } as const;
25
+
26
+ export type ResourceType = (typeof RESOURCE_TYPES)[keyof typeof RESOURCE_TYPES];
@@ -12,7 +12,7 @@ export class RolesService {
12
12
  private attributionHeaders: { [key: string]: string };
13
13
 
14
14
  /**
15
- * Public constructor to create the AuthorizationAttributesService instance.
15
+ * Public constructor to create the RolesService instance.
16
16
  * @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
17
17
  * @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
18
18
  */
@@ -1,27 +1,71 @@
1
1
  import { Resource } from './general';
2
+ import type { EntityType } from '../entity-attributes-constants';
3
+ import type { ResourceType } from '../resource-attributes-constants';
2
4
 
5
+ export type { EntityType, ResourceType };
6
+
7
+ // Common attribute keys that can be used for both resources and entities
8
+ export type CommonAttributeKey = string;
9
+
10
+ // Resource-specific attribute keys
11
+ export type ResourceAttributeKey = string;
12
+
13
+ // Entity-specific attribute keys
14
+ export type EntityAttributeKey = string;
15
+
16
+ // Combined types for attribute keys
17
+ export type ResourceAttributeKeyType = CommonAttributeKey | ResourceAttributeKey;
18
+ export type EntityAttributeKeyType = CommonAttributeKey | EntityAttributeKey;
19
+
20
+ // Resource Attribute Assignment - matching API contract
3
21
  export interface ResourceAttributeAssignment {
4
- resourceType: Resource['type'];
5
- resourceId: Resource['id'];
6
- key: string;
22
+ resourceId: number;
23
+ resourceType: ResourceType;
24
+ key: ResourceAttributeKeyType;
25
+ value: string;
26
+ }
27
+
28
+ // Entity Attribute Assignment - matching API contract
29
+ // Note: For validation, use the EntityAttributeAssignment class from '../entity-attribute-assignment'
30
+ export interface EntityAttributeAssignment {
31
+ entityId: number;
32
+ entityType: EntityType;
33
+ key: EntityAttributeKeyType;
7
34
  value: string;
8
35
  }
9
36
 
37
+ // Response types
10
38
  export interface ResourceAttributeResponse {
11
39
  attributes: ResourceAttributeAssignment[];
12
40
  }
13
41
 
42
+ export interface EntityAttributeResponse {
43
+ attributes: EntityAttributeAssignment[];
44
+ }
45
+
46
+ // Legacy types for backward compatibility
14
47
  export interface ResourceAttributeDelete {
15
48
  resourceType: Resource['type'];
16
49
  resourceId: Resource['id'];
17
50
  key: string;
18
51
  }
19
52
 
53
+ export interface EntityAttributeDelete {
54
+ entityType: EntityType;
55
+ entityId: number;
56
+ key: string;
57
+ }
58
+
20
59
  export enum ResourceAttributeOperationEnum {
21
60
  UPSERT = 'upsert',
22
61
  DELETE = 'delete',
23
62
  }
24
63
 
64
+ export enum EntityAttributeOperationEnum {
65
+ UPSERT = 'upsert',
66
+ DELETE = 'delete',
67
+ }
68
+
25
69
  interface UpsertResourceAttributeOperation extends ResourceAttributeAssignment {
26
70
  operationType: ResourceAttributeOperationEnum.UPSERT;
27
71
  }
@@ -30,4 +74,13 @@ interface DeleteResourceAttributeOperation extends ResourceAttributeDelete {
30
74
  operationType: ResourceAttributeOperationEnum.DELETE;
31
75
  }
32
76
 
77
+ interface UpsertEntityAttributeOperation extends EntityAttributeAssignment {
78
+ operationType: EntityAttributeOperationEnum.UPSERT;
79
+ }
80
+
81
+ interface DeleteEntityAttributeOperation extends EntityAttributeDelete {
82
+ operationType: EntityAttributeOperationEnum.DELETE;
83
+ }
84
+
33
85
  export type ResourceAttributesOperation = UpsertResourceAttributeOperation | DeleteResourceAttributeOperation;
86
+ export type EntityAttributesOperation = UpsertEntityAttributeOperation | DeleteEntityAttributeOperation;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Replaces path template parameters with actual values
3
+ * @param template Path template with placeholders like {accountId}
4
+ * @param params Object with parameter names and values
5
+ * @returns Path with all placeholders replaced
6
+ */
7
+ export function replacePathParams(template: string, params: Record<string, string | number>): string {
8
+ let path = template;
9
+ for (const [key, value] of Object.entries(params)) {
10
+ path = path.replace(`{${key}}`, String(value));
11
+ }
12
+ return path;
13
+ }
14
+