import {z} from 'zod' export type GetApiCallReportsIdArgs = {id: string}; export type GetApiCallReportsIdOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCallReportsIdResponse = z.object({id: z.string().optional(), name: z.string().optional(), type: z.enum(["NORMAL", "EXTENSION_GROUP_CALL_COST", "QUEUE_PERFORMANCE", "QUEUE_DETAILED_STATISTICS", "QUEUE_ABANDONED_CALLS", "QUEUE_SLA_STATISTICS", "QUEUE_BREACHES_SLA_STATISTICS", "QUEUE_CALLBACKS", "QUEUE_FAILED_CALLBACKS", "TEAM_QUEUE_GENERAL_STATISTICS", "RING_GROUP_STATISTICS"]).optional(), email: z.string().max(128).optional(), format: z.enum(["CSV", "HTML"]).optional(), range: z.enum(["TODAY", "YESTERDAY", "LAST_WEEK", "LAST_SEVEN_DAYS", "LAST_MONTH", "LAST_THIRTY_DAYS", "CUSTOM"]).optional(), started_at: z.string().optional(), ended_at: z.string().optional(), cron_expr: z.string().optional(), filter: z.union([z.object({from: z.enum(["ANY", "EXTENSION_OR_EXTENSION_RANGE", "NUMBER", "NUMBERS_START_WITH", "NUMBERS_CONTAIN", "INTERNAL_EXTENSIONS", "EXTERNAL_NUMBERS"]).optional(), from_value: z.string().optional(), to: z.enum(["ANY", "EXTENSION_OR_EXTENSION_RANGE", "NUMBER", "NUMBERS_START_WITH", "NUMBERS_CONTAIN", "INTERNAL_EXTENSIONS", "EXTERNAL_NUMBERS"]).optional(), to_value: z.string().optional(), answer_state: z.enum(["ANY", "ANSWERED", "NOT_ANSWERED"]).optional(), duration: z.enum(["ANY", "RING_DURATION", "TALK_DURATION"]).optional(), duration_from: z.number().int().gte(0).optional(), duration_to: z.number().int().gte(0).optional()}), z.object({extension: z.enum(["ANY", "EXTENSION_OR_EXTENSION_RANGE"]).optional(), extension_value: z.string().optional(), type: z.enum(["ANY", "INTERNAL", "EXTERNAL"]).optional()}), z.object({type: z.enum(["ANY", "LOCAL", "NATIONAL", "INTERNATIONAL", "MOBILE"]).optional(), groups: z.array(z.string().min(1).max(64)).optional()}), z.object({enable_exclude_calls_dropped_before_seconds: z.boolean().optional(), exclude_calls_dropped_before_seconds: z.number().int().gte(0).optional(), call_queues: z.array(z.string().min(3).max(64)).optional()}), z.object({enable_exclude_calls_dropped_before_seconds: z.boolean().optional(), exclude_calls_dropped_before_seconds: z.number().int().gte(0).optional(), call_queues: z.array(z.string().min(3).max(64)).optional()}), z.object({enable_exclude_calls_dropped_before_seconds: z.boolean().optional(), exclude_calls_dropped_before_seconds: z.number().int().gte(0).optional(), call_queues: z.array(z.string().min(3).max(64)).optional()}), z.object({enable_exclude_calls_dropped_before_seconds: z.boolean().optional(), exclude_calls_dropped_before_seconds: z.number().int().gte(0).optional(), call_queues: z.array(z.string().min(3).max(64)).optional()}), z.object({enable_exclude_calls_dropped_before_seconds: z.boolean().optional(), exclude_calls_dropped_before_seconds: z.number().int().gte(0).optional(), call_queues: z.array(z.string().min(3).max(64)).optional()}), z.object({enable_exclude_calls_dropped_before_seconds: z.boolean().optional(), exclude_calls_dropped_before_seconds: z.number().int().gte(0).optional(), call_queues: z.array(z.string().min(3).max(64)).optional()}), z.object({call_queues: z.array(z.string().min(3).max(64)).optional()}), z.object({enable_exclude_calls_dropped_before_seconds: z.boolean().optional(), exclude_calls_dropped_before_seconds: z.number().int().gte(0).optional(), call_queues: z.array(z.string().min(3).max(64)).optional()}), z.object({ring_groups: z.array(z.string().min(3).max(64)).optional()})]).optional(), status: z.enum(["RUNNING", "SCHEDULED", "ABORTED"]).optional()}); 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 call report details * * GET /call_reports/{id} */ export const getApiCallReportsId = async (args: GetApiCallReportsIdArgs, options?: GetApiCallReportsIdOptions) => { const {baseUrl = "https://HOSTNAME:8887/api", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/call_reports/${encodeURIComponent(String(args.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(getApiCallReportsIdResponse, await res.json()) };