@crvouga/mockingbird-service-twilio 1.6.1 → 1.7.1

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,17 @@
1
1
  # Changelog — @crvouga/mockingbird-service-twilio
2
2
 
3
+ ## 1.7.1 (2026-10-01)
4
+
5
+ ### Fixes and improvements
6
+
7
+ - freeze clock before setting time ([a054a1d](https://github.com/crvouga/mockingbird/commit/a054a1defad62539d719b1d31c15107afea623bd))
8
+
9
+ ## 1.7.0 (2026-09-30)
10
+
11
+ ### Features
12
+
13
+ - record SQL timelines and serve the admin explorer ([8ced17a](https://github.com/crvouga/mockingbird/commit/8ced17ac398e386ef4e9d7e01fc7744c34b95d07))
14
+
3
15
  ## 1.6.1 (2026-09-30)
4
16
 
5
17
  ### Fixes and improvements
@@ -189,6 +189,8 @@ var createControlPlane = (context) => {
189
189
  return adminError(400, "expected a JSON object");
190
190
  if (body.reset === true)
191
191
  context.clock.reset();
192
+ if (body.freeze === true)
193
+ context.clock.freeze();
192
194
  if (body.set !== void 0) {
193
195
  const instant = parseInstant(body.set);
194
196
  if (instant === void 0)
@@ -201,8 +203,6 @@ var createControlPlane = (context) => {
201
203
  return adminError(400, 'advance: expected ms or "15m"-style');
202
204
  context.clock.advance(delta);
203
205
  }
204
- if (body.freeze === true)
205
- context.clock.freeze();
206
206
  if (body.freeze === false)
207
207
  context.clock.unfreeze();
208
208
  return json(200, context.clock.state());
@@ -1752,6 +1752,167 @@ function faultPresetList(value) {
1752
1752
  })
1753
1753
  };
1754
1754
  }
1755
+ function mountSqlExplorer(root, api) {
1756
+ const cell = (value) => {
1757
+ if (value === null || value === void 0)
1758
+ return "";
1759
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1760
+ return String(value);
1761
+ }
1762
+ return JSON.stringify(value) ?? "";
1763
+ };
1764
+ root.replaceChildren();
1765
+ const layout = document.createElement("div");
1766
+ layout.className = "sql-layout";
1767
+ const tables = document.createElement("div");
1768
+ tables.className = "sql-tables";
1769
+ const stack = document.createElement("div");
1770
+ stack.className = "stack";
1771
+ const banner = document.createElement("p");
1772
+ banner.className = "banner";
1773
+ const grid = document.createElement("div");
1774
+ const input = document.createElement("textarea");
1775
+ input.className = "sql-input";
1776
+ input.spellcheck = false;
1777
+ input.placeholder = "SELECT * FROM ...";
1778
+ const actions = document.createElement("div");
1779
+ actions.className = "row-actions";
1780
+ const run = document.createElement("button");
1781
+ run.type = "button";
1782
+ run.textContent = "Run";
1783
+ actions.append(run);
1784
+ const result = document.createElement("pre");
1785
+ stack.append(banner, grid, input, actions, result);
1786
+ layout.append(tables, stack);
1787
+ root.append(layout);
1788
+ const showError = (error) => {
1789
+ banner.textContent = error instanceof Error ? error.message : String(error);
1790
+ banner.classList.add("show");
1791
+ };
1792
+ const clearError = () => {
1793
+ banner.textContent = "";
1794
+ banner.classList.remove("show");
1795
+ };
1796
+ const renderGrid = (columns, rows) => {
1797
+ grid.replaceChildren();
1798
+ if (columns.length === 0) {
1799
+ const empty = document.createElement("p");
1800
+ empty.className = "empty";
1801
+ empty.textContent = "No rows.";
1802
+ grid.append(empty);
1803
+ return;
1804
+ }
1805
+ const table = document.createElement("table");
1806
+ const head = document.createElement("thead");
1807
+ const headRow = document.createElement("tr");
1808
+ for (const column of columns) {
1809
+ const th = document.createElement("th");
1810
+ th.textContent = column;
1811
+ headRow.append(th);
1812
+ }
1813
+ head.append(headRow);
1814
+ const body = document.createElement("tbody");
1815
+ for (const row of rows) {
1816
+ const tr = document.createElement("tr");
1817
+ for (const column of columns) {
1818
+ const td = document.createElement("td");
1819
+ td.dataset.label = column;
1820
+ td.textContent = cell(row[column]);
1821
+ tr.append(td);
1822
+ }
1823
+ body.append(tr);
1824
+ }
1825
+ table.append(head, body);
1826
+ grid.append(table);
1827
+ };
1828
+ const rowsOf = (value) => {
1829
+ if (!isRecord2(value) || !Array.isArray(value.rows))
1830
+ return [];
1831
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
1832
+ };
1833
+ const columnsOf = (value, rows) => {
1834
+ if (isRecord2(value) && Array.isArray(value.columns)) {
1835
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
1836
+ if (named.length > 0)
1837
+ return named;
1838
+ }
1839
+ const first = rows[0];
1840
+ return first === void 0 ? [] : Object.keys(first);
1841
+ };
1842
+ let selected = "";
1843
+ const loadPage = async (schema, name) => {
1844
+ selected = `${schema}.${name}`;
1845
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
1846
+ const rows = rowsOf(page);
1847
+ renderGrid(columnsOf(page, rows), rows);
1848
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
1849
+ result.textContent = `${selected} \xB7 ${total} rows`;
1850
+ for (const button of tables.querySelectorAll("button")) {
1851
+ if (!(button instanceof HTMLButtonElement))
1852
+ continue;
1853
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
1854
+ }
1855
+ };
1856
+ const loadTables = async () => {
1857
+ const payload = await api.get("/sql/tables");
1858
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
1859
+ tables.replaceChildren();
1860
+ if (listed.length === 0) {
1861
+ const empty = document.createElement("p");
1862
+ empty.className = "empty";
1863
+ empty.textContent = "No tables.";
1864
+ tables.append(empty);
1865
+ return;
1866
+ }
1867
+ for (const item of listed) {
1868
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
1869
+ continue;
1870
+ const button = document.createElement("button");
1871
+ button.type = "button";
1872
+ button.dataset.schema = item.schema;
1873
+ button.dataset.table = item.name;
1874
+ button.textContent = `${item.schema}.${item.name}`;
1875
+ tables.append(button);
1876
+ }
1877
+ };
1878
+ tables.addEventListener("click", (event) => {
1879
+ const target = event.target;
1880
+ if (!(target instanceof Element))
1881
+ return;
1882
+ const button = target.closest("button");
1883
+ if (!(button instanceof HTMLButtonElement))
1884
+ return;
1885
+ const schema = button.dataset.schema;
1886
+ const name = button.dataset.table;
1887
+ if (schema === void 0 || name === void 0)
1888
+ return;
1889
+ clearError();
1890
+ loadPage(schema, name).catch(showError);
1891
+ });
1892
+ run.addEventListener("click", () => {
1893
+ const sql = input.value.trim();
1894
+ if (sql === "") {
1895
+ showError(new Error("Enter a statement"));
1896
+ return;
1897
+ }
1898
+ clearError();
1899
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
1900
+ const rows = rowsOf(payload);
1901
+ renderGrid(columnsOf(payload, rows), rows);
1902
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
1903
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
1904
+ result.textContent = `${count} rows${truncated}`;
1905
+ }).catch(showError);
1906
+ });
1907
+ const namespace = document.getElementById("namespace");
1908
+ if (namespace) {
1909
+ namespace.addEventListener("change", () => {
1910
+ clearError();
1911
+ loadTables().catch(showError);
1912
+ });
1913
+ }
1914
+ loadTables().catch(showError);
1915
+ }
1755
1916
  function bootAdmin(config) {
1756
1917
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1757
1918
  const sources = ["declared", "inferred", "mixed"];
@@ -2428,6 +2589,22 @@ function bootAdmin(config) {
2428
2589
  panel.script = value.script;
2429
2590
  return panel;
2430
2591
  };
2592
+ const decodeExtension = (value) => {
2593
+ if (!isRecord2(value))
2594
+ return void 0;
2595
+ if (value.kind === "sql") {
2596
+ return {
2597
+ kind: "sql",
2598
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2599
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2600
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2601
+ };
2602
+ }
2603
+ if (value.kind !== "panel")
2604
+ return void 0;
2605
+ const panel = decodePanel(value);
2606
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2607
+ };
2431
2608
  const mountPanels = (panels) => {
2432
2609
  const nav = el("nav", HTMLElement);
2433
2610
  const views = el("views", HTMLElement);
@@ -2481,10 +2658,48 @@ function bootAdmin(config) {
2481
2658
  return decoded === void 0 ? [] : [decoded];
2482
2659
  });
2483
2660
  mountPanels(panels);
2661
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2662
+ const decoded = decodeExtension(extension);
2663
+ return decoded === void 0 ? [] : [decoded];
2664
+ });
2665
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2666
+ mountPanels(extensionPanels);
2667
+ for (const extension of extensions) {
2668
+ if (extension.kind !== "sql")
2669
+ continue;
2670
+ const nav = el("nav", HTMLElement);
2671
+ const views = el("views", HTMLElement);
2672
+ const button = document.createElement("button");
2673
+ button.type = "button";
2674
+ button.dataset.view = extension.id;
2675
+ button.textContent = extension.title;
2676
+ nav.append(button);
2677
+ const section = document.createElement("section");
2678
+ section.className = "view";
2679
+ section.id = `view-${extension.id}`;
2680
+ section.hidden = true;
2681
+ const title = document.createElement("h2");
2682
+ title.textContent = extension.title;
2683
+ const lede = document.createElement("p");
2684
+ lede.className = "lede";
2685
+ lede.textContent = extension.description;
2686
+ const body = document.createElement("div");
2687
+ body.className = "panel-body";
2688
+ section.append(title, lede, body);
2689
+ views.append(section);
2690
+ mountSqlExplorer(body, panelApi);
2691
+ }
2484
2692
  return refresh();
2485
2693
  }).catch(showError);
2486
2694
  }
2487
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2695
+ var clientPrelude = [
2696
+ isRecord2,
2697
+ mountAdminBrand,
2698
+ startAdminBrand,
2699
+ faultPresetList,
2700
+ mountSqlExplorer,
2701
+ bootAdmin
2702
+ ].map((fn) => fn.toString()).join("\n");
2488
2703
  var adminClientSource = (config) => {
2489
2704
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2490
2705
  const entry = bootAdmin.name;
@@ -2534,19 +2749,33 @@ var STANDARD_ADMIN_ROUTES = [
2534
2749
  "GET /ui/manifest"
2535
2750
  ];
2536
2751
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2752
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2753
+ var checkPanel = (panel, seen, label) => {
2754
+ if (!PANEL_ID.test(panel.id)) {
2755
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2756
+ }
2757
+ if (RESERVED_VIEWS.has(panel.id)) {
2758
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2759
+ }
2760
+ if (seen.has(panel.id))
2761
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2762
+ seen.add(panel.id);
2763
+ if (panel.title.trim() === "")
2764
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2765
+ };
2537
2766
  var assertAdminUi = (ui) => {
2538
- if (!ui?.panels)
2767
+ if (!ui)
2539
2768
  return;
2540
2769
  const seen = /* @__PURE__ */ new Set();
2541
- for (const panel of ui.panels) {
2542
- if (!PANEL_ID.test(panel.id)) {
2543
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2770
+ for (const panel of ui.panels ?? [])
2771
+ checkPanel(panel, seen, "admin panel");
2772
+ for (const extension of ui.extensions ?? []) {
2773
+ if (extension.kind === "panel") {
2774
+ checkPanel(extension, seen, "admin extension");
2775
+ continue;
2544
2776
  }
2545
- if (seen.has(panel.id))
2546
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2547
- seen.add(panel.id);
2548
- if (panel.title.trim() === "")
2549
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2777
+ const id = extension.id ?? "sql";
2778
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2550
2779
  }
2551
2780
  };
2552
2781
 
@@ -2780,6 +3009,12 @@ var renderAdminDocument = (service) => {
2780
3009
  border-radius: 999px; padding: 4px 8px;
2781
3010
  }
2782
3011
  .chip i { color: var(--faint); font-style: normal; }
3012
+ .sql-layout {
3013
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3014
+ }
3015
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3016
+ .sql-tables button { text-align: left; }
3017
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2783
3018
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2784
3019
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2785
3020
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -2843,7 +3078,7 @@ var renderAdminDocument = (service) => {
2843
3078
  padding: 8px;
2844
3079
  }
2845
3080
  nav.side button { white-space: nowrap; flex: none; }
2846
- .split { grid-template-columns: minmax(0, 1fr); }
3081
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
2847
3082
  main { padding: 14px; }
2848
3083
  table, thead, tbody, tr, th, td { display: block; }
2849
3084
  thead { display: none; }
@@ -3014,6 +3249,24 @@ var json3 = (body) => new Response(JSON.stringify(body), {
3014
3249
  status: 200,
3015
3250
  headers: { "content-type": "application/json; charset=utf-8" }
3016
3251
  });
3252
+ var describeExtension = (extension) => {
3253
+ if (extension.kind === "sql") {
3254
+ return {
3255
+ kind: "sql",
3256
+ id: extension.id ?? "sql",
3257
+ title: extension.title ?? "SQL",
3258
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3259
+ };
3260
+ }
3261
+ return {
3262
+ kind: "panel",
3263
+ id: extension.id,
3264
+ title: extension.title,
3265
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3266
+ html: extension.html,
3267
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3268
+ };
3269
+ };
3017
3270
  var adminUiRoutes = (service, ui) => {
3018
3271
  const shell = () => renderAdminDocument(service);
3019
3272
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -3028,7 +3281,8 @@ var adminUiRoutes = (service, ui) => {
3028
3281
  ...panel.description !== void 0 ? { description: panel.description } : {},
3029
3282
  html: panel.html,
3030
3283
  ...panel.script !== void 0 ? { script: panel.script } : {}
3031
- }))
3284
+ })),
3285
+ extensions: (ui?.extensions ?? []).map(describeExtension)
3032
3286
  })
3033
3287
  };
3034
3288
  };
@@ -3631,7 +3885,7 @@ var stateAdminRoutes = (routes) => {
3631
3885
  };
3632
3886
 
3633
3887
  // ../core/dist/version.js
3634
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
3888
+ var PACKAGE_VERSION = true ? "1.7.1" : UNRELEASED_VERSION;
3635
3889
 
3636
3890
  // ../core/dist/signing.js
3637
3891
  var encoder = new TextEncoder();
@@ -5985,4 +6239,4 @@ export {
5985
6239
  twilioError,
5986
6240
  TwilioAPI
5987
6241
  };
5988
- //# sourceMappingURL=chunk-KBYCDOZD.js.map
6242
+ //# sourceMappingURL=chunk-SBUSJ7LX.js.map