mirror of
https://github.com/Komediruzecki/token-circles.git
synced 2026-10-20 09:46:43 +02:00
* 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
23 lines
1.0 KiB
SQL
23 lines
1.0 KiB
SQL
-- Saved, reusable import origins ("Connected Sources"): a saved Google-Sheet link
|
|
-- (and, later, a Drive folder or bank-aggregator connection) that can be re-fetched
|
|
-- and imported on demand or on a schedule. config/mapping/category_types hold JSON.
|
|
-- The column mapping is persisted BY HEADER NAME (not column index) so it survives the
|
|
-- sheet owner reordering columns; indices are re-resolved at fetch time.
|
|
CREATE TABLE IF NOT EXISTS import_sources (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
profile_id INTEGER NOT NULL,
|
|
kind TEXT NOT NULL DEFAULT 'google_sheet',
|
|
label TEXT NOT NULL DEFAULT '',
|
|
config TEXT NOT NULL DEFAULT '{}',
|
|
mapping TEXT,
|
|
category_types TEXT,
|
|
default_account_id INTEGER,
|
|
schedule TEXT NOT NULL DEFAULT 'manual',
|
|
last_synced_at TEXT,
|
|
last_cursor TEXT,
|
|
created_at TEXT DEFAULT (datetime('now')),
|
|
updated_at TEXT DEFAULT (datetime('now')),
|
|
FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_import_sources_profile ON import_sources(profile_id);
|