@usions/sdk 2.32.0 → 2.33.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/types/index.d.ts CHANGED
@@ -43,6 +43,11 @@ export interface UsionConfig {
43
43
  * `Usion.screen.support()`, which treats absent as all-false. (SDK ≥ 2.31)
44
44
  */
45
45
  screenCapture?: ScreenCaptureSupport;
46
+ /**
47
+ * Host capabilities declared in INIT. Absent on older app builds — read
48
+ * `feedShare` via `Usion.canShareToFeed()`. (SDK ≥ 2.33)
49
+ */
50
+ hostFeatures?: { feedShare?: boolean; feedShareImage?: boolean; feedShareVideo?: boolean; [feature: string]: boolean | undefined };
46
51
  }
47
52
 
48
53
  // ─── Payment ─────────────────────────────────────────────────────
@@ -94,6 +99,12 @@ export interface UserModule {
94
99
  */
95
100
  isAdult(): boolean | null;
96
101
  getProfile(): Promise<UserProfile>;
102
+ /**
103
+ * Open another player's Usion profile (SDK ≥ 2.33) — e.g. when a leaderboard
104
+ * row is tapped. The host shows it over the app, which keeps running; back
105
+ * returns to it. Fire-and-forget; a no-op outside the host or for guest ids.
106
+ */
107
+ openProfile(userId: string): void;
97
108
  }
98
109
 
99
110
  // ─── Storage ─────────────────────────────────────────────────────
@@ -163,6 +174,52 @@ export interface ShareMediaItem {
163
174
  duration?: number;
164
175
  }
165
176
 
