@mondaydotcomorg/monday-authorization 3.5.1 → 3.5.2-feat-shaime-support-entity-attributes-3-6202ab7

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 (111) hide show
  1. package/dist/authorization-attributes-ms-service.d.ts +72 -0
  2. package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
  3. package/dist/authorization-attributes-ms-service.js +279 -0
  4. package/dist/authorization-attributes-service.d.ts +25 -47
  5. package/dist/authorization-attributes-service.d.ts.map +1 -1
  6. package/dist/authorization-attributes-service.js +32 -171
  7. package/dist/authorization-attributes-sns-service.d.ts +70 -0
  8. package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
  9. package/dist/authorization-attributes-sns-service.js +179 -0
  10. package/dist/base-attribute-assignment.d.ts +19 -0
  11. package/dist/base-attribute-assignment.d.ts.map +1 -0
  12. package/dist/base-attribute-assignment.js +34 -0
  13. package/dist/constants/sns.d.ts +12 -2
  14. package/dist/constants/sns.d.ts.map +1 -1
  15. package/dist/constants/sns.js +22 -2
  16. package/dist/entity-attribute-assignment.d.ts +16 -0
  17. package/dist/entity-attribute-assignment.d.ts.map +1 -0
  18. package/dist/entity-attribute-assignment.js +33 -0
  19. package/dist/entity-attributes-constants.d.ts +7 -0
  20. package/dist/entity-attributes-constants.d.ts.map +1 -0
  21. package/dist/entity-attributes-constants.js +11 -0
  22. package/dist/errors/argument-error.d.ts +4 -0
  23. package/dist/errors/argument-error.d.ts.map +1 -0
  24. package/dist/errors/argument-error.js +10 -0
  25. package/dist/esm/authorization-attributes-ms-service.d.ts +72 -0
  26. package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
  27. package/dist/esm/authorization-attributes-ms-service.mjs +277 -0
  28. package/dist/esm/authorization-attributes-service.d.ts +25 -47
  29. package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
  30. package/dist/esm/authorization-attributes-service.mjs +32 -167
  31. package/dist/esm/authorization-attributes-sns-service.d.ts +70 -0
  32. package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
  33. package/dist/esm/authorization-attributes-sns-service.mjs +173 -0
  34. package/dist/esm/base-attribute-assignment.d.ts +19 -0
  35. package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
  36. package/dist/esm/base-attribute-assignment.mjs +28 -0
  37. package/dist/esm/constants/sns.d.ts +12 -2
  38. package/dist/esm/constants/sns.d.ts.map +1 -1
  39. package/dist/esm/constants/sns.mjs +17 -3
  40. package/dist/esm/entity-attribute-assignment.d.ts +16 -0
  41. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
  42. package/dist/esm/entity-attribute-assignment.mjs +31 -0
  43. package/dist/esm/entity-attributes-constants.d.ts +7 -0
  44. package/dist/esm/entity-attributes-constants.d.ts.map +1 -0
  45. package/dist/esm/entity-attributes-constants.mjs +9 -0
  46. package/dist/esm/errors/argument-error.d.ts +4 -0
  47. package/dist/esm/errors/argument-error.d.ts.map +1 -0
  48. package/dist/esm/errors/argument-error.mjs +8 -0
  49. package/dist/esm/resource-attribute-assignment.d.ts +16 -0
  50. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
  51. package/dist/esm/resource-attribute-assignment.mjs +31 -0
  52. package/dist/esm/resource-attributes-constants.d.ts +25 -0
  53. package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
  54. package/dist/esm/resource-attributes-constants.mjs +28 -0
  55. package/dist/esm/types/authorization-attributes-contracts.d.ts +26 -12
  56. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  57. package/dist/esm/types/authorization-attributes-contracts.mjs +6 -6
  58. package/dist/esm/types/authorization-attributes-service.interface.d.ts +43 -0
  59. package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -0
  60. package/dist/esm/types/authorization-attributes-service.interface.mjs +1 -0
  61. package/dist/esm/types/general.d.ts +1 -1
  62. package/dist/esm/types/general.d.ts.map +1 -1
  63. package/dist/esm/utils/assigment-schema.d.ts +23 -0
  64. package/dist/esm/utils/assigment-schema.d.ts.map +1 -0
  65. package/dist/esm/utils/assigment-schema.mjs +29 -0
  66. package/dist/esm/utils/resource-schema.d.ts +17 -0
  67. package/dist/esm/utils/resource-schema.d.ts.map +1 -0
  68. package/dist/esm/utils/resource-schema.mjs +16 -0
  69. package/dist/esm/utils/validation.d.ts +26 -0
  70. package/dist/esm/utils/validation.d.ts.map +1 -0
  71. package/dist/esm/utils/validation.mjs +70 -0
  72. package/dist/resource-attribute-assignment.d.ts +16 -0
  73. package/dist/resource-attribute-assignment.d.ts.map +1 -0
  74. package/dist/resource-attribute-assignment.js +33 -0
  75. package/dist/resource-attributes-constants.d.ts +25 -0
  76. package/dist/resource-attributes-constants.d.ts.map +1 -0
  77. package/dist/resource-attributes-constants.js +31 -0
  78. package/dist/types/authorization-attributes-contracts.d.ts +26 -12
  79. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  80. package/dist/types/authorization-attributes-contracts.js +5 -5
  81. package/dist/types/authorization-attributes-service.interface.d.ts +43 -0
  82. package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -0
  83. package/dist/types/authorization-attributes-service.interface.js +1 -0
  84. package/dist/types/general.d.ts +1 -1
  85. package/dist/types/general.d.ts.map +1 -1
  86. package/dist/utils/assigment-schema.d.ts +23 -0
  87. package/dist/utils/assigment-schema.d.ts.map +1 -0
  88. package/dist/utils/assigment-schema.js +36 -0
  89. package/dist/utils/resource-schema.d.ts +17 -0
  90. package/dist/utils/resource-schema.d.ts.map +1 -0
  91. package/dist/utils/resource-schema.js +22 -0
  92. package/dist/utils/validation.d.ts +26 -0
  93. package/dist/utils/validation.d.ts.map +1 -0
  94. package/dist/utils/validation.js +76 -0
  95. package/package.json +3 -1
  96. package/src/authorization-attributes-ms-service.ts +414 -0
  97. package/src/authorization-attributes-service.ts +34 -222
  98. package/src/authorization-attributes-sns-service.ts +257 -0
  99. package/src/base-attribute-assignment.ts +30 -0
  100. package/src/constants/sns.ts +19 -2
  101. package/src/entity-attribute-assignment.ts +33 -0
  102. package/src/entity-attributes-constants.ts +7 -0
  103. package/src/errors/argument-error.ts +6 -0
  104. package/src/resource-attribute-assignment.ts +36 -0
  105. package/src/resource-attributes-constants.ts +27 -0
  106. package/src/types/authorization-attributes-contracts.ts +34 -11
  107. package/src/types/authorization-attributes-service.interface.ts +70 -0
  108. package/src/types/general.ts +1 -1
  109. package/src/utils/assigment-schema.ts +29 -0
  110. package/src/utils/resource-schema.ts +21 -0
  111. package/src/utils/validation.ts +82 -0
