@myapihq/cli 1.0.9 → 1.0.11

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.
@@ -10,10 +10,13 @@ const sdk_1 = require("@myapihq/sdk");
10
10
  const config_js_1 = require("../config.js");
11
11
  const output_js_1 = require("../output.js");
12
12
  async function check(domain, flags) {
13
+ const orgId = flags.org;
14
+ if (!orgId)
15
+ (0, output_js_1.error)("Missing --org <id> flag");
13
16
  if (!domain)
14
17
  (0, output_js_1.error)("Missing domain");
15
18
  const config = (0, config_js_1.requireConfig)();
16
- const res = await sdk_1.domain.checkDomain(config.api_key, domain);
19
+ const res = await sdk_1.domain.checkDomain(config.api_key, orgId, domain);
17
20
  if (res.available) {
18
21
  (0, output_js_1.info)(`${domain} — Available ✓ Price: $${(res.price_cents / 100).toFixed(2)}/yr`);
19
22
  }
@@ -22,21 +25,27 @@ async function check(domain, flags) {
22
25
  }
23
26
  }
24
27
  async function register(domain, flags) {
28
+ const orgId = flags.org;
29
+ if (!orgId)
30
+ (0, output_js_1.error)("Missing --org <id> flag");
25
31
  if (!domain)
26
32
  (0, output_js_1.error)("Missing domain");
27
33
  const years = parseInt(flags.years) || 1;
28
34
  const config = (0, config_js_1.requireConfig)();
29
- const res = await sdk_1.domain.registerDomain(config.api_key, domain, years);
35
+ const res = await sdk_1.domain.registerDomain(config.api_key, orgId, domain, years);
30
36
  (0, output_js_1.success)(`Registered ${domain}!\n${JSON.stringify(res, null, 2)}`);
31
37
  }
32
38
  async function importDomain(domain, flags) {
39
+ const orgId = flags.org;
40
+ if (!orgId)
41
+ (0, output_js_1.error)("Missing --org <id> flag");
33
42
  if (!domain)
34
43
  (0, output_js_1.error)("Missing domain");
35
44
  if (!flags['namecheap-user'] || !flags['namecheap-key']) {
36
45
  (0, output_js_1.error)("Missing --namecheap-user or --namecheap-key flags");
37
46
  }
38
47
  const config = (0, config_js_1.requireConfig)();
39
- await sdk_1.domain.importDomain(config.api_key, {
48
+ await sdk_1.domain.importDomain(config.api_key, orgId, {
40
49
  domain,
41
50
  namecheap_api_user: flags['namecheap-user'],
42
51
  namecheap_api_key: flags['namecheap-key']
@@ -44,33 +53,40 @@ async function importDomain(domain, flags) {
44
53
  (0, output_js_1.success)(`Imported ${domain}`);
45
54
  }
46
55
  async function list(flags) {
56
+ const orgId = flags.org;
57
+ if (!orgId)
58
+ (0, output_js_1.error)("Missing --org <id> flag");
47
59
  const config = (0, config_js_1.requireConfig)();
48
- const domains = await sdk_1.domain.listDomains(config.api_key);
60
+ const filter = flags.filter;
61
+ const domains = await sdk_1.domain.listDomains(config.api_key, orgId, filter);
49
62
  (0, output_js_1.printTable)(domains);
50
63
  }
51
64
  async function settings(domain, flags) {
65
+ const orgId = flags.org;
66
+ if (!orgId)
67
+ (0, output_js_1.error)("Missing --org <id> flag");
52
68
  if (!domain)
53
69
  (0, output_js_1.error)("Missing domain");
54
70
  const config = (0, config_js_1.requireConfig)();
55
- const res = await sdk_1.domain.getDomainSettings(config.api_key, domain);
71
+ const res = await sdk_1.domain.getDomainSettings(config.api_key, orgId, domain);
56
72
  (0, output_js_1.printJson)(res);
57
73
  }
58
74
  async function run(subcommand, args, flags) {
59
75
  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');
76
+ (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\n\nNote: All domain commands require the --org <id> flag.');
61
77
  return;
62
78
  }
63
79
  if (flags.help) {
64
80
  if (subcommand === 'list')
65
- (0, output_js_1.info)('Usage: myapi domain list\n\nLists all registered domains in your account.');
81
+ (0, output_js_1.info)('Usage: myapi domain list --org <id> [--filter=all|unassigned|org]\n\nLists all registered domains in your account.\n --filter=all Lists all domains owned by the account.\n --filter=unassigned Lists domains not assigned to an org.\n --filter=org (Default) Lists domains assigned to the current org.');
66
82
  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.');
83
+ (0, output_js_1.info)('Usage: myapi domain check <domain> --org <id>\n\nChecks if a domain name is available for registration.');
68
84
  else if (subcommand === 'register')
69
- (0, output_js_1.info)('Usage: myapi domain register <domain> [--years <num>]\n\nRegisters a new domain name.');
85
+ (0, output_js_1.info)('Usage: myapi domain register <domain> --org <id> [--years <num>]\n\nRegisters a new domain name.');
70
86
  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.');
87
+ (0, output_js_1.info)('Usage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>\n\nImports an existing domain from Namecheap.');
72
88
  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.');
89
+ (0, output_js_1.info)('Usage: myapi domain settings <domain> --org <id>\n\nGets the DNS settings and configuration for a domain.');
74
90
  return;
75
91
  }
76
92
  if (subcommand === 'list')
@@ -68,13 +68,13 @@ async function del(id, flags) {
68
68
  }
69
69
  async function importOrg(args, flags) {
70
70
  if (flags.help) {
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.');
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 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>");
74
+ const domain = args[0];
75
+ const orgId = flags.org;
76
+ if (!domain || !orgId) {
77
+ (0, output_js_1.error)("Missing domain or --org flag. Usage: myapi org import <domain> --org <id>");
78
78
  return;
79
79
  }
80
80
  const config = (0, config_js_1.requireConfig)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "MyAPI command-line interface",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -3,9 +3,11 @@ import { requireConfig } from '../config.js';
3
3
  import { success, error, info, printTable, printJson } from '../output.js';
4
4
 
5
5
  export async function check(domain: string, flags: Record<string, string | boolean>) {
6
+ const orgId = flags.org as string;
7
+ if (!orgId) error("Missing --org <id> flag");
6
8
  if (!domain) error("Missing domain");
7
9
  const config = requireConfig();
8
- const res = await sdkDomain.checkDomain(config.api_key, domain);
10
+ const res = await sdkDomain.checkDomain(config.api_key, orgId, domain);
9
11
  if (res.available) {
10
12
  info(`${domain} — Available ✓ Price: $${(res.price_cents / 100).toFixed(2)}/yr`);
11
13
  } else {
@@ -14,20 +16,24 @@ export async function check(domain: string, flags: Record<string, string | boole
14
16
  }
15
17
 
16
18
  export async function register(domain: string, flags: Record<string, string | boolean>) {
19
+ const orgId = flags.org as string;
20
+ if (!orgId) error("Missing --org <id> flag");
17
21
  if (!domain) error("Missing domain");
18
22
  const years = parseInt(flags.years as string) || 1;
19
23
  const config = requireConfig();
20
- const res = await sdkDomain.registerDomain(config.api_key, domain, years);
24
+ const res = await sdkDomain.registerDomain(config.api_key, orgId, domain, years);
21
25
  success(`Registered ${domain}!\n${JSON.stringify(res, null, 2)}`);
22
26
  }
23
27
 
24
28
  export async function importDomain(domain: string, flags: Record<string, string | boolean>) {
29
+ const orgId = flags.org as string;
30
+ if (!orgId) error("Missing --org <id> flag");
25
31
  if (!domain) error("Missing domain");
26
32
  if (!flags['namecheap-user'] || !flags['namecheap-key']) {
27
33
  error("Missing --namecheap-user or --namecheap-key flags");
28
34
  }
29
35
  const config = requireConfig();
30
- await sdkDomain.importDomain(config.api_key, {
36
+ await sdkDomain.importDomain(config.api_key, orgId, {
31
37
  domain,
32
38
  namecheap_api_user: flags['namecheap-user'] as string,
33
39
  namecheap_api_key: flags['namecheap-key'] as string
@@ -36,30 +42,35 @@ export async function importDomain(domain: string, flags: Record<string, string
36
42
  }
37
43
 
38
44
  export async function list(flags: Record<string, string | boolean>) {
45
+ const orgId = flags.org as string;
46
+ if (!orgId) error("Missing --org <id> flag");
39
47
  const config = requireConfig();
40
- const domains = await sdkDomain.listDomains(config.api_key);
48
+ const filter = flags.filter as 'all' | 'unassigned' | 'org' | undefined;
49
+ const domains = await sdkDomain.listDomains(config.api_key, orgId, filter);
41
50
  printTable(domains as unknown as Record<string, unknown>[]);
42
51
  }
43
52
 
44
53
  export async function settings(domain: string, flags: Record<string, string | boolean>) {
54
+ const orgId = flags.org as string;
55
+ if (!orgId) error("Missing --org <id> flag");
45
56
  if (!domain) error("Missing domain");
46
57
  const config = requireConfig();
47
- const res = await sdkDomain.getDomainSettings(config.api_key, domain);
58
+ const res = await sdkDomain.getDomainSettings(config.api_key, orgId, domain);
48
59
  printJson(res);
49
60
  }
50
61
 
51
62
  export async function run(subcommand: string | undefined, args: string[], flags: Record<string, string | boolean>) {
52
63
  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');
64
+ 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\n\nNote: All domain commands require the --org <id> flag.');
54
65
  return;
55
66
  }
56
67
 
57
68
  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.');
69
+ if (subcommand === 'list') info('Usage: myapi domain list --org <id> [--filter=all|unassigned|org]\n\nLists all registered domains in your account.\n --filter=all Lists all domains owned by the account.\n --filter=unassigned Lists domains not assigned to an org.\n --filter=org (Default) Lists domains assigned to the current org.');
70
+ else if (subcommand === 'check') info('Usage: myapi domain check <domain> --org <id>\n\nChecks if a domain name is available for registration.');
71
+ else if (subcommand === 'register') info('Usage: myapi domain register <domain> --org <id> [--years <num>]\n\nRegisters a new domain name.');
72
+ else if (subcommand === 'import') info('Usage: myapi domain import <domain> --org <id> --namecheap-user <user> --namecheap-key <key>\n\nImports an existing domain from Namecheap.');
73
+ else if (subcommand === 'settings') info('Usage: myapi domain settings <domain> --org <id>\n\nGets the DNS settings and configuration for a domain.');
63
74
  return;
64
75
  }
65
76
 
@@ -63,14 +63,14 @@ export async function del(id: string, flags: Record<string, string | boolean>) {
63
63
 
64
64
  export async function importOrg(args: string[], flags: Record<string, string | boolean>) {
65
65
  if (flags.help) {
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.');
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 orgId = args[0];
70
- const domain = args[1];
69
+ const domain = args[0];
70
+ const orgId = flags.org as string;
71
71
 
72
- if (!orgId || !domain) {
73
- error("Missing arguments. Usage: myapi org import <org_id> <domain>");
72
+ if (!domain || !orgId) {
73
+ error("Missing domain or --org flag. Usage: myapi org import <domain> --org <id>");
74
74
  return;
75
75
  }
76
76
  const config = requireConfig();