@vibiz/cli 0.3.24 → 0.3.26

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,13 +11,12 @@ import {
11
11
  formatUsd,
12
12
  mergeEnvFile,
13
13
  oneKeyMessage
14
- } from "./chunk-VV76BJPD.js";
14
+ } from "./chunk-DRJAH7ZP.js";
15
15
 
16
16
  // packages/cli/src/main.ts
17
17
  import { spawn } from "node:child_process";
18
- import { randomUUID } from "node:crypto";
19
18
  import { chmod, mkdir as mkdir2, readFile as readFile3, writeFile as writeFile3 } from "node:fs/promises";
20
- import { dirname as dirname8, join as join9 } from "node:path";
19
+ import { dirname as dirname8, join as join10 } from "node:path";
21
20
  import { format } from "node:util";
22
21
 
23
22
  // packages/cli/src/commands.ts
@@ -40,6 +39,20 @@ var VibizAppError = class extends Error {
40
39
  this.details = details;
41
40
  }
42
41
  };
42
+ function attribution() {
43
+ const w = globalThis.window;
44
+ try {
45
+ const got = w?.vibiz?.attribution?.();
46
+ if (got && typeof got === "object") return got;
47
+ const raw = globalThis.sessionStorage?.getItem("_vz_a");
48
+ if (!w || !raw) return null;
49
+ const a = JSON.parse(raw);
50
+ const page = globalThis.location?.pathname;
51
+ return { ...a, checkout_page: page ?? a.checkout_page ?? null };
52
+ } catch {
53
+ return null;
54
+ }
55
+ }
43
56
  var WEBHOOK_TOLERANCE_S = 300;
44
57
  var K = new Uint32Array([
45
58
  1116352408,
@@ -618,6 +631,11 @@ var VibizApp = class _VibizApp {
618
631
  }
619
632
  }
620
633
  };
