@metricraven/cli 0.4.5 → 0.5.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 +33 -7
- package/dist/api.js +1 -1
- package/dist/args.js +127 -6
- package/dist/commands.js +841 -22
- package/dist/completion.js +14 -8
- package/dist/format.js +14 -0
- package/dist/index.js +86 -12
- package/dist/range.js +15 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,23 +36,37 @@ The token is saved to `~/.config/metricraven/config.json` (or `$XDG_CONFIG_HOME/
|
|
|
36
36
|
| `websites keys list\|create --name\|rename <id> --name\|revoke <id>\|roll <id> [--grace none\|24h\|7d]` | Site secret keys: the default key and named keys with last use; revoke and roll ask first (`--yes` to skip). Needs write access, admin |
|
|
37
37
|
| `use <website_id>` | Set the default website |
|
|
38
38
|
| `analytics traffic` | Visitors, pageviews, revenue, conversion rate and top sources |
|
|
39
|
-
| `analytics breakdown <dimension>` | Full table for `channel`, `referrer`, `page`, `utmSource`, `country`, `device`, … |
|
|
39
|
+
| `analytics breakdown <dimension>` | Full table for `channel`, `referrer`, `page`, `utmSource`, `country`, `device`, `language`, `screenSize`, `exitPage`, `urlParam` (with `--param <name>`), … with visitors, revenue, paying visitors and purchase rate. For `page`: avg time and exit rate, `--attribution first_touch\|viewed`, `--group folder`, `--folder /blog/`. For `page` and `entryPage`: `--include speed` adds LCP and INP at the 75th percentile, `--include errors` visitors who hit a JavaScript error and didn't pay (both: `--include speed,errors`) |
|
|
40
40
|
| `analytics revenue` | Payments, renewals, refunds, LTV, revenue by channel |
|
|
41
41
|
| `analytics mrr [day\|week\|month]` | MRR over time: new, expansion, contraction, churn |
|
|
42
|
-
| `analytics conversions` | Goals and funnel steps |
|
|
43
|
-
| `analytics
|
|
44
|
-
| `analytics
|
|
42
|
+
| `analytics conversions [--funnel <id> \| --steps <steps>]` | Goals and funnel steps, with the median time between steps and to payment; `--funnel` reports a saved funnel, `--steps` an unsaved one |
|
|
43
|
+
| `analytics paths` | Page sequences of payers and non-payers, with % that paid and revenue per path (`--steps 2-7`, `--group page\|section`, `--start /pricing`, `--end /checkout`, `--who all\|paid\|unpaid`) |
|
|
44
|
+
| `analytics goal <name>` | One goal with its sources, and for each property value: people, how many bought afterwards, purchase rate and revenue |
|
|
45
|
+
| `analytics errors` | JavaScript errors grouped by name and message, with how many of the visitors who hit them didn't pay. `--path /checkout` for one page, `--funnel <id>` or `--steps <list>` with `--drop-step <n>` for the visitors who didn't reach step `n`, `--group <id>` for one group's stack and people. Needs JavaScript errors on in Settings |
|
|
46
|
+
| `analytics properties [<name>]` | Event property names on goal events, or one property's values, with people counts (`--goal <name>` for one goal) |
|
|
47
|
+
| `analytics insights` | What converts, how long buyers take, channel by channel |
|
|
48
|
+
| `analytics speed` | Slow pages that lose buyers: slow and fast visitors, the share of each that paid, buyers lost, LCP and INP (needs Page speed on in Settings) |
|
|
45
49
|
| `analytics search` | Google Search Console queries |
|
|
46
50
|
| `analytics crawlers` | AI crawlers and bots |
|
|
51
|
+
| `analytics ai-companies` | Pages crawled, visits sent, paying customers and revenue per AI company |
|
|
47
52
|
| `analytics ads [campaign\|adgroup\|ad] [--provider all\|meta\|google] [--account <id>]` | Ad spend from every connected network, attributed and assisted revenue, ROAS and cost per customer, with each network's own reported value (Meta-reported, Google-reported) for comparison. `--account` reports one chosen ad account alone (the IDs are listed when several are combined; Google IDs with or without dashes, Meta without `act_`) |
|
|
48
53
|
| `analytics meta-ads [campaign\|adset\|ad] [--account <id>]` | Meta Ads spend, attributed revenue, ROAS and cost per customer |
|
|
49
54
|
| `realtime` | Visitors online now |
|
|
50
|
-
| `visitors list`, `visitors get <id>` | Visitors and journeys (token needs visitor details access) |
|
|
55
|
+
| `visitors list`, `visitors get <id>` | Visitors and journeys, with the number of session recordings (token needs visitor details access) |
|
|
51
56
|
| `visitors list --page /pricing --goal signup --visits-gt 2` | Search visitors by visited page (`--page`, `--page-contains`), completed goal, `--referrer`, `--channel`, `--source`, `--utm-source/medium/campaign`, `--country`, `--device`, `--browser`, `--os` and visits in the period (`--visits-gt`, `--visits-lt`) |
|
|
57
|
+
| `visitors list --visit-source google.com --visit-page /pricing` | Same visit: one visit that came from (`--visit-source`, `--visit-channel`, `--visit-campaign`, `--visit-referrer`, `--visit-entry-page`) and reached (`--visit-page`, `--visit-page-contains`, `--visit-goal`); adds a Matched visit column |
|
|
58
|
+
| `visitors list --trait role=founder` | People whose latest identify trait matches (`--trait key=value[,value]`, repeatable for other keys) |
|
|
59
|
+
| `visitors traits [--key role]` | Revenue, customers and purchase rate per value of one identify trait (token needs visitor details access) |
|
|
60
|
+
| `visitors get <id> --visit 2026-11-02T10:00:00Z` | Only the visit containing that time, with its number, span, source and landing page |
|
|
52
61
|
| `payments delete`, `goals delete-events` | Delete payments (`--transaction`, `--visitor`, `--user`, `--from/--to`) or goal events (`--goal`, `--visitor`, `--user`, `--from/--to`); shows the count and asks first (`--yes`, `--dry-run`) |
|
|
53
|
-
| `
|
|
62
|
+
| `events list`, `payments list` | Raw rows, newest first (token needs visitor details access). Events: `--type pageview,event,engagement`, `--goal <name>`, `--visitor`, `--user`. Payments (refunds and free trials flagged) with each customer and the first visit's channel, source and landing page: `--transaction`, `--visitor`, `--user`. Both: `--limit` (1–1000), `--cursor`, `--all` (follow every page, up to 100,000 rows), `--csv` (RFC 4180, formulas guarded), `--json`. Not for `--period all` |
|
|
63
|
+
| `funnels list\|create\|update\|delete` | Saved funnels; changes need write access. `funnels create --name "Pricing to paid" --steps visit,page:/pricing,payment` (1–8 of `visit`, `page:/path`, `page:=/path` (exact), `page:host/path` (one hostname), `event:goal_name`, `identify`, `payment`, counted in order); `funnels update <id> [--name] [--steps]`; `funnels delete <id>` asks first (`--yes`) and deletes no data |
|
|
64
|
+
| `segments list\|create\|update\|delete` | Saved segments; listing needs visitor details access, changes need write access. `segments create --name US --filter country:is:US` (repeat `--filter`, up to six; keyed forms like `urlParam.plan:is:pro` work); `segments update <id> [--name] [--filter …]` (filters replace all); `segments delete <id>` asks first (`--yes`) |
|
|
65
|
+
| `funnels dropoff <id> --step N` | Visitors who left after step N (1-based), with source, country and spend; `--continued` for who went on |
|
|
54
66
|
| `goals list`, `goals colors` | Goal display settings (display name, colour, description, hidden) and the palette |
|
|
55
67
|
| `goals set <goal> [--name] [--color] [--description] [--hidden\|--visible]`, `goals reset <goal>` | Change how a goal is shown (needs write access, admin) |
|
|
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
|
+
| `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 |
|
|
56
70
|
| `notes list`, `notes add --text [--date]` | Chart notes (adding needs write access) |
|
|
57
71
|
| `mentions [--platform x\|reddit] [--q text]` | X and Reddit posts mentioning the website (Growth plan) |
|
|
58
72
|
| `ai-visibility` | What AI assistants answer to your tracked prompts (Growth plan); `--period` for the trend (default 90d) |
|
|
@@ -62,13 +76,25 @@ The token is saved to `~/.config/metricraven/config.json` (or `$XDG_CONFIG_HOME/
|
|
|
62
76
|
| `proxy status\|enable <subdomain>\|check\|remove` | The managed proxy subdomain that serves the script |
|
|
63
77
|
| `completion bash\|zsh\|fish` | Shell completion script |
|
|
64
78
|
|
|
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`
|
|
79
|
+
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 weekdays` (the same length, starting whole weeks earlier so Mondays compare with Mondays), `--compare year` or a `YYYY-MM-DD` start changes what the change figures compare against; the default is the previous period of equal length. `--compare off` shows no comparison: no change column, and the comparison fields are left out of `--json`. Filter with `--filter dimension:operator:value` (repeatable; operators `is`, `is_not`, `contains`, `not_contains`, `starts_with`, `ends_with`, `regex`, `not_regex`, `is_empty` and `is_not_empty`, and `gt`/`lt` for `visits`, e.g. `-f visits:gt:2`). Starts with, ends with and regex ignore letter case; quote regexes so the shell leaves them alone: `-f 'page:regex:^/blog/'`. `is_empty` and `is_not_empty` take no value: `-f utmCampaign:is_empty` keeps visitors who never had a campaign. URL parameters you keep name the parameter after a dot: `-f urlParam.plan:is:pro`. Event properties name the property after a dot, and optionally a goal after `@`: `-f prop.plan:is:growth`, `-f prop.experiment@signup:is:B`. Identify traits name the trait after a dot: `-f trait.role:is:founder` (property or goal names containing `:` or `@` can't be written this way; use the API).
|
|
66
80
|
|
|
67
81
|
```bash
|
|
68
82
|
metricraven analytics traffic --period 7d
|
|
69
83
|
metricraven analytics breakdown referrer --sort revenue --limit 20
|
|
70
84
|
metricraven analytics breakdown page --sort visitors --order asc # least-visited pages first
|
|
85
|
+
metricraven analytics breakdown referrer --sort purchaseRate # referrers that convert best (rate needs 10 visitors)
|
|
86
|
+
metricraven analytics breakdown urlParam --param plan # values of a kept URL parameter, ?plan=
|
|
87
|
+
metricraven analytics properties plan --goal signup # values of signup's plan property
|
|
88
|
+
metricraven analytics traffic -f prop.experiment@signup:is:B # only people whose signup had experiment = B
|
|
89
|
+
metricraven analytics breakdown exitPage --sort revenue # pages buyers saw last before paying
|
|
90
|
+
metricraven analytics breakdown page --attribution viewed --sort buyers # pages buyers viewed before paying
|
|
91
|
+
metricraven analytics breakdown page --group folder --folder /blog/ # pages under /blog/, sub-folders marked ▸
|
|
92
|
+
metricraven analytics breakdown page --include errors # visitors per page who hit a JavaScript error and didn't pay
|
|
93
|
+
metricraven analytics errors --path /pricing # errors on /pricing, most non-paying visitors first
|
|
94
|
+
metricraven analytics errors --drop-step 2 # errors of visitors who left the default funnel before step 2
|
|
71
95
|
metricraven analytics traffic -f country:is:US -f device:is:mobile --json | jq .overview
|
|
96
|
+
metricraven payments list --period 90d --all --csv > payments.csv # every payment with the traffic that brought it
|
|
97
|
+
metricraven events list --goal signup --period 7d # raw signup events
|
|
72
98
|
```
|
|
73
99
|
|
|
74
100
|
## Environment
|
package/dist/api.js
CHANGED
|
@@ -51,7 +51,7 @@ export function createClient(opts) {
|
|
|
51
51
|
post: (path, body, params) => request("POST", path, params, body),
|
|
52
52
|
patch: (path, body, params) => request("PATCH", path, params, body),
|
|
53
53
|
put: (path, body, params) => request("PUT", path, params, body),
|
|
54
|
-
del: (path, params) => request("DELETE", path, params),
|
|
54
|
+
del: (path, params, body) => request("DELETE", path, params, body),
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
export function toError(status, data) {
|
package/dist/args.js
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { PERIODS, compareStartFor, customRange, presetRange, validTimeZone } from "./range.js";
|
|
3
|
-
export const FILTER_OPERATORS = [
|
|
3
|
+
export const FILTER_OPERATORS = [
|
|
4
|
+
"is",
|
|
5
|
+
"is_not",
|
|
6
|
+
"contains",
|
|
7
|
+
"not_contains",
|
|
8
|
+
"starts_with",
|
|
9
|
+
"ends_with",
|
|
10
|
+
"regex",
|
|
11
|
+
"not_regex",
|
|
12
|
+
"is_empty",
|
|
13
|
+
"is_not_empty",
|
|
14
|
+
"gt",
|
|
15
|
+
"lt",
|
|
16
|
+
];
|
|
17
|
+
const EMPTY_OPERATORS = ["is_empty", "is_not_empty"];
|
|
18
|
+
/** Dimensions that take a key after a dot (`urlParam.plan`), and the key's shape (core/filters.ts FILTER_KEY_PATTERNS). */
|
|
19
|
+
const KEYED_DIMENSIONS = {
|
|
20
|
+
urlParam: /^[a-z0-9_-]{1,40}$/,
|
|
21
|
+
prop: /^[^\u0000-\u001f\u007f]{1,64}$/,
|
|
22
|
+
// core/traits.ts TRAIT_KEY_PATTERN.
|
|
23
|
+
trait: /^[a-z][a-z0-9_-]{0,63}$/,
|
|
24
|
+
};
|
|
25
|
+
/** core/goals.ts GOAL_NAME_PATTERN. */
|
|
26
|
+
const GOAL_NAME = /^[a-zA-Z][a-zA-Z0-9_:.-]{0,99}$/;
|
|
27
|
+
/**
|
|
28
|
+
* `urlParam.plan` -> { dim: "urlParam", key: "plan" }; `prop.plan@signup` -> { dim: "prop", key:
|
|
29
|
+
* "plan", goal: "signup" }; other slots pass through as the dimension.
|
|
30
|
+
*/
|
|
31
|
+
function filterSlot(slot) {
|
|
32
|
+
const dot = slot.indexOf(".");
|
|
33
|
+
const dim = dot < 0 ? slot : slot.slice(0, dot);
|
|
34
|
+
const pattern = KEYED_DIMENSIONS[dim];
|
|
35
|
+
if (!pattern) {
|
|
36
|
+
if (dot >= 0)
|
|
37
|
+
throw new UsageError(`Filter dimension "${slot}" takes no key; only urlParam, prop and trait do, e.g. urlParam.plan:is:pro.`);
|
|
38
|
+
return { dim };
|
|
39
|
+
}
|
|
40
|
+
if (dim === "prop") {
|
|
41
|
+
let key = dot < 0 ? "" : slot.slice(dot + 1);
|
|
42
|
+
let goal;
|
|
43
|
+
const at = key.lastIndexOf("@");
|
|
44
|
+
if (at >= 0) {
|
|
45
|
+
goal = key.slice(at + 1);
|
|
46
|
+
key = key.slice(0, at);
|
|
47
|
+
if (!GOAL_NAME.test(goal))
|
|
48
|
+
throw new UsageError(`"${goal}" isn't a goal name. Use prop.<property>@<goal>, e.g. prop.plan@signup:is:growth.`);
|
|
49
|
+
}
|
|
50
|
+
if (!pattern.test(key))
|
|
51
|
+
throw new UsageError("prop needs a property name after a dot (up to 64 characters), e.g. prop.plan:is:growth or prop.plan@signup:is:growth.");
|
|
52
|
+
return goal ? { dim, key, goal } : { dim, key };
|
|
53
|
+
}
|
|
54
|
+
if (dim === "trait") {
|
|
55
|
+
const key = dot < 0 ? "" : slot.slice(dot + 1);
|
|
56
|
+
if (!pattern.test(key))
|
|
57
|
+
throw new UsageError("trait needs a trait name after a dot (lowercase letters, digits, _ or -), e.g. trait.role:is:founder.");
|
|
58
|
+
return { dim, key };
|
|
59
|
+
}
|
|
60
|
+
const key = dot < 0 ? "" : slot.slice(dot + 1).toLowerCase();
|
|
61
|
+
if (!pattern.test(key))
|
|
62
|
+
throw new UsageError(`${dim} needs a URL parameter name after a dot (letters, digits, _ or -), e.g. ${dim}.plan:is:pro.`);
|
|
63
|
+
return { dim, key };
|
|
64
|
+
}
|
|
65
|
+
const sameSlot = (f, slot) => f.dim === slot.dim && f.key === slot.key && f.goal === slot.goal;
|
|
4
66
|
/** Every flag the CLI understands; commands ignore the ones that don't apply. */
|
|
5
67
|
const OPTIONS = {
|
|
6
68
|
json: { type: "boolean" },
|
|
@@ -22,6 +84,16 @@ const OPTIONS = {
|
|
|
22
84
|
limit: { type: "string", short: "n" },
|
|
23
85
|
offset: { type: "string" },
|
|
24
86
|
q: { type: "string" },
|
|
87
|
+
// analytics breakdown urlParam: the URL parameter name
|
|
88
|
+
param: { type: "string" },
|
|
89
|
+
// analytics breakdown page: revenue credit (first_touch|viewed) and folder grouping
|
|
90
|
+
attribution: { type: "string" },
|
|
91
|
+
group: { type: "string" },
|
|
92
|
+
folder: { type: "string" },
|
|
93
|
+
// analytics breakdown page|entryPage: --include speed,errors; analytics errors --path and --drop-step (with --funnel/--steps)
|
|
94
|
+
include: { type: "string" },
|
|
95
|
+
path: { type: "string" },
|
|
96
|
+
"drop-step": { type: "string" },
|
|
25
97
|
payment: { type: "string" },
|
|
26
98
|
name: { type: "string" },
|
|
27
99
|
domain: { type: "string" },
|
|
@@ -59,6 +131,13 @@ const OPTIONS = {
|
|
|
59
131
|
// visitors list search filters
|
|
60
132
|
page: { type: "string" },
|
|
61
133
|
"page-contains": { type: "string" },
|
|
134
|
+
// goals define / preview: a link goal
|
|
135
|
+
link: { type: "string" },
|
|
136
|
+
"link-path": { type: "string" },
|
|
137
|
+
// goals define / preview: a button text, form or file from automatic events
|
|
138
|
+
click: { type: "string" },
|
|
139
|
+
form: { type: "string" },
|
|
140
|
+
download: { type: "string" },
|
|
62
141
|
referrer: { type: "string" },
|
|
63
142
|
channel: { type: "string" },
|
|
64
143
|
source: { type: "string" },
|
|
@@ -70,11 +149,39 @@ const OPTIONS = {
|
|
|
70
149
|
browser: { type: "string" },
|
|
71
150
|
os: { type: "string" },
|
|
72
151
|
"visits-gt": { type: "string" },
|
|
152
|
+
// visitors list --trait role=founder (repeatable); visitors traits --key role
|
|
153
|
+
trait: { type: "string", multiple: true },
|
|
154
|
+
key: { type: "string" },
|
|
73
155
|
"visits-lt": { type: "string" },
|
|
156
|
+
// visitors list "Same visit" condition, visitors get --visit
|
|
157
|
+
"visit-source": { type: "string" },
|
|
158
|
+
"visit-channel": { type: "string" },
|
|
159
|
+
"visit-campaign": { type: "string" },
|
|
160
|
+
"visit-referrer": { type: "string" },
|
|
161
|
+
"visit-entry-page": { type: "string" },
|
|
162
|
+
"visit-page": { type: "string" },
|
|
163
|
+
"visit-page-contains": { type: "string" },
|
|
164
|
+
"visit-goal": { type: "string" },
|
|
165
|
+
visit: { type: "string" },
|
|
74
166
|
grace: { type: "string" },
|
|
167
|
+
// analytics conversions, funnels dropoff: a saved funnel's ID or unsaved steps; funnels create|update: steps
|
|
168
|
+
funnel: { type: "string" },
|
|
169
|
+
steps: { type: "string" },
|
|
170
|
+
// funnels dropoff
|
|
171
|
+
step: { type: "string" },
|
|
172
|
+
// analytics paths: --steps 2–7 (shared with funnels above), start/end anchors, who (all|paid|unpaid); --group page|section
|
|
173
|
+
start: { type: "string" },
|
|
174
|
+
end: { type: "string" },
|
|
175
|
+
who: { type: "string" },
|
|
176
|
+
continued: { type: "boolean" },
|
|
75
177
|
// bots settings
|
|
76
178
|
"verified-only": { type: "string" },
|
|
77
179
|
datacenter: { type: "string" },
|
|
180
|
+
// events list, payments list
|
|
181
|
+
type: { type: "string" },
|
|
182
|
+
cursor: { type: "string" },
|
|
183
|
+
all: { type: "boolean" },
|
|
184
|
+
csv: { type: "boolean" },
|
|
78
185
|
};
|
|
79
186
|
export class UsageError extends Error {
|
|
80
187
|
}
|
|
@@ -90,28 +197,42 @@ export function parseCli(argv) {
|
|
|
90
197
|
/**
|
|
91
198
|
* `--filter country:is:US` (repeatable). Values may contain colons (`page:contains:/a:b`); the
|
|
92
199
|
* same dimension and operator merge into one filter with several values (OR), like the dashboard.
|
|
200
|
+
* is_empty and is_not_empty take no value: `utmCampaign:is_empty`. URL parameters name the
|
|
201
|
+
* parameter after a dot: `urlParam.plan:is:pro`; event properties the property, and optionally the
|
|
202
|
+
* goal after @: `prop.plan@signup:is:growth`. Property names with ":" and goal names with ":" can't
|
|
203
|
+
* be written this way (the first ":" ends the dimension).
|
|
93
204
|
*/
|
|
94
205
|
export function buildFilters(raw) {
|
|
95
206
|
const filters = [];
|
|
96
207
|
for (const item of raw ?? []) {
|
|
97
208
|
const first = item.indexOf(":");
|
|
98
209
|
const second = first < 0 ? -1 : item.indexOf(":", first + 1);
|
|
210
|
+
const emptyOp = first > 0 ? (second < 0 ? item.slice(first + 1) : item.slice(first + 1, second)) : "";
|
|
211
|
+
if (EMPTY_OPERATORS.includes(emptyOp)) {
|
|
212
|
+
if (second >= 0)
|
|
213
|
+
throw new UsageError("is_empty and is_not_empty take no value, e.g. utmCampaign:is_empty.");
|
|
214
|
+
const slot = filterSlot(item.slice(0, first));
|
|
215
|
+
// Never merged: one empty filter per dimension and operator.
|
|
216
|
+
if (!filters.some((f) => sameSlot(f, slot) && f.op === emptyOp))
|
|
217
|
+
filters.push({ ...slot, op: emptyOp, values: [] });
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
99
220
|
if (first <= 0 || second < 0)
|
|
100
221
|
throw new UsageError(`Filter "${item}" must look like dimension:operator:value, e.g. country:is:US.`);
|
|
101
|
-
const
|
|
222
|
+
const slot = filterSlot(item.slice(0, first));
|
|
102
223
|
const op = item.slice(first + 1, second);
|
|
103
224
|
const value = item.slice(second + 1);
|
|
104
225
|
if (!FILTER_OPERATORS.includes(op))
|
|
105
226
|
throw new UsageError(`Unknown filter operator "${op}". Use ${FILTER_OPERATORS.join(", ")}.`);
|
|
106
227
|
if (!value)
|
|
107
228
|
throw new UsageError(`Filter "${item}" has no value.`);
|
|
108
|
-
const existing = filters.find((f) => f
|
|
229
|
+
const existing = filters.find((f) => sameSlot(f, slot) && f.op === op);
|
|
109
230
|
if (existing) {
|
|
110
231
|
if (!existing.values.includes(value))
|
|
111
232
|
existing.values.push(value);
|
|
112
233
|
}
|
|
113
234
|
else
|
|
114
|
-
filters.push({
|
|
235
|
+
filters.push({ ...slot, op, values: [value] });
|
|
115
236
|
}
|
|
116
237
|
if (filters.length > 6)
|
|
117
238
|
throw new UsageError("At most six filters.");
|
|
@@ -150,9 +271,9 @@ export function rangeParams(flags, now = new Date()) {
|
|
|
150
271
|
params.set("filters", JSON.stringify(filters));
|
|
151
272
|
if (flags.compare) {
|
|
152
273
|
const from = params.get("from");
|
|
153
|
-
const start = from ? compareStartFor(flags.compare, new Date(from), zone) : null;
|
|
274
|
+
const start = from ? compareStartFor(flags.compare, new Date(from), zone, new Date(params.get("to"))) : null;
|
|
154
275
|
if (start === undefined)
|
|
155
|
-
throw new UsageError(`--compare must be previous, year, off or a YYYY-MM-DD day before the period starts (got "${flags.compare}").`);
|
|
276
|
+
throw new UsageError(`--compare must be previous, weekdays, year, off or a YYYY-MM-DD day before the period starts (got "${flags.compare}").`);
|
|
156
277
|
if (start)
|
|
157
278
|
params.set("compareStart", start.toISOString());
|
|
158
279
|
}
|