@pelican.ts/sdk 0.2.2 → 0.2.4

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.
Files changed (200) hide show
  1. package/README.md +11 -8
  2. package/dist/index.d.mts +1502 -0
  3. package/dist/index.d.ts +1500 -7
  4. package/dist/index.js +1979 -19
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1943 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +4 -3
  9. package/src/api/application/client.ts +40 -0
  10. package/src/api/application/database_hosts.ts +70 -0
  11. package/src/api/application/nodes.ts +72 -45
  12. package/src/api/application/nodes_allocations.ts +4 -6
  13. package/src/api/application/roles.ts +53 -0
  14. package/src/api/application/servers.ts +135 -0
  15. package/src/api/application/servers_databases.ts +49 -0
  16. package/src/api/application/types/container.ts +1 -3
  17. package/src/api/application/types/database_host.ts +11 -0
  18. package/src/api/application/types/node.ts +39 -4
  19. package/src/api/application/types/role.ts +8 -0
  20. package/src/api/application/types/server.ts +4 -4
  21. package/src/api/{common/types/server_allocations.ts → application/types/server_allocation.ts} +3 -2
  22. package/src/api/application/types/user.ts +4 -4
  23. package/src/api/application/users.ts +28 -18
  24. package/src/api/base/request.ts +3 -3
  25. package/src/api/client/server_allocations.ts +1 -1
  26. package/src/api/client/server_databases.ts +7 -7
  27. package/src/api/client/types/server.ts +1 -1
  28. package/src/api/client/types/server_allocation.ts +11 -0
  29. package/src/api/common/types/enums.ts +21 -0
  30. package/src/api/common/types/server_database.ts +1 -1
  31. package/src/index.ts +4 -4
  32. package/dist/api/application/client.d.ts +0 -8
  33. package/dist/api/application/client.d.ts.map +0 -1
  34. package/dist/api/application/client.js +0 -14
  35. package/dist/api/application/client.js.map +0 -1
  36. package/dist/api/application/nodes.d.ts +0 -36
  37. package/dist/api/application/nodes.d.ts.map +0 -1
  38. package/dist/api/application/nodes.js +0 -47
  39. package/dist/api/application/nodes.js.map +0 -1
  40. package/dist/api/application/nodes_allocations.d.ts +0 -11
  41. package/dist/api/application/nodes_allocations.d.ts.map +0 -1
  42. package/dist/api/application/nodes_allocations.js +0 -36
  43. package/dist/api/application/nodes_allocations.js.map +0 -1
  44. package/dist/api/application/types/container.d.ts +0 -12
  45. package/dist/api/application/types/container.d.ts.map +0 -1
  46. package/dist/api/application/types/container.js +0 -3
  47. package/dist/api/application/types/container.js.map +0 -1
  48. package/dist/api/application/types/location.d.ts +0 -8
  49. package/dist/api/application/types/location.d.ts.map +0 -1
  50. package/dist/api/application/types/location.js +0 -3
  51. package/dist/api/application/types/location.js.map +0 -1
  52. package/dist/api/application/types/node.d.ts +0 -32
  53. package/dist/api/application/types/node.d.ts.map +0 -1
  54. package/dist/api/application/types/node.js +0 -3
  55. package/dist/api/application/types/node.js.map +0 -1
  56. package/dist/api/application/types/server.d.ts +0 -23
  57. package/dist/api/application/types/server.d.ts.map +0 -1
  58. package/dist/api/application/types/server.js +0 -3
  59. package/dist/api/application/types/server.js.map +0 -1
  60. package/dist/api/application/types/user.d.ts +0 -20
  61. package/dist/api/application/types/user.d.ts.map +0 -1
  62. package/dist/api/application/types/user.js +0 -3
  63. package/dist/api/application/types/user.js.map +0 -1
  64. package/dist/api/application/users.d.ts +0 -38
  65. package/dist/api/application/users.d.ts.map +0 -1
  66. package/dist/api/application/users.js +0 -54
  67. package/dist/api/application/users.js.map +0 -1
  68. package/dist/api/base/request.d.ts +0 -8
  69. package/dist/api/base/request.d.ts.map +0 -1
  70. package/dist/api/base/request.js +0 -33
  71. package/dist/api/base/request.js.map +0 -1
  72. package/dist/api/base/types.d.ts +0 -40
  73. package/dist/api/base/types.d.ts.map +0 -1
  74. package/dist/api/base/types.js +0 -14
  75. package/dist/api/base/types.js.map +0 -1
  76. package/dist/api/client/account.d.ts +0 -31
  77. package/dist/api/client/account.d.ts.map +0 -1
  78. package/dist/api/client/account.js +0 -70
  79. package/dist/api/client/account.js.map +0 -1
  80. package/dist/api/client/client.d.ts +0 -14
  81. package/dist/api/client/client.d.ts.map +0 -1
  82. package/dist/api/client/client.js +0 -37
  83. package/dist/api/client/client.js.map +0 -1
  84. package/dist/api/client/server.d.ts +0 -33
  85. package/dist/api/client/server.d.ts.map +0 -1
  86. package/dist/api/client/server.js +0 -62
  87. package/dist/api/client/server.js.map +0 -1
  88. package/dist/api/client/server_activity.d.ts +0 -9
  89. package/dist/api/client/server_activity.d.ts.map +0 -1
  90. package/dist/api/client/server_activity.js +0 -22
  91. package/dist/api/client/server_activity.js.map +0 -1
  92. package/dist/api/client/server_allocations.d.ts +0 -13
  93. package/dist/api/client/server_allocations.d.ts.map +0 -1
  94. package/dist/api/client/server_allocations.js +0 -32
  95. package/dist/api/client/server_allocations.js.map +0 -1
  96. package/dist/api/client/server_backups.d.ts +0 -18
  97. package/dist/api/client/server_backups.d.ts.map +0 -1
  98. package/dist/api/client/server_backups.js +0 -50
  99. package/dist/api/client/server_backups.js.map +0 -1
  100. package/dist/api/client/server_databases.d.ts +0 -12
  101. package/dist/api/client/server_databases.d.ts.map +0 -1
  102. package/dist/api/client/server_databases.js +0 -36
  103. package/dist/api/client/server_databases.js.map +0 -1
  104. package/dist/api/client/server_files.d.ts +0 -34
  105. package/dist/api/client/server_files.d.ts.map +0 -1
  106. package/dist/api/client/server_files.js +0 -86
  107. package/dist/api/client/server_files.js.map +0 -1
  108. package/dist/api/client/server_schedules.d.ts +0 -38
  109. package/dist/api/client/server_schedules.d.ts.map +0 -1
  110. package/dist/api/client/server_schedules.js +0 -59
  111. package/dist/api/client/server_schedules.js.map +0 -1
  112. package/dist/api/client/server_settings.d.ts +0 -12
  113. package/dist/api/client/server_settings.d.ts.map +0 -1
  114. package/dist/api/client/server_settings.js +0 -30
  115. package/dist/api/client/server_settings.js.map +0 -1
  116. package/dist/api/client/server_startup.d.ts +0 -11
  117. package/dist/api/client/server_startup.d.ts.map +0 -1
  118. package/dist/api/client/server_startup.js +0 -25
  119. package/dist/api/client/server_startup.js.map +0 -1
  120. package/dist/api/client/server_users.d.ts +0 -13
  121. package/dist/api/client/server_users.d.ts.map +0 -1
  122. package/dist/api/client/server_users.js +0 -32
  123. package/dist/api/client/server_users.js.map +0 -1
  124. package/dist/api/client/server_websocket.d.ts +0 -60
  125. package/dist/api/client/server_websocket.d.ts.map +0 -1
  126. package/dist/api/client/server_websocket.js +0 -431
  127. package/dist/api/client/server_websocket.js.map +0 -1
  128. package/dist/api/client/types/server.d.ts +0 -64
  129. package/dist/api/client/types/server.d.ts.map +0 -1
  130. package/dist/api/client/types/server.js +0 -3
  131. package/dist/api/client/types/server.js.map +0 -1
  132. package/dist/api/client/types/server_subuser.d.ts +0 -14
  133. package/dist/api/client/types/server_subuser.d.ts.map +0 -1
  134. package/dist/api/client/types/server_subuser.js +0 -3
  135. package/dist/api/client/types/server_subuser.js.map +0 -1
  136. package/dist/api/client/types/user.d.ts +0 -31
  137. package/dist/api/client/types/user.d.ts.map +0 -1
  138. package/dist/api/client/types/user.js +0 -3
  139. package/dist/api/client/types/user.js.map +0 -1
  140. package/dist/api/client/types/websocket.d.ts +0 -116
  141. package/dist/api/client/types/websocket.d.ts.map +0 -1
  142. package/dist/api/client/types/websocket.js +0 -37
  143. package/dist/api/client/types/websocket.js.map +0 -1
  144. package/dist/api/client/websocket_old.d.ts +0 -171
  145. package/dist/api/client/websocket_old.d.ts.map +0 -1
  146. package/dist/api/client/websocket_old.js +0 -319
  147. package/dist/api/client/websocket_old.js.map +0 -1
  148. package/dist/api/common/types/egg.d.ts +0 -10
  149. package/dist/api/common/types/egg.d.ts.map +0 -1
  150. package/dist/api/common/types/egg.js +0 -3
  151. package/dist/api/common/types/egg.js.map +0 -1
  152. package/dist/api/common/types/server_allocations.d.ts +0 -18
  153. package/dist/api/common/types/server_allocations.d.ts.map +0 -1
  154. package/dist/api/common/types/server_allocations.js +0 -3
  155. package/dist/api/common/types/server_allocations.js.map +0 -1
  156. package/dist/api/common/types/server_backup.d.ts +0 -13
  157. package/dist/api/common/types/server_backup.d.ts.map +0 -1
  158. package/dist/api/common/types/server_backup.js +0 -3
  159. package/dist/api/common/types/server_backup.js.map +0 -1
  160. package/dist/api/common/types/server_database.d.ts +0 -18
  161. package/dist/api/common/types/server_database.d.ts.map +0 -1
  162. package/dist/api/common/types/server_database.js +0 -3
  163. package/dist/api/common/types/server_database.js.map +0 -1
  164. package/dist/api/common/types/server_files.d.ts +0 -12
  165. package/dist/api/common/types/server_files.d.ts.map +0 -1
  166. package/dist/api/common/types/server_files.js +0 -3
  167. package/dist/api/common/types/server_files.js.map +0 -1
  168. package/dist/api/common/types/server_limits.d.ts +0 -17
  169. package/dist/api/common/types/server_limits.d.ts.map +0 -1
  170. package/dist/api/common/types/server_limits.js +0 -3
  171. package/dist/api/common/types/server_limits.js.map +0 -1
  172. package/dist/api/common/types/server_power.d.ts +0 -2
  173. package/dist/api/common/types/server_power.d.ts.map +0 -1
  174. package/dist/api/common/types/server_power.js +0 -3
  175. package/dist/api/common/types/server_power.js.map +0 -1
  176. package/dist/api/common/types/server_schedule.d.ts +0 -34
  177. package/dist/api/common/types/server_schedule.d.ts.map +0 -1
  178. package/dist/api/common/types/server_schedule.js +0 -3
  179. package/dist/api/common/types/server_schedule.js.map +0 -1
  180. package/dist/api/common/types/server_startup.d.ts +0 -14
  181. package/dist/api/common/types/server_startup.d.ts.map +0 -1
  182. package/dist/api/common/types/server_startup.js +0 -3
  183. package/dist/api/common/types/server_startup.js.map +0 -1
  184. package/dist/index.d.ts.map +0 -1
  185. package/dist/pterodactyl.d.ts +0 -8
  186. package/dist/pterodactyl.d.ts.map +0 -1
  187. package/dist/pterodactyl.js +0 -20
  188. package/dist/pterodactyl.js.map +0 -1
  189. package/dist/utils/sized.d.ts +0 -10
  190. package/dist/utils/sized.d.ts.map +0 -1
  191. package/dist/utils/sized.js +0 -15
  192. package/dist/utils/sized.js.map +0 -1
  193. package/dist/utils/transform.d.ts +0 -9
  194. package/dist/utils/transform.d.ts.map +0 -1
  195. package/dist/utils/transform.js +0 -19
  196. package/dist/utils/transform.js.map +0 -1
  197. package/dist/utils/types.d.ts +0 -14
  198. package/dist/utils/types.d.ts.map +0 -1
  199. package/dist/utils/types.js +0 -3
  200. package/dist/utils/types.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import {AxiosInstance} from "axios";
