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.
- package/dist/middlewares/auth.users.middlewares.js +2 -2
- package/dist/validations/account.validations.d.ts +231 -0
- package/dist/validations/account.validations.js +136 -3
- package/dist/validations/auth.validations.d.ts +191 -49
- package/dist/validations/auth.validations.js +133 -18
- package/dist/validations/profiles.validations.d.ts +271 -123
- package/dist/validations/profiles.validations.js +135 -46
- package/dist/validations/users.admin.validations.d.ts +223 -72
- package/dist/validations/users.admin.validations.js +105 -13
- package/package.json +1 -1
|
@@ -1,43 +1,47 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const phoneRegex: RegExp;
|
|
3
|
+
export declare const emailRegex: RegExp;
|
|
3
4
|
export declare const passwordRegex: RegExp;
|
|
5
|
+
export declare const strongPasswordRegex: RegExp;
|
|
6
|
+
export declare const detectContactType: (value: string) => "EMAIL" | "PHONE" | "WHATSAPP" | "UNKNOWN";
|
|
7
|
+
export declare const validateContactValue: (value: string) => boolean;
|
|
4
8
|
export declare const userLoginSchema: z.ZodObject<{
|
|
5
9
|
body: z.ZodObject<{
|
|
6
|
-
|
|
10
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
7
11
|
password: z.ZodString;
|
|
8
12
|
}, "strip", z.ZodTypeAny, {
|
|
9
13
|
password: string;
|
|
10
|
-
|
|
14
|
+
contactValue: string;
|
|
11
15
|
}, {
|
|
12
16
|
password: string;
|
|
13
|
-
|
|
17
|
+
contactValue: string;
|
|
14
18
|
}>;
|
|
15
19
|
}, "strip", z.ZodTypeAny, {
|
|
16
20
|
body: {
|
|
17
21
|
password: string;
|
|
18
|
-
|
|
22
|
+
contactValue: string;
|
|
19
23
|
};
|
|
20
24
|
}, {
|
|
21
25
|
body: {
|
|
22
26
|
password: string;
|
|
23
|
-
|
|
27
|
+
contactValue: string;
|
|
24
28
|
};
|
|
25
29
|
}>;
|
|
26
30
|
export declare const forgotPasswordSchema: z.ZodObject<{
|
|
27
31
|
body: z.ZodObject<{
|
|
28
|
-
|
|
32
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
29
33
|
}, "strip", z.ZodTypeAny, {
|
|
30
|
-
|
|
34
|
+
contactValue: string;
|
|
31
35
|
}, {
|
|
32
|
-
|
|
36
|
+
contactValue: string;
|
|
33
37
|
}>;
|
|
34
38
|
}, "strip", z.ZodTypeAny, {
|
|
35
39
|
body: {
|
|
36
|
-
|
|
40
|
+
contactValue: string;
|
|
37
41
|
};
|
|
38
42
|
}, {
|
|
39
43
|
body: {
|
|
40
|
-
|
|
44
|
+
contactValue: string;
|
|
41
45
|
};
|
|
42
46
|
}>;
|
|
43
47
|
export declare const changePasswordSchema: z.ZodObject<{
|
|
@@ -83,143 +87,281 @@ export declare const registerSchema: z.ZodObject<{
|
|
|
83
87
|
body: z.ZodObject<{
|
|
84
88
|
firstName: z.ZodString;
|
|
85
89
|
lastName: z.ZodString;
|
|
86
|
-
|
|
87
|
-
email: z.ZodOptional<z.ZodString>;
|
|
90
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
88
91
|
password: z.ZodString;
|
|
92
|
+
role: z.ZodDefault<z.ZodOptional<z.ZodEnum<["PASSENGER", "RIDER"]>>>;
|
|
93
|
+
gender: z.ZodOptional<z.ZodEnum<["male", "female"]>>;
|
|
94
|
+
birthDate: z.ZodOptional<z.ZodNumber>;
|
|
95
|
+
birthMonth: z.ZodOptional<z.ZodNumber>;
|
|
96
|
+
birthYear: z.ZodOptional<z.ZodNumber>;
|
|
89
97
|
}, "strict", z.ZodTypeAny, {
|
|
90
98
|
firstName: string;
|
|
91
99
|
lastName: string;
|
|
92
100
|
password: string;
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
role: "RIDER" | "PASSENGER";
|
|
102
|
+
contactValue: string;
|
|
103
|
+
gender?: "male" | "female" | undefined;
|
|
104
|
+
birthDate?: number | undefined;
|
|
105
|
+
birthMonth?: number | undefined;
|
|
106
|
+
birthYear?: number | undefined;
|
|
95
107
|
}, {
|
|
96
108
|
firstName: string;
|
|
97
109
|
lastName: string;
|
|
98
110
|
password: string;
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
contactValue: string;
|
|
112
|
+
gender?: "male" | "female" | undefined;
|
|
113
|
+
birthDate?: number | undefined;
|
|
114
|
+
birthMonth?: number | undefined;
|
|
115
|
+
birthYear?: number | undefined;
|
|
116
|
+
role?: "RIDER" | "PASSENGER" | undefined;
|
|
101
117
|
}>;
|
|
102
118
|
}, "strip", z.ZodTypeAny, {
|
|
103
119
|
body: {
|
|
104
120
|
firstName: string;
|
|
105
121
|
lastName: string;
|
|
106
122
|
password: string;
|
|
107
|
-
|
|
108
|
-
|
|
123
|
+
role: "RIDER" | "PASSENGER";
|
|
124
|
+
contactValue: string;
|
|
125
|
+
gender?: "male" | "female" | undefined;
|
|
126
|
+
birthDate?: number | undefined;
|
|
127
|
+
birthMonth?: number | undefined;
|
|
128
|
+
birthYear?: number | undefined;
|
|
109
129
|
};
|
|
110
130
|
}, {
|
|
111
131
|
body: {
|
|
112
132
|
firstName: string;
|
|
113
133
|
lastName: string;
|
|
114
134
|
password: string;
|
|
115
|
-
|
|
116
|
-
|
|
135
|
+
contactValue: string;
|
|
136
|
+
gender?: "male" | "female" | undefined;
|
|
137
|
+
birthDate?: number | undefined;
|
|
138
|
+
birthMonth?: number | undefined;
|
|
139
|
+
birthYear?: number | undefined;
|
|
140
|
+
role?: "RIDER" | "PASSENGER" | undefined;
|
|
117
141
|
};
|
|
118
142
|
}>;
|
|
119
143
|
export declare const riderLoginSchema: z.ZodObject<{
|
|
120
144
|
body: z.ZodObject<{
|
|
121
|
-
|
|
122
|
-
|
|
145
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
146
|
+
password: z.ZodString;
|
|
123
147
|
}, "strip", z.ZodTypeAny, {
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
password: string;
|
|
149
|
+
contactValue: string;
|
|
126
150
|
}, {
|
|
127
|
-
|
|
128
|
-
|
|
151
|
+
password: string;
|
|
152
|
+
contactValue: string;
|
|
129
153
|
}>;
|
|
130
154
|
query: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
131
155
|
params: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
132
156
|
headers: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
133
157
|
}, "strip", z.ZodTypeAny, {
|
|
134
158
|
body: {
|
|
135
|
-
|
|
136
|
-
|
|
159
|
+
password: string;
|
|
160
|
+
contactValue: string;
|
|
137
161
|
};
|
|
138
|
-
query?: {} | undefined;
|
|
139
162
|
params?: {} | undefined;
|
|
163
|
+
query?: {} | undefined;
|
|
140
164
|
headers?: {} | undefined;
|
|
141
165
|
}, {
|
|
142
166
|
body: {
|
|
143
|
-
|
|
144
|
-
|
|
167
|
+
password: string;
|
|
168
|
+
contactValue: string;
|
|
145
169
|
};
|
|
146
|
-
query?: {} | undefined;
|
|
147
170
|
params?: {} | undefined;
|
|
171
|
+
query?: {} | undefined;
|
|
148
172
|
headers?: {} | undefined;
|
|
149
173
|
}>;
|
|
150
174
|
export declare const requestOtpSchema: z.ZodObject<{
|
|
151
175
|
body: z.ZodObject<{
|
|
152
|
-
|
|
176
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
153
177
|
}, "strip", z.ZodTypeAny, {
|
|
154
|
-
|
|
178
|
+
contactValue: string;
|
|
155
179
|
}, {
|
|
156
|
-
|
|
180
|
+
contactValue: string;
|
|
157
181
|
}>;
|
|
158
182
|
}, "strip", z.ZodTypeAny, {
|
|
159
183
|
body: {
|
|
160
|
-
|
|
184
|
+
contactValue: string;
|
|
161
185
|
};
|
|
162
186
|
}, {
|
|
163
187
|
body: {
|
|
164
|
-
|
|
188
|
+
contactValue: string;
|
|
165
189
|
};
|
|
166
190
|
}>;
|
|
167
191
|
export declare const verifyOtpSchema: z.ZodObject<{
|
|
168
192
|
body: z.ZodEffects<z.ZodObject<{
|
|
169
|
-
|
|
193
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
170
194
|
otp: z.ZodString;
|
|
171
195
|
firstName: z.ZodOptional<z.ZodString>;
|
|
172
196
|
lastName: z.ZodOptional<z.ZodString>;
|
|
173
197
|
}, "strip", z.ZodTypeAny, {
|
|
198
|
+
contactValue: string;
|
|
174
199
|
otp: string;
|
|
175
|
-
phoneNumber: string;
|
|
176
200
|
firstName?: string | undefined;
|
|
177
201
|
lastName?: string | undefined;
|
|
178
202
|
}, {
|
|
203
|
+
contactValue: string;
|
|
179
204
|
otp: string;
|
|
180
|
-
phoneNumber: string;
|
|
181
205
|
firstName?: string | undefined;
|
|
182
206
|
lastName?: string | undefined;
|
|
183
207
|
}>, {
|
|
208
|
+
contactValue: string;
|
|
184
209
|
otp: string;
|
|
185
|
-
phoneNumber: string;
|
|
186
210
|
firstName?: string | undefined;
|
|
187
211
|
lastName?: string | undefined;
|
|
188
212
|
}, {
|
|
213
|
+
contactValue: string;
|
|
189
214
|
otp: string;
|
|
190
|
-
phoneNumber: string;
|
|
191
215
|
firstName?: string | undefined;
|
|
192
216
|
lastName?: string | undefined;
|
|
193
217
|
}>;
|
|
194
218
|
}, "strip", z.ZodTypeAny, {
|
|
195
219
|
body: {
|
|
220
|
+
contactValue: string;
|
|
196
221
|
otp: string;
|
|
197
|
-
phoneNumber: string;
|
|
198
222
|
firstName?: string | undefined;
|
|
199
223
|
lastName?: string | undefined;
|
|
200
224
|
};
|
|
201
225
|
}, {
|
|
202
226
|
body: {
|
|
227
|
+
contactValue: string;
|
|
203
228
|
otp: string;
|
|
204
|
-
phoneNumber: string;
|
|
205
229
|
firstName?: string | undefined;
|
|
206
230
|
lastName?: string | undefined;
|
|
207
231
|
};
|
|
208
232
|
}>;
|
|
209
233
|
export declare const resendOtpSchema: z.ZodObject<{
|
|
210
234
|
body: z.ZodObject<{
|
|
211
|
-
|
|
235
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
236
|
+
}, "strip", z.ZodTypeAny, {
|
|
237
|
+
contactValue: string;
|
|
238
|
+
}, {
|
|
239
|
+
contactValue: string;
|
|
240
|
+
}>;
|
|
241
|
+
}, "strip", z.ZodTypeAny, {
|
|
242
|
+
body: {
|
|
243
|
+
contactValue: string;
|
|
244
|
+
};
|
|
245
|
+
}, {
|
|
246
|
+
body: {
|
|
247
|
+
contactValue: string;
|
|
248
|
+
};
|
|
249
|
+
}>;
|
|
250
|
+
export declare const createUserSchema: z.ZodObject<{
|
|
251
|
+
body: z.ZodObject<{
|
|
252
|
+
firstName: z.ZodString;
|
|
253
|
+
lastName: z.ZodString;
|
|
254
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
255
|
+
password: z.ZodString;
|
|
256
|
+
role: z.ZodEnum<["PASSENGER", "RIDER", "AGENT", "ADMIN", "SUPER_ADMIN"]>;
|
|
257
|
+
gender: z.ZodOptional<z.ZodEnum<["male", "female"]>>;
|
|
258
|
+
birthDate: z.ZodOptional<z.ZodNumber>;
|
|
259
|
+
birthMonth: z.ZodOptional<z.ZodNumber>;
|
|
260
|
+
birthYear: z.ZodOptional<z.ZodNumber>;
|
|
261
|
+
jacketId: z.ZodOptional<z.ZodString>;
|
|
262
|
+
plateNumber: z.ZodOptional<z.ZodString>;
|
|
263
|
+
}, "strip", z.ZodTypeAny, {
|
|
264
|
+
firstName: string;
|
|
265
|
+
lastName: string;
|
|
266
|
+
password: string;
|
|
267
|
+
role: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN";
|
|
268
|
+
contactValue: string;
|
|
269
|
+
jacketId?: string | undefined;
|
|
270
|
+
plateNumber?: string | undefined;
|
|
271
|
+
gender?: "male" | "female" | undefined;
|
|
272
|
+
birthDate?: number | undefined;
|
|
273
|
+
birthMonth?: number | undefined;
|
|
274
|
+
birthYear?: number | undefined;
|
|
275
|
+
}, {
|
|
276
|
+
firstName: string;
|
|
277
|
+
lastName: string;
|
|
278
|
+
password: string;
|
|
279
|
+
role: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN";
|
|
280
|
+
contactValue: string;
|
|
281
|
+
jacketId?: string | undefined;
|
|
282
|
+
plateNumber?: string | undefined;
|
|
283
|
+
gender?: "male" | "female" | undefined;
|
|
284
|
+
birthDate?: number | undefined;
|
|
285
|
+
birthMonth?: number | undefined;
|
|
286
|
+
birthYear?: number | undefined;
|
|
287
|
+
}>;
|
|
288
|
+
}, "strip", z.ZodTypeAny, {
|
|
289
|
+
body: {
|
|
290
|
+
firstName: string;
|
|
291
|
+
lastName: string;
|
|
292
|
+
password: string;
|
|
293
|
+
role: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN";
|
|
294
|
+
contactValue: string;
|
|
295
|
+
jacketId?: string | undefined;
|
|
296
|
+
plateNumber?: string | undefined;
|
|
297
|
+
gender?: "male" | "female" | undefined;
|
|
298
|
+
birthDate?: number | undefined;
|
|
299
|
+
birthMonth?: number | undefined;
|
|
300
|
+
birthYear?: number | undefined;
|
|
301
|
+
};
|
|
302
|
+
}, {
|
|
303
|
+
body: {
|
|
304
|
+
firstName: string;
|
|
305
|
+
lastName: string;
|
|
306
|
+
password: string;
|
|
307
|
+
role: "RIDER" | "PASSENGER" | "ADMIN" | "AGENT" | "SUPER_ADMIN";
|
|
308
|
+
contactValue: string;
|
|
309
|
+
jacketId?: string | undefined;
|
|
310
|
+
plateNumber?: string | undefined;
|
|
311
|
+
gender?: "male" | "female" | undefined;
|
|
312
|
+
birthDate?: number | undefined;
|
|
313
|
+
birthMonth?: number | undefined;
|
|
314
|
+
birthYear?: number | undefined;
|
|
315
|
+
};
|
|
316
|
+
}>;
|
|
317
|
+
export declare const updateContactSchema: z.ZodObject<{
|
|
318
|
+
body: z.ZodObject<{
|
|
319
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
320
|
+
}, "strip", z.ZodTypeAny, {
|
|
321
|
+
contactValue: string;
|
|
322
|
+
}, {
|
|
323
|
+
contactValue: string;
|
|
324
|
+
}>;
|
|
325
|
+
}, "strip", z.ZodTypeAny, {
|
|
326
|
+
body: {
|
|
327
|
+
contactValue: string;
|
|
328
|
+
};
|
|
329
|
+
}, {
|
|
330
|
+
body: {
|
|
331
|
+
contactValue: string;
|
|
332
|
+
};
|
|
333
|
+
}>;
|
|
334
|
+
export declare const addContactSchema: z.ZodObject<{
|
|
335
|
+
body: z.ZodObject<{
|
|
336
|
+
contactValue: z.ZodEffects<z.ZodString, string, string>;
|
|
337
|
+
type: z.ZodOptional<z.ZodEnum<["EMAIL", "PHONE", "WHATSAPP"]>>;
|
|
212
338
|
}, "strip", z.ZodTypeAny, {
|
|
213
|
-
|
|
339
|
+
contactValue: string;
|
|
340
|
+
type?: "EMAIL" | "PHONE" | "WHATSAPP" | undefined;
|
|
214
341
|
}, {
|
|
215
|
-
|
|
342
|
+
contactValue: string;
|
|
343
|
+
type?: "EMAIL" | "PHONE" | "WHATSAPP" | undefined;
|
|
216
344
|
}>;
|
|
217
345
|
}, "strip", z.ZodTypeAny, {
|
|
218
346
|
body: {
|
|
219
|
-
|
|
347
|
+
contactValue: string;
|
|
348
|
+
type?: "EMAIL" | "PHONE" | "WHATSAPP" | undefined;
|
|
220
349
|
};
|
|
221
350
|
}, {
|
|
222
351
|
body: {
|
|
223
|
-
|
|
352
|
+
contactValue: string;
|
|
353
|
+
type?: "EMAIL" | "PHONE" | "WHATSAPP" | undefined;
|
|
224
354
|
};
|
|
225
355
|
}>;
|
|
356
|
+
export type UserLoginSchema = z.infer<typeof userLoginSchema>;
|
|
357
|
+
export type ForgotPasswordSchema = z.infer<typeof forgotPasswordSchema>;
|
|
358
|
+
export type ChangePasswordSchema = z.infer<typeof changePasswordSchema>;
|
|
359
|
+
export type RefreshTokenSchema = z.infer<typeof refreshTokenSchema>;
|
|
360
|
+
export type RegisterSchema = z.infer<typeof registerSchema>;
|
|
361
|
+
export type RiderLoginSchema = z.infer<typeof riderLoginSchema>;
|
|
362
|
+
export type RequestOtpSchema = z.infer<typeof requestOtpSchema>;
|
|
363
|
+
export type VerifyOtpSchema = z.infer<typeof verifyOtpSchema>;
|
|
364
|
+
export type ResendOtpSchema = z.infer<typeof resendOtpSchema>;
|
|
365
|
+
export type CreateUserSchema = z.infer<typeof createUserSchema>;
|
|
366
|
+
export type UpdateContactSchema = z.infer<typeof updateContactSchema>;
|
|
367
|
+
export type AddContactSchema = z.infer<typeof addContactSchema>;
|
|
@@ -1,35 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resendOtpSchema = exports.verifyOtpSchema = exports.requestOtpSchema = exports.riderLoginSchema = exports.registerSchema = exports.refreshTokenSchema = exports.changePasswordSchema = exports.forgotPasswordSchema = exports.userLoginSchema = exports.passwordRegex = exports.phoneRegex = void 0;
|
|
3
|
+
exports.addContactSchema = exports.updateContactSchema = exports.createUserSchema = exports.resendOtpSchema = exports.verifyOtpSchema = exports.requestOtpSchema = exports.riderLoginSchema = exports.registerSchema = exports.refreshTokenSchema = exports.changePasswordSchema = exports.forgotPasswordSchema = exports.userLoginSchema = exports.validateContactValue = exports.detectContactType = exports.strongPasswordRegex = exports.passwordRegex = exports.emailRegex = exports.phoneRegex = void 0;
|
|
4
4
|
// src/validations/auth.schema.ts
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
|
+
// ==================== REGEX PATTERNS ====================
|
|
6
7
|
exports.phoneRegex = /^\+250(78|79|73|72)[0-9]{7}$/;
|
|
8
|
+
exports.emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
7
9
|
exports.passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{6,}$/;
|
|
10
|
+
exports.strongPasswordRegex = /^(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#^()_\-+=])[A-Za-z\d@$!%*?&#^()_\-+=]{8,}$/;
|
|
11
|
+
// ==================== CONTACT VALIDATION HELPERS ====================
|
|
12
|
+
const detectContactType = (value) => {
|
|
13
|
+
if (!value)
|
|
14
|
+
return "UNKNOWN";
|
|
15
|
+
// Check if it's an email
|
|
16
|
+
if (exports.emailRegex.test(value)) {
|
|
17
|
+
return "EMAIL";
|
|
18
|
+
}
|
|
19
|
+
// Check if it's a phone number
|
|
20
|
+
if (exports.phoneRegex.test(value)) {
|
|
21
|
+
return "PHONE";
|
|
22
|
+
}
|
|
23
|
+
return "UNKNOWN";
|
|
24
|
+
};
|
|
25
|
+
exports.detectContactType = detectContactType;
|
|
26
|
+
const validateContactValue = (value) => {
|
|
27
|
+
return exports.emailRegex.test(value) || exports.phoneRegex.test(value);
|
|
28
|
+
};
|
|
29
|
+
exports.validateContactValue = validateContactValue;
|
|
8
30
|
// ==================== ADMIN AUTH VALIDATIONS ====================
|
|
31
|
+
// Login with contact (email or phone)
|
|
9
32
|
exports.userLoginSchema = zod_1.z.object({
|
|
10
33
|
body: zod_1.z.object({
|
|
11
|
-
|
|
12
|
-
|
|
34
|
+
contactValue: zod_1.z
|
|
35
|
+
.string()
|
|
36
|
+
.min(1, "Email or phone number is required")
|
|
37
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
38
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
39
|
+
}),
|
|
40
|
+
password: zod_1.z.string().min(6, "Password must be at least 6 characters"),
|
|
13
41
|
}),
|
|
14
42
|
});
|
|
43
|
+
// Forgot password with contact (email or phone)
|
|
15
44
|
exports.forgotPasswordSchema = zod_1.z.object({
|
|
16
45
|
body: zod_1.z.object({
|
|
17
|
-
|
|
46
|
+
contactValue: zod_1.z
|
|
47
|
+
.string()
|
|
48
|
+
.min(1, "Email or phone number is required")
|
|
49
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
50
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
51
|
+
}),
|
|
18
52
|
}),
|
|
19
53
|
});
|
|
54
|
+
// Change password (authenticated users)
|
|
20
55
|
exports.changePasswordSchema = zod_1.z.object({
|
|
21
56
|
body: zod_1.z.object({
|
|
22
57
|
oldPassword: zod_1.z.string().min(1, "Old password is required"),
|
|
23
58
|
newPassword: zod_1.z
|
|
24
59
|
.string()
|
|
25
|
-
.regex(exports.
|
|
60
|
+
.regex(exports.strongPasswordRegex, "Password must be at least 8 characters, include 1 uppercase letter, 1 number and 1 symbol"),
|
|
26
61
|
}),
|
|
27
62
|
});
|
|
63
|
+
// Refresh token
|
|
28
64
|
exports.refreshTokenSchema = zod_1.z.object({
|
|
29
65
|
body: zod_1.z.object({
|
|
30
66
|
refreshToken: zod_1.z.string().min(1, "Refresh token is required"),
|
|
31
67
|
}),
|
|
32
68
|
});
|
|
69
|
+
// Register new user (public registration)
|
|
33
70
|
exports.registerSchema = zod_1.z.object({
|
|
34
71
|
body: zod_1.z
|
|
35
72
|
.object({
|
|
@@ -41,39 +78,60 @@ exports.registerSchema = zod_1.z.object({
|
|
|
41
78
|
.string()
|
|
42
79
|
.min(2, "Last name must be at least 2 characters")
|
|
43
80
|
.max(50, "Last name too long"),
|
|
44
|
-
|
|
45
|
-
|
|
81
|
+
contactValue: zod_1.z
|
|
82
|
+
.string()
|
|
83
|
+
.min(1, "Email or phone number is required")
|
|
84
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
85
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
86
|
+
}),
|
|
46
87
|
password: zod_1.z
|
|
47
88
|
.string()
|
|
48
|
-
.regex(exports.
|
|
89
|
+
.regex(exports.strongPasswordRegex, "Password must be at least 8 characters, include 1 uppercase letter, 1 number and 1 symbol"),
|
|
90
|
+
role: zod_1.z.enum(["PASSENGER", "RIDER"]).optional().default("PASSENGER"),
|
|
91
|
+
gender: zod_1.z.enum(["male", "female"]).optional(),
|
|
92
|
+
birthDate: zod_1.z.number().min(1).max(31).optional(),
|
|
93
|
+
birthMonth: zod_1.z.number().min(1).max(12).optional(),
|
|
94
|
+
birthYear: zod_1.z.number().min(1900).max(new Date().getFullYear()).optional(),
|
|
49
95
|
})
|
|
50
96
|
.strict(),
|
|
51
97
|
});
|
|
52
98
|
// ==================== USER (RIDER/PASSENGER) AUTH VALIDATIONS ====================
|
|
99
|
+
// Rider login with contact
|
|
53
100
|
exports.riderLoginSchema = zod_1.z.object({
|
|
54
101
|
body: zod_1.z.object({
|
|
55
|
-
|
|
102
|
+
contactValue: zod_1.z
|
|
56
103
|
.string()
|
|
57
|
-
.
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
104
|
+
.min(1, "Email or phone number is required")
|
|
105
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
106
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
107
|
+
}),
|
|
108
|
+
password: zod_1.z.string().min(6, "Password must be at least 6 characters"),
|
|
61
109
|
}),
|
|
62
110
|
query: zod_1.z.object({}).optional(),
|
|
63
111
|
params: zod_1.z.object({}).optional(),
|
|
64
112
|
headers: zod_1.z.object({}).optional(),
|
|
65
113
|
});
|
|
114
|
+
// Request OTP (for phone verification)
|
|
66
115
|
exports.requestOtpSchema = zod_1.z.object({
|
|
67
116
|
body: zod_1.z.object({
|
|
68
|
-
|
|
117
|
+
contactValue: zod_1.z
|
|
69
118
|
.string()
|
|
70
|
-
.
|
|
119
|
+
.min(1, "Email or phone number is required")
|
|
120
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
121
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
122
|
+
}),
|
|
71
123
|
}),
|
|
72
124
|
});
|
|
125
|
+
// Verify OTP with contact
|
|
73
126
|
exports.verifyOtpSchema = zod_1.z.object({
|
|
74
127
|
body: zod_1.z
|
|
75
128
|
.object({
|
|
76
|
-
|
|
129
|
+
contactValue: zod_1.z
|
|
130
|
+
.string()
|
|
131
|
+
.min(1, "Email or phone number is required")
|
|
132
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
133
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
134
|
+
}),
|
|
77
135
|
otp: zod_1.z.string().length(6, "OTP must be 6 digits"),
|
|
78
136
|
firstName: zod_1.z
|
|
79
137
|
.string()
|
|
@@ -87,14 +145,71 @@ exports.verifyOtpSchema = zod_1.z.object({
|
|
|
87
145
|
.optional(),
|
|
88
146
|
})
|
|
89
147
|
.refine((data) => {
|
|
148
|
+
// If firstName and lastName are provided, they must be valid
|
|
149
|
+
if (data.firstName || data.lastName) {
|
|
150
|
+
return data.firstName && data.lastName;
|
|
151
|
+
}
|
|
90
152
|
return true;
|
|
91
153
|
}, {
|
|
92
|
-
message: "
|
|
154
|
+
message: "Both first name and last name are required for new users",
|
|
93
155
|
path: ["firstName", "lastName"],
|
|
94
156
|
}),
|
|
95
157
|
});
|
|
158
|
+
// Resend OTP
|
|
96
159
|
exports.resendOtpSchema = zod_1.z.object({
|
|
97
160
|
body: zod_1.z.object({
|
|
98
|
-
|
|
161
|
+
contactValue: zod_1.z
|
|
162
|
+
.string()
|
|
163
|
+
.min(1, "Email or phone number is required")
|
|
164
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
165
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
166
|
+
}),
|
|
167
|
+
}),
|
|
168
|
+
});
|
|
169
|
+
// ==================== ADDITIONAL SCHEMAS ====================
|
|
170
|
+
// For administrators to create users
|
|
171
|
+
exports.createUserSchema = zod_1.z.object({
|
|
172
|
+
body: zod_1.z.object({
|
|
173
|
+
firstName: zod_1.z.string().min(2).max(50),
|
|
174
|
+
lastName: zod_1.z.string().min(2).max(50),
|
|
175
|
+
contactValue: zod_1.z
|
|
176
|
+
.string()
|
|
177
|
+
.min(1, "Email or phone number is required")
|
|
178
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
179
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
180
|
+
}),
|
|
181
|
+
password: zod_1.z
|
|
182
|
+
.string()
|
|
183
|
+
.regex(exports.strongPasswordRegex, "Password must be at least 8 characters, include 1 uppercase letter, 1 number and 1 symbol"),
|
|
184
|
+
role: zod_1.z.enum(["PASSENGER", "RIDER", "AGENT", "ADMIN", "SUPER_ADMIN"]),
|
|
185
|
+
gender: zod_1.z.enum(["male", "female"]).optional(),
|
|
186
|
+
birthDate: zod_1.z.number().min(1).max(31).optional(),
|
|
187
|
+
birthMonth: zod_1.z.number().min(1).max(12).optional(),
|
|
188
|
+
birthYear: zod_1.z.number().min(1900).max(new Date().getFullYear()).optional(),
|
|
189
|
+
jacketId: zod_1.z.string().optional(),
|
|
190
|
+
plateNumber: zod_1.z.string().optional(),
|
|
191
|
+
}),
|
|
192
|
+
});
|
|
193
|
+
// For users to update their own contact
|
|
194
|
+
exports.updateContactSchema = zod_1.z.object({
|
|
195
|
+
body: zod_1.z.object({
|
|
196
|
+
contactValue: zod_1.z
|
|
197
|
+
.string()
|
|
198
|
+
.min(1, "Email or phone number is required")
|
|
199
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
200
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
201
|
+
}),
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
// For users to add a new contact
|
|
205
|
+
exports.addContactSchema = zod_1.z.object({
|
|
206
|
+
body: zod_1.z.object({
|
|
207
|
+
contactValue: zod_1.z
|
|
208
|
+
.string()
|
|
209
|
+
.min(1, "Email or phone number is required")
|
|
210
|
+
.refine((val) => (0, exports.validateContactValue)(val), {
|
|
211
|
+
message: "Invalid contact value. Must be a valid email or Rwandan phone number (+250...)",
|
|
212
|
+
}),
|
|
213
|
+
type: zod_1.z.enum(["EMAIL", "PHONE", "WHATSAPP"]).optional(),
|
|
99
214
|
}),
|
|
100
215
|
});
|