@crvouga/mockingbird-service-customerio 1.8.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -110,13 +110,31 @@ var Collection = class {
110
110
  };
111
111
 
112
112
  // ../core/dist/control.js
113
- var HEALTH_PATH = "/health";
114
113
  var ADMIN_PREFIX = "/__admin";
114
+ var resolveAdminPrefix = (prefix = ADMIN_PREFIX) => {
115
+ if (!/^\/[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*$/.test(prefix)) {
116
+ throw new Error("adminPrefix must be an absolute non-root path of literal segments, without a trailing slash");
117
+ }
118
+ return prefix;
119
+ };
120
+ var isAdminPath = (path, prefix) => path === prefix || path.startsWith(`${prefix}/`);
121
+ var matchNamespacePath = (path, prefix) => /^\/ns\/([^/]+)(\/.*)?$/.exec(isAdminPath(path, prefix) ? path.slice(prefix.length) : "");
122
+ var assertAdminPrefixAvailable = (prefix, paths) => {
123
+ const reserved = prefix.split("/").slice(1);
124
+ for (const path of paths) {
125
+ const segments = path.split("/").slice(1);
126
+ if (segments.length < reserved.length || /^\{[^}]+\}$/.test(segments[0] ?? ""))
127
+ continue;
128
+ if (reserved.every((part, i) => segments[i] === part || /^\{[^}]+\}$/.test(segments[i] ?? ""))) {
129
+ throw new Error(`vendor route ${path} collides with adminPrefix ${prefix}; choose a different adminPrefix`);
130
+ }
131
+ }
132
+ };
115
133
  var ADMIN_KEY_HEADER = "x-mockingbird-admin-key";
116
134
  var NAMESPACE_HEADER = "x-mockingbird-namespace";
117
135
  var json = (status, body) => new Response(JSON.stringify(body), {
118
136
  status,
119
- headers: { "content-type": "application/json" }
137
+ headers: { "content-type": "application/json; charset=utf-8" }
120
138
  });
121
139
  var adminError = (status, message) => json(status, { error: { type: "mockingbird_admin", message } });
