vr-commons 1.0.48 → 1.0.49

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.
@@ -1,3 +1,3 @@
1
1
  import { Request, Response, NextFunction } from "express";
2
2
  import { UserRole } from "vr-models";
3
- export declare const checkUserAuthentication: (allowedRoles: UserRole[]) => (req: Request, res: Response, next: NextFunction) => Promise<Response<any, Record<string, any>> | undefined>;
3
+ export declare const checkUserAuthentication: (allowedRoles: UserRole[]) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -7,50 +7,76 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.checkUserAuthentication = void 0;
8
8
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
9
9
  const vr_models_1 = require("vr-models");
10
+ const __1 = require("..");
10
11
  const checkUserAuthentication = (allowedRoles) => async (req, res, next) => {
11
12
  try {
12
13
  const authHeader = req.headers.authorization;
13
14
  if (!authHeader || !authHeader.startsWith("Bearer ")) {
14
- return res.status(401).json({ message: "Missing or invalid token" });
15
+ return (0, __1.sendErrorResponse)(res, "Missing or invalid token", 401);
15
16
  }
16
17
  const token = authHeader.split(" ")[1];
17
18
  let payload;
18
19
  try {
19
20
  payload = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET);
20
21
  }
21
- catch {
22
- return res.status(401).json({ message: "Token expired or invalid" });
22
+ catch (error) {
23
+ if (error instanceof jsonwebtoken_1.default.TokenExpiredError) {
24
+ return (0, __1.sendErrorResponse)(res, "Token expired", 401);
25
+ }
26
+ return (0, __1.sendErrorResponse)(res, "Token invalid", 401);
27
+ }
28
+ // Validate that sessionId exists in payload
29
+ if (!payload.sessionId) {
30
+ return (0, __1.sendErrorResponse)(res, "Invalid token format: missing session", 401);
23
31
  }
24
32
  const user = await vr_models_1.User.findOne({
25
33
  where: { id: payload.userId },
26
34
  include: [
27
35
  {
28
36
  model: vr_models_1.SecurityClearance,
29
- as: "securityClearance"
30
- }
31
- ]
37
+ as: "securityClearance",
38
+ },
39
+ ],
32
40
  });
41
+ // Check if user exists
33
42
  if (!user || !user.securityClearance) {
34
- return res.status(401).json({ message: "User not found" });
43
+ return (0, __1.sendErrorResponse)(res, "User not found", 400);
44
+ }
45
+ // Check account moderation status
46
+ const moderation = await (0, __1.checkIsUserBannedOrSuspended)(user.id);
47
+ if (moderation.isRestricted) {
48
+ return (0, __1.sendErrorResponse)(res, "Restricted", 403, moderation);
35
49
  }
36
50
  // 🔐 Token versioning (logout all devices)
37
51
  if (user.tokenVersion !== payload.tokenVersion) {
38
- return res.status(401).json({ message: "Session expired" });
52
+ return (0, __1.sendErrorResponse)(res, "Session expired - token version mismatch", 401);
39
53
  }
40
54
  // 🧱 Role enforcement
41
55
  if (!allowedRoles.includes(user.securityClearance.role)) {
42
- return res.status(403).json({ message: "Access denied" });
56
+ return (0, __1.sendErrorResponse)(res, "Access denied", 403);
43
57
  }
44
- // Extend req
58
+ // Reconstruct session from payload
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
45
70
  req.userId = user.id;
46
71
  req.firstName = user.firstName;
47
72
  req.lastName = user.lastName;
48
73
  req.scRole = user.securityClearance.role;
49
74
  req.scLevel = user.securityClearance.level;
50
- req.tokenVersion = user.tokenVersion;
75
+ req.session = session;
51
76
  next();
52
77
  }
53
78
  catch (error) {
79
+ console.error("Authentication error:", error);
54
80
  next(error);
55
81
  }
56
82
  };
@@ -1,11 +1,18 @@
1
1
  import { UserRole } from "vr-models";
2
2
  export interface JWTPayload {
3
3
  userId: string;
4
- role: UserRole;
4
+ role: string;
5
5
  level: number;
6
6
  tokenVersion: number;
7
+ sessionId: string;
8
+ iat?: number;
9
+ exp?: number;
7
10
  }
8
- export declare const generateAdminToken: (userId: string, role: UserRole, level: number, tokenVersion: number, expiresIn: number) => string;
9
- export declare const generatePassengerToken: (userId: string, role: UserRole, level: number, tokenVersion: number, expiresIn: number) => string;
10
- export declare const generateRiderToken: (userId: string, role: UserRole, level: number, tokenVersion: number, expiresIn: number) => string;
11
+ export declare const generateToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId: string, type: "ADMIN" | "PASSENGER" | "RIDER") => string;
12
+ export declare const generateAdminToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId: string) => string;
13
+ export declare const generatePassengerToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId: string) => string;
14
+ export declare const generateRiderToken: (userId: string, role: UserRole, level: number, tokenVersion: number, sessionId: string) => string;
11
15
  export declare const verifyToken: (token: string) => Promise<JWTPayload>;
