@myapihq/cli 1.0.13 → 1.0.14

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.
@@ -0,0 +1,4 @@
1
+ export declare function setOrg(id: string, flags: Record<string, string | boolean>): Promise<void>;
2
+ export declare function setDomain(domain: string, flags: Record<string, string | boolean>): Promise<void>;
3
+ export declare function view(flags: Record<string, string | boolean>): Promise<void>;
4
+ export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setOrg = setOrg;
4
+ exports.setDomain = setDomain;
5
+ exports.view = view;
6
+ exports.run = run;
7
+ const config_js_1 = require("../config.js");
8
+ const output_js_1 = require("../output.js");
9
+ async function setOrg(id, flags) {
10
+ if (!id || flags.help) {
11
+ (0, output_js_1.info)("Usage: myapi config set-org <id>\n\nSets a default organization ID for subsequent commands.");
12
+ return;
13
+ }
14
+ const config = (0, config_js_1.requireConfig)();
15
+ config.default_org = id;
16
+ (0, config_js_1.saveConfig)(config);
17
+ (0, output_js_1.success)(`Default organization set to: ${id}`);
18
+ }
19
+ async function setDomain(domain, flags) {
20
+ if (!domain || flags.help) {
21
+ (0, output_js_1.info)("Usage: myapi config set-domain <domain>\n\nSets a default domain for subsequent commands.");
22
+ return;
23
+ }
24
+ const config = (0, config_js_1.requireConfig)();
25
+ config.default_domain = domain;
26
+ (0, config_js_1.saveConfig)(config);
27
+ (0, output_js_1.success)(`Default domain set to: ${domain}`);
28
+ }
29
+ async function view(flags) {
30
+ if (flags.help) {
31
+ (0, output_js_1.info)("Usage: myapi config view\n\nViews current config settings.");
32
+ return;
33
+ }
34
+ const config = (0, config_js_1.requireConfig)();
35
+ (0, output_js_1.info)(`Default Org: ${config.default_org || 'Not set'}`);
36
+ (0, output_js_1.info)(`Default Domain: ${config.default_domain || 'Not set'}`);
37
+ }
38
+ async function run(subcommand, args, flags) {
39
+ if (!subcommand || (flags.help && !subcommand)) {
40
+ (0, output_js_1.info)('Usage: myapi config <subcommand>\n\nSubcommands:\n view View current config\n set-org Set default organization\n set-domain Set default domain');
41
+ return;
42
+ }
43
+ if (subcommand === 'view')
44
+ await view(flags);
45
+ else if (subcommand === 'set-org')
46
+ await setOrg(args[0], flags);
47
+ else if (subcommand === 'set-domain')
48
+ await setDomain(args[0], flags);
49
+ else
50
+ (0, output_js_1.error)(`Unknown subcommand: ${subcommand}. Run "myapi config --help" for a list of valid subcommands.`);
51
+ }
@@ -1,9 +1,9 @@
1
- export declare function check(domain: string, flags: Record<string, string | boolean>): Promise<void>;
2
- export declare function register(domain: string, flags: Record<string, string | boolean>): Promise<void>;
3
- export declare function importDomain(domain: string, flags: Record<string, string | boolean>): Promise<void>;
1
+ export declare function check(domainArg: string, flags: Record<string, string | boolean>): Promise<void>;
2
+ export declare function register(domainArg: string, flags: Record<string, string | boolean>): Promise<void>;
3
+ export declare function importDomain(domainArg: string, flags: Record<string, string | boolean>): Promise<void>;
4
4
  export declare function list(flags: Record<string, string | boolean>): Promise<void>;
5
- export declare function assign(domain: string, flags: Record<string, string | boolean>): Promise<void>;
6
- export declare function unassign(domain: string, flags: Record<string, string | boolean>): Promise<void>;
7
- export declare function settings(domain: string, flags: Record<string, string | boolean>): Promise<void>;
8
- export declare function updateSettings(domain: string, flags: Record<string, string | boolean>): Promise<void>;
5
+ export declare function assign(domainArg: string, flags: Record<string, string | boolean>): Promise<void>;
6
+ export declare function unassign(domainArg: string, flags: Record<string, string | boolean>): Promise<void>;
7
+ export declare function settings(domainArg: string, flags: Record<string, string | boolean>): Promise<void>;
8
+ export declare function updateSettings(domainArg: string, flags: Record<string, string | boolean>): Promise<void>;
9
9
  export declare function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>): Promise<void>;
@@ -12,11 +12,12 @@ exports.run = run;
12
12
  const sdk_1 = require("@myapihq/sdk");
13
13
  const config_js_1 = require("../config.js");
14
14
  const output_js_1 = require("../output.js");
15
- async function check(domain, flags) {
16
- const orgId = flags.org;
17
- if (!orgId || !domain)
18
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain check <domain> --org <id>");
15
+ async function check(domainArg, flags) {
19
16
  const config = (0, config_js_1.requireConfig)();
17
+ const orgId = flags.org || config.default_org;
18
+ const domain = domainArg || config.default_domain;
19
+ if (!orgId || !domain)
20
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain check <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
20
21
  const res = await sdk_1.domain.checkDomain(config.api_key, orgId, domain);
21
22
  if (res.available) {
22
23
  (0, output_js_1.info)(`${domain} — Available ✓ Price: $${(res.price_cents / 100).toFixed(2)}/yr`);
@@ -25,23 +26,25 @@ async function check(domain, flags) {
25
26
  (0, output_js_1.info)(`Not available ✗`);
26
27
  }
27
28
  }
28
- async function register(domain, flags) {
29
- const orgId = flags.org;
29
+ async function register(domainArg, flags) {
30
+ const config = (0, config_js_1.requireConfig)();
31
+ const orgId = flags.org || config.default_org;
32
+ const domain = domainArg || config.default_domain;
30
33
  if (!orgId || !domain)
31
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain register <domain> --org <id> [--years <num>]");
34
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain register <domain> --org <id> [--years <num>]\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
32
35
  const years = parseInt(flags.years) || 1;
33
- const config = (0, config_js_1.requireConfig)();
34
36
  const res = await sdk_1.domain.registerDomain(config.api_key, orgId, domain, years);
35
37
  (0, output_js_1.success)(`Registered ${domain}!\n${JSON.stringify(res, null, 2)}`);
36
38
  }
37
- async function importDomain(domain, flags) {
38
- const orgId = flags.org;
39
+ async function importDomain(domainArg, flags) {
40
+ const config = (0, config_js_1.requireConfig)();
41
+ const orgId = flags.org || config.default_org;
42
+ const domain = domainArg || config.default_domain;
39
43
  if (!orgId || !domain)
40
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
44
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
41
45
  if (!flags['namecheap-user'] || !flags['namecheap-key']) {
42
46
  (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
43
47
  }
44
- const config = (0, config_js_1.requireConfig)();
45
48
  await sdk_1.domain.importDomain(config.api_key, orgId, {
46
49
  domain,
47
50
  namecheap_api_user: flags['namecheap-user'],
@@ -50,44 +53,48 @@ async function importDomain(domain, flags) {
50
53
  (0, output_js_1.success)(`Imported ${domain}`);
51
54
  }
52
55
  async function list(flags) {
53
- const orgId = flags.org;
54
- if (!orgId)
55
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain list --org <id> [--filter=all|unassigned|org]");
56
56
  const config = (0, config_js_1.requireConfig)();
57
+ const orgId = flags.org || config.default_org;
58
+ if (!orgId)
59
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain list --org <id> [--filter=all|unassigned|org]\n(Or set a default org via: myapi config set-org <id>)");
57
60
  const filter = flags.filter;
58
61
  const domains = await sdk_1.domain.listDomains(config.api_key, orgId, filter);
59
62
  (0, output_js_1.printTable)(domains);
60
63
  }
61
- async function assign(domain, flags) {
62
- const orgId = flags.org;
64
+ async function assign(domainArg, flags) {
65
+ const config = (0, config_js_1.requireConfig)();
66
+ const orgId = flags.org || config.default_org;
67
+ const domain = domainArg || config.default_domain;
63
68
  const targetOrgId = flags.target;
64
69
  if (!orgId || !domain || !targetOrgId)
65
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain assign <domain> --org <id> --target <target_org_id>");
66
- const config = (0, config_js_1.requireConfig)();
70
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain assign <domain> --org <id> --target <target_org_id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
67
71
  const res = await sdk_1.domain.assignDomain(config.api_key, orgId, domain, targetOrgId);
68
72
  (0, output_js_1.success)(`Assigned ${domain} to org ${targetOrgId}`);
69
73
  }
70
- async function unassign(domain, flags) {
71
- const orgId = flags.org;
72
- if (!orgId || !domain)
73
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain unassign <domain> --org <id>");
74
+ async function unassign(domainArg, flags) {
74
75
  const config = (0, config_js_1.requireConfig)();
76
+ const orgId = flags.org || config.default_org;
77
+ const domain = domainArg || config.default_domain;
78
+ if (!orgId || !domain)
79
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain unassign <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
75
80
  const res = await sdk_1.domain.unassignDomain(config.api_key, orgId, domain);
76
81
  (0, output_js_1.success)(`Unassigned ${domain} from org ${orgId}`);
77
82
  }
78
- async function settings(domain, flags) {
79
- const orgId = flags.org;
80
- if (!orgId || !domain)
81
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain settings <domain> --org <id>");
83
+ async function settings(domainArg, flags) {
82
84
  const config = (0, config_js_1.requireConfig)();
85
+ const orgId = flags.org || config.default_org;
86
+ const domain = domainArg || config.default_domain;
87
+ if (!orgId || !domain)
88
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain settings <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
83
89
  const res = await sdk_1.domain.getDomainSettings(config.api_key, orgId, domain);
84
90
  (0, output_js_1.printJson)(res);
85
91
  }
86
- async function updateSettings(domain, flags) {
87
- const orgId = flags.org;
88
- if (!orgId || !domain)
89
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain update-settings <domain> --org <id> [--security=...] [--browser-check=...] [--purge-cache]");
92
+ async function updateSettings(domainArg, flags) {
90
93
  const config = (0, config_js_1.requireConfig)();
94
+ const orgId = flags.org || config.default_org;
95
+ const domain = domainArg || config.default_domain;
96
+ if (!orgId || !domain)
97
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi domain update-settings <domain> --org <id> [--security=...] [--browser-check=...] [--purge-cache]\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
91
98
  const payload = {};
92
99
  if (flags.security)
93
100
  payload.security_level = flags.security;
@@ -14,28 +14,29 @@ const config_js_1 = require("../config.js");
14
14
  const output_js_1 = require("../output.js");
15
15
  const utils_js_1 = require("../utils.js");
16
16
  async function createMailbox(flags) {
17
- const orgId = flags.org;
18
- if (!orgId || !flags.domain || !flags.username) {
19
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email create-mailbox --org <id> --domain <domain> --username <user>");
20
- }
21
17
  const config = (0, config_js_1.requireConfig)();
22
- const address = await sdk_1.email.createMailbox(config.api_key, orgId, flags.domain, flags.username);
18
+ const orgId = flags.org || config.default_org;
19
+ const domain = flags.domain || config.default_domain;
20
+ if (!orgId || !domain || !flags.username) {
21
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email create-mailbox --org <id> --domain <domain> --username <user>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
22
+ }
23
+ const address = await sdk_1.email.createMailbox(config.api_key, orgId, domain, flags.username);
23
24
  (0, output_js_1.success)(`Mailbox created: ${address.address}`);
24
25
  }
25
26
  async function listMailboxes(flags) {
26
- const orgId = flags.org;
27
- if (!orgId)
28
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id>");
29
27
  const config = (0, config_js_1.requireConfig)();
28
+ const orgId = flags.org || config.default_org;
29
+ if (!orgId)
30
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id>\n(Or set a default org via: myapi config set-org <id>)");
30
31
  const mailboxes = await sdk_1.email.listMailboxes(config.api_key, orgId);
31
32
  (0, output_js_1.printTable)(mailboxes);
32
33
  }
33
34
  async function send(flags) {
34
- const orgId = flags.org;
35
+ const config = (0, config_js_1.requireConfig)();
36
+ const orgId = flags.org || config.default_org;
35
37
  if (!orgId || !flags.from || !flags.to || !flags.subject || !flags.body) {
36
38
  (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>");
37
39
  }
38
- const config = (0, config_js_1.requireConfig)();
39
40
  const res = await sdk_1.email.sendEmail(config.api_key, orgId, {
40
41
  from: flags.from,
41
42
  to: [flags.to],
@@ -45,27 +46,27 @@ async function send(flags) {
45
46
  (0, output_js_1.success)(`Email sent! Message ID: ${res.message_id}`);
46
47
  }
47
48
  async function inbox(address, flags) {
48
- const orgId = flags.org;
49
+ const config = (0, config_js_1.requireConfig)();
50
+ const orgId = flags.org || config.default_org;
49
51
  if (!orgId || !address)
50
52
  (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email inbox <address> --org <id>");
51
- const config = (0, config_js_1.requireConfig)();
52
53
  const messages = await sdk_1.email.getInbox(config.api_key, orgId, address);
53
54
  (0, output_js_1.printTable)(messages);
54
55
  }
55
56
  async function listTemplates(flags) {
56
- const orgId = flags.org;
57
- if (!orgId)
58
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-templates --org <id>");
59
57
  const config = (0, config_js_1.requireConfig)();
58
+ const orgId = flags.org || config.default_org;
59
+ if (!orgId)
60
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-templates --org <id>\n(Or set a default org via: myapi config set-org <id>)");
60
61
  const templates = await sdk_1.email.listTemplates(config.api_key, orgId);
61
62
  (0, output_js_1.printTable)(templates);
62
63
  }
63
64
  async function generateTemplate(flags) {
64
- const orgId = flags.org;
65
+ const config = (0, config_js_1.requireConfig)();
66
+ const orgId = flags.org || config.default_org;
65
67
  if (!orgId || !flags.prompt || !flags.name) {
66
68
  (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email generate-template --org <id> --prompt <str> --name <str>");
67
69
  }
68
- const config = (0, config_js_1.requireConfig)();
69
70
  const job = await sdk_1.email.generateTemplate(config.api_key, orgId, {
70
71
  prompt: flags.prompt,
71
72
  name: flags.name
@@ -93,18 +94,18 @@ async function generateTemplate(flags) {
93
94
  (0, output_js_1.error)("Template generation timed out");
94
95
  }
95
96
  async function listCampaigns(flags) {
96
- const orgId = flags.org;
97
- if (!orgId)
98
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-campaigns --org <id>");
99
97
  const config = (0, config_js_1.requireConfig)();
98
+ const orgId = flags.org || config.default_org;
99
+ if (!orgId)
100
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email list-campaigns --org <id>\n(Or set a default org via: myapi config set-org <id>)");
100
101
  const campaigns = await sdk_1.email.listCampaigns(config.api_key, orgId);
101
102
  (0, output_js_1.printTable)(campaigns);
102
103
  }
103
104
  async function campaignStats(id, flags) {
104
- const orgId = flags.org;
105
+ const config = (0, config_js_1.requireConfig)();
106
+ const orgId = flags.org || config.default_org;
105
107
  if (!orgId || !id)
106
108
  (0, output_js_1.error)("Missing required arguments.\nUsage: myapi email campaign-stats <id> --org <id>");
107
- const config = (0, config_js_1.requireConfig)();
108
109
  const stats = await sdk_1.email.getCampaignStats(config.api_key, orgId, id);
109
110
  (0, output_js_1.printJson)(stats);
110
111
  }
@@ -58,11 +58,15 @@ async function createNew(flags) {
58
58
  }
59
59
  async function list(flags) {
60
60
  if (flags.help) {
61
- (0, output_js_1.info)('Usage: myapi keys list\n\nLists all API keys associated with your account.');
61
+ (0, output_js_1.info)('Usage: myapi keys list [--json]\n\nLists all API keys associated with your account.');
62
62
  return;
63
63
  }
64
64
  const config = (0, config_js_1.requireConfig)();
65
65
  const keysList = await sdk_1.hq.listApiKeys(config.api_key);
66
+ if (flags.json) {
67
+ (0, output_js_1.printJson)(keysList);
68
+ return;
69
+ }
66
70
  const formattedKeys = keysList.map(k => {
67
71
  // Format creation date
68
72
  const createdDate = new Date(k.created_at);
@@ -71,13 +71,13 @@ async function importOrg(args, flags) {
71
71
  (0, output_js_1.info)('Usage: myapi org import <domain> --org <id>\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
- const domain = args[0];
75
- const orgId = flags.org;
74
+ const config = (0, config_js_1.requireConfig)();
75
+ const domain = args[0] || config.default_domain;
76
+ const orgId = flags.org || config.default_org;
76
77
  if (!domain || !orgId) {
77
- (0, output_js_1.error)("Missing required arguments.\nUsage: myapi org import <domain> --org <id>");
78
+ (0, output_js_1.error)("Missing required arguments.\nUsage: myapi org import <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
78
79
  return;
79
80
  }
80
- const config = (0, config_js_1.requireConfig)();
81
81
  const result = await sdk_1.hq.importOrg(config.api_key, orgId, domain);
82
82
  const importId = result.job_id;
83
83
  process.stdout.write("Importing ");
package/dist/config.d.ts CHANGED
@@ -2,6 +2,8 @@ export interface Config {
2
2
  api_key: string;
3
3
  account_id: string;
4
4
  pin: string;
5
+ default_org?: string;
6
+ default_domain?: string;
5
7
  }
6
8
  export declare function loadConfig(): Config | null;
7
9
  export declare function saveConfig(config: Config): void;
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 configCmd = __importStar(require("./commands/config.js"));
45
46
  const domainCmd = __importStar(require("./commands/domain.js"));
46
47
  const emailCmd = __importStar(require("./commands/email.js"));
47
48
  async function main() {
@@ -108,6 +109,9 @@ async function main() {
108
109
  else
109
110
  printHelp();
110
111
  break;
112
+ case 'config':
113
+ await configCmd.run(subcommand, restArgs, flags);
114
+ break;
111
115
  case 'domain':
112
116
  await domainCmd.run(subcommand, restArgs, flags);
113
117
  break;
@@ -139,6 +143,7 @@ Commands:
139
143
  billing Check balance and manage billing
140
144
  org Manage organizations
141
145
  setup Setup CLI credentials and view integration instructions
146
+ config Manage CLI defaults like org_id and domain
142
147
  domain Manage domain configurations
143
148
  email Send emails and manage templates
144
149
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "MyAPI command-line interface",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -0,0 +1,46 @@
1
+ import { requireConfig, saveConfig } from '../config.js';
2
+ import { success, error, info } from '../output.js';
3
+
4
+ export async function setOrg(id: string, flags: Record<string, string | boolean>) {
5
+ if (!id || flags.help) {
6
+ info("Usage: myapi config set-org <id>\n\nSets a default organization ID for subsequent commands.");
7
+ return;
8
+ }
9
+ const config = requireConfig();
10
+ config.default_org = id;
11
+ saveConfig(config);
12
+ success(`Default organization set to: ${id}`);
13
+ }
14
+
15
+ export async function setDomain(domain: string, flags: Record<string, string | boolean>) {
16
+ if (!domain || flags.help) {
17
+ info("Usage: myapi config set-domain <domain>\n\nSets a default domain for subsequent commands.");
18
+ return;
19
+ }
20
+ const config = requireConfig();
21
+ config.default_domain = domain;
22
+ saveConfig(config);
23
+ success(`Default domain set to: ${domain}`);
24
+ }
25
+
26
+ export async function view(flags: Record<string, string | boolean>) {
27
+ if (flags.help) {
28
+ info("Usage: myapi config view\n\nViews current config settings.");
29
+ return;
30
+ }
31
+ const config = requireConfig();
32
+ info(`Default Org: ${config.default_org || 'Not set'}`);
33
+ info(`Default Domain: ${config.default_domain || 'Not set'}`);
34
+ }
35
+
36
+ export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
37
+ if (!subcommand || (flags.help && !subcommand)) {
38
+ info('Usage: myapi config <subcommand>\n\nSubcommands:\n view View current config\n set-org Set default organization\n set-domain Set default domain');
39
+ return;
40
+ }
41
+
42
+ if (subcommand === 'view') await view(flags);
43
+ else if (subcommand === 'set-org') await setOrg(args[0], flags);
44
+ else if (subcommand === 'set-domain') await setDomain(args[0], flags);
45
+ else error(`Unknown subcommand: ${subcommand}. Run "myapi config --help" for a list of valid subcommands.`);
46
+ }
@@ -2,10 +2,11 @@ import { domain as sdkDomain } from '@myapihq/sdk';
2
2
  import { requireConfig } from '../config.js';
3
3
  import { success, error, info, printTable, printJson } from '../output.js';
4
4
 
5
- export async function check(domain: string, flags: Record<string, string | boolean>) {
6
- const orgId = flags.org as string;
7
- if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain check <domain> --org <id>");
5
+ export async function check(domainArg: string, flags: Record<string, string | boolean>) {
8
6
  const config = requireConfig();
7
+ const orgId = (flags.org as string) || config.default_org;
8
+ const domain = domainArg || (config.default_domain as string);
9
+ if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain check <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
9
10
  const res = await sdkDomain.checkDomain(config.api_key, orgId, domain);
10
11
  if (res.available) {
11
12
  info(`${domain} — Available ✓ Price: $${(res.price_cents / 100).toFixed(2)}/yr`);
@@ -14,22 +15,24 @@ export async function check(domain: string, flags: Record<string, string | boole
14
15
  }
15
16
  }
16
17
 
17
- export async function register(domain: string, flags: Record<string, string | boolean>) {
18
- const orgId = flags.org as string;
19
- if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain register <domain> --org <id> [--years <num>]");
20
- const years = parseInt(flags.years as string) || 1;
18
+ export async function register(domainArg: string, flags: Record<string, string | boolean>) {
21
19
  const config = requireConfig();
20
+ const orgId = (flags.org as string) || config.default_org;
21
+ const domain = domainArg || (config.default_domain as string);
22
+ if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain register <domain> --org <id> [--years <num>]\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
23
+ const years = parseInt(flags.years as string) || 1;
22
24
  const res = await sdkDomain.registerDomain(config.api_key, orgId, domain, years);
23
25
  success(`Registered ${domain}!\n${JSON.stringify(res, null, 2)}`);
24
26
  }
25
27
 
26
- export async function importDomain(domain: string, flags: Record<string, string | boolean>) {
27
- const orgId = flags.org as string;
28
- if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
28
+ export async function importDomain(domainArg: string, flags: Record<string, string | boolean>) {
29
+ const config = requireConfig();
30
+ const orgId = (flags.org as string) || config.default_org;
31
+ const domain = domainArg || (config.default_domain as string);
32
+ if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
29
33
  if (!flags['namecheap-user'] || !flags['namecheap-key']) {
30
34
  error("Missing required arguments.\nUsage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>");
31
35
  }
32
- const config = requireConfig();
33
36
  await sdkDomain.importDomain(config.api_key, orgId, {
34
37
  domain,
35
38
  namecheap_api_user: flags['namecheap-user'] as string,
@@ -39,43 +42,47 @@ export async function importDomain(domain: string, flags: Record<string, string
39
42
  }
40
43
 
41
44
  export async function list(flags: Record<string, string | boolean>) {
42
- const orgId = flags.org as string;
43
- if (!orgId) error("Missing required arguments.\nUsage: myapi domain list --org <id> [--filter=all|unassigned|org]");
44
45
  const config = requireConfig();
46
+ const orgId = (flags.org as string) || config.default_org;
47
+ if (!orgId) error("Missing required arguments.\nUsage: myapi domain list --org <id> [--filter=all|unassigned|org]\n(Or set a default org via: myapi config set-org <id>)");
45
48
  const filter = flags.filter as 'all' | 'unassigned' | 'org' | undefined;
46
49
  const domains = await sdkDomain.listDomains(config.api_key, orgId, filter);
47
50
  printTable(domains as unknown as Record<string, unknown>[]);
48
51
  }
49
52
 
50
- export async function assign(domain: string, flags: Record<string, string | boolean>) {
51
- const orgId = flags.org as string;
52
- const targetOrgId = flags.target as string;
53
- if (!orgId || !domain || !targetOrgId) error("Missing required arguments.\nUsage: myapi domain assign <domain> --org <id> --target <target_org_id>");
53
+ export async function assign(domainArg: string, flags: Record<string, string | boolean>) {
54
54
  const config = requireConfig();
55
+ const orgId = (flags.org as string) || config.default_org;
56
+ const domain = domainArg || (config.default_domain as string);
57
+ const targetOrgId = flags.target as string;
58
+ if (!orgId || !domain || !targetOrgId) error("Missing required arguments.\nUsage: myapi domain assign <domain> --org <id> --target <target_org_id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
55
59
  const res = await sdkDomain.assignDomain(config.api_key, orgId, domain, targetOrgId);
56
60
  success(`Assigned ${domain} to org ${targetOrgId}`);
57
61
  }
58
62
 
59
- export async function unassign(domain: string, flags: Record<string, string | boolean>) {
60
- const orgId = flags.org as string;
61
- if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain unassign <domain> --org <id>");
63
+ export async function unassign(domainArg: string, flags: Record<string, string | boolean>) {
62
64
  const config = requireConfig();
65
+ const orgId = (flags.org as string) || config.default_org;
66
+ const domain = domainArg || (config.default_domain as string);
67
+ if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain unassign <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
63
68
  const res = await sdkDomain.unassignDomain(config.api_key, orgId, domain);
64
69
  success(`Unassigned ${domain} from org ${orgId}`);
65
70
  }
66
71
 
67
- export async function settings(domain: string, flags: Record<string, string | boolean>) {
68
- const orgId = flags.org as string;
69
- if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain settings <domain> --org <id>");
72
+ export async function settings(domainArg: string, flags: Record<string, string | boolean>) {
70
73
  const config = requireConfig();
74
+ const orgId = (flags.org as string) || config.default_org;
75
+ const domain = domainArg || (config.default_domain as string);
76
+ if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain settings <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
71
77
  const res = await sdkDomain.getDomainSettings(config.api_key, orgId, domain);
72
78
  printJson(res);
73
79
  }
74
80
 
75
- export async function updateSettings(domain: string, flags: Record<string, string | boolean>) {
76
- const orgId = flags.org as string;
77
- if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain update-settings <domain> --org <id> [--security=...] [--browser-check=...] [--purge-cache]");
81
+ export async function updateSettings(domainArg: string, flags: Record<string, string | boolean>) {
78
82
  const config = requireConfig();
83
+ const orgId = (flags.org as string) || config.default_org;
84
+ const domain = domainArg || (config.default_domain as string);
85
+ if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain update-settings <domain> --org <id> [--security=...] [--browser-check=...] [--purge-cache]\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
79
86
  const payload: any = {};
80
87
  if (flags.security) payload.security_level = flags.security as string;
81
88
  if (flags['browser-check']) payload.browser_check = flags['browser-check'] as string;
@@ -4,29 +4,30 @@ import { success, error, printTable, printJson, info } from '../output.js';
4
4
  import { sleep } from '../utils.js';
5
5
 
6
6
  export async function createMailbox(flags: Record<string, string | boolean>) {
7
- const orgId = flags.org as string;
8
- if (!orgId || !flags.domain || !flags.username) {
9
- error("Missing required arguments.\nUsage: myapi email create-mailbox --org <id> --domain <domain> --username <user>");
10
- }
11
7
  const config = requireConfig();
12
- const address = await sdkEmail.createMailbox(config.api_key, orgId, flags.domain as string, flags.username as string);
8
+ const orgId = (flags.org as string) || config.default_org;
9
+ const domain = (flags.domain as string) || config.default_domain;
10
+ if (!orgId || !domain || !flags.username) {
11
+ error("Missing required arguments.\nUsage: myapi email create-mailbox --org <id> --domain <domain> --username <user>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
12
+ }
13
+ const address = await sdkEmail.createMailbox(config.api_key, orgId, domain, flags.username as string);
13
14
  success(`Mailbox created: ${address.address}`);
14
15
  }
15
16
 
16
17
  export async function listMailboxes(flags: Record<string, string | boolean>) {
17
- const orgId = flags.org as string;
18
- if (!orgId) error("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id>");
19
18
  const config = requireConfig();
19
+ const orgId = (flags.org as string) || config.default_org;
20
+ if (!orgId) error("Missing required arguments.\nUsage: myapi email list-mailboxes --org <id>\n(Or set a default org via: myapi config set-org <id>)");
20
21
  const mailboxes = await sdkEmail.listMailboxes(config.api_key, orgId);
21
22
  printTable(mailboxes as unknown as Record<string, unknown>[]);
22
23
  }
23
24
 
24
25
  export async function send(flags: Record<string, string | boolean>) {
25
- const orgId = flags.org as string;
26
+ const config = requireConfig();
27
+ const orgId = (flags.org as string) || config.default_org;
26
28
  if (!orgId || !flags.from || !flags.to || !flags.subject || !flags.body) {
27
29
  error("Missing required arguments.\nUsage: myapi email send --org <id> --from <email> --to <email> --subject <str> --body <str>");
28
30
  }
29
- const config = requireConfig();
30
31
  const res = await sdkEmail.sendEmail(config.api_key, orgId, {
31
32
  from: flags.from as string,
32
33
  to: [flags.to as string],
@@ -37,27 +38,27 @@ export async function send(flags: Record<string, string | boolean>) {
37
38
  }
38
39
 
39
40
  export async function inbox(address: string, flags: Record<string, string | boolean>) {
40
- const orgId = flags.org as string;
41
- if (!orgId || !address) error("Missing required arguments.\nUsage: myapi email inbox <address> --org <id>");
42
41
  const config = requireConfig();
42
+ const orgId = (flags.org as string) || config.default_org;
43
+ if (!orgId || !address) error("Missing required arguments.\nUsage: myapi email inbox <address> --org <id>");
43
44
  const messages = await sdkEmail.getInbox(config.api_key, orgId, address);
44
45
  printTable(messages as unknown as Record<string, unknown>[]);
45
46
  }
46
47
 
47
48
  export async function listTemplates(flags: Record<string, string | boolean>) {
48
- const orgId = flags.org as string;
49
- if (!orgId) error("Missing required arguments.\nUsage: myapi email list-templates --org <id>");
50
49
  const config = requireConfig();
50
+ const orgId = (flags.org as string) || config.default_org;
51
+ if (!orgId) error("Missing required arguments.\nUsage: myapi email list-templates --org <id>\n(Or set a default org via: myapi config set-org <id>)");
51
52
  const templates = await sdkEmail.listTemplates(config.api_key, orgId);
52
53
  printTable(templates as unknown as Record<string, unknown>[]);
53
54
  }
54
55
 
55
56
  export async function generateTemplate(flags: Record<string, string | boolean>) {
56
- const orgId = flags.org as string;
57
+ const config = requireConfig();
58
+ const orgId = (flags.org as string) || config.default_org;
57
59
  if (!orgId || !flags.prompt || !flags.name) {
58
60
  error("Missing required arguments.\nUsage: myapi email generate-template --org <id> --prompt <str> --name <str>");
59
61
  }
60
- const config = requireConfig();
61
62
 
62
63
  const job = await sdkEmail.generateTemplate(config.api_key, orgId, {
63
64
  prompt: flags.prompt as string,
@@ -89,17 +90,17 @@ export async function generateTemplate(flags: Record<string, string | boolean>)
89
90
  }
90
91
 
91
92
  export async function listCampaigns(flags: Record<string, string | boolean>) {
92
- const orgId = flags.org as string;
93
- if (!orgId) error("Missing required arguments.\nUsage: myapi email list-campaigns --org <id>");
94
93
  const config = requireConfig();
94
+ const orgId = (flags.org as string) || config.default_org;
95
+ if (!orgId) error("Missing required arguments.\nUsage: myapi email list-campaigns --org <id>\n(Or set a default org via: myapi config set-org <id>)");
95
96
  const campaigns = await sdkEmail.listCampaigns(config.api_key, orgId);
96
97
  printTable(campaigns as unknown as Record<string, unknown>[]);
97
98
  }
98
99
 
99
100
  export async function campaignStats(id: string, flags: Record<string, string | boolean>) {
100
- const orgId = flags.org as string;
101
- if (!orgId || !id) error("Missing required arguments.\nUsage: myapi email campaign-stats <id> --org <id>");
102
101
  const config = requireConfig();
102
+ const orgId = (flags.org as string) || config.default_org;
103
+ if (!orgId || !id) error("Missing required arguments.\nUsage: myapi email campaign-stats <id> --org <id>");
103
104
  const stats = await sdkEmail.getCampaignStats(config.api_key, orgId, id);
104
105
  printJson(stats);
105
106
  }
@@ -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
  import * as readline from 'readline';
5
5
 
6
6
  export async function createNew(flags: Record<string, string | boolean>) {
@@ -24,12 +24,17 @@ export async function createNew(flags: Record<string, string | boolean>) {
24
24
 
25
25
  export async function list(flags: Record<string, string | boolean>) {
26
26
  if (flags.help) {
27
- info('Usage: myapi keys list\n\nLists all API keys associated with your account.');
27
+ info('Usage: myapi keys list [--json]\n\nLists all API keys associated with your account.');
28
28
  return;
29
29
  }
30
30
  const config = requireConfig();
31
31
  const keysList = await hq.listApiKeys(config.api_key);
32
32
 
33
+ if (flags.json) {
34
+ printJson(keysList);
35
+ return;
36
+ }
37
+
33
38
  const formattedKeys = keysList.map(k => {
34
39
  // Format creation date
35
40
  const createdDate = new Date(k.created_at);
@@ -66,14 +66,14 @@ export async function importOrg(args: string[], flags: Record<string, string | b
66
66
  info('Usage: myapi org import <domain> --org <id>\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
- const domain = args[0];
70
- const orgId = flags.org as string;
69
+ const config = requireConfig();
70
+ const domain = args[0] || (config.default_domain as string);
71
+ const orgId = (flags.org as string) || config.default_org;
71
72
 
72
73
  if (!domain || !orgId) {
73
- error("Missing required arguments.\nUsage: myapi org import <domain> --org <id>");
74
+ error("Missing required arguments.\nUsage: myapi org import <domain> --org <id>\n(Or set defaults via: myapi config set-org <id> / set-domain <domain>)");
74
75
  return;
75
76
  }
76
- const config = requireConfig();
77
77
 
78
78
  const result = await hq.importOrg(config.api_key, orgId, domain);
79
79
  const importId = result.job_id;
package/src/config.ts CHANGED
@@ -6,6 +6,8 @@ export interface Config {
6
6
  api_key: string;
7
7
  account_id: string;
8
8
  pin: string;
9
+ default_org?: string;
10
+ default_domain?: string;
9
11
  }
10
12
 
11
13
  const CONFIG_DIR = path.join(os.homedir(), '.myapi');
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 configCmd from './commands/config.js';
10
11
  import * as domainCmd from './commands/domain.js';
11
12
  import * as emailCmd from './commands/email.js';
12
13
 
@@ -56,6 +57,9 @@ async function main() {
56
57
  else if (subcommand === 'setup') await billingCmd.setup(flags);
57
58
  else printHelp();
58
59
  break;
60
+ case 'config':
61
+ await configCmd.run(subcommand, restArgs, flags);
62
+ break;
59
63
  case 'domain':
60
64
  await domainCmd.run(subcommand, restArgs, flags);
61
65
  break;
@@ -85,6 +89,7 @@ Commands:
85
89
  billing Check balance and manage billing
86
90
  org Manage organizations
87
91
  setup Setup CLI credentials and view integration instructions
92
+ config Manage CLI defaults like org_id and domain
88
93
  domain Manage domain configurations
89
94
  email Send emails and manage templates
90
95