import { APIResponse, HttpMethod, normalizeAPIError } from './common'; interface ClientFetchRequestOptions extends RequestInit { method?: HttpMethod; body?: any; } export async function clientFetch( endpoint: string, options: ClientFetchRequestOptions = {} ): Promise { const defaultHeaders: HeadersInit = { 'Content-Type': 'application/json', }; try { const response = await fetch(endpoint, { method: options.method || 'GET', headers: { ...defaultHeaders, ...options.headers, }, body: options.body ?? JSON.stringify(options.body), credentials: 'include', ...options, }); if (!response.ok) { const errorText = await response.text(); throw JSON.parse(errorText); } const data: APIResponse = await response.json(); if (!data.success) { throw data; } return data.data as T; } catch (error) { normalizeAPIError(error); } } export * as AuthAPI from './endpoints/auth.client' export * as UserAPI from './endpoints/user.client'