steamutils 1.3.97 → 1.3.99

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +13 -47
  2. package/package.json +1 -1
  3. package/utils.js +155 -141
package/index.js CHANGED
@@ -8,7 +8,7 @@ import URL, { fileURLToPath } from "url";
8
8
  import Url from "url-parse";
9
9
  import qs from "qs";
10
10
  import xml2js from "xml2js";
11
- import { console_log, getCleanObject, JSON_parse, JSON_stringify, removeSpaceKeys, sleep } from "./utils.js";
11
+ import { console_log, getCleanObject, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
12
12
  import { Header, request } from "./axios.js";
13
13
  import { getTableHasHeaders, querySelectorAll, table2json } from "./cheerio.js";
14
14
  import { getJSObjectFronXML } from "./xml2json.js";
@@ -5931,7 +5931,7 @@ export default class SteamUser {
5931
5931
  });
5932
5932
 
5933
5933
  if (checkLoginResult.request?.res?.responseUrl?.startsWith("https://store.steampowered.com/login/")) {
5934
- break;
5934
+ continue;
5935
5935
  }
5936
5936
  } catch (e) {
5937
5937
  error = e;
@@ -7254,44 +7254,14 @@ export default class SteamUser {
7254
7254
  });
7255
7255
  return revokeRefreshTokenResult?.data;
7256
7256
  }
