@pelican.ts/sdk 0.4.15 → 0.4.16-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/bun.lock +40 -0
- package/dist/api/index.d.mts +774 -783
- package/dist/api/index.d.ts +774 -783
- package/dist/api/index.js +1540 -1534
- package/dist/api/index.mjs +1540 -1534
- package/dist/index.d.mts +270 -188
- package/dist/index.d.ts +270 -188
- package/dist/index.js +1118 -1081
- package/dist/index.mjs +1118 -1081
- package/dist/types.d.ts +250 -259
- package/package.json +3 -1
package/dist/api/index.js
CHANGED
|
@@ -35,1099 +35,588 @@ __export(index_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
|
-
// src/api/
|
|
38
|
+
// src/api/application/database_hosts.ts
|
|
39
39
|
var import_zod = __toESM(require("zod"));
|
|
40
|
-
var
|
|
40
|
+
var DatabaseHosts = class {
|
|
41
41
|
r;
|
|
42
|
-
constructor(
|
|
43
|
-
this.r =
|
|
42
|
+
constructor(r) {
|
|
43
|
+
this.r = r;
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
const { data } = await this.r.get("/
|
|
47
|
-
return data.attributes;
|
|
45
|
+
list = async (page = 1) => {
|
|
46
|
+
const { data } = await this.r.get("/database-hosts", { params: { page } });
|
|
47
|
+
return data.data.map((d) => d.attributes);
|
|
48
48
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
info = async (id) => {
|
|
50
|
+
const { data } = await this.r.get(`/database-hosts/${id}`);
|
|
51
|
+
return data.attributes;
|
|
52
52
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
// TODO: find out why API returns 500
|
|
54
|
+
create = async (opts) => {
|
|
55
|
+
opts = CreateDBHostSchema.parse(opts);
|
|
56
|
+
await this.r.post(
|
|
57
|
+
"/database-hosts",
|
|
58
|
+
opts
|
|
59
|
+
).catch((e) => {
|
|
58
60
|
});
|
|
59
61
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
create: async (description, allowed_ips) => {
|
|
66
|
-
allowed_ips = import_zod.default.array(import_zod.default.ipv4()).optional().parse(allowed_ips);
|
|
67
|
-
const { data } = await this.r.post("/account/api-keys", { description, allowed_ips });
|
|
68
|
-
return { ...data.attributes, secret_token: data.meta.secret_token };
|
|
69
|
-
},
|
|
70
|
-
delete: async (identifier) => {
|
|
71
|
-
await this.r.delete(`/account/api-keys/${identifier}`);
|
|
72
|
-
}
|
|
62
|
+
update = async (id, opts) => {
|
|
63
|
+
opts = CreateDBHostSchema.parse(opts);
|
|
64
|
+
const { data } = await this.r.patch(`/database-hosts/${id}`, opts);
|
|
65
|
+
return data.attributes;
|
|
73
66
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const { data } = await this.r.get("/account/ssh-keys");
|
|
77
|
-
return data.data.map((k) => k.attributes);
|
|
78
|
-
},
|
|
79
|
-
create: async (name, public_key) => {
|
|
80
|
-
const { data } = await this.r.post("/account/ssh-keys", { name, public_key });
|
|
81
|
-
return data.attributes;
|
|
82
|
-
},
|
|
83
|
-
delete: async (fingerprint) => {
|
|
84
|
-
await this.r.delete(`/account/ssh-keys/${fingerprint}`);
|
|
85
|
-
}
|
|
67
|
+
delete = async (id) => {
|
|
68
|
+
await this.r.delete(`/database-hosts/${id}`);
|
|
86
69
|
};
|
|
87
70
|
};
|
|
71
|
+
var CreateDBHostSchema = import_zod.default.object({
|
|
72
|
+
name: import_zod.default.string().min(1).max(255),
|
|
73
|
+
host: import_zod.default.string(),
|
|
74
|
+
port: import_zod.default.number().min(1).max(65535),
|
|
75
|
+
username: import_zod.default.string().min(1).max(255),
|
|
76
|
+
password: import_zod.default.string().optional(),
|
|
77
|
+
node_ids: import_zod.default.array(import_zod.default.string()).optional(),
|
|
78
|
+
max_databases: import_zod.default.number().optional()
|
|
79
|
+
});
|
|
88
80
|
|
|
89
|
-
// src/api/
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
// src/api/client/server_databases.ts
|
|
93
|
-
var import_zod2 = __toESM(require("zod"));
|
|
94
|
-
var ServerDatabases = class {
|
|
81
|
+
// src/api/application/eggs.ts
|
|
82
|
+
var Eggs = class {
|
|
95
83
|
r;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.r = requester;
|
|
99
|
-
this.id = id;
|
|
84
|
+
constructor(r) {
|
|
85
|
+
this.r = r;
|
|
100
86
|
}
|
|
101
|
-
list = async (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
87
|
+
list = async () => {
|
|
88
|
+
const { data } = await this.r.get(
|
|
89
|
+
"/eggs"
|
|
90
|
+
);
|
|
106
91
|
return data.data.map((d) => d.attributes);
|
|
107
92
|
};
|
|
108
|
-
|
|
109
|
-
const { data } = await this.r.
|
|
93
|
+
info = async (id) => {
|
|
94
|
+
const { data } = await this.r.get(
|
|
95
|
+
`/eggs/${id}`
|
|
96
|
+
);
|
|
110
97
|
return data.attributes;
|
|
111
98
|
};
|
|
112
|
-
|
|
113
|
-
const { data } = await this.r.
|
|
114
|
-
|
|
99
|
+
export = async (id, format) => {
|
|
100
|
+
const { data } = await this.r.get(`/eggs/${id}/export`, {
|
|
101
|
+
params: { format },
|
|
102
|
+
transformResponse: (r) => r
|
|
103
|
+
});
|
|
104
|
+
return data;
|
|
115
105
|
};
|
|
116
|
-
|
|
117
|
-
await this.r.
|
|
106
|
+
infoExportable = async (id) => {
|
|
107
|
+
const { data } = await this.r.get(`/eggs/${id}/export`, {
|
|
108
|
+
params: { format: "json" }
|
|
109
|
+
});
|
|
110
|
+
return data;
|
|
118
111
|
};
|
|
119
112
|
};
|
|
120
113
|
|
|
121
|
-
// src/api/
|
|
122
|
-
var
|
|
123
|
-
var
|
|
114
|
+
// src/api/application/mounts.ts
|
|
115
|
+
var import_zod2 = __toESM(require("zod"));
|
|
116
|
+
var Mounts = class {
|
|
124
117
|
r;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.r = requester;
|
|
128
|
-
this.id = id;
|
|
118
|
+
constructor(r) {
|
|
119
|
+
this.r = r;
|
|
129
120
|
}
|
|
130
|
-
list = async (
|
|
131
|
-
const { data } = await this.r.get(
|
|
132
|
-
return data.data.map((
|
|
121
|
+
list = async () => {
|
|
122
|
+
const { data } = await this.r.get("/mounts");
|
|
123
|
+
return data.data.map((d) => d.attributes);
|
|
133
124
|
};
|
|
134
|
-
|
|
135
|
-
* Return the contents of a file. To read binary file (non-editable) use {@link download} instead
|
|
136
|
-
*/
|
|
137
|
-
contents = async (path) => {
|
|
125
|
+
info = async (id) => {
|
|
138
126
|
const { data } = await this.r.get(
|
|
139
|
-
`/
|
|
140
|
-
{ params: { file: path } }
|
|
127
|
+
`/mounts/${id}`
|
|
141
128
|
);
|
|
142
|
-
return data;
|
|
143
|
-
};
|
|
144
|
-
downloadGetUrl = async (path) => {
|
|
145
|
-
const { data } = await this.r.get(`/servers/${this.id}/files/download`, { params: { file: path } });
|
|
146
|
-
return data.attributes.url;
|
|
129
|
+
return data.attributes;
|
|
147
130
|
};
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const { data } = await
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
131
|
+
create = async (opts) => {
|
|
132
|
+
opts = CreateMountSchema.parse(opts);
|
|
133
|
+
const { data } = await this.r.post(
|
|
134
|
+
"/mounts",
|
|
135
|
+
opts
|
|
136
|
+
);
|
|
137
|
+
return data.attributes;
|
|
154
138
|
};
|
|
155
|
-
|
|
156
|
-
|
|
139
|
+
update = async (id, opts) => {
|
|
140
|
+
opts = CreateMountSchema.parse(opts);
|
|
141
|
+
const { data } = await this.r.patch(
|
|
142
|
+
`/mounts/${id}`,
|
|
143
|
+
opts
|
|
144
|
+
);
|
|
145
|
+
return data.attributes;
|
|
157
146
|
};
|
|
158
|
-
|
|
159
|
-
await this.r.
|
|
147
|
+
delete = async (id) => {
|
|
148
|
+
await this.r.delete(`/mounts/${id}`);
|
|
160
149
|
};
|
|
161
|
-
|
|
162
|
-
await this.r.
|
|
163
|
-
|
|
164
|
-
});
|
|
150
|
+
listAssignedEggs = async (id) => {
|
|
151
|
+
const { data } = await this.r.get(`/mounts/${id}/eggs`);
|
|
152
|
+
return data.data.map((d) => d.attributes);
|
|
165
153
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
root,
|
|
169
|
-
files,
|
|
170
|
-
archive_name,
|
|
171
|
-
extension
|
|
172
|
-
});
|
|
173
|
-
return data.attributes;
|
|
154
|
+
assignEggs = async (id, eggs) => {
|
|
155
|
+
await this.r.post(`/mounts/${id}/eggs`, { eggs });
|
|
174
156
|
};
|
|
175
|
-
|
|
176
|
-
await this.r.
|
|
157
|
+
unassignEgg = async (id, egg_id) => {
|
|
158
|
+
await this.r.delete(`/mounts/${id}/eggs/${egg_id}`);
|
|
177
159
|
};
|
|
178
|
-
|
|
179
|
-
await this.r.
|
|
160
|
+
listAssignedNodes = async (id) => {
|
|
161
|
+
const { data } = await this.r.get(`/mounts/${id}/nodes`);
|
|
162
|
+
return data.data.map((d) => d.attributes);
|
|
180
163
|
};
|
|
181
|
-
|
|
182
|
-
await this.r.post(`/
|
|
183
|
-
root,
|
|
184
|
-
name
|
|
185
|
-
});
|
|
164
|
+
assignNodes = async (id, nodes) => {
|
|
165
|
+
await this.r.post(`/mounts/${id}/nodes`, { nodes });
|
|
186
166
|
};
|
|
187
|
-
|
|
188
|
-
await this.r.
|
|
167
|
+
unassignNode = async (id, node_id) => {
|
|
168
|
+
await this.r.delete(`/mounts/${id}/nodes/${node_id}`);
|
|
189
169
|
};
|
|
190
|
-
|
|
191
|
-
await this.r.
|
|
192
|
-
|
|
193
|
-
directory,
|
|
194
|
-
filename,
|
|
195
|
-
use_header,
|
|
196
|
-
foreground
|
|
197
|
-
});
|
|
170
|
+
listAssignedServers = async (id) => {
|
|
171
|
+
const { data } = await this.r.get(`/mounts/${id}/servers`);
|
|
172
|
+
return data.data.map((d) => d.attributes);
|
|
198
173
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
return data.attributes.url;
|
|
174
|
+
assignServers = async (id, servers) => {
|
|
175
|
+
await this.r.post(`/mounts/${id}/servers`, { servers });
|
|
202
176
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
await import_axios.default.post(
|
|
206
|
-
url,
|
|
207
|
-
{ files: file },
|
|
208
|
-
{
|
|
209
|
-
headers: { "Content-Type": "multipart/form-data" },
|
|
210
|
-
params: { directory: root }
|
|
211
|
-
}
|
|
212
|
-
);
|
|
177
|
+
unassignServer = async (id, server_id) => {
|
|
178
|
+
await this.r.delete(`/mounts/${id}/servers/${server_id}`);
|
|
213
179
|
};
|
|
214
180
|
};
|
|
181
|
+
var CreateMountSchema = import_zod2.default.object({
|
|
182
|
+
name: import_zod2.default.string().min(1).max(255),
|
|
183
|
+
description: import_zod2.default.string().optional(),
|
|
184
|
+
source: import_zod2.default.string(),
|
|
185
|
+
target: import_zod2.default.string(),
|
|
186
|
+
read_only: import_zod2.default.boolean().optional()
|
|
187
|
+
});
|
|
215
188
|
|
|
216
|
-
// src/api/
|
|
217
|
-
var
|
|
189
|
+
// src/api/application/nodes.ts
|
|
190
|
+
var import_zod4 = __toESM(require("zod"));
|
|
191
|
+
|
|
192
|
+
// src/api/application/nodes_allocations.ts
|
|
193
|
+
var import_zod3 = __toESM(require("zod"));
|
|
194
|
+
var NodesAllocations = class {
|
|
218
195
|
r;
|
|
219
196
|
id;
|
|
220
197
|
constructor(requester, id) {
|
|
221
198
|
this.r = requester;
|
|
222
199
|
this.id = id;
|
|
223
200
|
}
|
|
224
|
-
list = async () => {
|
|
225
|
-
const { data } = await this.r.get(`/
|
|
201
|
+
list = async (page = 1, per_page = 50, include) => {
|
|
202
|
+
const { data } = await this.r.get(`/nodes/${this.id}/allocations`, {
|
|
203
|
+
params: {
|
|
204
|
+
page,
|
|
205
|
+
per_page,
|
|
206
|
+
include: include?.join(",")
|
|
207
|
+
}
|
|
208
|
+
});
|
|
226
209
|
return data.data.map((d) => d.attributes);
|
|
227
210
|
};
|
|
228
|
-
create = async (
|
|
229
|
-
|
|
230
|
-
|
|
211
|
+
create = async (ip, ports, alias) => {
|
|
212
|
+
import_zod3.default.ipv4().parse(ip);
|
|
213
|
+
import_zod3.default.ipv4().or(import_zod3.default.url().max(255)).optional().parse(alias);
|
|
214
|
+
import_zod3.default.array(import_zod3.default.number()).or(import_zod3.default.string().regex(/\d+-\d+/)).parse(ports);
|
|
215
|
+
await this.r.post(`/nodes/${this.id}/allocations`, { ip, ports, alias });
|
|
216
|
+
};
|
|
217
|
+
delete = async (alloc_id) => {
|
|
218
|
+
await this.r.delete(`/nodes/${this.id}/allocations/${alloc_id}`);
|
|
231
219
|
};
|
|
232
|
-
control = (sched_id) => new ScheduleControl(this.r, this.id, sched_id);
|
|
233
220
|
};
|
|
234
|
-
|
|
221
|
+
|
|
222
|
+
// src/api/application/nodes.ts
|
|
223
|
+
var Nodes = class {
|
|
235
224
|
r;
|
|
236
|
-
|
|
237
|
-
sched_id;
|
|
238
|
-
constructor(requester, id, sched_id) {
|
|
225
|
+
constructor(requester) {
|
|
239
226
|
this.r = requester;
|
|
240
|
-
this.id = id;
|
|
241
|
-
this.sched_id = sched_id;
|
|
242
227
|
}
|
|
243
|
-
|
|
244
|
-
|
|
228
|
+
list = async (include, page = 1) => {
|
|
229
|
+
import_zod4.default.number().positive().parse(page);
|
|
230
|
+
const { data } = await this.r.get("/nodes", { params: { include: include?.join(","), page } });
|
|
231
|
+
return data.data.map((s) => s.attributes);
|
|
232
|
+
};
|
|
233
|
+
listDeployable = async (filters, include, page = 1) => {
|
|
234
|
+
import_zod4.default.number().positive().parse(page);
|
|
235
|
+
const { data } = await this.r.get("/nodes/deployable", {
|
|
236
|
+
params: {
|
|
237
|
+
include: include?.join(","),
|
|
238
|
+
disk: filters.disk,
|
|
239
|
+
memory: filters.memory,
|
|
240
|
+
cpu: filters.cpu,
|
|
241
|
+
location_ids: filters.location_ids,
|
|
242
|
+
tags: filters.tags,
|
|
243
|
+
page
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return data.data.map((s) => s.attributes);
|
|
247
|
+
};
|
|
248
|
+
info = async (id, include) => {
|
|
249
|
+
import_zod4.default.number().positive().parse(id);
|
|
250
|
+
const { data } = await this.r.get(
|
|
251
|
+
`/nodes/${id}`,
|
|
252
|
+
{ params: { include: include?.join(",") } }
|
|
253
|
+
);
|
|
245
254
|
return data.attributes;
|
|
246
255
|
};
|
|
247
|
-
|
|
248
|
-
|
|
256
|
+
create = async (node) => {
|
|
257
|
+
node = NodeCreateSchema.parse(node);
|
|
258
|
+
const { data } = await this.r.post(
|
|
259
|
+
"/nodes",
|
|
260
|
+
node
|
|
261
|
+
);
|
|
249
262
|
return data.attributes;
|
|
250
263
|
};
|
|
251
|
-
|
|
252
|
-
|
|
264
|
+
get_configuration = async (id) => {
|
|
265
|
+
import_zod4.default.number().positive().parse(id);
|
|
266
|
+
const { data } = await this.r.get(
|
|
267
|
+
`/nodes/${id}/configuration`
|
|
268
|
+
);
|
|
269
|
+
return data;
|
|
253
270
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
271
|
+
update = async (id, node) => {
|
|
272
|
+
import_zod4.default.number().positive().parse(id);
|
|
273
|
+
node = NodeCreateSchema.parse(node);
|
|
274
|
+
const { data } = await this.r.patch(
|
|
275
|
+
`/nodes/${id}`,
|
|
276
|
+
node
|
|
257
277
|
);
|
|
278
|
+
return data.attributes;
|
|
258
279
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return data.attributes;
|
|
263
|
-
},
|
|
264
|
-
update: async (task_id, opts) => {
|
|
265
|
-
const { data } = await this.r.post(
|
|
266
|
-
`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`,
|
|
267
|
-
opts
|
|
268
|
-
);
|
|
269
|
-
return data.attributes;
|
|
270
|
-
},
|
|
271
|
-
delete: async (task_id) => {
|
|
272
|
-
await this.r.delete(
|
|
273
|
-
`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`
|
|
274
|
-
);
|
|
275
|
-
}
|
|
280
|
+
delete = async (id) => {
|
|
281
|
+
import_zod4.default.number().positive().parse(id);
|
|
282
|
+
await this.r.delete(`/nodes/${id}`);
|
|
276
283
|
};
|
|
284
|
+
allocations = (server_id) => new NodesAllocations(this.r, server_id);
|
|
277
285
|
};
|
|
286
|
+
var NodeCreateSchema = import_zod4.default.object({
|
|
287
|
+
name: import_zod4.default.string().min(1).max(100),
|
|
288
|
+
description: import_zod4.default.string().optional(),
|
|
289
|
+
public: import_zod4.default.boolean().optional(),
|
|
290
|
+
fqdn: import_zod4.default.string().nonempty(),
|
|
291
|
+
scheme: import_zod4.default.enum(["http", "https"]),
|
|
292
|
+
behind_proxy: import_zod4.default.boolean().optional(),
|
|
293
|
+
memory: import_zod4.default.number().min(0),
|
|
294
|
+
memory_overallocate: import_zod4.default.number().min(-1),
|
|
295
|
+
disk: import_zod4.default.number().min(0),
|
|
296
|
+
disk_overallocate: import_zod4.default.number().min(-1),
|
|
297
|
+
cpu: import_zod4.default.number().min(0),
|
|
298
|
+
cpu_overallocate: import_zod4.default.number().min(-1),
|
|
299
|
+
daemon_base: import_zod4.default.string().nonempty().optional(),
|
|
300
|
+
daemon_sftp: import_zod4.default.number().min(1).max(65535),
|
|
301
|
+
daemon_sftp_alias: import_zod4.default.string().optional(),
|
|
302
|
+
daemon_listen: import_zod4.default.number().min(1).max(65535),
|
|
303
|
+
daemon_connect: import_zod4.default.number().min(1).max(65535),
|
|
304
|
+
maintenance_mode: import_zod4.default.boolean().optional(),
|
|
305
|
+
upload_size: import_zod4.default.number().min(1).max(1024),
|
|
306
|
+
tags: import_zod4.default.array(import_zod4.default.string()).optional()
|
|
307
|
+
});
|
|
278
308
|
|
|
279
|
-
// src/api/
|
|
280
|
-
var
|
|
309
|
+
// src/api/application/roles.ts
|
|
310
|
+
var Roles = class {
|
|
281
311
|
r;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.r = requester;
|
|
285
|
-
this.id = id;
|
|
312
|
+
constructor(r) {
|
|
313
|
+
this.r = r;
|
|
286
314
|
}
|
|
287
|
-
list = async () => {
|
|
288
|
-
const { data } = await this.r.get(`/
|
|
315
|
+
list = async (page = 1) => {
|
|
316
|
+
const { data } = await this.r.get(`/roles`, { params: { page } });
|
|
289
317
|
return data.data.map((r) => r.attributes);
|
|
290
318
|
};
|
|
291
|
-
|
|
292
|
-
const { data } = await this.r.
|
|
319
|
+
info = async (id) => {
|
|
320
|
+
const { data } = await this.r.get(
|
|
321
|
+
`/roles/${id}`
|
|
322
|
+
);
|
|
293
323
|
return data.attributes;
|
|
294
324
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return data.attributes;
|
|
325
|
+
create = async (opts) => {
|
|
326
|
+
await this.r.post(`/roles`, opts);
|
|
298
327
|
};
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return data.attributes;
|
|
328
|
+
update = async (id, opts) => {
|
|
329
|
+
await this.r.patch(`/roles/${id}`, opts);
|
|
302
330
|
};
|
|
303
|
-
|
|
304
|
-
await this.r.delete(
|
|
305
|
-
`/servers/${this.id}/network/allocations/${alloc_id}`
|
|
306
|
-
);
|
|
331
|
+
delete = async (id) => {
|
|
332
|
+
await this.r.delete(`/roles/${id}`);
|
|
307
333
|
};
|
|
308
334
|
};
|
|
309
335
|
|
|
310
|
-
// src/api/
|
|
311
|
-
var
|
|
336
|
+
// src/api/application/servers.ts
|
|
337
|
+
var import_zod6 = __toESM(require("zod"));
|
|
338
|
+
|
|
339
|
+
// src/api/application/servers_databases.ts
|
|
340
|
+
var import_zod5 = __toESM(require("zod"));
|
|
341
|
+
var ServersDatabases = class {
|
|
312
342
|
r;
|
|
313
343
|
id;
|
|
314
|
-
constructor(
|
|
315
|
-
this.r =
|
|
316
|
-
this.id =
|
|
344
|
+
constructor(r, server_id) {
|
|
345
|
+
this.r = r;
|
|
346
|
+
this.id = server_id;
|
|
317
347
|
}
|
|
318
348
|
list = async () => {
|
|
319
|
-
const { data } = await this.r.get(`/servers/${this.id}/
|
|
349
|
+
const { data } = await this.r.get(`/servers/${this.id}/databases`);
|
|
320
350
|
return data.data.map((d) => d.attributes);
|
|
321
351
|
};
|
|
322
|
-
create = async (
|
|
323
|
-
|
|
352
|
+
create = async (database, remote, host) => {
|
|
353
|
+
database = import_zod5.default.string().min(1).max(48).parse(database);
|
|
354
|
+
const { data } = await this.r.post(`/servers/${this.id}/databases`, { database, remote, host });
|
|
324
355
|
return data.attributes;
|
|
325
356
|
};
|
|
326
|
-
info = async (
|
|
327
|
-
const { data } = await this.r.get(
|
|
328
|
-
`/servers/${this.id}/users/${user_uuid}`
|
|
329
|
-
);
|
|
357
|
+
info = async (database_id) => {
|
|
358
|
+
const { data } = await this.r.get(`/servers/${this.id}/databases/${database_id}`);
|
|
330
359
|
return data.attributes;
|
|
331
360
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
`/servers/${this.id}/users/${user_uuid}`,
|
|
335
|
-
{ permissions }
|
|
336
|
-
);
|
|
337
|
-
return data.attributes;
|
|
361
|
+
delete = async (database_id) => {
|
|
362
|
+
await this.r.delete(`/servers/${this.id}/databases/${database_id}`);
|
|
338
363
|
};
|
|
339
|
-
|
|
340
|
-
await this.r.
|
|
364
|
+
resetPassword = async (database_id) => {
|
|
365
|
+
await this.r.post(
|
|
366
|
+
`/servers/${this.id}/databases/${database_id}/reset-password`
|
|
367
|
+
);
|
|
341
368
|
};
|
|
342
369
|
};
|
|
343
370
|
|
|
344
|
-
// src/api/
|
|
345
|
-
var
|
|
346
|
-
var import_zod3 = __toESM(require("zod"));
|
|
347
|
-
var ServerBackups = class {
|
|
371
|
+
// src/api/application/servers.ts
|
|
372
|
+
var Servers = class {
|
|
348
373
|
r;
|
|
349
374
|
id;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
this.
|
|
375
|
+
databases;
|
|
376
|
+
constructor(r, server_id) {
|
|
377
|
+
this.r = r;
|
|
378
|
+
this.id = server_id;
|
|
379
|
+
this.databases = new ServersDatabases(this.r, this.id);
|
|
353
380
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
const { data } = await this.r.get(`/servers/${this.id}/backups`, { params: { page } });
|
|
357
|
-
return data.data.map((d) => d.attributes);
|
|
358
|
-
};
|
|
359
|
-
create = async (args) => {
|
|
360
|
-
args.name = import_zod3.default.string().max(255).optional().parse(args.name);
|
|
361
|
-
const { data } = await this.r.post(`/servers/${this.id}/backups`, {
|
|
362
|
-
name: args.name,
|
|
363
|
-
is_locked: args.is_locked,
|
|
364
|
-
ignored_files: args.ignored_files.join("\n")
|
|
365
|
-
});
|
|
381
|
+
info = async (include) => {
|
|
382
|
+
const { data } = await this.r.get(`/servers/${this.id}`, { params: { include: include?.join(",") } });
|
|
366
383
|
return data.attributes;
|
|
367
384
|
};
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
return data.attributes;
|
|
385
|
+
delete = async (force = false) => {
|
|
386
|
+
await this.r.delete(`/servers/${this.id}${force ? "/force" : ""}`);
|
|
371
387
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
388
|
+
updateDetails = async (opts) => {
|
|
389
|
+
opts = UpdateDetailsSchema.parse(opts);
|
|
390
|
+
await this.r.patch(`/servers/${this.id}/details`, opts);
|
|
375
391
|
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
responseType: "arraybuffer"
|
|
380
|
-
});
|
|
381
|
-
return data;
|
|
392
|
+
updateBuild = async (opts) => {
|
|
393
|
+
opts = UpdateBuildSchema.parse(opts);
|
|
394
|
+
await this.r.patch(`/servers/${this.id}/build`, opts);
|
|
382
395
|
};
|
|
383
|
-
|
|
384
|
-
|
|
396
|
+
updateStartup = async (opts) => {
|
|
397
|
+
opts = UpdateStartupSchema.parse(opts);
|
|
398
|
+
await this.r.patch(`/servers/${this.id}/startup`, opts);
|
|
385
399
|
};
|
|
386
|
-
|
|
387
|
-
await this.r.
|
|
388
|
-
name
|
|
389
|
-
});
|
|
400
|
+
suspend = async () => {
|
|
401
|
+
await this.r.post(`/servers/${this.id}/suspend`);
|
|
390
402
|
};
|
|
391
|
-
|
|
392
|
-
await this.r.post(`/servers/${this.id}/
|
|
403
|
+
unsuspend = async () => {
|
|
404
|
+
await this.r.post(`/servers/${this.id}/unsuspend`);
|
|
393
405
|
};
|
|
394
|
-
|
|
395
|
-
await this.r.post(
|
|
396
|
-
`/servers/${this.id}/backups/${backup_uuid}/restore`,
|
|
397
|
-
{ truncate }
|
|
398
|
-
);
|
|
406
|
+
reinstall = async () => {
|
|
407
|
+
await this.r.post(`/servers/${this.id}/reinstall`);
|
|
399
408
|
};
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
constructor(requester, id) {
|
|
407
|
-
this.r = requester;
|
|
408
|
-
this.id = id;
|
|
409
|
-
}
|
|
410
|
-
list = async () => {
|
|
411
|
-
const { data } = await this.r.get(`/servers/${this.id}/startup`);
|
|
412
|
-
return {
|
|
413
|
-
object: "list",
|
|
414
|
-
meta: data.meta,
|
|
415
|
-
data: data.data.map((d) => d.attributes)
|
|
416
|
-
};
|
|
409
|
+
transferStart = async (node_id, allocation_id, allocation_additional) => {
|
|
410
|
+
await this.r.post(`/servers/${this.id}/transfer`, {
|
|
411
|
+
node_id,
|
|
412
|
+
allocation_id,
|
|
413
|
+
allocation_additional
|
|
414
|
+
});
|
|
417
415
|
};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
return data.attributes;
|
|
421
|
-
};
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
// src/api/client/server_settings.ts
|
|
425
|
-
var import_zod4 = __toESM(require("zod"));
|
|
426
|
-
var ServerSettings = class {
|
|
427
|
-
r;
|
|
428
|
-
id;
|
|
429
|
-
constructor(requester, id) {
|
|
430
|
-
this.r = requester;
|
|
431
|
-
this.id = id;
|
|
432
|
-
}
|
|
433
|
-
rename = async (name) => {
|
|
434
|
-
name = import_zod4.default.string().max(255).parse(name);
|
|
435
|
-
await this.r.post(`/servers/${this.id}/settings/rename`, { name });
|
|
436
|
-
};
|
|
437
|
-
updateDescription = async (description) => {
|
|
438
|
-
await this.r.post(`/servers/${this.id}/settings/description`, {
|
|
439
|
-
description
|
|
440
|
-
});
|
|
441
|
-
};
|
|
442
|
-
reinstall = async () => {
|
|
443
|
-
await this.r.post(`/servers/${this.id}/settings/reinstall`);
|
|
444
|
-
};
|
|
445
|
-
changeDockerImage = async (image) => {
|
|
446
|
-
await this.r.put(`/servers/${this.id}/settings/docker-image`, {
|
|
447
|
-
docker_image: image
|
|
448
|
-
});
|
|
416
|
+
transferCancel = async () => {
|
|
417
|
+
await this.r.post(`/servers/${this.id}/transfer/cancel`);
|
|
449
418
|
};
|
|
450
419
|
};
|
|
420
|
+
var CreateServerSchema = import_zod6.default.object({
|
|
421
|
+
external_id: import_zod6.default.string().min(1).max(255).optional(),
|
|
422
|
+
name: import_zod6.default.string().min(1).max(255),
|
|
423
|
+
description: import_zod6.default.string().optional(),
|
|
424
|
+
user: import_zod6.default.number(),
|
|
425
|
+
egg: import_zod6.default.number(),
|
|
426
|
+
docker_image: import_zod6.default.string().optional(),
|
|
427
|
+
startup: import_zod6.default.string().optional(),
|
|
428
|
+
environment: import_zod6.default.record(import_zod6.default.string(), import_zod6.default.string()),
|
|
429
|
+
skip_scripts: import_zod6.default.boolean().optional(),
|
|
430
|
+
oom_killer: import_zod6.default.boolean().optional(),
|
|
431
|
+
start_on_completion: import_zod6.default.boolean().optional(),
|
|
432
|
+
docker_labels: import_zod6.default.record(import_zod6.default.string(), import_zod6.default.string()).optional(),
|
|
433
|
+
limits: import_zod6.default.object({
|
|
434
|
+
memory: import_zod6.default.number().min(0),
|
|
435
|
+
swap: import_zod6.default.number().min(-1),
|
|
436
|
+
disk: import_zod6.default.number().min(0),
|
|
437
|
+
io: import_zod6.default.number().min(0),
|
|
438
|
+
threads: import_zod6.default.string().optional(),
|
|
439
|
+
cpu: import_zod6.default.number().min(0)
|
|
440
|
+
}),
|
|
441
|
+
feature_limits: import_zod6.default.object({
|
|
442
|
+
databases: import_zod6.default.number().min(0),
|
|
443
|
+
allocations: import_zod6.default.number().min(0),
|
|
444
|
+
backups: import_zod6.default.number().min(0)
|
|
445
|
+
}),
|
|
446
|
+
allocation: import_zod6.default.object({
|
|
447
|
+
default: import_zod6.default.string().nullable(),
|
|
448
|
+
additional: import_zod6.default.array(import_zod6.default.string()).optional()
|
|
449
|
+
}).optional(),
|
|
450
|
+
deploy: import_zod6.default.object({
|
|
451
|
+
tags: import_zod6.default.array(import_zod6.default.string()).optional(),
|
|
452
|
+
dedicated_ip: import_zod6.default.boolean().optional(),
|
|
453
|
+
port_range: import_zod6.default.array(import_zod6.default.string()).optional()
|
|
454
|
+
}).optional()
|
|
455
|
+
});
|
|
456
|
+
var UpdateDetailsSchema = CreateServerSchema.pick({
|
|
457
|
+
external_id: true,
|
|
458
|
+
name: true,
|
|
459
|
+
user: true,
|
|
460
|
+
description: true,
|
|
461
|
+
docker_labels: true
|
|
462
|
+
});
|
|
463
|
+
var UpdateBuildSchema = CreateServerSchema.pick({
|
|
464
|
+
oom_killer: true,
|
|
465
|
+
limits: true,
|
|
466
|
+
feature_limits: true
|
|
467
|
+
}).extend({
|
|
468
|
+
allocation: import_zod6.default.number().optional(),
|
|
469
|
+
add_allocations: import_zod6.default.array(import_zod6.default.string()).optional(),
|
|
470
|
+
remove_allocations: import_zod6.default.array(import_zod6.default.string()).optional()
|
|
471
|
+
});
|
|
472
|
+
var UpdateStartupSchema = CreateServerSchema.pick({
|
|
473
|
+
startup: true,
|
|
474
|
+
environment: true,
|
|
475
|
+
egg: true
|
|
476
|
+
}).extend({ image: import_zod6.default.string().optional(), skip_scripts: import_zod6.default.boolean() });
|
|
451
477
|
|
|
452
|
-
// src/api/
|
|
453
|
-
var
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
var
|
|
457
|
-
var
|
|
458
|
-
"
|
|
459
|
-
"
|
|
478
|
+
// src/api/application/users.ts
|
|
479
|
+
var import_zod8 = __toESM(require("zod"));
|
|
480
|
+
|
|
481
|
+
// src/api/common/types/enums.ts
|
|
482
|
+
var import_zod7 = __toESM(require("zod"));
|
|
483
|
+
var languagesSchema = import_zod7.default.enum([
|
|
484
|
+
"af",
|
|
485
|
+
"ak",
|
|
486
|
+
"am",
|
|
487
|
+
"ar",
|
|
488
|
+
"as",
|
|
489
|
+
"az",
|
|
490
|
+
"be",
|
|
491
|
+
"bg",
|
|
492
|
+
"bm",
|
|
493
|
+
"bn",
|
|
494
|
+
"bo",
|
|
495
|
+
"br",
|
|
496
|
+
"bs",
|
|
497
|
+
"ca",
|
|
498
|
+
"ce",
|
|
499
|
+
"cs",
|
|
500
|
+
"cv",
|
|
501
|
+
"cy",
|
|
502
|
+
"da",
|
|
503
|
+
"de",
|
|
504
|
+
"dz",
|
|
505
|
+
"ee",
|
|
506
|
+
"el",
|
|
507
|
+
"en",
|
|
508
|
+
"eo",
|
|
509
|
+
"es",
|
|
510
|
+
"et",
|
|
511
|
+
"eu",
|
|
512
|
+
"fa",
|
|
513
|
+
"ff",
|
|
514
|
+
"fi",
|
|
515
|
+
"fo",
|
|
516
|
+
"fr",
|
|
517
|
+
"fy",
|
|
518
|
+
"ga",
|
|
519
|
+
"gd",
|
|
520
|
+
"gl",
|
|
521
|
+
"gu",
|
|
522
|
+
"gv",
|
|
523
|
+
"ha",
|
|
524
|
+
"he",
|
|
525
|
+
"hi",
|
|
526
|
+
"hr",
|
|
527
|
+
"hu",
|
|
528
|
+
"hy",
|
|
529
|
+
"ia",
|
|
530
|
+
"id",
|
|
531
|
+
"ig",
|
|
532
|
+
"ii",
|
|
533
|
+
"is",
|
|
534
|
+
"it",
|
|
535
|
+
"ja",
|
|
536
|
+
"jv",
|
|
537
|
+
"ka",
|
|
538
|
+
"ki",
|
|
539
|
+
"kk",
|
|
540
|
+
"kl",
|
|
541
|
+
"km",
|
|
542
|
+
"kn",
|
|
543
|
+
"ko",
|
|
544
|
+
"ks",
|
|
545
|
+
"ku",
|
|
546
|
+
"kw",
|
|
547
|
+
"ky",
|
|
548
|
+
"lb",
|
|
549
|
+
"lg",
|
|
550
|
+
"ln",
|
|
551
|
+
"lo",
|
|
552
|
+
"lt",
|
|
553
|
+
"lu",
|
|
554
|
+
"lv",
|
|
555
|
+
"mg",
|
|
556
|
+
"mi",
|
|
557
|
+
"mk",
|
|
558
|
+
"ml",
|
|
559
|
+
"mn",
|
|
560
|
+
"mr",
|
|
561
|
+
"ms",
|
|
562
|
+
"mt",
|
|
563
|
+
"my",
|
|
564
|
+
"nb",
|
|
565
|
+
"nd",
|
|
566
|
+
"ne",
|
|
567
|
+
"nl",
|
|
568
|
+
"nn",
|
|
569
|
+
"no",
|
|
570
|
+
"om",
|
|
571
|
+
"or",
|
|
572
|
+
"os",
|
|
573
|
+
"pa",
|
|
574
|
+
"pl",
|
|
575
|
+
"ps",
|
|
576
|
+
"pt",
|
|
577
|
+
"qu",
|
|
578
|
+
"rm",
|
|
579
|
+
"rn",
|
|
580
|
+
"ro",
|
|
581
|
+
"ru",
|
|
582
|
+
"rw",
|
|
583
|
+
"sa",
|
|
584
|
+
"sc",
|
|
585
|
+
"sd",
|
|
586
|
+
"se",
|
|
587
|
+
"sg",
|
|
588
|
+
"si",
|
|
589
|
+
"sk",
|
|
590
|
+
"sl",
|
|
591
|
+
"sn",
|
|
592
|
+
"so",
|
|
593
|
+
"sq",
|
|
594
|
+
"sr",
|
|
595
|
+
"su",
|
|
596
|
+
"sv",
|
|
597
|
+
"sw",
|
|
598
|
+
"ta",
|
|
599
|
+
"te",
|
|
600
|
+
"tg",
|
|
601
|
+
"th",
|
|
602
|
+
"ti",
|
|
603
|
+
"tk",
|
|
604
|
+
"to",
|
|
605
|
+
"tr",
|
|
606
|
+
"tt",
|
|
607
|
+
"ug",
|
|
608
|
+
"uk",
|
|
609
|
+
"ur",
|
|
610
|
+
"uz",
|
|
611
|
+
"vi",
|
|
612
|
+
"wo",
|
|
613
|
+
"xh",
|
|
614
|
+
"yi",
|
|
615
|
+
"yo",
|
|
616
|
+
"zh",
|
|
617
|
+
"zu"
|
|
460
618
|
]);
|
|
461
|
-
var
|
|
462
|
-
var ServerWebsocket = class {
|
|
463
|
-
r;
|
|
464
|
-
serverId;
|
|
465
|
-
socket;
|
|
466
|
-
currentToken;
|
|
467
|
-
bus = new import_events.EventEmitter();
|
|
468
|
-
debugLogging = false;
|
|
469
|
-
stripColors;
|
|
470
|
-
detachMessageListener;
|
|
471
|
-
constructor(requester, id, stripColors = false) {
|
|
472
|
-
this.r = requester;
|
|
473
|
-
this.serverId = id;
|
|
474
|
-
this.stripColors = stripColors;
|
|
475
|
-
}
|
|
476
|
-
on(event, listener) {
|
|
477
|
-
const handler = listener;
|
|
478
|
-
this.bus.on(event, handler);
|
|
479
|
-
return () => {
|
|
480
|
-
this.bus.removeListener(event, handler);
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
deregister(event, listener) {
|
|
484
|
-
const handler = listener;
|
|
485
|
-
this.bus.removeListener(event, handler);
|
|
486
|
-
}
|
|
487
|
-
emit(event, ...args) {
|
|
488
|
-
if (args.length === 0) {
|
|
489
|
-
this.bus.emit(event);
|
|
490
|
-
} else {
|
|
491
|
-
this.bus.emit(event, args[0]);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
async connect(resumable, debugLogging) {
|
|
495
|
-
this.debugLogging = debugLogging ?? false;
|
|
496
|
-
if (this.socket) {
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
const socketUrl = await this.refreshCredentials();
|
|
500
|
-
this.socket = isBrowser ? new import_isomorphic_ws.default(socketUrl) : new import_isomorphic_ws.default(socketUrl, void 0, {
|
|
501
|
-
origin: new URL(socketUrl).origin
|
|
502
|
-
});
|
|
503
|
-
await new Promise((resolve, reject) => {
|
|
504
|
-
const socket = this.socket;
|
|
505
|
-
if (!socket) {
|
|
506
|
-
reject(new Error("Failed to create socket connection"));
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
socket.onopen = async () => {
|
|
510
|
-
try {
|
|
511
|
-
await this.authenticate();
|
|
512
|
-
this.attachMessageListener();
|
|
513
|
-
socket.onopen = null;
|
|
514
|
-
socket.onerror = null;
|
|
515
|
-
resolve();
|
|
516
|
-
} catch (error) {
|
|
517
|
-
socket.onopen = null;
|
|
518
|
-
socket.onerror = null;
|
|
519
|
-
reject(
|
|
520
|
-
error instanceof Error ? error : new Error("Websocket authentication failed")
|
|
521
|
-
);
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
socket.onerror = (event) => {
|
|
525
|
-
socket.onopen = null;
|
|
526
|
-
socket.onerror = null;
|
|
527
|
-
reject(
|
|
528
|
-
event instanceof Error ? event : new Error("Websocket connection error")
|
|
529
|
-
);
|
|
530
|
-
};
|
|
531
|
-
});
|
|
532
|
-
if (resumable) {
|
|
533
|
-
this.makeResumable(true);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
onSocketDisconnect(handler) {
|
|
537
|
-
if (!this.socket) {
|
|
538
|
-
console.error(new Error("No socket connection"));
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
this.socket.onclose = handler;
|
|
542
|
-
}
|
|
543
|
-
onSocketError(handler) {
|
|
544
|
-
if (!this.socket) {
|
|
545
|
-
console.error(new Error("No socket connection"));
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
this.socket.onerror = handler;
|
|
549
|
-
}
|
|
550
|
-
makeResumable(disconnectsToo) {
|
|
551
|
-
const scheduleReconnect = () => {
|
|
552
|
-
setTimeout(() => {
|
|
553
|
-
const previous = this.socket;
|
|
554
|
-
this.detachMessageListener?.();
|
|
555
|
-
this.detachMessageListener = void 0;
|
|
556
|
-
this.socket = void 0;
|
|
557
|
-
previous?.close();
|
|
558
|
-
void this.connect(true, this.debugLogging);
|
|
559
|
-
}, 1e3);
|
|
560
|
-
};
|
|
561
|
-
this.onSocketError(() => scheduleReconnect());
|
|
562
|
-
if (disconnectsToo) {
|
|
563
|
-
this.onSocketDisconnect(() => scheduleReconnect());
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
attachMessageListener() {
|
|
567
|
-
if (!this.socket) {
|
|
568
|
-
throw new Error("No socket connection");
|
|
569
|
-
}
|
|
570
|
-
this.detachMessageListener?.();
|
|
571
|
-
const handler = (event) => {
|
|
572
|
-
void this.handleIncomingMessage(event);
|
|
573
|
-
};
|
|
574
|
-
if (typeof this.socket.addEventListener === "function") {
|
|
575
|
-
this.socket.addEventListener(
|
|
576
|
-
"message",
|
|
577
|
-
handler
|
|
578
|
-
);
|
|
579
|
-
this.detachMessageListener = () => {
|
|
580
|
-
this.socket?.removeEventListener?.(
|
|
581
|
-
"message",
|
|
582
|
-
handler
|
|
583
|
-
);
|
|
584
|
-
};
|
|
585
|
-
} else {
|
|
586
|
-
const fallback = (data) => handler({ data });
|
|
587
|
-
const socket = this.socket;
|
|
588
|
-
socket.on?.("message", fallback);
|
|
589
|
-
this.detachMessageListener = () => {
|
|
590
|
-
const target = this.socket;
|
|
591
|
-
if (!target) {
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
if (typeof target.off === "function") {
|
|
595
|
-
target.off("message", fallback);
|
|
596
|
-
} else if (typeof target.removeListener === "function") {
|
|
597
|
-
target.removeListener("message", fallback);
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
async handleIncomingMessage(event) {
|
|
603
|
-
const message = this.parseMessage(event);
|
|
604
|
-
if (!message) {
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
try {
|
|
608
|
-
await this.dispatchMessage(message);
|
|
609
|
-
} catch (error) {
|
|
610
|
-
if (this.debugLogging) {
|
|
611
|
-
console.error("Error while handling websocket message", error);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
parseMessage(event) {
|
|
616
|
-
const payload = this.normalisePayload(event);
|
|
617
|
-
if (!payload) {
|
|
618
|
-
return null;
|
|
619
|
-
}
|
|
620
|
-
try {
|
|
621
|
-
return JSON.parse(payload);
|
|
622
|
-
} catch (error) {
|
|
623
|
-
if (this.debugLogging) {
|
|
624
|
-
console.warn("Failed to parse websocket payload", error);
|
|
625
|
-
}
|
|
626
|
-
return null;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
normalisePayload(event) {
|
|
630
|
-
if (typeof event === "string") {
|
|
631
|
-
return event;
|
|
632
|
-
}
|
|
633
|
-
if (typeof event === "object" && event !== null && "data" in event) {
|
|
634
|
-
return this.normalisePayload(event.data);
|
|
635
|
-
}
|
|
636
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer(event)) {
|
|
637
|
-
return event.toString("utf8");
|
|
638
|
-
}
|
|
639
|
-
if (typeof ArrayBuffer !== "undefined" && event instanceof ArrayBuffer) {
|
|
640
|
-
if (typeof TextDecoder !== "undefined") {
|
|
641
|
-
return new TextDecoder().decode(new Uint8Array(event));
|
|
642
|
-
}
|
|
643
|
-
if (typeof Buffer !== "undefined") {
|
|
644
|
-
return Buffer.from(event).toString("utf8");
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
return null;
|
|
648
|
-
}
|
|
649
|
-
async dispatchMessage(message) {
|
|
650
|
-
switch (message.event) {
|
|
651
|
-
case "auth success" /* AUTH_SUCCESS */: {
|
|
652
|
-
if (this.debugLogging) {
|
|
653
|
-
console.debug("Auth success");
|
|
654
|
-
}
|
|
655
|
-
this.emit("auth success" /* AUTH_SUCCESS */);
|
|
656
|
-
break;
|
|
657
|
-
}
|
|
658
|
-
case "status" /* STATUS */: {
|
|
659
|
-
if (this.debugLogging) {
|
|
660
|
-
console.debug("Received status event", message.args[0]);
|
|
661
|
-
}
|
|
662
|
-
this.emit("status" /* STATUS */, message.args[0]);
|
|
663
|
-
break;
|
|
664
|
-
}
|
|
665
|
-
case "console output" /* CONSOLE_OUTPUT */: {
|
|
666
|
-
let output = message.args[0];
|
|
667
|
-
if (this.stripColors) {
|
|
668
|
-
output = (0, import_strip_color.default)(output);
|
|
669
|
-
}
|
|
670
|
-
if (this.debugLogging) {
|
|
671
|
-
console.debug("Received console output", output);
|
|
672
|
-
}
|
|
673
|
-
this.emit("console output" /* CONSOLE_OUTPUT */, output);
|
|
674
|
-
break;
|
|
675
|
-
}
|
|
676
|
-
case "stats" /* STATS */: {
|
|
677
|
-
try {
|
|
678
|
-
const payload = JSON.parse(message.args[0]);
|
|
679
|
-
this.emit("stats" /* STATS */, payload);
|
|
680
|
-
} catch (error) {
|
|
681
|
-
if (this.debugLogging) {
|
|
682
|
-
console.warn("Failed to parse stats payload", error);
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
break;
|
|
686
|
-
}
|
|
687
|
-
case "daemon error" /* DAEMON_ERROR */: {
|
|
688
|
-
this.emit("daemon error" /* DAEMON_ERROR */);
|
|
689
|
-
break;
|
|
690
|
-
}
|
|
691
|
-
case "backup completed" /* BACKUP_COMPLETED */: {
|
|
692
|
-
try {
|
|
693
|
-
const payload = JSON.parse(
|
|
694
|
-
message.args[0]
|
|
695
|
-
);
|
|
696
|
-
this.emit("backup completed" /* BACKUP_COMPLETED */, payload);
|
|
697
|
-
} catch (error) {
|
|
698
|
-
if (this.debugLogging) {
|
|
699
|
-
console.warn("Failed to parse backup payload", error);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
break;
|
|
703
|
-
}
|
|
704
|
-
case "daemon message" /* DAEMON_MESSAGE */: {
|
|
705
|
-
let output = message.args[0];
|
|
706
|
-
if (this.stripColors) {
|
|
707
|
-
output = (0, import_strip_color.default)(output);
|
|
708
|
-
}
|
|
709
|
-
this.emit("daemon message" /* DAEMON_MESSAGE */, output);
|
|
710
|
-
break;
|
|
711
|
-
}
|
|
712
|
-
case "install output" /* INSTALL_OUTPUT */: {
|
|
713
|
-
let output = message.args[0];
|
|
714
|
-
if (this.stripColors) {
|
|
715
|
-
output = (0, import_strip_color.default)(output);
|
|
716
|
-
}
|
|
717
|
-
this.emit("install output" /* INSTALL_OUTPUT */, output);
|
|
718
|
-
break;
|
|
719
|
-
}
|
|
720
|
-
case "backup restore completed" /* BACKUP_RESTORE_COMPLETED */: {
|
|
721
|
-
this.emit("backup restore completed" /* BACKUP_RESTORE_COMPLETED */);
|
|
722
|
-
break;
|
|
723
|
-
}
|
|
724
|
-
case "install completed" /* INSTALL_COMPLETED */: {
|
|
725
|
-
this.emit("install completed" /* INSTALL_COMPLETED */);
|
|
726
|
-
break;
|
|
727
|
-
}
|
|
728
|
-
case "install started" /* INSTALL_STARTED */: {
|
|
729
|
-
this.emit("install started" /* INSTALL_STARTED */);
|
|
730
|
-
break;
|
|
731
|
-
}
|
|
732
|
-
case "transfer logs" /* TRANSFER_LOGS */: {
|
|
733
|
-
this.emit("transfer logs" /* TRANSFER_LOGS */, message.args[0]);
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
case "transfer status" /* TRANSFER_STATUS */: {
|
|
737
|
-
this.emit("transfer status" /* TRANSFER_STATUS */, message.args[0]);
|
|
738
|
-
break;
|
|
739
|
-
}
|
|
740
|
-
case "token expiring" /* TOKEN_EXPIRING */: {
|
|
741
|
-
this.emit("token expiring" /* TOKEN_EXPIRING */);
|
|
742
|
-
if (this.debugLogging) {
|
|
743
|
-
console.warn("Token expiring, renewing...");
|
|
744
|
-
}
|
|
745
|
-
await this.refreshCredentials();
|
|
746
|
-
await this.authenticate();
|
|
747
|
-
break;
|
|
748
|
-
}
|
|
749
|
-
case "token expired" /* TOKEN_EXPIRED */: {
|
|
750
|
-
this.emit("token expired" /* TOKEN_EXPIRED */);
|
|
751
|
-
throw new Error("Token expired");
|
|
752
|
-
}
|
|
753
|
-
case "jwt error" /* JWT_ERROR */: {
|
|
754
|
-
const reason = message.args[0];
|
|
755
|
-
if (RECONNECT_ERRORS.has(reason)) {
|
|
756
|
-
this.emit("token expiring" /* TOKEN_EXPIRING */);
|
|
757
|
-
if (this.debugLogging) {
|
|
758
|
-
console.warn("Token expiring (JWT error), renewing...");
|
|
759
|
-
}
|
|
760
|
-
await this.refreshCredentials();
|
|
761
|
-
await this.authenticate();
|
|
762
|
-
} else {
|
|
763
|
-
this.emit("jwt error" /* JWT_ERROR */, reason);
|
|
764
|
-
throw new Error("Token expired");
|
|
765
|
-
}
|
|
766
|
-
break;
|
|
767
|
-
}
|
|
768
|
-
default: {
|
|
769
|
-
if (this.debugLogging) {
|
|
770
|
-
console.warn("Unknown websocket event", message);
|
|
771
|
-
}
|
|
772
|
-
break;
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
async refreshCredentials() {
|
|
777
|
-
const { data } = await this.r.get(
|
|
778
|
-
`/servers/${this.serverId}/websocket`
|
|
779
|
-
);
|
|
780
|
-
this.currentToken = data.data.token;
|
|
781
|
-
return data.data.socket;
|
|
782
|
-
}
|
|
783
|
-
async authenticate() {
|
|
784
|
-
if (!this.socket) {
|
|
785
|
-
throw new Error("No socket connection");
|
|
786
|
-
}
|
|
787
|
-
if (!this.currentToken) {
|
|
788
|
-
throw new Error("Missing websocket token");
|
|
789
|
-
}
|
|
790
|
-
this.socket.send(
|
|
791
|
-
JSON.stringify({ event: "auth", args: [this.currentToken] })
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
disconnect() {
|
|
795
|
-
this.detachMessageListener?.();
|
|
796
|
-
this.detachMessageListener = void 0;
|
|
797
|
-
if (this.socket) {
|
|
798
|
-
this.socket.close();
|
|
799
|
-
this.socket = void 0;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
requestStats() {
|
|
803
|
-
this.send("send stats", [null]);
|
|
804
|
-
}
|
|
805
|
-
requestLogs() {
|
|
806
|
-
this.send("send logs", [null]);
|
|
807
|
-
}
|
|
808
|
-
send(event, args) {
|
|
809
|
-
if (!this.socket) {
|
|
810
|
-
if (this.debugLogging) {
|
|
811
|
-
console.warn(
|
|
812
|
-
`Attempted to send "${event}" without an active websocket connection`
|
|
813
|
-
);
|
|
814
|
-
}
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
this.socket.send(JSON.stringify({ event, args }));
|
|
818
|
-
}
|
|
819
|
-
getStats() {
|
|
820
|
-
return new Promise((resolve, reject) => {
|
|
821
|
-
if (!this.socket) {
|
|
822
|
-
reject(new Error("No socket connection"));
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
let off;
|
|
826
|
-
const timeout = setTimeout(() => {
|
|
827
|
-
off?.();
|
|
828
|
-
reject(new Error("Timed out waiting for stats"));
|
|
829
|
-
}, 5e3);
|
|
830
|
-
off = this.on("stats" /* STATS */, (payload) => {
|
|
831
|
-
clearTimeout(timeout);
|
|
832
|
-
off?.();
|
|
833
|
-
resolve(payload);
|
|
834
|
-
});
|
|
835
|
-
this.requestStats();
|
|
836
|
-
});
|
|
837
|
-
}
|
|
838
|
-
getLogs() {
|
|
839
|
-
return new Promise((resolve, reject) => {
|
|
840
|
-
if (!this.socket) {
|
|
841
|
-
reject(new Error("No socket connection"));
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
const lines = [];
|
|
845
|
-
let off;
|
|
846
|
-
let initialTimeout;
|
|
847
|
-
let idleTimeout;
|
|
848
|
-
const finalize = (payload) => {
|
|
849
|
-
off?.();
|
|
850
|
-
if (initialTimeout) {
|
|
851
|
-
clearTimeout(initialTimeout);
|
|
852
|
-
}
|
|
853
|
-
if (idleTimeout) {
|
|
854
|
-
clearTimeout(idleTimeout);
|
|
855
|
-
}
|
|
856
|
-
resolve(payload);
|
|
857
|
-
};
|
|
858
|
-
initialTimeout = setTimeout(() => {
|
|
859
|
-
finalize(lines.length > 0 ? lines : [FALLBACK_LOG_MESSAGE]);
|
|
860
|
-
}, 5e3);
|
|
861
|
-
off = this.on("console output" /* CONSOLE_OUTPUT */, (line) => {
|
|
862
|
-
lines.push(line);
|
|
863
|
-
if (initialTimeout) {
|
|
864
|
-
clearTimeout(initialTimeout);
|
|
865
|
-
initialTimeout = void 0;
|
|
866
|
-
}
|
|
867
|
-
if (idleTimeout) {
|
|
868
|
-
clearTimeout(idleTimeout);
|
|
869
|
-
}
|
|
870
|
-
idleTimeout = setTimeout(() => {
|
|
871
|
-
finalize(lines);
|
|
872
|
-
}, 1e3);
|
|
873
|
-
});
|
|
874
|
-
this.requestLogs();
|
|
875
|
-
});
|
|
876
|
-
}
|
|
877
|
-
sendPoweraction(action) {
|
|
878
|
-
this.send("set state", [action]);
|
|
879
|
-
}
|
|
880
|
-
sendCommand(cmd) {
|
|
881
|
-
this.send("send command", [cmd]);
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
|
|
885
|
-
// src/api/client/server_activity.ts
|
|
886
|
-
var ServerActivity = class {
|
|
887
|
-
r;
|
|
888
|
-
id;
|
|
889
|
-
constructor(r, id) {
|
|
890
|
-
this.r = r;
|
|
891
|
-
this.id = id;
|
|
892
|
-
}
|
|
893
|
-
list = async (page = 1, per_page = 25) => {
|
|
894
|
-
const { data } = await this.r.get(`/server/${this.id}/activity`, { params: { page, per_page } });
|
|
895
|
-
return data.data.map((log) => log.attributes);
|
|
896
|
-
};
|
|
897
|
-
};
|
|
898
|
-
|
|
899
|
-
// src/api/client/server.ts
|
|
900
|
-
var ServerClient = class {
|
|
901
|
-
r;
|
|
902
|
-
id;
|
|
903
|
-
activity;
|
|
904
|
-
databases;
|
|
905
|
-
files;
|
|
906
|
-
schedules;
|
|
907
|
-
allocations;
|
|
908
|
-
users;
|
|
909
|
-
backups;
|
|
910
|
-
startup;
|
|
911
|
-
variables;
|
|
912
|
-
settings;
|
|
913
|
-
constructor(requester, id) {
|
|
914
|
-
this.r = requester;
|
|
915
|
-
this.id = id;
|
|
916
|
-
this.activity = new ServerActivity(requester, id);
|
|
917
|
-
this.databases = new ServerDatabases(requester, id);
|
|
918
|
-
this.files = new ServerFiles(requester, id);
|
|
919
|
-
this.schedules = new ServerSchedules(requester, id);
|
|
920
|
-
this.allocations = new ServerAllocations(requester, id);
|
|
921
|
-
this.users = new ServerUsers(requester, id);
|
|
922
|
-
this.backups = new ServerBackups(requester, id);
|
|
923
|
-
this.startup = new ServerStartup(requester, id);
|
|
924
|
-
this.variables = this.startup;
|
|
925
|
-
this.settings = new ServerSettings(requester, id);
|
|
926
|
-
}
|
|
927
|
-
info = async (include) => {
|
|
928
|
-
const { data } = await this.r.get(
|
|
929
|
-
`/servers/${this.id}`,
|
|
930
|
-
{ params: { include: include?.join(",") } }
|
|
931
|
-
);
|
|
932
|
-
return data.attributes;
|
|
933
|
-
};
|
|
934
|
-
websocket = (stripColors = false) => {
|
|
935
|
-
return new ServerWebsocket(this.r, this.id, stripColors);
|
|
936
|
-
};
|
|
937
|
-
resources = async () => {
|
|
938
|
-
const { data } = await this.r.get(
|
|
939
|
-
`/servers/${this.id}/resources`
|
|
940
|
-
);
|
|
941
|
-
return data.attributes;
|
|
942
|
-
};
|
|
943
|
-
command = async (command) => {
|
|
944
|
-
await this.r.post(`/servers/${this.id}/command`, { command });
|
|
945
|
-
};
|
|
946
|
-
power = async (signal) => {
|
|
947
|
-
await this.r.post(`/servers/${this.id}/power`, { signal });
|
|
948
|
-
};
|
|
949
|
-
};
|
|
950
|
-
|
|
951
|
-
// src/api/client/client.ts
|
|
952
|
-
var Client = class {
|
|
953
|
-
account;
|
|
954
|
-
r;
|
|
955
|
-
constructor(requester) {
|
|
956
|
-
this.r = requester;
|
|
957
|
-
this.account = new Account(requester);
|
|
958
|
-
}
|
|
959
|
-
get $r() {
|
|
960
|
-
return this.r;
|
|
961
|
-
}
|
|
962
|
-
listPermissions = async () => {
|
|
963
|
-
const { data } = await this.r.get("/permissions");
|
|
964
|
-
return data.attributes.permissions;
|
|
965
|
-
};
|
|
966
|
-
listServers = async (type = "accessible", page = 1, per_page = 50, include) => {
|
|
967
|
-
import_zod5.default.number().positive().parse(page);
|
|
968
|
-
const { data } = await this.r.get("/", { params: { type, page, include: include?.join(",") } });
|
|
969
|
-
return data.data.map((s) => s.attributes);
|
|
970
|
-
};
|
|
971
|
-
server = (uuid) => new ServerClient(this.r, uuid);
|
|
972
|
-
};
|
|
973
|
-
|
|
974
|
-
// src/api/application/users.ts
|
|
975
|
-
var import_zod7 = __toESM(require("zod"));
|
|
976
|
-
|
|
977
|
-
// src/utils/transform.ts
|
|
978
|
-
var ArrayQueryParams = (p) => {
|
|
979
|
-
const params = new URLSearchParams();
|
|
980
|
-
const o = {};
|
|
981
|
-
for (const [param, value] of Object.entries(p)) {
|
|
982
|
-
for (const [key, val] of Object.entries(value)) {
|
|
983
|
-
o[`${param}[${key}]`] = val;
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
return o;
|
|
987
|
-
};
|
|
988
|
-
var SortParam = (key, p) => {
|
|
989
|
-
return `${p === "desc" ? "-" : ""}${key}`;
|
|
990
|
-
};
|
|
991
|
-
|
|
992
|
-
// src/api/common/types/enums.ts
|
|
993
|
-
var import_zod6 = __toESM(require("zod"));
|
|
994
|
-
var languagesSchema = import_zod6.default.enum([
|
|
995
|
-
"af",
|
|
996
|
-
"ak",
|
|
997
|
-
"am",
|
|
998
|
-
"ar",
|
|
999
|
-
"as",
|
|
1000
|
-
"az",
|
|
1001
|
-
"be",
|
|
1002
|
-
"bg",
|
|
1003
|
-
"bm",
|
|
1004
|
-
"bn",
|
|
1005
|
-
"bo",
|
|
1006
|
-
"br",
|
|
1007
|
-
"bs",
|
|
1008
|
-
"ca",
|
|
1009
|
-
"ce",
|
|
1010
|
-
"cs",
|
|
1011
|
-
"cv",
|
|
1012
|
-
"cy",
|
|
1013
|
-
"da",
|
|
1014
|
-
"de",
|
|
1015
|
-
"dz",
|
|
1016
|
-
"ee",
|
|
1017
|
-
"el",
|
|
1018
|
-
"en",
|
|
1019
|
-
"eo",
|
|
1020
|
-
"es",
|
|
1021
|
-
"et",
|
|
1022
|
-
"eu",
|
|
1023
|
-
"fa",
|
|
1024
|
-
"ff",
|
|
1025
|
-
"fi",
|
|
1026
|
-
"fo",
|
|
1027
|
-
"fr",
|
|
1028
|
-
"fy",
|
|
1029
|
-
"ga",
|
|
1030
|
-
"gd",
|
|
1031
|
-
"gl",
|
|
1032
|
-
"gu",
|
|
1033
|
-
"gv",
|
|
1034
|
-
"ha",
|
|
1035
|
-
"he",
|
|
1036
|
-
"hi",
|
|
1037
|
-
"hr",
|
|
1038
|
-
"hu",
|
|
1039
|
-
"hy",
|
|
1040
|
-
"ia",
|
|
1041
|
-
"id",
|
|
1042
|
-
"ig",
|
|
1043
|
-
"ii",
|
|
1044
|
-
"is",
|
|
1045
|
-
"it",
|
|
1046
|
-
"ja",
|
|
1047
|
-
"jv",
|
|
1048
|
-
"ka",
|
|
1049
|
-
"ki",
|
|
1050
|
-
"kk",
|
|
1051
|
-
"kl",
|
|
1052
|
-
"km",
|
|
1053
|
-
"kn",
|
|
1054
|
-
"ko",
|
|
1055
|
-
"ks",
|
|
1056
|
-
"ku",
|
|
1057
|
-
"kw",
|
|
1058
|
-
"ky",
|
|
1059
|
-
"lb",
|
|
1060
|
-
"lg",
|
|
1061
|
-
"ln",
|
|
1062
|
-
"lo",
|
|
1063
|
-
"lt",
|
|
1064
|
-
"lu",
|
|
1065
|
-
"lv",
|
|
1066
|
-
"mg",
|
|
1067
|
-
"mi",
|
|
1068
|
-
"mk",
|
|
1069
|
-
"ml",
|
|
1070
|
-
"mn",
|
|
1071
|
-
"mr",
|
|
1072
|
-
"ms",
|
|
1073
|
-
"mt",
|
|
1074
|
-
"my",
|
|
1075
|
-
"nb",
|
|
1076
|
-
"nd",
|
|
1077
|
-
"ne",
|
|
1078
|
-
"nl",
|
|
1079
|
-
"nn",
|
|
1080
|
-
"no",
|
|
1081
|
-
"om",
|
|
1082
|
-
"or",
|
|
1083
|
-
"os",
|
|
1084
|
-
"pa",
|
|
1085
|
-
"pl",
|
|
1086
|
-
"ps",
|
|
1087
|
-
"pt",
|
|
1088
|
-
"qu",
|
|
1089
|
-
"rm",
|
|
1090
|
-
"rn",
|
|
1091
|
-
"ro",
|
|
1092
|
-
"ru",
|
|
1093
|
-
"rw",
|
|
1094
|
-
"sa",
|
|
1095
|
-
"sc",
|
|
1096
|
-
"sd",
|
|
1097
|
-
"se",
|
|
1098
|
-
"sg",
|
|
1099
|
-
"si",
|
|
1100
|
-
"sk",
|
|
1101
|
-
"sl",
|
|
1102
|
-
"sn",
|
|
1103
|
-
"so",
|
|
1104
|
-
"sq",
|
|
1105
|
-
"sr",
|
|
1106
|
-
"su",
|
|
1107
|
-
"sv",
|
|
1108
|
-
"sw",
|
|
1109
|
-
"ta",
|
|
1110
|
-
"te",
|
|
1111
|
-
"tg",
|
|
1112
|
-
"th",
|
|
1113
|
-
"ti",
|
|
1114
|
-
"tk",
|
|
1115
|
-
"to",
|
|
1116
|
-
"tr",
|
|
1117
|
-
"tt",
|
|
1118
|
-
"ug",
|
|
1119
|
-
"uk",
|
|
1120
|
-
"ur",
|
|
1121
|
-
"uz",
|
|
1122
|
-
"vi",
|
|
1123
|
-
"wo",
|
|
1124
|
-
"xh",
|
|
1125
|
-
"yi",
|
|
1126
|
-
"yo",
|
|
1127
|
-
"zh",
|
|
1128
|
-
"zu"
|
|
1129
|
-
]);
|
|
1130
|
-
var timezonesSchema = import_zod6.default.enum([
|
|
619
|
+
var timezonesSchema = import_zod7.default.enum([
|
|
1131
620
|
"Africa/Abidjan",
|
|
1132
621
|
"Africa/Accra",
|
|
1133
622
|
"Africa/Addis_Ababa",
|
|
@@ -1549,605 +1038,1122 @@ var timezonesSchema = import_zod6.default.enum([
|
|
|
1549
1038
|
"UTC"
|
|
1550
1039
|
]);
|
|
1551
1040
|
|
|
1552
|
-
// src/
|
|
1553
|
-
var
|
|
1041
|
+
// src/utils/transform.ts
|
|
1042
|
+
var ArrayQueryParams = (p) => {
|
|
1043
|
+
const params = new URLSearchParams();
|
|
1044
|
+
const o = {};
|
|
1045
|
+
for (const [param, value] of Object.entries(p)) {
|
|
1046
|
+
for (const [key, val] of Object.entries(value)) {
|
|
1047
|
+
o[`${param}[${key}]`] = val;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
return o;
|
|
1051
|
+
};
|
|
1052
|
+
var SortParam = (key, p) => {
|
|
1053
|
+
return `${p === "desc" ? "-" : ""}${key}`;
|
|
1054
|
+
};
|
|
1055
|
+
|
|
1056
|
+
// src/api/application/users.ts
|
|
1057
|
+
var Users = class {
|
|
1058
|
+
r;
|
|
1059
|
+
constructor(requester) {
|
|
1060
|
+
this.r = requester;
|
|
1061
|
+
}
|
|
1062
|
+
list = async (opts, page = 1) => {
|
|
1063
|
+
import_zod8.default.number().positive().parse(page);
|
|
1064
|
+
const { data } = await this.r.get("/users", {
|
|
1065
|
+
params: {
|
|
1066
|
+
include: opts.include?.join(","),
|
|
1067
|
+
page,
|
|
1068
|
+
...ArrayQueryParams({ filters: opts.filters || {} }),
|
|
1069
|
+
sort: opts.sort && (opts.sort.id ? SortParam("id", opts.sort.id) : SortParam("uuid", opts.sort.uuid))
|
|
1070
|
+
}
|
|
1071
|
+
});
|
|
1072
|
+
return data.data.map((d) => d.attributes);
|
|
1073
|
+
};
|
|
1074
|
+
info = async (id, { include }) => {
|
|
1075
|
+
import_zod8.default.number().positive().parse(id);
|
|
1076
|
+
const { data } = await this.r.get(`/users/${id}`, { params: { include: include?.join(",") } });
|
|
1077
|
+
return data.attributes;
|
|
1078
|
+
};
|
|
1079
|
+
infoByExternal = async (external_id, { include }) => {
|
|
1080
|
+
const { data } = await this.r.get(`/users/external/${external_id}`, {
|
|
1081
|
+
params: { include: include?.join(",") }
|
|
1082
|
+
});
|
|
1083
|
+
return data.attributes;
|
|
1084
|
+
};
|
|
1085
|
+
create = async (user) => {
|
|
1086
|
+
user = CreateSchema.parse(user);
|
|
1087
|
+
const { data } = await this.r.post("/users", user);
|
|
1088
|
+
return data.attributes;
|
|
1089
|
+
};
|
|
1090
|
+
update = async (id, user) => {
|
|
1091
|
+
user = CreateSchema.parse(user);
|
|
1092
|
+
const { data } = await this.r.patch(`/users/${id}`, user);
|
|
1093
|
+
return data.attributes;
|
|
1094
|
+
};
|
|
1095
|
+
delete = async (id) => {
|
|
1096
|
+
import_zod8.default.number().positive().parse(id);
|
|
1097
|
+
await this.r.delete(`/users/${id}`);
|
|
1098
|
+
};
|
|
1099
|
+
addRoles = async (id, roles) => {
|
|
1100
|
+
import_zod8.default.number().positive().parse(id);
|
|
1101
|
+
await this.r.patch(`/users/${id}/roles/assign`, { roles });
|
|
1102
|
+
};
|
|
1103
|
+
removeRoles = async (id, roles) => {
|
|
1104
|
+
import_zod8.default.number().positive().parse(id);
|
|
1105
|
+
await this.r.patch(`/users/${id}/roles/remove`, { roles });
|
|
1106
|
+
};
|
|
1107
|
+
apiKeys = {
|
|
1108
|
+
list: async (id) => {
|
|
1109
|
+
const { data } = await this.r.get(`/users/${id}/api-keys`);
|
|
1110
|
+
return data.data.map((k) => k.attributes);
|
|
1111
|
+
},
|
|
1112
|
+
create: async (id, description, allowed_ips) => {
|
|
1113
|
+
allowed_ips = import_zod8.default.array(import_zod8.default.ipv4()).optional().parse(allowed_ips);
|
|
1114
|
+
const { data } = await this.r.post(`/users/${id}/api-keys`, { description, allowed_ips });
|
|
1115
|
+
return { ...data.attributes, secret_token: data.meta.secret_token };
|
|
1116
|
+
},
|
|
1117
|
+
delete: async (id, identifier) => {
|
|
1118
|
+
await this.r.delete(`/users/${id}/api-keys/${identifier}`);
|
|
1119
|
+
}
|
|
1120
|
+
};
|
|
1121
|
+
};
|
|
1122
|
+
var CreateSchema = import_zod8.default.object({
|
|
1123
|
+
email: import_zod8.default.email(),
|
|
1124
|
+
external_id: import_zod8.default.string().max(255).optional(),
|
|
1125
|
+
username: import_zod8.default.string().min(1).max(255),
|
|
1126
|
+
password: import_zod8.default.string().optional(),
|
|
1127
|
+
language: languagesSchema,
|
|
1128
|
+
timezone: timezonesSchema
|
|
1129
|
+
});
|
|
1130
|
+
|
|
1131
|
+
// src/api/application/client.ts
|
|
1132
|
+
var Client = class {
|
|
1133
|
+
r;
|
|
1134
|
+
users;
|
|
1135
|
+
nodes;
|
|
1136
|
+
databaseHosts;
|
|
1137
|
+
roles;
|
|
1138
|
+
eggs;
|
|
1139
|
+
mounts;
|
|
1140
|
+
constructor(requester) {
|
|
1141
|
+
this.r = requester;
|
|
1142
|
+
this.users = new Users(requester);
|
|
1143
|
+
this.nodes = new Nodes(requester);
|
|
1144
|
+
this.databaseHosts = new DatabaseHosts(requester);
|
|
1145
|
+
this.roles = new Roles(requester);
|
|
1146
|
+
this.eggs = new Eggs(requester);
|
|
1147
|
+
this.mounts = new Mounts(requester);
|
|
1148
|
+
}
|
|
1149
|
+
get $r() {
|
|
1150
|
+
return this.r;
|
|
1151
|
+
}
|
|
1152
|
+
listServers = async (search, page = 1) => {
|
|
1153
|
+
const { data } = await this.r.get("/servers", { params: { search, page } });
|
|
1154
|
+
return data.data.map((s) => s.attributes);
|
|
1155
|
+
};
|
|
1156
|
+
createServer = async (opts) => {
|
|
1157
|
+
opts = CreateServerSchema.parse(opts);
|
|
1158
|
+
const { data } = await this.r.post("/servers", opts);
|
|
1159
|
+
return data.attributes;
|
|
1160
|
+
};
|
|
1161
|
+
getServerByExternalId = async (external_id, include) => {
|
|
1162
|
+
const { data } = await this.r.get(`/servers/external/${external_id}`, {
|
|
1163
|
+
params: { include: include?.join(",") }
|
|
1164
|
+
});
|
|
1165
|
+
return data.attributes;
|
|
1166
|
+
};
|
|
1167
|
+
servers = (server_id) => new Servers(this.r, server_id);
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1170
|
+
// src/api/base/request.ts
|
|
1171
|
+
var import_axios = __toESM(require("axios"));
|
|
1172
|
+
var import_zod9 = __toESM(require("zod"));
|
|
1173
|
+
|
|
1174
|
+
// src/api/base/types.ts
|
|
1175
|
+
var PterodactylException = class extends Error {
|
|
1176
|
+
data;
|
|
1177
|
+
status;
|
|
1178
|
+
constructor(message, data, status) {
|
|
1179
|
+
super(message);
|
|
1180
|
+
this.data = data;
|
|
1181
|
+
this.status = status;
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
// src/api/base/request.ts
|
|
1186
|
+
var Agent = class {
|
|
1187
|
+
base_url;
|
|
1188
|
+
token;
|
|
1189
|
+
requester;
|
|
1190
|
+
constructor(url, token, type, suffix = "/api") {
|
|
1191
|
+
this.base_url = import_zod9.default.url("Invalid URL Schema").transform((url2) => new URL(url2).href).parse(url);
|
|
1192
|
+
this.token = import_zod9.default.string().regex(/^(ptl[ac]|pacc|papp)_.+$/, "Invalid token type").parse(token);
|
|
1193
|
+
this.requester = import_axios.default.create({
|
|
1194
|
+
baseURL: this.base_url.replace(/\/+$/, "") + `${suffix}/${type}`,
|
|
1195
|
+
timeout: 3e3,
|
|
1196
|
+
headers: { Authorization: `Bearer ${this.token}` }
|
|
1197
|
+
});
|
|
1198
|
+
this.requester.interceptors.response.use(void 0, (error) => {
|
|
1199
|
+
if (error.response && error.response.status === 400) {
|
|
1200
|
+
return Promise.reject(
|
|
1201
|
+
new PterodactylException(
|
|
1202
|
+
"Invalid request data",
|
|
1203
|
+
error.response.data,
|
|
1204
|
+
error.response.status
|
|
1205
|
+
)
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
return Promise.reject(error);
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
// src/api/client/client.ts
|
|
1214
|
+
var import_zod14 = __toESM(require("zod"));
|
|
1215
|
+
|
|
1216
|
+
// src/api/client/account.ts
|
|
1217
|
+
var import_zod10 = __toESM(require("zod"));
|
|
1218
|
+
var Account = class {
|
|
1219
|
+
r;
|
|
1220
|
+
constructor(requester) {
|
|
1221
|
+
this.r = requester;
|
|
1222
|
+
}
|
|
1223
|
+
info = async () => {
|
|
1224
|
+
const { data } = await this.r.get("/account");
|
|
1225
|
+
return data.attributes;
|
|
1226
|
+
};
|
|
1227
|
+
updateEmail = async (newEmail, password) => {
|
|
1228
|
+
newEmail = import_zod10.default.email().parse(newEmail);
|
|
1229
|
+
await this.r.put("/account/email", { email: newEmail, password });
|
|
1230
|
+
};
|
|
1231
|
+
updatePassword = async (newPassword) => {
|
|
1232
|
+
newPassword = import_zod10.default.string().min(8).parse(newPassword);
|
|
1233
|
+
await this.r.put("/account/password", {
|
|
1234
|
+
password: newPassword,
|
|
1235
|
+
password_confirmation: newPassword
|
|
1236
|
+
});
|
|
1237
|
+
};
|
|
1238
|
+
apiKeys = {
|
|
1239
|
+
list: async () => {
|
|
1240
|
+
const { data } = await this.r.get("/account/api-keys");
|
|
1241
|
+
return data.data.map((k) => k.attributes);
|
|
1242
|
+
},
|
|
1243
|
+
create: async (description, allowed_ips) => {
|
|
1244
|
+
allowed_ips = import_zod10.default.array(import_zod10.default.ipv4()).optional().parse(allowed_ips);
|
|
1245
|
+
const { data } = await this.r.post("/account/api-keys", { description, allowed_ips });
|
|
1246
|
+
return { ...data.attributes, secret_token: data.meta.secret_token };
|
|
1247
|
+
},
|
|
1248
|
+
delete: async (identifier) => {
|
|
1249
|
+
await this.r.delete(`/account/api-keys/${identifier}`);
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
sshKeys = {
|
|
1253
|
+
list: async () => {
|
|
1254
|
+
const { data } = await this.r.get("/account/ssh-keys");
|
|
1255
|
+
return data.data.map((k) => k.attributes);
|
|
1256
|
+
},
|
|
1257
|
+
create: async (name, public_key) => {
|
|
1258
|
+
const { data } = await this.r.post("/account/ssh-keys", { name, public_key });
|
|
1259
|
+
return data.attributes;
|
|
1260
|
+
},
|
|
1261
|
+
delete: async (fingerprint) => {
|
|
1262
|
+
await this.r.delete(`/account/ssh-keys/${fingerprint}`);
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
// src/api/client/server_activity.ts
|
|
1268
|
+
var ServerActivity = class {
|
|
1269
|
+
r;
|
|
1270
|
+
id;
|
|
1271
|
+
constructor(r, id) {
|
|
1272
|
+
this.r = r;
|
|
1273
|
+
this.id = id;
|
|
1274
|
+
}
|
|
1275
|
+
list = async (page = 1, per_page = 25) => {
|
|
1276
|
+
const { data } = await this.r.get(`/server/${this.id}/activity`, { params: { page, per_page } });
|
|
1277
|
+
return data.data.map((log) => log.attributes);
|
|
1278
|
+
};
|
|
1279
|
+
};
|
|
1280
|
+
|
|
1281
|
+
// src/api/client/server_allocations.ts
|
|
1282
|
+
var ServerAllocations = class {
|
|
1283
|
+
r;
|
|
1284
|
+
id;
|
|
1285
|
+
constructor(requester, id) {
|
|
1286
|
+
this.r = requester;
|
|
1287
|
+
this.id = id;
|
|
1288
|
+
}
|
|
1289
|
+
list = async () => {
|
|
1290
|
+
const { data } = await this.r.get(`/servers/${this.id}/network/allocations`);
|
|
1291
|
+
return data.data.map((r) => r.attributes);
|
|
1292
|
+
};
|
|
1293
|
+
autoAssign = async () => {
|
|
1294
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations`);
|
|
1295
|
+
return data.attributes;
|
|
1296
|
+
};
|
|
1297
|
+
setNotes = async (alloc_id, notes) => {
|
|
1298
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations/${alloc_id}`, { notes });
|
|
1299
|
+
return data.attributes;
|
|
1300
|
+
};
|
|
1301
|
+
setPrimary = async (alloc_id) => {
|
|
1302
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations/${alloc_id}/primary`);
|
|
1303
|
+
return data.attributes;
|
|
1304
|
+
};
|
|
1305
|
+
unassign = async (alloc_id) => {
|
|
1306
|
+
await this.r.delete(
|
|
1307
|
+
`/servers/${this.id}/network/allocations/${alloc_id}`
|
|
1308
|
+
);
|
|
1309
|
+
};
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
// src/api/client/server_backups.ts
|
|
1313
|
+
var import_axios2 = __toESM(require("axios"));
|
|
1314
|
+
var import_zod11 = __toESM(require("zod"));
|
|
1315
|
+
var ServerBackups = class {
|
|
1316
|
+
r;
|
|
1317
|
+
id;
|
|
1318
|
+
constructor(requester, id) {
|
|
1319
|
+
this.r = requester;
|
|
1320
|
+
this.id = id;
|
|
1321
|
+
}
|
|
1322
|
+
list = async (page = 1) => {
|
|
1323
|
+
import_zod11.default.number().positive().parse(page);
|
|
1324
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups`, { params: { page } });
|
|
1325
|
+
return data.data.map((d) => d.attributes);
|
|
1326
|
+
};
|
|
1327
|
+
create = async (args) => {
|
|
1328
|
+
args.name = import_zod11.default.string().max(255).optional().parse(args.name);
|
|
1329
|
+
const { data } = await this.r.post(`/servers/${this.id}/backups`, {
|
|
1330
|
+
name: args.name,
|
|
1331
|
+
is_locked: args.is_locked,
|
|
1332
|
+
ignored_files: args.ignored_files.join("\n")
|
|
1333
|
+
});
|
|
1334
|
+
return data.attributes;
|
|
1335
|
+
};
|
|
1336
|
+
info = async (backup_uuid) => {
|
|
1337
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups/${backup_uuid}`);
|
|
1338
|
+
return data.attributes;
|
|
1339
|
+
};
|
|
1340
|
+
downloadGetUrl = async (backup_uuid) => {
|
|
1341
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups/${backup_uuid}/download`);
|
|
1342
|
+
return data.attributes.url;
|
|
1343
|
+
};
|
|
1344
|
+
download = async (backup_uuid) => {
|
|
1345
|
+
const url = await this.downloadGetUrl(backup_uuid);
|
|
1346
|
+
const { data } = await import_axios2.default.get(url, {
|
|
1347
|
+
responseType: "arraybuffer"
|
|
1348
|
+
});
|
|
1349
|
+
return data;
|
|
1350
|
+
};
|
|
1351
|
+
delete = async (backup_uuid) => {
|
|
1352
|
+
await this.r.delete(`/servers/${this.id}/backups/${backup_uuid}`);
|
|
1353
|
+
};
|
|
1354
|
+
rename = async (backup_uuid, name) => {
|
|
1355
|
+
await this.r.put(`/servers/${this.id}/backups/${backup_uuid}/rename`, {
|
|
1356
|
+
name
|
|
1357
|
+
});
|
|
1358
|
+
};
|
|
1359
|
+
toggleLock = async (backup_uuid) => {
|
|
1360
|
+
await this.r.post(`/servers/${this.id}/backups/${backup_uuid}/lock`);
|
|
1361
|
+
};
|
|
1362
|
+
restore = async (backup_uuid, truncate) => {
|
|
1363
|
+
await this.r.post(
|
|
1364
|
+
`/servers/${this.id}/backups/${backup_uuid}/restore`,
|
|
1365
|
+
{ truncate }
|
|
1366
|
+
);
|
|
1367
|
+
};
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
// src/api/client/server_databases.ts
|
|
1371
|
+
var import_zod12 = __toESM(require("zod"));
|
|
1372
|
+
var ServerDatabases = class {
|
|
1373
|
+
r;
|
|
1374
|
+
id;
|
|
1375
|
+
constructor(requester, id) {
|
|
1376
|
+
this.r = requester;
|
|
1377
|
+
this.id = id;
|
|
1378
|
+
}
|
|
1379
|
+
list = async (include, page = 1) => {
|
|
1380
|
+
import_zod12.default.number().positive().parse(page);
|
|
1381
|
+
const { data } = await this.r.get(`/servers/${this.id}/databases`, {
|
|
1382
|
+
params: { include: include?.join(","), page }
|
|
1383
|
+
});
|
|
1384
|
+
return data.data.map((d) => d.attributes);
|
|
1385
|
+
};
|
|
1386
|
+
create = async (database, remote) => {
|
|
1387
|
+
const { data } = await this.r.post(`/servers/${this.id}/databases`, { database, remote });
|
|
1388
|
+
return data.attributes;
|
|
1389
|
+
};
|
|
1390
|
+
rotatePassword = async (database_id) => {
|
|
1391
|
+
const { data } = await this.r.post(`/servers/${this.id}/databases/${database_id}/rotate-password`);
|
|
1392
|
+
return data.attributes;
|
|
1393
|
+
};
|
|
1394
|
+
delete = async (database_id) => {
|
|
1395
|
+
await this.r.delete(`/servers/${this.id}/databases/${database_id}`);
|
|
1396
|
+
};
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
// src/api/client/server_files.ts
|
|
1400
|
+
var import_axios3 = __toESM(require("axios"));
|
|
1401
|
+
var ServerFiles = class {
|
|
1402
|
+
r;
|
|
1403
|
+
id;
|
|
1404
|
+
constructor(requester, id) {
|
|
1405
|
+
this.r = requester;
|
|
1406
|
+
this.id = id;
|
|
1407
|
+
}
|
|
1408
|
+
list = async (path) => {
|
|
1409
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/list`, { params: { directory: path } });
|
|
1410
|
+
return data.data.map((r) => r.attributes);
|
|
1411
|
+
};
|
|
1412
|
+
/**
|
|
1413
|
+
* Return the contents of a file. To read binary file (non-editable) use {@link download} instead
|
|
1414
|
+
*/
|
|
1415
|
+
contents = async (path) => {
|
|
1416
|
+
const { data } = await this.r.get(
|
|
1417
|
+
`/servers/${this.id}/files/contents`,
|
|
1418
|
+
{ params: { file: path } }
|
|
1419
|
+
);
|
|
1420
|
+
return data;
|
|
1421
|
+
};
|
|
1422
|
+
downloadGetUrl = async (path) => {
|
|
1423
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/download`, { params: { file: path } });
|
|
1424
|
+
return data.attributes.url;
|
|
1425
|
+
};
|
|
1426
|
+
download = async (path) => {
|
|
1427
|
+
const url = await this.downloadGetUrl(path);
|
|
1428
|
+
const { data } = await import_axios3.default.get(url, {
|
|
1429
|
+
responseType: "arraybuffer"
|
|
1430
|
+
});
|
|
1431
|
+
return data;
|
|
1432
|
+
};
|
|
1433
|
+
rename = async (root = "/", files) => {
|
|
1434
|
+
await this.r.put(`/servers/${this.id}/files/rename`, { root, files });
|
|
1435
|
+
};
|
|
1436
|
+
copy = async (location) => {
|
|
1437
|
+
await this.r.post(`/servers/${this.id}/files/copy`, { location });
|
|
1438
|
+
};
|
|
1439
|
+
write = async (path, content) => {
|
|
1440
|
+
await this.r.post(`/servers/${this.id}/files/write`, content, {
|
|
1441
|
+
params: { file: path }
|
|
1442
|
+
});
|
|
1443
|
+
};
|
|
1444
|
+
compress = async (root = "/", files, archive_name, extension) => {
|
|
1445
|
+
const { data } = await this.r.post(`/servers/${this.id}/files/compress`, {
|
|
1446
|
+
root,
|
|
1447
|
+
files,
|
|
1448
|
+
archive_name,
|
|
1449
|
+
extension
|
|
1450
|
+
});
|
|
1451
|
+
return data.attributes;
|
|
1452
|
+
};
|
|
1453
|
+
decompress = async (root = "/", file) => {
|
|
1454
|
+
await this.r.post(`/servers/${this.id}/files/decompress`, { root, file });
|
|
1455
|
+
};
|
|
1456
|
+
delete = async (root = "/", files) => {
|
|
1457
|
+
await this.r.post(`/servers/${this.id}/files/delete`, { root, files });
|
|
1458
|
+
};
|
|
1459
|
+
createFolder = async (root = "/", name) => {
|
|
1460
|
+
await this.r.post(`/servers/${this.id}/files/create-folder`, {
|
|
1461
|
+
root,
|
|
1462
|
+
name
|
|
1463
|
+
});
|
|
1464
|
+
};
|
|
1465
|
+
chmod = async (root = "/", files) => {
|
|
1466
|
+
await this.r.post(`/servers/${this.id}/files/chmod`, { root, files });
|
|
1467
|
+
};
|
|
1468
|
+
pullFromRemote = async (url, directory, filename, use_header = false, foreground = false) => {
|
|
1469
|
+
await this.r.post(`/servers/${this.id}/files/pull`, {
|
|
1470
|
+
url,
|
|
1471
|
+
directory,
|
|
1472
|
+
filename,
|
|
1473
|
+
use_header,
|
|
1474
|
+
foreground
|
|
1475
|
+
});
|
|
1476
|
+
};
|
|
1477
|
+
uploadGetUrl = async () => {
|
|
1478
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/upload`);
|
|
1479
|
+
return data.attributes.url;
|
|
1480
|
+
};
|
|
1481
|
+
upload = async (file, root = "/") => {
|
|
1482
|
+
const url = await this.uploadGetUrl();
|
|
1483
|
+
await import_axios3.default.post(
|
|
1484
|
+
url,
|
|
1485
|
+
{ files: file },
|
|
1486
|
+
{
|
|
1487
|
+
headers: { "Content-Type": "multipart/form-data" },
|
|
1488
|
+
params: { directory: root }
|
|
1489
|
+
}
|
|
1490
|
+
);
|
|
1491
|
+
};
|
|
1492
|
+
};
|
|
1493
|
+
|
|
1494
|
+
// src/api/client/server_schedules.ts
|
|
1495
|
+
var ServerSchedules = class {
|
|
1496
|
+
r;
|
|
1497
|
+
id;
|
|
1498
|
+
constructor(requester, id) {
|
|
1499
|
+
this.r = requester;
|
|
1500
|
+
this.id = id;
|
|
1501
|
+
}
|
|
1502
|
+
list = async () => {
|
|
1503
|
+
const { data } = await this.r.get(`/servers/${this.id}/schedules`);
|
|
1504
|
+
return data.data.map((d) => d.attributes);
|
|
1505
|
+
};
|
|
1506
|
+
create = async (params) => {
|
|
1507
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules`, params);
|
|
1508
|
+
return data.attributes;
|
|
1509
|
+
};
|
|
1510
|
+
control = (sched_id) => new ScheduleControl(this.r, this.id, sched_id);
|
|
1511
|
+
};
|
|
1512
|
+
var ScheduleControl = class {
|
|
1513
|
+
r;
|
|
1514
|
+
id;
|
|
1515
|
+
sched_id;
|
|
1516
|
+
constructor(requester, id, sched_id) {
|
|
1517
|
+
this.r = requester;
|
|
1518
|
+
this.id = id;
|
|
1519
|
+
this.sched_id = sched_id;
|
|
1520
|
+
}
|
|
1521
|
+
info = async () => {
|
|
1522
|
+
const { data } = await this.r.get(`/servers/${this.id}/schedules/${this.sched_id}`);
|
|
1523
|
+
return data.attributes;
|
|
1524
|
+
};
|
|
1525
|
+
update = async (params) => {
|
|
1526
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}`, params);
|
|
1527
|
+
return data.attributes;
|
|
1528
|
+
};
|
|
1529
|
+
delete = async () => {
|
|
1530
|
+
await this.r.delete(`/servers/${this.id}/schedules/${this.sched_id}`);
|
|
1531
|
+
};
|
|
1532
|
+
execute = async () => {
|
|
1533
|
+
await this.r.post(
|
|
1534
|
+
`/servers/${this.id}/schedules/${this.sched_id}/execute`
|
|
1535
|
+
);
|
|
1536
|
+
};
|
|
1537
|
+
tasks = {
|
|
1538
|
+
create: async (opts) => {
|
|
1539
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}/tasks`, opts);
|
|
1540
|
+
return data.attributes;
|
|
1541
|
+
},
|
|
1542
|
+
update: async (task_id, opts) => {
|
|
1543
|
+
const { data } = await this.r.post(
|
|
1544
|
+
`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`,
|
|
1545
|
+
opts
|
|
1546
|
+
);
|
|
1547
|
+
return data.attributes;
|
|
1548
|
+
},
|
|
1549
|
+
delete: async (task_id) => {
|
|
1550
|
+
await this.r.delete(
|
|
1551
|
+
`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
// src/api/client/server_settings.ts
|
|
1558
|
+
var import_zod13 = __toESM(require("zod"));
|
|
1559
|
+
var ServerSettings = class {
|
|
1554
1560
|
r;
|
|
1555
|
-
|
|
1561
|
+
id;
|
|
1562
|
+
constructor(requester, id) {
|
|
1563
|
+
this.r = requester;
|
|
1564
|
+
this.id = id;
|
|
1565
|
+
}
|
|
1566
|
+
rename = async (name) => {
|
|
1567
|
+
name = import_zod13.default.string().max(255).parse(name);
|
|
1568
|
+
await this.r.post(`/servers/${this.id}/settings/rename`, { name });
|
|
1569
|
+
};
|
|
1570
|
+
updateDescription = async (description) => {
|
|
1571
|
+
await this.r.post(`/servers/${this.id}/settings/description`, {
|
|
1572
|
+
description
|
|
1573
|
+
});
|
|
1574
|
+
};
|
|
1575
|
+
reinstall = async () => {
|
|
1576
|
+
await this.r.post(`/servers/${this.id}/settings/reinstall`);
|
|
1577
|
+
};
|
|
1578
|
+
changeDockerImage = async (image) => {
|
|
1579
|
+
await this.r.put(`/servers/${this.id}/settings/docker-image`, {
|
|
1580
|
+
docker_image: image
|
|
1581
|
+
});
|
|
1582
|
+
};
|
|
1583
|
+
};
|
|
1584
|
+
|
|
1585
|
+
// src/api/client/server_startup.ts
|
|
1586
|
+
var ServerStartup = class {
|
|
1587
|
+
r;
|
|
1588
|
+
id;
|
|
1589
|
+
constructor(requester, id) {
|
|
1590
|
+
this.r = requester;
|
|
1591
|
+
this.id = id;
|
|
1592
|
+
}
|
|
1593
|
+
list = async () => {
|
|
1594
|
+
const { data } = await this.r.get(`/servers/${this.id}/startup`);
|
|
1595
|
+
return {
|
|
1596
|
+
object: "list",
|
|
1597
|
+
meta: data.meta,
|
|
1598
|
+
data: data.data.map((d) => d.attributes)
|
|
1599
|
+
};
|
|
1600
|
+
};
|
|
1601
|
+
set = async (key, value) => {
|
|
1602
|
+
const { data } = await this.r.put(`/servers/${this.id}/startup/variable`, { key, value });
|
|
1603
|
+
return data.attributes;
|
|
1604
|
+
};
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1607
|
+
// src/api/client/server_users.ts
|
|
1608
|
+
var ServerUsers = class {
|
|
1609
|
+
r;
|
|
1610
|
+
id;
|
|
1611
|
+
constructor(requester, id) {
|
|
1612
|
+
this.r = requester;
|
|
1613
|
+
this.id = id;
|
|
1614
|
+
}
|
|
1615
|
+
list = async () => {
|
|
1616
|
+
const { data } = await this.r.get(`/servers/${this.id}/users`);
|
|
1617
|
+
return data.data.map((d) => d.attributes);
|
|
1618
|
+
};
|
|
1619
|
+
create = async (email, permissions) => {
|
|
1620
|
+
const { data } = await this.r.post(`/servers/${this.id}/users`, { email, permissions });
|
|
1621
|
+
return data.attributes;
|
|
1622
|
+
};
|
|
1623
|
+
info = async (user_uuid) => {
|
|
1624
|
+
const { data } = await this.r.get(
|
|
1625
|
+
`/servers/${this.id}/users/${user_uuid}`
|
|
1626
|
+
);
|
|
1627
|
+
return data.attributes;
|
|
1628
|
+
};
|
|
1629
|
+
update = async (user_uuid, permissions) => {
|
|
1630
|
+
const { data } = await this.r.put(
|
|
1631
|
+
`/servers/${this.id}/users/${user_uuid}`,
|
|
1632
|
+
{ permissions }
|
|
1633
|
+
);
|
|
1634
|
+
return data.attributes;
|
|
1635
|
+
};
|
|
1636
|
+
delete = async (user_uuid) => {
|
|
1637
|
+
await this.r.delete(`/servers/${this.id}/users/${user_uuid}`);
|
|
1638
|
+
};
|
|
1639
|
+
};
|
|
1640
|
+
|
|
1641
|
+
// src/api/client/server_websocket.ts
|
|
1642
|
+
var import_events = require("events");
|
|
1643
|
+
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
1644
|
+
var import_strip_color = __toESM(require("strip-color"));
|
|
1645
|
+
var isBrowser = typeof window !== "undefined";
|
|
1646
|
+
var RECONNECT_ERRORS = /* @__PURE__ */ new Set([
|
|
1647
|
+
"jwt: exp claim is invalid",
|
|
1648
|
+
"jwt: created too far in past (denylist)"
|
|
1649
|
+
]);
|
|
1650
|
+
var FALLBACK_LOG_MESSAGE = "No logs - is the server online?";
|
|
1651
|
+
var ServerWebsocket = class {
|
|
1652
|
+
r;
|
|
1653
|
+
serverId;
|
|
1654
|
+
socket;
|
|
1655
|
+
currentToken;
|
|
1656
|
+
bus = new import_events.EventEmitter();
|
|
1657
|
+
debugLogging = false;
|
|
1658
|
+
stripColors;
|
|
1659
|
+
detachMessageListener;
|
|
1660
|
+
constructor(requester, id, stripColors = false) {
|
|
1556
1661
|
this.r = requester;
|
|
1662
|
+
this.serverId = id;
|
|
1663
|
+
this.stripColors = stripColors;
|
|
1664
|
+
}
|
|
1665
|
+
on(event, listener) {
|
|
1666
|
+
const handler = listener;
|
|
1667
|
+
this.bus.on(event, handler);
|
|
1668
|
+
return () => {
|
|
1669
|
+
this.bus.removeListener(event, handler);
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
deregister(event, listener) {
|
|
1673
|
+
const handler = listener;
|
|
1674
|
+
this.bus.removeListener(event, handler);
|
|
1675
|
+
}
|
|
1676
|
+
emit(event, ...args) {
|
|
1677
|
+
if (args.length === 0) {
|
|
1678
|
+
this.bus.emit(event);
|
|
1679
|
+
} else {
|
|
1680
|
+
this.bus.emit(event, args[0]);
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
async connect(resumable, debugLogging) {
|
|
1684
|
+
this.debugLogging = debugLogging ?? false;
|
|
1685
|
+
if (this.socket) {
|
|
1686
|
+
return;
|
|
1687
|
+
}
|
|
1688
|
+
const socketUrl = await this.refreshCredentials();
|
|
1689
|
+
this.socket = isBrowser ? new import_isomorphic_ws.default(socketUrl) : new import_isomorphic_ws.default(socketUrl, void 0, {
|
|
1690
|
+
origin: new URL(socketUrl).origin
|
|
1691
|
+
});
|
|
1692
|
+
await new Promise((resolve, reject) => {
|
|
1693
|
+
const socket = this.socket;
|
|
1694
|
+
if (!socket) {
|
|
1695
|
+
reject(new Error("Failed to create socket connection"));
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
socket.onopen = async () => {
|
|
1699
|
+
try {
|
|
1700
|
+
await this.authenticate();
|
|
1701
|
+
this.attachMessageListener();
|
|
1702
|
+
socket.onopen = null;
|
|
1703
|
+
socket.onerror = null;
|
|
1704
|
+
resolve();
|
|
1705
|
+
} catch (error) {
|
|
1706
|
+
socket.onopen = null;
|
|
1707
|
+
socket.onerror = null;
|
|
1708
|
+
reject(
|
|
1709
|
+
error instanceof Error ? error : new Error("Websocket authentication failed")
|
|
1710
|
+
);
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1713
|
+
socket.onerror = (event) => {
|
|
1714
|
+
socket.onopen = null;
|
|
1715
|
+
socket.onerror = null;
|
|
1716
|
+
reject(
|
|
1717
|
+
event instanceof Error ? event : new Error("Websocket connection error")
|
|
1718
|
+
);
|
|
1719
|
+
};
|
|
1720
|
+
});
|
|
1721
|
+
if (resumable) {
|
|
1722
|
+
this.makeResumable(true);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
onSocketDisconnect(handler) {
|
|
1726
|
+
if (!this.socket) {
|
|
1727
|
+
console.error(new Error("No socket connection"));
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
this.socket.onclose = handler;
|
|
1731
|
+
}
|
|
1732
|
+
onSocketError(handler) {
|
|
1733
|
+
if (!this.socket) {
|
|
1734
|
+
console.error(new Error("No socket connection"));
|
|
1735
|
+
return;
|
|
1736
|
+
}
|
|
1737
|
+
this.socket.onerror = handler;
|
|
1738
|
+
}
|
|
1739
|
+
makeResumable(disconnectsToo) {
|
|
1740
|
+
const scheduleReconnect = () => {
|
|
1741
|
+
setTimeout(() => {
|
|
1742
|
+
const previous = this.socket;
|
|
1743
|
+
this.detachMessageListener?.();
|
|
1744
|
+
this.detachMessageListener = void 0;
|
|
1745
|
+
this.socket = void 0;
|
|
1746
|
+
previous?.close();
|
|
1747
|
+
void this.connect(true, this.debugLogging);
|
|
1748
|
+
}, 1e3);
|
|
1749
|
+
};
|
|
1750
|
+
this.onSocketError(() => scheduleReconnect());
|
|
1751
|
+
if (disconnectsToo) {
|
|
1752
|
+
this.onSocketDisconnect(() => scheduleReconnect());
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
attachMessageListener() {
|
|
1756
|
+
if (!this.socket) {
|
|
1757
|
+
throw new Error("No socket connection");
|
|
1758
|
+
}
|
|
1759
|
+
this.detachMessageListener?.();
|
|
1760
|
+
const handler = (event) => {
|
|
1761
|
+
void this.handleIncomingMessage(event);
|
|
1762
|
+
};
|
|
1763
|
+
if (typeof this.socket.addEventListener === "function") {
|
|
1764
|
+
this.socket.addEventListener(
|
|
1765
|
+
"message",
|
|
1766
|
+
handler
|
|
1767
|
+
);
|
|
1768
|
+
this.detachMessageListener = () => {
|
|
1769
|
+
this.socket?.removeEventListener?.(
|
|
1770
|
+
"message",
|
|
1771
|
+
handler
|
|
1772
|
+
);
|
|
1773
|
+
};
|
|
1774
|
+
} else {
|
|
1775
|
+
const fallback = (data) => handler({ data });
|
|
1776
|
+
const socket = this.socket;
|
|
1777
|
+
socket.on?.("message", fallback);
|
|
1778
|
+
this.detachMessageListener = () => {
|
|
1779
|
+
const target = this.socket;
|
|
1780
|
+
if (!target) {
|
|
1781
|
+
return;
|
|
1782
|
+
}
|
|
1783
|
+
if (typeof target.off === "function") {
|
|
1784
|
+
target.off("message", fallback);
|
|
1785
|
+
} else if (typeof target.removeListener === "function") {
|
|
1786
|
+
target.removeListener("message", fallback);
|
|
1787
|
+
}
|
|
1788
|
+
};
|
|
1789
|
+
}
|
|
1557
1790
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1791
|
+
async handleIncomingMessage(event) {
|
|
1792
|
+
const message = this.parseMessage(event);
|
|
1793
|
+
if (!message) {
|
|
1794
|
+
return;
|
|
1795
|
+
}
|
|
1796
|
+
try {
|
|
1797
|
+
await this.dispatchMessage(message);
|
|
1798
|
+
} catch (error) {
|
|
1799
|
+
if (this.debugLogging) {
|
|
1800
|
+
console.error("Error while handling websocket message", error);
|
|
1566
1801
|
}
|
|
1567
|
-
});
|
|
1568
|
-
return data.data.map((d) => d.attributes);
|
|
1569
|
-
};
|
|
1570
|
-
info = async (id, { include }) => {
|
|
1571
|
-
import_zod7.default.number().positive().parse(id);
|
|
1572
|
-
const { data } = await this.r.get(`/users/${id}`, { params: { include: include?.join(",") } });
|
|
1573
|
-
return data.attributes;
|
|
1574
|
-
};
|
|
1575
|
-
infoByExternal = async (external_id, { include }) => {
|
|
1576
|
-
const { data } = await this.r.get(`/users/external/${external_id}`, {
|
|
1577
|
-
params: { include: include?.join(",") }
|
|
1578
|
-
});
|
|
1579
|
-
return data.attributes;
|
|
1580
|
-
};
|
|
1581
|
-
create = async (user) => {
|
|
1582
|
-
user = CreateSchema.parse(user);
|
|
1583
|
-
const { data } = await this.r.post("/users", user);
|
|
1584
|
-
return data.attributes;
|
|
1585
|
-
};
|
|
1586
|
-
update = async (id, user) => {
|
|
1587
|
-
user = CreateSchema.parse(user);
|
|
1588
|
-
const { data } = await this.r.patch(`/users/${id}`, user);
|
|
1589
|
-
return data.attributes;
|
|
1590
|
-
};
|
|
1591
|
-
delete = async (id) => {
|
|
1592
|
-
import_zod7.default.number().positive().parse(id);
|
|
1593
|
-
await this.r.delete(`/users/${id}`);
|
|
1594
|
-
};
|
|
1595
|
-
addRoles = async (id, roles) => {
|
|
1596
|
-
import_zod7.default.number().positive().parse(id);
|
|
1597
|
-
await this.r.patch(`/users/${id}/roles/assign`, { roles });
|
|
1598
|
-
};
|
|
1599
|
-
removeRoles = async (id, roles) => {
|
|
1600
|
-
import_zod7.default.number().positive().parse(id);
|
|
1601
|
-
await this.r.patch(`/users/${id}/roles/remove`, { roles });
|
|
1602
|
-
};
|
|
1603
|
-
apiKeys = {
|
|
1604
|
-
list: async (id) => {
|
|
1605
|
-
const { data } = await this.r.get(`/users/${id}/api-keys`);
|
|
1606
|
-
return data.data.map((k) => k.attributes);
|
|
1607
|
-
},
|
|
1608
|
-
create: async (id, description, allowed_ips) => {
|
|
1609
|
-
allowed_ips = import_zod7.default.array(import_zod7.default.ipv4()).optional().parse(allowed_ips);
|
|
1610
|
-
const { data } = await this.r.post(`/users/${id}/api-keys`, { description, allowed_ips });
|
|
1611
|
-
return { ...data.attributes, secret_token: data.meta.secret_token };
|
|
1612
|
-
},
|
|
1613
|
-
delete: async (id, identifier) => {
|
|
1614
|
-
await this.r.delete(`/users/${id}/api-keys/${identifier}`);
|
|
1615
1802
|
}
|
|
1616
|
-
};
|
|
1617
|
-
};
|
|
1618
|
-
var CreateSchema = import_zod7.default.object({
|
|
1619
|
-
email: import_zod7.default.email(),
|
|
1620
|
-
external_id: import_zod7.default.string().max(255).optional(),
|
|
1621
|
-
username: import_zod7.default.string().min(1).max(255),
|
|
1622
|
-
password: import_zod7.default.string().optional(),
|
|
1623
|
-
language: languagesSchema,
|
|
1624
|
-
timezone: timezonesSchema
|
|
1625
|
-
});
|
|
1626
|
-
|
|
1627
|
-
// src/api/application/nodes_allocations.ts
|
|
1628
|
-
var import_zod8 = __toESM(require("zod"));
|
|
1629
|
-
var NodesAllocations = class {
|
|
1630
|
-
r;
|
|
1631
|
-
id;
|
|
1632
|
-
constructor(requester, id) {
|
|
1633
|
-
this.r = requester;
|
|
1634
|
-
this.id = id;
|
|
1635
1803
|
}
|
|
1636
|
-
|
|
1637
|
-
const
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
await this.r.delete(`/nodes/${this.id}/allocations/${alloc_id}`);
|
|
1650
|
-
};
|
|
1651
|
-
};
|
|
1652
|
-
|
|
1653
|
-
// src/api/application/nodes.ts
|
|
1654
|
-
var import_zod9 = __toESM(require("zod"));
|
|
1655
|
-
var Nodes = class {
|
|
1656
|
-
r;
|
|
1657
|
-
constructor(requester) {
|
|
1658
|
-
this.r = requester;
|
|
1804
|
+
parseMessage(event) {
|
|
1805
|
+
const payload = this.normalisePayload(event);
|
|
1806
|
+
if (!payload) {
|
|
1807
|
+
return null;
|
|
1808
|
+
}
|
|
1809
|
+
try {
|
|
1810
|
+
return JSON.parse(payload);
|
|
1811
|
+
} catch (error) {
|
|
1812
|
+
if (this.debugLogging) {
|
|
1813
|
+
console.warn("Failed to parse websocket payload", error);
|
|
1814
|
+
}
|
|
1815
|
+
return null;
|
|
1816
|
+
}
|
|
1659
1817
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1818
|
+
normalisePayload(event) {
|
|
1819
|
+
if (typeof event === "string") {
|
|
1820
|
+
return event;
|
|
1821
|
+
}
|
|
1822
|
+
if (typeof event === "object" && event !== null && "data" in event) {
|
|
1823
|
+
return this.normalisePayload(event.data);
|
|
1824
|
+
}
|
|
1825
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(event)) {
|
|
1826
|
+
return event.toString("utf8");
|
|
1827
|
+
}
|
|
1828
|
+
if (typeof ArrayBuffer !== "undefined" && event instanceof ArrayBuffer) {
|
|
1829
|
+
if (typeof TextDecoder !== "undefined") {
|
|
1830
|
+
return new TextDecoder().decode(new Uint8Array(event));
|
|
1831
|
+
}
|
|
1832
|
+
if (typeof Buffer !== "undefined") {
|
|
1833
|
+
return Buffer.from(event).toString("utf8");
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
return null;
|
|
1837
|
+
}
|
|
1838
|
+
async dispatchMessage(message) {
|
|
1839
|
+
switch (message.event) {
|
|
1840
|
+
case "auth success" /* AUTH_SUCCESS */: {
|
|
1841
|
+
if (this.debugLogging) {
|
|
1842
|
+
console.debug("Auth success");
|
|
1843
|
+
}
|
|
1844
|
+
this.emit("auth success" /* AUTH_SUCCESS */);
|
|
1845
|
+
break;
|
|
1846
|
+
}
|
|
1847
|
+
case "status" /* STATUS */: {
|
|
1848
|
+
if (this.debugLogging) {
|
|
1849
|
+
console.debug("Received status event", message.args[0]);
|
|
1850
|
+
}
|
|
1851
|
+
this.emit("status" /* STATUS */, message.args[0]);
|
|
1852
|
+
break;
|
|
1853
|
+
}
|
|
1854
|
+
case "console output" /* CONSOLE_OUTPUT */: {
|
|
1855
|
+
let output = message.args[0];
|
|
1856
|
+
if (this.stripColors) {
|
|
1857
|
+
output = (0, import_strip_color.default)(output);
|
|
1858
|
+
}
|
|
1859
|
+
if (this.debugLogging) {
|
|
1860
|
+
console.debug("Received console output", output);
|
|
1861
|
+
}
|
|
1862
|
+
this.emit("console output" /* CONSOLE_OUTPUT */, output);
|
|
1863
|
+
break;
|
|
1864
|
+
}
|
|
1865
|
+
case "stats" /* STATS */: {
|
|
1866
|
+
try {
|
|
1867
|
+
const payload = JSON.parse(message.args[0]);
|
|
1868
|
+
this.emit("stats" /* STATS */, payload);
|
|
1869
|
+
} catch (error) {
|
|
1870
|
+
if (this.debugLogging) {
|
|
1871
|
+
console.warn("Failed to parse stats payload", error);
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
break;
|
|
1875
|
+
}
|
|
1876
|
+
case "daemon error" /* DAEMON_ERROR */: {
|
|
1877
|
+
this.emit("daemon error" /* DAEMON_ERROR */);
|
|
1878
|
+
break;
|
|
1879
|
+
}
|
|
1880
|
+
case "backup completed" /* BACKUP_COMPLETED */: {
|
|
1881
|
+
try {
|
|
1882
|
+
const payload = JSON.parse(
|
|
1883
|
+
message.args[0]
|
|
1884
|
+
);
|
|
1885
|
+
this.emit("backup completed" /* BACKUP_COMPLETED */, payload);
|
|
1886
|
+
} catch (error) {
|
|
1887
|
+
if (this.debugLogging) {
|
|
1888
|
+
console.warn("Failed to parse backup payload", error);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
break;
|
|
1892
|
+
}
|
|
1893
|
+
case "daemon message" /* DAEMON_MESSAGE */: {
|
|
1894
|
+
let output = message.args[0];
|
|
1895
|
+
if (this.stripColors) {
|
|
1896
|
+
output = (0, import_strip_color.default)(output);
|
|
1897
|
+
}
|
|
1898
|
+
this.emit("daemon message" /* DAEMON_MESSAGE */, output);
|
|
1899
|
+
break;
|
|
1900
|
+
}
|
|
1901
|
+
case "install output" /* INSTALL_OUTPUT */: {
|
|
1902
|
+
let output = message.args[0];
|
|
1903
|
+
if (this.stripColors) {
|
|
1904
|
+
output = (0, import_strip_color.default)(output);
|
|
1905
|
+
}
|
|
1906
|
+
this.emit("install output" /* INSTALL_OUTPUT */, output);
|
|
1907
|
+
break;
|
|
1908
|
+
}
|
|
1909
|
+
case "backup restore completed" /* BACKUP_RESTORE_COMPLETED */: {
|
|
1910
|
+
this.emit("backup restore completed" /* BACKUP_RESTORE_COMPLETED */);
|
|
1911
|
+
break;
|
|
1912
|
+
}
|
|
1913
|
+
case "install completed" /* INSTALL_COMPLETED */: {
|
|
1914
|
+
this.emit("install completed" /* INSTALL_COMPLETED */);
|
|
1915
|
+
break;
|
|
1916
|
+
}
|
|
1917
|
+
case "install started" /* INSTALL_STARTED */: {
|
|
1918
|
+
this.emit("install started" /* INSTALL_STARTED */);
|
|
1919
|
+
break;
|
|
1920
|
+
}
|
|
1921
|
+
case "transfer logs" /* TRANSFER_LOGS */: {
|
|
1922
|
+
this.emit("transfer logs" /* TRANSFER_LOGS */, message.args[0]);
|
|
1923
|
+
break;
|
|
1924
|
+
}
|
|
1925
|
+
case "transfer status" /* TRANSFER_STATUS */: {
|
|
1926
|
+
this.emit("transfer status" /* TRANSFER_STATUS */, message.args[0]);
|
|
1927
|
+
break;
|
|
1928
|
+
}
|
|
1929
|
+
case "token expiring" /* TOKEN_EXPIRING */: {
|
|
1930
|
+
this.emit("token expiring" /* TOKEN_EXPIRING */);
|
|
1931
|
+
if (this.debugLogging) {
|
|
1932
|
+
console.warn("Token expiring, renewing...");
|
|
1933
|
+
}
|
|
1934
|
+
await this.refreshCredentials();
|
|
1935
|
+
await this.authenticate();
|
|
1936
|
+
break;
|
|
1937
|
+
}
|
|
1938
|
+
case "token expired" /* TOKEN_EXPIRED */: {
|
|
1939
|
+
this.emit("token expired" /* TOKEN_EXPIRED */);
|
|
1940
|
+
throw new Error("Token expired");
|
|
1941
|
+
}
|
|
1942
|
+
case "jwt error" /* JWT_ERROR */: {
|
|
1943
|
+
const reason = message.args[0];
|
|
1944
|
+
if (RECONNECT_ERRORS.has(reason)) {
|
|
1945
|
+
this.emit("token expiring" /* TOKEN_EXPIRING */);
|
|
1946
|
+
if (this.debugLogging) {
|
|
1947
|
+
console.warn("Token expiring (JWT error), renewing...");
|
|
1948
|
+
}
|
|
1949
|
+
await this.refreshCredentials();
|
|
1950
|
+
await this.authenticate();
|
|
1951
|
+
} else {
|
|
1952
|
+
this.emit("jwt error" /* JWT_ERROR */, reason);
|
|
1953
|
+
throw new Error("Token expired");
|
|
1954
|
+
}
|
|
1955
|
+
break;
|
|
1676
1956
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
return data.attributes;
|
|
1687
|
-
};
|
|
1688
|
-
create = async (node) => {
|
|
1689
|
-
node = NodeCreateSchema.parse(node);
|
|
1690
|
-
const { data } = await this.r.post(
|
|
1691
|
-
"/nodes",
|
|
1692
|
-
node
|
|
1693
|
-
);
|
|
1694
|
-
return data.attributes;
|
|
1695
|
-
};
|
|
1696
|
-
get_configuration = async (id) => {
|
|
1697
|
-
import_zod9.default.number().positive().parse(id);
|
|
1957
|
+
default: {
|
|
1958
|
+
if (this.debugLogging) {
|
|
1959
|
+
console.warn("Unknown websocket event", message);
|
|
1960
|
+
}
|
|
1961
|
+
break;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
async refreshCredentials() {
|
|
1698
1966
|
const { data } = await this.r.get(
|
|
1699
|
-
`/
|
|
1700
|
-
);
|
|
1701
|
-
return data;
|
|
1702
|
-
};
|
|
1703
|
-
update = async (id, node) => {
|
|
1704
|
-
import_zod9.default.number().positive().parse(id);
|
|
1705
|
-
node = NodeCreateSchema.parse(node);
|
|
1706
|
-
const { data } = await this.r.patch(
|
|
1707
|
-
`/nodes/${id}`,
|
|
1708
|
-
node
|
|
1967
|
+
`/servers/${this.serverId}/websocket`
|
|
1709
1968
|
);
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
delete = async (id) => {
|
|
1713
|
-
import_zod9.default.number().positive().parse(id);
|
|
1714
|
-
await this.r.delete(`/nodes/${id}`);
|
|
1715
|
-
};
|
|
1716
|
-
allocations = (server_id) => new NodesAllocations(this.r, server_id);
|
|
1717
|
-
};
|
|
1718
|
-
var NodeCreateSchema = import_zod9.default.object({
|
|
1719
|
-
name: import_zod9.default.string().min(1).max(100),
|
|
1720
|
-
description: import_zod9.default.string().optional(),
|
|
1721
|
-
public: import_zod9.default.boolean().optional(),
|
|
1722
|
-
fqdn: import_zod9.default.string().nonempty(),
|
|
1723
|
-
scheme: import_zod9.default.enum(["http", "https"]),
|
|
1724
|
-
behind_proxy: import_zod9.default.boolean().optional(),
|
|
1725
|
-
memory: import_zod9.default.number().min(0),
|
|
1726
|
-
memory_overallocate: import_zod9.default.number().min(-1),
|
|
1727
|
-
disk: import_zod9.default.number().min(0),
|
|
1728
|
-
disk_overallocate: import_zod9.default.number().min(-1),
|
|
1729
|
-
cpu: import_zod9.default.number().min(0),
|
|
1730
|
-
cpu_overallocate: import_zod9.default.number().min(-1),
|
|
1731
|
-
daemon_base: import_zod9.default.string().nonempty().optional(),
|
|
1732
|
-
daemon_sftp: import_zod9.default.number().min(1).max(65535),
|
|
1733
|
-
daemon_sftp_alias: import_zod9.default.string().optional(),
|
|
1734
|
-
daemon_listen: import_zod9.default.number().min(1).max(65535),
|
|
1735
|
-
daemon_connect: import_zod9.default.number().min(1).max(65535),
|
|
1736
|
-
maintenance_mode: import_zod9.default.boolean().optional(),
|
|
1737
|
-
upload_size: import_zod9.default.number().min(1).max(1024),
|
|
1738
|
-
tags: import_zod9.default.array(import_zod9.default.string()).optional()
|
|
1739
|
-
});
|
|
1740
|
-
|
|
1741
|
-
// src/api/application/servers.ts
|
|
1742
|
-
var import_zod11 = __toESM(require("zod"));
|
|
1743
|
-
|
|
1744
|
-
// src/api/application/servers_databases.ts
|
|
1745
|
-
var import_zod10 = __toESM(require("zod"));
|
|
1746
|
-
var ServersDatabases = class {
|
|
1747
|
-
r;
|
|
1748
|
-
id;
|
|
1749
|
-
constructor(r, server_id) {
|
|
1750
|
-
this.r = r;
|
|
1751
|
-
this.id = server_id;
|
|
1969
|
+
this.currentToken = data.data.token;
|
|
1970
|
+
return data.data.socket;
|
|
1752
1971
|
}
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
info = async (database_id) => {
|
|
1763
|
-
const { data } = await this.r.get(`/servers/${this.id}/databases/${database_id}`);
|
|
1764
|
-
return data.attributes;
|
|
1765
|
-
};
|
|
1766
|
-
delete = async (database_id) => {
|
|
1767
|
-
await this.r.delete(`/servers/${this.id}/databases/${database_id}`);
|
|
1768
|
-
};
|
|
1769
|
-
resetPassword = async (database_id) => {
|
|
1770
|
-
await this.r.post(
|
|
1771
|
-
`/servers/${this.id}/databases/${database_id}/reset-password`
|
|
1972
|
+
async authenticate() {
|
|
1973
|
+
if (!this.socket) {
|
|
1974
|
+
throw new Error("No socket connection");
|
|
1975
|
+
}
|
|
1976
|
+
if (!this.currentToken) {
|
|
1977
|
+
throw new Error("Missing websocket token");
|
|
1978
|
+
}
|
|
1979
|
+
this.socket.send(
|
|
1980
|
+
JSON.stringify({ event: "auth", args: [this.currentToken] })
|
|
1772
1981
|
);
|
|
1773
|
-
};
|
|
1774
|
-
};
|
|
1775
|
-
|
|
1776
|
-
// src/api/application/servers.ts
|
|
1777
|
-
var Servers = class {
|
|
1778
|
-
r;
|
|
1779
|
-
id;
|
|
1780
|
-
databases;
|
|
1781
|
-
constructor(r, server_id) {
|
|
1782
|
-
this.r = r;
|
|
1783
|
-
this.id = server_id;
|
|
1784
|
-
this.databases = new ServersDatabases(this.r, this.id);
|
|
1785
1982
|
}
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
updateDetails = async (opts) => {
|
|
1794
|
-
opts = UpdateDetailsSchema.parse(opts);
|
|
1795
|
-
await this.r.patch(`/servers/${this.id}/details`, opts);
|
|
1796
|
-
};
|
|
1797
|
-
updateBuild = async (opts) => {
|
|
1798
|
-
opts = UpdateBuildSchema.parse(opts);
|
|
1799
|
-
await this.r.patch(`/servers/${this.id}/build`, opts);
|
|
1800
|
-
};
|
|
1801
|
-
updateStartup = async (opts) => {
|
|
1802
|
-
opts = UpdateStartupSchema.parse(opts);
|
|
1803
|
-
await this.r.patch(`/servers/${this.id}/startup`, opts);
|
|
1804
|
-
};
|
|
1805
|
-
suspend = async () => {
|
|
1806
|
-
await this.r.post(`/servers/${this.id}/suspend`);
|
|
1807
|
-
};
|
|
1808
|
-
unsuspend = async () => {
|
|
1809
|
-
await this.r.post(`/servers/${this.id}/unsuspend`);
|
|
1810
|
-
};
|
|
1811
|
-
reinstall = async () => {
|
|
1812
|
-
await this.r.post(`/servers/${this.id}/reinstall`);
|
|
1813
|
-
};
|
|
1814
|
-
transferStart = async (node_id, allocation_id, allocation_additional) => {
|
|
1815
|
-
await this.r.post(`/servers/${this.id}/transfer`, {
|
|
1816
|
-
node_id,
|
|
1817
|
-
allocation_id,
|
|
1818
|
-
allocation_additional
|
|
1819
|
-
});
|
|
1820
|
-
};
|
|
1821
|
-
transferCancel = async () => {
|
|
1822
|
-
await this.r.post(`/servers/${this.id}/transfer/cancel`);
|
|
1823
|
-
};
|
|
1824
|
-
};
|
|
1825
|
-
var CreateServerSchema = import_zod11.default.object({
|
|
1826
|
-
external_id: import_zod11.default.string().min(1).max(255).optional(),
|
|
1827
|
-
name: import_zod11.default.string().min(1).max(255),
|
|
1828
|
-
description: import_zod11.default.string().optional(),
|
|
1829
|
-
user: import_zod11.default.number(),
|
|
1830
|
-
egg: import_zod11.default.number(),
|
|
1831
|
-
docker_image: import_zod11.default.string().optional(),
|
|
1832
|
-
startup: import_zod11.default.string().optional(),
|
|
1833
|
-
environment: import_zod11.default.record(import_zod11.default.string(), import_zod11.default.string()),
|
|
1834
|
-
skip_scripts: import_zod11.default.boolean().optional(),
|
|
1835
|
-
oom_killer: import_zod11.default.boolean().optional(),
|
|
1836
|
-
start_on_completion: import_zod11.default.boolean().optional(),
|
|
1837
|
-
docker_labels: import_zod11.default.record(import_zod11.default.string(), import_zod11.default.string()).optional(),
|
|
1838
|
-
limits: import_zod11.default.object({
|
|
1839
|
-
memory: import_zod11.default.number().min(0),
|
|
1840
|
-
swap: import_zod11.default.number().min(-1),
|
|
1841
|
-
disk: import_zod11.default.number().min(0),
|
|
1842
|
-
io: import_zod11.default.number().min(0),
|
|
1843
|
-
threads: import_zod11.default.string().optional(),
|
|
1844
|
-
cpu: import_zod11.default.number().min(0)
|
|
1845
|
-
}),
|
|
1846
|
-
feature_limits: import_zod11.default.object({
|
|
1847
|
-
databases: import_zod11.default.number().min(0),
|
|
1848
|
-
allocations: import_zod11.default.number().min(0),
|
|
1849
|
-
backups: import_zod11.default.number().min(0)
|
|
1850
|
-
}),
|
|
1851
|
-
allocation: import_zod11.default.object({
|
|
1852
|
-
default: import_zod11.default.string(),
|
|
1853
|
-
additional: import_zod11.default.array(import_zod11.default.string()).optional()
|
|
1854
|
-
}).optional(),
|
|
1855
|
-
deploy: import_zod11.default.object({
|
|
1856
|
-
tags: import_zod11.default.array(import_zod11.default.string()).optional(),
|
|
1857
|
-
dedicated_ip: import_zod11.default.boolean().optional(),
|
|
1858
|
-
port_range: import_zod11.default.array(import_zod11.default.string()).optional()
|
|
1859
|
-
}).optional()
|
|
1860
|
-
});
|
|
1861
|
-
var UpdateDetailsSchema = CreateServerSchema.pick({
|
|
1862
|
-
external_id: true,
|
|
1863
|
-
name: true,
|
|
1864
|
-
user: true,
|
|
1865
|
-
description: true,
|
|
1866
|
-
docker_labels: true
|
|
1867
|
-
});
|
|
1868
|
-
var UpdateBuildSchema = CreateServerSchema.pick({
|
|
1869
|
-
oom_killer: true,
|
|
1870
|
-
limits: true,
|
|
1871
|
-
feature_limits: true
|
|
1872
|
-
}).extend({
|
|
1873
|
-
allocation: import_zod11.default.number().optional(),
|
|
1874
|
-
add_allocations: import_zod11.default.array(import_zod11.default.string()).optional(),
|
|
1875
|
-
remove_allocations: import_zod11.default.array(import_zod11.default.string()).optional()
|
|
1876
|
-
});
|
|
1877
|
-
var UpdateStartupSchema = CreateServerSchema.pick({
|
|
1878
|
-
startup: true,
|
|
1879
|
-
environment: true,
|
|
1880
|
-
egg: true
|
|
1881
|
-
}).extend({ image: import_zod11.default.string().optional(), skip_scripts: import_zod11.default.boolean() });
|
|
1882
|
-
|
|
1883
|
-
// src/api/application/database_hosts.ts
|
|
1884
|
-
var import_zod12 = __toESM(require("zod"));
|
|
1885
|
-
var DatabaseHosts = class {
|
|
1886
|
-
r;
|
|
1887
|
-
constructor(r) {
|
|
1888
|
-
this.r = r;
|
|
1983
|
+
disconnect() {
|
|
1984
|
+
this.detachMessageListener?.();
|
|
1985
|
+
this.detachMessageListener = void 0;
|
|
1986
|
+
if (this.socket) {
|
|
1987
|
+
this.socket.close();
|
|
1988
|
+
this.socket = void 0;
|
|
1989
|
+
}
|
|
1889
1990
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
return data.data.map((d) => d.attributes);
|
|
1893
|
-
};
|
|
1894
|
-
info = async (id) => {
|
|
1895
|
-
const { data } = await this.r.get(`/database-hosts/${id}`);
|
|
1896
|
-
return data.attributes;
|
|
1897
|
-
};
|
|
1898
|
-
// TODO: find out why API returns 500
|
|
1899
|
-
create = async (opts) => {
|
|
1900
|
-
opts = CreateDBHostSchema.parse(opts);
|
|
1901
|
-
await this.r.post(
|
|
1902
|
-
"/database-hosts",
|
|
1903
|
-
opts
|
|
1904
|
-
).catch((e) => {
|
|
1905
|
-
});
|
|
1906
|
-
};
|
|
1907
|
-
update = async (id, opts) => {
|
|
1908
|
-
opts = CreateDBHostSchema.parse(opts);
|
|
1909
|
-
const { data } = await this.r.patch(`/database-hosts/${id}`, opts);
|
|
1910
|
-
return data.attributes;
|
|
1911
|
-
};
|
|
1912
|
-
delete = async (id) => {
|
|
1913
|
-
await this.r.delete(`/database-hosts/${id}`);
|
|
1914
|
-
};
|
|
1915
|
-
};
|
|
1916
|
-
var CreateDBHostSchema = import_zod12.default.object({
|
|
1917
|
-
name: import_zod12.default.string().min(1).max(255),
|
|
1918
|
-
host: import_zod12.default.string(),
|
|
1919
|
-
port: import_zod12.default.number().min(1).max(65535),
|
|
1920
|
-
username: import_zod12.default.string().min(1).max(255),
|
|
1921
|
-
password: import_zod12.default.string().optional(),
|
|
1922
|
-
node_ids: import_zod12.default.array(import_zod12.default.string()).optional(),
|
|
1923
|
-
max_databases: import_zod12.default.number().optional()
|
|
1924
|
-
});
|
|
1925
|
-
|
|
1926
|
-
// src/api/application/roles.ts
|
|
1927
|
-
var Roles = class {
|
|
1928
|
-
r;
|
|
1929
|
-
constructor(r) {
|
|
1930
|
-
this.r = r;
|
|
1991
|
+
requestStats() {
|
|
1992
|
+
this.send("send stats", [null]);
|
|
1931
1993
|
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
update = async (id, opts) => {
|
|
1946
|
-
await this.r.patch(`/roles/${id}`, opts);
|
|
1947
|
-
};
|
|
1948
|
-
delete = async (id) => {
|
|
1949
|
-
await this.r.delete(`/roles/${id}`);
|
|
1950
|
-
};
|
|
1951
|
-
};
|
|
1952
|
-
|
|
1953
|
-
// src/api/application/eggs.ts
|
|
1954
|
-
var Eggs = class {
|
|
1955
|
-
r;
|
|
1956
|
-
constructor(r) {
|
|
1957
|
-
this.r = r;
|
|
1994
|
+
requestLogs() {
|
|
1995
|
+
this.send("send logs", [null]);
|
|
1996
|
+
}
|
|
1997
|
+
send(event, args) {
|
|
1998
|
+
if (!this.socket) {
|
|
1999
|
+
if (this.debugLogging) {
|
|
2000
|
+
console.warn(
|
|
2001
|
+
`Attempted to send "${event}" without an active websocket connection`
|
|
2002
|
+
);
|
|
2003
|
+
}
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
this.socket.send(JSON.stringify({ event, args }));
|
|
1958
2007
|
}
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
2008
|
+
getStats() {
|
|
2009
|
+
return new Promise((resolve, reject) => {
|
|
2010
|
+
if (!this.socket) {
|
|
2011
|
+
reject(new Error("No socket connection"));
|
|
2012
|
+
return;
|
|
2013
|
+
}
|
|
2014
|
+
let off;
|
|
2015
|
+
const timeout = setTimeout(() => {
|
|
2016
|
+
off?.();
|
|
2017
|
+
reject(new Error("Timed out waiting for stats"));
|
|
2018
|
+
}, 5e3);
|
|
2019
|
+
off = this.on("stats" /* STATS */, (payload) => {
|
|
2020
|
+
clearTimeout(timeout);
|
|
2021
|
+
off?.();
|
|
2022
|
+
resolve(payload);
|
|
2023
|
+
});
|
|
2024
|
+
this.requestStats();
|
|
1975
2025
|
});
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2026
|
+
}
|
|
2027
|
+
getLogs() {
|
|
2028
|
+
return new Promise((resolve, reject) => {
|
|
2029
|
+
if (!this.socket) {
|
|
2030
|
+
reject(new Error("No socket connection"));
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
const lines = [];
|
|
2034
|
+
let off;
|
|
2035
|
+
let initialTimeout;
|
|
2036
|
+
let idleTimeout;
|
|
2037
|
+
const finalize = (payload) => {
|
|
2038
|
+
off?.();
|
|
2039
|
+
if (initialTimeout) {
|
|
2040
|
+
clearTimeout(initialTimeout);
|
|
2041
|
+
}
|
|
2042
|
+
if (idleTimeout) {
|
|
2043
|
+
clearTimeout(idleTimeout);
|
|
2044
|
+
}
|
|
2045
|
+
resolve(payload);
|
|
2046
|
+
};
|
|
2047
|
+
initialTimeout = setTimeout(() => {
|
|
2048
|
+
finalize(lines.length > 0 ? lines : [FALLBACK_LOG_MESSAGE]);
|
|
2049
|
+
}, 5e3);
|
|
2050
|
+
off = this.on("console output" /* CONSOLE_OUTPUT */, (line) => {
|
|
2051
|
+
lines.push(line);
|
|
2052
|
+
if (initialTimeout) {
|
|
2053
|
+
clearTimeout(initialTimeout);
|
|
2054
|
+
initialTimeout = void 0;
|
|
2055
|
+
}
|
|
2056
|
+
if (idleTimeout) {
|
|
2057
|
+
clearTimeout(idleTimeout);
|
|
2058
|
+
}
|
|
2059
|
+
idleTimeout = setTimeout(() => {
|
|
2060
|
+
finalize(lines);
|
|
2061
|
+
}, 1e3);
|
|
2062
|
+
});
|
|
2063
|
+
this.requestLogs();
|
|
1981
2064
|
});
|
|
1982
|
-
|
|
1983
|
-
|
|
2065
|
+
}
|
|
2066
|
+
sendPoweraction(action) {
|
|
2067
|
+
this.send("set state", [action]);
|
|
2068
|
+
}
|
|
2069
|
+
sendCommand(cmd) {
|
|
2070
|
+
this.send("send command", [cmd]);
|
|
2071
|
+
}
|
|
1984
2072
|
};
|
|
1985
2073
|
|
|
1986
|
-
// src/api/
|
|
1987
|
-
var
|
|
1988
|
-
var Mounts = class {
|
|
2074
|
+
// src/api/client/server.ts
|
|
2075
|
+
var ServerClient = class {
|
|
1989
2076
|
r;
|
|
1990
|
-
|
|
1991
|
-
|
|
2077
|
+
id;
|
|
2078
|
+
activity;
|
|
2079
|
+
databases;
|
|
2080
|
+
files;
|
|
2081
|
+
schedules;
|
|
2082
|
+
allocations;
|
|
2083
|
+
users;
|
|
2084
|
+
backups;
|
|
2085
|
+
startup;
|
|
2086
|
+
variables;
|
|
2087
|
+
settings;
|
|
2088
|
+
constructor(requester, id) {
|
|
2089
|
+
this.r = requester;
|
|
2090
|
+
this.id = id;
|
|
2091
|
+
this.activity = new ServerActivity(requester, id);
|
|
2092
|
+
this.databases = new ServerDatabases(requester, id);
|
|
2093
|
+
this.files = new ServerFiles(requester, id);
|
|
2094
|
+
this.schedules = new ServerSchedules(requester, id);
|
|
2095
|
+
this.allocations = new ServerAllocations(requester, id);
|
|
2096
|
+
this.users = new ServerUsers(requester, id);
|
|
2097
|
+
this.backups = new ServerBackups(requester, id);
|
|
2098
|
+
this.startup = new ServerStartup(requester, id);
|
|
2099
|
+
this.variables = this.startup;
|
|
2100
|
+
this.settings = new ServerSettings(requester, id);
|
|
1992
2101
|
}
|
|
1993
|
-
|
|
1994
|
-
const { data } = await this.r.get("/mounts");
|
|
1995
|
-
return data.data.map((d) => d.attributes);
|
|
1996
|
-
};
|
|
1997
|
-
info = async (id) => {
|
|
2102
|
+
info = async (include) => {
|
|
1998
2103
|
const { data } = await this.r.get(
|
|
1999
|
-
`/
|
|
2104
|
+
`/servers/${this.id}`,
|
|
2105
|
+
{ params: { include: include?.join(",") } }
|
|
2000
2106
|
);
|
|
2001
2107
|
return data.attributes;
|
|
2002
2108
|
};
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
const { data } = await this.r.post(
|
|
2006
|
-
"/mounts",
|
|
2007
|
-
opts
|
|
2008
|
-
);
|
|
2009
|
-
return data.attributes;
|
|
2109
|
+
websocket = (stripColors = false) => {
|
|
2110
|
+
return new ServerWebsocket(this.r, this.id, stripColors);
|
|
2010
2111
|
};
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
`/mounts/${id}`,
|
|
2015
|
-
opts
|
|
2112
|
+
resources = async () => {
|
|
2113
|
+
const { data } = await this.r.get(
|
|
2114
|
+
`/servers/${this.id}/resources`
|
|
2016
2115
|
);
|
|
2017
2116
|
return data.attributes;
|
|
2018
2117
|
};
|
|
2019
|
-
|
|
2020
|
-
await this.r.
|
|
2021
|
-
};
|
|
2022
|
-
listAssignedEggs = async (id) => {
|
|
2023
|
-
const { data } = await this.r.get(`/mounts/${id}/eggs`);
|
|
2024
|
-
return data.data.map((d) => d.attributes);
|
|
2025
|
-
};
|
|
2026
|
-
assignEggs = async (id, eggs) => {
|
|
2027
|
-
await this.r.post(`/mounts/${id}/eggs`, { eggs });
|
|
2028
|
-
};
|
|
2029
|
-
unassignEgg = async (id, egg_id) => {
|
|
2030
|
-
await this.r.delete(`/mounts/${id}/eggs/${egg_id}`);
|
|
2031
|
-
};
|
|
2032
|
-
listAssignedNodes = async (id) => {
|
|
2033
|
-
const { data } = await this.r.get(`/mounts/${id}/nodes`);
|
|
2034
|
-
return data.data.map((d) => d.attributes);
|
|
2035
|
-
};
|
|
2036
|
-
assignNodes = async (id, nodes) => {
|
|
2037
|
-
await this.r.post(`/mounts/${id}/nodes`, { nodes });
|
|
2038
|
-
};
|
|
2039
|
-
unassignNode = async (id, node_id) => {
|
|
2040
|
-
await this.r.delete(`/mounts/${id}/nodes/${node_id}`);
|
|
2041
|
-
};
|
|
2042
|
-
listAssignedServers = async (id) => {
|
|
2043
|
-
const { data } = await this.r.get(`/mounts/${id}/servers`);
|
|
2044
|
-
return data.data.map((d) => d.attributes);
|
|
2045
|
-
};
|
|
2046
|
-
assignServers = async (id, servers) => {
|
|
2047
|
-
await this.r.post(`/mounts/${id}/servers`, { servers });
|
|
2118
|
+
command = async (command) => {
|
|
2119
|
+
await this.r.post(`/servers/${this.id}/command`, { command });
|
|
2048
2120
|
};
|
|
2049
|
-
|
|
2050
|
-
await this.r.
|
|
2121
|
+
power = async (signal) => {
|
|
2122
|
+
await this.r.post(`/servers/${this.id}/power`, { signal });
|
|
2051
2123
|
};
|
|
2052
2124
|
};
|
|
2053
|
-
var CreateMountSchema = import_zod13.default.object({
|
|
2054
|
-
name: import_zod13.default.string().min(1).max(255),
|
|
2055
|
-
description: import_zod13.default.string().optional(),
|
|
2056
|
-
source: import_zod13.default.string(),
|
|
2057
|
-
target: import_zod13.default.string(),
|
|
2058
|
-
read_only: import_zod13.default.boolean().optional()
|
|
2059
|
-
});
|
|
2060
2125
|
|
|
2061
|
-
// src/api/
|
|
2126
|
+
// src/api/client/client.ts
|
|
2062
2127
|
var Client2 = class {
|
|
2128
|
+
account;
|
|
2063
2129
|
r;
|
|
2064
|
-
users;
|
|
2065
|
-
nodes;
|
|
2066
|
-
databaseHosts;
|
|
2067
|
-
roles;
|
|
2068
|
-
eggs;
|
|
2069
|
-
mounts;
|
|
2070
2130
|
constructor(requester) {
|
|
2071
2131
|
this.r = requester;
|
|
2072
|
-
this.
|
|
2073
|
-
this.nodes = new Nodes(requester);
|
|
2074
|
-
this.databaseHosts = new DatabaseHosts(requester);
|
|
2075
|
-
this.roles = new Roles(requester);
|
|
2076
|
-
this.eggs = new Eggs(requester);
|
|
2077
|
-
this.mounts = new Mounts(requester);
|
|
2132
|
+
this.account = new Account(requester);
|
|
2078
2133
|
}
|
|
2079
2134
|
get $r() {
|
|
2080
2135
|
return this.r;
|
|
2081
2136
|
}
|
|
2082
|
-
|
|
2083
|
-
const { data } = await this.r.get("/
|
|
2084
|
-
return data.
|
|
2085
|
-
};
|
|
2086
|
-
createServer = async (opts) => {
|
|
2087
|
-
opts = CreateServerSchema.parse(opts);
|
|
2088
|
-
const { data } = await this.r.post("/servers", opts);
|
|
2089
|
-
return data.attributes;
|
|
2137
|
+
listPermissions = async () => {
|
|
2138
|
+
const { data } = await this.r.get("/permissions");
|
|
2139
|
+
return data.attributes.permissions;
|
|
2090
2140
|
};
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
return data.attributes;
|
|
2141
|
+
listServers = async (type = "accessible", page = 1, per_page = 50, include) => {
|
|
2142
|
+
import_zod14.default.number().positive().parse(page);
|
|
2143
|
+
const { data } = await this.r.get("/", { params: { type, page, include: include?.join(",") } });
|
|
2144
|
+
return data.data.map((s) => s.attributes);
|
|
2096
2145
|
};
|
|
2097
|
-
|
|
2098
|
-
};
|
|
2099
|
-
|
|
2100
|
-
// src/api/base/request.ts
|
|
2101
|
-
var import_zod14 = __toESM(require("zod"));
|
|
2102
|
-
var import_axios3 = __toESM(require("axios"));
|
|
2103
|
-
|
|
2104
|
-
// src/api/base/types.ts
|
|
2105
|
-
var PterodactylException = class extends Error {
|
|
2106
|
-
data;
|
|
2107
|
-
status;
|
|
2108
|
-
constructor(message, data, status) {
|
|
2109
|
-
super(message);
|
|
2110
|
-
this.data = data;
|
|
2111
|
-
this.status = status;
|
|
2112
|
-
}
|
|
2113
|
-
};
|
|
2114
|
-
|
|
2115
|
-
// src/api/base/request.ts
|
|
2116
|
-
var Agent = class {
|
|
2117
|
-
base_url;
|
|
2118
|
-
token;
|
|
2119
|
-
requester;
|
|
2120
|
-
constructor(url, token, type, suffix = "/api") {
|
|
2121
|
-
this.base_url = import_zod14.default.url("Invalid URL Schema").transform((url2) => new URL(url2).href).parse(url);
|
|
2122
|
-
this.token = import_zod14.default.string().regex(/^(ptl[ac]|pacc|papp)_.+$/, "Invalid token type").parse(token);
|
|
2123
|
-
this.requester = import_axios3.default.create({
|
|
2124
|
-
baseURL: this.base_url.replace(/\/+$/, "") + `${suffix}/${type}`,
|
|
2125
|
-
timeout: 3e3,
|
|
2126
|
-
headers: { Authorization: `Bearer ${this.token}` }
|
|
2127
|
-
});
|
|
2128
|
-
this.requester.interceptors.response.use(void 0, (error) => {
|
|
2129
|
-
if (error.response && error.response.status === 400) {
|
|
2130
|
-
return Promise.reject(
|
|
2131
|
-
new PterodactylException(
|
|
2132
|
-
"Invalid request data",
|
|
2133
|
-
error.response.data,
|
|
2134
|
-
error.response.status
|
|
2135
|
-
)
|
|
2136
|
-
);
|
|
2137
|
-
}
|
|
2138
|
-
return Promise.reject(error);
|
|
2139
|
-
});
|
|
2140
|
-
}
|
|
2146
|
+
server = (uuid) => new ServerClient(this.r, uuid);
|
|
2141
2147
|
};
|
|
2142
2148
|
|
|
2143
2149
|
// src/api/index.ts
|
|
2144
|
-
var PelicanAPIClient = class extends
|
|
2150
|
+
var PelicanAPIClient = class extends Client2 {
|
|
2145
2151
|
constructor(url, token, suffix = "/api") {
|
|
2146
2152
|
const ax = new Agent(url, token, "client", suffix);
|
|
2147
2153
|
super(ax.requester);
|
|
2148
2154
|
}
|
|
2149
2155
|
};
|
|
2150
|
-
var PelicanAPIApplication = class extends
|
|
2156
|
+
var PelicanAPIApplication = class extends Client {
|
|
2151
2157
|
constructor(url, token, suffix = "/api") {
|
|
2152
2158
|
const ax = new Agent(url, token, "application", suffix);
|
|
2153
2159
|
super(ax.requester);
|