import {z} from 'zod' export type GetApiV1StocksTickerEarningsCallsPhraseTrendArgs = {ticker: string, phrase: string, calls?: number | undefined}; export type GetApiV1StocksTickerEarningsCallsPhraseTrendOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const transcriptPhraseQuoteDto = z.object({text: z.string().nullable().optional(), section: z.string().nullable().optional()}); export const transcriptPhraseSpellingDto = z.object({text: z.string().nullable().optional(), mentions: z.number().int().optional()}); export const transcriptPhraseTrendCallDto = z.object({eventId: z.string().optional(), fiscalYear: z.number().int().optional(), fiscalQuarter: z.number().int().optional(), callDate: z.string().optional(), callDateIsPeriodEnd: z.boolean().optional(), missingQuartersBefore: z.number().int().optional(), textSource: z.string().nullable().optional(), mentions: z.number().int().nullable().optional(), wordCount: z.number().int().nullable().optional(), ratePer10kWords: z.number().nullable().optional(), sectionSplit: z.string().nullable().optional(), preparedRemarksMentions: z.number().int().nullable().optional(), qaMentions: z.number().int().nullable().optional(), quotes: z.array(transcriptPhraseQuoteDto).nullable().optional(), spellings: z.array(transcriptPhraseSpellingDto).nullable().optional()}); export const transcriptPhraseTrendResponse = z.object({ticker: z.string().nullable().optional(), phrase: z.string().nullable().optional(), calls: z.array(transcriptPhraseTrendCallDto).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 often a word or phrase comes up on a company's last earnings calls, oldest call first: mentions per call, the rate per 10,000 words, the prepared-remarks vs Q&A split where the call states its hand-off to questions, and up to two quotes. Whole-word and case-insensitive; a call with no transcript text has null counts, never zero. * * GET /v1/stocks/{ticker}/earnings-calls/phrase-trend */ export const getApiV1StocksTickerEarningsCallsPhraseTrend = async (args: GetApiV1StocksTickerEarningsCallsPhraseTrendArgs, options?: GetApiV1StocksTickerEarningsCallsPhraseTrendOptions) => { 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.phrase != null) query.append("phrase", String(args.phrase)) 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))}/earnings-calls/phrase-trend${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(transcriptPhraseTrendResponse, await res.json()) };