@hosterai/types 0.0.31 → 0.0.32

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 (33) hide show
  1. package/README.md +1 -6
  2. package/dist/decorators/unique-field-in-array-validator.spec.js +0 -14
  3. package/dist/decorators/unique-field-in-array.validator.js +4 -18
  4. package/dist/dtos/addon-field.dto.d.ts +2 -6
  5. package/dist/dtos/addon-field.dto.js +2 -25
  6. package/dist/dtos/attribute-field.dto.d.ts +6 -18
  7. package/dist/dtos/attribute-field.dto.js +2 -18
  8. package/dist/dtos/field.dto.d.ts +64 -5
  9. package/dist/dtos/field.dto.js +186 -0
  10. package/dist/dtos/info.dto.d.ts +9 -2
  11. package/dist/dtos/info.dto.js +16 -2
  12. package/dist/dtos/product/product-info.dto.js +2 -2
  13. package/dist/dtos/responses/validate-attributes-response.dto.d.ts +4 -4
  14. package/dist/dtos/responses/validate-attributes-response.dto.js +6 -2
  15. package/dist/enums/field-type.enum.d.ts +7 -20
  16. package/dist/enums/field-type.enum.js +7 -19
  17. package/dist/enums/roles.enum.d.ts +1 -0
  18. package/dist/enums/roles.enum.js +1 -0
  19. package/dist/index.d.ts +0 -29
  20. package/dist/index.js +0 -29
  21. package/dist/openapi/schemas/components.schemas.d.ts +262 -1174
  22. package/dist/openapi/schemas/components.schemas.js +660 -1944
  23. package/dist/validators/addon-field-validator.d.ts +1 -4
  24. package/dist/validators/addon-field-validator.js +3 -22
  25. package/dist/validators/addon-field-validator.spec.js +21 -15
  26. package/dist/validators/attribute-field-validator.d.ts +0 -4
  27. package/dist/validators/attribute-field-validator.js +0 -16
  28. package/dist/validators/attribute-field-validator.spec.js +20 -30
  29. package/dist/validators/field-validator.d.ts +4 -2
  30. package/dist/validators/field-validator.js +10 -4
  31. package/dist/validators/field-validator.spec.js +79 -16
  32. package/dist/validators/product-info-validator.spec.js +108 -42
  33. package/package.json +1 -1
@@ -1,10 +1,7 @@
1
1
  import { ValidationError } from 'class-validator';
2
2
  /**
3
3
  * Validates an AddonFieldDto object.
4
- *
5
- * The nested `field` (a discriminated `AnyFieldDto`) is validated separately
6
- * via the dispatcher; its errors are merged into the returned list under the
7
- * `field` property.
4
+ * Since AddonFieldDto is an empty subclass of FieldDto, this delegates to validateFieldDto.
8
5
  *
9
6
  * @param data The object to validate as an AddonFieldDto.
10
7
  * @returns An array of validation errors, empty if validation succeeds.
@@ -1,33 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateAddonFieldDto = validateAddonFieldDto;
4
- const class_validator_1 = require("class-validator");
5
- const class_transformer_1 = require("class-transformer");
6
- const addon_field_dto_1 = require("../dtos/addon-field.dto");
7
- const any_field_validator_1 = require("./any-field-validator");
4
+ const field_validator_1 = require("./field-validator");
8
5
  /**
9
6
  * Validates an AddonFieldDto object.
10
- *
11
- * The nested `field` (a discriminated `AnyFieldDto`) is validated separately
12
- * via the dispatcher; its errors are merged into the returned list under the
13
- * `field` property.
7
+ * Since AddonFieldDto is an empty subclass of FieldDto, this delegates to validateFieldDto.
14
8
  *
15
9
  * @param data The object to validate as an AddonFieldDto.
16
10
  * @returns An array of validation errors, empty if validation succeeds.
17
11
  */
