@metricraven/cli 0.5.1 → 0.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/README.md +3 -2
- package/dist/args.js +6 -0
- package/dist/commands.js +274 -14
- package/dist/completion.js +28 -2
- package/dist/index.js +32 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,9 +68,10 @@ The token is saved to `~/.config/metricraven/config.json` (or `$XDG_CONFIG_HOME/
|
|
|
68
68
|
| `goals definitions`, `goals preview --page <path> \| --link <site> [--link-path <path>] \| --click <text> \| --form <id> \| --download <file>` | Goals defined without code, and how many visitors (and payers) a pattern matched in the last 30 days. `--click`, `--form` and `--download` match [automatic events](https://metricraven.com/docs/automatic-events) (a button text in any letter case, a form id or name, a file name or `.pdf` for any PDF) |
|
|
69
69
|
| `goals define <name> --page /pricing \| --link stripe.com [--link-path /checkout/**] \| --click "Start free trial" \| --form signup \| --download .pdf`, `goals undefine <name>` | Create a goal without code (previews, then asks; `--yes`) or delete one (says which alerts, funnels or primary goal still use it); needs write access |
|
|
70
70
|
| `notes list`, `notes add --text [--date]` | Chart notes (adding needs write access) |
|
|
71
|
-
| `mentions [--platform x\|reddit] [--q text]` |
|
|
71
|
+
| `mentions [--platform x\|reddit\|web\|youtube\|linkedin\|threads\|tiktok\|instagram\|facebook\|pinterest] [--q text]` | Posts mentioning the website on every platform, with the visits and revenue after posts that link to it (Growth plan) |
|
|
72
72
|
| `ai-visibility` | What AI assistants answer to your tracked prompts (Growth plan); `--period` for the trend (default 90d) |
|
|
73
|
-
| `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) |
|
|
73
|
+
| `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, `--channel <id,id>` also posts to alert channels (changes need write access) |
|
|
74
|
+
| `alerts channels list\|get <id>`, `alerts channels add slack\|discord\|webhook --url <URL> [--spikes] [--weekly] [--monthly]`, `alerts channels add telegram`, `alerts channels update\|test\|rotate-secret\|reconnect\|remove <id>` | Alert channels: Slack, Discord, Telegram (prints the connect links) and signed webhooks (prints the signing secret once). Destinations are shown masked; remove and rotate-secret ask first (`--yes`). Changes need write access, admin |
|
|
74
75
|
| `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) |
|
|
75
76
|
| `bots settings\|usage`, `bots settings --verified-only on\|off`, `bots settings --datacenter on\|off`, `bots exclude\|include <name…> [--company]`, `bots require-token on\|off` | Bot traffic settings (`--verified-only on` records only IP-verified crawlers; `--datacenter on`, the default, doesn't count tracker hits from cloud and hosting networks) and the bot request allowance |
|
|
76
77
|
| `proxy status\|enable <subdomain>\|check\|remove` | The managed proxy subdomain that serves the script |
|
package/dist/args.js
CHANGED
|
@@ -110,6 +110,12 @@ const OPTIONS = {
|
|
|
110
110
|
disabled: { type: "boolean" },
|
|
111
111
|
yes: { type: "boolean", short: "y" },
|
|
112
112
|
alert: { type: "string" },
|
|
113
|
+
// alerts channels add|update: the webhook URL and the site-wide notifications it gets
|
|
114
|
+
url: { type: "string" },
|
|
115
|
+
spikes: { type: "boolean" },
|
|
116
|
+
weekly: { type: "boolean" },
|
|
117
|
+
monthly: { type: "boolean" },
|
|
118
|
+
events: { type: "string" },
|
|
113
119
|
role: { type: "string" },
|
|
114
120
|
color: { type: "string" },
|
|
115
121
|
description: { type: "string" },
|
package/dist/commands.js
CHANGED
|
@@ -1170,13 +1170,26 @@ async function addNote(ctx) {
|
|
|
1170
1170
|
out(`Added a note on ${note.date}: ${note.text}`);
|
|
1171
1171
|
return 0;
|
|
1172
1172
|
}
|
|
1173
|
-
|
|
1173
|
+
const MENTION_PLATFORMS = ["x", "reddit", "web", "youtube", "linkedin", "threads", "tiktok", "instagram", "facebook", "pinterest"];
|
|
1174
|
+
const MENTION_LABEL = {
|
|
1175
|
+
x: "X",
|
|
1176
|
+
reddit: "Reddit",
|
|
1177
|
+
web: "Web",
|
|
1178
|
+
youtube: "YouTube",
|
|
1179
|
+
linkedin: "LinkedIn",
|
|
1180
|
+
threads: "Threads",
|
|
1181
|
+
tiktok: "TikTok",
|
|
1182
|
+
instagram: "Instagram",
|
|
1183
|
+
facebook: "Facebook",
|
|
1184
|
+
pinterest: "Pinterest",
|
|
1185
|
+
};
|
|
1186
|
+
/** Stored mentions on every platform in the period (newest first). Reads only; never starts a search. */
|
|
1174
1187
|
async function listMentions(ctx) {
|
|
1175
1188
|
const { flags } = ctx;
|
|
1176
1189
|
const params = rangeParams({ ...flags, filter: undefined });
|
|
1177
1190
|
if (flags.platform) {
|
|
1178
|
-
if (
|
|
1179
|
-
throw new UsageError(
|
|
1191
|
+
if (!MENTION_PLATFORMS.includes(flags.platform))
|
|
1192
|
+
throw new UsageError(`--platform must be one of ${MENTION_PLATFORMS.join(", ")}.`);
|
|
1180
1193
|
params.set("platform", flags.platform);
|
|
1181
1194
|
}
|
|
1182
1195
|
if (flags.q)
|
|
@@ -1192,15 +1205,28 @@ async function listMentions(ctx) {
|
|
|
1192
1205
|
if (flags.json)
|
|
1193
1206
|
return printJson(d), 0;
|
|
1194
1207
|
if (d.meta.locked)
|
|
1195
|
-
return out(d.meta.message ?? "
|
|
1208
|
+
return out(d.meta.message ?? "Social mentions need the Growth plan."), 0;
|
|
1196
1209
|
if (!d.data.length)
|
|
1197
1210
|
return out(dim("No mentions in this period.")), 0;
|
|
1198
|
-
const where = (m) =>
|
|
1211
|
+
const where = (m) => m.platform === "x"
|
|
1212
|
+
? `X @${m.author.username}`
|
|
1213
|
+
: m.platform === "reddit"
|
|
1214
|
+
? `r/${m.subreddit ?? "?"} u/${m.author.username}`
|
|
1215
|
+
: m.platform === "web"
|
|
1216
|
+
? m.author.name
|
|
1217
|
+
: `${MENTION_LABEL[m.platform] ?? m.platform} ${m.author.username ? `@${m.author.username}` : m.author.name}`;
|
|
1218
|
+
const e = (m) => m.engagement;
|
|
1199
1219
|
const stats = (m) => m.platform === "x"
|
|
1200
|
-
? `${num(m.
|
|
1201
|
-
:
|
|
1202
|
-
|
|
1203
|
-
|
|
1220
|
+
? `${num(e(m).likes ?? 0)} likes · ${num(e(m).reposts ?? 0)} reposts`
|
|
1221
|
+
: m.platform === "reddit"
|
|
1222
|
+
? `${num(e(m).score ?? 0)} pts · ${num(e(m).comments ?? 0)} comments`
|
|
1223
|
+
: [e(m).views != null ? `${num(e(m).views)} views` : "", e(m).likes != null ? `${num(e(m).likes)} likes` : "", e(m).comments != null ? `${num(e(m).comments)} comments` : ""]
|
|
1224
|
+
.filter(Boolean)
|
|
1225
|
+
.join(" · ") || "-";
|
|
1226
|
+
// Visits and first-touch revenue from the page's host or the platform after a post that links to the site.
|
|
1227
|
+
const traffic = (m) => (m.traffic ? `${num(m.traffic.visitors)} visitors · ${money(m.traffic.revenue, d.meta.currency)}` : "-");
|
|
1228
|
+
const body = (m) => truncate(`${m.title ? `${m.title}: ` : ""}${m.text}`.replace(/\s+/g, " ").trim(), 60);
|
|
1229
|
+
out(table(["Date", "Where", "Post", "Engagement", "After the post"], d.data.map((m) => [date(m.timestamp), where(m), body(m), stats(m), traffic(m)])));
|
|
1204
1230
|
if (d.pagination.hasMore)
|
|
1205
1231
|
out(dim(`Showing ${d.pagination.offset + 1}–${d.pagination.offset + d.data.length} of ${d.pagination.total}. Use --offset for more.`));
|
|
1206
1232
|
return 0;
|
|
@@ -1458,6 +1484,31 @@ function recipientsFlag(flags) {
|
|
|
1458
1484
|
throw new UsageError("--recipients needs member emails or user IDs, comma-separated, or all.");
|
|
1459
1485
|
return list.length === 1 && list[0].toLowerCase() === "all" ? { notify: "members" } : { recipients: list };
|
|
1460
1486
|
}
|
|
1487
|
+
/**
|
|
1488
|
+
* `--channel <id,id>`: the alert channels it posts to (replaces the list), or `none` to stop
|
|
1489
|
+
* posting to channels. IDs come from `metricraven alerts channels list`.
|
|
1490
|
+
*/
|
|
1491
|
+
function channelsFlag(flags) {
|
|
1492
|
+
if (flags.channel === undefined)
|
|
1493
|
+
return {};
|
|
1494
|
+
const list = flags.channel.split(",").map((c) => c.trim()).filter(Boolean);
|
|
1495
|
+
if (list.length === 1 && list[0].toLowerCase() === "none")
|
|
1496
|
+
return { channels: [] };
|
|
1497
|
+
if (!list.length)
|
|
1498
|
+
throw new UsageError("--channel needs channel IDs, comma-separated (from `metricraven alerts channels list`), or none.");
|
|
1499
|
+
return { channels: list };
|
|
1500
|
+
}
|
|
1501
|
+
const channelCount = (a) => a.channelIds?.length ?? 0;
|
|
1502
|
+
/** Who an alert reaches: its recipients' emails and how many channels. */
|
|
1503
|
+
function audience(a) {
|
|
1504
|
+
const emails = a.recipients.map((r) => r.email).join(", ");
|
|
1505
|
+
const channels = channelCount(a) ? `${num(channelCount(a))} ${plural("channels", channelCount(a))}` : "";
|
|
1506
|
+
if (emails && channels)
|
|
1507
|
+
return `emailing ${emails} and posting to ${channels}`;
|
|
1508
|
+
if (channels)
|
|
1509
|
+
return `posting to ${channels}`;
|
|
1510
|
+
return `emailing ${emails || "nobody yet"}`;
|
|
1511
|
+
}
|
|
1461
1512
|
const triggerText = (t) => (t.type === "goal" ? `goal ${t.goalName}` : t.type === "payment" ? "any payment" : "new customer");
|
|
1462
1513
|
/** `metricraven alerts …`: conversion alerts on the website (list/get/create/update/delete/history). */
|
|
1463
1514
|
async function alerts(ctx, sub, rest) {
|
|
@@ -1469,6 +1520,8 @@ async function alerts(ctx, sub, rest) {
|
|
|
1469
1520
|
throw new UsageError(`Use: metricraven alerts ${sub} <alert_id> (IDs from \`metricraven alerts list\`).`);
|
|
1470
1521
|
return `/alerts/${encodeURIComponent(id)}`;
|
|
1471
1522
|
};
|
|
1523
|
+
if (sub === "channels")
|
|
1524
|
+
return alertChannels(ctx, site, rest[0], rest.slice(1));
|
|
1472
1525
|
switch (sub ?? "list") {
|
|
1473
1526
|
case "list": {
|
|
1474
1527
|
const d = await client.get("/alerts", params());
|
|
@@ -1480,7 +1533,7 @@ async function alerts(ctx, sub, rest) {
|
|
|
1480
1533
|
out(dim(`Tracked goals: ${d.goals.slice(0, 12).join(", ")}`));
|
|
1481
1534
|
return 0;
|
|
1482
1535
|
}
|
|
1483
|
-
out(table(["Alert", "Trigger", "On", "Recipients", "Today", "Total", "ID"], d.data.map((a) => [a.name, triggerText(a.trigger), a.isEnabled ? "yes" : "no", String(a.recipients.length), num(a.dailyCount), num(a.triggerCount), a.id])));
|
|
1536
|
+
out(table(["Alert", "Trigger", "On", "Recipients", "Channels", "Today", "Total", "ID"], d.data.map((a) => [a.name, triggerText(a.trigger), a.isEnabled ? "yes" : "no", String(a.recipients.length), String(channelCount(a)), num(a.dailyCount), num(a.triggerCount), a.id])));
|
|
1484
1537
|
return 0;
|
|
1485
1538
|
}
|
|
1486
1539
|
case "get": {
|
|
@@ -1491,6 +1544,8 @@ async function alerts(ctx, sub, rest) {
|
|
|
1491
1544
|
out(bold(a.name));
|
|
1492
1545
|
out(`Trigger: ${triggerText(a.trigger)} · ${a.isEnabled ? "enabled" : "disabled"}`);
|
|
1493
1546
|
out(`Recipients: ${a.recipients.map((r) => r.email).join(", ") || "none"}`);
|
|
1547
|
+
if (channelCount(a))
|
|
1548
|
+
out(`Channels: ${a.channelIds.join(", ")}`);
|
|
1494
1549
|
if (a.optedOut?.length)
|
|
1495
1550
|
out(`Unsubscribed: ${a.optedOut.map((r) => r.email).join(", ")}`);
|
|
1496
1551
|
if (a.template.subject)
|
|
@@ -1519,13 +1574,14 @@ async function alerts(ctx, sub, rest) {
|
|
|
1519
1574
|
trigger: type === "goal" ? { type, goalName: goal } : { type },
|
|
1520
1575
|
template: flags.subject || flags.message ? { subject: flags.subject, message: flags.message } : undefined,
|
|
1521
1576
|
...recipientsFlag(flags),
|
|
1577
|
+
...channelsFlag(flags),
|
|
1522
1578
|
isEnabled: flags.disabled ? false : undefined,
|
|
1523
1579
|
};
|
|
1524
1580
|
const d = await needs("write", client.post("/alerts", body, params()));
|
|
1525
1581
|
if (flags.json)
|
|
1526
1582
|
return printJson(d), 0;
|
|
1527
1583
|
const a = d.data[0];
|
|
1528
|
-
out(`Created "${a.name}" (${triggerText(a.trigger)}), ${a.isEnabled ? "enabled" : "disabled"},
|
|
1584
|
+
out(`Created "${a.name}" (${triggerText(a.trigger)}), ${a.isEnabled ? "enabled" : "disabled"}, ${audience(a)}. ID ${a.id}`);
|
|
1529
1585
|
return 0;
|
|
1530
1586
|
}
|
|
1531
1587
|
case "update": {
|
|
@@ -1536,14 +1592,15 @@ async function alerts(ctx, sub, rest) {
|
|
|
1536
1592
|
trigger: flags.goal ? { type: "goal", goalName: flags.goal } : undefined,
|
|
1537
1593
|
isEnabled: flags.enabled ? true : flags.disabled ? false : undefined,
|
|
1538
1594
|
...recipientsFlag(flags),
|
|
1595
|
+
...channelsFlag(flags),
|
|
1539
1596
|
};
|
|
1540
1597
|
if (Object.values(body).every((v) => v === undefined))
|
|
1541
|
-
throw new UsageError("Nothing to change. Use --name, --goal, --enabled, --disabled or --
|
|
1598
|
+
throw new UsageError("Nothing to change. Use --name, --goal, --enabled, --disabled, --recipients or --channel.");
|
|
1542
1599
|
const d = await needs("write", client.patch(alertPath(rest[0]), body, params()));
|
|
1543
1600
|
if (flags.json)
|
|
1544
1601
|
return printJson(d), 0;
|
|
1545
1602
|
const a = d.data[0];
|
|
1546
|
-
out(`Updated "${a.name}" (${triggerText(a.trigger)}), ${a.isEnabled ? "enabled" : "disabled"}.`);
|
|
1603
|
+
out(`Updated "${a.name}" (${triggerText(a.trigger)}), ${a.isEnabled ? "enabled" : "disabled"}, ${audience(a)}.`);
|
|
1547
1604
|
return 0;
|
|
1548
1605
|
}
|
|
1549
1606
|
case "delete": {
|
|
@@ -1578,7 +1635,210 @@ async function alerts(ctx, sub, rest) {
|
|
|
1578
1635
|
return 0;
|
|
1579
1636
|
}
|
|
1580
1637
|
}
|
|
1581
|
-
throw new UsageError(`Unknown command "alerts ${sub}". Use list, get, create, update, delete or
|
|
1638
|
+
throw new UsageError(`Unknown command "alerts ${sub}". Use list, get, create, update, delete, history or channels.`);
|
|
1639
|
+
}
|
|
1640
|
+
const CHANNEL_TYPES = ["slack", "discord", "telegram", "webhook"];
|
|
1641
|
+
const CHANNEL_LABEL = { slack: "Slack", discord: "Discord", telegram: "Telegram", webhook: "Webhook" };
|
|
1642
|
+
const EVENT_NAMES = { spikes: "spike", weekly: "weeklyReport", monthly: "monthlyReport" };
|
|
1643
|
+
const eventsText = (e) => Object.entries(EVENT_NAMES)
|
|
1644
|
+
.filter(([, key]) => e[key])
|
|
1645
|
+
.map(([name]) => name)
|
|
1646
|
+
.join(", ") || "–";
|
|
1647
|
+
const channelLabel = (t) => CHANNEL_LABEL[t] ?? t;
|
|
1648
|
+
const destination = (c) => (c.status === "pending" ? "waiting for a chat" : c.target);
|
|
1649
|
+
/**
|
|
1650
|
+
* Spike alerts and weekly/monthly reports for a channel: --spikes, --weekly and --monthly switch
|
|
1651
|
+
* them on; --events spikes,weekly|none sets the whole list (on update, the others go off).
|
|
1652
|
+
*/
|
|
1653
|
+
function channelEvents(flags) {
|
|
1654
|
+
const picked = { spike: flags.spikes, weeklyReport: flags.weekly, monthlyReport: flags.monthly };
|
|
1655
|
+
const on = Object.entries(picked).filter(([, value]) => value);
|
|
1656
|
+
if (flags.events === undefined)
|
|
1657
|
+
return on.length ? Object.fromEntries(on.map(([key]) => [key, true])) : undefined;
|
|
1658
|
+
if (on.length)
|
|
1659
|
+
throw new UsageError("Use --events, or --spikes/--weekly/--monthly, not both.");
|
|
1660
|
+
const names = flags.events.split(",").map((e) => e.trim().toLowerCase()).filter(Boolean);
|
|
1661
|
+
const none = names.length === 1 && names[0] === "none";
|
|
1662
|
+
if (!names.length || (!none && names.some((n) => !EVENT_NAMES[n])))
|
|
1663
|
+
throw new UsageError("--events takes spikes, weekly and monthly, comma-separated, or none.");
|
|
1664
|
+
return { spike: names.includes("spikes"), weeklyReport: names.includes("weekly"), monthlyReport: names.includes("monthly") };
|
|
1665
|
+
}
|
|
1666
|
+
/** --timezone on a channel: the zone its weekly and monthly reports use. */
|
|
1667
|
+
function channelTimeZone(flags) {
|
|
1668
|
+
if (flags.timezone === undefined)
|
|
1669
|
+
return {};
|
|
1670
|
+
const zone = validTimeZone(flags.timezone);
|
|
1671
|
+
if (!zone)
|
|
1672
|
+
throw new UsageError(`Unknown timezone "${flags.timezone}". Use an IANA name like America/New_York.`);
|
|
1673
|
+
return { timeZone: zone };
|
|
1674
|
+
}
|
|
1675
|
+
/** Writes need write access; a 503 channel_unavailable means this server can't add that type. */
|
|
1676
|
+
async function channelWrite(request) {
|
|
1677
|
+
try {
|
|
1678
|
+
return await needs("write", request);
|
|
1679
|
+
}
|
|
1680
|
+
catch (error) {
|
|
1681
|
+
if (error instanceof ApiError && error.code === "channel_unavailable")
|
|
1682
|
+
throw new ApiError("This server can't add that kind of channel right now. `metricraven alerts channels list` shows the types it can add.", error.status, error.code);
|
|
1683
|
+
throw error;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* `metricraven alerts channels …`: where alerts go besides email (Slack, Discord, Telegram, signed
|
|
1688
|
+
* webhooks). Destinations are never printed in full: the API only returns a masked target.
|
|
1689
|
+
*/
|
|
1690
|
+
async function alertChannels(ctx, site, sub, rest) {
|
|
1691
|
+
const { flags, client } = ctx;
|
|
1692
|
+
const params = () => new URLSearchParams({ site });
|
|
1693
|
+
const channelPath = (id, suffix = "") => {
|
|
1694
|
+
if (!id)
|
|
1695
|
+
throw new UsageError(`Use: metricraven alerts channels ${sub} <channel_id> (IDs from \`metricraven alerts channels list\`).`);
|
|
1696
|
+
return `/alerts/channels/${encodeURIComponent(id)}${suffix}`;
|
|
1697
|
+
};
|
|
1698
|
+
const confirm = async (question) => {
|
|
1699
|
+
if (flags.yes)
|
|
1700
|
+
return true;
|
|
1701
|
+
if (!interactive() || flags.json)
|
|
1702
|
+
throw new UsageError("Add --yes to do this without a prompt.");
|
|
1703
|
+
return /^y(es)?$/i.test(await prompt(`${question} [y/N] `));
|
|
1704
|
+
};
|
|
1705
|
+
const describe = (c) => `${channelLabel(c.type)} channel "${c.name}" (${destination(c)})`;
|
|
1706
|
+
const showLinks = (c, s) => {
|
|
1707
|
+
out("Open a link in Telegram and press Start to connect a chat:");
|
|
1708
|
+
out(` Private chat: ${s.connectUrl}`);
|
|
1709
|
+
if (s.groupConnectUrl)
|
|
1710
|
+
out(` Group: ${s.groupConnectUrl}`);
|
|
1711
|
+
out(dim(`${c.connectExpiresAt ? `The links stop working ${date(c.connectExpiresAt)}. ` : ""}New links: metricraven alerts channels reconnect ${c.id}`));
|
|
1712
|
+
};
|
|
1713
|
+
const showSecret = (c, secret) => {
|
|
1714
|
+
out(`Signing secret for "${c.name}" (${c.id}): ${secret}`);
|
|
1715
|
+
out(dim("Shown once. Check the X-MetricRaven-Signature header with it: https://metricraven.com/docs/webhooks"));
|
|
1716
|
+
};
|
|
1717
|
+
switch (sub ?? "list") {
|
|
1718
|
+
case "list": {
|
|
1719
|
+
const d = await client.get("/alerts/channels", params());
|
|
1720
|
+
if (flags.json)
|
|
1721
|
+
return printJson(d), 0;
|
|
1722
|
+
if (!d.data.length)
|
|
1723
|
+
out(dim("No alert channels yet. Add one with `metricraven alerts channels add slack --url <webhook URL>`."));
|
|
1724
|
+
else
|
|
1725
|
+
out(table(["Channel", "Type", "Destination", "Also gets", "Alerts", "Last sent", "ID"], d.data.map((c) => [
|
|
1726
|
+
c.lastError ? `${c.name} (failing)` : c.name,
|
|
1727
|
+
channelLabel(c.type),
|
|
1728
|
+
destination(c),
|
|
1729
|
+
eventsText(c.events),
|
|
1730
|
+
num(c.alertCount),
|
|
1731
|
+
c.lastDeliveredAt ? date(c.lastDeliveredAt) : "never",
|
|
1732
|
+
c.id,
|
|
1733
|
+
])));
|
|
1734
|
+
const missing = CHANNEL_TYPES.filter((t) => !d.available.includes(t));
|
|
1735
|
+
const note = !d.available.length ? " This server can't add channels right now." : missing.length ? ` This server can't add ${missing.map(channelLabel).join(" or ")} channels.` : "";
|
|
1736
|
+
out(dim(`${num(d.data.length)} of ${num(d.limit)} channels.${note}`));
|
|
1737
|
+
return 0;
|
|
1738
|
+
}
|
|
1739
|
+
case "get": {
|
|
1740
|
+
const d = await client.get(channelPath(rest[0]), params());
|
|
1741
|
+
if (flags.json)
|
|
1742
|
+
return printJson(d), 0;
|
|
1743
|
+
const c = d.data[0];
|
|
1744
|
+
out(bold(c.name));
|
|
1745
|
+
out(`Type: ${channelLabel(c.type)} · ${c.status === "pending" ? "waiting for a chat" : "active"}`);
|
|
1746
|
+
if (c.status === "active")
|
|
1747
|
+
out(`Destination: ${c.target}${c.chatType ? ` (${c.chatType})` : ""}`);
|
|
1748
|
+
out(`Also gets: ${eventsText(c.events)} · reports in ${c.timeZone}`);
|
|
1749
|
+
out(`Used by ${num(c.alertCount)} ${plural("alerts", c.alertCount)}`);
|
|
1750
|
+
out(dim(c.lastDeliveredAt ? `Last sent ${date(c.lastDeliveredAt)}` : "Nothing sent yet"));
|
|
1751
|
+
if (c.lastError)
|
|
1752
|
+
out(`Last error: ${c.lastError}`);
|
|
1753
|
+
return 0;
|
|
1754
|
+
}
|
|
1755
|
+
case "add":
|
|
1756
|
+
case "create": {
|
|
1757
|
+
const type = (rest[0] ?? flags.type)?.toLowerCase();
|
|
1758
|
+
if (!type || !CHANNEL_TYPES.includes(type))
|
|
1759
|
+
throw new UsageError("Use: metricraven alerts channels add slack|discord|webhook --url <URL>, or add telegram.");
|
|
1760
|
+
let url = flags.url?.trim();
|
|
1761
|
+
if (type === "telegram") {
|
|
1762
|
+
if (url)
|
|
1763
|
+
throw new UsageError("Telegram channels connect with a link, not a URL. Leave out --url.");
|
|
1764
|
+
}
|
|
1765
|
+
else if (!url) {
|
|
1766
|
+
if (!interactive() || flags.json)
|
|
1767
|
+
throw new UsageError(`Use: metricraven alerts channels add ${type} --url <URL>`);
|
|
1768
|
+
url = (await promptHidden(`${channelLabel(type)} webhook URL: `)).trim();
|
|
1769
|
+
if (!url)
|
|
1770
|
+
throw new UsageError("No URL given.");
|
|
1771
|
+
}
|
|
1772
|
+
const body = { type, name: flags.name, url, events: channelEvents(flags), ...channelTimeZone(flags) };
|
|
1773
|
+
const d = await channelWrite(client.post("/alerts/channels", body, params()));
|
|
1774
|
+
if (flags.json)
|
|
1775
|
+
return printJson(d), 0;
|
|
1776
|
+
const c = d.data[0];
|
|
1777
|
+
out(`Added ${describe(c)}. ID ${c.id}`);
|
|
1778
|
+
if (d.signingSecret)
|
|
1779
|
+
showSecret(c, d.signingSecret);
|
|
1780
|
+
if (d.connectUrl)
|
|
1781
|
+
showLinks(c, d);
|
|
1782
|
+
if (c.status === "active")
|
|
1783
|
+
out(dim(`Send a test: metricraven alerts channels test ${c.id} · Post an alert there: metricraven alerts update <alert_id> --channel ${c.id}`));
|
|
1784
|
+
return 0;
|
|
1785
|
+
}
|
|
1786
|
+
case "update": {
|
|
1787
|
+
const path = channelPath(rest[0]);
|
|
1788
|
+
const body = { name: flags.name, url: flags.url?.trim() || undefined, events: channelEvents(flags), ...channelTimeZone(flags) };
|
|
1789
|
+
if (Object.values(body).every((v) => v === undefined))
|
|
1790
|
+
throw new UsageError("Nothing to change. Use --name, --url, --events (or --spikes, --weekly, --monthly) or --timezone.");
|
|
1791
|
+
const d = await channelWrite(client.patch(path, body, params()));
|
|
1792
|
+
if (flags.json)
|
|
1793
|
+
return printJson(d), 0;
|
|
1794
|
+
const c = d.data[0];
|
|
1795
|
+
out(`Updated ${describe(c)}. Also gets: ${eventsText(c.events)}.`);
|
|
1796
|
+
return 0;
|
|
1797
|
+
}
|
|
1798
|
+
case "test": {
|
|
1799
|
+
const d = await needs("write", client.post(channelPath(rest[0], "/test"), {}, params()));
|
|
1800
|
+
if (flags.json)
|
|
1801
|
+
return printJson(d), d.data.sent ? 0 : 1;
|
|
1802
|
+
const name = d.channel ? `"${d.channel.name}"` : rest[0];
|
|
1803
|
+
if (d.data.sent)
|
|
1804
|
+
return out(`Sent a test message to ${name}.`), 0;
|
|
1805
|
+
out(`The test message to ${name} failed: ${d.data.error ?? "unknown error"}`);
|
|
1806
|
+
return 1;
|
|
1807
|
+
}
|
|
1808
|
+
case "rotate-secret": {
|
|
1809
|
+
const path = channelPath(rest[0]);
|
|
1810
|
+
if (!(await confirm(`Rotate the signing secret of channel ${rest[0]}? The current secret stops working at once.`)))
|
|
1811
|
+
return out("Kept."), 0;
|
|
1812
|
+
const d = await needs("write", client.patch(path, { rotateSecret: true }, params()));
|
|
1813
|
+
if (flags.json)
|
|
1814
|
+
return printJson(d), 0;
|
|
1815
|
+
if (!d.signingSecret)
|
|
1816
|
+
throw new UsageError("Only webhook channels have a signing secret.");
|
|
1817
|
+
showSecret(d.data[0], d.signingSecret);
|
|
1818
|
+
return 0;
|
|
1819
|
+
}
|
|
1820
|
+
case "reconnect": {
|
|
1821
|
+
const d = await channelWrite(client.patch(channelPath(rest[0]), { reconnect: true }, params()));
|
|
1822
|
+
if (flags.json)
|
|
1823
|
+
return printJson(d), 0;
|
|
1824
|
+
if (!d.connectUrl)
|
|
1825
|
+
throw new UsageError("Only Telegram channels connect with a link.");
|
|
1826
|
+
showLinks(d.data[0], d);
|
|
1827
|
+
return 0;
|
|
1828
|
+
}
|
|
1829
|
+
case "remove":
|
|
1830
|
+
case "delete": {
|
|
1831
|
+
const path = channelPath(rest[0]);
|
|
1832
|
+
if (!(await confirm(`Remove channel ${rest[0]}? Alerts stop posting there; past deliveries stay in the history.`)))
|
|
1833
|
+
return out("Kept."), 0;
|
|
1834
|
+
const d = await needs("write", client.del(path, params()));
|
|
1835
|
+
if (flags.json)
|
|
1836
|
+
return printJson(d), 0;
|
|
1837
|
+
out(`Removed channel ${d.data.id}.`);
|
|
1838
|
+
return 0;
|
|
1839
|
+
}
|
|
1840
|
+
}
|
|
1841
|
+
throw new UsageError(`Unknown command "alerts channels ${sub}". Use list, get, add, update, test, rotate-secret, reconnect or remove.`);
|
|
1582
1842
|
}
|
|
1583
1843
|
/** `metricraven members …`: the website's team (list/invite/role/remove/revoke). Ownership transfer stays in the dashboard. */
|
|
1584
1844
|
async function members(ctx, sub, rest) {
|
package/dist/completion.js
CHANGED
|
@@ -17,13 +17,18 @@ const SUB = {
|
|
|
17
17
|
goals: ["list", "set", "reset", "colors", "definitions", "preview", "define", "undefine", "delete-events"],
|
|
18
18
|
notes: ["list", "add"],
|
|
19
19
|
mentions: ["list"],
|
|
20
|
-
alerts: ["list", "get", "create", "update", "delete", "history"],
|
|
20
|
+
alerts: ["list", "get", "create", "update", "delete", "history", "channels"],
|
|
21
21
|
members: ["list", "invite", "role", "remove", "revoke"],
|
|
22
22
|
bots: ["settings", "usage", "exclude", "include", "require-token"],
|
|
23
23
|
proxy: ["status", "enable", "check", "remove"],
|
|
24
24
|
completion: ["bash", "zsh", "fish"],
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
/** Commands with their own subcommands, completed after the second word. */
|
|
27
|
+
const NESTED = {
|
|
28
|
+
"alerts channels": ["list", "get", "add", "update", "test", "rotate-secret", "reconnect", "remove"],
|
|
29
|
+
"websites keys": ["list", "create", "rename", "revoke", "roll"],
|
|
30
|
+
};
|
|
31
|
+
const FLAGS = ["--json", "--fields", "--site", "--token", "--verbose", "--help", "--version", "--period", "--from", "--to", "--timezone", "--filter", "--compare", "--sort", "--limit", "--offset", "--q", "--param", "--attribution", "--group", "--folder", "--include", "--drop-step", "--path", "--payment", "--name", "--domain", "--date", "--text", "--goal", "--trigger", "--subject", "--message", "--notify", "--recipients", "--enabled", "--disabled", "--yes", "--alert", "--url", "--spikes", "--weekly", "--monthly", "--events", "--platform", "--role", "--color", "--description", "--hidden", "--visible", "--company", "--scopes", "--sites", "--transaction", "--visitor", "--user", "--dry-run", "--page", "--page-contains", "--link", "--link-path", "--click", "--form", "--download", "--referrer", "--channel", "--source", "--utm-source", "--utm-medium", "--utm-campaign", "--country", "--device", "--browser", "--os", "--visits-gt", "--visits-lt", "--trait", "--key", "--visit-source", "--visit-channel", "--visit-campaign", "--visit-referrer", "--visit-entry-page", "--visit-page", "--visit-page-contains", "--visit-goal", "--visit", "--grace", "--provider", "--account", "--order", "--verified-only", "--datacenter", "--type", "--cursor", "--all", "--csv", "--step", "--continued", "--funnel", "--steps", "--start", "--end", "--who"];
|
|
27
32
|
/** Flags with a fixed set of values; completion offers them after the flag. */
|
|
28
33
|
export const FLAG_VALUES = {
|
|
29
34
|
"--provider": AD_PROVIDER_VALUES,
|
|
@@ -35,6 +40,7 @@ export const FLAG_VALUES = {
|
|
|
35
40
|
"--include": ["speed", "errors", "speed,errors"],
|
|
36
41
|
"--verified-only": ["on", "off"],
|
|
37
42
|
"--datacenter": ["on", "off"],
|
|
43
|
+
"--events": ["spikes", "weekly", "monthly", "spikes,weekly,monthly", "none"],
|
|
38
44
|
};
|
|
39
45
|
export function completionScript(shell) {
|
|
40
46
|
if (shell === "bash") {
|
|
@@ -44,12 +50,20 @@ export function completionScript(shell) {
|
|
|
44
50
|
const cases = Object.entries(SUB)
|
|
45
51
|
.map(([cmd, subs]) => ` ${cmd}) COMPREPLY=($(compgen -W "${subs.join(" ")} ${FLAGS.join(" ")}" -- "$cur")) ;;`)
|
|
46
52
|
.join("\n");
|
|
53
|
+
const nested = Object.entries(NESTED)
|
|
54
|
+
.map(([cmd, subs]) => ` "${cmd}") COMPREPLY=($(compgen -W "${subs.join(" ")} ${FLAGS.join(" ")}" -- "$cur")); return ;;`)
|
|
55
|
+
.join("\n");
|
|
47
56
|
return `# metricraven bash completion. Add to ~/.bashrc: eval "$(metricraven completion bash)"
|
|
48
57
|
_metricraven() {
|
|
49
58
|
local cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
50
59
|
case "\${COMP_WORDS[COMP_CWORD-1]}" in
|
|
51
60
|
${values}
|
|
52
61
|
esac
|
|
62
|
+
if [ "$COMP_CWORD" -ge 3 ]; then
|
|
63
|
+
case "\${COMP_WORDS[1]} \${COMP_WORDS[2]}" in
|
|
64
|
+
${nested}
|
|
65
|
+
esac
|
|
66
|
+
fi
|
|
53
67
|
if [ "$COMP_CWORD" -eq 1 ]; then
|
|
54
68
|
COMPREPLY=($(compgen -W "${COMMANDS.join(" ")} ${FLAGS.join(" ")}" -- "$cur")); return
|
|
55
69
|
fi
|
|
@@ -67,12 +81,20 @@ complete -F _metricraven metricraven`;
|
|
|
67
81
|
const cases = Object.entries(SUB)
|
|
68
82
|
.map(([cmd, subs]) => ` ${cmd}) compadd -- ${subs.join(" ")} ${FLAGS.join(" ")} ;;`)
|
|
69
83
|
.join("\n");
|
|
84
|
+
const nested = Object.entries(NESTED)
|
|
85
|
+
.map(([cmd, subs]) => ` "${cmd}") compadd -- ${subs.join(" ")} ${FLAGS.join(" ")}; return ;;`)
|
|
86
|
+
.join("\n");
|
|
70
87
|
return `#compdef metricraven
|
|
71
88
|
# metricraven zsh completion. Add to ~/.zshrc: eval "$(metricraven completion zsh)"
|
|
72
89
|
_metricraven() {
|
|
73
90
|
case "\${words[CURRENT-1]}" in
|
|
74
91
|
${values}
|
|
75
92
|
esac
|
|
93
|
+
if (( CURRENT >= 4 )); then
|
|
94
|
+
case "\${words[2]} \${words[3]}" in
|
|
95
|
+
${nested}
|
|
96
|
+
esac
|
|
97
|
+
fi
|
|
76
98
|
if (( CURRENT == 2 )); then
|
|
77
99
|
compadd -- ${COMMANDS.join(" ")} ${FLAGS.join(" ")}
|
|
78
100
|
else
|
|
@@ -90,6 +112,10 @@ compdef _metricraven metricraven`;
|
|
|
90
112
|
"complete -c metricraven -f",
|
|
91
113
|
`complete -c metricraven -n "__fish_use_subcommand" -a "${COMMANDS.join(" ")}"`,
|
|
92
114
|
...Object.entries(SUB).map(([cmd, subs]) => `complete -c metricraven -n "__fish_seen_subcommand_from ${cmd}" -a "${subs.join(" ")}"`),
|
|
115
|
+
...Object.entries(NESTED).map(([cmd, subs]) => {
|
|
116
|
+
const [group, sub] = cmd.split(" ");
|
|
117
|
+
return `complete -c metricraven -n "__fish_seen_subcommand_from ${group}; and __fish_seen_subcommand_from ${sub}" -a "${subs.join(" ")}"`;
|
|
118
|
+
}),
|
|
93
119
|
...FLAGS.map((f) => FLAG_VALUES[f]
|
|
94
120
|
? `complete -c metricraven -l ${f.slice(2)} -x -a "${FLAG_VALUES[f].join(" ")}"`
|
|
95
121
|
: `complete -c metricraven -l ${f.slice(2)}`),
|
package/dist/index.js
CHANGED
|
@@ -137,24 +137,53 @@ Reports (default: last 30 days)
|
|
|
137
137
|
(follow every page, up to 100,000 rows), --csv
|
|
138
138
|
notes list Chart notes in the period
|
|
139
139
|
notes add --text [--date] Add a chart note (needs write access)
|
|
140
|
-
mentions
|
|
141
|
-
|
|
140
|
+
mentions Posts mentioning the website on X, Reddit, the web,
|
|
141
|
+
YouTube, LinkedIn, Threads, TikTok, Instagram,
|
|
142
|
+
Facebook, Pinterest (Growth); --platform <name>,
|
|
143
|
+
--q, -n/--limit, --offset
|
|
142
144
|
ai-visibility What AI assistants answer to your tracked prompts
|
|
143
145
|
(Growth): scores, per-assistant results, brands named;
|
|
144
146
|
--period (default 90d) for the trend
|
|
145
147
|
|
|
146
|
-
Alerts (email when a goal, payment or new
|
|
148
|
+
Alerts (email, Slack, Discord, Telegram or a webhook when a goal, payment or new
|
|
149
|
+
customer happens)
|
|
147
150
|
alerts list Alerts on the website
|
|
148
151
|
alerts get <alert_id> One alert with its counts
|
|
149
152
|
alerts create --goal <name> New goal alert; or --trigger payment|new_customer
|
|
150
153
|
[--name] [--subject] [--message]
|
|
151
154
|
[--recipients <email,email|all>] (default: you)
|
|
155
|
+
[--channel <channel_id,channel_id>] (also post there)
|
|
152
156
|
[--disabled] (needs write access, admin)
|
|
153
157
|
alerts update <alert_id> [--name] [--goal] [--enabled | --disabled]
|
|
154
158
|
[--recipients <email,email|all>]
|
|
159
|
+
[--channel <channel_id,…|none>] (replaces the list)
|
|
155
160
|
alerts delete <alert_id> Delete an alert (asks first; --yes to skip)
|
|
156
161
|
alerts history [--alert <id>] Emails the alerts sent, newest first
|
|
157
162
|
|
|
163
|
+
Alert channels (where alerts post besides email; changes need write access, admin)
|
|
164
|
+
alerts channels list Channels with their masked destination, what else they
|
|
165
|
+
get, how many alerts use them and the last delivery
|
|
166
|
+
alerts channels get <channel_id>
|
|
167
|
+
alerts channels add slack|discord|webhook --url <URL>
|
|
168
|
+
[--name] [--spikes] [--weekly] [--monthly]
|
|
169
|
+
[--timezone <zone>] (report weeks and months); asks for
|
|
170
|
+
the URL when --url is left out. A webhook prints its
|
|
171
|
+
signing secret once
|
|
172
|
+
alerts channels add telegram Prints the t.me links that connect a chat or group
|
|
173
|
+
alerts channels update <channel_id>
|
|
174
|
+
[--name] [--url] [--events spikes,weekly,monthly|none]
|
|
175
|
+
[--timezone <zone>]
|
|
176
|
+
alerts channels test <channel_id>
|
|
177
|
+
Post a test message now (exit code 1 when it fails)
|
|
178
|
+
alerts channels rotate-secret <channel_id>
|
|
179
|
+
New webhook signing secret, printed once; the old one
|
|
180
|
+
stops working at once (asks first; --yes to skip)
|
|
181
|
+
alerts channels reconnect <channel_id>
|
|
182
|
+
New Telegram connect links
|
|
183
|
+
alerts channels remove <channel_id>
|
|
184
|
+
Remove a channel and take it off every alert (asks
|
|
185
|
+
first; --yes to skip)
|
|
186
|
+
|
|
158
187
|
Team
|
|
159
188
|
members list Members, roles and (admins) pending invitations
|
|
160
189
|
members invite <email> --role admin|viewer
|
package/package.json
CHANGED