@@ -0,0 +1,257 @@
1
+ import chunk from 'lodash/chunk.js';
2
+ import { getTopicAttributes, sendToSns } from '@mondaydotcomorg/monday-sns';
3
+ import {
4
+ ResourceAttributeOperation,
5
+ EntityAttributeOperation,
6
+ AttributeOperation,
7
+ } from './types/authorization-attributes-contracts';
8
+ import { Resource } from './types/general';
9
+ import { logger } from './authorization-internal-service';
10
+ import {
11
+ ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
12
+ ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
13
+ RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
14
+ ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
15
+ RESOURCE_SNS_ARN_ENV_VAR_NAME,
16
+ ENTITY_SNS_ARN_ENV_VAR_NAME,
17
+ RESOURCE_SNS_DEV_TEST_NAME,
18
+ ENTITY_SNS_DEV_TEST_NAME,
19
+ SnsTopicType,
20
+ } from './constants/sns';
21
+ import { AuthorizationAttributesService } from './types/authorization-attributes-service.interface';
22
+ import { EntityType } from './entity-attributes-constants';
23
+ import { ValidationUtils } from './utils/validation';
24
+ import type { TopicAttributesMap } from 'aws-sdk/clients/sns';
25
+
26
+ /**
27
+ * Service class for managing resource attributes asynchronously via SNS.
28
+ * Provides asynchronous operations to create/update and delete attributes on resources.
29
+ */
30
+ export class AuthorizationAttributesSnsService implements AuthorizationAttributesService {
31
+ private static LOG_TAG = 'authorization_attributes';
32
+ private resourceSnsArn: string;
33
+ private entitySnsArn: string;
34
+
35
+ /**
36
+ * Public constructor to create the AuthorizationAttributesSnsService instance.
37
+ */
38
+ constructor() {
39
+ this.resourceSnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.RESOURCE);
40
+ this.entitySnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.ENTITY);
41
+ }
42
+
43
+ /**
44
+ * Async function to delete resource attributes using SNS.
45
+ * Sends the updates request to SNS and returns before the change actually took place.
46
+ * @param accountId The account ID
47
+ * @param appName App name of the calling app
48
+ * @param callerActionIdentifier Action identifier
49
+ * @param resource The resource (resourceType, resourceId)
50
+ * @param attributeKeys Array of attribute keys to delete
51
+ * @return Promise with array of sent operations
52
+ */
53
+ async deleteResourceAttributes(
54
+ accountId: number,
55
+ resource: Resource,
56
+ attributeKeys: string[],
57
+ appName?: string,
58
+ callerActionIdentifier?: string
59
+ ): Promise<ResourceAttributeOperation[]> {
60
+ if (!appName || !callerActionIdentifier) {
61
+ throw new Error('appName and callerActionIdentifier are required for SNS service');
62
+ }
63
+ const operations: ResourceAttributeOperation[] = attributeKeys.map(
64
+ key =>
65
+ ({
66
+ resourceType: resource.type,
67
+ resourceId: resource.id,
68
+ key,
69
+ operationType: AttributeOperation.DELETE,
70
+ } as ResourceAttributeOperation)
71
+ );
72
+ return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
73
+ }
74
+
75
+ /**
76
+ * Async function to delete entity attributes using SNS.
77
+ * Sends the updates request to SNS and returns before the change actually took place.
78
+ * @param accountId The account ID
79
+ * @param appName App name of the calling app
80
+ * @param callerActionIdentifier Action identifier
81
+ * @param entityType The entity type
82
+ * @param entityId The entity ID
83
+ * @param attributeKeys Array of attribute keys to delete
84
+ * @return Promise with array of sent operations
85
+ */
86
+ async deleteEntityAttributes(
87
+ accountId: number,
88
+ entityType: EntityType,
89
+ entityId: number,
90
+ attributeKeys: string[],
91
+ appName?: string,
92
+ callerActionIdentifier?: string
93
+ ): Promise<EntityAttributeOperation[]> {
94
+ if (!appName || !callerActionIdentifier) {
95
+ throw new Error('appName and callerActionIdentifier are required for SNS service');
96
+ }
97
+ const operations: EntityAttributeOperation[] = attributeKeys.map(key => {
98
+ ValidationUtils.validateEntityAssignment({ entityId, entityType, key, value: '' });
99
+ return {
100
+ entityType: entityType,
101
+ entityId,
102
+ key,
103
+ operationType: AttributeOperation.DELETE,
104
+ value: '',
105
+ };
106
+ });
107
+ return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
108
+ }
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(
119
+ accountId: number,
120
+ appName: string,
121
+ callerActionIdentifier: string,
122
+ resourceAttributeOperations: ResourceAttributeOperation[]
123
+ ): Promise<ResourceAttributeOperation[]> {
124
+ const topicArn: string = this.resourceSnsArn;
125
+ const sendToSnsPromises: Promise<ResourceAttributeOperation[]>[] = [];
126
+ const operationChucks = chunk(resourceAttributeOperations, ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
127
+ for (const operationsChunk of operationChucks) {
128
+ sendToSnsPromises.push(
129
+ this.sendSingleSnsMessage(
130
+ topicArn,
131
+ accountId,
132
+ appName,
133
+ callerActionIdentifier,
134
+ operationsChunk,
135
+ RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
136
+ 'Authorization resource attributes async update: failed to send operations to SNS'
137
+ )
138
+ );
139
+ }
140
+ return (await Promise.all(sendToSnsPromises)).flat();
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 entityAttributeOperations - Array of operations to do on entity attributes.
149
+ * @return {Promise<EntityAttributeOperation[]>} Array of sent operations
150
+ * */
151
+ async updateEntityAttributes(
152
+ accountId: number,
153
+ appName: string,
154
+ callerActionIdentifier: string,
155
+ entityAttributeOperations: EntityAttributeOperation[]
156
+ ): Promise<EntityAttributeOperation[]> {
157
+ const topicArn: string = this.entitySnsArn;
158
+ const sendToSnsPromises: Promise<EntityAttributeOperation[]>[] = [];
159
+ const operationChucks = chunk(entityAttributeOperations, ASYNC_ENTITY_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
+ ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
169
+ 'Authorization entity attributes async update: failed to send operations to SNS'
170
+ )
171
+ );
172
+ }
173
+ return (await Promise.all(sendToSnsPromises)).flat();
174
+ }
175
+
176
+ private async sendSingleSnsMessage<T extends ResourceAttributeOperation | EntityAttributeOperation>(
177
+ topicArn: string,
178
+ accountId: number,
179
+ appName: string,
180
+ callerActionIdentifier: string,
181
+ operations: T[],
182
+ kind: string,
183
+ errorLogMessage: string
184
+ ): Promise<T[]> {
185
+ const payload = {
186
+ kind,
187
+ payload: {
188
+ accountId: accountId,
189
+ callerAppName: appName,
190
+ callerActionIdentifier: callerActionIdentifier,
191
+ operations: operations,
192
+ },
193
+ };
194
+ try {
195
+ await sendToSns(payload, topicArn);
196
+ return operations;
197
+ } catch (error) {
198
+ logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, errorLogMessage);
199
+ return [];
200
+ }
201
+ }
202
+
203
+ private static getSnsTopicArn(type: SnsTopicType): string {
204
+ let envVarName: string;
205
+ let devTestName: string;
206
+
207
+ switch (type) {
208
+ case SnsTopicType.ENTITY:
209
+ envVarName = ENTITY_SNS_ARN_ENV_VAR_NAME;
210
+ devTestName = ENTITY_SNS_DEV_TEST_NAME;
211
+ break;
212
+ default:
213
+ // Default to resource SNS constants
214
+ envVarName = RESOURCE_SNS_ARN_ENV_VAR_NAME;
215
+ devTestName = RESOURCE_SNS_DEV_TEST_NAME;
216
+ break;
217
+ }
218
+
219
+ const arnFromEnv: string | undefined = process.env[envVarName];
220
+ if (arnFromEnv) {
221
+ return arnFromEnv;
222
+ }
223
+ if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
224
+ return devTestName;
225
+ }
226
+ throw new Error(`Unable to get ${type} sns topic arn from env variable`);
227
+ }
228
+
229
+ /**
230
+ * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
231
+ * This function can be used as health check for services that updating resource attributes in async is crucial.
232
+ * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
233
+ * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
234
+ * However, this is the best we can do without actually push dummy messages to the SNS.
235
+ * @return {Promise<boolean>} - true if succeeded
236
+ */
237
+ async asyncResourceAttributesHealthCheck(): Promise<boolean> {
238
+ try {
239
+ const requestedTopicArn: string = this.resourceSnsArn;
240
+ const attributes: TopicAttributesMap = await getTopicAttributes(requestedTopicArn);
241
+ const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
242
+ if (!isHealthy) {
243
+ logger.error(
244
+ { requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesSnsService.LOG_TAG },
245
+ 'authorization-attributes-service failed in health check'
246
+ );
247
+ }
248
+ return isHealthy;
249
+ } catch (error) {
250
+ logger.error(
251
+ { error, tag: AuthorizationAttributesSnsService.LOG_TAG },
252
+ 'authorization-attributes-service got error during health check'
253
+ );
254
+ return false;
255
+ }
256
+ }
257
+ }
@@ -0,0 +1,30 @@
1
+ import isEqual from 'lodash/isEqual.js';
2
+
3
+ /**
4
+ * Base class for attribute assignments (Resource or Entity)
5
+ * Provides common validation and functionality
6
+ */
7
+ export abstract class BaseAttributeAssignment<T, R> {
8
+ public readonly id: number;
9
+ public readonly type: T;
10
+ public readonly attributeKey: string;
11
+ public readonly attributeValue: string;
12
+
13
+ constructor(id: number, type: T, attributeKey: string, attributeValue: string) {
14
+ this.id = id;
15
+ this.type = type;
16
+ this.attributeKey = attributeKey;
17
+ this.attributeValue = attributeValue;
18
+ }
19
+
20
+ /**
21
+ * Compares two assignments for equality
22
+ * @param other Another assignment instance
23
+ * @returns true if all properties are equal
24
+ */
25
+ equals(other: BaseAttributeAssignment<T, R>): boolean {
26
+ return isEqual(this, other);
27
+ }
28
+
29
+ abstract toDataTransferObject(): R;
30
+ }
@@ -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;
@@ -0,0 +1,33 @@
1
+ import { EntityType } from './entity-attributes-constants';
2
+ import { BaseAttributeAssignment } from './base-attribute-assignment';
3
+ import { EntityAttributeAssignment as EntityAttributeAssignmentContract } from './types/authorization-attributes-contracts';
4
+ import { ValidationUtils } from './utils/validation';
5
+
6
+ export class EntityAttributeAssignment extends BaseAttributeAssignment<EntityType, EntityAttributeAssignmentContract> {
7
+ public readonly entityId: number;
8
+ public readonly entityType: EntityType;
9
+
10
+ constructor(entityId: number, entityType: EntityType, attributeKey: string, attributeValue: string) {
11
+ ValidationUtils.validateEntityAssignment({ entityId, entityType, key: attributeKey, value: attributeValue });
12
+ super(entityId, entityType, attributeKey, attributeValue);
13
+ this.entityId = entityId;
14
+ this.entityType = entityType;
15
+ }
16
+
17
+ toDataTransferObject(): EntityAttributeAssignmentContract {
18
+ return {
19
+ entityId: this.entityId,
20
+ entityType: this.entityType,
21
+ key: this.attributeKey,
22
+ value: this.attributeValue,
23
+ };
24
+ }
25
+ /**
26
+ * Compares two assignments for equality
27
+ * @param other Another EntityAttributeAssignment instance
28
+ * @returns true if all properties are equal
29
+ */
30
+ equals(other: EntityAttributeAssignment): boolean {
31
+ return super.equals(other);
32
+ }
33
+ }
@@ -0,0 +1,7 @@
1
+ export enum EntityType {
2
+ User = 'user',
3
+ Team = 'team',
4
+ Account = 'account',
5
+ }
6
+
7
+ export const ENTITY_TYPES = Object.freeze(Object.values(EntityType));
@@ -0,0 +1,6 @@
1
+ export class ArgumentError extends Error {
2
+ constructor(message: string) {
3
+ super(message);
4
+ this.name = 'ArgumentError';
5
+ }
6
+ }
@@ -0,0 +1,36 @@
1
+ import { ResourceType } from './resource-attributes-constants';
2
+ import { BaseAttributeAssignment } from './base-attribute-assignment';
3
+ import { ResourceAttributeAssignment as ResourceAttributeAssignmentContract } from './types/authorization-attributes-contracts';
4
+ import { ValidationUtils } from './utils/validation';
5
+
6
+ export class ResourceAttributeAssignment extends BaseAttributeAssignment<
7
+ ResourceType,
8
+ ResourceAttributeAssignmentContract
9
+ > {
10
+ public readonly resourceId: number;
11
+ public readonly resourceType: ResourceType;
12
+
13
+ constructor(resourceId: number, resourceType: ResourceType, attributeKey: string, attributeValue: string) {
14
+ ValidationUtils.validateResourceAssignment({ resourceId, resourceType, key: attributeKey, value: attributeValue });
15
+ super(resourceId, resourceType, attributeKey, attributeValue);
16
+ this.resourceId = resourceId;
17
+ this.resourceType = this.type;
18
+ }
19
+
20
+ toDataTransferObject(): ResourceAttributeAssignmentContract {
21
+ return {
22
+ resourceId: this.resourceId,
23
+ resourceType: this.resourceType,
24
+ key: this.attributeKey,
25
+ value: this.attributeValue,
26
+ };
27
+ }
28
+ /**
29
+ * Compares two assignments for equality
30
+ * @param other Another ResourceAttributeAssignment instance
31
+ * @returns true if all properties are equal
32
+ */
33
+ equals(other: ResourceAttributeAssignment): boolean {
34
+ return super.equals(other);
35
+ }
36
+ }
@@ -0,0 +1,27 @@
1
+ export const RESOURCE_ATTRIBUTES_CONSTANTS = Object.freeze({
2
+ ACCOUNT_RESOURCE_ATTRIBUTES: {
3
+ ENABLE_MEMBERS_INVITE_FROM_NON_AUTH_DOMAIN: 'enable_members_invite_from_non_auth_domain',
4
+ },
5
+ WORKSPACE_RESOURCE_ATTRIBUTES: {
6
+ IS_DEFAULT_WORKSPACE: 'is_default_workspace',
7
+ },
8
+ BOARD_RESOURCE_ATTRIBUTES: {
9
+ IS_SYNCABLE_CHILD_ENTITY: 'is_syncable_child_entity',
10
+ SYSTEM_ENTITY_TYPE: 'system_entity_type',
11
+ },
12
+ });
13
+
14
+ export enum ResourceType {
15
+ Account = 'account',
16
+ AccountProduct = 'account_product',
17
+ Workspace = 'workspace',
18
+ Board = 'board',
19
+ Item = 'item',
20
+ Team = 'team',
21
+ Overview = 'overview',
22
+ Document = 'document',
23
+ Crm = 'crm',
24
+ }
25
+
26
+ // Define the array of strings and use 'as const' to make its contents literal types
27
+ export const RESOURCE_TYPES = Object.freeze(Object.values(ResourceType));
@@ -1,33 +1,56 @@
1
1
  import { Resource } from './general';
