Add Pretix ticketing integration (every-minute sidecar sync)

- docs/backend/pretix.md: Pretix REST API reference (auth, orders/items
  endpoints, pagination, rate limiting, worked example)
- migration 20260909000000_pretix_sync.sql: events.pretix_organizer +
  pretix_event_slug; _map_ticket_type, _ensure_auth_user (QR token =
  password), sync_pretix_attendees (service-role-only, idempotent)
- sidecar: pretixFetch/fetchPretixOrders/fetchPretixItems/transformPretix,
  runPretixSync + every-minute runPretixLoop, POST /run-pretix, /status
  extended with pretix state
- admin: Pretix panel + recent runs in Interfaces, per-event Pretix config
  + Sync button in Events, api/types for Pretix
- docker-compose: PRETIX_API_KEY / PRETIX_BASE / PRETIX_SYNC_INTERVAL_MS

Verified on VM: 25 paid orders -> 25 attendees, auto-sync every minute,
login via QR token works, idempotent (no duplicate registrations).

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-09-09 11:40:56 +02:00
1 parent d5ec009cb5
commit 509e342204
8 files changed
+1009 -10

No files matched your search

+137 -2
View File
@@ -1,6 +1,13 @@
import { useEffect, useState } from 'react';
import { activateEvent, deactivateEvent, getAllEvents, runSessionizeSync, upsertEvent } from '../lib/api';
import type { Event, SyncResult } from '../lib/types';
import {
activateEvent,
deactivateEvent,
getAllEvents,
runPretixSync,
runSessionizeSync,
upsertEvent,
} from '../lib/api';
import type { Event, PretixSyncResult, SyncResult } from '../lib/types';
import { useToast } from '../context/ToastContext';
import { Empty, Modal, Spinner, Toggle } from '../components/ui';
@@ -12,6 +19,8 @@ export function Events() {
const [modal, setModal] = useState<{ event: Event | null } | null>(null);
const [syncingId, setSyncingId] = useState<string | null>(null);
const [syncResult, setSyncResult] = useState<SyncResult | null>(null);
const [pretixSyncingId, setPretixSyncingId] = useState<string | null>(null);
const [pretixResult, setPretixResult] = useState<PretixSyncResult | null>(null);
async function load() {
try {
@@ -56,6 +65,29 @@ export function Events() {
}
}
async function runPretix(ev: Event) {
if (!ev.pretix_organizer || !ev.pretix_event_slug) {
push('error', `Set the Pretix organizer + event slug for ${ev.name} first (Edit)`);
return;
}
setPretixSyncingId(ev.id);
try {
const result = await runPretixSync(ev.id);
setPretixResult(result);
await load();
push(
'success',
result.status === 'success'
? `Pretix synced ${ev.name} (${result.attendees ?? 0} attendees)`
: `Pretix ${result.status} for ${ev.name}`,
);
} catch (e) {
push('error', e instanceof Error ? e.message : 'Pretix sync failed');
} finally {
setPretixSyncingId(null);
}
}
if (error) return <Empty icon="⚠️" text={error} />;
if (!loaded)
return (
@@ -130,6 +162,18 @@ export function Events() {
>
{syncingId === ev.id ? 'Syncing…' : 'Sync'}
</button>
<button
className="btn small"
disabled={pretixSyncingId === ev.id || !ev.pretix_organizer || !ev.pretix_event_slug}
onClick={() => runPretix(ev)}
title={
ev.pretix_organizer && ev.pretix_event_slug
? 'Sync with Pretix'
: 'Set the Pretix organizer + event slug first (Edit)'
}
>
{pretixSyncingId === ev.id ? 'Syncing…' : 'Sync Pretix'}
</button>
<button className="btn small" onClick={() => setModal({ event: ev })}>
Edit
</button>
@@ -156,10 +200,72 @@ export function Events() {
)}
{syncResult && <SyncResultModal result={syncResult} onClose={() => setSyncResult(null)} />}
{pretixResult && <PretixResultModal result={pretixResult} onClose={() => setPretixResult(null)} />}
</div>
);
}
function PretixResultModal({ result, onClose }: { result: PretixSyncResult; onClose: () => void }) {
const s = result.summary;
return (
<Modal
open
title={`Pretix sync — ${result.event_name ?? result.event_id}`}
onClose={onClose}
footer={
<button className="btn primary" onClick={onClose}>
Close
</button>
}
>
{result.status === 'error' || result.status === 'skipped' ? (
<div className="pill red" style={{ display: 'inline-block', padding: '8px 12px' }}>
{result.error ?? result.reason ?? 'Pretix sync failed'}
</div>
) : (
<>
<div className="stat-grid">
<div className="stat">
<div className="val">{result.orders ?? 0}</div>
<div className="lbl">Orders</div>
</div>
<div className="stat">
<div className="val">{result.attendees ?? 0}</div>
<div className="lbl">Attendees</div>
</div>
<div className="stat">
<div className="val">{s?.created ?? 0}</div>
<div className="lbl">Created</div>
</div>
<div className="stat">
<div className="val">{s?.updated ?? 0}</div>
<div className="lbl">Updated</div>
</div>
<div className="stat">
<div className="val">{result.skipped ?? 0}</div>
<div className="lbl">Skipped</div>
</div>
</div>
{s && s.errors.length > 0 && (
<div style={{ marginTop: 12 }}>
<div className="pill red" style={{ display: 'inline-block', marginBottom: 8 }}>
{s.errors.length} error(s)
</div>
<ul style={{ margin: 0, paddingLeft: 18 }}>
{s.errors.map((e, i) => (
<li key={i} className="small">
{e}
</li>
))}
</ul>
</div>
)}
</>
)}
</Modal>
);
}
function EventModal({
event,
onClose,
@@ -174,6 +280,8 @@ function EventModal({
const [endDate, setEndDate] = useState(event ? event.end_date.slice(0, 10) : '');
const [location, setLocation] = useState(event?.location ?? '');
const [endpoint, setEndpoint] = useState(event?.sessionize_endpoint ?? '');
const [pretixOrganizer, setPretixOrganizer] = useState(event?.pretix_organizer ?? '');
const [pretixEventSlug, setPretixEventSlug] = useState(event?.pretix_event_slug ?? '');
const [realtimeClock, setRealtimeClock] = useState(event?.use_realtime_clock ?? false);
const [busy, setBusy] = useState(false);
@@ -187,6 +295,8 @@ function EventModal({
end_date: endDate,
location: location.trim() || null,
sessionize_endpoint: endpoint.trim() || null,
pretix_organizer: pretixOrganizer.trim() || null,
pretix_event_slug: pretixEventSlug.trim() || null,
use_realtime_clock: realtimeClock,
});
onSaved(event ? 'Event updated' : 'Event created');
@@ -244,6 +354,31 @@ function EventModal({
“Run sync” button. You can also import the .xlsx export in the Interfaces menu.
</div>
</div>
<div className="grid-2">
<div className="field">
<label>Pretix organizer</label>
<input
className="input"
value={pretixOrganizer}
onChange={(e) => setPretixOrganizer(e.target.value)}
placeholder="e.g. appecommday"
/>
</div>
<div className="field">
<label>Pretix event slug</label>
<input
className="input"
value={pretixEventSlug}
onChange={(e) => setPretixEventSlug(e.target.value)}
placeholder="e.g. tickets"
/>
</div>
</div>
<div className="muted small" style={{ marginBottom: 12, maxWidth: 640 }}>
The sidecar syncs paid Pretix tickets for this event every minute. Set the organizer +
event slug (e.g. <code>appecommday</code> / <code>tickets</code>). The API key is
configured on the sidecar.
</div>
<div className="field">
<div className="row between" style={{ alignItems: 'center' }}>
<div>
+215 -5
View File
@@ -1,6 +1,22 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { getAllEvents, getSidecarStatus, getSyncRuns, importSessionizeExcel, runSessionizeSync } from '../lib/api';
import type { Event, ExcelSyncResult, SidecarStatus, SyncResult, SyncRun } from '../lib/types';
import {
getAllEvents,
getPretixRuns,
getSidecarStatus,
getSyncRuns,
importSessionizeExcel,
runPretixSync,
runSessionizeSync,
} from '../lib/api';
import type {
Event,
ExcelSyncResult,
PretixRun,
PretixSyncResult,
SidecarStatus,
SyncResult,
SyncRun,
} from '../lib/types';
import { useToast } from '../context/ToastContext';
import { Empty, Modal, Spinner } from '../components/ui';
@@ -18,6 +34,9 @@ export function Interfaces() {
const [excelFile, setExcelFile] = useState<File | null>(null);
const [excelBusy, setExcelBusy] = useState(false);
const [excelResult, setExcelResult] = useState<ExcelSyncResult | null>(null);
const [pretixRuns, setPretixRuns] = useState<SyncRun[]>([]);
const [pretixRunning, setPretixRunning] = useState(false);
const [pretixResult, setPretixResult] = useState<PretixSyncResult | null>(null);
const fileRef = useRef<HTMLInputElement>(null);
const loadableEvents = events.filter((e) => e.sessionize_endpoint);
@@ -52,13 +71,24 @@ export function Interfaces() {
}
}
async function loadPretixRuns(eventId: string) {
try {
setPretixRuns(await getPretixRuns(eventId));
} catch {
setPretixRuns([]);
}
}
useEffect(() => {
load();
loadStatus();
}, []);
useEffect(() => {
if (selectedId) loadRuns(selectedId);
if (selectedId) {
loadRuns(selectedId);
loadPretixRuns(selectedId);
}
}, [selectedId]);
// Poll the sidecar status while a sync is running (the run call is blocking,
@@ -67,10 +97,10 @@ export function Interfaces() {
loadStatus();
}, []);
useEffect(() => {
if (!running) return;
if (!running && !pretixRunning) return;
const t = setInterval(pollStatus, 3000);
return () => clearInterval(t);
}, [running, pollStatus]);
}, [running, pretixRunning, pollStatus]);
async function runSync() {
if (!selectedId) return;
@@ -87,6 +117,21 @@ export function Interfaces() {
}
}
async function runPretixNow() {
if (!selectedId) return;
setPretixRunning(true);
try {
const res = await runPretixSync(selectedId);
setPretixResult(res);
await Promise.all([load(), loadStatus(), loadPretixRuns(selectedId)]);
push('success', 'Pretix sync finished');
} catch (e) {
push('error', e instanceof Error ? e.message : 'Pretix sync failed');
} finally {
setPretixRunning(false);
}
}
async function importExcel() {
if (!selectedId || !excelFile) return;
setExcelBusy(true);
@@ -239,6 +284,109 @@ export function Interfaces() {
</div>
</div>
{/* Pretix */}
<div className="card" style={{ marginBottom: 18 }}>
<h2 className="h2">🎟 Pretix</h2>
<div style={{ marginBottom: 12 }}>
{status?.pretixConfigured === false ? (
<span className="pill amber" style={{ display: 'inline-block', padding: '8px 12px' }}>
Pretix not configured (no API key on the sidecar)
</span>
) : (
<div className="muted small" style={{ display: 'flex', gap: 10, alignItems: 'center', flexWrap: 'wrap' }}>
<span>
Pretix auto-sync: every {status?.pretixIntervalMs ? status.pretixIntervalMs / 1000 : 60}s
</span>
{status?.lastPretixRun && (
<span>
last run {fmtTime(status.lastPretixRun.finished_at)} —{' '}
<span
className={`pill ${
status.lastPretixRun.status === 'success'
? 'green'
: status.lastPretixRun.status === 'skipped'
? 'amber'
: 'red'
}`}
>
{status.lastPretixRun.status}
</span>
{status.lastPretixRun.status === 'success' && (
<span className="muted">
{' '}
· {status.lastPretixRun.orders ?? 0} orders · {status.lastPretixRun.attendees ?? 0}{' '}
attendees · {status.lastPretixRun.skipped ?? 0} skipped
</span>
)}
{(status.lastPretixRun.status === 'error' || status.lastPretixRun.status === 'skipped') &&
(status.lastPretixRun.error || status.lastPretixRun.reason) && (
<span className="muted"> · {status.lastPretixRun.error || status.lastPretixRun.reason}</span>
)}
</span>
)}
</div>
)}
</div>
<div style={{ display: 'flex', gap: 12, alignItems: 'center', flexWrap: 'wrap' }}>
<select
className="input"
style={{ maxWidth: 320 }}
value={selectedId}
onChange={(e) => setSelectedId(e.target.value)}
>
{events.map((e) => (
<option key={e.id} value={e.id}>
{e.name}
</option>
))}
</select>
<button className="btn primary" disabled={pretixRunning || !selectedId} onClick={runPretixNow}>
{pretixRunning ? 'Syncing…' : 'Run Pretix now'}
</button>
</div>
</div>
{/* Recent Pretix runs (audit) */}
<div className="card" style={{ marginBottom: 18 }}>
<h2 className="h2">📜 Recent Pretix runs {selected ? `— ${selected.name}` : ''}</h2>
{pretixRuns.length === 0 ? (
<Empty icon="🎟" text="No Pretix sync runs recorded for this event yet." />
) : (
<div className="table-wrap">
<table className="data">
<thead>
<tr>
<th>Started</th>
<th>Finished</th>
<th>Created</th>
<th>Updated</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{pretixRuns.map((r) => (
<tr key={r.id}>
<td className="muted">{fmtTime(r.started_at)}</td>
<td className="muted">{r.finished_at ? fmtTime(r.finished_at) : '—'}</td>
<td className="muted">{r.created}</td>
<td className="muted">{r.updated}</td>
<td>
{r.error ? (
<span className="pill red" title={r.error}>
error
</span>
) : (
<span className="pill green">ok</span>
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
{/* Recent runs (audit) */}
<div className="card">
<h2 className="h2">📜 Recent runs {selected ? `— ${selected.name}` : ''}</h2>
@@ -282,10 +430,72 @@ export function Interfaces() {
{result && <SyncResultModal result={result} onClose={() => setResult(null)} />}
{excelResult && <ExcelResultModal result={excelResult} onClose={() => setExcelResult(null)} />}
{pretixResult && <PretixResultModal result={pretixResult} onClose={() => setPretixResult(null)} />}
</div>
);
}
function PretixResultModal({ result, onClose }: { result: PretixRun; onClose: () => void }) {
const s = result.summary;
return (
<Modal
open
title={`Pretix sync — ${result.event_name ?? result.event_id}`}
onClose={onClose}
footer={
<button className="btn primary" onClick={onClose}>
Close
</button>
}
>
{result.status === 'error' || result.status === 'skipped' ? (
<div className="pill red" style={{ display: 'inline-block', padding: '8px 12px' }}>
{result.error ?? result.reason ?? 'Pretix sync failed'}
</div>
) : (
<>
<div className="stat-grid">
<div className="stat">
<div className="val">{result.orders ?? 0}</div>
<div className="lbl">Orders</div>
</div>
<div className="stat">
<div className="val">{result.attendees ?? 0}</div>
<div className="lbl">Attendees</div>
</div>
<div className="stat">
<div className="val">{s?.created ?? 0}</div>
<div className="lbl">Created</div>
</div>
<div className="stat">
<div className="val">{s?.updated ?? 0}</div>
<div className="lbl">Updated</div>
</div>
<div className="stat">
<div className="val">{result.skipped ?? 0}</div>
<div className="lbl">Skipped</div>
</div>
</div>
{s && s.errors.length > 0 && (
<div style={{ marginTop: 12 }}>
<div className="pill red" style={{ display: 'inline-block', marginBottom: 8 }}>
{s.errors.length} error(s)
</div>
<ul style={{ margin: 0, paddingLeft: 18 }}>
{s.errors.map((e, i) => (
<li key={i} className="small">
{e}
</li>
))}
</ul>
</div>
)}
</>
)}
</Modal>
);
}
function ExcelResultModal({ result, onClose }: { result: ExcelSyncResult; onClose: () => void }) {
const s = result.summary;
return (