@nurix/nustack 0.26.0 → 0.26.2
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/commands/login.js +17 -4
- package/dist/lib/sync/client.js +17 -4
- package/package.json +4 -4
package/dist/commands/login.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import * as p from "@clack/prompts";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveNuStackOrigin } from "../lib/nustack_client.js";
|
|
3
3
|
import { launchBrowser } from "../lib/browser_opener.js";
|
|
4
4
|
import { selectCredentialStore } from "../lib/credential_store.js";
|
|
5
5
|
import { isInteractive } from "../lib/interactive.js";
|
|
6
6
|
import { ensureAccessToken, ENV_TOKEN_VARIABLE, envToken, loginWithLoopback, loginWithPastedCode, prepareLogin, readStoredCredential, } from "../lib/auth_grant.js";
|
|
7
7
|
import { isContractOrigin, nullUnlessOriginRefused, originMismatchError, refusedContractOrigin } from "../lib/origin_guard.js";
|
|
8
|
+
function originOf(url) {
|
|
9
|
+
try {
|
|
10
|
+
return url ? new URL(url).origin : null;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
8
16
|
async function readStdinLine() {
|
|
9
17
|
return new Promise((resolve) => {
|
|
10
18
|
let buffered = "";
|
|
@@ -96,7 +104,12 @@ export async function performDeviceLogin(baseUrl, _cwd = process.cwd(), flags =
|
|
|
96
104
|
p.log.error(error instanceof Error ? error.message : String(error));
|
|
97
105
|
return false;
|
|
98
106
|
}
|
|
99
|
-
|
|
107
|
+
const heldOrigin = originOf((await readStoredCredential().catch(() => null))?.credential?.studioBaseUrl);
|
|
108
|
+
const isMoving = flags.isOriginStated === true && heldOrigin !== null && heldOrigin !== originOf(baseUrl);
|
|
109
|
+
if (isMoving) {
|
|
110
|
+
p.log.info(`This machine is signed in to ${heldOrigin}; signing in to ${originOf(baseUrl)} moves it there, and the desktop app shares the sign-in.`);
|
|
111
|
+
}
|
|
112
|
+
if (!flags.force && !flags.reauthorize && !isMoving) {
|
|
100
113
|
const live = await ensureAccessToken().catch(nullUnlessOriginRefused);
|
|
101
114
|
if (live) {
|
|
102
115
|
p.log.success(`Signed in as ${live.userEmail || "this account"} — already signed in on this machine (use --force to sign in again).`);
|
|
@@ -140,9 +153,9 @@ export async function performDeviceLogin(baseUrl, _cwd = process.cwd(), flags =
|
|
|
140
153
|
return true;
|
|
141
154
|
}
|
|
142
155
|
export async function runLogin(options, flags = {}) {
|
|
143
|
-
const baseUrl =
|
|
156
|
+
const { url: baseUrl, source } = resolveNuStackOrigin(options, process.cwd());
|
|
144
157
|
p.intro("nustack login");
|
|
145
|
-
const didLogin = await performDeviceLogin(baseUrl, process.cwd(), flags);
|
|
158
|
+
const didLogin = await performDeviceLogin(baseUrl, process.cwd(), { ...flags, isOriginStated: source === "flag" || source === "env" });
|
|
146
159
|
if (!didLogin) {
|
|
147
160
|
p.outro("Nothing was written.");
|
|
148
161
|
process.exitCode = 1;
|
package/dist/lib/sync/client.js
CHANGED
|
@@ -18,7 +18,19 @@ const REQUEST_TIMEOUT_MS = 10_000;
|
|
|
18
18
|
const MAX_PUSH_PASSES = 50;
|
|
19
19
|
const MAX_PULL_PAGES = 500;
|
|
20
20
|
const DEVICE_PROJECTION_FIELDS = ["origin", "type", "subject", "state", "outcome", "ownerAgentDefinitionId"];
|
|
21
|
-
|
|
21
|
+
function releaseOf(version) {
|
|
22
|
+
const match = version ? /^v?(\d+)\.(\d+)/.exec(version.trim()) : null;
|
|
23
|
+
return match ? [Number(match[1]), Number(match[2])] : null;
|
|
24
|
+
}
|
|
25
|
+
export function outdatedMessage(message, serverVersion, clientVersion = cliVersion()) {
|
|
26
|
+
const client = releaseOf(clientVersion);
|
|
27
|
+
const server = releaseOf(serverVersion);
|
|
28
|
+
const isAhead = client !== null && server !== null && (client[0] > server[0] || (client[0] === server[0] && client[1] > server[1]));
|
|
29
|
+
if (isAhead) {
|
|
30
|
+
return `${message} — this CLI (${clientVersion}) is newer than the server (${serverVersion}); sync resumes once the server is updated, or install the server's release: npm i -g @nurix/nustack@${server[0]}.${server[1]}`;
|
|
31
|
+
}
|
|
32
|
+
return `${message} — this CLI (${clientVersion}) is behind the server. Update NuStack: ${UPGRADE_COMMAND}`;
|
|
33
|
+
}
|
|
22
34
|
async function request(url, init, bearer, timeoutMs) {
|
|
23
35
|
try {
|
|
24
36
|
await assertCredentialOrigin(url);
|
|
@@ -47,7 +59,8 @@ async function request(url, init, bearer, timeoutMs) {
|
|
|
47
59
|
if (!response.ok) {
|
|
48
60
|
const code = typeof body?.error?.code === "string" ? body.error.code : null;
|
|
49
61
|
const detail = typeof body?.error?.message === "string" ? body.error.message : typeof body?.message === "string" ? body.message : `HTTP ${response.status}`;
|
|
50
|
-
|
|
62
|
+
const serverVersion = typeof body?.error?.details?.minimumVersion === "string" ? body.error.details.minimumVersion : null;
|
|
63
|
+
return { ok: false, status: response.status, code, message: `${code ?? `HTTP ${response.status}`}: ${detail}`, serverVersion };
|
|
51
64
|
}
|
|
52
65
|
if (!body || body.data === undefined || body.data === null)
|
|
53
66
|
return { ok: false, status: response.status, code: null, message: "the server answered no data" };
|
|
@@ -176,7 +189,7 @@ async function pushBatch(store, base, batch, bearer, summary, timeoutMs) {
|
|
|
176
189
|
const now = Date.now();
|
|
177
190
|
if (!answer.ok) {
|
|
178
191
|
if (answer.status === 426) {
|
|
179
|
-
summary.outdated = outdatedMessage(answer.message);
|
|
192
|
+
summary.outdated = outdatedMessage(answer.message, answer.serverVersion);
|
|
180
193
|
summary.lastError = summary.outdated;
|
|
181
194
|
return false;
|
|
182
195
|
}
|
|
@@ -311,7 +324,7 @@ export async function pullAll(store, globals, options = {}) {
|
|
|
311
324
|
withApplying(store.db, () => writeSyncState(store.db, "cursor", "0"));
|
|
312
325
|
continue;
|
|
313
326
|
}
|
|
314
|
-
summary.lastError = answer.status === 426 ? outdatedMessage(answer.message) : answer.message;
|
|
327
|
+
summary.lastError = answer.status === 426 ? outdatedMessage(answer.message, answer.serverVersion) : answer.message;
|
|
315
328
|
if (answer.status === 426)
|
|
316
329
|
summary.outdated = summary.lastError;
|
|
317
330
|
return summary;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nurix/nustack",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.2",
|
|
4
4
|
"description": "The nustack CLI — bootstrap NuStack services into a repo via the NuStack discovery plane.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@types/node": "^22.19.20",
|
|
35
35
|
"typescript": "^5.7.2",
|
|
36
36
|
"vitest": "^4.1.11",
|
|
37
|
-
"@nurix/contracts": "3.0.1",
|
|
38
|
-
"@nurix/harness": "0.0.0",
|
|
39
37
|
"@nurix/nustack.studio": "0.0.0",
|
|
40
|
-
"@nurix/
|
|
38
|
+
"@nurix/contracts": "3.0.2",
|
|
39
|
+
"@nurix/nustack.ui": "0.0.0",
|
|
40
|
+
"@nurix/harness": "0.0.0"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|