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
+17 -12
View File
@@ -53,8 +53,13 @@ export type ReportPdfPayload = {
extraTables?: { title: string; columns: string[]; rows: (string | number)[][] }[];
};
/** The message in a v2 error body (or the text as it came). */
function v2ErrorText(text: string): string {
try { const j = JSON.parse(text); return j?.error?.message || j?.message || text; } catch { return text; }
}
export async function downloadReportPdf(apiBase: string, authToken: string, payload: ReportPdfPayload) {
const url = `${apiBase}/api/reports/pdf`;
const url = `${apiBase}/api/v2/reports/pdf`;
const res = await fetch(url, {
method: 'POST',
headers: {
@@ -65,7 +70,7 @@ export async function downloadReportPdf(apiBase: string, authToken: string, payl
});
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(text || `Failed to generate PDF (${res.status})`);
throw new Error(v2ErrorText(text) || `Failed to generate PDF (${res.status})`);
}
const blob = await res.blob();
const dl = document.createElement('a');
@@ -80,7 +85,7 @@ export async function downloadReportPdf(apiBase: string, authToken: string, payl
// Downloads a styled .xlsx mirroring the same branded look as the PDF (colored header,
// stat rows, a data-bar chart, banded table with a highlighted total row).
export async function downloadReportExcel(apiBase: string, authToken: string, payload: ReportPdfPayload) {
const url = `${apiBase}/api/reports/excel`;
const url = `${apiBase}/api/v2/reports/excel`;
const res = await fetch(url, {
method: 'POST',
headers: {
@@ -91,7 +96,7 @@ export async function downloadReportExcel(apiBase: string, authToken: string, pa
});
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(text || `Failed to generate Excel file (${res.status})`);
throw new Error(v2ErrorText(text) || `Failed to generate Excel file (${res.status})`);
}
const blob = await res.blob();
const dl = document.createElement('a');
@@ -104,7 +109,7 @@ export async function downloadReportExcel(apiBase: string, authToken: string, pa
}
export async function emailReportPdf(apiBase: string, authToken: string, payload: ReportPdfPayload & { subject?: string; body?: string }) {
const url = `${apiBase}/api/reports/email`;
const url = `${apiBase}/api/v2/reports/email`;
const res = await fetch(url, {
method: 'POST',
headers: {
@@ -115,15 +120,15 @@ export async function emailReportPdf(apiBase: string, authToken: string, payload
});
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(text || `Failed to email PDF (${res.status})`);
throw new Error(v2ErrorText(text) || `Failed to email PDF (${res.status})`);
}
return res.json();
return (await res.json()).data;
}
// Sends the report PDF to the current user's own WhatsApp number (same self-service pattern as
// emailReportPdf — no recipient picker needed).
export async function whatsappReportPdf(apiBase: string, authToken: string, payload: ReportPdfPayload & { caption?: string }) {
const url = `${apiBase}/api/reports/whatsapp`;
const url = `${apiBase}/api/v2/reports/whatsapp`;
const res = await fetch(url, {
method: 'POST',
headers: {
@@ -134,15 +139,15 @@ export async function whatsappReportPdf(apiBase: string, authToken: string, payl
});
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(text || `Failed to send PDF via WhatsApp (${res.status})`);
throw new Error(v2ErrorText(text) || `Failed to send PDF via WhatsApp (${res.status})`);
}
return res.json();
return (await res.json()).data;
}
// "Print": fetches the same PDF as downloadReportPdf but opens it in a new tab instead of
// downloading, so the browser's built-in PDF viewer's print button handles printing.
export async function viewReportPdf(apiBase: string, authToken: string, payload: ReportPdfPayload) {
const url = `${apiBase}/api/reports/pdf`;
const url = `${apiBase}/api/v2/reports/pdf`;
const res = await fetch(url, {
method: 'POST',
headers: {
@@ -153,7 +158,7 @@ export async function viewReportPdf(apiBase: string, authToken: string, payload:
});
if (!res.ok) {
const text = await res.text().catch(() => '');
throw new Error(text || `Failed to generate PDF (${res.status})`);
throw new Error(v2ErrorText(text) || `Failed to generate PDF (${res.status})`);
}
const blob = await res.blob();
const objUrl = URL.createObjectURL(blob);