import {z} from 'zod' export type GetApiV1StocksTickerFinancialFactsConceptArgs = {ticker: string, concept: string}; export type GetApiV1StocksTickerFinancialFactsConceptOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const financialFactPointDto = z.object({fiscalPeriod: z.string().nullable().optional(), value: z.number().optional(), splitBasis: z.string().nullable().optional(), periodStart: z.string().nullable().optional(), periodEnd: z.string().optional(), filedDate: z.string().optional(), form: z.string().nullable().optional(), isComparableAnnual: z.boolean().optional(), documentId: z.string().nullable().optional()}); export const financialFactResponse = z.object({ticker: z.string().nullable().optional(), companyName: z.string().nullable().optional(), concept: z.string().nullable().optional(), unit: z.string().nullable().optional(), coverageEndDate: z.string().nullable().optional(), companyFactsThrough: z.string().nullable().optional(), coverageNote: z.string().nullable().optional(), tagWarning: z.string().nullable().optional(), quarterly: z.array(financialFactPointDto).nullable().optional(), annual: z.array(financialFactPointDto).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 }; /** * One consolidated financial concept over time for a company, sourced from structured SEC XBRL. Returns separate annual and discrete-quarter series, oldest first, using the latest restated value: one point per fiscal period for flows, one point per as-of date (periodEnd) for balances and share counts. Per-share values and common-share counts are on today's split basis (splitBasis says when the filed value is kept). * * GET /v1/stocks/{ticker}/financial-facts/{concept} */ export const getApiV1StocksTickerFinancialFactsConcept = async (args: GetApiV1StocksTickerFinancialFactsConceptArgs, options?: GetApiV1StocksTickerFinancialFactsConceptOptions) => { 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 (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stocks/${encodeURIComponent(String(args.ticker))}/financial-facts/${encodeURIComponent(String(args.concept))}${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(financialFactResponse, await res.json()) };