@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,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for Hetzner Cloud Locations API
|
|
3
|
+
* Types are inferred from Zod schemas
|
|
4
|
+
* @see https://docs.hetzner.cloud/reference/cloud#locations
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// biome-ignore assist/source/organizeImports: we need to import the schemas first
|
|
8
|
+
import {
|
|
9
|
+
listLocationsResponseSchema,
|
|
10
|
+
getLocationResponseSchema,
|
|
11
|
+
listDataCentersResponseSchema,
|
|
12
|
+
getDataCenterResponseSchema,
|
|
13
|
+
locationSchema,
|
|
14
|
+
datacenterSchema,
|
|
15
|
+
datacenterServerTypesSchema,
|
|
16
|
+
} from "@/apis/locations/schemas";
|
|
17
|
+
import type { z } from "zod";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Hetzner Cloud Location
|
|
21
|
+
* @see https://docs.hetzner.cloud/reference/cloud#locations-list-locations
|
|
22
|
+
*/
|
|
23
|
+
export type Location = z.infer<typeof locationSchema>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Datacenter server types information
|
|
27
|
+
*/
|
|
28
|
+
export type DatacenterServerTypes = z.infer<typeof datacenterServerTypesSchema>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Hetzner Cloud Datacenter
|
|
32
|
+
* @see https://docs.hetzner.cloud/reference/cloud#data-centers-list-data-centers
|
|
33
|
+
*/
|
|
34
|
+
export type Datacenter = z.infer<typeof datacenterSchema>;
|
|
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 Locations query parameters
|
|
45
|
+
* @see https://docs.hetzner.cloud/reference/cloud#locations-list-locations
|
|
46
|
+
*/
|
|
47
|
+
export interface ListLocationsParams {
|
|
48
|
+
/**
|
|
49
|
+
* Can be used to filter Locations by their name. The response will only contain the Location matching the specified name.
|
|
50
|
+
*/
|
|
51
|
+
name?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Can be used multiple times. Choices: id, id:asc, id:desc, name, name:asc, name:desc
|
|
54
|
+
* @see https://docs.hetzner.cloud/reference/cloud#sorting
|
|
55
|
+
*/
|
|
56
|
+
sort?: string | string[];
|
|
57
|
+
/**
|
|
58
|
+
* Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
59
|
+
*/
|
|
60
|
+
page?: number;
|
|
61
|
+
/**
|
|
62
|
+
* Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
63
|
+
*/
|
|
64
|
+
per_page?: number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* List Locations response
|
|
69
|
+
* @see https://docs.hetzner.cloud/reference/cloud#locations-list-locations
|
|
70
|
+
*/
|
|
71
|
+
export type ListLocationsResponse = z.infer<typeof listLocationsResponseSchema>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get Location response
|
|
75
|
+
* @see https://docs.hetzner.cloud/reference/cloud#locations-get-a-location
|
|
76
|
+
*/
|
|
77
|
+
export type GetLocationResponse = z.infer<typeof getLocationResponseSchema>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* List Data Centers query parameters
|
|
81
|
+
* @see https://docs.hetzner.cloud/reference/cloud#data-centers-list-data-centers
|
|
82
|
+
*/
|
|
83
|
+
export interface ListDataCentersParams {
|
|
84
|
+
/**
|
|
85
|
+
* Can be used to filter Data Centers by their name. The response will only contain the Data Center matching the specified name.
|
|
86
|
+
*/
|
|
87
|
+
name?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Can be used multiple times. Choices: id, id:asc, id:desc, name, name:asc, name:desc
|
|
90
|
+
* @see https://docs.hetzner.cloud/reference/cloud#sorting
|
|
91
|
+
*/
|
|
92
|
+
sort?: string | string[];
|
|
93
|
+
/**
|
|
94
|
+
* Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
95
|
+
*/
|
|
96
|
+
page?: number;
|
|
97
|
+
/**
|
|
98
|
+
* Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
|
|
99
|
+
*/
|
|
100
|
+
per_page?: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* List Data Centers response
|
|
105
|
+
* @see https://docs.hetzner.cloud/reference/cloud#data-centers-list-data-centers
|
|
106
|
+
*/
|
|
107
|
+
export type ListDataCentersResponse = z.infer<typeof listDataCentersResponseSchema>;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get Data Center response
|
|
111
|
+
* @see https://docs.hetzner.cloud/reference/cloud#data-centers-get-a-data-center
|
|
112
|
+
*/
|
|
113
|
+
export type GetDataCenterResponse = z.infer<typeof getDataCenterResponseSchema>;
|
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hetzner Cloud Networks API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { HCloudClient } from "@/client/index";
|
|
7
|
+
import type {
|
|
8
|
+
ListNetworksParams,
|
|
9
|
+
ListNetworksResponse,
|
|
10
|
+
CreateNetworkParams,
|
|
11
|
+
CreateNetworkResponse,
|
|
12
|
+
GetNetworkResponse,
|
|
13
|
+
UpdateNetworkParams,
|
|
14
|
+
UpdateNetworkResponse,
|
|
15
|
+
DeleteNetworkResponse,
|
|
16
|
+
ListNetworkActionsParams,
|
|
17
|
+
ListNetworkActionsResponse,
|
|
18
|
+
GetNetworkActionResponse,
|
|
19
|
+
AddNetworkRouteParams,
|
|
20
|
+
AddNetworkRouteResponse,
|
|
21
|
+
DeleteNetworkRouteParams,
|
|
22
|
+
DeleteNetworkRouteResponse,
|
|
23
|
+
AddNetworkSubnetParams,
|
|
24
|
+
AddNetworkSubnetResponse,
|
|
25
|
+
DeleteNetworkSubnetParams,
|
|
26
|
+
DeleteNetworkSubnetResponse,
|
|
27
|
+
ChangeNetworkIpRangeParams,
|
|
28
|
+
ChangeNetworkIpRangeResponse,
|
|
29
|
+
ChangeNetworkProtectionParams,
|
|
30
|
+
ChangeNetworkProtectionResponse,
|
|
31
|
+
} from "@/apis/networks/types";
|
|
32
|
+
import { validate } from "@/validation/index";
|
|
33
|
+
import {
|
|
34
|
+
listNetworksResponseSchema,
|
|
35
|
+
createNetworkRequestSchema,
|
|
36
|
+
createNetworkResponseSchema,
|
|
37
|
+
getNetworkResponseSchema,
|
|
38
|
+
updateNetworkRequestSchema,
|
|
39
|
+
updateNetworkResponseSchema,
|
|
40
|
+
deleteNetworkResponseSchema,
|
|
41
|
+
listNetworkActionsResponseSchema,
|
|
42
|
+
getNetworkActionResponseSchema,
|
|
43
|
+
addNetworkRouteRequestSchema,
|
|
44
|
+
addNetworkRouteResponseSchema,
|
|
45
|
+
deleteNetworkRouteRequestSchema,
|
|
46
|
+
deleteNetworkRouteResponseSchema,
|
|
47
|
+
addNetworkSubnetRequestSchema,
|
|
48
|
+
addNetworkSubnetResponseSchema,
|
|
49
|
+
deleteNetworkSubnetRequestSchema,
|
|
50
|
+
deleteNetworkSubnetResponseSchema,
|
|
51
|
+
changeNetworkIpRangeRequestSchema,
|
|
52
|
+
changeNetworkIpRangeResponseSchema,
|
|
53
|
+
changeNetworkProtectionRequestSchema,
|
|
54
|
+
changeNetworkProtectionResponseSchema,
|
|
55
|
+
} from "@/apis/networks/schemas";
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Networks API client
|
|
59
|
+
*/
|
|
60
|
+
export class NetworksClient {
|
|
61
|
+
constructor(private readonly client: HCloudClient) {}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns all Network objects.
|
|
65
|
+
*
|
|
66
|
+
* @param params - Query parameters for filtering and pagination
|
|
67
|
+
* @returns Promise resolving to list of networks with pagination metadata
|
|
68
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-list-networks
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
73
|
+
*
|
|
74
|
+
* // List all networks
|
|
75
|
+
* const result = await client.networks.list();
|
|
76
|
+
*
|
|
77
|
+
* // List networks with filters
|
|
78
|
+
* const networks = await client.networks.list({
|
|
79
|
+
* name: 'my-network',
|
|
80
|
+
* label_selector: 'environment=production',
|
|
81
|
+
* sort: ['name:asc'],
|
|
82
|
+
* page: 1,
|
|
83
|
+
* per_page: 50
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
async list(params?: ListNetworksParams): Promise<ListNetworksResponse> {
|
|
88
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
89
|
+
|
|
90
|
+
if (params?.name) {
|
|
91
|
+
queryParams.name = params.name;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (params?.label_selector) {
|
|
95
|
+
queryParams.label_selector = params.label_selector;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (params?.sort) {
|
|
99
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (params?.page !== undefined) {
|
|
103
|
+
queryParams.page = params.page;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (params?.per_page !== undefined) {
|
|
107
|
+
queryParams.per_page = params.per_page;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const response = await this.client.get<unknown>("/networks", queryParams);
|
|
111
|
+
|
|
112
|
+
return validate(listNetworksResponseSchema, response, {
|
|
113
|
+
context: "List networks response",
|
|
114
|
+
detailed: true,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates a new Network.
|
|
120
|
+
*
|
|
121
|
+
* @param params - Parameters for creating the network
|
|
122
|
+
* @returns Promise resolving to the created network and action
|
|
123
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-create-a-network
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
128
|
+
*
|
|
129
|
+
* // Create a network
|
|
130
|
+
* const network = await client.networks.create({
|
|
131
|
+
* name: 'my-network',
|
|
132
|
+
* ip_range: '10.0.0.0/16',
|
|
133
|
+
* subnets: [{
|
|
134
|
+
* type: 'cloud',
|
|
135
|
+
* network_zone: 'eu-central'
|
|
136
|
+
* }],
|
|
137
|
+
* labels: { environment: 'production' }
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
async create(params: CreateNetworkParams): Promise<CreateNetworkResponse> {
|
|
142
|
+
const validatedParams = validate(createNetworkRequestSchema, params, {
|
|
143
|
+
context: "Create network request",
|
|
144
|
+
detailed: true,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const response = await this.client.post<unknown>("/networks", validatedParams);
|
|
148
|
+
|
|
149
|
+
return validate(createNetworkResponseSchema, response, {
|
|
150
|
+
context: "Create network response",
|
|
151
|
+
detailed: true,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Returns a specific Network object.
|
|
157
|
+
*
|
|
158
|
+
* @param id - ID of the Network
|
|
159
|
+
* @returns Promise resolving to the network
|
|
160
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-get-a-network
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
165
|
+
*
|
|
166
|
+
* // Get a network by ID
|
|
167
|
+
* const network = await client.networks.get(12345);
|
|
168
|
+
* console.log(network.network.name);
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
async get(id: number): Promise<GetNetworkResponse> {
|
|
172
|
+
const response = await this.client.get<unknown>(`/networks/${id}`);
|
|
173
|
+
|
|
174
|
+
return validate(getNetworkResponseSchema, response, {
|
|
175
|
+
context: "Get network response",
|
|
176
|
+
detailed: true,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Updates the Network.
|
|
182
|
+
*
|
|
183
|
+
* You can update a Network's name, labels, and expose_routes_to_vswitch.
|
|
184
|
+
*
|
|
185
|
+
* @param id - ID of the Network
|
|
186
|
+
* @param params - Parameters to update (name, labels, and/or expose_routes_to_vswitch)
|
|
187
|
+
* @returns Promise resolving to the updated network
|
|
188
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-update-a-network
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
193
|
+
*
|
|
194
|
+
* // Update network name
|
|
195
|
+
* const updated = await client.networks.update(12345, {
|
|
196
|
+
* name: 'new-network-name'
|
|
197
|
+
* });
|
|
198
|
+
*
|
|
199
|
+
* // Update labels
|
|
200
|
+
* const updated = await client.networks.update(12345, {
|
|
201
|
+
* labels: { environment: 'production', team: 'backend' }
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
async update(id: number, params: UpdateNetworkParams): Promise<UpdateNetworkResponse> {
|
|
206
|
+
const validatedParams = validate(updateNetworkRequestSchema, params, {
|
|
207
|
+
context: "Update network request",
|
|
208
|
+
detailed: true,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const response = await this.client.put<unknown>(`/networks/${id}`, validatedParams);
|
|
212
|
+
|
|
213
|
+
return validate(updateNetworkResponseSchema, response, {
|
|
214
|
+
context: "Update network response",
|
|
215
|
+
detailed: true,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Deletes a Network.
|
|
221
|
+
*
|
|
222
|
+
* @param id - ID of the Network
|
|
223
|
+
* @returns Promise resolving to empty object
|
|
224
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-delete-a-network
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
229
|
+
*
|
|
230
|
+
* // Delete a network
|
|
231
|
+
* await client.networks.delete(12345);
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
async delete(id: number): Promise<DeleteNetworkResponse> {
|
|
235
|
+
const response = await this.client.delete<unknown>(`/networks/${id}`);
|
|
236
|
+
|
|
237
|
+
return validate(deleteNetworkResponseSchema, response, {
|
|
238
|
+
context: "Delete network response",
|
|
239
|
+
detailed: true,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Returns all Action objects for a Network.
|
|
245
|
+
*
|
|
246
|
+
* @param id - ID of the Network
|
|
247
|
+
* @param params - Query parameters for filtering and pagination
|
|
248
|
+
* @returns Promise resolving to list of actions with pagination metadata
|
|
249
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-list-actions-for-a-network
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
254
|
+
*
|
|
255
|
+
* // List all actions for a network
|
|
256
|
+
* const actions = await client.networks.listActions(12345);
|
|
257
|
+
*
|
|
258
|
+
* // List actions with filters
|
|
259
|
+
* const runningActions = await client.networks.listActions(12345, {
|
|
260
|
+
* status: ['running'],
|
|
261
|
+
* sort: ['started:desc']
|
|
262
|
+
* });
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
async listActions(
|
|
266
|
+
id: number,
|
|
267
|
+
params?: ListNetworkActionsParams,
|
|
268
|
+
): Promise<ListNetworkActionsResponse> {
|
|
269
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
270
|
+
|
|
271
|
+
if (params?.sort) {
|
|
272
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (params?.status) {
|
|
276
|
+
queryParams.status = Array.isArray(params.status) ? params.status : [params.status];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (params?.page !== undefined) {
|
|
280
|
+
queryParams.page = params.page;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (params?.per_page !== undefined) {
|
|
284
|
+
queryParams.per_page = params.per_page;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const response = await this.client.get<unknown>(`/networks/${id}/actions`, queryParams);
|
|
288
|
+
|
|
289
|
+
return validate(listNetworkActionsResponseSchema, response, {
|
|
290
|
+
context: "List network actions response",
|
|
291
|
+
detailed: true,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Returns a specific Action object for a Network.
|
|
297
|
+
*
|
|
298
|
+
* @param id - ID of the Network
|
|
299
|
+
* @param actionId - ID of the Action
|
|
300
|
+
* @returns Promise resolving to the action
|
|
301
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-get-an-action-for-a-network
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
306
|
+
*
|
|
307
|
+
* // Get an action by ID
|
|
308
|
+
* const action = await client.networks.getAction(12345, 67890);
|
|
309
|
+
* console.log(action.action.command);
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
async getAction(id: number, actionId: number): Promise<GetNetworkActionResponse> {
|
|
313
|
+
const response = await this.client.get<unknown>(`/networks/${id}/actions/${actionId}`);
|
|
314
|
+
|
|
315
|
+
return validate(getNetworkActionResponseSchema, response, {
|
|
316
|
+
context: "Get network action response",
|
|
317
|
+
detailed: true,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Adds a route to a Network.
|
|
323
|
+
*
|
|
324
|
+
* @param id - ID of the Network
|
|
325
|
+
* @param params - Route configuration
|
|
326
|
+
* @returns Promise resolving to the action
|
|
327
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-add-a-route-to-a-network
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
332
|
+
*
|
|
333
|
+
* const result = await client.networks.addRoute(12345, {
|
|
334
|
+
* destination: '10.0.1.0/24',
|
|
335
|
+
* gateway: '10.0.0.1'
|
|
336
|
+
* });
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
async addRoute(id: number, params: AddNetworkRouteParams): Promise<AddNetworkRouteResponse> {
|
|
340
|
+
const validatedParams = validate(addNetworkRouteRequestSchema, params, {
|
|
341
|
+
context: "Add network route request",
|
|
342
|
+
detailed: true,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const response = await this.client.post<unknown>(
|
|
346
|
+
`/networks/${id}/actions/add_route`,
|
|
347
|
+
validatedParams,
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
return validate(addNetworkRouteResponseSchema, response, {
|
|
351
|
+
context: "Add network route response",
|
|
352
|
+
detailed: true,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Deletes a route from a Network.
|
|
358
|
+
*
|
|
359
|
+
* @param id - ID of the Network
|
|
360
|
+
* @param params - Route to delete
|
|
361
|
+
* @returns Promise resolving to the action
|
|
362
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-delete-a-route-from-a-network
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
367
|
+
*
|
|
368
|
+
* const result = await client.networks.deleteRoute(12345, {
|
|
369
|
+
* destination: '10.0.1.0/24',
|
|
370
|
+
* gateway: '10.0.0.1'
|
|
371
|
+
* });
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
async deleteRoute(
|
|
375
|
+
id: number,
|
|
376
|
+
params: DeleteNetworkRouteParams,
|
|
377
|
+
): Promise<DeleteNetworkRouteResponse> {
|
|
378
|
+
const validatedParams = validate(deleteNetworkRouteRequestSchema, params, {
|
|
379
|
+
context: "Delete network route request",
|
|
380
|
+
detailed: true,
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
const response = await this.client.post<unknown>(
|
|
384
|
+
`/networks/${id}/actions/delete_route`,
|
|
385
|
+
validatedParams,
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
return validate(deleteNetworkRouteResponseSchema, response, {
|
|
389
|
+
context: "Delete network route response",
|
|
390
|
+
detailed: true,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Adds a subnet to a Network.
|
|
396
|
+
*
|
|
397
|
+
* @param id - ID of the Network
|
|
398
|
+
* @param params - Subnet configuration
|
|
399
|
+
* @returns Promise resolving to the action
|
|
400
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-add-a-subnet-to-a-network
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
405
|
+
*
|
|
406
|
+
* const result = await client.networks.addSubnet(12345, {
|
|
407
|
+
* type: 'cloud',
|
|
408
|
+
* network_zone: 'eu-central',
|
|
409
|
+
* ip_range: '10.0.1.0/24'
|
|
410
|
+
* });
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
async addSubnet(
|
|
414
|
+
id: number,
|
|
415
|
+
params: AddNetworkSubnetParams,
|
|
416
|
+
): Promise<AddNetworkSubnetResponse> {
|
|
417
|
+
const validatedParams = validate(addNetworkSubnetRequestSchema, params, {
|
|
418
|
+
context: "Add network subnet request",
|
|
419
|
+
detailed: true,
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
const response = await this.client.post<unknown>(
|
|
423
|
+
`/networks/${id}/actions/add_subnet`,
|
|
424
|
+
validatedParams,
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
return validate(addNetworkSubnetResponseSchema, response, {
|
|
428
|
+
context: "Add network subnet response",
|
|
429
|
+
detailed: true,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Deletes a subnet from a Network.
|
|
435
|
+
*
|
|
436
|
+
* @param id - ID of the Network
|
|
437
|
+
* @param params - Subnet to delete
|
|
438
|
+
* @returns Promise resolving to the action
|
|
439
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-delete-a-subnet-from-a-network
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```typescript
|
|
443
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
444
|
+
*
|
|
445
|
+
* const result = await client.networks.deleteSubnet(12345, {
|
|
446
|
+
* ip_range: '10.0.1.0/24'
|
|
447
|
+
* });
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
450
|
+
async deleteSubnet(
|
|
451
|
+
id: number,
|
|
452
|
+
params: DeleteNetworkSubnetParams,
|
|
453
|
+
): Promise<DeleteNetworkSubnetResponse> {
|
|
454
|
+
const validatedParams = validate(deleteNetworkSubnetRequestSchema, params, {
|
|
455
|
+
context: "Delete network subnet request",
|
|
456
|
+
detailed: true,
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
const response = await this.client.post<unknown>(
|
|
460
|
+
`/networks/${id}/actions/delete_subnet`,
|
|
461
|
+
validatedParams,
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
return validate(deleteNetworkSubnetResponseSchema, response, {
|
|
465
|
+
context: "Delete network subnet response",
|
|
466
|
+
detailed: true,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Changes the IP range of a Network.
|
|
472
|
+
*
|
|
473
|
+
* @param id - ID of the Network
|
|
474
|
+
* @param params - New IP range
|
|
475
|
+
* @returns Promise resolving to the action
|
|
476
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-change-ip-range-of-a-network
|
|
477
|
+
*
|
|
478
|
+
* @example
|
|
479
|
+
* ```typescript
|
|
480
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
481
|
+
*
|
|
482
|
+
* const result = await client.networks.changeIpRange(12345, {
|
|
483
|
+
* ip_range: '10.0.0.0/16'
|
|
484
|
+
* });
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
async changeIpRange(
|
|
488
|
+
id: number,
|
|
489
|
+
params: ChangeNetworkIpRangeParams,
|
|
490
|
+
): Promise<ChangeNetworkIpRangeResponse> {
|
|
491
|
+
const validatedParams = validate(changeNetworkIpRangeRequestSchema, params, {
|
|
492
|
+
context: "Change network IP range request",
|
|
493
|
+
detailed: true,
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
const response = await this.client.post<unknown>(
|
|
497
|
+
`/networks/${id}/actions/change_ip_range`,
|
|
498
|
+
validatedParams,
|
|
499
|
+
);
|
|
500
|
+
|
|
501
|
+
return validate(changeNetworkIpRangeResponseSchema, response, {
|
|
502
|
+
context: "Change network IP range response",
|
|
503
|
+
detailed: true,
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Changes the Protection configuration of a Network.
|
|
509
|
+
*
|
|
510
|
+
* @param id - ID of the Network
|
|
511
|
+
* @param params - Protection configuration
|
|
512
|
+
* @returns Promise resolving to the action
|
|
513
|
+
* @see https://docs.hetzner.cloud/reference/cloud#networks-change-network-protection
|
|
514
|
+
*
|
|
515
|
+
* @example
|
|
516
|
+
* ```typescript
|
|
517
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
518
|
+
*
|
|
519
|
+
* // Enable delete protection
|
|
520
|
+
* const result = await client.networks.changeProtection(12345, {
|
|
521
|
+
* delete: true
|
|
522
|
+
* });
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
async changeProtection(
|
|
526
|
+
id: number,
|
|
527
|
+
params: ChangeNetworkProtectionParams,
|
|
528
|
+
): Promise<ChangeNetworkProtectionResponse> {
|
|
529
|
+
const validatedParams = validate(changeNetworkProtectionRequestSchema, params, {
|
|
530
|
+
context: "Change network protection request",
|
|
531
|
+
detailed: true,
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
const response = await this.client.post<unknown>(
|
|
535
|
+
`/networks/${id}/actions/change_protection`,
|
|
536
|
+
validatedParams,
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
return validate(changeNetworkProtectionResponseSchema, response, {
|
|
540
|
+
context: "Change network protection response",
|
|
541
|
+
detailed: true,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}
|