import {z} from 'zod' export type GetApiV1CallRecordsArgs = {agents?: string | undefined, destination?: string | undefined, duration?: string | undefined, call_type?: string | undefined, direction?: string | undefined, did_numbers?: string | undefined, call_id?: string | undefined, callerid?: string | undefined, department?: string | undefined, operator?: string | undefined, limit?: string | undefined, to_date?: string | undefined, broadcast?: string | undefined, ivr?: string | undefined, call_direction?: string | undefined, page?: string | undefined, from_date?: string | undefined, services?: string | undefined, Authorization: string}; export type GetApiV1CallRecordsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1CallRecordsResponse = z.object({}); 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 }; /** * Call Detail Records * * GET /v1/call/records */ export const getApiV1CallRecords = async (args: GetApiV1CallRecordsArgs, options?: GetApiV1CallRecordsOptions) => { const {baseUrl = "https://api-smartflo.tatateleservices.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.agents != null) query.append("agents", String(args.agents)) if (args.destination != null) query.append("destination", String(args.destination)) if (args.duration != null) query.append("duration", String(args.duration)) if (args.call_type != null) query.append("call_type", String(args.call_type)) if (args.direction != null) query.append("direction", String(args.direction)) if (args.did_numbers != null) query.append("did_numbers", String(args.did_numbers)) if (args.call_id != null) query.append("call_id", String(args.call_id)) if (args.callerid != null) query.append("callerid", String(args.callerid)) if (args.department != null) query.append("department", String(args.department)) if (args.operator != null) query.append("operator", String(args.operator)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.to_date != null) query.append("to_date", String(args.to_date)) if (args.broadcast != null) query.append("broadcast", String(args.broadcast)) if (args.ivr != null) query.append("ivr", String(args.ivr)) if (args.call_direction != null) query.append("call_direction", String(args.call_direction)) if (args.page != null) query.append("page", String(args.page)) if (args.from_date != null) query.append("from_date", String(args.from_date)) if (args.services != null) query.append("services", String(args.services)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/call/records${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(getApiV1CallRecordsResponse, await res.json()) };