* fix(enable-banking): stop reading every ASPSP_ERROR as a too-wide window (#2202) ASPSP_ERROR is Enable Banking's generic wrapper for any upstream bank failure, so "history window beyond the PSD2 limit" and "the bank is refusing right now" arrived as the same string, and every rejection walked the whole 90/60/30 narrowing ladder: one user click cost up to five upstream calls against a bank that was already saying no, the failure surfaced with "förnya anslutningen" advice that fixes nothing, and a sync that did narrow was reported as complete. What the account has accepted before is the signal that tells the two apart. sync.ts now records the widest window (days before date_to) each account's bank has answered, on accounts_data as accepted_history_days (no migration; persisted by the same write-back as dedup_scope). On a rejected window: no wider than that = the bank is unavailable, stop after one call; wider = one retry straight at the accepted width, then stop. Without a record (first sync, legacy rows) the ladder runs as before, but its exhaustion is now AspspUnavailableError too. The web sync route maps that to 503 BANK_UNAVAILABLE with copy that says the connection does not need renewing and leaves the row alone; the agent path keeps the contract code BANK_SYNC_FAILED but no longer persists renewal advice. getAllTransactionsWithRaw returns the requested and the effective date_from plus a narrowed flag; the sync result and the /sync response carry them (history_from), and the settings toast says from which date the history is complete when the bank cut the window. Not done: a per-account backoff for the user-triggered route (the agent path already has the 15-minute lease from #2165), and using the envelope's `detail` field (one sample, identical to a width rejection). Closes #2202 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VnConrmMCxJRQ5kfiPPWyy * docs(decisions): carry the batch's decision lines (#2237, #2203, #2214) here --------- Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
40 lines
1.5 KiB
TypeScript
40 lines
1.5 KiB
TypeScript
/**
|
|
* Day arithmetic for the transactions history window (date_from .. date_to,
|
|
* both YYYY-MM-DD, evaluated in UTC).
|
|
*
|
|
* Shared by api-client.ts (the narrowing ladder) and sync.ts (recording the
|
|
* widest window a bank has accepted for an account, issue #2202). It lives in
|
|
* its own module because sync.test.ts mocks api-client wholesale: a helper
|
|
* exported from there would be undefined under test.
|
|
*/
|
|
const DAY_MS = 24 * 60 * 60 * 1000
|
|
|
|
function parseUtcDay(value: string | undefined): number | undefined {
|
|
if (!value) return undefined
|
|
const t = new Date(`${value}T00:00:00Z`).getTime()
|
|
return Number.isFinite(t) ? t : undefined
|
|
}
|
|
|
|
/**
|
|
* Whole days from dateFrom to dateTo. Undefined when either end is missing or
|
|
* unparseable, or when the window is negative: callers treat undefined as
|
|
* "no width known", never as 0.
|
|
*/
|
|
export function historyWindowDays(
|
|
dateFrom: string | undefined,
|
|
dateTo: string | undefined
|
|
): number | undefined {
|
|
const from = parseUtcDay(dateFrom)
|
|
const to = parseUtcDay(dateTo)
|
|
if (from === undefined || to === undefined) return undefined
|
|
const days = Math.round((to - from) / DAY_MS)
|
|
return days >= 0 ? days : undefined
|
|
}
|
|
|
|
/** The YYYY-MM-DD that lies `days` days before dateTo; undefined when dateTo is unparseable. */
|
|
export function dateFromDaysBefore(dateTo: string | undefined, days: number): string | undefined {
|
|
const to = parseUtcDay(dateTo)
|
|
if (to === undefined) return undefined
|
|
return new Date(to - days * DAY_MS).toISOString().split('T')[0]
|
|
}
|