import {z} from 'zod' export type GameCreateUpdate = {id?: number | undefined, steam_id?: (string | null) | undefined, title: string, slug: unknown, description?: string | undefined, description_short?: string | undefined, description_fr?: string | undefined, header?: (string | null) | undefined, background?: (string | null) | undefined, video?: string | undefined, screenshots?: Record | undefined, developer?: string | undefined, publisher?: string | undefined, requirements?: Record | undefined, source?: Record | undefined, views?: number | undefined, likes?: number | undefined, favorites_count?: number | undefined, downloads_count?: number | undefined, release_date?: (string | null) | undefined, published_at?: string | undefined, updated_at?: string | undefined, is_published?: boolean | undefined, categories?: Array | undefined, tags?: Array | undefined}; export type UpdateApiApiAppGamesIdArgs = {body: GameCreateUpdate}; export type UpdateApiApiAppGamesIdOptions = {baseUrl?: string | undefined, Basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const gameCreateUpdate = z.object({id: z.number().int().optional(), steam_id: z.string().max(20).nullable().optional(), title: z.string().min(1).max(255), slug: z.string().min(1).max(255), description: z.string().optional(), description_short: z.string().max(500).optional(), description_fr: z.string().optional(), header: z.string().nullable().optional(), background: z.string().nullable().optional(), video: z.string().max(200).optional(), screenshots: z.object({}).optional(), developer: z.string().max(255).optional(), publisher: z.string().max(255).optional(), requirements: z.object({}).optional(), source: z.object({}).optional(), views: z.number().int().gte(0).lte(2147483647).optional(), likes: z.number().int().gte(0).lte(2147483647).optional(), favorites_count: z.number().int().gte(0).lte(2147483647).optional(), downloads_count: z.number().int().gte(0).lte(2147483647).optional(), release_date: z.string().nullable().optional(), published_at: z.string().optional(), updated_at: z.string().optional(), is_published: z.boolean().optional(), categories: z.array(z.number().int()).optional(), tags: z.array(z.number().int()).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 }; /** * API principale du catalogue de jeux * * PUT /api/app/games/{id}/ */ export const updateApiApiAppGamesId = async (args: UpdateApiApiAppGamesIdArgs, options?: UpdateApiApiAppGamesIdOptions) => { const {baseUrl = "https://api.jeuxcracks.fr", fetch: fetchFn = fetch, Basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Basic !== undefined) headers.set('authorization', `Basic ${btoa(`${Basic.username}:${Basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/app/games/${encodeURIComponent(String(args.id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(gameCreateUpdate, await res.json()) };