@skinpricer/sdk 0.5.0 → 0.6.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/dist/index.cjs CHANGED
@@ -83,14 +83,18 @@ var BaseResource = class {
83
83
  http;
84
84
  game;
85
85
  /** Performs a request and returns the data with {@link ResponseMeta} attached. */
86
- async call(input, options) {
86
+ async call(input, options, readBody) {
87
87
  assertPathSegments(input.path);
88
88
  const scoped = this.game === void 0 ? input : {
89
89
  ...input,
90
90
  baseUrl: this.http.versionedBaseUrl("v2", input.baseUrl),
91
91
  query: { ...input.query, game: this.game }
92
92
  };
93
- const { data, meta } = await this.http.request(scoped, options);
93
+ const { data, meta } = await this.http.request(
94
+ scoped,
95
+ options,
96
+ readBody
97
+ );
94
98
  return attachMeta(data, meta);
95
99
  }
96
100
  };
@@ -103,7 +107,9 @@ function historyQuery(params) {
103
107
  markets: params.markets,
104
108
  listingType: params.listingType,
105
109
  salesWindow: params.salesWindow,
106
- interval: params.interval
110
+ interval: params.interval,
111
+ basis: params.basis,
112
+ currency: params.currency
107
113
  };
108
114
  }
109
115
  var HistoryResource = class extends BaseResource {
@@ -130,6 +136,43 @@ var HistoryResource = class extends BaseResource {
130
136
  );
131
137
  }
132
138
  };
139
+ var GameHistoryResource = class extends HistoryResource {
140
+ get(marketHashName, params = {}, options) {
141
+ return super.get(marketHashName, params, options);
142
+ }
143
+ byMarket(marketHashName, params = {}, options) {
144
+ return super.byMarket(marketHashName, params, options);
145
+ }
146
+ /**
147
+ * `POST /v2/pricing/history/batch` — the aggregate series of {@link get} for
148
+ * up to 100 items. Entries that do not resolve are listed in `errors` and
149
+ * the rest are still served.
150
+ *
151
+ * Items x buckets may not exceed 10,000 points (twice the buckets for
152
+ * `SALE_HISTORY`), and a batch in 10m buckets takes at most 25 items; the
153
+ * API rejects a larger batch with a 400 error. Each distinct item costs 5
154
+ * rate-limit units.
155
+ */
156
+ batch(params, options) {
157
+ return this.call(
158
+ {
159
+ method: "POST",
160
+ path: "/pricing/history/batch",
161
+ body: {
162
+ items: params.items,
163
+ from: params.from,
164
+ to: params.to,
165
+ interval: params.interval,
166
+ listingType: params.listingType,
167
+ salesWindow: params.salesWindow,
168
+ basis: params.basis,
169
+ currency: params.currency
170
+ }
171
+ },
172
+ options
173
+ );
174
+ }
175
+ };
133
176
 
134
177
  // src/resources/items.ts
