steamutils 1.5.40 → 1.5.41

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/_steamproto.js +1 -1
  2. package/index.js +123 -21
  3. package/package.json +1 -1
package/_steamproto.js CHANGED
@@ -13,7 +13,7 @@ export class SteamProto {
13
13
 
14
14
  toProto() {
15
15
  const filePath = path.join(`${__dirname}/protos/`, this._proto.filename);
16
- const root = new Protobuf.Root().loadSync([gpf.getProtoPath("google/protobuf/descriptor.proto"), filePath], {
16
+ const root = new Protobuf.Root().loadSync([gpf.getProtoPath("protobuf/descriptor.proto"), filePath], {
17
17
  keepCase: true,
18
18
  });
19
19
  return root.lookupType(this._proto.name);
package/index.js CHANGED
@@ -4496,20 +4496,48 @@ export default class SteamUser {
4496
4496
  return await SteamUser.resolveUsers(steamIDs, this.getCookies());
4497
4497
  }
4498
4498
 
4499
- static async resolveUsers(steamIDs = [], cookie) {
4499
+ /**
4500
+ * @typedef {Object} SteamUserProfile
4501
+ * @property {string} steamId - The user's 64-bit SteamID.
4502
+ * @property {number} accountId - The user's numeric account ID.
4503
+ * @property {string} name - The Steam persona name.
4504
+ * @property {string} realName - The user's real name (may be empty).
4505
+ * @property {string} avatarHash - The user's avatar hash or identifier.
4506
+ * @property {string} customURL - The user's custom profile URL (may be empty).
4507
+ * @property {number} personaState - The user's online status/state.
4508
+ * @property {string} city - The user's city (may be empty).
4509
+ * @property {string} state - The user's state/region (may be empty).
4510
+ * @property {string} country - The user's country code (may be empty).
4511
+ * @property {boolean} isFriend - Whether the user is a friend.
4512
+ * @property {number} friendsInCommon - Number of mutual friends.
4513
+ */
4514
+
4515
+ /**
4516
+ * Resolves an array of Steam user IDs to their profile information using the Steam Community API.
4517
+ *
4518
+ * @param {(string|number)[]} steamIds - Array of Steam IDs (each a string or number).
4519
+ * @param {string} [cookie] - Optional session cookie for Steam authentication.
4520
+ * @returns {Promise<SteamUserProfile[]>} Promise resolving to an array of Steam user profile objects.
4521
+ *
4522
+ * @example
4523
+ * const users = await SteamUser.resolveUsers(['76561199409201417']);
4524
+ */
4525
+ static async resolveUsers(steamIds, cookie) {
4500
4526
  //steamIDs max = 200
4501
- if (typeof steamIDs === "string") {
4502
- steamIDs = [steamIDs];
4527
+
4528
+ if (!Array.isArray(steamIds) || !steamIds.every((id) => typeof id === "string" || typeof id === "number")) {
4529
+ console.error("steamIds must be an array of string or number.");
4530
+ return [];
4503
4531
  }
4504
4532
 
4505
- steamIDs = _.uniq(steamIDs);
4533
+ steamIds = _.uniq(steamIds);
4506
4534
 
4507
- if (steamIDs.length > 200) {
4508
- return _.flatten(await Promise.all(_.chunk(steamIDs, 200).map((_steamIDs) => SteamUser.resolveUsers(_steamIDs, cookie))));
4535
+ if (steamIds.length > 200) {
4536
+ return _.flatten(await Promise.all(_.chunk(steamIds, 200).map((_steamIds) => SteamUser.resolveUsers(_steamIds, cookie))));
4509
4537
  }
4510
4538
 
4511
4539
  const { data } = await request({
4512
- url: `https://steamcommunity.com/actions/ajaxresolveusers?steamids=${steamIDs.join(",")}`,
4540
+ url: `https://steamcommunity.com/actions/ajaxresolveusers?steamids=${steamIds.join(",")}`,
4513
4541
  headers: { ...(cookie && { cookie }) },
4514
4542
  });
4515
4543
 
@@ -4520,21 +4548,43 @@ export default class SteamUser {
4520
4548
  return data.map(function (player) {
4521
4549
  return {
4522
4550
  steamId: player.steamid,
4523
- accountid: player.accountid,
4551
+ accountId: player.accountid,
4524
4552
  name: player.persona_name,
4525
- realname: player.real_name,
4553
+ realName: player.real_name,
4526
4554
  avatarHash: player.avatar_url,
4527
4555
  customURL: player.profile_url,
4528
- persona_state: player.persona_state,
4556
+ personaState: player.persona_state,
4529
4557
  city: player.city,
4530
4558
  state: player.state,
4531
4559
  country: player.country,
4532
- is_friend: player.is_friend,
4533
- friends_in_common: player.friends_in_common,
4560
+ isFriend: player.is_friend,
4561
+ friendsInCommon: player.friends_in_common,
4534
4562
  };
4535
4563
  });
4536
4564
  }
4537
4565
 
4566
+ /**
4567
+ * Resolves a single Steam user ID to its profile information using the Steam Community API.
4568
+ *
4569
+ * @param {string|number} steamId - The Steam ID to resolve.
4570
+ * @param {string} [cookie] - Optional session cookie for Steam authentication.
4571
+ * @returns {Promise<SteamUserProfile|undefined>} Resolves to a user profile object, or undefined if not found or if input is invalid.
4572
+ *
4573
+ * @example
4574
+ * const user = await SteamUser.resolveUser('76561199409201417');
4575
+ * if (user) {
4576
+ * console.log(user.name);
4577
+ * }
4578
+ */
4579
+ static async resolveUser(steamId, cookie) {
4580
+ if (typeof steamId !== "string" && typeof steamId !== "number") {
4581
+ console.error("resolveUser: steamId must be a string or number. Received:", steamId);
4582
+ return;
4583
+ }
4584
+ const users = await this.resolveUsers([steamId], cookie);
4585
+ return users[0];
4586
+ }
4587
+
4538
4588
  static GetAvatarURLFromHash(hash, size) {
4539
4589
  if (!hash) {
4540
4590
  return;
@@ -4658,10 +4708,25 @@ export default class SteamUser {
4658
4708
  return list;
4659
4709
  }
4660
4710
 
4711
+ /**
4712
+ * Retrieves the current Steam Guard status for the account.
4713
+ *
4714
+ * Makes an HTTP request to the Steam two-factor management page,
4715
+ * parses the response, and determines the type of Steam Guard authentication enabled:
4716
+ * - "steam_authenticator" (mobile authenticator is enabled)
4717
+ * - "email_authenticator" (email confirmation is enabled)
4718
+ * - "none_authenticator" (no two-factor is enabled)
4719
+ *
4720
+ * If the request fails (ResponseError), returns null.
4721
+ *
4722
+ * @async
4723
+ * @returns {Promise<"steam_authenticator"|"email_authenticator"|"none_authenticator"|null>}
4724
+ * A string representing the authenticator type, or null if the request fails.
4725
+ */
4661
4726
  async getSteamGuardStatus() {
4662
4727
  const result = await this._httpRequest(`https://store.steampowered.com/twofactor/manage_action`);
4663
4728
  if (result instanceof ResponseError) {
4664
- return result;
4729
+ return nuill;
4665
4730
  }
4666
4731
  const $ = cheerio.load(result?.data || "");
4667
4732
 
@@ -4678,7 +4743,20 @@ export default class SteamUser {
4678
4743
  }
4679
4744
  }
4680
4745
 
4681
- async turningSteamGuardOff() {
4746
+ /**
4747
+ * Attempts to initiate the process of turning Steam Guard off for the account.
4748
+ *
4749
+ * Sends a POST request to Steam's two-factor management endpoint to request the
4750
+ * removal of Steam Guard. It then checks the response to verify whether the request
4751
+ * to turn Steam Guard off was successfully triggered (an email confirmation is sent).
4752
+ *
4753
+ * @async
4754
+ * @returns {Promise<boolean>}
4755
+ * Returns `true` if turning Steam Guard off requires email confirmation and the
4756
+ * corresponding message is found in the response;
4757
+ * returns `false` if an error occurs (e.g., a ResponseError is returned).
4758
+ */
4759
+ async requestSteamGuardDeactivation() {
4682
4760
  const result = await this._httpRequest({
4683
4761
  url: `https://store.steampowered.com/twofactor/manage_action`,
4684
4762
  headers: {
@@ -4692,13 +4770,25 @@ export default class SteamUser {
4692
4770
  method: "POST",
4693
4771
  });
4694
4772
  if (result instanceof ResponseError) {
4695
- return result;
4773
+ return false;
4696
4774
  }
4697
4775
  const $ = cheerio.load(result?.data || "");
4698
4776
  return $("title").text() === `Steam Guard Mobile Authenticator` && !!result?.data?.includes?.(`Turning Steam Guard off requires confirmation. We've sent you an email with a link to confirm disabling Steam Guard.`);
4699
4777
  }
4700
4778
 
4701
- async turningEmailAuthenticatorCheckOn() {
4779
+ /**
4780
+ * Activates the email-based Steam Guard authenticator for the account.
4781
+ *
4782
+ * Sends a POST request to Steam's two-factor management endpoint to enable email-based authentication.
4783
+ * Returns `true` if the response confirms that the email authenticator is enabled,
4784
+ * or `false` if the request fails or the response does not indicate successful activation.
4785
+ *
4786
+ * @async
4787
+ * @returns {Promise<boolean>}
4788
+ * Returns `true` if the email authenticator is activated successfully,
4789
+ * or `false` otherwise.
4790
+ */
4791
+ async activateEmailSteamGuard() {
4702
4792
  const result = await this._httpRequest({
4703
4793
  url: `https://store.steampowered.com/twofactor/manage_action`,
4704
4794
  headers: {
@@ -4713,19 +4803,31 @@ export default class SteamUser {
4713
4803
  method: "POST",
4714
4804
  });
4715
4805
  if (result instanceof ResponseError) {
4716
- return result;
4806
+ return false;
4717
4807
  }
4718
4808
  const $ = cheerio.load(result?.data || "");
4719
4809
  return $("title").text() === `Steam Guard Mobile Authenticator` && $("#email_authenticator_check")?.attr("checked") == "checked";
4720
4810
  }
4721
4811
 
4722
- async getPhoneManage() {
4723
- //Ends in 17
4812
+ /**
4813
+ * Retrieves the current phone number status associated with the Steam account.
4814
+ *
4815
+ * Performs an HTTP request to the Steam phone management page and parses the response to
4816
+ * determine if a phone number is bound to the account.
4817
+ * - Returns `'none'` if no phone number is linked.
4818
+ * - Returns a string describing the phone (e.g., 'Ends in 17') if one is bound.
4819
+ * - Returns `null` on request failure or unexpected page content.
4820
+ *
4821
+ * @async
4822
+ * @returns {Promise<string|null>}
4823
+ * The phone number status: `'none'`, a phone description string (like 'Ends in 17'), or `null` if the request fails.
4824
+ */
4825
+ async getPhoneNumberStatus() {
4724
4826
  const result = await this._httpRequest({
4725
4827
  url: `https://store.steampowered.com/phone/manage`,
4726
4828
  });
4727
4829
  if (result instanceof ResponseError) {
4728
- return result;
4830
+ return null;
4729
4831
  }
4730
4832
  const $ = cheerio.load(result?.data || "");
4731
4833
  const pageheader = $("h2.pageheader").text();
@@ -4733,7 +4835,7 @@ export default class SteamUser {
4733
4835
  case "Add a phone number to your account":
4734
4836
  return "none";
4735
4837
  case "Manage phone number":
4736
- return $(".phone_header_description > span").text(); //Ends in 17}
4838
+ return $(".phone_header_description > span").text(); //Example: Ends in 17
4737
4839
  }
4738
4840
  }
4739
4841
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.5.40",
3
+ "version": "1.5.41",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",