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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/authorization-attributes-ms-service.d.ts +72 -0
  2. package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
  3. package/dist/authorization-attributes-ms-service.js +279 -0
  4. package/dist/authorization-attributes-service.d.ts +25 -47
  5. package/dist/authorization-attributes-service.d.ts.map +1 -1
  6. package/dist/authorization-attributes-service.js +32 -171
  7. package/dist/authorization-attributes-sns-service.d.ts +70 -0
  8. package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
  9. package/dist/authorization-attributes-sns-service.js +179 -0
  10. package/dist/base-attribute-assignment.d.ts +19 -0
  11. package/dist/base-attribute-assignment.d.ts.map +1 -0
  12. package/dist/base-attribute-assignment.js +34 -0
  13. package/dist/constants/sns.d.ts +12 -2
  14. package/dist/constants/sns.d.ts.map +1 -1
  15. package/dist/constants/sns.js +22 -2
  16. package/dist/entity-attribute-assignment.d.ts +16 -0
  17. package/dist/entity-attribute-assignment.d.ts.map +1 -0
  18. package/dist/entity-attribute-assignment.js +33 -0
  19. package/dist/entity-attributes-constants.d.ts +7 -0
  20. package/dist/entity-attributes-constants.d.ts.map +1 -0
  21. package/dist/entity-attributes-constants.js +11 -0
  22. package/dist/errors/argument-error.d.ts +4 -0
  23. package/dist/errors/argument-error.d.ts.map +1 -0
  24. package/dist/errors/argument-error.js +10 -0
  25. package/dist/esm/authorization-attributes-ms-service.d.ts +72 -0
  26. package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
  27. package/dist/esm/authorization-attributes-ms-service.mjs +277 -0
  28. package/dist/esm/authorization-attributes-service.d.ts +25 -47
  29. package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
  30. package/dist/esm/authorization-attributes-service.mjs +32 -167
  31. package/dist/esm/authorization-attributes-sns-service.d.ts +70 -0
  32. package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
  33. package/dist/esm/authorization-attributes-sns-service.mjs +173 -0
  34. package/dist/esm/base-attribute-assignment.d.ts +19 -0
  35. package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
  36. package/dist/esm/base-attribute-assignment.mjs +28 -0
  37. package/dist/esm/constants/sns.d.ts +12 -2
  38. package/dist/esm/constants/sns.d.ts.map +1 -1
  39. package/dist/esm/constants/sns.mjs +17 -3
  40. package/dist/esm/entity-attribute-assignment.d.ts +16 -0
  41. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
  42. package/dist/esm/entity-attribute-assignment.mjs +31 -0
  43. package/dist/esm/entity-attributes-constants.d.ts +7 -0
  44. package/dist/esm/entity-attributes-constants.d.ts.map +1 -0
  45. package/dist/esm/entity-attributes-constants.mjs +9 -0
  46. package/dist/esm/errors/argument-error.d.ts +4 -0
  47. package/dist/esm/errors/argument-error.d.ts.map +1 -0
  48. package/dist/esm/errors/argument-error.mjs +8 -0
  49. package/dist/esm/resource-attribute-assignment.d.ts +16 -0
  50. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
  51. package/dist/esm/resource-attribute-assignment.mjs +31 -0
  52. package/dist/esm/resource-attributes-constants.d.ts +25 -0
  53. package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
  54. package/dist/esm/resource-attributes-constants.mjs +28 -0
  55. package/dist/esm/types/authorization-attributes-contracts.d.ts +26 -12
  56. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  57. package/dist/esm/types/authorization-attributes-contracts.mjs +6 -6
  58. package/dist/esm/types/authorization-attributes-service.interface.d.ts +43 -0
  59. package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -0
  60. package/dist/esm/types/authorization-attributes-service.interface.mjs +1 -0
  61. package/dist/esm/types/general.d.ts +1 -1
  62. package/dist/esm/types/general.d.ts.map +1 -1
  63. package/dist/esm/utils/assigment-schema.d.ts +23 -0
  64. package/dist/esm/utils/assigment-schema.d.ts.map +1 -0
  65. package/dist/esm/utils/assigment-schema.mjs +29 -0
  66. package/dist/esm/utils/resource-schema.d.ts +17 -0
  67. package/dist/esm/utils/resource-schema.d.ts.map +1 -0
  68. package/dist/esm/utils/resource-schema.mjs +16 -0
  69. package/dist/esm/utils/validation.d.ts +26 -0
  70. package/dist/esm/utils/validation.d.ts.map +1 -0
  71. package/dist/esm/utils/validation.mjs +70 -0
  72. package/dist/resource-attribute-assignment.d.ts +16 -0
  73. package/dist/resource-attribute-assignment.d.ts.map +1 -0
  74. package/dist/resource-attribute-assignment.js +33 -0
  75. package/dist/resource-attributes-constants.d.ts +25 -0
  76. package/dist/resource-attributes-constants.d.ts.map +1 -0
  77. package/dist/resource-attributes-constants.js +31 -0
  78. package/dist/types/authorization-attributes-contracts.d.ts +26 -12
  79. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  80. package/dist/types/authorization-attributes-contracts.js +5 -5
  81. package/dist/types/authorization-attributes-service.interface.d.ts +43 -0
  82. package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -0
  83. package/dist/types/authorization-attributes-service.interface.js +1 -0
  84. package/dist/types/general.d.ts +1 -1
  85. package/dist/types/general.d.ts.map +1 -1
  86. package/dist/utils/assigment-schema.d.ts +23 -0
  87. package/dist/utils/assigment-schema.d.ts.map +1 -0
  88. package/dist/utils/assigment-schema.js +36 -0
  89. package/dist/utils/resource-schema.d.ts +17 -0
  90. package/dist/utils/resource-schema.d.ts.map +1 -0
  91. package/dist/utils/resource-schema.js +22 -0
  92. package/dist/utils/validation.d.ts +26 -0
  93. package/dist/utils/validation.d.ts.map +1 -0
  94. package/dist/utils/validation.js +76 -0
  95. package/package.json +3 -1
  96. package/src/authorization-attributes-ms-service.ts +414 -0
  97. package/src/authorization-attributes-service.ts +34 -222
  98. package/src/authorization-attributes-sns-service.ts +257 -0
  99. package/src/base-attribute-assignment.ts +30 -0
  100. package/src/constants/sns.ts +19 -2
  101. package/src/entity-attribute-assignment.ts +33 -0
  102. package/src/entity-attributes-constants.ts +7 -0
  103. package/src/errors/argument-error.ts +6 -0
  104. package/src/resource-attribute-assignment.ts +36 -0
  105. package/src/resource-attributes-constants.ts +27 -0
  106. package/src/types/authorization-attributes-contracts.ts +34 -11
  107. package/src/types/authorization-attributes-service.interface.ts +70 -0
  108. package/src/types/general.ts +1 -1
  109. package/src/utils/assigment-schema.ts +29 -0
  110. package/src/utils/resource-schema.ts +21 -0
  111. package/src/utils/validation.ts +82 -0
