steamcommunity 3.49.0 → 3.50.1

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.
@@ -1,162 +1,162 @@
1
- var URL = require('url');
2
-
3
- var SteamCommunity = require('../index.js');
4
-
5
- SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) {
6
- if (typeof uri === 'object') {
7
- source = callback;
8
- callback = options;
9
- options = uri;
10
- uri = options.url || options.uri;
11
- } else if (typeof options === 'function') {
12
- source = callback;
13
- callback = options;
14
- options = {};
15
- }
16
-
17
- options.url = options.uri = uri;
18
-
19
- if (this._httpRequestConvenienceMethod) {
20
- options.method = this._httpRequestConvenienceMethod;
21
- delete this._httpRequestConvenienceMethod;
22
- }
23
-
24
- // Add origin header if necessary
25
- // https://github.com/DoctorMcKay/node-steamcommunity/issues/351
26
- if ((options.method || 'GET').toUpperCase() != 'GET') {
27
- options.headers = options.headers || {};
28
- if (!options.headers.origin) {
29
- var parsedUrl = URL.parse(options.url);
30
- options.headers.origin = parsedUrl.protocol + '//' + parsedUrl.host;
31
- }
32
- }
33
-
34
- var requestID = ++this._httpRequestID;
35
- source = source || "";
36
-
37
- var self = this;
38
- var continued = false;
39
-
40
- if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
41
- // No pre-hook, or the pre-hook doesn't want to delay the request.
42
- continueRequest(null);
43
- }
44
-
45
- function continueRequest(err) {
46
- if (continued) {
47
- return;
48
- }
49
-
50
- continued = true;
51
-
52
- if (err) {
53
- if (callback) {
54
- callback(err);
55
- }
56
-
57
- return;
58
- }
59
-
60
- self.request(options, function (err, response, body) {
61
- var hasCallback = !!callback;
62
- var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback, body);
63
- var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already
64
- var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function () {} : callback); // don't fire the callback if either of the previous already did
65
- var jsonError = options.json && options.checkJsonError !== false && !body ? new Error("Malformed JSON response") : null;
66
-
67
- self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || jsonError || null, response, body, {
68
- "hasCallback": hasCallback,
69
- "httpError": httpError,
70
- "communityError": communityError,
71
- "tradeError": tradeError,
72
- "jsonError": jsonError
73
- });
74
-
75
- if (hasCallback && !(httpError || communityError || tradeError)) {
76
- if (jsonError) {
77
- callback.call(self, jsonError, response);
78
- } else {
79
- callback.apply(self, arguments);
80
- }
81
- }
82
- });
83
- }
84
- };
85
-
86
- SteamCommunity.prototype.httpRequestGet = function() {
87
- this._httpRequestConvenienceMethod = "GET";
88
- return this.httpRequest.apply(this, arguments);
89
- };
90
-
91
- SteamCommunity.prototype.httpRequestPost = function() {
92
- this._httpRequestConvenienceMethod = "POST";
93
- return this.httpRequest.apply(this, arguments);
94
- };
95
-
96
- SteamCommunity.prototype._notifySessionExpired = function(err) {
97
- this.emit('sessionExpired', err);
98
- };
99
-
100
- SteamCommunity.prototype._checkHttpError = function(err, response, callback, body) {
101
- if (err) {
102
- callback(err, response, body);
103
- return err;
104
- }
105
-
106
- if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
107
- err = new Error("Not Logged In");
108
- callback(err, response, body);
109
- this._notifySessionExpired(err);
110
- return err;
111
- }
112
-
113
- if (response.statusCode == 403 && typeof response.body === 'string' && response.body.match(/<div id="parental_notice_instructions">Enter your PIN below to exit Family View.<\/div>/)) {
114
- err = new Error("Family View Restricted");
115
- callback(err, response, body);
116
- return err;
117
- }
118
-
119
- if (response.statusCode >= 400) {
120
- err = new Error("HTTP error " + response.statusCode);
121
- err.code = response.statusCode;
122
- callback(err, response, body);
123
- return err;
124
- }
125
-
126
- return false;
127
- };
128
-
129
- SteamCommunity.prototype._checkCommunityError = function(html, callback) {
130
- var err;
131
-
132
- if(typeof html === 'string' && html.match(/<h1>Sorry!<\/h1>/)) {
133
- var match = html.match(/<h3>(.+)<\/h3>/);
134
- err = new Error(match ? match[1] : "Unknown error occurred");
135
- callback(err);
136
- return err;
137
- }
138
-
139
- if (typeof html === 'string' && html.indexOf('g_steamID = false;') > -1 && html.indexOf('<title>Sign In</title>') > -1) {
140
- err = new Error("Not Logged In");
141
- callback(err);
142
- this._notifySessionExpired(err);
143
- return err;
144
- }
145
-
146
- return false;
147
- };
148
-
149
- SteamCommunity.prototype._checkTradeError = function(html, callback) {
150
- if (typeof html !== 'string') {
151
- return false;
152
- }
153
-
154
- var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
155
- if (match) {
156
- var err = new Error(match[1].trim());
157
- callback(err);
158
- return err;
159
- }
160
-
161
- return false;
162
- };
1
+ var URL = require('url');
2
+
3
+ var SteamCommunity = require('../index.js');
4
+
5
+ SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) {
6
+ if (typeof uri === 'object') {
7
+ source = callback;
8
+ callback = options;
9
+ options = uri;
10
+ uri = options.url || options.uri;
11
+ } else if (typeof options === 'function') {
12
+ source = callback;
13
+ callback = options;
14
+ options = {};
15
+ }
16
+
17
+ options.url = options.uri = uri;
18
+
19
+ if (this._httpRequestConvenienceMethod) {
20
+ options.method = this._httpRequestConvenienceMethod;
21
+ delete this._httpRequestConvenienceMethod;
22
+ }
23
+
24
+ // Add origin header if necessary
25
+ // https://github.com/DoctorMcKay/node-steamcommunity/issues/351
26
+ if ((options.method || 'GET').toUpperCase() != 'GET') {
27
+ options.headers = options.headers || {};
28
+ if (!options.headers.origin) {
29
+ var parsedUrl = URL.parse(options.url);
30
+ options.headers.origin = parsedUrl.protocol + '//' + parsedUrl.host;
31
+ }
32
+ }
33
+
34
+ var requestID = ++this._httpRequestID;
35
+ source = source || "";
36
+
37
+ var self = this;
38
+ var continued = false;
39
+
40
+ if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
41
+ // No pre-hook, or the pre-hook doesn't want to delay the request.
42
+ continueRequest(null);
43
+ }
44
+
45
+ function continueRequest(err) {
46
+ if (continued) {
47
+ return;
48
+ }
49
+
50
+ continued = true;
51
+
52
+ if (err) {
53
+ if (callback) {
54
+ callback(err);
55
+ }
56
+
57
+ return;
58
+ }
59
+
60
+ self.request(options, function (err, response, body) {
61
+ var hasCallback = !!callback;
62
+ var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback, body);
63
+ var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already
64
+ var tradeError = !options.json && options.checkTradeError !== false && self._checkTradeError(body, httpError || communityError ? function () {} : callback); // don't fire the callback if either of the previous already did
65
+ var jsonError = options.json && options.checkJsonError !== false && !body ? new Error("Malformed JSON response") : null;
66
+
67
+ self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || jsonError || null, response, body, {
68
+ "hasCallback": hasCallback,
69
+ "httpError": httpError,
70
+ "communityError": communityError,
71
+ "tradeError": tradeError,
72
+ "jsonError": jsonError
73
+ });
74
+
75
+ if (hasCallback && !(httpError || communityError || tradeError)) {
76
+ if (jsonError) {
77
+ callback.call(self, jsonError, response);
78
+ } else {
79
+ callback.apply(self, arguments);
80
+ }
81
+ }
82
+ });
83
+ }
84
+ };
85
+
86
+ SteamCommunity.prototype.httpRequestGet = function() {
87
+ this._httpRequestConvenienceMethod = "GET";
88
+ return this.httpRequest.apply(this, arguments);
89
+ };
90
+
91
+ SteamCommunity.prototype.httpRequestPost = function() {
92
+ this._httpRequestConvenienceMethod = "POST";
93
+ return this.httpRequest.apply(this, arguments);
94
+ };
95
+
96
+ SteamCommunity.prototype._notifySessionExpired = function(err) {
97
+ this.emit('sessionExpired', err);
98
+ };
99
+
100
+ SteamCommunity.prototype._checkHttpError = function(err, response, callback, body) {
101
+ if (err) {
102
+ callback(err, response, body);
103
+ return err;
104
+ }
105
+
106
+ if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
107
+ err = new Error("Not Logged In");
108
+ callback(err, response, body);
109
+ this._notifySessionExpired(err);
110
+ return err;
111
+ }
112
+
113
+ if (response.statusCode == 403 && typeof response.body === 'string' && response.body.match(/<div id="parental_notice_instructions">Enter your PIN below to exit Family View.<\/div>/)) {
114
+ err = new Error("Family View Restricted");
115
+ callback(err, response, body);
116
+ return err;
117
+ }
118
+
119
+ if (response.statusCode >= 400) {
120
+ err = new Error("HTTP error " + response.statusCode);
121
+ err.code = response.statusCode;
122
+ callback(err, response, body);
123
+ return err;
124
+ }
125
+
126
+ return false;
127
+ };
128
+
129
+ SteamCommunity.prototype._checkCommunityError = function(html, callback) {
130
+ var err;
131
+
132
+ if(typeof html === 'string' && html.match(/<h1>Sorry!<\/h1>/)) {
133
+ var match = html.match(/<h3>(.+)<\/h3>/);
134
+ err = new Error(match ? match[1] : "Unknown error occurred");
135
+ callback(err);
136
+ return err;
137
+ }
138
+
139
+ if (typeof html === 'string' && html.indexOf('g_steamID = false;') > -1 && html.indexOf('<title>Sign In</title>') > -1) {
140
+ err = new Error("Not Logged In");
141
+ callback(err);
142
+ this._notifySessionExpired(err);
143
+ return err;
144
+ }
145
+
146
+ return false;
147
+ };
148
+
149
+ SteamCommunity.prototype._checkTradeError = function(html, callback) {
150
+ if (typeof html !== 'string') {
151
+ return false;
152
+ }
153
+
154
+ var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
155
+ if (match) {
156
+ var err = new Error(match[1].trim());
157
+ callback(err);
158
+ return err;
159
+ }
160
+
161
+ return false;
162
+ };
@@ -1,110 +1,110 @@
1
- const {chrome} = require('@doctormckay/user-agents');
2
-
3
- const SteamCommunity = require('../index.js');
4
-
5
- /**
6
- * @typedef LogOnDetails
7
- * @property {string} accountName
8
- * @property {string} password
9
- * @property {string} [steamguard]
10
- * @property {string} [authCode]
11
- * @property {string} [twoFactorCode]
12
- * @property {boolean} disableMobile
13
- */
14
-
15
- /**
16
- * @typedef LogOnResponse
17
- * @property {string} sessionID
18
- * @property {string[]} cookies
19
- * @property {string} steamguard
20
- * @property {string} [mobileAccessToken]
21
- */
22
-
23
- /**
24
- *
25
- * @param {LogOnDetails} logOnDetails
26
- * @returns {Promise<LogOnResponse>}
27
- * @private
28
- */
29
- SteamCommunity.prototype._modernLogin = function(logOnDetails) {
30
- return new Promise(async (resolve, reject) => {
31
- if (!isNodeVersionNewEnough()) {
32
- return reject(new Error(`Node.js version is too old! Need >=12.22.0 or later, got ${process.versions.node}.`));
33
- }
34
-
35
- if (this._options.request) {
36
- return reject(new Error('SteamCommunity.login() is incompatible with node-steamcommunity v3\'s usage of \'request\'. If you need to specify a custom \'request\' instance (e.g. when using a proxy), use https://www.npmjs.com/package/steam-session directly to log onto Steam.'));
37
- }
38
-
39
- // Import this here so we don't cause problems on old Node versions if this code path isn't taken.
40
- const {LoginSession, EAuthTokenPlatformType, EAuthSessionGuardType} = require('steam-session');
41
-
42
- let session = new LoginSession(
43
- logOnDetails.disableMobile
44
- ? EAuthTokenPlatformType.WebBrowser
45
- : EAuthTokenPlatformType.MobileApp,
46
- {
47
- localAddress: this._options.localAddress,
48
- userAgent: this._options.userAgent || chrome()
49
- }
50
- );
51
-
52
- session.on('authenticated', async () => {
53
- try {
54
- let webCookies = await session.getWebCookies();
55
- let sessionIdCookie = webCookies.find(c => c.startsWith('sessionid='));
56
- resolve({
57
- sessionID: sessionIdCookie.split('=')[1].split(';')[0].trim(),
58
- cookies: webCookies,
59
- steamguard: session.steamGuardMachineToken,
60
- mobileAccessToken: logOnDetails.disableMobile ? null : session.accessToken
61
- });
62
- } catch (ex) {
63
- reject(ex);
64
- }
65
- });
66
-
67
- session.on('error', (err) => {
68
- reject(err);
69
- });
70
-
71
- try {
72
- let startResult = await session.startWithCredentials({
73
- accountName: logOnDetails.accountName,
74
- password: logOnDetails.password,
75
- steamGuardMachineToken: logOnDetails.steamguard,
76
- steamGuardCode: logOnDetails.authCode || logOnDetails.twoFactorCode
77
- });
78
-
79
- if (startResult.actionRequired) {
80
- // Cannot continue with login, need something from the user
81
- session.cancelLoginAttempt();
82
-
83
- let emailMfaAction = startResult.validActions.find(action => action.type == EAuthSessionGuardType.EmailCode);
84
- if (emailMfaAction) {
85
- let err = new Error('SteamGuard');
86
- err.emaildomain = emailMfaAction.detail;
87
- return reject(err);
88
- }
89
-
90
- return reject(new Error('SteamGuardMobile'));
91
- }
92
- } catch (ex) {
93
- return reject(ex);
94
- }
95
- });
96
- };
97
-
98
- function isNodeVersionNewEnough() {
99
- let [major, minor] = process.versions.node.split('.');
100
-
101
- if (major < 12) {
102
- return false;
103
- }
104
-
105
- if (major == 12 && minor < 22) {
106
- return false;
107
- }
108
-
109
- return true;
110
- }
1
+ const {chrome} = require('@doctormckay/user-agents');
2
+
3
+ const SteamCommunity = require('../index.js');
4
+
5
+ /**
6
+ * @typedef LogOnDetails
7
+ * @property {string} accountName
8
+ * @property {string} password
9
+ * @property {string} [steamguard]
10
+ * @property {string} [authCode]
11
+ * @property {string} [twoFactorCode]
12
+ * @property {boolean} disableMobile
13
+ */
14
+
15
+ /**
16
+ * @typedef LogOnResponse
17
+ * @property {string} sessionID
18
+ * @property {string[]} cookies
19
+ * @property {string} steamguard
20
+ * @property {string} [mobileAccessToken]
21
+ */
22
+
23
+ /**
24
+ *
25
+ * @param {LogOnDetails} logOnDetails
26
+ * @returns {Promise<LogOnResponse>}
27
+ * @private
28
+ */
29
+ SteamCommunity.prototype._modernLogin = function(logOnDetails) {
30
+ return new Promise(async (resolve, reject) => {
31
+ if (!isNodeVersionNewEnough()) {
32
+ return reject(new Error(`Node.js version is too old! Need >=12.22.0 or later, got ${process.versions.node}.`));
33
+ }
34
+
35
+ if (this._options.request) {
36
+ return reject(new Error('SteamCommunity.login() is incompatible with node-steamcommunity v3\'s usage of \'request\'. If you need to specify a custom \'request\' instance (e.g. when using a proxy), use https://www.npmjs.com/package/steam-session directly to log onto Steam.'));
37
+ }
38
+
39
+ // Import this here so we don't cause problems on old Node versions if this code path isn't taken.
40
+ const {LoginSession, EAuthTokenPlatformType, EAuthSessionGuardType} = require('steam-session');
41
+
42
+ let session = new LoginSession(
43
+ logOnDetails.disableMobile
44
+ ? EAuthTokenPlatformType.WebBrowser
45
+ : EAuthTokenPlatformType.MobileApp,
46
+ {
47
+ localAddress: this._options.localAddress,
48
+ userAgent: this._options.userAgent || chrome()
49
+ }
50
+ );
51
+
52
+ session.on('authenticated', async () => {
53
+ try {
54
+ let webCookies = await session.getWebCookies();
55
+ let sessionIdCookie = webCookies.find(c => c.startsWith('sessionid='));
56
+ resolve({
57
+ sessionID: sessionIdCookie.split('=')[1].split(';')[0].trim(),
58
+ cookies: webCookies,
59
+ steamguard: session.steamGuardMachineToken,
60
+ mobileAccessToken: logOnDetails.disableMobile ? null : session.accessToken
61
+ });
62
+ } catch (ex) {
63
+ reject(ex);
64
+ }
65
+ });
66
+
67
+ session.on('error', (err) => {
68
+ reject(err);
69
+ });
70
+
71
+ try {
72
+ let startResult = await session.startWithCredentials({
73
+ accountName: logOnDetails.accountName,
74
+ password: logOnDetails.password,
75
+ steamGuardMachineToken: logOnDetails.steamguard,
76
+ steamGuardCode: logOnDetails.authCode || logOnDetails.twoFactorCode
77
+ });
78
+
79
+ if (startResult.actionRequired) {
80
+ // Cannot continue with login, need something from the user
81
+ session.cancelLoginAttempt();
82
+
83
+ let emailMfaAction = startResult.validActions.find(action => action.type == EAuthSessionGuardType.EmailCode);
84
+ if (emailMfaAction) {
85
+ let err = new Error('SteamGuard');
86
+ err.emaildomain = emailMfaAction.detail;
87
+ return reject(err);
88
+ }
89
+
90
+ return reject(new Error('SteamGuardMobile'));
91
+ }
92
+ } catch (ex) {
93
+ return reject(ex);
94
+ }
95
+ });
96
+ };
97
+
98
+ function isNodeVersionNewEnough() {
99
+ let [major, minor] = process.versions.node.split('.');
100
+
101
+ if (major < 12) {
102
+ return false;
103
+ }
104
+
105
+ if (major == 12 && minor < 22) {
106
+ return false;
107
+ }
108
+
109
+ return true;
110
+ }