@networkbase/cli 1.0.0 → 1.0.1
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/bin/nb.mjs +13 -64
- package/package.json +1 -1
package/bin/nb.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { fileURLToPath } from "node:url";
|
|
|
11
11
|
|
|
12
12
|
const CLI_SCRIPT_PATH = fileURLToPath(import.meta.url);
|
|
13
13
|
|
|
14
|
-
const CLI_VERSION = "1.0.
|
|
14
|
+
const CLI_VERSION = "1.0.1";
|
|
15
15
|
const DEFAULT_API_URL = process.env.NETWORKBASE_API_URL || "https://networkbase.in";
|
|
16
16
|
const GLOBAL_CONFIG_DIR = path.join(os.homedir(), ".networkbase");
|
|
17
17
|
const GLOBAL_CREDENTIALS_PATH = path.join(GLOBAL_CONFIG_DIR, "credentials.json");
|
|
@@ -466,16 +466,7 @@ async function apiRequest(endpoint, options = {}) {
|
|
|
466
466
|
signal: AbortSignal.timeout(timeoutMs),
|
|
467
467
|
});
|
|
468
468
|
} catch (fetchErr) {
|
|
469
|
-
|
|
470
|
-
response = await fetch(`http://localhost:3000${endpoint}`, {
|
|
471
|
-
method: options.method || "GET",
|
|
472
|
-
headers,
|
|
473
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
474
|
-
signal: AbortSignal.timeout(timeoutMs),
|
|
475
|
-
});
|
|
476
|
-
} else {
|
|
477
|
-
throw fetchErr;
|
|
478
|
-
}
|
|
469
|
+
throw fetchErr;
|
|
479
470
|
}
|
|
480
471
|
|
|
481
472
|
if (response.status === 304) {
|
|
@@ -1342,28 +1333,14 @@ async function tuiTextInput({ title, stepLabel = title, hint = "", placeholder =
|
|
|
1342
1333
|
});
|
|
1343
1334
|
}
|
|
1344
1335
|
|
|
1345
|
-
async function resolveBestApiUrl(explicitUrl) {
|
|
1336
|
+
async function resolveBestApiUrl(explicitUrl, flags = {}) {
|
|
1346
1337
|
if (explicitUrl) return explicitUrl.replace(/\/+$/, "");
|
|
1338
|
+
if (flags.dev || flags.local) return "http://localhost:3000";
|
|
1347
1339
|
if (process.env.NETWORKBASE_API_URL) return process.env.NETWORKBASE_API_URL.replace(/\/+$/, "");
|
|
1348
|
-
const localCfg = getLocalConfig();
|
|
1349
|
-
if (localCfg?.apiUrl) return localCfg.apiUrl.replace(/\/+$/, "");
|
|
1350
1340
|
const creds = getCredentials();
|
|
1351
|
-
if (creds?.apiUrl) return creds.apiUrl.replace(/\/+$/, "");
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
try {
|
|
1355
|
-
const controller = new AbortController();
|
|
1356
|
-
const timer = setTimeout(() => controller.abort(), 600);
|
|
1357
|
-
const res = await fetch("http://localhost:3000/api/v1/extension/session", {
|
|
1358
|
-
signal: controller.signal,
|
|
1359
|
-
});
|
|
1360
|
-
clearTimeout(timer);
|
|
1361
|
-
if (res.status === 200 || res.status === 401) {
|
|
1362
|
-
return "http://localhost:3000";
|
|
1363
|
-
}
|
|
1364
|
-
} catch {
|
|
1365
|
-
// Local dev server not running; fall back to production URL
|
|
1366
|
-
}
|
|
1341
|
+
if (creds?.apiUrl && creds.apiUrl !== "http://localhost:3000") return creds.apiUrl.replace(/\/+$/, "");
|
|
1342
|
+
const localCfg = getLocalConfig();
|
|
1343
|
+
if (localCfg?.apiUrl && localCfg.apiUrl !== "http://localhost:3000") return localCfg.apiUrl.replace(/\/+$/, "");
|
|
1367
1344
|
return DEFAULT_API_URL.replace(/\/+$/, "");
|
|
1368
1345
|
}
|
|
1369
1346
|
|
|
@@ -1506,41 +1483,13 @@ async function loginWithToken(rawToken, apiUrl, explicitUrl = null) {
|
|
|
1506
1483
|
throw new Error("A valid `nb_dev_...` or `nb_pat_...` token is required.");
|
|
1507
1484
|
}
|
|
1508
1485
|
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
token,
|
|
1515
|
-
});
|
|
1516
|
-
} catch (err) {
|
|
1517
|
-
if (!explicitUrl && resolvedUrl !== "http://localhost:3000") {
|
|
1518
|
-
resolvedUrl = "http://localhost:3000";
|
|
1519
|
-
sessionInfo = await apiRequest("/api/v1/extension/session", {
|
|
1520
|
-
apiUrl: resolvedUrl,
|
|
1521
|
-
token,
|
|
1522
|
-
});
|
|
1523
|
-
} else {
|
|
1524
|
-
throw err;
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
if (!sessionInfo.active && !explicitUrl && resolvedUrl !== "http://localhost:3000") {
|
|
1529
|
-
try {
|
|
1530
|
-
const localInfo = await apiRequest("/api/v1/extension/session", {
|
|
1531
|
-
apiUrl: "http://localhost:3000",
|
|
1532
|
-
token,
|
|
1533
|
-
});
|
|
1534
|
-
if (localInfo?.active) {
|
|
1535
|
-
resolvedUrl = "http://localhost:3000";
|
|
1536
|
-
sessionInfo = localInfo;
|
|
1537
|
-
}
|
|
1538
|
-
} catch {
|
|
1539
|
-
// Ignore fallback failure
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1486
|
+
const resolvedUrl = apiUrl;
|
|
1487
|
+
const sessionInfo = await apiRequest("/api/v1/extension/session", {
|
|
1488
|
+
apiUrl: resolvedUrl,
|
|
1489
|
+
token,
|
|
1490
|
+
});
|
|
1542
1491
|
|
|
1543
|
-
if (!sessionInfo
|
|
1492
|
+
if (!sessionInfo?.active) {
|
|
1544
1493
|
throw new Error("This token is expired or has been revoked.");
|
|
1545
1494
|
}
|
|
1546
1495
|
|