@wise-old-man/utils 2.0.0-beta.4 → 2.0.0-beta.5

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +27 -12
  2. package/dist/index.js +136 -124
  3. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -388,6 +388,7 @@ export type Prisma_Base_Snapshot = {
388
388
 
389
389
 
390
390
 
391
+ import { AxiosInstance } from 'axios';
391
392
 
392
393
  /**
393
394
  * Prisma currently seems to ignore the @map() in enum declarations.
@@ -1854,7 +1855,16 @@ interface DeltaLeaderboardFilter extends BasePlayerFilter {
1854
1855
  period: Period | string;
1855
1856
  }
1856
1857
 
1857
- declare class DeltasClient {
1858
+ declare class BaseAPIClient {
1859
+ private axiosInstance;
1860
+ constructor(axiosInstance: AxiosInstance);
1861
+ postRequest<T>(path: string, body?: unknown): Promise<T>;
1862
+ putRequest<T>(path: string, body?: unknown): Promise<T>;
1863
+ deleteRequest<T>(path: string, body?: unknown): Promise<T>;
1864
+ getRequest<T>(path: string, params?: unknown): Promise<T>;
1865
+ }
1866
+
1867
+ declare class DeltasClient extends BaseAPIClient {
1858
1868
  /**
1859
1869
  * Fetches the current top leaderboard for a specific metric, period, playerType, playerBuild and country.
1860
1870
  * @returns A list of deltas, with their respective players, values and dates included.
@@ -1862,12 +1872,12 @@ declare class DeltasClient {
1862
1872
  getDeltaLeaderboard(filter: DeltaLeaderboardFilter): Promise<DeltaLeaderboardEntry[]>;
1863
1873
  }
1864
1874
 
1865
- declare type PaginationOptions = Partial<{
1866
- limit: number;
1867
- offset: number;
1868
- }>;
1875
+ interface PaginationOptions {
1876
+ limit?: number;
1877
+ offset?: number;
1878
+ }
1869
1879
 
1870
- declare class GroupsClient {
1880
+ declare class GroupsClient extends BaseAPIClient {
1871
1881
  /**
1872
1882
  * Searches for groups that match a partial name.
1873
1883
  * @returns A list of groups.
@@ -1946,7 +1956,7 @@ declare class GroupsClient {
1946
1956
  getGroupStatistics(id: number): Promise<GroupStatistics>;
1947
1957
  }
1948
1958
 
1949
- declare class PlayersClient {
1959
+ declare class PlayersClient extends BaseAPIClient {
1950
1960
  /**
1951
1961
  * Searches players by partial username.
1952
1962
  * @returns A list of players.
@@ -2019,7 +2029,7 @@ declare class PlayersClient {
2019
2029
  getPlayerNames(player: PlayerResolvable): Promise<NameChange[]>;
2020
2030
  }
2021
2031
 
2022
- declare class RecordsClient {
2032
+ declare class RecordsClient extends BaseAPIClient {
2023
2033
  /**
2024
2034
  * Fetches the current records leaderboard for a specific metric, period, playerType, playerBuild and country.
2025
2035
  * @returns A list of records, with their respective players, dates and values included.
@@ -2027,7 +2037,7 @@ declare class RecordsClient {
2027
2037
  getRecordLeaderboard(filter: RecordLeaderboardFilter): Promise<RecordLeaderboardEntry[]>;
2028
2038
  }
2029
2039
 
2030
- declare class EfficiencyClient {
2040
+ declare class EfficiencyClient extends BaseAPIClient {
2031
2041
  /**
2032
2042
  * Fetches the current efficiency leaderboard for a specific efficiency metric, playerType, playerBuild and country.
2033
2043
  * @returns A list of players.
@@ -2045,7 +2055,7 @@ declare class EfficiencyClient {
2045
2055
  getEHBRates(algorithmType: EfficiencyAlgorithmTypeUnion): Promise<BossMetaConfig[]>;
2046
2056
  }
2047
2057
 
2048
- declare class NameChangesClient {
2058
+ declare class NameChangesClient extends BaseAPIClient {
2049
2059
  /**
2050
2060
  * Searches for name changes that match a name and/or status filter.
2051
2061
  * @returns A list of name changes.
@@ -2063,7 +2073,7 @@ declare class NameChangesClient {
2063
2073
  getNameChangeDetails(id: number): Promise<NameChangeDetails>;
2064
2074
  }
2065
2075
 
2066
- declare class CompetitionsClient {
2076
+ declare class CompetitionsClient extends BaseAPIClient {
2067
2077
  /**
2068
2078
  * Searches for competitions that match a title, type, metric and status filter.
2069
2079
  * @returns A list of competitions.
@@ -2122,6 +2132,11 @@ declare class CompetitionsClient {
2122
2132
  updateAll(id: number, verificationCode: string): Promise<GenericCountMessageResponse>;
2123
2133
  }
2124
2134
 
2135
+ interface WOMClientOptions {
2136
+ apiKey?: string;
2137
+ userAgent?: string;
2138
+ baseAPIUrl?: string;
2139
+ }
2125
2140
  declare class WOMClient {
2126
2141
  deltas: DeltasClient;
2127
2142
  groups: GroupsClient;
@@ -2130,7 +2145,7 @@ declare class WOMClient {
2130
2145
  efficiency: EfficiencyClient;
2131
2146
  nameChanges: NameChangesClient;
2132
2147
  competitions: CompetitionsClient;
2133
- constructor();
2148
+ constructor(options?: WOMClientOptions);
2134
2149
  }
2135
2150
 
2136
2151
  export { ACTIVITIES, Achievement, AchievementDefinition, AchievementProgress, AchievementTemplate, Activity, ActivityDelta, ActivityValue, AlgorithmCache, AssertPlayerTypeResponse, BOSSES, Bonus, BonusType, Boss, BossDelta, BossMetaConfig, BossValue, CAPPED_MAX_TOTAL_XP, CMLGroupData, COMBAT_SKILLS, COMPETITION_STATUSES, COMPETITION_TYPES, COMPUTED_METRICS, COUNTRY_CODES, ChangeMemberRolePayload, CompetitionDetails, CompetitionListItem, CompetitionStatus, CompetitionStatusProps, CompetitionType, CompetitionTypeProps, CompetitionWithParticipations, CompetitionsSearchFilter, ComputedMetric, ComputedMetricDelta, ComputedMetricValue, Country, CountryDetails, CountryProps, CreateCompetitionPayload, CreateCompetitionResponse, CreateGroupPayload, CreateGroupResponse, DeltaLeaderboardEntry, DeltaLeaderboardFilter, EditCompetitionPayload, EditGroupPayload, EfficiencyAlgorithm, EfficiencyAlgorithmType, EfficiencyAlgorithmTypeUnion, EfficiencyLeaderboardsFilter, EfficiencyMap, ExperienceMap, ExtendedAchievement, F2P_BOSSES, FormattedSnapshot, GROUP_ROLES, GenericCountMessageResponse, GenericMessageResponse, GetGroupGainsFilter, GetPlayerGainsResponse, GroupDetails, GroupHiscoresActivityItem, GroupHiscoresBossItem, GroupHiscoresComputedMetricItem, GroupHiscoresEntry, GroupHiscoresSkillItem, GroupListItem, GroupMemberFragment, GroupRecordsFilter, GroupRole, GroupRoleProps, GroupStatistics, KillcountMap, MAX_LEVEL, MAX_SKILL_EXP, MAX_VIRTUAL_LEVEL, MEMBER_SKILLS, METRICS, MeasuredDeltaProgress, MemberInput, MembershipWithGroup, MembershipWithPlayer, Metric, MetricMeasure, MetricProps, MetricType, MigrationDataSource, NameChangeDetails, NameChangeStatus, NameChangesSearchFilter, PERIODS, PLAYER_BUILDS, PLAYER_TYPES, PRIVELEGED_GROUP_ROLES, ParticipationWithCompetition, ParticipationWithPlayer, ParticipationWithPlayerAndProgress, Period, PeriodProps, Player, PlayerBuild, PlayerBuildProps, PlayerDeltasArray, PlayerDeltasMap, PlayerDetails, PlayerRecordsFilter, PlayerResolvable, PlayerType, PlayerTypeProps, REAL_SKILLS, Record, RecordLeaderboardEntry, RecordLeaderboardFilter, SKILLS, SKILL_EXP_AT_99, Skill, SkillDelta, SkillMetaConfig, SkillValue, Snapshot, SnapshotDataSource, SnapshotFragment, Team, TempleGroupData, TimeRangeFilter, Top5ProgressResult, WOMClient, findCountry, findCountryByCode, findCountryByName, findGroupRole, findMetric, findPeriod, findPlayerBuild, findPlayerType, formatNumber, getCombatLevel, getExpForLevel, getLevel, getMetricMeasure, getMetricName, getMetricRankKey, getMetricValueKey, getMinimumBossKc, getParentEfficiencyMetric, isActivity, isBoss, isCompetitionStatus, isCompetitionType, isComputedMetric, isCountry, isGroupRole, isMetric, isPeriod, isPlayerBuild, isPlayerType, isSkill, padNumber, parseMetricAbbreviation, parsePeriodExpression, round };
package/dist/index.js CHANGED
@@ -4,14 +4,19 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var axios = require('axios');
6
6
  var dayjs = require('dayjs');
7
- var customParseFormaPlugin = require('dayjs/plugin/customParseFormat');
7
+ var customParseFormatPlugin = require('dayjs/plugin/customParseFormat');
8
8
  var lodash = require('lodash');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
12
12
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
13
13
  var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
14
- var customParseFormaPlugin__default = /*#__PURE__*/_interopDefaultLegacy(customParseFormaPlugin);
14
+ var customParseFormatPlugin__default = /*#__PURE__*/_interopDefaultLegacy(customParseFormatPlugin);
15
+
16
+ var config = {
17
+ defaultUserAgent: `WiseOldMan JS Client v${process.env.npm_package_version}`,
18
+ baseAPIUrl: 'https://api.wiseoldman.net/v2'
19
+ };
15
20
 
16
21
  /******************************************************************************
17
22
  Copyright (c) Microsoft Corporation.
@@ -38,12 +43,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
38
43
  });
39
44
  }
40
45
 
41
- var config = {
42
- // apiBaseUrl: 'http://localhost:5001'
43
- apiBaseUrl: 'https://api.wiseoldman.net/v2'
44
- };
45
-
46
- dayjs__default["default"].extend(customParseFormaPlugin__default["default"]);
46
+ dayjs__default["default"].extend(customParseFormatPlugin__default["default"]);
47
47
  function traverseTransform(input, transformation) {
48
48
  if (Array.isArray(input)) {
49
49
  return input.map(item => traverseTransform(item, transformation));
@@ -84,58 +84,6 @@ function handleError(requestURL, e) {
84
84
  throw new InternalServerError(requestURL, data.message);
85
85
  }
86
86
  }
87
- function sendPostRequest(path, body) {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- const requestURL = `${config.apiBaseUrl}${path}`;
90
- return axios__default["default"]
91
- .post(requestURL, body || {})
92
- .then(response => transformDates(response.data))
93
- .catch(e => {
94
- if (axios__default["default"].isAxiosError(e))
95
- handleError(requestURL, e);
96
- throw e;
97
- });
98
- });
99
- }
100
- function sendPutRequest(path, body) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- const requestURL = `${config.apiBaseUrl}${path}`;
103
- return axios__default["default"]
104
- .put(requestURL, body || {})
105
- .then(response => transformDates(response.data))
106
- .catch(e => {
107
- if (axios__default["default"].isAxiosError(e))
108
- handleError(requestURL, e);
109
- throw e;
110
- });
111
- });
112
- }
113
- function sendDeleteRequest(path, body) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- const requestURL = `${config.apiBaseUrl}${path}`;
116
- return axios__default["default"]
117
- .delete(requestURL, { data: body })
118
- .then(response => transformDates(response.data))
119
- .catch(e => {
120
- if (axios__default["default"].isAxiosError(e))
121
- handleError(requestURL, e);
122
- throw e;
123
- });
124
- });
125
- }
126
- function sendGetRequest(path, params) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- const requestURL = `${config.apiBaseUrl}${path}`;
129
- return axios__default["default"]
130
- .get(requestURL, { params })
131
- .then(response => transformDates(response.data))
132
- .catch(e => {
133
- if (axios__default["default"].isAxiosError(e))
134
- handleError(requestURL, e);
135
- throw e;
136
- });
137
- });
138
- }
139
87
  class BadRequestError extends Error {
140
88
  constructor(resource, message, data) {
141
89
  super(message);
@@ -178,58 +126,112 @@ class InternalServerError extends Error {
178
126
  }
179
127
  }
180
128
 
181
- class DeltasClient {
129
+ class BaseAPIClient {
130
+ constructor(axiosInstance) {
131
+ this.axiosInstance = axiosInstance;
132
+ }
133
+ postRequest(path, body) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ return this.axiosInstance
136
+ .post(path, body || {})
137
+ .then(response => transformDates(response.data))
138
+ .catch(e => {
139
+ if (axios__default["default"].isAxiosError(e))
140
+ handleError(path, e);
141
+ throw e;
142
+ });
143
+ });
144
+ }
145
+ putRequest(path, body) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ return this.axiosInstance
148
+ .put(path, body || {})
149
+ .then(response => transformDates(response.data))
150
+ .catch(e => {
151
+ if (axios__default["default"].isAxiosError(e))
152
+ handleError(path, e);
153
+ throw e;
154
+ });
155
+ });
156
+ }
157
+ deleteRequest(path, body) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ return this.axiosInstance
160
+ .delete(path, { data: body })
161
+ .then(response => transformDates(response.data))
162
+ .catch(e => {
163
+ if (axios__default["default"].isAxiosError(e))
164
+ handleError(path, e);
165
+ throw e;
166
+ });
167
+ });
168
+ }
169
+ getRequest(path, params) {
170
+ return __awaiter(this, void 0, void 0, function* () {
171
+ return this.axiosInstance
172
+ .get(path, { params })
173
+ .then(response => transformDates(response.data))
174
+ .catch(e => {
175
+ if (axios__default["default"].isAxiosError(e))
176
+ handleError(path, e);
177
+ throw e;
178
+ });
179
+ });
180
+ }
181
+ }
182
+
183
+ class DeltasClient extends BaseAPIClient {
182
184
  /**
183
185
  * Fetches the current top leaderboard for a specific metric, period, playerType, playerBuild and country.
184
186
  * @returns A list of deltas, with their respective players, values and dates included.
185
187
  */
186
188
  getDeltaLeaderboard(filter) {
187
- return sendGetRequest('/deltas/leaderboard', filter);
189
+ return this.getRequest('/deltas/leaderboard', filter);
188
190
  }
189
191
  }
