@orth/cli 0.2.5 → 0.2.6

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.
@@ -1,4 +1,5 @@
1
1
  export declare function balanceCommand(): Promise<void>;
2
2
  export declare function usageCommand(options: {
3
3
  limit: string;
4
+ days?: string;
4
5
  }): Promise<void>;
@@ -11,50 +11,73 @@ const api_js_1 = require("../api.js");
11
11
  async function balanceCommand() {
12
12
  const spinner = (0, ora_1.default)("Fetching balance...").start();
13
13
  try {
14
- // Note: This endpoint may not exist yet - placeholder
15
- const data = await (0, api_js_1.apiRequest)("/account/balance");
14
+ const data = await (0, api_js_1.apiRequest)("/credits/balance");
16
15
  spinner.stop();
17
- if (data && data.balance !== undefined) {
18
- console.log(chalk_1.default.bold("\nAccount Balance:"));
19
- console.log(chalk_1.default.green.bold(` $${data.balance.toFixed(2)} ${data.currency || "USD"}`));
20
- }
21
- else {
22
- console.log(chalk_1.default.gray("Balance information not available."));
23
- console.log(chalk_1.default.gray("Check your balance at: https://orthogonal.com/dashboard"));
24
- }
16
+ console.log(`\n ${chalk_1.default.green.bold(data.balance)}\n`);
25
17
  }
26
18
  catch (error) {
27
19
  spinner.stop();
28
- // Graceful fallback if endpoint doesn't exist
29
- console.log(chalk_1.default.gray("Balance information not available via API."));
30
- console.log(chalk_1.default.gray("Check your balance at: https://orthogonal.com/dashboard"));
20
+ const message = error instanceof Error ? error.message : String(error);
21
+ if (message.includes("401") || message.includes("Authentication")) {
22
+ console.error(chalk_1.default.red("\n Authentication failed. Check your API key with: orth login\n"));
23
+ }
24
+ else {
25
+ console.error(chalk_1.default.red(`\n Failed to fetch balance: ${message}\n`));
26
+ }
27
+ process.exit(1);
31
28
  }
32
29
  }
33
30
  async function usageCommand(options) {
34
31
  const spinner = (0, ora_1.default)("Fetching usage...").start();
35
32
  try {
36
- // Note: This endpoint may not exist yet - placeholder
37
- const data = await (0, api_js_1.apiRequest)(`/account/usage?limit=${options.limit}`);
33
+ const limit = parseInt(options.limit) || 20;
34
+ const days = parseInt(options.days || "30") || 30;
35
+ const data = await (0, api_js_1.apiRequest)(`/credits/usage?limit=${limit}&days=${days}`);
38
36
  spinner.stop();
39
- if (data?.usage && data.usage.length > 0) {
40
- console.log(chalk_1.default.bold("\nRecent API Usage:\n"));
41
- for (const item of data.usage) {
42
- const date = new Date(item.timestamp).toLocaleString();
43
- console.log(chalk_1.default.gray(date.padEnd(22)) +
44
- chalk_1.default.cyan(item.api.padEnd(15)) +
45
- chalk_1.default.white(item.path.padEnd(30)) +
46
- chalk_1.default.green(`$${item.cost.toFixed(4)}`));
47
- }
48
- console.log(chalk_1.default.bold(`\nTotal: $${data.total.toFixed(2)}`));
37
+ if (!data?.usage || data.usage.length === 0) {
38
+ console.log(chalk_1.default.gray("\n No API usage in the last " + days + " days.\n"));
39
+ return;
49
40
  }
50
- else {
51
- console.log(chalk_1.default.gray("No recent usage data available."));
41
+ console.log(chalk_1.default.bold(`\n API Usage (last ${days} days)\n`));
42
+ // Table header
43
+ console.log(chalk_1.default.gray(" " +
44
+ "Date".padEnd(18) +
45
+ "API".padEnd(20) +
46
+ "Endpoint".padEnd(32) +
47
+ "Cost".padStart(10)));
48
+ console.log(chalk_1.default.gray(" " + "─".repeat(80)));
49
+ for (const item of data.usage) {
50
+ const date = new Date(item.timestamp).toLocaleDateString("en-US", {
51
+ month: "short",
52
+ day: "numeric",
53
+ hour: "2-digit",
54
+ minute: "2-digit",
55
+ });
56
+ const statusIcon = item.status === "completed" ? "" : chalk_1.default.yellow(" ⚠");
57
+ console.log(" " +
58
+ chalk_1.default.gray(date.padEnd(18)) +
59
+ chalk_1.default.cyan(item.api.padEnd(20)) +
60
+ chalk_1.default.white((item.method + " " + item.path).substring(0, 30).padEnd(32)) +
61
+ chalk_1.default.green(item.cost.padStart(10)) +
62
+ statusIcon);
63
+ }
64
+ // Summary
65
+ if (data.totalSpent) {
66
+ console.log(chalk_1.default.gray("\n " + "─".repeat(80)));
67
+ console.log(chalk_1.default.bold(` Total: ${chalk_1.default.green(data.totalSpent)}`) +
68
+ chalk_1.default.gray(` (${data.pagination.total} calls)`));
52
69
  }
70
+ console.log();
53
71
  }
54
72
  catch (error) {
55
73
  spinner.stop();
56
- // Graceful fallback if endpoint doesn't exist
57
- console.log(chalk_1.default.gray("Usage information not available via API."));
58
- console.log(chalk_1.default.gray("Check your usage at: https://orthogonal.com/dashboard/usage"));
74
+ const message = error instanceof Error ? error.message : String(error);
75
+ if (message.includes("401") || message.includes("Authentication")) {
76
+ console.error(chalk_1.default.red("\n Authentication failed. Check your API key with: orth login\n"));
77
+ }
78
+ else {
79
+ console.error(chalk_1.default.red(`\n Failed to fetch usage: ${message}\n`));
80
+ }
81
+ process.exit(1);
59
82
  }
60
83
  }
package/dist/index.js CHANGED
@@ -67,7 +67,8 @@ program
67
67
  program
68
68
  .command("usage")
69
69
  .description("Show recent API usage")
70
- .option("-l, --limit <number>", "Number of recent calls", "10")
70
+ .option("-l, --limit <number>", "Number of recent calls", "20")
71
+ .option("-d, --days <number>", "Number of days to look back", "30")
71
72
  .action(asyncAction(async (options) => {
72
73
  (0, analytics_js_1.trackEvent)("usage");
73
74
  await (0, account_js_1.usageCommand)(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orth/cli",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "CLI to access all APIs and skills on the Orthogonal platform",
5
5
  "main": "dist/index.js",
6
6
  "bin": {