vr-commons 1.0.188 → 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/middlewares/index.d.ts +1 -0
- package/dist/middlewares/index.js +4 -1
- package/dist/middlewares/shared/shared.appVersion.middleware.d.ts +9 -0
- package/dist/middlewares/shared/shared.appVersion.middleware.js +175 -0
- 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/admin/admin.devicePayments.validations.d.ts +6 -6
- package/dist/validations/admin/admin.devices.validations.d.ts +12 -12
- package/dist/validations/admin/admin.eventLogs.validations.d.ts +24 -24
- package/dist/validations/admin/admin.installments.validations.d.ts +4 -4
- package/dist/validations/admin/admin.pricings.validations.d.ts +8 -8
- package/dist/validations/admin/admin.products.validations.d.ts +12 -12
- package/dist/validations/admin/admin.users.validations.d.ts +50 -50
- package/dist/validations/index.d.ts +1 -0
- package/dist/validations/index.js +5 -2
- package/dist/validations/shared/shared.account.validations.d.ts +10 -10
- package/dist/validations/shared/shared.appSpecs.validations.d.ts +70 -48
- package/dist/validations/shared/shared.appSpecs.validations.js +7 -2
- package/dist/validations/shared/shared.auth.validations.d.ts +28 -28
- package/dist/validations/shared/shared.moderation.validations.d.ts +18 -18
- package/dist/validations/shared/shared.profiles.validations.d.ts +86 -86
- package/dist/validations/users/users.accountRecovery.validations.d.ts +98 -0
- package/dist/validations/users/users.accountRecovery.validations.js +41 -0
- package/dist/validations/users/users.devicePaymentPlans.validations.d.ts +6 -6
- package/package.json +2 -2
|
@@ -3,3 +3,4 @@ export { checkUserAuthentication } from "./users/users.auth.middleware";
|
|
|
3
3
|
export { checkIsUserBanned, checkIsUserSuspended, checkUserAccountStatus, } from "./shared/shared.account.middleware";
|
|
4
4
|
export { errorHandler } from "./shared/shared.errorHandler.middleware";
|
|
5
5
|
export { loadAppRuntimeConfig } from "./shared/shared.appSpecs.middleware";
|
|
6
|
+
export { clearAppVersionMinimumsCache, enforceMinimumMobileAppVersion, } from "./shared/shared.appVersion.middleware";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadAppRuntimeConfig = exports.errorHandler = exports.checkUserAccountStatus = exports.checkIsUserSuspended = exports.checkIsUserBanned = exports.checkUserAuthentication = exports.checkAdminAuthentication = void 0;
|
|
3
|
+
exports.enforceMinimumMobileAppVersion = exports.clearAppVersionMinimumsCache = exports.loadAppRuntimeConfig = exports.errorHandler = exports.checkUserAccountStatus = exports.checkIsUserSuspended = exports.checkIsUserBanned = exports.checkUserAuthentication = exports.checkAdminAuthentication = void 0;
|
|
4
4
|
var admin_auth_middleware_1 = require("./admin/admin.auth.middleware");
|
|
5
5
|
Object.defineProperty(exports, "checkAdminAuthentication", { enumerable: true, get: function () { return admin_auth_middleware_1.checkAdminAuthentication; } });
|
|
6
6
|
var users_auth_middleware_1 = require("./users/users.auth.middleware");
|
|
@@ -13,3 +13,6 @@ var shared_errorHandler_middleware_1 = require("./shared/shared.errorHandler.mid
|
|
|
13
13
|
Object.defineProperty(exports, "errorHandler", { enumerable: true, get: function () { return shared_errorHandler_middleware_1.errorHandler; } });
|
|
14
14
|
var shared_appSpecs_middleware_1 = require("./shared/shared.appSpecs.middleware");
|
|
15
15
|
Object.defineProperty(exports, "loadAppRuntimeConfig", { enumerable: true, get: function () { return shared_appSpecs_middleware_1.loadAppRuntimeConfig; } });
|
|
16
|
+
var shared_appVersion_middleware_1 = require("./shared/shared.appVersion.middleware");
|
|
17
|
+
Object.defineProperty(exports, "clearAppVersionMinimumsCache", { enumerable: true, get: function () { return shared_appVersion_middleware_1.clearAppVersionMinimumsCache; } });
|
|
18
|
+
Object.defineProperty(exports, "enforceMinimumMobileAppVersion", { enumerable: true, get: function () { return shared_appVersion_middleware_1.enforceMinimumMobileAppVersion; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NextFunction, Request, Response } from "express";
|
|
2
|
+
/** Clear this process's cached app-version policy after an AppSpecs update. */
|
|
3
|
+
export declare function clearAppVersionMinimumsCache(appName?: string): void;
|
|
4
|
+
/**
|
|
5
|
+
* Enforce the platform-specific minimum app version/build for requests that
|
|
6
|
+
* explicitly identify as Viberide mobile. Requests from Postman, tests, and
|
|
7
|
+
* other clients without X-App-Client pass through unchanged.
|
|
8
|
+
*/
|
|
9
|
+
export declare function enforceMinimumMobileAppVersion(appName?: string): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.clearAppVersionMinimumsCache = clearAppVersionMinimumsCache;
|
|
4
|
+
exports.enforceMinimumMobileAppVersion = enforceMinimumMobileAppVersion;
|
|
5
|
+
const vr_models_1 = require("vr-models");
|
|
6
|
+
const MOBILE_APP_CLIENT = "VIBERIDE-MOBILE-APP";
|
|
7
|
+
const DEFAULT_APP_NAME = "VIBERIDE-MOBILE-APP";
|
|
8
|
+
const CACHE_TTL_MS = 30_000;
|
|
9
|
+
const minimumsCache = new Map();
|
|
10
|
+
const minimumsLoads = new Map();
|
|
11
|
+
function nullableString(value) {
|
|
12
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
13
|
+
}
|
|
14
|
+
async function loadVersionMinimums(appName) {
|
|
15
|
+
const cached = minimumsCache.get(appName);
|
|
16
|
+
if (cached && cached.expiresAt > Date.now())
|
|
17
|
+
return cached.value;
|
|
18
|
+
const pending = minimumsLoads.get(appName);
|
|
19
|
+
if (pending)
|
|
20
|
+
return pending;
|
|
21
|
+
const load = (async () => {
|
|
22
|
+
const specs = await vr_models_1.AppSpecs.getByAppName(appName);
|
|
23
|
+
const value = {
|
|
24
|
+
androidVersion: nullableString(specs?.minimumAndroidAppVersion),
|
|
25
|
+
androidBuild: typeof specs?.minimumAndroidAppBuild === "number"
|
|
26
|
+
? specs.minimumAndroidAppBuild
|
|
27
|
+
: null,
|
|
28
|
+
iosVersion: nullableString(specs?.minimumIosAppVersion),
|
|
29
|
+
iosBuild: nullableString(specs?.minimumIosAppBuild),
|
|
30
|
+
forceUpdateMessage: nullableString(specs?.forceUpdateMessage),
|
|
31
|
+
};
|
|
32
|
+
minimumsCache.set(appName, { value, expiresAt: Date.now() + CACHE_TTL_MS });
|
|
33
|
+
return value;
|
|
34
|
+
})();
|
|
35
|
+
minimumsLoads.set(appName, load);
|
|
36
|
+
try {
|
|
37
|
+
return await load;
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
if (minimumsLoads.get(appName) === load)
|
|
41
|
+
minimumsLoads.delete(appName);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Clear this process's cached app-version policy after an AppSpecs update. */
|
|
45
|
+
function clearAppVersionMinimumsCache(appName) {
|
|
46
|
+
if (appName)
|
|
47
|
+
minimumsCache.delete(appName);
|
|
48
|
+
else
|
|
49
|
+
minimumsCache.clear();
|
|
50
|
+
}
|
|
51
|
+
function parseDottedNumbers(value) {
|
|
52
|
+
if (!/^\d+(?:\.\d+)*$/.test(value))
|
|
53
|
+
return null;
|
|
54
|
+
const parts = value.split(".").map(Number);
|
|
55
|
+
return parts.every(Number.isSafeInteger) ? parts : null;
|
|
56
|
+
}
|
|
57
|
+
function compareDottedNumbers(left, right) {
|
|
58
|
+
const leftParts = parseDottedNumbers(left);
|
|
59
|
+
const rightParts = parseDottedNumbers(right);
|
|
60
|
+
if (!leftParts || !rightParts)
|
|
61
|
+
return null;
|
|
62
|
+
const length = Math.max(leftParts.length, rightParts.length);
|
|
63
|
+
for (let index = 0; index < length; index += 1) {
|
|
64
|
+
const leftPart = leftParts[index] ?? 0;
|
|
65
|
+
const rightPart = rightParts[index] ?? 0;
|
|
66
|
+
if (leftPart !== rightPart)
|
|
67
|
+
return leftPart < rightPart ? -1 : 1;
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
function compareBuild(platform, current, minimum) {
|
|
72
|
+
if (platform === "android") {
|
|
73
|
+
if (!/^\d+$/.test(current) || !/^\d+$/.test(minimum))
|
|
74
|
+
return null;
|
|
75
|
+
const currentNumber = Number(current);
|
|
76
|
+
const minimumNumber = Number(minimum);
|
|
77
|
+
if (!Number.isSafeInteger(currentNumber) || !Number.isSafeInteger(minimumNumber))
|
|
78
|
+
return null;
|
|
79
|
+
return currentNumber === minimumNumber ? 0 : currentNumber < minimumNumber ? -1 : 1;
|
|
80
|
+
}
|
|
81
|
+
return compareDottedNumbers(current, minimum);
|
|
82
|
+
}
|
|
83
|
+
function compareAppVersion(current, minimum) {
|
|
84
|
+
const currentParts = parseDottedNumbers(current);
|
|
85
|
+
const minimumParts = parseDottedNumbers(minimum);
|
|
86
|
+
if (!currentParts || !minimumParts || currentParts.length !== 3 || minimumParts.length !== 3) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return compareDottedNumbers(current, minimum);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Enforce the platform-specific minimum app version/build for requests that
|
|
93
|
+
* explicitly identify as Viberide mobile. Requests from Postman, tests, and
|
|
94
|
+
* other clients without X-App-Client pass through unchanged.
|
|
95
|
+
*/
|
|
96
|
+
function enforceMinimumMobileAppVersion(appName = DEFAULT_APP_NAME) {
|
|
97
|
+
return async (req, res, next) => {
|
|
98
|
+
const appClient = req.get("X-App-Client")?.trim() || null;
|
|
99
|
+
const platformHeader = req.get("X-App-Platform")?.trim().toLowerCase() || null;
|
|
100
|
+
const appVersion = req.get("X-App-Version")?.trim() || null;
|
|
101
|
+
const appBuild = req.get("X-App-Build")?.trim() || null;
|
|
102
|
+
// Log only app metadata; never dump authorization or other request headers.
|
|
103
|
+
console.info("[APP VERSION REQUEST]", { appClient, platform: platformHeader, appVersion, appBuild });
|
|
104
|
+
if (appClient?.toUpperCase() !== MOBILE_APP_CLIENT) {
|
|
105
|
+
next();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if ((platformHeader !== "android" && platformHeader !== "ios") ||
|
|
109
|
+
!appVersion ||
|
|
110
|
+
!appBuild) {
|
|
111
|
+
res.status(400).json({
|
|
112
|
+
success: false,
|
|
113
|
+
code: "INVALID_APP_VERSION_HEADERS",
|
|
114
|
+
message: "The mobile app version headers are missing or invalid.",
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const platform = platformHeader;
|
|
119
|
+
const parsedVersion = parseDottedNumbers(appVersion);
|
|
120
|
+
const parsedBuild = platform === "android"
|
|
121
|
+
? /^\d+$/.test(appBuild) && Number.isSafeInteger(Number(appBuild))
|
|
122
|
+
: parseDottedNumbers(appBuild) !== null;
|
|
123
|
+
if (!parsedVersion || parsedVersion.length !== 3 || !parsedBuild) {
|
|
124
|
+
res.status(400).json({
|
|
125
|
+
success: false,
|
|
126
|
+
code: "INVALID_APP_VERSION_HEADERS",
|
|
127
|
+
message: "The mobile app version headers are missing or invalid.",
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const minimums = await loadVersionMinimums(appName);
|
|
133
|
+
const minimumVersion = platform === "android"
|
|
134
|
+
? minimums.androidVersion
|
|
135
|
+
: minimums.iosVersion;
|
|
136
|
+
const minimumBuildValue = platform === "android"
|
|
137
|
+
? minimums.androidBuild
|
|
138
|
+
: minimums.iosBuild;
|
|
139
|
+
const minimumBuild = minimumBuildValue === null ? null : String(minimumBuildValue);
|
|
140
|
+
const versionComparison = minimumVersion
|
|
141
|
+
? compareAppVersion(appVersion, minimumVersion)
|
|
142
|
+
: null;
|
|
143
|
+
const buildComparison = minimumBuild
|
|
144
|
+
? compareBuild(platform, appBuild, minimumBuild)
|
|
145
|
+
: null;
|
|
146
|
+
if (versionComparison === null && minimumVersion) {
|
|
147
|
+
throw new Error(`Invalid configured minimum ${platform} app version: ${minimumVersion}`);
|
|
148
|
+
}
|
|
149
|
+
if (buildComparison === null && minimumBuild) {
|
|
150
|
+
throw new Error(`Invalid configured minimum ${platform} app build: ${minimumBuild}`);
|
|
151
|
+
}
|
|
152
|
+
const belowVersion = versionComparison !== null && versionComparison < 0;
|
|
153
|
+
const belowBuild = buildComparison !== null && buildComparison < 0;
|
|
154
|
+
if (belowVersion || belowBuild) {
|
|
155
|
+
res.status(426).json({
|
|
156
|
+
success: false,
|
|
157
|
+
code: "APP_UPDATE_REQUIRED",
|
|
158
|
+
message: minimums.forceUpdateMessage || "Please update Viberide to continue.",
|
|
159
|
+
data: {
|
|
160
|
+
platform,
|
|
161
|
+
minimumAppVersion: minimumVersion,
|
|
162
|
+
minimumAppBuild: minimumBuild,
|
|
163
|
+
currentAppVersion: appVersion,
|
|
164
|
+
currentAppBuild: appBuild,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
next();
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
next(error);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
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
|
+
}
|
|
@@ -45,17 +45,17 @@ export declare const listPlansSchema: z.ZodObject<{
|
|
|
45
45
|
status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
|
|
46
46
|
isOverdue?: "true" | "false" | undefined;
|
|
47
47
|
sortBy?: "createdAt" | "updatedAt" | "paidAmount" | "outstandingAmount" | "nextInstallmentDueAt" | undefined;
|
|
48
|
-
sortOrder?: "
|
|
48
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
49
49
|
deviceId?: string | undefined;
|
|
50
50
|
}, {
|
|
51
51
|
search?: string | undefined;
|
|
52
52
|
limit?: string | undefined;
|
|
53
53
|
userId?: string | undefined;
|
|
54
|
-
page?: string | undefined;
|
|
55
54
|
status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
|
|
56
55
|
isOverdue?: "true" | "false" | undefined;
|
|
56
|
+
page?: string | undefined;
|
|
57
57
|
sortBy?: "createdAt" | "updatedAt" | "paidAmount" | "outstandingAmount" | "nextInstallmentDueAt" | undefined;
|
|
58
|
-
sortOrder?: "
|
|
58
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
59
59
|
deviceId?: string | undefined;
|
|
60
60
|
}>;
|
|
61
61
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -67,7 +67,7 @@ export declare const listPlansSchema: z.ZodObject<{
|
|
|
67
67
|
status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
|
|
68
68
|
isOverdue?: "true" | "false" | undefined;
|
|
69
69
|
sortBy?: "createdAt" | "updatedAt" | "paidAmount" | "outstandingAmount" | "nextInstallmentDueAt" | undefined;
|
|
70
|
-
sortOrder?: "
|
|
70
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
71
71
|
deviceId?: string | undefined;
|
|
72
72
|
};
|
|
73
73
|
}, {
|
|
@@ -75,11 +75,11 @@ export declare const listPlansSchema: z.ZodObject<{
|
|
|
75
75
|
search?: string | undefined;
|
|
76
76
|
limit?: string | undefined;
|
|
77
77
|
userId?: string | undefined;
|
|
78
|
-
page?: string | undefined;
|
|
79
78
|
status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
|
|
80
79
|
isOverdue?: "true" | "false" | undefined;
|
|
80
|
+
page?: string | undefined;
|
|
81
81
|
sortBy?: "createdAt" | "updatedAt" | "paidAmount" | "outstandingAmount" | "nextInstallmentDueAt" | undefined;
|
|
82
|
-
sortOrder?: "
|
|
82
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
83
83
|
deviceId?: string | undefined;
|
|
84
84
|
};
|
|
85
85
|
}>;
|
|
@@ -68,23 +68,23 @@ export declare const getDevicesSchema: z.ZodObject<{
|
|
|
68
68
|
}, "strip", z.ZodTypeAny, {
|
|
69
69
|
search?: string | undefined;
|
|
70
70
|
limit?: number | undefined;
|
|
71
|
-
page?: number | undefined;
|
|
72
71
|
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
73
72
|
productId?: string | undefined;
|
|
73
|
+
page?: number | undefined;
|
|
74
74
|
sortBy?: "createdAt" | "updatedAt" | "status" | "serialNumber" | undefined;
|
|
75
|
-
sortOrder?: "
|
|
76
|
-
dedicatedUser?: "
|
|
75
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
76
|
+
dedicatedUser?: "PASSENGER" | "RIDER" | "N/A" | undefined;
|
|
77
77
|
isPermanentlyUnlocked?: "true" | "false" | undefined;
|
|
78
78
|
isAssigned?: "true" | "false" | undefined;
|
|
79
79
|
}, {
|
|
80
80
|
search?: string | undefined;
|
|
81
81
|
limit?: string | undefined;
|
|
82
|
-
page?: string | undefined;
|
|
83
82
|
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
84
83
|
productId?: string | undefined;
|
|
84
|
+
page?: string | undefined;
|
|
85
85
|
sortBy?: "createdAt" | "updatedAt" | "status" | "serialNumber" | undefined;
|
|
86
|
-
sortOrder?: "
|
|
87
|
-
dedicatedUser?: "
|
|
86
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
87
|
+
dedicatedUser?: "PASSENGER" | "RIDER" | "N/A" | undefined;
|
|
88
88
|
isPermanentlyUnlocked?: "true" | "false" | undefined;
|
|
89
89
|
isAssigned?: "true" | "false" | undefined;
|
|
90
90
|
}>;
|
|
@@ -92,12 +92,12 @@ export declare const getDevicesSchema: z.ZodObject<{
|
|
|
92
92
|
query: {
|
|
93
93
|
search?: string | undefined;
|
|
94
94
|
limit?: number | undefined;
|
|
95
|
-
page?: number | undefined;
|
|
96
95
|
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
97
96
|
productId?: string | undefined;
|
|
97
|
+
page?: number | undefined;
|
|
98
98
|
sortBy?: "createdAt" | "updatedAt" | "status" | "serialNumber" | undefined;
|
|
99
|
-
sortOrder?: "
|
|
100
|
-
dedicatedUser?: "
|
|
99
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
100
|
+
dedicatedUser?: "PASSENGER" | "RIDER" | "N/A" | undefined;
|
|
101
101
|
isPermanentlyUnlocked?: "true" | "false" | undefined;
|
|
102
102
|
isAssigned?: "true" | "false" | undefined;
|
|
103
103
|
};
|
|
@@ -105,12 +105,12 @@ export declare const getDevicesSchema: z.ZodObject<{
|
|
|
105
105
|
query: {
|
|
106
106
|
search?: string | undefined;
|
|
107
107
|
limit?: string | undefined;
|
|
108
|
-
page?: string | undefined;
|
|
109
108
|
status?: "locked" | "unlocked" | "disabled" | undefined;
|
|
110
109
|
productId?: string | undefined;
|
|
110
|
+
page?: string | undefined;
|
|
111
111
|
sortBy?: "createdAt" | "updatedAt" | "status" | "serialNumber" | undefined;
|
|
112
|
-
sortOrder?: "
|
|
113
|
-
dedicatedUser?: "
|
|
112
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
113
|
+
dedicatedUser?: "PASSENGER" | "RIDER" | "N/A" | undefined;
|
|
114
114
|
isPermanentlyUnlocked?: "true" | "false" | undefined;
|
|
115
115
|
isAssigned?: "true" | "false" | undefined;
|
|
116
116
|
};
|
|
@@ -20,19 +20,19 @@ export declare const listEventLogsSchema: z.ZodObject<{
|
|
|
20
20
|
}, "strip", z.ZodTypeAny, {
|
|
21
21
|
limit: number;
|
|
22
22
|
page: number;
|
|
23
|
-
sortBy: "createdAt" | "
|
|
24
|
-
sortOrder: "
|
|
23
|
+
sortBy: "createdAt" | "actorType" | "action" | "entity";
|
|
24
|
+
sortOrder: "DESC" | "ASC";
|
|
25
25
|
hasDeviceSession: boolean;
|
|
26
26
|
search?: string | undefined;
|
|
27
27
|
firstName?: string | undefined;
|
|
28
28
|
lastName?: string | undefined;
|
|
29
|
-
|
|
29
|
+
fromDate?: string | undefined;
|
|
30
|
+
toDate?: string | undefined;
|
|
31
|
+
actorType?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
|
|
30
32
|
actorId?: string | undefined;
|
|
31
33
|
action?: string | undefined;
|
|
32
34
|
entity?: string | undefined;
|
|
33
|
-
|
|
34
|
-
toDate?: string | undefined;
|
|
35
|
-
actorType?: "RIDER" | "PASSENGER" | "AGENT" | "ADMIN" | "SUPER_ADMIN" | undefined;
|
|
35
|
+
entityId?: string | undefined;
|
|
36
36
|
actorName?: string | undefined;
|
|
37
37
|
}, {
|
|
38
38
|
search?: string | undefined;
|
|
@@ -40,15 +40,15 @@ export declare const listEventLogsSchema: z.ZodObject<{
|
|
|
40
40
|
firstName?: string | undefined;
|
|
41
41
|
lastName?: string | undefined;
|
|
42
42
|
page?: string | undefined;
|
|
43
|
-
|
|
43
|
+
sortBy?: "createdAt" | "actorType" | "action" | "entity" | undefined;
|
|
44
|
+
fromDate?: string | undefined;
|
|
45
|
+
toDate?: string | undefined;
|
|
46
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
47
|
+
actorType?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
|
|
44
48
|
actorId?: string | undefined;
|
|
45
49
|
action?: string | undefined;
|
|
46
50
|
entity?: string | undefined;
|
|
47
|
-
|
|
48
|
-
fromDate?: string | undefined;
|
|
49
|
-
toDate?: string | undefined;
|
|
50
|
-
sortOrder?: "ASC" | "DESC" | undefined;
|
|
51
|
-
actorType?: "RIDER" | "PASSENGER" | "AGENT" | "ADMIN" | "SUPER_ADMIN" | undefined;
|
|
51
|
+
entityId?: string | undefined;
|
|
52
52
|
actorName?: string | undefined;
|
|
53
53
|
hasDeviceSession?: string | undefined;
|
|
54
54
|
}>, any, {
|
|
@@ -57,15 +57,15 @@ export declare const listEventLogsSchema: z.ZodObject<{
|
|
|
57
57
|
firstName?: string | undefined;
|
|
58
58
|
lastName?: string | undefined;
|
|
59
59
|
page?: string | undefined;
|
|
60
|
-
|
|
60
|
+
sortBy?: "createdAt" | "actorType" | "action" | "entity" | undefined;
|
|
61
|
+
fromDate?: string | undefined;
|
|
62
|
+
toDate?: string | undefined;
|
|
63
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
64
|
+
actorType?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
|
|
61
65
|
actorId?: string | undefined;
|
|
62
66
|
action?: string | undefined;
|
|
63
67
|
entity?: string | undefined;
|
|
64
|
-
|
|
65
|
-
fromDate?: string | undefined;
|
|
66
|
-
toDate?: string | undefined;
|
|
67
|
-
sortOrder?: "ASC" | "DESC" | undefined;
|
|
68
|
-
actorType?: "RIDER" | "PASSENGER" | "AGENT" | "ADMIN" | "SUPER_ADMIN" | undefined;
|
|
68
|
+
entityId?: string | undefined;
|
|
69
69
|
actorName?: string | undefined;
|
|
70
70
|
hasDeviceSession?: string | undefined;
|
|
71
71
|
}>;
|
|
@@ -78,15 +78,15 @@ export declare const listEventLogsSchema: z.ZodObject<{
|
|
|
78
78
|
firstName?: string | undefined;
|
|
79
79
|
lastName?: string | undefined;
|
|
80
80
|
page?: string | undefined;
|
|
81
|
-
|
|
81
|
+
sortBy?: "createdAt" | "actorType" | "action" | "entity" | undefined;
|
|
82
|
+
fromDate?: string | undefined;
|
|
83
|
+
toDate?: string | undefined;
|
|
84
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
85
|
+
actorType?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
|
|
82
86
|
actorId?: string | undefined;
|
|
83
87
|
action?: string | undefined;
|
|
84
88
|
entity?: string | undefined;
|
|
85
|
-
|
|
86
|
-
fromDate?: string | undefined;
|
|
87
|
-
toDate?: string | undefined;
|
|
88
|
-
sortOrder?: "ASC" | "DESC" | undefined;
|
|
89
|
-
actorType?: "RIDER" | "PASSENGER" | "AGENT" | "ADMIN" | "SUPER_ADMIN" | undefined;
|
|
89
|
+
entityId?: string | undefined;
|
|
90
90
|
actorName?: string | undefined;
|
|
91
91
|
hasDeviceSession?: string | undefined;
|
|
92
92
|
};
|
|
@@ -7,27 +7,27 @@ export declare const getInstallmentsSchema: z.ZodObject<{
|
|
|
7
7
|
limit: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
|
|
8
8
|
}, "strip", z.ZodTypeAny, {
|
|
9
9
|
limit?: number | undefined;
|
|
10
|
-
page?: number | undefined;
|
|
11
10
|
status?: "PENDING" | "PAID" | "OVERDUE" | "SKIPPED" | undefined;
|
|
11
|
+
page?: number | undefined;
|
|
12
12
|
planId?: string | undefined;
|
|
13
13
|
}, {
|
|
14
14
|
limit?: string | undefined;
|
|
15
|
-
page?: string | undefined;
|
|
16
15
|
status?: "PENDING" | "PAID" | "OVERDUE" | "SKIPPED" | undefined;
|
|
16
|
+
page?: string | undefined;
|
|
17
17
|
planId?: string | undefined;
|
|
18
18
|
}>;
|
|
19
19
|
}, "strip", z.ZodTypeAny, {
|
|
20
20
|
query: {
|
|
21
21
|
limit?: number | undefined;
|
|
22
|
-
page?: number | undefined;
|
|
23
22
|
status?: "PENDING" | "PAID" | "OVERDUE" | "SKIPPED" | undefined;
|
|
23
|
+
page?: number | undefined;
|
|
24
24
|
planId?: string | undefined;
|
|
25
25
|
};
|
|
26
26
|
}, {
|
|
27
27
|
query: {
|
|
28
28
|
limit?: string | undefined;
|
|
29
|
-
page?: string | undefined;
|
|
30
29
|
status?: "PENDING" | "PAID" | "OVERDUE" | "SKIPPED" | undefined;
|
|
30
|
+
page?: string | undefined;
|
|
31
31
|
planId?: string | undefined;
|
|
32
32
|
};
|
|
33
33
|
}>;
|
|
@@ -249,10 +249,10 @@ export declare const getPricingsSchema: z.ZodObject<{
|
|
|
249
249
|
type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
|
|
250
250
|
limit?: number | undefined;
|
|
251
251
|
isActive?: "true" | "false" | undefined;
|
|
252
|
-
page?: number | undefined;
|
|
253
252
|
productId?: string | undefined;
|
|
253
|
+
page?: number | undefined;
|
|
254
254
|
sortBy?: "createdAt" | "updatedAt" | "name" | "unitPrice" | undefined;
|
|
255
|
-
sortOrder?: "
|
|
255
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
256
256
|
minAmount?: number | undefined;
|
|
257
257
|
maxAmount?: number | undefined;
|
|
258
258
|
}, {
|
|
@@ -260,10 +260,10 @@ export declare const getPricingsSchema: z.ZodObject<{
|
|
|
260
260
|
type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
|
|
261
261
|
limit?: string | undefined;
|
|
262
262
|
isActive?: "true" | "false" | undefined;
|
|
263
|
-
page?: string | undefined;
|
|
264
263
|
productId?: string | undefined;
|
|
264
|
+
page?: string | undefined;
|
|
265
265
|
sortBy?: "createdAt" | "updatedAt" | "name" | "unitPrice" | undefined;
|
|
266
|
-
sortOrder?: "
|
|
266
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
267
267
|
minAmount?: string | undefined;
|
|
268
268
|
maxAmount?: string | undefined;
|
|
269
269
|
}>;
|
|
@@ -273,10 +273,10 @@ export declare const getPricingsSchema: z.ZodObject<{
|
|
|
273
273
|
type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
|
|
274
274
|
limit?: number | undefined;
|
|
275
275
|
isActive?: "true" | "false" | undefined;
|
|
276
|
-
page?: number | undefined;
|
|
277
276
|
productId?: string | undefined;
|
|
277
|
+
page?: number | undefined;
|
|
278
278
|
sortBy?: "createdAt" | "updatedAt" | "name" | "unitPrice" | undefined;
|
|
279
|
-
sortOrder?: "
|
|
279
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
280
280
|
minAmount?: number | undefined;
|
|
281
281
|
maxAmount?: number | undefined;
|
|
282
282
|
};
|
|
@@ -286,10 +286,10 @@ export declare const getPricingsSchema: z.ZodObject<{
|
|
|
286
286
|
type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
|
|
287
287
|
limit?: string | undefined;
|
|
288
288
|
isActive?: "true" | "false" | undefined;
|
|
289
|
-
page?: string | undefined;
|
|
290
289
|
productId?: string | undefined;
|
|
290
|
+
page?: string | undefined;
|
|
291
291
|
sortBy?: "createdAt" | "updatedAt" | "name" | "unitPrice" | undefined;
|
|
292
|
-
sortOrder?: "
|
|
292
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
293
293
|
minAmount?: string | undefined;
|
|
294
294
|
maxAmount?: string | undefined;
|
|
295
295
|
};
|