import {z} from 'zod' export type GetApiV1FilingsSearchArgs = {query: string, documentType?: string | undefined, startDate?: string | undefined, endDate?: string | undefined, limit?: number | undefined, excludeTickers?: string | undefined, maxResultsPerCompany?: number | undefined, match?: string | undefined}; export type GetApiV1FilingsSearchOptions = {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 documentSearchResultDto = z.object({documentId: z.string().optional(), ticker: z.string().nullable().optional(), companyName: z.string().nullable().optional(), documentType: z.string().nullable().optional(), documentTypeName: z.string().nullable().optional(), filedDate: z.string().optional(), chunkIndex: z.number().int().optional(), startLineNumber: z.number().int().optional(), text: z.string().nullable().optional(), url: z.string().nullable().optional()}); export const documentSearchResponse = z.object({limit: z.number().int().optional(), count: z.number().int().optional(), listingNotice: listingNotice.optional(), data: z.array(documentSearchResultDto).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 }; /** * Hybrid keyword and semantic search across all companies' SEC filings and earnings call transcripts. Returns matching excerpts with their document ids. When too few excerpts match every query word, the search automatically broadens to match any of the words — precise matches keep their rank and broader hits only fill the remainder. * * GET /v1/filings/search */ export const getApiV1FilingsSearch = async (args: GetApiV1FilingsSearchArgs, options?: GetApiV1FilingsSearchOptions) => { 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 (args.query != null) query.append("query", String(args.query)) if (args.documentType != null) query.append("documentType", String(args.documentType)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.excludeTickers != null) query.append("excludeTickers", String(args.excludeTickers)) if (args.maxResultsPerCompany != null) query.append("maxResultsPerCompany", String(args.maxResultsPerCompany)) if (args.match != null) query.append("match", String(args.match)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/filings/search${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(documentSearchResponse, await res.json()) };