import {z} from 'zod' export type MatchBeginAt = string; export type MatchDetailedStats = boolean; export type MatchIsDraw = boolean; export type MatchEndAt = string; export type MatchIsForfeit = boolean; export type MatchID = number; export type LeagueID = number; export type MatchType = 'all_games_played' | 'best_of' | 'custom' | 'first_to' | 'ow_best_of' | 'red_bull_home_ground'; export type MatchModifiedAt = string; export type MatchName = string; export type GameCount = number; export type TeamID = number; export type TeamSlug = string; export type TeamIDOrSlug = TeamID | TeamSlug; export type PlayerID = number; export type PlayerSlug = string; export type PlayerIDOrSlug = PlayerID | PlayerSlug; export type MatchScheduledAt = string; export type SerieID = number; export type MatchSlug = string; export type MatchStatus = 'canceled' | 'finished' | 'not_started' | 'postponed' | 'running'; export type TournamentID = number; export type VideogameID = 1 | 3 | 4 | 14 | 20 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36; export type VideogameSlug = 'cod-mw' | 'cs-go' | 'dota-2' | 'e-basketball' | 'e-cricket' | 'e-hockey' | 'e-soccer' | 'e-tennis' | 'fifa' | 'kog' | 'league-of-legends' | 'lol-wild-rift' | 'mlbb' | 'ow' | 'pubg' | 'r6-siege' | 'rl' | 'starcraft-2' | 'starcraft-brood-war' | 'valorant'; export type VideogameIDOrSlug = VideogameID | VideogameSlug; export type VideogameTitleID = number; export type VideogameTitleSlug = string; export type VideogameVersion = string; export type OpponentID = PlayerID | TeamID; export type MatchWinnerType = 'Player' | 'Team'; export type FilterOverKogMatches = {begin_at?: Array | undefined, detailed_stats?: MatchDetailedStats | undefined, draw?: MatchIsDraw | undefined, end_at?: Array | undefined, finished?: boolean | undefined, forfeit?: MatchIsForfeit | undefined, future?: boolean | undefined, id?: Array | undefined, league_id?: Array | undefined, low_latency_feed?: boolean | undefined, match_type?: Array | undefined, modified_at?: Array | undefined, name?: Array | undefined, not_started?: boolean | undefined, number_of_games?: Array | undefined, opponent_id?: (Array) | undefined, opponents_filled?: boolean | undefined, past?: boolean | undefined, running?: boolean | undefined, scheduled_at?: Array | undefined, serie_id?: Array | undefined, slug?: Array | undefined, status?: Array | undefined, tournament_id?: Array | undefined, unscheduled?: boolean | undefined, videogame?: Array | undefined, videogame_title?: (Array) | undefined, videogame_version?: (Array) | undefined, winner_id?: Array | undefined, winner_type?: Array | undefined}; export type RangeOverKogMatches = {begin_at?: Array | undefined, detailed_stats?: Array | undefined, draw?: Array | undefined, end_at?: Array | undefined, forfeit?: Array | undefined, id?: Array | undefined, match_type?: Array | undefined, modified_at?: Array | undefined, name?: Array | undefined, number_of_games?: Array | undefined, scheduled_at?: Array | undefined, slug?: Array | undefined, status?: Array | undefined, tournament_id?: Array | undefined, winner_id?: Array | undefined, winner_type?: Array | undefined}; export type SortOverKogMatches = Array<'begin_at' | '-begin_at' | 'detailed_stats' | '-detailed_stats' | 'draw' | '-draw' | 'end_at' | '-end_at' | 'forfeit' | '-forfeit' | 'id' | '-id' | 'match_type' | '-match_type' | 'modified_at' | '-modified_at' | 'name' | '-name' | 'number_of_games' | '-number_of_games' | 'scheduled_at' | '-scheduled_at' | 'slug' | '-slug' | 'status' | '-status' | 'tournament_id' | '-tournament_id' | 'winner_id' | '-winner_id' | 'winner_type' | '-winner_type'>; export type SearchOverKogMatches = {match_type?: MatchType | undefined, name?: MatchName | undefined, slug?: MatchSlug | undefined, status?: MatchStatus | undefined, winner_type?: MatchWinnerType | undefined}; export type GetApiKogMatchesRunningArgs = {filter?: FilterOverKogMatches | undefined, range?: RangeOverKogMatches | undefined, sort?: SortOverKogMatches | undefined, search?: SearchOverKogMatches | undefined, page?: (number | {number?: number | undefined, size?: number | undefined}) | undefined, per_page?: number | undefined}; export type GetApiKogMatchesRunningOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const matchDetailedStats = z.boolean(); export const matchIsDraw = z.boolean(); export const matchIsForfeit = z.boolean(); export const gameComplete = z.boolean(); export const gameDetailedStats = z.boolean(); export const gameIsFinished = z.boolean(); export const gameIsForfeit = z.boolean(); export const loLGameID = z.number().int().gte(1); export const cSGOGameID = 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 videogameTitleID = z.number().int().gte(1); export const videogameTitleName = z.string(); export const videogameTitleSlug = z.string().min(1); export const videogameID = z.union([z.literal(1), z.literal(3), z.literal(4), z.literal(14), z.literal(20), z.literal(22), z.literal(23), z.literal(24), z.literal(25), z.literal(26), z.literal(27), z.literal(28), z.literal(29), z.literal(30), z.literal(31), z.literal(32), z.literal(33), z.literal(34), z.literal(35), z.literal(36)]); export const videogameVersionIsCurrent = z.boolean(); export const matchWinnerType = z.enum(["Player", "Team"]); export const match = 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_title: z.object({id: videogameTitleID, name: videogameTitleName, slug: videogameTitleSlug, videogame_id: videogameID}).nullable(), 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 kogMatches = z.array(match); 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 running King of Glory matches * * GET /kog/matches/running * * Also accepts auth: QueryToken */ export const getApiKogMatchesRunning = async (args: GetApiKogMatchesRunningArgs, options?: GetApiKogMatchesRunningOptions) => { 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 (args.filter != null) query.append("filter", JSON.stringify(args.filter)) if (args.range != null) query.append("range", JSON.stringify(args.range)) for (const item of args.sort ?? []) query.append("sort", String(item)) if (args.search != null) query.append("search", JSON.stringify(args.search)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/kog/matches/running${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(kogMatches, await res.json()) };