import {z} from 'zod' export type GetApiLedgerV2WalletsProfilesArgs = {q?: string | undefined, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiLedgerV2WalletsProfilesOptions = {baseUrl?: string | undefined, Hawk?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiLedgerV2WalletsProfilesResponse = z.object({totalElements: z.number().int(), totalPages: z.number().int(), content: z.array(z.object({id: z.string(), currencies: z.array(z.enum(["USD", "EUR", "GBP", "USDT", "POL", "PYUSD", "BTC", "SOL", "BNB", "XRP", "ETH", "LTC", "USDC", "USDG", "TRX", "EURC", "DOGE"])), methods: z.array(z.enum(["ACH", "ACH_SAME_DAY", "FEDWIRE", "SWIFT", "FASTER_PAYMENT", "CHAPS", "SEPA_CT", "SEPA_INST", "RTP", "BOOK", "FEDNOW"]))})), pageable: z.object({pageNumber: z.number().int(), pageSize: z.number().int()}), hasNext: z.boolean()}); 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 wallet profiles * * GET /ledger/v2/wallets/profiles */ export const getApiLedgerV2WalletsProfiles = async (args: GetApiLedgerV2WalletsProfilesArgs, options?: GetApiLedgerV2WalletsProfilesOptions) => { const {baseUrl = "https://api.sandbox.bvnk.com", fetch: fetchFn = fetch, Hawk} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.q != null) query.append("q", String(args.q)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (Hawk !== undefined) headers.set("Authorization", Hawk) const url = `${baseUrl.replace(/\/+$/, '')}/ledger/v2/wallets/profiles${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(getApiLedgerV2WalletsProfilesResponse, await res.json()) };