18
12
  function validateAddonFieldDto(data) {
19
- const dto = (0, class_transformer_1.plainToInstance)(addon_field_dto_1.AddonFieldDto, data);
20
- const errors = (0, class_validator_1.validateSync)(dto);
21
- const field = data === null || data === void 0 ? void 0 : data.field;
22
- if (field && typeof field === 'object') {
23
- const fieldErrors = (0, any_field_validator_1.validateAnyFieldDto)(field);
24
- if (fieldErrors.length > 0) {
25
- const wrapped = new class_validator_1.ValidationError();
26
- wrapped.property = 'field';
27
- wrapped.value = field;
28
- wrapped.children = fieldErrors;
29
- errors.push(wrapped);
30
- }
31
- }
32
- return errors;
13
+ return (0, field_validator_1.validateFieldDto)(data);
33
14
  }
@@ -2,17 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("reflect-metadata");
4
4
  const addon_field_validator_1 = require("./addon-field-validator");
5
+ const field_type_enum_1 = require("../enums/field-type.enum");
5
6
  const language_enum_1 = require("../enums/language.enum");
6
- const validField = {
7
+ const baseValidDto = {
7
8
  id: 'addon-1',
8
9
  label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Addon Field' }],
9
- type: 'TEXT',
10
+ value: 'test-value',
11
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
10
12
  required: true,
11
13
  disabled: false,
12
- value: 'test-value',
13
- };
14
- const baseValidDto = {
15
- field: validField,
14
+ upgradable: false,
16
15
  };
17
16
  describe('AddonFieldDto Validator', () => {
18
17
  describe('Valid cases', () => {
@@ -21,19 +20,26 @@ describe('AddonFieldDto Validator', () => {
21
20
  });
22
21
  });
23
22
  describe('Missing required fields', () => {
24
- it('should return error when the nested `field` is missing', () => {
23
+ it('should return errors when all fields are missing', () => {
25
24
  const errors = (0, addon_field_validator_1.validateAddonFieldDto)({});
26
- expect(errors.some((e) => e.property === 'field')).toBe(true);
25
+ const requiredProps = [
26
+ 'id',
27
+ 'label',
28
+ 'value',
29
+ 'type',
30
+ 'required',
31
+ 'disabled',
32
+ ];
33
+ for (const prop of requiredProps) {
34
+ expect(errors.some((e) => e.property === prop)).toBe(true);
35
+ }
27
36
  });
28
37
  });
29
38
  describe('Invalid field values', () => {
30
- it('should surface errors from the nested field validator under `field`', () => {
31
- var _a;
32
- const errors = (0, addon_field_validator_1.validateAddonFieldDto)({
33
- field: { ...validField, type: 'NOT_REAL' },
34
- });
35
- const fieldErr = errors.find((e) => e.property === 'field');
36
- expect((_a = fieldErr === null || fieldErr === void 0 ? void 0 : fieldErr.children) === null || _a === void 0 ? void 0 : _a.some((c) => c.property === 'type')).toBe(true);
39
+ it('should return error for invalid type enum', () => {
40
+ const dto = { ...baseValidDto, type: 'not-a-valid-type' };
41
+ const errors = (0, addon_field_validator_1.validateAddonFieldDto)(dto);
42
+ expect(errors.some((e) => e.property === 'type')).toBe(true);
37
43
  });
38
44
  });
39
45
  });
@@ -2,10 +2,6 @@ import { ValidationError } from 'class-validator';
2
2
  /**
3
3
  * Validates an AttributeFieldDto object using class-validator decorators.
4
4
  *
5
- * The nested `field` (a discriminated `AnyFieldDto`) is validated separately
6
- * by dispatching to the matching concrete DTO's validator; its errors are
7
- * merged into the returned list under the `field` property.
8
- *
9
5
  * @param data The object to validate as an AttributeFieldDto.
10
6
  * @returns An array of validation errors, empty if validation succeeds.
11
7
  */
@@ -4,30 +4,14 @@ exports.validateAttributeFieldDto = validateAttributeFieldDto;
4
4
  const class_validator_1 = require("class-validator");
5
5
  const class_transformer_1 = require("class-transformer");
6
6
  const attribute_field_dto_1 = require("../dtos/attribute-field.dto");
7
- const any_field_validator_1 = require("./any-field-validator");
8
7
  /**
9
8
  * Validates an AttributeFieldDto object using class-validator decorators.
10
9
  *
11
- * The nested `field` (a discriminated `AnyFieldDto`) is validated separately
12
- * by dispatching to the matching concrete DTO's validator; its errors are
13
- * merged into the returned list under the `field` property.
14
- *
15
10
  * @param data The object to validate as an AttributeFieldDto.
16
11
  * @returns An array of validation errors, empty if validation succeeds.
17
12
  */
18
13
  function validateAttributeFieldDto(data) {
19
14
  const dto = (0, class_transformer_1.plainToInstance)(attribute_field_dto_1.AttributeFieldDto, data);
20
15
  const errors = (0, class_validator_1.validateSync)(dto);
21
- const field = data === null || data === void 0 ? void 0 : data.field;
22
- if (field && typeof field === 'object') {
23
- const fieldErrors = (0, any_field_validator_1.validateAnyFieldDto)(field);
24
- if (fieldErrors.length > 0) {
25
- const wrapped = new class_validator_1.ValidationError();
26
- wrapped.property = 'field';
27
- wrapped.value = field;
28
- wrapped.children = fieldErrors;
29
- errors.push(wrapped);
30
- }
31
- }
32
16
  return errors;
33
17
  }
@@ -2,21 +2,20 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("reflect-metadata");
4
4
  const attribute_field_validator_1 = require("./attribute-field-validator");
5
+ const field_type_enum_1 = require("../enums/field-type.enum");
5
6
  const language_enum_1 = require("../enums/language.enum");
6
- const validField = {
7
+ const baseValidDto = {
7
8
  id: 'attr-1',
8
9
  label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'CPU Cores' }],
9
- type: 'NUMBER',
10
+ value: '4',
11
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
10
12
  required: true,
11
13
  disabled: false,
12
- value: 4,
13
- };
14
- const baseValidDto = {
15
- field: validField,
14
+ upgradable: false,
16
15
  };
17
16
  describe('AttributeFieldDto Validator', () => {
18
17
  describe('Valid cases', () => {
19
- it('should return no errors for a valid DTO with only field', () => {
18
+ it('should return no errors for a valid DTO (inherited fields only)', () => {
20
19
  expect((0, attribute_field_validator_1.validateAttributeFieldDto)(baseValidDto)).toHaveLength(0);
21
20
  });
22
21
  it('should return no errors with optional visibleInOrder and visibleInClientPanel', () => {
@@ -36,12 +35,6 @@ describe('AttributeFieldDto Validator', () => {
36
35
  expect((0, attribute_field_validator_1.validateAttributeFieldDto)(dto)).toHaveLength(0);
37
36
  });
38
37
  });
39
- describe('Missing required fields', () => {
40
- it('should return error when the nested `field` is missing', () => {
41
- const errors = (0, attribute_field_validator_1.validateAttributeFieldDto)({});
42
- expect(errors.some((e) => e.property === 'field')).toBe(true);
43
- });
44
- });
45
38
  describe('AllOrNone constraint on repeatableMin/repeatableMax', () => {
46
39
  it('should return error when only repeatableMin is provided', () => {
47
40
  const dto = { ...baseValidDto, repeatableMin: 1 };
@@ -83,23 +76,20 @@ describe('AttributeFieldDto Validator', () => {
83
76
  expect(errors.some((e) => e.property === 'repeatableMax')).toBe(true);
84
77
  });
85
78
  });
86
- describe('Nested field validation', () => {
87
- it('should surface errors from the nested field validator under `field`', () => {
88
- var _a;
89
- const errors = (0, attribute_field_validator_1.validateAttributeFieldDto)({
90
- field: { ...validField, type: 'NUMBER', value: 'four' },
91
- });
92
- const fieldErr = errors.find((e) => e.property === 'field');
93
- expect(fieldErr).toBeDefined();
94
- expect((_a = fieldErr === null || fieldErr === void 0 ? void 0 : fieldErr.children) === null || _a === void 0 ? void 0 : _a.some((c) => c.property === 'value')).toBe(true);
95
- });
96
- it('should surface a type error when nested type literal is unknown', () => {
97
- var _a;
98
- const errors = (0, attribute_field_validator_1.validateAttributeFieldDto)({
99
- field: { ...validField, type: 'NOT_REAL' },
100
- });
101
- const fieldErr = errors.find((e) => e.property === 'field');
102
- expect((_a = fieldErr === null || fieldErr === void 0 ? void 0 : fieldErr.children) === null || _a === void 0 ? void 0 : _a.some((c) => c.property === 'type')).toBe(true);
79
+ describe('Inherited FieldDto validation', () => {
80
+ it('should return errors when inherited required fields are missing', () => {
81
+ const errors = (0, attribute_field_validator_1.validateAttributeFieldDto)({});
82
+ const requiredProps = [
83
+ 'id',
84
+ 'label',
85
+ 'value',
86
+ 'type',
87
+ 'required',
88
+ 'disabled',
89
+ ];
90
+ for (const prop of requiredProps) {
91
+ expect(errors.some((e) => e.property === prop)).toBe(true);
92
+ }
103
93
  });
104
94
  });
105
95
  });
@@ -1,6 +1,8 @@
1
1
  import { ValidationError } from 'class-validator';
2
2
  /**
3
- * @deprecated Use `validateAnyFieldDto` (or a concrete per-type validator like
4
- * `validateTextFieldDto`) instead. Kept for one release for backward compatibility.
3
+ * Validates a FieldDto object using class-validator decorators.
4
+ *
5
+ * @param data The object to validate as a FieldDto.
6
+ * @returns An array of validation errors, empty if validation succeeds.
5
7
  */
6
8
  export declare function validateFieldDto(data: object): ValidationError[];
@@ -1,11 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateFieldDto = validateFieldDto;
4
- const any_field_validator_1 = require("./any-field-validator");
4
+ const class_validator_1 = require("class-validator");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const field_dto_1 = require("../dtos/field.dto");
5
7
  /**
6
- * @deprecated Use `validateAnyFieldDto` (or a concrete per-type validator like
7
- * `validateTextFieldDto`) instead. Kept for one release for backward compatibility.
8
+ * Validates a FieldDto object using class-validator decorators.
9
+ *
10
+ * @param data The object to validate as a FieldDto.
11
+ * @returns An array of validation errors, empty if validation succeeds.
8
12
  */
9
13
  function validateFieldDto(data) {
10
- return (0, any_field_validator_1.validateAnyFieldDto)(data);
14
+ const dto = (0, class_transformer_1.plainToInstance)(field_dto_1.FieldDto, data);
15
+ const errors = (0, class_validator_1.validateSync)(dto);
16
+ return errors;
11
17
  }
@@ -2,36 +2,99 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("reflect-metadata");
4
4
  const field_validator_1 = require("./field-validator");
5
+ const field_type_enum_1 = require("../enums/field-type.enum");
5
6
  const language_enum_1 = require("../enums/language.enum");
6
7
  const baseValidDto = {
7
8
  id: 'test-id',
8
9
  label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Test Label' }],
9
- type: 'TEXT',
10
+ value: 'test-value',
11
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
10
12
  required: true,
11
13
  disabled: false,
14
+ upgradable: false,
12
15
  };
13
- describe('Deprecated validateFieldDto (dispatcher delegate)', () => {
16
+ describe('FieldDto Validator', () => {
14
17
  describe('Valid cases', () => {
15
- it('routes a TEXT payload', () => {
18
+ it('should return no errors for a valid DTO', () => {
16
19
  expect((0, field_validator_1.validateFieldDto)(baseValidDto)).toHaveLength(0);
17
20
  });
18
- it('routes a NUMBER payload', () => {
19
- expect((0, field_validator_1.validateFieldDto)({ ...baseValidDto, type: 'NUMBER', value: 1 })).toHaveLength(0);
20
- });
21
- });
22
- describe('Invalid field values', () => {
23
- it('returns a synthetic type error when discriminator is unknown', () => {
24
- const errors = (0, field_validator_1.validateFieldDto)({
21
+ it('should return no errors for a valid DTO with optional error messages', () => {
22
+ const dto = {
25
23
  ...baseValidDto,
26
- type: 'not-a-valid-type',
27
- });
28
- expect(errors.some((e) => e.property === 'type')).toBe(true);
24
+ regexValidationErrorMessage: [
25
+ { language: language_enum_1.LanguageEnum.ENGLISH, text: 'Invalid format' },
26
+ ],
27
+ remoteValidationErrorMessage: [
28
+ { language: language_enum_1.LanguageEnum.ENGLISH, text: 'Invalid value' },
29
+ ],
30
+ };
31
+ expect((0, field_validator_1.validateFieldDto)(dto)).toHaveLength(0);
29
32
  });
30
- it('returns errors for missing required base fields after routing', () => {
31
- const errors = (0, field_validator_1.validateFieldDto)({ type: 'TEXT' });
32
- for (const prop of ['id', 'label', 'required', 'disabled']) {
33
+ });
34
+ describe('Missing required fields', () => {
35
+ it('should return errors for all missing required fields (except upgradable)', () => {
36
+ const errors = (0, field_validator_1.validateFieldDto)({});
37
+ const requiredProps = [
38
+ 'id',
39
+ 'label',
40
+ 'value',
41
+ 'type',
42
+ 'required',
43
+ 'disabled',
44
+ ];
45
+ for (const prop of requiredProps) {
33
46
  expect(errors.some((e) => e.property === prop)).toBe(true);
34
47
  }
35
48
  });
49
+ it('should return error if value is missing', () => {
50
+ const dto = { ...baseValidDto };
51
+ delete dto.value;
52
+ const errors = (0, field_validator_1.validateFieldDto)(dto);
53
+ expect(errors.some((e) => e.property === 'value')).toBe(true);
54
+ });
55
+ });
56
+ describe('Invalid field values', () => {
57
+ it.each([
58
+ [{ ...baseValidDto, type: 'not-a-valid-type' }, 'type'],
59
+ [{}, 'id'],
60
+ [
61
+ {
62
+ ...baseValidDto,
63
+ regexValidation: 'regex',
64
+ regexValidationErrorMessage: 'not-an-array',
65
+ },
66
+ 'regexValidationErrorMessage',
67
+ ],
68
+ [
69
+ {
70
+ ...baseValidDto,
71
+ triggersRemoteValidation: true,
72
+ remoteValidationErrorMessage: 'not-an-array',
73
+ },
74
+ 'remoteValidationErrorMessage',
75
+ ],
76
+ ])('should return error for invalid %s', (dto, expectedProp) => {
77
+ const errors = (0, field_validator_1.validateFieldDto)(dto);
78
+ expect(errors.length).toBeGreaterThan(0);
79
+ expect(errors.some((e) => e.property === expectedProp)).toBe(true);
80
+ });
81
+ });
82
+ describe('Invalid `value` field', () => {
83
+ it.each([
84
+ [true, 'boolean'],
85
+ [null, 'null'],
86
+ [undefined, 'undefined'],
87
+ [{}, 'object'],
88
+ [[], 'array'],
89
+ ])('should return error if value is invalid type (%s)', (invalidValue, _label) => {
90
+ const dto = { ...baseValidDto, value: invalidValue };
91
+ const errors = (0, field_validator_1.validateFieldDto)(dto);
92
+ expect(errors.some((e) => e.property === 'value')).toBe(true);
93
+ });
94
+ it('should return error if value is empty string when required', () => {
95
+ const dto = { ...baseValidDto, value: '' };
96
+ const errors = (0, field_validator_1.validateFieldDto)(dto);
97
+ expect(errors.some((e) => e.property === 'value')).toBe(true);
98
+ });
36
99
  });
37
100
  });
@@ -1,24 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("reflect-metadata");
4
+ // import { ProductInfoDto } from '../dtos/product/product-info.dto';
4
5
  const item_actions_enum_1 = require("../enums/item-actions.enum");
5
6
  const language_enum_1 = require("../enums/language.enum");
7
+ const field_type_enum_1 = require("../enums/field-type.enum");
6
8
  const product_info_validator_1 = require("./product-info.validator");
7
9
  describe('ProductInfoDto Validator', () => {
8
- const validField = {
9
- field: {
10
- id: 'field',
11
- label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'label' }],
12
- type: 'TEXT',
13
- required: false,
14
- disabled: false,
15
- hidden: false,
16
- upgradable: false,
17
- value: 'string',
18
- },
10
+ const field = {
11
+ id: 'field',
12
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'label' }],
13
+ value: 'string',
14
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
15
+ required: false,
16
+ disabled: false,
17
+ hidden: false,
18
+ upgradable: false,
19
19
  };
20
20
  const invalidField = {
21
- // missing required field, so `field` is undefined
21
+ id: 'field',
22
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'label' }],
23
+ value: 'string',
24
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
25
+ disabled: false,
26
+ upgradable: false,
22
27
  };
23
28
  const testCases = [
24
29
  {
@@ -27,13 +32,13 @@ describe('ProductInfoDto Validator', () => {
27
32
  title: 'Test',
28
33
  supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
29
34
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
30
- productAttributes: [validField],
31
- itemAttributes: [validField],
35
+ productAttributes: [field],
36
+ itemAttributes: [field],
32
37
  },
33
38
  expectedErrorsLength: 0,
34
39
  },
35
40
  {
36
- description: 'should return error for missing field in attribute',
41
+ description: 'should return error for invalid required and hidden',
37
42
  dto: {
38
43
  title: 'Test',
39
44
  supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
@@ -48,8 +53,8 @@ describe('ProductInfoDto Validator', () => {
48
53
  title: '',
49
54
  supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
50
55
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
51
- productAttributes: [validField],
52
- itemAttributes: [validField],
56
+ productAttributes: [field],
57
+ itemAttributes: [field],
53
58
  },
54
59
  expectedErrorsLength: 1,
55
60
  },
@@ -59,8 +64,8 @@ describe('ProductInfoDto Validator', () => {
59
64
  title: 'Test',
60
65
  supportedActions: ['update'],
61
66
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
62
- productAttributes: [validField],
63
- itemAttributes: [validField],
67
+ productAttributes: [field],
68
+ itemAttributes: [field],
64
69
  },
65
70
  expectedErrorsLength: 1,
66
71
  },
@@ -70,8 +75,8 @@ describe('ProductInfoDto Validator', () => {
70
75
  title: 'Test',
71
76
  supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
72
77
  supportedLanguages: [],
73
- productAttributes: [validField],
74
- itemAttributes: [validField],
78
+ productAttributes: [field],
79
+ itemAttributes: [field],
75
80
  },
76
81
  expectedErrorsLength: 1,
77
82
  },
@@ -81,8 +86,8 @@ describe('ProductInfoDto Validator', () => {
81
86
  title: 'Test',
82
87
  supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
83
88
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
84
- productAttributes: [validField],
85
- itemAttributes: [validField],
89
+ productAttributes: [field],
90
+ itemAttributes: [field],
86
91
  adminPanel: {
87
92
  tabs: {
88
93
  product: [{ label: 'Product', url: 'https://example.com/product' }],
@@ -100,10 +105,14 @@ describe('ProductInfoDto Validator', () => {
100
105
  title: '',
101
106
  supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
102
107
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
103
- productAttributes: [validField],
104
- itemAttributes: [validField],
105
- adminPanel: {},
106
- clientPanel: {},
108
+ productAttributes: [field],
109
+ itemAttributes: [field],
110
+ adminPanel: {
111
+ /* invalid admin panel data */
112
+ },
113
+ clientPanel: {
114
+ /* invalid client panel data */
115
+ },
107
116
  },
108
117
  expectedErrorsLength: 3,
109
118
  },
@@ -113,8 +122,8 @@ describe('ProductInfoDto Validator', () => {
113
122
  title: 'Test',
114
123
  supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
115
124
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
116
- productAttributes: [validField],
117
- itemAttributes: [validField],
125
+ productAttributes: [field],
126
+ itemAttributes: [field],
118
127
  payPerUseUnits: [
119
128
  { id: 'ram', unitDescription: 'MB', intervalDescription: 'month' },
120
129
  ],
@@ -127,8 +136,8 @@ describe('ProductInfoDto Validator', () => {
127
136
  title: 'Test',
128
137
  supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
129
138
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
130
- productAttributes: [validField],
131
- itemAttributes: [validField],
139
+ productAttributes: [field],
140
+ itemAttributes: [field],
132
141
  payPerUseUnits: [
133
142
  { id: '', unitDescription: '', intervalDescription: '' },
134
143
  ],
@@ -142,10 +151,49 @@ describe('ProductInfoDto Validator', () => {
142
151
  expect(errors.length).toBe(expectedErrorsLength);
143
152
  });
144
153
  });
145
- describe('AttributeFieldDto class-level constraints inside ProductInfoDto', () => {
146
- it('fails when an AttributeFieldDto has only repeatableMin (AllOrNone)', () => {
154
+ const validationErrorTestCases = [
155
+ {
156
+ description: 'should return ValidationError for missing title',
157
+ dto: {
158
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
159
+ supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
160
+ productAttributes: [field],
161
+ itemAttributes: [field],
162
+ },
163
+ expectedErrors: ['title'],
164
+ },
165
+ {
166
+ description: 'should return ValidationError for unsupported action',
167
+ dto: {
168
+ title: 'Test',
169
+ supportedActions: ['update'],
170
+ supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
171
+ productAttributes: [field],
172
+ itemAttributes: [field],
173
+ },
174
+ expectedErrors: ['supportedActions'],
175
+ },
176
+ ];
177
+ validationErrorTestCases.forEach(({ description, dto, expectedErrors }) => {
178
+ it(description, async () => {
179
+ const errors = await (0, product_info_validator_1.validateProductInfoDto)(dto);
180
+ const errorProperties = errors.map((error) => error.property);
181
+ expectedErrors.forEach((expectedError) => {
182
+ expect(errorProperties).toContain(expectedError);
183
+ });
184
+ });
185
+ });
186
+ describe('FieldDto class-level constraints inside ProductInfoDto', () => {
187
+ it('fails when a FieldDto has only repeatableMin (AllOrNone)', () => {
147
188
  const fieldWithOnlyMin = {
148
- ...validField,
189
+ id: 'f1',
190
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'label' }],
191
+ value: 'v',
192
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
193
+ required: false,
194
+ disabled: false,
195
+ hidden: false,
196
+ upgradable: false,
149
197
  repeatableMin: 1,
150
198
  };
151
199
  const dto = {
@@ -157,9 +205,16 @@ describe('ProductInfoDto Validator', () => {
157
205
  const errors = (0, product_info_validator_1.validateProductInfoDto)(dto);
158
206
  expect(errors.length).toBeGreaterThan(0);
159
207
  });
160
- it('fails when an AttributeFieldDto has only repeatableMax (AllOrNone)', () => {
208
+ it('fails when a FieldDto has only repeatableMax (AllOrNone)', () => {
161
209
  const fieldWithOnlyMax = {
162
- ...validField,
210
+ id: 'f2',
211
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'label' }],
212
+ value: 'v',
213
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
214
+ required: false,
215
+ disabled: false,
216
+ upgradable: false,
217
+ hidden: false,
163
218
  repeatableMax: 5,
164
219
  };
165
220
  const dto = {
@@ -171,11 +226,15 @@ describe('ProductInfoDto Validator', () => {
171
226
  const errors = (0, product_info_validator_1.validateProductInfoDto)(dto);
172
227
  expect(errors.length).toBeGreaterThan(0);
173
228
  });
174
- it('passes when an AttributeFieldDto has both min and max with min <= max', () => {
229
+ it('passes when a FieldDto has both min and max with min <= max', () => {
175
230
  const fieldOk = {
176
- ...validField,
177
- repeatableMin: 1,
178
- repeatableMax: 3,
231
+ id: 'f3',
232
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'label' }],
233
+ value: 'v',
234
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
235
+ required: false,
236
+ disabled: false,
237
+ hidden: false,
179
238
  };
180
239
  const dto = {
181
240
  title: 'Test',
@@ -185,9 +244,16 @@ describe('ProductInfoDto Validator', () => {
185
244
  };
186
245
  expect((0, product_info_validator_1.validateProductInfoDto)(dto)).toHaveLength(0);
187
246
  });
188
- it('fails when an AttributeFieldDto has min > max (Min<=Max)', () => {
247
+ it('fails when a FieldDto has both min and max with min > max (Min<=Max)', () => {
189
248
  const fieldBad = {
190
- ...validField,
249
+ id: 'f4',
250
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'label' }],
251
+ value: 'v',
252
+ type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
253
+ required: false,
254
+ disabled: false,
255
+ hidden: false,
256
+ upgradable: false,
191
257
  repeatableMin: 5,
192
258
  repeatableMax: 2,
193
259
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hosterai/types",
3
- "version": "0.0.31",
3
+ "version": "0.0.32",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {