vr-commons 1.0.176 → 1.0.178

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.
Files changed (101) hide show
  1. package/dist/constants/regex.constants.d.ts +19 -0
  2. package/dist/constants/regex.constants.js +24 -0
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.js +0 -3
  5. package/dist/middlewares/admin/admin.auth.middleware.js +60 -0
  6. package/dist/middlewares/index.d.ts +4 -5
  7. package/dist/middlewares/index.js +11 -14
  8. package/dist/middlewares/shared/auth.admin.middlewares.d.ts +3 -0
  9. package/dist/middlewares/{auth.admin.middlewares.js → shared/auth.admin.middlewares.js} +7 -7
  10. package/dist/middlewares/{account.shared.middlewares.js → shared/shared.account.middleware.js} +8 -8
  11. package/dist/middlewares/{errorHandler.middleware.js → shared/shared.errorHandler.middleware.js} +0 -1
  12. package/dist/middlewares/{auth.users.middlewares.js → users/users.auth.middleware.js} +10 -10
  13. package/dist/utils/{admin.devicePayment.utils.d.ts → admin/admin.devicePayments.utils.d.ts} +2 -1
  14. package/dist/utils/{admin.devicePayment.utils.js → admin/admin.devicePayments.utils.js} +13 -10
  15. package/dist/utils/{admin.device.utils.d.ts → admin/admin.devices.utils.d.ts} +1 -1
  16. package/dist/utils/{admin.device.utils.js → admin/admin.devices.utils.js} +11 -12
  17. package/dist/utils/{eventlogs.admin.utils.js → admin/admin.eventLogs.utils.js} +0 -1
  18. package/dist/utils/{hierarchy.utils.js → admin/admin.hierarchy.utils.js} +0 -2
  19. package/dist/utils/{product.utils.d.ts → admin/admin.products.utils.d.ts} +1 -1
  20. package/dist/utils/{systemLog.utils.js → admin/admin.systemLogs.utils.js} +0 -1
  21. package/dist/utils/index.d.ts +16 -18
  22. package/dist/utils/index.js +88 -99
  23. package/dist/utils/{account.utils.js → shared/shared.accounts.utils.js} +0 -1
  24. package/dist/utils/{profiles.utils.d.ts → shared/shared.profiles.utils.d.ts} +2 -1
  25. package/dist/utils/{profiles.utils.js → shared/shared.profiles.utils.js} +3 -2
  26. package/dist/utils/{verification.utils.d.ts → users/users.verification.utils.d.ts} +1 -1
  27. package/dist/utils/{verification.utils.js → users/users.verification.utils.js} +5 -4
  28. package/dist/validations/{admin.devicePayment.validations.d.ts → admin/admin.devicePayments.validations.d.ts} +59 -59
  29. package/dist/validations/{admin.devicePayment.validations.js → admin/admin.devicePayments.validations.js} +4 -3
  30. package/dist/validations/{admin.devices.validations.d.ts → admin/admin.devices.validations.d.ts} +22 -22
  31. package/dist/validations/{admin.devices.validations.js → admin/admin.devices.validations.js} +4 -5
  32. package/dist/validations/{eventlogs.admin.validations.d.ts → admin/admin.eventLogs.validations.d.ts} +14 -14
  33. package/dist/validations/{eventlogs.admin.validations.js → admin/admin.eventLogs.validations.js} +2 -2
  34. package/dist/validations/{admin.installment.validations.js → admin/admin.installments.validations.js} +5 -4
  35. package/dist/validations/{pricings.validations.d.ts → admin/admin.pricings.validations.d.ts} +60 -60
  36. package/dist/validations/{pricings.validations.js → admin/admin.pricings.validations.js} +5 -5
  37. package/dist/validations/{product.validations.d.ts → admin/admin.products.validations.d.ts} +32 -32
  38. package/dist/validations/{product.validations.js → admin/admin.products.validations.js} +4 -3
  39. package/dist/validations/{users.admin.validations.d.ts → admin/admin.users.validations.d.ts} +44 -44
  40. package/dist/validations/{users.admin.validations.js → admin/admin.users.validations.js} +13 -13
  41. package/dist/validations/index.d.ts +16 -15
  42. package/dist/validations/index.js +132 -125
  43. package/dist/validations/{account.validations.js → shared/shared.account.validations.js} +7 -7
  44. package/dist/validations/{appSpecs.validations.d.ts → shared/shared.appSpecs.validations.d.ts} +14 -14
  45. package/dist/validations/{appSpecs.validations.js → shared/shared.appSpecs.validations.js} +0 -1
  46. package/dist/validations/{auth.validations.js → shared/shared.auth.validations.js} +6 -6
  47. package/dist/validations/{dateRange.validations.js → shared/shared.dateRanges.validations.js} +5 -5
  48. package/dist/validations/{moderation.validations.d.ts → shared/shared.moderation.validations.d.ts} +111 -111
  49. package/dist/validations/{moderation.validations.js → shared/shared.moderation.validations.js} +24 -25
  50. package/dist/validations/{profiles.validations.d.ts → shared/shared.profiles.validations.d.ts} +36 -36
  51. package/dist/validations/{profiles.validations.js → shared/shared.profiles.validations.js} +22 -21
  52. package/dist/validations/{devicePaymentPlan.validations.d.ts → users/users.devicePaymentPlans.validations.d.ts} +16 -16
  53. package/dist/validations/{devices.validations.js → users/users.devices.validations.js} +2 -1
  54. package/package.json +1 -1
  55. package/dist/middlewares/idempotency.middlewares.d.ts +0 -3
  56. package/dist/middlewares/idempotency.middlewares.js +0 -74
  57. package/dist/utils/deviceUtils.d.ts +0 -2
  58. package/dist/utils/deviceUtils.js +0 -21
  59. package/dist/utils/session.utils.d.ts +0 -6
  60. package/dist/utils/session.utils.js +0 -25
  61. package/dist/validations/appeals.validations.d.ts +0 -61
  62. package/dist/validations/appeals.validations.js +0 -31
  63. package/dist/validations/payinstallment.validations.d.ts +0 -56
  64. package/dist/validations/payinstallment.validations.js +0 -23
  65. package/dist/validations/pricing.validations.d.ts +0 -313
  66. package/dist/validations/pricing.validations.js +0 -376
  67. package/dist/middlewares/{auth.admin.middlewares.d.ts → admin/admin.auth.middleware.d.ts} +0 -0
  68. package/dist/middlewares/{account.shared.middlewares.d.ts → shared/shared.account.middleware.d.ts} +0 -0
  69. package/dist/middlewares/{errorHandler.middleware.d.ts → shared/shared.errorHandler.middleware.d.ts} +0 -0
  70. package/dist/middlewares/{auth.users.middlewares.d.ts → users/users.auth.middleware.d.ts} +0 -0
  71. package/dist/utils/{bans.utils.d.ts → admin/admin.bans.utils.d.ts} +0 -0
  72. package/dist/utils/{bans.utils.js → admin/admin.bans.utils.js} +0 -0
  73. package/dist/utils/{eventlogs.admin.utils.d.ts → admin/admin.eventLogs.utils.d.ts} +0 -0
  74. package/dist/utils/{hierarchy.utils.d.ts → admin/admin.hierarchy.utils.d.ts} +0 -0
  75. package/dist/utils/{moderation.utils.d.ts → admin/admin.moderation.utils.d.ts} +0 -0
  76. package/dist/utils/{moderation.utils.js → admin/admin.moderation.utils.js} +0 -0
  77. package/dist/utils/{product.utils.js → admin/admin.products.utils.js} +0 -0
  78. package/dist/utils/{suspension.utils.d.ts → admin/admin.suspensions.utils.d.ts} +0 -0
  79. package/dist/utils/{suspension.utils.js → admin/admin.suspensions.utils.js} +0 -0
  80. package/dist/utils/{systemLog.utils.d.ts → admin/admin.systemLogs.utils.d.ts} +0 -0
  81. package/dist/utils/{account.utils.d.ts → shared/shared.accounts.utils.d.ts} +0 -0
  82. package/dist/utils/{authTokens.utils.d.ts → shared/shared.authTokens.utils.d.ts} +0 -0
  83. package/dist/utils/{authTokens.utils.js → shared/shared.authTokens.utils.js} +0 -0
  84. package/dist/utils/{eventLog.utils.d.ts → shared/shared.eventLogs.utils.d.ts} +0 -0
  85. package/dist/utils/{eventLog.utils.js → shared/shared.eventLogs.utils.js} +0 -0
  86. package/dist/utils/{response.utils.d.ts → shared/shared.responses.utils.d.ts} +0 -0
  87. package/dist/utils/{response.utils.js → shared/shared.responses.utils.js} +0 -0
  88. package/dist/utils/{types.d.ts → shared/shared.types.d.ts} +0 -0
  89. package/dist/utils/{types.js → shared/shared.types.js} +0 -0
  90. package/dist/validations/{bans.validations.d.ts → admin/admin.bans.validations.d.ts} +8 -8
  91. package/dist/validations/{bans.validations.js → admin/admin.bans.validations.js} +0 -0
  92. package/dist/validations/{admin.installment.validations.d.ts → admin/admin.installments.validations.d.ts} +16 -16
  93. package/dist/validations/{suspensions.validations.d.ts → admin/admin.suspensions.validations.d.ts} +8 -8
  94. /package/dist/validations/{suspensions.validations.js → admin/admin.suspensions.validations.js} +0 -0
  95. /package/dist/validations/{account.validations.d.ts → shared/shared.account.validations.d.ts} +0 -0
  96. /package/dist/validations/{auth.validations.d.ts → shared/shared.auth.validations.d.ts} +0 -0
  97. /package/dist/validations/{dateRange.validations.d.ts → shared/shared.dateRanges.validations.d.ts} +0 -0
  98. /package/dist/validations/{validate.validations.d.ts → shared/shared.validate.validations.d.ts} +0 -0
  99. /package/dist/validations/{validate.validations.js → shared/shared.validate.validations.js} +0 -0
  100. /package/dist/validations/{devicePaymentPlan.validations.js → users/users.devicePaymentPlans.validations.js} +0 -0
  101. /package/dist/validations/{devices.validations.d.ts → users/users.devices.validations.d.ts} +0 -0
