@nilovonjs/hcloud-js 1.0.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/README.md +90 -0
- package/package.json +70 -0
- package/src/apis/actions/index.ts +113 -0
- package/src/apis/actions/schemas.ts +59 -0
- package/src/apis/actions/types.ts +77 -0
- package/src/apis/certificates/index.ts +326 -0
- package/src/apis/certificates/schemas.ts +140 -0
- package/src/apis/certificates/types.ts +176 -0
- package/src/apis/common/schemas.ts +19 -0
- package/src/apis/dns/index.ts +961 -0
- package/src/apis/dns/schemas.ts +437 -0
- package/src/apis/dns/types.ts +397 -0
- package/src/apis/firewalls/index.ts +469 -0
- package/src/apis/firewalls/schemas.ts +274 -0
- package/src/apis/firewalls/types.ts +205 -0
- package/src/apis/floating-ips/index.ts +466 -0
- package/src/apis/floating-ips/schemas.ts +203 -0
- package/src/apis/floating-ips/types.ts +207 -0
- package/src/apis/images/index.ts +195 -0
- package/src/apis/images/schemas.ts +113 -0
- package/src/apis/images/types.ts +124 -0
- package/src/apis/isos/index.ts +91 -0
- package/src/apis/isos/schemas.ts +43 -0
- package/src/apis/isos/types.ts +60 -0
- package/src/apis/load-balancers/index.ts +892 -0
- package/src/apis/load-balancers/schemas.ts +561 -0
- package/src/apis/load-balancers/types.ts +361 -0
- package/src/apis/locations/index.ts +176 -0
- package/src/apis/locations/schemas.ts +83 -0
- package/src/apis/locations/types.ts +113 -0
- package/src/apis/networks/index.ts +544 -0
- package/src/apis/networks/schemas.ts +279 -0
- package/src/apis/networks/types.ts +243 -0
- package/src/apis/placement-groups/index.ts +212 -0
- package/src/apis/placement-groups/schemas.ts +90 -0
- package/src/apis/placement-groups/types.ts +99 -0
- package/src/apis/pricing/index.ts +42 -0
- package/src/apis/pricing/schemas.ts +93 -0
- package/src/apis/pricing/types.ts +71 -0
- package/src/apis/primary-ips/index.ts +467 -0
- package/src/apis/primary-ips/schemas.ts +221 -0
- package/src/apis/primary-ips/types.ts +221 -0
- package/src/apis/server-types/index.ts +93 -0
- package/src/apis/server-types/schemas.ts +29 -0
- package/src/apis/server-types/types.ts +43 -0
- package/src/apis/servers/index.ts +378 -0
- package/src/apis/servers/schemas.ts +771 -0
- package/src/apis/servers/types.ts +538 -0
- package/src/apis/ssh-keys/index.ts +204 -0
- package/src/apis/ssh-keys/schemas.ts +84 -0
- package/src/apis/ssh-keys/types.ts +106 -0
- package/src/apis/volumes/index.ts +452 -0
- package/src/apis/volumes/schemas.ts +195 -0
- package/src/apis/volumes/types.ts +197 -0
- package/src/auth/index.ts +26 -0
- package/src/base/index.ts +10 -0
- package/src/client/index.ts +388 -0
- package/src/config/index.ts +34 -0
- package/src/errors/index.ts +38 -0
- package/src/index.ts +799 -0
- package/src/types/index.ts +37 -0
- package/src/validation/index.ts +109 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hetzner Cloud Volumes API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { HCloudClient } from "../../client/index";
|
|
7
|
+
import type {
|
|
8
|
+
ListVolumesParams,
|
|
9
|
+
ListVolumesResponse,
|
|
10
|
+
CreateVolumeParams,
|
|
11
|
+
CreateVolumeResponse,
|
|
12
|
+
GetVolumeResponse,
|
|
13
|
+
UpdateVolumeParams,
|
|
14
|
+
UpdateVolumeResponse,
|
|
15
|
+
DeleteVolumeResponse,
|
|
16
|
+
ListVolumeActionsParams,
|
|
17
|
+
ListVolumeActionsResponse,
|
|
18
|
+
GetVolumeActionResponse,
|
|
19
|
+
AttachVolumeToServerParams,
|
|
20
|
+
AttachVolumeToServerResponse,
|
|
21
|
+
DetachVolumeResponse,
|
|
22
|
+
ResizeVolumeParams,
|
|
23
|
+
ResizeVolumeResponse,
|
|
24
|
+
ChangeVolumeProtectionParams,
|
|
25
|
+
ChangeVolumeProtectionResponse,
|
|
26
|
+
} from "../../apis/volumes/types";
|
|
27
|
+
import { validate } from "../../validation/index";
|
|
28
|
+
import {
|
|
29
|
+
listVolumesResponseSchema,
|
|
30
|
+
createVolumeRequestSchema,
|
|
31
|
+
createVolumeResponseSchema,
|
|
32
|
+
getVolumeResponseSchema,
|
|
33
|
+
updateVolumeRequestSchema,
|
|
34
|
+
updateVolumeResponseSchema,
|
|
35
|
+
deleteVolumeResponseSchema,
|
|
36
|
+
listVolumeActionsResponseSchema,
|
|
37
|
+
getVolumeActionResponseSchema,
|
|
38
|
+
attachVolumeToServerRequestSchema,
|
|
39
|
+
attachVolumeToServerResponseSchema,
|
|
40
|
+
detachVolumeRequestSchema,
|
|
41
|
+
detachVolumeResponseSchema,
|
|
42
|
+
resizeVolumeRequestSchema,
|
|
43
|
+
resizeVolumeResponseSchema,
|
|
44
|
+
changeVolumeProtectionRequestSchema,
|
|
45
|
+
changeVolumeProtectionResponseSchema,
|
|
46
|
+
} from "../../apis/volumes/schemas";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Volumes API client
|
|
50
|
+
*/
|
|
51
|
+
export class VolumesClient {
|
|
52
|
+
constructor(private readonly client: HCloudClient) {}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns all Volume objects.
|
|
56
|
+
*
|
|
57
|
+
* @param params - Query parameters for filtering and pagination
|
|
58
|
+
* @returns Promise resolving to list of volumes with pagination metadata
|
|
59
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-list-volumes
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
64
|
+
*
|
|
65
|
+
* // List all volumes
|
|
66
|
+
* const result = await client.volumes.list();
|
|
67
|
+
*
|
|
68
|
+
* // List volumes with filters
|
|
69
|
+
* const volumes = await client.volumes.list({
|
|
70
|
+
* name: 'my-volume',
|
|
71
|
+
* label_selector: 'environment=production',
|
|
72
|
+
* sort: ['name:asc'],
|
|
73
|
+
* page: 1,
|
|
74
|
+
* per_page: 50
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
async list(params?: ListVolumesParams): Promise<ListVolumesResponse> {
|
|
79
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
80
|
+
|
|
81
|
+
if (params?.name) {
|
|
82
|
+
queryParams.name = params.name;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (params?.label_selector) {
|
|
86
|
+
queryParams.label_selector = params.label_selector;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (params?.sort) {
|
|
90
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (params?.page !== undefined) {
|
|
94
|
+
queryParams.page = params.page;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (params?.per_page !== undefined) {
|
|
98
|
+
queryParams.per_page = params.per_page;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const response = await this.client.get<unknown>("/volumes", queryParams);
|
|
102
|
+
|
|
103
|
+
return validate(listVolumesResponseSchema, response, {
|
|
104
|
+
context: "List volumes response",
|
|
105
|
+
detailed: true,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new Volume.
|
|
111
|
+
*
|
|
112
|
+
* @param params - Parameters for creating the volume
|
|
113
|
+
* @returns Promise resolving to the created volume and action
|
|
114
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-create-a-volume
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
119
|
+
*
|
|
120
|
+
* // Create a volume
|
|
121
|
+
* const volume = await client.volumes.create({
|
|
122
|
+
* name: 'my-volume',
|
|
123
|
+
* size: 100,
|
|
124
|
+
* location: 'nbg1',
|
|
125
|
+
* labels: { environment: 'production' }
|
|
126
|
+
* });
|
|
127
|
+
*
|
|
128
|
+
* // Create and attach to a server
|
|
129
|
+
* const volume = await client.volumes.create({
|
|
130
|
+
* name: 'my-volume',
|
|
131
|
+
* size: 100,
|
|
132
|
+
* server: 12345,
|
|
133
|
+
* automount: true
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
async create(params: CreateVolumeParams): Promise<CreateVolumeResponse> {
|
|
138
|
+
const validatedParams = validate(createVolumeRequestSchema, params, {
|
|
139
|
+
context: "Create volume request",
|
|
140
|
+
detailed: true,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const response = await this.client.post<unknown>("/volumes", validatedParams);
|
|
144
|
+
|
|
145
|
+
return validate(createVolumeResponseSchema, response, {
|
|
146
|
+
context: "Create volume response",
|
|
147
|
+
detailed: true,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Returns a specific Volume object.
|
|
153
|
+
*
|
|
154
|
+
* @param id - ID of the Volume
|
|
155
|
+
* @returns Promise resolving to the volume
|
|
156
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-get-a-volume
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
161
|
+
*
|
|
162
|
+
* // Get a volume by ID
|
|
163
|
+
* const volume = await client.volumes.get(12345);
|
|
164
|
+
* console.log(volume.volume.name);
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
async get(id: number): Promise<GetVolumeResponse> {
|
|
168
|
+
const response = await this.client.get<unknown>(`/volumes/${id}`);
|
|
169
|
+
|
|
170
|
+
return validate(getVolumeResponseSchema, response, {
|
|
171
|
+
context: "Get volume response",
|
|
172
|
+
detailed: true,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Updates the Volume.
|
|
178
|
+
*
|
|
179
|
+
* You can update a Volume's name and labels.
|
|
180
|
+
*
|
|
181
|
+
* @param id - ID of the Volume
|
|
182
|
+
* @param params - Parameters to update (name and/or labels)
|
|
183
|
+
* @returns Promise resolving to the updated volume
|
|
184
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-update-a-volume
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
189
|
+
*
|
|
190
|
+
* // Update volume name
|
|
191
|
+
* const updated = await client.volumes.update(12345, {
|
|
192
|
+
* name: 'new-volume-name'
|
|
193
|
+
* });
|
|
194
|
+
*
|
|
195
|
+
* // Update labels
|
|
196
|
+
* const updated = await client.volumes.update(12345, {
|
|
197
|
+
* labels: { environment: 'production', team: 'backend' }
|
|
198
|
+
* });
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
async update(id: number, params: UpdateVolumeParams): Promise<UpdateVolumeResponse> {
|
|
202
|
+
const validatedParams = validate(updateVolumeRequestSchema, params, {
|
|
203
|
+
context: "Update volume request",
|
|
204
|
+
detailed: true,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const response = await this.client.put<unknown>(`/volumes/${id}`, validatedParams);
|
|
208
|
+
|
|
209
|
+
return validate(updateVolumeResponseSchema, response, {
|
|
210
|
+
context: "Update volume response",
|
|
211
|
+
detailed: true,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Deletes a Volume.
|
|
217
|
+
*
|
|
218
|
+
* @param id - ID of the Volume
|
|
219
|
+
* @returns Promise resolving to the delete action
|
|
220
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-delete-a-volume
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
225
|
+
*
|
|
226
|
+
* // Delete a volume
|
|
227
|
+
* const result = await client.volumes.delete(12345);
|
|
228
|
+
* if (result.action) {
|
|
229
|
+
* console.log(`Delete action ID: ${result.action.id}`);
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
async delete(id: number): Promise<DeleteVolumeResponse> {
|
|
234
|
+
const response = await this.client.delete<unknown>(`/volumes/${id}`);
|
|
235
|
+
|
|
236
|
+
return validate(deleteVolumeResponseSchema, response, {
|
|
237
|
+
context: "Delete volume response",
|
|
238
|
+
detailed: true,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Returns all Action objects for a Volume.
|
|
244
|
+
*
|
|
245
|
+
* @param id - ID of the Volume
|
|
246
|
+
* @param params - Query parameters for filtering and pagination
|
|
247
|
+
* @returns Promise resolving to list of actions with pagination metadata
|
|
248
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-list-actions-for-a-volume
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
253
|
+
*
|
|
254
|
+
* // List all actions for a volume
|
|
255
|
+
* const actions = await client.volumes.listActions(12345);
|
|
256
|
+
*
|
|
257
|
+
* // List actions with filters
|
|
258
|
+
* const runningActions = await client.volumes.listActions(12345, {
|
|
259
|
+
* status: ['running'],
|
|
260
|
+
* sort: ['started:desc']
|
|
261
|
+
* });
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
async listActions(
|
|
265
|
+
id: number,
|
|
266
|
+
params?: ListVolumeActionsParams,
|
|
267
|
+
): Promise<ListVolumeActionsResponse> {
|
|
268
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
269
|
+
|
|
270
|
+
if (params?.sort) {
|
|
271
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (params?.status) {
|
|
275
|
+
queryParams.status = Array.isArray(params.status) ? params.status : [params.status];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (params?.page !== undefined) {
|
|
279
|
+
queryParams.page = params.page;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (params?.per_page !== undefined) {
|
|
283
|
+
queryParams.per_page = params.per_page;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const response = await this.client.get<unknown>(`/volumes/${id}/actions`, queryParams);
|
|
287
|
+
|
|
288
|
+
return validate(listVolumeActionsResponseSchema, response, {
|
|
289
|
+
context: "List volume actions response",
|
|
290
|
+
detailed: true,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Returns a specific Action object for a Volume.
|
|
296
|
+
*
|
|
297
|
+
* @param id - ID of the Volume
|
|
298
|
+
* @param actionId - ID of the Action
|
|
299
|
+
* @returns Promise resolving to the action
|
|
300
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-get-an-action-for-a-volume
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
305
|
+
*
|
|
306
|
+
* // Get an action by ID
|
|
307
|
+
* const action = await client.volumes.getAction(12345, 67890);
|
|
308
|
+
* console.log(action.action.command);
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
async getAction(id: number, actionId: number): Promise<GetVolumeActionResponse> {
|
|
312
|
+
const response = await this.client.get<unknown>(`/volumes/${id}/actions/${actionId}`);
|
|
313
|
+
|
|
314
|
+
return validate(getVolumeActionResponseSchema, response, {
|
|
315
|
+
context: "Get volume action response",
|
|
316
|
+
detailed: true,
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Attaches a Volume to a Server.
|
|
322
|
+
*
|
|
323
|
+
* @param id - ID of the Volume
|
|
324
|
+
* @param params - Server to attach to
|
|
325
|
+
* @returns Promise resolving to the action
|
|
326
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-attach-volume-to-a-server
|
|
327
|
+
*
|
|
328
|
+
* @example
|
|
329
|
+
* ```typescript
|
|
330
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
331
|
+
*
|
|
332
|
+
* const result = await client.volumes.attachToServer(12345, {
|
|
333
|
+
* server: 67890,
|
|
334
|
+
* automount: true
|
|
335
|
+
* });
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
async attachToServer(
|
|
339
|
+
id: number,
|
|
340
|
+
params: AttachVolumeToServerParams,
|
|
341
|
+
): Promise<AttachVolumeToServerResponse> {
|
|
342
|
+
const validatedParams = validate(attachVolumeToServerRequestSchema, params, {
|
|
343
|
+
context: "Attach volume to server request",
|
|
344
|
+
detailed: true,
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
const response = await this.client.post<unknown>(
|
|
348
|
+
`/volumes/${id}/actions/attach`,
|
|
349
|
+
validatedParams,
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
return validate(attachVolumeToServerResponseSchema, response, {
|
|
353
|
+
context: "Attach volume to server response",
|
|
354
|
+
detailed: true,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Detaches a Volume from a Server.
|
|
360
|
+
*
|
|
361
|
+
* @param id - ID of the Volume
|
|
362
|
+
* @returns Promise resolving to the action
|
|
363
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-detach-volume
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```typescript
|
|
367
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
368
|
+
*
|
|
369
|
+
* const result = await client.volumes.detach(12345);
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
async detach(id: number): Promise<DetachVolumeResponse> {
|
|
373
|
+
const response = await this.client.post<unknown>(`/volumes/${id}/actions/detach`, {});
|
|
374
|
+
|
|
375
|
+
return validate(detachVolumeResponseSchema, response, {
|
|
376
|
+
context: "Detach volume response",
|
|
377
|
+
detailed: true,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Resizes a Volume.
|
|
383
|
+
*
|
|
384
|
+
* @param id - ID of the Volume
|
|
385
|
+
* @param params - New size (in GB)
|
|
386
|
+
* @returns Promise resolving to the action
|
|
387
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-resize-volume
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
392
|
+
*
|
|
393
|
+
* const result = await client.volumes.resize(12345, {
|
|
394
|
+
* size: 200
|
|
395
|
+
* });
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
async resize(id: number, params: ResizeVolumeParams): Promise<ResizeVolumeResponse> {
|
|
399
|
+
const validatedParams = validate(resizeVolumeRequestSchema, params, {
|
|
400
|
+
context: "Resize volume request",
|
|
401
|
+
detailed: true,
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
const response = await this.client.post<unknown>(
|
|
405
|
+
`/volumes/${id}/actions/resize`,
|
|
406
|
+
validatedParams,
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
return validate(resizeVolumeResponseSchema, response, {
|
|
410
|
+
context: "Resize volume response",
|
|
411
|
+
detailed: true,
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Changes the Protection configuration of a Volume.
|
|
417
|
+
*
|
|
418
|
+
* @param id - ID of the Volume
|
|
419
|
+
* @param params - Protection configuration
|
|
420
|
+
* @returns Promise resolving to the action
|
|
421
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-change-volume-protection
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```typescript
|
|
425
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
426
|
+
*
|
|
427
|
+
* // Enable delete protection
|
|
428
|
+
* const result = await client.volumes.changeProtection(12345, {
|
|
429
|
+
* delete: true
|
|
430
|
+
* });
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
async changeProtection(
|
|
434
|
+
id: number,
|
|
435
|
+
params: ChangeVolumeProtectionParams,
|
|
436
|
+
): Promise<ChangeVolumeProtectionResponse> {
|
|
437
|
+
const validatedParams = validate(changeVolumeProtectionRequestSchema, params, {
|
|
438
|
+
context: "Change volume protection request",
|
|
439
|
+
detailed: true,
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
const response = await this.client.post<unknown>(
|
|
443
|
+
`/volumes/${id}/actions/change_protection`,
|
|
444
|
+
validatedParams,
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
return validate(changeVolumeProtectionResponseSchema, response, {
|
|
448
|
+
context: "Change volume protection response",
|
|
449
|
+
detailed: true,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for Hetzner Cloud Volumes API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { actionSchema, actionResourceSchema } from "../../apis/actions/schemas";
|
|
8
|
+
import { paginationMetaSchema } from "../../apis/common/schemas";
|
|
9
|
+
import { locationSchema } from "../../apis/servers/schemas";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Volume status schema
|
|
13
|
+
*/
|
|
14
|
+
export const volumeStatusSchema = z.enum(["creating", "available", "deleting"]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Volume protection schema
|
|
18
|
+
*/
|
|
19
|
+
export const volumeProtectionSchema = z.object({
|
|
20
|
+
delete: z.boolean(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Volume schema
|
|
25
|
+
*/
|
|
26
|
+
export const volumeSchema = z
|
|
27
|
+
.object({
|
|
28
|
+
id: z.number(),
|
|
29
|
+
name: z.string(),
|
|
30
|
+
status: volumeStatusSchema,
|
|
31
|
+
server: z.number().nullable(),
|
|
32
|
+
location: locationSchema,
|
|
33
|
+
size: z.number(),
|
|
34
|
+
linux_device: z.string(),
|
|
35
|
+
created: z.string(),
|
|
36
|
+
format: z.string().nullable(),
|
|
37
|
+
labels: z.record(z.string(), z.string()),
|
|
38
|
+
protection: volumeProtectionSchema,
|
|
39
|
+
blocking: z.array(actionResourceSchema).optional(),
|
|
40
|
+
})
|
|
41
|
+
.passthrough();
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* List Volumes response schema
|
|
45
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-list-volumes
|
|
46
|
+
*/
|
|
47
|
+
export const listVolumesResponseSchema = z.object({
|
|
48
|
+
volumes: z.array(volumeSchema),
|
|
49
|
+
meta: z
|
|
50
|
+
.object({
|
|
51
|
+
pagination: paginationMetaSchema,
|
|
52
|
+
})
|
|
53
|
+
.optional(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create Volume request schema
|
|
58
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-create-a-volume
|
|
59
|
+
*/
|
|
60
|
+
export const createVolumeRequestSchema = z.object({
|
|
61
|
+
name: z.string(),
|
|
62
|
+
size: z.number(),
|
|
63
|
+
location: z.string().optional(),
|
|
64
|
+
format: z.string().optional(),
|
|
65
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
66
|
+
automount: z.boolean().optional(),
|
|
67
|
+
server: z.number().optional(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create Volume response schema
|
|
72
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-create-a-volume
|
|
73
|
+
*/
|
|
74
|
+
export const createVolumeResponseSchema = z.object({
|
|
75
|
+
volume: volumeSchema,
|
|
76
|
+
action: actionSchema,
|
|
77
|
+
next_actions: z.array(actionSchema).optional(),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get Volume response schema
|
|
82
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-get-a-volume
|
|
83
|
+
*/
|
|
84
|
+
export const getVolumeResponseSchema = z.object({
|
|
85
|
+
volume: volumeSchema,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Update Volume request schema
|
|
90
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-update-a-volume
|
|
91
|
+
*/
|
|
92
|
+
export const updateVolumeRequestSchema = z.object({
|
|
93
|
+
name: z.string().optional(),
|
|
94
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Update Volume response schema
|
|
99
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-update-a-volume
|
|
100
|
+
*/
|
|
101
|
+
export const updateVolumeResponseSchema = z.object({
|
|
102
|
+
volume: volumeSchema,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Delete Volume response schema
|
|
107
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-delete-a-volume
|
|
108
|
+
*/
|
|
109
|
+
export const deleteVolumeResponseSchema = z.object({
|
|
110
|
+
action: actionSchema.optional(),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* List Volume Actions response schema
|
|
115
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-list-actions-for-a-volume
|
|
116
|
+
*/
|
|
117
|
+
export const listVolumeActionsResponseSchema = z.object({
|
|
118
|
+
actions: z.array(actionSchema),
|
|
119
|
+
meta: z
|
|
120
|
+
.object({
|
|
121
|
+
pagination: paginationMetaSchema,
|
|
122
|
+
})
|
|
123
|
+
.optional(),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get Volume Action response schema
|
|
128
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-get-an-action-for-a-volume
|
|
129
|
+
*/
|
|
130
|
+
export const getVolumeActionResponseSchema = z.object({
|
|
131
|
+
action: actionSchema,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Attach Volume to Server request schema
|
|
136
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-attach-volume-to-a-server
|
|
137
|
+
*/
|
|
138
|
+
export const attachVolumeToServerRequestSchema = z.object({
|
|
139
|
+
server: z.number(),
|
|
140
|
+
automount: z.boolean().optional(),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Attach Volume to Server response schema
|
|
145
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-attach-volume-to-a-server
|
|
146
|
+
*/
|
|
147
|
+
export const attachVolumeToServerResponseSchema = z.object({
|
|
148
|
+
action: actionSchema,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Detach Volume request schema
|
|
153
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-detach-volume
|
|
154
|
+
*/
|
|
155
|
+
export const detachVolumeRequestSchema = z.object({});
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Detach Volume response schema
|
|
159
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-detach-volume
|
|
160
|
+
*/
|
|
161
|
+
export const detachVolumeResponseSchema = z.object({
|
|
162
|
+
action: actionSchema,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Resize Volume request schema
|
|
167
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-resize-volume
|
|
168
|
+
*/
|
|
169
|
+
export const resizeVolumeRequestSchema = z.object({
|
|
170
|
+
size: z.number(),
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Resize Volume response schema
|
|
175
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-resize-volume
|
|
176
|
+
*/
|
|
177
|
+
export const resizeVolumeResponseSchema = z.object({
|
|
178
|
+
action: actionSchema,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Change Volume Protection request schema
|
|
183
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-change-volume-protection
|
|
184
|
+
*/
|
|
185
|
+
export const changeVolumeProtectionRequestSchema = z.object({
|
|
186
|
+
delete: z.boolean(),
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Change Volume Protection response schema
|
|
191
|
+
* @see https://docs.hetzner.cloud/reference/cloud#volumes-change-volume-protection
|
|
192
|
+
*/
|
|
193
|
+
export const changeVolumeProtectionResponseSchema = z.object({
|
|
194
|
+
action: actionSchema,
|
|
195
|
+
});
|