import { type Method, createFetch } from '@better-fetch/fetch'; import type { HeadersInit } from 'bun'; const apiClient = createFetch({ baseURL: 'https://api.ez-pp.farm/', throw: true, }); export type ApiResponse = { data: T; error: undefined } | { data: undefined; error: Error }; export const fetchApi = async ( route: string, options?: { query?: Record; headers?: HeadersInit; method?: Method; params?: Record; timeout?: number; signal?: AbortSignal; } ): Promise> => { try { const data = await apiClient(route, { query: options?.query, headers: options?.headers ?? { accept: 'application/json', }, method: options?.method ?? 'GET', params: options?.params, timeout: options?.timeout, signal: options?.signal, }); return { data, error: undefined }; } catch (err) { return { data: undefined, error: err as Error }; } };