@pelican.ts/sdk 0.2.4 → 0.3.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/README.md +4 -4
- package/dist/index.d.mts +118 -36
- package/dist/index.d.ts +118 -36
- package/dist/index.js +97 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -3
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +1121 -0
- package/package.json +11 -3
- package/scripts/create-types.ts +24 -0
- package/src/api/application/client.ts +13 -7
- package/src/api/application/eggs.ts +31 -0
- package/src/api/application/mounts.ts +96 -0
- package/src/api/application/nodes.ts +1 -1
- package/src/api/application/servers.ts +3 -3
- package/src/api/application/types/egg.ts +37 -0
- package/src/api/application/types/index.ts +10 -0
- package/src/api/application/types/mount.ts +12 -0
- package/src/api/application/types/node.ts +2 -2
- package/src/api/application/types/server.ts +1 -1
- package/src/api/application/types/server_allocation.ts +2 -2
- package/src/api/application/types/user.ts +3 -3
- package/src/api/application/users.ts +11 -11
- package/src/api/client/server_allocations.ts +9 -9
- package/src/api/client/server_backups.ts +7 -7
- package/src/api/client/types/index.ts +5 -0
- package/src/api/client/types/server.ts +2 -2
- package/src/api/client/types/server_allocation.ts +1 -1
- package/src/api/common/types/index.ts +9 -0
- package/src/api/common/types/server_backup.ts +1 -1
- package/src/types.ts +3 -0
package/package.json
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pelican.ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Pelican panel SDK for TypeScript",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./types": {
|
|
10
|
+
"types": "./dist/types.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
8
13
|
"scripts": {
|
|
9
|
-
"build": "tsup src/index.ts --format esm,cjs --dts --sourcemap --target esnext",
|
|
10
|
-
"
|
|
14
|
+
"build:code": "tsup src/index.ts --format esm,cjs --dts --sourcemap --target esnext",
|
|
15
|
+
"build:types": "tsup src/types.ts --dts-only --target esnext",
|
|
16
|
+
"build": "npm run build:code && npm run build:types",
|
|
17
|
+
"pub": "npm publish --access=public",
|
|
18
|
+
"generate-types": "bun run scripts/create-types.ts"
|
|
11
19
|
},
|
|
12
20
|
"keywords": ["pterodactyl", "pterodactyl.ts", "pterodactyl.js", "pelican", "pelican.ts", "pelican.js"],
|
|
13
21
|
"author": "M41den",
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
import fs from "fs"
|
|
3
|
+
import path from "path"
|
|
4
|
+
|
|
5
|
+
const typesPaths = [
|
|
6
|
+
"./api/common/types",
|
|
7
|
+
"./api/application/types",
|
|
8
|
+
"./api/client/types"
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
typesPaths.forEach(p => {
|
|
12
|
+
const prefix = path.join(__dirname, "../src" , p)
|
|
13
|
+
const files = fs.readdirSync(prefix)
|
|
14
|
+
.filter(f => f!=="index.ts")
|
|
15
|
+
.map(f => f.replace(/\.ts$/, ""))
|
|
16
|
+
const strings: Array<string> = []
|
|
17
|
+
files.forEach(f => {
|
|
18
|
+
strings.push(`export * from "./${f}"`)
|
|
19
|
+
})
|
|
20
|
+
fs.writeFileSync(path.join(prefix, "index.ts"), strings.join("\n"))
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const strings = typesPaths.map(p => `export * from "${p}"`)
|
|
24
|
+
fs.writeFileSync(path.join(__dirname, "../src/types.ts"), strings.join("\n"))
|
|
@@ -2,11 +2,13 @@ import {AxiosInstance} from "axios";
|
|
|
2
2
|
import {Users} from "@/api/application/users";
|
|
3
3
|
import {Nodes} from "@/api/application/nodes";
|
|
4
4
|
import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
5
|
-
import {
|
|
5
|
+
import {ApplicationServer} from "@/api/application/types/server";
|
|
6
6
|
import {CreateServerSchema, Servers} from "@/api/application/servers";
|
|
7
7
|
import z from "zod";
|
|
8
8
|
import {DatabaseHosts} from "@/api/application/database_hosts";
|
|
9
9
|
import {Roles} from "@/api/application/roles";
|
|
10
|
+
import {Eggs} from "@/api/application/eggs";
|
|
11
|
+
import {Mounts} from "@/api/application/mounts";
|
|
10
12
|
|
|
11
13
|
export class Client {
|
|
12
14
|
private readonly r: AxiosInstance
|
|
@@ -14,6 +16,8 @@ export class Client {
|
|
|
14
16
|
nodes: Nodes
|
|
15
17
|
databaseHosts: DatabaseHosts
|
|
16
18
|
roles: Roles
|
|
19
|
+
eggs: Eggs
|
|
20
|
+
mounts: Mounts
|
|
17
21
|
|
|
18
22
|
constructor(requester: AxiosInstance) {
|
|
19
23
|
this.r = requester
|
|
@@ -22,28 +26,30 @@ export class Client {
|
|
|
22
26
|
this.nodes = new Nodes(requester)
|
|
23
27
|
this.databaseHosts = new DatabaseHosts(requester)
|
|
24
28
|
this.roles = new Roles(requester)
|
|
29
|
+
this.eggs = new Eggs(requester)
|
|
30
|
+
this.mounts = new Mounts(requester)
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
listServers = async (
|
|
28
34
|
search?: string,
|
|
29
35
|
page: number = 1
|
|
30
|
-
): Promise<
|
|
36
|
+
): Promise<ApplicationServer[]> => {
|
|
31
37
|
const {data} = await this.r.get<
|
|
32
|
-
GenericListResponse<GenericResponse<
|
|
38
|
+
GenericListResponse<GenericResponse<ApplicationServer, "server">>
|
|
33
39
|
>("/servers", {
|
|
34
40
|
params: {search, page}
|
|
35
41
|
})
|
|
36
42
|
return data.data.map(s => s.attributes)
|
|
37
43
|
}
|
|
38
44
|
|
|
39
|
-
createServer = async (opts: z.infer<typeof CreateServerSchema>): Promise<
|
|
45
|
+
createServer = async (opts: z.infer<typeof CreateServerSchema>): Promise<ApplicationServer> => {
|
|
40
46
|
opts = CreateServerSchema.parse(opts)
|
|
41
|
-
const {data} = await this.r.post<GenericResponse<
|
|
47
|
+
const {data} = await this.r.post<GenericResponse<ApplicationServer, "server">>("/servers", opts)
|
|
42
48
|
return data.attributes
|
|
43
49
|
}
|
|
44
50
|
|
|
45
|
-
getServerByExternalId = async (external_id: string, include?: ("egg" | "subusers")[]): Promise<
|
|
46
|
-
const {data} = await this.r.get<GenericResponse<
|
|
51
|
+
getServerByExternalId = async (external_id: string, include?: ("egg" | "subusers")[]): Promise<ApplicationServer> => {
|
|
52
|
+
const {data} = await this.r.get<GenericResponse<ApplicationServer, "server">>(`/servers/external/${external_id}`, {
|
|
47
53
|
params: {include: include?.join(",")}
|
|
48
54
|
})
|
|
49
55
|
return data.attributes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {AxiosInstance} from "axios";
|
|
2
|
+
import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
3
|
+
import {Egg} 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} = await this.r.get<GenericListResponse<GenericResponse<Egg, "egg">>>("/eggs")
|
|
16
|
+
return data.data.map(d => d.attributes)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
info = async (id: number): Promise<Egg> => {
|
|
20
|
+
const {data} = await this.r.get<GenericResponse<Egg, "egg">>(`/eggs/${id}`)
|
|
21
|
+
return data.attributes
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export = async (id: number, format: "json" | "yaml"): Promise<string> => {
|
|
25
|
+
const {data} = await this.r.get<string>(`/eggs/${id}/export`, {
|
|
26
|
+
params: {format},
|
|
27
|
+
transformResponse: r => r
|
|
28
|
+
})
|
|
29
|
+
return data
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
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} = await this.r.get<
|
|
17
|
+
GenericListResponse<GenericResponse<Mount, "mount">>
|
|
18
|
+
>("/mounts")
|
|
19
|
+
return data.data.map(d => d.attributes)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
info = async (id: number): Promise<Mount> => {
|
|
23
|
+
const {data} = await this.r.get<GenericResponse<Mount, "mount">>(`/mounts/${id}`)
|
|
24
|
+
return data.attributes
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
create = async (opts: z.infer<typeof CreateMountSchema>): Promise<Mount> => {
|
|
28
|
+
opts = CreateMountSchema.parse(opts)
|
|
29
|
+
const {data} = await this.r.post<GenericResponse<Mount, "mount">>("/mounts", opts)
|
|
30
|
+
return data.attributes
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
update = async (id: number, opts: z.infer<typeof CreateMountSchema>): Promise<Mount> => {
|
|
34
|
+
opts = CreateMountSchema.parse(opts)
|
|
35
|
+
const {data} = await this.r.patch<GenericResponse<Mount, "mount">>(`/mounts/${id}`, opts)
|
|
36
|
+
return data.attributes
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
delete = async (id: number): Promise<void> => {
|
|
40
|
+
await this.r.delete(`/mounts/${id}`)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
listAssignedEggs = async (id: number): Promise<Egg[]> => {
|
|
44
|
+
const {data} = await this.r.get<
|
|
45
|
+
GenericListResponse<GenericResponse<Egg, "egg">>
|
|
46
|
+
>(`/mounts/${id}/eggs`)
|
|
47
|
+
return data.data.map(d => d.attributes)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
assignEggs = async (id: number, eggs: number[]): Promise<void> => {
|
|
51
|
+
await this.r.post(`/mounts/${id}/eggs`, {eggs})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
unassignEgg = async (id: number, egg_id: number): Promise<void> => {
|
|
55
|
+
await this.r.delete(`/mounts/${id}/eggs/${egg_id}`)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
listAssignedNodes = async (id: number): Promise<Node[]> => {
|
|
59
|
+
const {data} = await this.r.get<
|
|
60
|
+
GenericListResponse<GenericResponse<Node, "node">>
|
|
61
|
+
>(`/mounts/${id}/nodes`)
|
|
62
|
+
return data.data.map(d => d.attributes)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
assignNodes = async (id: number, nodes: number[]): Promise<void> => {
|
|
66
|
+
await this.r.post(`/mounts/${id}/nodes`, {nodes})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
unassignNode = async (id: number, node_id: number): Promise<void> => {
|
|
70
|
+
await this.r.delete(`/mounts/${id}/nodes/${node_id}`)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
listAssignedServers = async (id: number): Promise<ApplicationServer[]> => {
|
|
74
|
+
const {data} = await this.r.get<
|
|
75
|
+
GenericListResponse<GenericResponse<ApplicationServer, "server">>
|
|
76
|
+
>(`/mounts/${id}/servers`)
|
|
77
|
+
return data.data.map(d => d.attributes)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
assignServers = async (id: number, servers: number[]): Promise<void> => {
|
|
81
|
+
await this.r.post(`/mounts/${id}/servers`, {servers})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
unassignServer = async (id: number, server_id: number): Promise<void> => {
|
|
85
|
+
await this.r.delete(`/mounts/${id}/servers/${server_id}`)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
const CreateMountSchema = z.object({
|
|
91
|
+
name: z.string().min(1).max(255),
|
|
92
|
+
description: z.string().optional(),
|
|
93
|
+
source: z.string(),
|
|
94
|
+
target: z.string(),
|
|
95
|
+
read_only: z.boolean().optional()
|
|
96
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {AxiosInstance} from "axios";
|
|
2
2
|
import {NodesAllocations} from "@/api/application/nodes_allocations";
|
|
3
|
-
import {
|
|
3
|
+
import {ApplicationServer} from "@/api/application/types/server";
|
|
4
4
|
import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
5
5
|
import z from "zod";
|
|
6
6
|
import {Node, NodeConfiguration} from "@/api/application/types/node";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {AxiosInstance} from "axios";
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import {GenericResponse} from "@/api/base/types";
|
|
4
|
-
import {
|
|
4
|
+
import {ApplicationServer} from "@/api/application/types/server";
|
|
5
5
|
import {ServersDatabases} from "@/api/application/servers_databases";
|
|
6
6
|
|
|
7
7
|
export class Servers {
|
|
@@ -16,8 +16,8 @@ export class Servers {
|
|
|
16
16
|
this.databases = new ServersDatabases(this.r, this.id)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
info = async (include?: ("egg" | "subusers")[]): Promise<
|
|
20
|
-
const {data} = await this.r.get<GenericResponse<
|
|
19
|
+
info = async (include?: ("egg" | "subusers")[]): Promise<ApplicationServer> => {
|
|
20
|
+
const {data} = await this.r.get<GenericResponse<ApplicationServer, "server">>(`/servers/${this.id}`, {
|
|
21
21
|
params: {include: include?.join(",")}
|
|
22
22
|
})
|
|
23
23
|
return data.attributes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {Nullable} from "@/utils/types";
|
|
2
|
+
|
|
3
|
+
export type Egg = {
|
|
4
|
+
id: number,
|
|
5
|
+
uuid: string,
|
|
6
|
+
name: number,
|
|
7
|
+
author: string,
|
|
8
|
+
description: string,
|
|
9
|
+
features: string[],
|
|
10
|
+
tags: string[],
|
|
11
|
+
docker_image: string,
|
|
12
|
+
docker_images: Record<string, string>,
|
|
13
|
+
config: {
|
|
14
|
+
files: Record<string, FileConfig>
|
|
15
|
+
startup: Record<string, string>,
|
|
16
|
+
stop: string,
|
|
17
|
+
logs: object | [],
|
|
18
|
+
file_denylist: string[],
|
|
19
|
+
extends: Nullable<number>
|
|
20
|
+
},
|
|
21
|
+
startup: string,
|
|
22
|
+
startup_commands: Record<string, string>,
|
|
23
|
+
script: {
|
|
24
|
+
privileged: boolean,
|
|
25
|
+
install: string,
|
|
26
|
+
entry: string,
|
|
27
|
+
container: string,
|
|
28
|
+
extends: Nullable<number>
|
|
29
|
+
},
|
|
30
|
+
created_at: string,
|
|
31
|
+
updated_at: Nullable<string>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type FileConfig = {
|
|
35
|
+
parser: string,
|
|
36
|
+
find: Record<string, string>
|
|
37
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
2
2
|
import {Allocation} from "@/api/application/types/server_allocation";
|
|
3
3
|
import {Location} from "@/api/application/types/location";
|
|
4
|
-
import {
|
|
4
|
+
import {ApplicationServer} from "@/api/application/types/server";
|
|
5
5
|
import {Nullable} from "@/utils/types";
|
|
6
6
|
|
|
7
7
|
|
|
@@ -38,7 +38,7 @@ export type Node = {
|
|
|
38
38
|
relationships?: {
|
|
39
39
|
allocations?: GenericListResponse<GenericResponse<Allocation, "allocation">>,
|
|
40
40
|
location?: GenericResponse<Location, "location">,
|
|
41
|
-
servers?: GenericListResponse<GenericResponse<
|
|
41
|
+
servers?: GenericListResponse<GenericResponse<ApplicationServer, "server">>
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {GenericResponse} from "@/api/base/types";
|
|
2
|
-
import {
|
|
2
|
+
import {ApplicationServer} from "@/api/application/types/server";
|
|
3
3
|
import {Node} from "@/api/application/types/node";
|
|
4
4
|
import {Nullable} from "@/utils/types";
|
|
5
5
|
|
|
@@ -16,6 +16,6 @@ export type Allocation = {
|
|
|
16
16
|
export type AllocationRel = Allocation & {
|
|
17
17
|
relationships?: {
|
|
18
18
|
node?: GenericResponse<Node, "node">,
|
|
19
|
-
server?: GenericResponse<
|
|
19
|
+
server?: GenericResponse<ApplicationServer, "server">
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
2
|
-
import {
|
|
2
|
+
import {ApplicationServer} from "@/api/application/types/server";
|
|
3
3
|
import {Nullable} from "@/utils/types";
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type ApplicationUser = {
|
|
6
6
|
id: number,
|
|
7
7
|
external_id: Nullable<string>,
|
|
8
8
|
uuid: string,
|
|
@@ -15,6 +15,6 @@ export type User = {
|
|
|
15
15
|
created_at: string,
|
|
16
16
|
updated_at: Nullable<string>,
|
|
17
17
|
relationships?: {
|
|
18
|
-
servers: GenericListResponse<GenericResponse<
|
|
18
|
+
servers: GenericListResponse<GenericResponse<ApplicationServer>>
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {AxiosInstance} from "axios";
|
|
2
2
|
import z from "zod";
|
|
3
3
|
import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
4
|
-
import {
|
|
4
|
+
import {ApplicationUser} from "@/api/application/types/user";
|
|
5
5
|
import {ArrayQueryParams, SortParam} from "@/utils/transform";
|
|
6
6
|
import {ExactlyOneKey} from "@/utils/types";
|
|
7
7
|
import {languagesSchema, timezonesSchema} from "@/api/common/types/enums";
|
|
@@ -17,10 +17,10 @@ export class Users {
|
|
|
17
17
|
list = async (
|
|
18
18
|
opts: ListType,
|
|
19
19
|
page: number = 1
|
|
20
|
-
): Promise<
|
|
20
|
+
): Promise<ApplicationUser[]> => {
|
|
21
21
|
z.number().positive().parse(page)
|
|
22
22
|
const {data} = await this.r.get<
|
|
23
|
-
GenericListResponse<GenericResponse<
|
|
23
|
+
GenericListResponse<GenericResponse<ApplicationUser, "user">>
|
|
24
24
|
>("/users", {
|
|
25
25
|
params: {
|
|
26
26
|
include: opts.include?.join(","),
|
|
@@ -38,10 +38,10 @@ export class Users {
|
|
|
38
38
|
info = async (
|
|
39
39
|
id: number,
|
|
40
40
|
{include}: { include?: ("servers")[] }
|
|
41
|
-
): Promise<
|
|
41
|
+
): Promise<ApplicationUser> => {
|
|
42
42
|
z.number().positive().parse(id)
|
|
43
43
|
const {data} = await this.r.get<
|
|
44
|
-
GenericResponse<
|
|
44
|
+
GenericResponse<ApplicationUser, "user">
|
|
45
45
|
>(`/users/${id}`, {
|
|
46
46
|
params: {include: include?.join(",")}
|
|
47
47
|
})
|
|
@@ -51,27 +51,27 @@ export class Users {
|
|
|
51
51
|
infoByExternal = async (
|
|
52
52
|
external_id: string,
|
|
53
53
|
{include}: { include?: ("servers")[] }
|
|
54
|
-
): Promise<
|
|
54
|
+
): Promise<ApplicationUser> => {
|
|
55
55
|
const {data} = await this.r.get<
|
|
56
|
-
GenericResponse<
|
|
56
|
+
GenericResponse<ApplicationUser, "user">
|
|
57
57
|
>(`/users/external/${external_id}`, {
|
|
58
58
|
params: {include: include?.join(",")}
|
|
59
59
|
})
|
|
60
60
|
return data.attributes
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
create = async (user: z.infer<typeof CreateSchema>): Promise<
|
|
63
|
+
create = async (user: z.infer<typeof CreateSchema>): Promise<ApplicationUser> => {
|
|
64
64
|
user = CreateSchema.parse(user)
|
|
65
65
|
const {data} = await this.r.post<
|
|
66
|
-
GenericResponse<
|
|
66
|
+
GenericResponse<ApplicationUser, "user">
|
|
67
67
|
>("/users", user)
|
|
68
68
|
return data.attributes
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
update = async (id: number, user: z.infer<typeof CreateSchema>): Promise<
|
|
71
|
+
update = async (id: number, user: z.infer<typeof CreateSchema>): Promise<ApplicationUser> => {
|
|
72
72
|
user = CreateSchema.parse(user)
|
|
73
73
|
const {data} = await this.r.patch<
|
|
74
|
-
GenericResponse<
|
|
74
|
+
GenericResponse<ApplicationUser, "user">
|
|
75
75
|
>(`/users/${id}`, user)
|
|
76
76
|
return data.attributes
|
|
77
77
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {AxiosInstance} from "axios";
|
|
2
2
|
import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
3
|
-
import {
|
|
3
|
+
import {ServerAllocation} from "@/api/client/types/server_allocation";
|
|
4
4
|
|
|
5
5
|
export class ServerAllocations {
|
|
6
6
|
private readonly r: AxiosInstance
|
|
@@ -11,30 +11,30 @@ export class ServerAllocations {
|
|
|
11
11
|
this.id = id
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
list = async (): Promise<
|
|
14
|
+
list = async (): Promise<ServerAllocation[]> => {
|
|
15
15
|
const {data} = await this.r.get<
|
|
16
|
-
GenericListResponse<GenericResponse<
|
|
16
|
+
GenericListResponse<GenericResponse<ServerAllocation, "allocation">>
|
|
17
17
|
>(`/servers/${this.id}/network/allocations`)
|
|
18
18
|
return data.data.map(r => r.attributes)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
autoAssign = async (): Promise<
|
|
21
|
+
autoAssign = async (): Promise<ServerAllocation> => {
|
|
22
22
|
const {data} = await this.r.post<
|
|
23
|
-
GenericResponse<
|
|
23
|
+
GenericResponse<ServerAllocation, "allocation">
|
|
24
24
|
>(`/servers/${this.id}/network/allocations`)
|
|
25
25
|
return data.attributes
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
setNotes = async (alloc_id: number, notes: string): Promise<
|
|
28
|
+
setNotes = async (alloc_id: number, notes: string): Promise<ServerAllocation> => {
|
|
29
29
|
const {data} = await this.r.post<
|
|
30
|
-
GenericResponse<
|
|
30
|
+
GenericResponse<ServerAllocation, "allocation">
|
|
31
31
|
>(`/servers/${this.id}/network/allocations/${alloc_id}`, {notes})
|
|
32
32
|
return data.attributes
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
setPrimary = async (alloc_id: number): Promise<
|
|
35
|
+
setPrimary = async (alloc_id: number): Promise<ServerAllocation> => {
|
|
36
36
|
const {data} = await this.r.post<
|
|
37
|
-
GenericResponse<
|
|
37
|
+
GenericResponse<ServerAllocation, "allocation">
|
|
38
38
|
>(`/servers/${this.id}/network/allocations/${alloc_id}/primary`)
|
|
39
39
|
return data.attributes
|
|
40
40
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios, {AxiosInstance} from "axios";
|
|
2
|
-
import {
|
|
2
|
+
import {ServerBackup} from "@/api/common/types/server_backup";
|
|
3
3
|
import z, {string} from "zod";
|
|
4
4
|
import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
5
5
|
|
|
@@ -13,10 +13,10 @@ export class ServerBackups {
|
|
|
13
13
|
this.id = id
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
list = async (page: number = 1): Promise<
|
|
16
|
+
list = async (page: number = 1): Promise<ServerBackup[]> => {
|
|
17
17
|
z.number().positive().parse(page)
|
|
18
18
|
const {data} = await this.r.get<
|
|
19
|
-
GenericListResponse<GenericResponse<
|
|
19
|
+
GenericListResponse<GenericResponse<ServerBackup, "backup">>
|
|
20
20
|
>(`/servers/${this.id}/backups`, {
|
|
21
21
|
params: {page}
|
|
22
22
|
})
|
|
@@ -28,10 +28,10 @@ export class ServerBackups {
|
|
|
28
28
|
name?: string,
|
|
29
29
|
is_locked: boolean,
|
|
30
30
|
ignored_files: string[],
|
|
31
|
-
}): Promise<
|
|
31
|
+
}): Promise<ServerBackup> => {
|
|
32
32
|
args.name = z.string().max(255).optional().parse(args.name)
|
|
33
33
|
const {data} = await this.r.post<
|
|
34
|
-
GenericResponse<
|
|
34
|
+
GenericResponse<ServerBackup, "backup">
|
|
35
35
|
>(`/servers/${this.id}/backups`, {
|
|
36
36
|
name: args.name,
|
|
37
37
|
is_locked: args.is_locked,
|
|
@@ -40,9 +40,9 @@ export class ServerBackups {
|
|
|
40
40
|
return data.attributes
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
info = async (backup_uuid: string): Promise<
|
|
43
|
+
info = async (backup_uuid: string): Promise<ServerBackup> => {
|
|
44
44
|
const {data} = await this.r.get<
|
|
45
|
-
GenericResponse<
|
|
45
|
+
GenericResponse<ServerBackup, "backup">
|
|
46
46
|
>(`/servers/${this.id}/backups/${backup_uuid}`)
|
|
47
47
|
return data.attributes
|
|
48
48
|
}
|
|
@@ -2,7 +2,7 @@ import {GenericListResponse, GenericResponse} from "@/api/base/types";
|
|
|
2
2
|
import {EggVariable} from "@/api/common/types/egg";
|
|
3
3
|
import {ServerSubuser} from "@/api/client/types/server_subuser";
|
|
4
4
|
import {FeatureLimits, ServerLimits} from "@/api/common/types/server_limits";
|
|
5
|
-
import {
|
|
5
|
+
import {ServerAllocation} from "@/api/client/types/server_allocation";
|
|
6
6
|
import {Nullable} from "@/utils/types";
|
|
7
7
|
|
|
8
8
|
export type Server = {
|
|
@@ -29,7 +29,7 @@ export type Server = {
|
|
|
29
29
|
is_installing: boolean,
|
|
30
30
|
is_transferring: boolean,
|
|
31
31
|
relationships: {
|
|
32
|
-
allocations: GenericListResponse<GenericResponse<
|
|
32
|
+
allocations: GenericListResponse<GenericResponse<ServerAllocation, "allocation">>,
|
|
33
33
|
variables: GenericListResponse<GenericResponse<EggVariable, "egg_variable">>,
|
|
34
34
|
egg?: GenericResponse<{
|
|
35
35
|
uuid: string,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./server_power"
|
|
2
|
+
export * from "./server_database"
|
|
3
|
+
export * from "./server_limits"
|
|
4
|
+
export * from "./server_startup"
|
|
5
|
+
export * from "./server_backup"
|
|
6
|
+
export * from "./egg"
|
|
7
|
+
export * from "./server_files"
|
|
8
|
+
export * from "./enums"
|
|
9
|
+
export * from "./server_schedule"
|
package/src/types.ts
ADDED