UNPKG

hetzner-ts

Version:

A TypeScript SDK for the Hetzner Cloud API

2 lines 21.2 kB
"use strict";var k=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var x=(i,e)=>{for(var s in e)k(i,s,{get:e[s],enumerable:!0})},U=(i,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of v(e))!C.call(i,t)&&t!==s&&k(i,t,{get:()=>e[t],enumerable:!(r=N(e,t))||r.enumerable});return i};var J=i=>U(k({},"__esModule",{value:!0}),i);var j={};x(j,{HetznerAPI:()=>F});module.exports=J(j);var o=class{token;baseUrl;constructor(e,s){this.token=e,this.baseUrl=s||"https://api.hetzner.cloud/v1"}async request(e,s={}){let r=await fetch(`${this.baseUrl}${e}`,{...s,headers:{...s.headers||{},Authorization:`Bearer ${this.token}`,"Content-Type":"application/json"}}),t=r.status===204?null:await r.json();return r.ok?{success:!0,response:t}:{success:!1,response:t}}};var u=class extends o{async get(){return this.request("/pricing")}};var p=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/firewalls/actions${r?`?${r}`:""}`)}async get(e,s){return this.request(`/firewalls/${e}/actions/${s}`)}async applyToResources(e,s){return this.request(`/firewalls/${e}/actions/apply_to_resources`,{method:"POST",body:JSON.stringify({apply_to:s})})}async removeFromResources(e,s){return this.request(`/firewalls/${e}/actions/remove_from_resources`,{method:"POST",body:JSON.stringify({remove_from:s})})}async setRules(e,s){return this.request(`/firewalls/${e}/actions/set_rules`,{method:"POST",body:JSON.stringify({rules:s})})}async getFirewallActions(e,s){let r=new URLSearchParams;s&&Object.entries(s).forEach(([n,a])=>{a!==void 0&&r.append(n,a.toString())});let t=r.toString();return this.request(`/firewalls/${e}/actions${t?`?${t}`:""}`)}async getFirewallAction(e,s){return this.request(`/firewalls/${e}/actions/${s}`)}};var m=class extends o{_actions=null;get actions(){return this._actions||(this._actions=new p(this.token)),this._actions}async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/firewalls${r?`?${r}`:""}`)}async create(e){return this.request("/firewalls",{method:"POST",body:JSON.stringify(e)})}async get(e){return this.request(`/firewalls/${e}`)}async update(e,s){return this.request(`/firewalls/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/firewalls/${e}`,{method:"DELETE"})}};var l=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/floating_ips/actions${r?`?${r}`:""}`)}async get(e){return this.request(`/floating_ips/actions/${e}`)}async listForFloatingIP(e,s){let r=new URLSearchParams;s&&Object.entries(s).forEach(([n,a])=>{a!==void 0&&r.append(n,a.toString())});let t=r.toString();return this.request(`/floating_ips/${e}/actions${t?`?${t}`:""}`)}async assign(e,s){return this.request(`/floating_ips/${e}/actions/assign`,{method:"POST",body:JSON.stringify(s)})}async unassign(e){return this.request(`/floating_ips/${e}/actions/unassign`,{method:"POST"})}async changeDNSPTR(e,s){return this.request(`/floating_ips/${e}/actions/change_dns_ptr`,{method:"POST",body:JSON.stringify(s)})}async changeProtection(e,s){return this.request(`/floating_ips/${e}/actions/change_protection`,{method:"POST",body:JSON.stringify(s)})}async getForFloatingIP(e,s){return this.request(`/floating_ips/${e}/actions/${s}`)}};var P=class extends o{_actions=null;async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/floating_ips${r?`?${r}`:""}`)}async get(e){return this.request(`/floating_ips/${e}`)}async create(e){return this.request("/floating_ips",{method:"POST",body:JSON.stringify(e)})}async update(e,s){return this.request(`/floating_ips/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/floating_ips/${e}`,{method:"DELETE"})}get actions(){return this._actions||(this._actions=new l(this.token)),this._actions}};var d=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/locations${r?`?${r}`:""}`)}async get(e){return this.request(`/locations/${e}`)}},f=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/datacenters${r?`?${r}`:""}`)}async get(e){return this.request(`/datacenters/${e}`)}};var y=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/networks/actions${r?`?${r}`:""}`)}async get(e){return this.request(`/networks/actions/${e}`)}async listForNetwork(e,s){let r=new URLSearchParams;s&&Object.entries(s).forEach(([n,a])=>{a!==void 0&&r.append(n,a.toString())});let t=r.toString();return this.request(`/networks/${e}/actions${t?`?${t}`:""}`)}async getForNetwork(e,s){return this.request(`/networks/${e}/actions/${s}`)}async addRoute(e,s){return this.request(`/networks/${e}/actions/add_route`,{method:"POST",body:JSON.stringify(s)})}async deleteRoute(e,s){return this.request(`/networks/${e}/actions/delete_route`,{method:"POST",body:JSON.stringify(s)})}async addSubnet(e,s){return this.request(`/networks/${e}/actions/add_subnet`,{method:"POST",body:JSON.stringify(s)})}async deleteSubnet(e,s){return this.request(`/networks/${e}/actions/delete_subnet`,{method:"POST",body:JSON.stringify(s)})}async changeIPRange(e,s){return this.request(`/networks/${e}/actions/change_ip_range`,{method:"POST",body:JSON.stringify(s)})}async changeProtection(e,s){return this.request(`/networks/${e}/actions/change_protection`,{method:"POST",body:JSON.stringify(s)})}};var g=class extends o{_actions=null;async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/networks${r?`?${r}`:""}`)}async create(e){return this.request("/networks",{method:"POST",body:JSON.stringify(e)})}async get(e){return this.request(`/networks/${e}`)}async update(e,s){return this.request(`/networks/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/networks/${e}`,{method:"DELETE"})}get actions(){return this._actions||(this._actions=new y(this.token)),this._actions}};var A=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{Array.isArray(n)?n.forEach(a=>s.append(t,a.toString())):n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/certificates/actions${r?`?${r}`:""}`)}async get(e){return this.request(`/certificates/actions/${e}`)}async listForCertificate(e,s){let r=new URLSearchParams;s&&Object.entries(s).forEach(([n,a])=>{Array.isArray(a)?a.forEach(c=>r.append(n,c.toString())):a!==void 0&&r.append(n,a.toString())});let t=r.toString();return this.request(`/certificates/${e}/actions${t?`?${t}`:""}`)}async getForCertificate(e,s){return this.request(`/certificates/${e}/actions/${s}`)}async retry(e){return this.request(`/certificates/${e}/actions/retry`,{method:"POST"})}};var h=class extends o{_actions=null;async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/certificates${r?`?${r}`:""}`)}async get(e){return this.request(`/certificates/${e}`)}async create(e){return this.request("/certificates",{method:"POST",body:JSON.stringify(e)})}async update(e,s){return this.request(`/certificates/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/certificates/${e}`,{method:"DELETE"})}get actions(){return this._actions||(this._actions=new A(this.token)),this._actions}};var S=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/ssh_keys${r?`?${r}`:""}`)}async get(e){return this.request(`/ssh_keys/${e}`)}async create(e){return this.request("/ssh_keys",{method:"POST",body:JSON.stringify(e)})}async update(e,s){return this.request(`/ssh_keys/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/ssh_keys/${e}`,{method:"DELETE"})}};var b=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&(Array.isArray(n)?n.forEach(a=>s.append(t,a.toString())):s.append(t,n.toString()))});let r=s.toString();return this.request(`/volumes/actions${r?`?${r}`:""}`)}async getGlobalAction(e){return this.request(`/volumes/actions/${e}`)}async listForVolume(e,s){let r=new URLSearchParams;s&&Object.entries(s).forEach(([n,a])=>{a!==void 0&&(Array.isArray(a)?a.forEach(c=>r.append(n,c.toString())):r.append(n,a.toString()))});let t=r.toString();return this.request(`/volumes/${e}/actions${t?`?${t}`:""}`)}async getAction(e,s){return this.request(`/volumes/${e}/actions/${s}`)}async attach(e,s){return this.request(`/volumes/${e}/actions/attach`,{method:"POST",body:JSON.stringify(s)})}async detach(e){return this.request(`/volumes/${e}/actions/detach`,{method:"POST"})}async resize(e,s){return this.request(`/volumes/${e}/actions/resize`,{method:"POST",body:JSON.stringify(s)})}async changeProtection(e,s){return this.request(`/volumes/${e}/actions/change_protection`,{method:"POST",body:JSON.stringify(s)})}};var I=class extends o{_actions=null;async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&(Array.isArray(n)?n.forEach(a=>s.append(t,a.toString())):s.append(t,n.toString()))});let r=s.toString();return this.request(`/volumes${r?`?${r}`:""}`)}async get(e){return this.request(`/volumes/${e}`)}async create(e){return this.request("/volumes",{method:"POST",body:JSON.stringify(e)})}async update(e,s){return this.request(`/volumes/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/volumes/${e}`,{method:"DELETE"})}get actions(){return this._actions||(this._actions=new b(this.token)),this._actions}};var E=class extends o{async getAllGlobal(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&(Array.isArray(n)?n.forEach(a=>s.append(t,a.toString())):s.append(t,n.toString()))});let r=s.toString();return this.request(`/load_balancers/actions${r?`?${r}`:""}`)}async getGlobalAction(e){return this.request(`/load_balancers/actions/${e}`)}async listForLoadBalancer(e,s){let r=new URLSearchParams;s&&Object.entries(s).forEach(([n,a])=>{a!==void 0&&(Array.isArray(a)?a.forEach(c=>r.append(n,c.toString())):r.append(n,a.toString()))});let t=r.toString();return this.request(`/load_balancers/${e}/actions${t?`?${t}`:""}`)}async getAction(e,s){return this.request(`/load_balancers/${e}/actions/${s}`)}async addService(e,s){return this.request(`/load_balancers/${e}/actions/add_service`,{method:"POST",body:JSON.stringify(s)})}async updateService(e,s){return this.request(`/load_balancers/${e}/actions/update_service`,{method:"POST",body:JSON.stringify(s)})}async deleteService(e,s){return this.request(`/load_balancers/${e}/actions/delete_service`,{method:"POST",body:JSON.stringify(s)})}async addTarget(e,s){return this.request(`/load_balancers/${e}/actions/add_target`,{method:"POST",body:JSON.stringify(s)})}async removeTarget(e,s){return this.request(`/load_balancers/${e}/actions/remove_target`,{method:"POST",body:JSON.stringify(s)})}async attachToNetwork(e,s){return this.request(`/load_balancers/${e}/actions/attach_to_network`,{method:"POST",body:JSON.stringify(s)})}async detachFromNetwork(e,s){return this.request(`/load_balancers/${e}/actions/detach_from_network`,{method:"POST",body:JSON.stringify(s)})}async changeAlgorithm(e,s){return this.request(`/load_balancers/${e}/actions/change_algorithm`,{method:"POST",body:JSON.stringify(s)})}async changeDNSPTR(e,s){return this.request(`/load_balancers/${e}/actions/change_dns_ptr`,{method:"POST",body:JSON.stringify(s)})}async changeProtection(e,s){return this.request(`/load_balancers/${e}/actions/change_protection`,{method:"POST",body:JSON.stringify(s)})}async changeType(e,s){return this.request(`/load_balancers/${e}/actions/change_type`,{method:"POST",body:JSON.stringify(s)})}async enablePublicInterface(e){return this.request(`/load_balancers/${e}/actions/enable_public_interface`,{method:"POST"})}async disablePublicInterface(e){return this.request(`/load_balancers/${e}/actions/disable_public_interface`,{method:"POST"})}};var _=class extends o{_actions=null;async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/load_balancers${r?`?${r}`:""}`)}async create(e){return this.request("/load_balancers",{method:"POST",body:JSON.stringify(e)})}async get(e){return this.request(`/load_balancers/${e}`)}async update(e,s){return this.request(`/load_balancers/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/load_balancers/${e}`,{method:"DELETE"})}async getMetrics(e,s){let r=new URLSearchParams;return Object.entries(s).forEach(([t,n])=>{n!==void 0&&r.append(t,n.toString())}),this.request(`/load_balancers/${e}/metrics?${r.toString()}`)}async listTypes(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/load_balancer_types${r?`?${r}`:""}`)}async getType(e){return this.request(`/load_balancer_types/${e}`)}get actions(){return this._actions||(this._actions=new E(this.token)),this._actions}};var R=class extends o{async getAll(e){return this.request(`/actions?id=${e}`)}async get(e){return this.request(`/actions/${e}`)}};var w=class extends o{async getAll(e){let s=new URLSearchParams;return e&&Object.entries(e).forEach(([r,t])=>{t!=null&&t!==""&&s.append(r,t.toString())}),this.request(`/images${s?`?${s}`:""}`)}async get(e){return this.request(`/images/${e}`)}async update(e,s){return this.request(`/images/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/images/${e}`,{method:"DELETE"})}};var q=class extends o{async getAll(e){let s=new URLSearchParams;return e&&Object.entries(e).forEach(([r,t])=>{t!=null&&t!==""&&s.append(r,t.toString())}),this.request(`/primary_ips${s?`?${s}`:""}`)}async get(e){return this.request(`/primary_ips/${e}`)}async create(e){return this.request("/primary_ips",{method:"POST",body:JSON.stringify(e)})}async update(e,s){return this.request(`/primary_ips/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/primary_ips/${e}`,{method:"DELETE"})}};var L=class extends o{async getAll(e){let s=new URLSearchParams;return e&&Object.entries(e).forEach(([r,t])=>{t!=null&&t!==""&&s.append(r,t.toString())}),this.request(`/placement_groups${s?`?${s}`:""}`)}async get(e){return this.request(`/placement_groups/${e}`)}async create(e){return this.request("/placement_groups",{method:"POST",body:JSON.stringify(e)})}async update(e,s){return this.request(`/placement_groups/${e}`,{method:"PUT",body:JSON.stringify(s)})}async delete(e){return this.request(`/placement_groups/${e}`,{method:"DELETE"})}};var B=class extends o{async getAll(e){let s=new URLSearchParams;return e&&Object.entries(e).forEach(([r,t])=>{t!=null&&t!==""&&s.append(r,t.toString())}),this.request(`/isos${s?`?${s}`:""}`)}async get(e){return this.request(`/isos/${e}`)}};var $=class extends o{async getAll(e){let s=new URLSearchParams;return e&&Object.entries(e).forEach(([r,t])=>{t!=null&&t!==""&&s.append(r,t.toString())}),this.request(`/server_types${s?`?${s}`:""}`)}async get(e){return this.request(`/server_types/${e}`)}};var O=class extends o{async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&(Array.isArray(n)?n.forEach(a=>s.append(t,a.toString())):s.append(t,n.toString()))});let r=s.toString();return this.request(`/servers/actions${r?`?${r}`:""}`)}async get(e){return this.request(`/servers/actions/${e}`)}async getAllByServer(e,s){let r=new URLSearchParams;s&&Object.entries(s).forEach(([n,a])=>{a!==void 0&&r.append(n,a.toString())});let t=r.toString();return this.request(`/servers/${e}/actions${t?`?${t}`:""}`)}async addServerToPlacementGroup(e,s){return this.request(`/servers/${e}/actions/add_to_placement_group`,{method:"POST",body:JSON.stringify({placement_group:s})})}async attachIsoToServer(e,s){return this.request(`/servers/${e}/actions/attach_iso`,{method:"POST",body:JSON.stringify({iso:s})})}async attachServerToNetwork(e,s,r,t){return this.request(`/servers/${e}/actions/attach_to_network`,{method:"POST",body:JSON.stringify({network:s,ip:r,alias_ips:t})})}async changeAliasIpOfNetwork(e,s,r){return this.request(`/servers/${e}/actions/change_alias_ips`,{method:"POST",body:JSON.stringify({network:s,alias_ips:r})})}async changeReverseDnsEntryForServer(e,s,r){return this.request(`/servers/${e}/actions/change_reverse_dns`,{method:"POST",body:JSON.stringify({ip:s,dns_ptr:r})})}async changeServerProtection(e,s,r){return this.request(`/servers/${e}/actions/change_protection`,{method:"POST",body:JSON.stringify({protect:s,rebuild:r})})}async changeServerType(e,s,r){return this.request(`/servers/${e}/actions/change_type`,{method:"POST",body:JSON.stringify({type:s,upgrade_disk:r})})}async createImageFromServer(e,s,r,t){return this.request(`/servers/${e}/actions/create_image`,{method:"POST",body:JSON.stringify({type:s,description:r,labels:t})})}async detachServerFromNetwork(e,s){return this.request(`/servers/${e}/actions/detach_from_network`,{method:"POST",body:JSON.stringify({network:s})})}async detachIsoFromServer(e){return this.request(`/servers/${e}/actions/detach_iso`,{method:"POST"})}async disableBackupsForServer(e){return this.request(`/servers/${e}/actions/disable_backups`,{method:"POST"})}async disableRescueModeForServer(e){return this.request(`/servers/${e}/actions/disable_rescue`,{method:"POST"})}async enableBackupsForServer(e){return this.request(`/servers/${e}/actions/enable_backups`,{method:"POST"})}async enableRescueModeForServer(e,s,r){return this.request(`/servers/${e}/actions/enable_rescue`,{method:"POST"})}async powerOff(e){return this.request(`/servers/${e}/actions/poweroff`,{method:"POST"})}async powerOn(e){return this.request(`/servers/${e}/actions/poweron`,{method:"POST"})}async softReboot(e){return this.request(`/servers/${e}/actions/reboot`,{method:"POST"})}async rebuildFromImage(e,s){return this.request(`/servers/${e}/actions/rebuild`,{method:"POST",body:JSON.stringify({image:s})})}async removeFromPlacementGroup(e){return this.request(`/servers/${e}/actions/remove_from_placement_group`,{method:"POST"})}async requestConsoleForServer(e){return this.request(`/servers/${e}/actions/request_console`,{method:"POST"})}async resetServer(e){return this.request(`/servers/${e}/actions/reset`,{method:"POST"})}async resetServerPassword(e){return this.request(`/servers/${e}/actions/reset_password`,{method:"POST"})}async shutdownServer(e){return this.request(`/servers/${e}/actions/shutdown`,{method:"POST"})}async getActionForServer(e,s){return this.request(`/servers/${e}/actions/${s}`)}};var T=class extends o{_primaryIP=null;_images=null;_placementGroups=null;_isos=null;_serverTypes=null;_actions=null;get primaryIP(){return this._primaryIP||(this._primaryIP=new q(this.token)),this._primaryIP}get images(){return this._images||(this._images=new w(this.token)),this._images}get placementGroups(){return this._placementGroups||(this._placementGroups=new L(this.token)),this._placementGroups}get isos(){return this._isos||(this._isos=new B(this.token)),this._isos}get serverTypes(){return this._serverTypes||(this._serverTypes=new $(this.token)),this._serverTypes}get actions(){return this._actions||(this._actions=new O(this.token)),this._actions}async getAll(e){let s=new URLSearchParams;e&&Object.entries(e).forEach(([t,n])=>{n!==void 0&&s.append(t,n.toString())});let r=s.toString();return this.request(`/servers${r?`?${r}`:""}`)}async get(e){return this.request(`/servers/${e}`)}async create(e){return this.request("/servers",{method:"POST",body:JSON.stringify(e)})}async delete(e){return this.request(`/servers/${e}`,{method:"DELETE"})}getMetrics(e,s,r,t,n){return this.request(`/servers/${e}/metrics?type=${s}&start=${r}&end=${t}&step=${n}`)}};var F=class extends o{get actions(){return new R(this.token)}get billing(){return new u(this.token)}get certificates(){return new h(this.token)}get datacenters(){return new f(this.token)}get firewalls(){return new m(this.token)}get floatingIps(){return new P(this.token)}get loadBalancers(){return new _(this.token)}get locations(){return new d(this.token)}get networks(){return new g(this.token)}get servers(){return new T(this.token)}get sshKeys(){return new S(this.token)}get volumes(){return new I(this.token)}};0&&(module.exports={HetznerAPI}); //# sourceMappingURL=index.cjs.map