UNPKG

jspteroapi

Version:

A pterodactyl v1 api using undici

156 lines (155 loc) 5.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Application = void 0; const Request_1 = require("../modules/Request"); const allocation_1 = require("./methods/allocation"); const database_1 = require("./methods/database"); const nest_1 = require("./methods/nest"); const node_1 = require("./methods/node"); const server_1 = require("./methods/server"); const user_1 = require("./methods/user"); const location_1 = require("./methods/location"); const Error_1 = require("../modules/Error"); class Application { host; key; errorHandler; /** * @param host - Panels address * @param key - Api key to use * @param fast - Fast login (No credential check) */ constructor(host, key, errorHandler = (error) => { throw error; }, fast = false) { this.host = host; this.key = key; this.errorHandler = errorHandler; host = host.trim(); if (host.endsWith('/')) host = host.slice(0, -1); this.host = host; this.request = new Request_1.Request(this.host, this.key, this.errorHandler).request; const servermethods = new server_1.serverMethods(this); this.getAllServers = servermethods.getAllServers; this.getServerInfo = servermethods.getServerInfo; this.createServer = servermethods.createServer; this.deleteServer = servermethods.deleteServer; this.suspendServer = servermethods.suspendServer; this.unSuspendServer = servermethods.unSuspendServer; this.reinstallServer = servermethods.reinstallServer; this.getServerInfoByExtId = servermethods.getServerInfoByExtId; this.editServerDetails = servermethods.editServerDetails; this.editServerBuild = servermethods.editServerBuild; this.editServerStartup = servermethods.editServerStartup; const nestmethods = new nest_1.nestMethods(this); this.getAllNests = nestmethods.getAllNests; this.getNestInfo = nestmethods.getNestInfo; this.getAllNestEggs = nestmethods.getAllNestEggs; this.getEggInfo = nestmethods.getEggInfo; const databasemethods = new database_1.databaseMethods(this); this.getServersDatabases = databasemethods.getServersDatabases; this.getServersDatabaseInfo = databasemethods.getServersDatabaseInfo; this.createDatabase = databasemethods.createDatabase; this.resetDatabasePassword = databasemethods.resetDatabasePassword; this.deleteDatabase = databasemethods.deleteDatabase; const usermethods = new user_1.userMethods(this); this.getAllUsers = usermethods.getAllUsers; this.getUserInfo = usermethods.getUserInfo; this.createUser = usermethods.createUser; this.editUser = usermethods.editUser; this.deleteUser = usermethods.deleteUser; const nodemethods = new node_1.nodeMethods(this); this.getAllNodes = nodemethods.getAllNodes; this.getNodeInfo = nodemethods.getNodeInfo; this.getNodeConfig = nodemethods.getNodeConfig; this.createNode = nodemethods.createNode; this.editNode = nodemethods.editNode; this.deleteNode = nodemethods.deleteNode; const allocationmethods = new allocation_1.allocationMethods(this); this.getAllAllocations = allocationmethods.getAllAllocations; this.createAllocation = allocationmethods.createAllocation; this.deleteAllocation = allocationmethods.deleteAllocation; const locationmethods = new location_1.locationMethods(this); this.getAllLocations = locationmethods.getAllLocations; this.getLocationInfo = locationmethods.getLocationInfo; this.createLocation = locationmethods.createLocation; this.editLocation = locationmethods.editLocation; this.deleteLocation = locationmethods.deleteLocation; if (!fast) this.testAPI(); } /** * @param throwError - Whether to throw an error or return bool * @remarks Will not work if using custom error handler. */ testAPI = async (throwError = true) => { try { await this.getAllServers(); return true; } catch (e) { if (e instanceof Error_1.JSPteroAPIError) { if (throwError) { if (e.HTML_STATUS === 403) e.ERRORS = ['Invalid Application API key']; throw e; } return false; } else { if (throwError) throw e; return false; } } }; /** @internal */ request; // GET getAllServers; getAllNodes; getAllUsers; getUserInfo; getNodeInfo; getServerInfo; getAllNests; getNestInfo; getAllNestEggs; getEggInfo; getServerInfoByExtId; getServersDatabases; getServersDatabaseInfo; getNodeConfig; getAllAllocations; getAllLocations; getLocationInfo; // POST createUser; createServer; createNode; createDatabase; suspendServer; unSuspendServer; reinstallServer; resetDatabasePassword; createAllocation; createLocation; // PATCH editUser; editServerDetails; editServerBuild; editServerStartup; editNode; editLocation; // DELETE deleteUser; deleteNode; deleteServer; deleteDatabase; deleteAllocation; deleteLocation; } exports.Application = Application;