vr-commons 1.0.176 → 1.0.177
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/constants/regex.constants.d.ts +19 -0
- package/dist/constants/regex.constants.js +24 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -3
- package/dist/middlewares/admin/admin.auth.middleware.js +60 -0
- package/dist/middlewares/index.d.ts +4 -5
- package/dist/middlewares/index.js +11 -14
- package/dist/middlewares/shared/auth.admin.middlewares.d.ts +3 -0
- package/dist/middlewares/{auth.admin.middlewares.js → shared/auth.admin.middlewares.js} +7 -7
- package/dist/middlewares/{account.shared.middlewares.js → shared/shared.account.middleware.js} +8 -8
- package/dist/middlewares/{errorHandler.middleware.js → shared/shared.errorHandler.middleware.js} +0 -1
- package/dist/middlewares/{auth.users.middlewares.js → users/users.auth.middleware.js} +10 -10
- package/dist/utils/{admin.devicePayment.utils.js → admin/admin.devicePayments.utils.js} +0 -1
- package/dist/utils/{admin.device.utils.d.ts → admin/admin.devices.utils.d.ts} +1 -1
- package/dist/utils/{admin.device.utils.js → admin/admin.devices.utils.js} +11 -12
- package/dist/utils/{eventlogs.admin.utils.js → admin/admin.eventLogs.utils.js} +0 -1
- package/dist/utils/{hierarchy.utils.js → admin/admin.hierarchy.utils.js} +0 -2
- package/dist/utils/{product.utils.d.ts → admin/admin.products.utils.d.ts} +1 -1
- package/dist/utils/{systemLog.utils.js → admin/admin.systemLogs.utils.js} +0 -1
- package/dist/utils/index.d.ts +16 -18
- package/dist/utils/index.js +88 -99
- package/dist/utils/{account.utils.js → shared/shared.accounts.utils.js} +0 -1
- package/dist/utils/{profiles.utils.d.ts → shared/shared.profiles.utils.d.ts} +2 -1
- package/dist/utils/{profiles.utils.js → shared/shared.profiles.utils.js} +3 -2
- package/dist/utils/{verification.utils.d.ts → users/users.verification.utils.d.ts} +1 -1
- package/dist/utils/{verification.utils.js → users/users.verification.utils.js} +3 -2
- package/dist/validations/{admin.devicePayment.validations.js → admin/admin.devicePayments.validations.js} +3 -2
- package/dist/validations/{admin.devices.validations.js → admin/admin.devices.validations.js} +4 -5
- package/dist/validations/{eventlogs.admin.validations.js → admin/admin.eventLogs.validations.js} +2 -2
- package/dist/validations/{admin.installment.validations.js → admin/admin.installments.validations.js} +4 -3
- package/dist/validations/{pricings.validations.js → admin/admin.pricings.validations.js} +5 -5
- package/dist/validations/{product.validations.js → admin/admin.products.validations.js} +4 -3
- package/dist/validations/{users.admin.validations.js → admin/admin.users.validations.js} +13 -13
- package/dist/validations/index.d.ts +16 -15
- package/dist/validations/index.js +132 -125
- package/dist/validations/{account.validations.js → shared/shared.account.validations.js} +7 -7
- package/dist/validations/{appSpecs.validations.js → shared/shared.appSpecs.validations.js} +0 -1
- package/dist/validations/{auth.validations.js → shared/shared.auth.validations.js} +6 -6
- package/dist/validations/{dateRange.validations.js → shared/shared.dateRanges.validations.js} +5 -5
- package/dist/validations/{moderation.validations.js → shared/shared.moderation.validations.js} +24 -25
- package/dist/validations/{profiles.validations.js → shared/shared.profiles.validations.js} +22 -21
- package/dist/validations/{devices.validations.js → users/users.devices.validations.js} +2 -1
- package/package.json +1 -1
- package/dist/middlewares/idempotency.middlewares.d.ts +0 -3
- package/dist/middlewares/idempotency.middlewares.js +0 -74
- package/dist/utils/deviceUtils.d.ts +0 -2
- package/dist/utils/deviceUtils.js +0 -21
- package/dist/utils/session.utils.d.ts +0 -6
- package/dist/utils/session.utils.js +0 -25
- package/dist/validations/appeals.validations.d.ts +0 -61
- package/dist/validations/appeals.validations.js +0 -31
- package/dist/validations/payinstallment.validations.d.ts +0 -56
- package/dist/validations/payinstallment.validations.js +0 -23
- package/dist/validations/pricing.validations.d.ts +0 -313
- package/dist/validations/pricing.validations.js +0 -376
- /package/dist/middlewares/{auth.admin.middlewares.d.ts → admin/admin.auth.middleware.d.ts} +0 -0
- /package/dist/middlewares/{account.shared.middlewares.d.ts → shared/shared.account.middleware.d.ts} +0 -0
- /package/dist/middlewares/{errorHandler.middleware.d.ts → shared/shared.errorHandler.middleware.d.ts} +0 -0
- /package/dist/middlewares/{auth.users.middlewares.d.ts → users/users.auth.middleware.d.ts} +0 -0
- /package/dist/utils/{bans.utils.d.ts → admin/admin.bans.utils.d.ts} +0 -0
- /package/dist/utils/{bans.utils.js → admin/admin.bans.utils.js} +0 -0
- /package/dist/utils/{admin.devicePayment.utils.d.ts → admin/admin.devicePayments.utils.d.ts} +0 -0
- /package/dist/utils/{eventlogs.admin.utils.d.ts → admin/admin.eventLogs.utils.d.ts} +0 -0
- /package/dist/utils/{hierarchy.utils.d.ts → admin/admin.hierarchy.utils.d.ts} +0 -0
- /package/dist/utils/{moderation.utils.d.ts → admin/admin.moderation.utils.d.ts} +0 -0
- /package/dist/utils/{moderation.utils.js → admin/admin.moderation.utils.js} +0 -0
- /package/dist/utils/{product.utils.js → admin/admin.products.utils.js} +0 -0
- /package/dist/utils/{suspension.utils.d.ts → admin/admin.suspensions.utils.d.ts} +0 -0
- /package/dist/utils/{suspension.utils.js → admin/admin.suspensions.utils.js} +0 -0
- /package/dist/utils/{systemLog.utils.d.ts → admin/admin.systemLogs.utils.d.ts} +0 -0
- /package/dist/utils/{account.utils.d.ts → shared/shared.accounts.utils.d.ts} +0 -0
- /package/dist/utils/{authTokens.utils.d.ts → shared/shared.authTokens.utils.d.ts} +0 -0
- /package/dist/utils/{authTokens.utils.js → shared/shared.authTokens.utils.js} +0 -0
- /package/dist/utils/{eventLog.utils.d.ts → shared/shared.eventLogs.utils.d.ts} +0 -0
- /package/dist/utils/{eventLog.utils.js → shared/shared.eventLogs.utils.js} +0 -0
- /package/dist/utils/{response.utils.d.ts → shared/shared.responses.utils.d.ts} +0 -0
- /package/dist/utils/{response.utils.js → shared/shared.responses.utils.js} +0 -0
- /package/dist/utils/{types.d.ts → shared/shared.types.d.ts} +0 -0
- /package/dist/utils/{types.js → shared/shared.types.js} +0 -0
- /package/dist/validations/{bans.validations.d.ts → admin/admin.bans.validations.d.ts} +0 -0
- /package/dist/validations/{bans.validations.js → admin/admin.bans.validations.js} +0 -0
- /package/dist/validations/{admin.devicePayment.validations.d.ts → admin/admin.devicePayments.validations.d.ts} +0 -0
- /package/dist/validations/{admin.devices.validations.d.ts → admin/admin.devices.validations.d.ts} +0 -0
- /package/dist/validations/{eventlogs.admin.validations.d.ts → admin/admin.eventLogs.validations.d.ts} +0 -0
- /package/dist/validations/{admin.installment.validations.d.ts → admin/admin.installments.validations.d.ts} +0 -0
- /package/dist/validations/{pricings.validations.d.ts → admin/admin.pricings.validations.d.ts} +0 -0
- /package/dist/validations/{product.validations.d.ts → admin/admin.products.validations.d.ts} +0 -0
- /package/dist/validations/{suspensions.validations.d.ts → admin/admin.suspensions.validations.d.ts} +0 -0
- /package/dist/validations/{suspensions.validations.js → admin/admin.suspensions.validations.js} +0 -0
- /package/dist/validations/{users.admin.validations.d.ts → admin/admin.users.validations.d.ts} +0 -0
- /package/dist/validations/{account.validations.d.ts → shared/shared.account.validations.d.ts} +0 -0
- /package/dist/validations/{appSpecs.validations.d.ts → shared/shared.appSpecs.validations.d.ts} +0 -0
- /package/dist/validations/{auth.validations.d.ts → shared/shared.auth.validations.d.ts} +0 -0
- /package/dist/validations/{dateRange.validations.d.ts → shared/shared.dateRanges.validations.d.ts} +0 -0
- /package/dist/validations/{moderation.validations.d.ts → shared/shared.moderation.validations.d.ts} +0 -0
- /package/dist/validations/{profiles.validations.d.ts → shared/shared.profiles.validations.d.ts} +0 -0
- /package/dist/validations/{validate.validations.d.ts → shared/shared.validate.validations.d.ts} +0 -0
- /package/dist/validations/{validate.validations.js → shared/shared.validate.validations.js} +0 -0
- /package/dist/validations/{devicePaymentPlan.validations.d.ts → users/users.devicePaymentPlans.validations.d.ts} +0 -0
- /package/dist/validations/{devicePaymentPlan.validations.js → users/users.devicePaymentPlans.validations.js} +0 -0
- /package/dist/validations/{devices.validations.d.ts → users/users.devices.validations.d.ts} +0 -0
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setPrimaryContactSchema = exports.deleteContactSchema = exports.confirmVerificationSchema = exports.verifyContactSchema = exports.addContactSchema = exports.updateProfileSchema = exports.deleteAccountSchema = exports.deactivateAccountSchema = exports.updateRiderProfileSchema = exports.createRiderSchema = exports.updatePassengerProfileSchema = exports.passengerSignupSchema = exports.viewProfileSchema = exports.getAllUsersSchema = exports.updateUserProfileSchema = exports.getUserByIdSchema = exports.createUserSchema = exports.validateContactValue = exports.detectContactType = exports.strongPasswordRegex = exports.jacketIdRegex = exports.emailRegex = exports.phoneNumberRegex = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
const regex_constants_1 = require("../../constants/regex.constants");
|
|
5
6
|
// ============================================================================
|
|
6
7
|
// COMMON VALIDATIONS
|
|
7
8
|
// ============================================================================
|
|
8
|
-
exports.phoneNumberRegex =
|
|
9
|
-
exports.emailRegex =
|
|
10
|
-
exports.jacketIdRegex =
|
|
11
|
-
const plateRegex =
|
|
12
|
-
exports.strongPasswordRegex =
|
|
9
|
+
exports.phoneNumberRegex = regex_constants_1.PHONE_NUMBER_REGEX;
|
|
10
|
+
exports.emailRegex = regex_constants_1.EMAIL_ADDRESS_REGEX;
|
|
11
|
+
exports.jacketIdRegex = regex_constants_1.JACKET_ID_REGEX;
|
|
12
|
+
const plateRegex = regex_constants_1.PLATE_NUMBER_REGEX;
|
|
13
|
+
exports.strongPasswordRegex = regex_constants_1.STRONG_PASSWORD_REGEX;
|
|
13
14
|
// ============================================================================
|
|
14
15
|
// CONTACT VALIDATION HELPERS
|
|
15
16
|
// ============================================================================
|
|
@@ -89,7 +90,7 @@ exports.createUserSchema = zod_1.z.object({
|
|
|
89
90
|
path: ["birthDate"],
|
|
90
91
|
}),
|
|
91
92
|
headers: zod_1.z.object({
|
|
92
|
-
authorization: zod_1.z.string().regex(
|
|
93
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
93
94
|
message: "Authorization header must start with 'Bearer '",
|
|
94
95
|
}),
|
|
95
96
|
}),
|
|
@@ -100,7 +101,7 @@ exports.getUserByIdSchema = zod_1.z.object({
|
|
|
100
101
|
userId: zod_1.z.string().uuid("Invalid user ID format"),
|
|
101
102
|
}),
|
|
102
103
|
headers: zod_1.z.object({
|
|
103
|
-
authorization: zod_1.z.string().regex(
|
|
104
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
104
105
|
message: "Authorization header must start with 'Bearer '",
|
|
105
106
|
}),
|
|
106
107
|
}),
|
|
@@ -168,7 +169,7 @@ exports.updateUserProfileSchema = zod_1.z.object({
|
|
|
168
169
|
path: ["birthDate"],
|
|
169
170
|
}),
|
|
170
171
|
headers: zod_1.z.object({
|
|
171
|
-
authorization: zod_1.z.string().regex(
|
|
172
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
172
173
|
message: "Authorization header must start with 'Bearer '",
|
|
173
174
|
}),
|
|
174
175
|
}),
|
|
@@ -176,8 +177,8 @@ exports.updateUserProfileSchema = zod_1.z.object({
|
|
|
176
177
|
// Get All Users Schema (with pagination/filtering)
|
|
177
178
|
exports.getAllUsersSchema = zod_1.z.object({
|
|
178
179
|
query: zod_1.z.object({
|
|
179
|
-
page: zod_1.z.string().regex(
|
|
180
|
-
limit: zod_1.z.string().regex(
|
|
180
|
+
page: zod_1.z.string().regex(regex_constants_1.NUMERIC_STRING_REGEX).default("1").transform(Number).optional(),
|
|
181
|
+
limit: zod_1.z.string().regex(regex_constants_1.NUMERIC_STRING_REGEX).default("20").transform(Number).optional(),
|
|
181
182
|
role: zod_1.z
|
|
182
183
|
.enum(["RIDER", "PASSENGER", "AGENT", "ADMIN", "SUPER_ADMIN"])
|
|
183
184
|
.optional(),
|
|
@@ -200,7 +201,7 @@ exports.getAllUsersSchema = zod_1.z.object({
|
|
|
200
201
|
order: zod_1.z.enum(["asc", "desc"]).default("desc"),
|
|
201
202
|
}),
|
|
202
203
|
headers: zod_1.z.object({
|
|
203
|
-
authorization: zod_1.z.string().regex(
|
|
204
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
204
205
|
message: "Authorization header must start with 'Bearer '",
|
|
205
206
|
}),
|
|
206
207
|
}),
|
|
@@ -214,7 +215,7 @@ exports.viewProfileSchema = zod_1.z.object({
|
|
|
214
215
|
body: zod_1.z.object({}).optional(),
|
|
215
216
|
query: zod_1.z.object({}).optional(),
|
|
216
217
|
headers: zod_1.z.object({
|
|
217
|
-
authorization: zod_1.z.string().regex(
|
|
218
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
218
219
|
message: "Authorization header must start with 'Bearer '",
|
|
219
220
|
}),
|
|
220
221
|
}),
|
|
@@ -321,7 +322,7 @@ exports.updatePassengerProfileSchema = zod_1.z.object({
|
|
|
321
322
|
path: ["birthDate"],
|
|
322
323
|
}),
|
|
323
324
|
headers: zod_1.z.object({
|
|
324
|
-
authorization: zod_1.z.string().regex(
|
|
325
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
325
326
|
message: "Authorization header must start with 'Bearer '",
|
|
326
327
|
}),
|
|
327
328
|
}),
|
|
@@ -432,7 +433,7 @@ exports.updateRiderProfileSchema = zod_1.z.object({
|
|
|
432
433
|
}),
|
|
433
434
|
query: zod_1.z.object({}).optional(),
|
|
434
435
|
headers: zod_1.z.object({
|
|
435
|
-
authorization: zod_1.z.string().regex(
|
|
436
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
436
437
|
message: "Authorization header must start with 'Bearer '",
|
|
437
438
|
}),
|
|
438
439
|
}),
|
|
@@ -453,7 +454,7 @@ exports.deactivateAccountSchema = zod_1.z.object({
|
|
|
453
454
|
.optional(),
|
|
454
455
|
}),
|
|
455
456
|
headers: zod_1.z.object({
|
|
456
|
-
authorization: zod_1.z.string().regex(
|
|
457
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
457
458
|
message: "Authorization header must start with 'Bearer '",
|
|
458
459
|
}),
|
|
459
460
|
}),
|
|
@@ -471,7 +472,7 @@ exports.deleteAccountSchema = zod_1.z.object({
|
|
|
471
472
|
.optional(),
|
|
472
473
|
}),
|
|
473
474
|
headers: zod_1.z.object({
|
|
474
|
-
authorization: zod_1.z.string().regex(
|
|
475
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
475
476
|
message: "Authorization header must start with 'Bearer '",
|
|
476
477
|
}),
|
|
477
478
|
}),
|
|
@@ -529,7 +530,7 @@ exports.addContactSchema = zod_1.z.object({
|
|
|
529
530
|
type: zod_1.z.enum(["EMAIL", "PHONE", "WHATSAPP"]).optional(),
|
|
530
531
|
}),
|
|
531
532
|
headers: zod_1.z.object({
|
|
532
|
-
authorization: zod_1.z.string().regex(
|
|
533
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
533
534
|
message: "Authorization header must start with 'Bearer '",
|
|
534
535
|
}),
|
|
535
536
|
}),
|
|
@@ -540,7 +541,7 @@ exports.verifyContactSchema = zod_1.z.object({
|
|
|
540
541
|
contactId: zod_1.z.string().uuid("Invalid contact ID format"),
|
|
541
542
|
}),
|
|
542
543
|
headers: zod_1.z.object({
|
|
543
|
-
authorization: zod_1.z.string().regex(
|
|
544
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
544
545
|
message: "Authorization header must start with 'Bearer '",
|
|
545
546
|
}),
|
|
546
547
|
}),
|
|
@@ -554,7 +555,7 @@ exports.confirmVerificationSchema = zod_1.z.object({
|
|
|
554
555
|
contactId: zod_1.z.string().uuid("Invalid contact ID format"),
|
|
555
556
|
}),
|
|
556
557
|
headers: zod_1.z.object({
|
|
557
|
-
authorization: zod_1.z.string().regex(
|
|
558
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
558
559
|
message: "Authorization header must start with 'Bearer '",
|
|
559
560
|
}),
|
|
560
561
|
}),
|
|
@@ -565,7 +566,7 @@ exports.deleteContactSchema = zod_1.z.object({
|
|
|
565
566
|
contactId: zod_1.z.string().uuid("Invalid contact ID format"),
|
|
566
567
|
}),
|
|
567
568
|
headers: zod_1.z.object({
|
|
568
|
-
authorization: zod_1.z.string().regex(
|
|
569
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
569
570
|
message: "Authorization header must start with 'Bearer '",
|
|
570
571
|
}),
|
|
571
572
|
}),
|
|
@@ -576,7 +577,7 @@ exports.setPrimaryContactSchema = zod_1.z.object({
|
|
|
576
577
|
contactId: zod_1.z.string().uuid("Invalid contact ID format"),
|
|
577
578
|
}),
|
|
578
579
|
headers: zod_1.z.object({
|
|
579
|
-
authorization: zod_1.z.string().regex(
|
|
580
|
+
authorization: zod_1.z.string().regex(regex_constants_1.BEARER_TOKEN_PREFIX_REGEX, {
|
|
580
581
|
message: "Authorization header must start with 'Bearer '",
|
|
581
582
|
}),
|
|
582
583
|
}),
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extendSessionSchema = exports.unlockDeviceSchema = exports.serialRegex = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
|
|
5
|
+
const regex_constants_1 = require("../../constants/regex.constants");
|
|
6
|
+
exports.serialRegex = regex_constants_1.DEVICE_SERIAL_NUMBER_REGEX;
|
|
6
7
|
exports.unlockDeviceSchema = zod_1.z.object({
|
|
7
8
|
body: zod_1.z.object({
|
|
8
9
|
deviceSerialNumber: zod_1.z
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
export declare const idempotencyMiddleware: (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
3
|
-
export declare const storeIdempotencyResponse: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.storeIdempotencyResponse = exports.idempotencyMiddleware = void 0;
|
|
4
|
-
const vr_models_1 = require("vr-models");
|
|
5
|
-
const response_utils_1 = require("../utils/response.utils");
|
|
6
|
-
const idempotencyMiddleware = async (req, res, next) => {
|
|
7
|
-
// Skip for GET requests
|
|
8
|
-
if (req.method === "GET") {
|
|
9
|
-
return next();
|
|
10
|
-
}
|
|
11
|
-
const idempotencyKey = req.headers["idempotency-key"];
|
|
12
|
-
if (!idempotencyKey) {
|
|
13
|
-
return (0, response_utils_1.sendErrorResponse)(res, "Idempotency-Key header is required", 400);
|
|
14
|
-
}
|
|
15
|
-
// Validate UUID format
|
|
16
|
-
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
17
|
-
if (!uuidRegex.test(idempotencyKey)) {
|
|
18
|
-
return (0, response_utils_1.sendErrorResponse)(res, "Idempotency-Key must be a valid UUID", 400);
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
const existing = await vr_models_1.IdempotencyRecord.findOne({
|
|
22
|
-
where: { key: idempotencyKey },
|
|
23
|
-
});
|
|
24
|
-
if (existing && existing.isValid()) {
|
|
25
|
-
const response = existing.getResponse();
|
|
26
|
-
return res.status(response?.statusCode || 200).json(response?.body);
|
|
27
|
-
}
|
|
28
|
-
if (existing && existing.isExpired()) {
|
|
29
|
-
await vr_models_1.IdempotencyRecord.invalidate(idempotencyKey);
|
|
30
|
-
}
|
|
31
|
-
// Store original response methods
|
|
32
|
-
const originalJson = res.json.bind(res);
|
|
33
|
-
const originalStatus = res.status.bind(res);
|
|
34
|
-
res.json = function (body) {
|
|
35
|
-
res.locals.responseBody = body;
|
|
36
|
-
return originalJson(body);
|
|
37
|
-
};
|
|
38
|
-
res.status = function (code) {
|
|
39
|
-
res.locals.statusCode = code;
|
|
40
|
-
return originalStatus(code);
|
|
41
|
-
};
|
|
42
|
-
req.idempotencyKey = idempotencyKey;
|
|
43
|
-
next();
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error("Idempotency middleware error:", error);
|
|
47
|
-
next(error);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
exports.idempotencyMiddleware = idempotencyMiddleware;
|
|
51
|
-
// Store response after completion
|
|
52
|
-
const storeIdempotencyResponse = async (req, res, next) => {
|
|
53
|
-
if (req.method === "GET" || !req.idempotencyKey) {
|
|
54
|
-
return next();
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
const expiresAt = new Date();
|
|
58
|
-
expiresAt.setHours(expiresAt.getHours() + 24);
|
|
59
|
-
await vr_models_1.IdempotencyRecord.create({
|
|
60
|
-
key: req.idempotencyKey,
|
|
61
|
-
requestMethod: req.method,
|
|
62
|
-
requestPath: req.path,
|
|
63
|
-
requestParams: req.body,
|
|
64
|
-
responseStatusCode: res.locals.statusCode || 200,
|
|
65
|
-
responseBody: res.locals.responseBody || {},
|
|
66
|
-
expiresAt, // Add this
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error("Failed to store idempotency record:", error);
|
|
71
|
-
}
|
|
72
|
-
next();
|
|
73
|
-
};
|
|
74
|
-
exports.storeIdempotencyResponse = storeIdempotencyResponse;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractDedicatedUserFromSerial = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const extractDedicatedUserFromSerial = (serialNumber) => {
|
|
6
|
-
// Validate format first
|
|
7
|
-
const match = serialNumber.match(__1.serialRegex);
|
|
8
|
-
if (!match) {
|
|
9
|
-
console.warn(`Invalid serial number format: ${serialNumber}. Defaulting to N/A.`);
|
|
10
|
-
return "N/A";
|
|
11
|
-
}
|
|
12
|
-
// match[1] = VBRD or VIBERIDE (company)
|
|
13
|
-
// match[2] = PASSENGER or RIDER (dedicated user)
|
|
14
|
-
// match[3] = AA001A (serial)
|
|
15
|
-
const role = match[2];
|
|
16
|
-
if (role === "PASSENGER" || role === "RIDER") {
|
|
17
|
-
return role;
|
|
18
|
-
}
|
|
19
|
-
return "N/A";
|
|
20
|
-
};
|
|
21
|
-
exports.extractDedicatedUserFromSerial = extractDedicatedUserFromSerial;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { DeviceSessionPayload } from "vr-models";
|
|
2
|
-
/**
|
|
3
|
-
* Create a new device session (for BLE unlock)
|
|
4
|
-
* This is separate from the long-lasting auth token
|
|
5
|
-
*/
|
|
6
|
-
export declare const createDeviceSession: (userId: string, tokenVersion: number, deviceSerialNumber: string) => DeviceSessionPayload;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDeviceSession = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
// Session duration for device unlock sessions (12 minutes)
|
|
6
|
-
const SESSION_DURATION = parseInt(process.env.DEVICE_SESSION_DURATION || "12") * 60 * 1000; // Convert minutes to milliseconds
|
|
7
|
-
/**
|
|
8
|
-
* Create a new device session (for BLE unlock)
|
|
9
|
-
* This is separate from the long-lasting auth token
|
|
10
|
-
*/
|
|
11
|
-
const createDeviceSession = (userId, tokenVersion, deviceSerialNumber) => {
|
|
12
|
-
const now = Date.now();
|
|
13
|
-
return {
|
|
14
|
-
sessionId: (0, uuid_1.v4)(),
|
|
15
|
-
startedAt: now,
|
|
16
|
-
expiresAt: now + SESSION_DURATION,
|
|
17
|
-
userId,
|
|
18
|
-
tokenVersion,
|
|
19
|
-
deviceSerialNumber,
|
|
20
|
-
minutesGranted: SESSION_DURATION,
|
|
21
|
-
};
|
|
22
|
-
};
|
|
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
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const submitBanAppealSchema: z.ZodObject<{
|
|
3
|
-
params: z.ZodObject<{
|
|
4
|
-
banId: z.ZodString;
|
|
5
|
-
}, "strip", z.ZodTypeAny, {
|
|
6
|
-
banId: string;
|
|
7
|
-
}, {
|
|
8
|
-
banId: string;
|
|
9
|
-
}>;
|
|
10
|
-
body: z.ZodObject<{
|
|
11
|
-
appealReason: z.ZodString;
|
|
12
|
-
}, "strict", z.ZodTypeAny, {
|
|
13
|
-
appealReason: string;
|
|
14
|
-
}, {
|
|
15
|
-
appealReason: string;
|
|
16
|
-
}>;
|
|
17
|
-
}, "strip", z.ZodTypeAny, {
|
|
18
|
-
body: {
|
|
19
|
-
appealReason: string;
|
|
20
|
-
};
|
|
21
|
-
params: {
|
|
22
|
-
banId: string;
|
|
23
|
-
};
|
|
24
|
-
}, {
|
|
25
|
-
body: {
|
|
26
|
-
appealReason: string;
|
|
27
|
-
};
|
|
28
|
-
params: {
|
|
29
|
-
banId: string;
|
|
30
|
-
};
|
|
31
|
-
}>;
|
|
32
|
-
export declare const submitSuspensionAppealSchema: z.ZodObject<{
|
|
33
|
-
params: z.ZodObject<{
|
|
34
|
-
suspensionId: z.ZodString;
|
|
35
|
-
}, "strip", z.ZodTypeAny, {
|
|
36
|
-
suspensionId: string;
|
|
37
|
-
}, {
|
|
38
|
-
suspensionId: string;
|
|
39
|
-
}>;
|
|
40
|
-
body: z.ZodObject<{
|
|
41
|
-
appealReason: z.ZodString;
|
|
42
|
-
}, "strict", z.ZodTypeAny, {
|
|
43
|
-
appealReason: string;
|
|
44
|
-
}, {
|
|
45
|
-
appealReason: string;
|
|
46
|
-
}>;
|
|
47
|
-
}, "strip", z.ZodTypeAny, {
|
|
48
|
-
body: {
|
|
49
|
-
appealReason: string;
|
|
50
|
-
};
|
|
51
|
-
params: {
|
|
52
|
-
suspensionId: string;
|
|
53
|
-
};
|
|
54
|
-
}, {
|
|
55
|
-
body: {
|
|
56
|
-
appealReason: string;
|
|
57
|
-
};
|
|
58
|
-
params: {
|
|
59
|
-
suspensionId: string;
|
|
60
|
-
};
|
|
61
|
-
}>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.submitSuspensionAppealSchema = exports.submitBanAppealSchema = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const uuidSchema = zod_1.z.string().uuid("Invalid ID format");
|
|
6
|
-
exports.submitBanAppealSchema = zod_1.z.object({
|
|
7
|
-
params: zod_1.z.object({
|
|
8
|
-
banId: uuidSchema,
|
|
9
|
-
}),
|
|
10
|
-
body: zod_1.z
|
|
11
|
-
.object({
|
|
12
|
-
appealReason: zod_1.z
|
|
13
|
-
.string()
|
|
14
|
-
.min(10, "Appeal reason must be at least 10 characters")
|
|
15
|
-
.max(2000, "Appeal reason cannot exceed 2000 characters"),
|
|
16
|
-
})
|
|
17
|
-
.strict(),
|
|
18
|
-
});
|
|
19
|
-
exports.submitSuspensionAppealSchema = zod_1.z.object({
|
|
20
|
-
params: zod_1.z.object({
|
|
21
|
-
suspensionId: uuidSchema,
|
|
22
|
-
}),
|
|
23
|
-
body: zod_1.z
|
|
24
|
-
.object({
|
|
25
|
-
appealReason: zod_1.z
|
|
26
|
-
.string()
|
|
27
|
-
.min(10, "Appeal reason must be at least 10 characters")
|
|
28
|
-
.max(2000, "Appeal reason cannot exceed 2000 characters"),
|
|
29
|
-
})
|
|
30
|
-
.strict(),
|
|
31
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const payInstallmentSchema: z.ZodObject<{
|
|
3
|
-
params: z.ZodObject<{
|
|
4
|
-
id: z.ZodString;
|
|
5
|
-
}, "strip", z.ZodTypeAny, {
|
|
6
|
-
id: string;
|
|
7
|
-
}, {
|
|
8
|
-
id: string;
|
|
9
|
-
}>;
|
|
10
|
-
body: z.ZodObject<{
|
|
11
|
-
amount: z.ZodNumber;
|
|
12
|
-
provider: z.ZodDefault<z.ZodEnum<["AIRTEL_MONEY", "CASH", "MOMO_PAY"]>>;
|
|
13
|
-
providerReference: z.ZodString;
|
|
14
|
-
customerPhone: z.ZodString;
|
|
15
|
-
notes: z.ZodOptional<z.ZodString>;
|
|
16
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
17
|
-
}, "strip", z.ZodTypeAny, {
|
|
18
|
-
amount: number;
|
|
19
|
-
provider: "AIRTEL_MONEY" | "CASH" | "MOMO_PAY";
|
|
20
|
-
providerReference: string;
|
|
21
|
-
customerPhone: string;
|
|
22
|
-
notes?: string | undefined;
|
|
23
|
-
metadata?: Record<string, any> | undefined;
|
|
24
|
-
}, {
|
|
25
|
-
amount: number;
|
|
26
|
-
providerReference: string;
|
|
27
|
-
customerPhone: string;
|
|
28
|
-
provider?: "AIRTEL_MONEY" | "CASH" | "MOMO_PAY" | undefined;
|
|
29
|
-
notes?: string | undefined;
|
|
30
|
-
metadata?: Record<string, any> | undefined;
|
|
31
|
-
}>;
|
|
32
|
-
}, "strip", z.ZodTypeAny, {
|
|
33
|
-
params: {
|
|
34
|
-
id: string;
|
|
35
|
-
};
|
|
36
|
-
body: {
|
|
37
|
-
amount: number;
|
|
38
|
-
provider: "AIRTEL_MONEY" | "CASH" | "MOMO_PAY";
|
|
39
|
-
providerReference: string;
|
|
40
|
-
customerPhone: string;
|
|
41
|
-
notes?: string | undefined;
|
|
42
|
-
metadata?: Record<string, any> | undefined;
|
|
43
|
-
};
|
|
44
|
-
}, {
|
|
45
|
-
params: {
|
|
46
|
-
id: string;
|
|
47
|
-
};
|
|
48
|
-
body: {
|
|
49
|
-
amount: number;
|
|
50
|
-
providerReference: string;
|
|
51
|
-
customerPhone: string;
|
|
52
|
-
provider?: "AIRTEL_MONEY" | "CASH" | "MOMO_PAY" | undefined;
|
|
53
|
-
notes?: string | undefined;
|
|
54
|
-
metadata?: Record<string, any> | undefined;
|
|
55
|
-
};
|
|
56
|
-
}>;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.payInstallmentSchema = void 0;
|
|
4
|
-
const vr_models_1 = require("vr-models");
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
|
-
const phoneRegex = /^\+250(78|79|73|72)[0-9]{7}$/;
|
|
7
|
-
console.log("from vr-commons", vr_models_1.PAYMENT_PROVIDER);
|
|
8
|
-
// src/modules/installments/validations/installments.validations.ts
|
|
9
|
-
exports.payInstallmentSchema = zod_1.z.object({
|
|
10
|
-
params: zod_1.z.object({
|
|
11
|
-
id: zod_1.z.string().uuid("Invalid installment ID"),
|
|
12
|
-
}),
|
|
13
|
-
body: zod_1.z.object({
|
|
14
|
-
amount: zod_1.z.number().min(0.01, "Amount must be greater than 0"),
|
|
15
|
-
provider: zod_1.z.enum([...vr_models_1.PAYMENT_PROVIDER]).default("MOMO_PAY"),
|
|
16
|
-
providerReference: zod_1.z.string(),
|
|
17
|
-
customerPhone: zod_1.z
|
|
18
|
-
.string()
|
|
19
|
-
.regex(phoneRegex, "Invalid MTN Rwanda phone number"),
|
|
20
|
-
notes: zod_1.z.string().optional(),
|
|
21
|
-
metadata: zod_1.z.record(zod_1.z.any()).optional(),
|
|
22
|
-
}),
|
|
23
|
-
});
|