import {z} from 'zod' export type AvatarLightPayload = {avatar_id?: string | undefined, preset_light?: string | undefined, light_direction?: string | undefined, ambient_light_color?: string | undefined, ambient_light_intensity?: number | undefined, background_color?: string | undefined, background_image?: string | undefined, point_light_color?: string | undefined, point_light_decay?: number | undefined, point_light_intensity?: number | undefined, spot_light_color?: string | undefined, spot_light_decay?: number | undefined, spot_light_intensity?: number | undefined, spot_light_penumbra?: number | undefined, spot_light_position_x?: number | undefined, spot_light_position_y?: number | undefined, spot_light_position_z?: number | undefined}; export type CreateApiAvatarAvatarIdLightArgs = {avatar_id: string, team_id?: string | undefined, body: AvatarLightPayload}; export type CreateApiAvatarAvatarIdLightOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const avatarLightCustomization = z.object({id: z.string().optional(), date_created: z.string().optional(), date_updated: z.string().optional(), avatar_id: z.string().optional(), preset_light: z.string().optional(), light_direction: z.string().optional(), ambient_light_color: z.string().optional(), ambient_light_intensity: z.number().optional(), background_color: z.string().optional(), background_image: z.string().optional(), point_light_color: z.string().optional(), point_light_decay: z.number().optional(), point_light_intensity: z.number().optional(), spot_light_color: z.string().optional(), spot_light_decay: z.number().optional(), spot_light_intensity: z.number().optional(), spot_light_penumbra: z.number().optional(), spot_light_position_x: z.number().optional(), spot_light_position_y: z.number().optional(), spot_light_position_z: z.number().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 }; /** * Create Avatar Light Customization * * POST /avatar/{avatar_id}/light * * Also accepts auth: OAuth2PasswordBearer */ export const createApiAvatarAvatarIdLight = async (args: CreateApiAvatarAvatarIdLightArgs, options: CreateApiAvatarAvatarIdLightOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.team_id != null) query.append("team_id", String(args.team_id)) if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/avatar/${encodeURIComponent(String(args.avatar_id))}/light${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(avatarLightCustomization, await res.json()) };