import {z} from 'zod' export type GetApiTaxonomyMetadataAssetsArgs = {version?: string | undefined, start_time?: string | undefined, end_time?: string | undefined, start_inclusive?: boolean | undefined, end_inclusive?: boolean | undefined, page_size?: number | undefined, paging_from?: ('start' | 'end') | undefined, next_page_token?: string | undefined, pretty?: boolean | undefined}; export type GetApiTaxonomyMetadataAssetsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const taxonomyVersion = z.string(); export const taxonomyVersionStartTime = z.string(); export const taxonomyVersionEndTime = z.string(); export const taxonomyMetadataSubsectorClassId = z.string(); export const taxonomyMetadataSubsectorClass = z.string(); export const taxonomyMetadataSubsectorSectorId = z.string(); export const taxonomyMetadataSubsectorSector = z.string(); export const taxonomyMetadataSubsectorSubsectorId = z.string(); export const taxonomyMetadataSubsectorSubsector = z.string(); export const taxonomyMetadataSubsector = z.object({class_id: taxonomyMetadataSubsectorClassId.optional(), class: taxonomyMetadataSubsectorClass.optional(), sector_id: taxonomyMetadataSubsectorSectorId.optional(), sector: taxonomyMetadataSubsectorSector.optional(), subsector_id: taxonomyMetadataSubsectorSubsectorId.optional(), subsector: taxonomyMetadataSubsectorSubsector.optional()}); export const taxonomyMetadataSubsectors = z.array(taxonomyMetadataSubsector); export const taxonomyMetadataAsset = z.object({taxonomy_version: taxonomyVersion, taxonomy_start_time: taxonomyVersionStartTime, taxonomy_end_time: taxonomyVersionEndTime.optional(), subsectors: taxonomyMetadataSubsectors}); export const nextPageToken = z.string(); export const nextPageUrl = z.string(); export const taxonomyMetadataAssetsResponse = z.object({data: z.array(taxonomyMetadataAsset), 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 }; /** * Taxonomy metadata for assets * * GET /taxonomy-metadata/assets */ export const getApiTaxonomyMetadataAssets = async (args: GetApiTaxonomyMetadataAssetsArgs, options?: GetApiTaxonomyMetadataAssetsOptions) => { 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.version != null) query.append("version", String(args.version)) if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.start_inclusive != null) query.append("start_inclusive", String(args.start_inclusive)) if (args.end_inclusive != null) query.append("end_inclusive", String(args.end_inclusive)) 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(/\/+$/, '')}/taxonomy-metadata/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(taxonomyMetadataAssetsResponse, await res.json()) };