import {z} from 'zod' export type GetApiV1StocksTickerCallThemesHistoryArgs = {ticker: string, calls?: number | undefined}; export type GetApiV1StocksTickerCallThemesHistoryOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const callThemeHistoryCallDto = z.object({fiscalYear: z.number().int().optional(), fiscalQuarter: z.number().int().optional(), callDate: z.string().optional(), unscoredQuartersBefore: z.number().int().optional()}); export const callThemeHistoryPeriodDto = z.object({fiscalYear: z.number().int().optional(), fiscalQuarter: z.number().int().optional()}); export const callThemeHistoryEntryDto = z.object({fiscalYear: z.number().int().optional(), fiscalQuarter: z.number().int().optional(), mentionCount: z.number().int().nullable().optional(), tone: z.string().nullable().optional()}); export const callThemeHistoryThemeDto = z.object({name: z.string().nullable().optional(), status: z.string().nullable().optional(), firstSeen: callThemeHistoryPeriodDto.optional(), lastSeen: callThemeHistoryPeriodDto.optional(), entries: z.array(callThemeHistoryEntryDto).nullable().optional()}); export const callThemeHistoryResponse = z.object({ticker: z.string().nullable().optional(), calls: z.array(callThemeHistoryCallDto).nullable().optional(), themes: z.array(callThemeHistoryThemeDto).nullable().optional(), hasMoreCalls: z.boolean().optional(), note: z.string().nullable().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 }; /** * How a company's call themes move quarter over quarter: each theme's mention count and tone on each of the last scored calls, oldest call first, plus its status on the latest call. Verifier-approved reads only. * * GET /v1/stocks/{ticker}/call-themes/history */ export const getApiV1StocksTickerCallThemesHistory = async (args: GetApiV1StocksTickerCallThemesHistoryArgs, options?: GetApiV1StocksTickerCallThemesHistoryOptions) => { const {baseUrl = "https://api.equibles.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.calls != null) query.append("calls", String(args.calls)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stocks/${encodeURIComponent(String(args.ticker))}/call-themes/history${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(callThemeHistoryResponse, await res.json()) };