oasis_test 0.1.4 → 0.1.5
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/index.js +43 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -27451,6 +27451,13 @@ function nodesDomain(deps) {
|
|
|
27451
27451
|
const npxCmd = buildNpxCmd({ gatewayUrl: deps.gatewayUrl, nodeId, token, nodeName });
|
|
27452
27452
|
return { status: 200, body: { nodeId, nodeName, token, script, gatewayUrl: deps.gatewayUrl, npxCmd } };
|
|
27453
27453
|
});
|
|
27454
|
+
router.patch("/api/nodes/:nodeId", async (req) => {
|
|
27455
|
+
const nodeId = req.params["nodeId"];
|
|
27456
|
+
if (!nodeId) return { status: 400, body: { error: "missing nodeId" } };
|
|
27457
|
+
const body = req.body ?? {};
|
|
27458
|
+
if (body.name) nodeNames.set(nodeId, body.name);
|
|
27459
|
+
return { status: 200, body: { ok: true } };
|
|
27460
|
+
});
|
|
27454
27461
|
router.delete("/api/nodes/:nodeId", async (req) => {
|
|
27455
27462
|
const nodeId = req.params["nodeId"];
|
|
27456
27463
|
if (!nodeId) return { status: 400, body: { error: "missing nodeId" } };
|
|
@@ -40765,6 +40772,7 @@ var isRunning = (pid) => {
|
|
|
40765
40772
|
return false;
|
|
40766
40773
|
}
|
|
40767
40774
|
};
|
|
40775
|
+
var httpBase = (wsUrl) => wsUrl.replace(/^wss?:\/\//, "http://").replace(/\/node-gateway.*$/, "");
|
|
40768
40776
|
function installBinary() {
|
|
40769
40777
|
fs14.mkdirSync(path13.dirname(BIN_FILE), { recursive: true });
|
|
40770
40778
|
fs14.copyFileSync(process.argv[1], BIN_FILE);
|
|
@@ -40829,22 +40837,24 @@ function spawnDaemon() {
|
|
|
40829
40837
|
}
|
|
40830
40838
|
function stopDaemon() {
|
|
40831
40839
|
const pid = readPid();
|
|
40832
|
-
if (
|
|
40840
|
+
if (pid && isRunning(pid)) {
|
|
40833
40841
|
try {
|
|
40834
|
-
|
|
40842
|
+
process.kill(pid, "SIGTERM");
|
|
40835
40843
|
} catch {
|
|
40836
40844
|
}
|
|
40837
|
-
return false;
|
|
40838
40845
|
}
|
|
40839
40846
|
try {
|
|
40840
|
-
|
|
40847
|
+
fs14.unlinkSync(PID_FILE);
|
|
40841
40848
|
} catch {
|
|
40842
40849
|
}
|
|
40843
40850
|
try {
|
|
40844
|
-
|
|
40851
|
+
(0, import_node_child_process10.execSync)('pkill -f "oasis.js --_daemon"', { stdio: "ignore" });
|
|
40852
|
+
} catch {
|
|
40853
|
+
}
|
|
40854
|
+
try {
|
|
40855
|
+
(0, import_node_child_process10.execSync)("systemctl --user stop oasis-node 2>/dev/null", { stdio: "ignore" });
|
|
40845
40856
|
} catch {
|
|
40846
40857
|
}
|
|
40847
|
-
return true;
|
|
40848
40858
|
}
|
|
40849
40859
|
void (async () => {
|
|
40850
40860
|
const [, , cmd] = process.argv;
|
|
@@ -40871,6 +40881,15 @@ void (async () => {
|
|
|
40871
40881
|
cleanup();
|
|
40872
40882
|
process.exit(0);
|
|
40873
40883
|
});
|
|
40884
|
+
if (cfg.nodeId && cfg.name) {
|
|
40885
|
+
const base = httpBase(cfg.serverUrl);
|
|
40886
|
+
fetch(`${base}/api/nodes/${cfg.nodeId}`, {
|
|
40887
|
+
method: "PATCH",
|
|
40888
|
+
headers: { authorization: `Bearer ${cfg.token}`, "content-type": "application/json" },
|
|
40889
|
+
body: JSON.stringify({ name: cfg.name })
|
|
40890
|
+
}).catch(() => {
|
|
40891
|
+
});
|
|
40892
|
+
}
|
|
40874
40893
|
await startNode({
|
|
40875
40894
|
serverUrl: cfg.serverUrl,
|
|
40876
40895
|
token: cfg.token,
|
|
@@ -40880,26 +40899,30 @@ void (async () => {
|
|
|
40880
40899
|
return;
|
|
40881
40900
|
}
|
|
40882
40901
|
if (cmd === "start") {
|
|
40883
|
-
const
|
|
40884
|
-
const
|
|
40902
|
+
const prev = readConfig();
|
|
40903
|
+
const serverUrl = flags.get("server-ws") ?? process.env["OASIS_SERVER_WS"] ?? prev?.serverUrl;
|
|
40904
|
+
const token = flags.get("token") ?? process.env["OASIS_NODE_TOKEN"] ?? prev?.token;
|
|
40885
40905
|
if (!serverUrl || !token) {
|
|
40886
|
-
console.error("Usage: oasis start --server-ws <wss://...> --token <token> [--name <name>]");
|
|
40906
|
+
console.error("Usage: oasis start --server-ws <wss://...> --token <token> [--name <name>] [--id <nodeId>]");
|
|
40887
40907
|
process.exit(1);
|
|
40888
40908
|
}
|
|
40889
|
-
const nodeId = flags.get("id") ??
|
|
40890
|
-
|
|
40909
|
+
const nodeId = prev?.nodeId ?? flags.get("id") ?? `node-${(0, import_node_crypto21.randomUUID)()}`;
|
|
40910
|
+
const name = flags.get("name") ?? prev?.name;
|
|
40911
|
+
const nameChanged = prev?.name !== void 0 && name !== prev.name;
|
|
40912
|
+
saveConfig({ serverUrl, token, nodeId, ...name ? { name } : {} });
|
|
40891
40913
|
installBinary();
|
|
40892
40914
|
stopDaemon();
|
|
40893
40915
|
setupAutostart();
|
|
40894
40916
|
const pid = spawnDaemon();
|
|
40895
|
-
console.log(`\u2713 daemon started (PID ${pid})
|
|
40896
|
-
logs: tail -f ${LOG_FILE}`);
|
|
40917
|
+
console.log(`\u2713 daemon started (PID ${pid})${nameChanged ? ` [name updated: ${prev.name} \u2192 ${name}]` : ""}`);
|
|
40918
|
+
console.log(` logs: tail -f ${LOG_FILE}`);
|
|
40897
40919
|
if (!process.env["PATH"]?.includes(path13.dirname(LOCAL_BIN)))
|
|
40898
40920
|
console.log(` add to PATH: echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc && source ~/.bashrc`);
|
|
40899
40921
|
return;
|
|
40900
40922
|
}
|
|
40901
40923
|
if (cmd === "stop") {
|
|
40902
|
-
|
|
40924
|
+
stopDaemon();
|
|
40925
|
+
console.log("\u2713 stopped");
|
|
40903
40926
|
return;
|
|
40904
40927
|
}
|
|
40905
40928
|
if (cmd === "restart") {
|
|
@@ -40914,7 +40937,12 @@ void (async () => {
|
|
|
40914
40937
|
}
|
|
40915
40938
|
if (cmd === "status") {
|
|
40916
40939
|
const pid = readPid();
|
|
40917
|
-
|
|
40940
|
+
const cfg = readConfig();
|
|
40941
|
+
if (pid && isRunning(pid)) {
|
|
40942
|
+
console.log(`running PID=${pid} nodeId=${cfg?.nodeId ?? "?"} name=${cfg?.name ?? "(none)"}`);
|
|
40943
|
+
} else {
|
|
40944
|
+
console.log("not running");
|
|
40945
|
+
}
|
|
40918
40946
|
return;
|
|
40919
40947
|
}
|
|
40920
40948
|
await runCli(process.argv.slice(2));
|