r6-data.js 1.8.3 → 2.0.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.
@@ -1,39 +1,47 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege player account information
6
- * @param {Object} params - Parameters for the request
7
- * @param {string} params.nameOnPlatform - Player name on the platform
8
- * @param {string} params.platformType - Platform type (uplay, psn, xbl)
9
- * @returns {Promise<Object>} - Player account information
10
- */
11
- async function getAccountInfo({ nameOnPlatform, platformType } = {}) {
12
- try {
13
- // Validate required parameters
14
- if (!nameOnPlatform || !platformType) {
15
- throw new Error('Missing required parameters: nameOnPlatform, platformType');
16
- }
17
-
18
- // Build the URL with parameters
19
- const params = {
20
- type: 'accountInfo',
21
- nameOnPlatform,
22
- platformType
23
- };
24
-
25
- const url = buildUrlAndParams('/stats', params);
26
-
27
- const response = await axiosInstance.get(url);
28
-
29
- return response.data;
30
- } catch (error) {
31
- console.error('Error during the getAccountInfo request:', error.message);
32
- if (error.response && error.response.status === 401) {
33
- throw new Error('Authentication error');
34
- }
35
- throw error;
36
- }
37
- }
38
-
39
- module.exports = getAccountInfo;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege player account information
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @param {Object} params - Parameters for the request
8
+ * @param {string} params.nameOnPlatform - Player name on the platform
9
+ * @param {string} params.platformType - Platform type (uplay, psn, xbl)
10
+ * @returns {Promise<Object>} - Player account information
11
+ */
12
+ async function getAccountInfo(apiKey, { nameOnPlatform, platformType } = {}) {
13
+ try {
14
+ // Validate required parameters
15
+ if (!apiKey) {
16
+ throw new Error('Missing required parameter: apiKey');
17
+ }
18
+ if (!nameOnPlatform || !platformType) {
19
+ throw new Error('Missing required parameters: nameOnPlatform, platformType');
20
+ }
21
+
22
+ // Build the URL with parameters
23
+ const params = {
24
+ type: 'accountInfo',
25
+ nameOnPlatform,
26
+ platformType
27
+ };
28
+
29
+ const url = buildUrlAndParams('/stats', params);
30
+
31
+ const response = await axiosInstance.get(url, {
32
+ headers: {
33
+ 'api-key': apiKey
34
+ }
35
+ });
36
+
37
+ return response.data;
38
+ } catch (error) {
39
+ console.error('Error during the getAccountInfo request:', error.message);
40
+ if (error.response && error.response.status === 401) {
41
+ throw new Error('Authentication error');
42
+ }
43
+ throw error;
44
+ }
45
+ }
46
+
47
+ module.exports = getAccountInfo;
@@ -1,21 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getAttachment({ name, style, rarity, availability, bundle, season } = {}) {
5
- try {
6
-
7
- const url = buildUrlAndParams('/attachment', { name, style, rarity, availability, bundle, season });
8
-
9
- const response = await axiosInstance.get(url);
10
-
11
- return response.data;
12
- } catch (error) {
13
- console.error('Error during the getAttachment request:', error.message);
14
- if (error.response && error.response.status === 401) {
15
- throw new Error('request error');
16
- }
17
- throw error;
18
- }
19
- }
20
-
21
- module.exports = getAttachment;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getAttachment(apiKey, { name, style, rarity, availability, bundle, season } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/attachment', { name, style, rarity, availability, bundle, season });
11
+
12
+ const response = await axiosInstance.get(url, {
13
+ headers: {
14
+ 'api-key': apiKey
15
+ }
16
+ });
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error('Error during the getAttachment request:', error.message);
21
+ if (error.response && error.response.status === 401) {
22
+ throw new Error('request error');
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ module.exports = getAttachment;
@@ -1,21 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getCharms({ name, collection, rarity, availability, bundle, season } = {}) {
5
- try {
6
-
7
- const url = buildUrlAndParams('/charms', { name, collection, rarity, availability, bundle, season });
8
-
9
- const response = await axiosInstance.get(url);
10
-
11
- return response.data;
12
- } catch (error) {
13
- console.error('Errore during the getCharms request:', error.message);
14
- if (error.response && error.response.status === 401) {
15
- throw new Error('request error');
16
- }
17
- throw error;
18
- }
19
- }
20
-
21
- module.exports = getCharms;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getCharms(apiKey, { name, collection, rarity, availability, bundle, season } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/charms', { name, collection, rarity, availability, bundle, season });
11
+
12
+ const response = await axiosInstance.get(url, {
13
+ headers: {
14
+ 'api-key': apiKey
15
+ }
16
+ });
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error('Errore during the getCharms request:', error.message);
21
+ if (error.response && error.response.status === 401) {
22
+ throw new Error('request error');
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ module.exports = getCharms;
@@ -1,30 +1,38 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege game stats for all platform
6
- * @returns {Promise<Object>} - Game stats for all platform
7
- */
8
- async function getGameStats() {
9
- try {
10
-
11
- // Build the URL with parameters
12
- const params = {
13
- type: 'gameStats'
14
- };
15
-
16
- const url = buildUrlAndParams('/stats', params);
17
-
18
- const response = await axiosInstance.get(url);
19
-
20
- return response.data;
21
- } catch (error) {
22
- console.error('Error during the game stats request:', error.message);
23
- if (error.response && error.response.status === 401) {
24
- throw new Error('request error');
25
- }
26
- throw error;
27
- }
28
- }
29
-
30
- module.exports = getGameStats;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege game stats for all platform
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @returns {Promise<Object>} - Game stats for all platform
8
+ */
9
+ async function getGameStats(apiKey) {
10
+ try {
11
+ if (!apiKey) {
12
+ throw new Error('Missing required parameter: apiKey');
13
+ }
14
+
15
+ // Build the URL with parameters
16
+ const params = {
17
+ type: 'gameStats'
18
+ };
19
+
20
+ const url = buildUrlAndParams('/stats', params);
21
+
22
+ const response = await axiosInstance.get(url, {
23
+ headers: {
24
+ 'api-key': apiKey
25
+ }
26
+ });
27
+
28
+ return response.data;
29
+ } catch (error) {
30
+ console.error('Error during the game stats request:', error.message);
31
+ if (error.response && error.response.status === 401) {
32
+ throw new Error('request error');
33
+ }
34
+ throw error;
35
+ }
36
+ }
37
+
38
+ module.exports = getGameStats;
@@ -3,14 +3,18 @@ const buildUrlAndParams = require('./util');
3
3
 
4
4
  /**
5
5
  * Get Rainbow Six Siege player ban status
6
+ * @param {string} apiKey - Your API Key from r6data.eu
6
7
  * @param {Object} params - Parameters for the request
7
8
  * @param {string} params.nameOnPlatform - Player name on the platform
8
9
  * @param {string} params.platformType - Platform type (uplay, psn, xbl)
9
10
  * @returns {Promise<Object>} - Player ban status
10
11
  */
11
- async function getIsBanned({ nameOnPlatform, platformType } = {}) {
12
+ async function getIsBanned(apiKey, { nameOnPlatform, platformType } = {}) {
12
13
  try {
13
14
  // Validate required parameters
15
+ if (!apiKey) {
16
+ throw new Error('Missing required parameter: apiKey');
17
+ }
14
18
  if (!nameOnPlatform || !platformType) {
15
19
  throw new Error('Missing required parameters: nameOnPlatform, platformType');
16
20
  }
@@ -24,7 +28,11 @@ async function getIsBanned({ nameOnPlatform, platformType } = {}) {
24
28
 
25
29
  const url = buildUrlAndParams('/stats', params);
26
30
 
27
- const response = await axiosInstance.get(url);
31
+ const response = await axiosInstance.get(url, {
32
+ headers: {
33
+ 'api-key': apiKey
34
+ }
35
+ });
28
36
 
29
37
  return response.data;
30
38
  } catch (error) {
@@ -1,21 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getMaps({ name, location, releaseDate, playlists, mapReworked } = {}) {
5
- try {
6
-
7
- const url = buildUrlAndParams('/maps', { name, location, releaseDate, playlists, mapReworked });
8
-
9
- const response = await axiosInstance.get(url);
10
-
11
- return response.data;
12
- } catch (error) {
13
- console.error('Error during the getMaps request:', error.message);
14
- if (error.response && error.response.status === 401) {
15
- throw new Error('request error');
16
- }
17
- throw error;
18
- }
19
- }
20
-
21
- module.exports = getMaps;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getMaps(apiKey, { name, location, releaseDate, playlists, mapReworked } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/maps', { name, location, releaseDate, playlists, mapReworked });
11
+
12
+ const response = await axiosInstance.get(url, {
13
+ headers: {
14
+ 'api-key': apiKey
15
+ }
16
+ });
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error('Error during the getMaps request:', error.message);
21
+ if (error.response && error.response.status === 401) {
22
+ throw new Error('request error');
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ module.exports = getMaps;
@@ -1,21 +1,28 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getOperators({ name, safename, realname, birthplace, age, date_of_birth, season_introduced, health, speed, unit, country_code, roles, side } = {}) {
5
- try {
6
-
7
- const url = buildUrlAndParams('/operators', { name, safename, realname, birthplace, age, date_of_birth, season_introduced, health, speed, unit, country_code, roles, side });
8
-
9
- const response = await axiosInstance.get(url);
10
-
11
- return response.data;
12
- } catch (error) {
13
- console.error('Error during the getOperators request:', error.message);
14
- if (error.response && error.response.status === 401) {
15
- throw new Error('request error');
16
- }
17
- throw error;
18
- }
19
- }
20
-
21
- module.exports = getOperators;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getOperators(apiKey, { name, safename, realname, birthplace, age, date_of_birth, season_introduced, health, speed, unit, country_code, roles, side } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ const url = buildUrlAndParams('/operators', { name, safename, realname, birthplace, age, date_of_birth, season_introduced, health, speed, unit, country_code, roles, side });
11
+
12
+ const response = await axiosInstance.get(url, {
13
+ headers: {
14
+ 'api-key': apiKey
15
+ }
16
+ });
17
+
18
+ return response.data;
19
+ } catch (error) {
20
+ console.error('Error during the getOperators request:', error.message);
21
+ if (error.response && error.response.status === 401) {
22
+ throw new Error('request error');
23
+ }
24
+ throw error;
25
+ }
26
+ }
27
+
28
+ module.exports = getOperators;
@@ -3,6 +3,7 @@ const buildUrlAndParams = require('./util');
3
3
 
4
4
  /**
5
5
  * Compare Rainbow Six Siege player statistics between multiple players
6
+ * @param {string} apiKey - Your API Key from r6data.eu
6
7
  * @param {Object} params - Parameters for the request
7
8
  * @param {Array<Object>} params.players - Array of player objects to compare
8
9
  * @param {string} params.players[].nameOnPlatform - Player name on the platform
@@ -12,9 +13,12 @@ const buildUrlAndParams = require('./util');
12
13
  * @param {Array<string>} [params.compareFields] - Specific fields to compare (e.g., ['kills', 'deaths', 'wins', 'losses'])
13
14
  * @returns {Promise<Object>} - Comparison results with player statistics and comparison metrics
14
15
  */
15
- async function getPlayerComparisons({ players, platform_families, board_id, compareFields } = {}) {
16
+ async function getPlayerComparisons(apiKey, { players, platform_families, board_id, compareFields } = {}) {
16
17
  try {
17
18
  // Validate required parameters
19
+ if (!apiKey) {
20
+ throw new Error('Missing required parameter: apiKey');
21
+ }
18
22
  if (!players || !Array.isArray(players) || players.length < 2) {
19
23
  throw new Error('At least 2 players are required for comparison');
20
24
  }
@@ -54,7 +58,11 @@ async function getPlayerComparisons({ players, platform_families, board_id, comp
54
58
  }
55
59
 
56
60
  const url = buildUrlAndParams('/stats', params);
57
- const response = await axiosInstance.get(url);
61
+ const response = await axiosInstance.get(url, {
62
+ headers: {
63
+ 'api-key': apiKey
64
+ }
65
+ });
58
66
 
59
67
  if (response.data &&
60
68
  response.data.platform_families_full_profiles &&
@@ -97,138 +105,17 @@ async function getPlayerComparisons({ players, platform_families, board_id, comp
97
105
  });
98
106
  }
99
107
  }
100
-
101
- // Generate comparison results
102
- const comparison = {
103
- players: playerStats,
104
- comparison_summary: generateComparisonSummary(playerStats, compareFields),
105
- metadata: {
106
- total_players: players.length,
107
- successful_fetches: playerStats.filter(p => p.success).length,
108
- failed_fetches: playerStats.filter(p => !p.success).length,
109
- platform_families,
110
- board_id: board_id || 'all',
111
- timestamp: new Date().toISOString()
112
- }
108
+
109
+ // Logic for comparison could be added here if needed, but returning collected stats for now
110
+ return {
111
+ comparisons: playerStats,
112
+ errors: errors.length > 0 ? errors : undefined
113
113
  };
114
114
 
115
- if (errors.length > 0) {
116
- comparison.errors = errors;
117
- }
118
-
119
- return comparison;
120
-
121
115
  } catch (error) {
122
116
  console.error('Error during the getPlayerComparisons request:', error.message);
123
- if (error.response && error.response.status === 401) {
124
- throw new Error('Authentication error');
125
- }
126
117
  throw error;
127
118
  }
128
119
  }
129
120
 
130
- /**
131
- * Generate comparison summary between players
132
- * @param {Array} playerStats - Array of player statistics
133
- * @param {Array} compareFields - Fields to compare
134
- * @returns {Object} - Comparison summary
135
- */
136
- function generateComparisonSummary(playerStats, compareFields) {
137
- const successfulStats = playerStats.filter(p => p.success && p.stats);
138
-
139
- if (successfulStats.length < 2) {
140
- return {
141
- message: 'Not enough valid player data for comparison',
142
- valid_players: successfulStats.length
143
- };
144
- }
145
-
146
- const summary = {
147
- field_comparisons: {},
148
- rankings: {}
149
- };
150
-
151
- // Default fields to compare if none specified
152
- const fieldsToCompare = compareFields || [
153
- 'kills', 'deaths', 'wins', 'losses', 'matches_played',
154
- 'time_played', 'headshots', 'melee_kills', 'revives'
155
- ];
156
-
157
- // Extract and compare stats
158
- fieldsToCompare.forEach(field => {
159
- const fieldData = [];
160
-
161
- successfulStats.forEach(playerStat => {
162
- const stats = extractFieldFromStats(playerStat.stats, field);
163
- if (stats !== null) {
164
- fieldData.push({
165
- player: playerStat.player.nameOnPlatform,
166
- value: stats,
167
- platform: playerStat.player.platformType
168
- });
169
- }
170
- });
171
-
172
- if (fieldData.length > 0) {
173
- // Sort by value (descending)
174
- fieldData.sort((a, b) => b.value - a.value);
175
-
176
- summary.field_comparisons[field] = {
177
- rankings: fieldData,
178
- highest: fieldData[0],
179
- lowest: fieldData[fieldData.length - 1],
180
- average: fieldData.reduce((sum, item) => sum + item.value, 0) / fieldData.length
181
- };
182
- }
183
- });
184
-
185
- return summary;
186
- }
187
-
188
- /**
189
- * Extract a specific field value from player stats
190
- * @param {Object} stats - Player statistics object
191
- * @param {string} field - Field name to extract
192
- * @returns {number|null} - Field value or null if not found
193
- */
194
- function extractFieldFromStats(stats, field) {
195
- try {
196
- if (!stats.platform_families_full_profiles || stats.platform_families_full_profiles.length === 0) {
197
- return null;
198
- }
199
-
200
- const profile = stats.platform_families_full_profiles[0];
201
- if (!profile.board_ids_full_profiles || profile.board_ids_full_profiles.length === 0) {
202
- return null;
203
- }
204
-
205
- const boardProfile = profile.board_ids_full_profiles[0];
206
- if (!boardProfile.full_profiles || boardProfile.full_profiles.length === 0) {
207
- return null;
208
- }
209
-
210
- const fullProfile = boardProfile.full_profiles[0];
211
-
212
- // Map common field names to actual API field names
213
- const fieldMapping = {
214
- 'kills': 'kills',
215
- 'deaths': 'deaths',
216
- 'wins': 'wins',
217
- 'losses': 'losses',
218
- 'matches_played': 'matches_played',
219
- 'time_played': 'time_played',
220
- 'headshots': 'headshots',
221
- 'melee_kills': 'melee_kills',
222
- 'revives': 'revives'
223
- };
224
-
225
- const actualField = fieldMapping[field] || field;
226
- return fullProfile[actualField] || 0;
227
-
228
- } catch (error) {
229
- console.warn(`Error extracting field ${field}:`, error.message);
230
- return null;
231
- }
232
- }
233
-
234
- module.exports = getPlayerComparisons;
121
+ module.exports = getPlayerComparisons;