@battle-racing/br-common-lib 4.1.0 → 4.3.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 (162) hide show
  1. package/dist/__deprecated__/constants/checkpoint-type.d.ts +6 -0
  2. package/dist/__deprecated__/constants/checkpoint-type.js +9 -0
  3. package/dist/__deprecated__/constants/hardware/base-hardware-status.d.ts +6 -0
  4. package/dist/__deprecated__/constants/hardware/base-hardware-status.js +9 -0
  5. package/dist/__deprecated__/constants/hardware/damage.d.ts +10 -0
  6. package/dist/__deprecated__/constants/hardware/damage.js +13 -0
  7. package/dist/__deprecated__/constants/hardware/flag-media-name.d.ts +63 -0
  8. package/dist/__deprecated__/constants/hardware/flag-media-name.js +71 -0
  9. package/dist/__deprecated__/constants/hardware/flag-status.d.ts +10 -0
  10. package/dist/__deprecated__/constants/hardware/flag-status.js +11 -0
  11. package/dist/__deprecated__/constants/hardware/index.js +25 -0
  12. package/dist/__deprecated__/constants/hardware/lights-effect.d.ts +10 -0
  13. package/dist/__deprecated__/constants/hardware/lights-effect.js +14 -0
  14. package/dist/__deprecated__/constants/hardware/rgb-status.d.ts +8 -0
  15. package/dist/__deprecated__/constants/hardware/rgb-status.js +11 -0
  16. package/dist/__deprecated__/constants/hardware/screen-status.d.ts +7 -0
  17. package/dist/__deprecated__/constants/hardware/screen-status.js +8 -0
  18. package/dist/__deprecated__/constants/hardware/screen-view.d.ts +9 -0
  19. package/dist/__deprecated__/constants/hardware/screen-view.js +12 -0
  20. package/dist/__deprecated__/constants/hardware/speed-status.d.ts +9 -0
  21. package/dist/__deprecated__/constants/hardware/speed-status.js +10 -0
  22. package/dist/__deprecated__/constants/index.js +25 -0
  23. package/dist/__deprecated__/constants/kart-status.d.ts +12 -0
  24. package/dist/__deprecated__/constants/kart-status.js +15 -0
  25. package/dist/__deprecated__/constants/module-name.d.ts +12 -0
  26. package/dist/__deprecated__/constants/module-name.js +15 -0
  27. package/dist/__deprecated__/constants/payment-provider.d.ts +5 -0
  28. package/dist/__deprecated__/constants/payment-provider.js +8 -0
  29. package/dist/__deprecated__/constants/payment-status.d.ts +7 -0
  30. package/dist/__deprecated__/constants/payment-status.js +10 -0
  31. package/dist/__deprecated__/constants/permission.d.ts +12 -0
  32. package/dist/__deprecated__/constants/permission.js +15 -0
  33. package/dist/__deprecated__/constants/racing-team-role.d.ts +5 -0
  34. package/dist/__deprecated__/constants/racing-team-role.js +8 -0
  35. package/dist/__deprecated__/constants/user-role.d.ts +5 -0
  36. package/dist/__deprecated__/constants/user-role.js +8 -0
  37. package/dist/__deprecated__/types/checkpoint/CheckpointType.d.ts +1 -1
  38. package/dist/__deprecated__/types/damage/DamageName.d.ts +1 -1
  39. package/dist/__deprecated__/types/hardware/ModuleName.d.ts +1 -1
  40. package/dist/__deprecated__/types/hardware/flag/FlagMediaName.d.ts +1 -1
  41. package/dist/__deprecated__/types/hardware/flag/FlagStatus.d.ts +1 -1
  42. package/dist/__deprecated__/types/hardware/lights/LightsEffect.d.ts +1 -1
  43. package/dist/__deprecated__/types/hardware/rgb/RGBStatus.d.ts +1 -1
  44. package/dist/__deprecated__/types/hardware/screen/ScreenFinishViewInput.d.ts +1 -1
  45. package/dist/__deprecated__/types/hardware/screen/ScreenStatus.d.ts +1 -1
  46. package/dist/__deprecated__/types/hardware/screen/ScreenView.d.ts +1 -1
  47. package/dist/__deprecated__/types/hardware/speed/SpeedStatus.d.ts +1 -1
  48. package/dist/__deprecated__/types/kart/KartStatus.d.ts +1 -1
  49. package/dist/__deprecated__/types/racingTeam/RacingTeamMembership.schema.js +1 -1
  50. package/dist/__deprecated__/types/role/Permission.d.ts +1 -1
  51. package/dist/__deprecated__/types/role/UserRole.d.ts +1 -1
  52. package/dist/__deprecated__/types/ticketing/GameTurn.schema.d.ts +4 -4
  53. package/dist/__deprecated__/types/ticketing/GameTurn.schema.js +2 -2
  54. package/dist/__deprecated__/types/ticketing/PaymentProvider.d.ts +1 -1
  55. package/dist/__deprecated__/types/ticketing/ticketing.schemas.d.ts +1 -2
  56. package/dist/__deprecated__/types/ticketing/ticketing.schemas.js +0 -1
  57. package/dist/__deprecated__/types/user/user.schema.js +1 -1
  58. package/dist/domains/damage/Damage.schema.js +4 -3
  59. package/dist/domains/game/race/Race.schema.d.ts +2 -2
  60. package/dist/domains/hardware/KartHardwareState.schema.js +10 -10
  61. package/dist/domains/hardware/screen/Screen.schema.d.ts +0 -52
  62. package/dist/domains/hardware/screen/Screen.schema.js +5 -9
  63. package/dist/domains/hardware/screen/Screen.types.d.ts +2 -1
  64. package/dist/domains/hardware/screen/ScreenDebug.schema.d.ts +53 -0
  65. package/dist/domains/hardware/screen/ScreenDebug.schema.js +8 -0
  66. package/dist/domains/hardware/screen/index.d.ts +1 -0
  67. package/dist/domains/hardware/screen/index.js +1 -0
  68. package/dist/domains/index.d.ts +2 -0
  69. package/dist/domains/index.js +2 -0
  70. package/dist/domains/kart/Kart.schema.js +2 -2
  71. package/dist/domains/player/Player.const.d.ts +4 -0
  72. package/dist/domains/player/Player.const.js +7 -0
  73. package/dist/domains/player/Player.schema.d.ts +57 -0
  74. package/dist/domains/player/Player.schema.js +48 -0
  75. package/dist/domains/player/Player.types.d.ts +6 -0
  76. package/dist/domains/player/Player.types.js +2 -0
  77. package/dist/domains/player/index.d.ts +3 -0
  78. package/dist/domains/player/index.js +19 -0
  79. package/dist/domains/role/Role.const.d.ts +1 -0
  80. package/dist/domains/role/Role.const.js +1 -0
  81. package/dist/domains/role/Role.schema.d.ts +1 -0
  82. package/dist/domains/session/Session.const.d.ts +7 -0
  83. package/dist/domains/session/Session.const.js +10 -0
  84. package/dist/domains/session/Session.schema.d.ts +65 -0
  85. package/dist/domains/session/Session.schema.js +47 -0
  86. package/dist/domains/session/Session.types.d.ts +7 -0
  87. package/dist/domains/session/Session.types.js +2 -0
  88. package/dist/domains/session/index.d.ts +3 -0
  89. package/dist/domains/session/index.js +19 -0
  90. package/dist/domains/ticketing/Ticketing.const.d.ts +5 -0
  91. package/dist/domains/ticketing/Ticketing.const.js +6 -1
  92. package/dist/domains/ticketing/Ticketing.schema.d.ts +49 -34
  93. package/dist/domains/ticketing/Ticketing.schema.js +26 -26
  94. package/dist/domains/ticketing/Ticketing.types.d.ts +2 -3
  95. package/dist/domains/user/User.schema.d.ts +35 -11
  96. package/dist/domains/user/User.schema.js +47 -9
  97. package/docs/USER_VS_PLAYER.md +87 -0
  98. package/package.json +1 -1
  99. package/src/__deprecated__/constants/hardware/index.ts +9 -0
  100. package/src/__deprecated__/constants/index.ts +9 -0
  101. package/src/__deprecated__/types/checkpoint/CheckpointType.ts +1 -1
  102. package/src/__deprecated__/types/damage/DamageName.ts +1 -1
  103. package/src/__deprecated__/types/hardware/ModuleName.ts +1 -1
  104. package/src/__deprecated__/types/hardware/flag/FlagMediaName.ts +1 -1
  105. package/src/__deprecated__/types/hardware/flag/FlagStatus.ts +1 -1
  106. package/src/__deprecated__/types/hardware/lights/LightsEffect.ts +1 -1
  107. package/src/__deprecated__/types/hardware/rgb/RGBStatus.ts +1 -1
  108. package/src/__deprecated__/types/hardware/screen/ScreenFinishViewInput.ts +1 -1
  109. package/src/__deprecated__/types/hardware/screen/ScreenStatus.ts +1 -1
  110. package/src/__deprecated__/types/hardware/screen/ScreenView.ts +1 -1
  111. package/src/__deprecated__/types/hardware/speed/SpeedStatus.ts +1 -1
  112. package/src/__deprecated__/types/kart/KartStatus.ts +1 -1
  113. package/src/__deprecated__/types/racingTeam/RacingTeamMembership.schema.ts +1 -1
  114. package/src/__deprecated__/types/role/Permission.ts +1 -1
  115. package/src/__deprecated__/types/role/UserRole.ts +1 -1
  116. package/src/__deprecated__/types/ticketing/GameTurn.schema.ts +2 -2
  117. package/src/__deprecated__/types/ticketing/PaymentProvider.ts +1 -1
  118. package/src/__deprecated__/types/ticketing/ticketing.schemas.ts +0 -1
  119. package/src/__deprecated__/types/user/user.schema.ts +1 -1
  120. package/src/domains/damage/Damage.schema.ts +2 -1
  121. package/src/domains/hardware/KartHardwareState.schema.ts +5 -5
  122. package/src/domains/hardware/screen/Screen.schema.ts +2 -7
  123. package/src/domains/hardware/screen/Screen.types.ts +2 -1
  124. package/src/domains/hardware/screen/ScreenDebug.schema.ts +6 -0
  125. package/src/domains/hardware/screen/index.ts +1 -0
  126. package/src/domains/index.ts +2 -0
  127. package/src/domains/kart/Kart.schema.ts +1 -1
  128. package/src/domains/player/Player.const.ts +4 -0
  129. package/src/domains/player/Player.schema.ts +55 -0
  130. package/src/domains/player/Player.types.ts +8 -0
  131. package/src/domains/player/index.ts +3 -0
  132. package/src/domains/role/Role.const.ts +1 -0
  133. package/src/domains/session/Session.const.ts +7 -0
  134. package/src/domains/session/Session.schema.ts +58 -0
  135. package/src/domains/session/Session.types.ts +14 -0
  136. package/src/domains/session/index.ts +3 -0
  137. package/src/domains/ticketing/Ticketing.const.ts +6 -0
  138. package/src/domains/ticketing/Ticketing.schema.ts +33 -27
  139. package/src/domains/ticketing/Ticketing.types.ts +2 -4
  140. package/src/domains/user/User.schema.ts +61 -8
  141. package/br-common-lib.code-workspace +0 -19
  142. /package/{src/constants/hardware/index.ts → dist/__deprecated__/constants/hardware/index.d.ts} +0 -0
  143. /package/{src/constants/index.ts → dist/__deprecated__/constants/index.d.ts} +0 -0
  144. /package/{MIGRATION_GUIDE.md → docs/MIGRATION_GUIDE.md} +0 -0
  145. /package/{REFACTOR_README.md → docs/REFACTOR_README.md} +0 -0
  146. /package/src/{constants → __deprecated__/constants}/checkpoint-type.ts +0 -0
  147. /package/src/{constants → __deprecated__/constants}/hardware/base-hardware-status.ts +0 -0
  148. /package/src/{constants → __deprecated__/constants}/hardware/damage.ts +0 -0
  149. /package/src/{constants → __deprecated__/constants}/hardware/flag-media-name.ts +0 -0
  150. /package/src/{constants → __deprecated__/constants}/hardware/flag-status.ts +0 -0
  151. /package/src/{constants → __deprecated__/constants}/hardware/lights-effect.ts +0 -0
  152. /package/src/{constants → __deprecated__/constants}/hardware/rgb-status.ts +0 -0
  153. /package/src/{constants → __deprecated__/constants}/hardware/screen-status.ts +0 -0
  154. /package/src/{constants → __deprecated__/constants}/hardware/screen-view.ts +0 -0
  155. /package/src/{constants → __deprecated__/constants}/hardware/speed-status.ts +0 -0
  156. /package/src/{constants → __deprecated__/constants}/kart-status.ts +0 -0
  157. /package/src/{constants → __deprecated__/constants}/module-name.ts +0 -0
  158. /package/src/{constants → __deprecated__/constants}/payment-provider.ts +0 -0
  159. /package/src/{constants → __deprecated__/constants}/payment-status.ts +0 -0
  160. /package/src/{constants → __deprecated__/constants}/permission.ts +0 -0
  161. /package/src/{constants → __deprecated__/constants}/racing-team-role.ts +0 -0
  162. /package/src/{constants → __deprecated__/constants}/user-role.ts +0 -0