122
140
  var UNITS = {
@@ -168,11 +186,25 @@ var readJson = async (request) => {
168
186
  };
169
187
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
170
188
  var createControlPlane = (context) => {
189
+ const adminPrefix = resolveAdminPrefix(context.adminPrefix);
171
190
  const snapshots = /* @__PURE__ */ new Map();
172
191
  let snapshotCounter = 0;
173
192
  const headerNamespace = (request) => request.headers.get(NAMESPACE_HEADER) ?? context.defaultNamespace;
174
193
  const adminNamespace = (request, url) => url.searchParams.get("namespace") ?? headerNamespace(request);
194
+ const health = () => {
195
+ return json(200, {
196
+ ...context.describe(),
197
+ status: "ok",
198
+ service: context.name,
199
+ uptimeMs: context.wallNow() - context.startedAt,
200
+ clock: context.clock.state(),
201
+ namespaces: context.namespaces().length,
202
+ adminPrefix,
203
+ adminUi: `${adminPrefix}/ui`
204
+ });
205
+ };
175
206
  const builtin = {
207
+ "GET /health": health,
176
208
  "GET /": () => json(200, {
177
209
  service: context.name,
178
210
  routes: [...Object.keys(builtin), ...Object.keys(context.routes)].sort()
@@ -339,7 +371,14 @@ var createControlPlane = (context) => {
339
371
  return json(200, { status: "ok" });
340
372
  }
341
373
  };
342
- const routes = [...Object.entries(context.routes), ...Object.entries(builtin)].map(([key, handler]) => {
374
+ for (const key of Object.keys(context.routes)) {
375
+ if (Object.hasOwn(builtin, key))
376
+ throw new Error(`admin route ${key} overrides a shared route`);
377
+ const path = key.slice(key.indexOf(" ") + 1);
378
+ if (isAdminPath(path, "/ns") || isAdminPath(path, "/blobs"))
379
+ throw new Error(`admin route ${key} overlaps an internal transport`);
380
+ }
381
+ const routes = [...Object.entries(builtin), ...Object.entries(context.routes)].map(([key, handler]) => {
343
382
  const space = key.indexOf(" ");
344
383
  return { method: key.slice(0, space), pattern: key.slice(space + 1), handler };
345
384
  });
@@ -347,21 +386,13 @@ var createControlPlane = (context) => {
347
386
  namespaceOf: headerNamespace,
348
387
  async handle(request) {
349
388
  const url = new URL(request.url);
350
- if (url.pathname === HEALTH_PATH && request.method === "GET") {
351
- return json(200, {
352
- status: "ok",
353
- service: context.name,
354
- uptimeMs: context.wallNow() - context.startedAt,
355
- clock: context.clock.state(),
356
- namespaces: context.namespaces().length,
357
- adminUi: `${ADMIN_PREFIX}/ui`,
358
- ...context.describe()
359
- });
389
+ if (url.pathname === `${adminPrefix}/health` && request.method === "GET") {
390
+ return health();
360
391
  }
361
- if (url.pathname !== ADMIN_PREFIX && !url.pathname.startsWith(`${ADMIN_PREFIX}/`)) {
392
+ if (!isAdminPath(url.pathname, adminPrefix)) {
362
393
  return void 0;
363
394
  }
364
- const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
395
+ const path = url.pathname.slice(adminPrefix.length) || "/";
365
396
  const shell = request.method === "GET" && (path === "/ui" || path === "/ui/");
366
397
  if (!shell && context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
367
398
  return adminError(401, `missing or wrong ${ADMIN_KEY_HEADER}`);
@@ -369,7 +400,12 @@ var createControlPlane = (context) => {
369
400
  for (const route of routes) {
370
401
  if (route.method !== request.method)
371
402
  continue;
372
- const params = matchRoute(route.pattern, path);
403
+ let params;
404
+ try {
405
+ params = matchRoute(route.pattern, path);
406
+ } catch {
407
+ return adminError(400, "invalid path encoding");
408
+ }
373
409
  if (!params)
374
410
  continue;
375
411
  let body;
@@ -378,15 +414,18 @@ var createControlPlane = (context) => {
378
414
  } catch {
379
415
  return adminError(400, "request body is not valid JSON");
380
416
  }
417
+ const namespace = adminNamespace(request, url);
418
+ if (!/^[A-Za-z0-9_.-]{1,64}$/.test(namespace))
419
+ return adminError(400, "invalid namespace");
381
420
  return route.handler({
382
421
  request,
383
422
  url,
384
423
  params,
385
- namespace: adminNamespace(request, url),
424
+ namespace,
386
425
  body
387
426
  });
388
427
  }
389
- return adminError(404, `no admin route ${request.method} ${path}; GET ${ADMIN_PREFIX} lists them`);
428
+ return adminError(404, `no admin route ${request.method} ${path}; GET ${adminPrefix} lists them`);
390
429
  }
391
430
  };
392
431
  };
@@ -1213,7 +1252,10 @@ var OutboxStore = class {
1213
1252
  return query.limit !== void 0 ? matched.slice(-Math.max(0, query.limit)) : matched;
1214
1253
  }
1215
1254
  };
1216
- var json2 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
1255
+ var json2 = (status, body) => new Response(JSON.stringify(body), {
1256
+ status,
1257
+ headers: { "content-type": "application/json; charset=utf-8" }
1258
+ });
1217
1259
  var parseSince = (value) => {
1218
1260
  if (value === null)
1219
1261
  return void 0;
@@ -1859,6 +1901,34 @@ dialog:not([open]) {
1859
1901
  function isRecord2(value) {
1860
1902
  return typeof value === "object" && value !== null && !Array.isArray(value);
1861
1903
  }
1904
+ function highlightJsonText(text) {
1905
+ const escapeToken = (value) => value.replace(/[&<>"']/g, (char) => {
1906
+ switch (char) {
1907
+ case "&":
1908
+ return "&amp;";
1909
+ case "<":
1910
+ return "&lt;";
1911
+ case ">":
1912
+ return "&gt;";
1913
+ case '"':
1914
+ return "&quot;";
1915
+ default:
1916
+ return "&#39;";
1917
+ }
1918
+ });
1919
+ const token = /("(?:\\u[\da-fA-F]{4}|\\[^u]|[^\\"])*"\s*:|"(?:\\u[\da-fA-F]{4}|\\[^u]|[^\\"])*"|\b(?:true|false)\b|\bnull\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g;
1920
+ let cursor = 0;
1921
+ let html = "";
1922
+ for (const match of text.matchAll(token)) {
1923
+ const index = match.index ?? 0;
1924
+ const value = match[0];
1925
+ html += escapeToken(text.slice(cursor, index));
1926
+ const kind = value.startsWith('"') ? value.trimEnd().endsWith(":") ? "key" : "string" : value === "true" || value === "false" ? "boolean" : value === "null" ? "null" : "number";
1927
+ html += `<span class="json-${kind}">${escapeToken(value)}</span>`;
1928
+ cursor = index + value.length;
1929
+ }
1930
+ return html + escapeToken(text.slice(cursor));
1931
+ }
1862
1932
  function mountAdminBrand(doc, host, service, catalog) {
1863
1933
  const clip = (value, max) => {
1864
1934
  if (typeof value !== "string")
@@ -2220,14 +2290,16 @@ function bootAdmin(config) {
2220
2290
  const state = {
2221
2291
  namespace: "default",
2222
2292
  key: sessionStorage.getItem("mockingbird-admin-key") || "",
2223
- view: "overview",
2293
+ view: ["overview", "state", "clock", "faults", "journal", "routes"].includes(location.hash.slice(1)) ? location.hash.slice(1) : "overview",
2224
2294
  collection: "",
2225
2295
  shape: null,
2226
2296
  route: null,
2297
+ routes: [],
2227
2298
  editing: null
2228
2299
  };
2229
2300
  const standard = new Set(config.standardRoutes);
2230
2301
  const banner = el("banner", HTMLElement);
2302
+ const bannerMessage = el("banner-message", HTMLElement);
2231
2303
  const keyInput = el("admin-key", HTMLInputElement);
2232
2304
  keyInput.value = state.key;
2233
2305
  const params = new URLSearchParams(location.search);
@@ -2238,18 +2310,21 @@ function bootAdmin(config) {
2238
2310
  sessionStorage.setItem("mockingbird-admin-key", state.key);
2239
2311
  params.delete("key");
2240
2312
  const next = params.toString();
2241
- history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
2313
+ history.replaceState(null, "", location.pathname + (next ? `?${next}` : "") + location.hash);
2242
2314
  }
2243
2315
  const queryNamespace = params.get("namespace");
2244
2316
  if (queryNamespace)
2245
2317
  state.namespace = queryNamespace;
2246
2318
  const showError = (error) => {
2247
- banner.textContent = error instanceof Error ? error.message : String(error);
2319
+ bannerMessage.textContent = error instanceof Error ? error.message : String(error);
2248
2320
  banner.classList.add("show");
2321
+ banner.scrollIntoView({ behavior: "smooth", block: "nearest" });
2249
2322
  };
2250
2323
  const clearError = () => {
2251
2324
  banner.classList.remove("show");
2325
+ bannerMessage.textContent = "";
2252
2326
  };
2327
+ el("banner-dismiss", HTMLButtonElement).addEventListener("click", clearError);
2253
2328
  const api = async (method, path, body) => {
2254
2329
  const headers = { accept: "application/json" };
2255
2330
  if (state.key !== "")
@@ -2293,16 +2368,21 @@ function bootAdmin(config) {
2293
2368
  namespace: () => state.namespace
2294
2369
  };
2295
2370
  const isPanelScript = (value) => typeof value === "function";
2371
+ const themeButton = el("theme", HTMLButtonElement);
2296
2372
  const setTheme = (theme) => {
2297
2373
  if (theme)
2298
2374
  document.documentElement.dataset.theme = theme;
2299
2375
  else
2300
2376
  delete document.documentElement.dataset.theme;
2377
+ const dark = theme ? theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2378
+ themeButton.innerHTML = dark ? '<svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><circle cx="10" cy="10" r="3.2" stroke="currentColor" stroke-width="1.5"/><path d="M10 2v1.5M10 16.5V18M18 10h-1.5M3.5 10H2M15.7 4.3l-1 1M5.3 14.7l-1 1M15.7 15.7l-1-1M5.3 5.3l-1-1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>' : '<svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M16.8 12.2A7 7 0 0 1 7.8 3.2a7 7 0 1 0 9 9Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>';
2379
+ const label = dark ? "Use light theme" : "Use dark theme";
2380
+ themeButton.setAttribute("aria-label", label);
2381
+ themeButton.title = label;
2301
2382
  };
2302
2383
  const storedTheme = localStorage.getItem("mockingbird-admin-theme");
2303
- if (storedTheme)
2304
- setTheme(storedTheme);
2305
- el("theme", HTMLButtonElement).addEventListener("click", () => {
2384
+ setTheme(storedTheme === "dark" || storedTheme === "light" ? storedTheme : null);
2385
+ themeButton.addEventListener("click", () => {
2306
2386
  const current = document.documentElement.dataset.theme;
2307
2387
  const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2308
2388
  const next = dark ? "light" : "dark";
@@ -2321,6 +2401,7 @@ function bootAdmin(config) {
2321
2401
  continue;
2322
2402
  section.hidden = section.id !== `view-${view}`;
2323
2403
  }
2404
+ history.replaceState(null, "", `${location.pathname}${location.search}#${encodeURIComponent(view)}`);
2324
2405
  };
2325
2406
  el("nav", HTMLElement).addEventListener("click", (event) => {
2326
2407
  const target = event.target;
@@ -2335,7 +2416,7 @@ function bootAdmin(config) {
2335
2416
  show(view);
2336
2417
  refresh().catch(showError);
2337
2418
  });
2338
- const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
2419
+ const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card stat-card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
2339
2420
  const table = (columns, rows) => {
2340
2421
  if (rows.length === 0)
2341
2422
  return '<p class="empty">Nothing here yet.</p>';
@@ -2345,16 +2426,22 @@ function bootAdmin(config) {
2345
2426
  const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
2346
2427
  return `<tr${attrs}>${cells}</tr>`;
2347
2428
  }).join("");
2348
- return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
2429
+ return `<div class="table-shell"><table><thead>${head}</thead><tbody>${body}</tbody></table></div>`;
2349
2430
  };
2350
2431
  const preview = (value) => {
2351
2432
  const text = JSON.stringify(value) ?? "null";
2352
- return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
2433
+ const clipped = text.length > 180 ? `${text.slice(0, 180)}\u2026` : text;
2434
+ return `<code class="json-inline">${highlightJsonText(clipped)}</code>`;
2353
2435
  };
2354
2436
  const when = (epoch) => {
2355
2437
  const date = new Date(epoch);
2356
2438
  return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
2357
2439
  };
2440
+ const journalWhen = (value) => {
2441
+ const numeric = value.trim() === "" ? Number.NaN : Number(value);
2442
+ const epoch = Number.isFinite(numeric) ? numeric : Date.parse(value);
2443
+ return Number.isFinite(epoch) ? when(epoch) : value;
2444
+ };
2358
2445
  const clockCard = (epoch) => {
2359
2446
  const date = new Date(epoch);
2360
2447
  if (Number.isNaN(date.getTime()))
@@ -2474,7 +2561,7 @@ function bootAdmin(config) {
2474
2561
  };
2475
2562
  const renderOverview = async () => {
2476
2563
  const [health, shape, clock, journal] = await Promise.all([
2477
- originGet("/health"),
2564
+ originGet(`${config.adminPrefix}/health`),
2478
2565
  api("GET", "/state"),
2479
2566
  api("GET", "/clock"),
2480
2567
  api("GET", "/requests?limit=8")
@@ -2491,7 +2578,7 @@ function bootAdmin(config) {
2491
2578
  },
2492
2579
  {
2493
2580
  k: "Status",
2494
- v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
2581
+ v: `<span class="badge ok">${esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")}</span>`
2495
2582
  },
2496
2583
  { k: "Namespace", v: esc(state.namespace) },
2497
2584
  { k: "Collections", v: String(decoded.collections.length) },
@@ -2578,26 +2665,46 @@ function bootAdmin(config) {
2578
2665
  const renderJournal = async () => {
2579
2666
  const journal = await api("GET", "/requests?limit=100");
2580
2667
  el("journal", HTMLElement).innerHTML = table([
2581
- { label: "When", cell: (row) => esc(row.at) },
2582
- { label: "Method", cell: (row) => esc(row.method) },
2668
+ { label: "When", cell: (row) => esc(journalWhen(row.at)) },
2669
+ {
2670
+ label: "Method",
2671
+ cell: (row) => `<span class="method">${esc(row.method)}</span>`
2672
+ },
2583
2673
  { label: "Path", cell: (row) => esc(row.path) },
2584
- { label: "Status", cell: (row) => esc(row.status) },
2674
+ {
2675
+ label: "Status",
2676
+ cell: (row) => `<span class="badge ${row.status.startsWith("2") ? "ok" : row.status.startsWith("4") || row.status.startsWith("5") ? "warn" : ""}">${esc(row.status)}</span>`
2677
+ },
2585
2678
  { label: "ms", cell: (row) => esc(row.durationMs) }
2586
2679
  ], decodeJournal(journal));
2587
2680
  };
2588
- const renderRoutes = async () => {
2589
- const data = await api("GET", "/");
2590
- if (!isRecord2(data))
2591
- throw new Error("Route list was not an object");
2592
- const routes = requireList(data.routes, "Routes").map((route) => String(route));
2681
+ const paintRoutes = () => {
2682
+ const query = el("route-search", HTMLInputElement).value.trim().toLocaleLowerCase();
2683
+ const routes = state.routes.filter((route) => route.toLocaleLowerCase().includes(query));
2684
+ el("route-count", HTMLElement).textContent = `${routes.length} of ${state.routes.length}`;
2685
+ if (state.routes.length === 0) {
2686
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No admin routes are available.</p>';
2687
+ return;
2688
+ }
2689
+ if (routes.length === 0) {
2690
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No routes match this filter.</p>';
2691
+ return;
2692
+ }
2593
2693
  el("route-list", HTMLElement).innerHTML = routes.map((route) => {
2594
2694
  const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
2595
2695
  const parts = route.split(" ");
2596
2696
  const method = parts[0] ?? "";
2597
2697
  const path = parts.slice(1).join(" ");
2598
- return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}">Use</button></div>`;
2698
+ return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}" aria-label="Use ${esc(route)}">Use</button></div>`;
2599
2699
  }).join("");
2600
2700
  };
2701
+ const renderRoutes = async () => {
2702
+ const data = await api("GET", "/");
2703
+ if (!isRecord2(data))
2704
+ throw new Error("Route list was not an object");
2705
+ state.routes = requireList(data.routes, "Routes").map((route) => String(route));
2706
+ paintRoutes();
2707
+ };
2601
2708
  const renderers = {
2602
2709
  overview: renderOverview,
2603
2710
  state: renderState,
@@ -2606,19 +2713,50 @@ function bootAdmin(config) {
2606
2713
  journal: renderJournal,
2607
2714
  routes: renderRoutes
2608
2715
  };
2716
+ let refreshToken = 0;
2609
2717
  async function refresh() {
2718
+ const token = ++refreshToken;
2610
2719
  clearError();
2720
+ const main = el("views", HTMLElement);
2721
+ const sync = el("sync-status", HTMLElement);
2722
+ main.setAttribute("aria-busy", "true");
2723
+ sync.classList.add("busy");
2724
+ sync.textContent = "Updating";
2611
2725
  const render = renderers[state.view];
2612
- if (render)
2613
- await render();
2726
+ try {
2727
+ if (render)
2728
+ await render();
2729
+ if (token === refreshToken)
2730
+ sync.textContent = "Up to date";
2731
+ } finally {
2732
+ if (token === refreshToken) {
2733
+ main.removeAttribute("aria-busy");
2734
+ sync.classList.remove("busy");
2735
+ }
2736
+ }
2614
2737
  }
2615
2738
  const delay = (ms) => new Promise((resolve) => {
2616
2739
  window.setTimeout(resolve, ms);
2617
2740
  });
2618
- const confirmAction = async (button, pending, done, work) => {
2741
+ const confirmAction = async (button, pending, done, work, confirmLabel) => {
2619
2742
  if (button.dataset.pending === "1")
2620
2743
  return;
2621
2744
  const label = button.textContent ?? "";
2745
+ if (confirmLabel !== void 0 && button.dataset.confirming !== "1") {
2746
+ button.dataset.confirming = "1";
2747
+ button.classList.add("confirming");
2748
+ button.textContent = confirmLabel;
2749
+ window.setTimeout(() => {
2750
+ if (button.dataset.confirming !== "1")
2751
+ return;
2752
+ button.textContent = label;
2753
+ button.classList.remove("confirming");
2754
+ delete button.dataset.confirming;
2755
+ }, 3e3);
2756
+ return;
2757
+ }
2758
+ button.classList.remove("confirming");
2759
+ delete button.dataset.confirming;
2622
2760
  const width = button.offsetWidth;
2623
2761
  button.dataset.pending = "1";
2624
2762
  button.classList.add("pressed");
@@ -2639,6 +2777,65 @@ function bootAdmin(config) {
2639
2777
  delete button.dataset.pending;
2640
2778
  }
2641
2779
  };
2780
+ const wireJsonEditor = (textareaId, highlightId, statusId, shellId, allowEmpty) => {
2781
+ const textarea = el(textareaId, HTMLTextAreaElement);
2782
+ const highlight = el(highlightId, HTMLElement);
2783
+ const status = el(statusId, HTMLElement);
2784
+ const shell = el(shellId, HTMLElement);
2785
+ const sync = () => {
2786
+ const text = textarea.value;
2787
+ highlight.innerHTML = `${highlightJsonText(text)}
2788
+ `;
2789
+ let valid = true;
2790
+ let message = "Valid JSON";
2791
+ if (allowEmpty && text.trim() === "")
2792
+ message = "No body";
2793
+ else {
2794
+ try {
2795
+ readJson2(text);
2796
+ } catch {
2797
+ valid = false;
2798
+ message = "Invalid JSON";
2799
+ }
2800
+ }
2801
+ shell.classList.toggle("invalid", !valid);
2802
+ status.classList.toggle("invalid", !valid);
2803
+ status.textContent = message;
2804
+ textarea.setAttribute("aria-invalid", valid ? "false" : "true");
2805
+ };
2806
+ const syncScroll = () => {
2807
+ const preview2 = highlight.parentElement;
2808
+ if (!(preview2 instanceof HTMLElement))
2809
+ return;
2810
+ preview2.scrollTop = textarea.scrollTop;
2811
+ preview2.scrollLeft = textarea.scrollLeft;
2812
+ };
2813
+ textarea.addEventListener("input", sync);
2814
+ textarea.addEventListener("scroll", syncScroll);
2815
+ sync();
2816
+ return sync;
2817
+ };
2818
+ const syncRouteEditor = wireJsonEditor("route-body", "route-highlight", "route-json-status", "route-editor", true);
2819
+ const syncRecordEditor = wireJsonEditor("editor-value", "editor-highlight", "editor-json-status", "record-editor", false);
2820
+ for (const button of document.querySelectorAll("[data-format]")) {
2821
+ if (!(button instanceof HTMLButtonElement))
2822
+ continue;
2823
+ button.addEventListener("click", () => {
2824
+ const target = button.dataset.format;
2825
+ if (target === void 0)
2826
+ return;
2827
+ const textarea = document.getElementById(target);
2828
+ if (!(textarea instanceof HTMLTextAreaElement) || textarea.value.trim() === "")
2829
+ return;
2830
+ try {
2831
+ textarea.value = JSON.stringify(readJson2(textarea.value), null, 2) ?? "";
2832
+ textarea.dispatchEvent(new Event("input"));
2833
+ textarea.focus();
2834
+ } catch {
2835
+ showError(new Error("Fix the JSON before formatting it"));
2836
+ }
2837
+ });
2838
+ }
2642
2839
  document.addEventListener("click", (event) => {
2643
2840
  const target = event.target;
2644
2841
  if (!(target instanceof Element))
@@ -2711,6 +2908,7 @@ function bootAdmin(config) {
2711
2908
  } else {
2712
2909
  editorValue.value = "{\n \n}";
2713
2910
  }
2911
+ syncRecordEditor();
2714
2912
  editor.showModal();
2715
2913
  }
2716
2914
  el("new-record", HTMLButtonElement).addEventListener("click", () => {
@@ -2740,10 +2938,10 @@ function bootAdmin(config) {
2740
2938
  const id = state.editing;
2741
2939
  if (!id)
2742
2940
  return;
2743
- api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2941
+ confirmAction(editorDelete, "Deleting...", "Deleted", () => api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2744
2942
  editor.close();
2745
2943
  return renderState();
2746
- }).catch(showError);
2944
+ }), "Confirm delete").catch(showError);
2747
2945
  });
2748
2946
  for (const button of document.querySelectorAll("[data-advance]")) {
2749
2947
  if (!(button instanceof HTMLButtonElement))
@@ -2789,10 +2987,10 @@ function bootAdmin(config) {
2789
2987
  }).then(() => renderFaults()).catch(showError);
2790
2988
  });
2791
2989
  el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
2792
- confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults())).catch(showError);
2990
+ confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults()), "Confirm clear").catch(showError);
2793
2991
  });
2794
2992
  el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
2795
- confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal())).catch(showError);
2993
+ confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal()), "Confirm clear").catch(showError);
2796
2994
  });
2797
2995
  el("route-list", HTMLElement).addEventListener("click", (event) => {
2798
2996
  const target = event.target;
@@ -2806,9 +3004,15 @@ function bootAdmin(config) {
2806
3004
  return;
2807
3005
  state.route = route;
2808
3006
  el("route-title", HTMLElement).textContent = route;
3007
+ el("route-send", HTMLButtonElement).disabled = false;
2809
3008
  const method = route.split(" ")[0] ?? "";
2810
- el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
3009
+ const routeBody = el("route-body", HTMLTextAreaElement);
3010
+ routeBody.disabled = method === "GET" || method === "DELETE";
3011
+ el("route-editor", HTMLElement).hidden = routeBody.disabled;
3012
+ el("route-json-status", HTMLElement).parentElement?.toggleAttribute("hidden", routeBody.disabled);
3013
+ syncRouteEditor();
2811
3014
  });
3015
+ el("route-search", HTMLInputElement).addEventListener("input", paintRoutes);
2812
3016
  el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
2813
3017
  event.preventDefault();
2814
3018
  const send = async () => {
@@ -2830,7 +3034,8 @@ function bootAdmin(config) {
2830
3034
  }
2831
3035
  }
2832
3036
  const data = await api(method, concrete, body);
2833
- el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
3037
+ const text = JSON.stringify(data, null, 2) ?? "null";
3038
+ el("route-result", HTMLElement).innerHTML = `<code>${highlightJsonText(text)}</code>`;
2834
3039
  };
2835
3040
  send().catch(showError);
2836
3041
  });
@@ -2948,11 +3153,13 @@ function bootAdmin(config) {
2948
3153
  views.append(section);
2949
3154
  mountSqlExplorer(body, panelApi);
2950
3155
  }
3156
+ show(document.getElementById(`view-${state.view}`) === null ? "overview" : state.view);
2951
3157
  return refresh();
2952
3158
  }).catch(showError);
2953
3159
  }
2954
3160
  var clientPrelude = [
2955
3161
  isRecord2,
3162
+ highlightJsonText,
2956
3163
  mountAdminBrand,
2957
3164
  startAdminBrand,
2958
3165
  faultPresetList,
@@ -2975,6 +3182,7 @@ ${entry}(${payload});
2975
3182
  var defineMock = (runtime) => runtime;
2976
3183
  var STANDARD_ADMIN_ROUTES = [
2977
3184
  "GET /",
3185
+ "GET /health",
2978
3186
  "POST /reset",
2979
3187
  "GET /namespaces",
2980
3188
  "GET /clock",
@@ -3054,11 +3262,11 @@ var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
3054
3262
  }
3055
3263
  });
3056
3264
  var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
3057
- var renderAdminDocument = (service) => {
3265
+ var renderAdminDocument = (service, adminPrefix = ADMIN_PREFIX) => {
3058
3266
  const name = escapeHtml(service);
3059
3267
  const script = adminClientSource({
3060
3268
  standardRoutes: STANDARD_ADMIN_ROUTES,
3061
- adminPrefix: ADMIN_PREFIX,
3269
+ adminPrefix,
3062
3270
  adminKeyHeader: ADMIN_KEY_HEADER,
3063
3271
  brandsUrl: ADMIN_BRANDS_URL,
3064
3272
  service
@@ -3075,75 +3283,99 @@ var renderAdminDocument = (service) => {
3075
3283
  ${CSS_RESET}
3076
3284
  :root {
3077
3285
  color-scheme: light;
3078
- --bg: #fafafa;
3286
+ --bg: #f7f8fb;
3079
3287
  --bg-elev: #ffffff;
3080
- --bg-muted: #f4f4f5;
3081
- --bg-inset: #f4f4f5;
3082
- --line: #dedee3;
3083
- --line-strong: #c4c4cc;
3084
- --ink: #18181b;
3085
- --muted: #62626b;
3086
- --faint: #71717a;
3087
- --accent: #27272a;
3288
+ --bg-muted: #f1f3f7;
3289
+ --bg-inset: #f8f9fc;
3290
+ --line: #e4e7ec;
3291
+ --line-strong: #cfd4dc;
3292
+ --ink: #101828;
3293
+ --muted: #475467;
3294
+ --faint: #667085;
3295
+ --accent: #6941c6;
3296
+ --accent-hover: #5933b4;
3088
3297
  --accent-ink: #ffffff;
3089
- --accent-soft: #f4f4f5;
3090
- --ok: #166534;
3091
- --ok-soft: #f0fdf4;
3092
- --warn: #a16207;
3093
- --warn-soft: #fefce8;
3094
- --err: #a82d32;
3095
- --err-soft: #fef2f2;
3096
- --shadow: none;
3298
+ --accent-soft: #f4f0ff;
3299
+ --ok: #067647;
3300
+ --ok-soft: #ecfdf3;
3301
+ --warn: #b54708;
3302
+ --warn-soft: #fffaeb;
3303
+ --err: #b42318;
3304
+ --err-soft: #fef3f2;
3305
+ --code-key: #6941c6;
3306
+ --code-string: #067647;
3307
+ --code-number: #175cd3;
3308
+ --code-boolean: #c11574;
3309
+ --code-null: #667085;
3310
+ --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.05);
3311
+ --shadow-sm: 0 1px 3px rgb(16 24 40 / 0.08), 0 1px 2px rgb(16 24 40 / 0.04);
3312
+ --shadow-lg: 0 18px 48px rgb(16 24 40 / 0.16), 0 4px 12px rgb(16 24 40 / 0.08);
3097
3313
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
3098
3314
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
3099
- --radius: 10px;
3100
- --header: 56px;
3101
- --nav: 200px;
3315
+ --radius: 12px;
3316
+ --header: 72px;
3317
+ --nav: 224px;
3102
3318
  }
3103
3319
  :root[data-theme="dark"] {
3104
3320
  color-scheme: dark;
3105
- --bg: #111113;
3106
- --bg-elev: #19191c;
3107
- --bg-muted: #242428;
3108
- --bg-inset: #111113;
3109
- --line: #36363c;
3110
- --line-strong: #52525b;
3111
- --ink: #f4f4f5;
3112
- --muted: #a9a9b2;
3113
- --faint: #71717a;
3114
- --accent: #e4e4e7;
3115
- --accent-ink: #18181b;
3116
- --accent-soft: #242428;
3117
- --ok: #86efac;
3118
- --ok-soft: #14241b;
3119
- --warn: #fde68a;
3120
- --warn-soft: #2a2410;
3121
- --err: #ffaaaa;
3122
- --err-soft: #2c1516;
3123
- --shadow: none;
3321
+ --bg: #0c0e14;
3322
+ --bg-elev: #151821;
3323
+ --bg-muted: #20232e;
3324
+ --bg-inset: #11141c;
3325
+ --line: #2b303d;
3326
+ --line-strong: #414858;
3327
+ --ink: #f5f7fa;
3328
+ --muted: #b6bdc9;
3329
+ --faint: #8d96a7;
3330
+ --accent: #9e77ed;
3331
+ --accent-hover: #b692f6;
3332
+ --accent-ink: #ffffff;
3333
+ --accent-soft: #2b2142;
3334
+ --ok: #75e0a7;
3335
+ --ok-soft: #102a20;
3336
+ --warn: #fec84b;
3337
+ --warn-soft: #302611;
3338
+ --err: #fda29b;
3339
+ --err-soft: #321817;
3340
+ --code-key: #c3a6ff;
3341
+ --code-string: #75e0a7;
3342
+ --code-number: #84adff;
3343
+ --code-boolean: #f9a8d4;
3344
+ --code-null: #98a2b3;
3345
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3346
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3347
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
3124
3348
  }
3125
3349
  @media (prefers-color-scheme: dark) {
3126
3350
  :root:not([data-theme="light"]) {
3127
3351
  color-scheme: dark;
3128
- --bg: #111113;
3129
- --bg-elev: #19191c;
3130
- --bg-muted: #242428;
3131
- --bg-inset: #111113;
3132
- --line: #36363c;
3133
- --line-strong: #52525b;
3134
- --ink: #f4f4f5;
3135
- --muted: #a9a9b2;
3136
- --faint: #71717a;
3137
- --accent: #e4e4e7;
3138
- --accent-ink: #18181b;
3139
- --accent-soft: #242428;
3140
- --ok: #86efac;
3141
- --ok-soft: #14241b;
3142
- --warn: #fde68a;
3143
- --warn-soft: #2a2410;
3144
- --err: #ffaaaa;
3145
- --err-soft: #2c1516;
3146
- --shadow: none;
3352
+ --bg: #0c0e14;
3353
+ --bg-elev: #151821;
3354
+ --bg-muted: #20232e;
3355
+ --bg-inset: #11141c;
3356
+ --line: #2b303d;
3357
+ --line-strong: #414858;
3358
+ --ink: #f5f7fa;
3359
+ --muted: #b6bdc9;
3360
+ --faint: #8d96a7;
3361
+ --accent: #9e77ed;
3362
+ --accent-hover: #b692f6;
3363
+ --accent-ink: #ffffff;
3364
+ --accent-soft: #2b2142;
3365
+ --ok: #75e0a7;
3366
+ --ok-soft: #102a20;
3367
+ --warn: #fec84b;
3368
+ --warn-soft: #302611;
3369
+ --err: #fda29b;
3370
+ --err-soft: #321817;
3371
+ --code-key: #c3a6ff;
3372
+ --code-string: #75e0a7;
3373
+ --code-number: #84adff;
3374
+ --code-boolean: #f9a8d4;
3375
+ --code-null: #98a2b3;
3376
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3377
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3378
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
3147
3379
  }
3148
3380
  }
3149
3381
  /* Fill the viewport, then grow with the content so the background covers the scroll. */
@@ -3161,13 +3393,17 @@ var renderAdminDocument = (service) => {
3161
3393
  padding-right: env(safe-area-inset-right);
3162
3394
  -webkit-text-size-adjust: 100%;
3163
3395
  }
3164
- :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
3396
+ ::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
3397
+ :focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
3398
+ button, input, select, textarea { transition: border-color 140ms ease, box-shadow 140ms ease, transform 100ms ease; }
3399
+ button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.55; }
3165
3400
  .app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
3166
3401
  header.top {
3167
- position: sticky; top: 0; z-index: 5;
3402
+ position: sticky; top: 0; z-index: 20;
3168
3403
  display: flex; align-items: center; gap: 12px;
3169
- min-height: var(--header); padding: 10px 16px;
3170
- background: var(--bg-elev);
3404
+ min-height: var(--header); padding: 12px 20px;
3405
+ background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
3406
+ backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
3171
3407
  border-bottom: 1px solid var(--line);
3172
3408
  min-width: 0; max-width: 100%;
3173
3409
  }
@@ -3175,12 +3411,21 @@ var renderAdminDocument = (service) => {
3175
3411
  display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
3176
3412
  min-width: 0; max-width: 100%; margin-right: auto;
3177
3413
  }
3178
- .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
3179
- .brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
3414
+ .brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
3415
+ .brand-mark {
3416
+ width: 38px; height: 38px; display: grid; place-items: center; flex: none;
3417
+ border-radius: 11px; color: #fff;
3418
+ background: linear-gradient(145deg, #7f56d9 0%, #53389e 100%);
3419
+ box-shadow: 0 6px 16px rgb(105 65 198 / 0.24), inset 0 1px 0 rgb(255 255 255 / 0.25);
3420
+ }
3421
+ .brand-mark svg { width: 22px; height: 22px; }
3422
+ .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; line-height: 1.25; }
3423
+ .brand-id strong { font-size: 15px; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
3180
3424
  .brand-id span { color: var(--faint); font-size: 12px; }
3181
3425
  .vendor {
3182
3426
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
3183
3427
  min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
3428
+ padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-inset);
3184
3429
  }
3185
3430
  .vendor[hidden] { display: none; }
3186
3431
  /* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
@@ -3192,12 +3437,17 @@ var renderAdminDocument = (service) => {
3192
3437
  .vendor-sep { color: var(--faint); }
3193
3438
  .vendor-link { color: inherit; text-decoration: none; }
3194
3439
  .vendor-link:hover { color: var(--ink); text-decoration: underline; }
3195
- .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
3196
- label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
3440
+ .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
3441
+ .sync-status { align-self: center; display: flex; align-items: center; gap: 6px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3442
+ .sync-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
3443
+ .sync-status.busy::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: pulse 1.2s ease-in-out infinite; }
3444
+ label.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 600; color: var(--faint); }
3197
3445
  label.field input, label.field select, .controls input[type="password"] {
3198
- background-color: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
3199
- padding: 7px 8px; min-height: 36px; line-height: 1.2;
3446
+ background-color: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: 9px;
3447
+ padding: 8px 10px; min-height: 38px; line-height: 1.2; box-shadow: var(--shadow-xs);
3200
3448
  }
3449
+ label.field input:hover, label.field select:hover, textarea:hover { border-color: color-mix(in srgb, var(--accent) 38%, var(--line-strong)); }
3450
+ label.field input:focus, label.field select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); outline: none; }
3201
3451
  /* A native menu ignores min-height, so Preset rendered about half as tall as
3202
3452
  the text fields in the same form. Paint it like those fields. */
3203
3453
  label.field select {
@@ -3214,12 +3464,20 @@ var renderAdminDocument = (service) => {
3214
3464
  dialog .field > textarea { width: 100%; }
3215
3465
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger, nav.side button { cursor: pointer; }
3216
3466
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
3217
- border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
3218
- background: var(--bg-elev);
3219
- }
3220
- .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
3221
- .btn-quiet { background: transparent; }
3222
- .btn-danger { color: var(--err); }
3467
+ display: inline-flex; align-items: center; justify-content: center; gap: 7px;
3468
+ border-radius: 9px; min-height: 38px; padding: 0 13px; border: 1px solid var(--line-strong);
3469
+ background: var(--bg-elev); color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1;
3470
+ box-shadow: var(--shadow-xs);
3471
+ }
3472
+ .icon-btn { width: 38px; padding: 0; }
3473
+ .icon-btn svg, .btn svg, .btn-primary svg { width: 16px; height: 16px; }
3474
+ .icon-btn:hover, .btn:hover { background: var(--bg-muted); border-color: var(--line-strong); }
3475
+ .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 1px 2px rgb(16 24 40 / 0.08), 0 0 0 1px rgb(255 255 255 / 0.08) inset; }
3476
+ .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
3477
+ .btn-quiet { background: transparent; border-color: transparent; box-shadow: none; }
3478
+ .btn-quiet:hover { background: var(--bg-muted); }
3479
+ .btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, var(--line)); }
3480
+ .btn-danger:hover, .btn-danger.confirming { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
3223
3481
  /* Held after mouseup. Clearing an empty journal changes nothing on screen,
3224
3482
  so the press itself has to stay visible. */
3225
3483
  .icon-btn:active, .btn:active, .btn-quiet:active, .btn-danger:active, nav.side button:active,
@@ -3235,93 +3493,159 @@ var renderAdminDocument = (service) => {
3235
3493
  flex: 1 0 auto; min-width: 0;
3236
3494
  }
3237
3495
  nav.side {
3238
- border-right: 1px solid var(--line); padding: 12px;
3496
+ position: sticky; top: var(--header); align-self: start; height: calc(100vh - var(--header));
3497
+ border-right: 1px solid var(--line); padding: 18px 12px;
3239
3498
  display: flex; flex-direction: column; gap: 4px;
3240
- background: var(--bg-elev);
3499
+ background: var(--bg-elev); overflow-y: auto;
3241
3500
  }
3501
+ .nav-label { padding: 0 10px 8px; color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
3242
3502
  nav.side button {
3503
+ position: relative; display: flex; align-items: center; gap: 10px; width: 100%;
3243
3504
  text-align: left; border: 0; background: transparent; border-radius: 9px;
3244
- padding: 9px 10px; min-height: 40px; color: var(--muted);
3245
- }
3246
- nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
3247
- main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
3248
- .view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
3249
- .lede { margin: 0 0 16px; color: var(--muted); }
3250
- .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
3505
+ padding: 9px 10px; min-height: 42px; color: var(--muted); font-size: 13px; font-weight: 550;
3506
+ }
3507
+ nav.side button:hover { background: var(--bg-muted); color: var(--ink); }
3508
+ nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
3509
+ nav.side button[aria-current="true"]::before { content: ""; position: absolute; left: -12px; width: 3px; height: 22px; border-radius: 0 4px 4px 0; background: var(--accent); }
3510
+ .nav-icon { width: 18px; height: 18px; display: grid; place-items: center; flex: none; }
3511
+ .nav-icon svg { width: 18px; height: 18px; }
3512
+ main { padding: 32px clamp(20px, 4vw, 48px) 64px; max-width: 1320px; width: 100%; min-width: 0; }
3513
+ main[aria-busy="true"] .view { opacity: 0.62; }
3514
+ .view { animation: view-in 180ms ease-out; }
3515
+ .view[hidden] { display: none; }
3516
+ .view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
3517
+ .view h2 { margin: 0 0 5px; font-size: clamp(24px, 3vw, 30px); line-height: 1.2; letter-spacing: -0.035em; }
3518
+ .view h3 { margin: 24px 0 10px; font-size: 15px; letter-spacing: -0.01em; }
3519
+ .lede { margin: 0; color: var(--muted); max-width: 72ch; font-size: 14px; }
3520
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: 14px; }
3251
3521
  .card {
3252
3522
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
3253
- padding: 14px 16px; box-shadow: var(--shadow);
3523
+ padding: 18px; box-shadow: var(--shadow-sm);
3254
3524
  }
3255
- .card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
3256
- .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
3525
+ .stat-card { position: relative; overflow: hidden; }
3526
+ .stat-card::after { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, var(--accent), transparent 78%); opacity: 0.7; }
3527
+ .card .k { color: var(--faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
3528
+ .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 24px; font-weight: 650; margin-top: 7px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; letter-spacing: -0.025em; }
3257
3529
  .card .v .clock-time { font-size: 14px; color: var(--muted); }
3258
- .split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
3530
+ .section-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-xs); overflow: hidden; }
3531
+ .section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
3532
+ .section-title h3 { margin: 0; }
3533
+ .split { display: grid; grid-template-columns: minmax(0, 250px) minmax(0, 1fr); gap: 18px; align-items: start; }
3534
+ #collections { padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs); }
3259
3535
  .collection {
3260
3536
  width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
3261
- border-radius: 10px; padding: 8px 10px; min-height: 44px;
3537
+ border-radius: 9px; padding: 10px 11px; min-height: 48px; color: var(--ink); cursor: pointer;
3262
3538
  }
3263
- .collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
3539
+ .collection:hover { background: var(--bg-muted); }
3540
+ .collection[aria-current="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 18%, var(--line)); color: var(--accent); }
3264
3541
  .collection small { display: block; color: var(--faint); }
3265
3542
  .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
3266
- .chip {
3267
- font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
3268
- border-radius: 999px; padding: 4px 8px;
3269
- }
3543
+ .chip { font-family: var(--mono); font-size: 11px; background: var(--bg-muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; }
3270
3544
  .chip i { color: var(--faint); font-style: normal; }
3271
3545
  .sql-layout {
3272
3546
  display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3273
3547
  }
3274
- .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3275
- .sql-tables button { text-align: left; }
3548
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
3549
+ .sql-tables button { text-align: left; border: 0; border-radius: 8px; padding: 9px 10px; background: transparent; color: var(--muted); cursor: pointer; }
3550
+ .sql-tables button:hover, .sql-tables button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
3276
3551
  .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
3277
- table { width: 100%; border-collapse: collapse; font-size: 14px; }
3278
- th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
3279
- th { color: var(--faint); font-weight: 600; font-size: 12px; }
3552
+ .table-shell { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs); }
3553
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
3554
+ th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
3555
+ th { color: var(--faint); background: var(--bg-inset); font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: 0.045em; }
3556
+ tbody tr:last-child td { border-bottom: 0; }
3280
3557
  tr.clickable { cursor: pointer; }
3281
- tr.clickable:hover { background: var(--bg-muted); }
3558
+ tr.clickable:hover { background: var(--accent-soft); }
3282
3559
  pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
3283
3560
  pre {
3284
3561
  margin: 0; white-space: pre-wrap; word-break: break-word;
3285
- background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
3286
- }
3287
- .row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
3562
+ background: var(--bg-inset); border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-size: 12px; line-height: 1.65;
3563
+ }
3564
+ .json-key { color: var(--code-key); }
3565
+ .json-string { color: var(--code-string); }
3566
+ .json-number { color: var(--code-number); }
3567
+ .json-boolean { color: var(--code-boolean); }
3568
+ .json-null { color: var(--code-null); font-style: italic; }
3569
+ .json-inline { display: block; max-width: 44rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
3570
+ .json-view { position: relative; max-height: 26rem; overflow: auto; }
3571
+ .json-editor { position: relative; min-height: 190px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg-inset); overflow: hidden; }
3572
+ .json-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
3573
+ .json-editor.invalid { border-color: var(--err); }
3574
+ .json-editor pre, .json-editor textarea { margin: 0; padding: 12px; border: 0; border-radius: 0; min-height: 190px; width: 100%; font: 12px/1.65 var(--mono); tab-size: 2; white-space: pre; overflow: auto; }
3575
+ .json-editor pre { position: absolute; inset: 0; pointer-events: none; background: transparent; }
3576
+ .json-editor textarea { position: relative; z-index: 1; resize: vertical; background: transparent; color: transparent; caret-color: var(--ink); -webkit-text-fill-color: transparent; }
3577
+ .json-editor textarea::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
3578
+ .editor-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 7px; }
3579
+ .json-status { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-size: 11px; }
3580
+ .json-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
3581
+ .json-status.invalid { color: var(--err); }
3582
+ .format-json { border: 0; padding: 3px 5px; background: transparent; color: var(--accent); font-size: 11px; font-weight: 650; cursor: pointer; }
3583
+ .row-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 14px 0; }
3288
3584
  .banner {
3289
- display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
3290
- background: var(--err-soft); color: var(--err);
3291
- }
3292
- .banner.show { display: block; }
3293
- .empty { color: var(--muted); padding: 24px 8px; }
3585
+ display: none; position: sticky; top: calc(var(--header) + 12px); z-index: 15;
3586
+ align-items: center; gap: 10px; margin: 0 0 16px; padding: 11px 12px 11px 14px;
3587
+ border: 1px solid color-mix(in srgb, var(--err) 30%, var(--line)); border-radius: 10px;
3588
+ background: var(--err-soft); color: var(--err); box-shadow: var(--shadow-sm); font-size: 13px;
3589
+ }
3590
+ .banner.show { display: flex; }
3591
+ .banner span { flex: 1; }
3592
+ .banner button { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: currentColor; cursor: pointer; }
3593
+ .banner button:hover { background: color-mix(in srgb, var(--err) 10%, transparent); }
3594
+ .empty { color: var(--muted); padding: 34px 18px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: color-mix(in srgb, var(--bg-elev) 55%, transparent); }
3294
3595
  dialog {
3295
- border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
3296
- color: var(--ink); width: min(640px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: none;
3297
- }
3298
- dialog::backdrop { background: rgb(20 19 17 / 0.45); }
3299
- dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
3596
+ border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--bg-elev);
3597
+ color: var(--ink); width: min(720px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: var(--shadow-lg);
3598
+ }
3599
+ dialog[open] { animation: dialog-in 160ms ease-out; }
3600
+ dialog::backdrop { background: rgb(12 14 20 / 0.58); backdrop-filter: blur(3px); }
3601
+ dialog form, .dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
3602
+ .dialog-heading { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
3603
+ .dialog-heading strong { font-size: 18px; letter-spacing: -0.02em; }
3604
+ .dialog-heading span { color: var(--muted); font-size: 12px; }
3300
3605
  textarea {
3301
3606
  width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
3302
3607
  border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
3303
3608
  font-family: var(--mono); font-size: 12px;
3304
3609
  }
3305
- .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
3306
- .badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
3610
+ .dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 4px; }
3611
+ .dialog-actions .btn-danger { margin-right: auto; }
3612
+ .badge { display: inline-flex; align-items: center; font-size: 10px; font-weight: 700; letter-spacing: 0.03em; border: 1px solid var(--line); border-radius: 999px; padding: 3px 7px; background: var(--bg-muted); color: var(--muted); }
3307
3613
  .badge.ok { background: var(--ok-soft); color: var(--ok); }
3308
3614
  .badge.warn { background: var(--warn-soft); color: var(--warn); }
3309
3615
  .status-2 { color: var(--ok); }
3310
3616
  .status-4, .status-5, .status-0 { color: var(--err); }
3311
3617
  .stack { display: flex; flex-direction: column; gap: 12px; }
3618
+ .form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
3619
+ .form-grid .wide { grid-column: span 2; }
3312
3620
  .route {
3313
- display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
3314
- padding: 8px 0; border-bottom: 1px solid var(--line);
3315
- }
3316
- .method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
3621
+ display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 10px; align-items: center;
3622
+ padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg-elev);
3623
+ }
3624
+ .route:first-child { border-radius: var(--radius) var(--radius) 0 0; }
3625
+ .route:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
3626
+ .route-tools { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
3627
+ .route-tools .field { flex: 1; }
3628
+ .route-tools input { width: 100%; }
3629
+ .route-count { padding-bottom: 10px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3630
+ #route-list { max-height: 34rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow-xs); }
3631
+ .method { width: fit-content; font-family: var(--mono); font-size: 11px; font-weight: 750; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 4px 6px; }
3632
+ @keyframes view-in { from { transform: translateY(3px); } to { transform: translateY(0); } }
3633
+ @keyframes dialog-in { from { transform: translateY(8px) scale(0.99); } to { transform: translateY(0) scale(1); } }
3634
+ @keyframes pulse { 50% { opacity: 0.45; } }
3635
+ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
3636
+ @media (forced-colors: active) { .json-editor pre { display: none; } .json-editor textarea { color: CanvasText; -webkit-text-fill-color: CanvasText; } }
3317
3637
  @media (max-width: 800px) {
3638
+ :root { --header: 0px; }
3318
3639
  header.top {
3319
- align-items: stretch; flex-direction: column;
3320
- padding-top: max(10px, env(safe-area-inset-top));
3640
+ position: relative; align-items: stretch; flex-direction: column;
3641
+ padding: max(12px, env(safe-area-inset-top)) 14px 12px;
3321
3642
  }
3322
3643
  input, select, textarea { font-size: 16px; }
3323
3644
  .brand, .vendor, .controls { width: 100%; }
3645
+ .brand { gap: 10px; }
3646
+ .vendor { order: 2; border-radius: 9px; }
3324
3647
  label.field, label.field select, label.field input { flex: 1; min-width: 0; }
3648
+ .sync-status { display: none; }
3325
3649
  /* The layout fills the screen. A single-column grid stretches every auto
3326
3650
  row, so the tab bar grew with the leftover height and the buttons floated
3327
3651
  in the middle of it. The bar stays one row; the page below takes the rest. */
@@ -3331,14 +3655,23 @@ var renderAdminDocument = (service) => {
3331
3655
  align-content: start;
3332
3656
  }
3333
3657
  nav.side {
3334
- align-self: start; height: auto;
3658
+ position: sticky; top: 0; z-index: 12; align-self: start; height: auto;
3335
3659
  flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
3336
3660
  border-right: 0; border-bottom: 1px solid var(--line);
3337
- padding: 8px;
3661
+ padding: 8px; box-shadow: var(--shadow-xs);
3338
3662
  }
3339
- nav.side button { white-space: nowrap; flex: none; }
3663
+ .nav-label { display: none; }
3664
+ nav.side button { width: auto; white-space: nowrap; flex: none; }
3665
+ nav.side button[aria-current="true"]::before { inset: auto 9px -8px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
3340
3666
  .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
3341
- main { padding: 14px; }
3667
+ .form-grid { grid-template-columns: minmax(0, 1fr); }
3668
+ .form-grid .wide { grid-column: auto; }
3669
+ main { padding: 22px 14px 48px; }
3670
+ .view-head { margin-bottom: 18px; }
3671
+ .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
3672
+ .card { padding: 14px; }
3673
+ .card .v { font-size: 20px; }
3674
+ .table-shell { border: 0; background: transparent; box-shadow: none; overflow: visible; }
3342
3675
  table, thead, tbody, tr, th, td { display: block; }
3343
3676
  thead { display: none; }
3344
3677
  tr {
@@ -3353,50 +3686,63 @@ var renderAdminDocument = (service) => {
3353
3686
  .route { grid-template-columns: 72px 1fr; }
3354
3687
  .route button { grid-column: 1 / -1; }
3355
3688
  }
3689
+ @media (max-width: 460px) {
3690
+ .controls label.field { min-width: calc(50% - 4px); }
3691
+ .controls .icon-btn, .controls .btn { flex: 1; }
3692
+ .grid { grid-template-columns: minmax(0, 1fr); }
3693
+ .dialog-actions { flex-wrap: wrap; }
3694
+ .dialog-actions button { flex: 1; }
3695
+ .dialog-actions .btn-danger { flex-basis: 100%; margin-right: 0; }
3696
+ }
3356
3697
  </style>
3357
3698
  </head>
3358
3699
  <body>
3359
3700
  <div class="app" data-service="${name}" data-mockingbird-admin>
3360
3701
  <header class="top">
3361
3702
  <div class="brand">
3362
- <div class="brand-id">
3363
- <strong>${name}</strong>
3364
- <span>Admin</span>
3703
+ <div class="brand-lockup">
3704
+ <div class="brand-mark" aria-hidden="true">
3705
+ <svg viewBox="0 0 24 24" fill="none"><path d="M5 17.5V7l7 5 7-5v10.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/><path d="M8 15.5 12 18l4-2.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>
3706
+ </div>
3707
+ <div class="brand-id">
3708
+ <strong>${name}</strong>
3709
+ <span>Mock admin</span>
3710
+ </div>
3365
3711
  </div>
3366
3712
  <div class="vendor" id="vendor" hidden></div>
3367
3713
  </div>
3368
3714
  <div class="controls">
3715
+ <span class="sync-status" id="sync-status" role="status" aria-live="polite">Ready</span>
3369
3716
  <label class="field">Namespace
3370
3717
  <select id="namespace" aria-label="Namespace"></select>
3371
3718
  </label>
3372
3719
  <label class="field">Admin key
3373
3720
  <input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
3374
3721
  </label>
3375
- <button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
3376
- <button class="btn" id="refresh" type="button">Refresh</button>
3722
+ <button class="icon-btn" id="theme" type="button" aria-label="Use dark theme" title="Use dark theme"></button>
3723
+ <button class="btn" id="refresh" type="button"><svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M15.8 7.2A6.2 6.2 0 1 0 16 12" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="M12.8 7.2h3v-3" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>Refresh</button>
3377
3724
  </div>
3378
3725
  </header>
3379
3726
  <div class="layout">
3380
3727
  <nav class="side" id="nav" aria-label="Admin sections">
3381
- <button type="button" data-view="overview" aria-current="true">Overview</button>
3382
- <button type="button" data-view="state">State</button>
3383
- <button type="button" data-view="clock">Clock</button>
3384
- <button type="button" data-view="faults">Faults</button>
3385
- <button type="button" data-view="journal">Journal</button>
3386
- <button type="button" data-view="routes">Routes</button>
3728
+ <span class="nav-label">Workspace</span>
3729
+ <button type="button" data-view="overview" aria-current="true"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><rect x="2.5" y="2.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="11.5" y="2.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="2.5" y="11.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="11.5" y="11.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/></svg></span>Overview</button>
3730
+ <button type="button" data-view="state"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><ellipse cx="10" cy="5" rx="6.5" ry="2.5" stroke="currentColor" stroke-width="1.5"/><path d="M3.5 5v5c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5V5M3.5 10v5c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5v-5" stroke="currentColor" stroke-width="1.5"/></svg></span>State</button>
3731
+ <button type="button" data-view="clock"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><circle cx="10" cy="10" r="7.5" stroke="currentColor" stroke-width="1.5"/><path d="M10 5.8v4.6l3 1.8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg></span>Clock</button>
3732
+ <button type="button" data-view="faults"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="m11.2 2.8-6.5 9h5.1l-1 5.4 6.5-9h-5.1l1-5.4Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></span>Faults</button>
3733
+ <button type="button" data-view="journal"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="M5 3.5h10a1.5 1.5 0 0 1 1.5 1.5v12l-2.2-1.4-2.2 1.4-2.1-1.4L7.8 17l-2.2-1.4L3.5 17V5A1.5 1.5 0 0 1 5 3.5Z" stroke="currentColor" stroke-width="1.5"/><path d="M6.7 7h6.6M6.7 10h6.6M6.7 13h3.8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg></span>Journal</button>
3734
+ <button type="button" data-view="routes"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="M6.5 4.5h7a2 2 0 0 1 2 2v7M13 11l2.5 2.5L18 11M13.5 15.5h-7a2 2 0 0 1-2-2v-7M7 9 4.5 6.5 2 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span>Routes</button>
3387
3735
  </nav>
3388
3736
  <main id="views">
3389
- <p class="banner" id="banner" role="alert"></p>
3737
+ <div class="banner" id="banner" role="alert"><span id="banner-message"></span><button id="banner-dismiss" type="button" aria-label="Dismiss error">\xD7</button></div>
3390
3738
  <section class="view" id="view-overview">
3391
- <h2>Overview</h2>
3392
- <p class="lede">Health, clock, and the collections this namespace is holding.</p>
3739
+ <div class="view-head"><div><h2>Overview</h2><p class="lede">Health, clock, and the collections this namespace is holding.</p></div></div>
3393
3740
  <div class="grid" id="overview-cards"></div>
3394
3741
  <h3>Recent requests</h3>
3395
3742
  <div id="overview-requests"></div>
3396
3743
  </section>
3397
3744
  <section class="view" id="view-state" hidden>
3398
- <h2>State</h2>
3399
- <p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
3745
+ <div class="view-head"><div><h2>State</h2><p class="lede">Inspect and edit every collection in this namespace.</p></div></div>
3400
3746
  <div class="split">
3401
3747
  <div id="collections"></div>
3402
3748
  <div>
@@ -3409,8 +3755,7 @@ var renderAdminDocument = (service) => {
3409
3755
  </div>
3410
3756
  </section>
3411
3757
  <section class="view" id="view-clock" hidden>
3412
- <h2>Clock</h2>
3413
- <p class="lede">The clock every timestamp in this mock reads.</p>
3758
+ <div class="view-head"><div><h2>Clock</h2><p class="lede">Control the source of time used by every timestamp in this mock.</p></div></div>
3414
3759
  <div class="card" id="clock-readout"></div>
3415
3760
  <div class="row-actions">
3416
3761
  <button class="btn" type="button" data-advance="60000">+1m</button>
@@ -3429,21 +3774,22 @@ var renderAdminDocument = (service) => {
3429
3774
  </form>
3430
3775
  </section>
3431
3776
  <section class="view" id="view-faults" hidden>
3432
- <h2>Faults</h2>
3433
- <p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
3777
+ <div class="view-head"><div><h2>Faults</h2><p class="lede">Test unhappy paths with a response, delay, or named preset scoped to this namespace.</p></div></div>
3434
3778
  <form id="fault-form" class="card stack">
3435
- <label class="field">Preset
3436
- <select id="fault-preset"><option value="">Custom rule</option></select>
3437
- </label>
3438
- <label class="field">Status
3439
- <input id="fault-status" inputmode="numeric" placeholder="503">
3440
- </label>
3441
- <label class="field">Path prefix
3442
- <input id="fault-path" placeholder="/v1">
3443
- </label>
3444
- <label class="field">Method
3445
- <input id="fault-method" placeholder="GET">
3446
- </label>
3779
+ <div class="form-grid">
3780
+ <label class="field wide">Preset
3781
+ <select id="fault-preset"><option value="">Custom rule</option></select>
3782
+ </label>
3783
+ <label class="field">Status
3784
+ <input id="fault-status" inputmode="numeric" placeholder="503">
3785
+ </label>
3786
+ <label class="field wide">Path prefix
3787
+ <input id="fault-path" placeholder="/v1">
3788
+ </label>
3789
+ <label class="field">Method
3790
+ <input id="fault-method" placeholder="GET">
3791
+ </label>
3792
+ </div>
3447
3793
  <div class="dialog-actions">
3448
3794
  <button class="btn-primary" type="submit">Add fault</button>
3449
3795
  <button class="btn-danger" id="fault-clear" type="button">Clear all</button>
@@ -3452,26 +3798,31 @@ var renderAdminDocument = (service) => {
3452
3798
  <div id="fault-list"></div>
3453
3799
  </section>
3454
3800
  <section class="view" id="view-journal" hidden>
3455
- <h2>Journal</h2>
3456
- <p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
3457
- <div class="row-actions">
3458
- <button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
3459
- </div>
3801
+ <div class="view-head"><div><h2>Journal</h2><p class="lede">Requests this namespace has seen. Bodies are never stored.</p></div><button class="btn-danger" id="journal-clear" type="button">Clear journal</button></div>
3460
3802
  <div id="journal"></div>
3461
3803
  </section>
3462
3804
  <section class="view" id="view-routes" hidden>
3463
- <h2>Routes</h2>
3464
- <p class="lede">Shared controls, plus any routes this mock adds. Extra routes are how a bespoke workflow shows up beside the default UI.</p>
3805
+ <div class="view-head"><div><h2>Routes</h2><p class="lede">Explore shared controls and service-specific admin endpoints.</p></div></div>
3806
+ <div class="route-tools">
3807
+ <label class="field">Filter routes
3808
+ <input id="route-search" type="search" placeholder="Method, path, or extension" autocomplete="off">
3809
+ </label>
3810
+ <span class="route-count" id="route-count"></span>
3811
+ </div>
3465
3812
  <div id="route-list"></div>
3466
- <form id="route-form" class="card stack">
3813
+ <form id="route-form" class="card stack" style="margin-top: 18px">
3467
3814
  <strong id="route-title">Select a route</strong>
3468
3815
  <label class="field">JSON body
3469
- <textarea id="route-body" placeholder="{ }"></textarea>
3816
+ <div class="json-editor" id="route-editor" hidden>
3817
+ <pre aria-hidden="true"><code id="route-highlight"></code></pre>
3818
+ <textarea id="route-body" placeholder="{ }" spellcheck="false" aria-describedby="route-json-status" disabled></textarea>
3819
+ </div>
3820
+ <span class="editor-meta" hidden><span class="json-status" id="route-json-status">Valid JSON</span><button class="format-json" type="button" data-format="route-body">Format JSON</button></span>
3470
3821
  </label>
3471
3822
  <div class="dialog-actions">
3472
- <button class="btn-primary" type="submit">Send</button>
3823
+ <button class="btn-primary" id="route-send" type="submit" disabled>Send request</button>
3473
3824
  </div>
3474
- <pre id="route-result">Response will show here.</pre>
3825
+ <pre class="json-view" id="route-result"><code>Response will show here.</code></pre>
3475
3826
  </form>
3476
3827
  </section>
3477
3828
  </main>
@@ -3479,12 +3830,16 @@ var renderAdminDocument = (service) => {
3479
3830
  </div>
3480
3831
  <dialog id="editor">
3481
3832
  <form method="dialog" id="editor-form">
3482
- <strong id="editor-title">Record</strong>
3833
+ <div class="dialog-heading"><div><strong id="editor-title">Record</strong><br><span>Edit the ID and JSON value stored in this collection.</span></div></div>
3483
3834
  <label class="field">Id
3484
3835
  <input id="editor-id" required>
3485
3836
  </label>
3486
3837
  <label class="field">JSON value
3487
- <textarea id="editor-value"></textarea>
3838
+ <div class="json-editor" id="record-editor">
3839
+ <pre aria-hidden="true"><code id="editor-highlight"></code></pre>
3840
+ <textarea id="editor-value" spellcheck="false" aria-describedby="editor-json-status"></textarea>
3841
+ </div>
3842
+ <span class="editor-meta"><span class="json-status" id="editor-json-status">Valid JSON</span><button class="format-json" type="button" data-format="editor-value">Format JSON</button></span>
3488
3843
  </label>
3489
3844
  <div class="dialog-actions">
3490
3845
  <button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
@@ -3526,8 +3881,8 @@ var describeExtension = (extension) => {
3526
3881
  ...extension.script !== void 0 ? { script: extension.script } : {}
3527
3882
  };
3528
3883
  };
3529
- var adminUiRoutes = (service, ui) => {
3530
- const shell = () => renderAdminDocument(service);
3884
+ var adminUiRoutes = (service, ui, adminPrefix = ADMIN_PREFIX) => {
3885
+ const shell = () => renderAdminDocument(service, adminPrefix);
3531
3886
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
3532
3887
  return {
3533
3888
  "GET /ui": () => htmlResponse(document3()),
@@ -4218,7 +4573,7 @@ var stateAdminRoutes = (routes) => {
4218
4573
  };
4219
4574
 
4220
4575
  // ../core/dist/version.js
4221
- var PACKAGE_VERSION = true ? "1.8.0" : UNRELEASED_VERSION;
4576
+ var PACKAGE_VERSION = true ? "2.0.0" : UNRELEASED_VERSION;
4222
4577
 
4223
4578
  // ../core/dist/signing.js
4224
4579
  var encoder = new TextEncoder();
@@ -4591,7 +4946,10 @@ var createWebhookHub = (options) => {
4591
4946
  };
4592
4947
  return hub;
4593
4948
  };
4594
- var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
4949
+ var json5 = (status, body) => new Response(JSON.stringify(body), {
4950
+ status,
4951
+ headers: { "content-type": "application/json; charset=utf-8" }
4952
+ });
4595
4953
  var adminError3 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
4596
4954
  var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4597
4955
  var parseEndpoint = (value) => {
@@ -4699,7 +5057,6 @@ var AT_HEADER = "x-mockingbird-at";
4699
5057
  var CHECKPOINT_HEADER = "x-mockingbird-checkpoint";
4700
5058
  var DEFAULT_NAMESPACE = "default";
4701
5059
  var NAMESPACE_PATTERN = /^[A-Za-z0-9_.-]{1,64}$/;
4702
- var PATH_PREFIX = /^\/ns\/([^/]+)(\/.*)?$/;
4703
5060
  var BRANCH_PATTERN2 = /^[A-Za-z0-9_.-]{1,64}$/;
4704
5061
  var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
4705
5062
  var effects = /* @__PURE__ */ new WeakMap();
@@ -4740,6 +5097,22 @@ var operationMatcher = (document3) => {
4740
5097
  return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
4741
5098
  };
4742
5099
  var createRuntime = (options) => {
5100
+ const adminPrefix = resolveAdminPrefix(options.adminPrefix);
5101
+ const internalPaths = Object.entries(options.document?.paths ?? {}).filter(([, item]) => item["x-mockingbird-internal"] === true).map(([path]) => path);
5102
+ for (const path of internalPaths) {
5103
+ if (!path.startsWith(`${ADMIN_PREFIX}/blobs/`))
5104
+ throw new Error(`internal transport ${path} must live under ${ADMIN_PREFIX}/blobs/`);
5105
+ }
5106
+ assertAdminPrefixAvailable(adminPrefix, Object.keys(options.document?.paths ?? {}).filter((path) => !internalPaths.includes(path)));
5107
+ const internalMatch = (path) => {
5108
+ for (const pattern of internalPaths) {
5109
+ const actual = path.split("/");
5110
+ const expected = pattern.split("/");
5111
+ if (actual.length === expected.length && expected.every((part, i) => part.startsWith("{") || part === actual[i]))
5112
+ return pattern;
5113
+ }
5114
+ return void 0;
5115
+ };
4743
5116
  assertAdminUi(options.adminUi);
4744
5117
  const sqlite = bootSqlite(options.sqlite);
4745
5118
  const clock = options.clock ?? createClock();
@@ -4785,6 +5158,7 @@ var createRuntime = (options) => {
4785
5158
  const created = options.create({
4786
5159
  namespace: storageNamespace(key),
4787
5160
  publicNamespace,
5161
+ adminPrefix,
4788
5162
  sqlite,
4789
5163
  clock: namespaceClock(publicNamespace),
4790
5164
  rng: createdContextRng
@@ -5017,10 +5391,10 @@ var createRuntime = (options) => {
5017
5391
  namespaceClock,
5018
5392
  namespaceOf(request) {
5019
5393
  const url = new URL(request.url);
5020
- const prefixed = PATH_PREFIX.exec(url.pathname);
5394
+ const prefixed = matchNamespacePath(url.pathname, adminPrefix);
5021
5395
  const selected = request.headers.get(NAMESPACE_HEADER) ?? (prefixed ? decodeURIComponent(prefixed[1]) : void 0);
5022
5396
  const path = prefixed ? prefixed[2] ?? "/" : url.pathname;
5023
- if (path === "/__admin" || path.startsWith("/__admin/"))
5397
+ if (isAdminPath(path, adminPrefix))
5024
5398
  return url.searchParams.get("namespace") ?? selected ?? DEFAULT_NAMESPACE;
5025
5399
  if (selected !== void 0)
5026
5400
  return selected;
@@ -5086,7 +5460,7 @@ var createRuntime = (options) => {
5086
5460
  state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
5087
5461
  fetch: async (incoming) => {
5088
5462
  let request = incoming;
5089
- const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
5463
+ const prefixed = matchNamespacePath(new URL(request.url).pathname, adminPrefix);
5090
5464
  if (prefixed) {
5091
5465
  const url2 = new URL(request.url);
5092
5466
  url2.pathname = prefixed[2] ?? "/";
@@ -5102,7 +5476,15 @@ var createRuntime = (options) => {
5102
5476
  signal: request.signal
5103
5477
  });
5104
5478
  }
5105
- let namespace = control.namespaceOf(request);
5479
+ const internalUrl = new URL(request.url);
5480
+ const internalPath = isAdminPath(internalUrl.pathname, adminPrefix) ? `${ADMIN_PREFIX}${internalUrl.pathname.slice(adminPrefix.length)}` : "";
5481
+ const internal = internalMatch(internalPath);
5482
+ const obsoleteInternalPath = adminPrefix !== ADMIN_PREFIX && internalMatch(internalUrl.pathname) && !internal;
5483
+ if (internal) {
5484
+ internalUrl.pathname = internalPath;
5485
+ request = new Request(internalUrl, request);
5486
+ }
5487
+ let namespace = internal ? internalUrl.searchParams.get("namespace") ?? control.namespaceOf(request) : control.namespaceOf(request);
5106
5488
  if (!request.headers.has(NAMESPACE_HEADER) && options.credential) {
5107
5489
  const credential = options.credential(request);
5108
5490
  const mapped = credential !== void 0 ? credentials.get(credential) : void 0;
@@ -5122,7 +5504,9 @@ var createRuntime = (options) => {
5122
5504
  return copy;
5123
5505
  }
5124
5506
  };
5125
- const handled = await control.handle(request);
5507
+ if (obsoleteInternalPath)
5508
+ return stamp(adminFail(404, "internal transport is only available under adminPrefix"));
5509
+ const handled = internal ? void 0 : await control.handle(request);
5126
5510
  if (handled)
5127
5511
  return stamp(handled);
5128
5512
  const started = monotonicNow();
@@ -5163,7 +5547,7 @@ var createRuntime = (options) => {
5163
5547
  type: "mockingbird_admin",
5164
5548
  message: `${NAMESPACE_HEADER} must match ${NAMESPACE_PATTERN}`
5165
5549
  }
5166
- }), { status: 400, headers: { "content-type": "application/json" } }));
5550
+ }), { status: 400, headers: { "content-type": "application/json; charset=utf-8" } }));
5167
5551
  }
5168
5552
  if (!BRANCH_PATTERN2.test(selectedBranch)) {
5169
5553
  log(400);
@@ -5280,15 +5664,16 @@ var createRuntime = (options) => {
5280
5664
  ...options.admin?.(runtime) ?? {},
5281
5665
  // Shell routes win a colliding key. Fault presets are one of them: the admin page
5282
5666
  // maps `presets`, and a service route must not replace that list with a record.
5283
- ...options.presets ? presetRoutes(options.presets, runtime) : {},
5667
+ ...options.presets ? presetRoutes(options.presets, runtime, adminPrefix) : {},
5284
5668
  ...stateAdminRoutes({
5285
5669
  open: stateScope,
5286
5670
  afterWrite: (namespace) => {
5287
5671
  checkpoint(namespace, "main");
5288
5672
  }
5289
5673
  }),
5290
- ...adminUiRoutes(options.name, options.adminUi)
5674
+ ...adminUiRoutes(options.name, options.adminUi, adminPrefix)
5291
5675
  },
5676
+ adminPrefix,
5292
5677
  adminKey: options.adminKey
5293
5678
  });
5294
5679
  return defineMock(runtime);
@@ -5302,7 +5687,10 @@ var mutableResponse = (response) => {
5302
5687
  return new Response(response.body, response);
5303
5688
  }
5304
5689
  };
5305
- var adminJson = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
5690
+ var adminJson = (status, body) => new Response(JSON.stringify(body), {
5691
+ status,
5692
+ headers: { "content-type": "application/json; charset=utf-8" }
5693
+ });
5306
5694
  var adminFail = (status, message) => adminJson(status, { error: { type: "mockingbird_admin", message } });
5307
5695
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5308
5696
  var credentialRoutes = (registry) => ({
@@ -5354,7 +5742,7 @@ var credentialRoutes = (registry) => ({
5354
5742
  return adminJson(200, { status: "ok" });
5355
5743
  }
5356
5744
  });
5357
- var presetRoutes = (presets, runtime) => ({
5745
+ var presetRoutes = (presets, runtime, adminPrefix) => ({
5358
5746
  "GET /faults/presets": () => {
5359
5747
  const body = {
5360
5748
  presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
@@ -5364,7 +5752,7 @@ var presetRoutes = (presets, runtime) => ({
5364
5752
  "POST /faults/presets/:name": ({ params, body, namespace }) => {
5365
5753
  const name = params.name;
5366
5754
  if (!presets[name])
5367
- return adminFail(404, `no fault preset ${name}; GET /__admin/faults/presets`);
5755
+ return adminFail(404, `no fault preset ${name}; GET ${adminPrefix}/faults/presets`);
5368
5756
  const overrides = isObject(body) ? body : {};
5369
5757
  return adminJson(201, { preset: name, rules: runtime.applyPreset(name, namespace, overrides) });
5370
5758
  }
@@ -5793,6 +6181,7 @@ var createRuntime2 = (options = {}) => {
5793
6181
  ...options.sqlite ? { sqlite: options.sqlite } : {},
5794
6182
  ...options.clock ? { clock: options.clock } : {},
5795
6183
  ...options.seed !== void 0 ? { seed: options.seed } : {},
6184
+ ...options.adminPrefix !== void 0 ? { adminPrefix: options.adminPrefix } : {},
5796
6185
  ...options.adminKey !== void 0 ? { adminKey: options.adminKey } : {},
5797
6186
  ...options.onLog ? { onLog: options.onLog } : {},
5798
6187
  credential: customerIoCredential,
@@ -6361,6 +6750,7 @@ var CustomerIoAPI = class {
6361
6750
 
6362
6751
  export {
6363
6752
  createClock,
6753
+ resolveAdminPrefix,
6364
6754
  parseDuration,
6365
6755
  document2 as document,
6366
6756
  operationIds,
@@ -6378,4 +6768,4 @@ export {
6378
6768
  customerIoCredential,
6379
6769
  CustomerIoAPI
6380
6770
  };
6381
- //# sourceMappingURL=chunk-BGWMLNP4.js.map
6771
+ //# sourceMappingURL=chunk-BOZCY34D.js.map