import {z} from 'zod' export type ViewType = 0 | 1; export type GetApiV1DealsIdRoutingRunLogsArgs = {id: number, ViewType?: ViewType | undefined, Page?: number | undefined, ItemsPerPage?: number | undefined, ReturnTotalItems?: boolean | undefined}; export type GetApiV1DealsIdRoutingRunLogsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const routingRunStep = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9)]); export const routingRunLog = z.object({id: z.number().int().optional(), accountId: z.number().int().optional(), runId: z.string().min(1).max(64), queueId: z.number().int().optional(), queueName: z.string().max(255).nullable().optional(), linkedId: z.number().int().optional(), linkedType: z.number().int().optional(), step: routingRunStep.optional(), userId: z.number().int().nullable().optional(), groupId: z.number().int().nullable().optional(), createdAt: z.string().optional()}); export const routingRunLogQueryResult = z.object({totalItems: z.number().int().optional(), items: z.array(routingRunLog).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 }; /** * GET /v1/deals/{id}/routingRunLogs * * Also accepts auth: API Key */ export const getApiV1DealsIdRoutingRunLogs = async (args: GetApiV1DealsIdRoutingRunLogsArgs, options: GetApiV1DealsIdRoutingRunLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") 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 (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/deals/${encodeURIComponent(String(args.id))}/routingRunLogs${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(routingRunLogQueryResult, await res.json()) };