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:
1 parent
a0bcf866dc
commit
5f8ded56f6
31 files changed
+2729
-390
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user