API Reference

Flow non espone un’API custom. I client (mobile + web) parlano direttamente con Supabase via tre canali:

  1. PostgREST — auto-generato da Postgres, copre tutto il CRUD delle tabelle con RLS applicato automaticamente
  2. Edge Functions — endpoint HTTP Deno/TypeScript per logica che non può vivere in puro SQL (notifiche, scoring, moderazione)
  3. Realtime — subscription a Postgres changes + broadcast channels

Niente gateway custom, niente serializzazione manuale. I tipi TypeScript/Dart sono auto-generati dallo schema.


PostgREST — CRUD automatico

Ogni tabella con RLS è un endpoint REST. Esempi:

// Tutti gli eventi pubblici (RLS filtra il resto)
const { data } = await supabase.from('events').select('*');
 
// Eventi nell'area, ordinati per data
const { data } = await supabase
  .from('events')
  .select('*, venue:venues(*)')
  .gte('start_at', new Date().toISOString())
  .order('start_at', { ascending: true });
 
// INSERT — RLS richiede user.id come organizer
const { data, error } = await supabase
  .from('events')
  .insert({ title, start_at, venue_id });

Docs Supabase: PostgREST client.


Edge Functions

Funzioni deployate in supabase/functions/. Ciascuna esposta come endpoint HTTPS.

FunctionURLMetodoTrigger
send-notification/functions/v1/send-notificationPOSTDatabase webhook (INSERT su notifications)
process-rsvp/functions/v1/process-rsvpPOSTDatabase webhook (INSERT/UPDATE su event_attendees)
compute-recommendations/functions/v1/compute-recommendationsPOSTCron (6h) + on-demand
compute-matchmaking/functions/v1/compute-matchmakingPOSTChiamata dal client mobile
moderate-content/functions/v1/moderate-contentPOSTDatabase webhook (INSERT su messages/comments)
compute-connection-depth/functions/v1/compute-connection-depthPOSTDatabase webhook (INSERT su event_attendees)
evaluate-badges/functions/v1/evaluate-badgesPOSTChiamata interna da process-rsvp

Richiedere una Edge Function dal client:

const { data, error } = await supabase.functions.invoke('compute-matchmaking', {
  body: { max_results: 20 },
});

Deploy: npx supabase functions deploy <function-name>.


Realtime

Subscribe a cambi Postgres o a broadcast channels:

// Postgres change (notifiche dell'utente corrente)
const channel = supabase
  .channel(`notifications:${userId}`)
  .on(
    'postgres_changes',
    { event: 'INSERT', schema: 'public', table: 'notifications', filter: `user_id=eq.${userId}` },
    (payload) => { /* ... */ }
  )
  .subscribe();
 
// Broadcast (typing indicators, presence)
const chatChannel = supabase.channel(`chat:${chatId}`);
chatChannel.on('broadcast', { event: 'typing' }, (payload) => { /* ... */ });

Docs: Supabase Realtime.


Autenticazione

Tutte le richieste sono autenticate via JWT Supabase Auth:

// Login
await supabase.auth.signInWithPassword({ email, password });
 
// Le chiamate successive attaccano il JWT automaticamente
const { data: { user } } = await supabase.auth.getUser();

Le RLS policies leggono auth.uid() per autorizzare. Le Edge Functions che devono bypassare RLS usano la service_role key via _shared/supabase-client.ts.


Risorse