import {z} from 'zod' export type GetApiV1CustomersCustomerIdTreasuryArgs = {'X-API-Key'?: string | undefined, customerId: string, treasuryId?: string | undefined, view?: ('PORTFOLIO' | 'OVERVIEW') | undefined}; export type GetApiV1CustomersCustomerIdTreasuryOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const moneyOutputDto = z.object({currency: z.string(), exponent: z.number(), value: z.string(), displayValue: z.string()}); export const treasuryBalanceDto = z.object({available: moneyOutputDto, pending: moneyOutputDto.nullable().optional(), unallocated: moneyOutputDto.nullable().optional()}); export const treasuryFundingMethodDto = z.object({id: z.string(), type: z.enum(["BANK_ACCOUNT", "CRYPTO_ADDRESS"]), provider: z.enum(["BRALE", "BRIDGE", "CAPA", "CODEX", "DUE", "EREBOR", "INFINIA", "MANSA", "MESTA", "ONE_MONEY", "STABLES", "TURNKEY", "PRIVY", "INFINITE", "SOCURE", "SARDINE"]), currency: z.string().optional(), currencyCodes: z.array(z.string()).optional(), rail: z.string().optional(), rails: z.array(z.string()).optional(), bankName: z.string().optional(), beneficiaryName: z.string().optional(), accountNumber: z.string().optional(), routingNumber: z.string().optional(), iban: z.string().optional(), swiftBic: z.string().optional(), address: z.string().optional(), addressType: z.enum(["EVM", "TRON", "BITCOIN", "SOLANA"]).optional(), chains: z.array(z.enum(["ETHEREUM", "BASE", "POLYGON", "SOLANA", "TRON", "BITCOIN", "ARBITRUM", "ROBINHOOD"])).optional()}); export const walletTokenBalanceDto = z.object({currency: z.string(), balance: moneyOutputDto, chain: z.string()}); export const treasuryWalletDto = z.object({accountId: z.string(), address: z.string(), addressType: z.enum(["EVM", "TRON", "BITCOIN", "SOLANA"]), balances: z.array(walletTokenBalanceDto)}); export const treasuryDto = z.object({id: z.string(), name: z.string().nullable().optional(), provider: z.enum(["BRALE", "BRIDGE", "CAPA", "CODEX", "DUE", "EREBOR", "INFINIA", "MANSA", "MESTA", "ONE_MONEY", "STABLES", "TURNKEY", "PRIVY", "INFINITE", "SOCURE", "SARDINE"]).optional(), balances: z.record(z.string(), treasuryBalanceDto), fundingMethods: z.array(treasuryFundingMethodDto), wallets: z.array(treasuryWalletDto)}); export const customerTreasuryResponseDto = z.object({customerId: z.string(), treasuries: z.array(treasuryDto)}); 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 customer treasury balances * * GET /v1/customers/{customerId}/treasury */ export const getApiV1CustomersCustomerIdTreasury = async (args: GetApiV1CustomersCustomerIdTreasuryArgs, options?: GetApiV1CustomersCustomerIdTreasuryOptions) => { const {baseUrl = "https://sandbox.api.infinite.dev", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (args.treasuryId != null) query.append("treasuryId", String(args.treasuryId)) if (args.view != null) query.append("view", String(args.view)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/customers/${encodeURIComponent(String(args.customerId))}/treasury${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(customerTreasuryResponseDto, await res.json()) };