fnbr
Version:
A library to interact with Epic Games' Fortnite HTTP and XMPP services
80 lines • 3.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const Base_1 = tslib_1.__importDefault(require("../Base"));
const UserNotFoundError_1 = tslib_1.__importDefault(require("../exceptions/UserNotFoundError"));
const Endpoints_1 = tslib_1.__importDefault(require("../../resources/Endpoints"));
const enums_1 = require("../../resources/enums");
const EpicgamesAPIError_1 = tslib_1.__importDefault(require("../exceptions/EpicgamesAPIError"));
const STWProfile_1 = tslib_1.__importDefault(require("../structures/stw/STWProfile"));
const STWNewsMessage_1 = tslib_1.__importDefault(require("../structures/stw/STWNewsMessage"));
/**
* Represents the client's STW manager
*/
class STWManager extends Base_1.default {
/**
* Fetches the Save The World profile for a players
* @param user The id or display name of the user
* @throws {UserNotFoundError} The user wasn't found
* @throws {EpicgamesAPIError}
*/
async getProfile(user) {
const resolvedUser = await this.client.user.fetch(user);
if (!resolvedUser)
throw new UserNotFoundError_1.default(user);
let queryProfileResponse;
try {
queryProfileResponse = await this.client.http.epicgamesRequest({
method: 'POST',
url: `${Endpoints_1.default.MCP}/${resolvedUser.id}/public/QueryPublicProfile?profileId=campaign`,
headers: {
'Content-Type': 'application/json',
},
data: {},
}, enums_1.AuthSessionStoreKey.Fortnite);
}
catch (e) {
if (e instanceof EpicgamesAPIError_1.default && e.code === 'errors.com.epicgames.modules.profiles.profile_not_found') {
throw new UserNotFoundError_1.default(user);
}
throw e;
}
return new STWProfile_1.default(this.client, queryProfileResponse.profileChanges[0].profile, resolvedUser);
}
/**
* Fetches the current Save The World news
* @param language The language of the news
* @throws {EpicgamesAPIError}
*/
async getNews(language = this.client.config.language) {
const newsResponse = await this.client.http.epicgamesRequest({
method: 'GET',
url: `${Endpoints_1.default.BR_NEWS}/savetheworldnews?lang=${language}`,
headers: {
'Accept-Language': language,
},
}, enums_1.AuthSessionStoreKey.Fortnite);
return newsResponse.news.messages.map((m) => new STWNewsMessage_1.default(this.client, m));
}
/**
* Fetches the current Save The World world info
* @param language The language of the world info
* @throws {EpicgamesAPIError}
*/
async getWorldInfo(language = this.client.config.language) {
const worldInfoResponse = await this.client.http.epicgamesRequest({
method: 'GET',
url: Endpoints_1.default.STW_WORLD_INFO,
headers: {
'Accept-Language': language,
},
}, enums_1.AuthSessionStoreKey.Fortnite);
return {
theaters: worldInfoResponse.theaters,
missions: worldInfoResponse.missions,
missionAlerts: worldInfoResponse.missionAlerts,
};
}
}
exports.default = STWManager;
//# sourceMappingURL=STWManager.js.map