@mondaydotcomorg/monday-authorization 3.7.0-feat-shaime-support-entity-attributes-4-49e1de0 → 3.7.3

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 (115) hide show
  1. package/README.md +7 -1
  2. package/dist/authorization-attributes-ms-service.d.ts +20 -40
  3. package/dist/authorization-attributes-ms-service.d.ts.map +1 -1
  4. package/dist/authorization-attributes-ms-service.js +48 -103
  5. package/dist/authorization-attributes-service.d.ts +12 -10
  6. package/dist/authorization-attributes-service.d.ts.map +1 -1
  7. package/dist/authorization-attributes-service.js +17 -15
  8. package/dist/authorization-attributes-sns-service.d.ts +37 -44
  9. package/dist/authorization-attributes-sns-service.d.ts.map +1 -1
  10. package/dist/authorization-attributes-sns-service.js +53 -90
  11. package/dist/authorization-service.d.ts +0 -1
  12. package/dist/authorization-service.d.ts.map +1 -1
  13. package/dist/authorization-service.js +2 -22
  14. package/dist/base-attribute-assignment.d.ts +6 -7
  15. package/dist/base-attribute-assignment.d.ts.map +1 -1
  16. package/dist/base-attribute-assignment.js +5 -7
  17. package/dist/base-authorization-attributes-service.d.ts +32 -0
  18. package/dist/base-authorization-attributes-service.d.ts.map +1 -0
  19. package/dist/base-authorization-attributes-service.js +63 -0
  20. package/dist/entity-attribute-assignment.d.ts +4 -8
  21. package/dist/entity-attribute-assignment.d.ts.map +1 -1
  22. package/dist/entity-attribute-assignment.js +3 -4
  23. package/dist/esm/authorization-attributes-ms-service.d.ts +20 -40
  24. package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -1
  25. package/dist/esm/authorization-attributes-ms-service.mjs +48 -103
  26. package/dist/esm/authorization-attributes-service.d.ts +12 -10
  27. package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
  28. package/dist/esm/authorization-attributes-service.mjs +17 -15
  29. package/dist/esm/authorization-attributes-sns-service.d.ts +37 -44
  30. package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -1
  31. package/dist/esm/authorization-attributes-sns-service.mjs +53 -90
  32. package/dist/esm/authorization-service.d.ts +0 -1
  33. package/dist/esm/authorization-service.d.ts.map +1 -1
  34. package/dist/esm/authorization-service.mjs +3 -23
  35. package/dist/esm/base-attribute-assignment.d.ts +6 -7
  36. package/dist/esm/base-attribute-assignment.d.ts.map +1 -1
  37. package/dist/esm/base-attribute-assignment.mjs +5 -7
  38. package/dist/esm/base-authorization-attributes-service.d.ts +32 -0
  39. package/dist/esm/base-authorization-attributes-service.d.ts.map +1 -0
  40. package/dist/esm/base-authorization-attributes-service.mjs +61 -0
  41. package/dist/esm/entity-attribute-assignment.d.ts +4 -8
  42. package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
  43. package/dist/esm/entity-attribute-assignment.mjs +3 -4
  44. package/dist/esm/index.d.ts +6 -0
  45. package/dist/esm/index.d.ts.map +1 -1
  46. package/dist/esm/index.mjs +6 -0
  47. package/dist/esm/resource-attribute-assignment.d.ts +3 -7
  48. package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
  49. package/dist/esm/resource-attribute-assignment.mjs +8 -2
  50. package/dist/esm/resource-attributes-constants.d.ts +13 -10
  51. package/dist/esm/resource-attributes-constants.d.ts.map +1 -1
  52. package/dist/esm/resource-attributes-constants.mjs +5 -2
  53. package/dist/esm/testKit/index.d.ts +4 -4
  54. package/dist/esm/testKit/index.d.ts.map +1 -1
  55. package/dist/esm/types/authorization-attributes-contracts.d.ts +7 -21
  56. package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
  57. package/dist/esm/types/general.d.ts +4 -3
  58. package/dist/esm/types/general.d.ts.map +1 -1
  59. package/dist/esm/utils/assignment-schema.d.ts +51 -0
  60. package/dist/esm/utils/assignment-schema.d.ts.map +1 -0
  61. package/dist/esm/utils/assignment-schema.mjs +54 -0
  62. package/dist/esm/utils/resource-schema.d.ts +9 -0
  63. package/dist/esm/utils/resource-schema.d.ts.map +1 -0
  64. package/dist/esm/utils/resource-schema.mjs +16 -0
  65. package/dist/esm/utils/validation.d.ts +11 -28
  66. package/dist/esm/utils/validation.d.ts.map +1 -1
  67. package/dist/esm/utils/validation.mjs +61 -118
  68. package/dist/index.d.ts +6 -0
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js +24 -0
  71. package/dist/resource-attribute-assignment.d.ts +3 -7
  72. package/dist/resource-attribute-assignment.d.ts.map +1 -1
  73. package/dist/resource-attribute-assignment.js +8 -2
  74. package/dist/resource-attributes-constants.d.ts +13 -10
  75. package/dist/resource-attributes-constants.d.ts.map +1 -1
  76. package/dist/resource-attributes-constants.js +5 -2
  77. package/dist/testKit/index.d.ts +4 -4
  78. package/dist/testKit/index.d.ts.map +1 -1
  79. package/dist/types/authorization-attributes-contracts.d.ts +7 -21
  80. package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
  81. package/dist/types/general.d.ts +4 -3
  82. package/dist/types/general.d.ts.map +1 -1
  83. package/dist/utils/assignment-schema.d.ts +51 -0
  84. package/dist/utils/assignment-schema.d.ts.map +1 -0
  85. package/dist/utils/assignment-schema.js +63 -0
  86. package/dist/utils/resource-schema.d.ts +9 -0
  87. package/dist/utils/resource-schema.d.ts.map +1 -0
  88. package/dist/utils/resource-schema.js +22 -0
  89. package/dist/utils/validation.d.ts +11 -28
  90. package/dist/utils/validation.d.ts.map +1 -1
  91. package/dist/utils/validation.js +61 -118
  92. package/package.json +2 -3
  93. package/src/authorization-attributes-ms-service.ts +92 -154
  94. package/src/authorization-attributes-service.ts +18 -16
  95. package/src/authorization-attributes-sns-service.ts +132 -131
  96. package/src/authorization-service.ts +3 -28
  97. package/src/base-attribute-assignment.ts +10 -26
  98. package/src/base-authorization-attributes-service.ts +90 -0
  99. package/src/entity-attribute-assignment.ts +7 -6
  100. package/src/index.ts +17 -0
  101. package/src/resource-attribute-assignment.ts +13 -10
  102. package/src/resource-attributes-constants.ts +5 -2
  103. package/src/testKit/index.ts +5 -5
  104. package/src/types/authorization-attributes-contracts.ts +7 -27
  105. package/src/types/general.ts +4 -3
  106. package/src/utils/assignment-schema.ts +56 -0
  107. package/src/utils/resource-schema.ts +16 -0
  108. package/src/utils/validation.ts +90 -137
  109. package/dist/esm/types/authorization-attributes-service.interface.d.ts +0 -57
  110. package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +0 -1
  111. package/dist/esm/types/authorization-attributes-service.interface.mjs +0 -1
  112. package/dist/types/authorization-attributes-service.interface.d.ts +0 -57
  113. package/dist/types/authorization-attributes-service.interface.d.ts.map +0 -1
  114. package/dist/types/authorization-attributes-service.interface.js +0 -1
  115. package/src/types/authorization-attributes-service.interface.ts +0 -101
