fnapi-js 1.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.
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/package.json +38 -0
- package/src/client/Aes.js +23 -0
- package/src/client/ApiClient.js +113 -0
- package/src/client/Banners.js +23 -0
- package/src/client/Cosmetics.js +103 -0
- package/src/client/CreatorCode.js +19 -0
- package/src/client/Map.js +15 -0
- package/src/client/News.js +16 -0
- package/src/client/Playlists.js +25 -0
- package/src/client/Shop.js +17 -0
- package/src/client/Stats.js +50 -0
- package/src/enums/AccountType.js +11 -0
- package/src/enums/CosmeticType.js +251 -0
- package/src/enums/Language.js +58 -0
- package/src/enums/MatchMethod.js +14 -0
- package/src/enums/RequestFlags.js +62 -0
- package/src/enums/StatsImage.js +15 -0
- package/src/enums/TimeWindow.js +9 -0
- package/src/http/Response.js +30 -0
- package/src/index.d.ts +503 -0
- package/src/index.js +13 -0
- package/src/types/SearchOptions.js +50 -0
- package/src/utils/Enums.js +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ajaxfnc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# fnapi-js
|
|
2
|
+
|
|
3
|
+
An unofficial JavaScript/Typescript wrapper for the [Fortnite-API](https://fortnite-api.com/) REST API.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install fnapi-js
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
// ESM
|
|
15
|
+
import { ApiClient, Enums } from 'fnapi-js';
|
|
16
|
+
|
|
17
|
+
// CommonJS
|
|
18
|
+
const { ApiClient, Enums } = require('fnapi-js');
|
|
19
|
+
|
|
20
|
+
// Initialize the client
|
|
21
|
+
const fnApi = new ApiClient({ apiKey: 'your-api-key' });
|
|
22
|
+
|
|
23
|
+
// Get player stats
|
|
24
|
+
const stats = await fnApi.stats.get(
|
|
25
|
+
'username',
|
|
26
|
+
Enums.accountType.epic(),
|
|
27
|
+
Enums.timeWindow.lifetime(),
|
|
28
|
+
Enums.statsImage.all()
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Search cosmetics
|
|
32
|
+
const searchOptions = new SearchOptions()
|
|
33
|
+
.setType('outfit')
|
|
34
|
+
.setRarity('epic')
|
|
35
|
+
.setMatchMethod(Enums.matchMethod.contains());
|
|
36
|
+
|
|
37
|
+
const cosmetics = await fnApi.cosmetics.searchCosmetics(searchOptions);
|
|
38
|
+
|
|
39
|
+
// Get creator code
|
|
40
|
+
const creatorCode = await fnApi.sac.get('code');
|
|
41
|
+
|
|
42
|
+
// Get AES keys
|
|
43
|
+
const aesKeys = await fnApi.aes.getKeys();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Available Endpoints
|
|
47
|
+
|
|
48
|
+
- Stats
|
|
49
|
+
- Get player stats
|
|
50
|
+
- Get stats by account ID
|
|
51
|
+
- Cosmetics
|
|
52
|
+
- Search cosmetics
|
|
53
|
+
- Get new cosmetics
|
|
54
|
+
- Get by ID
|
|
55
|
+
- Get tracks, instruments, cars, LEGO items, etc.
|
|
56
|
+
- Creator Codes
|
|
57
|
+
- Get creator code info
|
|
58
|
+
- AES
|
|
59
|
+
- Get encryption keys
|
|
60
|
+
- Map
|
|
61
|
+
- Get current map info
|
|
62
|
+
- News
|
|
63
|
+
- Get game news
|
|
64
|
+
- Playlists
|
|
65
|
+
- Get available playlists
|
|
66
|
+
- Get playlist by ID
|
|
67
|
+
- Shop
|
|
68
|
+
- Get current shop items
|
|
69
|
+
- Banners
|
|
70
|
+
- Get all available banners
|
|
71
|
+
- Get all avaible banner colors
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "fnapi-js",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Unofficial API Wrapper for https://fortnite-api.com/",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "echo hi"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"api",
|
|
13
|
+
"wrapper",
|
|
14
|
+
"fortnite",
|
|
15
|
+
"fortnite-api",
|
|
16
|
+
"lobbybot",
|
|
17
|
+
"fortnite-bot"
|
|
18
|
+
],
|
|
19
|
+
"author": "Ajaxfnc",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/ajaxfnc/fnapi-js.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/ajaxfnc/fnapi-js/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/ajaxfnc/fnapi-js#readme",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"axios": "^1.9.0"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=14.0.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"jest": "^29.5.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Aes {
|
|
2
|
+
constructor(apiClient) {
|
|
3
|
+
this.client = apiClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async get() {
|
|
7
|
+
const requestData = await this.client.request('GET', '/v2/aes');
|
|
8
|
+
|
|
9
|
+
const data = requestData.body().data;
|
|
10
|
+
const build = data.build.replace(/\\u002B/g, '+').replace(/\\u002F/g, '/');
|
|
11
|
+
const mainKey = data.mainKey;
|
|
12
|
+
const dynamicKeys = data.dynamicKeys;
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
build: build,
|
|
16
|
+
mainKey: mainKey,
|
|
17
|
+
dynamicKeys: dynamicKeys
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default Aes;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import Response from '../http/Response.js';
|
|
3
|
+
import Cosmetics from './Cosmetics.js';
|
|
4
|
+
import Aes from './Aes.js'
|
|
5
|
+
import CreatorCode from './CreatorCode.js';
|
|
6
|
+
import Map from './Map.js';
|
|
7
|
+
import News from './News.js';
|
|
8
|
+
import Playlists from './Playlists.js';
|
|
9
|
+
import Shop from './Shop.js';
|
|
10
|
+
import Stats from './Stats.js';
|
|
11
|
+
import Banners from './Banners.js';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ApiClient {
|
|
15
|
+
constructor(config = {}) {
|
|
16
|
+
this.baseUrl = 'https://fortnite-api.com';
|
|
17
|
+
this.options = {
|
|
18
|
+
timeout: 30000,
|
|
19
|
+
headers: {},
|
|
20
|
+
...config
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (config.apiKey) {
|
|
24
|
+
this.options.headers['Authorization'] = `${config.apiKey}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
this.client = axios.create({
|
|
28
|
+
baseURL: this.baseUrl,
|
|
29
|
+
timeout: this.options.timeout,
|
|
30
|
+
headers: this.options.headers
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this.cosmetics = new Cosmetics(this);
|
|
34
|
+
this.aes = new Aes(this)
|
|
35
|
+
this.sac = new CreatorCode(this);
|
|
36
|
+
this.news = new News(this);
|
|
37
|
+
this.map = new Map(this);
|
|
38
|
+
this.playlists = new Playlists(this);
|
|
39
|
+
this.stats = new Stats(this);
|
|
40
|
+
this.shop = new Shop(this);
|
|
41
|
+
this.banners = new Banners(this);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async request(method, path, data = null, options = {}) {
|
|
45
|
+
const maxRetries = 3;
|
|
46
|
+
let lastError;
|
|
47
|
+
|
|
48
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
49
|
+
try {
|
|
50
|
+
const response = await this.client.request({
|
|
51
|
+
method,
|
|
52
|
+
url: path,
|
|
53
|
+
data,
|
|
54
|
+
headers: { ...this.options.headers, ...options.headers },
|
|
55
|
+
params: { ...this.options.query, ...options.params },
|
|
56
|
+
timeout: 60000
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return new Response(
|
|
60
|
+
response.status,
|
|
61
|
+
response.data,
|
|
62
|
+
response.headers
|
|
63
|
+
);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
lastError = error;
|
|
66
|
+
|
|
67
|
+
if (error.response) {
|
|
68
|
+
return new Response(
|
|
69
|
+
error.response.status,
|
|
70
|
+
error.response.data,
|
|
71
|
+
error.response.headers
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (error.code === 'ECONNRESET' || error.code === 'ETIMEDOUT' || error.code === 'ECONNABORTED') {
|
|
76
|
+
if (attempt < maxRetries) {
|
|
77
|
+
console.log(`Request failed (${error.code}). Retrying... (${attempt}/${maxRetries})`);
|
|
78
|
+
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw lastError;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setHeader(key, value) {
|
|
91
|
+
this.options.headers[key] = value;
|
|
92
|
+
this.client.defaults.headers[key] = value;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getBaseUrl() {
|
|
96
|
+
return this.baseUrl;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_getTypeValue(item) {
|
|
100
|
+
if (!item.type?.backendValue) return null;
|
|
101
|
+
|
|
102
|
+
const typeMapping = {
|
|
103
|
+
'AthenaCharacter': 'outfit',
|
|
104
|
+
'AthenaDance': 'emote',
|
|
105
|
+
'AthenaPickaxe': 'pickaxe',
|
|
106
|
+
'AthenaBackpack': 'backpack'
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return typeMapping[item.type.backendValue] || null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export default ApiClient;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Banners {
|
|
2
|
+
constructor(apiClient) {
|
|
3
|
+
this.client = apiClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async get() {
|
|
7
|
+
const requestData = await this.client.request('GET', '/v1/banners');
|
|
8
|
+
|
|
9
|
+
if (!requestData.isSuccess()) throw new Error(requestData.body().error);
|
|
10
|
+
const data = requestData.body().data;
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async getColors() {
|
|
15
|
+
const requestData = await this.client.request('GET', '/v1/banners/colors');
|
|
16
|
+
|
|
17
|
+
if (!requestData.isSuccess()) throw new Error(requestData.body().error);
|
|
18
|
+
const data = requestData.body().data;
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default Banners;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import RequestFlags from '../enums/requestFlags.js';
|
|
2
|
+
import SearchOptions from '../types/SearchOptions.js';
|
|
3
|
+
|
|
4
|
+
class Cosmetics {
|
|
5
|
+
constructor(apiClient) {
|
|
6
|
+
this.client = apiClient;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async getAll(flags = RequestFlags.none()) {
|
|
10
|
+
return await this.client.request('GET', '/v2/cosmetics/br', null, {
|
|
11
|
+
params: {
|
|
12
|
+
...flags && { responseFlags: flags }
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getAllNew(flags = RequestFlags.none()) {
|
|
18
|
+
return await this.client.request('GET', '/v2/cosmetics/new', null, {
|
|
19
|
+
params: {
|
|
20
|
+
...flags && { responseFlags: flags }
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getAllTracks(flags = RequestFlags.none()) {
|
|
26
|
+
return await this.client.request('GET', '/v2/cosmetics/tracks', null, {
|
|
27
|
+
params: {
|
|
28
|
+
...flags && { responseFlags: flags }
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getAllInstrument(flags = RequestFlags.none()) {
|
|
34
|
+
return await this.client.request('GET', '/v2/cosmetics/instruments', null, {
|
|
35
|
+
params: {
|
|
36
|
+
...flags && { responseFlags: flags }
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async getAllCars(flags = RequestFlags.none()) {
|
|
42
|
+
return await this.client.request('GET', '/v2/cosmetics/cars', null, {
|
|
43
|
+
params: {
|
|
44
|
+
...flags && { responseFlags: flags }
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async getAllLego(flags = RequestFlags.none()) {
|
|
50
|
+
return await this.client.request('GET', '/v2/cosmetics/lego', null, {
|
|
51
|
+
params: {
|
|
52
|
+
...flags && { responseFlags: flags }
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async getAllLegoKits(flags = RequestFlags.none()) {
|
|
58
|
+
return await this.client.request('GET', '/v2/cosmetics/lego/kits', null, {
|
|
59
|
+
params: {
|
|
60
|
+
...flags && { responseFlags: flags }
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async getAllBeans(flags = RequestFlags.none()) {
|
|
66
|
+
return await this.client.request('GET', '/v2/cosmetics/beans', null, {
|
|
67
|
+
params: {
|
|
68
|
+
...flags && { responseFlags: flags }
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async getById(cosmeticId, flags = RequestFlags.none()) {
|
|
74
|
+
if (!cosmeticId) throw new Error('Cosmetic ID is required');
|
|
75
|
+
|
|
76
|
+
return await this.client.request('GET', `/v2/cosmetics/br/${cosmeticId}`, null, {
|
|
77
|
+
params: {
|
|
78
|
+
...flags && { responseFlags: flags }
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async search(searchOptions = new SearchOptions(), flags = RequestFlags.none(), searchAll = true) {
|
|
84
|
+
const params = searchOptions.build();
|
|
85
|
+
if (searchAll) {
|
|
86
|
+
return await this.client.request('GET', '/v2/cosmetics/br/search/all', null, {
|
|
87
|
+
params: {
|
|
88
|
+
...params,
|
|
89
|
+
...flags && { responseFlags: flags }
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
return await this.client.request('GET', '/v2/cosmetics/br/search', null, {
|
|
94
|
+
params: {
|
|
95
|
+
...params,
|
|
96
|
+
...flags && { responseFlags: flags }
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export default Cosmetics;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
class CreatorCode {
|
|
2
|
+
constructor(apiClient) {
|
|
3
|
+
this.client = apiClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async get(code) {
|
|
7
|
+
if (!code) throw new Error('Code parameter is required');
|
|
8
|
+
|
|
9
|
+
const requestData = await this.client.request('GET', '/v2/creatorcode', null, {
|
|
10
|
+
params: {
|
|
11
|
+
name: code
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
if (!requestData.isSuccess()) throw new Error(requestData.body().error);
|
|
15
|
+
return requestData.body().data;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default CreatorCode;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Map {
|
|
2
|
+
constructor(apiClient) {
|
|
3
|
+
this.client = apiClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async get() {
|
|
7
|
+
const requestData = await this.client.request('GET', '/v1/map');
|
|
8
|
+
|
|
9
|
+
if (!requestData.isSuccess()) throw new Error(requestData.body().error);
|
|
10
|
+
const data = requestData.body().data;
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default Map;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class News {
|
|
2
|
+
constructor(apiClient) {
|
|
3
|
+
this.client = apiClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async get() {
|
|
7
|
+
const requestData = await this.client.request('GET', '/v2/news');
|
|
8
|
+
const data = requestData.body().data;
|
|
9
|
+
|
|
10
|
+
if (!requestData.isSuccess()) throw new Error(requestData.body().error);
|
|
11
|
+
return data;
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default News;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Playlists {
|
|
2
|
+
constructor(apiClient) {
|
|
3
|
+
this.client = apiClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async all() {
|
|
7
|
+
const requestData = await this.client.request('GET', '/v1/playlists');
|
|
8
|
+
|
|
9
|
+
const data = requestData.body().data;
|
|
10
|
+
if (!requestData.isSuccess()) throw new Error(requestData.body().error);
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async byId(id) {
|
|
15
|
+
if(!id) throw new Error("Id is required.")
|
|
16
|
+
|
|
17
|
+
const requestData = await this.client.request('GET', `/v1/playlists/${id}`);
|
|
18
|
+
|
|
19
|
+
const data = requestData.body().data;
|
|
20
|
+
if (!requestData.isSuccess()) throw new Error(requestData.body().error);
|
|
21
|
+
return data;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default Playlists;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class Shop {
|
|
2
|
+
constructor(apiClient) {
|
|
3
|
+
this.client = apiClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async get() {
|
|
7
|
+
const requestData = await this.client.request('GET', '/v2/shop');
|
|
8
|
+
|
|
9
|
+
const data = requestData.body().data;
|
|
10
|
+
|
|
11
|
+
if (!requestData.isSuccess()) throw new Error(requestData.body().error);
|
|
12
|
+
return data;
|
|
13
|
+
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default Shop;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
class Stats {
|
|
2
|
+
constructor(apiClient) {
|
|
3
|
+
this.client = apiClient;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
async get(name, accountType, timeWindow, image) {
|
|
7
|
+
if (!this.client.options.apiKey) throw new Error('API key is required for stats');
|
|
8
|
+
if (!name) throw new Error('Name parameter is required');
|
|
9
|
+
if (!accountType) throw new Error('Account type parameter is required');
|
|
10
|
+
if (!timeWindow) throw new Error('Time window parameter is required');
|
|
11
|
+
|
|
12
|
+
const requestData = await this.client.request('GET', '/v2/stats/br/v2', null, {
|
|
13
|
+
params: {
|
|
14
|
+
name: name,
|
|
15
|
+
accountType: accountType,
|
|
16
|
+
timeWindow: timeWindow,
|
|
17
|
+
image: image || 'all'
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (!requestData.isSuccess()) {
|
|
22
|
+
throw new Error(requestData.body().error || 'Failed to fetch stats');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return requestData.body().data;
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async byId(id, timeWindow, image) {
|
|
30
|
+
if (!this.client.options.apiKey) throw new Error('API key is required for stats');
|
|
31
|
+
if (!id) throw new Error('ID parameter is required');
|
|
32
|
+
if (!timeWindow) throw new Error('Time window parameter is required');
|
|
33
|
+
|
|
34
|
+
const requestData = await this.client.request('GET', `/v2/stats/br/v2/${id}`, null, {
|
|
35
|
+
params: {
|
|
36
|
+
timeWindow: timeWindow,
|
|
37
|
+
image: image || 'all'
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (!requestData.isSuccess()) {
|
|
42
|
+
throw new Error(requestData.body().error || 'Failed to fetch stats');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return requestData.body().data;
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default Stats;
|