@crvouga/mockingbird-service-wholescripts 1.7.1 → 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()
@@ -183,29 +215,30 @@ var createControlPlane = (context) => {
183
215
  return json(200, { status: "ok", reset: target === "*" ? context.namespaces() : [target] });
184
216
  },
185
217
  "GET /namespaces": () => json(200, { default: context.defaultNamespace, namespaces: context.namespaces() }),
186
- "GET /clock": () => json(200, context.clock.state()),
187
- "POST /clock": ({ body }) => {
218
+ "GET /clock": ({ namespace }) => json(200, (context.namespaceClock?.(namespace) ?? context.clock).state()),
219
+ "POST /clock": ({ body, namespace }) => {
220
+ const clock = context.namespaceClock?.(namespace) ?? context.clock;
188
221
  if (!isRecord(body))
189
222
  return adminError(400, "expected a JSON object");
190
223
  if (body.reset === true)
191
- context.clock.reset();
224
+ clock.reset();
192
225
  if (body.freeze === true)
193
- context.clock.freeze();
226
+ clock.freeze();
194
227
  if (body.set !== void 0) {
195
228
  const instant = parseInstant(body.set);
196
229
  if (instant === void 0)
197
230
  return adminError(400, "set: expected epoch ms or ISO-8601");
198
- context.clock.set(instant);
231
+ clock.set(instant);
199
232
  }
200
233
  if (body.advance !== void 0) {
201
234
  const delta = parseDuration(body.advance);
202
235
  if (delta === void 0)
203
236
  return adminError(400, 'advance: expected ms or "15m"-style');
204
- context.clock.advance(delta);
237
+ clock.advance(delta);
205
238
  }
206
239
  if (body.freeze === false)
207
- context.clock.unfreeze();
208
- return json(200, context.clock.state());
240
+ clock.unfreeze();
241
+ return json(200, clock.state());
209
242
  },
210
243
  "GET /faults": () => json(200, { faults: context.faults.list() }),
211
244
  "POST /faults": ({ body, namespace }) => {
@@ -338,7 +371,14 @@ var createControlPlane = (context) => {
338
371
  return json(200, { status: "ok" });
339
372
  }
340
373
  };
341
- 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]) => {
342
382
  const space = key.indexOf(" ");
343
383
  return { method: key.slice(0, space), pattern: key.slice(space + 1), handler };
344
384
  });
