@mondaydotcomorg/monday-authorization 3.5.3-feat-shaime-support-entity-attributes-in-authorization-sdk-a77c130 → 3.6.0-feat-shaime-support-entity-attributes-1-4c8e283

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 (125) hide show
  1. package/dist/authorization-attributes-service.d.ts +47 -26
  2. package/dist/authorization-attributes-service.d.ts.map +1 -1
  3. package/dist/authorization-attributes-service.js +172 -33
  4. package/dist/authorization-middleware.d.ts +2 -2
  5. package/dist/authorization-middleware.d.ts.map +1 -1
  6. package/dist/authorization-service.d.ts +3 -3
  7. package/dist/authorization-service.d.ts.map +1 -1
  8. package/dist/base-attribute-assignment.d.ts +6 -5
  9. package/dist/base-attribute-assignment.d.ts.map +1 -1
  10. package/dist/base-attribute-assignment.js +8 -17
  11. package/dist/constants/sns.d.ts +2 -12
  12. package/dist/constants/sns.d.ts.map +1 -1
  13. package/dist/constants/sns.js +2 -22
  14. package/dist/entity-attribute-assignment.d.ts +4 -8
  15. package/dist/entity-attribute-assignment.d.ts.map +1 -1
  16. package/dist/entity-attribute-assignment.js +5 -4
  17. package/dist/entity-attributes-constants.d.ts +6 -6
  18. package/dist/entity-attributes-constants.d.ts.map +1 -1
  19. package/dist/entity-attributes-constants.js +7 -5
  20. package/dist/errors/argument-error.d.ts.map +1 -1
  21. package/dist/errors/argument-error.js +0 -1
  22. package/dist/esm/authorization-attributes-service.d.ts +47 -26
  23. package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
  24. package/dist/esm/authorization-attributes-service.mjs +168 -33
  25. package/dist/esm/authorization-middleware.d.ts +2 -2
  26. package/dist/esm/authorization-middleware.d.ts.map +1 -1
  27. package/dist/esm/authorization-service.d.ts +3 -3
  28. package/dist/esm/authorization-service.d.ts.map +1 -1
  29. package/dist/esm/base-attribute-assignment.d.ts +6 -5
  30. package/dist/esm/base-attribute-assignment.d.ts.map +1 -1
  31. package/dist/esm/base-attribute-assignment.mjs +4 -17
  32. package/dist/esm/constants/sns.d.ts +2 -12
  33. package/dist/esm/constants/sns.d.ts.map +1 -1
  34. package/dist/esm/constants/sns.mjs +3 -17
  35. package/dist/esm/entity-attribute-assignment.d.ts +4 -8
  36. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
  37. package/dist/esm/entity-attribute-assignment.mjs +5 -4
  38. package/dist/esm/entity-attributes-constants.d.ts +6 -6
  39. package/dist/esm/entity-attributes-constants.d.ts.map +1 -1
  40. package/dist/esm/entity-attributes-constants.mjs +8 -6
  41. package/dist/esm/errors/argument-error.d.ts.map +1 -1
  42. package/dist/esm/errors/argument-error.mjs +0 -1
  43. package/dist/esm/index.d.ts +0 -9
  44. package/dist/esm/index.d.ts.map +1 -1
  45. package/dist/esm/index.mjs +0 -7
  46. package/dist/esm/prometheus-service.d.ts +2 -1
  47. package/dist/esm/prometheus-service.d.ts.map +1 -1
  48. package/dist/esm/resource-attribute-assignment.d.ts +4 -8
  49. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
  50. package/dist/esm/resource-attribute-assignment.mjs +3 -2
  51. package/dist/esm/resource-attributes-constants.d.ts +21 -11
  52. package/dist/esm/resource-attributes-constants.d.ts.map +1 -1
  53. package/dist/esm/resource-attributes-constants.mjs +17 -14
  54. package/dist/esm/testKit/index.d.ts +4 -4
  55. package/dist/esm/testKit/index.d.ts.map +1 -1
  56. package/dist/esm/types/authorization-attributes-contracts.d.ts +5 -4
  57. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  58. package/dist/esm/types/authorization-attributes-service.interface.d.ts +7 -20
  59. package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -1
  60. package/dist/esm/types/general.d.ts +2 -1
  61. package/dist/esm/types/general.d.ts.map +1 -1
  62. package/dist/esm/utils/assigment-schema.d.ts +29 -0
  63. package/dist/esm/utils/assigment-schema.d.ts.map +1 -0
  64. package/dist/esm/utils/assigment-schema.mjs +29 -0
  65. package/dist/esm/utils/validation.d.ts +13 -38
  66. package/dist/esm/utils/validation.d.ts.map +1 -1
  67. package/dist/esm/utils/validation.mjs +38 -97
  68. package/dist/index.d.ts +0 -9
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +0 -15
  71. package/dist/prometheus-service.d.ts +2 -1
  72. package/dist/prometheus-service.d.ts.map +1 -1
  73. package/dist/resource-attribute-assignment.d.ts +4 -8
  74. package/dist/resource-attribute-assignment.d.ts.map +1 -1
  75. package/dist/resource-attribute-assignment.js +3 -2
  76. package/dist/resource-attributes-constants.d.ts +21 -11
  77. package/dist/resource-attributes-constants.d.ts.map +1 -1
  78. package/dist/resource-attributes-constants.js +16 -13
  79. package/dist/testKit/index.d.ts +4 -4
  80. package/dist/testKit/index.d.ts.map +1 -1
  81. package/dist/types/authorization-attributes-contracts.d.ts +5 -4
  82. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  83. package/dist/types/authorization-attributes-service.interface.d.ts +7 -20
  84. package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -1
  85. package/dist/types/general.d.ts +2 -1
  86. package/dist/types/general.d.ts.map +1 -1
  87. package/dist/utils/assigment-schema.d.ts +29 -0
  88. package/dist/utils/assigment-schema.d.ts.map +1 -0
  89. package/dist/utils/assigment-schema.js +36 -0
  90. package/dist/utils/validation.d.ts +13 -38
  91. package/dist/utils/validation.d.ts.map +1 -1
  92. package/dist/utils/validation.js +42 -97
  93. package/package.json +3 -3
  94. package/src/authorization-attributes-service.ts +223 -35
  95. package/src/authorization-middleware.ts +2 -2
  96. package/src/authorization-service.ts +4 -4
  97. package/src/base-attribute-assignment.ts +10 -35
  98. package/src/constants/sns.ts +2 -19
  99. package/src/entity-attribute-assignment.ts +9 -6
  100. package/src/entity-attributes-constants.ts +6 -6
  101. package/src/errors/argument-error.ts +0 -1
  102. package/src/index.ts +0 -9
  103. package/src/prometheus-service.ts +3 -1
  104. package/src/resource-attribute-assignment.ts +11 -13
  105. package/src/resource-attributes-constants.ts +15 -23
  106. package/src/testKit/index.ts +5 -5
  107. package/src/types/authorization-attributes-contracts.ts +5 -5
  108. package/src/types/authorization-attributes-service.interface.ts +12 -38
  109. package/src/types/general.ts +2 -3
  110. package/src/utils/assigment-schema.ts +29 -0
  111. package/src/utils/validation.ts +41 -92
  112. package/dist/authorization-attributes-ms-service.d.ts +0 -90
  113. package/dist/authorization-attributes-ms-service.d.ts.map +0 -1
  114. package/dist/authorization-attributes-ms-service.js +0 -352
  115. package/dist/authorization-attributes-sns-service.d.ts +0 -90
  116. package/dist/authorization-attributes-sns-service.d.ts.map +0 -1
  117. package/dist/authorization-attributes-sns-service.js +0 -217
  118. package/dist/esm/authorization-attributes-ms-service.d.ts +0 -90
  119. package/dist/esm/authorization-attributes-ms-service.d.ts.map +0 -1
  120. package/dist/esm/authorization-attributes-ms-service.mjs +0 -350
  121. package/dist/esm/authorization-attributes-sns-service.d.ts +0 -90
  122. package/dist/esm/authorization-attributes-sns-service.d.ts.map +0 -1
  123. package/dist/esm/authorization-attributes-sns-service.mjs +0 -211
  124. package/src/authorization-attributes-ms-service.ts +0 -514
  125. package/src/authorization-attributes-sns-service.ts +0 -312
