@myapihq/cli 1.0.7 → 1.0.9

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)();
@@ -3,3 +3,4 @@ export declare function register(domain: string, flags: Record<string, string |
3
3
  export declare function importDomain(domain: string, flags: Record<string, string | boolean>): Promise<void>;
4
4
  export declare function list(flags: Record<string, string | boolean>): Promise<void>;
5
5
  export declare function settings(domain: string, flags: Record<string, string | boolean>): Promise<void>;
6
+ export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
@@ -5,6 +5,7 @@ exports.register = register;
5
5
  exports.importDomain = importDomain;
6
6
  exports.list = list;
7
7
  exports.settings = settings;
8
+ exports.run = run;
8
9
  const sdk_1 = require("@myapihq/sdk");
9
10
  const config_js_1 = require("../config.js");
10
11
  const output_js_1 = require("../output.js");
@@ -54,3 +55,34 @@ async function settings(domain, flags) {
54
55
  const res = await sdk_1.domain.getDomainSettings(config.api_key, domain);
55
56
  (0, output_js_1.printJson)(res);
56
57
  }
58
+ async function run(subcommand, args, flags) {
59
+ if (!subcommand || (flags.help && !subcommand)) {
60
+ (0, output_js_1.info)('Usage: myapi domain <subcommand>\n\nSubcommands:\n list List domains\n check Check domain availability\n register Register a domain\n import Import an existing domain\n settings Get domain settings');
61
+ return;
62
+ }
63
+ if (flags.help) {
64
+ if (subcommand === 'list')
65
+ (0, output_js_1.info)('Usage: myapi domain list\n\nLists all registered domains in your account.');
66
+ else if (subcommand === 'check')
67
+ (0, output_js_1.info)('Usage: myapi domain check <domain>\n\nChecks if a domain name is available for registration.');
68
+ else if (subcommand === 'register')
69
+ (0, output_js_1.info)('Usage: myapi domain register <domain> [--years <num>]\n\nRegisters a new domain name.');
70
+ else if (subcommand === 'import')
71
+ (0, output_js_1.info)('Usage: myapi domain import <domain> --namecheap-user <user> --namecheap-key <key>\n\nImports an existing domain from Namecheap.');
72
+ else if (subcommand === 'settings')
73
+ (0, output_js_1.info)('Usage: myapi domain settings <domain>\n\nGets the DNS settings and configuration for a domain.');
74
+ return;
75
+ }
76
+ if (subcommand === 'list')
77
+ await list(flags);
78
+ else if (subcommand === 'check')
79
+ await check(args[0], flags);
80
+ else if (subcommand === 'register')
81
+ await register(args[0], flags);
82
+ else if (subcommand === 'import')
83
+ await importDomain(args[0], flags);
84
+ else if (subcommand === 'settings')
85
+ await settings(args[0], flags);
86
+ else
87
+ (0, output_js_1.error)(`Unknown subcommand: ${subcommand}. Run "myapi domain --help" for a list of valid subcommands.`);
88
+ }
@@ -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
@@ -42,6 +42,7 @@ const keysCmd = __importStar(require("./commands/keys.js"));
42
42
  const billingCmd = __importStar(require("./commands/billing.js"));
43
43
  const orgCmd = __importStar(require("./commands/org.js"));
44
44
  const setupCmd = __importStar(require("./commands/setup.js"));
45
+ const domainCmd = __importStar(require("./commands/domain.js"));
45
46
  async function main() {
46
47
  const { args, flags } = (0, utils_js_1.parseArgs)(process.argv.slice(2));
47
48
  if (args.length === 0) {
@@ -86,7 +87,7 @@ async function main() {
86
87
  else if (subcommand === 'delete')
87
88
  await orgCmd.del(restArgs[0], flags);
88
89
  else if (subcommand === 'import')
89
- await orgCmd.importOrg(restArgs[0], flags);
90
+ await orgCmd.importOrg(restArgs, flags);
90
91
  else
91
92
  printHelp();
92
93
  break;
@@ -106,6 +107,9 @@ async function main() {
106
107
  else
107
108
  printHelp();
108
109
  break;
110
+ case 'domain':
111
+ await domainCmd.run(subcommand, restArgs, flags);
112
+ break;
109
113
  default:
110
114
  printHelp();
111
115
  process.exit(0);
@@ -131,6 +135,7 @@ Commands:
131
135
  billing Check balance and manage billing
132
136
  org Manage organizations
133
137
  setup Setup CLI credentials and view integration instructions
138
+ domain Manage domain configurations
134
139
 
135
140
  Run "myapi <command> --help" for subcommand help.`);
136
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
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
 
@@ -47,3 +47,26 @@ export async function settings(domain: string, flags: Record<string, string | bo
47
47
  const res = await sdkDomain.getDomainSettings(config.api_key, domain);
48
48
  printJson(res);
49
49
  }
50
+
51
+ export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
52
+ if (!subcommand || (flags.help && !subcommand)) {
53
+ info('Usage: myapi domain <subcommand>\n\nSubcommands:\n list List domains\n check Check domain availability\n register Register a domain\n import Import an existing domain\n settings Get domain settings');
54
+ return;
55
+ }
56
+
57
+ if (flags.help) {
58
+ if (subcommand === 'list') info('Usage: myapi domain list\n\nLists all registered domains in your account.');
59
+ else if (subcommand === 'check') info('Usage: myapi domain check <domain>\n\nChecks if a domain name is available for registration.');
60
+ else if (subcommand === 'register') info('Usage: myapi domain register <domain> [--years <num>]\n\nRegisters a new domain name.');
61
+ else if (subcommand === 'import') info('Usage: myapi domain import <domain> --namecheap-user <user> --namecheap-key <key>\n\nImports an existing domain from Namecheap.');
62
+ else if (subcommand === 'settings') info('Usage: myapi domain settings <domain>\n\nGets the DNS settings and configuration for a domain.');
63
+ return;
64
+ }
65
+
66
+ if (subcommand === 'list') await list(flags);
67
+ else if (subcommand === 'check') await check(args[0], flags);
68
+ else if (subcommand === 'register') await register(args[0], flags);
69
+ else if (subcommand === 'import') await importDomain(args[0], flags);
70
+ else if (subcommand === 'settings') await settings(args[0], flags);
71
+ else error(`Unknown subcommand: ${subcommand}. Run "myapi domain --help" for a list of valid subcommands.`);
72
+ }
@@ -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
@@ -7,6 +7,7 @@ import * as keysCmd from './commands/keys.js';
7
7
  import * as billingCmd from './commands/billing.js';
8
8
  import * as orgCmd from './commands/org.js';
9
9
  import * as setupCmd from './commands/setup.js';
10
+ import * as domainCmd from './commands/domain.js';
10
11
 
11
12
  async function main() {
12
13
  const { args, flags } = parseArgs(process.argv.slice(2));
@@ -40,7 +41,7 @@ async function main() {
40
41
  else if (subcommand === 'create') await orgCmd.create(flags);
41
42
  else if (subcommand === 'get') await orgCmd.get(restArgs[0], flags);
42
43
  else if (subcommand === 'delete') await orgCmd.del(restArgs[0], flags);
43
- else if (subcommand === 'import') await orgCmd.importOrg(restArgs[0], flags);
44
+ else if (subcommand === 'import') await orgCmd.importOrg(restArgs, flags);
44
45
  else printHelp();
45
46
  break;
46
47
  case 'billing':
@@ -54,6 +55,9 @@ async function main() {
54
55
  else if (subcommand === 'setup') await billingCmd.setup(flags);
55
56
  else printHelp();
56
57
  break;
58
+ case 'domain':
59
+ await domainCmd.run(subcommand, restArgs, flags);
60
+ break;
57
61
  default:
58
62
  printHelp();
59
63
  process.exit(0);
@@ -77,6 +81,7 @@ Commands:
77
81
  billing Check balance and manage billing
78
82
  org Manage organizations
79
83
  setup Setup CLI credentials and view integration instructions
84
+ domain Manage domain configurations
80
85
 
81
86
  Run "myapi <command> --help" for subcommand help.`);
82
87
  }