@wise-old-man/utils 2.0.0-beta.3 → 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 +33 -23
  2. package/dist/index.js +137 -132
  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.
@@ -1558,7 +1559,7 @@ interface FormattedSnapshot {
1558
1559
  interface GroupListItem extends Omit<Group, 'verificationHash'> {
1559
1560
  memberCount: number;
1560
1561
  }
1561
- interface GroupWithMemberships extends GroupListItem {
1562
+ interface GroupDetails extends GroupListItem {
1562
1563
  memberships: MembershipWithPlayer[];
1563
1564
  }
1564
1565
  interface MembershipWithGroup extends Membership {
@@ -1762,7 +1763,7 @@ interface CreateGroupPayload {
1762
1763
  }
1763
1764
  declare type EditGroupPayload = Partial<CreateGroupPayload>;
1764
1765
  interface CreateGroupResponse {
1765
- group: GroupWithMemberships;
1766
+ group: GroupDetails;
1766
1767
  verificationCode: string;
1767
1768
  }
1768
1769
  interface ChangeMemberRolePayload {
@@ -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,27 +1872,22 @@ 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.
1874
1884
  */
1875
1885
  searchGroups(name: string, pagination?: PaginationOptions): Promise<GroupListItem[]>;
1876
1886
  /**
1877
- * Fetches a group's details.
1887
+ * Fetches a group's details, including a list of membership objects.
1878
1888
  * @returns A group details object.
1879
1889
  */
1880
- getGroupDetails(id: number): Promise<GroupListItem>;
1881
- /**
1882
- * Fetches a group's entire members list.
1883
- * @returns A list of memberships, with players included.
1884
- */
1885
- getGroupMembers(id: number): Promise<MembershipWithPlayer[]>;
1890
+ getGroupDetails(id: number): Promise<GroupDetails>;
1886
1891
  /**
1887
1892
  * Creates a new group.
1888
1893
  * @returns The newly created group, and the verification code that authorizes future changes to it.
@@ -1892,7 +1897,7 @@ declare class GroupsClient {
1892
1897
  * Edits an existing group.
1893
1898
  * @returns The updated group.
1894
1899
  */
1895
- editGroup(id: number, payload: EditGroupPayload, verificationCode: string): Promise<GroupWithMemberships>;
1900
+ editGroup(id: number, payload: EditGroupPayload, verificationCode: string): Promise<GroupDetails>;
1896
1901
  /**
1897
1902
  * Deletes an existing group.
1898
1903
  * @returns A confirmation message.
@@ -1951,7 +1956,7 @@ declare class GroupsClient {
1951
1956
  getGroupStatistics(id: number): Promise<GroupStatistics>;
1952
1957
  }
1953
1958
 
1954
- declare class PlayersClient {
1959
+ declare class PlayersClient extends BaseAPIClient {
1955
1960
  /**
1956
1961
  * Searches players by partial username.
1957
1962
  * @returns A list of players.
@@ -2024,7 +2029,7 @@ declare class PlayersClient {
2024
2029
  getPlayerNames(player: PlayerResolvable): Promise<NameChange[]>;
2025
2030
  }
2026
2031
 
2027
- declare class RecordsClient {
2032
+ declare class RecordsClient extends BaseAPIClient {
2028
2033
  /**
2029
2034
  * Fetches the current records leaderboard for a specific metric, period, playerType, playerBuild and country.
2030
2035
  * @returns A list of records, with their respective players, dates and values included.
@@ -2032,7 +2037,7 @@ declare class RecordsClient {
2032
2037
  getRecordLeaderboard(filter: RecordLeaderboardFilter): Promise<RecordLeaderboardEntry[]>;
2033
2038
  }
2034
2039
 
2035
- declare class EfficiencyClient {
2040
+ declare class EfficiencyClient extends BaseAPIClient {
2036
2041
  /**
2037
2042
  * Fetches the current efficiency leaderboard for a specific efficiency metric, playerType, playerBuild and country.
2038
2043
  * @returns A list of players.
@@ -2050,7 +2055,7 @@ declare class EfficiencyClient {
2050
2055
  getEHBRates(algorithmType: EfficiencyAlgorithmTypeUnion): Promise<BossMetaConfig[]>;
2051
2056
  }
2052
2057
 
2053
- declare class NameChangesClient {
2058
+ declare class NameChangesClient extends BaseAPIClient {
2054
2059
  /**
2055
2060
  * Searches for name changes that match a name and/or status filter.
2056
2061
  * @returns A list of name changes.
@@ -2068,7 +2073,7 @@ declare class NameChangesClient {
2068
2073
  getNameChangeDetails(id: number): Promise<NameChangeDetails>;
2069
2074
  }
2070
2075
 
2071
- declare class CompetitionsClient {
2076
+ declare class CompetitionsClient extends BaseAPIClient {
2072
2077
  /**
2073
2078
  * Searches for competitions that match a title, type, metric and status filter.
2074
2079
  * @returns A list of competitions.
@@ -2127,6 +2132,11 @@ declare class CompetitionsClient {
2127
2132
  updateAll(id: number, verificationCode: string): Promise<GenericCountMessageResponse>;
2128
2133
  }
2129
2134
 
2135
+ interface WOMClientOptions {
2136
+ apiKey?: string;
2137
+ userAgent?: string;
2138
+ baseAPIUrl?: string;
2139
+ }
2130
2140
  declare class WOMClient {
2131
2141
  deltas: DeltasClient;
2132
2142
  groups: GroupsClient;
@@ -2135,7 +2145,7 @@ declare class WOMClient {
2135
2145
  efficiency: EfficiencyClient;
2136
2146
  nameChanges: NameChangesClient;
2137
2147
  competitions: CompetitionsClient;
2138
- constructor();
2148
+ constructor(options?: WOMClientOptions);
2139
2149
  }
2140
2150
 
2141
- 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, GroupHiscoresActivityItem, GroupHiscoresBossItem, GroupHiscoresComputedMetricItem, GroupHiscoresEntry, GroupHiscoresSkillItem, GroupListItem, GroupMemberFragment, GroupRecordsFilter, GroupRole, GroupRoleProps, GroupStatistics, GroupWithMemberships, 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 };
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,65 +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
- * Fetches a group's details.
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}`);
205
- }
206
- /**
207
- * Fetches a group's entire members list.
208
- * @returns A list of memberships, with players included.
209
- */
210
- getGroupMembers(id) {
211
- return sendGetRequest(`/groups/${id}/members`);
206
+ return this.getRequest(`/groups/${id}`);
212
207
  }
213
208
  /**
214
209
  * Creates a new group.
215
210
  * @returns The newly created group, and the verification code that authorizes future changes to it.
216
211
  */
217
212
  createGroup(payload) {
218
- return sendPostRequest('/groups', payload);
213
+ return this.postRequest('/groups', payload);
219
214
  }
220
215
  /**
221
216
  * Edits an existing group.
222
217
  * @returns The updated group.
223
218
  */
224
219
  editGroup(id, payload, verificationCode) {
225
- return sendPutRequest(`/groups/${id}`, Object.assign(Object.assign({}, payload), { verificationCode }));
220
+ return this.putRequest(`/groups/${id}`, Object.assign(Object.assign({}, payload), { verificationCode }));
226
221
  }
227
222
  /**
228
223
  * Deletes an existing group.
229
224
  * @returns A confirmation message.
230
225
  */
231
226
  deleteGroup(id, verificationCode) {
232
- return sendDeleteRequest(`/groups/${id}`, { verificationCode });
227
+ return this.deleteRequest(`/groups/${id}`, { verificationCode });
233
228
  }
234
229
  /**
235
230
  * Adds all (valid) given usernames (and roles) to a group, ignoring duplicates.
236
231
  * @returns The number of members added and a confirmation message.
237
232
  */
238
233
  addMembers(id, members, verificationCode) {
239
- return sendPostRequest(`/groups/${id}/members`, {
234
+ return this.postRequest(`/groups/${id}/members`, {
240
235
  verificationCode,
241
236
  members
242
237
  });
@@ -246,7 +241,7 @@ class GroupsClient {
246
241
  * @returns The number of members removed and a confirmation message.
247
242
  */
248
243
  removeMembers(id, usernames, verificationCode) {
249
- return sendDeleteRequest(`/groups/${id}/members`, {
244
+ return this.deleteRequest(`/groups/${id}/members`, {
250
245
  verificationCode,
251
246
  members: usernames
252
247
  });
@@ -256,14 +251,14 @@ class GroupsClient {
256
251
  * @returns The updated membership, with player included.
257
252
  */
258
253
  changeRole(id, payload, verificationCode) {
259
- return sendPutRequest(`/groups/${id}/role`, Object.assign(Object.assign({}, payload), { verificationCode }));
254
+ return this.putRequest(`/groups/${id}/role`, Object.assign(Object.assign({}, payload), { verificationCode }));
260
255
  }
261
256
  /**
262
257
  * Adds an "update" request to the queue, for each outdated group member.
263
258
  * @returns The number of players to be updated and a confirmation message.
264
259
  */
265
260
  updateAll(id, verificationCode) {
266
- return sendPostRequest(`/groups/${id}/update-all`, {
261
+ return this.postRequest(`/groups/${id}/update-all`, {
267
262
  verificationCode
268
263
  });
269
264
  }
@@ -272,146 +267,146 @@ class GroupsClient {
272
267
  * @returns A list of competitions.
273
268
  */
274
269
  getGroupCompetitions(id, pagination) {
275
- return sendGetRequest(`/groups/${id}/competitions`, Object.assign({}, pagination));
270
+ return this.getRequest(`/groups/${id}/competitions`, Object.assign({}, pagination));
276
271
  }
277
272
  getGroupGains(id, filter, pagination) {
278
- return sendGetRequest(`/groups/${id}/gained`, Object.assign(Object.assign({}, pagination), filter));
273
+ return this.getRequest(`/groups/${id}/gained`, Object.assign(Object.assign({}, pagination), filter));
279
274
  }
280
275
  /**
281
276
  * Fetches a group members' latest achievements.
282
277
  * @returns A list of achievements.
283
278
  */
284
279
  getGroupAchievements(id, pagination) {
285
- return sendGetRequest(`/groups/${id}/achievements`, Object.assign({}, pagination));
280
+ return this.getRequest(`/groups/${id}/achievements`, Object.assign({}, pagination));
286
281
  }
287
282
  /**
288
283
  * Fetches a group's record leaderboard for a specific metric and period.
289
284
  * @returns A list of records, including their respective players.
290
285
  */
291
286
  getGroupRecords(id, filter, pagination) {
292
- return sendGetRequest(`/groups/${id}/records`, Object.assign(Object.assign({}, pagination), filter));
287
+ return this.getRequest(`/groups/${id}/records`, Object.assign(Object.assign({}, pagination), filter));
293
288
  }
294
289
  /**
295
290
  * Fetches a group's hiscores for a specific metric.
296
291
  * @returns A list of hiscores entries (value, rank), including their respective players.
297
292
  */
298
293
  getGroupHiscores(id, metric, pagination) {
299
- return sendGetRequest(`/groups/${id}/hiscores`, Object.assign(Object.assign({}, pagination), { metric }));
294
+ return this.getRequest(`/groups/${id}/hiscores`, Object.assign(Object.assign({}, pagination), { metric }));
300
295
  }
301
296
  /**
302
297
  * Fetches a group members' latest name changes.
303
298
  * @returns A list of name change (approved) requests.
304
299
  */
305
300
  getGroupNameChanges(id, pagination) {
306
- return sendGetRequest(`/groups/${id}/name-changes`, Object.assign({}, pagination));
301
+ return this.getRequest(`/groups/${id}/name-changes`, Object.assign({}, pagination));
307
302
  }
308
303
  /**
309
304
  * Fetches a group's general statistics.
310
305
  * @returns An object with a few statistic values and an average stats snapshot.
311
306
  */
312
307
  getGroupStatistics(id) {
313
- return sendGetRequest(`/groups/${id}/statistics`);
308
+ return this.getRequest(`/groups/${id}/statistics`);
314
309
  }
315
310
  }
316
311
 
317
- class PlayersClient {
312
+ class PlayersClient extends BaseAPIClient {
318
313
  /**
319
314
  * Searches players by partial username.
320
315
  * @returns A list of players.
321
316
  */
322
317
  searchPlayers(partialUsername, pagination) {
323
- return sendGetRequest('/players/search', Object.assign({ username: partialUsername }, pagination));
318
+ return this.getRequest('/players/search', Object.assign({ username: partialUsername }, pagination));
324
319
  }
325
320
  /**
326
321
  * Updates/tracks a player.
327
322
  * @returns The player's new details, including the latest snapshot.
328
323
  */
329
324
  updatePlayer(player) {
330
- return sendPostRequest(getPlayerURL(player));
325
+ return this.postRequest(getPlayerURL(player));
331
326
  }
332
327
  /**
333
328
  * Asserts (and attempts to fix, if necessary) a player's game-mode type.
334
329
  * @returns The updated player, and an indication of whether the type was changed.
335
330
  */
336
331
  assertPlayerType(player) {
337
- return sendPostRequest(`${getPlayerURL(player)}/assert-type`);
332
+ return this.postRequest(`${getPlayerURL(player)}/assert-type`);
338
333
  }
339
334
  /**
340
335
  * Attempts to import a player's snapshot history from CrystalMathLabs.
341
336
  * @returns The number of snapshots that were imported.
342
337
  */
343
338
  importPlayer(player) {
344
- return sendPostRequest(`${getPlayerURL(player)}/import-history`);
339
+ return this.postRequest(`${getPlayerURL(player)}/import-history`);
345
340
  }
346
341
  /**
347
342
  * Fetches a player's details.
348
343
  * @returns The player's details, including the latest snapshot.
349
344
  */
350
345
  getPlayerDetails(player) {
351
- return sendGetRequest(getPlayerURL(player));
346
+ return this.getRequest(getPlayerURL(player));
352
347
  }
353
348
  /**
354
349
  * Fetches a player's current achievements.
355
350
  * @returns A list of achievements.
356
351
  */
357
352
  getPlayerAchievements(player) {
358
- return sendGetRequest(`${getPlayerURL(player)}/achievements`);
353
+ return this.getRequest(`${getPlayerURL(player)}/achievements`);
359
354
  }
360
355
  /**
361
356
  * Fetches a player's current achievement progress.
362
357
  * @returns A list of achievements (completed or otherwise), with their respective relative/absolute progress percentage.
363
358
  */
364
359
  getPlayerAchievementProgress(player) {
365
- return sendGetRequest(`${getPlayerURL(player)}/achievements/progress`);
360
+ return this.getRequest(`${getPlayerURL(player)}/achievements/progress`);
366
361
  }
367
362
  /**
368
363
  * Fetches all of the player's competition participations.
369
364
  * @returns A list of participations, with the respective competition included.
370
365
  */
371
366
  getPlayerCompetitions(player, pagination) {
372
- return sendGetRequest(`${getPlayerURL(player)}/competitions`, pagination);
367
+ return this.getRequest(`${getPlayerURL(player)}/competitions`, pagination);
373
368
  }
374
369
  /**
375
370
  * Fetches all of the player's group memberships.
376
371
  * @returns A list of memberships, with the respective group included.
377
372
  */
378
373
  getPlayerGroups(player, pagination) {
379
- return sendGetRequest(`${getPlayerURL(player)}/groups`, pagination);
374
+ return this.getRequest(`${getPlayerURL(player)}/groups`, pagination);
380
375
  }
381
376
  /**
382
377
  * Fetches a player's gains, for a specific period or time range, as a [metric: data] map.
383
378
  * @returns A map of each metric's gained data.
384
379
  */
385
380
  getPlayerGains(player, options) {
386
- return sendGetRequest(`${getPlayerURL(player)}/gained`, options);
381
+ return this.getRequest(`${getPlayerURL(player)}/gained`, options);
387
382
  }
388
383
  /**
389
384
  * Fetches a player's gains, for a specific period or time range, as an array.
390
385
  * @returns An array of each metric's gained data.
391
386
  */
392
387
  getPlayerGainsAsArray(player, options) {
393
- 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' }));
394
389
  }
395
390
  /**
396
391
  * Fetches all of the player's records.
397
392
  * @returns A list of records.
398
393
  */
399
394
  getPlayerRecords(player, options) {
400
- return sendGetRequest(`${getPlayerURL(player)}/records`, options);
395
+ return this.getRequest(`${getPlayerURL(player)}/records`, options);
401
396
  }
402
397
  /**
403
398
  * Fetches all of the player's past snapshots.
404
399
  * @returns A list of snapshots.
405
400
  */
406
401
  getPlayerSnapshots(player, options) {
407
- return sendGetRequest(`${getPlayerURL(player)}/snapshots`, options);
402
+ return this.getRequest(`${getPlayerURL(player)}/snapshots`, options);
408
403
  }
409
404
  /**
410
405
  * Fetches all of the player's approved name changes.
411
406
  * @returns A list of name changes.
412
407
  */
413
408
  getPlayerNames(player) {
414
- return sendGetRequest(`${getPlayerURL(player)}/names`);
409
+ return this.getRequest(`${getPlayerURL(player)}/names`);
415
410
  }
416
411
  }
417
412
  function getPlayerURL(player) {
@@ -424,13 +419,13 @@ function getPlayerURL(player) {
424
419
  return `/players/${player.username}`;
425
420
  }
426
421
 
427
- class RecordsClient {
422
+ class RecordsClient extends BaseAPIClient {
428
423
  /**
429
424
  * Fetches the current records leaderboard for a specific metric, period, playerType, playerBuild and country.
430
425
  * @returns A list of records, with their respective players, dates and values included.
431
426
  */
432
427
  getRecordLeaderboard(filter) {
433
- return sendGetRequest('/records/leaderboard', filter);
428
+ return this.getRequest('/records/leaderboard', filter);
434
429
  }
435
430
  }
436
431
 
@@ -2324,68 +2319,71 @@ exports.SnapshotDataSource = void 0;
2324
2319
  SnapshotDataSource[SnapshotDataSource["CRYSTAL_MATH_LABS"] = 1] = "CRYSTAL_MATH_LABS";
2325
2320
  })(exports.SnapshotDataSource || (exports.SnapshotDataSource = {}));
2326
2321
 
2327
- class EfficiencyClient {
2322
+ class EfficiencyClient extends BaseAPIClient {
2328
2323
  /**
2329
2324
  * Fetches the current efficiency leaderboard for a specific efficiency metric, playerType, playerBuild and country.
2330
2325
  * @returns A list of players.
2331
2326
  */
2332
2327
  getEfficiencyLeaderboards(filter, pagination) {
2333
- return sendGetRequest('/efficiency/leaderboard', Object.assign(Object.assign({}, filter), pagination));
2328
+ return this.getRequest('/efficiency/leaderboard', Object.assign(Object.assign({}, filter), pagination));
2334
2329
  }
2335
2330
  /**
2336
2331
  * Fetches the top EHP (Efficient Hours Played) rates.
2337
2332
  * @returns A list of skilling methods and their bonus exp ratios.
2338
2333
  */
2339
2334
  getEHPRates(algorithmType) {
2340
- return sendGetRequest('/efficiency/rates', { metric: Metric.EHP, type: algorithmType });
2335
+ return this.getRequest('/efficiency/rates', { metric: Metric.EHP, type: algorithmType });
2341
2336
  }
2342
2337
  /**
2343
2338
  * Fetches the top EHB (Efficient Hours Bossed) rates.
2344
2339
  * @returns A list of bosses and their respective "per-hour" kill rates.
2345
2340
  */
2346
2341
  getEHBRates(algorithmType) {
2347
- return sendGetRequest('/efficiency/rates', { metric: Metric.EHB, type: algorithmType });
2342
+ return this.getRequest('/efficiency/rates', {
2343
+ metric: Metric.EHB,
2344
+ type: algorithmType
2345
+ });
2348
2346
  }
2349
2347
  }
2350
2348
 
2351
- class NameChangesClient {
2349
+ class NameChangesClient extends BaseAPIClient {
2352
2350
  /**
2353
2351
  * Searches for name changes that match a name and/or status filter.
2354
2352
  * @returns A list of name changes.
2355
2353
  */
2356
2354
  searchNameChanges(filter, pagination) {
2357
- return sendGetRequest('/names', Object.assign(Object.assign({}, filter), pagination));
2355
+ return this.getRequest('/names', Object.assign(Object.assign({}, filter), pagination));
2358
2356
  }
2359
2357
  /**
2360
2358
  * Submits a name change request between two usernames (old and new).
2361
2359
  * @returns A pending name change request, to be reviewed and resolved at a later date.
2362
2360
  */
2363
2361
  submitNameChange(oldName, newName) {
2364
- return sendPostRequest('/names', { oldName, newName });
2362
+ return this.postRequest('/names', { oldName, newName });
2365
2363
  }
2366
2364
  /**
2367
2365
  * Gets details on a specific name change request.
2368
2366
  * @returns The name change request's details, which includes all data required to review.
2369
2367
  */
2370
2368
  getNameChangeDetails(id) {
2371
- return sendGetRequest(`/names/${id}`);
2369
+ return this.getRequest(`/names/${id}`);
2372
2370
  }
2373
2371
  }
2374
2372
 
2375
- class CompetitionsClient {
2373
+ class CompetitionsClient extends BaseAPIClient {
2376
2374
  /**
2377
2375
  * Searches for competitions that match a title, type, metric and status filter.
2378
2376
  * @returns A list of competitions.
2379
2377
  */
2380
2378
  searchCompetitions(filter, pagination) {
2381
- return sendGetRequest('/competitions', Object.assign(Object.assign({}, filter), pagination));
2379
+ return this.getRequest('/competitions', Object.assign(Object.assign({}, filter), pagination));
2382
2380
  }
2383
2381
  /**
2384
2382
  * Fetches the competition's full details, including all the participants and their progress.
2385
2383
  * @returns A competition with a list of participants.
2386
2384
  */
2387
2385
  getCompetitionDetails(id, previewMetric) {
2388
- return sendGetRequest(`/competitions/${id}`, { metric: previewMetric });
2386
+ return this.getRequest(`/competitions/${id}`, { metric: previewMetric });
2389
2387
  }
2390
2388
  /**
2391
2389
  * Fetches all the values (exp, kc, etc) in chronological order within the bounds
@@ -2393,7 +2391,7 @@ class CompetitionsClient {
2393
2391
  * @returns A list of competition progress objects, including the player and their value history over time.
2394
2392
  */
2395
2393
  getCompetitionTopHistory(id, previewMetric) {
2396
- return sendGetRequest(`/competitions/${id}/top-history`, {
2394
+ return this.getRequest(`/competitions/${id}/top-history`, {
2397
2395
  metric: previewMetric
2398
2396
  });
2399
2397
  }
@@ -2402,28 +2400,28 @@ class CompetitionsClient {
2402
2400
  * @returns The newly created competition, and the verification code that authorizes future changes to it.
2403
2401
  */
2404
2402
  createCompetition(payload) {
2405
- return sendPostRequest('/competitions', payload);
2403
+ return this.postRequest('/competitions', payload);
2406
2404
  }
2407
2405
  /**
2408
2406
  * Edits an existing competition.
2409
2407
  * @returns The updated competition.
2410
2408
  */
2411
2409
  editCompetition(id, payload, verificationCode) {
2412
- return sendPutRequest(`/competitions/${id}`, Object.assign(Object.assign({}, payload), { verificationCode }));
2410
+ return this.putRequest(`/competitions/${id}`, Object.assign(Object.assign({}, payload), { verificationCode }));
2413
2411
  }
2414
2412
  /**
2415
2413
  * Deletes an existing competition.
2416
2414
  * @returns A confirmation message.
2417
2415
  */
2418
2416
  deleteCompetition(id, verificationCode) {
2419
- return sendDeleteRequest(`/competitions/${id}`, { verificationCode });
2417
+ return this.deleteRequest(`/competitions/${id}`, { verificationCode });
2420
2418
  }
2421
2419
  /**
2422
2420
  * Adds all (valid) given participants to a competition, ignoring duplicates.
2423
2421
  * @returns The number of participants added and a confirmation message.
2424
2422
  */
2425
2423
  addParticipants(id, participants, verificationCode) {
2426
- return sendPostRequest(`/competitions/${id}/participants`, {
2424
+ return this.postRequest(`/competitions/${id}/participants`, {
2427
2425
  verificationCode,
2428
2426
  participants
2429
2427
  });
@@ -2433,7 +2431,7 @@ class CompetitionsClient {
2433
2431
  * @returns The number of participants removed and a confirmation message.
2434
2432
  */
2435
2433
  removeParticipants(id, participants, verificationCode) {
2436
- return sendDeleteRequest(`/competitions/${id}/participants`, {
2434
+ return this.deleteRequest(`/competitions/${id}/participants`, {
2437
2435
  verificationCode,
2438
2436
  participants
2439
2437
  });
@@ -2443,7 +2441,7 @@ class CompetitionsClient {
2443
2441
  * @returns The number of participants added and a confirmation message.
2444
2442
  */
2445
2443
  addTeams(id, teams, verificationCode) {
2446
- return sendPostRequest(`/competitions/${id}/teams`, {
2444
+ return this.postRequest(`/competitions/${id}/teams`, {
2447
2445
  verificationCode,
2448
2446
  teams
2449
2447
  });
@@ -2453,7 +2451,7 @@ class CompetitionsClient {
2453
2451
  * @returns The number of participants removed and a confirmation message.
2454
2452
  */
2455
2453
  removeTeams(id, teamNames, verificationCode) {
2456
- return sendDeleteRequest(`/competitions/${id}/teams`, {
2454
+ return this.deleteRequest(`/competitions/${id}/teams`, {
2457
2455
  verificationCode,
2458
2456
  teamNames
2459
2457
  });
@@ -2463,21 +2461,28 @@ class CompetitionsClient {
2463
2461
  * @returns The number of players to be updated and a confirmation message.
2464
2462
  */
2465
2463
  updateAll(id, verificationCode) {
2466
- return sendPostRequest(`/competitions/${id}/update-all`, {
2464
+ return this.postRequest(`/competitions/${id}/update-all`, {
2467
2465
  verificationCode
2468
2466
  });
2469
2467
  }
2470
2468
  }
2471
2469
 
2472
2470
  class WOMClient {
2473
- constructor() {
2474
- this.deltas = new DeltasClient();
2475
- this.groups = new GroupsClient();
2476
- this.players = new PlayersClient();
2477
- this.records = new RecordsClient();
2478
- this.efficiency = new EfficiencyClient();
2479
- this.nameChanges = new NameChangesClient();
2480
- 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);
2481
2486
  }
2482
2487
  }
2483
2488
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise-old-man/utils",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",