@cryptexlabs/codex-nodejs-common 0.12.1 → 0.12.2
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/lib/package.json +1 -1
- package/lib/src/decorator/is-valid-email-type.d.ts +4 -2
- package/lib/src/decorator/is-valid-email-type.js +15 -5
- package/lib/src/decorator/is-valid-email-type.js.map +1 -1
- package/lib/src/decorator/is-valid-email.d.ts +9 -0
- package/lib/src/decorator/is-valid-email.js +43 -0
- package/lib/src/decorator/is-valid-email.js.map +1 -0
- package/lib/src/decorator/is-valid-phone-type.d.ts +4 -2
- package/lib/src/decorator/is-valid-phone-type.js +15 -5
- package/lib/src/decorator/is-valid-phone-type.js.map +1 -1
- package/lib/src/decorator/is-valid-utc-timezone.d.ts +1 -1
- package/lib/src/decorator/is-valid-utc-timezone.js +3 -4
- package/lib/src/decorator/is-valid-utc-timezone.js.map +1 -1
- package/lib/src/dto/email.dto.js +3 -5
- package/lib/src/dto/email.dto.js.map +1 -1
- package/lib/src/dto/phone.dto.js +1 -3
- package/lib/src/dto/phone.dto.js.map +1 -1
- package/lib/src/dto/photo.dto.js +0 -1
- package/lib/src/dto/photo.dto.js.map +1 -1
- package/package.json +1 -1
- package/src/decorator/is-valid-email-type.ts +23 -7
- package/src/decorator/is-valid-email.ts +42 -0
- package/src/decorator/is-valid-phone-type.ts +33 -8
- package/src/decorator/is-valid-utc-timezone.ts +8 -6
- package/src/dto/email.dto.ts +3 -4
- package/src/dto/phone.dto.ts +1 -3
- package/src/dto/photo.dto.ts +0 -1
package/lib/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ValidatorConstraintInterface, ValidationArguments, ValidationOptions } from "class-validator";
|
|
2
2
|
export declare class IsValidEmailTypeConstraint implements ValidatorConstraintInterface {
|
|
3
3
|
private readonly EMAIL_TYPES;
|
|
4
|
-
validate(
|
|
4
|
+
validate(emailType: any, args: ValidationArguments): boolean;
|
|
5
5
|
defaultMessage(args: ValidationArguments): string;
|
|
6
6
|
}
|
|
7
|
-
export declare function IsValidEmailType(validationOptions?: ValidationOptions
|
|
7
|
+
export declare function IsValidEmailType(validationOptions?: ValidationOptions & {
|
|
8
|
+
optional?: boolean;
|
|
9
|
+
}): (object: any, propertyName: string) => void;
|
|
@@ -14,16 +14,26 @@ let IsValidEmailTypeConstraint = class IsValidEmailTypeConstraint {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
this.EMAIL_TYPES = Object.values(authf_data_model_1.EmailTypeEnum);
|
|
16
16
|
}
|
|
17
|
-
validate(
|
|
18
|
-
|
|
17
|
+
validate(emailType, args) {
|
|
18
|
+
var _a;
|
|
19
|
+
const optional = ((_a = args.constraints[0]) === null || _a === void 0 ? void 0 : _a.optional) || false;
|
|
20
|
+
if (optional && (emailType === undefined || emailType === null)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return this.EMAIL_TYPES.includes(emailType);
|
|
19
24
|
}
|
|
20
25
|
defaultMessage(args) {
|
|
21
|
-
|
|
26
|
+
var _a;
|
|
27
|
+
const optional = ((_a = args.constraints[0]) === null || _a === void 0 ? void 0 : _a.optional) || false;
|
|
28
|
+
if (optional && (args.value === undefined || args.value === null)) {
|
|
29
|
+
return `"${args.value}" is optional, but it must either be null/undefined or a valid email type.`;
|
|
30
|
+
}
|
|
31
|
+
return `"${args.value}" is not a valid email type. Allowed types: ${this.EMAIL_TYPES.join(", ")}.`;
|
|
22
32
|
}
|
|
23
33
|
};
|
|
24
34
|
exports.IsValidEmailTypeConstraint = IsValidEmailTypeConstraint;
|
|
25
35
|
exports.IsValidEmailTypeConstraint = IsValidEmailTypeConstraint = __decorate([
|
|
26
|
-
(0, class_validator_1.ValidatorConstraint)({
|
|
36
|
+
(0, class_validator_1.ValidatorConstraint)({ async: false })
|
|
27
37
|
], IsValidEmailTypeConstraint);
|
|
28
38
|
function IsValidEmailType(validationOptions) {
|
|
29
39
|
return (object, propertyName) => {
|
|
@@ -31,7 +41,7 @@ function IsValidEmailType(validationOptions) {
|
|
|
31
41
|
target: object.constructor,
|
|
32
42
|
propertyName,
|
|
33
43
|
options: validationOptions,
|
|
34
|
-
constraints: [],
|
|
44
|
+
constraints: [{ optional: (validationOptions === null || validationOptions === void 0 ? void 0 : validationOptions.optional) || false }],
|
|
35
45
|
validator: IsValidEmailTypeConstraint,
|
|
36
46
|
});
|
|
37
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-valid-email-type.js","sourceRoot":"","sources":["../../../src/decorator/is-valid-email-type.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"is-valid-email-type.js","sourceRoot":"","sources":["../../../src/decorator/is-valid-email-type.ts"],"names":[],"mappings":";;;;;;;;;AAqCA,4CAYC;AAjDD,qDAMyB;AACzB,oEAA8D;AAGvD,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAAhC;QAEY,gBAAW,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAa,CAAC,CAAC;IAuB9D,CAAC;IArBC,QAAQ,CAAC,SAAc,EAAE,IAAyB;;QAChD,MAAM,QAAQ,GAAG,CAAA,MAAA,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,0CAAE,QAAQ,KAAI,KAAK,CAAC;QAExD,IAAI,QAAQ,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC,EAAE,CAAC;YAChE,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED,cAAc,CAAC,IAAyB;;QACtC,MAAM,QAAQ,GAAG,CAAA,MAAA,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,0CAAE,QAAQ,KAAI,KAAK,CAAC;QACxD,IAAI,QAAQ,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;YAClE,OAAO,IAAI,IAAI,CAAC,KAAK,4EAA4E,CAAC;QACpG,CAAC;QACD,OAAO,IACL,IAAI,CAAC,KACP,+CAA+C,IAAI,CAAC,WAAW,CAAC,IAAI,CAClE,IAAI,CACL,GAAG,CAAC;IACP,CAAC;CACF,CAAA;AAzBY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,qCAAmB,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;GACzB,0BAA0B,CAyBtC;AAED,SAAgB,gBAAgB,CAC9B,iBAA8D;IAE9D,OAAO,CAAC,MAAW,EAAE,YAAoB,EAAE,EAAE;QAC3C,IAAA,mCAAiB,EAAC;YAChB,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY;YACZ,OAAO,EAAE,iBAAiB;YAC1B,WAAW,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAA,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAE,QAAQ,KAAI,KAAK,EAAE,CAAC;YACjE,SAAS,EAAE,0BAA0B;SACtC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ValidatorConstraintInterface, ValidationArguments, ValidationOptions } from "class-validator";
|
|
2
|
+
export declare class IsValidEmailConstraint implements ValidatorConstraintInterface {
|
|
3
|
+
private readonly EMAIL_TYPES;
|
|
4
|
+
validate(value: any, args: ValidationArguments): boolean;
|
|
5
|
+
defaultMessage(args: ValidationArguments): string;
|
|
6
|
+
}
|
|
7
|
+
export declare function IsValidEmail(options?: {
|
|
8
|
+
optional: boolean;
|
|
9
|
+
}, validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.IsValidEmailConstraint = void 0;
|
|
10
|
+
exports.IsValidEmail = IsValidEmail;
|
|
11
|
+
const class_validator_1 = require("class-validator");
|
|
12
|
+
const authf_data_model_1 = require("@cryptexlabs/authf-data-model");
|
|
13
|
+
let IsValidEmailConstraint = class IsValidEmailConstraint {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.EMAIL_TYPES = Object.values(authf_data_model_1.EmailTypeEnum);
|
|
16
|
+
}
|
|
17
|
+
validate(value, args) {
|
|
18
|
+
const [optional] = args.constraints;
|
|
19
|
+
if (optional && value === null) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
return this.EMAIL_TYPES.includes(value);
|
|
23
|
+
}
|
|
24
|
+
defaultMessage(args) {
|
|
25
|
+
return `"${args.value}" is not a valid email. Choose one of the allowed email types or set it to null if optional.`;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.IsValidEmailConstraint = IsValidEmailConstraint;
|
|
29
|
+
exports.IsValidEmailConstraint = IsValidEmailConstraint = __decorate([
|
|
30
|
+
(0, class_validator_1.ValidatorConstraint)({ name: "IsValidEmail", async: false })
|
|
31
|
+
], IsValidEmailConstraint);
|
|
32
|
+
function IsValidEmail(options, validationOptions) {
|
|
33
|
+
return (object, propertyName) => {
|
|
34
|
+
(0, class_validator_1.registerDecorator)({
|
|
35
|
+
target: object.constructor,
|
|
36
|
+
propertyName,
|
|
37
|
+
options: validationOptions,
|
|
38
|
+
constraints: [(options === null || options === void 0 ? void 0 : options.optional) || false],
|
|
39
|
+
validator: IsValidEmailConstraint,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=is-valid-email.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-valid-email.js","sourceRoot":"","sources":["../../../src/decorator/is-valid-email.ts"],"names":[],"mappings":";;;;;;;;;AA4BA,oCAaC;AAzCD,qDAMyB;AACzB,oEAA8D;AAGvD,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAA5B;QACY,gBAAW,GAAa,MAAM,CAAC,MAAM,CAAC,gCAAa,CAAC,CAAC;IAcxE,CAAC;IAXC,QAAQ,CAAC,KAAU,EAAE,IAAyB;QAC5C,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC/B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,cAAc,CAAC,IAAyB;QACtC,OAAO,IAAI,IAAI,CAAC,KAAK,8FAA8F,CAAC;IACtH,CAAC;CACF,CAAA;AAfY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,qCAAmB,EAAC,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;GAC/C,sBAAsB,CAelC;AAGD,SAAgB,YAAY,CAC1B,OAA+B,EAC/B,iBAAqC;IAErC,OAAO,CAAC,MAAW,EAAE,YAAoB,EAAE,EAAE;QAC3C,IAAA,mCAAiB,EAAC;YAChB,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY;YACZ,OAAO,EAAE,iBAAiB;YAC1B,WAAW,EAAE,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,KAAI,KAAK,CAAC;YACzC,SAAS,EAAE,sBAAsB;SAClC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ValidatorConstraintInterface, ValidationArguments, ValidationOptions } from "class-validator";
|
|
2
2
|
export declare class IsValidPhoneTypeConstraint implements ValidatorConstraintInterface {
|
|
3
3
|
private readonly PHONE_TYPES;
|
|
4
|
-
validate(
|
|
4
|
+
validate(phoneType: any, args: ValidationArguments): boolean;
|
|
5
5
|
defaultMessage(args: ValidationArguments): string;
|
|
6
6
|
}
|
|
7
|
-
export declare function IsValidPhoneType(validationOptions?: ValidationOptions
|
|
7
|
+
export declare function IsValidPhoneType(validationOptions?: ValidationOptions & {
|
|
8
|
+
optional?: boolean;
|
|
9
|
+
}): (object: any, propertyName: string) => void;
|
|
@@ -14,16 +14,26 @@ let IsValidPhoneTypeConstraint = class IsValidPhoneTypeConstraint {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
this.PHONE_TYPES = Object.values(authf_data_model_1.PhoneTypeEnum);
|
|
16
16
|
}
|
|
17
|
-
validate(
|
|
18
|
-
|
|
17
|
+
validate(phoneType, args) {
|
|
18
|
+
var _a;
|
|
19
|
+
const optional = ((_a = args.constraints[0]) === null || _a === void 0 ? void 0 : _a.optional) || false;
|
|
20
|
+
if (optional && (phoneType === undefined || phoneType === null)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return this.PHONE_TYPES.includes(phoneType);
|
|
19
24
|
}
|
|
20
25
|
defaultMessage(args) {
|
|
21
|
-
|
|
26
|
+
var _a;
|
|
27
|
+
const optional = ((_a = args.constraints[0]) === null || _a === void 0 ? void 0 : _a.optional) || false;
|
|
28
|
+
if (optional && (args.value === undefined || args.value === null)) {
|
|
29
|
+
return `"${args.property}" is optional but, if defined, must be one of: ${this.PHONE_TYPES.join(", ")}.`;
|
|
30
|
+
}
|
|
31
|
+
return `"${args.value}" is not a valid phone type. Allowed types: ${this.PHONE_TYPES.join(", ")}.`;
|
|
22
32
|
}
|
|
23
33
|
};
|
|
24
34
|
exports.IsValidPhoneTypeConstraint = IsValidPhoneTypeConstraint;
|
|
25
35
|
exports.IsValidPhoneTypeConstraint = IsValidPhoneTypeConstraint = __decorate([
|
|
26
|
-
(0, class_validator_1.ValidatorConstraint)({
|
|
36
|
+
(0, class_validator_1.ValidatorConstraint)({ async: false })
|
|
27
37
|
], IsValidPhoneTypeConstraint);
|
|
28
38
|
function IsValidPhoneType(validationOptions) {
|
|
29
39
|
return (object, propertyName) => {
|
|
@@ -31,7 +41,7 @@ function IsValidPhoneType(validationOptions) {
|
|
|
31
41
|
target: object.constructor,
|
|
32
42
|
propertyName,
|
|
33
43
|
options: validationOptions,
|
|
34
|
-
constraints: [],
|
|
44
|
+
constraints: [{ optional: (validationOptions === null || validationOptions === void 0 ? void 0 : validationOptions.optional) || false }],
|
|
35
45
|
validator: IsValidPhoneTypeConstraint,
|
|
36
46
|
});
|
|
37
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-valid-phone-type.js","sourceRoot":"","sources":["../../../src/decorator/is-valid-phone-type.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"is-valid-phone-type.js","sourceRoot":"","sources":["../../../src/decorator/is-valid-phone-type.ts"],"names":[],"mappings":";;;;;;;;;AA8CA,4CAYC;AA1DD,qDAMyB;AACzB,oEAA8D;AAGvD,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAAhC;QAEY,gBAAW,GAAG,MAAM,CAAC,MAAM,CAAC,gCAAa,CAAC,CAAC;IAgC9D,CAAC;IA9BC,QAAQ,CAAC,SAAc,EAAE,IAAyB;;QAChD,MAAM,QAAQ,GAAG,CAAA,MAAA,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,0CAAE,QAAQ,KAAI,KAAK,CAAC;QAGxD,IAAI,QAAQ,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,SAAS,KA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|
export declare class IsValidUtcTimezoneConstraint implements ValidatorConstraintInterface {
|
|
3
3
|
private readonly TIMEZONES;
|
|
4
|
-
validate(timezone: any
|
|
4
|
+
validate(timezone: any): boolean;
|
|
5
5
|
defaultMessage(args: ValidationArguments): string;
|
|
6
6
|
}
|
|
7
7
|
export declare function IsValidUtcTimezone(validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
|
|
@@ -55,16 +55,16 @@ let IsValidUtcTimezoneConstraint = class IsValidUtcTimezoneConstraint {
|
|
|
55
55
|
"+14:00",
|
|
56
56
|
];
|
|
57
57
|
}
|
|
58
|
-
validate(timezone
|
|
58
|
+
validate(timezone) {
|
|
59
59
|
return this.TIMEZONES.includes(timezone);
|
|
60
60
|
}
|
|
61
61
|
defaultMessage(args) {
|
|
62
|
-
return `"${args.value}" is not a valid UTC timezone.
|
|
62
|
+
return `"${args.value}" is not a valid UTC timezone. Allowed timezones: ${this.TIMEZONES.join(", ")}.`;
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
exports.IsValidUtcTimezoneConstraint = IsValidUtcTimezoneConstraint;
|
|
66
66
|
exports.IsValidUtcTimezoneConstraint = IsValidUtcTimezoneConstraint = __decorate([
|
|
67
|
-
(0, class_validator_1.ValidatorConstraint)({
|
|
67
|
+
(0, class_validator_1.ValidatorConstraint)({ async: false })
|
|
68
68
|
], IsValidUtcTimezoneConstraint);
|
|
69
69
|
function IsValidUtcTimezone(validationOptions) {
|
|
70
70
|
return (object, propertyName) => {
|
|
@@ -72,7 +72,6 @@ function IsValidUtcTimezone(validationOptions) {
|
|
|
72
72
|
target: object.constructor,
|
|
73
73
|
propertyName,
|
|
74
74
|
options: validationOptions,
|
|
75
|
-
constraints: [],
|
|
76
75
|
validator: IsValidUtcTimezoneConstraint,
|
|
77
76
|
});
|
|
78
77
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-valid-utc-timezone.js","sourceRoot":"","sources":["../../../src/decorator/is-valid-utc-timezone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B,EAAC;YAChB,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY;YACZ,OAAO,EAAE,iBAAiB;YAC1B,SAAS,EAAE,4BAA4B;SACxC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/src/dto/email.dto.js
CHANGED
|
@@ -11,19 +11,17 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EmailDto = void 0;
|
|
13
13
|
const authf_data_model_1 = require("@cryptexlabs/authf-data-model");
|
|
14
|
-
const class_validator_1 = require("class-validator");
|
|
15
14
|
const decorator_1 = require("../decorator");
|
|
15
|
+
const is_valid_email_1 = require("../decorator/is-valid-email");
|
|
16
16
|
class EmailDto {
|
|
17
17
|
}
|
|
18
18
|
exports.EmailDto = EmailDto;
|
|
19
19
|
__decorate([
|
|
20
|
-
(0,
|
|
21
|
-
(0, class_validator_1.IsEmail)(),
|
|
20
|
+
(0, is_valid_email_1.IsValidEmail)({ optional: true }),
|
|
22
21
|
__metadata("design:type", String)
|
|
23
22
|
], EmailDto.prototype, "value", void 0);
|
|
24
23
|
__decorate([
|
|
25
|
-
(0,
|
|
26
|
-
(0, decorator_1.IsValidEmailType)(),
|
|
24
|
+
(0, decorator_1.IsValidEmailType)({ optional: true }),
|
|
27
25
|
__metadata("design:type", String)
|
|
28
26
|
], EmailDto.prototype, "type", void 0);
|
|
29
27
|
//# sourceMappingURL=email.dto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.dto.js","sourceRoot":"","sources":["../../../src/dto/email.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oEAA8E;
|
|
1
|
+
{"version":3,"file":"email.dto.js","sourceRoot":"","sources":["../../../src/dto/email.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oEAA8E;AAE9E,4CAAgD;AAChD,gEAA2D;AAE3D,MAAa,QAAQ;CAMpB;AAND,4BAMC;AAJC;IADC,IAAA,6BAAY,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;uCACZ;AAGrB;IADC,IAAA,4BAAgB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;sCACjB"}
|
package/lib/src/dto/phone.dto.js
CHANGED
|
@@ -17,13 +17,11 @@ class PhoneDto {
|
|
|
17
17
|
}
|
|
18
18
|
exports.PhoneDto = PhoneDto;
|
|
19
19
|
__decorate([
|
|
20
|
-
(0, class_validator_1.IsOptional)(),
|
|
21
20
|
(0, class_validator_1.IsString)(),
|
|
22
21
|
__metadata("design:type", String)
|
|
23
22
|
], PhoneDto.prototype, "value", void 0);
|
|
24
23
|
__decorate([
|
|
25
|
-
(0,
|
|
26
|
-
(0, decorator_1.IsValidPhoneType)(),
|
|
24
|
+
(0, decorator_1.IsValidPhoneType)({ optional: true }),
|
|
27
25
|
__metadata("design:type", String)
|
|
28
26
|
], PhoneDto.prototype, "type", void 0);
|
|
29
27
|
//# sourceMappingURL=phone.dto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone.dto.js","sourceRoot":"","sources":["../../../src/dto/phone.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oEAA8E;AAC9E,qDAAuD;AACvD,4CAAgD;AAEhD,MAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"phone.dto.js","sourceRoot":"","sources":["../../../src/dto/phone.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oEAA8E;AAC9E,qDAAuD;AACvD,4CAAgD;AAEhD,MAAa,QAAQ;CAMpB;AAND,4BAMC;AAJC;IADC,IAAA,0BAAQ,GAAE;;uCACG;AAGd;IADC,IAAA,4BAAgB,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;sCACjB"}
|
package/lib/src/dto/photo.dto.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"photo.dto.js","sourceRoot":"","sources":["../../../src/dto/photo.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAoD;AAEpD,MAAa,QAAQ;
|
|
1
|
+
{"version":3,"file":"photo.dto.js","sourceRoot":"","sources":["../../../src/dto/photo.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAAoD;AAEpD,MAAa,QAAQ;CAGpB;AAHD,4BAGC;AADC;IADC,IAAA,uBAAK,GAAE;;qCACI"}
|
package/package.json
CHANGED
|
@@ -7,27 +7,43 @@ import {
|
|
|
7
7
|
} from "class-validator";
|
|
8
8
|
import { EmailTypeEnum } from "@cryptexlabs/authf-data-model";
|
|
9
9
|
|
|
10
|
-
@ValidatorConstraint({
|
|
10
|
+
@ValidatorConstraint({ async: false })
|
|
11
11
|
export class IsValidEmailTypeConstraint
|
|
12
12
|
implements ValidatorConstraintInterface {
|
|
13
|
-
private readonly EMAIL_TYPES
|
|
13
|
+
private readonly EMAIL_TYPES = Object.values(EmailTypeEnum);
|
|
14
14
|
|
|
15
|
-
validate(
|
|
16
|
-
|
|
15
|
+
validate(emailType: any, args: ValidationArguments): boolean {
|
|
16
|
+
const optional = args.constraints[0]?.optional || false;
|
|
17
|
+
// If optional, allow null or undefined values
|
|
18
|
+
if (optional && (emailType === undefined || emailType === null)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
// Otherwise, validate against allowed EMAIL_TYPES
|
|
22
|
+
return this.EMAIL_TYPES.includes(emailType);
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
defaultMessage(args: ValidationArguments): string {
|
|
20
|
-
|
|
26
|
+
const optional = args.constraints[0]?.optional || false;
|
|
27
|
+
if (optional && (args.value === undefined || args.value === null)) {
|
|
28
|
+
return `"${args.value}" is optional, but it must either be null/undefined or a valid email type.`;
|
|
29
|
+
}
|
|
30
|
+
return `"${
|
|
31
|
+
args.value
|
|
32
|
+
}" is not a valid email type. Allowed types: ${this.EMAIL_TYPES.join(
|
|
33
|
+
", "
|
|
34
|
+
)}.`;
|
|
21
35
|
}
|
|
22
36
|
}
|
|
23
37
|
|
|
24
|
-
export function IsValidEmailType(
|
|
38
|
+
export function IsValidEmailType(
|
|
39
|
+
validationOptions?: ValidationOptions & { optional?: boolean }
|
|
40
|
+
) {
|
|
25
41
|
return (object: any, propertyName: string) => {
|
|
26
42
|
registerDecorator({
|
|
27
43
|
target: object.constructor,
|
|
28
44
|
propertyName,
|
|
29
45
|
options: validationOptions,
|
|
30
|
-
constraints: [],
|
|
46
|
+
constraints: [{ optional: validationOptions?.optional || false }],
|
|
31
47
|
validator: IsValidEmailTypeConstraint,
|
|
32
48
|
});
|
|
33
49
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ValidatorConstraint,
|
|
3
|
+
ValidatorConstraintInterface,
|
|
4
|
+
ValidationArguments,
|
|
5
|
+
registerDecorator,
|
|
6
|
+
ValidationOptions,
|
|
7
|
+
} from "class-validator";
|
|
8
|
+
import { EmailTypeEnum } from "@cryptexlabs/authf-data-model";
|
|
9
|
+
|
|
10
|
+
@ValidatorConstraint({ name: "IsValidEmail", async: false })
|
|
11
|
+
export class IsValidEmailConstraint implements ValidatorConstraintInterface {
|
|
12
|
+
private readonly EMAIL_TYPES: string[] = Object.values(EmailTypeEnum);
|
|
13
|
+
|
|
14
|
+
// Receive constraints in the validate method
|
|
15
|
+
validate(value: any, args: ValidationArguments): boolean {
|
|
16
|
+
const [optional] = args.constraints; // Get optional flag from constraints
|
|
17
|
+
if (optional && value === null) {
|
|
18
|
+
return true; // Allow null if optional is true
|
|
19
|
+
}
|
|
20
|
+
return this.EMAIL_TYPES.includes(value); // Otherwise, validate normally
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
defaultMessage(args: ValidationArguments): string {
|
|
24
|
+
return `"${args.value}" is not a valid email. Choose one of the allowed email types or set it to null if optional.`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Custom decorator allowing the use of an optional argument
|
|
29
|
+
export function IsValidEmail(
|
|
30
|
+
options?: { optional: boolean }, // Add an optional parameter to control nullability
|
|
31
|
+
validationOptions?: ValidationOptions
|
|
32
|
+
) {
|
|
33
|
+
return (object: any, propertyName: string) => {
|
|
34
|
+
registerDecorator({
|
|
35
|
+
target: object.constructor,
|
|
36
|
+
propertyName,
|
|
37
|
+
options: validationOptions,
|
|
38
|
+
constraints: [options?.optional || false], // Pass optional flag to the validator
|
|
39
|
+
validator: IsValidEmailConstraint,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -5,29 +5,54 @@ import {
|
|
|
5
5
|
registerDecorator,
|
|
6
6
|
ValidationOptions,
|
|
7
7
|
} from "class-validator";
|
|
8
|
-
import {
|
|
8
|
+
import { PhoneTypeEnum } from "@cryptexlabs/authf-data-model";
|
|
9
9
|
|
|
10
|
-
@ValidatorConstraint({
|
|
10
|
+
@ValidatorConstraint({ async: false })
|
|
11
11
|
export class IsValidPhoneTypeConstraint
|
|
12
12
|
implements ValidatorConstraintInterface {
|
|
13
|
-
private readonly PHONE_TYPES
|
|
13
|
+
private readonly PHONE_TYPES = Object.values(PhoneTypeEnum);
|
|
14
14
|
|
|
15
|
-
validate(
|
|
16
|
-
|
|
15
|
+
validate(phoneType: any, args: ValidationArguments): boolean {
|
|
16
|
+
const optional = args.constraints[0]?.optional || false;
|
|
17
|
+
|
|
18
|
+
// If the property is optional, allow null or undefined values
|
|
19
|
+
if (optional && (phoneType === undefined || phoneType === null)) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Otherwise, validate against the allowed PHONE_TYPES
|
|
24
|
+
return this.PHONE_TYPES.includes(phoneType);
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
defaultMessage(args: ValidationArguments): string {
|
|
20
|
-
|
|
28
|
+
const optional = args.constraints[0]?.optional || false;
|
|
29
|
+
|
|
30
|
+
// Provide different messages based on `optional` status
|
|
31
|
+
if (optional && (args.value === undefined || args.value === null)) {
|
|
32
|
+
return `"${
|
|
33
|
+
args.property
|
|
34
|
+
}" is optional but, if defined, must be one of: ${this.PHONE_TYPES.join(
|
|
35
|
+
", "
|
|
36
|
+
)}.`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return `"${
|
|
40
|
+
args.value
|
|
41
|
+
}" is not a valid phone type. Allowed types: ${this.PHONE_TYPES.join(
|
|
42
|
+
", "
|
|
43
|
+
)}.`;
|
|
21
44
|
}
|
|
22
45
|
}
|
|
23
46
|
|
|
24
|
-
export function IsValidPhoneType(
|
|
47
|
+
export function IsValidPhoneType(
|
|
48
|
+
validationOptions?: ValidationOptions & { optional?: boolean }
|
|
49
|
+
) {
|
|
25
50
|
return (object: any, propertyName: string) => {
|
|
26
51
|
registerDecorator({
|
|
27
52
|
target: object.constructor,
|
|
28
53
|
propertyName,
|
|
29
54
|
options: validationOptions,
|
|
30
|
-
constraints: [],
|
|
55
|
+
constraints: [{ optional: validationOptions?.optional || false }],
|
|
31
56
|
validator: IsValidPhoneTypeConstraint,
|
|
32
57
|
});
|
|
33
58
|
};
|
|
@@ -6,11 +6,10 @@ import {
|
|
|
6
6
|
ValidationOptions,
|
|
7
7
|
} from "class-validator";
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
@ValidatorConstraint({ name: "IsValidUtcTimezone", async: false })
|
|
9
|
+
@ValidatorConstraint({ async: false })
|
|
11
10
|
export class IsValidUtcTimezoneConstraint
|
|
12
11
|
implements ValidatorConstraintInterface {
|
|
13
|
-
private readonly TIMEZONES
|
|
12
|
+
private readonly TIMEZONES = [
|
|
14
13
|
"-12:00",
|
|
15
14
|
"-11:00",
|
|
16
15
|
"-10:30",
|
|
@@ -54,12 +53,16 @@ export class IsValidUtcTimezoneConstraint
|
|
|
54
53
|
"+14:00",
|
|
55
54
|
];
|
|
56
55
|
|
|
57
|
-
validate(timezone: any
|
|
56
|
+
validate(timezone: any): boolean {
|
|
58
57
|
return this.TIMEZONES.includes(timezone);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
defaultMessage(args: ValidationArguments): string {
|
|
62
|
-
return `"${
|
|
61
|
+
return `"${
|
|
62
|
+
args.value
|
|
63
|
+
}" is not a valid UTC timezone. Allowed timezones: ${this.TIMEZONES.join(
|
|
64
|
+
", "
|
|
65
|
+
)}.`;
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
|
|
@@ -69,7 +72,6 @@ export function IsValidUtcTimezone(validationOptions?: ValidationOptions) {
|
|
|
69
72
|
target: object.constructor,
|
|
70
73
|
propertyName,
|
|
71
74
|
options: validationOptions,
|
|
72
|
-
constraints: [],
|
|
73
75
|
validator: IsValidUtcTimezoneConstraint,
|
|
74
76
|
});
|
|
75
77
|
};
|
package/src/dto/email.dto.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { EmailInterface, EmailTypeEnum } from "@cryptexlabs/authf-data-model";
|
|
2
2
|
import { IsEmail, IsOptional } from "class-validator";
|
|
3
3
|
import { IsValidEmailType } from "../decorator";
|
|
4
|
+
import { IsValidEmail } from "../decorator/is-valid-email";
|
|
4
5
|
|
|
5
6
|
export class EmailDto implements EmailInterface {
|
|
6
|
-
@
|
|
7
|
-
@IsEmail()
|
|
7
|
+
@IsValidEmail({ optional: true })
|
|
8
8
|
value: string | null;
|
|
9
9
|
|
|
10
|
-
@
|
|
11
|
-
@IsValidEmailType()
|
|
10
|
+
@IsValidEmailType({ optional: true })
|
|
12
11
|
type: EmailTypeEnum;
|
|
13
12
|
}
|
package/src/dto/phone.dto.ts
CHANGED
|
@@ -3,11 +3,9 @@ import { IsOptional, IsString } from "class-validator";
|
|
|
3
3
|
import { IsValidPhoneType } from "../decorator";
|
|
4
4
|
|
|
5
5
|
export class PhoneDto implements PhoneInterface {
|
|
6
|
-
@IsOptional()
|
|
7
6
|
@IsString()
|
|
8
7
|
value: string;
|
|
9
8
|
|
|
10
|
-
@
|
|
11
|
-
@IsValidPhoneType()
|
|
9
|
+
@IsValidPhoneType({ optional: true })
|
|
12
10
|
type: PhoneTypeEnum;
|
|
13
11
|
}
|