@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.
- package/CHANGELOG.md +23 -0
- package/README.md +42 -0
- package/dist/{chunk-L2DEU7R6.cjs → chunk-33AQCUGM.cjs} +53 -27
- package/dist/chunk-33AQCUGM.cjs.map +1 -0
- package/dist/{chunk-H7XZDE2U.js → chunk-4CSBA2YV.js} +53 -27
- package/dist/chunk-4CSBA2YV.js.map +1 -0
- package/dist/{client-E5Lg6k8d.d.cts → client-CNkaTuhG.d.cts} +121 -40
- package/dist/{client-E5Lg6k8d.d.ts → client-CNkaTuhG.d.ts} +121 -40
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/oauth.cjs +374 -39
- package/dist/oauth.cjs.map +1 -1
- package/dist/oauth.d.cts +156 -11
- package/dist/oauth.d.ts +156 -11
- package/dist/oauth.js +349 -14
- package/dist/oauth.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-H7XZDE2U.js.map +0 -1
- package/dist/chunk-L2DEU7R6.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0-alpha.1 (2026-10-10)
|
|
4
|
+
|
|
5
|
+
Alpha: install with `npm install @stxapp/stx-typescript@alpha`. The new API may change before beta.
|
|
6
|
+
|
|
7
|
+
Sign in with your STX account, and connect your STX account:
|
|
8
|
+
|
|
9
|
+
- `createConnect()` in `@stxapp/stx-typescript/oauth` runs the OpenID Connect sign-in from your server. `start()` returns the redirect (optionally straight to Google, Apple or X, with a login hint), `finish()` exchanges the code and verifies the ID token, `refresh()` keeps the connection, `userInfo()` reads the member's claims again, and `disconnect()` ends the connection at STX.
|
|
10
|
+
- `OAuthClient.authorizationUrl()` and `beginAuthorization()` take `connection` and `loginHint`, for an app with its own login that connects a member's STX account.
|
|
11
|
+
- Two typed errors when the member does not come back connected: `STXAccountPendingException` (the member's STX account is still being verified) and `STXAccessDeniedException` (the member declined, or their account cannot be connected). Both extend `STXOAuthException`, so existing `catch` blocks keep working.
|
|
12
|
+
- A refresh or code exchange refused because the member's account is still being verified also throws `STXAccountPendingException` (`errorReason` is `account_pending`), and `memberClient()` keeps the stored tokens: the same refresh token works once the member is verified. A refresh refused because the connection ended still throws `STXGrantRevokedException` and deletes them.
|
|
13
|
+
- `STXOAuthException.errorReason` carries the narrower reason when the exchange sends one.
|
|
14
|
+
- An error on the callback is reported only for a sign-in your app started: `finish()`, `completeAuthorization()` and `readCallback()` check the `state` before the error, so a callback with a missing or unknown `state` throws `invalid_state` whatever error it carries. `completeAuthorization()` and `readCallback()` also use the `state` up, so a replayed callback throws `invalid_state`; with `finish()` the saved sign-in is yours, so delete it after the first callback.
|
|
15
|
+
- `TokenSet.idToken` carries the ID token when `openid` is granted.
|
|
16
|
+
- HTTP Basic client credentials are form-urlencoded before base64, as RFC 6749 requires. Client ids and secrets with only letters, digits and `_-.` are sent exactly as before.
|
|
17
|
+
|
|
18
|
+
Creating markets as your app:
|
|
19
|
+
|
|
20
|
+
- `marketTypes()` lists the market types (`GET /api/v1/types`): the rules an app can create, the fields each takes and the stats on offer per event type.
|
|
21
|
+
- `createMarkets()` takes each market by its `rule`: `{ rule: "player_stat_line", playerId, stat, line }`. **Changed from 0.8.0:** `rule` is now required and `propType` is gone.
|
|
22
|
+
- `createMarkets(..., { dryRun: true })` runs every check and creates nothing; a market that would be created comes back `valid`.
|
|
23
|
+
- **Changed from 0.8.0:** each result is `{ index, status, market_id, reason }`. `index` is the market's position in your list, `market_id` and `reason` are `null` when they do not apply, and the `market` echo of the request is gone (use `index`). The `NewMarketInput` and `MarketRequestEcho` types are replaced by `NewMarket`.
|
|
24
|
+
- Fixed: a market the exchange returned no result for now comes back `rejected` with `not_created` instead of leaving a gap in the results.
|
|
25
|
+
|
|
3
26
|
## 0.8.0 (2026-10-06)
|
|
4
27
|
|
|
5
28
|
- Create player-prop markets as an app with the `markets.write` scope: `eventPlayers()`, `statsFor()` and `createMarkets()`, with `Stats` constants by sport and an opt-in `validate` check. Lines must be positive and end in `.5`; up to 25 markets per call.
|
package/README.md
CHANGED
|
@@ -69,6 +69,48 @@ Every field is described in the [API reference](https://docs.stxapp.io/sdks/type
|
|
|
69
69
|
|
|
70
70
|
</details>
|
|
71
71
|
|
|
72
|
+
## For apps: STX accounts and markets (alpha)
|
|
73
|
+
|
|
74
|
+
An app registered with STX can bring its members' STX accounts in, and can act as itself. These are in the alpha: `npm install @stxapp/stx-typescript@alpha`. They run on your server; the client secret and the tokens never go to a browser or a mobile app. There are two ways to bring a member's STX account in.
|
|
75
|
+
|
|
76
|
+
**Connect your STX account.** Your app keeps its own login, and a signed-in user links their STX account so your app can trade and read for them. It works with any login system (your own passwords, or a login service you already use); STX never sees it.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { MemoryPendingAuthorizationStore, MemoryTokenStore, OAuthClient } from "@stxapp/stx-typescript/oauth";
|
|
80
|
+
|
|
81
|
+
const oauth = new OAuthClient({ baseUrl: "https://demo.stxapp.io", clientId, clientSecret, redirectUri });
|
|
82
|
+
const pending = new MemoryPendingAuthorizationStore(); // sign-ins in progress; use your session store or database
|
|
83
|
+
const store = new MemoryTokenStore(); // members' tokens; use your database
|
|
84
|
+
const { url } = await oauth.beginAuthorization(pending, { scope: ["balance.read", "orders.write"], data: { userId } });
|
|
85
|
+
// redirect to url; on the callback:
|
|
86
|
+
await oauth.completeAuthorization(pending, callbackUrl, { store, memberKey: (d) => String(d?.userId) });
|
|
87
|
+
const balance = await oauth.memberClient(store, userId).balance();
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Sign in with your STX account.** The STX account is the login: one button signs the member in, onboards them on STX if they are new, and connects their account. You get tokens to call STX for the member and a verified `identity`.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { createConnect } from "@stxapp/stx-typescript/oauth";
|
|
94
|
+
|
|
95
|
+
const connect = createConnect({ issuer: "https://demo.stxapp.io", clientId, clientSecret, redirectUri });
|
|
96
|
+
const signIn = await connect.start({ connection: "google" }); // keep signIn in your session, redirect to signIn.url
|
|
97
|
+
const { tokens, identity } = await connect.finish(callbackUrl, signIn); // identity.sub is the member's stable id
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
If your login runs through a login service, you can add the STX account there as one more sign-in option instead. That service then runs the sign-in, and you use this SDK only afterwards, to call STX with the tokens it hands you. See [Using a login service](https://docs.stxapp.io/oauth/sign-in-with-your-stx-account/login-vendor/).
|
|
101
|
+
|
|
102
|
+
**Create markets as your app.** With an app token (client credentials) and the `markets.write` scope, list the market types and create markets on scheduled events. A client that holds a write scope has an IP allow-list, and the allow-list applies to every call that client makes, so run this from an allow-listed address.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const stx = oauth.appClient(["events", "markets.write"]);
|
|
106
|
+
const types = await stx.marketTypes(); // the rules you can create, their fields and stats
|
|
107
|
+
const results = await stx.createMarkets(eventId, [
|
|
108
|
+
{ rule: "player_stat_line", playerId, stat: "POINTS", line: 18.5 },
|
|
109
|
+
]);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
See the guides for [signing in and connecting](https://docs.stxapp.io/sdks/typescript/sign-in-with-stx/) and [creating markets](https://docs.stxapp.io/sdks/typescript/markets/), and `examples/sign-in-with-stx.ts`, `examples/isv-backend/` and `examples/create-markets.ts`.
|
|
113
|
+
|
|
72
114
|
## Documentation
|
|
73
115
|
|
|
74
116
|
- [TypeScript SDK guide](https://docs.stxapp.io/sdks/typescript/)
|
|
@@ -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: _nullishCoalesce(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
|
-
|
|
639
|
-
return { ...raw, market };
|
|
646
|
+
function toCreateMarketResult(raw, index) {
|
|
647
|
+
return { ...raw, index, market_id: _nullishCoalesce(raw.market_id, () => ( null)), reason: _nullishCoalesce(raw.reason, () => ( null)) };
|
|
640
648
|
}
|
|
641
|
-
function rejected(
|
|
642
|
-
|
|
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.
|
|
972
|
+
var VERSION = "0.9.0-alpha.1";
|
|
965
973
|
var USER_AGENT = `stx-typescript/${VERSION}`;
|
|
966
974
|
var ASYNC_DISPOSE = _nullishCoalesce(Symbol.asyncDispose, () => ( /* @__PURE__ */ Symbol.for("Symbol.asyncDispose")));
|
|
967
975
|
|
|
@@ -1703,19 +1711,32 @@ var STX = (_class3 = class _STX {
|
|
|
1703
1711
|
return (await this.eventPlayers(eventId)).stats;
|
|
1704
1712
|
}
|
|
1705
1713
|
/**
|
|
1706
|
-
* `
|
|
1707
|
-
*
|
|
1708
|
-
* `
|
|
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
|
|
1711
|
-
* `
|
|
1712
|
-
*
|
|
1713
|
-
*
|
|
1714
|
-
*
|
|
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
|
-
*
|
|
1717
|
-
*
|
|
1718
|
-
*
|
|
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 = (_class3 = 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(
|
|
1752
|
+
results[i] = rejected(i, checked.reason);
|
|
1732
1753
|
return [];
|
|
1733
1754
|
});
|
|
1734
1755
|
}
|
|
1735
1756
|
if (send.length) {
|
|
1736
|
-
const body = {
|
|
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
|
(_nullishCoalesce(raw.markets, () => ( []))).forEach((r, k) => {
|
|
1739
|
-
const
|
|
1740
|
-
|
|
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
|
|
1769
|
+
return Array.from(results, (r, i) => _nullishCoalesce(r, () => ( rejected(i, "not_created"))));
|
|
1744
1770
|
}
|
|
1745
1771
|
// ------------------------------------------------------------------
|
|
1746
1772
|
// Orders
|
|
@@ -2984,4 +3010,4 @@ function dropUndefined(payload) {
|
|
|
2984
3010
|
|
|
2985
3011
|
|
|
2986
3012
|
exports.Region = Region; exports.Environment = Environment; exports.geoRejection = geoRejection; exports.STXException = STXException; exports.STXConfigException = STXConfigException; exports.STXAPIException = STXAPIException; exports.STXValidationException = STXValidationException; exports.STXAuthenticationException = STXAuthenticationException; exports.STXForbiddenException = STXForbiddenException; exports.STXInvalidTokenException = STXInvalidTokenException; exports.STXInsufficientScopeException = STXInsufficientScopeException; exports.STXNotFoundException = STXNotFoundException; exports.STXRejectedException = STXRejectedException; exports.STXGeoLocationException = STXGeoLocationException; exports.STXRateLimitException = STXRateLimitException; exports.STXServerException = STXServerException; exports.STXTransportException = STXTransportException; exports.STXChannelException = STXChannelException; exports.STXTimeoutException = STXTimeoutException; exports.errorForStatus = errorForStatus; exports.Environments = Environments; exports.HOSTS = HOSTS; exports.environmentNamed = environmentNamed; exports.resolveHost = resolveHost; exports.baseUrlFor = baseUrlFor; exports.socketUrlFor = socketUrlFor; exports.OPERATIONS = OPERATIONS; exports.Stats = Stats; exports.MAX_MARKETS_PER_REQUEST = MAX_MARKETS_PER_REQUEST; exports.isValidLine = isValidLine; exports.Page = Page; exports.RetryPolicy = RetryPolicy; exports.NO_RETRY = NO_RETRY; exports.resolveSettings = resolveSettings; exports.KEY_HEADER = KEY_HEADER; exports.TIMESTAMP_HEADER = TIMESTAMP_HEADER; exports.SIGNATURE_HEADER = SIGNATURE_HEADER; exports.buildMessage = buildMessage; exports.requestPath = requestPath; exports.handshakePath = handshakePath; exports.loadPrivateKey = loadPrivateKey; exports.signerFromPrivateKey = signerFromPrivateKey; exports.ApiKeyCredentials = ApiKeyCredentials; exports.VERSION = VERSION; exports.USER_AGENT = USER_AGENT; exports.TERMINAL_ORDER_STATUSES = TERMINAL_ORDER_STATUSES; exports.AccountView = AccountView; exports.centsToDollars = centsToDollars; exports.toDollarString = toDollarString; exports.toQuantity = toQuantity; exports.convertMarketPayload = convertMarketPayload; exports.convertMarketsFrame = convertMarketsFrame; exports.convertBook = convertBook; exports.convertMarketChannelPayload = convertMarketChannelPayload; exports.SNAPSHOT_EVENTS = SNAPSHOT_EVENTS; exports.ChannelMessage = ChannelMessage; exports.ReconnectPolicy = ReconnectPolicy; exports.Channel = Channel; exports.STXWebSocket = STXWebSocket; exports.orderBody = orderBody; exports.STX = STX;
|
|
2987
|
-
//# sourceMappingURL=chunk-
|
|
3013
|
+
//# sourceMappingURL=chunk-33AQCUGM.cjs.map
|