import {z} from 'zod' export type CSGOGameID = number; export type GetApiCsgoGamesCsgoGameIdArgs = {csgo_game_id: CSGOGameID}; export type GetApiCsgoGamesCsgoGameIdOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const gameComplete = z.boolean(); export const gameDetailedStats = z.boolean(); export const gameIsFinished = z.boolean(); export const gameIsForfeit = z.boolean(); export const cSGOGameID = z.number().int().gte(1); export const cSGOMapID = z.number().int().gte(1); export const cSGOMapName = z.string(); export const cSGOMapSlug = z.string().min(1); export const matchDetailedStats = z.boolean(); export const matchIsDraw = z.boolean(); export const matchIsForfeit = z.boolean(); export const loLGameID = z.number().int().gte(1); export const owGameID = z.number().int().gte(1); export const dota2GameID = z.number().int().gte(1); export const pUBGGameID = z.number().int().gte(1); export const valorantGameID = z.number().int().gte(1); export const gameID = z.union([loLGameID, cSGOGameID, owGameID, dota2GameID, pUBGGameID, valorantGameID]); export const matchID = z.number().int().gte(1); export const gamePosition = z.number().int().gte(1); export const gameStatus = z.enum(["finished", "not_played", "not_started", "running"]); export const gameWinner = z.object({id: z.union([z.number().int().gte(1).nullable(), z.number().int().gte(1).nullable()]), type: z.enum(["Player", "Team"]).nullable()}); export const game = z.object({begin_at: z.string().min(1).nullable(), complete: gameComplete, detailed_stats: gameDetailedStats, end_at: z.string().min(1).nullable(), finished: gameIsFinished, forfeit: gameIsForfeit, id: gameID, length: z.number().int().gte(0).nullable(), match_id: matchID, position: gamePosition, status: gameStatus, winner: gameWinner, winner_type: z.enum(["Player", "Team"]).nullable()}); export const games = z.array(game); export const leagueID = z.number().int().gte(1); export const leagueModifiedAt = z.string().min(1); export const leagueName = z.string(); export const leagueSlug = z.string().min(1); export const baseLeague = z.object({id: leagueID, image_url: z.string().nullable(), modified_at: leagueModifiedAt, name: leagueName, slug: leagueSlug, url: z.string().nullable()}); export const matchLiveIsSupported = z.boolean(); export const matchLive = z.object({opens_at: z.string().min(1).nullable(), supported: matchLiveIsSupported, url: z.string().nullable()}); export const matchHasLowLatencyFeed = z.boolean(); export const valorantMapID = z.number().int().gte(1); export const valorantMapImageURL = z.string(); export const valorantMapName = z.string(); export const valorantMapSlug = z.string().min(1); export const videogameVersion = z.string(); export const videogameVersions = z.array(videogameVersion); export const valorantMapPick = z.object({id: valorantMapID, image_url: valorantMapImageURL, name: valorantMapName, picking_team_id: z.number().int().gte(1).nullable(), slug: valorantMapSlug, videogame_versions: videogameVersions}); export const matchType = z.enum(["all_games_played", "best_of", "custom", "first_to", "ow_best_of", "red_bull_home_ground"]); export const matchModifiedAt = z.string().min(1); export const matchName = z.string(); export const gameCount = z.number().int().gte(0); export const playerIsActive = z.boolean(); export const playerID = z.number().int().gte(1); export const playerModifiedAt = z.string().min(1); export const playerName = z.string(); export const basePlayer = z.object({active: playerIsActive, age: z.number().gte(0).nullable(), birthday: z.string().nullable(), first_name: z.string().nullable(), id: playerID, image_url: z.string().nullable(), last_name: z.string().nullable(), modified_at: playerModifiedAt, name: playerName, nationality: z.string().nullable(), role: z.string().nullable(), slug: z.string().min(1).nullable()}); export const teamID = z.number().int().gte(1); export const teamModifiedAt = z.string().min(1); export const teamName = z.string(); export const baseTeam = z.object({acronym: z.string().nullable(), dark_mode_image_url: z.string().nullable(), id: teamID, image_url: z.string().nullable(), location: z.string().nullable(), modified_at: teamModifiedAt, name: teamName, slug: z.string().min(1).nullable()}); export const baseOpponent = z.union([basePlayer, baseTeam]); export const opponentType = z.enum(["Player", "Team"]); export const opponent = z.object({opponent: baseOpponent, type: opponentType}); export const opponents = z.array(opponent); export const matchScore = z.number().int().gte(0); export const matchTeamResult = z.object({score: matchScore, team_id: teamID}); export const matchPlayerResult = z.object({player_id: playerID, score: matchScore}); export const matchResult = z.union([matchTeamResult, matchPlayerResult]); export const matchResults = z.array(matchResult); export const serieFullName = z.string(); export const serieID = z.number().int().gte(1); export const serieModifiedAt = z.string().min(1); export const serieSlug = z.string().min(1); export const baseSerie = z.object({begin_at: z.string().min(1).nullable(), end_at: z.string().min(1).nullable(), full_name: serieFullName, id: serieID, league_id: leagueID, modified_at: serieModifiedAt, name: z.string().nullable(), season: z.string().nullable(), slug: serieSlug, winner_id: z.union([z.number().int().gte(1).nullable(), z.number().int().gte(1).nullable()]), winner_type: z.enum(["Player", "Team"]).nullable(), year: z.number().int().gte(2012).nullable()}); export const matchStatus = z.enum(["canceled", "finished", "not_started", "postponed", "running"]); export const streamLanguage = z.enum(["aa", "ab", "ae", "af", "ak", "am", "an", "ar", "as", "av", "ay", "az", "ba", "be", "bg", "bh", "bi", "bm", "bn", "bo", "br", "bs", "ca", "ce", "ch", "co", "cr", "cs", "cu", "cv", "cy", "da", "de", "dv", "dz", "ee", "el", "en", "eo", "es", "et", "eu", "fa", "ff", "fi", "fj", "fo", "fr", "fy", "ga", "gd", "gl", "gn", "gu", "gv", "ha", "he", "hi", "ho", "hr", "ht", "hu", "hy", "hz", "ia", "id", "ie", "ig", "ii", "ik", "io", "is", "it", "iu", "ja", "jv", "ka", "kg", "ki", "kj", "kk", "kl", "km", "kn", "ko", "kr", "ks", "ku", "kv", "kw", "ky", "la", "lb", "lg", "li", "ln", "lo", "lt", "lu", "lv", "mg", "mh", "mi", "mk", "ml", "mn", "mr", "ms", "mt", "my", "na", "nb", "nd", "ne", "ng", "nl", "nn", "no", "nr", "nv", "ny", "oc", "oj", "om", "or", "os", "pa", "pi", "pl", "ps", "pt", "qu", "rm", "rn", "ro", "ru", "rw", "sa", "sc", "sd", "se", "sg", "si", "sk", "sl", "sm", "sn", "so", "sq", "sr", "ss", "st", "su", "sv", "sw", "ta", "te", "tg", "th", "ti", "tk", "tl", "tn", "to", "tr", "ts", "tt", "tw", "ty", "ug", "uk", "ur", "uz", "ve", "vi", "vo", "wa", "wo", "xh", "yi", "yo", "za", "zh", "zu"]); export const streamIsMain = z.boolean(); export const streamIsOfficial = z.boolean(); export const streamURL = z.string(); export const stream = z.object({embed_url: z.string().nullable(), language: streamLanguage, main: streamIsMain, official: streamIsOfficial, raw_url: streamURL}); export const streamsList = z.array(stream); export const tournamentDetailedStats = z.boolean(); export const tournamentHasBracket = z.boolean(); export const tournamentID = z.number().int().gte(1); export const tournamentLiveSupported = z.boolean(); export const tournamentModifiedAt = z.string().min(1); export const tournamentName = z.string(); export const tournamentSlug = z.string().min(1); export const baseTournament = z.object({begin_at: z.string().min(1).nullable(), country: z.string().nullable(), detailed_stats: tournamentDetailedStats, end_at: z.string().min(1).nullable(), has_bracket: tournamentHasBracket, id: tournamentID, league_id: leagueID, live_supported: tournamentLiveSupported, modified_at: tournamentModifiedAt, name: tournamentName, prizepool: z.string().nullable(), region: z.enum(["AF", "ASIA", "EEU", "ME", "NA", "OCE", "SA", "WEU"]).nullable(), serie_id: serieID, slug: tournamentSlug, tier: z.enum(["a", "b", "c", "d", "s", "unranked"]).nullable(), type: z.enum(["offline", "online", "online/offline"]).nullable(), winner_id: z.union([z.number().int().gte(1).nullable(), z.number().int().gte(1).nullable()]), winner_type: z.enum(["Player", "Team"]).nullable()}); export const currentVideogame = z.object({}); export const videogameVersionIsCurrent = z.boolean(); export const matchWinnerType = z.enum(["Player", "Team"]); export const fullGameMatch = z.object({begin_at: z.string().min(1).nullable(), detailed_stats: matchDetailedStats, draw: matchIsDraw, end_at: z.string().min(1).nullable(), forfeit: matchIsForfeit, game_advantage: z.number().int().gte(1).nullable(), games: games, id: matchID, league: baseLeague, league_id: leagueID, live: matchLive, low_latency_feed: matchHasLowLatencyFeed.optional(), map_picks: z.array(valorantMapPick).nullable().optional(), match_type: matchType, modified_at: matchModifiedAt, name: matchName, number_of_games: gameCount, opponents: opponents, original_scheduled_at: z.string().min(1).nullable(), rescheduled: z.boolean().nullable(), results: matchResults, scheduled_at: z.string().min(1).nullable(), serie: baseSerie, serie_id: serieID, slug: z.string().min(1).nullable(), status: matchStatus, streams_list: streamsList, tournament: baseTournament, tournament_id: tournamentID, videogame: currentVideogame, videogame_version: z.object({current: videogameVersionIsCurrent, name: videogameVersion}).nullable(), winner: z.union([z.object({active: playerIsActive, age: z.number().gte(0).nullable(), birthday: z.string().nullable(), first_name: z.string().nullable(), id: playerID, image_url: z.string().nullable(), last_name: z.string().nullable(), modified_at: playerModifiedAt, name: playerName, nationality: z.string().nullable(), role: z.string().nullable(), slug: z.string().min(1).nullable()}).nullable(), z.object({acronym: z.string().nullable(), dark_mode_image_url: z.string().nullable(), id: teamID, image_url: z.string().nullable(), location: z.string().nullable(), modified_at: teamModifiedAt, name: teamName, slug: z.string().min(1).nullable()}).nullable()]), winner_id: z.union([z.number().int().gte(1).nullable(), z.number().int().gte(1).nullable()]), winner_type: matchWinnerType}); export const cSGOGamePlayer = z.object({adr: z.number().gte(0).nullable(), assists: z.number().int().gte(0).nullable(), deaths: z.number().int().gte(0).nullable(), first_kills_diff: z.number().int().nullable(), flash_assists: z.number().gte(0).nullable(), game_id: cSGOGameID, headshots: z.number().int().gte(0).nullable(), k_d_diff: z.number().int().nullable(), kast: z.number().gte(0).nullable(), kills: z.number().int().gte(0).nullable(), opponent: baseOpponent, player: basePlayer, rating: z.number().gte(0).nullable(), team: baseTeam}); export const cSGOOutcome = z.enum(["defused", "eliminated", "exploded", "planted_eliminated", "timeout"]); export const cSGORoundID = z.number().int().gte(1); export const cSGOSide = z.enum(["ct", "terrorists"]); export const cSGORound = z.object({ct: teamID, outcome: cSGOOutcome, round: cSGORoundID, terrorists: teamID, winner_side: cSGOSide, winner_team: teamID}); export const cSGORoundScore = z.number().int().gte(0); export const cSGORoundsScore = z.object({score: cSGORoundScore, team_id: teamID}); export const cSGORoundsScores = z.array(cSGORoundsScore); export const cSGOGame = z.object({begin_at: z.string().min(1).nullable(), complete: gameComplete, detailed_stats: gameDetailedStats, end_at: z.string().min(1).nullable(), finished: gameIsFinished, forfeit: gameIsForfeit, id: cSGOGameID, length: z.number().int().gte(0).nullable(), map: z.object({id: cSGOMapID, image_url: z.string().nullable(), name: cSGOMapName, slug: cSGOMapSlug}).nullable(), match: fullGameMatch, match_id: matchID, players: z.array(cSGOGamePlayer).nullable(), position: gamePosition, rounds: z.array(cSGORound).nullable(), rounds_score: cSGORoundsScores, status: gameStatus, teams: z.array(baseTeam).nullable(), winner: gameWinner, winner_type: z.enum(["Player", "Team"]).nullable()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get a game * * GET /csgo/games/{csgo_game_id} * * Also accepts auth: QueryToken */ export const getApiCsgoGamesCsgoGameId = async (args: GetApiCsgoGamesCsgoGameIdArgs, options?: GetApiCsgoGamesCsgoGameIdOptions) => { const {baseUrl = "https://api.pandascore.co", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/csgo/games/${encodeURIComponent(String(args.csgo_game_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(cSGOGame, await res.json()) };