export type GetApiRampCountriesArgs = {currency?: string | undefined, amount?: number | undefined, type?: ('on-ramp' | 'off-ramp') | undefined}; export type GetApiRampCountriesOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * List supported countries * * GET /ramp/countries */ export const getApiRampCountries = async (args: GetApiRampCountriesArgs, options?: GetApiRampCountriesOptions) => { const {baseUrl = "https://api.chainrails.io/api/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.currency != null) query.append("currency", String(args.currency)) if (args.amount != null) query.append("amount", String(args.amount)) if (args.type != null) query.append("type", String(args.type)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/ramp/countries${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 };