@vibiz/cli 0.3.19 → 0.3.21

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/dist/vibiz.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  formatUsd,
12
12
  mergeEnvFile,
13
13
  oneKeyMessage
14
- } from "./chunk-ABEQTLK5.js";
14
+ } from "./chunk-EB6UCD3N.js";
15
15
 
16
16
  // packages/cli/src/main.ts
17
17
  import { spawn } from "node:child_process";
@@ -783,6 +783,282 @@ async function pullCommand(io, positionals, flags) {
783
783
  io.log(" Change what you need, then deploy it: vibiz deploy");
784
784
  }
785
785
 
786
+ // packages/cli/src/dashboards.ts
787
+ var RANGES = ["24h", "7d", "30d", "90d", "12m"];
788
+ function formatValue(v, unit) {
789
+ if (v === null || v === void 0) return "\u2013";
790
+ const n = Number(v);
791
+ if (!Number.isFinite(n)) return String(v);
792
+ switch (unit) {
793
+ case "usd_cents":
794
+ case "money":
795
+ return formatUsd(n / 100);
796
+ case "usd_micro":
797
+ return formatUsd(n / 1e6);
798
+ case "percent":
799
+ return `${n}%`;
800
+ default:
801
+ return n.toLocaleString("en-US");
802
+ }
803
+ }
804
+ function widgetLines(w, r) {
805
+ const head = w.title || r?.title || w.metric || (w.type === "text" ? "Text" : w.type);
806
+ if (w.type === "text")
807
+ return [` \xB6 ${(w.text ?? "").split("\n")[0]?.replace(/^#+\s*/, "") ?? ""}`];
808
+ if (!r) return [` ${head}: \u2013`];
809
+ if (r.error) {
810
+ const next = r.error.details?.next_step;
811
+ return [
812
+ ` \u2715 ${head}: ${r.error.message}`,
813
+ ...typeof next === "string" ? [` ${next}`] : []
814
+ ];
815
+ }
816
+ const d = r.data;
817
+ if (!d) return [` ${head}: \u2013`];
818
+ switch (d.shape) {
819
+ case "scalar": {
820
+ const change = d.change_pct === null ? "" : ` (${d.change_pct >= 0 ? "+" : ""}${d.change_pct}% vs before)`;
821
+ return [` ${head}: ${formatValue(d.value, d.unit)}${change}`];
822
+ }
823
+ case "timeseries": {
824
+ const lines = [` ${head} (by ${d.bucket}):`];
825
+ for (const s of d.series.slice(0, 6)) {
826
+ const last = s.values.at(-1);
827
+ lines.push(
828
+ ` ${s.label.padEnd(24)} total ${formatValue(s.total, d.unit)}, latest ${formatValue(last, d.unit)}`
829
+ );
830
+ }
831
+ if (!d.series.length) lines.push(" no data in this range");
832
+ return lines;
833
+ }
834
+ case "table": {
835
+ const lines = [` ${head}:`];
836
+ const cols = d.columns.slice(0, 5);
837
+ for (const row of d.rows.slice(0, 10)) {
838
+ lines.push(
839
+ ` ${cols.map(
840
+ (c) => c.unit === "text" || c.unit === "time" ? String(row[c.key] ?? "") : c.unit === "money" ? formatValue(row[c.key], "money") : formatValue(row[c.key], c.unit ?? d.unit)
841
+ ).join(" \xB7 ")}`
842
+ );
843
+ }
844
+ if (!d.rows.length) lines.push(" nothing in this range");
845
+ return lines;
846
+ }
847
+ case "funnel":
848
+ return [
849
+ ` ${head}:`,
850
+ ...d.steps.map(
851
+ (s) => ` ${s.label.padEnd(24)} ${String(s.visitors).padStart(7)}${s.rate_from_start === null ? "" : ` ${s.rate_from_start}%`}`
852
+ )
853
+ ];
854
+ case "cohort":
855
+ return [
856
+ ` ${head}:`,
857
+ ...d.cohorts.map(
858
+ (c) => ` ${c.label.padEnd(10)} ${String(c.size).padStart(5)} ${c.values.map((v) => v === null ? "" : `${Math.round(v)}%`.padStart(5)).join(" ")}`
859
+ )
860
+ ];
861
+ }
862
+ }
863
+ function printDashboard(io, d, results) {
864
+ const where = d.level === "account" ? "account" : `project ${d.project_id}`;
865
+ io.log(`${d.name} (${d.id}, ${where}, ${d.range})`);
866
+ const ordered = [...d.widgets].sort((a, b) => a.layout.y - b.layout.y || a.layout.x - b.layout.x);
867
+ for (const w of ordered) {
868
+ const r = results?.find((x) => x.widget_id === w.id);
869
+ for (const line2 of widgetLines(w, r)) io.log(line2);
870
+ if (!results) io.log(` ${w.id} \xB7 ${w.type}${w.metric ? ` \xB7 ${w.metric}` : ""}`);
871
+ }
872
+ if (!d.widgets.length)
873
+ io.log(
874
+ " No widgets yet: vibiz dashboards add-widget <id> --type stat --metric payments.revenue"
875
+ );
876
+ io.log(`
877
+ ${d.console_url}`);
878
+ }
879
+ function widgetFromFlags(f) {
880
+ if (!f.type) {
881
+ throw new Error(
882
+ "Say the widget type: --type stat|line|area|bar|table|list|funnel|cohort|text (vibiz dashboards metrics lists what each metric fits)."
883
+ );
884
+ }
885
+ const filters = {};
886
+ for (const kv of f.filter ?? []) {
887
+ const i = kv.indexOf("=");
888
+ if (i <= 0) throw new Error(`--filter ${kv}: write it as key=value (country=US).`);
889
+ filters[kv.slice(0, i)] = kv.slice(i + 1);
890
+ }
891
+ const limit = f.limit ? Number(f.limit) : void 0;
892
+ if (limit !== void 0 && !Number.isInteger(limit)) throw new Error("--limit: a whole number.");
893
+ const options = {
894
+ ...f.breakdown ? { breakdown: f.breakdown } : {},
895
+ ...Object.keys(filters).length ? { filters } : {},
896
+ ...limit ? { limit } : {},
897
+ ...f.bucket ? { bucket: f.bucket } : {},
898
+ ...f.steps ? {
899
+ steps: f.steps.split(",").map((x) => x.trim()).filter(Boolean)
900
+ } : {}
901
+ };
902
+ return {
903
+ type: f.type,
904
+ ...f.metric ? { metric: f.metric } : {},
905
+ ...f.title ? { title: f.title } : {},
906
+ ...f.text ? { text: f.text } : {},
907
+ options
908
+ };
909
+ }
910
+ var rangeOf = (f) => {
911
+ if (f.range && !RANGES.includes(f.range))
912
+ throw new Error(`--range: one of ${RANGES.join(", ")} (or --from/--to YYYY-MM-DD).`);
913
+ return f.range;
914
+ };
915
+ async function dashboardsCommand(io, positionals, f) {
916
+ const vibiz2 = await io.client();
917
+ const [sub, a, b] = positionals;
918
+ const account = f.level === "account";
919
+ if (f.level && f.level !== "account" && f.level !== "project")
920
+ throw new Error("--level: account or project.");
921
+ const out = (value) => io.log(JSON.stringify(value, null, 2));
922
+ switch (sub ?? "list") {
923
+ case "list": {
924
+ const projectId = account ? void 0 : await io.project().catch(() => void 0);
925
+ const list2 = await vibiz2.dashboards.list(
926
+ projectId ? { project_id: projectId } : { level: "account" }
927
+ );
928
+ if (f.json) return out(list2);
929
+ if (!list2.data.length) {
930
+ io.log(
931
+ projectId ? "No dashboards for this project yet. Start one: vibiz dashboards create --template traffic (or churn, ai_cost, growth)" : "No account dashboards yet. Start one: vibiz dashboards create --template portfolio --level account"
932
+ );
933
+ }
934
+ for (const d of list2.data) {
935
+ io.log(` ${d.id} ${d.name.padEnd(28)} ${d.widgets.length} widgets ${d.console_url}`);
936
+ }
937
+ io.log(`
938
+ ${list2.console_url}`);
939
+ return;
940
+ }
941
+ case "metrics": {
942
+ const cat = await vibiz2.dashboards.metrics();
943
+ if (f.json) return out(cat);
944
+ let product = "";
945
+ for (const m of cat.metrics) {
946
+ if (f.product && m.product !== f.product) continue;
947
+ if (m.product !== product) {
948
+ product = m.product;
949
+ io.log(`
950
+ ${m.product_label}`);
951
+ }
952
+ const extra = [
953
+ m.breakdowns.length ? `by ${m.breakdowns.map((x) => x.id).join("|")}` : "",
954
+ m.permission ? `needs ${m.permission}` : "",
955
+ m.levels.length === 1 ? `${m.levels[0]} only` : ""
956
+ ].filter(Boolean).join("; ");
957
+ io.log(
958
+ ` ${m.id.padEnd(34)} ${m.label} (${m.widget_types.join(", ")})${extra ? ` ${extra}` : ""}`
959
+ );
960
+ }
961
+ io.log("\nTemplates:");
962
+ for (const t of cat.templates)
963
+ io.log(` ${t.id.padEnd(12)} ${t.name} (${t.level}): ${t.description}`);
964
+ return;
965
+ }
966
+ case "templates": {
967
+ const cat = await vibiz2.dashboards.metrics();
968
+ if (f.json) return out(cat.templates);
969
+ for (const t of cat.templates)
970
+ io.log(` ${t.id.padEnd(12)} ${t.name} (${t.level}): ${t.description}`);
971
+ return;
972
+ }
973
+ case "create": {
974
+ const name = f.name ?? a;
975
+ if (!f.template && !name) {
976
+ throw new Error(
977
+ "Name it or start from a template: vibiz dashboards create --template churn (traffic, ai_cost, growth; portfolio for the account)."
978
+ );
979
+ }
980
+ const cat = f.template ? await vibiz2.dashboards.metrics() : null;
981
+ const tpl = cat?.templates.find((t) => t.id === f.template);
982
+ const forAccount = account || tpl?.level === "account";
983
+ const project_id = forAccount ? void 0 : await io.project();
984
+ const d = await vibiz2.dashboards.create({
985
+ ...name ? { name } : {},
986
+ ...f.template ? { template: f.template } : {},
987
+ ...project_id ? { project_id } : {},
988
+ ...rangeOf(f) ? { range: rangeOf(f) } : {}
989
+ });
990
+ if (f.json) return out(d);
991
+ io.log(`Made ${d.name} (${d.id}) with ${d.widgets.length} widgets.`);
992
+ io.log(` See it: ${d.console_url}`);
993
+ io.log(` Numbers here: vibiz dashboards show ${d.id}`);
994
+ if (f.open) io.openUrl(d.console_url);
995
+ return;
996
+ }
997
+ case "show": {
998
+ if (!a)
999
+ throw new Error(
1000
+ "Which dashboard? vibiz dashboards show <id> (vibiz dashboards lists them)."
1001
+ );
1002
+ const [d, data] = await Promise.all([
1003
+ vibiz2.dashboards.get(a),
1004
+ vibiz2.dashboards.data(a, {
1005
+ ...rangeOf(f) ? { range: rangeOf(f) } : {},
1006
+ ...f.from ? { from: f.from } : {},
1007
+ ...f.to ? { to: f.to } : {}
1008
+ })
1009
+ ]);
1010
+ if (f.json) return out({ dashboard: d, data });
1011
+ printDashboard(io, { ...d, console_url: data.console_url }, data.widgets);
1012
+ if (f.open) io.openUrl(data.console_url);
1013
+ return;
1014
+ }
1015
+ case "add-widget": {
1016
+ if (!a)
1017
+ throw new Error(
1018
+ "Which dashboard? vibiz dashboards add-widget <id> --type stat --metric payments.revenue"
1019
+ );
1020
+ const res = await vibiz2.dashboards.addWidget(a, widgetFromFlags(f));
1021
+ if (f.json) return out(res);
1022
+ io.log(
1023
+ `Added ${res.widget.title ?? res.widget.metric ?? res.widget.type} (${res.widget.id}) to ${res.name}.`
1024
+ );
1025
+ const data = await vibiz2.dashboards.data(a, { widget: res.widget.id });
1026
+ for (const line2 of widgetLines(res.widget, data.widgets[0])) io.log(line2);
1027
+ io.log(` ${res.console_url}`);
1028
+ return;
1029
+ }
1030
+ case "rm-widget": {
1031
+ if (!a || !b)
1032
+ throw new Error(
1033
+ "vibiz dashboards rm-widget <dashboard> <widget> (vibiz dashboards show <id> lists widget ids)."
1034
+ );
1035
+ const d = await vibiz2.dashboards.removeWidget(a, b);
1036
+ if (f.json) return out(d);
1037
+ io.log(`Removed ${b}; ${d.name} has ${d.widgets.length} widgets.`);
1038
+ return;
1039
+ }
1040
+ case "rm":
1041
+ case "delete": {
1042
+ if (!a) throw new Error("Which dashboard? vibiz dashboards rm <id>");
1043
+ const r = await vibiz2.dashboards.delete(a);
1044
+ if (f.json) return out(r);
1045
+ io.log(`Deleted dashboard ${a} (the data it showed stays).`);
1046
+ return;
1047
+ }
1048
+ case "open": {
1049
+ if (!a) throw new Error("Which dashboard? vibiz dashboards open <id>");
1050
+ const d = await vibiz2.dashboards.get(a);
1051
+ io.log(d.console_url);
1052
+ io.openUrl(d.console_url);
1053
+ return;
1054
+ }
1055
+ default:
1056
+ throw new Error(
1057
+ `vibiz dashboards ${sub}: not a command. Try list, metrics, templates, create, show, add-widget, rm-widget, rm, open.`
1058
+ );
1059
+ }
1060
+ }
1061
+
786
1062
  // packages/cli/src/design.ts
