import {z} from 'zod' export type GetApiApiV1AccountAuthIdCdrExportArgs = {auth_id: string, from_number?: string | undefined, to_number?: string | undefined, start_date?: string | undefined, end_date?: string | undefined, call_direction?: ('inbound' | 'outbound') | undefined, min_duration?: number | undefined, sip_call_id?: string | undefined, bridge_uuid?: string | undefined, hangup_cause?: string | undefined, hangup_disposition?: string | undefined, context?: string | undefined, campaign_id?: string | undefined, search?: string | undefined}; export type GetApiApiV1AccountAuthIdCdrExportOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1AccountAuthIdCdrExportResponse = 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 }; /** * Export CDRs as CSV * * GET /api/v1/Account/{auth_id}/cdr/export */ export const getApiApiV1AccountAuthIdCdrExport = async (args: GetApiApiV1AccountAuthIdCdrExportArgs, options?: GetApiApiV1AccountAuthIdCdrExportOptions) => { 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.from_number != null) query.append("from_number", String(args.from_number)) if (args.to_number != null) query.append("to_number", String(args.to_number)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.call_direction != null) query.append("call_direction", String(args.call_direction)) if (args.min_duration != null) query.append("min_duration", String(args.min_duration)) if (args.sip_call_id != null) query.append("sip_call_id", String(args.sip_call_id)) if (args.bridge_uuid != null) query.append("bridge_uuid", String(args.bridge_uuid)) if (args.hangup_cause != null) query.append("hangup_cause", String(args.hangup_cause)) if (args.hangup_disposition != null) query.append("hangup_disposition", String(args.hangup_disposition)) if (args.context != null) query.append("context", String(args.context)) if (args.campaign_id != null) query.append("campaign_id", String(args.campaign_id)) if (args.search != null) query.append("search", String(args.search)) 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/export${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(getApiApiV1AccountAuthIdCdrExportResponse, await res.json()) };