mantenimento-app 2.2.8 → 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 +97 -34
- package/app.js +558 -102
- package/backend/server.js +346 -23
- package/frontend/public/app.js +558 -102
- package/frontend/public/autologin.html +40 -0
- package/frontend/public/index.html +29 -6
- package/frontend/public/styles.css +78 -5
- package/frontend/public/supabase-config.js +4 -11
- package/package.json +5 -1
- package/scripts/auth-url-check.mjs +166 -0
- package/scripts/create-url-login-token.mjs +52 -0
- package/scripts/manage-donor-users.mjs +229 -0
- package/scripts/sql/grant-donor.sql +22 -0
- package/scripts/sql/revoke-donor.sql +19 -0
package/README.md
CHANGED
|
@@ -33,70 +33,133 @@ npm run dev
|
|
|
33
33
|
3. Apri:
|
|
34
34
|
|
|
35
35
|
```text
|
|
36
|
-
http://localhost:
|
|
36
|
+
http://localhost:3000
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
##
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
```
|
|
49
|
-
|
|
91
|
+
```text
|
|
92
|
+
https://favagit.github.io/mantenimento-app/autologin.html?authToken=...
|
|
50
93
|
```
|
|
51
94
|
|
|
52
|
-
|
|
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/?
|
|
101
|
+
https://favagit.github.io/mantenimento-app/?autologin=1&authToken=...
|
|
56
102
|
```
|
|
57
103
|
|
|
58
|
-
|
|
104
|
+
Avvio completamente automatico lato backend (senza generare token da shell):
|
|
59
105
|
|
|
60
106
|
```text
|
|
61
|
-
https://
|
|
107
|
+
https://mantenimento-app.onrender.com/api/auth/url-login/start?k=<BOOTSTRAP_KEY>&sub=favagit
|
|
62
108
|
```
|
|
63
109
|
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
Per tornare al backend di default:
|
|
113
|
+
Esempio pratico (solo password, email auto-risolta):
|
|
69
114
|
|
|
70
115
|
```text
|
|
71
|
-
|
|
116
|
+
AUTH_URL_LOGIN_SUPABASE_USERS_JSON={"favagit":{"password":"<PASS_FAVAGIT>"},"fabio.vacchino":{"password":"<PASS_FABIO>"}}
|
|
72
117
|
```
|
|
73
118
|
|
|
74
|
-
|
|
119
|
+
Per ottenere il link in JSON invece del redirect:
|
|
75
120
|
|
|
76
|
-
```
|
|
77
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
148
|
+
npm run donor:grant -- --users=favagit,fabio.vacchino
|
|
149
|
+
npm run donor:revoke -- --users=fabio.vacchino
|
|
86
150
|
```
|
|
87
151
|
|
|
88
|
-
|
|
152
|
+
Per test senza scrivere modifiche:
|
|
89
153
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
154
|
+
```bash
|
|
155
|
+
npm run donor:grant -- --users=favagit --dry-run
|
|
156
|
+
```
|
|
93
157
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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).
|