Document API client integration and migration guide
epic-bufdir-report-export-api-integration-task-010 — Write technical documentation for the bufdir-api-client covering: the shared interface contract between file-based and API submission paths, authentication setup and credential rotation steps, how to enable direct_api mode per organisation via the feature flag, the BufdirSubmissionResult model and error type catalogue, and a migration checklist for organisations transitioning from file-based to direct API submission once Norse Digital Products completes API negotiations with Bufdir.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Handles integration between different epics or system components. Requires coordination across multiple development streams.
Implementation Notes
Write the document in a tone suitable for both a developer implementing the integration and a non-developer project coordinator following the migration checklist. Use numbered lists for procedures, code blocks for all Dart snippets and shell commands, and admonition blocks (Note/Warning) for security-sensitive steps. Keep the migration checklist in a separate clearly labelled section so it can be extracted and sent to organisation contacts as a standalone document. Mark all sections that depend on Bufdir finalising the API contract with a `[PENDING: Bufdir API negotiation]` tag so reviewers know these sections require updating.
Store the document in the project repository so it is versioned alongside the code.
Testing Requirements
Documentation review rather than automated tests. The tech lead must verify: (1) every code snippet compiles or runs correctly against the actual implementation, (2) credential rotation steps are walked through in a staging environment to confirm they work without errors, (3) the feature flag toggle is tested against a real organisation record in staging to confirm it routes to the correct submission path. If any snippet is found to be incorrect during review, the doc must be updated before the task is marked done.
Norse Digital Products has not yet completed API negotiations with Bufdir. If negotiations stall or Bufdir's API design diverges significantly from expectations, the API client may need substantial rework, or the epic may be blocked indefinitely.
Mitigation & Contingency
Mitigation: Implement the client against a locally defined stub of the expected Bufdir API schema. Isolate all Bufdir-specific schema mapping in a single adapter class so that changes to the actual API schema require changes in only one place. Keep the epic in 'interface-ready' status until real API credentials are available for integration testing.
Contingency: If API negotiations are not completed within the planned window, defer this epic without impact on any other epic — the PDF/CSV fallback path from Epics 1–4 delivers full standalone value. Mark the epic as blocked and resurface when negotiations conclude.
Bufdir API credentials stored in the application or edge function environment could be exposed through misconfigured secrets management, log leakage, or a compromised deployment pipeline, allowing unauthorised Bufdir submissions on behalf of the organisation.
Mitigation & Contingency
Mitigation: Store all Bufdir API credentials exclusively in Supabase Vault (or the integration credential vault component), never in client-side code or environment variables accessible to the Flutter app. Transmit credentials only from within the edge function, not from the Flutter client. Implement credential rotation support from the outset.
Contingency: If a credential leak is detected, immediately revoke and rotate the affected API credentials through Bufdir's credential management portal, audit submission logs for any unauthorised calls, and notify Bufdir's technical contact per the API agreement's security incident clause.