@cryptexlabs/codex-nodejs-common 0.12.2 → 0.12.3
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 +2 -4
- package/lib/src/decorator/is-valid-email-type.js +5 -15
- package/lib/src/decorator/is-valid-email-type.js.map +1 -1
- package/lib/src/decorator/is-valid-phone-type.d.ts +2 -4
- package/lib/src/decorator/is-valid-phone-type.js +5 -15
- 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 +4 -3
- package/lib/src/decorator/is-valid-utc-timezone.js.map +1 -1
- package/lib/src/dto/email.dto.js +5 -3
- package/lib/src/dto/email.dto.js.map +1 -1
- package/lib/src/dto/phone.dto.js +3 -1
- package/lib/src/dto/phone.dto.js.map +1 -1
- package/lib/src/dto/photo.dto.js +1 -0
- package/lib/src/dto/photo.dto.js.map +1 -1
- package/lib/src/dto/profile.dto.d.ts +16 -12
- package/lib/src/dto/profile.dto.js +74 -0
- package/lib/src/dto/profile.dto.js.map +1 -1
- package/lib/src/dto/user.dto.js +7 -0
- package/lib/src/dto/user.dto.js.map +1 -1
- package/package.json +1 -1
- package/src/decorator/is-valid-email-type.ts +7 -23
- package/src/decorator/is-valid-phone-type.ts +8 -33
- package/src/decorator/is-valid-utc-timezone.ts +6 -8
- package/src/dto/email.dto.ts +4 -3
- package/src/dto/phone.dto.ts +3 -1
- package/src/dto/photo.dto.ts +1 -0
- package/src/dto/profile.dto.ts +47 -19
- package/src/dto/user.dto.ts +4 -1
- package/lib/src/decorator/is-valid-email.d.ts +0 -9
- package/lib/src/decorator/is-valid-email.js +0 -43
- package/lib/src/decorator/is-valid-email.js.map +0 -1
- package/src/decorator/is-valid-email.ts +0 -42
package/lib/package.json
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
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(timezone: any, args: ValidationArguments): boolean;
|
|
5
5
|
defaultMessage(args: ValidationArguments): string;
|
|
6
6
|
}
|
|
7
|
-
export declare function IsValidEmailType(validationOptions?: ValidationOptions
|
|
8
|
-
optional?: boolean;
|
|
9
|
-
}): (object: any, propertyName: string) => void;
|
|
7
|
+
export declare function IsValidEmailType(validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
|
|
@@ -14,26 +14,16 @@ let IsValidEmailTypeConstraint = class IsValidEmailTypeConstraint {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
this.EMAIL_TYPES = Object.values(authf_data_model_1.EmailTypeEnum);
|
|
16
16
|
}
|
|
17
|
-
validate(
|
|
18
|
-
|
|
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);
|
|
17
|
+
validate(timezone, args) {
|
|
18
|
+
return this.EMAIL_TYPES.includes(timezone);
|
|
24
19
|
}
|
|
25
20
|
defaultMessage(args) {
|
|
26
|
-
|
|
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(", ")}.`;
|
|
21
|
+
return `"${args.value}" is not a valid UTC timezone. Choose one of the allowed timezones.`;
|
|
32
22
|
}
|
|
33
23
|
};
|
|
34
24
|
exports.IsValidEmailTypeConstraint = IsValidEmailTypeConstraint;
|
|
35
25
|
exports.IsValidEmailTypeConstraint = IsValidEmailTypeConstraint = __decorate([
|
|
36
|
-
(0, class_validator_1.ValidatorConstraint)({ async: false })
|
|
26
|
+
(0, class_validator_1.ValidatorConstraint)({ name: "IsValidEmailType", async: false })
|
|
37
27
|
], IsValidEmailTypeConstraint);
|
|
38
28
|
function IsValidEmailType(validationOptions) {
|
|
39
29
|
return (object, propertyName) => {
|
|
@@ -41,7 +31,7 @@ function IsValidEmailType(validationOptions) {
|
|
|
41
31
|
target: object.constructor,
|
|
42
32
|
propertyName,
|
|
43
33
|
options: validationOptions,
|
|
44
|
-
constraints: [
|
|
34
|
+
constraints: [],
|
|
45
35
|
validator: IsValidEmailTypeConstraint,
|
|
46
36
|
});
|
|
47
37
|
};
|
|
@@ -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":";;;;;;;;;AAuBA,4CAUC;AAjCD,qDAMyB;AACzB,oEAA8D;AAGvD,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAAhC;QAEY,gBAAW,GAAa,MAAM,CAAC,MAAM,CAAC,gCAAa,CAAC,CAAC;IASxE,CAAC;IAPC,QAAQ,CAAC,QAAa,EAAE,IAAyB;QAC/C,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,cAAc,CAAC,IAAyB;QACtC,OAAO,IAAI,IAAI,CAAC,KAAK,qEAAqE,CAAC;IAC7F,CAAC;CACF,CAAA;AAXY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,qCAAmB,EAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;GACnD,0BAA0B,CAWtC;AAED,SAAgB,gBAAgB,CAAC,iBAAqC;IACpE,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,EAAE;YACf,SAAS,EAAE,0BAA0B;SACtC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
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(timezone: any, args: ValidationArguments): boolean;
|
|
5
5
|
defaultMessage(args: ValidationArguments): string;
|
|
6
6
|
}
|
|
7
|
-
export declare function IsValidPhoneType(validationOptions?: ValidationOptions
|
|
8
|
-
optional?: boolean;
|
|
9
|
-
}): (object: any, propertyName: string) => void;
|
|
7
|
+
export declare function IsValidPhoneType(validationOptions?: ValidationOptions): (object: any, propertyName: string) => void;
|
|
@@ -14,26 +14,16 @@ let IsValidPhoneTypeConstraint = class IsValidPhoneTypeConstraint {
|
|
|
14
14
|
constructor() {
|
|
15
15
|
this.PHONE_TYPES = Object.values(authf_data_model_1.PhoneTypeEnum);
|
|
16
16
|
}
|
|
17
|
-
validate(
|
|
18
|
-
|
|
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);
|
|
17
|
+
validate(timezone, args) {
|
|
18
|
+
return this.PHONE_TYPES.includes(timezone);
|
|
24
19
|
}
|
|
25
20
|
defaultMessage(args) {
|
|
26
|
-
|
|
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(", ")}.`;
|
|
21
|
+
return `"${args.value}" is not a valid UTC timezone. Choose one of the allowed timezones.`;
|
|
32
22
|
}
|
|
33
23
|
};
|
|
34
24
|
exports.IsValidPhoneTypeConstraint = IsValidPhoneTypeConstraint;
|
|
35
25
|
exports.IsValidPhoneTypeConstraint = IsValidPhoneTypeConstraint = __decorate([
|
|
36
|
-
(0, class_validator_1.ValidatorConstraint)({ async: false })
|
|
26
|
+
(0, class_validator_1.ValidatorConstraint)({ name: "IsValidPhoneType", async: false })
|
|
37
27
|
], IsValidPhoneTypeConstraint);
|
|
38
28
|
function IsValidPhoneType(validationOptions) {
|
|
39
29
|
return (object, propertyName) => {
|
|
@@ -41,7 +31,7 @@ function IsValidPhoneType(validationOptions) {
|
|
|
41
31
|
target: object.constructor,
|
|
42
32
|
propertyName,
|
|
43
33
|
options: validationOptions,
|
|
44
|
-
constraints: [
|
|
34
|
+
constraints: [],
|
|
45
35
|
validator: IsValidPhoneTypeConstraint,
|
|
46
36
|
});
|
|
47
37
|
};
|
|
@@ -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":";;;;;;;;;AAuBA,4CAUC;AAjCD,qDAMyB;AACzB,oEAA6E;AAGtE,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAAhC;QAEY,gBAAW,GAAa,MAAM,CAAC,MAAM,CAAC,gCAAa,CAAC,CAAC;IASxE,CAAC;IAPC,QAAQ,CAAC,QAAa,EAAE,IAAyB;QAC/C,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,cAAc,CAAC,IAAyB;QACtC,OAAO,IAAI,IAAI,CAAC,KAAK,qEAAqE,CAAC;IAC7F,CAAC;CACF,CAAA;AAXY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,qCAAmB,EAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;GACnD,0BAA0B,CAWtC;AAED,SAAgB,gBAAgB,CAAC,iBAAqC;IACpE,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,EAAE;YACf,SAAS,EAAE,0BAA0B;SACtC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ValidatorConstraintInterface, ValidationArguments, ValidationOptions } from "class-validator";
|
|
2
2
|
export declare class IsValidUtcTimezoneConstraint implements ValidatorConstraintInterface {
|
|
3
3
|
private readonly TIMEZONES;
|
|
4
|
-
validate(timezone: any): boolean;
|
|
4
|
+
validate(timezone: any, args: ValidationArguments): 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, args) {
|
|
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. Choose one of the allowed timezones.`;
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
exports.IsValidUtcTimezoneConstraint = IsValidUtcTimezoneConstraint;
|
|
66
66
|
exports.IsValidUtcTimezoneConstraint = IsValidUtcTimezoneConstraint = __decorate([
|
|
67
|
-
(0, class_validator_1.ValidatorConstraint)({ async: false })
|
|
67
|
+
(0, class_validator_1.ValidatorConstraint)({ name: "IsValidUtcTimezone", async: false })
|
|
68
68
|
], IsValidUtcTimezoneConstraint);
|
|
69
69
|
function IsValidUtcTimezone(validationOptions) {
|
|
70
70
|
return (object, propertyName) => {
|
|
@@ -72,6 +72,7 @@ function IsValidUtcTimezone(validationOptions) {
|
|
|
72
72
|
target: object.constructor,
|
|
73
73
|
propertyName,
|
|
74
74
|
options: validationOptions,
|
|
75
|
+
constraints: [],
|
|
75
76
|
validator: IsValidUtcTimezoneConstraint,
|
|
76
77
|
});
|
|
77
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-valid-utc-timezone.js","sourceRoot":"","sources":["../../../src/decorator/is-valid-utc-timezone.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"is-valid-utc-timezone.js","sourceRoot":"","sources":["../../../src/decorator/is-valid-utc-timezone.ts"],"names":[],"mappings":";;;;;;;;;AAiEA,gDAUC;AA3ED,qDAMyB;AAIlB,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAAlC;QAEY,cAAS,GAAa;YACrC,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;YACR,QAAQ;SACT,CAAC;IASJ,CAAC;IAPC,QAAQ,CAAC,QAAa,EAAE,IAAyB;QAC/C,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED,cAAc,CAAC,IAAyB;QACtC,OAAO,IAAI,IAAI,CAAC,KAAK,qEAAqE,CAAC;IAC7F,CAAC;CACF,CAAA;AArDY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,qCAAmB,EAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;GACrD,4BAA4B,CAqDxC;AAED,SAAgB,kBAAkB,CAAC,iBAAqC;IACtE,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,EAAE;YACf,SAAS,EAAE,4BAA4B;SACxC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/lib/src/dto/email.dto.js
CHANGED
|
@@ -11,17 +11,19 @@ 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");
|
|
14
15
|
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,
|
|
20
|
+
(0, class_validator_1.IsOptional)(),
|
|
21
|
+
(0, class_validator_1.IsEmail)(),
|
|
21
22
|
__metadata("design:type", String)
|
|
22
23
|
], EmailDto.prototype, "value", void 0);
|
|
23
24
|
__decorate([
|
|
24
|
-
(0,
|
|
25
|
+
(0, class_validator_1.IsOptional)(),
|
|
26
|
+
(0, decorator_1.IsValidEmailType)(),
|
|
25
27
|
__metadata("design:type", String)
|
|
26
28
|
], EmailDto.prototype, "type", void 0);
|
|
27
29
|
//# 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;AAC9E,qDAAsD;AACtD,4CAAgD;AAEhD,MAAa,QAAQ;CAQpB;AARD,4BAQC;AALC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,yBAAO,GAAE;;uCACW;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,4BAAgB,GAAE;;sCACC"}
|
package/lib/src/dto/phone.dto.js
CHANGED
|
@@ -17,11 +17,13 @@ class PhoneDto {
|
|
|
17
17
|
}
|
|
18
18
|
exports.PhoneDto = PhoneDto;
|
|
19
19
|
__decorate([
|
|
20
|
+
(0, class_validator_1.IsOptional)(),
|
|
20
21
|
(0, class_validator_1.IsString)(),
|
|
21
22
|
__metadata("design:type", String)
|
|
22
23
|
], PhoneDto.prototype, "value", void 0);
|
|
23
24
|
__decorate([
|
|
24
|
-
(0,
|
|
25
|
+
(0, class_validator_1.IsOptional)(),
|
|
26
|
+
(0, decorator_1.IsValidPhoneType)(),
|
|
25
27
|
__metadata("design:type", String)
|
|
26
28
|
], PhoneDto.prototype, "type", void 0);
|
|
27
29
|
//# 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;CAQpB;AARD,4BAQC;AALC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;uCACG;AAId;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,4BAAgB,GAAE;;sCACC"}
|
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;CAIpB;AAJD,4BAIC;AADC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,uBAAK,GAAE;;qCACI"}
|
|
@@ -3,18 +3,22 @@ import { EmailDto } from "./email.dto";
|
|
|
3
3
|
import { PhoneDto } from "./phone.dto";
|
|
4
4
|
import { PhotoDto } from "./photo.dto";
|
|
5
5
|
import { NameDto } from "./name.dto";
|
|
6
|
+
declare class EmailsDto {
|
|
7
|
+
primary: EmailDto | null;
|
|
8
|
+
other: EmailDto[];
|
|
9
|
+
}
|
|
10
|
+
declare class PhonesDto {
|
|
11
|
+
primary: PhoneDto | null;
|
|
12
|
+
other: PhoneDto[];
|
|
13
|
+
}
|
|
14
|
+
declare class PhotosDto {
|
|
15
|
+
primary: PhotoDto | null;
|
|
16
|
+
other: PhotoDto[];
|
|
17
|
+
}
|
|
6
18
|
export declare class ProfileDto implements ProfileInterface {
|
|
7
|
-
email:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
phone: {
|
|
12
|
-
primary: PhoneDto | null;
|
|
13
|
-
other: PhoneDto[];
|
|
14
|
-
};
|
|
15
|
-
photo: {
|
|
16
|
-
primary: PhotoDto | null;
|
|
17
|
-
other: PhotoDto[];
|
|
18
|
-
};
|
|
19
|
+
email: EmailsDto;
|
|
20
|
+
phone: PhonesDto;
|
|
21
|
+
photo: PhotosDto;
|
|
19
22
|
name: NameDto;
|
|
20
23
|
}
|
|
24
|
+
export {};
|
|
@@ -1,7 +1,81 @@
|
|
|
1
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
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.ProfileDto = void 0;
|
|
13
|
+
const email_dto_1 = require("./email.dto");
|
|
14
|
+
const phone_dto_1 = require("./phone.dto");
|
|
15
|
+
const photo_dto_1 = require("./photo.dto");
|
|
16
|
+
const name_dto_1 = require("./name.dto");
|
|
17
|
+
const class_validator_1 = require("class-validator");
|
|
18
|
+
const class_transformer_1 = require("class-transformer");
|
|
19
|
+
class EmailsDto {
|
|
20
|
+
}
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, class_validator_1.ValidateNested)(),
|
|
23
|
+
(0, class_transformer_1.Type)(() => email_dto_1.EmailDto),
|
|
24
|
+
__metadata("design:type", email_dto_1.EmailDto)
|
|
25
|
+
], EmailsDto.prototype, "primary", void 0);
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, class_validator_1.IsArray)(),
|
|
28
|
+
(0, class_validator_1.ValidateNested)({ each: true }),
|
|
29
|
+
(0, class_transformer_1.Type)(() => email_dto_1.EmailDto),
|
|
30
|
+
__metadata("design:type", Array)
|
|
31
|
+
], EmailsDto.prototype, "other", void 0);
|
|
32
|
+
class PhonesDto {
|
|
33
|
+
}
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, class_validator_1.ValidateNested)(),
|
|
36
|
+
(0, class_transformer_1.Type)(() => phone_dto_1.PhoneDto),
|
|
37
|
+
__metadata("design:type", phone_dto_1.PhoneDto)
|
|
38
|
+
], PhonesDto.prototype, "primary", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, class_validator_1.IsArray)(),
|
|
41
|
+
(0, class_validator_1.ValidateNested)({ each: true }),
|
|
42
|
+
(0, class_transformer_1.Type)(() => phone_dto_1.PhoneDto),
|
|
43
|
+
__metadata("design:type", Array)
|
|
44
|
+
], PhonesDto.prototype, "other", void 0);
|
|
45
|
+
class PhotosDto {
|
|
46
|
+
}
|
|
47
|
+
__decorate([
|
|
48
|
+
(0, class_validator_1.ValidateNested)(),
|
|
49
|
+
(0, class_transformer_1.Type)(() => photo_dto_1.PhotoDto),
|
|
50
|
+
__metadata("design:type", photo_dto_1.PhotoDto)
|
|
51
|
+
], PhotosDto.prototype, "primary", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, class_validator_1.IsArray)(),
|
|
54
|
+
(0, class_validator_1.ValidateNested)({ each: true }),
|
|
55
|
+
(0, class_transformer_1.Type)(() => photo_dto_1.PhotoDto),
|
|
56
|
+
__metadata("design:type", Array)
|
|
57
|
+
], PhotosDto.prototype, "other", void 0);
|
|
4
58
|
class ProfileDto {
|
|
5
59
|
}
|
|
6
60
|
exports.ProfileDto = ProfileDto;
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, class_validator_1.ValidateNested)(),
|
|
63
|
+
(0, class_transformer_1.Type)(() => EmailsDto),
|
|
64
|
+
__metadata("design:type", EmailsDto)
|
|
65
|
+
], ProfileDto.prototype, "email", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
(0, class_validator_1.ValidateNested)(),
|
|
68
|
+
(0, class_transformer_1.Type)(() => PhonesDto),
|
|
69
|
+
__metadata("design:type", PhonesDto)
|
|
70
|
+
], ProfileDto.prototype, "phone", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, class_validator_1.ValidateNested)(),
|
|
73
|
+
(0, class_transformer_1.Type)(() => PhotosDto),
|
|
74
|
+
__metadata("design:type", PhotosDto)
|
|
75
|
+
], ProfileDto.prototype, "photo", void 0);
|
|
76
|
+
__decorate([
|
|
77
|
+
(0, class_validator_1.ValidateNested)(),
|
|
78
|
+
(0, class_transformer_1.Type)(() => name_dto_1.NameDto),
|
|
79
|
+
__metadata("design:type", name_dto_1.NameDto)
|
|
80
|
+
], ProfileDto.prototype, "name", void 0);
|
|
7
81
|
//# sourceMappingURL=profile.dto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.dto.js","sourceRoot":"","sources":["../../../src/dto/profile.dto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"profile.dto.js","sourceRoot":"","sources":["../../../src/dto/profile.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAAuC;AACvC,2CAAuC;AACvC,2CAAuC;AACvC,yCAAqC;AACrC,qDAA0D;AAC1D,yDAAyC;AAEzC,MAAM,SAAS;CASd;AANC;IAFC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,oBAAQ,CAAC;8BACZ,oBAAQ;0CAAQ;AAKzB;IAHC,IAAA,yBAAO,GAAE;IACT,IAAA,gCAAc,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,oBAAQ,CAAC;;wCACH;AAGpB,MAAM,SAAS;CASd;AANC;IAFC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,oBAAQ,CAAC;8BACZ,oBAAQ;0CAAQ;AAKzB;IAHC,IAAA,yBAAO,GAAE;IACT,IAAA,gCAAc,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,oBAAQ,CAAC;;wCACH;AAGpB,MAAM,SAAS;CASd;AANC;IAFC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,oBAAQ,CAAC;8BACZ,oBAAQ;0CAAQ;AAKzB;IAHC,IAAA,yBAAO,GAAE;IACT,IAAA,gCAAc,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,oBAAQ,CAAC;;wCACH;AAGpB,MAAa,UAAU;CAgBtB;AAhBD,gCAgBC;AAbC;IAFC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,SAAS,CAAC;8BACf,SAAS;yCAAC;AAIjB;IAFC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,SAAS,CAAC;8BACf,SAAS;yCAAC;AAIjB;IAFC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,SAAS,CAAC;8BACf,SAAS;yCAAC;AAIjB;IAFC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,kBAAO,CAAC;8BACd,kBAAO;wCAAC"}
|
package/lib/src/dto/user.dto.js
CHANGED
|
@@ -11,7 +11,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.UserDto = void 0;
|
|
13
13
|
const class_validator_1 = require("class-validator");
|
|
14
|
+
const profile_dto_1 = require("./profile.dto");
|
|
14
15
|
const decorator_1 = require("../decorator");
|
|
16
|
+
const class_transformer_1 = require("class-transformer");
|
|
15
17
|
class UserDto {
|
|
16
18
|
}
|
|
17
19
|
exports.UserDto = UserDto;
|
|
@@ -19,6 +21,11 @@ __decorate([
|
|
|
19
21
|
(0, class_validator_1.IsString)(),
|
|
20
22
|
__metadata("design:type", String)
|
|
21
23
|
], UserDto.prototype, "username", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, class_validator_1.ValidateNested)(),
|
|
26
|
+
(0, class_transformer_1.Type)(() => profile_dto_1.ProfileDto),
|
|
27
|
+
__metadata("design:type", profile_dto_1.ProfileDto)
|
|
28
|
+
], UserDto.prototype, "profile", void 0);
|
|
22
29
|
__decorate([
|
|
23
30
|
(0, decorator_1.IsValidUtcTimezone)(),
|
|
24
31
|
__metadata("design:type", String)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.dto.js","sourceRoot":"","sources":["../../../src/dto/user.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"user.dto.js","sourceRoot":"","sources":["../../../src/dto/user.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,qDAA2D;AAC3D,+CAA2C;AAC3C,4CAAkD;AAClD,yDAAyC;AAEzC,MAAa,OAAO;CAUnB;AAVD,0BAUC;AARC;IADC,IAAA,0BAAQ,GAAE;;yCACM;AAIjB;IAFC,IAAA,gCAAc,GAAE;IAChB,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,wBAAU,CAAC;8BACd,wBAAU;wCAAC;AAGpB;IADC,IAAA,8BAAkB,GAAE;;yCACC"}
|
package/package.json
CHANGED
|
@@ -7,43 +7,27 @@ import {
|
|
|
7
7
|
} from "class-validator";
|
|
8
8
|
import { EmailTypeEnum } from "@cryptexlabs/authf-data-model";
|
|
9
9
|
|
|
10
|
-
@ValidatorConstraint({ async: false })
|
|
10
|
+
@ValidatorConstraint({ name: "IsValidEmailType", async: false })
|
|
11
11
|
export class IsValidEmailTypeConstraint
|
|
12
12
|
implements ValidatorConstraintInterface {
|
|
13
|
-
private readonly EMAIL_TYPES = Object.values(EmailTypeEnum);
|
|
13
|
+
private readonly EMAIL_TYPES: string[] = Object.values(EmailTypeEnum);
|
|
14
14
|
|
|
15
|
-
validate(
|
|
16
|
-
|
|
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);
|
|
15
|
+
validate(timezone: any, args: ValidationArguments): boolean {
|
|
16
|
+
return this.EMAIL_TYPES.includes(timezone);
|
|
23
17
|
}
|
|
24
18
|
|
|
25
19
|
defaultMessage(args: ValidationArguments): string {
|
|
26
|
-
|
|
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
|
-
)}.`;
|
|
20
|
+
return `"${args.value}" is not a valid UTC timezone. Choose one of the allowed timezones.`;
|
|
35
21
|
}
|
|
36
22
|
}
|
|
37
23
|
|
|
38
|
-
export function IsValidEmailType(
|
|
39
|
-
validationOptions?: ValidationOptions & { optional?: boolean }
|
|
40
|
-
) {
|
|
24
|
+
export function IsValidEmailType(validationOptions?: ValidationOptions) {
|
|
41
25
|
return (object: any, propertyName: string) => {
|
|
42
26
|
registerDecorator({
|
|
43
27
|
target: object.constructor,
|
|
44
28
|
propertyName,
|
|
45
29
|
options: validationOptions,
|
|
46
|
-
constraints: [
|
|
30
|
+
constraints: [],
|
|
47
31
|
validator: IsValidEmailTypeConstraint,
|
|
48
32
|
});
|
|
49
33
|
};
|
|
@@ -5,54 +5,29 @@ import {
|
|
|
5
5
|
registerDecorator,
|
|
6
6
|
ValidationOptions,
|
|
7
7
|
} from "class-validator";
|
|
8
|
-
import { PhoneTypeEnum } from "@cryptexlabs/authf-data-model";
|
|
8
|
+
import { EmailTypeEnum, PhoneTypeEnum } from "@cryptexlabs/authf-data-model";
|
|
9
9
|
|
|
10
|
-
@ValidatorConstraint({ async: false })
|
|
10
|
+
@ValidatorConstraint({ name: "IsValidPhoneType", async: false })
|
|
11
11
|
export class IsValidPhoneTypeConstraint
|
|
12
12
|
implements ValidatorConstraintInterface {
|
|
13
|
-
private readonly PHONE_TYPES = Object.values(PhoneTypeEnum);
|
|
13
|
+
private readonly PHONE_TYPES: string[] = Object.values(PhoneTypeEnum);
|
|
14
14
|
|
|
15
|
-
validate(
|
|
16
|
-
|
|
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);
|
|
15
|
+
validate(timezone: any, args: ValidationArguments): boolean {
|
|
16
|
+
return this.PHONE_TYPES.includes(timezone);
|
|
25
17
|
}
|
|
26
18
|
|
|
27
19
|
defaultMessage(args: ValidationArguments): string {
|
|
28
|
-
|
|
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
|
-
)}.`;
|
|
20
|
+
return `"${args.value}" is not a valid UTC timezone. Choose one of the allowed timezones.`;
|
|
44
21
|
}
|
|
45
22
|
}
|
|
46
23
|
|
|
47
|
-
export function IsValidPhoneType(
|
|
48
|
-
validationOptions?: ValidationOptions & { optional?: boolean }
|
|
49
|
-
) {
|
|
24
|
+
export function IsValidPhoneType(validationOptions?: ValidationOptions) {
|
|
50
25
|
return (object: any, propertyName: string) => {
|
|
51
26
|
registerDecorator({
|
|
52
27
|
target: object.constructor,
|
|
53
28
|
propertyName,
|
|
54
29
|
options: validationOptions,
|
|
55
|
-
constraints: [
|
|
30
|
+
constraints: [],
|
|
56
31
|
validator: IsValidPhoneTypeConstraint,
|
|
57
32
|
});
|
|
58
33
|
};
|
|
@@ -6,10 +6,11 @@ import {
|
|
|
6
6
|
ValidationOptions,
|
|
7
7
|
} from "class-validator";
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// Step 1: Define the custom validator
|
|
10
|
+
@ValidatorConstraint({ name: "IsValidUtcTimezone", async: false })
|
|
10
11
|
export class IsValidUtcTimezoneConstraint
|
|
11
12
|
implements ValidatorConstraintInterface {
|
|
12
|
-
private readonly TIMEZONES = [
|
|
13
|
+
private readonly TIMEZONES: string[] = [
|
|
13
14
|
"-12:00",
|
|
14
15
|
"-11:00",
|
|
15
16
|
"-10:30",
|
|
@@ -53,16 +54,12 @@ export class IsValidUtcTimezoneConstraint
|
|
|
53
54
|
"+14:00",
|
|
54
55
|
];
|
|
55
56
|
|
|
56
|
-
validate(timezone: any): boolean {
|
|
57
|
+
validate(timezone: any, args: ValidationArguments): boolean {
|
|
57
58
|
return this.TIMEZONES.includes(timezone);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
defaultMessage(args: ValidationArguments): string {
|
|
61
|
-
return `"${
|
|
62
|
-
args.value
|
|
63
|
-
}" is not a valid UTC timezone. Allowed timezones: ${this.TIMEZONES.join(
|
|
64
|
-
", "
|
|
65
|
-
)}.`;
|
|
62
|
+
return `"${args.value}" is not a valid UTC timezone. Choose one of the allowed timezones.`;
|
|
66
63
|
}
|
|
67
64
|
}
|
|
68
65
|
|
|
@@ -72,6 +69,7 @@ export function IsValidUtcTimezone(validationOptions?: ValidationOptions) {
|
|
|
72
69
|
target: object.constructor,
|
|
73
70
|
propertyName,
|
|
74
71
|
options: validationOptions,
|
|
72
|
+
constraints: [],
|
|
75
73
|
validator: IsValidUtcTimezoneConstraint,
|
|
76
74
|
});
|
|
77
75
|
};
|
package/src/dto/email.dto.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
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";
|
|
5
4
|
|
|
6
5
|
export class EmailDto implements EmailInterface {
|
|
7
|
-
@
|
|
6
|
+
@IsOptional()
|
|
7
|
+
@IsEmail()
|
|
8
8
|
value: string | null;
|
|
9
9
|
|
|
10
|
-
@
|
|
10
|
+
@IsOptional()
|
|
11
|
+
@IsValidEmailType()
|
|
11
12
|
type: EmailTypeEnum;
|
|
12
13
|
}
|
package/src/dto/phone.dto.ts
CHANGED
|
@@ -3,9 +3,11 @@ import { IsOptional, IsString } from "class-validator";
|
|
|
3
3
|
import { IsValidPhoneType } from "../decorator";
|
|
4
4
|
|
|
5
5
|
export class PhoneDto implements PhoneInterface {
|
|
6
|
+
@IsOptional()
|
|
6
7
|
@IsString()
|
|
7
8
|
value: string;
|
|
8
9
|
|
|
9
|
-
@
|
|
10
|
+
@IsOptional()
|
|
11
|
+
@IsValidPhoneType()
|
|
10
12
|
type: PhoneTypeEnum;
|
|
11
13
|
}
|
package/src/dto/photo.dto.ts
CHANGED
package/src/dto/profile.dto.ts
CHANGED
|
@@ -1,30 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EmailInterface,
|
|
3
|
-
NameInterface,
|
|
4
|
-
PhoneInterface,
|
|
5
|
-
PhotoInterface,
|
|
6
|
-
ProfileInterface,
|
|
7
|
-
} from "@cryptexlabs/authf-data-model";
|
|
1
|
+
import { ProfileInterface } from "@cryptexlabs/authf-data-model";
|
|
8
2
|
import { EmailDto } from "./email.dto";
|
|
9
3
|
import { PhoneDto } from "./phone.dto";
|
|
10
4
|
import { PhotoDto } from "./photo.dto";
|
|
11
5
|
import { NameDto } from "./name.dto";
|
|
6
|
+
import { ValidateNested, IsArray } from "class-validator";
|
|
7
|
+
import { Type } from "class-transformer";
|
|
8
|
+
|
|
9
|
+
class EmailsDto {
|
|
10
|
+
@ValidateNested()
|
|
11
|
+
@Type(() => EmailDto)
|
|
12
|
+
primary: EmailDto | null;
|
|
13
|
+
|
|
14
|
+
@IsArray()
|
|
15
|
+
@ValidateNested({ each: true })
|
|
16
|
+
@Type(() => EmailDto)
|
|
17
|
+
other: EmailDto[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class PhonesDto {
|
|
21
|
+
@ValidateNested()
|
|
22
|
+
@Type(() => PhoneDto)
|
|
23
|
+
primary: PhoneDto | null;
|
|
24
|
+
|
|
25
|
+
@IsArray()
|
|
26
|
+
@ValidateNested({ each: true })
|
|
27
|
+
@Type(() => PhoneDto)
|
|
28
|
+
other: PhoneDto[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class PhotosDto {
|
|
32
|
+
@ValidateNested()
|
|
33
|
+
@Type(() => PhotoDto)
|
|
34
|
+
primary: PhotoDto | null;
|
|
35
|
+
|
|
36
|
+
@IsArray()
|
|
37
|
+
@ValidateNested({ each: true })
|
|
38
|
+
@Type(() => PhotoDto)
|
|
39
|
+
other: PhotoDto[];
|
|
40
|
+
}
|
|
12
41
|
|
|
13
42
|
export class ProfileDto implements ProfileInterface {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
43
|
+
@ValidateNested()
|
|
44
|
+
@Type(() => EmailsDto)
|
|
45
|
+
email: EmailsDto;
|
|
18
46
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
47
|
+
@ValidateNested()
|
|
48
|
+
@Type(() => PhonesDto)
|
|
49
|
+
phone: PhonesDto;
|
|
23
50
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
51
|
+
@ValidateNested()
|
|
52
|
+
@Type(() => PhotosDto)
|
|
53
|
+
photo: PhotosDto;
|
|
28
54
|
|
|
55
|
+
@ValidateNested()
|
|
56
|
+
@Type(() => NameDto)
|
|
29
57
|
name: NameDto;
|
|
30
58
|
}
|
package/src/dto/user.dto.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { UserInterface, UtcTimezone } from "@cryptexlabs/authf-data-model";
|
|
2
|
-
import { IsString } from "class-validator";
|
|
2
|
+
import { IsString, ValidateNested } from "class-validator";
|
|
3
3
|
import { ProfileDto } from "./profile.dto";
|
|
4
4
|
import { IsValidUtcTimezone } from "../decorator";
|
|
5
|
+
import { Type } from "class-transformer";
|
|
5
6
|
|
|
6
7
|
export class UserDto implements UserInterface {
|
|
7
8
|
@IsString()
|
|
8
9
|
username: string;
|
|
9
10
|
|
|
11
|
+
@ValidateNested()
|
|
12
|
+
@Type(() => ProfileDto)
|
|
10
13
|
profile: ProfileDto;
|
|
11
14
|
|
|
12
15
|
@IsValidUtcTimezone()
|
|
@@ -1,9 +0,0 @@
|
|
|
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;
|
|
@@ -1,43 +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
|
-
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
|
|
@@ -1 +0,0 @@
|
|
|
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,42 +0,0 @@
|
|
|
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
|
-
}
|