vr-commons 1.0.113 → 1.0.115

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,13 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.jacketIdRegex = exports.phoneNumberRegex = void 0;
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
5
  // ============================================================================
6
6
  // COMMON VALIDATIONS
7
7
  // ============================================================================
8
- exports.phoneNumberRegex = /^\+?[0-9]{10,15}$/;
8
+ exports.phoneNumberRegex = /^\+250(78|79|73|72)[0-9]{7}$/;
9
+ exports.emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
9
10
  exports.jacketIdRegex = /^JKT-\d{9}$/;
10
- const phoneRegex = /^\+250(78|79|73|72)[0-9]{7}$/;
11
+ const plateRegex = /^[A-Z0-9]{3,10}$/i;
12
+ exports.strongPasswordRegex = /^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#^()_\-+=])[A-Za-z\d@$!%*?&#^()_\-+=]{8,}$/;
13
+ // ============================================================================
14
+ // CONTACT VALIDATION HELPERS
15
+ // ============================================================================
16
+ const detectContactType = (value) => {
17
+ if (!value)
18
+ return "UNKNOWN";
19
+ if (exports.emailRegex.test(value)) {
20
+ return "EMAIL";
21
+ }
22
+ if (exports.phoneNumberRegex.test(value)) {
23
+ return "PHONE";
24
+ }
25
+ return "UNKNOWN";
26
+ };
27
+ exports.detectContactType = detectContactType;
28
+ const validateContactValue = (value) => {
29
+ return exports.emailRegex.test(value) || exports.phoneNumberRegex.test(value);
30
+ };
31
+ exports.validateContactValue = validateContactValue;
11
32
  // Birth date validation helpers
