fix(core): update

This commit is contained in:
2024-01-29 21:08:05 +01:00
parent 82668f9610
commit d4f777d0e6
269 changed files with 120 additions and 28951 deletions

30
ts/classes.account.ts Normal file
View File

@ -0,0 +1,30 @@
import * as plugins from './hetznercloud.plugins.js';
export class HetznerAccount {
public token: string;
constructor(tokenArg: string) {
this.token = tokenArg;
}
getServers() {
}
/**
* 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}`;
const response = await plugins.smartrequest.request(url, {
method: methodArg,
headers: {
Authorization: `Bearer ${this.token}`,
},
requestBody: payloadArg,
});
return response;
}
}

40
ts/classes.server.ts Normal file
View File

@ -0,0 +1,40 @@
import type { HetznerAccount } from './classes.account.js';
import * as plugins from './hetznercloud.plugins.js';
import * as types from './types.js';
export class HetznerServer {
// STATIC
static async create(hetznerAccountRefArg: HetznerAccount, optionsArg: {
name: string,
datacenter: 'nbg1-dc3',
}) {
const server = new HetznerServer(hetznerAccountRefArg);
const createServerUrl = '/servers';
const createServerPayload: types.TServerCreateRequestBody =
{
name: optionsArg.name,
datacenter: optionsArg.datacenter,
image: '',
server_type: '',
start_after_create: true,
user_data: '',
};
const response = await server.hetznerAccountRef.request('POST', createServerUrl, createServerPayload);
server.data = (response.body as types.TServerCreateResponseBody).server;
return server;
}
// INSTANCE
public hetznerAccountRef: HetznerAccount;
public data: types.IServer;
constructor(hetznerAccountRefArg: HetznerAccount) {
this.hetznerAccountRef = hetznerAccountRefArg;
}
public async delete() {
await this.hetznerAccountRef.request('DELETE', `/servers/${this.data.id}`, {});
}
}

View File

@ -1,4 +1,12 @@
const removeme = {};
import * as hetznerOpenapi from '@tempfix/hetzner-openapi';
export {
removeme
hetznerOpenapi
}
// @push.rocks
import * as smartrequest from '@push.rocks/smartrequest';
export {
smartrequest,
}

View File

@ -1,3 +0,0 @@
import * as plugins from './hetznercloud.plugins.js';
export let demoExport = 'Hi there! :) This is an exported string';

12
ts/types.ts Normal file
View File

@ -0,0 +1,12 @@
import * as plugins from './hetznercloud.plugins.js';
// datacenters
export type TDatacenters = plugins.hetznerOpenapi.paths['/datacenters']['get']['responses']['200']['content']['application/json'];
// servers
export type IServer = plugins.hetznerOpenapi.paths['/servers/{id}']['get']['responses']['200']['content']['application/json']['server'];
export type TServersGetRequestBody = {};
export type TServersGetResponseBody = plugins.hetznerOpenapi.paths['/servers']['get']['responses']['200']['content']['application/json'];
export type TServerCreateRequestBody = plugins.hetznerOpenapi.paths['/servers']['post']['requestBody']['content']['application/json'];
export type TServerCreateResponseBody = plugins.hetznerOpenapi.paths['/servers']['post']['responses']['201']['content']['application/json'];