import {z} from 'zod' export type TournamentBeginAt = string; export type TournamentCountry = string; export type TournamentDetailedStats = boolean; export type TournamentEndAt = string; export type TournamentHasBracket = boolean; export type TournamentID = number; export type TournamentLiveSupported = boolean; export type TournamentModifiedAt = string; export type TournamentName = string; export type TournamentPrizepool = string; export type TournamentRegion = 'AF' | 'ASIA' | 'EEU' | 'ME' | 'NA' | 'OCE' | 'SA' | 'WEU'; export type SerieID = number; export type TournamentSlug = string; export type TournamentTier = 'a' | 'b' | 'c' | 'd' | 's' | 'unranked'; export type VideogameTitleID = number; export type VideogameTitleSlug = string; export type PlayerID = number; export type TeamID = number; export type OpponentID = PlayerID | TeamID; export type OpponentType = 'Player' | 'Team'; export type FilterOverShortTournaments = {begin_at?: Array | undefined, country?: Array | undefined, detailed_stats?: TournamentDetailedStats | undefined, end_at?: Array | undefined, has_bracket?: TournamentHasBracket | undefined, id?: Array | undefined, live_supported?: TournamentLiveSupported | undefined, modified_at?: Array | undefined, name?: Array | undefined, prizepool?: Array | undefined, region?: Array | undefined, serie_id?: Array | undefined, slug?: Array | undefined, tier?: Array | undefined, videogame_title?: (Array) | undefined, winner_id?: Array | undefined, winner_type?: Array | undefined}; export type RangeOverShortTournaments = {begin_at?: Array | undefined, country?: Array | undefined, detailed_stats?: Array | undefined, end_at?: Array | undefined, has_bracket?: Array | undefined, id?: Array | undefined, modified_at?: Array | undefined, name?: Array | undefined, prizepool?: Array | undefined, region?: Array | undefined, serie_id?: Array | undefined, slug?: Array | undefined, tier?: Array | undefined, winner_id?: Array | undefined, winner_type?: Array | undefined}; export type SortOverShortTournaments = Array<'begin_at' | '-begin_at' | 'country' | '-country' | 'detailed_stats' | '-detailed_stats' | 'end_at' | '-end_at' | 'has_bracket' | '-has_bracket' | 'id' | '-id' | 'modified_at' | '-modified_at' | 'name' | '-name' | 'prizepool' | '-prizepool' | 'region' | '-region' | 'serie_id' | '-serie_id' | 'slug' | '-slug' | 'tier' | '-tier' | 'winner_id' | '-winner_id' | 'winner_type' | '-winner_type'>; export type SearchOverShortTournaments = {country?: TournamentCountry | undefined, name?: TournamentName | undefined, prizepool?: TournamentPrizepool | undefined, region?: TournamentRegion | undefined, slug?: TournamentSlug | undefined, tier?: TournamentTier | undefined, winner_type?: OpponentType | undefined}; export type GetApiTournamentsPastArgs = {filter?: FilterOverShortTournaments | undefined, range?: RangeOverShortTournaments | undefined, sort?: SortOverShortTournaments | undefined, search?: SearchOverShortTournaments | undefined, page?: (number | {number?: number | undefined, size?: number | undefined}) | undefined, per_page?: number | undefined}; export type GetApiTournamentsPastOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const tournamentDetailedStats = z.boolean(); 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 basePlayers = z.array(basePlayer); 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 tournamentRosterItem = z.object({players: basePlayers, team: baseTeam}); export const tournamentRosterItems = z.array(tournamentRosterItem); export const tournamentHasBracket = z.boolean(); export const tournamentID = z.number().int().gte(1); 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 tournamentLiveSupported = z.boolean(); export const matchDetailedStats = z.boolean(); export const matchIsDraw = z.boolean(); export const matchIsForfeit = z.boolean(); export const matchID = z.number().int().gte(1); 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 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 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 matchWinnerType = z.enum(["Player", "Team"]); export const baseMatch = 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(), id: matchID, live: matchLive, low_latency_feed: matchHasLowLatencyFeed.optional(), match_type: matchType, modified_at: matchModifiedAt, name: matchName, number_of_games: gameCount, original_scheduled_at: z.string().min(1).nullable(), rescheduled: z.boolean().nullable(), scheduled_at: z.string().min(1).nullable(), slug: z.string().min(1).nullable(), status: matchStatus, streams_list: streamsList, tournament_id: tournamentID, winner_id: z.union([z.number().int().gte(1).nullable(), z.number().int().gte(1).nullable()]), winner_type: matchWinnerType}); export const baseMatches = z.array(baseMatch); export const tournamentModifiedAt = z.string().min(1); export const tournamentName = z.string(); 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 tournamentSlug = z.string().min(1); export const baseTeams = z.array(baseTeam); 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 shortTournament = z.object({begin_at: z.string().min(1).nullable(), country: z.string().nullable(), detailed_stats: tournamentDetailedStats, end_at: z.string().min(1).nullable(), expected_roster: tournamentRosterItems, has_bracket: tournamentHasBracket, id: tournamentID, league: baseLeague, league_id: leagueID, live_supported: tournamentLiveSupported, matches: baseMatches, modified_at: tournamentModifiedAt, name: tournamentName, prizepool: z.string().nullable(), region: z.enum(["AF", "ASIA", "EEU", "ME", "NA", "OCE", "SA", "WEU"]).nullable(), serie: baseSerie, serie_id: serieID, slug: tournamentSlug, teams: baseTeams, tier: z.enum(["a", "b", "c", "d", "s", "unranked"]).nullable(), type: z.enum(["offline", "online", "online/offline"]).nullable(), videogame: currentVideogame, videogame_title: z.object({id: videogameTitleID, name: videogameTitleName, slug: videogameTitleSlug, videogame_id: videogameID}).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 shortTournaments = z.array(shortTournament); 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 past tournaments * * GET /tournaments/past * * Also accepts auth: QueryToken */ export const getApiTournamentsPast = async (args: GetApiTournamentsPastArgs, options?: GetApiTournamentsPastOptions) => { 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(/\/+$/, '')}/tournaments/past${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(shortTournaments, await res.json()) };