@pelican.ts/sdk 0.4.13 → 0.4.15
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/CHANGELOG.md +127 -0
- package/dist/api/index.d.mts +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/index.d.mts +139 -139
- package/dist/index.d.ts +139 -139
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types.d.ts +258 -258
- package/package.json +1 -1
- package/.husky/pre-commit +0 -2
- package/scripts/create-types.ts +0 -24
- package/src/api/application/client.ts +0 -70
- package/src/api/application/database_hosts.ts +0 -65
- package/src/api/application/eggs.ts +0 -43
- package/src/api/application/mounts.ts +0 -109
- package/src/api/application/nodes.ts +0 -126
- package/src/api/application/nodes_allocations.ts +0 -47
- package/src/api/application/roles.ts +0 -39
- package/src/api/application/servers.ts +0 -145
- package/src/api/application/servers_databases.ts +0 -53
- package/src/api/application/types/container.ts +0 -9
- package/src/api/application/types/database_host.ts +0 -11
- package/src/api/application/types/egg.ts +0 -65
- package/src/api/application/types/index.ts +0 -10
- package/src/api/application/types/location.ts +0 -7
- package/src/api/application/types/mount.ts +0 -12
- package/src/api/application/types/node.ts +0 -58
- package/src/api/application/types/role.ts +0 -6
- package/src/api/application/types/server.ts +0 -24
- package/src/api/application/types/server_allocation.ts +0 -20
- package/src/api/application/types/user.ts +0 -34
- package/src/api/application/users.ts +0 -146
- package/src/api/base/request.ts +0 -44
- package/src/api/base/types.ts +0 -40
- package/src/api/client/account.ts +0 -77
- package/src/api/client/client.ts +0 -56
- package/src/api/client/server.ts +0 -74
- package/src/api/client/server_activity.ts +0 -25
- package/src/api/client/server_allocations.ts +0 -50
- package/src/api/client/server_backups.ts +0 -82
- package/src/api/client/server_databases.ts +0 -51
- package/src/api/client/server_files.ts +0 -145
- package/src/api/client/server_schedules.ts +0 -130
- package/src/api/client/server_settings.ts +0 -36
- package/src/api/client/server_startup.ts +0 -41
- package/src/api/client/server_users.ts +0 -55
- package/src/api/client/server_websocket.ts +0 -570
- package/src/api/client/types/index.ts +0 -5
- package/src/api/client/types/server.ts +0 -72
- package/src/api/client/types/server_allocation.ts +0 -10
- package/src/api/client/types/server_subuser.ts +0 -55
- package/src/api/client/types/user.ts +0 -31
- package/src/api/client/types/websocket.ts +0 -138
- package/src/api/common/types/egg.ts +0 -9
- package/src/api/common/types/enums.ts +0 -21
- package/src/api/common/types/index.ts +0 -9
- package/src/api/common/types/server_backup.ts +0 -13
- package/src/api/common/types/server_database.ts +0 -13
- package/src/api/common/types/server_files.ts +0 -11
- package/src/api/common/types/server_limits.ts +0 -18
- package/src/api/common/types/server_power.ts +0 -1
- package/src/api/common/types/server_schedule.ts +0 -37
- package/src/api/common/types/server_startup.ts +0 -11
- package/src/api/index.ts +0 -17
- package/src/humane/Account.ts +0 -60
- package/src/humane/Client.ts +0 -44
- package/src/humane/Server.ts +0 -206
- package/src/humane/ServerAllocation.ts +0 -41
- package/src/humane/ServerBackup.ts +0 -44
- package/src/humane/ServerDatabase.ts +0 -37
- package/src/humane/ServerFile.ts +0 -91
- package/src/humane/ServerSchedule.ts +0 -160
- package/src/humane/ServerUser.ts +0 -44
- package/src/index.ts +0 -21
- package/src/types.ts +0 -3
- package/src/utils/sized.ts +0 -13
- package/src/utils/transform.ts +0 -21
- package/src/utils/types.ts +0 -10
package/src/humane/Server.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {ServerBackups} from "@/api/client/server_backups"
|
|
3
|
-
import type {ServerFiles} from "@/api/client/server_files"
|
|
4
|
-
import type {ServerSchedules} from "@/api/client/server_schedules"
|
|
5
|
-
import type {Server as ServerT} from "@/api/client/types/server"
|
|
6
|
-
import {ServerAllocation} from "@/humane/ServerAllocation"
|
|
7
|
-
import {ServerBackup} from "@/humane/ServerBackup"
|
|
8
|
-
import {ServerDatabase} from "@/humane/ServerDatabase"
|
|
9
|
-
import {ServerFile} from "@/humane/ServerFile"
|
|
10
|
-
import {ServerSchedule} from "@/humane/ServerSchedule"
|
|
11
|
-
import {ServerUser} from "@/humane/ServerUser"
|
|
12
|
-
import type {
|
|
13
|
-
EggVariable,
|
|
14
|
-
FeatureLimits,
|
|
15
|
-
ServerLimits,
|
|
16
|
-
SubuserPermission
|
|
17
|
-
} from "@/types"
|
|
18
|
-
import type {Nullable} from "@/utils/types"
|
|
19
|
-
|
|
20
|
-
export class Server {
|
|
21
|
-
private readonly client: ServerClient
|
|
22
|
-
|
|
23
|
-
readonly ownsServer: boolean
|
|
24
|
-
readonly identifier: string
|
|
25
|
-
readonly internalId?: number
|
|
26
|
-
readonly uuid: string
|
|
27
|
-
private $name: string
|
|
28
|
-
get name() {
|
|
29
|
-
return this.$name
|
|
30
|
-
}
|
|
31
|
-
readonly node: string
|
|
32
|
-
readonly isNodeUnderMaintenance: boolean
|
|
33
|
-
readonly sftp: {ip: string; alias: Nullable<string>; port: number}
|
|
34
|
-
private $description: string
|
|
35
|
-
get description() {
|
|
36
|
-
return this.$description
|
|
37
|
-
}
|
|
38
|
-
readonly limits: ServerLimits
|
|
39
|
-
readonly invocation: string
|
|
40
|
-
private $dockerImage: string
|
|
41
|
-
get dockerImage() {
|
|
42
|
-
return this.$dockerImage
|
|
43
|
-
}
|
|
44
|
-
readonly eggFeatures: Nullable<string[]>
|
|
45
|
-
readonly featureLimits: FeatureLimits
|
|
46
|
-
readonly status: unknown
|
|
47
|
-
readonly isSuspended: boolean
|
|
48
|
-
readonly isInstalling: boolean
|
|
49
|
-
readonly isTransferring: boolean
|
|
50
|
-
readonly allocations: ServerAllocation[]
|
|
51
|
-
readonly variables: EggVariable[]
|
|
52
|
-
readonly egg?: {uuid: string; name: string}
|
|
53
|
-
readonly subusers?: ServerUser[]
|
|
54
|
-
|
|
55
|
-
constructor(client: ServerClient, server: ServerT) {
|
|
56
|
-
this.client = client
|
|
57
|
-
this.ownsServer = server.server_owner
|
|
58
|
-
this.identifier = server.identifier
|
|
59
|
-
this.internalId = server.internal_id
|
|
60
|
-
this.uuid = server.uuid
|
|
61
|
-
this.$name = server.name
|
|
62
|
-
this.node = server.node
|
|
63
|
-
this.isNodeUnderMaintenance = server.is_node_under_maintenance
|
|
64
|
-
this.sftp = server.sftp_details
|
|
65
|
-
this.$description = server.description
|
|
66
|
-
this.limits = server.limits
|
|
67
|
-
this.invocation = server.invocation
|
|
68
|
-
this.$dockerImage = server.docker_image
|
|
69
|
-
this.eggFeatures = server.egg_features
|
|
70
|
-
this.featureLimits = server.feature_limits
|
|
71
|
-
this.status = server.status
|
|
72
|
-
this.isSuspended = server.is_suspended
|
|
73
|
-
this.isInstalling = server.is_installing
|
|
74
|
-
this.isTransferring = server.is_transferring
|
|
75
|
-
this.allocations = server.relationships.allocations.data.map(
|
|
76
|
-
d => new ServerAllocation(this.client, d.attributes)
|
|
77
|
-
)
|
|
78
|
-
this.variables = server.relationships.variables.data.map(
|
|
79
|
-
d => d.attributes
|
|
80
|
-
)
|
|
81
|
-
this.egg = server.relationships.egg?.attributes
|
|
82
|
-
this.subusers = server.relationships.subusers?.data.map(
|
|
83
|
-
d => new ServerUser(this.client, d.attributes)
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
rename = async (name: string) => {
|
|
88
|
-
await this.client.settings.rename(name)
|
|
89
|
-
this.$name = name
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
updateDescription = async (description: string) => {
|
|
93
|
-
await this.client.settings.updateDescription(description)
|
|
94
|
-
this.$description = description
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
reinstall = async () => this.client.settings.reinstall()
|
|
98
|
-
|
|
99
|
-
changeDockerImage = async (image: string) => {
|
|
100
|
-
await this.client.settings.changeDockerImage(image)
|
|
101
|
-
this.$dockerImage = image
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
getActivityLogs = async (
|
|
105
|
-
opts: {page?: number; per_page?: number} = {page: 1, per_page: 50}
|
|
106
|
-
) => this.client.activity.list(opts.page, opts.per_page)
|
|
107
|
-
|
|
108
|
-
websocket = (stripColors: boolean = false) =>
|
|
109
|
-
this.client.websocket(stripColors)
|
|
110
|
-
|
|
111
|
-
getServerStats = async () => this.client.resources()
|
|
112
|
-
|
|
113
|
-
runCommand = async (command: string) => this.client.command(command)
|
|
114
|
-
|
|
115
|
-
sendPowerSignal = async (signal: "start" | "stop" | "restart" | "kill") =>
|
|
116
|
-
this.client.power(signal)
|
|
117
|
-
|
|
118
|
-
getDatabases = async (
|
|
119
|
-
opts: {include?: "password"[]; page?: number} = {include: [], page: 1}
|
|
120
|
-
) => {
|
|
121
|
-
const data = await this.client.databases.list(opts.include, opts.page)
|
|
122
|
-
return data.map(d => new ServerDatabase(this.client, d))
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
createDatabase = async (database: string, remote: string) => {
|
|
126
|
-
const data = await this.client.databases.create(database, remote)
|
|
127
|
-
return new ServerDatabase(this.client, data)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
getSchedules = async () => {
|
|
131
|
-
const data = await this.client.schedules.list()
|
|
132
|
-
return data.map(d => new ServerSchedule(this.client, d))
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
createSchedule = async (...opts: Parameters<ServerSchedules["create"]>) => {
|
|
136
|
-
const data = await this.client.schedules.create(...opts)
|
|
137
|
-
return new ServerSchedule(this.client, data)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
getBackups = async (page: number = 1) => {
|
|
141
|
-
const data = await this.client.backups.list(page)
|
|
142
|
-
return data.map(d => new ServerBackup(this.client, d))
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
createBackup = async (...args: Parameters<ServerBackups["create"]>) => {
|
|
146
|
-
const data = await this.client.backups.create(...args)
|
|
147
|
-
return new ServerBackup(this.client, data)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
getAllocations = async () => {
|
|
151
|
-
const data = await this.client.allocations.list()
|
|
152
|
-
return data.map(d => new ServerAllocation(this.client, d))
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
createAllocation = async () => {
|
|
156
|
-
const data = await this.client.allocations.autoAssign()
|
|
157
|
-
return new ServerAllocation(this.client, data)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
getFiles = async (path?: string) => {
|
|
161
|
-
const data = await this.client.files.list(path)
|
|
162
|
-
return data.map(d => new ServerFile(this.client, d, path))
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
createFolder = async (...opts: Parameters<ServerFiles["createFolder"]>) =>
|
|
166
|
-
this.client.files.createFolder(...opts)
|
|
167
|
-
|
|
168
|
-
uploadFile = async (...opts: Parameters<ServerFiles["upload"]>) =>
|
|
169
|
-
this.client.files.upload(...opts)
|
|
170
|
-
|
|
171
|
-
uploadFileGetUrl = async (
|
|
172
|
-
...opts: Parameters<ServerFiles["uploadGetUrl"]>
|
|
173
|
-
) => this.client.files.uploadGetUrl(...opts)
|
|
174
|
-
|
|
175
|
-
pullFileFromRemote = async (
|
|
176
|
-
...opts: Parameters<ServerFiles["pullFromRemote"]>
|
|
177
|
-
) => this.client.files.pullFromRemote(...opts)
|
|
178
|
-
|
|
179
|
-
compressMultipleFiles = async (
|
|
180
|
-
...opts: Parameters<ServerFiles["compress"]>
|
|
181
|
-
) => this.client.files.compress(...opts)
|
|
182
|
-
|
|
183
|
-
renameMultipleFiles = async (...opts: Parameters<ServerFiles["rename"]>) =>
|
|
184
|
-
this.client.files.rename(...opts)
|
|
185
|
-
|
|
186
|
-
deleteMultipleFiles = async (...opts: Parameters<ServerFiles["delete"]>) =>
|
|
187
|
-
this.client.files.delete(...opts)
|
|
188
|
-
|
|
189
|
-
getUsers = async () => {
|
|
190
|
-
const data = await this.client.users.list()
|
|
191
|
-
return data.map(d => new ServerUser(this.client, d))
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
createUser = async (
|
|
195
|
-
email: string,
|
|
196
|
-
permissions: SubuserPermission[] | string[]
|
|
197
|
-
) => {
|
|
198
|
-
const data = await this.client.users.create(email, permissions)
|
|
199
|
-
return new ServerUser(this.client, data)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
getStartupInfo = async () => this.client.startup.list()
|
|
203
|
-
|
|
204
|
-
setStartupVariable = async (key: string, value: string) =>
|
|
205
|
-
this.client.startup.set(key, value)
|
|
206
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {ServerAllocation as ServerAllocationT} from "@/api/client/types/server_allocation"
|
|
3
|
-
import type {Nullable} from "@/utils/types"
|
|
4
|
-
|
|
5
|
-
export class ServerAllocation {
|
|
6
|
-
private readonly client: ServerClient
|
|
7
|
-
readonly alias: Nullable<string>
|
|
8
|
-
readonly id: number
|
|
9
|
-
readonly ip: string
|
|
10
|
-
private $isDefault: boolean
|
|
11
|
-
get isDefault() {
|
|
12
|
-
return this.$isDefault
|
|
13
|
-
}
|
|
14
|
-
private $notes: Nullable<string>
|
|
15
|
-
get notes() {
|
|
16
|
-
return this.$notes
|
|
17
|
-
}
|
|
18
|
-
readonly port: number
|
|
19
|
-
|
|
20
|
-
constructor(client: ServerClient, alloc: ServerAllocationT) {
|
|
21
|
-
this.client = client
|
|
22
|
-
this.alias = alloc.ip_alias
|
|
23
|
-
this.id = alloc.id
|
|
24
|
-
this.ip = alloc.ip
|
|
25
|
-
this.$isDefault = alloc.is_default
|
|
26
|
-
this.$notes = alloc.notes
|
|
27
|
-
this.port = alloc.port
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
setNotes = async (notes: string) => {
|
|
31
|
-
const data = await this.client.allocations.setNotes(this.id, notes)
|
|
32
|
-
this.$notes = data.notes
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
makeDefault = async () => {
|
|
36
|
-
const data = await this.client.allocations.setPrimary(this.id)
|
|
37
|
-
this.$isDefault = data.is_default
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
unassign = async () => this.client.allocations.unassign(this.id)
|
|
41
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {ServerBackup as ServerBackupT} from "@/api/common/types/server_backup"
|
|
3
|
-
import type {Nullable} from "@/utils/types"
|
|
4
|
-
|
|
5
|
-
export class ServerBackup {
|
|
6
|
-
private readonly client: ServerClient
|
|
7
|
-
readonly bytes: number
|
|
8
|
-
readonly checksum: Nullable<string>
|
|
9
|
-
readonly completedAt: Nullable<Date>
|
|
10
|
-
readonly createdAt: Date
|
|
11
|
-
readonly ignoredFiles: string[]
|
|
12
|
-
readonly isLocked: boolean
|
|
13
|
-
readonly isSuccessful: boolean
|
|
14
|
-
readonly name: string
|
|
15
|
-
readonly uuid: string
|
|
16
|
-
|
|
17
|
-
constructor(client: ServerClient, backup: ServerBackupT) {
|
|
18
|
-
this.client = client
|
|
19
|
-
this.bytes = backup.bytes
|
|
20
|
-
this.checksum = backup.checksum
|
|
21
|
-
this.completedAt = backup.completed_at
|
|
22
|
-
? new Date(backup.completed_at)
|
|
23
|
-
: null
|
|
24
|
-
this.createdAt = new Date(backup.created_at)
|
|
25
|
-
this.ignoredFiles = backup.ignored_files
|
|
26
|
-
this.isLocked = backup.is_locked
|
|
27
|
-
this.isSuccessful = backup.is_successful
|
|
28
|
-
this.name = backup.name
|
|
29
|
-
this.uuid = backup.uuid
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
downloadGetUrl = async () => this.client.backups.downloadGetUrl(this.uuid)
|
|
33
|
-
|
|
34
|
-
download = async () => this.client.backups.download(this.uuid)
|
|
35
|
-
|
|
36
|
-
delete = async () => this.client.backups.delete(this.uuid)
|
|
37
|
-
|
|
38
|
-
rename = async (name: string) => this.client.backups.rename(this.uuid, name)
|
|
39
|
-
|
|
40
|
-
toggleLock = async () => this.client.backups.toggleLock(this.uuid)
|
|
41
|
-
|
|
42
|
-
restore = async (truncate: boolean) =>
|
|
43
|
-
this.client.backups.restore(this.uuid, truncate)
|
|
44
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {ServerDatabase as ServerDatabaseT} from "@/api/common/types/server_database"
|
|
3
|
-
// TODO: Check for validity
|
|
4
|
-
|
|
5
|
-
export class ServerDatabase {
|
|
6
|
-
private readonly client: ServerClient
|
|
7
|
-
readonly allowConnectionsFrom: string
|
|
8
|
-
readonly host: string
|
|
9
|
-
readonly port: number
|
|
10
|
-
readonly id: string
|
|
11
|
-
readonly maxConnections: number
|
|
12
|
-
readonly name: string
|
|
13
|
-
private $password?: string
|
|
14
|
-
get password() {
|
|
15
|
-
return this.$password
|
|
16
|
-
}
|
|
17
|
-
readonly username: string
|
|
18
|
-
|
|
19
|
-
constructor(client: ServerClient, database: ServerDatabaseT) {
|
|
20
|
-
this.client = client
|
|
21
|
-
this.allowConnectionsFrom = database.connections_from
|
|
22
|
-
this.host = database.host.address
|
|
23
|
-
this.port = database.host.port
|
|
24
|
-
this.id = database.id
|
|
25
|
-
this.maxConnections = database.max_connections
|
|
26
|
-
this.name = database.name
|
|
27
|
-
this.$password = database.relationships?.password.attributes.password
|
|
28
|
-
this.username = database.username
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
rotatePassword = async () => {
|
|
32
|
-
const data = await this.client.databases.rotatePassword(this.id)
|
|
33
|
-
this.$password = data.relationships?.password.attributes.password
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
delete = async () => this.client.databases.delete(this.id)
|
|
37
|
-
}
|
package/src/humane/ServerFile.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import path from "node:path"
|
|
2
|
-
import type {ServerClient} from "@/api/client/server"
|
|
3
|
-
import type {FileObject} from "@/api/common/types/server_files"
|
|
4
|
-
|
|
5
|
-
export class ServerFile {
|
|
6
|
-
private readonly client: ServerClient
|
|
7
|
-
private readonly dir: string
|
|
8
|
-
private readonly path: string
|
|
9
|
-
readonly createdAt: Date
|
|
10
|
-
readonly isFile: boolean
|
|
11
|
-
readonly isSymlink: boolean
|
|
12
|
-
readonly mimetype: string
|
|
13
|
-
readonly mode: string
|
|
14
|
-
readonly modeBits: string
|
|
15
|
-
readonly modifiedAt: Date
|
|
16
|
-
readonly name: string
|
|
17
|
-
readonly size: number
|
|
18
|
-
|
|
19
|
-
constructor(client: ServerClient, file: FileObject, dir: string = "/") {
|
|
20
|
-
this.client = client
|
|
21
|
-
this.dir = dir
|
|
22
|
-
this.createdAt = new Date(file.created_at)
|
|
23
|
-
this.isFile = file.is_file
|
|
24
|
-
this.isSymlink = file.is_symlink
|
|
25
|
-
this.mimetype = file.mimetype
|
|
26
|
-
this.mode = file.mode
|
|
27
|
-
this.modeBits = file.mode_bits
|
|
28
|
-
this.modifiedAt = new Date(file.modified_at)
|
|
29
|
-
this.name = file.name
|
|
30
|
-
this.size = file.size
|
|
31
|
-
this.path = path.join(dir, this.name)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get isArchive() {
|
|
35
|
-
// Maybe mimetype is better
|
|
36
|
-
return [
|
|
37
|
-
"zip",
|
|
38
|
-
"tgz",
|
|
39
|
-
"tar.gz",
|
|
40
|
-
"txz",
|
|
41
|
-
"tar.xz",
|
|
42
|
-
"tbz2",
|
|
43
|
-
"tar.bz2"
|
|
44
|
-
].some(ext => this.name.endsWith(`.${ext}`))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Return the contents of a file. To read binary file (non-editable) use {@link download} instead
|
|
49
|
-
*/
|
|
50
|
-
contents = async () => this.client.files.contents(this.path)
|
|
51
|
-
|
|
52
|
-
downloadGetUrl = async () => this.client.files.downloadGetUrl(this.path)
|
|
53
|
-
|
|
54
|
-
download = async () => this.client.files.download(this.path)
|
|
55
|
-
|
|
56
|
-
rename = async (newName: string) =>
|
|
57
|
-
this.client.files.rename(this.dir, [{from: this.name, to: newName}])
|
|
58
|
-
|
|
59
|
-
copy = async () => this.client.files.copy(this.path)
|
|
60
|
-
|
|
61
|
-
write = async (content: string) =>
|
|
62
|
-
this.client.files.write(this.path, content)
|
|
63
|
-
|
|
64
|
-
compress = async (
|
|
65
|
-
archive_name?: string,
|
|
66
|
-
extension?:
|
|
67
|
-
| "zip"
|
|
68
|
-
| "tgz"
|
|
69
|
-
| "tar.gz"
|
|
70
|
-
| "txz"
|
|
71
|
-
| "tar.xz"
|
|
72
|
-
| "tbz2"
|
|
73
|
-
| "tar.bz2"
|
|
74
|
-
) =>
|
|
75
|
-
new ServerFile(
|
|
76
|
-
this.client,
|
|
77
|
-
await this.client.files.compress(
|
|
78
|
-
this.dir,
|
|
79
|
-
[this.name],
|
|
80
|
-
archive_name,
|
|
81
|
-
extension
|
|
82
|
-
)
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
decompress = async () => this.client.files.decompress(this.dir, this.name)
|
|
86
|
-
|
|
87
|
-
delete = async () => this.client.files.delete(this.dir, [this.name])
|
|
88
|
-
|
|
89
|
-
chmod = async (mode: number) =>
|
|
90
|
-
this.client.files.chmod(this.dir, [{file: this.name, mode}])
|
|
91
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {Schedule, ScheduleTask} from "@/api/common/types/server_schedule"
|
|
3
|
-
import type {Nullable, PartialBy} from "@/utils/types"
|
|
4
|
-
|
|
5
|
-
export class ServerSchedule {
|
|
6
|
-
private readonly client: ServerClient
|
|
7
|
-
readonly createdAt: Date
|
|
8
|
-
private $cron: {
|
|
9
|
-
day_of_week: string
|
|
10
|
-
day_of_month: string
|
|
11
|
-
hour: string
|
|
12
|
-
minute: string
|
|
13
|
-
}
|
|
14
|
-
get cron() {
|
|
15
|
-
return {...this.$cron}
|
|
16
|
-
}
|
|
17
|
-
readonly id: number
|
|
18
|
-
private $isActive: boolean
|
|
19
|
-
get isActive() {
|
|
20
|
-
return this.$isActive
|
|
21
|
-
}
|
|
22
|
-
private $isProcessing: boolean
|
|
23
|
-
get isProcessing() {
|
|
24
|
-
return this.$isProcessing
|
|
25
|
-
}
|
|
26
|
-
readonly lastRunAt: Nullable<Date>
|
|
27
|
-
private $name: string
|
|
28
|
-
get name() {
|
|
29
|
-
return this.$name
|
|
30
|
-
}
|
|
31
|
-
readonly nextRunAt: Date
|
|
32
|
-
private $onlyWhenOnline: boolean
|
|
33
|
-
get onlyWhenOnline() {
|
|
34
|
-
return this.$onlyWhenOnline
|
|
35
|
-
}
|
|
36
|
-
readonly tasks: ServerScheduleTask[]
|
|
37
|
-
private $updatedAt: Date
|
|
38
|
-
get updatedAt() {
|
|
39
|
-
return this.$updatedAt
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
constructor(client: ServerClient, schedule: Schedule) {
|
|
43
|
-
this.client = client
|
|
44
|
-
this.createdAt = new Date(schedule.created_at)
|
|
45
|
-
this.$cron = schedule.cron
|
|
46
|
-
this.id = schedule.id
|
|
47
|
-
this.$isActive = schedule.is_active
|
|
48
|
-
this.$isProcessing = schedule.is_processing
|
|
49
|
-
this.lastRunAt = schedule.last_run_at
|
|
50
|
-
? new Date(schedule.last_run_at)
|
|
51
|
-
: null
|
|
52
|
-
this.$name = schedule.name
|
|
53
|
-
this.nextRunAt = new Date(schedule.next_run_at)
|
|
54
|
-
this.$onlyWhenOnline = schedule.only_when_online
|
|
55
|
-
this.tasks = schedule.relationships.tasks.data.map(
|
|
56
|
-
d => new ServerScheduleTask(this.client, this.id, d.attributes)
|
|
57
|
-
)
|
|
58
|
-
this.$updatedAt = new Date(schedule.updated_at)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
update = async (opts: {
|
|
62
|
-
name: string
|
|
63
|
-
is_active?: boolean
|
|
64
|
-
only_when_online?: boolean
|
|
65
|
-
minute: string
|
|
66
|
-
hour: string
|
|
67
|
-
day_of_week: string
|
|
68
|
-
month: string
|
|
69
|
-
day_of_month: string
|
|
70
|
-
}) => {
|
|
71
|
-
const data = await this.client.schedules.control(this.id).update(opts)
|
|
72
|
-
this.$name = data.name
|
|
73
|
-
this.$isActive = data.is_active
|
|
74
|
-
this.$isProcessing = data.is_processing
|
|
75
|
-
this.$onlyWhenOnline = data.only_when_online
|
|
76
|
-
this.$cron = data.cron
|
|
77
|
-
this.$updatedAt = new Date(data.updated_at)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
delete = async () => this.client.schedules.control(this.id).delete()
|
|
81
|
-
|
|
82
|
-
execute = async () => this.client.schedules.control(this.id).execute()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export class ServerScheduleTask {
|
|
86
|
-
private readonly client: ServerClient
|
|
87
|
-
private readonly scheduleId: number
|
|
88
|
-
private $action: "command" | "power" | "backup" | "delete_files"
|
|
89
|
-
get action() {
|
|
90
|
-
return this.$action
|
|
91
|
-
}
|
|
92
|
-
private $continueOnFailure: boolean
|
|
93
|
-
get continueOnFailure() {
|
|
94
|
-
return this.$continueOnFailure
|
|
95
|
-
}
|
|
96
|
-
readonly createdAt: Date
|
|
97
|
-
readonly id: number
|
|
98
|
-
private $isQueued: boolean
|
|
99
|
-
get isQueued() {
|
|
100
|
-
return this.$isQueued
|
|
101
|
-
}
|
|
102
|
-
private $payload: string
|
|
103
|
-
get payload() {
|
|
104
|
-
return this.$payload
|
|
105
|
-
}
|
|
106
|
-
private $sequenceId: number
|
|
107
|
-
get sequenceId() {
|
|
108
|
-
return this.$sequenceId
|
|
109
|
-
}
|
|
110
|
-
private $timeOffset: number
|
|
111
|
-
get timeOffset() {
|
|
112
|
-
return this.$timeOffset
|
|
113
|
-
}
|
|
114
|
-
private $updatedAt: Nullable<Date>
|
|
115
|
-
get updatedAt() {
|
|
116
|
-
return this.$updatedAt
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
constructor(client: ServerClient, scheduleId: number, task: ScheduleTask) {
|
|
120
|
-
this.client = client
|
|
121
|
-
this.scheduleId = scheduleId
|
|
122
|
-
this.$action = task.action
|
|
123
|
-
this.$continueOnFailure = task.continue_on_failure
|
|
124
|
-
this.createdAt = new Date(task.created_at)
|
|
125
|
-
this.id = task.id
|
|
126
|
-
this.$isQueued = task.is_queued
|
|
127
|
-
this.$payload = task.payload
|
|
128
|
-
this.$sequenceId = task.sequence_id
|
|
129
|
-
this.$timeOffset = task.time_offset
|
|
130
|
-
this.$updatedAt = task.updated_at ? new Date(task.updated_at) : null
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
delete = async () =>
|
|
134
|
-
this.client.schedules.control(this.scheduleId).tasks.delete(this.id)
|
|
135
|
-
|
|
136
|
-
update = async (
|
|
137
|
-
opts: PartialBy<
|
|
138
|
-
Pick<
|
|
139
|
-
ScheduleTask,
|
|
140
|
-
| "action"
|
|
141
|
-
| "payload"
|
|
142
|
-
| "time_offset"
|
|
143
|
-
| "sequence_id"
|
|
144
|
-
| "continue_on_failure"
|
|
145
|
-
>,
|
|
146
|
-
"payload" | "sequence_id" | "continue_on_failure"
|
|
147
|
-
>
|
|
148
|
-
) => {
|
|
149
|
-
const data = await this.client.schedules
|
|
150
|
-
.control(this.scheduleId)
|
|
151
|
-
.tasks.update(this.id, opts)
|
|
152
|
-
this.$action = data.action
|
|
153
|
-
this.$continueOnFailure = data.continue_on_failure
|
|
154
|
-
this.$isQueued = data.is_queued
|
|
155
|
-
this.$payload = data.payload
|
|
156
|
-
this.$sequenceId = data.sequence_id
|
|
157
|
-
this.$timeOffset = data.time_offset
|
|
158
|
-
this.$updatedAt = data.updated_at ? new Date(data.updated_at) : null
|
|
159
|
-
}
|
|
160
|
-
}
|
package/src/humane/ServerUser.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type {ServerClient} from "@/api/client/server"
|
|
2
|
-
import type {
|
|
3
|
-
ServerSubuser,
|
|
4
|
-
SubuserPermission
|
|
5
|
-
} from "@/api/client/types/server_subuser"
|
|
6
|
-
|
|
7
|
-
export class ServerUser {
|
|
8
|
-
private readonly client: ServerClient
|
|
9
|
-
|
|
10
|
-
readonly uuid: string
|
|
11
|
-
readonly username: string
|
|
12
|
-
readonly email: string
|
|
13
|
-
readonly language: string
|
|
14
|
-
readonly image: string
|
|
15
|
-
readonly admin: boolean
|
|
16
|
-
readonly root_admin: boolean
|
|
17
|
-
readonly has2faEnabled: boolean
|
|
18
|
-
readonly createdAt: Date
|
|
19
|
-
private $permissions: SubuserPermission[] | string[]
|
|
20
|
-
get permissions() {
|
|
21
|
-
return this.$permissions
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
constructor(client: ServerClient, user: ServerSubuser) {
|
|
25
|
-
this.client = client
|
|
26
|
-
this.uuid = user.uuid
|
|
27
|
-
this.username = user.username
|
|
28
|
-
this.email = user.email
|
|
29
|
-
this.language = user.language
|
|
30
|
-
this.image = user.image
|
|
31
|
-
this.admin = user.admin
|
|
32
|
-
this.root_admin = user.root_admin
|
|
33
|
-
this.has2faEnabled = user["2fa_enabled"]
|
|
34
|
-
this.createdAt = new Date(user.created_at)
|
|
35
|
-
this.$permissions = user.permissions
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
update = async (permissions: SubuserPermission[] | string[]) => {
|
|
39
|
-
const data = await this.client.users.update(this.uuid, permissions)
|
|
40
|
-
this.$permissions = data.permissions
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
delete = async () => this.client.users.delete(this.uuid)
|
|
44
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {PelicanAPIClient} from "@/api"
|
|
2
|
-
import {Client as UserClient} from "@/humane/Client"
|
|
3
|
-
|
|
4
|
-
export const createPelicanClient = (
|
|
5
|
-
url: string,
|
|
6
|
-
token: string,
|
|
7
|
-
suffix: string = "/api"
|
|
8
|
-
) => {
|
|
9
|
-
const client = new PelicanAPIClient(url, token, suffix)
|
|
10
|
-
return new UserClient(client)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export {Client} from "@/humane/Client"
|
|
14
|
-
export {Account} from "@/humane/Account"
|
|
15
|
-
export {Server} from "@/humane/Server"
|
|
16
|
-
export {ServerAllocation} from "@/humane/ServerAllocation"
|
|
17
|
-
export {ServerBackup} from "@/humane/ServerBackup"
|
|
18
|
-
export {ServerDatabase} from "@/humane/ServerDatabase"
|
|
19
|
-
export {ServerFile} from "@/humane/ServerFile"
|
|
20
|
-
export {ServerSchedule} from "@/humane/ServerSchedule"
|
|
21
|
-
export {ServerUser} from "@/humane/ServerUser"
|
package/src/types.ts
DELETED
package/src/utils/sized.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const SIZES = {
|
|
2
|
-
B: 1,
|
|
3
|
-
KB: 1024,
|
|
4
|
-
MB: 1024 * 1024,
|
|
5
|
-
GB: 1024 * 1024 * 1024,
|
|
6
|
-
TB: 1024 * 1024 * 1024 * 1024
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const sized = (bytes: number, unit: keyof typeof SIZES): number => {
|
|
10
|
-
return parseInt((bytes / SIZES[unit]).toFixed(3), 10)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default sized
|
package/src/utils/transform.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {string} from "zod"
|
|
2
|
-
|
|
3
|
-
export const ArrayQueryParams = (p: {
|
|
4
|
-
[key: string]: {[key: string]: string}
|
|
5
|
-
}): {[key: string]: string} => {
|
|
6
|
-
const params = new URLSearchParams()
|
|
7
|
-
|
|
8
|
-
const o: ReturnType<typeof ArrayQueryParams> = {}
|
|
9
|
-
|
|
10
|
-
for (const [param, value] of Object.entries(p)) {
|
|
11
|
-
for (const [key, val] of Object.entries(value)) {
|
|
12
|
-
o[`${param}[${key}]`] = val
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return o
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const SortParam = (key: string, p: "asc" | "desc"): string => {
|
|
20
|
-
return `${p === "desc" ? "-" : ""}${key}`
|
|
21
|
-
}
|