@mondaydotcomorg/monday-authorization 3.5.1 → 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-e355942

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 (124) hide show
  1. package/dist/authorization-attributes-ms-service.d.ts +95 -0
  2. package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
  3. package/dist/authorization-attributes-ms-service.js +362 -0
  4. package/dist/authorization-attributes-service.d.ts +26 -47
  5. package/dist/authorization-attributes-service.d.ts.map +1 -1
  6. package/dist/authorization-attributes-service.js +33 -171
  7. package/dist/authorization-attributes-sns-service.d.ts +91 -0
  8. package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
  9. package/dist/authorization-attributes-sns-service.js +217 -0
  10. package/dist/authorization-middleware.d.ts +2 -2
  11. package/dist/authorization-middleware.d.ts.map +1 -1
  12. package/dist/authorization-service.d.ts +3 -3
  13. package/dist/authorization-service.d.ts.map +1 -1
  14. package/dist/base-attribute-assignment.d.ts +18 -0
  15. package/dist/base-attribute-assignment.d.ts.map +1 -0
  16. package/dist/base-attribute-assignment.js +43 -0
  17. package/dist/constants/sns.d.ts +12 -2
  18. package/dist/constants/sns.d.ts.map +1 -1
  19. package/dist/constants/sns.js +22 -2
  20. package/dist/entity-attribute-assignment.d.ts +14 -0
  21. package/dist/entity-attribute-assignment.d.ts.map +1 -0
  22. package/dist/entity-attribute-assignment.js +24 -0
  23. package/dist/entity-attributes-constants.d.ts +7 -0
  24. package/dist/entity-attributes-constants.d.ts.map +1 -0
  25. package/dist/entity-attributes-constants.js +9 -0
  26. package/dist/errors/argument-error.d.ts +4 -0
  27. package/dist/errors/argument-error.d.ts.map +1 -0
  28. package/dist/errors/argument-error.js +11 -0
  29. package/dist/esm/authorization-attributes-ms-service.d.ts +95 -0
  30. package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
  31. package/dist/esm/authorization-attributes-ms-service.mjs +360 -0
  32. package/dist/esm/authorization-attributes-service.d.ts +26 -47
  33. package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
  34. package/dist/esm/authorization-attributes-service.mjs +33 -167
  35. package/dist/esm/authorization-attributes-sns-service.d.ts +91 -0
  36. package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
  37. package/dist/esm/authorization-attributes-sns-service.mjs +211 -0
  38. package/dist/esm/authorization-middleware.d.ts +2 -2
  39. package/dist/esm/authorization-middleware.d.ts.map +1 -1
  40. package/dist/esm/authorization-service.d.ts +3 -3
  41. package/dist/esm/authorization-service.d.ts.map +1 -1
  42. package/dist/esm/base-attribute-assignment.d.ts +18 -0
  43. package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
  44. package/dist/esm/base-attribute-assignment.mjs +41 -0
  45. package/dist/esm/constants/sns.d.ts +12 -2
  46. package/dist/esm/constants/sns.d.ts.map +1 -1
  47. package/dist/esm/constants/sns.mjs +17 -3
  48. package/dist/esm/entity-attribute-assignment.d.ts +14 -0
  49. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
  50. package/dist/esm/entity-attribute-assignment.mjs +22 -0
  51. package/dist/esm/entity-attributes-constants.d.ts +7 -0
  52. package/dist/esm/entity-attributes-constants.d.ts.map +1 -0
  53. package/dist/esm/entity-attributes-constants.mjs +7 -0
  54. package/dist/esm/errors/argument-error.d.ts +4 -0
  55. package/dist/esm/errors/argument-error.d.ts.map +1 -0
  56. package/dist/esm/errors/argument-error.mjs +9 -0
  57. package/dist/esm/index.d.ts +9 -0
  58. package/dist/esm/index.d.ts.map +1 -1
  59. package/dist/esm/index.mjs +7 -0
  60. package/dist/esm/prometheus-service.d.ts +1 -2
  61. package/dist/esm/prometheus-service.d.ts.map +1 -1
  62. package/dist/esm/resource-attribute-assignment.d.ts +24 -0
  63. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
  64. package/dist/esm/resource-attribute-assignment.mjs +34 -0
  65. package/dist/esm/resource-attributes-constants.d.ts +15 -0
  66. package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
  67. package/dist/esm/resource-attributes-constants.mjs +25 -0
  68. package/dist/esm/testKit/index.d.ts +4 -4
  69. package/dist/esm/testKit/index.d.ts.map +1 -1
  70. package/dist/esm/types/authorization-attributes-contracts.d.ts +27 -12
  71. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  72. package/dist/esm/types/authorization-attributes-contracts.mjs +6 -6
  73. package/dist/esm/types/authorization-attributes-service.interface.d.ts +57 -0
  74. package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -0
  75. package/dist/esm/types/authorization-attributes-service.interface.mjs +1 -0
  76. package/dist/esm/types/general.d.ts +1 -2
  77. package/dist/esm/types/general.d.ts.map +1 -1
  78. package/dist/esm/utils/validation.d.ts +45 -0
  79. package/dist/esm/utils/validation.d.ts.map +1 -0
  80. package/dist/esm/utils/validation.mjs +117 -0
  81. package/dist/index.d.ts +9 -0
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +15 -0
  84. package/dist/prometheus-service.d.ts +1 -2
  85. package/dist/prometheus-service.d.ts.map +1 -1
  86. package/dist/resource-attribute-assignment.d.ts +24 -0
  87. package/dist/resource-attribute-assignment.d.ts.map +1 -0
  88. package/dist/resource-attribute-assignment.js +36 -0
  89. package/dist/resource-attributes-constants.d.ts +15 -0
  90. package/dist/resource-attributes-constants.d.ts.map +1 -0
  91. package/dist/resource-attributes-constants.js +28 -0
  92. package/dist/testKit/index.d.ts +4 -4
  93. package/dist/testKit/index.d.ts.map +1 -1
  94. package/dist/types/authorization-attributes-contracts.d.ts +27 -12
  95. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  96. package/dist/types/authorization-attributes-contracts.js +5 -5
  97. package/dist/types/authorization-attributes-service.interface.d.ts +57 -0
  98. package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -0
  99. package/dist/types/authorization-attributes-service.interface.js +1 -0
  100. package/dist/types/general.d.ts +1 -2
  101. package/dist/types/general.d.ts.map +1 -1
  102. package/dist/utils/validation.d.ts +45 -0
  103. package/dist/utils/validation.d.ts.map +1 -0
  104. package/dist/utils/validation.js +119 -0
  105. package/package.json +3 -2
  106. package/src/authorization-attributes-ms-service.ts +528 -0
  107. package/src/authorization-attributes-service.ts +35 -222
  108. package/src/authorization-attributes-sns-service.ts +312 -0
  109. package/src/authorization-middleware.ts +2 -2
  110. package/src/authorization-service.ts +4 -4
  111. package/src/base-attribute-assignment.ts +55 -0
  112. package/src/constants/sns.ts +19 -2
  113. package/src/entity-attribute-assignment.ts +21 -0
  114. package/src/entity-attributes-constants.ts +7 -0
  115. package/src/errors/argument-error.ts +7 -0
  116. package/src/index.ts +9 -0
  117. package/src/prometheus-service.ts +1 -2
  118. package/src/resource-attribute-assignment.ts +43 -0
  119. package/src/resource-attributes-constants.ts +35 -0
  120. package/src/testKit/index.ts +5 -5
  121. package/src/types/authorization-attributes-contracts.ts +36 -11
  122. package/src/types/authorization-attributes-service.interface.ts +100 -0
  123. package/src/types/general.ts +3 -2
  124. package/src/utils/validation.ts +114 -0
