This commit completes the first phase of feature parity implementation and resolves all API integration issues to match the backend API format. ## API Integration Fixes - Remove all hardcoded default values from transformers (tick_rate, kast, player_count, steam_updated) - Update TypeScript types to make fields optional where backend doesn't guarantee them - Update Zod schemas to validate optional fields correctly - Fix mock data to match real API response format (plain arrays, not wrapped objects) - Update UI components to handle undefined values with proper fallbacks - Add comprehensive API documentation for Match and Player endpoints ## Phase 1 Features Implemented (3/6) ### 1. Player Tracking System ✅ - Created TrackPlayerModal.svelte with auth code input - Integrated track/untrack player API endpoints - Added UI for providing optional share code - Displays tracked status on player profiles - Full validation and error handling ### 2. Share Code Parsing ✅ - Created ShareCodeInput.svelte component - Added to matches page for easy match submission - Real-time validation of share code format - Parse status feedback with loading states - Auto-redirect to match page on success ### 3. VAC/Game Ban Status ✅ - Added VAC and game ban count/date fields to Player type - Display status badges on player profile pages - Show ban count and date when available - Visual indicators using DaisyUI badge components ## Component Improvements - Modal.svelte: Added Svelte 5 Snippet types, actions slot support - ThemeToggle.svelte: Removed deprecated svelte:component usage - Tooltip.svelte: Fixed type safety with Snippet type - All new components follow Svelte 5 runes pattern ($state, $derived, $bindable) ## Type Safety & Linting - Fixed all ESLint errors (any types → proper types) - Fixed form label accessibility issues - Replaced error: any with error: unknown + proper type guards - Added Snippet type imports where needed - Updated all catch blocks to use instanceof Error checks ## Static Assets - Migrated all files from public/ to static/ directory per SvelteKit best practices - Moved 200+ map icons, screenshots, and other assets - Updated all import paths to use /images/ (served from static/) ## Documentation - Created IMPLEMENTATION_STATUS.md tracking all 15 missing features - Updated API.md with optional field annotations - Created MATCHES_API.md with comprehensive endpoint documentation - Added inline comments marking optional vs required fields ## Testing - Updated mock fixtures to remove default values - Fixed mock handlers to return plain arrays like real API - Ensured all components handle undefined gracefully ## Remaining Phase 1 Tasks - [ ] Add VAC status column to match scoreboard - [ ] Create weapons statistics tab for matches - [ ] Implement recently visited players on home page 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
103 lines
3.8 KiB
TypeScript
103 lines
3.8 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
/**
|
|
* Zod schemas for Match data models
|
|
* Provides runtime validation and type safety
|
|
*/
|
|
|
|
/** MatchPlayer schema */
|
|
export const matchPlayerSchema = z.object({
|
|
id: z.string().min(1), // Steam ID uint64 as string to preserve precision
|
|
name: z.string().min(1),
|
|
avatar: z.string().url(),
|
|
team_id: z.number().int().min(2).max(3), // 2 = T, 3 = CT
|
|
|
|
// Performance metrics
|
|
kills: z.number().int().nonnegative(),
|
|
deaths: z.number().int().nonnegative(),
|
|
assists: z.number().int().nonnegative(),
|
|
headshot: z.number().int().nonnegative(),
|
|
mvp: z.number().int().nonnegative(),
|
|
score: z.number().int().nonnegative(),
|
|
kast: z.number().int().min(0).max(100).optional(),
|
|
|
|
// Rank (CS2 Premier rating: 0-30000)
|
|
rank_old: z.number().int().min(0).max(30000).optional(),
|
|
rank_new: z.number().int().min(0).max(30000).optional(),
|
|
|
|
// Damage
|
|
dmg_enemy: z.number().int().nonnegative().optional(),
|
|
dmg_team: z.number().int().nonnegative().optional(),
|
|
|
|
// Multi-kills
|
|
mk_2: z.number().int().nonnegative().optional(),
|
|
mk_3: z.number().int().nonnegative().optional(),
|
|
mk_4: z.number().int().nonnegative().optional(),
|
|
mk_5: z.number().int().nonnegative().optional(),
|
|
|
|
// Utility damage
|
|
ud_he: z.number().int().nonnegative().optional(),
|
|
ud_flames: z.number().int().nonnegative().optional(),
|
|
ud_flash: z.number().int().nonnegative().optional(),
|
|
ud_smoke: z.number().int().nonnegative().optional(),
|
|
ud_decoy: z.number().int().nonnegative().optional(),
|
|
|
|
// Flash statistics
|
|
flash_assists: z.number().int().nonnegative().optional(),
|
|
flash_duration_enemy: z.number().nonnegative().optional(),
|
|
flash_duration_team: z.number().nonnegative().optional(),
|
|
flash_duration_self: z.number().nonnegative().optional(),
|
|
flash_total_enemy: z.number().int().nonnegative().optional(),
|
|
flash_total_team: z.number().int().nonnegative().optional(),
|
|
flash_total_self: z.number().int().nonnegative().optional(),
|
|
|
|
// Other
|
|
crosshair: z.string().optional(),
|
|
color: z.enum(['green', 'yellow', 'purple', 'blue', 'orange', 'grey']).optional(),
|
|
avg_ping: z.number().nonnegative().optional()
|
|
});
|
|
|
|
/** Match schema */
|
|
export const matchSchema = z.object({
|
|
match_id: z.string().min(1), // uint64 as string to preserve precision
|
|
share_code: z
|
|
.string()
|
|
.regex(/^(CSGO-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5})?$/)
|
|
.optional(),
|
|
map: z.string().min(1),
|
|
date: z.string().datetime(),
|
|
score_team_a: z.number().int().nonnegative(),
|
|
score_team_b: z.number().int().nonnegative(),
|
|
duration: z.number().int().positive(),
|
|
match_result: z.number().int().min(0).max(2), // 0 = tie, 1 = team_a win, 2 = team_b win
|
|
max_rounds: z.number().int().positive(),
|
|
demo_parsed: z.boolean(),
|
|
vac_present: z.boolean(),
|
|
gameban_present: z.boolean(),
|
|
tick_rate: z.number().positive().optional(),
|
|
players: z.array(matchPlayerSchema).optional()
|
|
});
|
|
|
|
/** MatchListItem schema */
|
|
export const matchListItemSchema = z.object({
|
|
match_id: z.string().min(1), // uint64 as string to preserve precision
|
|
map: z.string().min(1),
|
|
date: z.string().datetime(),
|
|
score_team_a: z.number().int().nonnegative(),
|
|
score_team_b: z.number().int().nonnegative(),
|
|
duration: z.number().int().positive(),
|
|
demo_parsed: z.boolean(),
|
|
player_count: z.number().int().min(2).max(10).optional()
|
|
});
|
|
|
|
/** Parser functions for safe data validation */
|
|
export const parseMatch = (data: unknown) => matchSchema.parse(data);
|
|
export const parseMatchSafe = (data: unknown) => matchSchema.safeParse(data);
|
|
export const parseMatchPlayer = (data: unknown) => matchPlayerSchema.parse(data);
|
|
export const parseMatchListItem = (data: unknown) => matchListItemSchema.parse(data);
|
|
|
|
/** Infer TypeScript types from schemas */
|
|
export type MatchSchema = z.infer<typeof matchSchema>;
|
|
export type MatchPlayerSchema = z.infer<typeof matchPlayerSchema>;
|
|
export type MatchListItemSchema = z.infer<typeof matchListItemSchema>;
|