@myapihq/cli 1.0.47 → 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.
- package/dist/commands/domain.js +2 -1
- package/dist/commands/update.js +15 -10
- package/dist/index.js +14 -4
- package/package.json +1 -1
- package/src/commands/domain.ts +3 -2
- package/src/commands/update.ts +16 -11
- package/src/index.ts +9 -3
package/dist/commands/domain.js
CHANGED
|
@@ -13,7 +13,8 @@ export async function check(domainArg, flags) {
|
|
|
13
13
|
info(`${domain} — Available ✓ ${price}/yr`);
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
|
-
|
|
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) {
|
package/dist/commands/update.js
CHANGED
|
@@ -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) {
|
|
@@ -15,20 +19,18 @@ export async function checkForUpdate(currentVersion) {
|
|
|
15
19
|
if (latest && isNewer(latest, currentVersion)) {
|
|
16
20
|
info(`\n› New version available (${currentVersion} → ${latest}) — installing…`);
|
|
17
21
|
try {
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
execSync(`"${npmBin}" install -g @myapihq/cli`, { stdio: 'pipe' });
|
|
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' });
|
|
21
24
|
const config = loadConfig();
|
|
22
25
|
if (config?.skills_installed) {
|
|
23
26
|
await installSkills();
|
|
24
27
|
}
|
|
25
|
-
|
|
26
|
-
process.exit(0);
|
|
28
|
+
info(`› Updated to ${latest} — active after this command completes.\n`);
|
|
27
29
|
}
|
|
28
30
|
catch (installErr) {
|
|
29
31
|
const msg = installErr?.stderr?.toString?.() || installErr?.message || String(installErr);
|
|
30
32
|
info(`› Auto-update failed: ${msg.trim()}`);
|
|
31
|
-
info(`› Run manually: npm install -g @myapihq/cli`);
|
|
33
|
+
info(`› Run manually: npm install -g @myapihq/cli@${latest}`);
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
}
|
|
@@ -39,21 +41,24 @@ export async function checkForUpdate(currentVersion) {
|
|
|
39
41
|
// myapi update — explicit update, same logic as auto-update.
|
|
40
42
|
export async function update(flags = {}) {
|
|
41
43
|
if (flags.help) {
|
|
42
|
-
info('Usage: myapi update\n\nUpdates the MyAPI CLI
|
|
44
|
+
info('Usage: myapi update\n\nUpdates the MyAPI CLI to the latest published version.\nEquivalent to: npm install -g @myapihq/cli@latest');
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
45
47
|
info('› Checking for updates…');
|
|
48
|
+
let latest = '';
|
|
46
49
|
try {
|
|
47
50
|
const res = await fetch(REGISTRY_URL, { signal: AbortSignal.timeout(5000) });
|
|
48
51
|
if (!res.ok)
|
|
49
52
|
throw new Error(`registry returned ${res.status}`);
|
|
50
53
|
const data = await res.json();
|
|
51
|
-
|
|
54
|
+
latest = data.version ?? '';
|
|
55
|
+
if (latest)
|
|
56
|
+
info(`› Installing @myapihq/cli@${latest}…`);
|
|
52
57
|
}
|
|
53
58
|
catch { /* proceed anyway */ }
|
|
54
59
|
try {
|
|
55
|
-
const
|
|
56
|
-
execSync(`"${npmBin}" install -g
|
|
60
|
+
const pkg = latest ? `@myapihq/cli@${latest}` : '@myapihq/cli@latest';
|
|
61
|
+
execSync(`"${npmBin()}" install -g ${pkg}`, { stdio: 'inherit' });
|
|
57
62
|
}
|
|
58
63
|
catch {
|
|
59
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 ===
|
|
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
package/src/commands/domain.ts
CHANGED
|
@@ -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?:
|
|
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
|
-
|
|
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
|
|
package/src/commands/update.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
-
import { loadConfig
|
|
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> {
|
|
@@ -17,19 +22,17 @@ export async function checkForUpdate(currentVersion: string): Promise<void> {
|
|
|
17
22
|
if (latest && isNewer(latest, currentVersion)) {
|
|
18
23
|
info(`\n› New version available (${currentVersion} → ${latest}) — installing…`);
|
|
19
24
|
try {
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
execSync(`"${npmBin}" install -g @myapihq/cli`, { stdio: 'pipe' });
|
|
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' });
|
|
23
27
|
const config = loadConfig();
|
|
24
28
|
if (config?.skills_installed) {
|
|
25
29
|
await installSkills();
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
process.exit(0);
|
|
31
|
+
info(`› Updated to ${latest} — active after this command completes.\n`);
|
|
29
32
|
} catch (installErr: any) {
|
|
30
33
|
const msg = installErr?.stderr?.toString?.() || installErr?.message || String(installErr);
|
|
31
34
|
info(`› Auto-update failed: ${msg.trim()}`);
|
|
32
|
-
info(`› Run manually: npm install -g @myapihq/cli`);
|
|
35
|
+
info(`› Run manually: npm install -g @myapihq/cli@${latest}`);
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
} catch {
|
|
@@ -40,20 +43,22 @@ export async function checkForUpdate(currentVersion: string): Promise<void> {
|
|
|
40
43
|
// myapi update — explicit update, same logic as auto-update.
|
|
41
44
|
export async function update(flags: Record<string, string | boolean> = {}): Promise<void> {
|
|
42
45
|
if (flags.help) {
|
|
43
|
-
info('Usage: myapi update\n\nUpdates the MyAPI CLI
|
|
46
|
+
info('Usage: myapi update\n\nUpdates the MyAPI CLI to the latest published version.\nEquivalent to: npm install -g @myapihq/cli@latest');
|
|
44
47
|
return;
|
|
45
48
|
}
|
|
46
49
|
info('› Checking for updates…');
|
|
50
|
+
let latest = '';
|
|
47
51
|
try {
|
|
48
52
|
const res = await fetch(REGISTRY_URL, { signal: AbortSignal.timeout(5000) });
|
|
49
53
|
if (!res.ok) throw new Error(`registry returned ${res.status}`);
|
|
50
54
|
const data = await res.json() as { version?: string };
|
|
51
|
-
|
|
55
|
+
latest = data.version ?? '';
|
|
56
|
+
if (latest) info(`› Installing @myapihq/cli@${latest}…`);
|
|
52
57
|
} catch { /* proceed anyway */ }
|
|
53
58
|
|
|
54
59
|
try {
|
|
55
|
-
const
|
|
56
|
-
execSync(`"${npmBin}" install -g
|
|
60
|
+
const pkg = latest ? `@myapihq/cli@${latest}` : '@myapihq/cli@latest';
|
|
61
|
+
execSync(`"${npmBin()}" install -g ${pkg}`, { stdio: 'inherit' });
|
|
57
62
|
} catch {
|
|
58
63
|
process.exit(1);
|
|
59
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 ===
|
|
123
|
-
else if (err.status ===
|
|
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
|
|