feat: sync GridSmart agendas and use event-relative demo time

Support script and URL sources, automatic Sessionize polling, staff-linked service sessions, chronological agenda blocks, and inline Placeholders. Fix demo mode to use the active event date and document deployed behavior with regression coverage.
This commit is contained in:
Lago committed 2026-10-11 08:39:15 +02:00
1 parent 40f24cf5f7
commit c0fbf495dc
27 files changed
+1215 -60

No files matched your search

+25 -15
View File
@@ -42,6 +42,8 @@
const http = require('http');
const XLSX = require('xlsx');
const { transformExcel } = require('./transform-excel');
const { readSessionizeSource } = require('./sessionize-source');
const { createSessionizePoller } = require('./sessionize-poller');
const PDFDocument = require('pdfkit');
const SUPABASE_URL = (process.env.SUPABASE_URL || 'http://supabase_kong_Convivo:8000').replace(/\/$/, '');
@@ -52,6 +54,9 @@ const SESSIONIZE_API_KEY = process.env.SESSIONIZE_API_KEY || '';
const PRETIX_API_KEY = process.env.PRETIX_API_KEY || '';
const PRETIX_BASE = (process.env.PRETIX_BASE || 'https://pretix.eu/api/v1').replace(/\/$/, '');
const PRETIX_SYNC_INTERVAL_MS = parseInt(process.env.PRETIX_SYNC_INTERVAL_MS || '60000', 10);
const configuredSessionizeInterval = Number(process.env.SESSIONIZE_SYNC_INTERVAL_MS || 900000);
const SESSIONIZE_SYNC_INTERVAL_MS = configuredSessionizeInterval === 0 ? 0
: Number.isFinite(configuredSessionizeInterval) ? Math.max(60000, configuredSessionizeInterval) : 900000;
const PORT = parseInt(process.env.PORT || '3002', 10);
// In-memory last-run state (the sidecar is otherwise stateless).
@@ -305,21 +310,11 @@ async function runSync(eventId) {
throw new Error(`event "${event.name}" has no sessionize_endpoint set`);
}
// 2. Fetch the Sessionize data. The public /view/ endpoint needs no key;
// if a key is configured we send it (required for /api/ endpoints).
const szUrl = event.sessionize_endpoint.trim();
log('run: fetching Sessionize', { szUrl, hasKey: Boolean(SESSIONIZE_API_KEY) });
const szHeaders = {};
if (SESSIONIZE_API_KEY) szHeaders['X-Sessionize-API-Key'] = SESSIONIZE_API_KEY;
const szRes = await fetch(szUrl, { headers: szHeaders });
if (!szRes.ok) {
const t = await szRes.text();
throw new Error(`Sessionize ${szRes.status}: ${t.slice(0, 200)}`);
}
const szData = await szRes.json();
// 3. Transform.
const { payload, skippedSpeakers } = transform(szData);
const source = await readSessionizeSource(event.sessionize_endpoint, { apiKey: SESSIONIZE_API_KEY });
const { payload, skippedSpeakers } = source.payload
? { payload: source.payload, skippedSpeakers: [] }
: transform(source.data);
if (!payload.sessions.length) throw new Error('Sessionize contains no scheduled sessions; existing agenda retained');
log('run: transformed', {
speakers: payload.speakers.length,
sessions: payload.sessions.length,
@@ -331,6 +326,7 @@ async function runSync(eventId) {
method: 'POST',
body: { p_event_id: event.id, p_payload: payload },
});
if (summary.errors?.length) throw new Error(`Sessionize import reported ${summary.errors.length} error(s)`);
const finishedAt = new Date().toISOString();
const result = {
@@ -339,6 +335,7 @@ async function runSync(eventId) {
started_at: startedAt,
finished_at: finishedAt,
status: 'success',
source_format: source.format,
summary,
skipped_speakers: skippedSpeakers,
};
@@ -810,6 +807,13 @@ async function handleExport(body) {
};
}
const pollSessionize = createSessionizePoller({
listEvents: () => supabaseFetch('/rest/v1/events?is_active=eq.true&sessionize_endpoint=not.is.null&select=id'),
syncEvent: runSync,
isBusy: () => running,
onError: (error, eventId) => log('sessionize poll error', { eventId, error: error.message }),
});
const server = http.createServer(async (req, res) => {
const url = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
const path = url.pathname;
@@ -822,6 +826,7 @@ const server = http.createServer(async (req, res) => {
ok: true,
running,
lastRun,
sessionizeIntervalMs: SESSIONIZE_SYNC_INTERVAL_MS,
pretixRunning,
lastPretixRun,
pretixIntervalMs: PRETIX_SYNC_INTERVAL_MS,
@@ -870,6 +875,11 @@ const server = http.createServer(async (req, res) => {
});
server.listen(PORT, () => {
if (SESSIONIZE_SYNC_INTERVAL_MS > 0) {
log('sessionize auto-sync scheduled', { intervalMs: SESSIONIZE_SYNC_INTERVAL_MS });
setInterval(pollSessionize, SESSIONIZE_SYNC_INTERVAL_MS);
void pollSessionize();
}
log('sidecar listening', {
port: PORT,
supabase: SUPABASE_URL,