@@ -346,21 +386,13 @@ var createControlPlane = (context) => {
346
386
  namespaceOf: headerNamespace,
347
387
  async handle(request) {
348
388
  const url = new URL(request.url);
349
- if (url.pathname === HEALTH_PATH && request.method === "GET") {
350
- return json(200, {
351
- status: "ok",
352
- service: context.name,
353
- uptimeMs: context.wallNow() - context.startedAt,
354
- clock: context.clock.state(),
355
- namespaces: context.namespaces().length,
356
- adminUi: `${ADMIN_PREFIX}/ui`,
357
- ...context.describe()
358
- });
389
+ if (url.pathname === `${adminPrefix}/health` && request.method === "GET") {
390
+ return health();
359
391
  }
360
- if (url.pathname !== ADMIN_PREFIX && !url.pathname.startsWith(`${ADMIN_PREFIX}/`)) {
392
+ if (!isAdminPath(url.pathname, adminPrefix)) {
361
393
  return void 0;
362
394
  }
363
- const path = url.pathname.slice(ADMIN_PREFIX.length) || "/";
395
+ const path = url.pathname.slice(adminPrefix.length) || "/";
364
396
  const shell = request.method === "GET" && (path === "/ui" || path === "/ui/");
365
397
  if (!shell && context.adminKey !== void 0 && request.headers.get(ADMIN_KEY_HEADER) !== context.adminKey) {
366
398
  return adminError(401, `missing or wrong ${ADMIN_KEY_HEADER}`);
@@ -368,7 +400,12 @@ var createControlPlane = (context) => {
368
400
  for (const route of routes) {
369
401
  if (route.method !== request.method)
370
402
  continue;
371
- 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
+ }
372
409
  if (!params)
373
410
  continue;
374
411
  let body;
@@ -377,15 +414,18 @@ var createControlPlane = (context) => {
377
414
  } catch {
378
415
  return adminError(400, "request body is not valid JSON");
379
416
  }
417
+ const namespace = adminNamespace(request, url);
418
+ if (!/^[A-Za-z0-9_.-]{1,64}$/.test(namespace))
419
+ return adminError(400, "invalid namespace");
380
420
  return route.handler({
381
421
  request,
382
422
  url,
383
423
  params,
384
- namespace: adminNamespace(request, url),
424
+ namespace,
385
425
  body
386
426
  });
387
427
  }
388
- 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`);
389
429
  }
390
430
  };
391
431
  };
@@ -485,7 +525,33 @@ var faultResponse = (rule) => {
485
525
  };
486
526
  var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) => {
487
527
  const entries = [];
528
+ let isolated = false;
529
+ const scopedRngs = /* @__PURE__ */ new Map();
530
+ const random = (namespace) => {
531
+ if (!isolated || namespace === "default")
532
+ return rng;
533
+ let scoped = scopedRngs.get(namespace);
534
+ if (!scoped) {
535
+ scoped = createRng(rng.seed);
536
+ scopedRngs.set(namespace, scoped);
537
+ }
538
+ return scoped;
539
+ };
488
540
  return {
541
+ isolateNamespaces() {
542
+ isolated = true;
543
+ },
544
+ snapshot(namespace) {
545
+ return {
546
+ rules: structuredClone(entries.map((entry, position) => ({
547
+ ...entry.rule,
548
+ remaining: entry.remaining,
549
+ hits: entry.hits,
550
+ position
551
+ })).filter((entry) => entry.namespace === namespace)),
552
+ rngState: random(namespace).state()
553
+ };
554
+ },
489
555
  add(rule) {
490
556
  const existing = entries.findIndex((e) => e.rule.id === rule.id);
491
557
  const entry = { rule, remaining: rule.count ?? null, hits: 0 };
@@ -505,6 +571,16 @@ var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((reso
505
571
  },
506
572
  clear() {
507
573
  entries.length = 0;
574
+ rng.reset();
575
+ scopedRngs.clear();
576
+ },
577
+ restore(namespace, state) {
578
+ for (let i = entries.length - 1; i >= 0; i--)
579
+ if (entries[i]?.rule.namespace === namespace)
580
+ entries.splice(i, 1);
581
+ for (const { remaining, hits, position, ...rule } of state.rules)
582
+ entries.splice(Math.min(position, entries.length), 0, { rule, remaining, hits });
583
+ random(namespace).setState(state.rngState);
508
584
  },
509
585
  async take(candidate) {
510
586
  const hits = [];
@@ -514,7 +590,7 @@ var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((reso
514
590
  if (!matches(entry.rule, candidate))
515
591
  continue;
516
592
  const rate = entry.rule.rate ?? 1;
517
- if (rng.next() >= rate)
593
+ if (random(candidate.namespace).next() >= rate)
518
594
  continue;
519
595
  entry.hits++;
520
596
  if (entry.remaining !== null)
@@ -1063,7 +1139,8 @@ var annotateResponse = (response, extra) => {
1063
1139
  var responseNotes = (response) => notes.get(response);
1064
1140
 
1065
1141
  // ../core/dist/metrics.js
1066
- var createMetrics = () => {
1142
+ var createMetrics = (partition = true) => {
1143
+ const namespaces = /* @__PURE__ */ new Map();
1067
1144
  let requests = 0;
1068
1145
  let faults = 0;
1069
1146
  let totalDurationMs = 0;
@@ -1071,6 +1148,14 @@ var createMetrics = () => {
1071
1148
  const unmatched = /* @__PURE__ */ new Map();
1072
1149
  return {
1073
1150
  record(entry) {
1151
+ if (partition) {
1152
+ let scoped = namespaces.get(entry.namespace);
1153
+ if (!scoped) {
1154
+ scoped = createMetrics(false);
1155
+ namespaces.set(entry.namespace, scoped);
1156
+ }
1157
+ scoped.record(entry);
1158
+ }
1074
1159
  requests++;
1075
1160
  totalDurationMs += entry.durationMs;
1076
1161
  if (entry.faultId !== void 0)
@@ -1082,7 +1167,7 @@ var createMetrics = () => {
1082
1167
  unmatched.set(route, (unmatched.get(route) ?? 0) + 1);
1083
1168
  }
1084
1169
  },
1085
- report: () => ({
1170
+ report: (namespace) => namespace !== void 0 ? (namespaces.get(namespace) ?? createMetrics(false)).report() : {
1086
1171
  requests,
1087
1172
  byOperation: Object.fromEntries([...byOperation].sort(([a], [b]) => a.localeCompare(b))),
1088
1173
  unmatched: [...unmatched].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([route, count]) => {
@@ -1091,8 +1176,13 @@ var createMetrics = () => {
1091
1176
  }),
1092
1177
  faults,
1093
1178
  totalDurationMs
1094
- }),
1095
- reset() {
1179
+ },
1180
+ reset(namespace) {
1181
+ if (namespace !== void 0) {
1182
+ namespaces.delete(namespace);
1183
+ return;
1184
+ }
1185
+ namespaces.clear();
1096
1186
  requests = 0;
1097
1187
  faults = 0;
1098
1188
  totalDurationMs = 0;
@@ -1705,6 +1795,34 @@ dialog:not([open]) {
1705
1795
  function isRecord2(value) {
1706
1796
  return typeof value === "object" && value !== null && !Array.isArray(value);
1707
1797
  }
1798
+ function highlightJsonText(text) {
1799
+ const escapeToken = (value) => value.replace(/[&<>"']/g, (char) => {
1800
+ switch (char) {
1801
+ case "&":
1802
+ return "&amp;";
1803
+ case "<":
1804
+ return "&lt;";
1805
+ case ">":
1806
+ return "&gt;";
1807
+ case '"':
1808
+ return "&quot;";
1809
+ default:
1810
+ return "&#39;";
1811
+ }
1812
+ });
1813
+ 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;
1814
+ let cursor = 0;
1815
+ let html = "";
1816
+ for (const match of text.matchAll(token)) {
1817
+ const index = match.index ?? 0;
1818
+ const value = match[0];
1819
+ html += escapeToken(text.slice(cursor, index));
1820
+ const kind = value.startsWith('"') ? value.trimEnd().endsWith(":") ? "key" : "string" : value === "true" || value === "false" ? "boolean" : value === "null" ? "null" : "number";
1821
+ html += `<span class="json-${kind}">${escapeToken(value)}</span>`;
1822
+ cursor = index + value.length;
1823
+ }
1824
+ return html + escapeToken(text.slice(cursor));
1825
+ }
1708
1826
  function mountAdminBrand(doc, host, service, catalog) {
1709
1827
  const clip = (value, max) => {
1710
1828
  if (typeof value !== "string")
@@ -2066,14 +2184,16 @@ function bootAdmin(config) {
2066
2184
  const state = {
2067
2185
  namespace: "default",
2068
2186
  key: sessionStorage.getItem("mockingbird-admin-key") || "",
2069
- view: "overview",
2187
+ view: ["overview", "state", "clock", "faults", "journal", "routes"].includes(location.hash.slice(1)) ? location.hash.slice(1) : "overview",
2070
2188
  collection: "",
2071
2189
  shape: null,
2072
2190
  route: null,
2191
+ routes: [],
2073
2192
  editing: null
2074
2193
  };
2075
2194
  const standard = new Set(config.standardRoutes);
2076
2195
  const banner = el("banner", HTMLElement);
2196
+ const bannerMessage = el("banner-message", HTMLElement);
2077
2197
  const keyInput = el("admin-key", HTMLInputElement);
2078
2198
  keyInput.value = state.key;
2079
2199
  const params = new URLSearchParams(location.search);
@@ -2084,18 +2204,21 @@ function bootAdmin(config) {
2084
2204
  sessionStorage.setItem("mockingbird-admin-key", state.key);
2085
2205
  params.delete("key");
2086
2206
  const next = params.toString();
2087
- history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
2207
+ history.replaceState(null, "", location.pathname + (next ? `?${next}` : "") + location.hash);
2088
2208
  }
2089
2209
  const queryNamespace = params.get("namespace");
2090
2210
  if (queryNamespace)
2091
2211
  state.namespace = queryNamespace;
2092
2212
  const showError = (error) => {
2093
- banner.textContent = error instanceof Error ? error.message : String(error);
2213
+ bannerMessage.textContent = error instanceof Error ? error.message : String(error);
2094
2214
  banner.classList.add("show");
2215
+ banner.scrollIntoView({ behavior: "smooth", block: "nearest" });
2095
2216
  };
2096
2217
  const clearError = () => {
2097
2218
  banner.classList.remove("show");
2219
+ bannerMessage.textContent = "";
2098
2220
  };
2221
+ el("banner-dismiss", HTMLButtonElement).addEventListener("click", clearError);
2099
2222
  const api = async (method, path, body) => {
2100
2223
  const headers = { accept: "application/json" };
2101
2224
  if (state.key !== "")
@@ -2139,16 +2262,21 @@ function bootAdmin(config) {
2139
2262
  namespace: () => state.namespace
2140
2263
  };
2141
2264
  const isPanelScript = (value) => typeof value === "function";
2265
+ const themeButton = el("theme", HTMLButtonElement);
2142
2266
  const setTheme = (theme) => {
2143
2267
  if (theme)
2144
2268
  document.documentElement.dataset.theme = theme;
2145
2269
  else
2146
2270
  delete document.documentElement.dataset.theme;
2271
+ const dark = theme ? theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2272
+ 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>';
2273
+ const label = dark ? "Use light theme" : "Use dark theme";
2274
+ themeButton.setAttribute("aria-label", label);
2275
+ themeButton.title = label;
2147
2276
  };
2148
2277
  const storedTheme = localStorage.getItem("mockingbird-admin-theme");
2149
- if (storedTheme)
2150
- setTheme(storedTheme);
2151
- el("theme", HTMLButtonElement).addEventListener("click", () => {
2278
+ setTheme(storedTheme === "dark" || storedTheme === "light" ? storedTheme : null);
2279
+ themeButton.addEventListener("click", () => {
2152
2280
  const current = document.documentElement.dataset.theme;
2153
2281
  const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2154
2282
  const next = dark ? "light" : "dark";
@@ -2167,6 +2295,7 @@ function bootAdmin(config) {
2167
2295
  continue;
2168
2296
  section.hidden = section.id !== `view-${view}`;
2169
2297
  }
2298
+ history.replaceState(null, "", `${location.pathname}${location.search}#${encodeURIComponent(view)}`);
2170
2299
  };
2171
2300
  el("nav", HTMLElement).addEventListener("click", (event) => {
2172
2301
  const target = event.target;
@@ -2181,7 +2310,7 @@ function bootAdmin(config) {
2181
2310
  show(view);
2182
2311
  refresh().catch(showError);
2183
2312
  });
2184
- 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>`;
2313
+ 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>`;
2185
2314
  const table = (columns, rows) => {
2186
2315
  if (rows.length === 0)
2187
2316
  return '<p class="empty">Nothing here yet.</p>';
@@ -2191,16 +2320,22 @@ function bootAdmin(config) {
2191
2320
  const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
2192
2321
  return `<tr${attrs}>${cells}</tr>`;
2193
2322
  }).join("");
2194
- return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
2323
+ return `<div class="table-shell"><table><thead>${head}</thead><tbody>${body}</tbody></table></div>`;
2195
2324
  };
2196
2325
  const preview = (value) => {
2197
2326
  const text = JSON.stringify(value) ?? "null";
2198
- return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
2327
+ const clipped = text.length > 180 ? `${text.slice(0, 180)}\u2026` : text;
2328
+ return `<code class="json-inline">${highlightJsonText(clipped)}</code>`;
2199
2329
  };
2200
2330
  const when = (epoch) => {
2201
2331
  const date = new Date(epoch);
2202
2332
  return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
2203
2333
  };
2334
+ const journalWhen = (value) => {
2335
+ const numeric = value.trim() === "" ? Number.NaN : Number(value);
2336
+ const epoch = Number.isFinite(numeric) ? numeric : Date.parse(value);
2337
+ return Number.isFinite(epoch) ? when(epoch) : value;
2338
+ };
2204
2339
  const clockCard = (epoch) => {
2205
2340
  const date = new Date(epoch);
2206
2341
  if (Number.isNaN(date.getTime()))
@@ -2320,7 +2455,7 @@ function bootAdmin(config) {
2320
2455
  };
2321
2456
  const renderOverview = async () => {
2322
2457
  const [health, shape, clock, journal] = await Promise.all([
2323
- originGet("/health"),
2458
+ originGet(`${config.adminPrefix}/health`),
2324
2459
  api("GET", "/state"),
2325
2460
  api("GET", "/clock"),
2326
2461
  api("GET", "/requests?limit=8")
@@ -2337,7 +2472,7 @@ function bootAdmin(config) {
2337
2472
  },
2338
2473
  {
2339
2474
  k: "Status",
2340
- v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
2475
+ v: `<span class="badge ok">${esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")}</span>`
2341
2476
  },
2342
2477
  { k: "Namespace", v: esc(state.namespace) },
2343
2478
  { k: "Collections", v: String(decoded.collections.length) },
@@ -2424,26 +2559,46 @@ function bootAdmin(config) {
2424
2559
  const renderJournal = async () => {
2425
2560
  const journal = await api("GET", "/requests?limit=100");
2426
2561
  el("journal", HTMLElement).innerHTML = table([
2427
- { label: "When", cell: (row) => esc(row.at) },
2428
- { label: "Method", cell: (row) => esc(row.method) },
2562
+ { label: "When", cell: (row) => esc(journalWhen(row.at)) },
2563
+ {
2564
+ label: "Method",
2565
+ cell: (row) => `<span class="method">${esc(row.method)}</span>`
2566
+ },
2429
2567
  { label: "Path", cell: (row) => esc(row.path) },
2430
- { label: "Status", cell: (row) => esc(row.status) },
2568
+ {
2569
+ label: "Status",
2570
+ cell: (row) => `<span class="badge ${row.status.startsWith("2") ? "ok" : row.status.startsWith("4") || row.status.startsWith("5") ? "warn" : ""}">${esc(row.status)}</span>`
2571
+ },
2431
2572
  { label: "ms", cell: (row) => esc(row.durationMs) }
2432
2573
  ], decodeJournal(journal));
2433
2574
  };
2434
- const renderRoutes = async () => {
2435
- const data = await api("GET", "/");
2436
- if (!isRecord2(data))
2437
- throw new Error("Route list was not an object");
2438
- const routes = requireList(data.routes, "Routes").map((route) => String(route));
2575
+ const paintRoutes = () => {
2576
+ const query = el("route-search", HTMLInputElement).value.trim().toLocaleLowerCase();
2577
+ const routes = state.routes.filter((route) => route.toLocaleLowerCase().includes(query));
2578
+ el("route-count", HTMLElement).textContent = `${routes.length} of ${state.routes.length}`;
2579
+ if (state.routes.length === 0) {
2580
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No admin routes are available.</p>';
2581
+ return;
2582
+ }
2583
+ if (routes.length === 0) {
2584
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No routes match this filter.</p>';
2585
+ return;
2586
+ }
2439
2587
  el("route-list", HTMLElement).innerHTML = routes.map((route) => {
2440
2588
  const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
2441
2589
  const parts = route.split(" ");
2442
2590
  const method = parts[0] ?? "";
2443
2591
  const path = parts.slice(1).join(" ");
2444
- 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>`;
2592
+ 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>`;
2445
2593
  }).join("");
2446
2594
  };
2595
+ const renderRoutes = async () => {
2596
+ const data = await api("GET", "/");
2597
+ if (!isRecord2(data))
2598
+ throw new Error("Route list was not an object");
2599
+ state.routes = requireList(data.routes, "Routes").map((route) => String(route));
2600
+ paintRoutes();
2601
+ };
2447
2602
  const renderers = {
2448
2603
  overview: renderOverview,
2449
2604
  state: renderState,
@@ -2452,19 +2607,50 @@ function bootAdmin(config) {
2452
2607
  journal: renderJournal,
2453
2608
  routes: renderRoutes
2454
2609
  };
2610
+ let refreshToken = 0;
2455
2611
  async function refresh() {
2612
+ const token = ++refreshToken;
2456
2613
  clearError();
2614
+ const main = el("views", HTMLElement);
2615
+ const sync = el("sync-status", HTMLElement);
2616
+ main.setAttribute("aria-busy", "true");
2617
+ sync.classList.add("busy");
2618
+ sync.textContent = "Updating";
2457
2619
  const render = renderers[state.view];
2458
- if (render)
2459
- await render();
2620
+ try {
2621
+ if (render)
2622
+ await render();
2623
+ if (token === refreshToken)
2624
+ sync.textContent = "Up to date";
2625
+ } finally {
2626
+ if (token === refreshToken) {
2627
+ main.removeAttribute("aria-busy");
2628
+ sync.classList.remove("busy");
2629
+ }
2630
+ }
2460
2631
  }
2461
2632
  const delay = (ms) => new Promise((resolve) => {
2462
2633
  window.setTimeout(resolve, ms);
2463
2634
  });
2464
- const confirmAction = async (button, pending, done, work) => {
2635
+ const confirmAction = async (button, pending, done, work, confirmLabel) => {
2465
2636
  if (button.dataset.pending === "1")
2466
2637
  return;
2467
2638
  const label = button.textContent ?? "";
2639
+ if (confirmLabel !== void 0 && button.dataset.confirming !== "1") {
2640
+ button.dataset.confirming = "1";
2641
+ button.classList.add("confirming");
2642
+ button.textContent = confirmLabel;
2643
+ window.setTimeout(() => {
2644
+ if (button.dataset.confirming !== "1")
2645
+ return;
2646
+ button.textContent = label;
2647
+ button.classList.remove("confirming");
2648
+ delete button.dataset.confirming;
2649
+ }, 3e3);
2650
+ return;
2651
+ }
2652
+ button.classList.remove("confirming");
2653
+ delete button.dataset.confirming;
2468
2654
  const width = button.offsetWidth;
2469
2655
  button.dataset.pending = "1";
2470
2656
  button.classList.add("pressed");
@@ -2485,6 +2671,65 @@ function bootAdmin(config) {
2485
2671
  delete button.dataset.pending;
2486
2672
  }
2487
2673
  };
2674
+ const wireJsonEditor = (textareaId, highlightId, statusId, shellId, allowEmpty) => {
2675
+ const textarea = el(textareaId, HTMLTextAreaElement);
2676
+ const highlight = el(highlightId, HTMLElement);
2677
+ const status = el(statusId, HTMLElement);
2678
+ const shell = el(shellId, HTMLElement);
2679
+ const sync = () => {
2680
+ const text = textarea.value;
2681
+ highlight.innerHTML = `${highlightJsonText(text)}
2682
+ `;
2683
+ let valid = true;
2684
+ let message = "Valid JSON";
2685
+ if (allowEmpty && text.trim() === "")
2686
+ message = "No body";
2687
+ else {
2688
+ try {
2689
+ readJson2(text);
2690
+ } catch {
2691
+ valid = false;
2692
+ message = "Invalid JSON";
2693
+ }
2694
+ }
2695
+ shell.classList.toggle("invalid", !valid);
2696
+ status.classList.toggle("invalid", !valid);
2697
+ status.textContent = message;
2698
+ textarea.setAttribute("aria-invalid", valid ? "false" : "true");
2699
+ };
2700
+ const syncScroll = () => {
2701
+ const preview2 = highlight.parentElement;
2702
+ if (!(preview2 instanceof HTMLElement))
2703
+ return;
2704
+ preview2.scrollTop = textarea.scrollTop;
2705
+ preview2.scrollLeft = textarea.scrollLeft;
2706
+ };
2707
+ textarea.addEventListener("input", sync);
2708
+ textarea.addEventListener("scroll", syncScroll);
2709
+ sync();
2710
+ return sync;
2711
+ };
2712
+ const syncRouteEditor = wireJsonEditor("route-body", "route-highlight", "route-json-status", "route-editor", true);
2713
+ const syncRecordEditor = wireJsonEditor("editor-value", "editor-highlight", "editor-json-status", "record-editor", false);
2714
+ for (const button of document.querySelectorAll("[data-format]")) {
2715
+ if (!(button instanceof HTMLButtonElement))
2716
+ continue;
2717
+ button.addEventListener("click", () => {
2718
+ const target = button.dataset.format;
2719
+ if (target === void 0)
2720
+ return;
2721
+ const textarea = document.getElementById(target);
2722
+ if (!(textarea instanceof HTMLTextAreaElement) || textarea.value.trim() === "")
2723
+ return;
2724
+ try {
2725
+ textarea.value = JSON.stringify(readJson2(textarea.value), null, 2) ?? "";
2726
+ textarea.dispatchEvent(new Event("input"));
2727
+ textarea.focus();
2728
+ } catch {
2729
+ showError(new Error("Fix the JSON before formatting it"));
2730
+ }
2731
+ });
2732
+ }
2488
2733
  document.addEventListener("click", (event) => {
2489
2734
  const target = event.target;
2490
2735
  if (!(target instanceof Element))
@@ -2557,6 +2802,7 @@ function bootAdmin(config) {
2557
2802
  } else {
2558
2803
  editorValue.value = "{\n \n}";
2559
2804
  }
2805
+ syncRecordEditor();
2560
2806
  editor.showModal();
2561
2807
  }
2562
2808
  el("new-record", HTMLButtonElement).addEventListener("click", () => {
@@ -2586,10 +2832,10 @@ function bootAdmin(config) {
2586
2832
  const id = state.editing;
2587
2833
  if (!id)
2588
2834
  return;
2589
- api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2835
+ confirmAction(editorDelete, "Deleting...", "Deleted", () => api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2590
2836
  editor.close();
2591
2837
  return renderState();
2592
- }).catch(showError);
2838
+ }), "Confirm delete").catch(showError);
2593
2839
  });
2594
2840
  for (const button of document.querySelectorAll("[data-advance]")) {
2595
2841
  if (!(button instanceof HTMLButtonElement))
@@ -2635,10 +2881,10 @@ function bootAdmin(config) {
2635
2881
  }).then(() => renderFaults()).catch(showError);
2636
2882
  });
2637
2883
  el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
2638
- confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults())).catch(showError);
2884
+ confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults()), "Confirm clear").catch(showError);
2639
2885
  });
2640
2886
  el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
2641
- confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal())).catch(showError);
2887
+ confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal()), "Confirm clear").catch(showError);
2642
2888
  });
