@mondaydotcomorg/monday-authorization 3.5.1-feat-shaime-support-entity-attributes-in-authorization-sdk-d2be13e → 3.5.1-fix-authorize-profile-picker-9fcaf6a

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