@timmsy/riftjs 2.0.2 → 2.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/.github/workflows/publish.yml +1 -0
- package/README.md +6 -0
- package/endpoints/riot.js +41 -0
- package/package.json +1 -1
- package/test-endpoints.js +6 -0
|
@@ -46,6 +46,7 @@ jobs:
|
|
|
46
46
|
run: |
|
|
47
47
|
echo "@timmsy:registry=https://npm.pkg.github.com" >> "$NPM_CONFIG_USERCONFIG"
|
|
48
48
|
echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> "$NPM_CONFIG_USERCONFIG"
|
|
49
|
+
npm pkg set name="@timmsy1998/riftjs"
|
|
49
50
|
npm publish --registry=https://npm.pkg.github.com
|
|
50
51
|
env:
|
|
51
52
|
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/README.md
CHANGED
|
@@ -100,6 +100,8 @@ fetchStaticData();
|
|
|
100
100
|
|
|
101
101
|
- `getAccountByRiotId(riotId, [tagLine], [region])`: Fetch account by Riot ID (e.g., `Timmsy#BRUV`).
|
|
102
102
|
- `getSummonerByPuuid(puuid, [region])`: Get summoner data by PUUID.
|
|
103
|
+
- `getRankEntriesByPuuid(puuid, [region])`: Get all League-V4 rank entries for a player PUUID.
|
|
104
|
+
- `getRankByPuuid(puuid, [region])`: Get rank split by Solo and Flex queues from a PUUID.
|
|
103
105
|
- `getMatchlistByPuuid(puuid, [options], [region])`: Get match history (options: `{ start, count }`).
|
|
104
106
|
- `getMatchById(matchId, [region])`: Get full match payload (`metadata` + `info`) by match ID.
|
|
105
107
|
- `getMatchTimelineById(matchId, [region])`: Get timeline payload by match ID.
|
|
@@ -118,6 +120,10 @@ fetchStaticData();
|
|
|
118
120
|
- `getMatchlistByPuuidAll`: `{ delayMs, maxMatches }`
|
|
119
121
|
- `getMatchesWithDetailsByPuuid`: `{ pageDelayMs, detailDelayMs, maxMatches }`
|
|
120
122
|
|
|
123
|
+
Rank queue mapping used by helper methods:
|
|
124
|
+
- Solo Queue: `RANKED_SOLO_5x5`
|
|
125
|
+
- Flex Queue: `RANKED_FLEX_SR`
|
|
126
|
+
|
|
121
127
|
### DataDragon
|
|
122
128
|
|
|
123
129
|
- `getChampions()`: Fetch all champion data.
|
package/endpoints/riot.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
2
|
+
const SOLO_QUEUE = 'RANKED_SOLO_5x5';
|
|
3
|
+
const FLEX_QUEUE = 'RANKED_FLEX_SR';
|
|
4
|
+
const withRankMetrics = (entry) => {
|
|
5
|
+
if (!entry) return null;
|
|
6
|
+
const wins = Number(entry.wins) || 0;
|
|
7
|
+
const losses = Number(entry.losses) || 0;
|
|
8
|
+
const gamesPlayed = wins + losses;
|
|
9
|
+
const winRate = gamesPlayed > 0 ? Number(((wins / gamesPlayed) * 100).toFixed(2)) : 0;
|
|
10
|
+
return { ...entry, winRate };
|
|
11
|
+
};
|
|
2
12
|
|
|
3
13
|
module.exports = (client, defaultRegion, regionMap) => ({
|
|
4
14
|
/**
|
|
@@ -46,6 +56,37 @@ module.exports = (client, defaultRegion, regionMap) => ({
|
|
|
46
56
|
}
|
|
47
57
|
},
|
|
48
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Fetch all ranked entries for a player PUUID.
|
|
61
|
+
* @param {string} puuid - Player PUUID.
|
|
62
|
+
* @param {string} [region] - Region code used to resolve platform routing.
|
|
63
|
+
* @returns {Promise<object[]>} Ranked entries from League-V4.
|
|
64
|
+
*/
|
|
65
|
+
async getRankEntriesByPuuid(puuid, region = defaultRegion) {
|
|
66
|
+
const platform = regionMap[region].platform;
|
|
67
|
+
try {
|
|
68
|
+
const response = await client.get(`/lol/league/v4/entries/by-puuid/${encodeURIComponent(puuid)}`, {
|
|
69
|
+
baseURL: `https://${platform}`,
|
|
70
|
+
});
|
|
71
|
+
return response.data;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw this._handleError(error);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Fetch ranked info split into Solo and Flex queues.
|
|
79
|
+
* @param {string} puuid - Player PUUID.
|
|
80
|
+
* @param {string} [region] - Region code used to resolve platform routing.
|
|
81
|
+
* @returns {Promise<{solo: object|null, flex: object|null, entries: object[]}>} Queue-split rank payload.
|
|
82
|
+
*/
|
|
83
|
+
async getRankByPuuid(puuid, region = defaultRegion) {
|
|
84
|
+
const entries = await this.getRankEntriesByPuuid(puuid, region);
|
|
85
|
+
const solo = withRankMetrics(entries.find((entry) => entry.queueType === SOLO_QUEUE) || null);
|
|
86
|
+
const flex = withRankMetrics(entries.find((entry) => entry.queueType === FLEX_QUEUE) || null);
|
|
87
|
+
return { solo, flex, entries };
|
|
88
|
+
},
|
|
89
|
+
|
|
49
90
|
/**
|
|
50
91
|
* Fetch match IDs for a PUUID from Match-V5.
|
|
51
92
|
* @param {string} puuid - Player PUUID.
|
package/package.json
CHANGED
package/test-endpoints.js
CHANGED
|
@@ -17,6 +17,12 @@ async function run() {
|
|
|
17
17
|
summonerLevel: summoner.summonerLevel,
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
const rank = await riot.getRankByPuuid(account.puuid);
|
|
21
|
+
console.log('[PASS] getRankByPuuid:', {
|
|
22
|
+
solo: rank.solo ? `${rank.solo.tier} ${rank.solo.rank} | ${rank.solo.leaguePoints} LP | ${rank.solo.wins}W-${rank.solo.losses}L | ${rank.solo.winRate}% WR` : null,
|
|
23
|
+
flex: rank.flex ? `${rank.flex.tier} ${rank.flex.rank} | ${rank.flex.leaguePoints} LP | ${rank.flex.wins}W-${rank.flex.losses}L | ${rank.flex.winRate}% WR` : null,
|
|
24
|
+
});
|
|
25
|
+
|
|
20
26
|
const matchIds = await riot.getMatchlistByPuuid(account.puuid, { start: 0, count: 3 });
|
|
21
27
|
console.log('[PASS] getMatchlistByPuuid:', matchIds.length, 'match ids');
|
|
22
28
|
|