steamutils 1.4.23 → 1.4.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/index.js +122 -64
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4911,55 +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?.data || typeof result.data !== "string" || result instanceof ResponseError) {
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
+ };
4935
+ }
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) {
4916
4954
  return;
4917
4955
  }
4918
4956
 
4919
- let href = null;
4920
- const $ = cheerio.load(result.data);
4921
- $("a").each(function (index, el) {
4922
- if (!href) {
4923
- const link = $(el).attr("href");
4924
- if (link?.startsWith("https://help.steampowered.com/en/wizard/HelpWithLoginInfoEnterCode?s=")) {
4925
- href = link;
4926
- }
4927
- }
4928
- });
4929
- let s = null;
4930
- try {
4931
- s = URL.parse(href)
4932
- .query.split("&")
4933
- .map((q) => q.split("="))
4934
- .find((q) => q[0] === "s")[1];
4935
- } catch (e) {}
4936
- if (!s)
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) {
4937
4980
  return {
4938
4981
  success: false,
4939
4982
  };
4983
+ }
4940
4984
 
4941
- const sendAccountRecoveryCodeResult = await this._httpRequest({
4942
- url: `https://help.steampowered.com/en/wizard/AjaxSendAccountRecoveryCode`,
4943
- headers: {
4944
- 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",
4945
- "Content-Type": "application/x-www-form-urlencoded",
4946
- },
4947
- data: {
4948
- wizard_ajax: "1",
4949
- gamepad: "0",
4950
- s,
4951
- method: 4,
4952
- link: "",
4953
- },
4954
- method: "POST",
4955
- });
4956
- if (sendAccountRecoveryCodeResult instanceof ResponseError) {
4957
- 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
+ };
4958
5007
  }
4959
5008
 
4960
5009
  return {
4961
- success: !!sendAccountRecoveryCodeResult.data?.success,
4962
- s,
5010
+ success: true,
5011
+ params,
4963
5012
  };
4964
5013
  }
4965
5014
 
@@ -7280,6 +7329,39 @@ export default class SteamUser {
7280
7329
  } catch (e) {}
7281
7330
  }
7282
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
+
7283
7365
  async enumerateTokens(accessToken) {
7284
7366
  if (!accessToken || typeof accessToken !== "string") {
7285
7367
  console.error("revokeAccessToken", "invalid accessToken", accessToken);
@@ -7466,31 +7548,7 @@ export default class SteamUser {
7466
7548
  if (!html.includes("For security, verify that the code in the box below matches the code we display on the confirmations page.")) {
7467
7549
  return;
7468
7550
  }
7469
- const $ = cheerio.load(html);
7470
- const forgot_login_code_form = $("#forgot_login_code_form");
7471
- const s = forgot_login_code_form.find('input[name="s"]').val();
7472
- const reset = forgot_login_code_form.find('input[name="reset"]').val();
7473
- const lost = forgot_login_code_form.find('input[name="lost"]').val();
7474
- const method = forgot_login_code_form.find('input[name="method"]').val();
7475
- const issueid = forgot_login_code_form.find('input[name="issueid"]').val();
7476
-
7477
- const cleanHtml = html.replaceAll(/\s+/gi, " ");
7478
- //do not remove this line
7479
- const g_sessionID = cleanHtml.substringAfter("g_sessionID =").trim().substringBefore(";").replaceAll('"', "").trim();
7480
- const g_rgDefaultWizardPageParamsStr = cleanHtml.substringAfter("g_rgDefaultWizardPageParams =").trim().substringBefore(";").trim();
7481
- const g_rgDefaultWizardPageParams = eval(`() => {return ${g_rgDefaultWizardPageParamsStr};}`)();
7482
- delete g_rgDefaultWizardPageParams.sessionid;
7483
-
7484
- return {
7485
- issue: {
7486
- s,
7487
- reset,
7488
- lost,
7489
- method,
7490
- issueid,
7491
- },
7492
- g_rgDefaultWizardPageParams,
7493
- };
7551
+ return SteamUser.parseWizardPageParams(html);
7494
7552
  };
7495
7553
  const sendAccountRecoveryCode = async (issue, g_rgDefaultWizardPageParams, helpLink) => {
7496
7554
  const result = await this._httpRequest({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.4.23",
3
+ "version": "1.4.24",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",