import {z} from 'zod' export type GetApiV1CompaniesCodeOwnershipSignalsArgs = {code: string, signal_type?: (string | null) | undefined, include_trivial?: boolean | undefined, as_of?: (string | null) | undefined, limit?: number | undefined, offset?: number | undefined, cursor?: (string | null) | undefined}; export type GetApiV1CompaniesCodeOwnershipSignalsOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const ownershipSignalOut = z.object({signal_type: z.string(), filer_code: z.string(), filer_name: z.string().nullable().optional(), filer_name_en: z.string().nullable().optional(), issuer_security_code: z.string(), issuer_name: z.string().nullable().optional(), issuer_name_en: z.string().nullable().optional(), detected_date: z.string(), holding_ratio_pct: z.number().nullable().optional(), delta_pct: z.number().nullable().optional(), confidence: z.number(), doc_id: z.string().nullable().optional(), tier: z.number().int().optional(), metadata: z.record(z.string(), z.unknown()).nullable().optional()}); export const axioraApiSchemasMeta = z.record(z.string(), z.unknown()); export const listResponseOwnershipSignalOut = z.object({data: z.array(ownershipSignalOut), 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 Signals * * GET /v1/companies/{code}/ownership/signals */ export const getApiV1CompaniesCodeOwnershipSignals = async (args: GetApiV1CompaniesCodeOwnershipSignalsArgs, options: GetApiV1CompaniesCodeOwnershipSignalsOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.signal_type != null) query.append("signal_type", String(args.signal_type)) if (args.include_trivial != null) query.append("include_trivial", String(args.include_trivial)) if (args.as_of != null) query.append("as_of", String(args.as_of)) 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))}/ownership/signals${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(listResponseOwnershipSignalOut, await res.json()) };