@myapihq/cli 1.0.7 → 1.0.8

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.
@@ -21,25 +21,45 @@ async function balance(flags) {
21
21
  }
22
22
  async function history(flags) {
23
23
  if (flags.help) {
24
- (0, output_js_1.info)('Usage: myapi billing history\n\nShows your recent billing transactions and top-ups.');
24
+ (0, output_js_1.info)('Usage: myapi billing history [--json]\n\nShows your recent billing transactions and top-ups.');
25
25
  return;
26
26
  }
27
27
  const config = (0, config_js_1.requireConfig)();
28
28
  const items = await sdk_1.hq.getBillingHistory(config.api_key);
29
- (0, output_js_1.printTable)(items);
29
+ if (flags.json) {
30
+ (0, output_js_1.printJson)(items);
31
+ return;
32
+ }
33
+ const formattedItems = items.map(item => {
34
+ // Attempt to parse the date cleanly (handling Go's "+0000 UTC" suffix)
35
+ const cleanDate = item.created_at.replace(' +0000 UTC', 'Z');
36
+ const date = new Date(cleanDate);
37
+ const dateStr = isNaN(date.getTime()) ? item.created_at : date.toLocaleString();
38
+ // Format amount
39
+ const isNegative = item.amount_cents < 0;
40
+ const absAmount = Math.abs(item.amount_cents) / 100;
41
+ const amountStr = `${isNegative ? '-' : ''}$${absAmount.toFixed(2)}`;
42
+ return {
43
+ Type: item.type || 'unknown',
44
+ Amount: amountStr,
45
+ Status: item.status ? item.status.charAt(0).toUpperCase() + item.status.slice(1) : '',
46
+ Date: dateStr
47
+ };
48
+ });
49
+ (0, output_js_1.printTable)(formattedItems);
30
50
  }
31
51
  async function topup(amountStr, flags) {
32
52
  if (flags.help) {
33
- (0, output_js_1.info)('Usage: myapi billing topup <amount>\n\nAdds funds to your account balance using your saved payment method.\nExample: myapi billing topup 10.00');
53
+ (0, output_js_1.info)('Usage: myapi billing topup <amount_in_dollars>\n\nAdds funds to your account balance using your saved payment method.\nExample: myapi billing topup 10.00');
34
54
  return;
35
55
  }
36
56
  if (!amountStr) {
37
- (0, output_js_1.error)("Missing amount. Usage: myapi billing topup <amount>");
57
+ (0, output_js_1.error)("Missing amount. Usage: myapi billing topup <amount_in_dollars>");
38
58
  return;
39
59
  }
40
60
  const amount = parseFloat(amountStr);
41
61
  if (isNaN(amount)) {
42
- (0, output_js_1.error)("Invalid amount. Must be a number (e.g., 10.00)");
62
+ (0, output_js_1.error)("Invalid amount. Must be a number in dollars (e.g., 10.00)");
43
63
  return;
44
64
  }
45
65
  const config = (0, config_js_1.requireConfig)();
@@ -63,7 +63,25 @@ async function list(flags) {
63
63
  }
64
64
  const config = (0, config_js_1.requireConfig)();
65
65
  const keysList = await sdk_1.hq.listApiKeys(config.api_key);
66
- (0, output_js_1.printTable)(keysList);
66
+ const formattedKeys = keysList.map(k => {
67
+ // Format creation date
68
+ const createdDate = new Date(k.created_at);
69
+ const createdStr = isNaN(createdDate.getTime()) ? k.created_at : createdDate.toLocaleString();
70
+ // Format last used date
71
+ let lastUsedStr = 'Never';
72
+ if (k.last_used_at) {
73
+ const lastUsedDate = new Date(k.last_used_at);
74
+ lastUsedStr = isNaN(lastUsedDate.getTime()) ? k.last_used_at : lastUsedDate.toLocaleString();
75
+ }
76
+ return {
77
+ Name: k.name || 'Unnamed',
78
+ Prefix: k.prefix,
79
+ ID: k.id,
80
+ 'Created At': createdStr,
81
+ 'Last Used': lastUsedStr
82
+ };
83
+ });
84
+ (0, output_js_1.printTable)(formattedKeys);
67
85
  }
