@blinkdotnew/cli 0.5.1 → 0.5.2

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/dist/cli.js CHANGED
@@ -3663,19 +3663,14 @@ Examples:
3663
3663
 
3664
3664
  // src/commands/billing.ts
3665
3665
  import chalk23 from "chalk";
3666
- function printUsage(data) {
3667
- console.log();
3668
- printKv("Total", `${data.total ?? 0} credits used`);
3669
- const breakdown = data.breakdown ?? [];
3670
- if (breakdown.length) {
3671
- console.log();
3672
- console.log(chalk23.bold("Breakdown:"));
3673
- for (const item of breakdown) printKv(` ${item.category}`, `${item.amount}`);
3674
- }
3675
- console.log();
3666
+ function formatCredits(n) {
3667
+ return n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : n.toFixed(1);
3668
+ }
3669
+ function formatUsd(n) {
3670
+ return `$${n.toFixed(2)}`;
3676
3671
  }
3677
3672
  function registerBillingCommands(program2) {
3678
- program2.command("credits").description("Check your credit balance and tier").addHelpText("after", `
3673
+ program2.command("credits").description("Check your credit usage this month").addHelpText("after", `
3679
3674
  Examples:
3680
3675
  $ blink credits
3681
3676
  $ blink credits --json
@@ -3686,15 +3681,23 @@ Examples:
3686
3681
  () => appRequest("/api/usage/summary?period=month")
3687
3682
  );
3688
3683
  if (isJsonMode()) return printJson(result);
3689
- const data = result ?? {};
3684
+ const buckets = result?.data ?? [];
3685
+ const current = buckets[0];
3690
3686
  console.log();
3691
- printKv("Used", `${data.total ?? 0} credits this month`);
3687
+ if (current) {
3688
+ printKv("Period", current.time_bucket.slice(0, 7));
3689
+ printKv("Credits", formatCredits(current.total_credits));
3690
+ printKv("Requests", String(current.total_requests));
3691
+ printKv("Cost", formatUsd(current.total_cost_usd));
3692
+ } else {
3693
+ console.log(chalk23.dim(" No usage data for this month."));
3694
+ }
3692
3695
  console.log();
3693
3696
  });
3694
- program2.command("usage").description("Show usage summary for the current billing period").option("--period <granularity>", "Period granularity: hour, day, week, month", "day").addHelpText("after", `
3697
+ program2.command("usage").description("Show usage summary for the current billing period").option("--period <granularity>", "Period granularity: hour, day, week, month", "month").addHelpText("after", `
3695
3698
  Examples:
3696
3699
  $ blink usage
3697
- $ blink usage --period month
3700
+ $ blink usage --period day
3698
3701
  $ blink usage --json
3699
3702
  `).action(async (opts) => {
3700
3703
  requireToken();
@@ -3703,7 +3706,16 @@ Examples:
3703
3706
  () => appRequest(`/api/usage/summary?period=${opts.period}`)
3704
3707
  );
3705
3708
  if (isJsonMode()) return printJson(result);
3706
- printUsage(result);
3709
+ const buckets = result?.data ?? [];
3710
+ if (!buckets.length) {
3711
+ console.log(chalk23.dim("\n No usage data.\n"));
3712
+ return;
3713
+ }
3714
+ const table = createTable(["Period", "Credits", "Requests", "Cost"]);
3715
+ for (const b of buckets) {
3716
+ table.push([b.time_bucket.slice(0, 10), formatCredits(b.total_credits), String(b.total_requests), formatUsd(b.total_cost_usd)]);
3717
+ }
3718
+ console.log(table.toString());
3707
3719
  });
3708
3720
  }
3709
3721
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blinkdotnew/cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Blink CLI — full-stack cloud infrastructure from your terminal. Deploy, database, auth, storage, backend, domains, and more.",
5
5
  "bin": {
6
6
  "blink": "dist/cli.js"
@@ -1,24 +1,28 @@
1
1
  import { Command } from 'commander'
2
2
  import { appRequest } from '../lib/api-app.js'
3
3
  import { requireToken } from '../lib/auth.js'
4
- import { printJson, printKv, isJsonMode, withSpinner } from '../lib/output.js'
4
+ import { printJson, printKv, isJsonMode, withSpinner, createTable } from '../lib/output.js'
5
5
  import chalk from 'chalk'
6
6
 
7
- function printUsage(data: { total?: number; breakdown?: Array<{ category: string; amount: number }> }) {
8
- console.log()
9
- printKv('Total', `${data.total ?? 0} credits used`)
10
- const breakdown = data.breakdown ?? []
11
- if (breakdown.length) {
12
- console.log()
13
- console.log(chalk.bold('Breakdown:'))
14
- for (const item of breakdown) printKv(` ${item.category}`, `${item.amount}`)
15
- }
16
- console.log()
7
+ interface UsageBucket {
8
+ period: string
9
+ time_bucket: string
10
+ total_credits: number
11
+ total_requests: number
12
+ total_cost_usd: number
13
+ }
14
+
15
+ function formatCredits(n: number): string {
16
+ return n >= 1000 ? `${(n / 1000).toFixed(1)}k` : n.toFixed(1)
17
+ }
18
+
19
+ function formatUsd(n: number): string {
20
+ return `$${n.toFixed(2)}`
17
21
  }
18
22
 
19
23
  export function registerBillingCommands(program: Command) {
20
24
  program.command('credits')
21
- .description('Check your credit balance and tier')
25
+ .description('Check your credit usage this month')
22
26
  .addHelpText('after', `
23
27
  Examples:
24
28
  $ blink credits
@@ -30,19 +34,27 @@ Examples:
30
34
  appRequest('/api/usage/summary?period=month')
31
35
  )
32
36
  if (isJsonMode()) return printJson(result)
33
- const data = result ?? {}
37
+ const buckets: UsageBucket[] = result?.data ?? []
38
+ const current = buckets[0]
34
39
  console.log()
35
- printKv('Used', `${data.total ?? 0} credits this month`)
40
+ if (current) {
41
+ printKv('Period', current.time_bucket.slice(0, 7))
42
+ printKv('Credits', formatCredits(current.total_credits))
43
+ printKv('Requests', String(current.total_requests))
44
+ printKv('Cost', formatUsd(current.total_cost_usd))
45
+ } else {
46
+ console.log(chalk.dim(' No usage data for this month.'))
47
+ }
36
48
  console.log()
37
49
  })
38
50
 
39
51
  program.command('usage')
40
52
  .description('Show usage summary for the current billing period')
41
- .option('--period <granularity>', 'Period granularity: hour, day, week, month', 'day')
53
+ .option('--period <granularity>', 'Period granularity: hour, day, week, month', 'month')
42
54
  .addHelpText('after', `
43
55
  Examples:
44
56
  $ blink usage
45
- $ blink usage --period month
57
+ $ blink usage --period day
46
58
  $ blink usage --json
47
59
  `)
48
60
  .action(async (opts) => {
@@ -51,6 +63,15 @@ Examples:
51
63
  appRequest(`/api/usage/summary?period=${opts.period}`)
52
64
  )
53
65
  if (isJsonMode()) return printJson(result)
54
- printUsage(result)
66
+ const buckets: UsageBucket[] = result?.data ?? []
67
+ if (!buckets.length) {
68
+ console.log(chalk.dim('\n No usage data.\n'))
69
+ return
70
+ }
71
+ const table = createTable(['Period', 'Credits', 'Requests', 'Cost'])
72
+ for (const b of buckets) {
73
+ table.push([b.time_bucket.slice(0, 10), formatCredits(b.total_credits), String(b.total_requests), formatUsd(b.total_cost_usd)])
74
+ }
75
+ console.log(table.toString())
55
76
  })
56
77
  }