@timmsy/riftjs 1.0.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +152 -0
- package/endpoints/datadragon.js +29 -0
- package/endpoints/riot.js +84 -0
- package/index.js +29 -32
- package/package.json +14 -2
package/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# RiftJS
|
|
2
|
+
|
|
3
|
+
A lightweight Node.js wrapper for the Riot Games API, providing easy access to League of Legends game data.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@timmsy/riftjs)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
RiftJS simplifies interaction with the Riot Games API and DataDragon static data. It supports fetching account details, summoner info, match history, and game data using a modular endpoint structure. Built with `axios` and `dotenv`, it’s designed for developers building League of Legends tools or applications.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **RiotAPI**: Fetch account data by Riot ID, summoner data by PUUID, match history, and match details.
|
|
15
|
+
- **DataDragon**: Access static game data like champions and items.
|
|
16
|
+
- **Region Support**: Handles platform (e.g., `EUW1`) and shard (e.g., `europe`) routing.
|
|
17
|
+
- **Modular Design**: Endpoints are organized in an `/endpoints/` directory for easy extension.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install RiftJS via npm:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
npm install @timmsy/riftjs
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
You’ll also need a Riot Games API key from [developer.riotgames.com](https://developer.riotgames.com/).
|
|
28
|
+
|
|
29
|
+
## Setup
|
|
30
|
+
|
|
31
|
+
1. **Install Dependencies**:
|
|
32
|
+
Ensure you have Node.js installed, then run the install command above.
|
|
33
|
+
|
|
34
|
+
2. **Configure Environment**:
|
|
35
|
+
Create a `.env` file in your project root with your API key and region:
|
|
36
|
+
```
|
|
37
|
+
RIOT_API_KEY=RGAPI-your-api-key-here
|
|
38
|
+
REGION=EUW1
|
|
39
|
+
```
|
|
40
|
+
- Replace `RGAPI-your-api-key-here` with your API key.
|
|
41
|
+
- Use a short region code (e.g., `EUW1`, `NA1`). See [Region Mapping](#region-mapping) for details.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
Here’s a basic example to get started:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
const { RiotAPI, DataDragon } = require('@timmsy/riftjs');
|
|
49
|
+
|
|
50
|
+
// Initialize RiotAPI
|
|
51
|
+
const riot = new RiotAPI();
|
|
52
|
+
|
|
53
|
+
// Fetch account, summoner, and match data
|
|
54
|
+
async function fetchPlayerData() {
|
|
55
|
+
try {
|
|
56
|
+
const account = await riot.getAccountByRiotId('Timmsy#BRUV');
|
|
57
|
+
console.log('Account:', account);
|
|
58
|
+
|
|
59
|
+
const summoner = await riot.getSummonerByPuuid(account.puuid);
|
|
60
|
+
console.log('Summoner:', summoner);
|
|
61
|
+
|
|
62
|
+
const matchlist = await riot.getMatchlistByPuuid(account.puuid, { start: 0, count: 5 });
|
|
63
|
+
console.log('Matchlist:', matchlist);
|
|
64
|
+
|
|
65
|
+
const match = await riot.getMatchById(matchlist[0]);
|
|
66
|
+
console.log('Match:', match);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Error:', error.message);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Initialize DataDragon
|
|
73
|
+
const dd = new DataDragon();
|
|
74
|
+
|
|
75
|
+
async function fetchStaticData() {
|
|
76
|
+
try {
|
|
77
|
+
const champions = await dd.getChampions();
|
|
78
|
+
console.log('Champions:', champions.data);
|
|
79
|
+
|
|
80
|
+
const items = await dd.getItems();
|
|
81
|
+
console.log('Items:', items.data);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Error:', error.message);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Run the examples
|
|
88
|
+
fetchPlayerData();
|
|
89
|
+
fetchStaticData();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## API Reference
|
|
93
|
+
|
|
94
|
+
### RiotAPI
|
|
95
|
+
- `getAccountByRiotId(riotId, [tagLine], [region])`: Fetch account by Riot ID (e.g., `Timmsy#BRUV`).
|
|
96
|
+
- `getSummonerByPuuid(puuid, [region])`: Get summoner data by PUUID.
|
|
97
|
+
- `getMatchlistByPuuid(puuid, [options], [region])`: Get match history (options: `{ start, count }`).
|
|
98
|
+
- `getMatchById(matchId, [region])`: Get match details.
|
|
99
|
+
|
|
100
|
+
### DataDragon
|
|
101
|
+
- `getChampions()`: Fetch all champion data.
|
|
102
|
+
- `getItems()`: Fetch all item data.
|
|
103
|
+
|
|
104
|
+
## Region Mapping
|
|
105
|
+
|
|
106
|
+
RiftJS uses a region map to route requests correctly:
|
|
107
|
+
- **Platform Routing** (e.g., Summoner V4):
|
|
108
|
+
- `EUW1` → `euw1.api.riotgames.com`
|
|
109
|
+
- `NA1` → `na1.api.riotgames.com`
|
|
110
|
+
- **Shard Routing** (e.g., Account V1, Match V5):
|
|
111
|
+
- `EUW1` → `europe.api.riotgames.com`
|
|
112
|
+
- `NA1` → `americas.api.riotgames.com`
|
|
113
|
+
|
|
114
|
+
Supported regions: `BR1`, `EUN1`, `EUW1`, `JP1`, `KR`, `LA1`, `LA2`, `NA1`, `OC1`, `TR1`, `RU`, `PH2`, `SG2`, `TH2`, `TW2`, `VN2`.
|
|
115
|
+
|
|
116
|
+
## Keywords
|
|
117
|
+
|
|
118
|
+
- riot-api
|
|
119
|
+
- league-of-legends
|
|
120
|
+
- lol-api
|
|
121
|
+
- datadragon
|
|
122
|
+
- summoner
|
|
123
|
+
- match-history
|
|
124
|
+
- game-data
|
|
125
|
+
- node-js
|
|
126
|
+
- javascript
|
|
127
|
+
- api-wrapper
|
|
128
|
+
|
|
129
|
+
## Development
|
|
130
|
+
|
|
131
|
+
To contribute or run locally:
|
|
132
|
+
1. Clone the repo:
|
|
133
|
+
```
|
|
134
|
+
git clone https://github.com/timmsy1998/RiftJS.git
|
|
135
|
+
cd RiftJS
|
|
136
|
+
```
|
|
137
|
+
2. Install dependencies:
|
|
138
|
+
```
|
|
139
|
+
npm install
|
|
140
|
+
```
|
|
141
|
+
3. Create a `.env` file (see [Setup](#setup)).
|
|
142
|
+
4. Test with `node test.js` (requires a valid API key).
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT License © 2025 James Timms. See [LICENSE](LICENSE) for details.
|
|
147
|
+
|
|
148
|
+
## Links
|
|
149
|
+
|
|
150
|
+
- **npm Registry**: [https://www.npmjs.com/package/@timmsy/riftjs](https://www.npmjs.com/package/@timmsy/riftjs)
|
|
151
|
+
- **GitHub Repository**: [https://github.com/timmsy1998/RiftJS](https://github.com/timmsy1998/RiftJS)
|
|
152
|
+
- **Riot Developer Portal**: [https://developer.riotgames.com/](https://developer.riotgames.com/)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
|
|
3
|
+
module.exports = (baseURL) => ({
|
|
4
|
+
/**
|
|
5
|
+
* Get all champion data.
|
|
6
|
+
* @returns {Promise<object>} Champion data.
|
|
7
|
+
*/
|
|
8
|
+
async getChampions() {
|
|
9
|
+
try {
|
|
10
|
+
const response = await axios.get(`${baseURL}/champion.json`);
|
|
11
|
+
return response.data;
|
|
12
|
+
} catch (error) {
|
|
13
|
+
throw new Error(`DataDragon error: ${error.message}`);
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get all item data.
|
|
19
|
+
* @returns {Promise<object>} Item data.
|
|
20
|
+
*/
|
|
21
|
+
async getItems() {
|
|
22
|
+
try {
|
|
23
|
+
const response = await axios.get(`${baseURL}/item.json`);
|
|
24
|
+
return response.data;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error(`DataDragon error: ${error.message}`);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
module.exports = (client, defaultRegion, regionMap) => ({
|
|
2
|
+
/**
|
|
3
|
+
* Get account info by Riot ID (gameName and tagLine).
|
|
4
|
+
* @param {string} riotId - Riot ID (e.g., "Timmsy#BRUV" or "Timmsy", "BRUV").
|
|
5
|
+
* @param {string} [tagLine] - Optional tagLine if not included in riotId.
|
|
6
|
+
* @param {string} [region] - Short region (defaults to constructor region).
|
|
7
|
+
* @returns {Promise<object>} Account data including puuid.
|
|
8
|
+
*/
|
|
9
|
+
async getAccountByRiotId(riotId, tagLine = null, region = defaultRegion) {
|
|
10
|
+
let gameName, tag;
|
|
11
|
+
if (riotId.includes('#')) {
|
|
12
|
+
[gameName, tag] = riotId.split('#');
|
|
13
|
+
} else {
|
|
14
|
+
gameName = riotId;
|
|
15
|
+
tag = tagLine || '';
|
|
16
|
+
}
|
|
17
|
+
if (!tag) throw new Error('TagLine is required for getAccountByRiotId');
|
|
18
|
+
const shard = regionMap[region].shard;
|
|
19
|
+
try {
|
|
20
|
+
const response = await client.get(`/riot/account/v1/accounts/by-riot-id/${encodeURIComponent(gameName)}/${encodeURIComponent(tag)}`, {
|
|
21
|
+
baseURL: `https://${shard}`,
|
|
22
|
+
});
|
|
23
|
+
return response.data;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw this._handleError(error);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get summoner data by PUUID.
|
|
31
|
+
* @param {string} puuid - Encrypted PUUID.
|
|
32
|
+
* @param {string} [region] - Short region (defaults to constructor region).
|
|
33
|
+
* @returns {Promise<object>} Summoner data.
|
|
34
|
+
*/
|
|
35
|
+
async getSummonerByPuuid(puuid, region = defaultRegion) {
|
|
36
|
+
const platform = regionMap[region].platform;
|
|
37
|
+
try {
|
|
38
|
+
const response = await client.get(`/lol/summoner/v4/summoners/by-puuid/${encodeURIComponent(puuid)}`, {
|
|
39
|
+
baseURL: `https://${platform}`,
|
|
40
|
+
});
|
|
41
|
+
return response.data;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw this._handleError(error);
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get match history by PUUID.
|
|
49
|
+
* @param {string} puuid - Summoner's PUUID.
|
|
50
|
+
* @param {object} [options] - Query options (e.g., start, count).
|
|
51
|
+
* @param {string} [region] - Short region (defaults to constructor region).
|
|
52
|
+
* @returns {Promise<string[]>} Array of match IDs.
|
|
53
|
+
*/
|
|
54
|
+
async getMatchlistByPuuid(puuid, options = {}, region = defaultRegion) {
|
|
55
|
+
const shard = regionMap[region].shard;
|
|
56
|
+
try {
|
|
57
|
+
const response = await client.get(`/lol/match/v5/matches/by-puuid/${encodeURIComponent(puuid)}/ids`, {
|
|
58
|
+
baseURL: `https://${shard}`,
|
|
59
|
+
params: options,
|
|
60
|
+
});
|
|
61
|
+
return response.data;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw this._handleError(error);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Get match details by match ID.
|
|
69
|
+
* @param {string} matchId - Match ID (e.g., "EUW1_1234567890").
|
|
70
|
+
* @param {string} [region] - Short region (defaults to constructor region).
|
|
71
|
+
* @returns {Promise<object>} Match data.
|
|
72
|
+
*/
|
|
73
|
+
async getMatchById(matchId, region = defaultRegion) {
|
|
74
|
+
const shard = regionMap[region].shard;
|
|
75
|
+
try {
|
|
76
|
+
const response = await client.get(`/lol/match/v5/matches/${matchId}`, {
|
|
77
|
+
baseURL: `https://${shard}`,
|
|
78
|
+
});
|
|
79
|
+
return response.data;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw this._handleError(error);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
});
|
package/index.js
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
require('dotenv').config();
|
|
2
2
|
const axios = require('axios');
|
|
3
|
+
const riotEndpoints = require('./endpoints/riot');
|
|
4
|
+
const dataDragonEndpoints = require('./endpoints/datadragon');
|
|
5
|
+
|
|
6
|
+
// Region mapping: short region to shard
|
|
7
|
+
const regionMap = {
|
|
8
|
+
// Platform Routing (short regions)
|
|
9
|
+
BR1: { platform: 'br1.api.riotgames.com', shard: 'americas.api.riotgames.com' },
|
|
10
|
+
EUN1: { platform: 'eun1.api.riotgames.com', shard: 'europe.api.riotgames.com' },
|
|
11
|
+
EUW1: { platform: 'euw1.api.riotgames.com', shard: 'europe.api.riotgames.com' },
|
|
12
|
+
JP1: { platform: 'jp1.api.riotgames.com', shard: 'asia.api.riotgames.com' },
|
|
13
|
+
KR: { platform: 'kr.api.riotgames.com', shard: 'asia.api.riotgames.com' },
|
|
14
|
+
LA1: { platform: 'la1.api.riotgames.com', shard: 'americas.api.riotgames.com' },
|
|
15
|
+
LA2: { platform: 'la2.api.riotgames.com', shard: 'americas.api.riotgames.com' },
|
|
16
|
+
NA1: { platform: 'na1.api.riotgames.com', shard: 'americas.api.riotgames.com' },
|
|
17
|
+
OC1: { platform: 'oc1.api.riotgames.com', shard: 'sea.api.riotgames.com' },
|
|
18
|
+
TR1: { platform: 'tr1.api.riotgames.com', shard: 'europe.api.riotgames.com' },
|
|
19
|
+
RU: { platform: 'ru.api.riotgames.com', shard: 'europe.api.riotgames.com' },
|
|
20
|
+
PH2: { platform: 'ph2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
|
|
21
|
+
SG2: { platform: 'sg2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
|
|
22
|
+
TH2: { platform: 'th2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
|
|
23
|
+
TW2: { platform: 'tw2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
|
|
24
|
+
VN2: { platform: 'vn2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
|
|
25
|
+
};
|
|
3
26
|
|
|
4
27
|
/**
|
|
5
28
|
* RiotAPI class for interacting with Riot Games API endpoints.
|
|
@@ -8,28 +31,13 @@ class RiotAPI {
|
|
|
8
31
|
constructor() {
|
|
9
32
|
this.apiKey = process.env.RIOT_API_KEY;
|
|
10
33
|
if (!this.apiKey) throw new Error('RIOT_API_KEY is required in .env');
|
|
11
|
-
this.region = process.env.REGION || '
|
|
34
|
+
this.region = (process.env.REGION || 'EUW1').toUpperCase();
|
|
35
|
+
if (!regionMap[this.region]) throw new Error(`Invalid region: ${this.region}`);
|
|
12
36
|
this.client = axios.create({
|
|
13
|
-
baseURL: `https://${this.region}.api.riotgames.com`,
|
|
14
37
|
headers: { 'X-Riot-Token': this.apiKey },
|
|
15
38
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get summoner data by name.
|
|
20
|
-
* @param {string} name - Summoner name.
|
|
21
|
-
* @param {string} [region] - Region (defaults to constructor region).
|
|
22
|
-
* @returns {Promise<object>} Summoner data.
|
|
23
|
-
*/
|
|
24
|
-
async getSummonerByName(name, region = this.region) {
|
|
25
|
-
try {
|
|
26
|
-
const response = await this.client.get(`/lol/summoner/v4/summoners/by-name/${encodeURIComponent(name)}`, {
|
|
27
|
-
baseURL: `https://${region}.api.riotgames.com`,
|
|
28
|
-
});
|
|
29
|
-
return response.data;
|
|
30
|
-
} catch (error) {
|
|
31
|
-
throw this._handleError(error);
|
|
32
|
-
}
|
|
39
|
+
// Attach RiotAPI endpoints with region map
|
|
40
|
+
Object.assign(this, riotEndpoints(this.client, this.region, regionMap));
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
/**
|
|
@@ -55,19 +63,8 @@ class DataDragon {
|
|
|
55
63
|
this.version = version;
|
|
56
64
|
this.locale = locale;
|
|
57
65
|
this.baseURL = `https://ddragon.leagueoflegends.com/cdn/${this.version}/data/${this.locale}`;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Get all champion data.
|
|
62
|
-
* @returns {Promise<object>} Champion data.
|
|
63
|
-
*/
|
|
64
|
-
async getChampions() {
|
|
65
|
-
try {
|
|
66
|
-
const response = await axios.get(`${this.baseURL}/champion.json`);
|
|
67
|
-
return response.data;
|
|
68
|
-
} catch (error) {
|
|
69
|
-
throw new Error(`DataDragon error: ${error.message}`);
|
|
70
|
-
}
|
|
66
|
+
// Attach DataDragon endpoints
|
|
67
|
+
Object.assign(this, dataDragonEndpoints(this.baseURL));
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timmsy/riftjs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -9,6 +9,18 @@
|
|
|
9
9
|
"axios": "^1.7.7",
|
|
10
10
|
"dotenv": "^16.4.5"
|
|
11
11
|
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"riot-api",
|
|
14
|
+
"league-of-legends",
|
|
15
|
+
"lol-api",
|
|
16
|
+
"datadragon",
|
|
17
|
+
"summoner",
|
|
18
|
+
"match-history",
|
|
19
|
+
"game-data",
|
|
20
|
+
"node-js",
|
|
21
|
+
"javascript",
|
|
22
|
+
"api-wrapper"
|
|
23
|
+
],
|
|
12
24
|
"author": "James Timms",
|
|
13
25
|
"description": "A lightweight Node.js wrapper for the Riot Games API, providing easy access to League of Legends game data.",
|
|
14
26
|
"license": "MIT",
|
|
@@ -16,4 +28,4 @@
|
|
|
16
28
|
"type": "git",
|
|
17
29
|
"url": "git+https://github.com/timmsy1998/RiftJS.git"
|
|
18
30
|
}
|
|
19
|
-
}
|
|
31
|
+
}
|