steamutils 1.5.49 → 1.5.51
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.
- package/index.js +67 -16
- package/package.json +1 -1
- package/remote.js +2503 -2268
package/index.js
CHANGED
@@ -5,7 +5,7 @@ import moment from "moment";
|
|
5
5
|
import { hex2b64, Key as RSA } from "node-bignumber";
|
6
6
|
import SteamID from "steamid";
|
7
7
|
import qs from "qs";
|
8
|
-
import { console_log, convertLongsToNumbers, downloadImage, formatMarketHistoryDate, getCleanObject, getImageSize, isJWT, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
8
|
+
import { console_log, convertLongsToNumbers, downloadImage, formatMarketCurrency, formatMarketHistoryDate, getCleanObject, getImageSize, getMarketPriceValueAsInt, isJWT, JSON_parse, JSON_stringify, removeSpaceKeys, secretAsBuffer, sleep } from "./utils.js";
|
9
9
|
import { Header, request } from "./axios.js";
|
10
10
|
import { getTableHasHeaders, querySelectorAll, table2json } from "./cheerio.js";
|
11
11
|
import { getJSObjectFronXML } from "./xml2json.js";
|
@@ -6262,10 +6262,27 @@ export default class SteamUser {
|
|
6262
6262
|
}
|
6263
6263
|
}
|
6264
6264
|
|
6265
|
+
/**
|
6266
|
+
* Sells an item from the user's inventory on the Steam market.
|
6267
|
+
*
|
6268
|
+
* @param {Object} options - The item selling options.
|
6269
|
+
* @param {number} [options.appid=730] - The application ID (default is 730).
|
6270
|
+
* @param {number} [options.contextid=2] - The inventory context ID (default is 2).
|
6271
|
+
* @param {string|number} options.assetid - The asset ID of the item to sell.
|
6272
|
+
* @param {number} [options.amount=1] - The number of items to sell (default is 1).
|
6273
|
+
* @param {number|string} options.price - The price at which to list the item.
|
6274
|
+
* @returns {Promise<{
|
6275
|
+
* success: boolean,
|
6276
|
+
* requires_confirmation: number,
|
6277
|
+
* needs_mobile_confirmation: boolean,
|
6278
|
+
* needs_email_confirmation: boolean,
|
6279
|
+
* email_domain: string
|
6280
|
+
* } | null>} An object with the sale result and required confirmations, or null if input is invalid or request fails.
|
6281
|
+
*/
|
6265
6282
|
async sellItem({ appid = 730, contextid = 2, assetid, amount = 1, price }) {
|
6266
6283
|
price = parseInt(price);
|
6267
6284
|
if (!price) {
|
6268
|
-
return;
|
6285
|
+
return null;
|
6269
6286
|
}
|
6270
6287
|
|
6271
6288
|
const result = await this._httpRequestAjax({
|
@@ -6285,18 +6302,10 @@ export default class SteamUser {
|
|
6285
6302
|
});
|
6286
6303
|
|
6287
6304
|
if (result instanceof ResponseError) {
|
6288
|
-
return
|
6305
|
+
return null;
|
6289
6306
|
}
|
6290
6307
|
|
6291
6308
|
return result?.data;
|
6292
|
-
|
6293
|
-
const resultExample = {
|
6294
|
-
success: true,
|
6295
|
-
requires_confirmation: 1,
|
6296
|
-
needs_mobile_confirmation: true,
|
6297
|
-
needs_email_confirmation: false,
|
6298
|
-
email_domain: "gmail.com",
|
6299
|
-
};
|
6300
6309
|
}
|
6301
6310
|
|
6302
6311
|
async removeListing(id) {
|
@@ -6770,20 +6779,62 @@ export default class SteamUser {
|
|
6770
6779
|
return friendSince;
|
6771
6780
|
}
|
6772
6781
|
|
6782
|
+
/**
|
6783
|
+
* Retrieves the Steam Wallet balances (main and pending) and the account currency
|
6784
|
+
* for the currently authenticated user by parsing the wallet info from the profile HTML.
|
6785
|
+
*
|
6786
|
+
* @async
|
6787
|
+
* @returns {Promise<{mainBalance: string|null, pending: string|null, currency: string|null}|undefined>}
|
6788
|
+
* A Promise that resolves to an object containing:
|
6789
|
+
* - mainBalance: The main wallet balance as a string (e.g., "276.400,82₫"), or null if not found.
|
6790
|
+
* - pending: The pending wallet balance as a string (e.g., "90.176,70₫"), or null if not found.
|
6791
|
+
* - currency: The detected currency symbol or code (e.g., "₫", "€", "$", "TL"), or null if not found.
|
6792
|
+
* The function returns undefined if an error occurs or valid HTML is not available.
|
6793
|
+
*
|
6794
|
+
* @example
|
6795
|
+
* const { mainBalance, pending, currency } = await getWalletBalance();
|
6796
|
+
* console.log(mainBalance); // e.g., "276.400,82₫"
|
6797
|
+
* console.log(pending); // e.g., "90.176,70₫"
|
6798
|
+
* console.log(currency); // e.g., "₫"
|
6799
|
+
*/
|
6773
6800
|
async getWalletBalance() {
|
6774
6801
|
const result = await this._httpRequest(`my?l=english`);
|
6775
6802
|
if (result instanceof ResponseError) {
|
6776
|
-
return
|
6803
|
+
return;
|
6777
6804
|
}
|
6778
6805
|
const html = result?.data;
|
6779
6806
|
if (!html || typeof html !== "string") {
|
6780
6807
|
return;
|
6781
6808
|
}
|
6782
6809
|
const $ = cheerio.load(html);
|
6783
|
-
|
6784
|
-
|
6785
|
-
|
6786
|
-
|
6810
|
+
|
6811
|
+
const mainBalance = $("#header_wallet_balance").clone().children().remove().end().text().trim() || null;
|
6812
|
+
|
6813
|
+
let currency = null;
|
6814
|
+
if (mainBalance) {
|
6815
|
+
// This regex matches all non-digit, non-comma, non-dot characters at the end (currency symbol/code)
|
6816
|
+
// Handles "12,34€", "$12.34", "12,34 TL", etc.
|
6817
|
+
const m = mainBalance.match(/([^\d.,\s].*)$/);
|
6818
|
+
if (m) currency = m[1].trim();
|
6819
|
+
else {
|
6820
|
+
// fallback for prefix (e.g. "$12.34")
|
6821
|
+
const m2 = mainBalance.match(/^([^\d.,\s]+)/);
|
6822
|
+
if (m2) currency = m2[1].trim();
|
6823
|
+
}
|
6824
|
+
}
|
6825
|
+
|
6826
|
+
let pendingStr = $("#header_wallet_balance span.tooltip").text();
|
6827
|
+
let pending = null;
|
6828
|
+
if (pendingStr) {
|
6829
|
+
const match = pendingStr.match(/Pending:\s*([\d.,]+[^\s]*)/);
|
6830
|
+
if (match) pending = match[1];
|
6831
|
+
}
|
6832
|
+
|
6833
|
+
return {
|
6834
|
+
mainBalance,
|
6835
|
+
pending,
|
6836
|
+
currency,
|
6837
|
+
};
|
6787
6838
|
}
|
6788
6839
|
|
6789
6840
|
async acceptConfirmationForObject(accessToken, identitySecret, objectID) {
|