Files
KomediruzeckiandGitHub bbfe67d97a feat(import): saved sheet sources, daily cron sync, and email-in (#388)
* feat(import): saved sheet sources, daily cron sync, and email-in

Adds a "Connected Sources" foundation and three automation paths on top of the
existing import pipeline (parse -> map -> preview -> dedup -> execute), reusing
it rather than rebuilding.

Saved Google-Sheet sources
- New import_sources entity, profile-scoped, in both runtimes: D1 migration 0020
  + Worker CRUD routes, and idb v12 store + serverless handler + local router.
- Connected Sources UI on the Import page: save a published sheet once, then
  Auto sync (headless fetch -> apply saved mapping -> import only new; dedup is
  automatic) or Fetch & preview (reuses ImportPreviewStep in a modal). Two
  brand-styled buttons (SVG icons, no emoji).
- Column mapping is persisted BY HEADER NAME (shared/importMapping.ts) so it
  survives the sheet owner reordering columns; indices are re-resolved on fetch.
- Flow seams: fetchGoogleSheet({navigate:false}) + applySavedMapping.

Daily cron auto-sync
- A "Daily" toggle per source (self-hosted / cloud only). The existing daily
  cron (runScheduledSheetSyncs) fetches each daily sheet, resolves its mapping,
  and imports only new rows via the shared executeImport, logging the session.

Email-in via Cloudflare Email Routing
- A Worker email() handler: a statement forwarded to ingest+<secret>@<domain> is
  parsed (postal-mime), its CSV/XLSX attachments auto-mapped and imported into a
  configured profile with dedup. Secret-in-address auth + optional sender
  allowlist. Configured via EMAIL_INGEST_* env; disabled when unset.

Shared core
- Extracted executeImport() and fetchGoogleSheetRows() from the HTTP handlers so
  the routes, cron, and email handler share one insert+dedup engine (routes are
  now thin wrappers; existing behaviour unchanged).
- Moved the column-mapping definitions to shared/ so the Worker and frontend use
  the same field names, header variants, and auto-detection.

Docs: docs/plans/import-automation.md, bank-connectivity-and-encryption.md, and
import-automation-setup.md (daily-sync + email-in setup).

Tests: header-map round-trip, serverless source CRUD, email parseAttachment.
Frontend 848 + worker 227 green; typecheck, lint, prettier clean.

* fix(import): daily-sync records a session only when something imported
2026-07-27 18:14:05 +02:00
..