-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
487 lines (453 loc) · 15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
const fetch = require("node-fetch");
const BASE_URL = "https://api.mozambiquehe.re";
const DIRECTORY = {
SEARCH_URL: BASE_URL + "/bridge?version=",
NEWS_URL: BASE_URL + "/news?",
SERVER_STATUS: BASE_URL + "/servers?",
MATCH_HISTORY: BASE_URL + "/bridge?",
GAME_DATA: BASE_URL + "/gamedata?",
MAP_ROTATION: BASE_URL + "/maprotation?",
ORIGIN: BASE_URL + "/origin?",
ANNOUNCEMENTS: "https://apexlegendsstatus.com/anno.json",
NAME_TO_UID: BASE_URL + "/nametouid?",
};
//#region Private functions
/**
* Make the request to the API servers
*
* @private
* @param {*} self
* @param {String} url
* @returns {JSON|Promise<Error>}
*/
function request(self, url) {
return fetch(url, {
headers: self.headers,
})
.then(function (res) {
return res.json();
})
.catch(function (err) {
return Promise.reject(err);
});
}
//#endregion
/**
* Core of mozambique-api-wrapper
* @class
*/
class MozambiqueAPI {
/**
* @constructor
* @param {String} apiKey Your [Apex Legends API](https://apexlegendsapi.com) Auth Key
* @param {Number} [version=5] API version to use
* @param {String} [userAgent="mozambique-api-wrapper"] User-Agent header
*/
constructor(apiKey, version = 5, userAgent = "mozambique-api-wrapper") {
if (!apiKey)
throw new Error("[ERROR] mozampique-api-wrapper: API Key missing");
let self = this;
self.apiKey = apiKey;
self.version = version;
self.headers = {
"User-Agent": userAgent,
"Content-Type": "application/json",
Authorization: self.apiKey,
};
}
/**
* Search a player using player name or UID
*
* @param {PlayerQuery} query - Query parameters
* @param {object} [options]
* @param {Boolean} [options.merge=false]
* @param {Boolean} [options.removeMerged=false]
* @returns {Promise<Player>} Object with player info
*/
search(query, options = { merge: false, removeMerged: false }) {
let type;
if (query.player != null) type = "player=" + query.player;
if (query.uid != null) type = "uid=" + query.uid;
let url =
DIRECTORY.SEARCH_URL +
this.version +
"&platform=" +
query.platform +
"&" +
type +
(options.merge ? "&merge" : "") +
(options.removeMerged ? "&removeMerged" : "");
return request(this, url);
}
/**
*
* @param {BulkPlayerQuery} bulkQuery
* @param {object} [options]
* @param {Boolean} [options.merge=false]
* @param {Boolean} [options.removeMerged=false]
* @returns {Promise<Player[]>}
*/
bulkSearch(bulkQuery, options = { merge: false, removeMerged: false }) {
let type;
if (bulkQuery.players && bulkQuery.players.length > 0)
type = "&player=" + bulkQuery.players.map((p) => p).join(",");
if (bulkQuery.uids && bulkQuery.uids.length > 0)
type = "&uid=" + bulkQuery.uids.map((u) => u).join(",");
let url =
DIRECTORY.SEARCH_URL +
this.version +
"&platform=" +
query.platform +
type +
(options.merge ? "&merge" : "") +
(options.removeMerged ? "&removeMerged" : "");
return request(this, url);
}
/**
* Get recent news about Apex Legends
*
* @param {String} [lang="en-us"] Language of the news
* @returns {Promise<ApexNews[]>} Array of Apex Legends news
*/
news(lang = "en-us") {
let url = DIRECTORY.NEWS_URL + "lang=" + lang;
return request(this, url);
}
/**
* Get server status for Origin, EA, Apex Legends and apexlegendsapi API
*
* @returns {Promise<Servers>} Object with status of all servers
*/
server() {
let url = DIRECTORY.SERVER_STATUS;
return request(this, url);
}
/**
* Avaliable for everyone but with limitations depending on your api access type
*
* @param {String} action - Action for the Match History API (info, get, delete, add)
* @param {PlayerQuery} [query] - Query parameters
* @param {Number} [limit=-1] - Limit of events to get on action get. -1 is no limit
* @param {Number} [start] - Start UNIX Timestamp
* @param {Number} [end] - End UNIX Timestamp
* @returns {Promise<Object>} Data returned differs depending on action parameter. Please refer to [API documentation](https://apexlegendsapi.com) for more info
*/
history(action, query, limit = -1, start, end) {
let q = "";
if (action != "info") {
let type;
if (query.player) type = "player=" + query.player;
if (query.uid) type = "uid=" + query.uid;
q = type + "&platform=" + query.platform + "&";
}
let l = "";
if (!isNaN(limit) && limit != -1) l = "&limit=" + limit;
let url =
DIRECTORY.MATCH_HISTORY +
q +
"history=1&action=" +
action +
l +
(start != null ? "&start=" + start : "") +
(end != null ? "&end" + end : "");
return request(this, url);
}
/**
* Get the map rotation
* @returns {Promise<MapRotationData>}
*/
mapRotation() {
let url = DIRECTORY.MAP_ROTATION;
return request(this, url);
}
/**
* Search a Origin user
* @param {String} player - player name
* @param {Boolean} [showAllHits=false] - If true, get all possible hits for the given player name and returns it in an array
* @returns {Promise<OriginData|OriginData[]>}
*/
origin(player, showAllHits = false) {
let url =
DIRECTORY.ORIGIN +
"player=" +
player +
(showAllHits ? "&showAllHits" : "");
return request(this, url);
}
/**
* Get the latest announcement of [apexlegendsstatus](https://apexlegendsstatus.com)
* @returns {Promise<Announcement>}
*/
announcements() {
return request(this, DIRECTORY.ANNOUNCEMENTS);
}
/**
* Get the UID using the player name
* @param {PlayerQuery} query
* @param {String} query.player - player name
* @param {String} query.platform - player platform
* @returns {Promise<NameToUIDData|OriginData>} JSON Object with uid or {@link OriginData}
*/
nameToUID(query) {
let url =
DIRECTORY.NAME_TO_UID +
"player=" +
query.player +
"&platform=" +
query.platform;
return request(this, url);
}
/**
* Avaliable data types:
* assault_rifles, attachments, consumables, equipment, grenades, legends, light_machine_guns, pistols, shotguns, sniper_rifles, sub_machine_guns
* @deprecated data not updated
* @param {String} dataType Type of data requested
* @returns {Object} Object with requested game data
*/
gamedata(dataType) {
let url = DIRECTORY.GAME_DATA + "type=" + dataType;
return request(this, url);
}
}
module.exports = MozambiqueAPI;
//#region JSDoc typedefs
/**
* Player query
* @typedef {Object} PlayerQuery
* @property {String} [player] - Player in-game name, obligatory if uid is not specified
* @property {String|Number} [uid] - Player UID, obligatory if player name is not specified
* @property {String} platform - Player platform
*/
/**
* Bulk player query
* @typedef {Object} BulkPlayerQuery
* @property {String[]} [players] - Players in-game name, obligatory if uid is not specified
* @property {String[]|Number[]} [uids] - Players UID, obligatory if player name is not specified
* @property {String} platform - Players platform, has to be the same for every player in the bulk search
*/
/**
* NameToUID data
* @typedef {Object} NameToUIDData
* @property {String|Number} result - The uid of the provided player
*/
/**
* Player data object
* @typedef {Object} Player
* @property {Object} global
* @property {String} global.name - In-Game player name
* @property {Number} global.uid - Unique identifier
* @property {String} global.avatar - Only available for PC players
* @property {String} global.platform
* @property {Number} global.level
* @property {Number} global.toNextLevelPercent
* @property {Number} global.internalUpdateCount
* @property {Object} global.bans
* @property {Boolean} global.bans.isActive
* @property {Number} global.bans.remainingSeconds
* @property {String} global.bans.last_banReason
* @property {Object} global.rank
* @property {Number} global.rank.rankScore
* @property {String} global.rank.rankName
* @property {Number} global.rank.rankDiv
* @property {Number} global.rank.ladderPos
* @property {String} global.rank.rankImg
* @property {String} global.rank.rankedSeason
* @property {Object} global.battlepass
* @property {String} global.battlepass.level - Current season battle pass level
* @property {Object} global.battlepass.history - Level history for all seasons
* @property {Number} global.battlepass.history.season1
* @property {Number} global.battlepass.history.season2
* @property {Number} global.battlepass.history.season3
* @property {Number} global.battlepass.history.season4
* @property {Number} global.battlepass.history.season5
* @property {Number} global.battlepass.history.season6
* @property {Number} global.battlepass.history.season7
* @property {Number} global.battlepass.history.season8
* @property {Badge[]|null} global.badges
*
* @property {Object} realtime - realtime data
* @property {String} realtime.lobbyState
* @property {Number} realtime.isOnline
* @property {Number} realtime.isInGame
* @property {Number} realtime.canJoin
* @property {Number} realtime.partyFull
* @property {String} realtime.selectedLegend
* @property {String} realtime.currentState
* @property {Number} realtime.currentStateSinceTimestamp
* @property {String} realtime.currentStateAsText
*
* @property {Object} legends
* @property {Legend} legends.selected - Current selected legend
* @property {Object} legends.all - All legends
* @property {Legend} legends.all.Bangalore
* @property {Legend} legends.all.Bloodhound
* @property {Legend} legends.all.Lifeline
* @property {Legend} legends.all.Caustic
* @property {Legend} legends.all.Gibraltar
* @property {Legend} legends.all.Mirage
* @property {Legend} legends.all.Pathfinder
* @property {Legend} legends.all.Wraith
* @property {Legend} legends.all.Octane
* @property {Legend} legends.all.Wattson
* @property {Legend} legends.all.Crypto
* @property {Legend} legends.all.Revenant
* @property {Legend} legends.all.Loba
* @property {Legend} legends.all.Rampart
* @property {Legend} legends.all.Horizon
* @property {Legend} legends.all.Fuse
* @property {Legend} legends.all.Valkyrie
* @property {Legend} legends.all.Seer
*
* @property {Object} mozambiquehere_internal - Internal API data
* @property {String} mozambiquehere_internal.APIAccessType
* @property {String} mozambiquehere_internal.ClusterID
* @property {Object} mozambiquehere_internal.rate_limit
* @property {Number} mozambiquehere_internal.rate_limit.max_per_second
* @property {String} mozambiquehere_internal.rate_limit.current_req
* @property {String} mozambiquehere_internal.clusterSrv
*
* @property {Object} total - Total stats from all legends together
* @property {Number} total.kd - Will always be -1 unless kills and games played trackers are found
*/
/**
* Legend data object
* @typedef {Object} Legend
* @property {String} LegendName
* @property {Tracker[]} [data]
* @property {Object} [gameInfo]
* @property {String} gameInfo.skin
* @property {String} gameInfo.skinRarity
* @property {String} gameInfo.frame
* @property {String} gameInfo.frameRarity
* @property {String} gameInfo.pose
* @property {String} gameInfo.poseRarity
* @property {String} gameInfo.intro
* @property {String} gameInfo.introRarity
* @property {LegendBadge[]} gameInfo.badges
* @property {Object} ImgAssets
* @property {String} ImgAssets.icon
* @property {String} ImgAssets.banner
*/
/**
* Tracker data object
* @typedef {Object} Tracker
* @property {String} name
* @property {String|Number} value
* @property {String} key
* @property {object} [rank]
* @property {Number} rank.rankPos
* @property {Number} rank.topPercent
* @property {object} [rankPlatformSpecific]
* @property {Number} rankPlatformSpecific.rankPos
* @property {Number} rankPlatformSpecific.topPercent
*/
/**
* Badge data object
* @typedef {Object} Badge
* @property {String} name
* @property {String|Number} value
*/
/**
* Legend Badge data object
* @typedef {Object} LegendBadge
* @property {String} name
* @property {String|Number} value
* @property {String} category
*/
/**
* Apex Legends News Object
* @typedef {Object} ApexNews
* @property {String} title
* @property {String} link
* @property {String} img
* @property {String} short_desc
*/
/**
* Servers status data object
* @typedef {Object} Servers
* @property {Regions} Origin_login
* @property {Regions} EA_novafusion
* @property {Regions} EA_accounts
* @property {Regions} ApexOauth_Crossplay
* @property {Object} selfCoreTest
* @property {RegionData} selfCoreTest.Status-website
* @property {RegionData} selfCoreTest.Stats-API
* @property {RegionData} selfCoreTest.Overflow-#1
* @property {RegionData} selfCoreTest.Overflow-#2
* @property {RegionData} selfCoreTest.Origin-API
* @property {RegionData} selfCoreTest.Playstation-API
* @property {RegionData} selfCoreTest.Xbox-API
* @property {Object} otherPlatforms
* @property {Object} otherPlatforms.Playstation-Network
* @property {String} otherPlatforms.Playstation-Network.Status
* @property {Number} otherPlatforms.Playstation-Network.QueryTimestamp
* @property {Object} otherPlatforms.Xbox-Live
* @property {String} otherPlatforms.Xbox-Live.Status
* @property {Number} otherPlatforms.Xbox-Live.QueryTimestamp
*/
/**
* Regions object
* @typedef {Object} Regions
* @property {RegionData} EU-West
* @property {RegionData} EU-East
* @property {RegionData} US-West
* @property {RegionData} US-Central
* @property {RegionData} US-East
* @property {RegionData} SouthAmerica
* @property {RegionData} Asia
*/
/**
* Region data object
* @typedef {Object} RegionData
* @property {String} Status
* @property {Number} HTTPCode
* @property {Number} ResponseTime
* @property {Number} QueryTimestamp
*/
/**
* Map data
* @typedef {Object} MapData
* @property {Object} current
* @property {Number} current.start
* @property {Number} current.end
* @property {String} current.readableDate_start
* @property {String} current.readableDate_end
* @property {String} current.map
* @property {Number} current.DurationInSecs
* @property {Number} current.DurationInMinutes
* @property {Number} current.remainingSecs
* @property {Number} current.remainingMins
* @property {String} current.remainingTimer
*
* @property {Object} next
* @property {Number} next.start
* @property {Number} next.end
* @property {String} next.readableDate_start
* @property {String} next.readableDate_end
* @property {String} next.map
* @property {Number} next.DurationInSecs
* @property {Number} next.DurationInMinutes
*/
/**
* Map rotation data
* @typedef {Object} MapRotationData
* @property {MapData} battle_royale
* @property {MapData} arenas
* @property {MapData} ranked - May be incomplete
*/
/**
* Origin data
* @typedef {Object} OriginData
* @property {String} name
* @property {String} uid
* @property {String} pid
* @property {String} avatar
*/
/**
* Announcement of [apexlegendsstatus](https://apexlegendsstatus.com)
* @typedef {Object} Announcement
* @property {Number} Release
* @property {String} Content
* @property {Number} Duration
*/
//#endregion