virtualizorjs 1.0.5 → 2.1.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 -21
- package/README.md +212 -126
- package/dist/index.d.mts +383 -0
- package/dist/index.d.ts +383 -0
- package/dist/index.js +276 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +267 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -48
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -28
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/workflows/npm-publish-github-packages.yml +0 -36
- package/.github/workflows/release-package.yml +0 -33
- package/CODE_OF_CONDUCT.md +0 -128
- package/CONTRIBUTING.md +0 -92
- package/SECURITY.md +0 -26
- package/examples/createvps.js +0 -33
- package/examples/eventhandling.js +0 -36
- package/examples/listvps.js +0 -117
- package/src/Actions.js +0 -79
- package/src/VirtualizorClient.js +0 -491
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 kkMihai
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 kkMihai
|
|
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
CHANGED
|
@@ -1,126 +1,212 @@
|
|
|
1
|
-
# VirtualizorJS
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
1
|
+
# VirtualizorJS
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/virtualizorjs)
|
|
4
|
+
[](https://github.com/kkMihai/virtualizorjs/actions)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
A **TypeScript-first** SDK for the [Virtualizor](https://www.virtualizor.com/) server management API. Manage VPS instances, users, and plans with a clean, namespaced interface and zero production dependencies.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- ✅ **TypeScript-first**: Full type safety and IDE autocomplete
|
|
12
|
+
- ✅ **Namespaced API**: Logical organization (`client.vps.*`, `client.users.*`, `client.plans.*`, `client.tasks.*`)
|
|
13
|
+
- ✅ **SHA-256 Authentication**: Secure API communication
|
|
14
|
+
- ✅ **Zero Production Dependencies**: Lightweight and fast
|
|
15
|
+
- ✅ **Async Task Polling**: Built-in support for long-running operations
|
|
16
|
+
- ✅ **Self-signed SSL Ready**: Pre-configured for Virtualizor's typical certificate setup
|
|
17
|
+
- ✅ **Dual Output**: Outputs both CommonJS and ESM modules
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
**npm:**
|
|
22
|
+
```bash
|
|
23
|
+
npm install virtualizorjs
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**bun:**
|
|
27
|
+
```bash
|
|
28
|
+
bun add virtualizorjs
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### Create a Client
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { createVirtualizorClient } from 'virtualizorjs';
|
|
37
|
+
|
|
38
|
+
const client = createVirtualizorClient({
|
|
39
|
+
host: 'virtualizor.example.com',
|
|
40
|
+
apiKey: 'your-api-key',
|
|
41
|
+
apiPass: 'your-api-pass',
|
|
42
|
+
// Optional: port (default 4085), https (default true),
|
|
43
|
+
// rejectUnauthorized (default false), timeout (default 30000ms)
|
|
44
|
+
// 4085 for Https, 4084 for Http
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### List All VPS
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const vpsList = await client.vps.list();
|
|
52
|
+
|
|
53
|
+
for (const [vpsId, vps] of Object.entries(vpsList)) {
|
|
54
|
+
console.log(`${vpsId}: ${vps.hostname} (${vps.status})`);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Start a VPS and Wait for Completion
|
|
59
|
+
|
|
60
|
+
Many Virtualizor operations are asynchronous. Use `client.tasks.wait()` to poll for completion:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const result = await client.vps.start('123');
|
|
64
|
+
const task = await client.tasks.wait(result.taskid!);
|
|
65
|
+
|
|
66
|
+
console.log(`VPS started! Task status: ${task.status}`);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Error Handling
|
|
70
|
+
|
|
71
|
+
All SDK errors are instances of `VirtualizorApiError`. Catch and inspect them:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { VirtualizorApiError } from 'virtualizorjs';
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await client.vps.start('invalid-id');
|
|
78
|
+
} catch (err) {
|
|
79
|
+
if (err instanceof VirtualizorApiError) {
|
|
80
|
+
console.error(`API Error [${err.code}]: ${err.message}`);
|
|
81
|
+
} else {
|
|
82
|
+
console.error('Unexpected error:', err);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## API Reference
|
|
88
|
+
|
|
89
|
+
### VPS Management
|
|
90
|
+
|
|
91
|
+
| Method | Parameters | Returns | Notes |
|
|
92
|
+
|--------|-----------|---------|-------|
|
|
93
|
+
| `list()` | — | `Record<string, VPS>` | List all VPS |
|
|
94
|
+
| `get(vpsId)` | `vpsId: string` | `VPS` | Get a single VPS |
|
|
95
|
+
| `create(params)` | `CreateVPSParams` | `AsyncTaskResult` | Async |
|
|
96
|
+
| `delete(vpsId)` | `vpsId: string` | `AsyncTaskResult` | Async |
|
|
97
|
+
| `start(vpsId)` | `vpsId: string` | `AsyncTaskResult` | Async |
|
|
98
|
+
| `stop(vpsId)` | `vpsId: string` | `AsyncTaskResult` | Async |
|
|
99
|
+
| `restart(vpsId)` | `vpsId: string` | `AsyncTaskResult` | Async |
|
|
100
|
+
| `poweroff(vpsId)` | `vpsId: string` | `AsyncTaskResult` | Async |
|
|
101
|
+
| `suspend(vpsId)` | `vpsId: string` | `AsyncTaskResult` | Async |
|
|
102
|
+
| `unsuspend(vpsId)` | `vpsId: string` | `AsyncTaskResult` | Async |
|
|
103
|
+
| `rebuild(vpsId, params)` | `vpsId: string, RebuildVPSParams` | `AsyncTaskResult` | Async |
|
|
104
|
+
| `clone(vpsId, params)` | `vpsId: string, CloneVPSParams` | `AsyncTaskResult` | Async |
|
|
105
|
+
| `migrate(vpsId, params)` | `vpsId: string, MigrateVPSParams` | `AsyncTaskResult` | Async |
|
|
106
|
+
| `status(vpsId)` | `vpsId: string` | `unknown` | Current status snapshot |
|
|
107
|
+
| `vnc(vpsId)` | `vpsId: string` | `VNCInfo` | Get VNC connection details |
|
|
108
|
+
| `stats(vpsId)` | `vpsId: string` | `VPSStatsResponse` | Get resource usage statistics |
|
|
109
|
+
|
|
110
|
+
### User Management
|
|
111
|
+
|
|
112
|
+
| Method | Parameters | Returns | Notes |
|
|
113
|
+
|--------|-----------|---------|-------|
|
|
114
|
+
| `list()` | — | `Record<string, User>` | List all users |
|
|
115
|
+
| `create(params)` | `CreateUserParams` | `AsyncTaskResult` | Async |
|
|
116
|
+
| `delete(uid)` | `uid: string` | `AsyncTaskResult` | Async |
|
|
117
|
+
| `suspend(uid)` | `uid: string` | `AsyncTaskResult` | Async |
|
|
118
|
+
| `unsuspend(uid)` | `uid: string` | `AsyncTaskResult` | Async |
|
|
119
|
+
|
|
120
|
+
### Plan Management
|
|
121
|
+
|
|
122
|
+
| Method | Parameters | Returns | Notes |
|
|
123
|
+
|--------|-----------|---------|-------|
|
|
124
|
+
| `list()` | — | `Record<string, Plan>` | List all plans |
|
|
125
|
+
| `create(params)` | `CreatePlanParams` | `AsyncTaskResult` | Async |
|
|
126
|
+
| `delete(planId)` | `planId: string` | `AsyncTaskResult` | Async |
|
|
127
|
+
|
|
128
|
+
### Task Polling
|
|
129
|
+
|
|
130
|
+
| Method | Parameters | Returns | Notes |
|
|
131
|
+
|--------|-----------|---------|-------|
|
|
132
|
+
| `get(taskId)` | `taskId: string` | `Task \| undefined` | Get task status once |
|
|
133
|
+
| `wait(taskId, options?)` | `taskId: string, { pollIntervalMs?, timeoutMs? }?` | `Promise<Task>` | Poll until complete or timeout |
|
|
134
|
+
|
|
135
|
+
## Task Polling Pattern
|
|
136
|
+
|
|
137
|
+
Many API calls return `AsyncTaskResult` with a `taskid` field. Poll for completion:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Example: Create a VPS and wait for it to be ready
|
|
141
|
+
const createResult = await client.vps.create({
|
|
142
|
+
hostname: 'my-vps.example.com',
|
|
143
|
+
// ... other params
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
const completedTask = await client.tasks.wait(createResult.taskid!, {
|
|
147
|
+
pollIntervalMs: 5000, // Check every 5 seconds (default: 2000ms)
|
|
148
|
+
timeoutMs: 300000, // Give up after 5 minutes (default: 120000ms)
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
if (completedTask.status === '1' || completedTask.status === 'done') {
|
|
152
|
+
console.log('VPS creation completed successfully');
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Configuration
|
|
157
|
+
|
|
158
|
+
When creating a client, the following options are available:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
interface VirtualizorConfig {
|
|
162
|
+
host: string; // Virtualizor server hostname or IP
|
|
163
|
+
apiKey: string; // API key from Virtualizor panel
|
|
164
|
+
apiPass: string; // API password from Virtualizor panel
|
|
165
|
+
port?: number; // Server port (default: 4085)
|
|
166
|
+
https?: boolean; // Use HTTPS (default: true)
|
|
167
|
+
rejectUnauthorized?: boolean; // Reject self-signed certs (default: false)
|
|
168
|
+
timeout?: number; // Request timeout in ms (default: 30000)
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Self-Signed SSL Certificates
|
|
173
|
+
|
|
174
|
+
Virtualizor typically uses self-signed SSL certificates. The SDK handles this by default with `rejectUnauthorized: false`. If you need to enforce certificate validation, set `rejectUnauthorized: true` and ensure your Virtualizor instance has a valid certificate.
|
|
175
|
+
|
|
176
|
+
## TypeScript Types
|
|
177
|
+
|
|
178
|
+
All resources are fully typed. Import types as needed:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
import type {
|
|
182
|
+
VPS,
|
|
183
|
+
CreateVPSParams,
|
|
184
|
+
RebuildVPSParams,
|
|
185
|
+
CloneVPSParams,
|
|
186
|
+
MigrateVPSParams,
|
|
187
|
+
User,
|
|
188
|
+
CreateUserParams,
|
|
189
|
+
Plan,
|
|
190
|
+
CreatePlanParams,
|
|
191
|
+
Task,
|
|
192
|
+
AsyncTaskResult,
|
|
193
|
+
} from 'virtualizorjs';
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Contributing
|
|
197
|
+
|
|
198
|
+
We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines on how to help.
|
|
199
|
+
|
|
200
|
+
## Security
|
|
201
|
+
|
|
202
|
+
Please report security vulnerabilities to the maintainers privately. See [SECURITY.md](./SECURITY.md) for more details.
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
**Author**: [kkMihai](https://github.com/kkMihai)
|
|
211
|
+
**Package**: [npm/virtualizorjs](https://www.npmjs.com/package/virtualizorjs)
|
|
212
|
+
**Repository**: [github.com/kkMihai/virtualizorjs](https://github.com/kkMihai/virtualizorjs)
|