import {z} from 'zod' export type GetApiV1StocksTickerGoingConcernArgs = {ticker: string}; export type GetApiV1StocksTickerGoingConcernOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const goingConcernCurrentDto = z.object({isActive: z.boolean().optional(), flaggedDate: z.string().optional(), clearedDate: z.string().nullable().optional(), quote: z.string().nullable().optional(), form: z.string().nullable().optional(), filingUrl: z.string().nullable().optional(), firstFlaggedDate: z.string().nullable().optional(), firstFlaggedForm: z.string().nullable().optional()}); export const goingConcernHistoryDto = z.object({filedDate: z.string().optional(), form: z.string().nullable().optional(), filingUrl: z.string().nullable().optional(), substantialDoubt: z.boolean().optional(), alleviated: z.boolean().optional(), quote: z.string().nullable().optional()}); export const goingConcernResponse = z.object({ticker: z.string().nullable().optional(), companyName: z.string().nullable().optional(), examined: z.boolean().optional(), coverageStartDate: z.string().nullable().optional(), currentStatus: goingConcernCurrentDto.optional(), history: z.array(goingConcernHistoryDto).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 }; /** * Whether a company's latest SEC filing states substantial doubt about its ability to continue as a going concern, with the verbatim disclosure, the source filing, and the history of examined filings showing when doubt appeared, was alleviated, or cleared. Coverage begins at coverageStartDate — filings before it were never examined, so an episode predating it is invisible here, not disproven. examined is false when no filing has been checked yet. * * GET /v1/stocks/{ticker}/going-concern */ export const getApiV1StocksTickerGoingConcern = async (args: GetApiV1StocksTickerGoingConcernArgs, options?: GetApiV1StocksTickerGoingConcernOptions) => { 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))}/going-concern${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(goingConcernResponse, await res.json()) };