export type SubmitKycDto = {email: string, fields?: Record | undefined, countryCode: string, provider: 'FONBNK' | 'ONRAMP_MONEY' | 'GUARDARIAN' | 'YELLOW_CARD', fiatCurrency: string, callbackUrl?: string | undefined, amountUsd?: number | undefined}; export type CreateApiKycSubmitArgs = {body: SubmitKycDto}; export type CreateApiKycSubmitOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Submit KYC fields and start any required verification * * POST /kyc/submit */ export const createApiKycSubmit = async (args: CreateApiKycSubmitArgs, options?: CreateApiKycSubmitOptions) => { const {baseUrl = "https://api.chainrails.io/api/v1", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiKey !== undefined) headers.set('authorization', `Bearer ${apiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/kyc/submit${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };