├── .gitignore ├── index.js ├── test ├── index.js ├── util.js ├── endpoints.js ├── fortnite-api.js └── .eslintrc.yml ├── .github └── workflows │ └── node.js.yml ├── lib ├── util.js ├── endpoints-v2.js ├── base-client.js ├── endpoints.js ├── fortnite-api-v2.js └── fortnite-api.js ├── package.json ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | .git 4 | /coverage 5 | /.vscode 6 | /.nyc_output -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @license MIT 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * index.js 13 | * Export the API Class 14 | */ 15 | const FortniteAPI = require("./lib/fortnite-api"); 16 | module.exports = FortniteAPI; 17 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @license MIT 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * test/index.js 13 | * Test Libraries 14 | */ 15 | process.env.testMode = true; 16 | require("./endpoints"); 17 | require("./fortnite-api"); 18 | require("./util"); 19 | process.env.testMode = false; 20 | -------------------------------------------------------------------------------- /test/util.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @license MIT 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * test/util.js 13 | * Test Utilities library 14 | */ 15 | const test = require("tape"); 16 | const util = require("../lib/util"); 17 | 18 | test("test supportsLanguage with supported language", assert => { 19 | assert.plan(1); 20 | const lang = "en"; 21 | assert.true(util.supportsLanguage(lang), "en is supported"); 22 | assert.end(); 23 | }); 24 | 25 | test("test supportsLanguage with unsupported language", assert => { 26 | assert.plan(1); 27 | const lang = "cy"; 28 | assert.false(util.supportsLanguage(lang), "cy (welsh) is not supported"); 29 | assert.end(); 30 | }); 31 | -------------------------------------------------------------------------------- /.github/workflows/node.js.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | strategy: 18 | matrix: 19 | node-version: [12.x, 14.x] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v1 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | - run: npm ci 28 | - run: npm run build --if-present 29 | - run: npm test 30 | -------------------------------------------------------------------------------- /lib/util.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @license MIT 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * util.js 13 | * General utility functions 14 | */ 15 | 16 | /** 17 | * supportsLanguage() 18 | * Checks if supplied language is supported by the API 19 | * 20 | * @param {string} lang 21 | * @returns {boolean} 22 | */ 23 | function supportsLanguage(lang) { 24 | const supportedLanguages = [ 25 | "en", 26 | "ar", 27 | "de", 28 | "es", 29 | "es-419", 30 | "fr", 31 | "it", 32 | "ja", 33 | "ko", 34 | "pl", 35 | "pt-BR", 36 | "ru", 37 | "tr", 38 | "zh-CN", 39 | "zh-Hant" 40 | ]; 41 | return supportedLanguages.includes(lang); 42 | } 43 | 44 | module.exports = { 45 | supportsLanguage 46 | }; 47 | -------------------------------------------------------------------------------- /lib/endpoints-v2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @license MIT 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * endpoints-v2.js 13 | * Exports and builds fortniteapi.io V2 API endpoints 14 | */ 15 | 16 | const endpoint = "https://fortniteapi.io/v2"; 17 | 18 | module.exports = { 19 | listChallenges: (season, lang) => `${endpoint}/challenges?season=${season}&lang=${lang}`, 20 | listItems: lang => `${endpoint}/items/list?lang=${lang}`, 21 | listUpcomingItems: lang => `${endpoint}/items/upcoming?lang=${lang}`, 22 | getItemDetails: (id, lang) => `${endpoint}/items/get?id=${id}&lang=${lang}`, 23 | getDailyShop: lang => `${endpoint}/shop?lang=${lang}`, 24 | getBattlePassRewards: (season, lang) => `${endpoint}/battlepass?lang=${lang}&season=${season}`, 25 | listItemLocations: () => `${endpoint}/maps/items/list`, 26 | listCurrentPOI: lang => `${endpoint}/game/poi?lang=${lang}` 27 | }; 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fortnite-api-io", 3 | "version": "1.9.0", 4 | "description": "Nodejs module for making requests to fortniteapi.io", 5 | "main": "index.js", 6 | "author": "Ben Hawley", 7 | "contributors": [ 8 | "Theo Bontemps" 9 | ], 10 | "license": "MIT", 11 | "scripts": { 12 | "test": "npx tape test", 13 | "test:coverage": "nyc tape test" 14 | }, 15 | "keywords": [ 16 | "fortnite", 17 | "fortnite-api", 18 | "fortnite-api-io" 19 | ], 20 | "bugs": "https://github.com/benhawley7/fortnite-api-io/issues", 21 | "repository": { 22 | "type": "git", 23 | "url": "https://github.com/benhawley7/fortnite-api-io.git" 24 | }, 25 | "files": [ 26 | "index.js", 27 | "lib/**" 28 | ], 29 | "dependencies": { 30 | "node-fetch": "^2.6.0" 31 | }, 32 | "devDependencies": { 33 | "eslint": "^6.8.0", 34 | "nyc": "^15.1.0", 35 | "tape": "^4.13.3" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 benhawley7 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fortnite-api-io 2 | 3 | [![npm version](https://flat.badgen.net/npm/v/fortnite-api-io)](https://www.npmjs.com/package/fortnite-api-io) 4 | ![](https://github.com/benhawley7/fortnite-api-io/workflows/Node.js%20CI/badge.svg) 5 | 6 | Simple Wrapper Module for making API calls to https://fortniteapi.io. 7 | 8 | Go to the [API Docs](https://fortniteapi.io/) to register for an account and to get an API key. 9 | 10 | You can also read the [module docs](https://github.com/benhawley7/fortnite-api-io/wiki) for a list of supported calls. 11 | 12 | ## Install the Module 13 | ```bash 14 | npm install fortnite-api-io 15 | ``` 16 | 17 | ## Require and Instantiate 18 | ```js 19 | const FortniteAPI = require("fortnite-api-io"); 20 | 21 | // Instantiate with API Credentials 22 | const client = new FortniteAPI("credentials-go-here", { 23 | defaultLanguage: 'en', // Optional - will default to 'en' 24 | ignoreWarnings: false // Optional -will default to false 25 | }); 26 | ``` 27 | 28 | ## Example API Calls 29 | The API is currently transitioning into its second version. Where available, it is highly recommended to use the version 2 endpoint. 30 | 31 | ```js 32 | // Get the next upcoming items (version 2) 33 | const upcomingItems = await client.v2.listItems(); 34 | 35 | // Get this season's challenges (version 2) 36 | const challenges = await client.v2.listChallenges("current"); 37 | 38 | // Get all stats for a specific loot/weapon item (version 1) 39 | const loot = await client.getLootDetails(); 40 | ``` 41 | 42 | If you call a version 1 method, when there is an available version 2 method, a warning log will be printed. 43 | The deprecation warnings can be disabled when instantiating the API wrapper. 44 | 45 | ```js 46 | const upcomingItems = await client.listItems(); 47 | // WARNING: listItems has been deprecated - please use FortniteAPI.v2.listItems 48 | ``` 49 | 50 | ## Acknowledgement 51 | Thanks to the devs of https://fortniteapi.io, do consider subscribing on their API Dashboard to support the project and its costs. 52 | 53 | ## License 54 | MIT -------------------------------------------------------------------------------- /test/endpoints.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @license MIT 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * test/util.js 13 | * Test Endpoints Library 14 | */ 15 | 16 | const test = require("tape"); 17 | const endpoints = require("../lib/endpoints"); 18 | 19 | test("all endpoints prefix with correct url", assert => { 20 | const functions = Object.keys(endpoints); 21 | assert.plan(functions.length); 22 | functions.forEach(functionName => { 23 | const uri = endpoints[functionName](); 24 | assert.true(uri.includes("https://fortniteapi.io/"), `${functionName} has correct prefix url`); 25 | }); 26 | assert.end(); 27 | }); 28 | 29 | test("search account by id adds username and platform", assert => { 30 | assert.plan(2); 31 | const uri = endpoints.searchAccountId("ben", "xbl"); 32 | assert.true(uri.includes("?username=ben")); 33 | assert.true(uri.includes("&platform=xbl")); 34 | assert.end(); 35 | }); 36 | 37 | test("search account by id adds username and strict mode false", assert => { 38 | assert.plan(2); 39 | const uri = endpoints.searchAccountId("ben", false, false); 40 | assert.true(uri.includes("?username=ben")); 41 | assert.true(uri.includes("&strict=false")); 42 | assert.end(); 43 | }); 44 | 45 | test("endpoints with lang have &lang={lang}", assert => { 46 | const lang = "en"; 47 | const uris = [ 48 | endpoints.getAchievements(lang), 49 | endpoints.getBattlePassRewards("current", lang), 50 | endpoints.getDailyShop(lang), 51 | endpoints.getItemDetails("test-id", lang), 52 | endpoints.getNews("br", lang), 53 | endpoints.getDailyShop(lang), 54 | endpoints.listChallenges("current", lang), 55 | endpoints.listItems(lang), 56 | endpoints.listUpcomingItems(lang) 57 | ]; 58 | assert.plan(uris.length); 59 | uris.forEach(uri => { 60 | assert.true(uri.includes(`lang=${lang}`), `${uri} has lang`); 61 | }); 62 | assert.end(); 63 | }); 64 | -------------------------------------------------------------------------------- /lib/base-client.js: -------------------------------------------------------------------------------- 1 | const fetch = require("node-fetch"); 2 | const { supportsLanguage } = require("./util"); 3 | 4 | /** 5 | * Implements shared functions used by API versions 6 | */ 7 | class BaseClient { 8 | /** 9 | * constructor() 10 | * 11 | * @param {string} credentials 12 | * @param {object} [config] 13 | * @param {string} [config.defaultLanguage] 14 | */ 15 | constructor(credentials, config = {}) { 16 | if (!credentials) { 17 | throw new Error("Invalid Credentials Supplied."); 18 | } 19 | 20 | this.defaultLang = config.defaultLanguage || "en"; 21 | this.ignoreWarnings = Boolean(config.ignoreWarnings); 22 | this.credentials = credentials; 23 | 24 | if (!supportsLanguage(this.defaultLang)) { 25 | throw new Error( 26 | `Supplied default language ${this.defaultLang} is not supported` 27 | ); 28 | } 29 | } 30 | 31 | /** 32 | * request() 33 | * Use node-fetch to query API 34 | * 35 | * @param {string} uri 36 | * @param {object} [options] 37 | * @param {string} [options.method] 38 | * @returns {Promise} 39 | */ 40 | async request(uri, options = { method: "GET" }) { 41 | // In test mode, return the URI we are about to fetch 42 | if (process.env.testMode) { 43 | return uri; 44 | } 45 | const response = await fetch(uri, { 46 | method: options.method, 47 | headers: { 48 | Authorization: `${this.credentials}`, 49 | }, 50 | }); 51 | 52 | const data = await response.json(); 53 | return data; 54 | } 55 | 56 | /** 57 | * Prints a warning when using deprecated endpoints 58 | * @param {string} oldMethod 59 | * @param {string} newMethod 60 | */ 61 | deprecationWarning(oldMethod, newMethod) { 62 | if (this.ignoreWarnings) return; 63 | console.warn(`WARNING: ${oldMethod} has been deprecated - please use ${newMethod}`) 64 | } 65 | } 66 | 67 | module.exports = BaseClient; -------------------------------------------------------------------------------- /lib/endpoints.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @author Théo Bontemps (maintainer) 7 | * @license MIT 8 | */ 9 | 10 | "use strict"; 11 | 12 | /** 13 | * endpoints.js 14 | * Exports and builds fortniteapi.io API endpoints 15 | */ 16 | 17 | const endpoint = "https://fortniteapi.io/v1"; 18 | module.exports = { 19 | listChallenges: (season, lang) => `${endpoint}/challenges?season=${season}&lang=${lang}`, 20 | listItems: lang => `${endpoint}/items/list?lang=${lang}`, 21 | listUpcomingItems: lang => `${endpoint}/items/upcoming?lang=${lang}`, 22 | getItemDetails: (id, lang) => `${endpoint}/items/get?id=${id}&lang=${lang}`, 23 | getDailyShop: lang => `${endpoint}/shop?lang=${lang}`, 24 | getShopVotingOptions: _ => `${endpoint}/shop/voting`, 25 | searchAccountId: (username, platform, strict = true) => { 26 | let uri = `${endpoint}/lookup?username=${username}`; 27 | if (platform) { 28 | uri += `&platform=${platform}`; 29 | } 30 | if (strict === false) { 31 | uri += `&strict=false`; 32 | } 33 | return uri; 34 | }, 35 | getGlobalPlayerStats: account => `${endpoint}/stats?account=${account}`, 36 | getPlayerRecentMatches: account => `${endpoint}/matches?account=${account}`, 37 | getNews: (mode, lang) => `${endpoint}/news?lang=${lang}&type=${mode}`, 38 | getBattlePassRewards: (season, lang) => `${endpoint}/battlepass?lang=${lang}&season=${season}`, 39 | getAchievements: lang => `${endpoint}/achievements?lang=${lang}`, 40 | getTournaments: lang => `${endpoint}/events/list?lang=${lang}`, 41 | getTournamentSessionDetails: (windowId, page) => `${endpoint}/events/window?windowId=${windowId}&page=${page}`, 42 | getTournamentScores: eventId => `${endpoint}/events/cumulative?eventId=${eventId}`, 43 | listWeapons: _ => `${endpoint}/weapons/list`, 44 | listPreviousMaps: _ => `${endpoint}/maps/list`, 45 | listPreviousSeasons: _ => `${endpoint}/seasons/list`, 46 | listCurrentPOI: lang => `${endpoint}/game/poi?lang=${lang}`, 47 | getStatus: _ => `${endpoint}/status`, 48 | listCurrentGameModes: lang => `${endpoint}/game/modes?lang=${lang}`, 49 | listUsersById: (ids = []) => `${endpoint}/lookupUsername?id=${ids.join()}`, 50 | getBundles: lang => `${endpoint}/bundles?lang=${lang}`, 51 | listLoot: lang => `${endpoint}/loot/list?lang=${lang}`, 52 | getLootDetails: (id, lang) => `${endpoint}/loot/get?id=${id}&lang=${lang}`, 53 | listSets: lang => `${endpoint}/items/sets?lang=${lang}`, 54 | getReplayDownloadLink: id => `${endpoint}/events/replay?session=${id}`, 55 | getWeaponDetails: (id, lang) => `${endpoint}/loot/get?id=${id}&lang=${lang}`, 56 | listWeaponSpawnChances: mode => `${endpoint}/loot/chances?mode=${mode}`, 57 | getGameModeExtendedData: mode => `${endpoint}/game/modes/data?playlist=${mode}`, 58 | listFeaturedCreativeIslands: _ => `${endpoint}/creative/featured`, 59 | searchIsland: code => `${endpoint}/creative/island?code=${code}`, 60 | listFish: lang => `${endpoint}/loot/fish?lang=${lang}`, 61 | getPlayerFishStats: id => `${endpoint}/stats/fish?accountId=${id}`, 62 | getMapsItems: _ => `${endpoint}/maps/items/list`, 63 | getGameRadios: lang => `${endpoint}/game/radios?lang=${lang}`, 64 | getRarities: _ => `${endpoint}/rarities` 65 | }; 66 | -------------------------------------------------------------------------------- /test/fortnite-api.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @license MIT 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * test/fortnite-api.js 13 | * Test Fornite API Class 14 | */ 15 | 16 | const test = require("tape"); 17 | const ForniteAPI = require("../lib/fortnite-api"); 18 | 19 | test("api class throws without credentials", assert => { 20 | assert.plan(1); 21 | try { 22 | const fortniteAPI = new ForniteAPI(); 23 | assert.fail("error should have thrown"); 24 | } catch (e) { 25 | assert.equals(e.message, "Invalid Credentials Supplied.", "Invalid Creds msg thrown"); 26 | } 27 | assert.end(); 28 | }); 29 | 30 | test("api class throws with invalid lang", assert => { 31 | assert.plan(1); 32 | try { 33 | const fortniteAPI = new ForniteAPI("example-api-key", {defaultLanguage: "cy"}); 34 | assert.fail("error should have thrown"); 35 | } catch (e) { 36 | assert.equals(e.message, "Supplied default language cy is not supported", "Invalid Lang msg thrown"); 37 | } 38 | assert.end(); 39 | }); 40 | 41 | test("api class does not throw with credentials and valid default lang", assert => { 42 | assert.plan(1); 43 | try { 44 | const fortniteAPI = new ForniteAPI("example-api-key", {defaultLanguage: "en"}); 45 | assert.true("error did not throw"); 46 | } catch (e) { 47 | assert.fail("error should not have thrown"); 48 | } 49 | assert.end(); 50 | }); 51 | 52 | test("all v1 methods return a uri and uri has correct prefix", async assert => { 53 | const fortniteAPI = new ForniteAPI("example-api-key", { 54 | ignoreWarnings: false 55 | }); 56 | const ignore = ["constructor", "request"]; 57 | const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(fortniteAPI)) 58 | .filter(method => !ignore.includes(method)); 59 | assert.plan(methods.length); 60 | for (const methodName of methods) { 61 | const uri = await fortniteAPI[methodName](); 62 | assert.true(uri.includes("https://fortniteapi.io/v1"), `method: ${methodName} has correct prefix url`); 63 | } 64 | assert.end(); 65 | }); 66 | 67 | test("all v2 methods return a uri and uri has correct prefix", async assert => { 68 | const fortniteAPI = new ForniteAPI("example-api-key"); 69 | const ignore = ["constructor", "request"]; 70 | const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(fortniteAPI.v2)) 71 | .filter(method => !ignore.includes(method)); 72 | assert.plan(methods.length); 73 | for (const methodName of methods) { 74 | const uri = await fortniteAPI.v2[methodName](); 75 | assert.true(uri.includes("https://fortniteapi.io/v2"), `method: ${methodName}V2 has correct prefix url`); 76 | } 77 | assert.end(); 78 | }); 79 | 80 | test("credentials are set correctly", assert => { 81 | assert.plan(1); 82 | const credentials = "example-api-key"; 83 | const fortniteAPI = new ForniteAPI(credentials); 84 | assert.equals(fortniteAPI.credentials, credentials, "credentials are set"); 85 | assert.end(); 86 | }); 87 | 88 | test("getBattlepassRewards defaults to current season", async assert => { 89 | assert.plan(1); 90 | const fortniteAPI = new ForniteAPI("example-api-key"); 91 | const uri = await fortniteAPI.getBattlepassRewards(); 92 | assert.true(uri.includes("season=current")); 93 | assert.end(); 94 | }); 95 | 96 | test("listChallenges defaults to current season", async assert => { 97 | assert.plan(1); 98 | const fortniteAPI = new ForniteAPI("example-api-key"); 99 | const uri = await fortniteAPI.listChallenges(); 100 | assert.true(uri.includes("season=current")); 101 | assert.end(); 102 | }); 103 | 104 | test("getNews defaults to br news", async assert => { 105 | assert.plan(1); 106 | const fortniteAPI = new ForniteAPI("example-api-key"); 107 | const uri = await fortniteAPI.getNews(); 108 | assert.true(uri.includes("type=br")); 109 | assert.end(); 110 | }); 111 | 112 | -------------------------------------------------------------------------------- /lib/fortnite-api-v2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @license MIT 7 | */ 8 | 9 | "use strict"; 10 | 11 | /** 12 | * fortnite-api-v2.js 13 | * Class to make requests to API version 2 endpoints 14 | */ 15 | 16 | const BaseClient = require('./base-client'); 17 | const endpoints = require("./endpoints-v2"); 18 | 19 | /** 20 | * API Wrapper containing the V2 endpoints 21 | */ 22 | class FortniteAPIv2 extends BaseClient { 23 | 24 | /** 25 | * listItems() 26 | * List all cosmetic items: skins, backpacks, emotes, pickaxes, sprays, etc. 27 | * 28 | * @param {object} [options] 29 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 30 | * @returns {Promise} 31 | */ 32 | listItems(options = {}) { 33 | const lang = options.lang || this.defaultLang; 34 | const uri = endpoints.listItems(lang); 35 | return this.request(uri); 36 | } 37 | 38 | /** 39 | * listChallenges() 40 | * List all challenges as well as rewards (xp, stars, cosmetics). 41 | * Weekly challenges/missions are available for each season under .weekly 42 | * Limited time missions are available under .limited_time 43 | * 44 | * @param {string} [season=current] 45 | * @param {object} [options] 46 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 47 | * @returns {Promise} 48 | */ 49 | listChallenges(season = "current", options = {}) { 50 | const lang = options.lang || this.defaultLang; 51 | const uri = endpoints.listChallenges(season, lang); 52 | return this.request(uri); 53 | } 54 | 55 | /** 56 | * listUpcomingItems() 57 | * List upcoming cosmetic items: skins, backpacks, emotes, pickaxes. 58 | * 59 | * @param {object} [options] 60 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 61 | * @returns {Promise} 62 | */ 63 | listUpcomingItems(options = {}) { 64 | const lang = options.lang || this.defaultLang; 65 | const uri = endpoints.listUpcomingItems(lang); 66 | return this.request(uri); 67 | } 68 | 69 | /** 70 | * getItemDetails() 71 | * Get all available details about an item. 72 | * The ID can be found from the full list of items. 73 | * 74 | * @param {string} itemId 75 | * @param {object} [options] 76 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 77 | * @returns {Promise} 78 | */ 79 | getItemDetails(itemId, options = {}) { 80 | const lang = options.lang || this.defaultLang; 81 | const uri = endpoints.getItemDetails(itemId, lang); 82 | return this.request(uri); 83 | } 84 | 85 | /** 86 | * getDailyShop() 87 | * List all items currently in the shop 88 | * 89 | * @param {object} [options] 90 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 91 | * @returns {Promise} 92 | */ 93 | getDailyShop(options = {}) { 94 | const lang = options.lang || this.defaultLang; 95 | const uri = endpoints.getDailyShop(lang); 96 | return this.request(uri); 97 | } 98 | 99 | /** 100 | * getBattlepassRewards() 101 | * Get the list of rewards given in the Battle Pass for each season 102 | * 103 | * @param {string} [season=current] 104 | * @param {object} [options] 105 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 106 | * @returns {Promise} 107 | */ 108 | getBattlepassRewards(season = "current", options = {}) { 109 | const lang = options.lang || this.defaultLang; 110 | const uri = endpoints.getBattlePassRewards(season, lang); 111 | return this.request(uri); 112 | } 113 | 114 | /** 115 | * listCurrentPOI() 116 | * Get the current games points of interest 117 | * 118 | * @param {object} [options] 119 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 120 | * @returns {Promise} 121 | */ 122 | listCurrentPOI(options = {}) { 123 | const lang = options.lang || this.defaultLang; 124 | const uri = endpoints.listCurrentPOI(lang); 125 | return this.request(uri); 126 | } 127 | } 128 | 129 | module.exports = FortniteAPIv2; 130 | -------------------------------------------------------------------------------- /test/.eslintrc.yml: -------------------------------------------------------------------------------- 1 | root: true 2 | 3 | parserOptions: 4 | ecmaVersion: 2017 5 | 6 | env: 7 | es6: true # We are running ES6 8 | node: true # We are running node 9 | 10 | rules: 11 | 12 | # Possible Errors 13 | 14 | comma-dangle: ["error", "never"] # disallow trailing commas 15 | no-cond-assign: ["error", "always"] # disallow assignment operators in conditional expressions 16 | no-console: "warn" # disallow the use of console 17 | no-constant-condition: "error" # disallow constant expressions in conditions 18 | no-control-regex: "error" # disallow control characters in regular expressions 19 | no-debugger: "error" # disallow the use of debugger 20 | no-dupe-args: "error" # disallow duplicate arguments in function definitions 21 | no-dupe-keys: "error" # disallow duplicate keys in object literals 22 | no-duplicate-case: "error" # disallow duplicate case labels 23 | no-empty: "error" # disallow empty block statements 24 | no-empty-character-class: "error" # disallow empty character classes in regular expressions 25 | no-ex-assign: "error" # disallow reassigning exceptions in catch clauses 26 | no-extra-boolean-cast: "error" # disallow unnecessary boolean casts 27 | no-extra-parens: 0 # disallow unnecessary parentheses 28 | no-extra-semi: "error" # disallow unnecessary semicolons 29 | no-func-assign: "error" # disallow reassigning function declarations 30 | no-inner-declarations: "error" # disallow function or var declarations in nested blocks 31 | no-invalid-regexp: "error" # disallow invalid regular expression strings in RegExp constructors 32 | no-irregular-whitespace: "error" # disallow irregular whitespace outside of strings and comments 33 | no-negated-in-lhs: "error" # disallow negating the left operand in in expressions 34 | no-obj-calls: "error" # disallow calling global object properties as functions 35 | no-regex-spaces: "error" # disallow multiple spaces in regular expression literals 36 | no-sparse-arrays: "error" # disallow sparse arrays 37 | no-unexpected-multiline: "error" # disallow confusing multiline expressions 38 | no-unreachable: "error" # disallow unreachable code after return, throw, continue, and break statements 39 | no-unsafe-finally: "error" # disallow control flow statements in finally blocks 40 | use-isnan: "error" # require calls to isNaN() when checking for NaN 41 | valid-jsdoc: 0 # enforce valid JSDoc comments 42 | valid-typeof: "error" # enforce comparing typeof expressions against valid strings 43 | 44 | 45 | # Best Practice 46 | 47 | accessor-pairs: "error" # enforces getter/setter pairs in objects (off by default) 48 | block-scoped-var: "error" # treat var statements as if they were block scoped (off by default) 49 | complexity: 0 # specify the maximum cyclomatic complexity allowed in a program (off by default) 50 | consistent-return: 0 # require return statements to either always or never specify values 51 | curly: ["error", "all"] # specify curly brace conventions for all control statements 52 | default-case: "error" # require default case in switch statements (off by default) 53 | dot-notation: "error" # encourages use of dot notation whenever possible 54 | dot-location: ["error", "property"] # enforces consistent newlines before or after dots (off by default) 55 | eqeqeq: "error" # require the use of === and !== 56 | guard-for-in: "error" # make sure for-in loops have an if statement (off by default) 57 | no-alert: "error" # disallow the use of alert, confirm, and prompt 58 | no-caller: "error" # disallow use of arguments.caller or arguments.callee 59 | no-confusing-arrow: "error" # disallow arrow functions where they could be confused with comparisons 60 | no-div-regex: "error" # disallow division operators explicitly at beginning of regular expression (off by default) 61 | no-else-return: "error" # disallow else after a return in an if (off by default) 62 | no-eq-null: "error" # disallow comparisons to null without a type-checking operator (off by default) 63 | no-eval: "error" # disallow use of eval() 64 | no-extend-native: "error" # disallow adding to native types 65 | no-extra-bind: "error" # disallow unnecessary function binding 66 | no-fallthrough: "error" # disallow fallthrough of case statements 67 | no-floating-decimal: "error" # disallow the use of leading or trailing decimal points in numeric literals (off by default) 68 | no-implied-eval: "error" # disallow use of eval()-like methods 69 | no-iterator: "error" # disallow usage of __iterator__ property 70 | no-labels: "error" # disallow use of labeled statements 71 | no-lone-blocks: "error" # disallow unnecessary nested blocks 72 | no-loop-func: "error" # disallow creation of functions within loops 73 | no-multi-spaces: "error" # disallow use of multiple spaces 74 | no-multi-str: "error" # disallow use of multiline strings 75 | no-native-reassign: "error" # disallow reassignments of native objects 76 | no-new-func: "error" # disallow use of new operator for Function object 77 | no-new-wrappers: "error" # disallows creating new instances of String, Number, and Boolean 78 | no-new: "error" # disallow use of new operator when not part of the assignment or comparison 79 | no-octal-escape: "error" # disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251"; 80 | no-octal: "error" # disallow use of octal literals 81 | no-param-reassign: 0 # disallow reassignment of function parameters (off by default) 82 | no-process-env: 0 # disallow use of process.env (off by default) 83 | no-proto: "error" # disallow usage of __proto__ property 84 | no-redeclare: "error" # disallow declaring the same variable more then once 85 | no-return-assign: "error" # disallow use of assignment in return statement 86 | no-script-url: "error" # disallow use of javascript: urls 87 | no-self-compare: "error" # disallow comparisons where both sides are exactly the same (off by default) 88 | no-sequences: "error" # disallow use of comma operator 89 | no-throw-literal: "error" # restrict what can be thrown as an exception (off by default) 90 | no-unused-expressions: "error" # disallow usage of expressions in statement position 91 | no-void: "error" # disallow use of void operator (off by default) 92 | no-warning-comments: "warn" # disallow usage of configurable erroring terms in comments, e.g. TODO or FIXME (off by default) 93 | no-with: "error" # disallow use of the with statement 94 | radix: "error" # require use of the second argument for parseInt() (off by default) 95 | vars-on-top: "error" # requires to declare all vars on top of their containing scope (off by default) 96 | wrap-iife: "error" # require immediate function invocation to be wrapped in parentheses (off by default) 97 | yoda: 0 # require or disallow Yoda conditions 98 | 99 | 100 | # Strict Mode 101 | 102 | strict: "error" # controls location of Use Strict Directives 103 | 104 | 105 | # Variables 106 | 107 | no-catch-shadow: "error" # disallow the catch clause parameter name being the same as a variable in the outer scope (off by default in the node environment) 108 | no-delete-var: 0 # disallow deletion of variables 109 | no-label-var: "error" # disallow labels that share a name with a variable 110 | no-shadow: ["error", {"allow": ["_"]}] # disallow declaration of variables already declared in the outer scope 111 | no-shadow-restricted-names: "error" # disallow shadowing of names such as arguments 112 | no-undef: "error" # disallow use of undeclared variables unless mentioned in a /*global */ block 113 | no-undef-init: "error" # disallow use of undefined when initializing variables 114 | no-undefined: 0 # disallow use of undefined variable (off by default) 115 | no-use-before-define: ["error", "nofunc"] # disallow use of variables before they are defined 116 | 117 | 118 | # Node.js 119 | 120 | handle-callback-err: "warn" # enforces error handling in callbacks (off by default) (on by default in the node environment) 121 | no-mixed-requires: "error" # disallow mixing regular variable and require declarations (off by default) (on by default in the node environment) 122 | no-new-require: "error" # disallow use of new operator with the require function (off by default) (on by default in the node environment) 123 | no-path-concat: "error" # disallow string concatenation with __dirname and __filename (off by default) (on by default in the node environment) 124 | no-process-exit: 0 # disallow process.exit() (on by default in the node environment) 125 | no-restricted-modules: 0 # restrict usage of specified node modules (off by default) 126 | no-sync: "warn" # disallow use of synchronous methods (off by default) 127 | 128 | 129 | # Stylistic Issues 130 | 131 | array-bracket-spacing: ["error", "never"] # enforce spacing inside array brackets (off by default) 132 | brace-style: ["error", "1tbs"] # enforce one true brace style (off by default) 133 | camelcase: "error" # require camel case names 134 | comma-spacing: ["error", {before: false, after: true}] # enforce spacing before and after comma 135 | comma-style: ["error", "last"] # enforce one true comma style (off by default) 136 | computed-property-spacing: ["error", "never"] # require or disallow padding inside computed properties (off by default) 137 | consistent-this: ["error", "that"] # enforces consistent naming when capturing the current execution context (off by default) 138 | eol-last: "error" # enforce newline at the end of file, with no multiple empty lines 139 | func-names: 0 # require function expressions to have a name (off by default) 140 | func-style: 0 # enforces use of function declarations or expressions (off by default) 141 | indent: ["error", 4] # this option sets a specific tab width for your code (off by default) 142 | key-spacing: ["error", {beforeColon: false, afterColon: true}] # enforces spacing between keys and values in object literal properties 143 | lines-around-comment: 0 # enforces empty lines around comments (off by default) 144 | linebreak-style: ["error", "unix"] # disallow mixed 'LF' and 'CRLF' as linebreaks (off by default) 145 | max-nested-callbacks: ["error", 5] # require a capital letter for constructors 146 | new-parens: "error" # allow/disallow an empty newline after var statement (off by default) 147 | no-array-constructor: "error" # disallow use of the Array constructor 148 | no-continue: "error" # disallow use of the continue statement (off by default) 149 | no-inline-comments: 0 # disallow comments inline after code (off by default) 150 | no-lonely-if: "error" # disallow if as the only statement in an else block (off by default) 151 | no-mixed-spaces-and-tabs: "error" # disallow mixed spaces and tabs for indentation 152 | no-multiple-empty-lines: 0 # disallow multiple empty lines (off by default) 153 | no-nested-ternary: "error" # disallow nested ternary expressions (off by default) 154 | no-new-object: 0 # disallow use of the Object constructor 155 | no-spaced-func: "error" # disallow space between function identifier and application 156 | no-ternary: 0 # disallow the use of ternary operators (off by default) 157 | no-trailing-spaces: "error" # disallow trailing whitespace at the end of lines 158 | no-underscore-dangle: "error" # disallow dangling underscores in identifiers 159 | one-var: 0 # allow just one var statement per function (off by default) 160 | operator-assignment: ["error", "always"] # require assignment operator shorthand where possible or prohibit it entirely (off by default) 161 | operator-linebreak: ["error", "before"] # enforce operators to be placed before or after line breaks (off by default) 162 | padded-blocks: 0 # enforce padding within blocks (off by default) 163 | quote-props: 0 # require quotes around object literal property names (off by default) 164 | quotes: ["error", "double", {allowTemplateLiterals: true}] # specify whether double or single quotes should be used 165 | semi-spacing: ["error", {before: false, after: true}] # enforce spacing before and after semicolons 166 | semi: ["error", "always"] # require or disallow use of semicolons instead of ASI 167 | sort-vars: 0 # sort variables within the same declaration block (off by default) 168 | keyword-spacing: ["error", {before: true, after: true}] # require a space before or after certain keywords 169 | space-before-blocks: ["error", "always"] # require or disallow space before blocks (off by default) 170 | space-before-function-paren: ["error", {anonymous: always, named: never}] # require or disallow space before function opening parenthesis (off by default) 171 | space-in-parens: ["error", "never"] # require or disallow spaces inside parentheses (off by default) 172 | space-infix-ops: "error" # require spaces around operators 173 | space-unary-ops: "error" # require or disallow spaces before/after unary operators (words on by default, nonwords off by default) 174 | spaced-comment: ["error", "always"] # require or disallow a space immediately following the # or /* in a comment (off by default) 175 | wrap-regex: "error" # require regex literals to be wrapped in parentheses (off by default) 176 | 177 | 178 | # ECMAScript 6 179 | 180 | constructor-super: "error" # verify super() callings in constructors (off by default) 181 | generator-star-spacing: 0 # enforce the spacing around the * in generator functions (off by default) 182 | no-this-before-super: "error" # disallow to use this/super before super() calling in constructors (off by default) 183 | no-var: "error" # require let or const instead of var (off by default) 184 | object-shorthand: 0 # require method and property shorthand syntax for object literals (off by default) 185 | prefer-const: "error" # suggest using of const declaration for variables that are never modified after declared (off by default) 186 | no-const-assign: "error" # prevent attempted re-assignment of variables declared with const 187 | 188 | # Legacy 189 | 190 | max-depth: ["error", 5] # specify the maximum depth that blocks can be nested (off by default) 191 | max-len: ["error", 120] # specify the maximum length of a line in your program (off by default) 192 | max-params: ["error", 5] # limits the number of parameters that can be used in the function declaration. (off by default) 193 | max-statements: 0 # specify the maximum number of statement allowed in a function (off by default) 194 | no-bitwise: "error" # disallow use of bitwise operators (off by default) 195 | no-plusplus: "error" # disallow use of unary operators, ++ and -- (off by default) 196 | -------------------------------------------------------------------------------- /lib/fortnite-api.js: -------------------------------------------------------------------------------- 1 | /** 2 | * fortnite-api-io 3 | * Module to make API calls to fortniteapi.io 4 | * 5 | * @author Ben Hawley 6 | * @author Théo Bontemps (maintainer) 7 | * @license MIT 8 | */ 9 | 10 | "use strict"; 11 | 12 | /** 13 | * fortnite-api.js 14 | * Class to make requests to API 15 | */ 16 | 17 | // Internal Libaries 18 | const BaseClient = require('./base-client'); 19 | const FortniteAPIv2 = require('./fortnite-api-v2'); 20 | const endpoints = require("./endpoints"); 21 | 22 | /** 23 | * Fortnite API Class 24 | */ 25 | class FortniteAPI extends BaseClient { 26 | 27 | /** 28 | * constructor() 29 | * 30 | * @param {string} credentials 31 | * @param {object} [config] 32 | * @param {string} [config.defaultLanguage] 33 | * @param {string} [config.ignoreWarnings] 34 | */ 35 | constructor(credentials, config = {}) { 36 | super(credentials, config) 37 | 38 | // Attach the V2 API currently in development 39 | this.v2 = new FortniteAPIv2(credentials, config); 40 | } 41 | 42 | /** 43 | * listItems() 44 | * List all cosmetic items: skins, backpacks, emotes, pickaxes, sprays, etc. 45 | * 46 | * @deprecated 47 | * @param {object} [options] 48 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 49 | * @returns {Promise} 50 | */ 51 | listItems(options = {}) { 52 | this.deprecationWarning('listItems', 'FortniteAPI.v2.listItems'); 53 | const lang = options.lang || this.defaultLang; 54 | const uri = endpoints.listItems(lang); 55 | return this.request(uri); 56 | } 57 | 58 | /** 59 | * listChallenges() 60 | * List all challenges as well as rewards (xp, stars, cosmetics). 61 | * Weekly challenges/missions are available for each season under .weekly 62 | * Limited time missions are available under .limited_time 63 | * 64 | * @deprecated 65 | * @param {string} [season=current] 66 | * @param {object} [options] 67 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 68 | * @returns {Promise} 69 | */ 70 | listChallenges(season = "current", options = {}) { 71 | this.deprecationWarning('listChallenges', 'FortniteAPI.v2.listChallenges') 72 | const lang = options.lang || this.defaultLang; 73 | const uri = endpoints.listChallenges(season, lang); 74 | return this.request(uri); 75 | } 76 | 77 | /** 78 | * listUpcomingItems() 79 | * List upcoming cosmetic items: skins, backpacks, emotes, pickaxes. 80 | * 81 | * @deprecated 82 | * @param {object} [options] 83 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 84 | * @returns {Promise} 85 | */ 86 | listUpcomingItems(options = {}) { 87 | this.deprecationWarning('listUpcomingItems', 'FortniteAPI.v2.listUpcomingItems') 88 | const lang = options.lang || this.defaultLang; 89 | const uri = endpoints.listUpcomingItems(lang); 90 | return this.request(uri); 91 | } 92 | 93 | /** 94 | * getItemDetails() 95 | * Get all available details about an item. 96 | * The ID can be found from the full list of items. 97 | * 98 | * @deprecated 99 | * @param {string} itemId 100 | * @param {object} [options] 101 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 102 | * @returns {Promise} 103 | */ 104 | getItemDetails(itemId, options = {}) { 105 | this.deprecationWarning('getItemDetails', 'FortniteAPI.v2.getItemDetails') 106 | const lang = options.lang || this.defaultLang; 107 | const uri = endpoints.getItemDetails(itemId, lang); 108 | return this.request(uri); 109 | } 110 | 111 | /** 112 | * getDailyShop() 113 | * List all items currently in the shop 114 | * 115 | * @deprecated 116 | * @param {object} [options] 117 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr, zh-CN, zh-Hant 118 | * @returns {Promise} 119 | */ 120 | getDailyShop(options = {}) { 121 | this.deprecationWarning('getDailyShop', 'FortniteAPI.v2.getDailyShop') 122 | const lang = options.lang || this.defaultLang; 123 | const uri = endpoints.getDailyShop(lang); 124 | return this.request(uri); 125 | } 126 | 127 | /** 128 | * getShopVotingOptions() 129 | * Get options to vote for the next community shop item 130 | * @returns {Promise} 131 | */ 132 | getShopVotingOptions() { 133 | const uri = endpoints.getShopVotingOptions(); 134 | return this.request(uri); 135 | } 136 | 137 | /** 138 | * searchAccountId() 139 | * Search an account ID using a player name 140 | * 141 | * @deprecated since v1.3.0 please use getUserById 142 | * @param {string} username 143 | * @param {object} [options] 144 | * @param {boolean} [options.strict=true] When false will return other results for similar names 145 | * @param {string} [options.platform=""] Search for accounts not linked to an epic account: xbl or psn 146 | * @returns {Promise} 147 | */ 148 | searchAccountId(username, options = { strict: true, platform: "" }) { 149 | const uri = endpoints.searchAccountId( 150 | username, 151 | options.platform, 152 | options.strict 153 | ); 154 | return this.request(uri); 155 | } 156 | 157 | /** 158 | * getGlobalPlayerStats() 159 | * Get player stats, with a breakdown per platform used (mouse & keyboard, gamepad, touch) 160 | * 161 | * @param {string} accountId 162 | * @returns {Promise} 163 | */ 164 | getGlobalPlayerStats(accountId) { 165 | const uri = endpoints.getGlobalPlayerStats(accountId); 166 | return this.request(uri); 167 | } 168 | 169 | /** 170 | * getPlayerRecentMatches() 171 | * List the last 25 games for a player. Some games can be grouped. 172 | * If it's the first time you search this user, the matches list will be empty. 173 | * 174 | * @param {string} accountId 175 | * @returns {Promise} 176 | */ 177 | getPlayerRecentMatches(accountId) { 178 | const uri = endpoints.getPlayerRecentMatches(accountId); 179 | return this.request(uri); 180 | } 181 | 182 | /** 183 | * getNews() 184 | * Lists the current news in Fortnite Battle Royale or Save The World 185 | * 186 | * @param {string} [mode=br] game mode "br" or "stw" 187 | * @param {object} [options] 188 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 189 | * @returns {Promise} 190 | */ 191 | getNews(mode = "br", options = {}) { 192 | const lang = options.lang || this.defaultLang; 193 | const uri = endpoints.getNews(mode, lang); 194 | return this.request(uri); 195 | } 196 | 197 | /** 198 | * getBattlepassRewards() 199 | * Get the list of rewards given in the Battle Pass for each season 200 | * 201 | * @deprecated 202 | * @param {string} [season=current] 203 | * @param {object} [options] 204 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 205 | * @returns {Promise} 206 | */ 207 | getBattlepassRewards(season = "current", options = {}) { 208 | this.deprecationWarning('getBattlepassRewards', 'FortniteAPI.v2.getBattlepassRewards') 209 | const lang = options.lang || this.defaultLang; 210 | const uri = endpoints.getBattlePassRewards(season, lang); 211 | return this.request(uri); 212 | } 213 | 214 | /** 215 | * getAchievements() 216 | * Get the list of achievements 217 | * 218 | * @param {object} [options] 219 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 220 | * @returns {Promise} 221 | */ 222 | getAchievements(options = {}) { 223 | const lang = options.lang || this.defaultLang; 224 | const uri = endpoints.getAchievements(lang); 225 | return this.request(uri); 226 | } 227 | 228 | /** 229 | * getTournaments 230 | * Get the list of tournaments 231 | * 232 | * @param {object} [options] 233 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 234 | * @returns {Promise} 235 | */ 236 | getTournaments(options = {}) { 237 | const lang = options.lang || this.defaultLang; 238 | const uri = endpoints.getTournaments(lang); 239 | return this.request(uri); 240 | } 241 | 242 | /** 243 | * getTournamentSessionDetails() 244 | * Get a tournament session details: rules, payout, results 245 | * 246 | * @param {string} windowId 247 | * @param {Integer} [page=0] 248 | * @returns {Promise} 249 | */ 250 | getTournamentSessionDetails(windowId, page = 0) { 251 | const uri = endpoints.getTournamentSessionDetails(windowId, page); 252 | return this.request(uri); 253 | } 254 | 255 | /** 256 | * getTournamentScores() 257 | * Get the cumulative scoring for a tournament event 258 | * 259 | * @param {string} eventId the tournament event id 260 | * @returns {Promise} 261 | */ 262 | getTournamentScores(eventId) { 263 | const uri = endpoints.getTournamentScores(eventId); 264 | return this.request(uri); 265 | } 266 | 267 | /** 268 | * listPreviousMaps() 269 | * Get the list of links to the different maps 270 | * 271 | * @returns {Promise} 272 | */ 273 | listPreviousMaps() { 274 | const uri = endpoints.listPreviousMaps(); 275 | return this.request(uri); 276 | } 277 | 278 | /** 279 | * listPreviousSeasons() 280 | * List all the season dates and patch versions associated. 281 | * 282 | * @returns {Promise} 283 | */ 284 | listPreviousSeasons() { 285 | const uri = endpoints.listPreviousSeasons(); 286 | return this.request(uri); 287 | } 288 | 289 | /** 290 | * listCurrentPOI() 291 | * Get the current games points of interest 292 | * 293 | * @param {object} [options] 294 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 295 | * @returns {Promise} 296 | */ 297 | listCurrentPOI(options = {}) { 298 | this.deprecationWarning('listCurrentPOI', 'FortniteAPI.v2.listCurrentPOI'); 299 | const lang = options.lang || this.defaultLang; 300 | const uri = endpoints.listCurrentPOI(lang); 301 | return this.request(uri); 302 | } 303 | 304 | /** 305 | * getStatus() 306 | * Get the Fortnite server status 307 | * 308 | * @returns {Promise} 309 | */ 310 | getStatus() { 311 | const uri = endpoints.getStatus(); 312 | return this.request(uri); 313 | } 314 | 315 | /** 316 | * listCurrentGameModes() 317 | * List the current game modes 318 | * 319 | * @param {object} [options] 320 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 321 | * @returns {Promise} 322 | */ 323 | listCurrentGameModes(options = {}) { 324 | const lang = options.lang || this.defaultLang; 325 | const uri = endpoints.listCurrentGameModes(lang); 326 | return this.request(uri); 327 | } 328 | 329 | /** 330 | * getAccountIdByUsername() 331 | * Get an account ID using a player name 332 | * 333 | * @param {string} username 334 | * @param {object} [options] 335 | * @param {boolean} [options.strict=true] When false will return other results for similar names 336 | * @param {string} [options.platform=""] Search for accounts not linked to an epic account: xbl or psn 337 | * @returns {Promise} 338 | */ 339 | getAccountIdByUsername(username, options = { strict: true, platform: "" }) { 340 | const uri = endpoints.searchAccountId( 341 | username, 342 | options.platform, 343 | options.strict 344 | ); 345 | return this.request(uri); 346 | } 347 | 348 | /** 349 | * getUserById() 350 | * Get a user account name by their Fortnite ID 351 | * 352 | * @param {string} id 353 | * @returns {Promise} 354 | */ 355 | getUserById(id) { 356 | const uri = endpoints.listUsersById([id]); 357 | return this.request(uri); 358 | } 359 | 360 | /** 361 | * listUsersById() 362 | * List user accounts by a list of ids 363 | * 364 | * @param {Array} [ids=[]] 365 | * @returns {Promise} 366 | */ 367 | listUsersById(ids = []) { 368 | const uri = endpoints.listUsersById(ids); 369 | return this.request(uri); 370 | } 371 | 372 | /** 373 | * getBundles() 374 | * List recent bundles 375 | * 376 | * @premium 377 | * @param {object} [options] 378 | * @param {string} [options.lang] en, de, es, fr, it, ja 379 | * @returns {Promise} 380 | */ 381 | getBundles(options = {}) { 382 | const lang = options.lang || this.defaultLang; 383 | const uri = endpoints.getBundles(lang); 384 | return this.request(uri); 385 | } 386 | 387 | /** 388 | * listLoot() 389 | * List all loot/weapons in the game with their basic stats 390 | * 391 | * @param {object} [options] 392 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 393 | * @returns {Promise} 394 | */ 395 | listLoot(options = {}) { 396 | const lang = options.lang || this.defaultLang; 397 | const uri = endpoints.listLoot(lang); 398 | return this.request(uri); 399 | } 400 | 401 | /** 402 | * getLootDetails() 403 | * Get all stats for a specific loot/weapon item 404 | * 405 | * @premium 406 | * @param {string} id of loot item 407 | * @param {object} [options] 408 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 409 | * @returns {Promise} 410 | */ 411 | getLootDetails(id, options = {}) { 412 | const lang = options.lang || this.defaultLang; 413 | const uri = endpoints.getLootDetails(id, lang); 414 | return this.request(uri); 415 | } 416 | 417 | /** 418 | * listSets() 419 | * List all the sets used by cosmetics. 420 | * 421 | * @param {object} [options] 422 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 423 | * @returns {Promise} 424 | */ 425 | listSets(options = {}) { 426 | const lang = options.lang || this.defaultLang; 427 | const uri = endpoints.listSets(lang); 428 | return this.request(uri); 429 | } 430 | 431 | /** 432 | * getReplayDownloadLink() 433 | * Get creative map informations 434 | * 435 | * @premium 436 | * @param {string} id of session 437 | * @returns {Promise} 438 | */ 439 | getReplayDownloadLink(id) { 440 | const uri = endpoints.getReplayDownloadLink(id); 441 | return this.request(uri); 442 | } 443 | 444 | /** 445 | * getWeaponDetails() 446 | * Get all stats for a specific loot/weapon item 447 | * 448 | * @premium 449 | * @param {string} id of weapon 450 | * @param {object} [options] 451 | * @param {string} [options.lang] en, ar, de, es, es-419, fr, it, ja, ko, pl, pt-BR, ru, tr 452 | * @returns {Promise} 453 | */ 454 | getWeaponDetails(id, options = {}) { 455 | const lang = options.lang || this.defaultLang; 456 | const uri = endpoints.getWeaponDetails(id, lang); 457 | return this.request(uri); 458 | } 459 | 460 | /** 461 | * listWeaponsSpawnChance() 462 | * List the spawn chances for each type for a given game mode. 463 | * 464 | * @premium 465 | * @param {string} mode 466 | * @returns {Promise} 467 | */ 468 | listWeaponSpawnChances(mode) { 469 | const uri = endpoints.listWeaponSpawnChances(mode); 470 | return this.request(uri); 471 | } 472 | 473 | /** 474 | * getGameModeExtendedData() 475 | * A lot of different values, ranging from spawn % for rare chests, to number of llamas per game. 476 | * 477 | * @premium 478 | * @param {string} mode 479 | * @returns {Promise} 480 | */ 481 | getGameModeExtendedData(mode) { 482 | const uri = endpoints.getGameModeExtendedData(mode); 483 | return this.request(uri); 484 | } 485 | 486 | /** 487 | * listFeaturedCreativeIslands() 488 | * List the current featured islands in creative mode 489 | * 490 | * @returns {Promise} 491 | */ 492 | listFeaturedCreativeIslands() { 493 | const uri = endpoints.listFeaturedCreativeIslands(); 494 | return this.request(uri); 495 | } 496 | 497 | /** 498 | * searchIsland() 499 | * Get all details related to a creative island 500 | * 501 | * @param {string} code of map 502 | * @returns {Promise} 503 | */ 504 | searchIsland(code) { 505 | const uri = endpoints.searchIsland(code); 506 | return this.request(uri); 507 | } 508 | 509 | /** 510 | * listFish() 511 | * Get the list of fish (name, description, image) as well as their minimum and maximum length 512 | * 513 | * @param {object} [options] 514 | * @param {string} [options.lang] unknown supported languages 515 | * @returns {Promise} 516 | */ 517 | listFish(options = {}) { 518 | const lang = options.lang || this.defaultLang; 519 | const uri = endpoints.listFish(lang); 520 | return this.request(uri); 521 | } 522 | 523 | /** 524 | * getPlayerFishStats() 525 | * Get the stats for a specific player: each fish caught is returned with the best length for that player 526 | * 527 | * @param {string} accountId 528 | * @returns {Promise} 529 | */ 530 | getPlayerFishStats(accountId) { 531 | const uri = endpoints.getPlayerFishStats(accountId); 532 | return this.request(uri); 533 | } 534 | 535 | /** 536 | * getMapsItems() 537 | * Get items positions [NOT STABLE] 538 | * 539 | * @returns {Promise} 540 | */ 541 | getMapsItems() { 542 | const uri = endpoints.getMapsItems(); 543 | return this.request(uri); 544 | } 545 | 546 | /** 547 | * getGameRadios() 548 | * List the game radios as well as the audio files 549 | * Note: not all radios are available in all languages 550 | * 551 | * @premium 552 | * @param {object} [options] 553 | * @param {string} [options.lang] unknown supported languages 554 | * @returns {Promise} 555 | */ 556 | getGameRadios(options = {}) { 557 | const lang = options.lang || this.defaultLang; 558 | const uri = endpoints.getGameRadios(lang); 559 | return this.request(uri); 560 | } 561 | 562 | /** 563 | * getRarities() 564 | * Lists rarities and their associated colors 565 | * 566 | * @returns {Promise} 567 | */ 568 | getRarities() { 569 | const uri = endpoints.getRarities(); 570 | return this.request(uri); 571 | } 572 | } 573 | 574 | module.exports = FortniteAPI; 575 | --------------------------------------------------------------------------------