diff --git a/README.md b/README.md index 27a51ca..f62fcec 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ donate bitcoin

-This is an **unofficial** NodeJS library for interacting with the [VALORANT](https://playvalorant.com/) APIs used in game. +This is an **unofficial** NodeJS library for interacting with the [VALORANT](https://playvalorant.com/) APIs used in game. It also serves as a wrapper around third party APIs that provide game content such as maps, player cards and weapons. ## Install @@ -225,6 +225,10 @@ Below is a list of API calls that are implemented in this library. - [x] `getPlayers(playerIds)` - [x] `getStoryContractDefinitions()` +# Content API + +Check out the [Content API Docs](./docs/ContentAPI.md) if you're wanting to fetch game assets such as Maps, Player Cards and Weapons. + # Local Riot Client API If you're looking for information on how to interact with `RiotClientServices.exe`, such as intercepting requests, take a look at the documentation in [RiotClientServices.md](./docs/RiotClientServices.md) diff --git a/docs/ContentAPI.md b/docs/ContentAPI.md new file mode 100644 index 0000000..5bdab41 --- /dev/null +++ b/docs/ContentAPI.md @@ -0,0 +1,153 @@ +# Content API + +This is an API wrapper for [valorant-api.com](https://valorant-api.com). This API is separate from the in-game APIs and is managed by a third party. + +#### Getting Started: + +First you need to import the ContentAPI module and the Language Module. + +```javascript +const { ContentAPI, Languages } = require("@liamcottle/valorant.js"); +``` + +Next, you need to create a ContentAPI instance. You can optionally provide the Language the data should be returned in. By default, the language is set to English. Here is a list of all available languages: + +| **Languages** | +| :-----------------: | +| German | +| English | +| Spanish_Spain | +| Spanish_Mexico | +| French | +| Indonesian | +| Italien | +| Japanese | +| Korean | +| Polish | +| Portuguese_Brazil | +| Russian | +| Thai | +| Turkish | +| Vietnamese | +| Chinese_Simplified | +| Chinese_Traditional | + +```js +const content = new ContentAPI(Languages.English); +``` + +After you have created the ContentAPI instance you can start fetching data. For this you can either use _async/await_ or _.then_ this works as follows: +**Async/Await:** + +```js +//Send a request to get all agents +const data = await content.getAgents(); +//Log the received data in the console +console.log(data); +``` + +**.then** + +```js +content.getAgents().then((data) => { + //log data + console.log(data); +}); +``` + +Here is an example of how to get a players' Daily Store and then fetch the Asset Data using the ContentAPI. + +```js +// import modules +const { API, ContentAPI, Languages, Regions } = require("@liamcottle/valorant.js"); + +// initiate the API and the ContentAPI Module +const client = new API(Regions.EU); +const content = new ContentAPI(Languages.English); + +// authorize using the ClientAPI +client.authorize("username", "password").then(() => { + client.getPlayerStoreFront(client.user_id).then(async (response) => { + + // get assets for the first Skin in the Store + const item1 = await content.getWeaponSkinLevelByUuid( + response.data.SkinsPanelLayout.SingleItemOffers[0] + ); + + // log item + console.log(item1); + + }); +}); +``` + +Here is a list of all available Endpoints for the ContentAPI: + +- **[Agents](https://dash.valorant-api.com/endpoints/agents)** + - getAgents() + - getAgentsByUuid(_uuid_) +- **[Buddies](https://dash.valorant-api.com/endpoints/buddies)** + - getBuddies() + - getBuddyLevels() + - getBuddyByUuid(_uuid_) + - getBuddyLevelByUuid(_uuid_) +- **[Bundles](https://dash.valorant-api.com/endpoints/bundles)** + - getBundles() + - getBundleByUuid(_uuid_) +- **[Ceremonies](https://dash.valorant-api.com/endpoints/ceremonies)** + - getCeremonies() + - getCeremonyByUuid(_uuid_) +- **[Competitive Tiers](https://dash.valorant-api.com/endpoints/competitivetiers)** + - getCompetitiveTiers() + - getCompetitiveTierByUuid(_uuid_) +- **[ContentAPI Tiers](https://dash.valorant-api.com/endpoints/contenttiers)** + - getContentTiers() + - getContentTierByUuid(_uuid_) +- **[Contracts](https://dash.valorant-api.com/endpoints/contracts)** + - getContracts() + - getContractByUuid(_uuid_) +- **[Currencies](https://dash.valorant-api.com/endpoints/currencies)** + - getCurrencies() + - getCurrencyByUuid(_uuid_) +- **[Events](https://dash.valorant-api.com/endpoints/events)** + - getEvents() + - getEventByUuid(_uuid_) +- **[Gamemodes](https://dash.valorant-api.com/endpoints/gamemodes)** + - getGamemodes() + - getGamemodeEquippables() + - getGamemodeByUuid(_uuid_) + - getGamemodeEquippableByUuid(_uuid_) +- **[Gear](https://dash.valorant-api.com/endpoints/gear)** + - getGear() + - getGearByUuid(_uuid_) +- **[Maps](https://dash.valorant-api.com/endpoints/maps)** + - getMaps() + - getMapByUuid(_uuid_) +- **[Player Cards](https://dash.valorant-api.com/endpoints/playercards)** + - getPlayerCards() + - getPlayerCardByUuid(_uuid_) +- **[Player Titles](https://dash.valorant-api.com/endpoints/playertitles)** + - getPlayerTitles() + - getPlayerTitleByUuid(_uuid_) +- **[Seasons](https://dash.valorant-api.com/endpoints/seasons)** + - getSeasons() + - getCompetitiveSeasons() + - getSeasonByUuid(_uuid_) + - getCompetitiveSeasonByUuid(_uuid_) +- **[Sprays](https://dash.valorant-api.com/endpoints/sprays)** + - getSprays() + - getSprayByUuid(_uuid_) +- **[Themes](https://dash.valorant-api.com/endpoints/themes)** + - getThemes() + - getThemeByUuid(_uuid_) +- **[Weapons](https://dash.valorant-api.com/endpoints/weapons)** + - getWeapons() + - getWeaponSkins() + - getWeaponSkinChromas() + - get WeaponSkinLevels() + - getWeaponByUuid(_uuid_) + - getWeaponSkinByUuid(_uuid_) + - getWeaponSkinChromaByUuid(_uuid_) + - getWeaponSkinLevelByUuid(_uuid_) + +_If you have any Issue or Suggestion please open an Issue on the [Github Repository](https://github.com/liamcottle/valorant.js) or join the [Discord Server](https://discord.gg/HUFEkChRpP)_ diff --git a/index.js b/index.js index 5081952..2d1786f 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,16 @@ module.exports = { - API: require("./src/api"), - Maps: require("./src/maps"), - Regions: require("./src/regions"), - Tiers: require("./src/tiers"), - LocalRiotClientAPI: require("./src/LocalRiotClientAPI"), -}; \ No newline at end of file + + // Internal Game APIs + API: require("./src/api"), + LocalRiotClientAPI: require("./src/LocalRiotClientAPI"), + + // Third Party APIs + ContentAPI: require("./src/ContentAPI"), + + // Static Content + Languages: require("./src/languages"), + Maps: require("./src/maps"), + Regions: require("./src/regions"), + Tiers: require("./src/tiers"), + +}; diff --git a/src/ContentAPI.js b/src/ContentAPI.js new file mode 100644 index 0000000..65da525 --- /dev/null +++ b/src/ContentAPI.js @@ -0,0 +1,629 @@ +"use strict"; + +const axios = require("axios").default; +const languages = require("./languages"); + +class ContentAPI { + /** + * Initialize the Content API using https://valorant-api.com/ + * @param {string} language The language you want the content to be returned in + */ + constructor(language = languages.English) { + this.language = language; + this.baseURL = "https://valorant-api.com/v1/"; + } + + // agent Endpoints + + /** + * Get a list of all Agents + * @returns {Promise>} A list of all Agents + */ + async getAgents() { + const data = await axios.get(`${this.baseURL}agents`, { + params: { language: this.language, isPlayableCharacter: true }, + }); + return data.data.data; + } + + /** + * Get a specific Agent by UUID + * @param {string} uuid The UUID of the Agent + * @returns {Promise} Agent Object + */ + async getAgentByUuid(uuid) { + const data = await axios.get(`${this.baseURL}agents/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Buddies Endpoints + + /** + * Get a list of all Buddies + * @returns {Promise>} A list of all Buddies + */ + async getBuddies() { + const data = await axios.get(`${this.baseURL}buddies`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of all weapon buddy levels + * @returns {Promise>} A list of all Buddy Levels + */ + async getBuddyLevels() { + const data = await axios.get(`${this.baseURL}buddies/levels`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested weapon buddy + * @param {string} uuid The UUID of the Buddy + * @returns {Promise} Buddy Object + */ + async getBuddyByUuid(uuid) { + const data = await axios.get(`${this.baseURL}buddies/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested weapon buddy level + * @param {string} uuid Buddy UUID + * @returns {Promise} BuddyLevel Object + */ + async getBuddyLevelByUuid(uuid) { + const data = await axios.get(`${this.baseURL}buddies/levels/${uuid}`, { + params: { language: this.language }, + }); + } + + // Bundle Endpoints + + /** + * Returns a list of all Bundles + * @returns {Promise>} A list of all Bundles + */ + async getBundles() { + const data = await axios.get(`${this.baseURL}bundles`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested bundle + * @param {string} uuid Bundle UUID + * @returns {Promise} Bundle Object + */ + async getBundleByUuid(uuid) { + const data = await axios.get(`${this.baseURL}bundles/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Ceremony Endpoints + + /** + * Returns data and assets of all ceremonies + * @returns {Promise>} A list of all Ceremonies + */ + async getCeremonies() { + const data = await axios.get(`${this.baseURL}ceremonies`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested ceremony + * @param {string} uuid Ceremony UUID + * @returns {Promise} Ceremony Object + */ + async getCeremonyByUuid(uuid) { + const data = await axios.get(`${this.baseURL}ceremonies/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Competitive Tiers Endpoints + + /** + * Returns data and assets of all competitive tiers + * @returns {Promise>} A list of all Competitive Tiers + */ + async getCompetitiveTiers() { + const data = await axios.get(`${this.baseURL}competitivetiers`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets the requested competitive tier table + * @param {string} uuid Competitive Tier UUID + * @returns {Promise} CompetitiveTier Object + */ + async getCompetitiveTierByUuid(uuid) { + const data = axios.get(`${this.baseURL}competitivetiers/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Content Tiers Endpoints + + /** + * Returns data and assets of all content tiers + * @returns {Promise>} A list of all Content Tiers + */ + async getContentTiers() { + const data = await axios.get(`${this.baseURL}contenttiers`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets for the requested content tier + * @param {string} uuid Content Tier UUID + * @returns {Promise} ContentTier Object + */ + async getContentTierByUuid(uuid) { + const data = await axios.get(`${this.baseURL}contenttiers/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Contract Endpoints + + /** + * Returns data and assets of all contracts + * @returns {Promise>} A list of all Contracts + */ + async getContracts() { + const data = await axios.get(`${this.baseURL}contracts`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets the requested contract + * @param {string} uuid Contract UUID + * @returns {Promise} Contract Object + */ + async getContractByUuid(uuid) { + const data = await axios.get(`${this.baseURL}contracts/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Currencies Endpoints + + /** + * Returns data and assets of all in-game currencies + * @returns {Promise>} A list of all Currencies + */ + async getCurrencies() { + const data = await axios.get(`${this.baseURL}currencies`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets the requested in-game currency + * @param {string} uuid Currency UUID + * @returns {Promise} Currency Object + */ + async getCurrencyByUuid(uuid) { + const data = await axios.get(`${this.baseURL}currencies/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Events Endpoints + /** + * Returns data and assets of all events + * @returns {Promise>} A list of all Events + */ + async getEvents() { + const data = await axios.get(`${this.baseURL}events`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets the requested event + * @param {string} uuid Event UUID + * @returns {Promise} Event Object + */ + async getEventByUuid(uuid) { + const data = await axios.get(`${this.baseURL}events/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Gamemode Endpoints + + /** + * Returns data and assets of all gamemodes + * @returns {Promise>} A list of all Gamemodes + */ + async getGameModes() { + const data = await axios.get(`${this.baseURL}gamemodes`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of all gamemode equippables + * @returns {Promise>} A list of all Gamemode Equippables + */ + async getGamemodeEquippables() { + const data = await axios.get(`${this.baseURL}gamemodes/equippables`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested gamemode + * @param {string} uuid + * @returns {Promise} Gamemode Object + */ + async getGameModeByUuid(uuid) { + const data = await axios.get(`${this.baseURL}gamemodes/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested gamemode equippable + * @param {string} uuid Gamemode Equippable UUID + * @returns {Promise} Gamemode Equippable Object + */ + async getGamemodeEquippableByUuid(uuid) { + const data = await axios.get( + `${this.baseURL}gamemodes/equippables/${uuid}`, + { + params: { language: this.language }, + } + ); + return data.data.data; + } + + // Gear Endpoints + + /** + * Returns data and assets of all gear + * @returns {Promise>} A list of all Gear + */ + async getGear() { + const data = await axios.get(`${this.baseURL}gear`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested gear + * @param {string} uuid Gear UUID + * @returns {Promise} Gear Object + */ + async getGearByUuid(uuid) { + const data = await axios.get(`${this.baseURL}gear/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Map Endpoints + + /** + * Returns data and assets of all maps + * @returns {Promise>} A list of all Maps + */ + async getMaps() { + const data = await axios.get(`${this.baseURL}maps`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested map + * @param {string} uuid Map UUID + * @returns {Promise} Map Object + */ + async getMapByUuid(uuid) { + const data = await axios.get(`${this.baseURL}maps/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Player Cards Endpoints + + /** + * Returns data and assets of all player cards + * @returns {Promise>} A list of all Player Cards + */ + async getPlayerCards() { + const data = await axios.get(`${this.baseURL}playercards`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested player card + * @param {string} uuid Player Card UUID + * @returns {Promise} Player Card Object + */ + async getPlayerCardByUuid(uuid) { + const data = await axios.get(`${this.baseURL}playercards/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Player Titles Endpoints + + /** + * Returns data and assets of all player titles + * @returns {Promise>} A list of all Player Titles + */ + async getPlayerTitles() { + const data = await axios.get(`${this.baseURL}playertitles`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested player title + * @param {string} uuid Player Title UUID + * @returns {Promise} Player Title Object + */ + async getPlayerTitleByUuid(uuid) { + const data = await axios.get(`${this.baseURL}playertitles/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Seasons Endpoints + + /** + * Returns data and assets of all seasons + * @returns {Promise>} A list of all Seasons + */ + async getSeasons() { + const data = await axios.get(`${this.baseURL}seasons`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data of all competitive seasons + * @returns {Promise>} A list of all Competitive Seasons + */ + async getCompetitiveSeasons() { + const data = await axios.get(`${this.baseURL}seasons/competitive`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data of the requested season + * @param {string} uuid Season UUID + * @returns {Promise} Season Object + */ + async getSeasonByUuid(uuid) { + const data = await axios.get(`${this.baseURL}seasons/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data of the requested competitive season + * @param {string} uuid Competitive Season UUID + * @returns {Promise} Competitive Season Object + */ + async getCompetitiveSeasonByUuid(uuid) { + const data = await axios.get(`${this.baseURL}seasons/competitive/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Spray Endpoints + + /** + * Returns data and assets of all sprays + * @returns {Promise>} A list of all Seasons + */ + async getSprays() { + const data = await axios.get(`${this.baseURL}sprays`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of all spray levels + * @returns {Promise>} A list of all Sprays + */ + async getSprayLevels() { + const data = await axios.get(`${this.baseURL}sprays/levels`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested spray + * @param {string} uuid Spray UUID + * @returns {Promise} Spray Object + */ + async getSprayByUuid(uuid) { + const data = await axios.get(`${this.baseURL}sprays/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested spray level + * @param {string} uuid Spray Level UUID + * @returns {Promise} Spray Level Object + */ + async getSprayLevelByUuid(uuid) { + const data = await axios.get(`${this.baseURL}sprays/levels/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Theme Endpoints + + /** + * Returns data and assets of all themes + * @returns {Promise>} A list of all Themes + */ + async getThemes() { + const data = await axios.get(`${this.baseURL}themes`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested theme + * @param {string} uuid Theme UUID + * @returns {Promise} Theme Object + */ + async getThemeByUuid(uuid) { + const data = await axios.get(`${this.baseURL}themes/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + // Weapon Endpoints + + /** + * Returns data and assets of all weapons + * @returns {Promise>} A list of all Weapons + */ + async getWeapons() { + const data = await axios.get(`${this.baseURL}weapons`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of all weapon skins + * @returns {Promise>} A list of all Weapons + */ + async getWeaponsSkins() { + const data = await axios.get(`${this.baseURL}weapons/skins`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of all weapon skin chromas + * @returns {Promise>} A list of all Weapon Skins Chromas + */ + async getWeaponSkinChromas() { + const data = await axios.get(`${this.baseURL}weapons/skinchromas`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of all weapon skin levels + * @returns {Promise>} A list of all Weapon Skin Levels + */ + async getWeaponSkinLevels() { + const data = await axios.get(`${this.baseURL}weapons/skinlevels`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requeted weapon + * @param {string} uuid Weapon UUID + * @returns {Promise} Weapon Object + */ + async getWeaponByUuid(uuid) { + const data = await axios.get(`${this.baseURL}weapons/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requested weapon skin + * @param {string} uuid Weapon Skin UUID + * @returns {Promise} Weapon Skin Object + */ + async getWeaponSkinByUuid(uuid) { + const data = await axios.get(`${this.baseURL}weapons/skins/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requeted weapon skin chroma + * @param {string} uuid Weapon Skin Chroma UUID + * @returns {Promise} Weapon Skin Chroma Object + */ + async getWeaponSkinChromaByUuid(uuid) { + const data = await axios.get(`${this.baseURL}weapons/skinchromas/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } + + /** + * Returns data and assets of the requeted weapon skin level + * @param {string} uuid Weapon Skin Level UUID + * @returns {Promise} Weapon Skin Level Object + */ + async getWeaponSkinLevelByUuid(uuid) { + const data = await axios.get(`${this.baseURL}weapons/skinlevels/${uuid}`, { + params: { language: this.language }, + }); + return data.data.data; + } +} + +module.exports = ContentAPI; diff --git a/src/languages.js b/src/languages.js new file mode 100644 index 0000000..809c467 --- /dev/null +++ b/src/languages.js @@ -0,0 +1,22 @@ +const languages = { + Arabic: "ar-AE", + German: "de-DE", + English: "en-US", + Spanish_Spain: "es-ES", + Spanish_Mexico: "es-MX", + French: "fr-FR", + Indonesian: "id-ID", + Italien: "it-IT", + Japanese: "ja-JP", + Korean: "ko-KR", + Polish: "pl-PL", + Portuguese_Brazil: "pt-BR", + Russian: "ru-RU", + Thai: "th-TH", + Turkish: "tr-TR", + Vietnamese: "vi-VN", + Chinese_Simplified: "zh-CN", + Chinese_Traditional: "zh-TW", +}; + +module.exports = languages;