Add a Compte section with a privacy notice and a confirmed deletion that anonymises the player row, erases their possessions and cancels open trades. The public contact comes from CARDS_PRIVACY_CONTACT, which production now requires before enabling the game. The admin E2E no longer relies on a pull from the previous test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
148 lines
5.6 KiB
JavaScript
148 lines
5.6 KiB
JavaScript
// Rôle : centralise les appels authentifiés à l'API Sokko TCG.
|
|
let csrfToken = "";
|
|
|
|
async function request(path, options = {}) {
|
|
const headers = { Accept: "application/json", ...(options.headers || {}) };
|
|
if (options.body && !headers["Content-Type"]) headers["Content-Type"] = "application/json";
|
|
if (options.method && options.method !== "GET" && csrfToken) headers["X-CSRF-Token"] = csrfToken;
|
|
const response = await fetch(`/api/cards${path}`, { credentials: "same-origin", ...options, headers });
|
|
const payload = await response.json().catch(() => ({}));
|
|
if (!response.ok) throw Object.assign(new Error(payload.error?.message || "Sokko TCG est indisponible."), { status: response.status, code: payload.error?.code });
|
|
return payload;
|
|
}
|
|
|
|
export async function loadCardsConfig() {
|
|
return request("/config");
|
|
}
|
|
|
|
export async function loadCardsSession() {
|
|
const session = await request("/session");
|
|
csrfToken = session.csrfToken || "";
|
|
return session;
|
|
}
|
|
|
|
export function loadCardsState() {
|
|
return request("/state");
|
|
}
|
|
|
|
export function updateShopSetting(stardustValues, openingPrice, shopPackPrice, shopPackShare) {
|
|
return request("/admin/shop", { method: "PUT", body: JSON.stringify({ stardustValues, openingPrice, shopPackPrice, shopPackShare }) });
|
|
}
|
|
|
|
export function loadAdminDashboard() {
|
|
return request("/admin/dashboard");
|
|
}
|
|
|
|
export function loadAdminHistory(before = null) {
|
|
return request(`/admin/history${before == null ? "" : `?before=${before}`}`);
|
|
}
|
|
|
|
export async function devLogin() {
|
|
const result = await request("/auth/dev", { method: "POST" });
|
|
csrfToken = result.csrfToken;
|
|
return result;
|
|
}
|
|
|
|
export async function logoutCards() {
|
|
const result = await request("/auth/logout", { method: "POST" });
|
|
csrfToken = "";
|
|
return result;
|
|
}
|
|
|
|
export async function deleteCardsAccount() {
|
|
const result = await request("/account", { method: "DELETE" });
|
|
csrfToken = "";
|
|
return result;
|
|
}
|
|
|
|
// `purchased` : utilise une ouverture achetée en boutique au lieu de la réserve rechargeable.
|
|
export function openPack(collectionId, { purchased = false } = {}) {
|
|
const requestKey = crypto.randomUUID();
|
|
return request("/openings", { method: "POST", headers: { "Idempotency-Key": requestKey }, body: JSON.stringify({ collectionId, purchased }) });
|
|
}
|
|
|
|
// Sans `editionId`, recycle tous les doublons ; avec, un seul exemplaire de cette variation.
|
|
export function recycleDuplicates(editionId = null) {
|
|
return request("/recycle", { method: "POST", body: JSON.stringify({ editionId }) });
|
|
}
|
|
|
|
export function buyShopPack() {
|
|
return request("/shop/pack", { method: "POST", headers: { "Idempotency-Key": crypto.randomUUID() } });
|
|
}
|
|
|
|
export function buyOpening() {
|
|
return request("/shop/openings", { method: "POST" });
|
|
}
|
|
|
|
export function openGiftPack(giftPackId) {
|
|
return request(`/gift-packs/${encodeURIComponent(giftPackId)}/open`, { method: "POST", headers: { "Idempotency-Key": crypto.randomUUID() } });
|
|
}
|
|
|
|
export function completeOpening(openingId) {
|
|
return request(`/openings/${encodeURIComponent(openingId)}/complete`, { method: "POST" });
|
|
}
|
|
|
|
export function setFavorite(editionId, favorite) {
|
|
return request("/favorites", { method: "PUT", body: JSON.stringify({ editionId, favorite }) });
|
|
}
|
|
|
|
export function loadTraders() {
|
|
return request("/traders");
|
|
}
|
|
|
|
// Un don arrive immédiatement ; un échange réserve le doublon proposé jusqu'à la réponse du joueur.
|
|
export function createTransfer({ type, recipientId, editionId, requestedEditionId = null }) {
|
|
return request("/transfers", { method: "POST", body: JSON.stringify({ type, recipientId, editionId, requestedEditionId }) });
|
|
}
|
|
|
|
export function acceptTransfer(id) {
|
|
return request(`/transfers/${encodeURIComponent(id)}/accept`, { method: "POST" });
|
|
}
|
|
|
|
export function declineTransfer(id) {
|
|
return request(`/transfers/${encodeURIComponent(id)}/decline`, { method: "POST" });
|
|
}
|
|
|
|
export function cancelTransfer(id) {
|
|
return request(`/transfers/${encodeURIComponent(id)}/cancel`, { method: "POST" });
|
|
}
|
|
|
|
export function claimReward(code) {
|
|
return request("/rewards/claim", { method: "POST", body: JSON.stringify({ code }) });
|
|
}
|
|
|
|
export function createCampaign(values) {
|
|
return request("/admin/campaigns", { method: "POST", body: JSON.stringify(values) });
|
|
}
|
|
|
|
export function revokeCampaign(id) {
|
|
return request(`/admin/campaigns/${encodeURIComponent(id)}/revoke`, { method: "POST" });
|
|
}
|
|
|
|
export function updateCardMythic(cardId, { finishIds, opening }) {
|
|
return request(`/admin/catalog/cards/${encodeURIComponent(cardId)}/mythic`, { method: "PUT", body: JSON.stringify({ finishIds, opening }) });
|
|
}
|
|
|
|
export function updateCollectionMythicOpening(collectionId, { particleShapeId, particlePaletteId }) {
|
|
return request(`/admin/catalog/collections/${encodeURIComponent(collectionId)}/mythic-opening`, { method: "PUT", body: JSON.stringify({ particleShapeId, particlePaletteId }) });
|
|
}
|
|
|
|
export function setCollectionActive(collectionId, active) {
|
|
return request(`/admin/collections/${encodeURIComponent(collectionId)}/state`, { method: "PUT", body: JSON.stringify({ active }) });
|
|
}
|
|
|
|
export function setDropRates(collectionId, rarityWeights) {
|
|
return request(`/admin/collections/${encodeURIComponent(collectionId)}/drop-rates`, { method: "PUT", body: JSON.stringify({ rarityWeights }) });
|
|
}
|
|
|
|
export function updateRechargeSetting(intervalMs) {
|
|
return request("/admin/recharge", { method: "PUT", body: JSON.stringify({ intervalMs }) });
|
|
}
|
|
|
|
export function loadCampaignDetail(campaignId) {
|
|
return request(`/admin/campaigns/${encodeURIComponent(campaignId)}`);
|
|
}
|
|
|
|
export function extendCampaign(campaignId, expiresAt) {
|
|
return request(`/admin/campaigns/${encodeURIComponent(campaignId)}/expiry`, { method: "PUT", body: JSON.stringify({ expiresAt }) });
|
|
}
|