@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,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hetzner Cloud Primary IPs API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { HCloudClient } from "@/client/index";
|
|
7
|
+
import type {
|
|
8
|
+
ListPrimaryIPsParams,
|
|
9
|
+
ListPrimaryIPsResponse,
|
|
10
|
+
CreatePrimaryIPParams,
|
|
11
|
+
CreatePrimaryIPResponse,
|
|
12
|
+
GetPrimaryIPResponse,
|
|
13
|
+
UpdatePrimaryIPParams,
|
|
14
|
+
UpdatePrimaryIPResponse,
|
|
15
|
+
DeletePrimaryIPResponse,
|
|
16
|
+
ListPrimaryIPActionsParams,
|
|
17
|
+
ListPrimaryIPActionsResponse,
|
|
18
|
+
GetPrimaryIPActionResponse,
|
|
19
|
+
AssignPrimaryIPToResourceParams,
|
|
20
|
+
AssignPrimaryIPToResourceResponse,
|
|
21
|
+
ChangePrimaryIPReverseDNSParams,
|
|
22
|
+
ChangePrimaryIPReverseDNSResponse,
|
|
23
|
+
ChangePrimaryIPProtectionParams,
|
|
24
|
+
ChangePrimaryIPProtectionResponse,
|
|
25
|
+
UnassignPrimaryIPResponse,
|
|
26
|
+
} from "@/apis/primary-ips/types";
|
|
27
|
+
import { validate } from "@/validation/index";
|
|
28
|
+
import {
|
|
29
|
+
listPrimaryIPsResponseSchema,
|
|
30
|
+
createPrimaryIPRequestSchema,
|
|
31
|
+
createPrimaryIPResponseSchema,
|
|
32
|
+
getPrimaryIPResponseSchema,
|
|
33
|
+
updatePrimaryIPRequestSchema,
|
|
34
|
+
updatePrimaryIPResponseSchema,
|
|
35
|
+
deletePrimaryIPResponseSchema,
|
|
36
|
+
listPrimaryIPActionsResponseSchema,
|
|
37
|
+
getPrimaryIPActionResponseSchema,
|
|
38
|
+
assignPrimaryIPToResourceRequestSchema,
|
|
39
|
+
assignPrimaryIPToResourceResponseSchema,
|
|
40
|
+
changePrimaryIPReverseDNSRequestSchema,
|
|
41
|
+
changePrimaryIPReverseDNSResponseSchema,
|
|
42
|
+
changePrimaryIPProtectionRequestSchema,
|
|
43
|
+
changePrimaryIPProtectionResponseSchema,
|
|
44
|
+
unassignPrimaryIPRequestSchema,
|
|
45
|
+
unassignPrimaryIPResponseSchema,
|
|
46
|
+
} from "@/apis/primary-ips/schemas";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Primary IPs API client
|
|
50
|
+
*/
|
|
51
|
+
export class PrimaryIPsClient {
|
|
52
|
+
constructor(private readonly client: HCloudClient) {}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Returns all Primary IP objects.
|
|
56
|
+
*
|
|
57
|
+
* @param params - Query parameters for filtering and pagination
|
|
58
|
+
* @returns Promise resolving to list of primary IPs with pagination metadata
|
|
59
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-list-primary-ips
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
64
|
+
*
|
|
65
|
+
* // List all primary IPs
|
|
66
|
+
* const result = await client.primaryIPs.list();
|
|
67
|
+
*
|
|
68
|
+
* // List primary IPs with filters
|
|
69
|
+
* const primaryIPs = await client.primaryIPs.list({
|
|
70
|
+
* name: 'my-primary-ip',
|
|
71
|
+
* label_selector: 'environment=production',
|
|
72
|
+
* ip: '1.2.3.4',
|
|
73
|
+
* sort: ['name:asc'],
|
|
74
|
+
* page: 1,
|
|
75
|
+
* per_page: 50
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
async list(params?: ListPrimaryIPsParams): Promise<ListPrimaryIPsResponse> {
|
|
80
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
81
|
+
|
|
82
|
+
if (params?.name) {
|
|
83
|
+
queryParams.name = params.name;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (params?.label_selector) {
|
|
87
|
+
queryParams.label_selector = params.label_selector;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (params?.ip) {
|
|
91
|
+
queryParams.ip = params.ip;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (params?.sort) {
|
|
95
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (params?.page !== undefined) {
|
|
99
|
+
queryParams.page = params.page;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (params?.per_page !== undefined) {
|
|
103
|
+
queryParams.per_page = params.per_page;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const response = await this.client.get<unknown>("/primary_ips", queryParams);
|
|
107
|
+
|
|
108
|
+
return validate(listPrimaryIPsResponseSchema, response, {
|
|
109
|
+
context: "List primary IPs response",
|
|
110
|
+
detailed: true,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new Primary IP.
|
|
116
|
+
*
|
|
117
|
+
* @param params - Parameters for creating the primary IP
|
|
118
|
+
* @returns Promise resolving to the created primary IP and action
|
|
119
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-create-a-primary-ip
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
124
|
+
*
|
|
125
|
+
* // Create an IPv4 primary IP
|
|
126
|
+
* const primaryIP = await client.primaryIPs.create({
|
|
127
|
+
* name: 'my-primary-ip',
|
|
128
|
+
* type: 'ipv4',
|
|
129
|
+
* datacenter: 'nbg1-dc3',
|
|
130
|
+
* assignee_type: 'server',
|
|
131
|
+
* auto_delete: true,
|
|
132
|
+
* labels: { environment: 'production' }
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
async create(params: CreatePrimaryIPParams): Promise<CreatePrimaryIPResponse> {
|
|
137
|
+
const validatedParams = validate(createPrimaryIPRequestSchema, params, {
|
|
138
|
+
context: "Create primary IP request",
|
|
139
|
+
detailed: true,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const response = await this.client.post<unknown>("/primary_ips", validatedParams);
|
|
143
|
+
|
|
144
|
+
return validate(createPrimaryIPResponseSchema, response, {
|
|
145
|
+
context: "Create primary IP response",
|
|
146
|
+
detailed: true,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Returns a specific Primary IP object.
|
|
152
|
+
*
|
|
153
|
+
* @param id - ID of the Primary IP
|
|
154
|
+
* @returns Promise resolving to the primary IP
|
|
155
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-get-a-primary-ip
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
160
|
+
*
|
|
161
|
+
* // Get a primary IP by ID
|
|
162
|
+
* const primaryIP = await client.primaryIPs.get(12345);
|
|
163
|
+
* console.log(primaryIP.primary_ip.ip);
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
async get(id: number): Promise<GetPrimaryIPResponse> {
|
|
167
|
+
const response = await this.client.get<unknown>(`/primary_ips/${id}`);
|
|
168
|
+
|
|
169
|
+
return validate(getPrimaryIPResponseSchema, response, {
|
|
170
|
+
context: "Get primary IP response",
|
|
171
|
+
detailed: true,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Updates the Primary IP.
|
|
177
|
+
*
|
|
178
|
+
* You can update a Primary IP's name, auto_delete and labels.
|
|
179
|
+
*
|
|
180
|
+
* @param id - ID of the Primary IP
|
|
181
|
+
* @param params - Parameters to update (name, auto_delete, and/or labels)
|
|
182
|
+
* @returns Promise resolving to the updated primary IP
|
|
183
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-update-a-primary-ip
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```typescript
|
|
187
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
188
|
+
*
|
|
189
|
+
* // Update primary IP name
|
|
190
|
+
* const updated = await client.primaryIPs.update(12345, {
|
|
191
|
+
* name: 'new-primary-ip-name'
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* // Update labels
|
|
195
|
+
* const updated = await client.primaryIPs.update(12345, {
|
|
196
|
+
* labels: { environment: 'production', team: 'backend' }
|
|
197
|
+
* });
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
async update(
|
|
201
|
+
id: number,
|
|
202
|
+
params: UpdatePrimaryIPParams,
|
|
203
|
+
): Promise<UpdatePrimaryIPResponse> {
|
|
204
|
+
const validatedParams = validate(updatePrimaryIPRequestSchema, params, {
|
|
205
|
+
context: "Update primary IP request",
|
|
206
|
+
detailed: true,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const response = await this.client.put<unknown>(`/primary_ips/${id}`, validatedParams);
|
|
210
|
+
|
|
211
|
+
return validate(updatePrimaryIPResponseSchema, response, {
|
|
212
|
+
context: "Update primary IP response",
|
|
213
|
+
detailed: true,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Deletes a Primary IP.
|
|
219
|
+
*
|
|
220
|
+
* @param id - ID of the Primary IP
|
|
221
|
+
* @returns Promise resolving to the delete action
|
|
222
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-delete-a-primary-ip
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
227
|
+
*
|
|
228
|
+
* // Delete a primary IP
|
|
229
|
+
* const result = await client.primaryIPs.delete(12345);
|
|
230
|
+
* if (result.action) {
|
|
231
|
+
* console.log(`Delete action ID: ${result.action.id}`);
|
|
232
|
+
* }
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
async delete(id: number): Promise<DeletePrimaryIPResponse> {
|
|
236
|
+
const response = await this.client.delete<unknown>(`/primary_ips/${id}`);
|
|
237
|
+
|
|
238
|
+
return validate(deletePrimaryIPResponseSchema, response, {
|
|
239
|
+
context: "Delete primary IP response",
|
|
240
|
+
detailed: true,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Returns all Action objects for a Primary IP.
|
|
246
|
+
*
|
|
247
|
+
* @param id - ID of the Primary IP
|
|
248
|
+
* @param params - Query parameters for filtering and pagination
|
|
249
|
+
* @returns Promise resolving to list of actions with pagination metadata
|
|
250
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-list-actions-for-a-primary-ip
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
255
|
+
*
|
|
256
|
+
* // List all actions for a primary IP
|
|
257
|
+
* const actions = await client.primaryIPs.listActions(12345);
|
|
258
|
+
*
|
|
259
|
+
* // List actions with filters
|
|
260
|
+
* const runningActions = await client.primaryIPs.listActions(12345, {
|
|
261
|
+
* status: ['running'],
|
|
262
|
+
* sort: ['started:desc']
|
|
263
|
+
* });
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
async listActions(
|
|
267
|
+
id: number,
|
|
268
|
+
params?: ListPrimaryIPActionsParams,
|
|
269
|
+
): Promise<ListPrimaryIPActionsResponse> {
|
|
270
|
+
const queryParams: Record<string, string | number | string[] | undefined> = {};
|
|
271
|
+
|
|
272
|
+
if (params?.sort) {
|
|
273
|
+
queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (params?.status) {
|
|
277
|
+
queryParams.status = Array.isArray(params.status) ? params.status : [params.status];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (params?.page !== undefined) {
|
|
281
|
+
queryParams.page = params.page;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (params?.per_page !== undefined) {
|
|
285
|
+
queryParams.per_page = params.per_page;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const response = await this.client.get<unknown>(`/primary_ips/${id}/actions`, queryParams);
|
|
289
|
+
|
|
290
|
+
return validate(listPrimaryIPActionsResponseSchema, response, {
|
|
291
|
+
context: "List primary IP actions response",
|
|
292
|
+
detailed: true,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Returns a specific Action object for a Primary IP.
|
|
298
|
+
*
|
|
299
|
+
* @param id - ID of the Primary IP
|
|
300
|
+
* @param actionId - ID of the Action
|
|
301
|
+
* @returns Promise resolving to the action
|
|
302
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-get-an-action-for-a-primary-ip
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
307
|
+
*
|
|
308
|
+
* // Get an action by ID
|
|
309
|
+
* const action = await client.primaryIPs.getAction(12345, 67890);
|
|
310
|
+
* console.log(action.action.command);
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
async getAction(id: number, actionId: number): Promise<GetPrimaryIPActionResponse> {
|
|
314
|
+
const response = await this.client.get<unknown>(`/primary_ips/${id}/actions/${actionId}`);
|
|
315
|
+
|
|
316
|
+
return validate(getPrimaryIPActionResponseSchema, response, {
|
|
317
|
+
context: "Get primary IP action response",
|
|
318
|
+
detailed: true,
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Assigns a Primary IP to a resource.
|
|
324
|
+
*
|
|
325
|
+
* @param id - ID of the Primary IP
|
|
326
|
+
* @param params - Resource ID to assign the primary IP to
|
|
327
|
+
* @returns Promise resolving to the action
|
|
328
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-assign-a-primary-ip-to-a-resource
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
333
|
+
*
|
|
334
|
+
* // Assign primary IP to a server
|
|
335
|
+
* const result = await client.primaryIPs.assignToResource(12345, {
|
|
336
|
+
* assignee_id: 67890
|
|
337
|
+
* });
|
|
338
|
+
* console.log(`Action ID: ${result.action.id}`);
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
async assignToResource(
|
|
342
|
+
id: number,
|
|
343
|
+
params: AssignPrimaryIPToResourceParams,
|
|
344
|
+
): Promise<AssignPrimaryIPToResourceResponse> {
|
|
345
|
+
const validatedParams = validate(assignPrimaryIPToResourceRequestSchema, params, {
|
|
346
|
+
context: "Assign primary IP to resource request",
|
|
347
|
+
detailed: true,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
const response = await this.client.post<unknown>(
|
|
351
|
+
`/primary_ips/${id}/actions/assign`,
|
|
352
|
+
validatedParams,
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
return validate(assignPrimaryIPToResourceResponseSchema, response, {
|
|
356
|
+
context: "Assign primary IP to resource response",
|
|
357
|
+
detailed: true,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Changes the hostname that will appear when getting the hostname belonging to this Primary IP.
|
|
363
|
+
*
|
|
364
|
+
* @param id - ID of the Primary IP
|
|
365
|
+
* @param params - Reverse DNS configuration
|
|
366
|
+
* @returns Promise resolving to the action
|
|
367
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-reverse-dns-records-for-a-primary-ip
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```typescript
|
|
371
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
372
|
+
*
|
|
373
|
+
* // Change reverse DNS
|
|
374
|
+
* const result = await client.primaryIPs.changeReverseDNS(12345, {
|
|
375
|
+
* ip: '1.2.3.4',
|
|
376
|
+
* dns_ptr: 'server.example.com'
|
|
377
|
+
* });
|
|
378
|
+
* console.log(`Action ID: ${result.action.id}`);
|
|
379
|
+
* ```
|
|
380
|
+
*/
|
|
381
|
+
async changeReverseDNS(
|
|
382
|
+
id: number,
|
|
383
|
+
params: ChangePrimaryIPReverseDNSParams,
|
|
384
|
+
): Promise<ChangePrimaryIPReverseDNSResponse> {
|
|
385
|
+
const validatedParams = validate(changePrimaryIPReverseDNSRequestSchema, params, {
|
|
386
|
+
context: "Change primary IP reverse DNS request",
|
|
387
|
+
detailed: true,
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const response = await this.client.post<unknown>(
|
|
391
|
+
`/primary_ips/${id}/actions/change_dns_ptr`,
|
|
392
|
+
validatedParams,
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
return validate(changePrimaryIPReverseDNSResponseSchema, response, {
|
|
396
|
+
context: "Change primary IP reverse DNS response",
|
|
397
|
+
detailed: true,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Changes the Protection configuration of a Primary IP.
|
|
403
|
+
*
|
|
404
|
+
* @param id - ID of the Primary IP
|
|
405
|
+
* @param params - Protection configuration
|
|
406
|
+
* @returns Promise resolving to the action
|
|
407
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-primary-ip-protection
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```typescript
|
|
411
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
412
|
+
*
|
|
413
|
+
* // Enable delete protection
|
|
414
|
+
* const result = await client.primaryIPs.changeProtection(12345, {
|
|
415
|
+
* delete: true
|
|
416
|
+
* });
|
|
417
|
+
* console.log(`Action ID: ${result.action.id}`);
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
async changeProtection(
|
|
421
|
+
id: number,
|
|
422
|
+
params: ChangePrimaryIPProtectionParams,
|
|
423
|
+
): Promise<ChangePrimaryIPProtectionResponse> {
|
|
424
|
+
const validatedParams = validate(changePrimaryIPProtectionRequestSchema, params, {
|
|
425
|
+
context: "Change primary IP protection request",
|
|
426
|
+
detailed: true,
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
const response = await this.client.post<unknown>(
|
|
430
|
+
`/primary_ips/${id}/actions/change_protection`,
|
|
431
|
+
validatedParams,
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
return validate(changePrimaryIPProtectionResponseSchema, response, {
|
|
435
|
+
context: "Change primary IP protection response",
|
|
436
|
+
detailed: true,
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Unassigns a Primary IP from a resource.
|
|
442
|
+
*
|
|
443
|
+
* @param id - ID of the Primary IP
|
|
444
|
+
* @returns Promise resolving to the action
|
|
445
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-unassign-a-primary-ip-from-a-resource
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```typescript
|
|
449
|
+
* const client = new HCloudClient({ token: 'your-token' });
|
|
450
|
+
*
|
|
451
|
+
* // Unassign primary IP
|
|
452
|
+
* const result = await client.primaryIPs.unassign(12345);
|
|
453
|
+
* console.log(`Action ID: ${result.action.id}`);
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
async unassign(id: number): Promise<UnassignPrimaryIPResponse> {
|
|
457
|
+
const response = await this.client.post<unknown>(
|
|
458
|
+
`/primary_ips/${id}/actions/unassign`,
|
|
459
|
+
{},
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
return validate(unassignPrimaryIPResponseSchema, response, {
|
|
463
|
+
context: "Unassign primary IP response",
|
|
464
|
+
detailed: true,
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for Hetzner Cloud Primary IPs API
|
|
3
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { actionSchema } from "../../apis/actions/schemas";
|
|
8
|
+
import { paginationMetaSchema } from "../../apis/common/schemas";
|
|
9
|
+
import { locationSchema } from "../../apis/servers/schemas";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Primary IP type schema
|
|
13
|
+
*/
|
|
14
|
+
export const primaryIpTypeSchema = z.enum(["ipv4", "ipv6"]);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Primary IP DNS pointer schema
|
|
18
|
+
*/
|
|
19
|
+
export const primaryIpDnsPointerSchema = z.object({
|
|
20
|
+
ip: z.string(),
|
|
21
|
+
dns_ptr: z.string(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Primary IP protection schema
|
|
26
|
+
*/
|
|
27
|
+
export const primaryIpProtectionSchema = z.object({
|
|
28
|
+
delete: z.boolean(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Primary IP assignee type schema
|
|
33
|
+
*/
|
|
34
|
+
export const primaryIpAssigneeTypeSchema = z.enum(["server"]);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Primary IP schema
|
|
38
|
+
*/
|
|
39
|
+
export const primaryIpSchema = z
|
|
40
|
+
.object({
|
|
41
|
+
id: z.number(),
|
|
42
|
+
name: z.string(),
|
|
43
|
+
ip: z.string(),
|
|
44
|
+
type: primaryIpTypeSchema,
|
|
45
|
+
assignee_id: z.number().nullable(),
|
|
46
|
+
assignee_type: primaryIpAssigneeTypeSchema.nullable(),
|
|
47
|
+
auto_delete: z.boolean(),
|
|
48
|
+
blocked: z.boolean(),
|
|
49
|
+
created: z.string(),
|
|
50
|
+
datacenter: z
|
|
51
|
+
.object({
|
|
52
|
+
id: z.number(),
|
|
53
|
+
name: z.string(),
|
|
54
|
+
description: z.string(),
|
|
55
|
+
location: locationSchema,
|
|
56
|
+
server_types: z.object({
|
|
57
|
+
supported: z.array(z.number()),
|
|
58
|
+
available: z.array(z.number()),
|
|
59
|
+
available_for_migration: z.array(z.number()),
|
|
60
|
+
}),
|
|
61
|
+
})
|
|
62
|
+
.nullable(),
|
|
63
|
+
dns_ptr: z.array(primaryIpDnsPointerSchema),
|
|
64
|
+
labels: z.record(z.string(), z.string()),
|
|
65
|
+
protection: primaryIpProtectionSchema,
|
|
66
|
+
})
|
|
67
|
+
.passthrough();
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* List Primary IPs response schema
|
|
71
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-list-primary-ips
|
|
72
|
+
*/
|
|
73
|
+
export const listPrimaryIPsResponseSchema = z.object({
|
|
74
|
+
primary_ips: z.array(primaryIpSchema),
|
|
75
|
+
meta: z
|
|
76
|
+
.object({
|
|
77
|
+
pagination: paginationMetaSchema,
|
|
78
|
+
})
|
|
79
|
+
.optional(),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Create Primary IP request schema
|
|
84
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-create-a-primary-ip
|
|
85
|
+
*/
|
|
86
|
+
export const createPrimaryIPRequestSchema = z.object({
|
|
87
|
+
name: z.string(),
|
|
88
|
+
type: primaryIpTypeSchema,
|
|
89
|
+
assignee_id: z.number().optional(),
|
|
90
|
+
assignee_type: primaryIpAssigneeTypeSchema.optional(),
|
|
91
|
+
auto_delete: z.boolean().optional(),
|
|
92
|
+
datacenter: z.string().optional(),
|
|
93
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Create Primary IP response schema
|
|
98
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-create-a-primary-ip
|
|
99
|
+
*/
|
|
100
|
+
export const createPrimaryIPResponseSchema = z.object({
|
|
101
|
+
primary_ip: primaryIpSchema,
|
|
102
|
+
action: actionSchema,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Get Primary IP response schema
|
|
107
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-get-a-primary-ip
|
|
108
|
+
*/
|
|
109
|
+
export const getPrimaryIPResponseSchema = z.object({
|
|
110
|
+
primary_ip: primaryIpSchema,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Update Primary IP request schema
|
|
115
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-update-a-primary-ip
|
|
116
|
+
*/
|
|
117
|
+
export const updatePrimaryIPRequestSchema = z.object({
|
|
118
|
+
name: z.string().optional(),
|
|
119
|
+
auto_delete: z.boolean().optional(),
|
|
120
|
+
labels: z.record(z.string(), z.string()).optional(),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Update Primary IP response schema
|
|
125
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-update-a-primary-ip
|
|
126
|
+
*/
|
|
127
|
+
export const updatePrimaryIPResponseSchema = z.object({
|
|
128
|
+
primary_ip: primaryIpSchema,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Delete Primary IP response schema
|
|
133
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-delete-a-primary-ip
|
|
134
|
+
*/
|
|
135
|
+
export const deletePrimaryIPResponseSchema = z.object({
|
|
136
|
+
action: actionSchema.optional(),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* List Primary IP Actions response schema
|
|
141
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-list-actions-for-a-primary-ip
|
|
142
|
+
*/
|
|
143
|
+
export const listPrimaryIPActionsResponseSchema = z.object({
|
|
144
|
+
actions: z.array(actionSchema),
|
|
145
|
+
meta: z
|
|
146
|
+
.object({
|
|
147
|
+
pagination: paginationMetaSchema,
|
|
148
|
+
})
|
|
149
|
+
.optional(),
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Get Primary IP Action response schema
|
|
154
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-get-an-action-for-a-primary-ip
|
|
155
|
+
*/
|
|
156
|
+
export const getPrimaryIPActionResponseSchema = z.object({
|
|
157
|
+
action: actionSchema,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Assign Primary IP to resource request schema
|
|
162
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-assign-a-primary-ip-to-a-resource
|
|
163
|
+
*/
|
|
164
|
+
export const assignPrimaryIPToResourceRequestSchema = z.object({
|
|
165
|
+
assignee_id: z.number(),
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Assign Primary IP to resource response schema
|
|
170
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-assign-a-primary-ip-to-a-resource
|
|
171
|
+
*/
|
|
172
|
+
export const assignPrimaryIPToResourceResponseSchema = z.object({
|
|
173
|
+
action: actionSchema,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Change Primary IP reverse DNS request schema
|
|
178
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-reverse-dns-records-for-a-primary-ip
|
|
179
|
+
*/
|
|
180
|
+
export const changePrimaryIPReverseDNSRequestSchema = z.object({
|
|
181
|
+
ip: z.string(),
|
|
182
|
+
dns_ptr: z.string().nullable(),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Change Primary IP reverse DNS response schema
|
|
187
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-reverse-dns-records-for-a-primary-ip
|
|
188
|
+
*/
|
|
189
|
+
export const changePrimaryIPReverseDNSResponseSchema = z.object({
|
|
190
|
+
action: actionSchema,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Change Primary IP Protection request schema
|
|
195
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-primary-ip-protection
|
|
196
|
+
*/
|
|
197
|
+
export const changePrimaryIPProtectionRequestSchema = z.object({
|
|
198
|
+
delete: z.boolean(),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Change Primary IP Protection response schema
|
|
203
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-primary-ip-protection
|
|
204
|
+
*/
|
|
205
|
+
export const changePrimaryIPProtectionResponseSchema = z.object({
|
|
206
|
+
action: actionSchema,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Unassign Primary IP request schema
|
|
211
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-unassign-a-primary-ip-from-a-resource
|
|
212
|
+
*/
|
|
213
|
+
export const unassignPrimaryIPRequestSchema = z.object({});
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Unassign Primary IP response schema
|
|
217
|
+
* @see https://docs.hetzner.cloud/reference/cloud#primary-ips-unassign-a-primary-ip-from-a-resource
|
|
218
|
+
*/
|
|
219
|
+
export const unassignPrimaryIPResponseSchema = z.object({
|
|
220
|
+
action: actionSchema,
|
|
221
|
+
});
|