import {z} from 'zod' export type GetApiV1StocksTickerCustomerConcentrationArgs = {ticker: string}; export type GetApiV1StocksTickerCustomerConcentrationOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const concentrationFigureDto = z.object({basis: z.string().nullable().optional(), customerCount: z.number().int().nullable().optional(), percent: z.number().optional(), period: z.string().nullable().optional(), quote: z.string().nullable().optional()}); export const customerConcentrationResponse = z.object({ticker: z.string().nullable().optional(), companyName: z.string().nullable().optional(), hasDisclosure: z.boolean().optional(), form: z.string().nullable().optional(), filedDate: z.string().nullable().optional(), filingUrl: z.string().nullable().optional(), headline: concentrationFigureDto.optional(), figures: z.array(concentrationFigureDto).nullable().optional(), missReason: z.string().nullable().optional(), lastScannedForm: z.string().nullable().optional(), lastScannedFiledDate: 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 }; /** * A company's verified narrative customer-concentration disclosure ("one customer accounted for 31% of revenue"): each figure's basis, customer count, percentage, period, and verbatim quote, with the source filing. hasDisclosure is false when this REST surface returns no narrative row — missReason then says why: current tagged XBRL served by the MCP tool, a scanned filing that stated nothing, a company outside coverage because it files only foreign private issuer reports (20-F, 40-F, 6-K) and no 10-K or 10-Q, or a company not processed yet. A newer narrative supersedes stale tags. Never a statement of no risk. * * GET /v1/stocks/{ticker}/customer-concentration */ export const getApiV1StocksTickerCustomerConcentration = async (args: GetApiV1StocksTickerCustomerConcentrationArgs, options?: GetApiV1StocksTickerCustomerConcentrationOptions) => { 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))}/customer-concentration${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(customerConcentrationResponse, await res.json()) };