@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
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # @nilovonjs/hcloud-js
2
+
3
+ TypeScript SDK for the Hetzner Cloud API - Fully typed, validated, and easy to use.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @nilovonjs/hcloud-js
9
+ # or
10
+ yarn add @nilovonjs/hcloud-js
11
+ # or
12
+ pnpm add @nilovonjs/hcloud-js
13
+ # or
14
+ bun add @nilovonjs/hcloud-js
15
+ ```
16
+
17
+ ## Quick Start
18
+
19
+ ```typescript
20
+ import { HCloudClient } from '@nilovonjs/hcloud-js';
21
+
22
+ const client = new HCloudClient({
23
+ token: 'your-api-token'
24
+ });
25
+
26
+ // List all servers
27
+ const servers = await client.servers.list();
28
+ console.log(`Found ${servers.servers.length} server(s)`);
29
+
30
+ // Get a specific server
31
+ const server = await client.servers.get(12345);
32
+ console.log(server.server.name);
33
+
34
+ // Create a new server
35
+ const newServer = await client.servers.create({
36
+ name: 'my-server',
37
+ server_type: 'cpx11',
38
+ image: 'ubuntu-22.04',
39
+ location: 'nbg1'
40
+ });
41
+ ```
42
+
43
+ ## Features
44
+
45
+ - ✅ **Fully Typed** - Complete TypeScript types for all API endpoints
46
+ - ✅ **Validated** - Built-in validation using Zod schemas
47
+ - ✅ **Easy to Use** - Simple, intuitive API
48
+ - ✅ **Complete Coverage** - All Hetzner Cloud API endpoints supported
49
+ - ✅ **Well Documented** - Comprehensive documentation with examples
50
+
51
+ ## Supported APIs
52
+
53
+ - Servers
54
+ - Images
55
+ - Actions
56
+ - Certificates
57
+ - SSH Keys
58
+ - Locations
59
+ - Firewalls
60
+ - Floating IPs
61
+ - ISOs
62
+ - Placement Groups
63
+ - Primary IPs
64
+ - Server Types
65
+ - Load Balancers
66
+ - Networks
67
+ - Pricing
68
+ - Volumes
69
+ - DNS (Zones)
70
+
71
+ ## Documentation
72
+
73
+ Full documentation is available at: [https://hcloud-js.nilovon.com](https://hcloud-js.nilovon.com)
74
+
75
+ ## Requirements
76
+
77
+ - Node.js >= 18.0.0
78
+ - TypeScript >= 5.0.0
79
+
80
+ ## Contributing
81
+
82
+ Contributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for details.
83
+
84
+ ## Changelog
85
+
86
+ See [CHANGELOG.md](./CHANGELOG.md) for a list of changes.
87
+
88
+ ## License
89
+
90
+ MIT © [Nilovon](https://github.com/Nilovon)
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@nilovonjs/hcloud-js",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript SDK for the Hetzner Cloud API - Fully typed, validated, and easy to use",
5
+ "author": "Nilovon",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./src/index.ts",
9
+ "types": "./src/index.ts",
10
+ "module": "./src/index.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./src/index.ts",
14
+ "import": "./src/index.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "src",
19
+ "README.md",
20
+ "LICENSE",
21
+ "CHANGELOG.md"
22
+ ],
23
+ "keywords": [
24
+ "hetzner",
25
+ "hetzner-cloud",
26
+ "hcloud",
27
+ "cloud",
28
+ "api",
29
+ "sdk",
30
+ "typescript",
31
+ "types",
32
+ "servers",
33
+ "networks",
34
+ "load-balancer",
35
+ "dns",
36
+ "infrastructure"
37
+ ],
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/Nilovon/hcloud-js.git"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/Nilovon/hcloud-js/issues"
44
+ },
45
+ "homepage": "https://hcloud-js.nilovon.com",
46
+ "engines": {
47
+ "node": ">=18.0.0"
48
+ },
49
+ "dependencies": {
50
+ "zod": "^3.23.8"
51
+ },
52
+ "devDependencies": {
53
+ "@types/bun": "latest"
54
+ },
55
+ "peerDependencies": {
56
+ "typescript": "^5.0.0"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "typescript": {
60
+ "optional": false
61
+ }
62
+ },
63
+ "publishConfig": {
64
+ "access": "public",
65
+ "registry": "https://registry.npmjs.org/"
66
+ },
67
+ "scripts": {
68
+ "prepublishOnly": "echo 'Running prepublish checks...' && exit 0"
69
+ }
70
+ }
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Hetzner Cloud Actions API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#actions
4
+ */
5
+
6
+ import type { HCloudClient } from "../../client/index";
7
+ import type {
8
+ ListActionsParams,
9
+ ListActionsResponse,
10
+ GetActionResponse,
11
+ } from "../../apis/actions/types";
12
+ import { validate } from "../../validation/index";
13
+ import {
14
+ listActionsResponseSchema,
15
+ getActionResponseSchema,
16
+ } from "../../apis/actions/schemas";
17
+
18
+ /**
19
+ * Actions API client
20
+ */
21
+ export class ActionsClient {
22
+ constructor(private readonly client: HCloudClient) {}
23
+
24
+ /**
25
+ * Returns all Action objects.
26
+ *
27
+ * ⚠️ **Note:** As of 2025-01-30, the Hetzner Cloud API removed the ability to list arbitrary actions.
28
+ * This endpoint may return a 410 error. Actions should be retrieved individually by ID
29
+ * (typically obtained from resource operations).
30
+ *
31
+ * @param params - Query parameters for filtering and pagination
32
+ * @returns Promise resolving to list of actions with pagination metadata
33
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-multiple-actions
34
+ * @see https://docs.hetzner.cloud/changelog#2025-01-30-listing-arbitrary-actions-in-the-actions-list-endpoint-is-removed
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const client = new HCloudClient({ token: 'your-token' });
39
+ *
40
+ * // Note: This may fail with 410 error
41
+ * // Use client.actions.get(id) instead with an action ID from a resource operation
42
+ * try {
43
+ * const result = await client.actions.list();
44
+ * } catch (error) {
45
+ * // Handle 410 error (deprecated endpoint)
46
+ * }
47
+ * ```
48
+ * @deprecated This endpoint may be deprecated. Use {@link ActionsClient.get} with an action ID instead.
49
+ */
50
+ async list(params?: ListActionsParams): Promise<ListActionsResponse> {
51
+ // Build query parameters
52
+ const queryParams: Record<string, string | number | string[] | undefined> = {};
53
+
54
+ if (params?.id !== undefined) {
55
+ // Convert id(s) to array of strings for query params
56
+ const ids = Array.isArray(params.id) ? params.id : [params.id];
57
+ queryParams.id = ids.map(String);
58
+ }
59
+
60
+ if (params?.status) {
61
+ // Convert single status to array for consistent handling
62
+ queryParams.status = Array.isArray(params.status) ? params.status : [params.status];
63
+ }
64
+
65
+ if (params?.sort) {
66
+ // Convert single string to array for consistent handling
67
+ queryParams.sort = Array.isArray(params.sort) ? params.sort : [params.sort];
68
+ }
69
+
70
+ if (params?.page !== undefined) {
71
+ queryParams.page = params.page;
72
+ }
73
+
74
+ if (params?.per_page !== undefined) {
75
+ queryParams.per_page = params.per_page;
76
+ }
77
+
78
+ const response = await this.client.get<unknown>("/actions", queryParams);
79
+
80
+ // Validate response with Zod
81
+ return validate(listActionsResponseSchema, response, {
82
+ context: "List actions response",
83
+ detailed: true,
84
+ });
85
+ }
86
+
87
+ /**
88
+ * Returns a specific Action object.
89
+ *
90
+ * @param id - ID of the Action
91
+ * @returns Promise resolving to the action
92
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-an-action
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const client = new HCloudClient({ token: 'your-token' });
97
+ *
98
+ * // Get an action by ID
99
+ * const action = await client.actions.get(12345);
100
+ * console.log(action.action.command);
101
+ * console.log(action.action.status);
102
+ * ```
103
+ */
104
+ async get(id: number): Promise<GetActionResponse> {
105
+ const response = await this.client.get<unknown>(`/actions/${id}`);
106
+
107
+ // Validate response with Zod
108
+ return validate(getActionResponseSchema, response, {
109
+ context: "Get action response",
110
+ detailed: true,
111
+ });
112
+ }
113
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Zod schemas for Hetzner Cloud Actions API
3
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-multiple-actions
4
+ */
5
+
6
+ import { z } from "zod";
7
+ import { paginationMetaSchema } from "../common/schemas";
8
+
9
+ /**
10
+ * Action resource schema
11
+ * Common schema for action resources
12
+ */
13
+ export const actionResourceSchema = z.object({
14
+ id: z.number(),
15
+ type: z.string(),
16
+ });
17
+
18
+ /**
19
+ * Action schema
20
+ * Common schema for all Hetzner Cloud Actions
21
+ */
22
+ export const actionSchema = z
23
+ .object({
24
+ id: z.number(),
25
+ command: z.string(),
26
+ status: z.enum(["running", "success", "error"]),
27
+ progress: z.number(),
28
+ started: z.string(),
29
+ finished: z.string().nullable(),
30
+ resources: z.array(actionResourceSchema),
31
+ error: z
32
+ .object({
33
+ code: z.string(),
34
+ message: z.string(),
35
+ })
36
+ .nullable(),
37
+ })
38
+ .passthrough();
39
+
40
+ /**
41
+ * List Actions response schema
42
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-multiple-actions
43
+ */
44
+ export const listActionsResponseSchema = z.object({
45
+ actions: z.array(actionSchema),
46
+ meta: z
47
+ .object({
48
+ pagination: paginationMetaSchema,
49
+ })
50
+ .optional(),
51
+ });
52
+
53
+ /**
54
+ * Get Action response schema
55
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-an-action
56
+ */
57
+ export const getActionResponseSchema = z.object({
58
+ action: actionSchema,
59
+ });
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Types for Hetzner Cloud Actions API
3
+ * Types are inferred from Zod schemas
4
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-multiple-actions
5
+ */
6
+
7
+ // biome-ignore assist/source/organizeImports: we need to import the schemas first
8
+ import {
9
+ listActionsResponseSchema,
10
+ getActionResponseSchema,
11
+ } from "../../apis/actions/schemas";
12
+ import { actionSchema, actionResourceSchema } from "../../apis/actions/schemas";
13
+ import type { z } from "zod";
14
+
15
+ /**
16
+ * Action resource information
17
+ */
18
+ export type ActionResource = z.infer<typeof actionResourceSchema>;
19
+
20
+ /**
21
+ * Hetzner Cloud Action
22
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-multiple-actions
23
+ */
24
+ export type Action = z.infer<typeof actionSchema>;
25
+
26
+ /**
27
+ * Action status values
28
+ */
29
+ export type ActionStatus = "running" | "success" | "error";
30
+
31
+ /**
32
+ * Pagination metadata
33
+ * @see https://docs.hetzner.cloud/reference/cloud#pagination
34
+ * Re-exported from servers module for consistency
35
+ */
36
+ export type { PaginationMeta } from "../../apis/servers/types";
37
+
38
+ /**
39
+ * List Actions query parameters
40
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-multiple-actions
41
+ */
42
+ export interface ListActionsParams {
43
+ /**
44
+ * Can be used multiple times. The response will only contain Actions matching the specified IDs.
45
+ */
46
+ id?: number | number[];
47
+ /**
48
+ * Can be used multiple times. The response will only contain Actions matching the specified status.
49
+ * Choices: running, success, error
50
+ */
51
+ status?: ActionStatus | ActionStatus[];
52
+ /**
53
+ * 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
54
+ * @see https://docs.hetzner.cloud/reference/cloud#sorting
55
+ */
56
+ sort?: string | string[];
57
+ /**
58
+ * Page number to return. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
59
+ */
60
+ page?: number;
61
+ /**
62
+ * Maximum number of entries returned per page. For more information, see [Pagination](https://docs.hetzner.cloud/reference/cloud#pagination).
63
+ */
64
+ per_page?: number;
65
+ }
66
+
67
+ /**
68
+ * List Actions response
69
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-multiple-actions
70
+ */
71
+ export type ListActionsResponse = z.infer<typeof listActionsResponseSchema>;
72
+
73
+ /**
74
+ * Get Action response
75
+ * @see https://docs.hetzner.cloud/reference/cloud#actions-get-an-action
76
+ */
77
+ export type GetActionResponse = z.infer<typeof getActionResponseSchema>;