@mondaydotcomorg/monday-authorization 3.7.0-feat-shaime-support-entity-attributes-4-49e1de0 → 3.7.1
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/README.md +7 -1
- package/dist/authorization-attributes-ms-service.d.ts +20 -40
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -1
- package/dist/authorization-attributes-ms-service.js +48 -103
- package/dist/authorization-attributes-service.d.ts +12 -10
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +17 -15
- package/dist/authorization-attributes-sns-service.d.ts +37 -44
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -1
- package/dist/authorization-attributes-sns-service.js +53 -90
- package/dist/authorization-service.d.ts +0 -1
- package/dist/authorization-service.d.ts.map +1 -1
- package/dist/authorization-service.js +2 -22
- package/dist/base-attribute-assignment.d.ts +6 -7
- package/dist/base-attribute-assignment.d.ts.map +1 -1
- package/dist/base-attribute-assignment.js +5 -7
- package/dist/base-authorization-attributes-service.d.ts +32 -0
- package/dist/base-authorization-attributes-service.d.ts.map +1 -0
- package/dist/base-authorization-attributes-service.js +63 -0
- package/dist/entity-attribute-assignment.d.ts +4 -8
- package/dist/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/entity-attribute-assignment.js +3 -4
- package/dist/esm/authorization-attributes-ms-service.d.ts +20 -40
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-ms-service.mjs +48 -103
- package/dist/esm/authorization-attributes-service.d.ts +12 -10
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +17 -15
- package/dist/esm/authorization-attributes-sns-service.d.ts +37 -44
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-sns-service.mjs +53 -90
- package/dist/esm/authorization-service.d.ts +0 -1
- package/dist/esm/authorization-service.d.ts.map +1 -1
- package/dist/esm/authorization-service.mjs +3 -23
- package/dist/esm/base-attribute-assignment.d.ts +6 -7
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/base-attribute-assignment.mjs +5 -7
- package/dist/esm/base-authorization-attributes-service.d.ts +32 -0
- package/dist/esm/base-authorization-attributes-service.d.ts.map +1 -0
- package/dist/esm/base-authorization-attributes-service.mjs +61 -0
- package/dist/esm/entity-attribute-assignment.d.ts +4 -8
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/entity-attribute-assignment.mjs +3 -4
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.mjs +6 -0
- package/dist/esm/resource-attribute-assignment.d.ts +3 -7
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.mjs +8 -2
- package/dist/esm/resource-attributes-constants.d.ts +12 -10
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -1
- package/dist/esm/resource-attributes-constants.mjs +4 -2
- package/dist/esm/testKit/index.d.ts +4 -4
- package/dist/esm/testKit/index.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.d.ts +7 -21
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/general.d.ts +4 -3
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/utils/assignment-schema.d.ts +51 -0
- package/dist/esm/utils/assignment-schema.d.ts.map +1 -0
- package/dist/esm/utils/assignment-schema.mjs +54 -0
- package/dist/esm/utils/resource-schema.d.ts +9 -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 +11 -28
- package/dist/esm/utils/validation.d.ts.map +1 -1
- package/dist/esm/utils/validation.mjs +61 -118
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -0
- package/dist/resource-attribute-assignment.d.ts +3 -7
- package/dist/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.js +8 -2
- package/dist/resource-attributes-constants.d.ts +12 -10
- package/dist/resource-attributes-constants.d.ts.map +1 -1
- package/dist/resource-attributes-constants.js +4 -2
- package/dist/testKit/index.d.ts +4 -4
- package/dist/testKit/index.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.d.ts +7 -21
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/general.d.ts +4 -3
- package/dist/types/general.d.ts.map +1 -1
- package/dist/utils/assignment-schema.d.ts +51 -0
- package/dist/utils/assignment-schema.d.ts.map +1 -0
- package/dist/utils/assignment-schema.js +63 -0
- package/dist/utils/resource-schema.d.ts +9 -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 +11 -28
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +61 -118
- package/package.json +2 -3
- package/src/authorization-attributes-ms-service.ts +92 -154
- package/src/authorization-attributes-service.ts +18 -16
- package/src/authorization-attributes-sns-service.ts +132 -131
- package/src/authorization-service.ts +3 -28
- package/src/base-attribute-assignment.ts +10 -26
- package/src/base-authorization-attributes-service.ts +90 -0
- package/src/entity-attribute-assignment.ts +7 -6
- package/src/index.ts +17 -0
- package/src/resource-attribute-assignment.ts +13 -10
- package/src/resource-attributes-constants.ts +4 -2
- package/src/testKit/index.ts +5 -5
- package/src/types/authorization-attributes-contracts.ts +7 -27
- package/src/types/general.ts +4 -3
- package/src/utils/assignment-schema.ts +56 -0
- package/src/utils/resource-schema.ts +16 -0
- package/src/utils/validation.ts +90 -137
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +0 -57
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +0 -1
- package/dist/esm/types/authorization-attributes-service.interface.mjs +0 -1
- package/dist/types/authorization-attributes-service.interface.d.ts +0 -57
- package/dist/types/authorization-attributes-service.interface.d.ts.map +0 -1
- package/dist/types/authorization-attributes-service.interface.js +0 -1
- package/src/types/authorization-attributes-service.interface.ts +0 -101
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import chunk from 'lodash/chunk.js';
|
|
2
2
|
import { getTopicAttributes, sendToSns } from '@mondaydotcomorg/monday-sns';
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
ResourceAttributeUpsertOperation,
|
|
5
|
+
EntityAttributeUpsertOperation,
|
|
6
|
+
EntityAttributeDeleteOperation,
|
|
7
|
+
ResourceAttributeDeleteOperation,
|
|
8
8
|
} from './types/authorization-attributes-contracts';
|
|
9
|
-
import { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
10
9
|
import { Resource } from './types/general';
|
|
11
10
|
import { logger } from './authorization-internal-service';
|
|
12
11
|
import {
|
|
@@ -20,15 +19,15 @@ import {
|
|
|
20
19
|
ENTITY_SNS_DEV_TEST_NAME,
|
|
21
20
|
SnsTopicType,
|
|
22
21
|
} from './constants/sns';
|
|
23
|
-
import
|
|
24
|
-
import { AuthorizationAttributesService } from './types/authorization-attributes-service.interface';
|
|
22
|
+
import { BaseAuthorizationAttributesService } from './base-authorization-attributes-service';
|
|
25
23
|
import { EntityType } from './entity-attributes-constants';
|
|
24
|
+
import type { TopicAttributesMap } from 'aws-sdk/clients/sns';
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
27
|
* Service class for managing resource attributes asynchronously via SNS.
|
|
29
28
|
* Provides asynchronous operations to create/update and delete attributes on resources.
|
|
30
29
|
*/
|
|
31
|
-
export class AuthorizationAttributesSnsService
|
|
30
|
+
export class AuthorizationAttributesSnsService extends BaseAuthorizationAttributesService {
|
|
32
31
|
private static LOG_TAG = 'authorization_attributes';
|
|
33
32
|
private resourceSnsArn: string;
|
|
34
33
|
private entitySnsArn: string;
|
|
@@ -37,182 +36,178 @@ export class AuthorizationAttributesSnsService implements AuthorizationAttribute
|
|
|
37
36
|
* Public constructor to create the AuthorizationAttributesSnsService instance.
|
|
38
37
|
*/
|
|
39
38
|
constructor() {
|
|
39
|
+
super();
|
|
40
40
|
this.resourceSnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.RESOURCE);
|
|
41
41
|
this.entitySnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(SnsTopicType.ENTITY);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Async function to
|
|
46
|
-
* Sends the
|
|
47
|
-
* @param accountId The account ID
|
|
48
|
-
* @param appName App name of the calling app
|
|
49
|
-
* @param callerActionIdentifier Action identifier
|
|
50
|
-
* @param resourceAttributeAssignments Array of resource attribute assignments to upsert
|
|
51
|
-
* @return Promise with array of sent operations
|
|
52
|
-
*/
|
|
53
|
-
async upsertResourceAttributes(
|
|
54
|
-
accountId: number,
|
|
55
|
-
resourceAttributeAssignments: ResourceAttributeAssignment[],
|
|
56
|
-
appName?: string,
|
|
57
|
-
callerActionIdentifier?: string
|
|
58
|
-
): Promise<ResourceAttributeOperation[]> {
|
|
59
|
-
if (!appName || !callerActionIdentifier) {
|
|
60
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
61
|
-
}
|
|
62
|
-
const operations: ResourceAttributeOperation[] = resourceAttributeAssignments.map(assignment => ({
|
|
63
|
-
...assignment,
|
|
64
|
-
operationType: AttributeOperation.UPSERT,
|
|
65
|
-
}));
|
|
66
|
-
return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Async function to delete resource attributes using SNS.
|
|
71
|
-
* Sends the updates request to SNS and returns before the change actually took place.
|
|
45
|
+
* Async function to delete a resource attribute using SNS.
|
|
46
|
+
* Sends the delete request to SNS and returns before the change actually took place.
|
|
72
47
|
* @param accountId The account ID
|
|
48
|
+
* @param resource The resource (resourceType, resourceId)
|
|
49
|
+
* @param attributeKey Attribute key to delete
|
|
73
50
|
* @param appName App name of the calling app
|
|
74
51
|
* @param callerActionIdentifier Action identifier
|
|
75
|
-
* @
|
|
76
|
-
* @param attributeKeys Array of attribute keys to delete
|
|
77
|
-
* @return Promise with array of sent operations
|
|
52
|
+
* @return Promise with sent operation
|
|
78
53
|
*/
|
|
79
54
|
async deleteResourceAttributes(
|
|
80
55
|
accountId: number,
|
|
81
56
|
resource: Resource,
|
|
82
|
-
|
|
57
|
+
attributeKey: string,
|
|
83
58
|
appName?: string,
|
|
84
59
|
callerActionIdentifier?: string
|
|
85
|
-
): Promise<
|
|
60
|
+
): Promise<ResourceAttributeDeleteOperation> {
|
|
86
61
|
if (!appName || !callerActionIdentifier) {
|
|
87
62
|
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
88
63
|
}
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
resourceId: resource.id!,
|
|
94
|
-
key,
|
|
95
|
-
operationType: AttributeOperation.DELETE,
|
|
96
|
-
} as ResourceAttributeOperation)
|
|
64
|
+
const operation: ResourceAttributeDeleteOperation = await super.deleteResourceAttributes(
|
|
65
|
+
accountId,
|
|
66
|
+
resource,
|
|
67
|
+
attributeKey
|
|
97
68
|
);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*/
|
|
110
|
-
async upsertEntityAttributes(
|
|
111
|
-
accountId: number,
|
|
112
|
-
entityAttributeAssignments: EntityAttributeAssignment[],
|
|
113
|
-
appName?: string,
|
|
114
|
-
callerActionIdentifier?: string
|
|
115
|
-
): Promise<EntityAttributeOperation[]> {
|
|
116
|
-
if (!appName || !callerActionIdentifier) {
|
|
117
|
-
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
118
|
-
}
|
|
119
|
-
const operations: EntityAttributeOperation[] = entityAttributeAssignments.map(assignment => {
|
|
120
|
-
return {
|
|
121
|
-
entityId: assignment.entityId,
|
|
122
|
-
entityType: assignment.entityType,
|
|
123
|
-
key: assignment.attributeKey,
|
|
124
|
-
value: assignment.attributeValue,
|
|
125
|
-
operationType: AttributeOperation.UPSERT,
|
|
126
|
-
};
|
|
127
|
-
});
|
|
128
|
-
return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
|
|
69
|
+
const [result] = await this.sendOperationsToSns(
|
|
70
|
+
this.resourceSnsArn,
|
|
71
|
+
accountId,
|
|
72
|
+
appName,
|
|
73
|
+
callerActionIdentifier,
|
|
74
|
+
[operation],
|
|
75
|
+
ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
76
|
+
RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
77
|
+
'Authorization resource attributes async delete: failed to send operations to SNS'
|
|
78
|
+
);
|
|
79
|
+
return result;
|
|
129
80
|
}
|
|
130
81
|
|
|
131
82
|
/**
|
|
132
|
-
* Async function to delete entity
|
|
133
|
-
* Sends the
|
|
83
|
+
* Async function to delete an entity attribute using SNS.
|
|
84
|
+
* Sends the delete request to SNS and returns before the change actually took place.
|
|
134
85
|
* @param accountId The account ID
|
|
135
|
-
* @param appName App name of the calling app
|
|
136
|
-
* @param callerActionIdentifier Action identifier
|
|
137
86
|
* @param entityType The entity type
|
|
138
87
|
* @param entityId The entity ID
|
|
139
|
-
* @param
|
|
140
|
-
* @
|
|
88
|
+
* @param attributeKey Attribute key to delete
|
|
89
|
+
* @param appName App name of the calling app
|
|
90
|
+
* @param callerActionIdentifier Action identifier
|
|
91
|
+
* @return Promise with sent operation
|
|
141
92
|
*/
|
|
142
93
|
async deleteEntityAttributes(
|
|
143
94
|
accountId: number,
|
|
144
|
-
entityType: EntityType
|
|
95
|
+
entityType: EntityType,
|
|
145
96
|
entityId: number,
|
|
146
|
-
|
|
97
|
+
attributeKey: string,
|
|
147
98
|
appName?: string,
|
|
148
99
|
callerActionIdentifier?: string
|
|
149
|
-
): Promise<
|
|
100
|
+
): Promise<EntityAttributeDeleteOperation> {
|
|
150
101
|
if (!appName || !callerActionIdentifier) {
|
|
151
102
|
throw new Error('appName and callerActionIdentifier are required for SNS service');
|
|
152
103
|
}
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
key,
|
|
159
|
-
operationType: AttributeOperation.DELETE,
|
|
160
|
-
} as EntityAttributeOperation)
|
|
104
|
+
const operation: EntityAttributeDeleteOperation = await super.deleteEntityAttributes(
|
|
105
|
+
accountId,
|
|
106
|
+
entityType,
|
|
107
|
+
entityId,
|
|
108
|
+
attributeKey
|
|
161
109
|
);
|
|
162
|
-
|
|
110
|
+
const [result] = await this.sendOperationsToSns(
|
|
111
|
+
this.entitySnsArn,
|
|
112
|
+
accountId,
|
|
113
|
+
appName,
|
|
114
|
+
callerActionIdentifier,
|
|
115
|
+
[operation],
|
|
116
|
+
ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
117
|
+
ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
118
|
+
'Authorization entity attributes async delete: failed to send operations to SNS'
|
|
119
|
+
);
|
|
120
|
+
return result;
|
|
163
121
|
}
|
|
164
122
|
|
|
165
123
|
/**
|
|
166
|
-
* Async function, this function only send the
|
|
124
|
+
* Async function, this function only send the update request to SNS and return before the change actually took place
|
|
167
125
|
* @param accountId
|
|
168
126
|
* @param appName - App name of the calling app
|
|
169
127
|
* @param callerActionIdentifier - action identifier
|
|
170
|
-
* @param
|
|
171
|
-
* @return {Promise<
|
|
128
|
+
* @param resourceAttributeOperation - Operation to do on resource attribute.
|
|
129
|
+
* @return {Promise<ResourceAttributeUpsertOperation>} Sent operation
|
|
172
130
|
* */
|
|
173
131
|
async updateResourceAttributes(
|
|
174
132
|
accountId: number,
|
|
175
133
|
appName: string,
|
|
176
134
|
callerActionIdentifier: string,
|
|
177
|
-
|
|
178
|
-
): Promise<
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
'Authorization resource attributes async update: failed to send operations to SNS'
|
|
192
|
-
)
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
return (await Promise.all(sendToSnsPromises)).flat();
|
|
135
|
+
resourceAttributeOperation: ResourceAttributeUpsertOperation
|
|
136
|
+
): Promise<ResourceAttributeUpsertOperation> {
|
|
137
|
+
await super.updateResourceAttributes(accountId, appName, callerActionIdentifier, resourceAttributeOperation);
|
|
138
|
+
const [result] = await this.sendOperationsToSns(
|
|
139
|
+
this.resourceSnsArn,
|
|
140
|
+
accountId,
|
|
141
|
+
appName,
|
|
142
|
+
callerActionIdentifier,
|
|
143
|
+
[resourceAttributeOperation],
|
|
144
|
+
ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
145
|
+
RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
146
|
+
'Authorization resource attributes async update: failed to send operations to SNS'
|
|
147
|
+
);
|
|
148
|
+
return result;
|
|
196
149
|
}
|
|
197
150
|
|
|
198
151
|
/**
|
|
199
|
-
* Async function, this function only send the
|
|
152
|
+
* Async function, this function only send the update request to SNS and return before the change actually took place
|
|
200
153
|
* @param accountId
|
|
201
154
|
* @param appName - App name of the calling app
|
|
202
155
|
* @param callerActionIdentifier - action identifier
|
|
203
|
-
* @param
|
|
204
|
-
* @return {Promise<
|
|
156
|
+
* @param entityAttributeOperation - Operation to do on entity attribute.
|
|
157
|
+
* @return {Promise<EntityAttributeUpsertOperation>} Sent operation
|
|
205
158
|
* */
|
|
206
159
|
async updateEntityAttributes(
|
|
207
160
|
accountId: number,
|
|
208
161
|
appName: string,
|
|
209
162
|
callerActionIdentifier: string,
|
|
210
|
-
|
|
211
|
-
): Promise<
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
163
|
+
entityAttributeOperation: EntityAttributeUpsertOperation
|
|
164
|
+
): Promise<EntityAttributeUpsertOperation> {
|
|
165
|
+
await super.updateEntityAttributes(accountId, appName, callerActionIdentifier, entityAttributeOperation);
|
|
166
|
+
const [result] = await this.sendOperationsToSns(
|
|
167
|
+
this.entitySnsArn,
|
|
168
|
+
accountId,
|
|
169
|
+
appName,
|
|
170
|
+
callerActionIdentifier,
|
|
171
|
+
[entityAttributeOperation],
|
|
172
|
+
ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE,
|
|
173
|
+
ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
|
|
174
|
+
'Authorization entity attributes async update: failed to send operations to SNS'
|
|
175
|
+
);
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Base function to send attribute operations to SNS.
|
|
181
|
+
* Chunks operations and sends them in parallel.
|
|
182
|
+
* @param topicArn The SNS topic ARN to send messages to
|
|
183
|
+
* @param accountId The account ID
|
|
184
|
+
* @param appName App name of the calling app
|
|
185
|
+
* @param callerActionIdentifier Action identifier
|
|
186
|
+
* @param operations Array of operations to send
|
|
187
|
+
* @param chunkSize Maximum number of operations per message
|
|
188
|
+
* @param messageKind The kind of message being sent
|
|
189
|
+
* @param errorLogMessage Error message to log if sending fails
|
|
190
|
+
* @return Promise with array of sent operations
|
|
191
|
+
*/
|
|
192
|
+
private async sendOperationsToSns<
|
|
193
|
+
T extends
|
|
194
|
+
| ResourceAttributeUpsertOperation
|
|
195
|
+
| ResourceAttributeDeleteOperation
|
|
196
|
+
| EntityAttributeUpsertOperation
|
|
197
|
+
| EntityAttributeDeleteOperation
|
|
198
|
+
>(
|
|
199
|
+
topicArn: string,
|
|
200
|
+
accountId: number,
|
|
201
|
+
appName: string,
|
|
202
|
+
callerActionIdentifier: string,
|
|
203
|
+
operations: T[],
|
|
204
|
+
chunkSize: number,
|
|
205
|
+
messageKind: string,
|
|
206
|
+
errorLogMessage: string
|
|
207
|
+
): Promise<T[]> {
|
|
208
|
+
const sendToSnsPromises: Promise<T[]>[] = [];
|
|
209
|
+
const operationChunks = chunk(operations, chunkSize);
|
|
210
|
+
for (const operationsChunk of operationChunks) {
|
|
216
211
|
sendToSnsPromises.push(
|
|
217
212
|
this.sendSingleSnsMessage(
|
|
218
213
|
topicArn,
|
|
@@ -220,15 +215,21 @@ export class AuthorizationAttributesSnsService implements AuthorizationAttribute
|
|
|
220
215
|
appName,
|
|
221
216
|
callerActionIdentifier,
|
|
222
217
|
operationsChunk,
|
|
223
|
-
|
|
224
|
-
|
|
218
|
+
messageKind,
|
|
219
|
+
errorLogMessage
|
|
225
220
|
)
|
|
226
221
|
);
|
|
227
222
|
}
|
|
228
223
|
return (await Promise.all(sendToSnsPromises)).flat();
|
|
229
224
|
}
|
|
230
225
|
|
|
231
|
-
private async sendSingleSnsMessage<
|
|
226
|
+
private async sendSingleSnsMessage<
|
|
227
|
+
T extends
|
|
228
|
+
| ResourceAttributeUpsertOperation
|
|
229
|
+
| ResourceAttributeDeleteOperation
|
|
230
|
+
| EntityAttributeUpsertOperation
|
|
231
|
+
| EntityAttributeDeleteOperation
|
|
232
|
+
>(
|
|
232
233
|
topicArn: string,
|
|
233
234
|
accountId: number,
|
|
234
235
|
appName: string,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
ScopeOptions,
|
|
14
14
|
} from './types/scoped-actions-contracts';
|
|
15
15
|
import { AuthorizationInternalService, logger } from './authorization-internal-service';
|
|
16
|
-
import { getAttributionsFromApi, getProfile
|
|
16
|
+
import { getAttributionsFromApi, getProfile } from './attributions-service';
|
|
17
17
|
import { GraphApi } from './clients/graph-api';
|
|
18
18
|
import { PlatformApi } from './clients/platform-api';
|
|
19
19
|
import { scopeToResource } from './utils/authorization.utils';
|
|
@@ -21,9 +21,6 @@ import { scopeToResource } from './utils/authorization.utils';
|
|
|
21
21
|
const GRANTED_FEATURE_CACHE_EXPIRATION_SECONDS = 5 * 60;
|
|
22
22
|
const PLATFORM_AUTHORIZE_PATH = '/internal_ms/authorization/authorize';
|
|
23
23
|
|
|
24
|
-
const ALLOWED_SDK_PLATFORM_PROFILES_KEY = 'allowed-sdk-platform-profiles';
|
|
25
|
-
const IN_RELEASE_SDK_PLATFORM_PROFILES_KEY = 'in-release-sdk-platform-profile';
|
|
26
|
-
const PLATFORM_PROFILE_RELEASE_FF = 'sdk-platform-profiles';
|
|
27
24
|
const NAVIGATE_CAN_ACTION_IN_SCOPE_TO_GRAPH_FF = 'navigate-can-action-in-scope-to-graph';
|
|
28
25
|
|
|
29
26
|
export interface AuthorizeResponse {
|
|
@@ -149,28 +146,6 @@ export class AuthorizationService {
|
|
|
149
146
|
return scopedActionResponseObjects[0].permit;
|
|
150
147
|
}
|
|
151
148
|
|
|
152
|
-
private static getProfile(accountId: number, userId: number): PlatformProfile {
|
|
153
|
-
const appName: string = process.env.APP_NAME ?? 'INVALID_APP_NAME';
|
|
154
|
-
if (!this.igniteClient) {
|
|
155
|
-
logger.error({ tag: 'authorization-service' }, 'AuthorizationService: igniteClient is not set, failing request');
|
|
156
|
-
throw new Error('AuthorizationService: igniteClient is not set, failing request');
|
|
157
|
-
}
|
|
158
|
-
if (
|
|
159
|
-
this.igniteClient.configuration.getObjectValue<string[]>(ALLOWED_SDK_PLATFORM_PROFILES_KEY, []).includes(appName)
|
|
160
|
-
) {
|
|
161
|
-
return getProfile();
|
|
162
|
-
}
|
|
163
|
-
if (
|
|
164
|
-
this.igniteClient.configuration
|
|
165
|
-
.getObjectValue<string[]>(IN_RELEASE_SDK_PLATFORM_PROFILES_KEY, [])
|
|
166
|
-
.includes(appName) &&
|
|
167
|
-
this.igniteClient.isReleased(PLATFORM_PROFILE_RELEASE_FF, { accountId, userId })
|
|
168
|
-
) {
|
|
169
|
-
return getProfile();
|
|
170
|
-
}
|
|
171
|
-
return PlatformProfile.APP;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
149
|
static async canActionInScopeMultiple(
|
|
175
150
|
accountId: number,
|
|
176
151
|
userId: number,
|
|
@@ -193,7 +168,7 @@ export class AuthorizationService {
|
|
|
193
168
|
scopedActionResponseObjects = await this.graphApi.checkPermissions(accountId, userId, scopedActions);
|
|
194
169
|
} else {
|
|
195
170
|
apiType = 'platform';
|
|
196
|
-
const profile =
|
|
171
|
+
const profile = getProfile();
|
|
197
172
|
const internalAuthToken = AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
198
173
|
|
|
199
174
|
scopedActionResponseObjects = await this.platformApi.checkPermissions(
|
|
@@ -234,7 +209,7 @@ export class AuthorizationService {
|
|
|
234
209
|
userId: number,
|
|
235
210
|
authorizationRequestObjects: AuthorizationObject[]
|
|
236
211
|
): Promise<AuthorizeResponse> {
|
|
237
|
-
const profile =
|
|
212
|
+
const profile = getProfile();
|
|
238
213
|
const internalAuthToken = AuthorizationInternalService.generateInternalAuthToken(accountId, userId);
|
|
239
214
|
const startTime = performance.now();
|
|
240
215
|
const attributionHeaders = getAttributionsFromApi();
|
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
import { ValidationUtils } from './utils/validation';
|
|
2
1
|
import isEqual from 'lodash/isEqual.js';
|
|
3
|
-
import { EntityAttributeAssignment, ResourceAttributeDelete } from './types/authorization-attributes-contracts';
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Base class for attribute assignments (Resource or Entity)
|
|
7
5
|
* Provides common validation and functionality
|
|
8
6
|
*/
|
|
9
|
-
export abstract class BaseAttributeAssignment<
|
|
10
|
-
public readonly id:
|
|
11
|
-
public readonly type:
|
|
7
|
+
export abstract class BaseAttributeAssignment<T, R> {
|
|
8
|
+
public readonly id: number;
|
|
9
|
+
public readonly type: T;
|
|
12
10
|
public readonly attributeKey: string;
|
|
13
11
|
public readonly attributeValue: string;
|
|
14
12
|
|
|
15
|
-
constructor(
|
|
16
|
-
id
|
|
17
|
-
type
|
|
18
|
-
attributeKey
|
|
19
|
-
attributeValue
|
|
20
|
-
validTypes: readonly string[],
|
|
21
|
-
idFieldName: string,
|
|
22
|
-
typeFieldName: string
|
|
23
|
-
) {
|
|
24
|
-
const validated = ValidationUtils.validateAssignment<TType>(
|
|
25
|
-
{ id, type, attributeKey, attributeValue },
|
|
26
|
-
validTypes as readonly TType[],
|
|
27
|
-
{ id: idFieldName, type: typeFieldName }
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
this.id = validated.id as TId;
|
|
31
|
-
this.type = validated.type as TType;
|
|
32
|
-
this.attributeKey = validated.attributeKey;
|
|
33
|
-
this.attributeValue = validated.attributeValue;
|
|
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;
|
|
34
18
|
}
|
|
35
19
|
|
|
36
20
|
/**
|
|
@@ -38,9 +22,9 @@ export abstract class BaseAttributeAssignment<TId extends number, TType extends
|
|
|
38
22
|
* @param other Another assignment instance
|
|
39
23
|
* @returns true if all properties are equal
|
|
40
24
|
*/
|
|
41
|
-
equals(other: BaseAttributeAssignment<
|
|
25
|
+
equals(other: BaseAttributeAssignment<T, R>): boolean {
|
|
42
26
|
return isEqual(this, other);
|
|
43
27
|
}
|
|
44
28
|
|
|
45
|
-
abstract toDataTransferObject():
|
|
29
|
+
abstract toDataTransferObject(): R;
|
|
46
30
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { EntityType } from './entity-attributes-constants';
|
|
2
|
+
import {
|
|
3
|
+
ResourceAttributeDeleteOperation,
|
|
4
|
+
EntityAttributeDeleteOperation,
|
|
5
|
+
ResourceAttributeUpsertOperation,
|
|
6
|
+
EntityAttributeUpsertOperation,
|
|
7
|
+
AttributeOperation,
|
|
8
|
+
} from './types/authorization-attributes-contracts';
|
|
9
|
+
import { Resource } from './types/general';
|
|
10
|
+
import { ValidationUtils } from './utils/validation';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Abstract base class for authorization attributes operations.
|
|
14
|
+
* Both MS (HTTP) and SNS (async) services extend this class.
|
|
15
|
+
*/
|
|
16
|
+
export abstract class BaseAuthorizationAttributesService {
|
|
17
|
+
/**
|
|
18
|
+
* Deletes a resource attribute.
|
|
19
|
+
* Returns Promise<ResourceAttributeDeleteOperation>
|
|
20
|
+
*/
|
|
21
|
+
deleteResourceAttributes(
|
|
22
|
+
accountId: number,
|
|
23
|
+
resource: Resource,
|
|
24
|
+
attributeKey: string,
|
|
25
|
+
_appName?: string,
|
|
26
|
+
_callerActionIdentifier?: string
|
|
27
|
+
): Promise<ResourceAttributeDeleteOperation> {
|
|
28
|
+
const operation: ResourceAttributeDeleteOperation = {
|
|
29
|
+
resourceType: resource.type,
|
|
30
|
+
resourceId: resource.id,
|
|
31
|
+
key: attributeKey,
|
|
32
|
+
operationType: AttributeOperation.DELETE,
|
|
33
|
+
};
|
|
34
|
+
ValidationUtils.validateInteger(accountId);
|
|
35
|
+
ValidationUtils.validatDeleteResourceAssignment(operation);
|
|
36
|
+
return Promise.resolve(operation);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Deletes an entity attribute.
|
|
41
|
+
* Returns Promise<EntityAttributeDeleteOperation>
|
|
42
|
+
*/
|
|
43
|
+
deleteEntityAttributes(
|
|
44
|
+
accountId: number,
|
|
45
|
+
entityType: EntityType,
|
|
46
|
+
entityId: number,
|
|
47
|
+
attributeKey: string
|
|
48
|
+
): Promise<EntityAttributeDeleteOperation> {
|
|
49
|
+
const operation: EntityAttributeDeleteOperation = {
|
|
50
|
+
entityType: entityType,
|
|
51
|
+
entityId: entityId,
|
|
52
|
+
key: attributeKey,
|
|
53
|
+
operationType: AttributeOperation.DELETE,
|
|
54
|
+
};
|
|
55
|
+
ValidationUtils.validateInteger(accountId);
|
|
56
|
+
ValidationUtils.validatDeleteEntityAssignment(operation);
|
|
57
|
+
return Promise.resolve(operation);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Updates a resource attribute (single operation - upsert only).
|
|
62
|
+
* For MS service: performs upsert operation
|
|
63
|
+
* For SNS service: returns Promise<ResourceAttributeUpsertOperation>
|
|
64
|
+
*/
|
|
65
|
+
updateResourceAttributes(
|
|
66
|
+
accountId: number,
|
|
67
|
+
_appName: string,
|
|
68
|
+
_callerActionIdentifier: string,
|
|
69
|
+
resourceAttributeOperation: ResourceAttributeUpsertOperation
|
|
70
|
+
): Promise<ResourceAttributeUpsertOperation> {
|
|
71
|
+
ValidationUtils.validateInteger(accountId);
|
|
72
|
+
ValidationUtils.validatUpsertResourceAssignment(resourceAttributeOperation);
|
|
73
|
+
return Promise.resolve(resourceAttributeOperation);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Updates an entity attribute (single operation - upsert only).
|
|
77
|
+
* For MS service: performs upsert operation
|
|
78
|
+
* For SNS service: returns Promise<EntityAttributeUpsertOperation>
|
|
79
|
+
*/
|
|
80
|
+
updateEntityAttributes(
|
|
81
|
+
accountId: number,
|
|
82
|
+
_appName: string,
|
|
83
|
+
_callerActionIdentifier: string,
|
|
84
|
+
entityAttributeOperation: EntityAttributeUpsertOperation
|
|
85
|
+
): Promise<EntityAttributeUpsertOperation> {
|
|
86
|
+
ValidationUtils.validateInteger(accountId);
|
|
87
|
+
ValidationUtils.validatUpsertEntityAssignment(entityAttributeOperation);
|
|
88
|
+
return Promise.resolve(entityAttributeOperation);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntityType } from './entity-attributes-constants';
|
|
2
2
|
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
|
+
import { EntityAttributeAssignment as EntityAttributeAssignmentContract } from './types/authorization-attributes-contracts';
|
|
3
4
|
|
|
4
|
-
export class EntityAttributeAssignment extends BaseAttributeAssignment<
|
|
5
|
+
export class EntityAttributeAssignment extends BaseAttributeAssignment<EntityType, EntityAttributeAssignmentContract> {
|
|
5
6
|
public readonly entityId: number;
|
|
6
7
|
public readonly entityType: EntityType;
|
|
7
8
|
|
|
8
|
-
constructor(entityId: number, entityType:
|
|
9
|
-
super(entityId, entityType,
|
|
9
|
+
constructor(entityId: number, entityType: EntityType, key: string, value: string) {
|
|
10
|
+
super(entityId, entityType, key, value);
|
|
10
11
|
this.entityId = entityId;
|
|
11
|
-
this.entityType =
|
|
12
|
+
this.entityType = entityType;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
toDataTransferObject() {
|
|
15
|
+
toDataTransferObject(): EntityAttributeAssignmentContract {
|
|
15
16
|
return {
|
|
16
17
|
entityId: this.entityId,
|
|
17
18
|
entityType: this.entityType,
|
package/src/index.ts
CHANGED
|
@@ -58,6 +58,10 @@ export {
|
|
|
58
58
|
} from './authorization-middleware';
|
|
59
59
|
export { AuthorizationService, AuthorizeResponse } from './authorization-service';
|
|
60
60
|
export { AuthorizationAttributesService } from './authorization-attributes-service';
|
|
61
|
+
export * from './resource-attributes-constants';
|
|
62
|
+
export * from './entity-attributes-constants';
|
|
63
|
+
export { ResourceAttributeAssignment } from './resource-attribute-assignment';
|
|
64
|
+
export { EntityAttributeAssignment } from './entity-attribute-assignment';
|
|
61
65
|
export { RolesService } from './roles-service';
|
|
62
66
|
export { MembershipsService } from './memberships';
|
|
63
67
|
export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
|
|
@@ -68,5 +72,18 @@ export {
|
|
|
68
72
|
ScopedActionPermit,
|
|
69
73
|
} from './types/scoped-actions-contracts';
|
|
70
74
|
export { CustomRole, BasicRole, RoleType, RoleCreateRequest, RoleUpdateRequest, RolesResponse } from './types/roles';
|
|
75
|
+
export {
|
|
76
|
+
AttributeAssignment,
|
|
77
|
+
AttributeOperation,
|
|
78
|
+
ResourceAttributeDeleteAssignment,
|
|
79
|
+
ResourceAttributeUpsertOperation,
|
|
80
|
+
ResourceAttributeDeleteOperation,
|
|
81
|
+
EntityAttributeDeleteAssignment,
|
|
82
|
+
EntityAttributeUpsertOperation,
|
|
83
|
+
EntityAttributeDeleteOperation,
|
|
84
|
+
ResourceAttributeAssignment as ResourceAttributeAssignmentContract,
|
|
85
|
+
EntityAttributeAssignment as EntityAttributeAssignmentContract,
|
|
86
|
+
} from './types/authorization-attributes-contracts';
|
|
87
|
+
export { BaseAuthorizationAttributesService as IAuthorizationAttributesService } from './base-authorization-attributes-service';
|
|
71
88
|
|
|
72
89
|
export { TestKit };
|
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ResourceType } from './resource-attributes-constants';
|
|
2
2
|
import { BaseAttributeAssignment } from './base-attribute-assignment';
|
|
3
|
+
import { ResourceAttributeAssignment as ResourceAttributeAssignmentContract } from './types/authorization-attributes-contracts';
|
|
4
|
+
import { ValidationUtils } from './utils/validation';
|
|
3
5
|
|
|
4
|
-
export class ResourceAttributeAssignment extends BaseAttributeAssignment<
|
|
6
|
+
export class ResourceAttributeAssignment extends BaseAttributeAssignment<
|
|
7
|
+
ResourceType,
|
|
8
|
+
ResourceAttributeAssignmentContract
|
|
9
|
+
> {
|
|
5
10
|
public readonly resourceId: number;
|
|
6
11
|
public readonly resourceType: ResourceType;
|
|
7
12
|
|
|
8
13
|
constructor(resourceId: number, resourceType: ResourceType, attributeKey: string, attributeValue: string) {
|
|
9
|
-
|
|
14
|
+
ValidationUtils.validatUpsertResourceAssignment({
|
|
10
15
|
resourceId,
|
|
11
16
|
resourceType,
|
|
12
|
-
attributeKey,
|
|
13
|
-
attributeValue,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'resourceType'
|
|
17
|
-
);
|
|
17
|
+
key: attributeKey,
|
|
18
|
+
value: attributeValue,
|
|
19
|
+
});
|
|
20
|
+
super(resourceId, resourceType, attributeKey, attributeValue);
|
|
18
21
|
this.resourceId = resourceId;
|
|
19
22
|
this.resourceType = this.type;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
toDataTransferObject() {
|
|
25
|
+
toDataTransferObject(): ResourceAttributeAssignmentContract {
|
|
23
26
|
return {
|
|
24
27
|
resourceId: this.resourceId,
|
|
25
28
|
resourceType: this.resourceType,
|