@ebowwa/hetzner 0.3.1 → 0.3.3
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/dist/actions.js +782 -0
- package/dist/bootstrap/index.js +1 -0
- package/dist/client.js +1867 -0
- package/dist/errors.js +236 -0
- package/dist/index.js +40 -38
- package/dist/onboarding/index.js +2 -2
- package/dist/pricing.js +587 -0
- package/dist/schemas.js +475 -0
- package/dist/servers.js +688 -0
- package/dist/ssh-keys.js +474 -0
- package/dist/types.js +101 -0
- package/dist/volumes.js +119 -0
- package/package.json +3 -2
- package/dist/bootstrap/index.js.map +0 -15
- package/dist/index.js.map +0 -31
- package/dist/onboarding/index.js.map +0 -14
package/dist/ssh-keys.js
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __require = import.meta.require;
|
|
19
|
+
|
|
20
|
+
// src/schemas.ts
|
|
21
|
+
import { z } from "zod";
|
|
22
|
+
import {
|
|
23
|
+
EnvironmentStatus,
|
|
24
|
+
ActionStatus,
|
|
25
|
+
VolumeStatus
|
|
26
|
+
} from "@ebowwa/codespaces-types/compile";
|
|
27
|
+
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
28
|
+
var ipv6Regex = /^[0-9a-fA-F:]+(?:\/\d{1,3})?$/;
|
|
29
|
+
var ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/;
|
|
30
|
+
var HetznerErrorSchema = z.object({
|
|
31
|
+
code: z.string(),
|
|
32
|
+
message: z.string(),
|
|
33
|
+
details: z.any().optional()
|
|
34
|
+
});
|
|
35
|
+
var HetznerPaginationSchema = z.object({
|
|
36
|
+
page: z.number(),
|
|
37
|
+
per_page: z.number(),
|
|
38
|
+
previous_page: z.number().nullable(),
|
|
39
|
+
next_page: z.number().nullable(),
|
|
40
|
+
last_page: z.number(),
|
|
41
|
+
total_entries: z.number()
|
|
42
|
+
});
|
|
43
|
+
var HetznerMetaSchema = z.object({
|
|
44
|
+
pagination: HetznerPaginationSchema.optional()
|
|
45
|
+
});
|
|
46
|
+
var HetznerActionResourceSchema = z.object({
|
|
47
|
+
id: z.number(),
|
|
48
|
+
type: z.enum([
|
|
49
|
+
"server",
|
|
50
|
+
"volume",
|
|
51
|
+
"network",
|
|
52
|
+
"floating_ip",
|
|
53
|
+
"load_balancer",
|
|
54
|
+
"certificate",
|
|
55
|
+
"firewall",
|
|
56
|
+
"image"
|
|
57
|
+
])
|
|
58
|
+
});
|
|
59
|
+
var HetznerActionErrorSchema = z.object({
|
|
60
|
+
code: z.string(),
|
|
61
|
+
message: z.string()
|
|
62
|
+
});
|
|
63
|
+
var HetznerActionSchema = z.object({
|
|
64
|
+
id: z.number(),
|
|
65
|
+
command: z.string(),
|
|
66
|
+
status: z.nativeEnum(ActionStatus),
|
|
67
|
+
started: z.string(),
|
|
68
|
+
finished: z.string().nullable(),
|
|
69
|
+
progress: z.number().min(0).max(100),
|
|
70
|
+
resources: z.array(HetznerActionResourceSchema),
|
|
71
|
+
error: HetznerActionErrorSchema.nullable()
|
|
72
|
+
});
|
|
73
|
+
var HetznerActionResponseSchema = z.object({
|
|
74
|
+
action: HetznerActionSchema
|
|
75
|
+
});
|
|
76
|
+
var HetznerActionsResponseSchema = z.object({
|
|
77
|
+
actions: z.array(HetznerActionSchema),
|
|
78
|
+
meta: HetznerMetaSchema
|
|
79
|
+
});
|
|
80
|
+
var HetznerServerImageSchema = z.object({
|
|
81
|
+
id: z.number(),
|
|
82
|
+
name: z.string(),
|
|
83
|
+
description: z.string(),
|
|
84
|
+
type: z.enum(["snapshot", "backup", "system"])
|
|
85
|
+
});
|
|
86
|
+
var HetznerIPv4Schema = z.object({
|
|
87
|
+
ip: z.string().regex(ipv4Regex),
|
|
88
|
+
blocked: z.boolean()
|
|
89
|
+
});
|
|
90
|
+
var HetznerIPv6Schema = z.object({
|
|
91
|
+
ip: z.string().regex(ipv6Regex),
|
|
92
|
+
blocked: z.boolean()
|
|
93
|
+
});
|
|
94
|
+
var HetznerFloatingIpRefSchema = z.object({
|
|
95
|
+
id: z.number(),
|
|
96
|
+
ip: z.string()
|
|
97
|
+
});
|
|
98
|
+
var HetznerFirewallRefSchema = z.object({
|
|
99
|
+
id: z.number(),
|
|
100
|
+
name: z.string(),
|
|
101
|
+
status: z.enum(["applied", "pending"])
|
|
102
|
+
});
|
|
103
|
+
var HetznerPublicNetSchema = z.object({
|
|
104
|
+
ipv4: HetznerIPv4Schema,
|
|
105
|
+
ipv6: HetznerIPv6Schema.optional(),
|
|
106
|
+
floating_ips: z.array(HetznerFloatingIpRefSchema),
|
|
107
|
+
firewalls: z.array(HetznerFirewallRefSchema)
|
|
108
|
+
});
|
|
109
|
+
var HetznerServerTypeSchema = z.object({
|
|
110
|
+
id: z.number(),
|
|
111
|
+
name: z.string(),
|
|
112
|
+
description: z.string(),
|
|
113
|
+
cores: z.number(),
|
|
114
|
+
memory: z.number(),
|
|
115
|
+
disk: z.number()
|
|
116
|
+
});
|
|
117
|
+
var HetznerLocationSchema = z.object({
|
|
118
|
+
id: z.number(),
|
|
119
|
+
name: z.string(),
|
|
120
|
+
description: z.string(),
|
|
121
|
+
country: z.string(),
|
|
122
|
+
city: z.string(),
|
|
123
|
+
latitude: z.number(),
|
|
124
|
+
longitude: z.number(),
|
|
125
|
+
network_zone: z.string()
|
|
126
|
+
});
|
|
127
|
+
var HetznerDatacenterSchema = z.object({
|
|
128
|
+
id: z.number(),
|
|
129
|
+
name: z.string(),
|
|
130
|
+
description: z.string(),
|
|
131
|
+
location: HetznerLocationSchema,
|
|
132
|
+
supported_server_types: z.array(z.object({
|
|
133
|
+
id: z.number(),
|
|
134
|
+
name: z.string()
|
|
135
|
+
})).optional().nullable()
|
|
136
|
+
});
|
|
137
|
+
var HetznerVolumeRefSchema = z.object({
|
|
138
|
+
id: z.number(),
|
|
139
|
+
name: z.string(),
|
|
140
|
+
size: z.number().positive(),
|
|
141
|
+
linux_device: z.string()
|
|
142
|
+
});
|
|
143
|
+
var HetznerServerProtectionSchema = z.object({
|
|
144
|
+
delete: z.boolean(),
|
|
145
|
+
rebuild: z.boolean()
|
|
146
|
+
});
|
|
147
|
+
var HetznerServerSchema = z.object({
|
|
148
|
+
id: z.number().positive(),
|
|
149
|
+
name: z.string().min(1),
|
|
150
|
+
status: z.nativeEnum(EnvironmentStatus),
|
|
151
|
+
image: HetznerServerImageSchema.nullable().optional(),
|
|
152
|
+
public_net: HetznerPublicNetSchema,
|
|
153
|
+
server_type: HetznerServerTypeSchema,
|
|
154
|
+
datacenter: HetznerDatacenterSchema,
|
|
155
|
+
labels: z.record(z.string(), z.any()),
|
|
156
|
+
created: z.string().datetime(),
|
|
157
|
+
protection: HetznerServerProtectionSchema,
|
|
158
|
+
volumes: z.array(HetznerVolumeRefSchema)
|
|
159
|
+
});
|
|
160
|
+
var HetznerListServersResponseSchema = z.object({
|
|
161
|
+
servers: z.array(HetznerServerSchema),
|
|
162
|
+
meta: HetznerMetaSchema
|
|
163
|
+
});
|
|
164
|
+
var HetznerGetServerResponseSchema = z.object({
|
|
165
|
+
server: HetznerServerSchema
|
|
166
|
+
});
|
|
167
|
+
var HetznerCreateServerRequestSchema = z.object({
|
|
168
|
+
name: z.string().min(1).max(64).regex(/^[a-zA-Z0-9][a-zA-Z0-9-]*$/, "Name must start with letter/number and contain only letters, numbers, and hyphens"),
|
|
169
|
+
server_type: z.string().min(1),
|
|
170
|
+
image: z.string().min(1),
|
|
171
|
+
location: z.string().min(1).optional(),
|
|
172
|
+
datacenter: z.string().min(1).optional(),
|
|
173
|
+
ssh_keys: z.array(z.union([z.string(), z.number()])).optional(),
|
|
174
|
+
volumes: z.array(z.number().positive()).optional(),
|
|
175
|
+
labels: z.record(z.string(), z.any()).optional(),
|
|
176
|
+
start_after_create: z.boolean().optional()
|
|
177
|
+
}).refine((data) => !(data.location && data.datacenter), "Cannot specify both location and datacenter");
|
|
178
|
+
var HetznerCreateServerResponseSchema = z.object({
|
|
179
|
+
server: HetznerServerSchema,
|
|
180
|
+
action: HetznerActionSchema,
|
|
181
|
+
next_actions: z.array(HetznerActionSchema),
|
|
182
|
+
root_password: z.string().nullable()
|
|
183
|
+
});
|
|
184
|
+
var HetznerUpdateServerRequestSchema = z.object({
|
|
185
|
+
name: z.string().min(1).max(64).optional(),
|
|
186
|
+
labels: z.record(z.string(), z.any()).optional()
|
|
187
|
+
});
|
|
188
|
+
var HetznerUpdateServerResponseSchema = z.object({
|
|
189
|
+
server: HetznerServerSchema
|
|
190
|
+
});
|
|
191
|
+
var HetznerVolumeLocationSchema = z.object({
|
|
192
|
+
id: z.number(),
|
|
193
|
+
name: z.string(),
|
|
194
|
+
description: z.string(),
|
|
195
|
+
country: z.string(),
|
|
196
|
+
city: z.string(),
|
|
197
|
+
latitude: z.number(),
|
|
198
|
+
longitude: z.number()
|
|
199
|
+
});
|
|
200
|
+
var HetznerVolumeProtectionSchema = z.object({
|
|
201
|
+
delete: z.boolean()
|
|
202
|
+
});
|
|
203
|
+
var HetznerVolumeSchema = z.object({
|
|
204
|
+
id: z.number().positive(),
|
|
205
|
+
name: z.string().min(1),
|
|
206
|
+
status: z.nativeEnum(VolumeStatus),
|
|
207
|
+
server: z.number().positive().nullable().optional(),
|
|
208
|
+
size: z.number().positive(),
|
|
209
|
+
linux_device: z.string().nullable().optional(),
|
|
210
|
+
format: z.string().nullable().optional(),
|
|
211
|
+
location: HetznerVolumeLocationSchema.nullable().optional(),
|
|
212
|
+
labels: z.record(z.string(), z.any()),
|
|
213
|
+
created: z.string().datetime(),
|
|
214
|
+
protection: HetznerVolumeProtectionSchema
|
|
215
|
+
});
|
|
216
|
+
var HetznerListVolumesResponseSchema = z.object({
|
|
217
|
+
volumes: z.array(HetznerVolumeSchema),
|
|
218
|
+
meta: HetznerMetaSchema
|
|
219
|
+
});
|
|
220
|
+
var HetznerGetVolumeResponseSchema = z.object({
|
|
221
|
+
volume: HetznerVolumeSchema
|
|
222
|
+
});
|
|
223
|
+
var HetznerCreateVolumeRequestSchema = z.object({
|
|
224
|
+
name: z.string().min(1).max(64),
|
|
225
|
+
size: z.number().positive().multipleOf(1),
|
|
226
|
+
server: z.number().positive().optional(),
|
|
227
|
+
location: z.string().min(1).optional(),
|
|
228
|
+
automount: z.boolean().optional(),
|
|
229
|
+
format: z.string().optional(),
|
|
230
|
+
labels: z.record(z.string(), z.any()).optional()
|
|
231
|
+
}).refine((data) => {
|
|
232
|
+
return Number.isInteger(data.size);
|
|
233
|
+
}, "Volume size must be a whole number in GB");
|
|
234
|
+
var HetznerCreateVolumeResponseSchema = z.object({
|
|
235
|
+
volume: HetznerVolumeSchema,
|
|
236
|
+
action: HetznerActionSchema,
|
|
237
|
+
next_actions: z.array(HetznerActionSchema)
|
|
238
|
+
});
|
|
239
|
+
var HetznerSubnetSchema = z.object({
|
|
240
|
+
type: z.enum(["server", "cloud", "vswitch"]),
|
|
241
|
+
ip_range: z.string().regex(ipRegex),
|
|
242
|
+
network_zone: z.string(),
|
|
243
|
+
gateway: z.string().regex(ipRegex)
|
|
244
|
+
});
|
|
245
|
+
var HetznerRouteSchema = z.object({
|
|
246
|
+
destination: z.string().regex(ipRegex),
|
|
247
|
+
gateway: z.string().regex(ipRegex)
|
|
248
|
+
});
|
|
249
|
+
var HetznerNetworkProtectionSchema = z.object({
|
|
250
|
+
delete: z.boolean()
|
|
251
|
+
});
|
|
252
|
+
var HetznerNetworkSchema = z.object({
|
|
253
|
+
id: z.number().positive(),
|
|
254
|
+
name: z.string().min(1).max(64),
|
|
255
|
+
ip_range: z.string().regex(ipRegex),
|
|
256
|
+
subnets: z.array(HetznerSubnetSchema),
|
|
257
|
+
routes: z.array(HetznerRouteSchema),
|
|
258
|
+
servers: z.array(z.number().positive()),
|
|
259
|
+
protection: HetznerNetworkProtectionSchema,
|
|
260
|
+
labels: z.record(z.string(), z.any()),
|
|
261
|
+
created: z.string().datetime()
|
|
262
|
+
});
|
|
263
|
+
var HetznerListNetworksResponseSchema = z.object({
|
|
264
|
+
networks: z.array(HetznerNetworkSchema),
|
|
265
|
+
meta: HetznerMetaSchema
|
|
266
|
+
});
|
|
267
|
+
var HetznerGetNetworkResponseSchema = z.object({
|
|
268
|
+
network: HetznerNetworkSchema
|
|
269
|
+
});
|
|
270
|
+
var HetznerSSHKeySchema = z.object({
|
|
271
|
+
id: z.number().positive(),
|
|
272
|
+
name: z.string().min(1).max(64),
|
|
273
|
+
fingerprint: z.string(),
|
|
274
|
+
public_key: z.string(),
|
|
275
|
+
labels: z.record(z.string(), z.any()),
|
|
276
|
+
created: z.string().datetime()
|
|
277
|
+
});
|
|
278
|
+
var HetznerListSSHKeysResponseSchema = z.object({
|
|
279
|
+
ssh_keys: z.array(HetznerSSHKeySchema),
|
|
280
|
+
meta: HetznerMetaSchema
|
|
281
|
+
});
|
|
282
|
+
var HetznerGetSSHKeyResponseSchema = z.object({
|
|
283
|
+
ssh_key: HetznerSSHKeySchema
|
|
284
|
+
});
|
|
285
|
+
var HetznerCreateSSHKeyRequestSchema = z.object({
|
|
286
|
+
name: z.string().min(1).max(64).regex(/^[a-zA-Z0-9][a-zA-Z0-9-]*$/, "Name must start with letter/number and contain only letters, numbers, and hyphens"),
|
|
287
|
+
public_key: z.string().min(1),
|
|
288
|
+
labels: z.record(z.string(), z.any()).optional()
|
|
289
|
+
});
|
|
290
|
+
var HetznerCreateSSHKeyResponseSchema = z.object({
|
|
291
|
+
ssh_key: HetznerSSHKeySchema
|
|
292
|
+
});
|
|
293
|
+
var HetznerFloatingIpSchema = z.object({
|
|
294
|
+
id: z.number().positive(),
|
|
295
|
+
name: z.string().min(1).max(64),
|
|
296
|
+
description: z.string().optional(),
|
|
297
|
+
type: z.enum(["ipv4", "ipv6"]),
|
|
298
|
+
ip: z.string().regex(ipRegex),
|
|
299
|
+
server: z.number().positive().nullable(),
|
|
300
|
+
dns_ptr: z.array(z.object({
|
|
301
|
+
ip: z.string(),
|
|
302
|
+
dns_ptr: z.string()
|
|
303
|
+
})),
|
|
304
|
+
home_location: HetznerLocationSchema,
|
|
305
|
+
blocked: z.boolean(),
|
|
306
|
+
protection: z.object({
|
|
307
|
+
delete: z.boolean()
|
|
308
|
+
}),
|
|
309
|
+
labels: z.record(z.string(), z.any()),
|
|
310
|
+
created: z.string().datetime()
|
|
311
|
+
});
|
|
312
|
+
var HetznerListFloatingIpsResponseSchema = z.object({
|
|
313
|
+
floating_ips: z.array(HetznerFloatingIpSchema),
|
|
314
|
+
meta: HetznerMetaSchema
|
|
315
|
+
});
|
|
316
|
+
var HetznerFirewallRuleSchema = z.object({
|
|
317
|
+
direction: z.enum(["in", "out"]),
|
|
318
|
+
source_ips: z.array(z.string().regex(ipRegex)).optional(),
|
|
319
|
+
destination_ips: z.array(z.string().regex(ipRegex)).optional(),
|
|
320
|
+
source_port: z.string().optional(),
|
|
321
|
+
destination_port: z.string().optional(),
|
|
322
|
+
protocol: z.enum(["tcp", "udp", "icmp", "esp", "gre"])
|
|
323
|
+
});
|
|
324
|
+
var HetznerFirewallResourceSchema = z.object({
|
|
325
|
+
type: z.enum(["server", "label_selector"]),
|
|
326
|
+
server: z.object({
|
|
327
|
+
id: z.number().positive()
|
|
328
|
+
}).optional(),
|
|
329
|
+
label_selector: z.object({
|
|
330
|
+
selector: z.string()
|
|
331
|
+
}).optional()
|
|
332
|
+
});
|
|
333
|
+
var HetznerFirewallSchema = z.object({
|
|
334
|
+
id: z.number().positive(),
|
|
335
|
+
name: z.string().min(1).max(64),
|
|
336
|
+
rules: z.array(HetznerFirewallRuleSchema),
|
|
337
|
+
apply_to: z.array(HetznerFirewallResourceSchema),
|
|
338
|
+
labels: z.record(z.string(), z.any()),
|
|
339
|
+
created: z.string().datetime()
|
|
340
|
+
});
|
|
341
|
+
var HetznerListFirewallsResponseSchema = z.object({
|
|
342
|
+
firewalls: z.array(HetznerFirewallSchema),
|
|
343
|
+
meta: HetznerMetaSchema
|
|
344
|
+
});
|
|
345
|
+
var HetznerIsoSchema = z.object({
|
|
346
|
+
id: z.number().positive(),
|
|
347
|
+
name: z.string(),
|
|
348
|
+
description: z.string(),
|
|
349
|
+
type: z.enum(["public", "private"]),
|
|
350
|
+
deprecated: z.date().nullable().optional(),
|
|
351
|
+
architecture: z.array(z.enum(["x86", "arm"])).optional()
|
|
352
|
+
});
|
|
353
|
+
var HetznerListIsosResponseSchema = z.object({
|
|
354
|
+
isos: z.array(HetznerIsoSchema),
|
|
355
|
+
meta: HetznerMetaSchema
|
|
356
|
+
});
|
|
357
|
+
var HetznerListLocationsResponseSchema = z.object({
|
|
358
|
+
locations: z.array(HetznerLocationSchema)
|
|
359
|
+
});
|
|
360
|
+
var HetznerListDatacentersResponseSchema = z.object({
|
|
361
|
+
datacenters: z.array(HetznerDatacenterSchema)
|
|
362
|
+
});
|
|
363
|
+
var HetznerServerTypePricingSchema = z.object({
|
|
364
|
+
location: z.string().nullable().optional(),
|
|
365
|
+
price_hourly: z.object({
|
|
366
|
+
net: z.string(),
|
|
367
|
+
gross: z.string()
|
|
368
|
+
}),
|
|
369
|
+
price_monthly: z.object({
|
|
370
|
+
net: z.string(),
|
|
371
|
+
gross: z.string()
|
|
372
|
+
})
|
|
373
|
+
});
|
|
374
|
+
var HetznerServerTypeExtendedSchema = HetznerServerTypeSchema.extend({
|
|
375
|
+
deprecated: z.boolean().optional(),
|
|
376
|
+
prices: z.array(HetznerServerTypePricingSchema),
|
|
377
|
+
storage_type: z.enum(["local", "network"]),
|
|
378
|
+
cpu_type: z.enum(["shared", "dedicated"])
|
|
379
|
+
});
|
|
380
|
+
var HetznerListServerTypesResponseSchema = z.object({
|
|
381
|
+
server_types: z.array(HetznerServerTypeExtendedSchema)
|
|
382
|
+
});
|
|
383
|
+
var HetznerCertificateSchema = z.object({
|
|
384
|
+
id: z.number().positive(),
|
|
385
|
+
name: z.string().min(1).max(64),
|
|
386
|
+
labels: z.record(z.string(), z.any()),
|
|
387
|
+
certificate: z.string(),
|
|
388
|
+
not_valid_before: z.string().datetime(),
|
|
389
|
+
not_valid_after: z.string().datetime(),
|
|
390
|
+
domain_names: z.array(z.string().url()),
|
|
391
|
+
fingerprint: z.string(),
|
|
392
|
+
created: z.string().datetime(),
|
|
393
|
+
status: z.enum(["pending", "issued", "failed", "revoked"]),
|
|
394
|
+
failed: z.boolean().optional(),
|
|
395
|
+
type: z.enum(["uploaded", "managed"]),
|
|
396
|
+
usage: z.array(z.enum(["dual_stack", "server", "load_balancer", "dns"])).optional()
|
|
397
|
+
});
|
|
398
|
+
var HetznerListCertificatesResponseSchema = z.object({
|
|
399
|
+
certificates: z.array(HetznerCertificateSchema),
|
|
400
|
+
meta: HetznerMetaSchema
|
|
401
|
+
});
|
|
402
|
+
function createPaginatedResponseSchema(itemSchema, itemName) {
|
|
403
|
+
return z.object({
|
|
404
|
+
[itemName]: z.array(itemSchema),
|
|
405
|
+
meta: HetznerMetaSchema
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
function createItemResponseSchema(itemSchema, itemName) {
|
|
409
|
+
return z.object({
|
|
410
|
+
[itemName]: itemSchema
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/ssh-keys.ts
|
|
415
|
+
class SSHKeyOperations {
|
|
416
|
+
client;
|
|
417
|
+
constructor(client) {
|
|
418
|
+
this.client = client;
|
|
419
|
+
}
|
|
420
|
+
async list() {
|
|
421
|
+
const response = await this.client.request("/ssh_keys");
|
|
422
|
+
const validated = HetznerListSSHKeysResponseSchema.safeParse(response);
|
|
423
|
+
if (!validated.success) {
|
|
424
|
+
console.warn("Hetzner list SSH keys validation warning:", validated.error.issues);
|
|
425
|
+
return response.ssh_keys;
|
|
426
|
+
}
|
|
427
|
+
return validated.data.ssh_keys;
|
|
428
|
+
}
|
|
429
|
+
async get(idOrName) {
|
|
430
|
+
const endpoint = typeof idOrName === "number" ? `/ssh_keys/${idOrName}` : `/ssh_keys?name=${encodeURIComponent(idOrName)}`;
|
|
431
|
+
const response = await this.client.request(endpoint);
|
|
432
|
+
const validated = HetznerGetSSHKeyResponseSchema.safeParse(response);
|
|
433
|
+
if (!validated.success) {
|
|
434
|
+
console.warn("Hetzner get SSH key validation warning:", validated.error.issues);
|
|
435
|
+
return response.ssh_key;
|
|
436
|
+
}
|
|
437
|
+
return validated.data.ssh_key;
|
|
438
|
+
}
|
|
439
|
+
async create(options) {
|
|
440
|
+
const validatedOptions = HetznerCreateSSHKeyRequestSchema.safeParse(options);
|
|
441
|
+
if (!validatedOptions.success) {
|
|
442
|
+
throw new Error(`Invalid SSH key options: ${validatedOptions.error.issues.map((i) => i.message).join(", ")}`);
|
|
443
|
+
}
|
|
444
|
+
const body = {
|
|
445
|
+
name: validatedOptions.data.name,
|
|
446
|
+
public_key: validatedOptions.data.public_key,
|
|
447
|
+
...validatedOptions.data.labels && { labels: validatedOptions.data.labels }
|
|
448
|
+
};
|
|
449
|
+
const response = await this.client.request("/ssh_keys", {
|
|
450
|
+
method: "POST",
|
|
451
|
+
body: JSON.stringify(body)
|
|
452
|
+
});
|
|
453
|
+
const validated = HetznerCreateSSHKeyResponseSchema.safeParse(response);
|
|
454
|
+
if (!validated.success) {
|
|
455
|
+
console.warn("Hetzner create SSH key validation warning:", validated.error.issues);
|
|
456
|
+
return response.ssh_key;
|
|
457
|
+
}
|
|
458
|
+
return validated.data.ssh_key;
|
|
459
|
+
}
|
|
460
|
+
async delete(id) {
|
|
461
|
+
await this.client.request(`/ssh_keys/${id}`, { method: "DELETE" });
|
|
462
|
+
}
|
|
463
|
+
async findByName(name) {
|
|
464
|
+
try {
|
|
465
|
+
const keys = await this.list();
|
|
466
|
+
return keys.find((key) => key.name === name);
|
|
467
|
+
} catch {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
export {
|
|
473
|
+
SSHKeyOperations
|
|
474
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __require = import.meta.require;
|
|
19
|
+
|
|
20
|
+
// src/types.ts
|
|
21
|
+
import {
|
|
22
|
+
EnvironmentStatus,
|
|
23
|
+
ActionStatus,
|
|
24
|
+
VolumeStatus
|
|
25
|
+
} from "@ebowwa/codespaces-types/compile";
|
|
26
|
+
var ActionCommand;
|
|
27
|
+
((ActionCommand2) => {
|
|
28
|
+
ActionCommand2["CreateServer"] = "create_server";
|
|
29
|
+
ActionCommand2["DeleteServer"] = "delete_server";
|
|
30
|
+
ActionCommand2["StartServer"] = "start_server";
|
|
31
|
+
ActionCommand2["StopServer"] = "stop_server";
|
|
32
|
+
ActionCommand2["RebootServer"] = "reboot_server";
|
|
33
|
+
ActionCommand2["ResetServer"] = "reset_server";
|
|
34
|
+
ActionCommand2["ShutdownServer"] = "shutdown_server";
|
|
35
|
+
ActionCommand2["Poweroff"] = "poweroff";
|
|
36
|
+
ActionCommand2["ChangeServerType"] = "change_server_type";
|
|
37
|
+
ActionCommand2["RebuildServer"] = "rebuild_server";
|
|
38
|
+
ActionCommand2["EnableBackup"] = "enable_backup";
|
|
39
|
+
ActionCommand2["DisableBackup"] = "disable_backup";
|
|
40
|
+
ActionCommand2["CreateImage"] = "create_image";
|
|
41
|
+
ActionCommand2["ChangeDnsPtr"] = "change_dns_ptr";
|
|
42
|
+
ActionCommand2["AttachToNetwork"] = "attach_to_network";
|
|
43
|
+
ActionCommand2["DetachFromNetwork"] = "detach_from_network";
|
|
44
|
+
ActionCommand2["ChangeAliasIps"] = "change_alias_ips";
|
|
45
|
+
ActionCommand2["EnableRescue"] = "enable_rescue";
|
|
46
|
+
ActionCommand2["DisableRescue"] = "disable_rescue";
|
|
47
|
+
ActionCommand2["ChangeProtection"] = "change_protection";
|
|
48
|
+
ActionCommand2["CreateVolume"] = "create_volume";
|
|
49
|
+
ActionCommand2["DeleteVolume"] = "delete_volume";
|
|
50
|
+
ActionCommand2["AttachVolume"] = "attach_volume";
|
|
51
|
+
ActionCommand2["DetachVolume"] = "detach_volume";
|
|
52
|
+
ActionCommand2["ResizeVolume"] = "resize_volume";
|
|
53
|
+
ActionCommand2["VolumeChangeProtection"] = "volume_change_protection";
|
|
54
|
+
ActionCommand2["AddSubnet"] = "add_subnet";
|
|
55
|
+
ActionCommand2["DeleteSubnet"] = "delete_subnet";
|
|
56
|
+
ActionCommand2["AddRoute"] = "add_route";
|
|
57
|
+
ActionCommand2["DeleteRoute"] = "delete_route";
|
|
58
|
+
ActionCommand2["ChangeIpRange"] = "change_ip_range";
|
|
59
|
+
ActionCommand2["NetworkChangeProtection"] = "network_change_protection";
|
|
60
|
+
ActionCommand2["AssignFloatingIp"] = "assign_floating_ip";
|
|
61
|
+
ActionCommand2["UnassignFloatingIp"] = "unassign_floating_ip";
|
|
62
|
+
ActionCommand2["FloatingIpChangeDnsPtr"] = "floating_ip_change_dns_ptr";
|
|
63
|
+
ActionCommand2["FloatingIpChangeProtection"] = "floating_ip_change_protection";
|
|
64
|
+
ActionCommand2["CreateLoadBalancer"] = "create_load_balancer";
|
|
65
|
+
ActionCommand2["DeleteLoadBalancer"] = "delete_load_balancer";
|
|
66
|
+
ActionCommand2["AddTarget"] = "add_target";
|
|
67
|
+
ActionCommand2["RemoveTarget"] = "remove_target";
|
|
68
|
+
ActionCommand2["AddService"] = "add_service";
|
|
69
|
+
ActionCommand2["UpdateService"] = "update_service";
|
|
70
|
+
ActionCommand2["DeleteService"] = "delete_service";
|
|
71
|
+
ActionCommand2["LoadBalancerAttachToNetwork"] = "load_balancer_attach_to_network";
|
|
72
|
+
ActionCommand2["LoadBalancerDetachFromNetwork"] = "load_balancer_detach_from_network";
|
|
73
|
+
ActionCommand2["ChangeAlgorithm"] = "change_algorithm";
|
|
74
|
+
ActionCommand2["ChangeType"] = "change_type";
|
|
75
|
+
ActionCommand2["LoadBalancerChangeProtection"] = "load_balancer_change_protection";
|
|
76
|
+
ActionCommand2["IssueCertificate"] = "issue_certificate";
|
|
77
|
+
ActionCommand2["RetryCertificate"] = "retry_certificate";
|
|
78
|
+
ActionCommand2["SetFirewallRules"] = "set_firewall_rules";
|
|
79
|
+
ActionCommand2["ApplyFirewall"] = "apply_firewall";
|
|
80
|
+
ActionCommand2["RemoveFirewall"] = "remove_firewall";
|
|
81
|
+
ActionCommand2["FirewallChangeProtection"] = "firewall_change_protection";
|
|
82
|
+
ActionCommand2["ImageChangeProtection"] = "image_change_protection";
|
|
83
|
+
})(ActionCommand ||= {});
|
|
84
|
+
var ResourceType;
|
|
85
|
+
((ResourceType2) => {
|
|
86
|
+
ResourceType2["Server"] = "server";
|
|
87
|
+
ResourceType2["Volume"] = "volume";
|
|
88
|
+
ResourceType2["Network"] = "network";
|
|
89
|
+
ResourceType2["FloatingIp"] = "floating_ip";
|
|
90
|
+
ResourceType2["LoadBalancer"] = "load_balancer";
|
|
91
|
+
ResourceType2["Certificate"] = "certificate";
|
|
92
|
+
ResourceType2["Firewall"] = "firewall";
|
|
93
|
+
ResourceType2["Image"] = "image";
|
|
94
|
+
})(ResourceType ||= {});
|
|
95
|
+
export {
|
|
96
|
+
VolumeStatus,
|
|
97
|
+
ResourceType,
|
|
98
|
+
EnvironmentStatus,
|
|
99
|
+
ActionStatus,
|
|
100
|
+
ActionCommand
|
|
101
|
+
};
|
package/dist/volumes.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
+
for (let key of __getOwnPropNames(mod))
|
|
11
|
+
if (!__hasOwnProp.call(to, key))
|
|
12
|
+
__defProp(to, key, {
|
|
13
|
+
get: () => mod[key],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __require = import.meta.require;
|
|
19
|
+
|
|
20
|
+
// src/volumes.ts
|
|
21
|
+
class VolumeOperations {
|
|
22
|
+
client;
|
|
23
|
+
constructor(client) {
|
|
24
|
+
this.client = client;
|
|
25
|
+
}
|
|
26
|
+
async list(options) {
|
|
27
|
+
const params = new URLSearchParams;
|
|
28
|
+
if (options?.name)
|
|
29
|
+
params.set("name", options.name);
|
|
30
|
+
if (options?.status)
|
|
31
|
+
params.set("status", options.status);
|
|
32
|
+
if (options?.sort)
|
|
33
|
+
params.set("sort", options.sort);
|
|
34
|
+
if (options?.label_selector)
|
|
35
|
+
params.set("label_selector", options.label_selector);
|
|
36
|
+
const endpoint = `/volumes${params.toString() ? `?${params}` : ""}`;
|
|
37
|
+
const response = await this.client.request(endpoint);
|
|
38
|
+
return response.volumes || [];
|
|
39
|
+
}
|
|
40
|
+
async get(id) {
|
|
41
|
+
const response = await this.client.request(`/volumes/${id}`);
|
|
42
|
+
return response.volume;
|
|
43
|
+
}
|
|
44
|
+
async create(options) {
|
|
45
|
+
const response = await this.client.request("/volumes", {
|
|
46
|
+
method: "POST",
|
|
47
|
+
body: JSON.stringify({
|
|
48
|
+
name: options.name,
|
|
49
|
+
size: options.size,
|
|
50
|
+
server: options.server,
|
|
51
|
+
location: options.location,
|
|
52
|
+
automount: options.automount ?? true,
|
|
53
|
+
format: options.format,
|
|
54
|
+
labels: options.labels
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
async delete(id) {
|
|
60
|
+
const response = await this.client.request(`/volumes/${id}`, {
|
|
61
|
+
method: "DELETE"
|
|
62
|
+
});
|
|
63
|
+
return response.action;
|
|
64
|
+
}
|
|
65
|
+
async attach(volumeId, serverId, automount = true) {
|
|
66
|
+
const response = await this.client.request(`/volumes/${volumeId}/actions/attach`, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
body: JSON.stringify({
|
|
69
|
+
server: serverId,
|
|
70
|
+
automount
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
return response.action;
|
|
74
|
+
}
|
|
75
|
+
async detach(volumeId) {
|
|
76
|
+
const response = await this.client.request(`/volumes/${volumeId}/actions/detach`, {
|
|
77
|
+
method: "POST"
|
|
78
|
+
});
|
|
79
|
+
return response.action;
|
|
80
|
+
}
|
|
81
|
+
async resize(volumeId, size) {
|
|
82
|
+
const response = await this.client.request(`/volumes/${volumeId}/actions/resize`, {
|
|
83
|
+
method: "POST",
|
|
84
|
+
body: JSON.stringify({ size })
|
|
85
|
+
});
|
|
86
|
+
return response.action;
|
|
87
|
+
}
|
|
88
|
+
async changeProtection(volumeId, deleteProtection) {
|
|
89
|
+
const response = await this.client.request(`/volumes/${volumeId}/actions/change_protection`, {
|
|
90
|
+
method: "POST",
|
|
91
|
+
body: JSON.stringify({
|
|
92
|
+
delete: deleteProtection
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
return response.action;
|
|
96
|
+
}
|
|
97
|
+
async updateLabels(volumeId, labels) {
|
|
98
|
+
const response = await this.client.request(`/volumes/${volumeId}`, {
|
|
99
|
+
method: "PUT",
|
|
100
|
+
body: JSON.stringify({ labels })
|
|
101
|
+
});
|
|
102
|
+
return response.volume;
|
|
103
|
+
}
|
|
104
|
+
static calculatePrice(sizeInGB) {
|
|
105
|
+
const PRICE_PER_GB_MONTHLY = 0.008;
|
|
106
|
+
const HOURS_PER_MONTH = 730;
|
|
107
|
+
const monthly = sizeInGB * PRICE_PER_GB_MONTHLY;
|
|
108
|
+
const hourly = monthly / HOURS_PER_MONTH;
|
|
109
|
+
return {
|
|
110
|
+
size: sizeInGB,
|
|
111
|
+
monthly: Math.round(monthly * 100) / 100,
|
|
112
|
+
hourly: Math.round(hourly * 1e4) / 1e4,
|
|
113
|
+
currency: "EUR"
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
VolumeOperations
|
|
119
|
+
};
|