export type GetApiKycStateArgs = {provider: 'FONBNK' | 'ONRAMP_MONEY' | 'GUARDARIAN' | 'YELLOW_CARD', countryCode: string, fiatCurrency: string, userEmail: string, amountUsd?: number | undefined}; export type GetApiKycStateOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Inspect the current KYC state for a transaction * * GET /kyc/state */ export const getApiKycState = async (args: GetApiKycStateArgs, options?: GetApiKycStateOptions) => { const {baseUrl = "https://api.chainrails.io/api/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.provider != null) query.append("provider", String(args.provider)) if (args.countryCode != null) query.append("countryCode", String(args.countryCode)) if (args.fiatCurrency != null) query.append("fiatCurrency", String(args.fiatCurrency)) if (args.userEmail != null) query.append("userEmail", String(args.userEmail)) if (args.amountUsd != null) query.append("amountUsd", String(args.amountUsd)) if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/kyc/state${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 };