import {z} from 'zod' export type ClientBrandingRequest = {account: string}; export type CreateApiAccountsClientBrandingArgs = {body: ClientBrandingRequest}; export type CreateApiAccountsClientBrandingOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const clientBranding = z.object({account: z.string().optional(), display_name: z.string().optional(), app_name: z.string().optional(), primary_color: z.string().optional(), secondary_color: z.string().optional(), logo_data_uri: z.string().optional(), favicon_data_uri: z.string().optional(), favicon_dark_data_uri: z.string().optional(), ui_theme: z.record(z.string(), z.unknown()).optional()}); export const createApiAccountsClientBrandingResponse = z.object({data: clientBranding}); 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 sign-in branding * * POST /accounts/client-branding */ export const createApiAccountsClientBranding = async (args: CreateApiAccountsClientBrandingArgs, options?: CreateApiAccountsClientBrandingOptions) => { const {baseUrl = "https://api.quiva.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/accounts/client-branding${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(createApiAccountsClientBrandingResponse, await res.json()) };