@pelican.ts/sdk 0.4.8 → 0.4.10

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.
Files changed (78) hide show
  1. package/.husky/pre-commit +2 -3
  2. package/biome.json +42 -32
  3. package/bun.lock +3 -0
  4. package/dist/api/index.d.mts +5 -5
  5. package/dist/api/index.d.ts +5 -5
  6. package/dist/api/index.js +168 -102
  7. package/dist/api/index.mjs +168 -102
  8. package/dist/index.d.mts +2 -2
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +124 -70
  11. package/dist/index.mjs +124 -70
  12. package/dist/types.d.ts +1 -1
  13. package/package.json +60 -59
  14. package/scripts/create-types.ts +4 -4
  15. package/src/api/application/client.ts +26 -19
  16. package/src/api/application/database_hosts.ts +15 -20
  17. package/src/api/application/eggs.ts +14 -7
  18. package/src/api/application/mounts.ts +29 -16
  19. package/src/api/application/nodes.ts +34 -32
  20. package/src/api/application/nodes_allocations.ts +15 -11
  21. package/src/api/application/roles.ts +13 -27
  22. package/src/api/application/servers.ts +36 -27
  23. package/src/api/application/servers_databases.ts +11 -7
  24. package/src/api/application/types/container.ts +7 -8
  25. package/src/api/application/types/database_host.ts +8 -8
  26. package/src/api/application/types/egg.ts +47 -54
  27. package/src/api/application/types/location.ts +5 -7
  28. package/src/api/application/types/mount.ts +9 -9
  29. package/src/api/application/types/node.ts +49 -59
  30. package/src/api/application/types/role.ts +4 -6
  31. package/src/api/application/types/server.ts +21 -22
  32. package/src/api/application/types/server_allocation.ts +11 -12
  33. package/src/api/application/types/user.ts +25 -25
  34. package/src/api/application/users.ts +38 -27
  35. package/src/api/base/request.ts +28 -17
  36. package/src/api/base/types.ts +16 -23
  37. package/src/api/client/account.ts +20 -15
  38. package/src/api/client/client.ts +17 -18
  39. package/src/api/client/server.ts +24 -20
  40. package/src/api/client/server_activity.ts +10 -11
  41. package/src/api/client/server_allocations.ts +11 -6
  42. package/src/api/client/server_backups.ts +21 -17
  43. package/src/api/client/server_databases.ts +14 -8
  44. package/src/api/client/server_files.ts +56 -42
  45. package/src/api/client/server_schedules.ts +43 -19
  46. package/src/api/client/server_settings.ts +11 -8
  47. package/src/api/client/server_startup.ts +16 -8
  48. package/src/api/client/server_users.ts +22 -13
  49. package/src/api/client/server_websocket.ts +79 -33
  50. package/src/api/client/types/server.ts +8 -18
  51. package/src/api/client/types/server_allocation.ts +7 -8
  52. package/src/api/client/types/server_subuser.ts +10 -11
  53. package/src/api/client/types/user.ts +2 -5
  54. package/src/api/client/types/websocket.ts +12 -24
  55. package/src/api/common/types/egg.ts +7 -7
  56. package/src/api/common/types/enums.ts +1 -1
  57. package/src/api/common/types/server_backup.ts +4 -5
  58. package/src/api/common/types/server_database.ts +9 -12
  59. package/src/api/common/types/server_files.ts +9 -9
  60. package/src/api/common/types/server_limits.ts +11 -12
  61. package/src/api/common/types/server_power.ts +1 -1
  62. package/src/api/common/types/server_schedule.ts +27 -25
  63. package/src/api/common/types/server_startup.ts +7 -12
  64. package/src/api/index.ts +3 -3
  65. package/src/humane/Account.ts +2 -2
  66. package/src/humane/Client.ts +6 -6
  67. package/src/humane/Server.ts +31 -43
  68. package/src/humane/ServerAllocation.ts +3 -3
  69. package/src/humane/ServerBackup.ts +6 -9
  70. package/src/humane/ServerDatabase.ts +2 -2
  71. package/src/humane/ServerFile.ts +17 -11
  72. package/src/humane/ServerSchedule.ts +6 -6
  73. package/src/humane/ServerUser.ts +2 -2
  74. package/src/index.ts +3 -3
  75. package/src/utils/sized.ts +1 -1
  76. package/src/utils/transform.ts +5 -10
  77. package/src/utils/types.ts +6 -8
  78. package/tsconfig.json +0 -1
