vr-commons 1.0.113 → 1.0.114

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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resetPasswordSchema = exports.updateAdminSchema = exports.fireEmployeeSchema = exports.demoteAdminSchema = exports.promoteAdminSchema = exports.hireAdminSchema = exports.getUsersSchema = exports.getUserSchema = exports.deleteUserSchema = exports.updateRiderSchema = exports.upgradeToRiderSchema = void 0;
3
+ exports.setUserPrimaryContactSchema = exports.deleteUserContactSchema = exports.verifyUserContactSchema = exports.addUserContactSchema = exports.bulkResetPasswordsSchema = exports.resetPasswordSchema = exports.updateAdminSchema = exports.fireEmployeeSchema = exports.demoteAdminSchema = exports.promoteAdminSchema = exports.hireAdminSchema = exports.getUsersSchema = exports.getUserSchema = exports.deleteUserSchema = exports.updateRiderSchema = exports.upgradeToRiderSchema = void 0;
4
4
  // src/validations/users.validations.ts
5
5
  const zod_1 = require("zod");
6
6
  const auth_validations_1 = require("./auth.validations");
@@ -10,15 +10,23 @@ const isValidBirthDate = (date, month, year) => {
10
10
  const maxDays = new Date(year, month, 0).getDate();
11
11
  return date >= 1 && date <= maxDays;
12
12
  };
