import {z} from 'zod' export type GetApi3PersonPersonIdArgs = {person_id: number, append_to_response?: string | undefined, language?: string | undefined}; export type GetApi3PersonPersonIdOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApi3PersonPersonIdResponse = z.object({adult: z.boolean().optional(), also_known_as: z.array(z.string()).optional(), biography: z.string().optional(), birthday: z.string().optional(), deathday: z.unknown(), gender: z.number().int().optional(), homepage: z.unknown(), id: z.number().int().optional(), imdb_id: z.string().optional(), known_for_department: z.string().optional(), name: z.string().optional(), place_of_birth: z.string().optional(), popularity: z.number().optional(), profile_path: 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 }; /** * Details * * GET /3/person/{person_id} */ export const getApi3PersonPersonId = async (args: GetApi3PersonPersonIdArgs, options?: GetApi3PersonPersonIdOptions) => { 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.append_to_response != null) query.append("append_to_response", String(args.append_to_response)) if (args.language != null) query.append("language", String(args.language)) if (sec0 !== undefined) headers.set("Authorization", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/3/person/${encodeURIComponent(String(args.person_id))}${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(getApi3PersonPersonIdResponse, await res.json()) };