package/dist/index.js CHANGED
@@ -136,29 +136,28 @@ var ServerFiles = class {
136
136
  this.id = id;
137
137
  }
138
138
  list = async (path2) => {
139
- const { data } = await this.r.get(`/servers/${this.id}/files/list`, {
140
- params: { directory: path2 }
141
- });
139
+ const { data } = await this.r.get(`/servers/${this.id}/files/list`, { params: { directory: path2 } });
142
140
  return data.data.map((r) => r.attributes);
143
141
  };
144
142
  /**
145
143
  * Return the contents of a file. To read binary file (non-editable) use {@link download} instead
146
144
  */
147
145
  contents = async (path2) => {
148
- const { data } = await this.r.get(`/servers/${this.id}/files/contents`, {
149
- params: { file: path2 }
150
- });
146
+ const { data } = await this.r.get(
147
+ `/servers/${this.id}/files/contents`,
148
+ { params: { file: path2 } }
149
+ );
151
150
  return data;
152
151
  };
153
152
  downloadGetUrl = async (path2) => {
154
- const { data } = await this.r.get(`/servers/${this.id}/files/download`, {
155
- params: { file: path2 }
156
- });
153
+ const { data } = await this.r.get(`/servers/${this.id}/files/download`, { params: { file: path2 } });
157
154
  return data.attributes.url;
158
155
  };
159
156
  download = async (path2) => {
160
157
  const url = await this.downloadGetUrl(path2);
161
- const { data } = await import_axios.default.get(url, { responseType: "arraybuffer" });
158
+ const { data } = await import_axios.default.get(url, {
159
+ responseType: "arraybuffer"
160
+ });
162
161
  return data;
163
162
  };
164
163
  rename = async (root = "/", files) => {
@@ -173,7 +172,12 @@ var ServerFiles = class {
173
172
  });
174
173
  };
175
174
  compress = async (root = "/", files, archive_name, extension) => {
176
- const { data } = await this.r.post(`/servers/${this.id}/files/compress`, { root, files, archive_name, extension });
175
+ const { data } = await this.r.post(`/servers/${this.id}/files/compress`, {
176
+ root,
177
+ files,
178
+ archive_name,
179
+ extension
180
+ });
177
181
  return data.attributes;
178
182
  };
