/home/techb158/cosmic-risk.abdallabala.com/src/lib
NameSizeModeActions
api-client.js10120644editdlrm
crypto.js16770644editdlrm
email.js21750644editdlrm
http.js5630644editdlrm
idempotency.js5700644editdlrm
metrics.js10610644editdlrm
oidc.js17300644editdlrm
prisma.js2800644editdlrm
rate-limit.js26620644editdlrm
redis.js35170644editdlrm
request-context.js37250644editdlrm
tenant-guard.js14270644editdlrm
Edit: /home/techb158/cosmic-risk.abdallabala.com/src/lib/api-client.js (1012B)
const BASE = ''; async function request(method, path, body) { const opts = { method, headers: { 'Content-Type': 'application/json' } }; if (body) opts.body = JSON.stringify(body); const res = await fetch(`${BASE}${path}`, opts); const data = res.headers.get('content-type')?.includes('application/json') ? await res.json() : await res.text(); if (!res.ok) throw new Error(data?.error || data?.message || `Request failed (${res.status})`); return data; } export const api = { get: (path) => request('GET', path), post: (path, body) => request('POST', path, body), put: (path, body) => request('PUT', path, body), patch: (path, body) => request('PATCH', path, body), del: (path) => request('DELETE', path), }; export async function getSession() { try { const data = await api.get('/api/auth/session'); return data.user || data.actor || null; } catch { return null; } } export async function logout() { await api.post('/api/auth/logout'); window.location.href = '/'; }