@battle-racing/br-common-lib 4.3.0 → 4.5.0

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 (33) hide show
  1. package/.agents/rules/01-naming-and-typing.md +14 -0
  2. package/.agents/rules/02-architecture-and-routing.md +15 -0
  3. package/.agents/rules/03-state-and-data.md +10 -0
  4. package/.agents/rules/04-ui-and-styling.md +10 -0
  5. package/.agents/rules/05-code-quality-and-practices.md +10 -0
  6. package/dist/__deprecated__/types/ticketing/GameTurn.schema.d.ts +5 -5
  7. package/dist/__deprecated__/types/ticketing/GameTurnTask.schema.d.ts +2 -2
  8. package/dist/domains/player/Player.schema.d.ts +2 -8
  9. package/dist/domains/player/Player.schema.js +3 -7
  10. package/dist/domains/racingTeam/RacingTeam.schema.d.ts +77 -3
  11. package/dist/domains/racingTeam/RacingTeam.schema.js +18 -4
  12. package/dist/domains/racingTeam/RacingTeam.types.d.ts +4 -1
  13. package/dist/domains/session/Session.const.d.ts +2 -1
  14. package/dist/domains/session/Session.const.js +2 -1
  15. package/dist/domains/session/Session.schema.d.ts +144 -8
  16. package/dist/domains/session/Session.schema.js +19 -3
  17. package/dist/domains/session/Session.types.d.ts +4 -1
  18. package/dist/domains/ticketing/Ticketing.schema.d.ts +6 -0
  19. package/dist/domains/ticketing/Ticketing.schema.js +5 -0
  20. package/dist/domains/user/User.schema.d.ts +56 -7
  21. package/dist/domains/user/User.schema.js +44 -12
  22. package/dist/domains/user/User.types.d.ts +6 -1
  23. package/docs/TICKETING_AND_PURCHASE_FLOW.md +110 -0
  24. package/package.json +1 -1
  25. package/src/domains/player/Player.schema.ts +2 -7
  26. package/src/domains/racingTeam/RacingTeam.schema.ts +20 -3
  27. package/src/domains/racingTeam/RacingTeam.types.ts +7 -0
  28. package/src/domains/session/Session.const.ts +2 -1
  29. package/src/domains/session/Session.schema.ts +22 -2
  30. package/src/domains/session/Session.types.ts +6 -0
  31. package/src/domains/ticketing/Ticketing.schema.ts +5 -0
  32. package/src/domains/user/User.schema.ts +52 -14
  33. package/src/domains/user/User.types.ts +15 -1
@@ -7,12 +7,27 @@ export const userTypeSchema = z.enum(USER_TYPE);
7
7
  export const PHONE_REGEX = /^([+]?[\\s0-9]+)?(\\d{3}|[(]?[0-9]+[)])?([-]?[\\s]?[0-9])+$/;
8
8
  const MIN_PASSWORD_LENGTH = 6;
9
9
 
