import {z} from 'zod' export type GetApiV1CompaniesCodeShareholdingsArgs = {code: string, date_from?: (string | null) | undefined, date_to?: (string | null) | undefined, report_type?: (string | null) | undefined, limit?: number | undefined, offset?: number | undefined, cursor?: (string | null) | undefined}; export type GetApiV1CompaniesCodeShareholdingsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const shareholdingOut = z.object({id: z.number().int(), filer_edinet_code: z.string(), issuer_security_code: z.string().nullable().optional(), issuer_name: z.string().nullable().optional(), holder_name: z.string().nullable().optional(), holder_type: z.string().nullable().optional(), shares_held: z.number().int().nullable().optional(), holding_ratio_pct: z.number().nullable().optional(), previous_holding_ratio_pct: z.number().nullable().optional(), total_outstanding_shares: z.number().int().nullable().optional(), purpose_of_holding: z.string().nullable().optional(), holding_purpose_category: z.enum(["pure_investment", "portfolio_investment", "cross_holding", "management_participation", "activist", "going_private", "tender_offer_offeror", "tender_offer_target", "trading_inventory", "other"]).nullable().optional(), purpose_confidence: z.number().gte(0).lte(1).nullable().optional(), purpose_classifier_version: z.string().nullable().optional(), purpose_retrospective_label: z.enum(["pure_investment", "portfolio_investment", "cross_holding", "management_participation", "activist", "going_private", "tender_offer_offeror", "tender_offer_target", "trading_inventory", "other"]).nullable().optional(), purpose_retrospective_cutoff: z.string().nullable().optional(), has_important_proposal: z.boolean().optional(), base_date: z.string(), report_type: z.string(), filing_reason: z.string().nullable().optional(), doc_id: z.string().nullable().optional()}); export const axioraApiSchemasMeta = z.record(z.string(), z.unknown()); export const listResponseShareholdingOut = z.object({data: z.array(shareholdingOut), meta: axioraApiSchemasMeta}); 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 }; /** * List Company Shareholdings * * GET /v1/companies/{code}/shareholdings */ export const getApiV1CompaniesCodeShareholdings = async (args: GetApiV1CompaniesCodeShareholdingsArgs, options: GetApiV1CompaniesCodeShareholdingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.report_type != null) query.append("report_type", String(args.report_type)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/companies/${encodeURIComponent(String(args.code))}/shareholdings${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(listResponseShareholdingOut, await res.json()) };