@crvouga/mockingbird-service-customerio 1.6.1 → 1.7.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-customerio
2
2
 
3
+ ## 1.7.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.6.1 (2026-09-30)
4
14
 
5
15
  ### Fixes and improvements
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createRuntime
3
- } from "./chunk-GACYXHSL.js";
3
+ } from "./chunk-XHKPW7N3.js";
4
4
 
5
5
  // ../../adapters/node/dist/cli.js
6
6
  import { readFile } from "node:fs/promises";
@@ -368,4 +368,4 @@ export {
368
368
  createServer2 as createServer,
369
369
  serveTarget
370
370
  };
371
- //# sourceMappingURL=chunk-UJERTHN4.js.map
371
+ //# sourceMappingURL=chunk-SZRCSAWA.js.map
@@ -1960,6 +1960,167 @@ function faultPresetList(value) {
1960
1960
  })
1961
1961
  };
1962
1962
  }
1963
+ function mountSqlExplorer(root, api) {
1964
+ const cell = (value) => {
1965
+ if (value === null || value === void 0)
1966
+ return "";
1967
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1968
+ return String(value);
1969
+ }
1970
+ return JSON.stringify(value) ?? "";
1971
+ };
1972
+ root.replaceChildren();
1973
+ const layout = document.createElement("div");
1974
+ layout.className = "sql-layout";
1975
+ const tables = document.createElement("div");
1976
+ tables.className = "sql-tables";
1977
+ const stack = document.createElement("div");
1978
+ stack.className = "stack";
1979
+ const banner = document.createElement("p");
1980
+ banner.className = "banner";
1981
+ const grid = document.createElement("div");
1982
+ const input = document.createElement("textarea");
1983
+ input.className = "sql-input";
1984
+ input.spellcheck = false;
1985
+ input.placeholder = "SELECT * FROM ...";
1986
+ const actions = document.createElement("div");
1987
+ actions.className = "row-actions";
1988
+ const run = document.createElement("button");
1989
+ run.type = "button";
1990
+ run.textContent = "Run";
1991
+ actions.append(run);
1992
+ const result = document.createElement("pre");
1993
+ stack.append(banner, grid, input, actions, result);
1994
+ layout.append(tables, stack);
1995
+ root.append(layout);
1996
+ const showError = (error) => {
1997
+ banner.textContent = error instanceof Error ? error.message : String(error);
1998
+ banner.classList.add("show");
1999
+ };
2000
+ const clearError = () => {
2001
+ banner.textContent = "";
2002
+ banner.classList.remove("show");
2003
+ };
2004
+ const renderGrid = (columns, rows) => {
2005
+ grid.replaceChildren();
2006
+ if (columns.length === 0) {
2007
+ const empty = document.createElement("p");
2008
+ empty.className = "empty";
2009
+ empty.textContent = "No rows.";
2010
+ grid.append(empty);
2011
+ return;
2012
+ }
2013
+ const table = document.createElement("table");
2014
+ const head = document.createElement("thead");
2015
+ const headRow = document.createElement("tr");
2016
+ for (const column of columns) {
2017
+ const th = document.createElement("th");
2018
+ th.textContent = column;
2019
+ headRow.append(th);
2020
+ }
2021
+ head.append(headRow);
2022
+ const body = document.createElement("tbody");
2023
+ for (const row of rows) {
2024
+ const tr = document.createElement("tr");
2025
+ for (const column of columns) {
2026
+ const td = document.createElement("td");
2027
+ td.dataset.label = column;
2028
+ td.textContent = cell(row[column]);
2029
+ tr.append(td);
2030
+ }
2031
+ body.append(tr);
2032
+ }
2033
+ table.append(head, body);
2034
+ grid.append(table);
2035
+ };
2036
+ const rowsOf = (value) => {
2037
+ if (!isRecord2(value) || !Array.isArray(value.rows))
2038
+ return [];
2039
+ return value.rows.flatMap((row) => isRecord2(row) ? [row] : []);
2040
+ };
2041
+ const columnsOf = (value, rows) => {
2042
+ if (isRecord2(value) && Array.isArray(value.columns)) {
2043
+ const named = value.columns.flatMap((column) => typeof column === "string" ? [column] : []);
2044
+ if (named.length > 0)
2045
+ return named;
2046
+ }
2047
+ const first = rows[0];
2048
+ return first === void 0 ? [] : Object.keys(first);
2049
+ };
2050
+ let selected = "";
2051
+ const loadPage = async (schema, name) => {
2052
+ selected = `${schema}.${name}`;
2053
+ const page = await api.get(`/sql/tables/${encodeURIComponent(schema)}/${encodeURIComponent(name)}?limit=50`);
2054
+ const rows = rowsOf(page);
2055
+ renderGrid(columnsOf(page, rows), rows);
2056
+ const total = isRecord2(page) && typeof page.total === "number" ? page.total : rows.length;
2057
+ result.textContent = `${selected} \xB7 ${total} rows`;
2058
+ for (const button of tables.querySelectorAll("button")) {
2059
+ if (!(button instanceof HTMLButtonElement))
2060
+ continue;
2061
+ button.setAttribute("aria-current", button.dataset.schema === schema && button.dataset.table === name ? "true" : "false");
2062
+ }
2063
+ };
2064
+ const loadTables = async () => {
2065
+ const payload = await api.get("/sql/tables");
2066
+ const listed = isRecord2(payload) && Array.isArray(payload.tables) ? payload.tables : [];
2067
+ tables.replaceChildren();
2068
+ if (listed.length === 0) {
2069
+ const empty = document.createElement("p");
2070
+ empty.className = "empty";
2071
+ empty.textContent = "No tables.";
2072
+ tables.append(empty);
2073
+ return;
2074
+ }
2075
+ for (const item of listed) {
2076
+ if (!isRecord2(item) || typeof item.schema !== "string" || typeof item.name !== "string")
2077
+ continue;
2078
+ const button = document.createElement("button");
2079
+ button.type = "button";
2080
+ button.dataset.schema = item.schema;
2081
+ button.dataset.table = item.name;
2082
+ button.textContent = `${item.schema}.${item.name}`;
2083
+ tables.append(button);
2084
+ }
2085
+ };
2086
+ tables.addEventListener("click", (event) => {
2087
+ const target = event.target;
2088
+ if (!(target instanceof Element))
2089
+ return;
2090
+ const button = target.closest("button");
2091
+ if (!(button instanceof HTMLButtonElement))
2092
+ return;
2093
+ const schema = button.dataset.schema;
2094
+ const name = button.dataset.table;
2095
+ if (schema === void 0 || name === void 0)
2096
+ return;
2097
+ clearError();
2098
+ loadPage(schema, name).catch(showError);
2099
+ });
2100
+ run.addEventListener("click", () => {
2101
+ const sql = input.value.trim();
2102
+ if (sql === "") {
2103
+ showError(new Error("Enter a statement"));
2104
+ return;
2105
+ }
2106
+ clearError();
2107
+ api.send("POST", "/sql/query", { sql }).then((payload) => {
2108
+ const rows = rowsOf(payload);
2109
+ renderGrid(columnsOf(payload, rows), rows);
2110
+ const count = isRecord2(payload) && typeof payload.rowCount === "number" ? payload.rowCount : rows.length;
2111
+ const truncated = isRecord2(payload) && payload.truncated === true ? " (truncated)" : "";
2112
+ result.textContent = `${count} rows${truncated}`;
2113
+ }).catch(showError);
2114
+ });
2115
+ const namespace = document.getElementById("namespace");
2116
+ if (namespace) {
2117
+ namespace.addEventListener("change", () => {
2118
+ clearError();
2119
+ loadTables().catch(showError);
2120
+ });
2121
+ }
2122
+ loadTables().catch(showError);
2123
+ }
1963
2124
  function bootAdmin(config) {
1964
2125
  const fieldKinds = ["string", "number", "boolean", "null", "object", "array", "unknown"];
1965
2126
  const sources = ["declared", "inferred", "mixed"];
@@ -2636,6 +2797,22 @@ function bootAdmin(config) {
2636
2797
  panel.script = value.script;
2637
2798
  return panel;
2638
2799
  };
2800
+ const decodeExtension = (value) => {
2801
+ if (!isRecord2(value))
2802
+ return void 0;
2803
+ if (value.kind === "sql") {
2804
+ return {
2805
+ kind: "sql",
2806
+ id: typeof value.id === "string" && value.id !== "" ? value.id : "sql",
2807
+ title: typeof value.title === "string" && value.title !== "" ? value.title : "SQL",
2808
+ description: typeof value.description === "string" ? value.description : "Browse tables and run queries."
2809
+ };
2810
+ }
2811
+ if (value.kind !== "panel")
2812
+ return void 0;
2813
+ const panel = decodePanel(value);
2814
+ return panel === void 0 ? void 0 : { kind: "panel", ...panel };
2815
+ };
2639
2816
  const mountPanels = (panels) => {
2640
2817
  const nav = el("nav", HTMLElement);
2641
2818
  const views = el("views", HTMLElement);
@@ -2689,10 +2866,48 @@ function bootAdmin(config) {
2689
2866
  return decoded === void 0 ? [] : [decoded];
2690
2867
  });
2691
2868
  mountPanels(panels);
2869
+ const extensions = requireList(isRecord2(manifest) ? manifest.extensions : void 0, "Extensions").flatMap((extension) => {
2870
+ const decoded = decodeExtension(extension);
2871
+ return decoded === void 0 ? [] : [decoded];
2872
+ });
2873
+ const extensionPanels = extensions.flatMap((extension) => extension.kind === "panel" ? [extension] : []);
2874
+ mountPanels(extensionPanels);
2875
+ for (const extension of extensions) {
2876
+ if (extension.kind !== "sql")
2877
+ continue;
2878
+ const nav = el("nav", HTMLElement);
2879
+ const views = el("views", HTMLElement);
2880
+ const button = document.createElement("button");
2881
+ button.type = "button";
2882
+ button.dataset.view = extension.id;
2883
+ button.textContent = extension.title;
2884
+ nav.append(button);
2885
+ const section = document.createElement("section");
2886
+ section.className = "view";
2887
+ section.id = `view-${extension.id}`;
2888
+ section.hidden = true;
2889
+ const title = document.createElement("h2");
2890
+ title.textContent = extension.title;
2891
+ const lede = document.createElement("p");
2892
+ lede.className = "lede";
2893
+ lede.textContent = extension.description;
2894
+ const body = document.createElement("div");
2895
+ body.className = "panel-body";
2896
+ section.append(title, lede, body);
2897
+ views.append(section);
2898
+ mountSqlExplorer(body, panelApi);
2899
+ }
2692
2900
  return refresh();
2693
2901
  }).catch(showError);
