import {z} from 'zod' export type ViewType = 0 | 1; export type GetApiV1DialersSessionLogArgs = {Id?: number | undefined, DepartmentId?: number | undefined, DialerId?: number | undefined, DialerSessionId?: number | undefined, PhoneNumber?: string | undefined, FromDate?: string | undefined, ToDate?: string | undefined, LastCallState?: number | undefined, ViewType?: ViewType | undefined, Page?: number | undefined, ItemsPerPage?: number | undefined, ReturnTotalItems?: boolean | undefined, sortCol?: string | undefined, sortDir?: string | undefined, isExport?: boolean | undefined}; export type GetApiV1DialersSessionLogOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const dialerSessionLogModel = z.object({id: z.number().int().optional(), departmentId: z.number().int().optional(), dialerId: z.number().int().optional(), dialerSessionId: z.number().int().optional(), phoneNumber: z.string().nullable().optional(), phoneNumber2: z.string().nullable().optional(), phoneNumber3: z.string().nullable().optional(), lastCallTime: z.string().optional(), lastCallDuration: z.number().int().optional(), lastCallState: z.number().int().optional(), callEndState: z.number().int().optional(), callCount: z.number().int().optional(), lastCallDtmf: z.string().nullable().optional(), callParameters: z.string().nullable().optional(), callerNumber: z.string().nullable().optional(), voipUserId: z.number().int().nullable().optional()}); export const dialerSessionLogModelQueryResult = z.object({totalItems: z.number().int().optional(), items: z.array(dialerSessionLogModel).nullable().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 }; /** * List all existing Dialer session logs * * GET /v1/dialers/session/log * * Also accepts auth: API Key */ export const getApiV1DialersSessionLog = async (args: GetApiV1DialersSessionLogArgs, options: GetApiV1DialersSessionLogOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Id != null) query.append("Id", String(args.Id)) if (args.DepartmentId != null) query.append("DepartmentId", String(args.DepartmentId)) if (args.DialerId != null) query.append("DialerId", String(args.DialerId)) if (args.DialerSessionId != null) query.append("DialerSessionId", String(args.DialerSessionId)) if (args.PhoneNumber != null) query.append("PhoneNumber", String(args.PhoneNumber)) if (args.FromDate != null) query.append("FromDate", String(args.FromDate)) if (args.ToDate != null) query.append("ToDate", String(args.ToDate)) if (args.LastCallState != null) query.append("LastCallState", String(args.LastCallState)) if (args.ViewType != null) query.append("ViewType", String(args.ViewType)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.ItemsPerPage != null) query.append("ItemsPerPage", String(args.ItemsPerPage)) if (args.ReturnTotalItems != null) query.append("ReturnTotalItems", String(args.ReturnTotalItems)) if (args.sortCol != null) query.append("sortCol", String(args.sortCol)) if (args.sortDir != null) query.append("sortDir", String(args.sortDir)) if (args.isExport != null) query.append("isExport", String(args.isExport)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/dialers/session/log${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(dialerSessionLogModelQueryResult, await res.json()) };