import {z} from 'zod' export type GetApiInvestorsSlugArgs = {slug: string, depth?: ('slim' | 'standard' | 'full') | undefined}; export type GetApiInvestorsSlugOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const profileLoadState = z.object({status: z.enum(["ok", "partial", "unavailable", "failed"]), cause: z.enum(["outage", "defect"]).optional()}); export const investorProfile = z.object({id: z.string(), name: z.string(), slug: z.string(), data_as_of: z.string().nullable().optional(), logo_url: z.string().nullable().optional(), website: z.string().nullable().optional(), investor_type: z.string().nullable().optional(), description: z.string().nullable().optional(), hq_city: z.string().nullable().optional(), hq_country: z.string().nullable().optional(), total_investments_count: z.number().int().nullable().optional(), portfolio_company_count: z.number().int().nullable().optional(), total_capital_deployed: z.number().int().nullable().optional(), avg_check_size: z.number().int().nullable().optional(), typical_check_size_min: z.number().int().nullable().optional(), typical_check_size_max: z.number().int().nullable().optional(), load_states: z.object({portfolio: profileLoadState.optional(), investments: profileLoadState.optional(), family: profileLoadState.optional(), co_investors: profileLoadState.optional()}).optional(), portfolio_companies: z.array(z.object({company_name: z.string().optional(), company_slug: z.string().optional(), company_logo_url: z.string().nullable().optional(), industries: z.array(z.string()).optional(), hq_country: z.string().nullable().optional()})).optional(), investments: z.array(z.object({company_name: z.string().optional(), company_slug: z.string().optional(), event_type: z.string().optional(), date: z.string().nullable().optional(), amount: z.number().int().nullable().optional(), is_lead: z.boolean().optional()})).optional(), sub_funds: z.array(z.object({id: z.string().optional(), name: z.string().optional(), slug: z.string().optional()})).optional()}); export const getApiInvestorsSlugResponse = z.object({data: investorProfile}); 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 }; /** * Get investor by slug * * GET /investors/{slug} */ export const getApiInvestorsSlug = async (args: GetApiInvestorsSlugArgs, options?: GetApiInvestorsSlugOptions) => { 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.depth != null) query.append("depth", String(args.depth)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/investors/${encodeURIComponent(String(args.slug))}${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(getApiInvestorsSlugResponse, await res.json()) };