@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 +28 -16
- package/package.json +1 -1
- package/src/commands/billing.ts +38 -17
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
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
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
|
|
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
|
|
3684
|
+
const buckets = result?.data ?? [];
|
|
3685
|
+
const current = buckets[0];
|
|
3690
3686
|
console.log();
|
|
3691
|
-
|
|
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", "
|
|
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
|
|
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
|
-
|
|
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
package/src/commands/billing.ts
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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
|
|
37
|
+
const buckets: UsageBucket[] = result?.data ?? []
|
|
38
|
+
const current = buckets[0]
|
|
34
39
|
console.log()
|
|
35
|
-
|
|
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', '
|
|
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
|
|
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
|
-
|
|
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
|
}
|