import {z} from 'zod' export type LookupAccountPublicInput = {linkedin_url?: (string | null) | undefined, domain?: (string | null) | undefined}; export type CreateApiV1AccountsLookupArgs = {body: LookupAccountPublicInput}; export type CreateApiV1AccountsLookupOptions = {baseUrl?: string | undefined, BearerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const lookupAccountPublicOutput = z.object({found: z.boolean(), name: z.string().nullable().optional(), domain: z.string().nullable().optional(), linkedin_url: z.string().nullable().optional(), logo_url: z.string().nullable().optional(), industries: z.array(z.string()).optional(), employee_count: z.number().int().nullable().optional(), headcount_growth_6m: z.number().nullable().optional(), country: z.string().nullable().optional(), year_founded: z.string().nullable().optional(), revenue_lower_usd: z.number().int().nullable().optional(), revenue_upper_usd: z.number().int().nullable().optional(), last_funding_round_type: 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 }; /** * Lookup Account * * POST /v1/accounts/lookup */ export const createApiV1AccountsLookup = async (args: CreateApiV1AccountsLookupArgs, options?: CreateApiV1AccountsLookupOptions) => { const {baseUrl = "https://api.topo.io", fetch: fetchFn = fetch, BearerApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerApiKey !== undefined) headers.set('authorization', `Bearer ${BearerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/lookup${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(lookupAccountPublicOutput, await res.json()) };