Skip to content

feat(connectors): pluggable BankConnector interface, registry, and mock connector for Indian bank sync#286

Open
macan88 wants to merge 3 commits intorohitdash08:mainfrom
macan88:felix/fix-75
Open

feat(connectors): pluggable BankConnector interface, registry, and mock connector for Indian bank sync#286
macan88 wants to merge 3 commits intorohitdash08:mainfrom
macan88:felix/fix-75

Conversation

@macan88
Copy link

@macan88 macan88 commented Mar 2, 2026

Problem

The codebase has no abstraction for bank integrations — every potential connector would need to be hardcoded into the sync logic with no shared contract, making it impossible to add AA/API-provider connections without rewriting core sync code each time.

Solution

Adds three files that together form a minimal, extensible connector layer:

File Role
app/src/lib/connectors/base.ts BankConnector interface + Transaction/ImportResult types + typed error classes
app/src/lib/connectors/registry.ts ConnectorRegistry singleton — register(), getConnector(), listConnectors()
app/src/lib/connectors/mock.ts MockBankConnector — deterministic INR transaction data, cursor pagination, forced-failure auth path

Key design decisions:

  • Cursor-based pagination on importTransactions(cursor?) prevents duplicate transactions on retry and supports incremental sync without refetching full history.
  • refreshSync() separate from importTransactions() so AA connectors can re-validate consent on background polls without affecting user-triggered imports.
  • Registry throws on duplicate ID rather than silently overwriting — avoids hard-to-debug production data integrity issues.
  • In-memory credentials only — real connector implementations must proxy auth through the backend; no API keys in localStorage (documents the security requirement explicitly in base.ts).
  • _resetForTesting() on registry keeps unit tests isolated without module re-imports.

A real AA-provider connector (e.g., Finvu / Setu AA) can be added by implementing BankConnector and calling ConnectorRegistry.register('aa-finvu', FinvuConnector) — zero changes to existing files required.

Testing

  • Inline test suite documented in mock.ts (runnable via vitest) covering:
    • Registry returns MockBankConnector instance for id "mock"
    • Duplicate registration throws
    • Unregistered ID throws with helpful message
    • importTransactions() returns transactions with id, amount, date, currency: 'INR'
    • Cursor pagination produces non-overlapping pages; hasMore correct at end
    • authenticate({ fail_auth: 'true' }) throws ConnectorAuthError

Closes #75

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bank Sync Connector Architecture

1 participant