import {z} from 'zod' export type CreateApiApiExternalV1LeadsUpsertLeadsArgs = {body: {from?: (string | null) | undefined, campaign_id: number, audience_id?: (number | null) | undefined, callback_url?: (string | null) | undefined, send_email?: (boolean | null) | undefined, is_generate_ai_analysis?: (boolean | null) | undefined, enrich_data?: (boolean | null) | undefined, generate_ai_variables?: (boolean | null) | undefined, leads: Array<{lead_id?: (number | null) | undefined, genpage_url?: (string | null) | undefined, values: {first_name?: string | undefined, last_name?: string | undefined, email?: string | undefined, company_name?: string | undefined, linkedin_profile_url?: string | undefined, company_domain?: string | undefined, my_custom_variable?: string | undefined} | null}>}}; export type CreateApiApiExternalV1LeadsUpsertLeadsOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiExternalV1LeadsUpsertLeadsResponse = z.object({job_id: z.string().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 }; /** * Upsert leads. * * POST /api/external/v1/leads/upsert-leads */ export const createApiApiExternalV1LeadsUpsertLeads = async (args: CreateApiApiExternalV1LeadsUpsertLeadsArgs, options?: CreateApiApiExternalV1LeadsUpsertLeadsOptions) => { const {baseUrl = "https://backend.genpage.ai", fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (defaultValue !== undefined) headers.set('authorization', `Bearer ${defaultValue}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/external/v1/leads/upsert-leads${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiExternalV1LeadsUpsertLeadsResponse, await res.json()) };