import {z} from 'zod' export type GetApiApiAppGamesIdRelatedArgs = {limit?: number | undefined}; export type GetApiApiAppGamesIdRelatedOptions = {baseUrl?: string | undefined, Basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const gameList = z.object({id: z.number().int().optional(), title: z.string().min(1).max(255), slug: z.string().min(1).max(255), header: z.string().nullable().optional(), categories: z.array(z.string()).optional(), views: z.number().int().gte(0).lte(2147483647).optional(), likes: z.number().int().gte(0).lte(2147483647).optional(), is_liked: z.string().optional(), is_favorited: z.string().optional(), versions_count: z.string().optional(), latest_version: z.string().optional(), is_online: z.boolean().optional(), published_at: z.string().optional()}); export const getApiApiAppGamesIdRelatedResponse = z.array(gameList); 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 }; /** * Jeux similaires pour le maillage interne SEO * * GET /api/app/games/{id}/related/ */ export const getApiApiAppGamesIdRelated = async (args: GetApiApiAppGamesIdRelatedArgs, options?: GetApiApiAppGamesIdRelatedOptions) => { const {baseUrl = "https://api.jeuxcracks.fr", fetch: fetchFn = fetch, Basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (Basic !== undefined) headers.set('authorization', `Basic ${btoa(`${Basic.username}:${Basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/app/games/${encodeURIComponent(String(args.id))}/related/${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(getApiApiAppGamesIdRelatedResponse, await res.json()) };