cs2-inspect-lib
Version:
Enhanced CS2 Inspect URL library with full protobuf support, validation, and error handling
463 lines • 16.9 kB
JavaScript
"use strict";
/**
* CS2 Inspect URL Library - Enhanced Version
*
* A comprehensive TypeScript library for encoding and decoding CS2 inspect URLs
* with full protobuf support, validation, and error handling.
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LIBRARY_INFO = exports.VERSION = exports.cs2inspect = exports.isValidUrl = exports.normalizeUrl = exports.requiresSteamClient = exports.decodeMaskedData = exports.analyzeUrl = exports.validateUrl = exports.validateItem = exports.decodeInspectUrlAsync = exports.inspectItem = exports.decodeInspectUrl = exports.decodeMaskedUrl = exports.createInspectUrl = exports.CS2Inspect = exports.SteamClientManager = exports.SteamClient = exports.Protobuf = exports.ProtobufWriter = exports.ProtobufReader = exports.Validator = void 0;
// Export all types
__exportStar(require("./types"), exports);
__exportStar(require("./weapon-paints"), exports);
// Export error classes
__exportStar(require("./errors"), exports);
// Export validation utilities
var validation_1 = require("./validation");
Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return validation_1.Validator; } });
// Export protobuf classes and static methods
var protobuf_reader_1 = require("./protobuf-reader");
Object.defineProperty(exports, "ProtobufReader", { enumerable: true, get: function () { return protobuf_reader_1.ProtobufReader; } });
var protobuf_writer_1 = require("./protobuf-writer");
Object.defineProperty(exports, "ProtobufWriter", { enumerable: true, get: function () { return protobuf_writer_1.ProtobufWriter; } });
// Export direct protobuf methods for convenience
var protobuf_reader_2 = require("./protobuf-reader");
Object.defineProperty(exports, "Protobuf", { enumerable: true, get: function () { return protobuf_reader_2.ProtobufReader; } });
// Export URL utilities
__exportStar(require("./url-analyzer"), exports);
// Export Steam client utilities
var steam_client_1 = require("./steam-client");
Object.defineProperty(exports, "SteamClient", { enumerable: true, get: function () { return steam_client_1.SteamClient; } });
var steam_client_manager_1 = require("./steam-client-manager");
Object.defineProperty(exports, "SteamClientManager", { enumerable: true, get: function () { return steam_client_manager_1.SteamClientManager; } });
// Main API class
const types_1 = require("./types");
const protobuf_reader_3 = require("./protobuf-reader");
const protobuf_writer_2 = require("./protobuf-writer");
const url_analyzer_1 = require("./url-analyzer");
const validation_2 = require("./validation");
const steam_client_manager_2 = require("./steam-client-manager");
/**
* Main CS2 Inspect URL API class
*/
class CS2Inspect {
constructor(config = {}) {
this.config = { ...types_1.DEFAULT_CONFIG, ...config };
this.urlAnalyzer = new url_analyzer_1.UrlAnalyzer(this.config);
this.steamManager = new steam_client_manager_2.SteamClientManager(this.config.steamClient);
}
/**
* Creates an inspect URL from an EconItem
*
* @param item - The item data to encode
* @returns The generated inspect URL
*
* @example
* ```typescript
* const cs2 = new CS2Inspect();
* const item: EconItem = {
* defindex: WeaponType.AK_47,
* paintindex: 44, // Fire Serpent
* paintseed: 661,
* paintwear: 0.15
* };
* const url = cs2.createInspectUrl(item);
* ```
*/
createInspectUrl(item) {
return protobuf_writer_2.ProtobufWriter.createInspectUrl(item, this.config);
}
/**
* Decodes a MASKED inspect URL into an EconItem (synchronous, offline)
*
* ⚠️ ONLY works with MASKED URLs (URLs containing encoded protobuf data)
* ❌ Does NOT work with UNMASKED URLs (market/inventory links) - use inspectItem() instead
*
* @param url - The MASKED inspect URL to decode
* @returns The decoded item data
* @throws Error if URL is unmasked or invalid
*
* @example
* ```typescript
* const cs2 = new CS2Inspect();
* // This works - masked URL with protobuf data
* const maskedUrl = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20001807A8...";
* const item = cs2.decodeMaskedUrl(maskedUrl);
*
* // This will throw an error - unmasked URL
* const unmaskedUrl = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198123456789A987654321D456789123";
* // cs2.decodeMaskedUrl(unmaskedUrl); // ❌ Throws error
* ```
*/
decodeMaskedUrl(url) {
const analyzed = this.urlAnalyzer.analyzeInspectUrl(url);
if (analyzed.url_type === 'masked' && analyzed.hex_data) {
return protobuf_reader_3.ProtobufReader.decodeMaskedData(analyzed.hex_data, this.config);
}
if (analyzed.url_type === 'unmasked') {
throw new Error('This is an unmasked URL (market/inventory link). Use inspectItem() instead for Steam client inspection.');
}
throw new Error('Invalid URL format or missing data');
}
/**
* Decodes a MASKED inspect URL into an EconItem (synchronous, offline)
*
* @deprecated Use decodeMaskedUrl() instead for clearer naming
* @param url - The MASKED inspect URL to decode
* @returns The decoded item data
*/
decodeInspectUrl(url) {
return this.decodeMaskedUrl(url);
}
/**
* Analyzes an inspect URL structure
*
* @param url - The URL to analyze
* @returns Analyzed URL information
*/
analyzeUrl(url) {
return this.urlAnalyzer.analyzeInspectUrl(url);
}
/**
* Validates an EconItem
*
* @param item - The item to validate
* @returns Validation result
*/
validateItem(item) {
return validation_2.Validator.validateEconItem(item);
}
/**
* Validates an inspect URL
*
* @param url - The URL to validate
* @returns Validation result
*/
validateUrl(url) {
return validation_2.Validator.validateInspectUrl(url);
}
/**
* Checks if a URL is a valid inspect URL
*
* @deprecated Use analyzeUrl() and check for errors instead, or use validateUrl() for detailed validation
* @param url - The URL to check
* @returns True if valid, false otherwise
*/
isValidUrl(url) {
try {
this.urlAnalyzer.analyzeInspectUrl(url);
return true;
}
catch {
return false;
}
}
/**
* Normalizes an inspect URL to standard format
*
* @param url - The URL to normalize
* @returns Normalized URL
*/
normalizeUrl(url) {
return this.urlAnalyzer.normalizeUrl(url);
}
/**
* Gets basic URL information without full decoding
*
* @param url - The URL to analyze
* @returns Basic URL information
*/
getUrlInfo(url) {
return this.urlAnalyzer.getUrlInfo(url);
}
/**
* Inspects ANY inspect URL (both masked and unmasked) - Universal method
*
* ✅ Works with MASKED URLs (decoded offline using protobuf data)
* ✅ Works with UNMASKED URLs (fetched via Steam client)
* 🔄 Automatically detects URL type and uses appropriate method
*
* @param url - Any valid inspect URL (masked or unmasked)
* @returns Promise resolving to the decoded item data
* @throws Error if Steam client is required but not available
*
* @example
* ```typescript
* const cs2 = new CS2Inspect({
* steamClient: {
* enabled: true,
* username: 'your_username',
* password: 'your_password'
* }
* });
* await cs2.initializeSteamClient();
*
* // Works with masked URLs (offline)
* const maskedUrl = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20001807A8...";
* const maskedItem = await cs2.inspectItem(maskedUrl);
*
* // Works with unmasked URLs (via Steam client)
* const unmaskedUrl = "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198123456789A987654321D456789123";
* const unmaskedItem = await cs2.inspectItem(unmaskedUrl);
* ```
*/
async inspectItem(url) {
const analyzed = this.urlAnalyzer.analyzeInspectUrl(url);
if (analyzed.url_type === 'masked' && analyzed.hex_data) {
return protobuf_reader_3.ProtobufReader.decodeMaskedData(analyzed.hex_data, this.config);
}
if (analyzed.url_type === 'unmasked') {
if (!this.steamManager.isAvailable()) {
throw new Error('Steam client is not available. Please initialize it first with initializeSteamClient()');
}
return await this.steamManager.inspectUnmaskedUrl(analyzed);
}
throw new Error('Invalid URL format or missing data');
}
/**
* Inspects ANY inspect URL (both masked and unmasked) - Universal method
*
* @deprecated Use inspectItem() instead for clearer naming
* @param url - Any valid inspect URL (masked or unmasked)
* @returns Promise resolving to the decoded item data
*/
async decodeInspectUrlAsync(url) {
return this.inspectItem(url);
}
/**
* Initialize Steam client for unmasked URL support
*
* @returns Promise that resolves when Steam client is ready
*/
async initializeSteamClient() {
await this.steamManager.initialize();
}
/**
* Check if Steam client is available and ready
*
* @returns True if Steam client is ready for inspection
*/
isSteamClientReady() {
return this.steamManager.isAvailable();
}
/**
* Get Steam client status and statistics
*
* @returns Steam client status information
*/
getSteamClientStats() {
return this.steamManager.getStats();
}
/**
* Check if a URL requires Steam client for inspection
*
* @param url - The URL to check
* @returns True if URL requires Steam client
*/
requiresSteamClient(url) {
return this.urlAnalyzer.requiresSteamClient(url);
}
/**
* Disconnect Steam client
*/
async disconnectSteamClient() {
await this.steamManager.disconnect();
}
/**
* Updates the configuration
*
* @param newConfig - New configuration options
*/
updateConfig(newConfig) {
// Handle Steam client config merging separately
if (newConfig.steamClient) {
this.config = {
...this.config,
...newConfig,
steamClient: { ...this.config.steamClient, ...newConfig.steamClient }
};
this.steamManager.updateConfig(newConfig.steamClient);
}
else {
this.config = { ...this.config, ...newConfig };
}
this.urlAnalyzer = new url_analyzer_1.UrlAnalyzer(this.config);
}
/**
* Gets current configuration
*
* @returns Current configuration
*/
getConfig() {
return { ...this.config };
}
}
exports.CS2Inspect = CS2Inspect;
/**
* Static convenience functions for quick usage without instantiating the class
* These are optimized to avoid creating unnecessary instances
*/
/**
* Creates an inspect URL from an EconItem (convenience function)
*/
function createInspectUrl(item, config) {
return protobuf_writer_2.ProtobufWriter.createInspectUrl(item, config);
}
exports.createInspectUrl = createInspectUrl;
/**
* Decodes a MASKED inspect URL into an EconItem (convenience function)
* ⚠️ ONLY works with MASKED URLs - use inspectItem() for universal support
*/
function decodeMaskedUrl(url, config) {
const cs2 = new CS2Inspect(config);
return cs2.decodeMaskedUrl(url);
}
exports.decodeMaskedUrl = decodeMaskedUrl;
/**
* Decodes a MASKED inspect URL into an EconItem (convenience function)
* @deprecated Use decodeMaskedUrl() instead for clearer naming
*/
function decodeInspectUrl(url, config) {
const cs2 = new CS2Inspect(config);
return cs2.decodeInspectUrl(url);
}
exports.decodeInspectUrl = decodeInspectUrl;
/**
* Inspects ANY inspect URL (masked or unmasked) - Universal convenience function
* Automatically handles Steam client initialization if needed
*/
async function inspectItem(url, config) {
const cs2 = new CS2Inspect(config);
if (cs2.requiresSteamClient(url)) {
await cs2.initializeSteamClient();
}
return await cs2.inspectItem(url);
}
exports.inspectItem = inspectItem;
/**
* Inspects ANY inspect URL (masked or unmasked) - Universal convenience function
* @deprecated Use inspectItem() instead for clearer naming
*/
async function decodeInspectUrlAsync(url, config) {
const cs2 = new CS2Inspect(config);
if (cs2.requiresSteamClient(url)) {
await cs2.initializeSteamClient();
}
return await cs2.decodeInspectUrlAsync(url);
}
exports.decodeInspectUrlAsync = decodeInspectUrlAsync;
/**
* Validates an EconItem (convenience function)
*/
function validateItem(item) {
return validation_2.Validator.validateEconItem(item);
}
exports.validateItem = validateItem;
/**
* Validates an inspect URL (convenience function)
*/
function validateUrl(url) {
return validation_2.Validator.validateInspectUrl(url);
}
exports.validateUrl = validateUrl;
// ============================================================================
// OPTIMIZED STATIC METHODS - No instance creation needed
// ============================================================================
/**
* Analyzes an inspect URL structure (static, optimized)
* ⚡ More efficient than creating a CS2Inspect instance
*/
function analyzeUrl(url, config) {
const analyzer = new url_analyzer_1.UrlAnalyzer(config);
return analyzer.analyzeInspectUrl(url);
}
exports.analyzeUrl = analyzeUrl;
/**
* Decodes masked protobuf data directly (static, fastest)
* ⚡ Direct access to ProtobufReader.decodeMaskedData
* 🔥 Use this for maximum performance with known hex data
*/
function decodeMaskedData(hexData, config) {
return protobuf_reader_3.ProtobufReader.decodeMaskedData(hexData, config);
}
exports.decodeMaskedData = decodeMaskedData;
/**
* Checks if URL requires Steam client (static, optimized)
* ⚡ More efficient than creating a CS2Inspect instance
*/
function requiresSteamClient(url, config) {
try {
const analyzed = analyzeUrl(url, config);
return analyzed.url_type === 'unmasked';
}
catch {
return false;
}
}
exports.requiresSteamClient = requiresSteamClient;
/**
* Normalizes an inspect URL to standard format (static, optimized)
* ⚡ More efficient than creating a CS2Inspect instance
*/
function normalizeUrl(url, config) {
const analyzer = new url_analyzer_1.UrlAnalyzer(config);
return analyzer.normalizeUrl(url);
}
exports.normalizeUrl = normalizeUrl;
/**
* Quick URL validation check (static, optimized)
* ⚡ More efficient than creating a CS2Inspect instance
* 💡 Prefer analyzeUrl() for more detailed information
*/
function isValidUrl(url, config) {
try {
analyzeUrl(url, config);
return true;
}
catch {
return false;
}
}
exports.isValidUrl = isValidUrl;
/**
* Default CS2Inspect instance for quick usage
*/
exports.cs2inspect = new CS2Inspect();
/**
* Version information
*/
exports.VERSION = '3.0.6';
/**
* Library information
*/
exports.LIBRARY_INFO = {
name: 'cs2-inspect-lib',
version: exports.VERSION,
description: 'Enhanced CS2 Inspect library with full protobuf support and Steam client integration',
features: [
'Complete protobuf encoding/decoding',
'Steam client integration for unmasked URLs',
'Support for both masked and unmasked inspect URLs',
'Input validation and error handling',
'TypeScript support with comprehensive types',
'Support for all CS2 item fields including new additions',
'URL analysis and normalization',
'Configurable validation and limits',
'Queue system with rate limiting for Steam API calls'
]
};
//# sourceMappingURL=index.js.map