@skinpricer/sdk 0.2.0 → 0.4.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 +41 -0
- package/README.md +178 -15
- package/dist/index.cjs +504 -226
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +837 -365
- package/dist/index.d.ts +837 -365
- package/dist/index.js +494 -227
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -33,12 +33,383 @@ var ConfigurationError = class extends SkinpricerError {
|
|
|
33
33
|
var ParseError = class extends SkinpricerError {
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
// src/utils/url.ts
|
|
37
|
+
function encodePathSegment(segment) {
|
|
38
|
+
return encodeURIComponent(segment);
|
|
39
|
+
}
|
|
40
|
+
function joinUrl(baseUrl, path) {
|
|
41
|
+
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
42
|
+
return `${baseUrl}${normalizedPath}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/meta.ts
|
|
46
|
+
var RESPONSE_META = /* @__PURE__ */ Symbol("skinpricer.responseMeta");
|
|
47
|
+
function attachMeta(data, meta) {
|
|
48
|
+
if (data !== null && typeof data === "object") {
|
|
49
|
+
Object.defineProperty(data, RESPONSE_META, {
|
|
50
|
+
value: meta,
|
|
51
|
+
enumerable: false,
|
|
52
|
+
writable: false,
|
|
53
|
+
configurable: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
function getMeta(value) {
|
|
59
|
+
if (value !== null && typeof value === "object") {
|
|
60
|
+
return value[RESPONSE_META];
|
|
61
|
+
}
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/resources/resource.ts
|
|
66
|
+
function assertPathSegments(path) {
|
|
67
|
+
const segments = path.split("/").slice(1);
|
|
68
|
+
if (segments.some(
|
|
69
|
+
(segment) => segment === "" || segment === "." || segment === ".."
|
|
70
|
+
)) {
|
|
71
|
+
throw new ConfigurationError(
|
|
72
|
+
`Path segments cannot be empty, "." or "..": "${path}"`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var BaseResource = class {
|
|
77
|
+
constructor(http, game) {
|
|
78
|
+
this.http = http;
|
|
79
|
+
this.game = game;
|
|
80
|
+
}
|
|
81
|
+
http;
|
|
82
|
+
game;
|
|
83
|
+
/** Performs a request and returns the data with {@link ResponseMeta} attached. */
|
|
84
|
+
async call(input, options) {
|
|
85
|
+
assertPathSegments(input.path);
|
|
86
|
+
const scoped = this.game === void 0 ? input : {
|
|
87
|
+
...input,
|
|
88
|
+
baseUrl: this.http.versionedBaseUrl("v2", input.baseUrl),
|
|
89
|
+
query: { ...input.query, game: this.game }
|
|
90
|
+
};
|
|
91
|
+
const { data, meta } = await this.http.request(scoped, options);
|
|
92
|
+
return attachMeta(data, meta);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/resources/history.ts
|
|
97
|
+
function historyQuery(params) {
|
|
98
|
+
return {
|
|
99
|
+
from: params.from,
|
|
100
|
+
to: params.to,
|
|
101
|
+
markets: params.markets,
|
|
102
|
+
listingType: params.listingType,
|
|
103
|
+
salesWindow: params.salesWindow,
|
|
104
|
+
interval: params.interval
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
var HistoryResource = class extends BaseResource {
|
|
108
|
+
/** `GET /v1/pricing/:marketHashName/history` — aggregated time series. */
|
|
109
|
+
get(marketHashName, params = {}, options) {
|
|
110
|
+
return this.call(
|
|
111
|
+
{
|
|
112
|
+
method: "GET",
|
|
113
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/history`,
|
|
114
|
+
query: historyQuery(params)
|
|
115
|
+
},
|
|
116
|
+
options
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
/** `GET /v1/pricing/:marketHashName/history/markets` — per-market series. */
|
|
120
|
+
byMarket(marketHashName, params = {}, options) {
|
|
121
|
+
return this.call(
|
|
122
|
+
{
|
|
123
|
+
method: "GET",
|
|
124
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/history/markets`,
|
|
125
|
+
query: historyQuery(params)
|
|
126
|
+
},
|
|
127
|
+
options
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/resources/items.ts
|
|
133
|
+
var ItemSearchResource = class extends BaseResource {
|
|
134
|
+
/** GET /v1/items — paginated item search with current pricing. */
|
|
135
|
+
search(params = {}, options) {
|
|
136
|
+
return this.call(
|
|
137
|
+
{
|
|
138
|
+
method: "GET",
|
|
139
|
+
path: "/items",
|
|
140
|
+
query: {
|
|
141
|
+
search: params.search,
|
|
142
|
+
markets: params.markets,
|
|
143
|
+
page: params.page,
|
|
144
|
+
perPage: params.perPage
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
options
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
/** Async iterator over every matching item, walking pages. */
|
|
151
|
+
async *searchEach(params = {}, options) {
|
|
152
|
+
let page = params.page ?? 1;
|
|
153
|
+
for (; ; ) {
|
|
154
|
+
const res = await this.search({ ...params, page }, options);
|
|
155
|
+
for (const item of res.data) {
|
|
156
|
+
yield item;
|
|
157
|
+
}
|
|
158
|
+
const next = res.pagination.nextPage;
|
|
159
|
+
if (next === null || next <= page) return;
|
|
160
|
+
page = next;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var ItemsResource = class extends ItemSearchResource {
|
|
165
|
+
/** GET /v1/items/all — every tracked item with latest prices (capped, unpaginated). */
|
|
166
|
+
all(options) {
|
|
167
|
+
return this.call(
|
|
168
|
+
{ method: "GET", path: "/items/all" },
|
|
169
|
+
options
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/resources/liquidity.ts
|
|
175
|
+
var ItemLiquidityResource = class extends BaseResource {
|
|
176
|
+
/** `GET /v1/liquidity/:marketHashName` — full liquidity model for one item. */
|
|
177
|
+
get(marketHashName, params = {}, options) {
|
|
178
|
+
return this.call(
|
|
179
|
+
{
|
|
180
|
+
method: "GET",
|
|
181
|
+
path: `/liquidity/${encodePathSegment(marketHashName)}`,
|
|
182
|
+
query: { askPrice: params.askPrice, market: params.market }
|
|
183
|
+
},
|
|
184
|
+
options
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
/** `GET /v1/liquidity/summary/:marketHashName` — slim badge-only projection. */
|
|
188
|
+
summary(marketHashName, params = {}, options) {
|
|
189
|
+
return this.call(
|
|
190
|
+
{
|
|
191
|
+
method: "GET",
|
|
192
|
+
path: `/liquidity/summary/${encodePathSegment(marketHashName)}`,
|
|
193
|
+
query: { askPrice: params.askPrice, market: params.market }
|
|
194
|
+
},
|
|
195
|
+
options
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
/** `POST /v1/liquidity/batch` — score up to 100 items in one call. */
|
|
199
|
+
batch(body, options) {
|
|
200
|
+
return this.call(
|
|
201
|
+
{
|
|
202
|
+
method: "POST",
|
|
203
|
+
path: "/liquidity/batch",
|
|
204
|
+
body: { marketHashNames: body.marketHashNames, market: body.market }
|
|
205
|
+
},
|
|
206
|
+
options
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var LiquidityResource = class extends ItemLiquidityResource {
|
|
211
|
+
/** `GET /v1/liquidity/:marketHashName`. `"items"` is reserved for {@link bulk}. */
|
|
212
|
+
get(marketHashName, params = {}, options) {
|
|
213
|
+
if (marketHashName === "items") {
|
|
214
|
+
return Promise.reject(
|
|
215
|
+
new ConfigurationError(
|
|
216
|
+
'"items" is not an item name. Use `bulk()` for the whole-catalog map.'
|
|
217
|
+
)
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
return super.get(marketHashName, params, options);
|
|
221
|
+
}
|
|
222
|
+
bulk(params = {}, options) {
|
|
223
|
+
return this.call(
|
|
224
|
+
{
|
|
225
|
+
method: "GET",
|
|
226
|
+
path: "/liquidity/items",
|
|
227
|
+
ifNoneMatch: params.ifNoneMatch
|
|
228
|
+
},
|
|
229
|
+
options
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
manifest(params = {}, options) {
|
|
233
|
+
return this.call(
|
|
234
|
+
{
|
|
235
|
+
method: "GET",
|
|
236
|
+
path: "/liquidity/items/manifest",
|
|
237
|
+
ifNoneMatch: params.ifNoneMatch
|
|
238
|
+
},
|
|
239
|
+
options
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// src/resources/markets.ts
|
|
245
|
+
var MarketsResource = class extends BaseResource {
|
|
246
|
+
/**
|
|
247
|
+
* `GET /v1/markets/health` — per-market ingest status, last event time, and
|
|
248
|
+
* listing counts for every integrated market. Returns a plain array of
|
|
249
|
+
* {@link import("../types/markets").MarketHealthRow}.
|
|
250
|
+
*/
|
|
251
|
+
health(options) {
|
|
252
|
+
return this.call(
|
|
253
|
+
// Keyless: served by the public `api.` host, not the pricing base.
|
|
254
|
+
{
|
|
255
|
+
method: "GET",
|
|
256
|
+
authenticated: false,
|
|
257
|
+
path: "/markets/health",
|
|
258
|
+
baseUrl: this.http.publicBaseUrl
|
|
259
|
+
},
|
|
260
|
+
options
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/resources/nbbo.ts
|
|
266
|
+
var NbboResource = class extends BaseResource {
|
|
267
|
+
/** `GET /v1/nbbo` — best bid/ask across markets. Pass `id` or `marketHashName`. */
|
|
268
|
+
get(params, options) {
|
|
269
|
+
return this.call(
|
|
270
|
+
{
|
|
271
|
+
method: "GET",
|
|
272
|
+
path: "/nbbo",
|
|
273
|
+
query: {
|
|
274
|
+
id: params.id,
|
|
275
|
+
market_hash_name: params.marketHashName,
|
|
276
|
+
markets: params.markets
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
options
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
/** `GET /v1/nbbo/depth` — aggregated order-book depth per side. */
|
|
283
|
+
depth(params, options) {
|
|
284
|
+
return this.call(
|
|
285
|
+
{
|
|
286
|
+
method: "GET",
|
|
287
|
+
path: "/nbbo/depth",
|
|
288
|
+
query: {
|
|
289
|
+
id: params.id,
|
|
290
|
+
market_hash_name: params.marketHashName,
|
|
291
|
+
markets: params.markets,
|
|
292
|
+
depth: params.depth
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
options
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// src/resources/pricing.ts
|
|
301
|
+
var PricingResource = class extends BaseResource {
|
|
302
|
+
/** `GET /v1/pricing/:marketHashName` — full cross-market pricing snapshot. */
|
|
303
|
+
get(marketHashName, params = {}, options) {
|
|
304
|
+
return this.call(
|
|
305
|
+
{
|
|
306
|
+
method: "GET",
|
|
307
|
+
path: `/pricing/${encodePathSegment(marketHashName)}`,
|
|
308
|
+
query: { markets: params.markets }
|
|
309
|
+
},
|
|
310
|
+
options
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
/** `GET /v1/pricing/:marketHashName/listings` — individual listing samples. */
|
|
314
|
+
listings(marketHashName, params = {}, options) {
|
|
315
|
+
return this.call(
|
|
316
|
+
{
|
|
317
|
+
method: "GET",
|
|
318
|
+
path: `/pricing/${encodePathSegment(marketHashName)}/listings`,
|
|
319
|
+
query: { limit: params.limit, markets: params.markets }
|
|
320
|
+
},
|
|
321
|
+
options
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
// src/resources/schema.ts
|
|
327
|
+
var SchemaResource = class extends BaseResource {
|
|
328
|
+
/** Full catalog snapshot. A matching conditional ETag returns null. */
|
|
329
|
+
snapshot(params = {}, options) {
|
|
330
|
+
return this.call(
|
|
331
|
+
{ method: "GET", path: "/schema", ifNoneMatch: params.ifNoneMatch },
|
|
332
|
+
options
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
/** Look up one item by canonical id or exact name; v2 also accepts its game-scoped slug. */
|
|
336
|
+
get(idOrName, options) {
|
|
337
|
+
return this.call(
|
|
338
|
+
{ method: "GET", path: `/schema/items/${encodePathSegment(idOrName)}` },
|
|
339
|
+
options
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
/** One page of items changed after a catalog version or timestamp. */
|
|
343
|
+
changes(params, options) {
|
|
344
|
+
return this.call(
|
|
345
|
+
{
|
|
346
|
+
method: "GET",
|
|
347
|
+
path: "/schema/changes",
|
|
348
|
+
query: {
|
|
349
|
+
since: params.since,
|
|
350
|
+
cursor: params.cursor,
|
|
351
|
+
limit: params.limit
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
options
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
/** Iterate changes without moving the original version boundary while paging. */
|
|
358
|
+
async *changesEach(params, options) {
|
|
359
|
+
let cursor = params.cursor;
|
|
360
|
+
for (; ; ) {
|
|
361
|
+
const response = await this.changes({ ...params, cursor }, options);
|
|
362
|
+
for (const item of response.items) yield item;
|
|
363
|
+
const next = response.nextCursor;
|
|
364
|
+
if (!response.hasMore || next === null || next === cursor) return;
|
|
365
|
+
cursor = next;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
// src/game-client.ts
|
|
371
|
+
var GameClient = class {
|
|
372
|
+
constructor(http, game) {
|
|
373
|
+
this.game = game;
|
|
374
|
+
if (game !== "cs2" && game !== "rust") {
|
|
375
|
+
throw new ConfigurationError('The game must be "cs2" or "rust".');
|
|
376
|
+
}
|
|
377
|
+
this.pricing = new PricingResource(http, game);
|
|
378
|
+
this.history = new HistoryResource(http, game);
|
|
379
|
+
this.items = new ItemSearchResource(http, game);
|
|
380
|
+
this.nbbo = new NbboResource(http, game);
|
|
381
|
+
this.liquidity = new ItemLiquidityResource(http, game);
|
|
382
|
+
this.schema = new SchemaResource(http, game);
|
|
383
|
+
this.markets = new MarketsResource(http, game);
|
|
384
|
+
}
|
|
385
|
+
game;
|
|
386
|
+
pricing;
|
|
387
|
+
history;
|
|
388
|
+
items;
|
|
389
|
+
nbbo;
|
|
390
|
+
liquidity;
|
|
391
|
+
schema;
|
|
392
|
+
markets;
|
|
393
|
+
};
|
|
394
|
+
|
|
36
395
|
// src/version.ts
|
|
37
|
-
var VERSION = "0.
|
|
396
|
+
var VERSION = "0.4.0";
|
|
38
397
|
|
|
39
398
|
// src/config.ts
|
|
40
399
|
var DEFAULT_BASE_URL = "https://pricing.skinpricer.com/v1";
|
|
400
|
+
var DEFAULT_PUBLIC_BASE_URL = "https://api.skinpricer.com/v1";
|
|
41
401
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
402
|
+
function derivePublicBaseUrl(baseUrl) {
|
|
403
|
+
try {
|
|
404
|
+
const parsed = new URL(baseUrl);
|
|
405
|
+
if (parsed.hostname.startsWith("pricing.")) {
|
|
406
|
+
parsed.hostname = `api.${parsed.hostname.slice("pricing.".length)}`;
|
|
407
|
+
return parsed.toString().replace(/\/+$/, "");
|
|
408
|
+
}
|
|
409
|
+
} catch {
|
|
410
|
+
}
|
|
411
|
+
return DEFAULT_PUBLIC_BASE_URL;
|
|
412
|
+
}
|
|
42
413
|
var DEFAULT_RETRY = {
|
|
43
414
|
maxRetries: 2,
|
|
44
415
|
baseDelayMs: 250,
|
|
@@ -84,9 +455,13 @@ function resolveConfig(config) {
|
|
|
84
455
|
"A non-empty `apiKey` is required to construct SkinpricerClient."
|
|
85
456
|
);
|
|
86
457
|
}
|
|
458
|
+
const baseUrl = normalizeBaseUrl(config.baseUrl ?? DEFAULT_BASE_URL);
|
|
87
459
|
return {
|
|
88
460
|
apiKey: config.apiKey,
|
|
89
|
-
baseUrl
|
|
461
|
+
baseUrl,
|
|
462
|
+
publicBaseUrl: normalizeBaseUrl(
|
|
463
|
+
config.publicBaseUrl ?? derivePublicBaseUrl(baseUrl)
|
|
464
|
+
),
|
|
90
465
|
fetch: resolveFetch(config.fetch),
|
|
91
466
|
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
92
467
|
retry: resolveRetry(config.retry),
|
|
@@ -286,8 +661,10 @@ function tryJsonParse(text) {
|
|
|
286
661
|
return void 0;
|
|
287
662
|
}
|
|
288
663
|
}
|
|
289
|
-
async function parseResponse(response) {
|
|
664
|
+
async function parseResponse(response, allowNotModified = false) {
|
|
290
665
|
const meta = buildMeta(response);
|
|
666
|
+
if (allowNotModified && response.status === 304)
|
|
667
|
+
return { data: null, meta };
|
|
291
668
|
const text = await response.text();
|
|
292
669
|
if (response.ok) {
|
|
293
670
|
if (text.length === 0) {
|
|
@@ -310,15 +687,6 @@ async function parseResponse(response) {
|
|
|
310
687
|
throw errorFromResponse({ status: response.status, body, meta });
|
|
311
688
|
}
|
|
312
689
|
|
|
313
|
-
// src/utils/url.ts
|
|
314
|
-
function encodePathSegment(segment) {
|
|
315
|
-
return encodeURIComponent(segment);
|
|
316
|
-
}
|
|
317
|
-
function joinUrl(baseUrl, path) {
|
|
318
|
-
const normalizedPath = path.startsWith("/") ? path : `/${path}`;
|
|
319
|
-
return `${baseUrl}${normalizedPath}`;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
690
|
// src/http/query.ts
|
|
323
691
|
function serializeQuery(params) {
|
|
324
692
|
const search = new URLSearchParams();
|
|
@@ -342,19 +710,26 @@ function serializeQuery(params) {
|
|
|
342
710
|
// src/http/request-builder.ts
|
|
343
711
|
function buildRequest(config, input) {
|
|
344
712
|
const queryString = input.query ? serializeQuery(input.query) : "";
|
|
345
|
-
const url = joinUrl(config.baseUrl, input.path) + queryString;
|
|
713
|
+
const url = joinUrl(input.baseUrl ?? config.baseUrl, input.path) + queryString;
|
|
346
714
|
const headers = {
|
|
347
715
|
Accept: "application/json",
|
|
348
716
|
"User-Agent": config.userAgent,
|
|
349
717
|
"X-Skinpricer-Client": config.userAgent,
|
|
350
|
-
...
|
|
718
|
+
...Object.fromEntries(
|
|
719
|
+
Object.entries(config.headers).filter(
|
|
720
|
+
([name]) => name.toLowerCase() !== "authorization"
|
|
721
|
+
)
|
|
722
|
+
)
|
|
351
723
|
};
|
|
352
724
|
let body;
|
|
353
725
|
if (input.body !== void 0) {
|
|
354
726
|
body = JSON.stringify(input.body);
|
|
355
727
|
headers["Content-Type"] = "application/json";
|
|
356
728
|
}
|
|
357
|
-
|
|
729
|
+
if (input.authenticated !== false)
|
|
730
|
+
headers["Authorization"] = `${config.authScheme} ${config.apiKey}`;
|
|
731
|
+
if (input.ifNoneMatch !== void 0)
|
|
732
|
+
headers["If-None-Match"] = input.ifNoneMatch;
|
|
358
733
|
const prepared = { url, method: input.method, headers };
|
|
359
734
|
if (body !== void 0) prepared.body = body;
|
|
360
735
|
return prepared;
|
|
@@ -437,6 +812,16 @@ var HttpClient = class {
|
|
|
437
812
|
}
|
|
438
813
|
config;
|
|
439
814
|
throttleUntil = 0;
|
|
815
|
+
/** Base URL for keyless public-service endpoints (see {@link ResolvedConfig.publicBaseUrl}). */
|
|
816
|
+
get publicBaseUrl() {
|
|
817
|
+
return this.config.publicBaseUrl;
|
|
818
|
+
}
|
|
819
|
+
/** Selects an API version while retaining a configured gateway prefix. */
|
|
820
|
+
versionedBaseUrl(version, baseUrl = this.config.baseUrl) {
|
|
821
|
+
const url = new URL(baseUrl);
|
|
822
|
+
url.pathname = /\/v[0-9]+$/.test(url.pathname) ? url.pathname.replace(/\/v[0-9]+$/, `/${version}`) : `${url.pathname.replace(/\/$/, "")}/${version}`;
|
|
823
|
+
return url.toString().replace(/\/$/, "");
|
|
824
|
+
}
|
|
440
825
|
async request(input, options = {}) {
|
|
441
826
|
const prepared = buildRequest(this.config, input);
|
|
442
827
|
const retry = resolveRequestRetry(this.config.retry, options.retry);
|
|
@@ -452,46 +837,18 @@ var HttpClient = class {
|
|
|
452
837
|
url: prepared.url,
|
|
453
838
|
attempt
|
|
454
839
|
});
|
|
455
|
-
let response;
|
|
456
840
|
try {
|
|
457
|
-
response = await this.config.fetch(prepared.url, {
|
|
841
|
+
const response = await this.config.fetch(prepared.url, {
|
|
458
842
|
method: prepared.method,
|
|
459
843
|
headers: prepared.headers,
|
|
460
844
|
body: prepared.body,
|
|
461
845
|
signal: handle.signal
|
|
462
846
|
});
|
|
463
|
-
|
|
847
|
+
const parsed = await parseResponse(
|
|
848
|
+
response,
|
|
849
|
+
input.ifNoneMatch !== void 0
|
|
850
|
+
);
|
|
464
851
|
handle.cleanup();
|
|
465
|
-
if (callerSignal?.aborted && !handle.didTimeout()) {
|
|
466
|
-
throw abortError(callerSignal);
|
|
467
|
-
}
|
|
468
|
-
if (retry && shouldRetry({ method: input.method, attempt, retry, status: null })) {
|
|
469
|
-
const delayMs = retryDelayMs({
|
|
470
|
-
attempt,
|
|
471
|
-
retry,
|
|
472
|
-
retryAfterSeconds: null
|
|
473
|
-
});
|
|
474
|
-
await runHook(hooks.onRetry, {
|
|
475
|
-
method: input.method,
|
|
476
|
-
url: prepared.url,
|
|
477
|
-
attempt,
|
|
478
|
-
delayMs,
|
|
479
|
-
status: null
|
|
480
|
-
});
|
|
481
|
-
await sleep(delayMs, callerSignal);
|
|
482
|
-
attempt += 1;
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
if (handle.didTimeout()) {
|
|
486
|
-
throw new TimeoutError(`Request timed out after ${timeoutMs}ms`, {
|
|
487
|
-
cause: error
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
throw new NetworkError(networkMessage(error), { cause: error });
|
|
491
|
-
}
|
|
492
|
-
handle.cleanup();
|
|
493
|
-
try {
|
|
494
|
-
const parsed = await parseResponse(response);
|
|
495
852
|
this.recordRateLimit(parsed.meta.rateLimit);
|
|
496
853
|
await runHook(hooks.onResponse, {
|
|
497
854
|
method: input.method,
|
|
@@ -502,30 +859,32 @@ var HttpClient = class {
|
|
|
502
859
|
});
|
|
503
860
|
return parsed;
|
|
504
861
|
} catch (error) {
|
|
505
|
-
|
|
506
|
-
|
|
862
|
+
handle.cleanup();
|
|
863
|
+
if (callerSignal?.aborted && !handle.didTimeout())
|
|
864
|
+
throw abortError(callerSignal);
|
|
865
|
+
const failure = handle.didTimeout() ? new TimeoutError(`Request timed out after ${timeoutMs}ms`, {
|
|
866
|
+
cause: error
|
|
867
|
+
}) : error instanceof SkinpricerError ? error : new NetworkError(networkMessage(error), { cause: error });
|
|
868
|
+
if (failure instanceof RateLimitError) {
|
|
869
|
+
this.recordRateLimit(failure.rateLimit, failure.retryAfterSeconds);
|
|
507
870
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
retry,
|
|
512
|
-
status: error.status
|
|
513
|
-
})) {
|
|
514
|
-
const retryAfterSeconds = error instanceof RateLimitError ? error.retryAfterSeconds : error.rateLimit?.retryAfterSeconds ?? null;
|
|
871
|
+
const status = failure.status ?? null;
|
|
872
|
+
if (retry && shouldRetry({ method: input.method, attempt, retry, status })) {
|
|
873
|
+
const retryAfterSeconds = failure instanceof RateLimitError ? failure.retryAfterSeconds : failure.rateLimit?.retryAfterSeconds ?? null;
|
|
515
874
|
const delayMs = retryDelayMs({ attempt, retry, retryAfterSeconds });
|
|
516
875
|
await runHook(hooks.onRetry, {
|
|
517
876
|
method: input.method,
|
|
518
877
|
url: prepared.url,
|
|
519
878
|
attempt,
|
|
520
879
|
delayMs,
|
|
521
|
-
status
|
|
522
|
-
error
|
|
880
|
+
status,
|
|
881
|
+
error: failure
|
|
523
882
|
});
|
|
524
883
|
await sleep(delayMs, callerSignal);
|
|
525
884
|
attempt += 1;
|
|
526
885
|
continue;
|
|
527
886
|
}
|
|
528
|
-
throw
|
|
887
|
+
throw failure;
|
|
529
888
|
}
|
|
530
889
|
}
|
|
531
890
|
}
|
|
@@ -571,61 +930,36 @@ async function mapWithConcurrency(items, limit, fn) {
|
|
|
571
930
|
return results;
|
|
572
931
|
}
|
|
573
932
|
|
|
574
|
-
// src/meta.ts
|
|
575
|
-
var RESPONSE_META = /* @__PURE__ */ Symbol("skinpricer.responseMeta");
|
|
576
|
-
function attachMeta(data, meta) {
|
|
577
|
-
if (data !== null && typeof data === "object") {
|
|
578
|
-
Object.defineProperty(data, RESPONSE_META, {
|
|
579
|
-
value: meta,
|
|
580
|
-
enumerable: false,
|
|
581
|
-
writable: false,
|
|
582
|
-
configurable: true
|
|
583
|
-
});
|
|
584
|
-
}
|
|
585
|
-
return data;
|
|
586
|
-
}
|
|
587
|
-
function getMeta(value) {
|
|
588
|
-
if (value !== null && typeof value === "object") {
|
|
589
|
-
return value[RESPONSE_META];
|
|
590
|
-
}
|
|
591
|
-
return void 0;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
// src/resources/resource.ts
|
|
595
|
-
var BaseResource = class {
|
|
596
|
-
constructor(http) {
|
|
597
|
-
this.http = http;
|
|
598
|
-
}
|
|
599
|
-
http;
|
|
600
|
-
/** Performs a request and returns the data with {@link ResponseMeta} attached. */
|
|
601
|
-
async call(input, options) {
|
|
602
|
-
const { data, meta } = await this.http.request(input, options);
|
|
603
|
-
return attachMeta(data, meta);
|
|
604
|
-
}
|
|
605
|
-
};
|
|
606
|
-
|
|
607
933
|
// src/resources/aggregations.ts
|
|
608
934
|
var MAX_IDS_PER_REQUEST = 100;
|
|
609
935
|
var DEFAULT_BATCH_CONCURRENCY = 5;
|
|
610
936
|
var AggregationsResource = class extends BaseResource {
|
|
611
|
-
/** GET /v1/aggregations/min-prices — minimum sell price per market
|
|
937
|
+
/** GET /v1/aggregations/min-prices — minimum sell price per market. Pass up to 100 `ids` or `marketHashNames`. */
|
|
612
938
|
minPrices(params, options) {
|
|
613
939
|
return this.call(
|
|
614
940
|
{
|
|
615
941
|
method: "GET",
|
|
616
942
|
path: "/aggregations/min-prices",
|
|
617
|
-
query: {
|
|
943
|
+
query: {
|
|
944
|
+
ids: params.ids,
|
|
945
|
+
marketHashNames: params.marketHashNames,
|
|
946
|
+
markets: params.markets
|
|
947
|
+
}
|
|
618
948
|
},
|
|
619
949
|
options
|
|
620
950
|
);
|
|
621
951
|
}
|
|
622
|
-
/** GET /v1/aggregations/max-orders — maximum buy order per market
|
|
952
|
+
/** GET /v1/aggregations/max-orders — maximum buy order per market. Pass up to 100 `ids` or `marketHashNames`. */
|
|
623
953
|
maxOrders(params, options) {
|
|
624
954
|
return this.call(
|
|
625
955
|
{
|
|
626
956
|
method: "GET",
|
|
627
957
|
path: "/aggregations/max-orders",
|
|
628
|
-
query: {
|
|
958
|
+
query: {
|
|
959
|
+
ids: params.ids,
|
|
960
|
+
marketHashNames: params.marketHashNames,
|
|
961
|
+
markets: params.markets
|
|
962
|
+
}
|
|
629
963
|
},
|
|
630
964
|
options
|
|
631
965
|
);
|
|
@@ -798,82 +1132,6 @@ var Buff163Resource = class extends BaseResource {
|
|
|
798
1132
|
}
|
|
799
1133
|
};
|
|
800
1134
|
|
|
801
|
-
// src/resources/history.ts
|
|
802
|
-
function historyQuery(params) {
|
|
803
|
-
return {
|
|
804
|
-
from: params.from,
|
|
805
|
-
to: params.to,
|
|
806
|
-
markets: params.markets,
|
|
807
|
-
listingType: params.listingType,
|
|
808
|
-
salesWindow: params.salesWindow,
|
|
809
|
-
interval: params.interval
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
var HistoryResource = class extends BaseResource {
|
|
813
|
-
/** `GET /v1/pricing/:marketHashName/history` — aggregated time series. */
|
|
814
|
-
get(marketHashName, params = {}, options) {
|
|
815
|
-
return this.call(
|
|
816
|
-
{
|
|
817
|
-
method: "GET",
|
|
818
|
-
path: `/pricing/${encodePathSegment(marketHashName)}/history`,
|
|
819
|
-
query: historyQuery(params)
|
|
820
|
-
},
|
|
821
|
-
options
|
|
822
|
-
);
|
|
823
|
-
}
|
|
824
|
-
/** `GET /v1/pricing/:marketHashName/history/markets` — per-market series. */
|
|
825
|
-
byMarket(marketHashName, params = {}, options) {
|
|
826
|
-
return this.call(
|
|
827
|
-
{
|
|
828
|
-
method: "GET",
|
|
829
|
-
path: `/pricing/${encodePathSegment(marketHashName)}/history/markets`,
|
|
830
|
-
query: historyQuery(params)
|
|
831
|
-
},
|
|
832
|
-
options
|
|
833
|
-
);
|
|
834
|
-
}
|
|
835
|
-
};
|
|
836
|
-
|
|
837
|
-
// src/resources/items.ts
|
|
838
|
-
var ItemsResource = class extends BaseResource {
|
|
839
|
-
/** GET /v1/items — paginated item search with current pricing. */
|
|
840
|
-
search(params = {}, options) {
|
|
841
|
-
return this.call(
|
|
842
|
-
{
|
|
843
|
-
method: "GET",
|
|
844
|
-
path: "/items",
|
|
845
|
-
query: {
|
|
846
|
-
search: params.search,
|
|
847
|
-
markets: params.markets,
|
|
848
|
-
page: params.page,
|
|
849
|
-
perPage: params.perPage
|
|
850
|
-
}
|
|
851
|
-
},
|
|
852
|
-
options
|
|
853
|
-
);
|
|
854
|
-
}
|
|
855
|
-
/** GET /v1/items/all — every tracked item with latest prices (capped, unpaginated). */
|
|
856
|
-
all(options) {
|
|
857
|
-
return this.call(
|
|
858
|
-
{ method: "GET", path: "/items/all" },
|
|
859
|
-
options
|
|
860
|
-
);
|
|
861
|
-
}
|
|
862
|
-
/** Async iterator over every matching item, walking pages. */
|
|
863
|
-
async *searchEach(params = {}, options) {
|
|
864
|
-
let page = params.page ?? 1;
|
|
865
|
-
for (; ; ) {
|
|
866
|
-
const res = await this.search({ ...params, page }, options);
|
|
867
|
-
for (const item of res.data) {
|
|
868
|
-
yield item;
|
|
869
|
-
}
|
|
870
|
-
const next = res.pagination.nextPage;
|
|
871
|
-
if (next === null || next <= page) return;
|
|
872
|
-
page = next;
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
|
-
|
|
877
1135
|
// src/resources/market-analytics.ts
|
|
878
1136
|
var MarketAnalyticsResource = class extends BaseResource {
|
|
879
1137
|
/** `GET /v1/market-analytics/:marketHashName` — per-market analytics rows. */
|
|
@@ -889,61 +1147,16 @@ var MarketAnalyticsResource = class extends BaseResource {
|
|
|
889
1147
|
}
|
|
890
1148
|
};
|
|
891
1149
|
|
|
892
|
-
// src/resources/
|
|
893
|
-
var
|
|
894
|
-
|
|
895
|
-
get(params, options) {
|
|
896
|
-
return this.call(
|
|
897
|
-
{
|
|
898
|
-
method: "GET",
|
|
899
|
-
path: "/nbbo",
|
|
900
|
-
query: {
|
|
901
|
-
id: params.id,
|
|
902
|
-
market_hash_name: params.marketHashName,
|
|
903
|
-
markets: params.markets
|
|
904
|
-
}
|
|
905
|
-
},
|
|
906
|
-
options
|
|
907
|
-
);
|
|
908
|
-
}
|
|
909
|
-
/** `GET /v1/nbbo/depth` — aggregated order-book depth per side. */
|
|
910
|
-
depth(params, options) {
|
|
911
|
-
return this.call(
|
|
912
|
-
{
|
|
913
|
-
method: "GET",
|
|
914
|
-
path: "/nbbo/depth",
|
|
915
|
-
query: {
|
|
916
|
-
id: params.id,
|
|
917
|
-
market_hash_name: params.marketHashName,
|
|
918
|
-
markets: params.markets,
|
|
919
|
-
depth: params.depth
|
|
920
|
-
}
|
|
921
|
-
},
|
|
922
|
-
options
|
|
923
|
-
);
|
|
924
|
-
}
|
|
925
|
-
};
|
|
926
|
-
|
|
927
|
-
// src/resources/pricing.ts
|
|
928
|
-
var PricingResource = class extends BaseResource {
|
|
929
|
-
/** `GET /v1/pricing/:marketHashName` — full cross-market pricing snapshot. */
|
|
930
|
-
get(marketHashName, params = {}, options) {
|
|
931
|
-
return this.call(
|
|
932
|
-
{
|
|
933
|
-
method: "GET",
|
|
934
|
-
path: `/pricing/${encodePathSegment(marketHashName)}`,
|
|
935
|
-
query: { markets: params.markets }
|
|
936
|
-
},
|
|
937
|
-
options
|
|
938
|
-
);
|
|
939
|
-
}
|
|
940
|
-
/** `GET /v1/pricing/:marketHashName/listings` — individual listing samples. */
|
|
941
|
-
listings(marketHashName, params = {}, options) {
|
|
1150
|
+
// src/resources/prices.ts
|
|
1151
|
+
var PricesResource = class extends BaseResource {
|
|
1152
|
+
latestAll(params, options) {
|
|
942
1153
|
return this.call(
|
|
943
1154
|
{
|
|
944
1155
|
method: "GET",
|
|
945
|
-
path:
|
|
946
|
-
|
|
1156
|
+
path: "/prices/latest",
|
|
1157
|
+
baseUrl: this.http.versionedBaseUrl("v2"),
|
|
1158
|
+
query: { game: params.game },
|
|
1159
|
+
ifNoneMatch: params.ifNoneMatch
|
|
947
1160
|
},
|
|
948
1161
|
options
|
|
949
1162
|
);
|
|
@@ -996,6 +1209,14 @@ var SkinpricerClient = class {
|
|
|
996
1209
|
marketAnalytics;
|
|
997
1210
|
attributePrices;
|
|
998
1211
|
buff163;
|
|
1212
|
+
liquidity;
|
|
1213
|
+
markets;
|
|
1214
|
+
schema;
|
|
1215
|
+
prices;
|
|
1216
|
+
/** Access the v2 endpoints supported by the selected game. */
|
|
1217
|
+
forGame(game) {
|
|
1218
|
+
return new GameClient(this.httpClient, game);
|
|
1219
|
+
}
|
|
999
1220
|
httpClient;
|
|
1000
1221
|
constructor(config) {
|
|
1001
1222
|
this.httpClient = new HttpClient(resolveConfig(config));
|
|
@@ -1010,6 +1231,10 @@ var SkinpricerClient = class {
|
|
|
1010
1231
|
this.marketAnalytics = new MarketAnalyticsResource(this.httpClient);
|
|
1011
1232
|
this.attributePrices = new AttributePricesResource(this.httpClient);
|
|
1012
1233
|
this.buff163 = new Buff163Resource(this.httpClient);
|
|
1234
|
+
this.liquidity = new LiquidityResource(this.httpClient);
|
|
1235
|
+
this.markets = new MarketsResource(this.httpClient);
|
|
1236
|
+
this.schema = new SchemaResource(this.httpClient);
|
|
1237
|
+
this.prices = new PricesResource(this.httpClient);
|
|
1013
1238
|
}
|
|
1014
1239
|
};
|
|
1015
1240
|
|
|
@@ -1019,6 +1244,7 @@ var KNOWN_MARKETS = [
|
|
|
1019
1244
|
"skindeck",
|
|
1020
1245
|
"buff163",
|
|
1021
1246
|
"csfloat",
|
|
1247
|
+
"csdeals",
|
|
1022
1248
|
"marketcsgo",
|
|
1023
1249
|
"cstrade",
|
|
1024
1250
|
"dmarket",
|
|
@@ -1028,9 +1254,15 @@ var KNOWN_MARKETS = [
|
|
|
1028
1254
|
"whitemarket",
|
|
1029
1255
|
"waxpeer",
|
|
1030
1256
|
"lootfarm",
|
|
1257
|
+
"rapidskins",
|
|
1258
|
+
"avanmarket",
|
|
1031
1259
|
"tradeit-store",
|
|
1032
1260
|
"tradeit-trade",
|
|
1033
|
-
"steamcommunity"
|
|
1261
|
+
"steamcommunity",
|
|
1262
|
+
"youpin",
|
|
1263
|
+
"mannco-store",
|
|
1264
|
+
"rusttm",
|
|
1265
|
+
"rustskins"
|
|
1034
1266
|
];
|
|
1035
1267
|
var ATTRIBUTE_MARKETS = [
|
|
1036
1268
|
"buff163",
|
|
@@ -1040,6 +1272,41 @@ var ATTRIBUTE_MARKETS = [
|
|
|
1040
1272
|
"dmarket"
|
|
1041
1273
|
];
|
|
1042
1274
|
|
|
1275
|
+
// src/types/liquidity.ts
|
|
1276
|
+
var LIQUIDITY_BADGES = [
|
|
1277
|
+
"EXTREMELY_LIQUID",
|
|
1278
|
+
"VERY_LIQUID",
|
|
1279
|
+
"LIQUID",
|
|
1280
|
+
"ILLIQUID",
|
|
1281
|
+
"VERY_ILLIQUID",
|
|
1282
|
+
"EXTREMELY_ILLIQUID",
|
|
1283
|
+
"UNTRADED",
|
|
1284
|
+
"INSUFFICIENT_DATA"
|
|
1285
|
+
];
|
|
1286
|
+
var LIQUIDITY_CONFIDENCE = [
|
|
1287
|
+
"HIGH",
|
|
1288
|
+
"MEDIUM",
|
|
1289
|
+
"LOW",
|
|
1290
|
+
"CRITICAL"
|
|
1291
|
+
];
|
|
1292
|
+
var LIQUIDITY_LABELS = [
|
|
1293
|
+
"extremely_liquid",
|
|
1294
|
+
"very_liquid",
|
|
1295
|
+
"liquid",
|
|
1296
|
+
"illiquid",
|
|
1297
|
+
"very_illiquid",
|
|
1298
|
+
"extremely_illiquid",
|
|
1299
|
+
"unknown"
|
|
1300
|
+
];
|
|
1301
|
+
var SUPPORTED_LIQUIDITY_MARKETS = [
|
|
1302
|
+
"skinport",
|
|
1303
|
+
"marketcsgo",
|
|
1304
|
+
"dmarket",
|
|
1305
|
+
"steamcommunity",
|
|
1306
|
+
"csfloat"
|
|
1307
|
+
];
|
|
1308
|
+
var SUPPORTED_RUST_LIQUIDITY_MARKETS = ["rusttm", "skinport"];
|
|
1309
|
+
|
|
1043
1310
|
// src/utils/money.ts
|
|
1044
1311
|
function centsToUsd(cents) {
|
|
1045
1312
|
return cents / 100;
|
|
@@ -1056,6 +1323,6 @@ function parseIsoDate(value) {
|
|
|
1056
1323
|
return new Date(value);
|
|
1057
1324
|
}
|
|
1058
1325
|
|
|
1059
|
-
export { APIError, ATTRIBUTE_MARKETS, AggregationsResource, ArbitrageResource, AttributePricesResource, AuthenticationError, BaseResource, Buff163Resource, ConfigurationError, DEFAULT_BASE_URL, DEFAULT_RETRY, DEFAULT_TIMEOUT_MS, FeatureNotAvailableError, HistoryResource, ItemsResource, KNOWN_MARKETS, MarketAnalyticsResource, NbboResource, NetworkError, NotFoundError, ParseError, PermissionError, PricingResource, RESPONSE_META, RateLimitError, RecommendationsResource, ServerError, SkinpricerClient, SkinpricerError, StatusResource, TimeoutError, VERSION, ValidationError, centsToUsd, chunk, errorFromResponse, formatUsd, getMeta, mapWithConcurrency, parseIsoDate, resolveConfig };
|
|
1326
|
+
export { APIError, ATTRIBUTE_MARKETS, AggregationsResource, ArbitrageResource, AttributePricesResource, AuthenticationError, BaseResource, Buff163Resource, ConfigurationError, DEFAULT_BASE_URL, DEFAULT_PUBLIC_BASE_URL, DEFAULT_RETRY, DEFAULT_TIMEOUT_MS, FeatureNotAvailableError, GameClient, HistoryResource, ItemsResource, KNOWN_MARKETS, LIQUIDITY_BADGES, LIQUIDITY_CONFIDENCE, LIQUIDITY_LABELS, LiquidityResource, MarketAnalyticsResource, MarketsResource, NbboResource, NetworkError, NotFoundError, ParseError, PermissionError, PricesResource, PricingResource, RESPONSE_META, RateLimitError, RecommendationsResource, SUPPORTED_LIQUIDITY_MARKETS, SUPPORTED_RUST_LIQUIDITY_MARKETS, SchemaResource, ServerError, SkinpricerClient, SkinpricerError, StatusResource, TimeoutError, VERSION, ValidationError, centsToUsd, chunk, errorFromResponse, formatUsd, getMeta, mapWithConcurrency, parseIsoDate, resolveConfig };
|
|
1060
1327
|
//# sourceMappingURL=index.js.map
|
|
1061
1328
|
//# sourceMappingURL=index.js.map
|