export type GetApiExchangeRatesV1ConvertArgs = {base: string, target: string, amount?: string | undefined}; export type GetApiExchangeRatesV1ConvertOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Convert an amount from one currency to another. * * GET /exchange-rates/v1/convert */ export const getApiExchangeRatesV1Convert = async (args: GetApiExchangeRatesV1ConvertArgs, options?: GetApiExchangeRatesV1ConvertOptions) => { const {baseUrl = "https://api.orthogonal.com/mpp", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.base != null) query.append("base", String(args.base)) if (args.target != null) query.append("target", String(args.target)) if (args.amount != null) query.append("amount", String(args.amount)) const url = `${baseUrl.replace(/\/+$/, '')}/exchange-rates/v1/convert${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 undefined };