@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.
Files changed (62) hide show
  1. package/README.md +90 -0
  2. package/package.json +70 -0
  3. package/src/apis/actions/index.ts +113 -0
  4. package/src/apis/actions/schemas.ts +59 -0
  5. package/src/apis/actions/types.ts +77 -0
  6. package/src/apis/certificates/index.ts +326 -0
  7. package/src/apis/certificates/schemas.ts +140 -0
  8. package/src/apis/certificates/types.ts +176 -0
  9. package/src/apis/common/schemas.ts +19 -0
  10. package/src/apis/dns/index.ts +961 -0
  11. package/src/apis/dns/schemas.ts +437 -0
  12. package/src/apis/dns/types.ts +397 -0
  13. package/src/apis/firewalls/index.ts +469 -0
  14. package/src/apis/firewalls/schemas.ts +274 -0
  15. package/src/apis/firewalls/types.ts +205 -0
  16. package/src/apis/floating-ips/index.ts +466 -0
  17. package/src/apis/floating-ips/schemas.ts +203 -0
  18. package/src/apis/floating-ips/types.ts +207 -0
  19. package/src/apis/images/index.ts +195 -0
  20. package/src/apis/images/schemas.ts +113 -0
  21. package/src/apis/images/types.ts +124 -0
  22. package/src/apis/isos/index.ts +91 -0
  23. package/src/apis/isos/schemas.ts +43 -0
  24. package/src/apis/isos/types.ts +60 -0
  25. package/src/apis/load-balancers/index.ts +892 -0
  26. package/src/apis/load-balancers/schemas.ts +561 -0
  27. package/src/apis/load-balancers/types.ts +361 -0
  28. package/src/apis/locations/index.ts +176 -0
  29. package/src/apis/locations/schemas.ts +83 -0
  30. package/src/apis/locations/types.ts +113 -0
  31. package/src/apis/networks/index.ts +544 -0
  32. package/src/apis/networks/schemas.ts +279 -0
  33. package/src/apis/networks/types.ts +243 -0
  34. package/src/apis/placement-groups/index.ts +212 -0
  35. package/src/apis/placement-groups/schemas.ts +90 -0
  36. package/src/apis/placement-groups/types.ts +99 -0
  37. package/src/apis/pricing/index.ts +42 -0
  38. package/src/apis/pricing/schemas.ts +93 -0
  39. package/src/apis/pricing/types.ts +71 -0
  40. package/src/apis/primary-ips/index.ts +467 -0
  41. package/src/apis/primary-ips/schemas.ts +221 -0
  42. package/src/apis/primary-ips/types.ts +221 -0
  43. package/src/apis/server-types/index.ts +93 -0
  44. package/src/apis/server-types/schemas.ts +29 -0
  45. package/src/apis/server-types/types.ts +43 -0
  46. package/src/apis/servers/index.ts +378 -0
  47. package/src/apis/servers/schemas.ts +771 -0
  48. package/src/apis/servers/types.ts +538 -0
  49. package/src/apis/ssh-keys/index.ts +204 -0
  50. package/src/apis/ssh-keys/schemas.ts +84 -0
  51. package/src/apis/ssh-keys/types.ts +106 -0
  52. package/src/apis/volumes/index.ts +452 -0
  53. package/src/apis/volumes/schemas.ts +195 -0
  54. package/src/apis/volumes/types.ts +197 -0
  55. package/src/auth/index.ts +26 -0
  56. package/src/base/index.ts +10 -0
  57. package/src/client/index.ts +388 -0
  58. package/src/config/index.ts +34 -0
  59. package/src/errors/index.ts +38 -0
  60. package/src/index.ts +799 -0
  61. package/src/types/index.ts +37 -0
  62. package/src/validation/index.ts +109 -0
