@hosterai/types 0.0.30 → 0.0.31

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 (155) hide show
  1. package/README.md +6 -1
  2. package/dist/decorators/is-e164-validator.spec.d.ts +1 -0
  3. package/dist/decorators/is-e164-validator.spec.js +64 -0
  4. package/dist/decorators/is-e164.validator.d.ts +2 -0
  5. package/dist/decorators/is-e164.validator.js +30 -0
  6. package/dist/decorators/unique-field-in-array-validator.spec.js +14 -0
  7. package/dist/decorators/unique-field-in-array.validator.js +18 -4
  8. package/dist/dtos/addon-field.dto.d.ts +6 -2
  9. package/dist/dtos/addon-field.dto.js +25 -2
  10. package/dist/dtos/attribute-field.dto.d.ts +18 -6
  11. package/dist/dtos/attribute-field.dto.js +18 -2
  12. package/dist/dtos/base-field.dto.d.ts +45 -0
  13. package/dist/dtos/base-field.dto.js +133 -0
  14. package/dist/dtos/field.dto.d.ts +5 -64
  15. package/dist/dtos/field.dto.js +0 -186
  16. package/dist/dtos/fields/any-field.dto.d.ts +38 -0
  17. package/dist/dtos/fields/any-field.dto.js +36 -0
  18. package/dist/dtos/fields/boolean-field.dto.d.ts +14 -0
  19. package/dist/dtos/fields/boolean-field.dto.js +48 -0
  20. package/dist/dtos/fields/countries-field.dto.d.ts +14 -0
  21. package/dist/dtos/fields/countries-field.dto.js +51 -0
  22. package/dist/dtos/fields/currency-field.dto.d.ts +14 -0
  23. package/dist/dtos/fields/currency-field.dto.js +50 -0
  24. package/dist/dtos/fields/date-field.dto.d.ts +14 -0
  25. package/dist/dtos/fields/date-field.dto.js +49 -0
  26. package/dist/dtos/fields/email-field.dto.d.ts +14 -0
  27. package/dist/dtos/fields/email-field.dto.js +49 -0
  28. package/dist/dtos/fields/multi-select-field.dto.d.ts +15 -0
  29. package/dist/dtos/fields/multi-select-field.dto.js +53 -0
  30. package/dist/dtos/fields/number-field.dto.d.ts +26 -0
  31. package/dist/dtos/fields/number-field.dto.js +82 -0
  32. package/dist/dtos/fields/password-field.dto.d.ts +21 -0
  33. package/dist/dtos/fields/password-field.dto.js +64 -0
  34. package/dist/dtos/fields/phone-field.dto.d.ts +14 -0
  35. package/dist/dtos/fields/phone-field.dto.js +50 -0
  36. package/dist/dtos/fields/select-field.dto.d.ts +15 -0
  37. package/dist/dtos/fields/select-field.dto.js +51 -0
  38. package/dist/dtos/fields/text-field.dto.d.ts +31 -0
  39. package/dist/dtos/fields/text-field.dto.js +102 -0
  40. package/dist/dtos/fields/textarea-field.dto.d.ts +31 -0
  41. package/dist/dtos/fields/textarea-field.dto.js +102 -0
  42. package/dist/dtos/fields/url-field.dto.d.ts +14 -0
  43. package/dist/dtos/fields/url-field.dto.js +49 -0
  44. package/dist/dtos/info/info-notification.dto.d.ts +5 -0
  45. package/dist/dtos/info/info-notification.dto.js +7 -0
  46. package/dist/dtos/info/info.dto.d.ts +196 -0
  47. package/dist/dtos/info/info.dto.js +278 -0
  48. package/dist/dtos/info.dto.d.ts +2 -2
  49. package/dist/dtos/info.dto.js +2 -5
  50. package/dist/dtos/notification/notification-request.dto.d.ts +20 -0
  51. package/dist/dtos/notification/notification-request.dto.js +31 -0
  52. package/dist/dtos/product/product-info.dto.js +2 -2
  53. package/dist/dtos/receiver/receiver-email.dto.d.ts +20 -0
  54. package/dist/dtos/receiver/receiver-email.dto.js +39 -0
  55. package/dist/dtos/receiver/receiver-push.dto.d.ts +15 -0
  56. package/dist/dtos/receiver/receiver-push.dto.js +31 -0
  57. package/dist/dtos/receiver/receiver-sms.dto.d.ts +11 -0
  58. package/dist/dtos/receiver/receiver-sms.dto.js +26 -0
  59. package/dist/dtos/request.dto.d.ts +20 -0
  60. package/dist/dtos/request.dto.js +31 -0
  61. package/dist/dtos/responses/validate-attributes-response.dto.d.ts +4 -4
  62. package/dist/dtos/responses/validate-attributes-response.dto.js +2 -6
  63. package/dist/dtos/sender/sender-email.dto.d.ts +25 -0
  64. package/dist/dtos/sender/sender-email.dto.js +46 -0
  65. package/dist/dtos/sender/sender-push.dto.d.ts +31 -0
  66. package/dist/dtos/sender/sender-push.dto.js +50 -0
  67. package/dist/dtos/sender/sender-sms.dto.d.ts +15 -0
  68. package/dist/dtos/sender/sender-sms.dto.js +30 -0
  69. package/dist/enums/field-type.enum.d.ts +20 -7
  70. package/dist/enums/field-type.enum.js +19 -7
  71. package/dist/enums/message-type.enum.d.ts +5 -0
  72. package/dist/enums/message-type.enum.js +9 -0
  73. package/dist/index.d.ts +29 -0
  74. package/dist/index.js +29 -0
  75. package/dist/openapi/schemas/components.schemas.d.ts +1168 -235
  76. package/dist/openapi/schemas/components.schemas.js +1869 -558
  77. package/dist/validators/addon-field-validator.d.ts +4 -1
  78. package/dist/validators/addon-field-validator.js +22 -3
  79. package/dist/validators/addon-field-validator.spec.js +15 -21
  80. package/dist/validators/any-field-validator.d.ts +10 -0
  81. package/dist/validators/any-field-validator.js +28 -0
  82. package/dist/validators/any-field-validator.spec.d.ts +1 -0
  83. package/dist/validators/any-field-validator.spec.js +37 -0
  84. package/dist/validators/attribute-field-validator.d.ts +4 -0
  85. package/dist/validators/attribute-field-validator.js +16 -0
  86. package/dist/validators/attribute-field-validator.spec.js +30 -20
  87. package/dist/validators/field-validator.d.ts +2 -4
  88. package/dist/validators/field-validator.js +4 -10
  89. package/dist/validators/field-validator.spec.js +16 -79
  90. package/dist/validators/fields/boolean-field-validator.d.ts +8 -0
  91. package/dist/validators/fields/boolean-field-validator.js +15 -0
  92. package/dist/validators/fields/boolean-field-validator.spec.d.ts +1 -0
  93. package/dist/validators/fields/boolean-field-validator.spec.js +43 -0
  94. package/dist/validators/fields/countries-field-validator.d.ts +8 -0
  95. package/dist/validators/fields/countries-field-validator.js +15 -0
  96. package/dist/validators/fields/countries-field-validator.spec.d.ts +1 -0
  97. package/dist/validators/fields/countries-field-validator.spec.js +44 -0
  98. package/dist/validators/fields/currency-field-validator.d.ts +8 -0
  99. package/dist/validators/fields/currency-field-validator.js +15 -0
  100. package/dist/validators/fields/currency-field-validator.spec.d.ts +1 -0
  101. package/dist/validators/fields/currency-field-validator.spec.js +41 -0
  102. package/dist/validators/fields/date-field-validator.d.ts +8 -0
  103. package/dist/validators/fields/date-field-validator.js +15 -0
  104. package/dist/validators/fields/date-field-validator.spec.d.ts +1 -0
  105. package/dist/validators/fields/date-field-validator.spec.js +43 -0
  106. package/dist/validators/fields/email-field-validator.d.ts +8 -0
  107. package/dist/validators/fields/email-field-validator.js +15 -0
  108. package/dist/validators/fields/email-field-validator.spec.d.ts +1 -0
  109. package/dist/validators/fields/email-field-validator.spec.js +43 -0
  110. package/dist/validators/fields/multi-select-field-validator.d.ts +8 -0
  111. package/dist/validators/fields/multi-select-field-validator.js +15 -0
  112. package/dist/validators/fields/multi-select-field-validator.spec.d.ts +1 -0
  113. package/dist/validators/fields/multi-select-field-validator.spec.js +52 -0
  114. package/dist/validators/fields/number-field-validator.d.ts +8 -0
  115. package/dist/validators/fields/number-field-validator.js +15 -0
  116. package/dist/validators/fields/number-field-validator.spec.d.ts +1 -0
  117. package/dist/validators/fields/number-field-validator.spec.js +59 -0
  118. package/dist/validators/fields/password-field-validator.d.ts +8 -0
  119. package/dist/validators/fields/password-field-validator.js +15 -0
  120. package/dist/validators/fields/password-field-validator.spec.d.ts +1 -0
  121. package/dist/validators/fields/password-field-validator.spec.js +44 -0
  122. package/dist/validators/fields/phone-field-validator.d.ts +8 -0
  123. package/dist/validators/fields/phone-field-validator.js +15 -0
  124. package/dist/validators/fields/phone-field-validator.spec.d.ts +1 -0
  125. package/dist/validators/fields/phone-field-validator.spec.js +41 -0
  126. package/dist/validators/fields/select-field-validator.d.ts +8 -0
  127. package/dist/validators/fields/select-field-validator.js +15 -0
  128. package/dist/validators/fields/select-field-validator.spec.d.ts +1 -0
  129. package/dist/validators/fields/select-field-validator.spec.js +46 -0
  130. package/dist/validators/fields/text-field-validator.d.ts +8 -0
  131. package/dist/validators/fields/text-field-validator.js +15 -0
  132. package/dist/validators/fields/text-field-validator.spec.d.ts +1 -0
  133. package/dist/validators/fields/text-field-validator.spec.js +60 -0
  134. package/dist/validators/fields/textarea-field-validator.d.ts +8 -0
  135. package/dist/validators/fields/textarea-field-validator.js +15 -0
  136. package/dist/validators/fields/textarea-field-validator.spec.d.ts +1 -0
  137. package/dist/validators/fields/textarea-field-validator.spec.js +52 -0
  138. package/dist/validators/fields/url-field-validator.d.ts +8 -0
  139. package/dist/validators/fields/url-field-validator.js +15 -0
  140. package/dist/validators/fields/url-field-validator.spec.d.ts +1 -0
  141. package/dist/validators/fields/url-field-validator.spec.js +43 -0
  142. package/dist/validators/product-info-validator.spec.js +42 -108
  143. package/package.json +1 -1
  144. package/dist/dtos/product/requests/product-downgradeable-request.dto.d.ts +0 -18
  145. package/dist/dtos/product/requests/product-downgradeable-request.dto.js +0 -37
  146. package/dist/dtos/product/requests/product-upgradeable-request.dto.d.ts +0 -18
  147. package/dist/dtos/product/requests/product-upgradeable-request.dto.js +0 -37
  148. package/dist/dtos/product/responses/product-downgradeable-response.dto.d.ts +0 -22
  149. package/dist/dtos/product/responses/product-downgradeable-response.dto.js +0 -11
  150. package/dist/dtos/product/responses/product-upgradeable-response.dto.d.ts +0 -22
  151. package/dist/dtos/product/responses/product-upgradeable-response.dto.js +0 -11
  152. package/dist/validators/product-downgradeable-request-validator.d.ts +0 -8
  153. package/dist/validators/product-downgradeable-request-validator.js +0 -17
  154. package/dist/validators/product-upgradeable-request-validator.d.ts +0 -8
  155. package/dist/validators/product-upgradeable-request-validator.js +0 -17
