@ebowwa/hetzner 0.2.2 → 0.3.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.
Files changed (61) hide show
  1. package/dist/bootstrap/index.js +1126 -0
  2. package/dist/bootstrap/index.js.map +15 -0
  3. package/dist/index.js +3540 -0
  4. package/dist/index.js.map +31 -0
  5. package/dist/onboarding/index.js +460 -0
  6. package/dist/onboarding/index.js.map +14 -0
  7. package/package.json +53 -16
  8. package/actions.js +0 -1084
  9. package/actions.ts +0 -1053
  10. package/auth.js +0 -39
  11. package/auth.ts +0 -37
  12. package/bootstrap/FIREWALL.md +0 -326
  13. package/bootstrap/KERNEL-HARDENING.md +0 -258
  14. package/bootstrap/SECURITY-INTEGRATION.md +0 -281
  15. package/bootstrap/TESTING.md +0 -301
  16. package/bootstrap/cloud-init.js +0 -323
  17. package/bootstrap/cloud-init.ts +0 -394
  18. package/bootstrap/firewall.js +0 -292
  19. package/bootstrap/firewall.ts +0 -342
  20. package/bootstrap/genesis.js +0 -424
  21. package/bootstrap/genesis.ts +0 -518
  22. package/bootstrap/index.js +0 -59
  23. package/bootstrap/index.ts +0 -71
  24. package/bootstrap/kernel-hardening.js +0 -270
  25. package/bootstrap/kernel-hardening.test.js +0 -182
  26. package/bootstrap/kernel-hardening.test.ts +0 -230
  27. package/bootstrap/kernel-hardening.ts +0 -272
  28. package/bootstrap/security-audit.js +0 -122
  29. package/bootstrap/security-audit.ts +0 -124
  30. package/bootstrap/ssh-hardening.js +0 -186
  31. package/bootstrap/ssh-hardening.ts +0 -192
  32. package/client.js +0 -234
  33. package/client.ts +0 -177
  34. package/config.js +0 -7
  35. package/config.ts +0 -5
  36. package/errors.js +0 -345
  37. package/errors.ts +0 -371
  38. package/index.js +0 -73
  39. package/index.ts +0 -59
  40. package/onboarding/doppler.ts +0 -116
  41. package/onboarding/git.ts +0 -133
  42. package/onboarding/index.ts +0 -18
  43. package/onboarding/onboarding.ts +0 -193
  44. package/onboarding/tailscale.ts +0 -159
  45. package/onboarding/types.ts +0 -115
  46. package/pricing.js +0 -387
  47. package/pricing.ts +0 -422
  48. package/schemas.js +0 -667
  49. package/schemas.ts +0 -765
  50. package/server-status.js +0 -122
  51. package/server-status.ts +0 -81
  52. package/servers.js +0 -667
  53. package/servers.ts +0 -568
  54. package/ssh-keys.js +0 -180
  55. package/ssh-keys.ts +0 -122
  56. package/ssh-setup.js +0 -253
  57. package/ssh-setup.ts +0 -218
  58. package/types.js +0 -99
  59. package/types.ts +0 -389
  60. package/volumes.js +0 -295
  61. package/volumes.ts +0 -229
