import {z} from 'zod' export type GetApiScoreSetScoreSetSlugArgs = {Accept: 'application/vnd.Creative Force.v2.3+json' | 'application/vnd.Creative Force.v2.3+xml', 'x-api-language'?: (Array<'all' | 'ar_AR' | 'bg_BG' | 'bn_IN' | 'ca_ES' | 'cs_CZ' | 'cy_GB' | 'da_DK' | 'de_DE' | 'en_GB' | 'en_US' | 'el_GR' | 'es_NN' | 'es_LA' | 'et_EE' | 'fa_NN' | 'fi_FI' | 'fr_FR' | 'fr_CA' | 'he_IL' | 'hi_IN' | 'hr_HR' | 'hu_HU' | 'hy_AM' | 'it_IT' | 'ja_JP' | 'ko_KR' | 'lt_LT' | 'ms_MY' | 'nl_NL' | 'nb_NO' | 'pl_PL' | 'pt_BR' | 'ro_RO' | 'ru_RU' | 'sk_SK' | 'sl_SI' | 'sq_AL' | 'sr_RS' | 'sv_SE' | 'sw_NN' | 'th_TH' | 'tr_TR' | 'uk_UA' | 'vi_VN' | 'zh_CN' | 'zh_HK'>) | undefined}; export type GetApiScoreSetScoreSetSlugOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const scoreSet = z.object({created: z.string().optional(), form: z.string().optional(), mode: z.enum(["qualifying", "top_pick", "vip_judging", "voting", "gallery"]).optional(), name: z.record(z.string(), z.string()).optional(), order: z.number().int().nullable().optional(), season: z.object({slug: z.string().optional(), link: z.string().optional(), name: z.record(z.string(), z.string()).optional()}).optional(), slug: z.string().optional(), updated: z.string().optional()}); 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 }; /** * Retrieve a score set * * GET /score-set/{score_set_slug} */ export const getApiScoreSetScoreSetSlug = async (args: GetApiScoreSetScoreSetSlugArgs, options?: GetApiScoreSetScoreSetSlugOptions) => { const {baseUrl = "https://api.us.cr4ce.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['x-api-language'] != null) headers.set("x-api-language", args['x-api-language'].join(',')) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/score-set/${encodeURIComponent(String(args.score_set_slug))}${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(scoreSet, await res.json()) };