steamcommunity 3.47.0 → 3.48.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,150 +1,150 @@
1
- var SteamCommunity = require('../index.js');
2
-
3
- SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) {
4
- if (typeof uri === 'object') {
5
- source = callback;
6
- callback = options;
7
- options = uri;
8
- uri = options.url || options.uri;
9
- } else if (typeof options === 'function') {
10
- source = callback;
11
- callback = options;
12
- options = {};
13
- }
14
-
15
- options.url = options.uri = uri;
16
-
17
- if (this._httpRequestConvenienceMethod) {
18
- options.method = this._httpRequestConvenienceMethod;
19
- delete this._httpRequestConvenienceMethod;
20
- }
21
-
22
- var requestID = ++this._httpRequestID;
23
- source = source || "";
24
-
25
- var self = this;
26
- var continued = false;
27
-
28
- if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
29
- // No pre-hook, or the pre-hook doesn't want to delay the request.
30
- continueRequest(null);
31
- }
32
-
33
- function continueRequest(err) {
34
- if (continued) {
35
- return;
36
- }
37
-
38
- continued = true;
39
-
40
- if (err) {
41
- if (callback) {
42
- callback(err);
43
- }
44
-
45
- return;
46
- }
47
-
48
- self.request(options, function (err, response, body) {
49
- var hasCallback = !!callback;
50
- var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback, body);
51
- var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already
52
- 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
53
- var jsonError = options.json && options.checkJsonError !== false && !body ? new Error("Malformed JSON response") : null;
54
-
55
- self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || jsonError || null, response, body, {
56
- "hasCallback": hasCallback,
57
- "httpError": httpError,
58
- "communityError": communityError,
59
- "tradeError": tradeError,
60
- "jsonError": jsonError
61
- });
62
-
63
- if (hasCallback && !(httpError || communityError || tradeError)) {
64
- if (jsonError) {
65
- callback.call(self, jsonError, response);
66
- } else {
67
- callback.apply(self, arguments);
68
- }
69
- }
70
- });
71
- }
72
- };
73
-
74
- SteamCommunity.prototype.httpRequestGet = function() {
75
- this._httpRequestConvenienceMethod = "GET";
76
- return this.httpRequest.apply(this, arguments);
77
- };
78
-
79
- SteamCommunity.prototype.httpRequestPost = function() {
80
- this._httpRequestConvenienceMethod = "POST";
81
- return this.httpRequest.apply(this, arguments);
82
- };
83
-
84
- SteamCommunity.prototype._notifySessionExpired = function(err) {
85
- this.emit('sessionExpired', err);
86
- };
87
-
88
- SteamCommunity.prototype._checkHttpError = function(err, response, callback, body) {
89
- if (err) {
90
- callback(err, response, body);
91
- return err;
92
- }
93
-
94
- if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
95
- err = new Error("Not Logged In");
96
- callback(err, response, body);
97
- this._notifySessionExpired(err);
98
- return err;
99
- }
100
-
101
- 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>/)) {
102
- err = new Error("Family View Restricted");
103
- callback(err, response, body);
104
- return err;
105
- }
106
-
107
- if (response.statusCode >= 400) {
108
- err = new Error("HTTP error " + response.statusCode);
109
- err.code = response.statusCode;
110
- callback(err, response, body);
111
- return err;
112
- }
113
-
114
- return false;
115
- };
116
-
117
- SteamCommunity.prototype._checkCommunityError = function(html, callback) {
118
- var err;
119
-
120
- if(typeof html === 'string' && html.match(/<h1>Sorry!<\/h1>/)) {
121
- var match = html.match(/<h3>(.+)<\/h3>/);
122
- err = new Error(match ? match[1] : "Unknown error occurred");
123
- callback(err);
124
- return err;
125
- }
126
-
127
- if (typeof html === 'string' && html.indexOf('g_steamID = false;') > -1 && html.indexOf('<title>Sign In</title>') > -1) {
128
- err = new Error("Not Logged In");
129
- callback(err);
130
- this._notifySessionExpired(err);
131
- return err;
132
- }
133
-
134
- return false;
135
- };
136
-
137
- SteamCommunity.prototype._checkTradeError = function(html, callback) {
138
- if (typeof html !== 'string') {
139
- return false;
140
- }
141
-
142
- var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
143
- if (match) {
144
- var err = new Error(match[1].trim());
145
- callback(err);
146
- return err;
147
- }
148
-
149
- return false;
150
- };
1
+ var SteamCommunity = require('../index.js');
2
+
3
+ SteamCommunity.prototype.httpRequest = function(uri, options, callback, source) {
4
+ if (typeof uri === 'object') {
5
+ source = callback;
6
+ callback = options;
7
+ options = uri;
8
+ uri = options.url || options.uri;
9
+ } else if (typeof options === 'function') {
10
+ source = callback;
11
+ callback = options;
12
+ options = {};
13
+ }
14
+
15
+ options.url = options.uri = uri;
16
+
17
+ if (this._httpRequestConvenienceMethod) {
18
+ options.method = this._httpRequestConvenienceMethod;
19
+ delete this._httpRequestConvenienceMethod;
20
+ }
21
+
22
+ var requestID = ++this._httpRequestID;
23
+ source = source || "";
24
+
25
+ var self = this;
26
+ var continued = false;
27
+
28
+ if (!this.onPreHttpRequest || !this.onPreHttpRequest(requestID, source, options, continueRequest)) {
29
+ // No pre-hook, or the pre-hook doesn't want to delay the request.
30
+ continueRequest(null);
31
+ }
32
+
33
+ function continueRequest(err) {
34
+ if (continued) {
35
+ return;
36
+ }
37
+
38
+ continued = true;
39
+
40
+ if (err) {
41
+ if (callback) {
42
+ callback(err);
43
+ }
44
+
45
+ return;
46
+ }
47
+
48
+ self.request(options, function (err, response, body) {
49
+ var hasCallback = !!callback;
50
+ var httpError = options.checkHttpError !== false && self._checkHttpError(err, response, callback, body);
51
+ var communityError = !options.json && options.checkCommunityError !== false && self._checkCommunityError(body, httpError ? function () {} : callback); // don't fire the callback if hasHttpError did it already
52
+ 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
53
+ var jsonError = options.json && options.checkJsonError !== false && !body ? new Error("Malformed JSON response") : null;
54
+
55
+ self.emit('postHttpRequest', requestID, source, options, httpError || communityError || tradeError || jsonError || null, response, body, {
56
+ "hasCallback": hasCallback,
57
+ "httpError": httpError,
58
+ "communityError": communityError,
59
+ "tradeError": tradeError,
60
+ "jsonError": jsonError
61
+ });
62
+
63
+ if (hasCallback && !(httpError || communityError || tradeError)) {
64
+ if (jsonError) {
65
+ callback.call(self, jsonError, response);
66
+ } else {
67
+ callback.apply(self, arguments);
68
+ }
69
+ }
70
+ });
71
+ }
72
+ };
73
+
74
+ SteamCommunity.prototype.httpRequestGet = function() {
75
+ this._httpRequestConvenienceMethod = "GET";
76
+ return this.httpRequest.apply(this, arguments);
77
+ };
78
+
79
+ SteamCommunity.prototype.httpRequestPost = function() {
80
+ this._httpRequestConvenienceMethod = "POST";
81
+ return this.httpRequest.apply(this, arguments);
82
+ };
83
+
84
+ SteamCommunity.prototype._notifySessionExpired = function(err) {
85
+ this.emit('sessionExpired', err);
86
+ };
87
+
88
+ SteamCommunity.prototype._checkHttpError = function(err, response, callback, body) {
89
+ if (err) {
90
+ callback(err, response, body);
91
+ return err;
92
+ }
93
+
94
+ if (response.statusCode >= 300 && response.statusCode <= 399 && response.headers.location.indexOf('/login') != -1) {
95
+ err = new Error("Not Logged In");
96
+ callback(err, response, body);
97
+ this._notifySessionExpired(err);
98
+ return err;
99
+ }
100
+
101
+ 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>/)) {
102
+ err = new Error("Family View Restricted");
103
+ callback(err, response, body);
104
+ return err;
105
+ }
106
+
107
+ if (response.statusCode >= 400) {
108
+ err = new Error("HTTP error " + response.statusCode);
109
+ err.code = response.statusCode;
110
+ callback(err, response, body);
111
+ return err;
112
+ }
113
+
114
+ return false;
115
+ };
116
+
117
+ SteamCommunity.prototype._checkCommunityError = function(html, callback) {
118
+ var err;
119
+
120
+ if(typeof html === 'string' && html.match(/<h1>Sorry!<\/h1>/)) {
121
+ var match = html.match(/<h3>(.+)<\/h3>/);
122
+ err = new Error(match ? match[1] : "Unknown error occurred");
123
+ callback(err);
124
+ return err;
125
+ }
126
+
127
+ if (typeof html === 'string' && html.indexOf('g_steamID = false;') > -1 && html.indexOf('<title>Sign In</title>') > -1) {
128
+ err = new Error("Not Logged In");
129
+ callback(err);
130
+ this._notifySessionExpired(err);
131
+ return err;
132
+ }
133
+
134
+ return false;
135
+ };
136
+
137
+ SteamCommunity.prototype._checkTradeError = function(html, callback) {
138
+ if (typeof html !== 'string') {
139
+ return false;
140
+ }
141
+
142
+ var match = html.match(/<div id="error_msg">\s*([^<]+)\s*<\/div>/);
143
+ if (match) {
144
+ var err = new Error(match[1].trim());
145
+ callback(err);
146
+ return err;
147
+ }
148
+
149
+ return false;
150
+ };
@@ -1,173 +1,173 @@
1
- var SteamCommunity = require('../index.js');
2
- var CEconItem = require('../classes/CEconItem.js');
3
- var Helpers = require('./helpers.js');
4
- var SteamID = require('steamid');
5
- var request = require('request');
6
- var Cheerio = require('cheerio');
7
- var Async = require('async');
8
-
9
- /*
10
- * Inventory history in a nutshell.
11
- *
12
- * There are no more page numbers. Now you have to request after_time and optionally after_trade.
13
- * Without "prev" set, you will request 30 trades that were completed FURTHER IN THE PAST than after_time (and optionally after_trade)
14
- * With "prev" set, you will request 30 trades that were completed MORE RECENTLY than after_time (and optionally after_trade)
15
- */
16
-
17
- /**
18
- * @deprecated Use GetTradeHistory instead: https://lab.xpaw.me/steam_api_documentation.html#IEconService_GetTradeHistory_v1
19
- * @param {object} options
20
- * @param {function} callback
21
- */
22
- SteamCommunity.prototype.getInventoryHistory = function(options, callback) {
23
- if (typeof options === 'function') {
24
- callback = options;
25
- options = {};
26
- }
27
-
28
- options.direction = options.direction || "past";
29
-
30
- var qs = "?l=english";
31
- if (options.startTime) {
32
- if (options.startTime instanceof Date) {
33
- options.startTime = Math.floor(options.startTime.getTime() / 1000);
34
- }
35
-
36
- qs += "&after_time=" + options.startTime;
37
-
38
- if (options.startTrade) {
39
- qs += "&after_trade=" + options.startTrade;
40
- }
41
- }
42
-
43
- if (options.direction == "future") {
44
- qs += "&prev=1";
45
- }
46
-
47
- this._myProfile("inventoryhistory" + qs, null, function(err, response, body) {
48
- if (err) {
49
- callback(err);
50
- return;
51
- }
52
-
53
- var output = {};
54
- var vanityURLs = [];
55
-
56
- var $ = Cheerio.load(body);
57
- if (!$('.inventory_history_pagingrow').html()) {
58
- callback(new Error("Malformed page: no paging row found"));
59
- return;
60
- }
61
-
62
- // Load the inventory item data
63
- var match2 = body.match(/var g_rgHistoryInventory = (.*);/);
64
- if (!match2) {
65
- callback(new Error("Malformed page: no trade found"));
66
- return;
67
- }
68
-
69
- try {
70
- var historyInventory = JSON.parse(match2[1]);
71
- } catch (ex) {
72
- callback(new Error("Malformed page: no well-formed trade data found"));
73
- return;
74
- }
75
-
76
- var i;
77
-
78
- // See if we've got paging buttons
79
- var $paging = $('.inventory_history_nextbtn .pagebtn:not(.disabled)');
80
- var href;
81
- for (i = 0; i < $paging.length; i++) {
82
- href = $paging[i].attribs.href;
83
- if (href.match(/prev=1/)) {
84
- output.firstTradeTime = new Date(href.match(/after_time=(\d+)/)[1] * 1000);
85
- output.firstTradeID = href.match(/after_trade=(\d+)/)[1];
86
- } else {
87
- output.lastTradeTime = new Date(href.match(/after_time=(\d+)/)[1] * 1000);
88
- output.lastTradeID = href.match(/after_trade=(\d+)/)[1];
89
- }
90
- }
91
-
92
- output.trades = [];
93
- var trades = $('.tradehistoryrow');
94
-
95
- var item, trade, profileLink, items, j, econItem, timeMatch, time;
96
- for (i = 0; i < trades.length; i++) {
97
- item = $(trades[i]);
98
- trade = {};
99
-
100
- trade.onHold = !!item.find('span:nth-of-type(2)').text().match(/Trade on Hold/i);
101
-
102
- timeMatch = item.find('.tradehistory_timestamp').html().match(/(\d+):(\d+)(am|pm)/);
103
- if (timeMatch[1] == 12 && timeMatch[3] == 'am') {
104
- timeMatch[1] = 0;
105
- }
106
-
107
- if (timeMatch[1] < 12 && timeMatch[3] == 'pm') {
108
- timeMatch[1] = parseInt(timeMatch[1], 10) + 12;
109
- }
110
-
111
- time = (timeMatch[1] < 10 ? '0' : '') + timeMatch[1] + ':' + timeMatch[2] + ':00';
112
-
113
- trade.date = new Date(item.find('.tradehistory_date').html() + ' ' + time + ' UTC');
114
- trade.partnerName = item.find('.tradehistory_event_description a').html();
115
- trade.partnerSteamID = null;
116
- trade.partnerVanityURL = null;
117
- trade.itemsReceived = [];
118
- trade.itemsGiven = [];
119
-
120
- profileLink = item.find('.tradehistory_event_description a').attr('href');
121
- if (profileLink.indexOf('/profiles/') != -1) {
122
- trade.partnerSteamID = new SteamID(profileLink.match(/(\d+)$/)[1]);
123
- } else {
124
- trade.partnerVanityURL = profileLink.match(/\/([^\/]+)$/)[1];
125
- if (options.resolveVanityURLs && vanityURLs.indexOf(trade.partnerVanityURL) == -1) {
126
- vanityURLs.push(trade.partnerVanityURL);
127
- }
128
- }
129
-
130
- items = item.find('.history_item');
131
- for (j = 0; j < items.length; j++) {
132
- match = body.match(new RegExp("HistoryPageCreateItemHover\\( '" + $(items[j]).attr('id') + "', (\\d+), '(\\d+)', '(\\d+|class_\\d+_instance_\\d+|class_\\d+)', '(\\d+)' \\);"));
133
- econItem = historyInventory[match[1]][match[2]][match[3]];
134
-
135
- if ($(items[j]).attr('id').indexOf('received') != -1) {
136
- trade.itemsReceived.push(new CEconItem(econItem));
137
- } else {
138
- trade.itemsGiven.push(new CEconItem(econItem));
139
- }
140
- }
141
-
142
- output.trades.push(trade);
143
- }
144
-
145
- if (options.resolveVanityURLs) {
146
- Async.map(vanityURLs, Helpers.resolveVanityURL, function(err, results) {
147
- if (err) {
148
- callback(err);
149
- return;
150
- }
151
-
152
- for (i = 0; i < output.trades.length; i++) {
153
- if (output.trades[i].partnerSteamID || !output.trades[i].partnerVanityURL) {
154
- continue;
155
- }
156
-
157
- // Find the vanity URL
158
- for (j = 0; j < results.length; j++) {
159
- if (results[j].vanityURL == output.trades[i].partnerVanityURL) {
160
- output.trades[i].partnerSteamID = new SteamID(results[j].steamID);
161
- break;
162
- }
163
- }
164
- }
165
-
166
- callback(null, output);
167
- });
168
- } else {
169
- callback(null, output);
170
- }
171
- }, "steamcommunity");
172
- };
173
-
1
+ var SteamCommunity = require('../index.js');
2
+ var CEconItem = require('../classes/CEconItem.js');
3
+ var Helpers = require('./helpers.js');
4
+ var SteamID = require('steamid');
5
+ var request = require('request');
6
+ var Cheerio = require('cheerio');
7
+ var Async = require('async');
8
+
9
+ /*
10
+ * Inventory history in a nutshell.
11
+ *
12
+ * There are no more page numbers. Now you have to request after_time and optionally after_trade.
13
+ * Without "prev" set, you will request 30 trades that were completed FURTHER IN THE PAST than after_time (and optionally after_trade)
14
+ * With "prev" set, you will request 30 trades that were completed MORE RECENTLY than after_time (and optionally after_trade)
15
+ */
16
+
17
+ /**
18
+ * @deprecated Use GetTradeHistory instead: https://lab.xpaw.me/steam_api_documentation.html#IEconService_GetTradeHistory_v1
19
+ * @param {object} options
20
+ * @param {function} callback
21
+ */
22
+ SteamCommunity.prototype.getInventoryHistory = function(options, callback) {
23
+ if (typeof options === 'function') {
24
+ callback = options;
25
+ options = {};
26
+ }
27
+
28
+ options.direction = options.direction || "past";
29
+
30
+ var qs = "?l=english";
31
+ if (options.startTime) {
32
+ if (options.startTime instanceof Date) {
33
+ options.startTime = Math.floor(options.startTime.getTime() / 1000);
34
+ }
35
+
36
+ qs += "&after_time=" + options.startTime;
37
+
38
+ if (options.startTrade) {
39
+ qs += "&after_trade=" + options.startTrade;
40
+ }
41
+ }
42
+
43
+ if (options.direction == "future") {
44
+ qs += "&prev=1";
45
+ }
46
+
47
+ this._myProfile("inventoryhistory" + qs, null, function(err, response, body) {
48
+ if (err) {
49
+ callback(err);
50
+ return;
51
+ }
52
+
53
+ var output = {};
54
+ var vanityURLs = [];
55
+
56
+ var $ = Cheerio.load(body);
57
+ if (!$('.inventory_history_pagingrow').html()) {
58
+ callback(new Error("Malformed page: no paging row found"));
59
+ return;
60
+ }
61
+
62
+ // Load the inventory item data
63
+ var match2 = body.match(/var g_rgHistoryInventory = (.*);/);
64
+ if (!match2) {
65
+ callback(new Error("Malformed page: no trade found"));
66
+ return;
67
+ }
68
+
69
+ try {
70
+ var historyInventory = JSON.parse(match2[1]);
71
+ } catch (ex) {
72
+ callback(new Error("Malformed page: no well-formed trade data found"));
73
+ return;
74
+ }
75
+
76
+ var i;
77
+
78
+ // See if we've got paging buttons
79
+ var $paging = $('.inventory_history_nextbtn .pagebtn:not(.disabled)');
80
+ var href;
81
+ for (i = 0; i < $paging.length; i++) {
82
+ href = $paging[i].attribs.href;
83
+ if (href.match(/prev=1/)) {
84
+ output.firstTradeTime = new Date(href.match(/after_time=(\d+)/)[1] * 1000);
85
+ output.firstTradeID = href.match(/after_trade=(\d+)/)[1];
86
+ } else {
87
+ output.lastTradeTime = new Date(href.match(/after_time=(\d+)/)[1] * 1000);
88
+ output.lastTradeID = href.match(/after_trade=(\d+)/)[1];
89
+ }
90
+ }
91
+
92
+ output.trades = [];
93
+ var trades = $('.tradehistoryrow');
94
+
95
+ var item, trade, profileLink, items, j, econItem, timeMatch, time;
96
+ for (i = 0; i < trades.length; i++) {
97
+ item = $(trades[i]);
98
+ trade = {};
99
+
100
+ trade.onHold = !!item.find('span:nth-of-type(2)').text().match(/Trade on Hold/i);
101
+
102
+ timeMatch = item.find('.tradehistory_timestamp').html().match(/(\d+):(\d+)(am|pm)/);
103
+ if (timeMatch[1] == 12 && timeMatch[3] == 'am') {
104
+ timeMatch[1] = 0;
105
+ }
106
+
107
+ if (timeMatch[1] < 12 && timeMatch[3] == 'pm') {
108
+ timeMatch[1] = parseInt(timeMatch[1], 10) + 12;
109
+ }
110
+
111
+ time = (timeMatch[1] < 10 ? '0' : '') + timeMatch[1] + ':' + timeMatch[2] + ':00';
112
+
113
+ trade.date = new Date(item.find('.tradehistory_date').html() + ' ' + time + ' UTC');
114
+ trade.partnerName = item.find('.tradehistory_event_description a').html();
115
+ trade.partnerSteamID = null;
116
+ trade.partnerVanityURL = null;
117
+ trade.itemsReceived = [];
118
+ trade.itemsGiven = [];
119
+
120
+ profileLink = item.find('.tradehistory_event_description a').attr('href');
121
+ if (profileLink.indexOf('/profiles/') != -1) {
122
+ trade.partnerSteamID = new SteamID(profileLink.match(/(\d+)$/)[1]);
123
+ } else {
124
+ trade.partnerVanityURL = profileLink.match(/\/([^\/]+)$/)[1];
125
+ if (options.resolveVanityURLs && vanityURLs.indexOf(trade.partnerVanityURL) == -1) {
126
+ vanityURLs.push(trade.partnerVanityURL);
127
+ }
128
+ }
129
+
130
+ items = item.find('.history_item');
131
+ for (j = 0; j < items.length; j++) {
132
+ match = body.match(new RegExp("HistoryPageCreateItemHover\\( '" + $(items[j]).attr('id') + "', (\\d+), '(\\d+)', '(\\d+|class_\\d+_instance_\\d+|class_\\d+)', '(\\d+)' \\);"));
133
+ econItem = historyInventory[match[1]][match[2]][match[3]];
134
+
135
+ if ($(items[j]).attr('id').indexOf('received') != -1) {
136
+ trade.itemsReceived.push(new CEconItem(econItem));
137
+ } else {
138
+ trade.itemsGiven.push(new CEconItem(econItem));
139
+ }
140
+ }
141
+
142
+ output.trades.push(trade);
143
+ }
144
+
145
+ if (options.resolveVanityURLs) {
146
+ Async.map(vanityURLs, Helpers.resolveVanityURL, function(err, results) {
147
+ if (err) {
148
+ callback(err);
149
+ return;
150
+ }
151
+
152
+ for (i = 0; i < output.trades.length; i++) {
153
+ if (output.trades[i].partnerSteamID || !output.trades[i].partnerVanityURL) {
154
+ continue;
155
+ }
156
+
157
+ // Find the vanity URL
158
+ for (j = 0; j < results.length; j++) {
159
+ if (results[j].vanityURL == output.trades[i].partnerVanityURL) {
160
+ output.trades[i].partnerSteamID = new SteamID(results[j].steamID);
161
+ break;
162
+ }
163
+ }
164
+ }
165
+
166
+ callback(null, output);
167
+ });
168
+ } else {
169
+ callback(null, output);
170
+ }
171
+ }, "steamcommunity");
172
+ };
173
+