7257
- async revokeAccessToken(accessToken, tokenId, sharedSecret, clientId) {
7257
+ async revokeAccessToken(accessToken, tokenId, sharedSecret) {
7258
7258
  const version = 1;
7259
- // const clientId = tokenId;
7260
- let signatureData = Buffer.alloc(2 + 8 + 8);
7259
+ const signatureData = Buffer.alloc(2 + 8 + 8);
7261
7260
  signatureData.writeUInt16LE(version, 0);
7262
- signatureData.writeBigUInt64LE(BigInt(clientId), 2);
7261
+ signatureData.writeBigUInt64LE(BigInt(tokenId), 2);
7263
7262
  signatureData.writeBigUInt64LE(BigInt(this._steamIdUser), 10);
7264
- const secretAsBuffer = (sharedSecret) => {
7265
- if (Buffer.isBuffer(sharedSecret)) {
7266
- return sharedSecret;
7267
- }
7268
-
7269
- if (sharedSecret.match(/^[0-9a-f]{40}$/i)) {
7270
- // Looks like it's hex
7271
- return Buffer.from(sharedSecret, "hex");
7272
- }
7273
-
7274
- // It must be base64
7275
- return Buffer.from(sharedSecret, "base64");
7276
- };
7277
-
7278
7263
  const signature = createHmac("sha256", secretAsBuffer(sharedSecret)).update(signatureData).digest();
7279
7264
 
7280
- /*const approver = new LoginApprover(accessToken, sharedSecret, {});
7281
- const sessionInfo = await approver._handler.sendRequest({
7282
- apiInterface: "Authentication",
7283
- apiMethod: "RevokeRefreshToken",
7284
- apiVersion: 1,
7285
- data: {
7286
- token_id: tokenId,
7287
- steamid: this._steamIdUser,
7288
- revoke_action: 1,
7289
- signature: signature.toString(),
7290
- },
7291
- accessToken: accessToken,
7292
- });
7293
- console.log("sessionInfo", sessionInfo);*/
7294
-
7295
7265
  const Protos = helpers([
7296
7266
  {
7297
7267
  name: "csgo",
@@ -7311,25 +7281,21 @@ export default class SteamUser {
7311
7281
  }).toString("base64"),
7312
7282
  };
7313
7283
 
7314
- // const params = {
7315
- // access_token: accessToken,
7316
- // token_id: tokenId,
7317
- // steamid: this._steamIdUser,
7318
- // // revoke_action: Protos.csgo.EAuthTokenRevokeAction.k_EAuthTokenRevokePermanent,
7319
- // revoke_action: 1,
7320
- // signature: signature,
7321
- // };
7322
-
7323
- const revokeRefreshTokenResult = await this._httpRequest({
7284
+ const result = await this._httpRequest({
7324
7285
  url: `https://api.steampowered.com/IAuthenticationService/RevokeRefreshToken/v1?${qs.stringify(params)}`,
7325
7286
  // responseType: "arraybuffer",
7326
7287
  method: "POST",
7327
- data: params,
7288
+ data: {
7289
+ token_id: tokenId,
7290
+ steamid: this._steamIdUser,
7291
+ revoke_action: 1,
7292
+ signature: signature,
7293
+ },
7328
7294
  headers: {
7329
7295
  "Content-Type": "multipart/form-data",
7330
7296
  },
7331
7297
  });
7332
- return revokeRefreshTokenResult?.data;
7298
+ return result?.data;
7333
7299
  }
7334
7300
  }
7335
7301
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.3.97",
3
+ "version": "1.3.99",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",
package/utils.js CHANGED
@@ -1,141 +1,155 @@
1
- const isBrowser = typeof window !== "undefined";
2
-
3
- export const sleep = (ms) => {
4
- return new Promise((resolve) => {
5
- setTimeout(resolve, ms);
6
- });
7
- };
8
-
9
- export const sleepRandom = async (startMs, endMs) => {
10
- return await sleep(Math.random() * (endMs - startMs) + startMs);
11
- };
12
-
13
- /**
14
- * const audioTrack = stream.getAudioTracks()[0]
15
- * const videoStream = UserMedia.createBlankVideoTrack()
16
- * videoStream.addTrack(audioTrack)
17
- * stream = videoStream
18
- * **/
19
- export const createBlankVideoTrack = (opts = {}) => {
20
- const { width = 1920, height = 1080 } = opts;
21
-
22
- const canvas = Object.assign(document.createElement("canvas"), {
23
- width,
24
- height,
25
- });
26
-
27
- canvas.getContext("2d").fillRect(0, 0, width, height);
28
-
29
- return canvas.captureStream();
30
- };
31
-
32
- const minDate = new Date(0),
33
- maxDate = new Date(parseInt("ffffffff", 16) * 1000);
34
-
35
- export function objectIdFromDate(date) {
36
- if (date < minDate || date > maxDate) {
37
- return `Error: date must be between ${minDate.getFullYear()} and ${maxDate.getFullYear()}`;
38
- }
39
- var pad = "00000000";
40
- var hexSeconds = Math.floor(date.getTime() / 1000).toString(16);
41
- return `${pad.substring(0, pad.length - hexSeconds.length) + hexSeconds}0000000000000000`;
42
- }
43
-
44
- export function dateFromObjectId(objectId) {
45
- return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
46
- }
47
-
48
- export function console_log(...args) {
49
- const params = [];
50
- params.push(new Date().toUTCString());
51
- const errorStack = new Error().stack;
52
- const fnName = errorStack
53
- .split("\n")
54
- .map((e) => e?.trim())
55
- .filter((e) => e.startsWith("at") && !e.startsWith("at console_log") && !e.startsWith("at processTicksAndRejections"))[0]
56
- .substr(3);
57
- params.push(fnName);
58
- console.log(
59
- params
60
- .filter(Boolean)
61
- .map((p) => `[${p.trim()}]`)
62
- .join(" "),
63
- ...args,
64
- );
65
- }
66
-
67
- export function removeSpaceKeys(object) {
68
- //mutate object
69
- if (!object || Array.isArray(object)) {
70
- return object;
71
- }
72
-
73
- Object.entries(object).forEach(([key, value]) => {
74
- const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
75
- if (newKey !== key) {
76
- delete object[key];
77
- object[newKey] = value;
78
- }
79
- });
80
- return object;
81
- }
82
-
83
- export function getCleanObject(object) {
84
- //like removeSpaceKeys but not mutate object
85
- if (!object || Array.isArray(object)) {
86
- return object;
87
- }
88
-
89
- const newObject = {};
90
- Object.entries(object).forEach(([key, value]) => {
91
- const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
92
- newObject[newKey] = value;
93
- });
94
- return newObject;
95
- }
96
-
97
- export function JSON_parse(data) {
98
- try {
99
- return JSON.parse(data);
100
- } catch (e) {
101
- return null;
102
- }
103
- }
104
-
105
- export function JSON_stringify(data) {
106
- try {
107
- return JSON.stringify(data);
108
- } catch (e) {
109
- return null;
110
- }
111
- }
112
-
113
- export async function throttle(fn, delay) {
114
- let canFire = true;
115
- let queue = [];
116
-
117
- async function pop() {
118
- if (queue.length < 1) return;
119
-
120
- const [that, args] = queue.pop();
121
- await fn.apply(that, args);
122
- canFire = false;
123
- setTimeout(async () => {
124
- canFire = true;
125
- await pop();
126
- }, delay);
127
- }
128
-
129
- async function push() {
130
- queue.push([this, arguments]);
131
- if (canFire) {
132
- await pop();
133
- }
134
- }
135
-
136
- push.cancel = () => {
137
- queue = [];
138
- };
139
-
140
- return push;
141
- }
1
+ const isBrowser = typeof window !== "undefined";
2
+
3
+ export const sleep = (ms) => {
4
+ return new Promise((resolve) => {
5
+ setTimeout(resolve, ms);
6
+ });
7
+ };
8
+
9
+ export const sleepRandom = async (startMs, endMs) => {
10
+ return await sleep(Math.random() * (endMs - startMs) + startMs);
11
+ };
12
+
13
+ /**
14
+ * const audioTrack = stream.getAudioTracks()[0]
15
+ * const videoStream = UserMedia.createBlankVideoTrack()
16
+ * videoStream.addTrack(audioTrack)
17
+ * stream = videoStream
18
+ * **/
19
+ export const createBlankVideoTrack = (opts = {}) => {
20
+ const { width = 1920, height = 1080 } = opts;
21
+
22
+ const canvas = Object.assign(document.createElement("canvas"), {
23
+ width,
24
+ height,
25
+ });
26
+
27
+ canvas.getContext("2d").fillRect(0, 0, width, height);
28
+
29
+ return canvas.captureStream();
30
+ };
31
+
32
+ const minDate = new Date(0),
33
+ maxDate = new Date(parseInt("ffffffff", 16) * 1000);
34
+
35
+ export function objectIdFromDate(date) {
36
+ if (date < minDate || date > maxDate) {
37
+ return `Error: date must be between ${minDate.getFullYear()} and ${maxDate.getFullYear()}`;
38
+ }
39
+ var pad = "00000000";
40
+ var hexSeconds = Math.floor(date.getTime() / 1000).toString(16);
41
+ return `${pad.substring(0, pad.length - hexSeconds.length) + hexSeconds}0000000000000000`;
42
+ }
43
+
44
+ export function dateFromObjectId(objectId) {
45
+ return new Date(parseInt(objectId.substring(0, 8), 16) * 1000);
46
+ }
47
+
48
+ export function console_log(...args) {
49
+ const params = [];
50
+ params.push(new Date().toUTCString());
51
+ const errorStack = new Error().stack;
52
+ const fnName = errorStack
53
+ .split("\n")
54
+ .map((e) => e?.trim())
55
+ .filter((e) => e.startsWith("at") && !e.startsWith("at console_log") && !e.startsWith("at processTicksAndRejections"))[0]
56
+ .substr(3);
57
+ params.push(fnName);
58
+ console.log(
59
+ params
60
+ .filter(Boolean)
61
+ .map((p) => `[${p.trim()}]`)
62
+ .join(" "),
63
+ ...args,
64
+ );
65
+ }
66
+
67
+ export function removeSpaceKeys(object) {
68
+ //mutate object
69
+ if (!object || Array.isArray(object)) {
70
+ return object;
71
+ }
72
+
73
+ Object.entries(object).forEach(([key, value]) => {
74
+ const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
75
+ if (newKey !== key) {
76
+ delete object[key];
77
+ object[newKey] = value;
78
+ }
79
+ });
80
+ return object;
81
+ }
82
+
83
+ export function getCleanObject(object) {
84
+ //like removeSpaceKeys but not mutate object
85
+ if (!object || Array.isArray(object)) {
86
+ return object;
87
+ }
88
+
89
+ const newObject = {};
90
+ Object.entries(object).forEach(([key, value]) => {
91
+ const newKey = key.replaceAll(/[^a-zA-Z0-9]/gi, "_");
92
+ newObject[newKey] = value;
93
+ });
94
+ return newObject;
95
+ }
96
+
97
+ export function JSON_parse(data) {
98
+ try {
99
+ return JSON.parse(data);
100
+ } catch (e) {
101
+ return null;
102
+ }
103
+ }
104
+
105
+ export function JSON_stringify(data) {
106
+ try {
107
+ return JSON.stringify(data);
108
+ } catch (e) {
109
+ return null;
110
+ }
111
+ }
112
+
113
+ export async function throttle(fn, delay) {
114
+ let canFire = true;
115
+ let queue = [];
116
+
117
+ async function pop() {
118
+ if (queue.length < 1) return;
119
+
120
+ const [that, args] = queue.pop();
121
+ await fn.apply(that, args);
122
+ canFire = false;
123
+ setTimeout(async () => {
124
+ canFire = true;
125
+ await pop();
126
+ }, delay);
127
+ }
128
+
129
+ async function push() {
130
+ queue.push([this, arguments]);
131
+ if (canFire) {
132
+ await pop();
133
+ }
134
+ }
135
+
136
+ push.cancel = () => {
137
+ queue = [];
138
+ };
139
+
140
+ return push;
141
+ }
142
+
143
+ export const secretAsBuffer = (sharedSecret) => {
144
+ if (Buffer.isBuffer(sharedSecret)) {
145
+ return sharedSecret;
146
+ }
147
+
148
+ if (sharedSecret.match(/^[0-9a-f]{40}$/i)) {
149
+ // Looks like it's hex
150
+ return Buffer.from(sharedSecret, "hex");
151
+ }
152
+
153
+ // It must be base64
154
+ return Buffer.from(sharedSecret, "base64");
155
+ };