export const apiRequest = (input: RequestInfo | URL, init: RequestInit = {}): Promise => fetch(input, { ...init, credentials: init.credentials ?? "same-origin" }); export const apiJsonRequest = ( input: RequestInfo | URL, body: unknown, init: Omit = {}, ): Promise => apiRequest(input, { ...init, headers: { "content-type": "application/json", ...init.headers }, body: JSON.stringify(body), }); export const responseMessage = async (res: Response, fallback: string): Promise => { const body = (await res.json().catch(() => null)) as { message?: unknown } | null; return typeof body?.message === "string" && body.message.length > 0 ? body.message : fallback; };