DoctorMcKay / node-steamcommunity

Interact with various interfaces on Steam Community from Node.js
https://dev.doctormckay.com/forum/8-node-steamcommunity/
MIT License
475 stars 128 forks source link

Include unsupported fields in separate CEconItem property #229

Closed andrewda closed 5 years ago

andrewda commented 5 years ago

Per #224 and #194, non game-agnostic properties should not be included in CEconItem, which makes complete sense. However, it might be beneficial to add something like an auxiliary property which contains everything included in the inventory response that doesn't fit an existing property. This way, non game-agnostic properties can be included in a game-agnostic way, and used when desired without cluttering the normal CEconItem.

For example, CS:GO adds a cache_expiration property to items in trade lock, so that would be included in CEconItem like so:

CEconItem {
    market_hash_name: "P250 | Sand Dune (Minimal Wear)",
    ...
    auxiliary: {
        cache_expiration: "2019-09-28T07:00:00Z"
    }
}

In essence, this makes it so that users who require game-specific properties can access them easily without cluttering CEconItem with game-specific logic or variables.

I'd be more than happy to implement this if desired.

DoctorMcKay commented 5 years ago

If you're talking about the cache_expiration property available on Steam item objects, that's not a CS:GO-specific property. It's a generic Steam property that all games can use. Steam coupons use it for when they expire, for example.

As for your proposal, I think I would rather leave it up to external modules to do stuff like this. For example, you could create a package steam-csgo-item-parser or something that you pass a CEconItem object to and it could return what you're interested in.

andrewda commented 5 years ago

Sounds good. Is there a reason cache_expiration isn't included in CEconItem if it's not game-specific?

DoctorMcKay commented 5 years ago

It doesn't exist if it's not set for a particular item.

We could create it and set it null if it doesn't exist, but I don't see how that's significantly helpful.

andrewda commented 5 years ago

My inventory contains the following item (from /json/730/2, truncated for readability):

"3529226655_302028390": {
    "appid": "730",
    "classid": "3529226655",
    "instanceid": "302028390",
    "name": "UMP-45 | Scorched",
    "market_hash_name": "UMP-45 | Scorched (Field-Tested)",
    "type": "Consumer Grade SMG",
    "tradable": 0,
    "marketable": 1,
    "commodity": 0,
    "market_tradable_restriction": "7",
    "cache_expiration": "2019-09-28T07:00:00Z"
}

However, the corresponding CEconItem looks like this:

CEconItem {
  appid: 730,
  contextid: '2',
  assetid: '16795134774',
  classid: '3529226655',
  instanceid: '302028390',
  amount: 1,
  pos: 1,
  id: '16795134774',
  background_color: '',
  descriptions:
   [ { type: 'html', value: 'Exterior: Field-Tested' },
     { type: 'html', value: ' ' },
     { type: 'html',
       value:
        'The misunderstood middle child of the SMG family, the UMP45\'s small magazine is the only drawback to an otherwise versatile close-quarters automatic. It has been spray-pa
inted in a sun-dappled pattern.\n\n<i>The Phoenix is not a symbol of destruction... it\'s a symbol of rebirth - Valeria Jenner, Revolutionary</i>' },
     { type: 'html', value: ' ' },
     { type: 'html',
       value: 'The Overpass Collection',
       color: '9da1a9' },
     { type: 'html', value: ' ' } ],
  tradable: false,
  actions:
   [ { link:
        'steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S%owner_steamid%A%assetid%D10133737464838567434',
       name: 'Inspect in Game...' } ],
  name: 'UMP-45 | Scorched',
  name_color: 'D2D2D2',
  type: 'Consumer Grade SMG',
  market_name: 'UMP-45 | Scorched (Field-Tested)',
  market_hash_name: 'UMP-45 | Scorched (Field-Tested)',
  market_actions:
   [ { link:
        'steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D10133737464838567434',
       name: 'Inspect in Game...' } ],
  commodity: false,
  market_tradable_restriction: 7,
  marketable: true,
  tags:
   [ { internal_name: 'CSGO_Type_SMG',
       name: 'SMG',
       category: 'Type',
       color: '',
       category_name: 'Type' },
     { internal_name: 'weapon_ump45',
       name: 'UMP-45',
       category: 'Weapon',
       color: '',
       category_name: 'Weapon' },
     { internal_name: 'set_overpass',
       name: 'The Overpass Collection',
       category: 'ItemSet',
       color: '',
       category_name: 'Collection' },
     { internal_name: 'normal',
       name: 'Normal',
       category: 'Quality',
       color: '',
       category_name: 'Category' },
     { internal_name: 'Rarity_Common_Weapon',
       name: 'Consumer Grade',
       category: 'Rarity',
       color: 'b0c3d9',
       category_name: 'Quality' },
     { internal_name: 'WearCategory2',
       name: 'Field-Tested',
       category: 'Exterior',
       color: '',
       category_name: 'Exterior' } ],
  is_currency: false,
  market_marketable_restriction: 0,
  fraudwarnings: [] }

Call me crazy, but I don't seem to see cache_expiration anywhere in the CEconItem, despite its presence on the item in my inventory.

DoctorMcKay commented 5 years ago

Curious. It looks like cache_expiration is missing from /inventory/steamid/appid/contextid, but is present on /profiles/steamid/inventory/json/appid/contextid. For backwards compatibility's sake, I'm willing to fudge that property for CS:GO items, I suppose, since it technically does exist but Steam is hiding it from us. Let me see what I can do.

DoctorMcKay commented 5 years ago

https://github.com/DoctorMcKay/node-steamcommunity/releases/tag/v3.40.2

andrewda commented 5 years ago

Thanks for the quick fix! Looks perfect.