@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,221 @@
1
+ /**
2
+ * Types for Hetzner Cloud Primary IPs API
3
+ * Types are inferred from Zod schemas
4
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips
5
+ */
6
+
7
+ // biome-ignore assist/source/organizeImports: we need to import the schemas first
8
+ import {
9
+ listPrimaryIPsResponseSchema,
10
+ createPrimaryIPRequestSchema,
11
+ createPrimaryIPResponseSchema,
12
+ getPrimaryIPResponseSchema,
13
+ updatePrimaryIPRequestSchema,
14
+ updatePrimaryIPResponseSchema,
15
+ deletePrimaryIPResponseSchema,
16
+ listPrimaryIPActionsResponseSchema,
17
+ getPrimaryIPActionResponseSchema,
18
+ assignPrimaryIPToResourceRequestSchema,
19
+ assignPrimaryIPToResourceResponseSchema,
20
+ changePrimaryIPReverseDNSRequestSchema,
21
+ changePrimaryIPReverseDNSResponseSchema,
22
+ changePrimaryIPProtectionRequestSchema,
23
+ changePrimaryIPProtectionResponseSchema,
24
+ unassignPrimaryIPRequestSchema,
25
+ unassignPrimaryIPResponseSchema,
26
+ primaryIpSchema,
27
+ primaryIpTypeSchema,
28
+ primaryIpDnsPointerSchema,
29
+ primaryIpProtectionSchema,
30
+ primaryIpAssigneeTypeSchema,
31
+ } from "../../apis/primary-ips/schemas";
32
+ import type { z } from "zod";
33
+
34
+ /**
35
+ * Primary IP type
36
+ */
37
+ export type PrimaryIPType = z.infer<typeof primaryIpTypeSchema>;
38
+
39
+ /**
40
+ * Primary IP DNS pointer
41
+ */
42
+ export type PrimaryIPDnsPointer = z.infer<typeof primaryIpDnsPointerSchema>;
43
+
44
+ /**
45
+ * Primary IP protection
46
+ */
47
+ export type PrimaryIPProtection = z.infer<typeof primaryIpProtectionSchema>;
48
+
49
+ /**
50
+ * Primary IP assignee type
51
+ */
52
+ export type PrimaryIPAssigneeType = z.infer<typeof primaryIpAssigneeTypeSchema>;
53
+
54
+ /**
55
+ * Primary IP
56
+ */
57
+ export type PrimaryIP = z.infer<typeof primaryIpSchema>;
58
+
59
+ /**
60
+ * List Primary IPs query parameters
61
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-list-primary-ips
62
+ */
63
+ export interface ListPrimaryIPsParams {
64
+ /**
65
+ * Can be used to filter Primary IPs by their name. The response will only contain the Primary IP matching the specified name.
66
+ */
67
+ name?: string;
68
+ /**
69
+ * Can be used multiple times. Choices: id, id:asc, id:desc, name, name:asc, name:desc, created, created:asc, created:desc
70
+ * @see https://docs.hetzner.cloud/reference/cloud#sorting
71
+ */
72
+ sort?: string | string[];
73
+ /**
74
+ * Can be used to filter Primary IPs by labels. The response will only contain Primary IPs matching the label selector.
75
+ */
76
+ label_selector?: string;
77
+ /**
78
+ * Can be used to filter Primary IPs by their IP. The response will only contain the Primary IP matching the specified IP.
79
+ */
80
+ ip?: string;
81
+ /**
82
+ * Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
83
+ */
84
+ page?: number;
85
+ /**
86
+ * Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
87
+ */
88
+ per_page?: number;
89
+ }
90
+
91
+ /**
92
+ * List Primary IPs response
93
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-list-primary-ips
94
+ */
95
+ export type ListPrimaryIPsResponse = z.infer<typeof listPrimaryIPsResponseSchema>;
96
+
97
+ /**
98
+ * Create Primary IP parameters
99
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-create-a-primary-ip
100
+ */
101
+ export type CreatePrimaryIPParams = z.infer<typeof createPrimaryIPRequestSchema>;
102
+
103
+ /**
104
+ * Create Primary IP response
105
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-create-a-primary-ip
106
+ */
107
+ export type CreatePrimaryIPResponse = z.infer<typeof createPrimaryIPResponseSchema>;
108
+
109
+ /**
110
+ * Get Primary IP response
111
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-get-a-primary-ip
112
+ */
113
+ export type GetPrimaryIPResponse = z.infer<typeof getPrimaryIPResponseSchema>;
114
+
115
+ /**
116
+ * Update Primary IP parameters
117
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-update-a-primary-ip
118
+ */
119
+ export type UpdatePrimaryIPParams = z.infer<typeof updatePrimaryIPRequestSchema>;
120
+
121
+ /**
122
+ * Update Primary IP response
123
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-update-a-primary-ip
124
+ */
125
+ export type UpdatePrimaryIPResponse = z.infer<typeof updatePrimaryIPResponseSchema>;
126
+
127
+ /**
128
+ * Delete Primary IP response
129
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-delete-a-primary-ip
130
+ */
131
+ export type DeletePrimaryIPResponse = z.infer<typeof deletePrimaryIPResponseSchema>;
132
+
133
+ /**
134
+ * List Primary IP Actions query parameters
135
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-list-actions-for-a-primary-ip
136
+ */
137
+ export interface ListPrimaryIPActionsParams {
138
+ /**
139
+ * Can be used multiple times. Choices: id, id:asc, id:desc, command, command:asc, command:desc, status, status:asc, status:desc, progress, progress:asc, progress:desc, started, started:asc, started:desc, finished, finished:asc, finished:desc
140
+ * @see https://docs.hetzner.cloud/reference/cloud#sorting
141
+ */
142
+ sort?: string | string[];
143
+ /**
144
+ * Can be used to filter Actions by status. The response will only contain Actions matching the status.
145
+ */
146
+ status?: string | string[];
147
+ /**
148
+ * Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
149
+ */
150
+ page?: number;
151
+ /**
152
+ * Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
153
+ */
154
+ per_page?: number;
155
+ }
156
+
157
+ /**
158
+ * List Primary IP Actions response
159
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-list-actions-for-a-primary-ip
160
+ */
161
+ export type ListPrimaryIPActionsResponse = z.infer<typeof listPrimaryIPActionsResponseSchema>;
162
+
163
+ /**
164
+ * Get Primary IP Action response
165
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-get-an-action-for-a-primary-ip
166
+ */
167
+ export type GetPrimaryIPActionResponse = z.infer<typeof getPrimaryIPActionResponseSchema>;
168
+
169
+ /**
170
+ * Assign Primary IP to resource parameters
171
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-assign-a-primary-ip-to-a-resource
172
+ */
173
+ export type AssignPrimaryIPToResourceParams = z.infer<
174
+ typeof assignPrimaryIPToResourceRequestSchema
175
+ >;
176
+
177
+ /**
178
+ * Assign Primary IP to resource response
179
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-assign-a-primary-ip-to-a-resource
180
+ */
181
+ export type AssignPrimaryIPToResourceResponse = z.infer<
182
+ typeof assignPrimaryIPToResourceResponseSchema
183
+ >;
184
+
185
+ /**
186
+ * Change Primary IP reverse DNS parameters
187
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-reverse-dns-records-for-a-primary-ip
188
+ */
189
+ export type ChangePrimaryIPReverseDNSParams = z.infer<
190
+ typeof changePrimaryIPReverseDNSRequestSchema
191
+ >;
192
+
193
+ /**
194
+ * Change Primary IP reverse DNS response
195
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-reverse-dns-records-for-a-primary-ip
196
+ */
197
+ export type ChangePrimaryIPReverseDNSResponse = z.infer<
198
+ typeof changePrimaryIPReverseDNSResponseSchema
199
+ >;
200
+
201
+ /**
202
+ * Change Primary IP Protection parameters
203
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-primary-ip-protection
204
+ */
205
+ export type ChangePrimaryIPProtectionParams = z.infer<
206
+ typeof changePrimaryIPProtectionRequestSchema
207
+ >;
208
+
209
+ /**
210
+ * Change Primary IP Protection response
211
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-change-primary-ip-protection
212
+ */
213
+ export type ChangePrimaryIPProtectionResponse = z.infer<
214
+ typeof changePrimaryIPProtectionResponseSchema
215
+ >;
216
+
217
+ /**
218
+ * Unassign Primary IP response
219
+ * @see https://docs.hetzner.cloud/reference/cloud#primary-ips-unassign-a-primary-ip-from-a-resource
220
+ */
221
+ export type UnassignPrimaryIPResponse = z.infer<typeof unassignPrimaryIPResponseSchema>;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Hetzner Cloud Server Types API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types
4
+ */
5
+
6
+ import type { HCloudClient } from "../../client/index";
7
+ import type {
8
+ ListServerTypesParams,
9
+ ListServerTypesResponse,
10
+ GetServerTypeResponse,
11
+ } from "../../apis/server-types/types";
12
+ import { validate } from "../../validation/index";
13
+ import {
14
+ listServerTypesResponseSchema,
15
+ getServerTypeResponseSchema,
16
+ } from "../../apis/server-types/schemas";
17
+
18
+ /**
19
+ * Server Types API client
20
+ */
21
+ export class ServerTypesClient {
22
+ constructor(private readonly client: HCloudClient) {}
23
+
24
+ /**
25
+ * Returns all Server Type objects.
26
+ *
27
+ * @param params - Query parameters for filtering and pagination
28
+ * @returns Promise resolving to list of server types with pagination metadata
29
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types-list-server-types
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const client = new HCloudClient({ token: 'your-token' });
34
+ *
35
+ * // List all server types
36
+ * const result = await client.serverTypes.list();
37
+ *
38
+ * // List server types with filters
39
+ * const serverTypes = await client.serverTypes.list({
40
+ * name: 'cpx11',
41
+ * page: 1,
42
+ * per_page: 50
43
+ * });
44
+ * ```
45
+ */
46
+ async list(params?: ListServerTypesParams): Promise<ListServerTypesResponse> {
47
+ const queryParams: Record<string, string | number | string[] | undefined> = {};
48
+
49
+ if (params?.name) {
50
+ queryParams.name = params.name;
51
+ }
52
+
53
+ if (params?.page !== undefined) {
54
+ queryParams.page = params.page;
55
+ }
56
+
57
+ if (params?.per_page !== undefined) {
58
+ queryParams.per_page = params.per_page;
59
+ }
60
+
61
+ const response = await this.client.get<unknown>("/server_types", queryParams);
62
+
63
+ return validate(listServerTypesResponseSchema, response, {
64
+ context: "List server types response",
65
+ detailed: true,
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Returns a specific Server Type object.
71
+ *
72
+ * @param id - ID or name of the Server Type
73
+ * @returns Promise resolving to the server type
74
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types-get-a-server-type
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const client = new HCloudClient({ token: 'your-token' });
79
+ *
80
+ * // Get a server type by ID or name
81
+ * const serverType = await client.serverTypes.get('cpx11');
82
+ * console.log(serverType.server_type.name);
83
+ * ```
84
+ */
85
+ async get(id: string | number): Promise<GetServerTypeResponse> {
86
+ const response = await this.client.get<unknown>(`/server_types/${id}`);
87
+
88
+ return validate(getServerTypeResponseSchema, response, {
89
+ context: "Get server type response",
90
+ detailed: true,
91
+ });
92
+ }
93
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Zod schemas for Hetzner Cloud Server Types API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types
4
+ */
5
+
6
+ import { z } from "zod";
7
+ import { paginationMetaSchema } from "../../apis/common/schemas";
8
+ import { serverTypeSchema } from "../../apis/servers/schemas";
9
+
10
+ /**
11
+ * List Server Types response schema
12
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types-list-server-types
13
+ */
14
+ export const listServerTypesResponseSchema = z.object({
15
+ server_types: z.array(serverTypeSchema),
16
+ meta: z
17
+ .object({
18
+ pagination: paginationMetaSchema,
19
+ })
20
+ .optional(),
21
+ });
22
+
23
+ /**
24
+ * Get Server Type response schema
25
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types-get-a-server-type
26
+ */
27
+ export const getServerTypeResponseSchema = z.object({
28
+ server_type: serverTypeSchema,
29
+ });
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Types for Hetzner Cloud Server Types API
3
+ * Types are inferred from Zod schemas
4
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types
5
+ */
6
+
7
+ // biome-ignore assist/source/organizeImports: we need to import the schemas first
8
+ import {
9
+ listServerTypesResponseSchema,
10
+ getServerTypeResponseSchema,
11
+ } from "../../apis/server-types/schemas";
12
+ import type { z } from "zod";
13
+
14
+ /**
15
+ * List Server Types query parameters
16
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types-list-server-types
17
+ */
18
+ export interface ListServerTypesParams {
19
+ /**
20
+ * Can be used to filter Server Types by their name. The response will only contain the Server Type matching the specified name.
21
+ */
22
+ name?: string;
23
+ /**
24
+ * Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
25
+ */
26
+ page?: number;
27
+ /**
28
+ * Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
29
+ */
30
+ per_page?: number;
31
+ }
32
+
33
+ /**
34
+ * List Server Types response
35
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types-list-server-types
36
+ */
37
+ export type ListServerTypesResponse = z.infer<typeof listServerTypesResponseSchema>;
38
+
39
+ /**
40
+ * Get Server Type response
41
+ * @see https://docs.hetzner.cloud/reference/cloud#server-types-get-a-server-type
42
+ */
43
+ export type GetServerTypeResponse = z.infer<typeof getServerTypeResponseSchema>;