@@ -0,0 +1,9 @@
1
+ export * from './checkpoint-type';
2
+ export * from './hardware';
3
+ export * from './kart-status';
4
+ export * from './module-name';
5
+ export * from './payment-provider';
6
+ export * from './payment-status';
7
+ export * from './permission';
8
+ export * from './user-role';
9
+ export * from './racing-team-role';
@@ -1,4 +1,4 @@
1
- import { CHECKPOINT_TYPE } from '../../../constants';
1
+ import { CHECKPOINT_TYPE } from '../../constants';
2
2
  import type { ObjectValues } from '../utils';
3
3
 
4
4
  export type CheckpointType = ObjectValues<typeof CHECKPOINT_TYPE>;
@@ -1,4 +1,4 @@
1
- import { DAMAGE_EFFECT } from '../../../constants/hardware/damage';
1
+ import { DAMAGE_EFFECT } from '../../constants/hardware/damage';
2
2
  import { ObjectValues } from '../utils';
3
3
 
4
4
  export type DamageEffectName = ObjectValues<typeof DAMAGE_EFFECT>;
@@ -1,4 +1,4 @@
1
- import { MODULE_NAME } from '../../../constants';
1
+ import { MODULE_NAME } from '../../constants';
2
2
  import type { ObjectValues } from '../utils';
