export type CreateApiV1ReferralAddressArgs = {address: string, referral: string, 'x-verify': string}; export type CreateApiV1ReferralAddressOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Bind new referral * * POST /v1/referral/{address} */ export const createApiV1ReferralAddress = async (args: CreateApiV1ReferralAddressArgs, options?: CreateApiV1ReferralAddressOptions) => { const {baseUrl = "https://backend.swap.coffee", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.referral != null) query.append("referral", String(args.referral)) if (args['x-verify'] != null) headers.set("x-verify", String(args['x-verify'])) if (ApiKey !== undefined) headers.set("X-Api-Key", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/referral/${encodeURIComponent(String(args.address))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };