@vibiz/cli 0.3.20 → 0.3.22

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-CCEASH5K.js";
14
+ } from "./chunk-B6V7DN6A.js";
15
15
 
16
16
  // packages/cli/src/main.ts
17
17
  import { spawn } from "node:child_process";
@@ -491,6 +491,64 @@ var VibizApp = class _VibizApp {
491
491
  { method: "DELETE" }
492
492
  )
493
493
  };
494
+ /**
495
+ * Your users' own social accounts (docs: social ▸ "Social for your app's
496
+ * users"), on `vibiz.user(id)`: they connect Threads, Bluesky, Instagram…
497
+ * with no thelastapi sign-in, and post or schedule to them with no owner
498
+ * approval. Each user sees only their own accounts and posts. A development
499
+ * key connects test accounts at once and posts nowhere.
500
+ */
501
+ get social() {
502
+ const user = this.options.user;
503
+ const base = () => {
504
+ if (!user) {
505
+ throw new VibizAppError(
506
+ 400,
507
+ "invalid_request",
508
+ "Social acts for one of your users: call it on vibiz.user(userId).social."
509
+ );
510
+ }
511
+ return `/app/social/users/${encodeURIComponent(user)}`;
512
+ };
513
+ const getPost = (id) => this.request(`${base()}/posts/${encodeURIComponent(id)}`);
514
+ const createPost = (input) => this.request(`${base()}/posts`, { body: input });
515
+ function post(arg) {
516
+ return typeof arg === "string" ? getPost(arg) : createPost(arg);
517
+ }
518
+ return {
519
+ /** A link for your user to connect an account; `return_url` must be on your app's own address. */
520
+ connect: (input) => this.request(`${base()}/connect`, { body: input }),
521
+ accounts: () => this.request(
522
+ `${base()}/accounts`
523
+ ),
524
+ disconnect: (accountId) => this.request(`${base()}/accounts/${encodeURIComponent(accountId)}`, {
525
+ method: "DELETE"
526
+ }),
527
+ /** `post(input)` publishes, schedules or drafts; `post(id)` reads one back. */
528
+ post,
529
+ get: getPost,
530
+ posts: (opts = {}) => this.request(
531
+ `${base()}/posts${query({ ...opts, status: Array.isArray(opts.status) ? opts.status.join(",") : opts.status })}`
532
+ ),
533
+ /** Publish a draft now, or at `schedule_at`. */
534
+ publish: (id, opts = {}) => this.request(`${base()}/posts/${encodeURIComponent(id)}/publish`, {
535
+ body: opts
536
+ }),
537
+ /** Cancel a draft or a scheduled post (a published one stays on the platforms). */
538
+ cancel: (id) => this.request(`${base()}/posts/${encodeURIComponent(id)}/cancel`, {
539
+ body: {}
540
+ }),
541
+ /** Upload an image or video (at most 512 MB) → `{url}` to put in `media`. */
542
+ upload: async (file, opts) => {
543
+ const raw = file instanceof Uint8Array ? file : new Uint8Array(await file.arrayBuffer());
544
+ const contentType = opts.contentType ?? (file instanceof Blob && file.type ? file.type : void 0);
545
+ return this.request(`${base()}/media${query({ filename: opts.name })}`, {
546
+ raw,
547
+ ...contentType ? { contentType } : {}
548
+ });
549
+ }
550
+ };
551
+ }
494
552
  /**
495
553
  * The project's contacts (docs: email ▸ Contacts): who gets its newsletters and
496
554
  * automations. Add users at signup, keep their properties current, and track
@@ -783,6 +841,282 @@ async function pullCommand(io, positionals, flags) {
783
841
  io.log(" Change what you need, then deploy it: vibiz deploy");
784
842
  }
785
843
 
844
+ // packages/cli/src/dashboards.ts
845
+ var RANGES = ["24h", "7d", "30d", "90d", "12m"];
846
+ function formatValue(v, unit) {
847
+ if (v === null || v === void 0) return "\u2013";
848
+ const n = Number(v);
849
+ if (!Number.isFinite(n)) return String(v);
850
+ switch (unit) {
851
+ case "usd_cents":
852
+ case "money":
853
+ return formatUsd(n / 100);
854
+ case "usd_micro":
855
+ return formatUsd(n / 1e6);
856
+ case "percent":
857
+ return `${n}%`;
858
+ default:
859
+ return n.toLocaleString("en-US");
860
+ }
861
+ }
862
+ function widgetLines(w, r) {
863
+ const head = w.title || r?.title || w.metric || (w.type === "text" ? "Text" : w.type);
864
+ if (w.type === "text")
865
+ return [` \xB6 ${(w.text ?? "").split("\n")[0]?.replace(/^#+\s*/, "") ?? ""}`];
866
+ if (!r) return [` ${head}: \u2013`];
867
+ if (r.error) {
868
+ const next = r.error.details?.next_step;
869
+ return [
870
+ ` \u2715 ${head}: ${r.error.message}`,
871
+ ...typeof next === "string" ? [` ${next}`] : []
872
+ ];
873
+ }
874
+ const d = r.data;
875
+ if (!d) return [` ${head}: \u2013`];
876
+ switch (d.shape) {
877
+ case "scalar": {
878
+ const change = d.change_pct === null ? "" : ` (${d.change_pct >= 0 ? "+" : ""}${d.change_pct}% vs before)`;
879
+ return [` ${head}: ${formatValue(d.value, d.unit)}${change}`];
880
+ }
881
+ case "timeseries": {
882
+ const lines = [` ${head} (by ${d.bucket}):`];
883
+ for (const s of d.series.slice(0, 6)) {
884
+ const last = s.values.at(-1);
885
+ lines.push(
886
+ ` ${s.label.padEnd(24)} total ${formatValue(s.total, d.unit)}, latest ${formatValue(last, d.unit)}`
887
+ );
888
+ }
889
+ if (!d.series.length) lines.push(" no data in this range");
890
+ return lines;
891
+ }
892
+ case "table": {
893
+ const lines = [` ${head}:`];
894
+ const cols = d.columns.slice(0, 5);
895
+ for (const row of d.rows.slice(0, 10)) {
896
+ lines.push(
897
+ ` ${cols.map(
898
+ (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)
899
+ ).join(" \xB7 ")}`
900
+ );
901
+ }
902
+ if (!d.rows.length) lines.push(" nothing in this range");
903
+ return lines;
904
+ }
905
+ case "funnel":
906
+ return [
907
+ ` ${head}:`,
908
+ ...d.steps.map(
909
+ (s) => ` ${s.label.padEnd(24)} ${String(s.visitors).padStart(7)}${s.rate_from_start === null ? "" : ` ${s.rate_from_start}%`}`
910
+ )
911
+ ];
912
+ case "cohort":
913
+ return [
914
+ ` ${head}:`,
915
+ ...d.cohorts.map(
916
+ (c) => ` ${c.label.padEnd(10)} ${String(c.size).padStart(5)} ${c.values.map((v) => v === null ? "" : `${Math.round(v)}%`.padStart(5)).join(" ")}`
917
+ )
918
+ ];
919
+ }
920
+ }
921
+ function printDashboard(io, d, results) {
922
+ const where = d.level === "account" ? "account" : `project ${d.project_id}`;
923
+ io.log(`${d.name} (${d.id}, ${where}, ${d.range})`);
924
+ const ordered = [...d.widgets].sort((a, b) => a.layout.y - b.layout.y || a.layout.x - b.layout.x);
925
+ for (const w of ordered) {
926
+ const r = results?.find((x) => x.widget_id === w.id);
927
+ for (const line2 of widgetLines(w, r)) io.log(line2);
928
+ if (!results) io.log(` ${w.id} \xB7 ${w.type}${w.metric ? ` \xB7 ${w.metric}` : ""}`);
929
+ }
930
+ if (!d.widgets.length)
931
+ io.log(
932
+ " No widgets yet: vibiz dashboards add-widget <id> --type stat --metric payments.revenue"
933
+ );
934
+ io.log(`
935
+ ${d.console_url}`);
936
+ }
937
+ function widgetFromFlags(f) {
938
+ if (!f.type) {
939
+ throw new Error(
940
+ "Say the widget type: --type stat|line|area|bar|table|list|funnel|cohort|text (vibiz dashboards metrics lists what each metric fits)."
941
+ );
942
+ }
943
+ const filters = {};
944
+ for (const kv of f.filter ?? []) {
945
+ const i = kv.indexOf("=");
946
+ if (i <= 0) throw new Error(`--filter ${kv}: write it as key=value (country=US).`);
947
+ filters[kv.slice(0, i)] = kv.slice(i + 1);
948
+ }
949
+ const limit = f.limit ? Number(f.limit) : void 0;
950
+ if (limit !== void 0 && !Number.isInteger(limit)) throw new Error("--limit: a whole number.");
951
+ const options = {
952
+ ...f.breakdown ? { breakdown: f.breakdown } : {},
953
+ ...Object.keys(filters).length ? { filters } : {},
954
+ ...limit ? { limit } : {},
955
+ ...f.bucket ? { bucket: f.bucket } : {},
956
+ ...f.steps ? {
957
+ steps: f.steps.split(",").map((x) => x.trim()).filter(Boolean)
958
+ } : {}
959
+ };
960
+ return {
961
+ type: f.type,
962
+ ...f.metric ? { metric: f.metric } : {},
963
+ ...f.title ? { title: f.title } : {},
964
+ ...f.text ? { text: f.text } : {},
965
+ options
966
+ };
967
+ }
968
+ var rangeOf = (f) => {
969
+ if (f.range && !RANGES.includes(f.range))
970
+ throw new Error(`--range: one of ${RANGES.join(", ")} (or --from/--to YYYY-MM-DD).`);
971
+ return f.range;
972
+ };
973
+ async function dashboardsCommand(io, positionals, f) {
974
+ const vibiz2 = await io.client();
975
+ const [sub, a, b] = positionals;
976
+ const account = f.level === "account";
977
+ if (f.level && f.level !== "account" && f.level !== "project")
978
+ throw new Error("--level: account or project.");
979
+ const out = (value) => io.log(JSON.stringify(value, null, 2));
980
+ switch (sub ?? "list") {
981
+ case "list": {
982
+ const projectId = account ? void 0 : await io.project().catch(() => void 0);
983
+ const list2 = await vibiz2.dashboards.list(
984
+ projectId ? { project_id: projectId } : { level: "account" }
985
+ );
986
+ if (f.json) return out(list2);
987
+ if (!list2.data.length) {
988
+ io.log(
989
+ 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"
990
+ );
991
+ }
992
+ for (const d of list2.data) {
993
+ io.log(` ${d.id} ${d.name.padEnd(28)} ${d.widgets.length} widgets ${d.console_url}`);
994
+ }
995
+ io.log(`
996
+ ${list2.console_url}`);
997
+ return;
998
+ }
999
+ case "metrics": {
1000
+ const cat = await vibiz2.dashboards.metrics();
1001
+ if (f.json) return out(cat);
1002
+ let product = "";
1003
+ for (const m of cat.metrics) {
1004
+ if (f.product && m.product !== f.product) continue;
1005
+ if (m.product !== product) {
1006
+ product = m.product;
1007
+ io.log(`
1008
+ ${m.product_label}`);
1009
+ }
1010
+ const extra = [
1011
+ m.breakdowns.length ? `by ${m.breakdowns.map((x) => x.id).join("|")}` : "",
1012
+ m.permission ? `needs ${m.permission}` : "",
1013
+ m.levels.length === 1 ? `${m.levels[0]} only` : ""
1014
+ ].filter(Boolean).join("; ");
1015
+ io.log(
1016
+ ` ${m.id.padEnd(34)} ${m.label} (${m.widget_types.join(", ")})${extra ? ` ${extra}` : ""}`
1017
+ );
1018
+ }
1019
+ io.log("\nTemplates:");
1020
+ for (const t of cat.templates)
1021
+ io.log(` ${t.id.padEnd(12)} ${t.name} (${t.level}): ${t.description}`);
1022
+ return;
1023
+ }
1024
+ case "templates": {
1025
+ const cat = await vibiz2.dashboards.metrics();
1026
+ if (f.json) return out(cat.templates);
1027
+ for (const t of cat.templates)
1028
+ io.log(` ${t.id.padEnd(12)} ${t.name} (${t.level}): ${t.description}`);
1029
+ return;
1030
+ }
1031
+ case "create": {
1032
+ const name = f.name ?? a;
1033
+ if (!f.template && !name) {
1034
+ throw new Error(
1035
+ "Name it or start from a template: vibiz dashboards create --template churn (traffic, ai_cost, growth; portfolio for the account)."
1036
+ );
1037
+ }
1038
+ const cat = f.template ? await vibiz2.dashboards.metrics() : null;
1039
+ const tpl = cat?.templates.find((t) => t.id === f.template);
1040
+ const forAccount = account || tpl?.level === "account";
1041
+ const project_id = forAccount ? void 0 : await io.project();
1042
+ const d = await vibiz2.dashboards.create({
1043
+ ...name ? { name } : {},
1044
+ ...f.template ? { template: f.template } : {},
1045
+ ...project_id ? { project_id } : {},
1046
+ ...rangeOf(f) ? { range: rangeOf(f) } : {}
1047
+ });
1048
+ if (f.json) return out(d);
1049
+ io.log(`Made ${d.name} (${d.id}) with ${d.widgets.length} widgets.`);
1050
+ io.log(` See it: ${d.console_url}`);
1051
+ io.log(` Numbers here: vibiz dashboards show ${d.id}`);
1052
+ if (f.open) io.openUrl(d.console_url);
1053
+ return;
1054
+ }
1055
+ case "show": {
1056
+ if (!a)
1057
+ throw new Error(
1058
+ "Which dashboard? vibiz dashboards show <id> (vibiz dashboards lists them)."
1059
+ );
1060
+ const [d, data] = await Promise.all([
1061
+ vibiz2.dashboards.get(a),
1062
+ vibiz2.dashboards.data(a, {
1063
+ ...rangeOf(f) ? { range: rangeOf(f) } : {},
1064
+ ...f.from ? { from: f.from } : {},
1065
+ ...f.to ? { to: f.to } : {}
1066
+ })
1067
+ ]);
1068
+ if (f.json) return out({ dashboard: d, data });
1069
+ printDashboard(io, { ...d, console_url: data.console_url }, data.widgets);
1070
+ if (f.open) io.openUrl(data.console_url);
1071
+ return;
1072
+ }
1073
+ case "add-widget": {
1074
+ if (!a)
1075
+ throw new Error(
1076
+ "Which dashboard? vibiz dashboards add-widget <id> --type stat --metric payments.revenue"
1077
+ );
1078
+ const res = await vibiz2.dashboards.addWidget(a, widgetFromFlags(f));
1079
+ if (f.json) return out(res);
1080
+ io.log(
1081
+ `Added ${res.widget.title ?? res.widget.metric ?? res.widget.type} (${res.widget.id}) to ${res.name}.`
1082
+ );
1083
+ const data = await vibiz2.dashboards.data(a, { widget: res.widget.id });
1084
+ for (const line2 of widgetLines(res.widget, data.widgets[0])) io.log(line2);
1085
+ io.log(` ${res.console_url}`);
1086
+ return;
1087
+ }
1088
+ case "rm-widget": {
1089
+ if (!a || !b)
1090
+ throw new Error(
1091
+ "vibiz dashboards rm-widget <dashboard> <widget> (vibiz dashboards show <id> lists widget ids)."
1092
+ );
1093
+ const d = await vibiz2.dashboards.removeWidget(a, b);
1094
+ if (f.json) return out(d);
1095
+ io.log(`Removed ${b}; ${d.name} has ${d.widgets.length} widgets.`);
1096
+ return;
1097
+ }
1098
+ case "rm":
1099
+ case "delete": {
1100
+ if (!a) throw new Error("Which dashboard? vibiz dashboards rm <id>");
1101
+ const r = await vibiz2.dashboards.delete(a);
1102
+ if (f.json) return out(r);
1103
+ io.log(`Deleted dashboard ${a} (the data it showed stays).`);
1104
+ return;
1105
+ }
1106
+ case "open": {
1107
+ if (!a) throw new Error("Which dashboard? vibiz dashboards open <id>");
1108
+ const d = await vibiz2.dashboards.get(a);
1109
+ io.log(d.console_url);
1110
+ io.openUrl(d.console_url);
1111
+ return;
1112
+ }
1113
+ default:
1114
+ throw new Error(
1115
+ `vibiz dashboards ${sub}: not a command. Try list, metrics, templates, create, show, add-widget, rm-widget, rm, open.`
1116
+ );
1117
+ }
1118
+ }
1119
+
786
1120
  // packages/cli/src/design.ts
787
1121
  import { dirname as dirname2, join as join2 } from "node:path";
788
1122
  var usd = (micro) => micro === null || micro === void 0 ? "" : `$${(micro / 1e6).toFixed(micro < 1e4 ? 4 : 2)}`;
@@ -3501,6 +3835,20 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3501
3835
  to fix, and the console page
3502
3836
  vibiz health run [<project>] check again now (every business, or one); checks
3503
3837
  also run every hour on their own
3838
+ vibiz dashboards [--level account] [--json] this project's dashboards (or the account's, across
3839
+ businesses), each with its console link
3840
+ vibiz dashboards metrics [--product payments] the metric catalogue: what each widget can show,
3841
+ its breakdowns, filters and the permission it needs
3842
+ vibiz dashboards create --template churn|traffic|ai_cost|growth|portfolio [--name n] [--open]
3843
+ a whole dashboard in one call (portfolio: the account)
3844
+ vibiz dashboards create "<name>" [--level account] an empty one to add widgets to
3845
+ vibiz dashboards show <id> [--range 7d|30d|90d|12m] [--from YYYY-MM-DD --to \u2026] [--json]
3846
+ every widget's numbers, and the link with the range
3847
+ vibiz dashboards add-widget <id> --type stat|line|area|bar|table|list|funnel|cohort|text
3848
+ --metric <id> [--breakdown source] [--filter key=value]\u2026 [--limit n] [--bucket week]
3849
+ [--steps /,/pricing,Signup] [--title t] [--text "## Note"]
3850
+ add one, placed in the first free spot
3851
+ vibiz dashboards rm-widget <id> <widget> | rm <id> | open <id>
3504
3852
  vibiz search [--json] where this project's pages go to search engines:
3505
3853
  new and changed pages go to IndexNow after every
3506
3854
  production deploy (own domain only)
@@ -4806,6 +5154,16 @@ async function runCli(argv2, io) {
4806
5154
  period: { type: "string" },
4807
5155
  json: { type: "boolean", default: false },
4808
5156
  failing: { type: "boolean", default: false },
5157
+ // vibiz dashboards (docs: dashboards)
5158
+ metric: { type: "string" },
5159
+ breakdown: { type: "string" },
5160
+ filter: { type: "string", multiple: true },
5161
+ title: { type: "string" },
5162
+ steps: { type: "string" },
5163
+ range: { type: "string" },
5164
+ bucket: { type: "string" },
5165
+ level: { type: "string" },
5166
+ product: { type: "string" },
4809
5167
  // vibiz search pages (docs: Search)
4810
5168
  "not-indexed": { type: "boolean", default: false },
4811
5169
  "owner-email": { type: "string" },
@@ -6488,6 +6846,11 @@ ${await oneKeyLines(vibiz2, id)}`);
6488
6846
  await healthCommand(io, positionals, values);
6489
6847
  return;
6490
6848
  }
6849
+ case "dashboards":
6850
+ case "dashboard": {
6851
+ await dashboardsCommand(io, positionals, values);
6852
+ return;
6853
+ }
6491
6854
  case "replays": {
6492
6855
  if (positionals[0] === "frames") {
6493
6856
  await framesCommand(io, positionals[1], values);
@@ -7124,7 +7487,7 @@ Store the key now: it is not shown again.`
7124
7487
  return;
7125
7488
  }
7126
7489
  case "docs": {
7127
- const { DOC_TOPICS, DOCS } = await import("./src-UE373H2X.js");
7490
+ const { DOC_TOPICS, DOCS } = await import("./src-WEQ2GMQ2.js");
7128
7491
  const topic = positionals[0];
7129
7492
  if (!topic || !DOC_TOPICS.includes(topic)) {
7130
7493
  for (const t of DOC_TOPICS) io.log(` vibiz docs ${t.padEnd(13)} ${DOCS[t].title}`);
@@ -7149,7 +7512,7 @@ ${DOCS[topic].body}`);
7149
7512
  if (positionals[0])
7150
7513
  throw new Error('usage: vibiz mcp (serve over stdio) | vibiz mcp add --clients "<client>"');
7151
7514
  io.local();
7152
- const { serveStdio } = await import("./src-UE373H2X.js");
7515
+ const { serveStdio } = await import("./src-WEQ2GMQ2.js");
7153
7516
  await serveStdio({ version: cliVersion() });
7154
7517
  return;
7155
7518
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibiz/cli",
3
- "version": "0.3.20",
3
+ "version": "0.3.22",
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",