2643
2889
  el("route-list", HTMLElement).addEventListener("click", (event) => {
2644
2890
  const target = event.target;
@@ -2652,9 +2898,15 @@ function bootAdmin(config) {
2652
2898
  return;
2653
2899
  state.route = route;
2654
2900
  el("route-title", HTMLElement).textContent = route;
2901
+ el("route-send", HTMLButtonElement).disabled = false;
2655
2902
  const method = route.split(" ")[0] ?? "";
2656
- el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
2903
+ const routeBody = el("route-body", HTMLTextAreaElement);
2904
+ routeBody.disabled = method === "GET" || method === "DELETE";
2905
+ el("route-editor", HTMLElement).hidden = routeBody.disabled;
2906
+ el("route-json-status", HTMLElement).parentElement?.toggleAttribute("hidden", routeBody.disabled);
2907
+ syncRouteEditor();
2657
2908
  });
2909
+ el("route-search", HTMLInputElement).addEventListener("input", paintRoutes);
2658
2910
  el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
2659
2911
  event.preventDefault();
2660
2912
  const send = async () => {
@@ -2676,7 +2928,8 @@ function bootAdmin(config) {
2676
2928
  }
2677
2929
  }
2678
2930
  const data = await api(method, concrete, body);
2679
- el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
2931
+ const text = JSON.stringify(data, null, 2) ?? "null";
2932
+ el("route-result", HTMLElement).innerHTML = `<code>${highlightJsonText(text)}</code>`;
2680
2933
  };
2681
2934
  send().catch(showError);
2682
2935
  });
@@ -2794,11 +3047,13 @@ function bootAdmin(config) {
2794
3047
  views.append(section);
2795
3048
  mountSqlExplorer(body, panelApi);
2796
3049
  }
3050
+ show(document.getElementById(`view-${state.view}`) === null ? "overview" : state.view);
2797
3051
  return refresh();
2798
3052
  }).catch(showError);
2799
3053
  }
2800
3054
  var clientPrelude = [
2801
3055
  isRecord2,
3056
+ highlightJsonText,
2802
3057
  mountAdminBrand,
2803
3058
  startAdminBrand,
2804
3059
  faultPresetList,
@@ -2821,6 +3076,7 @@ ${entry}(${payload});
2821
3076
  var defineMock = (runtime) => runtime;
2822
3077
  var STANDARD_ADMIN_ROUTES = [
2823
3078
  "GET /",
3079
+ "GET /health",
2824
3080
  "POST /reset",
2825
3081
  "GET /namespaces",
2826
3082
  "GET /clock",
@@ -2900,11 +3156,11 @@ var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
2900
3156
  }
2901
3157
  });
2902
3158
  var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
2903
- var renderAdminDocument = (service) => {
3159
+ var renderAdminDocument = (service, adminPrefix = ADMIN_PREFIX) => {
2904
3160
  const name = escapeHtml(service);
2905
3161
  const script = adminClientSource({
2906
3162
  standardRoutes: STANDARD_ADMIN_ROUTES,
2907
- adminPrefix: ADMIN_PREFIX,
3163
+ adminPrefix,
2908
3164
  adminKeyHeader: ADMIN_KEY_HEADER,
2909
3165
  brandsUrl: ADMIN_BRANDS_URL,
2910
3166
  service
@@ -2921,75 +3177,99 @@ var renderAdminDocument = (service) => {
2921
3177
  ${CSS_RESET}
2922
3178
  :root {
2923
3179
  color-scheme: light;
2924
- --bg: #fafafa;
3180
+ --bg: #f7f8fb;
2925
3181
  --bg-elev: #ffffff;
2926
- --bg-muted: #f4f4f5;
2927
- --bg-inset: #f4f4f5;
2928
- --line: #dedee3;
2929
- --line-strong: #c4c4cc;
2930
- --ink: #18181b;
2931
- --muted: #62626b;
2932
- --faint: #71717a;
2933
- --accent: #27272a;
3182
+ --bg-muted: #f1f3f7;
3183
+ --bg-inset: #f8f9fc;
3184
+ --line: #e4e7ec;
3185
+ --line-strong: #cfd4dc;
3186
+ --ink: #101828;
3187
+ --muted: #475467;
3188
+ --faint: #667085;
3189
+ --accent: #6941c6;
3190
+ --accent-hover: #5933b4;
2934
3191
  --accent-ink: #ffffff;
2935
- --accent-soft: #f4f4f5;
2936
- --ok: #166534;
2937
- --ok-soft: #f0fdf4;
2938
- --warn: #a16207;
2939
- --warn-soft: #fefce8;
2940
- --err: #a82d32;
2941
- --err-soft: #fef2f2;
2942
- --shadow: none;
3192
+ --accent-soft: #f4f0ff;
3193
+ --ok: #067647;
3194
+ --ok-soft: #ecfdf3;
3195
+ --warn: #b54708;
3196
+ --warn-soft: #fffaeb;
3197
+ --err: #b42318;
3198
+ --err-soft: #fef3f2;
3199
+ --code-key: #6941c6;
3200
+ --code-string: #067647;
3201
+ --code-number: #175cd3;
3202
+ --code-boolean: #c11574;
3203
+ --code-null: #667085;
3204
+ --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.05);
3205
+ --shadow-sm: 0 1px 3px rgb(16 24 40 / 0.08), 0 1px 2px rgb(16 24 40 / 0.04);
3206
+ --shadow-lg: 0 18px 48px rgb(16 24 40 / 0.16), 0 4px 12px rgb(16 24 40 / 0.08);
2943
3207
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
2944
3208
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
2945
- --radius: 10px;
2946
- --header: 56px;
2947
- --nav: 200px;
3209
+ --radius: 12px;
3210
+ --header: 72px;
3211
+ --nav: 224px;
2948
3212
  }
2949
3213
  :root[data-theme="dark"] {
2950
3214
  color-scheme: dark;
2951
- --bg: #111113;
2952
- --bg-elev: #19191c;
2953
- --bg-muted: #242428;
2954
- --bg-inset: #111113;
2955
- --line: #36363c;
2956
- --line-strong: #52525b;
2957
- --ink: #f4f4f5;
2958
- --muted: #a9a9b2;
2959
- --faint: #71717a;
2960
- --accent: #e4e4e7;
2961
- --accent-ink: #18181b;
2962
- --accent-soft: #242428;
2963
- --ok: #86efac;
2964
- --ok-soft: #14241b;
2965
- --warn: #fde68a;
2966
- --warn-soft: #2a2410;
2967
- --err: #ffaaaa;
2968
- --err-soft: #2c1516;
2969
- --shadow: none;
3215
+ --bg: #0c0e14;
3216
+ --bg-elev: #151821;
3217
+ --bg-muted: #20232e;
3218
+ --bg-inset: #11141c;
3219
+ --line: #2b303d;
3220
+ --line-strong: #414858;
3221
+ --ink: #f5f7fa;
3222
+ --muted: #b6bdc9;
3223
+ --faint: #8d96a7;
3224
+ --accent: #9e77ed;
3225
+ --accent-hover: #b692f6;
3226
+ --accent-ink: #ffffff;
3227
+ --accent-soft: #2b2142;
3228
+ --ok: #75e0a7;
3229
+ --ok-soft: #102a20;
3230
+ --warn: #fec84b;
3231
+ --warn-soft: #302611;
3232
+ --err: #fda29b;
3233
+ --err-soft: #321817;
3234
+ --code-key: #c3a6ff;
3235
+ --code-string: #75e0a7;
3236
+ --code-number: #84adff;
3237
+ --code-boolean: #f9a8d4;
3238
+ --code-null: #98a2b3;
3239
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3240
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3241
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
2970
3242
  }
2971
3243
  @media (prefers-color-scheme: dark) {
2972
3244
  :root:not([data-theme="light"]) {
2973
3245
  color-scheme: dark;
2974
- --bg: #111113;
2975
- --bg-elev: #19191c;
2976
- --bg-muted: #242428;
2977
- --bg-inset: #111113;
2978
- --line: #36363c;
2979
- --line-strong: #52525b;
2980
- --ink: #f4f4f5;
2981
- --muted: #a9a9b2;
2982
- --faint: #71717a;
2983
- --accent: #e4e4e7;
2984
- --accent-ink: #18181b;
2985
- --accent-soft: #242428;
2986
- --ok: #86efac;
2987
- --ok-soft: #14241b;
2988
- --warn: #fde68a;
2989
- --warn-soft: #2a2410;
2990
- --err: #ffaaaa;
2991
- --err-soft: #2c1516;
2992
- --shadow: none;
3246
+ --bg: #0c0e14;
3247
+ --bg-elev: #151821;
3248
+ --bg-muted: #20232e;
3249
+ --bg-inset: #11141c;
3250
+ --line: #2b303d;
3251
+ --line-strong: #414858;
3252
+ --ink: #f5f7fa;
3253
+ --muted: #b6bdc9;
3254
+ --faint: #8d96a7;
3255
+ --accent: #9e77ed;
3256
+ --accent-hover: #b692f6;
3257
+ --accent-ink: #ffffff;
3258
+ --accent-soft: #2b2142;
3259
+ --ok: #75e0a7;
3260
+ --ok-soft: #102a20;
3261
+ --warn: #fec84b;
3262
+ --warn-soft: #302611;
3263
+ --err: #fda29b;
3264
+ --err-soft: #321817;
3265
+ --code-key: #c3a6ff;
3266
+ --code-string: #75e0a7;
3267
+ --code-number: #84adff;
3268
+ --code-boolean: #f9a8d4;
3269
+ --code-null: #98a2b3;
3270
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3271
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3272
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
2993
3273
  }
2994
3274
  }
2995
3275
  /* Fill the viewport, then grow with the content so the background covers the scroll. */
@@ -3007,13 +3287,17 @@ var renderAdminDocument = (service) => {
3007
3287
  padding-right: env(safe-area-inset-right);
3008
3288
  -webkit-text-size-adjust: 100%;
3009
3289
  }
3010
- :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
3290
+ ::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
3291
+ :focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
3292
+ button, input, select, textarea { transition: border-color 140ms ease, box-shadow 140ms ease, transform 100ms ease; }
3293
+ button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.55; }
3011
3294
  .app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
3012
3295
  header.top {
3013
- position: sticky; top: 0; z-index: 5;
3296
+ position: sticky; top: 0; z-index: 20;
3014
3297
  display: flex; align-items: center; gap: 12px;
3015
- min-height: var(--header); padding: 10px 16px;
3016
- background: var(--bg-elev);
3298
+ min-height: var(--header); padding: 12px 20px;
3299
+ background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
3300
+ backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
3017
3301
  border-bottom: 1px solid var(--line);
3018
3302
  min-width: 0; max-width: 100%;
3019
3303
  }
@@ -3021,12 +3305,21 @@ var renderAdminDocument = (service) => {
3021
3305
  display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
3022
3306
  min-width: 0; max-width: 100%; margin-right: auto;
3023
3307
  }
3024
- .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
3025
- .brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
3308
+ .brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
3309
+ .brand-mark {
3310
+ width: 38px; height: 38px; display: grid; place-items: center; flex: none;
3311
+ border-radius: 11px; color: #fff;
3312
+ background: linear-gradient(145deg, #7f56d9 0%, #53389e 100%);
3313
+ box-shadow: 0 6px 16px rgb(105 65 198 / 0.24), inset 0 1px 0 rgb(255 255 255 / 0.25);
3314
+ }
3315
+ .brand-mark svg { width: 22px; height: 22px; }
3316
+ .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; line-height: 1.25; }
3317
+ .brand-id strong { font-size: 15px; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
3026
3318
  .brand-id span { color: var(--faint); font-size: 12px; }
3027
3319
  .vendor {
3028
3320
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
3029
3321
  min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
3322
+ padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-inset);
3030
3323
  }
3031
3324
  .vendor[hidden] { display: none; }
3032
3325
  /* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
@@ -3038,12 +3331,17 @@ var renderAdminDocument = (service) => {
3038
3331
  .vendor-sep { color: var(--faint); }
3039
3332
  .vendor-link { color: inherit; text-decoration: none; }
3040
3333
  .vendor-link:hover { color: var(--ink); text-decoration: underline; }
3041
- .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
3042
- label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
3334
+ .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
3335
+ .sync-status { align-self: center; display: flex; align-items: center; gap: 6px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3336
+ .sync-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
3337
+ .sync-status.busy::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: pulse 1.2s ease-in-out infinite; }
3338
+ label.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 600; color: var(--faint); }
3043
3339
  label.field input, label.field select, .controls input[type="password"] {
3044
- background-color: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
3045
- padding: 7px 8px; min-height: 36px; line-height: 1.2;
3340
+ background-color: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: 9px;
3341
+ padding: 8px 10px; min-height: 38px; line-height: 1.2; box-shadow: var(--shadow-xs);
3046
3342
  }
3343
+ label.field input:hover, label.field select:hover, textarea:hover { border-color: color-mix(in srgb, var(--accent) 38%, var(--line-strong)); }
3344
+ 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; }
3047
3345
  /* A native menu ignores min-height, so Preset rendered about half as tall as
3048
3346
  the text fields in the same form. Paint it like those fields. */
3049
3347
  label.field select {
@@ -3060,12 +3358,20 @@ var renderAdminDocument = (service) => {
3060
3358
  dialog .field > textarea { width: 100%; }
3061
3359
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger, nav.side button { cursor: pointer; }
3062
3360
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
3063
- border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
3064
- background: var(--bg-elev);
3065
- }
3066
- .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
3067
- .btn-quiet { background: transparent; }
3068
- .btn-danger { color: var(--err); }
3361
+ display: inline-flex; align-items: center; justify-content: center; gap: 7px;
3362
+ border-radius: 9px; min-height: 38px; padding: 0 13px; border: 1px solid var(--line-strong);
3363
+ background: var(--bg-elev); color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1;
3364
+ box-shadow: var(--shadow-xs);
3365
+ }
3366
+ .icon-btn { width: 38px; padding: 0; }
3367
+ .icon-btn svg, .btn svg, .btn-primary svg { width: 16px; height: 16px; }
3368
+ .icon-btn:hover, .btn:hover { background: var(--bg-muted); border-color: var(--line-strong); }
3369
+ .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; }
3370
+ .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
3371
+ .btn-quiet { background: transparent; border-color: transparent; box-shadow: none; }
3372
+ .btn-quiet:hover { background: var(--bg-muted); }
3373
+ .btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, var(--line)); }
3374
+ .btn-danger:hover, .btn-danger.confirming { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
3069
3375
  /* Held after mouseup. Clearing an empty journal changes nothing on screen,
3070
3376
  so the press itself has to stay visible. */
3071
3377
  .icon-btn:active, .btn:active, .btn-quiet:active, .btn-danger:active, nav.side button:active,
@@ -3081,93 +3387,159 @@ var renderAdminDocument = (service) => {
3081
3387
  flex: 1 0 auto; min-width: 0;
3082
3388
  }
3083
3389
  nav.side {
3084
- border-right: 1px solid var(--line); padding: 12px;
3390
+ position: sticky; top: var(--header); align-self: start; height: calc(100vh - var(--header));
3391
+ border-right: 1px solid var(--line); padding: 18px 12px;
3085
3392
  display: flex; flex-direction: column; gap: 4px;
3086
- background: var(--bg-elev);
3393
+ background: var(--bg-elev); overflow-y: auto;
3087
3394
  }
3395
+ .nav-label { padding: 0 10px 8px; color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
3088
3396
  nav.side button {
3397
+ position: relative; display: flex; align-items: center; gap: 10px; width: 100%;
3089
3398
  text-align: left; border: 0; background: transparent; border-radius: 9px;
3090
- padding: 9px 10px; min-height: 40px; color: var(--muted);
3091
- }
3092
- nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
3093
- main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
3094
- .view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
3095
- .lede { margin: 0 0 16px; color: var(--muted); }
3096
- .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
3399
+ padding: 9px 10px; min-height: 42px; color: var(--muted); font-size: 13px; font-weight: 550;
3400
+ }
3401
+ nav.side button:hover { background: var(--bg-muted); color: var(--ink); }
3402
+ nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
3403
+ 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); }
3404
+ .nav-icon { width: 18px; height: 18px; display: grid; place-items: center; flex: none; }
3405
+ .nav-icon svg { width: 18px; height: 18px; }
3406
+ main { padding: 32px clamp(20px, 4vw, 48px) 64px; max-width: 1320px; width: 100%; min-width: 0; }
3407
+ main[aria-busy="true"] .view { opacity: 0.62; }
3408
+ .view { animation: view-in 180ms ease-out; }
3409
+ .view[hidden] { display: none; }
3410
+ .view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
3411
+ .view h2 { margin: 0 0 5px; font-size: clamp(24px, 3vw, 30px); line-height: 1.2; letter-spacing: -0.035em; }
3412
+ .view h3 { margin: 24px 0 10px; font-size: 15px; letter-spacing: -0.01em; }
3413
+ .lede { margin: 0; color: var(--muted); max-width: 72ch; font-size: 14px; }
3414
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: 14px; }
3097
3415
  .card {
3098
3416
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
3099
- padding: 14px 16px; box-shadow: var(--shadow);
3417
+ padding: 18px; box-shadow: var(--shadow-sm);
3100
3418
  }
