@urixen/ptero-connect
Version:
The only package you need for Pterodactyl API management.
1,097 lines • 92.2 kB
JavaScript
"use strict";
/**
* @ignore
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClientApi = exports.ServerPermissions = exports.PermissionError = exports.AuthenticationError = exports.ValidationError = exports.PterodactylAPIError = exports.ApplicationApi = void 0;
exports.smallUtility = smallUtility;
function removeTrailingSlash(url) {
return url.endsWith("/") && url.length > 1 ? url.slice(0, -1) : url;
}
/**
* @includeExample ./examples/ApplicationApi.example.ts
*
* @author nehxurai
*/
var ApplicationApi = /** @class */ (function () {
/**
* @param panelUrl - The base URL of the panel API.
* @param apiKey - The API key for authentication.
* @param customHeaders - Optional custom headers to include in requests.
*/
function ApplicationApi(panelUrl, apiKey, customHeaders) {
this.panelUrl = removeTrailingSlash(panelUrl);
this.apiKey = apiKey;
this.customHeaders = customHeaders;
}
ApplicationApi.prototype.getHeaders = function () {
var baseHeaders = {
Accept: "application/json",
Authorization: "Bearer ".concat(this.apiKey),
"Content-Type": "application/json",
};
return __assign(__assign({}, baseHeaders), (this.customHeaders || {}));
};
ApplicationApi.prototype.fetchJson = function (url, options) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fetch(url, options)];
case 1:
response = _a.sent();
if (!response.ok) {
throw new Error("API request failed: ".concat(response.status, ", ").concat(response.statusText));
}
return [2 /*return*/, response.json()];
}
});
});
};
/**
* Get all users from panel
* @includeExample ./examples/getAllUser.example.ts
*/
ApplicationApi.prototype.getAllUser = function () {
return __awaiter(this, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.fetchJson("".concat(this.panelUrl, "/api/application/users"), { headers: this.getHeaders() })];
case 1:
data = _a.sent();
return [2 /*return*/, data.data];
}
});
});
};
/**
* Get a user by email
* @param email User's email
* @includeExample ./examples/getUserByEmail.example.ts
*/
ApplicationApi.prototype.getAUserByEmail = function (email) {
return __awaiter(this, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.fetchJson("".concat(this.panelUrl, "/api/application/users?filter[email]=").concat(encodeURIComponent(email)), { headers: this.getHeaders() })];
case 1:
data = _a.sent();
if (data.data.length === 0)
throw new Error("User with email ".concat(email, " not found."));
return [2 /*return*/, data.data[0]];
}
});
});
};
/**
* Get a user by username
* @param username User's username
* @includeExample ./examples/getAUserByUsername.example.ts
*/
ApplicationApi.prototype.getAUserByUsername = function (username) {
return __awaiter(this, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.fetchJson("".concat(this.panelUrl, "/api/application/users?filter[username]=").concat(encodeURIComponent(username)), { headers: this.getHeaders() })];
case 1:
data = _a.sent();
if (data.data.length === 0)
throw new Error("User with username ".concat(username, " not found."));
return [2 /*return*/, data.data[0]];
}
});
});
};
/**
* Get a user by ID
* @param id User's ID
* @includeExample ./examples/getAUserById.example.ts
*/
ApplicationApi.prototype.getAUserById = function (id) {
return __awaiter(this, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.fetchJson("".concat(this.panelUrl, "/api/application/users/").concat(id), { headers: this.getHeaders() })];
case 1:
data = _a.sent();
return [2 /*return*/, data.data];
}
});
});
};
/**
* Create a new user
* @param user User creation data
* @includeExample ./examples/createAUser.example.ts
*/
ApplicationApi.prototype.createUser = function (user) {
return __awaiter(this, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.fetchJson("".concat(this.panelUrl, "/api/application/users"), {
method: "POST",
headers: this.getHeaders(),
body: JSON.stringify(user),
})];
case 1:
data = _a.sent();
return [2 /*return*/, data.data];
}
});
});
};
/**
* Update a user
* @param id User ID
* @param updates Fields to update
* @includeExample ./examples/updateUser.example.ts
*/
ApplicationApi.prototype.updateUser = function (id, updates) {
return __awaiter(this, void 0, void 0, function () {
var data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.fetchJson("".concat(this.panelUrl, "/api/application/users/").concat(id), {
method: "PATCH",
headers: this.getHeaders(),
body: JSON.stringify(updates),
})];
case 1:
data = _a.sent();
return [2 /*return*/, data.data];
}
});
});
};
/**
* Delete a user by ID
* @param id User ID
* @includeExample ./examples/deleteUser.example.ts
*/
ApplicationApi.prototype.deleteUser = function (id) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/users/").concat(id), {
method: "DELETE",
headers: this.getHeaders(),
})];
case 1:
response = _a.sent();
if (!response.ok) {
throw new Error("Failed to delete user: ".concat(response.status, ", ").concat(response.statusText));
return [2 /*return*/, false];
}
return [2 /*return*/, true];
}
});
});
};
/**
* Get all Servers
* @param filter set a filter
* @param value set value of the filter
*/
ApplicationApi.prototype.getAllServers = function (filter, value) {
return __awaiter(this, void 0, void 0, function () {
var url, response, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
url = this.panelUrl +
"/api/application/servers" +
(filter ? "?filter[".concat(filter, "]=").concat(value) : "");
return [4 /*yield*/, fetch(url, {
method: "GET",
headers: this.getHeaders(),
})];
case 1:
response = _a.sent();
if (!response.ok) {
throw new Error("Failed to fetch all servers: ".concat(response.status, ", ").concat(response.statusText));
}
return [4 /*yield*/, response.json()];
case 2:
data = _a.sent();
return [2 /*return*/, data.data];
}
});
});
};
/**
* Retrieve detailed information about a specific server.
* @param id Server Id
* @param include Include relationships (allocations, user, subusers, pack, nest, egg, variables, location, node, databases, backups)
*/
ApplicationApi.prototype.getAServerById = function (id, include) {
return __awaiter(this, void 0, void 0, function () {
var url, response, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
url = this.panelUrl + "/api/application/servers/".concat(id, "?include=").concat(include);
return [4 /*yield*/, fetch(url, {
method: "GET",
headers: this.getHeaders(),
})];
case 1:
response = _a.sent();
if (!response.ok) {
throw new Error("Failed to fetch server:".concat(response.status, ", ").concat(response.statusText));
}
return [4 /*yield*/, response.json()];
case 2:
data = _a.sent();
return [2 /*return*/, data];
}
});
});
};
/**
* create a server
* @param data - Server Data for creation
*/
ApplicationApi.prototype.createServer = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var url, response, data;
var name = _b.name, user = _b.user, egg = _b.egg, docker_image = _b.docker_image, startup = _b.startup, enviroment = _b.enviroment, limits = _b.limits, feature_limits = _b.feature_limits, allocation = _b.allocation, deploy = _b.deploy;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
url = this.panelUrl + "/api/application/servers/";
return [4 /*yield*/, fetch(url, {
method: "POST",
headers: this.getHeaders(),
body: JSON.stringify({
name: name,
user: user,
egg: egg,
docker_image: docker_image,
startup: startup,
enviroment: enviroment,
limits: limits,
feature_limits: feature_limits,
allocation: allocation,
deploy: deploy,
}),
})];
case 1:
response = _c.sent();
if (!response.ok) {
throw new Error("Error creating server: ".concat(response.status, ", ").concat(response.statusText));
return [2 /*return*/, false];
}
data = response.json();
return [2 /*return*/, { created: true, data: data }];
}
});
});
};
/**
* Updates a server's details via the panel API.
*
* @param id - The ID of the server to update.
* @param updatedData - An object containing the updated server fields.
* @returns The updated server object.
* @throws Will throw an error if the request fails.
*/
ApplicationApi.prototype.updateServerDetails = function (id, updatedData) {
return __awaiter(this, void 0, void 0, function () {
var url, response, errorText, data;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/details");
return [4 /*yield*/, fetch(url, {
method: "PATCH",
headers: this.getHeaders(),
body: JSON.stringify(updatedData),
})];
case 1:
response = _a.sent();
if (!!response.ok) return [3 /*break*/, 3];
return [4 /*yield*/, response.text().catch(function () { return ""; })];
case 2:
errorText = _a.sent();
throw new Error("Unable to update server details: ".concat(response.status, " ").concat(response.statusText, "\n").concat(errorText));
case 3: return [4 /*yield*/, response.json()];
case 4:
data = _a.sent();
return [2 /*return*/, data];
}
});
});
};
/**
* Suspend a server
* @param id Server id
*/
ApplicationApi.prototype.suspendServer = function (id) {
return __awaiter(this, void 0, void 0, function () {
var url, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/suspend");
return [4 /*yield*/, fetch(url, {
method: "POST",
headers: this.getHeaders(),
})];
case 1:
response = _a.sent();
if (!response.ok)
throw new Error("cannot suspend the server: ".concat(response.status));
return [2 /*return*/, true];
}
});
});
};
/**
* Remove suspension from a server to allow it to start.
* @param id Server id
*/
ApplicationApi.prototype.unSuspendServer = function (id) {
return __awaiter(this, void 0, void 0, function () {
var url, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/unsuspend");
return [4 /*yield*/, fetch(url, {
method: "POST",
headers: this.getHeaders(),
})];
case 1:
response = _a.sent();
if (!response.ok)
throw new Error("cannot unsuspend the server: ".concat(response.status));
return [2 /*return*/, true];
}
});
});
};
/**
* Update Server Build Configuration
* Update server resource limits and feature limits.
*
* PATCH /api/application/servers/{server}/build
*
* @param id - Server ID
* @param buildData - Build configuration object
* @returns Updated server object
*/
ApplicationApi.prototype.updateServerBuild = function (id, buildData) {
return __awaiter(this, void 0, void 0, function () {
var url, response, errorText;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/build");
return [4 /*yield*/, fetch(url, {
method: "PATCH",
headers: this.getHeaders(),
body: JSON.stringify(buildData),
})];
case 1:
response = _a.sent();
if (!!response.ok) return [3 /*break*/, 3];
return [4 /*yield*/, response.text().catch(function () { return ""; })];
case 2:
errorText = _a.sent();
throw new Error("Unable to update server build: ".concat(response.status, " ").concat(response.statusText, "\n").concat(errorText));
case 3: return [2 /*return*/, response.json()];
}
});
});
};
/**
* Updates server start up settings
*
* PATCH /api/application/servers/{id}/startup
*
* @param id - Server id
* @param updatedData - updated server start up settings
* @returns updated Server setting data
*/
ApplicationApi.prototype.updateServerStartup = function (id, updatedData) {
return __awaiter(this, void 0, void 0, function () {
var url, res, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/startup");
return [4 /*yield*/, fetch(url, {
method: "PATCH",
headers: this.getHeaders(),
body: JSON.stringify(updatedData),
})];
case 1:
res = _d.sent();
if (!!res.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Error updating startup: ".concat(res.status, ", ")).concat;
return [4 /*yield*/, res.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, res.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
/**
* Reinstall the corresponding server
*
* POST /api/application/servers/{id}/reinstall
*
* @param id - Server Id
* @return boolean
*/
ApplicationApi.prototype.reinstallServer = function (id) {
return __awaiter(this, void 0, void 0, function () {
var url, res;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/reinstall");
return [4 /*yield*/, fetch(url, {
method: "POST",
headers: this.getHeaders(),
})];
case 1:
res = _a.sent();
if (!res.ok)
return [2 /*return*/, false];
return [2 /*return*/, true];
}
});
});
};
/**
* Delete a server
*
* DELETE /api/application/servers/{id}
*
* @param id - server id
* @param force - force delete server (may damage wings)
* @returns boolean
*/
ApplicationApi.prototype.deleteServer = function (id_1) {
return __awaiter(this, arguments, void 0, function (id, force) {
var res;
if (force === void 0) { force = false; }
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/servers/").concat(id, "?force=").concat(force), {
method: "DELETE",
})];
case 1:
res = _a.sent();
if (!res.ok)
return [2 /*return*/, false];
return [2 /*return*/, true];
}
});
});
};
/**
* Manage server databases through the Application API for administrative control.
*/
/**
* get corresponding server databases
*
* GET /api/application/servers/{id}/databases
*
* @param id - server id
* @return server databases
*/
ApplicationApi.prototype.getServerDbs = function (id) {
return __awaiter(this, void 0, void 0, function () {
var url, res, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/databases");
return [4 /*yield*/, fetch(url, {
headers: this.getHeaders(),
})];
case 1:
res = _d.sent();
if (!!res.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "failed to fetch databases for server ".concat(id, ": ").concat(res.status, ", ")).concat;
return [4 /*yield*/, res.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, res.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data.data];
}
});
});
};
/**
* get a server's database details
*
* GET /api/application/servers/{id}/databases/{dbId}
*
* @param id - server id
* @param dbID - database id
* @returns database details
*/
ApplicationApi.prototype.getServerDB = function (id, dbID) {
return __awaiter(this, void 0, void 0, function () {
var url, res, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/databases/").concat(dbID);
return [4 /*yield*/, fetch(url, {
headers: this.getHeaders(),
})];
case 1:
res = _d.sent();
if (!!res.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "failed to fetch database for server ".concat(id, ": ").concat(res.status, ", ")).concat;
return [4 /*yield*/, res.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, res.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
/**
* Create a new database
*
* POST /api/application/servers/{id}/databases
*
* @param id - server id
* @param dataDB - database details
* @returns database
*/
ApplicationApi.prototype.createServerDB = function (id, dataDB) {
return __awaiter(this, void 0, void 0, function () {
var url, res, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/databases");
return [4 /*yield*/, fetch(url, {
headers: this.getHeaders(),
method: "POST",
body: JSON.stringify(dataDB),
})];
case 1:
res = _d.sent();
if (!!res.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "failed to create database for server ".concat(id, ": ").concat(res.status, ", ")).concat;
return [4 /*yield*/, res.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, res.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
/**
* update server database details
*
* PATCH /api/application/servers/{id}/databases/{dbID}
*
* @param id - server id
* @param dbID - database id
* @param dataDB - data to be updated
* @returns database details
*/
ApplicationApi.prototype.updateServerDB = function (id, dbID, dataDB) {
return __awaiter(this, void 0, void 0, function () {
var url, res, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/databases/").concat(dbID);
return [4 /*yield*/, fetch(url, {
headers: this.getHeaders(),
method: "PATCH",
body: JSON.stringify(dataDB),
})];
case 1:
res = _d.sent();
if (!!res.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "failed to update database for server ".concat(id, ": ").concat(res.status, ", ")).concat;
return [4 /*yield*/, res.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, res.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
ApplicationApi.prototype.resetServerDB = function (id, dbID) {
return __awaiter(this, void 0, void 0, function () {
var url, res, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/databases/").concat(dbID, "/reset-password");
return [4 /*yield*/, fetch(url, {
headers: this.getHeaders(),
method: "POST",
})];
case 1:
res = _d.sent();
if (!!res.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "failed to reset database password for server ".concat(id, ": ").concat(res.status, ", ")).concat;
return [4 /*yield*/, res.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, res.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
/**
* delete a database from server
*
* DELETE /api/application/servers/{id}/databases/{dbID}
*
* @param id - server id
* @param dbID - database id
* @returns boolean
*/
ApplicationApi.prototype.deleteServerDB = function (id, dbID) {
return __awaiter(this, void 0, void 0, function () {
var url, res, _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
url = "".concat(this.panelUrl, "/api/application/servers/").concat(id, "/databases/").concat(dbID);
return [4 /*yield*/, fetch(url, {
headers: this.getHeaders(),
method: "DELETE",
})];
case 1:
res = _d.sent();
if (!!res.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "failed to delete database for server ".concat(id, ": ").concat(res.status, ", ")).concat;
return [4 /*yield*/, res.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [2 /*return*/, true];
}
});
});
};
ApplicationApi.prototype.getAllNodes = function () {
return __awaiter(this, arguments, void 0, function (options) {
var params, response, _a, _b, _c, data;
if (options === void 0) { options = {}; }
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
params = new URLSearchParams(options);
return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nodes?").concat(params), {
headers: this.getHeaders(),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to fetch all nodes: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = (_d.sent()).data;
return [2 /*return*/, data];
}
});
});
};
ApplicationApi.prototype.createNode = function (nodeData) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nodes"), {
method: "POST",
headers: this.getHeaders(),
body: JSON.stringify(nodeData),
})];
case 1:
response = _a.sent();
return [4 /*yield*/, response.json()];
case 2: return [2 /*return*/, (_a.sent())];
}
});
});
};
ApplicationApi.prototype.getNodeConfiguration = function (nodeId) {
return __awaiter(this, void 0, void 0, function () {
var response, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nodes/").concat(nodeId, "/configuration"), {
headers: this.getHeaders(),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to fetch node config node: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
ApplicationApi.prototype.getAllAllocation = function (nodeId) {
return __awaiter(this, void 0, void 0, function () {
var response, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nodes/").concat(nodeId, "/allocations"), {
headers: this.getHeaders(),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to fetch node allocations: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = (_d.sent()).data;
return [2 /*return*/, data];
}
});
});
};
ApplicationApi.prototype.createAllocations = function (nodeId, allocationData) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nodes/").concat(nodeId, "/allocations"), {
method: "POST",
headers: this.getHeaders(),
body: JSON.stringify(allocationData),
})];
case 1:
response = _a.sent();
return [2 /*return*/, response.status === 204];
}
});
});
};
ApplicationApi.prototype.deleteNode = function (nodeId) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nodes/").concat(nodeId), {
method: "DELETE",
headers: this.getHeaders(),
})];
case 1:
response = _a.sent();
return [2 /*return*/, response.status === 204];
}
});
});
};
ApplicationApi.prototype.getAllLocations = function () {
return __awaiter(this, arguments, void 0, function (options) {
var params, response, _a, _b, _c, data;
if (options === void 0) { options = {}; }
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
params = new URLSearchParams(options);
return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/locations?").concat(params), {
headers: this.getHeaders(),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to fetch loactions: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = (_d.sent()).data;
return [2 /*return*/, data];
}
});
});
};
ApplicationApi.prototype.createLocation = function (locationData) {
return __awaiter(this, void 0, void 0, function () {
var response, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/locations"), {
method: "POST",
headers: this.getHeaders(),
body: JSON.stringify(locationData),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to create locations: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
ApplicationApi.prototype.updateLocation = function (locationId, updateData) {
return __awaiter(this, void 0, void 0, function () {
var response, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/locations/").concat(locationId), {
method: "PATCH",
headers: this.getHeaders(),
body: JSON.stringify(updateData),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to update location: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
ApplicationApi.prototype.deleteLocation = function (locationId) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/locations/").concat(locationId), {
method: "DELETE",
headers: this.getHeaders(),
})];
case 1:
response = _a.sent();
return [2 /*return*/, response.status === 204];
}
});
});
};
ApplicationApi.prototype.getLocationWithNodes = function (locationId) {
return __awaiter(this, void 0, void 0, function () {
var response, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/locations/").concat(locationId, "?include=nodes"), {
headers: this.getHeaders(),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to fetch location with nodes: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
/**
* get all nests
* @param options - additional options
*/
ApplicationApi.prototype.getAllNests = function () {
return __awaiter(this, arguments, void 0, function (options) {
var params, response, _a, _b, _c, data;
if (options === void 0) { options = {}; }
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
params = new URLSearchParams(options);
return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nests?").concat(params), {
headers: this.getHeaders(),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to fetch nests: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = (_d.sent()).data;
return [2 /*return*/, data];
}
});
});
};
/**
* get a nest
*
* @param nestId - nest id
*/
ApplicationApi.prototype.getANest = function (nestId) {
return __awaiter(this, void 0, void 0, function () {
var response, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nests/").concat(nestId), {
headers: this.getHeaders(),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to fetch nests: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = _d.sent();
return [2 /*return*/, data];
}
});
});
};
/**
* get all eggs
*
* @param nestId - nest id
*/
ApplicationApi.prototype.getAllEggs = function (nestId) {
return __awaiter(this, void 0, void 0, function () {
var response, _a, _b, _c, data;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, fetch("".concat(this.panelUrl, "/api/application/nests/").concat(nestId, "/eggs"), {
headers: this.getHeaders(),
})];
case 1:
response = _d.sent();
if (!!response.ok) return [3 /*break*/, 3];
_a = Error.bind;
_c = (_b = "Failed to fetch nests: ".concat(response.status, ", ")).concat;
return [4 /*yield*/, response.text()];
case 2: throw new (_a.apply(Error, [void 0, _c.apply(_b, [_d.sent()])]))();
case 3: return [4 /*yield*/, response.json()];
case 4:
data = (_d.sent()).data;
return [2 /*return*/, data];
}
});
});
};
/**
* get a egg
*
* @param nestId - nest id
* @param eggId - egg id
*/
ApplicationApi.prototype.getAEg