import {z} from 'zod' export type GetApiV1StocksTickerSupplyChainArgs = {ticker: string, side?: string | undefined, quantifiedOnly?: boolean | undefined, lens?: string | undefined, limit?: number | undefined}; export type GetApiV1StocksTickerSupplyChainOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const supplyChainFilingDto = z.object({form: z.string().nullable().optional(), filedDate: z.string().optional(), filingUrl: z.string().nullable().optional()}); export const supplyChainCountsDto = z.object({customers: z.number().int().optional(), suppliers: z.number().int().optional(), competitors: z.number().int().optional(), partners: z.number().int().optional()}); export const supplyChainTopShareDto = z.object({name: z.string().nullable().optional(), ticker: z.string().nullable().optional(), percent: z.number().optional(), isFloor: z.boolean().optional(), period: z.string().nullable().optional()}); export const supplyChainOverviewDto = z.object({namedCustomerShare: z.number().nullable().optional(), namedCustomerShareIsFloor: z.boolean().optional(), namedCustomerCount: z.number().int().optional(), namedCustomerPeriod: z.string().nullable().optional(), largestCustomer: supplyChainTopShareDto.optional(), mostReliantSupplier: supplyChainTopShareDto.optional()}); export const supplyChainOrganizationDto = z.object({slug: z.string().nullable().optional(), url: z.string().nullable().optional()}); export const supplyChainShareDto = z.object({percent: z.number().nullable().optional(), percentFloor: z.number().nullable().optional(), basis: z.string().nullable().optional(), period: z.string().nullable().optional()}); export const supplyChainShareValueDto = z.object({amountUsd: z.number().optional(), isFloor: z.boolean().optional(), revenueUsd: z.number().optional(), revenuePeriodEnd: z.string().optional(), customerRevenueShare: z.number().nullable().optional(), customerRevenueUsd: z.number().nullable().optional(), customerRevenuePeriodEnd: z.string().nullable().optional()}); export const supplyChainStatementDto = z.object({statedBy: z.string().nullable().optional(), isOwnFiling: z.boolean().optional(), form: z.string().nullable().optional(), filedDate: z.string().optional(), filingUrl: z.string().nullable().optional(), quote: z.string().nullable().optional(), role: z.string().nullable().optional(), via: z.string().nullable().optional(), share: supplyChainShareDto.optional(), value: supplyChainShareValueDto.optional()}); export const supplyChainCompanyDto = z.object({name: z.string().nullable().optional(), ticker: z.string().nullable().optional(), organization: supplyChainOrganizationDto.optional(), partOf: z.string().nullable().optional(), depth: z.number().int().nullable().optional(), competitorNamedBy: z.string().nullable().optional(), statements: z.array(supplyChainStatementDto).nullable().optional()}); export const supplyChainResponse = z.object({ticker: z.string().nullable().optional(), companyName: z.string().nullable().optional(), annualReport: supplyChainFilingDto.optional(), namedOnlyByOthers: z.boolean().optional(), locked: z.boolean().optional(), upgradeUrl: z.string().nullable().optional(), counts: supplyChainCountsDto.optional(), overview: supplyChainOverviewDto.optional(), customers: z.array(supplyChainCompanyDto).nullable().optional(), suppliers: z.array(supplyChainCompanyDto).nullable().optional(), competitors: z.array(supplyChainCompanyDto).nullable().optional(), partners: z.array(supplyChainCompanyDto).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 customers, suppliers, competitors and partners named in annual 10-K reports: its own and those of other listed companies that name it, each with the verbatim sentence, the source filing, any revenue or receivables share the filing states and, for a revenue share, its dollar amount from the same filing's revenue. Competitors carry who names the rivalry. A missing company is not evidence of no relationship. Requires the Pro plan; other plans get the counts and the unnamed overview. * * GET /v1/stocks/{ticker}/supply-chain */ export const getApiV1StocksTickerSupplyChain = async (args: GetApiV1StocksTickerSupplyChainArgs, options?: GetApiV1StocksTickerSupplyChainOptions) => { 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.side != null) query.append("side", String(args.side)) if (args.quantifiedOnly != null) query.append("quantifiedOnly", String(args.quantifiedOnly)) if (args.lens != null) query.append("lens", String(args.lens)) if (args.limit != null) query.append("limit", String(args.limit)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/stocks/${encodeURIComponent(String(args.ticker))}/supply-chain${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(supplyChainResponse, await res.json()) };