2
+ import type { EntityType } from '../entity-attributes-constants';
3
+ import type { ResourceType } from '../resource-attributes-constants';
2
4
 
3
- export interface ResourceAttributeAssignment {
4
- resourceType: Resource['type'];
5
- resourceId: Resource['id'];
5
+ export interface AttributeAssignment {
6
6
  key: string;
7
7
  value: string;
8
8
  }
9
9
 
10
- export interface ResourceAttributeResponse {
11
- attributes: ResourceAttributeAssignment[];
10
+ // Resource Attribute Assignment - matching API contract
11
+ export interface ResourceAttributeAssignment extends AttributeAssignment {
12
+ resourceId: number;
13
+ resourceType: ResourceType;
12
14
  }
13
15
 
16
+ // Entity Attribute Assignment - matching API contract
17
+ // Note: For validation, use the EntityAttributeAssignment class from '../entity-attribute-assignment'
18
+ export interface EntityAttributeAssignment extends AttributeAssignment {
19
+ entityId: number;
20
+ entityType: EntityType;
21
+ }
22
+
23
+ // Legacy types for backward compatibility
14
24
  export interface ResourceAttributeDelete {
15
25
  resourceType: Resource['type'];
16
26
  resourceId: Resource['id'];
17
27
  key: string;
18
28
  }
19
29
 
20
- export enum ResourceAttributeOperationEnum {
30
+ export interface EntityAttributeDelete {
31
+ entityType: EntityType;
32
+ entityId: number;
33
+ key: string;
34
+ }
35
+
36
+ export enum AttributeOperation {
21
37
  UPSERT = 'upsert',
22
38
  DELETE = 'delete',
23
39
  }
24
40
 
25
- interface UpsertResourceAttributeOperation extends ResourceAttributeAssignment {
26
- operationType: ResourceAttributeOperationEnum.UPSERT;
41
+ // Response types
42
+ export interface ResourceAttributeResponse {
43
+ attributes: ResourceAttributeAssignment[];
27
44
  }
28
45
 
29
- interface DeleteResourceAttributeOperation extends ResourceAttributeDelete {
30
- operationType: ResourceAttributeOperationEnum.DELETE;
46
+ export interface EntityAttributeResponse {
47
+ attributes: EntityAttributeAssignment[];
31
48
  }
32
49
 
33
- export type ResourceAttributesOperation = UpsertResourceAttributeOperation | DeleteResourceAttributeOperation;
50
+ export interface ResourceAttributeOperation extends ResourceAttributeAssignment {
51
+ operationType: AttributeOperation;
52
+ }
53
+
54
+ export interface EntityAttributeOperation extends EntityAttributeAssignment {
55
+ operationType: AttributeOperation;
56
+ }
@@ -0,0 +1,70 @@
1
+ import { EntityType } from '../entity-attributes-constants';
2
+ import { ResourceAttributeOperation, EntityAttributeOperation } from './authorization-attributes-contracts';
3
+ import { Resource } from './general';
4
+
5
+ /**
6
+ * Resource type compatible with both MS and SNS services
7
+ */
8
+ export interface CompatibleResource {
9
+ resourceType?: string;
10
+ resourceId?: number;
11
+ type?: string;
12
+ id?: number;
13
+ }
14
+
15
+ /**
16
+ * Interface for authorization attributes operations.
17
+ * Both MS (direct) and SNS (async) services implement this interface.
18
+ */
19
+ export interface AuthorizationAttributesService {
20
+ /**
21
+ * Deletes resource attributes.
22
+ * For MS service: returns Promise<void>
23
+ * For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
24
+ */
25
+ deleteResourceAttributes(
26
+ accountId: number,
27
+ resource: CompatibleResource | Resource,
28
+ attributeKeys: string[],
29
+ appName?: string,
30
+ callerActionIdentifier?: string
31
+ ): Promise<void | ResourceAttributeOperation[]>;
32
+
33
+ /**
34
+ * Deletes entity attributes.
35
+ * For MS service: returns Promise<void>
36
+ * For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
37
+ */
38
+ deleteEntityAttributes(
39
+ accountId: number,
40
+ entityType: EntityType | string,
41
+ entityId: number,
42
+ attributeKeys: string[],
43
+ appName?: string,
44
+ callerActionIdentifier?: string
45
+ ): Promise<void | EntityAttributeOperation[]>;
46
+
47
+ /**
48
+ * Updates resource attributes (batch operations).
49
+ * For MS service: may throw error or delegate to upsert/delete
50
+ * For SNS service: returns Promise<ResourceAttributesOperation[]>
51
+ */
52
+ updateResourceAttributes(
53
+ accountId: number,
54
+ appName: string,
55
+ callerActionIdentifier: string,
56
+ resourceAttributeOperations: ResourceAttributeOperation[]
57
+ ): Promise<ResourceAttributeOperation[]>;
58
+
59
+ /**
60
+ * Updates entity attributes (batch operations).
61
+ * For MS service: may throw error or delegate to upsert/delete
62
+ * For SNS service: returns Promise<EntityAttributesOperation[]>
63
+ */
64
+ updateEntityAttributes(
65
+ accountId: number,
66
+ appName: string,
67
+ callerActionIdentifier: string,
68
+ entityAttributeOperations: EntityAttributeOperation[]
69
+ ): Promise<EntityAttributeOperation[]>;
70
+ }
@@ -1,7 +1,7 @@
1
1
  import type { Request, Response } from 'express';
2
2
 
3
3
  export interface Resource {
4
- id?: number;
4
+ id: number;
5
5
  type: string;
6
6
  wrapperData?: object;
7
7
  }
@@ -0,0 +1,29 @@
1
+ import Ajv from 'ajv';
2
+ import { EntityType } from '../entity-attributes-constants';
3
+ import { ResourceType } from '../resource-attributes-constants';
4
+
5
+ const ajv = new Ajv({ allErrors: true });
6
+
7
+ export const entityAssignmentSchema = ajv.compile({
8
+ type: 'object',
9
+ properties: {
10
+ entityId: { type: 'number', multipleOf: 1 },
11
+ entityType: { type: 'string', enum: Object.values(EntityType) },
12
+ key: { type: 'string', minLength: 1 },
13
+ value: { type: 'string' },
14
+ },
15
+ required: ['entityId', 'entityType', 'key'],
16
+ additionalProperties: false,
17
+ });
18
+
19
+ export const resourceAssignmentSchema = ajv.compile({
20
+ type: 'object',
21
+ properties: {
22
+ id: { type: 'number', multipleOf: 1 },
23
+ type: { type: 'string', enum: Object.values(ResourceType) },
24
+ key: { type: 'string', minLength: 1 },
25
+ value: { type: 'string' },
26
+ },
27
+ required: ['id', 'type', 'key'],
28
+ additionalProperties: false,
29
+ });
@@ -0,0 +1,21 @@
1
+ import Ajv from 'ajv';
2
+ import { RESOURCE_TYPES } from '../resource-attributes-constants';
3
+
4
+ const ajv = new Ajv({ allErrors: true });
5
+
6
+ export interface Resource {
7
+ id?: number;
8
+ type: string;
9
+ wrapperData?: object;
10
+ }
11
+
12
+ export const resourceSchema = ajv.compile({
13
+ type: 'object',
14
+ properties: {
15
+ id: { type: 'number', multipleOf: 1 },
16
+ type: { type: 'string', enum: RESOURCE_TYPES },
17
+ wrapperData: { type: 'string', minLength: 1 },
18
+ },
19
+ required: ['id', 'type', 'wrapperData'],
20
+ additionalProperties: false,
21
+ });