@hosterai/types 0.0.30 → 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.
- package/dist/decorators/is-e164-validator.spec.d.ts +1 -0
- package/dist/decorators/is-e164-validator.spec.js +64 -0
- package/dist/decorators/is-e164.validator.d.ts +2 -0
- package/dist/decorators/is-e164.validator.js +30 -0
- package/dist/dtos/base-field.dto.d.ts +45 -0
- package/dist/dtos/base-field.dto.js +133 -0
- package/dist/dtos/fields/any-field.dto.d.ts +38 -0
- package/dist/dtos/fields/any-field.dto.js +36 -0
- package/dist/dtos/fields/boolean-field.dto.d.ts +14 -0
- package/dist/dtos/fields/boolean-field.dto.js +48 -0
- package/dist/dtos/fields/countries-field.dto.d.ts +14 -0
- package/dist/dtos/fields/countries-field.dto.js +51 -0
- package/dist/dtos/fields/currency-field.dto.d.ts +14 -0
- package/dist/dtos/fields/currency-field.dto.js +50 -0
- package/dist/dtos/fields/date-field.dto.d.ts +14 -0
- package/dist/dtos/fields/date-field.dto.js +49 -0
- package/dist/dtos/fields/email-field.dto.d.ts +14 -0
- package/dist/dtos/fields/email-field.dto.js +49 -0
- package/dist/dtos/fields/multi-select-field.dto.d.ts +15 -0
- package/dist/dtos/fields/multi-select-field.dto.js +53 -0
- package/dist/dtos/fields/number-field.dto.d.ts +26 -0
- package/dist/dtos/fields/number-field.dto.js +82 -0
- package/dist/dtos/fields/password-field.dto.d.ts +21 -0
- package/dist/dtos/fields/password-field.dto.js +64 -0
- package/dist/dtos/fields/phone-field.dto.d.ts +14 -0
- package/dist/dtos/fields/phone-field.dto.js +50 -0
- package/dist/dtos/fields/select-field.dto.d.ts +15 -0
- package/dist/dtos/fields/select-field.dto.js +51 -0
- package/dist/dtos/fields/text-field.dto.d.ts +31 -0
- package/dist/dtos/fields/text-field.dto.js +102 -0
- package/dist/dtos/fields/textarea-field.dto.d.ts +31 -0
- package/dist/dtos/fields/textarea-field.dto.js +102 -0
- package/dist/dtos/fields/url-field.dto.d.ts +14 -0
- package/dist/dtos/fields/url-field.dto.js +49 -0
- package/dist/dtos/info/info-notification.dto.d.ts +5 -0
- package/dist/dtos/info/info-notification.dto.js +7 -0
- package/dist/dtos/info/info.dto.d.ts +196 -0
- package/dist/dtos/info/info.dto.js +278 -0
- package/dist/dtos/info.dto.d.ts +7 -0
- package/dist/dtos/info.dto.js +11 -0
- package/dist/dtos/notification/notification-request.dto.d.ts +20 -0
- package/dist/dtos/notification/notification-request.dto.js +31 -0
- package/dist/dtos/receiver/receiver-email.dto.d.ts +20 -0
- package/dist/dtos/receiver/receiver-email.dto.js +39 -0
- package/dist/dtos/receiver/receiver-push.dto.d.ts +15 -0
- package/dist/dtos/receiver/receiver-push.dto.js +31 -0
- package/dist/dtos/receiver/receiver-sms.dto.d.ts +11 -0
- package/dist/dtos/receiver/receiver-sms.dto.js +26 -0
- package/dist/dtos/request.dto.d.ts +20 -0
- package/dist/dtos/request.dto.js +31 -0
- package/dist/dtos/sender/sender-email.dto.d.ts +25 -0
- package/dist/dtos/sender/sender-email.dto.js +46 -0
- package/dist/dtos/sender/sender-push.dto.d.ts +31 -0
- package/dist/dtos/sender/sender-push.dto.js +50 -0
- package/dist/dtos/sender/sender-sms.dto.d.ts +15 -0
- package/dist/dtos/sender/sender-sms.dto.js +30 -0
- package/dist/enums/message-type.enum.d.ts +5 -0
- package/dist/enums/message-type.enum.js +9 -0
- package/dist/enums/roles.enum.d.ts +1 -0
- package/dist/enums/roles.enum.js +1 -0
- package/dist/openapi/schemas/components.schemas.d.ts +27 -6
- package/dist/openapi/schemas/components.schemas.js +27 -0
- package/dist/validators/any-field-validator.d.ts +10 -0
- package/dist/validators/any-field-validator.js +28 -0
- package/dist/validators/any-field-validator.spec.d.ts +1 -0
- package/dist/validators/any-field-validator.spec.js +37 -0
- package/dist/validators/fields/boolean-field-validator.d.ts +8 -0
- package/dist/validators/fields/boolean-field-validator.js +15 -0
- package/dist/validators/fields/boolean-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/boolean-field-validator.spec.js +43 -0
- package/dist/validators/fields/countries-field-validator.d.ts +8 -0
- package/dist/validators/fields/countries-field-validator.js +15 -0
- package/dist/validators/fields/countries-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/countries-field-validator.spec.js +44 -0
- package/dist/validators/fields/currency-field-validator.d.ts +8 -0
- package/dist/validators/fields/currency-field-validator.js +15 -0
- package/dist/validators/fields/currency-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/currency-field-validator.spec.js +41 -0
- package/dist/validators/fields/date-field-validator.d.ts +8 -0
- package/dist/validators/fields/date-field-validator.js +15 -0
- package/dist/validators/fields/date-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/date-field-validator.spec.js +43 -0
- package/dist/validators/fields/email-field-validator.d.ts +8 -0
- package/dist/validators/fields/email-field-validator.js +15 -0
- package/dist/validators/fields/email-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/email-field-validator.spec.js +43 -0
- package/dist/validators/fields/multi-select-field-validator.d.ts +8 -0
- package/dist/validators/fields/multi-select-field-validator.js +15 -0
- package/dist/validators/fields/multi-select-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/multi-select-field-validator.spec.js +52 -0
- package/dist/validators/fields/number-field-validator.d.ts +8 -0
- package/dist/validators/fields/number-field-validator.js +15 -0
- package/dist/validators/fields/number-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/number-field-validator.spec.js +59 -0
- package/dist/validators/fields/password-field-validator.d.ts +8 -0
- package/dist/validators/fields/password-field-validator.js +15 -0
- package/dist/validators/fields/password-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/password-field-validator.spec.js +44 -0
- package/dist/validators/fields/phone-field-validator.d.ts +8 -0
- package/dist/validators/fields/phone-field-validator.js +15 -0
- package/dist/validators/fields/phone-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/phone-field-validator.spec.js +41 -0
- package/dist/validators/fields/select-field-validator.d.ts +8 -0
- package/dist/validators/fields/select-field-validator.js +15 -0
- package/dist/validators/fields/select-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/select-field-validator.spec.js +46 -0
- package/dist/validators/fields/text-field-validator.d.ts +8 -0
- package/dist/validators/fields/text-field-validator.js +15 -0
- package/dist/validators/fields/text-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/text-field-validator.spec.js +60 -0
- package/dist/validators/fields/textarea-field-validator.d.ts +8 -0
- package/dist/validators/fields/textarea-field-validator.js +15 -0
- package/dist/validators/fields/textarea-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/textarea-field-validator.spec.js +52 -0
- package/dist/validators/fields/url-field-validator.d.ts +8 -0
- package/dist/validators/fields/url-field-validator.js +15 -0
- package/dist/validators/fields/url-field-validator.spec.d.ts +1 -0
- package/dist/validators/fields/url-field-validator.spec.js +43 -0
- package/package.json +1 -1
- package/dist/dtos/product/requests/product-downgradeable-request.dto.d.ts +0 -18
- package/dist/dtos/product/requests/product-downgradeable-request.dto.js +0 -37
- package/dist/dtos/product/requests/product-upgradeable-request.dto.d.ts +0 -18
- package/dist/dtos/product/requests/product-upgradeable-request.dto.js +0 -37
- package/dist/dtos/product/responses/product-downgradeable-response.dto.d.ts +0 -22
- package/dist/dtos/product/responses/product-downgradeable-response.dto.js +0 -11
- package/dist/dtos/product/responses/product-upgradeable-response.dto.d.ts +0 -22
- package/dist/dtos/product/responses/product-upgradeable-response.dto.js +0 -11
- package/dist/validators/product-downgradeable-request-validator.d.ts +0 -8
- package/dist/validators/product-downgradeable-request-validator.js +0 -17
- package/dist/validators/product-upgradeable-request-validator.d.ts +0 -8
- package/dist/validators/product-upgradeable-request-validator.js +0 -17
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const number_field_validator_1 = require("./number-field-validator");
|
|
5
|
+
const language_enum_1 = require("../../enums/language.enum");
|
|
6
|
+
const baseValidDto = {
|
|
7
|
+
id: 'num-1',
|
|
8
|
+
label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'CPU Cores' }],
|
|
9
|
+
type: 'NUMBER',
|
|
10
|
+
required: true,
|
|
11
|
+
disabled: false,
|
|
12
|
+
};
|
|
13
|
+
describe('NumberFieldDto Validator', () => {
|
|
14
|
+
describe('Valid cases', () => {
|
|
15
|
+
it('should return no errors for a valid minimal DTO', () => {
|
|
16
|
+
expect((0, number_field_validator_1.validateNumberFieldDto)(baseValidDto)).toHaveLength(0);
|
|
17
|
+
});
|
|
18
|
+
it('should return no errors with value, min, max, integer', () => {
|
|
19
|
+
expect((0, number_field_validator_1.validateNumberFieldDto)({
|
|
20
|
+
...baseValidDto,
|
|
21
|
+
value: 4,
|
|
22
|
+
min: 1,
|
|
23
|
+
max: 16,
|
|
24
|
+
integer: true,
|
|
25
|
+
})).toHaveLength(0);
|
|
26
|
+
});
|
|
27
|
+
it('should return no errors when min equals max', () => {
|
|
28
|
+
expect((0, number_field_validator_1.validateNumberFieldDto)({ ...baseValidDto, min: 5, max: 5 })).toHaveLength(0);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
describe('Missing required fields', () => {
|
|
32
|
+
it('should return errors for all missing required fields', () => {
|
|
33
|
+
const errors = (0, number_field_validator_1.validateNumberFieldDto)({});
|
|
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.each([
|
|
41
|
+
[{ ...baseValidDto, type: 'TEXT' }, 'type'],
|
|
42
|
+
[{ ...baseValidDto, value: 'four' }, 'value'],
|
|
43
|
+
[{ ...baseValidDto, min: 'one' }, 'min'],
|
|
44
|
+
[{ ...baseValidDto, max: 'two' }, 'max'],
|
|
45
|
+
[{ ...baseValidDto, integer: 'yes' }, 'integer'],
|
|
46
|
+
])('should return error for invalid %#', (dto, expectedProp) => {
|
|
47
|
+
const errors = (0, number_field_validator_1.validateNumberFieldDto)(dto);
|
|
48
|
+
expect(errors.some((e) => e.property === expectedProp)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
it('should return error when min is greater than max', () => {
|
|
51
|
+
const errors = (0, number_field_validator_1.validateNumberFieldDto)({
|
|
52
|
+
...baseValidDto,
|
|
53
|
+
min: 10,
|
|
54
|
+
max: 5,
|
|
55
|
+
});
|
|
56
|
+
expect(errors.length).toBeGreaterThan(0);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a PasswordFieldDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as a PasswordFieldDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validatePasswordFieldDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePasswordFieldDto = validatePasswordFieldDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const password_field_dto_1 = require("../../dtos/fields/password-field.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates a PasswordFieldDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as a PasswordFieldDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validatePasswordFieldDto(data) {
|
|
14
|
+
return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(password_field_dto_1.PasswordFieldDto, 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 password_field_validator_1 = require("./password-field-validator");
|
|
5
|
+
const language_enum_1 = require("../../enums/language.enum");
|
|
6
|
+
const baseValidDto = {
|
|
7
|
+
id: 'pwd-1',
|
|
8
|
+
label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Password' }],
|
|
9
|
+
type: 'PASSWORD',
|
|
10
|
+
required: true,
|
|
11
|
+
disabled: false,
|
|
12
|
+
};
|
|
13
|
+
describe('PasswordFieldDto Validator', () => {
|
|
14
|
+
describe('Valid cases', () => {
|
|
15
|
+
it('should return no errors for a valid minimal DTO', () => {
|
|
16
|
+
expect((0, password_field_validator_1.validatePasswordFieldDto)(baseValidDto)).toHaveLength(0);
|
|
17
|
+
});
|
|
18
|
+
it('should return no errors with value and minLength', () => {
|
|
19
|
+
expect((0, password_field_validator_1.validatePasswordFieldDto)({
|
|
20
|
+
...baseValidDto,
|
|
21
|
+
value: 's3cret!',
|
|
22
|
+
minLength: 6,
|
|
23
|
+
})).toHaveLength(0);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe('Missing required fields', () => {
|
|
27
|
+
it('should return errors for all missing required fields', () => {
|
|
28
|
+
const errors = (0, password_field_validator_1.validatePasswordFieldDto)({});
|
|
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: 1234 }, 'value'],
|
|
38
|
+
[{ ...baseValidDto, minLength: -1 }, 'minLength'],
|
|
39
|
+
])('should return error for invalid %#', (dto, expectedProp) => {
|
|
40
|
+
const errors = (0, password_field_validator_1.validatePasswordFieldDto)(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 PhoneFieldDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as a PhoneFieldDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validatePhoneFieldDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePhoneFieldDto = validatePhoneFieldDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const phone_field_dto_1 = require("../../dtos/fields/phone-field.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates a PhoneFieldDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as a PhoneFieldDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validatePhoneFieldDto(data) {
|
|
14
|
+
return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(phone_field_dto_1.PhoneFieldDto, data));
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const phone_field_validator_1 = require("./phone-field-validator");
|
|
5
|
+
const language_enum_1 = require("../../enums/language.enum");
|
|
6
|
+
const baseValidDto = {
|
|
7
|
+
id: 'phone-1',
|
|
8
|
+
label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Phone' }],
|
|
9
|
+
type: 'PHONE',
|
|
10
|
+
required: true,
|
|
11
|
+
disabled: false,
|
|
12
|
+
};
|
|
13
|
+
describe('PhoneFieldDto Validator', () => {
|
|
14
|
+
describe('Valid cases', () => {
|
|
15
|
+
it('should return no errors for a valid minimal DTO', () => {
|
|
16
|
+
expect((0, phone_field_validator_1.validatePhoneFieldDto)(baseValidDto)).toHaveLength(0);
|
|
17
|
+
});
|
|
18
|
+
it('should return no errors with a canonical E.164 value', () => {
|
|
19
|
+
expect((0, phone_field_validator_1.validatePhoneFieldDto)({ ...baseValidDto, value: '+14155552671' })).toHaveLength(0);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe('Missing required fields', () => {
|
|
23
|
+
it('should return errors for all missing required fields', () => {
|
|
24
|
+
const errors = (0, phone_field_validator_1.validatePhoneFieldDto)({});
|
|
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.each([
|
|
32
|
+
[{ ...baseValidDto, type: 'TEXT' }, 'type'],
|
|
33
|
+
[{ ...baseValidDto, value: '14155552671' }, 'value'],
|
|
34
|
+
[{ ...baseValidDto, value: '+1 415 555 2671' }, 'value'],
|
|
35
|
+
[{ ...baseValidDto, value: 'not-a-phone' }, 'value'],
|
|
36
|
+
])('should return error for invalid %#', (dto, expectedProp) => {
|
|
37
|
+
const errors = (0, phone_field_validator_1.validatePhoneFieldDto)(dto);
|
|
38
|
+
expect(errors.some((e) => e.property === expectedProp)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a SelectFieldDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as a SelectFieldDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateSelectFieldDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSelectFieldDto = validateSelectFieldDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const select_field_dto_1 = require("../../dtos/fields/select-field.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates a SelectFieldDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as a SelectFieldDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validateSelectFieldDto(data) {
|
|
14
|
+
return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(select_field_dto_1.SelectFieldDto, data));
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const select_field_validator_1 = require("./select-field-validator");
|
|
5
|
+
const language_enum_1 = require("../../enums/language.enum");
|
|
6
|
+
const baseValidDto = {
|
|
7
|
+
id: 'sel-1',
|
|
8
|
+
label: [{ language: language_enum_1.LanguageEnum.ENGLISH, text: 'Plan' }],
|
|
9
|
+
type: 'SELECT',
|
|
10
|
+
required: true,
|
|
11
|
+
disabled: false,
|
|
12
|
+
};
|
|
13
|
+
describe('SelectFieldDto Validator', () => {
|
|
14
|
+
describe('Valid cases', () => {
|
|
15
|
+
it('should return no errors for a valid minimal DTO', () => {
|
|
16
|
+
expect((0, select_field_validator_1.validateSelectFieldDto)(baseValidDto)).toHaveLength(0);
|
|
17
|
+
});
|
|
18
|
+
it('should return no errors with a valid option value', () => {
|
|
19
|
+
expect((0, select_field_validator_1.validateSelectFieldDto)({
|
|
20
|
+
...baseValidDto,
|
|
21
|
+
value: { key: 'basic', value: 'Basic' },
|
|
22
|
+
})).toHaveLength(0);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe('Missing required fields', () => {
|
|
26
|
+
it('should return errors for all missing required fields', () => {
|
|
27
|
+
const errors = (0, select_field_validator_1.validateSelectFieldDto)({});
|
|
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('should return error for wrong type literal', () => {
|
|
35
|
+
const errors = (0, select_field_validator_1.validateSelectFieldDto)({ ...baseValidDto, type: 'TEXT' });
|
|
36
|
+
expect(errors.some((e) => e.property === 'type')).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
it('should return error for option missing required key', () => {
|
|
39
|
+
const errors = (0, select_field_validator_1.validateSelectFieldDto)({
|
|
40
|
+
...baseValidDto,
|
|
41
|
+
value: { value: 'No Key' },
|
|
42
|
+
});
|
|
43
|
+
expect(errors.some((e) => e.property === 'value')).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ValidationError } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a TextFieldDto object using class-validator decorators.
|
|
4
|
+
*
|
|
5
|
+
* @param data The object to validate as a TextFieldDto.
|
|
6
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateTextFieldDto(data: object): ValidationError[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTextFieldDto = validateTextFieldDto;
|
|
4
|
+
const class_validator_1 = require("class-validator");
|
|
5
|
+
const class_transformer_1 = require("class-transformer");
|
|
6
|
+
const text_field_dto_1 = require("../../dtos/fields/text-field.dto");
|
|
7
|
+
/**
|
|
8
|
+
* Validates a TextFieldDto object using class-validator decorators.
|
|
9
|
+
*
|
|
10
|
+
* @param data The object to validate as a TextFieldDto.
|
|
11
|
+
* @returns An array of validation errors, empty if validation succeeds.
|
|
12
|
+
*/
|
|
13
|
+
function validateTextFieldDto(data) {
|
|
14
|
+
return (0, class_validator_1.validateSync)((0, class_transformer_1.plainToInstance)(text_field_dto_1.TextFieldDto, data));
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
@@ -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
|
+
});
|
package/package.json
CHANGED
|
@@ -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);
|
|
@@ -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 upgradeable.
|
|
5
|
-
* This DTO contains all the necessary information for the check.
|
|
6
|
-
*/
|
|
7
|
-
export declare class ProductUpgradeableRequestDto {
|
|
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
|
-
}
|