import {z} from 'zod' export type GetApiApiV1PartnerAccountsCustomerAuthIdCdrsArgs = {customer_auth_id: string, start_date?: string | undefined, end_date?: string | undefined, call_direction?: ('inbound' | 'outbound') | undefined, status?: ('answered' | 'failed' | 'busy' | 'no_answer') | undefined, min_duration?: number | undefined, hangup_cause?: string | undefined, per_page?: number | undefined}; export type GetApiApiV1PartnerAccountsCustomerAuthIdCdrsOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1PartnerAccountsCustomerAuthIdCdrsResponse = z.object({account_id: z.string(), count: z.number().int(), data: z.array(z.unknown()), pagination: z.object({page: z.number().int(), per_page: z.number().int(), total: z.number().int(), pages: z.number().int(), has_next: z.boolean(), has_prev: z.boolean()}), success: z.boolean(), summary: z.object({answerRate: z.number().int(), answeredCalls: z.number().int(), avgCallDuration: z.string(), last_call_at: z.string(), totalCalls: z.number().int(), total_billable_seconds: z.number().int(), total_cost: z.number().int(), total_duration_seconds: z.number().int()}), account_auth_id: 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 customer CDRs * * GET /api/v1/partner/accounts/{customer_auth_id}/cdrs */ export const getApiApiV1PartnerAccountsCustomerAuthIdCdrs = async (args: GetApiApiV1PartnerAccountsCustomerAuthIdCdrsArgs, options?: GetApiApiV1PartnerAccountsCustomerAuthIdCdrsOptions) => { 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.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.status != null) query.append("status", String(args.status)) if (args.min_duration != null) query.append("min_duration", String(args.min_duration)) if (args.hangup_cause != null) query.append("hangup_cause", String(args.hangup_cause)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (AuthID !== undefined) headers.set("X-Auth-ID", AuthID) if (AuthToken !== undefined) headers.set("X-Auth-Token", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/partner/accounts/${encodeURIComponent(String(args.customer_auth_id))}/cdrs${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(getApiApiV1PartnerAccountsCustomerAuthIdCdrsResponse, await res.json()) };