Files
dashcaddy/status/sw.js
Hermes 6c9f9e59a3 [grade=B urn:ump:ez33fpgyydl3nyjnwaaplisz7slunupcf5dnr42pdblwx7chfcma] feat(DC-171): phase 2 — PowerDNS adapter (full plug-in parity) + shared wizard DNS serialisation
NEW powerdns.js adapter: PowerDNS Authoritative HTTP API (X-API-Key).
Full parity (zones + native RRset enumeration — no AXFR needed):
listZones/listRecords, additive create that merges with existing rrset
contents and FAILS CLOSED when the rrset cannot be read (blind REPLACE
would erase values), content-level delete with positive value-presence
proof (absent rrset/value → not-found with ZERO writes; empty/null value
rejected; only genuine whole-rrset intent issues DELETE), TTL preserved
in REPLACE payloads and on additive creates, cross-zone qualification via
the server-resolved zone id/name, case-insensitive rrset matching,
dig-based resolve against the DNS listener (distinct from the API port),
error guidance naming the exact pdns.conf prerequisite.

WIZARD SERIALISATION EXTRACTED to shared js/dns-provider-config.js
(browser global + module.exports): per-provider port defaults
(PowerDNS 8081, RFC2136 53, legacy Technitium 5380), strict port
validation (full-string digits, 1-65535), provider-specific aliases
(server/apiPort/dnsPort/apiToken). The backend tests now execute the
EXACT shipped wizard code, joined through the real createProviderDnsContext
factory to adapter authentication (X-API-Key asserted). provider-dns.js
dual-accepts generic wizard keys and provider-specific fields and
normalises ports to integers (fixes the same latent gap for rfc2136).

Also fixed: rfc2136 parity-matrix rows now exact-sorted-equality across
all five adapters; wizard confirmation summary uses the provider default.

Judge: 7 rounds — r1 C (silent-erase on failed read, cross-zone bug,
missing resolve tests) → r2 C (deleteRecord positive-proof semantics) →
r3 C (TTL in REPLACE, count honesty) → r4 C (empty-value fall-through)
→ r5 C (wizard ip/port/token vs builder field mismatch) → r6 C (5380
default defeating provider ports, untested serialisation) → r7 B zero
blockers (urn:ump:ez33fpgyydl3nyjnwaaplisz7slunupcf5dnr42pdblwx7chfcma).
Post-grade polish applied: strict port validation + range, summary uses
provider defaults, joined serialisation→factory→adapter test, invalid
port table tests.

Suite: backend 176 suites / 3791 tests, frontend 68/68.
2026-10-29 23:46:03 -07:00

128 lines
4.1 KiB
JavaScript

const CACHE = 'dashcaddy-shell-e90de1c239';
const PRECACHE = [
'/',
'/index.html',
'/css/themes.css',
'/css/dashboard.css',
'/css/driver.min.css',
'/css/onboarding.css',
'/dist/core.js',
'/dist/features.js',
'/dist/init.js',
'/dist/onboarding.js',
'/assets/fonts.css',
'/assets/site.webmanifest',
'/assets/favicon.svg',
'/assets/dashcaddy-favicon.ico',
'/assets/icon-192.png',
'/assets/icon-512.png',
'/assets/apple-touch-icon.png',
'/assets/dashcaddy-logo-dark.png',
'/assets/dashcaddy-logo-light.png',
'/assets/sami7777-logo.png',
'/assets/fonts/sami-grotesk/SamiGrotesk-Regular.woff2',
'/assets/fonts/sami-grotesk/SamiGrotesk-Medium.woff2',
'/assets/fonts/sami-grotesk/SamiGrotesk-Bold.woff2',
'/assets/fonts/DSEG7Classic-Bold.woff2',
'/assets/weather/clear-day.svg',
'/assets/weather/clear-night.svg',
'/assets/weather/partly-cloudy-day.svg',
'/assets/weather/partly-cloudy-night.svg',
'/assets/weather/cloudy.svg',
'/assets/weather/fog.svg',
'/assets/weather/drizzle.svg',
'/assets/weather/rain.svg',
'/assets/weather/sleet.svg',
'/assets/weather/snow.svg',
'/assets/weather/thunderstorm.svg',
'/assets/weather/wind.svg'
];
function isNavigationRequest(request) {
return request.mode === 'navigate';
}
function isStaticAsset(pathname) {
return pathname.startsWith('/assets/')
|| pathname.startsWith('/css/')
|| pathname.startsWith('/dist/');
}
async function networkFirst(request, preloadResponsePromise) {
const cache = await caches.open(CACHE);
try {
const preloadResponse = preloadResponsePromise ? await preloadResponsePromise : null;
if (preloadResponse) {
if (preloadResponse.ok) cache.put(request, preloadResponse.clone()).catch(() => {});
return preloadResponse;
}
const response = await fetch(request);
// DC-170: only cache GOOD responses — a 5xx was being stored and later
// served as the app shell by both strategies.
if (response.ok) cache.put(request, response.clone()).catch(() => {});
return response;
} catch (_) {
// DC-170: `caches.match(x) || caches.match(y)` returned a Promise (always
// truthy) so the offline fallback never ran — await both sides.
return (await caches.match(request)) || (await caches.match('/index.html'));
}
}
async function staleWhileRevalidate(request) {
const cache = await caches.open(CACHE);
const cached = await cache.match(request);
const networkPromise = fetch(request)
.then((response) => {
if (response && response.ok) cache.put(request, response.clone()).catch(() => {});
return response;
})
.catch(() => null);
if (cached) return cached;
return networkPromise.then((response) => response || Response.error());
}
self.addEventListener('install', (event) => {
self.skipWaiting();
event.waitUntil(
// DC-170: per-URL caching instead of one all-or-nothing addAll — a single
// renamed/missing asset previously rejected the whole install, leaving the
// OLD service worker (and its stale cache) in control indefinitely.
caches.open(CACHE).then((cache) =>
Promise.all(PRECACHE.map((url) =>
cache.add(new Request(url, { cache: 'reload' })).catch(() => {})
))
)
);
});
self.addEventListener('activate', (event) => {
event.waitUntil((async () => {
const keys = await caches.keys();
await Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key)));
if ('navigationPreload' in self.registration) {
await self.registration.navigationPreload.enable();
}
await self.clients.claim();
})());
});
self.addEventListener('fetch', (event) => {
const { request } = event;
if (request.method !== 'GET') return;
const url = new URL(request.url);
if (url.origin !== self.location.origin) return;
if (url.pathname.startsWith('/api/v1/') || url.pathname.startsWith('/probe/')) return;
if (isNavigationRequest(request) || url.pathname === '/' || url.pathname.endsWith('/index.html')) {
event.respondWith(networkFirst(request, event.preloadResponse));
return;
}
if (isStaticAsset(url.pathname)) {
event.respondWith(staleWhileRevalidate(request));
}
});