edge-function

Create or change a Supabase Edge Function (Deno) with JWT auth, zod contract from packages/shared, rate limiting, error envelope and tests. Use for bank sync, aggregator calls, export, notifications,

SKILL.md

GitHub

Edge function

Read first: docs/14-api-contracts.md (contract + §5 error codes), .claude/rules/08-security.md § Every new edge function, and docs/08 for anything bank-related.

  1. Folder supabase/functions/<name>/: index.ts (thin handler), handler.ts (logic with injected deps), *.test.ts. Shared helpers in supabase/functions/_shared/.
  2. Contract: request/response zod schemas in packages/shared/contracts/ (no hand-written payload types). Round-trip test there.
  3. Handler order: CORS preflight → verify JWT → derive householdId from the JWT, never the body → validate body → _shared/ratelimit.ts → authorise (app.is_member) → execute → map to the standard error envelope.
  4. Aggregator access only through getAdapter(env) returning an AggregatorAdapter; MockAggregatorAdapter must pass the same contract tests. Never a switch (provider).
  5. Secrets via function secrets only, read once in a config module. Never log or echo: provider tokens, raw provider payloads, IBANs, names, descriptions, amounts. Explicit column lists — no SELECT *.
  6. Webhooks (RevenueCat): verify signature, idempotent by event id.
  7. deno test with fakes; run locally with supabase functions serve; then add the client repository call + types in the app.