@pelican.ts/sdk 0.4.12 → 0.4.14
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/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 {AxiosInstance} from "axios"
|
|
2
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
3
|
-
import {DatabaseHost} from "@/api/application/types/database_host"
|
|
4
|
-
import z from "zod"
|
|
5
|
-
|
|
6
|
-
export class DatabaseHosts {
|
|
7
|
-
private readonly r: AxiosInstance
|
|
8
|
-
|
|
9
|
-
constructor(r: AxiosInstance) {
|
|
10
|
-
this.r = r
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
list = async (page: number = 1): Promise<DatabaseHost[]> => {
|
|
14
|
-
const {data} = await this.r.get<
|
|
15
|
-
GenericListResponse<GenericResponse<DatabaseHost, "database_host">>
|
|
16
|
-
>("/database-hosts", {params: {page}})
|
|
17
|
-
return data.data.map(d => d.attributes)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
info = async (id: string): Promise<DatabaseHost> => {
|
|
21
|
-
const {data} = await this.r.get<
|
|
22
|
-
GenericResponse<DatabaseHost, "database_host">
|
|
23
|
-
>(`/database-hosts/${id}`)
|
|
24
|
-
return data.attributes
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// TODO: find out why API returns 500
|
|
28
|
-
create = async (
|
|
29
|
-
opts: z.infer<typeof CreateDBHostSchema>
|
|
30
|
-
): Promise<void> => {
|
|
31
|
-
opts = CreateDBHostSchema.parse(opts)
|
|
32
|
-
await this.r
|
|
33
|
-
.post<GenericResponse<DatabaseHost, "database_host">>(
|
|
34
|
-
"/database-hosts",
|
|
35
|
-
opts
|
|
36
|
-
)
|
|
37
|
-
.catch(e => {})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
update = async (
|
|
41
|
-
id: string,
|
|
42
|
-
opts: z.infer<typeof CreateDBHostSchema>
|
|
43
|
-
): Promise<DatabaseHost> => {
|
|
44
|
-
opts = CreateDBHostSchema.parse(opts)
|
|
45
|
-
const {data} = await this.r.patch<
|
|
46
|
-
GenericResponse<DatabaseHost, "database_host">
|
|
47
|
-
>(`/database-hosts/${id}`, opts)
|
|
48
|
-
|
|
49
|
-
return data.attributes
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
delete = async (id: string): Promise<void> => {
|
|
53
|
-
await this.r.delete(`/database-hosts/${id}`)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const CreateDBHostSchema = z.object({
|
|
58
|
-
name: z.string().min(1).max(255),
|
|
59
|
-
host: z.string(),
|
|
60
|
-
port: z.number().min(1).max(65535),
|
|
61
|
-
username: z.string().min(1).max(255),
|
|
62
|
-
password: z.string().optional(),
|
|
63
|
-
node_ids: z.array(z.string()).optional(),
|
|
64
|
-
max_databases: z.number().optional()
|
|
65
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
3
|
-
import {Egg, ExportedEgg} from "@/api/application/types/egg"
|
|
4
|
-
|
|
5
|
-
// TODO: API is incomplete
|
|
6
|
-
|
|
7
|
-
export class Eggs {
|
|
8
|
-
private readonly r: AxiosInstance
|
|
9
|
-
|
|
10
|
-
constructor(r: AxiosInstance) {
|
|
11
|
-
this.r = r
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
list = async (): Promise<Egg[]> => {
|
|
15
|
-
const {data} =
|
|
16
|
-
await this.r.get<GenericListResponse<GenericResponse<Egg, "egg">>>(
|
|
17
|
-
"/eggs"
|
|
18
|
-
)
|
|
19
|
-
return data.data.map(d => d.attributes)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
info = async (id: number): Promise<Egg> => {
|
|
23
|
-
const {data} = await this.r.get<GenericResponse<Egg, "egg">>(
|
|
24
|
-
`/eggs/${id}`
|
|
25
|
-
)
|
|
26
|
-
return data.attributes
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export = async (id: number, format: "json" | "yaml"): Promise<string> => {
|
|
30
|
-
const {data} = await this.r.get<string>(`/eggs/${id}/export`, {
|
|
31
|
-
params: {format},
|
|
32
|
-
transformResponse: r => r
|
|
33
|
-
})
|
|
34
|
-
return data
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
infoExportable = async (id: number): Promise<ExportedEgg> => {
|
|
38
|
-
const {data} = await this.r.get<ExportedEgg>(`/eggs/${id}/export`, {
|
|
39
|
-
params: {format: "json"}
|
|
40
|
-
})
|
|
41
|
-
return data
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import {Mount} from "@/api/application/types/mount"
|
|
3
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
4
|
-
import z from "zod"
|
|
5
|
-
import {Egg} from "@/api/application/types/egg"
|
|
6
|
-
import {ApplicationServer} from "@/api/application/types"
|
|
7
|
-
|
|
8
|
-
export class Mounts {
|
|
9
|
-
private readonly r: AxiosInstance
|
|
10
|
-
|
|
11
|
-
constructor(r: AxiosInstance) {
|
|
12
|
-
this.r = r
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
list = async (): Promise<Mount[]> => {
|
|
16
|
-
const {data} =
|
|
17
|
-
await this.r.get<
|
|
18
|
-
GenericListResponse<GenericResponse<Mount, "mount">>
|
|
19
|
-
>("/mounts")
|
|
20
|
-
return data.data.map(d => d.attributes)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
info = async (id: number): Promise<Mount> => {
|
|
24
|
-
const {data} = await this.r.get<GenericResponse<Mount, "mount">>(
|
|
25
|
-
`/mounts/${id}`
|
|
26
|
-
)
|
|
27
|
-
return data.attributes
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
create = async (
|
|
31
|
-
opts: z.infer<typeof CreateMountSchema>
|
|
32
|
-
): Promise<Mount> => {
|
|
33
|
-
opts = CreateMountSchema.parse(opts)
|
|
34
|
-
const {data} = await this.r.post<GenericResponse<Mount, "mount">>(
|
|
35
|
-
"/mounts",
|
|
36
|
-
opts
|
|
37
|
-
)
|
|
38
|
-
return data.attributes
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
update = async (
|
|
42
|
-
id: number,
|
|
43
|
-
opts: z.infer<typeof CreateMountSchema>
|
|
44
|
-
): Promise<Mount> => {
|
|
45
|
-
opts = CreateMountSchema.parse(opts)
|
|
46
|
-
const {data} = await this.r.patch<GenericResponse<Mount, "mount">>(
|
|
47
|
-
`/mounts/${id}`,
|
|
48
|
-
opts
|
|
49
|
-
)
|
|
50
|
-
return data.attributes
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
delete = async (id: number): Promise<void> => {
|
|
54
|
-
await this.r.delete(`/mounts/${id}`)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
listAssignedEggs = async (id: number): Promise<Egg[]> => {
|
|
58
|
-
const {data} = await this.r.get<
|
|
59
|
-
GenericListResponse<GenericResponse<Egg, "egg">>
|
|
60
|
-
>(`/mounts/${id}/eggs`)
|
|
61
|
-
return data.data.map(d => d.attributes)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
assignEggs = async (id: number, eggs: number[]): Promise<void> => {
|
|
65
|
-
await this.r.post(`/mounts/${id}/eggs`, {eggs})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
unassignEgg = async (id: number, egg_id: number): Promise<void> => {
|
|
69
|
-
await this.r.delete(`/mounts/${id}/eggs/${egg_id}`)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
listAssignedNodes = async (id: number): Promise<Node[]> => {
|
|
73
|
-
const {data} = await this.r.get<
|
|
74
|
-
GenericListResponse<GenericResponse<Node, "node">>
|
|
75
|
-
>(`/mounts/${id}/nodes`)
|
|
76
|
-
return data.data.map(d => d.attributes)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
assignNodes = async (id: number, nodes: number[]): Promise<void> => {
|
|
80
|
-
await this.r.post(`/mounts/${id}/nodes`, {nodes})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
unassignNode = async (id: number, node_id: number): Promise<void> => {
|
|
84
|
-
await this.r.delete(`/mounts/${id}/nodes/${node_id}`)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
listAssignedServers = async (id: number): Promise<ApplicationServer[]> => {
|
|
88
|
-
const {data} = await this.r.get<
|
|
89
|
-
GenericListResponse<GenericResponse<ApplicationServer, "server">>
|
|
90
|
-
>(`/mounts/${id}/servers`)
|
|
91
|
-
return data.data.map(d => d.attributes)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
assignServers = async (id: number, servers: number[]): Promise<void> => {
|
|
95
|
-
await this.r.post(`/mounts/${id}/servers`, {servers})
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
unassignServer = async (id: number, server_id: number): Promise<void> => {
|
|
99
|
-
await this.r.delete(`/mounts/${id}/servers/${server_id}`)
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const CreateMountSchema = z.object({
|
|
104
|
-
name: z.string().min(1).max(255),
|
|
105
|
-
description: z.string().optional(),
|
|
106
|
-
source: z.string(),
|
|
107
|
-
target: z.string(),
|
|
108
|
-
read_only: z.boolean().optional()
|
|
109
|
-
})
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import {NodesAllocations} from "@/api/application/nodes_allocations"
|
|
3
|
-
import {ApplicationServer} from "@/api/application/types/server"
|
|
4
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
5
|
-
import z from "zod"
|
|
6
|
-
import {Node, NodeConfiguration} from "@/api/application/types/node"
|
|
7
|
-
|
|
8
|
-
export class Nodes {
|
|
9
|
-
private readonly r: AxiosInstance
|
|
10
|
-
|
|
11
|
-
constructor(requester: AxiosInstance) {
|
|
12
|
-
this.r = requester
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
list = async (
|
|
16
|
-
include?: ("allocations" | "location" | "servers")[],
|
|
17
|
-
page: number = 1
|
|
18
|
-
): Promise<Node[]> => {
|
|
19
|
-
z.number().positive().parse(page)
|
|
20
|
-
const {data} = await this.r.get<
|
|
21
|
-
GenericListResponse<GenericResponse<Node, "node">>
|
|
22
|
-
>("/nodes", {params: {include: include?.join(","), page}})
|
|
23
|
-
return data.data.map(s => s.attributes)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
listDeployable = async (
|
|
27
|
-
filters: {
|
|
28
|
-
disk: number
|
|
29
|
-
memory: number
|
|
30
|
-
cpu?: number
|
|
31
|
-
location_ids?: string[]
|
|
32
|
-
tags?: string[]
|
|
33
|
-
},
|
|
34
|
-
include?: ("allocations" | "location" | "servers")[],
|
|
35
|
-
page: number = 1
|
|
36
|
-
): Promise<Node[]> => {
|
|
37
|
-
z.number().positive().parse(page)
|
|
38
|
-
const {data} = await this.r.get<
|
|
39
|
-
GenericListResponse<GenericResponse<Node, "node">>
|
|
40
|
-
>("/nodes/deployable", {
|
|
41
|
-
params: {
|
|
42
|
-
include: include?.join(","),
|
|
43
|
-
disk: filters.disk,
|
|
44
|
-
memory: filters.memory,
|
|
45
|
-
cpu: filters.cpu,
|
|
46
|
-
location_ids: filters.location_ids,
|
|
47
|
-
tags: filters.tags,
|
|
48
|
-
page: page
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
return data.data.map(s => s.attributes)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
info = async (
|
|
55
|
-
id: number,
|
|
56
|
-
include?: ("allocations" | "location" | "servers")[]
|
|
57
|
-
): Promise<Node> => {
|
|
58
|
-
z.number().positive().parse(id)
|
|
59
|
-
const {data} = await this.r.get<GenericResponse<Node, "node">>(
|
|
60
|
-
`/nodes/${id}`,
|
|
61
|
-
{params: {include: include?.join(",")}}
|
|
62
|
-
)
|
|
63
|
-
return data.attributes
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
create = async (node: z.infer<typeof NodeCreateSchema>): Promise<Node> => {
|
|
67
|
-
node = NodeCreateSchema.parse(node)
|
|
68
|
-
const {data} = await this.r.post<GenericResponse<Node, "node">>(
|
|
69
|
-
"/nodes",
|
|
70
|
-
node
|
|
71
|
-
)
|
|
72
|
-
return data.attributes
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get_configuration = async (id: number): Promise<NodeConfiguration> => {
|
|
76
|
-
z.number().positive().parse(id)
|
|
77
|
-
const {data} = await this.r.get<NodeConfiguration>(
|
|
78
|
-
`/nodes/${id}/configuration`
|
|
79
|
-
)
|
|
80
|
-
return data
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
update = async (
|
|
84
|
-
id: number,
|
|
85
|
-
node: z.infer<typeof NodeCreateSchema>
|
|
86
|
-
): Promise<Node> => {
|
|
87
|
-
z.number().positive().parse(id)
|
|
88
|
-
node = NodeCreateSchema.parse(node)
|
|
89
|
-
const {data} = await this.r.patch<GenericResponse<Node, "node">>(
|
|
90
|
-
`/nodes/${id}`,
|
|
91
|
-
node
|
|
92
|
-
)
|
|
93
|
-
return data.attributes
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
delete = async (id: number): Promise<void> => {
|
|
97
|
-
z.number().positive().parse(id)
|
|
98
|
-
await this.r.delete(`/nodes/${id}`)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
allocations = (server_id: number): NodesAllocations =>
|
|
102
|
-
new NodesAllocations(this.r, server_id)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const NodeCreateSchema = z.object({
|
|
106
|
-
name: z.string().min(1).max(100),
|
|
107
|
-
description: z.string().optional(),
|
|
108
|
-
public: z.boolean().optional(),
|
|
109
|
-
fqdn: z.string().nonempty(),
|
|
110
|
-
scheme: z.enum(["http", "https"]),
|
|
111
|
-
behind_proxy: z.boolean().optional(),
|
|
112
|
-
memory: z.number().min(0),
|
|
113
|
-
memory_overallocate: z.number().min(-1),
|
|
114
|
-
disk: z.number().min(0),
|
|
115
|
-
disk_overallocate: z.number().min(-1),
|
|
116
|
-
cpu: z.number().min(0),
|
|
117
|
-
cpu_overallocate: z.number().min(-1),
|
|
118
|
-
daemon_base: z.string().nonempty().optional(),
|
|
119
|
-
daemon_sftp: z.number().min(1).max(65535),
|
|
120
|
-
daemon_sftp_alias: z.string().optional(),
|
|
121
|
-
daemon_listen: z.number().min(1).max(65535),
|
|
122
|
-
daemon_connect: z.number().min(1).max(65535),
|
|
123
|
-
maintenance_mode: z.boolean().optional(),
|
|
124
|
-
upload_size: z.number().min(1).max(1024),
|
|
125
|
-
tags: z.array(z.string()).optional()
|
|
126
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import {
|
|
3
|
-
Allocation,
|
|
4
|
-
AllocationRel
|
|
5
|
-
} from "@/api/application/types/server_allocation"
|
|
6
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
7
|
-
import z from "zod"
|
|
8
|
-
|
|
9
|
-
export class NodesAllocations {
|
|
10
|
-
private readonly r: AxiosInstance
|
|
11
|
-
private readonly id: number
|
|
12
|
-
|
|
13
|
-
constructor(requester: AxiosInstance, id: number) {
|
|
14
|
-
this.r = requester
|
|
15
|
-
this.id = id
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
list = async (
|
|
19
|
-
include?: ("node" | "server")[]
|
|
20
|
-
): Promise<AllocationRel[]> => {
|
|
21
|
-
const {data} = await this.r.get<
|
|
22
|
-
GenericListResponse<GenericResponse<AllocationRel, "allocation">>
|
|
23
|
-
>(`/nodes/${this.id}/allocations`, {
|
|
24
|
-
params: {include: include?.join(",")}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
return data.data.map(d => d.attributes)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
create = async (
|
|
31
|
-
ip: string,
|
|
32
|
-
ports: string[],
|
|
33
|
-
alias?: string
|
|
34
|
-
): Promise<void> => {
|
|
35
|
-
z.ipv4().parse(ip)
|
|
36
|
-
z.ipv4().or(z.url().max(255)).optional().parse(alias)
|
|
37
|
-
z.array(z.number())
|
|
38
|
-
.or(z.string().regex(/\d+-\d+/))
|
|
39
|
-
.parse(ports)
|
|
40
|
-
|
|
41
|
-
await this.r.post(`/nodes/${this.id}/allocations`, {ip, ports, alias})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
delete = async (alloc_id: number): Promise<void> => {
|
|
45
|
-
await this.r.delete(`/nodes/${this.id}/allocations/${alloc_id}`)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
3
|
-
import {Role} from "@/api/application/types/role"
|
|
4
|
-
|
|
5
|
-
// TODO: API is incomplete
|
|
6
|
-
|
|
7
|
-
export class Roles {
|
|
8
|
-
private readonly r: AxiosInstance
|
|
9
|
-
|
|
10
|
-
constructor(r: AxiosInstance) {
|
|
11
|
-
this.r = r
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
list = async (page: number = 1): Promise<Role[]> => {
|
|
15
|
-
const {data} = await this.r.get<
|
|
16
|
-
GenericListResponse<GenericResponse<Role, "role">>
|
|
17
|
-
>(`/roles`, {params: {page}})
|
|
18
|
-
return data.data.map(r => r.attributes)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
info = async (id: number): Promise<Role> => {
|
|
22
|
-
const {data} = await this.r.get<GenericResponse<Role, "role">>(
|
|
23
|
-
`/roles/${id}`
|
|
24
|
-
)
|
|
25
|
-
return data.attributes
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
create = async (opts: {name: string}): Promise<void> => {
|
|
29
|
-
await this.r.post(`/roles`, opts)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
update = async (id: number, opts: {name: string}): Promise<void> => {
|
|
33
|
-
await this.r.patch(`/roles/${id}`, opts)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
delete = async (id: number): Promise<void> => {
|
|
37
|
-
await this.r.delete(`/roles/${id}`)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import z from "zod"
|
|
3
|
-
import {GenericResponse} from "@/api/base/types"
|
|
4
|
-
import {ApplicationServer} from "@/api/application/types/server"
|
|
5
|
-
import {ServersDatabases} from "@/api/application/servers_databases"
|
|
6
|
-
|
|
7
|
-
export class Servers {
|
|
8
|
-
private readonly r: AxiosInstance
|
|
9
|
-
private readonly id: number
|
|
10
|
-
databases: ServersDatabases
|
|
11
|
-
|
|
12
|
-
constructor(r: AxiosInstance, server_id: number) {
|
|
13
|
-
this.r = r
|
|
14
|
-
this.id = server_id
|
|
15
|
-
|
|
16
|
-
this.databases = new ServersDatabases(this.r, this.id)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
info = async (
|
|
20
|
-
include?: ("egg" | "subusers")[]
|
|
21
|
-
): Promise<ApplicationServer> => {
|
|
22
|
-
const {data} = await this.r.get<
|
|
23
|
-
GenericResponse<ApplicationServer, "server">
|
|
24
|
-
>(`/servers/${this.id}`, {params: {include: include?.join(",")}})
|
|
25
|
-
return data.attributes
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
delete = async (force: boolean = false) => {
|
|
29
|
-
await this.r.delete(`/servers/${this.id}${force ? "/force" : ""}`)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
updateDetails = async (
|
|
33
|
-
opts: z.infer<typeof UpdateDetailsSchema>
|
|
34
|
-
): Promise<void> => {
|
|
35
|
-
opts = UpdateDetailsSchema.parse(opts)
|
|
36
|
-
await this.r.patch(`/servers/${this.id}/details`, opts)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
updateBuild = async (
|
|
40
|
-
opts: z.infer<typeof UpdateBuildSchema>
|
|
41
|
-
): Promise<void> => {
|
|
42
|
-
opts = UpdateBuildSchema.parse(opts)
|
|
43
|
-
await this.r.patch(`/servers/${this.id}/build`, opts)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
updateStartup = async (
|
|
47
|
-
opts: z.infer<typeof UpdateStartupSchema>
|
|
48
|
-
): Promise<void> => {
|
|
49
|
-
opts = UpdateStartupSchema.parse(opts)
|
|
50
|
-
await this.r.patch(`/servers/${this.id}/startup`, opts)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
suspend = async (): Promise<void> => {
|
|
54
|
-
await this.r.post(`/servers/${this.id}/suspend`)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
unsuspend = async (): Promise<void> => {
|
|
58
|
-
await this.r.post(`/servers/${this.id}/unsuspend`)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
reinstall = async (): Promise<void> => {
|
|
62
|
-
await this.r.post(`/servers/${this.id}/reinstall`)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
transferStart = async (
|
|
66
|
-
node_id: number,
|
|
67
|
-
allocation_id: number,
|
|
68
|
-
allocation_additional?: string[]
|
|
69
|
-
): Promise<void> => {
|
|
70
|
-
await this.r.post(`/servers/${this.id}/transfer`, {
|
|
71
|
-
node_id,
|
|
72
|
-
allocation_id,
|
|
73
|
-
allocation_additional
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
transferCancel = async (): Promise<void> => {
|
|
78
|
-
await this.r.post(`/servers/${this.id}/transfer/cancel`)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const CreateServerSchema = z.object({
|
|
83
|
-
external_id: z.string().min(1).max(255).optional(),
|
|
84
|
-
name: z.string().min(1).max(255),
|
|
85
|
-
description: z.string().optional(),
|
|
86
|
-
user: z.number(),
|
|
87
|
-
egg: z.number(),
|
|
88
|
-
docker_image: z.string().optional(),
|
|
89
|
-
startup: z.string().optional(),
|
|
90
|
-
environment: z.record(z.string(), z.string()),
|
|
91
|
-
skip_scripts: z.boolean().optional(),
|
|
92
|
-
oom_killer: z.boolean().optional(),
|
|
93
|
-
start_on_completion: z.boolean().optional(),
|
|
94
|
-
docker_labels: z.record(z.string(), z.string()).optional(),
|
|
95
|
-
limits: z.object({
|
|
96
|
-
memory: z.number().min(0),
|
|
97
|
-
swap: z.number().min(-1),
|
|
98
|
-
disk: z.number().min(0),
|
|
99
|
-
io: z.number().min(0),
|
|
100
|
-
threads: z.string().optional(),
|
|
101
|
-
cpu: z.number().min(0)
|
|
102
|
-
}),
|
|
103
|
-
feature_limits: z.object({
|
|
104
|
-
databases: z.number().min(0),
|
|
105
|
-
allocations: z.number().min(0),
|
|
106
|
-
backups: z.number().min(0)
|
|
107
|
-
}),
|
|
108
|
-
allocation: z
|
|
109
|
-
.object({
|
|
110
|
-
default: z.string(),
|
|
111
|
-
additional: z.array(z.string()).optional()
|
|
112
|
-
})
|
|
113
|
-
.optional(),
|
|
114
|
-
deploy: z
|
|
115
|
-
.object({
|
|
116
|
-
tags: z.array(z.string()).optional(),
|
|
117
|
-
dedicated_ip: z.boolean().optional(),
|
|
118
|
-
port_range: z.array(z.string()).optional()
|
|
119
|
-
})
|
|
120
|
-
.optional()
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
const UpdateDetailsSchema = CreateServerSchema.pick({
|
|
124
|
-
external_id: true,
|
|
125
|
-
name: true,
|
|
126
|
-
user: true,
|
|
127
|
-
description: true,
|
|
128
|
-
docker_labels: true
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
const UpdateBuildSchema = CreateServerSchema.pick({
|
|
132
|
-
oom_killer: true,
|
|
133
|
-
limits: true,
|
|
134
|
-
feature_limits: true
|
|
135
|
-
}).extend({
|
|
136
|
-
allocation: z.number().optional(),
|
|
137
|
-
add_allocations: z.array(z.string()).optional(),
|
|
138
|
-
remove_allocations: z.array(z.string()).optional()
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
const UpdateStartupSchema = CreateServerSchema.pick({
|
|
142
|
-
startup: true,
|
|
143
|
-
environment: true,
|
|
144
|
-
egg: true
|
|
145
|
-
}).extend({image: z.string().optional(), skip_scripts: z.boolean()})
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import {ServerDatabase} from "@/api/common/types/server_database"
|
|
3
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
4
|
-
import z from "zod"
|
|
5
|
-
|
|
6
|
-
// TODO: Check if database type is valid
|
|
7
|
-
export class ServersDatabases {
|
|
8
|
-
private readonly r: AxiosInstance
|
|
9
|
-
private readonly id: number
|
|
10
|
-
|
|
11
|
-
constructor(r: AxiosInstance, server_id: number) {
|
|
12
|
-
this.r = r
|
|
13
|
-
this.id = server_id
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
list = async (): Promise<ServerDatabase[]> => {
|
|
17
|
-
const {data} = await this.r.get<
|
|
18
|
-
GenericListResponse<
|
|
19
|
-
GenericResponse<ServerDatabase, "server_database">
|
|
20
|
-
>
|
|
21
|
-
>(`/servers/${this.id}/databases`)
|
|
22
|
-
return data.data.map(d => d.attributes)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
create = async (
|
|
26
|
-
database: string,
|
|
27
|
-
remote: string,
|
|
28
|
-
host: string
|
|
29
|
-
): Promise<ServerDatabase> => {
|
|
30
|
-
database = z.string().min(1).max(48).parse(database)
|
|
31
|
-
const {data} = await this.r.post<
|
|
32
|
-
GenericResponse<ServerDatabase, "server_database">
|
|
33
|
-
>(`/servers/${this.id}/databases`, {database, remote, host})
|
|
34
|
-
return data.attributes
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
info = async (database_id: number): Promise<ServerDatabase> => {
|
|
38
|
-
const {data} = await this.r.get<
|
|
39
|
-
GenericResponse<ServerDatabase, "server_database">
|
|
40
|
-
>(`/servers/${this.id}/databases/${database_id}`)
|
|
41
|
-
return data.attributes
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
delete = async (database_id: number): Promise<void> => {
|
|
45
|
-
await this.r.delete(`/servers/${this.id}/databases/${database_id}`)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
resetPassword = async (database_id: number): Promise<void> => {
|
|
49
|
-
await this.r.post(
|
|
50
|
-
`/servers/${this.id}/databases/${database_id}/reset-password`
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
}
|