import {z} from 'zod' export type GetApiProfileNetworksArgs = {networks?: Array | undefined, full_names?: Array | undefined, page_size?: number | undefined, paging_from?: ('start' | 'end') | undefined, next_page_token?: string | undefined, pretty?: boolean | undefined}; export type GetApiProfileNetworksOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const networkProfileFullName = z.string(); export const networkProfileNetwork = z.string(); export const networkProfileOverview = z.string(); export const networkProfileConsensusMechanism = z.string(); export const networkProfileHashingAlgorithm = z.string(); export const networkProfileTransactionFinality = z.string(); export const networkProfileAvailableClient = z.string(); export const networkProfileSmartContractDeployment = z.string(); export const networkProfileFoundation = z.string(); export const networkProfileFoundingTeamIdentity = z.string(); export const networkProfileRepositoryGithubRepository = z.string(); export const networkProfileRepositoryGithubUrl = z.string(); export const networkProfileRepository = z.object({github_repository: networkProfileRepositoryGithubRepository.optional(), github_url: networkProfileRepositoryGithubUrl.optional()}); export const networkProfileTransactionVisibility = z.string(); export const networkProfileNativeFeeToken = z.string(); export const networkProfileSignificantHistoricalChangesDate = z.string(); export const networkProfileSignificantHistoricalChangesDetails = z.string(); export const networkProfileSignificantHistoricalChange = z.object({date: networkProfileSignificantHistoricalChangesDate.optional(), details: networkProfileSignificantHistoricalChangesDetails.optional()}); export const networkProfileUpgradeHistoryDate = z.string(); export const networkProfileUpgradeHistoryDetails = z.string(); export const networkProfileUpgradeHistory = z.object({date: networkProfileUpgradeHistoryDate.optional(), details: networkProfileUpgradeHistoryDetails.optional()}); export const networkProfileRollupInfoRollupType = z.string(); export const networkProfileRollupInfoStateValidation = z.string(); export const networkProfileRollupInfo = z.object({rollup_type: networkProfileRollupInfoRollupType.optional(), state_validation: networkProfileRollupInfoStateValidation.optional()}); export const networkProfileModularOrMonolithic = z.string(); export const networkProfileNetworkScalingSolution = z.string(); export const networkProfileTypeOfNetwork = z.string(); export const networkProfileProfileChainExplorer = z.string(); export const networkProfileInfo = z.object({full_name: networkProfileFullName, network: networkProfileNetwork, overview: networkProfileOverview.optional(), consensus_mechanism: networkProfileConsensusMechanism.optional(), hashing_algorithm: networkProfileHashingAlgorithm.optional(), transaction_finality: networkProfileTransactionFinality.optional(), available_clients: z.array(networkProfileAvailableClient).optional(), smart_contract_deployment: networkProfileSmartContractDeployment.optional(), foundation: z.array(networkProfileFoundation).optional(), founding_team_identity: networkProfileFoundingTeamIdentity.optional(), repository: z.array(networkProfileRepository).optional(), transaction_visibility: networkProfileTransactionVisibility.optional(), native_fee_token: networkProfileNativeFeeToken.optional(), significant_historical_changes: z.array(networkProfileSignificantHistoricalChange).optional(), upgrade_history: z.array(networkProfileUpgradeHistory).optional(), rollup_info: z.array(networkProfileRollupInfo).optional(), modular_or_monolithic: networkProfileModularOrMonolithic, network_scaling_solution: networkProfileNetworkScalingSolution.optional(), type_of_network: networkProfileTypeOfNetwork.optional(), chain_explorers: z.array(networkProfileProfileChainExplorer).optional()}); export const nextPageToken = z.string(); export const nextPageUrl = z.string(); export const networkProfilesResponse = z.object({data: z.array(networkProfileInfo), next_page_token: nextPageToken.optional(), next_page_url: nextPageUrl.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 }; /** * Network profiles data (experimental) * * GET /profile/networks */ export const getApiProfileNetworks = async (args: GetApiProfileNetworksArgs, options?: GetApiProfileNetworksOptions) => { const {baseUrl = "https://api.coinmetrics.io/v4", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.networks != null) query.append("networks", args.networks.join(',')) if (args.full_names != null) query.append("full_names", args.full_names.join(',')) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.paging_from != null) query.append("paging_from", String(args.paging_from)) if (args.next_page_token != null) query.append("next_page_token", String(args.next_page_token)) if (args.pretty != null) query.append("pretty", String(args.pretty)) if (apiKey !== undefined) query.set("api_key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/profile/networks${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(networkProfilesResponse, await res.json()) };