3101
- .card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
3102
- .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
3419
+ .stat-card { position: relative; overflow: hidden; }
3420
+ .stat-card::after { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, var(--accent), transparent 78%); opacity: 0.7; }
3421
+ .card .k { color: var(--faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
3422
+ .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; }
3103
3423
  .card .v .clock-time { font-size: 14px; color: var(--muted); }
3104
- .split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
3424
+ .section-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-xs); overflow: hidden; }
3425
+ .section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
3426
+ .section-title h3 { margin: 0; }
3427
+ .split { display: grid; grid-template-columns: minmax(0, 250px) minmax(0, 1fr); gap: 18px; align-items: start; }
3428
+ #collections { padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs); }
3105
3429
  .collection {
3106
3430
  width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
3107
- border-radius: 10px; padding: 8px 10px; min-height: 44px;
3431
+ border-radius: 9px; padding: 10px 11px; min-height: 48px; color: var(--ink); cursor: pointer;
3108
3432
  }
3109
- .collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
3433
+ .collection:hover { background: var(--bg-muted); }
3434
+ .collection[aria-current="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 18%, var(--line)); color: var(--accent); }
3110
3435
  .collection small { display: block; color: var(--faint); }
3111
3436
  .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
3112
- .chip {
3113
- font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
3114
- border-radius: 999px; padding: 4px 8px;
3115
- }
3437
+ .chip { font-family: var(--mono); font-size: 11px; background: var(--bg-muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; }
3116
3438
  .chip i { color: var(--faint); font-style: normal; }
3117
3439
  .sql-layout {
3118
3440
  display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3119
3441
  }
3120
- .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3121
- .sql-tables button { text-align: left; }
3442
+ .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); }
3443
+ .sql-tables button { text-align: left; border: 0; border-radius: 8px; padding: 9px 10px; background: transparent; color: var(--muted); cursor: pointer; }
3444
+ .sql-tables button:hover, .sql-tables button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
3122
3445
  .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
3123
- table { width: 100%; border-collapse: collapse; font-size: 14px; }
3124
- th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
3125
- th { color: var(--faint); font-weight: 600; font-size: 12px; }
3446
+ .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); }
3447
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
3448
+ th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
3449
+ th { color: var(--faint); background: var(--bg-inset); font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: 0.045em; }
3450
+ tbody tr:last-child td { border-bottom: 0; }
3126
3451
  tr.clickable { cursor: pointer; }
3127
- tr.clickable:hover { background: var(--bg-muted); }
3452
+ tr.clickable:hover { background: var(--accent-soft); }
3128
3453
  pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
3129
3454
  pre {
3130
3455
  margin: 0; white-space: pre-wrap; word-break: break-word;
3131
- background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
3132
- }
3133
- .row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
3456
+ background: var(--bg-inset); border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-size: 12px; line-height: 1.65;
3457
+ }
3458
+ .json-key { color: var(--code-key); }
3459
+ .json-string { color: var(--code-string); }
3460
+ .json-number { color: var(--code-number); }
3461
+ .json-boolean { color: var(--code-boolean); }
3462
+ .json-null { color: var(--code-null); font-style: italic; }
3463
+ .json-inline { display: block; max-width: 44rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
3464
+ .json-view { position: relative; max-height: 26rem; overflow: auto; }
3465
+ .json-editor { position: relative; min-height: 190px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg-inset); overflow: hidden; }
3466
+ .json-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
3467
+ .json-editor.invalid { border-color: var(--err); }
3468
+ .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; }
3469
+ .json-editor pre { position: absolute; inset: 0; pointer-events: none; background: transparent; }
3470
+ .json-editor textarea { position: relative; z-index: 1; resize: vertical; background: transparent; color: transparent; caret-color: var(--ink); -webkit-text-fill-color: transparent; }
3471
+ .json-editor textarea::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
3472
+ .editor-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 7px; }
3473
+ .json-status { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-size: 11px; }
3474
+ .json-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
3475
+ .json-status.invalid { color: var(--err); }
3476
+ .format-json { border: 0; padding: 3px 5px; background: transparent; color: var(--accent); font-size: 11px; font-weight: 650; cursor: pointer; }
3477
+ .row-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 14px 0; }
3134
3478
  .banner {
3135
- display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
3136
- background: var(--err-soft); color: var(--err);
3137
- }
3138
- .banner.show { display: block; }
3139
- .empty { color: var(--muted); padding: 24px 8px; }
3479
+ display: none; position: sticky; top: calc(var(--header) + 12px); z-index: 15;
3480
+ align-items: center; gap: 10px; margin: 0 0 16px; padding: 11px 12px 11px 14px;
3481
+ border: 1px solid color-mix(in srgb, var(--err) 30%, var(--line)); border-radius: 10px;
3482
+ background: var(--err-soft); color: var(--err); box-shadow: var(--shadow-sm); font-size: 13px;
3483
+ }
3484
+ .banner.show { display: flex; }
3485
+ .banner span { flex: 1; }
3486
+ .banner button { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: currentColor; cursor: pointer; }
3487
+ .banner button:hover { background: color-mix(in srgb, var(--err) 10%, transparent); }
3488
+ .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); }
3140
3489
  dialog {
3141
- border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
3142
- color: var(--ink); width: min(640px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: none;
3143
- }
3144
- dialog::backdrop { background: rgb(20 19 17 / 0.45); }
3145
- dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
3490
+ border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--bg-elev);
3491
+ color: var(--ink); width: min(720px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: var(--shadow-lg);
3492
+ }
3493
+ dialog[open] { animation: dialog-in 160ms ease-out; }
3494
+ dialog::backdrop { background: rgb(12 14 20 / 0.58); backdrop-filter: blur(3px); }
3495
+ dialog form, .dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
3496
+ .dialog-heading { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
3497
+ .dialog-heading strong { font-size: 18px; letter-spacing: -0.02em; }
3498
+ .dialog-heading span { color: var(--muted); font-size: 12px; }
3146
3499
  textarea {
3147
3500
  width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
3148
3501
  border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
3149
3502
  font-family: var(--mono); font-size: 12px;
3150
3503
  }
3151
- .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
3152
- .badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
3504
+ .dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 4px; }
3505
+ .dialog-actions .btn-danger { margin-right: auto; }
3506
+ .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); }
3153
3507
  .badge.ok { background: var(--ok-soft); color: var(--ok); }
3154
3508
  .badge.warn { background: var(--warn-soft); color: var(--warn); }
3155
3509
  .status-2 { color: var(--ok); }
3156
3510
  .status-4, .status-5, .status-0 { color: var(--err); }
3157
3511
  .stack { display: flex; flex-direction: column; gap: 12px; }