190
192
 
191
- class GroupsClient {
193
+ class GroupsClient extends BaseAPIClient {
192
194
  /**
193
195
  * Searches for groups that match a partial name.
194
196
  * @returns A list of groups.
195
197
  */
196
198
  searchGroups(name, pagination) {
197
- return sendGetRequest('/groups', Object.assign({ name }, pagination));
199
+ return this.getRequest('/groups', Object.assign({ name }, pagination));
198
200
  }
199
201
  /**
200
202
  * Fetches a group's details, including a list of membership objects.
201
203
  * @returns A group details object.
202
204
  */
203
205
  getGroupDetails(id) {
204
- return sendGetRequest(`/groups/${id}`);
206
+ return this.getRequest(`/groups/${id}`);
205
207
  }
206
208
  /**
207
209
  * Creates a new group.
208
210
  * @returns The newly created group, and the verification code that authorizes future changes to it.
209
211
  */
210
212
  createGroup(payload) {
211
- return sendPostRequest('/groups', payload);
213
+ return this.postRequest('/groups', payload);
212
214
  }
213
215
  /**
214
216
  * Edits an existing group.
215
217
  * @returns The updated group.
216
218
  */
217
219
  editGroup(id, payload, verificationCode) {
218
- return sendPutRequest(`/groups/${id}`, Object.assign(Object.assign({}, payload), { verificationCode }));
220
+ return this.putRequest(`/groups/${id}`, Object.assign(Object.assign({}, payload), { verificationCode }));
219
221
  }
220
222
  /**
221
223
  * Deletes an existing group.
222
224
  * @returns A confirmation message.
223
225
  */
224
226
  deleteGroup(id, verificationCode) {
225
- return sendDeleteRequest(`/groups/${id}`, { verificationCode });
227
+ return this.deleteRequest(`/groups/${id}`, { verificationCode });
226
228
  }
227
229
  /**
228
230
  * Adds all (valid) given usernames (and roles) to a group, ignoring duplicates.
229
231
  * @returns The number of members added and a confirmation message.
230
232
  */
231
233
  addMembers(id, members, verificationCode) {
232
- return sendPostRequest(`/groups/${id}/members`, {
234
+ return this.postRequest(`/groups/${id}/members`, {
233
235
  verificationCode,
234
236
  members
235
237
  });
@@ -239,7 +241,7 @@ class GroupsClient {
239
241
  * @returns The number of members removed and a confirmation message.
240
242
  */
241
243
  removeMembers(id, usernames, verificationCode) {
242
- return sendDeleteRequest(`/groups/${id}/members`, {
244
+ return this.deleteRequest(`/groups/${id}/members`, {
243
245
  verificationCode,
244
246
  members: usernames
245
247
  });
@@ -249,14 +251,14 @@ class GroupsClient {
249
251
  * @returns The updated membership, with player included.
250
252
  */
251
253
  changeRole(id, payload, verificationCode) {
252
- return sendPutRequest(`/groups/${id}/role`, Object.assign(Object.assign({}, payload), { verificationCode }));
254
+ return this.putRequest(`/groups/${id}/role`, Object.assign(Object.assign({}, payload), { verificationCode }));
253
255
  }
254
256
  /**
255
257
  * Adds an "update" request to the queue, for each outdated group member.
256
258
  * @returns The number of players to be updated and a confirmation message.
257
259
  */
258
260
  updateAll(id, verificationCode) {
259
- return sendPostRequest(`/groups/${id}/update-all`, {
261
+ return this.postRequest(`/groups/${id}/update-all`, {
260
262
  verificationCode
261
263
  });
262
264
  }
@@ -265,146 +267,146 @@ class GroupsClient {
265
267
  * @returns A list of competitions.
266
268
  */
267
269
  getGroupCompetitions(id, pagination) {
268
- return sendGetRequest(`/groups/${id}/competitions`, Object.assign({}, pagination));
270
+ return this.getRequest(`/groups/${id}/competitions`, Object.assign({}, pagination));
269
271
  }
270
272
  getGroupGains(id, filter, pagination) {
271
- return sendGetRequest(`/groups/${id}/gained`, Object.assign(Object.assign({}, pagination), filter));
273
+ return this.getRequest(`/groups/${id}/gained`, Object.assign(Object.assign({}, pagination), filter));
272
274
  }
273
275
  /**
274
276
  * Fetches a group members' latest achievements.
275
277
  * @returns A list of achievements.
276
278
  */
277
279
  getGroupAchievements(id, pagination) {
278
- return sendGetRequest(`/groups/${id}/achievements`, Object.assign({}, pagination));
280
+ return this.getRequest(`/groups/${id}/achievements`, Object.assign({}, pagination));
279
281
  }
280
282
  /**
281
283
  * Fetches a group's record leaderboard for a specific metric and period.
282
284
  * @returns A list of records, including their respective players.
283
285
  */
284
286
  getGroupRecords(id, filter, pagination) {
285
- return sendGetRequest(`/groups/${id}/records`, Object.assign(Object.assign({}, pagination), filter));
287
+ return this.getRequest(`/groups/${id}/records`, Object.assign(Object.assign({}, pagination), filter));
286
288
  }
287
289
  /**
288
290
  * Fetches a group's hiscores for a specific metric.
289
291
  * @returns A list of hiscores entries (value, rank), including their respective players.
290
292
  */
291
293
  getGroupHiscores(id, metric, pagination) {
292
- return sendGetRequest(`/groups/${id}/hiscores`, Object.assign(Object.assign({}, pagination), { metric }));
294
+ return this.getRequest(`/groups/${id}/hiscores`, Object.assign(Object.assign({}, pagination), { metric }));
293
295
  }
294
296
  /**
295
297
  * Fetches a group members' latest name changes.
296
298
  * @returns A list of name change (approved) requests.
297
299
  */
298
300
  getGroupNameChanges(id, pagination) {
299
- return sendGetRequest(`/groups/${id}/name-changes`, Object.assign({}, pagination));
301
+ return this.getRequest(`/groups/${id}/name-changes`, Object.assign({}, pagination));
300
302
  }
301
303
  /**
302
304
  * Fetches a group's general statistics.
303
305
  * @returns An object with a few statistic values and an average stats snapshot.
304
306
  */
305
307
  getGroupStatistics(id) {
306
- return sendGetRequest(`/groups/${id}/statistics`);
308
+ return this.getRequest(`/groups/${id}/statistics`);
307
309
  }
308
310
  }
309
311
 
310
- class PlayersClient {
312
+ class PlayersClient extends BaseAPIClient {
311
313
  /**
312
314
  * Searches players by partial username.
313
315
  * @returns A list of players.
314
316
  */
315
317
  searchPlayers(partialUsername, pagination) {
316
- return sendGetRequest('/players/search', Object.assign({ username: partialUsername }, pagination));
318
+ return this.getRequest('/players/search', Object.assign({ username: partialUsername }, pagination));
317
319
  }
318
320
  /**
319
321
  * Updates/tracks a player.
320
322
  * @returns The player's new details, including the latest snapshot.
321
323
  */
322
324
  updatePlayer(player) {
323
- return sendPostRequest(getPlayerURL(player));
325
+ return this.postRequest(getPlayerURL(player));
324
326
  }
325
327
  /**
326
328
  * Asserts (and attempts to fix, if necessary) a player's game-mode type.
327
329
  * @returns The updated player, and an indication of whether the type was changed.
328
330
  */
329
331
  assertPlayerType(player) {
330
- return sendPostRequest(`${getPlayerURL(player)}/assert-type`);
332
+ return this.postRequest(`${getPlayerURL(player)}/assert-type`);
331
333
  }
332
334
  /**
333
335
  * Attempts to import a player's snapshot history from CrystalMathLabs.
334
336
  * @returns The number of snapshots that were imported.
335
337
  */
336
338
  importPlayer(player) {
337
- return sendPostRequest(`${getPlayerURL(player)}/import-history`);
339
+ return this.postRequest(`${getPlayerURL(player)}/import-history`);
338
340
  }
339
341
  /**
340
342
  * Fetches a player's details.
341
343
  * @returns The player's details, including the latest snapshot.
342
344
  */
343
345
  getPlayerDetails(player) {
344
- return sendGetRequest(getPlayerURL(player));
346
+ return this.getRequest(getPlayerURL(player));
345
347
  }
346
348
  /**
347
349
  * Fetches a player's current achievements.
348
350
  * @returns A list of achievements.
349
351
  */
350
352
  getPlayerAchievements(player) {
351
- return sendGetRequest(`${getPlayerURL(player)}/achievements`);
353
+ return this.getRequest(`${getPlayerURL(player)}/achievements`);
352
354
  }
353
355
  /**
354
356
  * Fetches a player's current achievement progress.
355
357
  * @returns A list of achievements (completed or otherwise), with their respective relative/absolute progress percentage.
356
358
  */
357
359
  getPlayerAchievementProgress(player) {
358
- return sendGetRequest(`${getPlayerURL(player)}/achievements/progress`);
360
+ return this.getRequest(`${getPlayerURL(player)}/achievements/progress`);
359
361
  }
360
362
  /**
361
363
  * Fetches all of the player's competition participations.
362
364
  * @returns A list of participations, with the respective competition included.
363
365
  */
364
366
  getPlayerCompetitions(player, pagination) {
365
- return sendGetRequest(`${getPlayerURL(player)}/competitions`, pagination);
367
+ return this.getRequest(`${getPlayerURL(player)}/competitions`, pagination);
366
368
  }
367
369
  /**
368
370
  * Fetches all of the player's group memberships.
369
371
  * @returns A list of memberships, with the respective group included.
370
372
  */
371
373
  getPlayerGroups(player, pagination) {
372
- return sendGetRequest(`${getPlayerURL(player)}/groups`, pagination);
374
+ return this.getRequest(`${getPlayerURL(player)}/groups`, pagination);
373
375
  }
374
376
  /**
375
377
  * Fetches a player's gains, for a specific period or time range, as a [metric: data] map.
376
378
  * @returns A map of each metric's gained data.
377
379
  */
378
380
  getPlayerGains(player, options) {
379
- return sendGetRequest(`${getPlayerURL(player)}/gained`, options);
381
+ return this.getRequest(`${getPlayerURL(player)}/gained`, options);
380
382
  }
381
383
  /**
382
384
  * Fetches a player's gains, for a specific period or time range, as an array.
383
385
  * @returns An array of each metric's gained data.
384
386
  */
385
387
  getPlayerGainsAsArray(player, options) {
386
- return sendGetRequest(`${getPlayerURL(player)}/gained`, Object.assign(Object.assign({}, options), { formatting: 'array' }));
388
+ return this.getRequest(`${getPlayerURL(player)}/gained`, Object.assign(Object.assign({}, options), { formatting: 'array' }));
387
389
  }
388
390
  /**
389
391
  * Fetches all of the player's records.
390
392
  * @returns A list of records.
391
393
  */
392
394
  getPlayerRecords(player, options) {
393
- return sendGetRequest(`${getPlayerURL(player)}/records`, options);
395
+ return this.getRequest(`${getPlayerURL(player)}/records`, options);
394
396
  }
395
397
  /**
396
398
  * Fetches all of the player's past snapshots.
397
399
  * @returns A list of snapshots.
398
400
  */
399
401
  getPlayerSnapshots(player, options) {
400
- return sendGetRequest(`${getPlayerURL(player)}/snapshots`, options);
402
+ return this.getRequest(`${getPlayerURL(player)}/snapshots`, options);
401
403
  }
402
404
  /**
403
405
  * Fetches all of the player's approved name changes.
404
406
  * @returns A list of name changes.
405
407
  */
406
408
  getPlayerNames(player) {
407
- return sendGetRequest(`${getPlayerURL(player)}/names`);
409
+ return this.getRequest(`${getPlayerURL(player)}/names`);
408
410
  }
409
411
  }
410
412
  function getPlayerURL(player) {
@@ -417,13 +419,13 @@ function getPlayerURL(player) {
417
419
  return `/players/${player.username}`;
418
420
  }
419
421
 
420
- class RecordsClient {
422
+ class RecordsClient extends BaseAPIClient {
421
423
  /**
422
424
  * Fetches the current records leaderboard for a specific metric, period, playerType, playerBuild and country.
423
425
  * @returns A list of records, with their respective players, dates and values included.
424
426
  */
425
427
  getRecordLeaderboard(filter) {
426
- return sendGetRequest('/records/leaderboard', filter);
428
+ return this.getRequest('/records/leaderboard', filter);
427
429
  }
428
430
  }
429
431
 
@@ -2317,68 +2319,71 @@ exports.SnapshotDataSource = void 0;
2317
2319
  SnapshotDataSource[SnapshotDataSource["CRYSTAL_MATH_LABS"] = 1] = "CRYSTAL_MATH_LABS";
2318
2320
  })(exports.SnapshotDataSource || (exports.SnapshotDataSource = {}));
2319
2321
 
2320
- class EfficiencyClient {
2322
+ class EfficiencyClient extends BaseAPIClient {
2321
2323
  /**
2322
2324
  * Fetches the current efficiency leaderboard for a specific efficiency metric, playerType, playerBuild and country.
2323
2325
  * @returns A list of players.
2324
2326
  */
2325
2327
  getEfficiencyLeaderboards(filter, pagination) {
2326
- return sendGetRequest('/efficiency/leaderboard', Object.assign(Object.assign({}, filter), pagination));
2328
+ return this.getRequest('/efficiency/leaderboard', Object.assign(Object.assign({}, filter), pagination));
2327
2329
  }
2328
2330
  /**
2329
2331
  * Fetches the top EHP (Efficient Hours Played) rates.
2330
2332
  * @returns A list of skilling methods and their bonus exp ratios.
2331
2333
  */
2332
2334
  getEHPRates(algorithmType) {
2333
- return sendGetRequest('/efficiency/rates', { metric: Metric.EHP, type: algorithmType });
2335
+ return this.getRequest('/efficiency/rates', { metric: Metric.EHP, type: algorithmType });
2334
2336
  }
2335
2337
  /**
2336
2338
  * Fetches the top EHB (Efficient Hours Bossed) rates.
2337
2339
  * @returns A list of bosses and their respective "per-hour" kill rates.
2338
2340
  */
2339
2341
  getEHBRates(algorithmType) {
2340
- return sendGetRequest('/efficiency/rates', { metric: Metric.EHB, type: algorithmType });
2342
+ return this.getRequest('/efficiency/rates', {
2343
+ metric: Metric.EHB,
2344
+ type: algorithmType
2345
+ });
2341
2346
  }
2342
2347
  }
2343
2348
 
2344
- class NameChangesClient {
2349
+ class NameChangesClient extends BaseAPIClient {
2345
2350
  /**
2346
2351
  * Searches for name changes that match a name and/or status filter.
2347
2352
  * @returns A list of name changes.
2348
2353
  */
2349
2354
  searchNameChanges(filter, pagination) {
2350
- return sendGetRequest('/names', Object.assign(Object.assign({}, filter), pagination));
2355
+ return this.getRequest('/names', Object.assign(Object.assign({}, filter), pagination));
2351
2356
  }
2352
2357
  /**
2353
2358
  * Submits a name change request between two usernames (old and new).
2354
2359
  * @returns A pending name change request, to be reviewed and resolved at a later date.
2355
2360
  */
2356
2361
  submitNameChange(oldName, newName) {
2357
- return sendPostRequest('/names', { oldName, newName });
2362
+ return this.postRequest('/names', { oldName, newName });
2358
2363
  }
2359
2364
  /**
2360
2365
  * Gets details on a specific name change request.
2361
2366
  * @returns The name change request's details, which includes all data required to review.
2362
2367
  */
2363
2368
  getNameChangeDetails(id) {
2364
- return sendGetRequest(`/names/${id}`);
2369
+ return this.getRequest(`/names/${id}`);
2365
2370
  }
2366
2371
  }
2367
2372
 
2368
- class CompetitionsClient {
2373
+ class CompetitionsClient extends BaseAPIClient {
2369
2374
  /**
2370
2375
  * Searches for competitions that match a title, type, metric and status filter.
2371
2376
  * @returns A list of competitions.
2372
2377
  */
2373
2378
  searchCompetitions(filter, pagination) {
2374
- return sendGetRequest('/competitions', Object.assign(Object.assign({}, filter), pagination));
2379
+ return this.getRequest('/competitions', Object.assign(Object.assign({}, filter), pagination));
2375
2380
  }
2376
2381
  /**
2377
2382
  * Fetches the competition's full details, including all the participants and their progress.
2378
2383
  * @returns A competition with a list of participants.
2379
2384
  */
2380
2385
  getCompetitionDetails(id, previewMetric) {
2381
- return sendGetRequest(`/competitions/${id}`, { metric: previewMetric });
2386
+ return this.getRequest(`/competitions/${id}`, { metric: previewMetric });
2382
2387
  }
2383
2388
  /**
2384
2389
  * Fetches all the values (exp, kc, etc) in chronological order within the bounds
@@ -2386,7 +2391,7 @@ class CompetitionsClient {
2386
2391
  * @returns A list of competition progress objects, including the player and their value history over time.
2387
2392
  */
2388
2393
  getCompetitionTopHistory(id, previewMetric) {
2389
- return sendGetRequest(`/competitions/${id}/top-history`, {
2394
+ return this.getRequest(`/competitions/${id}/top-history`, {
2390
2395
  metric: previewMetric
2391
2396
  });
2392
2397
  }
@@ -2395,28 +2400,28 @@ class CompetitionsClient {
2395
2400
  * @returns The newly created competition, and the verification code that authorizes future changes to it.
2396
2401
  */
2397
2402
  createCompetition(payload) {
2398
- return sendPostRequest('/competitions', payload);
2403
+ return this.postRequest('/competitions', payload);
2399
2404
  }
2400
2405
  /**
2401
2406
  * Edits an existing competition.
2402
2407
  * @returns The updated competition.
2403
2408
  */
2404
2409
  editCompetition(id, payload, verificationCode) {
2405
- return sendPutRequest(`/competitions/${id}`, Object.assign(Object.assign({}, payload), { verificationCode }));
2410
+ return this.putRequest(`/competitions/${id}`, Object.assign(Object.assign({}, payload), { verificationCode }));
2406
2411
  }
2407
2412
  /**
2408
2413
  * Deletes an existing competition.
2409
2414
  * @returns A confirmation message.
2410
2415
  */
2411
2416
  deleteCompetition(id, verificationCode) {
2412
- return sendDeleteRequest(`/competitions/${id}`, { verificationCode });
2417
+ return this.deleteRequest(`/competitions/${id}`, { verificationCode });
2413
2418
  }
2414
2419
  /**
2415
2420
  * Adds all (valid) given participants to a competition, ignoring duplicates.
2416
2421
  * @returns The number of participants added and a confirmation message.
2417
2422
  */
2418
2423
  addParticipants(id, participants, verificationCode) {
2419
- return sendPostRequest(`/competitions/${id}/participants`, {
2424
+ return this.postRequest(`/competitions/${id}/participants`, {
2420
2425
  verificationCode,
2421
2426
  participants
2422
2427
  });
@@ -2426,7 +2431,7 @@ class CompetitionsClient {
2426
2431
  * @returns The number of participants removed and a confirmation message.
2427
2432
  */
2428
2433
  removeParticipants(id, participants, verificationCode) {
2429
- return sendDeleteRequest(`/competitions/${id}/participants`, {
2434
+ return this.deleteRequest(`/competitions/${id}/participants`, {
2430
2435
  verificationCode,
2431
2436
  participants
2432
2437
  });
@@ -2436,7 +2441,7 @@ class CompetitionsClient {
2436
2441
  * @returns The number of participants added and a confirmation message.
2437
2442
  */
2438
2443
  addTeams(id, teams, verificationCode) {
2439
- return sendPostRequest(`/competitions/${id}/teams`, {
2444
+ return this.postRequest(`/competitions/${id}/teams`, {
2440
2445
  verificationCode,
2441
2446
  teams
2442
2447
  });
@@ -2446,7 +2451,7 @@ class CompetitionsClient {
2446
2451
  * @returns The number of participants removed and a confirmation message.
2447
2452
  */
2448
2453
  removeTeams(id, teamNames, verificationCode) {
2449
- return sendDeleteRequest(`/competitions/${id}/teams`, {
2454
+ return this.deleteRequest(`/competitions/${id}/teams`, {
2450
2455
  verificationCode,
2451
2456
  teamNames
2452
2457
  });
@@ -2456,21 +2461,28 @@ class CompetitionsClient {
2456
2461
  * @returns The number of players to be updated and a confirmation message.
2457
2462
  */
2458
2463
  updateAll(id, verificationCode) {
2459
- return sendPostRequest(`/competitions/${id}/update-all`, {
2464
+ return this.postRequest(`/competitions/${id}/update-all`, {
2460
2465
  verificationCode
2461
2466
  });
2462
2467
  }
2463
2468
  }
2464
2469
 
2465
2470
  class WOMClient {
2466
- constructor() {
2467
- this.deltas = new DeltasClient();
2468
- this.groups = new GroupsClient();
2469
- this.players = new PlayersClient();
2470
- this.records = new RecordsClient();
2471
- this.efficiency = new EfficiencyClient();
2472
- this.nameChanges = new NameChangesClient();
2473
- this.competitions = new CompetitionsClient();
2471
+ constructor(options) {
2472
+ const axiosInstance = axios__default["default"].create({
2473
+ baseURL: (options === null || options === void 0 ? void 0 : options.baseAPIUrl) || config.baseAPIUrl,
2474
+ headers: {
2475
+ 'x-api-key': (options === null || options === void 0 ? void 0 : options.apiKey) || null,
2476
+ 'x-user-agent': (options === null || options === void 0 ? void 0 : options.userAgent) || config.defaultUserAgent
2477
+ }
2478
+ });
2479
+ this.deltas = new DeltasClient(axiosInstance);
2480
+ this.groups = new GroupsClient(axiosInstance);
2481
+ this.players = new PlayersClient(axiosInstance);
2482
+ this.records = new RecordsClient(axiosInstance);
2483
+ this.efficiency = new EfficiencyClient(axiosInstance);
2484
+ this.nameChanges = new NameChangesClient(axiosInstance);
2485
+ this.competitions = new CompetitionsClient(axiosInstance);
2474
2486
  }
2475
2487
  }
2476
2488
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise-old-man/utils",
3
- "version": "2.0.0-beta.4",
3
+ "version": "2.0.0-beta.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",