import {z} from 'zod' export type CreateApiV1BrandKitsArgs = {body: {name: string, logo_asset_id?: string | undefined, logo_url?: string | undefined, primary_color?: string | undefined, secondary_color?: string | undefined, tertiary_color?: string | undefined, accent_color?: string | undefined, title_font?: string | undefined, body_font?: string | undefined, motion_style?: ('elevated' | 'friendly' | 'minimal' | 'professional' | 'playful') | undefined, brand_identity?: string | undefined}}; export type CreateApiV1BrandKitsOptions = {baseUrl?: string | undefined, ApiKeyBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const brandKit = z.object({object: z.string().optional(), brand_ref: z.string().optional(), name: z.string().optional(), logo_url: z.string().optional(), logo_asset_id: z.string().optional(), primary_color: z.string().optional(), secondary_color: z.string().optional(), tertiary_color: z.string().optional(), accent_color: z.string().optional(), title_font: z.string().optional(), body_font: z.string().optional(), motion_style: z.string().optional(), brand_identity: 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 }; /** * Create a brand kit * * POST /v1/brand-kits */ export const createApiV1BrandKits = async (args: CreateApiV1BrandKitsArgs, options?: CreateApiV1BrandKitsOptions) => { const {baseUrl = "https://api.vivideo.ai", fetch: fetchFn = fetch, ApiKeyBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyBearer !== undefined) headers.set('authorization', `Bearer ${ApiKeyBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/brand-kits${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(brandKit, await res.json()) };