@metricraven/cli 0.2.0 → 0.3.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/README.md CHANGED
@@ -13,7 +13,7 @@ Node.js 20 or later.
13
13
 
14
14
  ## Log in
15
15
 
16
- Create an access token in **Settings → API & MCP** (https://metricraven.com/app/api), then:
16
+ Create an access token on the **API & MCP** page (https://metricraven.com/app/api), then:
17
17
 
18
18
  ```bash
19
19
  metricraven login # paste the token (hidden)
@@ -38,11 +38,13 @@ The token is saved to `~/.config/metricraven/config.json` (or `$XDG_CONFIG_HOME/
38
38
  | `analytics traffic` | Visitors, pageviews, revenue, conversion rate and top sources |
39
39
  | `analytics breakdown <dimension>` | Full table for `channel`, `referrer`, `page`, `utmSource`, `country`, `device`, … |
40
40
  | `analytics revenue` | Payments, renewals, refunds, LTV, revenue by channel |
41
+ | `analytics mrr [day\|week\|month]` | MRR over time: new, expansion, contraction, churn |
41
42
  | `analytics conversions` | Goals and funnel steps |
42
43
  | `analytics goal <name>` | One goal with its sources and properties |
43
44
  | `analytics insights` | What converts and how long buyers take |
44
45
  | `analytics search` | Google Search Console queries |
45
46
  | `analytics crawlers` | AI crawlers and bots |
47
+ | `analytics ads [campaign\|adgroup\|ad] [--provider all\|meta\|google]` | Ad spend from every connected network, attributed and assisted revenue, ROAS and cost per customer |
46
48
  | `analytics meta-ads [campaign\|adset\|ad]` | Meta Ads spend, attributed revenue, ROAS and cost per customer |
47
49
  | `realtime` | Visitors online now |
48
50
  | `visitors list`, `visitors get <id>` | Visitors and journeys (token needs visitor details access) |
@@ -53,6 +55,11 @@ The token is saved to `~/.config/metricraven/config.json` (or `$XDG_CONFIG_HOME/
53
55
  | `goals set <goal> [--name] [--color] [--description] [--hidden\|--visible]`, `goals reset <goal>` | Change how a goal is shown (needs write access, admin) |
54
56
  | `notes list`, `notes add --text [--date]` | Chart notes (adding needs write access) |
55
57
  | `mentions [--platform x\|reddit] [--q text]` | X and Reddit posts mentioning the website (Growth plan) |
58
+ | `ai-visibility` | What AI assistants answer to your tracked prompts (Growth plan); `--period` for the trend (default 90d) |
59
+ | `alerts list\|get <id>\|history`, `alerts create --goal <name>` (or `--trigger payment\|new_customer`), `alerts update <id>`, `alerts delete <id>` | Conversion alerts; `--recipients a@x.com,b@x.com\|all` picks who gets them (changes need write access) |
60
+ | `members list`, `members invite <email> --role admin\|viewer`, `members role <user_id> --role …`, `members remove <user_id>`, `members revoke <invite_id>` | The website's team (changes need write access, admin) |
61
+ | `bots settings\|usage`, `bots exclude\|include <name…> [--company]`, `bots require-token on\|off` | Bot traffic settings and the bot request allowance |
62
+ | `proxy status\|enable <subdomain>\|check\|remove` | The managed proxy subdomain that serves the script |
56
63
  | `completion bash\|zsh\|fish` | Shell completion script |
57
64
 
58
65
  Reports cover the last 30 days by default. Use `--period today|yesterday|24h|7d|30d|90d|6m|1y|wtd|mtd|all`, or `--from 2026-10-01 --to 2026-10-31`, with `--timezone Europe/Madrid` for day boundaries. `--compare year` (or a `YYYY-MM-DD` start) changes what the change figures compare against; the default is the previous period of equal length. Filter with `--filter dimension:operator:value` (repeatable; operators `is`, `is_not`, `contains`, `not_contains`, and `gt`/`lt` for `visits`, e.g. `-f visits:gt:2`).
@@ -78,6 +85,6 @@ metricraven analytics traffic -p 7d --fields overview.current,series.date,series
78
85
  metricraven analytics breakdown country --fields rows.name,rows.revenue
79
86
  ```
80
87
 
81
- Global flags: `--site <id>`, `--json`, `--verbose` (request URLs and status codes on stderr), `--help`, `--version`.
88
+ Global flags: `--site <id>`, `--json`, `--fields`, `--verbose` (request URLs and status codes on stderr), `--help`, `--version`.
82
89
 
83
90
  Full documentation: https://metricraven.com/docs/cli
package/dist/args.js CHANGED
@@ -31,6 +31,7 @@ const OPTIONS = {
31
31
  subject: { type: "string" },
32
32
  message: { type: "string" },
33
33
  notify: { type: "string" },
34
+ recipients: { type: "string" },
34
35
  enabled: { type: "boolean" },
35
36
  disabled: { type: "boolean" },
36
37
  yes: { type: "boolean", short: "y" },
package/dist/commands.js CHANGED
@@ -3,10 +3,11 @@ import { UsageError, buildFilters, positiveInt, rangeParams } from "./args.js";
3
3
  import { customRange, validTimeZone } from "./range.js";
4
4
  import { completionScript } from "./completion.js";
5
5
  import { configPath, deleteConfigToken, readConfig, resolveSettings, updateConfig } from "./config.js";
6
- import { bold, change, date, dim, duration, money, num, pct, section, table, truncate } from "./format.js";
6
+ import { bold, change, date, dim, duration, money, num, pct, section, table, terminalSafe, truncate } from "./format.js";
7
7
  import { interactive, prompt, promptHidden, readStdin } from "./prompt.js";
8
8
  export const TOKENS_URL = "https://metricraven.com/app/api";
9
- const out = (s) => process.stdout.write(`${s}\n`);
9
+ /** Every line the CLI prints; terminalSafe strips escape sequences that came from report data. */
10
+ const out = (s) => process.stdout.write(`${terminalSafe(s)}\n`);
10
11
  const printJson = (data) => out(JSON.stringify(data));
11
12
  /**
12
13
  * --fields: the API's ?fields= selection (comma-separated dot paths, period always kept). The
@@ -123,7 +124,7 @@ async function login(flags) {
123
124
  let token = flags.token?.trim();
124
125
  if (!token) {
125
126
  if (process.stdin.isTTY) {
126
- out(`Create an access token at ${bold(TOKENS_URL)} (Settings → API & MCP), then paste it here.`);
127
+ out(`Create an access token at ${bold(TOKENS_URL)} (API & MCP), then paste it here.`);
127
128
  token = await promptHidden("Token: ");
128
129
  }
129
130
  else
@@ -219,7 +220,7 @@ async function useSite({ flags, client }, id) {
219
220
  out(`Default website: ${bold(site.name)} (${id}).`);
220
221
  return 0;
221
222
  }
222
- const REPORTS = ["traffic", "revenue", "conversions", "insights", "search", "crawlers", "ads", "meta-ads"];
223
+ const REPORTS = ["traffic", "revenue", "mrr", "conversions", "insights", "search", "crawlers", "ads", "meta-ads"];
223
224
  async function analytics(ctx, sub, rest) {
224
225
  const { flags, client } = ctx;
225
226
  if (!sub)
@@ -251,6 +252,12 @@ async function analytics(ctx, sub, rest) {
251
252
  throw new UsageError("Use: metricraven analytics meta-ads [campaign|adset|ad]");
252
253
  params.set("level", rest[0]);
253
254
  }
255
+ else if (sub === "mrr") {
256
+ if (rest[0] && !["day", "week", "month"].includes(rest[0]))
257
+ throw new UsageError("Use: metricraven analytics mrr [day|week|month]");
258
+ if (rest[0])
259
+ params.set("granularity", rest[0]);
260
+ }
254
261
  else if (sub === "ads") {
255
262
  if (rest[0] && !["campaign", "adgroup", "adset", "ad"].includes(rest[0]))
256
263
  throw new UsageError("Use: metricraven analytics ads [campaign|adgroup|ad] [--provider all|meta|google]");
@@ -267,7 +274,7 @@ async function analytics(ctx, sub, rest) {
267
274
  }
268
275
  params.set("site", await ctx.site());
269
276
  const selected = selectFields(flags, params);
270
- const path = sub === "breakdown" ? "/stats/breakdown" : sub === "goal" ? "/stats/goal" : `/stats/${sub}`;
277
+ const path = sub === "breakdown" ? "/stats/breakdown" : sub === "goal" ? "/stats/goal" : sub === "mrr" ? "/stats/mrr-history" : `/stats/${sub}`;
271
278
  const data = await client.get(path, params);
272
279
  if (flags.json || selected)
273
280
  return printJson(data), 0;
@@ -376,6 +383,32 @@ const RENDER = {
376
383
  d.ltv ? section("Lifetime value", `${num(d.ltv.customers)} customers · average ${money(d.ltv.average, cur)}`) : "",
377
384
  ].join("\n");
378
385
  },
386
+ mrr(d) {
387
+ if (!d.available || !d.series || !d.summary)
388
+ return dim(d.reason ?? "No MRR history yet.");
389
+ const cur = d.currency;
390
+ const s = d.summary;
391
+ const m = (n) => (n === null ? "–" : money(n, cur));
392
+ const points = d.series.filter((p) => p.mrr !== null);
393
+ return [
394
+ periodLine(d.period),
395
+ table(["Metric", "Value"], [
396
+ ["MRR at end", `${m(s.endMrr)}${s.change !== null ? ` (${s.change > 0 ? "+" : ""}${s.change}% in period)` : ""}`],
397
+ ["MRR at start", m(s.startMrr)],
398
+ ["New", `${m(s.newMrr)} · ${num(s.newSubscriptions)} started paying`],
399
+ ["Expansion", m(s.expansionMrr)],
400
+ ["Contraction", m(s.contractionMrr)],
401
+ ["Churned", `${m(s.churnedMrr)} · ${num(s.churned)} stopped paying`],
402
+ ["Net new", m(s.netNewMrr)],
403
+ ], ["left", "right"]),
404
+ section(`MRR by ${d.period.granularity ?? "day"} (last 12)`, points.length
405
+ ? table(["Date", "MRR", "Active", "Net new", ""], points.slice(-12).map((p) => [p.date, m(p.mrr), num(p.active), m(p.netNewMrr), p.reconstructed ? dim("reconstructed") : ""]), ["left", "right", "right", "right", "left"])
406
+ : dim("No MRR recorded in this period.")),
407
+ d.demo ? dim("Sample history (demo).") : "",
408
+ ]
409
+ .filter(Boolean)
410
+ .join("\n");
411
+ },
379
412
  conversions(d) {
380
413
  // Hidden goals (Settings → Goals) stay out of the table, like the dashboard; --json has them all.
381
414
  const shown = d.goals.filter((g) => !g.hidden);
@@ -713,6 +746,22 @@ async function goals(ctx, sub, rest) {
713
746
  }
714
747
  throw new UsageError(`Unknown command "goals ${sub}". Use list, set, reset or colors.`);
715
748
  }
749
+ /**
750
+ * `--recipients a@x.com,b@x.com` (emails or user IDs), or `all` for every current member. The API
751
+ * checks each one is a member of the website.
752
+ */
753
+ function recipientsFlag(flags) {
754
+ if (flags.recipients !== undefined && flags.notify !== undefined)
755
+ throw new UsageError("Use --recipients or --notify, not both.");
756
+ if (flags.notify !== undefined)
757
+ return { notify: flags.notify };
758
+ if (flags.recipients === undefined)
759
+ return {};
760
+ const list = flags.recipients.split(",").map((r) => r.trim()).filter(Boolean);
761
+ if (!list.length)
762
+ throw new UsageError("--recipients needs member emails or user IDs, comma-separated, or all.");
763
+ return list.length === 1 && list[0].toLowerCase() === "all" ? { notify: "members" } : { recipients: list };
764
+ }
716
765
  const triggerText = (t) => (t.type === "goal" ? `goal ${t.goalName}` : t.type === "payment" ? "any payment" : "new customer");
717
766
  /** `metricraven alerts …`: conversion alerts on the website (list/get/create/update/delete/history). */
718
767
  async function alerts(ctx, sub, rest) {
@@ -746,6 +795,8 @@ async function alerts(ctx, sub, rest) {
746
795
  out(bold(a.name));
747
796
  out(`Trigger: ${triggerText(a.trigger)} · ${a.isEnabled ? "enabled" : "disabled"}`);
748
797
  out(`Recipients: ${a.recipients.map((r) => r.email).join(", ") || "none"}`);
798
+ if (a.optedOut?.length)
799
+ out(`Unsubscribed: ${a.optedOut.map((r) => r.email).join(", ")}`);
749
800
  if (a.template.subject)
750
801
  out(`Subject: ${a.template.subject}`);
751
802
  if (a.template.message)
@@ -771,7 +822,7 @@ async function alerts(ctx, sub, rest) {
771
822
  name: flags.name,
772
823
  trigger: type === "goal" ? { type, goalName: goal } : { type },
773
824
  template: flags.subject || flags.message ? { subject: flags.subject, message: flags.message } : undefined,
774
- notify: flags.notify,
825
+ ...recipientsFlag(flags),
775
826
  isEnabled: flags.disabled ? false : undefined,
776
827
  };
777
828
  const d = await needs("write", client.post("/alerts", body, params()));
@@ -788,9 +839,10 @@ async function alerts(ctx, sub, rest) {
788
839
  name: flags.name,
789
840
  trigger: flags.goal ? { type: "goal", goalName: flags.goal } : undefined,
790
841
  isEnabled: flags.enabled ? true : flags.disabled ? false : undefined,
842
+ ...recipientsFlag(flags),
791
843
  };
792
844
  if (Object.values(body).every((v) => v === undefined))
793
- throw new UsageError("Nothing to change. Use --name, --goal, --enabled or --disabled.");
845
+ throw new UsageError("Nothing to change. Use --name, --goal, --enabled, --disabled or --recipients.");
794
846
  const d = await needs("write", client.patch(alertPath(rest[0]), body, params()));
795
847
  if (flags.json)
796
848
  return printJson(d), 0;
@@ -6,7 +6,7 @@ const SUB = {
6
6
  account: ["get", "update"],
7
7
  tokens: ["list", "create", "delete"],
8
8
  payments: ["delete"],
9
- analytics: ["traffic", "breakdown", "revenue", "conversions", "goal", "insights", "search", "crawlers", "ads", "meta-ads"],
9
+ analytics: ["traffic", "breakdown", "revenue", "mrr", "conversions", "goal", "insights", "search", "crawlers", "ads", "meta-ads"],
10
10
  visitors: ["list", "get"],
11
11
  funnels: ["list"],
12
12
  goals: ["list", "set", "reset", "colors", "delete-events"],
@@ -18,7 +18,7 @@ const SUB = {
18
18
  proxy: ["status", "enable", "check", "remove"],
19
19
  completion: ["bash", "zsh", "fish"],
20
20
  };
21
- const FLAGS = ["--json", "--fields", "--site", "--token", "--verbose", "--help", "--version", "--period", "--from", "--to", "--timezone", "--filter", "--compare", "--sort", "--limit", "--offset", "--q", "--payment", "--name", "--domain", "--date", "--text", "--goal", "--trigger", "--subject", "--message", "--notify", "--enabled", "--disabled", "--yes", "--alert", "--platform", "--role", "--color", "--description", "--hidden", "--visible", "--company", "--scopes", "--sites", "--transaction", "--visitor", "--user", "--dry-run", "--page", "--page-contains", "--referrer", "--channel", "--source", "--utm-source", "--utm-medium", "--utm-campaign", "--country", "--device", "--browser", "--os", "--visits-gt", "--visits-lt", "--grace", "--provider"];
21
+ const FLAGS = ["--json", "--fields", "--site", "--token", "--verbose", "--help", "--version", "--period", "--from", "--to", "--timezone", "--filter", "--compare", "--sort", "--limit", "--offset", "--q", "--payment", "--name", "--domain", "--date", "--text", "--goal", "--trigger", "--subject", "--message", "--notify", "--recipients", "--enabled", "--disabled", "--yes", "--alert", "--platform", "--role", "--color", "--description", "--hidden", "--visible", "--company", "--scopes", "--sites", "--transaction", "--visitor", "--user", "--dry-run", "--page", "--page-contains", "--referrer", "--channel", "--source", "--utm-source", "--utm-medium", "--utm-campaign", "--country", "--device", "--browser", "--os", "--visits-gt", "--visits-lt", "--grace", "--provider"];
22
22
  export function completionScript(shell) {
23
23
  if (shell === "bash") {
24
24
  const cases = Object.entries(SUB)
package/dist/format.js CHANGED
@@ -5,6 +5,22 @@ export const dim = (s) => (color ? `\x1b[2m${s}\x1b[22m` : s);
5
5
  const green = (s) => (color ? `\x1b[32m${s}\x1b[39m` : s);
6
6
  const red = (s) => (color ? `\x1b[31m${s}\x1b[39m` : s);
7
7
  const visibleLength = (s) => s.replace(/\x1b\[[0-9;]*m/g, "").length;
8
+ /** The only escape sequences the CLI writes itself: bold, dim, green, red and their resets. */
9
+ const OWN_STYLES = new Set(["\x1b[1m", "\x1b[22m", "\x1b[2m", "\x1b[32m", "\x1b[39m", "\x1b[31m"]);
10
+ /**
11
+ * Makes text safe to print to a terminal. Reports contain strings that visitors and third parties
12
+ * choose (event properties, names, mention text); escape sequences in them could clear or fake the
13
+ * screen, retitle the window, add hidden links or write the clipboard (OSC 52). Keeps newlines,
14
+ * tabs and the CLI's own colours; other escape sequences are removed and other control characters
15
+ * shown as "�".
16
+ */
17
+ export function terminalSafe(s) {
18
+ return s
19
+ .replace(
20
+ // OSC (titles, links, clipboard) and DCS/PM/APC strings up to BEL or ST; CSI; any other escape.
21
+ /\x1b[\]P^_][\s\S]*?(?:\x07|\x1b\\|$)|\x1b\[[0-?]*[ -/]*[@-~]|\x1b[@-Z\\-_]?/g, (seq) => (OWN_STYLES.has(seq) ? seq : ""))
22
+ .replace(/[\u0000-\u0008\u000b-\u001a\u001c-\u001f\u007f-\u009f]/g, "\ufffd");
23
+ }
8
24
  export function num(n, digits = 0) {
9
25
  if (n === null || n === undefined || !Number.isFinite(n))
10
26
  return "–";
package/dist/index.js CHANGED
@@ -40,6 +40,8 @@ Reports (default: last 30 days)
40
40
  entryPage, utmSource, utmCampaign, country, city,
41
41
  browser, os, device, hostname, outbound, …
42
42
  analytics revenue Payments, renewals, refunds, LTV, revenue by channel
43
+ analytics mrr [unit] MRR over time: new, expansion, contraction, churn
44
+ (unit: day, week or month)
43
45
  analytics conversions Goals and funnel steps
44
46
  analytics goal <name> One goal in detail
45
47
  analytics insights What converts: sources, countries, time to purchase
@@ -79,9 +81,11 @@ Alerts (email when a goal, payment or new customer happens)
79
81
  alerts list Alerts on the website
80
82
  alerts get <alert_id> One alert with its counts
81
83
  alerts create --goal <name> New goal alert; or --trigger payment|new_customer
82
- [--name] [--subject] [--message] [--notify me|members]
83
- [--disabled] (needs write access)
84
+ [--name] [--subject] [--message]
85
+ [--recipients <email,email|all>] (default: you)
86
+ [--disabled] (needs write access, admin)
84
87
  alerts update <alert_id> [--name] [--goal] [--enabled | --disabled]
88
+ [--recipients <email,email|all>]
85
89
  alerts delete <alert_id> Delete an alert (asks first; --yes to skip)
86
90
  alerts history [--alert <id>] Emails the alerts sent, newest first
87
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metricraven/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "MetricRaven from your terminal: traffic, revenue, goals, visitors and websites. Built for people and AI agents.",
5
5
  "type": "module",
6
6
  "license": "MIT",