@pelican.ts/sdk 0.4.15 → 0.4.16-next.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.
package/dist/index.d.ts CHANGED
@@ -1,17 +1,7 @@
1
1
  import { AxiosInstance } from 'axios';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
 
4
- type FileObject = {
5
- name: string;
6
- mode: string;
7
- mode_bits: string;
8
- size: number;
9
- is_file: boolean;
10
- is_symlink: boolean;
11
- mimetype: string;
12
- created_at: string;
13
- modified_at: string;
14
- };
4
+ type ServerSignalOption = "start" | "stop" | "restart" | "kill";
15
5
 
16
6
  type GenericResponse<T, N extends string = string, M = undefined> = {
17
7
  object: N;
@@ -24,7 +14,7 @@ type PaginationMeta = {
24
14
  per_page: number;
25
15
  current_page: number;
26
16
  total_pages: number;
27
- links: any;
17
+ links: unknown;
28
18
  };
29
19
  type GenericListResponse<T> = {
30
20
  object: "list";
@@ -59,20 +49,6 @@ type ServerDatabase$1 = {
59
49
  type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
60
50
  type Nullable<T> = T | null;
61
51
 
62
- type ServerBackup$1 = {
63
- uuid: string;
64
- is_successful: boolean;
65
- is_locked: boolean;
66
- name: string;
67
- ignored_files: string[];
68
- checksum: Nullable<string>;
69
- bytes: number;
70
- created_at: string;
71
- completed_at: Nullable<string>;
72
- };
73
-
74
- type ServerSignalOption = "start" | "stop" | "restart" | "kill";
75
-
76
52
  type ServerLimits = {
77
53
  memory: number;
78
54
  swap: number;
@@ -103,6 +79,40 @@ type StartupMeta = {
103
79
  raw_startup_command: string;
104
80
  };
105
81
 
82
+ type ServerBackup$1 = {
83
+ uuid: string;
84
+ is_successful: boolean;
85
+ is_locked: boolean;
86
+ name: string;
87
+ ignored_files: string[];
88
+ checksum: Nullable<string>;
89
+ bytes: number;
90
+ created_at: string;
91
+ completed_at: Nullable<string>;
92
+ };
93
+
94
+ type EggVariable = {
95
+ name: string;
96
+ description: string;
97
+ env_variable: string;
98
+ default_value: string;
99
+ server_value: string;
100
+ is_editable: boolean;
101
+ rules: string;
102
+ };
103
+
104
+ type FileObject = {
105
+ name: string;
106
+ mode: string;
107
+ mode_bits: string;
108
+ size: number;
109
+ is_file: boolean;
110
+ is_symlink: boolean;
111
+ mimetype: string;
112
+ created_at: string;
113
+ modified_at: string;
114
+ };
115
+
106
116
  type Schedule = {
107
117
  id: number;
108
118
  name: string;
@@ -135,14 +145,110 @@ type ScheduleTask = {
135
145
  updated_at: Nullable<string>;
136
146
  };
137
147
 
138
- type EggVariable = {
139
- name: string;
140
- description: string;
141
- env_variable: string;
142
- default_value: string;
143
- server_value: string;
144
- is_editable: boolean;
145
- rules: string;
148
+ type SocketEventPayloadMap = {
149
+ [SOCKET_EVENT.AUTH_SUCCESS]: undefined;
150
+ [SOCKET_EVENT.STATUS]: PowerState;
151
+ [SOCKET_EVENT.CONSOLE_OUTPUT]: string;
152
+ [SOCKET_EVENT.STATS]: StatsWsJson;
153
+ [SOCKET_EVENT.DAEMON_ERROR]: undefined;
154
+ [SOCKET_EVENT.DAEMON_MESSAGE]: string;
155
+ [SOCKET_EVENT.INSTALL_OUTPUT]: string;
156
+ [SOCKET_EVENT.INSTALL_STARTED]: undefined;
157
+ [SOCKET_EVENT.INSTALL_COMPLETED]: undefined;
158
+ [SOCKET_EVENT.TRANSFER_LOGS]: string;
159
+ [SOCKET_EVENT.TRANSFER_STATUS]: string;
160
+ [SOCKET_EVENT.BACKUP_COMPLETED]: BackupCompletedJson;
161
+ [SOCKET_EVENT.BACKUP_RESTORE_COMPLETED]: undefined;
162
+ [SOCKET_EVENT.TOKEN_EXPIRING]: undefined;
163
+ [SOCKET_EVENT.TOKEN_EXPIRED]: undefined;
164
+ [SOCKET_EVENT.JWT_ERROR]: string;
165
+ };
166
+ type Listener<E extends SOCKET_EVENT> = SocketEventPayloadMap[E] extends undefined ? () => void : (payload: SocketEventPayloadMap[E]) => void;
167
+ type CloseEventLike = Parameters<NonNullable<WebSocket["onclose"]>>[0];
168
+ type ErrorEventLike = Parameters<NonNullable<WebSocket["onerror"]>>[0];
169
+ declare class ServerWebsocket {
170
+ private readonly r;
171
+ private readonly serverId;
172
+ private socket?;
173
+ private currentToken?;
174
+ private readonly bus;
175
+ private debugLogging;
176
+ private stripColors;
177
+ private detachMessageListener?;
178
+ constructor(requester: AxiosInstance, id: string, stripColors?: boolean);
179
+ on<E extends SOCKET_EVENT>(event: E, listener: Listener<E>): () => void;
180
+ deregister<E extends SOCKET_EVENT>(event: E, listener: Listener<E>): void;
181
+ private emit;
182
+ connect(resumable?: boolean, debugLogging?: boolean): Promise<void>;
183
+ onSocketDisconnect(handler: (event: CloseEventLike) => void): void;
184
+ onSocketError(handler: (event: ErrorEventLike) => void): void;
185
+ makeResumable(disconnectsToo: boolean): void;
186
+ private attachMessageListener;
187
+ private handleIncomingMessage;
188
+ private parseMessage;
189
+ private normalisePayload;
190
+ private dispatchMessage;
191
+ private refreshCredentials;
192
+ private authenticate;
193
+ disconnect(): void;
194
+ requestStats(): void;
195
+ requestLogs(): void;
196
+ private send;
197
+ getStats(): Promise<StatsWsJson>;
198
+ getLogs(): Promise<string[]>;
199
+ sendPoweraction(action: ServerSignalOption): void;
200
+ sendCommand(cmd: string): void;
201
+ }
202
+
203
+ /**
204
+ * Source: https://github.com/pterodactyl/panel/blob/1.0-develop/resources/scripts/components/server/events.ts
205
+ */
206
+ declare enum SOCKET_EVENT {
207
+ AUTH_SUCCESS = "auth success",
208
+ DAEMON_MESSAGE = "daemon message",
209
+ DAEMON_ERROR = "daemon error",
210
+ INSTALL_OUTPUT = "install output",
211
+ INSTALL_STARTED = "install started",
212
+ INSTALL_COMPLETED = "install completed",
213
+ CONSOLE_OUTPUT = "console output",
214
+ STATUS = "status",
215
+ STATS = "stats",
216
+ TRANSFER_LOGS = "transfer logs",
217
+ TRANSFER_STATUS = "transfer status",
218
+ BACKUP_COMPLETED = "backup completed",
219
+ BACKUP_RESTORE_COMPLETED = "backup restore completed",
220
+ TOKEN_EXPIRING = "token expiring",
221
+ TOKEN_EXPIRED = "token expired",
222
+ JWT_ERROR = "jwt error"
223
+ }
224
+ type BackupCompletedJson = {
225
+ checksum: string;
226
+ checksum_type: "sha1";
227
+ file_size: number;
228
+ is_successful: boolean;
229
+ uuid: string;
230
+ };
231
+ type PowerState = "starting" | "stopping" | "running" | "offline";
232
+ type StatsWsJson = {
233
+ memory_bytes: number;
234
+ memory_limit_bytes: number;
235
+ cpu_absolute: number;
236
+ network: {
237
+ rx_bytes: number;
238
+ tx_bytes: number;
239
+ };
240
+ state: PowerState;
241
+ uptime: number;
242
+ disk_bytes: number;
243
+ };
244
+
245
+ type ServerAllocation$1 = {
246
+ id: number;
247
+ ip: string;
248
+ ip_alias: Nullable<string>;
249
+ port: number;
250
+ notes: Nullable<string>;
251
+ is_default: boolean;
146
252
  };
147
253
 
148
254
  type ServerSubuser = {
@@ -159,15 +265,6 @@ type ServerSubuser = {
159
265
  };
160
266
  type SubuserPermission = "activity.read" | "allocation.create" | "allocation.delete" | "allocation.read" | "allocation.update" | "backup.create" | "backup.delete" | "backup.download" | "backup.read" | "backup.restore" | "control.console" | "control.restart" | "control.start" | "control.stop" | "database.create" | "database.delete" | "database.read" | "database.update" | "database.view-password" | "file.archive" | "file.create" | "file.delete" | "file.read" | "file.read-content" | "file.sftp" | "file.update" | "schedule.create" | "schedule.delete" | "schedule.read" | "schedule.update" | "settings.description" | "settings.reinstall" | "settings.rename" | "startup.docker-image" | "startup.read" | "startup.update" | "user.create" | "user.delete" | "user.read" | "user.update" | "websocket.connect";
161
267
 
162
- type ServerAllocation$1 = {
163
- id: number;
164
- ip: string;
165
- ip_alias: Nullable<string>;
166
- port: number;
167
- notes: Nullable<string>;
168
- is_default: boolean;
169
- };
170
-
171
268
  type Server$1 = {
172
269
  server_owner: boolean;
173
270
  identifier: string;
@@ -255,103 +352,6 @@ type Permission = {
255
352
  keys: Record<string, string>;
256
353
  };
257
354
 
258
- type SocketEventPayloadMap = {
259
- [SOCKET_EVENT.AUTH_SUCCESS]: undefined;
260
- [SOCKET_EVENT.STATUS]: PowerState;
261
- [SOCKET_EVENT.CONSOLE_OUTPUT]: string;
262
- [SOCKET_EVENT.STATS]: StatsWsJson;
263
- [SOCKET_EVENT.DAEMON_ERROR]: undefined;
264
- [SOCKET_EVENT.DAEMON_MESSAGE]: string;
265
- [SOCKET_EVENT.INSTALL_OUTPUT]: string;
266
- [SOCKET_EVENT.INSTALL_STARTED]: undefined;
267
- [SOCKET_EVENT.INSTALL_COMPLETED]: undefined;
268
- [SOCKET_EVENT.TRANSFER_LOGS]: string;
269
- [SOCKET_EVENT.TRANSFER_STATUS]: string;
270
- [SOCKET_EVENT.BACKUP_COMPLETED]: BackupCompletedJson;
271
- [SOCKET_EVENT.BACKUP_RESTORE_COMPLETED]: undefined;
272
- [SOCKET_EVENT.TOKEN_EXPIRING]: undefined;
273
- [SOCKET_EVENT.TOKEN_EXPIRED]: undefined;
274
- [SOCKET_EVENT.JWT_ERROR]: string;
275
- };
276
- type Listener<E extends SOCKET_EVENT> = SocketEventPayloadMap[E] extends undefined ? () => void : (payload: SocketEventPayloadMap[E]) => void;
277
- type CloseEventLike = Parameters<NonNullable<WebSocket["onclose"]>>[0];
278
- type ErrorEventLike = Parameters<NonNullable<WebSocket["onerror"]>>[0];
279
- declare class ServerWebsocket {
280
- private readonly r;
281
- private readonly serverId;
282
- private socket?;
283
- private currentToken?;
284
- private readonly bus;
285
- private debugLogging;
286
- private stripColors;
287
- private detachMessageListener?;
288
- constructor(requester: AxiosInstance, id: string, stripColors?: boolean);
289
- on<E extends SOCKET_EVENT>(event: E, listener: Listener<E>): () => void;
290
- deregister<E extends SOCKET_EVENT>(event: E, listener: Listener<E>): void;
291
- private emit;
292
- connect(resumable?: boolean, debugLogging?: boolean): Promise<void>;
293
- onSocketDisconnect(handler: (event: CloseEventLike) => void): void;
294
- onSocketError(handler: (event: ErrorEventLike) => void): void;
295
- makeResumable(disconnectsToo: boolean): void;
296
- private attachMessageListener;
297
- private handleIncomingMessage;
298
- private parseMessage;
299
- private normalisePayload;
300
- private dispatchMessage;
301
- private refreshCredentials;
302
- private authenticate;
303
- disconnect(): void;
304
- requestStats(): void;
305
- requestLogs(): void;
306
- private send;
307
- getStats(): Promise<StatsWsJson>;
308
- getLogs(): Promise<string[]>;
309
- sendPoweraction(action: ServerSignalOption): void;
310
- sendCommand(cmd: string): void;
311
- }
312
-
313
- /**
314
- * Source: https://github.com/pterodactyl/panel/blob/1.0-develop/resources/scripts/components/server/events.ts
315
- */
316
- declare enum SOCKET_EVENT {
317
- AUTH_SUCCESS = "auth success",
318
- DAEMON_MESSAGE = "daemon message",
319
- DAEMON_ERROR = "daemon error",
320
- INSTALL_OUTPUT = "install output",
321
- INSTALL_STARTED = "install started",
322
- INSTALL_COMPLETED = "install completed",
323
- CONSOLE_OUTPUT = "console output",
324
- STATUS = "status",
325
- STATS = "stats",
326
- TRANSFER_LOGS = "transfer logs",
327
- TRANSFER_STATUS = "transfer status",
328
- BACKUP_COMPLETED = "backup completed",
329
- BACKUP_RESTORE_COMPLETED = "backup restore completed",
330
- TOKEN_EXPIRING = "token expiring",
331
- TOKEN_EXPIRED = "token expired",
332
- JWT_ERROR = "jwt error"
333
- }
334
- type BackupCompletedJson = {
335
- checksum: string;
336
- checksum_type: "sha1";
337
- file_size: number;
338
- is_successful: boolean;
339
- uuid: string;
340
- };
341
- type PowerState = "starting" | "stopping" | "running" | "offline";
342
- type StatsWsJson = {
343
- memory_bytes: number;
344
- memory_limit_bytes: number;
345
- cpu_absolute: number;
346
- network: {
347
- rx_bytes: number;
348
- tx_bytes: number;
349
- };
350
- state: PowerState;
351
- uptime: number;
352
- disk_bytes: number;
353
- };
354
-
355
355
  declare class Account$1 {
356
356
  private readonly r;
357
357
  constructor(requester: AxiosInstance);
@@ -372,6 +372,43 @@ declare class Account$1 {
372
372
  };
373
373
  }
374
374
 
375
+ declare class ServerActivity {
376
+ private readonly r;
377
+ private readonly id;
378
+ constructor(r: AxiosInstance, id: string);
379
+ list: (page?: number, per_page?: number) => Promise<ServerActivityLog[]>;
380
+ }
381
+
382
+ declare class ServerAllocations {
383
+ private readonly r;
384
+ private readonly id;
385
+ constructor(requester: AxiosInstance, id: string);
386
+ list: () => Promise<ServerAllocation$1[]>;
387
+ autoAssign: () => Promise<ServerAllocation$1>;
388
+ setNotes: (alloc_id: number, notes: string) => Promise<ServerAllocation$1>;
389
+ setPrimary: (alloc_id: number) => Promise<ServerAllocation$1>;
390
+ unassign: (alloc_id: number) => Promise<void>;
391
+ }
392
+
393
+ declare class ServerBackups {
394
+ private readonly r;
395
+ private readonly id;
396
+ constructor(requester: AxiosInstance, id: string);
397
+ list: (page?: number) => Promise<ServerBackup$1[]>;
398
+ create: (args: {
399
+ name?: string;
400
+ is_locked: boolean;
401
+ ignored_files: string[];
402
+ }) => Promise<ServerBackup$1>;
403
+ info: (backup_uuid: string) => Promise<ServerBackup$1>;
404
+ downloadGetUrl: (backup_uuid: string) => Promise<string>;
405
+ download: (backup_uuid: string) => Promise<ArrayBuffer>;
406
+ delete: (backup_uuid: string) => Promise<void>;
407
+ rename: (backup_uuid: string, name: string) => Promise<void>;
408
+ toggleLock: (backup_uuid: string) => Promise<void>;
409
+ restore: (backup_uuid: string, truncate: boolean) => Promise<void>;
410
+ }
411
+
375
412
  declare class ServerDatabases {
376
413
  private readonly r;
377
414
  private readonly id;
@@ -448,45 +485,14 @@ declare class ScheduleControl {
448
485
  };
449
486
  }
450
487
 
451
- declare class ServerAllocations {
452
- private readonly r;
453
- private readonly id;
454
- constructor(requester: AxiosInstance, id: string);
455
- list: () => Promise<ServerAllocation$1[]>;
456
- autoAssign: () => Promise<ServerAllocation$1>;
457
- setNotes: (alloc_id: number, notes: string) => Promise<ServerAllocation$1>;
458
- setPrimary: (alloc_id: number) => Promise<ServerAllocation$1>;
459
- unassign: (alloc_id: number) => Promise<void>;
460
- }
461
-
462
- declare class ServerUsers {
463
- private readonly r;
464
- private readonly id;
465
- constructor(requester: AxiosInstance, id: string);
466
- list: () => Promise<ServerSubuser[]>;
467
- create: (email: string, permissions: SubuserPermission[] | string[]) => Promise<ServerSubuser>;
468
- info: (user_uuid: string) => Promise<ServerSubuser>;
469
- update: (user_uuid: string, permissions: SubuserPermission[] | string[]) => Promise<ServerSubuser>;
470
- delete: (user_uuid: string) => Promise<void>;
471
- }
472
-
473
- declare class ServerBackups {
488
+ declare class ServerSettings {
474
489
  private readonly r;
475
490
  private readonly id;
476
491
  constructor(requester: AxiosInstance, id: string);
477
- list: (page?: number) => Promise<ServerBackup$1[]>;
478
- create: (args: {
479
- name?: string;
480
- is_locked: boolean;
481
- ignored_files: string[];
482
- }) => Promise<ServerBackup$1>;
483
- info: (backup_uuid: string) => Promise<ServerBackup$1>;
484
- downloadGetUrl: (backup_uuid: string) => Promise<string>;
485
- download: (backup_uuid: string) => Promise<ArrayBuffer>;
486
- delete: (backup_uuid: string) => Promise<void>;
487
- rename: (backup_uuid: string, name: string) => Promise<void>;
488
- toggleLock: (backup_uuid: string) => Promise<void>;
489
- restore: (backup_uuid: string, truncate: boolean) => Promise<void>;
492
+ rename: (name: string) => Promise<void>;
493
+ updateDescription: (description: Nullable<string>) => Promise<void>;
494
+ reinstall: () => Promise<void>;
495
+ changeDockerImage: (image: string) => Promise<void>;
490
496
  }
491
497
 
492
498
  declare class ServerStartup {
@@ -497,21 +503,15 @@ declare class ServerStartup {
497
503
  set: (key: string, value: string) => Promise<StartupParams>;
498
504
  }
499
505
 
500
- declare class ServerSettings {
506
+ declare class ServerUsers {
501
507
  private readonly r;
502
508
  private readonly id;
503
509
  constructor(requester: AxiosInstance, id: string);
504
- rename: (name: string) => Promise<void>;
505
- updateDescription: (description: Nullable<string>) => Promise<void>;
506
- reinstall: () => Promise<void>;
507
- changeDockerImage: (image: string) => Promise<void>;
508
- }
509
-
510
- declare class ServerActivity {
511
- private readonly r;
512
- private readonly id;
513
- constructor(r: AxiosInstance, id: string);
514
- list: (page?: number, per_page?: number) => Promise<ServerActivityLog[]>;
510
+ list: () => Promise<ServerSubuser[]>;
511
+ create: (email: string, permissions: SubuserPermission[] | string[]) => Promise<ServerSubuser>;
512
+ info: (user_uuid: string) => Promise<ServerSubuser>;
513
+ update: (user_uuid: string, permissions: SubuserPermission[] | string[]) => Promise<ServerSubuser>;
514
+ delete: (user_uuid: string) => Promise<void>;
515
515
  }
516
516
 
517
517
  declare class ServerClient {
@@ -545,6 +545,19 @@ declare class Client$1 {
545
545
  server: (uuid: string) => ServerClient;
546
546
  }
547
547
 
548
+ /**
549
+ * Instance of a Humane Pelican User
550
+ *
551
+ * @class
552
+ * @example
553
+ * You can create account from a raw client
554
+ * ```ts
555
+ * import {PelicanAPIClient} from "@pelican.ts/sdk/api"
556
+ * const client = new PelicanAPIClient(...)
557
+ * const userData = await client.account.info()
558
+ * const account = new Account(client, userData)
559
+ * ```
560
+ */
548
561
  declare class Account {
549
562
  private readonly client;
550
563
  readonly uuid: string;
@@ -734,14 +747,40 @@ declare class ServerUser {
734
747
  delete: () => Promise<void>;
735
748
  }
736
749
 
750
+ /**
751
+ * Instance of a Humane Pelican Server
752
+ *
753
+ * @class
754
+ * @example
755
+ * You can create account from a raw client
756
+ * ```ts
757
+ * import {PelicanAPIClient} from "@pelican.ts/sdk/api"
758
+ * const client = new PelicanAPIClient(...)
759
+ * const serverData = await client.account.server(...).info()
760
+ * const server = new Server(client, serverData)
761
+ * ```
762
+ */
737
763
  declare class Server {
738
764
  private readonly client;
765
+ /**
766
+ * Whether the user owns the server
767
+ *
768
+ * @remarks
769
+ * Useful for gatekeeping features from subusers
770
+ */
739
771
  readonly ownsServer: boolean;
740
772
  readonly identifier: string;
773
+ /**
774
+ * ID used by Pelican Application API
775
+ */
741
776
  readonly internalId?: number;
742
777
  readonly uuid: string;
743
778
  private $name;
744
779
  get name(): string;
780
+ /**
781
+ * Node name used by this server
782
+ * @
783
+ */
745
784
  readonly node: string;
746
785
  readonly isNodeUnderMaintenance: boolean;
747
786
  readonly sftp: {
@@ -806,21 +845,64 @@ declare class Server {
806
845
  setStartupVariable: (key: string, value: string) => Promise<StartupParams>;
807
846
  }
808
847
 
848
+ /**
849
+ * Pelican User Client
850
+ *
851
+ * @class
852
+ * @param client Pelican API Client
853
+ */
809
854
  declare class Client {
810
855
  private readonly client;
811
856
  constructor(client: Client$1);
857
+ /**
858
+ * Get raw API client
859
+ */
812
860
  get $client(): Client$1;
861
+ /**
862
+ * Get user account
863
+ */
813
864
  getAccount: () => Promise<Account>;
865
+ /**
866
+ * Get subuser (current user) permissions
867
+ *
868
+ * Return data is not compatible with subusers API
869
+ */
814
870
  listPermissions: () => Promise<Record<string, Permission>>;
871
+ /**
872
+ * List servers
873
+ *
874
+ * @param opts Filtering options (all optional)
875
+ */
815
876
  listServers: (opts?: {
877
+ /**
878
+ * Server access type (Default: accessible)
879
+ *
880
+ * Variants:
881
+ * - `accessible` — your servers and servers you have access to as a subuser
882
+ * - `mine` — only your servers
883
+ * - `admin` — only servers you have admin access to (excluding yours)
884
+ * - `admin-all` — all servers you have admin access to
885
+ */
816
886
  type?: "accessible" | "mine" | "admin" | "admin-all";
817
887
  page?: number;
818
888
  per_page?: number;
819
889
  include?: ("egg" | "subusers")[];
820
890
  }) => Promise<Server[]>;
891
+ /**
892
+ * Get server by UUID
893
+ *
894
+ * @param uuid Server UUID
895
+ * @param include Include additional data
896
+ */
821
897
  getServer: (uuid: string, include?: ("egg" | "subusers")[]) => Promise<Server>;
822
898
  }
823
899
 
900
+ /**
901
+ * Creates a Humane Pelican User client
902
+ * @param url Pelican Panel URL (ex: https://demo.pelican.dev)
903
+ * @param token Pelican User Token (`pacc...`)
904
+ * @param suffix API suffix, used if you expose api on a different path
905
+ */
824
906
  declare const createPelicanClient: (url: string, token: string, suffix?: string) => Client;
825
907
 
826
908
  export { Account, Client, Server, ServerAllocation, ServerBackup, ServerDatabase, ServerFile, ServerSchedule, ServerUser, createPelicanClient };