fix(core): update

This commit is contained in:
Philipp Kunz 2024-02-17 21:55:25 +01:00
parent 332a4a4195
commit 929404fadd
8 changed files with 100 additions and 31 deletions

View File

@ -19,12 +19,14 @@
"@git.zone/tsbundle": "^2.0.5", "@git.zone/tsbundle": "^2.0.5",
"@git.zone/tsrun": "^1.2.46", "@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.44", "@git.zone/tstest": "^1.0.44",
"@push.rocks/qenv": "^6.0.5",
"@push.rocks/tapbundle": "^5.0.15", "@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.8.7" "@types/node": "^20.8.7"
}, },
"dependencies": { "dependencies": {
"@push.rocks/smartrequest": "^2.0.21", "@push.rocks/smartrequest": "^2.0.21",
"@tempfix/hetzner-openapi": "^1.0.4" "@tempfix/hetzner-openapi": "^1.0.4",
"@tsclass/tsclass": "^4.0.52"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

40
pnpm-lock.yaml generated
View File

@ -11,6 +11,9 @@ dependencies:
'@tempfix/hetzner-openapi': '@tempfix/hetzner-openapi':
specifier: ^1.0.4 specifier: ^1.0.4
version: 1.0.4 version: 1.0.4
'@tsclass/tsclass':
specifier: ^4.0.52
version: 4.0.52
devDependencies: devDependencies:
'@git.zone/tsbuild': '@git.zone/tsbuild':
@ -25,6 +28,9 @@ devDependencies:
'@git.zone/tstest': '@git.zone/tstest':
specifier: ^1.0.44 specifier: ^1.0.44
version: 1.0.86(@types/node@20.11.10)(sinon@17.0.1) version: 1.0.86(@types/node@20.11.10)(sinon@17.0.1)
'@push.rocks/qenv':
specifier: ^6.0.5
version: 6.0.5
'@push.rocks/tapbundle': '@push.rocks/tapbundle':
specifier: ^5.0.15 specifier: ^5.0.15
version: 5.0.15(sinon@17.0.1) version: 5.0.15(sinon@17.0.1)
@ -74,7 +80,7 @@ packages:
'@push.rocks/smartstream': 3.0.30 '@push.rocks/smartstream': 3.0.30
'@push.rocks/smarttime': 4.0.6 '@push.rocks/smarttime': 4.0.6
'@push.rocks/webstore': 2.0.13 '@push.rocks/webstore': 2.0.13
'@tsclass/tsclass': 4.0.46 '@tsclass/tsclass': 4.0.52
'@types/express': 4.17.21 '@types/express': 4.17.21
body-parser: 1.20.2 body-parser: 1.20.2
cors: 2.8.5 cors: 2.8.5
@ -134,6 +140,12 @@ packages:
js-tokens: 4.0.0 js-tokens: 4.0.0
dev: true dev: true
/@configvault.io/interfaces@1.0.17:
resolution: {integrity: sha512-bEcCUR2VBDJsTin8HQh8Uw/mlYl2v8A3jMIaQ+MTB9Hrqd6CZL2dL7iJdWyFl/3EIX+LDxWFR+Oq7liIq7w+1Q==}
dependencies:
'@api.global/typedrequest-interfaces': 3.0.1
dev: true
/@cspotcode/source-map-support@0.8.1: /@cspotcode/source-map-support@0.8.1:
resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==}
engines: {node: '>=12'} engines: {node: '>=12'}
@ -596,6 +608,16 @@ packages:
symbol-tree: 3.2.4 symbol-tree: 3.2.4
dev: true dev: true
/@push.rocks/qenv@6.0.5:
resolution: {integrity: sha512-Id/eSKKqSDUGe+0Cp5HEJ58J1iVv1jQseLUMs9kFTPYwG+NJSETUCRsJV50w5cPv8bRFcSkSU+xVbUbOc1p29A==}
dependencies:
'@api.global/typedrequest': 3.0.4
'@configvault.io/interfaces': 1.0.17
'@push.rocks/smartfile': 11.0.4
'@push.rocks/smartlog': 3.0.3
'@push.rocks/smartpath': 5.0.11
dev: true
/@push.rocks/smartbrowser@2.0.6: /@push.rocks/smartbrowser@2.0.6:
resolution: {integrity: sha512-Ne+KCVhV/DROc1rHRRw59K6h0+LpQAK9fdOUtgDZ7laLPmB/tmnbUh3IuRDNcIY1iVA9pydoobwjnTjVgio9eQ==} resolution: {integrity: sha512-Ne+KCVhV/DROc1rHRRw59K6h0+LpQAK9fdOUtgDZ7laLPmB/tmnbUh3IuRDNcIY1iVA9pydoobwjnTjVgio9eQ==}
dependencies: dependencies:
@ -817,7 +839,7 @@ packages:
'@push.rocks/smartpromise': 4.0.3 '@push.rocks/smartpromise': 4.0.3
'@push.rocks/smartpuppeteer': 2.0.2 '@push.rocks/smartpuppeteer': 2.0.2
'@push.rocks/smartunique': 3.0.6 '@push.rocks/smartunique': 3.0.6
'@tsclass/tsclass': 4.0.46 '@tsclass/tsclass': 4.0.52
'@types/express': 4.17.21 '@types/express': 4.17.21
express: 4.18.2 express: 4.18.2
pdf-merger-js: 3.4.0 pdf-merger-js: 3.4.0
@ -880,7 +902,7 @@ packages:
'@push.rocks/smartxml': 1.0.8 '@push.rocks/smartxml': 1.0.8
'@push.rocks/smartyaml': 2.0.5 '@push.rocks/smartyaml': 2.0.5
'@push.rocks/webrequest': 3.0.34 '@push.rocks/webrequest': 3.0.34
'@tsclass/tsclass': 4.0.46 '@tsclass/tsclass': 4.0.52
dev: true dev: true
/@push.rocks/smartsocket@2.0.24: /@push.rocks/smartsocket@2.0.24:
@ -1321,11 +1343,10 @@ packages:
type-fest: 2.19.0 type-fest: 2.19.0
dev: true dev: true
/@tsclass/tsclass@4.0.46: /@tsclass/tsclass@4.0.52:
resolution: {integrity: sha512-UovPUvlozv1ftJp4KW5tt4MP/LQCNP3lSCinjyIrLkopOymczyzONUGvSAAwOBf1XBE9bO0tI4KtRuXWN9XBXQ==} resolution: {integrity: sha512-yjASmfnDvgWA1OKYXbz4diLIrPBSk5BpPStKuVkAhrhN8Xw4lc6/oSiJpsosEd8GDwr/FPsY2lgN8/5674vM0w==}
dependencies: dependencies:
type-fest: 4.10.1 type-fest: 4.10.2
dev: true
/@tsconfig/node10@1.0.9: /@tsconfig/node10@1.0.9:
resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==} resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==}
@ -5232,10 +5253,9 @@ packages:
engines: {node: '>=12.20'} engines: {node: '>=12.20'}
dev: true dev: true
/type-fest@4.10.1: /type-fest@4.10.2:
resolution: {integrity: sha512-7ZnJYTp6uc04uYRISWtiX3DSKB/fxNQT0B5o1OUeCqiQiwF+JC9+rJiZIDrPrNCLLuTqyQmh4VdQqh/ZOkv9MQ==} resolution: {integrity: sha512-anpAG63wSpdEbLwOqH8L84urkL6PiVIov3EMmgIhhThevh9aiMQov+6Btx0wldNcvm4wV+e2/Rt1QdDwKHFbHw==}
engines: {node: '>=16'} engines: {node: '>=16'}
dev: true
/type-is@1.6.18: /type-is@1.6.18:
resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==}