3
3
 
4
4
  export type ModuleName = ObjectValues<typeof MODULE_NAME>;
@@ -1,4 +1,4 @@
1
- import { FLAG_MEDIA_NAME } from '../../../../constants/hardware/flag-media-name';
1
+ import { FLAG_MEDIA_NAME } from '../../../constants/hardware/flag-media-name';
2
2
  import type { ObjectValues } from '../../utils';
3
3
 
4
4
  export type FlagMediaName = ObjectValues<typeof FLAG_MEDIA_NAME> | number;
@@ -1,4 +1,4 @@
1
- import { FLAG_STATUS } from '../../../../constants';
1
+ import { FLAG_STATUS } from '../../../constants';
2
2
  import type { ObjectValues } from '../../utils';
3
3
 
4
4
  export type FlagStatus = ObjectValues<typeof FLAG_STATUS>;
@@ -1,4 +1,4 @@
1
- import { LIGHTS_EFFECT } from '../../../../constants';
1
+ import { LIGHTS_EFFECT } from '../../../constants';
2
2
  import type { ObjectValues } from '../../utils';
3
3
 
4
4
  export type LightsEffect = ObjectValues<typeof LIGHTS_EFFECT>;
@@ -1,4 +1,4 @@
1
- import { RGB_STATUS } from '../../../../constants/hardware/rgb-status';
1
+ import { RGB_STATUS } from '../../../constants/hardware/rgb-status';
2
2
  import type { ObjectValues } from '../../utils';
