WIP 1.51.14: people and messaging on v2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ls1vMdg2GYqbnKZmPaX1ot
This commit is contained in:
2026-10-29 17:02:26 +02:00
co-authored by Claude Opus 5.5
parent fdc3db8d23
commit e95d52ccdd
42 changed files with 9250 additions and 183 deletions
+12 -31
View File
@@ -162,41 +162,15 @@ export async function apiFetch<T = unknown>(path: string, options: ApiOptions =
// instead of caching an empty one.
export async function apiFetchListForPrerender<T>(path: string, options: ApiOptions = {}): Promise<T[]> {
try {
return (await apiFetch<T[]>(path, options)) || [];
// v2 answers { data: [...] }; v1 answered the bare list.
const res = await apiFetch<T[] | { data?: T[] }>(path, options);
return (Array.isArray(res) ? res : res?.data) || [];
} catch (err) {
if (process.env.NEXT_PHASE === "phase-production-build") return [];
throw err;
}
}
// Several list endpoints (/api/users, /api/payments) are paginated and cap
// `limit` at 200 server-side, so a single request can silently miss records
// beyond the first page. This walks every page and returns the full list.
async function fetchAllPages<T>(path: string, token: string, params: Record<string, string> = {}): Promise<T[]> {
const query = new URLSearchParams({ ...params, limit: "200", page: "1" });
const first = await apiFetch<Paginated<T>>(`${path}?${query.toString()}`, { authToken: token });
const items: T[] = Array.isArray(first?.data) ? first.data : [];
const pages = first?.pages || 1;
if (pages > 1) {
// Page 1 told us the total page count — fetch the rest concurrently instead of
// awaiting them one at a time. This function is called on every dashboard poll
// (see useVisiblePolling usages), so a serial loop here directly slows those polls.
const remaining = await Promise.all(
Array.from({ length: pages - 1 }, (_, i) => {
const page = i + 2;
const pageQuery = new URLSearchParams({ ...params, limit: "200", page: String(page) });
return apiFetch<Paginated<T>>(`${path}?${pageQuery.toString()}`, { authToken: token });
})
);
for (const res of remaining) {
if (Array.isArray(res?.data)) items.push(...res.data);
}
}
return items;
}
/**
* Every event staff can see (API v2 GET /events/manage): upcoming by default; `past`,
* `inactive` widen it, `closed: false` leaves out cashed-up events. Full records — ticket options,
@@ -244,8 +218,15 @@ export async function fetchEvent<T = Event>(id: string, options: { authToken?: s
return data as unknown as T;
}
export function fetchAllUsers(token: string, params: Record<string, string> = {}): Promise<User[]> {
return fetchAllPages<User>("/api/users", token, params);
/** Every account (API v2 GET /users, all pages at once). */
export async function fetchAllUsers(token: string, params: Record<string, string> = {}): Promise<User[]> {
const { apiV2Data } = await import("@/lib/apiV2");
const page = (n: number) => apiV2Data("get", "/users", { query: { ...params, limit: "200", page: String(n) }, authToken: token }) as Promise<Paginated<User>>;
const first = await page(1);
const items: User[] = Array.isArray(first?.data) ? [...first.data] : [];
const rest = await Promise.all(Array.from({ length: Math.max(0, (first?.pages || 1) - 1) }, (_, i) => page(i + 2)));
for (const res of rest) if (Array.isArray(res?.data)) items.push(...res.data);
return items;
}
/** Every payment staff may see (API v2 GET /payments, all pages at once). */