12
33
  const isValidBirthDate = (date, month, year) => {
13
34
  const maxDays = new Date(year, month, 0).getDate();
@@ -28,25 +49,22 @@ exports.createUserSchema = zod_1.z.object({
28
49
  .string()
29
50
  .min(2, "Last name must be at least 2 characters")
30
51
  .max(100, "Last name cannot exceed 100 characters"),
31
- phoneNumber: zod_1.z
52
+ contactValue: zod_1.z
32
53
  .string()
33
- .regex(exports.phoneNumberRegex, "Phone number must be a valid Rwandan number (078/079/072/073) followed by 7 digits"),
34
- email: zod_1.z
35
- .string()
36
- .email("Invalid email address")
37
- .optional()
38
- .nullable()
39
- .or(zod_1.z.literal("")),
54
+ .min(1, "Email or phone number is required")
55
+ .refine((val) => (0, exports.validateContactValue)(val), {
56
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
57
+ }),
40
58
  password: zod_1.z
41
59
  .string()
42
- .min(6, "Password must be at least 6 characters")
43
- .max(100, "Password cannot exceed 100 characters")
60
+ .regex(exports.strongPasswordRegex, "Password must be at least 8 characters, include 1 uppercase letter, 1 number and 1 symbol")
44
61
  .optional(),
45
62
  role: zod_1.z.enum(["AGENT", "RIDER", "PASSENGER", "ADMIN", "SUPER_ADMIN"], {
46
63
  errorMap: () => ({ message: "Invalid role specified" }),
47
64
  }),
48
65
  plateNumber: zod_1.z
49
66
  .string()
67
+ .regex(plateRegex, "Invalid plate number format")
50
68
  .max(20, "Plate number cannot exceed 20 characters")
51
69
  .optional()
52
70
  .nullable(),
@@ -104,28 +122,23 @@ exports.updateUserProfileSchema = zod_1.z.object({
104
122
  .min(2, "Last name must be at least 2 characters")
105
123
  .max(100, "Last name cannot exceed 100 characters")
106
124
  .optional(),
107
- email: zod_1.z
108
- .string()
109
- .email("Invalid email address")
110
- .optional()
111
- .nullable()
112
- .or(zod_1.z.literal("")),
113
- phoneNumber: zod_1.z
125
+ contactValue: zod_1.z
114
126
  .string()
115
- .regex(exports.phoneNumberRegex, "Invalid phone number format")
127
+ .refine((val) => (0, exports.validateContactValue)(val), {
128
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
129
+ })
116
130
  .optional(),
117
131
  plateNumber: zod_1.z
118
132
  .string()
133
+ .regex(plateRegex, "Invalid plate number format")
119
134
  .max(20, "Plate number cannot exceed 20 characters")
120
135
  .optional()
121
136
  .nullable(),
122
137
  isActive: zod_1.z.boolean().optional(),
123
- isSuspended: zod_1.z.boolean().optional(),
124
138
  isDeactivated: zod_1.z.boolean().optional(),
125
139
  password: zod_1.z
126
140
  .string()
127
- .min(6, "Password must be at least 6 characters")
128
- .max(100, "Password cannot exceed 100 characters")
141
+ .regex(exports.strongPasswordRegex, "Password must be at least 8 characters, include 1 uppercase letter, 1 number and 1 symbol")
129
142
  .optional(),
130
143
  gender: zod_1.z.enum(["male", "female"]).optional(),
131
144
  birthDate: zod_1.z.number().min(1).max(31).optional(),
@@ -172,15 +185,12 @@ exports.getAllUsersSchema = zod_1.z.object({
172
185
  .enum(["true", "false"])
173
186
  .transform((val) => val === "true")
174
187
  .optional(),
175
- isSuspended: zod_1.z
176
- .enum(["true", "false"])
177
- .transform((val) => val === "true")
178
- .optional(),
179
- isBanned: zod_1.z
188
+ isDeactivated: zod_1.z
180
189
  .enum(["true", "false"])
181
190
  .transform((val) => val === "true")
182
191
  .optional(),
183
192
  gender: zod_1.z.enum(["male", "female"]).optional(),
193
+ contactType: zod_1.z.enum(["EMAIL", "PHONE", "WHATSAPP"]).optional(),
184
194
  search: zod_1.z.string().optional(),
185
195
  startDate: zod_1.z.string().optional(),
186
196
  endDate: zod_1.z.string().optional(),
@@ -224,27 +234,24 @@ exports.passengerSignupSchema = zod_1.z.object({
224
234
  .string()
225
235
  .min(2, "Last name must be at least 2 characters")
226
236
  .max(100, "Last name cannot exceed 100 characters"),
227
- phoneNumber: zod_1.z
237
+ contactValue: zod_1.z
228
238
  .string()
229
- .regex(exports.phoneNumberRegex, "Phone number must be a valid Rwandan number (078/079/072/073) followed by 7 digits"),
239
+ .min(1, "Email or phone number is required")
240
+ .refine((val) => (0, exports.validateContactValue)(val), {
241
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
242
+ }),
230
243
  jacketId: zod_1.z
231
244
  .string()
232
245
  .regex(exports.jacketIdRegex, "Jacket ID must be in format JKT-000000000")
233
246
  .optional(),
234
- email: zod_1.z
235
- .string()
236
- .email("Invalid email address")
237
- .optional()
238
- .nullable()
239
- .or(zod_1.z.literal("")),
240
247
  password: zod_1.z
241
248
  .string()
242
- .min(6, "Password must be at least 6 characters")
243
- .max(100, "Password cannot exceed 100 characters")
249
+ .regex(exports.strongPasswordRegex, "Password must be at least 8 characters, include 1 uppercase letter, 1 number and 1 symbol")
244
250
  .optional()
245
251
  .nullable(),
246
252
  plateNumber: zod_1.z
247
253
  .string()
254
+ .regex(plateRegex, "Invalid plate number format")
248
255
  .max(20, "Plate number cannot exceed 20 characters")
249
256
  .optional()
250
257
  .nullable(),
@@ -280,6 +287,12 @@ exports.updatePassengerProfileSchema = zod_1.z.object({
280
287
  .min(2, "Last name must be at least 2 characters")
281
288
  .max(100, "Last name cannot exceed 100 characters")
282
289
  .optional(),
290
+ contactValue: zod_1.z
291
+ .string()
292
+ .refine((val) => (0, exports.validateContactValue)(val), {
293
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
294
+ })
295
+ .optional(),
283
296
  gender: zod_1.z.enum(["male", "female"]).optional(),
284
297
  birthDate: zod_1.z.number().min(1).max(31).optional(),
285
298
  birthMonth: zod_1.z.number().min(1).max(12).optional(),
@@ -327,11 +340,15 @@ exports.createRiderSchema = zod_1.z.object({
327
340
  .string()
328
341
  .min(2, "Last name must be at least 2 characters")
329
342
  .max(100, "Last name cannot exceed 100 characters"),
330
- phoneNumber: zod_1.z
343
+ contactValue: zod_1.z
331
344
  .string()
332
- .regex(exports.phoneNumberRegex, "Phone number must be a valid Rwandan number (078/079/072/073) followed by 7 digits"),
345
+ .min(1, "Email or phone number is required")
346
+ .refine((val) => (0, exports.validateContactValue)(val), {
347
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
348
+ }),
333
349
  plateNumber: zod_1.z
334
350
  .string()
351
+ .regex(plateRegex, "Invalid plate number format")
335
352
  .max(20, "Plate number cannot exceed 20 characters"),
336
353
  jacketId: zod_1.z
337
354
  .string()
@@ -371,12 +388,15 @@ exports.updateRiderProfileSchema = zod_1.z.object({
371
388
  .min(2, "Last name must be at least 2 characters")
372
389
  .max(100, "Last name cannot exceed 100 characters")
373
390
  .optional(),
374
- phoneNumber: zod_1.z
391
+ contactValue: zod_1.z
375
392
  .string()
376
- .regex(exports.phoneNumberRegex, "Phone number must be a valid Rwandan number (078/079/072/073) followed by 7 digits")
393
+ .refine((val) => (0, exports.validateContactValue)(val), {
394
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
395
+ })
377
396
  .optional(),
378
397
  plateNumber: zod_1.z
379
398
  .string()
399
+ .regex(plateRegex, "Invalid plate number format")
380
400
  .max(20, "Plate number cannot exceed 20 characters")
381
401
  .optional(),
382
402
  jacketId: zod_1.z
@@ -456,16 +476,18 @@ exports.deleteAccountSchema = zod_1.z.object({
456
476
  }),
457
477
  }),
458
478
  });
479
+ // Update Profile Schema (for users)
459
480
  exports.updateProfileSchema = zod_1.z.object({
460
481
  body: zod_1.z
461
482
  .object({
462
483
  firstName: zod_1.z.string().min(2).max(50).optional(),
463
484
  lastName: zod_1.z.string().min(2).max(50).optional(),
464
- phoneNumber: zod_1.z
485
+ contactValue: zod_1.z
465
486
  .string()
466
- .regex(phoneRegex, "Invalid phone number")
487
+ .refine((val) => (0, exports.validateContactValue)(val), {
488
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
489
+ })
467
490
  .optional(),
468
- email: zod_1.z.string().email("Invalid email").optional(),
469
491
  gender: zod_1.z.enum(["male", "female"]).optional(),
470
492
  birthDate: zod_1.z.number().min(1).max(31).optional(),
471
493
  birthMonth: zod_1.z.number().min(1).max(12).optional(),
@@ -492,3 +514,70 @@ exports.updateProfileSchema = zod_1.z.object({
492
514
  path: ["birthDate"],
493
515
  }),
494
516
  });
517
+ // ============================================================================
518
+ // CONTACT MANAGEMENT SCHEMAS
519
+ // ============================================================================
520
+ // Add Contact Schema
521
+ exports.addContactSchema = zod_1.z.object({
522
+ body: zod_1.z.object({
523
+ contactValue: zod_1.z
524
+ .string()
525
+ .min(1, "Email or phone number is required")
526
+ .refine((val) => (0, exports.validateContactValue)(val), {
527
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
528
+ }),
529
+ type: zod_1.z.enum(["EMAIL", "PHONE", "WHATSAPP"]).optional(),
530
+ }),
531
+ headers: zod_1.z.object({
532
+ authorization: zod_1.z.string().regex(/^Bearer /, {
533
+ message: "Authorization header must start with 'Bearer '",
534
+ }),
535
+ }),
536
+ });
537
+ // Verify Contact Schema (send OTP)
538
+ exports.verifyContactSchema = zod_1.z.object({
539
+ params: zod_1.z.object({
540
+ contactId: zod_1.z.string().uuid("Invalid contact ID format"),
541
+ }),
542
+ headers: zod_1.z.object({
543
+ authorization: zod_1.z.string().regex(/^Bearer /, {
544
+ message: "Authorization header must start with 'Bearer '",
545
+ }),
546
+ }),
547
+ });
548
+ // Confirm Verification Schema
549
+ exports.confirmVerificationSchema = zod_1.z.object({
550
+ body: zod_1.z.object({
551
+ otp: zod_1.z.string().length(6, "OTP must be 6 digits"),
552
+ }),
553
+ params: zod_1.z.object({
554
+ contactId: zod_1.z.string().uuid("Invalid contact ID format"),
555
+ }),
556
+ headers: zod_1.z.object({
557
+ authorization: zod_1.z.string().regex(/^Bearer /, {
558
+ message: "Authorization header must start with 'Bearer '",
559
+ }),
560
+ }),
561
+ });
562
+ // Delete Contact Schema
563
+ exports.deleteContactSchema = zod_1.z.object({
564
+ params: zod_1.z.object({
565
+ contactId: zod_1.z.string().uuid("Invalid contact ID format"),
566
+ }),
567
+ headers: zod_1.z.object({
568
+ authorization: zod_1.z.string().regex(/^Bearer /, {
569
+ message: "Authorization header must start with 'Bearer '",
570
+ }),
571
+ }),
572
+ });
573
+ // Set Primary Contact Schema
574
+ exports.setPrimaryContactSchema = zod_1.z.object({
575
+ params: zod_1.z.object({
576
+ contactId: zod_1.z.string().uuid("Invalid contact ID format"),
577
+ }),
578
+ headers: zod_1.z.object({
579
+ authorization: zod_1.z.string().regex(/^Bearer /, {
580
+ message: "Authorization header must start with 'Bearer '",
581
+ }),
582
+ }),
583
+ });