@@ -241,6 +241,9 @@ export declare const updateUserProfileSchema: z.ZodObject<{
241
241
  authorization: string;
242
242
  }>;
243
243
  }, "strip", z.ZodTypeAny, {
244
+ params: {
245
+ userId: string;
246
+ };
244
247
  body: {
245
248
  firstName?: string | undefined;
246
249
  lastName?: string | undefined;
@@ -254,13 +257,13 @@ export declare const updateUserProfileSchema: z.ZodObject<{
254
257
  isDeactivated?: boolean | undefined;
255
258
  contactValue?: string | undefined;
256
259
  };
257
- params: {
258
- userId: string;
259
- };
260
260
  headers: {
261
261
  authorization: string;
262
262
  };
263
263
  }, {
264
+ params: {
265
+ userId: string;
266
+ };
264
267
  body: {
265
268
  firstName?: string | undefined;
266
269
  lastName?: string | undefined;
@@ -274,9 +277,6 @@ export declare const updateUserProfileSchema: z.ZodObject<{
274
277
  isDeactivated?: boolean | undefined;
275
278
  contactValue?: string | undefined;
276
279
  };
277
- params: {
278
- userId: string;
279
- };
280
280
  headers: {
281
281
  authorization: string;
282
282
  };
@@ -296,31 +296,31 @@ export declare const getAllUsersSchema: z.ZodObject<{
296
296
  sortBy: z.ZodDefault<z.ZodEnum<["firstName", "lastLoginAt", "createdAt", "gender"]>>;
297
297
  order: z.ZodDefault<z.ZodEnum<["asc", "desc"]>>;
298
298
  }, "strip", z.ZodTypeAny, {
299
+ sortBy: "createdAt" | "firstName" | "gender" | "lastLoginAt";
299
300
  order: "asc" | "desc";
300
- sortBy: "firstName" | "gender" | "lastLoginAt" | "createdAt";
301
- search?: string | undefined;
301
+ page?: number | undefined;
302
302
  limit?: number | undefined;
303
+ search?: string | undefined;
303
304
  gender?: "male" | "female" | undefined;
304
305
  isActive?: boolean | undefined;
305
306
  isDeactivated?: boolean | undefined;
306
307
  role?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
307
- page?: number | undefined;
308
308
  contactType?: "EMAIL" | "PHONE" | "WHATSAPP" | undefined;
309
309
  startDate?: string | undefined;
310
310
  endDate?: string | undefined;
311
311
  }, {
312
+ page?: string | undefined;
313
+ limit?: string | undefined;
312
314
  search?: string | undefined;
315
+ sortBy?: "createdAt" | "firstName" | "gender" | "lastLoginAt" | undefined;
313
316
  order?: "asc" | "desc" | undefined;
314
- limit?: string | undefined;
315
317
  gender?: "male" | "female" | undefined;
316
318
  isActive?: "true" | "false" | undefined;
317
319
  isDeactivated?: "true" | "false" | undefined;
318
320
  role?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
319
- page?: string | undefined;
320
321
  contactType?: "EMAIL" | "PHONE" | "WHATSAPP" | undefined;
321
322
  startDate?: string | undefined;
322
323
  endDate?: string | undefined;
323
- sortBy?: "firstName" | "gender" | "lastLoginAt" | "createdAt" | undefined;
324
324
  }>;
325
325
  headers: z.ZodObject<{
326
326
  authorization: z.ZodString;
@@ -331,15 +331,15 @@ export declare const getAllUsersSchema: z.ZodObject<{
331
331
  }>;
332
332
  }, "strip", z.ZodTypeAny, {
333
333
  query: {
334
+ sortBy: "createdAt" | "firstName" | "gender" | "lastLoginAt";
334
335
  order: "asc" | "desc";
335
- sortBy: "firstName" | "gender" | "lastLoginAt" | "createdAt";
336
- search?: string | undefined;
336
+ page?: number | undefined;
337
337
  limit?: number | undefined;
338
+ search?: string | undefined;
338
339
  gender?: "male" | "female" | undefined;
339
340
  isActive?: boolean | undefined;
340
341
  isDeactivated?: boolean | undefined;
341
342
  role?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
342
- page?: number | undefined;
343
343
  contactType?: "EMAIL" | "PHONE" | "WHATSAPP" | undefined;
344
344
  startDate?: string | undefined;
345
345
  endDate?: string | undefined;
@@ -349,18 +349,18 @@ export declare const getAllUsersSchema: z.ZodObject<{
349
349
  };
350
350
  }, {
351
351
  query: {
352
+ page?: string | undefined;
353
+ limit?: string | undefined;
352
354
  search?: string | undefined;
355
+ sortBy?: "createdAt" | "firstName" | "gender" | "lastLoginAt" | undefined;
353
356
  order?: "asc" | "desc" | undefined;
354
- limit?: string | undefined;
355
357
  gender?: "male" | "female" | undefined;
356
358
  isActive?: "true" | "false" | undefined;
357
359
  isDeactivated?: "true" | "false" | undefined;
358
360
  role?: "ADMIN" | "PASSENGER" | "RIDER" | "AGENT" | "SUPER_ADMIN" | undefined;
359
- page?: string | undefined;
360
361
  contactType?: "EMAIL" | "PHONE" | "WHATSAPP" | undefined;
361
362
  startDate?: string | undefined;
362
363
  endDate?: string | undefined;
363
- sortBy?: "firstName" | "gender" | "lastLoginAt" | "createdAt" | undefined;
364
364
  };
365
365
  headers: {
366
366
  authorization: string;
@@ -381,16 +381,16 @@ export declare const viewProfileSchema: z.ZodObject<{
381
381
  headers: {
382
382
  authorization: string;
383
383
  };
384
- body?: {} | undefined;
385
- query?: {} | undefined;
386
384
  params?: {} | undefined;
385
+ query?: {} | undefined;
386
+ body?: {} | undefined;
387
387
  }, {
388
388
  headers: {
389
389
  authorization: string;
390
390
  };
391
- body?: {} | undefined;
392
- query?: {} | undefined;
393
391
  params?: {} | undefined;
392
+ query?: {} | undefined;
393
+ body?: {} | undefined;
394
394
  }>;
395
395
  export declare const passengerSignupSchema: z.ZodObject<{
396
396
  body: z.ZodEffects<z.ZodObject<{
@@ -640,8 +640,8 @@ export declare const createRiderSchema: z.ZodObject<{
640
640
  birthYear: number;
641
641
  contactValue: string;
642
642
  };
643
- query?: {} | undefined;
644
643
  params?: {} | undefined;
644
+ query?: {} | undefined;
645
645
  }, {
646
646
  body: {
647
647
  firstName: string;
@@ -654,8 +654,8 @@ export declare const createRiderSchema: z.ZodObject<{
654
654
  birthYear: number;
655
655
  contactValue: string;
656
656
  };
657
- query?: {} | undefined;
658
657
  params?: {} | undefined;
658
+ query?: {} | undefined;
659
659
  }>;
660
660
  export declare const updateRiderProfileSchema: z.ZodObject<{
661
661
  params: z.ZodObject<{
@@ -745,6 +745,9 @@ export declare const updateRiderProfileSchema: z.ZodObject<{
745
745
  authorization: string;
746
746
  }>;
747
747
  }, "strip", z.ZodTypeAny, {
748
+ params: {
749
+ id: string;
750
+ };
748
751
  body: {
749
752
  firstName?: string | undefined;
750
753
  lastName?: string | undefined;
@@ -756,14 +759,14 @@ export declare const updateRiderProfileSchema: z.ZodObject<{
756
759
  birthYear?: number | undefined;
757
760
  contactValue?: string | undefined;
758
761
  };
759
- params: {
760
- id: string;
761
- };
762
762
  headers: {
763
763
  authorization: string;
764
764
  };
765
765
  query?: {} | undefined;
766
766
  }, {
767
+ params: {
768
+ id: string;
769
+ };
767
770
  body: {
768
771
  firstName?: string | undefined;
769
772
  lastName?: string | undefined;
@@ -775,9 +778,6 @@ export declare const updateRiderProfileSchema: z.ZodObject<{
775
778
  birthYear?: number | undefined;
776
779
  contactValue?: string | undefined;
777
780
  };
778
- params: {
779
- id: string;
780
- };
781
781
  headers: {
782
782
  authorization: string;
783
783
  };
@@ -1010,22 +1010,22 @@ export declare const confirmVerificationSchema: z.ZodObject<{
1010
1010
  authorization: string;
1011
1011
  }>;
1012
1012
  }, "strip", z.ZodTypeAny, {
1013
- body: {
1014
- otp: string;
1015
- };
1016
1013
  params: {
1017
1014
  contactId: string;
1018
1015
  };
1016
+ body: {
1017
+ otp: string;
1018
+ };
1019
1019
  headers: {
1020
1020
  authorization: string;
1021
1021
  };
1022
1022
  }, {
1023
- body: {
1024
- otp: string;
1025
- };
1026
1023
  params: {
1027
1024
  contactId: string;
1028
1025
  };
1026
+ body: {
1027
+ otp: string;
1028
+ };
1029
1029
  headers: {
1030
1030
  authorization: string;
1031
1031
  };
@@ -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 = /^\+250(78|79|73|72)[0-9]{7}$/;
9
- exports.emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
10
- exports.jacketIdRegex = /^JKT-\d{9}$/;
11
- const plateRegex = /^[A-Z0-9]{3,10}$/i;
12
- exports.strongPasswordRegex = /^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#^()_\-+=])[A-Za-z\d@$!%*?&#^()_\-+=]{8,}$/;
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^\d+$/).default("1").transform(Number).optional(),
180
- limit: zod_1.z.string().regex(/^\d+$/).default("20").transform(Number).optional(),
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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(/^Bearer /, {
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
  }),
@@ -7,33 +7,33 @@ export declare const listUserPaymentPlansSchema: z.ZodObject<{
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
- limit: number;
11
10
  page: number;
12
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
13
- sortBy?: "createdAt" | "updatedAt" | "status" | "nextInstallmentDueAt" | undefined;
14
- sortOrder?: "DESC" | "ASC" | undefined;
11
+ limit: number;
12
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
13
+ sortBy?: "status" | "createdAt" | "updatedAt" | "nextInstallmentDueAt" | undefined;
14
+ sortOrder?: "ASC" | "DESC" | undefined;
15
15
  }, {
16
- limit?: string | undefined;
17
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
16
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
18
17
  page?: string | undefined;
19
- sortBy?: "createdAt" | "updatedAt" | "status" | "nextInstallmentDueAt" | undefined;
20
- sortOrder?: "DESC" | "ASC" | undefined;
18
+ limit?: string | undefined;
19
+ sortBy?: "status" | "createdAt" | "updatedAt" | "nextInstallmentDueAt" | undefined;
20
+ sortOrder?: "ASC" | "DESC" | undefined;
21
21
  }>;
22
22
  }, "strip", z.ZodTypeAny, {
23
23
  query: {
24
- limit: number;
25
24
  page: number;
26
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
27
- sortBy?: "createdAt" | "updatedAt" | "status" | "nextInstallmentDueAt" | undefined;
28
- sortOrder?: "DESC" | "ASC" | undefined;
25
+ limit: number;
26
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
27
+ sortBy?: "status" | "createdAt" | "updatedAt" | "nextInstallmentDueAt" | undefined;
28
+ sortOrder?: "ASC" | "DESC" | undefined;
29
29
  };
30
30
  }, {
31
31
  query: {
32
- limit?: string | undefined;
33
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
32
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
34
33
  page?: string | undefined;
35
- sortBy?: "createdAt" | "updatedAt" | "status" | "nextInstallmentDueAt" | undefined;
36
- sortOrder?: "DESC" | "ASC" | undefined;
34
+ limit?: string | undefined;
35
+ sortBy?: "status" | "createdAt" | "updatedAt" | "nextInstallmentDueAt" | undefined;
36
+ sortOrder?: "ASC" | "DESC" | undefined;
37
37
  };
38
38
  }>;
39
39
  export declare const getUserPaymentPlanSchema: z.ZodObject<{
@@ -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
- exports.serialRegex = /^(VBRD|VIBERIDE)-(PASSENGER|RIDER)-([A-Z]{2}\d{3}[A-Z])$/;
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,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-commons",
3
- "version": "1.0.176",
3
+ "version": "1.0.178",
4
4
  "description": "Shared functions package",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -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,2 +0,0 @@
1
- import { DeviceDedication } from "vr-models";
2
- export declare const extractDedicatedUserFromSerial: (serialNumber: string) => DeviceDedication;
@@ -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
- }>;