import {z} from 'zod' export type GetApiApiV1BondsAnalyticsSymbolCashflowsResidualValueArgs = {symbol: string, from_date: string, to_date: string, settlement_entry: 'CI' | '24hs' | '48hs' | '72hs'}; export type GetApiApiV1BondsAnalyticsSymbolCashflowsResidualValueOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const residualValueDataPoint = z.object({operation_date: z.string(), settlement_entry: z.string(), settlement_date: z.string(), residual_value: z.number()}); export const residualValueResponse = z.array(residualValueDataPoint); 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 }; /** * Obtener la serie histórica de valor residual de un bono específico, filtrada por rango de fechas y plazo de liquidación * * GET /api/v1/bonds/analytics/{symbol}/cashflows/residual-value */ export const getApiApiV1BondsAnalyticsSymbolCashflowsResidualValue = async (args: GetApiApiV1BondsAnalyticsSymbolCashflowsResidualValueArgs, options?: GetApiApiV1BondsAnalyticsSymbolCashflowsResidualValueOptions) => { const {baseUrl = "https://api.doctacapital.com.ar", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from_date != null) query.append("from_date", String(args.from_date)) if (args.to_date != null) query.append("to_date", String(args.to_date)) if (args.settlement_entry != null) query.append("settlement_entry", String(args.settlement_entry)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/bonds/analytics/${encodeURIComponent(String(args.symbol))}/cashflows/residual-value${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(residualValueResponse, await res.json()) };