import {z} from 'zod' export type GetApiCustomerAccountReportsArgs = {limit?: number | undefined, cursor?: string | undefined, companyName?: string | undefined, minIcpMatchPercent?: number | undefined, maxIcpMatchPercent?: number | undefined, dateFrom?: string | undefined, dateTo?: string | undefined, query?: string | undefined, sort?: ('latestSignalAt' | 'leadCount' | 'averageIcpMatchPercent' | 'accountName') | undefined, sortDirection?: ('asc' | 'desc') | undefined}; export type GetApiCustomerAccountReportsOptions = {baseUrl?: string | undefined, CustomerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const pageEnvelope = z.object({data: z.array(z.record(z.string(), z.unknown())), page: z.object({limit: z.number().int(), cursor: z.string().nullable().optional(), nextCursor: z.string().nullable()})}); 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 account-level summaries derived from visible active leads. * * GET /customer/account-reports */ export const getApiCustomerAccountReports = async (args: GetApiCustomerAccountReportsArgs, options?: GetApiCustomerAccountReportsOptions) => { const {baseUrl = "https://api.traxy.ai/api/v1", fetch: fetchFn = fetch, CustomerApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.companyName != null) query.append("companyName", String(args.companyName)) if (args.minIcpMatchPercent != null) query.append("minIcpMatchPercent", String(args.minIcpMatchPercent)) if (args.maxIcpMatchPercent != null) query.append("maxIcpMatchPercent", String(args.maxIcpMatchPercent)) if (args.dateFrom != null) query.append("dateFrom", String(args.dateFrom)) if (args.dateTo != null) query.append("dateTo", String(args.dateTo)) if (args.query != null) query.append("query", String(args.query)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.sortDirection != null) query.append("sortDirection", String(args.sortDirection)) if (CustomerApiKey !== undefined) headers.set('authorization', `Bearer ${CustomerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/customer/account-reports${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(pageEnvelope, await res.json()) };