3512
+ .form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
3513
+ .form-grid .wide { grid-column: span 2; }
3158
3514
  .route {
3159
- display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
3160
- padding: 8px 0; border-bottom: 1px solid var(--line);
3161
- }
3162
- .method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
3515
+ display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 10px; align-items: center;
3516
+ padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg-elev);
3517
+ }
3518
+ .route:first-child { border-radius: var(--radius) var(--radius) 0 0; }
3519
+ .route:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
3520
+ .route-tools { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
3521
+ .route-tools .field { flex: 1; }
3522
+ .route-tools input { width: 100%; }
3523
+ .route-count { padding-bottom: 10px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3524
+ #route-list { max-height: 34rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow-xs); }
3525
+ .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; }
3526
+ @keyframes view-in { from { transform: translateY(3px); } to { transform: translateY(0); } }
3527
+ @keyframes dialog-in { from { transform: translateY(8px) scale(0.99); } to { transform: translateY(0) scale(1); } }
3528
+ @keyframes pulse { 50% { opacity: 0.45; } }
3529
+ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
3530
+ @media (forced-colors: active) { .json-editor pre { display: none; } .json-editor textarea { color: CanvasText; -webkit-text-fill-color: CanvasText; } }
3163
3531
  @media (max-width: 800px) {
3532
+ :root { --header: 0px; }
3164
3533
  header.top {
3165
- align-items: stretch; flex-direction: column;
3166
- padding-top: max(10px, env(safe-area-inset-top));
3534
+ position: relative; align-items: stretch; flex-direction: column;
3535
+ padding: max(12px, env(safe-area-inset-top)) 14px 12px;
3167
3536
  }
3168
3537
  input, select, textarea { font-size: 16px; }
3169
3538
  .brand, .vendor, .controls { width: 100%; }
3539
+ .brand { gap: 10px; }
3540
+ .vendor { order: 2; border-radius: 9px; }
3170
3541
  label.field, label.field select, label.field input { flex: 1; min-width: 0; }
3542
+ .sync-status { display: none; }
3171
3543
  /* The layout fills the screen. A single-column grid stretches every auto
3172
3544
  row, so the tab bar grew with the leftover height and the buttons floated
3173
3545
  in the middle of it. The bar stays one row; the page below takes the rest. */
@@ -3177,14 +3549,23 @@ var renderAdminDocument = (service) => {
3177
3549
  align-content: start;
3178
3550
  }
3179
3551
  nav.side {
3180
- align-self: start; height: auto;
3552
+ position: sticky; top: 0; z-index: 12; align-self: start; height: auto;
3181
3553
  flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
3182
3554
  border-right: 0; border-bottom: 1px solid var(--line);
3183
- padding: 8px;
3555
+ padding: 8px; box-shadow: var(--shadow-xs);
3184
3556
  }
3185
- nav.side button { white-space: nowrap; flex: none; }
3557
+ .nav-label { display: none; }
3558
+ nav.side button { width: auto; white-space: nowrap; flex: none; }
3559
+ nav.side button[aria-current="true"]::before { inset: auto 9px -8px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
3186
3560
  .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
3187
- main { padding: 14px; }
3561
+ .form-grid { grid-template-columns: minmax(0, 1fr); }
3562
+ .form-grid .wide { grid-column: auto; }
3563
+ main { padding: 22px 14px 48px; }
3564
+ .view-head { margin-bottom: 18px; }
3565
+ .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
3566
+ .card { padding: 14px; }
3567
+ .card .v { font-size: 20px; }
3568
+ .table-shell { border: 0; background: transparent; box-shadow: none; overflow: visible; }
3188
3569
  table, thead, tbody, tr, th, td { display: block; }
3189
3570
  thead { display: none; }
3190
3571
  tr {
@@ -3199,50 +3580,63 @@ var renderAdminDocument = (service) => {
3199
3580
  .route { grid-template-columns: 72px 1fr; }
3200
3581
  .route button { grid-column: 1 / -1; }
3201
3582
  }
3583
+ @media (max-width: 460px) {
3584
+ .controls label.field { min-width: calc(50% - 4px); }
3585
+ .controls .icon-btn, .controls .btn { flex: 1; }
3586
+ .grid { grid-template-columns: minmax(0, 1fr); }
3587
+ .dialog-actions { flex-wrap: wrap; }
3588
+ .dialog-actions button { flex: 1; }
3589
+ .dialog-actions .btn-danger { flex-basis: 100%; margin-right: 0; }
3590
+ }
3202
3591
  </style>
3203
3592
  </head>
3204
3593
  <body>
3205
3594
  <div class="app" data-service="${name}" data-mockingbird-admin>
3206
3595
  <header class="top">
3207
3596
  <div class="brand">
3208
- <div class="brand-id">
3209
- <strong>${name}</strong>
3210
- <span>Admin</span>
3597
+ <div class="brand-lockup">
3598
+ <div class="brand-mark" aria-hidden="true">
3599
+ <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>
3600
+ </div>
3601
+ <div class="brand-id">
3602
+ <strong>${name}</strong>
3603
+ <span>Mock admin</span>
3604
+ </div>
3211
3605
  </div>
3212
3606
  <div class="vendor" id="vendor" hidden></div>
3213
3607
  </div>
3214
3608
  <div class="controls">
3609
+ <span class="sync-status" id="sync-status" role="status" aria-live="polite">Ready</span>
3215
3610
  <label class="field">Namespace
3216
3611
  <select id="namespace" aria-label="Namespace"></select>
3217
3612
  </label>
3218
3613
  <label class="field">Admin key
3219
3614
  <input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
3220
3615
  </label>
3221
- <button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
3222
- <button class="btn" id="refresh" type="button">Refresh</button>
3616
+ <button class="icon-btn" id="theme" type="button" aria-label="Use dark theme" title="Use dark theme"></button>
3617
+ <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>
3223
3618
  </div>
3224
3619
  </header>
3225
3620
  <div class="layout">
3226
3621
  <nav class="side" id="nav" aria-label="Admin sections">
3227
- <button type="button" data-view="overview" aria-current="true">Overview</button>
3228
- <button type="button" data-view="state">State</button>
3229
- <button type="button" data-view="clock">Clock</button>
3230
- <button type="button" data-view="faults">Faults</button>
3231
- <button type="button" data-view="journal">Journal</button>
3232
- <button type="button" data-view="routes">Routes</button>
3622
+ <span class="nav-label">Workspace</span>
3623
+ <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>
3624
+ <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>
3625
+ <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>
3626
+ <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>
3627
+ <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>
3628
+ <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>
3233
3629
  </nav>
3234
3630
  <main id="views">
3235
- <p class="banner" id="banner" role="alert"></p>
3631
+ <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>
3236
3632
  <section class="view" id="view-overview">
3237
- <h2>Overview</h2>
3238
- <p class="lede">Health, clock, and the collections this namespace is holding.</p>
3633
+ <div class="view-head"><div><h2>Overview</h2><p class="lede">Health, clock, and the collections this namespace is holding.</p></div></div>
3239
3634
  <div class="grid" id="overview-cards"></div>
3240
3635
  <h3>Recent requests</h3>
3241
3636
  <div id="overview-requests"></div>
3242
3637
  </section>
3243
3638
  <section class="view" id="view-state" hidden>
3244
- <h2>State</h2>
3245
- <p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
3639
+ <div class="view-head"><div><h2>State</h2><p class="lede">Inspect and edit every collection in this namespace.</p></div></div>
3246
3640
  <div class="split">
3247
3641
  <div id="collections"></div>
3248
3642
  <div>
@@ -3255,8 +3649,7 @@ var renderAdminDocument = (service) => {
3255
3649
  </div>
3256
3650
  </section>
3257
3651
  <section class="view" id="view-clock" hidden>
3258
- <h2>Clock</h2>
3259
- <p class="lede">The clock every timestamp in this mock reads.</p>
3652
+ <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>
3260
3653
  <div class="card" id="clock-readout"></div>
3261
3654
  <div class="row-actions">
3262
3655
  <button class="btn" type="button" data-advance="60000">+1m</button>
@@ -3275,21 +3668,22 @@ var renderAdminDocument = (service) => {
3275
3668
  </form>
3276
3669
  </section>
3277
3670
  <section class="view" id="view-faults" hidden>
3278
- <h2>Faults</h2>
3279
- <p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
3671
+ <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>
3280
3672
  <form id="fault-form" class="card stack">
3281
- <label class="field">Preset
3282
- <select id="fault-preset"><option value="">Custom rule</option></select>
3283
- </label>
3284
- <label class="field">Status
3285
- <input id="fault-status" inputmode="numeric" placeholder="503">
3286
- </label>
3287
- <label class="field">Path prefix
3288
- <input id="fault-path" placeholder="/v1">
3289
- </label>
3290
- <label class="field">Method
3291
- <input id="fault-method" placeholder="GET">
3292
- </label>
3673
+ <div class="form-grid">
3674
+ <label class="field wide">Preset
3675
+ <select id="fault-preset"><option value="">Custom rule</option></select>
3676
+ </label>
3677
+ <label class="field">Status
3678
+ <input id="fault-status" inputmode="numeric" placeholder="503">
3679
+ </label>
3680
+ <label class="field wide">Path prefix
3681
+ <input id="fault-path" placeholder="/v1">
3682
+ </label>
3683
+ <label class="field">Method
3684
+ <input id="fault-method" placeholder="GET">
3685
+ </label>
3686
+ </div>
3293
3687
  <div class="dialog-actions">
3294
3688
  <button class="btn-primary" type="submit">Add fault</button>
3295
3689
  <button class="btn-danger" id="fault-clear" type="button">Clear all</button>
@@ -3298,26 +3692,31 @@ var renderAdminDocument = (service) => {
3298
3692
  <div id="fault-list"></div>
3299
3693
  </section>
3300
3694
  <section class="view" id="view-journal" hidden>
3301
- <h2>Journal</h2>
3302
- <p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
3303
- <div class="row-actions">
3304
- <button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
3305
- </div>
3695
+ <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>
3306
3696
  <div id="journal"></div>
3307
3697
  </section>
3308
3698
  <section class="view" id="view-routes" hidden>
3309
- <h2>Routes</h2>
3310
- <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>
3699
+ <div class="view-head"><div><h2>Routes</h2><p class="lede">Explore shared controls and service-specific admin endpoints.</p></div></div>
3700
+ <div class="route-tools">
3701
+ <label class="field">Filter routes
3702
+ <input id="route-search" type="search" placeholder="Method, path, or extension" autocomplete="off">
3703
+ </label>
3704
+ <span class="route-count" id="route-count"></span>
3705
+ </div>
3311
3706
  <div id="route-list"></div>
3312
- <form id="route-form" class="card stack">
3707
+ <form id="route-form" class="card stack" style="margin-top: 18px">
3313
3708
  <strong id="route-title">Select a route</strong>
3314
3709
  <label class="field">JSON body
3315
- <textarea id="route-body" placeholder="{ }"></textarea>
3710
+ <div class="json-editor" id="route-editor" hidden>
3711
+ <pre aria-hidden="true"><code id="route-highlight"></code></pre>
3712
+ <textarea id="route-body" placeholder="{ }" spellcheck="false" aria-describedby="route-json-status" disabled></textarea>
3713
+ </div>
3714
+ <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>
3316
3715
  </label>
3317
3716
  <div class="dialog-actions">
3318
- <button class="btn-primary" type="submit">Send</button>
3717
+ <button class="btn-primary" id="route-send" type="submit" disabled>Send request</button>
3319
3718
  </div>
3320
- <pre id="route-result">Response will show here.</pre>
3719
+ <pre class="json-view" id="route-result"><code>Response will show here.</code></pre>
3321
3720
  </form>
3322
3721
  </section>
3323
3722
  </main>
@@ -3325,12 +3724,16 @@ var renderAdminDocument = (service) => {
3325
3724
  </div>
3326
3725
  <dialog id="editor">
3327
3726
  <form method="dialog" id="editor-form">
3328
- <strong id="editor-title">Record</strong>
3727
+ <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>
3329
3728
  <label class="field">Id
3330
3729
  <input id="editor-id" required>
3331
3730
  </label>
3332
3731
  <label class="field">JSON value
3333
- <textarea id="editor-value"></textarea>
3732
+ <div class="json-editor" id="record-editor">
3733
+ <pre aria-hidden="true"><code id="editor-highlight"></code></pre>
3734
+ <textarea id="editor-value" spellcheck="false" aria-describedby="editor-json-status"></textarea>
3735
+ </div>
3736
+ <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>
3334
3737
  </label>
3335
3738
  <div class="dialog-actions">
3336
3739
  <button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
@@ -3372,8 +3775,8 @@ var describeExtension = (extension) => {
3372
3775
  ...extension.script !== void 0 ? { script: extension.script } : {}
3373
3776
  };
3374
3777
  };
3375
- var adminUiRoutes = (service, ui) => {
3376
- const shell = () => renderAdminDocument(service);
3778
+ var adminUiRoutes = (service, ui, adminPrefix = ADMIN_PREFIX) => {
3779
+ const shell = () => renderAdminDocument(service, adminPrefix);
3377
3780
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
3378
3781
  return {
3379
3782
  "GET /ui": () => htmlResponse(document3()),
@@ -4064,10 +4467,13 @@ var stateAdminRoutes = (routes) => {
4064
4467
  };
4065
4468
 
4066
4469
  // ../core/dist/version.js
4067
- var PACKAGE_VERSION = true ? "1.7.1" : UNRELEASED_VERSION;
4470
+ var PACKAGE_VERSION = true ? "2.0.0" : UNRELEASED_VERSION;
4068
4471
 
4069
4472
  // ../core/dist/webhooks.js
4070
- var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
4473
+ var json4 = (status, body) => new Response(JSON.stringify(body), {
4474
+ status,
4475
+ headers: { "content-type": "application/json; charset=utf-8" }
4476
+ });
4071
4477
  var adminError3 = (status, message) => json4(status, { error: { type: "mockingbird_admin", message } });
4072
4478
  var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4073
4479
  var parseEndpoint = (value) => {
@@ -4175,7 +4581,6 @@ var AT_HEADER = "x-mockingbird-at";
4175
4581
  var CHECKPOINT_HEADER = "x-mockingbird-checkpoint";
4176
4582
  var DEFAULT_NAMESPACE = "default";
4177
4583
  var NAMESPACE_PATTERN = /^[A-Za-z0-9_.-]{1,64}$/;
4178
- var PATH_PREFIX = /^\/ns\/([^/]+)(\/.*)?$/;
4179
4584
  var BRANCH_PATTERN2 = /^[A-Za-z0-9_.-]{1,64}$/;
4180
4585
  var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
4181
4586
  var effects = /* @__PURE__ */ new WeakMap();
@@ -4216,6 +4621,22 @@ var operationMatcher = (document3) => {
4216
4621
  return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
4217
4622
  };
4218
4623
  var createRuntime = (options) => {
4624
+ const adminPrefix = resolveAdminPrefix(options.adminPrefix);
4625
+ const internalPaths = Object.entries(options.document?.paths ?? {}).filter(([, item]) => item["x-mockingbird-internal"] === true).map(([path]) => path);
4626
+ for (const path of internalPaths) {
4627
+ if (!path.startsWith(`${ADMIN_PREFIX}/blobs/`))
4628
+ throw new Error(`internal transport ${path} must live under ${ADMIN_PREFIX}/blobs/`);
4629
+ }
4630
+ assertAdminPrefixAvailable(adminPrefix, Object.keys(options.document?.paths ?? {}).filter((path) => !internalPaths.includes(path)));
4631
+ const internalMatch = (path) => {
4632
+ for (const pattern of internalPaths) {
4633
+ const actual = path.split("/");
4634
+ const expected = pattern.split("/");
4635
+ if (actual.length === expected.length && expected.every((part, i) => part.startsWith("{") || part === actual[i]))
4636
+ return pattern;
4637
+ }
4638
+ return void 0;
4639
+ };
4219
4640
  assertAdminUi(options.adminUi);
4220
4641
  const sqlite = bootSqlite(options.sqlite);
4221
4642
  const clock = options.clock ?? createClock();
@@ -4230,6 +4651,20 @@ var createRuntime = (options) => {
4230
4651
  const instances = /* @__PURE__ */ new Map();
4231
4652
  const publicNamespaces = /* @__PURE__ */ new Set();
4232
4653
  const branchRngs = /* @__PURE__ */ new Map();
4654
+ const namespaceClocks = /* @__PURE__ */ new Map();
4655
+ const namespaceForStorage = /* @__PURE__ */ new Map();
4656
+ let isolatedNamespaces = false;
4657
+ const namespaceClock = (name = DEFAULT_NAMESPACE) => {
4658
+ if (!isolatedNamespaces || name === DEFAULT_NAMESPACE)
4659
+ return clock;
4660
+ let found = namespaceClocks.get(name);
4661
+ if (!found) {
4662
+ found = createClock();
4663
+ namespaceClocks.set(name, found);
4664
+ }
4665
+ return found;
4666
+ };
4667
+ const fleetPoints = /* @__PURE__ */ new WeakMap();
4233
4668
  const timelines = /* @__PURE__ */ new Map();
4234
4669
  const branchStorage = /* @__PURE__ */ new Map();
4235
4670
  const captured = /* @__PURE__ */ new Map();
@@ -4243,17 +4678,22 @@ var createRuntime = (options) => {
4243
4678
  if (!NAMESPACE_PATTERN.test(key) || !NAMESPACE_PATTERN.test(publicNamespace)) {
4244
4679
  throw new RangeError(`namespace must match ${NAMESPACE_PATTERN}: ${JSON.stringify(publicNamespace)}`);
4245
4680
  }
4681
+ const createdContextRng = isolatedRng ?? (isolatedNamespaces && key !== DEFAULT_NAMESPACE ? createRng(options.seed ?? 0) : rng);
4246
4682
  const created = options.create({
4247
4683
  namespace: storageNamespace(key),
4248
4684
  publicNamespace,
4685
+ adminPrefix,
4249
4686
  sqlite,
4250
- clock,
4251
- rng: isolatedRng ?? rng
4687
+ clock: namespaceClock(publicNamespace),
4688
+ rng: createdContextRng
4252
4689
  });
4253
4690
  instances.set(key, created);
4691
+ namespaceForStorage.set(key, publicNamespace);
4254
4692
  publicNamespaces.add(publicNamespace);
4255
4693
  if (isolatedRng)
4256
4694
  branchRngs.set(key, isolatedRng);
4695
+ else if (isolatedNamespaces && key !== DEFAULT_NAMESPACE)
4696
+ branchRngs.set(key, createdContextRng);
4257
4697
  return created;
4258
4698
  };
4259
4699
  const instance = (name = DEFAULT_NAMESPACE) => instanceFor(name);
@@ -4271,7 +4711,7 @@ var createRuntime = (options) => {
4271
4711
  captured.set(storage, snapshot2);
4272
4712
  return Object.freeze({
4273
4713
  snapshot: snapshot2,
4274
- clock: Object.freeze(clock.state()),
4714
+ clock: Object.freeze(namespaceClock(namespaceForStorage.get(storage) ?? storage).state()),
4275
4715
  rngState: (branchRngs.get(storage) ?? rng).state()
4276
4716
  });
4277
4717
  };
@@ -4281,7 +4721,7 @@ var createRuntime = (options) => {
4281
4721
  return found;
4282
4722
  instance(name);
4283
4723
  found = new Timeline({
4284
- now: clock.now,
4724
+ now: namespaceClock(name).now,
4285
4725
  ...options.maxCheckpoints !== void 0 ? { maxCheckpoints: options.maxCheckpoints } : {}
4286
4726
  });
4287
4727
  found.commit(capture(name));
@@ -4308,12 +4748,13 @@ var createRuntime = (options) => {
4308
4748
  const point = history2.checkout("main", at);
4309
4749
  restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
4310
4750
  captured.set(namespace, point.value.snapshot);
4311
- rng.setState(point.value.rngState);
4312
- clock.set(point.value.clock.now);
4751
+ (branchRngs.get(namespace) ?? rng).setState(point.value.rngState);
4752
+ const selectedClock = namespaceClock(namespace);
4753
+ selectedClock.set(point.value.clock.now);
4313
4754
  if (point.value.clock.frozen)
4314
- clock.freeze();
4755
+ selectedClock.freeze();
4315
4756
  else
4316
- clock.unfreeze();
4757
+ selectedClock.unfreeze();
4317
4758
  }
4318
4759
  return namespace;
4319
4760
  }
@@ -4371,11 +4812,12 @@ var createRuntime = (options) => {
4371
4812
  const storage = ensureBranch(namespace, branchName);
4372
4813
  restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
4373
4814
  captured.set(storage, point.value.snapshot);
4374
- clock.set(point.value.clock.now);
4815
+ const selectedClock = namespaceClock(namespace);
4816
+ selectedClock.set(point.value.clock.now);
4375
4817
  if (point.value.clock.frozen)
4376
- clock.freeze();
4818
+ selectedClock.freeze();
4377
4819
  else
4378
- clock.unfreeze();
4820
+ selectedClock.unfreeze();
4379
4821
  (branchRngs.get(storage) ?? rng).setState(point.value.rngState);
4380
4822
  };
4381
4823
  const reset = async (name = DEFAULT_NAMESPACE) => {
@@ -4383,10 +4825,21 @@ var createRuntime = (options) => {
4383
4825
  options.webhooks?.clear();
4384
4826
  for (const each of instances.values())
4385
4827
  await each.reset();
4828
+ for (const each of branchRngs.values())
4829
+ each.reset();
4386
4830
  timelines.clear();
4831
+ for (const storage of branchStorage.values()) {
4832
+ instances.delete(storage);
4833
+ branchRngs.delete(storage);
4834
+ namespaceForStorage.delete(storage);
4835
+ }
4387
4836
  branchStorage.clear();
4388
- branchRngs.clear();
4389
4837
  captured.clear();
4838
+ faults.clear();
4839
+ clock.reset();
4840
+ rng.reset();
4841
+ for (const each of namespaceClocks.values())
4842
+ each.reset();
4390
4843
  return;
4391
4844
  }
4392
4845
  options.webhooks?.clear(name);
@@ -4404,11 +4857,18 @@ var createRuntime = (options) => {
4404
4857
  else
4405
4858
  clearNamespace(sqlite, storageNamespace(storage));
4406
4859
  branchStorage.delete(mapping);
4860
+ instances.delete(storage);
4861
+ namespaceForStorage.delete(storage);
4407
4862
  branchRngs.delete(storage);
4408
4863
  captured.delete(storage);
4409
4864
  }
4410
4865
  timelines.delete(name);
4411
4866
  captured.delete(name);
4867
+ faults.restore(name, { rules: [], rngState: createRng(options.seed ?? 0).state() });
4868
+ namespaceClock(name).reset();
4869
+ (branchRngs.get(name) ?? rng).reset();
4870
+ journal.clear(name);
4871
+ metrics.reset(name);
4412
4872
  };
4413
4873
  const snapshot = (name = DEFAULT_NAMESPACE) => {
4414
4874
  return checkpoint(name, "main").value.snapshot;
@@ -4446,6 +4906,53 @@ var createRuntime = (options) => {
4446
4906
  rng,
4447
4907
  credentials,
4448
4908
  webhooks: options.webhooks,
4909
+ isolateNamespaces() {
4910
+ if (publicNamespaces.size > 1)
4911
+ throw new Error("enable namespace isolation before creating named namespaces");
4912
+ isolatedNamespaces = true;
4913
+ faults.isolateNamespaces();
4914
+ },
4915
+ namespaceClock,
4916
+ namespaceOf(request) {
4917
+ const url = new URL(request.url);
4918
+ const prefixed = matchNamespacePath(url.pathname, adminPrefix);
4919
+ const selected = request.headers.get(NAMESPACE_HEADER) ?? (prefixed ? decodeURIComponent(prefixed[1]) : void 0);
4920
+ const path = prefixed ? prefixed[2] ?? "/" : url.pathname;
4921
+ if (isAdminPath(path, adminPrefix))
4922
+ return url.searchParams.get("namespace") ?? selected ?? DEFAULT_NAMESPACE;
4923
+ if (selected !== void 0)
4924
+ return selected;
4925
+ const credential = options.credential?.(request);
4926
+ return (credential !== void 0 ? credentials.get(credential) : void 0) ?? DEFAULT_NAMESPACE;
4927
+ },
4928
+ fleetSnapshot(namespace) {
4929
+ instance(namespace);
4930
+ const handle = {};
4931
+ fleetPoints.set(handle, {
4932
+ namespace,
4933
+ state: capture(namespace),
4934
+ faults: faults.snapshot(namespace),
4935
+ webhooks: options.webhooks?.snapshot(namespace)
4936
+ });
4937
+ return handle;
4938
+ },
4939
+ fleetRestore(handle, namespace) {
4940
+ const point = typeof handle === "object" && handle !== null ? fleetPoints.get(handle) : void 0;
4941
+ if (!point || point.namespace !== namespace)
4942
+ throw new Error("invalid fleet checkpoint");
4943
+ restoreNamespace(sqlite, storageNamespace(namespace), point.state.snapshot);
4944
+ captured.set(namespace, point.state.snapshot);
4945
+ const selectedClock = namespaceClock(namespace);
4946
+ selectedClock.freeze();
4947
+ selectedClock.set(point.state.clock.now);
4948
+ if (!point.state.clock.frozen)
4949
+ selectedClock.unfreeze();
4950
+ (branchRngs.get(namespace) ?? rng).setState(point.state.rngState);
4951
+ faults.restore(namespace, point.faults);
4952
+ if (point.webhooks !== void 0)
4953
+ options.webhooks?.restore(namespace, point.webhooks);
4954
+ timelines.delete(namespace);
4955
+ },
4449
4956
  applyPreset: (name, namespace = DEFAULT_NAMESPACE, overrides = {}) => {
4450
4957
  const preset = options.presets?.[name];
4451
4958
  if (!preset)
@@ -4477,7 +4984,7 @@ var createRuntime = (options) => {
4477
4984
  state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
4478
4985
  fetch: async (incoming) => {
4479
4986
  let request = incoming;
4480
- const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
4987
+ const prefixed = matchNamespacePath(new URL(request.url).pathname, adminPrefix);
4481
4988
  if (prefixed) {
4482
4989
  const url2 = new URL(request.url);
4483
4990
  url2.pathname = prefixed[2] ?? "/";
@@ -4493,7 +5000,15 @@ var createRuntime = (options) => {
4493
5000
  signal: request.signal
4494
5001
  });
4495
5002
  }
4496
- let namespace = control.namespaceOf(request);
5003
+ const internalUrl = new URL(request.url);
5004
+ const internalPath = isAdminPath(internalUrl.pathname, adminPrefix) ? `${ADMIN_PREFIX}${internalUrl.pathname.slice(adminPrefix.length)}` : "";
5005
+ const internal = internalMatch(internalPath);
5006
+ const obsoleteInternalPath = adminPrefix !== ADMIN_PREFIX && internalMatch(internalUrl.pathname) && !internal;
5007
+ if (internal) {
5008
+ internalUrl.pathname = internalPath;
5009
+ request = new Request(internalUrl, request);
5010
+ }
5011
+ let namespace = internal ? internalUrl.searchParams.get("namespace") ?? control.namespaceOf(request) : control.namespaceOf(request);
4497
5012
  if (!request.headers.has(NAMESPACE_HEADER) && options.credential) {
4498
5013
  const credential = options.credential(request);
4499
5014
  const mapped = credential !== void 0 ? credentials.get(credential) : void 0;
@@ -4513,7 +5028,9 @@ var createRuntime = (options) => {
4513
5028
  return copy;
4514
5029
  }
4515
5030
  };
4516
- const handled = await control.handle(request);
5031
+ if (obsoleteInternalPath)
5032
+ return stamp(adminFail(404, "internal transport is only available under adminPrefix"));
5033
+ const handled = internal ? void 0 : await control.handle(request);
4517
5034
  if (handled)
4518
5035
  return stamp(handled);
4519
5036
  const started = monotonicNow();
@@ -4554,7 +5071,7 @@ var createRuntime = (options) => {
4554
5071
  type: "mockingbird_admin",
4555
5072
  message: `${NAMESPACE_HEADER} must match ${NAMESPACE_PATTERN}`
4556
5073
  }
4557
- }), { status: 400, headers: { "content-type": "application/json" } }));
5074
+ }), { status: 400, headers: { "content-type": "application/json; charset=utf-8" } }));
4558
5075
  }
4559
5076
  if (!BRANCH_PATTERN2.test(selectedBranch)) {
4560
5077
  log(400);
@@ -4621,6 +5138,7 @@ var createRuntime = (options) => {
4621
5138
  startedAt: wallNow(),
4622
5139
  wallNow,
4623
5140
  clock,
5141
+ namespaceClock,
4624
5142
  faults,
4625
5143
  metrics,
4626
5144
  journal,
@@ -4670,15 +5188,16 @@ var createRuntime = (options) => {
4670
5188
  ...options.admin?.(runtime) ?? {},
4671
5189
  // Shell routes win a colliding key. Fault presets are one of them: the admin page
4672
5190
  // maps `presets`, and a service route must not replace that list with a record.
4673
- ...options.presets ? presetRoutes(options.presets, runtime) : {},
5191
+ ...options.presets ? presetRoutes(options.presets, runtime, adminPrefix) : {},
4674
5192
  ...stateAdminRoutes({
4675
5193
  open: stateScope,
4676
5194
  afterWrite: (namespace) => {
4677
5195
  checkpoint(namespace, "main");
4678
5196
  }
4679
5197
  }),
4680
- ...adminUiRoutes(options.name, options.adminUi)
5198
+ ...adminUiRoutes(options.name, options.adminUi, adminPrefix)
4681
5199
  },
5200
+ adminPrefix,
4682
5201
  adminKey: options.adminKey
4683
5202
  });
4684
5203
  return defineMock(runtime);
@@ -4692,7 +5211,10 @@ var mutableResponse = (response) => {
4692
5211
  return new Response(response.body, response);
4693
5212
  }
4694
5213
  };
4695
- var adminJson = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
5214
+ var adminJson = (status, body) => new Response(JSON.stringify(body), {
5215
+ status,
5216
+ headers: { "content-type": "application/json; charset=utf-8" }
5217
+ });
4696
5218
  var adminFail = (status, message) => adminJson(status, { error: { type: "mockingbird_admin", message } });
4697
5219
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4698
5220
  var credentialRoutes = (registry) => ({
@@ -4744,7 +5266,7 @@ var credentialRoutes = (registry) => ({
4744
5266
  return adminJson(200, { status: "ok" });
4745
5267
  }
4746
5268
  });
4747
- var presetRoutes = (presets, runtime) => ({
5269
+ var presetRoutes = (presets, runtime, adminPrefix) => ({
4748
5270
  "GET /faults/presets": () => {
4749
5271
  const body = {
4750
5272
  presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
@@ -4754,7 +5276,7 @@ var presetRoutes = (presets, runtime) => ({
4754
5276
  "POST /faults/presets/:name": ({ params, body, namespace }) => {
4755
5277
  const name = params.name;
4756
5278
  if (!presets[name])
4757
- return adminFail(404, `no fault preset ${name}; GET /__admin/faults/presets`);
5279
+ return adminFail(404, `no fault preset ${name}; GET ${adminPrefix}/faults/presets`);
4758
5280
  const overrides = isObject(body) ? body : {};
4759
5281
  return adminJson(201, { preset: name, rules: runtime.applyPreset(name, namespace, overrides) });
4760
5282
  }
@@ -5067,6 +5589,7 @@ var createRuntime2 = (options = {}) => {
5067
5589
  ...options.sqlite ? { sqlite: options.sqlite } : {},
5068
5590
  ...options.clock ? { clock: options.clock } : {},
5069
5591
  ...options.seed !== void 0 ? { seed: options.seed } : {},
5592
+ ...options.adminPrefix !== void 0 ? { adminPrefix: options.adminPrefix } : {},
5070
5593
  ...options.adminKey !== void 0 ? { adminKey: options.adminKey } : {},
5071
5594
  ...options.onLog ? { onLog: options.onLog } : {},
5072
5595
  credential: basicUsername,
@@ -5369,6 +5892,9 @@ var WholescriptsAPI = class {
5369
5892
  };
5370
5893
 
5371
5894
  export {
5895
+ createClock,
5896
+ resolveAdminPrefix,
5897
+ parseDuration,
5372
5898
  MEDPAX_BOX_SKU,
5373
5899
  DEFAULT_CATALOG,
5374
5900
  document2 as document,
@@ -5381,4 +5907,4 @@ export {
5381
5907
  canonicalStatus,
5382
5908
  WholescriptsAPI
5383
5909
  };
5384
- //# sourceMappingURL=chunk-QGDPU444.js.map
5910
+ //# sourceMappingURL=chunk-6JAPA3JS.js.map