135
178
  var ItemSearchResource = class extends BaseResource {
@@ -265,6 +308,14 @@ var MarketsResource = class extends BaseResource {
265
308
  };
266
309
 
267
310
  // src/resources/nbbo.ts
311
+ function nbboQuery(params) {
312
+ return {
313
+ id: params.id,
314
+ marketHashName: params.marketHashName,
315
+ markets: params.markets,
316
+ currency: params.currency
317
+ };
318
+ }
268
319
  var NbboResource = class extends BaseResource {
269
320
  /** `GET /v1/nbbo` — best bid/ask across markets. Pass `id` or `marketHashName`. */
270
321
  get(params, options) {
@@ -272,11 +323,7 @@ var NbboResource = class extends BaseResource {
272
323
  {
273
324
  method: "GET",
274
325
  path: "/nbbo",
275
- query: {
276
- id: params.id,
277
- marketHashName: params.marketHashName,
278
- markets: params.markets
279
- }
326
+ query: nbboQuery(params)
280
327
  },
281
328
  options
282
329
  );
@@ -298,8 +345,16 @@ var NbboResource = class extends BaseResource {
298
345
  );
299
346
  }
300
347
  };
348
+ var GameNbboResource = class extends NbboResource {
349
+ get(params, options) {
350
+ return super.get(params, options);
351
+ }
352
+ };
301
353
 
302
354
  // src/resources/pricing.ts
355
+ function currentPriceQuery(params) {
356
+ return { markets: params.markets, currency: params.currency };
357
+ }
303
358
  var PricingResource = class extends BaseResource {
304
359
  /** `GET /v1/pricing/:marketHashName` — full cross-market pricing snapshot. */
305
360
  get(marketHashName, params = {}, options) {
@@ -307,7 +362,7 @@ var PricingResource = class extends BaseResource {
307
362
  {
308
363
  method: "GET",
309
364
  path: `/pricing/${encodePathSegment(marketHashName)}`,
310
- query: { markets: params.markets }
365
+ query: currentPriceQuery(params)
311
366
  },
312
367
  options
313
368
  );
@@ -324,6 +379,11 @@ var PricingResource = class extends BaseResource {
324
379
  );
325
380
  }
326
381
  };
382
+ var GamePricingResource = class extends PricingResource {
383
+ get(marketHashName, params = {}, options) {
384
+ return super.get(marketHashName, params, options);
385
+ }
386
+ };
327
387
 
328
388
  // src/resources/schema.ts
329
389
  var SchemaResource = class extends BaseResource {
@@ -376,10 +436,10 @@ var GameClient = class {
376
436
  if (game !== "cs2" && game !== "rust") {
377
437
  throw new ConfigurationError('The game must be "cs2" or "rust".');
378
438
  }
379
- this.pricing = new PricingResource(http, game);
380
- this.history = new HistoryResource(http, game);
439
+ this.pricing = new GamePricingResource(http, game);
440
+ this.history = new GameHistoryResource(http, game);
381
441
  this.items = new ItemSearchResource(http, game);
382
- this.nbbo = new NbboResource(http, game);
442
+ this.nbbo = new GameNbboResource(http, game);
383
443
  this.liquidity = new ItemLiquidityResource(http, game);
384
444
  this.schema = new SchemaResource(http, game);
385
445
  this.markets = new MarketsResource(http, game);
@@ -395,7 +455,7 @@ var GameClient = class {
395
455
  };
396
456
 
397
457
  // src/version.ts
398
- var VERSION = "0.5.0";
458
+ var VERSION = "0.6.0";
399
459
 
400
460
  // src/config.ts
401
461
  var DEFAULT_BASE_URL = "https://pricing.skinpricer.com/v1";
@@ -429,6 +489,15 @@ function resolveFetch(custom) {
429
489
  "No global `fetch` is available. Provide a `fetch` implementation in the client config (required on Node < 18 or non-fetch runtimes)."
430
490
  );
431
491
  }
492
+ function globalWebSocket(url, headers) {
493
+ const WebSocket = globalThis.WebSocket;
494
+ if (typeof WebSocket !== "function") {
495
+ throw new ConfigurationError(
496
+ "No global `WebSocket` is available. Provide `webSocket` in the client config (required on Node < 22), for example with the ws package."
497
+ );
498
+ }
499
+ return new WebSocket(url, { headers });
500
+ }
432
501
  function resolveRetry(retry) {
433
502
  if (retry === false) return null;
434
503
  if (retry === void 0) return DEFAULT_RETRY;
@@ -465,6 +534,7 @@ function resolveConfig(config) {
465
534
  config.publicBaseUrl ?? derivePublicBaseUrl(baseUrl)
466
535
  ),
467
536
  fetch: resolveFetch(config.fetch),
537
+ webSocket: config.webSocket ?? globalWebSocket,
468
538
  timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS,
469
539
  retry: resolveRetry(config.retry),
470
540
  headers: { ...config.headers },
@@ -676,10 +746,12 @@ function tryJsonParse(text) {
676
746
  return void 0;
677
747
  }
678
748
  }
679
- async function parseResponse(response, allowNotModified = false) {
749
+ async function parseResponse(response, allowNotModified = false, readBody, signal = new AbortController().signal) {
680
750
  const meta = buildMeta(response);
681
751
  if (allowNotModified && response.status === 304)
682
752
  return { data: null, meta };
753
+ if (readBody !== void 0 && response.ok)
754
+ return { data: await readBody(response, meta, signal), meta };
683
755
  const text = await response.text();
684
756
  if (response.ok) {
685
757
  if (text.length === 0) {
@@ -837,7 +909,13 @@ var HttpClient = class {
837
909
  url.pathname = /\/v[0-9]+$/.test(url.pathname) ? url.pathname.replace(/\/v[0-9]+$/, `/${version}`) : `${url.pathname.replace(/\/$/, "")}/${version}`;
838
910
  return url.toString().replace(/\/$/, "");
839
911
  }
840
- async request(input, options = {}) {
912
+ /** Opens a WebSocket to a GET route, sending the request's headers. */
913
+ openWebSocket(input) {
914
+ const { url, headers } = buildRequest(this.config, input);
915
+ const open = this.config.webSocket ?? globalWebSocket;
916
+ return open(url.replace(/^http/, "ws"), headers);
917
+ }
918
+ async request(input, options = {}, readBody) {
841
919
  const prepared = buildRequest(this.config, input);
842
920
  const retry = resolveRequestRetry(this.config.retry, options.retry);
843
921
  const timeoutMs = options.timeoutMs ?? this.config.timeoutMs;
@@ -861,7 +939,9 @@ var HttpClient = class {
861
939
  });
862
940
  const parsed = await parseResponse(
863
941
  response,
864
- input.ifNoneMatch !== void 0
942
+ input.ifNoneMatch !== void 0,
943
+ readBody,
944
+ handle.signal
865
945
  );
866
946
  handle.cleanup();
867
947
  this.recordRateLimit(parsed.meta.rateLimit);
@@ -1162,7 +1242,410 @@ var MarketAnalyticsResource = class extends BaseResource {
1162
1242
  }
1163
1243
  };
1164
1244
 
1245
+ // src/http/ndjson.ts
1246
+ var isGzip = (bytes, at) => bytes[at] === 31 && bytes[at + 1] === 139 && bytes[at + 2] === 8;
1247
+ async function gunzip(bytes, signal) {
1248
+ const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("gzip"), { signal });
1249
+ return new Uint8Array(await new Response(stream).arrayBuffer());
1250
+ }
1251
+ async function ndjsonText(response, signal) {
1252
+ const bytes = new Uint8Array(await response.arrayBuffer());
1253
+ if (!isGzip(bytes, 0)) return new TextDecoder().decode(bytes);
1254
+ const decoder = new TextDecoder();
1255
+ let text = "";
1256
+ let start = 0;
1257
+ while (start < bytes.length) {
1258
+ let end = start;
1259
+ for (; ; ) {
1260
+ end += 1;
1261
+ while (end < bytes.length && !isGzip(bytes, end)) end += 1;
1262
+ try {
1263
+ text += decoder.decode(await gunzip(bytes.slice(start, end), signal), {
1264
+ stream: true
1265
+ });
1266
+ break;
1267
+ } catch (error) {
1268
+ if (end >= bytes.length || signal.aborted) throw error;
1269
+ }
1270
+ }
1271
+ start = end;
1272
+ }
1273
+ return text + decoder.decode();
1274
+ }
1275
+ async function readNdjsonRows(response, meta, signal, fileName) {
1276
+ const text = await ndjsonText(response, signal);
1277
+ const rows = [];
1278
+ for (const line of text.split("\n")) {
1279
+ if (line.length === 0) continue;
1280
+ try {
1281
+ rows.push(JSON.parse(line));
1282
+ } catch (cause) {
1283
+ throw new ParseError(`Failed to parse a ${fileName} line.`, {
1284
+ status: meta.status,
1285
+ responseBody: line,
1286
+ cause,
1287
+ rateLimit: meta.rateLimit,
1288
+ requestId: meta.requestId
1289
+ });
1290
+ }
1291
+ }
1292
+ signal.throwIfAborted();
1293
+ return rows;
1294
+ }
1295
+
1296
+ // src/latest-prices-mirror.ts
1297
+ var RECENT_LINKS = 1024;
1298
+ var MAX_FAILED_OPENS = 10;
1299
+ var MAX_RECONNECT_DELAY_MS = 3e4;
1300
+ var CLOSE_KEY_NOT_ADMITTED = 4003;
1301
+ function cursorVersion(cursor) {
1302
+ return cursor.trim().replace(/^W\//, "").replace(/^"(.*)"$/, "$1");
1303
+ }
1304
+ function isFeedReset(error) {
1305
+ return error instanceof APIError && error.status === 410;
1306
+ }
1307
+ function messageText(data) {
1308
+ if (typeof data === "string") return data;
1309
+ if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
1310
+ return new TextDecoder().decode(data);
1311
+ }
1312
+ throw new ParseError("The price stream sent a message that is not text.");
1313
+ }
1314
+ function replacePoint(points, market, value) {
1315
+ const index = points.findIndex((point) => point.market === market);
1316
+ if (value === null) {
1317
+ if (index >= 0) points.splice(index, 1);
1318
+ } else if (index >= 0) {
1319
+ points[index] = value;
1320
+ } else {
1321
+ points.push(value);
1322
+ }
1323
+ }
1324
+ var LatestPricesMirror = class {
1325
+ constructor(prices, params) {
1326
+ this.prices = prices;
1327
+ const { game, ...given } = params;
1328
+ const list = (values, lower = false) => {
1329
+ const kept = (values ?? []).map((value) => lower ? value.trim().toLowerCase() : value.trim()).filter((value) => value !== "");
1330
+ return kept.length > 0 ? kept : void 0;
1331
+ };
1332
+ const markets = list(given.markets, true);
1333
+ const items = list(given.items);
1334
+ const sides = list(given.sides, true);
1335
+ this.game = game;
1336
+ this.filter = { markets, items, sides, best: given.best };
1337
+ if (markets) this.marketSet = new Set(markets);
1338
+ if (items) this.itemSet = new Set(items);
1339
+ this.asks = !sides || sides.includes("ask");
1340
+ this.bids = !sides || sides.includes("bid");
1341
+ this.best = given.best ?? !markets;
1342
+ }
1343
+ prices;
1344
+ game;
1345
+ filter;
1346
+ marketSet;
1347
+ itemSet;
1348
+ asks;
1349
+ bids;
1350
+ best;
1351
+ byId = /* @__PURE__ */ new Map();
1352
+ applied = /* @__PURE__ */ new Set();
1353
+ envelope = {};
1354
+ generatedAt = "";
1355
+ version = null;
1356
+ /** The version of the snapshot the copy equals, or null before a snapshot loads. */
1357
+ get cursor() {
1358
+ return this.version;
1359
+ }
1360
+ get size() {
1361
+ return this.byId.size;
1362
+ }
1363
+ item(canonicalItemId) {
1364
+ return this.byId.get(canonicalItemId);
1365
+ }
1366
+ items() {
1367
+ return this.byId.values();
1368
+ }
1369
+ /** The copy in snapshot form, items ordered by `canonicalItemId`. */
1370
+ toSnapshot() {
1371
+ const items = [...this.byId.values()].sort(
1372
+ (a, b) => a.canonicalItemId < b.canonicalItemId ? -1 : a.canonicalItemId > b.canonicalItemId ? 1 : 0
1373
+ );
1374
+ return {
1375
+ generatedAt: this.generatedAt,
1376
+ game: this.game,
1377
+ ...this.envelope,
1378
+ items,
1379
+ itemCount: items.length
1380
+ };
1381
+ }
1382
+ /**
1383
+ * Replaces the copy with a `latestAll()` snapshot read without `currency`
1384
+ * or `include`. `cursor` is its
1385
+ * ETag, or the `to` of the last link applied to a copy saved earlier.
1386
+ */
1387
+ load(snapshot, cursor) {
1388
+ const envelope = { ...snapshot };
1389
+ for (const key of ["generatedAt", "game", "items", "itemCount"]) {
1390
+ delete envelope[key];
1391
+ }
1392
+ this.envelope = envelope;
1393
+ this.generatedAt = snapshot.generatedAt;
1394
+ this.byId.clear();
1395
+ this.applied.clear();
1396
+ for (const item of snapshot.items) {
1397
+ if (this.itemSet && !this.itemSet.has(item.canonicalItemId)) continue;
1398
+ this.byId.set(item.canonicalItemId, {
1399
+ ...item,
1400
+ bestAsk: this.best && this.asks ? item.bestAsk : null,
1401
+ bestBid: this.best && this.bids ? item.bestBid : null,
1402
+ markets: this.asks ? item.markets.filter(this.selected, this) : [],
1403
+ buyOrders: this.bids ? item.buyOrders.filter(this.selected, this) : []
1404
+ });
1405
+ }
1406
+ this.version = cursorVersion(cursor);
1407
+ }
1408
+ /**
1409
+ * Applies one link and moves the cursor to its `to`. Returns false for a
1410
+ * link already applied. A link that does not start at the cursor throws,
1411
+ * and the copy then needs a new snapshot.
1412
+ */
1413
+ apply(link) {
1414
+ const to = cursorVersion(link.to);
1415
+ if (this.applied.has(to)) return false;
1416
+ if (this.version === null || cursorVersion(link.from) !== this.version) {
1417
+ throw new SkinpricerError(
1418
+ `The link from ${link.from} does not continue the copy at ${this.version ?? "no snapshot"}.`
1419
+ );
1420
+ }
1421
+ this.version = null;
1422
+ for (const change of link.changes) this.applyChange(change);
1423
+ if (link.envelope) this.envelope = { ...link.envelope };
1424
+ this.generatedAt = link.generatedAt;
1425
+ this.version = to;
1426
+ this.applied.add(to);
1427
+ if (this.applied.size > RECENT_LINKS) {
1428
+ this.applied.delete(this.applied.values().next().value);
1429
+ }
1430
+ return true;
1431
+ }
1432
+ /** Loads a new default snapshot of the game. */
1433
+ async reset(options) {
1434
+ const snapshot = await this.prices.latestAll({ game: this.game }, options);
1435
+ const etag = getMeta(snapshot)?.headers.get("etag");
1436
+ if (!etag) {
1437
+ throw new ParseError("The price snapshot has no ETag to resume from.");
1438
+ }
1439
+ this.load(snapshot, etag);
1440
+ }
1441
+ /**
1442
+ * Brings the copy up to date over HTTP: loads a snapshot when there is
1443
+ * none or the feed answers with a reset, then applies every link after
1444
+ * the cursor.
1445
+ */
1446
+ async sync(options) {
1447
+ const result = { snapshot: false, links: [] };
1448
+ if (this.version === null) {
1449
+ await this.reset(options);
1450
+ result.snapshot = true;
1451
+ }
1452
+ for (; ; ) {
1453
+ let page;
1454
+ try {
1455
+ page = await this.prices.changes(
1456
+ { ...this.filter, game: this.game, since: this.cursorOrThrow() },
1457
+ options
1458
+ );
1459
+ } catch (error) {
1460
+ if (!isFeedReset(error) || result.snapshot) throw error;
1461
+ await this.reset(options);
1462
+ result.snapshot = true;
1463
+ result.links = [];
1464
+ continue;
1465
+ }
1466
+ for (const link of page.links) {
1467
+ if (this.apply(link)) result.links.push(link);
1468
+ }
1469
+ if (page.complete || page.links.length === 0) return result;
1470
+ }
1471
+ }
1472
+ /**
1473
+ * Keeps the copy current over the WebSocket until `signal` aborts. It
1474
+ * resumes from the cursor after a disconnect and loads a new snapshot
1475
+ * after a reset. It rejects when the key is no longer admitted, when the
1476
+ * stream cannot be opened 10 times in a row, or when a callback throws.
1477
+ */
1478
+ async stream(options = {}) {
1479
+ const { signal } = options;
1480
+ let failures = 0;
1481
+ let reason = null;
1482
+ try {
1483
+ while (!signal?.aborted) {
1484
+ if (this.version === null) {
1485
+ await this.reset({ signal });
1486
+ options.onSnapshot?.(reason);
1487
+ reason = null;
1488
+ if (signal?.aborted) return;
1489
+ }
1490
+ const end = await this.connect(options, (next) => {
1491
+ reason = next;
1492
+ });
1493
+ if (signal?.aborted) return;
1494
+ if (end.kind === "failed") throw end.error;
1495
+ if (end.code === CLOSE_KEY_NOT_ADMITTED) {
1496
+ throw new PermissionError(
1497
+ "The API key is no longer admitted to the price stream."
1498
+ );
1499
+ }
1500
+ failures = end.opened ? 0 : failures + 1;
1501
+ if (failures >= MAX_FAILED_OPENS) {
1502
+ throw new NetworkError(
1503
+ `The price stream could not be opened ${failures} times in a row.`
1504
+ );
1505
+ }
1506
+ await sleep(
1507
+ Math.min(1e3 * 2 ** failures, MAX_RECONNECT_DELAY_MS),
1508
+ signal
1509
+ );
1510
+ }
1511
+ } catch (error) {
1512
+ if (signal?.aborted) return;
1513
+ throw error;
1514
+ }
1515
+ }
1516
+ connect(options, onReset) {
1517
+ const { signal } = options;
1518
+ return new Promise((resolve) => {
1519
+ let opened = false;
1520
+ let failure = null;
1521
+ const socket = this.prices.stream({
1522
+ ...this.filter,
1523
+ game: this.game,
1524
+ since: this.cursorOrThrow()
1525
+ });
1526
+ const onAbort = () => socket.close(1e3);
1527
+ signal?.addEventListener("abort", onAbort, { once: true });
1528
+ if (signal?.aborted) onAbort();
1529
+ socket.addEventListener("error", () => {
1530
+ });
1531
+ socket.addEventListener("message", (event) => {
1532
+ if (failure) return;
1533
+ opened = true;
1534
+ let applied = null;
1535
+ try {
1536
+ const message = JSON.parse(messageText(event.data));
1537
+ if (message.type === "reset") {
1538
+ this.version = null;
1539
+ onReset(message.reason);
1540
+ } else if (message.type === "link") {
1541
+ const link = message;
1542
+ if (this.apply(link)) applied = link;
1543
+ }
1544
+ } catch {
1545
+ this.version = null;
1546
+ socket.close(1e3);
1547
+ return;
1548
+ }
1549
+ if (!applied) return;
1550
+ try {
1551
+ options.onLink?.(applied);
1552
+ } catch (error) {
1553
+ failure = { error };
1554
+ socket.close(1e3);
1555
+ }
1556
+ });
1557
+ socket.addEventListener("close", (event) => {
1558
+ signal?.removeEventListener("abort", onAbort);
1559
+ if (event.code === 4009) this.version = null;
1560
+ resolve(
1561
+ failure ? { kind: "failed", error: failure.error } : { kind: "closed", code: event.code ?? 1006, opened }
1562
+ );
1563
+ });
1564
+ });
1565
+ }
1566
+ selected(point) {
1567
+ return !this.marketSet || this.marketSet.has(point.market.toLowerCase());
1568
+ }
1569
+ cursorOrThrow() {
1570
+ if (this.version === null) {
1571
+ throw new SkinpricerError("The copy has no snapshot loaded.");
1572
+ }
1573
+ return this.version;
1574
+ }
1575
+ itemOf(change) {
1576
+ const item = this.byId.get(change.item);
1577
+ if (!item) {
1578
+ throw new SkinpricerError(
1579
+ `Change ${change.id} is for item ${change.item}, which the copy does not hold.`
1580
+ );
1581
+ }
1582
+ return item;
1583
+ }
1584
+ applyChange(change) {
1585
+ switch (change.field) {
1586
+ case "name": {
1587
+ if (change.value === null) {
1588
+ this.byId.delete(change.item);
1589
+ return;
1590
+ }
1591
+ const item = this.byId.get(change.item);
1592
+ if (item) {
1593
+ item.name = change.value;
1594
+ } else {
1595
+ this.byId.set(change.item, {
1596
+ name: change.value,
1597
+ canonicalItemId: change.item,
1598
+ bestAsk: null,
1599
+ bestBid: null,
1600
+ markets: [],
1601
+ buyOrders: []
1602
+ });
1603
+ }
1604
+ return;
1605
+ }
1606
+ case "bestAsk":
1607
+ case "bestBid":
1608
+ this.itemOf(change)[change.field] = change.value;
1609
+ return;
1610
+ case "markets":
1611
+ replacePoint(this.itemOf(change).markets, change.market, change.value);
1612
+ return;
1613
+ case "buyOrders":
1614
+ replacePoint(
1615
+ this.itemOf(change).buyOrders,
1616
+ change.market,
1617
+ change.value
1618
+ );
1619
+ return;
1620
+ }
1621
+ }
1622
+ };
1623
+
1165
1624
  // src/resources/prices.ts
1625
+ async function readPricesRollingFile(response, meta, signal) {
1626
+ const rows = await readNdjsonRows(
1627
+ response,
1628
+ meta,
1629
+ signal,
1630
+ "rolling statistics file"
1631
+ );
1632
+ return {
1633
+ etag: meta.headers.get("etag"),
1634
+ windowEnd: meta.headers.get("x-rolling-window-end"),
1635
+ receivedThrough: meta.headers.get("x-rolling-received-through"),
1636
+ rows
1637
+ };
1638
+ }
1639
+ function feedQuery(params) {
1640
+ return {
1641
+ game: params.game,
1642
+ since: params.since,
1643
+ markets: params.markets,
1644
+ items: params.items,
1645
+ sides: params.sides,
1646
+ best: params.best
1647
+ };
1648
+ }
1166
1649
  var PricesResource = class extends BaseResource {
1167
1650
  latestAll(params, options) {
1168
1651
  return this.call(
@@ -1170,12 +1653,62 @@ var PricesResource = class extends BaseResource {
1170
1653
  method: "GET",
1171
1654
  path: "/prices/latest",
1172
1655
  baseUrl: this.http.versionedBaseUrl("v2"),
1656
+ query: {
1657
+ game: params.game,
1658
+ currency: params.currency,
1659
+ include: params.include
1660
+ },
1661
+ ifNoneMatch: params.ifNoneMatch
1662
+ },
1663
+ options
1664
+ );
1665
+ }
1666
+ rolling(params, options) {
1667
+ return this.call(
1668
+ {
1669
+ method: "GET",
1670
+ path: "/prices/rolling",
1671
+ baseUrl: this.http.versionedBaseUrl("v2"),
1173
1672
  query: { game: params.game },
1174
1673
  ifNoneMatch: params.ifNoneMatch
1175
1674
  },
1675
+ options,
1676
+ readPricesRollingFile
1677
+ );
1678
+ }
1679
+ /**
1680
+ * `GET /v2/prices/latest/changes`: up to 20 links after `since`. A cursor
1681
+ * that can no longer be resumed is an `APIError` with status 410 and code
1682
+ * `FEED_RESET`; take a new snapshot then.
1683
+ */
1684
+ changes(params, options) {
1685
+ return this.call(
1686
+ {
1687
+ method: "GET",
1688
+ path: "/prices/latest/changes",
1689
+ baseUrl: this.http.versionedBaseUrl("v2"),
1690
+ query: feedQuery(params)
1691
+ },
1176
1692
  options
1177
1693
  );
1178
1694
  }
1695
+ /**
1696
+ * Opens the WebSocket at `/v2/prices/stream`. It sends one `hello`, then a
1697
+ * `link` message per published snapshot, or a `reset` before closing with
1698
+ * code 4009. {@link mirror} handles the protocol.
1699
+ */
1700
+ stream(params) {
1701
+ return this.http.openWebSocket({
1702
+ method: "GET",
1703
+ path: "/prices/stream",
1704
+ baseUrl: this.http.versionedBaseUrl("v2"),
1705
+ query: feedQuery(params)
1706
+ });
1707
+ }
1708
+ /** A local copy of the snapshot that the change feed keeps current. */
1709
+ mirror(params) {
1710
+ return new LatestPricesMirror(this, params);
1711
+ }
1179
1712
  };
1180
1713
 
1181
1714
  // src/resources/recommendations.ts
@@ -1193,6 +1726,37 @@ var RecommendationsResource = class extends BaseResource {
1193
1726
  }
1194
1727
  };
1195
1728
 
1729
+ // src/resources/sales.ts
1730
+ async function readSalesDailyFile(response, meta, signal) {
1731
+ const rows = await readNdjsonRows(
1732
+ response,
1733
+ meta,
1734
+ signal,
1735
+ "daily sales file"
1736
+ );
1737
+ return {
1738
+ etag: meta.headers.get("etag"),
1739
+ final: meta.headers.get("x-sales-final") === "true",
1740
+ receivedThrough: meta.headers.get("x-sales-received-through"),
1741
+ rows
1742
+ };
1743
+ }
1744
+ var SalesResource = class extends BaseResource {
1745
+ daily(params, options) {
1746
+ return this.call(
1747
+ {
1748
+ method: "GET",
1749
+ path: "/sales/daily",
1750
+ baseUrl: this.http.versionedBaseUrl("v2"),
1751
+ query: { game: params.game, date: params.date },
1752
+ ifNoneMatch: params.ifNoneMatch
1753
+ },
1754
+ options,
1755
+ readSalesDailyFile
1756
+ );
1757
+ }
1758
+ };
1759
+
1196
1760
  // src/resources/status.ts
1197
1761
  var StatusResource = class extends BaseResource {
1198
1762
  /** `GET /v1/status/freshness` — per-market data freshness and overall health. */
@@ -1228,6 +1792,7 @@ var SkinpricerClient = class {
1228
1792
  markets;
1229
1793
  schema;
1230
1794
  prices;
1795
+ sales;
1231
1796
  /** Access the v2 endpoints supported by the selected game. */
1232
1797
  forGame(game) {
1233
1798
  return new GameClient(this.httpClient, game);
@@ -1250,6 +1815,7 @@ var SkinpricerClient = class {
1250
1815
  this.markets = new MarketsResource(this.httpClient);
1251
1816
  this.schema = new SchemaResource(this.httpClient);
1252
1817
  this.prices = new PricesResource(this.httpClient);
1818
+ this.sales = new SalesResource(this.httpClient);
1253
1819
  }
1254
1820
  };
1255
1821
 
@@ -1359,6 +1925,7 @@ exports.KNOWN_MARKETS = KNOWN_MARKETS;
1359
1925
  exports.LIQUIDITY_BADGES = LIQUIDITY_BADGES;
1360
1926
  exports.LIQUIDITY_CONFIDENCE = LIQUIDITY_CONFIDENCE;
1361
1927
  exports.LIQUIDITY_LABELS = LIQUIDITY_LABELS;
1928
+ exports.LatestPricesMirror = LatestPricesMirror;
1362
1929
  exports.LiquidityResource = LiquidityResource;
1363
1930
  exports.MarketAnalyticsResource = MarketAnalyticsResource;
1364
1931
  exports.MarketsResource = MarketsResource;
@@ -1374,6 +1941,7 @@ exports.RateLimitError = RateLimitError;
1374
1941
  exports.RecommendationsResource = RecommendationsResource;
1375
1942
  exports.SUPPORTED_LIQUIDITY_MARKETS = SUPPORTED_LIQUIDITY_MARKETS;
1376
1943
  exports.SUPPORTED_RUST_LIQUIDITY_MARKETS = SUPPORTED_RUST_LIQUIDITY_MARKETS;
1944
+ exports.SalesResource = SalesResource;
1377
1945
  exports.SchemaResource = SchemaResource;
1378
1946
  exports.ServerError = ServerError;
1379
1947
  exports.SkinpricerClient = SkinpricerClient;