@pelican.ts/sdk 0.4.0 → 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.
@@ -1,35 +1,34 @@
1
- import {Nullable} from "@/utils/types";
1
+ import { Nullable } from "@/utils/types"
2
2
 
3
3
  export type User = {
4
- uuid: string,
5
- username: string,
6
- email: string,
4
+ uuid: string
5
+ username: string
6
+ email: string
7
7
  language: string
8
- image: string,
9
- admin: boolean,
10
- root_admin: boolean,
11
- "2fa_enabled": boolean,
12
- created_at: string,
8
+ image: string
9
+ admin: boolean
10
+ root_admin: boolean
11
+ "2fa_enabled": boolean
12
+ created_at: string
13
13
  updated_at: string
14
-
15
14
  }
16
15
 
17
16
  export type APIKey = {
18
- identifier: string,
19
- description: string,
20
- allowed_ips: string[],
21
- last_used_at: Nullable<string>,
17
+ identifier: string
18
+ description: string
19
+ allowed_ips: string[]
20
+ last_used_at: Nullable<string>
22
21
  created_at: string
23
22
  }
24
23
 
25
24
  export type SSHKey = {
26
- name: string,
27
- fingerprint: string,
28
- pubic_key: string,
25
+ name: string
26
+ fingerprint: string
27
+ pubic_key: string
29
28
  created_at: string
30
29
  }
31
30
 
32
31
  export type Permission = {
33
- description: string,
32
+ description: string
34
33
  keys: Record<string, string>
35
- }
34
+ }
@@ -3,13 +3,13 @@
3
3
  * @license MIT
4
4
  */
5
5
 
6
- export type ServerStatus = 'starting' | 'stopping' | 'online' | 'offline';
6
+ export type ServerStatus = "starting" | "stopping" | "online" | "offline"
7
7
 
8
8
  export enum SERVER_SIGNAL {
9
- 'START' = 'start',
10
- 'STOP' = 'stop',
11
- 'RESTART' = 'restart',
12
- 'KILL' = 'kill',
9
+ START = "start",
10
+ STOP = "stop",
11
+ RESTART = "restart",
12
+ KILL = "kill",
13
13
  }
14
14
 
15
15
  export type WebsocketEvent =
@@ -28,101 +28,101 @@ export type WebsocketEvent =
28
28
  | TransferStatusEvent
29
29
  | BackupCompletedEvent
30
30
  | BackupRestoreCompletedEvent
31
- | JwtErrorEvent;
31
+ | JwtErrorEvent
32
32
 
33
33
  /**
34
34
  * Source: https://github.com/pterodactyl/panel/blob/1.0-develop/resources/scripts/components/server/events.ts
35
35
  */
36
36
  export enum SOCKET_EVENT {
37
- AUTH_SUCCESS = 'auth success',
38
- DAEMON_MESSAGE = 'daemon message',
39
- DAEMON_ERROR = 'daemon error',
40
- INSTALL_OUTPUT = 'install output',
41
- INSTALL_STARTED = 'install started',
42
- INSTALL_COMPLETED = 'install completed',
43
- CONSOLE_OUTPUT = 'console output',
44
- STATUS = 'status',
45
- STATS = 'stats',
46
- TRANSFER_LOGS = 'transfer logs',
47
- TRANSFER_STATUS = 'transfer status',
48
- BACKUP_COMPLETED = 'backup completed',
49
- BACKUP_RESTORE_COMPLETED = 'backup restore completed',
50
- TOKEN_EXPIRING = 'token expiring',
51
- TOKEN_EXPIRED = 'token expired',
52
- JWT_ERROR = 'jwt error',
37
+ AUTH_SUCCESS = "auth success",
38
+ DAEMON_MESSAGE = "daemon message",
39
+ DAEMON_ERROR = "daemon error",
40
+ INSTALL_OUTPUT = "install output",
41
+ INSTALL_STARTED = "install started",
42
+ INSTALL_COMPLETED = "install completed",
43
+ CONSOLE_OUTPUT = "console output",
44
+ STATUS = "status",
45
+ STATS = "stats",
46
+ TRANSFER_LOGS = "transfer logs",
47
+ TRANSFER_STATUS = "transfer status",
48
+ BACKUP_COMPLETED = "backup completed",
49
+ BACKUP_RESTORE_COMPLETED = "backup restore completed",
50
+ TOKEN_EXPIRING = "token expiring",
51
+ TOKEN_EXPIRED = "token expired",
52
+ JWT_ERROR = "jwt error",
53
53
  }
