import {z} from 'zod' export type GetApiOnrampAccountsIdDetailsArgs = {id: string, 'x-api-key'?: string | undefined, authorization?: string | undefined}; export type GetApiOnrampAccountsIdDetailsOptions = {baseUrl?: string | undefined, complianceSessionBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const onrampAccountDetails = z.object({bankDetails: z.object({schemaVersion: z.literal(1), capturedAt: z.string(), currency: z.enum(["USD", "EUR"]), accountHolderName: z.string().min(1), bankName: z.string().min(1).optional(), bankAddress: z.object({street: z.string().min(1), street2: z.string().min(1).optional(), city: z.string().min(1), postCode: z.string().min(1), state: z.string().min(1), country: z.string()}).optional(), reference: z.string().min(1).optional(), rails: z.array(z.object({type: z.enum(["BankAch", "BankFedwire", "BankSwift", "BankSepa"]), accountNumber: z.string().min(1), bankCode: z.string().min(1), fee: z.object({currency: z.enum(["USD", "EUR"]), base: z.string().max(38), percent: z.string().max(38), minimum: z.string().max(38)})}))})}); 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 bank details for a funding account * * GET /onramp/accounts/{id}/details */ export const getApiOnrampAccountsIdDetails = async (args: GetApiOnrampAccountsIdDetailsArgs, options?: GetApiOnrampAccountsIdDetailsOptions) => { const {baseUrl = "https://v1.orchestrator.rhinestone.dev/deposit-processor", fetch: fetchFn = fetch, complianceSessionBearer} = 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.authorization != null) headers.set("authorization", String(args.authorization)) if (complianceSessionBearer !== undefined) headers.set('authorization', `Bearer ${complianceSessionBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/onramp/accounts/${encodeURIComponent(String(args.id))}/details${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(onrampAccountDetails, await res.json()) };