1.4.2 • Published 10 months ago

@modexvpn/hcloud v1.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@modexvpn/hcloud

A clean, type-safe SDK for the Hetzner Cloud API using Node.js, TypeScript, and Zod.

Features

  • šŸ” Zod-powered runtime validation — fully JavaScript-safe
  • 🧠 Fully type-safe using TypeScript with z.infer<> and enums
  • šŸ“† Modular structure: hcloud.servers.list(), hcloud.locations.getById()
  • āš ļø Centralized error handling with formatHcloudError()
  • āš™ļø Axios-based HTTP client with auto-authentication
  • šŸ” ESM and CommonJS compatible
  • šŸ—‚ļø Clean folder structure for scalability and maintainability

SDK Status

This SDK is stable, but not yet feature-complete.
We're already on v1.x and will maintain backward compatibility.
Any breaking changes will be released as v2.0.0.


šŸš€ What's New in v1.4

  • createSSHKey(options) — Create a new SSH key
  • getSSHKeys() — List all SSH keys
  • getSSHKey(id) — Get a single SSH key by ID
  • updateSSHKey(id, options) — Update an existing SSH key
  • deleteSSHKey(id) — Delete an SSH key

āœļø Usage Examples

Create SSH Key

const sshKey = await hcloud.security.createSSHKey({
  name: "modex-prod-key",
  public_key: "ssh-ed25519 AAAAC3N...",
  labels: { environment: "prod" }
})

List SSH Keys

const allKeys = await hcloud.security.listSSHKeys()

Get SSH Key by ID

const key = await hcloud.security.getSSHKey(12345)

Update SSH Key

const updated = await hcloud.security.updateSSHKey(12345, {
  name: "modex-updated-key",
  labels: { updated: "true" }
})

Delete SSH Key

await hcloud.security.deleteSSHKey(12345)

šŸ“† Installation

npm install @modexvpn/hcloud

🧠 Usage

List all servers

import { hcloud } from '@modexvpn/hcloud'

const servers = await hcloud.servers.list()

Get a single server by ID

const server = await hcloud.servers.getById(123456)

Fetch server metrics

const metrics = await hcloud.servers.getMetrics(123456)

Power control

await hcloud.servers.powerControl.off(123456)
await hcloud.servers.powerControl.reboot(123456)
await hcloud.servers.powerControl.on(123456)
await hcloud.servers.powerControl.reset(123456)
await hcloud.servers.powerControl.shutdown(123456)

Create a server

await hcloud.servers.create({
  name: 'test-server',
  server_type: 'cx21',
  image: 'ubuntu-22.04',
  location: 'nbg1',
  ssh_keys: ['ssh-key-id'],
})

Delete a server

await hcloud.servers.delete(123456)

SSH Into Server

const { stdout } = await sshIntoServer("192.168.1.100", "apt update && apt upgrade -y", "root")
console.log(stdout)

šŸ’” Requires SSH_PRIVATE_KEY in your environment


šŸ”¢ Environment Setup

Create a .env file and add your Hetzner API token:

HCLOUD_API_TOKEN=your-token-here

šŸ“ Project Structure

@modexvpn/hcloud
ā”œā”€ā”€ client.ts
ā”œā”€ā”€ index.ts
ā”œā”€ā”€ sdk/
│   ā”œā”€ā”€ servers/
│   │   ā”œā”€ā”€ actions/
│   │   │   └── sshIntoServer.ts
│   │   ā”œā”€ā”€ createServer.ts
│   │   └── server-type/
│   │       ā”œā”€ā”€ getServerTypes.ts
│   │       ā”œā”€ā”€ getServerType.ts
│   │       └── index.ts
│   └── locations/
│       └── datacenters/
│           ā”œā”€ā”€ getDatacenters.ts
│           └── getDatacenter.ts
ā”œā”€ā”€ types/
│   ā”œā”€ā”€ common/
│   ā”œā”€ā”€ enums/
│   ā”œā”€ā”€ errors/
│   ā”œā”€ā”€ ...
ā”œā”€ā”€ utils/
│   └── formatError.ts
ā”œā”€ā”€ tsconfig.json
ā”œā”€ā”€ tsup.config.ts
ā”œā”€ā”€ README.md

šŸ”« API Coverage

Core Resources

Security

Storage & Networking

Firewalls & IPs

Load Balancers

Billing


šŸ“ Contributing

PRs welcome! Please follow the existing structure and run:

npm run lint
npm run build

šŸ“„ Resources

šŸ‘‰ License

MIT Ā© 2025 MODEX

1.4.2

10 months ago

1.4.1

10 months ago

1.4.0

10 months ago

1.3.0

10 months ago

1.2.0

10 months ago

1.1.1

10 months ago

1.1.0

10 months ago

1.0.0

10 months ago