@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.
- package/dist/authorization-attributes-ms-service.d.ts +72 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/authorization-attributes-ms-service.js +279 -0
- package/dist/authorization-attributes-service.d.ts +25 -47
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +32 -171
- package/dist/authorization-attributes-sns-service.d.ts +70 -0
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/authorization-attributes-sns-service.js +179 -0
- package/dist/base-attribute-assignment.d.ts +19 -0
- package/dist/base-attribute-assignment.d.ts.map +1 -0
- package/dist/base-attribute-assignment.js +34 -0
- package/dist/constants/sns.d.ts +12 -2
- package/dist/constants/sns.d.ts.map +1 -1
- package/dist/constants/sns.js +22 -2
- package/dist/entity-attribute-assignment.d.ts +16 -0
- package/dist/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/entity-attribute-assignment.js +33 -0
- package/dist/entity-attributes-constants.d.ts +7 -0
- package/dist/entity-attributes-constants.d.ts.map +1 -0
- package/dist/entity-attributes-constants.js +11 -0
- package/dist/errors/argument-error.d.ts +4 -0
- package/dist/errors/argument-error.d.ts.map +1 -0
- package/dist/errors/argument-error.js +10 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts +72 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-ms-service.mjs +277 -0
- package/dist/esm/authorization-attributes-service.d.ts +25 -47
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +32 -167
- package/dist/esm/authorization-attributes-sns-service.d.ts +70 -0
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-sns-service.mjs +173 -0
- package/dist/esm/base-attribute-assignment.d.ts +19 -0
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/base-attribute-assignment.mjs +28 -0
- package/dist/esm/constants/sns.d.ts +12 -2
- package/dist/esm/constants/sns.d.ts.map +1 -1
- package/dist/esm/constants/sns.mjs +17 -3
- package/dist/esm/entity-attribute-assignment.d.ts +16 -0
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/entity-attribute-assignment.mjs +31 -0
- package/dist/esm/entity-attributes-constants.d.ts +7 -0
- package/dist/esm/entity-attributes-constants.d.ts.map +1 -0
- package/dist/esm/entity-attributes-constants.mjs +9 -0
- package/dist/esm/errors/argument-error.d.ts +4 -0
- package/dist/esm/errors/argument-error.d.ts.map +1 -0
- package/dist/esm/errors/argument-error.mjs +8 -0
- package/dist/esm/resource-attribute-assignment.d.ts +16 -0
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/resource-attribute-assignment.mjs +31 -0
- package/dist/esm/resource-attributes-constants.d.ts +25 -0
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
- package/dist/esm/resource-attributes-constants.mjs +28 -0
- package/dist/esm/types/authorization-attributes-contracts.d.ts +26 -12
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.mjs +6 -6
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +43 -0
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -0
- package/dist/esm/types/authorization-attributes-service.interface.mjs +1 -0
- package/dist/esm/types/general.d.ts +1 -1
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/utils/assigment-schema.d.ts +23 -0
- package/dist/esm/utils/assigment-schema.d.ts.map +1 -0
- package/dist/esm/utils/assigment-schema.mjs +29 -0
- package/dist/esm/utils/resource-schema.d.ts +17 -0
- package/dist/esm/utils/resource-schema.d.ts.map +1 -0
- package/dist/esm/utils/resource-schema.mjs +16 -0
- package/dist/esm/utils/validation.d.ts +26 -0
- package/dist/esm/utils/validation.d.ts.map +1 -0
- package/dist/esm/utils/validation.mjs +70 -0
- package/dist/resource-attribute-assignment.d.ts +16 -0
- package/dist/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/resource-attribute-assignment.js +33 -0
- package/dist/resource-attributes-constants.d.ts +25 -0
- package/dist/resource-attributes-constants.d.ts.map +1 -0
- package/dist/resource-attributes-constants.js +31 -0
- package/dist/types/authorization-attributes-contracts.d.ts +26 -12
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.js +5 -5
- package/dist/types/authorization-attributes-service.interface.d.ts +43 -0
- package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -0
- package/dist/types/authorization-attributes-service.interface.js +1 -0
- package/dist/types/general.d.ts +1 -1
- package/dist/types/general.d.ts.map +1 -1
- package/dist/utils/assigment-schema.d.ts +23 -0
- package/dist/utils/assigment-schema.d.ts.map +1 -0
- package/dist/utils/assigment-schema.js +36 -0
- package/dist/utils/resource-schema.d.ts +17 -0
- package/dist/utils/resource-schema.d.ts.map +1 -0
- package/dist/utils/resource-schema.js +22 -0
- package/dist/utils/validation.d.ts +26 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +76 -0
- package/package.json +3 -1
- package/src/authorization-attributes-ms-service.ts +414 -0
- package/src/authorization-attributes-service.ts +34 -222
- package/src/authorization-attributes-sns-service.ts +257 -0
- package/src/base-attribute-assignment.ts +30 -0
- package/src/constants/sns.ts +19 -2
- package/src/entity-attribute-assignment.ts +33 -0
- package/src/entity-attributes-constants.ts +7 -0
- package/src/errors/argument-error.ts +6 -0
- package/src/resource-attribute-assignment.ts +36 -0
- package/src/resource-attributes-constants.ts +27 -0
- package/src/types/authorization-attributes-contracts.ts +34 -11
- package/src/types/authorization-attributes-service.interface.ts +70 -0
- package/src/types/general.ts +1 -1
- package/src/utils/assigment-schema.ts +29 -0
- package/src/utils/resource-schema.ts +21 -0
- 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
|
+
}
|
package/src/constants/sns.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
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,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
|
|
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
|
-
|
|
11
|
-
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
41
|
+
// Response types
|
|
42
|
+
export interface ResourceAttributeResponse {
|
|
43
|
+
attributes: ResourceAttributeAssignment[];
|
|
27
44
|
}
|
|
28
45
|
|
|
29
|
-
interface
|
|
30
|
-
|
|
46
|
+
export interface EntityAttributeResponse {
|
|
47
|
+
attributes: EntityAttributeAssignment[];
|
|
31
48
|
}
|
|
32
49
|
|
|
33
|
-
export
|
|
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
|
+
}
|
package/src/types/general.ts
CHANGED
|
@@ -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
|
+
});
|