@stxapp/stx-typescript 0.8.0 → 0.9.0-alpha.1

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.
@@ -551,6 +551,17 @@ var OPERATIONS = {
551
551
  model: "",
552
552
  isList: false,
553
553
  paginated: false
554
+ },
555
+ types_get: {
556
+ method: "GET",
557
+ path: "/api/v1/types",
558
+ query: [],
559
+ pathParams: [],
560
+ hasBody: false,
561
+ responseKey: "",
562
+ model: "",
563
+ isList: false,
564
+ paginated: false
554
565
  }
555
566
  };
556
567
 
@@ -630,19 +641,16 @@ function isValidLine(line) {
630
641
  return typeof line === "number" && Number.isFinite(line) && line > 0 && line * 2 % 2 === 1;
631
642
  }
632
643
  function marketEntry(m) {
633
- return {
634
- stat_detail: { player_id: m.playerId, stat: m.stat, prop_type: m.propType ?? "ou", line: m.line }
635
- };
644
+ return Object.fromEntries(Object.entries(m).map(([k, v]) => [k.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`), v]));
636
645
  }
637
- function toCreateMarketResult(raw) {
638
- const market = raw.market ?? raw.stat_detail ?? {};
639
- return { ...raw, market };
646
+ function toCreateMarketResult(raw, index) {
647
+ return { ...raw, index, market_id: raw.market_id ?? null, reason: raw.reason ?? null };
640
648
  }
641
- function rejected(m, reason) {
642
- const market = marketEntry(m).stat_detail;
643
- return { status: "rejected", reason, market };
649
+ function rejected(index, reason) {
650
+ return { index, status: "rejected", market_id: null, reason };
644
651
  }
645
652
  function checkMarket(m, players) {
653
+ if (m.rule !== "player_stat_line") return { market: m };
646
654
  if (!isValidLine(m.line)) return { reason: "invalid_line" };
647
655
  const stat = players.stats.find((s) => String(s.stat).toUpperCase() === String(m.stat).toUpperCase());
648
656
  if (!stat) return { reason: "unsupported_stat" };
@@ -961,7 +969,7 @@ function credentialsFromSettings(keyId, privateKey, signer) {
961
969
  }
962
970
 
963
971
  // src/version.ts
964
- var VERSION = "0.8.0";
972
+ var VERSION = "0.9.0-alpha.1";
965
973
  var USER_AGENT = `stx-typescript/${VERSION}`;
966
974
  var ASYNC_DISPOSE = Symbol.asyncDispose ?? /* @__PURE__ */ Symbol.for("Symbol.asyncDispose");
967
975
 
@@ -1703,19 +1711,32 @@ var STX = class _STX {
1703
1711
  return (await this.eventPlayers(eventId)).stats;
1704
1712
  }
1705
1713
  /**
1706
- * `POST /api/v1/markets`: create player-prop markets on a scheduled event,
1707
- * up to `MAX_MARKETS_PER_REQUEST` per call. Needs an OAuth app token with
1708
- * `markets.write`, which STX grants, from the client's IP allow-list.
1714
+ * `GET /api/v1/types`: the market types, keyed by rule. One with
1715
+ * `partner_create: true` can be created with `createMarkets()`, and lists
1716
+ * the `fields` an entry takes and, per event type, the `stats` on offer. It
1717
+ * changes only when STX adds a rule or a stat, so read it once and keep it.
1718
+ * Needs an OAuth app token with `events`, or an API key.
1719
+ */
1720
+ marketTypes() {
1721
+ return this.#one("types_get");
1722
+ }
1723
+ /**
1724
+ * `POST /api/v1/markets`: create markets on a scheduled event, up to
1725
+ * `MAX_MARKETS_PER_REQUEST` per call. Each market names its `rule` and the
1726
+ * fields that rule takes. Needs an OAuth app token with `markets.write`,
1727
+ * which STX grants, from an address on the client's IP allow-list (it
1728
+ * applies to every call that client makes).
1709
1729
  *
1710
- * Returns one result per market, in order: `created` or `exists` (both with
1711
- * `market_id`), or `rejected` with a `reason`. A rejected market is a
1712
- * result, not an error, and resending is safe: a market that is already
1713
- * listed comes back `exists`. A refused request throws (`403` without
1714
- * `markets.write`, `404` unknown event, `422` event not open).
1730
+ * Returns one result per market, in the order given, each with its `index`:
1731
+ * `created` or `exists` (both with `market_id`), `valid` (a `dryRun` market
1732
+ * that would be created), or `rejected` with a `reason`. A rejected market
1733
+ * is a result, not an error, and resending is safe: a market that is
1734
+ * already listed comes back `exists`. A refused request throws (`403`
1735
+ * without `markets.write`, `404` unknown event, `422` event not open).
1715
1736
  *
1716
- * Each `line` must be a positive number ending in `.5`, e.g. `18.5`. More
1717
- * than `MAX_MARKETS_PER_REQUEST` markets throws `TypeError` before any
1718
- * request. `validate` also needs the `events` scope.
1737
+ * `dryRun` runs every check and creates nothing. More than
1738
+ * `MAX_MARKETS_PER_REQUEST` markets throws `TypeError` before any request.
1739
+ * `validate` also needs the `events` scope.
1719
1740
  */
1720
1741
  async createMarkets(eventId, markets, opts = {}) {
1721
1742
  if (markets.length < 1 || markets.length > MAX_MARKETS_PER_REQUEST) {
@@ -1728,19 +1749,24 @@ var STX = class _STX {
1728
1749
  send = send.flatMap(({ m, i }) => {
1729
1750
  const checked = checkMarket(m, players);
1730
1751
  if ("market" in checked) return [{ m: checked.market, i }];
1731
- results[i] = rejected(m, checked.reason);
1752
+ results[i] = rejected(i, checked.reason);
1732
1753
  return [];
1733
1754
  });
1734
1755
  }
1735
1756
  if (send.length) {
1736
- const body = { event_id: eventId, markets: send.map(({ m }) => marketEntry(m)) };
1757
+ const body = {
1758
+ event_id: eventId,
1759
+ ...opts.dryRun ? { dry_run: true } : {},
1760
+ markets: send.map(({ m }) => marketEntry(m))
1761
+ };
1737
1762
  const raw = await this.#one("markets_post", { body });
1738
1763
  (raw.markets ?? []).forEach((r, k) => {
1739
- const slot = send[k];
1740
- if (slot) results[slot.i] = toCreateMarketResult(r);
1764
+ const sent = typeof r.index === "number" ? r.index : k;
1765
+ const slot = send[sent];
1766
+ if (slot) results[slot.i] = toCreateMarketResult(r, slot.i);
1741
1767
  });
1742
1768
  }
1743
- return results.map((r, i) => r ?? rejected(markets[i], "not_created"));
1769
+ return Array.from(results, (r, i) => r ?? rejected(i, "not_created"));
1744
1770
  }
1745
1771
  // ------------------------------------------------------------------
1746
1772
  // Orders
@@ -2984,4 +3010,4 @@ export {
2984
3010
  orderBody,
2985
3011
  STX
2986
3012
  };
2987
- //# sourceMappingURL=chunk-H7XZDE2U.js.map
3013
+ //# sourceMappingURL=chunk-4CSBA2YV.js.map