@mondaydotcomorg/monday-authorization 3.5.1 → 3.5.2-feat-shaime-support-entity-attributes-3-6202ab7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authorization-attributes-ms-service.d.ts +72 -0
- package/dist/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/authorization-attributes-ms-service.js +279 -0
- package/dist/authorization-attributes-service.d.ts +25 -47
- package/dist/authorization-attributes-service.d.ts.map +1 -1
- package/dist/authorization-attributes-service.js +32 -171
- package/dist/authorization-attributes-sns-service.d.ts +70 -0
- package/dist/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/authorization-attributes-sns-service.js +179 -0
- package/dist/base-attribute-assignment.d.ts +19 -0
- package/dist/base-attribute-assignment.d.ts.map +1 -0
- package/dist/base-attribute-assignment.js +34 -0
- package/dist/constants/sns.d.ts +12 -2
- package/dist/constants/sns.d.ts.map +1 -1
- package/dist/constants/sns.js +22 -2
- package/dist/entity-attribute-assignment.d.ts +16 -0
- package/dist/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/entity-attribute-assignment.js +33 -0
- package/dist/entity-attributes-constants.d.ts +7 -0
- package/dist/entity-attributes-constants.d.ts.map +1 -0
- package/dist/entity-attributes-constants.js +11 -0
- package/dist/errors/argument-error.d.ts +4 -0
- package/dist/errors/argument-error.d.ts.map +1 -0
- package/dist/errors/argument-error.js +10 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts +72 -0
- package/dist/esm/authorization-attributes-ms-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-ms-service.mjs +277 -0
- package/dist/esm/authorization-attributes-service.d.ts +25 -47
- package/dist/esm/authorization-attributes-service.d.ts.map +1 -1
- package/dist/esm/authorization-attributes-service.mjs +32 -167
- package/dist/esm/authorization-attributes-sns-service.d.ts +70 -0
- package/dist/esm/authorization-attributes-sns-service.d.ts.map +1 -0
- package/dist/esm/authorization-attributes-sns-service.mjs +173 -0
- package/dist/esm/base-attribute-assignment.d.ts +19 -0
- package/dist/esm/base-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/base-attribute-assignment.mjs +28 -0
- package/dist/esm/constants/sns.d.ts +12 -2
- package/dist/esm/constants/sns.d.ts.map +1 -1
- package/dist/esm/constants/sns.mjs +17 -3
- package/dist/esm/entity-attribute-assignment.d.ts +16 -0
- package/dist/esm/entity-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/entity-attribute-assignment.mjs +31 -0
- package/dist/esm/entity-attributes-constants.d.ts +7 -0
- package/dist/esm/entity-attributes-constants.d.ts.map +1 -0
- package/dist/esm/entity-attributes-constants.mjs +9 -0
- package/dist/esm/errors/argument-error.d.ts +4 -0
- package/dist/esm/errors/argument-error.d.ts.map +1 -0
- package/dist/esm/errors/argument-error.mjs +8 -0
- package/dist/esm/resource-attribute-assignment.d.ts +16 -0
- package/dist/esm/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/esm/resource-attribute-assignment.mjs +31 -0
- package/dist/esm/resource-attributes-constants.d.ts +25 -0
- package/dist/esm/resource-attributes-constants.d.ts.map +1 -0
- package/dist/esm/resource-attributes-constants.mjs +28 -0
- package/dist/esm/types/authorization-attributes-contracts.d.ts +26 -12
- package/dist/esm/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/esm/types/authorization-attributes-contracts.mjs +6 -6
- package/dist/esm/types/authorization-attributes-service.interface.d.ts +43 -0
- package/dist/esm/types/authorization-attributes-service.interface.d.ts.map +1 -0
- package/dist/esm/types/authorization-attributes-service.interface.mjs +1 -0
- 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 +26 -0
- package/dist/esm/utils/validation.d.ts.map +1 -0
- package/dist/esm/utils/validation.mjs +70 -0
- package/dist/resource-attribute-assignment.d.ts +16 -0
- package/dist/resource-attribute-assignment.d.ts.map +1 -0
- package/dist/resource-attribute-assignment.js +33 -0
- package/dist/resource-attributes-constants.d.ts +25 -0
- package/dist/resource-attributes-constants.d.ts.map +1 -0
- package/dist/resource-attributes-constants.js +31 -0
- package/dist/types/authorization-attributes-contracts.d.ts +26 -12
- package/dist/types/authorization-attributes-contracts.d.ts.map +1 -1
- package/dist/types/authorization-attributes-contracts.js +5 -5
- package/dist/types/authorization-attributes-service.interface.d.ts +43 -0
- package/dist/types/authorization-attributes-service.interface.d.ts.map +1 -0
- package/dist/types/authorization-attributes-service.interface.js +1 -0
- 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 +26 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +76 -0
- package/package.json +3 -1
- package/src/authorization-attributes-ms-service.ts +414 -0
- package/src/authorization-attributes-service.ts +34 -222
- package/src/authorization-attributes-sns-service.ts +257 -0
- package/src/base-attribute-assignment.ts +30 -0
- package/src/constants/sns.ts +19 -2
- package/src/entity-attribute-assignment.ts +33 -0
- package/src/entity-attributes-constants.ts +7 -0
- package/src/errors/argument-error.ts +6 -0
- package/src/resource-attribute-assignment.ts +36 -0
- package/src/resource-attributes-constants.ts +27 -0
- package/src/types/authorization-attributes-contracts.ts +34 -11
- package/src/types/authorization-attributes-service.interface.ts +70 -0
- 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 +82 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import Ajv, { ValidateFunction, ErrorObject } from 'ajv';
|
|
2
|
+
import { ArgumentError } from '../errors/argument-error';
|
|
3
|
+
import { ResourceAttributeAssignment, EntityAttributeAssignment } from '../types/authorization-attributes-contracts';
|
|
4
|
+
import { Resource } from '../types/general';
|
|
5
|
+
import { entityAssignmentSchema, resourceAssignmentSchema } from './assigment-schema';
|
|
6
|
+
import { resourceSchema } from './resource-schema';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Utility class for common validation operations using AJV
|
|
10
|
+
*/
|
|
11
|
+
export class ValidationUtils {
|
|
12
|
+
private static ajv = new Ajv({ allErrors: true });
|
|
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');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static validateString(value: string): void {
|
|
29
|
+
const valid = this.stringValidator(value);
|
|
30
|
+
if (!valid) {
|
|
31
|
+
throw new ArgumentError('Invalid string');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
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);
|
|
44
|
+
if (!isValid) {
|
|
45
|
+
const errorMessage = this.formatValidationErrors(resourceSchema.errors);
|
|
46
|
+
throw new ArgumentError(errorMessage ? `Invalid resource: ${errorMessage}` : 'Invalid resource');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Validates an attribute assignment object using a single AJV schema.
|
|
52
|
+
* Preserves legacy error messages for each field.
|
|
53
|
+
*/
|
|
54
|
+
static validateResourceAssignment(resource: ResourceAttributeAssignment): void {
|
|
55
|
+
const valid = resourceAssignmentSchema(resource);
|
|
56
|
+
if (!valid) {
|
|
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
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
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
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Formats AJV validation errors into a readable error message
|
|
78
|
+
*/
|
|
79
|
+
private static formatValidationErrors(errors: ErrorObject[] | null | undefined): string {
|
|
80
|
+
return (errors || []).join();
|
|
81
|
+
}
|
|
82
|
+
}
|