import {z} from 'zod' export type FeeId = string; export type PartnerFeeUpdateRequest = {rate?: (string | null) | undefined, fixed?: (string | null) | undefined, reverse_rate?: (string | null) | undefined}; export type PatchApiV1AccountsAccountIdPartnerFeesFeeIdArgs = {account_id: string, fee_id: FeeId, body: PartnerFeeUpdateRequest}; export type PatchApiV1AccountsAccountIdPartnerFeesFeeIdOptions = {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 }; /** * PATCH /v1/accounts/{account_id}/partner-fees/{fee_id} */ export const patchApiV1AccountsAccountIdPartnerFeesFeeId = async (args: PatchApiV1AccountsAccountIdPartnerFeesFeeIdArgs, options?: PatchApiV1AccountsAccountIdPartnerFeesFeeIdOptions) => { 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/${encodeURIComponent(String(args.fee_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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()) };