import {z} from 'zod' export type GetApiV1InstitutionsCikProfileArgs = {cik: string}; export type GetApiV1InstitutionsCikProfileOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const institutionAdviserHistoryDto = z.object({since: z.string().optional(), until: z.string().optional(), registration: z.string().nullable().optional(), regulatoryAum: z.number().int().nullable().optional(), clientBase: z.string().nullable().optional(), clientBaseAumShare: z.number().nullable().optional(), pooledVehicleAumShare: z.number().nullable().optional(), advisesPrivateFunds: z.boolean().nullable().optional(), privateFundCount: z.number().int().nullable().optional(), privateFundGrossAssets: z.number().int().nullable().optional()}); export const institutionScheduleDFundTypeDto = z.object({type: z.string().nullable().optional(), fundCount: z.number().int().optional(), grossAssets: z.number().int().optional()}); export const institutionScheduleDDto = z.object({filedOn: z.string().optional(), fundCount: z.number().int().optional(), grossAssets: z.number().int().optional(), fundTypes: z.array(institutionScheduleDFundTypeDto).nullable().optional()}); export const institutionHolderProfileDto = z.object({holderType: z.string().nullable().optional(), entityType: z.string().nullable().optional(), entityTypeSource: z.string().nullable().optional(), entityTypeSourceKey: z.string().nullable().optional(), entityTypeAsOf: z.string().nullable().optional(), hasConflictingEvidence: z.boolean().optional(), adviserCrd: z.number().int().nullable().optional(), adviserAsOf: z.string().nullable().optional(), regulatoryAum: z.number().int().nullable().optional(), clientBase: z.string().nullable().optional(), clientBaseAumShare: z.number().nullable().optional(), pooledVehicleAumShare: z.number().nullable().optional(), advisesPrivateFunds: z.boolean().nullable().optional(), privateFundCount: z.number().int().nullable().optional(), privateFundFocus: z.string().nullable().optional(), privateFundFocusBasis: z.string().nullable().optional(), privateFundFocusAsOf: z.string().nullable().optional(), privateFundGrossAssets: z.number().int().nullable().optional(), advisedSeriesCount: z.number().int().optional(), indexSeriesCount: z.number().int().optional(), etfSeriesCount: z.number().int().optional(), advisedNetAssets: z.number().nullable().optional(), indexNetAssets: z.number().nullable().optional(), advisedSeriesAsOf: z.string().nullable().optional(), lei: z.string().nullable().optional(), sic: z.string().nullable().optional(), adviserHistory: z.array(institutionAdviserHistoryDto).nullable().optional(), scheduleD: institutionScheduleDDto.optional()}); export const institutionCikLinkDto = z.object({name: z.string().nullable().optional(), cik: z.string().nullable().optional(), predecessorLastReportDate: z.string().optional(), successorFirstReportDate: z.string().optional()}); export const institutionStrategyStatementDto = z.object({category: z.string().nullable().optional(), quote: z.string().nullable().optional()}); export const institutionStatedStrategyDto = z.object({source: z.string().nullable().optional(), asOf: z.string().optional(), sourceUrl: z.string().nullable().optional(), statements: z.array(institutionStrategyStatementDto).nullable().optional()}); export const institutionProfileResponse = z.object({name: z.string().nullable().optional(), cik: z.string().nullable().optional(), profile: institutionHolderProfileDto.optional(), earlierCiks: z.array(institutionCikLinkDto).nullable().optional(), laterCiks: z.array(institutionCikLinkDto).nullable().optional(), strategy: z.array(institutionStatedStrategyDto).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 }; /** * An institution's profile from regulatory records, never from its name: the entity type and * the record that decided it, Form ADV adviser facts (regulatory assets, client base, private * funds) with their monthly roster history and the newest Schedule D 7.B.(1) private funds * dated by filing, the registered funds it advises by N-CEN, its LEI and SIC code, plus the * earlier or later CIKs its 13F reports continue under. profile is null until the filer is * classified. strategy lists the strategies the firm states in its own Form ADV Part 2A * brochures, quoted and dated, and is omitted when none is on file; it never decides the entity * type. * * GET /v1/institutions/{cik}/profile */ export const getApiV1InstitutionsCikProfile = async (args: GetApiV1InstitutionsCikProfileArgs, options?: GetApiV1InstitutionsCikProfileOptions) => { 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/institutions/${encodeURIComponent(String(args.cik))}/profile${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(institutionProfileResponse, await res.json()) };