import {z} from 'zod' export type GetApiNftsOwnershipAssetsArgs = {ncwId?: string | undefined, walletType?: ('VAULT_ACCOUNT' | 'END_USER_WALLET') | undefined, pageCursor?: string | undefined, pageSize?: number | undefined, sort?: Array<'name'> | undefined, order?: ('DESC' | 'ASC') | undefined, status?: ('LISTED' | 'ARCHIVED') | undefined, search?: string | undefined, spam?: ('true' | 'false' | 'all') | undefined}; export type GetApiNftsOwnershipAssetsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const paging = z.object({next: z.string()}); export const mediaEntityResponse = z.object({url: z.string(), contentType: z.enum(["IMAGE", "VIDEO", "ANIMATION", "THREE_D", "TEXT", "GIF", "UNKNOWN_TYPE", "SVG", "AUDIO"])}); export const spamTokenResponse = z.object({result: z.boolean()}); export const tokenCollectionResponse = z.object({id: z.string(), name: z.string().optional(), symbol: z.string().optional()}); export const tokenResponse = z.object({id: z.string(), tokenId: z.string(), standard: z.string(), metadataURI: z.string().optional(), cachedMetadataURI: z.string().optional(), media: z.array(mediaEntityResponse).optional(), spam: spamTokenResponse.optional(), collection: tokenCollectionResponse.optional(), blockchainDescriptor: z.enum(["ETH", "ETH_TEST3", "ETH_TEST5", "ETH_TEST6", "POLYGON", "POLYGON_TEST_MUMBAI", "AMOY_POLYGON_TEST", "XTZ", "XTZ_TEST", "BASECHAIN_ETH", "BASECHAIN_ETH_TEST3", "BASECHAIN_ETH_TEST5", "ETHERLINK", "ETHERLINK_TEST", "MANTLE", "MANTLE_TEST", "GUN_GUNZILLA", "GUN_GUNZILLA_TEST", "ETH_SONEIUM", "SONEIUM_MINATO_TEST", "IOTX_IOTEX", "KLAY_KAIA", "KLAY_KAIA_TEST", "APECHAIN", "APECHAIN_TEST", "CRONOS", "CRONOS_TEST", "ROBINHOOD_CHAIN_TESTNET_TEST", "ARB"]), description: z.string().optional(), name: z.string().optional()}); export const listOwnedTokensResponse = z.object({paging: paging.optional(), data: z.array(tokenResponse).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 all distinct owned tokens (paginated) * * GET /nfts/ownership/assets */ export const getApiNftsOwnershipAssets = async (args: GetApiNftsOwnershipAssetsArgs, options?: GetApiNftsOwnershipAssetsOptions) => { 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.ncwId != null) query.append("ncwId", String(args.ncwId)) if (args.walletType != null) query.append("walletType", String(args.walletType)) if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) for (const item of args.sort ?? []) query.append("sort", String(item)) if (args.order != null) query.append("order", String(args.order)) if (args.status != null) query.append("status", String(args.status)) if (args.search != null) query.append("search", String(args.search)) if (args.spam != null) query.append("spam", String(args.spam)) const url = `${baseUrl.replace(/\/+$/, '')}/nfts/ownership/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(listOwnedTokensResponse, await res.json()) };