import {z} from 'zod' export type GetApiInternalWalletsWalletIdAssetsArgs = {walletId: string, pageSize?: number | undefined, pageCursor?: string | undefined}; export type GetApiInternalWalletsWalletIdAssetsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const configChangeRequestStatus = z.enum(["WAITING_FOR_APPROVAL", "APPROVED", "CANCELLED", "REJECTED", "FAILED"]); export const walletAsset = z.object({id: z.string().optional(), balance: z.string().optional(), lockedAmount: z.string().optional(), status: configChangeRequestStatus.optional(), address: z.string().optional(), tag: z.string().optional(), activationTime: z.string().optional()}); export const unmanagedWallet = z.object({id: z.string(), name: z.string(), customerRefId: z.string().optional(), assets: z.array(walletAsset)}); export const paginatedAssetsResponse = z.object({total: z.number().optional(), data: unmanagedWallet, next: z.string().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 }; /** * List assets in an internal wallet (Paginated) * * GET /internal_wallets/{walletId}/assets */ export const getApiInternalWalletsWalletIdAssets = async (args: GetApiInternalWalletsWalletIdAssetsArgs, options?: GetApiInternalWalletsWalletIdAssetsOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) const url = `${baseUrl.replace(/\/+$/, '')}/internal_wallets/${encodeURIComponent(String(args.walletId))}/assets${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(paginatedAssetsResponse, await res.json()) };