@pelican.ts/sdk 0.3.4-next.4 → 0.4.1

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.
@@ -0,0 +1,2062 @@
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_uuid) => {
276
+ const { data } = await this.r.get(`/servers/${this.id}/users/${user_uuid}`);
277
+ return data.attributes;
278
+ };
279
+ update = async (user_uuid, permissions) => {
280
+ const { data } = await this.r.put(`/servers/${this.id}/users/${user_uuid}`, { permissions });
281
+ return data.attributes;
282
+ };
283
+ delete = async (user_uuid) => {
284
+ await this.r.delete(`/servers/${this.id}/users/${user_uuid}`);
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
+ get $r() {
868
+ return this.r;
869
+ }
870
+ listPermissions = async () => {
871
+ const { data } = await this.r.get("/permissions");
872
+ return data.attributes.permissions;
873
+ };
874
+ listServers = async (type = "accessible", page = 1, per_page = 50, include) => {
875
+ z5.number().positive().parse(page);
876
+ const { data } = await this.r.get("/", {
877
+ params: { type, page, include: include?.join(",") }
878
+ });
879
+ return data.data.map((s) => s.attributes);
880
+ };
881
+ server = (uuid) => new ServerClient(this.r, uuid);
882
+ };
883
+
884
+ // src/api/application/users.ts
885
+ import z7 from "zod";
886
+
887
+ // src/utils/transform.ts
888
+ var ArrayQueryParams = (p) => {
889
+ const params = new URLSearchParams();
890
+ const o = {};
891
+ for (const [param, value] of Object.entries(p)) {
892
+ for (const [key, val] of Object.entries(value)) {
893
+ o[`${param}[${key}]`] = val;
894
+ }
895
+ }
896
+ return o;
897
+ };
898
+ var SortParam = (key, p) => {
899
+ return `${p === "desc" ? "-" : ""}${key}`;
900
+ };
901
+
902
+ // src/api/common/types/enums.ts
903
+ import z6 from "zod";
904
+ var languagesSchema = z6.enum([
905
+ "af",
906
+ "ak",
907
+ "am",
908
+ "ar",
909
+ "as",
910
+ "az",
911
+ "be",
912
+ "bg",
913
+ "bm",
914
+ "bn",
915
+ "bo",
916
+ "br",
917
+ "bs",
918
+ "ca",
919
+ "ce",
920
+ "cs",
921
+ "cv",
922
+ "cy",
923
+ "da",
924
+ "de",
925
+ "dz",
926
+ "ee",
927
+ "el",
928
+ "en",
929
+ "eo",
930
+ "es",
931
+ "et",
932
+ "eu",
933
+ "fa",
934
+ "ff",
935
+ "fi",
936
+ "fo",
937
+ "fr",
938
+ "fy",
939
+ "ga",
940
+ "gd",
941
+ "gl",
942
+ "gu",
943
+ "gv",
944
+ "ha",
945
+ "he",
946
+ "hi",
947
+ "hr",
948
+ "hu",
949
+ "hy",
950
+ "ia",
951
+ "id",
952
+ "ig",
953
+ "ii",
954
+ "is",
955
+ "it",
956
+ "ja",
957
+ "jv",
958
+ "ka",
959
+ "ki",
960
+ "kk",
961
+ "kl",
962
+ "km",
963
+ "kn",
964
+ "ko",
965
+ "ks",
966
+ "ku",
967
+ "kw",
968
+ "ky",
969
+ "lb",
970
+ "lg",
971
+ "ln",
972
+ "lo",
973
+ "lt",
974
+ "lu",
975
+ "lv",
976
+ "mg",
977
+ "mi",
978
+ "mk",
979
+ "ml",
980
+ "mn",
981
+ "mr",
982
+ "ms",
983
+ "mt",
984
+ "my",
985
+ "nb",
986
+ "nd",
987
+ "ne",
988
+ "nl",
989
+ "nn",
990
+ "no",
991
+ "om",
992
+ "or",
993
+ "os",
994
+ "pa",
995
+ "pl",
996
+ "ps",
997
+ "pt",
998
+ "qu",
999
+ "rm",
1000
+ "rn",
1001
+ "ro",
1002
+ "ru",
1003
+ "rw",
1004
+ "sa",
1005
+ "sc",
1006
+ "sd",
1007
+ "se",
1008
+ "sg",
1009
+ "si",
1010
+ "sk",
1011
+ "sl",
1012
+ "sn",
1013
+ "so",
1014
+ "sq",
1015
+ "sr",
1016
+ "su",
1017
+ "sv",
1018
+ "sw",
1019
+ "ta",
1020
+ "te",
1021
+ "tg",
1022
+ "th",
1023
+ "ti",
1024
+ "tk",
1025
+ "to",
1026
+ "tr",
1027
+ "tt",
1028
+ "ug",
1029
+ "uk",
1030
+ "ur",
1031
+ "uz",
1032
+ "vi",
1033
+ "wo",
1034
+ "xh",
1035
+ "yi",
1036
+ "yo",
1037
+ "zh",
1038
+ "zu"
1039
+ ]);
1040
+ var timezonesSchema = z6.enum([
1041
+ "Africa/Abidjan",
1042
+ "Africa/Accra",
1043
+ "Africa/Addis_Ababa",
1044
+ "Africa/Algiers",
1045
+ "Africa/Asmara",
1046
+ "Africa/Bamako",
1047
+ "Africa/Bangui",
1048
+ "Africa/Banjul",
1049
+ "Africa/Bissau",
1050
+ "Africa/Blantyre",
1051
+ "Africa/Brazzaville",
1052
+ "Africa/Bujumbura",
1053
+ "Africa/Cairo",
1054
+ "Africa/Casablanca",
1055
+ "Africa/Ceuta",
1056
+ "Africa/Conakry",
1057
+ "Africa/Dakar",
1058
+ "Africa/Dar_es_Salaam",
1059
+ "Africa/Djibouti",
1060
+ "Africa/Douala",
1061
+ "Africa/El_Aaiun",
1062
+ "Africa/Freetown",
1063
+ "Africa/Gaborone",
1064
+ "Africa/Harare",
1065
+ "Africa/Johannesburg",
1066
+ "Africa/Juba",
1067
+ "Africa/Kampala",
1068
+ "Africa/Khartoum",
1069
+ "Africa/Kigali",
1070
+ "Africa/Kinshasa",
1071
+ "Africa/Lagos",
1072
+ "Africa/Libreville",
1073
+ "Africa/Lome",
1074
+ "Africa/Luanda",
1075
+ "Africa/Lubumbashi",
1076
+ "Africa/Lusaka",
1077
+ "Africa/Malabo",
1078
+ "Africa/Maputo",
1079
+ "Africa/Maseru",
1080
+ "Africa/Mbabane",
1081
+ "Africa/Mogadishu",
1082
+ "Africa/Monrovia",
1083
+ "Africa/Nairobi",
1084
+ "Africa/Ndjamena",
1085
+ "Africa/Niamey",
1086
+ "Africa/Nouakchott",
1087
+ "Africa/Ouagadougou",
1088
+ "Africa/Porto-Novo",
1089
+ "Africa/Sao_Tome",
1090
+ "Africa/Tripoli",
1091
+ "Africa/Tunis",
1092
+ "Africa/Windhoek",
1093
+ "America/Adak",
1094
+ "America/Anchorage",
1095
+ "America/Anguilla",
1096
+ "America/Antigua",
1097
+ "America/Araguaina",
1098
+ "America/Argentina/Buenos_Aires",
1099
+ "America/Argentina/Catamarca",
1100
+ "America/Argentina/Cordoba",
1101
+ "America/Argentina/Jujuy",
1102
+ "America/Argentina/La_Rioja",
1103
+ "America/Argentina/Mendoza",
1104
+ "America/Argentina/Rio_Gallegos",
1105
+ "America/Argentina/Salta",
1106
+ "America/Argentina/San_Juan",
1107
+ "America/Argentina/San_Luis",
1108
+ "America/Argentina/Tucuman",
1109
+ "America/Argentina/Ushuaia",
1110
+ "America/Aruba",
1111
+ "America/Asuncion",
1112
+ "America/Atikokan",
1113
+ "America/Bahia",
1114
+ "America/Bahia_Banderas",
1115
+ "America/Barbados",
1116
+ "America/Belem",
1117
+ "America/Belize",
1118
+ "America/Blanc-Sablon",
1119
+ "America/Boa_Vista",
1120
+ "America/Bogota",
1121
+ "America/Boise",
1122
+ "America/Cambridge_Bay",
1123
+ "America/Campo_Grande",
1124
+ "America/Cancun",
1125
+ "America/Caracas",
1126
+ "America/Cayenne",
1127
+ "America/Cayman",
1128
+ "America/Chicago",
1129
+ "America/Chihuahua",
1130
+ "America/Ciudad_Juarez",
1131
+ "America/Costa_Rica",
1132
+ "America/Coyhaique",
1133
+ "America/Creston",
1134
+ "America/Cuiaba",
1135
+ "America/Curacao",
1136
+ "America/Danmarkshavn",
1137
+ "America/Dawson",
1138
+ "America/Dawson_Creek",
1139
+ "America/Denver",
1140
+ "America/Detroit",
1141
+ "America/Dominica",
1142
+ "America/Edmonton",
1143
+ "America/Eirunepe",
1144
+ "America/El_Salvador",
1145
+ "America/Fort_Nelson",
1146
+ "America/Fortaleza",
1147
+ "America/Glace_Bay",
1148
+ "America/Goose_Bay",
1149
+ "America/Grand_Turk",
1150
+ "America/Grenada",
1151
+ "America/Guadeloupe",
1152
+ "America/Guatemala",
1153
+ "America/Guayaquil",
1154
+ "America/Guyana",
1155
+ "America/Halifax",
1156
+ "America/Havana",
1157
+ "America/Hermosillo",
1158
+ "America/Indiana/Indianapolis",
1159
+ "America/Indiana/Knox",
1160
+ "America/Indiana/Marengo",
1161
+ "America/Indiana/Petersburg",
1162
+ "America/Indiana/Tell_City",
1163
+ "America/Indiana/Vevay",
1164
+ "America/Indiana/Vincennes",
1165
+ "America/Indiana/Winamac",
1166
+ "America/Inuvik",
1167
+ "America/Iqaluit",
1168
+ "America/Jamaica",
1169
+ "America/Juneau",
1170
+ "America/Kentucky/Louisville",
1171
+ "America/Kentucky/Monticello",
1172
+ "America/Kralendijk",
1173
+ "America/La_Paz",
1174
+ "America/Lima",
1175
+ "America/Los_Angeles",
1176
+ "America/Lower_Princes",
1177
+ "America/Maceio",
1178
+ "America/Managua",
1179
+ "America/Manaus",
1180
+ "America/Marigot",
1181
+ "America/Martinique",
1182
+ "America/Matamoros",
1183
+ "America/Mazatlan",
1184
+ "America/Menominee",
1185
+ "America/Merida",
1186
+ "America/Metlakatla",
1187
+ "America/Mexico_City",
1188
+ "America/Miquelon",
1189
+ "America/Moncton",
1190
+ "America/Monterrey",
1191
+ "America/Montevideo",
1192
+ "America/Montserrat",
1193
+ "America/Nassau",
1194
+ "America/New_York",
1195
+ "America/Nome",
1196
+ "America/Noronha",
1197
+ "America/North_Dakota/Beulah",
1198
+ "America/North_Dakota/Center",
1199
+ "America/North_Dakota/New_Salem",
1200
+ "America/Nuuk",
1201
+ "America/Ojinaga",
1202
+ "America/Panama",
1203
+ "America/Paramaribo",
1204
+ "America/Phoenix",
1205
+ "America/Port-au-Prince",
1206
+ "America/Port_of_Spain",
1207
+ "America/Porto_Velho",
1208
+ "America/Puerto_Rico",
1209
+ "America/Punta_Arenas",
1210
+ "America/Rankin_Inlet",
1211
+ "America/Recife",
1212
+ "America/Regina",
1213
+ "America/Resolute",
1214
+ "America/Rio_Branco",
1215
+ "America/Santarem",
1216
+ "America/Santiago",
1217
+ "America/Santo_Domingo",
1218
+ "America/Sao_Paulo",
1219
+ "America/Scoresbysund",
1220
+ "America/Sitka",
1221
+ "America/St_Barthelemy",
1222
+ "America/St_Johns",
1223
+ "America/St_Kitts",
1224
+ "America/St_Lucia",
1225
+ "America/St_Thomas",
1226
+ "America/St_Vincent",
1227
+ "America/Swift_Current",
1228
+ "America/Tegucigalpa",
1229
+ "America/Thule",
1230
+ "America/Tijuana",
1231
+ "America/Toronto",
1232
+ "America/Tortola",
1233
+ "America/Vancouver",
1234
+ "America/Whitehorse",
1235
+ "America/Winnipeg",
1236
+ "America/Yakutat",
1237
+ "Antarctica/Casey",
1238
+ "Antarctica/Davis",
1239
+ "Antarctica/DumontDUrville",
1240
+ "Antarctica/Macquarie",
1241
+ "Antarctica/Mawson",
1242
+ "Antarctica/McMurdo",
1243
+ "Antarctica/Palmer",
1244
+ "Antarctica/Rothera",
1245
+ "Antarctica/Syowa",
1246
+ "Antarctica/Troll",
1247
+ "Antarctica/Vostok",
1248
+ "Arctic/Longyearbyen",
1249
+ "Asia/Aden",
1250
+ "Asia/Almaty",
1251
+ "Asia/Amman",
1252
+ "Asia/Anadyr",
1253
+ "Asia/Aqtau",
1254
+ "Asia/Aqtobe",
1255
+ "Asia/Ashgabat",
1256
+ "Asia/Atyrau",
1257
+ "Asia/Baghdad",
1258
+ "Asia/Bahrain",
1259
+ "Asia/Baku",
1260
+ "Asia/Bangkok",
1261
+ "Asia/Barnaul",
1262
+ "Asia/Beirut",
1263
+ "Asia/Bishkek",
1264
+ "Asia/Brunei",
1265
+ "Asia/Chita",
1266
+ "Asia/Colombo",
1267
+ "Asia/Damascus",
1268
+ "Asia/Dhaka",
1269
+ "Asia/Dili",
1270
+ "Asia/Dubai",
1271
+ "Asia/Dushanbe",
1272
+ "Asia/Famagusta",
1273
+ "Asia/Gaza",
1274
+ "Asia/Hebron",
1275
+ "Asia/Ho_Chi_Minh",
1276
+ "Asia/Hong_Kong",
1277
+ "Asia/Hovd",
1278
+ "Asia/Irkutsk",
1279
+ "Asia/Jakarta",
1280
+ "Asia/Jayapura",
1281
+ "Asia/Jerusalem",
1282
+ "Asia/Kabul",
1283
+ "Asia/Kamchatka",
1284
+ "Asia/Karachi",
1285
+ "Asia/Kathmandu",
1286
+ "Asia/Khandyga",
1287
+ "Asia/Kolkata",
1288
+ "Asia/Krasnoyarsk",
1289
+ "Asia/Kuala_Lumpur",
1290
+ "Asia/Kuching",
1291
+ "Asia/Kuwait",
1292
+ "Asia/Macau",
1293
+ "Asia/Magadan",
1294
+ "Asia/Makassar",
1295
+ "Asia/Manila",
1296
+ "Asia/Muscat",
1297
+ "Asia/Nicosia",
1298
+ "Asia/Novokuznetsk",
1299
+ "Asia/Novosibirsk",
1300
+ "Asia/Omsk",
1301
+ "Asia/Oral",
1302
+ "Asia/Phnom_Penh",
1303
+ "Asia/Pontianak",
1304
+ "Asia/Pyongyang",
1305
+ "Asia/Qatar",
1306
+ "Asia/Qostanay",
1307
+ "Asia/Qyzylorda",
1308
+ "Asia/Riyadh",
1309
+ "Asia/Sakhalin",
1310
+ "Asia/Samarkand",
1311
+ "Asia/Seoul",
1312
+ "Asia/Shanghai",
1313
+ "Asia/Singapore",
1314
+ "Asia/Srednekolymsk",
1315
+ "Asia/Taipei",
1316
+ "Asia/Tashkent",
1317
+ "Asia/Tbilisi",
1318
+ "Asia/Tehran",
1319
+ "Asia/Thimphu",
1320
+ "Asia/Tokyo",
1321
+ "Asia/Tomsk",
1322
+ "Asia/Ulaanbaatar",
1323
+ "Asia/Urumqi",
1324
+ "Asia/Ust-Nera",
1325
+ "Asia/Vientiane",
1326
+ "Asia/Vladivostok",
1327
+ "Asia/Yakutsk",
1328
+ "Asia/Yangon",
1329
+ "Asia/Yekaterinburg",
1330
+ "Asia/Yerevan",
1331
+ "Atlantic/Azores",
1332
+ "Atlantic/Bermuda",
1333
+ "Atlantic/Canary",
1334
+ "Atlantic/Cape_Verde",
1335
+ "Atlantic/Faroe",
1336
+ "Atlantic/Madeira",
1337
+ "Atlantic/Reykjavik",
1338
+ "Atlantic/South_Georgia",
1339
+ "Atlantic/St_Helena",
1340
+ "Atlantic/Stanley",
1341
+ "Australia/Adelaide",
1342
+ "Australia/Brisbane",
1343
+ "Australia/Broken_Hill",
1344
+ "Australia/Darwin",
1345
+ "Australia/Eucla",
1346
+ "Australia/Hobart",
1347
+ "Australia/Lindeman",
1348
+ "Australia/Lord_Howe",
1349
+ "Australia/Melbourne",
1350
+ "Australia/Perth",
1351
+ "Australia/Sydney",
1352
+ "Europe/Amsterdam",
1353
+ "Europe/Andorra",
1354
+ "Europe/Astrakhan",
1355
+ "Europe/Athens",
1356
+ "Europe/Belgrade",
1357
+ "Europe/Berlin",
1358
+ "Europe/Bratislava",
1359
+ "Europe/Brussels",
1360
+ "Europe/Bucharest",
1361
+ "Europe/Budapest",
1362
+ "Europe/Busingen",
1363
+ "Europe/Chisinau",
1364
+ "Europe/Copenhagen",
1365
+ "Europe/Dublin",
1366
+ "Europe/Gibraltar",
1367
+ "Europe/Guernsey",
1368
+ "Europe/Helsinki",
1369
+ "Europe/Isle_of_Man",
1370
+ "Europe/Istanbul",
1371
+ "Europe/Jersey",
1372
+ "Europe/Kaliningrad",
1373
+ "Europe/Kirov",
1374
+ "Europe/Kyiv",
1375
+ "Europe/Lisbon",
1376
+ "Europe/Ljubljana",
1377
+ "Europe/London",
1378
+ "Europe/Luxembourg",
1379
+ "Europe/Madrid",
1380
+ "Europe/Malta",
1381
+ "Europe/Mariehamn",
1382
+ "Europe/Minsk",
1383
+ "Europe/Monaco",
1384
+ "Europe/Moscow",
1385
+ "Europe/Oslo",
1386
+ "Europe/Paris",
1387
+ "Europe/Podgorica",
1388
+ "Europe/Prague",
1389
+ "Europe/Riga",
1390
+ "Europe/Rome",
1391
+ "Europe/Samara",
1392
+ "Europe/San_Marino",
1393
+ "Europe/Sarajevo",
1394
+ "Europe/Saratov",
1395
+ "Europe/Simferopol",
1396
+ "Europe/Skopje",
1397
+ "Europe/Sofia",
1398
+ "Europe/Stockholm",
1399
+ "Europe/Tallinn",
1400
+ "Europe/Tirane",
1401
+ "Europe/Ulyanovsk",
1402
+ "Europe/Vaduz",
1403
+ "Europe/Vatican",
1404
+ "Europe/Vienna",
1405
+ "Europe/Vilnius",
1406
+ "Europe/Volgograd",
1407
+ "Europe/Warsaw",
1408
+ "Europe/Zagreb",
1409
+ "Europe/Zurich",
1410
+ "Indian/Antananarivo",
1411
+ "Indian/Chagos",
1412
+ "Indian/Christmas",
1413
+ "Indian/Cocos",
1414
+ "Indian/Comoro",
1415
+ "Indian/Kerguelen",
1416
+ "Indian/Mahe",
1417
+ "Indian/Maldives",
1418
+ "Indian/Mauritius",
1419
+ "Indian/Mayotte",
1420
+ "Indian/Reunion",
1421
+ "Pacific/Apia",
1422
+ "Pacific/Auckland",
1423
+ "Pacific/Bougainville",
1424
+ "Pacific/Chatham",
1425
+ "Pacific/Chuuk",
1426
+ "Pacific/Easter",
1427
+ "Pacific/Efate",
1428
+ "Pacific/Fakaofo",
1429
+ "Pacific/Fiji",
1430
+ "Pacific/Funafuti",
1431
+ "Pacific/Galapagos",
1432
+ "Pacific/Gambier",
1433
+ "Pacific/Guadalcanal",
1434
+ "Pacific/Guam",
1435
+ "Pacific/Honolulu",
1436
+ "Pacific/Kanton",
1437
+ "Pacific/Kiritimati",
1438
+ "Pacific/Kosrae",
1439
+ "Pacific/Kwajalein",
1440
+ "Pacific/Majuro",
1441
+ "Pacific/Marquesas",
1442
+ "Pacific/Midway",
1443
+ "Pacific/Nauru",
1444
+ "Pacific/Niue",
1445
+ "Pacific/Norfolk",
1446
+ "Pacific/Noumea",
1447
+ "Pacific/Pago_Pago",
1448
+ "Pacific/Palau",
1449
+ "Pacific/Pitcairn",
1450
+ "Pacific/Pohnpei",
1451
+ "Pacific/Port_Moresby",
1452
+ "Pacific/Rarotonga",
1453
+ "Pacific/Saipan",
1454
+ "Pacific/Tahiti",
1455
+ "Pacific/Tarawa",
1456
+ "Pacific/Tongatapu",
1457
+ "Pacific/Wake",
1458
+ "Pacific/Wallis",
1459
+ "UTC"
1460
+ ]);
1461
+
1462
+ // src/api/application/users.ts
1463
+ var Users = class {
1464
+ r;
1465
+ constructor(requester) {
1466
+ this.r = requester;
1467
+ }
1468
+ list = async (opts, page = 1) => {
1469
+ z7.number().positive().parse(page);
1470
+ const { data } = await this.r.get("/users", {
1471
+ params: {
1472
+ include: opts.include?.join(","),
1473
+ page,
1474
+ ...ArrayQueryParams({ filters: opts.filters || {} }),
1475
+ sort: opts.sort?.id ? SortParam("id", opts.sort?.id) : SortParam("uuid", opts.sort?.uuid)
1476
+ }
1477
+ });
1478
+ return data.data.map((d) => d.attributes);
1479
+ };
1480
+ info = async (id, { include }) => {
1481
+ z7.number().positive().parse(id);
1482
+ const { data } = await this.r.get(`/users/${id}`, {
1483
+ params: { include: include?.join(",") }
1484
+ });
1485
+ return data.attributes;
1486
+ };
1487
+ infoByExternal = async (external_id, { include }) => {
1488
+ const { data } = await this.r.get(`/users/external/${external_id}`, {
1489
+ params: { include: include?.join(",") }
1490
+ });
1491
+ return data.attributes;
1492
+ };
1493
+ create = async (user) => {
1494
+ user = CreateSchema.parse(user);
1495
+ const { data } = await this.r.post("/users", user);
1496
+ return data.attributes;
1497
+ };
1498
+ update = async (id, user) => {
1499
+ user = CreateSchema.parse(user);
1500
+ const { data } = await this.r.patch(`/users/${id}`, user);
1501
+ return data.attributes;
1502
+ };
1503
+ delete = async (id) => {
1504
+ z7.number().positive().parse(id);
1505
+ await this.r.delete(`/users/${id}`);
1506
+ };
1507
+ addRoles = async (id, roles) => {
1508
+ z7.number().positive().parse(id);
1509
+ await this.r.patch(`/users/${id}/roles/assign`, { roles });
1510
+ };
1511
+ removeRoles = async (id, roles) => {
1512
+ z7.number().positive().parse(id);
1513
+ await this.r.patch(`/users/${id}/roles/remove`, { roles });
1514
+ };
1515
+ apiKeys = {
1516
+ list: async (id) => {
1517
+ const { data } = await this.r.get(`/users/${id}/api-keys`);
1518
+ return data.data.map((k) => k.attributes);
1519
+ },
1520
+ create: async (id, description, allowed_ips) => {
1521
+ allowed_ips = z7.array(z7.ipv4()).optional().parse(allowed_ips);
1522
+ const { data } = await this.r.post(`/users/${id}/api-keys`, { description, allowed_ips });
1523
+ return { ...data.attributes, secret_token: data.meta.secret_token };
1524
+ },
1525
+ delete: async (id, identifier) => {
1526
+ await this.r.delete(`/users/${id}/api-keys/${identifier}`);
1527
+ }
1528
+ };
1529
+ };
1530
+ var CreateSchema = z7.object({
1531
+ email: z7.email(),
1532
+ external_id: z7.string().max(255).optional(),
1533
+ username: z7.string().min(1).max(255),
1534
+ password: z7.string().optional(),
1535
+ language: languagesSchema,
1536
+ timezone: timezonesSchema
1537
+ });
1538
+
1539
+ // src/api/application/nodes_allocations.ts
1540
+ import z8 from "zod";
1541
+ var NodesAllocations = class {
1542
+ r;
1543
+ id;
1544
+ constructor(requester, id) {
1545
+ this.r = requester;
1546
+ this.id = id;
1547
+ }
1548
+ list = async (include) => {
1549
+ const { data } = await this.r.get(`/nodes/${this.id}/allocations`, {
1550
+ params: { include: include?.join(",") }
1551
+ });
1552
+ return data.data.map((d) => d.attributes);
1553
+ };
1554
+ create = async (ip, ports, alias) => {
1555
+ z8.ipv4().parse(ip);
1556
+ z8.ipv4().or(z8.url().max(255)).optional().parse(alias);
1557
+ z8.array(z8.number()).or(z8.string().regex(/\d+-\d+/)).parse(ports);
1558
+ await this.r.post(`/nodes/${this.id}/allocations`, {
1559
+ ip,
1560
+ ports,
1561
+ alias
1562
+ });
1563
+ };
1564
+ delete = async (alloc_id) => {
1565
+ await this.r.delete(`/nodes/${this.id}/allocations/${alloc_id}`);
1566
+ };
1567
+ };
1568
+
1569
+ // src/api/application/nodes.ts
1570
+ import z9 from "zod";
1571
+ var Nodes = class {
1572
+ r;
1573
+ constructor(requester) {
1574
+ this.r = requester;
1575
+ }
1576
+ list = async (include, page = 1) => {
1577
+ z9.number().positive().parse(page);
1578
+ const { data } = await this.r.get("/nodes", {
1579
+ params: { include: include?.join(","), page }
1580
+ });
1581
+ return data.data.map((s) => s.attributes);
1582
+ };
1583
+ listDeployable = async (filters, include, page = 1) => {
1584
+ z9.number().positive().parse(page);
1585
+ const { data } = await this.r.get("/nodes/deployable", {
1586
+ params: {
1587
+ include: include?.join(","),
1588
+ disk: filters.disk,
1589
+ memory: filters.memory,
1590
+ cpu: filters.cpu,
1591
+ location_ids: filters.location_ids,
1592
+ tags: filters.tags,
1593
+ page
1594
+ }
1595
+ });
1596
+ return data.data.map((s) => s.attributes);
1597
+ };
1598
+ info = async (id, include) => {
1599
+ z9.number().positive().parse(id);
1600
+ const { data } = await this.r.get(`/nodes/${id}`, {
1601
+ params: { include: include?.join(",") }
1602
+ });
1603
+ return data.attributes;
1604
+ };
1605
+ create = async (node) => {
1606
+ node = NodeCreateSchema.parse(node);
1607
+ const { data } = await this.r.post("/nodes", node);
1608
+ return data.attributes;
1609
+ };
1610
+ get_configuration = async (id) => {
1611
+ z9.number().positive().parse(id);
1612
+ const { data } = await this.r.get(`/nodes/${id}/configuration`);
1613
+ return data;
1614
+ };
1615
+ update = async (id, node) => {
1616
+ z9.number().positive().parse(id);
1617
+ node = NodeCreateSchema.parse(node);
1618
+ const { data } = await this.r.patch(`/nodes/${id}`, node);
1619
+ return data.attributes;
1620
+ };
1621
+ delete = async (id) => {
1622
+ z9.number().positive().parse(id);
1623
+ await this.r.delete(`/nodes/${id}`);
1624
+ };
1625
+ allocations = (server_id) => new NodesAllocations(this.r, server_id);
1626
+ };
1627
+ var NodeCreateSchema = z9.object({
1628
+ name: z9.string().min(1).max(100),
1629
+ description: z9.string().optional(),
1630
+ public: z9.boolean().optional(),
1631
+ fqdn: z9.string().nonempty(),
1632
+ scheme: z9.enum(["http", "https"]),
1633
+ behind_proxy: z9.boolean().optional(),
1634
+ memory: z9.number().min(0),
1635
+ memory_overallocate: z9.number().min(-1),
1636
+ disk: z9.number().min(0),
1637
+ disk_overallocate: z9.number().min(-1),
1638
+ cpu: z9.number().min(0),
1639
+ cpu_overallocate: z9.number().min(-1),
1640
+ daemon_base: z9.string().nonempty().optional(),
1641
+ daemon_sftp: z9.number().min(1).max(65535),
1642
+ daemon_sftp_alias: z9.string().optional(),
1643
+ daemon_listen: z9.number().min(1).max(65535),
1644
+ daemon_connect: z9.number().min(1).max(65535),
1645
+ maintenance_mode: z9.boolean().optional(),
1646
+ upload_size: z9.number().min(1).max(1024),
1647
+ tags: z9.array(z9.string()).optional()
1648
+ });
1649
+
1650
+ // src/api/application/servers.ts
1651
+ import z11 from "zod";
1652
+
1653
+ // src/api/application/servers_databases.ts
1654
+ import z10 from "zod";
1655
+ var ServersDatabases = class {
1656
+ r;
1657
+ id;
1658
+ constructor(r, server_id) {
1659
+ this.r = r;
1660
+ this.id = server_id;
1661
+ }
1662
+ list = async () => {
1663
+ const { data } = await this.r.get(`/servers/${this.id}/databases`);
1664
+ return data.data.map((d) => d.attributes);
1665
+ };
1666
+ create = async (database, remote, host) => {
1667
+ database = z10.string().min(1).max(48).parse(database);
1668
+ const { data } = await this.r.post(`/servers/${this.id}/databases`, { database, remote, host });
1669
+ return data.attributes;
1670
+ };
1671
+ info = async (database_id) => {
1672
+ const { data } = await this.r.get(`/servers/${this.id}/databases/${database_id}`);
1673
+ return data.attributes;
1674
+ };
1675
+ delete = async (database_id) => {
1676
+ await this.r.delete(`/servers/${this.id}/databases/${database_id}`);
1677
+ };
1678
+ resetPassword = async (database_id) => {
1679
+ await this.r.post(`/servers/${this.id}/databases/${database_id}/reset-password`);
1680
+ };
1681
+ };
1682
+
1683
+ // src/api/application/servers.ts
1684
+ var Servers = class {
1685
+ r;
1686
+ id;
1687
+ databases;
1688
+ constructor(r, server_id) {
1689
+ this.r = r;
1690
+ this.id = server_id;
1691
+ this.databases = new ServersDatabases(this.r, this.id);
1692
+ }
1693
+ info = async (include) => {
1694
+ const { data } = await this.r.get(`/servers/${this.id}`, {
1695
+ params: { include: include?.join(",") }
1696
+ });
1697
+ return data.attributes;
1698
+ };
1699
+ delete = async (force = false) => {
1700
+ await this.r.delete(`/servers/${this.id}${force ? "/force" : ""}`);
1701
+ };
1702
+ updateDetails = async (opts) => {
1703
+ opts = UpdateDetailsSchema.parse(opts);
1704
+ await this.r.patch(`/servers/${this.id}/details`, opts);
1705
+ };
1706
+ updateBuild = async (opts) => {
1707
+ opts = UpdateBuildSchema.parse(opts);
1708
+ await this.r.patch(`/servers/${this.id}/build`, opts);
1709
+ };
1710
+ updateStartup = async (opts) => {
1711
+ opts = UpdateStartupSchema.parse(opts);
1712
+ await this.r.patch(`/servers/${this.id}/startup`, opts);
1713
+ };
1714
+ suspend = async () => {
1715
+ await this.r.post(`/servers/${this.id}/suspend`);
1716
+ };
1717
+ unsuspend = async () => {
1718
+ await this.r.post(`/servers/${this.id}/unsuspend`);
1719
+ };
1720
+ reinstall = async () => {
1721
+ await this.r.post(`/servers/${this.id}/reinstall`);
1722
+ };
1723
+ transferStart = async (node_id, allocation_id, allocation_additional) => {
1724
+ await this.r.post(`/servers/${this.id}/transfer`, {
1725
+ node_id,
1726
+ allocation_id,
1727
+ allocation_additional
1728
+ });
1729
+ };
1730
+ transferCancel = async () => {
1731
+ await this.r.post(`/servers/${this.id}/transfer/cancel`);
1732
+ };
1733
+ };
1734
+ var CreateServerSchema = z11.object({
1735
+ external_id: z11.string().min(1).max(255).optional(),
1736
+ name: z11.string().min(1).max(255),
1737
+ description: z11.string().optional(),
1738
+ user: z11.number(),
1739
+ egg: z11.number(),
1740
+ docker_image: z11.string().optional(),
1741
+ startup: z11.string().optional(),
1742
+ environment: z11.record(z11.string(), z11.string()),
1743
+ skip_scripts: z11.boolean().optional(),
1744
+ oom_killer: z11.boolean().optional(),
1745
+ start_on_completion: z11.boolean().optional(),
1746
+ docker_labels: z11.record(z11.string(), z11.string()).optional(),
1747
+ limits: z11.object({
1748
+ memory: z11.number().min(0),
1749
+ swap: z11.number().min(-1),
1750
+ disk: z11.number().min(0),
1751
+ io: z11.number().min(0),
1752
+ threads: z11.string().optional(),
1753
+ cpu: z11.number().min(0)
1754
+ }),
1755
+ feature_limits: z11.object({
1756
+ databases: z11.number().min(0),
1757
+ allocations: z11.number().min(0),
1758
+ backups: z11.number().min(0)
1759
+ }),
1760
+ allocation: z11.object({
1761
+ default: z11.string(),
1762
+ additional: z11.array(z11.string()).optional()
1763
+ }).optional(),
1764
+ deploy: z11.object({
1765
+ tags: z11.array(z11.string()).optional(),
1766
+ dedicated_ip: z11.boolean().optional(),
1767
+ port_range: z11.array(z11.string()).optional()
1768
+ }).optional()
1769
+ });
1770
+ var UpdateDetailsSchema = CreateServerSchema.pick({
1771
+ external_id: true,
1772
+ name: true,
1773
+ user: true,
1774
+ description: true,
1775
+ docker_labels: true
1776
+ });
1777
+ var UpdateBuildSchema = CreateServerSchema.pick({
1778
+ oom_killer: true,
1779
+ limits: true,
1780
+ feature_limits: true
1781
+ }).extend({
1782
+ allocation: z11.number().optional(),
1783
+ add_allocations: z11.array(z11.string()).optional(),
1784
+ remove_allocations: z11.array(z11.string()).optional()
1785
+ });
1786
+ var UpdateStartupSchema = CreateServerSchema.pick({
1787
+ startup: true,
1788
+ environment: true,
1789
+ egg: true,
1790
+ skip_scripts: true
1791
+ }).extend({
1792
+ image: z11.string().optional()
1793
+ });
1794
+
1795
+ // src/api/application/database_hosts.ts
1796
+ import z12 from "zod";
1797
+ var DatabaseHosts = class {
1798
+ r;
1799
+ constructor(r) {
1800
+ this.r = r;
1801
+ }
1802
+ list = async (page = 1) => {
1803
+ const { data } = await this.r.get("/database-hosts", {
1804
+ params: { page }
1805
+ });
1806
+ return data.data.map((d) => d.attributes);
1807
+ };
1808
+ info = async (id) => {
1809
+ const { data } = await this.r.get(`/database-hosts/${id}`);
1810
+ return data.attributes;
1811
+ };
1812
+ // TODO: find out why API returns 500
1813
+ create = async (opts) => {
1814
+ opts = CreateDBHostSchema.parse(opts);
1815
+ await this.r.post("/database-hosts", opts).catch((e) => {
1816
+ });
1817
+ };
1818
+ update = async (id, opts) => {
1819
+ opts = CreateDBHostSchema.parse(opts);
1820
+ const { data } = await this.r.patch(`/database-hosts/${id}`, opts);
1821
+ return data.attributes;
1822
+ };
1823
+ delete = async (id) => {
1824
+ await this.r.delete(`/database-hosts/${id}`);
1825
+ };
1826
+ };
1827
+ var CreateDBHostSchema = z12.object({
1828
+ name: z12.string().min(1).max(255),
1829
+ host: z12.string(),
1830
+ port: z12.number().min(1).max(65535),
1831
+ username: z12.string().min(1).max(255),
1832
+ password: z12.string().optional(),
1833
+ node_ids: z12.array(z12.string()).optional(),
1834
+ max_databases: z12.number().optional()
1835
+ });
1836
+
1837
+ // src/api/application/roles.ts
1838
+ var Roles = class {
1839
+ r;
1840
+ constructor(r) {
1841
+ this.r = r;
1842
+ }
1843
+ list = async (page = 1) => {
1844
+ const { data } = await this.r.get(`/roles`, {
1845
+ params: { page }
1846
+ });
1847
+ return data.data.map((r) => r.attributes);
1848
+ };
1849
+ info = async (id) => {
1850
+ const { data } = await this.r.get(`/roles/${id}`);
1851
+ return data.attributes;
1852
+ };
1853
+ create = async (opts) => {
1854
+ await this.r.post(`/roles`, opts);
1855
+ };
1856
+ update = async (id, opts) => {
1857
+ await this.r.patch(`/roles/${id}`, opts);
1858
+ };
1859
+ delete = async (id) => {
1860
+ await this.r.delete(`/roles/${id}`);
1861
+ };
1862
+ };
1863
+
1864
+ // src/api/application/eggs.ts
1865
+ var Eggs = class {
1866
+ r;
1867
+ constructor(r) {
1868
+ this.r = r;
1869
+ }
1870
+ list = async () => {
1871
+ const { data } = await this.r.get("/eggs");
1872
+ return data.data.map((d) => d.attributes);
1873
+ };
1874
+ info = async (id) => {
1875
+ const { data } = await this.r.get(`/eggs/${id}`);
1876
+ return data.attributes;
1877
+ };
1878
+ export = async (id, format) => {
1879
+ const { data } = await this.r.get(`/eggs/${id}/export`, {
1880
+ params: { format },
1881
+ transformResponse: (r) => r
1882
+ });
1883
+ return data;
1884
+ };
1885
+ infoExportable = async (id) => {
1886
+ const { data } = await this.r.get(`/eggs/${id}/export`, { params: { format: "json" } });
1887
+ return data;
1888
+ };
1889
+ };
1890
+
1891
+ // src/api/application/mounts.ts
1892
+ import z13 from "zod";
1893
+ var Mounts = class {
1894
+ r;
1895
+ constructor(r) {
1896
+ this.r = r;
1897
+ }
1898
+ list = async () => {
1899
+ const { data } = await this.r.get("/mounts");
1900
+ return data.data.map((d) => d.attributes);
1901
+ };
1902
+ info = async (id) => {
1903
+ const { data } = await this.r.get(`/mounts/${id}`);
1904
+ return data.attributes;
1905
+ };
1906
+ create = async (opts) => {
1907
+ opts = CreateMountSchema.parse(opts);
1908
+ const { data } = await this.r.post("/mounts", opts);
1909
+ return data.attributes;
1910
+ };
1911
+ update = async (id, opts) => {
1912
+ opts = CreateMountSchema.parse(opts);
1913
+ const { data } = await this.r.patch(`/mounts/${id}`, opts);
1914
+ return data.attributes;
1915
+ };
1916
+ delete = async (id) => {
1917
+ await this.r.delete(`/mounts/${id}`);
1918
+ };
1919
+ listAssignedEggs = async (id) => {
1920
+ const { data } = await this.r.get(`/mounts/${id}/eggs`);
1921
+ return data.data.map((d) => d.attributes);
1922
+ };
1923
+ assignEggs = async (id, eggs) => {
1924
+ await this.r.post(`/mounts/${id}/eggs`, { eggs });
1925
+ };
1926
+ unassignEgg = async (id, egg_id) => {
1927
+ await this.r.delete(`/mounts/${id}/eggs/${egg_id}`);
1928
+ };
1929
+ listAssignedNodes = async (id) => {
1930
+ const { data } = await this.r.get(`/mounts/${id}/nodes`);
1931
+ return data.data.map((d) => d.attributes);
1932
+ };
1933
+ assignNodes = async (id, nodes) => {
1934
+ await this.r.post(`/mounts/${id}/nodes`, { nodes });
1935
+ };
1936
+ unassignNode = async (id, node_id) => {
1937
+ await this.r.delete(`/mounts/${id}/nodes/${node_id}`);
1938
+ };
1939
+ listAssignedServers = async (id) => {
1940
+ const { data } = await this.r.get(`/mounts/${id}/servers`);
1941
+ return data.data.map((d) => d.attributes);
1942
+ };
1943
+ assignServers = async (id, servers) => {
1944
+ await this.r.post(`/mounts/${id}/servers`, { servers });
1945
+ };
1946
+ unassignServer = async (id, server_id) => {
1947
+ await this.r.delete(`/mounts/${id}/servers/${server_id}`);
1948
+ };
1949
+ };
1950
+ var CreateMountSchema = z13.object({
1951
+ name: z13.string().min(1).max(255),
1952
+ description: z13.string().optional(),
1953
+ source: z13.string(),
1954
+ target: z13.string(),
1955
+ read_only: z13.boolean().optional()
1956
+ });
1957
+
1958
+ // src/api/application/client.ts
1959
+ var Client2 = class {
1960
+ r;
1961
+ users;
1962
+ nodes;
1963
+ databaseHosts;
1964
+ roles;
1965
+ eggs;
1966
+ mounts;
1967
+ constructor(requester) {
1968
+ this.r = requester;
1969
+ this.users = new Users(requester);
1970
+ this.nodes = new Nodes(requester);
1971
+ this.databaseHosts = new DatabaseHosts(requester);
1972
+ this.roles = new Roles(requester);
1973
+ this.eggs = new Eggs(requester);
1974
+ this.mounts = new Mounts(requester);
1975
+ }
1976
+ get $r() {
1977
+ return this.r;
1978
+ }
1979
+ listServers = async (search, page = 1) => {
1980
+ const { data } = await this.r.get("/servers", {
1981
+ params: { search, page }
1982
+ });
1983
+ return data.data.map((s) => s.attributes);
1984
+ };
1985
+ createServer = async (opts) => {
1986
+ opts = CreateServerSchema.parse(opts);
1987
+ const { data } = await this.r.post("/servers", opts);
1988
+ return data.attributes;
1989
+ };
1990
+ getServerByExternalId = async (external_id, include) => {
1991
+ const { data } = await this.r.get(`/servers/external/${external_id}`, {
1992
+ params: { include: include?.join(",") }
1993
+ });
1994
+ return data.attributes;
1995
+ };
1996
+ servers = (server_id) => new Servers(this.r, server_id);
1997
+ };
1998
+
1999
+ // src/api/base/request.ts
2000
+ import z14 from "zod";
2001
+ import axios3 from "axios";
2002
+
2003
+ // src/api/base/types.ts
2004
+ var PterodactylException = class extends Error {
2005
+ data;
2006
+ status;
2007
+ constructor(message, data, status) {
2008
+ super(message);
2009
+ this.data = data;
2010
+ this.status = status;
2011
+ }
2012
+ };
2013
+
2014
+ // src/api/base/request.ts
2015
+ var Agent = class {
2016
+ base_url;
2017
+ token;
2018
+ requester;
2019
+ constructor(url, token, type, suffix = "/api") {
2020
+ this.base_url = z14.url("Invalid URL Schema").transform((url2) => new URL(url2).href).parse(url);
2021
+ this.token = z14.string().regex(/^(ptl[ac]|pacc|papp)_.+$/, "Invalid token type").parse(token);
2022
+ this.requester = axios3.create({
2023
+ baseURL: this.base_url.replace(/\/+$/, "") + `${suffix}/${type}`,
2024
+ timeout: 3e3,
2025
+ headers: {
2026
+ Authorization: `Bearer ${this.token}`
2027
+ }
2028
+ });
2029
+ this.requester.interceptors.response.use(void 0, (error) => {
2030
+ if (error.response && error.response.status === 400) {
2031
+ return Promise.reject(new PterodactylException(
2032
+ "Invalid request data",
2033
+ error.response.data,
2034
+ error.response.status
2035
+ ));
2036
+ }
2037
+ return Promise.reject(error);
2038
+ });
2039
+ }
2040
+ };
2041
+
2042
+ // src/api/index.ts
2043
+ var PelicanAPIClient = class extends Client {
2044
+ constructor(url, token, suffix = "/api") {
2045
+ const ax = new Agent(url, token, "client", suffix);
2046
+ super(ax.requester);
2047
+ }
2048
+ };
2049
+ var PelicanAPIApplication = class extends Client2 {
2050
+ constructor(url, token, suffix = "/api") {
2051
+ const ax = new Agent(url, token, "application", suffix);
2052
+ super(ax.requester);
2053
+ }
2054
+ };
2055
+ export {
2056
+ PelicanAPIApplication,
2057
+ PelicanAPIClient
2058
+ };
2059
+ /*
2060
+ * @author BothimTV
2061
+ * @license MIT
2062
+ */