import {z} from 'zod' export type GetApiApiV1AccountAuthIdCdrCallIdArgs = {auth_id: string, call_id: string}; export type GetApiApiV1AccountAuthIdCdrCallIdOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1AccountAuthIdCdrCallIdResponse = z.object({data: z.object({account_id: z.string(), answer_time: z.string(), billsec: z.number().int(), bridge_uuid: z.string(), 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(), 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.unknown(), failure_reason: z.unknown(), hangup_cause: z.string(), hangup_cause_code: z.number().int(), hangup_cause_name: z.string(), hangup_disposition: z.string(), hangup_source: z.string(), id: z.number().int(), jitter: z.number(), mos: z.number(), network_addr: z.string(), origination_region: z.string(), packet_loss: z.number().int(), progress_time: z.string(), region: z.string(), ring_time: z.number().int(), sip_call_id: z.string(), sip_user_agent: z.string(), start_time: z.string(), streaming_cost: z.number().int(), terminated_to: z.unknown(), total_cost: z.number(), trunk_id: z.unknown(), 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 }; /** * Retrieve a CDR by call ID * * GET /api/v1/Account/{auth_id}/cdr/{call_id} */ export const getApiApiV1AccountAuthIdCdrCallId = async (args: GetApiApiV1AccountAuthIdCdrCallIdArgs, options?: GetApiApiV1AccountAuthIdCdrCallIdOptions) => { 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 (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/${encodeURIComponent(String(args.call_id))}${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(getApiApiV1AccountAuthIdCdrCallIdResponse, await res.json()) };