@scriptdb/server 1.0.3 → 1.0.4
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 +72 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -4358,7 +4358,7 @@ import { spawn } from "node:child_process";
|
|
|
4358
4358
|
import Storage from "@scriptdb/storage";
|
|
4359
4359
|
var pkgData = `{
|
|
4360
4360
|
"name": "scriptdb-workspace",
|
|
4361
|
-
"version": "1.0.
|
|
4361
|
+
"version": "1.0.4",
|
|
4362
4362
|
"description": "ScriptDB workspace for custom scripts, services, and databases",
|
|
4363
4363
|
"private": true,
|
|
4364
4364
|
"devDependencies": {
|
|
@@ -4720,6 +4720,9 @@ class ScriptDBClient {
|
|
|
4720
4720
|
});
|
|
4721
4721
|
}
|
|
4722
4722
|
}
|
|
4723
|
+
get connected() {
|
|
4724
|
+
return this._connected;
|
|
4725
|
+
}
|
|
4723
4726
|
connect() {
|
|
4724
4727
|
if (this._connecting)
|
|
4725
4728
|
return this._connecting;
|
|
@@ -5242,10 +5245,52 @@ class ScriptDBClient {
|
|
|
5242
5245
|
} catch (e) {}
|
|
5243
5246
|
this.client = null;
|
|
5244
5247
|
}
|
|
5248
|
+
disconnect() {
|
|
5249
|
+
this.close();
|
|
5250
|
+
}
|
|
5251
|
+
async sendRequest(action, data = {}) {
|
|
5252
|
+
return this.execute({ action, data });
|
|
5253
|
+
}
|
|
5254
|
+
async login(username, password) {
|
|
5255
|
+
return this.sendRequest("login", { username, password });
|
|
5256
|
+
}
|
|
5257
|
+
async logout() {
|
|
5258
|
+
return this.sendRequest("logout", {});
|
|
5259
|
+
}
|
|
5260
|
+
async listDatabases() {
|
|
5261
|
+
return this.sendRequest("list-dbs", {});
|
|
5262
|
+
}
|
|
5263
|
+
async createDatabase(name) {
|
|
5264
|
+
return this.sendRequest("create-db", { databaseName: name });
|
|
5265
|
+
}
|
|
5266
|
+
async removeDatabase(name) {
|
|
5267
|
+
return this.sendRequest("remove-db", { databaseName: name });
|
|
5268
|
+
}
|
|
5269
|
+
async renameDatabase(oldName, newName) {
|
|
5270
|
+
return this.sendRequest("rename-db", { databaseName: oldName, newName });
|
|
5271
|
+
}
|
|
5272
|
+
async run(code, databaseName) {
|
|
5273
|
+
return this.sendRequest("script-code", { code, databaseName });
|
|
5274
|
+
}
|
|
5275
|
+
async saveDatabase(databaseName) {
|
|
5276
|
+
return this.sendRequest("save-db", { databaseName });
|
|
5277
|
+
}
|
|
5278
|
+
async updateDatabase(databaseName, data) {
|
|
5279
|
+
return this.sendRequest("update-db", { databaseName, ...data });
|
|
5280
|
+
}
|
|
5281
|
+
async getInfo() {
|
|
5282
|
+
return this.sendRequest("get-info", {});
|
|
5283
|
+
}
|
|
5284
|
+
async executeShell(command) {
|
|
5285
|
+
return this.sendRequest("shell-command", { command });
|
|
5286
|
+
}
|
|
5245
5287
|
}
|
|
5246
5288
|
var src_default = ScriptDBClient;
|
|
5247
5289
|
|
|
5248
5290
|
// src/wsProxy.ts
|
|
5291
|
+
import { exec } from "child_process";
|
|
5292
|
+
import { promisify } from "util";
|
|
5293
|
+
var execPromise = promisify(exec);
|
|
5249
5294
|
var noopLogger2 = {
|
|
5250
5295
|
debug: () => {},
|
|
5251
5296
|
info: () => {},
|
|
@@ -5434,6 +5479,9 @@ class WebSocketProxy {
|
|
|
5434
5479
|
case "get-info":
|
|
5435
5480
|
result = await client.execute({ action: "get-info" });
|
|
5436
5481
|
break;
|
|
5482
|
+
case "shell-command":
|
|
5483
|
+
result = await this.executeShellCommand(payload.command);
|
|
5484
|
+
break;
|
|
5437
5485
|
default:
|
|
5438
5486
|
throw new Error(`Unknown action: ${action}`);
|
|
5439
5487
|
}
|
|
@@ -5473,6 +5521,29 @@ class WebSocketProxy {
|
|
|
5473
5521
|
sendError(ws, id, error) {
|
|
5474
5522
|
this.sendResponse(ws, id, "error", "ERROR", error);
|
|
5475
5523
|
}
|
|
5524
|
+
async executeShellCommand(command) {
|
|
5525
|
+
try {
|
|
5526
|
+
this.logger.info?.(`Executing shell command: ${command}`);
|
|
5527
|
+
if (command.length > 1000) {
|
|
5528
|
+
throw new Error("Command too long");
|
|
5529
|
+
}
|
|
5530
|
+
const { stdout, stderr } = await execPromise(command, {
|
|
5531
|
+
timeout: 30000,
|
|
5532
|
+
maxBuffer: 1024 * 1024,
|
|
5533
|
+
cwd: process.cwd()
|
|
5534
|
+
});
|
|
5535
|
+
return {
|
|
5536
|
+
stdout: stdout || "",
|
|
5537
|
+
stderr: stderr || ""
|
|
5538
|
+
};
|
|
5539
|
+
} catch (error) {
|
|
5540
|
+
this.logger.error?.("Shell command failed:", error);
|
|
5541
|
+
return {
|
|
5542
|
+
stdout: "",
|
|
5543
|
+
stderr: error.message || String(error)
|
|
5544
|
+
};
|
|
5545
|
+
}
|
|
5546
|
+
}
|
|
5476
5547
|
handleClose(session) {
|
|
5477
5548
|
this.logger.info?.("WebSocket connection closed");
|
|
5478
5549
|
if (session.client) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scriptdb/server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "server module resolver for script database",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"typescript": "^5.0.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@scriptdb/client": "^1.0.
|
|
45
|
-
"@scriptdb/storage": "^1.0.
|
|
46
|
-
"@scriptdb/system-modules": "^1.0.
|
|
47
|
-
"@scriptdb/vm": "^1.0.
|
|
44
|
+
"@scriptdb/client": "^1.0.4",
|
|
45
|
+
"@scriptdb/storage": "^1.0.4",
|
|
46
|
+
"@scriptdb/system-modules": "^1.0.4",
|
|
47
|
+
"@scriptdb/vm": "^1.0.4",
|
|
48
48
|
"@types/ws": "^8.18.1",
|
|
49
49
|
"bcryptjs": "^3.0.3",
|
|
50
50
|
"bottleneck": "^2.19.5",
|