import { APIResponse, HttpMethod, normalizeAPIError } from './common'; interface ClientFetchRequestOptions extends RequestInit { method?: HttpMethod; body?: string; } 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' export * as SmsAPI from './endpoints/sms.client' export * as AdminAPI from './endpoints/admin.client' export * as OSSAPI from './endpoints/oss.client' export * as BlogAPI from './endpoints/blog.client'