@@ -1,7 +1,10 @@
1
1
  import { ValidationError } from 'class-validator';
2
2
  /**
3
3
  * Validates an AddonFieldDto object.
4
- * Since AddonFieldDto is an empty subclass of FieldDto, this delegates to validateFieldDto.
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.
5
8
  *
6
9
  * @param data The object to validate as an AddonFieldDto.
7
10
  * @returns An array of validation errors, empty if validation succeeds.
@@ -1,14 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateAddonFieldDto = validateAddonFieldDto;
4
- const field_validator_1 = require("./field-validator");
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");
5
8
  /**
6
9
  * Validates an AddonFieldDto object.
7
- * Since AddonFieldDto is an empty subclass of FieldDto, this delegates to validateFieldDto.
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.
8
14
  *
9
15
  * @param data The object to validate as an AddonFieldDto.
10
16
  * @returns An array of validation errors, empty if validation succeeds.
11
17
  */
12
18
  function validateAddonFieldDto(data) {
13
- return (0, field_validator_1.validateFieldDto)(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;
14
33
  }
@@ -2,16 +2,17 @@
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");
6
5
  const language_enum_1 = require("../enums/language.enum");
7
- const baseValidDto = {
6
+ const validField = {
8
7
  id: 'addon-1',
9
8
  label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Addon Field' }],
10
- value: 'test-value',
11
- type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
9
+ type: 'TEXT',
12
10
  required: true,
13
11
  disabled: false,
14
- upgradable: false,
12
+ value: 'test-value',
13
+ };
14
+ const baseValidDto = {
15
+ field: validField,
15
16
  };
16
17
  describe('AddonFieldDto Validator', () => {
17
18
  describe('Valid cases', () => {
@@ -20,26 +21,19 @@ describe('AddonFieldDto Validator', () => {
20
21
  });
21
22
  });
22
23
  describe('Missing required fields', () => {
23
- it('should return errors when all fields are missing', () => {
24
+ it('should return error when the nested `field` is missing', () => {
24
25
  const errors = (0, addon_field_validator_1.validateAddonFieldDto)({});
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
- }
26
+ expect(errors.some((e) => e.property === 'field')).toBe(true);
36
27
  });
37
28
  });
38
29
  describe('Invalid field values', () => {
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);
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);
43
37
  });
44
38
  });
45
39
  });
