minehut-ts
Version:
Incomplete minehut library
446 lines (445 loc) • 12.2 kB
TypeScript
/**
* Login information about the logged in user.
*/
export interface LoginInfo {
userId: string;
servers: Array<string>;
authorization: string;
xSessionId: string;
slgSessionId: string;
xSlgUser: string;
}
interface unownedServer {
id: string;
online: boolean;
name: string;
maxPlayers: number;
playerCount: number;
serverPlan: string;
status: string;
startedAt: number;
}
/**
* Minehut user representation.
*/
export interface User {
servers: string[];
serverOrder: string[];
maxServers: number;
flags: string[];
id: string;
email: string;
emailVerified: boolean;
emailSentAt: number;
createdAt: Date;
birthday: string;
__v: number;
email_code: string;
lastPasswordChange: Date;
lastLogin: Date;
slgShadowProfileId: string;
minecraftLinkCode: any;
minecraftLastLinkTime: Date;
minecraftName: string;
minecraftUuid: string;
slgProfileId: string;
credits: number;
}
/**
* Gets user info
*
* @param userId Current user id
*/
export declare function getUserInfo(userId: string): Promise<User>;
/**
* This method is intended to be used when you have another login system implemented.
* Just updates internal variables then returns the argument.
*
* @param {LoginInfo} login Login information
* @returns The login argument.
*/
export declare function _altLogin(login: LoginInfo): LoginInfo;
/**
* @param {string} name Name of the server you want to create.
*
* @returns {Promise<Server>}
*/
export declare function createServer(name: string): Promise<Server>;
/**
* Get All Servers
*
* @returns {Promise<Array<Object>>} Array of servers
*/
export declare function getAllServers(): Promise<Array<unownedServer>>;
/**
* Read files from minehut.
*
* @param {Server|string} server Server id or Server object
* @param {string} path File path you want to read.
*
* @returns {Promise<string>}
*/
export declare function readFile(server: Server | string, path: string): Promise<string>;
/**
* Same as fetchServers() but returns a single server instead of an array.
*
* @param {string} serverName Name of the server to fetch.
*
* @returns {Promise<Server>}
*/
export declare function fetchServer(serverName: string): Promise<Server>;
export declare class FileInfo {
blocked: boolean;
directory: boolean;
name: string;
server: Server;
content?: string;
path: string;
constructor(file: {
name: string;
directory: boolean;
blocked: boolean;
size: number;
}, server: Server | string, path: string);
fetch(): Promise<string>;
delete(): Promise<unknown>;
}
/**
* Lists the given directory.
*
* @param {Server|string} server The server that the directory will be listed from. Can be Server object or server id as a string.
* @param {string} path Directory that will be listed. (root is /)
*
* @returns {Promise<File[]>}
*/
export declare function listDir(server: Server | string, path: string): Promise<FileInfo[]>;
/**
* Uploads your file to minehut
*
* @param {Server|string} The ServerID
* @param {string} the filename
* @param {object} File in binary
*
* @returns {Promise<void>}
*/
export declare function uploadFile(server: Server | string, filename: string, file: object): Promise<void>;
/**
* Fetches all servers available to the currently logged in user.
*
* @returns {Promise<Array<Server>>}
*/
export declare function fetchServers(): Promise<Array<Server>>;
export declare class Server {
id: string;
activePlugins: Array<string>;
activeServerPlan: string;
activeServerPlanDetails: {
adFree: boolean;
alwaysOnline: boolean;
backupSlots: number;
chargeInterval: number;
cost: number;
id: string;
index: number;
maxPlayers: number;
maxPlugins: number;
planName: string;
};
backupSlots: number;
categories: Array<string>;
created: Date;
creditsPerDay: number;
exited: boolean;
hibernationPrepStartTime: number;
installedContentPacks: [];
lastOnline: Date;
maxPlayers: number;
maxRam: number;
metrics: {};
motd: string;
name: string;
lowerName: string;
online: boolean;
owner: string;
platform: string;
playerCount: number;
players: [];
port: number;
purchasedIcons: [];
purchasedPlugins: [];
serverIp: string;
serverPlan: string;
serverPlanDetails: {
adFree: boolean;
alwaysOnline: boolean;
backupSlots: number;
chargeInterval: number;
cost: number;
id: string;
index: number;
maxPlayers: number;
maxPlugins: number;
planName: string;
};
serverPort: number;
serverProperites: {
allow_flight: boolean;
allow_nether: boolean;
announce_player_achievements: boolean;
difficulty: number;
enable_command_block: boolean;
force_gamemode: boolean;
gamemode: number;
generate_structures: boolean;
generator_settings: string;
hardcore: boolean;
level_name: string;
level_seed: string;
level_type: string;
max_players: number;
pvp: boolean;
resource_pack: string;
resource_pack_sha1: string;
spawn_animals: boolean;
spawn_mobs: boolean;
spawn_protection: number;
view_distance: number;
};
serviceOnline: boolean;
shutdownReason: string;
shutdownScheduled: boolean;
startedAt: number;
starting: boolean;
status: string;
stoppedAt: number;
stopping: boolean;
storageNode: string;
suspended: boolean;
timeNoPlayers: number;
visiblity: boolean;
constructor(server: any);
/**
* Starts the server.
*
* @returns Promise<void>
*/
start(): Promise<void>;
/**
* Hibernate the server.
*
* @returns Promise<void>
*/
hibernate(): Promise<void>;
/**
* Stop the server.
*
* @returns Promise<void>
*/
stop(): Promise<void>;
/**
* Restart the server.
* @returns Promise<void>
*/
restart(): Promise<void>;
/**
* Change the visibility of the server.
*
* @param {boolean} state Whether the server is visible or not.
* @returns Promise<void>
*/
changeVisibility(state: boolean): Promise<void>;
/**
* Send console command to server.
*
* @param {string} command Console command that will be executed.
* @returns Promise<void>
*/
sendServerCommand(command: string): Promise<void>;
/**
* Change the name of the server.
*
* @param {string} name The new name of the server.
* @returns Promise<void>
*/
changeName(name: string): Promise<void>;
/**
* Change server.properties
*
* @param {string} field Field to change.
* @param {string} value The value it should be.
* @returns Promise
*/
changeServerProperty(field: string, value: string): Promise<void>;
/**
* Install a plugin to the server.
*
* @param {string} plugin Plugin id.
* @returns Promise<void>
* @deprecated Plugin installing through the Server object is deprecated. Install through a Plugin object instead.
*/
installPlugin(plugin: string): Promise<void>;
/**
* Save the world of the server.
* @returns Promise<void>
*/
saveWorld(): Promise<void>;
/**
* Reset the world of the server.
* @returns Promise<void>
*/
resetWorld(): Promise<void>;
/**
* List available backups.
*
* @returns Promise<{backups: Array<Backup>, rollingBackup: RollingBackup}>
*/
listBackups(): Promise<BackupResponse>;
getPlugins(): Promise<Plugin[]>;
createFile(path: string, content?: string): Promise<FileInfo>;
}
interface BackupResponse {
backups: Array<Backup>;
rollingBackup: RollingBackup;
}
declare class Backup {
id: string;
content: {};
dataRemoved: boolean;
deleted: boolean;
description: string;
disabled: boolean;
lastBackupTime: Date;
pending: boolean;
serverId: string;
serverModelSnapshot: {
id: string;
activeIcon: string;
activePlugins: Array<string>;
backupSlots: number;
categories: [];
creation: Date;
creditsPerDay: number;
installedContentPacks: [];
key: string;
lastOnline: Date;
motd: string;
name: string;
lowerName: string;
owner: string;
platform: 'java';
port: number;
purchasedIcons: Array<string>;
purchasedPlugins: [];
serverPlan: string;
serverProperites: {
allowFlight: boolean;
allowNether: boolean;
announcePlayerAchievements: boolean;
difficulty: number;
enableCommandBlocks: boolean;
forceGamemode: boolean;
gamemode: number;
generateStructures: boolean;
generatorSettings: string;
hardcore: boolean;
levelName: string;
levelSeed: string;
levelType: string;
maxPlayers: number;
pvp: boolean;
resourcePack: string;
resourcePackSha1: string;
spawnAnimals: boolean;
spawnMobs: boolean;
spawnProtection: number;
viewDistance: number;
};
storageNode: string;
suspended: boolean;
visibility: boolean;
};
constructor(backup: any);
/**
* Restore this backup.
*
* @returns Promise
*/
restore(): Promise<void>;
}
declare class RollingBackup {
id: string;
etag: string;
lastBackupTime: string;
lastModified: string;
metaData: {
"content-type": "application/octet-stream";
mtime: string;
};
constructor(backup: any);
}
declare class Plugin {
id: string;
created: Date;
credits: number;
description: string;
extendedDescription: string;
disabled: boolean;
fileName: string;
htmlExtendedDesc: string;
lastUpdated: Date;
name: string;
version: string;
constructor(plugin: any);
/**
* Install this plugin to a server.
* @param {Server|string} server Server to install this plugin to.
* @returns Promise<void>
*/
install(server: Server | string): Promise<void>;
/**
* Uninstall this plugin from a server.
* @param {Server|string} server Server to uninstall the plugin from.
* @returns Promise<void>
*/
uninstall(server: Server | string): Promise<void>;
/**
* Reset plugin configurations.
*
* @param {Server|string} server The server the plugin data will be deleted from.
* @returns Promise<void>
*/
resetPlugin(server: Server | string): Promise<void>;
isInstalled(server: Server): boolean;
}
/**
* Fetch all plugins publicly available from Minehut
*
* @returns {Promise<Array<Plugin>>} Resolves to array of Plugin objects.
*/
export declare function getPublicPlugins(): Promise<Array<Plugin>>;
/**
* Login with a HAR file. Designed to be used when Minetron is not available.
*
* @param {string} file The HAR file as a string.
* @returns {loginObject} Login object
*/
export declare function harLogin(file: string): Promise<LoginInfo>;
/**
* @typedef {Object} loginObject
*
* @property {string} userId Minehut user id
* @property {Array<string>} servers Array of server id's
* @property {string} authorization Authorization token
* @property {string} xSessionId Current session id (minehut)
* @property {string} slgSessionId Current session id (superleauge)
* @property {string} xSlgUser Superleague user id
*/
/**
* Login with minetron. Recommended form of login.
*
* @see https://github.com/MrEnxo/minetron-server
* @param {string} token Minetron login token.
* @returns {loginObject} Login object
*/
export declare function minetronLogin(token: string): Promise<LoginInfo>;
export {};