787
1063
  import { dirname as dirname2, join as join2 } from "node:path";
788
1064
  var usd = (micro) => micro === null || micro === void 0 ? "" : `$${(micro / 1e6).toFixed(micro < 1e4 ? 4 : 2)}`;
@@ -3269,8 +3545,8 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3269
3545
  Authorize (Full access by default, or Limited),
3270
3546
  and the new key is saved here
3271
3547
  [--key <vz_sk_\u2026>] [--api <url>] [--no-browser] or save a key you already have
3272
- vibiz signup the same as login: invited, with no account yet? one
3273
- is opened for you on the way
3548
+ vibiz signup the same as login: no account yet? one is opened
3549
+ for you on the way
3274
3550
  vibiz whoami the account and key this machine uses
3275
3551
  vibiz logout forget this machine's key (a browser login's key is
3276
3552
  revoked too)
@@ -3501,6 +3777,20 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3501
3777
  to fix, and the console page
3502
3778
  vibiz health run [<project>] check again now (every business, or one); checks
3503
3779
  also run every hour on their own
3780
+ vibiz dashboards [--level account] [--json] this project's dashboards (or the account's, across
3781
+ businesses), each with its console link
3782
+ vibiz dashboards metrics [--product payments] the metric catalogue: what each widget can show,
3783
+ its breakdowns, filters and the permission it needs
3784
+ vibiz dashboards create --template churn|traffic|ai_cost|growth|portfolio [--name n] [--open]
3785
+ a whole dashboard in one call (portfolio: the account)
3786
+ vibiz dashboards create "<name>" [--level account] an empty one to add widgets to
3787
+ vibiz dashboards show <id> [--range 7d|30d|90d|12m] [--from YYYY-MM-DD --to \u2026] [--json]
3788
+ every widget's numbers, and the link with the range
3789
+ vibiz dashboards add-widget <id> --type stat|line|area|bar|table|list|funnel|cohort|text
3790
+ --metric <id> [--breakdown source] [--filter key=value]\u2026 [--limit n] [--bucket week]
3791
+ [--steps /,/pricing,Signup] [--title t] [--text "## Note"]
3792
+ add one, placed in the first free spot
3793
+ vibiz dashboards rm-widget <id> <widget> | rm <id> | open <id>
3504
3794
  vibiz search [--json] where this project's pages go to search engines:
