import {z} from 'zod' export type GetApiApiV1TranscriptsCallsArgs = {page?: number | undefined, page_size?: number | undefined, status?: string | undefined, symbol?: string | undefined, from?: string | undefined, to?: string | undefined, sort_by?: string | undefined, share_class_figi?: string | undefined, securities?: boolean | undefined, info_only?: boolean | undefined, filter?: string | undefined}; export type GetApiApiV1TranscriptsCallsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1TranscriptsCallsResponse = z.record(z.string(), z.unknown()); 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 }; /** * Fetch all calls * * GET /api/v1/transcripts/calls */ export const getApiApiV1TranscriptsCalls = async (args: GetApiApiV1TranscriptsCallsArgs, options?: GetApiApiV1TranscriptsCallsOptions) => { const {baseUrl = "https://api.benzinga.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.status != null) query.append("status", String(args.status)) if (args.symbol != null) query.append("symbol", String(args.symbol)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.share_class_figi != null) query.append("share_class_figi", String(args.share_class_figi)) if (args.securities != null) query.append("securities", String(args.securities)) if (args.info_only != null) query.append("info_only", String(args.info_only)) if (args.filter != null) query.append("filter", String(args.filter)) if (ApiKeyAuth !== undefined) headers.set("Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/transcripts/calls${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(getApiApiV1TranscriptsCallsResponse, await res.json()) };