Rilascio unico (3 moduli) costruito in flotta parallela + verifica avversariale. MODULO A — Audit interni (ISO 27001 §9.2, mig.055): internal_audits + internal_audit_items; codice AUD-NNN; checklist pre-popolata (clausole 4-10 + Annex A applicabili dal SoA); esiti per riga; apertura non conformità collegata a NCR/CAPA (source polimorfico); report HTML stampabile. InternalAuditController + internal-audits.html. MODULO B — Riesame di Direzione (ISO 27001 §9.3, mig.056): management_reviews + management_review_decisions; codice RD-AAAA-NN; INPUT aggregati automaticamente dai moduli (gather: NC/CAPA, audit interni, rischi+trattamenti, KPI/score, obiettivi, formazione, stakeholder, normative, scadenze), congelati nello snapshot all'approvazione; decisioni; verbale stampabile. ManagementReviewController + management-review.html. MODULO C — Calendario unico scadenze: aggregatore SOLA LETTURA (nessuna migrazione) di tutte le scadenze (incidenti/policy/rischi/NC-CAPA/formazione/stakeholder/audit/riesame/review_schedule), griglia mensile + lista + filtri + deep-link. CalendarController + calendario.html. Integrazione: router (3 controller+actionMap), api.js, sidebar V2+legacy, help.js (3 sezioni), i18n (IT+EN), review_schedule ENUM += internal_audit. v1.22.0 + sw cache + cache-buster 20260630. Verifica flotta (28 agenti, 4 dim + avversariale): 9 finding confermati, TUTTI corretti — MAJOR gatherRisks (risk_treatments.organization_id inesistente → JOIN risks); nextCode numerico (no dup >99/anno); footer report audit con etichetta "ISO buona prassi, non obbligo"; help 24→25 clausole; ARIA tab/calendario; focus modali; tasti su celle calendario; rimossi helper api morti. Smoke prod OK (calendario 18 eventi, audit AUD-001 25 item + report + audit→NCR + audit→calendario, riesame gather/decisione/approve/report, gatherRisks ora available); org 151 ripulita. Additivo. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
97 lines
3.4 KiB
JavaScript
97 lines
3.4 KiB
JavaScript
/*
|
|
* NIS2 Agile — Service Worker (PWA)
|
|
* -----------------------------------------------------------------------------
|
|
* Strategia (SaaS autenticato multi-tenant — sicurezza prima di tutto):
|
|
* - /api/* -> NETWORK-ONLY, MAI in cache. Nessun dato autenticato
|
|
* viene cacheato => zero leak cross-utente su un
|
|
* dispositivo condiviso. La sessione resta gestita da
|
|
* JWT / auth-gate.js, fuori dal service worker.
|
|
* - navigazioni HTML -> NETWORK-FIRST, fallback alla cache e infine /offline.html.
|
|
* - asset statici -> STALE-WHILE-REVALIDATE (risposta immediata dalla cache,
|
|
* aggiornamento in background).
|
|
*
|
|
* Il nome cache include la release: va BUMPATO ad ogni rilascio (vedi version.json),
|
|
* cosi' activate elimina automaticamente la shell vecchia.
|
|
*/
|
|
const CACHE = 'nis2-shell-v1.22.0';
|
|
|
|
const PRECACHE = [
|
|
'/offline.html',
|
|
'/manifest.webmanifest',
|
|
'/css/style.css',
|
|
'/js/common.js',
|
|
'/js/common-bi.js',
|
|
'/js/api.js',
|
|
'/js/i18n.js',
|
|
'/js/pwa.js',
|
|
'/vendor/bootstrap-italia/dist/css/bootstrap-italia.min.css',
|
|
'/vendor/bootstrap-italia/dist/js/bootstrap-italia.bundle.min.js',
|
|
'/vendor/bootstrap-italia/dist/svg/sprites.svg',
|
|
'/assets/icons/icon-192.png',
|
|
'/assets/icons/icon-512.png'
|
|
];
|
|
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil((async () => {
|
|
const cache = await caches.open(CACHE);
|
|
// add uno-a-uno: un singolo asset mancante non deve far fallire l'install
|
|
await Promise.all(PRECACHE.map((url) =>
|
|
cache.add(new Request(url, { cache: 'reload' })).catch((err) =>
|
|
console.warn('[sw] precache skip', url, err && err.message))
|
|
));
|
|
await self.skipWaiting();
|
|
})());
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil((async () => {
|
|
const keys = await caches.keys();
|
|
await Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)));
|
|
await self.clients.claim();
|
|
})());
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
const req = event.request;
|
|
if (req.method !== 'GET') return; // non-GET: rete normale
|
|
const url = new URL(req.url);
|
|
if (url.origin !== self.location.origin) return; // cross-origin: rete normale
|
|
|
|
// /api/* -> network-only, mai in cache
|
|
if (url.pathname.startsWith('/api/')) {
|
|
event.respondWith(
|
|
fetch(req).catch(() => new Response(
|
|
JSON.stringify({ error: 'offline', message: 'Connessione di rete assente' }),
|
|
{ status: 503, headers: { 'Content-Type': 'application/json' } }
|
|
))
|
|
);
|
|
return;
|
|
}
|
|
|
|
// navigazioni HTML -> network-first, fallback cache -> offline
|
|
if (req.mode === 'navigate') {
|
|
event.respondWith((async () => {
|
|
try {
|
|
return await fetch(req);
|
|
} catch (e) {
|
|
const cached = await caches.match(req);
|
|
return cached || (await caches.match('/offline.html'));
|
|
}
|
|
})());
|
|
return;
|
|
}
|
|
|
|
// asset statici stesso-origin -> stale-while-revalidate
|
|
event.respondWith((async () => {
|
|
const cache = await caches.open(CACHE);
|
|
const cached = await cache.match(req);
|
|
const network = fetch(req).then((res) => {
|
|
if (res && res.status === 200 && res.type === 'basic') {
|
|
cache.put(req, res.clone());
|
|
}
|
|
return res;
|
|
}).catch(() => null);
|
|
return cached || (await network) || (await caches.match('/offline.html'));
|
|
})());
|
|
});
|