vr-commons 1.0.189 → 1.0.190
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/utils/index.d.ts +1 -0
- package/dist/utils/index.js +9 -1
- package/dist/utils/users/users.accountRecovery.utils.d.ts +13 -0
- package/dist/utils/users/users.accountRecovery.utils.js +52 -0
- package/dist/validations/index.d.ts +1 -0
- package/dist/validations/index.js +5 -2
- package/dist/validations/users/users.accountRecovery.validations.d.ts +98 -0
- package/dist/validations/users/users.accountRecovery.validations.js +41 -0
- package/package.json +1 -1
package/dist/utils/index.d.ts
CHANGED
|
@@ -13,4 +13,5 @@ export { DPP_OperationsUtil } from "./admin/admin.devicePayments.utils";
|
|
|
13
13
|
export { formatDeviceSession, formatEventLog, formatEventLogs, buildEventLogWhereClause, buildSearchConditions, buildUserSearchConditions, } from "./admin/admin.eventLogs.utils";
|
|
14
14
|
export { logDebug, logError, logInfo, logSystem, logWarning, } from "./admin/admin.systemLogs.utils";
|
|
15
15
|
export { generateOTP, getOTPExpiry, getVerificationMethod, sendEmail, sendSMS, sendVerificationCode, detectContactType, validateContactValue, } from "./users/users.verification.utils";
|
|
16
|
+
export { ACCOUNT_RECOVERY_OTP_LENGTH, ACCOUNT_RECOVERY_OTP_TTL_MINUTES, ACCOUNT_RECOVERY_MAX_OTP_ATTEMPTS, generateAccountRecoveryOTP, hashAccountRecoveryOTP, verifyAccountRecoveryOTP, getAccountRecoveryOTPExpiry, } from "./users/users.accountRecovery.utils";
|
|
16
17
|
export { PendingRegistration, VerificationMethod, ConfirmResponse, UploadResult, StockChangeResult, DeviceResetResult, DeviceResetOptions, } from "./shared/shared.types";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stockUtil = exports.hierarchicalView = exports.validateHierarchy = exports.isSuperiorOrEqual = exports.isSuperior = exports.isSubordinateOrEqual = exports.isSubordinate = exports.isRankEqual = exports.getUserLevel = exports.suspensionUtil = exports.banUtil = exports.hasHigherAuthority = exports.getModeratableRoles = exports.canModerateUser = exports.canModerate = exports.softDeleteUser = exports.hashPassword = exports.validatePassword = exports.validateUniqueFields = exports.generateJacketId = exports.getSortOrder = exports.generateEventSearchConditions = exports.generateUserSearchConditions = exports.findSecurityClearanceByRole = exports.getUsersByRole = exports.getUserById = exports.isAccountAccessible = exports.canModifyAccount = exports.hasAllPermissions = exports.hasAnyPermission = exports.hasPermission = exports.hasRole = exports.formatUserListResponse = exports.formatUserProfile = exports.sendErrorResponse = exports.sendSuccessResponse = exports.logEvent = exports.formatTimeRemaining = exports.getTokenTimeRemaining = exports.generateToken = exports.shouldRefreshToken = exports.verifyToken = exports.generateRiderToken = exports.generatePassengerToken = exports.generateAdminToken = exports.checkSuspensionStatus = exports.checkIsUserBannedOrSuspended = exports.checkBanStatus = exports.hasActiveDependencies = exports.checkAccountDependencies = void 0;
|
|
4
|
-
exports.validateContactValue = exports.detectContactType = exports.sendVerificationCode = exports.sendSMS = exports.sendEmail = exports.getVerificationMethod = exports.getOTPExpiry = exports.generateOTP = exports.logWarning = exports.logSystem = exports.logInfo = exports.logError = exports.logDebug = exports.buildUserSearchConditions = exports.buildSearchConditions = exports.buildEventLogWhereClause = exports.formatEventLogs = exports.formatEventLog = exports.formatDeviceSession = exports.DPP_OperationsUtil = exports.cloudinaryUtil = void 0;
|
|
4
|
+
exports.getAccountRecoveryOTPExpiry = exports.verifyAccountRecoveryOTP = exports.hashAccountRecoveryOTP = exports.generateAccountRecoveryOTP = exports.ACCOUNT_RECOVERY_MAX_OTP_ATTEMPTS = exports.ACCOUNT_RECOVERY_OTP_TTL_MINUTES = exports.ACCOUNT_RECOVERY_OTP_LENGTH = exports.validateContactValue = exports.detectContactType = exports.sendVerificationCode = exports.sendSMS = exports.sendEmail = exports.getVerificationMethod = exports.getOTPExpiry = exports.generateOTP = exports.logWarning = exports.logSystem = exports.logInfo = exports.logError = exports.logDebug = exports.buildUserSearchConditions = exports.buildSearchConditions = exports.buildEventLogWhereClause = exports.formatEventLogs = exports.formatEventLog = exports.formatDeviceSession = exports.DPP_OperationsUtil = exports.cloudinaryUtil = void 0;
|
|
5
5
|
var shared_accounts_utils_1 = require("./shared/shared.accounts.utils");
|
|
6
6
|
Object.defineProperty(exports, "checkAccountDependencies", { enumerable: true, get: function () { return shared_accounts_utils_1.checkAccountDependencies; } });
|
|
7
7
|
Object.defineProperty(exports, "hasActiveDependencies", { enumerable: true, get: function () { return shared_accounts_utils_1.hasActiveDependencies; } });
|
|
@@ -88,3 +88,11 @@ Object.defineProperty(exports, "sendSMS", { enumerable: true, get: function () {
|
|
|
88
88
|
Object.defineProperty(exports, "sendVerificationCode", { enumerable: true, get: function () { return users_verification_utils_1.sendVerificationCode; } });
|
|
89
89
|
Object.defineProperty(exports, "detectContactType", { enumerable: true, get: function () { return users_verification_utils_1.detectContactType; } });
|
|
90
90
|
Object.defineProperty(exports, "validateContactValue", { enumerable: true, get: function () { return users_verification_utils_1.validateContactValue; } });
|
|
91
|
+
var users_accountRecovery_utils_1 = require("./users/users.accountRecovery.utils");
|
|
92
|
+
Object.defineProperty(exports, "ACCOUNT_RECOVERY_OTP_LENGTH", { enumerable: true, get: function () { return users_accountRecovery_utils_1.ACCOUNT_RECOVERY_OTP_LENGTH; } });
|
|
93
|
+
Object.defineProperty(exports, "ACCOUNT_RECOVERY_OTP_TTL_MINUTES", { enumerable: true, get: function () { return users_accountRecovery_utils_1.ACCOUNT_RECOVERY_OTP_TTL_MINUTES; } });
|
|
94
|
+
Object.defineProperty(exports, "ACCOUNT_RECOVERY_MAX_OTP_ATTEMPTS", { enumerable: true, get: function () { return users_accountRecovery_utils_1.ACCOUNT_RECOVERY_MAX_OTP_ATTEMPTS; } });
|
|
95
|
+
Object.defineProperty(exports, "generateAccountRecoveryOTP", { enumerable: true, get: function () { return users_accountRecovery_utils_1.generateAccountRecoveryOTP; } });
|
|
96
|
+
Object.defineProperty(exports, "hashAccountRecoveryOTP", { enumerable: true, get: function () { return users_accountRecovery_utils_1.hashAccountRecoveryOTP; } });
|
|
97
|
+
Object.defineProperty(exports, "verifyAccountRecoveryOTP", { enumerable: true, get: function () { return users_accountRecovery_utils_1.verifyAccountRecoveryOTP; } });
|
|
98
|
+
Object.defineProperty(exports, "getAccountRecoveryOTPExpiry", { enumerable: true, get: function () { return users_accountRecovery_utils_1.getAccountRecoveryOTPExpiry; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const ACCOUNT_RECOVERY_OTP_LENGTH = 4;
|
|
2
|
+
export declare const ACCOUNT_RECOVERY_OTP_TTL_MINUTES = 10;
|
|
3
|
+
export declare const ACCOUNT_RECOVERY_MAX_OTP_ATTEMPTS = 5;
|
|
4
|
+
/** Generate a zero-padded, cryptographically random account recovery code. */
|
|
5
|
+
export declare function generateAccountRecoveryOTP(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Create an HMAC verifier so a database read alone does not reveal the OTP.
|
|
8
|
+
* The same high-entropy secret must be configured in vr-admin-be and vr-users-be.
|
|
9
|
+
*/
|
|
10
|
+
export declare function hashAccountRecoveryOTP(otp: string, secret: string): string;
|
|
11
|
+
/** Compare an entered code with its stored HMAC verifier in constant time. */
|
|
12
|
+
export declare function verifyAccountRecoveryOTP(otp: string, expectedHash: string, secret: string): boolean;
|
|
13
|
+
export declare function getAccountRecoveryOTPExpiry(now?: Date): Date;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACCOUNT_RECOVERY_MAX_OTP_ATTEMPTS = exports.ACCOUNT_RECOVERY_OTP_TTL_MINUTES = exports.ACCOUNT_RECOVERY_OTP_LENGTH = void 0;
|
|
4
|
+
exports.generateAccountRecoveryOTP = generateAccountRecoveryOTP;
|
|
5
|
+
exports.hashAccountRecoveryOTP = hashAccountRecoveryOTP;
|
|
6
|
+
exports.verifyAccountRecoveryOTP = verifyAccountRecoveryOTP;
|
|
7
|
+
exports.getAccountRecoveryOTPExpiry = getAccountRecoveryOTPExpiry;
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
exports.ACCOUNT_RECOVERY_OTP_LENGTH = 4;
|
|
10
|
+
exports.ACCOUNT_RECOVERY_OTP_TTL_MINUTES = 10;
|
|
11
|
+
exports.ACCOUNT_RECOVERY_MAX_OTP_ATTEMPTS = 5;
|
|
12
|
+
const ACCOUNT_RECOVERY_OTP_REGEX = /^\d{4}$/;
|
|
13
|
+
const MIN_SECRET_BYTES = 32;
|
|
14
|
+
function assertAccountRecoverySecret(secret) {
|
|
15
|
+
if (Buffer.byteLength(secret, "utf8") < MIN_SECRET_BYTES) {
|
|
16
|
+
throw new Error(`ACCOUNT_RECOVERY_OTP_SECRET must be at least ${MIN_SECRET_BYTES} bytes.`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Generate a zero-padded, cryptographically random account recovery code. */
|
|
20
|
+
function generateAccountRecoveryOTP() {
|
|
21
|
+
const upperBound = 10 ** exports.ACCOUNT_RECOVERY_OTP_LENGTH;
|
|
22
|
+
return (0, crypto_1.randomInt)(0, upperBound).toString().padStart(exports.ACCOUNT_RECOVERY_OTP_LENGTH, "0");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create an HMAC verifier so a database read alone does not reveal the OTP.
|
|
26
|
+
* The same high-entropy secret must be configured in vr-admin-be and vr-users-be.
|
|
27
|
+
*/
|
|
28
|
+
function hashAccountRecoveryOTP(otp, secret) {
|
|
29
|
+
if (!ACCOUNT_RECOVERY_OTP_REGEX.test(otp)) {
|
|
30
|
+
throw new Error("Account recovery OTP must be exactly 4 digits.");
|
|
31
|
+
}
|
|
32
|
+
assertAccountRecoverySecret(secret);
|
|
33
|
+
return (0, crypto_1.createHmac)("sha256", secret).update(otp, "utf8").digest("hex");
|
|
34
|
+
}
|
|
35
|
+
/** Compare an entered code with its stored HMAC verifier in constant time. */
|
|
36
|
+
function verifyAccountRecoveryOTP(otp, expectedHash, secret) {
|
|
37
|
+
if (!ACCOUNT_RECOVERY_OTP_REGEX.test(otp) || !/^[a-f0-9]{64}$/i.test(expectedHash)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
assertAccountRecoverySecret(secret);
|
|
41
|
+
try {
|
|
42
|
+
const actual = Buffer.from(hashAccountRecoveryOTP(otp, secret), "hex");
|
|
43
|
+
const expected = Buffer.from(expectedHash, "hex");
|
|
44
|
+
return actual.length === expected.length && (0, crypto_1.timingSafeEqual)(actual, expected);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function getAccountRecoveryOTPExpiry(now = new Date()) {
|
|
51
|
+
return new Date(now.getTime() + exports.ACCOUNT_RECOVERY_OTP_TTL_MINUTES * 60 * 1000);
|
|
52
|
+
}
|
|
@@ -7,6 +7,7 @@ export { createAppSpecsSchema, updateAppSpecsSchema, listAppSpecsSchema, getActi
|
|
|
7
7
|
export { updateProfileSchema, requestPhoneChangeSchema, verifyPhoneChangeSchema, deleteAccountSchema, strongPasswordRegex, changePasswordSchema, riderPasswordSchema, registerRiderSchema, } from "./shared/shared.account.validations";
|
|
8
8
|
export { listUserPaymentPlansSchema, getUserPaymentPlanSchema, } from "./users/users.devicePaymentPlans.validations";
|
|
9
9
|
export { unlockDeviceSchema, extendSessionSchema, serialRegex, } from "./users/users.devices.validations";
|
|
10
|
+
export { requestRiderAccountRecoverySchema, completeRiderAccountRecoverySchema, RequestRiderAccountRecoverySchema, CompleteRiderAccountRecoverySchema, } from "./users/users.accountRecovery.validations";
|
|
10
11
|
export { payInstallmentSchema, getInstallmentByIdSchema, getInstallmentsSchema, } from "./admin/admin.installments.validations";
|
|
11
12
|
export { updateAdminSchema, updateRiderSchema, deleteUserSchema, getUserSchema, getUsersSchema, hireAdminSchema, promoteAdminSchema, demoteAdminSchema, fireEmployeeSchema, upgradeToRiderSchema, resetPasswordSchema, } from "./admin/admin.users.validations";
|
|
12
13
|
export { createProductSchema, updateProductSchema, getProductSchema, getProductsSchema, deactivateProductSchema, activateProductSchema, deleteProductSchema, updateStockSchema, } from "./admin/admin.products.validations";
|
|
@@ -15,8 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.activateAppSpecsSchema = exports.getAppSpecsByNameSchema = exports.getActiveAppSpecsSchema = exports.listAppSpecsSchema = exports.updateAppSpecsSchema = exports.createAppSpecsSchema = exports.exportBansSchema = exports.createSuspensionSchema = exports.createBanSchema = exports.extendSuspensionSchema = exports.revokeSuspensionSchema = exports.revokeBanSchema = exports.reviewAppealSchema = exports.listSuspensionsSchema = exports.listPendingAppealsSchema = exports.listBansSchema = exports.getUserBansSchema = exports.getUserSuspensionsSchema = exports.getSuspensionSchema = exports.getUserRestrictionsSchema = exports.getBanSchema = exports.submitSuspensionAppealSchema = exports.submitBanAppealSchema = exports.deactivateAccountSchema = exports.createRiderSchema = exports.updateRiderProfileSchema = exports.updatePassengerProfileSchema = exports.passengerSignupSchema = exports.viewProfileSchema = exports.getAllUsersSchema = exports.updateUserProfileSchema = exports.getUserByIdSchema = exports.createUserSchema = exports.googleLoginSchema = exports.completePassengerProfileSchema = exports.checkRiderAccountSchema = exports.setRiderPasswordSchema = exports.riderPasswordRegex = exports.passwordRegex = exports.emailRegex = exports.phoneRegex = exports.requestOtpSchema = exports.resendOtpSchema = exports.verifyOtpSchema = exports.registerSchema = exports.refreshTokenSchema = exports.userLoginSchema = exports.forgotPasswordSchema = exports.riderLoginSchema = exports.validate = void 0;
|
|
18
|
-
exports.
|
|
19
|
-
exports.getEventLogSchema = exports.listEventLogsSchema = exports.replacePlanDevicesSchema = exports.deletePlanSchema = exports.recordPaymentSchema = exports.listPlansSchema = exports.getUserPlansSchema = exports.getPlanSchema = exports.getDevicePlanSchema = exports.limitedUpdateSchema = exports.createPlanSchema = exports.customDeviceResetSchema = exports.triggerDeviceResetSchema = exports.getDevicesSchema = exports.getDeviceSchema = void 0;
|
|
18
|
+
exports.permanentDeleteDevicesByPairsSchema = exports.makeDevicesPermanentSchema = exports.deleteDevicesByPairsSchema = exports.unlockDevicesSchema = exports.lockDevicesSchema = exports.createDevicePairsSchema = exports.checkAvailabilitySchema = exports.deletePricingSchema = exports.getPricingsSchema = exports.getPricingSchema = exports.updatePricingSchema = exports.createPricingSchema = exports.updateStockSchema = exports.deleteProductSchema = exports.activateProductSchema = exports.deactivateProductSchema = exports.getProductsSchema = exports.getProductSchema = exports.updateProductSchema = exports.createProductSchema = exports.resetPasswordSchema = exports.upgradeToRiderSchema = exports.fireEmployeeSchema = exports.demoteAdminSchema = exports.promoteAdminSchema = exports.hireAdminSchema = exports.getUsersSchema = exports.getUserSchema = exports.deleteUserSchema = exports.updateRiderSchema = exports.updateAdminSchema = exports.getInstallmentsSchema = exports.getInstallmentByIdSchema = exports.payInstallmentSchema = exports.completeRiderAccountRecoverySchema = exports.requestRiderAccountRecoverySchema = exports.serialRegex = exports.extendSessionSchema = exports.unlockDeviceSchema = exports.getUserPaymentPlanSchema = exports.listUserPaymentPlansSchema = exports.registerRiderSchema = exports.riderPasswordSchema = exports.changePasswordSchema = exports.strongPasswordRegex = exports.deleteAccountSchema = exports.verifyPhoneChangeSchema = exports.requestPhoneChangeSchema = exports.updateProfileSchema = exports.getAppSpecsSchema = void 0;
|
|
19
|
+
exports.getEventLogSchema = exports.listEventLogsSchema = exports.replacePlanDevicesSchema = exports.deletePlanSchema = exports.recordPaymentSchema = exports.listPlansSchema = exports.getUserPlansSchema = exports.getPlanSchema = exports.getDevicePlanSchema = exports.limitedUpdateSchema = exports.createPlanSchema = exports.customDeviceResetSchema = exports.triggerDeviceResetSchema = exports.getDevicesSchema = exports.getDeviceSchema = exports.enableDevicesSchema = exports.disableDevicesSchema = void 0;
|
|
20
20
|
__exportStar(require("../constants/regex.constants"), exports);
|
|
21
21
|
var shared_validate_validations_1 = require("./shared/shared.validate.validations");
|
|
22
22
|
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return shared_validate_validations_1.validate; } });
|
|
@@ -90,6 +90,9 @@ var users_devices_validations_1 = require("./users/users.devices.validations");
|
|
|
90
90
|
Object.defineProperty(exports, "unlockDeviceSchema", { enumerable: true, get: function () { return users_devices_validations_1.unlockDeviceSchema; } });
|
|
91
91
|
Object.defineProperty(exports, "extendSessionSchema", { enumerable: true, get: function () { return users_devices_validations_1.extendSessionSchema; } });
|
|
92
92
|
Object.defineProperty(exports, "serialRegex", { enumerable: true, get: function () { return users_devices_validations_1.serialRegex; } });
|
|
93
|
+
var users_accountRecovery_validations_1 = require("./users/users.accountRecovery.validations");
|
|
94
|
+
Object.defineProperty(exports, "requestRiderAccountRecoverySchema", { enumerable: true, get: function () { return users_accountRecovery_validations_1.requestRiderAccountRecoverySchema; } });
|
|
95
|
+
Object.defineProperty(exports, "completeRiderAccountRecoverySchema", { enumerable: true, get: function () { return users_accountRecovery_validations_1.completeRiderAccountRecoverySchema; } });
|
|
93
96
|
var admin_installments_validations_1 = require("./admin/admin.installments.validations");
|
|
94
97
|
Object.defineProperty(exports, "payInstallmentSchema", { enumerable: true, get: function () { return admin_installments_validations_1.payInstallmentSchema; } });
|
|
95
98
|
Object.defineProperty(exports, "getInstallmentByIdSchema", { enumerable: true, get: function () { return admin_installments_validations_1.getInstallmentByIdSchema; } });
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const requestRiderAccountRecoverySchema: z.ZodObject<{
|
|
3
|
+
body: z.ZodEffects<z.ZodObject<{
|
|
4
|
+
phoneNumber: z.ZodString;
|
|
5
|
+
plateNumber: z.ZodString;
|
|
6
|
+
birthDate: z.ZodNumber;
|
|
7
|
+
birthMonth: z.ZodNumber;
|
|
8
|
+
birthYear: z.ZodNumber;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
plateNumber: string;
|
|
11
|
+
birthDate: number;
|
|
12
|
+
birthMonth: number;
|
|
13
|
+
birthYear: number;
|
|
14
|
+
phoneNumber: string;
|
|
15
|
+
}, {
|
|
16
|
+
plateNumber: string;
|
|
17
|
+
birthDate: number;
|
|
18
|
+
birthMonth: number;
|
|
19
|
+
birthYear: number;
|
|
20
|
+
phoneNumber: string;
|
|
21
|
+
}>, {
|
|
22
|
+
plateNumber: string;
|
|
23
|
+
birthDate: number;
|
|
24
|
+
birthMonth: number;
|
|
25
|
+
birthYear: number;
|
|
26
|
+
phoneNumber: string;
|
|
27
|
+
}, {
|
|
28
|
+
plateNumber: string;
|
|
29
|
+
birthDate: number;
|
|
30
|
+
birthMonth: number;
|
|
31
|
+
birthYear: number;
|
|
32
|
+
phoneNumber: string;
|
|
33
|
+
}>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
body: {
|
|
36
|
+
plateNumber: string;
|
|
37
|
+
birthDate: number;
|
|
38
|
+
birthMonth: number;
|
|
39
|
+
birthYear: number;
|
|
40
|
+
phoneNumber: string;
|
|
41
|
+
};
|
|
42
|
+
}, {
|
|
43
|
+
body: {
|
|
44
|
+
plateNumber: string;
|
|
45
|
+
birthDate: number;
|
|
46
|
+
birthMonth: number;
|
|
47
|
+
birthYear: number;
|
|
48
|
+
phoneNumber: string;
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
export declare const completeRiderAccountRecoverySchema: z.ZodEffects<z.ZodObject<{
|
|
52
|
+
body: z.ZodObject<{
|
|
53
|
+
phoneNumber: z.ZodString;
|
|
54
|
+
recoveryCode: z.ZodString;
|
|
55
|
+
newPassword: z.ZodEffects<z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>, string, string | undefined>;
|
|
56
|
+
confirmNewPassword: z.ZodString;
|
|
57
|
+
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
newPassword: string;
|
|
59
|
+
phoneNumber: string;
|
|
60
|
+
recoveryCode: string;
|
|
61
|
+
confirmNewPassword: string;
|
|
62
|
+
}, {
|
|
63
|
+
phoneNumber: string;
|
|
64
|
+
recoveryCode: string;
|
|
65
|
+
confirmNewPassword: string;
|
|
66
|
+
newPassword?: string | undefined;
|
|
67
|
+
}>;
|
|
68
|
+
}, "strip", z.ZodTypeAny, {
|
|
69
|
+
body: {
|
|
70
|
+
newPassword: string;
|
|
71
|
+
phoneNumber: string;
|
|
72
|
+
recoveryCode: string;
|
|
73
|
+
confirmNewPassword: string;
|
|
74
|
+
};
|
|
75
|
+
}, {
|
|
76
|
+
body: {
|
|
77
|
+
phoneNumber: string;
|
|
78
|
+
recoveryCode: string;
|
|
79
|
+
confirmNewPassword: string;
|
|
80
|
+
newPassword?: string | undefined;
|
|
81
|
+
};
|
|
82
|
+
}>, {
|
|
83
|
+
body: {
|
|
84
|
+
newPassword: string;
|
|
85
|
+
phoneNumber: string;
|
|
86
|
+
recoveryCode: string;
|
|
87
|
+
confirmNewPassword: string;
|
|
88
|
+
};
|
|
89
|
+
}, {
|
|
90
|
+
body: {
|
|
91
|
+
phoneNumber: string;
|
|
92
|
+
recoveryCode: string;
|
|
93
|
+
confirmNewPassword: string;
|
|
94
|
+
newPassword?: string | undefined;
|
|
95
|
+
};
|
|
96
|
+
}>;
|
|
97
|
+
export type RequestRiderAccountRecoverySchema = z.infer<typeof requestRiderAccountRecoverySchema>;
|
|
98
|
+
export type CompleteRiderAccountRecoverySchema = z.infer<typeof completeRiderAccountRecoverySchema>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.completeRiderAccountRecoverySchema = exports.requestRiderAccountRecoverySchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const regex_constants_1 = require("../../constants/regex.constants");
|
|
6
|
+
const shared_account_validations_1 = require("../shared/shared.account.validations");
|
|
7
|
+
const birthDateFields = {
|
|
8
|
+
birthDate: zod_1.z.number().int().min(1).max(31),
|
|
9
|
+
birthMonth: zod_1.z.number().int().min(1).max(12),
|
|
10
|
+
birthYear: zod_1.z.number().int().min(1900).max(new Date().getFullYear()),
|
|
11
|
+
};
|
|
12
|
+
exports.requestRiderAccountRecoverySchema = zod_1.z
|
|
13
|
+
.object({
|
|
14
|
+
body: zod_1.z
|
|
15
|
+
.object({
|
|
16
|
+
...birthDateFields,
|
|
17
|
+
phoneNumber: zod_1.z.string().regex(regex_constants_1.PHONE_NUMBER_REGEX, "Enter a valid Rwandan phone number"),
|
|
18
|
+
plateNumber: zod_1.z.string().trim().regex(regex_constants_1.RWANDA_PLATE_NUMBER_REGEX, "Enter a valid plate number"),
|
|
19
|
+
})
|
|
20
|
+
.refine(({ birthDate, birthMonth, birthYear }) => birthDate <= new Date(birthYear, birthMonth, 0).getDate(), { message: "Enter a valid date of birth", path: ["birthDate"] }),
|
|
21
|
+
});
|
|
22
|
+
const recoveryCodeSchema = zod_1.z
|
|
23
|
+
.string()
|
|
24
|
+
.length(4, "Recovery code must be 4 digits")
|
|
25
|
+
.regex(regex_constants_1.FOUR_DIGIT_PIN_REGEX, "Recovery code must contain only digits");
|
|
26
|
+
const newRiderPINSchema = shared_account_validations_1.riderPasswordSchema.refine((pin) => pin !== "1234", {
|
|
27
|
+
message: "Choose a PIN different from the temporary PIN",
|
|
28
|
+
});
|
|
29
|
+
exports.completeRiderAccountRecoverySchema = zod_1.z
|
|
30
|
+
.object({
|
|
31
|
+
body: zod_1.z.object({
|
|
32
|
+
phoneNumber: zod_1.z.string().regex(regex_constants_1.PHONE_NUMBER_REGEX, "Enter a valid Rwandan phone number"),
|
|
33
|
+
recoveryCode: recoveryCodeSchema,
|
|
34
|
+
newPassword: newRiderPINSchema,
|
|
35
|
+
confirmNewPassword: zod_1.z.string().length(4).regex(regex_constants_1.FOUR_DIGIT_PIN_REGEX),
|
|
36
|
+
}),
|
|
37
|
+
})
|
|
38
|
+
.refine((data) => data.body.newPassword === data.body.confirmNewPassword, {
|
|
39
|
+
message: "PINs do not match",
|
|
40
|
+
path: ["body", "confirmNewPassword"],
|
|
41
|
+
});
|