@hosterai/types 0.0.29 → 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 (164) 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/invoice/requests/base-invoice-request.dto.d.ts +1 -1
  51. package/dist/dtos/invoice/requests/base-invoice-request.dto.js +1 -1
  52. package/dist/dtos/notification/notification-request.dto.d.ts +20 -0
  53. package/dist/dtos/notification/notification-request.dto.js +31 -0
  54. package/dist/dtos/product/product-info.dto.d.ts +2 -2
  55. package/dist/dtos/product/product-info.dto.js +4 -4
  56. package/dist/dtos/product/product-item-data.dto.d.ts +2 -2
  57. package/dist/dtos/product/product-item-data.dto.js +2 -2
  58. package/dist/dtos/receiver/receiver-email.dto.d.ts +20 -0
  59. package/dist/dtos/receiver/receiver-email.dto.js +39 -0
  60. package/dist/dtos/receiver/receiver-push.dto.d.ts +15 -0
  61. package/dist/dtos/receiver/receiver-push.dto.js +31 -0
  62. package/dist/dtos/receiver/receiver-sms.dto.d.ts +11 -0
  63. package/dist/dtos/receiver/receiver-sms.dto.js +26 -0
  64. package/dist/dtos/request.dto.d.ts +20 -0
  65. package/dist/dtos/request.dto.js +31 -0
  66. package/dist/dtos/responses/validate-attributes-response.dto.d.ts +4 -4
  67. package/dist/dtos/responses/validate-attributes-response.dto.js +2 -6
  68. package/dist/dtos/sender/sender-email.dto.d.ts +25 -0
  69. package/dist/dtos/sender/sender-email.dto.js +46 -0
  70. package/dist/dtos/sender/sender-push.dto.d.ts +31 -0
  71. package/dist/dtos/sender/sender-push.dto.js +50 -0
  72. package/dist/dtos/sender/sender-sms.dto.d.ts +15 -0
  73. package/dist/dtos/sender/sender-sms.dto.js +30 -0
  74. package/dist/enums/field-type.enum.d.ts +20 -7
  75. package/dist/enums/field-type.enum.js +19 -7
  76. package/dist/enums/item-actions.enum.d.ts +10 -10
  77. package/dist/enums/item-actions.enum.js +13 -14
  78. package/dist/enums/message-type.enum.d.ts +5 -0
  79. package/dist/enums/message-type.enum.js +9 -0
  80. package/dist/index.d.ts +29 -0
  81. package/dist/index.js +29 -0
  82. package/dist/openapi/schemas/components.schemas.d.ts +1169 -236
  83. package/dist/openapi/schemas/components.schemas.js +1878 -567
  84. package/dist/validators/addon-field-validator.d.ts +4 -1
  85. package/dist/validators/addon-field-validator.js +22 -3
  86. package/dist/validators/addon-field-validator.spec.js +15 -21
  87. package/dist/validators/any-field-validator.d.ts +10 -0
  88. package/dist/validators/any-field-validator.js +28 -0
  89. package/dist/validators/any-field-validator.spec.d.ts +1 -0
  90. package/dist/validators/any-field-validator.spec.js +37 -0
  91. package/dist/validators/attribute-field-validator.d.ts +4 -0
  92. package/dist/validators/attribute-field-validator.js +16 -0
  93. package/dist/validators/attribute-field-validator.spec.js +30 -20
  94. package/dist/validators/field-validator.d.ts +2 -4
  95. package/dist/validators/field-validator.js +4 -10
  96. package/dist/validators/field-validator.spec.js +16 -79
  97. package/dist/validators/fields/boolean-field-validator.d.ts +8 -0
  98. package/dist/validators/fields/boolean-field-validator.js +15 -0
  99. package/dist/validators/fields/boolean-field-validator.spec.d.ts +1 -0
  100. package/dist/validators/fields/boolean-field-validator.spec.js +43 -0
  101. package/dist/validators/fields/countries-field-validator.d.ts +8 -0
  102. package/dist/validators/fields/countries-field-validator.js +15 -0
  103. package/dist/validators/fields/countries-field-validator.spec.d.ts +1 -0
  104. package/dist/validators/fields/countries-field-validator.spec.js +44 -0
  105. package/dist/validators/fields/currency-field-validator.d.ts +8 -0
  106. package/dist/validators/fields/currency-field-validator.js +15 -0
  107. package/dist/validators/fields/currency-field-validator.spec.d.ts +1 -0
  108. package/dist/validators/fields/currency-field-validator.spec.js +41 -0
  109. package/dist/validators/fields/date-field-validator.d.ts +8 -0
  110. package/dist/validators/fields/date-field-validator.js +15 -0
  111. package/dist/validators/fields/date-field-validator.spec.d.ts +1 -0
  112. package/dist/validators/fields/date-field-validator.spec.js +43 -0
  113. package/dist/validators/fields/email-field-validator.d.ts +8 -0
  114. package/dist/validators/fields/email-field-validator.js +15 -0
  115. package/dist/validators/fields/email-field-validator.spec.d.ts +1 -0
  116. package/dist/validators/fields/email-field-validator.spec.js +43 -0
  117. package/dist/validators/fields/multi-select-field-validator.d.ts +8 -0
  118. package/dist/validators/fields/multi-select-field-validator.js +15 -0
  119. package/dist/validators/fields/multi-select-field-validator.spec.d.ts +1 -0
  120. package/dist/validators/fields/multi-select-field-validator.spec.js +52 -0
  121. package/dist/validators/fields/number-field-validator.d.ts +8 -0
  122. package/dist/validators/fields/number-field-validator.js +15 -0
  123. package/dist/validators/fields/number-field-validator.spec.d.ts +1 -0
  124. package/dist/validators/fields/number-field-validator.spec.js +59 -0
  125. package/dist/validators/fields/password-field-validator.d.ts +8 -0
  126. package/dist/validators/fields/password-field-validator.js +15 -0
  127. package/dist/validators/fields/password-field-validator.spec.d.ts +1 -0
  128. package/dist/validators/fields/password-field-validator.spec.js +44 -0
  129. package/dist/validators/fields/phone-field-validator.d.ts +8 -0
  130. package/dist/validators/fields/phone-field-validator.js +15 -0
  131. package/dist/validators/fields/phone-field-validator.spec.d.ts +1 -0
  132. package/dist/validators/fields/phone-field-validator.spec.js +41 -0
  133. package/dist/validators/fields/select-field-validator.d.ts +8 -0
  134. package/dist/validators/fields/select-field-validator.js +15 -0
  135. package/dist/validators/fields/select-field-validator.spec.d.ts +1 -0
  136. package/dist/validators/fields/select-field-validator.spec.js +46 -0
  137. package/dist/validators/fields/text-field-validator.d.ts +8 -0
  138. package/dist/validators/fields/text-field-validator.js +15 -0
  139. package/dist/validators/fields/text-field-validator.spec.d.ts +1 -0
  140. package/dist/validators/fields/text-field-validator.spec.js +60 -0
  141. package/dist/validators/fields/textarea-field-validator.d.ts +8 -0
  142. package/dist/validators/fields/textarea-field-validator.js +15 -0
  143. package/dist/validators/fields/textarea-field-validator.spec.d.ts +1 -0
  144. package/dist/validators/fields/textarea-field-validator.spec.js +52 -0
  145. package/dist/validators/fields/url-field-validator.d.ts +8 -0
  146. package/dist/validators/fields/url-field-validator.js +15 -0
  147. package/dist/validators/fields/url-field-validator.spec.d.ts +1 -0
  148. package/dist/validators/fields/url-field-validator.spec.js +43 -0
  149. package/dist/validators/notification-info-validator.spec.js +5 -5
  150. package/dist/validators/product-info-validator.spec.js +54 -120
  151. package/dist/validators/product-item-data-validator.spec.js +3 -3
  152. package/package.json +1 -1
  153. package/dist/dtos/product/requests/product-downgradeable-request.dto.d.ts +0 -18
  154. package/dist/dtos/product/requests/product-downgradeable-request.dto.js +0 -37
  155. package/dist/dtos/product/requests/product-upgradeable-request.dto.d.ts +0 -18
  156. package/dist/dtos/product/requests/product-upgradeable-request.dto.js +0 -37
  157. package/dist/dtos/product/responses/product-downgradeable-response.dto.d.ts +0 -22
  158. package/dist/dtos/product/responses/product-downgradeable-response.dto.js +0 -11
  159. package/dist/dtos/product/responses/product-upgradeable-response.dto.d.ts +0 -22
  160. package/dist/dtos/product/responses/product-upgradeable-response.dto.js +0 -11
  161. package/dist/validators/product-downgradeable-request-validator.d.ts +0 -8
  162. package/dist/validators/product-downgradeable-request-validator.js +0 -17
  163. package/dist/validators/product-upgradeable-request-validator.d.ts +0 -8
  164. package/dist/validators/product-upgradeable-request-validator.js +0 -17
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const text_field_validator_1 = require("./text-field-validator");
5
+ const language_enum_1 = require("../../enums/language.enum");
6
+ const baseValidDto = {
7
+ id: 'text-1',
8
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Username' }],
9
+ type: 'TEXT',
10
+ required: true,
11
+ disabled: false,
12
+ };
13
+ describe('TextFieldDto Validator', () => {
14
+ describe('Valid cases', () => {
15
+ it('should return no errors for a valid minimal DTO', () => {
16
+ expect((0, text_field_validator_1.validateTextFieldDto)(baseValidDto)).toHaveLength(0);
17
+ });
18
+ it('should return no errors with optional value, min/max length and regex', () => {
19
+ const dto = {
20
+ ...baseValidDto,
21
+ value: 'abc',
22
+ minLength: 1,
23
+ maxLength: 10,
24
+ regexValidation: '^[a-z]+$',
25
+ regexValidationErrorMessage: [
26
+ { language: language_enum_1.LanguageEnum.ENGLISH, text: 'Lowercase only' },
27
+ ],
28
+ };
29
+ expect((0, text_field_validator_1.validateTextFieldDto)(dto)).toHaveLength(0);
30
+ });
31
+ });
32
+ describe('Missing required fields', () => {
33
+ it('should return errors for all missing required fields', () => {
34
+ const errors = (0, text_field_validator_1.validateTextFieldDto)({});
35
+ for (const prop of ['id', 'label', 'required', 'disabled']) {
36
+ expect(errors.some((e) => e.property === prop)).toBe(true);
37
+ }
38
+ });
39
+ });
40
+ describe('Invalid field values', () => {
41
+ it.each([
42
+ [{ ...baseValidDto, type: 'TEXTAREA' }, 'type'],
43
+ [{ ...baseValidDto, value: 123 }, 'value'],
44
+ [{ ...baseValidDto, minLength: -1 }, 'minLength'],
45
+ [{ ...baseValidDto, maxLength: 'ten' }, 'maxLength'],
46
+ [{ ...baseValidDto, regexValidation: '[' }, 'regexValidation'],
47
+ [
48
+ {
49
+ ...baseValidDto,
50
+ regexValidation: '^x$',
51
+ regexValidationErrorMessage: 'not-an-array',
52
+ },
53
+ 'regexValidationErrorMessage',
54
+ ],
55
+ ])('should return error for invalid %#', (dto, expectedProp) => {
56
+ const errors = (0, text_field_validator_1.validateTextFieldDto)(dto);
57
+ expect(errors.some((e) => e.property === expectedProp)).toBe(true);
58
+ });
59
+ });
60
+ });
@@ -0,0 +1,8 @@
1
+ import { ValidationError } from 'class-validator';
2
+ /**
3
+ * Validates a TextareaFieldDto object using class-validator decorators.
4
+ *
5
+ * @param data The object to validate as a TextareaFieldDto.
6
+ * @returns An array of validation errors, empty if validation succeeds.
7
+ */
8
+ export declare function validateTextareaFieldDto(data: object): ValidationError[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateTextareaFieldDto = validateTextareaFieldDto;
4
+ const class_validator_1 = require("class-validator");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const textarea_field_dto_1 = require("../../dtos/fields/textarea-field.dto");
7
+ /**
8
+ * Validates a TextareaFieldDto object using class-validator decorators.
9
+ *
10
+ * @param data The object to validate as a TextareaFieldDto.
11
+ * @returns An array of validation errors, empty if validation succeeds.
12
+ */
13
+ function validateTextareaFieldDto(data) {
14
+ return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(textarea_field_dto_1.TextareaFieldDto, data));
15
+ }
@@ -0,0 +1 @@
1
+ import 'reflect-metadata';
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ const textarea_field_validator_1 = require("./textarea-field-validator");
5
+ const language_enum_1 = require("../../enums/language.enum");
6
+ const baseValidDto = {
7
+ id: 'ta-1',
8
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Description' }],
9
+ type: 'TEXTAREA',
10
+ required: true,
11
+ disabled: false,
12
+ };
13
+ describe('TextareaFieldDto Validator', () => {
14
+ describe('Valid cases', () => {
15
+ it('should return no errors for a valid minimal DTO', () => {
16
+ expect((0, textarea_field_validator_1.validateTextareaFieldDto)(baseValidDto)).toHaveLength(0);
17
+ });
18
+ it('should return no errors with optional value and regex', () => {
19
+ expect((0, textarea_field_validator_1.validateTextareaFieldDto)({
20
+ ...baseValidDto,
21
+ value: 'Hello world',
22
+ minLength: 1,
23
+ maxLength: 1000,
24
+ regexValidation: '^.+$',
25
+ regexValidationErrorMessage: [
26
+ { language: language_enum_1.LanguageEnum.ENGLISH, text: 'Must not be empty' },
27
+ ],
28
+ })).toHaveLength(0);
29
+ });
30
+ });
31
+ describe('Missing required fields', () => {
32
+ it('should return errors for all missing required fields', () => {
33
+ const errors = (0, textarea_field_validator_1.validateTextareaFieldDto)({});
34
+ for (const prop of ['id', 'label', 'required', 'disabled']) {
35
+ expect(errors.some((e) => e.property === prop)).toBe(true);
36
+ }
37
+ });
38
+ });
39
+ describe('Invalid field values', () => {
40
+ it('should return error for wrong type literal', () => {
41
+ const errors = (0, textarea_field_validator_1.validateTextareaFieldDto)({
42
+ ...baseValidDto,
43
+ type: 'TEXT',
44
+ });
45
+ expect(errors.some((e) => e.property === 'type')).toBe(true);
46
+ });
47
+ it('should return error for non-string value', () => {
48
+ const errors = (0, textarea_field_validator_1.validateTextareaFieldDto)({ ...baseValidDto, value: 42 });
49
+ expect(errors.some((e) => e.property === 'value')).toBe(true);
50
+ });
51
+ });
52
+ });
@@ -0,0 +1,8 @@
1
+ import { ValidationError } from 'class-validator';
2
+ /**
3
+ * Validates a UrlFieldDto object using class-validator decorators.
4
+ *
5
+ * @param data The object to validate as a UrlFieldDto.
6
+ * @returns An array of validation errors, empty if validation succeeds.
7
+ */
8
+ export declare function validateUrlFieldDto(data: object): ValidationError[];
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateUrlFieldDto = validateUrlFieldDto;
4
+ const class_validator_1 = require("class-validator");
5
+ const class_transformer_1 = require("class-transformer");
6
+ const url_field_dto_1 = require("../../dtos/fields/url-field.dto");
7
+ /**
8
+ * Validates a UrlFieldDto object using class-validator decorators.
9
+ *
10
+ * @param data The object to validate as a UrlFieldDto.
11
+ * @returns An array of validation errors, empty if validation succeeds.
12
+ */
13
+ function validateUrlFieldDto(data) {
14
+ return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(url_field_dto_1.UrlFieldDto, 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 url_field_validator_1 = require("./url-field-validator");
5
+ const language_enum_1 = require("../../enums/language.enum");
6
+ const baseValidDto = {
7
+ id: 'url-1',
8
+ label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Website' }],
9
+ type: 'URL',
10
+ required: true,
11
+ disabled: false,
12
+ };
13
+ describe('UrlFieldDto Validator', () => {
14
+ describe('Valid cases', () => {
15
+ it('should return no errors for a valid minimal DTO', () => {
16
+ expect((0, url_field_validator_1.validateUrlFieldDto)(baseValidDto)).toHaveLength(0);
17
+ });
18
+ it('should return no errors with a valid URL value', () => {
19
+ expect((0, url_field_validator_1.validateUrlFieldDto)({
20
+ ...baseValidDto,
21
+ value: 'https://example.com',
22
+ })).toHaveLength(0);
23
+ });
24
+ });
25
+ describe('Missing required fields', () => {
26
+ it('should return errors for all missing required fields', () => {
27
+ const errors = (0, url_field_validator_1.validateUrlFieldDto)({});
28
+ for (const prop of ['id', 'label', 'required', 'disabled']) {
29
+ expect(errors.some((e) => e.property === prop)).toBe(true);
30
+ }
31
+ });
32
+ });
33
+ describe('Invalid field values', () => {
34
+ it.each([
35
+ [{ ...baseValidDto, type: 'TEXT' }, 'type'],
36
+ [{ ...baseValidDto, value: 'not a url' }, 'value'],
37
+ [{ ...baseValidDto, value: 42 }, 'value'],
38
+ ])('should return error for invalid %#', (dto, expectedProp) => {
39
+ const errors = (0, url_field_validator_1.validateUrlFieldDto)(dto);
40
+ expect(errors.some((e) => e.property === expectedProp)).toBe(true);
41
+ });
42
+ });
43
+ });
@@ -17,7 +17,7 @@ describe('NotificationInfoDto Validator', () => {
17
17
  dto: {
18
18
  type: notification_message_type_enum_1.NotificationMessageTypeEnum.EMAIL,
19
19
  title: 'Valid Title',
20
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
20
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
21
21
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
22
22
  payPerUseUnits: [validUnit],
23
23
  },
@@ -27,7 +27,7 @@ describe('NotificationInfoDto Validator', () => {
27
27
  description: 'should return error for missing type',
28
28
  dto: {
29
29
  title: 'Valid Title',
30
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
30
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
31
31
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
32
32
  payPerUseUnits: [validUnit],
33
33
  },
@@ -38,7 +38,7 @@ describe('NotificationInfoDto Validator', () => {
38
38
  dto: {
39
39
  type: notification_message_type_enum_1.NotificationMessageTypeEnum.EMAIL,
40
40
  title: 'Valid Title',
41
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
41
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
42
42
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
43
43
  payPerUseUnits: [
44
44
  { id: '', unitDescription: '', intervalDescription: '' },
@@ -58,7 +58,7 @@ describe('NotificationInfoDto Validator', () => {
58
58
  description: 'should return ValidationError for missing title',
59
59
  dto: {
60
60
  type: notification_message_type_enum_1.NotificationMessageTypeEnum.EMAIL,
61
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
61
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
62
62
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
63
63
  payPerUseUnits: [validUnit],
64
64
  },
@@ -69,7 +69,7 @@ describe('NotificationInfoDto Validator', () => {
69
69
  dto: {
70
70
  type: notification_message_type_enum_1.NotificationMessageTypeEnum.EMAIL,
71
71
  title: 'Valid Title',
72
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
72
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
73
73
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
74
74
  payPerUseUnits: [
75
75
  { id: '', unitDescription: '', intervalDescription: '' },
@@ -1,47 +1,42 @@
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';
5
4
  const item_actions_enum_1 = require("../enums/item-actions.enum");
6
5
  const language_enum_1 = require("../enums/language.enum");
7
- const field_type_enum_1 = require("../enums/field-type.enum");
8
6
  const product_info_validator_1 = require("./product-info.validator");
9
7
  describe('ProductInfoDto Validator', () => {
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,
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
+ },
19
19
  };
20
20
  const invalidField = {
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,
21
+ // missing required field, so `field` is undefined
27
22
  };
28
23
  const testCases = [
29
24
  {
30
25
  description: 'should return no errors for valid DTO',
31
26
  dto: {
32
27
  title: 'Test',
33
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
28
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
34
29
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
35
- productAttributes: [field],
36
- itemAttributes: [field],
30
+ productAttributes: [validField],
31
+ itemAttributes: [validField],
37
32
  },
38
33
  expectedErrorsLength: 0,
39
34
  },
40
35
  {
41
- description: 'should return error for invalid required and hidden',
36
+ description: 'should return error for missing field in attribute',
42
37
  dto: {
43
38
  title: 'Test',
44
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
39
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
45
40
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
46
41
  itemAttributes: [invalidField],
47
42
  },
@@ -51,10 +46,10 @@ describe('ProductInfoDto Validator', () => {
51
46
  description: 'should return error for invalid title',
52
47
  dto: {
53
48
  title: '',
54
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
49
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
55
50
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
56
- productAttributes: [field],
57
- itemAttributes: [field],
51
+ productAttributes: [validField],
52
+ itemAttributes: [validField],
58
53
  },
59
54
  expectedErrorsLength: 1,
60
55
  },
@@ -64,8 +59,8 @@ describe('ProductInfoDto Validator', () => {
64
59
  title: 'Test',
65
60
  supportedActions: ['update'],
66
61
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
67
- productAttributes: [field],
68
- itemAttributes: [field],
62
+ productAttributes: [validField],
63
+ itemAttributes: [validField],
69
64
  },
70
65
  expectedErrorsLength: 1,
71
66
  },
@@ -73,10 +68,10 @@ describe('ProductInfoDto Validator', () => {
73
68
  description: 'should return error for unsupported language',
74
69
  dto: {
75
70
  title: 'Test',
76
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
71
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
77
72
  supportedLanguages: [],
78
- productAttributes: [field],
79
- itemAttributes: [field],
73
+ productAttributes: [validField],
74
+ itemAttributes: [validField],
80
75
  },
81
76
  expectedErrorsLength: 1,
82
77
  },
@@ -84,10 +79,10 @@ describe('ProductInfoDto Validator', () => {
84
79
  description: 'should return no errors for valid DTO with adminPanel and clientPanel',
85
80
  dto: {
86
81
  title: 'Test',
87
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
82
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
88
83
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
89
- productAttributes: [field],
90
- itemAttributes: [field],
84
+ productAttributes: [validField],
85
+ itemAttributes: [validField],
91
86
  adminPanel: {
92
87
  tabs: {
93
88
  product: [{ label: 'Product', url: 'https://example.com/product' }],
@@ -103,16 +98,12 @@ describe('ProductInfoDto Validator', () => {
103
98
  description: 'should return error for invalid DTO with adminPanel and clientPanel',
104
99
  dto: {
105
100
  title: '',
106
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
101
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
107
102
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
108
- productAttributes: [field],
109
- itemAttributes: [field],
110
- adminPanel: {
111
- /* invalid admin panel data */
112
- },
113
- clientPanel: {
114
- /* invalid client panel data */
115
- },
103
+ productAttributes: [validField],
104
+ itemAttributes: [validField],
105
+ adminPanel: {},
106
+ clientPanel: {},
116
107
  },
117
108
  expectedErrorsLength: 3,
118
109
  },
@@ -120,10 +111,10 @@ describe('ProductInfoDto Validator', () => {
120
111
  description: 'should return no errors for valid DTO with payPerUseUnits',
121
112
  dto: {
122
113
  title: 'Test',
123
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
114
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
124
115
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
125
- productAttributes: [field],
126
- itemAttributes: [field],
116
+ productAttributes: [validField],
117
+ itemAttributes: [validField],
127
118
  payPerUseUnits: [
128
119
  { id: 'ram', unitDescription: 'MB', intervalDescription: 'month' },
129
120
  ],
@@ -134,10 +125,10 @@ describe('ProductInfoDto Validator', () => {
134
125
  description: 'should return error for invalid DTO with payPerUseUnits',
135
126
  dto: {
136
127
  title: 'Test',
137
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
128
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
138
129
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
139
- productAttributes: [field],
140
- itemAttributes: [field],
130
+ productAttributes: [validField],
131
+ itemAttributes: [validField],
141
132
  payPerUseUnits: [
142
133
  { id: '', unitDescription: '', intervalDescription: '' },
143
134
  ],
@@ -151,115 +142,58 @@ describe('ProductInfoDto Validator', () => {
151
142
  expect(errors.length).toBe(expectedErrorsLength);
152
143
  });
153
144
  });
154
- const validationErrorTestCases = [
155
- {
156
- description: 'should return ValidationError for missing title',
157
- dto: {
158
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.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)', () => {
145
+ describe('AttributeFieldDto class-level constraints inside ProductInfoDto', () => {
146
+ it('fails when an AttributeFieldDto has only repeatableMin (AllOrNone)', () => {
188
147
  const fieldWithOnlyMin = {
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,
148
+ ...validField,
197
149
  repeatableMin: 1,
198
150
  };
199
151
  const dto = {
200
152
  title: 'Test',
201
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
153
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
202
154
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
203
155
  productAttributes: [fieldWithOnlyMin],
204
156
  };
205
157
  const errors = (0, product_info_validator_1.validateProductInfoDto)(dto);
206
158
  expect(errors.length).toBeGreaterThan(0);
207
159
  });
208
- it('fails when a FieldDto has only repeatableMax (AllOrNone)', () => {
160
+ it('fails when an AttributeFieldDto has only repeatableMax (AllOrNone)', () => {
209
161
  const fieldWithOnlyMax = {
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,
162
+ ...validField,
218
163
  repeatableMax: 5,
219
164
  };
220
165
  const dto = {
221
166
  title: 'Test',
222
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
167
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
223
168
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
224
169
  itemAttributes: [fieldWithOnlyMax],
225
170
  };
226
171
  const errors = (0, product_info_validator_1.validateProductInfoDto)(dto);
227
172
  expect(errors.length).toBeGreaterThan(0);
228
173
  });
229
- it('passes when a FieldDto has both min and max with min <= max', () => {
174
+ it('passes when an AttributeFieldDto has both min and max with min <= max', () => {
230
175
  const fieldOk = {
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,
176
+ ...validField,
177
+ repeatableMin: 1,
178
+ repeatableMax: 3,
238
179
  };
239
180
  const dto = {
240
181
  title: 'Test',
241
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
182
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
242
183
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
243
184
  productAttributes: [fieldOk],
244
185
  };
245
186
  expect((0, product_info_validator_1.validateProductInfoDto)(dto)).toHaveLength(0);
246
187
  });
247
- it('fails when a FieldDto has both min and max with min > max (Min<=Max)', () => {
188
+ it('fails when an AttributeFieldDto has min > max (Min<=Max)', () => {
248
189
  const fieldBad = {
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,
190
+ ...validField,
257
191
  repeatableMin: 5,
258
192
  repeatableMax: 2,
259
193
  };
260
194
  const dto = {
261
195
  title: 'Test',
262
- supportedActions: [item_actions_enum_1.ProductItemActionsEnum.CREATE],
196
+ supportedActions: [item_actions_enum_1.ProductActionsEnum.CREATE],
263
197
  supportedLanguages: [language_enum_1.LanguageEnum.ENGLISH],
264
198
  itemAttributes: [fieldBad],
265
199
  };
@@ -18,10 +18,10 @@ describe('ProductItemDataDto Validator', () => {
18
18
  expect((0, product_item_data_validator_1.validateProductItemDataDto)(baseValidDto)).toHaveLength(0);
19
19
  });
20
20
  it('should return no errors with a valid action', () => {
21
- const dto = { ...baseValidDto, action: item_actions_enum_1.ProductItemActionsEnum.CREATE };
21
+ const dto = { ...baseValidDto, action: item_actions_enum_1.ProductActionsEnum.CREATE };
22
22
  expect((0, product_item_data_validator_1.validateProductItemDataDto)(dto)).toHaveLength(0);
23
23
  });
24
- it.each(Object.values(item_actions_enum_1.ProductItemActionsEnum))('should accept action %s', (action) => {
24
+ it.each(Object.values(item_actions_enum_1.ProductActionsEnum))('should accept action %s', (action) => {
25
25
  const dto = { ...baseValidDto, action };
26
26
  expect((0, product_item_data_validator_1.validateProductItemDataDto)(dto)).toHaveLength(0);
27
27
  });
@@ -31,7 +31,7 @@ describe('ProductItemDataDto Validator', () => {
31
31
  itemId: 'item-456',
32
32
  price: 9.99,
33
33
  discountPrice: 7.99,
34
- action: item_actions_enum_1.ProductItemActionsEnum.RENEW,
34
+ action: item_actions_enum_1.ProductActionsEnum.RENEW,
35
35
  };
36
36
  expect((0, product_item_data_validator_1.validateProductItemDataDto)(dto)).toHaveLength(0);
37
37
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hosterai/types",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
@@ -1,18 +0,0 @@
1
- import { ProductItemDataDto } from '../product-item-data.dto';
2
- import { ClientDataDto } from '../../client-data.dto';
3
- /**
4
- * Represents a request to check if a product item is downgradable.
5
- * This DTO contains all the necessary information for the check.
6
- */
7
- export declare class ProductDowngradableRequestDto {
8
- /**
9
- * The client's data.
10
- * This object holds all the relevant information about the client initiating the request.
11
- */
12
- clientData: ClientDataDto;
13
- /**
14
- * The data of the product item to be checked.
15
- * This object contains the specific details of the product instance being evaluated.
16
- */
17
- itemData: ProductItemDataDto;
18
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ProductDowngradableRequestDto = void 0;
13
- const class_validator_1 = require("class-validator");
14
- const class_transformer_1 = require("class-transformer");
15
- const product_item_data_dto_1 = require("../product-item-data.dto");
16
- const client_data_dto_1 = require("../../client-data.dto");
17
- /**
18
- * Represents a request to check if a product item is downgradable.
19
- * This DTO contains all the necessary information for the check.
20
- */
21
- class ProductDowngradableRequestDto {
22
- }
23
- exports.ProductDowngradableRequestDto = ProductDowngradableRequestDto;
24
- __decorate([
25
- (0, class_validator_1.IsDefined)(),
26
- (0, class_validator_1.IsObject)(),
27
- (0, class_validator_1.ValidateNested)(),
28
- (0, class_transformer_1.Type)(() => client_data_dto_1.ClientDataDto),
29
- __metadata("design:type", client_data_dto_1.ClientDataDto)
30
- ], ProductDowngradableRequestDto.prototype, "clientData", void 0);
31
- __decorate([
32
- (0, class_validator_1.IsDefined)(),
33
- (0, class_validator_1.IsObject)(),
34
- (0, class_validator_1.ValidateNested)(),
35
- (0, class_transformer_1.Type)(() => product_item_data_dto_1.ProductItemDataDto),
36
- __metadata("design:type", product_item_data_dto_1.ProductItemDataDto)
37
- ], ProductDowngradableRequestDto.prototype, "itemData", void 0);