import {z} from 'zod' export type GetApiApiV1AccountSearchLookalikesArgs = {query?: (string | null) | undefined, seed_domains?: Array | undefined, limit?: number | undefined, min_employees?: number | undefined, max_employees?: number | undefined, funding_stages?: (Array<'Pre-Seed' | 'Seed' | 'Series A' | 'Series B' | 'Series C' | 'Series D' | 'Series E' | 'Series F' | 'Series G' | 'Series H' | 'Acquired' | 'Private' | 'Public'>) | undefined, locations?: Array | undefined, 'X-API-Key': string}; export type GetApiApiV1AccountSearchLookalikesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const instantTraitSearchResult = z.object({name: z.string().nullable().optional(), domain: z.string().nullable().optional(), linkedin_url: z.string().nullable().optional(), headquarters: z.string().nullable().optional(), match_reason: z.string().nullable().optional(), employee_count: z.number().int().nullable().optional(), funding_stage: z.string().nullable().optional(), revenue_usd: z.number().int().nullable().optional(), industries: z.array(z.string()).nullable().optional(), hq_city: z.string().nullable().optional(), hq_region: z.string().nullable().optional(), hq_country: z.string().nullable().optional(), linkedin_follower_count: z.number().int().nullable().optional(), description: z.string().nullable().optional(), tagline: z.string().nullable().optional()}); export const instantTraitSearchResponse = z.object({query: z.string(), results: z.array(instantTraitSearchResult), total: z.number().int(), credits_consumed: z.number().int().optional(), derived_query: z.string().nullable().optional(), resolved_seed_domains: z.array(z.string()).nullable().optional(), unresolved_seed_domains: z.array(z.string()).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 }; /** * Search Lookalikes * * GET /api/v1/account/search-lookalikes */ export const getApiApiV1AccountSearchLookalikes = async (args: GetApiApiV1AccountSearchLookalikesArgs, options?: GetApiApiV1AccountSearchLookalikesOptions) => { const {baseUrl = "https://api.openfunnel.dev", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.query != null) query.append("query", String(args.query)) for (const item of args.seed_domains ?? []) query.append("seed_domains", String(item)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.min_employees != null) query.append("min_employees", String(args.min_employees)) if (args.max_employees != null) query.append("max_employees", String(args.max_employees)) for (const item of args.funding_stages ?? []) query.append("funding_stages", String(item)) for (const item of args.locations ?? []) query.append("locations", String(item)) if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/account/search-lookalikes${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(instantTraitSearchResponse, await res.json()) };