import {z} from 'zod' export type GetApi3AccountAccountIdListsArgs = {account_id: number, page?: number | undefined, session_id?: string | undefined}; export type GetApi3AccountAccountIdListsOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApi3AccountAccountIdListsResponse = z.object({page: z.number().int().optional(), results: z.array(z.object({description: z.string().optional(), favorite_count: z.number().int().optional(), id: z.number().int().optional(), item_count: z.number().int().optional(), iso_639_1: z.string().optional(), list_type: z.string().optional(), name: z.string().optional(), poster_path: z.unknown()})).optional(), total_pages: z.number().int().optional(), total_results: 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 }; /** * Lists * * GET /3/account/{account_id}/lists */ export const getApi3AccountAccountIdLists = async (args: GetApi3AccountAccountIdListsArgs, options?: GetApi3AccountAccountIdListsOptions) => { const {baseUrl = "https://api.themoviedb.org", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.session_id != null) query.append("session_id", String(args.session_id)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/3/account/${encodeURIComponent(String(args.account_id))}/lists${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(getApi3AccountAccountIdListsResponse, await res.json()) };