@@ -1,33 +1,54 @@
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
- */
1
+ import { FetcherConfig, HttpClient } from '@mondaydotcomorg/trident-backend-api';
2
+ import { RecursivePartial } from '@mondaydotcomorg/monday-fetch-api';
3
+ import { ResourceAttributeAssignment, ResourceAttributeResponse, ResourceAttributeUpsertOperation } from './types/authorization-attributes-contracts';
4
+ import { Resource } from './types/general';
17
5
  export declare class AuthorizationAttributesService {
18
- private _directService;
19
- private _snsService;
6
+ private static LOG_TAG;
7
+ private static API_PATHS;
8
+ private httpClient;
9
+ private fetchOptions;
10
+ private snsArn;
20
11
  /**
21
- * Gets the direct (MS) service instance.
22
- * Initializes the service on first access (lazy initialization).
23
- * @returns IAuthorizationAttributesService instance
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.
24
15
  */
25
- direct(): IAuthorizationAttributesService;
16
+ constructor(httpClient?: HttpClient, fetchOptions?: RecursivePartial<FetcherConfig>);
26
17
  /**
27
- * Gets the SNS service instance.
28
- * Initializes the service on first access (lazy initialization).
29
- * @returns IAuthorizationAttributesService instance
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.
30
23
  */
31
- sns(): IAuthorizationAttributesService;
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: ResourceAttributeUpsertOperation[]): Promise<ResourceAttributeUpsertOperation[]>;
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>;
32
53
  }
