export type Address = {city: string, country: string, postalCode: string, state?: string | undefined, streetLineOne: string, streetLineTwo?: string | undefined}; export type FiatPayoutMethod = {details: {bankName?: string | undefined, accountType: string, routingNumber: string, accountNumber: string, beneficiaryAddress: Address, bankAddress: Address} | {phoneNumber: string} | {iban: string}, owner: string, type: 'PAYOUT_TO_BANK' | 'ACH' | 'SEPA' | 'MOBILE_MONEY' | 'NG_BANK_TRANSFER' | 'ZA_BANK_TRANSFER'}; export type HeadlessOrderOfframpRequest = {customerId: string, destinationCurrencyCode: string, externalSubaccountCustomerId?: string | undefined, fiatPayoutMethod: FiatPayoutMethod, serviceProvider: 'NOAH' | 'DUENETWORK' | 'BRALE' | 'YELLOWCARD', sourceAmount: number, sourceCurrencyCode: string, sourceWalletAddress: string, subaccountCustomerId?: string | undefined}; export type CreateApiCryptoOrderHeadlessOfframpArgs = {'X-Idempotency-Key'?: string | undefined, body: HeadlessOrderOfframpRequest}; export type CreateApiCryptoOrderHeadlessOfframpOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a headless offramp order * * POST /crypto/order/headless/offramp */ export const createApiCryptoOrderHeadlessOfframp = async (args: CreateApiCryptoOrderHeadlessOfframpArgs, options?: CreateApiCryptoOrderHeadlessOfframpOptions) => { const {baseUrl = "https://api-sb.meld.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (args['X-Idempotency-Key'] != null) headers.set("X-Idempotency-Key", String(args['X-Idempotency-Key'])) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/crypto/order/headless/offramp${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 res.blob() };