@@ -0,0 +1,72 @@
1
+ import { ResourceAttributeOperation, EntityAttributeOperation } from './types/authorization-attributes-contracts';
2
+ import { EntityType } from './entity-attributes-constants';
3
+ import { AuthorizationAttributesService } from './types/authorization-attributes-service.interface';
4
+ import { Resource } from './types/general';
5
+ /**
6
+ * Service class for managing resource attributes in the authorization microservice.
7
+ * Provides synchronous HTTP operations to create/update and delete attributes on resources.
8
+ */
9
+ export declare class AuthorizationAttributesMsService implements AuthorizationAttributesService {
10
+ private static LOG_TAG;
11
+ private static httpClient;
12
+ /**
13
+ * Deletes specific attributes from a resource synchronously.
14
+ * @param accountId The account ID
15
+ * @param resource Object with resourceType (string) and resourceId (number)
16
+ * @param attributeKeys Array of attribute key strings to delete
17
+ * @returns Promise<void>
18
+ */
19
+ deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
20
+ /**
21
+ * Deletes specific attributes from an entity synchronously.
22
+ * @param accountId The account ID
23
+ * @param entityType The entity type
24
+ * @param entityId The entity ID
25
+ * @param attributeKeys Array of attribute key strings to delete
26
+ * @returns Promise<void>
27
+ */
28
+ deleteEntityAttributes(accountId: number, entityType: EntityType, entityId: number, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
29
+ /**
30
+ * Updates resource attributes (batch operations).
31
+ * Note: MS service does not support batch operations directly.
32
+ * This method processes operations sequentially using upsert/delete methods.
33
+ * @param accountId The account ID
34
+ * @param appName App name (required for interface compatibility, but not used in MS service)
35
+ * @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
36
+ * @param resourceAttributeOperations Array of operations to perform
37
+ * @returns Promise<ResourceAttributesOperation[]> Array of processed operations
38
+ */
39
+ updateResourceAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
40
+ /**
41
+ * Updates entity attributes (batch operations).
42
+ * Note: MS service does not support batch operations directly.
43
+ * This method processes operations sequentially using upsert/delete methods.
44
+ * @param accountId The account ID
45
+ * @param appName App name (required for interface compatibility, but not used in MS service)
46
+ * @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
47
+ * @param entityAttributeOperations Array of operations to perform
48
+ * @returns Promise<EntityAttributesOperation[]> Array of processed operations
49
+ */
50
+ updateEntityAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
51
+ /**
52
+ * Replaces path template parameters with actual values
53
+ * @param template Path template with placeholders like {accountId}
54
+ * @param params Object with parameter names and values
55
+ * @returns Path with all placeholders replaced
56
+ */
57
+ private static replacePathParams;
58
+ /**
59
+ * Generic helper for executing delete requests
60
+ */
61
+ private static executeDeleteRequest;
62
+ /**
63
+ * Gets request headers including Authorization, Content-Type, and optional attribution headers
64
+ */
65
+ private static getRequestHeaders;
66
+ /**
67
+ * Generic helper for executing upsert requests
68
+ */
69
+ private static executeUpsertRequest;
70
+ private upsertResourceAttributes;
71
+ }
72
+ //# sourceMappingURL=authorization-attributes-ms-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-attributes-ms-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-ms-service.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,0BAA0B,EAC1B,wBAAwB,EAEzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAK3D,OAAO,EAAE,8BAA8B,EAAE,MAAM,oDAAoD,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAY3C;;;GAGG;AACH,qBAAa,gCAAiC,YAAW,8BAA8B;IACrF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IACvD,OAAO,CAAC,MAAM,CAAC,UAAU,CAAqD;IAE9E;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAehB;;;;;;;OAOG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAehB;;;;;;;;;OASG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,EAC/B,2BAA2B,EAAE,0BAA0B,EAAE,GACxD,OAAO,CAAC,0BAA0B,EAAE,CAAC;IAmCxC;;;;;;;;;OASG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,MAAM,EAC/B,yBAAyB,EAAE,wBAAwB,EAAE,GACpD,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAqCtC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAQhC;;OAEG;mBACkB,oBAAoB;IAiEzC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA+ChC;;OAEG;mBACkB,oBAAoB;YA6D3B,wBAAwB;CAqBvC"}
@@ -0,0 +1,279 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ const tridentBackendApi = require('@mondaydotcomorg/trident-backend-api');
4
+ const mondayJwt = require('@mondaydotcomorg/monday-jwt');
5
+ const resourceAttributeAssignment = require('./resource-attribute-assignment.js');
6
+ const entityAttributeAssignment = require('./entity-attribute-assignment.js');
7
+ const types_authorizationAttributesContracts = require('./types/authorization-attributes-contracts.js');
8
+ const authorizationInternalService = require('./authorization-internal-service.js');
9
+ const attributionsService = require('./attributions-service.js');
10
+ const constants = require('./constants.js');
11
+ const utils_validation = require('./utils/validation.js');
12
+
13
+ const INTERNAL_APP_NAME = 'internal_ms';
14
+ const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
15
+ const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
16
+ const UPSERT_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity';
17
+ const DELETE_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity/{entityType}/{entityId}';
18
+ /**
19
+ * Service class for managing resource attributes in the authorization microservice.
20
+ * Provides synchronous HTTP operations to create/update and delete attributes on resources.
21
+ */
22
+ class AuthorizationAttributesMsService {
23
+ static LOG_TAG = 'authorization_attributes_ms';
24
+ static httpClient = tridentBackendApi.Api.getPart('httpClient');
25
+ /**
26
+ * Deletes specific attributes from a resource synchronously.
27
+ * @param accountId The account ID
28
+ * @param resource Object with resourceType (string) and resourceId (number)
29
+ * @param attributeKeys Array of attribute key strings to delete
30
+ * @returns Promise<void>
31
+ */
32
+ async deleteResourceAttributes(accountId, resource, attributeKeys, _appName, _callerActionIdentifier) {
33
+ utils_validation.ValidationUtils.validateResource(resource);
34
+ return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_RESOURCE_ATTRIBUTES_PATH, {
35
+ resourceType: resource.type,
36
+ resourceId: resource.id,
37
+ }, attributeKeys, 'resource', 'deleteResourceAttributesSync');
38
+ }
39
+ /**
40
+ * Deletes specific attributes from an entity synchronously.
41
+ * @param accountId The account ID
42
+ * @param entityType The entity type
43
+ * @param entityId The entity ID
44
+ * @param attributeKeys Array of attribute key strings to delete
45
+ * @returns Promise<void>
46
+ */
47
+ async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, _appName, _callerActionIdentifier) {
48
+ utils_validation.ValidationUtils.validateInteger(accountId);
49
+ return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_ENTITY_ATTRIBUTES_PATH, {
50
+ entityType,
51
+ entityId,
52
+ }, attributeKeys, 'entity', 'deleteEntityAttributesSync');
53
+ }
54
+ /**
55
+ * Updates resource attributes (batch operations).
56
+ * Note: MS service does not support batch operations directly.
57
+ * This method processes operations sequentially using upsert/delete methods.
58
+ * @param accountId The account ID
59
+ * @param appName App name (required for interface compatibility, but not used in MS service)
60
+ * @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
61
+ * @param resourceAttributeOperations Array of operations to perform
62
+ * @returns Promise<ResourceAttributesOperation[]> Array of processed operations
63
+ */
64
+ async updateResourceAttributes(accountId, _appName, _callerActionIdentifier, resourceAttributeOperations) {
65
+ // Process all operations in parallel using Promise.all
66
+ await Promise.all(resourceAttributeOperations.map(async (operation) => {
67
+ utils_validation.ValidationUtils.validateResourceAssignment({
68
+ resourceId: operation.resourceId,
69
+ resourceType: operation.resourceType,
70
+ key: operation.key,
71
+ value: operation.value || '',
72
+ });
73
+ if (operation.operationType === types_authorizationAttributesContracts.AttributeOperation.UPSERT) {
74
+ await this.upsertResourceAttributes(accountId, [
75
+ new resourceAttributeAssignment.ResourceAttributeAssignment(operation.resourceId, operation.resourceType, operation.key, operation.value || ''),
76
+ ]);
77
+ }
78
+ else if (operation.operationType === types_authorizationAttributesContracts.AttributeOperation.DELETE) {
79
+ await this.deleteResourceAttributes(accountId, {
80
+ type: operation.resourceType,
81
+ id: operation.resourceId,
82
+ }, [operation.key]);
83
+ }
84
+ }));
85
+ return resourceAttributeOperations;
86
+ }
87
+ /**
88
+ * Updates entity attributes (batch operations).
89
+ * Note: MS service does not support batch operations directly.
90
+ * This method processes operations sequentially using upsert/delete methods.
91
+ * @param accountId The account ID
92
+ * @param appName App name (required for interface compatibility, but not used in MS service)
93
+ * @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
94
+ * @param entityAttributeOperations Array of operations to perform
95
+ * @returns Promise<EntityAttributesOperation[]> Array of processed operations
96
+ */
97
+ async updateEntityAttributes(accountId, _appName, _callerActionIdentifier, entityAttributeOperations) {
98
+ // Process all operations in parallel using Promise.all
99
+ await Promise.all(entityAttributeOperations.map(async (operation) => {
100
+ // Validate before processing
101
+ utils_validation.ValidationUtils.validateEntityAssignment({
102
+ entityId: operation.entityId,
103
+ entityType: operation.entityType,
104
+ key: operation.key,
105
+ value: operation.value || '',
106
+ });
107
+ if (operation.operationType === 'upsert') {
108
+ await AuthorizationAttributesMsService.executeUpsertRequest(accountId, [
109
+ new entityAttributeAssignment.EntityAttributeAssignment(operation.entityId, operation.entityType, operation.key, operation.value || ''),
110
+ ], UPSERT_ENTITY_ATTRIBUTES_PATH, 'entityAttributeAssignments', 'entity', 'upsertEntityAttributesSync');
111
+ }
112
+ else if (operation.operationType === 'delete') {
113
+ await this.deleteEntityAttributes(accountId, operation.entityType, operation.entityId, [operation.key]);
114
+ }
115
+ }));
116
+ return entityAttributeOperations;
117
+ }
118
+ /**
119
+ * Replaces path template parameters with actual values
120
+ * @param template Path template with placeholders like {accountId}
121
+ * @param params Object with parameter names and values
122
+ * @returns Path with all placeholders replaced
123
+ */
124
+ static replacePathParams(template, params) {
125
+ let path = template;
126
+ for (const [key, value] of Object.entries(params)) {
127
+ path = path.replace(`{${key}}`, String(value));
128
+ }
129
+ return path;
130
+ }
131
+ /**
132
+ * Generic helper for executing delete requests
133
+ */
134
+ static async executeDeleteRequest(accountId, pathTemplate, pathParams, keys, logPrefix, methodName) {
135
+ // Validate inputs
136
+ utils_validation.ValidationUtils.validateInteger(accountId);
137
+ utils_validation.ValidationUtils.validateStringArray(keys);
138
+ if (!keys.length) {
139
+ authorizationInternalService.logger.warn({ tag: this.LOG_TAG, accountId, ...pathParams }, `${methodName} called with empty keys array`);
140
+ return;
141
+ }
142
+ const requestBody = { keys };
143
+ if (!AuthorizationAttributesMsService.httpClient) {
144
+ throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
145
+ }
146
+ const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId, ...pathParams });
147
+ const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
148
+ try {
149
+ authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Deleting ${logPrefix} attributes`);
150
+ await AuthorizationAttributesMsService.httpClient.fetch({
151
+ url: {
152
+ appName: constants.APP_NAME,
153
+ path,
154
+ },
155
+ method: 'DELETE',
156
+ headers,
157
+ body: JSON.stringify(requestBody),
158
+ }, {
159
+ timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
160
+ retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
161
+ });
162
+ authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Successfully deleted ${logPrefix} attributes`);
163
+ }
164
+ catch (err) {
165
+ authorizationInternalService.logger.error({
166
+ tag: AuthorizationAttributesMsService.LOG_TAG,
167
+ method: methodName,
168
+ accountId,
169
+ ...pathParams,
170
+ error: err instanceof Error ? err.message : String(err),
171
+ }, `Failed in ${methodName}`);
172
+ throw err;
173
+ }
174
+ }
175
+ /**
176
+ * Gets request headers including Authorization, Content-Type, and optional attribution headers
177
+ */
178
+ static getRequestHeaders(accountId, userId) {
179
+ const headers = {
180
+ 'Content-Type': 'application/json',
181
+ };
182
+ // Generate Authorization token
183
+ const authToken = mondayJwt.signAuthorizationHeader({
184
+ appName: INTERNAL_APP_NAME,
185
+ accountId,
186
+ userId,
187
+ });
188
+ headers.Authorization = authToken;
189
+ // Add attribution headers if available
190
+ const attributionHeaders = attributionsService.getAttributionsFromApi();
191
+ for (const key in attributionHeaders) {
192
+ if (Object.prototype.hasOwnProperty.call(attributionHeaders, key)) {
193
+ headers[key] = attributionHeaders[key];
194
+ }
195
+ }
196
+ // Add X-REQUEST-ID if available from context
197
+ try {
198
+ const tridentContext = tridentBackendApi.Api.getPart('context');
199
+ if (tridentContext?.runtimeAttributions) {
200
+ const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
201
+ if (outgoingHeaders) {
202
+ const attributionHeadersMap = {};
203
+ for (const [key, value] of outgoingHeaders) {
204
+ attributionHeadersMap[key] = value;
205
+ }
206
+ if (attributionHeadersMap['x-request-id']) {
207
+ headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
208
+ }
209
+ }
210
+ }
211
+ }
212
+ catch (error) {
213
+ // Silently fail if context is not available
214
+ authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, error }, 'Failed to get request ID from context');
215
+ }
216
+ // Add X-REQUEST-START timestamp
217
+ headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
218
+ return headers;
219
+ }
220
+ /**
221
+ * Generic helper for executing upsert requests
222
+ */
223
+ static async executeUpsertRequest(accountId, assignments, pathTemplate, requestBodyKey, logPrefix, methodName) {
224
+ const assignmentDto = assignments.map(assignment => assignment.toDataTransferObject());
225
+ const requestBody = requestBodyKey === 'resourceAttributeAssignments'
226
+ ? { resourceAttributeAssignments: assignmentDto }
227
+ : { entityAttributeAssignments: assignmentDto };
228
+ if (!AuthorizationAttributesMsService.httpClient) {
229
+ throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
230
+ }
231
+ const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId });
232
+ const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
233
+ try {
234
+ authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
235
+ await AuthorizationAttributesMsService.httpClient.fetch({
236
+ url: {
237
+ appName: constants.APP_NAME,
238
+ path,
239
+ },
240
+ method: 'POST',
241
+ headers,
242
+ body: JSON.stringify(requestBody),
243
+ }, {
244
+ timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
245
+ retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
246
+ });
247
+ authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
248
+ }
249
+ catch (err) {
250
+ authorizationInternalService.logger.error({
251
+ tag: AuthorizationAttributesMsService.LOG_TAG,
252
+ method: methodName,
253
+ accountId,
254
+ error: err instanceof Error ? err.message : String(err),
255
+ }, `Failed in ${methodName}`);
256
+ throw err;
257
+ }
258
+ }
259
+ async upsertResourceAttributes(accountId, resourceAttributeAssignments) {
260
+ const attributionHeaders = attributionsService.getAttributionsFromApi();
261
+ if (!AuthorizationAttributesMsService.httpClient) {
262
+ throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
263
+ }
264
+ return await AuthorizationAttributesMsService.httpClient.fetch({
265
+ url: {
266
+ appName: constants.APP_NAME,
267
+ path: UPSERT_RESOURCE_ATTRIBUTES_PATH.replace('{accountId}', accountId.toString()),
268
+ },
269
+ method: 'POST',
270
+ headers: {
271
+ 'Content-Type': 'application/json',
272
+ ...attributionHeaders,
273
+ },
274
+ body: JSON.stringify({ resourceAttributeAssignments }),
275
+ });
276
+ }
277
+ }
278
+
279
+ exports.AuthorizationAttributesMsService = AuthorizationAttributesMsService;
@@ -1,54 +1,32 @@
1
- import { FetcherConfig, HttpClient } from '@mondaydotcomorg/trident-backend-api';
2
- import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
3
- import { ResourceAttributeAssignment, ResourceAttributeResponse, ResourceAttributesOperation } from './types/authorization-attributes-contracts';
4
- import { Resource } from './types/general';
1
+ import { AuthorizationAttributesService as IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
2
+ /**
3
+ * Main service class for managing resource and entity attributes.
4
+ * Provides access to both direct (MS) and SNS operations.
5
+ *
6
+ * @example
7
+ * const service = new AuthorizationAttributesService();
8
+ *
9
+ * // Use direct operations
10
+ * await service.direct().upsertResourceAttributes(accountId, assignments);
11
+ *
12
+ * // Use SNS operations
13
+ * await service.sns().upsertResourceAttributes(accountId, assignments, appName, actionId);
14
+ * ```
15
+ */
5
16
  export declare class AuthorizationAttributesService {
6
- private static LOG_TAG;
7
- private static API_PATHS;
8
- private httpClient;
9
- private fetchOptions;
10
- private snsArn;
17
+ private _directService;
18
+ private _snsService;
11
19
  /**
12
- * Public constructor to create the AuthorizationAttributesService instance.
13
- * @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
14
- * @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
20
+ * Gets the direct (MS) service instance.
21
+ * Initializes the service on first access (lazy initialization).
22
+ * @returns IAuthorizationAttributesService instance
15
23
  */
16
- constructor(httpClient?: HttpClient, fetchOptions?: RecursivePartial<FetcherConfig>);
24
+ direct(): IAuthorizationAttributesService;
17
25
  /**
18
- * Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
19
- * @param accountId
20
- * @param resourceAttributeAssignments - Array of resource (resourceType, resourceId) and attribute (key, value) pairs to upsert in the authorization MS.
21
- * e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
22
- * @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
26
+ * Gets the SNS service instance.
27
+ * Initializes the service on first access (lazy initialization).
28
+ * @returns IAuthorizationAttributesService instance
23
29
  */
24
- upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[]): Promise<ResourceAttributeResponse>;
25
- /**
26
- * Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
27
- * @param accountId
28
- * @param resource - The resource (resourceType, resourceId) to delete the attributes for.
29
- * @param attributeKeys - Array of attribute keys to delete for the resource.
30
- * @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
31
- */
32
- deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[]): Promise<ResourceAttributeResponse>;
33
- /**
34
- * Async function, this function only send the updates request to SNS and return before the change actually took place
35
- * @param accountId
36
- * @param appName - App name of the calling app
37
- * @param callerActionIdentifier - action identifier
38
- * @param resourceAttributeOperations - Array of operations to do on resource attributes.
39
- * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
40
- * */
41
- updateResourceAttributesAsync(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributesOperation[]): Promise<ResourceAttributesOperation[]>;
42
- private sendSingleSnsMessage;
43
- private static getSnsTopicArn;
44
- /**
45
- * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
46
- * This function can be used as health check for services that updating resource attributes in async is crucial.
47
- * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
48
- * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
49
- * However, this is the best we can do without actually push dummy messages to the SNS.
50
- * @return {Promise<boolean>} - true if succeeded
51
- */
52
- asyncResourceAttributesHealthCheck(): Promise<boolean>;
30
+ sns(): IAuthorizationAttributesService;
53
31
  }
