fnapi-js 1.1.2 → 2.0.0-beta.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 -21
- package/README.md +81 -57
- package/config.example.json +24 -0
- package/dist/index.cjs +10508 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5737 -0
- package/dist/index.d.ts +5737 -0
- package/dist/index.js +10218 -0
- package/dist/index.js.map +1 -0
- package/docs.md +8848 -0
- package/package.json +54 -13
- package/src/client/Aes.js +0 -23
- package/src/client/ApiClient.js +0 -114
- package/src/client/Banners.js +0 -23
- package/src/client/Cosmetics.js +0 -103
- package/src/client/CreatorCode.js +0 -19
- package/src/client/Map.js +0 -15
- package/src/client/Misc.js +0 -21
- package/src/client/News.js +0 -16
- package/src/client/Playlists.js +0 -25
- package/src/client/Shop.js +0 -17
- package/src/client/Stats.js +0 -50
- package/src/docs/DOCUMENTATION.md +0 -435
- package/src/enums/AccountType.js +0 -11
- package/src/enums/CosmeticType.js +0 -251
- package/src/enums/Language.js +0 -58
- package/src/enums/MatchMethod.js +0 -14
- package/src/enums/RequestFlags.js +0 -62
- package/src/enums/StatsImage.js +0 -15
- package/src/enums/TimeWindow.js +0 -9
- package/src/examples/api-example.js +0 -220
- package/src/examples/fnbrjsAndfnapi.js +0 -63
- package/src/http/Response.js +0 -30
- package/src/index.d.ts +0 -503
- package/src/index.js +0 -13
- package/src/types/SearchOptions.js +0 -50
- package/src/utils/Enums.js +0 -39
package/package.json
CHANGED
|
@@ -1,20 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fnapi-js",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "src/index.js",
|
|
6
|
-
"types": "index.d.ts",
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
|
+
"description": "Zero-dependency TypeScript wrapper for the public Fortnite APIs with a full Epic Games account-service, realtime (XMPP/EOS), party, MCP and item-shop/gifting layer",
|
|
7
5
|
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"docs.md",
|
|
25
|
+
"config.example.json",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
8
29
|
"scripts": {
|
|
9
|
-
"
|
|
30
|
+
"build": "tsup",
|
|
31
|
+
"dev": "tsup --watch",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
36
|
+
"test:live": "vitest run --config vitest.live.config.ts",
|
|
37
|
+
"cli": "tsx tools/cli.ts",
|
|
38
|
+
"generate:mcp": "tsx tools/generate-mcp-operations.ts",
|
|
39
|
+
"prepublishOnly": "npm run typecheck && npm run test && npm run build"
|
|
10
40
|
},
|
|
11
41
|
"keywords": [
|
|
12
|
-
"api",
|
|
13
|
-
"wrapper",
|
|
14
42
|
"fortnite",
|
|
15
43
|
"fortnite-api",
|
|
44
|
+
"api",
|
|
45
|
+
"wrapper",
|
|
46
|
+
"typescript",
|
|
47
|
+
"cosmetics",
|
|
48
|
+
"item-shop",
|
|
16
49
|
"lobbybot",
|
|
17
|
-
"fortnite-bot"
|
|
50
|
+
"fortnite-bot",
|
|
51
|
+
"epic-games"
|
|
18
52
|
],
|
|
19
53
|
"author": "AjaxFNC-YT",
|
|
20
54
|
"license": "MIT",
|
|
@@ -26,13 +60,20 @@
|
|
|
26
60
|
"url": "https://github.com/AjaxFNC-YT/fnapi-js/issues"
|
|
27
61
|
},
|
|
28
62
|
"homepage": "https://github.com/AjaxFNC-YT/fnapi-js#readme",
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"axios": "^1.9.0"
|
|
31
|
-
},
|
|
32
63
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
64
|
+
"node": ">=18.0.0"
|
|
34
65
|
},
|
|
35
66
|
"devDependencies": {
|
|
36
|
-
"
|
|
67
|
+
"@types/node": "^26.2.0",
|
|
68
|
+
"@types/ws": "^8.18.1",
|
|
69
|
+
"@vitest/coverage-v8": "^3.0.5",
|
|
70
|
+
"tsup": "^8.3.6",
|
|
71
|
+
"tsx": "^4.23.12",
|
|
72
|
+
"typescript": "^5.7.3",
|
|
73
|
+
"vitest": "^3.0.5",
|
|
74
|
+
"ws": "^8.21.3"
|
|
75
|
+
},
|
|
76
|
+
"allowScripts": {
|
|
77
|
+
"esbuild@0.27.7": true
|
|
37
78
|
}
|
|
38
79
|
}
|
package/src/client/Aes.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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;
|
package/src/client/ApiClient.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
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
|
-
import Misc from './Misc.js';
|
|
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
|
-
this.misc = new Misc(this);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async request(method, path, data = null, options = {}) {
|
|
46
|
-
const maxRetries = 3;
|
|
47
|
-
let lastError;
|
|
48
|
-
|
|
49
|
-
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
50
|
-
try {
|
|
51
|
-
const response = await this.client.request({
|
|
52
|
-
method,
|
|
53
|
-
url: path,
|
|
54
|
-
data,
|
|
55
|
-
headers: { ...this.options.headers, ...options.headers },
|
|
56
|
-
params: { ...this.options.query, ...options.params },
|
|
57
|
-
timeout: 60000
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return new Response(
|
|
61
|
-
response.status,
|
|
62
|
-
response.data,
|
|
63
|
-
response.headers
|
|
64
|
-
);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
lastError = error;
|
|
67
|
-
|
|
68
|
-
if (error.response) {
|
|
69
|
-
return new Response(
|
|
70
|
-
error.response.status,
|
|
71
|
-
error.response.data,
|
|
72
|
-
error.response.headers
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (error.code === 'ECONNRESET' || error.code === 'ETIMEDOUT' || error.code === 'ECONNABORTED') {
|
|
77
|
-
if (attempt < maxRetries) {
|
|
78
|
-
console.log(`Request failed (${error.code}). Retrying... (${attempt}/${maxRetries})`);
|
|
79
|
-
await new Promise(resolve => setTimeout(resolve, 1000 * attempt));
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
throw lastError;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
setHeader(key, value) {
|
|
92
|
-
this.options.headers[key] = value;
|
|
93
|
-
this.client.defaults.headers[key] = value;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
getBaseUrl() {
|
|
97
|
-
return this.baseUrl;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
_getTypeValue(item) {
|
|
101
|
-
if (!item.type?.backendValue) return null;
|
|
102
|
-
|
|
103
|
-
const typeMapping = {
|
|
104
|
-
'AthenaCharacter': 'outfit',
|
|
105
|
-
'AthenaDance': 'emote',
|
|
106
|
-
'AthenaPickaxe': 'pickaxe',
|
|
107
|
-
'AthenaBackpack': 'backpack'
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
return typeMapping[item.type.backendValue] || null;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default ApiClient;
|
package/src/client/Banners.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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;
|
package/src/client/Cosmetics.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
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;
|
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
package/src/client/Map.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
package/src/client/Misc.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import RequestFlags from '../enums/RequestFlags.js';
|
|
2
|
-
import SearchOptions from '../types/SearchOptions.js';
|
|
3
|
-
|
|
4
|
-
class Misc {
|
|
5
|
-
constructor(apiClient) {
|
|
6
|
-
this.client = apiClient;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async fixPath(path) {
|
|
10
|
-
return path
|
|
11
|
-
.replace(/^FortniteGame\/Content/, '/Game')
|
|
12
|
-
.replace(/FortniteGame\/Plugins\/GameFeatures\/BRCosmetics\/Content/, '/BRCosmetics')
|
|
13
|
-
.replace(/FortniteGame\/Plugins\/GameFeatures\/CosmeticShoes\/Content/, '/CosmeticShoes')
|
|
14
|
-
.split('/')
|
|
15
|
-
.slice(0, -1)
|
|
16
|
-
.join('/');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default Misc;
|
package/src/client/News.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
package/src/client/Playlists.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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;
|
package/src/client/Shop.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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;
|
package/src/client/Stats.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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;
|