177
+ /** Input for `Usion.shareToFeed`. */
178
+ export interface ShareToFeedData {
179
+ /** The post's text (required, non-empty). */
180
+ text: string;
181
+ /** Relative in-app path readers open, e.g. `/q/57`. */
182
+ path?: string;
183
+ /** Idempotency key (UUID). Generated when omitted. */
184
+ requestId?: string;
185
+ /**
186
+ * The thing being shared (e.g. the question), shown on the feed as a
187
+ * tappable card that opens `path`; `text` is the user's caption. (SDK ≥ 2.33.0-dev.6)
188
+ */
189
+ card?: ShareToFeedCard;
190
+ /**
191
+ * The card as a picture (e.g. a rendered question card):
192
+ * `data:image/(png|jpeg|webp);base64,…`, decoded ≤ 5 MB. Send only when
193
+ * `Usion.canShareToFeed('image')` is true (older hosts drop it), and keep
194
+ * `card` alongside as its text/alt. (SDK ≥ 2.33.0-dev.7)
195
+ */
196
+ image?: string;
197
+ /** MP4 base64 data URL, at most 5 MB decoded; requires canShareToFeed('video'). */
198
+ video?: string;
199
+ /** Signed receipt returned by uploadFeedVideo (100 MB maximum). */
200
+ videoReceipt?: string;
201
+ /** @deprecated Ignored by current hosts. */
202
+ media?: Array<{ type: 'image' | 'video' | 'audio'; url: string; thumbnailUrl?: string; width?: number; height?: number; duration?: number }>;
203
+ }
204
+
205
+ /** The shared item shown as a card on a feed post. Both fields are trimmed. */
206
+ export interface ShareToFeedCard {
207
+ /** 1–200 Unicode code points. */
208
+ title: string;
209
+ /** Up to 60 Unicode code points; omitted when empty. */
210
+ subtitle?: string;
211
+ }
212
+
213
+ /** Result of a confirmed `Usion.shareToFeed`. */
214
+ export interface ShareToFeedResult {
215
+ success: true;
216
+ /** Id of the created (or, on a retry, the existing) post. */
217
+ postId: string;
218
+ /** Legacy hosts may also return a share URL. */
219
+ shareUrl?: string;
220
+ [key: string]: unknown;
221
+ }
222
+
166
223
  export interface ShareData {
167
224
  text?: string;
168
225
  message?: string;
@@ -404,7 +461,10 @@ export interface MatchResult {
404
461
  * Finishing order for a 3+ player match, BEST FIRST — how the card ranks
405
462
  * everyone. Pass it whenever there is a ranking: it cannot be derived from
406
463
  * `scores`, since a high score wins in some games and a low one wins in
407
- * others. Ids not in the room are ignored; anyone omitted is appended.
464
+ * others. Ids not in the room are ignored; scored players and the winner
465
+ * omitted from the order are appended. When scores or standings are supplied,
466
+ * include every actual participant in either field; other room members do
467
+ * not receive match cards. Without either field, the room roster is used.
408
468
  * Omit for 1-on-1. (SDK ≥ 2.27)
409
469
  */
410
470
  standings?: Array<string | { userId: string }>;
@@ -489,7 +549,27 @@ export interface SyncedState<S = Record<string, any>> {
489
549
  destroy(): void;
490
550
  }
491
551
 
552
+ export interface GameParticipant {
553
+ id: string;
554
+ name: string;
555
+ avatar: string | null;
556
+ joined: boolean;
557
+ connected: boolean;
558
+ }
559
+ export interface GameParticipantsResult {
560
+ roomId: string;
561
+ hostId: string;
562
+ source: 'room' | 'group';
563
+ participants: GameParticipant[];
564
+ }
492
565
  export interface GameModule {
566
+ /** Minimal profiles for the joined room and its authorized source group. */
567
+ getParticipants(): Promise<GameParticipantsResult>;
568
+
569
+ /** Join the current room and manage WebRTC with platform relay fallback.
570
+ * Resolves before peers connect; without a room, waits for an app invite.
571
+ * One active connection per game. Platform mode, up to 8 players, JSON only. */
572
+ connectPlayers(options?: ConnectPlayersOptions): Promise<PlayersConnection>;
493
573
  // Connection
494
574
  connect(socketUrl?: string, token?: string): Promise<void>;
495
575
  connectDirect(config?: DirectConnectionConfig): Promise<void>;
@@ -1142,7 +1222,22 @@ export interface SelectionGrid {
1142
1222
 
1143
1223
  // ─── Main SDK ────────────────────────────────────────────────────
1144
1224
 
1225
+ /** Local derived signals, available only while the user permits this mini-app. */
1226
+ export type CallAnalysisCapability = 'headPosition' | 'voiceActivity';
1227
+ export type CallAnalysisSample =
1228
+ | { kind: 'face'; detected: boolean; x: number; y: number }
1229
+ | { kind: 'voice'; speaking: boolean };
1230
+ export interface CallModule {
1231
+ capabilities(): Promise<{ capabilities: CallAnalysisCapability[]; connected: boolean }>;
1232
+ startAnalysis(options: {
1233
+ capabilities: CallAnalysisCapability[];
1234
+ onSample: (sample: CallAnalysisSample) => void;
1235
+ onStopped?: () => void;
1236
+ }): Promise<{ stop(): Promise<void> }>;
1237
+ }
1238
+
1145
1239
  export interface UsionSDK {
1240
+ call: CallModule;
1146
1241
  version: string;
1147
1242
  config: UsionConfig;
1148
1243
 
@@ -1218,10 +1313,54 @@ export interface UsionSDK {
1218
1313
  share(contentType: 'audio' | 'image' | 'video' | 'text' | 'mixed', data: ShareData): void;
1219
1314
  shareFile(url: string, options?: ShareFileOptions): Promise<FileTransferResult>;
1220
1315
  shareToStory(url: string, options?: StoryShareOptions): Promise<FileTransferResult>;
1221
- shareToFeed(contentType: 'text' | 'image' | 'video' | 'audio' | 'mixed', data: {
1222
- text?: string;
1223
- media?: Array<{ type: 'image' | 'video' | 'audio'; url: string; thumbnailUrl?: string; width?: number; height?: number; duration?: number }>;
1224
- }): Promise<{ success: boolean; postId?: string; shareUrl?: string }>;
1316
+ /**
1317
+ * `true` only when the host declared `hostFeatures.feedShare` in its INIT
1318
+ * config, i.e. it can show the confirm sheet and post. `false` outside a host
1319
+ * and on older app builds. Show your "Share to feed" button only when this is
1320
+ * true. `canShareToFeed('image')` additionally requires
1321
+ * `hostFeatures.feedShareImage` — send `image` only when it is true (older
1322
+ * hosts drop it). `'video'` requires `feedShareVideo` (SDK ≥ 2.33.0-dev.9).
1323
+ */
1324
+ canShareToFeed(feature?: 'image' | 'video' | 'videoUpload'): boolean;
1325
+ /** Upload a supported video directly; pass the returned receipt to shareToFeed. */
1326
+ uploadFeedVideo(file: Blob): Promise<{ receipt: string }>;
1327
+ /**
1328
+ * Post a short text to the signed-in user's Usions News Feed (it also shows
1329
+ * on their profile), stamped with this app and an optional in-app `path`.
1330
+ * Readers see a chip with this app's real icon and name; tapping it opens
1331
+ * this app at `path` (read it via `getLaunchParams().path` / `onHostNavigate`).
1332
+ *
1333
+ * - The host shows a confirm sheet EVERY time — never silent, never a stored grant.
1334
+ * - Public (listed) apps only; text ≤ 1000 characters, with an optional image or MP4 video.
1335
+ * - One call = at most one post: `requestId` is generated when omitted, so a
1336
+ * retry of the same call never duplicates. Pass your own to dedupe retries
1337
+ * across calls.
1338
+ * - `card` (optional): the item being shared, shown as a tappable card; the
1339
+ * post mentions your app automatically.
1340
+ * - Limits: 5 per minute and 30 per day per user per app.
1341
+ *
1342
+ * Rejects with a `UsionError` whose `code` is `CANCELLED` (the user declined),
1343
+ * `RATE_LIMITED`, `NOT_AUTHENTICATED` (guest), `PERMISSION_DENIED` (app not
1344
+ * public), `INVALID_INPUT` (empty text / bad path / bad card / bad image — checked locally before the
1345
+ * host is asked), `REQUEST_TIMEOUT` or `UNKNOWN`. (SDK ≥ 2.33)
1346
+ *
1347
+ * @param contentType Pass `'video'` for a video, otherwise `'text'`.
1348
+ */
1349
+ shareToFeed(contentType: 'text' | 'image' | 'video' | 'audio' | 'mixed', data: ShareToFeedData): Promise<ShareToFeedResult>;
1350
+ /**
1351
+ * Open another Usion app — or this one — at an optional in-app path (the
1352
+ * same address a feed post or notification carries). The host checks the
1353
+ * app exists and the user may open it; opening yourself navigates in place
1354
+ * (delivered through `onHostNavigate`). Fire-and-forget; a no-op on hosts
1355
+ * that predate it.
1356
+ *
1357
+ * @param serviceId Target app's service id.
1358
+ * @param path Relative in-app path starting with a single `/` (≤ 512 chars,
1359
+ * no `//`, `://`, spaces, backslashes or control characters).
1360
+ * @throws UsionError `INVALID_INPUT` synchronously for an empty `serviceId` or a bad `path`.
1361
+ * (SDK ≥ 2.33)
1362
+ */
1363
+ openApp(serviceId: string, path?: string): void;
1225
1364
 
1226
1365
  // Logging
1227
1366
  log(msg: string): void;
@@ -1278,6 +1417,8 @@ export interface UsionSDK {
1278
1417
  notify: NotifyModule;
1279
1418
  permissions: PermissionsModule;
1280
1419
  screen: UsionScreen;
1420
+ /** Consent-gated native cards in this app's category on the current user's profile. */
1421
+ profile: ProfileModule;
1281
1422
  netcode: NetcodeModule;
1282
1423
  }
1283
1424
 
@@ -1303,11 +1444,34 @@ export interface PermissionResult {
1303
1444
  permissions: Record<string, boolean>;
1304
1445
  }
1305
1446
 
1447
+ export interface ProfileContentItem {
1448
+ /** Unique within this app's content. 1–80 letters, digits, underscores or hyphens. */
1449
+ id: string;
1450
+ /** Plain text, 1–120 characters. */
1451
+ title: string;
1452
+ /** Plain text, at most 2,000 characters. */
1453
+ description?: string;
1454
+ /** HTTPS image URL, at most 2,048 characters. Upload media before publishing. */
1455
+ imageUrl?: string;
1456
+ }
1457
+ export interface ProfileContent { items: ProfileContentItem[]; }
1458
+ export interface ProfileModule {
1459
+ /** Read only this app's content for the current user. Requires profile_content permission. */
1460
+ getContent(): Promise<ProfileContent>;
1461
+ /** Replace up to 50 cards. Requires profile_content permission; never prompts automatically.
1462
+ * Signed-in profile visitors can see these cards. [] hides this app's category.
1463
+ * Requires an updated mobile/web host. Old hosts reject with REQUEST_TIMEOUT.
1464
+ */
1465
+ setContent(content: ProfileContent): Promise<ProfileContent>;
1466
+ /** Remove this app's cards. Allowed after permission revocation as well. */
1467
+ clearContent(): Promise<void>;
1468
+ }
1469
+
1306
1470
  /**
1307
1471
  * Ask the user to allow capabilities (the host shows a modal — like asking for
1308
1472
  * money). The platform enforces grants: e.g. `notify.send` is dropped until
1309
1473
  * `notifications` is granted. Embedded feature; standalone resolves "not
1310
- * granted". Permission keys today: `'notifications'`.
1474
+ * granted". Permission keys: `'notifications'` and `'profile_content'`.
1311
1475
  */
1312
1476
  export interface PermissionsModule {
1313
1477
  /** Prompt the user to allow one or more permissions. */
@@ -1379,16 +1543,37 @@ export interface CloudScope {
1379
1543
  keys(opts?: { serviceId?: string }): Promise<string[]>;
1380
1544
  }
1381
1545
 
1546
+ /** One accepted friend's value from `Usion.cloud.friends.list`. */
1547
+ export interface FriendCloudValue {
1548
+ userId: string;
1549
+ name: string | null;
1550
+ avatar: string | null;
1551
+ value: any;
1552
+ /** ISO 8601 time the friend last wrote the value. */
1553
+ updatedAt: string | null;
1554
+ }
1555
+
1382
1556
  /**
1383
1557
  * Server-persisted cloud storage. Per-user scope on the module itself
1384
1558
  * (cloud saves synced across devices); `shared` is one bucket per app that
1385
1559
  * all users read/write. Quotas: 64 KB/value, 200 keys + 1 MB per bucket.
1560
+ * `friends` holds values you own that your accepted friends can read
1561
+ * (4 KB/value, 200 keys).
1386
1562
  */
1387
1563
  export interface CloudModule extends CloudScope {
1388
1564
  shared: CloudScope & {
1389
1565
  /** Atomically increment a shared numeric value (default delta 1). Resolves to the new value. */
1390
1566
  incr(key: string, delta?: number, opts?: { serviceId?: string }): Promise<number>;
1391
1567
  };
1568
+ /**
1569
+ * Values you own that your accepted friends (mutual consent, blocks
1570
+ * excluded) can read in this app. get/set/remove/keys act on your own
1571
+ * values; `list` reads your friends'. Max 4 KB/value, 200 keys.
1572
+ */
1573
+ friends: CloudScope & {
1574
+ /** Friends' values for `key`, newest first (max 200). [] for guests. Never includes you. */
1575
+ list(key: string, opts?: { serviceId?: string }): Promise<FriendCloudValue[]>;
1576
+ };
1392
1577
  }
1393
1578
 
1394
1579
  export interface Match { roomId: string; players: string[]; serviceId?: string; }
@@ -1464,6 +1649,7 @@ export interface LobbyModule {
1464
1649
  * `err.code`, never on message text.
1465
1650
  */
1466
1651
  export declare const ERROR_CODES: {
1652
+ readonly PERMISSION_DENIED: 'PERMISSION_DENIED';
1467
1653
  readonly NOT_CONNECTED: 'NOT_CONNECTED';
1468
1654
  readonly NO_ROOM: 'NO_ROOM';
1469
1655
  readonly ROOM_NOT_FOUND: 'ROOM_NOT_FOUND';
@@ -1510,3 +1696,49 @@ declare const Usion: UsionSDK;
1510
1696
 
1511
1697
  export { Usion };
1512
1698
  export default Usion;
1699
+
1700
+ /** Connection options for small platform rooms. TURN credentials are supplied by the caller. */
1701
+ export interface ConnectPlayersOptions {
1702
+ roomId?: string;
1703
+ iceServers?: RTCIceServer[];
1704
+ direct?: boolean;
1705
+ /** 1000–30000ms; default 6000. Gameplay uses the relay during negotiation. */
1706
+ directTimeoutMs?: number;
1707
+ }
1708
+ export interface PlayersPeerStatus {
1709
+ playerId: string;
1710
+ transport: 'connecting' | 'webrtc' | 'direct' | 'turn' | 'relay' | 'offline';
1711
+ rttMs: number | null;
1712
+ sent: number;
1713
+ received: number;
1714
+ }
1715
+ export interface PlayersStatus {
1716
+ roomId: string | null;
1717
+ state: 'waiting' | 'connected' | 'offline' | 'closed';
1718
+ peers: PlayersPeerStatus[];
1719
+ }
1720
+ export interface PlayersLog {
1721
+ time: number;
1722
+ event: string;
1723
+ peerId?: string;
1724
+ reason?: string;
1725
+ }
1726
+ export interface PlayersConnection {
1727
+ readonly selfId: string;
1728
+ readonly roomId: string | null;
1729
+ readonly closed: boolean;
1730
+ /** Best-effort JSON updates, up to 4096 UTF-8 bytes. No buffering while offline.
1731
+ * Returns local acceptance, not a delivery acknowledgement. Omit playerId to broadcast.
1732
+ * Late/duplicate updates are discarded; use game.action for durable actions. */
1733
+ send(data: unknown, playerId?: string): boolean;
1734
+ onMessage(callback: (message: {data: any; playerId: string; transport: 'direct' | 'turn' | 'webrtc' | 'relay'}) => void): () => void;
1735
+ onStatusChange(callback: (status: PlayersStatus) => void): () => void;
1736
+ onLog(callback: (entry: PlayersLog) => void): () => void;
1737
+ getStatus(): PlayersStatus;
1738
+ getLogs(): PlayersLog[];
1739
+ forceRelay(playerId?: string): void;
1740
+ retryDirect(playerId?: string): void;
1741
+ invite(): Promise<{success: boolean; roomId: string | null; invited: string[]}>;
1742
+ /** Close networking only; does not leave the platform room or erase game state. */
1743
+ close(): void;
1744
+ }