import {z} from 'zod' export type GetApiApiV21CalendarSplitsArgs = {accept: 'application/json', page?: number | undefined, pagesize?: number | undefined, 'parameters[date]'?: unknown | undefined, 'parameters[date_from]'?: unknown | undefined, 'parameters[date_to]'?: unknown | undefined, 'parameters[date_search_field]'?: ('announced' | 'ex') | undefined, 'parameters[importance]'?: (0 | 1 | 2 | 3 | 4 | 5) | undefined, 'parameters[tickers]'?: unknown | undefined, 'parameters[updated]'?: number | undefined}; export type GetApiApiV21CalendarSplitsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiSplit = z.object({cusip: z.string().optional(), date_announced: z.string().optional(), date_distribution: z.string().optional(), date_ex: z.string().optional(), date_recorded: z.string().optional(), exchange: z.string().optional(), id: z.string().optional(), importance: z.number().int().optional(), name: z.string().optional(), notes: z.string().optional(), optionable: z.boolean().optional(), ratio: z.string().optional(), split_type: z.string().optional(), ticker: z.string().optional(), updated: z.number().int().optional()}); export const apiSplitResponse = z.object({splits: z.array(gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiSplit).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 }; /** * Returns the splits calendar data * * GET /api/v2.1/calendar/splits */ export const getApiApiV21CalendarSplits = async (args: GetApiApiV21CalendarSplitsArgs, options?: GetApiApiV21CalendarSplitsOptions) => { 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.accept != null) headers.set("accept", String(args.accept)) if (args.page != null) query.append("page", String(args.page)) if (args.pagesize != null) query.append("pagesize", String(args.pagesize)) if (args['parameters[date]'] != null) query.append("parameters[date]", String(args['parameters[date]'])) if (args['parameters[date_from]'] != null) query.append("parameters[date_from]", String(args['parameters[date_from]'])) if (args['parameters[date_to]'] != null) query.append("parameters[date_to]", String(args['parameters[date_to]'])) if (args['parameters[date_search_field]'] != null) query.append("parameters[date_search_field]", String(args['parameters[date_search_field]'])) if (args['parameters[importance]'] != null) query.append("parameters[importance]", String(args['parameters[importance]'])) if (args['parameters[tickers]'] != null) query.append("parameters[tickers]", String(args['parameters[tickers]'])) if (args['parameters[updated]'] != null) query.append("parameters[updated]", String(args['parameters[updated]'])) if (ApiKeyAuth !== undefined) headers.set("Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2.1/calendar/splits${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(apiSplitResponse, await res.json()) };