package/servers.js DELETED
@@ -1,667 +0,0 @@
1
- "use strict";
2
- /**
3
- * Hetzner server operations
4
- */
5
- var __assign = (this && this.__assign) || function () {
6
- __assign = Object.assign || function(t) {
7
- for (var s, i = 1, n = arguments.length; i < n; i++) {
8
- s = arguments[i];
9
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
10
- t[p] = s[p];
11
- }
12
- return t;
13
- };
14
- return __assign.apply(this, arguments);
15
- };
16
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
- return new (P || (P = Promise))(function (resolve, reject) {
19
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
- step((generator = generator.apply(thisArg, _arguments || [])).next());
23
- });
24
- };
25
- var __generator = (this && this.__generator) || function (thisArg, body) {
26
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
27
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
- function verb(n) { return function (v) { return step([n, v]); }; }
29
- function step(op) {
30
- if (f) throw new TypeError("Generator is already executing.");
31
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
- if (y = 0, t) op = [op[0] & 2, t.value];
34
- switch (op[0]) {
35
- case 0: case 1: t = op; break;
36
- case 4: _.label++; return { value: op[1], done: false };
37
- case 5: _.label++; y = op[1]; op = [0]; continue;
38
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
- default:
40
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
- if (t[2]) _.ops.pop();
45
- _.trys.pop(); continue;
46
- }
47
- op = body.call(thisArg, _);
48
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
- }
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- exports.ServerOperations = void 0;
54
- var zod_1 = require("zod");
55
- var schemas_js_1 = require("./schemas.js");
56
- var ServerOperations = /** @class */ (function () {
57
- function ServerOperations(client) {
58
- this.client = client;
59
- }
60
- /**
61
- * List all servers
62
- */
63
- ServerOperations.prototype.list = function () {
64
- return __awaiter(this, void 0, void 0, function () {
65
- var response, validated;
66
- return __generator(this, function (_a) {
67
- switch (_a.label) {
68
- case 0: return [4 /*yield*/, this.client.request("/servers")];
69
- case 1:
70
- response = _a.sent();
71
- validated = schemas_js_1.HetznerListServersResponseSchema.safeParse(response);
72
- if (!validated.success) {
73
- console.warn('Hetzner list servers validation warning:', validated.error.issues);
74
- return [2 /*return*/, response.servers]; // Return unvalidated data for backward compatibility
75
- }
76
- return [2 /*return*/, validated.data.servers];
77
- }
78
- });
79
- });
80
- };
81
- /**
82
- * Get a specific server by ID
83
- */
84
- ServerOperations.prototype.get = function (id) {
85
- return __awaiter(this, void 0, void 0, function () {
86
- var response, validated;
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
89
- case 0: return [4 /*yield*/, this.client.request("/servers/".concat(id))];
90
- case 1:
91
- response = _a.sent();
92
- validated = schemas_js_1.HetznerGetServerResponseSchema.safeParse(response);
93
- if (!validated.success) {
94
- console.warn('Hetzner get server validation warning:', validated.error.issues);
95
- return [2 /*return*/, response.server]; // Return unvalidated data for backward compatibility
96
- }
97
- return [2 /*return*/, validated.data.server];
98
- }
99
- });
100
- });
101
- };
102
- /**
103
- * Create a new server
104
- *
105
- * @param options - Server creation options
106
- * @returns Create server response including server, action, and next_actions
107
- */
108
- ServerOperations.prototype.create = function (options) {
109
- return __awaiter(this, void 0, void 0, function () {
110
- var createServerOptionsSchema, validatedOptions, body, response, validatedResponse;
111
- return __generator(this, function (_a) {
112
- switch (_a.label) {
113
- case 0:
114
- createServerOptionsSchema = zod_1.z.object({
115
- name: zod_1.z.string().min(1),
116
- server_type: zod_1.z.string().min(1).default("cpx11"),
117
- image: zod_1.z.string().min(1).default("ubuntu-24.04"),
118
- location: zod_1.z.string().min(1).optional(),
119
- datacenter: zod_1.z.string().min(1).optional(),
120
- ssh_keys: zod_1.z.array(zod_1.z.union([zod_1.z.string(), zod_1.z.number()])).default([]),
121
- volumes: zod_1.z.array(zod_1.z.number()).default([]),
122
- labels: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
123
- start_after_create: zod_1.z.boolean().default(true),
124
- user_data: zod_1.z.string().optional(),
125
- });
126
- validatedOptions = createServerOptionsSchema.safeParse(options);
127
- if (!validatedOptions.success) {
128
- throw new Error("Invalid server options: ".concat(validatedOptions.error.issues.map(function (i) { return i.message; }).join(', ')));
129
- }
130
- // Ensure either location or datacenter, not both
131
- if (validatedOptions.data.location && validatedOptions.data.datacenter) {
132
- throw new Error('Cannot specify both location and datacenter');
133
- }
134
- body = __assign(__assign(__assign(__assign(__assign(__assign({ name: validatedOptions.data.name, server_type: validatedOptions.data.server_type, image: validatedOptions.data.image }, (validatedOptions.data.location && { location: validatedOptions.data.location })), (validatedOptions.data.datacenter && { datacenter: { id: validatedOptions.data.datacenter } })), { ssh_keys: validatedOptions.data.ssh_keys, volumes: validatedOptions.data.volumes }), (validatedOptions.data.labels && { labels: validatedOptions.data.labels })), { start_after_create: validatedOptions.data.start_after_create }), (validatedOptions.data.user_data && { user_data: validatedOptions.data.user_data }));
135
- console.log('[Hetzner] Creating server with body:', JSON.stringify(body, null, 2));
136
- return [4 /*yield*/, this.client.request("/servers", {
137
- method: "POST",
138
- body: JSON.stringify(body),
139
- })];
140
- case 1:
141
- response = _a.sent();
142
- validatedResponse = schemas_js_1.HetznerCreateServerResponseSchema.safeParse(response);
143
- if (!validatedResponse.success) {
144
- console.warn('Hetzner create server validation warning:', validatedResponse.error.issues);
145
- return [2 /*return*/, response]; // Return unvalidated data for backward compatibility
146
- }
147
- return [2 /*return*/, validatedResponse.data];
148
- }
149
- });
150
- });
151
- };
152
- /**
153
- * Create a new server and wait for it to be ready
154
- *
155
- * This convenience method creates a server and waits for the initial action to complete.
156
- *
157
- * @param options - Server creation options
158
- * @param onProgress - Optional progress callback
159
- * @returns Server once ready
160
- */
161
- ServerOperations.prototype.createAndWait = function (options, onProgress) {
162
- return __awaiter(this, void 0, void 0, function () {
163
- var response, waitOptions, _i, _a, action, server;
164
- return __generator(this, function (_b) {
165
- switch (_b.label) {
166
- case 0: return [4 /*yield*/, this.create(options)];
167
- case 1:
168
- response = _b.sent();
169
- waitOptions = onProgress !== undefined ? { onProgress: onProgress } : {};
170
- if (!(response.action.status === 'running')) return [3 /*break*/, 3];
171
- return [4 /*yield*/, this.client.actions.waitFor(response.action.id, waitOptions)];
172
- case 2:
173
- _b.sent();
174
- _b.label = 3;
175
- case 3:
176
- if (!(response.next_actions.length > 0)) return [3 /*break*/, 7];
177
- _i = 0, _a = response.next_actions;
178
- _b.label = 4;
179
- case 4:
180
- if (!(_i < _a.length)) return [3 /*break*/, 7];
181
- action = _a[_i];
182
- return [4 /*yield*/, this.client.actions.waitFor(action.id, waitOptions)];
183
- case 5:
184
- _b.sent();
185
- _b.label = 6;
186
- case 6:
187
- _i++;
188
- return [3 /*break*/, 4];
189
- case 7: return [4 /*yield*/, this.get(response.server.id)];
190
- case 8:
191
- server = _b.sent();
192
- return [2 /*return*/, server];
193
- }
194
- });
195
- });
196
- };
197
- /**
198
- * Delete a server
199
- *
200
- * @param id - Server ID
201
- * @returns Action for server deletion
202
- */
203
- ServerOperations.prototype.delete = function (id) {
204
- return __awaiter(this, void 0, void 0, function () {
205
- var serverIdSchema, validatedId, response, validated;
206
- return __generator(this, function (_a) {
207
- switch (_a.label) {
208
- case 0:
209
- serverIdSchema = zod_1.z.number().int().positive();
210
- validatedId = serverIdSchema.safeParse(id);
211
- if (!validatedId.success) {
212
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
213
- }
214
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data), { method: "DELETE" })];
215
- case 1:
216
- response = _a.sent();
217
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
218
- if (!validated.success) {
219
- console.warn('Hetzner delete server validation warning:', validated.error.issues);
220
- return [2 /*return*/, response.action];
221
- }
222
- return [2 /*return*/, validated.data];
223
- }
224
- });
225
- });
226
- };
227
- /**
228
- * Delete a server and wait for completion
229
- *
230
- * @param id - Server ID
231
- * @param onProgress - Optional progress callback
232
- */
233
- ServerOperations.prototype.deleteAndWait = function (id, onProgress) {
234
- return __awaiter(this, void 0, void 0, function () {
235
- var action;
236
- return __generator(this, function (_a) {
237
- switch (_a.label) {
238
- case 0: return [4 /*yield*/, this.delete(id)];
239
- case 1:
240
- action = _a.sent();
241
- return [4 /*yield*/, this.client.actions.waitFor(action.id, { onProgress: onProgress })];
242
- case 2:
243
- _a.sent();
244
- return [2 /*return*/];
245
- }
246
- });
247
- });
248
- };
249
- /**
250
- * Power on a server
251
- *
252
- * @param id - Server ID
253
- * @returns Action for server power on
254
- */
255
- ServerOperations.prototype.powerOn = function (id) {
256
- return __awaiter(this, void 0, void 0, function () {
257
- var serverIdSchema, validatedId, response, validated;
258
- return __generator(this, function (_a) {
259
- switch (_a.label) {
260
- case 0:
261
- serverIdSchema = zod_1.z.number().int().positive();
262
- validatedId = serverIdSchema.safeParse(id);
263
- if (!validatedId.success) {
264
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
265
- }
266
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/poweron"), { method: "POST" })];
267
- case 1:
268
- response = _a.sent();
269
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
270
- if (!validated.success) {
271
- console.warn('Hetzner power on validation warning:', validated.error.issues);
272
- return [2 /*return*/, response.action];
273
- }
274
- return [2 /*return*/, validated.data];
275
- }
276
- });
277
- });
278
- };
279
- /**
280
- * Power on a server and wait for completion
281
- *
282
- * @param id - Server ID
283
- * @param onProgress - Optional progress callback
284
- */
285
- ServerOperations.prototype.powerOnAndWait = function (id, onProgress) {
286
- return __awaiter(this, void 0, void 0, function () {
287
- var action;
288
- return __generator(this, function (_a) {
289
- switch (_a.label) {
290
- case 0: return [4 /*yield*/, this.powerOn(id)];
291
- case 1:
292
- action = _a.sent();
293
- return [4 /*yield*/, this.client.actions.waitFor(action.id, { onProgress: onProgress })];
294
- case 2: return [2 /*return*/, _a.sent()];
295
- }
296
- });
297
- });
298
- };
299
- /**
300
- * Power off a server
301
- *
302
- * @param id - Server ID
303
- * @returns Action for server power off
304
- */
305
- ServerOperations.prototype.powerOff = function (id) {
306
- return __awaiter(this, void 0, void 0, function () {
307
- var serverIdSchema, validatedId, response, validated;
308
- return __generator(this, function (_a) {
309
- switch (_a.label) {
310
- case 0:
311
- serverIdSchema = zod_1.z.number().int().positive();
312
- validatedId = serverIdSchema.safeParse(id);
313
- if (!validatedId.success) {
314
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
315
- }
316
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/poweroff"), { method: "POST" })];
317
- case 1:
318
- response = _a.sent();
319
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
320
- if (!validated.success) {
321
- console.warn('Hetzner power off validation warning:', validated.error.issues);
322
- return [2 /*return*/, response.action];
323
- }
324
- return [2 /*return*/, validated.data];
325
- }
326
- });
327
- });
328
- };
329
- /**
330
- * Power off a server and wait for completion
331
- *
332
- * @param id - Server ID
333
- * @param onProgress - Optional progress callback
334
- */
335
- ServerOperations.prototype.powerOffAndWait = function (id, onProgress) {
336
- return __awaiter(this, void 0, void 0, function () {
337
- var action;
338
- return __generator(this, function (_a) {
339
- switch (_a.label) {
340
- case 0: return [4 /*yield*/, this.powerOff(id)];
341
- case 1:
342
- action = _a.sent();
343
- return [4 /*yield*/, this.client.actions.waitFor(action.id, { onProgress: onProgress })];
344
- case 2: return [2 /*return*/, _a.sent()];
345
- }
346
- });
347
- });
348
- };
349
- /**
350
- * Reboot a server
351
- *
352
- * @param id - Server ID
353
- * @returns Action for server reboot
354
- */
355
- ServerOperations.prototype.reboot = function (id) {
356
- return __awaiter(this, void 0, void 0, function () {
357
- var serverIdSchema, validatedId, response, validated;
358
- return __generator(this, function (_a) {
359
- switch (_a.label) {
360
- case 0:
361
- serverIdSchema = zod_1.z.number().int().positive();
362
- validatedId = serverIdSchema.safeParse(id);
363
- if (!validatedId.success) {
364
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
365
- }
366
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/reboot"), { method: "POST" })];
367
- case 1:
368
- response = _a.sent();
369
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
370
- if (!validated.success) {
371
- console.warn('Hetzner reboot validation warning:', validated.error.issues);
372
- return [2 /*return*/, response.action];
373
- }
374
- return [2 /*return*/, validated.data];
375
- }
376
- });
377
- });
378
- };
379
- /**
380
- * Reboot a server and wait for completion
381
- *
382
- * @param id - Server ID
383
- * @param onProgress - Optional progress callback
384
- */
385
- ServerOperations.prototype.rebootAndWait = function (id, onProgress) {
386
- return __awaiter(this, void 0, void 0, function () {
387
- var action;
388
- return __generator(this, function (_a) {
389
- switch (_a.label) {
390
- case 0: return [4 /*yield*/, this.reboot(id)];
391
- case 1:
392
- action = _a.sent();
393
- return [4 /*yield*/, this.client.actions.waitFor(action.id, { onProgress: onProgress })];
394
- case 2: return [2 /*return*/, _a.sent()];
395
- }
396
- });
397
- });
398
- };
399
- /**
400
- * Shutdown a server gracefully
401
- *
402
- * @param id - Server ID
403
- * @returns Action for server shutdown
404
- */
405
- ServerOperations.prototype.shutdown = function (id) {
406
- return __awaiter(this, void 0, void 0, function () {
407
- var serverIdSchema, validatedId, response, validated;
408
- return __generator(this, function (_a) {
409
- switch (_a.label) {
410
- case 0:
411
- serverIdSchema = zod_1.z.number().int().positive();
412
- validatedId = serverIdSchema.safeParse(id);
413
- if (!validatedId.success) {
414
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
415
- }
416
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/shutdown"), { method: "POST" })];
417
- case 1:
418
- response = _a.sent();
419
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
420
- if (!validated.success) {
421
- console.warn('Hetzner shutdown validation warning:', validated.error.issues);
422
- return [2 /*return*/, response.action];
423
- }
424
- return [2 /*return*/, validated.data];
425
- }
426
- });
427
- });
428
- };
429
- /**
430
- * Shutdown a server and wait for completion
431
- *
432
- * @param id - Server ID
433
- * @param onProgress - Optional progress callback
434
- */
435
- ServerOperations.prototype.shutdownAndWait = function (id, onProgress) {
436
- return __awaiter(this, void 0, void 0, function () {
437
- var action;
438
- return __generator(this, function (_a) {
439
- switch (_a.label) {
440
- case 0: return [4 /*yield*/, this.shutdown(id)];
441
- case 1:
442
- action = _a.sent();
443
- return [4 /*yield*/, this.client.actions.waitFor(action.id, { onProgress: onProgress })];
444
- case 2: return [2 /*return*/, _a.sent()];
445
- }
446
- });
447
- });
448
- };
449
- /**
450
- * Reset a server
451
- *
452
- * @param id - Server ID
453
- * @returns Action for server reset
454
- */
455
- ServerOperations.prototype.reset = function (id) {
456
- return __awaiter(this, void 0, void 0, function () {
457
- var serverIdSchema, validatedId, response, validated;
458
- return __generator(this, function (_a) {
459
- switch (_a.label) {
460
- case 0:
461
- serverIdSchema = zod_1.z.number().int().positive();
462
- validatedId = serverIdSchema.safeParse(id);
463
- if (!validatedId.success) {
464
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
465
- }
466
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/reset"), { method: "POST" })];
467
- case 1:
468
- response = _a.sent();
469
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
470
- if (!validated.success) {
471
- console.warn('Hetzner reset validation warning:', validated.error.issues);
472
- return [2 /*return*/, response.action];
473
- }
474
- return [2 /*return*/, validated.data];
475
- }
476
- });
477
- });
478
- };
479
- /**
480
- * Reset a server and wait for completion
481
- *
482
- * @param id - Server ID
483
- * @param onProgress - Optional progress callback
484
- */
485
- ServerOperations.prototype.resetAndWait = function (id, onProgress) {
486
- return __awaiter(this, void 0, void 0, function () {
487
- var action;
488
- return __generator(this, function (_a) {
489
- switch (_a.label) {
490
- case 0: return [4 /*yield*/, this.reset(id)];
491
- case 1:
492
- action = _a.sent();
493
- return [4 /*yield*/, this.client.actions.waitFor(action.id, { onProgress: onProgress })];
494
- case 2: return [2 /*return*/, _a.sent()];
495
- }
496
- });
497
- });
498
- };
499
- /**
500
- * Rebuild a server from an image
501
- *
502
- * @param id - Server ID
503
- * @param image - Image ID or name
504
- * @returns Action for server rebuild
505
- */
506
- ServerOperations.prototype.rebuild = function (id, image) {
507
- return __awaiter(this, void 0, void 0, function () {
508
- var serverIdSchema, validatedId, response, validated;
509
- return __generator(this, function (_a) {
510
- switch (_a.label) {
511
- case 0:
512
- serverIdSchema = zod_1.z.number().int().positive();
513
- validatedId = serverIdSchema.safeParse(id);
514
- if (!validatedId.success) {
515
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
516
- }
517
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/rebuild"), {
518
- method: "POST",
519
- body: JSON.stringify({ image: image }),
520
- })];
521
- case 1:
522
- response = _a.sent();
523
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
524
- if (!validated.success) {
525
- console.warn('Hetzner rebuild validation warning:', validated.error.issues);
526
- return [2 /*return*/, response.action];
527
- }
528
- return [2 /*return*/, validated.data];
529
- }
530
- });
531
- });
532
- };
533
- /**
534
- * Enable rescue mode for a server
535
- *
536
- * @param id - Server ID
537
- * @param options - Rescue mode options
538
- * @returns Action for enabling rescue mode
539
- */
540
- ServerOperations.prototype.enableRescue = function (id, options) {
541
- return __awaiter(this, void 0, void 0, function () {
542
- var serverIdSchema, validatedId, response, validated;
543
- return __generator(this, function (_a) {
544
- switch (_a.label) {
545
- case 0:
546
- serverIdSchema = zod_1.z.number().int().positive();
547
- validatedId = serverIdSchema.safeParse(id);
548
- if (!validatedId.success) {
549
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
550
- }
551
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/enable_rescue"), {
552
- method: "POST",
553
- body: JSON.stringify(options || {}),
554
- })];
555
- case 1:
556
- response = _a.sent();
557
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
558
- if (!validated.success) {
559
- console.warn('Hetzner enable rescue validation warning:', validated.error.issues);
560
- return [2 /*return*/, response.action];
561
- }
562
- return [2 /*return*/, validated.data];
563
- }
564
- });
565
- });
566
- };
567
- /**
568
- * Disable rescue mode for a server
569
- *
570
- * @param id - Server ID
571
- * @returns Action for disabling rescue mode
572
- */
573
- ServerOperations.prototype.disableRescue = function (id) {
574
- return __awaiter(this, void 0, void 0, function () {
575
- var serverIdSchema, validatedId, response, validated;
576
- return __generator(this, function (_a) {
577
- switch (_a.label) {
578
- case 0:
579
- serverIdSchema = zod_1.z.number().int().positive();
580
- validatedId = serverIdSchema.safeParse(id);
581
- if (!validatedId.success) {
582
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
583
- }
584
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/disable_rescue"), { method: "POST" })];
585
- case 1:
586
- response = _a.sent();
587
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
588
- if (!validated.success) {
589
- console.warn('Hetzner disable rescue validation warning:', validated.error.issues);
590
- return [2 /*return*/, response.action];
591
- }
592
- return [2 /*return*/, validated.data];
593
- }
594
- });
595
- });
596
- };
597
- /**
598
- * Change server type
599
- *
600
- * @param id - Server ID
601
- * @param serverType - New server type
602
- * @param upgradeDisk - Whether to upgrade disk (default: false)
603
- * @returns Action for changing server type
604
- */
605
- ServerOperations.prototype.changeType = function (id_1, serverType_1) {
606
- return __awaiter(this, arguments, void 0, function (id, serverType, upgradeDisk) {
607
- var serverIdSchema, validatedId, response, validated;
608
- if (upgradeDisk === void 0) { upgradeDisk = false; }
609
- return __generator(this, function (_a) {
610
- switch (_a.label) {
611
- case 0:
612
- serverIdSchema = zod_1.z.number().int().positive();
613
- validatedId = serverIdSchema.safeParse(id);
614
- if (!validatedId.success) {
615
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
616
- }
617
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions/change_type"), {
618
- method: "POST",
619
- body: JSON.stringify({ server_type: serverType, upgrade_disk: upgradeDisk }),
620
- })];
621
- case 1:
622
- response = _a.sent();
623
- validated = schemas_js_1.HetznerActionSchema.safeParse(response.action);
624
- if (!validated.success) {
625
- console.warn('Hetzner change type validation warning:', validated.error.issues);
626
- return [2 /*return*/, response.action];
627
- }
628
- return [2 /*return*/, validated.data];
629
- }
630
- });
631
- });
632
- };
633
- /**
634
- * Get actions for a specific server
635
- *
636
- * @param id - Server ID
637
- * @param options - Optional filters (status, sort, etc.)
638
- * @returns Array of server actions
639
- */
640
- ServerOperations.prototype.getActions = function (id, options) {
641
- return __awaiter(this, void 0, void 0, function () {
642
- var serverIdSchema, validatedId, params, query, response;
643
- return __generator(this, function (_a) {
644
- switch (_a.label) {
645
- case 0:
646
- serverIdSchema = zod_1.z.number().int().positive();
647
- validatedId = serverIdSchema.safeParse(id);
648
- if (!validatedId.success) {
649
- throw new Error("Invalid server ID: ".concat(validatedId.error.issues.map(function (i) { return i.message; }).join(', ')));
650
- }
651
- params = new URLSearchParams();
652
- if (options === null || options === void 0 ? void 0 : options.status)
653
- params.append("status", options.status);
654
- if (options === null || options === void 0 ? void 0 : options.sort)
655
- params.append("sort", options.sort);
656
- query = params.toString();
657
- return [4 /*yield*/, this.client.request("/servers/".concat(validatedId.data, "/actions").concat(query ? "?".concat(query) : ""))];
658
- case 1:
659
- response = _a.sent();
660
- return [2 /*return*/, response.actions];
661
- }
662
- });
663
- });
664
- };
665
- return ServerOperations;
666
- }());
667
- exports.ServerOperations = ServerOperations;