Supabase Mileage Adapter
Component Detail
Description
Low-level Supabase client wrapper scoped to the mileage claims and org configuration tables. Translates domain model objects to/from Supabase JSON rows and handles Row Level Security policy compliance for peer mentor and coordinator access scopes.
supabase-mileage-adapter
Summaries
This infrastructure component forms the secure data bridge between the mobile application and the cloud database, enforcing access control rules that ensure peer mentors can only view their own claims while coordinators retain the oversight access they need to approve and manage submissions. By centralising all database communication logic, it protects the business from data leakage and unauthorised access, which are significant compliance and reputational risks for an organisation handling sensitive financial records. It also allows future database or security policy changes to be made in one place rather than scattered across the codebase.
As a foundational infrastructure component with no upstream dependencies, this adapter should be delivered and stabilised early in the sprint schedule, as all repository-layer components depend on it. The Row Level Security policy configuration in Supabase must be agreed with the backend or database team before development begins, making this a cross-team coordination risk. Testing must cover both peer mentor and coordinator access scopes to verify RLS enforcement, and error-path coverage for Supabase-specific error codes (e.g., 42501 permission denied, 23505 unique violation) is mandatory before other components can rely on its exception contract.
A thin data-layer wrapper around the Supabase Dart client, scoped exclusively to the `mileage_claims` and `org_configuration` tables. Each public method constructs the appropriate Supabase query builder chain and returns raw `Map
Error handling must translate Supabase `PostgrestException` codes to domain exceptions before surfacing them to callers.
Responsibilities
- Execute Supabase insert, select, update, and delete queries against the mileage_claims table
- Execute select queries against the org_configuration table for rate and threshold fields
- Map raw Supabase JSON responses to typed Dart model objects
- Handle Supabase error codes and surface domain-friendly exceptions
Interfaces
insertClaimRow(Map<String, dynamic> data) → Future<Map<String, dynamic>>
selectClaimsWhere(Map<String, dynamic> filters) → Future<List<Map<String, dynamic>>>
updateClaimRow(String id, Map<String, dynamic> data) → Future<void>
selectOrgConfig(String orgId) → Future<Map<String, dynamic>>
watchOrgConfig(String orgId) → Stream<Map<String, dynamic>>
Relationships
Dependents (2)
Components that depend on this component
Related Data Entities (2)
Data entities managed by this component