diff --git a/apps/logicsrc-web/contract/logicsrc-web.contract.test.ts b/apps/logicsrc-web/contract/logicsrc-web.contract.test.ts index d7d93994..77a958af 100644 --- a/apps/logicsrc-web/contract/logicsrc-web.contract.test.ts +++ b/apps/logicsrc-web/contract/logicsrc-web.contract.test.ts @@ -98,7 +98,8 @@ describe("server-rendered page markup", () => { const markup = renderPageMarkup("/", await siteFooterHtml()); expect(markup).toContain("data-pfs-footer"); const from = "from=https%3A%2F%2Flogicsrc.com%2F"; - for (const hop of ["previous", "next", "random"]) { + // @profullstack/footer 0.2.2 dropped the random and vote links from the ring nav. + for (const hop of ["previous", "next"]) { expect(markup).toContain(`https://rssamplifier.com/ring/profullstack/${hop}?${from}`); } }); diff --git a/apps/pwa/package.json b/apps/pwa/package.json index a1755466..b43b7024 100644 --- a/apps/pwa/package.json +++ b/apps/pwa/package.json @@ -11,6 +11,7 @@ "test": "node --test" }, "dependencies": { + "@profullstack/footer": "latest", "@profullstack/libsql-pg": "^0.1.2", "@simplewebauthn/browser": "^13.3.0", "@simplewebauthn/server": "^13.1.0", diff --git a/apps/pwa/public/manifest.webmanifest b/apps/pwa/public/manifest.webmanifest index 6d1d0f4c..4a2e4abe 100644 --- a/apps/pwa/public/manifest.webmanifest +++ b/apps/pwa/public/manifest.webmanifest @@ -1,7 +1,7 @@ { "name": "LogicSRC Credentials", "short_name": "LogicSRC", - "description": "Human-in-the-loop approvals for your moshscript loops.", + "description": "Share secrets with your team, end-to-end encrypted. The server never sees them.", "start_url": "/", "scope": "/", "display": "standalone", diff --git a/apps/pwa/src/lib/html.mjs b/apps/pwa/src/lib/html.mjs index 73c81d25..8b0bbd92 100644 --- a/apps/pwa/src/lib/html.mjs +++ b/apps/pwa/src/lib/html.mjs @@ -106,6 +106,7 @@ export function page({ title = "LogicSRC ▸ credentials", body = "", head = "" ${esc(title)} + diff --git a/apps/pwa/src/lib/ring-footer.mjs b/apps/pwa/src/lib/ring-footer.mjs new file mode 100644 index 00000000..8f05431d --- /dev/null +++ b/apps/pwa/src/lib/ring-footer.mjs @@ -0,0 +1,33 @@ +// The Profullstack footer (links, copyright, the << Profullstack >> webring row and +// the built.indie + pwamart badges) from @profullstack/footer, on the public +// sign-in page. It is rendered into the HTML on the server because rssamplifier's +// ring verifier reads the page and never runs script. +// +// Pages render synchronously, so the footer is kept as a string: the bundled +// template at boot, then the @latest template from the CDN, refreshed every 15 +// minutes (a footer release reaches us with no redeploy). A failed refresh keeps +// the last good copy. No CSP on this app, so the footer brings its own styles. +import { footerHtml, footerHtmlSync } from "@profullstack/footer"; + +export const RING_FOOTER_OPTIONS = { site: "https://app.logicsrc.com/" }; + +let html = footerHtmlSync(RING_FOOTER_OPTIONS); + +/** The footer markup; never empty. */ +export const ringFooter = () => html; + +/** Accept a rendered footer only when it still links the ring. */ +export function setRingFooter(next) { + if (typeof next !== "string" || !next.includes("/ring/profullstack") || next.length > 64_000) return false; + html = next; + return true; +} + +export function startRingFooterRefresh(everyMs = 15 * 60_000) { + if (process.env.PROFULLSTACK_FOOTER_OFFLINE === "1") return () => {}; + const run = () => footerHtml(RING_FOOTER_OPTIONS).then(setRingFooter, () => {}); + run(); + const timer = setInterval(run, everyMs); + timer.unref?.(); + return () => clearInterval(timer); +} diff --git a/apps/pwa/src/routes/auth.mjs b/apps/pwa/src/routes/auth.mjs index e90ce3c2..5bfa2d39 100644 --- a/apps/pwa/src/routes/auth.mjs +++ b/apps/pwa/src/routes/auth.mjs @@ -6,6 +6,7 @@ import { hashPassword, verifyPassword } from "../lib/crypto.mjs"; import { createUserWithPassword, userByEmail } from "../lib/users.mjs"; import { dashboardHandler } from "./pages.mjs"; import { config } from "../config.mjs"; +import { ringFooter } from "../lib/ring-footer.mjs"; export const authRouter = Router(); @@ -38,7 +39,7 @@ function authPage(req, { error = "", mode = "in" } = {}) { : ``}

- ${footer} + ${footer}${ringFooter()} `; return page({ title: "LogicSRC ▸ sign in", body }); diff --git a/apps/pwa/src/server.mjs b/apps/pwa/src/server.mjs index f221df44..dd6562d1 100644 --- a/apps/pwa/src/server.mjs +++ b/apps/pwa/src/server.mjs @@ -14,6 +14,8 @@ import { apiKeysRouter } from "./routes/apikeys.mjs"; import { opencredsRouter } from "./routes/opencreds.mjs"; import { cliRouter } from "./routes/cli.mjs"; import { pagesRouter } from "./routes/pages.mjs"; +import { descriptor } from "@profullstack/footer"; +import { RING_FOOTER_OPTIONS, startRingFooterRefresh } from "./lib/ring-footer.mjs"; const app = express(); app.disable("x-powered-by"); @@ -48,6 +50,10 @@ const sodiumCore = createRequire(sodiumWrappers).resolve("libsodium"); app.get("/vendor/libsodium.js", (_req, res) => res.sendFile(sodiumCore)); app.get("/vendor/libsodium-wrappers.js", (_req, res) => res.sendFile(sodiumWrappers)); +// The Profullstack webring descriptor (the ring footer is on the sign-in page, /). +app.get("/.well-known/openwebring.json", (_req, res) => + res.json(descriptor({ site: RING_FOOTER_OPTIONS.site, name: "LogicSRC credentials" }))); + app.get("/healthz", (_req, res) => res.json({ ok: true, env: config.env })); app.use(sessionMiddleware); @@ -74,6 +80,7 @@ app.use((err, _req, res, _next) => { async function main() { await migrate(); + startRingFooterRefresh(); app.listen(config.port, () => console.log(`🔐 logicsrc credentials on :${config.port} (${config.env}) — ${config.origin}`)); } main().catch((e) => { console.error("boot failed:", e); process.exit(1); }); diff --git a/apps/pwa/test/ring-footer.test.mjs b/apps/pwa/test/ring-footer.test.mjs new file mode 100644 index 00000000..d33d66d9 --- /dev/null +++ b/apps/pwa/test/ring-footer.test.mjs @@ -0,0 +1,20 @@ +// The sign-in page carries the Profullstack footer (webring row + badges), and +// the refresh only ever swaps in a footer that still links the ring. +import assert from "node:assert/strict"; +import test from "node:test"; + +import { ringFooter, setRingFooter } from "../src/lib/ring-footer.mjs"; + +test("the bundled footer links the ring and both badges for app.logicsrc.com", () => { + const html = ringFooter(); + assert.match(html, /rssamplifier\.com\/ring\/profullstack/); + assert.match(html, /built\.indie\.pit\.world/); + assert.match(html, /pwamart\.com\/for\.svg\?site=https%3A%2F%2Fapp\.logicsrc\.com%2F|pwamart\.com\/for\.svg\?site=https:\/\/app\.logicsrc\.com\//); +}); + +test("a refresh without the ring row is ignored", () => { + const before = ringFooter(); + assert.equal(setRingFooter(""), false); + assert.equal(setRingFooter(undefined), false); + assert.equal(ringFooter(), before); +}); diff --git a/bun.lock b/bun.lock index 6174b665..5c8b2159 100644 --- a/bun.lock +++ b/bun.lock @@ -82,6 +82,7 @@ "name": "@logicsrc/pwa", "version": "0.1.1", "dependencies": { + "@profullstack/footer": "latest", "@profullstack/libsql-pg": "^0.1.2", "@simplewebauthn/browser": "^13.3.0", "@simplewebauthn/server": "^13.1.0", @@ -802,7 +803,7 @@ "@profullstack/emailer": ["@profullstack/emailer@1.0.1", "", {}, "sha512-/uhHJJGH+1xSSz3mJn6X+m6aruYjMD3JOaRp/d4R/YWlzpy07H9z0/JUleIyRyBPNmaANSIwjTZ7aVjaukOEpg=="], - "@profullstack/footer": ["@profullstack/footer@0.2.1", "", { "peerDependencies": { "react": ">=18" }, "optionalPeers": ["react"], "bin": { "profullstack-footer": "bin/profullstack-footer.js" } }, "sha512-KHmKVwrlzCBrSAAJ4zobNFCxTg8VF0gvNMeAut00dX3+gbWCtk6eOwIR2AaqEC7smj6Aio6cIexzt/dUnv1McA=="], + "@profullstack/footer": ["@profullstack/footer@0.2.6", "", { "peerDependencies": { "react": ">=18" }, "optionalPeers": ["react"], "bin": { "profullstack-footer": "bin/profullstack-footer.js" } }, "sha512-BKwbDszAc7e0mYIBiPjgr/5WS8WyDt8IW718s/zW/8pCWOIB1BGwSNs6fmImRSo5kqIjQKUVbXp22jZQ5GEipA=="], "@profullstack/hqtui": ["@profullstack/hqtui@0.5.0", "", { "bin": { "hqtui": "bin/hqtui.mjs" } }, "sha512-jDwILBmdQx8pQA0ao/tzzty8u5nFNS4XhvU9xXhZvdIaMeiF3HBJIVtP6cS6kigS4lXmHR7sztbb9QJpaWwhig=="],