@crvouga/mockingbird-service-oauth 1.9.1 → 1.10.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog — @crvouga/mockingbird-service-oauth
2
2
 
3
+ ## 1.10.0 (2026-10-01)
4
+
5
+ ### Features
6
+
7
+ - record SQL timelines and serve the admin explorer ([8ced17a](https://github.com/crvouga/mockingbird/commit/8ced17ac398e386ef4e9d7e01fc7744c34b95d07))
8
+
9
+ ### Dependencies
10
+
11
+ - `@crvouga/mockingbird-service-sqlite`
12
+
3
13
  ## 1.9.1 (2026-09-30)
4
14
 
5
15
  ### Fixes and improvements
@@ -1447,6 +1447,167 @@ function faultPresetList(value) {
1447
1447
  })
1448
1448
  };
1449
1449
  }
1450
+ function mountSqlExplorer(root, api) {
1451
+ const cell = (value) => {
1452
+ if (value === null || value === void 0)
1453
+ return "";
1454
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1455
+ return String(value);
1456
+ }
1457
+ return JSON.stringify(value) ?? "";
1458
+ };
1459
+ root.replaceChildren();
1460
+ const layout = document.createElement("div");
1461
+ layout.className = "sql-layout";
1462
+ const tables = document.createElement("div");
1463
+ tables.className = "sql-tables";
1464
+ const stack = document.createElement("div");
1465
+ stack.className = "stack";
1466
+ const banner = document.createElement("p");
1467
+ banner.className = "banner";
1468
+ const grid = document.createElement("div");
1469
+ const input = document.createElement("textarea");
1470
+ input.className = "sql-input";
1471
+ input.spellcheck = false;
1472
+ input.placeholder = "SELECT * FROM ...";
1473
+ const actions = document.createElement("div");
1474
+ actions.className = "row-actions";
1475
+ const run = document.createElement("button");
1476
+ run.type = "button";
1477
+ run.textContent = "Run";
1478
+ actions.append(run);
1479
+ const result = document.createElement("pre");
1480
+ stack.append(banner, grid, input, actions, result);
1481
+ layout.append(tables, stack);
1482
+ root.append(layout);
1483
+ const showError = (error) => {
1484
+ banner.textContent = error instanceof Error ? error.message : String(error);
1485
+ banner.classList.add("show");
1486
+ };
1487
+ const clearError = () => {
1488
+ banner.textContent = "";
1489
+ banner.classList.remove("show");
1490
+ };
1491
+ const renderGrid = (columns, rows) => {
1492
+ grid.replaceChildren();
1493
+ if (columns.length === 0) {
1494
+ const empty = document.createElement("p");
1495
+ empty.className = "empty";
1496
+ empty.textContent = "No rows.";
1497
+ grid.append(empty);
1498
+ return;
1499
+ }
1500
+ const table = document.createElement("table");
1501
+ const head = document.createElement("thead");
1502
+ const headRow = document.createElement("tr");
1503
+ for (const column of columns) {
1504
+ const th = document.createElement("th");
1505
+ th.textContent = column;
1506
+ headRow.append(th);
1507
+ }
1508
+ head.append(headRow);
1509
+ const body = document.createElement("tbody");
1510
+ for (const row of rows) {
1511
+ const tr = document.createElement("tr");
1512
+ for (const column of columns) {
1513
+ const td = document.createElement("td");
1514
+ td.dataset.label = column;
1515
+ td.textContent = cell(row[column]);
1516
+ tr.append(td);
1517
+ }
1518
+ body.append(tr);
1519
+ }
1520
+ table.append(head, body);
1521
+ grid.append(table);
1522
+ };
1523
+ const rowsOf = (value) => {
1524
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1525
+ return [];
1526
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1527
+ };
1528
+ const columnsOf = (value, rows) => {
1529
+ if (isRecord2(value) && Array.isArray(value.columns)) {
1530
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
1531
+ if (named.length > 0)
1532
+ return named;
1533
+ }
1534
+ const first = rows[0];
1535
+ return first === void 0 ? [] : Object.keys(first);
1536
+ };
1537
+ let selected = "";
1538
+ const loadPage = async (schema, name) => {
1539
+ selected = `${schema}.${name}`;
1540
+ const page2 = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
1541
+ const rows = rowsOf(page2);
1542
+ renderGrid(columnsOf(page2, rows), rows);
1543
+ const total = isRecord2(page2) && typeof page2.total === "number" ? page2.total : rows.length;
1544
+ result.textContent = `${selected} \xB7 ${total} rows`;
1545
+ for (const button of tables.querySelectorAll("button")) {
1546
+ if (!(button instanceof HTMLButtonElement))
1547
+ continue;
1548
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
1549
+ }
1550
+ };
1551
+ const loadTables = async () => {
1552
+ const payload = await api.get("/sql/tables");
1553
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
1554
+ tables.replaceChildren();
1555
+ if (listed.length === 0) {
1556
+ const empty = document.createElement("p");
1557
+ empty.className = "empty";
1558
+ empty.textContent = "No tables.";
1559
+ tables.append(empty);
1560
+ return;
1561
+ }
1562
+ for (const item of listed) {
1563
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
1564
+ continue;
1565
+ const button = document.createElement("button");
1566
+ button.type = "button";
1567
+ button.dataset.schema = item.schema;
1568
+ button.dataset.table = item.name;
1569
+ button.textContent = `${item.schema}.${item.name}`;
1570
+ tables.append(button);
1571
+ }
1572
+ };
1573
+ tables.addEventListener("click", (event) => {
1574
+ const target = event.target;
1575
+ if (!(target instanceof Element))
1576
+ return;
1577
+ const button = target.closest("button");
1578
+ if (!(button instanceof HTMLButtonElement))
1579
+ return;
1580
+ const schema = button.dataset.schema;
1581
+ const name = button.dataset.table;
1582
+ if (schema === void 0 || name === void 0)
1583
+ return;
1584
+ clearError();
1585
+ loadPage(schema, name).catch(showError);
1586
+ });
1587
+ run.addEventListener("click", () => {
1588
+ const sql = input.value.trim();
1589
+ if (sql === "") {
1590
+ showError(new Error("Enter a statement"));
1591
+ return;
1592
+ }
1593
+ clearError();
1594
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
1595
+ const rows = rowsOf(payload);
1596
+ renderGrid(columnsOf(payload, rows), rows);
1597
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
1598
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
1599
+ result.textContent = `${count} rows${truncated}`;
1600
+ }).catch(showError);
1601
+ });
1602
+ const namespace = document.getElementById("namespace");
1603
+ if (namespace) {
1604
+ namespace.addEventListener("change", () => {
1605
+ clearError();
1606
+ loadTables().catch(showError);
1607
+ });
1608
+ }
1609
+ loadTables().catch(showError);
1610
+ }
1450
1611
  function bootAdmin(config) {
1451
1612
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1452
1613
  const sources = ["declared", "inferred", "mixed"];
@@ -2123,6 +2284,22 @@ function bootAdmin(config) {
2123
2284
  panel.script = value.script;
2124
2285
  return panel;
2125
2286
  };
2287
+ const decodeExtension = (value) => {
2288
+ if (!isRecord2(value))
2289
+ return void 0;
2290
+ if (value.kind === "sql") {
2291
+ return {
2292
+ kind: "sql",
2293
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2294
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2295
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2296
+ };
2297
+ }
2298
+ if (value.kind !== "panel")
2299
+ return void 0;
2300
+ const panel = decodePanel(value);
2301
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2302
+ };
2126
2303
  const mountPanels = (panels) => {
2127
2304
  const nav = el("nav", HTMLElement);
2128
2305
  const views = el("views", HTMLElement);
@@ -2176,10 +2353,48 @@ function bootAdmin(config) {
2176
2353
  return decoded === void 0 ? [] : [decoded];
2177
2354
  });
2178
2355
  mountPanels(panels);
2356
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2357
+ const decoded = decodeExtension(extension);
2358
+ return decoded === void 0 ? [] : [decoded];
2359
+ });
2360
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2361
+ mountPanels(extensionPanels);
2362
+ for (const extension of extensions) {
2363
+ if (extension.kind !== "sql")
2364
+ continue;
2365
+ const nav = el("nav", HTMLElement);
2366
+ const views = el("views", HTMLElement);
2367
+ const button = document.createElement("button");
2368
+ button.type = "button";
2369
+ button.dataset.view = extension.id;
2370
+ button.textContent = extension.title;
2371
+ nav.append(button);
2372
+ const section = document.createElement("section");
2373
+ section.className = "view";
2374
+ section.id = `view-${extension.id}`;
2375
+ section.hidden = true;
2376
+ const title = document.createElement("h2");
2377
+ title.textContent = extension.title;
2378
+ const lede = document.createElement("p");
2379
+ lede.className = "lede";
2380
+ lede.textContent = extension.description;
2381
+ const body = document.createElement("div");
2382
+ body.className = "panel-body";
2383
+ section.append(title, lede, body);
2384
+ views.append(section);
2385
+ mountSqlExplorer(body, panelApi);
2386
+ }
2179
2387
  return refresh();
2180
2388
  }).catch(showError);
2181
2389
  }
2182
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2390
+ var clientPrelude = [
2391
+ isRecord2,
2392
+ mountAdminBrand,
2393
+ startAdminBrand,
2394
+ faultPresetList,
2395
+ mountSqlExplorer,
2396
+ bootAdmin
2397
+ ].map((fn) => fn.toString()).join("\n");
2183
2398
  var adminClientSource = (config) => {
2184
2399
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2185
2400
  const entry = bootAdmin.name;
@@ -2229,19 +2444,33 @@ var STANDARD_ADMIN_ROUTES = [
2229
2444
  "GET /ui/manifest"
2230
2445
  ];
2231
2446
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2447
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2448
+ var checkPanel = (panel, seen, label) => {
2449
+ if (!PANEL_ID.test(panel.id)) {
2450
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2451
+ }
2452
+ if (RESERVED_VIEWS.has(panel.id)) {
2453
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2454
+ }
2455
+ if (seen.has(panel.id))
2456
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2457
+ seen.add(panel.id);
2458
+ if (panel.title.trim() === "")
2459
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2460
+ };
2232
2461
  var assertAdminUi = (ui) => {
2233
- if (!ui?.panels)
2462
+ if (!ui)
2234
2463
  return;
2235
2464
  const seen = /* @__PURE__ */ new Set();
2236
- for (const panel of ui.panels) {
2237
- if (!PANEL_ID.test(panel.id)) {
2238
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2465
+ for (const panel of ui.panels ?? [])
2466
+ checkPanel(panel, seen, "admin panel");
2467
+ for (const extension of ui.extensions ?? []) {
2468
+ if (extension.kind === "panel") {
2469
+ checkPanel(extension, seen, "admin extension");
2470
+ continue;
2239
2471
  }
2240
- if (seen.has(panel.id))
2241
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2242
- seen.add(panel.id);
2243
- if (panel.title.trim() === "")
2244
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2472
+ const id = extension.id ?? "sql";
2473
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2245
2474
  }
2246
2475
  };
2247
2476
 
@@ -2475,6 +2704,12 @@ var renderAdminDocument = (service) => {
2475
2704
  border-radius: 999px; padding: 4px 8px;
2476
2705
  }
2477
2706
  .chip i { color: var(--faint); font-style: normal; }
2707
+ .sql-layout {
2708
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
2709
+ }
2710
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
2711
+ .sql-tables button { text-align: left; }
2712
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2478
2713
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2479
2714
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2480
2715
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -2538,7 +2773,7 @@ var renderAdminDocument = (service) => {
2538
2773
  padding: 8px;
2539
2774
  }
2540
2775
  nav.side button { white-space: nowrap; flex: none; }
2541
- .split { grid-template-columns: minmax(0, 1fr); }
2776
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
2542
2777
  main { padding: 14px; }
2543
2778
  table, thead, tbody, tr, th, td { display: block; }
2544
2779
  thead { display: none; }
@@ -2709,6 +2944,24 @@ var json2 = (body) => new Response(JSON.stringify(body), {
2709
2944
  status: 200,
2710
2945
  headers: { "content-type": "application/json; charset=utf-8" }
2711
2946
  });
2947
+ var describeExtension = (extension) => {
2948
+ if (extension.kind === "sql") {
2949
+ return {
2950
+ kind: "sql",
2951
+ id: extension.id ?? "sql",
2952
+ title: extension.title ?? "SQL",
2953
+ ...extension.description !== void 0 ? { description: extension.description } : {}
2954
+ };
2955
+ }
2956
+ return {
2957
+ kind: "panel",
2958
+ id: extension.id,
2959
+ title: extension.title,
2960
+ ...extension.description !== void 0 ? { description: extension.description } : {},
2961
+ html: extension.html,
2962
+ ...extension.script !== void 0 ? { script: extension.script } : {}
2963
+ };
2964
+ };
2712
2965
  var adminUiRoutes = (service, ui) => {
2713
2966
  const shell = () => renderAdminDocument(service);
2714
2967
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -2723,7 +2976,8 @@ var adminUiRoutes = (service, ui) => {
2723
2976
  ...panel.description !== void 0 ? { description: panel.description } : {},
2724
2977
  html: panel.html,
2725
2978
  ...panel.script !== void 0 ? { script: panel.script } : {}
2726
- }))
2979
+ })),
2980
+ extensions: (ui?.extensions ?? []).map(describeExtension)
2727
2981
  })
2728
2982
  };
2729
2983
  };
@@ -3630,7 +3884,7 @@ var stateAdminRoutes = (routes) => {
3630
3884
  };
3631
3885
 
3632
3886
  // ../core/dist/version.js
3633
- var PACKAGE_VERSION = true ? "1.9.1" : UNRELEASED_VERSION;
3887
+ var PACKAGE_VERSION = true ? "1.10.0" : UNRELEASED_VERSION;
3634
3888
 
3635
3889
  // ../core/dist/webhooks.js
3636
3890
  var json4 = (status, body) => new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json" } });
@@ -6243,4 +6497,4 @@ export {
6243
6497
  createMultiRuntime,
6244
6498
  OAuthAPI
6245
6499
  };
6246
- //# sourceMappingURL=chunk-XQNANV2C.js.map
6500
+ //# sourceMappingURL=chunk-23KIY5RO.js.map