@@ -1,185 +1,47 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const chunk = require('lodash/chunk.js');
4
- const tridentBackendApi = require('@mondaydotcomorg/trident-backend-api');
5
- const mondaySns = require('@mondaydotcomorg/monday-sns');
6
- const mondayFetchApi = require('@mondaydotcomorg/monday-fetch-api');
7
- const authorizationInternalService = require('./authorization-internal-service.js');
8
- const attributionsService = require('./attributions-service.js');
9
- const constants_sns = require('./constants/sns.js');
10
- const constants = require('./constants.js');
11
-
12
- const _interopDefault = e => e && e.__esModule ? e : { default: e };
13
-
14
- const chunk__default = /*#__PURE__*/_interopDefault(chunk);
3
+ const authorizationAttributesMsService = require('./authorization-attributes-ms-service.js');
4
+ const authorizationAttributesSnsService = require('./authorization-attributes-sns-service.js');
15
5
 
6
+ /**
7
+ * Main service class for managing resource and entity attributes.
8
+ * Provides access to both direct (MS) and SNS operations.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const service = new AuthorizationAttributesService();
13
+ *
14
+ * // Use direct operations
15
+ * await service.direct().upsertResourceAttributes(accountId, assignments);
16
+ *
17
+ * // Use SNS operations
18
+ * await service.sns().upsertResourceAttributes(accountId, assignments, appName, actionId);
19
+ * ```
20
+ */
16
21
  class AuthorizationAttributesService {
17
- static LOG_TAG = 'authorization_attributes';
18
- static API_PATHS = {
19
- UPSERT_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource',
20
- DELETE_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource/{resourceType}/{resourceId}',
21
- };
22
- httpClient;
23
- fetchOptions;
24
- snsArn;
22
+ _directService = null;
23
+ _snsService = null;
25
24
  /**
26
- * Public constructor to create the AuthorizationAttributesService instance.
27
- * @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
28
- * @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
25
+ * Gets the direct (MS) service instance.
26
+ * Initializes the service on first access (lazy initialization).
27
+ * @returns IAuthorizationAttributesService instance
29
28
  */
30
- constructor(httpClient, fetchOptions) {
31
- if (!httpClient) {
32
- httpClient = tridentBackendApi.Api.getPart('httpClient');
33
- if (!httpClient) {
34
- throw new Error(constants.ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
35
- }
36
- }
37
- if (!fetchOptions) {
38
- fetchOptions = constants.DEFAULT_FETCH_OPTIONS;
39
- }
40
- else {
41
- fetchOptions = {
42
- ...constants.DEFAULT_FETCH_OPTIONS,
43
- ...fetchOptions,
44
- };
29
+ direct() {
30
+ if (this._directService === null) {
31
+ this._directService = new authorizationAttributesMsService.AuthorizationAttributesMsService();
45
32
  }
46
- this.httpClient = httpClient;
47
- this.fetchOptions = fetchOptions;
48
- this.snsArn = AuthorizationAttributesService.getSnsTopicArn();
33
+ return this._directService;
49
34
  }
50
35
  /**
51
- * Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
52
- * @param accountId
53
- * @param resourceAttributeAssignments - Array of resource (resourceType, resourceId) and attribute (key, value) pairs to upsert in the authorization MS.
54
- * e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
55
- * @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
36
+ * Gets the SNS service instance.
37
+ * Initializes the service on first access (lazy initialization).
38
+ * @returns IAuthorizationAttributesService instance
56
39
  */
57
- async upsertResourceAttributes(accountId, resourceAttributeAssignments) {
58
- const attributionHeaders = attributionsService.getAttributionsFromApi();
59
- try {
60
- return await this.httpClient.fetch({
61
- url: {
62
- appName: constants.APP_NAME,
63
- path: AuthorizationAttributesService.API_PATHS.UPSERT_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString()),
64
- },
65
- method: 'POST',
66
- headers: {
67
- 'Content-Type': 'application/json',
68
- ...attributionHeaders,
69
- },
70
- body: JSON.stringify({ resourceAttributeAssignments }),
71
- }, this.fetchOptions);
72
- }
73
- catch (err) {
74
- if (err instanceof mondayFetchApi.HttpFetcherError) {
75
- throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('upsertResourceAttributes', err.status, err.message));
76
- }
77
- throw err;
78
- }
79
- }
80
- /**
81
- * Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
82
- * @param accountId
83
- * @param resource - The resource (resourceType, resourceId) to delete the attributes for.
84
- * @param attributeKeys - Array of attribute keys to delete for the resource.
85
- * @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
86
- */
87
- async deleteResourceAttributes(accountId, resource, attributeKeys) {
88
- const attributionHeaders = attributionsService.getAttributionsFromApi();
89
- if (!resource.id) {
90
- throw new Error('Resource ID is required');
91
- }
92
- try {
93
- return await this.httpClient.fetch({
94
- url: {
95
- appName: constants.APP_NAME,
96
- path: AuthorizationAttributesService.API_PATHS.DELETE_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString())
97
- .replace('{resourceType}', resource.type)
98
- .replace('{resourceId}', resource.id.toString()),
99
- },
100
- method: 'DELETE',
101
- headers: {
102
- 'Content-Type': 'application/json',
103
- ...attributionHeaders,
104
- },
105
- body: JSON.stringify({ keys: attributeKeys }),
106
- }, this.fetchOptions);
107
- }
108
- catch (err) {
109
- if (err instanceof mondayFetchApi.HttpFetcherError) {
110
- throw new Error(constants.ERROR_MESSAGES.REQUEST_FAILED('deleteResourceAttributes', err.status, err.message));
111
- }
112
- throw err;
113
- }
114
- }
115
- /**
116
- * Async function, this function only send the updates request to SNS and return before the change actually took place
117
- * @param accountId
118
- * @param appName - App name of the calling app
119
- * @param callerActionIdentifier - action identifier
120
- * @param resourceAttributeOperations - Array of operations to do on resource attributes.
121
- * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
122
- * */
123
- async updateResourceAttributesAsync(accountId, appName, callerActionIdentifier, resourceAttributeOperations) {
124
- const topicArn = this.snsArn;
125
- const sendToSnsPromises = [];
126
- const operationChucks = chunk__default.default(resourceAttributeOperations, constants_sns.ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
127
- for (const operationsChunk of operationChucks) {
128
- sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk));
129
- }
130
- return (await Promise.all(sendToSnsPromises)).flat();
131
- }
132
- async sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations) {
133
- const payload = {
134
- kind: constants_sns.RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
135
- payload: {
136
- accountId: accountId,
137
- callerAppName: appName,
138
- callerActionIdentifier: callerActionIdentifier,
139
- operations: operations,
140
- },
141
- };
142
- try {
143
- await mondaySns.sendToSns(payload, topicArn);
144
- return operations;
145
- }
146
- catch (error) {
147
- authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesService.LOG_TAG }, 'Authorization resource attributes async update: failed to send operations to SNS');
148
- return [];
149
- }
150
- }
151
- static getSnsTopicArn() {
152
- const arnFromEnv = process.env[constants_sns.SNS_ARN_ENV_VAR_NAME];
153
- if (arnFromEnv) {
154
- return arnFromEnv;
155
- }
156
- if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
157
- return constants_sns.SNS_DEV_TEST_NAME;
158
- }
159
- throw new Error('Unable to get sns topic arn from env variable');
160
- }
161
- /**
162
- * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
163
- * This function can be used as health check for services that updating resource attributes in async is crucial.
164
- * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
165
- * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
166
- * However, this is the best we can do without actually push dummy messages to the SNS.
167
- * @return {Promise<boolean>} - true if succeeded
168
- */
169
- async asyncResourceAttributesHealthCheck() {
170
- try {
171
- const requestedTopicArn = this.snsArn;
172
- const attributes = await mondaySns.getTopicAttributes(requestedTopicArn);
173
- const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
174
- if (!isHealthy) {
175
- authorizationInternalService.logger.error({ requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesService.LOG_TAG }, 'authorization-attributes-service failed in health check');
176
- }
177
- return isHealthy;
178
- }
179
- catch (error) {
180
- authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesService.LOG_TAG }, 'authorization-attributes-service got error during health check');
181
- return false;
40
+ sns() {
41
+ if (this._snsService === null) {
42
+ this._snsService = new authorizationAttributesSnsService.AuthorizationAttributesSnsService();
182
43
  }
44
+ return this._snsService;
183
45
  }
184
46
  }
185
47
 
@@ -0,0 +1,91 @@
1
+ import { ResourceAttributeAssignment, ResourceAttributeOperation, EntityAttributeOperation } from './types/authorization-attributes-contracts';
2
+ import { EntityAttributeAssignment } from './entity-attribute-assignment';
3
+ import { Resource } from './types/general';
4
+ import { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
5
+ import { EntityType } from './types/authorization-attributes-contracts';
6
+ /**
7
+ * Service class for managing resource attributes asynchronously via SNS.
8
+ * Provides asynchronous operations to create/update and delete attributes on resources.
9
+ */
10
+ export declare class AuthorizationAttributesSnsService implements IAuthorizationAttributesService {
11
+ private static LOG_TAG;
12
+ private resourceSnsArn;
13
+ private entitySnsArn;
14
+ /**
15
+ * Public constructor to create the AuthorizationAttributesSnsService instance.
16
+ */
17
+ constructor();
18
+ /**
19
+ * Async function to upsert resource attributes using SNS.
20
+ * Sends the updates request to SNS and returns before the change actually took place.
21
+ * @param accountId The account ID
22
+ * @param appName App name of the calling app
23
+ * @param callerActionIdentifier Action identifier
24
+ * @param resourceAttributeAssignments Array of resource attribute assignments to upsert
25
+ * @return Promise with array of sent operations
26
+ */
27
+ upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[], appName?: string, callerActionIdentifier?: string): Promise<ResourceAttributeOperation[]>;
28
+ /**
29
+ * Async function to delete resource attributes using SNS.
30
+ * Sends the updates request to SNS and returns before the change actually took place.
31
+ * @param accountId The account ID
32
+ * @param appName App name of the calling app
33
+ * @param callerActionIdentifier Action identifier
34
+ * @param resource The resource (resourceType, resourceId)
35
+ * @param attributeKeys Array of attribute keys to delete
36
+ * @return Promise with array of sent operations
37
+ */
38
+ deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<ResourceAttributeOperation[]>;
39
+ /**
40
+ * Async function to upsert entity 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 entityAttributeAssignments Array of entity attribute assignments to upsert
46
+ * @return Promise with array of sent operations
47
+ */
48
+ upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[], appName?: string, callerActionIdentifier?: string): Promise<EntityAttributeOperation[]>;
49
+ /**
50
+ * Async function to delete entity attributes using SNS.
51
+ * Sends the updates request to SNS and returns before the change actually took place.
52
+ * @param accountId The account ID
53
+ * @param appName App name of the calling app
54
+ * @param callerActionIdentifier Action identifier
55
+ * @param entityType The entity type
56
+ * @param entityId The entity ID
57
+ * @param attributeKeys Array of attribute keys to delete
58
+ * @return Promise with array of sent operations
59
+ */
60
+ deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<EntityAttributeOperation[]>;
61
+ /**
62
+ * Async function, this function only send the updates request to SNS and return before the change actually took place
63
+ * @param accountId
64
+ * @param appName - App name of the calling app
65
+ * @param callerActionIdentifier - action identifier
66
+ * @param resourceAttributeOperations - Array of operations to do on resource attributes.
67
+ * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
68
+ * */
69
+ updateResourceAttributes(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
70
+ /**
71
+ * Async function, this function only send the updates request to SNS and return before the change actually took place
72
+ * @param accountId
73
+ * @param appName - App name of the calling app
74
+ * @param callerActionIdentifier - action identifier
75
+ * @param entityAttributeOperations - Array of operations to do on entity attributes.
76
+ * @return {Promise<EntityAttributeOperation[]>} Array of sent operations
77
+ * */
78
+ updateEntityAttributes(accountId: number, appName: string, callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
79
+ private sendSingleSnsMessage;
80
+ private static getSnsTopicArn;
81
+ /**
82
+ * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
83
+ * This function can be used as health check for services that updating resource attributes in async is crucial.
84
+ * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
85
+ * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
86
+ * However, this is the best we can do without actually push dummy messages to the SNS.
87
+ * @return {Promise<boolean>} - true if succeeded
88
+ */
89
+ asyncResourceAttributesHealthCheck(): Promise<boolean>;
90
+ }
91
+ //# sourceMappingURL=authorization-attributes-sns-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-attributes-sns-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-sns-service.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAe3C,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAExE;;;GAGG;AACH,qBAAa,iCAAkC,YAAW,+BAA+B;IACvF,OAAO,CAAC,MAAM,CAAC,OAAO,CAA8B;IACpD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAS;IAE7B;;OAEG;;IAMH;;;;;;;;OAQG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,EAC3D,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAWxC;;;;;;;;;OASG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAgBxC;;;;;;;;OAQG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,EACvD,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAgBtC;;;;;;;;;;OAUG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAgBtC;;;;;;;UAOM;IACA,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,0BAA0B,EAAE,GACxD,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAoBxC;;;;;;;UAOM;IACA,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,yBAAyB,EAAE,wBAAwB,EAAE,GACpD,OAAO,CAAC,wBAAwB,EAAE,CAAC;YAoBxB,oBAAoB;IA2BlC,OAAO,CAAC,MAAM,CAAC,cAAc;IA0B7B;;;;;;;OAOG;IACG,kCAAkC,IAAI,OAAO,CAAC,OAAO,CAAC;CAoB7D"}
@@ -0,0 +1,217 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const chunk = require('lodash/chunk.js');
4
+ const mondaySns = require('@mondaydotcomorg/monday-sns');
5
+ const authorizationInternalService = require('./authorization-internal-service.js');
6
+ const constants_sns = require('./constants/sns.js');
7
+ const types_authorizationAttributesContracts = require('./types/authorization-attributes-contracts.js');
8
+
9
+ const _interopDefault = e => e && e.__esModule ? e : { default: e };
10
+
11
+ const chunk__default = /*#__PURE__*/_interopDefault(chunk);
12
+
13
+ /**
14
+ * Service class for managing resource attributes asynchronously via SNS.
15
+ * Provides asynchronous operations to create/update and delete attributes on resources.
16
+ */
17
+ class AuthorizationAttributesSnsService {
18
+ static LOG_TAG = 'authorization_attributes';
19
+ resourceSnsArn;
20
+ entitySnsArn;
21
+ /**
22
+ * Public constructor to create the AuthorizationAttributesSnsService instance.
23
+ */
24
+ constructor() {
25
+ this.resourceSnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(constants_sns.SnsTopicType.RESOURCE);
26
+ this.entitySnsArn = AuthorizationAttributesSnsService.getSnsTopicArn(constants_sns.SnsTopicType.ENTITY);
27
+ }
28
+ /**
29
+ * Async function to upsert resource attributes using SNS.
30
+ * Sends the updates request to SNS and returns before the change actually took place.
31
+ * @param accountId The account ID
32
+ * @param appName App name of the calling app
33
+ * @param callerActionIdentifier Action identifier
34
+ * @param resourceAttributeAssignments Array of resource attribute assignments to upsert
35
+ * @return Promise with array of sent operations
36
+ */
37
+ async upsertResourceAttributes(accountId, resourceAttributeAssignments, appName, callerActionIdentifier) {
38
+ if (!appName || !callerActionIdentifier) {
39
+ throw new Error('appName and callerActionIdentifier are required for SNS service');
40
+ }
41
+ const operations = resourceAttributeAssignments.map(assignment => ({
42
+ ...assignment,
43
+ operationType: types_authorizationAttributesContracts.AttributeOperation.UPSERT,
44
+ }));
45
+ return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
46
+ }
47
+ /**
48
+ * Async function to delete resource attributes using SNS.
49
+ * Sends the updates request to SNS and returns before the change actually took place.
50
+ * @param accountId The account ID
51
+ * @param appName App name of the calling app
52
+ * @param callerActionIdentifier Action identifier
53
+ * @param resource The resource (resourceType, resourceId)
54
+ * @param attributeKeys Array of attribute keys to delete
55
+ * @return Promise with array of sent operations
56
+ */
57
+ async deleteResourceAttributes(accountId, resource, attributeKeys, appName, callerActionIdentifier) {
58
+ if (!appName || !callerActionIdentifier) {
59
+ throw new Error('appName and callerActionIdentifier are required for SNS service');
60
+ }
61
+ const operations = attributeKeys.map(key => ({
62
+ resourceType: resource.type,
63
+ resourceId: resource.id,
64
+ key,
65
+ operationType: types_authorizationAttributesContracts.AttributeOperation.DELETE,
66
+ }));
67
+ return this.updateResourceAttributes(accountId, appName, callerActionIdentifier, operations);
68
+ }
69
+ /**
70
+ * Async function to upsert entity attributes using SNS.
71
+ * Sends the updates request to SNS and returns before the change actually took place.
72
+ * @param accountId The account ID
73
+ * @param appName App name of the calling app
74
+ * @param callerActionIdentifier Action identifier
75
+ * @param entityAttributeAssignments Array of entity attribute assignments to upsert
76
+ * @return Promise with array of sent operations
77
+ */
78
+ async upsertEntityAttributes(accountId, entityAttributeAssignments, appName, callerActionIdentifier) {
79
+ if (!appName || !callerActionIdentifier) {
80
+ throw new Error('appName and callerActionIdentifier are required for SNS service');
81
+ }
82
+ const operations = entityAttributeAssignments.map(assignment => {
83
+ return {
84
+ entityId: assignment.entityId,
85
+ entityType: assignment.entityType,
86
+ key: assignment.attributeKey,
87
+ value: assignment.attributeValue,
88
+ operationType: types_authorizationAttributesContracts.AttributeOperation.UPSERT,
89
+ };
90
+ });
91
+ return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
92
+ }
93
+ /**
94
+ * Async function to delete entity attributes using SNS.
95
+ * Sends the updates request to SNS and returns before the change actually took place.
96
+ * @param accountId The account ID
97
+ * @param appName App name of the calling app
98
+ * @param callerActionIdentifier Action identifier
99
+ * @param entityType The entity type
100
+ * @param entityId The entity ID
101
+ * @param attributeKeys Array of attribute keys to delete
102
+ * @return Promise with array of sent operations
103
+ */
104
+ async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, appName, callerActionIdentifier) {
105
+ if (!appName || !callerActionIdentifier) {
106
+ throw new Error('appName and callerActionIdentifier are required for SNS service');
107
+ }
108
+ const operations = attributeKeys.map(key => ({
109
+ entityType: entityType,
110
+ entityId,
111
+ key,
112
+ operationType: types_authorizationAttributesContracts.AttributeOperation.DELETE,
113
+ }));
114
+ return this.updateEntityAttributes(accountId, appName, callerActionIdentifier, operations);
115
+ }
116
+ /**
117
+ * Async function, this function only send the updates request to SNS and return before the change actually took place
118
+ * @param accountId
119
+ * @param appName - App name of the calling app
120
+ * @param callerActionIdentifier - action identifier
121
+ * @param resourceAttributeOperations - Array of operations to do on resource attributes.
122
+ * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
123
+ * */
124
+ async updateResourceAttributes(accountId, appName, callerActionIdentifier, resourceAttributeOperations) {
125
+ const topicArn = this.resourceSnsArn;
126
+ const sendToSnsPromises = [];
127
+ const operationChucks = chunk__default.default(resourceAttributeOperations, constants_sns.ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
128
+ for (const operationsChunk of operationChucks) {
129
+ sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk, constants_sns.RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, 'Authorization resource attributes async update: failed to send operations to SNS'));
130
+ }
131
+ return (await Promise.all(sendToSnsPromises)).flat();
132
+ }
133
+ /**
134
+ * Async function, this function only send the updates request to SNS and return before the change actually took place
135
+ * @param accountId
136
+ * @param appName - App name of the calling app
137
+ * @param callerActionIdentifier - action identifier
138
+ * @param entityAttributeOperations - Array of operations to do on entity attributes.
139
+ * @return {Promise<EntityAttributeOperation[]>} Array of sent operations
140
+ * */
141
+ async updateEntityAttributes(accountId, appName, callerActionIdentifier, entityAttributeOperations) {
142
+ const topicArn = this.entitySnsArn;
143
+ const sendToSnsPromises = [];
144
+ const operationChucks = chunk__default.default(entityAttributeOperations, constants_sns.ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
145
+ for (const operationsChunk of operationChucks) {
146
+ sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk, constants_sns.ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, 'Authorization entity attributes async update: failed to send operations to SNS'));
147
+ }
148
+ return (await Promise.all(sendToSnsPromises)).flat();
149
+ }
150
+ async sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations, kind, errorLogMessage) {
151
+ const payload = {
152
+ kind,
153
+ payload: {
154
+ accountId: accountId,
155
+ callerAppName: appName,
156
+ callerActionIdentifier: callerActionIdentifier,
157
+ operations: operations,
158
+ },
159
+ };
160
+ try {
161
+ await mondaySns.sendToSns(payload, topicArn);
162
+ return operations;
163
+ }
164
+ catch (error) {
165
+ authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, errorLogMessage);
166
+ return [];
167
+ }
168
+ }
169
+ static getSnsTopicArn(type) {
170
+ let envVarName;
171
+ let devTestName;
172
+ switch (type) {
173
+ case constants_sns.SnsTopicType.ENTITY:
174
+ envVarName = constants_sns.ENTITY_SNS_ARN_ENV_VAR_NAME;
175
+ devTestName = constants_sns.ENTITY_SNS_DEV_TEST_NAME;
176
+ break;
177
+ default:
178
+ // Default to resource SNS constants
179
+ envVarName = constants_sns.RESOURCE_SNS_ARN_ENV_VAR_NAME;
180
+ devTestName = constants_sns.RESOURCE_SNS_DEV_TEST_NAME;
181
+ break;
182
+ }
183
+ const arnFromEnv = process.env[envVarName];
184
+ if (arnFromEnv) {
185
+ return arnFromEnv;
186
+ }
187
+ if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
188
+ return devTestName;
189
+ }
190
+ throw new Error(`Unable to get ${type} sns topic arn from env variable`);
191
+ }
192
+ /**
193
+ * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
194
+ * This function can be used as health check for services that updating resource attributes in async is crucial.
195
+ * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
196
+ * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
197
+ * However, this is the best we can do without actually push dummy messages to the SNS.
198
+ * @return {Promise<boolean>} - true if succeeded
199
+ */
200
+ async asyncResourceAttributesHealthCheck() {
201
+ try {
202
+ const requestedTopicArn = this.resourceSnsArn;
203
+ const attributes = await mondaySns.getTopicAttributes(requestedTopicArn);
204
+ const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
205
+ if (!isHealthy) {
206
+ authorizationInternalService.logger.error({ requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesSnsService.LOG_TAG }, 'authorization-attributes-service failed in health check');
207
+ }
208
+ return isHealthy;
209
+ }
210
+ catch (error) {
211
+ authorizationInternalService.logger.error({ error, tag: AuthorizationAttributesSnsService.LOG_TAG }, 'authorization-attributes-service got error during health check');
212
+ return false;
213
+ }
214
+ }
215
+ }
216
+
217
+ exports.AuthorizationAttributesSnsService = AuthorizationAttributesSnsService;
@@ -1,6 +1,6 @@
1
- import { Action, BaseRequest, BaseResponse, Context, ContextGetter, ResourceGetter } from './types/general';
1
+ import { BaseRequest, BaseResponse, Context, ContextGetter, ResourceGetter } from './types/general';
2
2
  import type { NextFunction } from 'express';
