UNPKG

jspteroapi

Version:

A pterodactyl v1 api using undici

168 lines (167 loc) 5.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.accountMethods = void 0; class accountMethods { client; constructor(client) { this.client = client; } /** * @returns Permission data * @remarks Just returns all available permissions. Not that useful! * @example * ```ts * const res = await client.getPermissions() // res = Permissions * ``` * @example * ```ts * client.getPermissions().then((res) => console.log(res)) // res = Permissions * ``` */ getAllPermissions = async () => { return this.client.request('GET', null, 'attributes', `/api/client/permissions`); }; /** * @returns Account information * @example * ```ts * const res = await client.getAccountInfo() // res = UserAttributes * ``` * @example * ```ts * client.getAccountInfo().then((res) => console.log(res)) // res = UserAttributes * ``` */ getAccountInfo = () => { return this.client.request('GET', null, 'attributes', `/api/client/account`); }; /** * @returns TOTP QR code image url (otpauth) * ```ts * const res = await client.getAccountInfo() // res = string (otpauth) * ``` * @example * ```ts * client.getAccountInfo().then((res) => console.log(res)) // res = string (otpauth) * ``` */ getAccount2FADetails = async () => { return this.client.request('GET', null, 'data.image_url_data', `/api/client/account/two-factor`); }; /** * @param code - The code from authenticator * @returns Tokens * ```ts * const res = await client.enable2FA('505134') // res = string[] (tokens) * ``` * @example * ```ts * client.enable2FA('505134').then((res) => console.log(res)) // res = string[] (tokens) * ``` */ enable2FA = async (code) => { return this.client.request('POST', { code: code }, 'attributes.tokens', `/api/client/account/two-factor`); }; /** * @param password - The code from authenticator * @returns If succesful returns Successfully disable 2FA! * ```ts * const res = await client.disable2FA('securepassword') // res = Successfully disable 2FA! * ``` * @example * ```ts * client.disable2FA('securepassword').then((res) => console.log(res)) // res = Successfully disable 2FA! * ``` */ disable2FA = async (password) => { return this.client.request('DELETE', { password: password }, 'Successfully disable 2FA!', `/api/client/account/two-factor`); }; /** * @param email - The new email address * @param password - The password of the user * @returns If succesful returns Successfully updated email! * ```ts * const res = await client.updateEmail('jspteroapi@linux123123.cf', 'verySecurePass') // res = Successfully updated email! * ``` * @example * ```ts * client.updateEmail('jspteroapi@linux123123.cf', 'verySecurePass').then((res) => console.log(res)) // res = Successfully updated email! * ``` */ updateEmail = async (email, password) => { return this.client.request('PUT', { email: email, password: password }, 'Successfully updated email!', `/api/client/account/email`); }; /** * @param currentPassword - The currect passowrd * @param password - The new password * @returns If succesful returns Successfully updated password! * ```ts * const res = await client.updatePassword('verySecurePass', 'moreSecurePass') // res = Successfully updated password! * ``` * @example * ```ts * client.updatePassword('verySecurePass', 'moreSecurePass').then((res) => console.log(res)) // res = Successfully updated password! * ``` */ updatePassword = async (currentPassword, password) => { return this.client.request('PUT', { current_password: currentPassword, password: password, password_confirmation: password }, 'Successfully updated password!', `/api/client/account/password`); }; /** * @returns Api key array * @example * ```ts * const res = await client.getAllApiKeys() // res = ApiKey[] * ``` * @example * ```ts * client.getAllApiKeys().then((res) => console.log(res)) // res = ApiKey[] * ``` */ getAllApiKeys = async () => { return this.client.request('GET', null, 'data', `/api/client/account/api-keys`); }; /** * @param description - Api key description * @param allowedIps - Array of allowed IP addresses (default empty []) * @returns The new api key information + meta (token) * ```ts * const res = await client.createApiKey('TESTING', []) // res = ApiKey + meta (token) * ``` * @example * ```ts * client.createApiKey('TESTING', []).then((res) => console.log(res)) // res = ApiKey + meta (token) * ``` */ createApiKey = async (description, allowedIps = []) => { return this.client.request('POST', { description: description, allowed_ips: allowedIps }, '', `/api/client/account/api-keys`); }; /** * @param apiKeyIden - The api keys identifier code * @returns If succesful returns Successfully deleted api key! * ```ts * const res = await client.deleteApiKey('NWKMYMT2Mrav0Iq2') // res = Successfully deleted api key! * ``` * @example * ```ts * client.deleteApiKey('NWKMYMT2Mrav0Iq2').then((res) => console.log(res)) // res = Successfully deleted api key! * ``` */ deleteApiKey = async (apiKeyIden) => { return this.client.request('DELETE', null, 'Successfully deleted api key!', `/api/client/account/api-keys/${apiKeyIden}`); }; } exports.accountMethods = accountMethods;