Unify the provider connection lifecycle for Brex, Lunch Flow, and Mercury

Merged
JJ
7h ago
+17705-7181

Summary

Brex, Lunch Flow, and Mercury each maintained their own connection setup, account linking, and sync lifecycle. This PR moves those three providers onto shared Rails models, controllers, and view components. Account-provider adapters declare their connections in one place, which supplies the lists used by Bank Sync, the Accounts page, and the connection-status API. The provider:family generator now builds on the same kit.

This brings the 56 reviewed changes from stack #5268 onto main, in their original order. Refs #5003.

Behavior to review

  • Brex, Lunch Flow, and Mercury share the account-selection and setup flows. Account cards and post-setup Turbo updates respect the viewer’s account access, including for family admins.
  • Editing a Lunch Flow connection keeps its stored API key out of the rendered form. A blank secret on edit preserves the existing credential.
  • Mercury validates every transaction page before saving the account’s fetch. Malformed pages, repeated full pages, and page limits leave the stored transactions intact and retain the retry date. A successful explicit window that starts later also preserves the earlier retry date. Both Lunch Flow and Mercury honor an explicit sync start date.
  • Linking an existing account requires ownership or a full-control share. Link submissions recheck the upstream account list, and rotating credentials isolates in-flight discovery results. Settings panels show connection-wide counts only when the admin can see all linked accounts.
  • Stored accounts remain available during a setup refresh outage. Generated investment providers offer Crypto with wallet and exchange subtypes. Each subtype picker has its own accessible label, and its blank choice is keyboard-selectable.
  • Sync statistics count linked and unlinked accounts in a single query. Lunch Flow reports balance-refresh failures separately from transaction-fetch failures.
  • GET /api/v1/provider_connections lists providers alphabetically by key. Connections within a provider retain their order.

Database migration

Apply 20261201120000_add_transactions_sync_start_date_to_mercury_accounts during deployment. This adds one nullable date to each Mercury account. The importer initializes it on the next fetch from that account’s previous sync history, so deployment requires no backfill.

Screenshots

The Brex account-setup prompt from #5232 illustrates the shared card. The Lunch Flow credential form and Mercury setup dialogs have additional comparisons.

BeforeAfter
Previous Brex account-setup promptUpdated Brex account-setup prompt

Validation

  • Verified that all 56 rebased commits preserve the reviewed stack order and that each commit’s files match the corresponding changes applied to main at 5f31a17f5.
  • After the review fixes, bin/rails test completed with 20,204 tests, 121,912 assertions, nine skips, and zero failures or errors.
  • The full browser suite passed on the rebased stack (532 tests). The provider account setup browser test also passed after the review fixes, including keyboard clearing and submitting the selected subtype.
  • RuboCop, ERB lint, Biome, Brakeman, and the dependency audit passed.

Summary by cubic

Unifies the connection lifecycle for Brex, Lunch Flow, and Mercury on shared provider-kit infrastructure: models, controllers, account flows, syncers, and view components. Connection declarations on each provider adapter now drive the provider lists in Bank Sync, the Accounts page, and the connection-status API; the provider:family generator emits the same kit. No database migration is needed.

Behavior changes

  • Mercury now pages through transactions instead of importing only the first page; Lunch Flow and Mercury honor an explicit sync start date.
  • An open redirect via protocol-relative return_to paths is closed for Lunch Flow and Mercury.
  • Lunch Flow's panel no longer renders the stored API key into the page HTML; a blank secret on edit preserves the stored credential.
  • Linking several accounts is transactional, unsupported account types are refused, and setup accepts subtypes only for the chosen account type.
  • Failed syncs are reported once to Sentry, tagged with both connection and sync ids; swallowed Brex import failures now appear in the debug log.
  • GET /api/v1/provider_connections lists providers alphabetically by key.

Summary by CodeRabbit

  • New Features

    • Added guided account selection and setup for provider connections, including account-type and subtype choices.
    • Lunch Flow and Mercury connections now support choosing a transaction import start date.
    • Added clearer connection status, sync summaries, and troubleshooting details for provider errors.
  • Improvements

    • Provider settings and account lists now reflect connection details, with account visibility respecting access.
    • Blank connection names receive a localized default.
    • Large Mercury transaction imports handle pagination and duplicate records more reliably.
  • Bug Fixes

    • Unnamed provider accounts can’t be selected for linking.
    • Keyboard selection now works for options with empty values.