@villdyr/gigahost-js
v0.1.0
Published
A zero-dependency TypeScript client for the Gigahost API - manage servers, DNS zones, BGP, and more.
Maintainers
Readme
gigahost-js
A zero-dependency TypeScript client for the Gigahost API. Manage servers, DNS zones, BGP, .no domains, and more.
- Zero runtime dependencies - uses native
fetch - Full TypeScript - typed responses and request params
- Dual auth - use a Bearer token or authenticate with username/password
- ESM + CommonJS - works in Node and bundlers
Installation
npm install @villdyr/gigahost-jsQuick Start
Option A - Token (e.g. from your own auth flow):
import { GigahostClient } from "@villdyr/gigahost-js";
const client = new GigahostClient({
token: "YOUR_BEARER_TOKEN",
});
const servers = await client.listServers();
const zones = await client.listDnsZones();Option B - Username + password (client will authenticate for you):
import { GigahostClient } from "@villdyr/gigahost-js";
const client = new GigahostClient({
username: "[email protected]",
password: "your-password",
// code: 123456, // if 2FA is enabled
});
// Token is fetched automatically on first request
const servers = await client.listServers();Get a token explicitly:
const client = new GigahostClient({ username: "[email protected]", password: "secret" });
const { token, token_expire, customer_id } = await client.authenticate();
// Use token elsewhere or keep using the client (it already has the token)API Reference
Constructor
// With token (no automatic auth)
new GigahostClient({ token: string, baseUrl?: string })
// With credentials (authenticates on first request or when you call authenticate())
new GigahostClient({ username: string, password: string, code?: number, baseUrl?: string })| Option | Type | Description |
| ---------- | -------- | --------------------------------------------------------------------------- |
| token | string | Bearer token from POST /authenticate. Use when you already have a token. |
| username | string | Gigahost account username/email. |
| password | string | Account password. |
| code | number | 2FA code when enabled. |
| baseUrl | string | Override base URL. Defaults to https://api.gigahost.no/api/v0. |
Servers
await client.listServers();
await client.getServer(serverId);
await client.updateServerName(serverId, "my-server");
await client.rebootServer(serverId);
await client.powerOnServer(serverId);
await client.powerOffServer(serverId);
await client.getServerPowerState(serverId);
// Snapshots
await client.listServerSnapshots(serverId);
await client.createServerSnapshot(serverId, "backup-1");
await client.deleteServerSnapshot(serverId, snapId);
// KVM/IPMI (session ~3h)
await client.createServerIpmiSession(serverId, "1.2.3.4;10.0.0.0/24");
// Reinstall
const distros = await client.listReinstallDistros();
const osList = await client.listReinstallOs(distroId);
const { root_passwd, reboot } = await client.reinstallServer(serverId, {
os_id: 72,
language: "en_US",
keyboard: "no",
timezone: "Europe/Oslo",
hostname: "srv123.gigahost.no",
});
// Reverse DNS, upgrades, IPs, graphs, ISOs
await client.updateServerReverse(serverId, { ip_id: 7795, dns: "host.example.com" });
await client.listServerUpgrades(serverId);
await client.upgradeServer(serverId, pkgId);
await client.orderServerIpv4(serverId, "l3");
await client.getServerPortBits(serverId); // base64 graphs
await client.getServerPortUpkts(serverId);
await client.listServerIsos(serverId);
await client.mountServerIso(serverId, isoId);DNS zones & records
// Zones
const zones = await client.listDnsZones();
await client.createDnsZone({ zone_name: "example.no" });
await client.deleteDnsZone(zoneId);
// Records
const records = await client.listDnsRecords(zoneId);
await client.createDnsRecord(zoneId, {
record_name: "www",
record_type: "A",
record_value: "185.125.168.166",
record_ttl: 3600,
});
await client.updateDnsRecord(zoneId, recordId, { record_value: "1.2.3.4" });
await client.deleteDnsRecord(zoneId, recordId, "www", "A");
// .no domain registration & registrant
const check = await client.dnsCheckDomain("example.no");
await client.registerDomain({ domain_name: "example.no", registrant_type: "organization", ... });
const registrant = await client.getDnsRegistrant(zoneId);
await client.updateDnsRegistrant(zoneId, { ... });
await client.setDnsAutoRenew(zoneId, 1);
await client.updateDnsNameservers(zoneId, ["ns1.example.com", "ns2.example.com"]);
await client.updateDnsRegistrantEmail(zoneId, "[email protected]", true);
// Redirects
await client.listDnsRedirects(zoneId);
await client.createDnsRedirect(zoneId, { source: "@", target_url: "https://www.example.com" });
await client.updateDnsRedirect(zoneId, "@", "https://new.example.com");
await client.deleteDnsRedirect(zoneId, "@");
// DNSSEC, DS records, PTR
await client.getDnsDsRecords(zoneId);
await client.setDnsDnssec(zoneId, 1);
await client.createDnsPtrZone({ prefix: "185.181.63", ip_version: "ipv4", zone_name: "63.181.185.in-addr.arpa" });BGP
const bgp = await client.getBgp(); // { asn, prefix_lists, sessions }
await client.submitBgpAsn("212345");
await client.createBgpSession(asnId, { redundant: 1, defaultroute: 1, ip_id_v4: "7795", ip_id_v6: "7796" });
await client.deleteBgpSession(sessionId);Account & invoices
const account = await client.getAccount();
const invoices = await client.listInvoices();Lookup helpers
const org = await client.dnsLookupOrganization("123456789"); // Brønnøysund
const domainCheck = await client.dnsCheckDomain("example.no");Error handling
All API errors throw GigahostError with status, body, and optional messageFromApi:
import { GigahostClient, GigahostError } from "@villdyr/gigahost-js";
try {
await client.getServer(999);
} catch (err) {
if (err instanceof GigahostError) {
console.error(err.status);
console.error(err.messageFromApi);
console.error(err.body);
}
}TypeScript
Types are exported for use in your code:
import type {
Server,
DnsZone,
DnsRecord,
BgpData,
Account,
Invoice,
GigahostClientOptions,
} from "@villdyr/gigahost-js";License
MIT