179
183
  decompress = async (root = "/", file) => {
@@ -183,13 +187,22 @@ var ServerFiles = class {
183
187
  await this.r.post(`/servers/${this.id}/files/delete`, { root, files });
184
188
  };
185
189
  createFolder = async (root = "/", name) => {
186
- await this.r.post(`/servers/${this.id}/files/create-folder`, { root, name });
190
+ await this.r.post(`/servers/${this.id}/files/create-folder`, {
191
+ root,
192
+ name
193
+ });
187
194
  };
188
195
  chmod = async (root = "/", files) => {
189
196
  await this.r.post(`/servers/${this.id}/files/chmod`, { root, files });
190
197
  };
191
198
  pullFromRemote = async (url, directory, filename, use_header = false, foreground = false) => {
192
- await this.r.post(`/servers/${this.id}/files/pull`, { url, directory, filename, use_header, foreground });
199
+ await this.r.post(`/servers/${this.id}/files/pull`, {
200
+ url,
201
+ directory,
202
+ filename,
203
+ use_header,
204
+ foreground
205
+ });
193
206
  };
194
207
  uploadGetUrl = async () => {
195
208
  const { data } = await this.r.get(`/servers/${this.id}/files/upload`);
@@ -197,10 +210,14 @@ var ServerFiles = class {
197
210
  };
198
211
  upload = async (file, root = "/") => {
199
212
  const url = await this.uploadGetUrl();
200
- await import_axios.default.post(url, { files: file }, {
201
- headers: { "Content-Type": "multipart/form-data" },
202
- params: { directory: root }
203
- });
213
+ await import_axios.default.post(
214
+ url,
215
+ { files: file },
216
+ {
217
+ headers: { "Content-Type": "multipart/form-data" },
218
+ params: { directory: root }
219
+ }
220
+ );
204
221
  };
205
222
  };
206
223
 
@@ -243,7 +260,9 @@ var ScheduleControl = class {
243
260
  await this.r.delete(`/servers/${this.id}/schedules/${this.sched_id}`);
244
261
  };
245
262
  execute = async () => {
246
- await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}/execute`);
263
+ await this.r.post(
264
+ `/servers/${this.id}/schedules/${this.sched_id}/execute`
265
+ );
247
266
  };
248
267
  tasks = {
249
268
  create: async (opts) => {
@@ -251,11 +270,16 @@ var ScheduleControl = class {
251
270
  return data.attributes;
252
271
  },
253
272
  update: async (task_id, opts) => {
254
- const { data } = await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`, opts);
273
+ const { data } = await this.r.post(
274
+ `/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`,
275
+ opts
276
+ );
255
277
  return data.attributes;
256
278
  },
257
279
  delete: async (task_id) => {
258
- await this.r.delete(`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`);
280
+ await this.r.delete(
281
+ `/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`
282
+ );
259
283
  }
260
284
  };
261
285
  };
@@ -285,7 +309,9 @@ var ServerAllocations = class {
285
309
  return data.attributes;
286
310
  };
287
311
  unassign = async (alloc_id) => {
288
- await this.r.delete(`/servers/${this.id}/network/allocations/${alloc_id}`);
312
+ await this.r.delete(
313
+ `/servers/${this.id}/network/allocations/${alloc_id}`
314
+ );
289
315
  };
290
316
  };
291
317
 
@@ -306,11 +332,16 @@ var ServerUsers = class {
306
332
  return data.attributes;
307
333
  };
308
334
  info = async (user_uuid) => {
309
- const { data } = await this.r.get(`/servers/${this.id}/users/${user_uuid}`);
335
+ const { data } = await this.r.get(
336
+ `/servers/${this.id}/users/${user_uuid}`
337
+ );
310
338
  return data.attributes;
311
339
  };
312
340
  update = async (user_uuid, permissions) => {
313
- const { data } = await this.r.put(`/servers/${this.id}/users/${user_uuid}`, { permissions });
341
+ const { data } = await this.r.put(
342
+ `/servers/${this.id}/users/${user_uuid}`,
343
+ { permissions }
344
+ );
314
345
  return data.attributes;
315
346
  };
