import {z} from 'zod' export type GetApiApiV1AnalystInsightsArgs = {page?: number | undefined, pageSize?: number | undefined, date?: string | undefined, date_from?: string | undefined, date_to?: string | undefined, symbols?: unknown | undefined, analyst?: string | undefined, rating_id?: string | undefined, search_keys_type?: ('firm_id' | 'firm' | 'analyst_id' | 'analyst_name') | undefined, search_keys?: string | undefined, sort?: 'date' | undefined, 'parameters[updated]'?: number | undefined}; export type GetApiApiV1AnalystInsightsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiAnalystInsightsSecurity = z.object({cik: z.string().optional(), exchange: z.string().optional(), isin: z.string().optional(), name: z.string().optional(), symbol: z.string().optional()}); export const gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiAnalystInsights = z.object({action: z.string().optional(), analyst_id: z.string().optional(), analyst_insights: z.string().optional(), date: z.string().optional(), firm: z.string().optional(), firm_id: z.string().optional(), id: z.string().optional(), pt: z.string().optional(), rating: z.string().optional(), rating_id: z.string().optional(), security: gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiAnalystInsightsSecurity.optional(), updated: z.number().int().optional()}); export const apiAnalystInsightsResponse = z.object({"analyst-insights": z.array(gitlabBenzingaIoBenzingaBzgoPkgModelsCalendarApiAnalystInsights).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 }; /** * Analyst Insights V1 * * GET /api/v1/analyst/insights */ export const getApiApiV1AnalystInsights = async (args: GetApiApiV1AnalystInsightsArgs, options?: GetApiApiV1AnalystInsightsOptions) => { 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.date != null) query.append("date", String(args.date)) if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.symbols != null) query.append("symbols", String(args.symbols)) if (args.analyst != null) query.append("analyst", String(args.analyst)) if (args.rating_id != null) query.append("rating_id", String(args.rating_id)) 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 (args.sort != null) query.append("sort", String(args.sort)) 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/v1/analyst/insights${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(apiAnalystInsightsResponse, await res.json()) };