@oasiz/sdk 1.6.2 → 1.8.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/dist/index.d.cts CHANGED
@@ -1,143 +1,10 @@
1
- type GraphicsPerformanceTier = "minimal" | "low" | "medium" | "high";
2
- interface GraphicsPerformanceMetric {
3
- /** Recommended graphics/rendering frame-rate target for the current device. */
4
- fps: number;
5
- /** Suggested graphics/rendering tier for the current device. */
6
- tier: GraphicsPerformanceTier;
7
- }
8
- /**
9
- * Return the current device's recommended graphics performance profile.
10
- *
11
- * Hosts can provide an FPS/tier recommendation through
12
- * `window.getGraphicsPerformance()` or `window.__OASIZ_GRAPHICS_PERFORMANCE__`.
13
- * When no host value exists, the SDK estimates from browser/device/WebGL
14
- * capability signals so games still get a usable recommendation in local
15
- * development and unsupported hosts.
16
- */
17
- declare function getGraphicsPerformance(): GraphicsPerformanceMetric;
18
-
19
- type ViewportInsetSide = "top" | "right" | "bottom" | "left";
20
- interface ViewportInsetEdges {
21
- top: number;
22
- right: number;
23
- bottom: number;
24
- left: number;
25
- }
26
- interface ViewportInsets {
27
- pixels: ViewportInsetEdges;
28
- percent: ViewportInsetEdges;
29
- }
30
- /**
31
- * Effective viewport insets that game UI should avoid.
32
- *
33
- * `top` preserves the existing Oasiz game-safe top behavior: host chrome and
34
- * invite/leaderboard clearance can contribute to it. Other sides are device
35
- * safe-area insets today, and can include future host UI obstructions.
36
- */
37
- declare function getViewportInsets(): ViewportInsets;
38
- /**
39
- * Legacy alias for the top entry of `getViewportInsets().percent`.
40
- */
41
- declare function getSafeAreaTop(): number;
42
- declare function setLeaderboardVisible(visible: boolean): void;
43
-
44
- type Unsubscribe = () => void;
45
- declare function onPause(callback: () => void): Unsubscribe;
46
- declare function onResume(callback: () => void): Unsubscribe;
47
-
48
- interface BackButtonTestingOptions {
49
- /**
50
- * When true, pressing Escape dispatches the same event the host app sends for
51
- * back actions. Defaults to true.
52
- */
53
- keyboard?: boolean;
54
- /**
55
- * When true, the SDK traps one browser-history entry while back override is
56
- * active, so the browser Back button can be used for local testing. Defaults
57
- * to true.
58
- */
59
- browserHistory?: boolean;
60
- /** Log setup details to the console. Defaults to false. */
61
- log?: boolean;
62
- }
63
- interface BackButtonTestingHandle {
64
- destroy: () => void;
65
- isBackOverrideActive: () => boolean;
66
- triggerBack: () => void;
67
- triggerLeave: () => void;
68
- }
69
- declare function enableBackButtonTesting(options?: BackButtonTestingOptions): BackButtonTestingHandle;
70
- declare function onBackButton(callback: () => void): Unsubscribe;
71
- declare function onLeaveGame(callback: () => void): Unsubscribe;
72
- declare function leaveGame(): void;
73
-
74
- type AppSimulatorDeviceName = "iphone-11" | "iphone-11-pro" | "iphone-11-pro-max" | "iphone-12-mini" | "iphone-12" | "iphone-12-pro" | "iphone-12-pro-max" | "iphone-13-mini" | "iphone-13" | "iphone-13-pro" | "iphone-13-pro-max" | "iphone-14" | "iphone-14-plus" | "iphone-14-pro" | "iphone-14-pro-max" | "iphone-15" | "iphone-15-plus" | "iphone-15-pro" | "iphone-15-pro-max" | "iphone-16" | "iphone-16-plus" | "iphone-16-pro" | "iphone-16-pro-max" | "iphone-16e" | "iphone-17" | "iphone-17-pro" | "iphone-17-pro-max" | "iphone-17e" | "iphone-air" | "iphone-se" | "pixel-8";
75
- type AppSimulatorOrientation = "portrait" | "landscape";
76
- interface AppSimulatorDevice {
77
- height: number;
78
- name?: string;
79
- safeArea?: Partial<ViewportInsetEdges>;
80
- width: number;
81
- }
82
- interface AppSimulatorOptions {
83
- browserHistoryBack?: BackButtonTestingOptions["browserHistory"];
84
- comments?: number;
85
- device?: AppSimulatorDeviceName | AppSimulatorDevice;
86
- enabled?: boolean;
87
- /**
88
- * When true, the SDK tries to place the current game DOM inside a centered
89
- * phone viewport on desktop. Use false if your game already runs in browser
90
- * device emulation or owns its own preview frame. Defaults to true.
91
- */
92
- frame?: boolean | "auto";
93
- keyboardBack?: BackButtonTestingOptions["keyboard"];
94
- leaderboardVisible?: boolean;
95
- likes?: number;
96
- log?: boolean;
97
- orientation?: AppSimulatorOrientation;
98
- score?: number;
99
- title?: string;
100
- }
101
- interface AppSimulatorHandle {
102
- closeSheet: () => void;
103
- destroy: () => void;
104
- getViewportInsets: () => ViewportInsets;
105
- hide: () => void;
106
- isVisible: () => boolean;
107
- openComments: () => void;
108
- openLeaderboard: () => void;
109
- setCounts: (counts: {
110
- comments?: number;
111
- likes?: number;
112
- }) => void;
113
- setLeaderboardVisible: (visible: boolean) => void;
114
- setLiked: (liked: boolean) => void;
115
- show: () => void;
116
- triggerBack: () => void;
117
- triggerLeave: () => void;
118
- }
119
- declare function enableAppSimulator(options?: AppSimulatorOptions): AppSimulatorHandle;
120
-
121
1
  type HapticType = "light" | "medium" | "heavy" | "success" | "error";
