@usions/sdk 2.11.1 → 2.12.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/README.md CHANGED
@@ -4,6 +4,14 @@ Client SDK for building mini-apps and games on the [Usion](https://usions.com) p
4
4
 
5
5
  Provides access to user info, storage, wallet, chat, sessions, and real-time multiplayer game features.
6
6
 
7
+ ## Documentation
8
+
9
+ - [Guides](../../docs/sdk-guides/README.md) — first game in 30 min, the reliability contract, netcode, money, cloud saves
10
+ - [API reference](../../docs/sdk-api/README.md) (generated from the type declarations)
11
+ - [Platform behavior spec](../../docs/sdk-guides/06-platform-spec.md) — delivery guarantees, quotas, security model
12
+ - [CHANGELOG](CHANGELOG.md) · [versioning policy](../../docs/sdk-versioning-policy.md)
13
+ - Local development: [`@usions/devkit`](../devkit/README.md) — build and chaos-test without a Usion account
14
+
7
15
  ## Install
8
16
 
9
17
  ```bash
@@ -109,8 +117,36 @@ Usion.game.onGameRestarted((data) => { ... })
109
117
  Usion.game.onError((data) => { ... })
110
118
  Usion.game.onDisconnect((reason) => { ... })
111
119
  Usion.game.onReconnect((attempt) => { ... })
120
+ Usion.game.onPlayerConnection((d) => { ... }) // d.state: 'connected' | 'reconnecting' | 'gone'
112
121
  ```
113
122
 
123
+ #### Reliability contract (read this before shipping multiplayer)
124
+
125
+ The platform recovers from connection blips for you — your game just has to
126
+ follow four rules so both screens always agree:
127
+
128
+ 1. **Apply moves only in `onAction`** — never optimistically on send. Every
129
+ action (including your own) is echoed back with the authoritative
130
+ `sequence`; the SDK deduplicates, so each action is delivered exactly once
131
+ even across reconnect replays.
132
+ 2. **Turn-based? Pass `{ nextTurn }`** on every move and trust `current_turn`
133
+ from the join result / `onSync` instead of deriving the turn locally:
134
+ ```javascript
135
+ await Usion.game.action('move', { cell: 4 }, { nextTurn: opponentId })
136
+ ```
137
+ 3. **Handle `onDisconnect` / `onReconnect`** — pause input and show a
138
+ "reconnecting…" hint. The platform rejoins the room and replays missed
139
+ actions automatically. Use `onPlayerConnection` for the opponent's status;
140
+ don't end the match on `'reconnecting'` (a ~15s grace window applies),
141
+ treat `'gone'` as the opponent having left.
142
+ 4. **Authority checkpoints with `setState`** — the room authority
143
+ (`player_ids[0]`) should checkpoint at meaningful transitions so a
144
+ rejoining client restores instantly (delivered as `game_state` in the
145
+ join result and `onSync`; max 64 KB):
146
+ ```javascript
147
+ await Usion.game.setState(fullGameState)
148
+ ```
149
+
114
150
  #### Other
115
151
 
116
152
  ```javascript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usions/sdk",
3
- "version": "2.11.1",
3
+ "version": "2.12.0",
4
4
  "description": "Usion Mini App SDK for iframe games and services",
5
5
  "type": "module",
6
6
  "main": "src/modules/index.js",
@@ -26,11 +26,18 @@
26
26
  "build": "rollup -c",
27
27
  "build:copy": "npm run build && cp src/browser.js ../../web/public/usion-sdk.js && cp src/browser.js ../../microservices/shared/usion-sdk.js",
28
28
  "watch": "rollup -c --watch",
29
- "test": "npm run build && vitest run",
30
- "prepublishOnly": "npm run build && vitest run"
29
+ "test": "npm run build && vitest run && npm run test:types && npm run check:src && npm run check:size",
30
+ "prepublishOnly": "npm run build && vitest run && npm run test:types && npm run check:src && npm run check:size",
31
+ "test:types": "tsc -p test/tsconfig.json",
32
+ "check:size": "node scripts/check-size.mjs",
33
+ "docs:api": "typedoc --plugin typedoc-plugin-markdown --entryPoints types/index.d.ts --out ../../docs/sdk-api --readme none --tsconfig test/tsconfig.json",
34
+ "check:src": "tsc -p tsconfig.src.json"
31
35
  },
32
36
  "devDependencies": {
33
37
  "rollup": "^4.0.0",
38
+ "typedoc": "^0.28.19",
39
+ "typedoc-plugin-markdown": "^4.12.0",
40
+ "typescript": "^5.9.3",
34
41
  "vitest": "^2.1.9"
35
42
  },
36
43
  "keywords": [
@@ -53,4 +60,4 @@
53
60
  "publishConfig": {
54
61
  "access": "public"
55
62
  }
56
- }
63
+ }