@pelican.ts/sdk 0.4.13 → 0.4.15
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/CHANGELOG.md +127 -0
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/index.d.mts +139 -139
- package/dist/index.d.ts +139 -139
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types.d.ts +258 -258
- package/package.json +1 -1
- package/.husky/pre-commit +0 -2
- package/scripts/create-types.ts +0 -24
- package/src/api/application/client.ts +0 -70
- package/src/api/application/database_hosts.ts +0 -65
- package/src/api/application/eggs.ts +0 -43
- package/src/api/application/mounts.ts +0 -109
- package/src/api/application/nodes.ts +0 -126
- package/src/api/application/nodes_allocations.ts +0 -47
- package/src/api/application/roles.ts +0 -39
- package/src/api/application/servers.ts +0 -145
- package/src/api/application/servers_databases.ts +0 -53
- package/src/api/application/types/container.ts +0 -9
- package/src/api/application/types/database_host.ts +0 -11
- package/src/api/application/types/egg.ts +0 -65
- package/src/api/application/types/index.ts +0 -10
- package/src/api/application/types/location.ts +0 -7
- package/src/api/application/types/mount.ts +0 -12
- package/src/api/application/types/node.ts +0 -58
- package/src/api/application/types/role.ts +0 -6
- package/src/api/application/types/server.ts +0 -24
- package/src/api/application/types/server_allocation.ts +0 -20
- package/src/api/application/types/user.ts +0 -34
- package/src/api/application/users.ts +0 -146
- package/src/api/base/request.ts +0 -44
- package/src/api/base/types.ts +0 -40
- package/src/api/client/account.ts +0 -77
- package/src/api/client/client.ts +0 -56
- package/src/api/client/server.ts +0 -74
- package/src/api/client/server_activity.ts +0 -25
- package/src/api/client/server_allocations.ts +0 -50
- package/src/api/client/server_backups.ts +0 -82
- package/src/api/client/server_databases.ts +0 -51
- package/src/api/client/server_files.ts +0 -145
- package/src/api/client/server_schedules.ts +0 -130
- package/src/api/client/server_settings.ts +0 -36
- package/src/api/client/server_startup.ts +0 -41
- package/src/api/client/server_users.ts +0 -55
- package/src/api/client/server_websocket.ts +0 -570
- package/src/api/client/types/index.ts +0 -5
- package/src/api/client/types/server.ts +0 -72
- package/src/api/client/types/server_allocation.ts +0 -10
- package/src/api/client/types/server_subuser.ts +0 -55
- package/src/api/client/types/user.ts +0 -31
- package/src/api/client/types/websocket.ts +0 -138
- package/src/api/common/types/egg.ts +0 -9
- package/src/api/common/types/enums.ts +0 -21
- package/src/api/common/types/index.ts +0 -9
- package/src/api/common/types/server_backup.ts +0 -13
- package/src/api/common/types/server_database.ts +0 -13
- package/src/api/common/types/server_files.ts +0 -11
- package/src/api/common/types/server_limits.ts +0 -18
- package/src/api/common/types/server_power.ts +0 -1
- package/src/api/common/types/server_schedule.ts +0 -37
- package/src/api/common/types/server_startup.ts +0 -11
- package/src/api/index.ts +0 -17
- package/src/humane/Account.ts +0 -60
- package/src/humane/Client.ts +0 -44
- package/src/humane/Server.ts +0 -206
- package/src/humane/ServerAllocation.ts +0 -41
- package/src/humane/ServerBackup.ts +0 -44
- package/src/humane/ServerDatabase.ts +0 -37
- package/src/humane/ServerFile.ts +0 -91
- package/src/humane/ServerSchedule.ts +0 -160
- package/src/humane/ServerUser.ts +0 -44
- package/src/index.ts +0 -21
- package/src/types.ts +0 -3
- package/src/utils/sized.ts +0 -13
- package/src/utils/transform.ts +0 -21
- package/src/utils/types.ts +0 -10
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import {Nullable} from "@/utils/types"
|
|
2
|
-
import {EggVariable} from "@/api/common/types"
|
|
3
|
-
|
|
4
|
-
export type Egg = {
|
|
5
|
-
id: number
|
|
6
|
-
uuid: string
|
|
7
|
-
name: string
|
|
8
|
-
author: string
|
|
9
|
-
description: string
|
|
10
|
-
features: string[]
|
|
11
|
-
tags: string[]
|
|
12
|
-
docker_image: Nullable<string>
|
|
13
|
-
docker_images: Record<string, string>
|
|
14
|
-
config: {
|
|
15
|
-
files: Record<string, FileConfig>
|
|
16
|
-
startup: Record<string, string>
|
|
17
|
-
stop: string
|
|
18
|
-
logs: object | []
|
|
19
|
-
file_denylist: string[]
|
|
20
|
-
extends: Nullable<number>
|
|
21
|
-
}
|
|
22
|
-
startup: string
|
|
23
|
-
startup_commands: Record<string, string>
|
|
24
|
-
script: {
|
|
25
|
-
privileged: boolean
|
|
26
|
-
install: string
|
|
27
|
-
entry: string
|
|
28
|
-
container: string
|
|
29
|
-
extends: Nullable<number>
|
|
30
|
-
}
|
|
31
|
-
created_at: string
|
|
32
|
-
updated_at: Nullable<string>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
type FileConfig = {parser: string; find: Record<string, string>}
|
|
36
|
-
|
|
37
|
-
export type ApplicationEggVariable = Omit<
|
|
38
|
-
EggVariable,
|
|
39
|
-
"server_value" | "is_editable" | "rules"
|
|
40
|
-
> & {
|
|
41
|
-
rules: string[]
|
|
42
|
-
sort: number
|
|
43
|
-
user_viewable: boolean
|
|
44
|
-
user_editable: boolean
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export type ExportedEgg = {
|
|
48
|
-
meta: {version: "PLCN_v3"; update_url: Nullable<string>}
|
|
49
|
-
exported_at: string
|
|
50
|
-
name: string
|
|
51
|
-
author: string
|
|
52
|
-
description: string
|
|
53
|
-
uuid: string
|
|
54
|
-
image: Nullable<string>
|
|
55
|
-
docker_images: Record<string, string>
|
|
56
|
-
features: string[]
|
|
57
|
-
tags: string[]
|
|
58
|
-
file_denylist: string[]
|
|
59
|
-
startup_commands: Record<string, string>
|
|
60
|
-
config: Omit<Egg["config"], "extends" | "file_denylist">
|
|
61
|
-
scripts: {
|
|
62
|
-
installation: {script: string; container: string; entrypoint: string}
|
|
63
|
-
}
|
|
64
|
-
variables: ApplicationEggVariable[]
|
|
65
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from "./node"
|
|
2
|
-
export * from "./mount"
|
|
3
|
-
export * from "./location"
|
|
4
|
-
export * from "./database_host"
|
|
5
|
-
export * from "./container"
|
|
6
|
-
export * from "./role"
|
|
7
|
-
export * from "./egg"
|
|
8
|
-
export * from "./server_allocation"
|
|
9
|
-
export * from "./server"
|
|
10
|
-
export * from "./user"
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
2
|
-
import {Allocation} from "@/api/application/types/server_allocation"
|
|
3
|
-
import {Location} from "@/api/application/types/location"
|
|
4
|
-
import {ApplicationServer} from "@/api/application/types/server"
|
|
5
|
-
import {Nullable} from "@/utils/types"
|
|
6
|
-
|
|
7
|
-
export type Node = {
|
|
8
|
-
id: number
|
|
9
|
-
uuid: string
|
|
10
|
-
public: boolean
|
|
11
|
-
name: string
|
|
12
|
-
description: Nullable<string>
|
|
13
|
-
fqdn: string
|
|
14
|
-
scheme: "https" | "http"
|
|
15
|
-
behind_proxy: boolean
|
|
16
|
-
maintenance_mode: boolean
|
|
17
|
-
memory: number
|
|
18
|
-
memory_overallocate: number
|
|
19
|
-
disk: number
|
|
20
|
-
disk_overallocate: number
|
|
21
|
-
cpu: number
|
|
22
|
-
cpu_overallocate: number
|
|
23
|
-
upload_size: number
|
|
24
|
-
daemon_listen: number
|
|
25
|
-
daemon_sftp: number
|
|
26
|
-
daemon_sftp_alias: Nullable<string>
|
|
27
|
-
daemon_base: string
|
|
28
|
-
daemon_connect: number
|
|
29
|
-
created_at: string
|
|
30
|
-
updated_at: Nullable<string>
|
|
31
|
-
tags: string[]
|
|
32
|
-
allocated_resources: {memory: number; disk: number; cpu: number}
|
|
33
|
-
relationships?: {
|
|
34
|
-
allocations?: GenericListResponse<
|
|
35
|
-
GenericResponse<Allocation, "allocation">
|
|
36
|
-
>
|
|
37
|
-
location?: GenericResponse<Location, "location">
|
|
38
|
-
servers?: GenericListResponse<
|
|
39
|
-
GenericResponse<ApplicationServer, "server">
|
|
40
|
-
>
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type NodeConfiguration = {
|
|
45
|
-
debug: boolean
|
|
46
|
-
uuid: string
|
|
47
|
-
token_id: string
|
|
48
|
-
token: string
|
|
49
|
-
api: {
|
|
50
|
-
host: string
|
|
51
|
-
port: number
|
|
52
|
-
upload_limit: number
|
|
53
|
-
ssl: {enabled: boolean; cert: string; key: string}
|
|
54
|
-
}
|
|
55
|
-
system: {data: string; sftp: {bind_port: number}}
|
|
56
|
-
allowed_mounts: string[]
|
|
57
|
-
remote: string
|
|
58
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {FeatureLimits, ServerLimits} from "@/api/common/types/server_limits"
|
|
2
|
-
import {Container} from "@/api/application/types/container"
|
|
3
|
-
import {Nullable} from "@/utils/types"
|
|
4
|
-
|
|
5
|
-
export type ApplicationServer = {
|
|
6
|
-
id: number
|
|
7
|
-
external_id: Nullable<string>
|
|
8
|
-
uuid: string
|
|
9
|
-
identifier: string
|
|
10
|
-
name: string
|
|
11
|
-
description: string
|
|
12
|
-
status: Nullable<unknown>
|
|
13
|
-
docker_labels: Record<string, string>
|
|
14
|
-
suspended: boolean
|
|
15
|
-
limits: ServerLimits
|
|
16
|
-
feature_limits: FeatureLimits
|
|
17
|
-
user: number
|
|
18
|
-
node: number
|
|
19
|
-
allocation: number
|
|
20
|
-
egg: number
|
|
21
|
-
container: Container
|
|
22
|
-
created_at: string
|
|
23
|
-
updated_at: Nullable<string>
|
|
24
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {GenericResponse} from "@/api/base/types"
|
|
2
|
-
import {ApplicationServer} from "@/api/application/types/server"
|
|
3
|
-
import {Node} from "@/api/application/types/node"
|
|
4
|
-
import {Nullable} from "@/utils/types"
|
|
5
|
-
|
|
6
|
-
export type Allocation = {
|
|
7
|
-
id: number
|
|
8
|
-
ip: string
|
|
9
|
-
alias: Nullable<string>
|
|
10
|
-
port: number
|
|
11
|
-
notes: Nullable<string>
|
|
12
|
-
assigned: boolean
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type AllocationRel = Allocation & {
|
|
16
|
-
relationships?: {
|
|
17
|
-
node?: GenericResponse<Node, "node">
|
|
18
|
-
server?: GenericResponse<ApplicationServer, "server">
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
2
|
-
import {ApplicationServer} from "@/api/application/types/server"
|
|
3
|
-
import {Nullable} from "@/utils/types"
|
|
4
|
-
|
|
5
|
-
export type ApplicationUser = {
|
|
6
|
-
id: number
|
|
7
|
-
external_id: Nullable<string>
|
|
8
|
-
uuid: string
|
|
9
|
-
username: string
|
|
10
|
-
email: string
|
|
11
|
-
language: string
|
|
12
|
-
root_admin: string
|
|
13
|
-
"2fa_enabled": boolean
|
|
14
|
-
"2fa": boolean
|
|
15
|
-
created_at: string
|
|
16
|
-
updated_at: Nullable<string>
|
|
17
|
-
relationships?: {
|
|
18
|
-
servers: GenericListResponse<GenericResponse<ApplicationServer>>
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type ApplicationUserApiKey = {
|
|
23
|
-
id: number
|
|
24
|
-
user_id: number
|
|
25
|
-
key_type: 1
|
|
26
|
-
identifier: string
|
|
27
|
-
memo: string
|
|
28
|
-
allowed_ips: Array<string>
|
|
29
|
-
permissions: []
|
|
30
|
-
last_used_at: Nullable<string>
|
|
31
|
-
expires_at: Nullable<string>
|
|
32
|
-
created_at: string
|
|
33
|
-
updated_at: string
|
|
34
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import z from "zod"
|
|
3
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
4
|
-
import {
|
|
5
|
-
ApplicationUser,
|
|
6
|
-
ApplicationUserApiKey
|
|
7
|
-
} from "@/api/application/types/user"
|
|
8
|
-
import {ArrayQueryParams, SortParam} from "@/utils/transform"
|
|
9
|
-
import {ExactlyOneKey} from "@/utils/types"
|
|
10
|
-
import {languagesSchema, timezonesSchema} from "@/api/common/types/enums"
|
|
11
|
-
import {APIKey} from "@/api/client/types"
|
|
12
|
-
|
|
13
|
-
export class Users {
|
|
14
|
-
private readonly r: AxiosInstance
|
|
15
|
-
|
|
16
|
-
constructor(requester: AxiosInstance) {
|
|
17
|
-
this.r = requester
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
list = async (
|
|
21
|
-
opts: ListType,
|
|
22
|
-
page: number = 1
|
|
23
|
-
): Promise<ApplicationUser[]> => {
|
|
24
|
-
z.number().positive().parse(page)
|
|
25
|
-
const {data} = await this.r.get<
|
|
26
|
-
GenericListResponse<GenericResponse<ApplicationUser, "user">>
|
|
27
|
-
>("/users", {
|
|
28
|
-
params: {
|
|
29
|
-
include: opts.include?.join(","),
|
|
30
|
-
page,
|
|
31
|
-
...ArrayQueryParams({filters: opts.filters || {}}),
|
|
32
|
-
sort: opts.sort?.id
|
|
33
|
-
? SortParam("id", opts.sort?.id)
|
|
34
|
-
: SortParam("uuid", opts.sort?.uuid!)
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return data.data.map(d => d.attributes)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
info = async (
|
|
42
|
-
id: number,
|
|
43
|
-
{include}: {include?: "servers"[]}
|
|
44
|
-
): Promise<ApplicationUser> => {
|
|
45
|
-
z.number().positive().parse(id)
|
|
46
|
-
const {data} = await this.r.get<
|
|
47
|
-
GenericResponse<ApplicationUser, "user">
|
|
48
|
-
>(`/users/${id}`, {params: {include: include?.join(",")}})
|
|
49
|
-
return data.attributes
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
infoByExternal = async (
|
|
53
|
-
external_id: string,
|
|
54
|
-
{include}: {include?: "servers"[]}
|
|
55
|
-
): Promise<ApplicationUser> => {
|
|
56
|
-
const {data} = await this.r.get<
|
|
57
|
-
GenericResponse<ApplicationUser, "user">
|
|
58
|
-
>(`/users/external/${external_id}`, {
|
|
59
|
-
params: {include: include?.join(",")}
|
|
60
|
-
})
|
|
61
|
-
return data.attributes
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
create = async (
|
|
65
|
-
user: z.infer<typeof CreateSchema>
|
|
66
|
-
): Promise<ApplicationUser> => {
|
|
67
|
-
user = CreateSchema.parse(user)
|
|
68
|
-
const {data} = await this.r.post<
|
|
69
|
-
GenericResponse<ApplicationUser, "user">
|
|
70
|
-
>("/users", user)
|
|
71
|
-
return data.attributes
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
update = async (
|
|
75
|
-
id: number,
|
|
76
|
-
user: z.infer<typeof CreateSchema>
|
|
77
|
-
): Promise<ApplicationUser> => {
|
|
78
|
-
user = CreateSchema.parse(user)
|
|
79
|
-
const {data} = await this.r.patch<
|
|
80
|
-
GenericResponse<ApplicationUser, "user">
|
|
81
|
-
>(`/users/${id}`, user)
|
|
82
|
-
return data.attributes
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
delete = async (id: number): Promise<void> => {
|
|
86
|
-
z.number().positive().parse(id)
|
|
87
|
-
await this.r.delete(`/users/${id}`)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
addRoles = async (id: number, roles: number[]): Promise<void> => {
|
|
91
|
-
z.number().positive().parse(id)
|
|
92
|
-
await this.r.patch(`/users/${id}/roles/assign`, {roles})
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
removeRoles = async (id: number, roles: number[]): Promise<void> => {
|
|
96
|
-
z.number().positive().parse(id)
|
|
97
|
-
await this.r.patch(`/users/${id}/roles/remove`, {roles})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
apiKeys = {
|
|
101
|
-
list: async (id: number): Promise<ApplicationUserApiKey[]> => {
|
|
102
|
-
const {data} = await this.r.get<
|
|
103
|
-
GenericListResponse<
|
|
104
|
-
GenericResponse<ApplicationUserApiKey, "api_key">
|
|
105
|
-
>
|
|
106
|
-
>(`/users/${id}/api-keys`)
|
|
107
|
-
return data.data.map(k => k.attributes)
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
create: async (
|
|
111
|
-
id: number,
|
|
112
|
-
description: string,
|
|
113
|
-
allowed_ips?: string[]
|
|
114
|
-
): Promise<ApplicationUserApiKey & {secret_token: string}> => {
|
|
115
|
-
allowed_ips = z.array(z.ipv4()).optional().parse(allowed_ips)
|
|
116
|
-
const {data} = await this.r.post<
|
|
117
|
-
GenericResponse<
|
|
118
|
-
ApplicationUserApiKey,
|
|
119
|
-
"api_key",
|
|
120
|
-
{secret_token: string}
|
|
121
|
-
>
|
|
122
|
-
>(`/users/${id}/api-keys`, {description, allowed_ips})
|
|
123
|
-
return {...data.attributes, secret_token: data.meta!.secret_token}
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
delete: async (id: number, identifier: string): Promise<void> => {
|
|
127
|
-
await this.r.delete(`/users/${id}/api-keys/${identifier}`)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
type ListType = {include?: "servers"[]; filters?: ListFilters; sort?: ListSort}
|
|
133
|
-
type ListFilters = {
|
|
134
|
-
[key in "email" | "uuid" | "username" | "external_id"]: string
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
type ListSort = ExactlyOneKey<"id" | "uuid", "asc" | "desc">
|
|
138
|
-
|
|
139
|
-
const CreateSchema = z.object({
|
|
140
|
-
email: z.email(),
|
|
141
|
-
external_id: z.string().max(255).optional(),
|
|
142
|
-
username: z.string().min(1).max(255),
|
|
143
|
-
password: z.string().optional(),
|
|
144
|
-
language: languagesSchema,
|
|
145
|
-
timezone: timezonesSchema
|
|
146
|
-
})
|
package/src/api/base/request.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import z from "zod"
|
|
2
|
-
import axios, {AxiosInstance, AxiosResponse} from "axios"
|
|
3
|
-
import {PterodactylError, PterodactylException} from "@/api/base/types"
|
|
4
|
-
|
|
5
|
-
export class Agent {
|
|
6
|
-
private readonly base_url: string
|
|
7
|
-
private readonly token: string
|
|
8
|
-
readonly requester: AxiosInstance
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
url: string,
|
|
12
|
-
token: string,
|
|
13
|
-
type: "client" | "application",
|
|
14
|
-
suffix: string = "/api"
|
|
15
|
-
) {
|
|
16
|
-
this.base_url = z
|
|
17
|
-
.url("Invalid URL Schema")
|
|
18
|
-
.transform(url => new URL(url).href)
|
|
19
|
-
.parse(url)
|
|
20
|
-
this.token = z
|
|
21
|
-
.string()
|
|
22
|
-
.regex(/^(ptl[ac]|pacc|papp)_.+$/, "Invalid token type")
|
|
23
|
-
.parse(token)
|
|
24
|
-
|
|
25
|
-
this.requester = axios.create({
|
|
26
|
-
baseURL: this.base_url.replace(/\/+$/, "") + `${suffix}/${type}`,
|
|
27
|
-
timeout: 3000,
|
|
28
|
-
headers: {Authorization: `Bearer ${this.token}`}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
this.requester.interceptors.response.use(undefined, (error: any) => {
|
|
32
|
-
if (error.response && error.response.status === 400) {
|
|
33
|
-
return Promise.reject(
|
|
34
|
-
new PterodactylException(
|
|
35
|
-
"Invalid request data",
|
|
36
|
-
error.response.data as PterodactylError[],
|
|
37
|
-
error.response.status
|
|
38
|
-
)
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
return Promise.reject(error)
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/api/base/types.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export type GenericResponse<T, N extends string = string, M = undefined> = {
|
|
2
|
-
object: N
|
|
3
|
-
attributes: T
|
|
4
|
-
meta?: M
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type PaginationMeta = {
|
|
8
|
-
total: number
|
|
9
|
-
count: number
|
|
10
|
-
per_page: number
|
|
11
|
-
current_page: number
|
|
12
|
-
total_pages: number
|
|
13
|
-
links: any
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type GenericListResponse<T> = {
|
|
17
|
-
object: "list"
|
|
18
|
-
data: T[]
|
|
19
|
-
meta?: {pagination: PaginationMeta}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type CustomListResponse<T, M> = {object: "list"; data: T[]; meta?: M}
|
|
23
|
-
|
|
24
|
-
export class PterodactylException extends Error {
|
|
25
|
-
data: PterodactylError[]
|
|
26
|
-
status: number
|
|
27
|
-
|
|
28
|
-
constructor(message: string, data: PterodactylError[], status: number) {
|
|
29
|
-
super(message)
|
|
30
|
-
this.data = data
|
|
31
|
-
this.status = status
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type PterodactylError = {
|
|
36
|
-
code: string
|
|
37
|
-
status?: number
|
|
38
|
-
detail: string
|
|
39
|
-
source?: {[key: string]: string}
|
|
40
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import {APIKey, SSHKey, User} from "@/api/client/types/user"
|
|
3
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
4
|
-
import z from "zod"
|
|
5
|
-
|
|
6
|
-
export class Account {
|
|
7
|
-
private readonly r: AxiosInstance
|
|
8
|
-
|
|
9
|
-
constructor(requester: AxiosInstance) {
|
|
10
|
-
this.r = requester
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
info = async (): Promise<User> => {
|
|
14
|
-
const {data} =
|
|
15
|
-
await this.r.get<GenericResponse<User, "user">>("/account")
|
|
16
|
-
return data.attributes
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
updateEmail = async (newEmail: string, password: string): Promise<void> => {
|
|
20
|
-
newEmail = z.email().parse(newEmail)
|
|
21
|
-
await this.r.put("/account/email", {email: newEmail, password})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
updatePassword = async (newPassword: string): Promise<void> => {
|
|
25
|
-
newPassword = z.string().min(8).parse(newPassword)
|
|
26
|
-
await this.r.put("/account/password", {
|
|
27
|
-
password: newPassword,
|
|
28
|
-
password_confirmation: newPassword
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
apiKeys = {
|
|
33
|
-
list: async (): Promise<APIKey[]> => {
|
|
34
|
-
const {data} =
|
|
35
|
-
await this.r.get<
|
|
36
|
-
GenericListResponse<GenericResponse<APIKey, "api_key">>
|
|
37
|
-
>("/account/api-keys")
|
|
38
|
-
return data.data.map(k => k.attributes)
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
create: async (
|
|
42
|
-
description: string,
|
|
43
|
-
allowed_ips?: string[]
|
|
44
|
-
): Promise<APIKey & {secret_token: string}> => {
|
|
45
|
-
allowed_ips = z.array(z.ipv4()).optional().parse(allowed_ips)
|
|
46
|
-
const {data} = await this.r.post<
|
|
47
|
-
GenericResponse<APIKey, "api_key", {secret_token: string}>
|
|
48
|
-
>("/account/api-keys", {description, allowed_ips})
|
|
49
|
-
return {...data.attributes, secret_token: data.meta!.secret_token}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
delete: async (identifier: string): Promise<void> => {
|
|
53
|
-
await this.r.delete(`/account/api-keys/${identifier}`)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
sshKeys = {
|
|
58
|
-
list: async (): Promise<SSHKey[]> => {
|
|
59
|
-
const {data} =
|
|
60
|
-
await this.r.get<
|
|
61
|
-
GenericListResponse<GenericResponse<SSHKey, "ssh_key">>
|
|
62
|
-
>("/account/ssh-keys")
|
|
63
|
-
return data.data.map(k => k.attributes)
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
create: async (name: string, public_key: string): Promise<SSHKey> => {
|
|
67
|
-
const {data} = await this.r.post<
|
|
68
|
-
GenericResponse<SSHKey, "ssh_key">
|
|
69
|
-
>("/account/ssh-keys", {name, public_key})
|
|
70
|
-
return data.attributes
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
delete: async (fingerprint: string): Promise<void> => {
|
|
74
|
-
await this.r.post(`/account/ssh-keys/remove`, {fingerprint})
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/api/client/client.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {Account} from "@/api/client/account"
|
|
2
|
-
import {AxiosInstance} from "axios"
|
|
3
|
-
import {Permission} from "@/api/client/types/user"
|
|
4
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
5
|
-
import {Server} from "@/api/client/types/server"
|
|
6
|
-
import z from "zod"
|
|
7
|
-
import {ServerClient} from "@/api/client/server"
|
|
8
|
-
|
|
9
|
-
export class Client {
|
|
10
|
-
account: Account
|
|
11
|
-
|
|
12
|
-
private readonly r: AxiosInstance
|
|
13
|
-
|
|
14
|
-
constructor(requester: AxiosInstance) {
|
|
15
|
-
this.r = requester
|
|
16
|
-
this.account = new Account(requester)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get $r(): AxiosInstance {
|
|
20
|
-
return this.r
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
listPermissions = async (): Promise<Record<string, Permission>> => {
|
|
24
|
-
const {data} =
|
|
25
|
-
await this.r.get<
|
|
26
|
-
GenericResponse<
|
|
27
|
-
{permissions: Record<string, Permission>},
|
|
28
|
-
"system_permissions"
|
|
29
|
-
>
|
|
30
|
-
>("/permissions")
|
|
31
|
-
|
|
32
|
-
return data.attributes.permissions
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
listServers = async (
|
|
36
|
-
type: "accessible" | "mine" | "admin" | "admin-all" = "accessible",
|
|
37
|
-
page: number = 1,
|
|
38
|
-
per_page: number = 50,
|
|
39
|
-
include?: ("egg" | "subusers")[]
|
|
40
|
-
): Promise<Server[]> => {
|
|
41
|
-
z.number().positive().parse(page)
|
|
42
|
-
const {data} = await this.r.get<
|
|
43
|
-
GenericListResponse<GenericResponse<Server, "server">>
|
|
44
|
-
>("/", {params: {type, page, include: include?.join(",")}})
|
|
45
|
-
return data.data.map(s => s.attributes)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
server = (uuid: string): ServerClient => new ServerClient(this.r, uuid)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/*
|
|
52
|
-
Include: ?include=param1,param2
|
|
53
|
-
Avail: ?param1=val1¶m2=val2
|
|
54
|
-
Filters: ?filter[param1]=val1&filter[param2]=val2
|
|
55
|
-
Sort: ?sort=-param, param=asc, -param=desc
|
|
56
|
-
*/
|
package/src/api/client/server.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import {GenericResponse} from "@/api/base/types"
|
|
3
|
-
import {Server, ServerStats} from "@/api/client/types/server"
|
|
4
|
-
import {ServerDatabases} from "@/api/client/server_databases"
|
|
5
|
-
import {ServerFiles} from "@/api/client/server_files"
|
|
6
|
-
import {ServerSchedules} from "@/api/client/server_schedules"
|
|
7
|
-
import {ServerAllocations} from "@/api/client/server_allocations"
|
|
8
|
-
import {ServerUsers} from "@/api/client/server_users"
|
|
9
|
-
import {ServerBackups} from "@/api/client/server_backups"
|
|
10
|
-
import {ServerStartup} from "@/api/client/server_startup"
|
|
11
|
-
import {ServerSettings} from "@/api/client/server_settings"
|
|
12
|
-
import {ServerWebsocket} from "@/api/client/server_websocket"
|
|
13
|
-
import {ServerActivity} from "@/api/client/server_activity"
|
|
14
|
-
|
|
15
|
-
export class ServerClient {
|
|
16
|
-
private readonly r: AxiosInstance
|
|
17
|
-
private readonly id: string
|
|
18
|
-
|
|
19
|
-
activity: ServerActivity
|
|
20
|
-
databases: ServerDatabases
|
|
21
|
-
files: ServerFiles
|
|
22
|
-
schedules: ServerSchedules
|
|
23
|
-
allocations: ServerAllocations
|
|
24
|
-
users: ServerUsers
|
|
25
|
-
backups: ServerBackups
|
|
26
|
-
startup: ServerStartup
|
|
27
|
-
variables: ServerStartup
|
|
28
|
-
settings: ServerSettings
|
|
29
|
-
|
|
30
|
-
constructor(requester: AxiosInstance, id: string) {
|
|
31
|
-
this.r = requester
|
|
32
|
-
this.id = id
|
|
33
|
-
|
|
34
|
-
this.activity = new ServerActivity(requester, id)
|
|
35
|
-
this.databases = new ServerDatabases(requester, id)
|
|
36
|
-
this.files = new ServerFiles(requester, id)
|
|
37
|
-
this.schedules = new ServerSchedules(requester, id)
|
|
38
|
-
this.allocations = new ServerAllocations(requester, id)
|
|
39
|
-
this.users = new ServerUsers(requester, id)
|
|
40
|
-
this.backups = new ServerBackups(requester, id)
|
|
41
|
-
this.startup = new ServerStartup(requester, id)
|
|
42
|
-
this.variables = this.startup // preferable
|
|
43
|
-
this.settings = new ServerSettings(requester, id)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
info = async (include?: ("egg" | "subusers")[]): Promise<Server> => {
|
|
47
|
-
const {data} = await this.r.get<GenericResponse<Server, "server">>(
|
|
48
|
-
`/servers/${this.id}`,
|
|
49
|
-
{params: {include: include?.join(",")}}
|
|
50
|
-
)
|
|
51
|
-
return data.attributes
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
websocket = (stripColors: boolean = false): ServerWebsocket => {
|
|
55
|
-
return new ServerWebsocket(this.r, this.id, stripColors)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
resources = async (): Promise<ServerStats> => {
|
|
59
|
-
const {data} = await this.r.get<GenericResponse<ServerStats, "stats">>(
|
|
60
|
-
`/servers/${this.id}/resources`
|
|
61
|
-
)
|
|
62
|
-
return data.attributes
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
command = async (command: string): Promise<void> => {
|
|
66
|
-
await this.r.post(`/servers/${this.id}/command`, {command})
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
power = async (
|
|
70
|
-
signal: "start" | "stop" | "restart" | "kill"
|
|
71
|
-
): Promise<void> => {
|
|
72
|
-
await this.r.post(`/servers/${this.id}/power`, {signal})
|
|
73
|
-
}
|
|
74
|
-
}
|