@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,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Hetzner Cloud Floating IPs API
|
|
3
|
+
* Types are inferred from Zod schemas
|
|
4
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// biome-ignore assist/source/organizeImports: we need to import the schemas first
|
|
8
|
+
import {
|
|
9
|
+
listFloatingIPsResponseSchema,
|
|
10
|
+
createFloatingIPRequestSchema,
|
|
11
|
+
createFloatingIPResponseSchema,
|
|
12
|
+
getFloatingIPResponseSchema,
|
|
13
|
+
updateFloatingIPRequestSchema,
|
|
14
|
+
updateFloatingIPResponseSchema,
|
|
15
|
+
deleteFloatingIPResponseSchema,
|
|
16
|
+
listFloatingIPActionsResponseSchema,
|
|
17
|
+
getFloatingIPActionResponseSchema,
|
|
18
|
+
assignFloatingIPToServerRequestSchema,
|
|
19
|
+
assignFloatingIPToServerResponseSchema,
|
|
20
|
+
changeFloatingIPReverseDNSRequestSchema,
|
|
21
|
+
changeFloatingIPReverseDNSResponseSchema,
|
|
22
|
+
changeFloatingIPProtectionRequestSchema,
|
|
23
|
+
changeFloatingIPProtectionResponseSchema,
|
|
24
|
+
unassignFloatingIPRequestSchema,
|
|
25
|
+
unassignFloatingIPResponseSchema,
|
|
26
|
+
floatingIpSchema,
|
|
27
|
+
floatingIpTypeSchema,
|
|
28
|
+
floatingIpDnsPointerSchema,
|
|
29
|
+
floatingIpProtectionSchema,
|
|
30
|
+
} from "../../apis/floating-ips/schemas";
|
|
31
|
+
import type { z } from "zod";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Floating IP type
|
|
35
|
+
*/
|
|
36
|
+
export type FloatingIPType = z.infer<typeof floatingIpTypeSchema>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Floating IP DNS pointer
|
|
40
|
+
*/
|
|
41
|
+
export type FloatingIPDnsPointer = z.infer<typeof floatingIpDnsPointerSchema>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Floating IP protection
|
|
45
|
+
*/
|
|
46
|
+
export type FloatingIPProtection = z.infer<typeof floatingIpProtectionSchema>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Floating IP
|
|
50
|
+
*/
|
|
51
|
+
export type FloatingIP = z.infer<typeof floatingIpSchema>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* List Floating IPs query parameters
|
|
55
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-list-floating-ips
|
|
56
|
+
*/
|
|
57
|
+
export interface ListFloatingIPsParams {
|
|
58
|
+
/**
|
|
59
|
+
* Can be used to filter Floating IPs by their name. The response will only contain the Floating IP matching the specified name.
|
|
60
|
+
*/
|
|
61
|
+
name?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Can be used multiple times. Choices: id, id:asc, id:desc, name, name:asc, name:desc, created, created:asc, created:desc
|
|
64
|
+
* @see https://docs.hetzner.cloud/reference/cloud#sorting
|
|
65
|
+
*/
|
|
66
|
+
sort?: string | string[];
|
|
67
|
+
/**
|
|
68
|
+
* Can be used to filter Floating IPs by labels. The response will only contain Floating IPs matching the label selector.
|
|
69
|
+
*/
|
|
70
|
+
label_selector?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
73
|
+
*/
|
|
74
|
+
page?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
77
|
+
*/
|
|
78
|
+
per_page?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* List Floating IPs response
|
|
83
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-list-floating-ips
|
|
84
|
+
*/
|
|
85
|
+
export type ListFloatingIPsResponse = z.infer<typeof listFloatingIPsResponseSchema>;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Create Floating IP parameters
|
|
89
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-create-a-floating-ip
|
|
90
|
+
*/
|
|
91
|
+
export type CreateFloatingIPParams = z.infer<typeof createFloatingIPRequestSchema>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Create Floating IP response
|
|
95
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-create-a-floating-ip
|
|
96
|
+
*/
|
|
97
|
+
export type CreateFloatingIPResponse = z.infer<typeof createFloatingIPResponseSchema>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get Floating IP response
|
|
101
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-get-a-floating-ip
|
|
102
|
+
*/
|
|
103
|
+
export type GetFloatingIPResponse = z.infer<typeof getFloatingIPResponseSchema>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Update Floating IP parameters
|
|
107
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-update-a-floating-ip
|
|
108
|
+
*/
|
|
109
|
+
export type UpdateFloatingIPParams = z.infer<typeof updateFloatingIPRequestSchema>;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Update Floating IP response
|
|
113
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-update-a-floating-ip
|
|
114
|
+
*/
|
|
115
|
+
export type UpdateFloatingIPResponse = z.infer<typeof updateFloatingIPResponseSchema>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Delete Floating IP response
|
|
119
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-delete-a-floating-ip
|
|
120
|
+
*/
|
|
121
|
+
export type DeleteFloatingIPResponse = z.infer<typeof deleteFloatingIPResponseSchema>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* List Floating IP Actions query parameters
|
|
125
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-list-actions-for-a-floating-ip
|
|
126
|
+
*/
|
|
127
|
+
export interface ListFloatingIPActionsParams {
|
|
128
|
+
/**
|
|
129
|
+
* Can be used multiple times. Choices: id, id:asc, id:desc, command, command:asc, command:desc, status, status:asc, status:desc, progress, progress:asc, progress:desc, started, started:asc, started:desc, finished, finished:asc, finished:desc
|
|
130
|
+
* @see https://docs.hetzner.cloud/reference/cloud#sorting
|
|
131
|
+
*/
|
|
132
|
+
sort?: string | string[];
|
|
133
|
+
/**
|
|
134
|
+
* Can be used to filter Actions by status. The response will only contain Actions matching the status.
|
|
135
|
+
*/
|
|
136
|
+
status?: string | string[];
|
|
137
|
+
/**
|
|
138
|
+
* Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
139
|
+
*/
|
|
140
|
+
page?: number;
|
|
141
|
+
/**
|
|
142
|
+
* Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
143
|
+
*/
|
|
144
|
+
per_page?: number;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* List Floating IP Actions response
|
|
149
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-list-actions-for-a-floating-ip
|
|
150
|
+
*/
|
|
151
|
+
export type ListFloatingIPActionsResponse = z.infer<typeof listFloatingIPActionsResponseSchema>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Get Floating IP Action response
|
|
155
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-get-an-action-for-a-floating-ip
|
|
156
|
+
*/
|
|
157
|
+
export type GetFloatingIPActionResponse = z.infer<typeof getFloatingIPActionResponseSchema>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Assign Floating IP to Server parameters
|
|
161
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-assign-a-floating-ip-to-a-server
|
|
162
|
+
*/
|
|
163
|
+
export type AssignFloatingIPToServerParams = z.infer<typeof assignFloatingIPToServerRequestSchema>;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Assign Floating IP to Server response
|
|
167
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-assign-a-floating-ip-to-a-server
|
|
168
|
+
*/
|
|
169
|
+
export type AssignFloatingIPToServerResponse = z.infer<typeof assignFloatingIPToServerResponseSchema>;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Change Floating IP reverse DNS parameters
|
|
173
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-reverse-dns-records-for-a-floating-ip
|
|
174
|
+
*/
|
|
175
|
+
export type ChangeFloatingIPReverseDNSParams = z.infer<
|
|
176
|
+
typeof changeFloatingIPReverseDNSRequestSchema
|
|
177
|
+
>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Change Floating IP reverse DNS response
|
|
181
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-reverse-dns-records-for-a-floating-ip
|
|
182
|
+
*/
|
|
183
|
+
export type ChangeFloatingIPReverseDNSResponse = z.infer<
|
|
184
|
+
typeof changeFloatingIPReverseDNSResponseSchema
|
|
185
|
+
>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Change Floating IP Protection parameters
|
|
189
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-floating-ip-protection
|
|
190
|
+
*/
|
|
191
|
+
export type ChangeFloatingIPProtectionParams = z.infer<
|
|
192
|
+
typeof changeFloatingIPProtectionRequestSchema
|
|
193
|
+
>;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Change Floating IP Protection response
|
|
197
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-change-floating-ip-protection
|
|
198
|
+
*/
|
|
199
|
+
export type ChangeFloatingIPProtectionResponse = z.infer<
|
|
200
|
+
typeof changeFloatingIPProtectionResponseSchema
|
|
201
|
+
>;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Unassign Floating IP response
|
|
205
|
+
* @see https://docs.hetzner.cloud/reference/cloud#floating-ips-unassign-a-floating-ip
|
|
206
|
+
*/
|
|
207
|
+
export type UnassignFloatingIPResponse = z.infer<typeof unassignFloatingIPResponseSchema>;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hetzner Cloud Images API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { HCloudClient } from "@/client/index";
|
|
7
|
+
import { validate } from "@/validation/index";
|
|
8
|
+
import { deleteImageResponseSchema, getImageResponseSchema, listImagesResponseSchema, updateImageRequestSchema, updateImageResponseSchema } from "@/apis/images/schemas";
|
|
9
|
+
import type {
|
|
10
|
+
ListImagesParams,
|
|
11
|
+
ListImagesResponse,
|
|
12
|
+
GetImageResponse,
|
|
13
|
+
UpdateImageParams,
|
|
14
|
+
UpdateImageResponse,
|
|
15
|
+
DeleteImageResponse,
|
|
16
|
+
} from "@/apis/images/types";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Images API client
|
|
20
|
+
*/
|
|
21
|
+
export class ImagesClient {
|
|
22
|
+
constructor(private readonly client: HCloudClient) {}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns all Image objects.
|
|
26
|
+
*
|
|
27
|
+
* You can select specific Image types only and sort the results by using URI parameters.
|
|
28
|
+
*
|
|
29
|
+
* @param params - Query parameters for filtering and pagination
|
|
30
|
+
* @returns Promise resolving to list of images with pagination metadata
|
|
31
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-list-images
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
36
|
+
*
|
|
37
|
+
* // List all images
|
|
38
|
+
* const result = await client.images.list();
|
|
39
|
+
*
|
|
40
|
+
* // List images with filters
|
|
41
|
+
* const snapshots = await client.images.list({
|
|
42
|
+
* type: ['snapshot'],
|
|
43
|
+
* status: ['available'],
|
|
44
|
+
* label_selector: 'environment=production',
|
|
45
|
+
* sort: ['created:desc'],
|
|
46
|
+
* page: 1,
|
|
47
|
+
* per_page: 50
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
async list(params?: ListImagesParams): Promise<ListImagesResponse> {
|
|
52
|
+
// Build query parameters
|
|
53
|
+
const queryParams: Record<string, string | number | boolean | string[] | undefined> = {};
|
|
54
|
+
|
|
55
|
+
if (params?.type) {
|
|
56
|
+
// Convert single type to array for consistent handling
|
|
57
|
+
queryParams.type = Array.isArray(params.type) ? params.type : [params.type];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (params?.status) {
|
|
61
|
+
// Convert single status to array for consistent handling
|
|
62
|
+
queryParams.status = Array.isArray(params.status) ? params.status : [params.status];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (params?.name) {
|
|
66
|
+
queryParams.name = params.name;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (params?.label_selector) {
|
|
70
|
+
queryParams.label_selector = params.label_selector;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (params?.sort) {
|
|
74
|
+
// Convert single string to array for consistent handling
|
|
75
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (params?.architecture) {
|
|
79
|
+
// Convert single architecture to array for consistent handling
|
|
80
|
+
queryParams.architecture = Array.isArray(params.architecture)
|
|
81
|
+
? params.architecture
|
|
82
|
+
: [params.architecture];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (params?.bound_to !== undefined) {
|
|
86
|
+
queryParams.bound_to = params.bound_to;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (params?.include_deprecated !== undefined) {
|
|
90
|
+
queryParams.include_deprecated = params.include_deprecated;
|
|
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>("/images", queryParams);
|
|
102
|
+
|
|
103
|
+
// Validate response with Zod
|
|
104
|
+
return validate(listImagesResponseSchema, response, { context: "List images response" });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Returns a specific Image object.
|
|
109
|
+
*
|
|
110
|
+
* @param id - ID of the Image
|
|
111
|
+
* @returns Promise resolving to the image
|
|
112
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-get-an-image
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
117
|
+
*
|
|
118
|
+
* // Get an image by ID
|
|
119
|
+
* const image = await client.images.get(12345);
|
|
120
|
+
* console.log(image.image.name);
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
async get(id: number): Promise<GetImageResponse> {
|
|
124
|
+
const response = await this.client.get<unknown>(`/images/${id}`);
|
|
125
|
+
|
|
126
|
+
// Validate response with Zod
|
|
127
|
+
return validate(getImageResponseSchema, response, { context: "Get image response" });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Updates the Image. You may change the description or convert a Snapshot to a backup Image.
|
|
132
|
+
*
|
|
133
|
+
* Only callable on `snapshot` and `backup` image types.
|
|
134
|
+
*
|
|
135
|
+
* @param id - ID of the Image
|
|
136
|
+
* @param params - Parameters to update (description, type, and/or labels)
|
|
137
|
+
* @returns Promise resolving to the updated image
|
|
138
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-update-an-image
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
143
|
+
*
|
|
144
|
+
* // Update image description
|
|
145
|
+
* const updated = await client.images.update(12345, {
|
|
146
|
+
* description: 'Updated description'
|
|
147
|
+
* });
|
|
148
|
+
*
|
|
149
|
+
* // Update labels
|
|
150
|
+
* const updated = await client.images.update(12345, {
|
|
151
|
+
* labels: { environment: 'production', team: 'backend' }
|
|
152
|
+
* });
|
|
153
|
+
*
|
|
154
|
+
* // Convert snapshot to backup
|
|
155
|
+
* const updated = await client.images.update(12345, {
|
|
156
|
+
* type: 'snapshot'
|
|
157
|
+
* });
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
async update(id: number, params: UpdateImageParams): Promise<UpdateImageResponse> {
|
|
161
|
+
// Validate request parameters
|
|
162
|
+
const validatedParams = validate(updateImageRequestSchema, params, { context: "Update image request" });
|
|
163
|
+
|
|
164
|
+
// Make API request
|
|
165
|
+
const response = await this.client.put<unknown>(`/images/${id}`, validatedParams);
|
|
166
|
+
|
|
167
|
+
// Validate response with Zod
|
|
168
|
+
return validate(updateImageResponseSchema, response, { context: "Update image response" });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Deletes an Image.
|
|
173
|
+
*
|
|
174
|
+
* Only available for `snapshot` and `backup` image types.
|
|
175
|
+
*
|
|
176
|
+
* @param id - ID of the Image
|
|
177
|
+
* @returns Promise resolving to the delete action
|
|
178
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-delete-an-image
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
183
|
+
*
|
|
184
|
+
* // Delete an image
|
|
185
|
+
* const result = await client.images.delete(12345);
|
|
186
|
+
* console.log(`Delete action ID: ${result.action.id}`);
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
async delete(id: number): Promise<DeleteImageResponse> {
|
|
190
|
+
const response = await this.client.delete<unknown>(`/images/${id}`);
|
|
191
|
+
|
|
192
|
+
// Validate response with Zod
|
|
193
|
+
return validate(deleteImageResponseSchema, response, { context: "Delete image response" });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for Hetzner Cloud Images API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-list-images
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { paginationMetaSchema } from "@/apis/common/schemas";
|
|
8
|
+
import { actionSchema } from "@/apis/actions/schemas";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Image status schema
|
|
12
|
+
*/
|
|
13
|
+
export const imageStatusSchema = z.enum(["available", "creating", "unavailable"]);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Image type schema
|
|
17
|
+
*/
|
|
18
|
+
export const imageTypeSchema = z.enum(["system", "app", "snapshot", "backup"]);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Image created from schema
|
|
22
|
+
*/
|
|
23
|
+
export const imageCreatedFromSchema = z.object({
|
|
24
|
+
id: z.number(),
|
|
25
|
+
name: z.string(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Image protection schema
|
|
30
|
+
*/
|
|
31
|
+
export const imageProtectionSchema = z.object({
|
|
32
|
+
delete: z.boolean(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Image deprecation schema
|
|
37
|
+
*/
|
|
38
|
+
export const imageDeprecationSchema = z.object({
|
|
39
|
+
announced: z.string(),
|
|
40
|
+
unavailable_after: z.string(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Image schema
|
|
45
|
+
*/
|
|
46
|
+
export const imageSchema = z
|
|
47
|
+
.object({
|
|
48
|
+
id: z.number(),
|
|
49
|
+
type: imageTypeSchema,
|
|
50
|
+
status: imageStatusSchema,
|
|
51
|
+
name: z.string(),
|
|
52
|
+
description: z.string(),
|
|
53
|
+
image_size: z.number().nullable(),
|
|
54
|
+
disk_size: z.number(),
|
|
55
|
+
created: z.string(),
|
|
56
|
+
created_from: imageCreatedFromSchema.nullable(),
|
|
57
|
+
bound_to: z.number().nullable(),
|
|
58
|
+
os_flavor: z.string(),
|
|
59
|
+
os_version: z.string().nullable(),
|
|
60
|
+
rapid_deploy: z.boolean(),
|
|
61
|
+
protection: imageProtectionSchema,
|
|
62
|
+
deprecation: imageDeprecationSchema.nullable().optional(),
|
|
63
|
+
labels: z.record(z.string(), z.string()),
|
|
64
|
+
deleted: z.string().nullable(),
|
|
65
|
+
})
|
|
66
|
+
.passthrough();
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* List Images response schema
|
|
70
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-list-images
|
|
71
|
+
*/
|
|
72
|
+
export const listImagesResponseSchema = z.object({
|
|
73
|
+
images: z.array(imageSchema),
|
|
74
|
+
meta: z
|
|
75
|
+
.object({
|
|
76
|
+
pagination: paginationMetaSchema,
|
|
77
|
+
})
|
|
78
|
+
.optional(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Update Image request schema
|
|
83
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-update-an-image
|
|
84
|
+
*/
|
|
85
|
+
export const updateImageRequestSchema = z.object({
|
|
86
|
+
description: z.string().optional(),
|
|
87
|
+
type: z.enum(["snapshot"]).optional(),
|
|
88
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get Image response schema
|
|
93
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-get-an-image
|
|
94
|
+
*/
|
|
95
|
+
export const getImageResponseSchema = z.object({
|
|
96
|
+
image: imageSchema,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Update Image response schema
|
|
101
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-update-an-image
|
|
102
|
+
*/
|
|
103
|
+
export const updateImageResponseSchema = z.object({
|
|
104
|
+
image: imageSchema,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Delete Image response schema
|
|
109
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-delete-an-image
|
|
110
|
+
*/
|
|
111
|
+
export const deleteImageResponseSchema = z.object({
|
|
112
|
+
action: actionSchema,
|
|
113
|
+
});
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Hetzner Cloud Images API
|
|
3
|
+
* Types are inferred from Zod schemas
|
|
4
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-list-images
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// biome-ignore assist/source/organizeImports: we need to import the schemas first
|
|
8
|
+
import {
|
|
9
|
+
imageStatusSchema,
|
|
10
|
+
imageTypeSchema,
|
|
11
|
+
listImagesResponseSchema,
|
|
12
|
+
updateImageRequestSchema,
|
|
13
|
+
getImageResponseSchema,
|
|
14
|
+
updateImageResponseSchema,
|
|
15
|
+
deleteImageResponseSchema,
|
|
16
|
+
} from "@/apis/images/schemas";
|
|
17
|
+
import { imageSchema } from "@/apis/images/schemas";
|
|
18
|
+
import type { z } from "zod";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Image status values
|
|
22
|
+
*/
|
|
23
|
+
export type ImageStatus = z.infer<typeof imageStatusSchema>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Image type values
|
|
27
|
+
*/
|
|
28
|
+
export type ImageType = z.infer<typeof imageTypeSchema>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Hetzner Cloud Image
|
|
32
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-list-images
|
|
33
|
+
*/
|
|
34
|
+
export type Image = z.infer<typeof imageSchema>;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Pagination metadata
|
|
38
|
+
* @see https://docs.hetzner.cloud/reference/cloud#pagination
|
|
39
|
+
* Re-exported from servers module for consistency
|
|
40
|
+
*/
|
|
41
|
+
export type { PaginationMeta } from "@/apis/servers/types";
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* List Images query parameters
|
|
45
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-list-images
|
|
46
|
+
*/
|
|
47
|
+
export interface ListImagesParams {
|
|
48
|
+
/**
|
|
49
|
+
* Can be used multiple times. The response will only contain Images matching the type.
|
|
50
|
+
* Choices: system, app, snapshot, backup
|
|
51
|
+
*/
|
|
52
|
+
type?: ImageType | ImageType[];
|
|
53
|
+
/**
|
|
54
|
+
* Can be used multiple times. The response will only contain Images matching the status.
|
|
55
|
+
* Choices: available, creating, unavailable
|
|
56
|
+
*/
|
|
57
|
+
status?: ImageStatus | ImageStatus[];
|
|
58
|
+
/**
|
|
59
|
+
* Can be used to filter Images by their name. The response will only contain the Image matching the specified name.
|
|
60
|
+
*/
|
|
61
|
+
name?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Can be used to filter Images by labels. The response will only contain Images matching the label selector.
|
|
64
|
+
* @see https://docs.hetzner.cloud/reference/cloud#label-selector
|
|
65
|
+
*/
|
|
66
|
+
label_selector?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Can be used multiple times. Choices: id, id:asc, id:desc, name, name:asc, name:desc, created, created:asc, created:desc, type, type:asc, type:desc
|
|
69
|
+
* @see https://docs.hetzner.cloud/reference/cloud#sorting
|
|
70
|
+
*/
|
|
71
|
+
sort?: string | string[];
|
|
72
|
+
/**
|
|
73
|
+
* Can be used multiple times, the response will only contain Images matching the specified architecture.
|
|
74
|
+
* Choices: x86, arm
|
|
75
|
+
*/
|
|
76
|
+
architecture?: "x86" | "arm" | ("x86" | "arm")[];
|
|
77
|
+
/**
|
|
78
|
+
* Can be used to filter Images by their bound server. The response will only contain the Image matching the specified server ID.
|
|
79
|
+
*/
|
|
80
|
+
bound_to?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Can be used to filter Images by their include_deprecated status.
|
|
83
|
+
* If set to true, deprecated Images are included in the response. If set to false, deprecated Images are excluded from the response.
|
|
84
|
+
*/
|
|
85
|
+
include_deprecated?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
88
|
+
*/
|
|
89
|
+
page?: number;
|
|
90
|
+
/**
|
|
91
|
+
* Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
92
|
+
*/
|
|
93
|
+
per_page?: number;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* List Images response
|
|
98
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-list-images
|
|
99
|
+
*/
|
|
100
|
+
export type ListImagesResponse = z.infer<typeof listImagesResponseSchema>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Update Image request parameters
|
|
104
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-update-an-image
|
|
105
|
+
*/
|
|
106
|
+
export type UpdateImageParams = z.infer<typeof updateImageRequestSchema>;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get Image response
|
|
110
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-get-an-image
|
|
111
|
+
*/
|
|
112
|
+
export type GetImageResponse = z.infer<typeof getImageResponseSchema>;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Update Image response
|
|
116
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-update-an-image
|
|
117
|
+
*/
|
|
118
|
+
export type UpdateImageResponse = z.infer<typeof updateImageResponseSchema>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Delete Image response
|
|
122
|
+
* @see https://docs.hetzner.cloud/reference/cloud#images-delete-an-image
|
|
123
|
+
*/
|
|
124
|
+
export type DeleteImageResponse = z.infer<typeof deleteImageResponseSchema>;
|