54
32
  //# sourceMappingURL=authorization-attributes-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,aAAa,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAEtF,OAAO,EAAoB,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,2BAA2B,EAC5B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAY3C,qBAAa,8BAA8B;IACzC,OAAO,CAAC,MAAM,CAAC,OAAO,CAA8B;IACpD,OAAO,CAAC,MAAM,CAAC,SAAS,CAGb;IACX,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,MAAM,CAAS;IAEvB;;;;OAIG;gBACS,UAAU,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC;IAqBnF;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,GAC1D,OAAO,CAAC,yBAAyB,CAAC;IA6BrC;;;;;;OAMG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EAAE,GACtB,OAAO,CAAC,yBAAyB,CAAC;IAkCrC;;;;;;;UAOM;IACA,6BAA6B,CACjC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,2BAA2B,EAAE,GACzD,OAAO,CAAC,2BAA2B,EAAE,CAAC;YAY3B,oBAAoB;IA4BlC,OAAO,CAAC,MAAM,CAAC,cAAc;IAW7B;;;;;;;OAOG;IACG,kCAAkC,IAAI,OAAO,CAAC,OAAO,CAAC;CAoB7D"}
1
+ {"version":3,"file":"authorization-attributes-service.d.ts","sourceRoot":"","sources":["../src/authorization-attributes-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,8BAA8B,IAAI,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAEvI;;;;;;;;;;;;;GAaG;AACH,qBAAa,8BAA8B;IACzC,OAAO,CAAC,cAAc,CAAiD;IACvE,OAAO,CAAC,WAAW,CAAkD;IAErE;;;;OAIG;IACH,MAAM,IAAI,+BAA+B;IAOzC;;;;OAIG;IACH,GAAG,IAAI,+BAA+B;CAMvC"}