nexarch 0.1.1 → 0.1.3
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/README.md +1 -1
- package/dist/commands/login.js +4 -57
- package/dist/commands/setup.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ npx nexarch setup
|
|
|
17
17
|
| `nexarch logout` | Remove local credentials |
|
|
18
18
|
| `nexarch status` | Check connection and show architecture summary |
|
|
19
19
|
| `nexarch setup` | Auto-configure detected MCP clients |
|
|
20
|
-
| `nexarch mcp-config [client]` | Print config block for manual setup |
|
|
20
|
+
| `nexarch mcp-config [client]` | Print config block for manual setup (`claude-desktop`, `cursor`, `windsurf`) |
|
|
21
21
|
| `nexarch mcp-proxy` | stdio→HTTP bridge used internally by MCP clients |
|
|
22
22
|
|
|
23
23
|
## Requirements
|
package/dist/commands/login.js
CHANGED
|
@@ -2,11 +2,9 @@ import { createServer } from "http";
|
|
|
2
2
|
import { createServer as createNetServer } from "net";
|
|
3
3
|
import { randomBytes } from "crypto";
|
|
4
4
|
import { execFile } from "child_process";
|
|
5
|
-
import https from "https";
|
|
6
5
|
import { saveCredentials } from "../lib/credentials.js";
|
|
7
6
|
const NEXARCH_URL = "https://nexarch.ai";
|
|
8
7
|
const LOGIN_TIMEOUT_MS = 5 * 60 * 1000;
|
|
9
|
-
const VERIFY_TIMEOUT_MS = 15 * 1000;
|
|
10
8
|
function generateState() {
|
|
11
9
|
return randomBytes(16).toString("hex");
|
|
12
10
|
}
|
|
@@ -59,6 +57,7 @@ function waitForCallback(port, expectedState) {
|
|
|
59
57
|
clearTimeout(timeout);
|
|
60
58
|
const state = url.searchParams.get("state");
|
|
61
59
|
const token = url.searchParams.get("token");
|
|
60
|
+
const companyId = url.searchParams.get("companyId");
|
|
62
61
|
const error = url.searchParams.get("error");
|
|
63
62
|
const html = (message) => `<!DOCTYPE html><html><head><meta charset="utf-8"><title>Nexarch CLI</title>
|
|
64
63
|
<style>body{font-family:system-ui,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#f8fafc}
|
|
@@ -79,7 +78,7 @@ function waitForCallback(port, expectedState) {
|
|
|
79
78
|
settle(() => reject(new Error("Authorization was cancelled.")));
|
|
80
79
|
return;
|
|
81
80
|
}
|
|
82
|
-
if (!token) {
|
|
81
|
+
if (!token || !companyId) {
|
|
83
82
|
res.writeHead(400, { "Content-Type": "text/html" });
|
|
84
83
|
res.end(html("Missing token. Please run <code>nexarch login</code> again."));
|
|
85
84
|
server.close();
|
|
@@ -89,7 +88,7 @@ function waitForCallback(port, expectedState) {
|
|
|
89
88
|
res.writeHead(200, { "Content-Type": "text/html" });
|
|
90
89
|
res.end(html("Authorization successful! You can close this tab and return to your terminal."));
|
|
91
90
|
server.close();
|
|
92
|
-
settle(() => resolve({ token }));
|
|
91
|
+
settle(() => resolve({ token, companyId }));
|
|
93
92
|
});
|
|
94
93
|
const timeout = setTimeout(() => {
|
|
95
94
|
server.close();
|
|
@@ -102,55 +101,6 @@ function waitForCallback(port, expectedState) {
|
|
|
102
101
|
});
|
|
103
102
|
});
|
|
104
103
|
}
|
|
105
|
-
function fetchCompanyId(token) {
|
|
106
|
-
const body = JSON.stringify({
|
|
107
|
-
jsonrpc: "2.0",
|
|
108
|
-
id: 1,
|
|
109
|
-
method: "tools/call",
|
|
110
|
-
params: { name: "nexarch_get_governance_summary", arguments: {} },
|
|
111
|
-
});
|
|
112
|
-
return new Promise((resolve, reject) => {
|
|
113
|
-
const url = new URL("/mcp", "https://mcp.nexarch.ai");
|
|
114
|
-
const req = https.request({
|
|
115
|
-
hostname: url.hostname,
|
|
116
|
-
port: url.port || 443,
|
|
117
|
-
path: url.pathname,
|
|
118
|
-
method: "POST",
|
|
119
|
-
headers: {
|
|
120
|
-
"Content-Type": "application/json",
|
|
121
|
-
Authorization: `Bearer ${token}`,
|
|
122
|
-
"Content-Length": Buffer.byteLength(body),
|
|
123
|
-
},
|
|
124
|
-
timeout: VERIFY_TIMEOUT_MS,
|
|
125
|
-
}, (res) => {
|
|
126
|
-
const chunks = [];
|
|
127
|
-
res.on("data", (c) => chunks.push(c));
|
|
128
|
-
res.on("end", () => {
|
|
129
|
-
try {
|
|
130
|
-
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
131
|
-
const json = JSON.parse(raw);
|
|
132
|
-
if (json.error)
|
|
133
|
-
return reject(new Error(json.error.message));
|
|
134
|
-
const text = json.result?.content?.[0]?.text ?? "{}";
|
|
135
|
-
const data = JSON.parse(text);
|
|
136
|
-
const companyId = data.companyId;
|
|
137
|
-
if (!companyId)
|
|
138
|
-
return reject(new Error("Could not retrieve workspace ID from Nexarch."));
|
|
139
|
-
resolve(companyId);
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
reject(new Error("Unexpected response while verifying credentials."));
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
req.on("timeout", () => {
|
|
147
|
-
req.destroy(new Error("Timed out verifying credentials. Check your connection and try again."));
|
|
148
|
-
});
|
|
149
|
-
req.on("error", reject);
|
|
150
|
-
req.write(body);
|
|
151
|
-
req.end();
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
104
|
export async function login(_args) {
|
|
155
105
|
const state = generateState();
|
|
156
106
|
const port = await findFreePort();
|
|
@@ -159,10 +109,7 @@ export async function login(_args) {
|
|
|
159
109
|
console.log(`\n ${authUrl}\n`);
|
|
160
110
|
console.log("If the browser did not open, copy the URL above and paste it in manually.\n");
|
|
161
111
|
openBrowser(authUrl);
|
|
162
|
-
const { token } = await waitForCallback(port, state);
|
|
163
|
-
process.stdout.write("Verifying credentials… ");
|
|
164
|
-
const companyId = await fetchCompanyId(token);
|
|
165
|
-
console.log("done\n");
|
|
112
|
+
const { token, companyId } = await waitForCallback(port, state);
|
|
166
113
|
const expiresAt = new Date();
|
|
167
114
|
expiresAt.setDate(expiresAt.getDate() + 90);
|
|
168
115
|
saveCredentials({ token, email: "", company: "", companyId, expiresAt: expiresAt.toISOString() });
|
package/dist/commands/setup.js
CHANGED