feat: add sidecar service for Sessionize sync

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

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-08-24 20:47:29 +02:00
1 parent a0bcf866dc
commit 5f8ded56f6
31 files changed
+2729 -390

No files matched your search

+1
View File
@@ -12,6 +12,7 @@ Postgres. This folder documents that core.
| [rls.md](./rls.md) | Row Level Security policies + which key the app uses |
| [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) |
| [sidecar.md](./sidecar.md) | The Sessionize sync sidecar (on-demand, service-role) |
## The big picture
+22 -7
View File
@@ -4,10 +4,13 @@ Docker is the backbone. Two pieces:
1. **The Supabase core** — a set of containers managed by the **Supabase CLI**
(not by a compose file in this repo). See [supabase-core.md](./supabase-core.md).
2. **The app sidecars** — two containers, the attendee app
([`apps/convivo/Dockerfile`](../../apps/convivo/Dockerfile), `:3000`) and the
2. **The app sidecars** — the attendee app
([`apps/convivo/Dockerfile`](../../apps/convivo/Dockerfile), `:3000`), the
admin console ([`apps/admin/Dockerfile`](../../apps/admin/Dockerfile), `:3001`),
and the **Sessionize sync sidecar**
([`apps/sidecar/Dockerfile`](../../apps/sidecar/Dockerfile), `:3002`),
orchestrated by the root [`docker-compose.yml`](../../docker-compose.yml).
The sidecar is documented in [sidecar.md](./sidecar.md).
Each app container **joins the network the CLI created** for the core and proxies
the Supabase same-origin paths to the Kong container. Both use the identical
@@ -24,10 +27,13 @@ flowchart LR
K["supabase_kong_Convivo<br/>:8000 (internal)"]
APP["convivo-app<br/>nginx :3000"]
ADM["convivo-admin<br/>nginx :3001"]
SC["convivo-sidecar<br/>node :3002"]
end
CLI -.creates.-> Net
APP -->|"proxy /auth /rest /realtime /storage"| K
ADM -->|"proxy /auth /rest /realtime /storage"| K
ADM -->|"proxy /sidecar/*"| SC
SC -->|"service-role key"| K
APP -->|"host port 3000"| U["Browser"]
ADM -->|"host port 3001"| U
```
@@ -67,9 +73,10 @@ same-origin paths to the core:
## Root `docker-compose.yml`
Runs **only the apps** (the core is CLI-managed). There are two services —
`convivo-app` (`:3000`) and `convivo-admin` (`:3001`) — with identical settings
except the build context and port:
Runs **only the apps** (the core is CLI-managed). There are three services —
`convivo-app` (`:3000`), `convivo-admin` (`:3001`), and `convivo-sidecar`
(`:3002`). The two nginx apps have identical settings except the build context
and port:
| Setting | `convivo-app` | `convivo-admin` | Why |
|---|---|---|---|
@@ -79,6 +86,12 @@ except the build context and port:
| `networks.supabase` | **external**, name `supabase_network_Convivo` | same | Joins the CLI-created network |
| `healthcheck` | `wget http://127.0.0.1:3000/` | `wget http://127.0.0.1:3001/` | Container reports healthy |
The **`convivo-sidecar`** service is different: it builds
[`apps/sidecar`](../../apps/sidecar) (a plain Node service, no nginx), exposes
`:3002`, and carries the sidecar env vars (`SUPABASE_URL`,
`SUPABASE_SERVICE_ROLE_KEY`, `SESSIONIZE_API_KEY`). It is the first server-side
holder of the service-role key. See [sidecar.md](./sidecar.md).
> If you change `project_id` in `supabase/config.toml`, update the external
> network name (`supabase_network_<project_id>`) and the default proxy target
> (`supabase_kong_<project_id>:8000`) to match.
@@ -92,7 +105,7 @@ npm run db:start
# 2. (Optional) reset to clean seed data
npm run db:reset
# 3. Build + run both app sidecars (:3000 + :3001)
# 3. Build + run the app sidecars (:3000 + :3001) and the sync sidecar (:3002)
docker compose up --build
```
@@ -101,12 +114,14 @@ Open **http://localhost:3000** (attendee) and **http://localhost:3001** (admin).
### Alternative: dev server (no app container)
For faster iteration you can skip the app containers and use the Vite dev
servers, which proxy the same paths to `127.0.0.1:54321` (host port):
servers, which proxy the same paths to `127.0.0.1:54321` (host port). The admin
dev server also proxies `/sidecar` to `127.0.0.1:3002`, so start the sidecar too:
```bash
npm run db:start
npm run app:dev # attendee Vite on :3000
npm run admin:dev # admin Vite on :3001
npm run sidecar:dev # sync sidecar on :3002
```
## Verified behavior
+48
View File
@@ -202,6 +202,54 @@ profile from the Convivo app: the LinkedIn URL and the two visibility toggles
touch `is_admin`, `password`, `external_id`, etc.
- Returns the updated contact row.
### `sync_sessionize_event(p_event_id, p_payload)` → `jsonb`
**Service-role only** (the Sessionize sync sidecar — see [sidecar.md](./sidecar.md)).
Imports an event's Sessionize data in order: (1) speakers → contacts (matched by
email), (2) sessions (upserted by `external_id`), (3) the agenda (slots
find-or-created by date/start/end + `session_speakers` links). `p_payload` is
`{ speakers: [{email, full_name, external_id?}], sessions: [{external_id, title,
description?, room?, date, start_time, end_time, speakers: [email,...]}] }`.
- Guarded to the `service_role` caller (JWT role claim); granted to `service_role`
only — the apps cannot call it.
- **Idempotent:** re-running updates in place (contacts by email, sessions by
`external_id`, slots by date/start/end). Speaker links are **diffed** (insert the
new set, then delete only removed) so the `session_needs_speaker` trigger never
blocks a removal.
- Linking a speaker fires `session_speakers_speaker_promote`, which promotes an
existing registration to `speaker`. **No registrations are created** — the ticket
sync does that (checking `session_speakers` by email).
- Per-item failures are collected into `errors[]` (the run does not abort). Returns
a JSONB summary (`speakers_created/updated`, `sessions_created/updated`,
`slots_created`, `speakers_linked`, `errors`) and stamps `events.last_synced_at`.
- Writes a `sync_runs` audit row (see [schema.md](./schema.md)).
### `sync_sessionize_excel(p_event_id, p_payload)` → `jsonb`
**Service-role only** (the Sessionize sync sidecar's **Excel import** path — see
[sidecar.md](./sidecar.md)). Imports the Sessionize **"Sessions and speakers
(advanced)"** `.xlsx` export (parsed by the sidecar, which carries the speaker
**emails** the public API lacks). Same shape as `sync_sessionize_event` plus
`is_service_session` per session and `linkedin_url` per speaker, and it runs one
extra step:
1. **Speakers → contacts** (matched by email; also sets `linkedin_url`).
2. **Sessions + agenda** — slots are typed from `is_service_session`
(`service_session` for breaks/lunch/closing, else `session`), sessions
upserted by `external_id`, speaker links diffed.
3. **Speaker registrations** — for every speaker, creates a `speaker`
registration or updates an existing `attendee` one to `speaker`
(`on conflict (event_id, contact_email)`). **Never overrides `staff` /
`sponsor`** tickets. This is the "add the missing registrations for the
speakers" step the API sync deliberately leaves to the ticket sync.
- Guarded to the `service_role` caller; granted to `service_role` only.
- **Idempotent:** re-running updates in place (contacts by email, sessions by
`external_id`, slots by date/start/end, registrations by event+contact).
- Per-item failures are collected into `errors[]`. Returns a JSONB summary
(`speakers_created/updated`, `sessions_created/updated`, `slots_created`,
`speakers_linked`, `registrations_created/updated`, `errors`) and stamps
`events.last_synced_at`.
- Writes a `sync_runs` audit row with `source = 'sessionize_excel'`.
## Role helper functions
| Function | Returns | Meaning |
+32 -4
View File
@@ -77,6 +77,8 @@ queries everything for the active event and handles "no active event" gracefully
| `num_speakers` | `integer` | maintained aggregate |
| `num_registrations` | `integer` | maintained aggregate |
| `num_checked_in_registrations` | `integer` | maintained aggregate |
| `sessionize_endpoint` | `text` | nullable — the Sessionize API URL for this event (see [sidecar.md](./sidecar.md)) |
| `last_synced_at` | `timestamptz` | nullable — when the Sessionize sync last ran |
| `created_at` | `timestamptz` | |
**Constraint:** `unique index events_one_active on (is_active) where is_active`
@@ -132,13 +134,20 @@ Unpaid sponsors are hidden from non-admins (RLS).
| Column | Type | Notes |
|---|---|---|
| `id` | `integer` PK | 1–6 |
| `id` | `integer` PK | `nextval('slots_id_seq')` default — the UI/sidecar can create a slot **without** supplying an id (the seed inserts explicit ids and re-syncs the sequence) |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `type` | `text` | `session` \| `lunch_break` \| `coffee_break` \| `keynote` \| `close_up` (default `session`) |
| `name` | `text` | e.g. "Slot 1" |
| `slot_date` | `date` | `2026-10-23` |
| `type` | `slot_type` (enum) | **`session` \| `service_session`** (default `session`) — a true optionset, not freetext. `service_session` = breaks / lunch / closing (Sessionize's `isServiceSession`) |
| `name` | `text` | e.g. "Slot 09:00–09:45" / "Service Session" |
| `slot_date` | `date` | |
| `start_time` / `end_time` | `time` | |
> **`type` is a Postgres ENUM** (`public.slot_type`, added by
> [`20260832000000_slots_enum_excel_import.sql`](../../supabase/migrations/20260832000000_slots_enum_excel_import.sql)).
> The old freetext values (`keynote` / `lunch_break` / `coffee_break` /
> `close_up`) were all folded into `service_session` — they are all non-talk
> agenda items. The admin Schedule view shows the two values as **Session** /
> **Service Session**.
## `sessions` — one per (slot, room)
| Column | Type | Notes |
@@ -272,6 +281,25 @@ Powers the per-category points breakdown on the Profile screen (per event).
Index: `points_log_event_id_idx (event_id)`.
## `sync_runs` — Sessionize sync audit trail
Event-scoped record of every sidecar sync run (the data behind the admin
Interfaces view's "recent runs").
| Column | Type | Notes |
|---|---|---|
| `id` | `uuid` PK | `gen_random_uuid()` |
| `event_id` | `uuid` FK → `events` | `on delete cascade` |
| `source` | `text` | `sessionize` (API sync) \| `sessionize_excel` (Excel import) |
| `started_at` / `finished_at` | `timestamptz` | `finished_at` nullable |
| `created` / `updated` / `skipped` | `integer` | counts from the run |
| `error` | `text` | nullable — error text if the run failed |
| `triggered_by` | `text` | default `service_role` |
**RLS:** enabled; `SELECT` for `authenticated` restricted to admins
(`sync_runs_select_admin`). Written only by the `sync_sessionize_event` /
`sync_sessionize_excel` RPCs.
## Other indexes
- `slots_event_id_idx (event_id)`, `registrations_event_id_idx (event_id)`,
+72 -98
View File
@@ -1,23 +1,37 @@
# Seed Data & Demo Accounts
Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs on
`npm run db:reset` and is **idempotent** (`on conflict ... do nothing`).
`npm run db:reset` and is **idempotent** (`on conflict ... do nothing` /
`do update`).
The seed uses **real data** from a past event — the **Global Power Platform
Bootcamp (Austria)** — instead of random demo data:
- The **agenda** (slots + sessions) comes from the event's Sessionize public API
(`…/api/v2/4domszaq/view/All`): 22 sessions on 2026-02-20 (18 talks + 4 service
sessions: coffee break, lunch, a partner session, and the closing).
- The **speakers** are **not** seeded — they are imported from the Sessionize
**"Sessions and speakers (advanced)"** `.xlsx` via the admin **Interfaces →
Import Excel** control (see [sidecar.md](./sidecar.md)). That import creates the
speaker contacts, links them to sessions, and creates their `speaker`
registrations (matched by email).
## What it creates
| Data | Count | Notes |
|---|---|---|
| `auth.users` + `auth.identities` | 13 | 12 attendees + 1 admin; **QR token = bcrypt password** (attendees/staff) — the admin uses a real **password** instead |
| `contacts` | 14 | 13 registrants + 1 external keynote speaker (no token — tokens live on registrations) |
| `events` | 1 | **APPE 2026**, 2026-10-23, São Paulo, Brazil, **active** |
| `registrations` | 13 | one per contact (Elena has none); points + **QR token** scoped here |
| `sponsors` | 3 | Nubank (headline, paid), Acme Corp (gold, paid), Globant (community, unpaid) |
| `slots` | 6 | 23 Oct, 09:00–15:45 (see table below) |
| `sessions` | 18 | 3 per slot (Main Stage / Room A / Room B) |
| `session_speakers` | 22 | M:N session → contact |
| `leaderboard` | 10 | mirrored from `registrations`, **staff excluded** (13 registrants − 3 staff) |
| `points_log` | 16 | Ana's coherent breakdown + one `admin` entry per other user |
| Ana's demo state | — | 6 preferences, 2 check-ins, 4 connections, 1 feedback |
| `auth.users` + `auth.identities` | 54 | 50 attendees + 4 staff; **QR token = bcrypt password** (attendees), **`appe-admin-2026`** (staff) |
| `contacts` | 54 | 50 attendees + 4 staff (`is_admin = true`, `password = 'appe-admin-2026'`) |
| `events` | 1 | **Global Power Platform Bootcamp \| Austrian Power Platform Enthusiasts Edition**, 2026-02-20, Vienna, Austria, **active**, `sessionize_endpoint` set to `https://sessionize.com/api/v2/4domszaq/view/All` |
| `registrations` | 54 | 50 `attendee` + 4 `staff`; each with a `CVV-XXX-NNNN` QR token |
| `slots` | 10 | 2026-02-20, 09:15–17:00 (7 `session` + 3 `service_session`) |
| `sessions` | 22 | real titles/descriptions/rooms from the Sessionize API |
| `session_speakers` | 0 | **added by the Excel import** (not seeded) |
| `sponsors` | 0 | none for this event |
> **Speaker contacts are intentionally absent.** After `db:reset`, run the Excel
> import (Interfaces → Import Excel → choose the `.xlsx` → Import) to add the 21
> speakers: their contacts, session links, and `speaker` registrations.
> **GoTrue gotcha:** manually-inserted `auth.users` must have
> `confirmation_token`, `recovery_token`, `email_change_token_new`, and
@@ -25,101 +39,61 @@ Source of truth: [`supabase/seed.sql`](../../supabase/seed.sql). The seed runs o
> grant can't scan a NULL `confirmation_token`. `phone` is left NULL (unique
> constraint).
> **Staff = admin (merged).** Bruno, Rita, and the APPE Admin have
> `is_admin = true` on their `contacts` row. Their registration `type` is
> `staff` (the ticket type shown on the lanyard).
> **Staff = admin (merged).** The four staff have `is_admin = true` on their
> `contacts` row (so they can open the APPE Admin console **and** generate the
> Sessionize export) and their registration `type` is `staff`.
## Slots
## Slots (2026-02-20)
| id | Type | Time |
|---|---|---|
| 1 | keynote | 09:00–09:45 |
| 2 | session | 10:00–10:45 |
| 3 | session | 11:30–12:15 |
| 4 | lunch_break | 13:15–14:00 |
| 5 | session | 14:00–14:45 |
| 6 | close_up | 15:00–15:45 |
| Type | Time |
|---|---|
| session | 09:15–10:00 (keynote) |
| service_session | 10:00–10:30 (coffee break) |
| session | 10:30–11:15 |
| session | 11:15–12:00 |
| service_session | 12:00–13:00 (lunch) |
| session | 13:00–13:45 |
| session | 13:45–14:30 |
| session | 14:30–15:15 |
| session | 15:15–16:00 |
| service_session | 16:00–17:00 (partner session + closing) |
> `type` is the `slot_type` **enum** (`session` / `service_session`) — see
> [schema.md](./schema.md#slots--schedule-blocks).
## Demo accounts
**Attendees** log in with **QR code** (typed or scanned) + **email** — the QR
token is the Auth password. **Staff** log in with **QR code + their staff
password** (the Convivo app shows a password field when a staff QR is detected;
the email comes from the resolved contact). The **APPE Admin** (and any staff
member you give one) can also log in with **email + password** in the admin app
(event-independent, so it works for any event). The password lives in
`contacts.password`; a trigger (`trg_contact_password_sync`) **auto-syncs** it as
the bcrypt hash in `auth.users.encrypted_password`, so just set
`contacts.password` in Supabase and it works with `signInWithPassword`
immediately.
password** in the Convivo app, or **email + password** in the admin app. All four
staff share the password **`appe-admin-2026`** (stored in `contacts.password`,
auto-synced to `auth.users.encrypted_password` by the `trg_contact_password_sync`
trigger).
| Person | Type | Login | Email | Start pts |
|---|---|---|---|---|
| **Ana Silva** | speaker | QR `CVV-ANA-4821` | ana.silva@nubank.com | 40 |
| **Bruno Costa** | staff (admin) | QR `CVV-BRU-1177` + **password** `appe-admin-2026` | bruno.costa@acme.com | 140 |
| **Rita Lopes** | staff (admin) | QR `CVV-RIT-9034` + **password** `appe-admin-2026` | rita.lopes@globant.com | 95 |
| **APPE Admin** | staff (admin) | **password** `appe-admin-2026` | admin@appe.at | 0 |
| Tomás Ribeiro | speaker | `CVV-TOM-5566` | tomas.ribeiro@dataprev.com | 88 |
| Sofia Almeida | speaker | `CVV-SOF-2299` | sofia.almeida@loop.com | 76 |
| Marco Chen | speaker | `CVV-MRC-7712` | marco.chen@deepmind.com | 70 |
| Julia Santos | speaker | `CVV-JUL-3345` | julia.santos@ifood.com | 64 |
| Pedro Nunes | speaker | `CVV-PED-8801` | pedro.nunes@microsoft.com | 58 |
| Carla Mendes | speaker | `CVV-CAR-6623` | carla.mendes@quintoessencial.com | 52 |
| Diego Ferreira | speaker | `CVV-DIE-4458` | diego.ferreira@stone.com | 35 |
| Marina Costa | speaker | `CVV-MNA-2210` | marina.costa@olx.com | 28 |
| Lucas Oliveira | speaker | `CVV-LUC-9987` | lucas.oliveira@usp.br | 15 |
| Dr. Elena Vasquez | (external speaker) | — | elena.vasquez@keynote.com | — |
| Person | Type | Email | Login |
|---|---|---|---|
| **Amelia Hernandez** | staff (admin) | amelia@appe.at | `appe-admin-2026` |
| **Sabrina Hota** | staff (admin) | sabrina@appe.at | `appe-admin-2026` |
| **Jose Lago** | staff (admin) | jose@appe.at | `appe-admin-2026` |
| **Markus Franz** | staff (admin) | markus@appe.at | `appe-admin-2026` |
| 50 attendees | attendee | (made-up, e.g. lena.huber@gmail.com) | QR `CVV-ATT-1000`…`CVV-ATT-1049` |
> **Speaker auto-promote:** every seeded attendee who speaks in a session is
> typed `speaker` (the `session_speakers_speaker_promote` trigger promotes
> `attendee` → `speaker` on insert, so the seed states the final type). Only
> Bruno, Rita, and the APPE Admin are `staff` (the trigger never overrides an
> explicit staff/sponsor ticket).
>
> **Staff passwords:** Bruno and Rita have `contacts.password = 'appe-admin-2026'`
> so the Convivo **staff QR login** (QR + staff password) works out of the box.
> **Dr. Elena Vasquez** is an external keynote speaker: she has a `contacts` row
> (and speaks in `session_speakers`) but **no registration, no QR token, and no
> auth user**, so she can't log in — she only appears as a speaker on the agenda.
## Ana's demo state (so the app looks alive on first login)
Ana (`[email protected]`) is seeded with a coherent 40-point history:
- **Points breakdown** (`points_log`): 2× check-in (+10 each), 2× connection
(+5 each), 1× feedback (+10) = **40**.
- **Preferences** — one pick per slot (matches the mockup):
- Slot 1 → *Designing for Trust in AI Products*
- Slot 2 → *AI in Practice: Lessons from Production*
- Slot 3 → *Data Storytelling*
- Slot 4 → *Prototyping with AI*
- Slot 5 → *Community-Led Growth*
- Slot 6 → *Closing Panel: What's Next*
- **Check-ins** — checked into Slot 1 and Slot 2 (by staff Bruno).
- **Connections**:
- accepted with **Bruno** and **Rita**
- incoming (pending) from **Sofia**
- outgoing (pending) to **Julia**
- **Feedback** — rated Slot 1's *Designing for Trust in AI Products* 5★ with a
comment.
- **Speaker** — Ana is a speaker of Slot 6's *Open Space: Your Ideas* (so the
Agenda shows a "🎤 you" tag and the material-upload notice).
> Everyone else gets a single `admin` `points_log` entry for their starting points
> (so the Profile breakdown shows "Other"), and no other activity.
> **Speaker auto-promote:** the Excel import creates the speakers' registrations
> as `speaker` directly (and the `session_speakers_speaker_promote` trigger
> promotes any `attendee` that gets linked). The seed itself contains **no
> speakers** — only the 50 attendees and 4 staff.
## Suggested demo flow
1. Log in as **Ana** (attendee) → Home, Agenda, Leaderboard all populated.
2. Scan **Marco** (`CVV-MRC-7712`) → send a connection request.
3. Log in as **Bruno** (staff) → QR `CVV-BRU-1177` + staff password
`appe-admin-2026` → the Scan tab becomes **Check-in** → pick a session → scan
**Carla** (`CVV-CAR-6623`) → she gets +10. Flip the **check-in type toggle**
to **Welcome check-in** and scan **Tomás** (`CVV-TOM-5566`) → he's marked
present at the event (no points).
4. Watch the **Leaderboard** update live (Realtime).
5. Log in as **APPE Admin** (`[email protected]` / password `appe-admin-2026`) in the
admin app → Dashboard, Contacts, Registrations, Sponsors, Schedule, Activity,
Events. (Staff Bruno/Rita can also open the admin app with their email + QR
token, since that is their Auth password.)
1. Log in as **Amelia** (staff/admin) in the admin app (`[email protected]` /
`appe-admin-2026`) → Dashboard shows the real event (54 registrations, 22
sessions).
2. **Interfaces → Import Excel** → choose the "Sessions and speakers
(advanced)" `.xlsx` → **Import** → the result modal shows the speakers
created, sessions updated, speaker links, and speaker registrations created.
3. **Schedule** → slots now show **Session** / **Service Session** types and the
sessions list their speakers.
4. **Events** → the event's **Sessionize endpoint** is set; the **Sync** button
runs the (keyless) API sync.
5. Log in as an **attendee** in the Convivo app (QR `CVV-ATT-1000` +
`[email protected]`) → Home/Agenda show the real agenda.
+128
View File
@@ -0,0 +1,128 @@
# Sidecar — Sessionize sync
The **sidecar** is a small Node HTTP service that syncs an event's agenda from
[Sessionize](https://sessionize.com) into Convivo. It is the only server-side
component that holds the **service-role key**, and it is driven entirely by the
APPE Admin **Interfaces** menu — it runs **on demand only** (no scheduling).
- Code: [`apps/sidecar/`](../../apps/sidecar/) (single file:
[`src/server.js`](../../apps/sidecar/src/server.js))
- Image: [`apps/sidecar/Dockerfile`](../../apps/sidecar/Dockerfile)
(`node:20-alpine`; one runtime dependency, **`xlsx`**, to parse the Sessionize
Excel export — everything else is built-in `http` + `fetch`)
- Compose service: `convivo-sidecar` in the root
[`docker-compose.yml`](../../docker-compose.yml) (`:3002`)
- DB side: the `sync_sessionize_event` RPC + `sync_runs` audit table — see
[rpcs.md](./rpcs.md) and [schema.md](./schema.md)
## What it does
There are **two import paths**, both on demand:
**A. API sync** (`POST /run`) — fetches the event's `sessionize_endpoint` and
imports, in order: (1) speakers as contacts (matched by **email**), (2) sessions
(upserted by `external_id`), (3) the agenda/schedule (slots find-or-created by
date/start/end + `session_speakers` links). The public `/view/` payload has no
speaker emails, so this path imports sessions + agenda but **skips speakers**
(unless an authenticated `/api/` endpoint + key is configured).
**B. Excel import** (`POST /import-excel`) — the admin uploads the Sessionize
**"Sessions and speakers (advanced)"** `.xlsx` export (generated on the fly by
any organizer with admin access to the event). The sidecar parses it (two sheets:
*Accepted sessions* + *Accepted speakers*) and calls the
`sync_sessionize_excel` RPC, which imports, in order: (1) speakers as contacts
(matched by **email** — the Excel carries emails, so this is reliable), (2)
sessions + agenda (slots typed `session` / `service_session` from
`isServiceSession` + `session_speakers` links), and (3) **a `speaker`
registration for every speaker** (create, or update `attendee`→`speaker`; never
overrides `staff`/`sponsor`). This is the path that creates the missing speaker
contacts + registrations.
Linking a speaker to a session fires the `session_speakers_speaker_promote`
trigger, which promotes an existing registration to `speaker`.
## How it reaches things
```mermaid
flowchart LR
ADM["convivo-admin<br/>nginx :3001"] -->|"/sidecar/*"| SC["convivo-sidecar<br/>node :3002"]
SC -->|"service-role key"| K["supabase_kong_Convivo<br/>:8000 (PostgREST)"]
SC -->|"GET (key optional)"| SZ["Sessionize /view/ or /api/"]
K --> PG["Postgres 17"]
```
- **Supabase:** PostgREST at `supabase_kong_Convivo:8000` (Kong's internal port
on the shared network — see [supabase-core.md#ports](./supabase-core.md#ports)),
authenticated with the **service-role key**.
- **Sessionize:** the event's stored `sessionize_endpoint`, fetched **as-is**.
The public `/view/` endpoint needs no key. If `SESSIONIZE_API_KEY` is set it
is sent as the `X-Sessionize-API-Key` header (harmless for `/view/`, required
for an `/api/` endpoint).
> **Key is optional.** The public `/view/` endpoint (the one stored on the
> event) returns sessions, speakers, and rooms **without** speaker email
> addresses. Email is the matching key, so a keyless sync imports sessions +
> agenda but **skips speakers** (reported in `skipped_speakers`). To import
> speakers by email, set `SESSIONIZE_API_KEY` and point the event at the
> authenticated `/api/` endpoint, which returns `email` on each speaker.
## HTTP API
| Method | Path | Body | Returns |
|---|---|---|---|
| `GET` | `/health` | — | `{ ok: true }` (compose healthcheck) |
| `GET` | `/status` | — | `{ ok, running, lastRun }` |
| `POST` | `/run` | `{ event_id }` | **blocking** — the API-sync result (summary + errors) |
| `POST` | `/import-excel` | `multipart/form-data` (`event_id` + `file` = the `.xlsx`) | **blocking** — the Excel-import result (summary + errors) |
`/run` is **blocking**: it reads the event's endpoint, fetches Sessionize,
transforms, calls the RPC, and returns the summary. The admin's "Sync" button and
the Interfaces "Run sync" both call it and show the result inline.
`/import-excel` is **blocking** too: it reads the uploaded `.xlsx` (parsed with
`xlsx`), transforms the two sheets into the `sync_sessionize_excel` payload, and
calls that RPC. The admin's Interfaces **"Import Excel"** control posts the file
here and shows the result inline.
## Env vars
| Var | Default | Notes |
|---|---|---|
| `SUPABASE_URL` | `http://supabase_kong_Convivo:8000` | Where PostgREST lives |
| `SUPABASE_SERVICE_ROLE_KEY` | standard local service-role JWT | **First server-side holder** of this key (bypasses RLS). Override for a real deployment. |
| `SESSIONIZE_API_KEY` | *(empty)* | **Optional.** Only needed if the endpoint is an authenticated `/api/` URL. Sent as `X-Sessionize-API-Key` when set. |
| `PORT` | `3002` | |
> **Secrets convention:** the anon key ships in the apps (public by design); the
> service-role key is **never in the app** and stays server-side. The sidecar is
> the first consumer of that rule — it holds the key in a container env var,
> defaulting to the standard local key (overridable), mirroring how the anon key
> is defaulted inline in compose. See [rls.md](./rls.md).
## Running
```bash
# With the rest of the stack (recommended)
docker compose up --build # brings up convivo-sidecar on :3002
# Or just the sidecar, against a running core
npm run sidecar:dev # node apps/sidecar/src/server.js (SUPABASE_URL -> 127.0.0.1:54321)
```
The admin app reaches the sidecar through the same-origin `/sidecar/` proxy
(nginx in Docker, Vite in dev) — see [docker.md](./docker.md).
## Verified behavior
- `GET /health` → `{ ok: true }` (direct `:3002` and via `:3001/sidecar/health`).
- `POST /run` against a public `/view/` endpoint (no key) → fetches, transforms,
calls the RPC, and writes sessions/slots (speakers skipped — no emails in the
public payload — reported in `skipped_speakers`).
- `POST /run` with `SESSIONIZE_API_KEY` set + an `/api/` endpoint → speakers
imported by email.
- `POST /run` with a reachable Sessionize endpoint → fetches, transforms, calls
the RPC, and writes contacts/sessions/slots/links (idempotent on re-run).
- `POST /import-excel` with the real "Sessions and speakers (advanced)" export →
creates the speaker contacts, links them to sessions, and creates/updates their
`speaker` registrations (idempotent on re-run). Verified: 21 speakers created,
25 speaker links, 21 speaker registrations, 0 errors.
+1 -1
View File
@@ -85,7 +85,7 @@ npx supabase status
| Key | Value | Where it's used |
|---|---|---|
| **Anon key** | standard local anon JWT (see `apps/convivo/.env.example`) | **Ships in the app** (public by design) |
| **Service-role key** | standard local service-role JWT | **Never in the app** — server-side only (used for admin ops / verification) |
| **Service-role key** | standard local service-role JWT | **Never in the app** — server-side only. The **sidecar** is its first consumer (see [sidecar.md](./sidecar.md)). |
The app's security model (anon key + session JWT + RLS) is documented in
[rls.md](./rls.md).