steamcommunity 3.48.8 → 3.49.0

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,221 +1,221 @@
1
- const SteamCommunity = require('../index.js');
2
-
3
- const Helpers = require('./helpers.js');
4
-
5
- /**
6
- * Retrieves your account's Steam Web API key, if you already have one. If you don't yet have one, this will fail.
7
- * To create a Web API key, use `createWebApiKey()`.
8
- *
9
- * @param {null|function} unused - No longer used, kept for backward compatibility. You can omit this parameter and pass
10
- * your callback directly as the first parameter if you want.
11
- * @param {function} callback
12
- */
13
- SteamCommunity.prototype.getWebApiKey = function(unused, callback) {
14
- if (typeof unused == 'function') {
15
- callback = unused;
16
- }
17
-
18
- this.httpRequest({
19
- uri: 'https://steamcommunity.com/dev/apikey?l=english',
20
- followRedirect: false
21
- }, (err, response, body) => {
22
- if (err) {
23
- callback(err);
24
- return;
25
- }
26
-
27
- if (body.match(/You must have a validated email address to create a Steam Web API key./)) {
28
- return callback(new Error('You must have a validated email address to create a Steam Web API key.'));
29
- }
30
-
31
- if (body.match(/Your account requires (<a [^>]+>)?Steam Guard Mobile Authenticator/)) {
32
- return callback(new Error('Steam Guard Mobile Authenticator required to create a Steam Web API key'));
33
- }
34
-
35
- if (body.match(/<h2>Access Denied<\/h2>/)) {
36
- return callback(new Error('Access Denied'));
37
- }
38
-
39
- let match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
40
- if (match) {
41
- // We already have an API key registered
42
- callback(null, match[1]);
43
- } else {
44
- callback(new Error('No API key created for this account'));
45
- }
46
- }, "steamcommunity");
47
- };
48
-
49
- /**
50
- * @typedef CreateApiKeyOptions
51
- * @property {string} domain - The domain to associate with your API key
52
- * @property {string} [requestID] - If finalizing an existing create request, include the request ID
53
- * @property {string|Buffer} [identitySecret] - If you pass your identity_secret here, then steamcommunity will
54
- * internally handle accepting any confirmations.
55
- */
56
-
57
- /**
58
- * @typedef CreateApiKeyResponse
59
- * @property {boolean} confirmationRequired
60
- * @property {string} [apiKey] - If creating your API key succeeded, this is the new key
61
- * @property {CreateApiKeyOptions} [finalizeOptions] - If confirmation is required to create a key, then accept the
62
- * confirmation, then call createWebApiKey again and pass this whole object for the `options` parameter.
63
- */
64
-
65
- /**
66
- * @callback createWebApiKeyCallback
67
- * @param {Error|null} err
68
- * @param {CreateApiKeyResponse} [result]
69
- */
70
-
71
- /**
72
- * Starts the process to create a Steam Web API key. When the callback is fired, you will need to approve a mobile
73
- * confirmation in your app or using getConfirmations().
74
- *
75
- * @param {CreateApiKeyOptions} options
76
- * @param {createWebApiKeyCallback} callback
77
- */
78
- SteamCommunity.prototype.createWebApiKey = function(options, callback) {
79
- if (!options.domain) {
80
- callback(new Error('Passing a domain is required to register an API key'));
81
- return;
82
- }
83
-
84
- this.httpRequestPost({
85
- uri: 'https://steamcommunity.com/dev/requestkey',
86
- form: {
87
- domain: options.domain,
88
- request_id: options.requestID || '0',
89
- sessionid: this.getSessionID(),
90
- agreeToTerms: 'true'
91
- },
92
- json: true
93
- }, (err, res, body) => {
94
- if (err) {
95
- callback(err);
96
- return;
97
- }
98
-
99
- // body.requires_confirmation is 1/0, but the Steam website doesn't check this value and instead only checks the
100
- // value of `success`. So let's just do that.
101
-
102
- // This is a mess. I'm glad we have promises and await now.
103
-
104
- switch (body.success) {
105
- case SteamCommunity.EResult.OK:
106
- if (body.api_key) {
107
- callback(null, {confirmationRequired: false, apiKey: body.api_key});
108
- return;
109
- }
110
-
111
- // It's not been observed that we get result OK without api_key included, but the Steam website doesn't
112
- // use this value so let's be safe just in case it disappears in the future.
113
- this.getWebApiKey((err, key) => {
114
- if (err) {
115
- callback(err);
116
- return;
117
- }
118
-
119
- callback(null, {confirmationRequired: false, apiKey: key});
120
- });
121
- return;
122
-
123
- case SteamCommunity.EResult.Pending:
124
- let finalizeOptions = {
125
- domain: options.domain,
126
- requestID: body.request_id || options.requestID
127
- }
128
-
129
- if (options.identitySecret) {
130
- this.acceptConfirmationForObject(options.identitySecret, finalizeOptions.requestID, (err) => {
131
- if (err) {
132
- callback(err);
133
- } else {
134
- this.createWebApiKey(finalizeOptions, callback);
135
- }
136
- });
137
- return;
138
- }
139
-
140
- callback(null, {
141
- confirmationRequired: true,
142
- finalizeOptions: finalizeOptions
143
- });
144
- return;
145
-
146
- default:
147
- callback(Helpers.eresultError(body.success));
148
- }
149
- });
150
- };
151
-
152
- /**
153
- * @deprecated No longer works. Will be removed in a future release.
154
- * @param {function} callback
155
- */
156
- SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
157
- if (this.oAuthToken) {
158
- return callback(null, this.oAuthToken);
159
- }
160
-
161
- callback(new Error('This operation requires an OAuth token, which is no longer issued by Steam.'));
162
- };
163
-
164
- /**
165
- * Sets an access_token generated by steam-session using EAuthTokenPlatformType.MobileApp.
166
- * Required for some operations such as 2FA enabling and disabling.
167
- * This will throw an Error if the provided token is not valid, was not generated for the MobileApp platform, is expired,
168
- * or does not belong to the logged-in user account.
169
- *
170
- * @param {string} token
171
- */
172
- SteamCommunity.prototype.setMobileAppAccessToken = function(token) {
173
- if (!this.steamID) {
174
- throw new Error('Log on to steamcommunity before setting a mobile app access token');
175
- }
176
-
177
- let decodedToken = Helpers.decodeJwt(token);
178
-
179
- if (!decodedToken.iss || !decodedToken.sub || !decodedToken.aud || !decodedToken.exp) {
180
- throw new Error('Provided value is not a valid Steam access token');
181
- }
182
-
183
- if (decodedToken.iss == 'steam') {
184
- throw new Error('Provided token is a refresh token, not an access token');
185
- }
186
-
187
- if (decodedToken.sub != this.steamID.getSteamID64()) {
188
- throw new Error(`Provided token belongs to account ${decodedToken.sub}, but we are logged into ${this.steamID.getSteamID64()}`);
189
- }
190
-
191
- if (decodedToken.exp < Math.floor(Date.now() / 1000)) {
192
- throw new Error('Provided token is expired');
193
- }
194
-
195
- if ((decodedToken.aud || []).indexOf('mobile') == -1) {
196
- throw new Error('Provided token is not valid for MobileApp platform type');
197
- }
198
-
199
- this.mobileAccessToken = token;
200
- };
201
-
202
- /**
203
- * Verifies that the mobile access token we already have set is still valid for current login.
204
- *
205
- * @private
206
- */
207
- SteamCommunity.prototype._verifyMobileAccessToken = function() {
208
- if (!this.mobileAccessToken) {
209
- // No access token, so nothing to do here.
210
- return;
211
- }
212
-
213
- let decodedToken = Helpers.decodeJwt(this.mobileAccessToken);
214
-
215
- let isTokenInvalid = decodedToken.sub != this.steamID.getSteamID64() // SteamID doesn't match
216
- || decodedToken.exp < Math.floor(Date.now() / 1000); // Token is expired
217
-
218
- if (isTokenInvalid) {
219
- delete this.mobileAccessToken;
220
- }
221
- };
1
+ const SteamCommunity = require('../index.js');
2
+
3
+ const Helpers = require('./helpers.js');
4
+
5
+ /**
6
+ * Retrieves your account's Steam Web API key, if you already have one. If you don't yet have one, this will fail.
7
+ * To create a Web API key, use `createWebApiKey()`.
8
+ *
9
+ * @param {null|function} unused - No longer used, kept for backward compatibility. You can omit this parameter and pass
10
+ * your callback directly as the first parameter if you want.
11
+ * @param {function} callback
12
+ */
13
+ SteamCommunity.prototype.getWebApiKey = function(unused, callback) {
14
+ if (typeof unused == 'function') {
15
+ callback = unused;
16
+ }
17
+
18
+ this.httpRequest({
19
+ uri: 'https://steamcommunity.com/dev/apikey?l=english',
20
+ followRedirect: false
21
+ }, (err, response, body) => {
22
+ if (err) {
23
+ callback(err);
24
+ return;
25
+ }
26
+
27
+ if (body.match(/You must have a validated email address to create a Steam Web API key./)) {
28
+ return callback(new Error('You must have a validated email address to create a Steam Web API key.'));
29
+ }
30
+
31
+ if (body.match(/Your account requires (<a [^>]+>)?Steam Guard Mobile Authenticator/)) {
32
+ return callback(new Error('Steam Guard Mobile Authenticator required to create a Steam Web API key'));
33
+ }
34
+
35
+ if (body.match(/<h2>Access Denied<\/h2>/)) {
36
+ return callback(new Error('Access Denied'));
37
+ }
38
+
39
+ let match = body.match(/<p>Key: ([0-9A-F]+)<\/p>/);
40
+ if (match) {
41
+ // We already have an API key registered
42
+ callback(null, match[1]);
43
+ } else {
44
+ callback(new Error('No API key created for this account'));
45
+ }
46
+ }, "steamcommunity");
47
+ };
48
+
49
+ /**
50
+ * @typedef CreateApiKeyOptions
51
+ * @property {string} domain - The domain to associate with your API key
52
+ * @property {string} [requestID] - If finalizing an existing create request, include the request ID
53
+ * @property {string|Buffer} [identitySecret] - If you pass your identity_secret here, then steamcommunity will
54
+ * internally handle accepting any confirmations.
55
+ */
56
+
57
+ /**
58
+ * @typedef CreateApiKeyResponse
59
+ * @property {boolean} confirmationRequired
60
+ * @property {string} [apiKey] - If creating your API key succeeded, this is the new key
61
+ * @property {CreateApiKeyOptions} [finalizeOptions] - If confirmation is required to create a key, then accept the
62
+ * confirmation, then call createWebApiKey again and pass this whole object for the `options` parameter.
63
+ */
64
+
65
+ /**
66
+ * @callback createWebApiKeyCallback
67
+ * @param {Error|null} err
68
+ * @param {CreateApiKeyResponse} [result]
69
+ */
70
+
71
+ /**
72
+ * Starts the process to create a Steam Web API key. When the callback is fired, you will need to approve a mobile
73
+ * confirmation in your app or using getConfirmations().
74
+ *
75
+ * @param {CreateApiKeyOptions} options
76
+ * @param {createWebApiKeyCallback} callback
77
+ */
78
+ SteamCommunity.prototype.createWebApiKey = function(options, callback) {
79
+ if (!options.domain) {
80
+ callback(new Error('Passing a domain is required to register an API key'));
81
+ return;
82
+ }
83
+
84
+ this.httpRequestPost({
85
+ uri: 'https://steamcommunity.com/dev/requestkey',
86
+ form: {
87
+ domain: options.domain,
88
+ request_id: options.requestID || '0',
89
+ sessionid: this.getSessionID(),
90
+ agreeToTerms: 'true'
91
+ },
92
+ json: true
93
+ }, (err, res, body) => {
94
+ if (err) {
95
+ callback(err);
96
+ return;
97
+ }
98
+
99
+ // body.requires_confirmation is 1/0, but the Steam website doesn't check this value and instead only checks the
100
+ // value of `success`. So let's just do that.
101
+
102
+ // This is a mess. I'm glad we have promises and await now.
103
+
104
+ switch (body.success) {
105
+ case SteamCommunity.EResult.OK:
106
+ if (body.api_key) {
107
+ callback(null, {confirmationRequired: false, apiKey: body.api_key});
108
+ return;
109
+ }
110
+
111
+ // It's not been observed that we get result OK without api_key included, but the Steam website doesn't
112
+ // use this value so let's be safe just in case it disappears in the future.
113
+ this.getWebApiKey((err, key) => {
114
+ if (err) {
115
+ callback(err);
116
+ return;
117
+ }
118
+
119
+ callback(null, {confirmationRequired: false, apiKey: key});
120
+ });
121
+ return;
122
+
123
+ case SteamCommunity.EResult.Pending:
124
+ let finalizeOptions = {
125
+ domain: options.domain,
126
+ requestID: body.request_id || options.requestID
127
+ }
128
+
129
+ if (options.identitySecret) {
130
+ this.acceptConfirmationForObject(options.identitySecret, finalizeOptions.requestID, (err) => {
131
+ if (err) {
132
+ callback(err);
133
+ } else {
134
+ this.createWebApiKey(finalizeOptions, callback);
135
+ }
136
+ });
137
+ return;
138
+ }
139
+
140
+ callback(null, {
141
+ confirmationRequired: true,
142
+ finalizeOptions: finalizeOptions
143
+ });
144
+ return;
145
+
146
+ default:
147
+ callback(Helpers.eresultError(body.success));
148
+ }
149
+ });
150
+ };
151
+
152
+ /**
153
+ * @deprecated No longer works. Will be removed in a future release.
154
+ * @param {function} callback
155
+ */
156
+ SteamCommunity.prototype.getWebApiOauthToken = function(callback) {
157
+ if (this.oAuthToken) {
158
+ return callback(null, this.oAuthToken);
159
+ }
160
+
161
+ callback(new Error('This operation requires an OAuth token, which is no longer issued by Steam.'));
162
+ };
163
+
164
+ /**
165
+ * Sets an access_token generated by steam-session using EAuthTokenPlatformType.MobileApp.
166
+ * Required for some operations such as 2FA enabling and disabling.
167
+ * This will throw an Error if the provided token is not valid, was not generated for the MobileApp platform, is expired,
168
+ * or does not belong to the logged-in user account.
169
+ *
170
+ * @param {string} token
171
+ */
172
+ SteamCommunity.prototype.setMobileAppAccessToken = function(token) {
173
+ if (!this.steamID) {
174
+ throw new Error('Log on to steamcommunity before setting a mobile app access token');
175
+ }
176
+
177
+ let decodedToken = Helpers.decodeJwt(token);
178
+
179
+ if (!decodedToken.iss || !decodedToken.sub || !decodedToken.aud || !decodedToken.exp) {
180
+ throw new Error('Provided value is not a valid Steam access token');
181
+ }
182
+
183
+ if (decodedToken.iss == 'steam') {
184
+ throw new Error('Provided token is a refresh token, not an access token');
185
+ }
186
+
187
+ if (decodedToken.sub != this.steamID.getSteamID64()) {
188
+ throw new Error(`Provided token belongs to account ${decodedToken.sub}, but we are logged into ${this.steamID.getSteamID64()}`);
189
+ }
190
+
191
+ if (decodedToken.exp < Math.floor(Date.now() / 1000)) {
192
+ throw new Error('Provided token is expired');
193
+ }
194
+
195
+ if ((decodedToken.aud || []).indexOf('mobile') == -1) {
196
+ throw new Error('Provided token is not valid for MobileApp platform type');
197
+ }
198
+
199
+ this.mobileAccessToken = token;
200
+ };
201
+
202
+ /**
203
+ * Verifies that the mobile access token we already have set is still valid for current login.
204
+ *
205
+ * @private
206
+ */
207
+ SteamCommunity.prototype._verifyMobileAccessToken = function() {
208
+ if (!this.mobileAccessToken) {
209
+ // No access token, so nothing to do here.
210
+ return;
211
+ }
212
+
213
+ let decodedToken = Helpers.decodeJwt(this.mobileAccessToken);
214
+
215
+ let isTokenInvalid = decodedToken.sub != this.steamID.getSteamID64() // SteamID doesn't match
216
+ || decodedToken.exp < Math.floor(Date.now() / 1000); // Token is expired
217
+
218
+ if (isTokenInvalid) {
219
+ delete this.mobileAccessToken;
220
+ }
221
+ };
@@ -1,35 +1,35 @@
1
- # node-steamcommunity examples
2
-
3
- The files in this directory are example scripts that you can use as a getting-started point for using node-steamcommunity.
4
-
5
- ## Enable or Disable Two-Factor Authentication
6
-
7
- If you need to enable or disable 2FA on your bot account, you can use enable_twofactor.js and disable_twofactor.js to do so.
8
- The way that you're intended to use these scripts is by cloning the repository locally, and then running them directly
9
- from this examples directory.
10
-
11
- For example:
12
-
13
- ```shell
14
- git clone https://github.com/DoctorMcKay/node-steamcommunity node-steamcommunity
15
- cd node-steamcommunity
16
- npm install
17
- cd examples
18
- node enable_twofactor.js
19
- ```
20
-
21
- ## Accept All Confirmations
22
-
23
- If you need to accept trade or market confirmations on your bot account for which you have your identity secret, you can
24
- use accept_all_confirmations.js to do so. The way that you're intended to use this script is by cloning the repository
25
- locally, and then running it directly from this examples directory.
26
-
27
- For example:
28
-
29
- ```shell
30
- git clone https://github.com/DoctorMcKay/node-steamcommunity node-steamcommunity
31
- cd node-steamcommunity
32
- npm install
33
- cd examples
34
- node accept_all_confirmations.js
35
- ```
1
+ # node-steamcommunity examples
2
+
3
+ The files in this directory are example scripts that you can use as a getting-started point for using node-steamcommunity.
4
+
5
+ ## Enable or Disable Two-Factor Authentication
6
+
7
+ If you need to enable or disable 2FA on your bot account, you can use enable_twofactor.js and disable_twofactor.js to do so.
8
+ The way that you're intended to use these scripts is by cloning the repository locally, and then running them directly
9
+ from this examples directory.
10
+
11
+ For example:
12
+
13
+ ```shell
14
+ git clone https://github.com/DoctorMcKay/node-steamcommunity node-steamcommunity
15
+ cd node-steamcommunity
16
+ npm install
17
+ cd examples
18
+ node enable_twofactor.js
19
+ ```
20
+
21
+ ## Accept All Confirmations
22
+
23
+ If you need to accept trade or market confirmations on your bot account for which you have your identity secret, you can
24
+ use accept_all_confirmations.js to do so. The way that you're intended to use this script is by cloning the repository
25
+ locally, and then running it directly from this examples directory.
26
+
27
+ For example:
28
+
29
+ ```shell
30
+ git clone https://github.com/DoctorMcKay/node-steamcommunity node-steamcommunity
31
+ cd node-steamcommunity
32
+ npm install
33
+ cd examples
34
+ node accept_all_confirmations.js
35
+ ```