feat(parcel-sync): eTerra health check + maintenance detection

- New eterra-health.ts service: pings eTerra periodically (3min),
  detects maintenance (503, keywords), tracks consecutive failures
- New /api/eterra/health endpoint for explicit health queries
- Session route blocks login when eTerra is in maintenance (503 response)
- GET /api/eterra/session now includes eterraAvailable/eterraMaintenance
- ConnectionPill shows amber 'Mentenanță' state with AlertTriangle icon
  instead of confusing red error when eTerra is down
- Auto-connect skips when maintenance detected, retries when back online
- 30s session poll auto-detects recovery and re-enables auto-connect
This commit is contained in:
AI Assistant
2026-03-08 10:28:30 +02:00
parent 6557cd5374
commit b7a236c45a
5 changed files with 362 additions and 27 deletions
+24 -3
View File
@@ -7,16 +7,24 @@ import {
getSessionCredentials,
getSessionStatus,
} from "@/modules/parcel-sync/services/session-store";
import { getEterraHealth } from "@/modules/parcel-sync/services/eterra-health";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
/**
* GET /api/eterra/session — returns current server-side session status.
* Any client can call this to check if eTerra is connected.
* GET /api/eterra/session — returns current server-side session status
* enriched with eTerra platform health info.
*/
export async function GET() {
return NextResponse.json(getSessionStatus());
const status = getSessionStatus();
const health = getEterraHealth();
return NextResponse.json({
...status,
eterraAvailable: health.available,
eterraMaintenance: health.maintenance,
eterraHealthMessage: health.message,
});
}
/**
@@ -70,6 +78,19 @@ export async function POST(req: Request) {
);
}
// Block login when eTerra is in maintenance
const health = getEterraHealth();
if (!health.available && health.maintenance) {
return NextResponse.json(
{
error:
"eTerra este în mentenanță — conectarea este dezactivată temporar",
maintenance: true,
},
{ status: 503 },
);
}
// Check if already connected with same credentials
const existing = getSessionCredentials();
if (existing && existing.username === username) {