mantenimento-app 2.2.9 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,70 +33,133 @@ npm run dev
33
33
  3. Apri:
34
34
 
35
35
  ```text
36
- http://localhost:3001
36
+ http://localhost:3000
37
37
  ```
38
38
 
39
- ## Puntare GitHub Pages a un backend dev separato
39
+ ## Build frontend minificato
40
+
41
+ ```bash
42
+ npm run build:frontend
43
+ ```
44
+
45
+ Il server serve automaticamente `app.min.js` se presente, altrimenti `app.js`.
46
+
47
+ ## Avvio produzione locale
48
+
49
+ ```bash
50
+ npm start
51
+ ```
52
+
53
+ `npm start` esegue build frontend + avvio server.
40
54
 
41
- Il frontend gia supporta un endpoint backend esplicitamente configurato.
42
- Per usare `https://favagit.github.io/mantenimento-app/` contro un backend dev reale:
55
+ ## Endpoint backend
56
+ - `POST /api/calculate`: calcolo modello mantenimento server-side; il payload transita su HTTPS/TLS in produzione e la risposta applica header `Cache-Control: no-store`
57
+ - `GET /api/health`: health check
58
+
59
+ Parametri server utili:
60
+ - `CALCULATE_RATE_WINDOW_MS`: finestra del rate limit per `/api/calculate` (default `60000`)
61
+ - `CALCULATE_RATE_MAX_REQUESTS`: massimo richieste per IP nella finestra (default `30`)
62
+ - `ACCESS_LOG_ENABLED`: abilita log strutturati minimizzati, attivo di default in produzione
63
+ - `ACCESS_LOG_SALT`: sale usato per anonimizzare il riferimento client nei log applicativi
64
+ - payload JSON in ingresso limitato a `64kb`
65
+
66
+ ### URL login sicuro (token monouso)
67
+ Per evitare credenziali in chiaro nel link, e disponibile un flusso `authToken` firmato server-side.
68
+
69
+ Variabili ambiente backend richieste:
70
+ - `AUTH_URL_LOGIN_SECRET`: segreto HMAC (lungo e casuale)
71
+ - `AUTH_URL_LOGIN_ALLOWED_USER`: utenti consentiti (separati da virgola, es. `favagit,fabio.vacchino`)
72
+ - `AUTH_URL_LOGIN_SUPABASE_URL`: URL progetto Supabase
73
+ - `AUTH_URL_LOGIN_SUPABASE_ANON_KEY`: anon key Supabase
74
+ - `AUTH_URL_LOGIN_SUPABASE_SERVICE_ROLE_KEY`: service-role key (necessaria per risolvere email automaticamente da `sub`)
75
+ - `AUTH_URL_LOGIN_SUPABASE_EMAIL`: email account da autenticare via URL token
76
+ - `AUTH_URL_LOGIN_SUPABASE_PASSWORD`: password account da autenticare via URL token
77
+ - `AUTH_URL_LOGIN_SUPABASE_USERS_JSON`: mappa opzionale `sub -> {password}` (email risolta automaticamente da Supabase) oppure `sub -> {email,password}`
78
+ - `AUTH_URL_LOGIN_MAX_TTL_SEC`: TTL massimo token (default `180`)
79
+ - `AUTH_URL_LOGIN_BOOTSTRAP_KEY`: chiave per avviare autologin server-side senza shell
80
+ - `AUTH_URL_LOGIN_FRONTEND_BASE`: URL frontend di destinazione (default `https://favagit.github.io/mantenimento-app/autologin.html`)
81
+ - `API_ALLOWED_ORIGINS`: origini consentite per API cross-origin (es. `https://favagit.github.io`)
82
+
83
+ Generazione token e link:
84
+
85
+ ```bash
86
+ npm run auth:url-token -- --sub=favagit --ttl=120 --baseUrl=https://favagit.github.io/mantenimento-app/
87
+ ```
43
88
 
44
- 1. Pubblica il backend dev su un host HTTPS raggiungibile pubblicamente.
45
- Esempio: `https://dev-api.example.com`
46
- 2. Nel backend dev abilita CORS verso GitHub Pages:
89
+ Entry point dedicato per URL autologin:
47
90
 
48
- ```env
49
- CORS_ALLOWED_ORIGINS=https://favagit.github.io
91
+ ```text
92
+ https://favagit.github.io/mantenimento-app/autologin.html?authToken=...
50
93
  ```
51
94
 
52
- 3. Apri GitHub Pages con l'override runtime dell'API base:
95
+ La pagina `autologin.html` reindirizza automaticamente su `index` aggiungendo `autologin=1`.
96
+ Supporta anche token nel fragment/hash (es. `.../autologin.html#authToken=...`) per ridurre esposizione nei log intermedi.
97
+
98
+ Il comando stampa un link del tipo:
53
99
 
