@pelican.ts/sdk 0.2.4 → 0.2.5

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/package.json CHANGED
@@ -1,13 +1,21 @@
1
1
  {
2
2
  "name": "@pelican.ts/sdk",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
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
- "pub": "npm publish --access=public"
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,7 +2,7 @@ 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 {Server} from "@/api/application/types/server";
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";
@@ -27,23 +27,23 @@ export class Client {
27
27
  listServers = async (
28
28
  search?: string,
29
29
  page: number = 1
30
- ): Promise<Server[]> => {
30
+ ): Promise<ApplicationServer[]> => {
31
31
  const {data} = await this.r.get<
32
- GenericListResponse<GenericResponse<Server, "server">>
32
+ GenericListResponse<GenericResponse<ApplicationServer, "server">>
33
33
  >("/servers", {
34
34
  params: {search, page}
35
35
  })
36
36
  return data.data.map(s => s.attributes)
37
37
  }
38
38
 
39
- createServer = async (opts: z.infer<typeof CreateServerSchema>): Promise<Server> => {
39
+ createServer = async (opts: z.infer<typeof CreateServerSchema>): Promise<ApplicationServer> => {
40
40
  opts = CreateServerSchema.parse(opts)
41
- const {data} = await this.r.post<GenericResponse<Server, "server">>("/servers", opts)
41
+ const {data} = await this.r.post<GenericResponse<ApplicationServer, "server">>("/servers", opts)
42
42
  return data.attributes
43
43
  }
44
44
 
45
- getServerByExternalId = async (external_id: string, include?: ("egg" | "subusers")[]): Promise<Server> => {
46
- const {data} = await this.r.get<GenericResponse<Server, "server">>(`/servers/external/${external_id}`, {
45
+ getServerByExternalId = async (external_id: string, include?: ("egg" | "subusers")[]): Promise<ApplicationServer> => {
46
+ const {data} = await this.r.get<GenericResponse<ApplicationServer, "server">>(`/servers/external/${external_id}`, {
47
47
  params: {include: include?.join(",")}
48
48
  })
49
49
  return data.attributes
@@ -1,6 +1,6 @@
1
1
  import {AxiosInstance} from "axios";
2
2
  import {NodesAllocations} from "@/api/application/nodes_allocations";
3
- import {Server} from "@/api/application/types/server";
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 {Server} from "@/api/application/types/server";
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<Server> => {
20
- const {data} = await this.r.get<GenericResponse<Server, "server">>(`/servers/${this.id}`, {
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,8 @@
1
+ export * from "./node"
2
+ export * from "./location"
3
+ export * from "./database_host"
4
+ export * from "./container"
5
+ export * from "./role"
6
+ export * from "./server_allocation"
7
+ export * from "./server"
8
+ 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 {Server} from "@/api/application/types/server";
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<Server, "server">>
41
+ servers?: GenericListResponse<GenericResponse<ApplicationServer, "server">>
42
42
  }
43
43
  }
44
44
 
@@ -3,7 +3,7 @@ import {Container} from "@/api/application/types/container";
3
3
  import {Nullable} from "@/utils/types";
4
4
 
5
5
 
6
- export type Server = {
6
+ export type ApplicationServer = {
7
7
  id: number,
8
8
  external_id: Nullable<string>,
9
9
  uuid: string,
@@ -1,5 +1,5 @@
1
1
  import {GenericResponse} from "@/api/base/types";
2
- import {Server} from "@/api/application/types/server";
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<Server, "server">
19
+ server?: GenericResponse<ApplicationServer, "server">
20
20
  }
21
21
  }
@@ -1,8 +1,8 @@
1
1
  import {GenericListResponse, GenericResponse} from "@/api/base/types";
2
- import {Server} from "@/api/application/types/server";
2
+ import {ApplicationServer} from "@/api/application/types/server";
3
3
  import {Nullable} from "@/utils/types";
4
4
 
5
- export type User = {
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<Server>>
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 {User} from "@/api/application/types/user";
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<User[]> => {
20
+ ): Promise<ApplicationUser[]> => {
21
21
  z.number().positive().parse(page)
22
22
  const {data} = await this.r.get<
23
- GenericListResponse<GenericResponse<User, "user">>
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<User> => {
41
+ ): Promise<ApplicationUser> => {
42
42
  z.number().positive().parse(id)
43
43
  const {data} = await this.r.get<
44
- GenericResponse<User, "user">
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<User> => {
54
+ ): Promise<ApplicationUser> => {
55
55
  const {data} = await this.r.get<
56
- GenericResponse<User, "user">
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<User> => {
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<User, "user">
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<User> => {
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<User, "user">
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 {Allocation} from "@/api/client/types/server_allocation";
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<Allocation[]> => {
14
+ list = async (): Promise<ServerAllocation[]> => {
15
15
  const {data} = await this.r.get<
16
- GenericListResponse<GenericResponse<Allocation, "allocation">>
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<Allocation> => {
21
+ autoAssign = async (): Promise<ServerAllocation> => {
22
22
  const {data} = await this.r.post<
23
- GenericResponse<Allocation, "allocation">
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<Allocation> => {
28
+ setNotes = async (alloc_id: number, notes: string): Promise<ServerAllocation> => {
29
29
  const {data} = await this.r.post<
30
- GenericResponse<Allocation, "allocation">
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<Allocation> => {
35
+ setPrimary = async (alloc_id: number): Promise<ServerAllocation> => {
36
36
  const {data} = await this.r.post<
37
- GenericResponse<Allocation, "allocation">
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 {Backup} from "@/api/common/types/server_backup";
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<Backup[]> => {
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<Backup, "backup">>
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<Backup> => {
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<Backup, "backup">
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<Backup> => {
43
+ info = async (backup_uuid: string): Promise<ServerBackup> => {
44
44
  const {data} = await this.r.get<
45
- GenericResponse<Backup, "backup">
45
+ GenericResponse<ServerBackup, "backup">
46
46
  >(`/servers/${this.id}/backups/${backup_uuid}`)
47
47
  return data.attributes
48
48
  }
@@ -0,0 +1,5 @@
1
+ export * from "./websocket"
2
+ export * from "./server_allocation"
3
+ export * from "./server_subuser"
4
+ export * from "./server"
5
+ export * from "./user"
@@ -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/client/types/server_allocation";
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<Allocation, "allocation">>,
32
+ allocations: GenericListResponse<GenericResponse<ServerAllocation, "allocation">>,
33
33
  variables: GenericListResponse<GenericResponse<EggVariable, "egg_variable">>,
34
34
  egg?: GenericResponse<{
35
35
  uuid: string,
@@ -1,7 +1,7 @@
1
1
  import {Nullable} from "@/utils/types";
2
2
 
3
3
 
4
- export type Allocation = {
4
+ export type ServerAllocation = {
5
5
  id: number,
6
6
  ip: string,
7
7
  alias: Nullable<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"
@@ -1,7 +1,7 @@
1
1
  import {Nullable} from "@/utils/types";
2
2
 
3
3
 
4
- export type Backup = {
4
+ export type ServerBackup = {
5
5
  uuid: string
6
6
  is_successful: boolean,
7
7
  is_locked: boolean,
package/src/types.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./api/common/types"
2
+ export * from "./api/application/types"
3
+ export * from "./api/client/types"