@neat.is/core 0.9.15-dev.20260911 → 0.9.15-dev.20260912
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.js
CHANGED
|
@@ -5776,7 +5776,9 @@ async function clearActiveProfile(home = neatHome()) {
|
|
|
5776
5776
|
}
|
|
5777
5777
|
|
|
5778
5778
|
// src/login-cli.ts
|
|
5779
|
-
var
|
|
5779
|
+
var PROBE_ATTEMPT_TIMEOUT_MS = 3e4;
|
|
5780
|
+
var PROBE_TOTAL_BUDGET_MS = 12e4;
|
|
5781
|
+
var PROBE_RETRY_PAUSE_MS = 2e3;
|
|
5780
5782
|
var DEFAULT_PROFILE_NAME = "hosted";
|
|
5781
5783
|
function readFlagValue(argv, i) {
|
|
5782
5784
|
const arg = argv[i];
|
|
@@ -5817,15 +5819,19 @@ function printLoginHelp(out) {
|
|
|
5817
5819
|
out(' "hosted"). The token can also come from NEAT_LOGIN_TOKEN.');
|
|
5818
5820
|
out(" Exit 0 on success, 1 rejected token/endpoint, 2 misuse, 3 unreachable.");
|
|
5819
5821
|
}
|
|
5820
|
-
|
|
5821
|
-
const
|
|
5822
|
+
function isTimeoutError(err) {
|
|
5823
|
+
const name = err?.name;
|
|
5824
|
+
return name === "TimeoutError" || name === "AbortError";
|
|
5825
|
+
}
|
|
5826
|
+
async function probeOnce(fetchImpl, root, token, timeoutMs) {
|
|
5822
5827
|
let res;
|
|
5823
5828
|
try {
|
|
5824
5829
|
res = await fetchImpl(`${root}/health`, {
|
|
5825
5830
|
headers: { authorization: `Bearer ${token}` },
|
|
5826
|
-
signal: AbortSignal.timeout(
|
|
5831
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
5827
5832
|
});
|
|
5828
5833
|
} catch (err) {
|
|
5834
|
+
if (isTimeoutError(err)) return { kind: "timeout" };
|
|
5829
5835
|
return { kind: "unreachable", detail: err.message };
|
|
5830
5836
|
}
|
|
5831
5837
|
if (res.status === 401 || res.status === 403) return { kind: "unauthorized", status: res.status };
|
|
@@ -5834,6 +5840,23 @@ async function probeDaemon(fetchImpl, endpoint, token) {
|
|
|
5834
5840
|
if (!contentType.includes("json")) return { kind: "not-neat", status: res.status };
|
|
5835
5841
|
return { kind: "ok" };
|
|
5836
5842
|
}
|
|
5843
|
+
async function probeDaemon(fetchImpl, endpoint, token, hooks) {
|
|
5844
|
+
const root = endpoint.replace(/\/$/, "");
|
|
5845
|
+
const deadline = hooks.now() + PROBE_TOTAL_BUDGET_MS;
|
|
5846
|
+
let warned = false;
|
|
5847
|
+
for (; ; ) {
|
|
5848
|
+
const result = await probeOnce(fetchImpl, root, token, PROBE_ATTEMPT_TIMEOUT_MS);
|
|
5849
|
+
if (result.kind !== "timeout") return result;
|
|
5850
|
+
if (!warned) {
|
|
5851
|
+
hooks.onWaiting();
|
|
5852
|
+
warned = true;
|
|
5853
|
+
}
|
|
5854
|
+
if (hooks.now() >= deadline) {
|
|
5855
|
+
return { kind: "unreachable", detail: `no response after ${Math.round(PROBE_TOTAL_BUDGET_MS / 1e3)}s` };
|
|
5856
|
+
}
|
|
5857
|
+
await hooks.sleep(PROBE_RETRY_PAUSE_MS);
|
|
5858
|
+
}
|
|
5859
|
+
}
|
|
5837
5860
|
async function runLoginCommand(argv, deps = {}) {
|
|
5838
5861
|
const out = deps.out ?? ((line) => console.log(line));
|
|
5839
5862
|
const err = deps.err ?? ((line) => console.error(line));
|
|
@@ -5841,6 +5864,8 @@ async function runLoginCommand(argv, deps = {}) {
|
|
|
5841
5864
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
5842
5865
|
const readLine = deps.readLine ?? defaultReadLine;
|
|
5843
5866
|
const readSecret = deps.readSecret ?? defaultReadSecret;
|
|
5867
|
+
const sleep2 = deps.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
5868
|
+
const now = deps.now ?? Date.now;
|
|
5844
5869
|
const args = parseLoginArgs(argv);
|
|
5845
5870
|
if (args.help) {
|
|
5846
5871
|
printLoginHelp(out);
|
|
@@ -5874,7 +5899,11 @@ async function runLoginCommand(argv, deps = {}) {
|
|
|
5874
5899
|
err("neat login: a token is required \u2014 pass --token, set NEAT_LOGIN_TOKEN, or run interactively");
|
|
5875
5900
|
return 2;
|
|
5876
5901
|
}
|
|
5877
|
-
const probe = await probeDaemon(fetchImpl, endpoint, token
|
|
5902
|
+
const probe = await probeDaemon(fetchImpl, endpoint, token, {
|
|
5903
|
+
sleep: sleep2,
|
|
5904
|
+
now,
|
|
5905
|
+
onWaiting: () => err("Waking the hosted daemon \u2014 a cold instance can take up to a minute\u2026")
|
|
5906
|
+
});
|
|
5878
5907
|
if (probe.kind === "unreachable") {
|
|
5879
5908
|
err(`neat login: can't reach ${endpoint} \u2014 ${probe.detail}`);
|
|
5880
5909
|
return 3;
|