grm-shared-library 1.1.183 → 1.1.185
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/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/modules/auth/dtos/login-mobile-user.dto.js +15 -3
- package/dist/cjs/modules/auth/dtos/login-mobile-user.dto.js.map +1 -1
- package/dist/cjs/modules/auth/dtos/register-mobile-user.dto.js +15 -3
- package/dist/cjs/modules/auth/dtos/register-mobile-user.dto.js.map +1 -1
- package/dist/cjs/modules/auth/dtos/register.dto.js +15 -3
- package/dist/cjs/modules/auth/dtos/register.dto.js.map +1 -1
- package/dist/cjs/modules/auth/dtos/resend-otp.dto.js +15 -3
- package/dist/cjs/modules/auth/dtos/resend-otp.dto.js.map +1 -1
- package/dist/cjs/modules/auth/dtos/send-otp.dto.js +15 -3
- package/dist/cjs/modules/auth/dtos/send-otp.dto.js.map +1 -1
- package/dist/cjs/modules/phone/index.js +23 -0
- package/dist/cjs/modules/phone/index.js.map +1 -0
- package/dist/cjs/modules/phone/interfaces/normalized-phone.js +3 -0
- package/dist/cjs/modules/phone/interfaces/normalized-phone.js.map +1 -0
- package/dist/cjs/modules/phone/phone.util.js +92 -0
- package/dist/cjs/modules/phone/phone.util.js.map +1 -0
- package/dist/cjs/modules/phone/validators/is-supported-phone-number.decorator.js +39 -0
- package/dist/cjs/modules/phone/validators/is-supported-phone-number.decorator.js.map +1 -0
- package/dist/cjs/modules/user/dtos/create-user.dto.js +15 -3
- package/dist/cjs/modules/user/dtos/create-user.dto.js.map +1 -1
- package/dist/cjs/modules/user/dtos/guardian.dto.js +15 -3
- package/dist/cjs/modules/user/dtos/guardian.dto.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/modules/auth/dtos/login-mobile-user.dto.js +17 -5
- package/dist/esm/modules/auth/dtos/login-mobile-user.dto.js.map +1 -1
- package/dist/esm/modules/auth/dtos/register-mobile-user.dto.js +17 -5
- package/dist/esm/modules/auth/dtos/register-mobile-user.dto.js.map +1 -1
- package/dist/esm/modules/auth/dtos/register.dto.js +16 -4
- package/dist/esm/modules/auth/dtos/register.dto.js.map +1 -1
- package/dist/esm/modules/auth/dtos/resend-otp.dto.js +16 -4
- package/dist/esm/modules/auth/dtos/resend-otp.dto.js.map +1 -1
- package/dist/esm/modules/auth/dtos/send-otp.dto.js +16 -4
- package/dist/esm/modules/auth/dtos/send-otp.dto.js.map +1 -1
- package/dist/esm/modules/phone/index.js +7 -0
- package/dist/esm/modules/phone/index.js.map +1 -0
- package/dist/esm/modules/phone/interfaces/normalized-phone.js +2 -0
- package/dist/esm/modules/phone/interfaces/normalized-phone.js.map +1 -0
- package/dist/esm/modules/phone/phone.util.js +86 -0
- package/dist/esm/modules/phone/phone.util.js.map +1 -0
- package/dist/esm/modules/phone/validators/is-supported-phone-number.decorator.js +36 -0
- package/dist/esm/modules/phone/validators/is-supported-phone-number.decorator.js.map +1 -0
- package/dist/esm/modules/user/dtos/create-user.dto.js +16 -4
- package/dist/esm/modules/user/dtos/create-user.dto.js.map +1 -1
- package/dist/esm/modules/user/dtos/guardian.dto.js +16 -4
- package/dist/esm/modules/user/dtos/guardian.dto.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/modules/auth/dtos/login-mobile-user.dto.d.ts +2 -0
- package/dist/types/modules/auth/dtos/register-mobile-user.dto.d.ts +2 -0
- package/dist/types/modules/auth/dtos/register.dto.d.ts +2 -0
- package/dist/types/modules/auth/dtos/resend-otp.dto.d.ts +2 -0
- package/dist/types/modules/auth/dtos/send-otp.dto.d.ts +2 -0
- package/dist/types/modules/phone/index.d.ts +3 -0
- package/dist/types/modules/phone/interfaces/normalized-phone.d.ts +22 -0
- package/dist/types/modules/phone/phone.util.d.ts +20 -0
- package/dist/types/modules/phone/validators/is-supported-phone-number.decorator.d.ts +12 -0
- package/dist/types/modules/user/dtos/create-user.dto.d.ts +2 -0
- package/dist/types/modules/user/dtos/guardian.dto.d.ts +2 -0
- package/dist/types/modules/user/interfaces/user.d.ts +6 -0
- package/package.json +3 -2
|
@@ -7,9 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { IsEmail, IsEnum, IsNotEmpty, IsNumber,
|
|
11
|
-
import { ApiProperty } from "@nestjs/swagger";
|
|
10
|
+
import { IsEmail, IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString } from "class-validator";
|
|
11
|
+
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
12
12
|
import { IncidentAppId } from "../../incident";
|
|
13
|
+
import { CountryCode } from "../../country/enums/country-code.enum";
|
|
14
|
+
import { IsSupportedPhoneNumber } from "../../phone/validators/is-supported-phone-number.decorator";
|
|
13
15
|
export class RegisterMobileUserDto {
|
|
14
16
|
}
|
|
15
17
|
__decorate([
|
|
@@ -43,14 +45,24 @@ __decorate([
|
|
|
43
45
|
], RegisterMobileUserDto.prototype, "email", void 0);
|
|
44
46
|
__decorate([
|
|
45
47
|
ApiProperty({
|
|
46
|
-
description: 'Phone number
|
|
47
|
-
example: '+
|
|
48
|
+
description: 'Phone number in E.164 format (e.g. +254712345678), or national format when countryCode is provided',
|
|
49
|
+
example: '+254712345678',
|
|
48
50
|
format: 'phone'
|
|
49
51
|
}),
|
|
50
|
-
|
|
52
|
+
IsSupportedPhoneNumber(),
|
|
51
53
|
IsNotEmpty(),
|
|
52
54
|
__metadata("design:type", String)
|
|
53
55
|
], RegisterMobileUserDto.prototype, "phoneNumber", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
ApiPropertyOptional({
|
|
58
|
+
description: 'ISO 3166-1 alpha-2 country code for the phone number (KE, UG, TZ). Required when phoneNumber is in national format; defaults to KE.',
|
|
59
|
+
enum: CountryCode,
|
|
60
|
+
example: CountryCode.KE
|
|
61
|
+
}),
|
|
62
|
+
IsEnum(CountryCode),
|
|
63
|
+
IsOptional(),
|
|
64
|
+
__metadata("design:type", String)
|
|
65
|
+
], RegisterMobileUserDto.prototype, "countryCode", void 0);
|
|
54
66
|
__decorate([
|
|
55
67
|
ApiProperty({
|
|
56
68
|
description: 'ID of the control centre the user belongs to',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-mobile-user.dto.js","sourceRoot":"","sources":["../../../../../src/modules/auth/dtos/register-mobile-user.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"register-mobile-user.dto.js","sourceRoot":"","sources":["../../../../../src/modules/auth/dtos/register-mobile-user.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAC;AAEpG,MAAM,OAAO,qBAAqB;CA4DjC;AApDG;IAPC,WAAW,CAAC;QACT,WAAW,EAAE,mDAAmD;QAChE,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,aAAa,CAAC,KAAK;KAC/B,CAAC;IACD,MAAM,CAAC,aAAa,CAAC;IACrB,UAAU,EAAE;;oDACS;AAQtB;IANC,WAAW,CAAC;QACT,WAAW,EAAE,8BAA8B;QAC3C,OAAO,EAAE,UAAU;KACtB,CAAC;IACD,QAAQ,EAAE;IACV,UAAU,EAAE;;mDACC;AASd;IAPC,WAAW,CAAC;QACT,WAAW,EAAE,kCAAkC;QAC/C,OAAO,EAAE,sBAAsB;QAC/B,MAAM,EAAE,OAAO;KAClB,CAAC;IACD,OAAO,EAAE;IACT,UAAU,EAAE;;oDACE;AASf;IAPC,WAAW,CAAC;QACT,WAAW,EAAE,oGAAoG;QACjH,OAAO,EAAE,eAAe;QACxB,MAAM,EAAE,OAAO;KAClB,CAAC;IACD,sBAAsB,EAAE;IACxB,UAAU,EAAE;;0DACQ;AASrB;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,qIAAqI;QAClJ,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW,CAAC,EAAE;KAC1B,CAAC;IACD,MAAM,CAAC,WAAW,CAAC;IACnB,UAAU,EAAE;;0DACa;AAQ1B;IANC,WAAW,CAAC;QACT,WAAW,EAAE,8CAA8C;QAC3D,OAAO,EAAE,GAAG;KACf,CAAC;IACD,QAAQ,EAAE;IACV,UAAU,EAAE;;8DACY;AAQzB;IANC,WAAW,CAAC;QACT,WAAW,EAAE,4CAA4C;QACzD,OAAO,EAAE,GAAG;KACf,CAAC;IACD,QAAQ,EAAE;IACV,UAAU,EAAE;;6DACW"}
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { IsArray, IsEmail, IsEnum, IsNotEmpty, IsOptional,
|
|
10
|
+
import { IsArray, IsEmail, IsEnum, IsNotEmpty, IsOptional, IsString, IsUrl, Matches, MaxLength, MinLength, ValidateNested } from "class-validator";
|
|
11
11
|
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
12
12
|
import { MapAddressDto } from "../../common";
|
|
13
13
|
import { Roles } from "../../role";
|
|
@@ -16,6 +16,8 @@ import { PASSWORD_ERROR_MESSAGE, PASSWORD_REGEX } from "../../common/constants/p
|
|
|
16
16
|
import { Type } from "class-transformer";
|
|
17
17
|
import { OrganizationType } from "../../organization/enums/org-type.enum";
|
|
18
18
|
import { IncidentAppId, IncidentClass } from "../../incident";
|
|
19
|
+
import { CountryCode } from "../../country/enums/country-code.enum";
|
|
20
|
+
import { IsSupportedPhoneNumber } from "../../phone/validators/is-supported-phone-number.decorator";
|
|
19
21
|
export class RegisterDto {
|
|
20
22
|
}
|
|
21
23
|
__decorate([
|
|
@@ -66,16 +68,26 @@ __decorate([
|
|
|
66
68
|
], RegisterDto.prototype, "email", void 0);
|
|
67
69
|
__decorate([
|
|
68
70
|
ApiProperty({
|
|
69
|
-
description: 'Phone number
|
|
70
|
-
example: '+
|
|
71
|
+
description: 'Phone number in E.164 format (e.g. +254712345678), or national format when countryCode is provided',
|
|
72
|
+
example: '+254712345678',
|
|
71
73
|
format: 'phone',
|
|
72
74
|
maxLength: 20
|
|
73
75
|
}),
|
|
74
|
-
|
|
76
|
+
IsSupportedPhoneNumber(),
|
|
75
77
|
MaxLength(20),
|
|
76
78
|
IsNotEmpty(),
|
|
77
79
|
__metadata("design:type", String)
|
|
78
80
|
], RegisterDto.prototype, "phoneNumber", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
ApiPropertyOptional({
|
|
83
|
+
description: 'ISO 3166-1 alpha-2 country code for the phone number (KE, UG, TZ). Required when phoneNumber is in national format; defaults to KE.',
|
|
84
|
+
enum: CountryCode,
|
|
85
|
+
example: CountryCode.KE
|
|
86
|
+
}),
|
|
87
|
+
IsEnum(CountryCode),
|
|
88
|
+
IsOptional(),
|
|
89
|
+
__metadata("design:type", String)
|
|
90
|
+
], RegisterDto.prototype, "countryCode", void 0);
|
|
79
91
|
__decorate([
|
|
80
92
|
ApiPropertyOptional({
|
|
81
93
|
description: 'User roles (optional)',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.dto.js","sourceRoot":"","sources":["../../../../../src/modules/auth/dtos/register.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"register.dto.js","sourceRoot":"","sources":["../../../../../src/modules/auth/dtos/register.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACnJ,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AACrG,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAC;AAEpG,MAAM,OAAO,WAAW;CAoIvB;AA5HG;IAPC,WAAW,CAAC;QACT,WAAW,EAAE,4CAA4C;QACzD,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,aAAa,CAAC,GAAG;KAC7B,CAAC;IACD,MAAM,CAAC,aAAa,CAAC;IACrB,UAAU,EAAE;;0CACS;AAStB;IAPC,WAAW,CAAC;QACT,WAAW,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gBAAgB,CAAC;IACxB,UAAU,EAAE;;4CACc"}
|
|
@@ -7,9 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { IsEmail, IsEnum, IsNotEmpty, IsOptional,
|
|
10
|
+
import { IsEmail, IsEnum, IsNotEmpty, IsOptional, IsString } from "class-validator";
|
|
11
11
|
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
12
12
|
import { OtpAction } from "../enums/otp-action";
|
|
13
|
+
import { CountryCode } from "../../country/enums/country-code.enum";
|
|
14
|
+
import { IsSupportedPhoneNumber } from "../../phone/validators/is-supported-phone-number.decorator";
|
|
13
15
|
export class ResendOTPDto {
|
|
14
16
|
}
|
|
15
17
|
__decorate([
|
|
@@ -45,12 +47,22 @@ __decorate([
|
|
|
45
47
|
], ResendOTPDto.prototype, "email", void 0);
|
|
46
48
|
__decorate([
|
|
47
49
|
ApiPropertyOptional({
|
|
48
|
-
description: 'Phone number of the user requesting OTP',
|
|
49
|
-
example: '+
|
|
50
|
+
description: 'Phone number of the user requesting OTP, in E.164 format (e.g. +254712345678) or national format when countryCode is provided',
|
|
51
|
+
example: '+254712345678',
|
|
50
52
|
format: 'phone'
|
|
51
53
|
}),
|
|
52
|
-
|
|
54
|
+
IsSupportedPhoneNumber(),
|
|
53
55
|
IsOptional(),
|
|
54
56
|
__metadata("design:type", String)
|
|
55
57
|
], ResendOTPDto.prototype, "phoneNumber", void 0);
|
|
58
|
+
__decorate([
|
|
59
|
+
ApiPropertyOptional({
|
|
60
|
+
description: 'ISO 3166-1 alpha-2 country code for the phone number (KE, UG, TZ). Required when phoneNumber is in national format; defaults to KE.',
|
|
61
|
+
enum: CountryCode,
|
|
62
|
+
example: CountryCode.KE
|
|
63
|
+
}),
|
|
64
|
+
IsEnum(CountryCode),
|
|
65
|
+
IsOptional(),
|
|
66
|
+
__metadata("design:type", String)
|
|
67
|
+
], ResendOTPDto.prototype, "countryCode", void 0);
|
|
56
68
|
//# sourceMappingURL=resend-otp.dto.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resend-otp.dto.js","sourceRoot":"","sources":["../../../../../src/modules/auth/dtos/resend-otp.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"resend-otp.dto.js","sourceRoot":"","sources":["../../../../../src/modules/auth/dtos/resend-otp.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAC;AAEpG,MAAM,OAAO,YAAY;CA8CxB;AArCG;IARC,WAAW,CAAC;QACT,WAAW,EAAE,yCAAyC;QACtD,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,SAAS,CAAC,KAAK;QACxB,MAAM,EAAE,QAAQ;KACnB,CAAC;IACD,MAAM,CAAC,SAAS,CAAC;IACjB,UAAU,EAAE;;4CACM;AASnB;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,0CAA0C;QACvD,OAAO,EAAE,cAAc;QACvB,MAAM,EAAE,QAAQ;KACnB,CAAC;IACD,QAAQ,EAAE;IACV,UAAU,EAAE;;uDACc;AAS3B;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,kCAAkC;QAC/C,OAAO,EAAE,kBAAkB;QAC3B,MAAM,EAAE,OAAO;KAClB,CAAC;IACD,OAAO,EAAE;IACT,UAAU,EAAE;;2CACE;AASf;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,+HAA+H;QAC5I,OAAO,EAAE,eAAe;QACxB,MAAM,EAAE,OAAO;KAClB,CAAC;IACD,sBAAsB,EAAE;IACxB,UAAU,EAAE;;iDACQ;AASrB;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,qIAAqI;QAClJ,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW,CAAC,EAAE;KAC1B,CAAC;IACD,MAAM,CAAC,WAAW,CAAC;IACnB,UAAU,EAAE;;iDACa"}
|
|
@@ -8,20 +8,32 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
11
|
-
import { IsEmail, IsEnum, IsNotEmpty, IsOptional
|
|
11
|
+
import { IsEmail, IsEnum, IsNotEmpty, IsOptional } from "class-validator";
|
|
12
12
|
import { OtpAction } from "../enums/otp-action";
|
|
13
|
+
import { CountryCode } from "../../country/enums/country-code.enum";
|
|
14
|
+
import { IsSupportedPhoneNumber } from "../../phone/validators/is-supported-phone-number.decorator";
|
|
13
15
|
export class SendOTPDto {
|
|
14
16
|
}
|
|
15
17
|
__decorate([
|
|
16
18
|
ApiPropertyOptional({
|
|
17
|
-
description: 'The phone number to send the OTP to (If email is not provided)',
|
|
18
|
-
example: '+
|
|
19
|
+
description: 'The phone number to send the OTP to, in E.164 format (e.g. +254712345678) or national format when countryCode is provided (If email is not provided)',
|
|
20
|
+
example: '+254712345678',
|
|
19
21
|
format: 'phone'
|
|
20
22
|
}),
|
|
21
|
-
|
|
23
|
+
IsSupportedPhoneNumber(),
|
|
22
24
|
IsOptional(),
|
|
23
25
|
__metadata("design:type", String)
|
|
24
26
|
], SendOTPDto.prototype, "phoneNumber", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
ApiPropertyOptional({
|
|
29
|
+
description: 'ISO 3166-1 alpha-2 country code for the phone number (KE, UG, TZ). Required when phoneNumber is in national format; defaults to KE.',
|
|
30
|
+
enum: CountryCode,
|
|
31
|
+
example: CountryCode.KE
|
|
32
|
+
}),
|
|
33
|
+
IsEnum(CountryCode),
|
|
34
|
+
IsOptional(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], SendOTPDto.prototype, "countryCode", void 0);
|
|
25
37
|
__decorate([
|
|
26
38
|
ApiPropertyOptional({
|
|
27
39
|
description: 'The email address to send the OTP to (If phone number is not provided)',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-otp.dto.js","sourceRoot":"","sources":["../../../../../src/modules/auth/dtos/send-otp.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"send-otp.dto.js","sourceRoot":"","sources":["../../../../../src/modules/auth/dtos/send-otp.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAY,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAC;AAEpG,MAAM,OAAO,UAAU;CAoCtB;AA5BG;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,sJAAsJ;QACnK,OAAO,EAAE,eAAe;QACxB,MAAM,EAAE,OAAO;KAClB,CAAC;IACD,sBAAsB,EAAE;IACxB,UAAU,EAAE;;+CACQ;AASrB;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,qIAAqI;QAClJ,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW,CAAC,EAAE;KAC1B,CAAC;IACD,MAAM,CAAC,WAAW,CAAC;IACnB,UAAU,EAAE;;+CACa;AAS1B;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,wEAAwE;QACrF,OAAO,EAAE,kBAAkB;QAC3B,MAAM,EAAE,OAAO;KAClB,CAAC;IACD,OAAO,EAAE;IACT,UAAU,EAAE;;yCACE;AASf;IAPC,WAAW,CAAC;QACT,WAAW,EAAE,yCAAyC;QACtD,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,SAAS,CAAC,YAAY;KAClC,CAAC;IACD,MAAM,CAAC,SAAS,CAAC;IACjB,UAAU,EAAE;;0CACM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/phone/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,+BAA+B,CAAC;AAE9C,YAAY;AACZ,cAAc,cAAc,CAAC;AAE7B,aAAa;AACb,cAAc,kDAAkD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalized-phone.js","sourceRoot":"","sources":["../../../../../src/modules/phone/interfaces/normalized-phone.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { parsePhoneNumberFromString } from 'libphonenumber-js';
|
|
2
|
+
import { DEFAULT_COUNTRY_CODE } from '../country/constants/country-defaults.const';
|
|
3
|
+
import { isSupportedCountryCode } from '../country/utils/country.util';
|
|
4
|
+
/**
|
|
5
|
+
* Phone-number normalization for the platform's supported countries (KE/UG/TZ).
|
|
6
|
+
*
|
|
7
|
+
* Built on `libphonenumber-js` (robust parsing/validation — no bespoke regex)
|
|
8
|
+
* and the Phase 1 country primitives. The canonical stored/queried form is
|
|
9
|
+
* always E.164 (e.g. '+254712345678').
|
|
10
|
+
*/
|
|
11
|
+
/** Digit strings of the supported E.164 calling codes, for the "code-without-plus" case. */
|
|
12
|
+
const SUPPORTED_CALLING_CODE_DIGITS = ['254', '256', '255'];
|
|
13
|
+
function toResult(phone) {
|
|
14
|
+
if (!phone || !phone.isValid()) {
|
|
15
|
+
return {
|
|
16
|
+
ok: false,
|
|
17
|
+
error: 'INVALID_PHONE_NUMBER',
|
|
18
|
+
message: 'The phone number is not a valid number.',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const country = phone.country;
|
|
22
|
+
if (!country || !isSupportedCountryCode(country)) {
|
|
23
|
+
return {
|
|
24
|
+
ok: false,
|
|
25
|
+
error: 'UNSUPPORTED_COUNTRY',
|
|
26
|
+
message: `Phone numbers from ${country !== null && country !== void 0 ? country : 'this country'} are not supported. Supported countries are Kenya (KE), Uganda (UG) and Tanzania (TZ).`,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
ok: true,
|
|
31
|
+
value: {
|
|
32
|
+
e164: phone.number,
|
|
33
|
+
countryCode: country,
|
|
34
|
+
nationalNumber: phone.nationalNumber,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Normalize a phone number to canonical E.164 for a supported country.
|
|
40
|
+
*
|
|
41
|
+
* Resolution order for a raw (non-`+`) input:
|
|
42
|
+
* 1. already international (`+254…`) — parsed as-is;
|
|
43
|
+
* 2. calling code without `+` (`254…`/`256…`/`255…`) — treated as international;
|
|
44
|
+
* 3. national/local (`0712…`, `712…`) — parsed using `defaultCountry`
|
|
45
|
+
* (the caller-supplied country, else Kenya for backward compatibility).
|
|
46
|
+
*
|
|
47
|
+
* @returns a discriminated result: `{ ok: true, value }` or `{ ok: false, error, message }`.
|
|
48
|
+
*/
|
|
49
|
+
export function normalizeSupportedPhoneNumber(input, defaultCountry) {
|
|
50
|
+
if (input == null || String(input).trim() === '') {
|
|
51
|
+
return { ok: false, error: 'INVALID_PHONE_NUMBER', message: 'A phone number is required.' };
|
|
52
|
+
}
|
|
53
|
+
const raw = String(input).trim();
|
|
54
|
+
const region = isSupportedCountryCode(defaultCountry)
|
|
55
|
+
? defaultCountry
|
|
56
|
+
: DEFAULT_COUNTRY_CODE;
|
|
57
|
+
// 1. Already international.
|
|
58
|
+
if (raw.startsWith('+')) {
|
|
59
|
+
return toResult(parsePhoneNumberFromString(raw));
|
|
60
|
+
}
|
|
61
|
+
const digits = raw.replace(/[^\d]/g, '');
|
|
62
|
+
// 2. Calling code supplied without the leading '+', e.g. '254712345678'.
|
|
63
|
+
if (SUPPORTED_CALLING_CODE_DIGITS.some((code) => digits.startsWith(code))) {
|
|
64
|
+
const international = parsePhoneNumberFromString('+' + digits);
|
|
65
|
+
if (international && international.isValid()) {
|
|
66
|
+
return toResult(international);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// 3. National/local format — resolve using the selected/default country.
|
|
70
|
+
return toResult(parsePhoneNumberFromString(raw, region));
|
|
71
|
+
}
|
|
72
|
+
/** Convenience: `true` if the input can be normalized to a supported-country E.164 number. */
|
|
73
|
+
export function isSupportedPhoneNumber(input, defaultCountry) {
|
|
74
|
+
return normalizeSupportedPhoneNumber(input, defaultCountry).ok;
|
|
75
|
+
}
|
|
76
|
+
/** Convenience: the canonical E.164 string, or `undefined` if the input cannot be normalized. */
|
|
77
|
+
export function toSupportedE164(input, defaultCountry) {
|
|
78
|
+
var _a;
|
|
79
|
+
return (_a = normalizeSupportedPhoneNumber(input, defaultCountry).value) === null || _a === void 0 ? void 0 : _a.e164;
|
|
80
|
+
}
|
|
81
|
+
/** Resolve the supported country a (normalizable) phone number belongs to, or `undefined`. */
|
|
82
|
+
export function getCountryForPhoneNumber(input, defaultCountry) {
|
|
83
|
+
var _a;
|
|
84
|
+
return (_a = normalizeSupportedPhoneNumber(input, defaultCountry).value) === null || _a === void 0 ? void 0 : _a.countryCode;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=phone.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone.util.js","sourceRoot":"","sources":["../../../../src/modules/phone/phone.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAe,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAEnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAGvE;;;;;;GAMG;AAEH,4FAA4F;AAC5F,MAAM,6BAA6B,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAE5D,SAAS,QAAQ,CAAC,KAA8B;IAC5C,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;QAC7B,OAAO;YACH,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,sBAAsB;YAC7B,OAAO,EAAE,yCAAyC;SACrD,CAAC;IACN,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,IAAI,CAAC,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/C,OAAO;YACH,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,qBAAqB;YAC5B,OAAO,EAAE,sBAAsB,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,cAAc,wFAAwF;SACnJ,CAAC;IACN,CAAC;IACD,OAAO;QACH,EAAE,EAAE,IAAI;QACR,KAAK,EAAE;YACH,IAAI,EAAE,KAAK,CAAC,MAAM;YAClB,WAAW,EAAE,OAAsB;YACnC,cAAc,EAAE,KAAK,CAAC,cAAc;SACvC;KACJ,CAAC;AACN,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,6BAA6B,CAC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E,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,eAAe,CAC3B,KAAgC,EAChC,cAA4C;;IAE5C,OAAO,MAAA,6BAA6B,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,KAAK,0CAAE,IAAI,CAAC;AAC5E,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,wBAAwB,CACpC,KAAgC,EAChC,cAA4C;;IAE5C,OAAO,MAAA,6BAA6B,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,KAAK,0CAAE,WAAW,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { registerDecorator } from 'class-validator';
|
|
2
|
+
import { isSupportedCountryCode } from '../../country/utils/country.util';
|
|
3
|
+
import { isSupportedPhoneNumber } from '../phone.util';
|
|
4
|
+
/**
|
|
5
|
+
* Validates that a property is a phone number for a supported country (KE/UG/TZ).
|
|
6
|
+
*
|
|
7
|
+
* Accepts either a full E.164 number (e.g. '+254712345678') OR a national/local
|
|
8
|
+
* number (e.g. '0712345678') when a sibling `countryCode` field is present. When
|
|
9
|
+
* no `countryCode` sibling is provided, Kenya is used as the default region for
|
|
10
|
+
* backward compatibility.
|
|
11
|
+
*
|
|
12
|
+
* Pairs with an optional `countryCode?: CountryCode` field on the same DTO.
|
|
13
|
+
*/
|
|
14
|
+
export function IsSupportedPhoneNumber(validationOptions) {
|
|
15
|
+
return function (object, propertyName) {
|
|
16
|
+
registerDecorator({
|
|
17
|
+
name: 'isSupportedPhoneNumber',
|
|
18
|
+
target: object.constructor,
|
|
19
|
+
propertyName,
|
|
20
|
+
options: validationOptions,
|
|
21
|
+
validator: {
|
|
22
|
+
validate(value, args) {
|
|
23
|
+
if (typeof value !== 'string') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const country = args.object['countryCode'];
|
|
27
|
+
return isSupportedPhoneNumber(value, isSupportedCountryCode(country) ? country : undefined);
|
|
28
|
+
},
|
|
29
|
+
defaultMessage(args) {
|
|
30
|
+
return `${args.property} must be a valid phone number for a supported country (KE, UG, TZ) — provide it in E.164 format (e.g. +254712345678), or in national format together with a countryCode.`;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=is-supported-phone-number.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-supported-phone-number.decorator.js","sourceRoot":"","sources":["../../../../../src/modules/phone/validators/is-supported-phone-number.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA0C,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAAC,iBAAqC;IACxE,OAAO,UAAU,MAAc,EAAE,YAAoB;QACjD,iBAAiB,CAAC;YACd,IAAI,EAAE,wBAAwB;YAC9B,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY;YACZ,OAAO,EAAE,iBAAiB;YAC1B,SAAS,EAAE;gBACP,QAAQ,CAAC,KAAc,EAAE,IAAyB;oBAC9C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;wBAC5B,OAAO,KAAK,CAAC;oBACjB,CAAC;oBACD,MAAM,OAAO,GAAI,IAAI,CAAC,MAAkC,CAAC,aAAa,CAAC,CAAC;oBACxE,OAAO,sBAAsB,CACzB,KAAK,EACL,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CACxD,CAAC;gBACN,CAAC;gBACD,cAAc,CAAC,IAAyB;oBACpC,OAAO,GAAG,IAAI,CAAC,QAAQ,0KAA0K,CAAC;gBACtM,CAAC;aACJ;SACJ,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { ArrayNotEmpty, IsArray, IsBoolean, IsDate, IsEmail, IsEnum, IsNotEmpty, IsNumber, IsOptional,
|
|
10
|
+
import { ArrayNotEmpty, IsArray, IsBoolean, IsDate, IsEmail, IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString, Matches, MaxLength, MinLength, ValidateNested, } from 'class-validator';
|
|
11
11
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
12
12
|
import { SentenceCase } from '../../../decorators/case-decorators';
|
|
13
13
|
import { UserStatus } from '../enums/user-status.enum';
|
|
@@ -16,6 +16,8 @@ import { Roles } from '../../role';
|
|
|
16
16
|
import { Type } from 'class-transformer';
|
|
17
17
|
import { GuardianDto } from './guardian.dto';
|
|
18
18
|
import { IncidentAppId } from '../../incident';
|
|
19
|
+
import { CountryCode } from '../../country/enums/country-code.enum';
|
|
20
|
+
import { IsSupportedPhoneNumber } from '../../phone/validators/is-supported-phone-number.decorator';
|
|
19
21
|
export class CreateUserDto {
|
|
20
22
|
}
|
|
21
23
|
__decorate([
|
|
@@ -56,16 +58,26 @@ __decorate([
|
|
|
56
58
|
], CreateUserDto.prototype, "email", void 0);
|
|
57
59
|
__decorate([
|
|
58
60
|
ApiPropertyOptional({
|
|
59
|
-
description: 'Phone number
|
|
60
|
-
example: '+
|
|
61
|
+
description: 'Phone number in E.164 format (e.g. +254712345678), or national format when countryCode is provided',
|
|
62
|
+
example: '+254712345678',
|
|
61
63
|
format: 'phone',
|
|
62
64
|
maxLength: 20
|
|
63
65
|
}),
|
|
64
|
-
|
|
66
|
+
IsSupportedPhoneNumber(),
|
|
65
67
|
MaxLength(20),
|
|
66
68
|
IsOptional(),
|
|
67
69
|
__metadata("design:type", String)
|
|
68
70
|
], CreateUserDto.prototype, "phoneNumber", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
ApiPropertyOptional({
|
|
73
|
+
description: 'ISO 3166-1 alpha-2 country code for the phone number (KE, UG, TZ). Required when phoneNumber is in national format; defaults to KE.',
|
|
74
|
+
enum: CountryCode,
|
|
75
|
+
example: CountryCode.KE
|
|
76
|
+
}),
|
|
77
|
+
IsEnum(CountryCode),
|
|
78
|
+
IsOptional(),
|
|
79
|
+
__metadata("design:type", String)
|
|
80
|
+
], CreateUserDto.prototype, "countryCode", void 0);
|
|
69
81
|
__decorate([
|
|
70
82
|
ApiProperty({
|
|
71
83
|
description: 'User roles',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-user.dto.js","sourceRoot":"","sources":["../../../../../src/modules/user/dtos/create-user.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACH,aAAa,EACb,OAAO,EACP,SAAS,EACT,MAAM,EACN,OAAO,EACP,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,
|
|
1
|
+
{"version":3,"file":"create-user.dto.js","sourceRoot":"","sources":["../../../../../src/modules/user/dtos/create-user.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EACH,aAAa,EACb,OAAO,EACP,SAAS,EACT,MAAM,EACN,OAAO,EACP,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,OAAO,EACP,SAAS,EACT,SAAS,EACT,cAAc,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AACrG,OAAO,EAAE,KAAK,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ACW"}
|
|
@@ -7,9 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumber, IsOptional,
|
|
10
|
+
import { IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString } from "class-validator";
|
|
11
11
|
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
|
|
12
12
|
import { GuardianRelationship } from "../enums/guardian-relationship.enum";
|
|
13
|
+
import { CountryCode } from "../../country/enums/country-code.enum";
|
|
14
|
+
import { IsSupportedPhoneNumber } from "../../phone/validators/is-supported-phone-number.decorator";
|
|
13
15
|
export class GuardianDto {
|
|
14
16
|
}
|
|
15
17
|
__decorate([
|
|
@@ -32,14 +34,24 @@ __decorate([
|
|
|
32
34
|
], GuardianDto.prototype, "name", void 0);
|
|
33
35
|
__decorate([
|
|
34
36
|
ApiProperty({
|
|
35
|
-
description: 'Guardian phone number
|
|
36
|
-
example: '+
|
|
37
|
+
description: 'Guardian phone number in E.164 format (e.g. +254712345678), or national format when countryCode is provided',
|
|
38
|
+
example: '+254712345678',
|
|
37
39
|
format: 'phone'
|
|
38
40
|
}),
|
|
39
|
-
|
|
41
|
+
IsSupportedPhoneNumber(),
|
|
40
42
|
IsNotEmpty(),
|
|
41
43
|
__metadata("design:type", String)
|
|
42
44
|
], GuardianDto.prototype, "phoneNumber", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
ApiPropertyOptional({
|
|
47
|
+
description: 'ISO 3166-1 alpha-2 country code for the guardian phone number (KE, UG, TZ). Required when phoneNumber is in national format; defaults to KE.',
|
|
48
|
+
enum: CountryCode,
|
|
49
|
+
example: CountryCode.KE
|
|
50
|
+
}),
|
|
51
|
+
IsEnum(CountryCode),
|
|
52
|
+
IsOptional(),
|
|
53
|
+
__metadata("design:type", String)
|
|
54
|
+
], GuardianDto.prototype, "countryCode", void 0);
|
|
43
55
|
__decorate([
|
|
44
56
|
ApiPropertyOptional({
|
|
45
57
|
description: 'Whether this is the primary guardian',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guardian.dto.js","sourceRoot":"","sources":["../../../../../src/modules/user/dtos/guardian.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"guardian.dto.js","sourceRoot":"","sources":["../../../../../src/modules/user/dtos/guardian.dto.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzG,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4DAA4D,CAAC;AAEpG,MAAM,OAAO,WAAW;CA6DvB;AAtDG;IANC,mBAAmB,CAAC;QACjB,WAAW,EAAE,wCAAwC;QACrD,OAAO,EAAE,GAAG;KACf,CAAC;IACD,QAAQ,EAAE;IACV,UAAU,EAAE;;2CACG;AAQhB;IANC,WAAW,CAAC;QACT,WAAW,EAAE,oBAAoB;QACjC,OAAO,EAAE,YAAY;KACxB,CAAC;IACD,QAAQ,EAAE;IACV,UAAU,EAAE;;yCACC;AASd;IAPC,WAAW,CAAC;QACT,WAAW,EAAE,6GAA6G;QAC1H,OAAO,EAAE,eAAe;QACxB,MAAM,EAAE,OAAO;KAClB,CAAC;IACD,sBAAsB,EAAE;IACxB,UAAU,EAAE;;gDACQ;AASrB;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,8IAA8I;QAC3J,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,WAAW,CAAC,EAAE;KAC1B,CAAC;IACD,MAAM,CAAC,WAAW,CAAC;IACnB,UAAU,EAAE;;gDACa;AAS1B;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,sCAAsC;QACnD,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,KAAK;KACjB,CAAC;IACD,SAAS,EAAE;IACX,UAAU,EAAE;;8CACO;AASpB;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,+BAA+B;QAC5C,IAAI,EAAE,oBAAoB;QAC1B,OAAO,EAAE,oBAAoB,CAAC,MAAM;KACvC,CAAC;IACD,MAAM,CAAC,oBAAoB,CAAC;IAC5B,UAAU,EAAE;;iDACuB;AASpC;IAPC,mBAAmB,CAAC;QACjB,WAAW,EAAE,wBAAwB;QACrC,OAAO,EAAE,wBAAwB;QACjC,MAAM,EAAE,OAAO;KAClB,CAAC;IACD,OAAO,EAAE;IACT,UAAU,EAAE;;0CACE"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from './modules/web-notification/index';
|
|
|
17
17
|
export * from './modules/notification/index';
|
|
18
18
|
export * from './modules/chat/index';
|
|
19
19
|
export * from './modules/country/index';
|
|
20
|
+
export * from './modules/phone/index';
|
|
20
21
|
export * from './interfaces/server-message';
|
|
21
22
|
export * from './interfaces/i-request-with-user';
|
|
22
23
|
export * from './interfaces/validated-user';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { IncidentAppId } from "../../incident";
|
|
2
|
+
import { CountryCode } from "../../country/enums/country-code.enum";
|
|
2
3
|
export declare class RegisterMobileUserDto {
|
|
3
4
|
appId: IncidentAppId;
|
|
4
5
|
name: string;
|
|
5
6
|
email: string;
|
|
6
7
|
phoneNumber: string;
|
|
8
|
+
countryCode?: CountryCode;
|
|
7
9
|
controlCentreId: number;
|
|
8
10
|
organizationId: number;
|
|
9
11
|
}
|
|
@@ -2,12 +2,14 @@ import { MapAddressDto } from "../../common";
|
|
|
2
2
|
import { Roles } from "../../role";
|
|
3
3
|
import { OrganizationType } from "../../organization/enums/org-type.enum";
|
|
4
4
|
import { IncidentAppId, IncidentClass } from "../../incident";
|
|
5
|
+
import { CountryCode } from "../../country/enums/country-code.enum";
|
|
5
6
|
export declare class RegisterDto {
|
|
6
7
|
appId: IncidentAppId;
|
|
7
8
|
incidentClass: IncidentClass;
|
|
8
9
|
name: string;
|
|
9
10
|
email: string;
|
|
10
11
|
phoneNumber: string;
|
|
12
|
+
countryCode?: CountryCode;
|
|
11
13
|
roles?: Roles[];
|
|
12
14
|
designation: string;
|
|
13
15
|
password: string;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { OtpAction } from "../enums/otp-action";
|
|
2
|
+
import { CountryCode } from "../../country/enums/country-code.enum";
|
|
2
3
|
export declare class ResendOTPDto {
|
|
3
4
|
action: OtpAction;
|
|
4
5
|
verificationToken?: string;
|
|
5
6
|
email?: string;
|
|
6
7
|
phoneNumber?: string;
|
|
8
|
+
countryCode?: CountryCode;
|
|
7
9
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CountryCode } from '../../country/enums/country-code.enum';
|
|
2
|
+
/** A phone number successfully normalized to canonical E.164 for a supported country. */
|
|
3
|
+
export interface NormalizedPhoneNumber {
|
|
4
|
+
/** Canonical E.164 representation, e.g. '+254712345678'. This is the value to store/query. */
|
|
5
|
+
e164: string;
|
|
6
|
+
/** ISO 3166-1 alpha-2 country the number belongs to (KE/UG/TZ). */
|
|
7
|
+
countryCode: CountryCode;
|
|
8
|
+
/** National (significant) number without the calling code, e.g. '712345678'. */
|
|
9
|
+
nationalNumber: string;
|
|
10
|
+
}
|
|
11
|
+
/** Machine-readable reason a phone number could not be normalized. */
|
|
12
|
+
export type PhoneNormalizationErrorCode = 'INVALID_PHONE_NUMBER' | 'UNSUPPORTED_COUNTRY';
|
|
13
|
+
/**
|
|
14
|
+
* Result of attempting to normalize a phone number to a supported-country E.164 value.
|
|
15
|
+
* Discriminated by `ok` — on success `value` is present, on failure `error`/`message` are.
|
|
16
|
+
*/
|
|
17
|
+
export interface PhoneNormalizationResult {
|
|
18
|
+
ok: boolean;
|
|
19
|
+
value?: NormalizedPhoneNumber;
|
|
20
|
+
error?: PhoneNormalizationErrorCode;
|
|
21
|
+
message?: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CountryCode } from '../country/enums/country-code.enum';
|
|
2
|
+
import { PhoneNormalizationResult } from './interfaces/normalized-phone';
|
|
3
|
+
/**
|
|
4
|
+
* Normalize a phone number to canonical E.164 for a supported country.
|
|
5
|
+
*
|
|
6
|
+
* Resolution order for a raw (non-`+`) input:
|
|
7
|
+
* 1. already international (`+254…`) — parsed as-is;
|
|
8
|
+
* 2. calling code without `+` (`254…`/`256…`/`255…`) — treated as international;
|
|
9
|
+
* 3. national/local (`0712…`, `712…`) — parsed using `defaultCountry`
|
|
10
|
+
* (the caller-supplied country, else Kenya for backward compatibility).
|
|
11
|
+
*
|
|
12
|
+
* @returns a discriminated result: `{ ok: true, value }` or `{ ok: false, error, message }`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function normalizeSupportedPhoneNumber(input: string | null | undefined, defaultCountry?: CountryCode | string | null): PhoneNormalizationResult;
|
|
15
|
+
/** Convenience: `true` if the input can be normalized to a supported-country E.164 number. */
|
|
16
|
+
export declare function isSupportedPhoneNumber(input: string | null | undefined, defaultCountry?: CountryCode | string | null): boolean;
|
|
17
|
+
/** Convenience: the canonical E.164 string, or `undefined` if the input cannot be normalized. */
|
|
18
|
+
export declare function toSupportedE164(input: string | null | undefined, defaultCountry?: CountryCode | string | null): string | undefined;
|
|
19
|
+
/** Resolve the supported country a (normalizable) phone number belongs to, or `undefined`. */
|
|
20
|
+
export declare function getCountryForPhoneNumber(input: string | null | undefined, defaultCountry?: CountryCode | string | null): CountryCode | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ValidationOptions } from 'class-validator';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that a property is a phone number for a supported country (KE/UG/TZ).
|
|
4
|
+
*
|
|
5
|
+
* Accepts either a full E.164 number (e.g. '+254712345678') OR a national/local
|
|
6
|
+
* number (e.g. '0712345678') when a sibling `countryCode` field is present. When
|
|
7
|
+
* no `countryCode` sibling is provided, Kenya is used as the default region for
|
|
8
|
+
* backward compatibility.
|
|
9
|
+
*
|
|
10
|
+
* Pairs with an optional `countryCode?: CountryCode` field on the same DTO.
|
|
11
|
+
*/
|
|
12
|
+
export declare function IsSupportedPhoneNumber(validationOptions?: ValidationOptions): (object: object, propertyName: string) => void;
|