@villdyr/gigahost-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -0
- package/dist/index.cjs +412 -0
- package/dist/index.d.ts +445 -0
- package/dist/index.js +408 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# gigahost-js
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
|
|
5
|
+
A zero-dependency TypeScript client for the [Gigahost API](https://gigahost.no/api-dokumentasjon). Manage servers, DNS zones, BGP, .no domains, and more.
|
|
6
|
+
|
|
7
|
+
- **Zero runtime dependencies** - uses native `fetch`
|
|
8
|
+
- **Full TypeScript** - typed responses and request params
|
|
9
|
+
- **Dual auth** - use a Bearer token or authenticate with username/password
|
|
10
|
+
- **ESM + CommonJS** - works in Node and bundlers
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @villdyr/gigahost-js
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
**Option A - Token (e.g. from your own auth flow):**
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { GigahostClient } from "@villdyr/gigahost-js";
|
|
24
|
+
|
|
25
|
+
const client = new GigahostClient({
|
|
26
|
+
token: "YOUR_BEARER_TOKEN",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const servers = await client.listServers();
|
|
30
|
+
const zones = await client.listDnsZones();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Option B - Username + password (client will authenticate for you):**
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { GigahostClient } from "@villdyr/gigahost-js";
|
|
37
|
+
|
|
38
|
+
const client = new GigahostClient({
|
|
39
|
+
username: "your@email.com",
|
|
40
|
+
password: "your-password",
|
|
41
|
+
// code: 123456, // if 2FA is enabled
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Token is fetched automatically on first request
|
|
45
|
+
const servers = await client.listServers();
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Get a token explicitly:**
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
const client = new GigahostClient({ username: "you@example.com", password: "secret" });
|
|
52
|
+
const { token, token_expire, customer_id } = await client.authenticate();
|
|
53
|
+
// Use token elsewhere or keep using the client (it already has the token)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
### Constructor
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
// With token (no automatic auth)
|
|
62
|
+
new GigahostClient({ token: string, baseUrl?: string })
|
|
63
|
+
|
|
64
|
+
// With credentials (authenticates on first request or when you call authenticate())
|
|
65
|
+
new GigahostClient({ username: string, password: string, code?: number, baseUrl?: string })
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Option | Type | Description |
|
|
69
|
+
| ---------- | -------- | --------------------------------------------------------------------------- |
|
|
70
|
+
| `token` | `string` | Bearer token from `POST /authenticate`. Use when you already have a token. |
|
|
71
|
+
| `username` | `string` | Gigahost account username/email. |
|
|
72
|
+
| `password` | `string` | Account password. |
|
|
73
|
+
| `code` | `number` | 2FA code when enabled. |
|
|
74
|
+
| `baseUrl` | `string` | Override base URL. Defaults to `https://api.gigahost.no/api/v0`. |
|
|
75
|
+
|
|
76
|
+
### Servers
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
await client.listServers();
|
|
80
|
+
await client.getServer(serverId);
|
|
81
|
+
await client.updateServerName(serverId, "my-server");
|
|
82
|
+
await client.rebootServer(serverId);
|
|
83
|
+
await client.powerOnServer(serverId);
|
|
84
|
+
await client.powerOffServer(serverId);
|
|
85
|
+
await client.getServerPowerState(serverId);
|
|
86
|
+
|
|
87
|
+
// Snapshots
|
|
88
|
+
await client.listServerSnapshots(serverId);
|
|
89
|
+
await client.createServerSnapshot(serverId, "backup-1");
|
|
90
|
+
await client.deleteServerSnapshot(serverId, snapId);
|
|
91
|
+
|
|
92
|
+
// KVM/IPMI (session ~3h)
|
|
93
|
+
await client.createServerIpmiSession(serverId, "1.2.3.4;10.0.0.0/24");
|
|
94
|
+
|
|
95
|
+
// Reinstall
|
|
96
|
+
const distros = await client.listReinstallDistros();
|
|
97
|
+
const osList = await client.listReinstallOs(distroId);
|
|
98
|
+
const { root_passwd, reboot } = await client.reinstallServer(serverId, {
|
|
99
|
+
os_id: 72,
|
|
100
|
+
language: "en_US",
|
|
101
|
+
keyboard: "no",
|
|
102
|
+
timezone: "Europe/Oslo",
|
|
103
|
+
hostname: "srv123.gigahost.no",
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Reverse DNS, upgrades, IPs, graphs, ISOs
|
|
107
|
+
await client.updateServerReverse(serverId, { ip_id: 7795, dns: "host.example.com" });
|
|
108
|
+
await client.listServerUpgrades(serverId);
|
|
109
|
+
await client.upgradeServer(serverId, pkgId);
|
|
110
|
+
await client.orderServerIpv4(serverId, "l3");
|
|
111
|
+
await client.getServerPortBits(serverId); // base64 graphs
|
|
112
|
+
await client.getServerPortUpkts(serverId);
|
|
113
|
+
await client.listServerIsos(serverId);
|
|
114
|
+
await client.mountServerIso(serverId, isoId);
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### DNS zones & records
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// Zones
|
|
121
|
+
const zones = await client.listDnsZones();
|
|
122
|
+
await client.createDnsZone({ zone_name: "example.no" });
|
|
123
|
+
await client.deleteDnsZone(zoneId);
|
|
124
|
+
|
|
125
|
+
// Records
|
|
126
|
+
const records = await client.listDnsRecords(zoneId);
|
|
127
|
+
await client.createDnsRecord(zoneId, {
|
|
128
|
+
record_name: "www",
|
|
129
|
+
record_type: "A",
|
|
130
|
+
record_value: "185.125.168.166",
|
|
131
|
+
record_ttl: 3600,
|
|
132
|
+
});
|
|
133
|
+
await client.updateDnsRecord(zoneId, recordId, { record_value: "1.2.3.4" });
|
|
134
|
+
await client.deleteDnsRecord(zoneId, recordId, "www", "A");
|
|
135
|
+
|
|
136
|
+
// .no domain registration & registrant
|
|
137
|
+
const check = await client.dnsCheckDomain("example.no");
|
|
138
|
+
await client.registerDomain({ domain_name: "example.no", registrant_type: "organization", ... });
|
|
139
|
+
const registrant = await client.getDnsRegistrant(zoneId);
|
|
140
|
+
await client.updateDnsRegistrant(zoneId, { ... });
|
|
141
|
+
await client.setDnsAutoRenew(zoneId, 1);
|
|
142
|
+
await client.updateDnsNameservers(zoneId, ["ns1.example.com", "ns2.example.com"]);
|
|
143
|
+
await client.updateDnsRegistrantEmail(zoneId, "new@example.com", true);
|
|
144
|
+
|
|
145
|
+
// Redirects
|
|
146
|
+
await client.listDnsRedirects(zoneId);
|
|
147
|
+
await client.createDnsRedirect(zoneId, { source: "@", target_url: "https://www.example.com" });
|
|
148
|
+
await client.updateDnsRedirect(zoneId, "@", "https://new.example.com");
|
|
149
|
+
await client.deleteDnsRedirect(zoneId, "@");
|
|
150
|
+
|
|
151
|
+
// DNSSEC, DS records, PTR
|
|
152
|
+
await client.getDnsDsRecords(zoneId);
|
|
153
|
+
await client.setDnsDnssec(zoneId, 1);
|
|
154
|
+
await client.createDnsPtrZone({ prefix: "185.181.63", ip_version: "ipv4", zone_name: "63.181.185.in-addr.arpa" });
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### BGP
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const bgp = await client.getBgp(); // { asn, prefix_lists, sessions }
|
|
161
|
+
await client.submitBgpAsn("212345");
|
|
162
|
+
await client.createBgpSession(asnId, { redundant: 1, defaultroute: 1, ip_id_v4: "7795", ip_id_v6: "7796" });
|
|
163
|
+
await client.deleteBgpSession(sessionId);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Account & invoices
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
const account = await client.getAccount();
|
|
170
|
+
const invoices = await client.listInvoices();
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Lookup helpers
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
const org = await client.dnsLookupOrganization("123456789"); // Brønnøysund
|
|
177
|
+
const domainCheck = await client.dnsCheckDomain("example.no");
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Error handling
|
|
181
|
+
|
|
182
|
+
All API errors throw `GigahostError` with `status`, `body`, and optional `messageFromApi`:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { GigahostClient, GigahostError } from "@villdyr/gigahost-js";
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
await client.getServer(999);
|
|
189
|
+
} catch (err) {
|
|
190
|
+
if (err instanceof GigahostError) {
|
|
191
|
+
console.error(err.status);
|
|
192
|
+
console.error(err.messageFromApi);
|
|
193
|
+
console.error(err.body);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## TypeScript
|
|
199
|
+
|
|
200
|
+
Types are exported for use in your code:
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import type {
|
|
204
|
+
Server,
|
|
205
|
+
DnsZone,
|
|
206
|
+
DnsRecord,
|
|
207
|
+
BgpData,
|
|
208
|
+
Account,
|
|
209
|
+
Invoice,
|
|
210
|
+
GigahostClientOptions,
|
|
211
|
+
} from "@villdyr/gigahost-js";
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## License
|
|
215
|
+
|
|
216
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.GigahostClient = exports.GigahostError = void 0;
|
|
24
|
+
const DEFAULT_BASE_URL = "https://api.gigahost.no/api/v0";
|
|
25
|
+
class GigahostError extends Error {
|
|
26
|
+
constructor(message, status, body, messageFromApi) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = "GigahostError";
|
|
29
|
+
this.status = status;
|
|
30
|
+
this.body = body;
|
|
31
|
+
this.messageFromApi = messageFromApi;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.GigahostError = GigahostError;
|
|
35
|
+
class GigahostClient {
|
|
36
|
+
constructor(options) {
|
|
37
|
+
var _a;
|
|
38
|
+
this.baseUrl = (_a = options.baseUrl) !== null && _a !== void 0 ? _a : DEFAULT_BASE_URL;
|
|
39
|
+
if ("token" in options) {
|
|
40
|
+
if (!options.token)
|
|
41
|
+
throw new Error("token is required");
|
|
42
|
+
this.token = options.token;
|
|
43
|
+
this.credentials = undefined;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
if (!options.username || !options.password)
|
|
47
|
+
throw new Error("username and password are required");
|
|
48
|
+
this.token = null;
|
|
49
|
+
this.credentials = {
|
|
50
|
+
username: options.username,
|
|
51
|
+
password: options.password,
|
|
52
|
+
code: options.code,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
authenticate(params) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const body = params !== null && params !== void 0 ? params : this.credentials;
|
|
59
|
+
if (!(body === null || body === void 0 ? void 0 : body.username) || !(body === null || body === void 0 ? void 0 : body.password)) {
|
|
60
|
+
throw new Error("Authenticate requires username and password (pass params or use credential-based constructor)");
|
|
61
|
+
}
|
|
62
|
+
const payload = {
|
|
63
|
+
username: body.username,
|
|
64
|
+
password: body.password,
|
|
65
|
+
};
|
|
66
|
+
if (body.code !== undefined)
|
|
67
|
+
payload.code = body.code;
|
|
68
|
+
const res = yield this.requestRaw("POST", "/authenticate", { body: payload });
|
|
69
|
+
const data = res.data;
|
|
70
|
+
if (data === null || data === void 0 ? void 0 : data.token) {
|
|
71
|
+
this.token = data.token;
|
|
72
|
+
}
|
|
73
|
+
if (!data)
|
|
74
|
+
throw new GigahostError("Authentication failed", 401, res);
|
|
75
|
+
return data;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
ensureToken() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
if (this.token)
|
|
81
|
+
return this.token;
|
|
82
|
+
if (this.credentials) {
|
|
83
|
+
yield this.authenticate();
|
|
84
|
+
return this.token;
|
|
85
|
+
}
|
|
86
|
+
throw new Error("No token available. Use token in constructor or call authenticate() with credentials.");
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
requestRaw(method, path, options) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
var _a;
|
|
92
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
93
|
+
if (options === null || options === void 0 ? void 0 : options.params) {
|
|
94
|
+
for (const [key, value] of Object.entries(options.params)) {
|
|
95
|
+
if (value !== undefined)
|
|
96
|
+
url.searchParams.set(key, value);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const headers = {};
|
|
100
|
+
if (path !== "/authenticate") {
|
|
101
|
+
headers["Authorization"] = `Bearer ${yield this.ensureToken()}`;
|
|
102
|
+
}
|
|
103
|
+
if ((options === null || options === void 0 ? void 0 : options.body) !== undefined) {
|
|
104
|
+
headers["Content-Type"] = "application/json";
|
|
105
|
+
}
|
|
106
|
+
const response = yield fetch(url.toString(), Object.assign({ method,
|
|
107
|
+
headers }, ((options === null || options === void 0 ? void 0 : options.body) !== undefined ? { body: JSON.stringify(options.body) } : {})));
|
|
108
|
+
let body;
|
|
109
|
+
try {
|
|
110
|
+
const text = yield response.text();
|
|
111
|
+
body = text ? JSON.parse(text) : undefined;
|
|
112
|
+
}
|
|
113
|
+
catch (_b) {
|
|
114
|
+
body = undefined;
|
|
115
|
+
}
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
const apiBody = body;
|
|
118
|
+
throw new GigahostError(`Gigahost API error: ${response.status} ${response.statusText}`, response.status, body, (_a = apiBody === null || apiBody === void 0 ? void 0 : apiBody.meta) === null || _a === void 0 ? void 0 : _a.message);
|
|
119
|
+
}
|
|
120
|
+
return (body !== null && body !== void 0 ? body : undefined);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
request(method, path, options) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const res = yield this.requestRaw(method, path, options);
|
|
126
|
+
const typed = res;
|
|
127
|
+
if ((typed === null || typed === void 0 ? void 0 : typed.data) !== undefined)
|
|
128
|
+
return typed.data;
|
|
129
|
+
return undefined;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
requestWithMeta(method, path, options) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
return this.requestRaw(method, path, options);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
getBgp() {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
return this.request("GET", "/bgp");
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
submitBgpAsn(asn) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const normalized = typeof asn === "string" && asn.toUpperCase().startsWith("AS") ? asn : String(asn);
|
|
145
|
+
yield this.requestWithMeta("POST", "/bgp/asn", { body: { asn: normalized } });
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
createBgpSession(asnId, params) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
yield this.requestWithMeta("POST", `/bgp/${asnId}/session`, { body: params });
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
deleteBgpSession(sessionId) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
yield this.requestWithMeta("DELETE", `/bgp/${sessionId}/session`);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
dnsLookupOrganization(orgNumber) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
return this.request("GET", `/dns/lookup/organization/${encodeURIComponent(orgNumber)}`);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
dnsCheckDomain(domain) {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
return this.request("GET", `/dns/domains/check/${encodeURIComponent(domain)}`);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
listDnsZones() {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
return this.request("GET", "/dns/zones");
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
listDnsRecords(zoneId) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
return this.request("GET", `/dns/zones/${zoneId}/records`);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
getDnsRegistrant(zoneId) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
return this.request("GET", `/dns/zones/${zoneId}/registrant`);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
registerDomain(params) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
return this.request("POST", "/dns/domains/register", { body: params });
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
createDnsZone(params) {
|
|
189
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
190
|
+
return this.request("POST", "/dns/zones", { body: params });
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
createDnsRecord(zoneId, params) {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
yield this.requestWithMeta("POST", `/dns/zones/${zoneId}/records`, { body: params });
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
updateDnsRecord(zoneId, recordId, params) {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
+
yield this.requestWithMeta("PUT", `/dns/zones/${zoneId}/records/${recordId}`, { body: params });
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
updateDnsRegistrant(zoneId, params) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
yield this.requestWithMeta("PUT", `/dns/zones/${zoneId}/registrant`, { body: params });
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
setDnsAutoRenew(zoneId, autoRenew) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
yield this.requestWithMeta("PUT", `/dns/zones/${zoneId}/auto-renew`, { body: { auto_renew: autoRenew } });
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
updateDnsNameservers(zoneId, nameservers) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
yield this.requestWithMeta("PUT", `/dns/zones/${zoneId}/nameservers`, { body: { nameservers } });
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
deleteDnsZone(zoneId) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
yield this.requestWithMeta("DELETE", `/dns/zones/${zoneId}`);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
deleteDnsRecord(zoneId, recordId, name, type) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
yield this.requestWithMeta("DELETE", `/dns/zones/${zoneId}/records/${recordId}`, {
|
|
226
|
+
params: { name, type },
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
getDnsDsRecords(zoneId) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
return this.request("GET", `/dns/zones/${zoneId}/ds-records`);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
getDnsDsRecordsExternal(zoneId) {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
return this.request("GET", `/dns/zones/${zoneId}/ds-records/external`);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
createDnsPtrZone(params) {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
return this.request("POST", "/dns/zones/ptr", { body: params });
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
submitDnsDsRecordsExternal(zoneId, dsRecords) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
yield this.requestWithMeta("POST", `/dns/zones/${zoneId}/ds-records/external`, { body: { ds_records: dsRecords } });
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
setDnsDnssec(zoneId, enable) {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
252
|
+
yield this.requestWithMeta("PUT", `/dns/zones/${zoneId}/dnssec`, { body: { enable } });
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
listDnsRedirects(zoneId) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
return this.request("GET", `/dns/zones/${zoneId}/redirect`);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
createDnsRedirect(zoneId, params) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
yield this.requestWithMeta("POST", `/dns/zones/${zoneId}/redirect`, { body: params });
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
updateDnsRedirect(zoneId, source, targetUrl) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
yield this.requestWithMeta("PUT", `/dns/zones/${zoneId}/redirect`, { body: { source, target_url: targetUrl } });
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
deleteDnsRedirect(zoneId, source) {
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
yield this.requestWithMeta("DELETE", `/dns/zones/${zoneId}/redirect`, { params: { source } });
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
updateDnsRegistrantEmail(zoneId, email, enableProtection) {
|
|
276
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
+
yield this.requestWithMeta("PUT", `/dns/zones/${zoneId}/registrant-email`, {
|
|
278
|
+
body: { email, enable_protection: enableProtection !== null && enableProtection !== void 0 ? enableProtection : false },
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
listServers() {
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
return this.request("GET", "/servers");
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
getServer(serverId) {
|
|
288
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
289
|
+
const data = yield this.request("GET", `/servers/${serverId}`);
|
|
290
|
+
return Array.isArray(data) ? data[0] : data;
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
updateServerName(serverId, name) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
yield this.requestWithMeta("PUT", `/servers/${serverId}/name`, { body: { name } });
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
createServerIpmiSession(serverId, acl) {
|
|
299
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
const res = yield this.request("POST", `/servers/${serverId}/ipmi`, { body: { acl } });
|
|
301
|
+
return res;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
getServerPowerState(serverId) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
const res = yield this.requestRaw("GET", `/servers/${serverId}/powerstate`);
|
|
307
|
+
return { powerstate: res.powerstate, timestamp: res.timestamp };
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
rebootServer(serverId) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
+
yield this.request("GET", `/servers/${serverId}/reboot`);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
powerOnServer(serverId) {
|
|
316
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
yield this.request("GET", `/servers/${serverId}/power/on`);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
powerOffServer(serverId) {
|
|
321
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
322
|
+
yield this.request("GET", `/servers/${serverId}/power/off`);
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
listServerSnapshots(serverId) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
+
return this.request("GET", `/servers/${serverId}/snapshots`);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
createServerSnapshot(serverId, name) {
|
|
331
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
332
|
+
yield this.requestWithMeta("POST", `/servers/${serverId}/snapshot`, { body: { name } });
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
deleteServerSnapshot(serverId, snapId) {
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
yield this.requestWithMeta("DELETE", `/servers/${serverId}/snapshot/${snapId}`);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
getServerPortBits(serverId) {
|
|
341
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
return this.request("GET", `/servers/${serverId}/port_bits`);
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
getServerPortUpkts(serverId) {
|
|
346
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
347
|
+
return this.request("GET", `/servers/${serverId}/port_upkts`);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
listReinstallDistros() {
|
|
351
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
352
|
+
return this.request("GET", "/reinstall/distro");
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
listReinstallOs(distroId) {
|
|
356
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
357
|
+
return this.request("GET", `/reinstall/distro/${distroId}`);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
reinstallServer(serverId, params) {
|
|
361
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
362
|
+
const res = yield this.requestRaw("POST", `/servers/${serverId}/reinstall`, { body: params });
|
|
363
|
+
const meta = res;
|
|
364
|
+
return { message: meta.message, reboot: meta.reboot, root_passwd: meta.root_passwd };
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
updateServerReverse(serverId, params) {
|
|
368
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
369
|
+
yield this.requestWithMeta("PUT", `/servers/${serverId}/reverse`, { body: params });
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
listServerIsos(serverId) {
|
|
373
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
374
|
+
return this.request("GET", `/servers/${serverId}/isos`);
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
mountServerIso(serverId, isoId) {
|
|
378
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
379
|
+
yield this.requestWithMeta("POST", `/servers/${serverId}/isos`, { body: { iso_id: isoId } });
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
listServerUpgrades(serverId) {
|
|
383
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
384
|
+
return this.request("GET", `/servers/${serverId}/upgrade`);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
upgradeServer(serverId, pkgId) {
|
|
388
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
389
|
+
yield this.requestWithMeta("POST", `/servers/${serverId}/upgrade`, { body: { pkg_id: pkgId } });
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
orderServerIpv4(serverId, ipType) {
|
|
393
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
394
|
+
yield this.requestWithMeta("POST", `/servers/${serverId}/ipv4`, { body: { ip_type: ipType } });
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
getAccount() {
|
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
const res = yield this.requestRaw("GET", "/my/account");
|
|
400
|
+
const _a = res, { success: _s } = _a, account = __rest(_a, ["success"]);
|
|
401
|
+
return account;
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
listInvoices() {
|
|
405
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
406
|
+
var _a;
|
|
407
|
+
const res = yield this.requestRaw("GET", "/my/invoices");
|
|
408
|
+
return (_a = res.invoices) !== null && _a !== void 0 ? _a : [];
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
exports.GigahostClient = GigahostClient;
|