13
- // Operations Schemas
13
+ // ============================================================================
14
+ // OPERATIONS SCHEMAS
15
+ // ============================================================================
16
+ // Upgrade Passenger to Rider
14
17
  exports.upgradeToRiderSchema = zod_1.z.object({
15
18
  params: zod_1.z.object({
16
19
  userId: zod_1.z.string().uuid("Invalid user ID format"),
17
20
  }),
18
21
  body: zod_1.z
19
22
  .object({
20
- jacketId: zod_1.z.string().regex(profiles_validations_1.jacketIdRegex, "invalid jacket id"),
21
- phoneNumber: zod_1.z.string().regex(auth_validations_1.phoneRegex, "Invalid phone number format"),
23
+ jacketId: zod_1.z.string().regex(profiles_validations_1.jacketIdRegex, "Invalid jacket ID format"),
24
+ contactValue: zod_1.z
25
+ .string()
26
+ .min(1, "Email or phone number is required")
27
+ .refine((val) => (0, auth_validations_1.validateContactValue)(val), {
28
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
29
+ }),
22
30
  plateNumber: zod_1.z.string().min(3).max(10).optional(),
23
31
  gender: zod_1.z.enum(["male", "female"], {
24
32
  errorMap: () => ({
@@ -36,6 +44,7 @@ exports.upgradeToRiderSchema = zod_1.z.object({
36
44
  path: ["birthDate"],
37
45
  }),
38
46
  });
47
+ // Update Rider
39
48
  exports.updateRiderSchema = zod_1.z.object({
40
49
  params: zod_1.z.object({
41
50
  userId: zod_1.z.string().uuid("Invalid user ID format"),
@@ -44,10 +53,17 @@ exports.updateRiderSchema = zod_1.z.object({
44
53
  .object({
45
54
  firstName: zod_1.z.string().min(2).max(100).optional(),
46
55
  lastName: zod_1.z.string().min(2).max(100).optional(),
47
- phoneNumber: zod_1.z.string().regex(auth_validations_1.phoneRegex).optional(),
48
- jacketId: zod_1.z.string().min(5).max(20).optional(),
56
+ contactValue: zod_1.z
57
+ .string()
58
+ .refine((val) => (0, auth_validations_1.validateContactValue)(val), {
59
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
60
+ })
61
+ .optional(),
62
+ jacketId: zod_1.z
63
+ .string()
64
+ .regex(profiles_validations_1.jacketIdRegex, "Invalid jacket ID format")
65
+ .optional(),
49
66
  plateNumber: zod_1.z.string().min(3).max(10).optional(),
50
- email: zod_1.z.string().email().optional(),
51
67
  gender: zod_1.z.enum(["male", "female"]).optional(),
52
68
  birthDate: zod_1.z.number().min(1).max(31).optional(),
53
69
  birthMonth: zod_1.z.number().min(1).max(12).optional(),
@@ -73,16 +89,19 @@ exports.updateRiderSchema = zod_1.z.object({
73
89
  path: ["birthDate"],
74
90
  }),
75
91
  });
92
+ // Delete User (Permanent)
76
93
  exports.deleteUserSchema = zod_1.z.object({
77
94
  params: zod_1.z.object({
78
95
  userId: zod_1.z.string().uuid("Invalid user ID format"),
79
96
  }),
80
97
  });
98
+ // Get Single User
81
99
  exports.getUserSchema = zod_1.z.object({
82
100
  params: zod_1.z.object({
83
101
  userId: zod_1.z.string().uuid("Invalid user ID format"),
84
102
  }),
85
103
  });
104
+ // Get All Users (with pagination)
86
105
  exports.getUsersSchema = zod_1.z.object({
87
106
  query: zod_1.z.object({
88
107
  page: zod_1.z.string().regex(/^\d+$/).transform(Number).optional(),
@@ -92,19 +111,29 @@ exports.getUsersSchema = zod_1.z.object({
92
111
  isDeactivated: zod_1.z.enum(["true", "false"]).optional(),
93
112
  role: zod_1.z.string().optional(),
94
113
  gender: zod_1.z.enum(["male", "female"]).optional(),
114
+ contactType: zod_1.z.enum(["EMAIL", "PHONE", "WHATSAPP"]).optional(),
95
115
  sortBy: zod_1.z.enum(["createdAt", "firstName", "lastName", "gender"]).optional(),
96
116
  sortOrder: zod_1.z.enum(["ASC", "DESC"]).optional(),
97
117
  }),
98
118
  });
99
- // Management Schemas
119
+ // ============================================================================
120
+ // MANAGEMENT SCHEMAS
121
+ // ============================================================================
122
+ // Hire Admin (Agent, Admin, Super Admin)
100
123
  exports.hireAdminSchema = zod_1.z.object({
101
124
  body: zod_1.z
102
125
  .object({
103
- email: zod_1.z.string().email(),
126
+ contactValue: zod_1.z
127
+ .string()
128
+ .min(1, "Email or phone number is required")
129
+ .refine((val) => (0, auth_validations_1.validateContactValue)(val), {
130
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
131
+ }),
104
132
  firstName: zod_1.z.string().min(2).max(100),
105
133
  lastName: zod_1.z.string().min(2).max(100),
106
- phoneNumber: zod_1.z.string().regex(auth_validations_1.phoneRegex),
107
- password: zod_1.z.string().min(6),
134
+ password: zod_1.z
135
+ .string()
136
+ .regex(auth_validations_1.strongPasswordRegex, "Password must be at least 8 characters, include 1 uppercase letter, 1 number and 1 symbol"),
108
137
  role: zod_1.z.enum(["AGENT", "ADMIN", "SUPER_ADMIN"]),
109
138
  superAdminPassword: zod_1.z.string().optional(),
110
139
  gender: zod_1.z.enum(["male", "female"], {
@@ -133,6 +162,7 @@ exports.hireAdminSchema = zod_1.z.object({
133
162
  path: ["birthDate"],
134
163
  }),
135
164
  });
165
+ // Promote Admin
136
166
  exports.promoteAdminSchema = zod_1.z.object({
137
167
  params: zod_1.z.object({
138
168
  userId: zod_1.z.string().uuid("Invalid user ID format"),
@@ -142,6 +172,7 @@ exports.promoteAdminSchema = zod_1.z.object({
142
172
  password: zod_1.z.string().optional(),
143
173
  }),
144
174
  });
175
+ // Demote Admin
145
176
  exports.demoteAdminSchema = zod_1.z.object({
146
177
  params: zod_1.z.object({
147
178
  userId: zod_1.z.string().uuid("Invalid user ID format"),
@@ -150,14 +181,16 @@ exports.demoteAdminSchema = zod_1.z.object({
150
181
  targetRole: zod_1.z.enum(["AGENT", "ADMIN"]),
151
182
  }),
152
183
  });
184
+ // Fire Employee
153
185
  exports.fireEmployeeSchema = zod_1.z.object({
154
186
  params: zod_1.z.object({
155
187
  userId: zod_1.z.string().uuid("Invalid user ID format"),
156
188
  }),
157
189
  body: zod_1.z.object({
158
- reason: zod_1.z.string().min(1).optional(),
190
+ reason: zod_1.z.string().min(1, "Reason is required").optional(),
159
191
  }),
160
192
  });
193
+ // Update Admin
161
194
  exports.updateAdminSchema = zod_1.z.object({
162
195
  params: zod_1.z.object({
163
196
  userId: zod_1.z.string().uuid("Invalid user ID format"),
@@ -166,7 +199,12 @@ exports.updateAdminSchema = zod_1.z.object({
166
199
  .object({
167
200
  firstName: zod_1.z.string().min(2).max(100).optional(),
168
201
  lastName: zod_1.z.string().min(2).max(100).optional(),
169
- email: zod_1.z.string().email().optional(),
202
+ contactValue: zod_1.z
203
+ .string()
204
+ .refine((val) => (0, auth_validations_1.validateContactValue)(val), {
205
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
206
+ })
207
+ .optional(),
170
208
  gender: zod_1.z.enum(["male", "female"]).optional(),
171
209
  birthDate: zod_1.z.number().min(1).max(31).optional(),
172
210
  birthMonth: zod_1.z.number().min(1).max(12).optional(),
@@ -192,8 +230,62 @@ exports.updateAdminSchema = zod_1.z.object({
192
230
  path: ["birthDate"],
193
231
  }),
194
232
  });
233
+ // Reset Password (Admin)
195
234
  exports.resetPasswordSchema = zod_1.z.object({
196
235
  params: zod_1.z.object({
197
236
  userId: zod_1.z.string().uuid("Invalid user ID format"),
198
237
  }),
199
238
  });
239
+ // Bulk Reset Passwords (Super Admin only)
240
+ exports.bulkResetPasswordsSchema = zod_1.z.object({
241
+ body: zod_1.z.object({
242
+ userIds: zod_1.z.array(zod_1.z.string().uuid("Invalid user ID format")).optional(),
243
+ allUsers: zod_1.z.boolean().optional(),
244
+ }),
245
+ headers: zod_1.z.object({
246
+ authorization: zod_1.z.string().regex(/^Bearer /, {
247
+ message: "Authorization header must start with 'Bearer '",
248
+ }),
249
+ }),
250
+ });
251
+ // ============================================================================
252
+ // CONTACT MANAGEMENT SCHEMAS
253
+ // ============================================================================
254
+ // Add Contact to User (Admin)
255
+ exports.addUserContactSchema = zod_1.z.object({
256
+ params: zod_1.z.object({
257
+ userId: zod_1.z.string().uuid("Invalid user ID format"),
258
+ }),
259
+ body: zod_1.z.object({
260
+ contactValue: zod_1.z
261
+ .string()
262
+ .min(1, "Email or phone number is required")
263
+ .refine((val) => (0, auth_validations_1.validateContactValue)(val), {
264
+ message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
265
+ }),
266
+ type: zod_1.z.enum(["EMAIL", "PHONE", "WHATSAPP"]).optional(),
267
+ isVerified: zod_1.z.boolean().default(false).optional(),
268
+ isPrimary: zod_1.z.boolean().default(false).optional(),
269
+ }),
270
+ });
271
+ // Verify User Contact (Admin)
272
+ exports.verifyUserContactSchema = zod_1.z.object({
273
+ params: zod_1.z.object({
274
+ userId: zod_1.z.string().uuid("Invalid user ID format"),
275
+ contactId: zod_1.z.string().uuid("Invalid contact ID format"),
276
+ }),
277
+ });
278
+ // Delete User Contact (Admin)
279
+ exports.deleteUserContactSchema = zod_1.z.object({
280
+ params: zod_1.z.object({
281
+ userId: zod_1.z.string().uuid("Invalid user ID format"),
282
+ contactId: zod_1.z.string().uuid("Invalid contact ID format"),
283
+ }),
284
+ });
285
+ // Set Primary Contact (Admin)
286
+ exports.setUserPrimaryContactSchema = zod_1.z.object({
287
+ params: zod_1.z.object({
288
+ userId: zod_1.z.string().uuid("Invalid user ID format"),
289
+ contactId: zod_1.z.string().uuid("Invalid contact ID format"),
290
+ }),
291
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-commons",
3
- "version": "1.0.113",
3
+ "version": "1.0.114",
4
4
  "description": "Shared functions package",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",