import {z} from 'zod' export type ExternalId = string; export type PartnerFeeType = 'FIAT_DEPOSIT' | 'FIAT_WITHDRAWAL' | 'CRYPTO_WITHDRAWAL' | 'CONVERSION'; export type ChronoDateTimeSchema = string; export type SortOrder = 'ASC' | 'DESC'; export type GetApiV1AccountsAccountIdPartnerFeesArgs = {account_id: string, external_id?: ExternalId | undefined, include_sub_accounts?: boolean | undefined, fee_type?: PartnerFeeType | undefined, created_after?: ChronoDateTimeSchema | undefined, created_before?: ChronoDateTimeSchema | undefined, sort_order?: SortOrder | undefined, pagination: {page?: number | undefined, size?: number | undefined}}; export type GetApiV1AccountsAccountIdPartnerFeesOptions = {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 partnerFeeListResponse = z.object({items: z.array(partnerFeeResponse), total: z.number().int().gte(0).nullable().optional()}); 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 }; /** * GET /v1/accounts/{account_id}/partner-fees */ export const getApiV1AccountsAccountIdPartnerFees = async (args: GetApiV1AccountsAccountIdPartnerFeesArgs, options?: GetApiV1AccountsAccountIdPartnerFeesOptions) => { const {baseUrl = "https://api.1money.com", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.external_id != null) query.append("external_id", String(args.external_id)) if (args.include_sub_accounts != null) query.append("include_sub_accounts", String(args.include_sub_accounts)) if (args.fee_type != null) query.append("fee_type", String(args.fee_type)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.pagination != null) query.append("pagination", JSON.stringify(args.pagination)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(partnerFeeListResponse, await res.json()) };