@rigstate/cli 0.7.14 → 0.7.16
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/index.cjs +77 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +71 -92
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/config.ts +4 -4
- package/src/commands/link.ts +3 -2
- package/src/daemon/factory.ts +2 -3
- package/src/utils/config.ts +1 -42
package/package.json
CHANGED
package/src/commands/config.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
import { getApiKey, setApiKey, getProjectId, setProjectId, getApiUrl } from '../utils/config.js';
|
|
3
|
+
import { getApiKey, setApiKey, getProjectId, setProjectId, getApiUrl, setApiUrl } from '../utils/config.js';
|
|
4
4
|
|
|
5
5
|
export function createConfigCommand() {
|
|
6
6
|
const config = new Command('config');
|
|
@@ -68,12 +68,12 @@ export function createConfigCommand() {
|
|
|
68
68
|
console.log(chalk.green(`✅ project_id updated`));
|
|
69
69
|
break;
|
|
70
70
|
case 'api_url':
|
|
71
|
-
|
|
72
|
-
console.log(chalk.
|
|
71
|
+
setApiUrl(value);
|
|
72
|
+
console.log(chalk.green(`✅ api_url updated`));
|
|
73
73
|
break;
|
|
74
74
|
default:
|
|
75
75
|
console.log(chalk.red(`Unknown config key: ${key}`));
|
|
76
|
-
console.log(chalk.dim('Valid keys: api_key, project_id'));
|
|
76
|
+
console.log(chalk.dim('Valid keys: api_key, project_id, api_url'));
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
|
package/src/commands/link.ts
CHANGED
|
@@ -4,6 +4,7 @@ import fs from 'fs/promises';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import os from 'os';
|
|
7
|
+
import { getApiUrl, getApiKey } from '../utils/config.js';
|
|
7
8
|
|
|
8
9
|
export function createLinkCommand() {
|
|
9
10
|
return new Command('link')
|
|
@@ -31,7 +32,7 @@ export function createLinkCommand() {
|
|
|
31
32
|
|
|
32
33
|
const content = {
|
|
33
34
|
project_id: projectId,
|
|
34
|
-
api_url:
|
|
35
|
+
api_url: getApiUrl(),
|
|
35
36
|
linked_at: new Date().toISOString()
|
|
36
37
|
};
|
|
37
38
|
|
|
@@ -45,7 +46,7 @@ export function createLinkCommand() {
|
|
|
45
46
|
console.log(chalk.bold('🤖 Rigstate Automation Detected'));
|
|
46
47
|
console.log('');
|
|
47
48
|
|
|
48
|
-
const { getApiKey, getApiUrl } = await import('../utils/config.js');
|
|
49
|
+
const { getApiKey: _getApiKey, getApiUrl: _getApiUrl } = await import('../utils/config.js');
|
|
49
50
|
const apiKey = getApiKey(); // Might throw if not logged in
|
|
50
51
|
const apiUrl = getApiUrl();
|
|
51
52
|
|
package/src/daemon/factory.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GuardianDaemon } from './core.js';
|
|
2
|
-
import { getApiKey, getApiUrl,
|
|
2
|
+
import { getApiKey, getApiUrl, getProjectId } from '../utils/config.js';
|
|
3
3
|
import { loadManifest } from '../utils/manifest.js';
|
|
4
4
|
import { DaemonConfig } from './types.js';
|
|
5
5
|
|
|
@@ -12,8 +12,7 @@ export async function createDaemon(options: {
|
|
|
12
12
|
noBridge?: boolean;
|
|
13
13
|
verbose?: boolean;
|
|
14
14
|
}): Promise<GuardianDaemon> {
|
|
15
|
-
|
|
16
|
-
const apiUrl = await discoverApiUrl();
|
|
15
|
+
const apiUrl = getApiUrl();
|
|
17
16
|
|
|
18
17
|
let projectId = options.project;
|
|
19
18
|
|
package/src/utils/config.ts
CHANGED
|
@@ -11,7 +11,7 @@ interface RigstateConfig {
|
|
|
11
11
|
const config = new Conf<RigstateConfig>({
|
|
12
12
|
projectName: 'rigstate-cli',
|
|
13
13
|
defaults: {
|
|
14
|
-
apiUrl: '
|
|
14
|
+
apiUrl: 'https://app.rigstate.com',
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -50,12 +50,6 @@ export function setProjectId(projectId: string): void {
|
|
|
50
50
|
config.set('projectId', projectId);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// Basic check if a port is open - simplistic implementation for now
|
|
54
|
-
// In a real scenario, we might want to actually ping /api/health
|
|
55
|
-
// But for getApiUrl which is synchronous, we cannot easily do async checks.
|
|
56
|
-
// So we will stick to the config/env value, BUT we will expose a separate
|
|
57
|
-
// async function `discoverApiUrl` that the Daemon calls on startup.
|
|
58
|
-
|
|
59
53
|
/**
|
|
60
54
|
* Get the API URL (Synchronous)
|
|
61
55
|
* Priority: Environment variable > Stored config > Production default
|
|
@@ -74,41 +68,6 @@ export function getApiUrl(): string {
|
|
|
74
68
|
return 'https://app.rigstate.com';
|
|
75
69
|
}
|
|
76
70
|
|
|
77
|
-
/**
|
|
78
|
-
* Discovers the active local API URL (Async)
|
|
79
|
-
* Scans ports 3000-3010 to find a responding Rigstate server.
|
|
80
|
-
* This is now SILENT and will not spam the console.
|
|
81
|
-
*/
|
|
82
|
-
export async function discoverApiUrl(): Promise<string> {
|
|
83
|
-
const configuredUrl = getApiUrl();
|
|
84
|
-
const ports = [3000, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010];
|
|
85
|
-
|
|
86
|
-
// If not localhost, don't even bother scanning (saves time/noise)
|
|
87
|
-
if (!configuredUrl.includes('localhost') && !configuredUrl.includes('127.0.0.1')) {
|
|
88
|
-
return configuredUrl;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Silent scan - check ports for a valid health endpoint
|
|
92
|
-
for (const port of ports) {
|
|
93
|
-
const url = `http://localhost:${port}`;
|
|
94
|
-
try {
|
|
95
|
-
const res = await axios.get(`${url}/api/v1/system/health`, { timeout: 200 });
|
|
96
|
-
// If it responds with 'healthy', we found a Rigstate server!
|
|
97
|
-
if (res.data?.status === 'healthy') {
|
|
98
|
-
if (url !== configuredUrl) {
|
|
99
|
-
setApiUrl(url);
|
|
100
|
-
}
|
|
101
|
-
return url;
|
|
102
|
-
}
|
|
103
|
-
} catch (e) {
|
|
104
|
-
// Move to next port silently
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Default to Cloud if local Rigstate server is not found
|
|
109
|
-
return 'https://app.rigstate.com';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
71
|
/**
|
|
113
72
|
* Set the API URL
|
|
114
73
|
*/
|