2
- import {Allocation, AllocationRel} from "@/api/common/types/server_allocations";
2
+ import {Allocation, AllocationRel} from "@/api/application/types/server_allocation";
3
3
  import {GenericListResponse, GenericResponse} from "@/api/base/types";
4
4
  import z from "zod";
5
5
 
@@ -25,17 +25,15 @@ export class NodesAllocations {
25
25
 
26
26
  create = async (
27
27
  ip: string,
28
- ports: number[] | string,
28
+ ports: string[],
29
29
  alias?: string
30
30
  ): Promise<void> => {
31
31
  z.ipv4().parse(ip)
32
- z.ipv4().or(z.url()).optional().parse(alias)
32
+ z.ipv4().or(z.url().max(255)).optional().parse(alias)
33
33
  z.array(z.number()).or(z.string().regex(/\d+-\d+/)).parse(ports)
34
34
 
35
35
  await this.r.post(`/nodes/${this.id}/allocations`, {
36
- ip,
37
- ports,
38
- alias
36
+ ip, ports, alias
39
37
  })
40
38
  }
41
39
 
@@ -0,0 +1,53 @@
1
+ import {AxiosInstance} from "axios";
2
+ import {GenericListResponse, GenericResponse} from "@/api/base/types";
3
+ import {Role} from "@/api/application/types/role";
4
+
5
+
6
+ // TODO: API is incomplete
7
+
8
+ export class Roles {
9
+ private readonly r: AxiosInstance
10
+
11
+ constructor(r: AxiosInstance) {
12
+ this.r = r
13
+ }
14
+
15
+ list = async (
16
+ page: number = 1
17
+ ): Promise<Role[]> => {
18
+ const {data} = await this.r.get<
19
+ GenericListResponse<GenericResponse<Role, "role">>
20
+ >(`/roles`, {
21
+ params: {page}
22
+ })
23
+ return data.data.map(r => r.attributes)
24
+ }
25
+
26
+ info = async (
27
+ id: number
28
+ ): Promise<Role> => {
29
+ const {data} = await this.r.get<
30
+ GenericResponse<Role, "role">
31
+ >(`/roles/${id}`)
32
+ return data.attributes
33
+ }
34
+
35
+ create = async (
36
+ opts: {name: string}
37
+ ): Promise<void> => {
38
+ await this.r.post(`/roles`, opts)
39
+ }
40
+
41
+ update = async (
42
+ id: number,
43
+ opts: {name: string}
44
+ ): Promise<void> => {
45
+ await this.r.patch(`/roles/${id}`, opts)
46
+ }
47
+
48
+ delete = async (
49
+ id: number
50
+ ): Promise<void> => {
51
+ await this.r.delete(`/roles/${id}`)
52
+ }
53
+ }
@@ -0,0 +1,135 @@
1
+ import {AxiosInstance} from "axios";
2
+ import z from "zod";
3
+ import {GenericResponse} from "@/api/base/types";
4
+ import {Server} 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 (include?: ("egg" | "subusers")[]): Promise<Server> => {
20
+ const {data} = await this.r.get<GenericResponse<Server, "server">>(`/servers/${this.id}`, {
21
+ params: {include: include?.join(",")}
22
+ })
23
+ return data.attributes
24
+ }
25
+
26
+ delete = async (force: boolean = false) => {
27
+ await this.r.delete(`/servers/${this.id}${force ? "/force" : ""}`)
28
+ }
29
+
30
+ updateDetails = async (opts: z.infer<typeof UpdateDetailsSchema>): Promise<void> => {
31
+ opts = UpdateDetailsSchema.parse(opts)
32
+ await this.r.patch(`/servers/${this.id}/details`, opts)
33
+ }
34
+
35
+ updateBuild = async (opts: z.infer<typeof UpdateBuildSchema>): Promise<void> => {
36
+ opts = UpdateBuildSchema.parse(opts)
37
+ await this.r.patch(`/servers/${this.id}/build`, opts)
38
+ }
39
+
40
+ updateStartup = async (opts: z.infer<typeof UpdateStartupSchema>): Promise<void> => {
41
+ opts = UpdateStartupSchema.parse(opts)
42
+ await this.r.patch(`/servers/${this.id}/startup`, opts)
43
+ }
44
+
45
+ suspend = async (): Promise<void> => {
46
+ await this.r.post(`/servers/${this.id}/suspend`)
47
+ }
48
+
49
+ unsuspend = async (): Promise<void> => {
50
+ await this.r.post(`/servers/${this.id}/unsuspend`)
51
+ }
52
+
53
+ reinstall = async (): Promise<void> => {
54
+ await this.r.post(`/servers/${this.id}/reinstall`)
55
+ }
56
+
57
+ transferStart = async (
58
+ node_id: number,
59
+ allocation_id: number,
60
+ allocation_additional?: string[]
61
+ ): Promise<void> => {
62
+ await this.r.post(`/servers/${this.id}/transfer`, {
63
+ node_id,
64
+ allocation_id,
65
+ allocation_additional
66
+ })
67
+ }
68
+
69
+ transferCancel = async (): Promise<void> => {
70
+ await this.r.post(`/servers/${this.id}/transfer/cancel`)
71
+ }
72
+ }
73
+
74
+
75
+ export const CreateServerSchema = z.object({
76
+ external_id: z.string().min(1).max(255).optional(),
77
+ name: z.string().min(1).max(255),
78
+ description: z.string().optional(),
79
+ user: z.number(),
80
+ egg: z.number(),
81
+ docker_image: z.string().optional(),
82
+ startup: z.string().optional(),
83
+ environment: z.array(z.string()),
84
+ skip_scripts: z.boolean().optional(),
85
+ oom_killer: z.boolean().optional(),
86
+ start_on_completion: z.boolean().optional(),
87
+ limits: z.object({
88
+ memory: z.number().min(0),
89
+ swap: z.number().min(-1),
90
+ disk: z.number().min(0),
91
+ io: z.number().min(0),
92
+ threads: z.string().optional(),
93
+ cpu: z.number().min(0)
94
+ }),
95
+ feature_limits: z.object({
96
+ databases: z.number().min(0),
97
+ allocations: z.number().min(0),
98
+ backups: z.number().min(0)
99
+ }),
100
+ allocation: z.object({
101
+ default: z.string(),
102
+ additional: z.array(z.string()).optional()
103
+ }).optional(),
104
+ deploy: z.object({
105
+ tags: z.array(z.string()).optional(),
106
+ dedicated_ip: z.boolean().optional(),
107
+ port_range: z.array(z.string()).optional()
108
+ }).optional()
109
+ })
110
+
111
+ const UpdateDetailsSchema = CreateServerSchema.pick({
112
+ external_id: true,
113
+ name: true,
114
+ user: true,
115
+ description: true
116
+ })
117
+
118
+ const UpdateBuildSchema = CreateServerSchema.pick({
119
+ oom_killer: true,
120
+ limits: true,
121
+ feature_limits: true,
122
+ }).extend({
123
+ allocation: z.number().optional(),
124
+ add_allocations: z.array(z.string()).optional(),
125
+ remove_allocations: z.array(z.string()).optional(),
126
+ })
127
+
128
+ const UpdateStartupSchema = CreateServerSchema.pick({
129
+ startup: true,
130
+ environment: true,
131
+ egg: true,
132
+ skip_scripts: true
133
+ }).extend({
134
+ image: z.string().optional()
135
+ })
@@ -0,0 +1,49 @@
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<GenericResponse<ServerDatabase, "server_database">>
19
+ >(`/servers/${this.id}/databases`)
20
+ return data.data.map(d => d.attributes)
21
+ }
22
+
23
+ create = async (
24
+ database: string,
25
+ remote: string,
26
+ host: string
27
+ ): Promise<ServerDatabase> => {
28
+ database = z.string().min(1).max(48).parse(database)
29
+ const {data} = await this.r.post<
30
+ GenericResponse<ServerDatabase, "server_database">
31
+ >(`/servers/${this.id}/databases`, {database, remote, host})
32
+ return data.attributes
33
+ }
34
+
35
+ info = async (database_id: number): Promise<ServerDatabase> => {
36
+ const {data} = await this.r.get<
37
+ GenericResponse<ServerDatabase, "server_database">
38
+ >(`/servers/${this.id}/databases/${database_id}`)
39
+ return data.attributes
40
+ }
41
+
42
+ delete = async (database_id: number): Promise<void> => {
43
+ await this.r.delete(`/servers/${this.id}/databases/${database_id}`)
44
+ }
45
+
46
+ resetPassword = async (database_id: number): Promise<void> => {
47
+ await this.r.post(`/servers/${this.id}/databases/${database_id}/reset-password`)
48
+ }
49
+ }
@@ -3,9 +3,7 @@ export type Container = {
3
3
  startup_command: string,
4
4
  image: string,
5
5
  installed: number,
6
- environment: {
7
- [key: string]: string | number
8
- },
6
+ environment: Record<string, string>,
9
7
  ports: number[],
10
8
  volumes: string[],
11
9
  network_mode: string
@@ -0,0 +1,11 @@
1
+ import {Nullable} from "@/utils/types";
2
+
3
+ export type DatabaseHost = {
4
+ id: number,
5
+ name: string,
6
+ host: string,
7
+ port: number,
8
+ username: string,
9
+ created_at: string,
10
+ updated_at: Nullable<string>
11
+ }
@@ -1,7 +1,8 @@
1
1
  import {GenericListResponse, GenericResponse} from "@/api/base/types";
2
- import {Allocation} from "@/api/common/types/server_allocations";
2
+ import {Allocation} from "@/api/application/types/server_allocation";
3
3
  import {Location} from "@/api/application/types/location";
4
4
  import {Server} from "@/api/application/types/server";
5
+ import {Nullable} from "@/utils/types";
5
6
 
6
7
 
7
8
  export type Node = {
@@ -9,8 +10,7 @@ export type Node = {
9
10
  uuid: string,
10
11
  public: boolean,
11
12
  name: string,
12
- description: string,
13
- location_id: number,
13
+ description: Nullable<string>,
14
14
  fqdn: string,
15
15
  scheme: "https" | "http",
16
16
  behind_proxy: boolean,
@@ -19,15 +19,50 @@ export type Node = {
19
19
  memory_overallocate: number,
20
20
  disk: number,
21
21
  disk_overallocate: number,
22
+ cpu: number,
23
+ cpu_overallocate: number,
22
24
  upload_size: number,
23
25
  daemon_listen: number,
24
26
  daemon_sftp: number,
27
+ daemon_sftp_alias: Nullable<string>,
25
28
  daemon_base: string,
29
+ daemon_connect: number,
26
30
  created_at: string,
27
- updated_at: string | null
31
+ updated_at: Nullable<string>,
32
+ tags: string[],
33
+ allocated_resources: {
34
+ memory: number,
35
+ disk: number,
36
+ cpu: number
37
+ },
28
38
  relationships?: {
29
39
  allocations?: GenericListResponse<GenericResponse<Allocation, "allocation">>,
30
40
  location?: GenericResponse<Location, "location">,
31
41
  servers?: GenericListResponse<GenericResponse<Server, "server">>
32
42
  }
43
+ }
44
+
45
+ export type NodeConfiguration = {
46
+ debug: boolean,
47
+ uuid: string,
48
+ token_id: string,
49
+ token: string,
50
+ api: {
51
+ host: string,
52
+ port: number,
53
+ upload_limit: number,
54
+ ssl: {
55
+ enabled: boolean,
56
+ cert: string,
57
+ key: string
58
+ }
59
+ },
60
+ system: {
61
+ data: string,
62
+ sftp: {
63
+ bind_port: number,
64
+ }
65
+ },
66
+ allowed_mounts: string[],
67
+ remote: string
33
68
  }
@@ -0,0 +1,8 @@
1
+
2
+
3
+ export type Role = {
4
+ id: number,
5
+ name: string,
6
+ created_at: string,
7
+ updated_at: string
8
+ }
@@ -1,24 +1,24 @@
1
1
  import {FeatureLimits, ServerLimits} from "@/api/common/types/server_limits";
2
2
  import {Container} from "@/api/application/types/container";
3
+ import {Nullable} from "@/utils/types";
3
4
 
4
5
 
5
6
  export type Server = {
6
7
  id: number,
7
- external_id: string | null,
8
+ external_id: Nullable<string>,
8
9
  uuid: string,
9
10
  identifier: string,
10
11
  name: string,
11
12
  description: string,
12
- status: any | null,
13
+ status: Nullable<unknown>,
13
14
  suspended: boolean,
14
15
  limits: ServerLimits,
15
16
  feature_limits: FeatureLimits,
16
17
  user: number,
17
18
  node: number,
18
19
  allocation: number,
19
- nest: number,
20
20
  egg: number,
21
21
  container: Container,
22
22
  created_at: string,
23
- updated_at: string | null
23
+ updated_at: Nullable<string>
24
24
  }
@@ -1,15 +1,16 @@
1
1
  import {GenericResponse} from "@/api/base/types";
2
2
  import {Server} from "@/api/application/types/server";
3
+ import {Node} from "@/api/application/types/node";
3
4
  import {Nullable} from "@/utils/types";
4
5
 
5
6
 
6
7
  export type Allocation = {
7
8
  id: number,
8
9
  ip: string,
9
- ip_alias: Nullable<string>,
10
+ alias: Nullable<string>,
10
11
  port: number,
11
12
  notes: Nullable<string>,
12
- is_default: boolean
13
+ assigned: boolean
13
14
  }
14
15
 
15
16
  export type AllocationRel = Allocation & {
@@ -1,19 +1,19 @@
1
1
  import {GenericListResponse, GenericResponse} from "@/api/base/types";
2
2
  import {Server} from "@/api/application/types/server";
3
+ import {Nullable} from "@/utils/types";
3
4
 
4
5
  export type User = {
5
6
  id: number,
6
- external_id: string | null,
7
+ external_id: Nullable<string>,
7
8
  uuid: string,
8
9
  username: string,
9
10
  email: string,
10
- first_name: string,
11
- last_name: string,
12
11
  language: string,
13
12
  root_admin: string,
13
+ "2fa_enabled": boolean,
14
14
  "2fa": boolean,
15
15
  created_at: string,
16
- updated_at: string,
16
+ updated_at: Nullable<string>,
17
17
  relationships?: {
18
18
  servers: GenericListResponse<GenericResponse<Server>>
19
19
  }
@@ -4,6 +4,7 @@ import {GenericListResponse, GenericResponse} from "@/api/base/types";
4
4
  import {User} from "@/api/application/types/user";
5
5
  import {ArrayQueryParams, SortParam} from "@/utils/transform";
6
6
  import {ExactlyOneKey} from "@/utils/types";
7
+ import {languagesSchema, timezonesSchema} from "@/api/common/types/enums";
7
8
 
8
9
 
9
10
  export class Users {
@@ -14,7 +15,7 @@ export class Users {
14
15
  }
15
16
 
16
17
  list = async (
17
- {...opts}: ListType,
18
+ opts: ListType,
18
19
  page: number = 1
19
20
  ): Promise<User[]> => {
20
21
  z.number().positive().parse(page)
@@ -50,23 +51,26 @@ export class Users {
50
51
  infoByExternal = async (
51
52
  external_id: string,
52
53
  {include}: { include?: ("servers")[] }
53
- ): Promise<User> => {
54
+ ): Promise<User> => {
54
55
  const {data} = await this.r.get<
55
56
  GenericResponse<User, "user">
56
- >(`/users/external/${external_id}`)
57
+ >(`/users/external/${external_id}`, {
58
+ params: {include: include?.join(",")}
59
+ })
57
60
  return data.attributes
58
61
  }
59
62
 
60
- create = async (user: CreateType): Promise<User> => {
63
+ create = async (user: z.infer<typeof CreateSchema>): Promise<User> => {
64
+ user = CreateSchema.parse(user)
61
65
  const {data} = await this.r.post<
62
66
  GenericResponse<User, "user">
63
67
  >("/users", user)
64
68
  return data.attributes
65
69
  }
66
70
 
67
- update = async (id: number, user: UpdateType): Promise<User> => {
68
- z.number().positive().parse(id)
69
- const {data} = await this.r.put<
71
+ update = async (id: number, user: z.infer<typeof CreateSchema>): Promise<User> => {
72
+ user = CreateSchema.parse(user)
73
+ const {data} = await this.r.patch<
70
74
  GenericResponse<User, "user">
71
75
  >(`/users/${id}`, user)
72
76
  return data.attributes
@@ -77,6 +81,15 @@ export class Users {
77
81
  await this.r.delete(`/users/${id}`)
78
82
  }
79
83
 
84
+ addRoles = async (id: number, roles: number[]): Promise<void> => {
85
+ z.number().positive().parse(id)
86
+ await this.r.patch(`/users/${id}/roles/assign`, {roles})
87
+ }
88
+
89
+ removeRoles = async (id: number, roles: number[]): Promise<void> => {
90
+ z.number().positive().parse(id)
91
+ await this.r.patch(`/users/${id}/roles/remove`, {roles})
92
+ }
80
93
  }
81
94
 
82
95
  type ListType = {
@@ -90,14 +103,11 @@ type ListFilters = {
90
103
 
91
104
  type ListSort = ExactlyOneKey<"id" | "uuid", "asc" | "desc">
92
105
 
93
- type CreateType = {
94
- email: string,
95
- username: string,
96
- first_name: string,
97
- last_name: string
98
- }
99
-
100
- type UpdateType = CreateType & {
101
- language: string
102
- password: string
103
- }
106
+ const CreateSchema = z.object({
107
+ email: z.email(),
108
+ external_id: z.string().max(255).optional(),
109
+ username: z.string().min(1).max(255),
110
+ password: z.string().optional(),
111
+ language: languagesSchema,
112
+ timezone: timezonesSchema
113
+ })
@@ -7,12 +7,12 @@ export class Agent {
7
7
  private readonly token: string
8
8
  readonly requester: AxiosInstance
9
9
 
10
- constructor(url: string, token: string, type: "client" | "application") {
11
- this.base_url = z.url("Invalid URL Schema").parse(url)
10
+ constructor(url: string, token: string, type: "client" | "application", suffix: string = "/api") {
11
+ this.base_url = z.url("Invalid URL Schema").transform(url => new URL(url).href).parse(url)
12
12
  this.token = z.string().regex(/^(ptl[ac]|pacc|papp)_.+$/, "Invalid token type").parse(token)
13
13
 
14
14
  this.requester = axios.create({
15
- baseURL: this.base_url.replace(/\/+$/, "")+`/api/${type}`,
15
+ baseURL: this.base_url.replace(/\/+$/, "")+`${suffix}/${type}`,
16
16
  timeout: 3000,
17
17
  headers: {
18
18
  Authorization: `Bearer ${this.token}`
@@ -1,6 +1,6 @@
1
1
  import {AxiosInstance} from "axios";
2
2
  import {GenericListResponse, GenericResponse} from "@/api/base/types";
3
- import {Allocation} from "@/api/common/types/server_allocations";
3
+ import {Allocation} from "@/api/client/types/server_allocation";
4
4
 
5
5
  export class ServerAllocations {
6
6
  private readonly r: AxiosInstance
@@ -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 {Database} from "@/api/common/types/server_database";
4
+ import {ServerDatabase} from "@/api/common/types/server_database";
5
5
  // TODO: Check for validity
6
6
 
7
7
  export class ServerDatabases {
@@ -15,26 +15,26 @@ export class ServerDatabases {
15
15
 
16
16
  list = async (
17
17
  include?: ("password")[], page: number = 1
18
- ): Promise<Database[]> => {
18
+ ): Promise<ServerDatabase[]> => {
19
19
  z.number().positive().parse(page)
20
20
  const {data} = await this.r.get<
21
- GenericListResponse<GenericResponse<Database, "server_database">>
21
+ GenericListResponse<GenericResponse<ServerDatabase, "server_database">>
22
22
  >(`/servers/${this.id}/databases`, {
23
23
  params: {include: include?.join(","), page}
24
24
  })
25
25
  return data.data.map(d => d.attributes)
26
26
  }
27
27
 
28
- create = async (database: string, remote: string): Promise<Database> => {
28
+ create = async (database: string, remote: string): Promise<ServerDatabase> => {
29
29
  const {data} = await this.r.post<
30
- GenericResponse<Database, "server_database">
30
+ GenericResponse<ServerDatabase, "server_database">
31
31
  >(`/servers/${this.id}/databases`, {database, remote})
32
32
  return data.attributes
33
33
  }
34
34
 
35
- rotatePassword = async (database_id: string): Promise<Database> => {
35
+ rotatePassword = async (database_id: string): Promise<ServerDatabase> => {
36
36
  const {data} = await this.r.post<
37
- GenericResponse<Database, "server_database">
37
+ GenericResponse<ServerDatabase, "server_database">
38
38
  >(`/servers/${this.id}/databases/${database_id}/rotate-password`)
39
39
  return data.attributes
40
40
  }
@@ -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 {Allocation} from "@/api/common/types/server_allocations";
5
+ import {Allocation} from "@/api/client/types/server_allocation";
6
6
  import {Nullable} from "@/utils/types";
7
7
 
8
8
  export type Server = {
@@ -0,0 +1,11 @@
1
+ import {Nullable} from "@/utils/types";
2
+
3
+
4
+ export type Allocation = {
5
+ id: number,
6
+ ip: string,
7
+ alias: Nullable<string>,
8
+ port: number,
9
+ notes: Nullable<string>,
10
+ is_default: boolean
11
+ }