import {z} from 'zod' export type GetApiV1WalletsIdVirtualAccountsVIdTransactionsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1WalletsIdVirtualAccountsVIdTransactionsResponse = z.object({data: z.array(z.object({amlScreening: z.object({message: z.string().optional(), provider: z.string().optional(), status: z.string().optional()}).optional(), amount: z.string().optional(), amountPaid: z.string().optional(), amountUSD: z.string().optional(), asset: z.object({address: z.string().optional(), configurations: z.unknown(), createdAt: z.string().optional(), currency: z.string().optional(), decimals: z.number().optional(), id: z.string().optional(), isActive: z.boolean().optional(), isNative: z.boolean().optional(), name: z.string().optional(), network: z.string().optional(), standard: z.unknown(), symbol: z.string().optional(), updatedAt: z.string().optional()}).optional(), assetSwept: z.unknown(), assetSweptAmount: z.unknown(), assetSweptAt: z.unknown(), assetSweptGasFee: z.unknown(), assetSweptHash: z.unknown(), assetSweptRecipientAddress: z.unknown(), assetSweptSenderAddress: z.unknown(), blockHash: z.string().optional(), blockNumber: z.number().optional(), blockchain: z.object({configurations: z.unknown(), createdAt: z.string().optional(), derivationPath: z.string().optional(), id: z.string().optional(), isActive: z.boolean().optional(), isEvmCompatible: z.boolean().optional(), isL2: z.boolean().optional(), name: z.string().optional(), networkFeeModel: z.string().optional(), slug: z.string().optional(), symbol: z.string().optional(), tokenStandard: z.unknown(), updatedAt: z.string().optional()}).optional(), chainId: z.number().optional(), confirmations: z.number().optional(), confirmed: z.boolean().optional(), createdAt: z.string().optional(), createdChannel: z.string().optional(), currency: z.string().optional(), fee: z.unknown(), feeHash: z.unknown(), feeUSD: z.unknown(), gasFee: z.string().optional(), gasPrice: z.string().optional(), gasUsed: z.string().optional(), hash: z.string().optional(), id: z.string().optional(), isAutoSweep: z.boolean().optional(), metadata: z.object({autoFunding: z.object({narration: z.string().optional(), senderAccountName: z.string().optional(), senderBankName: z.string().optional(), sessionId: z.string().optional()}).optional()}).optional(), network: z.string().optional(), note: z.string().optional(), rate: z.unknown(), rateUSD: z.string().optional(), reason: z.unknown(), recipientAddress: z.string().optional(), reference: z.string().optional(), senderAddress: z.string().optional(), signedTransaction: z.unknown(), status: z.string().optional(), toAmount: z.unknown(), toCurrency: z.unknown(), tokenAddress: z.string().optional(), type: z.string().optional(), updatedAt: z.string().optional()})).optional(), message: z.string().optional(), meta: z.object({totalItems: z.number().optional(), itemCount: z.number().optional(), itemsPerPage: z.number().optional(), totalPages: z.number().optional(), currentPage: z.number().optional()}).optional(), statusCode: z.number().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 }; /** * Master Wallet Transactions * * GET /v1/wallets/{id}/virtual-accounts/{vId}/transactions */ export const getApiV1WalletsIdVirtualAccountsVIdTransactions = async (options?: GetApiV1WalletsIdVirtualAccountsVIdTransactionsOptions) => { const {baseUrl = "https://api.blockradar.co", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/wallets/${encodeURIComponent(String(args.id))}/virtual-accounts/${encodeURIComponent(String(args.vId))}/transactions${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(getApiV1WalletsIdVirtualAccountsVIdTransactionsResponse, await res.json()) };