@supalytics/cli 0.4.1 → 0.4.3

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/src/index.ts CHANGED
@@ -1,105 +1,73 @@
1
1
  #!/usr/bin/env bun
2
- import { program } from "commander";
3
- import updateNotifier from "update-notifier";
4
- import { loginCommand } from "./commands/login";
5
- import { logoutCommand } from "./commands/logout";
6
- import { sitesCommand, defaultCommand, removeCommand } from "./commands/sites";
7
- import { statsCommand } from "./commands/stats";
8
- import { pagesCommand } from "./commands/pages";
9
- import { referrersCommand } from "./commands/referrers";
10
- import { countriesCommand } from "./commands/countries";
11
- import { trendCommand } from "./commands/trend";
12
- import { queryCommand } from "./commands/query";
13
- import { eventsCommand } from "./commands/events";
14
- import { realtimeCommand } from "./commands/realtime";
15
- import { completionsCommand } from "./commands/completions";
16
- import { annotationsCommand } from "./commands/annotations";
17
- import { journeysCommand } from "./commands/journeys";
18
- import { initCommand } from "./commands/init";
19
- import { updateCommand } from "./commands/update";
2
+ import { program } from "commander"
3
+ import updateNotifier from "update-notifier"
4
+ import { annotationsCommand } from "./commands/annotations"
5
+ import { completionsCommand } from "./commands/completions"
6
+ import { countriesCommand } from "./commands/countries"
7
+ import { eventsCommand } from "./commands/events"
8
+ import { funnelsCommand } from "./commands/funnels"
9
+ import { initCommand } from "./commands/init"
10
+ import { journeysCommand } from "./commands/journeys"
11
+ import { loginCommand } from "./commands/login"
12
+ import { logoutCommand } from "./commands/logout"
13
+ import { pagesCommand } from "./commands/pages"
14
+ import { queryCommand } from "./commands/query"
15
+ import { realtimeCommand } from "./commands/realtime"
16
+ import { referrersCommand } from "./commands/referrers"
17
+ import { defaultCommand, removeCommand, sitesCommand } from "./commands/sites"
18
+ import { statsCommand } from "./commands/stats"
19
+ import { trendCommand } from "./commands/trend"
20
+ import { updateCommand } from "./commands/update"
20
21
 
