@rigstate/cli 0.7.7 → 0.7.9

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.js CHANGED
@@ -55,6 +55,7 @@ var config_exports = {};
55
55
  __export(config_exports, {
56
56
  clearConfig: () => clearConfig,
57
57
  config: () => config,
58
+ discoverApiUrl: () => discoverApiUrl,
58
59
  getApiKey: () => getApiKey,
59
60
  getApiUrl: () => getApiUrl,
60
61
  getProjectId: () => getProjectId,
@@ -91,6 +92,27 @@ function getApiUrl() {
91
92
  }
92
93
  return "https://app.rigstate.com";
93
94
  }
95
+ async function discoverApiUrl() {
96
+ const configuredUrl = getApiUrl();
97
+ if (!configuredUrl.includes("localhost") && !configuredUrl.includes("127.0.0.1")) {
98
+ return configuredUrl;
99
+ }
100
+ const ports = [3e3, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010];
101
+ const { default: axios22 } = await import("axios");
102
+ for (const port of ports) {
103
+ try {
104
+ const url = `http://localhost:${port}`;
105
+ await axios22.get(`${url}/api/v1/system/health`, { timeout: 500 });
106
+ if (url !== configuredUrl) {
107
+ setApiUrl(url);
108
+ }
109
+ return url;
110
+ } catch (e) {
111
+ continue;
112
+ }
113
+ }
114
+ return configuredUrl;
115
+ }
94
116
  function setApiUrl(url) {
95
117
  config.set("apiUrl", url);
96
118
  }
@@ -1843,9 +1865,9 @@ function createLinkCommand() {
1843
1865
  console.log("");
1844
1866
  console.log(chalk6.bold("\u{1F916} Rigstate Automation Detected"));
1845
1867
  console.log("");
1846
- const { getApiKey: getApiKey2, getApiUrl: getApiUrl2 } = await Promise.resolve().then(() => (init_config(), config_exports));
1868
+ const { getApiKey: getApiKey2, getApiUrl: getApiUrl3 } = await Promise.resolve().then(() => (init_config(), config_exports));
1847
1869
  const apiKey = getApiKey2();
1848
- const apiUrl = getApiUrl2();
1870
+ const apiUrl = getApiUrl3();
1849
1871
  if (apiKey) {
1850
1872
  console.log(chalk6.blue("\u{1F510} Checking Vault for secrets..."));
1851
1873
  const { syncEnv: syncEnv2 } = await Promise.resolve().then(() => (init_env(), env_exports));
@@ -3836,7 +3858,7 @@ var GuardianDaemon = class extends EventEmitter3 {
3836
3858
  // src/daemon/factory.ts
3837
3859
  init_config();
3838
3860
  async function createDaemon(options) {
3839
- const apiUrl = getApiUrl();
3861
+ const apiUrl = await discoverApiUrl();
3840
3862
  let projectId = options.project;
3841
3863
  if (!projectId) {
3842
3864
  const manifest = await loadManifest();