@@ -0,0 +1,10 @@
1
+ import { ValidationError } from 'class-validator';
2
+ /**
3
+ * Validates any field DTO by reading the string-literal `type` discriminator and
4
+ * routing to the matching concrete DTO's validation.
5
+ *
6
+ * @param data Object with a string `type` discriminator.
7
+ * @returns ValidationError[] from the concrete DTO, or a synthetic error if
8
+ * `type` is missing or not a recognized literal.
9
+ */
10
+ export declare function validateAnyFieldDto(data: object): ValidationError[];
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateAnyFieldDto = validateAnyFieldDto;
4
+ const class_validator_1 = require("class-validator");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const any_field_dto_1 = require("../dtos/fields/any-field.dto");
7
+ /**
8
+ * Validates any field DTO by reading the string-literal `type` discriminator and
9
+ * routing to the matching concrete DTO's validation.
10
+ *
11
+ * @param data Object with a string `type` discriminator.
12
+ * @returns ValidationError[] from the concrete DTO, or a synthetic error if
13
+ * `type` is missing or not a recognized literal.
14
+ */
15
+ function validateAnyFieldDto(data) {
16
+ const type = data === null || data === void 0 ? void 0 : data.type;
17
+ if (typeof type !== 'string' || !(type in any_field_dto_1.FIELD_DTO_CLASSES)) {
18
+ const err = new class_validator_1.ValidationError();
19
+ err.property = 'type';
20
+ err.value = type;
21
+ err.constraints = {
22
+ isFieldType: `type must be one of: ${Object.keys(any_field_dto_1.FIELD_DTO_CLASSES).join(', ')}`,
23
+ };
24
+ return [err];
25
+ }
26
+ const Cls = any_field_dto_1.FIELD_DTO_CLASSES[type];
27
+ return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(Cls, data));
28
+ }
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const any_field_validator_1 = require("./any-field-validator");
5
+ const language_enum_1 = require("../enums/language.enum");
6
+ const minimalBase = (type) => ({
7
+ id: 'x',
8
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'X' }],
9
+ type,
10
+ required: true,
11
+ disabled: false,
12
+ });
13
+ describe('AnyField dispatcher', () => {
14
+ it('routes a TEXT payload to TextFieldDto validation', () => {
15
+ expect((0, any_field_validator_1.validateAnyFieldDto)(minimalBase('TEXT'))).toHaveLength(0);
16
+ });
17
+ it('routes a NUMBER payload to NumberFieldDto validation', () => {
18
+ expect((0, any_field_validator_1.validateAnyFieldDto)(minimalBase('NUMBER'))).toHaveLength(0);
19
+ });
20
+ it('returns a synthetic type error when discriminator is missing', () => {
21
+ const errors = (0, any_field_validator_1.validateAnyFieldDto)({ id: 'x' });
22
+ expect(errors.some((e) => e.property === 'type')).toBe(true);
23
+ });
24
+ it('returns a synthetic type error when discriminator is unknown', () => {
25
+ const errors = (0, any_field_validator_1.validateAnyFieldDto)({
26
+ ...minimalBase('NOT_REAL'),
27
+ });
28
+ expect(errors.some((e) => e.property === 'type')).toBe(true);
29
+ });
30
+ it('propagates type-specific validation errors from the concrete DTO', () => {
31
+ const errors = (0, any_field_validator_1.validateAnyFieldDto)({
32
+ ...minimalBase('PHONE'),
33
+ value: 'not-a-phone',
34
+ });
35
+ expect(errors.some((e) => e.property === 'value')).toBe(true);
36
+ });
37
+ });
@@ -2,6 +2,10 @@ 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
+ *
5
9
  * @param data The object to validate as an AttributeFieldDto.
