From dc1eeb47a27e2fed4f54f47e835596db7b07eee1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 2 Nov 2026 12:50:13 +0000 Subject: [PATCH] Fix a new browser database dropping card details, sample data flag and import pause (v1.16.5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When IndexedDB is created while localStorage still holds data, DB._migrateSync() copied a hand-written list of keys into app_state, and DB.loadAll() read a second list. cardDetails and sampleData (v1.16.0) and csvAutoImportPaused (v1.9.0) were only on the second, so they weren't copied and loadAll() reset them to their defaults. - db.js: DB.APP_STATE_KEYS, every app_state key with the default loadAll() uses. _migrateSync() copies those keys and loadAll() reads them, both under storageKey(). loadAll() loads the same keys with the same defaults as before. - CHANGELOG, version in the four places, CLAUDE.md §1, §4.5, §12, §19. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013Z8iBXzUjiQbYziDZ8CZft --- CHANGELOG.md | 19 +++++++++++ CLAUDE.md | 13 +++++--- README.md | 4 +-- index.html | 2 +- js/core.js | 4 +-- js/db.js | 76 +++++++++++++++++++++----------------------- js/views-settings.js | 2 +- 7 files changed, 70 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23788dc..1696f55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,25 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). --- +## [1.16.5] — 2026-11-02 + +### Fixed +- **A new browser database lost the card details, the sample-data flag and the import pause.** + - **When:** FinLens creates its IndexedDB database (`finlens_db`) while localStorage still holds your settings: `finlens_db` alone was deleted (for example from the browser's developer tools) and localStorage was kept. + - **Symptom:** after that boot, and every boot after it that read IndexedDB, the APR and due day under **Settings → Credit cards** were gone, though localStorage still held them. The sample-data flag and the import pause were reset too: after **Clear transactions & accounts**, a boot that didn't load `finlens-state.json` could import the folder's CSVs again. + - **Cause:** the new database is filled from localStorage by `DB._migrateSync()`, which had its own hand-written list of keys. `DB.loadAll()` reads a second list. When `cardDetails` and `sampleData` (v1.16.0) were added to the second list, they weren't added to the first, and neither was `csvAutoImportPaused` (v1.9.0). So they weren't copied, and `DB.loadAll()` then set them to their defaults, which win over the values `lsGet()` read at startup. `master` has the same gap for `csvAutoImportPaused`. + - **Fix:** one list, `DB.APP_STATE_KEYS` (`db.js`): each State key kept in `app_state` and the default `DB.loadAll()` uses when it's missing. `_migrateSync()` copies those keys and `DB.loadAll()` reads them, both under `storageKey()` (v1.16.4). A key added to the list is copied and loaded alike. + - **Lost before this fix?** Enter the card details again. + +### Unchanged +- **`DB.loadAll()` loads the same keys with the same defaults.** Its list moved to `DB.APP_STATE_KEYS` unchanged; `recurringConfirmed` and `categoryRules` still load from `recurring` and `catRules`. +- **A database that already exists isn't touched.** `_migrateSync()` runs only when the database is created. + +### Docs +- **CLAUDE.md** — §1 version; §4.5 the code that goes through `storageKey()`; §12 adding a persisted field (it said `lsGet` was all you needed; it also takes `DB.APP_STATE_KEYS`, the state file's list and §20); §19 `DB.APP_STATE_KEYS`. + +--- + ## [1.16.4] — 2026-11-02 ### Fixed diff --git a/CLAUDE.md b/CLAUDE.md index 963b2dd..cc1516c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,7 +59,7 @@ Until then, this section is the rule. FinLens is a **single-origin, zero-build, vanilla JavaScript personal finance dashboard** that runs entirely in the browser. There is no server, no npm, no bundler, no framework, and no TypeScript. The entry point is `index.html`; everything else is a plain `.js` file in the `js/` folder. -**Current version:** v1.16.4 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). +**Current version:** v1.16.5 (updated in `index.html` footer, `README.md`, and `CHANGELOG.md` on every release). **What it does:** Imports CSV exports from a bank (checking + savings) and credit cards, parses and normalizes them into a unified transaction model, and renders a multi-tab financial dashboard with budgeting, debt tracking, savings forecasting, investment planning, and Claude-powered AI analysis. @@ -320,7 +320,7 @@ loadStateFromFile() → found? - **Fallback chain** — If filesystem load fails, IndexedDB provides a session-local cache. If IndexedDB isn't available, localStorage defaults apply. - Always use `lsSet(key, value)` and `lsGet(key, default)` — **never** call `localStorage` directly. - The `finlens_` prefix is applied automatically by `lsSet`/`lsGet`. -- **Two keys have older storage names (v1.16.4).** Browser storage (localStorage and IndexedDB `app_state`) keeps `State.recurringConfirmed` as `recurring` and `State.categoryRules` as `catRules`; every other key is stored under its State name. `STORAGE_KEYS` / `storageKey(stateKey)` in `core.js` is the one mapping. Code that saves or loads keys by State name in a loop must go through it: JSON import, Data & reset's plan clears, `migrate.js`. Up to v1.16.3 the JSON import didn't, and its values were lost on reload. Don't rename the storage keys: existing data lives under them. `finlens-state.json` and JSON exports use State names. +- **Two keys have older storage names (v1.16.4).** Browser storage (localStorage and IndexedDB `app_state`) keeps `State.recurringConfirmed` as `recurring` and `State.categoryRules` as `catRules`; every other key is stored under its State name. `STORAGE_KEYS` / `storageKey(stateKey)` in `core.js` is the one mapping. Code that saves or loads keys by State name in a loop must go through it: JSON import, Data & reset's plan clears, `DB.loadAll()` and the new-database copy (`DB.APP_STATE_KEYS`, v1.16.5), `migrate.js`. Up to v1.16.3 the JSON import didn't, and its values were lost on reload. Don't rename the storage keys: existing data lives under them. `finlens-state.json` and JSON exports use State names. - Don't call `saveStateToFile()` directly in hot paths — it's meant to be debounced via `_saveStateDebounced()` in `lsSet()`. - **Never use transactions straight from JSON.** `JSON.parse` turns `date` into a string and freezes the `category` getter. `loadStateFromFile()` rebuilds them with `reconstituteTx()`, as `DB.loadAll()` does; any new code that reads transactions from JSON must do the same. - **IndexedDB may not hold the loaded transactions.** After a boot or restore from `finlens-state.json` (a new browser, cleared site data, `_restoreStateIfBrowserEmpty()`), the `transactions` store can be empty or hold only some of them. Code that changes the loaded transactions works from `State.transactions`, never by replacing them with the store's rows: a store row may only fill in a value a transaction lacks. Up to v1.16.0, Clear transaction edits replaced them and wiped every transaction (§20). @@ -784,7 +784,10 @@ el.innerHTML = ``; ### Adding a new persisted field 1. Add the field to `State` with `lsGet('myKey', defaultValue)`. Use the State name as the storage key; only the two older keys in `STORAGE_KEYS` differ (§4.5). -2. That's it — `lsSet` automatically mirrors to IndexedDB `app_state` and localStorage. +2. `lsSet` mirrors it to IndexedDB `app_state` and localStorage. +3. Add it to `DB.APP_STATE_KEYS` (`db.js`), with the default `DB.loadAll()` uses when it's missing. A new database copies the same keys from localStorage (v1.16.5). +4. Add it to `saveStateToFile()`'s list, unless it's browser-only like `csvAutoImportPaused` (§20). Never the API key. +5. Update §20, so Start over and the clean-up actions cover it. ### App Bar Navigation (v1.13.0) @@ -987,7 +990,7 @@ Multiple credit card files can be loaded simultaneously. Each gets a unique `acc --- -*Last updated: v1.16.4 — 2026-11-02 (JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* +*Last updated: v1.16.5 — 2026-11-02 (a new database copies every saved setting: §4.5 the keys that go through `storageKey()`; §12 adding a persisted field; §19 `DB.APP_STATE_KEYS`; v1.16.4: JSON import saves under the storage keys: §4.5 `STORAGE_KEYS` / `storageKey()`; §8 `storageKey()`; §12 adding a persisted field uses the State name; v1.16.3: An import keeps the loaded transactions it doesn't replace: §4.5 an import never drops loaded transactions; §8 `mergeImported()`, `undoTransferDetection()`; §10 memory follows the same re-upload rules; §11 kept transfers are detected again; v1.16.2: Imports read every file before changing anything: §8 `loadFiles()` options and result, `parseCsvFile()` reads only, `importParsedCsv()`, `importProblemText()`, `reloadFromDirHandle()`; §20 Rebuild from your folder reads before it clears, read before clearing; v1.16.1: Clear transaction edits works from memory: §4.2 `_originalCategories`, `_originalType` and what a transaction keeps of its row; §4.5 IndexedDB may not hold the loaded transactions; §10 a stored row holds the CSV's values; §20 Clear transaction edits; v1.16.0: Trends, AI Analysis, Settings and the Welcome rebuilt: §3 file roles; §4.1 `cardDetails`, `sampleData`, AI history `model`; §6 tile tokens and Insights/Settings/Welcome components; §7 rule 7 covers Trends; §8 `loadFiles()` sample option; §9 `shellHero()`, `NO_RANGE_VIEWS`, ☰ → ×, JSON export/import buttons; §12 Settings tabs renamed, the Welcome, range label hidden on Trends and Settings; §13 quick analyses, tab state, history; §20 new fields, Use my own files, Export/Import JSON; §21 quick analyses send `AI_PROMPTS`; v1.15.0: Plan screens rebuilt: §3 file roles; §4.1 `debtPlan` and the Budget / Bucket / Debt / Scenario shapes; §6 `--teal-text` and Plan components; §7 rule 7 covers the Plan charts; §8 plan helpers (`payoffPlan()`, `growthByYear()` …); §9 plan form helpers, `simulatePayoff()` kept unused; §12 Plan titles, Forecast tabs, range label hidden on Plan screens; §13 debt balances in the summary; §20 Clear forecast scenarios / investment mix, Clear debts resets `debtPlan`; v1.14.0: Finances screens rebuilt: §4.1 Bill shape and `recurringConfirmed`; §6 new tokens and Finances components; §7 rule 7 inline SVG charts; §8 new aggregation helpers; §9 drawer, `TX_VIEWS`, SVG/heatmap/format helpers, bill helpers, removed renderers; §11 keywords re-run detection, `transferPairs()`, card payments; §12 page actions and Transactions pills; §20 Clear bills also clears spotted-charge choices; v1.13.0: Clarity redesign — §6 tokens and components; §9 theme, chart colors and app bar helpers; §12 app bar navigation replaces the sidebar and the emoji rule; §17 footer; §20 Data & Reset; v1.12.0: bank-neutral account codes, names, samples and docs; §22 `migrate.js` added; §3, §4, §5, §10, §18, §21 updated; v1.10.2: §13 summary states its dates; §21 per-month derivations; v1.10.1: §13 `AI_MAX_TOKENS`, thinking and cut-off answers; v1.10.0: §21 AI Eval added; §13 `callClaude()` raw mode; v1.9.6: §14 folder access lasts until the last tab closes, not one page load; v1.9.5: §7 chart guard; v1.9.4: views-db.js changelog reads CRLF checkouts; v1.9.3: §14 folder permission: re-request on click, Reconnect banner, browser copy wins; v1.9.2: §0 branch, PR and approval workflow added; v1.9.1: §4.5 rehydrate transactions loaded from JSON; v1.9.0: §20 Data & Reset added; v1.8.1: §10 re-upload dedup rewritten for the occurrence-suffix fix; v1.8.0: AI Analysis restored with API-key and output hardening; `renderMarkdown()` added; `samples/` added; §1–3, §13, §14, §17 corrected to match the code)* --- @@ -998,7 +1001,7 @@ The full IndexedDB implementation is live. See **`docs/archive/INDEXEDDB_PLAN.md ### What changed - **`js/db.js`** — new file, loaded after `core.js`. Exposes the `DB` object and `reconstituteTx()` helper. - **`DB.open()`** — opens `finlens_db` v1, creates all 5 object stores, migrates `localStorage → app_state` on first run. -- **`DB.loadAll()`** — called at boot in `init.js`. Restores all State from IndexedDB (including transactions). Users do not need to re-upload CSVs after a page refresh. +- **`DB.loadAll()`** — called at boot in `init.js`. Restores all State from IndexedDB (including transactions). Users do not need to re-upload CSVs after a page refresh. The State keys it reads, and their defaults, are `DB.APP_STATE_KEYS`, each under `storageKey()` (v1.16.5). A new database copies the same keys from localStorage (`_migrateSync()`). - **`lsSet(k, v)`** — now also calls `DB.setState(k, v)` fire-and-forget when DB is ready. All existing `lsSet` call sites work unchanged. - **`State.transactions`** remains the in-memory working array. All views use `filteredTx()` unchanged. - **Bank Schema Registry** — `BANK_SCHEMAS` (global in `core.js`) drives CSV parsing. `detectSchema()` + `normalizeRow()` replace the old hardcoded normalizers. diff --git a/README.md b/README.md index 168bc06..8274d14 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ > A zero-install, browser-native finance dashboard. Drop in your bank CSVs, get instant clarity on your money. -**Version:** v1.16.4  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None +**Version:** v1.16.5  ·  **Stack:** Vanilla JS, HTML, CSS  ·  **Install:** None --- @@ -263,4 +263,4 @@ See [CHANGELOG.md](CHANGELOG.md) for the full release history. --- -*FinLens v1.16.4 — Built for one person's finances, designed to be useful for anyone's.* +*FinLens v1.16.5 — Built for one person's finances, designed to be useful for anyone's.* diff --git a/index.html b/index.html index 80f81e2..2156717 100644 --- a/index.html +++ b/index.html @@ -1202,7 +1202,7 @@
-
v1.16.4 · FinLens
+
v1.16.5 · FinLens
diff --git a/js/core.js b/js/core.js index 8b14f1b..e4344ec 100644 --- a/js/core.js +++ b/js/core.js @@ -41,8 +41,8 @@ const lsClearAll = () => { // Browser storage (lsSet/lsGet and IndexedDB app_state) keeps two State keys under older // names; every other key is stored under its State name. Existing data lives under these // names, so they stay. Code that saves or loads a key by its State name (JSON import, -// Data & reset, migrate.js) goes through storageKey(). finlens-state.json and JSON -// exports use State names. +// Data & reset, DB.loadAll() and the new-database copy, migrate.js) goes through +// storageKey(). finlens-state.json and JSON exports use State names. const STORAGE_KEYS = { recurringConfirmed: 'recurring', categoryRules: 'catRules' }; const storageKey = (stateKey) => STORAGE_KEYS[stateKey] || stateKey; const debounce = (fn, ms=300) => { let t; return (...a)=>{ clearTimeout(t); t=setTimeout(()=>fn(...a),ms); }; }; diff --git a/js/db.js b/js/db.js index 85d7189..c2651fc 100644 --- a/js/db.js +++ b/js/db.js @@ -41,6 +41,37 @@ const DB = { DB_NAME: 'finlens_db', DB_VERSION: 1, + // Every State key kept in app_state, with the value loadAll() uses when the store has + // none (null: keep what State already has). Each is stored under storageKey(stateKey) + // (core.js). A new database copies the same keys from localStorage (_migrateSync). + APP_STATE_KEYS: [ + ['budgets', []], + ['buckets', []], + ['debts', []], + ['bills', []], + ['recurringConfirmed', {}], // stored as 'recurring' + ['txOverrides', {}], + ['manualBalances', {}], + ['categoryRules', []], // stored as 'catRules' + ['categories', null], + ['apiKey', ''], + ['aiHistory', []], + ['scenarios', []], + ['investAlloc', {}], + ['debtPlan', null], + ['cardDetails', {}], + ['sampleData', false], + ['fileAssignments', {}], + ['lastFolderName', ''], + ['theme', 'light'], + ['accountOrder', []], + ['accountLabels', {}], + ['txRules', []], + ['transferKeywords', null], + ['customSchemas', []], + ['csvAutoImportPaused', false], + ], + /* ── Internal helpers ────────────────────────────────────────── */ _req(req) { return new Promise((res, rej) => { @@ -116,14 +147,10 @@ const DB = { }, /* Called inside onupgradeneeded — must be sync (uses the upgrade transaction) */ + // Copies every app_state key from localStorage. The list used to be written out here + // and missed cardDetails, sampleData and csvAutoImportPaused, which loadAll() then reset. _migrateSync(appStateStore) { - const LS_KEYS = [ - 'budgets','buckets','debts','bills','recurring','txOverrides','manualBalances', - 'catRules','categories','apiKey','aiHistory','scenarios','investAlloc','debtPlan', - 'fileAssignments','lastFolderName','theme','accountOrder','accountLabels', - 'txRules','transferKeywords','customSchemas', - ]; - for (const k of LS_KEYS) { + for (const k of this.APP_STATE_KEYS.map(([stateKey]) => storageKey(stateKey))) { try { const raw = localStorage.getItem('finlens_' + k); if (raw !== null) { @@ -315,38 +342,9 @@ const DB = { async loadAll() { if (!this._db) return; - // ── 1. Load app_state into State ── - const appStateMap = [ - // [stateKey, dbKey, default] - ['budgets', 'budgets', []], - ['buckets', 'buckets', []], - ['debts', 'debts', []], - ['bills', 'bills', []], - ['recurringConfirmed', 'recurring', {}], - ['txOverrides', 'txOverrides', {}], - ['manualBalances', 'manualBalances', {}], - ['categoryRules', 'catRules', []], - ['categories', 'categories', null], - ['apiKey', 'apiKey', ''], - ['aiHistory', 'aiHistory', []], - ['scenarios', 'scenarios', []], - ['investAlloc', 'investAlloc', {}], - ['debtPlan', 'debtPlan', null], - ['cardDetails', 'cardDetails', {}], - ['sampleData', 'sampleData', false], - ['fileAssignments', 'fileAssignments', {}], - ['lastFolderName', 'lastFolderName', ''], - ['theme', 'theme', 'light'], - ['accountOrder', 'accountOrder', []], - ['accountLabels', 'accountLabels', {}], - ['txRules', 'txRules', []], - ['transferKeywords', 'transferKeywords', null], - ['customSchemas', 'customSchemas', []], - ['csvAutoImportPaused','csvAutoImportPaused', false], - ]; - - for (const [stateKey, dbKey, def] of appStateMap) { - const val = await this.getState(dbKey, def); + // ── 1. Load app_state into State (APP_STATE_KEYS, each under its storage key) ── + for (const [stateKey, def] of this.APP_STATE_KEYS) { + const val = await this.getState(storageKey(stateKey), def); if (val !== null && val !== undefined) State[stateKey] = val; } diff --git a/js/views-settings.js b/js/views-settings.js index 7db2d6b..6139b6a 100644 --- a/js/views-settings.js +++ b/js/views-settings.js @@ -67,7 +67,7 @@ function _renderGeneralSettings(root) { ``).join('')} -
VersionFinLens v1.16.4
+
VersionFinLens v1.16.5
`); const opts=$$('[data-theme-opt]',root); opts.forEach((b,i)=>{