neurondb 1.0.0
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/LICENSE +21 -0
- package/README.md +62 -0
- package/bin/cli.js +13 -0
- package/package.json +40 -0
- package/src/api.js +144 -0
- package/src/app.js +467 -0
- package/src/config.js +38 -0
- package/src/executor.js +64 -0
- package/src/sandbox.js +80 -0
- package/src/ui.js +655 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pisani da Arq
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# N-Bash — Remote Bash for NeuronDB
|
|
2
|
+
|
|
3
|
+
Interactive SNL terminal and remote bash executor for NeuronDB.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g neuron-bash
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
nbash
|
|
15
|
+
# or
|
|
16
|
+
neuron-bash
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
You'll be prompted for:
|
|
20
|
+
- **Node URL** — NeuronDB server (e.g., `https://api.neuron-db.com`)
|
|
21
|
+
- **Instance** — NeuronDB instance (default: `system`)
|
|
22
|
+
- **Username** / **Password** — Your NeuronDB credentials
|
|
23
|
+
- **Session name** — Name for this bash session (default: hostname)
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
### Interactive SNL Terminal
|
|
28
|
+
Type any SNL command and it executes on the server:
|
|
29
|
+
```
|
|
30
|
+
nbash> GET() ON(main.users.*) GO()
|
|
31
|
+
nbash> SET() VALUE({"hello":"world"}) ON(main.test.key1) GO()
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Remote Bash Execution
|
|
35
|
+
From NeuronDB Studio or another terminal, run commands on the machine where nbash is connected:
|
|
36
|
+
```
|
|
37
|
+
BASH("ls -la") GO(result)
|
|
38
|
+
BASH("echo hello", "my-laptop") GO(result)
|
|
39
|
+
CATALOG(Bash) GO()
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Results are written to `__nbash_results.{request_id}` and can be retrieved with:
|
|
43
|
+
```
|
|
44
|
+
GET() ON(system.main.__nbash_results.{request_id}) GO(data)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Sandbox Security
|
|
48
|
+
All commands execute in `~/neuron-home/{instance}/` with:
|
|
49
|
+
- Restricted PATH
|
|
50
|
+
- 30s timeout
|
|
51
|
+
- 1MB output buffer
|
|
52
|
+
- Blocked dangerous commands (sudo, rm /, etc.)
|
|
53
|
+
- Path traversal prevention
|
|
54
|
+
|
|
55
|
+
## Requirements
|
|
56
|
+
|
|
57
|
+
- Node.js >= 18.0.0
|
|
58
|
+
- A running NeuronDB server
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
package/bin/cli.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "neurondb",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "N-Bash — Interactive SNL terminal and remote bash executor for NeuronDB",
|
|
5
|
+
"bin": {
|
|
6
|
+
"neuron": "./bin/cli.js",
|
|
7
|
+
"neuron-bash": "./bin/cli.js",
|
|
8
|
+
"nbash": "./bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=18.0.0"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"neurondb",
|
|
16
|
+
"database",
|
|
17
|
+
"snl",
|
|
18
|
+
"bash",
|
|
19
|
+
"remote-execution",
|
|
20
|
+
"cli",
|
|
21
|
+
"terminal"
|
|
22
|
+
],
|
|
23
|
+
"author": "Pisani da Arq",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/nickmpisani/N-Bash.git"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://neuron-db.com",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"blessed": "^0.1.81",
|
|
32
|
+
"chalk": "^5.3.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"bin/",
|
|
36
|
+
"src/",
|
|
37
|
+
"LICENSE",
|
|
38
|
+
"README.md"
|
|
39
|
+
]
|
|
40
|
+
}
|
package/src/api.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* N-Bash API Client — HTTP communication with NeuronDB
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import https from 'node:https';
|
|
6
|
+
import http from 'node:http';
|
|
7
|
+
|
|
8
|
+
/** Reusable agent that ignores self-signed certs */
|
|
9
|
+
const insecureAgent = new https.Agent({ rejectUnauthorized: false });
|
|
10
|
+
|
|
11
|
+
export class NdbApi {
|
|
12
|
+
constructor(baseUrl) {
|
|
13
|
+
// Normalize: remove trailing slash
|
|
14
|
+
this.baseUrl = baseUrl.replace(/\/+$/, '');
|
|
15
|
+
this.token = null;
|
|
16
|
+
this.isHttps = this.baseUrl.startsWith('https');
|
|
17
|
+
// Store credentials for auto-reconnect
|
|
18
|
+
this._creds = null;
|
|
19
|
+
this._reconnecting = false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Login and get auth token
|
|
24
|
+
* @param {string} username
|
|
25
|
+
* @param {string} password
|
|
26
|
+
* @param {string} instance
|
|
27
|
+
* @returns {Promise<{token: string, success: boolean, message: string}>}
|
|
28
|
+
*/
|
|
29
|
+
async login(username, password, instance) {
|
|
30
|
+
const body = JSON.stringify({ username, password, instance });
|
|
31
|
+
const result = await this._request('POST', '/login', body);
|
|
32
|
+
|
|
33
|
+
// Token can be at result.token or result.data.token
|
|
34
|
+
const token = result.token || result.data?.token;
|
|
35
|
+
if (token) {
|
|
36
|
+
this.token = token;
|
|
37
|
+
this._creds = { username, password, instance };
|
|
38
|
+
return { success: true, token, message: 'Logged in' };
|
|
39
|
+
}
|
|
40
|
+
return { success: false, token: null, message: result.message || result.error || 'Login failed' };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Auto-reconnect on 401 — re-login with stored credentials
|
|
45
|
+
*/
|
|
46
|
+
async _reconnect() {
|
|
47
|
+
if (this._reconnecting || !this._creds) return false;
|
|
48
|
+
this._reconnecting = true;
|
|
49
|
+
try {
|
|
50
|
+
const { username, password, instance } = this._creds;
|
|
51
|
+
const result = await this.login(username, password, instance);
|
|
52
|
+
return result.success;
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
} finally {
|
|
56
|
+
this._reconnecting = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Execute SNL command
|
|
62
|
+
* @param {string} snl - SNL command string
|
|
63
|
+
* @returns {Promise<object>} - Server response
|
|
64
|
+
*/
|
|
65
|
+
async execute(snl) {
|
|
66
|
+
const body = JSON.stringify({ command: snl });
|
|
67
|
+
const result = await this._request('POST', '/execute', body);
|
|
68
|
+
|
|
69
|
+
// Auto-reconnect on auth failure
|
|
70
|
+
if (result.error === 'No token' || result.error === 'Invalid token') {
|
|
71
|
+
const ok = await this._reconnect();
|
|
72
|
+
if (ok) return this._request('POST', '/execute', body);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Execute SNL and return parsed result
|
|
79
|
+
* @param {string} snl
|
|
80
|
+
* @returns {Promise<{success: boolean, message: string, data: any}>}
|
|
81
|
+
*/
|
|
82
|
+
async snl(snl) {
|
|
83
|
+
const resp = await this.execute(snl);
|
|
84
|
+
return {
|
|
85
|
+
success: resp.success !== false && resp.success !== 0,
|
|
86
|
+
message: resp.info?.message || resp.message || '',
|
|
87
|
+
data: resp.result ?? resp.data ?? null,
|
|
88
|
+
raw: resp,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Low-level HTTP request
|
|
94
|
+
*/
|
|
95
|
+
_request(method, path, body) {
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
const url = new URL(path, this.baseUrl);
|
|
98
|
+
const mod = this.isHttps ? https : http;
|
|
99
|
+
|
|
100
|
+
const options = {
|
|
101
|
+
method,
|
|
102
|
+
hostname: url.hostname,
|
|
103
|
+
port: url.port,
|
|
104
|
+
path: url.pathname,
|
|
105
|
+
headers: {
|
|
106
|
+
'Content-Type': 'application/json',
|
|
107
|
+
'Content-Length': Buffer.byteLength(body || ''),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
if (this.isHttps) {
|
|
112
|
+
options.agent = insecureAgent;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (this.token) {
|
|
116
|
+
options.headers['Authorization'] = `Bearer ${this.token}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const req = mod.request(options, (res) => {
|
|
120
|
+
let data = '';
|
|
121
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
122
|
+
res.on('end', () => {
|
|
123
|
+
try {
|
|
124
|
+
resolve(JSON.parse(data));
|
|
125
|
+
} catch {
|
|
126
|
+
resolve({ success: false, message: 'Invalid JSON response', raw: data });
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
req.on('error', (err) => {
|
|
132
|
+
resolve({ success: false, message: `Connection error: ${err.message}` });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
req.setTimeout(60000, () => {
|
|
136
|
+
req.destroy();
|
|
137
|
+
resolve({ success: false, message: 'Request timeout' });
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (body) req.write(body);
|
|
141
|
+
req.end();
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|