@supalytics/cli 0.3.3 → 0.3.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supalytics/cli",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "CLI for Supalytics web analytics",
5
5
  "type": "module",
6
6
  "bin": {
@@ -12,7 +12,10 @@
12
12
  "README.md"
13
13
  ],
14
14
  "scripts": {
15
- "dev": "bun run src/index.ts"
15
+ "dev": "bun run src/index.ts",
16
+ "release:patch": "npm version patch --no-git-tag-version && npm publish",
17
+ "release:minor": "npm version minor --no-git-tag-version && npm publish",
18
+ "release:major": "npm version major --no-git-tag-version && npm publish"
16
19
  },
17
20
  "keywords": [
18
21
  "analytics",
@@ -34,6 +37,7 @@
34
37
  "dependencies": {
35
38
  "chalk": "^5.6.2",
36
39
  "commander": "^14.0.2",
37
- "open": "^10.1.0"
40
+ "open": "^10.1.0",
41
+ "update-notifier": "^7.3.1"
38
42
  }
39
43
  }
package/src/api.ts CHANGED
@@ -75,7 +75,7 @@ export async function query(
75
75
  Authorization: `Bearer ${apiKey}`,
76
76
  "Content-Type": "application/json",
77
77
  },
78
- body: JSON.stringify(request),
78
+ body: JSON.stringify({ ...request, domain: site }),
79
79
  });
80
80
 
81
81
  if (!response.ok) {
@@ -177,7 +177,7 @@ export async function listEvents(
177
177
  );
178
178
  }
179
179
 
180
- const params = new URLSearchParams({ period, limit: String(limit) });
180
+ const params = new URLSearchParams({ period, limit: String(limit), domain: site });
181
181
  if (isDev) {
182
182
  params.set("is_dev", "true");
183
183
  }
@@ -208,7 +208,7 @@ export async function getEventProperties(
208
208
  throw new Error(`Not authenticated. Run \`supalytics login\` first.`);
209
209
  }
210
210
 
211
- const params = new URLSearchParams({ period });
211
+ const params = new URLSearchParams({ period, domain: site });
212
212
  if (isDev) {
213
213
  params.set("is_dev", "true");
214
214
  }
@@ -247,6 +247,7 @@ export async function getPropertyBreakdown(
247
247
  period,
248
248
  limit: String(limit),
249
249
  include_revenue: String(includeRevenue),
250
+ domain: site,
250
251
  });
251
252
  if (isDev) {
252
253
  params.set("is_dev", "true");
@@ -311,12 +312,11 @@ export async function getRealtime(site: string, isDev: boolean = false): Promise
311
312
  );
312
313
  }
313
314
 
314
- const params = new URLSearchParams();
315
+ const params = new URLSearchParams({ domain: site });
315
316
  if (isDev) {
316
317
  params.set("is_dev", "true");
317
318
  }
318
- const url = params.toString() ? `${API_BASE}/v1/realtime?${params}` : `${API_BASE}/v1/realtime`;
319
- const response = await fetch(url, {
319
+ const response = await fetch(`${API_BASE}/v1/realtime?${params}`, {
320
320
  headers: { Authorization: `Bearer ${apiKey}` },
321
321
  });
322
322
 
@@ -0,0 +1,54 @@
1
+ import { Command } from "commander";
2
+ import chalk from "chalk";
3
+ import { $ } from "bun";
4
+
5
+ export const updateCommand = new Command("update")
6
+ .description("Update Supalytics CLI to the latest version")
7
+ .action(async () => {
8
+ // Read current version
9
+ const pkg = await Bun.file(new URL("../../package.json", import.meta.url)).json();
10
+ console.log(chalk.dim(`Current version: ${pkg.version}`));
11
+ console.log(chalk.dim("Checking for updates..."));
12
+ console.log();
13
+
14
+ try {
15
+ // Check latest version from npm
16
+ const response = await fetch("https://registry.npmjs.org/@supalytics/cli/latest");
17
+ if (!response.ok) {
18
+ throw new Error("Failed to check npm registry");
19
+ }
20
+ const data = await response.json();
21
+ const latestVersion = data.version;
22
+
23
+ if (latestVersion === pkg.version) {
24
+ console.log(chalk.green("✓ Already on the latest version"));
25
+ return;
26
+ }
27
+
28
+ console.log(chalk.cyan(`New version available: ${latestVersion}`));
29
+ console.log();
30
+ console.log(chalk.dim("Updating..."));
31
+
32
+ // Try bun first, fall back to npm
33
+ try {
34
+ await $`bun upgrade @supalytics/cli`.quiet();
35
+ console.log(chalk.green(`✓ Updated to ${latestVersion}`));
36
+ } catch {
37
+ // bun upgrade might not work for global packages, try npm
38
+ try {
39
+ await $`npm update -g @supalytics/cli`.quiet();
40
+ console.log(chalk.green(`✓ Updated to ${latestVersion}`));
41
+ } catch {
42
+ console.log(chalk.yellow("Automatic update failed."));
43
+ console.log();
44
+ console.log("Please update manually:");
45
+ console.log(chalk.cyan(" bun install -g @supalytics/cli@latest"));
46
+ console.log(" or");
47
+ console.log(chalk.cyan(" npm install -g @supalytics/cli@latest"));
48
+ }
49
+ }
50
+ } catch (error) {
51
+ console.error(chalk.red(`Error: ${(error as Error).message}`));
52
+ process.exit(1);
53
+ }
54
+ });
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
  import { program } from "commander";
3
+ import updateNotifier from "update-notifier";
3
4
  import { loginCommand } from "./commands/login";
4
5
  import { logoutCommand } from "./commands/logout";
5
6
  import { sitesCommand, defaultCommand, removeCommand } from "./commands/sites";
@@ -13,6 +14,7 @@ import { eventsCommand } from "./commands/events";
13
14
  import { realtimeCommand } from "./commands/realtime";
14
15
  import { completionsCommand } from "./commands/completions";
15
16
  import { initCommand } from "./commands/init";
17
+ import { updateCommand } from "./commands/update";
16
18
 
17
19
  const description = `CLI for Supalytics web analytics.
18
20
 
@@ -64,6 +66,9 @@ Output:
64
66
  // Read version from package.json
65
67
  const pkg = await Bun.file(new URL("../package.json", import.meta.url)).json();
66
68
 
69
+ // Check for updates (runs in background, non-blocking)
70
+ updateNotifier({ pkg }).notify();
71
+
67
72
  program
68
73
  .name("supalytics")
69
74
  .description(description)
@@ -90,4 +95,7 @@ program.addCommand(eventsCommand);
90
95
  program.addCommand(realtimeCommand);
91
96
  program.addCommand(completionsCommand);
92
97
 
98
+ // Utility commands
99
+ program.addCommand(updateCommand);
100
+
93
101
  program.parse();