@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
@@ -0,0 +1,95 @@
1
+ import { ResourceAttributeAssignment } from './resource-attribute-assignment';
2
+ import { EntityAttributeAssignment } from './entity-attribute-assignment';
3
+ import { EntityType } from './types/authorization-attributes-contracts';
4
+ import { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
5
+ import { Resource } from './types/general';
6
+ import { ResourceAttributeOperation, EntityAttributeOperation } from './types/authorization-attributes-contracts';
7
+ /**
8
+ * Service class for managing resource attributes in the authorization microservice.
9
+ * Provides synchronous HTTP operations to create/update and delete attributes on resources.
10
+ */
11
+ export declare class AuthorizationAttributesMsService implements IAuthorizationAttributesService {
12
+ private static LOG_TAG;
13
+ private static httpClient;
14
+ /**
15
+ * Resets the cached HTTP client (useful for testing)
16
+ */
17
+ private static resetHttpClient;
18
+ /**
19
+ * Gets request headers including Authorization, Content-Type, and optional attribution headers
20
+ */
21
+ private static getRequestHeaders;
22
+ /**
23
+ * Validates that all messages are instances of the specified message class
24
+ */
25
+ private static validateMessages;
26
+ /**
27
+ * Generic helper for executing upsert requests
28
+ */
29
+ private static executeUpsertRequest;
30
+ /**
31
+ * Generic helper for executing delete requests
32
+ */
33
+ private static executeDeleteRequest;
34
+ /**
35
+ * Creates or updates resource attributes synchronously.
36
+ * @param accountId The account ID
37
+ * @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
38
+ * @returns Promise<void>
39
+ */
40
+ upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
41
+ /**
42
+ * Deletes specific attributes from a resource synchronously.
43
+ * @param accountId The account ID
44
+ * @param resource Object with resourceType (string) and resourceId (number)
45
+ * @param attributeKeys Array of attribute key strings to delete
46
+ * @returns Promise<void>
47
+ */
48
+ deleteResourceAttributes(accountId: number, resource: Resource, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
49
+ /**
50
+ * Creates or updates entity attributes synchronously.
51
+ * @param accountId The account ID
52
+ * @param entityAttributeAssignments Array of EntityAttributeAssignment objects
53
+ * @returns Promise<void>
54
+ */
55
+ upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
56
+ /**
57
+ * Deletes specific attributes from an entity synchronously.
58
+ * @param accountId The account ID
59
+ * @param entityType The entity type
60
+ * @param entityId The entity ID
61
+ * @param attributeKeys Array of attribute key strings to delete
62
+ * @returns Promise<void>
63
+ */
64
+ deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], _appName?: string, _callerActionIdentifier?: string): Promise<void>;
65
+ /**
66
+ * Updates resource attributes (batch operations).
67
+ * Note: MS service does not support batch operations directly.
68
+ * This method processes operations sequentially using upsert/delete methods.
69
+ * @param accountId The account ID
70
+ * @param appName App name (required for interface compatibility, but not used in MS service)
71
+ * @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
72
+ * @param resourceAttributeOperations Array of operations to perform
73
+ * @returns Promise<ResourceAttributesOperation[]> Array of processed operations
74
+ */
75
+ updateResourceAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
76
+ /**
77
+ * Updates entity attributes (batch operations).
78
+ * Note: MS service does not support batch operations directly.
79
+ * This method processes operations sequentially using upsert/delete methods.
80
+ * @param accountId The account ID
81
+ * @param appName App name (required for interface compatibility, but not used in MS service)
82
+ * @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
83
+ * @param entityAttributeOperations Array of operations to perform
84
+ * @returns Promise<EntityAttributesOperation[]> Array of processed operations
85
+ */
86
+ updateEntityAttributes(accountId: number, _appName: string, _callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
87
+ /**
88
+ * Replaces path template parameters with actual values
89
+ * @param template Path template with placeholders like {accountId}
90
+ * @param params Object with parameter names and values
91
+ * @returns Path with all placeholders replaced
92
+ */
93
+ private static replacePathParams;
94
+ }
95
+ //# 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,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAsB,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAM5F,OAAO,EAAE,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AACrG,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAWlH;;;GAGG;AACH,qBAAa,gCAAiC,YAAW,+BAA+B;IACtF,OAAO,CAAC,MAAM,CAAC,OAAO,CAAiC;IACvD,OAAO,CAAC,MAAM,CAAC,UAAU,CAAqD;IAE9E;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAI9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA+ChC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAsD/B;;OAEG;mBACkB,oBAAoB;IA4EzC;;OAEG;mBACkB,oBAAoB;IA2EzC;;;;;OAKG;IACG,wBAAwB,CAC5B,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,EAC3D,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;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;IAyBhB;;;;;OAKG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,EACvD,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;;OAOG;IACG,sBAAsB,CAC1B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,CAAC,EAAE,MAAM,EACjB,uBAAuB,CAAC,EAAE,MAAM,GAC/B,OAAO,CAAC,IAAI,CAAC;IAoBhB;;;;;;;;;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;IAoCxC;;;;;;;;;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;IAyBtC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;CAOjC"}
@@ -0,0 +1,362 @@
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 zod = require('zod');
6
+ const resourceAttributeAssignment = require('./resource-attribute-assignment.js');
7
+ const entityAttributeAssignment = require('./entity-attribute-assignment.js');
8
+ const types_authorizationAttributesContracts = require('./types/authorization-attributes-contracts.js');
9
+ const errors_argumentError = require('./errors/argument-error.js');
10
+ const authorizationInternalService = require('./authorization-internal-service.js');
11
+ const attributionsService = require('./attributions-service.js');
12
+ const constants = require('./constants.js');
13
+ const utils_validation = require('./utils/validation.js');
14
+
15
+ const INTERNAL_APP_NAME = 'internal_ms';
16
+ const UPSERT_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource';
17
+ const DELETE_RESOURCE_ATTRIBUTES_PATH = '/attributes/{accountId}/resource/{resourceType}/{resourceId}';
18
+ const UPSERT_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity';
19
+ const DELETE_ENTITY_ATTRIBUTES_PATH = '/attributes/{accountId}/entity/{entityType}/{entityId}';
20
+ /**
21
+ * Service class for managing resource attributes in the authorization microservice.
22
+ * Provides synchronous HTTP operations to create/update and delete attributes on resources.
23
+ */
24
+ class AuthorizationAttributesMsService {
25
+ static LOG_TAG = 'authorization_attributes_ms';
26
+ static httpClient = tridentBackendApi.Api.getPart('httpClient');
27
+ /**
28
+ * Resets the cached HTTP client (useful for testing)
29
+ */
30
+ static resetHttpClient() {
31
+ AuthorizationAttributesMsService.httpClient = undefined;
32
+ }
33
+ /**
34
+ * Gets request headers including Authorization, Content-Type, and optional attribution headers
35
+ */
36
+ static getRequestHeaders(accountId, userId) {
37
+ const headers = {
38
+ 'Content-Type': 'application/json',
39
+ };
40
+ // Generate Authorization token
41
+ const authToken = mondayJwt.signAuthorizationHeader({
42
+ appName: INTERNAL_APP_NAME,
43
+ accountId,
44
+ userId,
45
+ });
46
+ headers.Authorization = authToken;
47
+ // Add attribution headers if available
48
+ const attributionHeaders = attributionsService.getAttributionsFromApi();
49
+ for (const key in attributionHeaders) {
50
+ if (Object.prototype.hasOwnProperty.call(attributionHeaders, key)) {
51
+ headers[key] = attributionHeaders[key];
52
+ }
53
+ }
54
+ // Add X-REQUEST-ID if available from context
55
+ try {
56
+ const tridentContext = tridentBackendApi.Api.getPart('context');
57
+ if (tridentContext?.runtimeAttributions) {
58
+ const outgoingHeaders = tridentContext.runtimeAttributions.buildOutgoingHeaders('HTTP_INTERNAL');
59
+ if (outgoingHeaders) {
60
+ const attributionHeadersMap = {};
61
+ for (const [key, value] of outgoingHeaders) {
62
+ attributionHeadersMap[key] = value;
63
+ }
64
+ if (attributionHeadersMap['x-request-id']) {
65
+ headers['X-REQUEST-ID'] = attributionHeadersMap['x-request-id'];
66
+ }
67
+ }
68
+ }
69
+ }
70
+ catch (error) {
71
+ // Silently fail if context is not available
72
+ authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, error }, 'Failed to get request ID from context');
73
+ }
74
+ // Add X-REQUEST-START timestamp
75
+ headers['X-REQUEST-START'] = Math.floor(Date.now() / 1000).toString();
76
+ return headers;
77
+ }
78
+ /**
79
+ * Validates that all messages are instances of the specified message class
80
+ */
81
+ static validateMessages(attributesMessages, messageClass) {
82
+ // Validate messageClass is a function using Zod
83
+ const classSchema = zod.z.custom(value => typeof value === 'function', {
84
+ message: 'messageClass must be a class/constructor function',
85
+ });
86
+ try {
87
+ classSchema.parse(messageClass);
88
+ }
89
+ catch (error) {
90
+ if (error instanceof zod.z.ZodError) {
91
+ const firstError = error.issues[0];
92
+ throw new errors_argumentError.ArgumentError(firstError.message);
93
+ }
94
+ throw error;
95
+ }
96
+ const className = messageClass.name || 'ResourceAttributeAssignment';
97
+ // First validate it's an array
98
+ utils_validation.ValidationUtils.validateArray(attributesMessages, 'attributesMessages');
99
+ // Then use Zod to validate each item is an instance of the class
100
+ const schema = zod.z.array(zod.z.any()).refine(items => {
101
+ for (let i = 0; i < items.length; i++) {
102
+ if (!(items[i] instanceof messageClass)) {
103
+ return false;
104
+ }
105
+ }
106
+ return true;
107
+ }, {
108
+ message: `All attributesMessages must be instances of ${className}`,
109
+ });
110
+ try {
111
+ schema.parse(attributesMessages);
112
+ }
113
+ catch (error) {
114
+ if (error instanceof zod.z.ZodError) {
115
+ // Find the first invalid index for a more specific error message
116
+ const invalidIndex = attributesMessages.findIndex(item => !(item instanceof messageClass));
117
+ if (invalidIndex !== -1) {
118
+ throw new errors_argumentError.ArgumentError(`All attributesMessages must be instances of ${className}, but item at index ${invalidIndex} is not`);
119
+ }
120
+ const firstError = error.issues[0];
121
+ throw new errors_argumentError.ArgumentError(firstError.message);
122
+ }
123
+ throw error;
124
+ }
125
+ }
126
+ /**
127
+ * Generic helper for executing upsert requests
128
+ */
129
+ static async executeUpsertRequest(accountId, assignments, pathTemplate, requestBodyKey, assignmentClass, logPrefix, methodName) {
130
+ // Validate inputs
131
+ utils_validation.ValidationUtils.validateInteger(accountId, 'accountId');
132
+ utils_validation.ValidationUtils.validateArray(assignments, 'assignments');
133
+ if (!assignments.length) {
134
+ authorizationInternalService.logger.warn({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId }, `${methodName} called with empty array`);
135
+ return;
136
+ }
137
+ // Validate all assignments are instances of the correct class
138
+ AuthorizationAttributesMsService.validateMessages(assignments, assignmentClass);
139
+ const requestBody = requestBodyKey === 'resourceAttributeAssignments'
140
+ ? { resourceAttributeAssignments: assignments }
141
+ : { entityAttributeAssignments: assignments };
142
+ if (!AuthorizationAttributesMsService.httpClient) {
143
+ throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
144
+ }
145
+ const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId });
146
+ const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
147
+ try {
148
+ authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Upserting ${logPrefix} attributes`);
149
+ await AuthorizationAttributesMsService.httpClient.fetch({
150
+ url: {
151
+ appName: constants.APP_NAME,
152
+ path,
153
+ },
154
+ method: 'POST',
155
+ headers,
156
+ body: JSON.stringify(requestBody),
157
+ }, {
158
+ timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
159
+ retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
160
+ });
161
+ authorizationInternalService.logger.debug({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, count: assignments.length }, `Successfully upserted ${logPrefix} attributes`);
162
+ }
163
+ catch (err) {
164
+ const error = err;
165
+ authorizationInternalService.logger.error({
166
+ tag: AuthorizationAttributesMsService.LOG_TAG,
167
+ method: methodName,
168
+ accountId,
169
+ error: error instanceof Error ? error.message : String(error),
170
+ }, `Failed in ${methodName}`);
171
+ throw error;
172
+ }
173
+ }
174
+ /**
175
+ * Generic helper for executing delete requests
176
+ */
177
+ static async executeDeleteRequest(accountId, pathTemplate, pathParams, keys, logPrefix, methodName, context = {}) {
178
+ // Validate inputs
179
+ utils_validation.ValidationUtils.validateInteger(accountId, 'accountId');
180
+ utils_validation.ValidationUtils.validateArray(keys, 'attributeKeys');
181
+ if (!keys.length) {
182
+ authorizationInternalService.logger.warn({ tag: this.LOG_TAG, accountId, ...pathParams }, `${methodName} called with empty keys array`);
183
+ return;
184
+ }
185
+ // Validate all keys are strings
186
+ utils_validation.ValidationUtils.validateStringArray(keys, 'attributeKeys');
187
+ // Build request body
188
+ const requestBody = {
189
+ keys,
190
+ };
191
+ if (!AuthorizationAttributesMsService.httpClient) {
192
+ throw new Error('AuthorizationAttributesMsService: HTTP client is not initialized');
193
+ }
194
+ const path = AuthorizationAttributesMsService.replacePathParams(pathTemplate, { accountId, ...pathParams });
195
+ const headers = AuthorizationAttributesMsService.getRequestHeaders(accountId);
196
+ try {
197
+ authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Deleting ${logPrefix} attributes`);
198
+ await AuthorizationAttributesMsService.httpClient.fetch({
199
+ url: {
200
+ appName: constants.APP_NAME,
201
+ path,
202
+ },
203
+ method: 'DELETE',
204
+ headers,
205
+ body: JSON.stringify(requestBody),
206
+ }, {
207
+ timeout: authorizationInternalService.AuthorizationInternalService.getRequestTimeout(),
208
+ retryPolicy: authorizationInternalService.AuthorizationInternalService.getRetriesPolicy(),
209
+ });
210
+ authorizationInternalService.logger.info({ tag: AuthorizationAttributesMsService.LOG_TAG, accountId, ...pathParams, keys }, `Successfully deleted ${logPrefix} attributes`);
211
+ }
212
+ catch (err) {
213
+ const error = err;
214
+ authorizationInternalService.logger.error({
215
+ tag: AuthorizationAttributesMsService.LOG_TAG,
216
+ method: methodName,
217
+ accountId,
218
+ ...pathParams,
219
+ ...context,
220
+ error: error instanceof Error ? error.message : String(error),
221
+ }, `Failed in ${methodName}`);
222
+ throw error;
223
+ }
224
+ }
225
+ /**
226
+ * Creates or updates resource attributes synchronously.
227
+ * @param accountId The account ID
228
+ * @param resourceAttributeAssignments Array of ResourceAttributeAssignment objects
229
+ * @returns Promise<void>
230
+ */
231
+ async upsertResourceAttributes(accountId, resourceAttributeAssignments, _appName, _callerActionIdentifier) {
232
+ return AuthorizationAttributesMsService.executeUpsertRequest(accountId, resourceAttributeAssignments, UPSERT_RESOURCE_ATTRIBUTES_PATH, 'resourceAttributeAssignments', resourceAttributeAssignment.ResourceAttributeAssignment, 'resource', 'upsertResourceAttributesSync');
233
+ }
234
+ /**
235
+ * Deletes specific attributes from a resource synchronously.
236
+ * @param accountId The account ID
237
+ * @param resource Object with resourceType (string) and resourceId (number)
238
+ * @param attributeKeys Array of attribute key strings to delete
239
+ * @returns Promise<void>
240
+ */
241
+ async deleteResourceAttributes(accountId, resource, attributeKeys, _appName, _callerActionIdentifier) {
242
+ // Validate resource object
243
+ if (!resource || typeof resource !== 'object') {
244
+ throw new errors_argumentError.ArgumentError('resource must be an object');
245
+ }
246
+ if (!resource.id) {
247
+ throw new errors_argumentError.ArgumentError('resource.id is required');
248
+ }
249
+ utils_validation.ValidationUtils.validateInteger(resource.id, 'resource.id');
250
+ utils_validation.ValidationUtils.validateString(resource.type, 'resource.type');
251
+ return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_RESOURCE_ATTRIBUTES_PATH, {
252
+ resourceType: resource.type,
253
+ resourceId: resource.id,
254
+ }, attributeKeys, 'resource', 'deleteResourceAttributesSync', { resource });
255
+ }
256
+ /**
257
+ * Creates or updates entity attributes synchronously.
258
+ * @param accountId The account ID
259
+ * @param entityAttributeAssignments Array of EntityAttributeAssignment objects
260
+ * @returns Promise<void>
261
+ */
262
+ async upsertEntityAttributes(accountId, entityAttributeAssignments, _appName, _callerActionIdentifier) {
263
+ return AuthorizationAttributesMsService.executeUpsertRequest(accountId, entityAttributeAssignments, UPSERT_ENTITY_ATTRIBUTES_PATH, 'entityAttributeAssignments', entityAttributeAssignment.EntityAttributeAssignment, 'entity', 'upsertEntityAttributesSync');
264
+ }
265
+ /**
266
+ * Deletes specific attributes from an entity synchronously.
267
+ * @param accountId The account ID
268
+ * @param entityType The entity type
269
+ * @param entityId The entity ID
270
+ * @param attributeKeys Array of attribute key strings to delete
271
+ * @returns Promise<void>
272
+ */
273
+ async deleteEntityAttributes(accountId, entityType, entityId, attributeKeys, _appName, _callerActionIdentifier) {
274
+ if (!entityType || typeof entityType !== 'string' || entityType.trim() === '') {
275
+ throw new errors_argumentError.ArgumentError(`entityType must be a non-empty string, got: ${entityType}`);
276
+ }
277
+ utils_validation.ValidationUtils.validateInteger(entityId, 'entityId');
278
+ return AuthorizationAttributesMsService.executeDeleteRequest(accountId, DELETE_ENTITY_ATTRIBUTES_PATH, {
279
+ entityType,
280
+ entityId,
281
+ }, attributeKeys, 'entity', 'deleteEntityAttributesSync', { entityType, entityId });
282
+ }
283
+ /**
284
+ * Updates resource attributes (batch operations).
285
+ * Note: MS service does not support batch operations directly.
286
+ * This method processes operations sequentially using upsert/delete methods.
287
+ * @param accountId The account ID
288
+ * @param appName App name (required for interface compatibility, but not used in MS service)
289
+ * @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
290
+ * @param resourceAttributeOperations Array of operations to perform
291
+ * @returns Promise<ResourceAttributesOperation[]> Array of processed operations
292
+ */
293
+ async updateResourceAttributes(accountId, _appName, _callerActionIdentifier, resourceAttributeOperations) {
294
+ const processedOperations = [];
295
+ for (const operation of resourceAttributeOperations) {
296
+ if (operation.operationType === types_authorizationAttributesContracts.AttributeOperation.UPSERT) {
297
+ if (!operation.resourceId) {
298
+ throw new errors_argumentError.ArgumentError('resourceId is required for upsert operation');
299
+ }
300
+ await this.upsertResourceAttributes(accountId, [
301
+ new resourceAttributeAssignment.ResourceAttributeAssignment(operation.resourceId, operation.resourceType, operation.key, operation.value || ''),
302
+ ]);
303
+ processedOperations.push(operation);
304
+ }
305
+ else if (operation.operationType === types_authorizationAttributesContracts.AttributeOperation.DELETE) {
306
+ if (!operation.resourceId) {
307
+ throw new errors_argumentError.ArgumentError('resourceId is required for delete operation');
308
+ }
309
+ await this.deleteResourceAttributes(accountId, {
310
+ type: operation.resourceType,
311
+ id: operation.resourceId,
312
+ }, [operation.key]);
313
+ processedOperations.push(operation);
314
+ }
315
+ }
316
+ return processedOperations;
317
+ }
318
+ /**
319
+ * Updates entity attributes (batch operations).
320
+ * Note: MS service does not support batch operations directly.
321
+ * This method processes operations sequentially using upsert/delete methods.
322
+ * @param accountId The account ID
323
+ * @param appName App name (required for interface compatibility, but not used in MS service)
324
+ * @param callerActionIdentifier Action identifier (required for interface compatibility, but not used in MS service)
325
+ * @param entityAttributeOperations Array of operations to perform
326
+ * @returns Promise<EntityAttributesOperation[]> Array of processed operations
327
+ */
328
+ async updateEntityAttributes(accountId, _appName, _callerActionIdentifier, entityAttributeOperations) {
329
+ const processedOperations = [];
330
+ for (const operation of entityAttributeOperations) {
331
+ if (operation.operationType === 'upsert') {
332
+ const upsertOp = operation;
333
+ await this.upsertEntityAttributes(accountId, [
334
+ new entityAttributeAssignment.EntityAttributeAssignment(operation.entityId, operation.entityType, operation.key, upsertOp.value || ''),
335
+ ]);
336
+ processedOperations.push(operation);
337
+ }
338
+ else if (operation.operationType === 'delete') {
339
+ await this.deleteEntityAttributes(accountId, operation.entityType, operation.entityId, [
340
+ operation.key,
341
+ ]);
342
+ processedOperations.push(operation);
343
+ }
344
+ }
345
+ return processedOperations;
346
+ }
347
+ /**
348
+ * Replaces path template parameters with actual values
349
+ * @param template Path template with placeholders like {accountId}
350
+ * @param params Object with parameter names and values
351
+ * @returns Path with all placeholders replaced
352
+ */
353
+ static replacePathParams(template, params) {
354
+ let path = template;
355
+ for (const [key, value] of Object.entries(params)) {
356
+ path = path.replace(`{${key}}`, String(value));
357
+ }
358
+ return path;
359
+ }
360
+ }
361
+
362
+ exports.AuthorizationAttributesMsService = AuthorizationAttributesMsService;
@@ -1,54 +1,33 @@
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 { 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
+ * ```typescript
8
+ * const service = new AuthorizationAttributesService();
9
+ *
10
+ * // Use direct operations
11
+ * await service.direct().upsertResourceAttributes(accountId, assignments);
12
+ *
13
+ * // Use SNS operations
14
+ * await service.sns().upsertResourceAttributes(accountId, assignments, appName, actionId);
15
+ * ```
16
+ */
5
17
  export declare class AuthorizationAttributesService {
6
- private static LOG_TAG;
7
- private static API_PATHS;
8
- private httpClient;
9
- private fetchOptions;
10
- private snsArn;
18
+ private _directService;
19
+ private _snsService;
11
20
  /**
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.
21
+ * Gets the direct (MS) service instance.
22
+ * Initializes the service on first access (lazy initialization).
23
+ * @returns IAuthorizationAttributesService instance
15
24
  */
16
- constructor(httpClient?: HttpClient, fetchOptions?: RecursivePartial<FetcherConfig>);
25
+ direct(): IAuthorizationAttributesService;
17
26
  /**
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.
27
+ * Gets the SNS service instance.
28
+ * Initializes the service on first access (lazy initialization).
29
+ * @returns IAuthorizationAttributesService instance
23
30
  */
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>;
31
+ sns(): IAuthorizationAttributesService;
53
32
  }
54
33
  //# 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,+BAA+B,EAAE,MAAM,oDAAoD,CAAC;AAErG;;;;;;;;;;;;;;GAcG;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"}