import {z} from 'zod' export type PartnerFee = {currency?: ('USD' | 'EUR' | 'CNY' | 'HKD' | 'MXN' | 'BRL' | 'GBP' | 'AED' | 'INR' | 'PHP' | 'SGD' | 'JPY' | 'null' | null) | undefined, payment_rail?: ('US_ACH' | 'US_FEDWIRE' | 'US_RTP' | 'US_FEDNOW' | 'SWIFT' | 'LOCAL_BANK_TRANSFER' | 'CHATS' | 'FPS' | 'SPEI' | 'PIX_TRANSFER' | 'SEPA' | 'FASTER_PAYMENT' | 'UAEFTS' | 'UPI' | 'null' | null) | undefined, rate: string, fixed?: string | undefined, fee_type: 'FIAT_DEPOSIT'} | {currency?: ('USD' | 'EUR' | 'CNY' | 'HKD' | 'MXN' | 'BRL' | 'GBP' | 'AED' | 'INR' | 'PHP' | 'SGD' | 'JPY' | 'null' | null) | undefined, source_asset?: ('USD' | 'EUR' | 'CNY' | 'HKD' | 'MXN' | 'BRL' | 'GBP' | 'AED' | 'INR' | 'PHP' | 'SGD' | 'JPY' | 'USDC' | 'USDT' | 'null' | null) | undefined, payment_rail?: ('US_ACH' | 'US_FEDWIRE' | 'US_RTP' | 'US_FEDNOW' | 'SWIFT' | 'LOCAL_BANK_TRANSFER' | 'CHATS' | 'FPS' | 'SPEI' | 'PIX_TRANSFER' | 'SEPA' | 'FASTER_PAYMENT' | 'UAEFTS' | 'UPI' | 'null' | null) | undefined, rate: string, fixed?: string | undefined, fee_type: 'FIAT_WITHDRAWAL'} | {token?: ('USDC' | 'USDT' | 'PYUSD' | 'RLUSD' | 'USDG' | 'USDP' | 'USD1' | '1USD' | 'AUSD' | 'DAI' | 'EURC' | 'MXNB' | 'MEXAS' | 'GYEN' | 'BRL1' | 'BRLA' | 'COPM' | 'USTB' | 'BTC' | 'ETH' | 'SOL' | 'null' | null) | undefined, network?: ('AVALANCHE' | 'ETHEREUM' | 'POLYGON' | 'BNBCHAIN' | 'BASE' | 'ARBITRUM' | 'SOLANA' | 'TRON' | 'ONE_MONEY' | 'EMERALD' | 'BITCOIN' | 'null' | null) | undefined, rate: string, fixed?: string | undefined, fee_type: 'CRYPTO_WITHDRAWAL'} | {from_asset?: (string | null) | undefined, to_asset?: (string | null) | undefined, rate: string, reverse_rate?: string | undefined, from_asset_fixed?: string | undefined, to_asset_fixed?: string | undefined, fee_type: 'CONVERSION'}; export type ExternalId = string; export type PartnerFeeCreateRequest = {fee: PartnerFee, external_id: ExternalId}; export type CreateApiV1AccountsAccountIdPartnerFeesArgs = {account_id: string, body: PartnerFeeCreateRequest}; export type CreateApiV1AccountsAccountIdPartnerFeesOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const feeId = z.string(); export const accountId = z.string(); export const partnerFee = z.union([z.object({currency: z.enum(["USD", "EUR", "CNY", "HKD", "MXN", "BRL", "GBP", "AED", "INR", "PHP", "SGD", "JPY", "null"]).nullable().optional(), payment_rail: z.enum(["US_ACH", "US_FEDWIRE", "US_RTP", "US_FEDNOW", "SWIFT", "LOCAL_BANK_TRANSFER", "CHATS", "FPS", "SPEI", "PIX_TRANSFER", "SEPA", "FASTER_PAYMENT", "UAEFTS", "UPI", "null"]).nullable().optional(), rate: z.string(), fixed: z.string().optional(), fee_type: z.literal("FIAT_DEPOSIT")}), z.object({currency: z.enum(["USD", "EUR", "CNY", "HKD", "MXN", "BRL", "GBP", "AED", "INR", "PHP", "SGD", "JPY", "null"]).nullable().optional(), source_asset: z.enum(["USD", "EUR", "CNY", "HKD", "MXN", "BRL", "GBP", "AED", "INR", "PHP", "SGD", "JPY", "USDC", "USDT", "null"]).nullable().optional(), payment_rail: z.enum(["US_ACH", "US_FEDWIRE", "US_RTP", "US_FEDNOW", "SWIFT", "LOCAL_BANK_TRANSFER", "CHATS", "FPS", "SPEI", "PIX_TRANSFER", "SEPA", "FASTER_PAYMENT", "UAEFTS", "UPI", "null"]).nullable().optional(), rate: z.string(), fixed: z.string().optional(), fee_type: z.literal("FIAT_WITHDRAWAL")}), z.object({token: z.enum(["USDC", "USDT", "PYUSD", "RLUSD", "USDG", "USDP", "USD1", "1USD", "AUSD", "DAI", "EURC", "MXNB", "MEXAS", "GYEN", "BRL1", "BRLA", "COPM", "USTB", "BTC", "ETH", "SOL", "null"]).nullable().optional(), network: z.enum(["AVALANCHE", "ETHEREUM", "POLYGON", "BNBCHAIN", "BASE", "ARBITRUM", "SOLANA", "TRON", "ONE_MONEY", "EMERALD", "BITCOIN", "null"]).nullable().optional(), rate: z.string(), fixed: z.string().optional(), fee_type: z.literal("CRYPTO_WITHDRAWAL")}), z.object({from_asset: z.string().nullable().optional(), to_asset: z.string().nullable().optional(), rate: z.string(), reverse_rate: z.string().optional(), from_asset_fixed: z.string().optional(), to_asset_fixed: z.string().optional(), fee_type: z.literal("CONVERSION")})]); export const partnerFeeResponse = z.object({fee_id: feeId, account_id: accountId, fee: partnerFee, created_at: z.string(), modified_at: z.string()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * POST /v1/accounts/{account_id}/partner-fees */ export const createApiV1AccountsAccountIdPartnerFees = async (args: CreateApiV1AccountsAccountIdPartnerFeesArgs, options?: CreateApiV1AccountsAccountIdPartnerFeesOptions) => { const {baseUrl = "https://api.1money.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Authorization !== undefined) headers.set('authorization', `Bearer ${Authorization}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.account_id))}/partner-fees${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 validateResponse(partnerFeeResponse, await res.json()) };