n8n ingest swap: lead-intake & onboarding write to the DB

Both flows now POST into the smb-crm DB API instead of appending to Sheets, so
Postgres stays the source of truth and the DB->Sheets mirror keeps the Sheet
current. Telegram notifications unchanged.

- lead-intake: Webhook -> Build lead row -> POST /api/leads -> Telegram
  (dropped the direct Sheets append + the redundant activity-log nodes; the DB
  service logs + mirrors activity itself).
- onboarding: Webhook -> Compute -> POST /api/clients (DB assigns C-id) ->
  Build project w/ returned id -> POST /api/projects -> Telegram. DB computes
  renewal_date; go-live = start + 14d.
- Token injected at deploy time; repo keeps the __CRM_TOKEN__ placeholder.

Verified end-to-end on the live webhooks: lead and client+project land in the
DB and mirror to Sheets; test data cleaned; DB/Sheets consistent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 09:33:53 +02:00
parent e59996a385
commit d5a304ebe9
3 changed files with 94 additions and 469 deletions
+20 -13
View File
@@ -20,19 +20,24 @@ Implications to work through:
replace with something hosting-agnostic (e.g. `hosting = google | selfhosted`, `plan = …`).
- [ ] Onboarding form + workflow currently ask for Tier A/B — realign once the model is settled.
## Onboard dashboard → manage Leads & Clients (CRUD)
The operator onboarding page (https://onboard.mivanchenko.de) currently only **creates** records.
Extend it into a small back-office where I can **read, edit, delete and add** both Leads and
Clients directly:
- [ ] **Read:** pull and list the current `Leads` and `Clients` rows (via n8n webhook → Sheets
`values.get`, or Sheets API) in a clean table on the onboard page.
- [ ] **Add:** new Lead / new Client manually (Clients add already exists via the onboarding form;
add a lighter "new lead" form too).
- [ ] **Edit:** update a row in place (e.g. change a lead's status, fix a client's fee/renewal).
- [ ] **Delete:** cleanly remove a row (Sheets `deleteDimension`), so test/junk rows don't pile up
— replaces the current scratchpad `del_rows.py`/`del_lead.py` manual cleanup.
- [ ] Stays behind the existing Caddy basic-auth (operator-only; these are billable/CRM records).
- [ ] Needs new n8n webhooks (list/update/delete) keyed by `lead_id` / `client_id`.
## Onboard dashboard → manage Leads & Clients (CRUD) — DONE 2026-06-25
Built as a DB-first back-office (architecture pivot: **Postgres is the source of truth**, Sheets
is a one-way mirror — see `backoffice/` and the `smb-db-source-of-truth` memory). Live at
**onboard.mivanchenko.de/crm** behind the existing basic-auth.
- [x] **Read:** Leads & Clients tables, served by `smb-crm` straight from Postgres.
- [x] **Add:** "+ Neu" modal per entity; auto-IDs (C-#### / L-epoch), renewal auto-compute.
- [x] **Edit:** per-row ✎ modal, token-protected PATCH.
- [x] **Delete:** per-row 🗑 (token-protected), audit-logged — replaces the scratchpad cleanup.
- [x] Behind Caddy basic-auth; mutations gated by `CRM_API_TOKEN`; all changes audit-logged.
- [x] One-way **DB→Sheets mirror** keeps the Sheet overview current after every change.
- [x] **n8n ingest swap:** `lead-intake` & `onboarding` now POST into the DB API (not Sheets);
Telegram notify unchanged. `renewal-reminder` still reads Sheets (fine — Sheets mirrors DB).
Follow-ups (not yet done):
- [ ] Extend CRUD UI beyond Leads/Clients (projects, bookings, invoices, activity) if useful.
- [ ] Daily backup of the `smb-db` Postgres volume.
- [ ] Make the DB→Sheets overwrite atomic (currently clear-then-write; brief mid-write window a
reader could catch the cleared sheet — harmless for a human overview).
## Other
- [ ] Harden n8n auth: compose still has deprecated `N8N_BASIC_AUTH_*` with password `password`
@@ -49,3 +54,5 @@ Clients directly:
- [x] 2026-06-25 — Pizzeria demo with online ordering added.
- [x] 2026-06-25 — Barbershop "Google Kalender" dot-overlap styling fixed.
- [x] 2026-06-25 — All three demo pages neutralised (stack-agnostic, non-stale dates).
- [x] 2026-06-25 — DB-first back office: Postgres source of truth + Sheets mirror + CRUD + n8n
ingest swap (lead-intake/onboarding → DB API). Live at onboard.mivanchenko.de/crm.