import {z} from 'zod' export type GetApiV3AvatarsLooksLookIdArgs = {look_id: string}; export type GetApiV3AvatarsLooksLookIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const avatarLookType = z.enum(["studio_avatar", "digital_twin", "photo_avatar"]); export const avatarStatus = z.enum(["processing", "pending_consent", "failed", "completed"]); export const avatarError = z.object({code: z.string(), message: z.string()}); export const avatarLookItem = z.object({id: z.string(), name: z.string(), avatar_type: avatarLookType, group_id: z.string().nullable().optional(), preview_image_url: z.string().nullable().optional(), preview_video_url: z.string().nullable().optional(), gender: z.string().nullable().optional(), tags: z.array(z.string()).optional(), default_voice_id: z.string().nullable().optional(), supported_api_engines: z.array(z.string()).optional(), image_width: z.number().int().nullable().optional(), image_height: z.number().int().nullable().optional(), preferred_orientation: z.enum(["portrait", "landscape", "square"]).nullable().optional(), status: avatarStatus.nullable().optional(), error: avatarError.nullable().optional()}); export const getApiV3AvatarsLooksLookIdResponse = z.object({data: avatarLookItem.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 }; /** * Get Avatar Look * * GET /v3/avatars/looks/{look_id} * * Also accepts auth: BearerAuth */ export const getApiV3AvatarsLooksLookId = async (args: GetApiV3AvatarsLooksLookIdArgs, options?: GetApiV3AvatarsLooksLookIdOptions) => { const {baseUrl = "https://api.heygen.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v3/avatars/looks/${encodeURIComponent(String(args.look_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(getApiV3AvatarsLooksLookIdResponse, await res.json()) };