Build Bufdir API integration service stub
epic-bufdir-reporting-export-processing-services-task-010 — Implement the BufdirApiIntegrationService as an abstraction layer that encapsulates the file delivery mechanism. The stub should implement the service interface with file-based delivery (writing to storage and returning download URLs) while defining the interface contract that a future direct Bufdir API submission implementation must satisfy. Include configuration flag to switch between file and API delivery modes.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 3 - 413 tasks
Can start after Tier 2 completes
Implementation Notes
Define `abstract class BufdirApiIntegrationService` with three async methods. Use Riverpod's `Provider
Document the future `BufdirDirectApiService` with a detailed `// TODO` block referencing the interface contract task (task-011) and listing the expected Bufdir API endpoint path, auth header format, and payload schema placeholder. Avoid using `dynamic` anywhere — all method signatures must be strongly typed. Register the provider in a dedicated `bufdir_providers.dart` file to keep provider definitions co-located with the service.
Testing Requirements
Unit tests (flutter_test with mocktail) must cover: (1) file delivery — mock Supabase Storage upload succeeds, assert `BufdirDeliveryResult` has status `pending_review` and non-empty `package_urls`; (2) file delivery — mock Supabase Storage upload throws, assert result has status `failed` and error message is populated; (3) configuration routing — with `BUFDIR_DELIVERY_MODE=fileDelivery`, assert `BufdirFileDeliveryService` is injected; (4) interface contract — instantiate `BufdirDirectApiService` and assert calling any method throws `UnimplementedError` with a descriptive message; (5) audit log write — assert `bufdir_export_audit_log` insert is called with correct fields on both success and failure paths. Riverpod provider override pattern must be demonstrated in at least one test to confirm testability. Test coverage for the stub implementation must be at least 90%.
NHF contacts can belong to up to five local chapters simultaneously. If the deduplication logic in the activity query service incorrectly attributes cross-chapter activities, organisations will either under-report or over-report to Bufdir, which could trigger grant clawback or compliance investigations.
Mitigation & Contingency
Mitigation: Implement deduplication using the existing multi-chapter membership service as the source of truth for chapter affiliation. Write test fixtures covering all known multi-chapter edge cases and validate outputs against manually prepared reference exports from NHF.
Contingency: If deduplication cannot be made deterministic for complex hierarchies before release, gate the export behind an org-level feature flag and require NHF to validate a preview export against their manual Excel before enabling in production.
Server-side Dart libraries for Excel generation are less mature than equivalents in Node.js or Python. The chosen library may lack support for Bufdir-required formatting features (merged cells, data validation, specific date formats), requiring significant workaround effort or a library switch mid-implementation.
Mitigation & Contingency
Mitigation: Evaluate the top two Dart xlsx libraries (excel, spreadsheet_decoder) against a Bufdir template sample file before committing. Identify all required formatting features and verify library support in a spike.
Contingency: If no Dart library meets requirements, implement the Excel generation as a Supabase Edge Function in TypeScript using the well-supported ExcelJS library, exposing it to the Dart backend via an internal RPC call.
The attachment bundler must retrieve documents from Supabase Storage that were uploaded by the document attachments feature. If storage paths, RLS policies, or signed URL expiry have not been standardised across features, the bundler may fail to retrieve attachments at export time.
Mitigation & Contingency
Mitigation: Audit the document attachments feature's storage schema and RLS policies before implementing the bundler. Agree on a stable internal service-account access pattern for cross-feature storage reads.
Contingency: If cross-feature storage access cannot be made reliable, implement the bundler to include only attachments that can be retrieved successfully and produce a manifest listing any attachments that could not be bundled, rather than failing the entire export.