@pelican.ts/sdk 0.4.8 → 0.4.10
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 +2 -3
- package/biome.json +42 -32
- package/bun.lock +3 -0
- package/dist/api/index.d.mts +5 -5
- package/dist/api/index.d.ts +5 -5
- package/dist/api/index.js +168 -102
- package/dist/api/index.mjs +168 -102
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +124 -70
- package/dist/index.mjs +124 -70
- package/dist/types.d.ts +1 -1
- package/package.json +60 -59
- package/scripts/create-types.ts +4 -4
- package/src/api/application/client.ts +26 -19
- package/src/api/application/database_hosts.ts +15 -20
- package/src/api/application/eggs.ts +14 -7
- package/src/api/application/mounts.ts +29 -16
- package/src/api/application/nodes.ts +34 -32
- package/src/api/application/nodes_allocations.ts +15 -11
- package/src/api/application/roles.ts +13 -27
- package/src/api/application/servers.ts +36 -27
- package/src/api/application/servers_databases.ts +11 -7
- package/src/api/application/types/container.ts +7 -8
- package/src/api/application/types/database_host.ts +8 -8
- package/src/api/application/types/egg.ts +47 -54
- package/src/api/application/types/location.ts +5 -7
- package/src/api/application/types/mount.ts +9 -9
- package/src/api/application/types/node.ts +49 -59
- package/src/api/application/types/role.ts +4 -6
- package/src/api/application/types/server.ts +21 -22
- package/src/api/application/types/server_allocation.ts +11 -12
- package/src/api/application/types/user.ts +25 -25
- package/src/api/application/users.ts +38 -27
- package/src/api/base/request.ts +28 -17
- package/src/api/base/types.ts +16 -23
- package/src/api/client/account.ts +20 -15
- package/src/api/client/client.ts +17 -18
- package/src/api/client/server.ts +24 -20
- package/src/api/client/server_activity.ts +10 -11
- package/src/api/client/server_allocations.ts +11 -6
- package/src/api/client/server_backups.ts +21 -17
- package/src/api/client/server_databases.ts +14 -8
- package/src/api/client/server_files.ts +56 -42
- package/src/api/client/server_schedules.ts +43 -19
- package/src/api/client/server_settings.ts +11 -8
- package/src/api/client/server_startup.ts +16 -8
- package/src/api/client/server_users.ts +22 -13
- package/src/api/client/server_websocket.ts +79 -33
- package/src/api/client/types/server.ts +8 -18
- package/src/api/client/types/server_allocation.ts +7 -8
- package/src/api/client/types/server_subuser.ts +10 -11
- package/src/api/client/types/user.ts +2 -5
- package/src/api/client/types/websocket.ts +12 -24
- package/src/api/common/types/egg.ts +7 -7
- package/src/api/common/types/enums.ts +1 -1
- package/src/api/common/types/server_backup.ts +4 -5
- package/src/api/common/types/server_database.ts +9 -12
- package/src/api/common/types/server_files.ts +9 -9
- package/src/api/common/types/server_limits.ts +11 -12
- package/src/api/common/types/server_power.ts +1 -1
- package/src/api/common/types/server_schedule.ts +27 -25
- package/src/api/common/types/server_startup.ts +7 -12
- package/src/api/index.ts +3 -3
- package/src/humane/Account.ts +2 -2
- package/src/humane/Client.ts +6 -6
- package/src/humane/Server.ts +31 -43
- package/src/humane/ServerAllocation.ts +3 -3
- package/src/humane/ServerBackup.ts +6 -9
- package/src/humane/ServerDatabase.ts +2 -2
- package/src/humane/ServerFile.ts +17 -11
- package/src/humane/ServerSchedule.ts +6 -6
- package/src/humane/ServerUser.ts +2 -2
- package/src/index.ts +3 -3
- package/src/utils/sized.ts +1 -1
- package/src/utils/transform.ts +5 -10
- package/src/utils/types.ts +6 -8
- package/tsconfig.json +0 -1
|
@@ -1,72 +1,65 @@
|
|
|
1
|
-
import {Nullable} from "@/utils/types"
|
|
2
|
-
import {EggVariable} from "@/api/common/types"
|
|
1
|
+
import {Nullable} from "@/utils/types"
|
|
2
|
+
import {EggVariable} from "@/api/common/types"
|
|
3
3
|
|
|
4
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
|
|
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
14
|
config: {
|
|
15
15
|
files: Record<string, FileConfig>
|
|
16
|
-
startup: Record<string, string
|
|
17
|
-
stop: string
|
|
18
|
-
logs: object | []
|
|
19
|
-
file_denylist: string[]
|
|
16
|
+
startup: Record<string, string>
|
|
17
|
+
stop: string
|
|
18
|
+
logs: object | []
|
|
19
|
+
file_denylist: string[]
|
|
20
20
|
extends: Nullable<number>
|
|
21
|
-
}
|
|
22
|
-
startup: string
|
|
23
|
-
startup_commands: Record<string, string
|
|
21
|
+
}
|
|
22
|
+
startup: string
|
|
23
|
+
startup_commands: Record<string, string>
|
|
24
24
|
script: {
|
|
25
|
-
privileged: boolean
|
|
26
|
-
install: string
|
|
27
|
-
entry: string
|
|
28
|
-
container: string
|
|
25
|
+
privileged: boolean
|
|
26
|
+
install: string
|
|
27
|
+
entry: string
|
|
28
|
+
container: string
|
|
29
29
|
extends: Nullable<number>
|
|
30
|
-
}
|
|
31
|
-
created_at: string
|
|
30
|
+
}
|
|
31
|
+
created_at: string
|
|
32
32
|
updated_at: Nullable<string>
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
type FileConfig = {
|
|
36
|
-
parser: string,
|
|
37
|
-
find: Record<string, string>
|
|
38
|
-
}
|
|
35
|
+
type FileConfig = {parser: string; find: Record<string, string>}
|
|
39
36
|
|
|
40
|
-
export type ApplicationEggVariable = Omit<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
45
|
}
|
|
46
46
|
|
|
47
47
|
export type ExportedEgg = {
|
|
48
|
-
meta: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
author: string,
|
|
55
|
-
description: string,
|
|
56
|
-
uuid: string,
|
|
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
|
|
57
54
|
image: Nullable<string>
|
|
58
|
-
docker_images: Record<string, string
|
|
59
|
-
features: string[]
|
|
60
|
-
tags: string[]
|
|
61
|
-
file_denylist: string[]
|
|
62
|
-
startup_commands: Record<string, string
|
|
55
|
+
docker_images: Record<string, string>
|
|
56
|
+
features: string[]
|
|
57
|
+
tags: string[]
|
|
58
|
+
file_denylist: string[]
|
|
59
|
+
startup_commands: Record<string, string>
|
|
63
60
|
config: Omit<Egg["config"], "extends" | "file_denylist">
|
|
64
61
|
scripts: {
|
|
65
|
-
installation: {
|
|
66
|
-
|
|
67
|
-
container: string,
|
|
68
|
-
entrypoint: string
|
|
69
|
-
}
|
|
70
|
-
},
|
|
62
|
+
installation: {script: string; container: string; entrypoint: string}
|
|
63
|
+
}
|
|
71
64
|
variables: ApplicationEggVariable[]
|
|
72
|
-
}
|
|
65
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {Nullable} from "@/utils/types"
|
|
1
|
+
import {Nullable} from "@/utils/types"
|
|
2
2
|
|
|
3
3
|
export type Mount = {
|
|
4
|
-
id: number
|
|
5
|
-
uuid: string
|
|
6
|
-
name: string
|
|
7
|
-
description: Nullable<string
|
|
8
|
-
source: string
|
|
9
|
-
target: string
|
|
10
|
-
read_only: boolean
|
|
4
|
+
id: number
|
|
5
|
+
uuid: string
|
|
6
|
+
name: string
|
|
7
|
+
description: Nullable<string>
|
|
8
|
+
source: string
|
|
9
|
+
target: string
|
|
10
|
+
read_only: boolean
|
|
11
11
|
user_mountable: boolean
|
|
12
|
-
}
|
|
12
|
+
}
|
|
@@ -1,68 +1,58 @@
|
|
|
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
|
-
|
|
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"
|
|
7
6
|
|
|
8
7
|
export type Node = {
|
|
9
|
-
id: number
|
|
10
|
-
uuid: string
|
|
11
|
-
public: boolean
|
|
12
|
-
name: string
|
|
13
|
-
description: Nullable<string
|
|
14
|
-
fqdn: string
|
|
15
|
-
scheme: "https" | "http"
|
|
16
|
-
behind_proxy: boolean
|
|
17
|
-
maintenance_mode: boolean
|
|
18
|
-
memory: number
|
|
19
|
-
memory_overallocate: number
|
|
20
|
-
disk: number
|
|
21
|
-
disk_overallocate: number
|
|
22
|
-
cpu: number
|
|
23
|
-
cpu_overallocate: number
|
|
24
|
-
upload_size: number
|
|
25
|
-
daemon_listen: number
|
|
26
|
-
daemon_sftp: number
|
|
27
|
-
daemon_sftp_alias: Nullable<string
|
|
28
|
-
daemon_base: string
|
|
29
|
-
daemon_connect: number
|
|
30
|
-
created_at: string
|
|
31
|
-
updated_at: Nullable<string
|
|
32
|
-
tags: string[]
|
|
33
|
-
allocated_resources: {
|
|
34
|
-
memory: number,
|
|
35
|
-
disk: number,
|
|
36
|
-
cpu: number
|
|
37
|
-
},
|
|
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}
|
|
38
33
|
relationships?: {
|
|
39
|
-
allocations?: GenericListResponse<
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
allocations?: GenericListResponse<
|
|
35
|
+
GenericResponse<Allocation, "allocation">
|
|
36
|
+
>
|
|
37
|
+
location?: GenericResponse<Location, "location">
|
|
38
|
+
servers?: GenericListResponse<
|
|
39
|
+
GenericResponse<ApplicationServer, "server">
|
|
40
|
+
>
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
export type NodeConfiguration = {
|
|
46
|
-
debug: boolean
|
|
47
|
-
uuid: string
|
|
48
|
-
token_id: string
|
|
49
|
-
token: string
|
|
45
|
+
debug: boolean
|
|
46
|
+
uuid: string
|
|
47
|
+
token_id: string
|
|
48
|
+
token: string
|
|
50
49
|
api: {
|
|
51
|
-
host: string
|
|
52
|
-
port: number
|
|
53
|
-
upload_limit: number
|
|
54
|
-
ssl: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
system: {
|
|
61
|
-
data: string,
|
|
62
|
-
sftp: {
|
|
63
|
-
bind_port: number,
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
allowed_mounts: string[],
|
|
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[]
|
|
67
57
|
remote: string
|
|
68
|
-
}
|
|
58
|
+
}
|
|
@@ -1,25 +1,24 @@
|
|
|
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
|
-
|
|
1
|
+
import {FeatureLimits, ServerLimits} from "@/api/common/types/server_limits"
|
|
2
|
+
import {Container} from "@/api/application/types/container"
|
|
3
|
+
import {Nullable} from "@/utils/types"
|
|
5
4
|
|
|
6
5
|
export type ApplicationServer = {
|
|
7
|
-
id: number
|
|
8
|
-
external_id: Nullable<string
|
|
9
|
-
uuid: string
|
|
10
|
-
identifier: string
|
|
11
|
-
name: string
|
|
12
|
-
description: string
|
|
13
|
-
status: Nullable<unknown
|
|
14
|
-
docker_labels: Record<string, string
|
|
15
|
-
suspended: boolean
|
|
16
|
-
limits: ServerLimits
|
|
17
|
-
feature_limits: FeatureLimits
|
|
18
|
-
user: number
|
|
19
|
-
node: number
|
|
20
|
-
allocation: number
|
|
21
|
-
egg: number
|
|
22
|
-
container: Container
|
|
23
|
-
created_at: string
|
|
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
|
|
24
23
|
updated_at: Nullable<string>
|
|
25
|
-
}
|
|
24
|
+
}
|
|
@@ -1,21 +1,20 @@
|
|
|
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
|
-
|
|
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"
|
|
6
5
|
|
|
7
6
|
export type Allocation = {
|
|
8
|
-
id: number
|
|
9
|
-
ip: string
|
|
10
|
-
alias: Nullable<string
|
|
11
|
-
port: number
|
|
12
|
-
notes: Nullable<string
|
|
7
|
+
id: number
|
|
8
|
+
ip: string
|
|
9
|
+
alias: Nullable<string>
|
|
10
|
+
port: number
|
|
11
|
+
notes: Nullable<string>
|
|
13
12
|
assigned: boolean
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
export type AllocationRel = Allocation & {
|
|
17
16
|
relationships?: {
|
|
18
|
-
node?: GenericResponse<Node, "node"
|
|
17
|
+
node?: GenericResponse<Node, "node">
|
|
19
18
|
server?: GenericResponse<ApplicationServer, "server">
|
|
20
19
|
}
|
|
21
|
-
}
|
|
20
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
2
|
-
import {ApplicationServer} from "@/api/application/types/server"
|
|
3
|
-
import {Nullable} from "@/utils/types"
|
|
1
|
+
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
2
|
+
import {ApplicationServer} from "@/api/application/types/server"
|
|
3
|
+
import {Nullable} from "@/utils/types"
|
|
4
4
|
|
|
5
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
|
|
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
17
|
relationships?: {
|
|
18
18
|
servers: GenericListResponse<GenericResponse<ApplicationServer>>
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
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
|
|
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
33
|
updated_at: string
|
|
34
|
-
}
|
|
34
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios"
|
|
2
|
-
import z from "zod"
|
|
3
|
-
import {GenericListResponse, GenericResponse} from "@/api/base/types"
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
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"
|
|
10
12
|
|
|
11
13
|
export class Users {
|
|
12
14
|
private readonly r: AxiosInstance
|
|
@@ -38,20 +40,18 @@ export class Users {
|
|
|
38
40
|
|
|
39
41
|
info = async (
|
|
40
42
|
id: number,
|
|
41
|
-
{include}: {
|
|
43
|
+
{include}: {include?: "servers"[]}
|
|
42
44
|
): Promise<ApplicationUser> => {
|
|
43
45
|
z.number().positive().parse(id)
|
|
44
46
|
const {data} = await this.r.get<
|
|
45
47
|
GenericResponse<ApplicationUser, "user">
|
|
46
|
-
>(`/users/${id}`, {
|
|
47
|
-
params: {include: include?.join(",")}
|
|
48
|
-
})
|
|
48
|
+
>(`/users/${id}`, {params: {include: include?.join(",")}})
|
|
49
49
|
return data.attributes
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
infoByExternal = async (
|
|
53
53
|
external_id: string,
|
|
54
|
-
{include}: {
|
|
54
|
+
{include}: {include?: "servers"[]}
|
|
55
55
|
): Promise<ApplicationUser> => {
|
|
56
56
|
const {data} = await this.r.get<
|
|
57
57
|
GenericResponse<ApplicationUser, "user">
|
|
@@ -61,7 +61,9 @@ export class Users {
|
|
|
61
61
|
return data.attributes
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
create = async (
|
|
64
|
+
create = async (
|
|
65
|
+
user: z.infer<typeof CreateSchema>
|
|
66
|
+
): Promise<ApplicationUser> => {
|
|
65
67
|
user = CreateSchema.parse(user)
|
|
66
68
|
const {data} = await this.r.post<
|
|
67
69
|
GenericResponse<ApplicationUser, "user">
|
|
@@ -69,7 +71,10 @@ export class Users {
|
|
|
69
71
|
return data.attributes
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
update = async (
|
|
74
|
+
update = async (
|
|
75
|
+
id: number,
|
|
76
|
+
user: z.infer<typeof CreateSchema>
|
|
77
|
+
): Promise<ApplicationUser> => {
|
|
73
78
|
user = CreateSchema.parse(user)
|
|
74
79
|
const {data} = await this.r.patch<
|
|
75
80
|
GenericResponse<ApplicationUser, "user">
|
|
@@ -95,15 +100,25 @@ export class Users {
|
|
|
95
100
|
apiKeys = {
|
|
96
101
|
list: async (id: number): Promise<ApplicationUserApiKey[]> => {
|
|
97
102
|
const {data} = await this.r.get<
|
|
98
|
-
GenericListResponse<
|
|
103
|
+
GenericListResponse<
|
|
104
|
+
GenericResponse<ApplicationUserApiKey, "api_key">
|
|
105
|
+
>
|
|
99
106
|
>(`/users/${id}/api-keys`)
|
|
100
107
|
return data.data.map(k => k.attributes)
|
|
101
108
|
},
|
|
102
109
|
|
|
103
|
-
create: async (
|
|
110
|
+
create: async (
|
|
111
|
+
id: number,
|
|
112
|
+
description: string,
|
|
113
|
+
allowed_ips?: string[]
|
|
114
|
+
): Promise<ApplicationUserApiKey & {secret_token: string}> => {
|
|
104
115
|
allowed_ips = z.array(z.ipv4()).optional().parse(allowed_ips)
|
|
105
116
|
const {data} = await this.r.post<
|
|
106
|
-
GenericResponse<
|
|
117
|
+
GenericResponse<
|
|
118
|
+
ApplicationUserApiKey,
|
|
119
|
+
"api_key",
|
|
120
|
+
{secret_token: string}
|
|
121
|
+
>
|
|
107
122
|
>(`/users/${id}/api-keys`, {description, allowed_ips})
|
|
108
123
|
return {...data.attributes, secret_token: data.meta!.secret_token}
|
|
109
124
|
},
|
|
@@ -114,14 +129,10 @@ export class Users {
|
|
|
114
129
|
}
|
|
115
130
|
}
|
|
116
131
|
|
|
117
|
-
type ListType = {
|
|
118
|
-
include?: ("servers")[],
|
|
119
|
-
filters?: ListFilters,
|
|
120
|
-
sort?: ListSort
|
|
121
|
-
}
|
|
132
|
+
type ListType = {include?: "servers"[]; filters?: ListFilters; sort?: ListSort}
|
|
122
133
|
type ListFilters = {
|
|
123
|
-
[key in "email" | "uuid" | "username" | "external_id"]: string
|
|
124
|
-
}
|
|
134
|
+
[key in "email" | "uuid" | "username" | "external_id"]: string
|
|
135
|
+
}
|
|
125
136
|
|
|
126
137
|
type ListSort = ExactlyOneKey<"id" | "uuid", "asc" | "desc">
|
|
127
138
|
|
|
@@ -132,4 +143,4 @@ const CreateSchema = z.object({
|
|
|
132
143
|
password: z.string().optional(),
|
|
133
144
|
language: languagesSchema,
|
|
134
145
|
timezone: timezonesSchema
|
|
135
|
-
})
|
|
146
|
+
})
|
package/src/api/base/request.ts
CHANGED
|
@@ -1,33 +1,44 @@
|
|
|
1
1
|
import z from "zod"
|
|
2
|
-
import axios, {AxiosInstance, AxiosResponse} from "axios"
|
|
3
|
-
import {PterodactylError, PterodactylException} from "@/api/base/types"
|
|
2
|
+
import axios, {AxiosInstance, AxiosResponse} from "axios"
|
|
3
|
+
import {PterodactylError, PterodactylException} from "@/api/base/types"
|
|
4
4
|
|
|
5
5
|
export class Agent {
|
|
6
6
|
private readonly base_url: string
|
|
7
7
|
private readonly token: string
|
|
8
8
|
readonly requester: AxiosInstance
|
|
9
9
|
|
|
10
|
-
constructor(
|
|
11
|
-
|
|
12
|
-
|
|
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)
|
|
13
24
|
|
|
14
25
|
this.requester = axios.create({
|
|
15
|
-
baseURL: this.base_url.replace(/\/+$/, "")
|
|
26
|
+
baseURL: this.base_url.replace(/\/+$/, "") + `${suffix}/${type}`,
|
|
16
27
|
timeout: 3000,
|
|
17
|
-
headers: {
|
|
18
|
-
Authorization: `Bearer ${this.token}`
|
|
19
|
-
}
|
|
28
|
+
headers: {Authorization: `Bearer ${this.token}`}
|
|
20
29
|
})
|
|
21
30
|
|
|
22
|
-
this.requester.interceptors.response.use(undefined, (error: any)=>{
|
|
31
|
+
this.requester.interceptors.response.use(undefined, (error: any) => {
|
|
23
32
|
if (error.response && error.response.status === 400) {
|
|
24
|
-
return Promise.reject(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
return Promise.reject(
|
|
34
|
+
new PterodactylException(
|
|
35
|
+
"Invalid request data",
|
|
36
|
+
error.response.data as PterodactylError[],
|
|
37
|
+
error.response.status
|
|
38
|
+
)
|
|
39
|
+
)
|
|
29
40
|
}
|
|
30
|
-
return Promise.reject(error)
|
|
41
|
+
return Promise.reject(error)
|
|
31
42
|
})
|
|
32
43
|
}
|
|
33
|
-
}
|
|
44
|
+
}
|