2694
2902
  }
2695
- var clientPrelude = [isRecord2, mountAdminBrand, startAdminBrand, faultPresetList, bootAdmin].map((fn) => fn.toString()).join("\n");
2903
+ var clientPrelude = [
2904
+ isRecord2,
2905
+ mountAdminBrand,
2906
+ startAdminBrand,
2907
+ faultPresetList,
2908
+ mountSqlExplorer,
2909
+ bootAdmin
2910
+ ].map((fn) => fn.toString()).join("\n");
2696
2911
  var adminClientSource = (config) => {
2697
2912
  const payload = JSON.stringify(config).replace(/</g, "\\u003c");
2698
2913
  const entry = bootAdmin.name;
@@ -2742,19 +2957,33 @@ var STANDARD_ADMIN_ROUTES = [
2742
2957
  "GET /ui/manifest"
2743
2958
  ];
2744
2959
  var PANEL_ID = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
2960
+ var RESERVED_VIEWS = /* @__PURE__ */ new Set(["overview", "state", "clock", "faults", "journal", "routes"]);
2961
+ var checkPanel = (panel, seen, label) => {
2962
+ if (!PANEL_ID.test(panel.id)) {
2963
+ throw new RangeError(`${label} id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2964
+ }
2965
+ if (RESERVED_VIEWS.has(panel.id)) {
2966
+ throw new RangeError(`${label} id ${panel.id} is reserved by the admin shell`);
2967
+ }
2968
+ if (seen.has(panel.id))
2969
+ throw new RangeError(`duplicate admin view id ${panel.id}`);
2970
+ seen.add(panel.id);
2971
+ if (panel.title.trim() === "")
2972
+ throw new RangeError(`${label} ${panel.id} needs a title`);
2973
+ };
2745
2974
  var assertAdminUi = (ui) => {
2746
- if (!ui?.panels)
2975
+ if (!ui)
2747
2976
  return;
2748
2977
  const seen = /* @__PURE__ */ new Set();
2749
- for (const panel of ui.panels) {
2750
- if (!PANEL_ID.test(panel.id)) {
2751
- throw new RangeError(`admin panel id must match ${PANEL_ID}: ${JSON.stringify(panel.id)}`);
2978
+ for (const panel of ui.panels ?? [])
2979
+ checkPanel(panel, seen, "admin panel");
2980
+ for (const extension of ui.extensions ?? []) {
2981
+ if (extension.kind === "panel") {
2982
+ checkPanel(extension, seen, "admin extension");
2983
+ continue;
2752
2984
  }
2753
- if (seen.has(panel.id))
2754
- throw new RangeError(`duplicate admin panel id ${panel.id}`);
2755
- seen.add(panel.id);
2756
- if (panel.title.trim() === "")
2757
- throw new RangeError(`admin panel ${panel.id} needs a title`);
2985
+ const id = extension.id ?? "sql";
2986
+ checkPanel({ id, title: extension.title ?? "SQL" }, seen, "admin extension");
2758
2987
  }
2759
2988
  };
2760
2989
 
@@ -2988,6 +3217,12 @@ var renderAdminDocument = (service) => {
2988
3217
  border-radius: 999px; padding: 4px 8px;
2989
3218
  }
2990
3219
  .chip i { color: var(--faint); font-style: normal; }
3220
+ .sql-layout {
3221
+ display: grid; grid-template-columns: minmax(10rem, 16rem) minmax(0, 1fr); gap: 16px;
3222
+ }
3223
+ .sql-tables { display: flex; flex-direction: column; gap: 4px; max-height: 28rem; overflow: auto; }
3224
+ .sql-tables button { text-align: left; }
3225
+ .sql-input { font-family: var(--mono); min-height: 7rem; width: 100%; }
2991
3226
  table { width: 100%; border-collapse: collapse; font-size: 14px; }
2992
3227
  th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
2993
3228
  th { color: var(--faint); font-weight: 600; font-size: 12px; }
@@ -3051,7 +3286,7 @@ var renderAdminDocument = (service) => {
3051
3286
  padding: 8px;
3052
3287
  }
3053
3288
  nav.side button { white-space: nowrap; flex: none; }
3054
- .split { grid-template-columns: minmax(0, 1fr); }
3289
+ .split, .sql-layout { grid-template-columns: minmax(0, 1fr); }
3055
3290
  main { padding: 14px; }
3056
3291
  table, thead, tbody, tr, th, td { display: block; }
3057
3292
  thead { display: none; }
@@ -3222,6 +3457,24 @@ var json3 = (body) => new Response(JSON.stringify(body), {
3222
3457
  status: 200,
3223
3458
  headers: { "content-type": "application/json; charset=utf-8" }
3224
3459
  });
3460
+ var describeExtension = (extension) => {
3461
+ if (extension.kind === "sql") {
3462
+ return {
3463
+ kind: "sql",
3464
+ id: extension.id ?? "sql",
3465
+ title: extension.title ?? "SQL",
3466
+ ...extension.description !== void 0 ? { description: extension.description } : {}
3467
+ };
3468
+ }
3469
+ return {
3470
+ kind: "panel",
3471
+ id: extension.id,
3472
+ title: extension.title,
3473
+ ...extension.description !== void 0 ? { description: extension.description } : {},
3474
+ html: extension.html,
3475
+ ...extension.script !== void 0 ? { script: extension.script } : {}
3476
+ };
3477
+ };
3225
3478
  var adminUiRoutes = (service, ui) => {
3226
3479
  const shell = () => renderAdminDocument(service);
3227
3480
  const document3 = () => ui?.render ? ui.render({ service, defaultHtml: shell }) : shell();
@@ -3236,7 +3489,8 @@ var adminUiRoutes = (service, ui) => {
3236
3489
  ...panel.description !== void 0 ? { description: panel.description } : {},
3237
3490
  html: panel.html,
3238
3491
  ...panel.script !== void 0 ? { script: panel.script } : {}
3239
- }))
3492
+ })),
3493
+ extensions: (ui?.extensions ?? []).map(describeExtension)
3240
3494
  })
3241
3495
  };
3242
3496
  };
@@ -3913,7 +4167,7 @@ var stateAdminRoutes = (routes) => {
3913
4167
  };
3914
4168
 
3915
4169
  // ../core/dist/version.js
3916
- var PACKAGE_VERSION = true ? "1.6.1" : UNRELEASED_VERSION;
4170
+ var PACKAGE_VERSION = true ? "1.7.0" : UNRELEASED_VERSION;
3917
4171
 
3918
4172
  // ../core/dist/signing.js
3919
4173
  var encoder = new TextEncoder();
@@ -5947,4 +6201,4 @@ export {
5947
6201
  customerIoCredential,
5948
6202
  CustomerIoAPI
5949
6203
  };
5950
- //# sourceMappingURL=chunk-GACYXHSL.js.map
6204
+ //# sourceMappingURL=chunk-XHKPW7N3.js.map