Hub 2.7.0: emergency updates as soon as possible; events on now need a second yes

asap (emergency only, reason + 2FA) queues the update now; the church is
told it's happening now. A church whose Events heartbeat reports an event
on now (stats.live, Events 3.2.0) refuses an emergency update with
LIVE_EVENT until confirmLive. Both update forms offer "As soon as possible"
and ask again for a live event. Contracts 1.10.0 vendored. 4 new tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 22:01:28 +02:00
co-authored by Claude Opus 5.5
parent 3893fb91e0
commit dd5612fb2a
12 changed files with 156 additions and 34 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "events-hub-frontend",
"version": "2.6.1",
"version": "2.7.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "events-hub-frontend",
"version": "2.6.1",
"version": "2.7.0",
"dependencies": {
"lucide-react": "^0.536.0",
"next": "^15.5.24",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "events-hub-frontend",
"version": "2.6.1",
"version": "2.7.0",
"private": true,
"scripts": {
"dev": "next dev -p 3200",
@@ -3,7 +3,7 @@
import React, { useCallback, useEffect, useState } from "react";
import Link from "next/link";
import { useParams, useRouter, useSearchParams } from "next/navigation";
import { api, errorText } from "@/lib/api";
import { api, ApiError, errorText } from "@/lib/api";
import { ago, bytes, fmtDate } from "@/lib/format";
import { useServerPaged } from "@/lib/paging";
import { PRODUCT_NAMES } from "@/lib/products";
@@ -28,7 +28,7 @@ export default function DeploymentPage() {
const [d, setD] = useState<Detail | null>(null);
const [msg, setMsg] = useState<Msg>(warn ? { type: "err", text: warn } : null);
const [problems, setProblems] = useState<string[]>([]);
const [upd, setUpd] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, reason: "", totp: "" });
const [upd, setUpd] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, asap: true, reason: "", totp: "" });
const [adopt, setAdopt] = useState({ eventsDir: "", version: "", address: "", at: toInput(new Date(Date.now() + 5 * H)) });
const [un, setUn] = useState({ at: toInput(new Date(Date.now() + 7 * 24 * H)), totp: "", confirm: "" });
const [demo, setDemo] = useState({ profile: "events", confirm: "", markConfirm: "" });
@@ -44,13 +44,17 @@ export default function DeploymentPage() {
useEffect(() => { load(); }, [load]);
useEffect(() => { api<Release[]>("/api/admin/releases").then(setReleases).catch(() => {}); }, []);
const act = async (path: string, body: unknown, ok: string) => {
const act = async (path: string, body: Record<string, unknown>, ok: string) => {
setMsg(null);
try {
const r = await api<{ warnings?: string[] }>(path, { method: "POST", body });
setMsg({ type: "ok", text: `${ok}${r?.warnings?.length ? ` Note: ${r.warnings.join(" ")}` : ""}` });
load();
} catch (e) { setMsg({ type: "err", text: errorText(e) }); }
} catch (e) {
// Hub 2.7.0: an event is on there now: ask once more, then go ahead.
if (e instanceof ApiError && e.code === "LIVE_EVENT" && !body.confirmLive && window.confirm(e.message)) return act(path, { ...body, confirmLive: true }, ok);
setMsg({ type: "err", text: errorText(e) });
}
};
const proxyDone = async () => {
setMsg(null);
@@ -100,7 +104,7 @@ export default function DeploymentPage() {
)}
{x.status === "live" && (
<form className="card grid gap-3 md:grid-cols-2" onSubmit={e => { e.preventDefault(); act("/api/admin/updates", { deploymentIds: [x.id], product: x.product, version: upd.version || undefined, at: fromInput(upd.at), emergency: upd.emergency, reason: upd.reason || null, totp: upd.totp || null }, "Planned. The site admin was emailed and sees a banner."); }}>
<form className="card grid gap-3 md:grid-cols-2" onSubmit={e => { e.preventDefault(); const asap = upd.emergency && upd.asap; act("/api/admin/updates", { deploymentIds: [x.id], product: x.product, version: upd.version || undefined, at: asap ? undefined : fromInput(upd.at), asap, emergency: upd.emergency, reason: upd.reason || null, totp: upd.totp || null }, asap ? "Started: the agent picks it up within a minute. The site admin was emailed and sees a banner." : "Planned. The site admin was emailed and sees a banner."); }}>
<h2 className="font-medium md:col-span-2">Schedule an update</h2>
<div>
<label className="label" htmlFor="u-v">{PRODUCT_NAMES[x.product as keyof typeof PRODUCT_NAMES] || x.product} release</label>
@@ -109,13 +113,20 @@ export default function DeploymentPage() {
{releases.filter(r => r.product === x.product).map(r => <option key={r.id} value={r.version}>{r.version}{r.latest ? " (latest)" : ""}{r.requires?.length ? ` · needs ${r.requires.map(q => `${PRODUCT_NAMES[q.product]} ${q.version}`).join(", ")}` : ""}</option>)}
</select>
</div>
<div><label className="label" htmlFor="u-at">When</label><input id="u-at" type="datetime-local" className="input" value={upd.at} min={toInput(new Date(Date.now() + minAt))} onChange={e => setUpd({ ...upd, at: e.target.value })} /><p className="mt-1 text-xs text-slate-500">At least {upd.emergency ? "15 minutes" : "4 hours"} away, so the church gets notice.</p></div>
<label className="flex items-center gap-2 text-sm md:col-span-2"><input type="checkbox" checked={upd.emergency} onChange={e => setUpd({ ...upd, emergency: e.target.checked })} /> Emergency (security fix or broken release): 15 minutes&apos; notice, a reason and your two-factor code</label>
{upd.emergency && upd.asap
? <div><span className="label">When</span><p className="mt-2 text-sm">As soon as possible: the agent starts within a minute.</p></div>
: <div><label className="label" htmlFor="u-at">When</label><input id="u-at" type="datetime-local" className="input" value={upd.at} min={toInput(new Date(Date.now() + minAt))} onChange={e => setUpd({ ...upd, at: e.target.value })} /><p className="mt-1 text-xs text-slate-500">At least {upd.emergency ? "15 minutes" : "4 hours"} away, so the church gets notice.</p></div>}
<label className="flex items-center gap-2 text-sm md:col-span-2"><input type="checkbox" checked={upd.emergency} onChange={e => setUpd({ ...upd, emergency: e.target.checked })} /> Emergency (security fix or broken release): a reason and your two-factor code</label>
{upd.emergency && <>
<fieldset className="md:col-span-2 flex flex-wrap gap-4 text-sm">
<legend className="sr-only">When the emergency update runs</legend>
<label className="flex items-center gap-2"><input type="radio" name="u-when" checked={upd.asap} onChange={() => setUpd({ ...upd, asap: true })} /> As soon as possible (within a minute)</label>
<label className="flex items-center gap-2"><input type="radio" name="u-when" checked={!upd.asap} onChange={() => setUpd({ ...upd, asap: false })} /> At a time, at least 15 minutes away</label>
</fieldset>
<div><label className="label" htmlFor="u-r">Reason (shown to the church)</label><input id="u-r" className="input" required value={upd.reason} onChange={e => setUpd({ ...upd, reason: e.target.value })} /></div>
<div><label className="label" htmlFor="u-t">Two-factor code</label><input id="u-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={upd.totp} onChange={e => setUpd({ ...upd, totp: e.target.value })} /></div>
</>}
<div className="md:col-span-2"><button className="btn-primary">Schedule</button></div>
<div className="md:col-span-2"><button className="btn-primary">{upd.emergency && upd.asap ? "Update now" : "Schedule"}</button></div>
</form>
)}
@@ -2,7 +2,7 @@
import React, { useCallback, useEffect, useMemo, useState } from "react";
import Link from "next/link";
import { api, errorText } from "@/lib/api";
import { api, ApiError, errorText } from "@/lib/api";
import { fmtDate } from "@/lib/format";
import { usePaged } from "@/lib/paging";
import { PRODUCT_NAMES } from "@/lib/products";
@@ -30,7 +30,7 @@ export default function UpdatesPage() {
const [releases, setReleases] = useState<Release[]>([]);
const [upcoming, setUpcoming] = useState<Job[]>([]);
const [chosen, setChosen] = useState<string[]>([]);
const [form, setForm] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, reason: "", totp: "" });
const [form, setForm] = useState({ version: "", at: toInput(new Date(Date.now() + 5 * H)), emergency: false, asap: true, reason: "", totp: "" });
const [msg, setMsg] = useState<Msg>(null);
const load = useCallback(() => {
@@ -54,17 +54,22 @@ export default function UpdatesPage() {
setMsg(null);
};
const submit = async (e: React.FormEvent) => {
e.preventDefault();
const submit = async (e: React.FormEvent | null, confirmLive = false) => {
e?.preventDefault();
setMsg(null);
const asap = form.emergency && form.asap;
try {
const r = await api<{ jobs: Job[]; warnings: string[] }>("/api/admin/updates", { method: "POST", body: { deploymentIds: chosen, product, version: form.version || undefined, at: fromInput(form.at), emergency: form.emergency, reason: form.reason || null, totp: form.totp || null } });
const r = await api<{ jobs: Job[]; warnings: string[] }>("/api/admin/updates", { method: "POST", body: { deploymentIds: chosen, product, version: form.version || undefined, at: asap ? undefined : fromInput(form.at), asap, confirmLive, emergency: form.emergency, reason: form.reason || null, totp: form.totp || null } });
const deploys = r.jobs.filter(j => j.type === "deploy").length;
const installs = r.jobs.length - deploys;
setMsg({ type: "ok", text: `Planned for ${deploys} install(s)${installs ? `, with ${installs} Accounts install(s) first` : ""}; each church was emailed and sees a banner.${r.warnings.length ? ` Note: ${r.warnings.join(" ")}` : ""}` });
setChosen([]);
load();
} catch (err) { setMsg({ type: "err", text: errorText(err) }); }
} catch (err) {
// Hub 2.7.0: an event is on at one of them: ask once more, then go ahead.
if (err instanceof ApiError && err.code === "LIVE_EVENT" && !confirmLive && window.confirm(err.message)) return submit(null, true);
setMsg({ type: "err", text: errorText(err) });
}
};
const name = PRODUCT_NAMES[product];
@@ -103,14 +108,21 @@ export default function UpdatesPage() {
</select>
{product === "events" && <p className="mt-1 text-xs text-slate-500">Each church&apos;s Accounts stays on its version, unless this release needs a newer one: then it&apos;s updated first in the same deploy, or installed first if the church has none. The confirmation lists what happens.</p>}
</div>
<div><label className="label" htmlFor="b-at">When</label><input id="b-at" type="datetime-local" className="input" value={form.at} onChange={e => setForm({ ...form, at: e.target.value })} /><p className="mt-1 text-xs text-slate-500">At least {form.emergency ? "15 minutes" : "4 hours"} away. They run one at a time from then.</p></div>
<label className="flex items-center gap-2 text-sm md:col-span-2"><input type="checkbox" checked={form.emergency} onChange={e => setForm({ ...form, emergency: e.target.checked })} /> Emergency: 15 minutes&apos; notice, with a reason and your two-factor code</label>
{form.emergency && form.asap
? <div><span className="label">When</span><p className="mt-2 text-sm">As soon as possible: the agent starts within a minute. They run one at a time.</p></div>
: <div><label className="label" htmlFor="b-at">When</label><input id="b-at" type="datetime-local" className="input" value={form.at} onChange={e => setForm({ ...form, at: e.target.value })} /><p className="mt-1 text-xs text-slate-500">At least {form.emergency ? "15 minutes" : "4 hours"} away. They run one at a time from then.</p></div>}
<label className="flex items-center gap-2 text-sm md:col-span-2"><input type="checkbox" checked={form.emergency} onChange={e => setForm({ ...form, emergency: e.target.checked })} /> Emergency (a security fix or a broken release): a reason and your two-factor code</label>
{form.emergency && <>
<fieldset className="md:col-span-2 flex flex-wrap gap-4 text-sm">
<legend className="sr-only">When the emergency update runs</legend>
<label className="flex items-center gap-2"><input type="radio" name="b-when" checked={form.asap} onChange={() => setForm({ ...form, asap: true })} /> As soon as possible (within a minute)</label>
<label className="flex items-center gap-2"><input type="radio" name="b-when" checked={!form.asap} onChange={() => setForm({ ...form, asap: false })} /> At a time, at least 15 minutes away (gives the church notice)</label>
</fieldset>
<div><label className="label" htmlFor="b-r">Reason (shown to the churches)</label><input id="b-r" className="input" required value={form.reason} onChange={e => setForm({ ...form, reason: e.target.value })} /></div>
<div><label className="label" htmlFor="b-t">Two-factor code</label><input id="b-t" className="input" inputMode="numeric" autoComplete="one-time-code" required value={form.totp} onChange={e => setForm({ ...form, totp: e.target.value })} /></div>
</>}
</div>
<button className="btn-primary" disabled={!chosen.length}>Plan the {name} update for {chosen.length} install(s)</button>
<button className="btn-primary" disabled={!chosen.length}>{form.emergency && form.asap ? `Update ${chosen.length} ${name} install(s) now` : `Plan the ${name} update for ${chosen.length} install(s)`}</button>
</form>
)}