@mondaydotcomorg/monday-authorization 3.5.2-feat-shaime-support-entity-attributes-4-ddec1d3 → 3.5.2-feat-shaime-support-entity-attributes-3-00b45ac
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.
- package/dist/authorization-attributes-ms-service.d.ts +1 -17
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -1
- package/dist/authorization-attributes-ms-service.js +47 -58
- package/dist/authorization-attributes-sns-service.d.ts +2 -23
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -1
- package/dist/authorization-attributes-sns-service.js +11 -49
- package/dist/base-attribute-assignment.d.ts +6 -7
- package/dist/base-attribute-assignment.d.ts.map +1 -1
- package/dist/base-attribute-assignment.js +5 -7
- package/dist/entity-attribute-assignment.d.ts +4 -8
- package/dist/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/entity-attribute-assignment.js +4 -3
- package/dist/errors/argument-error.d.ts.map +1 -1
- package/dist/errors/argument-error.js +0 -1
- package/dist/esm/authorization-attributes-ms-service.d.ts +1 -17
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-ms-service.mjs +47 -58
- package/dist/esm/authorization-attributes-sns-service.d.ts +2 -23
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-sns-service.mjs +11 -49
- package/dist/esm/base-attribute-assignment.d.ts +6 -7
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/base-attribute-assignment.mjs +5 -7
- package/dist/esm/entity-attribute-assignment.d.ts +4 -8
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/entity-attribute-assignment.mjs +4 -3
- package/dist/esm/errors/argument-error.d.ts.map +1 -1
- package/dist/esm/errors/argument-error.mjs +0 -1
- package/dist/esm/resource-attribute-assignment.d.ts +3 -7
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/esm/resource-attribute-assignment.mjs +3 -2
- package/dist/esm/resource-attributes-constants.d.ts +9 -9
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -1
- package/dist/esm/resource-attributes-constants.mjs +2 -2
- package/dist/esm/testKit/index.d.ts +4 -4
- package/dist/esm/testKit/index.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.d.ts +1 -2
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +2 -16
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -1
- package/dist/esm/types/general.d.ts +1 -1
- package/dist/esm/types/general.d.ts.map +1 -1
- package/dist/esm/utils/assigment-schema.d.ts +23 -0
- package/dist/esm/utils/assigment-schema.d.ts.map +1 -0
- package/dist/esm/utils/assigment-schema.mjs +29 -0
- package/dist/esm/utils/resource-schema.d.ts +17 -0
- package/dist/esm/utils/resource-schema.d.ts.map +1 -0
- package/dist/esm/utils/resource-schema.mjs +16 -0
- package/dist/esm/utils/validation.d.ts +9 -28
- package/dist/esm/utils/validation.d.ts.map +1 -1
- package/dist/esm/utils/validation.mjs +47 -120
- package/dist/resource-attribute-assignment.d.ts +3 -7
- package/dist/resource-attribute-assignment.d.ts.map +1 -1
- package/dist/resource-attribute-assignment.js +3 -2
- package/dist/resource-attributes-constants.d.ts +9 -9
- package/dist/resource-attributes-constants.d.ts.map +1 -1
- package/dist/resource-attributes-constants.js +2 -2
- package/dist/testKit/index.d.ts +4 -4
- package/dist/testKit/index.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.d.ts +1 -2
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-service.interface.d.ts +2 -16
- package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -1
- package/dist/types/general.d.ts +1 -1
- package/dist/types/general.d.ts.map +1 -1
- package/dist/utils/assigment-schema.d.ts +23 -0
- package/dist/utils/assigment-schema.d.ts.map +1 -0
- package/dist/utils/assigment-schema.js +36 -0
- package/dist/utils/resource-schema.d.ts +17 -0
- package/dist/utils/resource-schema.d.ts.map +1 -0
- package/dist/utils/resource-schema.js +22 -0
- package/dist/utils/validation.d.ts +9 -28
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +47 -120
- package/package.json +2 -3
- package/src/authorization-attributes-ms-service.ts +93 -117
- package/src/authorization-attributes-sns-service.ts +14 -69
- package/src/base-attribute-assignment.ts +10 -26
- package/src/entity-attribute-assignment.ts +9 -6
- package/src/errors/argument-error.ts +0 -1
- package/src/resource-attribute-assignment.ts +10 -12
- package/src/resource-attributes-constants.ts +2 -2
- package/src/testKit/index.ts +5 -5
- package/src/types/authorization-attributes-contracts.ts +1 -1
- package/src/types/authorization-attributes-service.interface.ts +2 -33
- package/src/types/general.ts +1 -1
- package/src/utils/assigment-schema.ts +29 -0
- package/src/utils/resource-schema.ts +21 -0
- package/src/utils/validation.ts +60 -138
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ResourceAttributeAssignment as ResourceAttributeAssignmentContract,
|
|
3
|
-
EntityAttributeAssignment as EntityAttributeAssignmentContract,
|
|
4
|
-
ResourceAttributeOperation,
|
|
5
|
-
EntityAttributeOperation,
|
|
6
|
-
} from './authorization-attributes-contracts';
|
|
7
|
-
import { ResourceAttributeAssignment } from '../resource-attribute-assignment';
|
|
8
|
-
import { EntityAttributeAssignment } from '../entity-attribute-assignment';
|
|
9
|
-
import { Resource } from './general';
|
|
10
1
|
import { EntityType } from '../entity-attributes-constants';
|
|
2
|
+
import { ResourceAttributeOperation, EntityAttributeOperation } from './authorization-attributes-contracts';
|
|
3
|
+
import { Resource } from './general';
|
|
11
4
|
|
|
12
5
|
/**
|
|
13
6
|
* Resource type compatible with both MS and SNS services
|
|
@@ -24,18 +17,6 @@ export interface CompatibleResource {
|
|
|
24
17
|
* Both MS (direct) and SNS (async) services implement this interface.
|
|
25
18
|
*/
|
|
26
19
|
export interface AuthorizationAttributesService {
|
|
27
|
-
/**authorization-attributes-service.ts
|
|
28
|
-
* Upserts resource attributes.
|
|
29
|
-
* For MS service: returns Promise<void>
|
|
30
|
-
* For SNS service: requires appName and callerActionIdentifier, returns Promise<ResourceAttributesOperation[]>
|
|
31
|
-
*/
|
|
32
|
-
upsertResourceAttributes(
|
|
33
|
-
accountId: number,
|
|
34
|
-
resourceAttributeAssignments: ResourceAttributeAssignment[] | ResourceAttributeAssignmentContract[],
|
|
35
|
-
appName?: string,
|
|
36
|
-
callerActionIdentifier?: string
|
|
37
|
-
): Promise<void | ResourceAttributeOperation[]>;
|
|
38
|
-
|
|
39
20
|
/**
|
|
40
21
|
* Deletes resource attributes.
|
|
41
22
|
* For MS service: returns Promise<void>
|
|
@@ -49,18 +30,6 @@ export interface AuthorizationAttributesService {
|
|
|
49
30
|
callerActionIdentifier?: string
|
|
50
31
|
): Promise<void | ResourceAttributeOperation[]>;
|
|
51
32
|
|
|
52
|
-
/**
|
|
53
|
-
* Upserts entity attributes.
|
|
54
|
-
* For MS service: returns Promise<void>
|
|
55
|
-
* For SNS service: requires appName and callerActionIdentifier, returns Promise<EntityAttributesOperation[]>
|
|
56
|
-
*/
|
|
57
|
-
upsertEntityAttributes(
|
|
58
|
-
accountId: number,
|
|
59
|
-
entityAttributeAssignments: EntityAttributeAssignment[] | EntityAttributeAssignmentContract[],
|
|
60
|
-
appName?: string,
|
|
61
|
-
callerActionIdentifier?: string
|
|
62
|
-
): Promise<void | EntityAttributeOperation[]>;
|
|
63
|
-
|
|
64
33
|
/**
|
|
65
34
|
* Deletes entity attributes.
|
|
66
35
|
* For MS service: returns Promise<void>
|
package/src/types/general.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import { EntityType } from '../entity-attributes-constants';
|
|
3
|
+
import { ResourceType } from '../resource-attributes-constants';
|
|
4
|
+
|
|
5
|
+
const ajv = new Ajv({ allErrors: true });
|
|
6
|
+
|
|
7
|
+
export const entityAssignmentSchema = ajv.compile({
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
entityId: { type: 'number', multipleOf: 1 },
|
|
11
|
+
entityType: { type: 'string', enum: Object.values(EntityType) },
|
|
12
|
+
key: { type: 'string', minLength: 1 },
|
|
13
|
+
value: { type: 'string' },
|
|
14
|
+
},
|
|
15
|
+
required: ['entityId', 'entityType', 'key'],
|
|
16
|
+
additionalProperties: false,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export const resourceAssignmentSchema = ajv.compile({
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
id: { type: 'number', multipleOf: 1 },
|
|
23
|
+
type: { type: 'string', enum: Object.values(ResourceType) },
|
|
24
|
+
key: { type: 'string', minLength: 1 },
|
|
25
|
+
value: { type: 'string' },
|
|
26
|
+
},
|
|
27
|
+
required: ['id', 'type', 'key'],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Ajv from 'ajv';
|
|
2
|
+
import { RESOURCE_TYPES } from '../resource-attributes-constants';
|
|
3
|
+
|
|
4
|
+
const ajv = new Ajv({ allErrors: true });
|
|
5
|
+
|
|
6
|
+
export interface Resource {
|
|
7
|
+
id?: number;
|
|
8
|
+
type: string;
|
|
9
|
+
wrapperData?: object;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const resourceSchema = ajv.compile({
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
id: { type: 'number', multipleOf: 1 },
|
|
16
|
+
type: { type: 'string', enum: RESOURCE_TYPES },
|
|
17
|
+
wrapperData: { type: 'string', minLength: 1 },
|
|
18
|
+
},
|
|
19
|
+
required: ['id', 'type', 'wrapperData'],
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
});
|
package/src/utils/validation.ts
CHANGED
|
@@ -1,171 +1,93 @@
|
|
|
1
|
-
import Ajv from 'ajv';
|
|
1
|
+
import Ajv, { ValidateFunction, ErrorObject } from 'ajv';
|
|
2
2
|
import { ArgumentError } from '../errors/argument-error';
|
|
3
|
+
import { ResourceAttributeAssignment, EntityAttributeAssignment } from '../types/authorization-attributes-contracts';
|
|
3
4
|
import { Resource } from '../types/general';
|
|
5
|
+
import { entityAssignmentSchema, resourceAssignmentSchema } from './assigment-schema';
|
|
6
|
+
import { resourceSchema } from './resource-schema';
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Utility class for common validation operations using AJV
|
|
7
10
|
*/
|
|
8
11
|
export class ValidationUtils {
|
|
9
12
|
private static ajv = new Ajv({ allErrors: true });
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
static
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
|
|
14
|
+
private static integerValidator: ValidateFunction = this.ajv.compile({ type: 'number', multipleOf: 1 });
|
|
15
|
+
private static stringValidator: ValidateFunction = this.ajv.compile({ type: 'string', minLength: 1 });
|
|
16
|
+
private static stringArrayValidator: ValidateFunction = this.ajv.compile({
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: { type: 'string' },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
public static validateInteger(value: number): void {
|
|
22
|
+
const valid = this.integerValidator(value);
|
|
23
|
+
if (!valid) {
|
|
24
|
+
throw new ArgumentError('Invalid integer');
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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}`);
|
|
28
|
+
public static validateString(value: string): void {
|
|
29
|
+
const valid = this.stringValidator(value);
|
|
30
|
+
if (!valid) {
|
|
31
|
+
throw new ArgumentError('Invalid string');
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
minLength: 1,
|
|
48
|
-
pattern: '\\S',
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
const validateStringArray = ValidationUtils.ajv.compile(string_array_schema);
|
|
52
|
-
const isValid = validateStringArray(value);
|
|
35
|
+
public static validateStringArray(value: string[]): void {
|
|
36
|
+
const valid = this.stringArrayValidator(value);
|
|
37
|
+
if (!valid) {
|
|
38
|
+
throw new ArgumentError('Invalid string array');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static validateResource(resource: Resource) {
|
|
43
|
+
const isValid = resourceSchema(resource);
|
|
53
44
|
if (!isValid) {
|
|
54
|
-
|
|
45
|
+
const errorMessage = this.formatValidationErrors(resourceSchema.errors);
|
|
46
|
+
throw new ArgumentError(errorMessage ? `Invalid resource: ${errorMessage}` : 'Invalid resource');
|
|
55
47
|
}
|
|
56
|
-
// Allow empty arrays to pass validation - caller should handle early return
|
|
57
|
-
// Non-empty arrays will be validated for string content above
|
|
58
48
|
}
|
|
59
49
|
|
|
60
50
|
/**
|
|
61
51
|
* Validates an attribute assignment object using a single AJV schema.
|
|
62
52
|
* Preserves legacy error messages for each field.
|
|
63
53
|
*/
|
|
64
|
-
static
|
|
65
|
-
|
|
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);
|
|
54
|
+
static validateResourceAssignment(resource: ResourceAttributeAssignment): void {
|
|
55
|
+
const valid = resourceAssignmentSchema(resource);
|
|
83
56
|
if (!valid) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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');
|
|
57
|
+
const errorMessage = this.formatValidationErrors(resourceAssignmentSchema.errors);
|
|
58
|
+
throw new ArgumentError(
|
|
59
|
+
errorMessage
|
|
60
|
+
? `Invalid resource attribute assignment: ${errorMessage}`
|
|
61
|
+
: 'Invalid resource attribute assignment'
|
|
62
|
+
);
|
|
116
63
|
}
|
|
64
|
+
}
|
|
117
65
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
66
|
+
static validateEntityAssignment(entity: EntityAttributeAssignment): void {
|
|
67
|
+
const valid = entityAssignmentSchema(entity);
|
|
68
|
+
if (!valid) {
|
|
69
|
+
const errorMessage = this.formatValidationErrors(entityAssignmentSchema.errors);
|
|
70
|
+
throw new ArgumentError(
|
|
71
|
+
errorMessage ? `Invalid entity attribute assignment: ${errorMessage}` : 'Invalid entity attribute assignment'
|
|
72
|
+
);
|
|
73
|
+
}
|
|
124
74
|
}
|
|
125
75
|
|
|
126
76
|
/**
|
|
127
|
-
*
|
|
128
|
-
* Throws ArgumentError with legacy-compatible messages.
|
|
77
|
+
* Formats AJV validation errors into a readable error message
|
|
129
78
|
*/
|
|
130
|
-
static
|
|
131
|
-
if (!
|
|
132
|
-
|
|
133
|
-
}
|
|
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');
|
|
79
|
+
private static formatValidationErrors(errors: ErrorObject[] | null | undefined): string {
|
|
80
|
+
if (!errors || errors.length === 0) {
|
|
81
|
+
return '';
|
|
148
82
|
}
|
|
149
|
-
}
|
|
150
83
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
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
|
-
}
|
|
169
|
-
}
|
|
84
|
+
return errors
|
|
85
|
+
.map(err => {
|
|
86
|
+
const path =
|
|
87
|
+
err.instancePath || (err.params && 'missingProperty' in err.params ? `/${err.params.missingProperty}` : '');
|
|
88
|
+
const message = err.message || 'validation failed';
|
|
89
|
+
return path ? `${path}: ${message}` : message;
|
|
90
|
+
})
|
|
91
|
+
.join('; ');
|
|
170
92
|
}
|
|
171
93
|
}
|