6
10
  * @returns An array of validation errors, empty if validation succeeds.
7
11
  */
@@ -4,14 +4,30 @@ 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");
7
8
  /**
8
9
  * Validates an AttributeFieldDto object using class-validator decorators.
9
10
  *
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
+ *
10
15
  * @param data The object to validate as an AttributeFieldDto.
11
16
  * @returns An array of validation errors, empty if validation succeeds.
12
17
  */
13
18
  function validateAttributeFieldDto(data) {
14
19
  const dto = (0, class_transformer_1.plainToInstance)(attribute_field_dto_1.AttributeFieldDto, data);
15
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
+ }
16
32
  return errors;
17
33
  }
@@ -2,20 +2,21 @@
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");
6
5
  const language_enum_1 = require("../enums/language.enum");
7
- const baseValidDto = {
6
+ const validField = {
8
7
  id: 'attr-1',
9
8
  label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'CPU Cores' }],
10
- value: '4',
11
- type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
9
+ type: 'NUMBER',
12
10
  required: true,
13
11
  disabled: false,
14
- upgradable: false,
12
+ value: 4,
13
+ };
14
+ const baseValidDto = {
15
+ field: validField,
15
16
  };
16
17
  describe('AttributeFieldDto Validator', () => {
17
18
  describe('Valid cases', () => {
18
- it('should return no errors for a valid DTO (inherited fields only)', () => {
19
+ it('should return no errors for a valid DTO with only field', () => {
19
20
  expect((0, attribute_field_validator_1.validateAttributeFieldDto)(baseValidDto)).toHaveLength(0);
20
21
  });
21
22
  it('should return no errors with optional visibleInOrder and visibleInClientPanel', () => {
@@ -35,6 +36,12 @@ describe('AttributeFieldDto Validator', () => {
35
36
  expect((0, attribute_field_validator_1.validateAttributeFieldDto)(dto)).toHaveLength(0);
36
37
  });
37
38
  });
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
+ });
38
45
  describe('AllOrNone constraint on repeatableMin/repeatableMax', () => {
39
46
  it('should return error when only repeatableMin is provided', () => {
40
47
  const dto = { ...baseValidDto, repeatableMin: 1 };
@@ -76,20 +83,23 @@ describe('AttributeFieldDto Validator', () => {
76
83
  expect(errors.some((e) => e.property === 'repeatableMax')).toBe(true);
77
84
  });
78
85
  });
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
- }
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);
93
103
  });
94
104
  });
