@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,204 @@
1
+ /**
2
+ * Hetzner Cloud SSH Keys API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys
4
+ */
5
+
6
+ import type { HCloudClient } from "../../client/index";
7
+ import type {
8
+ ListSSHKeysParams,
9
+ ListSSHKeysResponse,
10
+ CreateSSHKeyParams,
11
+ CreateSSHKeyResponse,
12
+ GetSSHKeyResponse,
13
+ UpdateSSHKeyParams,
14
+ UpdateSSHKeyResponse,
15
+ DeleteSSHKeyResponse,
16
+ } from "../../apis/ssh-keys/types";
17
+ import { validate } from "../../validation/index";
18
+ import {
19
+ listSSHKeysResponseSchema,
20
+ createSSHKeyRequestSchema,
21
+ createSSHKeyResponseSchema,
22
+ getSSHKeyResponseSchema,
23
+ updateSSHKeyRequestSchema,
24
+ updateSSHKeyResponseSchema,
25
+ deleteSSHKeyResponseSchema,
26
+ } from "../../apis/ssh-keys/schemas";
27
+
28
+ /**
29
+ * SSH Keys API client
30
+ */
31
+ export class SSHKeysClient {
32
+ constructor(private readonly client: HCloudClient) {}
33
+
34
+ /**
35
+ * Returns all SSH key objects.
36
+ *
37
+ * @param params - Query parameters for filtering and pagination
38
+ * @returns Promise resolving to list of SSH keys with pagination metadata
39
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-list-ssh-keys
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const client = new HCloudClient({ token: 'your-token' });
44
+ *
45
+ * // List all SSH keys
46
+ * const result = await client.sshKeys.list();
47
+ *
48
+ * // List SSH keys with filters
49
+ * const filtered = await client.sshKeys.list({
50
+ * label_selector: 'environment=production',
51
+ * sort: ['name:asc'],
52
+ * page: 1,
53
+ * per_page: 50
54
+ * });
55
+ * ```
56
+ */
57
+ async list(params?: ListSSHKeysParams): Promise<ListSSHKeysResponse> {
58
+ const queryParams: Record<string, string | number | string[] | undefined> = {};
59
+
60
+ if (params?.name) {
61
+ queryParams.name = params.name;
62
+ }
63
+
64
+ if (params?.label_selector) {
65
+ queryParams.label_selector = params.label_selector;
66
+ }
67
+
68
+ if (params?.sort) {
69
+ queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
70
+ }
71
+
72
+ if (params?.fingerprint) {
73
+ queryParams.fingerprint = params.fingerprint;
74
+ }
75
+
76
+ if (params?.page !== undefined) {
77
+ queryParams.page = params.page;
78
+ }
79
+
80
+ if (params?.per_page !== undefined) {
81
+ queryParams.per_page = params.per_page;
82
+ }
83
+
84
+ const response = await this.client.get<unknown>("/ssh_keys", queryParams);
85
+
86
+ return validate(listSSHKeysResponseSchema, response, {
87
+ context: "List SSH keys response",
88
+ detailed: true,
89
+ });
90
+ }
91
+
92
+ /**
93
+ * Creates a new SSH key.
94
+ *
95
+ * @param params - Parameters for creating the SSH key
96
+ * @returns Promise resolving to the created SSH key
97
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-create-an-ssh-key
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const client = new HCloudClient({ token: 'your-token' });
102
+ *
103
+ * const result = await client.sshKeys.create({
104
+ * name: 'my-ssh-key',
105
+ * public_key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAB...'
106
+ * });
107
+ * ```
108
+ */
109
+ async create(params: CreateSSHKeyParams): Promise<CreateSSHKeyResponse> {
110
+ const validatedParams = validate(createSSHKeyRequestSchema, params, {
111
+ context: "Create SSH key request",
112
+ detailed: true,
113
+ });
114
+
115
+ const response = await this.client.post<unknown>("/ssh_keys", validatedParams);
116
+
117
+ return validate(createSSHKeyResponseSchema, response, {
118
+ context: "Create SSH key response",
119
+ detailed: true,
120
+ });
121
+ }
122
+
123
+ /**
124
+ * Returns a specific SSH key object.
125
+ *
126
+ * @param id - ID of the SSH key
127
+ * @returns Promise resolving to the SSH key
128
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-get-an-ssh-key
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const client = new HCloudClient({ token: 'your-token' });
133
+ *
134
+ * const sshKey = await client.sshKeys.get(12345);
135
+ * console.log(sshKey.ssh_key.name);
136
+ * ```
137
+ */
138
+ async get(id: number): Promise<GetSSHKeyResponse> {
139
+ const response = await this.client.get<unknown>(`/ssh_keys/${id}`);
140
+
141
+ return validate(getSSHKeyResponseSchema, response, {
142
+ context: "Get SSH key response",
143
+ detailed: true,
144
+ });
145
+ }
146
+
147
+ /**
148
+ * Updates an SSH key.
149
+ *
150
+ * You can update an SSH key's name and labels.
151
+ *
152
+ * @param id - ID of the SSH key
153
+ * @param params - Parameters to update (name and/or labels)
154
+ * @returns Promise resolving to the updated SSH key
155
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-update-an-ssh-key
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const client = new HCloudClient({ token: 'your-token' });
160
+ *
161
+ * const updated = await client.sshKeys.update(12345, {
162
+ * name: 'new-ssh-key-name',
163
+ * labels: { environment: 'production' }
164
+ * });
165
+ * ```
166
+ */
167
+ async update(id: number, params: UpdateSSHKeyParams): Promise<UpdateSSHKeyResponse> {
168
+ const validatedParams = validate(updateSSHKeyRequestSchema, params, {
169
+ context: "Update SSH key request",
170
+ detailed: true,
171
+ });
172
+
173
+ const response = await this.client.put<unknown>(`/ssh_keys/${id}`, validatedParams);
174
+
175
+ return validate(updateSSHKeyResponseSchema, response, {
176
+ context: "Update SSH key response",
177
+ detailed: true,
178
+ });
179
+ }
180
+
181
+ /**
182
+ * Deletes an SSH key.
183
+ *
184
+ * @param id - ID of the SSH key
185
+ * @returns Promise resolving to the delete action
186
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-delete-an-ssh-key
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const client = new HCloudClient({ token: 'your-token' });
191
+ *
192
+ * const result = await client.sshKeys.delete(12345);
193
+ * console.log(`Delete action ID: ${result.action.id}`);
194
+ * ```
195
+ */
196
+ async delete(id: number): Promise<DeleteSSHKeyResponse> {
197
+ const response = await this.client.delete<unknown>(`/ssh_keys/${id}`);
198
+
199
+ return validate(deleteSSHKeyResponseSchema, response, {
200
+ context: "Delete SSH key response",
201
+ detailed: true,
202
+ });
203
+ }
204
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Zod schemas for Hetzner Cloud SSH Keys API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys
4
+ */
5
+
6
+ import { z } from "zod";
7
+ import { actionSchema } from "../../apis/actions/schemas";
8
+ import { paginationMetaSchema } from "../../apis/common/schemas";
9
+
10
+ /**
11
+ * SSH Key schema
12
+ */
13
+ export const sshKeySchema = z
14
+ .object({
15
+ id: z.number(),
16
+ name: z.string(),
17
+ fingerprint: z.string(),
18
+ public_key: z.string(),
19
+ labels: z.record(z.string(), z.string()),
20
+ created: z.string(),
21
+ })
22
+ .passthrough();
23
+
24
+ /**
25
+ * List SSH Keys response schema
26
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-list-ssh-keys
27
+ */
28
+ export const listSSHKeysResponseSchema = z.object({
29
+ ssh_keys: z.array(sshKeySchema),
30
+ meta: z
31
+ .object({
32
+ pagination: paginationMetaSchema,
33
+ })
34
+ .optional(),
35
+ });
36
+
37
+ /**
38
+ * Create SSH Key request schema
39
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-create-an-ssh-key
40
+ */
41
+ export const createSSHKeyRequestSchema = z.object({
42
+ name: z.string().min(1),
43
+ public_key: z.string().min(1),
44
+ labels: z.record(z.string(), z.string()).optional(),
45
+ });
46
+
47
+ /**
48
+ * Create SSH Key response schema
49
+ */
50
+ export const createSSHKeyResponseSchema = z.object({
51
+ ssh_key: sshKeySchema,
52
+ });
53
+
54
+ /**
55
+ * Get SSH Key response schema
56
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-get-an-ssh-key
57
+ */
58
+ export const getSSHKeyResponseSchema = z.object({
59
+ ssh_key: sshKeySchema,
60
+ });
61
+
62
+ /**
63
+ * Update SSH Key request schema
64
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-update-an-ssh-key
65
+ */
66
+ export const updateSSHKeyRequestSchema = z.object({
67
+ name: z.string().min(1).optional(),
68
+ labels: z.record(z.string(), z.string()).optional(),
69
+ });
70
+
71
+ /**
72
+ * Update SSH Key response schema
73
+ */
74
+ export const updateSSHKeyResponseSchema = z.object({
75
+ ssh_key: sshKeySchema,
76
+ });
77
+
78
+ /**
79
+ * Delete SSH Key response schema
80
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-delete-an-ssh-key
81
+ */
82
+ export const deleteSSHKeyResponseSchema = z.object({
83
+ action: actionSchema,
84
+ });
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Types for Hetzner Cloud SSH Keys API
3
+ * Types are inferred from Zod schemas
4
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys
5
+ */
6
+
7
+ // biome-ignore assist/source/organizeImports: we need to import the schemas first
8
+ import {
9
+ listSSHKeysResponseSchema,
10
+ createSSHKeyRequestSchema,
11
+ createSSHKeyResponseSchema,
12
+ getSSHKeyResponseSchema,
13
+ updateSSHKeyRequestSchema,
14
+ updateSSHKeyResponseSchema,
15
+ deleteSSHKeyResponseSchema,
16
+ sshKeySchema,
17
+ } from "../../apis/ssh-keys/schemas";
18
+ import type { z } from "zod";
19
+
20
+ /**
21
+ * Hetzner Cloud SSH Key
22
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-list-ssh-keys
23
+ */
24
+ export type SSHKey = z.infer<typeof sshKeySchema>;
25
+
26
+ /**
27
+ * Pagination metadata
28
+ * @see https://docs.hetzner.cloud/reference/cloud#pagination
29
+ * Re-exported from servers module for consistency
30
+ */
31
+ export type { PaginationMeta } from "../../apis/servers/types";
32
+
33
+ /**
34
+ * List SSH Keys query parameters
35
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-list-ssh-keys
36
+ */
37
+ export interface ListSSHKeysParams {
38
+ /**
39
+ * Can be used to filter SSH Keys by their name. The response will only contain the SSH Key matching the specified name.
40
+ */
41
+ name?: string;
42
+ /**
43
+ * Can be used to filter SSH Keys by labels. The response will only contain SSH Keys matching the label selector.
44
+ * @see https://docs.hetzner.cloud/reference/cloud#label-selector
45
+ */
46
+ label_selector?: string;
47
+ /**
48
+ * Can be used multiple times. Choices: id, id:asc, id:desc, name, name:asc, name:desc, created, created:asc, created:desc
49
+ * @see https://docs.hetzner.cloud/reference/cloud#sorting
50
+ */
51
+ sort?: string | string[];
52
+ /**
53
+ * Can be used to filter SSH Keys by their fingerprint. The response will only contain the SSH Key matching the specified fingerprint.
54
+ */
55
+ fingerprint?: string;
56
+ /**
57
+ * Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
58
+ */
59
+ page?: number;
60
+ /**
61
+ * Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
62
+ */
63
+ per_page?: number;
64
+ }
65
+
66
+ /**
67
+ * List SSH Keys response
68
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-list-ssh-keys
69
+ */
70
+ export type ListSSHKeysResponse = z.infer<typeof listSSHKeysResponseSchema>;
71
+
72
+ /**
73
+ * Create SSH Key request parameters
74
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-create-an-ssh-key
75
+ */
76
+ export type CreateSSHKeyParams = z.infer<typeof createSSHKeyRequestSchema>;
77
+
78
+ /**
79
+ * Create SSH Key response
80
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-create-an-ssh-key
81
+ */
82
+ export type CreateSSHKeyResponse = z.infer<typeof createSSHKeyResponseSchema>;
83
+
84
+ /**
85
+ * Get SSH Key response
86
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-get-an-ssh-key
87
+ */
88
+ export type GetSSHKeyResponse = z.infer<typeof getSSHKeyResponseSchema>;
89
+
90
+ /**
91
+ * Update SSH Key request parameters
92
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-update-an-ssh-key
93
+ */
94
+ export type UpdateSSHKeyParams = z.infer<typeof updateSSHKeyRequestSchema>;
95
+
96
+ /**
97
+ * Update SSH Key response
98
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-update-an-ssh-key
99
+ */
100
+ export type UpdateSSHKeyResponse = z.infer<typeof updateSSHKeyResponseSchema>;
101
+
102
+ /**
103
+ * Delete SSH Key response
104
+ * @see https://docs.hetzner.cloud/reference/cloud#ssh-keys-delete-an-ssh-key
105
+ */
106
+ export type DeleteSSHKeyResponse = z.infer<typeof deleteSSHKeyResponseSchema>;