54
100
  ```text
55
- https://favagit.github.io/mantenimento-app/?apiBase=https://dev-api.example.com
101
+ https://favagit.github.io/mantenimento-app/?autologin=1&authToken=...
56
102
  ```
57
103
 
58
- Per usare anche il frontend del branch dev con un link unico:
104
+ Avvio completamente automatico lato backend (senza generare token da shell):
59
105
 
60
106
  ```text
61
- https://favagit.github.io/mantenimento-app/?frontend=dev&env=dev
107
+ https://mantenimento-app.onrender.com/api/auth/url-login/start?k=<BOOTSTRAP_KEY>&sub=favagit
62
108
  ```
63
109
 
64
- `frontend=dev` apre la preview frontend del branch configurata in `supabase-config.js`,
65
- mentre `env=dev` seleziona il backend dev.
110
+ Il backend genera token monouso in automatico e reindirizza al frontend.
111
+ Se `AUTH_URL_LOGIN_SUPABASE_USERS_JSON` e configurato, il valore `sub` determina anche quale account Supabase viene autenticato.
66
112
 
67
- L'override viene memorizzato in `localStorage`, quindi resta attivo anche ai refresh successivi.
68
- Per tornare al backend di default:
113
+ Esempio pratico (solo password, email auto-risolta):
69
114
 
70
115
  ```text
71
- https://favagit.github.io/mantenimento-app/?apiBase=reset
116
+ AUTH_URL_LOGIN_SUPABASE_USERS_JSON={"favagit":{"password":"<PASS_FAVAGIT>"},"fabio.vacchino":{"password":"<PASS_FABIO>"}}
72
117
  ```
73
118
 
74
- ## Build frontend minificato
119
+ Per ottenere il link in JSON invece del redirect:
75
120
 
76
- ```bash
77
- npm run build:frontend
121
+ ```text
122
+ https://mantenimento-app.onrender.com/api/auth/url-login/start?k=<BOOTSTRAP_KEY>&sub=favagit&format=json
78
123
  ```
79
124
 
80
- Il server serve automaticamente `app.min.js` se presente, altrimenti `app.js`.
125
+ Note sicurezza:
126
+ - Il token e monouso, con scadenza breve e firma HMAC.
127
+ - I parametri sensibili vengono rimossi dalla barra URL subito dopo la lettura.
128
+ - Il login via `authPass`/`authPass64` e disabilitato per hardening.
81
129
 
82
- ## Avvio produzione locale
130
+ ### Script SQL donor (globale server-side)
131
+ Per assegnare/rimuovere privilegi donor in modo globale su Supabase:
132
+
133
+ - `scripts/sql/grant-donor.sql`
134
+ - `scripts/sql/revoke-donor.sql`
135
+
136
+ Esegui gli script da Supabase SQL Editor (modificando eventualmente la lista utenti nel `WHERE`).
137
+
138
+ ### Gestione donor da CLI (senza SQL Editor)
139
+ In alternativa puoi gestire i donor direttamente da riga di comando usando l'Admin API di Supabase.
140
+
141
+ Variabili ambiente richieste:
142
+ - `DONOR_ADMIN_SUPABASE_URL` (es. `https://<project>.supabase.co`)
143
+ - `DONOR_ADMIN_SUPABASE_SERVICE_ROLE_KEY` (service-role key)
144
+
145
+ Esempi:
83
146
 
84
147
  ```bash
85
- npm start
148
+ npm run donor:grant -- --users=favagit,fabio.vacchino
149
+ npm run donor:revoke -- --users=fabio.vacchino
86
150
  ```
87
151
 
88
- `npm start` esegue build frontend + avvio server.
152
+ Per test senza scrivere modifiche:
89
153
 
90
- ## Endpoint backend
91
- - `POST /api/calculate`: calcolo modello mantenimento server-side; il payload transita su HTTPS/TLS in produzione e la risposta applica header `Cache-Control: no-store`
92
- - `GET /api/health`: health check
154
+ ```bash
155
+ npm run donor:grant -- --users=favagit --dry-run
156
+ ```
93
157
 
94
- Parametri server utili:
95
- - `CALCULATE_RATE_WINDOW_MS`: finestra del rate limit per `/api/calculate` (default `60000`)
96
- - `CALCULATE_RATE_MAX_REQUESTS`: massimo richieste per IP nella finestra (default `30`)
97
- - `ACCESS_LOG_ENABLED`: abilita log strutturati minimizzati, attivo di default in produzione
98
- - `ACCESS_LOG_SALT`: sale usato per anonimizzare il riferimento client nei log applicativi
99
- - payload JSON in ingresso limitato a `64kb`
158
+ Supporta anche email complete:
159
+
160
+ ```bash
161
+ npm run donor:grant -- --emails=fabio.vacchino@gmail.com
162
+ ```
100
163
 
101
164
  ## KeyLock multi-device (Supabase)
102
165
  Il login cloud resta lato frontend e usa `supabase-config.js` (chiave anon pubblica).