Slate
π Table of Contents
Introduction
Slate is a simple modular library to represent Steam trade offers using @automatedtf/sherpa
in a standardised compact data object called an OfferArtifact
; this format is optimised for archiving trade offers within a database.
π Getting Started
You can install this module with npm within your project by running the command:
npm install @automatedtf/slate
Parsing to an OfferArtifact
This module exposes one function: parseToOfferArtifact
.
const steamid: string = "76561198081082634";
const offer: TradeOffer = { ... };
const artifact: OfferArtifact = await parseToOfferArtifact(steamid, offer);
The OfferArtifact Type
The OfferArtifact
type is the primary datatype you will be working with when interacting with this module.
type OfferArtifact = {
id?: string;
message?: string;
state: OfferState;
created: number;
updated: number;
expires: number;
escrowEnds?: number;
sender: string;
recipient: string;
itemsSending: ItemInstance[];
itemsReceiving: ItemInstance[];
}
ItemInstance
The itemsSending
and itemsReceiving
field of OfferArtifact
are both arrays of objects of the interface ItemInstance
. This is an interface that is derived from @automatedtf/sherpa
.
interface ItemInstance {
appid: number;
assetid: string;
instanceid: string;
classid: string;
icon_url: string;
sku: string;
full_sku: string;
}
π See @automatedtf/sherpa
ItemInstance
Information Population with Sherpa
To provide sufficient item details, @automatedtf/sherpa
is used to populate every item under itemsSending
and itemsReceiving
. Originally, the input TradeOffer
object from steam-tradeoffer-manager
will represent each item within itemsToGive
and itemsToReceive
as a TradeItem
.
interface TradeItem {
appid: number;
contextid: string;
assetid: string;
classid: string;
instanceid: string;
...
descriptions: any[],
...
tags: any[],
tradable: boolean,
...
}
This may be insufficient to developers who may like e.g the icon_url
of an item to quickly display the item visually on their website without making further API calls on-the-fly.
This is resolved by taking the TradeOffer
object from and extracting the
least but necessary fields of a TradeItem
into an ItemInstance
by using Catalog
to represent item types and customisations as a single-string SKU
and Sherpa
to provide item instance information. This is all done as a TradeOffer
is parsed to an OfferArtifact
.
π Helpful Resources