@skinpricer/sdk 0.3.0 → 0.5.0
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/CHANGELOG.md +51 -0
- package/README.md +179 -16
- package/dist/index.cjs +441 -299
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1109 -625
- package/dist/index.d.ts +1109 -625
- package/dist/index.js +438 -300
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -35,8 +35,367 @@ var ConfigurationError = class extends SkinpricerError {
|
|
|
35
35
|
var ParseError = class extends SkinpricerError {
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
// src/utils/url.ts
|
|
39
|
+
function encodePathSegment(segment) {
|
|
40
|
+
return encodeURIComponent(segment);
|
|
41
|
+
}
|
|
42
|
+
function joinUrl(baseUrl, path) {
|
|
43
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
44
|
+
return `${baseUrl}${normalizedPath}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/meta.ts
|
|
48
|
+
var RESPONSE_META = /* @__PURE__ */ Symbol("skinpricer.responseMeta");
|
|
49
|
+
function attachMeta(data, meta) {
|
|
50
|
+
if (data !== null && typeof data === "object") {
|
|
51
|
+
Object.defineProperty(data, RESPONSE_META, {
|
|
52
|
+
value: meta,
|
|
53
|
+
enumerable: false,
|
|
54
|
+
writable: false,
|
|
55
|
+
configurable: true
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
}
|
|
60
|
+
function getMeta(value) {
|
|
61
|
+
if (value !== null && typeof value === "object") {
|
|
62
|
+
return value[RESPONSE_META];
|
|
63
|
+
}
|
|
64
|
+
return void 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/resources/resource.ts
|
|
68
|
+
function assertPathSegments(path) {
|
|
69
|
+
const segments = path.split("/").slice(1);
|
|
70
|
+
if (segments.some(
|
|
71
|
+
(segment) => segment === "" || segment === "." || segment === ".."
|
|
72
|
+
)) {
|
|
73
|
+
throw new ConfigurationError(
|
|
74
|
+
`Path segments cannot be empty, "." or "..": "${path}"`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
var BaseResource = class {
|
|
79
|
+
constructor(http, game) {
|
|
80
|
+
this.http = http;
|
|
81
|
+
this.game = game;
|
|
82
|
+
}
|
|
83
|
+
http;
|
|
84
|
+
game;
|
|
85
|
+
/** Performs a request and returns the data with {@link ResponseMeta} attached. */
|
|
86
|
+
async call(input, options) {
|
|
87
|
+
assertPathSegments(input.path);
|
|
88
|
+
const scoped = this.game === void 0 ? input : {
|
|
89
|
+
...input,
|
|
90
|
+
baseUrl: this.http.versionedBaseUrl("v2", input.baseUrl),
|
|
91
|
+
query: { ...input.query, game: this.game }
|
|
92
|
+
};
|
|
93
|
+
const { data, meta } = await this.http.request(scoped, options);
|
|
94
|
+
return attachMeta(data, meta);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/resources/history.ts
|
|
99
|
+
function historyQuery(params) {
|
|
100
|
+
return {
|
|
101
|
+
from: params.from,
|
|
102
|
+
to: params.to,
|
|
103
|
+
markets: params.markets,
|
|
104
|
+
listingType: params.listingType,
|
|
105
|
+
salesWindow: params.salesWindow,
|
|
106
|
+
interval: params.interval
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
var HistoryResource = class extends BaseResource {
|
|
110
|
+
/** `GET /v1/pricing/:marketHashName/history` — aggregated time series. */
|
|
111
|
+
get(marketHashName, params = {}, options) {
|
|
112
|
+
return this.call(
|
|
113
|
+
{
|
|
114
|
+
method: "GET",
|
|
115
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/history`,
|
|
116
|
+
query: historyQuery(params)
|
|
117
|
+
},
|
|
118
|
+
options
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
/** `GET /v1/pricing/:marketHashName/history/markets` — per-market series. */
|
|
122
|
+
byMarket(marketHashName, params = {}, options) {
|
|
123
|
+
return this.call(
|
|
124
|
+
{
|
|
125
|
+
method: "GET",
|
|
126
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/history/markets`,
|
|
127
|
+
query: historyQuery(params)
|
|
128
|
+
},
|
|
129
|
+
options
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/resources/items.ts
|
|
135
|
+
var ItemSearchResource = class extends BaseResource {
|
|
136
|
+
/** GET /v1/items — paginated item search with current pricing. */
|
|
137
|
+
search(params = {}, options) {
|
|
138
|
+
return this.call(
|
|
139
|
+
{
|
|
140
|
+
method: "GET",
|
|
141
|
+
path: "/items",
|
|
142
|
+
query: {
|
|
143
|
+
search: params.search,
|
|
144
|
+
markets: params.markets,
|
|
145
|
+
page: params.page,
|
|
146
|
+
perPage: params.perPage
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
options
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
/** Async iterator over every matching item, walking pages. */
|
|
153
|
+
async *searchEach(params = {}, options) {
|
|
154
|
+
let page = params.page ?? 1;
|
|
155
|
+
for (; ; ) {
|
|
156
|
+
const res = await this.search({ ...params, page }, options);
|
|
157
|
+
for (const item of res.data) {
|
|
158
|
+
yield item;
|
|
159
|
+
}
|
|
160
|
+
const next = res.pagination.nextPage;
|
|
161
|
+
if (next === null || next <= page) return;
|
|
162
|
+
page = next;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
var ItemsResource = class extends ItemSearchResource {
|
|
167
|
+
/** GET /v1/items/all — every tracked item with latest prices (capped, unpaginated). */
|
|
168
|
+
all(options) {
|
|
169
|
+
return this.call(
|
|
170
|
+
{ method: "GET", path: "/items/all" },
|
|
171
|
+
options
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// src/resources/liquidity.ts
|
|
177
|
+
var ItemLiquidityResource = class extends BaseResource {
|
|
178
|
+
/** `GET /v1/liquidity/:marketHashName` — full liquidity model for one item. */
|
|
179
|
+
get(marketHashName, params = {}, options) {
|
|
180
|
+
return this.call(
|
|
181
|
+
{
|
|
182
|
+
method: "GET",
|
|
183
|
+
path: `/liquidity/${encodePathSegment(marketHashName)}`,
|
|
184
|
+
query: { askPrice: params.askPrice, market: params.market }
|
|
185
|
+
},
|
|
186
|
+
options
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
/** `GET /v1/liquidity/summary/:marketHashName` — slim badge-only projection. */
|
|
190
|
+
summary(marketHashName, params = {}, options) {
|
|
191
|
+
return this.call(
|
|
192
|
+
{
|
|
193
|
+
method: "GET",
|
|
194
|
+
path: `/liquidity/summary/${encodePathSegment(marketHashName)}`,
|
|
195
|
+
query: { askPrice: params.askPrice, market: params.market }
|
|
196
|
+
},
|
|
197
|
+
options
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
/** `POST /v1/liquidity/batch` — score up to 100 items in one call. */
|
|
201
|
+
batch(body, options) {
|
|
202
|
+
return this.call(
|
|
203
|
+
{
|
|
204
|
+
method: "POST",
|
|
205
|
+
path: "/liquidity/batch",
|
|
206
|
+
body: { marketHashNames: body.marketHashNames, market: body.market }
|
|
207
|
+
},
|
|
208
|
+
options
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
var LiquidityResource = class extends ItemLiquidityResource {
|
|
213
|
+
/** `GET /v1/liquidity/:marketHashName`. `"items"` is reserved for {@link bulk}. */
|
|
214
|
+
get(marketHashName, params = {}, options) {
|
|
215
|
+
if (marketHashName === "items") {
|
|
216
|
+
return Promise.reject(
|
|
217
|
+
new ConfigurationError(
|
|
218
|
+
'"items" is not an item name. Use `bulk()` for the whole-catalog map.'
|
|
219
|
+
)
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return super.get(marketHashName, params, options);
|
|
223
|
+
}
|
|
224
|
+
bulk(params = {}, options) {
|
|
225
|
+
return this.call(
|
|
226
|
+
{
|
|
227
|
+
method: "GET",
|
|
228
|
+
path: "/liquidity/items",
|
|
229
|
+
ifNoneMatch: params.ifNoneMatch
|
|
230
|
+
},
|
|
231
|
+
options
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
manifest(params = {}, options) {
|
|
235
|
+
return this.call(
|
|
236
|
+
{
|
|
237
|
+
method: "GET",
|
|
238
|
+
path: "/liquidity/items/manifest",
|
|
239
|
+
ifNoneMatch: params.ifNoneMatch
|
|
240
|
+
},
|
|
241
|
+
options
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// src/resources/markets.ts
|
|
247
|
+
var MarketsResource = class extends BaseResource {
|
|
248
|
+
/**
|
|
249
|
+
* `GET /v1/markets/health` — per-market ingest status, last event time, and
|
|
250
|
+
* listing counts for every integrated market. Returns a plain array of
|
|
251
|
+
* {@link import("../types/markets").MarketHealthRow}.
|
|
252
|
+
*/
|
|
253
|
+
health(options) {
|
|
254
|
+
return this.call(
|
|
255
|
+
// Keyless: served by the public `api.` host, not the pricing base.
|
|
256
|
+
{
|
|
257
|
+
method: "GET",
|
|
258
|
+
authenticated: false,
|
|
259
|
+
path: "/markets/health",
|
|
260
|
+
baseUrl: this.http.publicBaseUrl
|
|
261
|
+
},
|
|
262
|
+
options
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// src/resources/nbbo.ts
|
|
268
|
+
var NbboResource = class extends BaseResource {
|
|
269
|
+
/** `GET /v1/nbbo` — best bid/ask across markets. Pass `id` or `marketHashName`. */
|
|
270
|
+
get(params, options) {
|
|
271
|
+
return this.call(
|
|
272
|
+
{
|
|
273
|
+
method: "GET",
|
|
274
|
+
path: "/nbbo",
|
|
275
|
+
query: {
|
|
276
|
+
id: params.id,
|
|
277
|
+
marketHashName: params.marketHashName,
|
|
278
|
+
markets: params.markets
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
options
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
/** `GET /v1/nbbo/depth` — aggregated order-book depth per side. */
|
|
285
|
+
depth(params, options) {
|
|
286
|
+
return this.call(
|
|
287
|
+
{
|
|
288
|
+
method: "GET",
|
|
289
|
+
path: "/nbbo/depth",
|
|
290
|
+
query: {
|
|
291
|
+
id: params.id,
|
|
292
|
+
marketHashName: params.marketHashName,
|
|
293
|
+
markets: params.markets,
|
|
294
|
+
depth: params.depth
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
options
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/resources/pricing.ts
|
|
303
|
+
var PricingResource = class extends BaseResource {
|
|
304
|
+
/** `GET /v1/pricing/:marketHashName` — full cross-market pricing snapshot. */
|
|
305
|
+
get(marketHashName, params = {}, options) {
|
|
306
|
+
return this.call(
|
|
307
|
+
{
|
|
308
|
+
method: "GET",
|
|
309
|
+
path: `/pricing/${encodePathSegment(marketHashName)}`,
|
|
310
|
+
query: { markets: params.markets }
|
|
311
|
+
},
|
|
312
|
+
options
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
/** `GET /v1/pricing/:marketHashName/listings` — individual listing samples. */
|
|
316
|
+
listings(marketHashName, params = {}, options) {
|
|
317
|
+
return this.call(
|
|
318
|
+
{
|
|
319
|
+
method: "GET",
|
|
320
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/listings`,
|
|
321
|
+
query: { limit: params.limit, markets: params.markets }
|
|
322
|
+
},
|
|
323
|
+
options
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/resources/schema.ts
|
|
329
|
+
var SchemaResource = class extends BaseResource {
|
|
330
|
+
/** Full catalog snapshot. A matching conditional ETag returns null. */
|
|
331
|
+
snapshot(params = {}, options) {
|
|
332
|
+
return this.call(
|
|
333
|
+
{ method: "GET", path: "/schema", ifNoneMatch: params.ifNoneMatch },
|
|
334
|
+
options
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
/** Look up one item by canonical id or exact name; v2 also accepts its game-scoped slug. */
|
|
338
|
+
get(idOrName, options) {
|
|
339
|
+
return this.call(
|
|
340
|
+
{ method: "GET", path: `/schema/items/${encodePathSegment(idOrName)}` },
|
|
341
|
+
options
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
/** One page of items changed after a catalog version or timestamp. */
|
|
345
|
+
changes(params, options) {
|
|
346
|
+
return this.call(
|
|
347
|
+
{
|
|
348
|
+
method: "GET",
|
|
349
|
+
path: "/schema/changes",
|
|
350
|
+
query: {
|
|
351
|
+
since: params.since,
|
|
352
|
+
cursor: params.cursor,
|
|
353
|
+
limit: params.limit
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
options
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
/** Iterate changes without moving the original version boundary while paging. */
|
|
360
|
+
async *changesEach(params, options) {
|
|
361
|
+
let cursor = params.cursor;
|
|
362
|
+
for (; ; ) {
|
|
363
|
+
const response = await this.changes({ ...params, cursor }, options);
|
|
364
|
+
for (const item of response.items) yield item;
|
|
365
|
+
const next = response.nextCursor;
|
|
366
|
+
if (!response.hasMore || next === null || next === cursor) return;
|
|
367
|
+
cursor = next;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
// src/game-client.ts
|
|
373
|
+
var GameClient = class {
|
|
374
|
+
constructor(http, game) {
|
|
375
|
+
this.game = game;
|
|
376
|
+
if (game !== "cs2" && game !== "rust") {
|
|
377
|
+
throw new ConfigurationError('The game must be "cs2" or "rust".');
|
|
378
|
+
}
|
|
379
|
+
this.pricing = new PricingResource(http, game);
|
|
380
|
+
this.history = new HistoryResource(http, game);
|
|
381
|
+
this.items = new ItemSearchResource(http, game);
|
|
382
|
+
this.nbbo = new NbboResource(http, game);
|
|
383
|
+
this.liquidity = new ItemLiquidityResource(http, game);
|
|
384
|
+
this.schema = new SchemaResource(http, game);
|
|
385
|
+
this.markets = new MarketsResource(http, game);
|
|
386
|
+
}
|
|
387
|
+
game;
|
|
388
|
+
pricing;
|
|
389
|
+
history;
|
|
390
|
+
items;
|
|
391
|
+
nbbo;
|
|
392
|
+
liquidity;
|
|
393
|
+
schema;
|
|
394
|
+
markets;
|
|
395
|
+
};
|
|
396
|
+
|
|
38
397
|
// src/version.ts
|
|
39
|
-
var VERSION = "0.
|
|
398
|
+
var VERSION = "0.5.0";
|
|
40
399
|
|
|
41
400
|
// src/config.ts
|
|
42
401
|
var DEFAULT_BASE_URL = "https://pricing.skinpricer.com/v1";
|
|
@@ -207,6 +566,16 @@ function extractErrorFields(body, status) {
|
|
|
207
566
|
const message = typeof err.message === "string" ? err.message : defaultMessage(status);
|
|
208
567
|
const result = { message };
|
|
209
568
|
if (typeof err.code === "string") result.code = err.code;
|
|
569
|
+
if (Array.isArray(err.details)) {
|
|
570
|
+
const messages = err.details.filter(
|
|
571
|
+
(entry) => typeof entry === "string"
|
|
572
|
+
);
|
|
573
|
+
if (messages.length > 0) {
|
|
574
|
+
result.message = `${message}: ${messages.join(", ")}`;
|
|
575
|
+
result.messages = messages;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
if (typeof body.requestId === "string") result.requestId = body.requestId;
|
|
210
579
|
return result;
|
|
211
580
|
}
|
|
212
581
|
const rawMessage = body.message;
|
|
@@ -236,11 +605,14 @@ function looksLikeFeatureError(message) {
|
|
|
236
605
|
}
|
|
237
606
|
function errorFromResponse(input) {
|
|
238
607
|
const { status, body, meta } = input;
|
|
239
|
-
const { code, message, messages } = extractErrorFields(
|
|
608
|
+
const { code, message, messages, requestId } = extractErrorFields(
|
|
609
|
+
body,
|
|
610
|
+
status
|
|
611
|
+
);
|
|
240
612
|
const base = {
|
|
241
613
|
status,
|
|
242
614
|
code,
|
|
243
|
-
requestId: meta.requestId,
|
|
615
|
+
requestId: meta.requestId ?? requestId ?? null,
|
|
244
616
|
responseBody: body,
|
|
245
617
|
rateLimit: meta.rateLimit
|
|
246
618
|
};
|
|
@@ -304,8 +676,10 @@ function tryJsonParse(text) {
|
|
|
304
676
|
return void 0;
|
|
305
677
|
}
|
|
306
678
|
}
|
|
307
|
-
async function parseResponse(response) {
|
|
679
|
+
async function parseResponse(response, allowNotModified = false) {
|
|
308
680
|
const meta = buildMeta(response);
|
|
681
|
+
if (allowNotModified && response.status === 304)
|
|
682
|
+
return { data: null, meta };
|
|
309
683
|
const text = await response.text();
|
|
310
684
|
if (response.ok) {
|
|
311
685
|
if (text.length === 0) {
|
|
@@ -328,15 +702,6 @@ async function parseResponse(response) {
|
|
|
328
702
|
throw errorFromResponse({ status: response.status, body, meta });
|
|
329
703
|
}
|
|
330
704
|
|
|
331
|
-
// src/utils/url.ts
|
|
332
|
-
function encodePathSegment(segment) {
|
|
333
|
-
return encodeURIComponent(segment);
|
|
334
|
-
}
|
|
335
|
-
function joinUrl(baseUrl, path) {
|
|
336
|
-
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
337
|
-
return `${baseUrl}${normalizedPath}`;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
705
|
// src/http/query.ts
|
|
341
706
|
function serializeQuery(params) {
|
|
342
707
|
const search = new URLSearchParams();
|
|
@@ -365,14 +730,21 @@ function buildRequest(config, input) {
|
|
|
365
730
|
Accept: "application/json",
|
|
366
731
|
"User-Agent": config.userAgent,
|
|
367
732
|
"X-Skinpricer-Client": config.userAgent,
|
|
368
|
-
...
|
|
733
|
+
...Object.fromEntries(
|
|
734
|
+
Object.entries(config.headers).filter(
|
|
735
|
+
([name]) => name.toLowerCase() !== "authorization"
|
|
736
|
+
)
|
|
737
|
+
)
|
|
369
738
|
};
|
|
370
739
|
let body;
|
|
371
740
|
if (input.body !== void 0) {
|
|
372
741
|
body = JSON.stringify(input.body);
|
|
373
742
|
headers["Content-Type"] = "application/json";
|
|
374
743
|
}
|
|
375
|
-
|
|
744
|
+
if (input.authenticated !== false)
|
|
745
|
+
headers["Authorization"] = `${config.authScheme} ${config.apiKey}`;
|
|
746
|
+
if (input.ifNoneMatch !== void 0)
|
|
747
|
+
headers["If-None-Match"] = input.ifNoneMatch;
|
|
376
748
|
const prepared = { url, method: input.method, headers };
|
|
377
749
|
if (body !== void 0) prepared.body = body;
|
|
378
750
|
return prepared;
|
|
@@ -459,6 +831,12 @@ var HttpClient = class {
|
|
|
459
831
|
get publicBaseUrl() {
|
|
460
832
|
return this.config.publicBaseUrl;
|
|
461
833
|
}
|
|
834
|
+
/** Selects an API version while retaining a configured gateway prefix. */
|
|
835
|
+
versionedBaseUrl(version, baseUrl = this.config.baseUrl) {
|
|
836
|
+
const url = new URL(baseUrl);
|
|
837
|
+
url.pathname = /\/v[0-9]+$/.test(url.pathname) ? url.pathname.replace(/\/v[0-9]+$/, `/${version}`) : `${url.pathname.replace(/\/$/, "")}/${version}`;
|
|
838
|
+
return url.toString().replace(/\/$/, "");
|
|
839
|
+
}
|
|
462
840
|
async request(input, options = {}) {
|
|
463
841
|
const prepared = buildRequest(this.config, input);
|
|
464
842
|
const retry = resolveRequestRetry(this.config.retry, options.retry);
|
|
@@ -474,46 +852,18 @@ var HttpClient = class {
|
|
|
474
852
|
url: prepared.url,
|
|
475
853
|
attempt
|
|
476
854
|
});
|
|
477
|
-
let response;
|
|
478
855
|
try {
|
|
479
|
-
response = await this.config.fetch(prepared.url, {
|
|
856
|
+
const response = await this.config.fetch(prepared.url, {
|
|
480
857
|
method: prepared.method,
|
|
481
858
|
headers: prepared.headers,
|
|
482
859
|
body: prepared.body,
|
|
483
860
|
signal: handle.signal
|
|
484
861
|
});
|
|
485
|
-
|
|
862
|
+
const parsed = await parseResponse(
|
|
863
|
+
response,
|
|
864
|
+
input.ifNoneMatch !== void 0
|
|
865
|
+
);
|
|
486
866
|
handle.cleanup();
|
|
487
|
-
if (callerSignal?.aborted && !handle.didTimeout()) {
|
|
488
|
-
throw abortError(callerSignal);
|
|
489
|
-
}
|
|
490
|
-
if (retry && shouldRetry({ method: input.method, attempt, retry, status: null })) {
|
|
491
|
-
const delayMs = retryDelayMs({
|
|
492
|
-
attempt,
|
|
493
|
-
retry,
|
|
494
|
-
retryAfterSeconds: null
|
|
495
|
-
});
|
|
496
|
-
await runHook(hooks.onRetry, {
|
|
497
|
-
method: input.method,
|
|
498
|
-
url: prepared.url,
|
|
499
|
-
attempt,
|
|
500
|
-
delayMs,
|
|
501
|
-
status: null
|
|
502
|
-
});
|
|
503
|
-
await sleep(delayMs, callerSignal);
|
|
504
|
-
attempt += 1;
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
if (handle.didTimeout()) {
|
|
508
|
-
throw new TimeoutError(`Request timed out after ${timeoutMs}ms`, {
|
|
509
|
-
cause: error
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
|
-
throw new NetworkError(networkMessage(error), { cause: error });
|
|
513
|
-
}
|
|
514
|
-
handle.cleanup();
|
|
515
|
-
try {
|
|
516
|
-
const parsed = await parseResponse(response);
|
|
517
867
|
this.recordRateLimit(parsed.meta.rateLimit);
|
|
518
868
|
await runHook(hooks.onResponse, {
|
|
519
869
|
method: input.method,
|
|
@@ -524,30 +874,32 @@ var HttpClient = class {
|
|
|
524
874
|
});
|
|
525
875
|
return parsed;
|
|
526
876
|
} catch (error) {
|
|
527
|
-
|
|
528
|
-
|
|
877
|
+
handle.cleanup();
|
|
878
|
+
if (callerSignal?.aborted && !handle.didTimeout())
|
|
879
|
+
throw abortError(callerSignal);
|
|
880
|
+
const failure = handle.didTimeout() ? new TimeoutError(`Request timed out after ${timeoutMs}ms`, {
|
|
881
|
+
cause: error
|
|
882
|
+
}) : error instanceof SkinpricerError ? error : new NetworkError(networkMessage(error), { cause: error });
|
|
883
|
+
if (failure instanceof RateLimitError) {
|
|
884
|
+
this.recordRateLimit(failure.rateLimit, failure.retryAfterSeconds);
|
|
529
885
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
retry,
|
|
534
|
-
status: error.status
|
|
535
|
-
})) {
|
|
536
|
-
const retryAfterSeconds = error instanceof RateLimitError ? error.retryAfterSeconds : error.rateLimit?.retryAfterSeconds ?? null;
|
|
886
|
+
const status = failure.status ?? null;
|
|
887
|
+
if (retry && shouldRetry({ method: input.method, attempt, retry, status })) {
|
|
888
|
+
const retryAfterSeconds = failure instanceof RateLimitError ? failure.retryAfterSeconds : failure.rateLimit?.retryAfterSeconds ?? null;
|
|
537
889
|
const delayMs = retryDelayMs({ attempt, retry, retryAfterSeconds });
|
|
538
890
|
await runHook(hooks.onRetry, {
|
|
539
891
|
method: input.method,
|
|
540
892
|
url: prepared.url,
|
|
541
893
|
attempt,
|
|
542
894
|
delayMs,
|
|
543
|
-
status
|
|
544
|
-
error
|
|
895
|
+
status,
|
|
896
|
+
error: failure
|
|
545
897
|
});
|
|
546
898
|
await sleep(delayMs, callerSignal);
|
|
547
899
|
attempt += 1;
|
|
548
900
|
continue;
|
|
549
901
|
}
|
|
550
|
-
throw
|
|
902
|
+
throw failure;
|
|
551
903
|
}
|
|
552
904
|
}
|
|
553
905
|
}
|
|
@@ -593,39 +945,6 @@ async function mapWithConcurrency(items, limit, fn) {
|
|
|
593
945
|
return results;
|
|
594
946
|
}
|
|
595
947
|
|
|
596
|
-
// src/meta.ts
|
|
597
|
-
var RESPONSE_META = /* @__PURE__ */ Symbol("skinpricer.responseMeta");
|
|
598
|
-
function attachMeta(data, meta) {
|
|
599
|
-
if (data !== null && typeof data === "object") {
|
|
600
|
-
Object.defineProperty(data, RESPONSE_META, {
|
|
601
|
-
value: meta,
|
|
602
|
-
enumerable: false,
|
|
603
|
-
writable: false,
|
|
604
|
-
configurable: true
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
return data;
|
|
608
|
-
}
|
|
609
|
-
function getMeta(value) {
|
|
610
|
-
if (value !== null && typeof value === "object") {
|
|
611
|
-
return value[RESPONSE_META];
|
|
612
|
-
}
|
|
613
|
-
return void 0;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
// src/resources/resource.ts
|
|
617
|
-
var BaseResource = class {
|
|
618
|
-
constructor(http) {
|
|
619
|
-
this.http = http;
|
|
620
|
-
}
|
|
621
|
-
http;
|
|
622
|
-
/** Performs a request and returns the data with {@link ResponseMeta} attached. */
|
|
623
|
-
async call(input, options) {
|
|
624
|
-
const { data, meta } = await this.http.request(input, options);
|
|
625
|
-
return attachMeta(data, meta);
|
|
626
|
-
}
|
|
627
|
-
};
|
|
628
|
-
|
|
629
948
|
// src/resources/aggregations.ts
|
|
630
949
|
var MAX_IDS_PER_REQUEST = 100;
|
|
631
950
|
var DEFAULT_BATCH_CONCURRENCY = 5;
|
|
@@ -828,141 +1147,6 @@ var Buff163Resource = class extends BaseResource {
|
|
|
828
1147
|
}
|
|
829
1148
|
};
|
|
830
1149
|
|
|
831
|
-
// src/resources/history.ts
|
|
832
|
-
function historyQuery(params) {
|
|
833
|
-
return {
|
|
834
|
-
from: params.from,
|
|
835
|
-
to: params.to,
|
|
836
|
-
markets: params.markets,
|
|
837
|
-
listingType: params.listingType,
|
|
838
|
-
salesWindow: params.salesWindow,
|
|
839
|
-
interval: params.interval
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
var HistoryResource = class extends BaseResource {
|
|
843
|
-
/** `GET /v1/pricing/:marketHashName/history` — aggregated time series. */
|
|
844
|
-
get(marketHashName, params = {}, options) {
|
|
845
|
-
return this.call(
|
|
846
|
-
{
|
|
847
|
-
method: "GET",
|
|
848
|
-
path: `/pricing/${encodePathSegment(marketHashName)}/history`,
|
|
849
|
-
query: historyQuery(params)
|
|
850
|
-
},
|
|
851
|
-
options
|
|
852
|
-
);
|
|
853
|
-
}
|
|
854
|
-
/** `GET /v1/pricing/:marketHashName/history/markets` — per-market series. */
|
|
855
|
-
byMarket(marketHashName, params = {}, options) {
|
|
856
|
-
return this.call(
|
|
857
|
-
{
|
|
858
|
-
method: "GET",
|
|
859
|
-
path: `/pricing/${encodePathSegment(marketHashName)}/history/markets`,
|
|
860
|
-
query: historyQuery(params)
|
|
861
|
-
},
|
|
862
|
-
options
|
|
863
|
-
);
|
|
864
|
-
}
|
|
865
|
-
};
|
|
866
|
-
|
|
867
|
-
// src/resources/items.ts
|
|
868
|
-
var ItemsResource = class extends BaseResource {
|
|
869
|
-
/** GET /v1/items — paginated item search with current pricing. */
|
|
870
|
-
search(params = {}, options) {
|
|
871
|
-
return this.call(
|
|
872
|
-
{
|
|
873
|
-
method: "GET",
|
|
874
|
-
path: "/items",
|
|
875
|
-
query: {
|
|
876
|
-
search: params.search,
|
|
877
|
-
markets: params.markets,
|
|
878
|
-
page: params.page,
|
|
879
|
-
perPage: params.perPage
|
|
880
|
-
}
|
|
881
|
-
},
|
|
882
|
-
options
|
|
883
|
-
);
|
|
884
|
-
}
|
|
885
|
-
/** GET /v1/items/all — every tracked item with latest prices (capped, unpaginated). */
|
|
886
|
-
all(options) {
|
|
887
|
-
return this.call(
|
|
888
|
-
{ method: "GET", path: "/items/all" },
|
|
889
|
-
options
|
|
890
|
-
);
|
|
891
|
-
}
|
|
892
|
-
/** Async iterator over every matching item, walking pages. */
|
|
893
|
-
async *searchEach(params = {}, options) {
|
|
894
|
-
let page = params.page ?? 1;
|
|
895
|
-
for (; ; ) {
|
|
896
|
-
const res = await this.search({ ...params, page }, options);
|
|
897
|
-
for (const item of res.data) {
|
|
898
|
-
yield item;
|
|
899
|
-
}
|
|
900
|
-
const next = res.pagination.nextPage;
|
|
901
|
-
if (next === null || next <= page) return;
|
|
902
|
-
page = next;
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
// src/resources/liquidity.ts
|
|
908
|
-
var LiquidityResource = class extends BaseResource {
|
|
909
|
-
/** `GET /v1/liquidity/:marketHashName` — full liquidity model for one item. */
|
|
910
|
-
get(marketHashName, params = {}, options) {
|
|
911
|
-
return this.call(
|
|
912
|
-
{
|
|
913
|
-
method: "GET",
|
|
914
|
-
path: `/liquidity/${encodePathSegment(marketHashName)}`,
|
|
915
|
-
query: { askPrice: params.askPrice, market: params.market }
|
|
916
|
-
},
|
|
917
|
-
options
|
|
918
|
-
);
|
|
919
|
-
}
|
|
920
|
-
/** `GET /v1/liquidity/summary/:marketHashName` — slim badge-only projection. */
|
|
921
|
-
summary(marketHashName, params = {}, options) {
|
|
922
|
-
return this.call(
|
|
923
|
-
{
|
|
924
|
-
method: "GET",
|
|
925
|
-
path: `/liquidity/summary/${encodePathSegment(marketHashName)}`,
|
|
926
|
-
query: { askPrice: params.askPrice, market: params.market }
|
|
927
|
-
},
|
|
928
|
-
options
|
|
929
|
-
);
|
|
930
|
-
}
|
|
931
|
-
/** `POST /v1/liquidity/batch` — score up to 100 items in one call. */
|
|
932
|
-
batch(body, options) {
|
|
933
|
-
return this.call(
|
|
934
|
-
{
|
|
935
|
-
method: "POST",
|
|
936
|
-
path: "/liquidity/batch",
|
|
937
|
-
body: { marketHashNames: body.marketHashNames, market: body.market }
|
|
938
|
-
},
|
|
939
|
-
options
|
|
940
|
-
);
|
|
941
|
-
}
|
|
942
|
-
/**
|
|
943
|
-
* `GET /v1/liquidity/items` — Enterprise: the whole-catalog liquidity map,
|
|
944
|
-
* rematerialized every ~10 minutes. Poll {@link manifest} and compare
|
|
945
|
-
* `version` before refetching this heavier payload.
|
|
946
|
-
*/
|
|
947
|
-
bulk(options) {
|
|
948
|
-
return this.call(
|
|
949
|
-
{ method: "GET", path: "/liquidity/items" },
|
|
950
|
-
options
|
|
951
|
-
);
|
|
952
|
-
}
|
|
953
|
-
/**
|
|
954
|
-
* `GET /v1/liquidity/items/manifest` — Enterprise: a cheap change-probe for
|
|
955
|
-
* the {@link bulk} map (`version`, `calculatedAt`, `cadence`, `markets`,
|
|
956
|
-
* `itemCount`). Refetch the bulk map only when `version` changes.
|
|
957
|
-
*/
|
|
958
|
-
manifest(options) {
|
|
959
|
-
return this.call(
|
|
960
|
-
{ method: "GET", path: "/liquidity/items/manifest" },
|
|
961
|
-
options
|
|
962
|
-
);
|
|
963
|
-
}
|
|
964
|
-
};
|
|
965
|
-
|
|
966
1150
|
// src/resources/market-analytics.ts
|
|
967
1151
|
var MarketAnalyticsResource = class extends BaseResource {
|
|
968
1152
|
/** `GET /v1/market-analytics/:marketHashName` — per-market analytics rows. */
|
|
@@ -978,77 +1162,16 @@ var MarketAnalyticsResource = class extends BaseResource {
|
|
|
978
1162
|
}
|
|
979
1163
|
};
|
|
980
1164
|
|
|
981
|
-
// src/resources/
|
|
982
|
-
var
|
|
983
|
-
|
|
984
|
-
* `GET /v1/markets/health` — per-market ingest status, last event time, and
|
|
985
|
-
* listing counts for every integrated market. Returns a plain array of
|
|
986
|
-
* {@link import("../types/markets").MarketHealthRow}.
|
|
987
|
-
*/
|
|
988
|
-
health(options) {
|
|
989
|
-
return this.call(
|
|
990
|
-
// Keyless: served by the public `api.` host, not the pricing base.
|
|
991
|
-
{ method: "GET", path: "/markets/health", baseUrl: this.http.publicBaseUrl },
|
|
992
|
-
options
|
|
993
|
-
);
|
|
994
|
-
}
|
|
995
|
-
};
|
|
996
|
-
|
|
997
|
-
// src/resources/nbbo.ts
|
|
998
|
-
var NbboResource = class extends BaseResource {
|
|
999
|
-
/** `GET /v1/nbbo` — best bid/ask across markets. Pass `id` or `marketHashName`. */
|
|
1000
|
-
get(params, options) {
|
|
1001
|
-
return this.call(
|
|
1002
|
-
{
|
|
1003
|
-
method: "GET",
|
|
1004
|
-
path: "/nbbo",
|
|
1005
|
-
query: {
|
|
1006
|
-
id: params.id,
|
|
1007
|
-
market_hash_name: params.marketHashName,
|
|
1008
|
-
markets: params.markets
|
|
1009
|
-
}
|
|
1010
|
-
},
|
|
1011
|
-
options
|
|
1012
|
-
);
|
|
1013
|
-
}
|
|
1014
|
-
/** `GET /v1/nbbo/depth` — aggregated order-book depth per side. */
|
|
1015
|
-
depth(params, options) {
|
|
1016
|
-
return this.call(
|
|
1017
|
-
{
|
|
1018
|
-
method: "GET",
|
|
1019
|
-
path: "/nbbo/depth",
|
|
1020
|
-
query: {
|
|
1021
|
-
id: params.id,
|
|
1022
|
-
market_hash_name: params.marketHashName,
|
|
1023
|
-
markets: params.markets,
|
|
1024
|
-
depth: params.depth
|
|
1025
|
-
}
|
|
1026
|
-
},
|
|
1027
|
-
options
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
};
|
|
1031
|
-
|
|
1032
|
-
// src/resources/pricing.ts
|
|
1033
|
-
var PricingResource = class extends BaseResource {
|
|
1034
|
-
/** `GET /v1/pricing/:marketHashName` — full cross-market pricing snapshot. */
|
|
1035
|
-
get(marketHashName, params = {}, options) {
|
|
1036
|
-
return this.call(
|
|
1037
|
-
{
|
|
1038
|
-
method: "GET",
|
|
1039
|
-
path: `/pricing/${encodePathSegment(marketHashName)}`,
|
|
1040
|
-
query: { markets: params.markets }
|
|
1041
|
-
},
|
|
1042
|
-
options
|
|
1043
|
-
);
|
|
1044
|
-
}
|
|
1045
|
-
/** `GET /v1/pricing/:marketHashName/listings` — individual listing samples. */
|
|
1046
|
-
listings(marketHashName, params = {}, options) {
|
|
1165
|
+
// src/resources/prices.ts
|
|
1166
|
+
var PricesResource = class extends BaseResource {
|
|
1167
|
+
latestAll(params, options) {
|
|
1047
1168
|
return this.call(
|
|
1048
1169
|
{
|
|
1049
1170
|
method: "GET",
|
|
1050
|
-
path:
|
|
1051
|
-
|
|
1171
|
+
path: "/prices/latest",
|
|
1172
|
+
baseUrl: this.http.versionedBaseUrl("v2"),
|
|
1173
|
+
query: { game: params.game },
|
|
1174
|
+
ifNoneMatch: params.ifNoneMatch
|
|
1052
1175
|
},
|
|
1053
1176
|
options
|
|
1054
1177
|
);
|
|
@@ -1103,6 +1226,12 @@ var SkinpricerClient = class {
|
|
|
1103
1226
|
buff163;
|
|
1104
1227
|
liquidity;
|
|
1105
1228
|
markets;
|
|
1229
|
+
schema;
|
|
1230
|
+
prices;
|
|
1231
|
+
/** Access the v2 endpoints supported by the selected game. */
|
|
1232
|
+
forGame(game) {
|
|
1233
|
+
return new GameClient(this.httpClient, game);
|
|
1234
|
+
}
|
|
1106
1235
|
httpClient;
|
|
1107
1236
|
constructor(config) {
|
|
1108
1237
|
this.httpClient = new HttpClient(resolveConfig(config));
|
|
@@ -1119,6 +1248,8 @@ var SkinpricerClient = class {
|
|
|
1119
1248
|
this.buff163 = new Buff163Resource(this.httpClient);
|
|
1120
1249
|
this.liquidity = new LiquidityResource(this.httpClient);
|
|
1121
1250
|
this.markets = new MarketsResource(this.httpClient);
|
|
1251
|
+
this.schema = new SchemaResource(this.httpClient);
|
|
1252
|
+
this.prices = new PricesResource(this.httpClient);
|
|
1122
1253
|
}
|
|
1123
1254
|
};
|
|
1124
1255
|
|
|
@@ -1138,10 +1269,15 @@ var KNOWN_MARKETS = [
|
|
|
1138
1269
|
"whitemarket",
|
|
1139
1270
|
"waxpeer",
|
|
1140
1271
|
"lootfarm",
|
|
1272
|
+
"rapidskins",
|
|
1141
1273
|
"avanmarket",
|
|
1142
1274
|
"tradeit-store",
|
|
1143
1275
|
"tradeit-trade",
|
|
1144
|
-
"steamcommunity"
|
|
1276
|
+
"steamcommunity",
|
|
1277
|
+
"youpin",
|
|
1278
|
+
"mannco-store",
|
|
1279
|
+
"rusttm",
|
|
1280
|
+
"rustskins"
|
|
1145
1281
|
];
|
|
1146
1282
|
var ATTRIBUTE_MARKETS = [
|
|
1147
1283
|
"buff163",
|
|
@@ -1159,7 +1295,8 @@ var LIQUIDITY_BADGES = [
|
|
|
1159
1295
|
"ILLIQUID",
|
|
1160
1296
|
"VERY_ILLIQUID",
|
|
1161
1297
|
"EXTREMELY_ILLIQUID",
|
|
1162
|
-
"UNTRADED"
|
|
1298
|
+
"UNTRADED",
|
|
1299
|
+
"INSUFFICIENT_DATA"
|
|
1163
1300
|
];
|
|
1164
1301
|
var LIQUIDITY_CONFIDENCE = [
|
|
1165
1302
|
"HIGH",
|
|
@@ -1180,9 +1317,10 @@ var SUPPORTED_LIQUIDITY_MARKETS = [
|
|
|
1180
1317
|
"skinport",
|
|
1181
1318
|
"marketcsgo",
|
|
1182
1319
|
"dmarket",
|
|
1183
|
-
"
|
|
1320
|
+
"steamcommunity",
|
|
1184
1321
|
"csfloat"
|
|
1185
1322
|
];
|
|
1323
|
+
var SUPPORTED_RUST_LIQUIDITY_MARKETS = ["rusttm", "skinport"];
|
|
1186
1324
|
|
|
1187
1325
|
// src/utils/money.ts
|
|
1188
1326
|
function centsToUsd(cents) {
|
|
@@ -1214,6 +1352,7 @@ exports.DEFAULT_PUBLIC_BASE_URL = DEFAULT_PUBLIC_BASE_URL;
|
|
|
1214
1352
|
exports.DEFAULT_RETRY = DEFAULT_RETRY;
|
|
1215
1353
|
exports.DEFAULT_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;
|
|
1216
1354
|
exports.FeatureNotAvailableError = FeatureNotAvailableError;
|
|
1355
|
+
exports.GameClient = GameClient;
|
|
1217
1356
|
exports.HistoryResource = HistoryResource;
|
|
1218
1357
|
exports.ItemsResource = ItemsResource;
|
|
1219
1358
|
exports.KNOWN_MARKETS = KNOWN_MARKETS;
|
|
@@ -1228,11 +1367,14 @@ exports.NetworkError = NetworkError;
|
|
|
1228
1367
|
exports.NotFoundError = NotFoundError;
|
|
1229
1368
|
exports.ParseError = ParseError;
|
|
1230
1369
|
exports.PermissionError = PermissionError;
|
|
1370
|
+
exports.PricesResource = PricesResource;
|
|
1231
1371
|
exports.PricingResource = PricingResource;
|
|
1232
1372
|
exports.RESPONSE_META = RESPONSE_META;
|
|
1233
1373
|
exports.RateLimitError = RateLimitError;
|
|
1234
1374
|
exports.RecommendationsResource = RecommendationsResource;
|
|
1235
1375
|
exports.SUPPORTED_LIQUIDITY_MARKETS = SUPPORTED_LIQUIDITY_MARKETS;
|
|
1376
|
+
exports.SUPPORTED_RUST_LIQUIDITY_MARKETS = SUPPORTED_RUST_LIQUIDITY_MARKETS;
|
|
1377
|
+
exports.SchemaResource = SchemaResource;
|
|
1236
1378
|
exports.ServerError = ServerError;
|
|
1237
1379
|
exports.SkinpricerClient = SkinpricerClient;
|
|
1238
1380
|
exports.SkinpricerError = SkinpricerError;
|