import { HetznerServer } from './classes.server.js'; import * as plugins from './hetznercloud.plugins.js'; export class HetznerAccount { public token: string; constructor(tokenArg: string) { this.token = tokenArg; } public async getServers() { return HetznerServer.getServers(this); } public async getServersByLabel(labelObject: plugins.tsclass.typeFestOwn.SecondArgument) { return HetznerServer.getServersByLabel(this, labelObject); } public async createServer(optionsArg: plugins.tsclass.typeFestOwn.SecondArgument) { return HetznerServer.create(this, optionsArg); } /** * request things from the hetzner API * @param methodArg * @param pathArg * @param payloadArg */ public request = async (methodArg: string, pathArg: string, payloadArg: any) => { const url = `https://api.hetzner.cloud/v1${pathArg}`; console.log(`Url: ${url}`); console.log(`Method: ${methodArg}`); console.log(`Payload: ${JSON.stringify(payloadArg, null, 2)}`); const response = await plugins.smartrequest.request(url, { method: methodArg, headers: { Authorization: `Bearer ${this.token}`, }, requestBody: payloadArg, keepAlive: false, }); console.log(response.statusCode); console.log(response.body); return response; } }