@wise-old-man/utils 3.1.8 → 3.1.10

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/dist/index.d.ts CHANGED
@@ -1394,11 +1394,11 @@ interface ParticipationWithPlayer extends CleanParticipation {
1394
1394
  }
1395
1395
  interface ParticipationWithPlayerAndProgress extends ParticipationWithPlayer {
1396
1396
  progress: MeasuredDeltaProgress;
1397
- levels?: MeasuredDeltaProgress;
1397
+ levels: MeasuredDeltaProgress;
1398
1398
  }
1399
1399
  interface ParticipationWithCompetitionAndStandings extends ParticipationWithCompetition {
1400
1400
  progress: MeasuredDeltaProgress;
1401
- levels?: MeasuredDeltaProgress;
1401
+ levels: MeasuredDeltaProgress;
1402
1402
  rank: number;
1403
1403
  }
1404
1404
  interface Team {
@@ -1547,6 +1547,11 @@ declare enum CompetitionStatus {
1547
1547
  ONGOING = "ongoing",
1548
1548
  FINISHED = "finished"
1549
1549
  }
1550
+ declare enum CompetitionCSVTableType {
1551
+ TEAM = "team",
1552
+ TEAMS = "teams",
1553
+ PARTICIPANTS = "participants"
1554
+ }
1550
1555
  declare const CompetitionTypeProps: MapOf<CompetitionType, {
1551
1556
  name: string;
1552
1557
  }>;
@@ -1734,6 +1739,7 @@ declare const REAL_SKILLS: Skill[];
1734
1739
  declare const F2P_BOSSES: Boss[];
1735
1740
  declare const MEMBER_SKILLS: Skill[];
1736
1741
  declare const COMBAT_SKILLS: Skill[];
1742
+ declare const REAL_METRICS: (Skill | Activity | Boss)[];
1737
1743
  declare function findMetric(metricName: string): Metric | null;
1738
1744
  declare function isMetric(metric: Metric | string): metric is Metric;
1739
1745
  declare function isSkill(metric: Metric | string): metric is Skill;
@@ -1842,6 +1848,11 @@ interface CompetitionsSearchFilter {
1842
1848
  type?: CompetitionType;
1843
1849
  status?: CompetitionStatus;
1844
1850
  }
1851
+ declare type CompetitionDetailsCSVParams = {
1852
+ previewMetric?: Metric;
1853
+ teamName?: string;
1854
+ table?: CompetitionCSVTableType;
1855
+ };
1845
1856
  declare type CreateCompetitionPayload = {
1846
1857
  title: string;
1847
1858
  metric: Metric;
@@ -1922,11 +1933,14 @@ declare class BaseAPIClient {
1922
1933
  private baseUrl;
1923
1934
  constructor(headers: object, baseUrl: string);
1924
1935
  private buildParams;
1936
+ private fetch;
1925
1937
  private request;
1938
+ private requestText;
1926
1939
  postRequest<T>(path: string, body?: unknown): Promise<T>;
1927
1940
  putRequest<T>(path: string, body?: unknown): Promise<T>;
1928
1941
  deleteRequest<T>(path: string, body?: unknown): Promise<T>;
1929
1942
  getRequest<T>(path: string, params?: unknown): Promise<T>;
1943
+ getText(path: string, params?: unknown): Promise<string>;
1930
1944
  }
1931
1945
 
1932
1946
  declare class DeltasClient extends BaseAPIClient {
@@ -2024,6 +2038,11 @@ declare class GroupsClient extends BaseAPIClient {
2024
2038
  * @returns A list of a group's (join, leave and role changed) activity.
2025
2039
  */
2026
2040
  getGroupActivity(id: number, pagination?: PaginationOptions): Promise<MemberActivityWithPlayer[]>;
2041
+ /**
2042
+ * Fetches the groups's member list in CSV format.
2043
+ * @returns A string containing the CSV content.
2044
+ */
2045
+ getMembersCSV(id: number): Promise<string>;
2027
2046
  }
2028
2047
 
2029
2048
  declare class PlayersClient extends BaseAPIClient {
@@ -2163,6 +2182,11 @@ declare class CompetitionsClient extends BaseAPIClient {
2163
2182
  * @returns A competition with a list of participants.
2164
2183
  */
2165
2184
  getCompetitionDetails(id: number, previewMetric?: Metric): Promise<CompetitionDetails>;
2185
+ /**
2186
+ * Fetches the competition's participant list in CSV format.
2187
+ * @returns A string containing the CSV content.
2188
+ */
2189
+ getCompetitionDetailsCSV(id: number, params?: CompetitionDetailsCSVParams): Promise<string>;
2166
2190
  /**
2167
2191
  * Fetches all the values (exp, kc, etc) in chronological order within the bounds
2168
2192
  * of the competition, for the top 5 participants.
@@ -2227,4 +2251,4 @@ declare class WOMClient extends BaseAPIClient {
2227
2251
  constructor(options?: WOMClientOptions);
2228
2252
  }
2229
2253
 
2230
- export { ACTIVITIES, Achievement, AchievementDefinition, AchievementProgress, AchievementTemplate, Activity, ActivityDelta, ActivityType, ActivityValue, ActivityValueWithPlayer, AssertPlayerTypeResponse, BOSSES, Bonus, BonusType, Boss, BossDelta, BossMetaConfig, BossValue, BossValueWithPlayer, 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, ComputedMetricValueWithPlayer, Country, CountryDetails, CountryProps, CreateCompetitionPayload, CreateCompetitionResponse, CreateGroupPayload, CreateGroupResponse, DeltaGroupLeaderboardEntry, DeltaLeaderboardEntry, DeltaLeaderboardFilter, DenyContext, EditCompetitionPayload, EditGroupPayload, EfficiencyAlgorithm, EfficiencyAlgorithmType, EfficiencyAlgorithmTypeUnion, EfficiencyLeaderboardsFilter, EfficiencyMap, ExperienceMap, ExtendedAchievement, ExtendedAchievementWithPlayer, F2P_BOSSES, FlaggedPlayerReviewContext, 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, MapOf, MeasuredDeltaProgress, MemberActivityWithPlayer, MemberInput, MemberJoinedEvent, MemberLeftEvent, MemberRoleChangeEvent, MembershipWithGroup, MembershipWithPlayer, Metric, MetricLeaders, MetricMeasure, MetricProps, MetricType, MetricValueKey, MigrationDataSource, NameChange, NameChangeDetails, NameChangeStatus, NameChangeWithPlayer, NameChangesSearchFilter, PERIODS, PLAYER_BUILDS, PLAYER_STATUSES, PLAYER_TYPES, PRIVELEGED_GROUP_ROLES, ParticipationWithCompetition, ParticipationWithCompetitionAndStandings, ParticipationWithPlayer, ParticipationWithPlayerAndProgress, Period, PeriodProps, Player, PlayerBuild, PlayerBuildProps, PlayerCompetitionStandingsFilter, PlayerCompetitionsFilter, PlayerDeltasArray, PlayerDeltasMap, PlayerDetails, PlayerRecordsFilter, PlayerStatus, PlayerStatusProps, PlayerType, PlayerTypeProps, REAL_SKILLS, Record, RecordLeaderboardEntry, RecordLeaderboardFilter, SKILLS, SKILL_EXP_AT_99, Skill, SkillDelta, SkillMetaConfig, SkillMetaMethod, SkillValue, SkillValueWithPlayer, SkipContext, Snapshot, SnapshotDataSource, SnapshotFragment, Team, TempleGroupData, TimeRangeFilter, Top5ProgressResult, WOMClient, findCountry, findCountryByCode, findCountryByName, findGroupRole, findMetric, findPeriod, findPlayerBuild, findPlayerType, formatNumber, getCombatLevel, getExpForLevel, getLevel, getMetricMeasure, getMetricName, getMetricRankKey, getMetricValueKey, getMinimumValue, getParentEfficiencyMetric, isActivity, isBoss, isCompetitionStatus, isCompetitionType, isComputedMetric, isCountry, isGroupRole, isMetric, isPeriod, isPlayerBuild, isPlayerStatus, isPlayerType, isSkill, padNumber, parseMetricAbbreviation, parsePeriodExpression, round };
2254
+ export { ACTIVITIES, Achievement, AchievementDefinition, AchievementProgress, AchievementTemplate, Activity, ActivityDelta, ActivityType, ActivityValue, ActivityValueWithPlayer, AssertPlayerTypeResponse, BOSSES, Bonus, BonusType, Boss, BossDelta, BossMetaConfig, BossValue, BossValueWithPlayer, CAPPED_MAX_TOTAL_XP, CMLGroupData, COMBAT_SKILLS, COMPETITION_STATUSES, COMPETITION_TYPES, COMPUTED_METRICS, COUNTRY_CODES, ChangeMemberRolePayload, CompetitionCSVTableType, CompetitionDetails, CompetitionDetailsCSVParams, CompetitionListItem, CompetitionStatus, CompetitionStatusProps, CompetitionType, CompetitionTypeProps, CompetitionWithParticipations, CompetitionsSearchFilter, ComputedMetric, ComputedMetricDelta, ComputedMetricValue, ComputedMetricValueWithPlayer, Country, CountryDetails, CountryProps, CreateCompetitionPayload, CreateCompetitionResponse, CreateGroupPayload, CreateGroupResponse, DeltaGroupLeaderboardEntry, DeltaLeaderboardEntry, DeltaLeaderboardFilter, DenyContext, EditCompetitionPayload, EditGroupPayload, EfficiencyAlgorithm, EfficiencyAlgorithmType, EfficiencyAlgorithmTypeUnion, EfficiencyLeaderboardsFilter, EfficiencyMap, ExperienceMap, ExtendedAchievement, ExtendedAchievementWithPlayer, F2P_BOSSES, FlaggedPlayerReviewContext, 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, MapOf, MeasuredDeltaProgress, MemberActivityWithPlayer, MemberInput, MemberJoinedEvent, MemberLeftEvent, MemberRoleChangeEvent, MembershipWithGroup, MembershipWithPlayer, Metric, MetricLeaders, MetricMeasure, MetricProps, MetricType, MetricValueKey, MigrationDataSource, NameChange, NameChangeDetails, NameChangeStatus, NameChangeWithPlayer, NameChangesSearchFilter, PERIODS, PLAYER_BUILDS, PLAYER_STATUSES, PLAYER_TYPES, PRIVELEGED_GROUP_ROLES, ParticipationWithCompetition, ParticipationWithCompetitionAndStandings, ParticipationWithPlayer, ParticipationWithPlayerAndProgress, Period, PeriodProps, Player, PlayerBuild, PlayerBuildProps, PlayerCompetitionStandingsFilter, PlayerCompetitionsFilter, PlayerDeltasArray, PlayerDeltasMap, PlayerDetails, PlayerRecordsFilter, PlayerStatus, PlayerStatusProps, PlayerType, PlayerTypeProps, REAL_METRICS, REAL_SKILLS, Record, RecordLeaderboardEntry, RecordLeaderboardFilter, SKILLS, SKILL_EXP_AT_99, Skill, SkillDelta, SkillMetaConfig, SkillMetaMethod, SkillValue, SkillValueWithPlayer, SkipContext, Snapshot, SnapshotDataSource, SnapshotFragment, Team, TempleGroupData, TimeRangeFilter, Top5ProgressResult, WOMClient, findCountry, findCountryByCode, findCountryByName, findGroupRole, findMetric, findPeriod, findPlayerBuild, findPlayerType, formatNumber, getCombatLevel, getExpForLevel, getLevel, getMetricMeasure, getMetricName, getMetricRankKey, getMetricValueKey, getMinimumValue, getParentEfficiencyMetric, isActivity, isBoss, isCompetitionStatus, isCompetitionType, isComputedMetric, isCountry, isGroupRole, isMetric, isPeriod, isPlayerBuild, isPlayerStatus, isPlayerType, isSkill, padNumber, parseMetricAbbreviation, parsePeriodExpression, round };
package/dist/index.js CHANGED
@@ -147,7 +147,7 @@ class BaseAPIClient {
147
147
  const query = builder.toString();
148
148
  return query ? `?${query}` : '';
149
149
  }
150
- request({ method, path, body, params }) {
150
+ fetch({ method, path, body, params }) {
151
151
  return __awaiter(this, void 0, void 0, function* () {
152
152
  const req = { method, body: undefined, headers: this.headers };
153
153
  let query = '';
@@ -157,7 +157,12 @@ class BaseAPIClient {
157
157
  if (params) {
158
158
  query = this.buildParams(params);
159
159
  }
160
- const res = yield fetch(this.baseUrl + path + query, req);
160
+ return yield fetch(this.baseUrl + path + query, req);
161
+ });
162
+ }
163
+ request({ method, path, body, params }) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const res = yield this.fetch({ method, path, body, params });
161
166
  const data = yield res.json();
162
167
  if (res.ok) {
163
168
  return transformDates(data);
@@ -165,6 +170,16 @@ class BaseAPIClient {
165
170
  handleError(res.status, path, data);
166
171
  });
167
172
  }
173
+ requestText({ method, path, body, params }) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ const res = yield this.fetch({ method, path, body, params });
176
+ const text = yield res.text();
177
+ if (res.ok) {
178
+ return text;
179
+ }
180
+ handleError(res.status, path, JSON.parse(text));
181
+ });
182
+ }
168
183
  postRequest(path, body) {
169
184
  return __awaiter(this, void 0, void 0, function* () {
170
185
  return yield this.request({ method: 'POST', path, body: body || {} });
@@ -185,6 +200,11 @@ class BaseAPIClient {
185
200
  return yield this.request({ method: 'GET', path, params });
186
201
  });
187
202
  }
203
+ getText(path, params) {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ return yield this.requestText({ method: 'GET', path, params });
206
+ });
207
+ }
188
208
  }
189
209
 
190
210
  class DeltasClient extends BaseAPIClient {
@@ -321,6 +341,13 @@ class GroupsClient extends BaseAPIClient {
321
341
  getGroupActivity(id, pagination) {
322
342
  return this.getRequest(`/groups/${id}/activity`, Object.assign({}, pagination));
323
343
  }
344
+ /**
345
+ * Fetches the groups's member list in CSV format.
346
+ * @returns A string containing the CSV content.
347
+ */
348
+ getMembersCSV(id) {
349
+ return this.getText(`/groups/${id}/csv`);
350
+ }
324
351
  }
325
352
 
326
353
  class PlayersClient extends BaseAPIClient {
@@ -1169,6 +1196,12 @@ exports.CompetitionStatus = void 0;
1169
1196
  CompetitionStatus["ONGOING"] = "ongoing";
1170
1197
  CompetitionStatus["FINISHED"] = "finished";
1171
1198
  })(exports.CompetitionStatus || (exports.CompetitionStatus = {}));
1199
+ exports.CompetitionCSVTableType = void 0;
1200
+ (function (CompetitionCSVTableType) {
1201
+ CompetitionCSVTableType["TEAM"] = "team";
1202
+ CompetitionCSVTableType["TEAMS"] = "teams";
1203
+ CompetitionCSVTableType["PARTICIPANTS"] = "participants";
1204
+ })(exports.CompetitionCSVTableType || (exports.CompetitionCSVTableType = {}));
1172
1205
  const CompetitionTypeProps = {
1173
1206
  [CompetitionType.CLASSIC]: { name: 'Classic' },
1174
1207
  [CompetitionType.TEAM]: { name: 'Team' }
@@ -1530,10 +1563,10 @@ function mapValues(obj, callback) {
1530
1563
  const GROUP_ROLES = Object.values(GroupRole);
1531
1564
  const PRIVELEGED_GROUP_ROLES = [
1532
1565
  GroupRole.ADMINISTRATOR,
1533
- GroupRole.DEPUTY_OWNER,
1566
+ GroupRole.OWNER,
1534
1567
  GroupRole.LEADER,
1535
- GroupRole.MODERATOR,
1536
- GroupRole.OWNER
1568
+ GroupRole.DEPUTY_OWNER,
1569
+ GroupRole.MODERATOR
1537
1570
  ];
1538
1571
  const GroupRoleProps = mapValues({
1539
1572
  [GroupRole.ACHIEVER]: { name: 'Achiever' },
@@ -1919,7 +1952,7 @@ const BossProps = mapValues({
1919
1952
  [Boss.ZULRAH]: { name: 'Zulrah' }
1920
1953
  }, props => (Object.assign(Object.assign({}, props), { type: exports.MetricType.BOSS, measure: exports.MetricMeasure.KILLS, isMembers: 'isMembers' in props ? props.isMembers : true, minimumValue: 'minimumValue' in props ? props.minimumValue : 5 })));
1921
1954
  const ActivityProps = mapValues({
1922
- [Activity.LEAGUE_POINTS]: { name: 'League Points' },
1955
+ [Activity.LEAGUE_POINTS]: { name: 'League Points', minimumValue: 100 },
1923
1956
  [Activity.BOUNTY_HUNTER_HUNTER]: { name: 'Bounty Hunter (Hunter)', minimumValue: 2 },
1924
1957
  [Activity.BOUNTY_HUNTER_ROGUE]: { name: 'Bounty Hunter (Rogue)', minimumValue: 2 },
1925
1958
  [Activity.CLUE_SCROLLS_ALL]: { name: 'Clue Scrolls (All)' },
@@ -1948,6 +1981,7 @@ const REAL_SKILLS = SKILLS.filter(s => s !== Skill.OVERALL);
1948
1981
  const F2P_BOSSES = BOSSES.filter(b => !MetricProps[b].isMembers);
1949
1982
  const MEMBER_SKILLS = SKILLS.filter(s => MetricProps[s].isMembers);
1950
1983
  const COMBAT_SKILLS = SKILLS.filter(s => MetricProps[s].isCombat);
1984
+ const REAL_METRICS = [...SKILLS, ...BOSSES, ...ACTIVITIES];
1951
1985
  function findMetric(metricName) {
1952
1986
  for (const [key, value] of Object.entries(MetricProps)) {
1953
1987
  if (value.name.toUpperCase() === metricName.toUpperCase())
@@ -2483,6 +2517,13 @@ class CompetitionsClient extends BaseAPIClient {
2483
2517
  getCompetitionDetails(id, previewMetric) {
2484
2518
  return this.getRequest(`/competitions/${id}`, { metric: previewMetric });
2485
2519
  }
2520
+ /**
2521
+ * Fetches the competition's participant list in CSV format.
2522
+ * @returns A string containing the CSV content.
2523
+ */
2524
+ getCompetitionDetailsCSV(id, params) {
2525
+ return this.getText(`/competitions/${id}/csv`, Object.assign({ metric: params.previewMetric }, params));
2526
+ }
2486
2527
  /**
2487
2528
  * Fetches all the values (exp, kc, etc) in chronological order within the bounds
2488
2529
  * of the competition, for the top 5 participants.
@@ -2627,6 +2668,7 @@ exports.PlayerStatus = PlayerStatus;
2627
2668
  exports.PlayerStatusProps = PlayerStatusProps;
2628
2669
  exports.PlayerType = PlayerType;
2629
2670
  exports.PlayerTypeProps = PlayerTypeProps;
2671
+ exports.REAL_METRICS = REAL_METRICS;
2630
2672
  exports.REAL_SKILLS = REAL_SKILLS;
2631
2673
  exports.SKILLS = SKILLS;
2632
2674
  exports.SKILL_EXP_AT_99 = SKILL_EXP_AT_99;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise-old-man/utils",
3
- "version": "3.1.8",
3
+ "version": "3.1.10",
4
4
  "description": "A JavaScript/TypeScript client that interfaces and consumes the Wise Old Man API, an API that tracks and measures players' progress in Old School Runescape.",
5
5
  "keywords": [
6
6
  "wiseoldman",