@wise-old-man/utils 3.1.9 → 3.1.11

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
@@ -19,6 +19,15 @@ export type MemberActivity = {
19
19
  createdAt: Date;
20
20
  };
21
21
 
22
+ export type PlayerArchive = {
23
+ playerId: number;
24
+ previousUsername: string;
25
+ archiveUsername: string;
26
+ restoredUsername: string | null;
27
+ createdAt: Date;
28
+ restoredAt: Date | null;
29
+ };
30
+
22
31
  type Prisma_Base_GroupSocialLinks = {
23
32
  id: number;
24
33
  groupId: number;
@@ -1533,6 +1542,9 @@ interface FlaggedPlayerReviewContext {
1533
1542
  rejectedRank: number;
1534
1543
  };
1535
1544
  }
1545
+ declare type PlayerArchiveWithPlayer = PlayerArchive & {
1546
+ player: Player;
1547
+ };
1536
1548
 
1537
1549
  declare type RecordLeaderboardEntry = Record & {
1538
1550
  player: Player;
@@ -1547,6 +1559,11 @@ declare enum CompetitionStatus {
1547
1559
  ONGOING = "ongoing",
1548
1560
  FINISHED = "finished"
1549
1561
  }
1562
+ declare enum CompetitionCSVTableType {
1563
+ TEAM = "team",
1564
+ TEAMS = "teams",
1565
+ PARTICIPANTS = "participants"
1566
+ }
1550
1567
  declare const CompetitionTypeProps: MapOf<CompetitionType, {
1551
1568
  name: string;
1552
1569
  }>;
@@ -1734,6 +1751,7 @@ declare const REAL_SKILLS: Skill[];
1734
1751
  declare const F2P_BOSSES: Boss[];
1735
1752
  declare const MEMBER_SKILLS: Skill[];
1736
1753
  declare const COMBAT_SKILLS: Skill[];
1754
+ declare const REAL_METRICS: (Skill | Activity | Boss)[];
1737
1755
  declare function findMetric(metricName: string): Metric | null;
1738
1756
  declare function isMetric(metric: Metric | string): metric is Metric;
1739
1757
  declare function isSkill(metric: Metric | string): metric is Skill;
@@ -1842,6 +1860,11 @@ interface CompetitionsSearchFilter {
1842
1860
  type?: CompetitionType;
1843
1861
  status?: CompetitionStatus;
1844
1862
  }
1863
+ declare type CompetitionDetailsCSVParams = {
1864
+ previewMetric?: Metric;
1865
+ teamName?: string;
1866
+ table?: CompetitionCSVTableType;
1867
+ };
1845
1868
  declare type CreateCompetitionPayload = {
1846
1869
  title: string;
1847
1870
  metric: Metric;
@@ -1922,11 +1945,14 @@ declare class BaseAPIClient {
1922
1945
  private baseUrl;
1923
1946
  constructor(headers: object, baseUrl: string);
1924
1947
  private buildParams;
1948
+ private fetch;
1925
1949
  private request;
1950
+ private requestText;
1926
1951
  postRequest<T>(path: string, body?: unknown): Promise<T>;
1927
1952
  putRequest<T>(path: string, body?: unknown): Promise<T>;
1928
1953
  deleteRequest<T>(path: string, body?: unknown): Promise<T>;
1929
1954
  getRequest<T>(path: string, params?: unknown): Promise<T>;
1955
+ getText(path: string, params?: unknown): Promise<string>;
1930
1956
  }
1931
1957
 
1932
1958
  declare class DeltasClient extends BaseAPIClient {
@@ -2024,6 +2050,11 @@ declare class GroupsClient extends BaseAPIClient {
2024
2050
  * @returns A list of a group's (join, leave and role changed) activity.
2025
2051
  */
2026
2052
  getGroupActivity(id: number, pagination?: PaginationOptions): Promise<MemberActivityWithPlayer[]>;
2053
+ /**
2054
+ * Fetches the groups's member list in CSV format.
2055
+ * @returns A string containing the CSV content.
2056
+ */
2057
+ getMembersCSV(id: number): Promise<string>;
2027
2058
  }
2028
2059
 
2029
2060
  declare class PlayersClient extends BaseAPIClient {
@@ -2111,6 +2142,11 @@ declare class PlayersClient extends BaseAPIClient {
2111
2142
  * @returns A list of name changes.
2112
2143
  */
2113
2144
  getPlayerNames(username: string): Promise<NameChange[]>;
2145
+ /**
2146
+ * Fetches all of archived players that previously held this username.
2147
+ * @returns A list of player archives.
2148
+ */
2149
+ getPlayerArchives(username: string): Promise<PlayerArchiveWithPlayer[]>;
2114
2150
  }
2115
2151
 
2116
2152
  declare class RecordsClient extends BaseAPIClient {
@@ -2163,6 +2199,11 @@ declare class CompetitionsClient extends BaseAPIClient {
2163
2199
  * @returns A competition with a list of participants.
2164
2200
  */
2165
2201
  getCompetitionDetails(id: number, previewMetric?: Metric): Promise<CompetitionDetails>;
2202
+ /**
2203
+ * Fetches the competition's participant list in CSV format.
2204
+ * @returns A string containing the CSV content.
2205
+ */
2206
+ getCompetitionDetailsCSV(id: number, params?: CompetitionDetailsCSVParams): Promise<string>;
2166
2207
  /**
2167
2208
  * Fetches all the values (exp, kc, etc) in chronological order within the bounds
2168
2209
  * of the competition, for the top 5 participants.
@@ -2227,4 +2268,4 @@ declare class WOMClient extends BaseAPIClient {
2227
2268
  constructor(options?: WOMClientOptions);
2228
2269
  }
2229
2270
 
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 };
2271
+ 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, PlayerArchiveWithPlayer, 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 {
@@ -436,6 +463,13 @@ class PlayersClient extends BaseAPIClient {
436
463
  getPlayerNames(username) {
437
464
  return this.getRequest(`/players/${username}/names`);
438
465
  }
466
+ /**
467
+ * Fetches all of archived players that previously held this username.
468
+ * @returns A list of player archives.
469
+ */
470
+ getPlayerArchives(username) {
471
+ return this.getRequest(`/players/${username}/archives`);
472
+ }
439
473
  }
440
474
 
441
475
  class RecordsClient extends BaseAPIClient {
@@ -1169,6 +1203,12 @@ exports.CompetitionStatus = void 0;
1169
1203
  CompetitionStatus["ONGOING"] = "ongoing";
1170
1204
  CompetitionStatus["FINISHED"] = "finished";
1171
1205
  })(exports.CompetitionStatus || (exports.CompetitionStatus = {}));
1206
+ exports.CompetitionCSVTableType = void 0;
1207
+ (function (CompetitionCSVTableType) {
1208
+ CompetitionCSVTableType["TEAM"] = "team";
1209
+ CompetitionCSVTableType["TEAMS"] = "teams";
1210
+ CompetitionCSVTableType["PARTICIPANTS"] = "participants";
1211
+ })(exports.CompetitionCSVTableType || (exports.CompetitionCSVTableType = {}));
1172
1212
  const CompetitionTypeProps = {
1173
1213
  [CompetitionType.CLASSIC]: { name: 'Classic' },
1174
1214
  [CompetitionType.TEAM]: { name: 'Team' }
@@ -1530,10 +1570,10 @@ function mapValues(obj, callback) {
1530
1570
  const GROUP_ROLES = Object.values(GroupRole);
1531
1571
  const PRIVELEGED_GROUP_ROLES = [
1532
1572
  GroupRole.ADMINISTRATOR,
1533
- GroupRole.DEPUTY_OWNER,
1573
+ GroupRole.OWNER,
1534
1574
  GroupRole.LEADER,
1535
- GroupRole.MODERATOR,
1536
- GroupRole.OWNER
1575
+ GroupRole.DEPUTY_OWNER,
1576
+ GroupRole.MODERATOR
1537
1577
  ];
1538
1578
  const GroupRoleProps = mapValues({
1539
1579
  [GroupRole.ACHIEVER]: { name: 'Achiever' },
@@ -1919,7 +1959,7 @@ const BossProps = mapValues({
1919
1959
  [Boss.ZULRAH]: { name: 'Zulrah' }
1920
1960
  }, 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
1961
  const ActivityProps = mapValues({
1922
- [Activity.LEAGUE_POINTS]: { name: 'League Points' },
1962
+ [Activity.LEAGUE_POINTS]: { name: 'League Points', minimumValue: 100 },
1923
1963
  [Activity.BOUNTY_HUNTER_HUNTER]: { name: 'Bounty Hunter (Hunter)', minimumValue: 2 },
1924
1964
  [Activity.BOUNTY_HUNTER_ROGUE]: { name: 'Bounty Hunter (Rogue)', minimumValue: 2 },
1925
1965
  [Activity.CLUE_SCROLLS_ALL]: { name: 'Clue Scrolls (All)' },
@@ -1948,6 +1988,7 @@ const REAL_SKILLS = SKILLS.filter(s => s !== Skill.OVERALL);
1948
1988
  const F2P_BOSSES = BOSSES.filter(b => !MetricProps[b].isMembers);
1949
1989
  const MEMBER_SKILLS = SKILLS.filter(s => MetricProps[s].isMembers);
1950
1990
  const COMBAT_SKILLS = SKILLS.filter(s => MetricProps[s].isCombat);
1991
+ const REAL_METRICS = [...SKILLS, ...BOSSES, ...ACTIVITIES];
1951
1992
  function findMetric(metricName) {
1952
1993
  for (const [key, value] of Object.entries(MetricProps)) {
1953
1994
  if (value.name.toUpperCase() === metricName.toUpperCase())
@@ -2483,6 +2524,13 @@ class CompetitionsClient extends BaseAPIClient {
2483
2524
  getCompetitionDetails(id, previewMetric) {
2484
2525
  return this.getRequest(`/competitions/${id}`, { metric: previewMetric });
2485
2526
  }
2527
+ /**
2528
+ * Fetches the competition's participant list in CSV format.
2529
+ * @returns A string containing the CSV content.
2530
+ */
2531
+ getCompetitionDetailsCSV(id, params) {
2532
+ return this.getText(`/competitions/${id}/csv`, Object.assign({ metric: params.previewMetric }, params));
2533
+ }
2486
2534
  /**
2487
2535
  * Fetches all the values (exp, kc, etc) in chronological order within the bounds
2488
2536
  * of the competition, for the top 5 participants.
@@ -2627,6 +2675,7 @@ exports.PlayerStatus = PlayerStatus;
2627
2675
  exports.PlayerStatusProps = PlayerStatusProps;
2628
2676
  exports.PlayerType = PlayerType;
2629
2677
  exports.PlayerTypeProps = PlayerTypeProps;
2678
+ exports.REAL_METRICS = REAL_METRICS;
2630
2679
  exports.REAL_SKILLS = REAL_SKILLS;
2631
2680
  exports.SKILLS = SKILLS;
2632
2681
  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.9",
3
+ "version": "3.1.11",
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",