feat: add sidecar service for Sessionize sync

- Introduced a new Node HTTP service (sidecar) to sync event agendas from Sessionize into Convivo.
- Implemented two import paths: API sync and Excel import for session and speaker data.
- Added necessary database migrations for sessionize integration, including new columns and audit tables.
- Created functions for handling speaker and session imports, ensuring proper error handling and logging.
- Established row-level security and grants for new functions to restrict access to service-role only.

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-08-24 20:47:29 +02:00
1 parent a0bcf866dc
commit 5f8ded56f6
31 files changed
+2729 -390

No files matched your search

+63 -1
View File
@@ -4,6 +4,7 @@ import type {
Connection,
Contact,
Event,
ExcelSyncResult,
Feedback,
LeaderboardRow,
PointsLogRow,
@@ -11,8 +12,11 @@ import type {
ResetQrResult,
Session,
SessionSpeaker,
SidecarStatus,
Slot,
Sponsor,
SyncResult,
SyncRun,
} from './types';
export class ApiError extends Error {}
@@ -142,7 +146,13 @@ export async function deleteSponsor(id: string): Promise<void> {
export async function upsertEvent(
id: string | null,
input: { name: string; start_date: string; end_date: string; location?: string | null },
input: {
name: string;
start_date: string;
end_date: string;
location?: string | null;
sessionize_endpoint?: string | null;
},
): Promise<void> {
if (id) {
const { error } = await supabase.from('events').update(input).eq('id', id);
@@ -153,6 +163,58 @@ export async function upsertEvent(
}
}
// ---- Sessionize sync (sidecar) ---------------------------------------------
// The sidecar is a separate Docker service (not Supabase), so these use raw
// fetch against the same-origin /sidecar proxy (see nginx.conf.template).
async function sidecarFetch<T>(path: string, init?: RequestInit): Promise<T> {
let res: Response;
try {
res = await fetch(`/sidecar${path}`, {
headers: { 'Content-Type': 'application/json' },
...init,
});
} catch {
throw new ApiError('Could not reach the sync sidecar (is it running?)');
}
const body = (await res.json().catch(() => ({}))) as T & { error?: string };
if (!res.ok) throw new ApiError(body.error || `sidecar error (${res.status})`);
return body;
}
export const getSidecarStatus = () => sidecarFetch<SidecarStatus>('/status');
/** Trigger a (blocking) Sessionize sync for an event. Resolves with the result. */
export const runSessionizeSync = (eventId: string) =>
sidecarFetch<SyncResult>('/run', { method: 'POST', body: JSON.stringify({ event_id: eventId }) });
/**
* Upload the Sessionize "Sessions and speakers (advanced)" .xlsx for an event.
* The sidecar parses it and imports speakers/sessions/agenda + speaker
* registrations. Resolves with the result (blocking).
*/
export async function importSessionizeExcel(eventId: string, file: File): Promise<ExcelSyncResult> {
const base64 = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
const url = reader.result as string;
resolve(url.slice(url.indexOf(',') + 1));
};
reader.onerror = () => reject(new Error('Could not read the file'));
reader.readAsDataURL(file);
});
return sidecarFetch<ExcelSyncResult>('/import-excel', {
method: 'POST',
body: JSON.stringify({ event_id: eventId, file_base64: base64, filename: file.name }),
});
}
/** Recent sync_runs rows for an event (newest first). */
export const getSyncRuns = (eventId: string) =>
all<SyncRun>('sync_runs', { col: 'started_at', asc: false }).then((rows) =>
rows.filter((r) => r.event_id === eventId),
);
/** Set an event active (deactivates all others via trigger). */
export async function activateEvent(id: string): Promise<void> {
const { error } = await supabase.from('events').update({ is_active: true }).eq('id', id);
+75 -1
View File
@@ -10,7 +10,7 @@ export type SponsorType =
| 'catering'
| 'diversity';
export type SlotType = 'session' | 'lunch_break' | 'coffee_break' | 'keynote' | 'close_up';
export type SlotType = 'session' | 'service_session';
export interface Contact {
email: string;
@@ -31,6 +31,10 @@ export interface Event {
end_date: string;
location: string | null;
is_active: boolean;
/** Sessionize API URL for this event (e.g. .../api/v2/<id>/view/All). */
sessionize_endpoint: string | null;
/** When the Sessionize sync last ran for this event. */
last_synced_at: string | null;
avg_feedback: number | null;
num_sessions: number;
num_speakers: number;
@@ -39,6 +43,76 @@ export interface Event {
created_at: string;
}
// ---- Sessionize sync (sidecar) ---------------------------------------------
/** A row in the sync_runs audit table (event-scoped). */
export interface SyncRun {
id: string;
event_id: string;
source: string;
started_at: string;
finished_at: string | null;
created: number;
updated: number;
skipped: number;
error: string | null;
triggered_by: string;
}
/** The summary returned by the sync_sessionize_event RPC. */
export interface SyncSummary {
speakers_created: number;
speakers_updated: number;
sessions_created: number;
sessions_updated: number;
slots_created: number;
speakers_linked: number;
errors: string[];
}
/** The result of a (blocking) sidecar sync run. */
export interface SyncResult {
event_id: string;
event_name?: string;
started_at: string;
finished_at: string;
status: 'success' | 'error';
summary?: SyncSummary;
skipped_speakers?: string[];
error?: string;
}
/** The summary returned by the sync_sessionize_excel RPC. */
export interface ExcelSyncSummary {
speakers_created: number;
speakers_updated: number;
sessions_created: number;
sessions_updated: number;
slots_created: number;
speakers_linked: number;
registrations_created: number;
registrations_updated: number;
errors: string[];
}
/** The result of a (blocking) sidecar Excel import. */
export interface ExcelSyncResult {
event_id: string;
event_name?: string;
started_at: string;
finished_at: string;
status: 'success' | 'error';
summary?: ExcelSyncSummary;
error?: string;
}
/** The sidecar's /status response. */
export interface SidecarStatus {
ok: boolean;
running: boolean;
lastRun: SyncResult | null;
}
export interface Registration {
id: string;
event_id: string;