@pelican.ts/sdk 0.3.4-next.3 → 0.4.0
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/.husky/pre-commit +3 -0
- package/biome.json +39 -0
- package/bun.lock +24 -1
- package/dist/api/index.d.mts +1641 -0
- package/dist/api/index.d.ts +1641 -0
- package/dist/api/index.js +2100 -0
- package/dist/api/index.mjs +2062 -0
- package/dist/index.d.mts +622 -1430
- package/dist/index.d.ts +622 -1430
- package/dist/index.js +532 -444
- package/dist/index.mjs +531 -442
- package/dist/types.d.ts +61 -4
- package/package.json +15 -4
- package/src/api/client/types/server.ts +2 -2
- package/src/api/client/types/user.ts +1 -1
- package/src/api/client/types/websocket.ts +1 -1
- package/src/api/index.ts +17 -0
- package/src/humane/Account.ts +84 -0
- package/src/humane/Client.ts +43 -0
- package/src/humane/Server.ts +217 -0
- package/src/humane/ServerAllocation.ts +39 -0
- package/src/humane/ServerBackup.ts +37 -0
- package/src/humane/ServerDatabase.ts +36 -0
- package/src/humane/ServerFile.ts +73 -0
- package/src/humane/ServerSchedule.ts +126 -0
- package/src/humane/ServerUser.ts +42 -0
- package/src/index.ts +5 -14
- package/src/utils/sized.ts +1 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
import WebSocket from 'isomorphic-ws';
|
|
2
4
|
|
|
3
5
|
type ServerSignalOption = 'start' | 'stop' | 'restart' | 'kill';
|
|
4
6
|
|
|
@@ -938,6 +940,61 @@ type ApplicationUserApiKey = {
|
|
|
938
940
|
updated_at: string;
|
|
939
941
|
};
|
|
940
942
|
|
|
943
|
+
type SocketEventPayloadMap = {
|
|
944
|
+
[SOCKET_EVENT.AUTH_SUCCESS]: undefined;
|
|
945
|
+
[SOCKET_EVENT.STATUS]: PowerState;
|
|
946
|
+
[SOCKET_EVENT.CONSOLE_OUTPUT]: string;
|
|
947
|
+
[SOCKET_EVENT.STATS]: StatsWsJson;
|
|
948
|
+
[SOCKET_EVENT.DAEMON_ERROR]: undefined;
|
|
949
|
+
[SOCKET_EVENT.DAEMON_MESSAGE]: string;
|
|
950
|
+
[SOCKET_EVENT.INSTALL_OUTPUT]: string;
|
|
951
|
+
[SOCKET_EVENT.INSTALL_STARTED]: undefined;
|
|
952
|
+
[SOCKET_EVENT.INSTALL_COMPLETED]: undefined;
|
|
953
|
+
[SOCKET_EVENT.TRANSFER_LOGS]: string;
|
|
954
|
+
[SOCKET_EVENT.TRANSFER_STATUS]: string;
|
|
955
|
+
[SOCKET_EVENT.BACKUP_COMPLETED]: BackupCompletedJson;
|
|
956
|
+
[SOCKET_EVENT.BACKUP_RESTORE_COMPLETED]: undefined;
|
|
957
|
+
[SOCKET_EVENT.TOKEN_EXPIRING]: undefined;
|
|
958
|
+
[SOCKET_EVENT.TOKEN_EXPIRED]: undefined;
|
|
959
|
+
[SOCKET_EVENT.JWT_ERROR]: string;
|
|
960
|
+
};
|
|
961
|
+
type Listener<E extends SOCKET_EVENT> = SocketEventPayloadMap[E] extends undefined ? () => void : (payload: SocketEventPayloadMap[E]) => void;
|
|
962
|
+
type CloseEventLike = Parameters<NonNullable<WebSocket["onclose"]>>[0];
|
|
963
|
+
type ErrorEventLike = Parameters<NonNullable<WebSocket["onerror"]>>[0];
|
|
964
|
+
declare class ServerWebsocket {
|
|
965
|
+
private readonly r;
|
|
966
|
+
private readonly serverId;
|
|
967
|
+
private socket?;
|
|
968
|
+
private currentToken?;
|
|
969
|
+
private readonly bus;
|
|
970
|
+
private debugLogging;
|
|
971
|
+
private stripColors;
|
|
972
|
+
private detachMessageListener?;
|
|
973
|
+
constructor(requester: AxiosInstance, id: string, stripColors?: boolean);
|
|
974
|
+
on<E extends SOCKET_EVENT>(event: E, listener: Listener<E>): () => void;
|
|
975
|
+
deregister<E extends SOCKET_EVENT>(event: E, listener: Listener<E>): void;
|
|
976
|
+
private emit;
|
|
977
|
+
connect(resumable?: boolean, debugLogging?: boolean): Promise<void>;
|
|
978
|
+
onSocketDisconnect(handler: (event: CloseEventLike) => void): void;
|
|
979
|
+
onSocketError(handler: (event: ErrorEventLike) => void): void;
|
|
980
|
+
makeResumable(disconnectsToo: boolean): void;
|
|
981
|
+
private attachMessageListener;
|
|
982
|
+
private handleIncomingMessage;
|
|
983
|
+
private parseMessage;
|
|
984
|
+
private normalisePayload;
|
|
985
|
+
private dispatchMessage;
|
|
986
|
+
private refreshCredentials;
|
|
987
|
+
private authenticate;
|
|
988
|
+
disconnect(): void;
|
|
989
|
+
requestStats(): void;
|
|
990
|
+
requestLogs(): void;
|
|
991
|
+
private send;
|
|
992
|
+
getStats(): Promise<StatsWsJson>;
|
|
993
|
+
getLogs(): Promise<string[]>;
|
|
994
|
+
sendPoweraction(action: ServerSignalOption): void;
|
|
995
|
+
sendCommand(cmd: string): void;
|
|
996
|
+
}
|
|
997
|
+
|
|
941
998
|
type ServerStatus = 'starting' | 'stopping' | 'online' | 'offline';
|
|
942
999
|
declare enum SERVER_SIGNAL {
|
|
943
1000
|
'START' = "start",
|
|
@@ -1094,7 +1151,7 @@ type Server = {
|
|
|
1094
1151
|
limits: ServerLimits;
|
|
1095
1152
|
invocation: string;
|
|
1096
1153
|
docker_image: string;
|
|
1097
|
-
egg_features: string[]
|
|
1154
|
+
egg_features: Nullable<string[]>;
|
|
1098
1155
|
feature_limits: FeatureLimits;
|
|
1099
1156
|
status: Nullable<unknown>;
|
|
1100
1157
|
is_suspended: boolean;
|
|
@@ -1107,7 +1164,7 @@ type Server = {
|
|
|
1107
1164
|
uuid: string;
|
|
1108
1165
|
name: string;
|
|
1109
1166
|
}, "egg">;
|
|
1110
|
-
subusers
|
|
1167
|
+
subusers?: GenericListResponse<GenericResponse<ServerSubuser, "server_subuser">>;
|
|
1111
1168
|
};
|
|
1112
1169
|
};
|
|
1113
1170
|
type ServerStats = {
|
|
@@ -1142,7 +1199,7 @@ type User = {
|
|
|
1142
1199
|
image: string;
|
|
1143
1200
|
admin: boolean;
|
|
1144
1201
|
root_admin: boolean;
|
|
1145
|
-
"2fa_enabled":
|
|
1202
|
+
"2fa_enabled": boolean;
|
|
1146
1203
|
created_at: string;
|
|
1147
1204
|
updated_at: string;
|
|
1148
1205
|
};
|
|
@@ -1164,4 +1221,4 @@ type Permission = {
|
|
|
1164
1221
|
keys: Record<string, string>;
|
|
1165
1222
|
};
|
|
1166
1223
|
|
|
1167
|
-
export { type APIKey, type Allocation, type AllocationRel, type ApplicationEggVariable, type ApplicationServer, type ApplicationUser, type ApplicationUserApiKey, type AuthSuccessWsEvent, type BackupCompletedEvent, type BackupCompletedJson, type BackupRestoreCompletedEvent, type ConsoleLogWsEvent, type Container, type DaemonErrorEvent, type DaemonMessageEvent, type DatabaseHost, type Egg, type EggVariable, type ExportedEgg, type FeatureLimits, type FileObject, type InstallCompletedEvent, type InstallOutputEvent, type InstallStartedEvent, type JwtErrorEvent, type LanguagesType, type Location, type Mount, type Node, type NodeConfiguration, type Permission, type PowerState, type Role, SERVER_SIGNAL, SOCKET_EVENT, type SSHKey, type Schedule, type ScheduleTask, type Server, type ServerActivityLog, type ServerAllocation, type ServerBackup, type ServerDatabase, type ServerLimits, type ServerSignalOption, type ServerStats, type ServerStatus, type ServerSubuser, type StartupMeta, type StartupParams, type StatsWsEvent, type StatsWsJson, type StatusWsEvent, type SubuserPermission, type TimezonesType, type TokenExpiredWsEvent, type TokenExpiringWsEvent, type TransferLogsEvent, type TransferStatusEvent, type User, type WebsocketEvent, languagesSchema, timezonesSchema };
|
|
1224
|
+
export { type APIKey, type Allocation, type AllocationRel, type ApplicationEggVariable, type ApplicationServer, type ApplicationUser, type ApplicationUserApiKey, type AuthSuccessWsEvent, type BackupCompletedEvent, type BackupCompletedJson, type BackupRestoreCompletedEvent, type ConsoleLogWsEvent, type Container, type DaemonErrorEvent, type DaemonMessageEvent, type DatabaseHost, type Egg, type EggVariable, type ExportedEgg, type FeatureLimits, type FileObject, type InstallCompletedEvent, type InstallOutputEvent, type InstallStartedEvent, type JwtErrorEvent, type LanguagesType, type Location, type Mount, type Node, type NodeConfiguration, type Permission, type PowerState, type Role, SERVER_SIGNAL, SOCKET_EVENT, type SSHKey, type Schedule, type ScheduleTask, type Server, type ServerActivityLog, type ServerAllocation, type ServerBackup, type ServerDatabase, type ServerLimits, type ServerSignalOption, type ServerStats, type ServerStatus, type ServerSubuser, ServerWebsocket, type StartupMeta, type StartupParams, type StatsWsEvent, type StatsWsJson, type StatusWsEvent, type SubuserPermission, type TimezonesType, type TokenExpiredWsEvent, type TokenExpiringWsEvent, type TransferLogsEvent, type TransferStatusEvent, type User, type WebsocketEvent, languagesSchema, timezonesSchema };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pelican.ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Pelican panel SDK for TypeScript",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -11,18 +11,27 @@
|
|
|
11
11
|
"require": "./dist/index.js",
|
|
12
12
|
"import": "./dist/index.mjs"
|
|
13
13
|
},
|
|
14
|
+
"./api": {
|
|
15
|
+
"types": "./dist/api/index.d.ts",
|
|
16
|
+
"require": "./dist/api/index.js",
|
|
17
|
+
"import": "./dist/api/index.mjs"
|
|
18
|
+
},
|
|
14
19
|
"./types": {
|
|
15
20
|
"types": "./dist/types.d.ts"
|
|
16
21
|
}
|
|
17
22
|
},
|
|
18
23
|
"scripts": {
|
|
19
|
-
"build:
|
|
24
|
+
"build:api": "tsup src/api/index.ts --format esm,cjs --dts --target esnext -d dist/api",
|
|
25
|
+
"build:humane": "tsup src/index.ts --format esm,cjs --dts --target esnext",
|
|
20
26
|
"build:types": "tsup src/types.ts --dts-only --target esnext",
|
|
21
|
-
"build": "rm -rf ./dist && npm run build:
|
|
27
|
+
"build": "rm -rf ./dist && npm run build:api && npm run build:humane && npm run build:types",
|
|
22
28
|
"pub": "npm publish --access=public",
|
|
23
29
|
"pub:next": "npm publish --access=public --tag=next",
|
|
24
30
|
"generate-types": "bun run scripts/create-types.ts",
|
|
25
|
-
"pipeline": "bun run generate-types && bun run build && bun run pub:next"
|
|
31
|
+
"pipeline:next": "bun run generate-types && bun run build && bun run pub:next",
|
|
32
|
+
"pipeline": "bun run generate-types && bun run build && bun run pub",
|
|
33
|
+
"format": "biome format --no-errors-on-unmatched --files-ignore-unknown=true --write .",
|
|
34
|
+
"prepare": "husky"
|
|
26
35
|
},
|
|
27
36
|
"keywords": [
|
|
28
37
|
"pterodactyl",
|
|
@@ -38,8 +47,10 @@
|
|
|
38
47
|
"url": "git+https://github.com/m41denx/Pelican.ts"
|
|
39
48
|
},
|
|
40
49
|
"devDependencies": {
|
|
50
|
+
"@biomejs/biome": "2.3.6",
|
|
41
51
|
"@types/node": "^22.18.12",
|
|
42
52
|
"@types/strip-color": "^0.1.2",
|
|
53
|
+
"husky": "^9.1.7",
|
|
43
54
|
"tsc-alias": "^1.8.16",
|
|
44
55
|
"tsup": "^8.5.0",
|
|
45
56
|
"typescript": "^5.9.3"
|
|
@@ -22,7 +22,7 @@ export type Server = {
|
|
|
22
22
|
limits: ServerLimits,
|
|
23
23
|
invocation: string,
|
|
24
24
|
docker_image: string,
|
|
25
|
-
egg_features: string[]
|
|
25
|
+
egg_features: Nullable<string[]>,
|
|
26
26
|
feature_limits: FeatureLimits,
|
|
27
27
|
status: Nullable<unknown>,
|
|
28
28
|
is_suspended: boolean,
|
|
@@ -35,7 +35,7 @@ export type Server = {
|
|
|
35
35
|
uuid: string,
|
|
36
36
|
name: string
|
|
37
37
|
}, "egg">,
|
|
38
|
-
subusers
|
|
38
|
+
subusers?: GenericListResponse<GenericResponse<ServerSubuser, "server_subuser">>
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
|
|
5
|
+
export class PelicanAPIClient extends UserClient {
|
|
6
|
+
constructor(url: string, token: string, suffix: string = "/api") {
|
|
7
|
+
const ax = new Agent(url, token, "client", suffix)
|
|
8
|
+
super(ax.requester)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class PelicanAPIApplication extends AppClient {
|
|
13
|
+
constructor(url: string, token: string, suffix: string = "/api") {
|
|
14
|
+
const ax = new Agent(url, token, "application", suffix)
|
|
15
|
+
super(ax.requester)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {Client} from "@/api/client/client";
|
|
2
|
+
import type {User} from "@/api/client/types/user";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class Account {
|
|
6
|
+
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;
|
|
19
|
+
|
|
20
|
+
constructor(client: Client, user: User) {
|
|
21
|
+
this.client = client
|
|
22
|
+
this.uuid = user.uuid
|
|
23
|
+
this.username = user.username
|
|
24
|
+
this.$email = user.email
|
|
25
|
+
this.language = user.language
|
|
26
|
+
this.image = user.image
|
|
27
|
+
this.admin = user.admin
|
|
28
|
+
this.root_admin = user.root_admin
|
|
29
|
+
this.$has2faEnabled = user["2fa_enabled"]
|
|
30
|
+
this.createdAt = new Date(user.created_at)
|
|
31
|
+
this.updatedAt = new Date(user.updated_at)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
updateEmail = async (
|
|
35
|
+
newEmail: string,
|
|
36
|
+
password: string
|
|
37
|
+
) => {
|
|
38
|
+
await this.client.account.updateEmail(newEmail, password)
|
|
39
|
+
this.$email = newEmail
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
updatePassword = async (
|
|
43
|
+
newPassword: string
|
|
44
|
+
) => this.client.account.updatePassword(newPassword)
|
|
45
|
+
|
|
46
|
+
listApiKeys = async () => this.client.account.apiKeys.list()
|
|
47
|
+
|
|
48
|
+
createApiKey = async (
|
|
49
|
+
description: string,
|
|
50
|
+
allowed_ips?: string[]
|
|
51
|
+
) => this.client.account.apiKeys.create(description, allowed_ips)
|
|
52
|
+
|
|
53
|
+
deleteApiKey = async (
|
|
54
|
+
identifier: string
|
|
55
|
+
) => this.client.account.apiKeys.delete(identifier)
|
|
56
|
+
|
|
57
|
+
listSshKeys = async () => this.client.account.sshKeys.list()
|
|
58
|
+
|
|
59
|
+
createSshKey = async (
|
|
60
|
+
name: string,
|
|
61
|
+
public_key: string
|
|
62
|
+
) => this.client.account.sshKeys.create(name, public_key)
|
|
63
|
+
|
|
64
|
+
deleteSshKey = async (
|
|
65
|
+
fingerprint: string
|
|
66
|
+
) => this.client.account.sshKeys.delete(fingerprint)
|
|
67
|
+
|
|
68
|
+
get2faQR = async () => this.client.account.twoFactor.info()
|
|
69
|
+
|
|
70
|
+
enable2fa = async (
|
|
71
|
+
code: string
|
|
72
|
+
) => {
|
|
73
|
+
const tokens = await this.client.account.twoFactor.enable(code)
|
|
74
|
+
this.$has2faEnabled = true
|
|
75
|
+
return tokens
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
disable2fa = async (
|
|
79
|
+
password: string
|
|
80
|
+
) => {
|
|
81
|
+
await this.client.account.twoFactor.disable(password)
|
|
82
|
+
this.$has2faEnabled = false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type {Client as ClientT} from "@/api/client/client";
|
|
2
|
+
import {Account} from "@/humane/Account";
|
|
3
|
+
import {Server} from "@/humane/Server";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export class Client {
|
|
7
|
+
private readonly client: ClientT
|
|
8
|
+
|
|
9
|
+
constructor(client: ClientT) {
|
|
10
|
+
this.client = client
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get $client(): ClientT {
|
|
14
|
+
return this.client
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getAccount = async () => {
|
|
18
|
+
const user = await this.client.account.info()
|
|
19
|
+
return new Account(this.client, user)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
listPermissions = async () => this.client.listPermissions()
|
|
23
|
+
|
|
24
|
+
listServers = async (
|
|
25
|
+
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}
|
|
31
|
+
) => {
|
|
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))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getServer = async (
|
|
37
|
+
uuid: string,
|
|
38
|
+
include?: ("egg" | "subusers")[]
|
|
39
|
+
) => {
|
|
40
|
+
const server = await this.client.server(uuid).info(include)
|
|
41
|
+
return new Server(this.client.server(uuid), server)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type {ServerClient} from "@/api/client/server";
|
|
2
|
+
import type {ServerBackups} from "@/api/client/server_backups";
|
|
3
|
+
import type {ServerFiles} from "@/api/client/server_files";
|
|
4
|
+
import type {ServerSchedules} from "@/api/client/server_schedules";
|
|
5
|
+
import type {Server as ServerT} from "@/api/client/types/server";
|
|
6
|
+
import { ServerAllocation } from "@/humane/ServerAllocation";
|
|
7
|
+
import {ServerBackup} from "@/humane/ServerBackup";
|
|
8
|
+
import {ServerDatabase} from "@/humane/ServerDatabase";
|
|
9
|
+
import {ServerFile} from "@/humane/ServerFile";
|
|
10
|
+
import {ServerSchedule} from "@/humane/ServerSchedule";
|
|
11
|
+
import {ServerUser} from "@/humane/ServerUser";
|
|
12
|
+
import type {EggVariable, FeatureLimits, ServerLimits, SubuserPermission} from "@/types";
|
|
13
|
+
import type {Nullable} from "@/utils/types";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export class Server {
|
|
17
|
+
private readonly client: ServerClient
|
|
18
|
+
|
|
19
|
+
readonly ownsServer: boolean;
|
|
20
|
+
readonly identifier: string;
|
|
21
|
+
readonly internalId?: number;
|
|
22
|
+
readonly uuid: string;
|
|
23
|
+
private $name: string;
|
|
24
|
+
get name() {return this.$name}
|
|
25
|
+
readonly node: string;
|
|
26
|
+
readonly isNodeUnderMaintenance: boolean;
|
|
27
|
+
readonly sftp: {
|
|
28
|
+
ip: string,
|
|
29
|
+
alias: Nullable<string>,
|
|
30
|
+
port: number
|
|
31
|
+
};
|
|
32
|
+
private $description: string;
|
|
33
|
+
get description() {return this.$description}
|
|
34
|
+
readonly limits: ServerLimits;
|
|
35
|
+
readonly invocation: string;
|
|
36
|
+
private $dockerImage: string;
|
|
37
|
+
get dockerImage() {return this.$dockerImage}
|
|
38
|
+
readonly eggFeatures: Nullable<string[]>;
|
|
39
|
+
readonly featureLimits: FeatureLimits;
|
|
40
|
+
readonly status: unknown;
|
|
41
|
+
readonly isSuspended: boolean;
|
|
42
|
+
readonly isInstalling: boolean;
|
|
43
|
+
readonly isTransferring: boolean;
|
|
44
|
+
readonly allocations: ServerAllocation[]
|
|
45
|
+
readonly variables: EggVariable[]
|
|
46
|
+
readonly egg?: {
|
|
47
|
+
uuid: string,
|
|
48
|
+
name: string
|
|
49
|
+
}
|
|
50
|
+
readonly subusers?: ServerUser[]
|
|
51
|
+
|
|
52
|
+
constructor(client: ServerClient, server: ServerT) {
|
|
53
|
+
this.client = client
|
|
54
|
+
this.ownsServer = server.server_owner
|
|
55
|
+
this.identifier = server.identifier
|
|
56
|
+
this.internalId = server.internal_id
|
|
57
|
+
this.uuid = server.uuid
|
|
58
|
+
this.$name = server.name
|
|
59
|
+
this.node = server.node
|
|
60
|
+
this.isNodeUnderMaintenance = server.is_node_under_maintenance
|
|
61
|
+
this.sftp = server.sftp_details
|
|
62
|
+
this.$description = server.description
|
|
63
|
+
this.limits = server.limits
|
|
64
|
+
this.invocation = server.invocation
|
|
65
|
+
this.$dockerImage = server.docker_image
|
|
66
|
+
this.eggFeatures = server.egg_features
|
|
67
|
+
this.featureLimits = server.feature_limits
|
|
68
|
+
this.status = server.status
|
|
69
|
+
this.isSuspended = server.is_suspended
|
|
70
|
+
this.isInstalling = server.is_installing
|
|
71
|
+
this.isTransferring = server.is_transferring
|
|
72
|
+
this.allocations = server.relationships.allocations.data.map(d => new ServerAllocation(this.client, d.attributes))
|
|
73
|
+
this.variables = server.relationships.variables.data.map(d => d.attributes)
|
|
74
|
+
this.egg = server.relationships.egg?.attributes
|
|
75
|
+
this.subusers = server.relationships.subusers?.data.map(d => new ServerUser(this.client, d.attributes))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
rename = async (
|
|
79
|
+
name: string
|
|
80
|
+
) => {
|
|
81
|
+
await this.client.settings.rename(name)
|
|
82
|
+
this.$name = name
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
updateDescription = async (
|
|
86
|
+
description: string
|
|
87
|
+
) => {
|
|
88
|
+
await this.client.settings.updateDescription(description)
|
|
89
|
+
this.$description = description
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
reinstall = async () => this.client.settings.reinstall()
|
|
93
|
+
|
|
94
|
+
changeDockerImage = async (
|
|
95
|
+
image: string
|
|
96
|
+
) => {
|
|
97
|
+
await this.client.settings.changeDockerImage(image)
|
|
98
|
+
this.$dockerImage = image
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getActivityLogs = async (
|
|
102
|
+
opts: {
|
|
103
|
+
page?: number,
|
|
104
|
+
per_page?: number
|
|
105
|
+
} = {page: 1, per_page: 50}
|
|
106
|
+
) => this.client.activity.list(opts.page, opts.per_page)
|
|
107
|
+
|
|
108
|
+
websocket = (stripColors: boolean = false) =>
|
|
109
|
+
this.client.websocket(stripColors)
|
|
110
|
+
|
|
111
|
+
getServerStats = async () => this.client.resources()
|
|
112
|
+
|
|
113
|
+
runCommand = async (command: string) => this.client.command(command)
|
|
114
|
+
|
|
115
|
+
sendPowerSignal = async (
|
|
116
|
+
signal: "start" | "stop" | "restart" | "kill"
|
|
117
|
+
) => this.client.power(signal)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
getDatabases = async (
|
|
122
|
+
opts: {
|
|
123
|
+
include?: ("password")[],
|
|
124
|
+
page?: number
|
|
125
|
+
} = {include: [], page: 1}
|
|
126
|
+
) => {
|
|
127
|
+
const data = await this.client.databases.list(opts.include, opts.page)
|
|
128
|
+
return data.map(d => new ServerDatabase(this.client, d))
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
createDatabase = async (
|
|
132
|
+
database: string,
|
|
133
|
+
remote: string
|
|
134
|
+
) => {
|
|
135
|
+
const data = await this.client.databases.create(database, remote)
|
|
136
|
+
return new ServerDatabase(this.client, data)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getSchedules = async () => {
|
|
140
|
+
const data = await this.client.schedules.list()
|
|
141
|
+
return data.map(d => new ServerSchedule(this.client, d))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
createSchedule = async (
|
|
145
|
+
...opts: Parameters<ServerSchedules["create"]>
|
|
146
|
+
) => {
|
|
147
|
+
const data = await this.client.schedules.create(...opts)
|
|
148
|
+
return new ServerSchedule(this.client, data)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getBackups = async (
|
|
152
|
+
page: number = 1
|
|
153
|
+
) => {
|
|
154
|
+
const data = await this.client.backups.list(page)
|
|
155
|
+
return data.map(d => new ServerBackup(this.client, d))
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
createBackup = async (
|
|
159
|
+
...args: Parameters<ServerBackups["create"]>
|
|
160
|
+
) => {
|
|
161
|
+
const data = await this.client.backups.create(...args)
|
|
162
|
+
return new ServerBackup(this.client, data)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
getAllocations = async () => {
|
|
166
|
+
const data = await this.client.allocations.list()
|
|
167
|
+
return data.map(d => new ServerAllocation(this.client, d))
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
createAllocation = async () => {
|
|
171
|
+
const data = await this.client.allocations.autoAssign()
|
|
172
|
+
return new ServerAllocation(this.client, data)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
getFiles = async (
|
|
176
|
+
path?: string
|
|
177
|
+
) => {
|
|
178
|
+
const data = await this.client.files.list(path)
|
|
179
|
+
return data.map(d => new ServerFile(this.client, d))
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
createFolder = async (
|
|
183
|
+
...opts: Parameters<ServerFiles["createFolder"]>
|
|
184
|
+
) => this.client.files.createFolder(...opts)
|
|
185
|
+
|
|
186
|
+
uploadFile = async (
|
|
187
|
+
...opts: Parameters<ServerFiles["upload"]>
|
|
188
|
+
) => this.client.files.upload(...opts)
|
|
189
|
+
|
|
190
|
+
uploadFileGetUrl = async (
|
|
191
|
+
...opts: Parameters<ServerFiles["uploadGetUrl"]>
|
|
192
|
+
) => this.client.files.uploadGetUrl(...opts)
|
|
193
|
+
|
|
194
|
+
pullFileFromRemote = async (
|
|
195
|
+
...opts: Parameters<ServerFiles["pullFromRemote"]>
|
|
196
|
+
) => this.client.files.pullFromRemote(...opts)
|
|
197
|
+
|
|
198
|
+
getUsers = async () => {
|
|
199
|
+
const data = await this.client.users.list()
|
|
200
|
+
return data.map(d => new ServerUser(this.client, d))
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
createUser = async (
|
|
204
|
+
email: string,
|
|
205
|
+
permissions: SubuserPermission[] | string[]
|
|
206
|
+
) => {
|
|
207
|
+
const data = await this.client.users.create(email, permissions)
|
|
208
|
+
return new ServerUser(this.client, data)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
getStartupInfo = async () => this.client.startup.list()
|
|
212
|
+
|
|
213
|
+
setStartupVariable = async (
|
|
214
|
+
key: string,
|
|
215
|
+
value: string
|
|
216
|
+
) => this.client.startup.set(key, value)
|
|
217
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type {ServerClient} from "@/api/client/server";
|
|
2
|
+
import type {ServerAllocation as ServerAllocationT} from "@/api/client/types/server_allocation";
|
|
3
|
+
import type {Nullable} from "@/utils/types";
|
|
4
|
+
|
|
5
|
+
export class ServerAllocation {
|
|
6
|
+
private readonly client: ServerClient
|
|
7
|
+
readonly alias: Nullable<string>
|
|
8
|
+
readonly id: number
|
|
9
|
+
readonly ip: string
|
|
10
|
+
private $isDefault: boolean
|
|
11
|
+
get isDefault() {return this.$isDefault}
|
|
12
|
+
private $notes: Nullable<string>
|
|
13
|
+
get notes() {return this.$notes}
|
|
14
|
+
readonly port: number
|
|
15
|
+
|
|
16
|
+
constructor(client: ServerClient, alloc: ServerAllocationT) {
|
|
17
|
+
this.client = client
|
|
18
|
+
this.alias = alloc.alias
|
|
19
|
+
this.id = alloc.id
|
|
20
|
+
this.ip = alloc.ip
|
|
21
|
+
this.$isDefault = alloc.is_default
|
|
22
|
+
this.$notes = alloc.notes
|
|
23
|
+
this.port = alloc.port
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
setNotes = async (
|
|
27
|
+
notes: string
|
|
28
|
+
) => {
|
|
29
|
+
const data = await this.client.allocations.setNotes(this.id, notes)
|
|
30
|
+
this.$notes = data.notes
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
makeDefault = async () => {
|
|
34
|
+
const data = await this.client.allocations.setPrimary(this.id)
|
|
35
|
+
this.$isDefault = data.is_default
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
unassign = async () => this.client.allocations.unassign(this.id)
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type {ServerClient} from "@/api/client/server";
|
|
2
|
+
import type {ServerBackup as ServerBackupT} from "@/api/common/types/server_backup";
|
|
3
|
+
import type {Nullable} from "@/utils/types";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export class ServerBackup {
|
|
7
|
+
private readonly client: ServerClient
|
|
8
|
+
readonly bytes: number
|
|
9
|
+
readonly checksum: Nullable<string>
|
|
10
|
+
readonly completedAt: Nullable<Date>
|
|
11
|
+
readonly createdAt: Date
|
|
12
|
+
readonly ignoredFiles: string[]
|
|
13
|
+
readonly isLocked: boolean
|
|
14
|
+
readonly isSuccessful: boolean
|
|
15
|
+
readonly name: string
|
|
16
|
+
readonly uuid: string
|
|
17
|
+
|
|
18
|
+
constructor(client: ServerClient, backup: ServerBackupT) {
|
|
19
|
+
this.client = client
|
|
20
|
+
this.bytes = backup.bytes
|
|
21
|
+
this.checksum = backup.checksum
|
|
22
|
+
this.completedAt = backup.completed_at ? new Date(backup.completed_at) : null
|
|
23
|
+
this.createdAt = new Date(backup.created_at)
|
|
24
|
+
this.ignoredFiles = backup.ignored_files
|
|
25
|
+
this.isLocked = backup.is_locked
|
|
26
|
+
this.isSuccessful = backup.is_successful
|
|
27
|
+
this.name = backup.name
|
|
28
|
+
this.uuid = backup.uuid
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
downloadGetUrl = async () => this.client.backups.downloadGetUrl(this.uuid)
|
|
33
|
+
|
|
34
|
+
download = async () => this.client.backups.download(this.uuid)
|
|
35
|
+
|
|
36
|
+
delete = async () => this.client.backups.delete(this.uuid)
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type {ServerClient} from "@/api/client/server";
|
|
2
|
+
import type {ServerDatabase as ServerDatabaseT} from "@/api/common/types/server_database";
|
|
3
|
+
// TODO: Check for validity
|
|
4
|
+
|
|
5
|
+
export class ServerDatabase {
|
|
6
|
+
private readonly client: ServerClient
|
|
7
|
+
readonly allowConnectionsFrom: string
|
|
8
|
+
readonly host: string
|
|
9
|
+
readonly port: number
|
|
10
|
+
readonly id: string
|
|
11
|
+
readonly maxConnections: number
|
|
12
|
+
readonly name: string
|
|
13
|
+
private $password?: string
|
|
14
|
+
get password() {return this.$password}
|
|
15
|
+
readonly username: string
|
|
16
|
+
|
|
17
|
+
constructor(client: ServerClient, database: ServerDatabaseT) {
|
|
18
|
+
this.client = client
|
|
19
|
+
this.allowConnectionsFrom = database.connections_from
|
|
20
|
+
this.host = database.host.address
|
|
21
|
+
this.port = database.host.port
|
|
22
|
+
this.id = database.id
|
|
23
|
+
this.maxConnections = database.max_connections
|
|
24
|
+
this.name = database.name
|
|
25
|
+
this.$password = database.relationships?.password.attributes.password
|
|
26
|
+
this.username = database.username
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
rotatePassword = async () => {
|
|
31
|
+
const data = await this.client.databases.rotatePassword(this.id)
|
|
32
|
+
this.$password = data.relationships?.password.attributes.password
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
delete = async () => this.client.databases.delete(this.id)
|
|
36
|
+
}
|