import {z} from 'zod' export type GetApiV1AccountsAccountIdConfigurationArgs = {accountId: string}; export type GetApiV1AccountsAccountIdConfigurationOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const accountStatus = z.enum(["ACTIVE", "INACTIVE", "CREATING"]); export const accountType = z.enum(["CREDIT", "CASH"]); export const beneficiaryType = z.literal("CORPORATE"); export const bankInstructionAddress = z.object({addressLine1: z.string(), addressLine2: z.string().optional(), city: z.string(), region: z.string(), country: z.string(), postalCode: z.string().optional()}); export const depositBankInstruction = z.object({currency: z.string().optional(), beneficiaryType: beneficiaryType.optional(), beneficiaryLegalName: z.string().optional(), beneficiaryAddress: bankInstructionAddress.optional(), beneficiaryBankName: z.string().optional(), beneficiaryBankAddress: bankInstructionAddress.optional(), beneficiaryBankBic: z.string().optional(), routingCode: z.string().nullable().optional(), beneficiaryAccountNumber: z.string().optional(), beneficiaryBankMemo: z.string().nullable().optional(), intermediaryBankName: z.string().nullable().optional(), intermediaryBankAddress: bankInstructionAddress.optional(), intermediaryBankBic: z.string().nullable().optional(), intermediaryAccountNumber: z.string().nullable().optional()}); export const getApiV1AccountsAccountIdConfigurationResponse = z.object({accountId: z.string().optional(), accountStatus: accountStatus.optional(), creditLimit: z.string().optional(), accountType: accountType.optional(), tradeStrategyEnablement: z.array(z.literal("RFQ")).optional(), pairEnablement: z.array(z.enum(["BTC-USD", "ETH-USD"])).optional(), depositBankInstructions: z.array(depositBankInstruction).optional(), depositWallets: z.array(z.object({asset: z.string().optional(), network: z.string().optional(), address: z.string().optional()})).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 Account Configuration * * GET /v1/accounts/{accountId}/configuration */ export const getApiV1AccountsAccountIdConfiguration = async (args: GetApiV1AccountsAccountIdConfigurationArgs, options?: GetApiV1AccountsAccountIdConfigurationOptions) => { const {baseUrl = "https://cams.aquanow.com/api", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounts/${encodeURIComponent(String(args.accountId))}/configuration${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(getApiV1AccountsAccountIdConfigurationResponse, await res.json()) };