2
qenv.yml Normal file
View File

@ -0,0 +1,2 @@
required:
- 'HETZNER_API_TOKEN'

View File

@ -1,8 +1,28 @@
import { expect, expectAsync, tap } from '@push.rocks/tapbundle'; import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
import * as hetznercloud from '../ts/index.js' import * as hetznercloud from '../ts/index.js';
import * as qenv from '@push.rocks/qenv';
const testQenv = new qenv.Qenv('./', './.nogit/');
tap.test('first test', async () => { let testAccount: hetznercloud.HetznerAccount;
console.log(hetznercloud)
tap.test('should create a valid hetzer account', async () => {
testAccount = new hetznercloud.HetznerAccount(await testQenv.getEnvVarOnDemand('HETZNER_API_TOKEN'));
expect(testAccount).toBeInstanceOf(hetznercloud.HetznerAccount);
});
tap.test('should be able to list all servers', async () => {
const servers = await testAccount.getServers();
expect(servers).toBeArray();
console.log(JSON.stringify(servers, null, 2));
})
tap.test('should be able to create a server', async () => {
const newServer = await testAccount.createServer({
name: 'testserver',
location: 'nbg1'
});
expect(newServer).toBeInstanceOf(hetznercloud.HetznerServer);
console.log(newServer);
}) })
tap.start() tap.start()

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@apiclient.xyz/hetznercloud', name: '@apiclient.xyz/hetznercloud',
version: '1.0.7', version: '1.0.8',
description: 'an unofficial api client for the hetzner cloud api' description: 'an unofficial api client for the hetzner cloud api'
} }

