@myapihq/cli 1.0.46 → 1.0.49

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.
@@ -13,7 +13,8 @@ export async function check(domainArg, flags) {
13
13
  info(`${domain} — Available ✓ ${price}/yr`);
14
14
  }
15
15
  else {
16
- info(`${domain} ${res.message || 'Not available'} ✗`);
16
+ const msg = typeof res.message === 'string' ? res.message : res.message ? JSON.stringify(res.message) : 'Not available';
17
+ info(`${domain} — ${msg} ✗`);
17
18
  }
18
19
  }
19
20
  export async function register(domainArg, flags) {
@@ -3,6 +3,10 @@ import { loadConfig } from '../config.js';
3
3
  import { info, success } from '../output.js';
4
4
  import { installSkills } from './setup.js';
5
5
  const REGISTRY_URL = 'https://registry.npmjs.org/@myapihq/cli/latest';
6
+ // Use the npm binary next to the active node — critical for nvm users.
7
+ function npmBin() {
8
+ return process.execPath.replace(/[/\\]node$/, '/npm');
9
+ }
6
10
  // checkForUpdate runs silently in the background on every command.
7
11
  // Auto-installs if a newer version is available.
8
12
  export async function checkForUpdate(currentVersion) {
@@ -14,36 +18,47 @@ export async function checkForUpdate(currentVersion) {
14
18
  const latest = data.version;
15
19
  if (latest && isNewer(latest, currentVersion)) {
16
20
  info(`\n› New version available (${currentVersion} → ${latest}) — installing…`);
17
- execSync('npm install -g @myapihq/cli', { stdio: 'pipe' });
18
- const config = loadConfig();
19
- if (config?.skills_installed) {
20
- await installSkills();
21
+ try {
22
+ // Pin the exact version so npm can't resolve to a cached older one.
23
+ execSync(`"${npmBin()}" install -g @myapihq/cli@${latest}`, { stdio: 'pipe' });
24
+ const config = loadConfig();
25
+ if (config?.skills_installed) {
26
+ await installSkills();
27
+ }
28
+ info(`› Updated to ${latest} — active after this command completes.\n`);
29
+ }
30
+ catch (installErr) {
31
+ const msg = installErr?.stderr?.toString?.() || installErr?.message || String(installErr);
32
+ info(`› Auto-update failed: ${msg.trim()}`);
33
+ info(`› Run manually: npm install -g @myapihq/cli@${latest}`);
21
34
  }
22
- success(`› MyAPI CLI updated to ${latest}. Re-run your command.\n`);
23
- process.exit(0);
24
35
  }
25
36
  }
26
37
  catch {
27
- // Network or install errors are silently ignored.
38
+ // Network errors are silently ignored.
28
39
  }
29
40
  }
30
41
  // myapi update — explicit update, same logic as auto-update.
31
42
  export async function update(flags = {}) {
32
43
  if (flags.help) {
33
- info('Usage: myapi update\n\nUpdates the MyAPI CLI and skills pack to the latest published version.\nEquivalent to: npm install -g @myapihq/cli');
44
+ info('Usage: myapi update\n\nUpdates the MyAPI CLI to the latest published version.\nEquivalent to: npm install -g @myapihq/cli@latest');
34
45
  return;
35
46
  }
36
47
  info('› Checking for updates…');
48
+ let latest = '';
37
49
  try {
38
50
  const res = await fetch(REGISTRY_URL, { signal: AbortSignal.timeout(5000) });
39
51
  if (!res.ok)
40
52
  throw new Error(`registry returned ${res.status}`);
41
53
  const data = await res.json();
42
- info(`› Installing @myapihq/cli@${data.version}…`);
54
+ latest = data.version ?? '';
55
+ if (latest)
56
+ info(`› Installing @myapihq/cli@${latest}…`);
43
57
  }
44
58
  catch { /* proceed anyway */ }
45
59
  try {
46
- execSync('npm install -g @myapihq/cli', { stdio: 'inherit' });
60
+ const pkg = latest ? `@myapihq/cli@${latest}` : '@myapihq/cli@latest';
61
+ execSync(`"${npmBin()}" install -g ${pkg}`, { stdio: 'inherit' });
47
62
  }
48
63
  catch {
49
64
  process.exit(1);
package/dist/index.js CHANGED
@@ -140,12 +140,22 @@ async function main() {
140
140
  }
141
141
  catch (err) {
142
142
  if (err instanceof MyApiError) {
143
- if (err.status === 402)
144
- error('Insufficient balance. Run: myapi billing topup <amount>');
145
- else if (err.status === 401)
143
+ if (err.status === 401)
146
144
  error('Invalid API key. Run: myapi auth setup');
145
+ else if (err.status === 402) {
146
+ if (err.code === 'REGISTRATION_REQUIRED')
147
+ error('A verified email is required. Run: myapi auth signup');
148
+ else if (err.code === 'UPGRADE_REQUIRED')
149
+ error('A verified email is required. Run: myapi auth signup');
150
+ else
151
+ error(`Insufficient balance. Run: myapi billing topup <amount>`);
152
+ }
153
+ else
154
+ error(err.code || err.message);
155
+ }
156
+ else {
157
+ error(err.message || (typeof err === 'object' ? JSON.stringify(err) : String(err)));
147
158
  }
148
- error(err.message || (typeof err === 'object' ? JSON.stringify(err) : String(err)));
149
159
  }
150
160
  }
151
161
  function printHelp() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myapihq/cli",
3
- "version": "1.0.46",
3
+ "version": "1.0.49",
4
4
  "description": "MyAPI command-line interface",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -7,12 +7,13 @@ export async function check(domainArg: string, flags: Record<string, string | bo
7
7
  const orgId = (flags.org as string) || config.default_org;
8
8
  const domain = domainArg || (config.default_domain as string);
9
9
  if (!orgId || !domain) error("Missing required arguments.\nUsage: myapi domain check <domain> --org <id>\n(Set defaults: myapi auth config set-org <id> / myapi auth config set-domain <domain>)");
10
- const res = await sdkDomain.checkDomain(config.api_key, orgId, domain) as { available: boolean; price_cents: number; price_display?: string; message?: string };
10
+ const res = await sdkDomain.checkDomain(config.api_key, orgId, domain) as { available: boolean; price_cents: number; price_display?: string; message?: unknown };
11
11
  if (res.available) {
12
12
  const price = res.price_display || `$${(res.price_cents / 100).toFixed(2)}`;
13
13
  info(`${domain} — Available ✓ ${price}/yr`);
14
14
  } else {
15
- info(`${domain} ${res.message || 'Not available'} ✗`);
15
+ const msg = typeof res.message === 'string' ? res.message : res.message ? JSON.stringify(res.message) : 'Not available';
16
+ info(`${domain} — ${msg} ✗`);
16
17
  }
17
18
  }
18
19
 
@@ -1,10 +1,15 @@
1
1
  import { execSync } from 'child_process';
2
- import { loadConfig, saveConfig } from '../config.js';
2
+ import { loadConfig } from '../config.js';
3
3
  import { info, success } from '../output.js';
4
4
  import { installSkills } from './setup.js';
5
5
 
6
6
  const REGISTRY_URL = 'https://registry.npmjs.org/@myapihq/cli/latest';
7
7
 
8
+ // Use the npm binary next to the active node — critical for nvm users.
9
+ function npmBin(): string {
10
+ return process.execPath.replace(/[/\\]node$/, '/npm');
11
+ }
12
+
8
13
  // checkForUpdate runs silently in the background on every command.
9
14
  // Auto-installs if a newer version is available.
10
15
  export async function checkForUpdate(currentVersion: string): Promise<void> {
@@ -16,35 +21,44 @@ export async function checkForUpdate(currentVersion: string): Promise<void> {
16
21
 
17
22
  if (latest && isNewer(latest, currentVersion)) {
18
23
  info(`\n› New version available (${currentVersion} → ${latest}) — installing…`);
19
- execSync('npm install -g @myapihq/cli', { stdio: 'pipe' });
20
- const config = loadConfig();
21
- if (config?.skills_installed) {
22
- await installSkills();
24
+ try {
25
+ // Pin the exact version so npm can't resolve to a cached older one.
26
+ execSync(`"${npmBin()}" install -g @myapihq/cli@${latest}`, { stdio: 'pipe' });
27
+ const config = loadConfig();
28
+ if (config?.skills_installed) {
29
+ await installSkills();
30
+ }
31
+ info(`› Updated to ${latest} — active after this command completes.\n`);
32
+ } catch (installErr: any) {
33
+ const msg = installErr?.stderr?.toString?.() || installErr?.message || String(installErr);
34
+ info(`› Auto-update failed: ${msg.trim()}`);
35
+ info(`› Run manually: npm install -g @myapihq/cli@${latest}`);
23
36
  }
24
- success(`› MyAPI CLI updated to ${latest}. Re-run your command.\n`);
25
- process.exit(0);
26
37
  }
27
38
  } catch {
28
- // Network or install errors are silently ignored.
39
+ // Network errors are silently ignored.
29
40
  }
30
41
  }
31
42
 
32
43
  // myapi update — explicit update, same logic as auto-update.
33
44
  export async function update(flags: Record<string, string | boolean> = {}): Promise<void> {
34
45
  if (flags.help) {
35
- info('Usage: myapi update\n\nUpdates the MyAPI CLI and skills pack to the latest published version.\nEquivalent to: npm install -g @myapihq/cli');
46
+ info('Usage: myapi update\n\nUpdates the MyAPI CLI to the latest published version.\nEquivalent to: npm install -g @myapihq/cli@latest');
36
47
  return;
37
48
  }
38
49
  info('› Checking for updates…');
50
+ let latest = '';
39
51
  try {
40
52
  const res = await fetch(REGISTRY_URL, { signal: AbortSignal.timeout(5000) });
41
53
  if (!res.ok) throw new Error(`registry returned ${res.status}`);
42
54
  const data = await res.json() as { version?: string };
43
- info(`› Installing @myapihq/cli@${data.version}…`);
55
+ latest = data.version ?? '';
56
+ if (latest) info(`› Installing @myapihq/cli@${latest}…`);
44
57
  } catch { /* proceed anyway */ }
45
58
 
46
59
  try {
47
- execSync('npm install -g @myapihq/cli', { stdio: 'inherit' });
60
+ const pkg = latest ? `@myapihq/cli@${latest}` : '@myapihq/cli@latest';
61
+ execSync(`"${npmBin()}" install -g ${pkg}`, { stdio: 'inherit' });
48
62
  } catch {
49
63
  process.exit(1);
50
64
  }
package/src/index.ts CHANGED
@@ -119,10 +119,16 @@ async function main() {
119
119
  }
120
120
  } catch (err: any) {
121
121
  if (err instanceof MyApiError) {
122
- if (err.status === 402) error('Insufficient balance. Run: myapi billing topup <amount>');
123
- else if (err.status === 401) error('Invalid API key. Run: myapi auth setup');
122
+ if (err.status === 401) error('Invalid API key. Run: myapi auth setup');
123
+ else if (err.status === 402) {
124
+ if (err.code === 'REGISTRATION_REQUIRED') error('A verified email is required. Run: myapi auth signup');
125
+ else if (err.code === 'UPGRADE_REQUIRED') error('A verified email is required. Run: myapi auth signup');
126
+ else error(`Insufficient balance. Run: myapi billing topup <amount>`);
127
+ }
128
+ else error(err.code || err.message);
129
+ } else {
130
+ error(err.message || (typeof err === 'object' ? JSON.stringify(err) : String(err)));
124
131
  }
125
- error(err.message || (typeof err === 'object' ? JSON.stringify(err) : String(err)));
126
132
  }
127
133
  }
128
134