Enable Banking: warn before the bank's permission runs out, and link again cleanly

- save when the permission ends (consent_until, migration 0032)
- Accounts warns two weeks ahead, says Needs attention once it ran out, and offers
  Link again; an expired or revoked session no longer shows a raw API error
- accounts and rows are keyed on identification_hash, which stays the same across
  links (the uid doesn't), so linking again adds no copies and keeps edits
- links made with the per-link uid move to the stable key on their next sync
- linking the same bank again replaces the old connection

Tested against the stand-in: first link, moving old IDs, linking again,
the warning and an expired permission.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MangaValkandClaude Opus 5.5 committed 2026-11-19 17:23:49 +01:00
1 parent 0a97ddbcae
commit 514b2aac77
8 files changed
+88 -15

No files matched your search

+16
View File
@@ -107,3 +107,19 @@ console.log("feeds: ok");
assert.equal(pemFrom(oneLine), rsa);
assert.ok(load(pemFrom(oneLine)));
}
// Permission that ran out: by date before calling, and when Enable Banking turns the session away (revoked early).
{
const env = { ENABLE_BANKING_APP_ID: "app", ENABLE_BANKING_PRIVATE_KEY: pem };
const acct = [{ uid: "u-new", identification_hash: "h-stable" }];
const past = JSON.stringify({ accounts: acct, valid_until: "2020-01-01T00:00:00Z" });
await assert.rejects(feedData("enablebanking", env, past, "2026-01-01", (() => { throw new Error("no call expected"); }) as typeof fetch), { code: "CONSENT_EXPIRED" });
const live = JSON.stringify({ accounts: acct, valid_until: "2999-01-01T00:00:00Z" });
const refused = (async () => new Response(JSON.stringify({ error: "EXPIRED_SESSION" }), { status: 401 })) as unknown as typeof fetch;
await assert.rejects(feedData("enablebanking", env, live, "2026-01-01", refused), { code: "CONSENT_EXPIRED" });
// The account and its rows are keyed on identification_hash, so a new link (new uid) updates the same ones.
const ok = (async (u: string) => new Response(JSON.stringify(String(u).includes("/balances") ? { balances: [] } : { transactions: [{ entry_reference: "r1", booking_date: "2026-11-02", transaction_amount: { amount: "1" }, credit_debit_indicator: "DBIT", status: "BOOK" }], continuation_key: null }))) as unknown as typeof fetch;
const r = await feedData("enablebanking", env, live, "2026-01-01", ok);
assert.equal(r.accounts[0].plaid_account_id, "enablebanking:h-stable");
assert.equal(r.txns[0].plaid_transaction_id, "enablebanking:h-stable:r1");
}