3
- export declare function getAuthorizationMiddleware(action: Action, resourceGetter: ResourceGetter, contextGetter?: ContextGetter): (request: BaseRequest, response: BaseResponse, next: NextFunction) => Promise<void>;
3
+ export declare function getAuthorizationMiddleware(action: string, resourceGetter: ResourceGetter, contextGetter?: ContextGetter): (request: BaseRequest, response: BaseResponse, next: NextFunction) => Promise<void>;
4
4
  export declare function skipAuthorizationMiddleware(request: BaseRequest, response: BaseResponse, next: NextFunction): void;
5
5
  export declare function authorizationCheckMiddleware(request: BaseRequest, response: BaseResponse, next: NextFunction): void;
6
6
  export declare function defaultContextGetter(request: BaseRequest): Context;
@@ -1 +1 @@
1
- {"version":3,"file":"authorization-middleware.d.ts","sourceRoot":"","sources":["../src/authorization-middleware.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAC5G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI5C,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,EAC9B,aAAa,CAAC,EAAE,aAAa,IAG3B,SAAS,WAAW,EACpB,UAAU,YAAY,EACtB,MAAM,YAAY,KACjB,OAAO,CAAC,IAAI,CAAC,CAajB;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAGlH;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CASnH;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAElE"}
1
+ {"version":3,"file":"authorization-middleware.d.ts","sourceRoot":"","sources":["../src/authorization-middleware.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI5C,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,EAC9B,aAAa,CAAC,EAAE,aAAa,IAG3B,SAAS,WAAW,EACpB,UAAU,YAAY,EACtB,MAAM,YAAY,KACjB,OAAO,CAAC,IAAI,CAAC,CAajB;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CAGlH;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI,CASnH;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAElE"}
@@ -1,6 +1,6 @@
1
1
  import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
2
2
  import { IgniteClient } from '@mondaydotcomorg/ignite-sdk';
3
- import { Action, AuthorizationObject, AuthorizationParams, Resource } from './types/general';
3
+ import { AuthorizationObject, AuthorizationParams, Resource } from './types/general';
4
4
  import { ScopedAction, ScopedActionPermit, ScopedActionResponseObject, ScopeOptions } from './types/scoped-actions-contracts';
5
5
  export interface AuthorizeResponse {
6
6
  isAuthorized: boolean;
@@ -21,7 +21,7 @@ export declare class AuthorizationService {
21
21
  * @deprecated use the second form with authorizationRequestObjects instead,
22
22
  * support of this function will be dropped gradually
23
23
  */
24
- static isAuthorized(accountId: number, userId: number, resources: Resource[], action: Action): Promise<AuthorizeResponse>;
24
+ static isAuthorized(accountId: number, userId: number, resources: Resource[], action: string): Promise<AuthorizeResponse>;
25
25
  static isAuthorized(accountId: number, userId: number, authorizationRequestObjects: AuthorizationObject[]): Promise<AuthorizeResponse>;
26
26
  /**
27
27
  * @deprecated - Please use Ignite instead: https://github.com/DaPulse/ignite-monorepo/blob/master/packages/ignite-sdk/README.md
@@ -40,5 +40,5 @@ export declare class AuthorizationService {
40
40
  }
41
41
  export declare function setRedisClient(client: any, grantedFeatureRedisExpirationInSeconds?: number): void;
42
42
  export declare function setIgniteClient(): Promise<void>;
43
- export declare function createAuthorizationParams(resources: Resource[], action: Action): AuthorizationParams;
43
+ export declare function createAuthorizationParams(resources: Resource[], action: string): AuthorizationParams;
44
44
  //# sourceMappingURL=authorization-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authorization-service.d.ts","sourceRoot":"","sources":["../src/authorization-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAAmB,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG7F,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACb,MAAM,kCAAkC,CAAC;AAe1C,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAA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 /**
2
+ * Base class for attribute assignments (Resource or Entity)
3
+ * Provides common validation and functionality
4
+ */
5
+ export declare abstract class BaseAttributeAssignment<TId extends number, TType extends string> {
6
+ readonly id: TId;
7
+ readonly type: TType;
8
+ readonly attributeKey: string;
9
+ readonly attributeValue: string;
10
+ constructor(id: TId, type: string, attributeKey: string, attributeValue: string, validTypes: readonly string[], idFieldName: string, typeFieldName: string);
11
+ /**
12
+ * Compares two assignments for equality
13
+ * @param other Another assignment instance
14
+ * @returns true if all properties are equal
15
+ */
16
+ equals(other: BaseAttributeAssignment<TId, TType>): boolean;
17
+ }
18
+ //# sourceMappingURL=base-attribute-assignment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-attribute-assignment.d.ts","sourceRoot":"","sources":["../src/base-attribute-assignment.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,8BAAsB,uBAAuB,CAAC,GAAG,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM;IACpF,SAAgB,EAAE,EAAE,GAAG,CAAC;IACxB,SAAgB,IAAI,EAAE,KAAK,CAAC;IAC5B,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,cAAc,EAAE,MAAM,CAAC;gBAGrC,EAAE,EAAE,GAAG,EACP,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM;IAmBvB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,uBAAuB,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,OAAO;CAW5D"}
@@ -0,0 +1,43 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const utils_validation = require('./utils/validation.js');
4
+
5
+ /**
6
+ * Base class for attribute assignments (Resource or Entity)
7
+ * Provides common validation and functionality
8
+ */
9
+ class BaseAttributeAssignment {
10
+ id;
11
+ type;
12
+ attributeKey;
13
+ attributeValue;
14
+ constructor(id, type, attributeKey, attributeValue, validTypes, idFieldName, typeFieldName) {
15
+ // Validate id
16
+ utils_validation.ValidationUtils.validateInteger(id, idFieldName);
17
+ // Validate type
18
+ this.type = utils_validation.ValidationUtils.validateEnum(type, validTypes, typeFieldName);
19
+ // Validate attributeKey
20
+ utils_validation.ValidationUtils.validateString(attributeKey, 'attributeKey');
21
+ // Validate attributeValue
22
+ utils_validation.ValidationUtils.validateString(attributeValue, 'attributeValue');
23
+ this.id = id;
24
+ this.attributeKey = attributeKey;
25
+ this.attributeValue = attributeValue;
26
+ }
27
+ /**
28
+ * Compares two assignments for equality
29
+ * @param other Another assignment instance
30
+ * @returns true if all properties are equal
31
+ */
32
+ equals(other) {
33
+ if (!(other instanceof this.constructor)) {
34
+ return false;
35
+ }
36
+ return (this.id === other.id &&
37
+ this.type === other.type &&
38
+ this.attributeKey === other.attributeKey &&
39
+ this.attributeValue === other.attributeValue);
40
+ }
41
+ }
42
+
43
+ exports.BaseAttributeAssignment = BaseAttributeAssignment;