View File

@ -11,6 +11,10 @@ export class HetznerAccount {
return HetznerServer.getServers(this); return HetznerServer.getServers(this);
} }
public async createServer(optionsArg: plugins.tsclass.typeFestOwn.SecondArgument<typeof HetznerServer.create>) {
return HetznerServer.create(this, optionsArg);
}
/** /**
* request things from the hetzner API * request things from the hetzner API
* @param methodArg * @param methodArg
@ -19,6 +23,9 @@ export class HetznerAccount {
*/ */
public request = async (methodArg: string, pathArg: string, payloadArg: any) => { public request = async (methodArg: string, pathArg: string, payloadArg: any) => {
const url = `https://api.hetzner.cloud/v1${pathArg}`; 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, { const response = await plugins.smartrequest.request(url, {
method: methodArg, method: methodArg,
headers: { headers: {
@ -26,6 +33,8 @@ export class HetznerAccount {
}, },
requestBody: payloadArg, requestBody: payloadArg,
}); });
console.log(response.statusCode);
console.log(response.body);
return response; return response;
} }
} }

View File

@ -4,24 +4,33 @@ import * as types from './types.js';
export class HetznerServer { export class HetznerServer {
// STATIC // STATIC
public static async create(hetznerAccountRefArg: HetznerAccount, optionsArg: { public static async create(
name: string, hetznerAccountRefArg: HetznerAccount,
datacenter: 'nbg1-dc3', optionsArg: {
}) { name: string;
location: 'nbg1';
}
) {
const server = new HetznerServer(hetznerAccountRefArg); const server = new HetznerServer(hetznerAccountRefArg);
const createServerUrl = '/servers'; const createServerUrl = '/servers';
const createServerPayload: types.TServerCreateRequestBody = const createServerPayload: types.TServerCreateRequestBody = {
{ name: optionsArg.name,
name: optionsArg.name, image: 'ubuntu-22.04',
datacenter: optionsArg.datacenter, server_type: 'cx11',
image: '', start_after_create: true,
server_type: '', labels: {},
start_after_create: true, location: optionsArg.location,
user_data: '', public_net: {
}; enable_ipv4: true,
enable_ipv6: true,
const response = await server.hetznerAccountRef.request('POST', createServerUrl, createServerPayload); },
};
const response = await server.hetznerAccountRef.request(
'POST',
createServerUrl,
createServerPayload
);
server.data = (response.body as types.TServerCreateResponseBody).server; server.data = (response.body as types.TServerCreateResponseBody).server;
return server; return server;
} }
@ -29,7 +38,7 @@ export class HetznerServer {
public static async getServers(hetznerAccountRefArg: HetznerAccount) { public static async getServers(hetznerAccountRefArg: HetznerAccount) {
const serversGetUrl = '/servers'; const serversGetUrl = '/servers';
const response = await hetznerAccountRefArg.request('GET', serversGetUrl, {}); const response = await hetznerAccountRefArg.request('GET', serversGetUrl, {});
const serversDataArray = (response.body as types.TServersGetResponseBody).servers; const serversDataArray = (response.body as types.TServersGetResponseBody).servers;
const servers: HetznerServer[] = []; const servers: HetznerServer[] = [];
for (const serverData of serversDataArray) { for (const serverData of serversDataArray) {
const server = new HetznerServer(hetznerAccountRefArg); const server = new HetznerServer(hetznerAccountRefArg);

View File

@ -10,3 +10,10 @@ import * as smartrequest from '@push.rocks/smartrequest';
export { export {
smartrequest, smartrequest,
} }
// @tsclass scope
import * as tsclass from '@tsclass/tsclass';
export {
tsclass,
}