3
3
 
4
4
  export type RGBStatus = ObjectValues<typeof RGB_STATUS>;
@@ -1,4 +1,4 @@
1
- import { KART_FINAL_STATE } from '../../../../constants';
1
+ import { KART_FINAL_STATE } from '../../../constants';
2
2
  import { ObjectValues } from '../../utils';
3
3
  import { ScreenCurrentTotal } from './ScreenViewBaseConfig';
4
4
 
@@ -1,4 +1,4 @@
1
- import { SCREEN_STATUS } from '../../../../constants';
1
+ import { SCREEN_STATUS } from '../../../constants';
2
2
  import { ObjectValues } from '../../utils';
3
3
 
4
4
  export type ScreenStatus = ObjectValues<typeof SCREEN_STATUS>;
@@ -1,4 +1,4 @@
1
- import { SCREEN_VIEW } from '../../../../constants';
1
+ import { SCREEN_VIEW } from '../../../constants';
2
2
  import { ObjectValues } from '../../utils';
3
3
 
4
4
  export type ScreenView = ObjectValues<typeof SCREEN_VIEW>;
@@ -1,4 +1,4 @@
1
- import { SPEED_STATUS } from '../../../../constants/hardware';
1
+ import { SPEED_STATUS } from '../../../constants/hardware';
2
2
  import { ObjectValues } from '../../utils';
3
3
 
4
4
  export type SpeedStatus = ObjectValues<typeof SPEED_STATUS>;
@@ -1,4 +1,4 @@
1
- import { KART_STATUS } from '../../../constants';
1
+ import { KART_STATUS } from '../../constants';
2
2
  import type { ObjectValues } from '../utils';
3
3
 
4
4
  export type KartStatus = ObjectValues<typeof KART_STATUS>;
@@ -1,7 +1,7 @@
1
1
  // libs/common/src/schemas/racing-team-membership.ts
2
2
 
3
3
  import { z } from 'zod';
4
- import { RACING_TEAM_ROLE } from '../../../constants';
4
+ import { RACING_TEAM_ROLE } from '../../constants';
5
5
 