@@ -1,4 +1,4 @@
1
- export const RESOURCE_ATTRIBUTES_CONSTANTS = {
1
+ export const RESOURCE_ATTRIBUTES_CONSTANTS = Object.freeze({
2
2
  ACCOUNT_RESOURCE_ATTRIBUTES: {
3
3
  ENABLE_MEMBERS_INVITE_FROM_NON_AUTH_DOMAIN: 'enable_members_invite_from_non_auth_domain',
4
4
  },
@@ -9,7 +9,7 @@ export const RESOURCE_ATTRIBUTES_CONSTANTS = {
9
9
  IS_SYNCABLE_CHILD_ENTITY: 'is_syncable_child_entity',
10
10
  SYSTEM_ENTITY_TYPE: 'system_entity_type',
11
11
  },
12
- } as const;
12
+ });
13
13
 
14
14
  export enum ResourceType {
15
15
  Account = 'account',
@@ -21,6 +21,9 @@ export enum ResourceType {
21
21
  Overview = 'overview',
22
22
  Document = 'document',
23
23
  Crm = 'crm',
24
+ Feature = 'feature',
25
+ POST = 'post',
26
+ ASSET = 'asset',
24
27
  }
25
28
 
26
29
  // Define the array of strings and use 'as const' to make its contents literal types
@@ -1,4 +1,4 @@
1
- import { BaseRequest, BaseResponse, ContextGetter, Resource, ResourceGetter } from '../types/general';
1
+ import { Action, BaseRequest, BaseResponse, ContextGetter, Resource, ResourceGetter } from '../types/general';
2
2
  import { defaultContextGetter } from '../authorization-middleware';
3
3
  import { AuthorizationInternalService } from '../authorization-internal-service';
4
4
  import type { NextFunction } from 'express';
@@ -7,11 +7,11 @@ export type TestPermittedAction = {
7
7
  accountId: number;
8
8
  userId: number;
9
9
  resources: Resource[];
10
- action: string;
10
+ action: Action;
11
11
  };
12
12
 
13
13
  let testPermittedActions: TestPermittedAction[] = [];
14
- export const addTestPermittedAction = (accountId: number, userId: number, resources: Resource[], action: string) => {
14
+ export const addTestPermittedAction = (accountId: number, userId: number, resources: Resource[], action: Action) => {
15
15
  testPermittedActions.push({ accountId, userId, resources, action });
16
16
  };
17
17
 
@@ -19,7 +19,7 @@ export const clearTestPermittedActions = () => {
19
19
  testPermittedActions = [];
20
20
  };
21
21
 
22
- const isActionAuthorized = (accountId: number, userId: number, resources: Resource[], action: string) => {
22
+ const isActionAuthorized = (accountId: number, userId: number, resources: Resource[], action: Action) => {
23
23
  // If no resources to check, deny access
24
24
  if (resources.length === 0) {
25
25
  return { isAuthorized: false };
@@ -46,7 +46,7 @@ const isActionAuthorized = (accountId: number, userId: number, resources: Resour
46
46
  };
47
47
 
48
48
  export const getTestAuthorizationMiddleware = (
49
- action: string,
49
+ action: Action,
50
50
  resourceGetter: ResourceGetter,
51
51
  contextGetter?: ContextGetter
52
52
  ) => {
@@ -1,8 +1,7 @@
1
- import { Resource } from './general';
2
1
  import type { EntityType } from '../entity-attributes-constants';
3
2
  import type { ResourceType } from '../resource-attributes-constants';
4
3
 
5
- interface AttributeAssignment {
4
+ export interface AttributeAssignment {
6
5
  key: string;
7
6
  value: string;
8
7
  }
@@ -12,6 +11,7 @@ export interface ResourceAttributeAssignment extends AttributeAssignment {
12
11
  resourceId: number;
13
12
  resourceType: ResourceType;
14
13
  }
14
+ export type ResourceAttributeDeleteAssignment = Omit<ResourceAttributeAssignment, 'value'>;
15
15
 
16
16
  // Entity Attribute Assignment - matching API contract
17
17
  // Note: For validation, use the EntityAttributeAssignment class from '../entity-attribute-assignment'
@@ -19,38 +19,18 @@ export interface EntityAttributeAssignment extends AttributeAssignment {
19
19
  entityId: number;
20
20
  entityType: EntityType;
21
21
  }
22
-
23
- // Legacy types for backward compatibility
24
- export interface ResourceAttributeDelete {
25
- resourceType: Resource['type'];
26
- resourceId: Resource['id'];
27
- key: string;
28
- }
29
-
30
- export interface EntityAttributeDelete {
31
- entityType: EntityType;
32
- entityId: number;
33
- key: string;
34
- }
22
+ export type EntityAttributeDeleteAssignment = Omit<EntityAttributeAssignment, 'value'>;
35
23
 
36
24
  export enum AttributeOperation {
37
25
  UPSERT = 'upsert',
38
26
  DELETE = 'delete',
39
27
  }
40
-
41
- // Response types
42
- export interface ResourceAttributeResponse {
43
- attributes: ResourceAttributeAssignment[];
44
- }
45
-
46
- export interface EntityAttributeResponse {
47
- attributes: EntityAttributeAssignment[];
48
- }
49
-
50
- export interface ResourceAttributeOperation extends ResourceAttributeAssignment {
28
+ export interface ResourceAttributeUpsertOperation extends ResourceAttributeAssignment {
51
29
  operationType: AttributeOperation;
52
30
  }
31
+ export type ResourceAttributeDeleteOperation = Omit<ResourceAttributeUpsertOperation, 'value'>;
53
32
 
54
- export interface EntityAttributeOperation extends EntityAttributeAssignment {
33
+ export interface EntityAttributeUpsertOperation extends EntityAttributeAssignment {
55
34
  operationType: AttributeOperation;
56
35
  }
36
+ export type EntityAttributeDeleteOperation = Omit<EntityAttributeUpsertOperation, 'value'>;
@@ -1,8 +1,9 @@
1
1
  import type { Request, Response } from 'express';
2
+ import type { ResourceType } from '../resource-attributes-constants';
2
3
 
3
4
  export interface Resource {
4
- id?: number;
5
- type: string;
5
+ id: number;
6
+ type: ResourceType;
6
7
  wrapperData?: object;
7
8
  }
8
9
  export type Action = string;
@@ -12,7 +13,7 @@ export interface Context {
12
13
  }
13
14
  export interface AuthorizationObject {
14
15
  resource_id?: Resource['id'];
15
- resource_type: Resource['type'];
16
+ resource_type: string;
16
17
  wrapper_data?: Resource['wrapperData'];
17
18
  action: Action;
18
19
  }
@@ -0,0 +1,56 @@
1
+ import Ajv from 'ajv';
2
+ import { EntityType } from '../entity-attributes-constants';
3
+ import { ResourceType } from '../resource-attributes-constants';
4
+ import { AttributeOperation } from '../types/authorization-attributes-contracts';
5
+
6
+ const ajv = new Ajv({ allErrors: true });
7
+
8
+ export const entityUpsertAssignmentSchema = ajv.compile({
9
+ type: 'object',
10
+ properties: {
11
+ entityId: { type: 'number', multipleOf: 1 },
12
+ entityType: { type: 'string', enum: Object.values(EntityType) },
13
+ key: { type: 'string', minLength: 1 },
14
+ value: { type: 'string', minLength: 1 },
15
+ operationType: { type: 'string', enum: Object.values(AttributeOperation) },
16
+ },
17
+ required: ['entityId', 'entityType', 'key', 'value'],
18
+ additionalProperties: false,
19
+ });
20
+
21
+ export const entityDeleteAssignmentSchema = ajv.compile({
22
+ type: 'object',
23
+ properties: {
24
+ entityId: { type: 'number', multipleOf: 1 },
25
+ entityType: { type: 'string', enum: Object.values(EntityType) },
26
+ key: { type: 'string', minLength: 1 },
27
+ operationType: { type: 'string', enum: Object.values(AttributeOperation) },
28
+ },
29
+ required: ['entityId', 'entityType', 'key'],
30
+ additionalProperties: false,
31
+ });
32
+
33
+ export const resourceDeleteAssignmentSchema = ajv.compile({
34
+ type: 'object',
35
+ properties: {
36
+ resourceId: { type: 'number', multipleOf: 1 },
37
+ resourceType: { type: 'string', enum: Object.values(ResourceType) },
38
+ key: { type: 'string', minLength: 1 },
39
+ operationType: { type: 'string', enum: Object.values(AttributeOperation) },
40
+ },
41
+ required: ['resourceId', 'resourceType', 'key'],
42
+ additionalProperties: false,
43
+ });
44
+
45
+ export const resourceUpsertAssignmentSchema = ajv.compile({
46
+ type: 'object',
47
+ properties: {
48
+ resourceId: { type: 'number', multipleOf: 1 },
49
+ resourceType: { type: 'string', enum: Object.values(ResourceType) },
50
+ key: { type: 'string', minLength: 1 },
51
+ value: { type: 'string', minLength: 1 },
52
+ operationType: { type: 'string', enum: Object.values(AttributeOperation) },
53
+ },
54
+ required: ['resourceId', 'resourceType', 'key', 'value'],
55
+ additionalProperties: false,
56
+ });
@@ -0,0 +1,16 @@
1
+ import Ajv from 'ajv';
2
+ import { RESOURCE_TYPES } from '../resource-attributes-constants';
3
+
4
+ const ajv = new Ajv({ allErrors: true });
5
+
6
+ export const resourceSchema = ajv.compile({
7
+ type: 'object',
8
+ properties: {
9
+ id: { type: 'number', multipleOf: 1 },
10
+ type: { type: 'string', enum: RESOURCE_TYPES },
11
+ wrapperData: { type: 'object' },
12
+ },
13
+
14
+ required: ['id', 'type'],
15
+ additionalProperties: false,
16
+ });
@@ -1,171 +1,124 @@
1
- import Ajv from 'ajv';
1
+ import Ajv, { ValidateFunction, ErrorObject } from 'ajv';
2
2
  import { ArgumentError } from '../errors/argument-error';
3
+ import {
4
+ ResourceAttributeAssignment,
5
+ EntityAttributeAssignment,
6
+ ResourceAttributeDeleteAssignment,
7
+ EntityAttributeDeleteAssignment,
8
+ } from '../types/authorization-attributes-contracts';
3
9
  import { Resource } from '../types/general';
10
+ import {
11
+ entityUpsertAssignmentSchema,
12
+ resourceUpsertAssignmentSchema,
13
+ entityDeleteAssignmentSchema,
14
+ resourceDeleteAssignmentSchema,
15
+ } from './assignment-schema';
16
+ import { resourceSchema } from './resource-schema';
4
17
 
5
18
  /**
6
19
  * Utility class for common validation operations using AJV
7
20
  */
8
21
  export class ValidationUtils {
9
22
  private static ajv = new Ajv({ allErrors: true });
10
- /**
11
- * Validates that a value is an integer. Throws ArgumentError with a descriptive message on failure.
12
- */
13
- static validateInteger(value: number): void {
14
- const numberSchema = { type: 'number', multipleOf: 1 };
15
- const validate = ValidationUtils.ajv.compile(numberSchema);
16
- const isValid = validate(value);
17
- if (!isValid) {
18
- throw new ArgumentError(`Value must be an integer, got: ${value}`);
23
+
24
+ private static integerValidator: ValidateFunction = this.ajv.compile({ type: 'number', multipleOf: 1 });
25
+ private static stringValidator: ValidateFunction = this.ajv.compile({ type: 'string', minLength: 1 });
26
+ private static stringArrayValidator: ValidateFunction = this.ajv.compile({
27
+ type: 'array',
28
+ items: { type: 'string' },
29
+ });
30
+
31
+ public static validateInteger(value: number): void {
32
+ const valid = this.integerValidator(value);
33
+ if (!valid) {
34
+ throw new ArgumentError('Invalid integer');
19
35
  }
20
36
  }
21
37
 
22
- /**
23
- * Validates that a value is a non-empty string. Throws ArgumentError on failure.
24
- */
25
- static validateString(value: string): void {
26
- const non_empty_string_schema = {
27
- type: 'string',
28
- minLength: 1,
29
- pattern: '\\S',
30
- };
31
- const validate = ValidationUtils.ajv.compile(non_empty_string_schema);
32
- const isValid = validate(value);
33
- if (!isValid) {
34
- throw new ArgumentError(`Value must be a non-empty string, got: ${value}`);
38
+ public static validateString(value: string): void {
39
+ const valid = this.stringValidator(value);
40
+ if (!valid) {
41
+ throw new ArgumentError('Invalid string');
35
42
  }
36
43
  }
37
44
 
38
- /**
39
- * Validates that a value is an array of non-empty strings. Throws ArgumentError on failure.
40
- * Allows empty arrays - caller should handle early return.
41
- */
42
- static validateStringArray(value: string[]): void {
43
- const string_array_schema = {
44
- type: 'array',
45
- items: {
46
- type: 'string',
47
- minLength: 1,
48
- pattern: '\\S',
49
- },
50
- };
51
- const validateStringArray = ValidationUtils.ajv.compile(string_array_schema);
52
- const isValid = validateStringArray(value);
45
+ public static validateStringArray(value: string[]): void {
46
+ const valid = this.stringArrayValidator(value);
47
+ if (!valid) {
48
+ throw new ArgumentError('Invalid string array');
49
+ }
50
+ }
51
+
52
+ public static validateResource(resource: Resource) {
53
+ const isValid = resourceSchema(resource);
53
54
  if (!isValid) {
54
- throw new ArgumentError(`Value must be an array of non-empty strings, got: ${value}`);
55
+ const errorMessage = this.formatValidationErrors(resourceSchema.errors);
56
+ throw new ArgumentError(errorMessage ? `Invalid resource: ${errorMessage}` : 'Invalid resource');
55
57
  }
56
- // Allow empty arrays to pass validation - caller should handle early return
57
- // Non-empty arrays will be validated for string content above
58
58
  }
59
59
 
60
60
  /**
61
61
  * Validates an attribute assignment object using a single AJV schema.
62
62
  * Preserves legacy error messages for each field.
63
63
  */
64
- static validateAssignment<TType extends string>(
65
- data: { id: any; type: string; attributeKey: any; attributeValue: any },
66
- validTypes: readonly TType[],
67
- fieldNames: { id: string; type: string }
68
- ): { id: number; type: TType; attributeKey: string; attributeValue: string } {
69
- const schema = {
70
- type: 'object',
71
- properties: {
72
- id: { type: 'number', multipleOf: 1 },
73
- type: { type: 'string', enum: validTypes as TType[] },
74
- attributeKey: { type: 'string', minLength: 1 },
75
- attributeValue: { type: 'string', minLength: 1 },
76
- },
77
- required: ['id', 'type', 'attributeKey', 'attributeValue'],
78
- additionalProperties: false,
79
- } as const;
80
-
81
- const validate = this.ajv.compile(schema);
82
- const valid = validate(data);
64
+ static validatUpsertResourceAssignment(resource: ResourceAttributeAssignment): void {
65
+ const valid = resourceUpsertAssignmentSchema(resource);
83
66
  if (!valid) {
84
- // Map to legacy error messages deterministically
85
- const { id, type, attributeKey, attributeValue } = data;
86
-
87
- // id must be integer
88
- const isInteger = typeof id === 'number' && Number.isFinite(id) && Math.floor(id) === id;
89
- if (!isInteger) {
90
- throw new ArgumentError(`${fieldNames.id} must be an integer, got: ${id}`);
91
- }
92
-
93
- // type must be within enum
94
- if (typeof type !== 'string' || !validTypes.includes(type as TType)) {
95
- throw new ArgumentError(`${fieldNames.type} must be one of [${validTypes.join(', ')}], got: ${type}`);
96
- }
97
-
98
- // attributeKey
99
- if (typeof attributeKey !== 'string') {
100
- throw new ArgumentError(`attributeKey must be a string, got: ${typeof attributeKey}`);
101
- }
102
- if (!attributeKey) {
103
- throw new ArgumentError('attributeKey must be a non-empty string');
104
- }
105
-
106
- // attributeValue
107
- if (typeof attributeValue !== 'string') {
108
- throw new ArgumentError(`attributeValue must be a string, got: ${typeof attributeValue}`);
109
- }
110
- if (!attributeValue) {
111
- throw new ArgumentError('attributeValue must be a non-empty string');
112
- }
113
-
114
- // Fallback
115
- throw new ArgumentError('Invalid attribute assignment');
67
+ const errorMessage = this.formatValidationErrors(resourceUpsertAssignmentSchema.errors);
68
+ throw new ArgumentError(
69
+ errorMessage
70
+ ? `Invalid resource attribute assignment: ${errorMessage}`
71
+ : 'Invalid resource attribute assignment'
72
+ );
116
73
  }
117
-
118
- return {
119
- id: data.id as number,
120
- type: data.type as TType,
121
- attributeKey: data.attributeKey as string,
122
- attributeValue: data.attributeValue as string,
123
- };
124
74
  }
125
75
 
126
- /**
127
- * Validates a Resource-like object shape: { id: number; type: string }.
128
- * Throws ArgumentError with legacy-compatible messages.
129
- */
130
- static validateResource(resource: Resource): void {
131
- if (!resource || typeof resource !== 'object') {
132
- throw new ArgumentError('resource must be an object');
76
+ static validatDeleteResourceAssignment(resource: ResourceAttributeDeleteAssignment): void {
77
+ const valid = resourceDeleteAssignmentSchema(resource);
78
+ if (!valid) {
79
+ const errorMessage = this.formatValidationErrors(resourceDeleteAssignmentSchema.errors);
80
+ throw new ArgumentError(
81
+ errorMessage
82
+ ? `Invalid resource attribute assignment: ${errorMessage}`
83
+ : 'Invalid resource attribute assignment'
84
+ );
133
85
  }
134
- const schema = {
135
- type: 'object',
136
- properties: {
137
- id: { type: 'number', multipleOf: 1 },
138
- type: { type: 'string', minLength: 1 },
139
- wrapperData: { type: 'string' },
140
- },
141
- required: ['type', 'id'],
142
- additionalProperties: false,
143
- } as const;
144
- const validate = this.ajv.compile(schema);
145
- const isValid = validate(resource);
146
- if (!isValid) {
147
- throw new ArgumentError('Invalid resource');
86
+ }
87
+
88
+ static validatUpsertEntityAssignment(entity: EntityAttributeAssignment): void {
89
+ const valid = entityUpsertAssignmentSchema(entity);
90
+ if (!valid) {
91
+ const errorMessage = this.formatValidationErrors(entityUpsertAssignmentSchema.errors);
92
+ throw new ArgumentError(
93
+ errorMessage ? `Invalid entity attribute assignment: ${errorMessage}` : 'Invalid entity attribute assignment'
94
+ );
148
95
  }
149
96
  }
150
97
 
151
- static validateArrayTypeOf<T>(attributesMessages: T[], messageClass: abstract new (...args: any[]) => T): void {
152
- const arraySchema = {
153
- type: 'array',
154
- };
155
- const validateArray = ValidationUtils.ajv.compile(arraySchema);
156
- const isArrayValid = validateArray(attributesMessages);
157
- if (!isArrayValid) {
158
- throw new ArgumentError(`attributesMessages must be an array`);
98
+ static validatDeleteEntityAssignment(entity: EntityAttributeDeleteAssignment): void {
99
+ const valid = entityDeleteAssignmentSchema(entity);
100
+ if (!valid) {
101
+ const errorMessage = this.formatValidationErrors(entityDeleteAssignmentSchema.errors);
102
+ throw new ArgumentError(
103
+ errorMessage ? `Invalid entity attribute assignment: ${errorMessage}` : 'Invalid entity attribute assignment'
104
+ );
159
105
  }
160
- for (let i = 0; i < attributesMessages.length; i++) {
161
- const item = attributesMessages[i];
162
- if (!(item instanceof messageClass)) {
163
- throw new ArgumentError(
164
- `attributesMessages[${i}] must be an instance of ${messageClass.name}, got: ${
165
- item?.constructor?.name || typeof item
166
- }`
167
- );
168
- }
106
+ }
107
+ /**
108
+ * Formats AJV validation errors into a readable error message
109
+ */
110
+ private static formatValidationErrors(errors: ErrorObject[] | null | undefined): string {
111
+ if (!errors || !errors.length) {
112
+ return '';
169
113
  }
114
+
115
+ return errors
116
+ .map(err => {
117
+ const path =
118
+ err.instancePath || (err.params && 'missingProperty' in err.params ? `/${err.params.missingProperty}` : '');
119
+ const message = err.message || 'validation failed';
120
+ return path ? `${path}: ${message}` : message;
121
+ })
122
+ .join('; ');
170
123
  }
171
124
  }
@@ -1,57 +0,0 @@
1
- import { ResourceAttributeAssignment as ResourceAttributeAssignmentContract, EntityAttributeAssignment as EntityAttributeAssignmentContract, ResourceAttributeOperation, EntityAttributeOperation } from './authorization-attributes-contracts';
2
- import { ResourceAttributeAssignment } from '../resource-attribute-assignment';
3
- import { EntityAttributeAssignment } from '../entity-attribute-assignment';
4
- import { Resource } from './general';
5
- import { EntityType } from '../entity-attributes-constants';
6
- /**
7
- * Resource type compatible with both MS and SNS services
8
- */
9
- export interface CompatibleResource {
10
- resourceType?: string;
11
- resourceId?: number;
12
- type?: string;
13
- id?: number;
14
- }
15
- /**
16
- * Interface for authorization attributes operations.
17
- * Both MS (direct) and SNS (async) services implement this interface.
18
- */
19
- export interface AuthorizationAttributesService {
20
- /**authorization-attributes-service.ts
21
- * Upserts resource attributes.
22
- * For MS service: returns Promise<void>
23
- * For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
24
- */
25
- upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[] | ResourceAttributeAssignmentContract[], appName?: string, callerActionIdentifier?: string): Promise<void | ResourceAttributeOperation[]>;
26
- /**
27
- * Deletes resource attributes.
28
- * For MS service: returns Promise<void>
29
- * For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
30
- */
31
- deleteResourceAttributes(accountId: number, resource: CompatibleResource | Resource, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<void | ResourceAttributeOperation[]>;
32
- /**
33
- * Upserts entity attributes.
34
- * For MS service: returns Promise<void>
35
- * For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
36
- */
37
- upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[] | EntityAttributeAssignmentContract[], appName?: string, callerActionIdentifier?: string): Promise<void | EntityAttributeOperation[]>;
38
- /**
39
- * Deletes entity attributes.
40
- * For MS service: returns Promise<void>
41
- * For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
42
- */
43
- deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<void | EntityAttributeOperation[]>;
44
- /**
45
- * Updates resource attributes (batch operations).
46
- * For MS service: may throw error or delegate to upsert/delete
47
- * For SNS service: returns Promise<ResourceAttributesOperation[]>
48
- */
49
- updateResourceAttributes(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
50
- /**
51
- * Updates entity attributes (batch operations).
52
- * For MS service: may throw error or delegate to upsert/delete
53
- * For SNS service: returns Promise<EntityAttributesOperation[]>
54
- */
55
- updateEntityAttributes(accountId: number, appName: string, callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
56
- }
57
- //# sourceMappingURL=authorization-attributes-service.interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authorization-attributes-service.interface.d.ts","sourceRoot":"","sources":["../../../src/types/authorization-attributes-service.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,IAAI,mCAAmC,EAClE,yBAAyB,IAAI,iCAAiC,EAC9D,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,wBAAwB,CACtB,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,GAAG,mCAAmC,EAAE,EACnG,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,0BAA0B,EAAE,CAAC,CAAC;IAEhD;;;;OAIG;IACH,wBAAwB,CACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,kBAAkB,GAAG,QAAQ,EACvC,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,0BAA0B,EAAE,CAAC,CAAC;IAEhD;;;;OAIG;IACH,sBAAsB,CACpB,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,GAAG,iCAAiC,EAAE,EAC7F,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAAC,CAAC;IAE9C;;;;OAIG;IACH,sBAAsB,CACpB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAAC,CAAC;IAE9C;;;;OAIG;IACH,wBAAwB,CACtB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,0BAA0B,EAAE,GACxD,OAAO,CAAC,0BAA0B,EAAE,CAAC,CAAC;IAEzC;;;;OAIG;IACH,sBAAsB,CACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,yBAAyB,EAAE,wBAAwB,EAAE,GACpD,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;CACxC"}
@@ -1,57 +0,0 @@
1
- import { ResourceAttributeAssignment as ResourceAttributeAssignmentContract, EntityAttributeAssignment as EntityAttributeAssignmentContract, ResourceAttributeOperation, EntityAttributeOperation } from './authorization-attributes-contracts';
2
- import { ResourceAttributeAssignment } from '../resource-attribute-assignment';
3
- import { EntityAttributeAssignment } from '../entity-attribute-assignment';
4
- import { Resource } from './general';
5
- import { EntityType } from '../entity-attributes-constants';
6
- /**
7
- * Resource type compatible with both MS and SNS services
8
- */
9
- export interface CompatibleResource {
10
- resourceType?: string;
11
- resourceId?: number;
12
- type?: string;
13
- id?: number;
14
- }
15
- /**
16
- * Interface for authorization attributes operations.
17
- * Both MS (direct) and SNS (async) services implement this interface.
18
- */
19
- export interface AuthorizationAttributesService {
20
- /**authorization-attributes-service.ts
21
- * Upserts resource attributes.
22
- * For MS service: returns Promise<void>
23
- * For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
24
- */
25
- upsertResourceAttributes(accountId: number, resourceAttributeAssignments: ResourceAttributeAssignment[] | ResourceAttributeAssignmentContract[], appName?: string, callerActionIdentifier?: string): Promise<void | ResourceAttributeOperation[]>;
26
- /**
27
- * Deletes resource attributes.
28
- * For MS service: returns Promise<void>
29
- * For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
30
- */
31
- deleteResourceAttributes(accountId: number, resource: CompatibleResource | Resource, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<void | ResourceAttributeOperation[]>;
32
- /**
33
- * Upserts entity attributes.
34
- * For MS service: returns Promise<void>
35
- * For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
36
- */
37
- upsertEntityAttributes(accountId: number, entityAttributeAssignments: EntityAttributeAssignment[] | EntityAttributeAssignmentContract[], appName?: string, callerActionIdentifier?: string): Promise<void | EntityAttributeOperation[]>;
38
- /**
39
- * Deletes entity attributes.
40
- * For MS service: returns Promise<void>
41
- * For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
42
- */
43
- deleteEntityAttributes(accountId: number, entityType: EntityType | string, entityId: number, attributeKeys: string[], appName?: string, callerActionIdentifier?: string): Promise<void | EntityAttributeOperation[]>;
44
- /**
45
- * Updates resource attributes (batch operations).
46
- * For MS service: may throw error or delegate to upsert/delete
47
- * For SNS service: returns Promise<ResourceAttributesOperation[]>
48
- */
49
- updateResourceAttributes(accountId: number, appName: string, callerActionIdentifier: string, resourceAttributeOperations: ResourceAttributeOperation[]): Promise<ResourceAttributeOperation[]>;
50
- /**
51
- * Updates entity attributes (batch operations).
52
- * For MS service: may throw error or delegate to upsert/delete
53
- * For SNS service: returns Promise<EntityAttributesOperation[]>
54
- */
55
- updateEntityAttributes(accountId: number, appName: string, callerActionIdentifier: string, entityAttributeOperations: EntityAttributeOperation[]): Promise<EntityAttributeOperation[]>;
56
- }
57
- //# sourceMappingURL=authorization-attributes-service.interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authorization-attributes-service.interface.d.ts","sourceRoot":"","sources":["../../src/types/authorization-attributes-service.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,IAAI,mCAAmC,EAClE,yBAAyB,IAAI,iCAAiC,EAC9D,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;GAGG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,wBAAwB,CACtB,SAAS,EAAE,MAAM,EACjB,4BAA4B,EAAE,2BAA2B,EAAE,GAAG,mCAAmC,EAAE,EACnG,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,0BAA0B,EAAE,CAAC,CAAC;IAEhD;;;;OAIG;IACH,wBAAwB,CACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,kBAAkB,GAAG,QAAQ,EACvC,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,0BAA0B,EAAE,CAAC,CAAC;IAEhD;;;;OAIG;IACH,sBAAsB,CACpB,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,yBAAyB,EAAE,GAAG,iCAAiC,EAAE,EAC7F,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAAC,CAAC;IAE9C;;;;OAIG;IACH,sBAAsB,CACpB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,UAAU,GAAG,MAAM,EAC/B,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,CAAC,EAAE,MAAM,EAChB,sBAAsB,CAAC,EAAE,MAAM,GAC9B,OAAO,CAAC,IAAI,GAAG,wBAAwB,EAAE,CAAC,CAAC;IAE9C;;;;OAIG;IACH,wBAAwB,CACtB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,2BAA2B,EAAE,0BAA0B,EAAE,GACxD,OAAO,CAAC,0BAA0B,EAAE,CAAC,CAAC;IAEzC;;;;OAIG;IACH,sBAAsB,CACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,yBAAyB,EAAE,wBAAwB,EAAE,GACpD,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;CACxC"}