diff --git a/docs/profile-verification.md b/docs/profile-verification.md index a7a8710..6cdca75 100644 --- a/docs/profile-verification.md +++ b/docs/profile-verification.md @@ -13,3 +13,5 @@ Chromium, 390×844 и 1280×900: пустые поля, обязательнос После rebase на main: сохранены дневник, рецепты и готовый план тренировок. 37 тестов пройдены. Chromium дополнительно проверяет авторизованный переход в дневник, те же вычисленные нормы, четыре дня плана, запрет доступа после выхода и отсутствие личных страниц/ответов в CacheStorage. Общая прежняя запись localStorage не переносится между учётными записями. После обновления main строгая проверка всех OpenSpec нашла два унаследованных предупреждения: Purpose-заглушки в deploy и tracker. Эти требования не менялись в TPTIP-4. Строгая проверка private-profile проходит; они не влияют на проверки приложения. + +При повторных rebase общий sw.js постоянно менялся в main. Политика приватного приложения вынесена в profile/private-sw.js; production profile-server.mjs отдаёт этот файл по /sw.js. Общий sw.js совпадает с main. Браузерная проверка подтверждает прежний запрет хранения личных страниц и ответов. diff --git a/profile-server.mjs b/profile-server.mjs index edd0eb7..746ea06 100644 --- a/profile-server.mjs +++ b/profile-server.mjs @@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url'; import { ProfileService, InputError } from './profile/service.mjs'; if (process.env.SENTRY_DSN) Sentry.init({dsn:process.env.SENTRY_DSN,release:process.env.SENTRY_RELEASE,environment:process.env.SENTRY_ENVIRONMENT || 'dev',sendDefaultPii:false,beforeSend(event){ delete event.request; delete event.user; return event; }}); const root = fileURLToPath(new URL('.',import.meta.url)); -const files = new Map([['/profile/tracker-guard.js',['profile/tracker-guard.js','text/javascript']],['/gym-plan.i18n.js',['gym-plan.i18n.js','text/javascript']],['/manifest.webmanifest',['manifest.webmanifest','application/manifest+json']],['/sw.js',['sw.js','text/javascript']],['/icon.svg',['icon.svg','image/svg+xml']],['/',['profile/index.html','text/html']],['/profile/app.js',['profile/app.js','text/javascript']],['/profile/telemetry.js',['profile/telemetry.js','text/javascript']],['/profile/style.css',['profile/style.css','text/css']],['/profile/i18n.json',['profile/i18n.json','application/json']]]); +const files = new Map([['/profile/tracker-guard.js',['profile/tracker-guard.js','text/javascript']],['/gym-plan.i18n.js',['gym-plan.i18n.js','text/javascript']],['/manifest.webmanifest',['manifest.webmanifest','application/manifest+json']],['/sw.js',['profile/private-sw.js','text/javascript']],['/icon.svg',['icon.svg','image/svg+xml']],['/',['profile/index.html','text/html']],['/profile/app.js',['profile/app.js','text/javascript']],['/profile/telemetry.js',['profile/telemetry.js','text/javascript']],['/profile/style.css',['profile/style.css','text/css']],['/profile/i18n.json',['profile/i18n.json','application/json']]]); export function createApp({database,secure = process.env.NODE_ENV === 'production'} = {}) { if (!database) mkdirSync(process.env.DATA_DIR || resolve(root,'data'),{recursive:true,mode:0o700}); const service = new ProfileService(database || resolve(process.env.DATA_DIR || resolve(root,'data'),'profile.sqlite')); diff --git a/profile/private-sw.js b/profile/private-sw.js new file mode 100644 index 0000000..4c57aad --- /dev/null +++ b/profile/private-sw.js @@ -0,0 +1,16 @@ +// Офлайн-кэш только публичных ресурсов; личные страницы и ответы требуют сети. +const CACHE = 'tpt-v7-private-profile-required-fields'; +const FILES = ['gym-plan.i18n.js', 'manifest.webmanifest', 'icon.svg']; +self.addEventListener('install', e => { e.waitUntil(caches.open(CACHE).then(c => c.addAll(FILES)).then(() => self.skipWaiting())); }); +self.addEventListener('activate', e => { + e.waitUntil(caches.keys().then(ks => Promise.all(ks.filter(k => k !== CACHE).map(k => caches.delete(k)))).then(() => self.clients.claim())); +}); +self.addEventListener('fetch', e => { + if (e.request.method !== 'GET' || !FILES.some(f => new URL(e.request.url).pathname === '/' + f)) return; + e.respondWith(fetch(e.request).then(r => { + const copy = r.clone(); + caches.open(CACHE).then(c => c.put(e.request, copy)); + return r; + }).catch(() => caches.match(e.request).then(m => m || Response.error()))); +}); +self.addEventListener('notificationclick', e => { e.notification.close(); e.waitUntil(self.clients.openWindow('./')); }); diff --git a/sw.js b/sw.js index 4c57aad..e2fc066 100644 --- a/sw.js +++ b/sw.js @@ -1,16 +1,16 @@ -// Офлайн-кэш только публичных ресурсов; личные страницы и ответы требуют сети. -const CACHE = 'tpt-v7-private-profile-required-fields'; -const FILES = ['gym-plan.i18n.js', 'manifest.webmanifest', 'icon.svg']; +// Сервис-воркер: приложение открывается без интернета (сначала сеть, при отсутствии — копия из кэша). +const CACHE = 'tpt-v6-required'; +const FILES = ['./', 'index.html', 'gym-plan.i18n.js', 'manifest.webmanifest', 'icon.svg']; self.addEventListener('install', e => { e.waitUntil(caches.open(CACHE).then(c => c.addAll(FILES)).then(() => self.skipWaiting())); }); self.addEventListener('activate', e => { e.waitUntil(caches.keys().then(ks => Promise.all(ks.filter(k => k !== CACHE).map(k => caches.delete(k)))).then(() => self.clients.claim())); }); self.addEventListener('fetch', e => { - if (e.request.method !== 'GET' || !FILES.some(f => new URL(e.request.url).pathname === '/' + f)) return; + if (e.request.method !== 'GET') return; e.respondWith(fetch(e.request).then(r => { const copy = r.clone(); caches.open(CACHE).then(c => c.put(e.request, copy)); return r; - }).catch(() => caches.match(e.request).then(m => m || Response.error()))); + }).catch(() => caches.match(e.request).then(m => m || caches.match('index.html')))); }); self.addEventListener('notificationclick', e => { e.notification.close(); e.waitUntil(self.clients.openWindow('./')); });