634
+ /**
635
+ * Analytics helpers. `attribution()` runs in the browser (no key, no
636
+ * request): the tab's first-touch attribution, to send with a checkout.
637
+ */
638
+ analytics = { attribution };
621
639
  /**
622
640
  * A server-side event in the project's analytics, next to the browser's.
623
641
  * Never throws: analytics must not break the request that tracks it.
@@ -3951,9 +3969,15 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
3951
3969
  vibiz whoami the account and key this machine uses
3952
3970
  vibiz logout forget this machine's key (a browser login's key is
3953
3971
  revoked too)
3954
- vibiz feedback "<what happened>" [--kind bug|missing|confusing_error|docs|other]
3955
- [--tool <command>] [--project <id>] tell the thelastapi team: something it can't do yet,
3956
- an unclear error, wrong docs. The team reads every one
3972
+ vibiz feedback "<what you tried and what happened>" [--kind bug|missing|confusing_error|docs|other]
3973
+ [--tool <command>] [--project <id>] tell the thelastapi team, in one call, then carry on
3974
+ (the team reads every report). Send one when an error
3975
+ showed a "report" hint, thelastapi can't do something
3976
+ the task needs, an error didn't say how to fix it, you
3977
+ had to work around thelastapi, or the docs were wrong.
3978
+ Not for your own typos or validation errors you fixed,
3979
+ missing credits, or permission refusals that explained
3980
+ themselves. The last failed call is attached for you
3957
3981
  vibiz init <name> [--resources a,b|none] create a project here (default: hosting, database,
3958
3982
  auth, analytics). Any one alone works for an app on
3959
3983
  another host: --resources email, auth, ai, analytics\u2026
@@ -4165,6 +4189,11 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
4165
4189
  vibiz add <hosting|database|auth|email|analytics|replay|ai> add a resource to this project
4166
4190
  vibiz analytics [--period 24h|7d|30d] [--json] visitors, pages, sources, events
4167
4191
  vibiz analytics snippet the tag for a site hosted anywhere, and the domains it counts
4192
+ vibiz analytics visitors [--converted] [--source google.com|direct] [--landing /p] [--country ES]
4193
+ [--period 24h|7d|30d] [--goals Signup,Purchase] [--limit n] [--cursor c] [--json]
4194
+ visitor journeys: where each visitor (or buyer) came from, their path
4195
+ vibiz analytics visitor <visitor_id> [--day YYYY-MM-DD] [--json]
4196
+ one visitor's day: every page and event, replays, sales
4168
4197
  vibiz replays [--errors] [--rage] [--dead] [--path /x] [--period 7d] [--json]
4169
4198
  what went wrong for visitors, then sessions to watch
4170
4199
  vibiz replay <id> [--json] one session's signals and a link to watch it
@@ -4435,7 +4464,8 @@ var HELP = `vibiz \u2014 website, database and sign-in for a new business, in on
4435
4464
  connectors, social
4436
4465
 
4437
4466
  Env: VIBIZ_API_KEY, VIBIZ_API_URL override the saved login.
4438
- AI commands bill the account (or --project <id>); each prints what it cost.`;
4467
+ AI commands bill the account (or --project <id>); each prints what it cost.
4468
+ Something thelastapi should do, or got wrong? vibiz feedback "<what happened>": the team reads it.`;
4439
4469
  var TOKEN_ENV = {
4440
4470
  vercel: "VERCEL_TOKEN",
4441
4471
  netlify: "NETLIFY_AUTH_TOKEN",
@@ -5311,6 +5341,50 @@ function printAnalytics(io, r) {
5311
5341
  r.events.map((e) => [e.name, e.count])
5312
5342
  );
5313
5343
  }
5344
+ var fromLabel = (source) => source ?? "direct";
5345
+ function printJourneys(io, r) {
5346
+ const f = r.filters;
5347
+ const only = [
5348
+ f.converted && "converted",
5349
+ f.source && `from ${f.source}`,
5350
+ f.landing && `landing ${f.landing}`,
5351
+ f.country
5352
+ ].filter(Boolean);
5353
+ io.log(`Visitors, last ${r.period}${only.length ? ` (${only.join(", ")})` : ""}, newest first`);
5354
+ if (!r.data.length) io.log(" none");
5355
+ for (const j of r.data) {
5356
+ const sale = j.sales.length ? ` bought ${j.sales.map((p) => formatMinor(p.amount_cents, p.currency)).join(" + ")}` : j.converted ? " converted" : "";
5357
+ io.log(
5358
+ `
5359
+ ${j.started_at.slice(0, 16).replace("T", " ")} from ${fromLabel(j.source)} ${[j.country, j.device].filter(Boolean).join(" ")} ${clock(j.duration_ms)}${sale}`
5360
+ );
5361
+ io.log(` ${j.pages.map((p) => p.path).join(" \u2192 ")}`);
5362
+ if (j.custom_events.length)
5363
+ io.log(` events: ${j.custom_events.map((e) => e.name).join(", ")}`);
5364
+ io.log(` vibiz analytics visitor ${j.visitor_id} --day ${j.day}`);
5365
+ }
5366
+ if (r.next_cursor) io.log(`
5367
+ more: --cursor ${r.next_cursor}`);
5368
+ if (r.console_url) io.log(`
5369
+ ${r.console_url}`);
5370
+ }
5371
+ function printJourney(io, j) {
5372
+ io.log(
5373
+ `Visitor ${j.visitor_id} on ${j.day}: from ${fromLabel(j.source)}, landed on ${j.landing_page ?? "?"}`
5374
+ );
5375
+ io.log(
5376
+ ` ${[j.country, j.device].filter(Boolean).join(" \xB7 ")} ${j.pageviews} pages \xB7 ${j.events} events \xB7 ${clock(j.duration_ms)}${j.converted ? " \xB7 converted" : ""}`
5377
+ );
5378
+ for (const t of j.timeline) {
5379
+ const what = t.type === "pageview" ? t.path : `${t.name} (${t.path})`;
5380
+ const src = t.source ? ` \u2190 ${t.source}` : "";
5381
+ io.log(` ${t.at.slice(11, 19)} ${t.type === "pageview" ? " " : " \u2022 "}${what}${src}`);
5382
+ }
5383
+ for (const p of j.sales)
5384
+ io.log(` sale ${p.id}: ${formatMinor(p.amount_cents, p.currency)} (${p.environment})`);
5385
+ for (const r of j.replays) io.log(` replay ${r.id}: vibiz replay ${r.id}`);
5386
+ if (j.console_url) io.log(` ${j.console_url}`);
5387
+ }
5314
5388
  var clock = (ms2) => {
5315
5389
  const sec = Math.round(ms2 / 1e3);
5316
5390
  return `${Math.floor(sec / 60)}:${String(sec % 60).padStart(2, "0")}`;
@@ -5681,6 +5755,11 @@ async function runCli(argv2, io) {
5681
5755
  "max-pages": { type: "string" },
5682
5756
  action: { type: "string" },
5683
5757
  cursor: { type: "string" },
5758
+ // visitor journeys (vibiz analytics visitors | visitor <id>)
5759
+ day: { type: "string" },
5760
+ landing: { type: "string" },
5761
+ converted: { type: "boolean", default: false },
5762
+ goals: { type: "string" },
5684
5763
  page: { type: "boolean", default: false },
5685
5764
  code: { type: "boolean", default: false },
5686
5765
  db: { type: "boolean", default: false },
@@ -5759,6 +5838,9 @@ async function runCli(argv2, io) {
5759
5838
  io.log(
5760
5839
  `${values.key ? "Logged in. " : ""}Available: ${[...caps.resources, ...caps.actions].join(", ")}`
5761
5840
  );
5841
+ io.log(
5842
+ 'If thelastapi fails you or lacks something: vibiz feedback "<what happened>" (the team reads every report).'
5843
+ );
5762
5844
  return;
5763
5845
  }
5764
5846
  case "whoami": {
@@ -5794,6 +5876,11 @@ async function runCli(argv2, io) {
5794
5876
  return;
5795
5877
  }
5796
5878
  io.log(out.message);
5879
+ if (out.linked_error) {
5880
+ io.log(
5881
+ ` Linked to your last failed call: ${out.linked_error.route}${out.linked_error.code ? ` (${out.linked_error.code})` : ""}`
5882
+ );
5883
+ }
5797
5884
  return;
5798
5885
  }
5799
5886
  case "logout": {
@@ -7250,6 +7337,35 @@ ${await oneKeyLines(vibiz2, id)}`);
7250
7337
  }
7251
7338
  const period = values.period ?? "7d";
7252
7339
  if (!["24h", "7d", "30d"].includes(period)) throw new Error("--period is 24h, 7d or 30d");
7340
+ if (positionals[0] === "visitors" || positionals[0] === "journeys") {
7341
+ const goals = values.goals?.split(",").map((g) => g.trim()).filter(Boolean);
7342
+ const list2 = await (await io.client()).analytics.visitors(await io.project(), {
7343
+ period,
7344
+ ...values.source ? { source: values.source } : {},
7345
+ ...values.landing ? { landing: values.landing } : {},
7346
+ ...values.country ? { country: values.country } : {},
7347
+ ...values.converted ? { converted: true } : {},
7348
+ ...goals?.length ? { goals } : {},
7349
+ ...values.limit ? { limit: Number(values.limit) } : {},
7350
+ ...values.cursor ? { cursor: values.cursor } : {}
7351
+ });
7352
+ if (values.json) io.log(JSON.stringify(list2, null, 2));
7353
+ else printJourneys(io, list2);
7354
+ return;
7355
+ }
7356
+ if (positionals[0] === "visitor") {
7357
+ const id = positionals[1];
7358
+ if (!id)
7359
+ throw new Error(
7360
+ "Which visitor? vibiz analytics visitor <visitor_id> --day YYYY-MM-DD (ids are in vibiz analytics visitors)"
7361
+ );
7362
+ const j = await (await io.client()).analytics.visitor(await io.project(), id, {
7363
+ ...values.day ? { day: values.day } : {}
7364
+ });
7365
+ if (values.json) io.log(JSON.stringify(j, null, 2));
7366
+ else printJourney(io, j);
7367
+ return;
7368
+ }
7253
7369
  const report = await (await io.client()).analytics.get(await io.project(), { period });
7254
7370
  if (values.json) io.log(JSON.stringify(report, null, 2));
7255
7371
  else printAnalytics(io, report);
@@ -7988,7 +8104,7 @@ Store the key now: it is not shown again.`
7988
8104
  return;
7989
8105
  }
7990
8106
  case "docs": {
7991
- const { DOC_TOPICS, DOCS } = await import("./src-M73GYB5U.js");
8107
+ const { DOC_TOPICS, DOCS } = await import("./src-N4LIZWBV.js");
7992
8108
  const topic = positionals[0];
7993
8109
  if (!topic || !DOC_TOPICS.includes(topic)) {
7994
8110
  for (const t of DOC_TOPICS) io.log(` vibiz docs ${t.padEnd(13)} ${DOCS[t].title}`);
@@ -8013,7 +8129,7 @@ ${DOCS[topic].body}`);
8013
8129
  if (positionals[0])
8014
8130
  throw new Error('usage: vibiz mcp (serve over stdio) | vibiz mcp add --clients "<client>"');
8015
8131
  io.local();
8016
- const { serveStdio } = await import("./src-M73GYB5U.js");
8132
+ const { serveStdio } = await import("./src-N4LIZWBV.js");
8017
8133
  await serveStdio({ version: cliVersion() });
8018
8134
  return;
8019
8135
  }
@@ -8023,10 +8139,17 @@ ${DOCS[topic].body}`);
8023
8139
  io.log(HELP);
8024
8140
  return;
8025
8141
  default:
8026
- throw new Error(`Unknown command "${command}". Run: vibiz help`);
8142
+ throw new Error(`Unknown command "${command}". Run: vibiz help
8143
+ ${UNKNOWN_COMMAND_FEEDBACK}`);
8027
8144
  }
8028
8145
  }
8029
- function cliErrorLines(err) {
8146
+ var UNKNOWN_COMMAND_FEEDBACK = 'If thelastapi should do this, tell the team: vibiz feedback "<what you wanted to do>" --kind missing';
8147
+ function reportLine(d) {
8148
+ const r = d?.report;
8149
+ return typeof r?.message === "string" && r.message ? r.message.replace(/\s+/g, " ") : null;
8150
+ }
8151
+ function cliErrorLines(err, opts = {}) {
8152
+ const dim = opts.dim ?? ((l) => l);
8030
8153
  if (err instanceof VibizApiError && err.code === "forbidden" && /production env/.test(err.message)) {
8031
8154
  return [
8032
8155
  `\u2715 ${err.message}`,
@@ -8051,9 +8174,17 @@ function cliErrorLines(err) {
8051
8174
  }
8052
8175
  if (d?.next_step) out.push(` ${d.next_step}`);
8053
8176
  if (d?.console_url && !d.next_step?.includes(d.console_url)) out.push(` ${d.console_url}`);
8177
+ const report = reportLine(d);
8178
+ if (report) out.push(dim(` ${report}`));
8054
8179
  return out;
8055
8180
  }
8056
- return [`\u2715 ${err instanceof Error ? err.message : String(err)}`];
8181
+ const message = err instanceof Error ? err.message : String(err);
8182
+ const tail = `
8183
+ ${UNKNOWN_COMMAND_FEEDBACK}`;
8184
+ if (message.endsWith(tail)) {
8185
+ return [`\u2715 ${message.slice(0, -tail.length)}`, dim(` ${UNKNOWN_COMMAND_FEEDBACK}`)];
8186
+ }
8187
+ return [`\u2715 ${message}`];
8057
8188
  }
8058
8189
  async function aiBudgetCommand(io, args, values) {
8059
8190
  const vibiz2 = await io.client();
@@ -8348,9 +8479,40 @@ async function siteSearchCommand(io, positionals, values) {
8348
8479
  }
8349
8480
  }
8350
8481
 
8482
+ // packages/cli/src/session.ts
8483
+ import { randomUUID } from "node:crypto";
8484
+ import { mkdirSync, readFileSync as readFileSync2, renameSync, writeFileSync } from "node:fs";
8485
+ import { join as join8 } from "node:path";
8486
+ var IDLE_MS = 30 * 6e4;
8487
+ var KEEP = 50;
8488
+ function cliSessionId(o) {
8489
+ const given = o.env.VIBIZ_SESSION?.trim();
8490
+ if (given) return `cli_${given.replace(/[^A-Za-z0-9_.:-]/g, "").slice(0, 80) || randomUUID()}`;
8491
+ const now = o.now ?? Date.now();
8492
+ const file = join8(o.dir, "sessions.json");
8493
+ let store = {};
8494
+ try {
8495
+ const parsed = JSON.parse(readFileSync2(file, "utf8"));
8496
+ if (parsed && typeof parsed === "object") store = parsed;
8497
+ } catch {
8498
+ }
8499
+ const prev = store[o.cwd];
8500
+ const id = prev && typeof prev.id === "string" && now - prev.last < IDLE_MS ? prev.id : randomUUID();
8501
+ store[o.cwd] = { id, last: now };
8502
+ const kept = Object.entries(store).filter(([, v]) => v && now - v.last < IDLE_MS).sort((a, b) => b[1].last - a[1].last).slice(0, KEEP);
8503
+ try {
8504
+ mkdirSync(o.dir, { recursive: true });
8505
+ const tmp = `${file}.${process.pid}.tmp`;
8506
+ writeFileSync(tmp, JSON.stringify(Object.fromEntries(kept)), { mode: 384 });
8507
+ renameSync(tmp, file);
8508
+ } catch {
8509
+ }
8510
+ return `cli_${id}`;
8511
+ }
8512
+
8351
8513
  // packages/cli/src/update-check.ts
8352
8514
  import { mkdir, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
8353
- import { join as join8 } from "node:path";
8515
+ import { join as join9 } from "node:path";
8354
8516
  var DAY_MS = 24 * 60 * 60 * 1e3;
8355
8517
  var LATEST_URL = "https://registry.npmjs.org/@vibiz/cli/latest";
8356
8518
  function isNewer(latest, current) {
@@ -8372,7 +8534,7 @@ function updateNotice(latest, current) {
8372
8534
  }
8373
8535
  async function latestVersion(configDir, env, fetchImpl = fetch, now = Date.now()) {
8374
8536
  if (env.VIBIZ_NO_UPDATE_CHECK || env.CI) return null;
8375
- const file = join8(configDir, "update-check.json");
8537
+ const file = join9(configDir, "update-check.json");
8376
8538
  let cache = null;
8377
8539
  try {
8378
8540
  cache = JSON.parse(await readFile2(file, "utf8"));
@@ -8450,7 +8612,7 @@ function openUrl(url) {
8450
8612
  }
8451
8613
  var runCommand = commandName(process.argv.slice(2));
8452
8614
  var agentHeaders = {
8453
- "x-vibiz-session": `cli_${randomUUID()}`,
8615
+ "x-vibiz-session": cliSessionId({ dir: CONFIG_DIR, cwd: process.cwd(), env: process.env }),
8454
8616
  ...runCommand ? { "x-vibiz-tool": runCommand } : {}
8455
8617
  };
8456
8618
  var CLIENT = `vibiz-cli/${cliVersion()}`;
@@ -8479,7 +8641,7 @@ var terminal = {
8479
8641
  },
8480
8642
  project: async () => {
8481
8643
  for (let dir = process.cwd(); ; dir = dirname8(dir)) {
8482
- const linked = await readJson2(join9(dir, PROJECT_FILE));
8644
+ const linked = await readJson2(join10(dir, PROJECT_FILE));
8483
8645
  if (linked?.project_id) return linked.project_id;
8484
8646
  if (dirname8(dir) === dir) break;
8485
8647
  }
@@ -8550,7 +8712,8 @@ if (argv[0] === "--version" || argv[0] === "-v") {
8550
8712
  ${text2}`);
8551
8713
  };
8552
8714
  runCli(argv, terminal).then(notice).catch(async (err) => {
8553
- for (const line2 of cliErrorLines(err)) console.error(line2);
8715
+ const dim = process.stderr.isTTY && !process.env.NO_COLOR ? (l) => `\x1B[2m${l}\x1B[22m` : void 0;
8716
+ for (const line2 of cliErrorLines(err, dim ? { dim } : {})) console.error(line2);
8554
8717
  if (err instanceof VibizApiError && err.grantUrl && process.stdin.isTTY && process.stdout.isTTY)
8555
8718
  openUrl(err.grantUrl);
8556
8719
  await notice();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibiz/cli",
3
- "version": "0.3.24",
3
+ "version": "0.3.26",
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",