Files
token-circles/worker/package.json
T
KomediruzeckiandGitHub aed6150007 fix(retirement): explain the withdrawal rate, reload on profile switch, and diagnose the dev sign-in (#409)
* fix(retirement): explain the withdrawal rate, and reload on a profile switch

The withdrawal rate is not a bug, but nothing on the page said so. Raising it from
4% to 12% moved the date from age 52 to age 36 and dropped the target from
300,000 to 100,000, which reads as a free lunch. It is arithmetic: the target is
annual spending divided by the rate, so claiming a bigger slice each year means
needing a smaller pot. What was missing is the other half — at 12% against a
4.39% real return the pot is empty after about eleven years. The field now works
that out (yearsOfWithdrawals, closed form, P cancels) and says it, in a warning
tone when the rate outruns the return.

Switching profile did not reload the page. Pages stay mounted under the
keep-alive host (#317) — hidden with CSS, not unmounted — so an onMount loader
fires once for the whole session, and the panel kept showing the previous
profile's plan until the page was reloaded by hand. The retirement goals list,
the planner and the emergency-fund calculator now go through refetchOnActive, and
the import page tracks profileVersion alongside its revisit reload. Settings is
deliberately left alone: its onMount writes the local currency INTO the profile,
so re-running it on a switch would relabel the new profile's amounts.

Advanced mode squeezed four selects, an amount and a button into a 360px rail, so
no month name was visible at all. The rail is 440px and an editable row wraps
rather than shrinking; the chart column still takes the larger share (784px
against 440px at 1600px wide). Measured at nine widths from 1920 down to 375: no
clipping, no horizontal overflow.

Return and inflation sat on different lines whenever "Expected annual return (%)"
wrapped and "Inflation (%)" did not. The row bottom-aligns its groups now.

Also, the sign-in failure on dev. A Turnstile site key pairs with exactly one
secret. 62598e6 (2026-06-30) changed dev's site key from 0x4AAAAAADoNlUQIGinFGTZv
to 0x4AAAAAADtAZsLABBBY6Rqe; prod was given that same key later and its secret
matches, which is why prod works. The dev worker's TURNSTILE_SECRET still belongs
to the old widget, so every token is minted by one widget and verified against
another: green in the browser, 403 from the API, and a message blaming the
captcha. Nothing removed the secret — the key moved out from under it.

Cloudflare names this exactly, as invalid-input-secret, and the code was throwing
the error codes away. It now reads them, logs them, and answers 503 with "the
captcha secret does not match the site key" instead of a 403 that invites a
retry which cannot work. /api/health reports whether the gate is configured, so a
deploy can be checked without attempting a sign-in, and secret:{dev,prod} now
includes TURNSTILE_SECRET — it never did, which is how one environment ended up
without it.

The fix itself is operational and not in this diff:
  cd worker && npx wrangler secret put TURNSTILE_SECRET --env dev
with the secret for widget 0x4AAAAAADtAZsLABBBY6Rqe.

Tests: 1162 frontend, 328 worker. The withdrawal-rate suite reproduces the
reported plan to the cent and pins the direction as intentional; the
profile-switch tests fail against the old onMount exactly as reported.

* fix(worker): correct the captcha diagnosis — dev had no secret at all

Setting it settled which of the two failure modes it was: wrangler said
"Creating the secret for the Worker finance-manager-api-dev", not updating one.
So dev's TURNSTILE_SECRET was absent rather than pointing at the old widget, and
the worker had been taking its fail-closed branch on every password sign-in
since 5caef64 (2026-06-30) switched the dev widget on.

The distinction does not change the code — a missing secret and a rejected one
are both reported now, with different messages — but the comment claimed the
wrong one, and a wrong story in a test is worse than no story.

Both environments now carry the secret, confirmed with `wrangler secret list`.

* fix(backend): serve /api/retirement/settings so the page stops 404ing

The planner asks for saved assumptions on every visit to the retirement page,
unconditionally. They are a Worker feature and this server had no route for
them, so every visit against the legacy backend was a guaranteed 404 — a console
error on a page that otherwise works.

It surfaced as a flake rather than a failure because page-loading.spec.ts
attaches its console listener after login and navigation and samples a short
window; whether it caught the 404 depended on timing. Moving the load from
onMount to refetchOnActive shifted the request into that window, so the spec
began failing every run. The fault was always there — only the detection was
intermittent. Same shape as /api/import-sources in #407.

Deliberately stores no defaults. An empty object is the honest answer when
nothing has been saved, and the client's normalizeSettings() fills in every
field; restating DEFAULT_SETTINGS here would be a second copy of
shared/retirementSettings.ts with nothing keeping it in step. `filled` and
`missing` describe values derived from the user's own data, which this server
does not compute, so empty is accurate rather than a placeholder.

PUT is implemented too, keyed per profile, so saving works instead of failing
against a route that only reads.

Six tests: the empty answer, the envelope shape the planner destructures, auth,
a store/read round trip, per-profile isolation, and an unparseable stored blob
falling back to defaults rather than 500ing the page.

Verified live: GET before any save returns {} with a well-formed startMonth, PUT
round-trips, profile 1 does not see profile 3's plan, and unauthenticated is 401.
2026-08-23 12:03:07 +02:00

48 lines
1.9 KiB
JSON

{
"name": "finance-manager-worker",
"private": true,
"type": "module",
"description": "Cloudflare Worker + D1 API scaffold for Finance Manager (preparation; not yet live).",
"license": "AGPL-3.0-only",
"scripts": {
"dev": "wrangler dev",
"deploy:dev": "wrangler deploy --env dev",
"deploy:prod": "wrangler deploy --env prod",
"d1:create:dev": "wrangler d1 create finance-manager-dev",
"d1:create:prod": "wrangler d1 create finance-manager",
"d1:migrate:local": "wrangler d1 migrations apply finance-manager --local",
"d1:migrate:dev": "wrangler d1 migrations apply finance-manager-dev --remote --env dev",
"d1:migrate:prod": "wrangler d1 migrations apply finance-manager --remote --env prod",
"d1:exec:local": "wrangler d1 execute finance-manager --local --command",
"r2:create:dev": "wrangler r2 bucket create finance-manager-receipts-dev",
"r2:create:prod": "wrangler r2 bucket create finance-manager-receipts",
"secret:dev": "wrangler secret put JWT_SECRET --env dev && wrangler secret put GOOGLE_CLIENT_SECRET --env dev && wrangler secret put TURNSTILE_SECRET --env dev",
"secret:prod": "wrangler secret put JWT_SECRET --env prod && wrangler secret put GOOGLE_CLIENT_SECRET --env prod && wrangler secret put TURNSTILE_SECRET --env prod",
"typecheck": "tsc --noEmit",
"cf-typegen": "wrangler types",
"test": "vitest run",
"test:watch": "vitest"
},
"dependencies": {
"hono": "^4.6.0",
"pdf-lib": "^1.17.1",
"postal-mime": "^2.7.5",
"xlsx": "file:../vendor/xlsx-0.20.3.tgz",
"zod": "^4.4.3"
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "0.17.0",
"@cloudflare/workers-types": "^4.20241127.0",
"typescript": "^5.7.2",
"vitest": "4.1.9",
"wrangler": "^4.0.0"
},
"pnpm": {
"onlyBuiltDependencies": [
"workerd",
"@cloudflare/workerd-linux-64",
"esbuild"
]
}
}