vr-commons 1.0.60 → 1.0.62
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/auth.middlewares.js +23 -21
- package/dist/utils/authTokens.utils.d.ts +6 -5
- package/dist/utils/authTokens.utils.js +27 -19
- package/dist/utils/eventLog.utils.d.ts +3 -3
- package/dist/utils/eventLog.utils.js +2 -2
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +2 -4
- package/dist/utils/session.utils.d.ts +4 -15
- package/dist/utils/session.utils.js +11 -54
- package/dist/validations/appSpecs.validations.d.ts +18 -18
- package/dist/validations/appeals.validations.d.ts +8 -8
- package/dist/validations/auth.validations.d.ts +2 -2
- package/dist/validations/bans.validations.d.ts +8 -8
- package/dist/validations/devicePaymentPlan.validations.d.ts +17 -17
- package/dist/validations/devices.validations.d.ts +4 -4
- package/dist/validations/moderation.validations.d.ts +77 -77
- package/dist/validations/payinstallment.validations.d.ts +5 -5
- package/dist/validations/profiles.validations.d.ts +38 -38
- package/dist/validations/suspensions.validations.d.ts +8 -8
- package/package.json +2 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// src/middlewares/auth/checkUserAuthentication.middleware.ts
|
|
3
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
4
|
};
|
|
@@ -8,6 +7,7 @@ exports.checkUserAuthentication = void 0;
|
|
|
8
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
9
8
|
const vr_models_1 = require("vr-models");
|
|
10
9
|
const __1 = require("..");
|
|
10
|
+
const authTokens_utils_1 = require("../utils/authTokens.utils");
|
|
11
11
|
const checkUserAuthentication = (allowedRoles) => async (req, res, next) => {
|
|
12
12
|
try {
|
|
13
13
|
const authHeader = req.headers.authorization;
|
|
@@ -21,14 +21,10 @@ const checkUserAuthentication = (allowedRoles) => async (req, res, next) => {
|
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|
|
23
23
|
if (error instanceof jsonwebtoken_1.default.TokenExpiredError) {
|
|
24
|
-
return (0, __1.sendErrorResponse)(res, "Token expired", 401);
|
|
24
|
+
return (0, __1.sendErrorResponse)(res, "Token expired. Please re-verify your phone.", 401);
|
|
25
25
|
}
|
|
26
26
|
return (0, __1.sendErrorResponse)(res, "Token invalid", 401);
|
|
27
27
|
}
|
|
28
|
-
// Validate that sessionId exists in payload
|
|
29
|
-
if (!payload.sessionId) {
|
|
30
|
-
return (0, __1.sendErrorResponse)(res, "Invalid token format: missing session", 401);
|
|
31
|
-
}
|
|
32
28
|
const user = await vr_models_1.User.findOne({
|
|
33
29
|
where: { id: payload.userId },
|
|
34
30
|
include: [
|
|
@@ -45,34 +41,40 @@ const checkUserAuthentication = (allowedRoles) => async (req, res, next) => {
|
|
|
45
41
|
// Check account moderation status
|
|
46
42
|
const moderation = await (0, __1.checkIsUserBannedOrSuspended)(user.id);
|
|
47
43
|
if (moderation.isRestricted) {
|
|
48
|
-
return (0, __1.sendErrorResponse)(res, "
|
|
44
|
+
return (0, __1.sendErrorResponse)(res, "Account restricted", 403, moderation);
|
|
49
45
|
}
|
|
50
46
|
// 🔐 Token versioning (logout all devices)
|
|
51
47
|
if (user.tokenVersion !== payload.tokenVersion) {
|
|
52
|
-
return (0, __1.sendErrorResponse)(res, "Session expired -
|
|
48
|
+
return (0, __1.sendErrorResponse)(res, "Session expired. Please re-verify your phone.", 401);
|
|
53
49
|
}
|
|
54
50
|
// 🧱 Role enforcement
|
|
55
51
|
if (!allowedRoles.includes(user.securityClearance.role)) {
|
|
56
52
|
return (0, __1.sendErrorResponse)(res, "Access denied", 403);
|
|
57
53
|
}
|
|
58
|
-
//
|
|
59
|
-
const currentTime = Math.floor(Date.now() / 1000);
|
|
60
|
-
const session = {
|
|
61
|
-
sessionId: payload.sessionId,
|
|
62
|
-
startedAt: payload.iat ? payload.iat * 1000 : Date.now(), // Convert to ms if exists
|
|
63
|
-
expiresAt: payload.exp
|
|
64
|
-
? payload.exp * 1000
|
|
65
|
-
: Date.now() + 15 * 60 * 1000, // Default 15min if no exp
|
|
66
|
-
userId: user.id,
|
|
67
|
-
tokenVersion: user.tokenVersion,
|
|
68
|
-
};
|
|
69
|
-
// ✅ Extend req with user info AND session
|
|
54
|
+
// ✅ Extend req with user info
|
|
70
55
|
req.userId = user.id;
|
|
71
56
|
req.firstName = user.firstName;
|
|
72
57
|
req.lastName = user.lastName;
|
|
73
58
|
req.scRole = user.securityClearance.role;
|
|
74
59
|
req.scLevel = user.securityClearance.level;
|
|
75
|
-
req.
|
|
60
|
+
req.tokenVersion = user.tokenVersion;
|
|
61
|
+
// Optional: Add sessionId if present in payload (for backward compatibility)
|
|
62
|
+
if (payload.sessionId) {
|
|
63
|
+
req.sessionId = payload.sessionId;
|
|
64
|
+
}
|
|
65
|
+
// 🔄 Auto-refresh token if it's about to expire (within 5 days)
|
|
66
|
+
if ((0, authTokens_utils_1.shouldRefreshToken)(token)) {
|
|
67
|
+
const newToken = (0, authTokens_utils_1.generateToken)(user.id, user.securityClearance.role, user.securityClearance.level, user.tokenVersion, payload.sessionId, // Preserve sessionId if exists
|
|
68
|
+
user.securityClearance.role === "ADMIN"
|
|
69
|
+
? "ADMIN"
|
|
70
|
+
: user.securityClearance.role === "RIDER"
|
|
71
|
+
? "RIDER"
|
|
72
|
+
: "PASSENGER");
|
|
73
|
+
// Set new token in response header for client to update
|
|
74
|
+
res.setHeader("X-New-Token", newToken);
|
|
75
|
+
res.setHeader("X-Token-Refreshed", "true");
|
|
76
|
+
console.log(`🔄 Auto-refreshed token for user ${user.id}`);
|
|
77
|
+
}
|
|
76
78
|
next();
|
|
77
79
|
}
|
|
78
80
|
catch (error) {
|
|
@@ -4,14 +4,15 @@ export interface JWTPayload {
|
|
|
4
4
|
role: string;
|
|
5
5
|
level: number;
|
|
6
6
|
tokenVersion: number;
|
|
7
|
-
sessionId
|
|
7
|
+
sessionId?: string;
|
|
8
8
|
iat?: number;
|
|
9
9
|
exp?: number;
|
|
10
10
|
}
|
|
11
|
-
export declare const generateToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId
|
|
12
|
-
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
11
|
+
export declare const generateToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId?: string, // Made optional for new flow
|
|
12
|
+
type?: "ADMIN" | "PASSENGER" | "RIDER") => string;
|
|
13
|
+
export declare const generateAdminToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId?: string) => string;
|
|
14
|
+
export declare const generatePassengerToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId?: string) => string;
|
|
15
|
+
export declare const generateRiderToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId?: string) => string;
|
|
15
16
|
export declare const verifyToken: (token: string) => Promise<JWTPayload>;
|
|
16
17
|
export declare const shouldRefreshToken: (token: string) => boolean;
|
|
17
18
|
export declare const getTokenTimeRemaining: (token: string) => number | null;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.formatTimeRemaining = exports.getTokenTimeRemaining = exports.shouldRefreshToken = exports.verifyToken = exports.generateRiderToken = exports.generatePassengerToken = exports.generateAdminToken = exports.generateToken = void 0;
|
|
7
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
// Get token lifespan from env with fallback to
|
|
8
|
+
// Get token lifespan from env with fallback to 30 days (in seconds)
|
|
9
9
|
const getTokenLifespan = (type) => {
|
|
10
10
|
const envVar = `${type}_TOKEN_LIFE_SPAN`;
|
|
11
11
|
const value = process.env[envVar];
|
|
@@ -15,23 +15,24 @@ const getTokenLifespan = (type) => {
|
|
|
15
15
|
return parsed;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
// Default to
|
|
19
|
-
console.warn(`⚠️ ${envVar} not set or invalid, using default
|
|
20
|
-
return
|
|
18
|
+
// Default to 30 days (2,592,000 seconds)
|
|
19
|
+
console.warn(`⚠️ ${envVar} not set or invalid, using default 30 days (2,592,000 seconds)`);
|
|
20
|
+
return 30 * 24 * 60 * 60;
|
|
21
21
|
};
|
|
22
|
-
// Helper to
|
|
23
|
-
const generateToken = (userId, role, level, tokenVersion, sessionId,
|
|
22
|
+
// Helper to generate token with 30-day expiry
|
|
23
|
+
const generateToken = (userId, role, level, tokenVersion, sessionId, // Made optional for new flow
|
|
24
|
+
type = "PASSENGER") => {
|
|
24
25
|
const payload = {
|
|
25
26
|
userId,
|
|
26
27
|
role,
|
|
27
28
|
level,
|
|
28
29
|
tokenVersion,
|
|
29
|
-
sessionId,
|
|
30
|
+
...(sessionId && { sessionId }), // Only include sessionId if provided
|
|
30
31
|
};
|
|
31
32
|
const expiresIn = getTokenLifespan(type);
|
|
32
|
-
console.log(`🔐 Generating ${type} token for user ${userId} with ${expiresIn}s expiry`);
|
|
33
|
+
console.log(`🔐 Generating ${type} token for user ${userId} with ${expiresIn}s expiry (${expiresIn / 86400} days)`);
|
|
33
34
|
return jsonwebtoken_1.default.sign(payload, process.env.JWT_SECRET, {
|
|
34
|
-
expiresIn,
|
|
35
|
+
expiresIn,
|
|
35
36
|
});
|
|
36
37
|
};
|
|
37
38
|
exports.generateToken = generateToken;
|
|
@@ -55,9 +56,10 @@ const verifyToken = async (token) => {
|
|
|
55
56
|
// Log token expiration info for debugging
|
|
56
57
|
if (decoded.exp) {
|
|
57
58
|
const expiresIn = decoded.exp - Math.floor(Date.now() / 1000);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const daysRemaining = expiresIn / 86400;
|
|
60
|
+
console.log(`🔍 Token expires in ${expiresIn} seconds (${daysRemaining.toFixed(1)} days)`);
|
|
61
|
+
if (expiresIn < 5 * 24 * 60 * 60) {
|
|
62
|
+
// Less than 5 days
|
|
61
63
|
console.warn(`⚠️ Token expiring soon: ${expiresIn} seconds remaining`);
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -76,7 +78,7 @@ const verifyToken = async (token) => {
|
|
|
76
78
|
}
|
|
77
79
|
};
|
|
78
80
|
exports.verifyToken = verifyToken;
|
|
79
|
-
// Helper to check if token needs refresh (within 5
|
|
81
|
+
// Helper to check if token needs refresh (within 5 days of expiry)
|
|
80
82
|
const shouldRefreshToken = (token) => {
|
|
81
83
|
try {
|
|
82
84
|
const decoded = jsonwebtoken_1.default.decode(token);
|
|
@@ -84,7 +86,7 @@ const shouldRefreshToken = (token) => {
|
|
|
84
86
|
return false;
|
|
85
87
|
const now = Math.floor(Date.now() / 1000);
|
|
86
88
|
const timeUntilExpiry = decoded.exp - now;
|
|
87
|
-
const refreshThreshold =
|
|
89
|
+
const refreshThreshold = 5 * 24 * 60 * 60; // 5 days in seconds
|
|
88
90
|
return timeUntilExpiry < refreshThreshold && timeUntilExpiry > 0;
|
|
89
91
|
}
|
|
90
92
|
catch {
|
|
@@ -108,10 +110,16 @@ const getTokenTimeRemaining = (token) => {
|
|
|
108
110
|
exports.getTokenTimeRemaining = getTokenTimeRemaining;
|
|
109
111
|
// Format time remaining in a human-readable format
|
|
110
112
|
const formatTimeRemaining = (seconds) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
113
|
+
const days = Math.floor(seconds / 86400);
|
|
114
|
+
const hours = Math.floor((seconds % 86400) / 3600);
|
|
115
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
116
|
+
const secs = seconds % 60;
|
|
117
|
+
if (days > 0)
|
|
118
|
+
return `${days} days, ${hours} hours`;
|
|
119
|
+
if (hours > 0)
|
|
120
|
+
return `${hours} hours, ${minutes} minutes`;
|
|
121
|
+
if (minutes > 0)
|
|
122
|
+
return `${minutes} minutes, ${secs} seconds`;
|
|
123
|
+
return `${secs} seconds`;
|
|
116
124
|
};
|
|
117
125
|
exports.formatTimeRemaining = formatTimeRemaining;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventAction, UserRole,
|
|
1
|
+
import { EventAction, UserRole, DeviceSessionPayload } from "vr-models";
|
|
2
2
|
import { Transaction } from "sequelize";
|
|
3
3
|
interface LogEventInput {
|
|
4
4
|
actorId?: string | null;
|
|
@@ -10,7 +10,7 @@ interface LogEventInput {
|
|
|
10
10
|
ipAddress?: string | null;
|
|
11
11
|
userAgent?: string | null;
|
|
12
12
|
transaction?: Transaction;
|
|
13
|
-
|
|
13
|
+
deviceSession: DeviceSessionPayload;
|
|
14
14
|
}
|
|
15
|
-
export declare const logEvent: ({ actorId, actorType, action, entity, entityId, metadata, ipAddress, userAgent, transaction,
|
|
15
|
+
export declare const logEvent: ({ actorId, actorType, action, entity, entityId, metadata, ipAddress, userAgent, transaction, deviceSession, }: LogEventInput) => Promise<void>;
|
|
16
16
|
export {};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.logEvent = void 0;
|
|
4
4
|
const vr_models_1 = require("vr-models");
|
|
5
|
-
const logEvent = async ({ actorId = null, actorType = "ADMIN", action, entity, entityId = null, metadata = {}, ipAddress = null, userAgent = null, transaction,
|
|
5
|
+
const logEvent = async ({ actorId = null, actorType = "ADMIN", action, entity, entityId = null, metadata = {}, ipAddress = null, userAgent = null, transaction, deviceSession, // Required session parameter matching the model
|
|
6
6
|
}) => {
|
|
7
7
|
try {
|
|
8
8
|
// Create event log with optional transaction
|
|
@@ -16,7 +16,7 @@ const logEvent = async ({ actorId = null, actorType = "ADMIN", action, entity, e
|
|
|
16
16
|
metadata,
|
|
17
17
|
ipAddress,
|
|
18
18
|
userAgent,
|
|
19
|
-
|
|
19
|
+
deviceSession, // Now passed as dedicated field matching the model
|
|
20
20
|
}, { transaction });
|
|
21
21
|
}
|
|
22
22
|
catch (err) {
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@ export { formatUserProfile, formatUserListResponse, hasRole, hasPermission, hasA
|
|
|
6
6
|
export { canModerate, canModerateUser, getModeratableRoles, hasHigherAuthority, } from "./moderation.utils";
|
|
7
7
|
export { banUtil } from "./bans.utils";
|
|
8
8
|
export { suspensionUtil } from "./suspension.utils";
|
|
9
|
-
export {
|
|
9
|
+
export { createDeviceSession } from "./session.utils";
|
|
10
10
|
export { generateOTP, getOTPExpiry, getVerificationMethod, sendEmail, sendSMS, sendVerificationCode, } from "./verification.utils";
|
|
11
11
|
export { PendingRegistration, VerificationMethod, ConfirmResponse, } from "./types";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendVerificationCode = exports.sendSMS = exports.sendEmail = exports.getVerificationMethod = exports.getOTPExpiry = exports.generateOTP = exports.
|
|
3
|
+
exports.sendVerificationCode = exports.sendSMS = exports.sendEmail = exports.getVerificationMethod = exports.getOTPExpiry = exports.generateOTP = exports.createDeviceSession = 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.verifyToken = exports.generateRiderToken = exports.generatePassengerToken = exports.generateAdminToken = exports.checkSuspensionStatus = exports.checkIsUserBannedOrSuspended = exports.checkBanStatus = exports.hasActiveDependencies = exports.checkAccountDependencies = void 0;
|
|
4
4
|
var account_utils_1 = require("./account.utils");
|
|
5
5
|
Object.defineProperty(exports, "checkAccountDependencies", { enumerable: true, get: function () { return account_utils_1.checkAccountDependencies; } });
|
|
6
6
|
Object.defineProperty(exports, "hasActiveDependencies", { enumerable: true, get: function () { return account_utils_1.hasActiveDependencies; } });
|
|
@@ -54,9 +54,7 @@ Object.defineProperty(exports, "banUtil", { enumerable: true, get: function () {
|
|
|
54
54
|
var suspension_utils_1 = require("./suspension.utils");
|
|
55
55
|
Object.defineProperty(exports, "suspensionUtil", { enumerable: true, get: function () { return suspension_utils_1.suspensionUtil; } });
|
|
56
56
|
var session_utils_1 = require("./session.utils");
|
|
57
|
-
Object.defineProperty(exports, "
|
|
58
|
-
Object.defineProperty(exports, "getTokenTimeRemaining", { enumerable: true, get: function () { return session_utils_1.getTokenTimeRemaining; } });
|
|
59
|
-
Object.defineProperty(exports, "shouldRefreshToken", { enumerable: true, get: function () { return session_utils_1.shouldRefreshToken; } });
|
|
57
|
+
Object.defineProperty(exports, "createDeviceSession", { enumerable: true, get: function () { return session_utils_1.createDeviceSession; } });
|
|
60
58
|
var verification_utils_1 = require("./verification.utils");
|
|
61
59
|
Object.defineProperty(exports, "generateOTP", { enumerable: true, get: function () { return verification_utils_1.generateOTP; } });
|
|
62
60
|
Object.defineProperty(exports, "getOTPExpiry", { enumerable: true, get: function () { return verification_utils_1.getOTPExpiry; } });
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DeviceSessionPayload } from "vr-models";
|
|
2
2
|
/**
|
|
3
|
-
* Create a new session
|
|
3
|
+
* Create a new device session (for BLE unlock)
|
|
4
|
+
* This is separate from the long-lasting auth token
|
|
4
5
|
*/
|
|
5
|
-
export declare const
|
|
6
|
-
/**
|
|
7
|
-
* Check if token needs refresh (within 5 minutes of expiry)
|
|
8
|
-
*/
|
|
9
|
-
export declare const shouldRefreshToken: (token: string) => boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Get time remaining on token in seconds
|
|
12
|
-
*/
|
|
13
|
-
export declare const getTokenTimeRemaining: (token: string) => number | null;
|
|
14
|
-
/**
|
|
15
|
-
* Format time remaining in a human-readable format
|
|
16
|
-
*/
|
|
17
|
-
export declare const formatTimeRemaining: (seconds: number) => string;
|
|
6
|
+
export declare const createDeviceSession: (userId: string, tokenVersion: number, deviceSerialNumber: string) => DeviceSessionPayload;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.createDeviceSession = void 0;
|
|
7
4
|
const uuid_1 = require("uuid");
|
|
8
|
-
|
|
9
|
-
const SESSION_DURATION = parseInt(process.env.
|
|
5
|
+
// Session duration for device unlock sessions (15 minutes)
|
|
6
|
+
const SESSION_DURATION = parseInt(process.env.DEVICE_SESSION_DURATION || "15") * 60 * 1000; // Convert minutes to milliseconds
|
|
10
7
|
/**
|
|
11
|
-
* Create a new session
|
|
8
|
+
* Create a new device session (for BLE unlock)
|
|
9
|
+
* This is separate from the long-lasting auth token
|
|
12
10
|
*/
|
|
13
|
-
const
|
|
11
|
+
const createDeviceSession = (userId, tokenVersion, deviceSerialNumber) => {
|
|
14
12
|
const now = Date.now();
|
|
15
13
|
return {
|
|
16
14
|
sessionId: (0, uuid_1.v4)(),
|
|
@@ -18,51 +16,10 @@ const createSession = (userId, tokenVersion) => {
|
|
|
18
16
|
expiresAt: now + SESSION_DURATION,
|
|
19
17
|
userId,
|
|
20
18
|
tokenVersion,
|
|
19
|
+
deviceSerialNumber,
|
|
20
|
+
minutesGranted: SESSION_DURATION,
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
|
-
exports.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
const shouldRefreshToken = (token) => {
|
|
28
|
-
try {
|
|
29
|
-
const decoded = jsonwebtoken_1.default.decode(token);
|
|
30
|
-
if (!decoded || !decoded.exp)
|
|
31
|
-
return false;
|
|
32
|
-
const now = Math.floor(Date.now() / 1000);
|
|
33
|
-
const timeUntilExpiry = decoded.exp - now;
|
|
34
|
-
const refreshThreshold = 300; // 5 minutes in seconds
|
|
35
|
-
return timeUntilExpiry < refreshThreshold && timeUntilExpiry > 0;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
exports.shouldRefreshToken = shouldRefreshToken;
|
|
42
|
-
/**
|
|
43
|
-
* Get time remaining on token in seconds
|
|
44
|
-
*/
|
|
45
|
-
const getTokenTimeRemaining = (token) => {
|
|
46
|
-
try {
|
|
47
|
-
const decoded = jsonwebtoken_1.default.decode(token);
|
|
48
|
-
if (!decoded || !decoded.exp)
|
|
49
|
-
return null;
|
|
50
|
-
const now = Math.floor(Date.now() / 1000);
|
|
51
|
-
return Math.max(0, decoded.exp - now);
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
exports.getTokenTimeRemaining = getTokenTimeRemaining;
|
|
58
|
-
/**
|
|
59
|
-
* Format time remaining in a human-readable format
|
|
60
|
-
*/
|
|
61
|
-
const formatTimeRemaining = (seconds) => {
|
|
62
|
-
if (seconds < 60)
|
|
63
|
-
return `${seconds} seconds`;
|
|
64
|
-
if (seconds < 3600)
|
|
65
|
-
return `${Math.floor(seconds / 60)} minutes ${seconds % 60} seconds`;
|
|
66
|
-
return `${Math.floor(seconds / 3600)} hours ${Math.floor((seconds % 3600) / 60)} minutes`;
|
|
67
|
-
};
|
|
68
|
-
exports.formatTimeRemaining = formatTimeRemaining;
|
|
23
|
+
exports.createDeviceSession = createDeviceSession;
|
|
24
|
+
// Note: We no longer need session-related functions for auth tokens
|
|
25
|
+
// since we're using a single 30-day token without session tracking
|
|
@@ -616,9 +616,6 @@ export declare const updateAppSpecsSchema: z.ZodObject<{
|
|
|
616
616
|
sentryDsn?: string | null | undefined;
|
|
617
617
|
}>;
|
|
618
618
|
}, "strip", z.ZodTypeAny, {
|
|
619
|
-
params: {
|
|
620
|
-
id: string;
|
|
621
|
-
};
|
|
622
619
|
body: {
|
|
623
620
|
appName?: string | undefined;
|
|
624
621
|
appShortName?: string | null | undefined;
|
|
@@ -695,10 +692,10 @@ export declare const updateAppSpecsSchema: z.ZodObject<{
|
|
|
695
692
|
facebookPixelId?: string | null | undefined;
|
|
696
693
|
sentryDsn?: string | null | undefined;
|
|
697
694
|
};
|
|
698
|
-
}, {
|
|
699
695
|
params: {
|
|
700
696
|
id: string;
|
|
701
697
|
};
|
|
698
|
+
}, {
|
|
702
699
|
body: {
|
|
703
700
|
appName?: string | undefined;
|
|
704
701
|
appShortName?: string | null | undefined;
|
|
@@ -775,6 +772,9 @@ export declare const updateAppSpecsSchema: z.ZodObject<{
|
|
|
775
772
|
facebookPixelId?: string | null | undefined;
|
|
776
773
|
sentryDsn?: string | null | undefined;
|
|
777
774
|
};
|
|
775
|
+
params: {
|
|
776
|
+
id: string;
|
|
777
|
+
};
|
|
778
778
|
}>;
|
|
779
779
|
export declare const listAppSpecsSchema: z.ZodObject<{
|
|
780
780
|
query: z.ZodObject<{
|
|
@@ -785,37 +785,37 @@ export declare const listAppSpecsSchema: z.ZodObject<{
|
|
|
785
785
|
sortBy: z.ZodOptional<z.ZodEnum<["version", "createdAt", "updatedAt"]>>;
|
|
786
786
|
sortOrder: z.ZodOptional<z.ZodEnum<["ASC", "DESC"]>>;
|
|
787
787
|
}, "strip", z.ZodTypeAny, {
|
|
788
|
-
page: number;
|
|
789
788
|
limit: number;
|
|
790
|
-
|
|
791
|
-
sortOrder?: "ASC" | "DESC" | undefined;
|
|
789
|
+
page: number;
|
|
792
790
|
search?: string | undefined;
|
|
793
791
|
isActive?: "true" | "false" | undefined;
|
|
794
|
-
}, {
|
|
795
|
-
page?: string | undefined;
|
|
796
|
-
limit?: string | undefined;
|
|
797
792
|
sortBy?: "createdAt" | "updatedAt" | "version" | undefined;
|
|
798
|
-
sortOrder?: "
|
|
793
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
794
|
+
}, {
|
|
799
795
|
search?: string | undefined;
|
|
796
|
+
limit?: string | undefined;
|
|
800
797
|
isActive?: "true" | "false" | undefined;
|
|
798
|
+
page?: string | undefined;
|
|
799
|
+
sortBy?: "createdAt" | "updatedAt" | "version" | undefined;
|
|
800
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
801
801
|
}>;
|
|
802
802
|
}, "strip", z.ZodTypeAny, {
|
|
803
803
|
query: {
|
|
804
|
-
page: number;
|
|
805
804
|
limit: number;
|
|
806
|
-
|
|
807
|
-
sortOrder?: "ASC" | "DESC" | undefined;
|
|
805
|
+
page: number;
|
|
808
806
|
search?: string | undefined;
|
|
809
807
|
isActive?: "true" | "false" | undefined;
|
|
808
|
+
sortBy?: "createdAt" | "updatedAt" | "version" | undefined;
|
|
809
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
810
810
|
};
|
|
811
811
|
}, {
|
|
812
812
|
query: {
|
|
813
|
-
page?: string | undefined;
|
|
814
|
-
limit?: string | undefined;
|
|
815
|
-
sortBy?: "createdAt" | "updatedAt" | "version" | undefined;
|
|
816
|
-
sortOrder?: "ASC" | "DESC" | undefined;
|
|
817
813
|
search?: string | undefined;
|
|
814
|
+
limit?: string | undefined;
|
|
818
815
|
isActive?: "true" | "false" | undefined;
|
|
816
|
+
page?: string | undefined;
|
|
817
|
+
sortBy?: "createdAt" | "updatedAt" | "version" | undefined;
|
|
818
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
819
819
|
};
|
|
820
820
|
}>;
|
|
821
821
|
export declare const getAppSpecsSchema: z.ZodObject<{
|
|
@@ -15,19 +15,19 @@ export declare const submitBanAppealSchema: z.ZodObject<{
|
|
|
15
15
|
appealReason: string;
|
|
16
16
|
}>;
|
|
17
17
|
}, "strip", z.ZodTypeAny, {
|
|
18
|
-
params: {
|
|
19
|
-
banId: string;
|
|
20
|
-
};
|
|
21
18
|
body: {
|
|
22
19
|
appealReason: string;
|
|
23
20
|
};
|
|
24
|
-
}, {
|
|
25
21
|
params: {
|
|
26
22
|
banId: string;
|
|
27
23
|
};
|
|
24
|
+
}, {
|
|
28
25
|
body: {
|
|
29
26
|
appealReason: string;
|
|
30
27
|
};
|
|
28
|
+
params: {
|
|
29
|
+
banId: string;
|
|
30
|
+
};
|
|
31
31
|
}>;
|
|
32
32
|
export declare const submitSuspensionAppealSchema: z.ZodObject<{
|
|
33
33
|
params: z.ZodObject<{
|
|
@@ -45,17 +45,17 @@ export declare const submitSuspensionAppealSchema: z.ZodObject<{
|
|
|
45
45
|
appealReason: string;
|
|
46
46
|
}>;
|
|
47
47
|
}, "strip", z.ZodTypeAny, {
|
|
48
|
-
params: {
|
|
49
|
-
suspensionId: string;
|
|
50
|
-
};
|
|
51
48
|
body: {
|
|
52
49
|
appealReason: string;
|
|
53
50
|
};
|
|
54
|
-
}, {
|
|
55
51
|
params: {
|
|
56
52
|
suspensionId: string;
|
|
57
53
|
};
|
|
54
|
+
}, {
|
|
58
55
|
body: {
|
|
59
56
|
appealReason: string;
|
|
60
57
|
};
|
|
58
|
+
params: {
|
|
59
|
+
suspensionId: string;
|
|
60
|
+
};
|
|
61
61
|
}>;
|
|
@@ -20,16 +20,16 @@ export declare const riderLoginSchema: z.ZodObject<{
|
|
|
20
20
|
phoneNumber: string;
|
|
21
21
|
nationalId: string;
|
|
22
22
|
};
|
|
23
|
-
params?: {} | undefined;
|
|
24
23
|
query?: {} | undefined;
|
|
24
|
+
params?: {} | undefined;
|
|
25
25
|
headers?: {} | undefined;
|
|
26
26
|
}, {
|
|
27
27
|
body: {
|
|
28
28
|
phoneNumber: string;
|
|
29
29
|
nationalId: string;
|
|
30
30
|
};
|
|
31
|
-
params?: {} | undefined;
|
|
32
31
|
query?: {} | undefined;
|
|
32
|
+
params?: {} | undefined;
|
|
33
33
|
headers?: {} | undefined;
|
|
34
34
|
}>;
|
|
35
35
|
export declare const userLoginSchema: z.ZodObject<{
|
|
@@ -32,19 +32,19 @@ export declare const getUserRestrictionsSchema: z.ZodObject<{
|
|
|
32
32
|
includeResolved?: "true" | "false" | undefined;
|
|
33
33
|
}>;
|
|
34
34
|
}, "strip", z.ZodTypeAny, {
|
|
35
|
-
params: {
|
|
36
|
-
userId: string;
|
|
37
|
-
};
|
|
38
35
|
query: {
|
|
39
36
|
includeResolved?: "true" | "false" | undefined;
|
|
40
37
|
};
|
|
41
|
-
}, {
|
|
42
38
|
params: {
|
|
43
39
|
userId: string;
|
|
44
40
|
};
|
|
41
|
+
}, {
|
|
45
42
|
query: {
|
|
46
43
|
includeResolved?: "true" | "false" | undefined;
|
|
47
44
|
};
|
|
45
|
+
params: {
|
|
46
|
+
userId: string;
|
|
47
|
+
};
|
|
48
48
|
}>;
|
|
49
49
|
export declare const createBanSchema: z.ZodObject<{
|
|
50
50
|
params: z.ZodObject<{
|
|
@@ -65,19 +65,19 @@ export declare const createBanSchema: z.ZodObject<{
|
|
|
65
65
|
isPermanent?: boolean | undefined;
|
|
66
66
|
}>;
|
|
67
67
|
}, "strip", z.ZodTypeAny, {
|
|
68
|
-
params: {
|
|
69
|
-
userId: string;
|
|
70
|
-
};
|
|
71
68
|
body: {
|
|
72
69
|
reason: string;
|
|
73
70
|
isPermanent: boolean;
|
|
74
71
|
};
|
|
75
|
-
}, {
|
|
76
72
|
params: {
|
|
77
73
|
userId: string;
|
|
78
74
|
};
|
|
75
|
+
}, {
|
|
79
76
|
body: {
|
|
80
77
|
reason: string;
|
|
81
78
|
isPermanent?: boolean | undefined;
|
|
82
79
|
};
|
|
80
|
+
params: {
|
|
81
|
+
userId: string;
|
|
82
|
+
};
|
|
83
83
|
}>;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const listUserPaymentPlansSchema: z.ZodObject<{
|
|
3
3
|
query: z.ZodObject<{
|
|
4
|
-
status: z.ZodOptional<z.ZodEnum<["
|
|
4
|
+
status: z.ZodOptional<z.ZodEnum<["pending", "succeeded", "failed"]>>;
|
|
5
5
|
page: z.ZodPipeline<z.ZodEffects<z.ZodOptional<z.ZodString>, number, string | undefined>, z.ZodNumber>;
|
|
6
6
|
limit: z.ZodPipeline<z.ZodEffects<z.ZodOptional<z.ZodString>, number, string | undefined>, z.ZodNumber>;
|
|
7
7
|
sortBy: z.ZodOptional<z.ZodEnum<["createdAt", "updatedAt", "nextInstallmentDueAt", "status"]>>;
|
|
8
8
|
sortOrder: z.ZodOptional<z.ZodEnum<["ASC", "DESC"]>>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
page: number;
|
|
11
10
|
limit: number;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
page: number;
|
|
12
|
+
status?: "pending" | "succeeded" | "failed" | undefined;
|
|
13
|
+
sortBy?: "createdAt" | "updatedAt" | "status" | "nextInstallmentDueAt" | undefined;
|
|
14
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
15
15
|
}, {
|
|
16
|
-
status?: "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
|
|
17
|
-
page?: string | undefined;
|
|
18
16
|
limit?: string | undefined;
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
status?: "pending" | "succeeded" | "failed" | undefined;
|
|
18
|
+
page?: string | undefined;
|
|
19
|
+
sortBy?: "createdAt" | "updatedAt" | "status" | "nextInstallmentDueAt" | undefined;
|
|
20
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
21
21
|
}>;
|
|
22
22
|
}, "strip", z.ZodTypeAny, {
|
|
23
23
|
query: {
|
|
24
|
-
page: number;
|
|
25
24
|
limit: number;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
page: number;
|
|
26
|
+
status?: "pending" | "succeeded" | "failed" | undefined;
|
|
27
|
+
sortBy?: "createdAt" | "updatedAt" | "status" | "nextInstallmentDueAt" | undefined;
|
|
28
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
29
29
|
};
|
|
30
30
|
}, {
|
|
31
31
|
query: {
|
|
32
|
-
status?: "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
|
|
33
|
-
page?: string | undefined;
|
|
34
32
|
limit?: string | undefined;
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
status?: "pending" | "succeeded" | "failed" | undefined;
|
|
34
|
+
page?: string | undefined;
|
|
35
|
+
sortBy?: "createdAt" | "updatedAt" | "status" | "nextInstallmentDueAt" | undefined;
|
|
36
|
+
sortOrder?: "DESC" | "ASC" | undefined;
|
|
37
37
|
};
|
|
38
38
|
}>;
|
|
39
39
|
export declare const getUserPaymentPlanSchema: z.ZodObject<{
|
|
@@ -21,20 +21,20 @@ export declare const extendSessionSchema: z.ZodObject<{
|
|
|
21
21
|
deviceSerialNumber: z.ZodString;
|
|
22
22
|
sessionId: z.ZodString;
|
|
23
23
|
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
deviceSerialNumber: string;
|
|
25
24
|
sessionId: string;
|
|
26
|
-
}, {
|
|
27
25
|
deviceSerialNumber: string;
|
|
26
|
+
}, {
|
|
28
27
|
sessionId: string;
|
|
28
|
+
deviceSerialNumber: string;
|
|
29
29
|
}>;
|
|
30
30
|
}, "strip", z.ZodTypeAny, {
|
|
31
31
|
body: {
|
|
32
|
-
deviceSerialNumber: string;
|
|
33
32
|
sessionId: string;
|
|
33
|
+
deviceSerialNumber: string;
|
|
34
34
|
};
|
|
35
35
|
}, {
|
|
36
36
|
body: {
|
|
37
|
-
deviceSerialNumber: string;
|
|
38
37
|
sessionId: string;
|
|
38
|
+
deviceSerialNumber: string;
|
|
39
39
|
};
|
|
40
40
|
}>;
|