import {z} from 'zod' export type GetApiApiV1AccountAuthIdApplicationArgs = {auth_id: string, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiV1AccountAuthIdApplicationOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1AccountAuthIdApplicationResponse = z.object({api_id: z.string(), meta: z.object({limit: z.number().int(), next: z.string(), offset: z.number().int(), previous: z.unknown(), total_count: z.number().int()}), objects: z.array(z.object({answer_method: z.string(), answer_url: z.string(), app_id: z.string(), app_name: z.string(), application_type: z.string(), created_at: z.string(), default_app: z.boolean(), default_endpoint_app: z.boolean(), enabled: z.boolean(), fallback_answer_url: z.string().nullable(), fallback_method: z.string(), hangup_method: z.string(), hangup_url: z.string(), log_incoming_message: z.boolean(), message_method: z.string(), message_url: z.string().nullable(), public_uri: z.boolean(), resource_uri: z.string(), sip_transfer_method: z.string(), sip_transfer_url: z.unknown(), sip_uri: z.string(), sub_account: z.unknown(), updated_at: z.string()}))}); 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 All Applications * * GET /api/v1/Account/{auth_id}/Application/ */ export const getApiApiV1AccountAuthIdApplication = async (args: GetApiApiV1AccountAuthIdApplicationArgs, options?: GetApiApiV1AccountAuthIdApplicationOptions) => { const {baseUrl = "https://api.vobiz.ai", fetch: fetchFn = fetch, AuthID, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (AuthID !== undefined) headers.set("X-Auth-ID", AuthID) if (AuthToken !== undefined) headers.set("X-Auth-Token", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/Account/${encodeURIComponent(String(args.auth_id))}/Application/${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(getApiApiV1AccountAuthIdApplicationResponse, await res.json()) };