import {z} from 'zod' export type GetApiApiExternalV1ZapierGetLeadsArgs = {workspace_id: number, campaign_id: number, created_after?: (string | null) | undefined, last_lead_id?: (number | null) | undefined, limit?: (number | null) | undefined, is_test?: (boolean | null) | undefined}; export type GetApiApiExternalV1ZapierGetLeadsOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiExternalV1ZapierGetLeadsResponse = z.array(z.object({})); 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 }; /** * Poll for leads created in a campaign. * * GET /api/external/v1/zapier/get-leads */ export const getApiApiExternalV1ZapierGetLeads = async (args: GetApiApiExternalV1ZapierGetLeadsArgs, options?: GetApiApiExternalV1ZapierGetLeadsOptions) => { const {baseUrl = "https://backend.genpage.ai", fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.workspace_id != null) query.append("workspace_id", String(args.workspace_id)) if (args.campaign_id != null) query.append("campaign_id", String(args.campaign_id)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.last_lead_id != null) query.append("last_lead_id", String(args.last_lead_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.is_test != null) query.append("is_test", String(args.is_test)) if (defaultValue !== undefined) headers.set('authorization', `Bearer ${defaultValue}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/external/v1/zapier/get-leads${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(getApiApiExternalV1ZapierGetLeadsResponse, await res.json()) };