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,
Files1
View on GitHubSKILL.md.claude/skills/edge-function/SKILL.md
GitHubEdge 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.
- Folder
supabase/functions/<name>/:index.ts(thin handler),handler.ts(logic with injected deps),*.test.ts. Shared helpers insupabase/functions/_shared/. - Contract: request/response zod schemas in
packages/shared/contracts/(no hand-written payload types). Round-trip test there. - Handler order: CORS preflight → verify JWT → derive
householdIdfrom the JWT, never the body → validate body →_shared/ratelimit.ts→ authorise (app.is_member) → execute → map to the standard error envelope. - Aggregator access only through
getAdapter(env)returning anAggregatorAdapter;MockAggregatorAdaptermust pass the same contract tests. Never aswitch (provider). - 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 *. - Webhooks (RevenueCat): verify signature, idempotent by event id.
deno testwith fakes; run locally withsupabase functions serve; then add the client repository call + types in the app.