33
54
  //# 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":"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"}
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,gCAAgC,EACjC,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;IAsBnF;;;;;;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,gCAAgC,EAAE,GAC9D,OAAO,CAAC,gCAAgC,EAAE,CAAC;YAYhC,oBAAoB;IA4BlC,OAAO,CAAC,MAAM,CAAC,cAAc;IAW7B;;;;;;;OAOG;IACG,kCAAkC,IAAI,OAAO,CAAC,OAAO,CAAC;CAoB7D"}
@@ -1,45 +1,180 @@
1
- import { AuthorizationAttributesMsService } from './authorization-attributes-ms-service.mjs';
2
- import { AuthorizationAttributesSnsService } from './authorization-attributes-sns-service.mjs';
1
+ import chunk from 'lodash/chunk.js';
2
+ import { Api } from '@mondaydotcomorg/trident-backend-api';
3
+ import { sendToSns, getTopicAttributes } from '@mondaydotcomorg/monday-sns';
4
+ import { HttpFetcherError } from '@mondaydotcomorg/monday-fetch-api';
5
+ import { logger } from './authorization-internal-service.mjs';
6
+ import { getAttributionsFromApi } from './attributions-service.mjs';
7
+ import { ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE, SNS_ARN_ENV_VAR_NAME, SNS_DEV_TEST_NAME, RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND } from './constants/sns.mjs';
8
+ import { ERROR_MESSAGES, DEFAULT_FETCH_OPTIONS, APP_NAME } from './constants.mjs';
3
9
 
