import {z} from 'zod' export type GetApiApiV2CalendarEventsArgs = {page?: number | undefined, pageSize?: number | undefined, 'parameters[date]'?: string | undefined, 'parameters[date_from]'?: string | undefined, 'parameters[date_to]'?: string | undefined, 'parameters[importance]'?: (0 | 1 | 2 | 3 | 4 | 5) | undefined, 'parameters[tickers]'?: unknown | undefined, 'parameters[updated]'?: number | undefined, search_keys_type?: 'event_type' | undefined, search_keys?: string | undefined}; export type GetApiApiV2CalendarEventsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiSecurities = z.object({country: z.string().optional(), cusip: z.string().optional(), exchange: z.string().optional(), isin: z.string().optional(), symbol: z.string().optional()}); export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiEvents = z.object({date_end: z.string().optional(), date_start: z.string().optional(), event_name: z.string().optional(), event_type: z.string().optional(), id: z.string().optional(), importance: z.number().int().optional(), international_number: z.string().optional(), location: z.string().optional(), phone_number: z.string().optional(), securities: z.array(gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiSecurities).optional(), source_link: z.string().optional(), start_time: z.string().optional(), tags: z.array(z.string()).optional(), updated: z.number().int().optional(), webcast_link: z.string().optional()}); export const apiEventsResponse = z.object({events: z.array(gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiEvents).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 }; /** * Events * * GET /api/v2/calendar/events */ export const getApiApiV2CalendarEvents = async (args: GetApiApiV2CalendarEventsArgs, options?: GetApiApiV2CalendarEventsOptions) => { 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.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[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 (args.search_keys_type != null) query.append("search_keys_type", String(args.search_keys_type)) if (args.search_keys != null) query.append("search_keys", String(args.search_keys)) if (ApiKeyAuth !== undefined) headers.set("Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/calendar/events${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(apiEventsResponse, await res.json()) };