Private
Public Access
1
0

refacto: Keeping entrypoints clean and making files by purpose

This commit is contained in:
gauvainboiche
2026-03-29 13:28:18 +02:00
parent 79cf3ca13e
commit 84af90e81e
13 changed files with 1198 additions and 1167 deletions

51
public/src/api.js Normal file
View File

@@ -0,0 +1,51 @@
// ── Raw HTTP wrappers ─────────────────────────────────────────────────────────
// These functions only perform fetch() calls and return the raw Response or
// parsed JSON. No state mutations, no DOM access.
export async function apiFetchConfig(team) {
const res = await fetch(`/api/config?team=${encodeURIComponent(team)}`);
if (!res.ok) throw new Error("config_fetch_failed");
return res.json();
}
export async function apiFetchScores() {
const res = await fetch("/api/scores");
if (!res.ok) throw new Error("scores_fetch_failed");
return res.json();
}
/** Returns the raw Response so the caller can inspect status codes (410, etc.). */
export async function apiFetchGrid(seed) {
return fetch(`/api/grid/${encodeURIComponent(seed)}`);
}
/** Returns the raw Response so the caller can inspect status codes (409, 410, etc.). */
export async function apiRevealCell(seed, x, y, team) {
return fetch("/api/cell/reveal", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ seed, x, y, team }),
});
}
export async function apiLogin(username, password) {
return fetch("/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
});
}
export async function apiRegister(username, email, password, team) {
return fetch("/api/auth/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, email, password, team }),
});
}
export async function apiGetMe(token) {
return fetch("/api/auth/me", {
headers: { Authorization: `Bearer ${token}` },
});
}