@@ -0,0 +1,961 @@
1
+ /**
2
+ * Hetzner Cloud DNS (Zones) API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#dns
4
+ */
5
+
6
+ import type { HCloudClient } from "../../client/index";
7
+ import type {
8
+ ListZonesParams,
9
+ ListZonesResponse,
10
+ CreateZoneParams,
11
+ CreateZoneResponse,
12
+ GetZoneResponse,
13
+ UpdateZoneParams,
14
+ UpdateZoneResponse,
15
+ DeleteZoneResponse,
16
+ ExportZoneResponse,
17
+ ListZoneActionsParams,
18
+ ListZoneActionsResponse,
19
+ GetZoneActionResponse,
20
+ ChangeZonePrimaryNameserversParams,
21
+ ChangeZonePrimaryNameserversResponse,
22
+ ChangeZoneProtectionParams,
23
+ ChangeZoneProtectionResponse,
24
+ ChangeZoneDefaultTTLParams,
25
+ ChangeZoneDefaultTTLResponse,
26
+ ImportZoneFileParams,
27
+ ImportZoneFileResponse,
28
+ ListRRSetsParams,
29
+ ListRRSetsResponse,
30
+ GetRRSetResponse,
31
+ CreateRRSetParams,
32
+ CreateRRSetResponse,
33
+ UpdateRRSetParams,
34
+ UpdateRRSetResponse,
35
+ DeleteRRSetResponse,
36
+ ChangeRRSetProtectionParams,
37
+ ChangeRRSetProtectionResponse,
38
+ ChangeRRSetTTLParams,
39
+ ChangeRRSetTTLResponse,
40
+ SetRRSetRecordsParams,
41
+ SetRRSetRecordsResponse,
42
+ AddRRSetRecordsParams,
43
+ AddRRSetRecordsResponse,
44
+ RemoveRRSetRecordsParams,
45
+ RemoveRRSetRecordsResponse,
46
+ UpdateRRSetRecordsParams,
47
+ UpdateRRSetRecordsResponse,
48
+ } from "../../apis/dns/types";
49
+ import { validate } from "../../validation/index";
50
+ import {
51
+ listZonesResponseSchema,
52
+ createZoneRequestSchema,
53
+ createZoneResponseSchema,
54
+ getZoneResponseSchema,
55
+ updateZoneRequestSchema,
56
+ updateZoneResponseSchema,
57
+ deleteZoneResponseSchema,
58
+ exportZoneResponseSchema,
59
+ listZoneActionsResponseSchema,
60
+ getZoneActionResponseSchema,
61
+ changeZonePrimaryNameserversRequestSchema,
62
+ changeZonePrimaryNameserversResponseSchema,
63
+ changeZoneProtectionRequestSchema,
64
+ changeZoneProtectionResponseSchema,
65
+ changeZoneDefaultTTLRequestSchema,
66
+ changeZoneDefaultTTLResponseSchema,
67
+ importZoneFileRequestSchema,
68
+ importZoneFileResponseSchema,
69
+ listRRSetsResponseSchema,
70
+ getRRSetResponseSchema,
71
+ createRRSetRequestSchema,
72
+ createRRSetResponseSchema,
73
+ updateRRSetRequestSchema,
74
+ updateRRSetResponseSchema,
75
+ deleteRRSetResponseSchema,
76
+ changeRRSetProtectionRequestSchema,
77
+ changeRRSetProtectionResponseSchema,
78
+ changeRRSetTTLRequestSchema,
79
+ changeRRSetTTLResponseSchema,
80
+ setRRSetRecordsRequestSchema,
81
+ setRRSetRecordsResponseSchema,
82
+ addRRSetRecordsRequestSchema,
83
+ addRRSetRecordsResponseSchema,
84
+ removeRRSetRecordsRequestSchema,
85
+ removeRRSetRecordsResponseSchema,
86
+ updateRRSetRecordsRequestSchema,
87
+ updateRRSetRecordsResponseSchema,
88
+ } from "../../apis/dns/schemas";
89
+
90
+ /**
91
+ * DNS (Zones) API client
92
+ */
93
+ export class DNSClient {
94
+ constructor(private readonly client: HCloudClient) {}
95
+
96
+ /**
97
+ * Returns all Zone objects.
98
+ *
99
+ * @param params - Query parameters for filtering and pagination
100
+ * @returns Promise resolving to list of zones with pagination metadata
101
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-list-zones
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * const client = new HCloudClient({ token: 'your-token' });
106
+ *
107
+ * // List all zones
108
+ * const result = await client.dns.listZones();
109
+ *
110
+ * // List zones with filters
111
+ * const zones = await client.dns.listZones({
112
+ * name: 'example.com',
113
+ * label_selector: 'environment=production',
114
+ * sort: ['name:asc'],
115
+ * page: 1,
116
+ * per_page: 50
117
+ * });
118
+ * ```
119
+ */
120
+ async listZones(params?: ListZonesParams): Promise<ListZonesResponse> {
121
+ const queryParams: Record<string, string | number | string[] | undefined> = {};
122
+
123
+ if (params?.name) {
124
+ queryParams.name = params.name;
125
+ }
126
+
127
+ if (params?.label_selector) {
128
+ queryParams.label_selector = params.label_selector;
129
+ }
130
+
131
+ if (params?.sort) {
132
+ queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
133
+ }
134
+
135
+ if (params?.page !== undefined) {
136
+ queryParams.page = params.page;
137
+ }
138
+
139
+ if (params?.per_page !== undefined) {
140
+ queryParams.per_page = params.per_page;
141
+ }
142
+
143
+ const response = await this.client.get<unknown>("/zones", queryParams);
144
+
145
+ return validate(listZonesResponseSchema, response, {
146
+ context: "List zones response",
147
+ detailed: true,
148
+ });
149
+ }
150
+
151
+ /**
152
+ * Creates a new Zone.
153
+ *
154
+ * @param params - Parameters for creating the zone
155
+ * @returns Promise resolving to the created zone and action
156
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-create-a-zone
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const client = new HCloudClient({ token: 'your-token' });
161
+ *
162
+ * const zone = await client.dns.createZone({
163
+ * name: 'example.com',
164
+ * ttl: 3600,
165
+ * labels: { environment: 'production' }
166
+ * });
167
+ * ```
168
+ */
169
+ async createZone(params: CreateZoneParams): Promise<CreateZoneResponse> {
170
+ const validatedParams = validate(createZoneRequestSchema, params, {
171
+ context: "Create zone request",
172
+ detailed: true,
173
+ });
174
+
175
+ const response = await this.client.post<unknown>("/zones", validatedParams);
176
+
177
+ return validate(createZoneResponseSchema, response, {
178
+ context: "Create zone response",
179
+ detailed: true,
180
+ });
181
+ }
182
+
183
+ /**
184
+ * Returns a specific Zone object.
185
+ *
186
+ * @param idOrName - ID or name of the Zone
187
+ * @returns Promise resolving to the zone
188
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-get-a-zone
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const client = new HCloudClient({ token: 'your-token' });
193
+ *
194
+ * // Get a zone by ID or name
195
+ * const zone = await client.dns.getZone('example.com');
196
+ * console.log(zone.zone.name);
197
+ * ```
198
+ */
199
+ async getZone(idOrName: string): Promise<GetZoneResponse> {
200
+ const response = await this.client.get<unknown>(`/zones/${idOrName}`);
201
+
202
+ return validate(getZoneResponseSchema, response, {
203
+ context: "Get zone response",
204
+ detailed: true,
205
+ });
206
+ }
207
+
208
+ /**
209
+ * Updates the Zone.
210
+ *
211
+ * You can update a Zone's TTL and labels.
212
+ *
213
+ * @param idOrName - ID or name of the Zone
214
+ * @param params - Parameters to update (ttl and/or labels)
215
+ * @returns Promise resolving to the updated zone
216
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-update-a-zone
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * const client = new HCloudClient({ token: 'your-token' });
221
+ *
222
+ * const updated = await client.dns.updateZone('example.com', {
223
+ * ttl: 7200,
224
+ * labels: { environment: 'production' }
225
+ * });
226
+ * ```
227
+ */
228
+ async updateZone(idOrName: string, params: UpdateZoneParams): Promise<UpdateZoneResponse> {
229
+ const validatedParams = validate(updateZoneRequestSchema, params, {
230
+ context: "Update zone request",
231
+ detailed: true,
232
+ });
233
+
234
+ const response = await this.client.put<unknown>(`/zones/${idOrName}`, validatedParams);
235
+
236
+ return validate(updateZoneResponseSchema, response, {
237
+ context: "Update zone response",
238
+ detailed: true,
239
+ });
240
+ }
241
+
242
+ /**
243
+ * Deletes a Zone.
244
+ *
245
+ * @param idOrName - ID or name of the Zone
246
+ * @returns Promise resolving to empty object
247
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-delete-a-zone
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * const client = new HCloudClient({ token: 'your-token' });
252
+ *
253
+ * await client.dns.deleteZone('example.com');
254
+ * ```
255
+ */
256
+ async deleteZone(idOrName: string): Promise<DeleteZoneResponse> {
257
+ const response = await this.client.delete<unknown>(`/zones/${idOrName}`);
258
+
259
+ return validate(deleteZoneResponseSchema, response, {
260
+ context: "Delete zone response",
261
+ detailed: true,
262
+ });
263
+ }
264
+
265
+ /**
266
+ * Exports a Zone file.
267
+ *
268
+ * @param idOrName - ID or name of the Zone
269
+ * @returns Promise resolving to the zone file content
270
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-export-a-zone-file
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const client = new HCloudClient({ token: 'your-token' });
275
+ *
276
+ * const exported = await client.dns.exportZone('example.com');
277
+ * console.log(exported.zone_file);
278
+ * ```
279
+ */
280
+ async exportZone(idOrName: string): Promise<ExportZoneResponse> {
281
+ const response = await this.client.get<unknown>(`/zones/${idOrName}/export`);
282
+
283
+ return validate(exportZoneResponseSchema, response, {
284
+ context: "Export zone response",
285
+ detailed: true,
286
+ });
287
+ }
288
+
289
+ /**
290
+ * Returns all Action objects for a Zone.
291
+ *
292
+ * @param idOrName - ID or name of the Zone
293
+ * @param params - Query parameters for filtering and pagination
294
+ * @returns Promise resolving to list of actions with pagination metadata
295
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-list-actions-for-a-zone
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * const client = new HCloudClient({ token: 'your-token' });
300
+ *
301
+ * const actions = await client.dns.listZoneActions('example.com', {
302
+ * status: ['running'],
303
+ * sort: ['started:desc']
304
+ * });
305
+ * ```
306
+ */
307
+ async listZoneActions(
308
+ idOrName: string,
309
+ params?: ListZoneActionsParams,
310
+ ): Promise<ListZoneActionsResponse> {
311
+ const queryParams: Record<string, string | number | string[] | undefined> = {};
312
+
313
+ if (params?.sort) {
314
+ queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
315
+ }
316
+
317
+ if (params?.status) {
318
+ queryParams.status = Array.isArray(params.status) ? params.status : [params.status];
319
+ }
320
+
321
+ if (params?.page !== undefined) {
322
+ queryParams.page = params.page;
323
+ }
324
+
325
+ if (params?.per_page !== undefined) {
326
+ queryParams.per_page = params.per_page;
327
+ }
328
+
329
+ const response = await this.client.get<unknown>(`/zones/${idOrName}/actions`, queryParams);
330
+
331
+ return validate(listZoneActionsResponseSchema, response, {
332
+ context: "List zone actions response",
333
+ detailed: true,
334
+ });
335
+ }
336
+
337
+ /**
338
+ * Returns a specific Action object for a Zone.
339
+ *
340
+ * @param idOrName - ID or name of the Zone
341
+ * @param actionId - ID of the Action
342
+ * @returns Promise resolving to the action
343
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-get-an-action-for-a-zone
344
+ *
345
+ * @example
346
+ * ```typescript
347
+ * const client = new HCloudClient({ token: 'your-token' });
348
+ *
349
+ * const action = await client.dns.getZoneAction('example.com', 12345);
350
+ * console.log(action.action.command);
351
+ * ```
352
+ */
353
+ async getZoneAction(idOrName: string, actionId: number): Promise<GetZoneActionResponse> {
354
+ const response = await this.client.get<unknown>(`/zones/${idOrName}/actions/${actionId}`);
355
+
356
+ return validate(getZoneActionResponseSchema, response, {
357
+ context: "Get zone action response",
358
+ detailed: true,
359
+ });
360
+ }
361
+
362
+ /**
363
+ * Changes the primary nameservers of a Zone.
364
+ *
365
+ * @param idOrName - ID or name of the Zone
366
+ * @param params - Nameservers configuration
367
+ * @returns Promise resolving to the action
368
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-change-a-zones-primary-nameservers
369
+ *
370
+ * @example
371
+ * ```typescript
372
+ * const client = new HCloudClient({ token: 'your-token' });
373
+ *
374
+ * const result = await client.dns.changeZonePrimaryNameservers('example.com', {
375
+ * nameservers: ['ns1.example.com', 'ns2.example.com']
376
+ * });
377
+ * ```
378
+ */
379
+ async changeZonePrimaryNameservers(
380
+ idOrName: string,
381
+ params: ChangeZonePrimaryNameserversParams,
382
+ ): Promise<ChangeZonePrimaryNameserversResponse> {
383
+ const validatedParams = validate(changeZonePrimaryNameserversRequestSchema, params, {
384
+ context: "Change zone primary nameservers request",
385
+ detailed: true,
386
+ });
387
+
388
+ const response = await this.client.post<unknown>(
389
+ `/zones/${idOrName}/actions/change_nameservers`,
390
+ validatedParams,
391
+ );
392
+
393
+ return validate(changeZonePrimaryNameserversResponseSchema, response, {
394
+ context: "Change zone primary nameservers response",
395
+ detailed: true,
396
+ });
397
+ }
398
+
399
+ /**
400
+ * Changes the Protection configuration of a Zone.
401
+ *
402
+ * @param idOrName - ID or name of the Zone
403
+ * @param params - Protection configuration
404
+ * @returns Promise resolving to the action
405
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-change-a-zones-protection
406
+ *
407
+ * @example
408
+ * ```typescript
409
+ * const client = new HCloudClient({ token: 'your-token' });
410
+ *
411
+ * const result = await client.dns.changeZoneProtection('example.com', {
412
+ * delete: true
413
+ * });
414
+ * ```
415
+ */
416
+ async changeZoneProtection(
417
+ idOrName: string,
418
+ params: ChangeZoneProtectionParams,
419
+ ): Promise<ChangeZoneProtectionResponse> {
420
+ const validatedParams = validate(changeZoneProtectionRequestSchema, params, {
421
+ context: "Change zone protection request",
422
+ detailed: true,
423
+ });
424
+
425
+ const response = await this.client.post<unknown>(
426
+ `/zones/${idOrName}/actions/change_protection`,
427
+ validatedParams,
428
+ );
429
+
430
+ return validate(changeZoneProtectionResponseSchema, response, {
431
+ context: "Change zone protection response",
432
+ detailed: true,
433
+ });
434
+ }
435
+
436
+ /**
437
+ * Changes the default TTL of a Zone.
438
+ *
439
+ * @param idOrName - ID or name of the Zone
440
+ * @param params - TTL configuration
441
+ * @returns Promise resolving to the action
442
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-change-a-zones-default-ttl
443
+ *
444
+ * @example
445
+ * ```typescript
446
+ * const client = new HCloudClient({ token: 'your-token' });
447
+ *
448
+ * const result = await client.dns.changeZoneDefaultTTL('example.com', {
449
+ * ttl: 7200
450
+ * });
451
+ * ```
452
+ */
453
+ async changeZoneDefaultTTL(
454
+ idOrName: string,
455
+ params: ChangeZoneDefaultTTLParams,
456
+ ): Promise<ChangeZoneDefaultTTLResponse> {
457
+ const validatedParams = validate(changeZoneDefaultTTLRequestSchema, params, {
458
+ context: "Change zone default TTL request",
459
+ detailed: true,
460
+ });
461
+
462
+ const response = await this.client.post<unknown>(
463
+ `/zones/${idOrName}/actions/change_ttl`,
464
+ validatedParams,
465
+ );
466
+
467
+ return validate(changeZoneDefaultTTLResponseSchema, response, {
468
+ context: "Change zone default TTL response",
469
+ detailed: true,
470
+ });
471
+ }
472
+
473
+ /**
474
+ * Imports a Zone file.
475
+ *
476
+ * @param idOrName - ID or name of the Zone
477
+ * @param params - Zone file content
478
+ * @returns Promise resolving to the zone and action
479
+ * @see https://docs.hetzner.cloud/reference/cloud#zones-import-a-zone-file
480
+ *
481
+ * @example
482
+ * ```typescript
483
+ * const client = new HCloudClient({ token: 'your-token' });
484
+ *
485
+ * const result = await client.dns.importZoneFile('example.com', {
486
+ * zone_file: '$ORIGIN example.com.\n$TTL 3600\n...'
487
+ * });
488
+ * ```
489
+ */
490
+ async importZoneFile(
491
+ idOrName: string,
492
+ params: ImportZoneFileParams,
493
+ ): Promise<ImportZoneFileResponse> {
494
+ const validatedParams = validate(importZoneFileRequestSchema, params, {
495
+ context: "Import zone file request",
496
+ detailed: true,
497
+ });
498
+
499
+ const response = await this.client.post<unknown>(
500
+ `/zones/${idOrName}/actions/import`,
501
+ validatedParams,
502
+ );
503
+
504
+ return validate(importZoneFileResponseSchema, response, {
505
+ context: "Import zone file response",
506
+ detailed: true,
507
+ });
508
+ }
509
+
510
+ /**
511
+ * Returns all RRSet objects for a Zone.
512
+ *
513
+ * @param idOrName - ID or name of the Zone
514
+ * @param params - Query parameters for filtering and pagination
515
+ * @returns Promise resolving to list of RRSets with pagination metadata
516
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-list-rrsets
517
+ *
518
+ * @example
519
+ * ```typescript
520
+ * const client = new HCloudClient({ token: 'your-token' });
521
+ *
522
+ * // List all RRSets for a zone
523
+ * const rrsets = await client.dns.listRRSets('example.com');
524
+ *
525
+ * // List RRSets with filters
526
+ * const aRecords = await client.dns.listRRSets('example.com', {
527
+ * type: 'A',
528
+ * name: 'www',
529
+ * sort: ['name:asc']
530
+ * });
531
+ * ```
532
+ */
533
+ async listRRSets(idOrName: string, params?: ListRRSetsParams): Promise<ListRRSetsResponse> {
534
+ const queryParams: Record<string, string | number | string[] | undefined> = {};
535
+
536
+ if (params?.name) {
537
+ queryParams.name = params.name;
538
+ }
539
+
540
+ if (params?.type) {
541
+ queryParams.type = params.type;
542
+ }
543
+
544
+ if (params?.label_selector) {
545
+ queryParams.label_selector = params.label_selector;
546
+ }
547
+
548
+ if (params?.sort) {
549
+ queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
550
+ }
551
+
552
+ if (params?.page !== undefined) {
553
+ queryParams.page = params.page;
554
+ }
555
+
556
+ if (params?.per_page !== undefined) {
557
+ queryParams.per_page = params.per_page;
558
+ }
559
+
560
+ const response = await this.client.get<unknown>(`/zones/${idOrName}/rrsets`, queryParams);
561
+
562
+ return validate(listRRSetsResponseSchema, response, {
563
+ context: "List RRSets response",
564
+ detailed: true,
565
+ });
566
+ }
567
+
568
+ /**
569
+ * Returns a specific RRSet object.
570
+ *
571
+ * @param idOrName - ID or name of the Zone
572
+ * @param rrName - Name of the RRSet
573
+ * @param rrType - Type of the RRSet
574
+ * @returns Promise resolving to the RRSet
575
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-get-an-rrset
576
+ *
577
+ * @example
578
+ * ```typescript
579
+ * const client = new HCloudClient({ token: 'your-token' });
580
+ *
581
+ * const rrset = await client.dns.getRRSet('example.com', 'www', 'A');
582
+ * console.log(rrset.rrset.name);
583
+ * ```
584
+ */
585
+ async getRRSet(idOrName: string, rrName: string, rrType: string): Promise<GetRRSetResponse> {
586
+ const response = await this.client.get<unknown>(
587
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}`,
588
+ );
589
+
590
+ return validate(getRRSetResponseSchema, response, {
591
+ context: "Get RRSet response",
592
+ detailed: true,
593
+ });
594
+ }
595
+
596
+ /**
597
+ * Creates a new RRSet.
598
+ *
599
+ * @param idOrName - ID or name of the Zone
600
+ * @param params - Parameters for creating the RRSet
601
+ * @returns Promise resolving to the created RRSet and action
602
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-create-an-rrset
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * const client = new HCloudClient({ token: 'your-token' });
607
+ *
608
+ * const rrset = await client.dns.createRRSet('example.com', {
609
+ * name: 'www',
610
+ * type: 'A',
611
+ * ttl: 3600,
612
+ * records: [
613
+ * { value: '1.2.3.4', comment: 'Web server' }
614
+ * ]
615
+ * });
616
+ * ```
617
+ */
618
+ async createRRSet(idOrName: string, params: CreateRRSetParams): Promise<CreateRRSetResponse> {
619
+ const validatedParams = validate(createRRSetRequestSchema, params, {
620
+ context: "Create RRSet request",
621
+ detailed: true,
622
+ });
623
+
624
+ const response = await this.client.post<unknown>(
625
+ `/zones/${idOrName}/rrsets`,
626
+ validatedParams,
627
+ );
628
+
629
+ return validate(createRRSetResponseSchema, response, {
630
+ context: "Create RRSet response",
631
+ detailed: true,
632
+ });
633
+ }
634
+
635
+ /**
636
+ * Updates an RRSet.
637
+ *
638
+ * @param idOrName - ID or name of the Zone
639
+ * @param rrName - Name of the RRSet
640
+ * @param rrType - Type of the RRSet
641
+ * @param params - Parameters to update
642
+ * @returns Promise resolving to the updated RRSet and action
643
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-update-an-rrset
644
+ *
645
+ * @example
646
+ * ```typescript
647
+ * const client = new HCloudClient({ token: 'your-token' });
648
+ *
649
+ * const updated = await client.dns.updateRRSet('example.com', 'www', 'A', {
650
+ * ttl: 7200,
651
+ * records: [
652
+ * { value: '5.6.7.8', comment: 'Updated web server' }
653
+ * ]
654
+ * });
655
+ * ```
656
+ */
657
+ async updateRRSet(
658
+ idOrName: string,
659
+ rrName: string,
660
+ rrType: string,
661
+ params: UpdateRRSetParams,
662
+ ): Promise<UpdateRRSetResponse> {
663
+ const validatedParams = validate(updateRRSetRequestSchema, params, {
664
+ context: "Update RRSet request",
665
+ detailed: true,
666
+ });
667
+
668
+ const response = await this.client.put<unknown>(
669
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}`,
670
+ validatedParams,
671
+ );
672
+
673
+ return validate(updateRRSetResponseSchema, response, {
674
+ context: "Update RRSet response",
675
+ detailed: true,
676
+ });
677
+ }
678
+
679
+ /**
680
+ * Deletes an RRSet.
681
+ *
682
+ * @param idOrName - ID or name of the Zone
683
+ * @param rrName - Name of the RRSet
684
+ * @param rrType - Type of the RRSet
685
+ * @returns Promise resolving to the delete action
686
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-delete-an-rrset
687
+ *
688
+ * @example
689
+ * ```typescript
690
+ * const client = new HCloudClient({ token: 'your-token' });
691
+ *
692
+ * const result = await client.dns.deleteRRSet('example.com', 'www', 'A');
693
+ * ```
694
+ */
695
+ async deleteRRSet(idOrName: string, rrName: string, rrType: string): Promise<DeleteRRSetResponse> {
696
+ const response = await this.client.delete<unknown>(
697
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}`,
698
+ );
699
+
700
+ return validate(deleteRRSetResponseSchema, response, {
701
+ context: "Delete RRSet response",
702
+ detailed: true,
703
+ });
704
+ }
705
+
706
+ /**
707
+ * Changes the Protection configuration of an RRSet.
708
+ *
709
+ * @param idOrName - ID or name of the Zone
710
+ * @param rrName - Name of the RRSet
711
+ * @param rrType - Type of the RRSet
712
+ * @param params - Protection configuration
713
+ * @returns Promise resolving to the action
714
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-change-an-rrsets-protection
715
+ *
716
+ * @example
717
+ * ```typescript
718
+ * const client = new HCloudClient({ token: 'your-token' });
719
+ *
720
+ * const result = await client.dns.changeRRSetProtection('example.com', 'www', 'A', {
721
+ * delete: true
722
+ * });
723
+ * ```
724
+ */
725
+ async changeRRSetProtection(
726
+ idOrName: string,
727
+ rrName: string,
728
+ rrType: string,
729
+ params: ChangeRRSetProtectionParams,
730
+ ): Promise<ChangeRRSetProtectionResponse> {
731
+ const validatedParams = validate(changeRRSetProtectionRequestSchema, params, {
732
+ context: "Change RRSet protection request",
733
+ detailed: true,
734
+ });
735
+
736
+ const response = await this.client.post<unknown>(
737
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}/actions/change_protection`,
738
+ validatedParams,
739
+ );
740
+
741
+ return validate(changeRRSetProtectionResponseSchema, response, {
742
+ context: "Change RRSet protection response",
743
+ detailed: true,
744
+ });
745
+ }
746
+
747
+ /**
748
+ * Changes the TTL of an RRSet.
749
+ *
750
+ * @param idOrName - ID or name of the Zone
751
+ * @param rrName - Name of the RRSet
752
+ * @param rrType - Type of the RRSet
753
+ * @param params - TTL configuration
754
+ * @returns Promise resolving to the action
755
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-change-an-rrsets-ttl
756
+ *
757
+ * @example
758
+ * ```typescript
759
+ * const client = new HCloudClient({ token: 'your-token' });
760
+ *
761
+ * const result = await client.dns.changeRRSetTTL('example.com', 'www', 'A', {
762
+ * ttl: 7200
763
+ * });
764
+ * ```
765
+ */
766
+ async changeRRSetTTL(
767
+ idOrName: string,
768
+ rrName: string,
769
+ rrType: string,
770
+ params: ChangeRRSetTTLParams,
771
+ ): Promise<ChangeRRSetTTLResponse> {
772
+ const validatedParams = validate(changeRRSetTTLRequestSchema, params, {
773
+ context: "Change RRSet TTL request",
774
+ detailed: true,
775
+ });
776
+
777
+ const response = await this.client.post<unknown>(
778
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}/actions/change_ttl`,
779
+ validatedParams,
780
+ );
781
+
782
+ return validate(changeRRSetTTLResponseSchema, response, {
783
+ context: "Change RRSet TTL response",
784
+ detailed: true,
785
+ });
786
+ }
787
+
788
+ /**
789
+ * Sets all records of an RRSet.
790
+ *
791
+ * @param idOrName - ID or name of the Zone
792
+ * @param rrName - Name of the RRSet
793
+ * @param rrType - Type of the RRSet
794
+ * @param params - Records to set
795
+ * @returns Promise resolving to the action
796
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-set-records-of-an-rrset
797
+ *
798
+ * @example
799
+ * ```typescript
800
+ * const client = new HCloudClient({ token: 'your-token' });
801
+ *
802
+ * const result = await client.dns.setRRSetRecords('example.com', 'www', 'A', {
803
+ * records: [
804
+ * { value: '1.2.3.4', comment: 'Web server' }
805
+ * ],
806
+ * ttl: 3600
807
+ * });
808
+ * ```
809
+ */
810
+ async setRRSetRecords(
811
+ idOrName: string,
812
+ rrName: string,
813
+ rrType: string,
814
+ params: SetRRSetRecordsParams,
815
+ ): Promise<SetRRSetRecordsResponse> {
816
+ const validatedParams = validate(setRRSetRecordsRequestSchema, params, {
817
+ context: "Set RRSet records request",
818
+ detailed: true,
819
+ });
820
+
821
+ const response = await this.client.post<unknown>(
822
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}/actions/set_records`,
823
+ validatedParams,
824
+ );
825
+
826
+ return validate(setRRSetRecordsResponseSchema, response, {
827
+ context: "Set RRSet records response",
828
+ detailed: true,
829
+ });
830
+ }
831
+
832
+ /**
833
+ * Adds records to an RRSet.
834
+ *
835
+ * @param idOrName - ID or name of the Zone
836
+ * @param rrName - Name of the RRSet
837
+ * @param rrType - Type of the RRSet
838
+ * @param params - Records to add
839
+ * @returns Promise resolving to the action
840
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-add-records-to-an-rrset
841
+ *
842
+ * @example
843
+ * ```typescript
844
+ * const client = new HCloudClient({ token: 'your-token' });
845
+ *
846
+ * const result = await client.dns.addRRSetRecords('example.com', 'www', 'A', {
847
+ * records: [
848
+ * { value: '5.6.7.8', comment: 'Additional server' }
849
+ * ],
850
+ * ttl: 3600
851
+ * });
852
+ * ```
853
+ */
854
+ async addRRSetRecords(
855
+ idOrName: string,
856
+ rrName: string,
857
+ rrType: string,
858
+ params: AddRRSetRecordsParams,
859
+ ): Promise<AddRRSetRecordsResponse> {
860
+ const validatedParams = validate(addRRSetRecordsRequestSchema, params, {
861
+ context: "Add RRSet records request",
862
+ detailed: true,
863
+ });
864
+
865
+ const response = await this.client.post<unknown>(
866
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}/actions/add_records`,
867
+ validatedParams,
868
+ );
869
+
870
+ return validate(addRRSetRecordsResponseSchema, response, {
871
+ context: "Add RRSet records response",
872
+ detailed: true,
873
+ });
874
+ }
875
+
876
+ /**
877
+ * Removes records from an RRSet.
878
+ *
879
+ * @param idOrName - ID or name of the Zone
880
+ * @param rrName - Name of the RRSet
881
+ * @param rrType - Type of the RRSet
882
+ * @param params - Records to remove
883
+ * @returns Promise resolving to the action
884
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-remove-records-from-an-rrset
885
+ *
886
+ * @example
887
+ * ```typescript
888
+ * const client = new HCloudClient({ token: 'your-token' });
889
+ *
890
+ * const result = await client.dns.removeRRSetRecords('example.com', 'www', 'A', {
891
+ * records: [
892
+ * { value: '1.2.3.4', comment: null }
893
+ * ]
894
+ * });
895
+ * ```
896
+ */
897
+ async removeRRSetRecords(
898
+ idOrName: string,
899
+ rrName: string,
900
+ rrType: string,
901
+ params: RemoveRRSetRecordsParams,
902
+ ): Promise<RemoveRRSetRecordsResponse> {
903
+ const validatedParams = validate(removeRRSetRecordsRequestSchema, params, {
904
+ context: "Remove RRSet records request",
905
+ detailed: true,
906
+ });
907
+
908
+ const response = await this.client.post<unknown>(
909
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}/actions/remove_records`,
910
+ validatedParams,
911
+ );
912
+
913
+ return validate(removeRRSetRecordsResponseSchema, response, {
914
+ context: "Remove RRSet records response",
915
+ detailed: true,
916
+ });
917
+ }
918
+
919
+ /**
920
+ * Updates records of an RRSet.
921
+ *
922
+ * @param idOrName - ID or name of the Zone
923
+ * @param rrName - Name of the RRSet
924
+ * @param rrType - Type of the RRSet
925
+ * @param params - Records to update
926
+ * @returns Promise resolving to the action
927
+ * @see https://docs.hetzner.cloud/reference/cloud#rrsets-update-records-of-an-rrset
928
+ *
929
+ * @example
930
+ * ```typescript
931
+ * const client = new HCloudClient({ token: 'your-token' });
932
+ *
933
+ * const result = await client.dns.updateRRSetRecords('example.com', 'www', 'A', {
934
+ * records: [
935
+ * { value: '1.2.3.4', comment: 'Updated comment' }
936
+ * ]
937
+ * });
938
+ * ```
939
+ */
940
+ async updateRRSetRecords(
941
+ idOrName: string,
942
+ rrName: string,
943
+ rrType: string,
944
+ params: UpdateRRSetRecordsParams,
945
+ ): Promise<UpdateRRSetRecordsResponse> {
946
+ const validatedParams = validate(updateRRSetRecordsRequestSchema, params, {
947
+ context: "Update RRSet records request",
948
+ detailed: true,
949
+ });
950
+
951
+ const response = await this.client.post<unknown>(
952
+ `/zones/${idOrName}/rrsets/${rrName}/${rrType}/actions/update_records`,
953
+ validatedParams,
954
+ );
955
+
956
+ return validate(updateRRSetRecordsResponseSchema, response, {
957
+ context: "Update RRSet records response",
958
+ detailed: true,
959
+ });
960
+ }
961
+ }