@pelican.ts/sdk 0.2.1 → 0.2.3
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/.github/logo.png +0 -0
- package/.idea/Pterodactyl.ts.iml +12 -0
- package/.idea/discord.xml +14 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +1 -1
- package/dist/index.d.mts +661 -0
- package/dist/index.d.ts +661 -0
- package/dist/index.js +1055 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1017 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +3 -3
- package/bun.lock +0 -159
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1017 @@
|
|
|
1
|
+
// src/api/client/account.ts
|
|
2
|
+
import z from "zod";
|
|
3
|
+
var Account = class {
|
|
4
|
+
r;
|
|
5
|
+
constructor(requester) {
|
|
6
|
+
this.r = requester;
|
|
7
|
+
}
|
|
8
|
+
info = async () => {
|
|
9
|
+
const { data } = await this.r.get("/account");
|
|
10
|
+
return data.attributes;
|
|
11
|
+
};
|
|
12
|
+
updateEmail = async (newEmail, password) => {
|
|
13
|
+
newEmail = z.email().parse(newEmail);
|
|
14
|
+
await this.r.put("/account/email", { email: newEmail, password });
|
|
15
|
+
};
|
|
16
|
+
updatePassword = async (newPassword) => {
|
|
17
|
+
newPassword = z.string().min(8).parse(newPassword);
|
|
18
|
+
await this.r.put("/account/password", {
|
|
19
|
+
password: newPassword,
|
|
20
|
+
password_confirmation: newPassword
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
apiKeys = {
|
|
24
|
+
list: async () => {
|
|
25
|
+
const { data } = await this.r.get("/account/api-keys");
|
|
26
|
+
return data.data.map((k) => k.attributes);
|
|
27
|
+
},
|
|
28
|
+
create: async (description, allowed_ips) => {
|
|
29
|
+
allowed_ips = z.array(z.ipv4()).optional().parse(allowed_ips);
|
|
30
|
+
const { data } = await this.r.post("/account/api-keys", { description, allowed_ips });
|
|
31
|
+
return { ...data.attributes, secret_token: data.meta.secret_token };
|
|
32
|
+
},
|
|
33
|
+
delete: async (identifier) => {
|
|
34
|
+
await this.r.delete(`/account/api-keys/${identifier}`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
sshKeys = {
|
|
38
|
+
list: async () => {
|
|
39
|
+
const { data } = await this.r.get("/account/ssh-keys");
|
|
40
|
+
return data.data.map((k) => k.attributes);
|
|
41
|
+
},
|
|
42
|
+
create: async (name, public_key) => {
|
|
43
|
+
const { data } = await this.r.post("/account/ssh-keys", { name, public_key });
|
|
44
|
+
return data.attributes;
|
|
45
|
+
},
|
|
46
|
+
delete: async (fingerprint) => {
|
|
47
|
+
await this.r.post(`/account/ssh-keys/remove`, { fingerprint });
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
twoFactor = {
|
|
51
|
+
info: async () => {
|
|
52
|
+
const { data } = await this.r.get("/account/two-factor");
|
|
53
|
+
return data;
|
|
54
|
+
},
|
|
55
|
+
enable: async (code) => {
|
|
56
|
+
const { data } = await this.r.post("/account/two-factor", { code });
|
|
57
|
+
return data;
|
|
58
|
+
},
|
|
59
|
+
disable: async (password) => {
|
|
60
|
+
await this.r.delete("/account/two-factor", { data: { password } });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/api/client/client.ts
|
|
66
|
+
import z5 from "zod";
|
|
67
|
+
|
|
68
|
+
// src/api/client/server_databases.ts
|
|
69
|
+
import z2 from "zod";
|
|
70
|
+
var ServerDatabases = class {
|
|
71
|
+
r;
|
|
72
|
+
id;
|
|
73
|
+
constructor(requester, id) {
|
|
74
|
+
this.r = requester;
|
|
75
|
+
this.id = id;
|
|
76
|
+
}
|
|
77
|
+
list = async (include, page = 1) => {
|
|
78
|
+
z2.number().positive().parse(page);
|
|
79
|
+
const { data } = await this.r.get(`/servers/${this.id}/databases`, {
|
|
80
|
+
params: { include: include?.join(","), page }
|
|
81
|
+
});
|
|
82
|
+
return data.data.map((d) => d.attributes);
|
|
83
|
+
};
|
|
84
|
+
create = async (database, remote) => {
|
|
85
|
+
const { data } = await this.r.post(`/servers/${this.id}/databases`, { database, remote });
|
|
86
|
+
return data.attributes;
|
|
87
|
+
};
|
|
88
|
+
rotatePassword = async (database_id) => {
|
|
89
|
+
const { data } = await this.r.post(`/servers/${this.id}/databases/${database_id}/rotate-password`);
|
|
90
|
+
return data.attributes;
|
|
91
|
+
};
|
|
92
|
+
delete = async (database_id) => {
|
|
93
|
+
await this.r.delete(`/servers/${this.id}/databases/${database_id}`);
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/api/client/server_files.ts
|
|
98
|
+
import axios from "axios";
|
|
99
|
+
var ServerFiles = class {
|
|
100
|
+
r;
|
|
101
|
+
id;
|
|
102
|
+
constructor(requester, id) {
|
|
103
|
+
this.r = requester;
|
|
104
|
+
this.id = id;
|
|
105
|
+
}
|
|
106
|
+
list = async (path) => {
|
|
107
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/list`, {
|
|
108
|
+
params: { directory: path }
|
|
109
|
+
});
|
|
110
|
+
return data.data.map((r) => r.attributes);
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Return the contents of a file. To read binary file (non-editable) use {@link download} instead
|
|
114
|
+
*/
|
|
115
|
+
contents = async (path) => {
|
|
116
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/contents`, {
|
|
117
|
+
params: { file: path }
|
|
118
|
+
});
|
|
119
|
+
return data;
|
|
120
|
+
};
|
|
121
|
+
downloadGetUrl = async (path) => {
|
|
122
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/download`, {
|
|
123
|
+
params: { file: path }
|
|
124
|
+
});
|
|
125
|
+
return data.attributes.url;
|
|
126
|
+
};
|
|
127
|
+
download = async (path) => {
|
|
128
|
+
const url = await this.downloadGetUrl(path);
|
|
129
|
+
const { data } = await axios.get(url, { responseType: "arraybuffer" });
|
|
130
|
+
return data;
|
|
131
|
+
};
|
|
132
|
+
rename = async (root = "/", files) => {
|
|
133
|
+
await this.r.put(`/servers/${this.id}/files/rename`, { root, files });
|
|
134
|
+
};
|
|
135
|
+
copy = async (location) => {
|
|
136
|
+
await this.r.post(`/servers/${this.id}/files/copy`, { location });
|
|
137
|
+
};
|
|
138
|
+
write = async (path, content) => {
|
|
139
|
+
await this.r.post(`/servers/${this.id}/files/write`, content, {
|
|
140
|
+
params: { file: path }
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
compress = async (root = "/", files, archive_name, extension) => {
|
|
144
|
+
await this.r.post(`/servers/${this.id}/files/compress`, { root, files, archive_name, extension });
|
|
145
|
+
};
|
|
146
|
+
decompress = async (root = "/", file) => {
|
|
147
|
+
await this.r.post(`/servers/${this.id}/files/decompress`, { root, file });
|
|
148
|
+
};
|
|
149
|
+
delete = async (root = "/", files) => {
|
|
150
|
+
await this.r.post(`/servers/${this.id}/files/delete`, { root, files });
|
|
151
|
+
};
|
|
152
|
+
createFolder = async (root = "/", name) => {
|
|
153
|
+
await this.r.post(`/servers/${this.id}/files/create-folder`, { root, name });
|
|
154
|
+
};
|
|
155
|
+
chmod = async (root = "/", files) => {
|
|
156
|
+
await this.r.post(`/servers/${this.id}/files/chmod`, { root, files });
|
|
157
|
+
};
|
|
158
|
+
pullFromRemote = async (url, directory, filename, use_header = false, foreground = false) => {
|
|
159
|
+
await this.r.post(`/servers/${this.id}/files/pull`, { url, directory, filename, use_header, foreground });
|
|
160
|
+
};
|
|
161
|
+
uploadGetUrl = async () => {
|
|
162
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/upload`);
|
|
163
|
+
return data.attributes.url;
|
|
164
|
+
};
|
|
165
|
+
upload = async (file, root = "/") => {
|
|
166
|
+
const url = await this.uploadGetUrl();
|
|
167
|
+
await axios.post(url, { files: file }, {
|
|
168
|
+
headers: { "Content-Type": "multipart/form-data" },
|
|
169
|
+
params: { directory: root }
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/api/client/server_schedules.ts
|
|
175
|
+
var ServerSchedules = class {
|
|
176
|
+
r;
|
|
177
|
+
id;
|
|
178
|
+
constructor(requester, id) {
|
|
179
|
+
this.r = requester;
|
|
180
|
+
this.id = id;
|
|
181
|
+
}
|
|
182
|
+
list = async () => {
|
|
183
|
+
const { data } = await this.r.get(`/servers/${this.id}/schedules`);
|
|
184
|
+
return data.data.map((d) => d.attributes);
|
|
185
|
+
};
|
|
186
|
+
create = async (params) => {
|
|
187
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules`, params);
|
|
188
|
+
return data.attributes;
|
|
189
|
+
};
|
|
190
|
+
control = (sched_id) => new ScheduleControl(this.r, this.id, sched_id);
|
|
191
|
+
};
|
|
192
|
+
var ScheduleControl = class {
|
|
193
|
+
r;
|
|
194
|
+
id;
|
|
195
|
+
sched_id;
|
|
196
|
+
constructor(requester, id, sched_id) {
|
|
197
|
+
this.r = requester;
|
|
198
|
+
this.id = id;
|
|
199
|
+
this.sched_id = sched_id;
|
|
200
|
+
}
|
|
201
|
+
info = async () => {
|
|
202
|
+
const { data } = await this.r.get(`/servers/${this.id}/schedules/${this.sched_id}`);
|
|
203
|
+
return data.attributes;
|
|
204
|
+
};
|
|
205
|
+
update = async (params) => {
|
|
206
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}`, params);
|
|
207
|
+
return data.attributes;
|
|
208
|
+
};
|
|
209
|
+
delete = async () => {
|
|
210
|
+
await this.r.delete(`/servers/${this.id}/schedules/${this.sched_id}`);
|
|
211
|
+
};
|
|
212
|
+
execute = async () => {
|
|
213
|
+
await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}/execute`);
|
|
214
|
+
};
|
|
215
|
+
tasks = {
|
|
216
|
+
create: async (opts) => {
|
|
217
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}/tasks`, opts);
|
|
218
|
+
return data.attributes;
|
|
219
|
+
},
|
|
220
|
+
update: async (task_id, opts) => {
|
|
221
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`, opts);
|
|
222
|
+
return data.attributes;
|
|
223
|
+
},
|
|
224
|
+
delete: async (task_id) => {
|
|
225
|
+
await this.r.delete(`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/api/client/server_allocations.ts
|
|
231
|
+
var ServerAllocations = class {
|
|
232
|
+
r;
|
|
233
|
+
id;
|
|
234
|
+
constructor(requester, id) {
|
|
235
|
+
this.r = requester;
|
|
236
|
+
this.id = id;
|
|
237
|
+
}
|
|
238
|
+
list = async () => {
|
|
239
|
+
const { data } = await this.r.get(`/servers/${this.id}/network/allocations`);
|
|
240
|
+
return data.data.map((r) => r.attributes);
|
|
241
|
+
};
|
|
242
|
+
autoAssign = async () => {
|
|
243
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations`);
|
|
244
|
+
return data.attributes;
|
|
245
|
+
};
|
|
246
|
+
setNotes = async (alloc_id, notes) => {
|
|
247
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations/${alloc_id}`, { notes });
|
|
248
|
+
return data.attributes;
|
|
249
|
+
};
|
|
250
|
+
setPrimary = async (alloc_id) => {
|
|
251
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations/${alloc_id}/primary`);
|
|
252
|
+
return data.attributes;
|
|
253
|
+
};
|
|
254
|
+
unassign = async (alloc_id) => {
|
|
255
|
+
await this.r.delete(`/servers/${this.id}/network/allocations/${alloc_id}`);
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// src/api/client/server_users.ts
|
|
260
|
+
var ServerUsers = class {
|
|
261
|
+
r;
|
|
262
|
+
id;
|
|
263
|
+
constructor(requester, id) {
|
|
264
|
+
this.r = requester;
|
|
265
|
+
this.id = id;
|
|
266
|
+
}
|
|
267
|
+
list = async () => {
|
|
268
|
+
const { data } = await this.r.get(`/servers/${this.id}/users`);
|
|
269
|
+
return data.data.map((d) => d.attributes);
|
|
270
|
+
};
|
|
271
|
+
create = async (email, permissions) => {
|
|
272
|
+
const { data } = await this.r.post(`/servers/${this.id}/users`, { email, permissions });
|
|
273
|
+
return data.attributes;
|
|
274
|
+
};
|
|
275
|
+
info = async (user_id) => {
|
|
276
|
+
const { data } = await this.r.get(`/servers/${this.id}/users/${user_id}`);
|
|
277
|
+
return data.attributes;
|
|
278
|
+
};
|
|
279
|
+
update = async (user_id, permissions) => {
|
|
280
|
+
const { data } = await this.r.put(`/servers/${this.id}/users/${user_id}`, { permissions });
|
|
281
|
+
return data.attributes;
|
|
282
|
+
};
|
|
283
|
+
delete = async (user_id) => {
|
|
284
|
+
await this.r.delete(`/servers/${this.id}/users/${user_id}`);
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/api/client/server_backups.ts
|
|
289
|
+
import axios2 from "axios";
|
|
290
|
+
import z3 from "zod";
|
|
291
|
+
var ServerBackups = class {
|
|
292
|
+
r;
|
|
293
|
+
id;
|
|
294
|
+
constructor(requester, id) {
|
|
295
|
+
this.r = requester;
|
|
296
|
+
this.id = id;
|
|
297
|
+
}
|
|
298
|
+
list = async (page = 1) => {
|
|
299
|
+
z3.number().positive().parse(page);
|
|
300
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups`, {
|
|
301
|
+
params: { page }
|
|
302
|
+
});
|
|
303
|
+
return data.data.map((d) => d.attributes);
|
|
304
|
+
};
|
|
305
|
+
create = async (args) => {
|
|
306
|
+
args.name = z3.string().max(255).optional().parse(args.name);
|
|
307
|
+
const { data } = await this.r.post(`/servers/${this.id}/backups`, {
|
|
308
|
+
name: args.name,
|
|
309
|
+
is_locked: args.is_locked,
|
|
310
|
+
ignored_files: args.ignored_files.join("\n")
|
|
311
|
+
});
|
|
312
|
+
return data.attributes;
|
|
313
|
+
};
|
|
314
|
+
info = async (backup_uuid) => {
|
|
315
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups/${backup_uuid}`);
|
|
316
|
+
return data.attributes;
|
|
317
|
+
};
|
|
318
|
+
downloadGetUrl = async (backup_uuid) => {
|
|
319
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups/${backup_uuid}/download`);
|
|
320
|
+
return data.attributes.url;
|
|
321
|
+
};
|
|
322
|
+
download = async (backup_uuid) => {
|
|
323
|
+
const url = await this.downloadGetUrl(backup_uuid);
|
|
324
|
+
const { data } = await axios2.get(url, { responseType: "arraybuffer" });
|
|
325
|
+
return data;
|
|
326
|
+
};
|
|
327
|
+
delete = async (backup_uuid) => {
|
|
328
|
+
await this.r.delete(`/servers/${this.id}/backups/${backup_uuid}`);
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/api/client/server_startup.ts
|
|
333
|
+
var ServerStartup = class {
|
|
334
|
+
r;
|
|
335
|
+
id;
|
|
336
|
+
constructor(requester, id) {
|
|
337
|
+
this.r = requester;
|
|
338
|
+
this.id = id;
|
|
339
|
+
}
|
|
340
|
+
list = async () => {
|
|
341
|
+
const { data } = await this.r.get(`/servers/${this.id}/startup`);
|
|
342
|
+
return {
|
|
343
|
+
object: "list",
|
|
344
|
+
meta: data.meta,
|
|
345
|
+
data: data.data.map((d) => d.attributes)
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
set = async (key, value) => {
|
|
349
|
+
const { data } = await this.r.put(`/servers/${this.id}/startup/variable`, { key, value });
|
|
350
|
+
return data.attributes;
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// src/api/client/server_settings.ts
|
|
355
|
+
import z4 from "zod";
|
|
356
|
+
var ServerSettings = class {
|
|
357
|
+
r;
|
|
358
|
+
id;
|
|
359
|
+
constructor(requester, id) {
|
|
360
|
+
this.r = requester;
|
|
361
|
+
this.id = id;
|
|
362
|
+
}
|
|
363
|
+
rename = async (name) => {
|
|
364
|
+
name = z4.string().max(255).parse(name);
|
|
365
|
+
await this.r.post(`/servers/${this.id}/settings/rename`, { name });
|
|
366
|
+
};
|
|
367
|
+
updateDescription = async (description) => {
|
|
368
|
+
await this.r.post(`/servers/${this.id}/settings/description`, { description });
|
|
369
|
+
};
|
|
370
|
+
reinstall = async () => {
|
|
371
|
+
await this.r.post(`/servers/${this.id}/settings/reinstall`);
|
|
372
|
+
};
|
|
373
|
+
changeDockerImage = async (image) => {
|
|
374
|
+
await this.r.post(`/servers/${this.id}/settings/docker-image`, { image });
|
|
375
|
+
};
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// src/api/client/server_websocket.ts
|
|
379
|
+
import { EventEmitter } from "events";
|
|
380
|
+
import WebSocket from "isomorphic-ws";
|
|
381
|
+
import stripColor from "strip-color";
|
|
382
|
+
var isBrowser = typeof window !== "undefined";
|
|
383
|
+
var RECONNECT_ERRORS = /* @__PURE__ */ new Set([
|
|
384
|
+
"jwt: exp claim is invalid",
|
|
385
|
+
"jwt: created too far in past (denylist)"
|
|
386
|
+
]);
|
|
387
|
+
var FALLBACK_LOG_MESSAGE = "No logs - is the server online?";
|
|
388
|
+
var ServerWebsocket = class {
|
|
389
|
+
r;
|
|
390
|
+
serverId;
|
|
391
|
+
socket;
|
|
392
|
+
currentToken;
|
|
393
|
+
bus = new EventEmitter();
|
|
394
|
+
debugLogging = false;
|
|
395
|
+
stripColors;
|
|
396
|
+
detachMessageListener;
|
|
397
|
+
constructor(requester, id, stripColors = false) {
|
|
398
|
+
this.r = requester;
|
|
399
|
+
this.serverId = id;
|
|
400
|
+
this.stripColors = stripColors;
|
|
401
|
+
}
|
|
402
|
+
on(event, listener) {
|
|
403
|
+
const handler = listener;
|
|
404
|
+
this.bus.on(event, handler);
|
|
405
|
+
return () => {
|
|
406
|
+
this.bus.removeListener(event, handler);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
deregister(event, listener) {
|
|
410
|
+
const handler = listener;
|
|
411
|
+
this.bus.removeListener(event, handler);
|
|
412
|
+
}
|
|
413
|
+
emit(event, ...args) {
|
|
414
|
+
if (args.length === 0) {
|
|
415
|
+
this.bus.emit(event);
|
|
416
|
+
} else {
|
|
417
|
+
this.bus.emit(event, args[0]);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
async connect(resumable, debugLogging) {
|
|
421
|
+
this.debugLogging = debugLogging ?? false;
|
|
422
|
+
if (this.socket) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const socketUrl = await this.refreshCredentials();
|
|
426
|
+
this.socket = isBrowser ? new WebSocket(socketUrl) : new WebSocket(socketUrl, void 0, { origin: new URL(socketUrl).origin });
|
|
427
|
+
await new Promise((resolve, reject) => {
|
|
428
|
+
const socket = this.socket;
|
|
429
|
+
if (!socket) {
|
|
430
|
+
reject(new Error("Failed to create socket connection"));
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
socket.onopen = async () => {
|
|
434
|
+
try {
|
|
435
|
+
await this.authenticate();
|
|
436
|
+
this.attachMessageListener();
|
|
437
|
+
socket.onopen = null;
|
|
438
|
+
socket.onerror = null;
|
|
439
|
+
resolve();
|
|
440
|
+
} catch (error) {
|
|
441
|
+
socket.onopen = null;
|
|
442
|
+
socket.onerror = null;
|
|
443
|
+
reject(error instanceof Error ? error : new Error("Websocket authentication failed"));
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
socket.onerror = (event) => {
|
|
447
|
+
socket.onopen = null;
|
|
448
|
+
socket.onerror = null;
|
|
449
|
+
reject(event instanceof Error ? event : new Error("Websocket connection error"));
|
|
450
|
+
};
|
|
451
|
+
});
|
|
452
|
+
if (resumable) {
|
|
453
|
+
this.makeResumable(true);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
onSocketDisconnect(handler) {
|
|
457
|
+
if (!this.socket) {
|
|
458
|
+
console.error(new Error("No socket connection"));
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
this.socket.onclose = handler;
|
|
462
|
+
}
|
|
463
|
+
onSocketError(handler) {
|
|
464
|
+
if (!this.socket) {
|
|
465
|
+
console.error(new Error("No socket connection"));
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
this.socket.onerror = handler;
|
|
469
|
+
}
|
|
470
|
+
makeResumable(disconnectsToo) {
|
|
471
|
+
const scheduleReconnect = () => {
|
|
472
|
+
setTimeout(() => {
|
|
473
|
+
const previous = this.socket;
|
|
474
|
+
this.detachMessageListener?.();
|
|
475
|
+
this.detachMessageListener = void 0;
|
|
476
|
+
this.socket = void 0;
|
|
477
|
+
previous?.close();
|
|
478
|
+
void this.connect(true, this.debugLogging);
|
|
479
|
+
}, 1e3);
|
|
480
|
+
};
|
|
481
|
+
this.onSocketError(() => scheduleReconnect());
|
|
482
|
+
if (disconnectsToo) {
|
|
483
|
+
this.onSocketDisconnect(() => scheduleReconnect());
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
attachMessageListener() {
|
|
487
|
+
if (!this.socket) {
|
|
488
|
+
throw new Error("No socket connection");
|
|
489
|
+
}
|
|
490
|
+
this.detachMessageListener?.();
|
|
491
|
+
const handler = (event) => {
|
|
492
|
+
void this.handleIncomingMessage(event);
|
|
493
|
+
};
|
|
494
|
+
if (typeof this.socket.addEventListener === "function") {
|
|
495
|
+
this.socket.addEventListener("message", handler);
|
|
496
|
+
this.detachMessageListener = () => {
|
|
497
|
+
this.socket?.removeEventListener?.("message", handler);
|
|
498
|
+
};
|
|
499
|
+
} else {
|
|
500
|
+
const fallback = (data) => handler({ data });
|
|
501
|
+
const socket = this.socket;
|
|
502
|
+
socket.on?.("message", fallback);
|
|
503
|
+
this.detachMessageListener = () => {
|
|
504
|
+
const target = this.socket;
|
|
505
|
+
if (!target) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (typeof target.off === "function") {
|
|
509
|
+
target.off("message", fallback);
|
|
510
|
+
} else if (typeof target.removeListener === "function") {
|
|
511
|
+
target.removeListener("message", fallback);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
async handleIncomingMessage(event) {
|
|
517
|
+
const message = this.parseMessage(event);
|
|
518
|
+
if (!message) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
try {
|
|
522
|
+
await this.dispatchMessage(message);
|
|
523
|
+
} catch (error) {
|
|
524
|
+
if (this.debugLogging) {
|
|
525
|
+
console.error("Error while handling websocket message", error);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
parseMessage(event) {
|
|
530
|
+
const payload = this.normalisePayload(event);
|
|
531
|
+
if (!payload) {
|
|
532
|
+
return null;
|
|
533
|
+
}
|
|
534
|
+
try {
|
|
535
|
+
return JSON.parse(payload);
|
|
536
|
+
} catch (error) {
|
|
537
|
+
if (this.debugLogging) {
|
|
538
|
+
console.warn("Failed to parse websocket payload", error);
|
|
539
|
+
}
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
normalisePayload(event) {
|
|
544
|
+
if (typeof event === "string") {
|
|
545
|
+
return event;
|
|
546
|
+
}
|
|
547
|
+
if (typeof event === "object" && event !== null && "data" in event) {
|
|
548
|
+
return this.normalisePayload(event.data);
|
|
549
|
+
}
|
|
550
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(event)) {
|
|
551
|
+
return event.toString("utf8");
|
|
552
|
+
}
|
|
553
|
+
if (typeof ArrayBuffer !== "undefined" && event instanceof ArrayBuffer) {
|
|
554
|
+
if (typeof TextDecoder !== "undefined") {
|
|
555
|
+
return new TextDecoder().decode(new Uint8Array(event));
|
|
556
|
+
}
|
|
557
|
+
if (typeof Buffer !== "undefined") {
|
|
558
|
+
return Buffer.from(event).toString("utf8");
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
async dispatchMessage(message) {
|
|
564
|
+
switch (message.event) {
|
|
565
|
+
case "auth success" /* AUTH_SUCCESS */: {
|
|
566
|
+
if (this.debugLogging) {
|
|
567
|
+
console.debug("Auth success");
|
|
568
|
+
}
|
|
569
|
+
this.emit("auth success" /* AUTH_SUCCESS */);
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
case "status" /* STATUS */: {
|
|
573
|
+
if (this.debugLogging) {
|
|
574
|
+
console.debug("Received status event", message.args[0]);
|
|
575
|
+
}
|
|
576
|
+
this.emit("status" /* STATUS */, message.args[0]);
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
case "console output" /* CONSOLE_OUTPUT */: {
|
|
580
|
+
let output = message.args[0];
|
|
581
|
+
if (this.stripColors) {
|
|
582
|
+
output = stripColor(output);
|
|
583
|
+
}
|
|
584
|
+
if (this.debugLogging) {
|
|
585
|
+
console.debug("Received console output", output);
|
|
586
|
+
}
|
|
587
|
+
this.emit("console output" /* CONSOLE_OUTPUT */, output);
|
|
588
|
+
break;
|
|
589
|
+
}
|
|
590
|
+
case "stats" /* STATS */: {
|
|
591
|
+
try {
|
|
592
|
+
const payload = JSON.parse(message.args[0]);
|
|
593
|
+
this.emit("stats" /* STATS */, payload);
|
|
594
|
+
} catch (error) {
|
|
595
|
+
if (this.debugLogging) {
|
|
596
|
+
console.warn("Failed to parse stats payload", error);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
case "daemon error" /* DAEMON_ERROR */: {
|
|
602
|
+
this.emit("daemon error" /* DAEMON_ERROR */);
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
case "backup completed" /* BACKUP_COMPLETED */: {
|
|
606
|
+
try {
|
|
607
|
+
const payload = JSON.parse(message.args[0]);
|
|
608
|
+
this.emit("backup completed" /* BACKUP_COMPLETED */, payload);
|
|
609
|
+
} catch (error) {
|
|
610
|
+
if (this.debugLogging) {
|
|
611
|
+
console.warn("Failed to parse backup payload", error);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
case "daemon message" /* DAEMON_MESSAGE */: {
|
|
617
|
+
let output = message.args[0];
|
|
618
|
+
if (this.stripColors) {
|
|
619
|
+
output = stripColor(output);
|
|
620
|
+
}
|
|
621
|
+
this.emit("daemon message" /* DAEMON_MESSAGE */, output);
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
case "install output" /* INSTALL_OUTPUT */: {
|
|
625
|
+
let output = message.args[0];
|
|
626
|
+
if (this.stripColors) {
|
|
627
|
+
output = stripColor(output);
|
|
628
|
+
}
|
|
629
|
+
this.emit("install output" /* INSTALL_OUTPUT */, output);
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
case "backup restore completed" /* BACKUP_RESTORE_COMPLETED */: {
|
|
633
|
+
this.emit("backup restore completed" /* BACKUP_RESTORE_COMPLETED */);
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
case "install completed" /* INSTALL_COMPLETED */: {
|
|
637
|
+
this.emit("install completed" /* INSTALL_COMPLETED */);
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
case "install started" /* INSTALL_STARTED */: {
|
|
641
|
+
this.emit("install started" /* INSTALL_STARTED */);
|
|
642
|
+
break;
|
|
643
|
+
}
|
|
644
|
+
case "transfer logs" /* TRANSFER_LOGS */: {
|
|
645
|
+
this.emit("transfer logs" /* TRANSFER_LOGS */, message.args[0]);
|
|
646
|
+
break;
|
|
647
|
+
}
|
|
648
|
+
case "transfer status" /* TRANSFER_STATUS */: {
|
|
649
|
+
this.emit("transfer status" /* TRANSFER_STATUS */, message.args[0]);
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
case "token expiring" /* TOKEN_EXPIRING */: {
|
|
653
|
+
this.emit("token expiring" /* TOKEN_EXPIRING */);
|
|
654
|
+
if (this.debugLogging) {
|
|
655
|
+
console.warn("Token expiring, renewing...");
|
|
656
|
+
}
|
|
657
|
+
await this.refreshCredentials();
|
|
658
|
+
await this.authenticate();
|
|
659
|
+
break;
|
|
660
|
+
}
|
|
661
|
+
case "token expired" /* TOKEN_EXPIRED */: {
|
|
662
|
+
this.emit("token expired" /* TOKEN_EXPIRED */);
|
|
663
|
+
throw new Error("Token expired");
|
|
664
|
+
}
|
|
665
|
+
case "jwt error" /* JWT_ERROR */: {
|
|
666
|
+
const reason = message.args[0];
|
|
667
|
+
if (RECONNECT_ERRORS.has(reason)) {
|
|
668
|
+
this.emit("token expiring" /* TOKEN_EXPIRING */);
|
|
669
|
+
if (this.debugLogging) {
|
|
670
|
+
console.warn("Token expiring (JWT error), renewing...");
|
|
671
|
+
}
|
|
672
|
+
await this.refreshCredentials();
|
|
673
|
+
await this.authenticate();
|
|
674
|
+
} else {
|
|
675
|
+
this.emit("jwt error" /* JWT_ERROR */, reason);
|
|
676
|
+
throw new Error("Token expired");
|
|
677
|
+
}
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
default: {
|
|
681
|
+
if (this.debugLogging) {
|
|
682
|
+
console.warn("Unknown websocket event", message);
|
|
683
|
+
}
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
async refreshCredentials() {
|
|
689
|
+
const { data } = await this.r.get(`/servers/${this.serverId}/websocket`);
|
|
690
|
+
this.currentToken = data.data.token;
|
|
691
|
+
return data.data.socket;
|
|
692
|
+
}
|
|
693
|
+
async authenticate() {
|
|
694
|
+
if (!this.socket) {
|
|
695
|
+
throw new Error("No socket connection");
|
|
696
|
+
}
|
|
697
|
+
if (!this.currentToken) {
|
|
698
|
+
throw new Error("Missing websocket token");
|
|
699
|
+
}
|
|
700
|
+
this.socket.send(JSON.stringify({ event: "auth", args: [this.currentToken] }));
|
|
701
|
+
}
|
|
702
|
+
disconnect() {
|
|
703
|
+
this.detachMessageListener?.();
|
|
704
|
+
this.detachMessageListener = void 0;
|
|
705
|
+
if (this.socket) {
|
|
706
|
+
this.socket.close();
|
|
707
|
+
this.socket = void 0;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
requestStats() {
|
|
711
|
+
this.send("send stats", [null]);
|
|
712
|
+
}
|
|
713
|
+
requestLogs() {
|
|
714
|
+
this.send("send logs", [null]);
|
|
715
|
+
}
|
|
716
|
+
send(event, args) {
|
|
717
|
+
if (!this.socket) {
|
|
718
|
+
if (this.debugLogging) {
|
|
719
|
+
console.warn(`Attempted to send "${event}" without an active websocket connection`);
|
|
720
|
+
}
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
this.socket.send(JSON.stringify({ event, args }));
|
|
724
|
+
}
|
|
725
|
+
getStats() {
|
|
726
|
+
return new Promise((resolve, reject) => {
|
|
727
|
+
if (!this.socket) {
|
|
728
|
+
reject(new Error("No socket connection"));
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
let off;
|
|
732
|
+
const timeout = setTimeout(() => {
|
|
733
|
+
off?.();
|
|
734
|
+
reject(new Error("Timed out waiting for stats"));
|
|
735
|
+
}, 5e3);
|
|
736
|
+
off = this.on("stats" /* STATS */, (payload) => {
|
|
737
|
+
clearTimeout(timeout);
|
|
738
|
+
off?.();
|
|
739
|
+
resolve(payload);
|
|
740
|
+
});
|
|
741
|
+
this.requestStats();
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
getLogs() {
|
|
745
|
+
return new Promise((resolve, reject) => {
|
|
746
|
+
if (!this.socket) {
|
|
747
|
+
reject(new Error("No socket connection"));
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
const lines = [];
|
|
751
|
+
let off;
|
|
752
|
+
let initialTimeout;
|
|
753
|
+
let idleTimeout;
|
|
754
|
+
const finalize = (payload) => {
|
|
755
|
+
off?.();
|
|
756
|
+
if (initialTimeout) {
|
|
757
|
+
clearTimeout(initialTimeout);
|
|
758
|
+
}
|
|
759
|
+
if (idleTimeout) {
|
|
760
|
+
clearTimeout(idleTimeout);
|
|
761
|
+
}
|
|
762
|
+
resolve(payload);
|
|
763
|
+
};
|
|
764
|
+
initialTimeout = setTimeout(() => {
|
|
765
|
+
finalize(lines.length > 0 ? lines : [FALLBACK_LOG_MESSAGE]);
|
|
766
|
+
}, 5e3);
|
|
767
|
+
off = this.on("console output" /* CONSOLE_OUTPUT */, (line) => {
|
|
768
|
+
lines.push(line);
|
|
769
|
+
if (initialTimeout) {
|
|
770
|
+
clearTimeout(initialTimeout);
|
|
771
|
+
initialTimeout = void 0;
|
|
772
|
+
}
|
|
773
|
+
if (idleTimeout) {
|
|
774
|
+
clearTimeout(idleTimeout);
|
|
775
|
+
}
|
|
776
|
+
idleTimeout = setTimeout(() => {
|
|
777
|
+
finalize(lines);
|
|
778
|
+
}, 1e3);
|
|
779
|
+
});
|
|
780
|
+
this.requestLogs();
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
sendPoweraction(action) {
|
|
784
|
+
this.send("set state", [action]);
|
|
785
|
+
}
|
|
786
|
+
sendCommand(cmd) {
|
|
787
|
+
this.send("send command", [cmd]);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// src/api/client/server_activity.ts
|
|
792
|
+
var ServerActivity = class {
|
|
793
|
+
r;
|
|
794
|
+
id;
|
|
795
|
+
constructor(r, id) {
|
|
796
|
+
this.r = r;
|
|
797
|
+
this.id = id;
|
|
798
|
+
}
|
|
799
|
+
list = async (page = 1, per_page = 25) => {
|
|
800
|
+
const { data } = await this.r.get(`/server/${this.id}/activity`, {
|
|
801
|
+
params: {
|
|
802
|
+
page,
|
|
803
|
+
per_page
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
return data.data.map((log) => log.attributes);
|
|
807
|
+
};
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
// src/api/client/server.ts
|
|
811
|
+
var ServerClient = class {
|
|
812
|
+
r;
|
|
813
|
+
id;
|
|
814
|
+
activity;
|
|
815
|
+
databases;
|
|
816
|
+
files;
|
|
817
|
+
schedules;
|
|
818
|
+
allocations;
|
|
819
|
+
users;
|
|
820
|
+
backups;
|
|
821
|
+
startup;
|
|
822
|
+
variables;
|
|
823
|
+
settings;
|
|
824
|
+
constructor(requester, id) {
|
|
825
|
+
this.r = requester;
|
|
826
|
+
this.id = id;
|
|
827
|
+
this.activity = new ServerActivity(requester, id);
|
|
828
|
+
this.databases = new ServerDatabases(requester, id);
|
|
829
|
+
this.files = new ServerFiles(requester, id);
|
|
830
|
+
this.schedules = new ServerSchedules(requester, id);
|
|
831
|
+
this.allocations = new ServerAllocations(requester, id);
|
|
832
|
+
this.users = new ServerUsers(requester, id);
|
|
833
|
+
this.backups = new ServerBackups(requester, id);
|
|
834
|
+
this.startup = new ServerStartup(requester, id);
|
|
835
|
+
this.variables = this.startup;
|
|
836
|
+
this.settings = new ServerSettings(requester, id);
|
|
837
|
+
}
|
|
838
|
+
info = async (include) => {
|
|
839
|
+
const { data } = await this.r.get(`/servers/${this.id}`, {
|
|
840
|
+
params: { include: include?.join(",") }
|
|
841
|
+
});
|
|
842
|
+
return data.attributes;
|
|
843
|
+
};
|
|
844
|
+
websocket = (stripColors = false) => {
|
|
845
|
+
return new ServerWebsocket(this.r, this.id, stripColors);
|
|
846
|
+
};
|
|
847
|
+
resources = async () => {
|
|
848
|
+
const { data } = await this.r.get(`/servers/${this.id}/resources`);
|
|
849
|
+
return data.attributes;
|
|
850
|
+
};
|
|
851
|
+
command = async (command) => {
|
|
852
|
+
await this.r.post(`/servers/${this.id}/command`, { command });
|
|
853
|
+
};
|
|
854
|
+
power = async (signal) => {
|
|
855
|
+
await this.r.post(`/servers/${this.id}/power`, { signal });
|
|
856
|
+
};
|
|
857
|
+
};
|
|
858
|
+
|
|
859
|
+
// src/api/client/client.ts
|
|
860
|
+
var Client = class {
|
|
861
|
+
account;
|
|
862
|
+
r;
|
|
863
|
+
constructor(requester) {
|
|
864
|
+
this.r = requester;
|
|
865
|
+
this.account = new Account(requester);
|
|
866
|
+
}
|
|
867
|
+
listPermissions = async () => {
|
|
868
|
+
const { data } = await this.r.get("/permissions");
|
|
869
|
+
return data.attributes.permissions;
|
|
870
|
+
};
|
|
871
|
+
listServers = async (type = "accessible", page = 1, per_page = 50, include) => {
|
|
872
|
+
z5.number().positive().parse(page);
|
|
873
|
+
const { data } = await this.r.get("/servers", {
|
|
874
|
+
params: { type, page, include: include?.join(",") }
|
|
875
|
+
});
|
|
876
|
+
return data.data.map((s) => s.attributes);
|
|
877
|
+
};
|
|
878
|
+
server = (uuid) => new ServerClient(this.r, uuid);
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
// src/api/application/users.ts
|
|
882
|
+
import z6 from "zod";
|
|
883
|
+
|
|
884
|
+
// src/utils/transform.ts
|
|
885
|
+
var ArrayQueryParams = (p) => {
|
|
886
|
+
const params = new URLSearchParams();
|
|
887
|
+
const o = {};
|
|
888
|
+
for (const [param, value] of Object.entries(p)) {
|
|
889
|
+
for (const [key, val] of Object.entries(value)) {
|
|
890
|
+
o[`${param}[${key}]`] = val;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
return o;
|
|
894
|
+
};
|
|
895
|
+
var SortParam = (key, p) => {
|
|
896
|
+
return `${p === "desc" ? "-" : ""}${key}`;
|
|
897
|
+
};
|
|
898
|
+
|
|
899
|
+
// src/api/application/users.ts
|
|
900
|
+
var Users = class {
|
|
901
|
+
r;
|
|
902
|
+
constructor(requester) {
|
|
903
|
+
this.r = requester;
|
|
904
|
+
}
|
|
905
|
+
list = async ({ ...opts }, page = 1) => {
|
|
906
|
+
z6.number().positive().parse(page);
|
|
907
|
+
const { data } = await this.r.get("/users", {
|
|
908
|
+
params: {
|
|
909
|
+
include: opts.include?.join(","),
|
|
910
|
+
page,
|
|
911
|
+
...ArrayQueryParams({ filters: opts.filters || {} }),
|
|
912
|
+
sort: opts.sort?.id ? SortParam("id", opts.sort?.id) : SortParam("uuid", opts.sort?.uuid)
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
return data.data.map((d) => d.attributes);
|
|
916
|
+
};
|
|
917
|
+
info = async (id, { include }) => {
|
|
918
|
+
z6.number().positive().parse(id);
|
|
919
|
+
const { data } = await this.r.get(`/users/${id}`, {
|
|
920
|
+
params: { include: include?.join(",") }
|
|
921
|
+
});
|
|
922
|
+
return data.attributes;
|
|
923
|
+
};
|
|
924
|
+
infoByExternal = async (external_id, { include }) => {
|
|
925
|
+
const { data } = await this.r.get(`/users/external/${external_id}`);
|
|
926
|
+
return data.attributes;
|
|
927
|
+
};
|
|
928
|
+
create = async (user) => {
|
|
929
|
+
const { data } = await this.r.post("/users", user);
|
|
930
|
+
return data.attributes;
|
|
931
|
+
};
|
|
932
|
+
update = async (id, user) => {
|
|
933
|
+
z6.number().positive().parse(id);
|
|
934
|
+
const { data } = await this.r.put(`/users/${id}`, user);
|
|
935
|
+
return data.attributes;
|
|
936
|
+
};
|
|
937
|
+
delete = async (id) => {
|
|
938
|
+
z6.number().positive().parse(id);
|
|
939
|
+
await this.r.delete(`/users/${id}`);
|
|
940
|
+
};
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
// src/api/application/client.ts
|
|
944
|
+
var Client2 = class {
|
|
945
|
+
r;
|
|
946
|
+
users;
|
|
947
|
+
constructor(requester) {
|
|
948
|
+
this.r = requester;
|
|
949
|
+
this.users = new Users(requester);
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
// src/api/base/request.ts
|
|
954
|
+
import z7 from "zod";
|
|
955
|
+
import axios3 from "axios";
|
|
956
|
+
|
|
957
|
+
// src/api/base/types.ts
|
|
958
|
+
var PterodactylException = class extends Error {
|
|
959
|
+
data;
|
|
960
|
+
status;
|
|
961
|
+
constructor(message, data, status) {
|
|
962
|
+
super(message);
|
|
963
|
+
this.data = data;
|
|
964
|
+
this.status = status;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
// src/api/base/request.ts
|
|
969
|
+
var Agent = class {
|
|
970
|
+
base_url;
|
|
971
|
+
token;
|
|
972
|
+
requester;
|
|
973
|
+
constructor(url, token, type) {
|
|
974
|
+
this.base_url = z7.url("Invalid URL Schema").parse(url);
|
|
975
|
+
this.token = z7.string().regex(/^(ptl[ac]|pacc|papp)_.+$/, "Invalid token type").parse(token);
|
|
976
|
+
this.requester = axios3.create({
|
|
977
|
+
baseURL: this.base_url.replace(/\/+$/, "") + `/api/${type}`,
|
|
978
|
+
timeout: 3e3,
|
|
979
|
+
headers: {
|
|
980
|
+
Authorization: `Bearer ${this.token}`
|
|
981
|
+
}
|
|
982
|
+
});
|
|
983
|
+
this.requester.interceptors.response.use(void 0, (error) => {
|
|
984
|
+
if (error.response && error.response.status === 400) {
|
|
985
|
+
return Promise.reject(new PterodactylException(
|
|
986
|
+
"Invalid request data",
|
|
987
|
+
error.response.data,
|
|
988
|
+
error.response.status
|
|
989
|
+
));
|
|
990
|
+
}
|
|
991
|
+
return Promise.reject(error);
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
// src/index.ts
|
|
997
|
+
var PelicanClient = class extends Client {
|
|
998
|
+
constructor(url, token) {
|
|
999
|
+
const ax = new Agent(url, token, "client");
|
|
1000
|
+
super(ax.requester);
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
var PelicanApplication = class extends Client2 {
|
|
1004
|
+
constructor(url, token) {
|
|
1005
|
+
const ax = new Agent(url, token, "application");
|
|
1006
|
+
super(ax.requester);
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
export {
|
|
1010
|
+
PelicanApplication,
|
|
1011
|
+
PelicanClient
|
|
1012
|
+
};
|
|
1013
|
+
/*
|
|
1014
|
+
* @author BothimTV
|
|
1015
|
+
* @license MIT
|
|
1016
|
+
*/
|
|
1017
|
+
//# sourceMappingURL=index.mjs.map
|