@usions/sdk 2.24.2 → 3.0.0-next.7

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.
Files changed (59) hide show
  1. package/README.md +45 -277
  2. package/dist/browser.global.js +1972 -0
  3. package/dist/browser.global.js.map +1 -0
  4. package/dist/index.d.ts +337 -0
  5. package/dist/index.js +1955 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/testing.d.ts +23 -0
  8. package/dist/testing.js +63 -0
  9. package/dist/testing.js.map +1 -0
  10. package/dist/types-G075L8Nl.d.ts +83 -0
  11. package/package.json +25 -46
  12. package/src/browser.js +0 -6725
  13. package/src/index.js +0 -10
  14. package/src/modules/back-button.js +0 -26
  15. package/src/modules/backend-channel.js +0 -109
  16. package/src/modules/bot.js +0 -52
  17. package/src/modules/chat.js +0 -35
  18. package/src/modules/cloud.js +0 -67
  19. package/src/modules/core.js +0 -424
  20. package/src/modules/errors.js +0 -120
  21. package/src/modules/file-storage.js +0 -46
  22. package/src/modules/game-ack.js +0 -32
  23. package/src/modules/game-core.js +0 -278
  24. package/src/modules/game-direct.js +0 -267
  25. package/src/modules/game-methods.js +0 -782
  26. package/src/modules/game-netcode.js +0 -349
  27. package/src/modules/game-proxy.js +0 -184
  28. package/src/modules/game-reliability.js +0 -278
  29. package/src/modules/game-resilience.js +0 -245
  30. package/src/modules/game-socket.js +0 -214
  31. package/src/modules/index.js +0 -78
  32. package/src/modules/leaderboard.js +0 -46
  33. package/src/modules/lobby.js +0 -103
  34. package/src/modules/matchmaking.js +0 -140
  35. package/src/modules/misc.js +0 -152
  36. package/src/modules/netcode/binary.js +0 -113
  37. package/src/modules/netcode/delta.js +0 -236
  38. package/src/modules/netcode/index.js +0 -43
  39. package/src/modules/netcode/interest-grid.js +0 -227
  40. package/src/modules/netcode/interpolation.js +0 -235
  41. package/src/modules/netcode/lagcomp.js +0 -104
  42. package/src/modules/netcode/lockstep.js +0 -103
  43. package/src/modules/netcode/mesh-network.js +0 -103
  44. package/src/modules/netcode/mesh.js +0 -188
  45. package/src/modules/netcode/netsim.js +0 -77
  46. package/src/modules/netcode/ping.js +0 -69
  47. package/src/modules/netcode/prediction.js +0 -113
  48. package/src/modules/netcode/sender.js +0 -102
  49. package/src/modules/netcode/webtransport.js +0 -195
  50. package/src/modules/notify.js +0 -70
  51. package/src/modules/permissions.js +0 -157
  52. package/src/modules/results.js +0 -34
  53. package/src/modules/session.js +0 -62
  54. package/src/modules/storage.js +0 -64
  55. package/src/modules/ui.js +0 -111
  56. package/src/modules/user.js +0 -61
  57. package/src/modules/wallet.js +0 -253
  58. package/types/browser.d.ts +0 -5
  59. package/types/index.d.ts +0 -1308
