Scaffold Supabase Edge Function for webhook
epic-pause-status-notifications-backend-pipeline-task-002 — Create the Supabase Edge Function file structure for the pause status webhook handler. Set up the Deno entry point, configure the function to listen on the correct route, establish the HTTP request/response cycle, and wire up the Supabase webhook secret verification middleware.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 1 - 540 tasks
Can start after Tier 0 completes
Implementation Notes
Supabase Edge Functions run on Deno — use Deno.serve() (Deno 1.35+) rather than the older addEventListener('fetch') pattern. The Supabase webhook secret header is typically 'x-webhook-secret' but verify against the Supabase dashboard webhook configuration. For constant-time comparison use crypto.subtle.timingSafeEqual() with TextEncoder — do NOT use === for secret comparison as it is vulnerable to timing attacks. Structure the entry point as: (1) parse request, (2) verify method, (3) verify secret, (4) parse body, (5) delegate to handler (stub for now).
Keep index.ts thin — middleware logic should be extracted to middleware.ts for testability.
Testing Requirements
Manual integration test using supabase functions serve locally: (1) POST with correct secret and valid JSON body → 200, (2) POST with wrong secret → 401, (3) POST with no secret header → 401, (4) POST with valid secret but malformed JSON body → 400, (5) GET request → 405. Document these curl commands in a README or test script alongside the function. Automated Deno unit tests for the middleware function itself (inject mock Request objects).
Supabase Edge Functions have cold start latency that may push coordinator notification delivery beyond the 5-second SLA, particularly during low-traffic periods when the function is not warm.
Mitigation & Contingency
Mitigation: Keep the Edge Function lightweight — delegate all heavy logic to the orchestrator layer and avoid large dependency bundles. Measure p95 end-to-end latency in staging and document actual SLA achievable.
Contingency: If cold start latency consistently breaches 5 seconds, introduce a keep-warm ping from the nightly-scheduler or document the actual p95 latency in the feature spec and adjust the acceptance criterion to reflect the realistic bound.
Supabase database webhooks may fire duplicate events for a single status change under retry conditions, causing coordinators to receive multiple identical notifications for one pause event.
Mitigation & Contingency
Mitigation: Add idempotency checking in the webhook handler using the event timestamp and peer mentor ID. Store a notification dispatch record in the pause-status-record-repository and skip dispatch if a record for the same event already exists.
Contingency: If duplicates slip through in production, add a de-duplication filter in the notification centre UI layer so the coordinator sees at most one card per event, and implement a cleanup job for the notifications table.
A peer mentor with multi-chapter membership may have more than one responsible coordinator. The orchestrator design currently targets a single coordinator, and resolving multiple recipients may require schema changes to the org membership query.
Mitigation & Contingency
Mitigation: Review the multi-chapter-membership-service patterns before implementing the orchestrator's coordinator resolution. Design the dispatcher call to accept an array of coordinator IDs from the outset so adding multiple recipients is non-breaking.
Contingency: If multi-coordinator dispatch is out of scope for this epic, document the limitation and create a follow-up task. Default to the primary coordinator (lowest chapter hierarchy level) as the single recipient in the interim.