68
86
  async function revoke(id, flags) {
69
87
  if (flags.help) {
@@ -2,4 +2,4 @@ export declare function create(flags: Record<string, string | boolean>): Promise
2
2
  export declare function list(flags: Record<string, string | boolean>): Promise<void>;
3
3
  export declare function get(id: string, flags: Record<string, string | boolean>): Promise<void>;
4
4
  export declare function del(id: string, flags: Record<string, string | boolean>): Promise<void>;
5
- export declare function importOrg(domain: string, flags: Record<string, string | boolean>): Promise<void>;
5
+ export declare function importOrg(args: string[], flags: Record<string, string | boolean>): Promise<void>;
@@ -33,12 +33,12 @@ async function create(flags) {
33
33
  }
34
34
  async function list(flags) {
35
35
  if (flags.help) {
36
- (0, output_js_1.info)('Usage: myapi org list\n\nLists all organizations in your account.');
36
+ (0, output_js_1.info)('Usage: myapi org list\n\nLists all organizations in your account as JSON.');
37
37
  return;
38
38
  }
39
39
  const config = (0, config_js_1.requireConfig)();
40
40
  const orgs = await sdk_1.hq.listOrgs(config.api_key);
41
- (0, output_js_1.printTable)(orgs);
41
+ (0, output_js_1.printJson)(orgs);
42
42
  }
43
43
  async function get(id, flags) {
44
44
  if (flags.help) {
@@ -66,17 +66,19 @@ async function del(id, flags) {
66
66
  await sdk_1.hq.deleteOrg(config.api_key, id);
67
67
  (0, output_js_1.success)(`Org ${id} deleted`);
68
68
  }
69
- async function importOrg(domain, flags) {
69
+ async function importOrg(args, flags) {
70
70
  if (flags.help) {
71
- (0, output_js_1.info)('Usage: myapi org import <domain>\n\nAutomatically extracts brand info from an existing website and creates an organization.');
71
+ (0, output_js_1.info)('Usage: myapi org import <org_id> <domain>\n\nAutomatically extracts brand info from an existing website and updates the organization.\n\nNote: You must create a placeholder organization first using `myapi org create` to get an org_id.');
72
72
  return;
73
73
  }
74
- if (!domain) {
75
- (0, output_js_1.error)("Missing domain. Usage: myapi org import <domain>");
74
+ const orgId = args[0];
75
+ const domain = args[1];
76
+ if (!orgId || !domain) {
77
+ (0, output_js_1.error)("Missing arguments. Usage: myapi org import <org_id> <domain>");
76
78
  return;
77
79
  }
78
80
  const config = (0, config_js_1.requireConfig)();
79
- const result = await sdk_1.hq.importOrg(config.api_key, domain);
81
+ const result = await sdk_1.hq.importOrg(config.api_key, orgId, domain);
80
82
  const importId = result.job_id;
81
83
  process.stdout.write("Importing ");
82
84
  const chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
package/dist/index.js CHANGED
@@ -86,7 +86,7 @@ async function main() {
86
86
  else if (subcommand === 'delete')
87
87
  await orgCmd.del(restArgs[0], flags);
88
88
  else if (subcommand === 'import')
89
- await orgCmd.importOrg(restArgs[0], flags);
89
+ await orgCmd.importOrg(restArgs, flags);
90
90
  else
91
91
  printHelp();
92
92
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "MyAPI command-line interface",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  import { hq } from '@myapihq/sdk';
2
2
  import { requireConfig } from '../config.js';
3
- import { success, error, printTable, info } from '../output.js';
3
+ import { success, error, printTable, info, printJson } from '../output.js';
4
4
 
5
5
  export async function balance(flags: Record<string, string | boolean>) {
6
6
  if (flags.help) {
@@ -19,26 +19,51 @@ export async function balance(flags: Record<string, string | boolean>) {
19
19
 
20
20
  export async function history(flags: Record<string, string | boolean>) {
21
21
  if (flags.help) {
22
- info('Usage: myapi billing history\n\nShows your recent billing transactions and top-ups.');
22
+ info('Usage: myapi billing history [--json]\n\nShows your recent billing transactions and top-ups.');
23
23
  return;
24
24
  }
25
25
  const config = requireConfig();
26
26
  const items = await hq.getBillingHistory(config.api_key);
27
- printTable(items as unknown as Record<string, unknown>[]);
27
+
28
+ if (flags.json) {
29
+ printJson(items);
30
+ return;
31
+ }
32
+
33
+ const formattedItems = items.map(item => {
34
+ // Attempt to parse the date cleanly (handling Go's "+0000 UTC" suffix)
35
+ const cleanDate = item.created_at.replace(' +0000 UTC', 'Z');
36
+ const date = new Date(cleanDate);
37
+ const dateStr = isNaN(date.getTime()) ? item.created_at : date.toLocaleString();
38
+
39
+ // Format amount
40
+ const isNegative = item.amount_cents < 0;
41
+ const absAmount = Math.abs(item.amount_cents) / 100;
42
+ const amountStr = `${isNegative ? '-' : ''}$${absAmount.toFixed(2)}`;
43
+
44
+ return {
45
+ Type: item.type || 'unknown',
46
+ Amount: amountStr,
47
+ Status: item.status ? item.status.charAt(0).toUpperCase() + item.status.slice(1) : '',
48
+ Date: dateStr
49
+ };
50
+ });
51
+
52
+ printTable(formattedItems as unknown as Record<string, unknown>[]);
28
53
  }
29
54
 
30
55
  export async function topup(amountStr: string, flags: Record<string, string | boolean>) {
31
56
  if (flags.help) {
32
- info('Usage: myapi billing topup <amount>\n\nAdds funds to your account balance using your saved payment method.\nExample: myapi billing topup 10.00');
57
+ info('Usage: myapi billing topup <amount_in_dollars>\n\nAdds funds to your account balance using your saved payment method.\nExample: myapi billing topup 10.00');
33
58
  return;
34
59
  }
35
60
  if (!amountStr) {
36
- error("Missing amount. Usage: myapi billing topup <amount>");
61
+ error("Missing amount. Usage: myapi billing topup <amount_in_dollars>");
37
62
  return;
38
63
  }
39
64
  const amount = parseFloat(amountStr);
40
65
  if (isNaN(amount)) {
41
- error("Invalid amount. Must be a number (e.g., 10.00)");
66
+ error("Invalid amount. Must be a number in dollars (e.g., 10.00)");
42
67
  return;
43
68
  }
44
69
 
@@ -29,7 +29,29 @@ export async function list(flags: Record<string, string | boolean>) {
29
29
  }
30
30
  const config = requireConfig();
31
31
  const keysList = await hq.listApiKeys(config.api_key);
32
- printTable(keysList as unknown as Record<string, unknown>[]);
32
+
33
+ const formattedKeys = keysList.map(k => {
34
+ // Format creation date
35
+ const createdDate = new Date(k.created_at);
36
+ const createdStr = isNaN(createdDate.getTime()) ? k.created_at : createdDate.toLocaleString();
37
+
38
+ // Format last used date
39
+ let lastUsedStr = 'Never';
40
+ if (k.last_used_at) {
41
+ const lastUsedDate = new Date(k.last_used_at);
42
+ lastUsedStr = isNaN(lastUsedDate.getTime()) ? k.last_used_at : lastUsedDate.toLocaleString();
43
+ }
44
+
45
+ return {
46
+ Name: k.name || 'Unnamed',
47
+ Prefix: k.prefix,
48
+ ID: k.id,
49
+ 'Created At': createdStr,
50
+ 'Last Used': lastUsedStr
51
+ };
52
+ });
53
+
54
+ printTable(formattedKeys as unknown as Record<string, unknown>[]);
33
55
  }
34
56
 
35
57
  export async function revoke(id: string, flags: Record<string, string | boolean>) {
@@ -25,12 +25,12 @@ export async function create(flags: Record<string, string | boolean>) {
25
25
 
26
26
  export async function list(flags: Record<string, string | boolean>) {
27
27
  if (flags.help) {
28
- info('Usage: myapi org list\n\nLists all organizations in your account.');
28
+ info('Usage: myapi org list\n\nLists all organizations in your account as JSON.');
29
29
  return;
30
30
  }
31
31
  const config = requireConfig();
32
32
  const orgs = await hq.listOrgs(config.api_key);
33
- printTable(orgs as unknown as Record<string, unknown>[]);
33
+ printJson(orgs);
34
34
  }
35
35
 
36
36
  export async function get(id: string, flags: Record<string, string | boolean>) {
@@ -61,18 +61,21 @@ export async function del(id: string, flags: Record<string, string | boolean>) {
61
61
  success(`Org ${id} deleted`);
62
62
  }
63
63
 
64
- export async function importOrg(domain: string, flags: Record<string, string | boolean>) {
64
+ export async function importOrg(args: string[], flags: Record<string, string | boolean>) {
65
65
  if (flags.help) {
66
- info('Usage: myapi org import <domain>\n\nAutomatically extracts brand info from an existing website and creates an organization.');
66
+ info('Usage: myapi org import <org_id> <domain>\n\nAutomatically extracts brand info from an existing website and updates the organization.\n\nNote: You must create a placeholder organization first using `myapi org create` to get an org_id.');
67
67
  return;
68
68
  }
69
- if (!domain) {
70
- error("Missing domain. Usage: myapi org import <domain>");
69
+ const orgId = args[0];
70
+ const domain = args[1];
71
+
72
+ if (!orgId || !domain) {
73
+ error("Missing arguments. Usage: myapi org import <org_id> <domain>");
71
74
  return;
72
75
  }
73
76
  const config = requireConfig();
74
77
 
75
- const result = await hq.importOrg(config.api_key, domain);
78
+ const result = await hq.importOrg(config.api_key, orgId, domain);
76
79
  const importId = result.job_id;
77
80
 
78
81
  process.stdout.write("Importing ");
package/src/index.ts CHANGED
@@ -40,7 +40,7 @@ async function main() {
40
40
  else if (subcommand === 'create') await orgCmd.create(flags);
41
41
  else if (subcommand === 'get') await orgCmd.get(restArgs[0], flags);
42
42
  else if (subcommand === 'delete') await orgCmd.del(restArgs[0], flags);
43
- else if (subcommand === 'import') await orgCmd.importOrg(restArgs[0], flags);
43
+ else if (subcommand === 'import') await orgCmd.importOrg(restArgs, flags);
44
44
  else printHelp();
45
45
  break;
46
46
  case 'billing':