steamapi

repository·master·Indexed 41 days ago

https://github.com/xdimgg/node-steamapi

A Node.js and TypeScript wrapper for the Steam Web API. It provides methods for resolving Steam IDs, fetching user profiles, achievements, and stats, as well as retrieving game details, store data, and server information. Version 3.1.5 supports ES Modules and includes built-in in-memory caching for game details and user resolution.

Tokens
18K
Snippets
54
Records
95
Agent score
42%

What's inside steamapi

  1. Overview of steamapi

    master

    The steamapi package provides a TypeScript interface for interacting with various Steam API endpoints. It allows developers to retrieve data regarding games, servers, user profiles, achievements, badges, and more. The library is organized into several core components:

    • Classes: Represent major data entities and service providers (e.g., Game, UserSummary, UserAchievements, GameServer).
    • Interfaces: Define the shape of configuration objects and data responses (e.g., SteamAPIOptions, GetGameNewsOptions).
    • Enumerations: Provide type-safe constants for specific Steam states (e.g., ServerRegion, UserPersonaState).
    • Type Aliases: Define common types used throughout the library (e.g., Currency, Language).
  2. Accessing game media URLs

    master
    The GameDetails object provides several ways to access visual assets. For thumbnails, use capsuleImage or capsuleImagev5. For high-quality backgrounds, use backgroundRaw. For video content, the movies array provides access to both mp4 and webm formats at different resolutions (e.g., 480 and max).
  3. Understanding game pricing and discounts

    master

    Pricing information is encapsulated in the priceOverview object. This object provides both raw numeric values and human-readable formatted strings, which is useful for displaying prices in different locales. It also includes the discountPercent to easily calculate or display sales.

    // Example of accessing price data
    const price = gameDetails.priceOverview;
    console.log(`Price: ${price.finalFormatted} (Discount: ${price.discountPercent}%)`);
  4. Migrating from SteamAPI 2.x to 3.x

    master

    If upgrading from version 2.x, note the following breaking changes:

    • Module System: Switched from CommonJS (require) to ES Modules (import).
    • Constructor: The first parameter is now false if no key is provided. Options object keys have changed significantly (see configuration record).
    • Caching: To use custom caching, set inMemoryCacheEnabled: false and implement the CacheMap<K, V> interface for <SteamAPI>.gameDetailCache or <SteamAPI>.userResolveCache.
    • Return Types: getFeaturedGames() now returns an object instead of an array.
    • Property Renaming: Server#game is now Server#gameDir.
    • Parameter Types: App IDs should be passed as numbers rather than strings.
  5. Configure SteamAPI constructor options

    master

    The SteamAPI constructor accepts an options object. In version 3.x, the available configuration keys are:

    • language: The language for API requests.
    • currency: The currency for API requests.
    • headers: Custom HTTP headers.
    • baseAPI: Custom base API URL.
    • baseStore: Custom base store URL.
    • baseActions: Custom base actions URL.
    • inMemoryCacheEnabled: Boolean to enable/disable in-memory caching.
    • gameDetailCacheEnabled: Boolean to enable/disable game detail caching.
    • gameDetailCacheTTL: Time-to-live for game detail cache.
    • userResolveCacheEnabled: Boolean to enable/disable user resolve caching.
    • userResolveCacheTTL: Time-to-live for user resolve cache.
  6. Use the UserSummary class

    master

    The UserSummary class provides a structured representation of a Steam user's profile information, including their identity, status, and current activity. It extends the base User class.

    To instantiate a UserSummary, pass a data object to the constructor.

    Key features:

    • Identity: Access steamID, nickname, and url.
    • Status: Check visible (profile visibility), personaState (online/offline status), and allowsComments.
    • Activity: Retrieve current game information via gameID and gameName, or server details via gameServerID and gameServerIP.
    • Timestamps: Use the createdAt and lastLogOffAt accessors to get JavaScript Date objects instead of raw Unix timestamps.
    // Example instantiation (assuming data is fetched from the API)
    const userSummary = new UserSummary(apiResponseData);
    
    console.log(userSummary.nickname);
    console.log(userSummary.createdAt); // Returns a Date object or undefined
  7. Configure SteamAPI with SteamAPIOptions

    master
    When initializing the SteamAPI class, you can pass an optional SteamAPIOptions object to customize the behavior of the client. This includes setting base URLs for different Steam services, configuring default localization (language and currency), managing custom HTTP headers, and controlling the built-in in-memory caching system.
  8. Instantiate the UserServer class

    master

    The UserServer class represents a game server instance within the Steam API. You can create a new instance by passing a data object (of type any) to the constructor. This object should contain the raw server data returned from the Steam API.

    const userServer = new UserServer(rawData);
  9. Initialize the SteamAPI client

    master

    To use the library, create a new instance of the SteamAPI class using the new default() constructor.

    Parameters

    • key: A string representing your Steam API key. You can generate one at https://steamcommunity.com/dev/apikey. If you wish to make requests without an API key, pass false.
    • options: An optional SteamAPIOptions object used to configure the default language, HTTP parameters, and caching behavior.
    import { SteamAPI } from 'steamapi';
    
    // Using an API key
    const api = new SteamAPI('YOUR_API_KEY_HERE');
    
    // Making requests without an API key
    const apiNoKey = new SteamAPI(false);
    
    // Using custom options
    const apiWithOptions = new SteamAPI('YOUR_API_KEY_HERE', {
      language: 'english',
      // other SteamAPIOptions properties
    });
  10. Use the UserBans class to check user ban status

    master

    The UserBans class provides detailed information regarding a user's ban history on Steam. It can be instantiated with a data object containing the relevant ban information.

    Key properties include:

    • communityBanned: boolean indicating if the user is community banned.
    • vacBanned: boolean indicating if the user is VAC banned.
    • economyBan: string representing the economy ban status (e.g., 'none', 'probation').
    • gameBans: number representing the total count of game bans.
    • vacBans: number representing the total count of VAC bans.
    • daysSinceLastBan: number representing the days elapsed since the last ban.
    • steamID: string (inherited from User) identifying the user.
    // Example instantiation (assuming data is provided by the API client)
    const userBans = new UserBans(banData);
    
    console.log(userBans.vacBanned);
    console.log(userBans.economyBan);