@usions/sdk 2.0.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/README.md +144 -0
- package/package.json +37 -0
- package/src/browser.js +1793 -0
- package/src/index.js +55 -0
- package/types/index.d.ts +278 -0
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @usion/sdk
|
|
2
|
+
|
|
3
|
+
Client SDK for building mini-apps and games on the [Usion](https://usions.com) platform.
|
|
4
|
+
|
|
5
|
+
Provides access to user info, storage, wallet, chat, sessions, and real-time multiplayer game features.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @usion/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or load via script tag:
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://usions.com/usion-sdk.js"></script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import Usion from '@usion/sdk';
|
|
23
|
+
|
|
24
|
+
Usion.init((config) => {
|
|
25
|
+
console.log('User:', Usion.user.getName());
|
|
26
|
+
console.log('Room:', config.roomId);
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Modules
|
|
31
|
+
|
|
32
|
+
### User
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
Usion.user.getId() // User ID
|
|
36
|
+
Usion.user.getName() // Display name
|
|
37
|
+
Usion.user.getAvatar() // Avatar URL
|
|
38
|
+
Usion.user.getToken() // Auth JWT
|
|
39
|
+
Usion.user.getProfile() // Promise<{ id, name, avatar }>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Storage (persistent, per-user, per-service)
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
await Usion.storage.set('highscore', 1500)
|
|
46
|
+
await Usion.storage.get('highscore') // 1500
|
|
47
|
+
await Usion.storage.remove('highscore')
|
|
48
|
+
await Usion.storage.keys() // ['key1', 'key2']
|
|
49
|
+
await Usion.storage.clear()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Wallet
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
await Usion.wallet.getBalance() // 500
|
|
56
|
+
await Usion.wallet.hasCredits(100) // true
|
|
57
|
+
await Usion.wallet.requestPayment(50, 'Power-up')
|
|
58
|
+
Usion.wallet.onBalanceChange((balance) => { ... })
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Session (ephemeral)
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
Usion.session.getId()
|
|
65
|
+
Usion.session.getData('key')
|
|
66
|
+
Usion.session.setData('key', 'value')
|
|
67
|
+
Usion.session.clear()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Chat
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
await Usion.chat.sendMessage(recipientId, 'Hello!')
|
|
74
|
+
await Usion.chat.createPersonalChat(peerUserId)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Game (Multiplayer)
|
|
78
|
+
|
|
79
|
+
#### Platform Mode (relay through Usion backend)
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
await Usion.game.connect()
|
|
83
|
+
await Usion.game.join(roomId)
|
|
84
|
+
|
|
85
|
+
// Send actions (validated, sequenced)
|
|
86
|
+
await Usion.game.action('move', { cell: 4 })
|
|
87
|
+
|
|
88
|
+
// Send real-time updates (fire-and-forget)
|
|
89
|
+
Usion.game.realtime('position', { x: 100, y: 200 })
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Direct Mode (connect to game creator's server)
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
await Usion.game.connectDirect()
|
|
96
|
+
await Usion.game.join(roomId)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Event Handlers
|
|
100
|
+
|
|
101
|
+
```javascript
|
|
102
|
+
Usion.game.onPlayerJoined((data) => { ... })
|
|
103
|
+
Usion.game.onPlayerLeft((data) => { ... })
|
|
104
|
+
Usion.game.onStateUpdate((data) => { ... })
|
|
105
|
+
Usion.game.onAction((data) => { ... })
|
|
106
|
+
Usion.game.onRealtime((data) => { ... })
|
|
107
|
+
Usion.game.onGameFinished((data) => { ... })
|
|
108
|
+
Usion.game.onGameRestarted((data) => { ... })
|
|
109
|
+
Usion.game.onError((data) => { ... })
|
|
110
|
+
Usion.game.onDisconnect((reason) => { ... })
|
|
111
|
+
Usion.game.onReconnect((attempt) => { ... })
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Other
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
Usion.game.requestSync(lastSequence) // Recover missed actions
|
|
118
|
+
Usion.game.requestRematch()
|
|
119
|
+
Usion.game.forfeit()
|
|
120
|
+
Usion.game.disconnect()
|
|
121
|
+
Usion.game.isConnected() // boolean
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Utility
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
Usion.requestPayment(amount, reason)
|
|
128
|
+
Usion.share('image', { imageUrl, text })
|
|
129
|
+
Usion.exit() // Close the mini-app
|
|
130
|
+
Usion.log(message) // Debug log
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## TypeScript
|
|
134
|
+
|
|
135
|
+
Full type declarations included:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import Usion from '@usion/sdk';
|
|
139
|
+
import type { UsionConfig, GameModule, PlayerJoinedData } from '@usion/sdk';
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@usions/sdk",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Usion Mini App SDK for iframe games and services",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"browser": "src/browser.js",
|
|
8
|
+
"types": "types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./src/index.js",
|
|
12
|
+
"browser": "./src/browser.js",
|
|
13
|
+
"default": "./src/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./browser": "./src/browser.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"src/",
|
|
19
|
+
"types/"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"usion",
|
|
23
|
+
"game",
|
|
24
|
+
"sdk",
|
|
25
|
+
"multiplayer",
|
|
26
|
+
"mini-app"
|
|
27
|
+
],
|
|
28
|
+
"homepage": "https://github.com/usion-platform/sdk#readme",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/usion-platform/sdk.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/usion-platform/sdk/issues"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT"
|
|
37
|
+
}
|