r6-data.js 2.0.1 → 2.2.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,121 +1,121 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Compare Rainbow Six Siege player statistics between multiple players
6
- * @param {string} apiKey - Your API Key from r6data.eu
7
- * @param {Object} params - Parameters for the request
8
- * @param {Array<Object>} params.players - Array of player objects to compare
9
- * @param {string} params.players[].nameOnPlatform - Player name on the platform
10
- * @param {string} params.players[].platformType - Platform type (uplay, psn, xbl)
11
- * @param {string} params.platform_families - Platform families: "pc" or "console"
12
- * @param {string} [params.board_id] - Game mode to filter stats (casual, event, warmup, standard, ranked)
13
- * @param {Array<string>} [params.compareFields] - Specific fields to compare (e.g., ['kills', 'deaths', 'wins', 'losses'])
14
- * @returns {Promise<Object>} - Comparison results with player statistics and comparison metrics
15
- */
16
- async function getPlayerComparisons(apiKey, { players, platform_families, board_id, compareFields } = {}) {
17
- try {
18
- // Validate required parameters
19
- if (!apiKey) {
20
- throw new Error('Missing required parameter: apiKey');
21
- }
22
- if (!players || !Array.isArray(players) || players.length < 2) {
23
- throw new Error('At least 2 players are required for comparison');
24
- }
25
-
26
- if (!platform_families) {
27
- throw new Error('Missing required parameter: platform_families');
28
- }
29
-
30
- // Validate each player object
31
- for (let i = 0; i < players.length; i++) {
32
- const player = players[i];
33
- if (!player.nameOnPlatform || !player.platformType) {
34
- throw new Error(`Player ${i + 1} is missing required fields: nameOnPlatform, platformType`);
35
- }
36
- }
37
-
38
- // Validate board_id if provided
39
- if (board_id && !['casual', 'event', 'warmup', 'standard', 'ranked'].includes(board_id)) {
40
- throw new Error('Invalid board_id. Must be one of: casual, event, warmup, standard, ranked');
41
- }
42
-
43
- // Fetch stats for each player
44
- const playerStats = [];
45
- const errors = [];
46
-
47
- for (const player of players) {
48
- try {
49
- const params = {
50
- type: 'stats',
51
- nameOnPlatform: player.nameOnPlatform,
52
- platformType: player.platformType,
53
- platform_families
54
- };
55
-
56
- if (board_id) {
57
- params.board_id = board_id;
58
- }
59
-
60
- const url = buildUrlAndParams('/stats', params);
61
- const response = await axiosInstance.get(url, {
62
- headers: {
63
- 'api-key': apiKey
64
- }
65
- });
66
-
67
- if (response.data &&
68
- response.data.platform_families_full_profiles &&
69
- response.data.platform_families_full_profiles.length > 0) {
70
-
71
- // Filter by board_id if specified
72
- if (board_id && response.data.platform_families_full_profiles) {
73
- response.data.platform_families_full_profiles.forEach(profile => {
74
- if (profile.board_ids_full_profiles) {
75
- profile.board_ids_full_profiles = profile.board_ids_full_profiles.filter(
76
- board => board.board_id === board_id
77
- );
78
- }
79
- });
80
- }
81
-
82
- playerStats.push({
83
- player: player,
84
- stats: response.data,
85
- success: true
86
- });
87
- } else {
88
- playerStats.push({
89
- player: player,
90
- stats: null,
91
- success: false,
92
- error: 'No stats found for player'
93
- });
94
- }
95
- } catch (error) {
96
- errors.push({
97
- player: player,
98
- error: error.message
99
- });
100
- playerStats.push({
101
- player: player,
102
- stats: null,
103
- success: false,
104
- error: error.message
105
- });
106
- }
107
- }
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
- };
114
-
115
- } catch (error) {
116
- console.error('Error during the getPlayerComparisons request:', error.message);
117
- throw error;
118
- }
119
- }
120
-
121
- module.exports = getPlayerComparisons;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Compare Rainbow Six Siege player statistics between multiple players
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @param {Object} params - Parameters for the request
8
+ * @param {Array<Object>} params.players - Array of player objects to compare
9
+ * @param {string} params.players[].nameOnPlatform - Player name on the platform
10
+ * @param {string} params.players[].platformType - Platform type (uplay, psn, xbl)
11
+ * @param {string} params.platform_families - Platform families: "pc" or "console"
12
+ * @param {string} [params.board_id] - Game mode to filter stats (casual, event, warmup, standard, ranked)
13
+ * @param {Array<string>} [params.compareFields] - Specific fields to compare (e.g., ['kills', 'deaths', 'wins', 'losses'])
14
+ * @returns {Promise<Object>} - Comparison results with player statistics and comparison metrics
15
+ */
16
+ async function getPlayerComparisons(apiKey, { players, platform_families, board_id, compareFields } = {}) {
17
+ try {
18
+ // Validate required parameters
19
+ if (!apiKey) {
20
+ throw new Error('Missing required parameter: apiKey');
21
+ }
22
+ if (!players || !Array.isArray(players) || players.length < 2) {
23
+ throw new Error('At least 2 players are required for comparison');
24
+ }
25
+
26
+ if (!platform_families) {
27
+ throw new Error('Missing required parameter: platform_families');
28
+ }
29
+
30
+ // Validate each player object
31
+ for (let i = 0; i < players.length; i++) {
32
+ const player = players[i];
33
+ if (!player.nameOnPlatform || !player.platformType) {
34
+ throw new Error(`Player ${i + 1} is missing required fields: nameOnPlatform, platformType`);
35
+ }
36
+ }
37
+
38
+ // Validate board_id if provided
39
+ if (board_id && !['casual', 'event', 'warmup', 'standard', 'ranked'].includes(board_id)) {
40
+ throw new Error('Invalid board_id. Must be one of: casual, event, warmup, standard, ranked');
41
+ }
42
+
43
+ // Fetch stats for each player
44
+ const playerStats = [];
45
+ const errors = [];
46
+
47
+ for (const player of players) {
48
+ try {
49
+ const params = {
50
+ type: 'stats',
51
+ nameOnPlatform: player.nameOnPlatform,
52
+ platformType: player.platformType,
53
+ platform_families
54
+ };
55
+
56
+ if (board_id) {
57
+ params.board_id = board_id;
58
+ }
59
+
60
+ const url = buildUrlAndParams('/stats', params);
61
+ const response = await axiosInstance.get(url, {
62
+ headers: {
63
+ 'api-key': apiKey
64
+ }
65
+ });
66
+
67
+ if (response.data &&
68
+ response.data.platform_families_full_profiles &&
69
+ response.data.platform_families_full_profiles.length > 0) {
70
+
71
+ // Filter by board_id if specified
72
+ if (board_id && response.data.platform_families_full_profiles) {
73
+ response.data.platform_families_full_profiles.forEach(profile => {
74
+ if (profile.board_ids_full_profiles) {
75
+ profile.board_ids_full_profiles = profile.board_ids_full_profiles.filter(
76
+ board => board.board_id === board_id
77
+ );
78
+ }
79
+ });
80
+ }
81
+
82
+ playerStats.push({
83
+ player: player,
84
+ stats: response.data,
85
+ success: true
86
+ });
87
+ } else {
88
+ playerStats.push({
89
+ player: player,
90
+ stats: null,
91
+ success: false,
92
+ error: 'No stats found for player'
93
+ });
94
+ }
95
+ } catch (error) {
96
+ errors.push({
97
+ player: player,
98
+ error: error.message
99
+ });
100
+ playerStats.push({
101
+ player: player,
102
+ stats: null,
103
+ success: false,
104
+ error: error.message
105
+ });
106
+ }
107
+ }
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
+ };
114
+
115
+ } catch (error) {
116
+ console.error('Error during the getPlayerComparisons request:', error.message);
117
+ throw error;
118
+ }
119
+ }
120
+
121
+ module.exports = getPlayerComparisons;
@@ -1,83 +1,77 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege player statistics
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
- * @param {string} params.platform_families - Platform families: "pc" or "console"
11
- * @param {string} [params.board_id] - Game mode to filter stats (casual, event, warmup, standard, ranked)
12
- * @returns {Promise<Object>} - Player statistics
13
- */
14
- async function getPlayerStats(apiKey, { nameOnPlatform, platformType, platform_families, board_id } = {}) {
15
- try {
16
- // Validate required parameters
17
- if (!apiKey) {
18
- throw new Error('Missing required parameter: apiKey');
19
- }
20
- if (!nameOnPlatform || !platformType || !platform_families) {
21
- throw new Error('Missing required parameters: nameOnPlatform, platformType, platform_families');
22
- }
23
-
24
- // Validate board_id if provided
25
- if (board_id && !['casual', 'event', 'warmup', 'standard', 'ranked'].includes(board_id)) {
26
- throw new Error('Invalid board_id. Must be one of: casual, event, warmup, standard, ranked');
27
- }
28
-
29
- // Build the URL with parameters
30
- const params = {
31
- type: 'stats',
32
- nameOnPlatform,
33
- platformType,
34
- platform_families
35
- };
36
-
37
- // Add board_id if provided
38
- if (board_id) {
39
- params.board_id = board_id;
40
- }
41
-
42
- const url = buildUrlAndParams('/stats', params);
43
-
44
- const response = await axiosInstance.get(url, {
45
- headers: {
46
- 'api-key': apiKey
47
- }
48
- });
49
-
50
- if (response.data &&
51
- response.data.platform_families_full_profiles &&
52
- response.data.platform_families_full_profiles.length > 0) {
53
-
54
- // If board_id is specified, filter the response data
55
- if (board_id && response.data.platform_families_full_profiles) {
56
- response.data.platform_families_full_profiles.forEach(profile => {
57
- if (profile.board_ids_full_profiles) {
58
- // Filter to only include the specified board_id
59
- profile.board_ids_full_profiles = profile.board_ids_full_profiles.filter(
60
- board => board.board_id === board_id
61
- );
62
- }
63
- });
64
- }
65
-
66
- response.data.platform_families_full_profiles.forEach(profile => {
67
- if (profile.board_ids_full_profiles) {
68
- console.log(JSON.stringify(profile.board_ids_full_profiles, null, 2));
69
- }
70
- });
71
- }
72
-
73
- return response.data;
74
- } catch (error) {
75
- console.error('Error during the getPlayerStats request:', error.message);
76
- if (error.response && error.response.status === 401) {
77
- throw new Error('Authentication error');
78
- }
79
- throw error;
80
- }
81
- }
82
-
83
- module.exports = getPlayerStats;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege player statistics
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
+ * @param {string} params.platform_families - Platform families: "pc" or "console"
11
+ * @param {string} [params.board_id] - Game mode to filter stats (casual, event, warmup, standard, ranked)
12
+ * @returns {Promise<Object>} - Player statistics
13
+ */
14
+ async function getPlayerStats(apiKey, { nameOnPlatform, platformType, platform_families, board_id } = {}) {
15
+ try {
16
+ // Validate required parameters
17
+ if (!apiKey) {
18
+ throw new Error('Missing required parameter: apiKey');
19
+ }
20
+ if (!nameOnPlatform || !platformType || !platform_families) {
21
+ throw new Error('Missing required parameters: nameOnPlatform, platformType, platform_families');
22
+ }
23
+
24
+ // Validate board_id if provided
25
+ if (board_id && !['casual', 'event', 'warmup', 'standard', 'ranked'].includes(board_id)) {
26
+ throw new Error('Invalid board_id. Must be one of: casual, event, warmup, standard, ranked');
27
+ }
28
+
29
+ // Build the URL with parameters
30
+ const params = {
31
+ type: 'stats',
32
+ nameOnPlatform,
33
+ platformType,
34
+ platform_families
35
+ };
36
+
37
+ // Add board_id if provided
38
+ if (board_id) {
39
+ params.board_id = board_id;
40
+ }
41
+
42
+ const url = buildUrlAndParams('/stats', params);
43
+
44
+ const response = await axiosInstance.get(url, {
45
+ headers: {
46
+ 'api-key': apiKey
47
+ }
48
+ });
49
+
50
+ if (response.data &&
51
+ response.data.platform_families_full_profiles &&
52
+ response.data.platform_families_full_profiles.length > 0) {
53
+
54
+ // If board_id is specified, filter the response data
55
+ if (board_id && response.data.platform_families_full_profiles) {
56
+ response.data.platform_families_full_profiles.forEach(profile => {
57
+ if (profile.board_ids_full_profiles) {
58
+ // Filter to only include the specified board_id
59
+ profile.board_ids_full_profiles = profile.board_ids_full_profiles.filter(
60
+ board => board.board_id === board_id
61
+ );
62
+ }
63
+ });
64
+ }
65
+ }
66
+
67
+ return response.data;
68
+ } catch (error) {
69
+ console.error('Error during the getPlayerStats request:', error.message);
70
+ if (error.response && error.response.status === 401) {
71
+ throw new Error('Authentication error');
72
+ }
73
+ throw error;
74
+ }
75
+ }
76
+
77
+ module.exports = getPlayerStats;
@@ -1,32 +1,32 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- async function getRanks(apiKey, { name, min_mmr, max_mmr, version } = {}) {
5
- try {
6
- if (!apiKey) {
7
- throw new Error('Missing required parameter: apiKey');
8
- }
9
-
10
- if (!['v1', 'v2', 'v3', 'v4', 'v5', 'v6'].includes(version)) {
11
- throw new Error('Version not valid. Choose between v1, v2, v3, v4, v5, and v6.');
12
- }
13
-
14
- const url = buildUrlAndParams('/ranks', { name, min_mmr, max_mmr, version });
15
-
16
- const response = await axiosInstance.get(url, {
17
- headers: {
18
- 'api-key': apiKey
19
- }
20
- });
21
-
22
- return response.data;
23
- } catch (error) {
24
- console.error('Error during the getRanks request:', error.message);
25
- if (error.response && error.response.status === 401) {
26
- throw new Error('request error');
27
- }
28
- throw error;
29
- }
30
- }
31
-
32
- module.exports = getRanks;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ async function getRanks(apiKey, { name, min_mmr, max_mmr, version } = {}) {
5
+ try {
6
+ if (!apiKey) {
7
+ throw new Error('Missing required parameter: apiKey');
8
+ }
9
+
10
+ if (!['v1', 'v2', 'v3', 'v4', 'v5', 'v6'].includes(version)) {
11
+ throw new Error('Version not valid. Choose between v1, v2, v3, v4, v5, and v6.');
12
+ }
13
+
14
+ const url = buildUrlAndParams('/ranks', { name, min_mmr, max_mmr, version });
15
+
16
+ const response = await axiosInstance.get(url, {
17
+ headers: {
18
+ 'api-key': apiKey
19
+ }
20
+ });
21
+
22
+ return response.data;
23
+ } catch (error) {
24
+ console.error('Error during the getRanks request:', error.message);
25
+ if (error.response && error.response.status === 401) {
26
+ throw new Error('request error');
27
+ }
28
+ throw error;
29
+ }
30
+ }
31
+
32
+ module.exports = getRanks;
@@ -1,35 +1,35 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Search across all R6 entities (operators, weapons, maps, etc.)
6
- * @param {string} apiKey - Your API Key from r6data.eu
7
- * @param {string} query - The search term to query across all entities
8
- * @returns {Promise<Object>} - Search results organized by entity type
9
- */
10
- async function getSearchAll(apiKey, query) {
11
- if (!apiKey) {
12
- throw new Error('Missing required parameter: apiKey');
13
- }
14
- if (!query || typeof query !== 'string') {
15
- throw new Error('Search query is required and must be a string');
16
- }
17
-
18
- try {
19
- const url = buildUrlAndParams('/searchAll', { q: query });
20
- const response = await axiosInstance.get(url, {
21
- headers: {
22
- 'api-key': apiKey
23
- }
24
- });
25
- return response.data;
26
- } catch (error) {
27
- console.error('Error during the getSearchAll request:', error.message);
28
- if (error.response && error.response.status === 401) {
29
- throw new Error('Authentication error');
30
- }
31
- throw error;
32
- }
33
- }
34
-
35
- module.exports = getSearchAll;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Search across all R6 entities (operators, weapons, maps, etc.)
6
+ * @param {string} apiKey - Your API Key from r6data.eu
7
+ * @param {string} query - The search term to query across all entities
8
+ * @returns {Promise<Object>} - Search results organized by entity type
9
+ */
10
+ async function getSearchAll(apiKey, query) {
11
+ if (!apiKey) {
12
+ throw new Error('Missing required parameter: apiKey');
13
+ }
14
+ if (!query || typeof query !== 'string') {
15
+ throw new Error('Search query is required and must be a string');
16
+ }
17
+
18
+ try {
19
+ const url = buildUrlAndParams('/searchAll', { q: query });
20
+ const response = await axiosInstance.get(url, {
21
+ headers: {
22
+ 'api-key': apiKey
23
+ }
24
+ });
25
+ return response.data;
26
+ } catch (error) {
27
+ console.error('Error during the getSearchAll request:', error.message);
28
+ if (error.response && error.response.status === 401) {
29
+ throw new Error('Authentication error');
30
+ }
31
+ throw error;
32
+ }
33
+ }
34
+
35
+ module.exports = getSearchAll;
@@ -1,47 +1,47 @@
1
- const axiosInstance = require('../axiosInstance/axiosInstance');
2
- const buildUrlAndParams = require('./util');
3
-
4
- /**
5
- * Get Rainbow Six Siege player stats for current season
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 stats for current season
11
- */
12
- async function getSeasonalStats(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: 'seasonalStats',
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 getSeasonalStats 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 = getSeasonalStats;
1
+ const axiosInstance = require('../axiosInstance/axiosInstance');
2
+ const buildUrlAndParams = require('./util');
3
+
4
+ /**
5
+ * Get Rainbow Six Siege player stats for current season
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 stats for current season
11
+ */
12
+ async function getSeasonalStats(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: 'seasonalStats',
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 getSeasonalStats 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 = getSeasonalStats;