@timmsy/riftjs 2.1.0 → 3.1.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/index.js DELETED
@@ -1,88 +0,0 @@
1
- require('dotenv').config();
2
- const axios = require('axios');
3
- const riotEndpoints = require('./endpoints/riot');
4
- const dataDragonEndpoints = require('./endpoints/datadragon');
5
-
6
- // Maps region codes to the platform and routing shard hosts required by Riot APIs.
7
- const regionMap = {
8
- BR1: { platform: 'br1.api.riotgames.com', shard: 'americas.api.riotgames.com' },
9
- EUN1: { platform: 'eun1.api.riotgames.com', shard: 'europe.api.riotgames.com' },
10
- EUW1: { platform: 'euw1.api.riotgames.com', shard: 'europe.api.riotgames.com' },
11
- JP1: { platform: 'jp1.api.riotgames.com', shard: 'asia.api.riotgames.com' },
12
- KR: { platform: 'kr.api.riotgames.com', shard: 'asia.api.riotgames.com' },
13
- LA1: { platform: 'la1.api.riotgames.com', shard: 'americas.api.riotgames.com' },
14
- LA2: { platform: 'la2.api.riotgames.com', shard: 'americas.api.riotgames.com' },
15
- NA1: { platform: 'na1.api.riotgames.com', shard: 'americas.api.riotgames.com' },
16
- OC1: { platform: 'oc1.api.riotgames.com', shard: 'sea.api.riotgames.com' },
17
- TR1: { platform: 'tr1.api.riotgames.com', shard: 'europe.api.riotgames.com' },
18
- RU: { platform: 'ru.api.riotgames.com', shard: 'europe.api.riotgames.com' },
19
- PH2: { platform: 'ph2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
20
- SG2: { platform: 'sg2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
21
- TH2: { platform: 'th2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
22
- TW2: { platform: 'tw2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
23
- VN2: { platform: 'vn2.api.riotgames.com', shard: 'sea.api.riotgames.com' },
24
- };
25
-
26
- class RiotAPI {
27
- constructor() {
28
- this.apiKey = process.env.RIOT_API_KEY;
29
- if (!this.apiKey) throw new Error('RIOT_API_KEY is required in .env');
30
- this.region = (process.env.REGION || 'EUW1').toUpperCase();
31
- if (!regionMap[this.region]) throw new Error(`Invalid region: ${this.region}`);
32
- this.client = axios.create({
33
- headers: { 'X-Riot-Token': this.apiKey },
34
- });
35
- // Attach endpoint methods with a shared axios client and region configuration.
36
- Object.assign(this, riotEndpoints(this.client, this.region, regionMap));
37
- }
38
-
39
- // Normalize axios errors to stable Error messages for consumers.
40
- _handleError(error) {
41
- if (error.response) {
42
- const { status, data } = error.response;
43
- return new Error(`API error ${status}: ${data.status?.message || 'Unknown error'}`);
44
- } else if (error.request) {
45
- return new Error('No response received from the server');
46
- }
47
- return new Error(`Request error: ${error.message}`);
48
- }
49
- }
50
-
51
- class DataDragon {
52
- constructor(version = null, locale = 'en_US') {
53
- this.version = version;
54
- this.locale = locale;
55
- this.baseURL = null;
56
- this._baseURLPromise = null;
57
-
58
- // Attach static-data endpoint methods that resolve the latest version when needed.
59
- Object.assign(this, dataDragonEndpoints(() => this._resolveBaseURL()));
60
- }
61
-
62
- async _resolveBaseURL() {
63
- if (this.baseURL) return this.baseURL;
64
- if (this._baseURLPromise) return this._baseURLPromise;
65
-
66
- this._baseURLPromise = (async () => {
67
- if (!this.version) {
68
- const response = await axios.get('https://ddragon.leagueoflegends.com/api/versions.json');
69
- const latestVersion = Array.isArray(response.data) ? response.data[0] : null;
70
- if (!latestVersion) {
71
- throw new Error('Could not resolve latest Data Dragon version');
72
- }
73
- this.version = latestVersion;
74
- }
75
-
76
- this.baseURL = `https://ddragon.leagueoflegends.com/cdn/${this.version}/data/${this.locale}`;
77
- return this.baseURL;
78
- })();
79
-
80
- try {
81
- return await this._baseURLPromise;
82
- } finally {
83
- this._baseURLPromise = null;
84
- }
85
- }
86
- }
87
-
88
- module.exports = { RiotAPI, DataDragon };