54
54
 
55
55
  export type InstallOutputEvent = {
56
- event: SOCKET_EVENT.INSTALL_OUTPUT;
57
- args: [string];
58
- };
56
+ event: SOCKET_EVENT.INSTALL_OUTPUT
57
+ args: [string]
58
+ }
59
59
 
60
60
  export type InstallStartedEvent = {
61
- event: SOCKET_EVENT.INSTALL_STARTED;
62
- };
61
+ event: SOCKET_EVENT.INSTALL_STARTED
62
+ }
63
63
 
64
64
  export type InstallCompletedEvent = {
65
- event: SOCKET_EVENT.INSTALL_COMPLETED;
66
- };
65
+ event: SOCKET_EVENT.INSTALL_COMPLETED
66
+ }
67
67
 
68
68
  export type TransferLogsEvent = {
69
- event: SOCKET_EVENT.TRANSFER_LOGS;
70
- args: [string];
71
- };
69
+ event: SOCKET_EVENT.TRANSFER_LOGS
70
+ args: [string]
71
+ }
72
72
 
73
73
  export type TransferStatusEvent = {
74
- event: SOCKET_EVENT.TRANSFER_STATUS;
75
- args: [string];
76
- };
74
+ event: SOCKET_EVENT.TRANSFER_STATUS
75
+ args: [string]
76
+ }
77
77
 
78
78
  export type BackupCompletedEvent = {
79
- event: SOCKET_EVENT.BACKUP_COMPLETED;
80
- args: [string];
81
- };
79
+ event: SOCKET_EVENT.BACKUP_COMPLETED
80
+ args: [string]
81
+ }
82
82
 
83
83
  export type BackupCompletedJson = {
84
- checksum: string;
85
- checksum_type: 'sha1';
86
- file_size: number;
87
- is_successful: boolean;
88
- uuid: string;
89
- };
84
+ checksum: string
85
+ checksum_type: "sha1"
86
+ file_size: number
87
+ is_successful: boolean
88
+ uuid: string
89
+ }
90
90
 
91
91
  export type BackupRestoreCompletedEvent = {
92
- event: SOCKET_EVENT.BACKUP_RESTORE_COMPLETED;
93
- };
92
+ event: SOCKET_EVENT.BACKUP_RESTORE_COMPLETED
93
+ }
94
94
 
95
95
  export type AuthSuccessWsEvent = {
96
- event: SOCKET_EVENT.AUTH_SUCCESS;
97
- };
96
+ event: SOCKET_EVENT.AUTH_SUCCESS
97
+ }
98
98
 
99
- export type StatusWsEvent = { event: SOCKET_EVENT.STATUS; args: [PowerState] };
99
+ export type StatusWsEvent = { event: SOCKET_EVENT.STATUS; args: [PowerState] }
100
100
 
101
- export type PowerState = 'starting' | 'stopping' | 'running' | 'offline';
101
+ export type PowerState = "starting" | "stopping" | "running" | "offline"
102
102
 
103
103
  export type ConsoleLogWsEvent = {
104
- event: SOCKET_EVENT.CONSOLE_OUTPUT;
105
- args: [string];
106
- };
104
+ event: SOCKET_EVENT.CONSOLE_OUTPUT
105
+ args: [string]
106
+ }
107
107
 
108
108
  export type StatsWsEvent = {
109
- event: SOCKET_EVENT.STATS;
110
- args: [string];
111
- };
109
+ event: SOCKET_EVENT.STATS
110
+ args: [string]
111
+ }
112
112
 
113
113
  export type StatsWsJson = {
114
- memory_bytes: number;
115
- memory_limit_bytes: number;
116
- cpu_absolute: number;
117
- network: { rx_bytes: number; tx_bytes: number };
118
- state: PowerState;
119
- uptime: number;
120
- disk_bytes: number;
121
- };
114
+ memory_bytes: number
115
+ memory_limit_bytes: number
116
+ cpu_absolute: number
117
+ network: { rx_bytes: number; tx_bytes: number }
118
+ state: PowerState
119
+ uptime: number
120
+ disk_bytes: number
121
+ }
122
122
 
