diff --git a/.gitignore b/.gitignore
index 98066dc..6dbcd7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ appdata//
data/
*.log
.DS_Store
+dev-harness.mjs
diff --git a/db/migrations/002_account.sql b/db/migrations/002_account.sql
new file mode 100644
index 0000000..a7b8e78
--- /dev/null
+++ b/db/migrations/002_account.sql
@@ -0,0 +1,8 @@
+-- Additive only: existing users/sessions/roast_plans rows and columns are untouched.
+CREATE TABLE password_reset_tokens (token_hash text PRIMARY KEY, user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE, expires_at timestamptz NOT NULL, created_at timestamptz NOT NULL DEFAULT now());
+ALTER TABLE users ADD COLUMN disabled_at timestamptz;
+ALTER TABLE sessions ADD COLUMN user_agent text, ADD COLUMN ip text, ADD COLUMN last_seen_at timestamptz;
+CREATE TABLE audit_events (id uuid PRIMARY KEY DEFAULT gen_random_uuid(), actor_user_id uuid REFERENCES users(id) ON DELETE SET NULL, action text NOT NULL, target text, created_at timestamptz NOT NULL DEFAULT now());
+CREATE INDEX audit_events_created ON audit_events(created_at DESC);
+CREATE INDEX sessions_user_id ON sessions(user_id);
+CREATE INDEX password_reset_tokens_user_id ON password_reset_tokens(user_id);
diff --git a/db/migrations/003_inventory_cupping.sql b/db/migrations/003_inventory_cupping.sql
new file mode 100644
index 0000000..cf82204
--- /dev/null
+++ b/db/migrations/003_inventory_cupping.sql
@@ -0,0 +1,45 @@
+-- Additive only: existing tables, rows, and columns are untouched.
+CREATE TABLE green_bean_lots (
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
+ user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ origin text NOT NULL,
+ variety text NOT NULL DEFAULT '',
+ process text NOT NULL DEFAULT '',
+ producer text NOT NULL DEFAULT '',
+ purchase_date date,
+ initial_weight_g numeric NOT NULL,
+ remaining_weight_g numeric NOT NULL,
+ cost_total numeric,
+ moisture_pct numeric,
+ density_g_l numeric,
+ notes text NOT NULL DEFAULT '',
+ archived boolean NOT NULL DEFAULT false,
+ created_at timestamptz NOT NULL DEFAULT now(),
+ updated_at timestamptz NOT NULL DEFAULT now()
+);
+CREATE TABLE bean_consumption (
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
+ lot_id uuid NOT NULL REFERENCES green_bean_lots(id) ON DELETE CASCADE,
+ user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ roast_plan_id uuid REFERENCES roast_plans(id) ON DELETE SET NULL,
+ weight_g numeric NOT NULL CHECK (weight_g > 0),
+ created_at timestamptz NOT NULL DEFAULT now()
+);
+-- One draw-down per roast plan, ever (NULLs are distinct in Postgres, so plan-less manual
+-- entries remain unlimited). This is the server-side backstop that makes the client's
+-- "Draw from lot" button idempotent even if clicked twice or from two devices.
+CREATE UNIQUE INDEX bean_consumption_one_per_plan ON bean_consumption(roast_plan_id);
+CREATE TABLE cupping_sessions (
+ id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
+ user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+ roast_plan_id uuid REFERENCES roast_plans(id) ON DELETE SET NULL,
+ data jsonb NOT NULL,
+ total_score numeric NOT NULL DEFAULT 0,
+ created_at timestamptz NOT NULL DEFAULT now(),
+ updated_at timestamptz NOT NULL DEFAULT now()
+);
+CREATE INDEX green_bean_lots_user ON green_bean_lots(user_id, archived, purchase_date DESC);
+CREATE INDEX bean_consumption_lot ON bean_consumption(lot_id, created_at DESC);
+CREATE INDEX bean_consumption_user ON bean_consumption(user_id);
+CREATE INDEX cupping_sessions_user ON cupping_sessions(user_id, updated_at DESC);
+CREATE INDEX cupping_sessions_plan ON cupping_sessions(roast_plan_id);
diff --git a/package-lock.json b/package-lock.json
index 4aaed8b..85266e6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,7 @@
"@earendil-works/pi-coding-agent": "^0.83.0",
"bcryptjs": "^3.0.3",
"express": "^5.0.1",
+ "nodemailer": "^9.0.3",
"pg": "^8.22.0"
},
"devDependencies": {
@@ -2745,6 +2746,15 @@
"node": ">= 0.6"
}
},
+ "node_modules/nodemailer": {
+ "version": "9.0.3",
+ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-9.0.3.tgz",
+ "integrity": "sha512-n+YP+NKwR5zRWa60k3GiQ6Q3B4KXCoAw40dAKeCtYn020iNN74aWK2liXIC3ZEATeGql7we3tE3t8QwhY0eskw==",
+ "license": "MIT-0",
+ "engines": {
+ "node": ">=6.0.0"
+ }
+ },
"node_modules/object-hash": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.2.0.tgz",
diff --git a/package.json b/package.json
index 068d3fd..0c771c0 100644
--- a/package.json
+++ b/package.json
@@ -13,6 +13,7 @@
"@earendil-works/pi-coding-agent": "^0.83.0",
"bcryptjs": "^3.0.3",
"express": "^5.0.1",
+ "nodemailer": "^9.0.3",
"pg": "^8.22.0"
},
"devDependencies": {
diff --git a/public/account.html b/public/account.html
new file mode 100644
index 0000000..d4c32cc
--- /dev/null
+++ b/public/account.html
@@ -0,0 +1,259 @@
+
+
+
+
+
+ Account — Roast Planner
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Profile
+
+
+
+
+ Admin
+
+
+
Change email
+
+
+
+
+
+
+
Security
+
+
+
Change password
+
+
Active sessions
+
+
+
+
+ | Device |
+ Last seen |
+ Expires |
+ |
+
+
+
+
+
+
+
+
+
+
+
+
Your plans
+
+
+
+
+
+
+ | Title |
+ Updated |
+ |
+
+
+
+
+
+
+
+
+
+
+
App
+
+
+
+ Install Roast Planner for a focused, offline-capable
+ workspace. Updates wait for your confirmation so an
+ in-progress plan is never discarded.
+
+
+
+
+
+
+
+
+
Danger zone
+
+
+
+ Deleting your account permanently removes your plans and
+ cannot be undone.
+
+
+
+
+
+
+
+
+
+
diff --git a/public/admin.html b/public/admin.html
index 6e5b29c..308b010 100644
--- a/public/admin.html
+++ b/public/admin.html
@@ -3,22 +3,200 @@
- Roast Planner Admin
+ Admin — Roast Planner
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+ Pending password resets
+
+
+ No outgoing email is configured for this deployment
+ (SMTP_URL). Hand these links to the user
+ directly.
+
+
+
+
+
+ | Email |
+ Link |
+ Expires |
+
+
+
+
+
+
+
+
+
+
+
+
+
Users
+
+
+
+
+
+
+
+ | Email |
+ Role |
+ Status |
+ Plans |
+ Joined |
+ |
+
+
+
+
+
+
+
+
+
+
+
Roast plans
+
+
+
+
+
+
+
+ | Owner |
+ Title |
+ Updated |
+
+
+
+
+
+
+
+
+
+ Recent activity
+
+
+
+
+
+ | When |
+ Actor |
+ Action |
+ Target |
+
+
+
+
+
+
+
+
+
+