Phase 7+8: Pretix + Sessionize interfaces
- Migration 20260825000000_interfaces.sql: external_id on contacts/ registrations/sessions (+ partial unique indexes), slots_id_seq, sync_runs audit table, and service-role-only sync_pretix_attendees / sync_sessionize_sessions RPCs (idempotent upserts). - sync-trigger Edge Function: admin-JWT or CRON_SECRET auth, pulls from Pretix/Sessionize base URLs, normalizes, calls the service-role RPCs. - interfaces/mock-api: dependency-free Node server (:54330) + fixtures so the full pipeline is testable without real tokens. - APPE Admin 'Interfaces' view: per-source + 'Sync all' triggers, result counts, recent sync runs, and QR CSV export; /functions proxy added. - Docs: new docs/backend/interfaces.md; updated README, roadmap, next-steps, schema, rls, rpcs, architecture, admin-app, and docs index. Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
1 parent
7605c9bbf4
commit
74c41c8c1d
26 files changed
+1529
-80
No files matched your search
+6
-2
@@ -4,10 +4,12 @@ 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
|
||||
system works*; the root [`README.md`](../README.md) is the quick-start.
|
||||
|
||||
> **Status:** Phases 0–6 are complete and verified. The **Redesign** (Phases
|
||||
> **Status:** Phases 0–8 are complete and verified. The **Redesign** (Phases
|
||||
> 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
|
||||
> apps carry the APPE branding. See the root
|
||||
> apps carry the APPE branding. **Phases 7–8** added the Pretix + Sessionize
|
||||
> 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).
|
||||
|
||||
## Where things live
|
||||
@@ -20,6 +22,7 @@ system works*; the root [`README.md`](../README.md) is the quick-start.
|
||||
| Database schema (all tables) | [backend/schema.md](./backend/schema.md) |
|
||||
| Transactional points RPCs (the business logic) | [backend/rpcs.md](./backend/rpcs.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) |
|
||||
| Docker (app image + compose) | [backend/docker.md](./backend/docker.md) |
|
||||
| **Frontend — overview (both apps)** | [frontend/README.md](./frontend/README.md) |
|
||||
@@ -49,6 +52,7 @@ 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 —
|
||||
fix the doc. Key files:
|
||||
- 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)
|
||||
- Seed: [`supabase/seed.sql`](../supabase/seed.sql)
|
||||
- Attendee app source: [`apps/convivo/src/`](../apps/convivo/src/)
|
||||
|
||||
+11
-3
@@ -34,16 +34,20 @@ flowchart LR
|
||||
K --> R["PostgREST"]
|
||||
K --> RT["Realtime"]
|
||||
K --> S["Storage"]
|
||||
K --> EF["Edge Functions<br/>sync-trigger"]
|
||||
R --> P[("Postgres 17<br/>schema · RLS · points RPCs")]
|
||||
RT --> P
|
||||
G --> P
|
||||
EF -->|"service-role RPCs"| R
|
||||
end
|
||||
MA["mock-api (:54330)<br/>Pretix + Sessionize fixtures"]
|
||||
end
|
||||
|
||||
A -->|"same-origin /auth /rest /realtime /storage"| N
|
||||
AD -->|"same-origin /auth /rest /realtime /storage"| NA
|
||||
A -->|"same-origin /auth /rest /realtime /storage /functions"| N
|
||||
AD -->|"same-origin /auth /rest /realtime /storage /functions"| NA
|
||||
N -->|"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,
|
||||
@@ -58,6 +62,7 @@ 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 |
|
||||
| QR | `html5-qrcode` (scan) + `qrcode.react` (render) | Camera scan with manual-entry fallback |
|
||||
| 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 |
|
||||
|
||||
## 4. The two halves
|
||||
@@ -70,6 +75,9 @@ Everything server-side lives in Postgres. See [backend/README.md](./backend/READ
|
||||
keep the leaderboard consistent. → [backend/rpcs.md](./backend/rpcs.md)
|
||||
- **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)
|
||||
- **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
|
||||
registrations, 3 sponsors. → [backend/seed.md](./backend/seed.md)
|
||||
|
||||
@@ -85,7 +93,7 @@ A separate desktop-first React app for organizers, guarded to the **`is_admin`**
|
||||
flag. See [frontend/admin-app.md](./frontend/admin-app.md):
|
||||
- **Views** — Dashboard (active event + aggregates), Contacts, Registrations,
|
||||
Sponsors, Schedule (slots/sessions/speakers/material/AI-evaluate), Activity,
|
||||
Events.
|
||||
Events, and **Interfaces** (trigger Pretix/Sessionize syncs + export the QR CSV).
|
||||
- **Auth guard** — same QR + email login, but non-admin sessions are rejected.
|
||||
- **Key RPCs** — `reset_qr_token` (regenerate a lanyard token + sync the Auth
|
||||
password), `adjust_points`, `upsert_contact`, `create_registration`,
|
||||
|
||||
@@ -7,18 +7,20 @@ Postgres. This folder documents that core.
|
||||
| File | What it covers |
|
||||
|---|---|
|
||||
| [supabase-core.md](./supabase-core.md) | The local stack: containers, ports, how to start/reset, config |
|
||||
| [schema.md](./schema.md) | All 13 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) |
|
||||
| [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 |
|
||||
| [docker.md](./docker.md) | Docker: the app image + root compose (how the core + app run together) |
|
||||
|
||||
## The big picture
|
||||
|
||||
```
|
||||
Postgres 17 ── schema (13 tables, multi-event model)
|
||||
Postgres 17 ── schema (14 tables, multi-event model)
|
||||
── RLS (who can read/write what)
|
||||
── RPCs (security definer, transactional points logic)
|
||||
── sync RPCs (service-role-only Pretix/Sessionize import)
|
||||
── seed (demo data)
|
||||
```
|
||||
|
||||
@@ -27,7 +29,10 @@ Postgres 17 ── schema (13 tables, multi-event model)
|
||||
rules.
|
||||
- **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
|
||||
is never shipped to the app. See [rls.md](./rls.md).
|
||||
is never shipped to the app. See [rls.md](./rls.md). The one exception is the
|
||||
**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,
|
||||
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).
|
||||
@@ -35,6 +40,7 @@ Postgres 17 ── schema (13 tables, multi-event model)
|
||||
## Source of truth
|
||||
|
||||
- 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):
|
||||
[`20260822000000_init.sql`](../../supabase/migrations/20260822000000_init.sql) and
|
||||
[`20260823000000_admin_app.sql`](../../supabase/migrations/20260823000000_admin_app.sql)
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
# 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`. Keeps the existing QR token unless a new
|
||||
one is supplied; **generates a token** (`CVV-XXX-NNNN`) for new ticket holders
|
||||
(Pretix doesn't provide one) so they can log in.
|
||||
- **Ensure the auth user** exists (`_ensure_auth_user` — QR token = password).
|
||||
- **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).
|
||||
|
||||
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, qr_token? }] }`.
|
||||
|
||||
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` |
|
||||
| *(generated)* | `contacts.qr_token` (for new ticket 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).
|
||||
+10
-3
@@ -1,6 +1,6 @@
|
||||
# Row Level Security (RLS)
|
||||
|
||||
RLS is the security boundary. It is **enabled on all 13 tables**, and every
|
||||
RLS is the security boundary. It is **enabled on all 14 tables**, and every
|
||||
policy is scoped to the `authenticated` role. The `anon` role has `GRANT select`
|
||||
at the Postgres level, but RLS blocks it from reading anything — so an
|
||||
unauthenticated request sees no rows.
|
||||
@@ -52,6 +52,7 @@ Source of truth:
|
||||
| `feedback` | own **or** admin | — | — | — |
|
||||
| `leaderboard` | all authenticated | — | — | — |
|
||||
| `points_log` | own **or** admin | — | — | — |
|
||||
| `sync_runs` | admin only | — | — | — |
|
||||
|
||||
**"—" (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
|
||||
@@ -119,6 +120,10 @@ create policy "leaderboard_select_all" on public.leaderboard for select to authe
|
||||
-- points_log: read own or admin
|
||||
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());
|
||||
|
||||
-- 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
|
||||
@@ -150,9 +155,11 @@ see):
|
||||
|
||||
```sql
|
||||
grant usage on schema public to anon, authenticated, service_role;
|
||||
grant select on <all 13 tables> to anon, authenticated, service_role;
|
||||
grant insert, update, delete on <all 13 tables> to 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 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
|
||||
|
||||
@@ -162,6 +162,23 @@ session** (the `sessions` table is admin-write only, so speakers need this
|
||||
security-definer RPC to attach their uploaded material). The attendee app calls
|
||||
this after uploading a file to the `materials` bucket.
|
||||
|
||||
## 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
|
||||
|
||||
| Function | Returns | Meaning |
|
||||
|
||||
+29
-4
@@ -4,10 +4,11 @@ All tables live in the `public` schema. Source of truth:
|
||||
[`supabase/migrations/20260824000000_redesign.sql`](../../supabase/migrations/20260824000000_redesign.sql)
|
||||
(the Redesign migration, which **replaces** the old `profiles`-based schema).
|
||||
|
||||
There are **13 tables**: people (`contacts`), the event (`events`), participation
|
||||
There are **14 tables**: people (`contacts`), the event (`events`), participation
|
||||
(`registrations`, `sponsors`), the schedule (`slots`, `sessions`,
|
||||
`session_speakers`), and the event's activity (`preferences`, `connections`,
|
||||
`checkins`, `feedback`, `leaderboard`, `points_log`).
|
||||
`session_speakers`), the event's activity (`preferences`, `connections`,
|
||||
`checkins`, `feedback`, `leaderboard`, `points_log`), and the interface audit
|
||||
(`sync_runs`).
|
||||
|
||||
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**
|
||||
@@ -54,9 +55,11 @@ One row per person. **`email` is the primary key** (a natural key that matches
|
||||
| `show_linkedin` | `boolean` | default `false` — visibility toggle |
|
||||
| `is_admin` | `boolean` | default `false` — **staff = admin (merged)**; grants check-in + APPE Admin access |
|
||||
| `qr_token` | `text` **unique** | The lanyard token; **doubles as the Auth password** |
|
||||
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
Index: `contacts_qr_token_idx (qr_token)` — fast lanyard lookups.
|
||||
Partial unique index: `contacts_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
|
||||
|
||||
## `events` — a conference
|
||||
|
||||
@@ -93,10 +96,11 @@ Points are scoped **per event** here (one row per contact per event).
|
||||
| `type` | `text` | `attendee` \| `speaker` \| `staff` \| `sponsor` (default `attendee`) |
|
||||
| `checked_in` | `boolean` | default `false` |
|
||||
| `points` | `integer` | `>= 0`, default 0 |
|
||||
| `external_id` | `text` | nullable — the Pretix order code (set by the sync) |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
**Constraint:** `unique (event_id, contact_email)` — one registration per contact
|
||||
per event.
|
||||
per event. Partial unique index: `registrations_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
|
||||
|
||||
## `sponsors` — a sponsor for an event
|
||||
|
||||
@@ -140,6 +144,7 @@ Unpaid sponsors are hidden from non-admins (RLS).
|
||||
| `average_feedback` | `numeric` | maintained by `submit_feedback` |
|
||||
| `ai_generated_feedback` | `text` | AI-feedback state (stub) |
|
||||
| `material_path` | `text` | nullable — storage object path for session material |
|
||||
| `external_id` | `text` | nullable — the Sessionize session id (set by the sync) |
|
||||
| `created_at` | `timestamptz` | |
|
||||
|
||||
> **Speakers are no longer a `text` column** — they live in the `session_speakers`
|
||||
@@ -147,6 +152,7 @@ Unpaid sponsors are hidden from non-admins (RLS).
|
||||
> comma-separated `speakers` string for display.
|
||||
|
||||
Indexes: `sessions_event_id_idx (event_id)`, `sessions_slot_id_idx (slot_id)`.
|
||||
Partial unique index: `sessions_external_id_uniq (external_id) WHERE external_id IS NOT NULL`.
|
||||
|
||||
## `session_speakers` — M:N between sessions and contacts
|
||||
|
||||
@@ -253,6 +259,25 @@ Powers the per-category points breakdown on the Profile screen (per event).
|
||||
|
||||
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
|
||||
|
||||
- `slots_event_id_idx (event_id)`, `registrations_event_id_idx (event_id)`,
|
||||
|
||||
@@ -20,6 +20,7 @@ It runs on **port 3001** (Vite dev) or as the `convivo-admin` Docker container
|
||||
| **Schedule** | Slots (with type) + sessions (with speakers 1:N, material upload, `average_feedback`, `ai_generated_feedback` + an **Evaluate** stub button). |
|
||||
| **Activity** | Tables of check-ins, connections, and feedback (per active event). |
|
||||
| **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
|
||||
|
||||
@@ -59,7 +60,8 @@ apps/admin/src/
|
||||
├─ Sponsors.tsx # sponsor CRUD
|
||||
├─ Schedule.tsx # slots + sessions + speakers + material + AI-evaluate
|
||||
├─ 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
|
||||
@@ -100,6 +102,25 @@ The Schedule view uploads a session's material to the `materials` bucket and set
|
||||
button calls `evaluate_session_feedback` (the AI stub) to set
|
||||
`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
|
||||
|
||||
The admin app reuses the attendee app's **design tokens** (colors, Poppins font,
|
||||
|
||||
+52
-36
@@ -4,9 +4,10 @@ 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
|
||||
current phase.
|
||||
|
||||
> **Current state:** Phases 0–6 are complete and verified, including the full
|
||||
> **Redesign** (Phases 3–6) on the new multi-event data model. The next work is
|
||||
> the **Pretix** (Phase 7) and **Sessionize** (Phase 8) interfaces.
|
||||
> **Current state:** Phases 0–8 are complete and verified. The **Redesign**
|
||||
> (Phases 3–6) and the **Pretix + Sessionize interfaces** (Phases 7–8) are done.
|
||||
> Remaining work is cross-cutting (real event clock, deployment, testing) and
|
||||
> the open questions in [backend/interfaces.md](./backend/interfaces.md).
|
||||
|
||||
## Done
|
||||
|
||||
@@ -138,40 +139,45 @@ rebuilt the views on the new model:
|
||||
- `https://www.appe.at/assets/appe_full.png` as favicon + PWA icon (192/512)
|
||||
for **both** apps. Updated `index.html` + `manifest.webmanifest` + `public/`.
|
||||
|
||||
## Later (post-redesign)
|
||||
## The Interfaces (Phases 7–8) — ✅ complete
|
||||
|
||||
### Phase 7 — Pretix interface ⬜
|
||||
Both external interfaces are built and browser-verified end-to-end (against the
|
||||
local mock API). Full detail: [backend/interfaces.md](./backend/interfaces.md).
|
||||
|
||||
### Phase 7 — Pretix interface ✅
|
||||
Sync **tickets → contacts + registrations** from [Pretix](https://pretix.eu).
|
||||
Replaces the hand-written seed with real ticket data.
|
||||
|
||||
**Goal:** when someone buys a ticket in Pretix, a contact is created (if it
|
||||
doesn't exist) and a registration is created using the contact lookup.
|
||||
- **`sync-trigger` Edge Function** pulls `GET /pretix/attendees`, normalizes, and
|
||||
calls the service-role-only `sync_pretix_attendees(jsonb)` RPC.
|
||||
- **Upserts** `contacts` (by email) + `registrations` (by event + contact) +
|
||||
`auth.users` (QR token = password). **Generates a QR token** for new ticket
|
||||
holders so they can log in.
|
||||
- **Type mapping** — `_map_ticket_type` maps the Pretix ticket type to
|
||||
`attendee` / `speaker` / `staff` / `sponsor` (substring match; sponsor
|
||||
auto-creates a sponsor row).
|
||||
- **Idempotent** — keyed on `external_id` (Pretix order code) + email; re-runs
|
||||
update in place.
|
||||
- **QR export** — the APPE Admin **Interfaces** view exports a CSV of lanyard QR
|
||||
codes for the active event.
|
||||
|
||||
Likely scope:
|
||||
- A **sync job / edge function** (or a small service) that pulls
|
||||
orders/attendees from the Pretix API and upserts `contacts` +
|
||||
`registrations` (+ `auth.users`).
|
||||
- **QR token generation** for each contact (the lanyard token).
|
||||
- **Type mapping** — which Pretix ticket type maps to
|
||||
`attendee` / `speaker` / `staff` / `sponsor` (open question).
|
||||
- **Idempotency** — re-running the sync must not duplicate (key on the Pretix
|
||||
order/attendee id + email).
|
||||
- A way to **print/export lanyard QR codes** for the event.
|
||||
|
||||
**Open questions:**
|
||||
1. Which Pretix fields map to registration type and contact?
|
||||
2. Push (webhook on new order) vs pull (scheduled sync)?
|
||||
3. Where does the sync job run (Supabase Edge Function vs a separate container)?
|
||||
|
||||
### Phase 8 — Sessionize interface ⬜
|
||||
### Phase 8 — Sessionize interface ✅
|
||||
Sync the **real agenda** (slots, sessions, speakers, rooms) from
|
||||
[Sessionize](https://sessionize.com) instead of the hand-written seed.
|
||||
[Sessionize](https://sessionize.com).
|
||||
|
||||
Likely scope:
|
||||
- A sync job that pulls the event schedule from the Sessionize API and upserts
|
||||
`slots` + `sessions` + `session_speakers`.
|
||||
- Map Sessionize track/room/time → our `slots` / `sessions` shape.
|
||||
- This makes the agenda **data-driven** from the real event.
|
||||
- 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.
|
||||
|
||||
## Cross-cutting / later
|
||||
|
||||
@@ -189,11 +195,21 @@ Likely scope:
|
||||
|
||||
## Open decisions (need user input)
|
||||
|
||||
1. **Pretix type mapping** — which ticket type = speaker/staff/sponsor?
|
||||
2. **Sync style** — webhook (push) vs scheduled (pull) for Pretix/Sessionize?
|
||||
3. **Sync runtime** — Supabase Edge Functions vs separate containers?
|
||||
4. **AI provider** — which LLM/API for `ai_generated_feedback` (Phase 4+)?
|
||||
5. **Deployment target** — stay on localhost, or plan for the `appe.at`
|
||||
**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:**
|
||||
1. **Pretix type 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).
|
||||
4. **Deployment target** — stay on localhost, or plan for the `appe.at`
|
||||
subdomains now?
|
||||
|
||||
## How to pick up work
|
||||
|
||||
Reference in new issue
Block a user