122
- type LogOverlayLevel = "debug" | "log" | "info" | "warn" | "error";
123
- interface LogOverlayEntry {
124
- id: number;
125
- level: LogOverlayLevel;
126
- message: string;
127
- timestamp: number;
2
+ interface ScoreAnchor {
3
+ raw: number;
4
+ normalized: 100 | 300 | 600 | 950;
128
5
  }
129
- interface LogOverlayOptions {
130
- collapsed?: boolean;
131
- enabled?: boolean;
132
- maxEntries?: number;
133
- title?: string;
134
- }
135
- interface LogOverlayHandle {
136
- clear: () => void;
137
- destroy: () => void;
138
- hide: () => void;
139
- isVisible: () => boolean;
140
- show: () => void;
6
+ interface ScoreConfig {
7
+ anchors: [ScoreAnchor, ScoreAnchor, ScoreAnchor, ScoreAnchor];
141
8
  }
142
9
  type GameState = Record<string, unknown>;
143
10
  interface ShareRequest {
@@ -145,166 +12,88 @@ interface ShareRequest {
145
12
  score?: number;
146
13
  text?: string;
147
14
  }
148
- /**
149
- * One frame in a texture atlas. Coordinates are in pixels, top-left origin
150
- * (matches HTML canvas / WebGL texture coordinates after Y-flip).
151
- */
152
- interface TextureAtlasFrame {
153
- name: string;
154
- x: number;
155
- y: number;
156
- width: number;
157
- height: number;
158
- }
159
- /**
160
- * Per-direction frame indexes inside an animation. `left` is either an
161
- * integer index or the literal string `"mirror"`, indicating the renderer
162
- * should mirror the right-facing frame instead of using a dedicated one.
163
- */
164
- interface FacingFrameMap {
165
- front: number;
166
- back: number;
167
- right: number;
168
- left: number | "mirror";
169
- }
170
- /**
171
- * One named animation in a texture atlas. `frames` is the playback-ordered
172
- * list of frame names; resolve each name against the parent atlas's
173
- * `frames` array to get pixel coordinates.
174
- */
175
- interface TextureAtlasAnimation {
176
- animationId: string;
177
- role: string | null;
178
- group: string | null;
179
- direction: string | null;
180
- frameRate: number;
181
- frames: string[];
182
- facingFrameMap: FacingFrameMap | null;
183
- }
184
- /**
185
- * TexturePacker / Phaser-style texture atlas describing a baked sprite
186
- * image. Drop-in compatible with Phaser via `addAtlas(key, img, atlas)`
187
- * after a tiny shape transform; usable directly in custom GL renderers.
188
- */
189
- interface TextureAtlas {
190
- imageUrl: string;
191
- imageWidth: number;
192
- imageHeight: number;
193
- frames: TextureAtlasFrame[];
194
- animations: TextureAtlasAnimation[];
195
- }
196
- /**
197
- * The authenticated player's character, returned by `getPlayerCharacter()`.
198
- * `editorTextureAtlas` is the higher-detail variant intended for character
199
- * previews / customizer UI and may be `null`.
200
- */
201
- interface PlayerCharacter {
202
- characterName: string | null;
203
- baseCharacterId: string;
204
- compositionCode: string;
205
- textureAtlas: TextureAtlas;
206
- editorTextureAtlas: TextureAtlas | null;
207
- }
208
- /**
209
- * Result of `addScore(delta)` / `setScore(score)`. Returns `null` when the
210
- * host bridge is unavailable (e.g. local development) or when the backend
211
- * refused the request; production code should treat `null` as "no change
212
- * was persisted, do not update local UI".
213
- */
214
- interface ScoreEditResult {
215
- playerId: string;
216
- previousScore: number;
217
- newScore: number;
218
- previousWeeklyScore: number;
219
- newWeeklyScore: number;
220
- normalizedScore: number | null;
15
+ type StoreProductType = "non-consumable" | "consumable";
16
+ type StoreProductStatus = "active" | "disabled" | "archived";
17
+ type StoreEntitlementStatus = "active" | "consumed" | "revoked" | "refunded";
18
+ interface StoreManifestProduct {
19
+ description?: string | null;
20
+ jemPrice: number;
21
+ metadata?: Record<string, unknown>;
22
+ productId: string;
23
+ title: string;
24
+ type: StoreProductType;
25
+ }
26
+ interface StoreProduct {
27
+ description: string | null;
28
+ gameId: string;
29
+ jemPrice: number;
30
+ metadata: Record<string, unknown>;
31
+ productId: string;
32
+ status: StoreProductStatus;
33
+ title: string;
34
+ type: StoreProductType;
35
+ version: number;
36
+ }
37
+ interface StoreEntitlement {
38
+ gameId: string;
39
+ grantedAt: string | null;
40
+ lastEventId: string | null;
41
+ owned: boolean;
42
+ productId: string;
43
+ quantity: number;
44
+ status: StoreEntitlementStatus;
45
+ updatedAt: string;
46
+ }
47
+ interface StoreStateSnapshot {
48
+ catalogVersion: number;
49
+ entitlements: StoreEntitlement[];
50
+ gameId: string;
51
+ jemBalance: number;
52
+ products: StoreProduct[];
53
+ }
54
+ interface StorePurchaseSuccess {
55
+ attemptId: string;
56
+ entitlement: StoreEntitlement;
57
+ jemBalance: number;
58
+ ok: true;
59
+ state: StoreStateSnapshot;
60
+ transactionId: string;
61
+ }
62
+ interface StorePurchaseFailure {
63
+ attemptId: string;
64
+ code: "ALREADY_OWNED" | "INSUFFICIENT_JEMS" | "INVALID_PRODUCT" | "PRODUCT_DISABLED" | "INVALID_QUANTITY" | "ENTITLEMENT_EXHAUSTED" | "STALE_CATALOG_VERSION" | "UNAUTHORIZED";
65
+ jemBalance: number;
66
+ message: string;
67
+ ok: false;
68
+ state?: StoreStateSnapshot;
69
+ topUpIntentId?: string;
70
+ topUpRedirectUrl?: string;
71
+ }
72
+ type StorePurchaseResult = StorePurchaseSuccess | StorePurchaseFailure;
73
+ interface StoreConsumeSuccess {
74
+ entitlement: StoreEntitlement;
75
+ ok: true;
76
+ state: StoreStateSnapshot;
77
+ }
78
+ interface StoreConsumeFailure {
79
+ code: "INVALID_PRODUCT" | "INVALID_QUANTITY" | "NOT_CONSUMABLE" | "ENTITLEMENT_EXHAUSTED";
80
+ jemBalance: number;
81
+ message: string;
82
+ ok: false;
83
+ state?: StoreStateSnapshot;
221
84
  }
222
-
223
- /**
224
- * Fetch the authenticated player's character, including a TexturePacker /
225
- * Phaser-style texture atlas describing the baked sprite image.
226
- *
227
- * Returns:
228
- * - `null` when the user has no character composition yet, OR
229
- * - `null` when the host bridge is unavailable (local dev / unauthenticated)
230
- *
231
- * The host transparently caches and proxies to `GET /api/sdk/me/character`,
232
- * so calling this multiple times in a session is cheap. The returned
233
- * `imageUrl` is content-addressed (R2 key derives from the composition
234
- * hash), so games can safely cache the downloaded texture by `compositionCode`.
235
- *
236
- * Example (Phaser):
237
- *
238
- * const character = await oasiz.getPlayerCharacter();
239
- * if (!character) return;
240
- * const atlas = character.textureAtlas;
241
- * scene.load.image("player-tex", atlas.imageUrl);
242
- * scene.load.atlas("player", atlas.imageUrl, {
243
- * frames: Object.fromEntries(
244
- * atlas.frames.map((f) => [f.name, { frame: { x: f.x, y: f.y, w: f.width, h: f.height } }]),
245
- * ),
246
- * });
247
- */
248
- declare function getPlayerCharacter(): Promise<PlayerCharacter | null>;
85
+ type StoreConsumeResult = StoreConsumeSuccess | StoreConsumeFailure;
249
86
 
250
87
  declare function triggerHaptic(type: HapticType): void;
251
88
 
252
- declare function enableLogOverlay(options?: LogOverlayOptions): LogOverlayHandle;
253
-
254
- interface ShareRoomCodeOptions {
255
- inviteOverride?: boolean;
256
- }
257
- /**
258
- * Notify the platform of the active multiplayer room so friends can join.
259
- * Pass `{ inviteOverride: true }` when the game wants to hide the platform
260
- * invite pill and own the invite UI itself.
261
- */
262
- declare function shareRoomCode(roomCode: string | null, options?: ShareRoomCodeOptions): void;
263
- /**
264
- * Ask the platform to open the invite-friends modal for the current game room.
265
- * Only has effect when the platform has a room code (game has called shareRoomCode).
266
- * No-op when the bridge is unavailable (e.g. local development).
267
- */
268
- declare function openInviteModal(): void;
89
+ declare function shareRoomCode(roomCode: string | null): void;
269
90
  declare function getGameId(): string | undefined;
270
91
  declare function getRoomCode(): string | undefined;
271
- /**
272
- * Stable, unique, opaque identifier for the authenticated player, injected
273
- * by the platform. Safe to use as a primary key for save slots, matchmaking,
274
- * per-player analytics, or anywhere you need a reliable per-user key —
275
- * unlike `getPlayerName()` (mutable, not unique).
276
- *
277
- * Mirrors the backend's `playerId` field returned by `GET /api/sdk/me`
278
- * (= the Better Auth `user.id`). Returns `undefined` when the platform
279
- * has not injected an identity (e.g. unauthenticated preview).
280
- */
281
- declare function getPlayerId(): string | undefined;
282
92
  declare function getPlayerName(): string | undefined;
283
93
  declare function getPlayerAvatar(): string | undefined;
284
94
 
285
95
  declare function submitScore(score: number): void;
286
-
287
- /**
288
- * Add (or subtract) `delta` from the player's current score for this game.
289
- * The new score is clamped to >= 0 server-side.
290
- *
291
- * Unlike `submitScore()` (which is high-water and only ever raises the
292
- * score), this endpoint always overwrites the row. Use it for game models
293
- * where the leaderboard tracks an accumulator, balance, or persistent state
294
- * instead of a single best-run value.
295
- *
296
- * Returns the resulting score values, or `null` when the bridge is
297
- * unavailable. The integer must be a non-zero integer (positive or negative).
298
- */
299
- declare function addScore(delta: number): Promise<ScoreEditResult | null>;
300
- /**
301
- * Force the player's score to an absolute value (clamped to >= 0).
302
- *
303
- * Same overwrite semantics as `addScore`. Use when the game has computed
304
- * the authoritative score locally (e.g. after offline play) and wants to
305
- * sync it back to the leaderboard.
306
- */
307
- declare function setScore(score: number): Promise<ScoreEditResult | null>;
96
+ declare function emitScoreConfig(config: ScoreConfig): void;
308
97
 
309
98
  declare function share(options: ShareRequest): Promise<void>;
310
99
 
@@ -312,38 +101,55 @@ declare function loadGameState(): GameState;
312
101
  declare function saveGameState(state: GameState): void;
313
102
  declare function flushGameState(): void;
314
103
 
104
+ type Unsubscribe = () => void;
105
+ declare function onPause(callback: () => void): Unsubscribe;
106
+ declare function onResume(callback: () => void): Unsubscribe;
107
+
108
+ declare function onBackButton(callback: () => void): Unsubscribe;
109
+ declare function onLeaveGame(callback: () => void): Unsubscribe;
110
+ declare function leaveGame(): void;
111
+
112
+ declare function syncProducts(products: StoreManifestProduct[], expectedVersion?: number | null): Promise<StoreStateSnapshot>;
113
+ declare function getProducts(): Promise<StoreProduct[]>;
114
+ declare function getEntitlements(): Promise<StoreEntitlement[]>;
115
+ declare function hasEntitlement(productId: string): Promise<boolean>;
116
+ declare function getQuantity(productId: string): Promise<number>;
117
+ declare function purchase(productId: string, quantity?: number): Promise<StorePurchaseResult>;
118
+ declare function consume(productId: string, quantity?: number): Promise<StoreConsumeResult>;
119
+ declare function getJemBalance(): Promise<number>;
120
+ declare function onEntitlementsChanged(callback: (entitlements: StoreEntitlement[]) => void): () => void;
121
+ declare function onJemBalanceChanged(callback: (jemBalance: number) => void): () => void;
122
+
315
123
  declare const oasiz: {
316
124
  submitScore: typeof submitScore;
317
- enableAppSimulator: typeof enableAppSimulator;
318
- addScore: typeof addScore;
319
- setScore: typeof setScore;
320
- getPlayerCharacter: typeof getPlayerCharacter;
125
+ emitScoreConfig: typeof emitScoreConfig;
321
126
  share: typeof share;
322
127
  triggerHaptic: typeof triggerHaptic;
323
- enableLogOverlay: typeof enableLogOverlay;
324
128
  loadGameState: typeof loadGameState;
325
129
  saveGameState: typeof saveGameState;
326
130
  flushGameState: typeof flushGameState;
327
131
  shareRoomCode: typeof shareRoomCode;
328
- openInviteModal: typeof openInviteModal;
329
132
  onPause: typeof onPause;
330
133
  onResume: typeof onResume;
331
- getSafeAreaTop: typeof getSafeAreaTop;
332
- getViewportInsets: typeof getViewportInsets;
333
- setLeaderboardVisible: typeof setLeaderboardVisible;
334
- getGraphicsPerformance: typeof getGraphicsPerformance;
335
- enableBackButtonTesting: typeof enableBackButtonTesting;
336
134
  onBackButton: typeof onBackButton;
337
135
  onLeaveGame: typeof onLeaveGame;
338
136
  leaveGame: typeof leaveGame;
137
+ store: {
138
+ syncProducts: typeof syncProducts;
139
+ getProducts: typeof getProducts;
140
+ getEntitlements: typeof getEntitlements;
141
+ hasEntitlement: typeof hasEntitlement;
142
+ getQuantity: typeof getQuantity;
143
+ purchase: typeof purchase;
144
+ consume: typeof consume;
145
+ getJemBalance: typeof getJemBalance;
146
+ onEntitlementsChanged: typeof onEntitlementsChanged;
147
+ onJemBalanceChanged: typeof onJemBalanceChanged;
148
+ };
339
149
  readonly gameId: string | undefined;
340
150
  readonly roomCode: string | undefined;
341
- readonly playerId: string | undefined;
342
151
  readonly playerName: string | undefined;
343
152
  readonly playerAvatar: string | undefined;
344
- readonly safeAreaTop: number;
345
- readonly viewportInsets: ViewportInsets;
346
- readonly graphicsPerformance: GraphicsPerformanceMetric;
347
153
  };
348
154
 
349
- export { type AppSimulatorDevice, type AppSimulatorDeviceName, type AppSimulatorHandle, type AppSimulatorOptions, type AppSimulatorOrientation, type BackButtonTestingHandle, type BackButtonTestingOptions, type FacingFrameMap, type GameState, type GraphicsPerformanceMetric, type GraphicsPerformanceTier, type HapticType, type LogOverlayEntry, type LogOverlayHandle, type LogOverlayLevel, type LogOverlayOptions, type PlayerCharacter, type ScoreEditResult, type ShareRequest, type ShareRoomCodeOptions, type TextureAtlas, type TextureAtlasAnimation, type TextureAtlasFrame, type Unsubscribe, type ViewportInsetEdges, type ViewportInsetSide, type ViewportInsets, addScore, enableAppSimulator, enableBackButtonTesting, enableLogOverlay, flushGameState, getGameId, getGraphicsPerformance, getPlayerAvatar, getPlayerCharacter, getPlayerId, getPlayerName, getRoomCode, getSafeAreaTop, getViewportInsets, leaveGame, loadGameState, oasiz, onBackButton, onLeaveGame, onPause, onResume, openInviteModal, saveGameState, setLeaderboardVisible, setScore, share, shareRoomCode, submitScore, triggerHaptic };
155
+ export { type GameState, type HapticType, type ScoreAnchor, type ScoreConfig, type ShareRequest, type StoreConsumeFailure, type StoreConsumeResult, type StoreConsumeSuccess, type StoreEntitlement, type StoreEntitlementStatus, type StoreManifestProduct, type StoreProduct, type StoreProductStatus, type StoreProductType, type StorePurchaseFailure, type StorePurchaseResult, type StorePurchaseSuccess, type StoreStateSnapshot, type Unsubscribe, consume, emitScoreConfig, flushGameState, getEntitlements, getGameId, getJemBalance, getPlayerAvatar, getPlayerName, getProducts, getQuantity, getRoomCode, hasEntitlement, leaveGame, loadGameState, oasiz, onBackButton, onEntitlementsChanged, onJemBalanceChanged, onLeaveGame, onPause, onResume, purchase, saveGameState, share, shareRoomCode, submitScore, syncProducts, triggerHaptic };