4
- /**
5
- * Main service class for managing resource and entity attributes.
6
- * Provides access to both direct (MS) and SNS operations.
7
- *
8
- * @example
9
- * ```typescript
10
- * const service = new AuthorizationAttributesService();
11
- *
12
- * // Use direct operations
13
- * await service.direct().upsertResourceAttributes(accountId, assignments);
14
- *
15
- * // Use SNS operations
16
- * await service.sns().upsertResourceAttributes(accountId, assignments, appName, actionId);
17
- * ```
18
- */
19
10
  class AuthorizationAttributesService {
20
- _directService = null;
21
- _snsService = null;
11
+ static LOG_TAG = 'authorization_attributes';
12
+ static API_PATHS = {
13
+ UPSERT_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource',
14
+ DELETE_RESOURCE_ATTRIBUTES: '/attributes/{accountId}/resource/{resourceType}/{resourceId}',
15
+ };
16
+ httpClient;
17
+ fetchOptions;
18
+ snsArn;
22
19
  /**
23
- * Gets the direct (MS) service instance.
24
- * Initializes the service on first access (lazy initialization).
25
- * @returns IAuthorizationAttributesService instance
20
+ * Public constructor to create the AuthorizationAttributesService instance.
21
+ * @param httpClient The HTTP client to use for API requests, if not provided, the default HTTP client from Api will be used.
22
+ * @param fetchOptions The fetch options to use for API requests, if not provided, the default fetch options will be used.
26
23
  */
27
- direct() {
28
- if (this._directService === null) {
29
- this._directService = new AuthorizationAttributesMsService();
24
+ constructor(httpClient, fetchOptions) {
25
+ console.log(1);
26
+ if (!httpClient) {
27
+ httpClient = Api.getPart('httpClient');
28
+ if (!httpClient) {
29
+ throw new Error(ERROR_MESSAGES.HTTP_CLIENT_NOT_INITIALIZED);
30
+ }
31
+ }
32
+ if (!fetchOptions) {
33
+ fetchOptions = DEFAULT_FETCH_OPTIONS;
34
+ }
35
+ else {
36
+ fetchOptions = {
37
+ ...DEFAULT_FETCH_OPTIONS,
38
+ ...fetchOptions,
39
+ };
40
+ }
41
+ this.httpClient = httpClient;
42
+ this.fetchOptions = fetchOptions;
43
+ this.snsArn = AuthorizationAttributesService.getSnsTopicArn();
44
+ }
45
+ /**
46
+ * Upsert resource attributes synchronously, performing http call to the authorization MS to assign the given attributes to the given resource.
47
+ * @param accountId
48
+ * @param resourceAttributeAssignments - Array of resource (resourceType, resourceId) and attribute (key, value) pairs to upsert in the authorization MS.
49
+ * e.g. [{ resourceType: 'board', resourceId: 123, key: 'board_kind', value: 'private' }]
50
+ * @returns ResourceAttributeResponse - The affected (created and updated_ resource attributes assignments in the `attributes` field.
51
+ */
52
+ async upsertResourceAttributes(accountId, resourceAttributeAssignments) {
53
+ const attributionHeaders = getAttributionsFromApi();
54
+ try {
55
+ return await this.httpClient.fetch({
56
+ url: {
57
+ appName: APP_NAME,
58
+ path: AuthorizationAttributesService.API_PATHS.UPSERT_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString()),
59
+ },
60
+ method: 'POST',
61
+ headers: {
62
+ 'Content-Type': 'application/json',
63
+ ...attributionHeaders,
64
+ },
65
+ body: JSON.stringify({ resourceAttributeAssignments }),
66
+ }, this.fetchOptions);
67
+ }
68
+ catch (err) {
69
+ if (err instanceof HttpFetcherError) {
70
+ throw new Error(ERROR_MESSAGES.REQUEST_FAILED('upsertResourceAttributes', err.status, err.message));
71
+ }
72
+ throw err;
30
73
  }
31
- return this._directService;
32
74
  }
33
75
  /**
34
- * Gets the SNS service instance.
35
- * Initializes the service on first access (lazy initialization).
36
- * @returns IAuthorizationAttributesService instance
76
+ * Delete resource attributes assignments synchronously, performing http call to the authorization MS to delete the given attributes from the given singular resource.
77
+ * @param accountId
78
+ * @param resource - The resource (resourceType, resourceId) to delete the attributes for.
79
+ * @param attributeKeys - Array of attribute keys to delete for the resource.
80
+ * @returns ResourceAttributeResponse - The affected (deleted) resource attributes assignments in the `attributes` field.
37
81
  */
38
- sns() {
39
- if (this._snsService === null) {
40
- this._snsService = new AuthorizationAttributesSnsService();
82
+ async deleteResourceAttributes(accountId, resource, attributeKeys) {
83
+ const attributionHeaders = getAttributionsFromApi();
84
+ if (!resource.id) {
85
+ throw new Error('Resource ID is required');
86
+ }
87
+ try {
88
+ return await this.httpClient.fetch({
89
+ url: {
90
+ appName: APP_NAME,
91
+ path: AuthorizationAttributesService.API_PATHS.DELETE_RESOURCE_ATTRIBUTES.replace('{accountId}', accountId.toString())
92
+ .replace('{resourceType}', resource.type)
93
+ .replace('{resourceId}', resource.id.toString()),
94
+ },
95
+ method: 'DELETE',
96
+ headers: {
97
+ 'Content-Type': 'application/json',
98
+ ...attributionHeaders,
99
+ },
100
+ body: JSON.stringify({ keys: attributeKeys }),
101
+ }, this.fetchOptions);
102
+ }
103
+ catch (err) {
104
+ if (err instanceof HttpFetcherError) {
105
+ throw new Error(ERROR_MESSAGES.REQUEST_FAILED('deleteResourceAttributes', err.status, err.message));
106
+ }
107
+ throw err;
108
+ }
109
+ }
110
+ /**
111
+ * Async function, this function only send the updates request to SNS and return before the change actually took place
112
+ * @param accountId
113
+ * @param appName - App name of the calling app
114
+ * @param callerActionIdentifier - action identifier
115
+ * @param resourceAttributeOperations - Array of operations to do on resource attributes.
116
+ * @return {Promise<ResourceAttributesOperation[]>} Array of sent operations
117
+ * */
118
+ async updateResourceAttributesAsync(accountId, appName, callerActionIdentifier, resourceAttributeOperations) {
119
+ const topicArn = this.snsArn;
120
+ const sendToSnsPromises = [];
121
+ const operationChucks = chunk(resourceAttributeOperations, ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE);
122
+ for (const operationsChunk of operationChucks) {
123
+ sendToSnsPromises.push(this.sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operationsChunk));
124
+ }
125
+ return (await Promise.all(sendToSnsPromises)).flat();
126
+ }
127
+ async sendSingleSnsMessage(topicArn, accountId, appName, callerActionIdentifier, operations) {
128
+ const payload = {
129
+ kind: RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND,
130
+ payload: {
131
+ accountId: accountId,
132
+ callerAppName: appName,
133
+ callerActionIdentifier: callerActionIdentifier,
134
+ operations: operations,
135
+ },
136
+ };
137
+ try {
138
+ await sendToSns(payload, topicArn);
139
+ return operations;
140
+ }
141
+ catch (error) {
142
+ logger.error({ error, tag: AuthorizationAttributesService.LOG_TAG }, 'Authorization resource attributes async update: failed to send operations to SNS');
143
+ return [];
144
+ }
145
+ }
146
+ static getSnsTopicArn() {
147
+ const arnFromEnv = process.env[SNS_ARN_ENV_VAR_NAME];
148
+ if (arnFromEnv) {
149
+ return arnFromEnv;
150
+ }
151
+ if (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test') {
152
+ return SNS_DEV_TEST_NAME;
153
+ }
154
+ throw new Error('Unable to get sns topic arn from env variable');
155
+ }
156
+ /**
157
+ * Checks we can contact the required SNS topic that used to send attribute updates to Authorization MS.
158
+ * This function can be used as health check for services that updating resource attributes in async is crucial.
159
+ * Note this function only verify the POD can contact AWS SDK and the topic exists, but the user still might get
160
+ * errors when pushing for the SNS (e.g: in case the AWS role of the POD don't have permissions to push messages).
161
+ * However, this is the best we can do without actually push dummy messages to the SNS.
162
+ * @return {Promise<boolean>} - true if succeeded
163
+ */
164
+ async asyncResourceAttributesHealthCheck() {
165
+ try {
166
+ const requestedTopicArn = this.snsArn;
167
+ const attributes = await getTopicAttributes(requestedTopicArn);
168
+ const isHealthy = !(!attributes || !('TopicArn' in attributes) || attributes.TopicArn !== requestedTopicArn);
169
+ if (!isHealthy) {
170
+ logger.error({ requestedTopicArn, snsReturnedAttributes: attributes, tag: AuthorizationAttributesService.LOG_TAG }, 'authorization-attributes-service failed in health check');
171
+ }
172
+ return isHealthy;
173
+ }
174
+ catch (error) {
175
+ logger.error({ error, tag: AuthorizationAttributesService.LOG_TAG }, 'authorization-attributes-service got error during health check');
176
+ return false;
41
177
  }
42
- return this._snsService;
43
178
  }
44
179
  }
45
180
 
@@ -1,6 +1,6 @@
1
- import { BaseRequest, BaseResponse, Context, ContextGetter, ResourceGetter } from './types/general';
1
+ import { Action, BaseRequest, BaseResponse, Context, ContextGetter, ResourceGetter } from './types/general';
2
2
  import type { NextFunction } from 'express';
3
- export declare function getAuthorizationMiddleware(action: string, resourceGetter: ResourceGetter, contextGetter?: ContextGetter): (request: BaseRequest, response: BaseResponse, next: NextFunction) => Promise<void>;
3
+ export declare function getAuthorizationMiddleware(action: Action, 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,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
+ {"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,6 +1,6 @@
1
1
  import { MondayFetchOptions } from '@mondaydotcomorg/monday-fetch';
2
2
  import { IgniteClient } from '@mondaydotcomorg/ignite-sdk';
3
- import { AuthorizationObject, AuthorizationParams, Resource } from './types/general';
3
+ import { Action, 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: string): Promise<AuthorizeResponse>;
24
+ static isAuthorized(accountId: number, userId: number, resources: Resource[], action: Action): 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: string): AuthorizationParams;
43
+ export declare function createAuthorizationParams(resources: Resource[], action: Action): 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,mBAAmB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGrF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,0BAA0B,EAC1B,YAAY,EACb,MAAM,kCAAkC,CAAC;AAe1C,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,mBAAmB,CAAC,EAAE,mBAAmB,EAAE,CAAC;CAC7C;AAED,wBAAgB,sBAAsB,CAAC,wBAAwB,EAAE,kBAAkB,QAElF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S,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,QAAQ,EAAE,EACrB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,iBAAiB,CAAC;WAEhB,YAAY,CACvB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,2BAA2B,EAAE,mBAAmB,EAAE,GACjD,OAAO,CAAC,iBAAiB,CAAC;IAY7B;;;OAGG;WACU,wBAAwB,CACnC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE;QAAE,eAAe,CAAC,EAAE,OAAO,CAAA;KAAO,GAC1C,OAAO,CAAC,OAAO,CAAC;mBAkBE,6BAA6B;IAclD,OAAO,CAAC,MAAM,CAAC,gBAAgB;WAIlB,gBAAgB,CAC3B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,YAAY,GAClB,OAAO,CAAC,kBAAkB,CAAC;IAM9B,OAAO,CAAC,MAAM,CAAC,UAAU;WAsBZ,wBAAwB,CACnC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,YAAY,EAAE,GAC5B,OAAO,CAAC,0BAA0B,EAAE,CAAC;mBA4CnB,oBAAoB;mBAUpB,oBAAoB;CAmF1C;AAED,wBAAgB,cAAc,CAC5B,MAAM,KAAA,EACN,sCAAsC,GAAE,MAAiD,QAY1F;AAED,wBAAsB,eAAe,kBAMpC;AAED,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,CAepG"}
@@ -2,17 +2,18 @@
2
2
  * Base class for attribute assignments (Resource or Entity)
3
3
  * Provides common validation and functionality
4
4
  */
5
- export declare abstract class BaseAttributeAssignment<TId extends number, TType extends string> {
6
- readonly id: TId;
7
- readonly type: TType;
5
+ export declare abstract class BaseAttributeAssignment<T, R> {
6
+ readonly id: number;
7
+ readonly type: T;
8
8
  readonly attributeKey: string;
9
9
  readonly attributeValue: string;
10
- constructor(id: TId, type: string, attributeKey: string, attributeValue: string, validTypes: readonly string[], idFieldName: string, typeFieldName: string);
10
+ constructor(id: number, type: T, attributeKey: string, attributeValue: string);
11
11
  /**
12
12
  * Compares two assignments for equality
13
13
  * @param other Another assignment instance
14
14
  * @returns true if all properties are equal
15
15
  */
16
- equals(other: BaseAttributeAssignment<TId, TType>): boolean;
16
+ equals(other: BaseAttributeAssignment<T, R>): boolean;
17
+ abstract toDataTransferObject(): R;
17
18
  }
18
19
  //# sourceMappingURL=base-attribute-assignment.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"base-attribute-assignment.d.ts","sourceRoot":"","sources":["../../src/base-attribute-assignment.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,8BAAsB,uBAAuB,CAAC,CAAC,EAAE,CAAC;IAChD,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,IAAI,EAAE,CAAC,CAAC;IACxB,SAAgB,YAAY,EAAE,MAAM,CAAC;IACrC,SAAgB,cAAc,EAAE,MAAM,CAAC;gBAE3B,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAO7E;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO;IAIrD,QAAQ,CAAC,oBAAoB,IAAI,CAAC;CACnC"}
@@ -1,4 +1,4 @@
1
- import { ValidationUtils } from './utils/validation.mjs';
1
+ import isEqual from 'lodash/isEqual.js';
2
2
 
3
3
  /**
4
4
  * Base class for attribute assignments (Resource or Entity)
@@ -9,16 +9,9 @@ class BaseAttributeAssignment {
9
9
  type;
10
10
  attributeKey;
11
11
  attributeValue;
12
- constructor(id, type, attributeKey, attributeValue, validTypes, idFieldName, typeFieldName) {
13
- // Validate id
14
- ValidationUtils.validateInteger(id, idFieldName);
15
- // Validate type
16
- this.type = ValidationUtils.validateEnum(type, validTypes, typeFieldName);
17
- // Validate attributeKey
18
- ValidationUtils.validateString(attributeKey, 'attributeKey');
19
- // Validate attributeValue
20
- ValidationUtils.validateString(attributeValue, 'attributeValue');
12
+ constructor(id, type, attributeKey, attributeValue) {
21
13
  this.id = id;
14
+ this.type = type;
22
15
  this.attributeKey = attributeKey;
23
16
  this.attributeValue = attributeValue;
24
17
  }
@@ -28,13 +21,7 @@ class BaseAttributeAssignment {
28
21
  * @returns true if all properties are equal
29
22
  */
30
23
  equals(other) {
31
- if (!(other instanceof this.constructor)) {
32
- return false;
33
- }
34
- return (this.id === other.id &&
35
- this.type === other.type &&
36
- this.attributeKey === other.attributeKey &&
37
- this.attributeValue === other.attributeValue);
24
+ return isEqual(this, other);
38
25
  }
39
26
  }
40
27
 
@@ -1,15 +1,5 @@
1
- export declare enum SnsTopicType {
2
- RESOURCE = "resource",
3
- ENTITY = "entity"
4
- }
5
- export declare const RESOURCE_SNS_ARN_ENV_VAR_NAME = "SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES";
6
- export declare const RESOURCE_SNS_DEV_TEST_NAME = "arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local";
7
- export declare const ENTITY_SNS_ARN_ENV_VAR_NAME = "SHARED_AUTHORIZATION_SNS_ENDPOINT_ENTITY_ATTRIBUTES";
8
- export declare const ENTITY_SNS_DEV_TEST_NAME = "arn:aws:sns:us-east-1:000000000000:monday-authorization-entity-attributes-sns-local";
9
- export declare const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = "resourceAttributeModification";
10
- export declare const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = "entityAttributeModification";
11
- export declare const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
12
- export declare const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
13
1
  export declare const SNS_ARN_ENV_VAR_NAME = "SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES";
14
2
  export declare const SNS_DEV_TEST_NAME = "arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local";
3
+ export declare const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = "resourceAttributeModification";
4
+ export declare const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
15
5
  //# sourceMappingURL=sns.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sns.d.ts","sourceRoot":"","sources":["../../../src/constants/sns.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,QAAQ,aAAa;IACrB,MAAM,WAAW;CAClB;AAGD,eAAO,MAAM,6BAA6B,0DAA0D,CAAC;AACrG,eAAO,MAAM,0BAA0B,0FACkD,CAAC;AAG1F,eAAO,MAAM,2BAA2B,wDAAwD,CAAC;AACjG,eAAO,MAAM,wBAAwB,wFACkD,CAAC;AACxF,eAAO,MAAM,qDAAqD,kCAAkC,CAAC;AACrG,eAAO,MAAM,mDAAmD,gCAAgC,CAAC;AACjG,eAAO,MAAM,oDAAoD,MAAM,CAAC;AACxE,eAAO,MAAM,kDAAkD,MAAM,CAAC;AAGtE,eAAO,MAAM,oBAAoB,0DAAgC,CAAC;AAClE,eAAO,MAAM,iBAAiB,0FAA6B,CAAC"}
1
+ {"version":3,"file":"sns.d.ts","sourceRoot":"","sources":["../../../src/constants/sns.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,0DAA0D,CAAC;AAC5F,eAAO,MAAM,iBAAiB,0FAC2D,CAAC;AAC1F,eAAO,MAAM,qDAAqD,kCAAkC,CAAC;AACrG,eAAO,MAAM,oDAAoD,MAAM,CAAC"}
@@ -1,20 +1,6 @@
1
- var SnsTopicType;
2
- (function (SnsTopicType) {
3
- SnsTopicType["RESOURCE"] = "resource";
4
- SnsTopicType["ENTITY"] = "entity";
5
- })(SnsTopicType || (SnsTopicType = {}));
6
- // Resource SNS constants
7
- const RESOURCE_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES';
8
- const RESOURCE_SNS_DEV_TEST_NAME = 'arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local';
9
- // Entity SNS constants
10
- const ENTITY_SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_ENTITY_ATTRIBUTES';
11
- const ENTITY_SNS_DEV_TEST_NAME = 'arn:aws:sns:us-east-1:000000000000:monday-authorization-entity-attributes-sns-local';
1
+ const SNS_ARN_ENV_VAR_NAME = 'SHARED_AUTHORIZATION_SNS_ENDPOINT_RESOURCE_ATTRIBUTES';
2
+ const SNS_DEV_TEST_NAME = 'arn:aws:sns:us-east-1:000000000000:monday-authorization-resource-attributes-sns-local';
12
3
  const RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'resourceAttributeModification';
13
- const ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND = 'entityAttributeModification';
14
4
  const ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
15
- const ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE = 100;
16
- // Legacy exports for backward compatibility
17
- const SNS_ARN_ENV_VAR_NAME = RESOURCE_SNS_ARN_ENV_VAR_NAME;
18
- const SNS_DEV_TEST_NAME = RESOURCE_SNS_DEV_TEST_NAME;
19
5
 
20
- export { ASYNC_ENTITY_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE, ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE, ENTITY_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, ENTITY_SNS_ARN_ENV_VAR_NAME, ENTITY_SNS_DEV_TEST_NAME, RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, RESOURCE_SNS_ARN_ENV_VAR_NAME, RESOURCE_SNS_DEV_TEST_NAME, SNS_ARN_ENV_VAR_NAME, SNS_DEV_TEST_NAME, SnsTopicType };
6
+ export { ASYNC_RESOURCE_ATTRIBUTES_MAX_OPERATIONS_PER_MESSAGE, RESOURCE_ATTRIBUTES_SNS_UPDATE_OPERATION_MESSAGE_KIND, SNS_ARN_ENV_VAR_NAME, SNS_DEV_TEST_NAME };
@@ -1,15 +1,11 @@
1
1
  import { EntityType } from './entity-attributes-constants';
2
2
  import { BaseAttributeAssignment } from './base-attribute-assignment';
3
- export declare class EntityAttributeAssignment extends BaseAttributeAssignment<number, EntityType> {
3
+ import { EntityAttributeAssignment as EntityAttributeAssignmentContract } from './types/authorization-attributes-contracts';
4
+ export declare class EntityAttributeAssignment extends BaseAttributeAssignment<EntityType, EntityAttributeAssignmentContract> {
4
5
  readonly entityId: number;
5
6
  readonly entityType: EntityType;
6
- constructor(entityId: number, entityType: string, attributeKey: string, attributeValue: string);
7
- toDataTransferObject(): {
8
- entityId: number;
9
- entityType: EntityType;
10
- key: string;
11
- value: string;
12
- };
7
+ constructor(entityId: number, entityType: EntityType, key: string, value: string);
8
+ toDataTransferObject(): EntityAttributeAssignmentContract;
13
9
  /**
14
10
  * Compares two assignments for equality
15
11
  * @param other Another EntityAttributeAssignment instance
@@ -1 +1 @@
1
- {"version":3,"file":"entity-attribute-assignment.d.ts","sourceRoot":"","sources":["../../src/entity-attribute-assignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,qBAAa,yBAA0B,SAAQ,uBAAuB,CAAC,MAAM,EAAE,UAAU,CAAC;IACxF,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,UAAU,EAAE,UAAU,CAAC;gBAE3B,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAM9F,oBAAoB;;;;;;IAQpB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO;CAGlD"}
1
+ {"version":3,"file":"entity-attribute-assignment.d.ts","sourceRoot":"","sources":["../../src/entity-attribute-assignment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,yBAAyB,IAAI,iCAAiC,EAAE,MAAM,4CAA4C,CAAC;AAG5H,qBAAa,yBAA0B,SAAQ,uBAAuB,CAAC,UAAU,EAAE,iCAAiC,CAAC;IACnH,SAAgB,QAAQ,EAAE,MAAM,CAAC;IACjC,SAAgB,UAAU,EAAE,UAAU,CAAC;gBAE3B,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAOhF,oBAAoB,IAAI,iCAAiC;IAQzD;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,yBAAyB,GAAG,OAAO;CAGlD"}
@@ -1,13 +1,14 @@
1
- import { ENTITY_TYPES } from './entity-attributes-constants.mjs';
2
1
  import { BaseAttributeAssignment } from './base-attribute-assignment.mjs';
2
+ import { ValidationUtils } from './utils/validation.mjs';
3
3
 
4
4
  class EntityAttributeAssignment extends BaseAttributeAssignment {
5
5
  entityId;
6
6
  entityType;
7
- constructor(entityId, entityType, attributeKey, attributeValue) {
8
- super(entityId, entityType, attributeKey, attributeValue, Object.values(ENTITY_TYPES), 'entityId', 'entityType');
7
+ constructor(entityId, entityType, key, value) {
8
+ ValidationUtils.validateEntityAssignment({ entityId, entityType, key, value });
9
+ super(entityId, entityType, key, value);
9
10
  this.entityId = entityId;
10
- this.entityType = this.type;
11
+ this.entityType = entityType;
11
12
  }
12
13
  toDataTransferObject() {
13
14
  return {
@@ -1,7 +1,7 @@
1
- export declare const ENTITY_TYPES: {
2
- readonly USER: "user";
3
- readonly TEAM: "team";
4
- readonly ACCOUNT: "account";
5
- };
6
- export type EntityType = (typeof ENTITY_TYPES)[keyof typeof ENTITY_TYPES];
1
+ export declare enum EntityType {
2
+ User = "user",
3
+ Team = "team",
4
+ Account = "account"
5
+ }
6
+ export declare const ENTITY_TYPES: readonly EntityType[];
7
7
  //# sourceMappingURL=entity-attributes-constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entity-attributes-constants.d.ts","sourceRoot":"","sources":["../../src/entity-attributes-constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY;;;;CAIf,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC"}
1
+ {"version":3,"file":"entity-attributes-constants.d.ts","sourceRoot":"","sources":["../../src/entity-attributes-constants.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED,eAAO,MAAM,YAAY,uBAA2C,CAAC"}
@@ -1,7 +1,9 @@
1
- const ENTITY_TYPES = {
2
- USER: 'user',
3
- TEAM: 'team',
4
- ACCOUNT: 'account',
5
- };
1
+ var EntityType;
2
+ (function (EntityType) {
3
+ EntityType["User"] = "user";
4
+ EntityType["Team"] = "team";
5
+ EntityType["Account"] = "account";
6
+ })(EntityType || (EntityType = {}));
7
+ const ENTITY_TYPES = Object.freeze(Object.values(EntityType));
6
8
 
7
- export { ENTITY_TYPES };
9
+ export { ENTITY_TYPES, EntityType };
@@ -1 +1 @@
1
- {"version":3,"file":"argument-error.d.ts","sourceRoot":"","sources":["../../../src/errors/argument-error.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAK5B"}
1
+ {"version":3,"file":"argument-error.d.ts","sourceRoot":"","sources":["../../../src/errors/argument-error.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B"}
@@ -2,7 +2,6 @@ class ArgumentError extends Error {
2
2
  constructor(message) {
3
3
  super(message);
4
4
  this.name = 'ArgumentError';
5
- Object.setPrototypeOf(this, ArgumentError.prototype);
6
5
  }
7
6
  }
8
7
 
@@ -19,15 +19,6 @@ export declare function init(options?: InitOptions): Promise<void>;
19
19
  export { authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware, } from './authorization-middleware';
20
20
  export { AuthorizationService, AuthorizeResponse } from './authorization-service';
21
21
  export { AuthorizationAttributesService } from './authorization-attributes-service';
22
- export { AuthorizationAttributesSnsService } from './authorization-attributes-sns-service';
23
- export { AuthorizationAttributesMsService } from './authorization-attributes-ms-service';
24
- export { IAuthorizationAttributesService } from './types/authorization-attributes-service.interface';
25
- export { ResourceAttributeAssignment } from './resource-attribute-assignment';
26
- export { RESOURCE_TYPES, RESOURCE_ATTRIBUTES_CONSTANTS } from './resource-attributes-constants';
27
- export { EntityAttributeAssignment } from './entity-attribute-assignment';
28
- export { ENTITY_TYPES } from './entity-attributes-constants';
29
- export { ArgumentError } from './errors/argument-error';
30
- export type { EntityType } from './entity-attributes-constants';
31
22
  export { RolesService } from './roles-service';
32
23
  export { MembershipsService } from './memberships';
33
24
  export { AuthorizationObject, Resource, BaseRequest, ResourceGetter, ContextGetter } from './types/general';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGnE,OAAO,EAAqB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,UAAU,kBAAkB;IAC1B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,WAAW,CAAC,EAAE,GAAG,CAAC;IAClB,sCAAsC,CAAC,EAAE,MAAM,CAAC;IAChD,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED,wBAAsB,IAAI,CAAC,OAAO,GAAE,WAAgB,iBA6BnD;AAED,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE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{ authorizationCheckMiddleware, getAuthorizationMiddleware, skipAuthorizationMiddleware } from './authorization-middleware.mjs';
8
8
  export { AuthorizationAttributesService } from './authorization-attributes-service.mjs';
9
- export { AuthorizationAttributesSnsService } from './authorization-attributes-sns-service.mjs';
10
- export { AuthorizationAttributesMsService } from './authorization-attributes-ms-service.mjs';
11
- export { ResourceAttributeAssignment } from './resource-attribute-assignment.mjs';
12
- export { RESOURCE_ATTRIBUTES_CONSTANTS, RESOURCE_TYPES } from './resource-attributes-constants.mjs';
13
- export { EntityAttributeAssignment } from './entity-attribute-assignment.mjs';
14
- export { ENTITY_TYPES } from './entity-attributes-constants.mjs';
15
- export { ArgumentError } from './errors/argument-error.mjs';
16
9
  export { RolesService } from './roles-service.mjs';
17
10
  export { MembershipsService } from './memberships.mjs';
18
11
  export { RoleType } from './types/roles.mjs';