WIP 1.51.12: tickets, scan locks, attendance, allocations 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:
File diff suppressed because it is too large
Load Diff
+3617
File diff suppressed because it is too large
Load Diff
@@ -43,6 +43,17 @@ export function apiV2<M extends Method, P extends PathsWith<M>>(method: M, path:
|
||||
return apiFetch<V2Result<P, M>>(`/api/v2${url}`, { method: method.toUpperCase(), authToken: opts.authToken, body: opts.body, nextOptions: opts.nextOptions });
|
||||
}
|
||||
|
||||
/**
|
||||
* An untyped v2 call, for screens whose helpers take the path as a string (`call(path, method)`):
|
||||
* the answer's `data`. Prefer `apiV2`/`apiV2Data` with a literal path where you can.
|
||||
*/
|
||||
export async function apiV2Raw<T = unknown>(method: Method, path: string, options: { authToken?: string | null; body?: unknown; query?: Record<string, unknown> } = {}): Promise<T> {
|
||||
const qs = new URLSearchParams();
|
||||
for (const [k, v] of Object.entries(options.query || {})) if (v !== undefined && v !== null && v !== "") qs.set(k, String(v));
|
||||
const res = await apiFetch<{ data: T }>(`/api/v2${path}${qs.toString() ? `?${qs.toString()}` : ""}`, { method: method.toUpperCase(), authToken: options.authToken, body: options.body });
|
||||
return res.data;
|
||||
}
|
||||
|
||||
/** The JSON body a v2 endpoint takes. */
|
||||
export type V2Body<P extends keyof paths, M extends Method> = Body<Op<P, M>>;
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ export async function fetchApiFile(apiBase: string, authToken: string, path: str
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => '');
|
||||
let message = text;
|
||||
try { message = JSON.parse(text)?.message || text; } catch { /* not JSON */ }
|
||||
try { const j = JSON.parse(text); message = j?.error?.message || j?.message || text; } catch { /* not JSON */ }
|
||||
throw new Error(message || `Download failed (${res.status})`);
|
||||
}
|
||||
return res.blob();
|
||||
|
||||
Reference in New Issue
Block a user