import {z} from 'zod' export type GetApiApiV1ProjectsProjectIdReportsLeadsSessionIdCollatedArgs = {projectId: number, sessionId: string}; export type GetApiApiV1ProjectsProjectIdReportsLeadsSessionIdCollatedOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const projectLeadsExport = z.object({project_id: z.number().int().optional(), session_id: z.string().optional(), query_id: z.number().int().optional(), name: z.string().nullable().optional(), email: z.string().nullable().optional(), phone_number: z.string().nullable().optional(), company: z.string().nullable().optional(), captured_at: z.string().optional(), other_data: z.object({}).nullable().optional(), user_defined: z.object({}).nullable().optional(), tags: z.array(z.string()).nullable().optional()}); export const getApiApiV1ProjectsProjectIdReportsLeadsSessionIdCollatedResponse = z.object({status: z.enum(["error", "success"]).optional(), data: projectLeadsExport.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 }; /** * Export a single collated lead for a conversation. * * GET /api/v1/projects/{projectId}/reports/leads/{sessionId}/collated */ export const getApiApiV1ProjectsProjectIdReportsLeadsSessionIdCollated = async (args: GetApiApiV1ProjectsProjectIdReportsLeadsSessionIdCollatedArgs, options?: GetApiApiV1ProjectsProjectIdReportsLeadsSessionIdCollatedOptions) => { const {baseUrl = "https://app.customgpt.ai", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/projects/${encodeURIComponent(String(args.projectId))}/reports/leads/${encodeURIComponent(String(args.sessionId))}/collated${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(getApiApiV1ProjectsProjectIdReportsLeadsSessionIdCollatedResponse, await res.json()) };