import {z} from 'zod' export type GetApiInvestorsArgs = {q?: string | undefined, domain?: string | undefined, types?: string | undefined, stages?: string | undefined, industries?: string | undefined, countries?: string | undefined, geographicFocus?: string | undefined, minCheckSize?: number | undefined, maxCheckSize?: number | undefined, minAum?: number | undefined, maxAum?: number | undefined, minCompleteness?: number | undefined, updated_since?: string | undefined, sort?: ('name' | 'aum' | 'portfolio_count' | 'total_investments' | 'last_investment_date' | 'data_completeness_score') | undefined, order?: ('asc' | 'desc') | undefined, page?: number | undefined, limit?: number | undefined, cursor?: string | undefined, reveal_status?: ('all' | 'revealed' | 'unrevealed') | undefined}; export type GetApiInvestorsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const investorCard = z.object({id: z.string(), name: z.string(), slug: z.string(), logo_url: z.string().nullable().optional(), website: z.string().nullable().optional(), investor_type: z.enum(["vc", "pe", "growth_equity", "hedge_fund", "cvc", "family_office", "sovereign_wealth", "accelerator", "incubator", "angel_group", "angel", "individual", "bank", "other", "null"]).nullable().optional(), hq_city: z.string().nullable().optional(), hq_country: z.string().nullable().optional(), total_investments_count: z.number().int().nullable().optional(), _revealed: z.boolean()}); export const searchPageMeta = z.object({total: z.number().int(), total_is_estimate: z.boolean().optional(), page: z.number().int(), limit: z.number().int(), hasMore: z.boolean(), revealed_count: z.number().int(), unrevealed_count: z.number().int(), all_revealed: z.boolean().optional(), next_cursor: z.string().nullable().optional(), search_quota: z.object({per_day: z.number().int(), used_today: z.number().int(), remaining_today: z.number().int(), resets_at: z.string(), note: z.string().optional()}), depth: z.object({endpoint: z.string(), cost_credits: z.number().int(), unlocks: z.array(z.string()), docs: z.string(), free_plan: z.object({credits_per_month: z.number().int(), full_records_per_month: z.number().int()}).optional()}).optional(), alternate_entities: z.array(z.object({entity_type: z.literal("investor"), id: z.string(), name: z.string(), slug: z.string(), website: z.string(), investor_type: z.string().nullable(), profile_path: z.string()})).optional(), alternate_entities_truncated: z.boolean().optional(), investor_lookup: z.string().optional(), resolved_filters: z.record(z.string(), z.unknown()).optional()}); export const getApiInvestorsResponse = z.object({data: z.array(investorCard), meta: searchPageMeta}); 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 investors * * GET /investors */ export const getApiInvestors = async (args: GetApiInvestorsArgs, options?: GetApiInvestorsOptions) => { const {baseUrl = "https://indexed.vc/api/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.q != null) query.append("q", String(args.q)) if (args.domain != null) query.append("domain", String(args.domain)) if (args.types != null) query.append("types", String(args.types)) if (args.stages != null) query.append("stages", String(args.stages)) if (args.industries != null) query.append("industries", String(args.industries)) if (args.countries != null) query.append("countries", String(args.countries)) if (args.geographicFocus != null) query.append("geographicFocus", String(args.geographicFocus)) if (args.minCheckSize != null) query.append("minCheckSize", String(args.minCheckSize)) if (args.maxCheckSize != null) query.append("maxCheckSize", String(args.maxCheckSize)) if (args.minAum != null) query.append("minAum", String(args.minAum)) if (args.maxAum != null) query.append("maxAum", String(args.maxAum)) if (args.minCompleteness != null) query.append("minCompleteness", String(args.minCompleteness)) if (args.updated_since != null) query.append("updated_since", String(args.updated_since)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.reveal_status != null) query.append("reveal_status", String(args.reveal_status)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/investors${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(getApiInvestorsResponse, await res.json()) };