6
6
  export const joinRequestSchema = z.object({
7
7
  id: z.string(),
@@ -1,4 +1,4 @@
1
- import { PERMISSION } from '../../../constants';
1
+ import { PERMISSION } from '../../constants';
2
2
  import type { ObjectValues } from '../utils';
3
3
 
4
4
  export type Permission = ObjectValues<typeof PERMISSION>;
@@ -1,4 +1,4 @@
1
- import { USER_ROLE } from '../../../constants';
1
+ import { USER_ROLE } from '../../constants';
2
2
  import type { ObjectValues } from '../utils';
3
3
 
4
4
  export type UserRole = ObjectValues<typeof USER_ROLE>;
@@ -32,9 +32,9 @@ export const GameTurnCheckSchema = z.enum([
32
32
  export const GameTurnSchema = z.object({
33
33
  id: z.string(),
34
34
  purchaseId: z.string(),
35
- leaderUsername: z.string(),
35
+ leaderPlayerId: z.string(),
36
36
  gameTickets: z.array(z.string()),
37
- usernames: z.array(z.string()),
37
+ playerIds: z.array(z.string()),
38
38
  status: GameTurnStatusSchema,
39
39
  tasks: z.array(GameTurnTaskSchema),
40
40
  createdAt: z.date(),
@@ -1,4 +1,4 @@
1
- import { PAYMENT_PROVIDERS, PAYMENT_STATUSES } from '../../../constants';
1
+ import { PAYMENT_PROVIDERS, PAYMENT_STATUSES } from '../../constants';
2
2
 
3
3
  export type PaymentProviderName = (typeof PAYMENT_PROVIDERS)[keyof typeof PAYMENT_PROVIDERS];
4
4
 
@@ -29,7 +29,6 @@ export const GameTicketSchema = z.object({
29
29
  id: z.string(),
30
30
  purchaseId: z.string(),
31
31
  gameTurnId: z.string(),
32
- ownerUsername: z.string(),
33
32
  userType: TicketUserTypeSchema,
34
33
  status: GameTicketStatusSchema,
35
34
  type: TicketTypeSchema.default(TICKET_TYPE.RACE),
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { USER_ROLE } from '../../../constants/user-role';
2
+ import { USER_ROLE } from '../../constants/user-role';
3
3
  import { UserTypeSchema } from './user-type.schema';
4
4
 
5
5
  export const UserRoleSchema = z.enum([USER_ROLE.SUPER_ADMIN, USER_ROLE.PLAYER, USER_ROLE.OPERATOR] as const);
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { flagMediaNameSchema, kartEffectSchema } from '../hardware';
2
+ import { flagMediaNameSchema } from '../hardware/flag/Flag.schema';
3
+ import { kartEffectSchema } from '../hardware/kart-effect/KartEffect.schema';
3
4
  import { soundNameSchema } from '../sounds';
4
5
  import { DAMAGE_EFFECT, DAMAGE_TARGET } from './Damage.const';
5
6
 
@@ -1,9 +1,9 @@
1
1
  import { z } from 'zod';
2
- import { checkpointTypeSchema } from '../checkpoint';
3
- import { flagStatusSchema } from './flag';
4
- import { rgbStatusSchema } from './rgb';
5
- import { screenStatusSchema } from './screen';
6
- import { speedStatusSchema } from './speed';
2
+ import { checkpointTypeSchema } from '../checkpoint/Checkpoint.schema';
3
+ import { flagStatusSchema } from './flag/Flag.schema';
4
+ import { rgbStatusSchema } from './rgb/RGB.schema';
5
+ import { screenStatusSchema } from './screen/Screen.schema';
6
+ import { speedStatusSchema } from './speed/Speed.schema';
7
7
 
8
8
  export const kartHardwareStateSchema = z.object({
9
9
  speed: z
@@ -1,10 +1,9 @@
1
1
  import { z } from 'zod';
2
2
 
3
- import { damageEffectNameSchema } from '../../damage';
4
- import { kartHardwareStateSchema } from '../../hardware';
3
+ import { damageEffectNameSchema } from '../../damage/Damage.schema';
5
4
  import { powerUpNameSchema } from '../../powerUp/PowerUpAttributes.schema';
6
5
  import { SCREEN_STATUS, SCREEN_VIEW } from './Screen.const';
7
- import { KART_FINAL_STATE } from '../../kart';
6
+ import { KART_FINAL_STATE } from '../../kart/Kart.const';
8
7
 
9
8
  export const screenStatusSchema = z.enum(SCREEN_STATUS);
10
9
  export const screenViewSchema = z.enum(SCREEN_VIEW);
@@ -79,10 +78,6 @@ export const screenFinishViewInputSchema = z.object({
79
78
  finalState: kartFinalStateSchema.optional(),
80
79
  });
81
80
 
82
- export const screenDebugViewInputSchema = kartHardwareStateSchema.extend({
83
- kartNumber: z.number(),
84
- });
85
-
86
81
  export const screenHomeViewInputSchema = z.object({
87
82
  kartNumber: z.number().nullable().optional(),
88
83
  });
@@ -4,7 +4,6 @@ import {
4
4
  countDownNextViewRaceSchema,
5
5
  screenBattleViewConfigSchema,
6
6
  screenCountdownParamsSchema,
7
- screenDebugViewInputSchema,
8
7
  screenFinishViewInputSchema,
9
8
  screenGameTimeLeftSchema,
10
9
  screenHomeViewInputSchema,
@@ -18,6 +17,8 @@ import {
18
17
  updateRaceViewInputSchema,
19
18
  } from './Screen.schema';
20
19
 
20
+ import { screenDebugViewInputSchema } from './ScreenDebug.schema';
21
+
21
22
  export type ScreenStatus = z.infer<typeof screenStatusSchema>;
22
23
  export type ScreenView = z.infer<typeof screenViewSchema>;
23
24
  export type ScreenModuleStatus = z.infer<typeof screenModuleStatusSchema>;
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ import { kartHardwareStateSchema } from '../KartHardwareState.schema';
3
+
4
+ export const screenDebugViewInputSchema = kartHardwareStateSchema.extend({
5
+ kartNumber: z.number(),
6
+ });
@@ -1,3 +1,4 @@
1
1
  export * from './Screen.const';
2
2
  export * from './Screen.schema';
3
+ export * from './ScreenDebug.schema';
3
4
  export * from './Screen.types';
@@ -9,7 +9,9 @@ export * from './hardware';
9
9
  export * from './kart';
10
10
  export * from './kartTracking';
11
11
  export * from './powerUp';
12
+ export * from './player';
12
13
  export * from './racingTeam';
14
+ export * from './session';
13
15
  export * from './socket';
14
16
  export * from './ticketing';
15
17
  export * from './user';
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { colorNameSchema } from '../color';
3
3
  import { damageEffectNameSchema } from '../damage';
4
4
  import { gameTypeSchema } from '../game';
5
- import { kartHardwareStateSchema } from '../hardware';
5
+ import { kartHardwareStateSchema } from '../hardware/KartHardwareState.schema';
6
6
  import { powerUpNameSchema } from '../powerUp/PowerUpAttributes.schema';
7
7
  import { KART_STATUS } from './Kart.const';
8
8
 
@@ -0,0 +1,4 @@
1
+ export const PLAYER_TYPE = {
2
+ ADULT: 'ADULT',
3
+ MINOR: 'MINOR', // Managed by a Guardian
4
+ } as const;
@@ -0,0 +1,55 @@
1
+ import { z } from 'zod';
2
+ import { PLAYER_TYPE } from './Player.const';
3
+
4
+ export const playerTypeSchema = z.enum(PLAYER_TYPE);
5
+
6
+ export const playerWaiverStatusSchema = z.object({
7
+ isSigned: z.boolean().default(false),
8
+ waiverId: z.uuidv4().nullable().optional(),
9
+ templateVersion: z.string().optional(),
10
+ expiresAt: z.date().nullable().optional(),
11
+ });
12
+
13
+ export const playerStatsSchema = z.object({
14
+ totalRaces: z.number().int().default(0),
15
+ bestTimeMs: z.number().int().nullable().optional(),
16
+ xp: z.number().int().default(0),
17
+ });
18
+
19
+ export const playerSchema = z.object({
20
+ id: z.uuidv4(),
21
+ nickname: z.string().min(2).max(20),
22
+ avatarUrl: z.url().optional(),
23
+ birthDate: z.date(),
24
+ type: playerTypeSchema.default(PLAYER_TYPE.ADULT),
25
+
26
+ ownerUserId: z.uuidv4().nullable().optional(),
27
+ isGuest: z.boolean().default(true),
28
+ waiver: playerWaiverStatusSchema,
29
+
30
+ // TODO: Add the stats here, to aovid extra queries
31
+ stats: playerStatsSchema.optional().nullable(),
32
+
33
+ createdAt: z.date(),
34
+ updatedAt: z.date(),
35
+ });
36
+
37
+ export const createPlayerSchema = playerSchema
38
+ .pick({
39
+ nickname: true,
40
+ type: true,
41
+ })
42
+ .extend({
43
+ birthDate: z.coerce.date(),
44
+ });
45
+
46
+ export const signWaiverSchema = z.object({
47
+ signature: z.string().optional(), // Base64 or simply a boolean acceptance. Let's make it flexible.
48
+ accepted: z.literal(true), // They must explicitly pass accepted: true
49
+ });
50
+
51
+ export const createMinorPlayerSchema = z.object({
52
+ nickname: z.string().min(2).max(20),
53
+ birthDate: z.coerce.date(),
54
+ // For a minor, the signature is implicitly granted by the tutor calling this endpoint
55
+ });
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ import { playerSchema, playerStatsSchema, playerTypeSchema, playerWaiverStatusSchema } from './Player.schema';
3
+
4
+ export type PlayerType = z.infer<typeof playerTypeSchema>;
5
+ export type PlayerStats = z.infer<typeof playerStatsSchema>;
6
+ export type PlayerWaiverStatus = z.infer<typeof playerWaiverStatusSchema>;
7
+
8
+ export type Player = z.infer<typeof playerSchema>;
@@ -0,0 +1,3 @@
1
+ export * from './Player.const';
2
+ export * from './Player.schema';
3
+ export * from './Player.types';
@@ -18,4 +18,5 @@ export const USER_ROLE = {
18
18
  SUPER_ADMIN: 'SUPER_ADMIN',
19
19
  OPERATOR: 'OPERATOR',
20
20
  PLAYER: 'PLAYER',
21
+ CASHIER: 'CASHIER',
21
22
  } as const;
@@ -0,0 +1,7 @@
1
+ export const SESSION_STATUS = {
2
+ CREATED: 'CREATED',
3
+ READY: 'READY',
4
+ STARTED: 'STARTED',
5
+ FINISHED: 'FINISHED',
6
+ CANCELLED: 'CANCELLED',
7
+ } as const;
@@ -0,0 +1,58 @@
1
+ import { z } from 'zod';
2
+ import { SESSION_STATUS } from './Session.const';
3
+ import { gameTypeSchema } from '../game/Game.schema';
4
+
5
+ export const sessionStatusSchema = z.enum(SESSION_STATUS);
6
+
7
+ export const sessionTicketSchema = z.object({
8
+ quantity: z.number().int().positive(),
9
+ type: gameTypeSchema,
10
+ });
11
+
12
+ export const gameSessionSchema = z.object({
13
+ code: z.string().length(6), // 6-char alphanumeric
14
+ contactPhone: z.string().optional(),
15
+ userId: z.string().optional().nullable(),
16
+
17
+ tickets: z.array(sessionTicketSchema),
18
+ playerIds: z.array(z.uuidv4()),
19
+ linkedPurchaseId: z.string().optional(),
20
+
21
+ status: sessionStatusSchema.default(SESSION_STATUS.CREATED),
22
+
23
+ createdAt: z.date(),
24
+ updatedAt: z.date(),
25
+ });
26
+
27
+ export const createSessionInputSchema = z.object({
28
+ contactPhone: z.string().optional(),
29
+ userId: z.string().optional().nullable(),
30
+ tickets: z.array(sessionTicketSchema).min(1),
31
+ });
32
+
33
+ export const joinSessionSchema = z.object({
34
+ nickname: z.string().min(2),
35
+ birthDate: z.coerce.date(),
36
+ });
37
+
38
+ export const createGameTurnInputSchema = z.object({
39
+ assignments: z
40
+ .array(
41
+ z.object({
42
+ ticketId: z.string(),
43
+ playerId: z.uuidv4(),
44
+ }),
45
+ )
46
+ .min(1),
47
+ });
48
+
49
+ export const assignSessionTicketsInputSchema = z.object({
50
+ assignments: z
51
+ .array(
52
+ z.object({
53
+ ticketId: z.string(),
54
+ playerId: z.uuidv4(),
55
+ }),
56
+ )
57
+ .min(1),
58
+ });
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ assignSessionTicketsInputSchema,
4
+ createSessionInputSchema,
5
+ gameSessionSchema,
6
+ sessionStatusSchema,
7
+ sessionTicketSchema,
8
+ } from './Session.schema';
9
+
10
+ export type SessionStatus = z.infer<typeof sessionStatusSchema>;
11
+ export type SessionTicket = z.infer<typeof sessionTicketSchema>;
12
+ export type GameSession = z.infer<typeof gameSessionSchema>;
13
+ export type CreateSessionInput = z.infer<typeof createSessionInputSchema>;
14
+ export type AssignSessionTicketsInput = z.infer<typeof assignSessionTicketsInputSchema>;
@@ -0,0 +1,3 @@
1
+ export * from './Session.const';
2
+ export * from './Session.schema';
3
+ export * from './Session.types';
@@ -42,3 +42,9 @@ export const GAME_TURN_TASK_STATUS = {
42
42
  PENDING: 'pending',
43
43
  COMPLETED: 'completed',
44
44
  } as const;
45
+
46
+ export const PURCHASE_STATUS = {
47
+ PENDING: 'pending',
48
+ PAID: 'paid',
49
+ CANCELLED: 'cancelled',
50
+ } as const;
@@ -5,9 +5,11 @@ import {
5
5
  GAME_TURN_STATUS,
6
6
  GAME_TURN_TASK_STATUS,
7
7
  GAME_TURN_TASK_TYPE,
8
+ PURCHASE_STATUS,
8
9
  TICKET_TYPE,
9
10
  TICKET_USER_TYPE,
10
11
  } from './Ticketing.const';
12
+ import { gameTypeSchema } from '../game';
11
13
 
12
14
  export const gameTicketStatusSchema = z.enum(GAME_TICKET_STATUS);
13
15
  export const ticketUserTypeSchema = z.enum(TICKET_USER_TYPE);
@@ -15,11 +17,11 @@ export const ticketTypeSchema = z.enum(TICKET_TYPE);
15
17
  export const ticketSummarySchema = z.record(ticketTypeSchema, z.number());
16
18
 
17
19
  export const gameTicketSchema = z.object({
18
- id: z.string(),
20
+ id: z.uuidv4(),
19
21
  purchaseId: z.string(),
20
- gameTurnId: z.string(),
21
- ownerUsername: z.string(),
22
- userType: ticketUserTypeSchema,
22
+ sessionId: z.string().optional().nullable(),
23
+ gameTurnId: z.string().optional().nullable(),
24
+ playerId: z.uuidv4().optional().nullable(),
23
25
  status: gameTicketStatusSchema,
24
26
  type: ticketTypeSchema.default(TICKET_TYPE.RACE),
25
27
  createdAt: z.date(),
@@ -27,34 +29,38 @@ export const gameTicketSchema = z.object({
27
29
  completedAt: z.date().optional(),
28
30
  });
29
31
 
32
+ export const purchaseStatusSchema = z.enum(PURCHASE_STATUS);
33
+
34
+ export const purchaseItemSchema = z.object({
35
+ ticketType: gameTypeSchema,
36
+ quantity: z.number().int().positive(),
37
+ priceCents: z.number().int().nonnegative(),
38
+ });
39
+
30
40
  export const purchaseSchema = z.object({
31
- id: z.string(),
41
+ id: z.uuidv4(),
32
42
  purchaseNumber: z.number(),
33
- buyerUserId: z.string(),
34
- totalTickets: z.number(),
35
- purchaseDate: z.date(),
36
- ticketType: ticketTypeSchema.default(TICKET_TYPE.RACE),
43
+
44
+ // Buyer can be null for Guest/On-Site purchases
45
+ buyerUserId: z.string().optional().nullable(),
46
+
47
+ items: z.array(purchaseItemSchema),
48
+ totalAmountCents: z.number().min(0),
49
+ status: purchaseStatusSchema.default(PURCHASE_STATUS.PENDING),
50
+
51
+ // Deprecated fields (kept for backward compatibility if needed, or remove if safe)
52
+ totalTickets: z.number().optional(),
53
+ ticketType: ticketTypeSchema.optional(),
54
+
37
55
  paymentData: z.any().optional(),
38
56
  createdAt: z.date(),
39
57
  updatedAt: z.date(),
40
58
  });
41
59
 
42
- export const createPurchasePublicSchema = purchaseSchema
43
- .pick({
44
- ticketType: true,
45
- })
46
- .extend({
47
- ticketCount: z.number(),
48
- });
49
-
50
- export const createPurchaseInternalSchema = purchaseSchema
51
- .pick({
52
- ticketType: true,
53
- buyerUserId: true,
54
- })
55
- .extend({
56
- ticketCount: z.number(),
57
- });
60
+ export const createPurchaseInputSchema = z.object({
61
+ buyerUserId: z.string().optional(),
62
+ items: z.array(purchaseItemSchema).min(1),
63
+ });
58
64
 
59
65
  export const gameTurnStatusSchema = z.enum(GAME_TURN_STATUS);
60
66
 
@@ -76,9 +82,9 @@ export const gameTurnTaskSchema = z.object({
76
82
  export const gameTurnSchema = z.object({
77
83
  id: z.string(),
78
84
  purchaseId: z.string(),
79
- leaderUsername: z.string(),
85
+ leaderPlayerId: z.string(),
80
86
  gameTickets: z.array(z.string()),
81
- usernames: z.array(z.string()),
87
+ playerIds: z.array(z.string()),
82
88
  status: gameTurnStatusSchema,
83
89
  tasks: z.array(gameTurnTaskSchema),
84
90
  createdAt: z.date(),
@@ -1,7 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import {
3
- createPurchaseInternalSchema,
4
- createPurchasePublicSchema,
3
+ createPurchaseInputSchema,
5
4
  gameTicketSchema,
6
5
  gameTicketStatusSchema,
7
6
  gameTurnCheckSchema,
@@ -23,8 +22,7 @@ export type TicketUserType = z.infer<typeof ticketUserTypeSchema>;
23
22
  export type TicketSummary = z.infer<typeof ticketSummarySchema>;
24
23
 
25
24
  export type Purchase = z.infer<typeof purchaseSchema>;
26
- export type CreatePurchasePublicInput = z.infer<typeof createPurchasePublicSchema>;
27
- export type CreatePurchaseInternalInput = z.infer<typeof createPurchaseInternalSchema>;
25
+ export type CreatePurchaseInput = z.infer<typeof createPurchaseInputSchema>;
28
26
 
29
27
  export type GameTicket = z.infer<typeof gameTicketSchema>;
30
28
 
@@ -4,16 +4,69 @@ import { USER_TYPE } from './User.const';
4
4
 
5
5
  export const userTypeSchema = z.enum(USER_TYPE);
6
6
 
7
- export const userSchema = z.object({
8
- id: z.string(),
9
- name: z.string(),
10
- username: z.string(),
11
- email: z.email(),
12
- phone: z.string().optional(),
7
+ export const PHONE_REGEX = /^([+]?[\\s0-9]+)?(\\d{3}|[(]?[0-9]+[)])?([-]?[\\s]?[0-9])+$/;
8
+ const MIN_PASSWORD_LENGTH = 6;
9
+
10
+ const baseUserObj = z.object({
11
+ id: z.uuidv4(),
12
+
13
+ email: z.email().toLowerCase().optional(),
14
+
15
+ phoneNumber: z.string().regex(PHONE_REGEX, 'Invalid phone number format').optional(),
16
+
17
+ // --- ACCESS CONTROL ---
13
18
  role: userRoleSchema,
14
19
  type: userTypeSchema,
20
+
21
+ isActive: z.boolean().default(true),
22
+ // TODO: Implement mechanism to validate users later by email or phone
23
+ isEmailVerified: z.boolean().default(false),
24
+ isPhoneVerified: z.boolean().default(false),
25
+
26
+ defaultPlayerId: z.uuidv4().optional(),
27
+
28
+ createdAt: z.date(),
29
+ lastLoginAt: z.date().optional(),
30
+ });
31
+
32
+ export const userSchema = baseUserObj.refine((data) => data.email || data.phoneNumber, {
33
+ message: 'User must have either an email or a phone number',
34
+ path: ['email', 'phoneNumber'],
15
35
  });
16
36
 
17
- export const userWithPasswordSchema = userSchema.extend({
18
- password: z.string(),
37
+ export const userWithPasswordSchema = userSchema.and(
38
+ z.object({
39
+ password: z.string().min(MIN_PASSWORD_LENGTH),
40
+ }),
41
+ );
42
+
43
+ export const userRegistrationInputSchema = baseUserObj
44
+ .pick({
45
+ email: true,
46
+ phoneNumber: true,
47
+ })
48
+ .extend({
49
+ name: z.string().optional(),
50
+ password: z.string().min(6),
51
+ nickname: z.string().min(2),
52
+ birthDate: z.coerce.date(),
53
+ })
54
+ .refine((data) => data.email || data.phoneNumber, {
55
+ message: 'User must have either an email or a phone number',
56
+ path: ['email', 'phoneNumber'],
57
+ });
58
+
59
+ 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
+ ),
71
+ password: z.string().min(MIN_PASSWORD_LENGTH, `Password must be at least ${MIN_PASSWORD_LENGTH} characters`),
19
72
  });