Kez/kez-chat/web/vite.config.ts
Jason Tudisco 60aeaedbad feat(kez-chat): Web Push notifications + WhatsApp-style chat bubbles
Server (kez-chat/src/)
  - push.rs: VAPID (PEM/PKCS#8) auto-generated on first run;
    StoredSubscription store table; PushSender using
    IsahcWebPushClient; fanout drops 410/404 subs automatically.
    Push payload carries metadata only ({type,to,seq}) — never
    plaintext or ciphertext.
  - api.rs: GET /v1/push/vapid-public-key,
    POST /v1/push/subscribe/:handle, POST /v1/push/unsubscribe/:handle.
    Auth via X-KEZ-Auth: <ts>:<sig>, canonical message binds the
    endpoint URL so headers can't be replayed against other subs.
  - messages.rs: after broker.publish, fire-and-forget
    push.fanout for offline recipients.
  - config.rs: --vapid-key-path, --vapid-subject (env-backed).
  - main.rs: load_or_generate_vapid on startup.

Web client (kez-chat/web/src/)
  - vite.config.ts: switched vite-plugin-pwa to injectManifest mode.
  - sw.ts: custom service worker with workbox precache,
    NetworkOnly for /v1/*, NavigationRoute SPA fallback, push +
    notificationclick handlers (focus existing tab via postMessage,
    or open a new one).
  - lib/push.ts: enablePush / disablePush / isPushSubscribed +
    iOS PWA-install detection.
  - routes/Settings.svelte: "Background notifications (Web Push)"
    section with toggle and iOS Add-to-Home-Screen nudge.
  - main.ts: bridge from SW navigate message to svelte-spa-router
    via location.hash.

Chat UX (routes/Messages.svelte)
  - Bubbles now shrink-wrap to content with WhatsApp-style asymmetric
    corners and inline bottom-right timestamps. Old layout used
    nested block-level divs inside max-w-[78%], which stretched
    every bubble to full width regardless of content.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-06 21:47:07 -06:00

102 lines
3.6 KiB
TypeScript

import { execSync } from "node:child_process";
import { existsSync, readFileSync } from "node:fs";
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import tailwindcss from "@tailwindcss/vite";
import { VitePWA } from "vite-plugin-pwa";
// Build-time identity: short git SHA + ISO date. Surfaced in the footer
// as "kez-chat <sha>" so users can eyeball which build they're on (handy
// when verifying that a deploy actually landed instead of being cached).
//
// Resolution order, so it works both locally (with .git) and in the
// Docker build on the remote (no .git copied):
// 1. process.env.BUILD_SHA — set by deploy script
// 2. ./BUILD_SHA file in this dir — set by deploy script
// 3. `git rev-parse --short HEAD` — local dev
// 4. "dev" — give up
const BUILD_SHA = (() => {
if (process.env.BUILD_SHA) return process.env.BUILD_SHA.trim();
if (existsSync("./BUILD_SHA")) {
return readFileSync("./BUILD_SHA", "utf-8").trim();
}
try {
return execSync("git rev-parse --short HEAD").toString().trim();
} catch {
return "dev";
}
})();
const BUILD_TIME = new Date().toISOString();
export default defineConfig({
define: {
__BUILD_SHA__: JSON.stringify(BUILD_SHA),
__BUILD_TIME__: JSON.stringify(BUILD_TIME),
},
plugins: [
svelte(),
tailwindcss(),
VitePWA({
// Auto-update: a new SW activates on next page load. No "click to
// update" prompt — chat needs to stay fresh and we don't want users
// stuck on an old build.
registerType: "autoUpdate",
injectRegister: "auto",
// We need a custom Service Worker so we can handle `push` and
// `notificationclick` events. `injectManifest` keeps the workbox
// precache list autogenerated but lets us own the SW source.
strategies: "injectManifest",
srcDir: "src",
filename: "sw.ts",
injectManifest: {
// zstd wasm is ~350 KB; raise the per-file cap so the precache
// doesn't silently skip it.
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
globPatterns: ["**/*.{js,css,html,svg,png,ico,wasm}"],
},
manifest: {
name: "kez-chat",
short_name: "kez-chat",
description:
"End-to-end encrypted chat on top of KEZ — portable cross-app identity.",
start_url: "/",
scope: "/",
display: "standalone",
background_color: "#0b0c0e",
theme_color: "#0b0c0e",
categories: ["social", "communication"],
icons: [
{ src: "pwa-64x64.png", sizes: "64x64", type: "image/png" },
{ src: "pwa-192x192.png", sizes: "192x192", type: "image/png" },
{ src: "pwa-512x512.png", sizes: "512x512", type: "image/png" },
{
src: "maskable-icon-512x512.png",
sizes: "512x512",
type: "image/png",
purpose: "maskable",
},
],
},
// No `workbox: {...}` here — that key only applies in
// `generateSW` mode. In injectManifest mode, the SW source itself
// (src/sw.ts) handles caching strategies + push events.
devOptions: {
enabled: false,
},
}),
],
server: {
// For dev: proxy API calls to the locally-running chat-server.
// The deployed SPA (served by the same chat-server) doesn't need this.
proxy: {
"/v1": "http://localhost:6969",
"/internal": "http://localhost:6969",
"/.well-known": "http://localhost:6969",
},
},
build: {
outDir: "dist",
emptyOutDir: true,
},
});