@@ -0,0 +1,337 @@
1
+ import { J as JsonValue, R as RequestOptions, U as Unsubscribe, A as AppContext, a as RawTransport, I as InitOptions } from './types-G075L8Nl.js';
2
+ export { S as SdkCapability } from './types-G075L8Nl.js';
3
+
4
+ interface CloudChangedPayload {
5
+ readonly subscriptionId: string;
6
+ readonly key: string;
7
+ readonly value?: JsonValue;
8
+ readonly removed: boolean;
9
+ }
10
+ interface GameActionPayload {
11
+ readonly operationId?: string;
12
+ readonly playerId: string;
13
+ readonly type: string;
14
+ readonly data: JsonValue;
15
+ readonly sequence: number;
16
+ readonly currentTurn?: string;
17
+ }
18
+ interface GameStatePayload {
19
+ readonly roomId: string;
20
+ readonly hostId?: string;
21
+ readonly playerIds: readonly string[];
22
+ readonly status: string;
23
+ readonly currentTurn?: string;
24
+ readonly checkpoint: JsonValue;
25
+ readonly checkpointSequence: number;
26
+ readonly serverSequence: number;
27
+ }
28
+ interface GameRecoveryPayload extends GameStatePayload {
29
+ readonly actions: readonly GameActionPayload[];
30
+ }
31
+ interface GameConnectionPayload {
32
+ readonly state: 'disconnected' | 'recovering' | 'ready';
33
+ readonly reason?: string;
34
+ }
35
+ interface GameRealtimePayload {
36
+ readonly playerId: string;
37
+ readonly type: string;
38
+ readonly data: JsonValue;
39
+ }
40
+ interface GameSnapshotPayload {
41
+ readonly sequence: number;
42
+ readonly tick: number;
43
+ readonly acknowledgedInput: number;
44
+ readonly keyframe: boolean;
45
+ readonly serverTime?: number;
46
+ readonly state: JsonValue;
47
+ }
48
+ interface ModuleCommandInputMap {
49
+ readonly 'auth.getToken': Record<string, never>;
50
+ readonly 'cloud.get': {
51
+ readonly key: string;
52
+ };
53
+ readonly 'cloud.keys': Record<string, never>;
54
+ readonly 'cloud.remove': {
55
+ readonly key: string;
56
+ };
57
+ readonly 'cloud.set': {
58
+ readonly key: string;
59
+ readonly value: JsonValue;
60
+ };
61
+ readonly 'cloud.subscribe': {
62
+ readonly key?: string;
63
+ };
64
+ readonly 'cloud.unsubscribe': {
65
+ readonly subscriptionId: string;
66
+ };
67
+ readonly 'game.action': {
68
+ readonly operationId: string;
69
+ readonly type: string;
70
+ readonly data: JsonValue;
71
+ readonly nextTurn?: string;
72
+ };
73
+ readonly 'game.checkpoint': {
74
+ readonly state: JsonValue;
75
+ readonly sequence: number;
76
+ };
77
+ readonly 'game.join': {
78
+ readonly appliedSequence?: number;
79
+ };
80
+ readonly 'game.input': {
81
+ readonly inputSequence: number;
82
+ readonly data: JsonValue;
83
+ };
84
+ readonly 'game.leave': Record<string, never>;
85
+ readonly 'game.recover': {
86
+ readonly appliedSequence: number;
87
+ };
88
+ }
89
+ interface ModuleCommandOutputMap {
90
+ readonly 'auth.getToken': {
91
+ readonly token: string;
92
+ readonly expiresAt: number;
93
+ };
94
+ readonly 'cloud.get': {
95
+ readonly value: JsonValue;
96
+ };
97
+ readonly 'cloud.keys': {
98
+ readonly keys: readonly string[];
99
+ };
100
+ readonly 'cloud.remove': {
101
+ readonly removed: boolean;
102
+ };
103
+ readonly 'cloud.set': {
104
+ readonly size: number;
105
+ };
106
+ readonly 'cloud.subscribe': {
107
+ readonly subscriptionId: string;
108
+ };
109
+ readonly 'cloud.unsubscribe': {
110
+ readonly removed: boolean;
111
+ };
112
+ readonly 'game.action': {
113
+ readonly operationId: string;
114
+ readonly sequence: number;
115
+ };
116
+ readonly 'game.checkpoint': {
117
+ readonly sequence: number;
118
+ };
119
+ readonly 'game.join': GameStatePayload;
120
+ readonly 'game.input': Record<string, never>;
121
+ readonly 'game.leave': {
122
+ readonly left: boolean;
123
+ };
124
+ readonly 'game.recover': GameRecoveryPayload;
125
+ }
126
+ type ModuleCommand = keyof ModuleCommandInputMap;
127
+ type ModuleEphemeralCommand = 'game.input';
128
+ type ModuleRequest<C extends ModuleCommand> = ModuleCommandInputMap[C];
129
+ type ModuleResponse<C extends ModuleCommand> = ModuleCommandOutputMap[C];
130
+ interface ModuleEventMap {
131
+ readonly 'cloud.changed': CloudChangedPayload;
132
+ readonly 'game.action': GameActionPayload;
133
+ readonly 'game.connection': GameConnectionPayload;
134
+ readonly 'game.realtime': GameRealtimePayload;
135
+ readonly 'game.snapshot': GameSnapshotPayload;
136
+ }
137
+ type ModuleEvent = keyof ModuleEventMap;
138
+ interface ModuleBus {
139
+ request<C extends ModuleCommand>(command: C, payload: ModuleRequest<C>, options?: RequestOptions): Promise<ModuleResponse<C>>;
140
+ send<C extends ModuleEphemeralCommand>(command: C, payload: ModuleRequest<C>): boolean;
141
+ on<E extends ModuleEvent>(event: E, handler: (data: ModuleEventMap[E]) => void): Unsubscribe;
142
+ }
143
+
144
+ interface ScopedToken {
145
+ token: string;
146
+ expiresAt: number;
147
+ }
148
+ declare class AuthModule {
149
+ private readonly bus;
150
+ constructor(bus: ModuleBus);
151
+ getToken(options?: RequestOptions): Promise<ScopedToken>;
152
+ }
153
+
154
+ type CloudChange = CloudChangedPayload;
155
+ declare class CloudModule {
156
+ private readonly bus;
157
+ constructor(bus: ModuleBus);
158
+ get<T extends JsonValue = JsonValue>(key: string, options?: RequestOptions): Promise<T | null>;
159
+ set(key: string, value: JsonValue, options?: RequestOptions): Promise<{
160
+ readonly size: number;
161
+ }>;
162
+ remove(key: string, options?: RequestOptions): Promise<{
163
+ readonly removed: boolean;
164
+ }>;
165
+ keys(options?: RequestOptions): Promise<readonly string[]>;
166
+ subscribe(key: string | undefined, handler: (change: CloudChange) => void, options?: RequestOptions): Promise<Unsubscribe>;
167
+ }
168
+
169
+ interface GameActionAck {
170
+ readonly operationId: string;
171
+ readonly sequence: number;
172
+ }
173
+
174
+ type GameConnectionState = 'idle' | 'joining' | 'recovering' | 'ready' | 'disconnected' | 'leaving' | 'failed';
175
+ interface GameStatus {
176
+ readonly connection: GameConnectionState;
177
+ readonly roomId?: string;
178
+ readonly hostId?: string;
179
+ readonly playerIds: readonly string[];
180
+ readonly roomStatus?: string;
181
+ readonly currentTurn?: string;
182
+ readonly serverSequence: number;
183
+ readonly checkpointSequence: number;
184
+ readonly appliedSequence: number;
185
+ readonly queuedActions: number;
186
+ readonly error?: string;
187
+ }
188
+ interface GameActionOptions extends RequestOptions {
189
+ readonly nextTurn?: string;
190
+ readonly queueIfOffline?: boolean;
191
+ }
192
+ interface GameStateAction {
193
+ readonly playerId: string;
194
+ readonly type: string;
195
+ readonly data: JsonValue;
196
+ readonly sequence: number;
197
+ readonly operationId?: string;
198
+ readonly currentTurn?: string;
199
+ }
200
+ type GameReducer<T extends JsonValue> = (state: T, action: GameStateAction) => T;
201
+ interface SyncedStateOptions {
202
+ readonly checkpointEvery?: number;
203
+ readonly authority?: 'host' | 'all';
204
+ }
205
+ interface SyncedGameState<T extends JsonValue> {
206
+ get(): Readonly<T>;
207
+ commit(type: string, data: JsonValue, options?: GameActionOptions): Promise<{
208
+ readonly operationId: string;
209
+ readonly sequence: number;
210
+ }>;
211
+ checkpoint(options?: RequestOptions): Promise<{
212
+ readonly sequence: number;
213
+ }>;
214
+ onChange(handler: (state: Readonly<T>, reason: 'action' | 'recover') => void): Unsubscribe;
215
+ destroy(): void;
216
+ }
217
+ type GameActionEvent = GameActionPayload;
218
+ type GameRealtimeEvent = GameRealtimePayload;
219
+ interface RecoveryNotice {
220
+ readonly recovery: GameRecoveryPayload;
221
+ readonly source: 'join' | 'recover';
222
+ readonly applyCheckpoint: boolean;
223
+ }
224
+
225
+ type AppliedSource = 'action' | 'recover';
226
+ type AppliedHandler = (action: GameStateAction, source: AppliedSource) => void;
227
+
228
+ type GameCommand = Extract<ModuleCommand, `game.${string}`>;
229
+ type GameEphemeralCommand = Extract<ModuleEphemeralCommand, `game.${string}`>;
230
+ type GameEvent = Extract<ModuleEvent, `game.${string}`>;
231
+ type GameTransportMode = 'platform' | 'direct' | 'hosted';
232
+ type GameConnectionTransport = 'websocket' | 'webrtc';
233
+ interface GameTransport {
234
+ readonly mode: GameTransportMode;
235
+ readonly connectionTransport: GameConnectionTransport;
236
+ request<C extends GameCommand>(command: C, payload: ModuleRequest<C>, options?: RequestOptions): Promise<ModuleResponse<C>>;
237
+ send<C extends GameEphemeralCommand>(command: C, payload: ModuleRequest<C>): boolean;
238
+ on<E extends GameEvent>(event: E, handler: (data: ModuleEventMap[E]) => void): Unsubscribe;
239
+ destroy(): void;
240
+ }
241
+
242
+ declare class GameModule {
243
+ private readonly transport;
244
+ private readonly getContext;
245
+ private readonly queue;
246
+ private readonly state;
247
+ private readonly realtime;
248
+ private readonly actions;
249
+ private readonly recoveryTimers;
250
+ private readonly cleanups;
251
+ private joinPromise;
252
+ private recoveryPromise;
253
+ private generation;
254
+ private destroyed;
255
+ constructor(transport: GameTransport, getContext: () => Readonly<AppContext>);
256
+ get status(): Readonly<GameStatus>;
257
+ get userId(): string;
258
+ join(options?: RequestOptions): Promise<Readonly<GameStatus>>;
259
+ recover(options?: RequestOptions): Promise<void>;
260
+ action(type: string, data: JsonValue, options?: GameActionOptions): Promise<GameActionAck>;
261
+ checkpoint(state: JsonValue, options?: RequestOptions): Promise<{
262
+ readonly sequence: number;
263
+ }>;
264
+ leave(options?: RequestOptions): Promise<void>;
265
+ createState<T extends JsonValue>(initial: T, reducer?: GameReducer<T>, options?: SyncedStateOptions): SyncedGameState<T>;
266
+ /**
267
+ * Queues the newest realtime input for best-effort delivery. Inputs are
268
+ * discarded while disconnected and are never replayed after reconnection.
269
+ */
270
+ sendInput(data: JsonValue): boolean;
271
+ onSnapshot(handler: (snapshot: GameSnapshotPayload) => void): Unsubscribe;
272
+ onStatus(handler: (status: Readonly<GameStatus>) => void): Unsubscribe;
273
+ onAction(handler: (action: GameActionEvent) => void): Unsubscribe;
274
+ onRealtime(handler: (event: {
275
+ readonly playerId: string;
276
+ readonly type: string;
277
+ readonly data: JsonValue;
278
+ }) => void): Unsubscribe;
279
+ onRecovery(handler: (notice: RecoveryNotice) => void): Unsubscribe;
280
+ onAppliedAction(handler: AppliedHandler): Unsubscribe;
281
+ destroy(): void;
282
+ private receiveConnection;
283
+ private flushQueue;
284
+ private scheduleRecoveryCheck;
285
+ private reset;
286
+ }
287
+
288
+ declare class UsionClient {
289
+ readonly auth: AuthModule;
290
+ readonly cloud: CloudModule;
291
+ readonly game: GameModule;
292
+ private snapshot;
293
+ private readonly bus;
294
+ private closed;
295
+ constructor(context: AppContext, transport: RawTransport);
296
+ get context(): Readonly<AppContext>;
297
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
298
+ destroy(reason?: string): Promise<void>;
299
+ private close;
300
+ }
301
+
302
+ declare const ERROR_CODES: {
303
+ readonly CANCELLED: "CANCELLED";
304
+ readonly CONFLICT: "CONFLICT";
305
+ readonly DESTROYED: "DESTROYED";
306
+ readonly INTERNAL: "INTERNAL";
307
+ readonly INIT_TIMEOUT: "INIT_TIMEOUT";
308
+ readonly INVALID_INPUT: "INVALID_INPUT";
309
+ readonly INVALID_MESSAGE: "INVALID_MESSAGE";
310
+ readonly NOT_AUTHENTICATED: "NOT_AUTHENTICATED";
311
+ readonly PERMISSION_DENIED: "PERMISSION_DENIED";
312
+ readonly PROTOCOL_MISMATCH: "PROTOCOL_MISMATCH";
313
+ readonly QUOTA_EXCEEDED: "QUOTA_EXCEEDED";
314
+ readonly RATE_LIMITED: "RATE_LIMITED";
315
+ readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
316
+ readonly TRUST_VIOLATION: "TRUST_VIOLATION";
317
+ readonly UNAVAILABLE: "UNAVAILABLE";
318
+ readonly UNSUPPORTED: "UNSUPPORTED";
319
+ readonly UNKNOWN: "UNKNOWN";
320
+ };
321
+ type UsionErrorCode = keyof typeof ERROR_CODES;
322
+ declare class UsionError extends Error {
323
+ readonly name = "UsionError";
324
+ readonly code: UsionErrorCode;
325
+ readonly retryAfter?: number;
326
+ constructor(code: UsionErrorCode, message: string, options?: {
327
+ retryAfter?: number;
328
+ cause?: unknown;
329
+ });
330
+ }
331
+
332
+ declare const Usion: Readonly<{
333
+ version: "3.0.0-next.7";
334
+ init(options?: InitOptions): Promise<UsionClient>;
335
+ }>;
336
+
337
+ export { AppContext, type CloudChange, ERROR_CODES, type GameActionAck, type GameActionEvent, type GameActionOptions, type GameCommand, type GameConnectionState, type GameConnectionTransport, type GameEvent, type GameRealtimeEvent, type GameReducer, type GameStateAction, type GameStatus, type GameTransport, type GameTransportMode, InitOptions, JsonValue, type RecoveryNotice, RequestOptions, type ScopedToken, type SyncedGameState, type SyncedStateOptions, Unsubscribe, Usion, UsionClient, UsionError, Usion as default };