steamutils 1.4.22 → 1.4.24

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 (2) hide show
  1. package/index.js +124 -65
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4911,54 +4911,104 @@ export default class SteamUser {
4911
4911
  }
4912
4912
 
4913
4913
  async removePhoneNumber() {
4914
- const result = await this._httpRequest(`https://help.steampowered.com/en/wizard/HelpRemovePhoneNumber?redir=store/account`);
4915
- if (result instanceof ResponseError) {
4916
- return result;
4917
- }
4918
- let href = null;
4919
- const $ = result._$();
4920
- $("a").each(function (index, el) {
4921
- if (!href) {
4922
- const link = $(el).attr("href");
4923
- if (link?.startsWith("https://help.steampowered.com/en/wizard/HelpWithLoginInfoEnterCode?s=")) {
4924
- href = link;
4925
- }
4914
+ const getHelpLink = async () => {
4915
+ const response = await this._httpRequest("https://help.steampowered.com/en/wizard/HelpRemovePhoneNumber?redir=store/account");
4916
+ const html = response.data;
4917
+ const $ = cheerio.load(html);
4918
+ const buttons = $("a.help_wizard_button");
4919
+ const buttonsMapping = [...buttons].map(function (el) {
4920
+ el = $(el);
4921
+ const text = el.text().trim();
4922
+ const link = el.attr("href");
4923
+ return {
4924
+ text,
4925
+ link,
4926
+ };
4927
+ });
4928
+
4929
+ const steamAppConfirmBtn = buttonsMapping.find(({ text }) => text === "Send a confirmation to my Steam Mobile app");
4930
+ if (steamAppConfirmBtn) {
4931
+ return {
4932
+ ...steamAppConfirmBtn,
4933
+ type: "SteamAppConfirm",
4934
+ };
4926
4935
  }
4927
- });
4928
- let s = null;
4929
- try {
4930
- s = URL.parse(href)
4931
- .query.split("&")
4932
- .map((q) => q.split("="))
4933
- .find((q) => q[0] === "s")[1];
4934
- } catch (e) {}
4935
- if (!s)
4936
+
4937
+ const phoneTextingConfirmBtn = buttonsMapping.find(({ text }) => text.startsWith("Text an account verification code to my phone number ending in"));
4938
+ if (phoneTextingConfirmBtn) {
4939
+ return {
4940
+ ...phoneTextingConfirmBtn,
4941
+ type: "PhoneTextingConfirm",
4942
+ };
4943
+ }
4944
+ };
4945
+
4946
+ const isVerificationCodeSent = (html) => {
4947
+ const $ = cheerio.load(html);
4948
+ const help_page_title = $("#forgot_login_code_form .help_page_title").text().trim();
4949
+ return help_page_title.startsWith("A verification code was sent to phone number ending in");
4950
+ };
4951
+
4952
+ const { type, link: helpLink } = (await getHelpLink()) || {};
4953
+ if (!type) {
4954
+ return;
4955
+ }
4956
+
4957
+ const result = await this._httpRequest(helpLink);
4958
+ const html = result?.data;
4959
+ if (!html || typeof html !== "string" || result instanceof ResponseError) {
4960
+ return;
4961
+ }
4962
+
4963
+ const params = SteamUser.parseWizardPageParams(html);
4964
+ const paramsExample = {
4965
+ g_sessionID: "a32bcb41a7917a9f0e20a02a",
4966
+ issue: {
4967
+ s: "8531824267074740155",
4968
+ reset: "4",
4969
+ lost: "0",
4970
+ method: "4",
4971
+ issueid: "403",
4972
+ },
4973
+ g_rgDefaultWizardPageParams: {
4974
+ wizard_ajax: 1,
4975
+ gamepad: 0,
4976
+ },
4977
+ };
4978
+
4979
+ if (!params) {
4936
4980
  return {
4937
4981
  success: false,
4938
4982
  };
4983
+ }
4939
4984
 
4940
- const sendAccountRecoveryCodeResult = await this._httpRequest({
4941
- url: `https://help.steampowered.com/en/wizard/AjaxSendAccountRecoveryCode`,
4942
- headers: {
4943
- accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
4944
- "Content-Type": "application/x-www-form-urlencoded",
4945
- },
4946
- data: {
4947
- wizard_ajax: "1",
4948
- gamepad: "0",
4949
- s,
4950
- method: 4,
4951
- link: "",
4952
- },
4953
- method: "POST",
4954
- });
4955
- if (sendAccountRecoveryCodeResult instanceof ResponseError) {
4956
- return sendAccountRecoveryCodeResult;
4985
+ if (!isVerificationCodeSent(html)) {
4986
+ const sendAccountRecoveryCodeResult = await this._httpRequest({
4987
+ url: `https://help.steampowered.com/en/wizard/AjaxSendAccountRecoveryCode`,
4988
+ headers: {
4989
+ "x-requested-with": "XMLHttpRequest",
4990
+ "content-type": "application/x-www-form-urlencoded",
4991
+ },
4992
+ data: {
4993
+ ...params.g_rgDefaultWizardPageParams,
4994
+ s: params.issue.s,
4995
+ method: params.issue.method,
4996
+ link: "",
4997
+ },
4998
+ method: "POST",
4999
+ });
5000
+ if (sendAccountRecoveryCodeResult instanceof ResponseError) {
5001
+ return sendAccountRecoveryCodeResult;
5002
+ }
5003
+ return {
5004
+ success: !!sendAccountRecoveryCodeResult.data?.success,
5005
+ params,
5006
+ };
4957
5007
  }
4958
5008
 
4959
5009
  return {
4960
- success: !!sendAccountRecoveryCodeResult.data?.success,
4961
- s,
5010
+ success: true,
5011
+ params,
4962
5012
  };
4963
5013
  }
4964
5014
 
@@ -7279,6 +7329,39 @@ export default class SteamUser {
7279
7329
  } catch (e) {}
7280
7330
  }
7281
7331
 
7332
+ static parseWizardPageParams(html) {
7333
+ if (!html || typeof html !== "string") {
7334
+ return;
7335
+ }
7336
+
7337
+ const $ = cheerio.load(html);
7338
+ const forgot_login_code_form = $("#forgot_login_code_form");
7339
+ const s = forgot_login_code_form.find('input[name="s"]').val();
7340
+ const reset = forgot_login_code_form.find('input[name="reset"]').val();
7341
+ const lost = forgot_login_code_form.find('input[name="lost"]').val();
7342
+ const method = forgot_login_code_form.find('input[name="method"]').val();
7343
+ const issueid = forgot_login_code_form.find('input[name="issueid"]').val();
7344
+
7345
+ const cleanHtml = html.replaceAll(/\s+/gi, " ");
7346
+ //do not remove this line
7347
+ const g_sessionID = cleanHtml.substringBetweenOrNull('var g_sessionID = "', '";');
7348
+ const g_rgDefaultWizardPageParamsStr = cleanHtml.substringAfter("g_rgDefaultWizardPageParams =").trim().substringBefore(";").trim();
7349
+ const g_rgDefaultWizardPageParams = eval(`() => {return ${g_rgDefaultWizardPageParamsStr};}`)();
7350
+ delete g_rgDefaultWizardPageParams.sessionid;
7351
+
7352
+ return {
7353
+ g_sessionID,
7354
+ issue: {
7355
+ s,
7356
+ reset,
7357
+ lost,
7358
+ method,
7359
+ issueid,
7360
+ },
7361
+ g_rgDefaultWizardPageParams,
7362
+ };
7363
+ }
7364
+
7282
7365
  async enumerateTokens(accessToken) {
7283
7366
  if (!accessToken || typeof accessToken !== "string") {
7284
7367
  console.error("revokeAccessToken", "invalid accessToken", accessToken);
@@ -7465,31 +7548,7 @@ export default class SteamUser {
7465
7548
  if (!html.includes("For security, verify that the code in the box below matches the code we display on the confirmations page.")) {
7466
7549
  return;
7467
7550
  }
7468
- const $ = cheerio.load(html);
7469
- const forgot_login_code_form = $("#forgot_login_code_form");
7470
- const s = forgot_login_code_form.find('input[name="s"]').val();
7471
- const reset = forgot_login_code_form.find('input[name="reset"]').val();
7472
- const lost = forgot_login_code_form.find('input[name="lost"]').val();
7473
- const method = forgot_login_code_form.find('input[name="method"]').val();
7474
- const issueid = forgot_login_code_form.find('input[name="issueid"]').val();
7475
-
7476
- const cleanHtml = html.replaceAll(/\s+/gi, " ");
7477
- //do not remove this line
7478
- const g_sessionID = cleanHtml.substringAfter("g_sessionID =").trim().substringBefore(";").replaceAll('"', "").trim();
7479
- const g_rgDefaultWizardPageParamsStr = cleanHtml.substringAfter("g_rgDefaultWizardPageParams =").trim().substringBefore(";").trim();
7480
- const g_rgDefaultWizardPageParams = eval(`() => {return ${g_rgDefaultWizardPageParamsStr};}`)();
7481
- delete g_rgDefaultWizardPageParams.sessionid;
7482
-
7483
- return {
7484
- issue: {
7485
- s,
7486
- reset,
7487
- lost,
7488
- method,
7489
- issueid,
7490
- },
7491
- g_rgDefaultWizardPageParams,
7492
- };
7551
+ return SteamUser.parseWizardPageParams(html);
7493
7552
  };
7494
7553
  const sendAccountRecoveryCode = async (issue, g_rgDefaultWizardPageParams, helpLink) => {
7495
7554
  const result = await this._httpRequest({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.4.22",
3
+ "version": "1.4.24",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",