@crvouga/mockingbird-service-customerio 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
  };
@@ -492,7 +532,33 @@ var faultResponse = (rule) => {
492
532
  };
493
533
  var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) => {
494
534
  const entries = [];
535
+ let isolated = false;
536
+ const scopedRngs = /* @__PURE__ */ new Map();
537
+ const random = (namespace) => {
538
+ if (!isolated || namespace === "default")
539
+ return rng;
540
+ let scoped = scopedRngs.get(namespace);
541
+ if (!scoped) {
542
+ scoped = createRng(rng.seed);
543
+ scopedRngs.set(namespace, scoped);
544
+ }
545
+ return scoped;
546
+ };
495
547
  return {
548
+ isolateNamespaces() {
549
+ isolated = true;
550
+ },
551
+ snapshot(namespace) {
552
+ return {
553
+ rules: structuredClone(entries.map((entry, position) => ({
554
+ ...entry.rule,
555
+ remaining: entry.remaining,
556
+ hits: entry.hits,
557
+ position
558
+ })).filter((entry) => entry.namespace === namespace)),
559
+ rngState: random(namespace).state()
560
+ };
561
+ },
496
562
  add(rule) {
497
563
  const existing = entries.findIndex((e) => e.rule.id === rule.id);
498
564
  const entry = { rule, remaining: rule.count ?? null, hits: 0 };
@@ -512,6 +578,16 @@ var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((reso
512
578
  },
513
579
  clear() {
514
580
  entries.length = 0;
581
+ rng.reset();
582
+ scopedRngs.clear();
583
+ },
584
+ restore(namespace, state) {
585
+ for (let i = entries.length - 1; i >= 0; i--)
586
+ if (entries[i]?.rule.namespace === namespace)
587
+ entries.splice(i, 1);
588
+ for (const { remaining, hits, position, ...rule } of state.rules)
589
+ entries.splice(Math.min(position, entries.length), 0, { rule, remaining, hits });
590
+ random(namespace).setState(state.rngState);
515
591
  },
516
592
  async take(candidate) {
517
593
  const hits = [];
@@ -521,7 +597,7 @@ var createFaultRegistry = (rng = createRng(0), sleep = (ms) => new Promise((reso
521
597
  if (!matches(entry.rule, candidate))
522
598
  continue;
523
599
  const rate = entry.rule.rate ?? 1;
524
- if (rng.next() >= rate)
600
+ if (random(candidate.namespace).next() >= rate)
525
601
  continue;
526
602
  entry.hits++;
527
603
  if (entry.remaining !== null)
@@ -1089,7 +1165,8 @@ var annotateResponse = (response, extra) => {
1089
1165
  var responseNotes = (response) => notes.get(response);
1090
1166
 
1091
1167
  // ../core/dist/metrics.js
1092
- var createMetrics = () => {
1168
+ var createMetrics = (partition = true) => {
1169
+ const namespaces = /* @__PURE__ */ new Map();
1093
1170
  let requests = 0;
1094
1171
  let faults = 0;
1095
1172
  let totalDurationMs = 0;
@@ -1097,6 +1174,14 @@ var createMetrics = () => {
1097
1174
  const unmatched = /* @__PURE__ */ new Map();
1098
1175
  return {
1099
1176
  record(entry) {
1177
+ if (partition) {
1178
+ let scoped = namespaces.get(entry.namespace);
1179
+ if (!scoped) {
1180
+ scoped = createMetrics(false);
1181
+ namespaces.set(entry.namespace, scoped);
1182
+ }
1183
+ scoped.record(entry);
1184
+ }
1100
1185
  requests++;
1101
1186
  totalDurationMs += entry.durationMs;
1102
1187
  if (entry.faultId !== void 0)
@@ -1108,7 +1193,7 @@ var createMetrics = () => {
1108
1193
  unmatched.set(route, (unmatched.get(route) ?? 0) + 1);
1109
1194
  }
1110
1195
  },
1111
- report: () => ({
1196
+ report: (namespace) => namespace !== void 0 ? (namespaces.get(namespace) ?? createMetrics(false)).report() : {
1112
1197
  requests,
1113
1198
  byOperation: Object.fromEntries([...byOperation].sort(([a], [b]) => a.localeCompare(b))),
1114
1199
  unmatched: [...unmatched].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([route, count]) => {
@@ -1117,8 +1202,13 @@ var createMetrics = () => {
1117
1202
  }),
1118
1203
  faults,
1119
1204
  totalDurationMs
1120
- }),
1121
- reset() {
1205
+ },
1206
+ reset(namespace) {
1207
+ if (namespace !== void 0) {
1208
+ namespaces.delete(namespace);
1209
+ return;
1210
+ }
1211
+ namespaces.clear();
1122
1212
  requests = 0;
1123
1213
  faults = 0;
1124
1214
  totalDurationMs = 0;
@@ -1162,7 +1252,10 @@ var OutboxStore = class {
1162
1252
  return query.limit !== void 0 ? matched.slice(-Math.max(0, query.limit)) : matched;
1163
1253
  }
1164
1254
  };
1165
- var json2 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
1255
+ var json2 = (status, body) => new Response(JSON.stringify(body), {
1256
+ status,
1257
+ headers: { "content-type": "application/json; charset=utf-8" }
1258
+ });
1166
1259
  var parseSince = (value) => {
1167
1260
  if (value === null)
1168
1261
  return void 0;
@@ -1808,6 +1901,34 @@ dialog:not([open]) {
1808
1901
  function isRecord2(value) {
1809
1902
  return typeof value === "object" && value !== null && !Array.isArray(value);
1810
1903
  }
1904
+ function highlightJsonText(text) {
1905
+ const escapeToken = (value) => value.replace(/[&<>"']/g, (char) => {
1906
+ switch (char) {
1907
+ case "&":
1908
+ return "&amp;";
1909
+ case "<":
1910
+ return "&lt;";
1911
+ case ">":
1912
+ return "&gt;";
1913
+ case '"':
1914
+ return "&quot;";
1915
+ default:
1916
+ return "&#39;";
1917
+ }
1918
+ });
1919
+ const token = /("(?:\\u[\da-fA-F]{4}|\\[^u]|[^\\"])*"\s*:|"(?:\\u[\da-fA-F]{4}|\\[^u]|[^\\"])*"|\b(?:true|false)\b|\bnull\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g;
1920
+ let cursor = 0;
1921
+ let html = "";
1922
+ for (const match of text.matchAll(token)) {
1923
+ const index = match.index ?? 0;
1924
+ const value = match[0];
1925
+ html += escapeToken(text.slice(cursor, index));
1926
+ const kind = value.startsWith('"') ? value.trimEnd().endsWith(":") ? "key" : "string" : value === "true" || value === "false" ? "boolean" : value === "null" ? "null" : "number";
1927
+ html += `<span class="json-${kind}">${escapeToken(value)}</span>`;
1928
+ cursor = index + value.length;
1929
+ }
1930
+ return html + escapeToken(text.slice(cursor));
1931
+ }
1811
1932
  function mountAdminBrand(doc, host, service, catalog) {
1812
1933
  const clip = (value, max) => {
1813
1934
  if (typeof value !== "string")
@@ -2169,14 +2290,16 @@ function bootAdmin(config) {
2169
2290
  const state = {
2170
2291
  namespace: "default",
2171
2292
  key: sessionStorage.getItem("mockingbird-admin-key") || "",
2172
- view: "overview",
2293
+ view: ["overview", "state", "clock", "faults", "journal", "routes"].includes(location.hash.slice(1)) ? location.hash.slice(1) : "overview",
2173
2294
  collection: "",
2174
2295
  shape: null,
2175
2296
  route: null,
2297
+ routes: [],
2176
2298
  editing: null
2177
2299
  };
2178
2300
  const standard = new Set(config.standardRoutes);
2179
2301
  const banner = el("banner", HTMLElement);
2302
+ const bannerMessage = el("banner-message", HTMLElement);
2180
2303
  const keyInput = el("admin-key", HTMLInputElement);
2181
2304
  keyInput.value = state.key;
2182
2305
  const params = new URLSearchParams(location.search);
@@ -2187,18 +2310,21 @@ function bootAdmin(config) {
2187
2310
  sessionStorage.setItem("mockingbird-admin-key", state.key);
2188
2311
  params.delete("key");
2189
2312
  const next = params.toString();
2190
- history.replaceState(null, "", location.pathname + (next ? `?${next}` : ""));
2313
+ history.replaceState(null, "", location.pathname + (next ? `?${next}` : "") + location.hash);
2191
2314
  }
2192
2315
  const queryNamespace = params.get("namespace");
2193
2316
  if (queryNamespace)
2194
2317
  state.namespace = queryNamespace;
2195
2318
  const showError = (error) => {
2196
- banner.textContent = error instanceof Error ? error.message : String(error);
2319
+ bannerMessage.textContent = error instanceof Error ? error.message : String(error);
2197
2320
  banner.classList.add("show");
2321
+ banner.scrollIntoView({ behavior: "smooth", block: "nearest" });
2198
2322
  };
2199
2323
  const clearError = () => {
2200
2324
  banner.classList.remove("show");
2325
+ bannerMessage.textContent = "";
2201
2326
  };
2327
+ el("banner-dismiss", HTMLButtonElement).addEventListener("click", clearError);
2202
2328
  const api = async (method, path, body) => {
2203
2329
  const headers = { accept: "application/json" };
2204
2330
  if (state.key !== "")
@@ -2242,16 +2368,21 @@ function bootAdmin(config) {
2242
2368
  namespace: () => state.namespace
2243
2369
  };
2244
2370
  const isPanelScript = (value) => typeof value === "function";
2371
+ const themeButton = el("theme", HTMLButtonElement);
2245
2372
  const setTheme = (theme) => {
2246
2373
  if (theme)
2247
2374
  document.documentElement.dataset.theme = theme;
2248
2375
  else
2249
2376
  delete document.documentElement.dataset.theme;
2377
+ const dark = theme ? theme === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2378
+ themeButton.innerHTML = dark ? '<svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><circle cx="10" cy="10" r="3.2" stroke="currentColor" stroke-width="1.5"/><path d="M10 2v1.5M10 16.5V18M18 10h-1.5M3.5 10H2M15.7 4.3l-1 1M5.3 14.7l-1 1M15.7 15.7l-1-1M5.3 5.3l-1-1" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>' : '<svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M16.8 12.2A7 7 0 0 1 7.8 3.2a7 7 0 1 0 9 9Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg>';
2379
+ const label = dark ? "Use light theme" : "Use dark theme";
2380
+ themeButton.setAttribute("aria-label", label);
2381
+ themeButton.title = label;
2250
2382
  };
2251
2383
  const storedTheme = localStorage.getItem("mockingbird-admin-theme");
2252
- if (storedTheme)
2253
- setTheme(storedTheme);
2254
- el("theme", HTMLButtonElement).addEventListener("click", () => {
2384
+ setTheme(storedTheme === "dark" || storedTheme === "light" ? storedTheme : null);
2385
+ themeButton.addEventListener("click", () => {
2255
2386
  const current = document.documentElement.dataset.theme;
2256
2387
  const dark = current ? current === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
2257
2388
  const next = dark ? "light" : "dark";
@@ -2270,6 +2401,7 @@ function bootAdmin(config) {
2270
2401
  continue;
2271
2402
  section.hidden = section.id !== `view-${view}`;
2272
2403
  }
2404
+ history.replaceState(null, "", `${location.pathname}${location.search}#${encodeURIComponent(view)}`);
2273
2405
  };
2274
2406
  el("nav", HTMLElement).addEventListener("click", (event) => {
2275
2407
  const target = event.target;
@@ -2284,7 +2416,7 @@ function bootAdmin(config) {
2284
2416
  show(view);
2285
2417
  refresh().catch(showError);
2286
2418
  });
2287
- const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
2419
+ const cards = (items) => `<div class="grid">${items.map((item) => `<article class="card stat-card"><div class="k">${item.k}</div><div class="v">${item.v}</div></article>`).join("")}</div>`;
2288
2420
  const table = (columns, rows) => {
2289
2421
  if (rows.length === 0)
2290
2422
  return '<p class="empty">Nothing here yet.</p>';
@@ -2294,16 +2426,22 @@ function bootAdmin(config) {
2294
2426
  const attrs = "attrs" in row && typeof row.attrs === "string" ? row.attrs : "";
2295
2427
  return `<tr${attrs}>${cells}</tr>`;
2296
2428
  }).join("");
2297
- return `<table><thead>${head}</thead><tbody>${body}</tbody></table>`;
2429
+ return `<div class="table-shell"><table><thead>${head}</thead><tbody>${body}</tbody></table></div>`;
2298
2430
  };
2299
2431
  const preview = (value) => {
2300
2432
  const text = JSON.stringify(value) ?? "null";
2301
- return esc(text.length > 180 ? `${text.slice(0, 180)}\u2026` : text);
2433
+ const clipped = text.length > 180 ? `${text.slice(0, 180)}\u2026` : text;
2434
+ return `<code class="json-inline">${highlightJsonText(clipped)}</code>`;
2302
2435
  };
2303
2436
  const when = (epoch) => {
2304
2437
  const date = new Date(epoch);
2305
2438
  return Number.isNaN(date.getTime()) ? String(epoch) : date.toISOString();
2306
2439
  };
2440
+ const journalWhen = (value) => {
2441
+ const numeric = value.trim() === "" ? Number.NaN : Number(value);
2442
+ const epoch = Number.isFinite(numeric) ? numeric : Date.parse(value);
2443
+ return Number.isFinite(epoch) ? when(epoch) : value;
2444
+ };
2307
2445
  const clockCard = (epoch) => {
2308
2446
  const date = new Date(epoch);
2309
2447
  if (Number.isNaN(date.getTime()))
@@ -2423,7 +2561,7 @@ function bootAdmin(config) {
2423
2561
  };
2424
2562
  const renderOverview = async () => {
2425
2563
  const [health, shape, clock, journal] = await Promise.all([
2426
- originGet("/health"),
2564
+ originGet(`${config.adminPrefix}/health`),
2427
2565
  api("GET", "/state"),
2428
2566
  api("GET", "/clock"),
2429
2567
  api("GET", "/requests?limit=8")
@@ -2440,7 +2578,7 @@ function bootAdmin(config) {
2440
2578
  },
2441
2579
  {
2442
2580
  k: "Status",
2443
- v: esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")
2581
+ v: `<span class="badge ok">${esc(typeof health.status === "string" && health.status !== "" ? health.status : "ok")}</span>`
2444
2582
  },
2445
2583
  { k: "Namespace", v: esc(state.namespace) },
2446
2584
  { k: "Collections", v: String(decoded.collections.length) },
@@ -2527,26 +2665,46 @@ function bootAdmin(config) {
2527
2665
  const renderJournal = async () => {
2528
2666
  const journal = await api("GET", "/requests?limit=100");
2529
2667
  el("journal", HTMLElement).innerHTML = table([
2530
- { label: "When", cell: (row) => esc(row.at) },
2531
- { label: "Method", cell: (row) => esc(row.method) },
2668
+ { label: "When", cell: (row) => esc(journalWhen(row.at)) },
2669
+ {
2670
+ label: "Method",
2671
+ cell: (row) => `<span class="method">${esc(row.method)}</span>`
2672
+ },
2532
2673
  { label: "Path", cell: (row) => esc(row.path) },
2533
- { label: "Status", cell: (row) => esc(row.status) },
2674
+ {
2675
+ label: "Status",
2676
+ cell: (row) => `<span class="badge ${row.status.startsWith("2") ? "ok" : row.status.startsWith("4") || row.status.startsWith("5") ? "warn" : ""}">${esc(row.status)}</span>`
2677
+ },
2534
2678
  { label: "ms", cell: (row) => esc(row.durationMs) }
2535
2679
  ], decodeJournal(journal));
2536
2680
  };
2537
- const renderRoutes = async () => {
2538
- const data = await api("GET", "/");
2539
- if (!isRecord2(data))
2540
- throw new Error("Route list was not an object");
2541
- const routes = requireList(data.routes, "Routes").map((route) => String(route));
2681
+ const paintRoutes = () => {
2682
+ const query = el("route-search", HTMLInputElement).value.trim().toLocaleLowerCase();
2683
+ const routes = state.routes.filter((route) => route.toLocaleLowerCase().includes(query));
2684
+ el("route-count", HTMLElement).textContent = `${routes.length} of ${state.routes.length}`;
2685
+ if (state.routes.length === 0) {
2686
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No admin routes are available.</p>';
2687
+ return;
2688
+ }
2689
+ if (routes.length === 0) {
2690
+ el("route-list", HTMLElement).innerHTML = '<p class="empty">No routes match this filter.</p>';
2691
+ return;
2692
+ }
2542
2693
  el("route-list", HTMLElement).innerHTML = routes.map((route) => {
2543
2694
  const extra = standard.has(route) ? "" : " <span class='badge'>extension</span>";
2544
2695
  const parts = route.split(" ");
2545
2696
  const method = parts[0] ?? "";
2546
2697
  const path = parts.slice(1).join(" ");
2547
- return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}">Use</button></div>`;
2698
+ return `<div class="route"><span class="method">${esc(method)}</span><span>${esc(path)}${extra}</span><button class="btn" type="button" data-route="${esc(route)}" aria-label="Use ${esc(route)}">Use</button></div>`;
2548
2699
  }).join("");
2549
2700
  };
2701
+ const renderRoutes = async () => {
2702
+ const data = await api("GET", "/");
2703
+ if (!isRecord2(data))
2704
+ throw new Error("Route list was not an object");
2705
+ state.routes = requireList(data.routes, "Routes").map((route) => String(route));
2706
+ paintRoutes();
2707
+ };
2550
2708
  const renderers = {
2551
2709
  overview: renderOverview,
2552
2710
  state: renderState,
@@ -2555,19 +2713,50 @@ function bootAdmin(config) {
2555
2713
  journal: renderJournal,
2556
2714
  routes: renderRoutes
2557
2715
  };
2716
+ let refreshToken = 0;
2558
2717
  async function refresh() {
2718
+ const token = ++refreshToken;
2559
2719
  clearError();
2720
+ const main = el("views", HTMLElement);
2721
+ const sync = el("sync-status", HTMLElement);
2722
+ main.setAttribute("aria-busy", "true");
2723
+ sync.classList.add("busy");
2724
+ sync.textContent = "Updating";
2560
2725
  const render = renderers[state.view];
2561
- if (render)
2562
- await render();
2726
+ try {
2727
+ if (render)
2728
+ await render();
2729
+ if (token === refreshToken)
2730
+ sync.textContent = "Up to date";
2731
+ } finally {
2732
+ if (token === refreshToken) {
2733
+ main.removeAttribute("aria-busy");
2734
+ sync.classList.remove("busy");
2735
+ }
2736
+ }
2563
2737
  }
2564
2738
  const delay = (ms) => new Promise((resolve) => {
2565
2739
  window.setTimeout(resolve, ms);
2566
2740
  });
2567
- const confirmAction = async (button, pending, done, work) => {
2741
+ const confirmAction = async (button, pending, done, work, confirmLabel) => {
2568
2742
  if (button.dataset.pending === "1")
2569
2743
  return;
2570
2744
  const label = button.textContent ?? "";
2745
+ if (confirmLabel !== void 0 && button.dataset.confirming !== "1") {
2746
+ button.dataset.confirming = "1";
2747
+ button.classList.add("confirming");
2748
+ button.textContent = confirmLabel;
2749
+ window.setTimeout(() => {
2750
+ if (button.dataset.confirming !== "1")
2751
+ return;
2752
+ button.textContent = label;
2753
+ button.classList.remove("confirming");
2754
+ delete button.dataset.confirming;
2755
+ }, 3e3);
2756
+ return;
2757
+ }
2758
+ button.classList.remove("confirming");
2759
+ delete button.dataset.confirming;
2571
2760
  const width = button.offsetWidth;
2572
2761
  button.dataset.pending = "1";
2573
2762
  button.classList.add("pressed");
@@ -2588,6 +2777,65 @@ function bootAdmin(config) {
2588
2777
  delete button.dataset.pending;
2589
2778
  }
2590
2779
  };
2780
+ const wireJsonEditor = (textareaId, highlightId, statusId, shellId, allowEmpty) => {
2781
+ const textarea = el(textareaId, HTMLTextAreaElement);
2782
+ const highlight = el(highlightId, HTMLElement);
2783
+ const status = el(statusId, HTMLElement);
2784
+ const shell = el(shellId, HTMLElement);
2785
+ const sync = () => {
2786
+ const text = textarea.value;
2787
+ highlight.innerHTML = `${highlightJsonText(text)}
2788
+ `;
2789
+ let valid = true;
2790
+ let message = "Valid JSON";
2791
+ if (allowEmpty && text.trim() === "")
2792
+ message = "No body";
2793
+ else {
2794
+ try {
2795
+ readJson2(text);
2796
+ } catch {
2797
+ valid = false;
2798
+ message = "Invalid JSON";
2799
+ }
2800
+ }
2801
+ shell.classList.toggle("invalid", !valid);
2802
+ status.classList.toggle("invalid", !valid);
2803
+ status.textContent = message;
2804
+ textarea.setAttribute("aria-invalid", valid ? "false" : "true");
2805
+ };
2806
+ const syncScroll = () => {
2807
+ const preview2 = highlight.parentElement;
2808
+ if (!(preview2 instanceof HTMLElement))
2809
+ return;
2810
+ preview2.scrollTop = textarea.scrollTop;
2811
+ preview2.scrollLeft = textarea.scrollLeft;
2812
+ };
2813
+ textarea.addEventListener("input", sync);
2814
+ textarea.addEventListener("scroll", syncScroll);
2815
+ sync();
2816
+ return sync;
2817
+ };
2818
+ const syncRouteEditor = wireJsonEditor("route-body", "route-highlight", "route-json-status", "route-editor", true);
2819
+ const syncRecordEditor = wireJsonEditor("editor-value", "editor-highlight", "editor-json-status", "record-editor", false);
2820
+ for (const button of document.querySelectorAll("[data-format]")) {
2821
+ if (!(button instanceof HTMLButtonElement))
2822
+ continue;
2823
+ button.addEventListener("click", () => {
2824
+ const target = button.dataset.format;
2825
+ if (target === void 0)
2826
+ return;
2827
+ const textarea = document.getElementById(target);
2828
+ if (!(textarea instanceof HTMLTextAreaElement) || textarea.value.trim() === "")
2829
+ return;
2830
+ try {
2831
+ textarea.value = JSON.stringify(readJson2(textarea.value), null, 2) ?? "";
2832
+ textarea.dispatchEvent(new Event("input"));
2833
+ textarea.focus();
2834
+ } catch {
2835
+ showError(new Error("Fix the JSON before formatting it"));
2836
+ }
2837
+ });
2838
+ }
2591
2839
  document.addEventListener("click", (event) => {
2592
2840
  const target = event.target;
2593
2841
  if (!(target instanceof Element))
@@ -2660,6 +2908,7 @@ function bootAdmin(config) {
2660
2908
  } else {
2661
2909
  editorValue.value = "{\n \n}";
2662
2910
  }
2911
+ syncRecordEditor();
2663
2912
  editor.showModal();
2664
2913
  }
2665
2914
  el("new-record", HTMLButtonElement).addEventListener("click", () => {
@@ -2689,10 +2938,10 @@ function bootAdmin(config) {
2689
2938
  const id = state.editing;
2690
2939
  if (!id)
2691
2940
  return;
2692
- api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2941
+ confirmAction(editorDelete, "Deleting...", "Deleted", () => api("DELETE", `/state/${encodeURIComponent(state.collection)}/${encodeURIComponent(id)}`).then(() => {
2693
2942
  editor.close();
2694
2943
  return renderState();
2695
- }).catch(showError);
2944
+ }), "Confirm delete").catch(showError);
2696
2945
  });
2697
2946
  for (const button of document.querySelectorAll("[data-advance]")) {
2698
2947
  if (!(button instanceof HTMLButtonElement))
@@ -2738,10 +2987,10 @@ function bootAdmin(config) {
2738
2987
  }).then(() => renderFaults()).catch(showError);
2739
2988
  });
2740
2989
  el("fault-clear", HTMLButtonElement).addEventListener("click", () => {
2741
- confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults())).catch(showError);
2990
+ confirmAction(el("fault-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/faults").then(() => renderFaults()), "Confirm clear").catch(showError);
2742
2991
  });
2743
2992
  el("journal-clear", HTMLButtonElement).addEventListener("click", () => {
2744
- confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal())).catch(showError);
2993
+ confirmAction(el("journal-clear", HTMLButtonElement), "Clearing...", "Cleared", () => api("DELETE", "/requests").then(() => renderJournal()), "Confirm clear").catch(showError);
2745
2994
  });
2746
2995
  el("route-list", HTMLElement).addEventListener("click", (event) => {
2747
2996
  const target = event.target;
@@ -2755,9 +3004,15 @@ function bootAdmin(config) {
2755
3004
  return;
2756
3005
  state.route = route;
2757
3006
  el("route-title", HTMLElement).textContent = route;
3007
+ el("route-send", HTMLButtonElement).disabled = false;
2758
3008
  const method = route.split(" ")[0] ?? "";
2759
- el("route-body", HTMLTextAreaElement).disabled = method === "GET" || method === "DELETE";
3009
+ const routeBody = el("route-body", HTMLTextAreaElement);
3010
+ routeBody.disabled = method === "GET" || method === "DELETE";
3011
+ el("route-editor", HTMLElement).hidden = routeBody.disabled;
3012
+ el("route-json-status", HTMLElement).parentElement?.toggleAttribute("hidden", routeBody.disabled);
3013
+ syncRouteEditor();
2760
3014
  });
3015
+ el("route-search", HTMLInputElement).addEventListener("input", paintRoutes);
2761
3016
  el("route-form", HTMLFormElement).addEventListener("submit", (event) => {
2762
3017
  event.preventDefault();
2763
3018
  const send = async () => {
@@ -2779,7 +3034,8 @@ function bootAdmin(config) {
2779
3034
  }
2780
3035
  }
2781
3036
  const data = await api(method, concrete, body);
2782
- el("route-result", HTMLElement).textContent = JSON.stringify(data, null, 2);
3037
+ const text = JSON.stringify(data, null, 2) ?? "null";
3038
+ el("route-result", HTMLElement).innerHTML = `<code>${highlightJsonText(text)}</code>`;
2783
3039
  };
2784
3040
  send().catch(showError);
2785
3041
  });
@@ -2897,11 +3153,13 @@ function bootAdmin(config) {
2897
3153
  views.append(section);
2898
3154
  mountSqlExplorer(body, panelApi);
2899
3155
  }
3156
+ show(document.getElementById(`view-${state.view}`) === null ? "overview" : state.view);
2900
3157
  return refresh();
2901
3158
  }).catch(showError);
2902
3159
  }
2903
3160
  var clientPrelude = [
2904
3161
  isRecord2,
3162
+ highlightJsonText,
2905
3163
  mountAdminBrand,
2906
3164
  startAdminBrand,
2907
3165
  faultPresetList,
@@ -2924,6 +3182,7 @@ ${entry}(${payload});
2924
3182
  var defineMock = (runtime) => runtime;
2925
3183
  var STANDARD_ADMIN_ROUTES = [
2926
3184
  "GET /",
3185
+ "GET /health",
2927
3186
  "POST /reset",
2928
3187
  "GET /namespaces",
2929
3188
  "GET /clock",
@@ -3003,11 +3262,11 @@ var escapeHtml = (value) => value.replace(/[&<>"']/g, (char) => {
3003
3262
  }
3004
3263
  });
3005
3264
  var ADMIN_BRANDS_URL = "https://mockingbird.chrisvouga.dev/brands.json";
3006
- var renderAdminDocument = (service) => {
3265
+ var renderAdminDocument = (service, adminPrefix = ADMIN_PREFIX) => {
3007
3266
  const name = escapeHtml(service);
3008
3267
  const script = adminClientSource({
3009
3268
  standardRoutes: STANDARD_ADMIN_ROUTES,
3010
- adminPrefix: ADMIN_PREFIX,
3269
+ adminPrefix,
3011
3270
  adminKeyHeader: ADMIN_KEY_HEADER,
3012
3271
  brandsUrl: ADMIN_BRANDS_URL,
3013
3272
  service
@@ -3024,75 +3283,99 @@ var renderAdminDocument = (service) => {
3024
3283
  ${CSS_RESET}
3025
3284
  :root {
3026
3285
  color-scheme: light;
3027
- --bg: #fafafa;
3286
+ --bg: #f7f8fb;
3028
3287
  --bg-elev: #ffffff;
3029
- --bg-muted: #f4f4f5;
3030
- --bg-inset: #f4f4f5;
3031
- --line: #dedee3;
3032
- --line-strong: #c4c4cc;
3033
- --ink: #18181b;
3034
- --muted: #62626b;
3035
- --faint: #71717a;
3036
- --accent: #27272a;
3288
+ --bg-muted: #f1f3f7;
3289
+ --bg-inset: #f8f9fc;
3290
+ --line: #e4e7ec;
3291
+ --line-strong: #cfd4dc;
3292
+ --ink: #101828;
3293
+ --muted: #475467;
3294
+ --faint: #667085;
3295
+ --accent: #6941c6;
3296
+ --accent-hover: #5933b4;
3037
3297
  --accent-ink: #ffffff;
3038
- --accent-soft: #f4f4f5;
3039
- --ok: #166534;
3040
- --ok-soft: #f0fdf4;
3041
- --warn: #a16207;
3042
- --warn-soft: #fefce8;
3043
- --err: #a82d32;
3044
- --err-soft: #fef2f2;
3045
- --shadow: none;
3298
+ --accent-soft: #f4f0ff;
3299
+ --ok: #067647;
3300
+ --ok-soft: #ecfdf3;
3301
+ --warn: #b54708;
3302
+ --warn-soft: #fffaeb;
3303
+ --err: #b42318;
3304
+ --err-soft: #fef3f2;
3305
+ --code-key: #6941c6;
3306
+ --code-string: #067647;
3307
+ --code-number: #175cd3;
3308
+ --code-boolean: #c11574;
3309
+ --code-null: #667085;
3310
+ --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.05);
3311
+ --shadow-sm: 0 1px 3px rgb(16 24 40 / 0.08), 0 1px 2px rgb(16 24 40 / 0.04);
3312
+ --shadow-lg: 0 18px 48px rgb(16 24 40 / 0.16), 0 4px 12px rgb(16 24 40 / 0.08);
3046
3313
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
3047
3314
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
3048
- --radius: 10px;
3049
- --header: 56px;
3050
- --nav: 200px;
3315
+ --radius: 12px;
3316
+ --header: 72px;
3317
+ --nav: 224px;
3051
3318
  }
3052
3319
  :root[data-theme="dark"] {
3053
3320
  color-scheme: dark;
3054
- --bg: #111113;
3055
- --bg-elev: #19191c;
3056
- --bg-muted: #242428;
3057
- --bg-inset: #111113;
3058
- --line: #36363c;
3059
- --line-strong: #52525b;
3060
- --ink: #f4f4f5;
3061
- --muted: #a9a9b2;
3062
- --faint: #71717a;
3063
- --accent: #e4e4e7;
3064
- --accent-ink: #18181b;
3065
- --accent-soft: #242428;
3066
- --ok: #86efac;
3067
- --ok-soft: #14241b;
3068
- --warn: #fde68a;
3069
- --warn-soft: #2a2410;
3070
- --err: #ffaaaa;
3071
- --err-soft: #2c1516;
3072
- --shadow: none;
3321
+ --bg: #0c0e14;
3322
+ --bg-elev: #151821;
3323
+ --bg-muted: #20232e;
3324
+ --bg-inset: #11141c;
3325
+ --line: #2b303d;
3326
+ --line-strong: #414858;
3327
+ --ink: #f5f7fa;
3328
+ --muted: #b6bdc9;
3329
+ --faint: #8d96a7;
3330
+ --accent: #9e77ed;
3331
+ --accent-hover: #b692f6;
3332
+ --accent-ink: #ffffff;
3333
+ --accent-soft: #2b2142;
3334
+ --ok: #75e0a7;
3335
+ --ok-soft: #102a20;
3336
+ --warn: #fec84b;
3337
+ --warn-soft: #302611;
3338
+ --err: #fda29b;
3339
+ --err-soft: #321817;
3340
+ --code-key: #c3a6ff;
3341
+ --code-string: #75e0a7;
3342
+ --code-number: #84adff;
3343
+ --code-boolean: #f9a8d4;
3344
+ --code-null: #98a2b3;
3345
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3346
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3347
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
3073
3348
  }
3074
3349
  @media (prefers-color-scheme: dark) {
3075
3350
  :root:not([data-theme="light"]) {
3076
3351
  color-scheme: dark;
3077
- --bg: #111113;
3078
- --bg-elev: #19191c;
3079
- --bg-muted: #242428;
3080
- --bg-inset: #111113;
3081
- --line: #36363c;
3082
- --line-strong: #52525b;
3083
- --ink: #f4f4f5;
3084
- --muted: #a9a9b2;
3085
- --faint: #71717a;
3086
- --accent: #e4e4e7;
3087
- --accent-ink: #18181b;
3088
- --accent-soft: #242428;
3089
- --ok: #86efac;
3090
- --ok-soft: #14241b;
3091
- --warn: #fde68a;
3092
- --warn-soft: #2a2410;
3093
- --err: #ffaaaa;
3094
- --err-soft: #2c1516;
3095
- --shadow: none;
3352
+ --bg: #0c0e14;
3353
+ --bg-elev: #151821;
3354
+ --bg-muted: #20232e;
3355
+ --bg-inset: #11141c;
3356
+ --line: #2b303d;
3357
+ --line-strong: #414858;
3358
+ --ink: #f5f7fa;
3359
+ --muted: #b6bdc9;
3360
+ --faint: #8d96a7;
3361
+ --accent: #9e77ed;
3362
+ --accent-hover: #b692f6;
3363
+ --accent-ink: #ffffff;
3364
+ --accent-soft: #2b2142;
3365
+ --ok: #75e0a7;
3366
+ --ok-soft: #102a20;
3367
+ --warn: #fec84b;
3368
+ --warn-soft: #302611;
3369
+ --err: #fda29b;
3370
+ --err-soft: #321817;
3371
+ --code-key: #c3a6ff;
3372
+ --code-string: #75e0a7;
3373
+ --code-number: #84adff;
3374
+ --code-boolean: #f9a8d4;
3375
+ --code-null: #98a2b3;
3376
+ --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.24);
3377
+ --shadow-sm: 0 4px 12px rgb(0 0 0 / 0.2);
3378
+ --shadow-lg: 0 20px 56px rgb(0 0 0 / 0.45);
3096
3379
  }
3097
3380
  }
3098
3381
  /* Fill the viewport, then grow with the content so the background covers the scroll. */
@@ -3110,13 +3393,17 @@ var renderAdminDocument = (service) => {
3110
3393
  padding-right: env(safe-area-inset-right);
3111
3394
  -webkit-text-size-adjust: 100%;
3112
3395
  }
3113
- :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
3396
+ ::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
3397
+ :focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
3398
+ button, input, select, textarea { transition: border-color 140ms ease, box-shadow 140ms ease, transform 100ms ease; }
3399
+ button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: 0.55; }
3114
3400
  .app { flex: 1 0 auto; display: flex; flex-direction: column; min-width: 0; width: 100%; }
3115
3401
  header.top {
3116
- position: sticky; top: 0; z-index: 5;
3402
+ position: sticky; top: 0; z-index: 20;
3117
3403
  display: flex; align-items: center; gap: 12px;
3118
- min-height: var(--header); padding: 10px 16px;
3119
- background: var(--bg-elev);
3404
+ min-height: var(--header); padding: 12px 20px;
3405
+ background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
3406
+ backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
3120
3407
  border-bottom: 1px solid var(--line);
3121
3408
  min-width: 0; max-width: 100%;
3122
3409
  }
@@ -3124,12 +3411,21 @@ var renderAdminDocument = (service) => {
3124
3411
  display: flex; flex-flow: row wrap; align-items: center; gap: 14px;
3125
3412
  min-width: 0; max-width: 100%; margin-right: auto;
3126
3413
  }
3127
- .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; }
3128
- .brand-id strong { font-size: 15px; letter-spacing: -0.01em; }
3414
+ .brand-lockup { display: flex; align-items: center; gap: 10px; min-width: 0; }
3415
+ .brand-mark {
3416
+ width: 38px; height: 38px; display: grid; place-items: center; flex: none;
3417
+ border-radius: 11px; color: #fff;
3418
+ background: linear-gradient(145deg, #7f56d9 0%, #53389e 100%);
3419
+ box-shadow: 0 6px 16px rgb(105 65 198 / 0.24), inset 0 1px 0 rgb(255 255 255 / 0.25);
3420
+ }
3421
+ .brand-mark svg { width: 22px; height: 22px; }
3422
+ .brand-id { display: flex; flex-direction: column; min-width: 0; flex: none; line-height: 1.25; }
3423
+ .brand-id strong { font-size: 15px; letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
3129
3424
  .brand-id span { color: var(--faint); font-size: 12px; }
3130
3425
  .vendor {
3131
3426
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
3132
3427
  min-width: 0; max-width: 100%; font-size: 12px; color: var(--muted);
3428
+ padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg-inset);
3133
3429
  }
3134
3430
  .vendor[hidden] { display: none; }
3135
3431
  /* Logos are drawn for a light tile, same as the docs site, so the plate stays white. */
@@ -3141,12 +3437,17 @@ var renderAdminDocument = (service) => {
3141
3437
  .vendor-sep { color: var(--faint); }
3142
3438
  .vendor-link { color: inherit; text-decoration: none; }
3143
3439
  .vendor-link:hover { color: var(--ink); text-decoration: underline; }
3144
- .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
3145
- label.field { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--faint); }
3440
+ .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
3441
+ .sync-status { align-self: center; display: flex; align-items: center; gap: 6px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3442
+ .sync-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
3443
+ .sync-status.busy::before { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: pulse 1.2s ease-in-out infinite; }
3444
+ label.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 600; color: var(--faint); }
3146
3445
  label.field input, label.field select, .controls input[type="password"] {
3147
- background-color: var(--bg-inset); border: 1px solid var(--line); border-radius: 8px;
3148
- padding: 7px 8px; min-height: 36px; line-height: 1.2;
3446
+ background-color: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: 9px;
3447
+ padding: 8px 10px; min-height: 38px; line-height: 1.2; box-shadow: var(--shadow-xs);
3149
3448
  }
3449
+ label.field input:hover, label.field select:hover, textarea:hover { border-color: color-mix(in srgb, var(--accent) 38%, var(--line-strong)); }
3450
+ label.field input:focus, label.field select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); outline: none; }
3150
3451
  /* A native menu ignores min-height, so Preset rendered about half as tall as
3151
3452
  the text fields in the same form. Paint it like those fields. */
3152
3453
  label.field select {
@@ -3163,12 +3464,20 @@ var renderAdminDocument = (service) => {
3163
3464
  dialog .field > textarea { width: 100%; }
3164
3465
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger, nav.side button { cursor: pointer; }
3165
3466
  .icon-btn, .btn, .btn-primary, .btn-quiet, .btn-danger {
3166
- border-radius: 9px; min-height: 36px; padding: 0 12px; border: 1px solid var(--line);
3167
- background: var(--bg-elev);
3168
- }
3169
- .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
3170
- .btn-quiet { background: transparent; }
3171
- .btn-danger { color: var(--err); }
3467
+ display: inline-flex; align-items: center; justify-content: center; gap: 7px;
3468
+ border-radius: 9px; min-height: 38px; padding: 0 13px; border: 1px solid var(--line-strong);
3469
+ background: var(--bg-elev); color: var(--ink); font-size: 13px; font-weight: 600; line-height: 1;
3470
+ box-shadow: var(--shadow-xs);
3471
+ }
3472
+ .icon-btn { width: 38px; padding: 0; }
3473
+ .icon-btn svg, .btn svg, .btn-primary svg { width: 16px; height: 16px; }
3474
+ .icon-btn:hover, .btn:hover { background: var(--bg-muted); border-color: var(--line-strong); }
3475
+ .btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); box-shadow: 0 1px 2px rgb(16 24 40 / 0.08), 0 0 0 1px rgb(255 255 255 / 0.08) inset; }
3476
+ .btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
3477
+ .btn-quiet { background: transparent; border-color: transparent; box-shadow: none; }
3478
+ .btn-quiet:hover { background: var(--bg-muted); }
3479
+ .btn-danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, var(--line)); }
3480
+ .btn-danger:hover, .btn-danger.confirming { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
3172
3481
  /* Held after mouseup. Clearing an empty journal changes nothing on screen,
3173
3482
  so the press itself has to stay visible. */
3174
3483
  .icon-btn:active, .btn:active, .btn-quiet:active, .btn-danger:active, nav.side button:active,
@@ -3184,93 +3493,159 @@ var renderAdminDocument = (service) => {
3184
3493
  flex: 1 0 auto; min-width: 0;
3185
3494
  }
3186
3495
  nav.side {
3187
- border-right: 1px solid var(--line); padding: 12px;
3496
+ position: sticky; top: var(--header); align-self: start; height: calc(100vh - var(--header));
3497
+ border-right: 1px solid var(--line); padding: 18px 12px;
3188
3498
  display: flex; flex-direction: column; gap: 4px;
3189
- background: var(--bg-elev);
3499
+ background: var(--bg-elev); overflow-y: auto;
3190
3500
  }
3501
+ .nav-label { padding: 0 10px 8px; color: var(--faint); font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
3191
3502
  nav.side button {
3503
+ position: relative; display: flex; align-items: center; gap: 10px; width: 100%;
3192
3504
  text-align: left; border: 0; background: transparent; border-radius: 9px;
3193
- padding: 9px 10px; min-height: 40px; color: var(--muted);
3194
- }
3195
- nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
3196
- main { padding: 20px; max-width: 1100px; width: 100%; min-width: 0; }
3197
- .view h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
3198
- .lede { margin: 0 0 16px; color: var(--muted); }
3199
- .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr)); gap: 12px; }
3505
+ padding: 9px 10px; min-height: 42px; color: var(--muted); font-size: 13px; font-weight: 550;
3506
+ }
3507
+ nav.side button:hover { background: var(--bg-muted); color: var(--ink); }
3508
+ nav.side button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
3509
+ nav.side button[aria-current="true"]::before { content: ""; position: absolute; left: -12px; width: 3px; height: 22px; border-radius: 0 4px 4px 0; background: var(--accent); }
3510
+ .nav-icon { width: 18px; height: 18px; display: grid; place-items: center; flex: none; }
3511
+ .nav-icon svg { width: 18px; height: 18px; }
3512
+ main { padding: 32px clamp(20px, 4vw, 48px) 64px; max-width: 1320px; width: 100%; min-width: 0; }
3513
+ main[aria-busy="true"] .view { opacity: 0.62; }
3514
+ .view { animation: view-in 180ms ease-out; }
3515
+ .view[hidden] { display: none; }
3516
+ .view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
3517
+ .view h2 { margin: 0 0 5px; font-size: clamp(24px, 3vw, 30px); line-height: 1.2; letter-spacing: -0.035em; }
3518
+ .view h3 { margin: 24px 0 10px; font-size: 15px; letter-spacing: -0.01em; }
3519
+ .lede { margin: 0; color: var(--muted); max-width: 72ch; font-size: 14px; }
3520
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: 14px; }
3200
3521
  .card {
3201
3522
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
3202
- padding: 14px 16px; box-shadow: var(--shadow);
3523
+ padding: 18px; box-shadow: var(--shadow-sm);
3203
3524
  }
3204
- .card .k { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
3205
- .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 22px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
3525
+ .stat-card { position: relative; overflow: hidden; }
3526
+ .stat-card::after { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, var(--accent), transparent 78%); opacity: 0.7; }
3527
+ .card .k { color: var(--faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; }
3528
+ .card .v { display: flex; flex-direction: column; gap: 2px; font-size: 24px; font-weight: 650; margin-top: 7px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; letter-spacing: -0.025em; }
3206
3529
  .card .v .clock-time { font-size: 14px; color: var(--muted); }
3207
- .split { display: grid; grid-template-columns: minmax(0, 240px) minmax(0, 1fr); gap: 16px; align-items: start; }
3530
+ .section-card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-xs); overflow: hidden; }
3531
+ .section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
3532
+ .section-title h3 { margin: 0; }
3533
+ .split { display: grid; grid-template-columns: minmax(0, 250px) minmax(0, 1fr); gap: 18px; align-items: start; }
3534
+ #collections { padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs); }
3208
3535
  .collection {
3209
3536
  width: 100%; text-align: left; border: 1px solid transparent; background: transparent;
3210
- border-radius: 10px; padding: 8px 10px; min-height: 44px;
3537
+ border-radius: 9px; padding: 10px 11px; min-height: 48px; color: var(--ink); cursor: pointer;
3211
3538
  }
3212
- .collection[aria-current="true"] { background: var(--bg-elev); border-color: var(--line); }
3539
+ .collection:hover { background: var(--bg-muted); }
3540
+ .collection[aria-current="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 18%, var(--line)); color: var(--accent); }
3213
3541
  .collection small { display: block; color: var(--faint); }
3214
3542
  .chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
3215
- .chip {
3216
- font-family: var(--mono); font-size: 12px; background: var(--bg-muted);
3217
- border-radius: 999px; padding: 4px 8px;
3218
- }
3543
+ .chip { font-family: var(--mono); font-size: 11px; background: var(--bg-muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; }
3219
3544
  .chip i { color: var(--faint); font-style: normal; }
3220
3545
  .sql-layout {
3221
3546
  display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3222
3547
  }
3223
- .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3224
- .sql-tables button { text-align: left; }
3548
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
3549
+ .sql-tables button { text-align: left; border: 0; border-radius: 8px; padding: 9px 10px; background: transparent; color: var(--muted); cursor: pointer; }
3550
+ .sql-tables button:hover, .sql-tables button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
3225
3551
  .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
3226
- table { width: 100%; border-collapse: collapse; font-size: 14px; }
3227
- th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
3228
- th { color: var(--faint); font-weight: 600; font-size: 12px; }
3552
+ .table-shell { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow-xs); }
3553
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
3554
+ th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }
3555
+ th { color: var(--faint); background: var(--bg-inset); font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: 0.045em; }
3556
+ tbody tr:last-child td { border-bottom: 0; }
3229
3557
  tr.clickable { cursor: pointer; }
3230
- tr.clickable:hover { background: var(--bg-muted); }
3558
+ tr.clickable:hover { background: var(--accent-soft); }
3231
3559
  pre, code, .mono { font-family: var(--mono); overflow-wrap: anywhere; }
3232
3560
  pre {
3233
3561
  margin: 0; white-space: pre-wrap; word-break: break-word;
3234
- background: var(--bg-inset); border-radius: 10px; padding: 12px; font-size: 12px;
3235
- }
3236
- .row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
3562
+ background: var(--bg-inset); border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-size: 12px; line-height: 1.65;
3563
+ }
3564
+ .json-key { color: var(--code-key); }
3565
+ .json-string { color: var(--code-string); }
3566
+ .json-number { color: var(--code-number); }
3567
+ .json-boolean { color: var(--code-boolean); }
3568
+ .json-null { color: var(--code-null); font-style: italic; }
3569
+ .json-inline { display: block; max-width: 44rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
3570
+ .json-view { position: relative; max-height: 26rem; overflow: auto; }
3571
+ .json-editor { position: relative; min-height: 190px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--bg-inset); overflow: hidden; }
3572
+ .json-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
3573
+ .json-editor.invalid { border-color: var(--err); }
3574
+ .json-editor pre, .json-editor textarea { margin: 0; padding: 12px; border: 0; border-radius: 0; min-height: 190px; width: 100%; font: 12px/1.65 var(--mono); tab-size: 2; white-space: pre; overflow: auto; }
3575
+ .json-editor pre { position: absolute; inset: 0; pointer-events: none; background: transparent; }
3576
+ .json-editor textarea { position: relative; z-index: 1; resize: vertical; background: transparent; color: transparent; caret-color: var(--ink); -webkit-text-fill-color: transparent; }
3577
+ .json-editor textarea::selection { background: color-mix(in srgb, var(--accent) 32%, transparent); }
3578
+ .editor-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 7px; }
3579
+ .json-status { display: inline-flex; align-items: center; gap: 6px; color: var(--ok); font-size: 11px; }
3580
+ .json-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
3581
+ .json-status.invalid { color: var(--err); }
3582
+ .format-json { border: 0; padding: 3px 5px; background: transparent; color: var(--accent); font-size: 11px; font-weight: 650; cursor: pointer; }
3583
+ .row-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin: 14px 0; }
3237
3584
  .banner {
3238
- display: none; margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
3239
- background: var(--err-soft); color: var(--err);
3240
- }
3241
- .banner.show { display: block; }
3242
- .empty { color: var(--muted); padding: 24px 8px; }
3585
+ display: none; position: sticky; top: calc(var(--header) + 12px); z-index: 15;
3586
+ align-items: center; gap: 10px; margin: 0 0 16px; padding: 11px 12px 11px 14px;
3587
+ border: 1px solid color-mix(in srgb, var(--err) 30%, var(--line)); border-radius: 10px;
3588
+ background: var(--err-soft); color: var(--err); box-shadow: var(--shadow-sm); font-size: 13px;
3589
+ }
3590
+ .banner.show { display: flex; }
3591
+ .banner span { flex: 1; }
3592
+ .banner button { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: currentColor; cursor: pointer; }
3593
+ .banner button:hover { background: color-mix(in srgb, var(--err) 10%, transparent); }
3594
+ .empty { color: var(--muted); padding: 34px 18px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: color-mix(in srgb, var(--bg-elev) 55%, transparent); }
3243
3595
  dialog {
3244
- border: 1px solid var(--line); border-radius: var(--radius); padding: 0; background: var(--bg-elev);
3245
- color: var(--ink); width: min(640px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: none;
3246
- }
3247
- dialog::backdrop { background: rgb(20 19 17 / 0.45); }
3248
- dialog form, .dialog-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
3596
+ border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--bg-elev);
3597
+ color: var(--ink); width: min(720px, calc(100% - 24px)); max-width: calc(100vw - 24px); box-shadow: var(--shadow-lg);
3598
+ }
3599
+ dialog[open] { animation: dialog-in 160ms ease-out; }
3600
+ dialog::backdrop { background: rgb(12 14 20 / 0.58); backdrop-filter: blur(3px); }
3601
+ dialog form, .dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
3602
+ .dialog-heading { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
3603
+ .dialog-heading strong { font-size: 18px; letter-spacing: -0.02em; }
3604
+ .dialog-heading span { color: var(--muted); font-size: 12px; }
3249
3605
  textarea {
3250
3606
  width: 100%; min-height: 180px; resize: vertical; border-radius: 10px;
3251
3607
  border: 1px solid var(--line); background: var(--bg-inset); padding: 10px;
3252
3608
  font-family: var(--mono); font-size: 12px;
3253
3609
  }
3254
- .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
3255
- .badge { font-size: 11px; border-radius: 999px; padding: 2px 7px; background: var(--bg-muted); color: var(--muted); }
3610
+ .dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 4px; }
3611
+ .dialog-actions .btn-danger { margin-right: auto; }
3612
+ .badge { display: inline-flex; align-items: center; font-size: 10px; font-weight: 700; letter-spacing: 0.03em; border: 1px solid var(--line); border-radius: 999px; padding: 3px 7px; background: var(--bg-muted); color: var(--muted); }
3256
3613
  .badge.ok { background: var(--ok-soft); color: var(--ok); }
3257
3614
  .badge.warn { background: var(--warn-soft); color: var(--warn); }
3258
3615
  .status-2 { color: var(--ok); }
3259
3616
  .status-4, .status-5, .status-0 { color: var(--err); }
3260
3617
  .stack { display: flex; flex-direction: column; gap: 12px; }
3618
+ .form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
3619
+ .form-grid .wide { grid-column: span 2; }
3261
3620
  .route {
3262
- display: grid; grid-template-columns: 88px 1fr auto; gap: 8px; align-items: center;
3263
- padding: 8px 0; border-bottom: 1px solid var(--line);
3264
- }
3265
- .method { font-family: var(--mono); font-size: 12px; font-weight: 700; }
3621
+ display: grid; grid-template-columns: 84px minmax(0, 1fr) auto; gap: 10px; align-items: center;
3622
+ padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg-elev);
3623
+ }
3624
+ .route:first-child { border-radius: var(--radius) var(--radius) 0 0; }
3625
+ .route:last-child { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
3626
+ .route-tools { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 12px; }
3627
+ .route-tools .field { flex: 1; }
3628
+ .route-tools input { width: 100%; }
3629
+ .route-count { padding-bottom: 10px; color: var(--faint); font-size: 12px; white-space: nowrap; }
3630
+ #route-list { max-height: 34rem; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow-xs); }
3631
+ .method { width: fit-content; font-family: var(--mono); font-size: 11px; font-weight: 750; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 4px 6px; }
3632
+ @keyframes view-in { from { transform: translateY(3px); } to { transform: translateY(0); } }
3633
+ @keyframes dialog-in { from { transform: translateY(8px) scale(0.99); } to { transform: translateY(0) scale(1); } }
3634
+ @keyframes pulse { 50% { opacity: 0.45; } }
3635
+ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
3636
+ @media (forced-colors: active) { .json-editor pre { display: none; } .json-editor textarea { color: CanvasText; -webkit-text-fill-color: CanvasText; } }
3266
3637
  @media (max-width: 800px) {
3638
+ :root { --header: 0px; }
3267
3639
  header.top {
3268
- align-items: stretch; flex-direction: column;
3269
- padding-top: max(10px, env(safe-area-inset-top));
3640
+ position: relative; align-items: stretch; flex-direction: column;
3641
+ padding: max(12px, env(safe-area-inset-top)) 14px 12px;
3270
3642
  }
3271
3643
  input, select, textarea { font-size: 16px; }
3272
3644
  .brand, .vendor, .controls { width: 100%; }
3645
+ .brand { gap: 10px; }
3646
+ .vendor { order: 2; border-radius: 9px; }
3273
3647
  label.field, label.field select, label.field input { flex: 1; min-width: 0; }
3648
+ .sync-status { display: none; }
3274
3649
  /* The layout fills the screen. A single-column grid stretches every auto
3275
3650
  row, so the tab bar grew with the leftover height and the buttons floated
3276
3651
  in the middle of it. The bar stays one row; the page below takes the rest. */
@@ -3280,14 +3655,23 @@ var renderAdminDocument = (service) => {
3280
3655
  align-content: start;
3281
3656
  }
3282
3657
  nav.side {
3283
- align-self: start; height: auto;
3658
+ position: sticky; top: 0; z-index: 12; align-self: start; height: auto;
3284
3659
  flex-direction: row; align-items: center; overflow-x: auto; min-width: 0;
3285
3660
  border-right: 0; border-bottom: 1px solid var(--line);
3286
- padding: 8px;
3661
+ padding: 8px; box-shadow: var(--shadow-xs);
3287
3662
  }
3288
- nav.side button { white-space: nowrap; flex: none; }
3663
+ .nav-label { display: none; }
3664
+ nav.side button { width: auto; white-space: nowrap; flex: none; }
3665
+ nav.side button[aria-current="true"]::before { inset: auto 9px -8px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
3289
3666
  .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
3290
- main { padding: 14px; }
3667
+ .form-grid { grid-template-columns: minmax(0, 1fr); }
3668
+ .form-grid .wide { grid-column: auto; }
3669
+ main { padding: 22px 14px 48px; }
3670
+ .view-head { margin-bottom: 18px; }
3671
+ .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
3672
+ .card { padding: 14px; }
3673
+ .card .v { font-size: 20px; }
3674
+ .table-shell { border: 0; background: transparent; box-shadow: none; overflow: visible; }
3291
3675
  table, thead, tbody, tr, th, td { display: block; }
3292
3676
  thead { display: none; }
3293
3677
  tr {
@@ -3302,50 +3686,63 @@ var renderAdminDocument = (service) => {
3302
3686
  .route { grid-template-columns: 72px 1fr; }
3303
3687
  .route button { grid-column: 1 / -1; }
3304
3688
  }
3689
+ @media (max-width: 460px) {
3690
+ .controls label.field { min-width: calc(50% - 4px); }
3691
+ .controls .icon-btn, .controls .btn { flex: 1; }
3692
+ .grid { grid-template-columns: minmax(0, 1fr); }
3693
+ .dialog-actions { flex-wrap: wrap; }
3694
+ .dialog-actions button { flex: 1; }
3695
+ .dialog-actions .btn-danger { flex-basis: 100%; margin-right: 0; }
3696
+ }
3305
3697
  </style>
3306
3698
  </head>
3307
3699
  <body>
3308
3700
  <div class="app" data-service="${name}" data-mockingbird-admin>
3309
3701
  <header class="top">
3310
3702
  <div class="brand">
3311
- <div class="brand-id">
3312
- <strong>${name}</strong>
3313
- <span>Admin</span>
3703
+ <div class="brand-lockup">
3704
+ <div class="brand-mark" aria-hidden="true">
3705
+ <svg viewBox="0 0 24 24" fill="none"><path d="M5 17.5V7l7 5 7-5v10.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/><path d="M8 15.5 12 18l4-2.5" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>
3706
+ </div>
3707
+ <div class="brand-id">
3708
+ <strong>${name}</strong>
3709
+ <span>Mock admin</span>
3710
+ </div>
3314
3711
  </div>
3315
3712
  <div class="vendor" id="vendor" hidden></div>
3316
3713
  </div>
3317
3714
  <div class="controls">
3715
+ <span class="sync-status" id="sync-status" role="status" aria-live="polite">Ready</span>
3318
3716
  <label class="field">Namespace
3319
3717
  <select id="namespace" aria-label="Namespace"></select>
3320
3718
  </label>
3321
3719
  <label class="field">Admin key
3322
3720
  <input id="admin-key" type="password" autocomplete="off" spellcheck="false" aria-label="Admin key">
3323
3721
  </label>
3324
- <button class="icon-btn" id="theme" type="button" aria-label="Toggle color theme">Theme</button>
3325
- <button class="btn" id="refresh" type="button">Refresh</button>
3722
+ <button class="icon-btn" id="theme" type="button" aria-label="Use dark theme" title="Use dark theme"></button>
3723
+ <button class="btn" id="refresh" type="button"><svg viewBox="0 0 20 20" fill="none" aria-hidden="true"><path d="M15.8 7.2A6.2 6.2 0 1 0 16 12" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/><path d="M12.8 7.2h3v-3" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg>Refresh</button>
3326
3724
  </div>
3327
3725
  </header>
3328
3726
  <div class="layout">
3329
3727
  <nav class="side" id="nav" aria-label="Admin sections">
3330
- <button type="button" data-view="overview" aria-current="true">Overview</button>
3331
- <button type="button" data-view="state">State</button>
3332
- <button type="button" data-view="clock">Clock</button>
3333
- <button type="button" data-view="faults">Faults</button>
3334
- <button type="button" data-view="journal">Journal</button>
3335
- <button type="button" data-view="routes">Routes</button>
3728
+ <span class="nav-label">Workspace</span>
3729
+ <button type="button" data-view="overview" aria-current="true"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><rect x="2.5" y="2.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="11.5" y="2.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="2.5" y="11.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="11.5" y="11.5" width="6" height="6" rx="1.5" stroke="currentColor" stroke-width="1.5"/></svg></span>Overview</button>
3730
+ <button type="button" data-view="state"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><ellipse cx="10" cy="5" rx="6.5" ry="2.5" stroke="currentColor" stroke-width="1.5"/><path d="M3.5 5v5c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5V5M3.5 10v5c0 1.4 2.9 2.5 6.5 2.5s6.5-1.1 6.5-2.5v-5" stroke="currentColor" stroke-width="1.5"/></svg></span>State</button>
3731
+ <button type="button" data-view="clock"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><circle cx="10" cy="10" r="7.5" stroke="currentColor" stroke-width="1.5"/><path d="M10 5.8v4.6l3 1.8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg></span>Clock</button>
3732
+ <button type="button" data-view="faults"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="m11.2 2.8-6.5 9h5.1l-1 5.4 6.5-9h-5.1l1-5.4Z" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"/></svg></span>Faults</button>
3733
+ <button type="button" data-view="journal"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="M5 3.5h10a1.5 1.5 0 0 1 1.5 1.5v12l-2.2-1.4-2.2 1.4-2.1-1.4L7.8 17l-2.2-1.4L3.5 17V5A1.5 1.5 0 0 1 5 3.5Z" stroke="currentColor" stroke-width="1.5"/><path d="M6.7 7h6.6M6.7 10h6.6M6.7 13h3.8" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg></span>Journal</button>
3734
+ <button type="button" data-view="routes"><span class="nav-icon" aria-hidden="true"><svg viewBox="0 0 20 20" fill="none"><path d="M6.5 4.5h7a2 2 0 0 1 2 2v7M13 11l2.5 2.5L18 11M13.5 15.5h-7a2 2 0 0 1-2-2v-7M7 9 4.5 6.5 2 9" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></span>Routes</button>
3336
3735
  </nav>
3337
3736
  <main id="views">
3338
- <p class="banner" id="banner" role="alert"></p>
3737
+ <div class="banner" id="banner" role="alert"><span id="banner-message"></span><button id="banner-dismiss" type="button" aria-label="Dismiss error">\xD7</button></div>
3339
3738
  <section class="view" id="view-overview">
3340
- <h2>Overview</h2>
3341
- <p class="lede">Health, clock, and the collections this namespace is holding.</p>
3739
+ <div class="view-head"><div><h2>Overview</h2><p class="lede">Health, clock, and the collections this namespace is holding.</p></div></div>
3342
3740
  <div class="grid" id="overview-cards"></div>
3343
3741
  <h3>Recent requests</h3>
3344
3742
  <div id="overview-requests"></div>
3345
3743
  </section>
3346
3744
  <section class="view" id="view-state" hidden>
3347
- <h2>State</h2>
3348
- <p class="lede">Every collection in this namespace. Declared fields stay visible before any row exists; stored rows add whatever else they contain.</p>
3745
+ <div class="view-head"><div><h2>State</h2><p class="lede">Inspect and edit every collection in this namespace.</p></div></div>
3349
3746
  <div class="split">
3350
3747
  <div id="collections"></div>
3351
3748
  <div>
@@ -3358,8 +3755,7 @@ var renderAdminDocument = (service) => {
3358
3755
  </div>
3359
3756
  </section>
3360
3757
  <section class="view" id="view-clock" hidden>
3361
- <h2>Clock</h2>
3362
- <p class="lede">The clock every timestamp in this mock reads.</p>
3758
+ <div class="view-head"><div><h2>Clock</h2><p class="lede">Control the source of time used by every timestamp in this mock.</p></div></div>
3363
3759
  <div class="card" id="clock-readout"></div>
3364
3760
  <div class="row-actions">
3365
3761
  <button class="btn" type="button" data-advance="60000">+1m</button>
@@ -3378,21 +3774,22 @@ var renderAdminDocument = (service) => {
3378
3774
  </form>
3379
3775
  </section>
3380
3776
  <section class="view" id="view-faults" hidden>
3381
- <h2>Faults</h2>
3382
- <p class="lede">Inject a response, a delay, or a named preset. Rules apply to this namespace.</p>
3777
+ <div class="view-head"><div><h2>Faults</h2><p class="lede">Test unhappy paths with a response, delay, or named preset scoped to this namespace.</p></div></div>
3383
3778
  <form id="fault-form" class="card stack">
3384
- <label class="field">Preset
3385
- <select id="fault-preset"><option value="">Custom rule</option></select>
3386
- </label>
3387
- <label class="field">Status
3388
- <input id="fault-status" inputmode="numeric" placeholder="503">
3389
- </label>
3390
- <label class="field">Path prefix
3391
- <input id="fault-path" placeholder="/v1">
3392
- </label>
3393
- <label class="field">Method
3394
- <input id="fault-method" placeholder="GET">
3395
- </label>
3779
+ <div class="form-grid">
3780
+ <label class="field wide">Preset
3781
+ <select id="fault-preset"><option value="">Custom rule</option></select>
3782
+ </label>
3783
+ <label class="field">Status
3784
+ <input id="fault-status" inputmode="numeric" placeholder="503">
3785
+ </label>
3786
+ <label class="field wide">Path prefix
3787
+ <input id="fault-path" placeholder="/v1">
3788
+ </label>
3789
+ <label class="field">Method
3790
+ <input id="fault-method" placeholder="GET">
3791
+ </label>
3792
+ </div>
3396
3793
  <div class="dialog-actions">
3397
3794
  <button class="btn-primary" type="submit">Add fault</button>
3398
3795
  <button class="btn-danger" id="fault-clear" type="button">Clear all</button>
@@ -3401,26 +3798,31 @@ var renderAdminDocument = (service) => {
3401
3798
  <div id="fault-list"></div>
3402
3799
  </section>
3403
3800
  <section class="view" id="view-journal" hidden>
3404
- <h2>Journal</h2>
3405
- <p class="lede">Requests this namespace has seen. Bodies are not stored.</p>
3406
- <div class="row-actions">
3407
- <button class="btn-danger" id="journal-clear" type="button">Clear journal</button>
3408
- </div>
3801
+ <div class="view-head"><div><h2>Journal</h2><p class="lede">Requests this namespace has seen. Bodies are never stored.</p></div><button class="btn-danger" id="journal-clear" type="button">Clear journal</button></div>
3409
3802
  <div id="journal"></div>
3410
3803
  </section>
3411
3804
  <section class="view" id="view-routes" hidden>
3412
- <h2>Routes</h2>
3413
- <p class="lede">Shared controls, plus any routes this mock adds. Extra routes are how a bespoke workflow shows up beside the default UI.</p>
3805
+ <div class="view-head"><div><h2>Routes</h2><p class="lede">Explore shared controls and service-specific admin endpoints.</p></div></div>
3806
+ <div class="route-tools">
3807
+ <label class="field">Filter routes
3808
+ <input id="route-search" type="search" placeholder="Method, path, or extension" autocomplete="off">
3809
+ </label>
3810
+ <span class="route-count" id="route-count"></span>
3811
+ </div>
3414
3812
  <div id="route-list"></div>
3415
- <form id="route-form" class="card stack">
3813
+ <form id="route-form" class="card stack" style="margin-top: 18px">
3416
3814
  <strong id="route-title">Select a route</strong>
3417
3815
  <label class="field">JSON body
3418
- <textarea id="route-body" placeholder="{ }"></textarea>
3816
+ <div class="json-editor" id="route-editor" hidden>
3817
+ <pre aria-hidden="true"><code id="route-highlight"></code></pre>
3818
+ <textarea id="route-body" placeholder="{ }" spellcheck="false" aria-describedby="route-json-status" disabled></textarea>
3819
+ </div>
3820
+ <span class="editor-meta" hidden><span class="json-status" id="route-json-status">Valid JSON</span><button class="format-json" type="button" data-format="route-body">Format JSON</button></span>
3419
3821
  </label>
3420
3822
  <div class="dialog-actions">
3421
- <button class="btn-primary" type="submit">Send</button>
3823
+ <button class="btn-primary" id="route-send" type="submit" disabled>Send request</button>
3422
3824
  </div>
3423
- <pre id="route-result">Response will show here.</pre>
3825
+ <pre class="json-view" id="route-result"><code>Response will show here.</code></pre>
3424
3826
  </form>
3425
3827
  </section>
3426
3828
  </main>
@@ -3428,12 +3830,16 @@ var renderAdminDocument = (service) => {
3428
3830
  </div>
3429
3831
  <dialog id="editor">
3430
3832
  <form method="dialog" id="editor-form">
3431
- <strong id="editor-title">Record</strong>
3833
+ <div class="dialog-heading"><div><strong id="editor-title">Record</strong><br><span>Edit the ID and JSON value stored in this collection.</span></div></div>
3432
3834
  <label class="field">Id
3433
3835
  <input id="editor-id" required>
3434
3836
  </label>
3435
3837
  <label class="field">JSON value
3436
- <textarea id="editor-value"></textarea>
3838
+ <div class="json-editor" id="record-editor">
3839
+ <pre aria-hidden="true"><code id="editor-highlight"></code></pre>
3840
+ <textarea id="editor-value" spellcheck="false" aria-describedby="editor-json-status"></textarea>
3841
+ </div>
3842
+ <span class="editor-meta"><span class="json-status" id="editor-json-status">Valid JSON</span><button class="format-json" type="button" data-format="editor-value">Format JSON</button></span>
3437
3843
  </label>
3438
3844
  <div class="dialog-actions">
3439
3845
  <button class="btn-danger" id="editor-delete" type="button" value="delete">Delete</button>
@@ -3475,8 +3881,8 @@ var describeExtension = (extension) => {
3475
3881
  ...extension.script !== void 0 ? { script: extension.script } : {}
3476
3882
  };
3477
3883
  };
3478
- var adminUiRoutes = (service, ui) => {
3479
- const shell = () => renderAdminDocument(service);
3884
+ var adminUiRoutes = (service, ui, adminPrefix = ADMIN_PREFIX) => {
3885
+ const shell = () => renderAdminDocument(service, adminPrefix);
3480
3886
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
3481
3887
  return {
3482
3888
  "GET /ui": () => htmlResponse(document3()),
@@ -4167,7 +4573,7 @@ var stateAdminRoutes = (routes) => {
4167
4573
  };
4168
4574
 
4169
4575
  // ../core/dist/version.js
4170
- var PACKAGE_VERSION = true ? "1.7.1" : UNRELEASED_VERSION;
4576
+ var PACKAGE_VERSION = true ? "2.0.0" : UNRELEASED_VERSION;
4171
4577
 
4172
4578
  // ../core/dist/signing.js
4173
4579
  var encoder = new TextEncoder();
@@ -4260,7 +4666,9 @@ var createWebhookHub = (options) => {
4260
4666
  const faults = /* @__PURE__ */ new Map();
4261
4667
  const held = /* @__PURE__ */ new Map();
4262
4668
  const inFlight = /* @__PURE__ */ new Set();
4669
+ const controllers = /* @__PURE__ */ new Map();
4263
4670
  let immediate = Promise.resolve();
4671
+ const snapshots = /* @__PURE__ */ new WeakMap();
4264
4672
  const track = (work) => {
4265
4673
  inFlight.add(work);
4266
4674
  void work.finally(() => inFlight.delete(work));
@@ -4281,6 +4689,7 @@ var createWebhookHub = (options) => {
4281
4689
  responseBody: null
4282
4690
  };
4283
4691
  const controller = new AbortController();
4692
+ controllers.set(delivery.id, controller);
4284
4693
  const timer = scheduleTimer(() => controller.abort(), timeoutMs);
4285
4694
  try {
4286
4695
  const signed = await options.signer({
@@ -4310,6 +4719,7 @@ var createWebhookHub = (options) => {
4310
4719
  } catch (error) {
4311
4720
  record.error = controller.signal.aborted ? `timed out after ${timeoutMs}ms` : error instanceof Error ? error.message : String(error);
4312
4721
  } finally {
4722
+ controllers.delete(delivery.id);
4313
4723
  cancel(timer);
4314
4724
  record.durationMs = now() - started;
4315
4725
  delivery.attempts.push(record);
@@ -4327,6 +4737,8 @@ var createWebhookHub = (options) => {
4327
4737
  if (!payloads.has(delivery.id))
4328
4738
  return;
4329
4739
  await attempt(delivery).then((ok) => {
4740
+ if (!payloads.has(delivery.id))
4741
+ return;
4330
4742
  if (ok)
4331
4743
  delivery.state = "delivered";
4332
4744
  else
@@ -4388,6 +4800,37 @@ var createWebhookHub = (options) => {
4388
4800
  fanOut(message);
4389
4801
  };
4390
4802
  const hub = {
4803
+ pending(namespace) {
4804
+ return inFlight.size + (held.get(namespace)?.length ?? 0) + [...deliveries.values()].filter((d) => d.namespace === namespace && d.state === "pending").length;
4805
+ },
4806
+ snapshot(namespace) {
4807
+ if (hub.pending(namespace) > 0)
4808
+ throw new Error("webhooks are not quiescent");
4809
+ const handle = {};
4810
+ snapshots.set(handle, structuredClone({
4811
+ namespace,
4812
+ endpoints: own.get(namespace) ?? [],
4813
+ messages: messages.filter((m) => m.namespace === namespace),
4814
+ deliveries: [...deliveries].filter(([, d]) => d.namespace === namespace),
4815
+ payloads: [...payloads].filter(([, p]) => p.message.namespace === namespace),
4816
+ faults: faults.get(namespace) ?? []
4817
+ }));
4818
+ return handle;
4819
+ },
4820
+ restore(namespace, handle) {
4821
+ const point = typeof handle === "object" && handle !== null ? snapshots.get(handle) : void 0;
4822
+ if (!point || point.namespace !== namespace || hub.pending(namespace) > 0)
4823
+ throw new Error("invalid webhook restore");
4824
+ hub.clear(namespace);
4825
+ const copied = structuredClone(point);
4826
+ own.set(namespace, copied.endpoints);
4827
+ messages.push(...copied.messages);
4828
+ for (const [id2, delivery] of copied.deliveries)
4829
+ deliveries.set(id2, delivery);
4830
+ for (const [id2, payload] of copied.payloads)
4831
+ payloads.set(id2, payload);
4832
+ faults.set(namespace, copied.faults);
4833
+ },
4391
4834
  publish(input) {
4392
4835
  const contentType = input.contentType ?? (input.form ? "application/x-www-form-urlencoded" : "application/json");
4393
4836
  const body = typeof input.body === "string" ? input.body : input.form ? new URLSearchParams(input.form).toString() : JSON.stringify(input.body);
@@ -4478,6 +4921,7 @@ var createWebhookHub = (options) => {
4478
4921
  for (const [id2, delivery] of deliveries) {
4479
4922
  if (namespace !== void 0 && delivery.namespace !== namespace)
4480
4923
  continue;
4924
+ controllers.get(id2)?.abort();
4481
4925
  const timer = pending.get(id2);
4482
4926
  if (timer !== void 0)
4483
4927
  cancel(timer);
@@ -4502,7 +4946,10 @@ var createWebhookHub = (options) => {
4502
4946
  };
4503
4947
  return hub;
4504
4948
  };
4505
- var json5 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
4949
+ var json5 = (status, body) => new Response(JSON.stringify(body), {
4950
+ status,
4951
+ headers: { "content-type": "application/json; charset=utf-8" }
4952
+ });
4506
4953
  var adminError3 = (status, message) => json5(status, { error: { type: "mockingbird_admin", message } });
4507
4954
  var isRecord5 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4508
4955
  var parseEndpoint = (value) => {
@@ -4610,7 +5057,6 @@ var AT_HEADER = "x-mockingbird-at";
4610
5057
  var CHECKPOINT_HEADER = "x-mockingbird-checkpoint";
4611
5058
  var DEFAULT_NAMESPACE = "default";
4612
5059
  var NAMESPACE_PATTERN = /^[A-Za-z0-9_.-]{1,64}$/;
4613
- var PATH_PREFIX = /^\/ns\/([^/]+)(\/.*)?$/;
4614
5060
  var BRANCH_PATTERN2 = /^[A-Za-z0-9_.-]{1,64}$/;
4615
5061
  var MUTATING_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
4616
5062
  var effects = /* @__PURE__ */ new WeakMap();
@@ -4651,6 +5097,22 @@ var operationMatcher = (document3) => {
4651
5097
  return (request, path) => matchers.find((m) => m.method === request.method && m.pattern.test(path))?.operationId;
4652
5098
  };
4653
5099
  var createRuntime = (options) => {
5100
+ const adminPrefix = resolveAdminPrefix(options.adminPrefix);
5101
+ const internalPaths = Object.entries(options.document?.paths ?? {}).filter(([, item]) => item["x-mockingbird-internal"] === true).map(([path]) => path);
5102
+ for (const path of internalPaths) {
5103
+ if (!path.startsWith(`${ADMIN_PREFIX}/blobs/`))
5104
+ throw new Error(`internal transport ${path} must live under ${ADMIN_PREFIX}/blobs/`);
5105
+ }
5106
+ assertAdminPrefixAvailable(adminPrefix, Object.keys(options.document?.paths ?? {}).filter((path) => !internalPaths.includes(path)));
5107
+ const internalMatch = (path) => {
5108
+ for (const pattern of internalPaths) {
5109
+ const actual = path.split("/");
5110
+ const expected = pattern.split("/");
5111
+ if (actual.length === expected.length && expected.every((part, i) => part.startsWith("{") || part === actual[i]))
5112
+ return pattern;
5113
+ }
5114
+ return void 0;
5115
+ };
4654
5116
  assertAdminUi(options.adminUi);
4655
5117
  const sqlite = bootSqlite(options.sqlite);
4656
5118
  const clock = options.clock ?? createClock();
@@ -4665,6 +5127,20 @@ var createRuntime = (options) => {
4665
5127
  const instances = /* @__PURE__ */ new Map();
4666
5128
  const publicNamespaces = /* @__PURE__ */ new Set();
4667
5129
  const branchRngs = /* @__PURE__ */ new Map();
5130
+ const namespaceClocks = /* @__PURE__ */ new Map();
5131
+ const namespaceForStorage = /* @__PURE__ */ new Map();
5132
+ let isolatedNamespaces = false;
5133
+ const namespaceClock = (name = DEFAULT_NAMESPACE) => {
5134
+ if (!isolatedNamespaces || name === DEFAULT_NAMESPACE)
5135
+ return clock;
5136
+ let found = namespaceClocks.get(name);
5137
+ if (!found) {
5138
+ found = createClock();
5139
+ namespaceClocks.set(name, found);
5140
+ }
5141
+ return found;
5142
+ };
5143
+ const fleetPoints = /* @__PURE__ */ new WeakMap();
4668
5144
  const timelines = /* @__PURE__ */ new Map();
4669
5145
  const branchStorage = /* @__PURE__ */ new Map();
4670
5146
  const captured = /* @__PURE__ */ new Map();
@@ -4678,17 +5154,22 @@ var createRuntime = (options) => {
4678
5154
  if (!NAMESPACE_PATTERN.test(key) || !NAMESPACE_PATTERN.test(publicNamespace)) {
4679
5155
  throw new RangeError(`namespace must match ${NAMESPACE_PATTERN}: ${JSON.stringify(publicNamespace)}`);
4680
5156
  }
5157
+ const createdContextRng = isolatedRng ?? (isolatedNamespaces && key !== DEFAULT_NAMESPACE ? createRng(options.seed ?? 0) : rng);
4681
5158
  const created = options.create({
4682
5159
  namespace: storageNamespace(key),
4683
5160
  publicNamespace,
5161
+ adminPrefix,
4684
5162
  sqlite,
4685
- clock,
4686
- rng: isolatedRng ?? rng
5163
+ clock: namespaceClock(publicNamespace),
5164
+ rng: createdContextRng
4687
5165
  });
4688
5166
  instances.set(key, created);
5167
+ namespaceForStorage.set(key, publicNamespace);
4689
5168
  publicNamespaces.add(publicNamespace);
4690
5169
  if (isolatedRng)
4691
5170
  branchRngs.set(key, isolatedRng);
5171
+ else if (isolatedNamespaces && key !== DEFAULT_NAMESPACE)
5172
+ branchRngs.set(key, createdContextRng);
4692
5173
  return created;
4693
5174
  };
4694
5175
  const instance = (name = DEFAULT_NAMESPACE) => instanceFor(name);
@@ -4706,7 +5187,7 @@ var createRuntime = (options) => {
4706
5187
  captured.set(storage, snapshot2);
4707
5188
  return Object.freeze({
4708
5189
  snapshot: snapshot2,
4709
- clock: Object.freeze(clock.state()),
5190
+ clock: Object.freeze(namespaceClock(namespaceForStorage.get(storage) ?? storage).state()),
4710
5191
  rngState: (branchRngs.get(storage) ?? rng).state()
4711
5192
  });
4712
5193
  };
@@ -4716,7 +5197,7 @@ var createRuntime = (options) => {
4716
5197
  return found;
4717
5198
  instance(name);
4718
5199
  found = new Timeline({
4719
- now: clock.now,
5200
+ now: namespaceClock(name).now,
4720
5201
  ...options.maxCheckpoints !== void 0 ? { maxCheckpoints: options.maxCheckpoints } : {}
4721
5202
  });
4722
5203
  found.commit(capture(name));
@@ -4743,12 +5224,13 @@ var createRuntime = (options) => {
4743
5224
  const point = history2.checkout("main", at);
4744
5225
  restoreNamespace(sqlite, storageNamespace(namespace), point.value.snapshot);
4745
5226
  captured.set(namespace, point.value.snapshot);
4746
- rng.setState(point.value.rngState);
4747
- clock.set(point.value.clock.now);
5227
+ (branchRngs.get(namespace) ?? rng).setState(point.value.rngState);
5228
+ const selectedClock = namespaceClock(namespace);
5229
+ selectedClock.set(point.value.clock.now);
4748
5230
  if (point.value.clock.frozen)
4749
- clock.freeze();
5231
+ selectedClock.freeze();
4750
5232
  else
4751
- clock.unfreeze();
5233
+ selectedClock.unfreeze();
4752
5234
  }
4753
5235
  return namespace;
4754
5236
  }
@@ -4806,11 +5288,12 @@ var createRuntime = (options) => {
4806
5288
  const storage = ensureBranch(namespace, branchName);
4807
5289
  restoreNamespace(sqlite, storageNamespace(storage), point.value.snapshot);
4808
5290
  captured.set(storage, point.value.snapshot);
4809
- clock.set(point.value.clock.now);
5291
+ const selectedClock = namespaceClock(namespace);
5292
+ selectedClock.set(point.value.clock.now);
4810
5293
  if (point.value.clock.frozen)
4811
- clock.freeze();
5294
+ selectedClock.freeze();
4812
5295
  else
4813
- clock.unfreeze();
5296
+ selectedClock.unfreeze();
4814
5297
  (branchRngs.get(storage) ?? rng).setState(point.value.rngState);
4815
5298
  };
4816
5299
  const reset = async (name = DEFAULT_NAMESPACE) => {
@@ -4818,10 +5301,21 @@ var createRuntime = (options) => {
4818
5301
  options.webhooks?.clear();
4819
5302
  for (const each of instances.values())
4820
5303
  await each.reset();
5304
+ for (const each of branchRngs.values())
5305
+ each.reset();
4821
5306
  timelines.clear();
5307
+ for (const storage of branchStorage.values()) {
5308
+ instances.delete(storage);
5309
+ branchRngs.delete(storage);
5310
+ namespaceForStorage.delete(storage);
5311
+ }
4822
5312
  branchStorage.clear();
4823
- branchRngs.clear();
4824
5313
  captured.clear();
5314
+ faults.clear();
5315
+ clock.reset();
5316
+ rng.reset();
5317
+ for (const each of namespaceClocks.values())
5318
+ each.reset();
4825
5319
  return;
4826
5320
  }
4827
5321
  options.webhooks?.clear(name);
@@ -4839,11 +5333,18 @@ var createRuntime = (options) => {
4839
5333
  else
4840
5334
  clearNamespace(sqlite, storageNamespace(storage));
4841
5335
  branchStorage.delete(mapping);
5336
+ instances.delete(storage);
5337
+ namespaceForStorage.delete(storage);
4842
5338
  branchRngs.delete(storage);
4843
5339
  captured.delete(storage);
4844
5340
  }
4845
5341
  timelines.delete(name);
4846
5342
  captured.delete(name);
5343
+ faults.restore(name, { rules: [], rngState: createRng(options.seed ?? 0).state() });
5344
+ namespaceClock(name).reset();
5345
+ (branchRngs.get(name) ?? rng).reset();
5346
+ journal.clear(name);
5347
+ metrics.reset(name);
4847
5348
  };
4848
5349
  const snapshot = (name = DEFAULT_NAMESPACE) => {
4849
5350
  return checkpoint(name, "main").value.snapshot;
@@ -4881,6 +5382,53 @@ var createRuntime = (options) => {
4881
5382
  rng,
4882
5383
  credentials,
4883
5384
  webhooks: options.webhooks,
5385
+ isolateNamespaces() {
5386
+ if (publicNamespaces.size > 1)
5387
+ throw new Error("enable namespace isolation before creating named namespaces");
5388
+ isolatedNamespaces = true;
5389
+ faults.isolateNamespaces();
5390
+ },
5391
+ namespaceClock,
5392
+ namespaceOf(request) {
5393
+ const url = new URL(request.url);
5394
+ const prefixed = matchNamespacePath(url.pathname, adminPrefix);
5395
+ const selected = request.headers.get(NAMESPACE_HEADER) ?? (prefixed ? decodeURIComponent(prefixed[1]) : void 0);
5396
+ const path = prefixed ? prefixed[2] ?? "/" : url.pathname;
5397
+ if (isAdminPath(path, adminPrefix))
5398
+ return url.searchParams.get("namespace") ?? selected ?? DEFAULT_NAMESPACE;
5399
+ if (selected !== void 0)
5400
+ return selected;
5401
+ const credential = options.credential?.(request);
5402
+ return (credential !== void 0 ? credentials.get(credential) : void 0) ?? DEFAULT_NAMESPACE;
5403
+ },
5404
+ fleetSnapshot(namespace) {
5405
+ instance(namespace);
5406
+ const handle = {};
5407
+ fleetPoints.set(handle, {
5408
+ namespace,
5409
+ state: capture(namespace),
5410
+ faults: faults.snapshot(namespace),
5411
+ webhooks: options.webhooks?.snapshot(namespace)
5412
+ });
5413
+ return handle;
5414
+ },
5415
+ fleetRestore(handle, namespace) {
5416
+ const point = typeof handle === "object" && handle !== null ? fleetPoints.get(handle) : void 0;
5417
+ if (!point || point.namespace !== namespace)
5418
+ throw new Error("invalid fleet checkpoint");
5419
+ restoreNamespace(sqlite, storageNamespace(namespace), point.state.snapshot);
5420
+ captured.set(namespace, point.state.snapshot);
5421
+ const selectedClock = namespaceClock(namespace);
5422
+ selectedClock.freeze();
5423
+ selectedClock.set(point.state.clock.now);
5424
+ if (!point.state.clock.frozen)
5425
+ selectedClock.unfreeze();
5426
+ (branchRngs.get(namespace) ?? rng).setState(point.state.rngState);
5427
+ faults.restore(namespace, point.faults);
5428
+ if (point.webhooks !== void 0)
5429
+ options.webhooks?.restore(namespace, point.webhooks);
5430
+ timelines.delete(namespace);
5431
+ },
4884
5432
  applyPreset: (name, namespace = DEFAULT_NAMESPACE, overrides = {}) => {
4885
5433
  const preset = options.presets?.[name];
4886
5434
  if (!preset)
@@ -4912,7 +5460,7 @@ var createRuntime = (options) => {
4912
5460
  state: (namespace = DEFAULT_NAMESPACE) => inspectState(stateScope(namespace)),
4913
5461
  fetch: async (incoming) => {
4914
5462
  let request = incoming;
4915
- const prefixed = PATH_PREFIX.exec(new URL(request.url).pathname);
5463
+ const prefixed = matchNamespacePath(new URL(request.url).pathname, adminPrefix);
4916
5464
  if (prefixed) {
4917
5465
  const url2 = new URL(request.url);
4918
5466
  url2.pathname = prefixed[2] ?? "/";
@@ -4928,7 +5476,15 @@ var createRuntime = (options) => {
4928
5476
  signal: request.signal
4929
5477
  });
4930
5478
  }
4931
- let namespace = control.namespaceOf(request);
5479
+ const internalUrl = new URL(request.url);
5480
+ const internalPath = isAdminPath(internalUrl.pathname, adminPrefix) ? `${ADMIN_PREFIX}${internalUrl.pathname.slice(adminPrefix.length)}` : "";
5481
+ const internal = internalMatch(internalPath);
5482
+ const obsoleteInternalPath = adminPrefix !== ADMIN_PREFIX && internalMatch(internalUrl.pathname) && !internal;
5483
+ if (internal) {
5484
+ internalUrl.pathname = internalPath;
5485
+ request = new Request(internalUrl, request);
5486
+ }
5487
+ let namespace = internal ? internalUrl.searchParams.get("namespace") ?? control.namespaceOf(request) : control.namespaceOf(request);
4932
5488
  if (!request.headers.has(NAMESPACE_HEADER) && options.credential) {
4933
5489
  const credential = options.credential(request);
4934
5490
  const mapped = credential !== void 0 ? credentials.get(credential) : void 0;
@@ -4948,7 +5504,9 @@ var createRuntime = (options) => {
4948
5504
  return copy;
4949
5505
  }
4950
5506
  };
4951
- const handled = await control.handle(request);
5507
+ if (obsoleteInternalPath)
5508
+ return stamp(adminFail(404, "internal transport is only available under adminPrefix"));
5509
+ const handled = internal ? void 0 : await control.handle(request);
4952
5510
  if (handled)
4953
5511
  return stamp(handled);
4954
5512
  const started = monotonicNow();
@@ -4989,7 +5547,7 @@ var createRuntime = (options) => {
4989
5547
  type: "mockingbird_admin",
4990
5548
  message: `${NAMESPACE_HEADER} must match ${NAMESPACE_PATTERN}`
4991
5549
  }
4992
- }), { status: 400, headers: { "content-type": "application/json" } }));
5550
+ }), { status: 400, headers: { "content-type": "application/json; charset=utf-8" } }));
4993
5551
  }
4994
5552
  if (!BRANCH_PATTERN2.test(selectedBranch)) {
4995
5553
  log(400);
@@ -5056,6 +5614,7 @@ var createRuntime = (options) => {
5056
5614
  startedAt: wallNow(),
5057
5615
  wallNow,
5058
5616
  clock,
5617
+ namespaceClock,
5059
5618
  faults,
5060
5619
  metrics,
5061
5620
  journal,
@@ -5105,15 +5664,16 @@ var createRuntime = (options) => {
5105
5664
  ...options.admin?.(runtime) ?? {},
5106
5665
  // Shell routes win a colliding key. Fault presets are one of them: the admin page
5107
5666
  // maps `presets`, and a service route must not replace that list with a record.
5108
- ...options.presets ? presetRoutes(options.presets, runtime) : {},
5667
+ ...options.presets ? presetRoutes(options.presets, runtime, adminPrefix) : {},
5109
5668
  ...stateAdminRoutes({
5110
5669
  open: stateScope,
5111
5670
  afterWrite: (namespace) => {
5112
5671
  checkpoint(namespace, "main");
5113
5672
  }
5114
5673
  }),
5115
- ...adminUiRoutes(options.name, options.adminUi)
5674
+ ...adminUiRoutes(options.name, options.adminUi, adminPrefix)
5116
5675
  },
5676
+ adminPrefix,
5117
5677
  adminKey: options.adminKey
5118
5678
  });
5119
5679
  return defineMock(runtime);
@@ -5127,7 +5687,10 @@ var mutableResponse = (response) => {
5127
5687
  return new Response(response.body, response);
5128
5688
  }
5129
5689
  };
5130
- var adminJson = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
5690
+ var adminJson = (status, body) => new Response(JSON.stringify(body), {
5691
+ status,
5692
+ headers: { "content-type": "application/json; charset=utf-8" }
5693
+ });
5131
5694
  var adminFail = (status, message) => adminJson(status, { error: { type: "mockingbird_admin", message } });
5132
5695
  var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
5133
5696
  var credentialRoutes = (registry) => ({
@@ -5179,7 +5742,7 @@ var credentialRoutes = (registry) => ({
5179
5742
  return adminJson(200, { status: "ok" });
5180
5743
  }
5181
5744
  });
5182
- var presetRoutes = (presets, runtime) => ({
5745
+ var presetRoutes = (presets, runtime, adminPrefix) => ({
5183
5746
  "GET /faults/presets": () => {
5184
5747
  const body = {
5185
5748
  presets: Object.entries(presets).map(([name, preset]) => ({ name, ...preset }))
@@ -5189,7 +5752,7 @@ var presetRoutes = (presets, runtime) => ({
5189
5752
  "POST /faults/presets/:name": ({ params, body, namespace }) => {
5190
5753
  const name = params.name;
5191
5754
  if (!presets[name])
5192
- return adminFail(404, `no fault preset ${name}; GET /__admin/faults/presets`);
5755
+ return adminFail(404, `no fault preset ${name}; GET ${adminPrefix}/faults/presets`);
5193
5756
  const overrides = isObject(body) ? body : {};
5194
5757
  return adminJson(201, { preset: name, rules: runtime.applyPreset(name, namespace, overrides) });
5195
5758
  }
@@ -5618,6 +6181,7 @@ var createRuntime2 = (options = {}) => {
5618
6181
  ...options.sqlite ? { sqlite: options.sqlite } : {},
5619
6182
  ...options.clock ? { clock: options.clock } : {},
5620
6183
  ...options.seed !== void 0 ? { seed: options.seed } : {},
6184
+ ...options.adminPrefix !== void 0 ? { adminPrefix: options.adminPrefix } : {},
5621
6185
  ...options.adminKey !== void 0 ? { adminKey: options.adminKey } : {},
5622
6186
  ...options.onLog ? { onLog: options.onLog } : {},
5623
6187
  credential: customerIoCredential,
@@ -6185,6 +6749,9 @@ var CustomerIoAPI = class {
6185
6749
  };
6186
6750
 
6187
6751
  export {
6752
+ createClock,
6753
+ resolveAdminPrefix,
6754
+ parseDuration,
6188
6755
  document2 as document,
6189
6756
  operationIds,
6190
6757
  supportedOperationIds,
@@ -6201,4 +6768,4 @@ export {
6201
6768
  customerIoCredential,
6202
6769
  CustomerIoAPI
6203
6770
  };
6204
- //# sourceMappingURL=chunk-OCBE22Z7.js.map
6771
+ //# sourceMappingURL=chunk-BOZCY34D.js.map