95
105
  });
@@ -1,8 +1,6 @@
1
1
  import { ValidationError } from 'class-validator';
2
2
  /**
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.
3
+ * @deprecated Use `validateAnyFieldDto` (or a concrete per-type validator like
4
+ * `validateTextFieldDto`) instead. Kept for one release for backward compatibility.
7
5
  */
8
6
  export declare function validateFieldDto(data: object): ValidationError[];
@@ -1,17 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateFieldDto = validateFieldDto;
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");
4
+ const any_field_validator_1 = require("./any-field-validator");
7
5
  /**
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.
6
+ * @deprecated Use `validateAnyFieldDto` (or a concrete per-type validator like
7
+ * `validateTextFieldDto`) instead. Kept for one release for backward compatibility.
12
8
  */
13
9
  function validateFieldDto(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;
10
+ return (0, any_field_validator_1.validateAnyFieldDto)(data);
17
11
  }
@@ -2,99 +2,36 @@
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");
6
5
  const language_enum_1 = require("../enums/language.enum");
7
6
  const baseValidDto = {
8
7
  id: 'test-id',
9
8
  label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Test Label' }],
10
- value: 'test-value',
11
- type: field_type_enum_1.FieldTypeEnum.TEXT_BOX,
9
+ type: 'TEXT',
12
10
  required: true,
13
11
  disabled: false,
14
- upgradable: false,
15
12
  };
