@stxapp/stx-typescript 0.8.3 → 0.9.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 CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.0 (2026-10-21)
4
+
5
+ One SDK for every STX exchange. Features an exchange does not have yet say so instead of failing obscurely, so the same release works against Ontario production today and against the features on US demo.
6
+
7
+ Not available:
8
+
9
+ - `STXNotAvailableException` (extends `STXAPIException`) with `feature`, `host` and a sentence such as `Combos are not available on demo.stxapp.ca yet.` It is thrown for: combos on an exchange without the combo topics (`STXCombosUnavailableException` stays a channel exception and now also matches `instanceof STXNotAvailableException`, with `feature` and `host`); OAuth discovery, token, refresh, revoke and introspect calls on an exchange without OAuth (a 404, or a 403 page from in front of the exchange); `createConnect()` where there is no OpenID configuration; `marketTypes()`, `eventPlayers()`, `createMarkets()` and the leaderboard calls where the exchange has no such route (or, for the leaderboard, has it switched off) (a 404 `{"error": "not_found"}`; a 404 about a missing event is still `STXNotFoundException`); and an `invalid_scope` for a scope the exchange's discovery document does not list (`feature` is `scope:<name>`).
10
+ - `await stx.capabilities()` reports which features the exchange has (`oauth`, `oauth.member`, `oauth.app`, `connect`, `terms.stx_page`, `markets.create`, `market_types`, `event_players`, `leaderboard`, `combos`) from its discovery document, `/api_version`, signed GETs and a join of a combo topic nobody owns. Nothing is created or changed. Cached per client; `has()` and `require()` on the result.
11
+ - Every other call behaves exactly as in 0.8.3.
12
+
13
+ Apps (OAuth):
14
+
15
+ - `OAuthClient.discover()` builds a client from the exchange's discovery document and keeps it as `oauth.metadata`; `fromMetadata()` keeps it too.
16
+ - Sign in with your STX account: `createConnect()` 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. `TokenSet.idToken` carries the ID token.
17
+ - `authorizationUrl()` and `beginAuthorization()` take `connection` and `loginHint`.
18
+ - `STXAccountPendingException` when the member's STX account is still being verified (on the callback, or on a refresh or code exchange; `memberClient()` keeps the stored tokens), and `STXAccessDeniedException` when the member declined or cannot connect. Both extend `STXOAuthException`; `STXOAuthException.errorReason` carries the exchange's narrower reason.
19
+ - A callback error is reported only for a sign-in your app started: the `state` is checked (and used up) first.
20
+ - Terms are accepted on an STX page. `STXTermsRequiredException` (extends `STXForbiddenException`, with `termsUrl`) when a connected member has new terms to accept; `termsUrlWithReturn()`; a refresh while terms are pending succeeds and carries `termsRequired` and `termsUrl`, with an `onTermsRequired` session hook; `STXTermsNotAcceptedException` when the member leaves the terms page during sign-in. `MemberScopes.TERMS_WRITE` and the legacy `onboarding` are removed, since the exchange retired the scope, and `parseScopes()` leaves them out.
21
+ - `STXIPNotAllowedException` (extends `STXForbiddenException`) for a write from an address the app's IP allow-list lacks (`ip_not_allowed`).
22
+ - 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.
23
+
24
+ Leaderboard:
25
+
26
+ - `leaderboard()`, `leaderboardMe()` and `updateProfile()` (`GET /api/v1/leaderboard`, `GET /api/v1/leaderboard/me`, `PATCH /api/v1/me/profile`).
27
+
28
+ Markets:
29
+
30
+ - `marketTypes()` lists the market types (`GET /api/v1/types`): the rules an app can create, their fields and the stats per event type. `NewMarket`, `PlayerStatLineMarket` and `MarketRule` name the input types; `NewMarketInput` is unchanged.
31
+
32
+ Fixes:
33
+
34
+ - The socket no longer sends channel `ping` frames on the `market:<id>`, `rfq:` and `combo_quote:` topics, which have no `ping` command. On the combo topics each one was refused (`unknown_command`) and logged a "ping failed" warning every 30 seconds per channel; on `market:<id>` it crashed the channel on the exchange, which then rejoined every 30 seconds. The socket heartbeat keeps these topics alive. Other channels are pinged as before.
35
+ - `ComboPlayer.leave()` and `ComboMaker.leave()` document that delivery stops when they resolve: the requests and quotes on that channel end as `cancelled`, and the exchange's `negotiation_closed` for them, which arrives after the channel has closed, is not delivered.
36
+
37
+ Examples: `examples/sign-in-with-stx.ts` and `examples/expo-connect/` (an Expo / React Native app with its server).
38
+
3
39
  ## 0.8.3 (2026-10-20)
4
40
 
5
41
  - Combos are no longer marked preview.
package/README.md CHANGED
@@ -72,6 +72,48 @@ Every field is described in the [API reference](https://docs.stxapp.io/sdks/type
72
72
 
73
73
  </details>
74
74
 
75
+ ## For apps: STX accounts and markets
76
+
77
+ An app registered with STX can bring its members' STX accounts in, and can act as itself. This runs on your server; the client secret and the tokens never go to a browser or a mobile app. OAuth is on in US demo today; on an exchange without it these calls throw `STXNotAvailableException`, and `await stx.capabilities()` says which features an exchange has. There are two ways to bring a member's STX account in.
78
+
79
+ **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.
80
+
81
+ ```ts
82
+ import { MemoryPendingAuthorizationStore, MemoryTokenStore, OAuthClient } from "@stxapp/stx-typescript/oauth";
83
+
84
+ const oauth = await OAuthClient.discover({ baseUrl: "https://demo.stxapp.io", clientId, clientSecret, redirectUri });
85
+ const pending = new MemoryPendingAuthorizationStore(); // sign-ins in progress; use your session store or database
86
+ const store = new MemoryTokenStore(); // members' tokens; use your database
87
+ const { url } = await oauth.beginAuthorization(pending, { scope: ["balance.read", "orders.write"], data: { userId } });
88
+ // redirect to url; on the callback:
89
+ await oauth.completeAuthorization(pending, callbackUrl, { store, memberKey: (d) => String(d?.userId) });
90
+ const balance = await oauth.memberClient(store, userId).balance();
91
+ ```
92
+
93
+ **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`.
94
+
95
+ ```ts
96
+ import { createConnect } from "@stxapp/stx-typescript/oauth";
97
+
98
+ const connect = createConnect({ issuer: "https://demo.stxapp.io", clientId, clientSecret, redirectUri });
99
+ const signIn = await connect.start({ connection: "google" }); // keep signIn in your session, redirect to signIn.url
100
+ const { tokens, identity } = await connect.finish(callbackUrl, signIn); // identity.sub is the member's stable id
101
+ ```
102
+
103
+ 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/).
104
+
105
+ **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.
106
+
107
+ ```ts
108
+ const stx = oauth.appClient(["events", "markets.write"]);
109
+ const types = await stx.marketTypes(); // the rules you can create, their fields and stats
110
+ const results = await stx.createMarkets(eventId, [
111
+ { rule: "player_stat_line", playerId, stat: "POINTS", line: 18.5 },
112
+ ]);
113
+ ```
114
+
115
+ See the guides for [what you can do where](https://docs.stxapp.io/sdks/typescript/capabilities/), [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/`, `examples/expo-connect/` and `examples/create-markets.ts`.
116
+
75
117
  ## Documentation
76
118
 
77
119
  - [TypeScript SDK guide](https://docs.stxapp.io/sdks/typescript/)