123
- export type TokenExpiringWsEvent = { event: SOCKET_EVENT.TOKEN_EXPIRING };
123
+ export type TokenExpiringWsEvent = { event: SOCKET_EVENT.TOKEN_EXPIRING }
124
124
 
125
- export type TokenExpiredWsEvent = { event: SOCKET_EVENT.TOKEN_EXPIRED };
125
+ export type TokenExpiredWsEvent = { event: SOCKET_EVENT.TOKEN_EXPIRED }
126
126
 
127
127
  /**
128
128
  * Example:
@@ -133,18 +133,18 @@ export type TokenExpiredWsEvent = { event: SOCKET_EVENT.TOKEN_EXPIRED };
133
133
  * {"event":"daemon message","args":["Completed server restoration from local backup."]}
134
134
  */
135
135
  export type DaemonMessageEvent = {
136
- event: SOCKET_EVENT.DAEMON_MESSAGE;
137
- args: [string];
138
- };
136
+ event: SOCKET_EVENT.DAEMON_MESSAGE
137
+ args: [string]
138
+ }
139
139
 
140
140
  export type DaemonErrorEvent = {
141
- event: SOCKET_EVENT.DAEMON_ERROR;
142
- args: [string];
143
- };
141
+ event: SOCKET_EVENT.DAEMON_ERROR
142
+ args: [string]
143
+ }
144
144
 
145
145
  export type JwtErrorEvent = {
146
- event: SOCKET_EVENT.JWT_ERROR;
147
- args: [string];
148
- };
146
+ event: SOCKET_EVENT.JWT_ERROR
147
+ args: [string]
148
+ }
149
149
 
150
- export {ServerWebsocket} from "@/api/client/server_websocket";
150
+ export { ServerWebsocket } from "@/api/client/server_websocket"
package/src/api/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import {Client as UserClient} from "@/api/client/client";
2
- import {Client as AppClient} from "@/api/application/client";
3
- import {Agent} from "@/api/base/request";
1
+ import { Client as UserClient } from "@/api/client/client"
2
+ import { Client as AppClient } from "@/api/application/client"
3
+ import { Agent } from "@/api/base/request"
4
4
 
5
5
  export class PelicanAPIClient extends UserClient {
6
6
  constructor(url: string, token: string, suffix: string = "/api") {
@@ -14,4 +14,4 @@ export class PelicanAPIApplication extends AppClient {
14
14
  const ax = new Agent(url, token, "application", suffix)
15
15
  super(ax.requester)
16
16
  }
17
- }
17
+ }
@@ -1,21 +1,24 @@
1
- import type {Client} from "@/api/client/client";
2
- import type {User} from "@/api/client/types/user";
3
-
1
+ import type { Client } from "@/api/client/client"
2
+ import type { User } from "@/api/client/types/user"
4
3
 
