import {z} from 'zod' export type GetApiV1SuperInvestorsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listingNotice = z.object({status: z.string().nullable().optional(), ticker: z.string().nullable().optional(), delistedOn: z.string().nullable().optional(), successorTicker: z.string().nullable().optional()}); export const superInvestorDto = z.object({managerName: z.string().nullable().optional(), firmName: z.string().nullable().optional(), cik: z.string().nullable().optional(), portfolioValue: z.number().int().nullable().optional(), positionCount: z.number().int().nullable().optional(), qoqChangePercent: z.number().nullable().optional(), asOf: z.string().nullable().optional(), isStale: z.boolean().nullable().optional()}); export const superInvestorDtoListResponse = z.object({listingNotice: listingNotice.optional(), data: z.array(superInvestorDto).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 }; /** * The curated superinvestor directory — well-known value investors and fund managers, each with their 13F filer CIK, latest published tracked portfolio value, position count, quarter-over-quarter change, and report date. Values normally use report-date closing prices, may fall back to filer values, and can be zero when unavailable. Use the CIK with the institution endpoints for a manager's full holdings. * * GET /v1/super-investors */ export const getApiV1SuperInvestors = async (options?: GetApiV1SuperInvestorsOptions) => { const {baseUrl = "https://api.equibles.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/super-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(superInvestorDtoListResponse, await res.json()) };