10
+ export const emailOrPhoneSchema = z
11
+ .string()
12
+ .min(1, 'Email or phone is required')
13
+ .refine(
14
+ (val) => {
15
+ const isEmail = z.email().safeParse(val).success;
16
+ const isPhone = PHONE_REGEX.test(val);
17
+ return isEmail || isPhone;
18
+ },
19
+ { message: 'Must be a valid email or phone number' },
20
+ );
21
+
10
22
  const baseUserObj = z.object({
11
23
  id: z.uuidv4(),
12
24
 
13
- email: z.email().toLowerCase().optional(),
25
+ name: z.string(),
26
+ lastName: z.string(),
27
+
28
+ email: z.email().toLowerCase().optional().nullable(),
14
29
 
15
- phoneNumber: z.string().regex(PHONE_REGEX, 'Invalid phone number format').optional(),
30
+ phoneNumber: z.string().regex(PHONE_REGEX, 'Invalid phone number format').optional().nullable(),
16
31
 
17
32
  // --- ACCESS CONTROL ---
18
33
  role: userRoleSchema,
@@ -34,19 +49,52 @@ export const userSchema = baseUserObj.refine((data) => data.email || data.phoneN
34
49
  path: ['email', 'phoneNumber'],
35
50
  });
36
51
 
52
+ /**
53
+ * The schema for the user returned on login
54
+ */
55
+ export const authUserSchema = baseUserObj.extend({
56
+ authToken: z.string(),
57
+ });
58
+
37
59
  export const userWithPasswordSchema = userSchema.and(
38
60
  z.object({
39
61
  password: z.string().min(MIN_PASSWORD_LENGTH),
40
62
  }),
41
63
  );
42
64
 
65
+ export const userInitialRegistrationSchema = z.object({
66
+ emailOrPhone: emailOrPhoneSchema,
67
+ password: z.string().min(MIN_PASSWORD_LENGTH, `Password must be at least ${MIN_PASSWORD_LENGTH} characters`),
68
+ });
69
+
70
+ export const userVerifySchema = z.object({
71
+ emailOrPhone: emailOrPhoneSchema,
72
+ code: z.string().min(6, 'Code must be at least 6 characters').max(10, 'Code is too long'),
73
+ });
74
+
75
+ export const userCompleteProfileSchema = baseUserObj
76
+ .pick({
77
+ name: true,
78
+ })
79
+ .extend({
80
+ lastName: z.string().optional(),
81
+ nickname: z.string().min(2),
82
+ birthDate: z.coerce.date(),
83
+ waiverSignature: z.boolean().refine((val) => val === true, {
84
+ message: 'You must accept the waiver signature',
85
+ }),
86
+ teamName: z.string().optional(),
87
+ });
88
+
89
+ // Deprecated in favor of multi-step registration
43
90
  export const userRegistrationInputSchema = baseUserObj
44
91
  .pick({
92
+ name: true,
93
+ lastName: true,
45
94
  email: true,
46
95
  phoneNumber: true,
47
96
  })
48
97
  .extend({
49
- name: z.string().optional(),
50
98
  password: z.string().min(6),
51
99
  nickname: z.string().min(2),
52
100
  birthDate: z.coerce.date(),
@@ -57,16 +105,6 @@ export const userRegistrationInputSchema = baseUserObj
57
105
  });
58
106
 
59
107
  export const userLoginInputSchema = z.object({
60
- emailOrPhone: z
61
- .string()
62
- .min(1, 'Email or phone is required')
63
- .refine(
64
- (val) => {
65
- const isEmail = z.email().safeParse(val).success;
66
- const isPhone = PHONE_REGEX.test(val);
67
- return isEmail || isPhone;
68
- },
69
- { message: 'Must be a valid email or phone number' },
70
- ),
108
+ emailOrPhone: emailOrPhoneSchema,
71
109
  password: z.string().min(MIN_PASSWORD_LENGTH, `Password must be at least ${MIN_PASSWORD_LENGTH} characters`),
72
110
  });
@@ -1,6 +1,20 @@
1
1
  import { z } from 'zod';
2
- import { userSchema, userTypeSchema, userWithPasswordSchema } from './User.schema';
2
+ import {
3
+ userSchema,
4
+ userTypeSchema,
5
+ userWithPasswordSchema,
6
+ userInitialRegistrationSchema,
7
+ userVerifySchema,
8
+ userCompleteProfileSchema,
9
+ userLoginInputSchema,
10
+ authUserSchema,
11
+ } from './User.schema';
3
12
 
4
13
  export type UserType = z.infer<typeof userTypeSchema>;
5
14
  export type User = z.infer<typeof userSchema>;
6
15
  export type UserWithPassword = z.infer<typeof userWithPasswordSchema>;
16
+ export type AuthUser = z.infer<typeof authUserSchema>;
17
+ export type UserInitialRegistration = z.infer<typeof userInitialRegistrationSchema>;
18
+ export type UserVerify = z.infer<typeof userVerifySchema>;
19
+ export type UserCompleteProfile = z.infer<typeof userCompleteProfileSchema>;
20
+ export type UserLogin = z.infer<typeof userLoginInputSchema>;