5
4
  export class Account {
6
5
  private readonly client: Client
7
- readonly uuid: string;
8
- readonly username: string;
9
- private $email: string;
10
- get email() {return this.$email}
11
- readonly language: string;
12
- readonly image: string;
13
- readonly admin: boolean;
14
- readonly root_admin: boolean;
15
- private $has2faEnabled: boolean;
16
- get has2faEnabled() {return this.$has2faEnabled}
17
- readonly createdAt: Date;
18
- readonly updatedAt: Date;
6
+ readonly uuid: string
7
+ readonly username: string
8
+ private $email: string
9
+ get email() {
10
+ return this.$email
11
+ }
12
+ readonly language: string
13
+ readonly image: string
14
+ readonly admin: boolean
15
+ readonly root_admin: boolean
16
+ private $has2faEnabled: boolean
17
+ get has2faEnabled() {
18
+ return this.$has2faEnabled
19
+ }
20
+ readonly createdAt: Date
21
+ readonly updatedAt: Date
19
22
 
20
23
  constructor(client: Client, user: User) {
21
24
  this.client = client
@@ -31,54 +34,40 @@ export class Account {
31
34
  this.updatedAt = new Date(user.updated_at)
32
35
  }
33
36
 
34
- updateEmail = async (
35
- newEmail: string,
36
- password: string
37
- ) => {
37
+ updateEmail = async (newEmail: string, password: string) => {
38
38
  await this.client.account.updateEmail(newEmail, password)
39
39
  this.$email = newEmail
40
40
  }
41
41
 
42
- updatePassword = async (
43
- newPassword: string
44
- ) => this.client.account.updatePassword(newPassword)
42
+ updatePassword = async (newPassword: string) =>
43
+ this.client.account.updatePassword(newPassword)
45
44
 
46
45
  listApiKeys = async () => this.client.account.apiKeys.list()
47
46
 
48
- createApiKey = async (
49
- description: string,
50
- allowed_ips?: string[]
51
- ) => this.client.account.apiKeys.create(description, allowed_ips)
47
+ createApiKey = async (description: string, allowed_ips?: string[]) =>
48
+ this.client.account.apiKeys.create(description, allowed_ips)
52
49
 
53
- deleteApiKey = async (
54
- identifier: string
55
- ) => this.client.account.apiKeys.delete(identifier)
50
+ deleteApiKey = async (identifier: string) =>
51
+ this.client.account.apiKeys.delete(identifier)
56
52
 
57
53
  listSshKeys = async () => this.client.account.sshKeys.list()
58
54
 
59
- createSshKey = async (
60
- name: string,
61
- public_key: string
62
- ) => this.client.account.sshKeys.create(name, public_key)
55
+ createSshKey = async (name: string, public_key: string) =>
56
+ this.client.account.sshKeys.create(name, public_key)
63
57
 
64
- deleteSshKey = async (
65
- fingerprint: string
66
- ) => this.client.account.sshKeys.delete(fingerprint)
58
+ deleteSshKey = async (fingerprint: string) =>
59
+ this.client.account.sshKeys.delete(fingerprint)
67
60
 
68
61
  get2faQR = async () => this.client.account.twoFactor.info()
69
62
 
70
- enable2fa = async (
71
- code: string
72
- ) => {
63
+ enable2fa = async (code: string) => {
73
64
  const tokens = await this.client.account.twoFactor.enable(code)
74
65
  this.$has2faEnabled = true
75
66
  return tokens
76
67
  }
77
68
 
78
- disable2fa = async (
79
- password: string
80
- ) => {
69
+ disable2fa = async (password: string) => {
81
70
  await this.client.account.twoFactor.disable(password)
82
71
  this.$has2faEnabled = false
83
72
  }
84
- }
73
+ }
@@ -1,7 +1,6 @@
1
- import type {Client as ClientT} from "@/api/client/client";
2
- import {Account} from "@/humane/Account";
3
- import {Server} from "@/humane/Server";
4
-
1
+ import type { Client as ClientT } from "@/api/client/client"
2
+ import { Account } from "@/humane/Account"
3
+ import { Server } from "@/humane/Server"
5
4
 
6
5
  export class Client {
7
6
  private readonly client: ClientT
@@ -23,21 +22,23 @@ export class Client {
23
22
 
24
23
  listServers = async (
25
24
  opts: {
26
- type?: "accessible" | "mine" | "admin" | "admin-all",
27
- page?: number,
28
- per_page?: number,
29
- include?: ("egg" | "subusers")[],
30
- } = {type: "accessible", page: 1, per_page: 50}
25
+ type?: "accessible" | "mine" | "admin" | "admin-all"
26
+ page?: number
27
+ per_page?: number
28
+ include?: ("egg" | "subusers")[]
29
+ } = { type: "accessible", page: 1, per_page: 50 },
31
30
  ) => {
32
- const data = await this.client.listServers(opts.type, opts.page, opts.per_page, opts.include)
33
- return data.map(d => new Server(this.client.server(d.uuid), d))
31
+ const data = await this.client.listServers(
32
+ opts.type,
33
+ opts.page,
34
+ opts.per_page,
35
+ opts.include,
36
+ )
37
+ return data.map((d) => new Server(this.client.server(d.uuid), d))
34
38
  }
35
39
 
36
- getServer = async (
37
- uuid: string,
38
- include?: ("egg" | "subusers")[]
39
- ) => {
40
+ getServer = async (uuid: string, include?: ("egg" | "subusers")[]) => {
40
41
  const server = await this.client.server(uuid).info(include)
41
42
  return new Server(this.client.server(uuid), server)
42
43
  }
43
- }
44
+ }