316
347
  delete = async (user_uuid) => {
@@ -330,9 +361,7 @@ var ServerBackups = class {
330
361
  }
331
362
  list = async (page = 1) => {
332
363
  import_zod3.default.number().positive().parse(page);
333
- const { data } = await this.r.get(`/servers/${this.id}/backups`, {
334
- params: { page }
335
- });
364
+ const { data } = await this.r.get(`/servers/${this.id}/backups`, { params: { page } });
336
365
  return data.data.map((d) => d.attributes);
337
366
  };
338
367
  create = async (args) => {
@@ -354,20 +383,27 @@ var ServerBackups = class {
354
383
  };
355
384
  download = async (backup_uuid) => {
356
385
  const url = await this.downloadGetUrl(backup_uuid);
357
- const { data } = await import_axios2.default.get(url, { responseType: "arraybuffer" });
386
+ const { data } = await import_axios2.default.get(url, {
387
+ responseType: "arraybuffer"
388
+ });
358
389
  return data;
359
390
  };
360
391
  delete = async (backup_uuid) => {
361
392
  await this.r.delete(`/servers/${this.id}/backups/${backup_uuid}`);
362
393
  };
363
394
  rename = async (backup_uuid, name) => {
364
- await this.r.put(`/servers/${this.id}/backups/${backup_uuid}/rename`, { name });
395
+ await this.r.put(`/servers/${this.id}/backups/${backup_uuid}/rename`, {
396
+ name
397
+ });
365
398
  };
366
399
  toggleLock = async (backup_uuid) => {
367
400
  await this.r.post(`/servers/${this.id}/backups/${backup_uuid}/lock`);
368
401
  };
369
402
  restore = async (backup_uuid, truncate) => {
370
- await this.r.post(`/servers/${this.id}/backups/${backup_uuid}/restore`, { truncate });
403
+ await this.r.post(
404
+ `/servers/${this.id}/backups/${backup_uuid}/restore`,
405
+ { truncate }
406
+ );
371
407
  };
372
408
  };
373
409
 
@@ -407,13 +443,15 @@ var ServerSettings = class {
407
443
  await this.r.post(`/servers/${this.id}/settings/rename`, { name });
408
444
  };
409
445
  updateDescription = async (description) => {
410
- await this.r.post(`/servers/${this.id}/settings/description`, { description });
446
+ await this.r.post(`/servers/${this.id}/settings/description`, {
447
+ description
448
+ });
411
449
  };
412
450
  reinstall = async () => {
413
451
  await this.r.post(`/servers/${this.id}/settings/reinstall`);
414
452
  };
415
453
  changeDockerImage = async (image) => {
416
- await this.r.post(`/servers/${this.id}/settings/docker-image`, { image });
454
+ await this.r.put(`/servers/${this.id}/settings/docker-image`, { image });
417
455
  };
418
456
  };
419
457
 
@@ -465,7 +503,9 @@ var ServerWebsocket = class {
465
503
  return;
466
504
  }
467
505
  const socketUrl = await this.refreshCredentials();
468
- this.socket = isBrowser ? new import_isomorphic_ws.default(socketUrl) : new import_isomorphic_ws.default(socketUrl, void 0, { origin: new URL(socketUrl).origin });
506
+ this.socket = isBrowser ? new import_isomorphic_ws.default(socketUrl) : new import_isomorphic_ws.default(socketUrl, void 0, {
507
+ origin: new URL(socketUrl).origin
508
+ });
469
509
  await new Promise((resolve, reject) => {
470
510
  const socket = this.socket;
471
511
  if (!socket) {
@@ -482,13 +522,17 @@ var ServerWebsocket = class {
482
522
  } catch (error) {
483
523
  socket.onopen = null;
484
524
  socket.onerror = null;
485
- reject(error instanceof Error ? error : new Error("Websocket authentication failed"));
525
+ reject(
526
+ error instanceof Error ? error : new Error("Websocket authentication failed")
527
+ );
486
528
  }
487
529
  };
488
530
  socket.onerror = (event) => {
489
531
  socket.onopen = null;
490
532
  socket.onerror = null;
491
- reject(event instanceof Error ? event : new Error("Websocket connection error"));
533
+ reject(
534
+ event instanceof Error ? event : new Error("Websocket connection error")
535
+ );
492
536
  };
493
537
  });