16
- describe('FieldDto Validator', () => {
13
+ describe('Deprecated validateFieldDto (dispatcher delegate)', () => {
17
14
  describe('Valid cases', () => {
18
- it('should return no errors for a valid DTO', () => {
15
+ it('routes a TEXT payload', () => {
19
16
  expect((0, field_validator_1.validateFieldDto)(baseValidDto)).toHaveLength(0);
20
17
  });
21
- it('should return no errors for a valid DTO with optional error messages', () => {
22
- const dto = {
23
- ...baseValidDto,
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);
32
- });
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) {
46
- expect(errors.some((e) => e.property === prop)).toBe(true);
47
- }
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);
18
+ it('routes a NUMBER payload', () => {
19
+ expect((0, field_validator_1.validateFieldDto)({ ...baseValidDto, type: 'NUMBER', value: 1 })).toHaveLength(0);
54
20
  });
55
21
  });
56
22
  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);
23
+ it('returns a synthetic type error when discriminator is unknown', () => {
24
+ const errors = (0, field_validator_1.validateFieldDto)({
25
+ ...baseValidDto,
26
+ type: 'not-a-valid-type',
27
+ });
28
+ expect(errors.some((e) => e.property === 'type')).toBe(true);
93
29
  });
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);
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
+ expect(errors.some((e) => e.property === prop)).toBe(true);
34
+ }
98
35
  });
99
36
  });
100
37
  });
