import {z} from 'zod' export type GetApiApiV1AccountAuthIdCdrRecentArgs = {auth_id: string, limit?: number | undefined}; export type GetApiApiV1AccountAuthIdCdrRecentOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1AccountAuthIdCdrRecentResponse = z.object({account_id: z.string(), count: z.number().int(), data: z.array(z.object({account_id: z.string(), answer_time: z.string().nullable(), billsec: z.number().int(), bridge_uuid: z.string().nullable(), call_direction: z.string(), caller_id_name: z.string(), caller_id_number: z.string(), campaign_id: z.unknown(), carrier_ip: z.unknown(), codec: z.string().nullable(), context: z.string(), cost: z.number(), created_at: z.string(), currency: z.string(), customer_endpoint: z.unknown(), destination_number: z.string(), duration: z.number().int(), end_time: z.string(), failure_code: z.string().nullable(), failure_reason: z.string().nullable(), hangup_cause: z.string().nullable(), hangup_cause_code: z.number().int().nullable(), hangup_cause_name: z.string().nullable(), hangup_disposition: z.string().nullable(), hangup_source: z.string().nullable(), id: z.number().int(), jitter: z.number().nullable(), mos: z.number().nullable(), network_addr: z.string().nullable(), origination_region: z.string(), packet_loss: z.number().nullable(), progress_time: z.string().nullable(), region: z.string(), ring_time: z.number().int(), sip_call_id: z.string(), sip_user_agent: z.string().nullable(), start_time: z.string(), streaming_cost: z.number(), terminated_to: z.string().nullable(), total_cost: z.number(), trunk_id: z.string().nullable(), updated_at: z.string(), uuid: z.string()})), success: 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 }; /** * Get the most recent CDRs * * GET /api/v1/Account/{auth_id}/cdr/recent */ export const getApiApiV1AccountAuthIdCdrRecent = async (args: GetApiApiV1AccountAuthIdCdrRecentArgs, options?: GetApiApiV1AccountAuthIdCdrRecentOptions) => { 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 (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))}/cdr/recent${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(getApiApiV1AccountAuthIdCdrRecentResponse, await res.json()) };