import { useQuery } from '@tanstack/react-query' import { miscKeys } from './keys' import { fetchHandler } from '@/data/fetchers' import { BASE_PATH, IS_PLATFORM } from '@/lib/constants' import type { ResponseError, UseCustomQueryOptions } from '@/types' export async function getCLIReleaseVersion() { try { const data = await fetchHandler(`${BASE_PATH}/api/cli-release-version`).then((res) => res.json() ) return data as { current?: string; latest?: string; beta?: string; published_at?: string } } catch (error) { throw error } } export type CLIReleaseVersionData = Awaited> export type CLIReleaseVersionError = ResponseError export const useCLIReleaseVersionQuery = ({ enabled = true, ...options }: UseCustomQueryOptions = {}) => useQuery({ queryKey: miscKeys.cliReleaseVersion(), queryFn: () => getCLIReleaseVersion(), enabled: enabled && !IS_PLATFORM, ...options, })