16
+ export declare const shouldRefreshToken: (token: string) => boolean;
17
+ export declare const getTokenTimeRemaining: (token: string) => number | null;
18
+ export declare const formatTimeRemaining: (seconds: number) => string;
@@ -3,30 +3,115 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.verifyToken = exports.generateRiderToken = exports.generatePassengerToken = exports.generateAdminToken = void 0;
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
- const generateAdminToken = (userId, role, level, tokenVersion, expiresIn) => {
9
- const payload = { userId, role, level, tokenVersion };
8
+ // Get token lifespan from env with fallback to 15 minutes (in seconds)
9
+ const getTokenLifespan = (type) => {
10
+ const envVar = `${type}_TOKEN_LIFE_SPAN`;
11
+ const value = process.env[envVar];
12
+ if (value) {
13
+ const parsed = parseInt(value, 10);
14
+ if (!isNaN(parsed) && parsed > 0) {
15
+ return parsed;
16
+ }
17
+ }
18
+ // Default to 15 minutes (900 seconds)
19
+ console.warn(`⚠️ ${envVar} not set or invalid, using default 15 minutes (900 seconds)`);
20
+ return 900;
21
+ };
22
+ // Helper to ensure expiration is exactly 15 minutes from now
23
+ const generateToken = (userId, role, level, tokenVersion, sessionId, type) => {
24
+ const payload = {
25
+ userId,
26
+ role,
27
+ level,
28
+ tokenVersion,
29
+ sessionId,
30
+ };
31
+ const expiresIn = getTokenLifespan(type);
32
+ console.log(`🔐 Generating ${type} token for user ${userId} with ${expiresIn}s expiry`);
10
33
  return jsonwebtoken_1.default.sign(payload, process.env.JWT_SECRET, {
11
- expiresIn: expiresIn || Number(process.env.ADMIN_TOKEN_LIFE_SPAN)
34
+ expiresIn, // This ensures exp is set to (iat + expiresIn)
12
35
  });
13
36
  };
37
+ exports.generateToken = generateToken;
38
+ // Specific token generators
39
+ const generateAdminToken = (userId, role, level, tokenVersion, sessionId) => {
40
+ return (0, exports.generateToken)(userId, role, level, tokenVersion, sessionId, "ADMIN");
41
+ };
14
42
  exports.generateAdminToken = generateAdminToken;
15
- const generatePassengerToken = (userId, role, level, tokenVersion, expiresIn) => {
16
- const payload = { userId, role, level, tokenVersion };
17
- return jsonwebtoken_1.default.sign(payload, process.env.JWT_SECRET, {
18
- expiresIn: expiresIn || Number(process.env.PASSENGER_TOKEN_LIFE_SPAN)
19
- });
43
+ const generatePassengerToken = (userId, role, level, tokenVersion, sessionId) => {
44
+ return (0, exports.generateToken)(userId, role, level, tokenVersion, sessionId, "PASSENGER");
20
45
  };
21
46
  exports.generatePassengerToken = generatePassengerToken;
22
- const generateRiderToken = (userId, role, level, tokenVersion, expiresIn) => {
23
- const payload = { userId, role, level, tokenVersion };
24
- return jsonwebtoken_1.default.sign(payload, process.env.JWT_SECRET, {
25
- expiresIn: expiresIn || Number(process.env.RIDER_TOKEN_LIFE_SPAN)
26
- });
47
+ const generateRiderToken = (userId, role, level, tokenVersion, sessionId) => {
48
+ return (0, exports.generateToken)(userId, role, level, tokenVersion, sessionId, "RIDER");
27
49
  };
28
50
  exports.generateRiderToken = generateRiderToken;
51
+ // Verify token and return payload with expiration info
29
52
  const verifyToken = async (token) => {
30
- return jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET);
53
+ try {
54
+ const decoded = jsonwebtoken_1.default.verify(token, process.env.JWT_SECRET);
55
+ // Log token expiration info for debugging
56
+ if (decoded.exp) {
57
+ const expiresIn = decoded.exp - Math.floor(Date.now() / 1000);
58
+ console.log(`🔍 Token expires in ${expiresIn} seconds`);
59
+ if (expiresIn < 300) {
60
+ // Less than 5 minutes
61
+ console.warn(`⚠️ Token expiring soon: ${expiresIn} seconds remaining`);
62
+ }
63
+ }
64
+ return decoded;
65
+ }
66
+ catch (error) {
67
+ if (error instanceof jsonwebtoken_1.default.TokenExpiredError) {
68
+ console.error("❌ Token expired at:", error.expiredAt);
69
+ throw new Error("Token has expired");
70
+ }
71
+ if (error instanceof jsonwebtoken_1.default.JsonWebTokenError) {
72
+ console.error("❌ Invalid token:", error.message);
73
+ throw new Error("Invalid token");
74
+ }
75
+ throw error;
76
+ }
31
77
  };
32
78
  exports.verifyToken = verifyToken;
79
+ // Helper to check if token needs refresh (within 5 minutes of expiry)
80
+ const shouldRefreshToken = (token) => {
81
+ try {
82
+ const decoded = jsonwebtoken_1.default.decode(token);
83
+ if (!decoded || !decoded.exp)
84
+ return false;
85
+ const now = Math.floor(Date.now() / 1000);
86
+ const timeUntilExpiry = decoded.exp - now;
87
+ const refreshThreshold = 300; // 5 minutes in seconds
88
+ return timeUntilExpiry < refreshThreshold && timeUntilExpiry > 0;
89
+ }
90
+ catch {
91
+ return false;
92
+ }
93
+ };
94
+ exports.shouldRefreshToken = shouldRefreshToken;
95
+ // Get time remaining on token in seconds
96
+ const getTokenTimeRemaining = (token) => {
97
+ try {
98
+ const decoded = jsonwebtoken_1.default.decode(token);
99
+ if (!decoded || !decoded.exp)
100
+ return null;
101
+ const now = Math.floor(Date.now() / 1000);
102
+ return Math.max(0, decoded.exp - now);
103
+ }
104
+ catch {
105
+ return null;
106
+ }
107
+ };
108
+ exports.getTokenTimeRemaining = getTokenTimeRemaining;
109
+ // Format time remaining in a human-readable format
110
+ const formatTimeRemaining = (seconds) => {
111
+ if (seconds < 60)
112
+ return `${seconds} seconds`;
113
+ if (seconds < 3600)
114
+ return `${Math.floor(seconds / 60)} minutes ${seconds % 60} seconds`;
115
+ return `${Math.floor(seconds / 3600)} hours ${Math.floor((seconds % 3600) / 60)} minutes`;
116
+ };
117
+ exports.formatTimeRemaining = formatTimeRemaining;
@@ -1,4 +1,4 @@
1
- import { EventAction, UserRole } from "vr-models";
1
+ import { EventAction, UserRole, SessionPayload } from "vr-models";
2
2
  import { Transaction } from "sequelize";
3
3
  interface LogEventInput {
4
4
  actorId?: string | null;
@@ -10,6 +10,7 @@ interface LogEventInput {
10
10
  ipAddress?: string | null;
11
11
  userAgent?: string | null;
12
12
  transaction?: Transaction;
13
+ session: SessionPayload;
13
14
  }
14
- export declare const logEvent: ({ actorId, actorType, action, entity, entityId, metadata, ipAddress, userAgent, transaction, }: LogEventInput) => Promise<void>;
15
+ export declare const logEvent: ({ actorId, actorType, action, entity, entityId, metadata, ipAddress, userAgent, transaction, session, }: LogEventInput) => Promise<void>;
15
16
  export {};
@@ -2,10 +2,11 @@
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, // Optional transaction parameter
5
+ const logEvent = async ({ actorId = null, actorType = "ADMIN", action, entity, entityId = null, metadata = {}, ipAddress = null, userAgent = null, transaction, session, // Required session parameter matching the model
6
6
  }) => {
7
7
  try {
8
8
  // Create event log with optional transaction
9
+ // session is passed directly as its own field, not inside metadata
9
10
  await vr_models_1.EventLog.create({
10
11
  actorId,
11
12
  actorType,
@@ -15,7 +16,8 @@ const logEvent = async ({ actorId = null, actorType = "ADMIN", action, entity, e
15
16
  metadata,
16
17
  ipAddress,
17
18
  userAgent,
18
- }, { transaction }); // Pass transaction if provided
19
+ session, // Now passed as dedicated field matching the model
20
+ }, { transaction });
19
21
  }
20
22
  catch (err) {
21
23
  console.log("Error Logging event ::::::", err);
@@ -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
  }>;
@@ -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<{
@@ -58,26 +58,26 @@ export declare const createBanSchema: z.ZodObject<{
58
58
  reason: z.ZodString;
59
59
  isPermanent: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
60
60
  }, "strict", z.ZodTypeAny, {
61
- isPermanent: boolean;
62
61
  reason: string;
62
+ isPermanent: boolean;
63
63
  }, {
64
64
  reason: string;
65
65
  isPermanent?: boolean | undefined;
66
66
  }>;
67
67
  }, "strip", z.ZodTypeAny, {
68
- params: {
69
- userId: string;
70
- };
71
68
  body: {
72
- isPermanent: boolean;
73
69
  reason: string;
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
  }>;
@@ -14,81 +14,81 @@ export declare const listBansSchema: z.ZodObject<{
14
14
  sortBy: z.ZodOptional<z.ZodEnum<["bannedAt", "createdAt", "reason"]>>;
15
15
  sortOrder: z.ZodOptional<z.ZodEnum<["ASC", "DESC"]>>;
16
16
  }, "strip", z.ZodTypeAny, {
17
- page: number;
18
17
  limit: number;
19
- fromDate?: string | undefined;
20
- toDate?: string | undefined;
21
- status?: "active" | "revoked" | undefined;
18
+ page: number;
19
+ search?: string | undefined;
22
20
  userId?: string | undefined;
23
- appealStatus?: "pending" | "approved" | "rejected" | undefined;
24
21
  isPermanent?: "true" | "false" | undefined;
25
- search?: string | undefined;
22
+ appealStatus?: "pending" | "approved" | "rejected" | undefined;
23
+ status?: "active" | "revoked" | undefined;
26
24
  sortBy?: "bannedAt" | "createdAt" | "reason" | undefined;
27
- sortOrder?: "ASC" | "DESC" | undefined;
28
- }, {
29
25
  fromDate?: string | undefined;
30
26
  toDate?: string | undefined;
31
- status?: "active" | "revoked" | undefined;
32
- page?: string | undefined;
27
+ sortOrder?: "DESC" | "ASC" | undefined;
28
+ }, {
29
+ search?: string | undefined;
33
30
  limit?: string | undefined;
34
31
  userId?: string | undefined;
35
- appealStatus?: "pending" | "approved" | "rejected" | undefined;
36
32
  isPermanent?: "true" | "false" | undefined;
37
- search?: string | undefined;
33
+ appealStatus?: "pending" | "approved" | "rejected" | undefined;
34
+ status?: "active" | "revoked" | undefined;
35
+ page?: string | undefined;
38
36
  sortBy?: "bannedAt" | "createdAt" | "reason" | undefined;
39
- sortOrder?: "ASC" | "DESC" | undefined;
40
- }>, {
41
- page: number;
42
- limit: number;
43
37
  fromDate?: string | undefined;
44
38
  toDate?: string | undefined;
45
- status?: "active" | "revoked" | undefined;
39
+ sortOrder?: "DESC" | "ASC" | undefined;
40
+ }>, {
41
+ limit: number;
42
+ page: number;
43
+ search?: string | undefined;
46
44
  userId?: string | undefined;
47
- appealStatus?: "pending" | "approved" | "rejected" | undefined;
48
45
  isPermanent?: "true" | "false" | undefined;
49
- search?: string | undefined;
46
+ appealStatus?: "pending" | "approved" | "rejected" | undefined;
47
+ status?: "active" | "revoked" | undefined;
50
48
  sortBy?: "bannedAt" | "createdAt" | "reason" | undefined;
51
- sortOrder?: "ASC" | "DESC" | undefined;
52
- }, {
53
49
  fromDate?: string | undefined;
54
50
  toDate?: string | undefined;
55
- status?: "active" | "revoked" | undefined;
56
- page?: string | undefined;
51
+ sortOrder?: "DESC" | "ASC" | undefined;
52
+ }, {
53
+ search?: string | undefined;
57
54
  limit?: string | undefined;
58
55
  userId?: string | undefined;
59
- appealStatus?: "pending" | "approved" | "rejected" | undefined;
60
56
  isPermanent?: "true" | "false" | undefined;
61
- search?: string | undefined;
57
+ appealStatus?: "pending" | "approved" | "rejected" | undefined;
58
+ status?: "active" | "revoked" | undefined;
59
+ page?: string | undefined;
62
60
  sortBy?: "bannedAt" | "createdAt" | "reason" | undefined;
63
- sortOrder?: "ASC" | "DESC" | undefined;
61
+ fromDate?: string | undefined;
62
+ toDate?: string | undefined;
63
+ sortOrder?: "DESC" | "ASC" | undefined;
64
64
  }>;
65
65
  }, "strip", z.ZodTypeAny, {
66
66
  query: {
67
- page: number;
68
67
  limit: number;
69
- fromDate?: string | undefined;
70
- toDate?: string | undefined;
71
- status?: "active" | "revoked" | undefined;
68
+ page: number;
69
+ search?: string | undefined;
72
70
  userId?: string | undefined;
73
- appealStatus?: "pending" | "approved" | "rejected" | undefined;
74
71
  isPermanent?: "true" | "false" | undefined;
75
- search?: string | undefined;
72
+ appealStatus?: "pending" | "approved" | "rejected" | undefined;
73
+ status?: "active" | "revoked" | undefined;
76
74
  sortBy?: "bannedAt" | "createdAt" | "reason" | undefined;
77
- sortOrder?: "ASC" | "DESC" | undefined;
75
+ fromDate?: string | undefined;
76
+ toDate?: string | undefined;
77
+ sortOrder?: "DESC" | "ASC" | undefined;
78
78
  };
79
79
  }, {
80
80
  query: {
81
- fromDate?: string | undefined;
82
- toDate?: string | undefined;
83
- status?: "active" | "revoked" | undefined;
84
- page?: string | undefined;
81
+ search?: string | undefined;
85
82
  limit?: string | undefined;
86
83
  userId?: string | undefined;
87
- appealStatus?: "pending" | "approved" | "rejected" | undefined;
88
84
  isPermanent?: "true" | "false" | undefined;
89
- search?: string | undefined;
85
+ appealStatus?: "pending" | "approved" | "rejected" | undefined;
86
+ status?: "active" | "revoked" | undefined;
87
+ page?: string | undefined;
90
88
  sortBy?: "bannedAt" | "createdAt" | "reason" | undefined;
91
- sortOrder?: "ASC" | "DESC" | undefined;
89
+ fromDate?: string | undefined;
90
+ toDate?: string | undefined;
91
+ sortOrder?: "DESC" | "ASC" | undefined;
92
92
  };
93
93
  }>;
94
94
  export declare const listSuspensionsSchema: z.ZodObject<{
@@ -105,75 +105,75 @@ export declare const listSuspensionsSchema: z.ZodObject<{
105
105
  sortBy: z.ZodOptional<z.ZodEnum<["startedAt", "endsAt", "createdAt", "reason"]>>;
106
106
  sortOrder: z.ZodOptional<z.ZodEnum<["ASC", "DESC"]>>;
107
107
  }, "strip", z.ZodTypeAny, {
108
- page: number;
109
108
  limit: number;
110
- fromDate?: string | undefined;
111
- toDate?: string | undefined;
112
- status?: "active" | "revoked" | "expired" | undefined;
109
+ page: number;
110
+ search?: string | undefined;
113
111
  userId?: string | undefined;
114
112
  appealStatus?: "pending" | "approved" | "rejected" | undefined;
115
- search?: string | undefined;
116
- sortBy?: "createdAt" | "reason" | "startedAt" | "endsAt" | undefined;
117
- sortOrder?: "ASC" | "DESC" | undefined;
118
- }, {
113
+ status?: "active" | "revoked" | "expired" | undefined;
114
+ sortBy?: "createdAt" | "reason" | "endsAt" | "startedAt" | undefined;
119
115
  fromDate?: string | undefined;
120
116
  toDate?: string | undefined;
121
- status?: "active" | "revoked" | "expired" | undefined;
122
- page?: string | undefined;
117
+ sortOrder?: "DESC" | "ASC" | undefined;
118
+ }, {
119
+ search?: string | undefined;
123
120
  limit?: string | undefined;
124
121
  userId?: string | undefined;
125
122
  appealStatus?: "pending" | "approved" | "rejected" | undefined;
126
- search?: string | undefined;
127
- sortBy?: "createdAt" | "reason" | "startedAt" | "endsAt" | undefined;
128
- sortOrder?: "ASC" | "DESC" | undefined;
129
- }>, {
130
- page: number;
131
- limit: number;
123
+ status?: "active" | "revoked" | "expired" | undefined;
124
+ page?: string | undefined;
125
+ sortBy?: "createdAt" | "reason" | "endsAt" | "startedAt" | undefined;
132
126
  fromDate?: string | undefined;
133
127
  toDate?: string | undefined;
134
- status?: "active" | "revoked" | "expired" | undefined;
128
+ sortOrder?: "DESC" | "ASC" | undefined;
129
+ }>, {
130
+ limit: number;
131
+ page: number;
132
+ search?: string | undefined;
135
133
  userId?: string | undefined;
136
134
  appealStatus?: "pending" | "approved" | "rejected" | undefined;
137
- search?: string | undefined;
138
- sortBy?: "createdAt" | "reason" | "startedAt" | "endsAt" | undefined;
139
- sortOrder?: "ASC" | "DESC" | undefined;
140
- }, {
135
+ status?: "active" | "revoked" | "expired" | undefined;
136
+ sortBy?: "createdAt" | "reason" | "endsAt" | "startedAt" | undefined;
141
137
  fromDate?: string | undefined;
142
138
  toDate?: string | undefined;
143
- status?: "active" | "revoked" | "expired" | undefined;
144
- page?: string | undefined;
139
+ sortOrder?: "DESC" | "ASC" | undefined;
140
+ }, {
141
+ search?: string | undefined;
145
142
  limit?: string | undefined;
146
143
  userId?: string | undefined;
147
144
  appealStatus?: "pending" | "approved" | "rejected" | undefined;
148
- search?: string | undefined;
149
- sortBy?: "createdAt" | "reason" | "startedAt" | "endsAt" | undefined;
150
- sortOrder?: "ASC" | "DESC" | undefined;
145
+ status?: "active" | "revoked" | "expired" | undefined;
146
+ page?: string | undefined;
147
+ sortBy?: "createdAt" | "reason" | "endsAt" | "startedAt" | undefined;
148
+ fromDate?: string | undefined;
149
+ toDate?: string | undefined;
150
+ sortOrder?: "DESC" | "ASC" | undefined;
151
151
  }>;
152
152
  }, "strip", z.ZodTypeAny, {
153
153
  query: {
154
- page: number;
155
154
  limit: number;
156
- fromDate?: string | undefined;
157
- toDate?: string | undefined;
158
- status?: "active" | "revoked" | "expired" | undefined;
155
+ page: number;
156
+ search?: string | undefined;
159
157
  userId?: string | undefined;
160
158
  appealStatus?: "pending" | "approved" | "rejected" | undefined;
161
- search?: string | undefined;
162
- sortBy?: "createdAt" | "reason" | "startedAt" | "endsAt" | undefined;
163
- sortOrder?: "ASC" | "DESC" | undefined;
159
+ status?: "active" | "revoked" | "expired" | undefined;
160
+ sortBy?: "createdAt" | "reason" | "endsAt" | "startedAt" | undefined;
161
+ fromDate?: string | undefined;
162
+ toDate?: string | undefined;
163
+ sortOrder?: "DESC" | "ASC" | undefined;
164
164
  };
165
165
  }, {
166
166
  query: {
167
- fromDate?: string | undefined;
168
- toDate?: string | undefined;
169
- status?: "active" | "revoked" | "expired" | undefined;
170
- page?: string | undefined;
167
+ search?: string | undefined;
171
168
  limit?: string | undefined;
172
169
  userId?: string | undefined;
173
170
  appealStatus?: "pending" | "approved" | "rejected" | undefined;
174
- search?: string | undefined;
175
- sortBy?: "createdAt" | "reason" | "startedAt" | "endsAt" | undefined;
176
- sortOrder?: "ASC" | "DESC" | undefined;
171
+ status?: "active" | "revoked" | "expired" | undefined;
172
+ page?: string | undefined;
173
+ sortBy?: "createdAt" | "reason" | "endsAt" | "startedAt" | undefined;
174
+ fromDate?: string | undefined;
175
+ toDate?: string | undefined;
176
+ sortOrder?: "DESC" | "ASC" | undefined;
177
177
  };
178
178
  }>;
179
179
  export declare const revokeBanSchema: z.ZodObject<{
@@ -192,19 +192,19 @@ export declare const revokeBanSchema: z.ZodObject<{
192
192
  revocationReason?: string | undefined;
193
193
  }>;
194
194
  }, "strip", z.ZodTypeAny, {
195
- params: {
196
- banId: string;
197
- };
198
195
  body: {
199
196
  revocationReason?: string | undefined;
200
197
  };
201
- }, {
202
198
  params: {
203
199
  banId: string;
204
200
  };
201
+ }, {
205
202
  body: {
206
203
  revocationReason?: string | undefined;
207
204
  };
205
+ params: {
206
+ banId: string;
207
+ };
208
208
  }>;
209
209
  export declare const revokeSuspensionSchema: z.ZodObject<{
210
210
  params: z.ZodObject<{
@@ -222,19 +222,19 @@ export declare const revokeSuspensionSchema: z.ZodObject<{
222
222
  revocationReason?: string | undefined;
223
223
  }>;
224
224
  }, "strip", z.ZodTypeAny, {
225
- params: {
226
- suspensionId: string;
227
- };
228
225
  body: {
229
226
  revocationReason?: string | undefined;
230
227
  };
231
- }, {
232
228
  params: {
233
229
  suspensionId: string;
234
230
  };
231
+ }, {
235
232
  body: {
236
233
  revocationReason?: string | undefined;
237
234
  };
235
+ params: {
236
+ suspensionId: string;
237
+ };
238
238
  }>;
239
239
  export declare const extendSuspensionSchema: z.ZodObject<{
240
240
  params: z.ZodObject<{
@@ -261,21 +261,21 @@ export declare const extendSuspensionSchema: z.ZodObject<{
261
261
  extensionReason?: string | undefined;
262
262
  }>;
263
263
  }, "strip", z.ZodTypeAny, {
264
- params: {
265
- suspensionId: string;
266
- };
267
264
  body: {
268
265
  newEndDate: string;
269
266
  extensionReason?: string | undefined;
270
267
  };
271
- }, {
272
268
  params: {
273
269
  suspensionId: string;
274
270
  };
271
+ }, {
275
272
  body: {
276
273
  newEndDate: string;
277
274
  extensionReason?: string | undefined;
278
275
  };
276
+ params: {
277
+ suspensionId: string;
278
+ };
279
279
  }>;
280
280
  export declare const listPendingAppealsSchema: z.ZodObject<{
281
281
  query: z.ZodEffects<z.ZodObject<{
@@ -286,34 +286,34 @@ export declare const listPendingAppealsSchema: z.ZodObject<{
286
286
  fromDate: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
287
287
  toDate: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
288
288
  }, "strip", z.ZodTypeAny, {
289
- page: number;
290
289
  limit: number;
290
+ page: number;
291
291
  type?: "ban" | "suspension" | undefined;
292
292
  fromDate?: string | undefined;
293
293
  toDate?: string | undefined;
294
294
  }, {
295
295
  type?: "ban" | "suspension" | undefined;
296
+ limit?: string | undefined;
297
+ page?: string | undefined;
296
298
  fromDate?: string | undefined;
297
299
  toDate?: string | undefined;
298
- page?: string | undefined;
299
- limit?: string | undefined;
300
300
  }>, {
301
- page: number;
302
301
  limit: number;
302
+ page: number;
303
303
  type?: "ban" | "suspension" | undefined;
304
304
  fromDate?: string | undefined;
305
305
  toDate?: string | undefined;
306
306
  }, {
307
307
  type?: "ban" | "suspension" | undefined;
308
+ limit?: string | undefined;
309
+ page?: string | undefined;
308
310
  fromDate?: string | undefined;
309
311
  toDate?: string | undefined;
310
- page?: string | undefined;
311
- limit?: string | undefined;
312
312
  }>;
313
313
  }, "strip", z.ZodTypeAny, {
314
314
  query: {
315
- page: number;
316
315
  limit: number;
316
+ page: number;
317
317
  type?: "ban" | "suspension" | undefined;
318
318
  fromDate?: string | undefined;
319
319
  toDate?: string | undefined;
@@ -321,10 +321,10 @@ export declare const listPendingAppealsSchema: z.ZodObject<{
321
321
  }, {
322
322
  query: {
323
323
  type?: "ban" | "suspension" | undefined;
324
+ limit?: string | undefined;
325
+ page?: string | undefined;
324
326
  fromDate?: string | undefined;
325
327
  toDate?: string | undefined;
326
- page?: string | undefined;
327
- limit?: string | undefined;
328
328
  };
329
329
  }>;
330
330
  export declare const reviewAppealSchema: z.ZodObject<{
@@ -349,23 +349,23 @@ export declare const reviewAppealSchema: z.ZodObject<{
349
349
  adminNotes?: string | undefined;
350
350
  }>;
351
351
  }, "strip", z.ZodTypeAny, {
352
- params: {
353
- banId?: string | undefined;
354
- suspensionId?: string | undefined;
355
- };
356
352
  body: {
357
353
  appealStatus: "approved" | "rejected";
358
354
  adminNotes?: string | undefined;
359
355
  };
360
- }, {
361
356
  params: {
362
357
  banId?: string | undefined;
363
358
  suspensionId?: string | undefined;
364
359
  };
360
+ }, {
365
361
  body: {
366
362
  appealStatus: "approved" | "rejected";
367
363
  adminNotes?: string | undefined;
368
364
  };
365
+ params: {
366
+ banId?: string | undefined;
367
+ suspensionId?: string | undefined;
368
+ };
369
369
  }>;
370
370
  export declare const exportBansSchema: z.ZodObject<{
371
371
  query: z.ZodEffects<z.ZodObject<{
@@ -16,7 +16,7 @@ export declare const createUserSchema: z.ZodObject<{
16
16
  phoneNumber: string;
17
17
  password: string;
18
18
  nationalId: string;
19
- role: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN";
19
+ role: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN";
20
20
  jacketId?: string | null | undefined;
21
21
  email?: string | null | undefined;
22
22
  plateNumber?: string | null | undefined;
@@ -26,7 +26,7 @@ export declare const createUserSchema: z.ZodObject<{
26
26
  phoneNumber: string;
27
27
  password: string;
28
28
  nationalId: string;
29
- role: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN";
29
+ role: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN";
30
30
  jacketId?: string | null | undefined;
31
31
  email?: string | null | undefined;
32
32
  plateNumber?: string | null | undefined;
@@ -45,7 +45,7 @@ export declare const createUserSchema: z.ZodObject<{
45
45
  phoneNumber: string;
46
46
  password: string;
47
47
  nationalId: string;
48
- role: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN";
48
+ role: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN";
49
49
  jacketId?: string | null | undefined;
50
50
  email?: string | null | undefined;
51
51
  plateNumber?: string | null | undefined;
@@ -60,7 +60,7 @@ export declare const createUserSchema: z.ZodObject<{
60
60
  phoneNumber: string;
61
61
  password: string;
62
62
  nationalId: string;
63
- role: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN";
63
+ role: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN";
64
64
  jacketId?: string | null | undefined;
65
65
  email?: string | null | undefined;
66
66
  plateNumber?: string | null | undefined;
@@ -222,9 +222,9 @@ export declare const getAllUsersSchema: z.ZodObject<{
222
222
  limit?: number | undefined;
223
223
  isActive?: boolean | undefined;
224
224
  isSuspended?: boolean | undefined;
225
- role?: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN" | undefined;
226
- page?: number | undefined;
225
+ role?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
227
226
  isBanned?: boolean | undefined;
227
+ page?: number | undefined;
228
228
  startDate?: string | undefined;
229
229
  endDate?: string | undefined;
230
230
  }, {
@@ -233,9 +233,9 @@ export declare const getAllUsersSchema: z.ZodObject<{
233
233
  limit?: string | undefined;
234
234
  isActive?: "true" | "false" | undefined;
235
235
  isSuspended?: "true" | "false" | undefined;
236
- role?: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN" | undefined;
237
- page?: string | undefined;
236
+ role?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
238
237
  isBanned?: "true" | "false" | undefined;
238
+ page?: string | undefined;
239
239
  startDate?: string | undefined;
240
240
  endDate?: string | undefined;
241
241
  sortBy?: "firstName" | "lastLoginAt" | "createdAt" | undefined;
@@ -255,9 +255,9 @@ export declare const getAllUsersSchema: z.ZodObject<{
255
255
  limit?: number | undefined;
256
256
  isActive?: boolean | undefined;
257
257
  isSuspended?: boolean | undefined;
258
- role?: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN" | undefined;
259
- page?: number | undefined;
258
+ role?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
260
259
  isBanned?: boolean | undefined;
260
+ page?: number | undefined;
261
261
  startDate?: string | undefined;
262
262
  endDate?: string | undefined;
263
263
  };
@@ -271,9 +271,9 @@ export declare const getAllUsersSchema: z.ZodObject<{
271
271
  limit?: string | undefined;
272
272
  isActive?: "true" | "false" | undefined;
273
273
  isSuspended?: "true" | "false" | undefined;
274
- role?: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN" | undefined;
275
- page?: string | undefined;
274
+ role?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
276
275
  isBanned?: "true" | "false" | undefined;
276
+ page?: string | undefined;
277
277
  startDate?: string | undefined;
278
278
  endDate?: string | undefined;
279
279
  sortBy?: "firstName" | "lastLoginAt" | "createdAt" | undefined;
@@ -35,21 +35,21 @@ export declare const getUserSuspensionsSchema: z.ZodObject<{
35
35
  includeResolved?: "true" | "false" | undefined;
36
36
  }>;
37
37
  }, "strip", z.ZodTypeAny, {
38
- params: {
39
- userId: string;
40
- };
41
38
  query: {
42
39
  status?: "active" | "revoked" | "expired" | undefined;
43
40
  includeResolved?: "true" | "false" | undefined;
44
41
  };
45
- }, {
46
42
  params: {
47
43
  userId: string;
48
44
  };
45
+ }, {
49
46
  query: {
50
47
  status?: "active" | "revoked" | "expired" | undefined;
51
48
  includeResolved?: "true" | "false" | undefined;
52
49
  };
50
+ params: {
51
+ userId: string;
52
+ };
53
53
  }>;
54
54
  export declare const createSuspensionSchema: z.ZodObject<{
55
55
  params: z.ZodObject<{
@@ -70,19 +70,19 @@ export declare const createSuspensionSchema: z.ZodObject<{
70
70
  endsAt: string;
71
71
  }>;
72
72
  }, "strip", z.ZodTypeAny, {
73
- params: {
74
- userId: string;
75
- };
76
73
  body: {
77
74
  reason: string;
78
75
  endsAt: string;
79
76
  };
80
- }, {
81
77
  params: {
82
78
  userId: string;
83
79
  };
80
+ }, {
84
81
  body: {
85
82
  reason: string;
86
83
  endsAt: string;
87
84
  };
85
+ params: {
86
+ userId: string;
87
+ };
88
88
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-commons",
3
- "version": "1.0.48",
3
+ "version": "1.0.49",
4
4
  "description": "Shared functions package",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -98,7 +98,7 @@
98
98
  "@types/uuid": "^10.0.0",
99
99
  "axios": "^1.9.0",
100
100
  "date-fns": "^4.1.0",
101
- "vr-models": "^1.0.26",
101
+ "vr-models": "^1.0.29",
102
102
  "rimraf": "^5.0.5",
103
103
  "typescript": "^5.3.3",
104
104
  "zod": "^3.25.20"