Existing-sponsor link + remove Interfaces (Pretix/Sessionize)
- Sponsor lookup popup can now link an existing sponsor (dropdown + pre-fill) or create a new one; save upserts the sponsor linked to the contact and sets the registration type to sponsor. - Remove the Interfaces feature end-to-end: admin nav button + Sync view, sync API helpers + SyncRun type, sync-trigger Edge Function, mock-api + its docker-compose service, and a migration dropping the sync RPCs, helpers, and sync_runs table. - Update docs (architecture, backend, frontend, README, roadmap, next-steps).
This commit is contained in:
1 parent
1cbbd1b529
commit
a54ce69c4d
27 files changed
+147
-1150
No files matched your search
@@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
**Turn a conference into a game.** Convivo is a mobile-first web app (PWA) that gets attendees out of their seats: mark the sessions you want, scan lanyards to make connections, get checked in by staff, and climb the live leaderboard. The whole thing runs on a **Dockerized Supabase core** — no custom backend.
|
**Turn a conference into a game.** Convivo is a mobile-first web app (PWA) that gets attendees out of their seats: mark the sessions you want, scan lanyards to make connections, get checked in by staff, and climb the live leaderboard. The whole thing runs on a **Dockerized Supabase core** — no custom backend.
|
||||||
|
|
||||||
> **Status:** Phases 0–8 complete and verified. The **Redesign** (Phases 3–6)
|
> **Status:** Phases 0–6 complete and verified. The **Redesign** (Phases 3–6)
|
||||||
> and the **Pretix + Sessionize interfaces** (Phases 7–8) are done — the new
|
> is done — the new multi-event data model is live, the admin app is **APPE
|
||||||
> multi-event data model is live, the admin app is **APPE Admin**, the Convivo
|
> Admin**, the Convivo App has all the new behaviors, and both apps carry the
|
||||||
> App has all the new behaviors, both apps carry the APPE branding, and the
|
> APPE branding.
|
||||||
> interfaces sync real ticket + agenda data (testable end-to-end via a local
|
|
||||||
> mock API).
|
|
||||||
>
|
>
|
||||||
> - **Phase 0** — Dockerized Supabase core (Postgres + GoTrue + PostgREST + Realtime + Kong + Studio) with the full schema, RLS, and transactional points RPCs.
|
> - **Phase 0** — Dockerized Supabase core (Postgres + GoTrue + PostgREST + Realtime + Kong + Studio) with the full schema, RLS, and transactional points RPCs.
|
||||||
> - **Phase 1** — Attendee web PWA: login (QR + email), Home, Agenda, Scan/Connect, staff Check-in, Feedback, live Leaderboard, Profile.
|
> - **Phase 1** — Attendee web PWA: login (QR + email), Home, Agenda, Scan/Connect, staff Check-in, Feedback, live Leaderboard, Profile.
|
||||||
@@ -16,8 +14,6 @@
|
|||||||
> - **Phase 4** — APPE Admin: rebrand + Contacts / Registrations / Sponsors / Schedule / Activity / event mgmt.
|
> - **Phase 4** — APPE Admin: rebrand + Contacts / Registrations / Sponsors / Schedule / Activity / event mgmt.
|
||||||
> - **Phase 5** — Convivo App: 24h login, 5s polling, QR type badge, red dot, speaker material.
|
> - **Phase 5** — Convivo App: 24h login, 5s polling, QR type badge, red dot, speaker material.
|
||||||
> - **Phase 6** — Branding: APPE favicon + icons for both apps.
|
> - **Phase 6** — Branding: APPE favicon + icons for both apps.
|
||||||
> - **Phase 7** — Pretix interface: `sync-trigger` Edge Function → contacts + registrations (QR tokens, types, idempotent) + QR CSV export.
|
|
||||||
> - **Phase 8** — Sessionize interface: same Edge Function → slots + sessions + speakers (idempotent).
|
|
||||||
>
|
>
|
||||||
> **Next:** cross-cutting work (real event clock, deployment, automated testing).
|
> **Next:** cross-cutting work (real event clock, deployment, automated testing).
|
||||||
> See [`roadmap.md`](./roadmap.md).
|
> See [`roadmap.md`](./roadmap.md).
|
||||||
@@ -153,12 +149,12 @@ The model is **multi-event**: people (`contacts`) register for `events` via
|
|||||||
|
|
||||||
| Table | Key fields | Notes |
|
| Table | Key fields | Notes |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `contacts` | email (PK), full_name, linkedin_url, show_email, show_linkedin, is_admin, qr_token (unique), external_id | One row per person; mirrors `auth.users` (email + bcrypt(qr_token)); `external_id` = Pretix order code |
|
| `contacts` | email (PK), full_name, linkedin_url, show_email, show_linkedin, is_admin, qr_token (unique), external_id | One row per person; mirrors `auth.users` (email + bcrypt(qr_token)); `external_id` reserved for an external system |
|
||||||
| `events` | id, name, start_date, end_date, location, is_active, + aggregates | Partial unique index → at most one active event |
|
| `events` | id, name, start_date, end_date, location, is_active, + aggregates | Partial unique index → at most one active event |
|
||||||
| `registrations` | id, event_id, contact_email, type (attendee/speaker/staff/sponsor), checked_in, points, external_id | Unique (event_id, contact_email); points live here |
|
| `registrations` | id, event_id, contact_email, type (attendee/speaker/staff/sponsor), checked_in, points, external_id | Unique (event_id, contact_email); points live here |
|
||||||
| `sponsors` | id, event_id, type, name, email, phone, paid, amount_eur, contact_email | `paid` gates visibility to non-admins |
|
| `sponsors` | id, event_id, type, name, email, phone, paid, amount_eur, contact_email | `paid` gates visibility to non-admins |
|
||||||
| `slots` | id, event_id, type (session/lunch_break/coffee_break/keynote/close_up), name, slot_date, start_time, end_time | 6 rows for 23 Oct |
|
| `slots` | id, event_id, type (session/lunch_break/coffee_break/keynote/close_up), name, slot_date, start_time, end_time | 6 rows for 23 Oct |
|
||||||
| `sessions` | id, event_id, slot_id, title, description, room, capacity, average_feedback, ai_generated_feedback, material_path, external_id | 18 rows (3 per session slot); `external_id` = Sessionize id |
|
| `sessions` | id, event_id, slot_id, title, description, room, capacity, average_feedback, ai_generated_feedback, material_path, external_id | 18 rows (3 per session slot); `external_id` reserved for an external system |
|
||||||
| `session_speakers` | session_id, contact_email | Join; a session must have ≥1 speaker |
|
| `session_speakers` | session_id, contact_email | Join; a session must have ≥1 speaker |
|
||||||
| `preferences` | event_id, contact_email, session_id, slot_id | Unique per (event, contact, slot) — one pick per slot |
|
| `preferences` | event_id, contact_email, session_id, slot_id | Unique per (event, contact, slot) — one pick per slot |
|
||||||
| `connections` | event_id, from_email, to_email, status, created_at, resolved_at | Unique per unordered pair (via `least`/`greatest` index) |
|
| `connections` | event_id, from_email, to_email, status, created_at, resolved_at | Unique per unordered pair (via `least`/`greatest` index) |
|
||||||
@@ -166,33 +162,11 @@ The model is **multi-event**: people (`contacts`) register for `events` via
|
|||||||
| `feedback` | event_id, contact_email, session_id, rating (1–5), comment, created_at | Unique per (event, contact, session); only after session end |
|
| `feedback` | event_id, contact_email, session_id, rating (1–5), comment, created_at | Unique per (event, contact, session); only after session end |
|
||||||
| `leaderboard` | event_id, contact_email, full_name, points, updated_at | Realtime mirror, kept in sync by the RPCs |
|
| `leaderboard` | event_id, contact_email, full_name, points, updated_at | Realtime mirror, kept in sync by the RPCs |
|
||||||
| `points_log` | event_id, contact_email, delta, category, created_at | Audit trail powering the per-category breakdown |
|
| `points_log` | event_id, contact_email, delta, category, created_at | Audit trail powering the per-category breakdown |
|
||||||
| `sync_runs` | id, source (pretix/sessionize), started_at, finished_at, created, updated, skipped, error, triggered_by | Audit trail of every interface sync (admin-only read) |
|
|
||||||
|
|
||||||
**Key RPCs** (all `security definer`, transactional): `lanyard_lookup`, `get_active_event`, `get_agenda`, `get_public_contacts`, `get_leaderboard`, `set_preference`, `clear_preference`, `create_connection_request`, `accept_connection`, `reject_connection`, `checkin_attendee`, `submit_feedback`, `adjust_points`, `reset_qr_token`, `upsert_contact`, `create_registration`, `set_registration_type`, `evaluate_session_feedback`, `set_session_material`, plus the **service-role-only** interface RPCs `sync_pretix_attendees` and `sync_sessionize_sessions` (called by the `sync-trigger` Edge Function — see [Interfaces](#interfaces-pretix--sessionize)).
|
**Key RPCs** (all `security definer`, transactional): `lanyard_lookup`, `get_active_event`, `get_agenda`, `get_public_contacts`, `get_leaderboard`, `set_preference`, `clear_preference`, `create_connection_request`, `accept_connection`, `reject_connection`, `checkin_attendee`, `submit_feedback`, `adjust_points`, `reset_qr_token`, `upsert_contact`, `create_registration`, `set_registration_type`, `evaluate_session_feedback`, `set_session_material`.
|
||||||
|
|
||||||
**RLS:** every table has policies. Contacts are self-or-admin; sponsors are visible only when `paid` (or to admins); schedule/registrations are readable per active event and writable by admin; the leaderboard is readable by any authenticated user. A `materials` storage bucket holds session materials (read for attendees, write for speakers/admins).
|
**RLS:** every table has policies. Contacts are self-or-admin; sponsors are visible only when `paid` (or to admins); schedule/registrations are readable per active event and writable by admin; the leaderboard is readable by any authenticated user. A `materials` storage bucket holds session materials (read for attendees, write for speakers/admins).
|
||||||
|
|
||||||
## Interfaces (Pretix & Sessionize)
|
|
||||||
|
|
||||||
Convivo syncs real ticket and agenda data from the conference's ticketing (Pretix) and
|
|
||||||
scheduling (Sessionize) platforms. The design is **pull-based**: an APPE Admin triggers a
|
|
||||||
sync on demand from the **Interfaces** view (or a cron job can call the same endpoint with
|
|
||||||
a shared secret).
|
|
||||||
|
|
||||||
- **`sync-trigger` Edge Function** — fetches from the configured Pretix/Sessionize base
|
|
||||||
URLs, normalizes the payloads, and calls the service-role-only RPCs
|
|
||||||
`sync_pretix_attendees` / `sync_sessionize_sessions`.
|
|
||||||
- **Pretix → contacts + registrations** — each attendee becomes a `contacts` row (with a
|
|
||||||
generated QR token if none supplied) and a `registrations` row; ticket type maps to
|
|
||||||
attendee/speaker/staff/sponsor.
|
|
||||||
- **Sessionize → slots + sessions + speakers** — each session is upserted by its
|
|
||||||
`external_id`, its time window becomes a `slots` row (find-or-create), and speakers are
|
|
||||||
linked via `session_speakers`.
|
|
||||||
- **Local mock API** (`interfaces/mock-api`, port 54330) — a dependency-free Node server
|
|
||||||
serving fixture data so the whole pipeline is testable without real tokens.
|
|
||||||
|
|
||||||
Full details: [`docs/backend/interfaces.md`](docs/backend/interfaces.md).
|
|
||||||
|
|
||||||
## 8. Tech stack
|
## 8. Tech stack
|
||||||
|
|
||||||
| Layer | Choice | Why |
|
| Layer | Choice | Why |
|
||||||
@@ -221,12 +195,10 @@ Convivo/
|
|||||||
│ └─ src/ # screens, components, lib, context
|
│ └─ src/ # screens, components, lib, context
|
||||||
├─ supabase/
|
├─ supabase/
|
||||||
│ ├─ config.toml # Local stack config (ports, auth, RLS defaults)
|
│ ├─ config.toml # Local stack config (ports, auth, RLS defaults)
|
||||||
│ ├─ migrations/ # 20260824000000_redesign.sql + 20260825000000_interfaces.sql
|
│ ├─ migrations/ # 20260824000000_redesign.sql + follow-up migrations
|
||||||
│ ├─ functions/ # sync-trigger Edge Function (Pretix/Sessionize sync)
|
|
||||||
│ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state
|
│ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state
|
||||||
├─ apps/admin/ # APPE Admin console (React + Vite + TS)
|
├─ apps/admin/ # APPE Admin console (React + Vite + TS)
|
||||||
├─ interfaces/mock-api/ # Mock Pretix + Sessionize API (Docker, :54330)
|
├─ docker-compose.yml # Runs the app sidecars on the Supabase network
|
||||||
├─ docker-compose.yml # Runs the app sidecars + mock-api on the Supabase network
|
|
||||||
└─ mockup/index.html # Original interactive mockup (design reference)
|
└─ mockup/index.html # Original interactive mockup (design reference)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -269,7 +241,6 @@ Open **http://localhost:3000** (attendee) and **http://localhost:3001** (admin).
|
|||||||
|---|---|
|
|---|---|
|
||||||
| Attendee app | **http://localhost:3000** |
|
| Attendee app | **http://localhost:3000** |
|
||||||
| Admin console (APPE Admin) | **http://localhost:3001** |
|
| Admin console (APPE Admin) | **http://localhost:3001** |
|
||||||
| Mock Pretix/Sessionize API | http://127.0.0.1:54330 |
|
|
||||||
| Supabase Studio | **http://localhost:54323** (user `postgres`, password `postgres`) |
|
| Supabase Studio | **http://localhost:54323** (user `postgres`, password `postgres`) |
|
||||||
| Supabase API (Kong) | http://127.0.0.1:54321 |
|
| Supabase API (Kong) | http://127.0.0.1:54321 |
|
||||||
| Postgres (direct) | `postgresql://postgres:[email protected]:54322/postgres` |
|
| Postgres (direct) | `postgresql://postgres:[email protected]:54322/postgres` |
|
||||||
@@ -320,10 +291,8 @@ Full detail in [`roadmap.md`](./roadmap.md).
|
|||||||
| **4** | **Redesign — APPE Admin**: rebrand + Contacts / Registrations / Sponsors / Schedule / Activity / event mgmt | ✅ |
|
| **4** | **Redesign — APPE Admin**: rebrand + Contacts / Registrations / Sponsors / Schedule / Activity / event mgmt | ✅ |
|
||||||
| **5** | **Redesign — Convivo App**: 24h login, 5s polling, QR type badge, red dot, speaker material | ✅ |
|
| **5** | **Redesign — Convivo App**: 24h login, 5s polling, QR type badge, red dot, speaker material | ✅ |
|
||||||
| **6** | **Redesign — branding**: APPE favicon + icons for both apps | ✅ |
|
| **6** | **Redesign — branding**: APPE favicon + icons for both apps | ✅ |
|
||||||
| **7** | **Pretix** interface — `sync-trigger` Edge Function → contacts + registrations (QR tokens, types, idempotent) + QR CSV export | ✅ |
|
|
||||||
| **8** | **Sessionize** interface — same Edge Function → slots + sessions + speakers (idempotent) | ✅ |
|
|
||||||
|
|
||||||
> **Subdomains** (`convivo.appe.at`, `admin.appe.at`, `db.appe.at`, `pretix.eu`, `sessionize.com`) do not exist yet — everything runs on **localhost** for now.
|
> **Subdomains** (`convivo.appe.at`, `admin.appe.at`, `db.appe.at`) do not exist yet — everything runs on **localhost** for now.
|
||||||
|
|
||||||
## 14. Out of scope (v1)
|
## 14. Out of scope (v1)
|
||||||
|
|
||||||
@@ -334,6 +303,5 @@ Full detail in [`roadmap.md`](./roadmap.md).
|
|||||||
|
|
||||||
## 15. Open questions
|
## 15. Open questions
|
||||||
|
|
||||||
1. **Schedule times** — the 6 slot times above are an assumption; confirm against the real agenda (Phase 4 will pull them from Sessionize).
|
1. **Schedule times** — the 6 slot times above are an assumption; confirm against the real agenda.
|
||||||
2. **Connection acceptance** — in-app only for v1? (Push notifications would be a later add-on.)
|
2. **Connection acceptance** — in-app only for v1? (Push notifications would be a later add-on.)
|
||||||
3. **Pretix mapping** — which ticket fields map to role (attendee/staff/admin) and company?
|
|
||||||
@@ -75,7 +75,7 @@ server {
|
|||||||
client_max_body_size 50M;
|
client_max_body_size 50M;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Edge Functions (e.g. sync-trigger for the Pretix/Sessionize interfaces).
|
# Edge Functions.
|
||||||
location /functions/ {
|
location /functions/ {
|
||||||
proxy_pass http://__SUPABASE_PROXY_TARGET__;
|
proxy_pass http://__SUPABASE_PROXY_TARGET__;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import { Sponsors } from './views/Sponsors';
|
|||||||
import { Schedule } from './views/Schedule';
|
import { Schedule } from './views/Schedule';
|
||||||
import { Activity } from './views/Activity';
|
import { Activity } from './views/Activity';
|
||||||
import { Events } from './views/Events';
|
import { Events } from './views/Events';
|
||||||
import { Sync } from './views/Sync';
|
|
||||||
import { Spinner } from './components/ui';
|
import { Spinner } from './components/ui';
|
||||||
|
|
||||||
export type View =
|
export type View =
|
||||||
@@ -19,8 +18,7 @@ export type View =
|
|||||||
| 'sponsors'
|
| 'sponsors'
|
||||||
| 'schedule'
|
| 'schedule'
|
||||||
| 'activity'
|
| 'activity'
|
||||||
| 'events'
|
| 'events';
|
||||||
| 'sync';
|
|
||||||
|
|
||||||
const NAV: { id: View; label: string; ico: string }[] = [
|
const NAV: { id: View; label: string; ico: string }[] = [
|
||||||
{ id: 'dashboard', label: 'Dashboard', ico: '📊' },
|
{ id: 'dashboard', label: 'Dashboard', ico: '📊' },
|
||||||
@@ -30,7 +28,6 @@ const NAV: { id: View; label: string; ico: string }[] = [
|
|||||||
{ id: 'schedule', label: 'Schedule', ico: '🗓️' },
|
{ id: 'schedule', label: 'Schedule', ico: '🗓️' },
|
||||||
{ id: 'activity', label: 'Activity', ico: '⚡' },
|
{ id: 'activity', label: 'Activity', ico: '⚡' },
|
||||||
{ id: 'events', label: 'Events', ico: '📅' },
|
{ id: 'events', label: 'Events', ico: '📅' },
|
||||||
{ id: 'sync', label: 'Interfaces', ico: '🔄' },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
function Shell() {
|
function Shell() {
|
||||||
@@ -98,7 +95,6 @@ function Shell() {
|
|||||||
{view === 'schedule' && <Schedule />}
|
{view === 'schedule' && <Schedule />}
|
||||||
{view === 'activity' && <Activity />}
|
{view === 'activity' && <Activity />}
|
||||||
{view === 'events' && <Events />}
|
{view === 'events' && <Events />}
|
||||||
{view === 'sync' && <Sync />}
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import type {
|
|||||||
SessionSpeaker,
|
SessionSpeaker,
|
||||||
Slot,
|
Slot,
|
||||||
Sponsor,
|
Sponsor,
|
||||||
SyncRun,
|
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
export class ApiError extends Error {}
|
export class ApiError extends Error {}
|
||||||
@@ -220,71 +219,3 @@ export async function evaluateSessionFeedback(sessionId: string): Promise<Sessio
|
|||||||
// evaluate_session_feedback returns a single composite row (a JSON object, not an array).
|
// 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 });
|
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 (!r.qr_token) continue;
|
|
||||||
lines.push([esc(c?.full_name ?? r.contact_email), esc(r.contact_email), esc(r.type), esc(r.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;
|
|
||||||
}
|
|
||||||
@@ -144,15 +144,3 @@ export interface ResetQrResult {
|
|||||||
email: string;
|
email: string;
|
||||||
qr_token: string;
|
qr_token: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SyncRun {
|
|
||||||
id: string;
|
|
||||||
source: 'pretix' | 'sessionize';
|
|
||||||
started_at: string;
|
|
||||||
finished_at: string | null;
|
|
||||||
created: number;
|
|
||||||
updated: number;
|
|
||||||
skipped: number;
|
|
||||||
error: string | null;
|
|
||||||
triggered_by: string;
|
|
||||||
}
|
|
||||||
@@ -114,8 +114,6 @@ body {
|
|||||||
.pill.swag { background: rgba(219,39,119,.12); border-color: rgba(219,39,119,.4); color: #be185d; }
|
.pill.swag { background: rgba(219,39,119,.12); border-color: rgba(219,39,119,.4); color: #be185d; }
|
||||||
.pill.catering { background: rgba(234,88,12,.13); border-color: rgba(234,88,12,.4); color: #c2410c; }
|
.pill.catering { background: rgba(234,88,12,.13); border-color: rgba(234,88,12,.4); color: #c2410c; }
|
||||||
.pill.diversity { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.4); color: #6d28d9; }
|
.pill.diversity { background: rgba(124,58,237,.12); border-color: rgba(124,58,237,.4); color: #6d28d9; }
|
||||||
/* sync result pills (Interfaces view) */
|
|
||||||
.sync-result { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
|
|
||||||
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 800; color: #fff; flex-shrink: 0; }
|
.avatar { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; font-weight: 800; color: #fff; flex-shrink: 0; }
|
||||||
.input, select.input {
|
.input, select.input {
|
||||||
width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
|
width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import {
|
|||||||
getAllContacts,
|
getAllContacts,
|
||||||
getActiveEvent,
|
getActiveEvent,
|
||||||
getRegistrations,
|
getRegistrations,
|
||||||
|
getSponsors,
|
||||||
setCheckedIn,
|
setCheckedIn,
|
||||||
setRegistrationType,
|
setRegistrationType,
|
||||||
upsertSponsor,
|
upsertSponsor,
|
||||||
} from '../lib/api';
|
} from '../lib/api';
|
||||||
import type { Contact, Event, Registration, RegistrationType, SponsorType } from '../lib/types';
|
import type { Contact, Event, Registration, RegistrationType, Sponsor, SponsorType } from '../lib/types';
|
||||||
import { useToast } from '../context/ToastContext';
|
import { useToast } from '../context/ToastContext';
|
||||||
import { Avatar, Empty, Modal, QrImage, Spinner, Toggle, TypeBadge } from '../components/ui';
|
import { Avatar, Empty, Modal, QrImage, Spinner, Toggle, TypeBadge } from '../components/ui';
|
||||||
|
|
||||||
@@ -234,7 +235,7 @@ export function Registrations() {
|
|||||||
<QrImage value={qrFor.qr_token ?? ''} size={190} />
|
<QrImage value={qrFor.qr_token ?? ''} size={190} />
|
||||||
<div className="token-big">{qrFor.qr_token ?? '—'}</div>
|
<div className="token-big">{qrFor.qr_token ?? '—'}</div>
|
||||||
<p className="muted small">
|
<p className="muted small">
|
||||||
This token is final — it was generated by Pretix and can’t be reset.
|
This token is final — it was generated for this event and can’t be reset.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -350,6 +351,8 @@ function SponsorLookupModal({
|
|||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onSaved: (msg: string) => void;
|
onSaved: (msg: string) => void;
|
||||||
}) {
|
}) {
|
||||||
|
const [sponsors, setSponsors] = useState<Sponsor[]>([]);
|
||||||
|
const [selectedSponsorId, setSelectedSponsorId] = useState('');
|
||||||
const [type, setType] = useState<SponsorType>('gold');
|
const [type, setType] = useState<SponsorType>('gold');
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
@@ -359,12 +362,32 @@ function SponsorLookupModal({
|
|||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
const contactEmail = registration.contact_email;
|
const contactEmail = registration.contact_email;
|
||||||
|
const isExisting = selectedSponsorId !== '';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getSponsors(eventId).then(setSponsors).catch(() => setSponsors([]));
|
||||||
|
}, [eventId]);
|
||||||
|
|
||||||
|
function pickSponsor(id: string) {
|
||||||
|
setSelectedSponsorId(id);
|
||||||
|
if (id) {
|
||||||
|
const s = sponsors.find((x) => x.id === id);
|
||||||
|
if (s) {
|
||||||
|
setType(s.type);
|
||||||
|
setName(s.name);
|
||||||
|
setEmail(s.email ?? '');
|
||||||
|
setPhone(s.phone ?? '');
|
||||||
|
setPaid(s.paid);
|
||||||
|
setAmount(s.amount_eur != null ? String(s.amount_eur) : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function save() {
|
async function save() {
|
||||||
if (!name.trim()) return;
|
if (!name.trim()) return;
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
try {
|
try {
|
||||||
await upsertSponsor(null, {
|
await upsertSponsor(selectedSponsorId || null, {
|
||||||
event_id: eventId,
|
event_id: eventId,
|
||||||
type,
|
type,
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
@@ -375,7 +398,11 @@ function SponsorLookupModal({
|
|||||||
contact_email: contactEmail,
|
contact_email: contactEmail,
|
||||||
});
|
});
|
||||||
await setRegistrationType(contactEmail, 'sponsor');
|
await setRegistrationType(contactEmail, 'sponsor');
|
||||||
onSaved(`Sponsor "${name.trim()}" created — ${contact?.full_name ?? contactEmail} is now a sponsor`);
|
onSaved(
|
||||||
|
isExisting
|
||||||
|
? `Sponsor "${name.trim()}" linked — ${contact?.full_name ?? contactEmail} is now a sponsor`
|
||||||
|
: `Sponsor "${name.trim()}" created — ${contact?.full_name ?? contactEmail} is now a sponsor`,
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
onSaved(e instanceof Error ? e.message : 'Save failed');
|
onSaved(e instanceof Error ? e.message : 'Save failed');
|
||||||
} finally {
|
} finally {
|
||||||
@@ -394,15 +421,26 @@ function SponsorLookupModal({
|
|||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button className="btn primary" disabled={busy || !name.trim()} onClick={save}>
|
<button className="btn primary" disabled={busy || !name.trim()} onClick={save}>
|
||||||
{busy ? 'Saving…' : 'Create sponsor & set type'}
|
{busy ? 'Saving…' : isExisting ? 'Link sponsor & set type' : 'Create sponsor & set type'}
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<p className="muted small" style={{ marginBottom: 14 }}>
|
<p className="muted small" style={{ marginBottom: 14 }}>
|
||||||
A sponsor registration needs a sponsor lookup. Create the sponsor below — it will be linked to{' '}
|
A sponsor registration needs a sponsor lookup. Link an existing sponsor or create a new one — it will be
|
||||||
<b>{contact?.full_name ?? contactEmail}</b> and their registration type set to <b>Sponsor</b>.
|
linked to <b>{contact?.full_name ?? contactEmail}</b> and their registration type set to <b>Sponsor</b>.
|
||||||
</p>
|
</p>
|
||||||
|
<div className="field" style={{ marginBottom: 14 }}>
|
||||||
|
<label>Sponsor</label>
|
||||||
|
<select className="input" value={selectedSponsorId} onChange={(e) => pickSponsor(e.target.value)}>
|
||||||
|
<option value="">— Create new —</option>
|
||||||
|
{sponsors.map((s) => (
|
||||||
|
<option key={s.id} value={s.id}>
|
||||||
|
{s.name} ({s.type})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div className="grid-2">
|
<div className="grid-2">
|
||||||
<div className="field">
|
<div className="field">
|
||||||
<label>Sponsor type</label>
|
<label>Sponsor type</label>
|
||||||
|
|||||||
@@ -1,240 +0,0 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
|
||||||
import {
|
|
||||||
exportQrCsv,
|
|
||||||
getActiveEvent,
|
|
||||||
getSyncRuns,
|
|
||||||
triggerSync,
|
|
||||||
type SyncResult,
|
|
||||||
} from '../lib/api';
|
|
||||||
import type { Event, SyncRun } from '../lib/types';
|
|
||||||
import { useToast } from '../context/ToastContext';
|
|
||||||
import { Empty, Spinner } from '../components/ui';
|
|
||||||
|
|
||||||
type Source = 'pretix' | 'sessionize' | 'both';
|
|
||||||
|
|
||||||
function fmtTime(iso: string | null): string {
|
|
||||||
if (!iso) return '—';
|
|
||||||
const d = new Date(iso);
|
|
||||||
return d.toLocaleString(undefined, {
|
|
||||||
month: 'short',
|
|
||||||
day: 'numeric',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
second: '2-digit',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function SourcePill({ source }: { source: SyncRun['source'] }) {
|
|
||||||
return <span className={`pill ${source === 'pretix' ? 'gold' : 'green'}`}>{source}</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function Sync() {
|
|
||||||
const { push } = useToast();
|
|
||||||
const [event, setEvent] = useState<Event | null>(null);
|
|
||||||
const [loaded, setLoaded] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [runs, setRuns] = useState<SyncRun[]>([]);
|
|
||||||
const [busy, setBusy] = useState<Source | null>(null);
|
|
||||||
const [last, setLast] = useState<SyncResult | null>(null);
|
|
||||||
|
|
||||||
const load = useCallback(async () => {
|
|
||||||
try {
|
|
||||||
const [ev, r] = await Promise.all([getActiveEvent(), getSyncRuns(8)]);
|
|
||||||
setEvent(ev);
|
|
||||||
setRuns(r);
|
|
||||||
setLoaded(true);
|
|
||||||
} catch (e) {
|
|
||||||
setError(e instanceof Error ? e.message : 'Failed to load');
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
load();
|
|
||||||
}, [load]);
|
|
||||||
|
|
||||||
async function doSync(source: Source) {
|
|
||||||
setBusy(source);
|
|
||||||
setLast(null);
|
|
||||||
try {
|
|
||||||
const res = await triggerSync(source);
|
|
||||||
setLast(res);
|
|
||||||
const bits: string[] = [];
|
|
||||||
if (res.results.pretix)
|
|
||||||
bits.push(`Pretix: ${res.results.pretix.updated} updated`);
|
|
||||||
if (res.results.sessionize)
|
|
||||||
bits.push(
|
|
||||||
`Sessionize: ${res.results.sessionize.sessions_created} new, ${res.results.sessionize.sessions_updated} updated`,
|
|
||||||
);
|
|
||||||
push(res.ok ? 'success' : 'error', res.ok ? `Sync complete — ${bits.join(' · ')}` : `Sync finished with errors`);
|
|
||||||
await load();
|
|
||||||
} catch (e) {
|
|
||||||
push('error', e instanceof Error ? e.message : 'Sync failed');
|
|
||||||
} finally {
|
|
||||||
setBusy(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function doExport() {
|
|
||||||
if (!event) return;
|
|
||||||
try {
|
|
||||||
const n = await exportQrCsv(event.id);
|
|
||||||
push('success', `Exported ${n} lanyard QR code${n === 1 ? '' : 's'} to CSV`);
|
|
||||||
} catch (e) {
|
|
||||||
push('error', e instanceof Error ? e.message : 'Export failed');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) return <Empty icon="⚠️" text={error} />;
|
|
||||||
if (!loaded)
|
|
||||||
return (
|
|
||||||
<div className="loading-screen">
|
|
||||||
<Spinner />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<div className="page-head">
|
|
||||||
<div>
|
|
||||||
<h1>Interfaces</h1>
|
|
||||||
<div className="sub">
|
|
||||||
Sync real data from <strong>Pretix</strong> (tickets → contacts + registrations) and{' '}
|
|
||||||
<strong>Sessionize</strong> (agenda → slots + sessions + speakers).
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="row" style={{ gap: 8 }}>
|
|
||||||
<button className="btn" disabled={busy !== null} onClick={() => doExport()}>
|
|
||||||
⬇ Export QR CSV
|
|
||||||
</button>
|
|
||||||
<button className="btn primary" disabled={busy !== null} onClick={() => doSync('both')}>
|
|
||||||
{busy === 'both' ? 'Syncing…' : '🔄 Sync all'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{!event && (
|
|
||||||
<div className="card" style={{ marginBottom: 16 }}>
|
|
||||||
<Empty icon="📅" text="No active event. Syncs target the active event — set one in the Events view." />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="grid-2">
|
|
||||||
<div className="card">
|
|
||||||
<div className="row between" style={{ marginBottom: 14 }}>
|
|
||||||
<h2 className="h2">🎟️ Pretix</h2>
|
|
||||||
<button
|
|
||||||
className="btn small"
|
|
||||||
disabled={busy !== null || !event}
|
|
||||||
onClick={() => doSync('pretix')}
|
|
||||||
>
|
|
||||||
{busy === 'pretix' ? 'Syncing…' : 'Sync now'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<p className="muted small" style={{ marginTop: 0 }}>
|
|
||||||
Pulls ticket holders and upserts <code>contacts</code> + <code>registrations</code> (QR tokens
|
|
||||||
generated for new ticket holders). Ticket type maps to registration type
|
|
||||||
(speaker / staff / sponsor / attendee).
|
|
||||||
</p>
|
|
||||||
{last?.results.pretix && (
|
|
||||||
<div className="sync-result">
|
|
||||||
<span className="pill green">{last.results.pretix.updated} updated</span>
|
|
||||||
<span className="pill">{last.results.pretix.skipped} skipped</span>
|
|
||||||
{last.results.pretix.errors.length > 0 && (
|
|
||||||
<span className="pill red">{last.results.pretix.errors.length} errors</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="card">
|
|
||||||
<div className="row between" style={{ marginBottom: 14 }}>
|
|
||||||
<h2 className="h2">🗓️ Sessionize</h2>
|
|
||||||
<button
|
|
||||||
className="btn small"
|
|
||||||
disabled={busy !== null || !event}
|
|
||||||
onClick={() => doSync('sessionize')}
|
|
||||||
>
|
|
||||||
{busy === 'sessionize' ? 'Syncing…' : 'Sync now'}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<p className="muted small" style={{ marginTop: 0 }}>
|
|
||||||
Pulls the agenda and upserts <code>slots</code> + <code>sessions</code> + speakers. Slots are
|
|
||||||
matched by date + time; sessions by their Sessionize id.
|
|
||||||
</p>
|
|
||||||
{last?.results.sessionize && (
|
|
||||||
<div className="sync-result">
|
|
||||||
<span className="pill green">{last.results.sessionize.sessions_created} new</span>
|
|
||||||
<span className="pill">{last.results.sessionize.sessions_updated} updated</span>
|
|
||||||
<span className="pill">{last.results.sessionize.slots_created} slots</span>
|
|
||||||
<span className="pill">{last.results.sessionize.speakers_linked} speakers</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{last && last.errors.length > 0 && (
|
|
||||||
<div className="card" style={{ marginTop: 16, borderColor: 'var(--red, #d50000)' }}>
|
|
||||||
<h2 className="h2" style={{ color: 'var(--red, #d50000)' }}>
|
|
||||||
⚠️ Sync errors
|
|
||||||
</h2>
|
|
||||||
<ul className="muted small" style={{ margin: '8px 0 0', paddingLeft: 18 }}>
|
|
||||||
{last.errors.map((e, i) => (
|
|
||||||
<li key={i}>{e}</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="card" style={{ marginTop: 16 }}>
|
|
||||||
<div className="row between" style={{ marginBottom: 14 }}>
|
|
||||||
<h2 className="h2">🕘 Recent sync runs</h2>
|
|
||||||
<button className="btn small ghost" onClick={load}>
|
|
||||||
Refresh
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{runs.length === 0 ? (
|
|
||||||
<Empty icon="🔄" text="No sync runs yet. Trigger one above." />
|
|
||||||
) : (
|
|
||||||
<div className="table-wrap">
|
|
||||||
<table className="data">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Source</th>
|
|
||||||
<th>Started</th>
|
|
||||||
<th>Created</th>
|
|
||||||
<th>Updated</th>
|
|
||||||
<th>Skipped</th>
|
|
||||||
<th>Triggered by</th>
|
|
||||||
<th>Status</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{runs.map((r) => (
|
|
||||||
<tr key={r.id}>
|
|
||||||
<td>
|
|
||||||
<SourcePill source={r.source} />
|
|
||||||
</td>
|
|
||||||
<td className="muted small">{fmtTime(r.started_at)}</td>
|
|
||||||
<td>{r.created}</td>
|
|
||||||
<td>{r.updated}</td>
|
|
||||||
<td>{r.skipped}</td>
|
|
||||||
<td className="muted small">{r.triggered_by}</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>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -14,8 +14,7 @@ export interface Contact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** The signed-in contact's registration for the active event.
|
/** The signed-in contact's registration for the active event.
|
||||||
* The QR token lives here (per event, generated by Pretix) and doubles as
|
* The QR token lives here (per event) and doubles as the login password. */
|
||||||
* the login password. */
|
|
||||||
export interface Registration {
|
export interface Registration {
|
||||||
id: string;
|
id: string;
|
||||||
event_id: string;
|
event_id: string;
|
||||||
|
|||||||
@@ -76,28 +76,6 @@ services:
|
|||||||
retries: 5
|
retries: 5
|
||||||
start_period: 10s
|
start_period: 10s
|
||||||
|
|
||||||
# Mock Pretix + Sessionize API (Phase 7 + 8). Serves the same response shapes
|
|
||||||
# as the real APIs so the `sync-trigger` Edge Function can be tested end-to-end
|
|
||||||
# without real credentials. The Edge Function reaches it at http://mock-api:54330.
|
|
||||||
mock-api:
|
|
||||||
build:
|
|
||||||
context: ./interfaces/mock-api
|
|
||||||
image: convivo-mock-api:latest
|
|
||||||
container_name: convivo-mock-api
|
|
||||||
ports:
|
|
||||||
- "54330:54330"
|
|
||||||
environment:
|
|
||||||
PORT: "54330"
|
|
||||||
networks:
|
|
||||||
- supabase
|
|
||||||
restart: unless-stopped
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "wget", "-qO-", "http://127.0.0.1:54330/health"]
|
|
||||||
interval: 15s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 5
|
|
||||||
start_period: 5s
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
supabase:
|
supabase:
|
||||||
# External network created by `supabase start`. Name = supabase_network_<project_id>.
|
# External network created by `supabase start`. Name = supabase_network_<project_id>.
|
||||||
|
|||||||
+2
-6
@@ -4,12 +4,10 @@ Living documentation for **Convivo** — a conference networking app that turns
|
|||||||
conference into a game. This folder is the single source of truth for *how the
|
conference into a game. This folder is the single source of truth for *how the
|
||||||
system works*; the root [`README.md`](../README.md) is the quick-start.
|
system works*; the root [`README.md`](../README.md) is the quick-start.
|
||||||
|
|
||||||
> **Status:** Phases 0–8 are complete and verified. The **Redesign** (Phases
|
> **Status:** Phases 0–6 are complete and verified. The **Redesign** (Phases
|
||||||
> 3–6) is done: the new multi-event data model is live, the admin app is
|
> 3–6) is done: the new multi-event data model is live, the admin app is
|
||||||
> rebranded to **APPE Admin**, the Convivo App has all the new behaviors, and both
|
> rebranded to **APPE Admin**, the Convivo App has all the new behaviors, and both
|
||||||
> apps carry the APPE branding. **Phases 7–8** added the Pretix + Sessionize
|
> apps carry the APPE branding. See the root
|
||||||
> interfaces (sync RPCs, `sync-trigger` Edge Function, mock API, APPE Admin
|
|
||||||
> Interfaces view). See the root
|
|
||||||
> [`roadmap.md`](../roadmap.md) and [next-steps.md](./next-steps.md).
|
> [`roadmap.md`](../roadmap.md) and [next-steps.md](./next-steps.md).
|
||||||
|
|
||||||
## Where things live
|
## Where things live
|
||||||
@@ -22,7 +20,6 @@ system works*; the root [`README.md`](../README.md) is the quick-start.
|
|||||||
| Database schema (all tables) | [backend/schema.md](./backend/schema.md) |
|
| Database schema (all tables) | [backend/schema.md](./backend/schema.md) |
|
||||||
| Transactional points RPCs (the business logic) | [backend/rpcs.md](./backend/rpcs.md) |
|
| Transactional points RPCs (the business logic) | [backend/rpcs.md](./backend/rpcs.md) |
|
||||||
| Row Level Security policies | [backend/rls.md](./backend/rls.md) |
|
| Row Level Security policies | [backend/rls.md](./backend/rls.md) |
|
||||||
| **Interfaces (Pretix + Sessionize sync)** | [backend/interfaces.md](./backend/interfaces.md) |
|
|
||||||
| Seed data + demo accounts | [backend/seed.md](./backend/seed.md) |
|
| Seed data + demo accounts | [backend/seed.md](./backend/seed.md) |
|
||||||
| Docker (app image + compose) | [backend/docker.md](./backend/docker.md) |
|
| Docker (app image + compose) | [backend/docker.md](./backend/docker.md) |
|
||||||
| **Frontend — overview (both apps)** | [frontend/README.md](./frontend/README.md) |
|
| **Frontend — overview (both apps)** | [frontend/README.md](./frontend/README.md) |
|
||||||
@@ -52,7 +49,6 @@ system works*; the root [`README.md`](../README.md) is the quick-start.
|
|||||||
- **Code is the source of truth.** If a doc and the code disagree, the code wins —
|
- **Code is the source of truth.** If a doc and the code disagree, the code wins —
|
||||||
fix the doc. Key files:
|
fix the doc. Key files:
|
||||||
- Schema + RPCs + RLS (the Redesign, **current**): [`supabase/migrations/20260824000000_redesign.sql`](../supabase/migrations/20260824000000_redesign.sql)
|
- Schema + RPCs + RLS (the Redesign, **current**): [`supabase/migrations/20260824000000_redesign.sql`](../supabase/migrations/20260824000000_redesign.sql)
|
||||||
- Interfaces (Pretix + Sessionize sync): [`supabase/migrations/20260825000000_interfaces.sql`](../supabase/migrations/20260825000000_interfaces.sql) + [`supabase/functions/sync-trigger/`](../supabase/functions/sync-trigger/)
|
|
||||||
- Earlier migrations (applied, then replaced by the Redesign): [`20260822000000_init.sql`](../supabase/migrations/20260822000000_init.sql), [`20260823000000_admin_app.sql`](../supabase/migrations/20260823000000_admin_app.sql)
|
- Earlier migrations (applied, then replaced by the Redesign): [`20260822000000_init.sql`](../supabase/migrations/20260822000000_init.sql), [`20260823000000_admin_app.sql`](../supabase/migrations/20260823000000_admin_app.sql)
|
||||||
- Seed: [`supabase/seed.sql`](../supabase/seed.sql)
|
- Seed: [`supabase/seed.sql`](../supabase/seed.sql)
|
||||||
- Attendee app source: [`apps/convivo/src/`](../apps/convivo/src/)
|
- Attendee app source: [`apps/convivo/src/`](../apps/convivo/src/)
|
||||||
|
|||||||
+4
-11
@@ -34,20 +34,16 @@ flowchart LR
|
|||||||
K --> R["PostgREST"]
|
K --> R["PostgREST"]
|
||||||
K --> RT["Realtime"]
|
K --> RT["Realtime"]
|
||||||
K --> S["Storage"]
|
K --> S["Storage"]
|
||||||
K --> EF["Edge Functions<br/>sync-trigger"]
|
|
||||||
R --> P[("Postgres 17<br/>schema · RLS · points RPCs")]
|
R --> P[("Postgres 17<br/>schema · RLS · points RPCs")]
|
||||||
RT --> P
|
RT --> P
|
||||||
G --> P
|
G --> P
|
||||||
EF -->|"service-role RPCs"| R
|
|
||||||
end
|
end
|
||||||
MA["mock-api (:54330)<br/>Pretix + Sessionize fixtures"]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
A -->|"same-origin /auth /rest /realtime /storage /functions"| N
|
A -->|"same-origin /auth /rest /realtime /storage /functions"| N
|
||||||
AD -->|"same-origin /auth /rest /realtime /storage /functions"| NA
|
AD -->|"same-origin /auth /rest /realtime /storage /functions"| NA
|
||||||
N -->|"proxy (supabase_kong_Convivo:8000)"| K
|
N -->|"proxy (supabase_kong_Convivo:8000)"| K
|
||||||
NA -->|"proxy (supabase_kong_Convivo:8000)"| K
|
NA -->|"proxy (supabase_kong_Convivo:8000)"| K
|
||||||
EF -->|"GET /pretix/attendees · /sessionize/sessions"| MA
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Key idea:** there is **no custom backend**. Supabase provides auth, data,
|
**Key idea:** there is **no custom backend**. Supabase provides auth, data,
|
||||||
@@ -62,7 +58,6 @@ talks to Supabase through **same-origin paths**, so there is no CORS to manage.
|
|||||||
| App | **React 18 + Vite 5 + TypeScript** (PWA) | Fast, mobile-first, installable; same-origin proxy avoids CORS |
|
| App | **React 18 + Vite 5 + TypeScript** (PWA) | Fast, mobile-first, installable; same-origin proxy avoids CORS |
|
||||||
| QR | `html5-qrcode` (scan) + `qrcode.react` (render) | Camera scan with manual-entry fallback |
|
| QR | `html5-qrcode` (scan) + `qrcode.react` (render) | Camera scan with manual-entry fallback |
|
||||||
| Client | `@supabase/supabase-js` | Auth + REST + Realtime in one client |
|
| Client | `@supabase/supabase-js` | Auth + REST + Realtime in one client |
|
||||||
| Interfaces | **`sync-trigger` Edge Function** (Deno) + **mock API** (Node) | Pulls real Pretix/Sessionize data and imports it via service-role RPCs; the mock API serves fixtures locally |
|
|
||||||
| Packaging | **Docker** (multi-stage build → nginx) | The app is a sidecar that joins the Supabase network |
|
| Packaging | **Docker** (multi-stage build → nginx) | The app is a sidecar that joins the Supabase network |
|
||||||
|
|
||||||
## 4. The two halves
|
## 4. The two halves
|
||||||
@@ -75,9 +70,6 @@ Everything server-side lives in Postgres. See [backend/README.md](./backend/READ
|
|||||||
keep the leaderboard consistent. → [backend/rpcs.md](./backend/rpcs.md)
|
keep the leaderboard consistent. → [backend/rpcs.md](./backend/rpcs.md)
|
||||||
- **Security** — Row Level Security on every table; the app only ever uses the
|
- **Security** — Row Level Security on every table; the app only ever uses the
|
||||||
**anon key + the user's session JWT**. → [backend/rls.md](./backend/rls.md)
|
**anon key + the user's session JWT**. → [backend/rls.md](./backend/rls.md)
|
||||||
- **Interfaces** — service-role-only sync RPCs (`sync_pretix_attendees`,
|
|
||||||
`sync_sessionize_sessions`) called by the `sync-trigger` Edge Function, which
|
|
||||||
pulls from Pretix/Sessionize (or the local mock API). → [backend/interfaces.md](./backend/interfaces.md)
|
|
||||||
- **Data** — seed with 1 event, 6 slots, 18 sessions, 14 contacts, 13
|
- **Data** — seed with 1 event, 6 slots, 18 sessions, 14 contacts, 13
|
||||||
registrations, 3 sponsors. → [backend/seed.md](./backend/seed.md)
|
registrations, 3 sponsors. → [backend/seed.md](./backend/seed.md)
|
||||||
|
|
||||||
@@ -93,7 +85,7 @@ A separate desktop-first React app for organizers, guarded to the **`is_admin`**
|
|||||||
flag. See [frontend/admin-app.md](./frontend/admin-app.md):
|
flag. See [frontend/admin-app.md](./frontend/admin-app.md):
|
||||||
- **Views** — Dashboard (active event + aggregates), Contacts, Registrations,
|
- **Views** — Dashboard (active event + aggregates), Contacts, Registrations,
|
||||||
Sponsors, Schedule (slots/sessions/speakers/material/AI-evaluate), Activity,
|
Sponsors, Schedule (slots/sessions/speakers/material/AI-evaluate), Activity,
|
||||||
Events, and **Interfaces** (trigger Pretix/Sessionize syncs + export the QR CSV).
|
and Events.
|
||||||
- **Auth guard** — same QR + email login, but non-admin sessions are rejected.
|
- **Auth guard** — same QR + email login, but non-admin sessions are rejected.
|
||||||
- **Key RPCs** — `reset_registration_qr_token` (regenerate a registration's
|
- **Key RPCs** — `reset_registration_qr_token` (regenerate a registration's
|
||||||
lanyard token + sync the Auth password), `adjust_points`, `upsert_contact`,
|
lanyard token + sync the Auth password), `adjust_points`, `upsert_contact`,
|
||||||
@@ -192,8 +184,9 @@ Convivo/
|
|||||||
│ │ ├─ 20260822000000_init.sql # original schema (replaced by the Redesign)
|
│ │ ├─ 20260822000000_init.sql # original schema (replaced by the Redesign)
|
||||||
│ │ ├─ 20260823000000_admin_app.sql # admin read RLS + reset_qr_token (superseded)
|
│ │ ├─ 20260823000000_admin_app.sql # admin read RLS + reset_qr_token (superseded)
|
||||||
│ │ ├─ 20260824000000_redesign.sql # multi-event model, RPCs, RLS, materials
|
│ │ ├─ 20260824000000_redesign.sql # multi-event model, RPCs, RLS, materials
|
||||||
│ │ ├─ 20260825000000_interfaces.sql # external_id + sync_runs + sync RPCs
|
│ │ ├─ 20260825000000_interfaces.sql # external_id (sync objects later dropped)
|
||||||
│ │ └─ 20260826000000_registration_qr_token.sql # ← current: QR token on registration
|
│ │ ├─ 20260826000000_registration_qr_token.sql # QR token on registration
|
||||||
|
│ │ └─ 20260830000000_remove_interfaces.sql # ← drops the sync RPCs + sync_runs
|
||||||
│ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state
|
│ └─ seed.sql # 1 event, 6 slots, 18 sessions, 14 contacts, demo state
|
||||||
├─ docker-compose.yml # Runs both app sidecars on the Supabase network
|
├─ docker-compose.yml # Runs both app sidecars on the Supabase network
|
||||||
├─ docs/ # ← this documentation
|
├─ docs/ # ← this documentation
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ Postgres. This folder documents that core.
|
|||||||
| [schema.md](./schema.md) | All 14 tables, columns, constraints, indexes |
|
| [schema.md](./schema.md) | All 14 tables, columns, constraints, indexes |
|
||||||
| [rpcs.md](./rpcs.md) | The transactional points RPCs (the business logic) |
|
| [rpcs.md](./rpcs.md) | The transactional points RPCs (the business logic) |
|
||||||
| [rls.md](./rls.md) | Row Level Security policies + which key the app uses |
|
| [rls.md](./rls.md) | Row Level Security policies + which key the app uses |
|
||||||
| [interfaces.md](./interfaces.md) | Pretix + Sessionize sync (RPCs, `sync-trigger` Edge Function, mock API) |
|
|
||||||
| [seed.md](./seed.md) | Seed data + the demo accounts |
|
| [seed.md](./seed.md) | Seed data + the demo accounts |
|
||||||
| [docker.md](./docker.md) | Docker: the app image + root compose (how the core + app run together) |
|
| [docker.md](./docker.md) | Docker: the app image + root compose (how the core + app run together) |
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ Postgres. This folder documents that core.
|
|||||||
Postgres 17 ── schema (14 tables, multi-event model)
|
Postgres 17 ── schema (14 tables, multi-event model)
|
||||||
── RLS (who can read/write what)
|
── RLS (who can read/write what)
|
||||||
── RPCs (security definer, transactional points logic)
|
── RPCs (security definer, transactional points logic)
|
||||||
── sync RPCs (service-role-only Pretix/Sessionize import)
|
|
||||||
── seed (demo data)
|
── seed (demo data)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -29,10 +27,7 @@ Postgres 17 ── schema (14 tables, multi-event model)
|
|||||||
rules.
|
rules.
|
||||||
- **RLS is the security boundary.** The app uses the **anon key + the user's
|
- **RLS is the security boundary.** The app uses the **anon key + the user's
|
||||||
session JWT**; RLS decides what that user may see and do. The service-role key
|
session JWT**; RLS decides what that user may see and do. The service-role key
|
||||||
is never shipped to the app. See [rls.md](./rls.md). The one exception is the
|
is never shipped to the app. See [rls.md](./rls.md).
|
||||||
**interface sync RPCs**, which are `service_role`-only and are called by the
|
|
||||||
`sync-trigger` Edge Function (which holds the service-role key server-side).
|
|
||||||
See [interfaces.md](./interfaces.md).
|
|
||||||
- **Points are transactional.** Each RPC updates points, inserts the related row,
|
- **Points are transactional.** Each RPC updates points, inserts the related row,
|
||||||
and re-syncs the `leaderboard` mirror in **one transaction**, so the leaderboard
|
and re-syncs the `leaderboard` mirror in **one transaction**, so the leaderboard
|
||||||
is always consistent and duplicate actions never double-award. See [rpcs.md](./rpcs.md).
|
is always consistent and duplicate actions never double-award. See [rpcs.md](./rpcs.md).
|
||||||
@@ -40,7 +35,6 @@ Postgres 17 ── schema (14 tables, multi-event model)
|
|||||||
## Source of truth
|
## Source of truth
|
||||||
|
|
||||||
- Schema + RPCs + RLS (the Redesign, **current**): [`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
|
- Schema + RPCs + RLS (the Redesign, **current**): [`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
|
||||||
- Interfaces (Pretix + Sessionize sync): [`supabase/migrations/20260825000000_interfaces.sql`](../../supabase/migrations/20260825000000_interfaces.sql) + [`supabase/functions/sync-trigger/`](../../supabase/functions/sync-trigger/)
|
|
||||||
- Earlier migrations (still applied, then replaced by the Redesign):
|
- Earlier migrations (still applied, then replaced by the Redesign):
|
||||||
[`20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql) and
|
[`20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql) and
|
||||||
[`20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)
|
[`20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)
|
||||||
|
|||||||
@@ -1,209 +0,0 @@
|
|||||||
# Interfaces — Pretix + Sessionize sync (Phase 7 + 8)
|
|
||||||
|
|
||||||
Convivo can pull **real** data from the two systems that run a conference:
|
|
||||||
|
|
||||||
- **Pretix** — ticket sales → `contacts` + `registrations` (with generated QR
|
|
||||||
tokens).
|
|
||||||
- **Sessionize** — the agenda → `slots` + `sessions` + `session_speakers`.
|
|
||||||
|
|
||||||
This replaces the hand-written seed with live event data. The sync is
|
|
||||||
**idempotent** (safe to re-run) and **audited** (every run is recorded).
|
|
||||||
|
|
||||||
> **Local testing:** a mock Pretix/Sessionize API (`interfaces/mock-api/`) serves
|
|
||||||
> the same response shapes as the real APIs, so the whole pipeline is testable
|
|
||||||
> end-to-end without real credentials. See [Testing](#testing-with-the-mock-api).
|
|
||||||
|
|
||||||
## Architecture
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
flowchart LR
|
|
||||||
subgraph Admin["APPE Admin (:3001)"]
|
|
||||||
UI["Interfaces view<br/>Sync now / Sync all / Export QR CSV"]
|
|
||||||
end
|
|
||||||
subgraph Core["Supabase core"]
|
|
||||||
K["Kong :54321"]
|
|
||||||
EF["Edge Function<br/>sync-trigger"]
|
|
||||||
PG[("Postgres<br/>sync RPCs + sync_runs")]
|
|
||||||
end
|
|
||||||
P[("Pretix API")]
|
|
||||||
S[("Sessionize API")]
|
|
||||||
M[("mock-api :54330<br/>(local fixtures)")]
|
|
||||||
|
|
||||||
UI -->|"POST /functions/v1/sync-trigger<br/>(admin JWT)"| K
|
|
||||||
K --> EF
|
|
||||||
EF -->|"GET /pretix/attendees"| P
|
|
||||||
EF -->|"GET /sessionize/sessions"| S
|
|
||||||
EF -.->|"local: same paths"| M
|
|
||||||
EF -->|"service-role RPC"| PG
|
|
||||||
PG --> PG
|
|
||||||
```
|
|
||||||
|
|
||||||
The **Edge Function** is the only component that talks to the external APIs and
|
|
||||||
holds the **service-role key**. The apps never do.
|
|
||||||
|
|
||||||
## Components
|
|
||||||
|
|
||||||
| Piece | Where | Role |
|
|
||||||
|---|---|---|
|
|
||||||
| `sync-trigger` Edge Function | `supabase/functions/sync-trigger/index.ts` | Auth (admin/cron), fetch + normalize external data, call the sync RPCs |
|
|
||||||
| `sync_pretix_attendees(jsonb)` | migration `20260825000000_interfaces.sql` | Upsert contacts + registrations (+ auth users) |
|
|
||||||
| `sync_sessionize_sessions(jsonb)` | same migration | Upsert slots + sessions + speakers |
|
|
||||||
| `sync_runs` table | same migration | Audit trail of every run |
|
|
||||||
| `mock-api` service | `interfaces/mock-api/` | Local Pretix/Sessionize stand-in (Docker, :54330) |
|
|
||||||
| Interfaces view | `apps/admin/src/views/Sync.tsx` | Trigger syncs, show results + run history, export QR CSV |
|
|
||||||
|
|
||||||
## The Edge Function (`sync-trigger`)
|
|
||||||
|
|
||||||
**Trigger:** `POST /functions/v1/sync-trigger` with body `{ "source": "pretix" | "sessionize" | "both" }`.
|
|
||||||
|
|
||||||
**Auth** (either):
|
|
||||||
- A valid **admin** JWT in the `Authorization` header — the APPE Admin app
|
|
||||||
passes its session token. The function verifies it by calling the `is_admin()`
|
|
||||||
RPC with that token.
|
|
||||||
- A matching `x-cron-secret` header == `CRON_SECRET` — for scheduled runs.
|
|
||||||
|
|
||||||
**Flow:**
|
|
||||||
1. Verify the caller (admin or cron).
|
|
||||||
2. For each requested source, `fetch` the external API and **normalize** the
|
|
||||||
response into the shape the sync RPC expects.
|
|
||||||
3. Call the service-role sync RPC via PostgREST
|
|
||||||
(`${SUPABASE_URL}/rest/v1/rpc/<fn>`, `apikey` + `Authorization` = service-role key).
|
|
||||||
4. Return a JSON summary (`{ ok, triggered_by, results, errors }`).
|
|
||||||
|
|
||||||
**Config (env, all optional — defaults point at the local mock):**
|
|
||||||
|
|
||||||
| Var | Default | Purpose |
|
|
||||||
|---|---|---|
|
|
||||||
| `PRETIX_BASE_URL` | `http://mock-api:54330` | Pretix API base |
|
|
||||||
| `PRETIX_API_TOKEN` | — | Pretix org/event API token |
|
|
||||||
| `SESSIONIZE_BASE_URL` | `http://mock-api:54330` | Sessionize API base |
|
|
||||||
| `SESSIONIZE_API_KEY` | — | Sessionize API key |
|
|
||||||
| `CRON_SECRET` | — | Shared secret for scheduled triggers |
|
|
||||||
|
|
||||||
> **Local note:** the local edge runtime bundles functions at `supabase start`
|
|
||||||
> time, so after adding/editing a function run `npx supabase stop && npx
|
|
||||||
> supabase start` to register it.
|
|
||||||
|
|
||||||
## The sync RPCs (service-role only)
|
|
||||||
|
|
||||||
Both RPCs are `security definer` and **guarded to the service-role caller**
|
|
||||||
(checked via the JWT `role` claim — `session_user` is the owner inside a definer
|
|
||||||
function). They can write to `auth.users` and bypass RLS, but **only** the Edge
|
|
||||||
Function (which holds the service-role key) can call them. The apps
|
|
||||||
(`anon`/`authenticated`) get `service_role only`.
|
|
||||||
|
|
||||||
### `sync_pretix_attendees(p_attendees jsonb)`
|
|
||||||
|
|
||||||
Input: a JSON array of
|
|
||||||
`{ email, full_name, ticket_type, qr_token?, linkedin_url?, external_id? }`.
|
|
||||||
|
|
||||||
For each item:
|
|
||||||
- **Upsert the contact** by `email` (no token on the contact).
|
|
||||||
- **Map the ticket type** to a registration type via `_map_ticket_type`
|
|
||||||
(case-insensitive substring: `speaker` / `staff` / `sponsor`, else `attendee`).
|
|
||||||
- **Auto-create a sponsor row** if the type is `sponsor` (the sponsor rule
|
|
||||||
requires a sponsor lookup).
|
|
||||||
- **Upsert the registration** for the active event (by contact). The **QR token
|
|
||||||
lives on the registration**: it keeps the existing token unless a new one is
|
|
||||||
supplied (so a re-sync never invalidates a lanyard), and **generates a token**
|
|
||||||
(`CVV-XXX-NNNN`) for new ticket holders (Pretix doesn't always provide one) so
|
|
||||||
they can log in.
|
|
||||||
- **Ensure the auth user** exists and **sync the token as the Auth password**
|
|
||||||
(QR token = password).
|
|
||||||
|
|
||||||
Returns `{ created, updated, skipped, errors[] }`.
|
|
||||||
|
|
||||||
### `sync_sessionize_sessions(p_sessions jsonb)`
|
|
||||||
|
|
||||||
Input: a JSON array of
|
|
||||||
`{ external_id, title, description?, room?, capacity?, date, start_time, end_time,
|
|
||||||
speakers: [{ email, full_name }] }`.
|
|
||||||
|
|
||||||
For each item:
|
|
||||||
- **Find or create the slot** by `(event, date, start, end)` (new slots get an
|
|
||||||
id from the `slots_id_seq` sequence).
|
|
||||||
- **Upsert the session** by `external_id` (partial unique index).
|
|
||||||
- **Link speakers** — upsert each speaker as a contact (+ auth user) and insert
|
|
||||||
into `session_speakers` (idempotent).
|
|
||||||
|
|
||||||
Returns `{ slots_created, sessions_created, sessions_updated, speakers_linked, errors[] }`.
|
|
||||||
|
|
||||||
### Idempotency
|
|
||||||
|
|
||||||
External ids are stored on `contacts.external_id`, `registrations.external_id`,
|
|
||||||
and `sessions.external_id` (each with a partial unique index `WHERE external_id
|
|
||||||
IS NOT NULL`). Re-running a sync **updates in place** instead of duplicating —
|
|
||||||
verified: a second run reports `0 created, N updated`.
|
|
||||||
|
|
||||||
### `sync_runs` (audit)
|
|
||||||
|
|
||||||
Every run inserts a row: `source`, `started_at`, `finished_at`, `created`,
|
|
||||||
`updated`, `skipped`, `error`, `triggered_by`. RLS: **admin-only** read. The
|
|
||||||
Interfaces view shows the last 8 runs.
|
|
||||||
|
|
||||||
## Data mapping
|
|
||||||
|
|
||||||
| Pretix field | → Convivo |
|
|
||||||
|---|---|
|
|
||||||
| `attendee_email` | `contacts.email` (PK) |
|
|
||||||
| `attendee_name` | `contacts.full_name` |
|
|
||||||
| `ticket_type` | `registrations.type` (via `_map_ticket_type`) |
|
|
||||||
| `order_code` | `contacts.external_id` + `registrations.external_id` |
|
|
||||||
| `qr_token` / *(generated)* | `registrations.qr_token` (Pretix per-ticket, or generated for new holders) |
|
|
||||||
|
|
||||||
| Sessionize field | → Convivo |
|
|
||||||
|---|---|
|
|
||||||
| `id` | `sessions.external_id` |
|
|
||||||
| `title` / `description` / `room` / `capacity` | `sessions.*` |
|
|
||||||
| `start_time` / `end_time` (ISO) | slot `slot_date` + `start_time`/`end_time` (slot matched by date+time) |
|
|
||||||
| `speakers[].email` / `name` | `contacts` + `session_speakers` |
|
|
||||||
|
|
||||||
## Testing with the mock API
|
|
||||||
|
|
||||||
The `mock-api` Docker service (`interfaces/mock-api/`) is a dependency-free Node
|
|
||||||
server that serves the real API shapes from `fixtures/`:
|
|
||||||
|
|
||||||
- `GET /pretix/attendees` → 3 ticket holders (2 new emails + 1 existing, to test
|
|
||||||
create vs update).
|
|
||||||
- `GET /sessionize/sessions` → 2 sessions (new ids, new time slots, new +
|
|
||||||
existing speakers).
|
|
||||||
|
|
||||||
**Run it:**
|
|
||||||
```bash
|
|
||||||
docker compose up -d --build mock-api # :54330
|
|
||||||
```
|
|
||||||
|
|
||||||
**Trigger a sync** (as admin, from the APPE Admin **Interfaces** view, or via
|
|
||||||
curl with an admin JWT):
|
|
||||||
```bash
|
|
||||||
# 1. get an admin JWT
|
|
||||||
ADMIN_JWT=$(curl -s -X POST "http://127.0.0.1:54321/auth/v1/token?grant_type=password" \
|
|
||||||
-H "apikey: $ANON" -H "Content-Type: application/json" \
|
|
||||||
-d '{"email":"[email protected]","password":"CVV-ADM-0001"}' | jq -r .access_token)
|
|
||||||
|
|
||||||
# 2. trigger the sync
|
|
||||||
curl -s -X POST "http://127.0.0.1:54321/functions/v1/sync-trigger" \
|
|
||||||
-H "Content-Type: application/json" -H "Authorization: Bearer $ADMIN_JWT" \
|
|
||||||
-d '{"source":"both"}'
|
|
||||||
```
|
|
||||||
|
|
||||||
Expected: new contacts get generated QR tokens (and can log in), types are
|
|
||||||
mapped, sessions/slots/speakers are created, and `sync_runs` records the run.
|
|
||||||
|
|
||||||
## Going live (real Pretix / Sessionize)
|
|
||||||
|
|
||||||
1. Set the real base URLs + tokens as env on the Edge Function
|
|
||||||
(`npx supabase secrets set PRETIX_BASE_URL=... PRETIX_API_TOKEN=...` etc.).
|
|
||||||
2. Adjust the normalizers in `sync-trigger/index.ts` if the real API shapes
|
|
||||||
differ from the mock fixtures (the field mapping is isolated in
|
|
||||||
`fetchPretixAttendees` / `fetchSessionizeSessions`).
|
|
||||||
3. (Optional) schedule a pull with a cron that POSTs to the function with the
|
|
||||||
`x-cron-secret` header.
|
|
||||||
|
|
||||||
## Open questions
|
|
||||||
|
|
||||||
1. **Pretix type mapping** — confirm which ticket types map to
|
|
||||||
speaker/staff/sponsor (the substring matcher is a reasonable default).
|
|
||||||
2. **Sync cadence** — how often to pull (pre-event vs during the event)?
|
|
||||||
3. **Webhooks** — Pretix/Sessionize can push on change; the current design is
|
|
||||||
pull-based (add a webhook endpoint later if real-time is needed).
|
|
||||||
@@ -52,7 +52,6 @@ Source of truth:
|
|||||||
| `feedback` | own **or** admin | — | — | — |
|
| `feedback` | own **or** admin | — | — | — |
|
||||||
| `leaderboard` | all authenticated | — | — | — |
|
| `leaderboard` | all authenticated | — | — | — |
|
||||||
| `points_log` | own **or** admin | — | — | — |
|
| `points_log` | own **or** admin | — | — | — |
|
||||||
| `sync_runs` | admin only | — | — | — |
|
|
||||||
|
|
||||||
**"—" (no policy)** means normal users have **no direct write access** — those
|
**"—" (no policy)** means normal users have **no direct write access** — those
|
||||||
tables are written only by the `security definer` RPCs, which bypass RLS. This is
|
tables are written only by the `security definer` RPCs, which bypass RLS. This is
|
||||||
@@ -120,10 +119,6 @@ create policy "leaderboard_select_all" on public.leaderboard for select to authe
|
|||||||
-- points_log: read own or admin
|
-- points_log: read own or admin
|
||||||
create policy "points_log_select_own_or_admin" on public.points_log for select to authenticated
|
create policy "points_log_select_own_or_admin" on public.points_log for select to authenticated
|
||||||
using (contact_email = public.current_email() or public.is_admin());
|
using (contact_email = public.current_email() or public.is_admin());
|
||||||
|
|
||||||
-- sync_runs: admin only (interface sync audit)
|
|
||||||
create policy "sync_runs_select_admin" on public.sync_runs for select to authenticated
|
|
||||||
using (public.is_admin());
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Storage — `materials` bucket
|
## Storage — `materials` bucket
|
||||||
@@ -158,8 +153,6 @@ grant usage on schema public to anon, authenticated, service_role;
|
|||||||
grant select on <all 14 tables> to anon, authenticated, service_role;
|
grant select on <all 14 tables> to anon, authenticated, service_role;
|
||||||
grant insert, update, delete on <all 14 tables> to authenticated, service_role;
|
grant insert, update, delete on <all 14 tables> to authenticated, service_role;
|
||||||
grant execute on function <all public RPCs + helpers> to authenticated;
|
grant execute on function <all public RPCs + helpers> to authenticated;
|
||||||
grant execute on function sync_pretix_attendees(jsonb), sync_sessionize_sessions(jsonb)
|
|
||||||
to service_role; -- interface sync RPCs are service-role-only
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Note `anon` gets `select` but **no** `insert/update/delete`; `authenticated` gets
|
Note `anon` gets `select` but **no** `insert/update/delete`; `authenticated` gets
|
||||||
|
|||||||
@@ -202,23 +202,6 @@ profile from the Convivo app: the LinkedIn URL and the two visibility toggles
|
|||||||
touch `is_admin`, `password`, `external_id`, etc.
|
touch `is_admin`, `password`, `external_id`, etc.
|
||||||
- Returns the updated contact row.
|
- Returns the updated contact row.
|
||||||
|
|
||||||
## Interface sync RPCs (service-role-only)
|
|
||||||
|
|
||||||
Two additional `security definer` RPCs import external data. They are **not**
|
|
||||||
called by the apps — they are called by the `sync-trigger` Edge Function using the
|
|
||||||
**service-role key**, and each guards with
|
|
||||||
`if coalesce(auth.jwt() ->> 'role', '') <> 'service_role' then raise exception`.
|
|
||||||
Full details (payloads, mapping, the Edge Function, the mock API) live in
|
|
||||||
[interfaces.md](./interfaces.md).
|
|
||||||
|
|
||||||
| Function | Input | Effect |
|
|
||||||
|---|---|---|
|
|
||||||
| `sync_pretix_attendees(p_attendees jsonb)` | array of `{email, full_name, ticket_type, qr_token?, linkedin_url?, external_id?}` | Upserts `contacts` (by email) + `registrations` (by event+contact); creates the `auth.users` row if missing; auto-creates a `sponsors` row for `sponsor` ticket types; records a `sync_runs` row. Returns `{created, updated, skipped, errors[]}`. |
|
|
||||||
| `sync_sessionize_sessions(p_sessions jsonb)` | array of `{external_id, title, description?, room?, capacity?, date, start_time, end_time, speakers[]}` | Find-or-creates a `slots` row per time window, upserts `sessions` by `external_id`, upserts speaker `contacts` + `session_speakers`; records a `sync_runs` row. Returns `{slots_created, sessions_created, sessions_updated, speakers_linked, errors[]}`. |
|
|
||||||
|
|
||||||
Both are **idempotent** — re-running a sync updates existing rows instead of
|
|
||||||
duplicating them (keyed on email / `external_id`).
|
|
||||||
|
|
||||||
## Role helper functions
|
## Role helper functions
|
||||||
|
|
||||||
| Function | Returns | Meaning |
|
| Function | Returns | Meaning |
|
||||||
|
|||||||
+7
-28
@@ -4,11 +4,10 @@ All tables live in the `public` schema. Source of truth:
|
|||||||
[`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
|
[`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
|
||||||
(the Redesign migration, which **replaces** the old `profiles`-based schema).
|
(the Redesign migration, which **replaces** the old `profiles`-based schema).
|
||||||
|
|
||||||
There are **14 tables**: people (`contacts`), the event (`events`), participation
|
There are **13 tables**: people (`contacts`), the event (`events`), participation
|
||||||
(`registrations`, `sponsors`), the schedule (`slots`, `sessions`,
|
(`registrations`, `sponsors`), the schedule (`slots`, `sessions`,
|
||||||
`session_speakers`), the event's activity (`preferences`, `connections`,
|
`session_speakers`), and the event's activity (`preferences`, `connections`,
|
||||||
`checkins`, `feedback`, `leaderboard`, `points_log`), and the interface audit
|
`checkins`, `feedback`, `leaderboard`, `points_log`).
|
||||||
(`sync_runs`).
|
|
||||||
|
|
||||||
The old `profiles` table is **dropped**. People are now `contacts` (keyed by
|
The old `profiles` table is **dropped**. People are now `contacts` (keyed by
|
||||||
email), and every activity table is scoped to an **event** + a **contact email**
|
email), and every activity table is scoped to an **event** + a **contact email**
|
||||||
@@ -45,8 +44,7 @@ erDiagram
|
|||||||
|
|
||||||
One row per person. **`email` is the primary key** (a natural key that matches
|
One row per person. **`email` is the primary key** (a natural key that matches
|
||||||
`auth.users.email`). Contacts carry **no QR token** — the token lives on the
|
`auth.users.email`). Contacts carry **no QR token** — the token lives on the
|
||||||
registration (it is generated per event by Pretix and doubles as the Auth
|
registration (it is generated per event and doubles as the Auth password).
|
||||||
password).
|
|
||||||
|
|
||||||
| Column | Type | Notes |
|
| Column | Type | Notes |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
@@ -57,7 +55,7 @@ password).
|
|||||||
| `show_linkedin` | `boolean` | default `false` — visibility toggle |
|
| `show_linkedin` | `boolean` | default `false` — visibility toggle |
|
||||||
| `is_admin` | `boolean` | default `false` — **staff = admin (merged)**; grants check-in + APPE Admin access |
|
| `is_admin` | `boolean` | default `false` — **staff = admin (merged)**; grants check-in + APPE Admin access |
|
||||||
| `password` | `text` | nullable — the **login password** (event-independent) for admin/staff. Setting it (e.g. in the Supabase Table Editor) **auto-syncs** the bcrypt hash into `auth.users.encrypted_password` via the `trg_contact_password_sync` trigger, so it works with `signInWithPassword` immediately |
|
| `password` | `text` | nullable — the **login password** (event-independent) for admin/staff. Setting it (e.g. in the Supabase Table Editor) **auto-syncs** the bcrypt hash into `auth.users.encrypted_password` via the `trg_contact_password_sync` trigger, so it works with `signInWithPassword` immediately |
|
||||||
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
|
| `external_id` | `text` | nullable — reserved for an external system's id (currently unused) |
|
||||||
| `created_at` | `timestamptz` | |
|
| `created_at` | `timestamptz` | |
|
||||||
|
|
||||||
Partial unique index: `contacts_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
|
Partial unique index: `contacts_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
|
||||||
@@ -98,7 +96,7 @@ Points are scoped **per event** here (one row per contact per event).
|
|||||||
| `checked_in` | `boolean` | default `false` |
|
| `checked_in` | `boolean` | default `false` |
|
||||||
| `points` | `integer` | `>= 0`, default 0 |
|
| `points` | `integer` | `>= 0`, default 0 |
|
||||||
| `qr_token` | `text` | nullable — the lanyard token; **doubles as the Auth password** (generated per event) |
|
| `qr_token` | `text` | nullable — the lanyard token; **doubles as the Auth password** (generated per event) |
|
||||||
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
|
| `external_id` | `text` | nullable — reserved for an external system's id (currently unused) |
|
||||||
| `created_at` | `timestamptz` | |
|
| `created_at` | `timestamptz` | |
|
||||||
|
|
||||||
**Constraint:** `unique (event_id, contact_email)` — one registration per contact
|
**Constraint:** `unique (event_id, contact_email)` — one registration per contact
|
||||||
@@ -155,7 +153,7 @@ Unpaid sponsors are hidden from non-admins (RLS).
|
|||||||
| `average_feedback` | `numeric` | maintained by `submit_feedback` |
|
| `average_feedback` | `numeric` | maintained by `submit_feedback` |
|
||||||
| `ai_generated_feedback` | `text` | AI-feedback state (stub) |
|
| `ai_generated_feedback` | `text` | AI-feedback state (stub) |
|
||||||
| `material_path` | `text` | nullable — storage object path for session material |
|
| `material_path` | `text` | nullable — storage object path for session material |
|
||||||
| `external_id` | `text` | nullable — the Sessionize session id (set by the sync) |
|
| `external_id` | `text` | nullable — reserved for an external system's id (currently unused) |
|
||||||
| `created_at` | `timestamptz` | |
|
| `created_at` | `timestamptz` | |
|
||||||
|
|
||||||
> **Speakers are no longer a `text` column** — they live in the `session_speakers`
|
> **Speakers are no longer a `text` column** — they live in the `session_speakers`
|
||||||
@@ -274,25 +272,6 @@ Powers the per-category points breakdown on the Profile screen (per event).
|
|||||||
|
|
||||||
Index: `points_log_event_id_idx (event_id)`.
|
Index: `points_log_event_id_idx (event_id)`.
|
||||||
|
|
||||||
## `sync_runs` — interface sync audit
|
|
||||||
|
|
||||||
One row per Pretix/Sessionize sync run, written by the service-role-only sync
|
|
||||||
RPCs (see [interfaces.md](./interfaces.md)).
|
|
||||||
|
|
||||||
| Column | Type | Notes |
|
|
||||||
|---|---|---|
|
|
||||||
| `id` | `uuid` PK | `gen_random_uuid()` |
|
|
||||||
| `source` | `text` | `pretix` \| `sessionize` |
|
|
||||||
| `started_at` | `timestamptz` | |
|
|
||||||
| `finished_at` | `timestamptz` | nullable |
|
|
||||||
| `created` | `integer` | rows created |
|
|
||||||
| `updated` | `integer` | rows updated |
|
|
||||||
| `skipped` | `integer` | rows skipped |
|
|
||||||
| `error` | `text` | nullable — top-level error, if any |
|
|
||||||
| `triggered_by` | `text` | default `service_role` |
|
|
||||||
|
|
||||||
Index: `sync_runs_source_idx (source)`. RLS: admin-only `select`.
|
|
||||||
|
|
||||||
## Other indexes
|
## Other indexes
|
||||||
|
|
||||||
- `slots_event_id_idx (event_id)`, `registrations_event_id_idx (event_id)`,
|
- `slots_event_id_idx (event_id)`, `registrations_event_id_idx (event_id)`,
|
||||||
|
|||||||
+10
-29
@@ -20,7 +20,6 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
|
|||||||
| **Schedule** | Slots (with type) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
|
| **Schedule** | Slots (with type) + sessions (with speakers 1:N via a **multi-select search dropdown**, material upload with a **submitted / not submitted** state, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
|
||||||
| **Activity** | Tables of check-ins, connections, and feedback (per active event). |
|
| **Activity** | Tables of check-ins, connections, and feedback (per active event). |
|
||||||
| **Events** | Create event, set active (only one), edit dates/location. |
|
| **Events** | Create event, set active (only one), edit dates/location. |
|
||||||
| **Interfaces** | Trigger **Pretix** and **Sessionize** syncs (per-source or "Sync all"), show the result counts, list recent sync runs, and **export the QR CSV** (name/email/type/qr_token for the active event). |
|
|
||||||
|
|
||||||
## Auth guard
|
## Auth guard
|
||||||
|
|
||||||
@@ -63,8 +62,7 @@ apps/admin/src/
|
|||||||
├─ Sponsors.tsx # sponsor CRUD
|
├─ Sponsors.tsx # sponsor CRUD
|
||||||
├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate
|
├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate
|
||||||
├─ Activity.tsx # check-ins / connections / feedback tables
|
├─ Activity.tsx # check-ins / connections / feedback tables
|
||||||
├─ Events.tsx # event management
|
└─ Events.tsx # event management
|
||||||
└─ Sync.tsx # Interfaces: Pretix/Sessionize sync + QR CSV export
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Data access
|
## Data access
|
||||||
@@ -82,25 +80,27 @@ key. Everything it can do is allowed by RLS:
|
|||||||
- **RPCs** — `adjust_points` (manual, audited as `admin`), `upsert_contact`,
|
- **RPCs** — `adjust_points` (manual, audited as `admin`), `upsert_contact`,
|
||||||
`create_registration`, `set_registration_type`, `evaluate_session_feedback`
|
`create_registration`, `set_registration_type`, `evaluate_session_feedback`
|
||||||
(AI stub), and `set_session_material` (attach uploaded material). The
|
(AI stub), and `set_session_material` (attach uploaded material). The
|
||||||
`reset_registration_qr_token` RPC still exists (used by the sync path) but the
|
`reset_registration_qr_token` RPC still exists but the admin UI no longer
|
||||||
admin UI no longer exposes a token reset. See
|
exposes a token reset. See
|
||||||
[../backend/rpcs.md](../backend/rpcs.md).
|
[../backend/rpcs.md](../backend/rpcs.md).
|
||||||
|
|
||||||
### Viewing a QR token
|
### Viewing a QR token
|
||||||
|
|
||||||
The QR token lives on the **registration** (per event), not the contact. The
|
The QR token lives on the **registration** (per event), not the contact. The
|
||||||
**Registrations** view shows each registration's token and a **QR** button that
|
**Registrations** view shows each registration's token and a **QR** button that
|
||||||
opens a modal with the scannable code. The token is **final** — it is generated by
|
opens a modal with the scannable code. The token is **final** — it is generated
|
||||||
Pretix and can't be reset from the UI (the `reset_registration_qr_token` RPC still
|
per event and can't be reset from the UI (the `reset_registration_qr_token` RPC
|
||||||
exists for the sync path, but the admin UI no longer exposes a reset action).
|
still exists, but the admin UI no longer exposes a reset action).
|
||||||
|
|
||||||
### Sponsor lookup (in-place)
|
### Sponsor lookup (in-place)
|
||||||
|
|
||||||
Setting a registration's type to **Sponsor** requires a sponsor lookup. If none
|
Setting a registration's type to **Sponsor** requires a sponsor lookup. If none
|
||||||
exists for that contact, the change fails with `a sponsor registration requires a
|
exists for that contact, the change fails with `a sponsor registration requires a
|
||||||
sponsor lookup` and the UI opens an **in-place sponsor popup** (instead of just
|
sponsor lookup` and the UI opens an **in-place sponsor popup** (instead of just
|
||||||
erroring). The popup lets the admin create the sponsor (type, name, email, phone,
|
erroring). The popup lets the admin either **link an existing sponsor** (a
|
||||||
amount, paid) linked to that contact, then sets the registration type to
|
dropdown lists the event's sponsors; picking one pre-fills the form) or **create
|
||||||
|
a new one** (type, name, email, phone, amount, paid). On save it upserts the
|
||||||
|
sponsor linked to that contact's email, then sets the registration type to
|
||||||
`sponsor` in one step.
|
`sponsor` in one step.
|
||||||
|
|
||||||
### Adjusting points
|
### Adjusting points
|
||||||
@@ -116,25 +116,6 @@ The Schedule view uploads a session's material to the `materials` bucket and set
|
|||||||
button calls `evaluate_session_feedback` (the AI stub) to set
|
button calls `evaluate_session_feedback` (the AI stub) to set
|
||||||
`ai_generated_feedback`.
|
`ai_generated_feedback`.
|
||||||
|
|
||||||
### Interfaces (Pretix + Sessionize sync)
|
|
||||||
|
|
||||||
The **Interfaces** view is the admin's control panel for the data interfaces
|
|
||||||
(Phases 7–8). It does **not** call the sync RPCs directly — those are
|
|
||||||
`service_role`-only. Instead it POSTs to the **`sync-trigger` Edge Function**
|
|
||||||
(`/functions/v1/sync-trigger`) with the admin's session JWT; the function verifies
|
|
||||||
the caller is an admin (via the `is_admin()` RPC), fetches from the configured
|
|
||||||
Pretix/Sessionize base URLs (the local **mock API** by default), and calls the
|
|
||||||
service-role RPCs `sync_pretix_attendees` / `sync_sessionize_sessions`.
|
|
||||||
|
|
||||||
- **Sync now / Sync all** — trigger one source or both; the response shows
|
|
||||||
`created` / `updated` / `skipped` counts (and any per-item errors).
|
|
||||||
- **Recent sync runs** — the last 8 rows of `sync_runs` (admin-only read).
|
|
||||||
- **Export QR CSV** — builds a CSV of the active event's registrations
|
|
||||||
(name, email, type, qr_token) and triggers a browser download, so organizers can
|
|
||||||
print lanyards without touching the database.
|
|
||||||
|
|
||||||
Full details: [../backend/interfaces.md](../backend/interfaces.md).
|
|
||||||
|
|
||||||
## Styling
|
## Styling
|
||||||
|
|
||||||
The admin app reuses the attendee app's **design tokens** (colors, Poppins font,
|
The admin app reuses the attendee app's **design tokens** (colors, Poppins font,
|
||||||
|
|||||||
+32
-54
@@ -4,7 +4,7 @@ What's done, what's next, and the open decisions. The full roadmap lives in the
|
|||||||
root [`roadmap.md`](../roadmap.md); this file is the working detail for the
|
root [`roadmap.md`](../roadmap.md); this file is the working detail for the
|
||||||
current phase.
|
current phase.
|
||||||
|
|
||||||
> **Current state:** Phases 0–8 are complete and verified, plus five polish
|
> **Current state:** Phases 0–6 are complete and verified, plus six polish
|
||||||
> rounds: **Fixes & Refinements** (QR token moved to the registration, role-pill
|
> rounds: **Fixes & Refinements** (QR token moved to the registration, role-pill
|
||||||
> capitalization, connection detail sheet + red-dot recalc, admin schedule
|
> capitalization, connection detail sheet + red-dot recalc, admin schedule
|
||||||
> speaker multi-select + upload/speaker bug fixes, sponsor contact search),
|
> speaker multi-select + upload/speaker bug fixes, sponsor contact search),
|
||||||
@@ -13,14 +13,17 @@ current phase.
|
|||||||
> password sync** (setting `contacts.password` auto-syncs the Auth password;
|
> password sync** (setting `contacts.password` auto-syncs the Auth password;
|
||||||
> staff excluded from the leaderboard; Home/Agenda/Profile identical for all
|
> staff excluded from the leaderboard; Home/Agenda/Profile identical for all
|
||||||
> roles), **Convivo staff QR login** (a staff QR asks for the staff password, not
|
> roles), **Convivo staff QR login** (a staff QR asks for the staff password, not
|
||||||
> an email), and **Registration optionset + speaker promote + welcome check-in**
|
> an email), **Registration optionset + speaker promote + welcome check-in**
|
||||||
> (`registrations.type` is now a Postgres enum; adding a speaker auto-promotes
|
> (`registrations.type` is now a Postgres enum; adding a speaker auto-promotes
|
||||||
> their registration to `speaker`; staff can do a Welcome check-in that marks an
|
> their registration to `speaker`; staff can do a Welcome check-in that marks an
|
||||||
> attendee present at the event; the admin QR token is final (no reset) and a
|
> attendee present at the event; the admin QR token is final (no reset) and a
|
||||||
> failed sponsor change opens an in-place sponsor lookup; speakers see a red
|
> failed sponsor change opens an in-place sponsor lookup; speakers see a red
|
||||||
> pending-material pill on Home and can delete their material to re-upload).
|
> pending-material pill on Home and can delete their material to re-upload), and
|
||||||
> Remaining work is cross-cutting (real event clock, deployment, testing) and
|
> **Existing-sponsor link + Interfaces removal** (the in-place sponsor lookup can
|
||||||
> the open questions in [backend/interfaces.md](./backend/interfaces.md).
|
> now link an existing sponsor, not just create one; the Pretix/Sessionize
|
||||||
|
> "Interfaces" feature — admin view, `sync-trigger` Edge Function, mock API, and
|
||||||
|
> the `sync_runs` table + sync RPCs — is removed).
|
||||||
|
> Remaining work is cross-cutting (real event clock, deployment, testing).
|
||||||
|
|
||||||
## Done
|
## Done
|
||||||
|
|
||||||
@@ -152,45 +155,31 @@ rebuilt the views on the new model:
|
|||||||
- `https://www.appe.at/assets/appe_full.png` as favicon + PWA icon (192/512)
|
- `https://www.appe.at/assets/appe_full.png` as favicon + PWA icon (192/512)
|
||||||
for **both** apps. Updated `index.html` + `manifest.webmanifest` + `public/`.
|
for **both** apps. Updated `index.html` + `manifest.webmanifest` + `public/`.
|
||||||
|
|
||||||
## The Interfaces (Phases 7–8) — ✅ complete
|
## Existing-sponsor link + Interfaces removal — ✅ complete
|
||||||
|
|
||||||
Both external interfaces are built and browser-verified end-to-end (against the
|
A polish round (migration `20260830000000_remove_interfaces.sql` + app changes),
|
||||||
local mock API). Full detail: [backend/interfaces.md](./backend/interfaces.md).
|
all browser-verified.
|
||||||
|
|
||||||
### Phase 7 — Pretix interface ✅
|
**In-place sponsor lookup can link an existing sponsor.**
|
||||||
Sync **tickets → contacts + registrations** from [Pretix](https://pretix.eu).
|
- The sponsor lookup popup (opened when a registration is set to `sponsor` with
|
||||||
|
no sponsor yet) now lists the event's existing sponsors in a dropdown. Picking
|
||||||
|
one pre-fills the form (type, name, email, phone, amount, paid) and the save
|
||||||
|
button reads **Link sponsor & set type**; leaving it on **— Create new —**
|
||||||
|
keeps the original create flow. On save it upserts the sponsor linked to the
|
||||||
|
contact's email, then sets the registration type to `sponsor`.
|
||||||
|
|
||||||
- **`sync-trigger` Edge Function** pulls `GET /pretix/attendees`, normalizes, and
|
**The Pretix/Sessionize "Interfaces" feature is removed.**
|
||||||
calls the service-role-only `sync_pretix_attendees(jsonb)` RPC.
|
- **Admin UI** — the **Interfaces** nav button + `Sync.tsx` view are gone; the
|
||||||
- **Upserts** `contacts` (by email) + `registrations` (by event + contact) +
|
sync API helpers (`triggerSync`, `getSyncRuns`, `exportQrCsv`, `SyncResult`)
|
||||||
`auth.users` (QR token = password). **Generates a QR token** for new ticket
|
and the `SyncRun` type are removed from the admin client.
|
||||||
holders so they can log in.
|
- **Edge Function** — `supabase/functions/sync-trigger/` is deleted.
|
||||||
- **Type mapping** — `_map_ticket_type` maps the Pretix ticket type to
|
- **Mock API** — `interfaces/mock-api/` and its `docker-compose.yml` service are
|
||||||
`attendee` / `speaker` / `staff` / `sponsor` (substring match; sponsor
|
deleted.
|
||||||
auto-creates a sponsor row).
|
- **DB** — migration `20260830000000_remove_interfaces.sql` drops the
|
||||||
- **Idempotent** — keyed on `external_id` (Pretix order code) + email; re-runs
|
`sync_pretix_attendees` / `sync_sessionize_sessions` RPCs, the
|
||||||
update in place.
|
`_ensure_auth_user` / `_map_ticket_type` helpers, and the `sync_runs` table.
|
||||||
- **QR export** — the APPE Admin **Interfaces** view exports a CSV of lanyard QR
|
The `external_id` columns are kept (harmless, nullable, reserved for a future
|
||||||
codes for the active event.
|
external system).
|
||||||
|
|
||||||
### Phase 8 — Sessionize interface ✅
|
|
||||||
Sync the **real agenda** (slots, sessions, speakers, rooms) from
|
|
||||||
[Sessionize](https://sessionize.com).
|
|
||||||
|
|
||||||
- The same Edge Function pulls `GET /sessionize/sessions` and calls the
|
|
||||||
service-role-only `sync_sessionize_sessions(jsonb)` RPC.
|
|
||||||
- **Slots** are matched/created by `(event, date, start, end)`; **sessions** are
|
|
||||||
upserted by `external_id` (Sessionize id); **speakers** are upserted as
|
|
||||||
contacts + `session_speakers` links.
|
|
||||||
- **Idempotent** — keyed on `external_id`; re-runs update in place.
|
|
||||||
|
|
||||||
### Shared plumbing (both phases)
|
|
||||||
- **`sync_runs`** audit table (admin-only read) records every run; the
|
|
||||||
Interfaces view shows the last 8.
|
|
||||||
- **`mock-api`** Docker service (`interfaces/mock-api/`, :54330) serves the real
|
|
||||||
API shapes from fixtures so the pipeline is testable without credentials.
|
|
||||||
- **Auth** — the Edge Function accepts an admin JWT (verified via `is_admin()`)
|
|
||||||
or a `CRON_SECRET` header for scheduled runs.
|
|
||||||
|
|
||||||
## Fixes & Refinements — ✅ complete
|
## Fixes & Refinements — ✅ complete
|
||||||
|
|
||||||
@@ -336,7 +325,7 @@ Migration `20260829000000_registration_type_optionset_speaker_promote_welcome_ch
|
|||||||
`checkin_attendee`) and **Welcome check-in** (`welcome_checkin`).
|
`checkin_attendee`) and **Welcome check-in** (`welcome_checkin`).
|
||||||
|
|
||||||
**Admin Registrations: final QR token + in-place sponsor lookup.**
|
**Admin Registrations: final QR token + in-place sponsor lookup.**
|
||||||
- The **Reset token** button is gone — the token is final (generated by Pretix).
|
- The **Reset token** button is gone — the token is final (generated per event).
|
||||||
The QR modal now says "This token is final…".
|
The QR modal now says "This token is final…".
|
||||||
- Setting a type to **Sponsor** when no sponsor lookup exists opens an
|
- Setting a type to **Sponsor** when no sponsor lookup exists opens an
|
||||||
**in-place sponsor popup** (create the sponsor linked to the contact, then set
|
**in-place sponsor popup** (create the sponsor linked to the contact, then set
|
||||||
@@ -374,19 +363,8 @@ Migration `20260829000000_registration_type_optionset_speaker_promote_welcome_ch
|
|||||||
|
|
||||||
## Open decisions (need user input)
|
## Open decisions (need user input)
|
||||||
|
|
||||||
**Resolved in Phases 7–8:**
|
|
||||||
- **Sync runtime** — Supabase **Edge Function** (`sync-trigger`), not a separate
|
|
||||||
container. Keeps the "no custom backend" philosophy.
|
|
||||||
- **Sync style** — **pull** (on-demand from the APPE Admin Interfaces view +
|
|
||||||
cron-ready via `CRON_SECRET`). Webhooks are a later add-on.
|
|
||||||
- **Credentials** — env-configured (`PRETIX_*` / `SESSIONIZE_*`), with a local
|
|
||||||
**mock API** for testing. Real tokens are set as Edge Function secrets.
|
|
||||||
|
|
||||||
**Still open:**
|
**Still open:**
|
||||||
1. **Pretix type mapping** — confirm the ticket-type → registration-type mapping
|
1. **AI provider** — which LLM/API for `ai_generated_feedback` (the admin
|
||||||
(the substring matcher is a reasonable default).
|
|
||||||
2. **Sync cadence** — how often to pull (pre-event vs during the event)?
|
|
||||||
3. **AI provider** — which LLM/API for `ai_generated_feedback` (the admin
|
|
||||||
"Evaluate" button is still a stub).
|
"Evaluate" button is still a stub).
|
||||||
4. **Deployment target** — stay on localhost, or plan for the `appe.at`
|
4. **Deployment target** — stay on localhost, or plan for the `appe.at`
|
||||||
subdomains now?
|
subdomains now?
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
# Convivo — mock Pretix/Sessionize API (Phase 7 + 8).
|
|
||||||
# Dependency-free Node server; no build step needed.
|
|
||||||
FROM node:20-alpine
|
|
||||||
WORKDIR /app
|
|
||||||
COPY package.json server.js ./
|
|
||||||
COPY fixtures ./fixtures
|
|
||||||
EXPOSE 54330
|
|
||||||
CMD ["node", "server.js"]
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
{
|
|
||||||
"results": [
|
|
||||||
{
|
|
||||||
"order_code": "PX-NEW-001",
|
|
||||||
"attendee_name": "New Attendee One",
|
|
||||||
"attendee_email": "[email protected]",
|
|
||||||
"ticket_type": "Regular",
|
|
||||||
"qr_token": "CVV-PX1-1001"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"order_code": "PX-NEW-002",
|
|
||||||
"attendee_name": "New Speaker Two",
|
|
||||||
"attendee_email": "[email protected]",
|
|
||||||
"ticket_type": "Speaker",
|
|
||||||
"qr_token": "CVV-PX2-1002"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"order_code": "PX-ANA-003",
|
|
||||||
"attendee_name": "Ana Silva",
|
|
||||||
"attendee_email": "[email protected]",
|
|
||||||
"ticket_type": "Regular",
|
|
||||||
"qr_token": "CVV-ANA-4821"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"sessions": [
|
|
||||||
{
|
|
||||||
"id": "ses-900",
|
|
||||||
"title": "Lightning Talks (Synced)",
|
|
||||||
"description": "A batch of short talks, synced from Sessionize.",
|
|
||||||
"room": "Main Hall",
|
|
||||||
"capacity": 200,
|
|
||||||
"start_time": "2026-10-23T16:00:00Z",
|
|
||||||
"end_time": "2026-10-23T16:45:00Z",
|
|
||||||
"speakers": [
|
|
||||||
{ "id": "spk-1", "name": "New Speaker Two", "email": "[email protected]" },
|
|
||||||
{ "id": "spk-2", "name": "Dr. Elena Vasquez", "email": "[email protected]" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "ses-901",
|
|
||||||
"title": "Panel: The Future of APPE",
|
|
||||||
"description": "A panel discussion, synced from Sessionize.",
|
|
||||||
"room": "Room B",
|
|
||||||
"capacity": 120,
|
|
||||||
"start_time": "2026-10-23T17:00:00Z",
|
|
||||||
"end_time": "2026-10-23T17:45:00Z",
|
|
||||||
"speakers": [
|
|
||||||
{ "id": "spk-3", "name": "Bruno Costa", "email": "[email protected]" }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "convivo-mock-api",
|
|
||||||
"version": "0.1.0",
|
|
||||||
"private": true,
|
|
||||||
"type": "module",
|
|
||||||
"description": "Mock Pretix + Sessionize API server for testing the Convivo sync interfaces (Phase 7 + 8).",
|
|
||||||
"scripts": {
|
|
||||||
"start": "node server.js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
// Convivo — Mock Pretix + Sessionize API server (Phase 7 + 8).
|
|
||||||
//
|
|
||||||
// A tiny, dependency-free Node HTTP server that serves the SAME response shapes
|
|
||||||
// as the real Pretix and Sessionize APIs, so the `sync-trigger` Edge Function
|
|
||||||
// can be tested end-to-end WITHOUT real credentials. Point the Edge Function at
|
|
||||||
// this server (PRETIX_BASE_URL / SESSIONIZE_BASE_URL) to run a full sync.
|
|
||||||
//
|
|
||||||
// Endpoints:
|
|
||||||
// GET /health → { ok: true }
|
|
||||||
// GET /pretix/attendees → Pretix order-positions shape (fixtures/pretix.json)
|
|
||||||
// GET /sessionize/sessions → Sessionize sessions shape (fixtures/sessionize.json)
|
|
||||||
//
|
|
||||||
// Run locally: node server.js (listens on :54330)
|
|
||||||
// In Docker: the `mock-api` service in docker-compose.yml.
|
|
||||||
|
|
||||||
import http from 'node:http';
|
|
||||||
import { readFile } from 'node:fs/promises';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
import { dirname, join } from 'node:path';
|
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
||||||
const PORT = Number(process.env.PORT || 54330);
|
|
||||||
|
|
||||||
const ROUTES = {
|
|
||||||
'/pretix/attendees': join(__dirname, 'fixtures', 'pretix.json'),
|
|
||||||
'/sessionize/sessions': join(__dirname, 'fixtures', 'sessionize.json'),
|
|
||||||
};
|
|
||||||
|
|
||||||
const server = http.createServer(async (req, res) => {
|
|
||||||
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
||||||
const path = url.pathname.replace(/\/+$/, '') || '/';
|
|
||||||
|
|
||||||
const send = (status, body, type = 'application/json') => {
|
|
||||||
res.writeHead(status, { 'Content-Type': type, 'Access-Control-Allow-Origin': '*' });
|
|
||||||
res.end(body);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.writeHead(204, {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'Authorization, Content-Type',
|
|
||||||
'Access-Control-Allow-Methods': 'GET, OPTIONS',
|
|
||||||
});
|
|
||||||
res.end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path === '/health') {
|
|
||||||
send(200, JSON.stringify({ ok: true, service: 'convivo-mock-api' }));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const file = ROUTES[path];
|
|
||||||
if (!file) {
|
|
||||||
send(404, JSON.stringify({ error: 'not found', path }));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const raw = await readFile(file, 'utf8');
|
|
||||||
send(200, raw);
|
|
||||||
} catch (err) {
|
|
||||||
send(500, JSON.stringify({ error: String(err) }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
server.listen(PORT, () => {
|
|
||||||
console.log(`[mock-api] listening on :${PORT}`);
|
|
||||||
console.log(`[mock-api] GET /pretix/attendees`);
|
|
||||||
console.log(`[mock-api] GET /sessionize/sessions`);
|
|
||||||
});
|
|
||||||
+5
-39
@@ -3,10 +3,9 @@
|
|||||||
Living roadmap. The top section is the **current focus**; completed phases are
|
Living roadmap. The top section is the **current focus**; completed phases are
|
||||||
summarized below. For *how* each piece works, see [`docs/`](./docs/README.md).
|
summarized below. For *how* each piece works, see [`docs/`](./docs/README.md).
|
||||||
|
|
||||||
> **Status:** Phases 0–8 are complete and verified. The **Redesign** (Phases
|
> **Status:** Phases 0–6 are complete and verified. The **Redesign** (Phases
|
||||||
> 3–6) is done, and the **Pretix + Sessionize interfaces** (Phases 7–8) are
|
> 3–6) is done. Remaining work is cross-cutting (real event clock, deployment,
|
||||||
> built and browser-verified end-to-end (against the local mock API). Remaining
|
> automated testing).
|
||||||
> work is cross-cutting (real event clock, deployment, automated testing).
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -38,33 +37,6 @@ Convivo App gains several behaviors. Details live in
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## The Interfaces (Phases 7–8) ✅ DONE
|
|
||||||
|
|
||||||
Pull **real** data from the systems that run a conference. Full detail in
|
|
||||||
[`docs/backend/interfaces.md`](./docs/backend/interfaces.md).
|
|
||||||
|
|
||||||
| Phase | Scope | Status |
|
|
||||||
|---|---|---|
|
|
||||||
| **7** | **Pretix interface** — `sync-trigger` Edge Function pulls tickets → `contacts` + `registrations` (+ auth users, generated QR tokens, type mapping, idempotent by `external_id`); QR CSV export in APPE Admin | ✅ |
|
|
||||||
| **8** | **Sessionize interface** — same Edge Function pulls the agenda → `slots` + `sessions` + `session_speakers` (idempotent by `external_id`) | ✅ |
|
|
||||||
|
|
||||||
### Interface decisions (locked)
|
|
||||||
- **Runtime** — a Supabase **Edge Function** (`sync-trigger`), not a separate
|
|
||||||
container. It's the only component that talks to the external APIs and holds
|
|
||||||
the service-role key.
|
|
||||||
- **Style** — **pull** (on-demand from the APPE Admin **Interfaces** view +
|
|
||||||
cron-ready via `CRON_SECRET`). Webhooks are a later add-on.
|
|
||||||
- **Service-role-only RPCs** — `sync_pretix_attendees` / `sync_sessionize_sessions`
|
|
||||||
are guarded to the service-role caller (JWT `role` claim); the apps cannot
|
|
||||||
call them.
|
|
||||||
- **Idempotency** — `external_id` columns (partial unique indexes) on
|
|
||||||
contacts / registrations / sessions; re-runs update in place.
|
|
||||||
- **Audit** — a `sync_runs` table (admin-only read) records every run.
|
|
||||||
- **Local testing** — a `mock-api` Docker service serves the real API shapes
|
|
||||||
from fixtures, so the pipeline is testable without credentials.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Completed
|
## Completed
|
||||||
|
|
||||||
| Phase | Scope | Status |
|
| Phase | Scope | Status |
|
||||||
@@ -93,13 +65,7 @@ Pull **real** data from the systems that run a conference. Full detail in
|
|||||||
|
|
||||||
## Open questions
|
## Open questions
|
||||||
|
|
||||||
**Resolved in Phases 7–8:** sync runtime (Edge Function), sync style (pull +
|
1. **AI provider** — which LLM/API for `ai_generated_feedback` (the admin
|
||||||
cron-ready), credentials (env-configured + local mock API).
|
|
||||||
|
|
||||||
1. **Pretix mapping** — confirm the ticket-type → registration-type mapping
|
|
||||||
(the substring matcher is a reasonable default).
|
|
||||||
2. **Sync cadence** — how often to pull (pre-event vs during the event)?
|
|
||||||
3. **AI provider** — which LLM/API for `ai_generated_feedback` (the admin
|
|
||||||
"Evaluate" button is still a stub).
|
"Evaluate" button is still a stub).
|
||||||
4. **Deployment target** — stay on localhost, or plan for the `appe.at`
|
2. **Deployment target** — stay on localhost, or plan for the `appe.at`
|
||||||
subdomains now?
|
subdomains now?
|
||||||
@@ -1,197 +0,0 @@
|
|||||||
// Convivo — sync-trigger Edge Function (Phase 7 + 8).
|
|
||||||
//
|
|
||||||
// Pulls real data from Pretix (tickets) and Sessionize (agenda) and pushes it
|
|
||||||
// into the multi-event model via the service-role-only sync RPCs
|
|
||||||
// (`sync_pretix_attendees`, `sync_sessionize_sessions`).
|
|
||||||
//
|
|
||||||
// Trigger:
|
|
||||||
// POST / { "source": "pretix" | "sessionize" | "both" }
|
|
||||||
//
|
|
||||||
// Auth (either):
|
|
||||||
// * A valid **admin** JWT in the `Authorization` header (the APPE Admin app
|
|
||||||
// calls this from its Sync view). Verified by calling the `is_admin()` RPC.
|
|
||||||
// * A matching `x-cron-secret` header == CRON_SECRET (for scheduled runs).
|
|
||||||
//
|
|
||||||
// Config (env, all optional — defaults point at the local mock API):
|
|
||||||
// PRETIX_BASE_URL (default http://mock-api:54330)
|
|
||||||
// PRETIX_API_TOKEN (Pretix org/event API token)
|
|
||||||
// SESSIONIZE_BASE_URL (default http://mock-api:54330)
|
|
||||||
// SESSIONIZE_API_KEY (Sessionize API key)
|
|
||||||
// CRON_SECRET (shared secret for scheduled triggers)
|
|
||||||
//
|
|
||||||
// No npm dependencies — uses the global `fetch` + `Deno.serve`.
|
|
||||||
|
|
||||||
const SUPABASE_URL = Deno.env.get('SUPABASE_URL') ?? 'http://kong:8000';
|
|
||||||
const SERVICE_ROLE_KEY = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') ?? '';
|
|
||||||
const PRETIX_BASE_URL = (Deno.env.get('PRETIX_BASE_URL') ?? 'http://mock-api:54330').replace(/\/+$/, '');
|
|
||||||
const PRETIX_API_TOKEN = Deno.env.get('PRETIX_API_TOKEN') ?? '';
|
|
||||||
const SESSIONIZE_BASE_URL = (Deno.env.get('SESSIONIZE_BASE_URL') ?? 'http://mock-api:54330').replace(/\/+$/, '');
|
|
||||||
const SESSIONIZE_API_KEY = Deno.env.get('SESSIONIZE_API_KEY') ?? '';
|
|
||||||
const CRON_SECRET = Deno.env.get('CRON_SECRET') ?? '';
|
|
||||||
|
|
||||||
type Source = 'pretix' | 'sessionize' | 'both';
|
|
||||||
|
|
||||||
function json(status: number, body: unknown): Response {
|
|
||||||
return new Response(JSON.stringify(body), {
|
|
||||||
status,
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the caller is an admin by calling the is_admin() RPC with their JWT.
|
|
||||||
async function isAdmin(authorization: string | null): Promise<boolean> {
|
|
||||||
if (!authorization) return false;
|
|
||||||
const res = await fetch(`${SUPABASE_URL}/rest/v1/rpc/is_admin`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
apikey: SERVICE_ROLE_KEY,
|
|
||||||
Authorization: authorization,
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: '{}',
|
|
||||||
});
|
|
||||||
if (!res.ok) return false;
|
|
||||||
return (await res.json()) === true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call a service-role sync RPC via PostgREST.
|
|
||||||
async function callSyncRpc(fn: string, argName: string, payload: unknown): Promise<unknown> {
|
|
||||||
const res = await fetch(`${SUPABASE_URL}/rest/v1/rpc/${fn}`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
apikey: SERVICE_ROLE_KEY,
|
|
||||||
Authorization: `Bearer ${SERVICE_ROLE_KEY}`,
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ [argName]: payload }),
|
|
||||||
});
|
|
||||||
const text = await res.text();
|
|
||||||
if (!res.ok) {
|
|
||||||
throw new Error(`${fn} failed (${res.status}): ${text}`);
|
|
||||||
}
|
|
||||||
return JSON.parse(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Pretix: fetch + normalize ---------------------------------------------
|
|
||||||
|
|
||||||
async function fetchPretixAttendees(): Promise<Record<string, unknown>[]> {
|
|
||||||
const res = await fetch(`${PRETIX_BASE_URL}/pretix/attendees`, {
|
|
||||||
headers: PRETIX_API_TOKEN ? { Authorization: `Bearer ${PRETIX_API_TOKEN}` } : {},
|
|
||||||
});
|
|
||||||
if (!res.ok) throw new Error(`Pretix fetch failed (${res.status})`);
|
|
||||||
const data = (await res.json()) as { results?: PretixOrder[] };
|
|
||||||
const results = data.results ?? [];
|
|
||||||
return results.map((a) => ({
|
|
||||||
email: a.attendee_email,
|
|
||||||
full_name: a.attendee_name,
|
|
||||||
ticket_type: a.ticket_type,
|
|
||||||
external_id: a.order_code,
|
|
||||||
// Pretix generates a QR token per ticket; it becomes the registration's
|
|
||||||
// token (and the login password).
|
|
||||||
qr_token: a.qr_token ?? null,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PretixOrder {
|
|
||||||
order_code: string;
|
|
||||||
attendee_name: string;
|
|
||||||
attendee_email: string;
|
|
||||||
ticket_type: string;
|
|
||||||
qr_token?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Sessionize: fetch + normalize -----------------------------------------
|
|
||||||
|
|
||||||
async function fetchSessionizeSessions(): Promise<Record<string, unknown>[]> {
|
|
||||||
const res = await fetch(`${SESSIONIZE_BASE_URL}/sessionize/sessions`, {
|
|
||||||
headers: SESSIONIZE_API_KEY ? { 'X-Api-Key': SESSIONIZE_API_KEY } : {},
|
|
||||||
});
|
|
||||||
if (!res.ok) throw new Error(`Sessionize fetch failed (${res.status})`);
|
|
||||||
const data = (await res.json()) as { sessions?: SessionizeSession[] };
|
|
||||||
const sessions = data.sessions ?? [];
|
|
||||||
return sessions.map((s) => ({
|
|
||||||
external_id: s.id,
|
|
||||||
title: s.title,
|
|
||||||
description: s.description ?? null,
|
|
||||||
room: s.room ?? null,
|
|
||||||
capacity: s.capacity ?? null,
|
|
||||||
date: s.start_time.slice(0, 10),
|
|
||||||
start_time: s.start_time.slice(11, 16),
|
|
||||||
end_time: s.end_time.slice(11, 16),
|
|
||||||
speakers: (s.speakers ?? []).map((sp) => ({ email: sp.email, full_name: sp.name })),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SessionizeSession {
|
|
||||||
id: string;
|
|
||||||
title: string;
|
|
||||||
description?: string;
|
|
||||||
room?: string;
|
|
||||||
capacity?: number;
|
|
||||||
start_time: string; // ISO 8601
|
|
||||||
end_time: string; // ISO 8601
|
|
||||||
speakers?: { id: string; name: string; email: string }[];
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- Handler ---------------------------------------------------------------
|
|
||||||
|
|
||||||
Deno.serve(async (req: Request) => {
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
return new Response(null, {
|
|
||||||
status: 204,
|
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Allow-Headers': 'Authorization, Content-Type, x-cron-secret',
|
|
||||||
'Access-Control-Allow-Methods': 'POST, OPTIONS',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (req.method !== 'POST') {
|
|
||||||
return json(405, { error: 'method not allowed; use POST' });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Auth: admin JWT or cron secret.
|
|
||||||
const authorization = req.headers.get('Authorization');
|
|
||||||
const cronSecret = req.headers.get('x-cron-secret');
|
|
||||||
const isCron = CRON_SECRET !== '' && cronSecret === CRON_SECRET;
|
|
||||||
if (!isCron) {
|
|
||||||
const admin = await isAdmin(authorization);
|
|
||||||
if (!admin) return json(401, { error: 'admin or cron secret required' });
|
|
||||||
}
|
|
||||||
|
|
||||||
let source: Source = 'both';
|
|
||||||
try {
|
|
||||||
const body = await req.json();
|
|
||||||
if (body && typeof body.source === 'string') source = body.source as Source;
|
|
||||||
} catch {
|
|
||||||
// no body → default to 'both'
|
|
||||||
}
|
|
||||||
|
|
||||||
const results: Record<string, unknown> = {};
|
|
||||||
const errors: string[] = [];
|
|
||||||
|
|
||||||
if (source === 'pretix' || source === 'both') {
|
|
||||||
try {
|
|
||||||
const attendees = await fetchPretixAttendees();
|
|
||||||
results.pretix = await callSyncRpc('sync_pretix_attendees', 'p_attendees', attendees);
|
|
||||||
} catch (e) {
|
|
||||||
errors.push(`pretix: ${(e as Error).message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (source === 'sessionize' || source === 'both') {
|
|
||||||
try {
|
|
||||||
const sessions = await fetchSessionizeSessions();
|
|
||||||
results.sessionize = await callSyncRpc('sync_sessionize_sessions', 'p_sessions', sessions);
|
|
||||||
} catch (e) {
|
|
||||||
errors.push(`sessionize: ${(e as Error).message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return json(errors.length > 0 ? 207 : 200, {
|
|
||||||
ok: errors.length === 0,
|
|
||||||
triggered_by: isCron ? 'cron' : 'admin',
|
|
||||||
results,
|
|
||||||
errors,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
-- =============================================================================
|
||||||
|
-- Convivo — remove the Pretix/Sessionize "Interfaces" feature
|
||||||
|
--
|
||||||
|
-- The Interfaces feature (Phases 7 + 8) is being removed: the APPE Admin
|
||||||
|
-- "Interfaces" view, the `sync-trigger` Edge Function, the local mock API, and
|
||||||
|
-- the supporting DB objects. This migration drops the DB side:
|
||||||
|
--
|
||||||
|
-- * `sync_pretix_attendees(jsonb)` — service-role sync RPC (Pretix tickets)
|
||||||
|
-- * `sync_sessionize_sessions(jsonb)` — service-role sync RPC (Sessionize agenda)
|
||||||
|
-- * `_ensure_auth_user(text,text,text)` — helper used only by the sync RPCs
|
||||||
|
-- * `_map_ticket_type(text)` — helper used only by the sync RPCs
|
||||||
|
-- * `sync_runs` table (+ index, RLS policies) — sync audit trail
|
||||||
|
--
|
||||||
|
-- The `external_id` columns added by the interfaces migration are left in place
|
||||||
|
-- (they are harmless, nullable, and part of the base table definitions).
|
||||||
|
-- =============================================================================
|
||||||
|
|
||||||
|
-- Drop the sync RPCs first (they reference the helpers + sync_runs).
|
||||||
|
drop function if exists public.sync_pretix_attendees(jsonb);
|
||||||
|
drop function if exists public.sync_sessionize_sessions(jsonb);
|
||||||
|
|
||||||
|
-- Drop the sync-only helper functions.
|
||||||
|
drop function if exists public._ensure_auth_user(text, text, text);
|
||||||
|
drop function if exists public._map_ticket_type(text);
|
||||||
|
|
||||||
|
-- Drop the audit table (cascades to its index + RLS policies).
|
||||||
|
drop table if exists public.sync_runs;
|
||||||
Reference in new issue
Block a user