494
538
  if (resumable) {
@@ -534,9 +578,15 @@ var ServerWebsocket = class {
534
578
  void this.handleIncomingMessage(event);
535
579
  };
536
580
  if (typeof this.socket.addEventListener === "function") {
537
- this.socket.addEventListener("message", handler);
581
+ this.socket.addEventListener(
582
+ "message",
583
+ handler
584
+ );
538
585
  this.detachMessageListener = () => {
539
- this.socket?.removeEventListener?.("message", handler);
586
+ this.socket?.removeEventListener?.(
587
+ "message",
588
+ handler
589
+ );
540
590
  };
541
591
  } else {
542
592
  const fallback = (data) => handler({ data });
@@ -646,7 +696,9 @@ var ServerWebsocket = class {
646
696
  }
647
697
  case "backup completed" /* BACKUP_COMPLETED */: {
648
698
  try {
649
- const payload = JSON.parse(message.args[0]);
699
+ const payload = JSON.parse(
700
+ message.args[0]
701
+ );
650
702
  this.emit("backup completed" /* BACKUP_COMPLETED */, payload);
651
703
  } catch (error) {
652
704
  if (this.debugLogging) {
@@ -728,7 +780,9 @@ var ServerWebsocket = class {
728
780
  }
729
781
  }
730
782
  async refreshCredentials() {
731
- const { data } = await this.r.get(`/servers/${this.serverId}/websocket`);
783
+ const { data } = await this.r.get(
784
+ `/servers/${this.serverId}/websocket`
785
+ );
732
786
  this.currentToken = data.data.token;
733
787
  return data.data.socket;
734
788
  }
@@ -739,7 +793,9 @@ var ServerWebsocket = class {
739
793
  if (!this.currentToken) {
740
794
  throw new Error("Missing websocket token");
741
795
  }
742
- this.socket.send(JSON.stringify({ event: "auth", args: [this.currentToken] }));
796
+ this.socket.send(
797
+ JSON.stringify({ event: "auth", args: [this.currentToken] })
798
+ );
743
799
  }
744
800
  disconnect() {
745
801
  this.detachMessageListener?.();
@@ -758,7 +814,9 @@ var ServerWebsocket = class {
758
814
  send(event, args) {
759
815
  if (!this.socket) {
760
816
  if (this.debugLogging) {
761
- console.warn(`Attempted to send "${event}" without an active websocket connection`);
817
+ console.warn(
818
+ `Attempted to send "${event}" without an active websocket connection`
819
+ );
762
820
  }
763
821
  return;
764
822
  }
@@ -839,12 +897,7 @@ var ServerActivity = class {
839
897
  this.id = id;
840
898
  }
841
899
  list = async (page = 1, per_page = 25) => {
842
- const { data } = await this.r.get(`/server/${this.id}/activity`, {
843
- params: {
844
- page,
845
- per_page
846
- }
847
- });
900
+ const { data } = await this.r.get(`/server/${this.id}/activity`, { params: { page, per_page } });
848
901
  return data.data.map((log) => log.attributes);
849
902
  };
850
903
  };
@@ -878,16 +931,19 @@ var ServerClient = class {
878
931
  this.settings = new ServerSettings(requester, id);
879
932
  }
880
933
  info = async (include) => {
881
- const { data } = await this.r.get(`/servers/${this.id}`, {
882
- params: { include: include?.join(",") }
883
- });
934
+ const { data } = await this.r.get(
935
+ `/servers/${this.id}`,
936
+ { params: { include: include?.join(",") } }
937
+ );
884
938
  return data.attributes;
885
939
  };
886
940
  websocket = (stripColors = false) => {
887
941
  return new ServerWebsocket(this.r, this.id, stripColors);
888
942
  };
889
943
  resources = async () => {
890
- const { data } = await this.r.get(`/servers/${this.id}/resources`);
944
+ const { data } = await this.r.get(
945
+ `/servers/${this.id}/resources`
946
+ );
891
947
  return data.attributes;
892
948
  };
893
949
  command = async (command) => {
@@ -915,9 +971,7 @@ var Client = class {
915
971
  };
916
972
  listServers = async (type = "accessible", page = 1, per_page = 50, include) => {
917
973
  import_zod5.default.number().positive().parse(page);
918
- const { data } = await this.r.get("/", {
919
- params: { type, page, include: include?.join(",") }
920
- });
974
+ const { data } = await this.r.get("/", { params: { type, page, include: include?.join(",") } });
921
975
  return data.data.map((s) => s.attributes);
922
976
  };
923
977
  server = (uuid) => new ServerClient(this.r, uuid);
@@ -1588,9 +1642,7 @@ var UpdateStartupSchema = CreateServerSchema.pick({
1588
1642
  environment: true,
1589
1643
  egg: true,
1590
1644
  skip_scripts: true
1591
- }).extend({
1592
- image: import_zod11.default.string().optional()
1593
- });
1645
+ }).extend({ image: import_zod11.default.string().optional() });
1594
1646
 
1595
1647
  // src/api/application/database_hosts.ts
1596
1648
  var import_zod12 = __toESM(require("zod"));
@@ -1640,17 +1692,17 @@ var Agent = class {
1640
1692
  this.requester = import_axios3.default.create({
1641
1693
  baseURL: this.base_url.replace(/\/+$/, "") + `${suffix}/${type}`,
1642
1694
  timeout: 3e3,
1643
- headers: {
1644
- Authorization: `Bearer ${this.token}`
1645
- }
1695
+ headers: { Authorization: `Bearer ${this.token}` }
1646
1696
  });
1647
1697
  this.requester.interceptors.response.use(void 0, (error) => {
1648
1698
  if (error.response && error.response.status === 400) {
1649
- return Promise.reject(new PterodactylException(
1650
- "Invalid request data",
1651
- error.response.data,
1652
- error.response.status
1653
- ));
1699
+ return Promise.reject(
1700
+ new PterodactylException(
1701
+ "Invalid request data",
1702
+ error.response.data,
1703
+ error.response.status
1704
+ )
1705
+ );
1654
1706
  }
1655
1707
  return Promise.reject(error);
1656
1708
  });
@@ -1860,7 +1912,12 @@ var ServerFile = class _ServerFile {
1860
1912
  write = async (content) => this.client.files.write(this.path, content);
1861
1913
  compress = async (archive_name, extension) => new _ServerFile(
1862
1914
  this.client,
1863
- await this.client.files.compress(this.dir, [this.name], archive_name, extension)
1915
+ await this.client.files.compress(
1916
+ this.dir,
1917
+ [this.name],
1918
+ archive_name,
1919
+ extension
1920
+ )
1864
1921
  );
1865
1922
  decompress = async () => this.client.files.decompress(this.dir, this.name);
1866
1923
  delete = async () => this.client.files.delete(this.dir, [this.name]);
@@ -2105,10 +2162,7 @@ var Server = class {
2105
2162
  getServerStats = async () => this.client.resources();
2106
2163
  runCommand = async (command) => this.client.command(command);
2107
2164
  sendPowerSignal = async (signal) => this.client.power(signal);
2108
- getDatabases = async (opts = {
2109
- include: [],
2110
- page: 1
2111
- }) => {
2165
+ getDatabases = async (opts = { include: [], page: 1 }) => {
2112
2166
  const data = await this.client.databases.list(opts.include, opts.page);
2113
2167
  return data.map((d) => new ServerDatabase(this.client, d));
2114
2168
  };
@@ -2142,7 +2196,7 @@ var Server = class {
2142
2196
  };
2143
2197
  getFiles = async (path2) => {
2144
2198
  const data = await this.client.files.list(path2);
2145
- return data.map((d) => new ServerFile(this.client, d));
2199
+ return data.map((d) => new ServerFile(this.client, d, path2));
2146
2200
  };
2147
2201
  createFolder = async (...opts) => this.client.files.createFolder(...opts);
2148
2202
  uploadFile = async (...opts) => this.client.files.upload(...opts);