Expose consent status API endpoint for service layer
epic-geographic-peer-mentor-map-consent-privacy-task-008 — Create a Supabase Edge Function or RPC endpoint that wraps checkConsent and returns a typed ConsentStatusResponse for use by mentor-location-service and any other component that must gate on consent. The endpoint must validate the calling user's JWT, confirm org membership, and return status within 300ms under normal load.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Implement as a Supabase Edge Function in Deno (TypeScript). At the top of the handler, call createClient with the Authorization header from the request to get a user-scoped client — this ensures RLS from task-005 is applied. Use const { data, error } = await supabase.from('consent_grants').select('status, granted_at, consent_version, requires_reconsent').eq('mentor_id', mentorId).eq('org_id', orgId).maybeSingle() — maybeSingle() returns null instead of error when no row exists, allowing the 'pending' fallback. For the Dart client, use Supabase's functions.invoke('check-consent-status') method rather than raw http calls to get automatic JWT injection.
Define ConsentStatusResponse as an immutable Dart class with fromJson factory and copyWith. Keep the function stateless and free of any caching layer — consent status must always reflect the current database state.
Testing Requirements
Unit tests for the Dart ConsentStatusClient: mock HTTP responses for each status variant (granted, denied, revoked, pending), assert correct ConsentStatusResponse parsing, assert ConsentUnauthorizedException on 403, assert ConsentAuthException on 401, assert network error surfaced as ConsentNetworkException. Integration tests against local Supabase (supabase start): deploy function locally, call with valid JWT for each role, assert correct status returned for each consent state. Load test: 50 concurrent requests to confirm p95 < 300ms. Test cold start by restarting the function and measuring first-call latency.
If the privacy policy text or consent terms change after mentors have already opted in, existing consent records may become legally insufficient, requiring re-consent from all opted-in mentors which could temporarily reduce map coverage.
Mitigation & Contingency
Mitigation: Store a consent_version field on every consent record. Implement a consent version check in location-consent-service that compares the stored version against the current policy version from location-privacy-config and flags stale consents for re-consent prompting.
Contingency: If a policy update invalidates existing consents, suppress affected mentors from the map, queue them for re-consent notification via the existing in-app notification system, and restore map visibility only after new consent is recorded.
A poorly designed consent dialog may lead to low opt-in rates, reducing map utility for coordinators to the point where the feature delivers insufficient value to justify maintenance cost.
Mitigation & Contingency
Mitigation: Follow plain-language writing guidelines from the cognitive accessibility feature. User-test the dialog with 2-3 peer mentors from Blindeforbundet before implementation is finalised. Ensure the dialog explains the benefit to the mentor, not just the data collection facts.
Contingency: If opt-in rate after launch is below 40%, conduct a targeted usability study and iterate on dialog copy and layout. The coordinator can also send a bulk opt-in invitation notification (per the user story) to non-consenting mentors.