import {z} from 'zod' export type GetApiServicesMultichainApiV1ClustersClusterIdChainsArgs = {cluster_id: string, sort?: string | undefined, order?: string | undefined}; export type GetApiServicesMultichainApiV1ClustersClusterIdChainsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const v1Chain = z.object({explorer_url: z.string().optional(), icon_url: z.string().optional(), id: z.string().optional(), name: z.string().optional()}); export const v1ListClusterChainsResponse = z.object({items: z.array(v1Chain).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 }; /** * Lists all chains in the cluster, optionally sorted by a metric (e.g. active_accounts, tps). * * GET /services/multichain/api/v1/clusters/{cluster_id}/chains * * Also accepts auth: apiKeyAuth */ export const getApiServicesMultichainApiV1ClustersClusterIdChains = async (args: GetApiServicesMultichainApiV1ClustersClusterIdChainsArgs, options?: GetApiServicesMultichainApiV1ClustersClusterIdChainsOptions) => { const {baseUrl = "https://api.blockscout.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/services/multichain/api/v1/clusters/${encodeURIComponent(String(args.cluster_id))}/chains${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(v1ListClusterChainsResponse, await res.json()) };