export type UniverseSpec = {type?: (string | null) | undefined, value?: (string | null) | undefined, symbols?: (Array | null) | undefined}; export type FilterNode = {op?: (string | null) | undefined, conditions?: (Array | null) | undefined, field?: (string | null) | undefined, formula?: (string | null) | undefined, operator?: (string | null) | undefined, value: unknown}; export type SortSpec = {field?: (string | null) | undefined, formula?: (string | null) | undefined, direction?: (string | null) | undefined}; export type FormulaField = {alias?: (string | null) | undefined, expression?: (string | null) | undefined}; export type ScreenerRequest = {universe?: UniverseSpec | undefined, filters?: FilterNode | undefined, sort?: (Array | null) | undefined, select?: (Array | null) | undefined, formulas?: (Array | null) | undefined, limit?: number | undefined, offset?: number | undefined}; export type CreateApiV1ScreenerArgs = {body: ScreenerRequest}; export type CreateApiV1ScreenerOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST /v1/screener */ export const createApiV1Screener = async (args: CreateApiV1ScreenerArgs, options: CreateApiV1ScreenerOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (ApiKey !== undefined) headers.set("X-Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/screener${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };