@neat.is/core 0.9.15-dev.20260911 → 0.9.15-dev.20260913
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/cli.cjs +34 -5
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +34 -5
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.cjs
CHANGED
|
@@ -30250,7 +30250,9 @@ async function clearActiveProfile(home = neatHome3()) {
|
|
|
30250
30250
|
}
|
|
30251
30251
|
|
|
30252
30252
|
// src/login-cli.ts
|
|
30253
|
-
var
|
|
30253
|
+
var PROBE_ATTEMPT_TIMEOUT_MS = 3e4;
|
|
30254
|
+
var PROBE_TOTAL_BUDGET_MS = 12e4;
|
|
30255
|
+
var PROBE_RETRY_PAUSE_MS = 2e3;
|
|
30254
30256
|
var DEFAULT_PROFILE_NAME = "hosted";
|
|
30255
30257
|
function readFlagValue(argv, i) {
|
|
30256
30258
|
const arg = argv[i];
|
|
@@ -30291,15 +30293,19 @@ function printLoginHelp(out) {
|
|
|
30291
30293
|
out(' "hosted"). The token can also come from NEAT_LOGIN_TOKEN.');
|
|
30292
30294
|
out(" Exit 0 on success, 1 rejected token/endpoint, 2 misuse, 3 unreachable.");
|
|
30293
30295
|
}
|
|
30294
|
-
|
|
30295
|
-
const
|
|
30296
|
+
function isTimeoutError(err) {
|
|
30297
|
+
const name = err?.name;
|
|
30298
|
+
return name === "TimeoutError" || name === "AbortError";
|
|
30299
|
+
}
|
|
30300
|
+
async function probeOnce(fetchImpl, root, token, timeoutMs) {
|
|
30296
30301
|
let res;
|
|
30297
30302
|
try {
|
|
30298
30303
|
res = await fetchImpl(`${root}/health`, {
|
|
30299
30304
|
headers: { authorization: `Bearer ${token}` },
|
|
30300
|
-
signal: AbortSignal.timeout(
|
|
30305
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
30301
30306
|
});
|
|
30302
30307
|
} catch (err) {
|
|
30308
|
+
if (isTimeoutError(err)) return { kind: "timeout" };
|
|
30303
30309
|
return { kind: "unreachable", detail: err.message };
|
|
30304
30310
|
}
|
|
30305
30311
|
if (res.status === 401 || res.status === 403) return { kind: "unauthorized", status: res.status };
|
|
@@ -30308,6 +30314,23 @@ async function probeDaemon(fetchImpl, endpoint2, token) {
|
|
|
30308
30314
|
if (!contentType.includes("json")) return { kind: "not-neat", status: res.status };
|
|
30309
30315
|
return { kind: "ok" };
|
|
30310
30316
|
}
|
|
30317
|
+
async function probeDaemon(fetchImpl, endpoint2, token, hooks) {
|
|
30318
|
+
const root = endpoint2.replace(/\/$/, "");
|
|
30319
|
+
const deadline = hooks.now() + PROBE_TOTAL_BUDGET_MS;
|
|
30320
|
+
let warned = false;
|
|
30321
|
+
for (; ; ) {
|
|
30322
|
+
const result = await probeOnce(fetchImpl, root, token, PROBE_ATTEMPT_TIMEOUT_MS);
|
|
30323
|
+
if (result.kind !== "timeout") return result;
|
|
30324
|
+
if (!warned) {
|
|
30325
|
+
hooks.onWaiting();
|
|
30326
|
+
warned = true;
|
|
30327
|
+
}
|
|
30328
|
+
if (hooks.now() >= deadline) {
|
|
30329
|
+
return { kind: "unreachable", detail: `no response after ${Math.round(PROBE_TOTAL_BUDGET_MS / 1e3)}s` };
|
|
30330
|
+
}
|
|
30331
|
+
await hooks.sleep(PROBE_RETRY_PAUSE_MS);
|
|
30332
|
+
}
|
|
30333
|
+
}
|
|
30311
30334
|
async function runLoginCommand(argv, deps = {}) {
|
|
30312
30335
|
const out = deps.out ?? ((line) => console.log(line));
|
|
30313
30336
|
const err = deps.err ?? ((line) => console.error(line));
|
|
@@ -30315,6 +30338,8 @@ async function runLoginCommand(argv, deps = {}) {
|
|
|
30315
30338
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
30316
30339
|
const readLine = deps.readLine ?? defaultReadLine;
|
|
30317
30340
|
const readSecret = deps.readSecret ?? defaultReadSecret;
|
|
30341
|
+
const sleep2 = deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
30342
|
+
const now = deps.now ?? Date.now;
|
|
30318
30343
|
const args = parseLoginArgs(argv);
|
|
30319
30344
|
if (args.help) {
|
|
30320
30345
|
printLoginHelp(out);
|
|
@@ -30348,7 +30373,11 @@ async function runLoginCommand(argv, deps = {}) {
|
|
|
30348
30373
|
err("neat login: a token is required \u2014 pass --token, set NEAT_LOGIN_TOKEN, or run interactively");
|
|
30349
30374
|
return 2;
|
|
30350
30375
|
}
|
|
30351
|
-
const probe = await probeDaemon(fetchImpl, endpoint2, token
|
|
30376
|
+
const probe = await probeDaemon(fetchImpl, endpoint2, token, {
|
|
30377
|
+
sleep: sleep2,
|
|
30378
|
+
now,
|
|
30379
|
+
onWaiting: () => err("Waking the hosted daemon \u2014 a cold instance can take up to a minute\u2026")
|
|
30380
|
+
});
|
|
30352
30381
|
if (probe.kind === "unreachable") {
|
|
30353
30382
|
err(`neat login: can't reach ${endpoint2} \u2014 ${probe.detail}`);
|
|
30354
30383
|
return 3;
|