Phase 7+8: Pretix + Sessionize interfaces
- Migration 20260825000000_interfaces.sql: external_id on contacts/ registrations/sessions (+ partial unique indexes), slots_id_seq, sync_runs audit table, and service-role-only sync_pretix_attendees / sync_sessionize_sessions RPCs (idempotent upserts). - sync-trigger Edge Function: admin-JWT or CRON_SECRET auth, pulls from Pretix/Sessionize base URLs, normalizes, calls the service-role RPCs. - interfaces/mock-api: dependency-free Node server (:54330) + fixtures so the full pipeline is testable without real tokens. - APPE Admin 'Interfaces' view: per-source + 'Sync all' triggers, result counts, recent sync runs, and QR CSV export; /functions proxy added. - Docs: new docs/backend/interfaces.md; updated README, roadmap, next-steps, schema, rls, rpcs, architecture, admin-app, and docs index. 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:
1 parent
7605c9bbf4
commit
74c41c8c1d
26 files changed
+1529
-80
No files matched your search
@@ -13,6 +13,7 @@ import type {
|
||||
SessionSpeaker,
|
||||
Slot,
|
||||
Sponsor,
|
||||
SyncRun,
|
||||
} from './types';
|
||||
|
||||
export class ApiError extends Error {}
|
||||
@@ -206,3 +207,71 @@ export async function evaluateSessionFeedback(sessionId: string): Promise<Sessio
|
||||
// evaluate_session_feedback returns a single composite row (a JSON object, not an array).
|
||||
return await rpc<Session>('evaluate_session_feedback', { p_session_id: sessionId });
|
||||
}
|
||||
|
||||
// ---- Interfaces: Pretix + Sessionize sync (Phase 7 + 8) ---------------------
|
||||
|
||||
export interface SyncResult {
|
||||
ok: boolean;
|
||||
triggered_by: string;
|
||||
results: {
|
||||
pretix?: { created: number; updated: number; skipped: number; errors: string[] };
|
||||
sessionize?: {
|
||||
slots_created: number;
|
||||
sessions_created: number;
|
||||
sessions_updated: number;
|
||||
speakers_linked: number;
|
||||
errors: string[];
|
||||
};
|
||||
};
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a sync from the `sync-trigger` Edge Function. The admin's session
|
||||
* JWT is passed as the Authorization header; the function verifies it is an
|
||||
* admin (via the is_admin() RPC) before running.
|
||||
*/
|
||||
export async function triggerSync(source: 'pretix' | 'sessionize' | 'both'): Promise<SyncResult> {
|
||||
const { data } = await supabase.auth.getSession();
|
||||
const token = data.session?.access_token;
|
||||
if (!token) throw new ApiError('not signed in');
|
||||
const res = await fetch('/functions/v1/sync-trigger', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({ source }),
|
||||
});
|
||||
const body = (await res.json()) as SyncResult & { error?: string };
|
||||
if (!res.ok) throw new ApiError(body.error ?? `sync failed (${res.status})`);
|
||||
return body;
|
||||
}
|
||||
|
||||
/** Recent sync runs (audit trail), newest first. */
|
||||
export const getSyncRuns = (limit = 10) =>
|
||||
all<SyncRun>('sync_runs', { col: 'started_at', asc: false }).then((rows) => rows.slice(0, limit));
|
||||
|
||||
/**
|
||||
* Build a CSV of lanyard QR codes for the active event's registrations
|
||||
* (name, email, type, QR token) and trigger a browser download.
|
||||
*/
|
||||
export async function exportQrCsv(eventId: string): Promise<number> {
|
||||
const regs = await getRegistrations(eventId);
|
||||
const contacts = await getAllContacts();
|
||||
const byEmail = new Map(contacts.map((c) => [c.email, c]));
|
||||
const esc = (v: string | null | undefined) => `"${(v ?? '').replace(/"/g, '""')}"`;
|
||||
const lines = ['name,email,type,qr_token'];
|
||||
let count = 0;
|
||||
for (const r of regs) {
|
||||
const c = byEmail.get(r.contact_email);
|
||||
if (!c?.qr_token) continue;
|
||||
lines.push([esc(c.full_name), esc(c.email), esc(r.type), esc(c.qr_token)].join(','));
|
||||
count++;
|
||||
}
|
||||
const blob = new Blob([lines.join('\n')], { type: 'text/csv;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `lanyard-qr-codes-${eventId.slice(0, 8)}.csv`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
return count;
|
||||
}
|
||||
Reference in new issue
Block a user