Listoca

Server-side code

Database functions, Edge Functions, scheduled jobs and emails, without an API server.

There is no API server. Logic that must run on a server goes, in this order:

  1. A constraint, trigger or policy, when the rule is about the data (the 25 people on a list and the Sync plan check are triggers).
  2. A database function called over RPC, when several statements must be one transaction, or a caller needs more than their own rows (the admin area's lists).
  3. An Edge Function, when it needs a secret or another service (emails, RevenueCat, account deletion).

Database functions

security definer functions live in the private schema with a fixed search_path; a public RPC checks its caller first (perform private.require_admin()). Clients call them with supabase.rpc("admin_list_users", { search }), typed from the generated types.

Edge Functions

A function is a plain handler in packages/functions/src/handlers/<name>.ts:

export const deleteAccount: Handler = async (request, deps) => {
  const user = await requireUser(request, deps);
  // …
  return json({ deleted: true });
};

Its first lines state the caller: requireUser, requireAdmin, requireSecret (pg_cron) or verifyWebhook (Supabase Auth hooks). Errors are { error: { code } }, translated by the apps. bun run functions:build bundles each handler with the workspace code it imports into supabase/functions/<name>/index.js, which the Edge Runtime serves. Tests call handlers directly with test dependencies (packages/functions/src/testing.ts).

FunctionCalled by
send-emailSupabase Auth (the email hook)
send-queued-emailpg_cron, every minute
delete-accountthe apps
admin-usersthe admin area
revenuecat-webhookRevenueCat
sync-entitlementsthe native app after a purchase
reconcile-entitlementspg_cron, nightly
healthuptime checks

Scheduled jobs

pg_cron schedules live in migrations. A job that calls a function reads the URL and the shared secret from Vault:

select cron.schedule('send-queued-email', '* * * * *', $$
  select net.http_post(url := private.function_url('send-queued-email'),
                       headers := private.function_headers(), body := '{}'::jsonb);
$$);

Emails

Auth emails (sign-up, sign-in codes, password reset, email change) go through the send-email hook: one template, the 6-digit code, in the user's language. Every other email is a row in email_outbox (private.enqueue_email(...)), sent by send-queued-email with retries. Templates are React Email components in packages/mail; preview them with bun run dev:mail. Resend sends them in production: Emails.

On this page