21
22
  const description = `CLI for Supalytics web analytics.
22
23
 
23
- Quick Start:
24
- supalytics init Auto-setup: login → create site → get snippet
25
-
26
- Authentication:
27
- supalytics login Open browser to authenticate
28
- supalytics logout Log out and remove all credentials
29
-
30
- Site Management:
31
- supalytics sites List configured sites
32
- supalytics sites add <name> Create a new site
33
- supalytics sites update <name> --domain <domain> Update domain
34
- supalytics default <domain> Set default site
35
- supalytics remove <domain> Remove a site
36
-
37
24
  Date Ranges:
38
25
  --period: 7d, 14d, 30d, 90d, 12mo, all (default: 30d)
39
26
  --start/--end: Custom range in YYYY-MM-DD format
40
27
 
41
28
  Filters (-f, --filter):
42
29
  Format: field:operator:value
43
-
44
- Fields:
45
- page, country, region, city, browser, os, device,
46
- referrer, utm_source, utm_medium, utm_campaign, utm_content, utm_term,
47
- event, event_property, exit_link
48
-
49
- Operators:
50
- is Exact match (supports comma-separated: "country:is:US,UK")
51
- is_not Exclude exact match
52
- contains Substring match
53
- not_contains Exclude substring
54
- starts_with Prefix match
55
-
56
- Examples:
57
- -f "country:is:US"
58
- -f "page:contains:/blog"
59
- -f "device:is:mobile"
60
- -f "referrer:is:twitter.com"
61
- -f "event:is:signup"
62
- -f "event_property:is:plan:premium"
30
+ Fields: page, country, browser, device, referrer, utm_*, event
31
+ Operators: is, is_not, contains, not_contains, starts_with
32
+ Example: -f "country:is:US" -f "page:contains:/blog"
63
33
 
64
34
  Output:
65
- --json Raw JSON output (useful for piping to other tools or AI)
66
- --no-revenue Exclude revenue metrics from output`;
35
+ --json Raw JSON output
36
+ --no-revenue Exclude revenue metrics`
67
37
 
68
38
  // Read version from package.json
69
- const pkg = await Bun.file(new URL("../package.json", import.meta.url)).json();
39
+ const pkg = await Bun.file(new URL("../package.json", import.meta.url)).json()
70
40
 
71
41
  // Check for updates (runs in background, non-blocking)
72
- updateNotifier({ pkg }).notify();
42
+ updateNotifier({ pkg }).notify()
73
43
 
74
- program
75
- .name("supalytics")
76
- .description(description)
77
- .version(pkg.version);
44
+ program.name("supalytics").description(description).version(pkg.version)
78
45
 
79
46
  // Quick start
80
- program.addCommand(initCommand);
47
+ program.addCommand(initCommand)
81
48
 
82
49
  // Auth & site management commands
83
- program.addCommand(loginCommand);
84
- program.addCommand(logoutCommand);
85
- program.addCommand(sitesCommand);
86
- program.addCommand(defaultCommand);
87
- program.addCommand(removeCommand);
50
+ program.addCommand(loginCommand)
51
+ program.addCommand(logoutCommand)
52
+ program.addCommand(sitesCommand)
53
+ program.addCommand(defaultCommand)
54
+ program.addCommand(removeCommand)
88
55
 
89
56
  // Analytics commands
90
- program.addCommand(statsCommand);
91
- program.addCommand(pagesCommand);
92
- program.addCommand(referrersCommand);
93
- program.addCommand(countriesCommand);
94
- program.addCommand(trendCommand);
95
- program.addCommand(queryCommand);
96
- program.addCommand(eventsCommand);
97
- program.addCommand(journeysCommand);
98
- program.addCommand(realtimeCommand);
99
- program.addCommand(annotationsCommand);
100
- program.addCommand(completionsCommand);
57
+ program.addCommand(statsCommand)
58
+ program.addCommand(pagesCommand)
59
+ program.addCommand(referrersCommand)
60
+ program.addCommand(countriesCommand)
61
+ program.addCommand(trendCommand)
62
+ program.addCommand(queryCommand)
63
+ program.addCommand(eventsCommand)
64
+ program.addCommand(funnelsCommand)
65
+ program.addCommand(journeysCommand)
66
+ program.addCommand(realtimeCommand)
67
+ program.addCommand(annotationsCommand)
68
+ program.addCommand(completionsCommand)
101
69
 
102
70
  // Utility commands
103
- program.addCommand(updateCommand);
71
+ program.addCommand(updateCommand)
104
72
 
105
- program.parse();
73
+ program.parse()
package/src/ui.ts CHANGED
@@ -44,9 +44,25 @@ export function parsePeriod(period: string): string | [string, string] {
44
44
  const endOfLastMonth = new Date(today.getFullYear(), today.getMonth(), 0);
45
45
  return [yyyy(startOfLastMonth), yyyy(endOfLastMonth)];
46
46
  }
47
- default:
48
- // Return as-is for 7d, 30d, etc.
47
+ default: {
48
+ // Parse arbitrary periods: Nd (days), Nmo (months)
49
+ const daysMatch = period.match(/^(\d+)d$/i);
50
+ if (daysMatch) {
51
+ const days = parseInt(daysMatch[1]);
52
+ const start = new Date(today);
53
+ start.setDate(today.getDate() - days);
54
+ return [yyyy(start), yyyy(today)];
55
+ }
56
+ const moMatch = period.match(/^(\d+)mo$/i);
57
+ if (moMatch) {
58
+ const months = parseInt(moMatch[1]);
59
+ const start = new Date(today);
60
+ start.setMonth(today.getMonth() - months);
61
+ return [yyyy(start), yyyy(today)];
62
+ }
63
+ // "all" or API-recognized strings
49
64
  return period;
65
+ }
50
66
  }
51
67
  }
52
68