@@ -0,0 +1,8 @@
1
+ import { ValidationError } from 'class-validator';
2
+ /**
3
+ * Validates a BooleanFieldDto object using class-validator decorators.
4
+ *
5
+ * @param data The object to validate as a BooleanFieldDto.
6
+ * @returns An array of validation errors, empty if validation succeeds.
7
+ */
8
+ export declare function validateBooleanFieldDto(data: object): ValidationError[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateBooleanFieldDto = validateBooleanFieldDto;
4
+ const class_validator_1 = require("class-validator");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const boolean_field_dto_1 = require("../../dtos/fields/boolean-field.dto");
7
+ /**
8
+ * Validates a BooleanFieldDto object using class-validator decorators.
9
+ *
10
+ * @param data The object to validate as a BooleanFieldDto.
11
+ * @returns An array of validation errors, empty if validation succeeds.
12
+ */
13
+ function validateBooleanFieldDto(data) {
14
+ return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(boolean_field_dto_1.BooleanFieldDto, data));
15
+ }
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const boolean_field_validator_1 = require("./boolean-field-validator");
5
+ const language_enum_1 = require("../../enums/language.enum");
6
+ const baseValidDto = {
7
+ id: 'bool-1',
8
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Accept Terms' }],
9
+ type: 'BOOLEAN',
10
+ required: true,
11
+ disabled: false,
12
+ };
13
+ describe('BooleanFieldDto Validator', () => {
14
+ describe('Valid cases', () => {
15
+ it('should return no errors for a valid DTO', () => {
16
+ expect((0, boolean_field_validator_1.validateBooleanFieldDto)(baseValidDto)).toHaveLength(0);
17
+ });
18
+ it('should return no errors with a boolean value', () => {
19
+ expect((0, boolean_field_validator_1.validateBooleanFieldDto)({ ...baseValidDto, value: true })).toHaveLength(0);
20
+ });
21
+ });
22
+ describe('Missing required fields', () => {
23
+ it('should return errors for all missing required fields', () => {
24
+ const errors = (0, boolean_field_validator_1.validateBooleanFieldDto)({});
25
+ for (const prop of ['id', 'label', 'required', 'disabled']) {
26
+ expect(errors.some((e) => e.property === prop)).toBe(true);
27
+ }
28
+ });
29
+ });
30
+ describe('Invalid field values', () => {
31
+ it('should return error for wrong type literal', () => {
32
+ const errors = (0, boolean_field_validator_1.validateBooleanFieldDto)({ ...baseValidDto, type: 'TEXT' });
33
+ expect(errors.some((e) => e.property === 'type')).toBe(true);
34
+ });
35
+ it('should return error for non-boolean value', () => {
36
+ const errors = (0, boolean_field_validator_1.validateBooleanFieldDto)({
37
+ ...baseValidDto,
38
+ value: 'true',
39
+ });
40
+ expect(errors.some((e) => e.property === 'value')).toBe(true);
41
+ });
42
+ });
43
+ });
@@ -0,0 +1,8 @@
1
+ import { ValidationError } from 'class-validator';
2
+ /**
3
+ * Validates a CountriesFieldDto object using class-validator decorators.
4
+ *
5
+ * @param data The object to validate as a CountriesFieldDto.
6
+ * @returns An array of validation errors, empty if validation succeeds.
7
+ */
8
+ export declare function validateCountriesFieldDto(data: object): ValidationError[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateCountriesFieldDto = validateCountriesFieldDto;
4
+ const class_validator_1 = require("class-validator");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const countries_field_dto_1 = require("../../dtos/fields/countries-field.dto");
7
+ /**
8
+ * Validates a CountriesFieldDto object using class-validator decorators.
9
+ *
10
+ * @param data The object to validate as a CountriesFieldDto.
11
+ * @returns An array of validation errors, empty if validation succeeds.
12
+ */
13
+ function validateCountriesFieldDto(data) {
14
+ return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(countries_field_dto_1.CountriesFieldDto, data));
15
+ }
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const countries_field_validator_1 = require("./countries-field-validator");
5
+ const language_enum_1 = require("../../enums/language.enum");
6
+ const country_enum_1 = require("../../enums/country.enum");
7
+ const baseValidDto = {
8
+ id: 'countries-1',
9
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Countries' }],
10
+ type: 'COUNTRIES',
11
+ required: true,
12
+ disabled: false,
13
+ };
14
+ describe('CountriesFieldDto Validator', () => {
15
+ describe('Valid cases', () => {
16
+ it('should return no errors for a valid minimal DTO', () => {
17
+ expect((0, countries_field_validator_1.validateCountriesFieldDto)(baseValidDto)).toHaveLength(0);
18
+ });
19
+ it('should return no errors with a valid value array', () => {
20
+ expect((0, countries_field_validator_1.validateCountriesFieldDto)({
21
+ ...baseValidDto,
22
+ value: [country_enum_1.CountryEnum.GREECE, country_enum_1.CountryEnum.UNITED_STATES],
23
+ })).toHaveLength(0);
24
+ });
25
+ });
26
+ describe('Missing required fields', () => {
27
+ it('should return errors for all missing required fields', () => {
28
+ const errors = (0, countries_field_validator_1.validateCountriesFieldDto)({});
29
+ for (const prop of ['id', 'label', 'required', 'disabled']) {
30
+ expect(errors.some((e) => e.property === prop)).toBe(true);
31
+ }
32
+ });
33
+ });
34
+ describe('Invalid field values', () => {
35
+ it.each([
36
+ [{ ...baseValidDto, type: 'TEXT' }, 'type'],
37
+ [{ ...baseValidDto, value: 'GR' }, 'value'],
38
+ [{ ...baseValidDto, value: ['NOT_A_COUNTRY'] }, 'value'],
39
+ ])('should return error for invalid %#', (dto, expectedProp) => {
40
+ const errors = (0, countries_field_validator_1.validateCountriesFieldDto)(dto);
41
+ expect(errors.some((e) => e.property === expectedProp)).toBe(true);
42
+ });
43
+ });
44
+ });
@@ -0,0 +1,8 @@
1
+ import { ValidationError } from 'class-validator';
2
+ /**
3
+ * Validates a CurrencyFieldDto object using class-validator decorators.
4
+ *
5
+ * @param data The object to validate as a CurrencyFieldDto.
6
+ * @returns An array of validation errors, empty if validation succeeds.
7
+ */
8
+ export declare function validateCurrencyFieldDto(data: object): ValidationError[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateCurrencyFieldDto = validateCurrencyFieldDto;
4
+ const class_validator_1 = require("class-validator");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const currency_field_dto_1 = require("../../dtos/fields/currency-field.dto");
7
+ /**
8
+ * Validates a CurrencyFieldDto object using class-validator decorators.
9
+ *
10
+ * @param data The object to validate as a CurrencyFieldDto.
11
+ * @returns An array of validation errors, empty if validation succeeds.
12
+ */
13
+ function validateCurrencyFieldDto(data) {
14
+ return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(currency_field_dto_1.CurrencyFieldDto, data));
15
+ }
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';