@pelican.ts/sdk 0.4.14 → 0.4.16-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +127 -0
- package/README.md +5 -4
- package/bun.lock +40 -0
- package/dist/api/index.d.mts +778 -787
- package/dist/api/index.d.ts +778 -787
- package/dist/api/index.js +1536 -1534
- package/dist/api/index.mjs +1536 -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 +251 -260
- package/package.json +3 -1
package/dist/api/index.js
CHANGED
|
@@ -35,1099 +35,584 @@ __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 (include) => {
|
|
202
|
+
const { data } = await this.r.get(`/nodes/${this.id}/allocations`, {
|
|
203
|
+
params: { include: include?.join(",") }
|
|
204
|
+
});
|
|
226
205
|
return data.data.map((d) => d.attributes);
|
|
227
206
|
};
|
|
228
|
-
create = async (
|
|
229
|
-
|
|
230
|
-
|
|
207
|
+
create = async (ip, ports, alias) => {
|
|
208
|
+
import_zod3.default.ipv4().parse(ip);
|
|
209
|
+
import_zod3.default.ipv4().or(import_zod3.default.url().max(255)).optional().parse(alias);
|
|
210
|
+
import_zod3.default.array(import_zod3.default.number()).or(import_zod3.default.string().regex(/\d+-\d+/)).parse(ports);
|
|
211
|
+
await this.r.post(`/nodes/${this.id}/allocations`, { ip, ports, alias });
|
|
212
|
+
};
|
|
213
|
+
delete = async (alloc_id) => {
|
|
214
|
+
await this.r.delete(`/nodes/${this.id}/allocations/${alloc_id}`);
|
|
231
215
|
};
|
|
232
|
-
control = (sched_id) => new ScheduleControl(this.r, this.id, sched_id);
|
|
233
216
|
};
|
|
234
|
-
|
|
217
|
+
|
|
218
|
+
// src/api/application/nodes.ts
|
|
219
|
+
var Nodes = class {
|
|
235
220
|
r;
|
|
236
|
-
|
|
237
|
-
sched_id;
|
|
238
|
-
constructor(requester, id, sched_id) {
|
|
221
|
+
constructor(requester) {
|
|
239
222
|
this.r = requester;
|
|
240
|
-
this.id = id;
|
|
241
|
-
this.sched_id = sched_id;
|
|
242
223
|
}
|
|
243
|
-
|
|
244
|
-
|
|
224
|
+
list = async (include, page = 1) => {
|
|
225
|
+
import_zod4.default.number().positive().parse(page);
|
|
226
|
+
const { data } = await this.r.get("/nodes", { params: { include: include?.join(","), page } });
|
|
227
|
+
return data.data.map((s) => s.attributes);
|
|
228
|
+
};
|
|
229
|
+
listDeployable = async (filters, include, page = 1) => {
|
|
230
|
+
import_zod4.default.number().positive().parse(page);
|
|
231
|
+
const { data } = await this.r.get("/nodes/deployable", {
|
|
232
|
+
params: {
|
|
233
|
+
include: include?.join(","),
|
|
234
|
+
disk: filters.disk,
|
|
235
|
+
memory: filters.memory,
|
|
236
|
+
cpu: filters.cpu,
|
|
237
|
+
location_ids: filters.location_ids,
|
|
238
|
+
tags: filters.tags,
|
|
239
|
+
page
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
return data.data.map((s) => s.attributes);
|
|
243
|
+
};
|
|
244
|
+
info = async (id, include) => {
|
|
245
|
+
import_zod4.default.number().positive().parse(id);
|
|
246
|
+
const { data } = await this.r.get(
|
|
247
|
+
`/nodes/${id}`,
|
|
248
|
+
{ params: { include: include?.join(",") } }
|
|
249
|
+
);
|
|
245
250
|
return data.attributes;
|
|
246
251
|
};
|
|
247
|
-
|
|
248
|
-
|
|
252
|
+
create = async (node) => {
|
|
253
|
+
node = NodeCreateSchema.parse(node);
|
|
254
|
+
const { data } = await this.r.post(
|
|
255
|
+
"/nodes",
|
|
256
|
+
node
|
|
257
|
+
);
|
|
249
258
|
return data.attributes;
|
|
250
259
|
};
|
|
251
|
-
|
|
252
|
-
|
|
260
|
+
get_configuration = async (id) => {
|
|
261
|
+
import_zod4.default.number().positive().parse(id);
|
|
262
|
+
const { data } = await this.r.get(
|
|
263
|
+
`/nodes/${id}/configuration`
|
|
264
|
+
);
|
|
265
|
+
return data;
|
|
253
266
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
267
|
+
update = async (id, node) => {
|
|
268
|
+
import_zod4.default.number().positive().parse(id);
|
|
269
|
+
node = NodeCreateSchema.parse(node);
|
|
270
|
+
const { data } = await this.r.patch(
|
|
271
|
+
`/nodes/${id}`,
|
|
272
|
+
node
|
|
257
273
|
);
|
|
274
|
+
return data.attributes;
|
|
258
275
|
};
|
|
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
|
-
}
|
|
276
|
+
delete = async (id) => {
|
|
277
|
+
import_zod4.default.number().positive().parse(id);
|
|
278
|
+
await this.r.delete(`/nodes/${id}`);
|
|
276
279
|
};
|
|
280
|
+
allocations = (server_id) => new NodesAllocations(this.r, server_id);
|
|
277
281
|
};
|
|
282
|
+
var NodeCreateSchema = import_zod4.default.object({
|
|
283
|
+
name: import_zod4.default.string().min(1).max(100),
|
|
284
|
+
description: import_zod4.default.string().optional(),
|
|
285
|
+
public: import_zod4.default.boolean().optional(),
|
|
286
|
+
fqdn: import_zod4.default.string().nonempty(),
|
|
287
|
+
scheme: import_zod4.default.enum(["http", "https"]),
|
|
288
|
+
behind_proxy: import_zod4.default.boolean().optional(),
|
|
289
|
+
memory: import_zod4.default.number().min(0),
|
|
290
|
+
memory_overallocate: import_zod4.default.number().min(-1),
|
|
291
|
+
disk: import_zod4.default.number().min(0),
|
|
292
|
+
disk_overallocate: import_zod4.default.number().min(-1),
|
|
293
|
+
cpu: import_zod4.default.number().min(0),
|
|
294
|
+
cpu_overallocate: import_zod4.default.number().min(-1),
|
|
295
|
+
daemon_base: import_zod4.default.string().nonempty().optional(),
|
|
296
|
+
daemon_sftp: import_zod4.default.number().min(1).max(65535),
|
|
297
|
+
daemon_sftp_alias: import_zod4.default.string().optional(),
|
|
298
|
+
daemon_listen: import_zod4.default.number().min(1).max(65535),
|
|
299
|
+
daemon_connect: import_zod4.default.number().min(1).max(65535),
|
|
300
|
+
maintenance_mode: import_zod4.default.boolean().optional(),
|
|
301
|
+
upload_size: import_zod4.default.number().min(1).max(1024),
|
|
302
|
+
tags: import_zod4.default.array(import_zod4.default.string()).optional()
|
|
303
|
+
});
|
|
278
304
|
|
|
279
|
-
// src/api/
|
|
280
|
-
var
|
|
305
|
+
// src/api/application/roles.ts
|
|
306
|
+
var Roles = class {
|
|
281
307
|
r;
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.r = requester;
|
|
285
|
-
this.id = id;
|
|
308
|
+
constructor(r) {
|
|
309
|
+
this.r = r;
|
|
286
310
|
}
|
|
287
|
-
list = async () => {
|
|
288
|
-
const { data } = await this.r.get(`/
|
|
311
|
+
list = async (page = 1) => {
|
|
312
|
+
const { data } = await this.r.get(`/roles`, { params: { page } });
|
|
289
313
|
return data.data.map((r) => r.attributes);
|
|
290
314
|
};
|
|
291
|
-
|
|
292
|
-
const { data } = await this.r.
|
|
315
|
+
info = async (id) => {
|
|
316
|
+
const { data } = await this.r.get(
|
|
317
|
+
`/roles/${id}`
|
|
318
|
+
);
|
|
293
319
|
return data.attributes;
|
|
294
320
|
};
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
return data.attributes;
|
|
321
|
+
create = async (opts) => {
|
|
322
|
+
await this.r.post(`/roles`, opts);
|
|
298
323
|
};
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return data.attributes;
|
|
324
|
+
update = async (id, opts) => {
|
|
325
|
+
await this.r.patch(`/roles/${id}`, opts);
|
|
302
326
|
};
|
|
303
|
-
|
|
304
|
-
await this.r.delete(
|
|
305
|
-
`/servers/${this.id}/network/allocations/${alloc_id}`
|
|
306
|
-
);
|
|
327
|
+
delete = async (id) => {
|
|
328
|
+
await this.r.delete(`/roles/${id}`);
|
|
307
329
|
};
|
|
308
330
|
};
|
|
309
331
|
|
|
310
|
-
// src/api/
|
|
311
|
-
var
|
|
332
|
+
// src/api/application/servers.ts
|
|
333
|
+
var import_zod6 = __toESM(require("zod"));
|
|
334
|
+
|
|
335
|
+
// src/api/application/servers_databases.ts
|
|
336
|
+
var import_zod5 = __toESM(require("zod"));
|
|
337
|
+
var ServersDatabases = class {
|
|
312
338
|
r;
|
|
313
339
|
id;
|
|
314
|
-
constructor(
|
|
315
|
-
this.r =
|
|
316
|
-
this.id =
|
|
340
|
+
constructor(r, server_id) {
|
|
341
|
+
this.r = r;
|
|
342
|
+
this.id = server_id;
|
|
317
343
|
}
|
|
318
344
|
list = async () => {
|
|
319
|
-
const { data } = await this.r.get(`/servers/${this.id}/
|
|
345
|
+
const { data } = await this.r.get(`/servers/${this.id}/databases`);
|
|
320
346
|
return data.data.map((d) => d.attributes);
|
|
321
347
|
};
|
|
322
|
-
create = async (
|
|
323
|
-
|
|
348
|
+
create = async (database, remote, host) => {
|
|
349
|
+
database = import_zod5.default.string().min(1).max(48).parse(database);
|
|
350
|
+
const { data } = await this.r.post(`/servers/${this.id}/databases`, { database, remote, host });
|
|
324
351
|
return data.attributes;
|
|
325
352
|
};
|
|
326
|
-
info = async (
|
|
327
|
-
const { data } = await this.r.get(
|
|
328
|
-
`/servers/${this.id}/users/${user_uuid}`
|
|
329
|
-
);
|
|
353
|
+
info = async (database_id) => {
|
|
354
|
+
const { data } = await this.r.get(`/servers/${this.id}/databases/${database_id}`);
|
|
330
355
|
return data.attributes;
|
|
331
356
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
`/servers/${this.id}/users/${user_uuid}`,
|
|
335
|
-
{ permissions }
|
|
336
|
-
);
|
|
337
|
-
return data.attributes;
|
|
357
|
+
delete = async (database_id) => {
|
|
358
|
+
await this.r.delete(`/servers/${this.id}/databases/${database_id}`);
|
|
338
359
|
};
|
|
339
|
-
|
|
340
|
-
await this.r.
|
|
360
|
+
resetPassword = async (database_id) => {
|
|
361
|
+
await this.r.post(
|
|
362
|
+
`/servers/${this.id}/databases/${database_id}/reset-password`
|
|
363
|
+
);
|
|
341
364
|
};
|
|
342
365
|
};
|
|
343
366
|
|
|
344
|
-
// src/api/
|
|
345
|
-
var
|
|
346
|
-
var import_zod3 = __toESM(require("zod"));
|
|
347
|
-
var ServerBackups = class {
|
|
367
|
+
// src/api/application/servers.ts
|
|
368
|
+
var Servers = class {
|
|
348
369
|
r;
|
|
349
370
|
id;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
this.
|
|
371
|
+
databases;
|
|
372
|
+
constructor(r, server_id) {
|
|
373
|
+
this.r = r;
|
|
374
|
+
this.id = server_id;
|
|
375
|
+
this.databases = new ServersDatabases(this.r, this.id);
|
|
353
376
|
}
|
|
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
|
-
});
|
|
377
|
+
info = async (include) => {
|
|
378
|
+
const { data } = await this.r.get(`/servers/${this.id}`, { params: { include: include?.join(",") } });
|
|
366
379
|
return data.attributes;
|
|
367
380
|
};
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
return data.attributes;
|
|
381
|
+
delete = async (force = false) => {
|
|
382
|
+
await this.r.delete(`/servers/${this.id}${force ? "/force" : ""}`);
|
|
371
383
|
};
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
384
|
+
updateDetails = async (opts) => {
|
|
385
|
+
opts = UpdateDetailsSchema.parse(opts);
|
|
386
|
+
await this.r.patch(`/servers/${this.id}/details`, opts);
|
|
375
387
|
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
responseType: "arraybuffer"
|
|
380
|
-
});
|
|
381
|
-
return data;
|
|
388
|
+
updateBuild = async (opts) => {
|
|
389
|
+
opts = UpdateBuildSchema.parse(opts);
|
|
390
|
+
await this.r.patch(`/servers/${this.id}/build`, opts);
|
|
382
391
|
};
|
|
383
|
-
|
|
384
|
-
|
|
392
|
+
updateStartup = async (opts) => {
|
|
393
|
+
opts = UpdateStartupSchema.parse(opts);
|
|
394
|
+
await this.r.patch(`/servers/${this.id}/startup`, opts);
|
|
385
395
|
};
|
|
386
|
-
|
|
387
|
-
await this.r.
|
|
388
|
-
name
|
|
389
|
-
});
|
|
396
|
+
suspend = async () => {
|
|
397
|
+
await this.r.post(`/servers/${this.id}/suspend`);
|
|
390
398
|
};
|
|
391
|
-
|
|
392
|
-
await this.r.post(`/servers/${this.id}/
|
|
399
|
+
unsuspend = async () => {
|
|
400
|
+
await this.r.post(`/servers/${this.id}/unsuspend`);
|
|
393
401
|
};
|
|
394
|
-
|
|
395
|
-
await this.r.post(
|
|
396
|
-
`/servers/${this.id}/backups/${backup_uuid}/restore`,
|
|
397
|
-
{ truncate }
|
|
398
|
-
);
|
|
402
|
+
reinstall = async () => {
|
|
403
|
+
await this.r.post(`/servers/${this.id}/reinstall`);
|
|
399
404
|
};
|
|
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
|
-
};
|
|
405
|
+
transferStart = async (node_id, allocation_id, allocation_additional) => {
|
|
406
|
+
await this.r.post(`/servers/${this.id}/transfer`, {
|
|
407
|
+
node_id,
|
|
408
|
+
allocation_id,
|
|
409
|
+
allocation_additional
|
|
410
|
+
});
|
|
417
411
|
};
|
|
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
|
-
});
|
|
412
|
+
transferCancel = async () => {
|
|
413
|
+
await this.r.post(`/servers/${this.id}/transfer/cancel`);
|
|
449
414
|
};
|
|
450
415
|
};
|
|
416
|
+
var CreateServerSchema = import_zod6.default.object({
|
|
417
|
+
external_id: import_zod6.default.string().min(1).max(255).optional(),
|
|
418
|
+
name: import_zod6.default.string().min(1).max(255),
|
|
419
|
+
description: import_zod6.default.string().optional(),
|
|
420
|
+
user: import_zod6.default.number(),
|
|
421
|
+
egg: import_zod6.default.number(),
|
|
422
|
+
docker_image: import_zod6.default.string().optional(),
|
|
423
|
+
startup: import_zod6.default.string().optional(),
|
|
424
|
+
environment: import_zod6.default.record(import_zod6.default.string(), import_zod6.default.string()),
|
|
425
|
+
skip_scripts: import_zod6.default.boolean().optional(),
|
|
426
|
+
oom_killer: import_zod6.default.boolean().optional(),
|
|
427
|
+
start_on_completion: import_zod6.default.boolean().optional(),
|
|
428
|
+
docker_labels: import_zod6.default.record(import_zod6.default.string(), import_zod6.default.string()).optional(),
|
|
429
|
+
limits: import_zod6.default.object({
|
|
430
|
+
memory: import_zod6.default.number().min(0),
|
|
431
|
+
swap: import_zod6.default.number().min(-1),
|
|
432
|
+
disk: import_zod6.default.number().min(0),
|
|
433
|
+
io: import_zod6.default.number().min(0),
|
|
434
|
+
threads: import_zod6.default.string().optional(),
|
|
435
|
+
cpu: import_zod6.default.number().min(0)
|
|
436
|
+
}),
|
|
437
|
+
feature_limits: import_zod6.default.object({
|
|
438
|
+
databases: import_zod6.default.number().min(0),
|
|
439
|
+
allocations: import_zod6.default.number().min(0),
|
|
440
|
+
backups: import_zod6.default.number().min(0)
|
|
441
|
+
}),
|
|
442
|
+
allocation: import_zod6.default.object({
|
|
443
|
+
default: import_zod6.default.string().nullable(),
|
|
444
|
+
additional: import_zod6.default.array(import_zod6.default.string()).optional()
|
|
445
|
+
}).optional(),
|
|
446
|
+
deploy: import_zod6.default.object({
|
|
447
|
+
tags: import_zod6.default.array(import_zod6.default.string()).optional(),
|
|
448
|
+
dedicated_ip: import_zod6.default.boolean().optional(),
|
|
449
|
+
port_range: import_zod6.default.array(import_zod6.default.string()).optional()
|
|
450
|
+
}).optional()
|
|
451
|
+
});
|
|
452
|
+
var UpdateDetailsSchema = CreateServerSchema.pick({
|
|
453
|
+
external_id: true,
|
|
454
|
+
name: true,
|
|
455
|
+
user: true,
|
|
456
|
+
description: true,
|
|
457
|
+
docker_labels: true
|
|
458
|
+
});
|
|
459
|
+
var UpdateBuildSchema = CreateServerSchema.pick({
|
|
460
|
+
oom_killer: true,
|
|
461
|
+
limits: true,
|
|
462
|
+
feature_limits: true
|
|
463
|
+
}).extend({
|
|
464
|
+
allocation: import_zod6.default.number().optional(),
|
|
465
|
+
add_allocations: import_zod6.default.array(import_zod6.default.string()).optional(),
|
|
466
|
+
remove_allocations: import_zod6.default.array(import_zod6.default.string()).optional()
|
|
467
|
+
});
|
|
468
|
+
var UpdateStartupSchema = CreateServerSchema.pick({
|
|
469
|
+
startup: true,
|
|
470
|
+
environment: true,
|
|
471
|
+
egg: true
|
|
472
|
+
}).extend({ image: import_zod6.default.string().optional(), skip_scripts: import_zod6.default.boolean() });
|
|
451
473
|
|
|
452
|
-
// src/api/
|
|
453
|
-
var
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
var
|
|
457
|
-
var
|
|
458
|
-
"
|
|
459
|
-
"
|
|
474
|
+
// src/api/application/users.ts
|
|
475
|
+
var import_zod8 = __toESM(require("zod"));
|
|
476
|
+
|
|
477
|
+
// src/api/common/types/enums.ts
|
|
478
|
+
var import_zod7 = __toESM(require("zod"));
|
|
479
|
+
var languagesSchema = import_zod7.default.enum([
|
|
480
|
+
"af",
|
|
481
|
+
"ak",
|
|
482
|
+
"am",
|
|
483
|
+
"ar",
|
|
484
|
+
"as",
|
|
485
|
+
"az",
|
|
486
|
+
"be",
|
|
487
|
+
"bg",
|
|
488
|
+
"bm",
|
|
489
|
+
"bn",
|
|
490
|
+
"bo",
|
|
491
|
+
"br",
|
|
492
|
+
"bs",
|
|
493
|
+
"ca",
|
|
494
|
+
"ce",
|
|
495
|
+
"cs",
|
|
496
|
+
"cv",
|
|
497
|
+
"cy",
|
|
498
|
+
"da",
|
|
499
|
+
"de",
|
|
500
|
+
"dz",
|
|
501
|
+
"ee",
|
|
502
|
+
"el",
|
|
503
|
+
"en",
|
|
504
|
+
"eo",
|
|
505
|
+
"es",
|
|
506
|
+
"et",
|
|
507
|
+
"eu",
|
|
508
|
+
"fa",
|
|
509
|
+
"ff",
|
|
510
|
+
"fi",
|
|
511
|
+
"fo",
|
|
512
|
+
"fr",
|
|
513
|
+
"fy",
|
|
514
|
+
"ga",
|
|
515
|
+
"gd",
|
|
516
|
+
"gl",
|
|
517
|
+
"gu",
|
|
518
|
+
"gv",
|
|
519
|
+
"ha",
|
|
520
|
+
"he",
|
|
521
|
+
"hi",
|
|
522
|
+
"hr",
|
|
523
|
+
"hu",
|
|
524
|
+
"hy",
|
|
525
|
+
"ia",
|
|
526
|
+
"id",
|
|
527
|
+
"ig",
|
|
528
|
+
"ii",
|
|
529
|
+
"is",
|
|
530
|
+
"it",
|
|
531
|
+
"ja",
|
|
532
|
+
"jv",
|
|
533
|
+
"ka",
|
|
534
|
+
"ki",
|
|
535
|
+
"kk",
|
|
536
|
+
"kl",
|
|
537
|
+
"km",
|
|
538
|
+
"kn",
|
|
539
|
+
"ko",
|
|
540
|
+
"ks",
|
|
541
|
+
"ku",
|
|
542
|
+
"kw",
|
|
543
|
+
"ky",
|
|
544
|
+
"lb",
|
|
545
|
+
"lg",
|
|
546
|
+
"ln",
|
|
547
|
+
"lo",
|
|
548
|
+
"lt",
|
|
549
|
+
"lu",
|
|
550
|
+
"lv",
|
|
551
|
+
"mg",
|
|
552
|
+
"mi",
|
|
553
|
+
"mk",
|
|
554
|
+
"ml",
|
|
555
|
+
"mn",
|
|
556
|
+
"mr",
|
|
557
|
+
"ms",
|
|
558
|
+
"mt",
|
|
559
|
+
"my",
|
|
560
|
+
"nb",
|
|
561
|
+
"nd",
|
|
562
|
+
"ne",
|
|
563
|
+
"nl",
|
|
564
|
+
"nn",
|
|
565
|
+
"no",
|
|
566
|
+
"om",
|
|
567
|
+
"or",
|
|
568
|
+
"os",
|
|
569
|
+
"pa",
|
|
570
|
+
"pl",
|
|
571
|
+
"ps",
|
|
572
|
+
"pt",
|
|
573
|
+
"qu",
|
|
574
|
+
"rm",
|
|
575
|
+
"rn",
|
|
576
|
+
"ro",
|
|
577
|
+
"ru",
|
|
578
|
+
"rw",
|
|
579
|
+
"sa",
|
|
580
|
+
"sc",
|
|
581
|
+
"sd",
|
|
582
|
+
"se",
|
|
583
|
+
"sg",
|
|
584
|
+
"si",
|
|
585
|
+
"sk",
|
|
586
|
+
"sl",
|
|
587
|
+
"sn",
|
|
588
|
+
"so",
|
|
589
|
+
"sq",
|
|
590
|
+
"sr",
|
|
591
|
+
"su",
|
|
592
|
+
"sv",
|
|
593
|
+
"sw",
|
|
594
|
+
"ta",
|
|
595
|
+
"te",
|
|
596
|
+
"tg",
|
|
597
|
+
"th",
|
|
598
|
+
"ti",
|
|
599
|
+
"tk",
|
|
600
|
+
"to",
|
|
601
|
+
"tr",
|
|
602
|
+
"tt",
|
|
603
|
+
"ug",
|
|
604
|
+
"uk",
|
|
605
|
+
"ur",
|
|
606
|
+
"uz",
|
|
607
|
+
"vi",
|
|
608
|
+
"wo",
|
|
609
|
+
"xh",
|
|
610
|
+
"yi",
|
|
611
|
+
"yo",
|
|
612
|
+
"zh",
|
|
613
|
+
"zu"
|
|
460
614
|
]);
|
|
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([
|
|
615
|
+
var timezonesSchema = import_zod7.default.enum([
|
|
1131
616
|
"Africa/Abidjan",
|
|
1132
617
|
"Africa/Accra",
|
|
1133
618
|
"Africa/Addis_Ababa",
|
|
@@ -1549,605 +1034,1122 @@ var timezonesSchema = import_zod6.default.enum([
|
|
|
1549
1034
|
"UTC"
|
|
1550
1035
|
]);
|
|
1551
1036
|
|
|
1552
|
-
// src/
|
|
1553
|
-
var
|
|
1037
|
+
// src/utils/transform.ts
|
|
1038
|
+
var ArrayQueryParams = (p) => {
|
|
1039
|
+
const params = new URLSearchParams();
|
|
1040
|
+
const o = {};
|
|
1041
|
+
for (const [param, value] of Object.entries(p)) {
|
|
1042
|
+
for (const [key, val] of Object.entries(value)) {
|
|
1043
|
+
o[`${param}[${key}]`] = val;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
return o;
|
|
1047
|
+
};
|
|
1048
|
+
var SortParam = (key, p) => {
|
|
1049
|
+
return `${p === "desc" ? "-" : ""}${key}`;
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
// src/api/application/users.ts
|
|
1053
|
+
var Users = class {
|
|
1054
|
+
r;
|
|
1055
|
+
constructor(requester) {
|
|
1056
|
+
this.r = requester;
|
|
1057
|
+
}
|
|
1058
|
+
list = async (opts, page = 1) => {
|
|
1059
|
+
import_zod8.default.number().positive().parse(page);
|
|
1060
|
+
const { data } = await this.r.get("/users", {
|
|
1061
|
+
params: {
|
|
1062
|
+
include: opts.include?.join(","),
|
|
1063
|
+
page,
|
|
1064
|
+
...ArrayQueryParams({ filters: opts.filters || {} }),
|
|
1065
|
+
sort: opts.sort && (opts.sort.id ? SortParam("id", opts.sort.id) : SortParam("uuid", opts.sort.uuid))
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
return data.data.map((d) => d.attributes);
|
|
1069
|
+
};
|
|
1070
|
+
info = async (id, { include }) => {
|
|
1071
|
+
import_zod8.default.number().positive().parse(id);
|
|
1072
|
+
const { data } = await this.r.get(`/users/${id}`, { params: { include: include?.join(",") } });
|
|
1073
|
+
return data.attributes;
|
|
1074
|
+
};
|
|
1075
|
+
infoByExternal = async (external_id, { include }) => {
|
|
1076
|
+
const { data } = await this.r.get(`/users/external/${external_id}`, {
|
|
1077
|
+
params: { include: include?.join(",") }
|
|
1078
|
+
});
|
|
1079
|
+
return data.attributes;
|
|
1080
|
+
};
|
|
1081
|
+
create = async (user) => {
|
|
1082
|
+
user = CreateSchema.parse(user);
|
|
1083
|
+
const { data } = await this.r.post("/users", user);
|
|
1084
|
+
return data.attributes;
|
|
1085
|
+
};
|
|
1086
|
+
update = async (id, user) => {
|
|
1087
|
+
user = CreateSchema.parse(user);
|
|
1088
|
+
const { data } = await this.r.patch(`/users/${id}`, user);
|
|
1089
|
+
return data.attributes;
|
|
1090
|
+
};
|
|
1091
|
+
delete = async (id) => {
|
|
1092
|
+
import_zod8.default.number().positive().parse(id);
|
|
1093
|
+
await this.r.delete(`/users/${id}`);
|
|
1094
|
+
};
|
|
1095
|
+
addRoles = async (id, roles) => {
|
|
1096
|
+
import_zod8.default.number().positive().parse(id);
|
|
1097
|
+
await this.r.patch(`/users/${id}/roles/assign`, { roles });
|
|
1098
|
+
};
|
|
1099
|
+
removeRoles = async (id, roles) => {
|
|
1100
|
+
import_zod8.default.number().positive().parse(id);
|
|
1101
|
+
await this.r.patch(`/users/${id}/roles/remove`, { roles });
|
|
1102
|
+
};
|
|
1103
|
+
apiKeys = {
|
|
1104
|
+
list: async (id) => {
|
|
1105
|
+
const { data } = await this.r.get(`/users/${id}/api-keys`);
|
|
1106
|
+
return data.data.map((k) => k.attributes);
|
|
1107
|
+
},
|
|
1108
|
+
create: async (id, description, allowed_ips) => {
|
|
1109
|
+
allowed_ips = import_zod8.default.array(import_zod8.default.ipv4()).optional().parse(allowed_ips);
|
|
1110
|
+
const { data } = await this.r.post(`/users/${id}/api-keys`, { description, allowed_ips });
|
|
1111
|
+
return { ...data.attributes, secret_token: data.meta.secret_token };
|
|
1112
|
+
},
|
|
1113
|
+
delete: async (id, identifier) => {
|
|
1114
|
+
await this.r.delete(`/users/${id}/api-keys/${identifier}`);
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
};
|
|
1118
|
+
var CreateSchema = import_zod8.default.object({
|
|
1119
|
+
email: import_zod8.default.email(),
|
|
1120
|
+
external_id: import_zod8.default.string().max(255).optional(),
|
|
1121
|
+
username: import_zod8.default.string().min(1).max(255),
|
|
1122
|
+
password: import_zod8.default.string().optional(),
|
|
1123
|
+
language: languagesSchema,
|
|
1124
|
+
timezone: timezonesSchema
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
// src/api/application/client.ts
|
|
1128
|
+
var Client = class {
|
|
1129
|
+
r;
|
|
1130
|
+
users;
|
|
1131
|
+
nodes;
|
|
1132
|
+
databaseHosts;
|
|
1133
|
+
roles;
|
|
1134
|
+
eggs;
|
|
1135
|
+
mounts;
|
|
1136
|
+
constructor(requester) {
|
|
1137
|
+
this.r = requester;
|
|
1138
|
+
this.users = new Users(requester);
|
|
1139
|
+
this.nodes = new Nodes(requester);
|
|
1140
|
+
this.databaseHosts = new DatabaseHosts(requester);
|
|
1141
|
+
this.roles = new Roles(requester);
|
|
1142
|
+
this.eggs = new Eggs(requester);
|
|
1143
|
+
this.mounts = new Mounts(requester);
|
|
1144
|
+
}
|
|
1145
|
+
get $r() {
|
|
1146
|
+
return this.r;
|
|
1147
|
+
}
|
|
1148
|
+
listServers = async (search, page = 1) => {
|
|
1149
|
+
const { data } = await this.r.get("/servers", { params: { search, page } });
|
|
1150
|
+
return data.data.map((s) => s.attributes);
|
|
1151
|
+
};
|
|
1152
|
+
createServer = async (opts) => {
|
|
1153
|
+
opts = CreateServerSchema.parse(opts);
|
|
1154
|
+
const { data } = await this.r.post("/servers", opts);
|
|
1155
|
+
return data.attributes;
|
|
1156
|
+
};
|
|
1157
|
+
getServerByExternalId = async (external_id, include) => {
|
|
1158
|
+
const { data } = await this.r.get(`/servers/external/${external_id}`, {
|
|
1159
|
+
params: { include: include?.join(",") }
|
|
1160
|
+
});
|
|
1161
|
+
return data.attributes;
|
|
1162
|
+
};
|
|
1163
|
+
servers = (server_id) => new Servers(this.r, server_id);
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
// src/api/base/request.ts
|
|
1167
|
+
var import_axios = __toESM(require("axios"));
|
|
1168
|
+
var import_zod9 = __toESM(require("zod"));
|
|
1169
|
+
|
|
1170
|
+
// src/api/base/types.ts
|
|
1171
|
+
var PterodactylException = class extends Error {
|
|
1172
|
+
data;
|
|
1173
|
+
status;
|
|
1174
|
+
constructor(message, data, status) {
|
|
1175
|
+
super(message);
|
|
1176
|
+
this.data = data;
|
|
1177
|
+
this.status = status;
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
|
|
1181
|
+
// src/api/base/request.ts
|
|
1182
|
+
var Agent = class {
|
|
1183
|
+
base_url;
|
|
1184
|
+
token;
|
|
1185
|
+
requester;
|
|
1186
|
+
constructor(url, token, type, suffix = "/api") {
|
|
1187
|
+
this.base_url = import_zod9.default.url("Invalid URL Schema").transform((url2) => new URL(url2).href).parse(url);
|
|
1188
|
+
this.token = import_zod9.default.string().regex(/^(ptl[ac]|pacc|papp)_.+$/, "Invalid token type").parse(token);
|
|
1189
|
+
this.requester = import_axios.default.create({
|
|
1190
|
+
baseURL: this.base_url.replace(/\/+$/, "") + `${suffix}/${type}`,
|
|
1191
|
+
timeout: 3e3,
|
|
1192
|
+
headers: { Authorization: `Bearer ${this.token}` }
|
|
1193
|
+
});
|
|
1194
|
+
this.requester.interceptors.response.use(void 0, (error) => {
|
|
1195
|
+
if (error.response && error.response.status === 400) {
|
|
1196
|
+
return Promise.reject(
|
|
1197
|
+
new PterodactylException(
|
|
1198
|
+
"Invalid request data",
|
|
1199
|
+
error.response.data,
|
|
1200
|
+
error.response.status
|
|
1201
|
+
)
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
return Promise.reject(error);
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
// src/api/client/client.ts
|
|
1210
|
+
var import_zod14 = __toESM(require("zod"));
|
|
1211
|
+
|
|
1212
|
+
// src/api/client/account.ts
|
|
1213
|
+
var import_zod10 = __toESM(require("zod"));
|
|
1214
|
+
var Account = class {
|
|
1215
|
+
r;
|
|
1216
|
+
constructor(requester) {
|
|
1217
|
+
this.r = requester;
|
|
1218
|
+
}
|
|
1219
|
+
info = async () => {
|
|
1220
|
+
const { data } = await this.r.get("/account");
|
|
1221
|
+
return data.attributes;
|
|
1222
|
+
};
|
|
1223
|
+
updateEmail = async (newEmail, password) => {
|
|
1224
|
+
newEmail = import_zod10.default.email().parse(newEmail);
|
|
1225
|
+
await this.r.put("/account/email", { email: newEmail, password });
|
|
1226
|
+
};
|
|
1227
|
+
updatePassword = async (newPassword) => {
|
|
1228
|
+
newPassword = import_zod10.default.string().min(8).parse(newPassword);
|
|
1229
|
+
await this.r.put("/account/password", {
|
|
1230
|
+
password: newPassword,
|
|
1231
|
+
password_confirmation: newPassword
|
|
1232
|
+
});
|
|
1233
|
+
};
|
|
1234
|
+
apiKeys = {
|
|
1235
|
+
list: async () => {
|
|
1236
|
+
const { data } = await this.r.get("/account/api-keys");
|
|
1237
|
+
return data.data.map((k) => k.attributes);
|
|
1238
|
+
},
|
|
1239
|
+
create: async (description, allowed_ips) => {
|
|
1240
|
+
allowed_ips = import_zod10.default.array(import_zod10.default.ipv4()).optional().parse(allowed_ips);
|
|
1241
|
+
const { data } = await this.r.post("/account/api-keys", { description, allowed_ips });
|
|
1242
|
+
return { ...data.attributes, secret_token: data.meta.secret_token };
|
|
1243
|
+
},
|
|
1244
|
+
delete: async (identifier) => {
|
|
1245
|
+
await this.r.delete(`/account/api-keys/${identifier}`);
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
sshKeys = {
|
|
1249
|
+
list: async () => {
|
|
1250
|
+
const { data } = await this.r.get("/account/ssh-keys");
|
|
1251
|
+
return data.data.map((k) => k.attributes);
|
|
1252
|
+
},
|
|
1253
|
+
create: async (name, public_key) => {
|
|
1254
|
+
const { data } = await this.r.post("/account/ssh-keys", { name, public_key });
|
|
1255
|
+
return data.attributes;
|
|
1256
|
+
},
|
|
1257
|
+
delete: async (fingerprint) => {
|
|
1258
|
+
await this.r.delete(`/account/ssh-keys/${fingerprint}`);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
// src/api/client/server_activity.ts
|
|
1264
|
+
var ServerActivity = class {
|
|
1265
|
+
r;
|
|
1266
|
+
id;
|
|
1267
|
+
constructor(r, id) {
|
|
1268
|
+
this.r = r;
|
|
1269
|
+
this.id = id;
|
|
1270
|
+
}
|
|
1271
|
+
list = async (page = 1, per_page = 25) => {
|
|
1272
|
+
const { data } = await this.r.get(`/server/${this.id}/activity`, { params: { page, per_page } });
|
|
1273
|
+
return data.data.map((log) => log.attributes);
|
|
1274
|
+
};
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
// src/api/client/server_allocations.ts
|
|
1278
|
+
var ServerAllocations = class {
|
|
1279
|
+
r;
|
|
1280
|
+
id;
|
|
1281
|
+
constructor(requester, id) {
|
|
1282
|
+
this.r = requester;
|
|
1283
|
+
this.id = id;
|
|
1284
|
+
}
|
|
1285
|
+
list = async () => {
|
|
1286
|
+
const { data } = await this.r.get(`/servers/${this.id}/network/allocations`);
|
|
1287
|
+
return data.data.map((r) => r.attributes);
|
|
1288
|
+
};
|
|
1289
|
+
autoAssign = async () => {
|
|
1290
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations`);
|
|
1291
|
+
return data.attributes;
|
|
1292
|
+
};
|
|
1293
|
+
setNotes = async (alloc_id, notes) => {
|
|
1294
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations/${alloc_id}`, { notes });
|
|
1295
|
+
return data.attributes;
|
|
1296
|
+
};
|
|
1297
|
+
setPrimary = async (alloc_id) => {
|
|
1298
|
+
const { data } = await this.r.post(`/servers/${this.id}/network/allocations/${alloc_id}/primary`);
|
|
1299
|
+
return data.attributes;
|
|
1300
|
+
};
|
|
1301
|
+
unassign = async (alloc_id) => {
|
|
1302
|
+
await this.r.delete(
|
|
1303
|
+
`/servers/${this.id}/network/allocations/${alloc_id}`
|
|
1304
|
+
);
|
|
1305
|
+
};
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
// src/api/client/server_backups.ts
|
|
1309
|
+
var import_axios2 = __toESM(require("axios"));
|
|
1310
|
+
var import_zod11 = __toESM(require("zod"));
|
|
1311
|
+
var ServerBackups = class {
|
|
1312
|
+
r;
|
|
1313
|
+
id;
|
|
1314
|
+
constructor(requester, id) {
|
|
1315
|
+
this.r = requester;
|
|
1316
|
+
this.id = id;
|
|
1317
|
+
}
|
|
1318
|
+
list = async (page = 1) => {
|
|
1319
|
+
import_zod11.default.number().positive().parse(page);
|
|
1320
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups`, { params: { page } });
|
|
1321
|
+
return data.data.map((d) => d.attributes);
|
|
1322
|
+
};
|
|
1323
|
+
create = async (args) => {
|
|
1324
|
+
args.name = import_zod11.default.string().max(255).optional().parse(args.name);
|
|
1325
|
+
const { data } = await this.r.post(`/servers/${this.id}/backups`, {
|
|
1326
|
+
name: args.name,
|
|
1327
|
+
is_locked: args.is_locked,
|
|
1328
|
+
ignored_files: args.ignored_files.join("\n")
|
|
1329
|
+
});
|
|
1330
|
+
return data.attributes;
|
|
1331
|
+
};
|
|
1332
|
+
info = async (backup_uuid) => {
|
|
1333
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups/${backup_uuid}`);
|
|
1334
|
+
return data.attributes;
|
|
1335
|
+
};
|
|
1336
|
+
downloadGetUrl = async (backup_uuid) => {
|
|
1337
|
+
const { data } = await this.r.get(`/servers/${this.id}/backups/${backup_uuid}/download`);
|
|
1338
|
+
return data.attributes.url;
|
|
1339
|
+
};
|
|
1340
|
+
download = async (backup_uuid) => {
|
|
1341
|
+
const url = await this.downloadGetUrl(backup_uuid);
|
|
1342
|
+
const { data } = await import_axios2.default.get(url, {
|
|
1343
|
+
responseType: "arraybuffer"
|
|
1344
|
+
});
|
|
1345
|
+
return data;
|
|
1346
|
+
};
|
|
1347
|
+
delete = async (backup_uuid) => {
|
|
1348
|
+
await this.r.delete(`/servers/${this.id}/backups/${backup_uuid}`);
|
|
1349
|
+
};
|
|
1350
|
+
rename = async (backup_uuid, name) => {
|
|
1351
|
+
await this.r.put(`/servers/${this.id}/backups/${backup_uuid}/rename`, {
|
|
1352
|
+
name
|
|
1353
|
+
});
|
|
1354
|
+
};
|
|
1355
|
+
toggleLock = async (backup_uuid) => {
|
|
1356
|
+
await this.r.post(`/servers/${this.id}/backups/${backup_uuid}/lock`);
|
|
1357
|
+
};
|
|
1358
|
+
restore = async (backup_uuid, truncate) => {
|
|
1359
|
+
await this.r.post(
|
|
1360
|
+
`/servers/${this.id}/backups/${backup_uuid}/restore`,
|
|
1361
|
+
{ truncate }
|
|
1362
|
+
);
|
|
1363
|
+
};
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
// src/api/client/server_databases.ts
|
|
1367
|
+
var import_zod12 = __toESM(require("zod"));
|
|
1368
|
+
var ServerDatabases = class {
|
|
1369
|
+
r;
|
|
1370
|
+
id;
|
|
1371
|
+
constructor(requester, id) {
|
|
1372
|
+
this.r = requester;
|
|
1373
|
+
this.id = id;
|
|
1374
|
+
}
|
|
1375
|
+
list = async (include, page = 1) => {
|
|
1376
|
+
import_zod12.default.number().positive().parse(page);
|
|
1377
|
+
const { data } = await this.r.get(`/servers/${this.id}/databases`, {
|
|
1378
|
+
params: { include: include?.join(","), page }
|
|
1379
|
+
});
|
|
1380
|
+
return data.data.map((d) => d.attributes);
|
|
1381
|
+
};
|
|
1382
|
+
create = async (database, remote) => {
|
|
1383
|
+
const { data } = await this.r.post(`/servers/${this.id}/databases`, { database, remote });
|
|
1384
|
+
return data.attributes;
|
|
1385
|
+
};
|
|
1386
|
+
rotatePassword = async (database_id) => {
|
|
1387
|
+
const { data } = await this.r.post(`/servers/${this.id}/databases/${database_id}/rotate-password`);
|
|
1388
|
+
return data.attributes;
|
|
1389
|
+
};
|
|
1390
|
+
delete = async (database_id) => {
|
|
1391
|
+
await this.r.delete(`/servers/${this.id}/databases/${database_id}`);
|
|
1392
|
+
};
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
// src/api/client/server_files.ts
|
|
1396
|
+
var import_axios3 = __toESM(require("axios"));
|
|
1397
|
+
var ServerFiles = class {
|
|
1398
|
+
r;
|
|
1399
|
+
id;
|
|
1400
|
+
constructor(requester, id) {
|
|
1401
|
+
this.r = requester;
|
|
1402
|
+
this.id = id;
|
|
1403
|
+
}
|
|
1404
|
+
list = async (path) => {
|
|
1405
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/list`, { params: { directory: path } });
|
|
1406
|
+
return data.data.map((r) => r.attributes);
|
|
1407
|
+
};
|
|
1408
|
+
/**
|
|
1409
|
+
* Return the contents of a file. To read binary file (non-editable) use {@link download} instead
|
|
1410
|
+
*/
|
|
1411
|
+
contents = async (path) => {
|
|
1412
|
+
const { data } = await this.r.get(
|
|
1413
|
+
`/servers/${this.id}/files/contents`,
|
|
1414
|
+
{ params: { file: path } }
|
|
1415
|
+
);
|
|
1416
|
+
return data;
|
|
1417
|
+
};
|
|
1418
|
+
downloadGetUrl = async (path) => {
|
|
1419
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/download`, { params: { file: path } });
|
|
1420
|
+
return data.attributes.url;
|
|
1421
|
+
};
|
|
1422
|
+
download = async (path) => {
|
|
1423
|
+
const url = await this.downloadGetUrl(path);
|
|
1424
|
+
const { data } = await import_axios3.default.get(url, {
|
|
1425
|
+
responseType: "arraybuffer"
|
|
1426
|
+
});
|
|
1427
|
+
return data;
|
|
1428
|
+
};
|
|
1429
|
+
rename = async (root = "/", files) => {
|
|
1430
|
+
await this.r.put(`/servers/${this.id}/files/rename`, { root, files });
|
|
1431
|
+
};
|
|
1432
|
+
copy = async (location) => {
|
|
1433
|
+
await this.r.post(`/servers/${this.id}/files/copy`, { location });
|
|
1434
|
+
};
|
|
1435
|
+
write = async (path, content) => {
|
|
1436
|
+
await this.r.post(`/servers/${this.id}/files/write`, content, {
|
|
1437
|
+
params: { file: path }
|
|
1438
|
+
});
|
|
1439
|
+
};
|
|
1440
|
+
compress = async (root = "/", files, archive_name, extension) => {
|
|
1441
|
+
const { data } = await this.r.post(`/servers/${this.id}/files/compress`, {
|
|
1442
|
+
root,
|
|
1443
|
+
files,
|
|
1444
|
+
archive_name,
|
|
1445
|
+
extension
|
|
1446
|
+
});
|
|
1447
|
+
return data.attributes;
|
|
1448
|
+
};
|
|
1449
|
+
decompress = async (root = "/", file) => {
|
|
1450
|
+
await this.r.post(`/servers/${this.id}/files/decompress`, { root, file });
|
|
1451
|
+
};
|
|
1452
|
+
delete = async (root = "/", files) => {
|
|
1453
|
+
await this.r.post(`/servers/${this.id}/files/delete`, { root, files });
|
|
1454
|
+
};
|
|
1455
|
+
createFolder = async (root = "/", name) => {
|
|
1456
|
+
await this.r.post(`/servers/${this.id}/files/create-folder`, {
|
|
1457
|
+
root,
|
|
1458
|
+
name
|
|
1459
|
+
});
|
|
1460
|
+
};
|
|
1461
|
+
chmod = async (root = "/", files) => {
|
|
1462
|
+
await this.r.post(`/servers/${this.id}/files/chmod`, { root, files });
|
|
1463
|
+
};
|
|
1464
|
+
pullFromRemote = async (url, directory, filename, use_header = false, foreground = false) => {
|
|
1465
|
+
await this.r.post(`/servers/${this.id}/files/pull`, {
|
|
1466
|
+
url,
|
|
1467
|
+
directory,
|
|
1468
|
+
filename,
|
|
1469
|
+
use_header,
|
|
1470
|
+
foreground
|
|
1471
|
+
});
|
|
1472
|
+
};
|
|
1473
|
+
uploadGetUrl = async () => {
|
|
1474
|
+
const { data } = await this.r.get(`/servers/${this.id}/files/upload`);
|
|
1475
|
+
return data.attributes.url;
|
|
1476
|
+
};
|
|
1477
|
+
upload = async (file, root = "/") => {
|
|
1478
|
+
const url = await this.uploadGetUrl();
|
|
1479
|
+
await import_axios3.default.post(
|
|
1480
|
+
url,
|
|
1481
|
+
{ files: file },
|
|
1482
|
+
{
|
|
1483
|
+
headers: { "Content-Type": "multipart/form-data" },
|
|
1484
|
+
params: { directory: root }
|
|
1485
|
+
}
|
|
1486
|
+
);
|
|
1487
|
+
};
|
|
1488
|
+
};
|
|
1489
|
+
|
|
1490
|
+
// src/api/client/server_schedules.ts
|
|
1491
|
+
var ServerSchedules = class {
|
|
1492
|
+
r;
|
|
1493
|
+
id;
|
|
1494
|
+
constructor(requester, id) {
|
|
1495
|
+
this.r = requester;
|
|
1496
|
+
this.id = id;
|
|
1497
|
+
}
|
|
1498
|
+
list = async () => {
|
|
1499
|
+
const { data } = await this.r.get(`/servers/${this.id}/schedules`);
|
|
1500
|
+
return data.data.map((d) => d.attributes);
|
|
1501
|
+
};
|
|
1502
|
+
create = async (params) => {
|
|
1503
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules`, params);
|
|
1504
|
+
return data.attributes;
|
|
1505
|
+
};
|
|
1506
|
+
control = (sched_id) => new ScheduleControl(this.r, this.id, sched_id);
|
|
1507
|
+
};
|
|
1508
|
+
var ScheduleControl = class {
|
|
1509
|
+
r;
|
|
1510
|
+
id;
|
|
1511
|
+
sched_id;
|
|
1512
|
+
constructor(requester, id, sched_id) {
|
|
1513
|
+
this.r = requester;
|
|
1514
|
+
this.id = id;
|
|
1515
|
+
this.sched_id = sched_id;
|
|
1516
|
+
}
|
|
1517
|
+
info = async () => {
|
|
1518
|
+
const { data } = await this.r.get(`/servers/${this.id}/schedules/${this.sched_id}`);
|
|
1519
|
+
return data.attributes;
|
|
1520
|
+
};
|
|
1521
|
+
update = async (params) => {
|
|
1522
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}`, params);
|
|
1523
|
+
return data.attributes;
|
|
1524
|
+
};
|
|
1525
|
+
delete = async () => {
|
|
1526
|
+
await this.r.delete(`/servers/${this.id}/schedules/${this.sched_id}`);
|
|
1527
|
+
};
|
|
1528
|
+
execute = async () => {
|
|
1529
|
+
await this.r.post(
|
|
1530
|
+
`/servers/${this.id}/schedules/${this.sched_id}/execute`
|
|
1531
|
+
);
|
|
1532
|
+
};
|
|
1533
|
+
tasks = {
|
|
1534
|
+
create: async (opts) => {
|
|
1535
|
+
const { data } = await this.r.post(`/servers/${this.id}/schedules/${this.sched_id}/tasks`, opts);
|
|
1536
|
+
return data.attributes;
|
|
1537
|
+
},
|
|
1538
|
+
update: async (task_id, opts) => {
|
|
1539
|
+
const { data } = await this.r.post(
|
|
1540
|
+
`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`,
|
|
1541
|
+
opts
|
|
1542
|
+
);
|
|
1543
|
+
return data.attributes;
|
|
1544
|
+
},
|
|
1545
|
+
delete: async (task_id) => {
|
|
1546
|
+
await this.r.delete(
|
|
1547
|
+
`/servers/${this.id}/schedules/${this.sched_id}/tasks/${task_id}`
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
};
|
|
1552
|
+
|
|
1553
|
+
// src/api/client/server_settings.ts
|
|
1554
|
+
var import_zod13 = __toESM(require("zod"));
|
|
1555
|
+
var ServerSettings = class {
|
|
1554
1556
|
r;
|
|
1555
|
-
|
|
1557
|
+
id;
|
|
1558
|
+
constructor(requester, id) {
|
|
1559
|
+
this.r = requester;
|
|
1560
|
+
this.id = id;
|
|
1561
|
+
}
|
|
1562
|
+
rename = async (name) => {
|
|
1563
|
+
name = import_zod13.default.string().max(255).parse(name);
|
|
1564
|
+
await this.r.post(`/servers/${this.id}/settings/rename`, { name });
|
|
1565
|
+
};
|
|
1566
|
+
updateDescription = async (description) => {
|
|
1567
|
+
await this.r.post(`/servers/${this.id}/settings/description`, {
|
|
1568
|
+
description
|
|
1569
|
+
});
|
|
1570
|
+
};
|
|
1571
|
+
reinstall = async () => {
|
|
1572
|
+
await this.r.post(`/servers/${this.id}/settings/reinstall`);
|
|
1573
|
+
};
|
|
1574
|
+
changeDockerImage = async (image) => {
|
|
1575
|
+
await this.r.put(`/servers/${this.id}/settings/docker-image`, {
|
|
1576
|
+
docker_image: image
|
|
1577
|
+
});
|
|
1578
|
+
};
|
|
1579
|
+
};
|
|
1580
|
+
|
|
1581
|
+
// src/api/client/server_startup.ts
|
|
1582
|
+
var ServerStartup = class {
|
|
1583
|
+
r;
|
|
1584
|
+
id;
|
|
1585
|
+
constructor(requester, id) {
|
|
1586
|
+
this.r = requester;
|
|
1587
|
+
this.id = id;
|
|
1588
|
+
}
|
|
1589
|
+
list = async () => {
|
|
1590
|
+
const { data } = await this.r.get(`/servers/${this.id}/startup`);
|
|
1591
|
+
return {
|
|
1592
|
+
object: "list",
|
|
1593
|
+
meta: data.meta,
|
|
1594
|
+
data: data.data.map((d) => d.attributes)
|
|
1595
|
+
};
|
|
1596
|
+
};
|
|
1597
|
+
set = async (key, value) => {
|
|
1598
|
+
const { data } = await this.r.put(`/servers/${this.id}/startup/variable`, { key, value });
|
|
1599
|
+
return data.attributes;
|
|
1600
|
+
};
|
|
1601
|
+
};
|
|
1602
|
+
|
|
1603
|
+
// src/api/client/server_users.ts
|
|
1604
|
+
var ServerUsers = class {
|
|
1605
|
+
r;
|
|
1606
|
+
id;
|
|
1607
|
+
constructor(requester, id) {
|
|
1608
|
+
this.r = requester;
|
|
1609
|
+
this.id = id;
|
|
1610
|
+
}
|
|
1611
|
+
list = async () => {
|
|
1612
|
+
const { data } = await this.r.get(`/servers/${this.id}/users`);
|
|
1613
|
+
return data.data.map((d) => d.attributes);
|
|
1614
|
+
};
|
|
1615
|
+
create = async (email, permissions) => {
|
|
1616
|
+
const { data } = await this.r.post(`/servers/${this.id}/users`, { email, permissions });
|
|
1617
|
+
return data.attributes;
|
|
1618
|
+
};
|
|
1619
|
+
info = async (user_uuid) => {
|
|
1620
|
+
const { data } = await this.r.get(
|
|
1621
|
+
`/servers/${this.id}/users/${user_uuid}`
|
|
1622
|
+
);
|
|
1623
|
+
return data.attributes;
|
|
1624
|
+
};
|
|
1625
|
+
update = async (user_uuid, permissions) => {
|
|
1626
|
+
const { data } = await this.r.put(
|
|
1627
|
+
`/servers/${this.id}/users/${user_uuid}`,
|
|
1628
|
+
{ permissions }
|
|
1629
|
+
);
|
|
1630
|
+
return data.attributes;
|
|
1631
|
+
};
|
|
1632
|
+
delete = async (user_uuid) => {
|
|
1633
|
+
await this.r.delete(`/servers/${this.id}/users/${user_uuid}`);
|
|
1634
|
+
};
|
|
1635
|
+
};
|
|
1636
|
+
|
|
1637
|
+
// src/api/client/server_websocket.ts
|
|
1638
|
+
var import_events = require("events");
|
|
1639
|
+
var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
|
|
1640
|
+
var import_strip_color = __toESM(require("strip-color"));
|
|
1641
|
+
var isBrowser = typeof window !== "undefined";
|
|
1642
|
+
var RECONNECT_ERRORS = /* @__PURE__ */ new Set([
|
|
1643
|
+
"jwt: exp claim is invalid",
|
|
1644
|
+
"jwt: created too far in past (denylist)"
|
|
1645
|
+
]);
|
|
1646
|
+
var FALLBACK_LOG_MESSAGE = "No logs - is the server online?";
|
|
1647
|
+
var ServerWebsocket = class {
|
|
1648
|
+
r;
|
|
1649
|
+
serverId;
|
|
1650
|
+
socket;
|
|
1651
|
+
currentToken;
|
|
1652
|
+
bus = new import_events.EventEmitter();
|
|
1653
|
+
debugLogging = false;
|
|
1654
|
+
stripColors;
|
|
1655
|
+
detachMessageListener;
|
|
1656
|
+
constructor(requester, id, stripColors = false) {
|
|
1556
1657
|
this.r = requester;
|
|
1658
|
+
this.serverId = id;
|
|
1659
|
+
this.stripColors = stripColors;
|
|
1660
|
+
}
|
|
1661
|
+
on(event, listener) {
|
|
1662
|
+
const handler = listener;
|
|
1663
|
+
this.bus.on(event, handler);
|
|
1664
|
+
return () => {
|
|
1665
|
+
this.bus.removeListener(event, handler);
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
deregister(event, listener) {
|
|
1669
|
+
const handler = listener;
|
|
1670
|
+
this.bus.removeListener(event, handler);
|
|
1671
|
+
}
|
|
1672
|
+
emit(event, ...args) {
|
|
1673
|
+
if (args.length === 0) {
|
|
1674
|
+
this.bus.emit(event);
|
|
1675
|
+
} else {
|
|
1676
|
+
this.bus.emit(event, args[0]);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
async connect(resumable, debugLogging) {
|
|
1680
|
+
this.debugLogging = debugLogging ?? false;
|
|
1681
|
+
if (this.socket) {
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
const socketUrl = await this.refreshCredentials();
|
|
1685
|
+
this.socket = isBrowser ? new import_isomorphic_ws.default(socketUrl) : new import_isomorphic_ws.default(socketUrl, void 0, {
|
|
1686
|
+
origin: new URL(socketUrl).origin
|
|
1687
|
+
});
|
|
1688
|
+
await new Promise((resolve, reject) => {
|
|
1689
|
+
const socket = this.socket;
|
|
1690
|
+
if (!socket) {
|
|
1691
|
+
reject(new Error("Failed to create socket connection"));
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
socket.onopen = async () => {
|
|
1695
|
+
try {
|
|
1696
|
+
await this.authenticate();
|
|
1697
|
+
this.attachMessageListener();
|
|
1698
|
+
socket.onopen = null;
|
|
1699
|
+
socket.onerror = null;
|
|
1700
|
+
resolve();
|
|
1701
|
+
} catch (error) {
|
|
1702
|
+
socket.onopen = null;
|
|
1703
|
+
socket.onerror = null;
|
|
1704
|
+
reject(
|
|
1705
|
+
error instanceof Error ? error : new Error("Websocket authentication failed")
|
|
1706
|
+
);
|
|
1707
|
+
}
|
|
1708
|
+
};
|
|
1709
|
+
socket.onerror = (event) => {
|
|
1710
|
+
socket.onopen = null;
|
|
1711
|
+
socket.onerror = null;
|
|
1712
|
+
reject(
|
|
1713
|
+
event instanceof Error ? event : new Error("Websocket connection error")
|
|
1714
|
+
);
|
|
1715
|
+
};
|
|
1716
|
+
});
|
|
1717
|
+
if (resumable) {
|
|
1718
|
+
this.makeResumable(true);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
onSocketDisconnect(handler) {
|
|
1722
|
+
if (!this.socket) {
|
|
1723
|
+
console.error(new Error("No socket connection"));
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
this.socket.onclose = handler;
|
|
1727
|
+
}
|
|
1728
|
+
onSocketError(handler) {
|
|
1729
|
+
if (!this.socket) {
|
|
1730
|
+
console.error(new Error("No socket connection"));
|
|
1731
|
+
return;
|
|
1732
|
+
}
|
|
1733
|
+
this.socket.onerror = handler;
|
|
1734
|
+
}
|
|
1735
|
+
makeResumable(disconnectsToo) {
|
|
1736
|
+
const scheduleReconnect = () => {
|
|
1737
|
+
setTimeout(() => {
|
|
1738
|
+
const previous = this.socket;
|
|
1739
|
+
this.detachMessageListener?.();
|
|
1740
|
+
this.detachMessageListener = void 0;
|
|
1741
|
+
this.socket = void 0;
|
|
1742
|
+
previous?.close();
|
|
1743
|
+
void this.connect(true, this.debugLogging);
|
|
1744
|
+
}, 1e3);
|
|
1745
|
+
};
|
|
1746
|
+
this.onSocketError(() => scheduleReconnect());
|
|
1747
|
+
if (disconnectsToo) {
|
|
1748
|
+
this.onSocketDisconnect(() => scheduleReconnect());
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
attachMessageListener() {
|
|
1752
|
+
if (!this.socket) {
|
|
1753
|
+
throw new Error("No socket connection");
|
|
1754
|
+
}
|
|
1755
|
+
this.detachMessageListener?.();
|
|
1756
|
+
const handler = (event) => {
|
|
1757
|
+
void this.handleIncomingMessage(event);
|
|
1758
|
+
};
|
|
1759
|
+
if (typeof this.socket.addEventListener === "function") {
|
|
1760
|
+
this.socket.addEventListener(
|
|
1761
|
+
"message",
|
|
1762
|
+
handler
|
|
1763
|
+
);
|
|
1764
|
+
this.detachMessageListener = () => {
|
|
1765
|
+
this.socket?.removeEventListener?.(
|
|
1766
|
+
"message",
|
|
1767
|
+
handler
|
|
1768
|
+
);
|
|
1769
|
+
};
|
|
1770
|
+
} else {
|
|
1771
|
+
const fallback = (data) => handler({ data });
|
|
1772
|
+
const socket = this.socket;
|
|
1773
|
+
socket.on?.("message", fallback);
|
|
1774
|
+
this.detachMessageListener = () => {
|
|
1775
|
+
const target = this.socket;
|
|
1776
|
+
if (!target) {
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
if (typeof target.off === "function") {
|
|
1780
|
+
target.off("message", fallback);
|
|
1781
|
+
} else if (typeof target.removeListener === "function") {
|
|
1782
|
+
target.removeListener("message", fallback);
|
|
1783
|
+
}
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1557
1786
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1787
|
+
async handleIncomingMessage(event) {
|
|
1788
|
+
const message = this.parseMessage(event);
|
|
1789
|
+
if (!message) {
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
try {
|
|
1793
|
+
await this.dispatchMessage(message);
|
|
1794
|
+
} catch (error) {
|
|
1795
|
+
if (this.debugLogging) {
|
|
1796
|
+
console.error("Error while handling websocket message", error);
|
|
1566
1797
|
}
|
|
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
1798
|
}
|
|
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
1799
|
}
|
|
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;
|
|
1800
|
+
parseMessage(event) {
|
|
1801
|
+
const payload = this.normalisePayload(event);
|
|
1802
|
+
if (!payload) {
|
|
1803
|
+
return null;
|
|
1804
|
+
}
|
|
1805
|
+
try {
|
|
1806
|
+
return JSON.parse(payload);
|
|
1807
|
+
} catch (error) {
|
|
1808
|
+
if (this.debugLogging) {
|
|
1809
|
+
console.warn("Failed to parse websocket payload", error);
|
|
1810
|
+
}
|
|
1811
|
+
return null;
|
|
1812
|
+
}
|
|
1659
1813
|
}
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1814
|
+
normalisePayload(event) {
|
|
1815
|
+
if (typeof event === "string") {
|
|
1816
|
+
return event;
|
|
1817
|
+
}
|
|
1818
|
+
if (typeof event === "object" && event !== null && "data" in event) {
|
|
1819
|
+
return this.normalisePayload(event.data);
|
|
1820
|
+
}
|
|
1821
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(event)) {
|
|
1822
|
+
return event.toString("utf8");
|
|
1823
|
+
}
|
|
1824
|
+
if (typeof ArrayBuffer !== "undefined" && event instanceof ArrayBuffer) {
|
|
1825
|
+
if (typeof TextDecoder !== "undefined") {
|
|
1826
|
+
return new TextDecoder().decode(new Uint8Array(event));
|
|
1827
|
+
}
|
|
1828
|
+
if (typeof Buffer !== "undefined") {
|
|
1829
|
+
return Buffer.from(event).toString("utf8");
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
return null;
|
|
1833
|
+
}
|
|
1834
|
+
async dispatchMessage(message) {
|
|
1835
|
+
switch (message.event) {
|
|
1836
|
+
case "auth success" /* AUTH_SUCCESS */: {
|
|
1837
|
+
if (this.debugLogging) {
|
|
1838
|
+
console.debug("Auth success");
|
|
1839
|
+
}
|
|
1840
|
+
this.emit("auth success" /* AUTH_SUCCESS */);
|
|
1841
|
+
break;
|
|
1842
|
+
}
|
|
1843
|
+
case "status" /* STATUS */: {
|
|
1844
|
+
if (this.debugLogging) {
|
|
1845
|
+
console.debug("Received status event", message.args[0]);
|
|
1846
|
+
}
|
|
1847
|
+
this.emit("status" /* STATUS */, message.args[0]);
|
|
1848
|
+
break;
|
|
1849
|
+
}
|
|
1850
|
+
case "console output" /* CONSOLE_OUTPUT */: {
|
|
1851
|
+
let output = message.args[0];
|
|
1852
|
+
if (this.stripColors) {
|
|
1853
|
+
output = (0, import_strip_color.default)(output);
|
|
1854
|
+
}
|
|
1855
|
+
if (this.debugLogging) {
|
|
1856
|
+
console.debug("Received console output", output);
|
|
1857
|
+
}
|
|
1858
|
+
this.emit("console output" /* CONSOLE_OUTPUT */, output);
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
1861
|
+
case "stats" /* STATS */: {
|
|
1862
|
+
try {
|
|
1863
|
+
const payload = JSON.parse(message.args[0]);
|
|
1864
|
+
this.emit("stats" /* STATS */, payload);
|
|
1865
|
+
} catch (error) {
|
|
1866
|
+
if (this.debugLogging) {
|
|
1867
|
+
console.warn("Failed to parse stats payload", error);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
break;
|
|
1871
|
+
}
|
|
1872
|
+
case "daemon error" /* DAEMON_ERROR */: {
|
|
1873
|
+
this.emit("daemon error" /* DAEMON_ERROR */);
|
|
1874
|
+
break;
|
|
1875
|
+
}
|
|
1876
|
+
case "backup completed" /* BACKUP_COMPLETED */: {
|
|
1877
|
+
try {
|
|
1878
|
+
const payload = JSON.parse(
|
|
1879
|
+
message.args[0]
|
|
1880
|
+
);
|
|
1881
|
+
this.emit("backup completed" /* BACKUP_COMPLETED */, payload);
|
|
1882
|
+
} catch (error) {
|
|
1883
|
+
if (this.debugLogging) {
|
|
1884
|
+
console.warn("Failed to parse backup payload", error);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
break;
|
|
1888
|
+
}
|
|
1889
|
+
case "daemon message" /* DAEMON_MESSAGE */: {
|
|
1890
|
+
let output = message.args[0];
|
|
1891
|
+
if (this.stripColors) {
|
|
1892
|
+
output = (0, import_strip_color.default)(output);
|
|
1893
|
+
}
|
|
1894
|
+
this.emit("daemon message" /* DAEMON_MESSAGE */, output);
|
|
1895
|
+
break;
|
|
1896
|
+
}
|
|
1897
|
+
case "install output" /* INSTALL_OUTPUT */: {
|
|
1898
|
+
let output = message.args[0];
|
|
1899
|
+
if (this.stripColors) {
|
|
1900
|
+
output = (0, import_strip_color.default)(output);
|
|
1901
|
+
}
|
|
1902
|
+
this.emit("install output" /* INSTALL_OUTPUT */, output);
|
|
1903
|
+
break;
|
|
1904
|
+
}
|
|
1905
|
+
case "backup restore completed" /* BACKUP_RESTORE_COMPLETED */: {
|
|
1906
|
+
this.emit("backup restore completed" /* BACKUP_RESTORE_COMPLETED */);
|
|
1907
|
+
break;
|
|
1908
|
+
}
|
|
1909
|
+
case "install completed" /* INSTALL_COMPLETED */: {
|
|
1910
|
+
this.emit("install completed" /* INSTALL_COMPLETED */);
|
|
1911
|
+
break;
|
|
1912
|
+
}
|
|
1913
|
+
case "install started" /* INSTALL_STARTED */: {
|
|
1914
|
+
this.emit("install started" /* INSTALL_STARTED */);
|
|
1915
|
+
break;
|
|
1916
|
+
}
|
|
1917
|
+
case "transfer logs" /* TRANSFER_LOGS */: {
|
|
1918
|
+
this.emit("transfer logs" /* TRANSFER_LOGS */, message.args[0]);
|
|
1919
|
+
break;
|
|
1920
|
+
}
|
|
1921
|
+
case "transfer status" /* TRANSFER_STATUS */: {
|
|
1922
|
+
this.emit("transfer status" /* TRANSFER_STATUS */, message.args[0]);
|
|
1923
|
+
break;
|
|
1924
|
+
}
|
|
1925
|
+
case "token expiring" /* TOKEN_EXPIRING */: {
|
|
1926
|
+
this.emit("token expiring" /* TOKEN_EXPIRING */);
|
|
1927
|
+
if (this.debugLogging) {
|
|
1928
|
+
console.warn("Token expiring, renewing...");
|
|
1929
|
+
}
|
|
1930
|
+
await this.refreshCredentials();
|
|
1931
|
+
await this.authenticate();
|
|
1932
|
+
break;
|
|
1933
|
+
}
|
|
1934
|
+
case "token expired" /* TOKEN_EXPIRED */: {
|
|
1935
|
+
this.emit("token expired" /* TOKEN_EXPIRED */);
|
|
1936
|
+
throw new Error("Token expired");
|
|
1937
|
+
}
|
|
1938
|
+
case "jwt error" /* JWT_ERROR */: {
|
|
1939
|
+
const reason = message.args[0];
|
|
1940
|
+
if (RECONNECT_ERRORS.has(reason)) {
|
|
1941
|
+
this.emit("token expiring" /* TOKEN_EXPIRING */);
|
|
1942
|
+
if (this.debugLogging) {
|
|
1943
|
+
console.warn("Token expiring (JWT error), renewing...");
|
|
1944
|
+
}
|
|
1945
|
+
await this.refreshCredentials();
|
|
1946
|
+
await this.authenticate();
|
|
1947
|
+
} else {
|
|
1948
|
+
this.emit("jwt error" /* JWT_ERROR */, reason);
|
|
1949
|
+
throw new Error("Token expired");
|
|
1950
|
+
}
|
|
1951
|
+
break;
|
|
1676
1952
|
}
|
|
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);
|
|
1953
|
+
default: {
|
|
1954
|
+
if (this.debugLogging) {
|
|
1955
|
+
console.warn("Unknown websocket event", message);
|
|
1956
|
+
}
|
|
1957
|
+
break;
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
async refreshCredentials() {
|
|
1698
1962
|
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
|
|
1963
|
+
`/servers/${this.serverId}/websocket`
|
|
1709
1964
|
);
|
|
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;
|
|
1965
|
+
this.currentToken = data.data.token;
|
|
1966
|
+
return data.data.socket;
|
|
1752
1967
|
}
|
|
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`
|
|
1968
|
+
async authenticate() {
|
|
1969
|
+
if (!this.socket) {
|
|
1970
|
+
throw new Error("No socket connection");
|
|
1971
|
+
}
|
|
1972
|
+
if (!this.currentToken) {
|
|
1973
|
+
throw new Error("Missing websocket token");
|
|
1974
|
+
}
|
|
1975
|
+
this.socket.send(
|
|
1976
|
+
JSON.stringify({ event: "auth", args: [this.currentToken] })
|
|
1772
1977
|
);
|
|
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
1978
|
}
|
|
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;
|
|
1979
|
+
disconnect() {
|
|
1980
|
+
this.detachMessageListener?.();
|
|
1981
|
+
this.detachMessageListener = void 0;
|
|
1982
|
+
if (this.socket) {
|
|
1983
|
+
this.socket.close();
|
|
1984
|
+
this.socket = void 0;
|
|
1985
|
+
}
|
|
1889
1986
|
}
|
|
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;
|
|
1987
|
+
requestStats() {
|
|
1988
|
+
this.send("send stats", [null]);
|
|
1931
1989
|
}
|
|
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;
|
|
1990
|
+
requestLogs() {
|
|
1991
|
+
this.send("send logs", [null]);
|
|
1992
|
+
}
|
|
1993
|
+
send(event, args) {
|
|
1994
|
+
if (!this.socket) {
|
|
1995
|
+
if (this.debugLogging) {
|
|
1996
|
+
console.warn(
|
|
1997
|
+
`Attempted to send "${event}" without an active websocket connection`
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
return;
|
|
2001
|
+
}
|
|
2002
|
+
this.socket.send(JSON.stringify({ event, args }));
|
|
1958
2003
|
}
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
2004
|
+
getStats() {
|
|
2005
|
+
return new Promise((resolve, reject) => {
|
|
2006
|
+
if (!this.socket) {
|
|
2007
|
+
reject(new Error("No socket connection"));
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
let off;
|
|
2011
|
+
const timeout = setTimeout(() => {
|
|
2012
|
+
off?.();
|
|
2013
|
+
reject(new Error("Timed out waiting for stats"));
|
|
2014
|
+
}, 5e3);
|
|
2015
|
+
off = this.on("stats" /* STATS */, (payload) => {
|
|
2016
|
+
clearTimeout(timeout);
|
|
2017
|
+
off?.();
|
|
2018
|
+
resolve(payload);
|
|
2019
|
+
});
|
|
2020
|
+
this.requestStats();
|
|
1975
2021
|
});
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2022
|
+
}
|
|
2023
|
+
getLogs() {
|
|
2024
|
+
return new Promise((resolve, reject) => {
|
|
2025
|
+
if (!this.socket) {
|
|
2026
|
+
reject(new Error("No socket connection"));
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
const lines = [];
|
|
2030
|
+
let off;
|
|
2031
|
+
let initialTimeout;
|
|
2032
|
+
let idleTimeout;
|
|
2033
|
+
const finalize = (payload) => {
|
|
2034
|
+
off?.();
|
|
2035
|
+
if (initialTimeout) {
|
|
2036
|
+
clearTimeout(initialTimeout);
|
|
2037
|
+
}
|
|
2038
|
+
if (idleTimeout) {
|
|
2039
|
+
clearTimeout(idleTimeout);
|
|
2040
|
+
}
|
|
2041
|
+
resolve(payload);
|
|
2042
|
+
};
|
|
2043
|
+
initialTimeout = setTimeout(() => {
|
|
2044
|
+
finalize(lines.length > 0 ? lines : [FALLBACK_LOG_MESSAGE]);
|
|
2045
|
+
}, 5e3);
|
|
2046
|
+
off = this.on("console output" /* CONSOLE_OUTPUT */, (line) => {
|
|
2047
|
+
lines.push(line);
|
|
2048
|
+
if (initialTimeout) {
|
|
2049
|
+
clearTimeout(initialTimeout);
|
|
2050
|
+
initialTimeout = void 0;
|
|
2051
|
+
}
|
|
2052
|
+
if (idleTimeout) {
|
|
2053
|
+
clearTimeout(idleTimeout);
|
|
2054
|
+
}
|
|
2055
|
+
idleTimeout = setTimeout(() => {
|
|
2056
|
+
finalize(lines);
|
|
2057
|
+
}, 1e3);
|
|
2058
|
+
});
|
|
2059
|
+
this.requestLogs();
|
|
1981
2060
|
});
|
|
1982
|
-
|
|
1983
|
-
|
|
2061
|
+
}
|
|
2062
|
+
sendPoweraction(action) {
|
|
2063
|
+
this.send("set state", [action]);
|
|
2064
|
+
}
|
|
2065
|
+
sendCommand(cmd) {
|
|
2066
|
+
this.send("send command", [cmd]);
|
|
2067
|
+
}
|
|
1984
2068
|
};
|
|
1985
2069
|
|
|
1986
|
-
// src/api/
|
|
1987
|
-
var
|
|
1988
|
-
var Mounts = class {
|
|
2070
|
+
// src/api/client/server.ts
|
|
2071
|
+
var ServerClient = class {
|
|
1989
2072
|
r;
|
|
1990
|
-
|
|
1991
|
-
|
|
2073
|
+
id;
|
|
2074
|
+
activity;
|
|
2075
|
+
databases;
|
|
2076
|
+
files;
|
|
2077
|
+
schedules;
|
|
2078
|
+
allocations;
|
|
2079
|
+
users;
|
|
2080
|
+
backups;
|
|
2081
|
+
startup;
|
|
2082
|
+
variables;
|
|
2083
|
+
settings;
|
|
2084
|
+
constructor(requester, id) {
|
|
2085
|
+
this.r = requester;
|
|
2086
|
+
this.id = id;
|
|
2087
|
+
this.activity = new ServerActivity(requester, id);
|
|
2088
|
+
this.databases = new ServerDatabases(requester, id);
|
|
2089
|
+
this.files = new ServerFiles(requester, id);
|
|
2090
|
+
this.schedules = new ServerSchedules(requester, id);
|
|
2091
|
+
this.allocations = new ServerAllocations(requester, id);
|
|
2092
|
+
this.users = new ServerUsers(requester, id);
|
|
2093
|
+
this.backups = new ServerBackups(requester, id);
|
|
2094
|
+
this.startup = new ServerStartup(requester, id);
|
|
2095
|
+
this.variables = this.startup;
|
|
2096
|
+
this.settings = new ServerSettings(requester, id);
|
|
1992
2097
|
}
|
|
1993
|
-
|
|
1994
|
-
const { data } = await this.r.get("/mounts");
|
|
1995
|
-
return data.data.map((d) => d.attributes);
|
|
1996
|
-
};
|
|
1997
|
-
info = async (id) => {
|
|
2098
|
+
info = async (include) => {
|
|
1998
2099
|
const { data } = await this.r.get(
|
|
1999
|
-
`/
|
|
2100
|
+
`/servers/${this.id}`,
|
|
2101
|
+
{ params: { include: include?.join(",") } }
|
|
2000
2102
|
);
|
|
2001
2103
|
return data.attributes;
|
|
2002
2104
|
};
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
const { data } = await this.r.post(
|
|
2006
|
-
"/mounts",
|
|
2007
|
-
opts
|
|
2008
|
-
);
|
|
2009
|
-
return data.attributes;
|
|
2105
|
+
websocket = (stripColors = false) => {
|
|
2106
|
+
return new ServerWebsocket(this.r, this.id, stripColors);
|
|
2010
2107
|
};
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
`/mounts/${id}`,
|
|
2015
|
-
opts
|
|
2108
|
+
resources = async () => {
|
|
2109
|
+
const { data } = await this.r.get(
|
|
2110
|
+
`/servers/${this.id}/resources`
|
|
2016
2111
|
);
|
|
2017
2112
|
return data.attributes;
|
|
2018
2113
|
};
|
|
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 });
|
|
2114
|
+
command = async (command) => {
|
|
2115
|
+
await this.r.post(`/servers/${this.id}/command`, { command });
|
|
2048
2116
|
};
|
|
2049
|
-
|
|
2050
|
-
await this.r.
|
|
2117
|
+
power = async (signal) => {
|
|
2118
|
+
await this.r.post(`/servers/${this.id}/power`, { signal });
|
|
2051
2119
|
};
|
|
2052
2120
|
};
|
|
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
2121
|
|
|
2061
|
-
// src/api/
|
|
2122
|
+
// src/api/client/client.ts
|
|
2062
2123
|
var Client2 = class {
|
|
2124
|
+
account;
|
|
2063
2125
|
r;
|
|
2064
|
-
users;
|
|
2065
|
-
nodes;
|
|
2066
|
-
databaseHosts;
|
|
2067
|
-
roles;
|
|
2068
|
-
eggs;
|
|
2069
|
-
mounts;
|
|
2070
2126
|
constructor(requester) {
|
|
2071
2127
|
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);
|
|
2128
|
+
this.account = new Account(requester);
|
|
2078
2129
|
}
|
|
2079
2130
|
get $r() {
|
|
2080
2131
|
return this.r;
|
|
2081
2132
|
}
|
|
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;
|
|
2133
|
+
listPermissions = async () => {
|
|
2134
|
+
const { data } = await this.r.get("/permissions");
|
|
2135
|
+
return data.attributes.permissions;
|
|
2090
2136
|
};
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
return data.attributes;
|
|
2137
|
+
listServers = async (type = "accessible", page = 1, per_page = 50, include) => {
|
|
2138
|
+
import_zod14.default.number().positive().parse(page);
|
|
2139
|
+
const { data } = await this.r.get("/", { params: { type, page, include: include?.join(",") } });
|
|
2140
|
+
return data.data.map((s) => s.attributes);
|
|
2096
2141
|
};
|
|
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
|
-
}
|
|
2142
|
+
server = (uuid) => new ServerClient(this.r, uuid);
|
|
2141
2143
|
};
|
|
2142
2144
|
|
|
2143
2145
|
// src/api/index.ts
|
|
2144
|
-
var PelicanAPIClient = class extends
|
|
2146
|
+
var PelicanAPIClient = class extends Client2 {
|
|
2145
2147
|
constructor(url, token, suffix = "/api") {
|
|
2146
2148
|
const ax = new Agent(url, token, "client", suffix);
|
|
2147
2149
|
super(ax.requester);
|
|
2148
2150
|
}
|
|
2149
2151
|
};
|
|
2150
|
-
var PelicanAPIApplication = class extends
|
|
2152
|
+
var PelicanAPIApplication = class extends Client {
|
|
2151
2153
|
constructor(url, token, suffix = "/api") {
|
|
2152
2154
|
const ax = new Agent(url, token, "application", suffix);
|
|
2153
2155
|
super(ax.requester);
|