steamutils 1.0.21 → 1.0.23

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/SteamClient.js +55 -10
  2. package/package.json +1 -1
package/SteamClient.js CHANGED
@@ -587,19 +587,64 @@ function SteamClient({
587
587
  })
588
588
  }
589
589
 
590
+ async function getNewCookie(cookie){
591
+ let response = (await axios.request({
592
+ url: 'https://store.steampowered.com/', headers: {
593
+ cookie,
594
+ 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",
595
+ }
596
+ }))
597
+ while (Array.isArray(response.headers?.["set-cookie"])) {
598
+ const cookieObj = cookie.split(';').reduce(function (accumulator, currentValue) {
599
+ accumulator[currentValue.trim().split('=')[0].trim()] = currentValue.trim().split('=')[1].trim()
600
+ return accumulator
601
+ }, {})
602
+ for (const mcookie of response.headers["set-cookie"]) {
603
+ const name = mcookie.split('=')[0].trim()
604
+ const value = mcookie.split('=')[1].split(";")[0].trim()
605
+ cookieObj[name] = value
606
+ }
607
+ cookie = Object.keys(cookieObj).map(name => `${name}=${cookieObj[name]}`).join(';')
608
+ response = (await axios.request({
609
+ url: 'https://store.steampowered.com/', headers: {
610
+ cookie,
611
+ 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",
612
+ }
613
+ }))
614
+ }
615
+ return cookie
616
+ }
617
+
618
+
619
+ async function loginWithCookie(cookie, tryNewCookie = false) {
620
+ const response = (await axios.request({
621
+ url: 'https://steamcommunity.com/chat/clientjstoken', headers: {
622
+ cookie,
623
+ }
624
+ }))
625
+ const result = response?.data
626
+ if (result?.logged_in) {
627
+ Object.assign(result, {
628
+ steamID: new SteamID(result.steamid), accountName: result.account_name, webLogonToken: result.token
629
+ })
630
+ steamClient.logOn(result)
631
+ return cookie
632
+ } else {
633
+ if (tryNewCookie) {
634
+ console.log('You are not logged in', cookie)
635
+ return null
636
+ } else {
637
+ return await loginWithCookie(await getNewCookie(cookie), true)
638
+ }
639
+ }
640
+ }
641
+
590
642
  async function login() {
591
643
  if (cookie) {
592
644
  console.log('login with cookie')
593
- const result = (await axios.request({
594
- url: 'https://steamcommunity.com/chat/clientjstoken', headers: {
595
- cookie,
596
- }
597
- }))?.data
598
- if (result) {
599
- Object.assign(result, {
600
- steamID: new SteamID(result.steamid), accountName: result.account_name, webLogonToken: result.token
601
- })
602
- steamClient.logOn(result)
645
+ const newCookie = await loginWithCookie(cookie)
646
+ if (newCookie) {
647
+ cookie = newCookie
603
648
  }
604
649
  } else if (username && password) {
605
650
  console.log(`login with username ${username}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "dependencies": {
5
5
  "axios": "^1.3.4",
6
6
  "cheerio": "^1.0.0-rc.12",