3505
3795
  new and changed pages go to IndexNow after every
3506
3796
  production deploy (own domain only)
@@ -4806,6 +5096,16 @@ async function runCli(argv2, io) {
4806
5096
  period: { type: "string" },
4807
5097
  json: { type: "boolean", default: false },
4808
5098
  failing: { type: "boolean", default: false },
5099
+ // vibiz dashboards (docs: dashboards)
5100
+ metric: { type: "string" },
5101
+ breakdown: { type: "string" },
5102
+ filter: { type: "string", multiple: true },
5103
+ title: { type: "string" },
5104
+ steps: { type: "string" },
5105
+ range: { type: "string" },
5106
+ bucket: { type: "string" },
5107
+ level: { type: "string" },
5108
+ product: { type: "string" },
4809
5109
  // vibiz search pages (docs: Search)
4810
5110
  "not-indexed": { type: "boolean", default: false },
4811
5111
  "owner-email": { type: "string" },
@@ -6488,6 +6788,11 @@ ${await oneKeyLines(vibiz2, id)}`);
6488
6788
  await healthCommand(io, positionals, values);
6489
6789
  return;
6490
6790
  }
6791
+ case "dashboards":
6792
+ case "dashboard": {
6793
+ await dashboardsCommand(io, positionals, values);
6794
+ return;
6795
+ }
6491
6796
  case "replays": {
6492
6797
  if (positionals[0] === "frames") {
6493
6798
  await framesCommand(io, positionals[1], values);
@@ -7124,7 +7429,7 @@ Store the key now: it is not shown again.`
7124
7429
  return;
7125
7430
  }
7126
7431
  case "docs": {
7127
- const { DOC_TOPICS, DOCS } = await import("./src-QORY7VZT.js");
7432
+ const { DOC_TOPICS, DOCS } = await import("./src-2NR66EYY.js");
7128
7433
  const topic = positionals[0];
7129
7434
  if (!topic || !DOC_TOPICS.includes(topic)) {
7130
7435
  for (const t of DOC_TOPICS) io.log(` vibiz docs ${t.padEnd(13)} ${DOCS[t].title}`);
@@ -7149,7 +7454,7 @@ ${DOCS[topic].body}`);
7149
7454
  if (positionals[0])
7150
7455
  throw new Error('usage: vibiz mcp (serve over stdio) | vibiz mcp add --clients "<client>"');
7151
7456
  io.local();
7152
- const { serveStdio } = await import("./src-QORY7VZT.js");
7457
+ const { serveStdio } = await import("./src-2NR66EYY.js");
7153
7458
  await serveStdio({ version: cliVersion() });
7154
7459
  return;
7155
7460
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibiz/cli",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
4
4
  "description": "The thelastapi CLI and MCP server: website, database, sign-in, email and AI for a new business, from your terminal or your AI agent.",
5
5
  "keywords": [
6
6
  "vibiz",