@ho3einwave/pterodactyl-ts 0.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/README.md ADDED
@@ -0,0 +1,165 @@
1
+ # pterodactyl-ts
2
+
3
+ [![CI](https://github.com/Ho3einWave/pterodactyl-ts/actions/workflows/ci.yml/badge.svg)](https://github.com/Ho3einWave/pterodactyl-ts/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/@ho3einwave/pterodactyl-ts)](https://www.npmjs.com/package/@ho3einwave/pterodactyl-ts)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ Type-safe TypeScript library for the [Pterodactyl Panel](https://pterodactyl.io/) API. Zero dependencies.
8
+
9
+ - **Client API** (`PteroClient`) - Account, servers, files, databases, backups, schedules, network, subusers
10
+ - **Application API** (`PteroApplication`) - Users, servers, nodes, locations, nests/eggs (admin)
11
+ - **WebSocket API** (`WebSocketManager`) - Real-time console, stats, status with auto-reconnect
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @ho3einwave/pterodactyl-ts
17
+ ```
18
+
19
+ ## Client API
20
+
21
+ ```ts
22
+ import { PteroClient } from '@ho3einwave/pterodactyl-ts';
23
+
24
+ const client = new PteroClient({
25
+ baseUrl: 'https://panel.example.com',
26
+ apiKey: 'ptlc_...',
27
+ });
28
+
29
+ // Account
30
+ const account = await client.account.getDetails();
31
+
32
+ // List servers
33
+ const { data: servers } = await client.servers.list();
34
+
35
+ // Server-scoped operations
36
+ const srv = client.server('abc123');
37
+
38
+ await srv.sendCommand('say Hello!');
39
+ await srv.setPowerState('restart');
40
+
41
+ const resources = await srv.getResources();
42
+ console.log(`Memory: ${resources.resources.memory_bytes}`);
43
+
44
+ // Files
45
+ const files = await srv.files.list('/');
46
+ const content = await srv.files.getContent('/server.properties');
47
+ await srv.files.writeFile('/motd.txt', 'Welcome!');
48
+
49
+ // Backups
50
+ const { data: backups } = await srv.backups.list();
51
+ const backup = await srv.backups.create({ name: 'before-update' });
52
+
53
+ // Databases
54
+ const dbs = await srv.databases.list();
55
+ const newDb = await srv.databases.create({ database: 'mydb', remote: '%' });
56
+
57
+ // Schedules
58
+ const schedules = await srv.schedules.list();
59
+ ```
60
+
61
+ ## Application API
62
+
63
+ ```ts
64
+ import { PteroApplication } from '@ho3einwave/pterodactyl-ts';
65
+
66
+ const app = new PteroApplication({
67
+ baseUrl: 'https://panel.example.com',
68
+ apiKey: 'ptla_...',
69
+ });
70
+
71
+ // Users
72
+ const { data: users } = await app.users.list();
73
+ const user = await app.users.create({
74
+ email: 'user@example.com',
75
+ username: 'newuser',
76
+ first_name: 'New',
77
+ last_name: 'User',
78
+ });
79
+
80
+ // Servers
81
+ const { data: servers } = await app.servers.list();
82
+ await app.servers.suspend(1);
83
+ await app.servers.unsuspend(1);
84
+
85
+ // Nodes
86
+ const { data: nodes } = await app.nodes.list();
87
+
88
+ // Locations
89
+ const { data: locations } = await app.locations.list();
90
+
91
+ // Nests & Eggs
92
+ const { data: nests } = await app.nests.list();
93
+ const { data: eggs } = await app.nests.listEggs(1);
94
+ ```
95
+
96
+ ## WebSocket
97
+
98
+ ```ts
99
+ import { PteroClient, WebSocketManager } from '@ho3einwave/pterodactyl-ts';
100
+
101
+ const client = new PteroClient({
102
+ baseUrl: 'https://panel.example.com',
103
+ apiKey: 'ptlc_...',
104
+ });
105
+
106
+ const srv = client.server('abc123');
107
+ const creds = await srv.getWebSocketCredentials();
108
+
109
+ const ws = new WebSocketManager({
110
+ origin: creds.socket,
111
+ serverUuid: 'full-server-uuid',
112
+ getToken: async () => {
113
+ const c = await srv.getWebSocketCredentials();
114
+ return c.token;
115
+ },
116
+ });
117
+
118
+ ws.on('console output', (line) => console.log(line));
119
+ ws.on('status', (status) => console.log('Status:', status));
120
+ ws.on('stats', (stats) => console.log('CPU:', stats.cpu_absolute));
121
+
122
+ await ws.connect();
123
+
124
+ ws.sendCommand('say Hello from API!');
125
+ ws.sendPowerAction('restart');
126
+
127
+ // Later
128
+ ws.disconnect();
129
+ ```
130
+
131
+ ## Error Handling
132
+
133
+ ```ts
134
+ import { PteroError, PteroValidationError, PteroRateLimitError } from '@ho3einwave/pterodactyl-ts';
135
+
136
+ try {
137
+ await app.users.create({ /* ... */ });
138
+ } catch (err) {
139
+ if (err instanceof PteroValidationError) {
140
+ console.log(err.fieldErrors); // { email: ['Must be valid email.'] }
141
+ } else if (err instanceof PteroRateLimitError) {
142
+ console.log(`Retry after ${err.retryAfter}s`);
143
+ } else if (err instanceof PteroError) {
144
+ console.log(err.status, err.code, err.message);
145
+ }
146
+ }
147
+ ```
148
+
149
+ ## Pagination & Filtering
150
+
151
+ ```ts
152
+ const { data, pagination } = await app.servers.list({
153
+ page: 2,
154
+ perPage: 25,
155
+ sort: '-id',
156
+ filters: { name: 'minecraft' },
157
+ include: ['allocations', 'user'],
158
+ });
159
+
160
+ console.log(`Page ${pagination.currentPage} of ${pagination.totalPages}`);
161
+ ```
162
+
163
+ ## License
164
+
165
+ MIT