import {z} from 'zod' export type GetApiV1AccountConnectionsListArgs = {page?: number | undefined, size?: number | undefined, sort_column?: (string | null) | undefined, sort_desc?: (boolean | null) | undefined}; export type GetApiV1AccountConnectionsListOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const twilioCredentials = z.object({twilio_account_sid: z.string(), twilio_auth_token: z.string()}); export const twilioAccountConnection = z.object({id: z.string(), user_id: z.string(), credentials: twilioCredentials, type: z.literal("account_connection_twilio"), steering_pool: z.array(z.string()).optional(), account_supports_any_caller_id: z.boolean().optional()}); export const openAICredentials = z.object({openai_api_key: z.string()}); export const openAIAccountConnection = z.object({id: z.string(), user_id: z.string(), credentials: openAICredentials, type: z.literal("account_connection_openai")}); export const accountConnectionPage = z.object({items: z.array(z.discriminatedUnion("type", [twilioAccountConnection, openAIAccountConnection])), page: z.number().int(), size: z.number().int(), has_more: z.boolean(), total: z.number().int(), total_is_estimated: z.boolean()}); 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 }; /** * List Account Connections * * GET /v1/account_connections/list */ export const getApiV1AccountConnectionsList = async (args: GetApiV1AccountConnectionsListArgs, options?: GetApiV1AccountConnectionsListOptions) => { const {baseUrl = "https://api.vocode.dev", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) if (args.sort_column != null) query.append("sort_column", String(args.sort_column)) if (args.sort_desc != null) query.append("sort_desc", String(args.sort_desc)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/account_connections/list${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(accountConnectionPage, await res.json()) };