[web] The web UI: hosts, add/edit with apply progress, undo, history and restore, share links, engine switch, certificates and device installs, signing by hand, settings and tokens; smoke test counts every §4 flow's clicks
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
// The one typed API client (handoff §0, §10, §11). It owns the base path, the UI header (CSRF),
|
||||
// redirect: "manual" (sign-out detection), Idempotency-Keys, the error envelope, the server
|
||||
// clock offset, rate-limit and in-progress retries, and lost-contact detection. It decides
|
||||
// nothing about the data.
|
||||
|
||||
import type { ErrorBody, ErrorEnvelope } from "./types";
|
||||
|
||||
export const BASE = "/api/v1";
|
||||
|
||||
/** A refusal from control, with its envelope. */
|
||||
export class ApiError extends Error {
|
||||
constructor(
|
||||
public status: number,
|
||||
public body: ErrorBody,
|
||||
public errors: ErrorBody[],
|
||||
public requestId: string,
|
||||
) {
|
||||
super(body.message);
|
||||
}
|
||||
get code(): string {
|
||||
return this.body.code;
|
||||
}
|
||||
}
|
||||
|
||||
/** Authelia's portal redirect, or a 401 without Ianitor's envelope. */
|
||||
export class SignedOut extends Error {}
|
||||
|
||||
/** No answer (network, or a proxy error without an envelope). */
|
||||
export class LostContact extends Error {}
|
||||
|
||||
type Listener = () => void;
|
||||
|
||||
export interface ClientEvents {
|
||||
onSignedOut?: Listener;
|
||||
onContact?: (ok: boolean) => void;
|
||||
onServerTime?: (offsetMs: number) => void;
|
||||
}
|
||||
|
||||
let events: ClientEvents = {};
|
||||
export function setClientEvents(e: ClientEvents): void {
|
||||
events = e;
|
||||
}
|
||||
|
||||
/** A key for one click; reused by every retry of that click (§11.3). */
|
||||
export function newKey(): string {
|
||||
if (typeof crypto !== "undefined" && "randomUUID" in crypto) return crypto.randomUUID();
|
||||
return Math.random().toString(36).slice(2) + Date.now().toString(36);
|
||||
}
|
||||
|
||||
export interface CallOptions {
|
||||
idem?: string;
|
||||
etag?: string;
|
||||
/** Do not count a failure as lost contact (engine switch, §9.2). */
|
||||
quiet?: boolean;
|
||||
keepalive?: boolean;
|
||||
}
|
||||
|
||||
export interface Answer<T> {
|
||||
status: number;
|
||||
data: T | null;
|
||||
etag: string | null;
|
||||
}
|
||||
|
||||
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
||||
|
||||
function envelope(v: unknown): v is ErrorEnvelope {
|
||||
return typeof v === "object" && v !== null && "error" in v && typeof (v as ErrorEnvelope).error === "object";
|
||||
}
|
||||
|
||||
export async function call<T>(
|
||||
method: string,
|
||||
path: string,
|
||||
body?: unknown,
|
||||
opts: CallOptions = {},
|
||||
): Promise<Answer<T>> {
|
||||
let rateRetried = false;
|
||||
for (let attempt = 0; attempt < 12; attempt++) {
|
||||
const headers: Record<string, string> = { "X-Ianitor-UI": "1", Accept: "application/json" };
|
||||
if (body !== undefined) headers["Content-Type"] = "application/json";
|
||||
if (opts.idem) headers["Idempotency-Key"] = opts.idem;
|
||||
if (opts.etag) headers["If-None-Match"] = opts.etag;
|
||||
let res: Response;
|
||||
try {
|
||||
res = await fetch(BASE + path, {
|
||||
method,
|
||||
headers,
|
||||
body: body === undefined ? undefined : JSON.stringify(body),
|
||||
redirect: "manual",
|
||||
credentials: "same-origin",
|
||||
keepalive: opts.keepalive,
|
||||
});
|
||||
} catch {
|
||||
if (!opts.quiet) events.onContact?.(false);
|
||||
throw new LostContact("no answer");
|
||||
}
|
||||
if (res.type === "opaqueredirect" || (res.status >= 300 && res.status < 400 && res.status !== 304)) {
|
||||
events.onSignedOut?.();
|
||||
throw new SignedOut("signed out");
|
||||
}
|
||||
if (res.status === 304) {
|
||||
events.onContact?.(true);
|
||||
return { status: 304, data: null, etag: opts.etag ?? null };
|
||||
}
|
||||
let json: unknown = null;
|
||||
const text = await res.text();
|
||||
try {
|
||||
json = text ? JSON.parse(text) : null;
|
||||
} catch {
|
||||
json = null;
|
||||
}
|
||||
if (json && typeof json === "object" && "server_time" in json) {
|
||||
const t = Date.parse(String((json as { server_time: string }).server_time));
|
||||
if (!Number.isNaN(t)) events.onServerTime?.(t - Date.now());
|
||||
}
|
||||
if (!envelope(json)) {
|
||||
if (res.status === 401) {
|
||||
events.onSignedOut?.();
|
||||
throw new SignedOut("signed out");
|
||||
}
|
||||
if (res.status >= 502 && res.status <= 504) {
|
||||
if (!opts.quiet) events.onContact?.(false);
|
||||
throw new LostContact(`proxy answered ${res.status}`);
|
||||
}
|
||||
events.onContact?.(true);
|
||||
return { status: res.status, data: json as T, etag: res.headers.get("ETag") };
|
||||
}
|
||||
events.onContact?.(true);
|
||||
const env = json;
|
||||
if (env.error.code === "request.in_progress") {
|
||||
await sleep(1000);
|
||||
continue;
|
||||
}
|
||||
if (env.error.code === "rate.limited" && !rateRetried) {
|
||||
rateRetried = true;
|
||||
await sleep(Math.min(60, env.error.retry_after_s ?? 1) * 1000);
|
||||
continue;
|
||||
}
|
||||
if (res.status === 401 && env.error.code.startsWith("token.")) {
|
||||
// The UI holds no token: a token refusal means the sign-in did not reach control.
|
||||
events.onSignedOut?.();
|
||||
throw new SignedOut(env.error.message);
|
||||
}
|
||||
throw new ApiError(res.status, env.error, env.errors ?? [], env.request_id ?? "");
|
||||
}
|
||||
throw new ApiError(
|
||||
409,
|
||||
{
|
||||
code: "request.in_progress",
|
||||
message: "The first request with this Idempotency-Key is still being handled. Try again in a moment.",
|
||||
field: null,
|
||||
params: {},
|
||||
retry_after_s: 1,
|
||||
detail: null,
|
||||
},
|
||||
[],
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
export const get = <T>(path: string, opts?: CallOptions) => call<T>("GET", path, undefined, opts).then((a) => a.data as T);
|
||||
export const post = <T>(path: string, body: unknown = {}, opts?: CallOptions) =>
|
||||
call<T>("POST", path, body, { idem: newKey(), ...opts }).then((a) => a.data as T);
|
||||
export const put = <T>(path: string, body: unknown, opts?: CallOptions) =>
|
||||
call<T>("PUT", path, body, { idem: newKey(), ...opts }).then((a) => a.data as T);
|
||||
export const patch = <T>(path: string, body: unknown, opts?: CallOptions) =>
|
||||
call<T>("PATCH", path, body, { idem: newKey(), ...opts }).then((a) => a.data as T);
|
||||
export const del = (path: string, opts?: CallOptions) => call<unknown>("DELETE", path, undefined, opts).then(() => undefined);
|
||||
|
||||
/** A UI sentence for request.* codes (handoff §12.4): bugs or a stale page, not user mistakes. */
|
||||
export function sentence(e: unknown): string {
|
||||
if (e instanceof ApiError) {
|
||||
if (e.code.startsWith("request.") && e.code !== "request.in_progress") {
|
||||
return "Ianitor refused this request from the page. Reload the page and try again.";
|
||||
}
|
||||
return e.body.message;
|
||||
}
|
||||
if (e instanceof LostContact) return "Ianitor's control service is not answering. Traffic keeps flowing; changes wait until it is back.";
|
||||
if (e instanceof SignedOut) return "Your sign-in has ended. Sign in again; this page keeps what you typed.";
|
||||
return "Something went wrong.";
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
// Shared UI state: the overview (polled, handoff §3), the route, contact and sign-in state,
|
||||
// the server clock offset and toasts. No business logic: everything shown comes from control.
|
||||
|
||||
import { call, setClientEvents } from "./api";
|
||||
import type { Overview } from "./types";
|
||||
|
||||
export interface Toast {
|
||||
id: number;
|
||||
text: string;
|
||||
}
|
||||
|
||||
export const app = $state({
|
||||
overview: null as Overview | null,
|
||||
etag: null as string | null,
|
||||
loadError: false,
|
||||
lostContact: false,
|
||||
lostSince: 0,
|
||||
lastUpdated: 0,
|
||||
signedOut: false,
|
||||
offset: 0,
|
||||
now: Date.now(),
|
||||
path: typeof location === "undefined" ? "/" : location.pathname + location.search,
|
||||
toasts: [] as Toast[],
|
||||
/** Dismissed banner keys (reverted outcome, renewed, switched). */
|
||||
dismissed: [] as string[],
|
||||
/** The outcome of the last engine switch, until dismissed (handoff §9.2). */
|
||||
switchResult: null as null | { ok: boolean; title: string; text: string; detail?: string | null },
|
||||
/** A renewal just installed (handoff §13.5). */
|
||||
renewedUntil: null as null | string,
|
||||
/** Panels the main screen opens (add/edit host, share, engine). */
|
||||
panel: null as null | { kind: "host"; hostname?: string; resume?: string } | { kind: "share"; hostname: string } | { kind: "engine" },
|
||||
});
|
||||
|
||||
let failures = 0;
|
||||
let firstFailure = 0;
|
||||
|
||||
setClientEvents({
|
||||
onSignedOut: () => {
|
||||
app.signedOut = true;
|
||||
},
|
||||
onContact: (ok) => {
|
||||
if (ok) {
|
||||
failures = 0;
|
||||
app.lostContact = false;
|
||||
return;
|
||||
}
|
||||
if (failures === 0) firstFailure = Date.now();
|
||||
failures++;
|
||||
// Retry quietly for 10 s (a reload takes about 2 s), then say so (§11.1).
|
||||
if (Date.now() - firstFailure >= 10_000) {
|
||||
if (!app.lostContact) app.lostSince = Date.now();
|
||||
app.lostContact = true;
|
||||
}
|
||||
},
|
||||
onServerTime: (o) => {
|
||||
app.offset = o;
|
||||
},
|
||||
});
|
||||
|
||||
/** Server time now, in ms (all countdowns use it, §7.2). */
|
||||
export function serverNow(): number {
|
||||
return app.now + app.offset;
|
||||
}
|
||||
|
||||
/** Seconds left until an ISO time, on the server's clock. */
|
||||
export function secondsLeft(iso: string | null | undefined): number {
|
||||
if (!iso) return 0;
|
||||
return Math.max(0, Math.ceil((Date.parse(iso) - serverNow()) / 1000));
|
||||
}
|
||||
|
||||
export async function refresh(): Promise<void> {
|
||||
if (app.signedOut) return;
|
||||
try {
|
||||
const a = await call<Overview>("GET", "/overview", undefined, { etag: app.etag ?? undefined });
|
||||
if (a.status === 200 && a.data) {
|
||||
app.overview = a.data;
|
||||
app.etag = a.etag;
|
||||
}
|
||||
app.loadError = false;
|
||||
app.lastUpdated = Date.now();
|
||||
} catch {
|
||||
if (!app.overview) app.loadError = true;
|
||||
}
|
||||
}
|
||||
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
let hiddenSince = 0;
|
||||
|
||||
/** Poll every 5 s while visible, 30 s when hidden, stop after 15 min hidden (Q9). */
|
||||
export function startPolling(): () => void {
|
||||
let stopped = false;
|
||||
const tick = async () => {
|
||||
if (stopped) return;
|
||||
const hidden = typeof document !== "undefined" && document.visibilityState === "hidden";
|
||||
if (hidden && !hiddenSince) hiddenSince = Date.now();
|
||||
if (!hidden) hiddenSince = 0;
|
||||
if (!(hidden && Date.now() - hiddenSince > 15 * 60_000)) await refresh();
|
||||
const every = app.lostContact ? 5000 : hidden ? 30_000 : 5000;
|
||||
timer = setTimeout(tick, every);
|
||||
};
|
||||
const vis = () => {
|
||||
if (document.visibilityState === "visible" && hiddenSince) {
|
||||
hiddenSince = 0;
|
||||
clearTimeout(timer);
|
||||
void tick();
|
||||
}
|
||||
};
|
||||
document.addEventListener("visibilitychange", vis);
|
||||
const clock = setInterval(() => (app.now = Date.now()), 1000);
|
||||
void tick();
|
||||
return () => {
|
||||
stopped = true;
|
||||
clearTimeout(timer);
|
||||
clearInterval(clock);
|
||||
document.removeEventListener("visibilitychange", vis);
|
||||
};
|
||||
}
|
||||
|
||||
let toastId = 0;
|
||||
export function toast(text: string): void {
|
||||
const id = ++toastId;
|
||||
app.toasts = [...app.toasts.slice(-2), { id, text }];
|
||||
setTimeout(() => {
|
||||
app.toasts = app.toasts.filter((t) => t.id !== id);
|
||||
}, 6000);
|
||||
}
|
||||
|
||||
export function navigate(path: string): void {
|
||||
if (path === app.path) return;
|
||||
history.pushState({}, "", path);
|
||||
app.path = path;
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
window.addEventListener("popstate", () => {
|
||||
app.path = location.pathname + location.search;
|
||||
});
|
||||
}
|
||||
|
||||
/** Is a change allowed now? (Paused, or no contact.) */
|
||||
export function changesBlocked(): string | null {
|
||||
const o = app.overview;
|
||||
if (app.lostContact) return "Ianitor's control service is not answering.";
|
||||
if (o?.paused) return "Changes are paused.";
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
// Following an apply (handoff §2.2 of ui-api, §3 here): GET /applies/{id} every second while it
|
||||
// runs; quiet retries while edge reloads; the id kept in sessionStorage so a reload resumes it.
|
||||
|
||||
import { get } from "./api";
|
||||
import { refresh } from "./app.svelte";
|
||||
import type { ApplyView } from "./types";
|
||||
|
||||
export const FINAL = ["kept", "reverted", "failed", "needs_attention"];
|
||||
const KEY = "ianitor.activeApply";
|
||||
|
||||
export function remember(id: string | null): void {
|
||||
try {
|
||||
if (id) sessionStorage.setItem(KEY, id);
|
||||
else sessionStorage.removeItem(KEY);
|
||||
} catch {
|
||||
/* storage may be off; the bar still shows the running apply */
|
||||
}
|
||||
}
|
||||
|
||||
export function remembered(): string | null {
|
||||
try {
|
||||
return sessionStorage.getItem(KEY);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Poll until the apply ends. Returns a stop function. */
|
||||
export function follow(id: string, onupdate: (a: ApplyView) => void, every = 1000): () => void {
|
||||
let stopped = false;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
remember(id);
|
||||
const tick = async () => {
|
||||
if (stopped) return;
|
||||
try {
|
||||
const a = await get<ApplyView>(`/applies/${encodeURIComponent(id)}`);
|
||||
if (stopped) return;
|
||||
onupdate(a);
|
||||
if (FINAL.includes(a.state)) {
|
||||
remember(null);
|
||||
void refresh();
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
/* lost contact or a reload in progress: keep trying (the banner says so after 10 s) */
|
||||
}
|
||||
timer = setTimeout(tick, every);
|
||||
};
|
||||
void tick();
|
||||
return () => {
|
||||
stopped = true;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
// Formatting only (handoff §3): times in the browser's zone, 24-hour clock, counts sentences.
|
||||
|
||||
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
const LONG = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
||||
|
||||
const two = (n: number) => String(n).padStart(2, "0");
|
||||
|
||||
/** "Today 14:02", "Yesterday 21:14", "5 Nov 21:14", "5 Nov 2025". */
|
||||
export function when(iso: string | null | undefined, now = Date.now()): string {
|
||||
if (!iso) return "";
|
||||
const d = new Date(iso);
|
||||
if (Number.isNaN(d.getTime())) return "";
|
||||
const n = new Date(now);
|
||||
const hm = `${two(d.getHours())}:${two(d.getMinutes())}`;
|
||||
const sameDay = (a: Date, b: Date) => a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
||||
if (sameDay(d, n)) return `Today ${hm}`;
|
||||
const y = new Date(n);
|
||||
y.setDate(n.getDate() - 1);
|
||||
if (sameDay(d, y)) return `Yesterday ${hm}`;
|
||||
if (d.getFullYear() !== n.getFullYear()) return `${d.getDate()} ${MONTHS[d.getMonth()]} ${d.getFullYear()}`;
|
||||
return `${d.getDate()} ${MONTHS[d.getMonth()]} ${hm}`;
|
||||
}
|
||||
|
||||
/** "14 November 2026 at 14:20". */
|
||||
export function longDate(iso: string | null | undefined, withTime = true): string {
|
||||
if (!iso) return "";
|
||||
const d = new Date(iso);
|
||||
if (Number.isNaN(d.getTime())) return "";
|
||||
const s = `${d.getDate()} ${LONG[d.getMonth()]} ${d.getFullYear()}`;
|
||||
return withTime ? `${s} at ${two(d.getHours())}:${two(d.getMinutes())}` : s;
|
||||
}
|
||||
|
||||
/** "2 Mar 2027". */
|
||||
export function shortDate(iso: string | null | undefined): string {
|
||||
if (!iso) return "";
|
||||
const d = new Date(iso);
|
||||
return `${d.getDate()} ${MONTHS[d.getMonth()]} ${d.getFullYear()}`;
|
||||
}
|
||||
|
||||
/** "8 s", "6 minutes", "2 hours", "3 days". */
|
||||
export function duration(secs: number): string {
|
||||
if (secs < 60) return `${Math.max(0, Math.round(secs))} s`;
|
||||
const m = Math.round(secs / 60);
|
||||
if (m < 60) return m === 1 ? "1 minute" : `${m} minutes`;
|
||||
const h = Math.round(secs / 3600);
|
||||
if (h < 48) return h === 1 ? "1 hour" : `${h} hours`;
|
||||
const days = Math.round(secs / 86400);
|
||||
return `${days} days`;
|
||||
}
|
||||
|
||||
export function ago(iso: string | null | undefined, now: number): string {
|
||||
if (!iso) return "";
|
||||
return duration((now - Date.parse(iso)) / 1000) + " ago";
|
||||
}
|
||||
|
||||
/** "7 hosts · 5 healthy, 1 degraded, 1 down" (handoff §5.1). */
|
||||
export function countsSentence(c: { hosts: number; healthy: number; degraded: number; down: number; unknown: number }): string {
|
||||
const parts = [`${c.healthy} healthy`];
|
||||
if (c.degraded) parts.push(`${c.degraded} degraded`);
|
||||
if (c.down) parts.push(`${c.down} down`);
|
||||
if (c.unknown) parts.push(`${c.unknown} not checked`);
|
||||
return `${c.hosts} ${c.hosts === 1 ? "host" : "hosts"} · ${parts.join(", ")}`;
|
||||
}
|
||||
|
||||
/** Split a server message on its first sentence (handoff §7.5). */
|
||||
export function firstSentence(m: string): [string, string] {
|
||||
const i = m.indexOf(". ");
|
||||
return i < 0 ? [m, ""] : [m.slice(0, i + 1), m.slice(i + 2)];
|
||||
}
|
||||
|
||||
/** Field labels in sentences (handoff §6.5). */
|
||||
export const FIELD_LABEL: Record<string, string> = {
|
||||
hostname: "address",
|
||||
upstreams: "sends traffic to",
|
||||
tls: "certificate",
|
||||
auth: "who can open it",
|
||||
"health_check.path": "health check address",
|
||||
"health_check.interval_secs": "checks every",
|
||||
share_links: "share links",
|
||||
device_certs: "device certificates",
|
||||
access_log: "visit log",
|
||||
websockets: "websockets",
|
||||
headers: "header rules",
|
||||
};
|
||||
|
||||
export function fieldValue(field: string, v: string): string {
|
||||
if (v === "") return "none";
|
||||
if (field === "tls") return v === "domi" ? "Domi certificate" : "Let's Encrypt";
|
||||
if (field === "auth") return v === "forward-auth" ? "sign in first" : "anyone";
|
||||
if (field === "access_log") return v === "truncated" ? "on" : "off";
|
||||
if (v === "true") return "on";
|
||||
if (v === "false") return "off";
|
||||
if (field === "health_check.interval_secs") return `${v} s`;
|
||||
return v;
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
// The shapes the UI reads from control (docs/api.md, docs/ui-api.md, GET /api/v1/openapi.json).
|
||||
// Only the fields the UI uses are typed.
|
||||
|
||||
export interface ErrorBody {
|
||||
code: string;
|
||||
message: string;
|
||||
field: string | null;
|
||||
params: Record<string, string>;
|
||||
retry_after_s: number | null;
|
||||
detail: string | null;
|
||||
}
|
||||
|
||||
export interface ErrorEnvelope {
|
||||
error: ErrorBody;
|
||||
errors: ErrorBody[];
|
||||
request_id: string;
|
||||
}
|
||||
|
||||
export interface Blocked {
|
||||
code: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface Reason {
|
||||
code: string;
|
||||
message: string;
|
||||
hostname?: string | null;
|
||||
upstream?: string | null;
|
||||
field?: string | null;
|
||||
detail?: string | null;
|
||||
params?: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface Step {
|
||||
key: "validate" | "compile" | "write" | "reload" | "watch" | "push";
|
||||
state: "pending" | "running" | "done" | "failed" | "skipped";
|
||||
}
|
||||
|
||||
export interface ApplyView {
|
||||
id: string;
|
||||
change_id: string;
|
||||
kind: "add" | "edit" | "remove" | "undo" | "restore" | "share_links";
|
||||
summary: string;
|
||||
hosts: string[];
|
||||
state: "queued" | "validating" | "applying" | "watching" | "kept" | "reverted" | "failed" | "needs_attention";
|
||||
created_at: string;
|
||||
finished_at: string | null;
|
||||
steps: Step[];
|
||||
queue: { position: number; waiting_for: { apply_id: string; summary: string; seconds_left: number | null } | null } | null;
|
||||
watch: { ends_at: string; seconds_left: number; hosts: { hostname: string; passed: number; failed: number; total: number }[] } | null;
|
||||
reason: Reason | null;
|
||||
errors: ErrorBody[];
|
||||
commit_short: string | null;
|
||||
push: { state: "pushed" | "pending" | "failed"; at: string | null; error_code: string | null; next_try_at: string | null } | null;
|
||||
attempted_host?: HostSpec | null;
|
||||
}
|
||||
|
||||
export interface HeaderRule {
|
||||
action: "set" | "remove";
|
||||
name: string;
|
||||
value?: string;
|
||||
secret?: string;
|
||||
}
|
||||
|
||||
export interface HostSpec {
|
||||
hostname: string;
|
||||
upstreams: string[];
|
||||
tls: "domi" | "letsencrypt";
|
||||
auth: "none" | "forward-auth";
|
||||
websockets: boolean;
|
||||
share_links: boolean;
|
||||
device_certs?: boolean;
|
||||
access_log: "off" | "truncated";
|
||||
health_check?: { path: string; interval_secs: number } | null;
|
||||
request_headers?: HeaderRule[];
|
||||
response_headers?: HeaderRule[];
|
||||
}
|
||||
|
||||
export interface HealthView {
|
||||
state: "healthy" | "degraded" | "down" | "unknown" | "pending";
|
||||
last_check_at: string | null;
|
||||
latency_ms: number | null;
|
||||
since: string | null;
|
||||
failure: { kind: string; upstream: string | null; count: number; of: number } | null;
|
||||
upstreams: { url: string; state: string; last_check_at: string | null; latency_ms: number | null; failure_kind: string | null }[];
|
||||
}
|
||||
|
||||
export interface HostRow {
|
||||
hostname: string;
|
||||
upstreams: string[];
|
||||
tls: string;
|
||||
auth: string;
|
||||
websockets: boolean;
|
||||
share_links: boolean;
|
||||
device_certs: boolean;
|
||||
added_at: string | null;
|
||||
health: HealthView;
|
||||
certificate: { state: "ok" | "pending" | "failed"; not_after: string | null; error_code: string | null };
|
||||
}
|
||||
|
||||
export interface PkiRequest {
|
||||
request_id: string;
|
||||
kind: "device" | "intermediate";
|
||||
state: "waiting" | "approved" | "denied" | "expired" | "cancelled" | "failed";
|
||||
match_code: string;
|
||||
created_at: string;
|
||||
expires_at: string;
|
||||
approved_at: string | null;
|
||||
device_id: string | null;
|
||||
name: string | null;
|
||||
csr_pem: string | null;
|
||||
not_after: string | null;
|
||||
message_code: string;
|
||||
message: string;
|
||||
approve_command: string | null;
|
||||
problem: string | null;
|
||||
}
|
||||
|
||||
export interface IntermediateView {
|
||||
state: "ok" | "due" | "urgent" | "expired" | "missing";
|
||||
subject: string | null;
|
||||
not_after: string | null;
|
||||
days_left: number | null;
|
||||
renewal: PkiRequest | null;
|
||||
banner: Blocked | null;
|
||||
}
|
||||
|
||||
export interface EngineView {
|
||||
running: "pingora" | "caddy";
|
||||
state: "running" | "switching" | "stopped";
|
||||
since: string | null;
|
||||
target: string | null;
|
||||
switchable: boolean;
|
||||
fallback_ready: { built_at: string | null; current: boolean } | null;
|
||||
last_error: Reason | null;
|
||||
notes: Blocked[];
|
||||
}
|
||||
|
||||
export interface UndoView {
|
||||
available: boolean;
|
||||
target: { change_id: string; summary: string; kept_at: string | null; commit_short: string | null } | null;
|
||||
effect: string | null;
|
||||
blocked: Blocked | null;
|
||||
}
|
||||
|
||||
export interface Overview {
|
||||
counts: { hosts: number; healthy: number; degraded: number; down: number; unknown: number };
|
||||
hosts: HostRow[];
|
||||
engine: EngineView;
|
||||
last_apply: ApplyView | null;
|
||||
undo: UndoView;
|
||||
active_apply: { id: string; state: string; summary: string; seconds_left: number | null; queued: number } | null;
|
||||
repo: { name: string; last_push_at: string | null; unpushed: number; push_error_code: string | null } | null;
|
||||
intermediate: IntermediateView | null;
|
||||
site: { forward_auth_configured: boolean; acme_configured: boolean; secrets: string[]; watch_seconds: number; share_links_available: boolean } | null;
|
||||
paused: Blocked | null;
|
||||
paused_reason: string | null;
|
||||
health_error: Blocked | null;
|
||||
rev: string | null;
|
||||
viewer?: { name: string; via: string } | null;
|
||||
server_time: string;
|
||||
}
|
||||
|
||||
export interface HistoryEntry {
|
||||
change_id: string;
|
||||
summary: string;
|
||||
kind: string;
|
||||
state: string;
|
||||
at: string;
|
||||
commit_short: string | null;
|
||||
hosts: string[];
|
||||
reason_short: string | null;
|
||||
}
|
||||
|
||||
export interface RestorePreview {
|
||||
restorable: boolean;
|
||||
same_as_current: boolean;
|
||||
changes: { hostname: string; effect: "added" | "removed" | "changed"; fields: { field: string; from: string; to: string }[] }[];
|
||||
blocked: Blocked | null;
|
||||
}
|
||||
|
||||
export interface ShareLink {
|
||||
id: string;
|
||||
hostname: string;
|
||||
path_prefix: string;
|
||||
created_at: string;
|
||||
expires_at: string;
|
||||
has_password: boolean;
|
||||
state: "active" | "expired" | "stopped";
|
||||
}
|
||||
|
||||
export interface MintedLink {
|
||||
id: string;
|
||||
url: string;
|
||||
expires_at: string;
|
||||
path_prefix: string;
|
||||
has_password: boolean;
|
||||
warning: Blocked | null;
|
||||
}
|
||||
|
||||
export interface TokenRow {
|
||||
id: string;
|
||||
name: string;
|
||||
created_at: string;
|
||||
last_used_at: string | null;
|
||||
expires_at: string | null;
|
||||
revoked_at?: string | null;
|
||||
}
|
||||
|
||||
export interface CreatedToken {
|
||||
id: string;
|
||||
name: string;
|
||||
token: string;
|
||||
expires_at: string | null;
|
||||
}
|
||||
|
||||
export interface DeviceRow {
|
||||
id: string;
|
||||
name: string;
|
||||
kind: "phone" | "computer" | "app";
|
||||
created_at: string;
|
||||
not_after: string;
|
||||
state: "valid" | "revoked" | "expired";
|
||||
revoked_at: string | null;
|
||||
}
|
||||
|
||||
export interface CertsView {
|
||||
intermediate: IntermediateView | null;
|
||||
root: { offline: boolean; subject: string; not_after: string; sha256: string };
|
||||
devices: DeviceRow[];
|
||||
device_lifetime_days: number;
|
||||
server_lifetime_days: number;
|
||||
approval: string;
|
||||
requests: PkiRequest[];
|
||||
}
|
||||
|
||||
export interface Bundle {
|
||||
download_url: string;
|
||||
one_time_password: string;
|
||||
expires_at: string;
|
||||
filename: string;
|
||||
qr_svg: string | null;
|
||||
}
|
||||
Reference in New Issue
Block a user