@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../src/types/general.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,EAAE,
|
|
1
|
+
{"version":3,"file":"general.d.ts","sourceRoot":"","sources":["../../src/types/general.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AACD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAC5B,MAAM,WAAW,OAAO;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAChC,YAAY,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,mBAAmB;IAClC,oBAAoB,EAAE,mBAAmB,EAAE,CAAC;CAC7C;AAED,KAAK,WAAW,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAE9C,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC;AACzC,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAC3C,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC7C,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAC9C,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,CAAC;AAC7G,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACtD,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,QAAQ,EAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const entityAssignmentSchema: import("ajv").ValidateFunction<{
|
|
2
|
+
entityId: any;
|
|
3
|
+
entityType: any;
|
|
4
|
+
key: any;
|
|
5
|
+
} & {
|
|
6
|
+
entityId: any;
|
|
7
|
+
} & {
|
|
8
|
+
entityType: any;
|
|
9
|
+
} & {
|
|
10
|
+
key: any;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const resourceAssignmentSchema: import("ajv").ValidateFunction<{
|
|
13
|
+
id: any;
|
|
14
|
+
type: any;
|
|
15
|
+
key: any;
|
|
16
|
+
} & {
|
|
17
|
+
id: any;
|
|
18
|
+
} & {
|
|
19
|
+
type: any;
|
|
20
|
+
} & {
|
|
21
|
+
key: any;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=assigment-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assigment-schema.d.ts","sourceRoot":"","sources":["../../src/utils/assigment-schema.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,sBAAsB;;;;;;;;;;EAUjC,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;EAUnC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const Ajv = require('ajv');
|
|
4
|
+
const entityAttributesConstants = require('../entity-attributes-constants.js');
|
|
5
|
+
const resourceAttributesConstants = require('../resource-attributes-constants.js');
|
|
6
|
+
|
|
7
|
+
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
8
|
+
|
|
9
|
+
const Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
10
|
+
|
|
11
|
+
const ajv = new Ajv__default.default({ allErrors: true });
|
|
12
|
+
const entityAssignmentSchema = ajv.compile({
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
entityId: { type: 'number', multipleOf: 1 },
|
|
16
|
+
entityType: { type: 'string', enum: Object.values(entityAttributesConstants.EntityType) },
|
|
17
|
+
key: { type: 'string', minLength: 1 },
|
|
18
|
+
value: { type: 'string' },
|
|
19
|
+
},
|
|
20
|
+
required: ['entityId', 'entityType', 'key'],
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
});
|
|
23
|
+
const resourceAssignmentSchema = ajv.compile({
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
id: { type: 'number', multipleOf: 1 },
|
|
27
|
+
type: { type: 'string', enum: Object.values(resourceAttributesConstants.ResourceType) },
|
|
28
|
+
key: { type: 'string', minLength: 1 },
|
|
29
|
+
value: { type: 'string' },
|
|
30
|
+
},
|
|
31
|
+
required: ['id', 'type', 'key'],
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
exports.entityAssignmentSchema = entityAssignmentSchema;
|
|
36
|
+
exports.resourceAssignmentSchema = resourceAssignmentSchema;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Resource {
|
|
2
|
+
id?: number;
|
|
3
|
+
type: string;
|
|
4
|
+
wrapperData?: object;
|
|
5
|
+
}
|
|
6
|
+
export declare const resourceSchema: import("ajv").ValidateFunction<{
|
|
7
|
+
id: any;
|
|
8
|
+
type: any;
|
|
9
|
+
wrapperData: any;
|
|
10
|
+
} & {
|
|
11
|
+
id: any;
|
|
12
|
+
} & {
|
|
13
|
+
type: any;
|
|
14
|
+
} & {
|
|
15
|
+
wrapperData: any;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=resource-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-schema.d.ts","sourceRoot":"","sources":["../../src/utils/resource-schema.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,cAAc;;;;;;;;;;EASzB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
const Ajv = require('ajv');
|
|
4
|
+
const resourceAttributesConstants = require('../resource-attributes-constants.js');
|
|
5
|
+
|
|
6
|
+
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
7
|
+
|
|
8
|
+
const Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
9
|
+
|
|
10
|
+
const ajv = new Ajv__default.default({ allErrors: true });
|
|
11
|
+
const resourceSchema = ajv.compile({
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
id: { type: 'number', multipleOf: 1 },
|
|
15
|
+
type: { type: 'string', enum: resourceAttributesConstants.RESOURCE_TYPES },
|
|
16
|
+
wrapperData: { type: 'string', minLength: 1 },
|
|
17
|
+
},
|
|
18
|
+
required: ['id', 'type', 'wrapperData'],
|
|
19
|
+
additionalProperties: false,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
exports.resourceSchema = resourceSchema;
|
|
@@ -1,45 +1,26 @@
|
|
|
1
|
+
import { ResourceAttributeAssignment, EntityAttributeAssignment } from '../types/authorization-attributes-contracts';
|
|
1
2
|
import { Resource } from '../types/general';
|
|
2
3
|
/**
|
|
3
4
|
* Utility class for common validation operations using AJV
|
|
4
5
|
*/
|
|
5
6
|
export declare class ValidationUtils {
|
|
6
7
|
private static ajv;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
private static integerValidator;
|
|
9
|
+
private static stringValidator;
|
|
10
|
+
private static stringArrayValidator;
|
|
10
11
|
static validateInteger(value: number): void;
|
|
11
|
-
/**
|
|
12
|
-
* Validates that a value is a non-empty string. Throws ArgumentError on failure.
|
|
13
|
-
*/
|
|
14
12
|
static validateString(value: string): void;
|
|
15
|
-
/**
|
|
16
|
-
* Validates that a value is an array of non-empty strings. Throws ArgumentError on failure.
|
|
17
|
-
* Allows empty arrays - caller should handle early return.
|
|
18
|
-
*/
|
|
19
13
|
static validateStringArray(value: string[]): void;
|
|
14
|
+
static validateResource(resource: Resource): void;
|
|
20
15
|
/**
|
|
21
16
|
* Validates an attribute assignment object using a single AJV schema.
|
|
22
17
|
* Preserves legacy error messages for each field.
|
|
23
18
|
*/
|
|
24
|
-
static
|
|
25
|
-
|
|
26
|
-
type: string;
|
|
27
|
-
attributeKey: any;
|
|
28
|
-
attributeValue: any;
|
|
29
|
-
}, validTypes: readonly TType[], fieldNames: {
|
|
30
|
-
id: string;
|
|
31
|
-
type: string;
|
|
32
|
-
}): {
|
|
33
|
-
id: number;
|
|
34
|
-
type: TType;
|
|
35
|
-
attributeKey: string;
|
|
36
|
-
attributeValue: string;
|
|
37
|
-
};
|
|
19
|
+
static validateResourceAssignment(resource: ResourceAttributeAssignment): void;
|
|
20
|
+
static validateEntityAssignment(entity: EntityAttributeAssignment): void;
|
|
38
21
|
/**
|
|
39
|
-
*
|
|
40
|
-
* Throws ArgumentError with legacy-compatible messages.
|
|
22
|
+
* Formats AJV validation errors into a readable error message
|
|
41
23
|
*/
|
|
42
|
-
static
|
|
43
|
-
static validateArrayTypeOf<T>(attributesMessages: T[], messageClass: abstract new (...args: any[]) => T): void;
|
|
24
|
+
private static formatValidationErrors;
|
|
44
25
|
}
|
|
45
26
|
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AACrH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAgC;IAElD,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAyE;IACxG,OAAO,CAAC,MAAM,CAAC,eAAe,CAAwE;IACtG,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAGhC;WAEW,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;WAOpC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;WAOnC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;WAO1C,gBAAgB,CAAC,QAAQ,EAAE,QAAQ;IAQjD;;;OAGG;IACH,MAAM,CAAC,0BAA0B,CAAC,QAAQ,EAAE,2BAA2B,GAAG,IAAI;IAY9E,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,yBAAyB,GAAG,IAAI;IAUxE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,sBAAsB;CActC"}
|
package/dist/utils/validation.js
CHANGED
|
@@ -2,6 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
const Ajv = require('ajv');
|
|
4
4
|
const errors_argumentError = require('../errors/argument-error.js');
|
|
5
|
+
const utils_assigmentSchema = require('./assigment-schema.js');
|
|
6
|
+
const utils_resourceSchema = require('./resource-schema.js');
|
|
5
7
|
|
|
6
8
|
const _interopDefault = e => e && e.__esModule ? e : { default: e };
|
|
7
9
|
|
|
@@ -12,146 +14,71 @@ const Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
|
|
|
12
14
|
*/
|
|
13
15
|
class ValidationUtils {
|
|
14
16
|
static ajv = new Ajv__default.default({ allErrors: true });
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
static integerValidator = this.ajv.compile({ type: 'number', multipleOf: 1 });
|
|
18
|
+
static stringValidator = this.ajv.compile({ type: 'string', minLength: 1 });
|
|
19
|
+
static stringArrayValidator = this.ajv.compile({
|
|
20
|
+
type: 'array',
|
|
21
|
+
items: { type: 'string' },
|
|
22
|
+
});
|
|
18
23
|
static validateInteger(value) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!isValid) {
|
|
23
|
-
throw new errors_argumentError.ArgumentError(`Value must be an integer, got: ${value}`);
|
|
24
|
+
const valid = this.integerValidator(value);
|
|
25
|
+
if (!valid) {
|
|
26
|
+
throw new errors_argumentError.ArgumentError('Invalid integer');
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Validates that a value is a non-empty string. Throws ArgumentError on failure.
|
|
28
|
-
*/
|
|
29
29
|
static validateString(value) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
pattern: '\\S',
|
|
34
|
-
};
|
|
35
|
-
const validate = ValidationUtils.ajv.compile(non_empty_string_schema);
|
|
36
|
-
const isValid = validate(value);
|
|
37
|
-
if (!isValid) {
|
|
38
|
-
throw new errors_argumentError.ArgumentError(`Value must be a non-empty string, got: ${value}`);
|
|
30
|
+
const valid = this.stringValidator(value);
|
|
31
|
+
if (!valid) {
|
|
32
|
+
throw new errors_argumentError.ArgumentError('Invalid string');
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Validates that a value is an array of non-empty strings. Throws ArgumentError on failure.
|
|
43
|
-
* Allows empty arrays - caller should handle early return.
|
|
44
|
-
*/
|
|
45
35
|
static validateStringArray(value) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
const validateStringArray = ValidationUtils.ajv.compile(string_array_schema);
|
|
55
|
-
const isValid = validateStringArray(value);
|
|
36
|
+
const valid = this.stringArrayValidator(value);
|
|
37
|
+
if (!valid) {
|
|
38
|
+
throw new errors_argumentError.ArgumentError('Invalid string array');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
static validateResource(resource) {
|
|
42
|
+
const isValid = utils_resourceSchema.resourceSchema(resource);
|
|
56
43
|
if (!isValid) {
|
|
57
|
-
|
|
44
|
+
const errorMessage = this.formatValidationErrors(utils_resourceSchema.resourceSchema.errors);
|
|
45
|
+
throw new errors_argumentError.ArgumentError(errorMessage ? `Invalid resource: ${errorMessage}` : 'Invalid resource');
|
|
58
46
|
}
|
|
59
|
-
// Allow empty arrays to pass validation - caller should handle early return
|
|
60
|
-
// Non-empty arrays will be validated for string content above
|
|
61
47
|
}
|
|
62
48
|
/**
|
|
63
49
|
* Validates an attribute assignment object using a single AJV schema.
|
|
64
50
|
* Preserves legacy error messages for each field.
|
|
65
51
|
*/
|
|
66
|
-
static
|
|
67
|
-
const
|
|
68
|
-
type: 'object',
|
|
69
|
-
properties: {
|
|
70
|
-
id: { type: 'number', multipleOf: 1 },
|
|
71
|
-
type: { type: 'string', enum: validTypes },
|
|
72
|
-
attributeKey: { type: 'string', minLength: 1 },
|
|
73
|
-
attributeValue: { type: 'string', minLength: 1 },
|
|
74
|
-
},
|
|
75
|
-
required: ['id', 'type', 'attributeKey', 'attributeValue'],
|
|
76
|
-
additionalProperties: false,
|
|
77
|
-
};
|
|
78
|
-
const validate = this.ajv.compile(schema);
|
|
79
|
-
const valid = validate(data);
|
|
52
|
+
static validateResourceAssignment(resource) {
|
|
53
|
+
const valid = utils_assigmentSchema.resourceAssignmentSchema(resource);
|
|
80
54
|
if (!valid) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (!isInteger) {
|
|
86
|
-
throw new errors_argumentError.ArgumentError(`${fieldNames.id} must be an integer, got: ${id}`);
|
|
87
|
-
}
|
|
88
|
-
// type must be within enum
|
|
89
|
-
if (typeof type !== 'string' || !validTypes.includes(type)) {
|
|
90
|
-
throw new errors_argumentError.ArgumentError(`${fieldNames.type} must be one of [${validTypes.join(', ')}], got: ${type}`);
|
|
91
|
-
}
|
|
92
|
-
// attributeKey
|
|
93
|
-
if (typeof attributeKey !== 'string') {
|
|
94
|
-
throw new errors_argumentError.ArgumentError(`attributeKey must be a string, got: ${typeof attributeKey}`);
|
|
95
|
-
}
|
|
96
|
-
if (!attributeKey) {
|
|
97
|
-
throw new errors_argumentError.ArgumentError('attributeKey must be a non-empty string');
|
|
98
|
-
}
|
|
99
|
-
// attributeValue
|
|
100
|
-
if (typeof attributeValue !== 'string') {
|
|
101
|
-
throw new errors_argumentError.ArgumentError(`attributeValue must be a string, got: ${typeof attributeValue}`);
|
|
102
|
-
}
|
|
103
|
-
if (!attributeValue) {
|
|
104
|
-
throw new errors_argumentError.ArgumentError('attributeValue must be a non-empty string');
|
|
105
|
-
}
|
|
106
|
-
// Fallback
|
|
107
|
-
throw new errors_argumentError.ArgumentError('Invalid attribute assignment');
|
|
55
|
+
const errorMessage = this.formatValidationErrors(utils_assigmentSchema.resourceAssignmentSchema.errors);
|
|
56
|
+
throw new errors_argumentError.ArgumentError(errorMessage
|
|
57
|
+
? `Invalid resource attribute assignment: ${errorMessage}`
|
|
58
|
+
: 'Invalid resource attribute assignment');
|
|
108
59
|
}
|
|
109
|
-
return {
|
|
110
|
-
id: data.id,
|
|
111
|
-
type: data.type,
|
|
112
|
-
attributeKey: data.attributeKey,
|
|
113
|
-
attributeValue: data.attributeValue,
|
|
114
|
-
};
|
|
115
60
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (!resource || typeof resource !== 'object') {
|
|
122
|
-
throw new errors_argumentError.ArgumentError('resource must be an object');
|
|
123
|
-
}
|
|
124
|
-
const schema = {
|
|
125
|
-
type: 'object',
|
|
126
|
-
properties: {
|
|
127
|
-
id: { type: 'number', multipleOf: 1 },
|
|
128
|
-
type: { type: 'string', minLength: 1 },
|
|
129
|
-
wrapperData: { type: 'string' },
|
|
130
|
-
},
|
|
131
|
-
required: ['type', 'id'],
|
|
132
|
-
additionalProperties: false,
|
|
133
|
-
};
|
|
134
|
-
const validate = this.ajv.compile(schema);
|
|
135
|
-
const isValid = validate(resource);
|
|
136
|
-
if (!isValid) {
|
|
137
|
-
throw new errors_argumentError.ArgumentError('Invalid resource');
|
|
61
|
+
static validateEntityAssignment(entity) {
|
|
62
|
+
const valid = utils_assigmentSchema.entityAssignmentSchema(entity);
|
|
63
|
+
if (!valid) {
|
|
64
|
+
const errorMessage = this.formatValidationErrors(utils_assigmentSchema.entityAssignmentSchema.errors);
|
|
65
|
+
throw new errors_argumentError.ArgumentError(errorMessage ? `Invalid entity attribute assignment: ${errorMessage}` : 'Invalid entity attribute assignment');
|
|
138
66
|
}
|
|
139
67
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (!isArrayValid) {
|
|
147
|
-
throw new errors_argumentError.ArgumentError(`attributesMessages must be an array`);
|
|
148
|
-
}
|
|
149
|
-
for (let i = 0; i < attributesMessages.length; i++) {
|
|
150
|
-
const item = attributesMessages[i];
|
|
151
|
-
if (!(item instanceof messageClass)) {
|
|
152
|
-
throw new errors_argumentError.ArgumentError(`attributesMessages[${i}] must be an instance of ${messageClass.name}, got: ${item?.constructor?.name || typeof item}`);
|
|
153
|
-
}
|
|
68
|
+
/**
|
|
69
|
+
* Formats AJV validation errors into a readable error message
|
|
70
|
+
*/
|
|
71
|
+
static formatValidationErrors(errors) {
|
|
72
|
+
if (!errors || errors.length === 0) {
|
|
73
|
+
return '';
|
|
154
74
|
}
|
|
75
|
+
return errors
|
|
76
|
+
.map(err => {
|
|
77
|
+
const path = err.instancePath || (err.params && 'missingProperty' in err.params ? `/${err.params.missingProperty}` : '');
|
|
78
|
+
const message = err.message || 'validation failed';
|
|
79
|
+
return path ? `${path}: ${message}` : message;
|
|
80
|
+
})
|
|
81
|
+
.join('; ');
|
|
155
82
|
}
|
|
156
83
|
}
|
|
157
84
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mondaydotcomorg/monday-authorization",
|
|
3
|
-
"version": "3.5.2-feat-shaime-support-entity-attributes-
|
|
3
|
+
"version": "3.5.2-feat-shaime-support-entity-attributes-3-00b45ac",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
@@ -28,8 +28,7 @@
|
|
|
28
28
|
"@mondaydotcomorg/monday-observability-kit": "^1.5.3",
|
|
29
29
|
"@mondaydotcomorg/monday-sns": "^1.2.1",
|
|
30
30
|
"@mondaydotcomorg/trident-backend-api": "^0.24.3",
|
|
31
|
-
"ajv": "^8.
|
|
32
|
-
"ajv-keywords": "^5.1.0",
|
|
31
|
+
"ajv": "^8.12.0",
|
|
33
32
|
"lodash": "^4.17.21",
|
|
34
33
|
"node-fetch": "^2.6.7",
|
|
35
34
|
"on-headers": "^1.0.2",
|