fix(core): update
This commit is contained in:
		@@ -5,10 +5,23 @@
 | 
				
			|||||||
      "githost": "gitlab.com",
 | 
					      "githost": "gitlab.com",
 | 
				
			||||||
      "gitscope": "apiclient.xyz",
 | 
					      "gitscope": "apiclient.xyz",
 | 
				
			||||||
      "gitrepo": "hetznercloud",
 | 
					      "gitrepo": "hetznercloud",
 | 
				
			||||||
      "description": "an unofficial api client for the hetzner cloud api",
 | 
					      "description": "An unofficial TypeScript API client for the Hetzner Cloud API providing easy methods to manage servers, volumes, and firewalls.",
 | 
				
			||||||
      "npmPackagename": "@apiclient.xyz/hetznercloud",
 | 
					      "npmPackagename": "@apiclient.xyz/hetznercloud",
 | 
				
			||||||
      "license": "MIT",
 | 
					      "license": "MIT",
 | 
				
			||||||
      "projectDomain": "apiclient.xyz"
 | 
					      "projectDomain": "apiclient.xyz",
 | 
				
			||||||
 | 
					      "keywords": [
 | 
				
			||||||
 | 
					        "Hetzner",
 | 
				
			||||||
 | 
					        "Cloud",
 | 
				
			||||||
 | 
					        "API",
 | 
				
			||||||
 | 
					        "TypeScript",
 | 
				
			||||||
 | 
					        "Client",
 | 
				
			||||||
 | 
					        "Servers",
 | 
				
			||||||
 | 
					        "Volumes",
 | 
				
			||||||
 | 
					        "Firewalls",
 | 
				
			||||||
 | 
					        "Automation",
 | 
				
			||||||
 | 
					        "DevOps",
 | 
				
			||||||
 | 
					        "Cloud Infrastructure"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "npmci": {
 | 
					  "npmci": {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								package.json
									
									
									
									
									
								
							@@ -2,7 +2,7 @@
 | 
				
			|||||||
  "name": "@apiclient.xyz/hetznercloud",
 | 
					  "name": "@apiclient.xyz/hetznercloud",
 | 
				
			||||||
  "version": "1.1.0",
 | 
					  "version": "1.1.0",
 | 
				
			||||||
  "private": false,
 | 
					  "private": false,
 | 
				
			||||||
  "description": "an unofficial api client for the hetzner cloud api",
 | 
					  "description": "An unofficial TypeScript API client for the Hetzner Cloud API providing easy methods to manage servers, volumes, and firewalls.",
 | 
				
			||||||
  "main": "dist_ts/index.js",
 | 
					  "main": "dist_ts/index.js",
 | 
				
			||||||
  "typings": "dist_ts/index.d.ts",
 | 
					  "typings": "dist_ts/index.d.ts",
 | 
				
			||||||
  "type": "module",
 | 
					  "type": "module",
 | 
				
			||||||
@@ -12,7 +12,7 @@
 | 
				
			|||||||
    "test": "(tstest test/ --web)",
 | 
					    "test": "(tstest test/ --web)",
 | 
				
			||||||
    "build": "(tsbuild --web --allowimplicitany)",
 | 
					    "build": "(tsbuild --web --allowimplicitany)",
 | 
				
			||||||
    "buildDocs": "(tsdoc)",
 | 
					    "buildDocs": "(tsdoc)",
 | 
				
			||||||
    "create": "openapi-generator-cli generate -i https://docs.hetzner.cloud/spec.json -g typescript-node -o ts_openapi"
 | 
					    "updateAPI": "openapi-typescript https://docs.hetzner.cloud/spec.json --output ts/api.ts && tsc"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@git.zone/tsbuild": "^2.1.25",
 | 
					    "@git.zone/tsbuild": "^2.1.25",
 | 
				
			||||||
@@ -21,11 +21,11 @@
 | 
				
			|||||||
    "@git.zone/tstest": "^1.0.44",
 | 
					    "@git.zone/tstest": "^1.0.44",
 | 
				
			||||||
    "@push.rocks/qenv": "^6.0.5",
 | 
					    "@push.rocks/qenv": "^6.0.5",
 | 
				
			||||||
    "@push.rocks/tapbundle": "^5.0.15",
 | 
					    "@push.rocks/tapbundle": "^5.0.15",
 | 
				
			||||||
    "@types/node": "^20.11.22"
 | 
					    "@types/node": "^20.11.22",
 | 
				
			||||||
 | 
					    "openapi-typescript": "^6.7.6"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
    "@push.rocks/smartrequest": "^2.0.21",
 | 
					    "@push.rocks/smartrequest": "^2.0.21",
 | 
				
			||||||
    "@tempfix/hetzner-openapi": "^1.0.4",
 | 
					 | 
				
			||||||
    "@tsclass/tsclass": "^4.0.52"
 | 
					    "@tsclass/tsclass": "^4.0.52"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "repository": {
 | 
					  "repository": {
 | 
				
			||||||
@@ -50,5 +50,18 @@
 | 
				
			|||||||
    "cli.js",
 | 
					    "cli.js",
 | 
				
			||||||
    "npmextra.json",
 | 
					    "npmextra.json",
 | 
				
			||||||
    "readme.md"
 | 
					    "readme.md"
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "keywords": [
 | 
				
			||||||
 | 
					    "Hetzner",
 | 
				
			||||||
 | 
					    "Cloud",
 | 
				
			||||||
 | 
					    "API",
 | 
				
			||||||
 | 
					    "TypeScript",
 | 
				
			||||||
 | 
					    "Client",
 | 
				
			||||||
 | 
					    "Servers",
 | 
				
			||||||
 | 
					    "Volumes",
 | 
				
			||||||
 | 
					    "Firewalls",
 | 
				
			||||||
 | 
					    "Automation",
 | 
				
			||||||
 | 
					    "DevOps",
 | 
				
			||||||
 | 
					    "Cloud Infrastructure"
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										6683
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6683
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										0
									
								
								readme.hints.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								readme.hints.md
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										283
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										283
									
								
								readme.md
									
									
									
									
									
								
							@@ -1,40 +1,267 @@
 | 
				
			|||||||
# @apiclient.xyz/hetznercloud
 | 
					# @apiclient.xyz/hetznercloud
 | 
				
			||||||
an unofficial api client for the hetzner cloud api
 | 
					An unofficial API client for the Hetzner Cloud API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Availabililty and Links
 | 
					## Install
 | 
				
			||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@apiclient.xyz/hetznercloud)
 | 
					 | 
				
			||||||
* [gitlab.com (source)](https://gitlab.com/apiclient.xyz/hetznercloud)
 | 
					 | 
				
			||||||
* [github.com (source mirror)](https://github.com/apiclient.xyz/hetznercloud)
 | 
					 | 
				
			||||||
* [docs (typedoc)](https://apiclient.xyz.gitlab.io/hetznercloud/)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Status for master
 | 
					You can install the `@apiclient.xyz/hetznercloud` package via npm:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Status Category | Status Badge
 | 
					```bash
 | 
				
			||||||
-- | --
 | 
					npm install @apiclient.xyz/hetznercloud
 | 
				
			||||||
GitLab Pipelines | [](https://lossless.cloud)
 | 
					```
 | 
				
			||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
 | 
					
 | 
				
			||||||
npm | [](https://lossless.cloud)
 | 
					Or using yarn:
 | 
				
			||||||
Snyk | [](https://lossless.cloud)
 | 
					
 | 
				
			||||||
TypeScript Support | [](https://lossless.cloud)
 | 
					```bash
 | 
				
			||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
 | 
					yarn add @apiclient.xyz/hetznercloud
 | 
				
			||||||
Code Style | [](https://lossless.cloud)
 | 
					```
 | 
				
			||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
 | 
					 | 
				
			||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
 | 
					 | 
				
			||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Usage
 | 
					## Usage
 | 
				
			||||||
A modern approach to talking to the hetzner API.
 | 
					
 | 
				
			||||||
 | 
					The `@apiclient.xyz/hetznercloud` package provides a modern approach to interact with the Hetzner Cloud API. Below are some detailed examples demonstrating the usage of this package for different scenarios like managing accounts, servers, volumes, and firewalls. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Initial Setup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To begin using the package, you need to import it and initialize your Hetzner account with an API token:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```typescript
 | 
					```typescript
 | 
				
			||||||
// assuming top level await here
 | 
					import { HetznerAccount, HetznerServer, Volume, HetznerFirewall } from '@apiclient.xyz/hetznercloud';
 | 
				
			||||||
import hetznerCloud from '@apiclient.xyz/hetznercloud'
 | 
					
 | 
				
			||||||
const myhetznerAccount = new hetznerCloud.HetznerAccount('myToken');
 | 
					// Initialize Hetzner account
 | 
				
			||||||
const servers = await myhetznerAccount.getServers();
 | 
					const myHetznerAccount = new HetznerAccount('yourHetznerApiToken');
 | 
				
			||||||
for (const server of servers) {
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Managing Servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Creating a Server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can create a new server using the `createServer` method in the `HetznerAccount` class. Provide the necessary options such as name, type, location, labels, and optional user data:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const newServer = await myHetznerAccount.createServer({
 | 
				
			||||||
 | 
					  name: 'my-server',
 | 
				
			||||||
 | 
					  type: 'cpx31',
 | 
				
			||||||
 | 
					  location: 'nbg1',
 | 
				
			||||||
 | 
					  labels: {
 | 
				
			||||||
 | 
					    purpose: 'test'
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  userData: '#!/bin/bash\necho Hello from your new server!'
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('New server details:', newServer.data);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Listing Servers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To list all servers in your account, you can use the `getServers` method:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const servers = await myHetznerAccount.getServers();
 | 
				
			||||||
 | 
					console.log('Current servers:', servers);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Filtering Servers by Labels
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can filter servers based on specific labels:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const filteredServers = await myHetznerAccount.getServersByLabel({ purpose: 'test' });
 | 
				
			||||||
 | 
					console.log('Filtered servers:', filteredServers);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Deleting a Server
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To delete a server, call the `delete` method on the server instance:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const serverToDelete = filteredServers[0]; // Example, choose the first filtered server
 | 
				
			||||||
 | 
					await serverToDelete.delete();
 | 
				
			||||||
 | 
					console.log('Server deleted successfully');
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Managing Volumes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Creating a Volume
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To create a new volume, use the `Volume.create` method, passing in the necessary options:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const newVolume = await Volume.create(myHetznerAccount, {
 | 
				
			||||||
 | 
					  name: 'my-volume',
 | 
				
			||||||
 | 
					  size: 10, // Size in GB
 | 
				
			||||||
 | 
					  location: 'nbg1',
 | 
				
			||||||
 | 
					  labels: {
 | 
				
			||||||
 | 
					    purpose: 'test-volume'
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  server: newServer // Attach the volume to a specific server (newServer in this case)
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('New volume details:', newVolume.data);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Listing Volumes
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					You can list all volumes in your account with the `getVolumes` method:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const volumes = await Volume.getVolumes(myHetznerAccount);
 | 
				
			||||||
 | 
					console.log('Current volumes:', volumes);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Filtering Volumes by Labels
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To filter volumes based on specific labels:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const filteredVolumes = await Volume.getVolumesByLabel(myHetznerAccount, { purpose: 'test-volume' });
 | 
				
			||||||
 | 
					console.log('Filtered volumes:', filteredVolumes);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Deleting a Volume
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To delete a volume, call the `delete` method on the volume instance:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const volumeToDelete = filteredVolumes[0]; // Example, choose the first filtered volume
 | 
				
			||||||
 | 
					await volumeToDelete.delete();
 | 
				
			||||||
 | 
					console.log('Volume deleted successfully');
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Managing Firewalls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Creating a Firewall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To create a new firewall, use the `create` method in the `HetznerFirewall` class:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const newFirewall = await HetznerFirewall.create(myHetznerAccount, {
 | 
				
			||||||
 | 
					  name: 'my-firewall',
 | 
				
			||||||
 | 
					  labels: {
 | 
				
			||||||
 | 
					    purpose: 'test-firewall'
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  rules: [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      direction: 'in',
 | 
				
			||||||
 | 
					      protocol: 'tcp',
 | 
				
			||||||
 | 
					      port: '80',
 | 
				
			||||||
 | 
					      source_ips: ['0.0.0.0/0', '::/0']
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      direction: 'in',
 | 
				
			||||||
 | 
					      protocol: 'tcp',
 | 
				
			||||||
 | 
					      port: '443',
 | 
				
			||||||
 | 
					      source_ips: ['0.0.0.0/0', '::/0']
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					console.log('New firewall details:', newFirewall.data);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Listing Firewalls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To list all firewalls in your account:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const firewalls = await HetznerFirewall.getFirewalls(myHetznerAccount);
 | 
				
			||||||
 | 
					console.log('Current firewalls:', firewalls);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Filtering Firewalls by Labels
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To filter firewalls based on specific labels:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const filteredFirewalls = await HetznerFirewall.getFirewallsByLabel(myHetznerAccount, { purpose: 'test-firewall' });
 | 
				
			||||||
 | 
					console.log('Filtered firewalls:', filteredFirewalls);
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#### Deleting a Firewall
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To delete a firewall, call the `delete` method on the firewall instance:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					const firewallToDelete = filteredFirewalls[0]; // Example, choose the first filtered firewall
 | 
				
			||||||
 | 
					await firewallToDelete.delete();
 | 
				
			||||||
 | 
					console.log('Firewall deleted successfully');
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Example: Full Lifecycle Management
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Here is a complete example that demonstrates the full lifecycle of creating, listing, filtering, and deleting servers, volumes, and firewalls:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```typescript
 | 
				
			||||||
 | 
					import { HetznerAccount, HetznerServer, Volume, HetznerFirewall } from '@apiclient.xyz/hetznercloud';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Initialize Hetzner account
 | 
				
			||||||
 | 
					const myHetznerAccount = new HetznerAccount('yourHetznerApiToken');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Step 1: Create a new server
 | 
				
			||||||
 | 
					const newServer = await myHetznerAccount.createServer({
 | 
				
			||||||
 | 
					  name: 'my-server',
 | 
				
			||||||
 | 
					  type: 'cpx31',
 | 
				
			||||||
 | 
					  location: 'nbg1',
 | 
				
			||||||
 | 
					  labels: { purpose: 'test' },
 | 
				
			||||||
 | 
					  userData: '#!/bin/bash\necho Hello from your new server!'
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					console.log('New server created:', newServer.data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Step 2: Create a new volume and attach it to the server
 | 
				
			||||||
 | 
					const newVolume = await Volume.create(myHetznerAccount, {
 | 
				
			||||||
 | 
					  name: 'my-volume',
 | 
				
			||||||
 | 
					  size: 10, // GB
 | 
				
			||||||
 | 
					  location: 'nbg1',
 | 
				
			||||||
 | 
					  labels: { purpose: 'test-volume' },
 | 
				
			||||||
 | 
					  server: newServer
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					console.log('New volume created:', newVolume.data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Step 3: Create a new firewall and attach rules to it
 | 
				
			||||||
 | 
					const newFirewall = await HetznerFirewall.create(myHetznerAccount, {
 | 
				
			||||||
 | 
					  name: 'my-firewall',
 | 
				
			||||||
 | 
					  labels: { purpose: 'test-firewall' },
 | 
				
			||||||
 | 
					  rules: [
 | 
				
			||||||
 | 
					    { direction: 'in', protocol: 'tcp', port: '80', source_ips: ['0.0.0.0/0', '::/0'] },
 | 
				
			||||||
 | 
					    { direction: 'in', protocol: 'tcp', port: '443', source_ips: ['0.0.0.0/0', '::/0'] }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					console.log('New firewall created:', newFirewall.data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Step 4: List all servers, volumes, and firewalls
 | 
				
			||||||
 | 
					const servers = await myHetznerAccount.getServers();
 | 
				
			||||||
 | 
					console.log('All servers:', servers);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const volumes = await Volume.getVolumes(myHetznerAccount);
 | 
				
			||||||
 | 
					console.log('All volumes:', volumes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const firewalls = await HetznerFirewall.getFirewalls(myHetznerAccount);
 | 
				
			||||||
 | 
					console.log('All firewalls:', firewalls);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Step 5: Filter servers, volumes, and firewalls by labels
 | 
				
			||||||
 | 
					const filteredServers = await myHetznerAccount.getServersByLabel({ purpose: 'test' });
 | 
				
			||||||
 | 
					console.log('Filtered servers:', filteredServers);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const filteredVolumes = await Volume.getVolumesByLabel(myHetznerAccount, { purpose: 'test-volume' });
 | 
				
			||||||
 | 
					console.log('Filtered volumes:', filteredVolumes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const filteredFirewalls = await HetznerFirewall.getFirewallsByLabel(myHetznerAccount, { purpose: 'test-firewall' });
 | 
				
			||||||
 | 
					console.log('Filtered firewalls:', filteredFirewalls);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Step 6: Cleanup - Delete created resources
 | 
				
			||||||
 | 
					for (const server of filteredServers) {
 | 
				
			||||||
  await server.delete();
 | 
					  await server.delete();
 | 
				
			||||||
 | 
					  console.log('Server deleted:', server.data);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for (const volume of filteredVolumes) {
 | 
				
			||||||
 | 
					  await volume.delete();
 | 
				
			||||||
 | 
					  console.log('Volume deleted:', volume.data);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					for (const firewall of filteredFirewalls) {
 | 
				
			||||||
 | 
					  await firewall.delete();
 | 
				
			||||||
 | 
					  console.log('Firewall deleted:', firewall.data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Legal
 | 
					This comprehensive example demonstrates how you can manage your Hetzner resources using the `@apiclient.xyz/hetznercloud` package efficiently and effectively.
 | 
				
			||||||
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
 | 
					undefined
 | 
				
			||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
 | 
					 | 
				
			||||||
@@ -3,6 +3,6 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
export const commitinfo = {
 | 
					export const commitinfo = {
 | 
				
			||||||
  name: '@apiclient.xyz/hetznercloud',
 | 
					  name: '@apiclient.xyz/hetznercloud',
 | 
				
			||||||
  version: '1.1.0',
 | 
					  version: '1.1.1',
 | 
				
			||||||
  description: 'an unofficial api client for the hetzner cloud api'
 | 
					  description: 'An unofficial TypeScript API client for the Hetzner Cloud API providing easy methods to manage servers, volumes, and firewalls.'
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ import type { HetznerServer } from './classes.server.js';
 | 
				
			|||||||
import * as plugins from './hetznercloud.plugins.js';
 | 
					import * as plugins from './hetznercloud.plugins.js';
 | 
				
			||||||
import * as types from './types.js';
 | 
					import * as types from './types.js';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class Volume {
 | 
					export class HetznerVolume {
 | 
				
			||||||
  public static create = async (
 | 
					  public static create = async (
 | 
				
			||||||
    hetznerAccountRefArg: HetznerAccount,
 | 
					    hetznerAccountRefArg: HetznerAccount,
 | 
				
			||||||
    optionsArg: {
 | 
					    optionsArg: {
 | 
				
			||||||
@@ -14,7 +14,7 @@ export class Volume {
 | 
				
			|||||||
      server: HetznerServer,
 | 
					      server: HetznerServer,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  ) => {
 | 
					  ) => {
 | 
				
			||||||
    const volume = new Volume(hetznerAccountRefArg);
 | 
					    const volume = new HetznerVolume(hetznerAccountRefArg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const createVolumeUrl = '/volumes';
 | 
					    const createVolumeUrl = '/volumes';
 | 
				
			||||||
    const createVolumePayload: types.TVolumeCreateRequestBody = {
 | 
					    const createVolumePayload: types.TVolumeCreateRequestBody = {
 | 
				
			||||||
@@ -38,9 +38,9 @@ export class Volume {
 | 
				
			|||||||
    const volumesGetUrl = '/volumes';
 | 
					    const volumesGetUrl = '/volumes';
 | 
				
			||||||
    const response = await hetznerAccountRefArg.request('GET', volumesGetUrl, {});
 | 
					    const response = await hetznerAccountRefArg.request('GET', volumesGetUrl, {});
 | 
				
			||||||
    const volumesDataArray = (response.body as types.TVolumeGetResponseBody).volumes;
 | 
					    const volumesDataArray = (response.body as types.TVolumeGetResponseBody).volumes;
 | 
				
			||||||
    const volumes: Volume[] = [];
 | 
					    const volumes: HetznerVolume[] = [];
 | 
				
			||||||
    for (const volumeData of volumesDataArray) {
 | 
					    for (const volumeData of volumesDataArray) {
 | 
				
			||||||
      const volume = new Volume(hetznerAccountRefArg);
 | 
					      const volume = new HetznerVolume(hetznerAccountRefArg);
 | 
				
			||||||
      volume.data = volumeData;
 | 
					      volume.data = volumeData;
 | 
				
			||||||
      volumes.push(volume);
 | 
					      volumes.push(volume);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -48,8 +48,8 @@ export class Volume {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public static getVolumesByLabel = async (hetznerAccountRefArg: HetznerAccount, labelObject: {[key: string]: string}) => {
 | 
					  public static getVolumesByLabel = async (hetznerAccountRefArg: HetznerAccount, labelObject: {[key: string]: string}) => {
 | 
				
			||||||
    const volumes = await Volume.getVolumes(hetznerAccountRefArg);
 | 
					    const volumes = await HetznerVolume.getVolumes(hetznerAccountRefArg);
 | 
				
			||||||
    const results: Volume[] = [];
 | 
					    const results: HetznerVolume[] = [];
 | 
				
			||||||
    for (const volume of volumes) {
 | 
					    for (const volume of volumes) {
 | 
				
			||||||
      let isMatch = true;
 | 
					      let isMatch = true;
 | 
				
			||||||
      for (const key in labelObject) {
 | 
					      for (const key in labelObject) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user